Home | History | Annotate | only in /src/sys/dev/ic
History log of /src/sys/dev/ic
RevisionDateAuthorComments
 1.30 30-Nov-2024  macallan install summitreg.h - we will need it for Xorg
 1.29 04-Mar-2024  macallan branches: 1.29.2;
install stireg.h
 1.28 07-Dec-2021  brad A driver and user land utility for the Sparkfun Serial Controlled Motor
Driver module as illustrated here:

https://www.sparkfun.com/products/13911

A SCMD module is a ARM SOC simular to a Arduino in front of a motor
driver chip. The single SCMD module can control two motors and up to
16 additional modules can be chained together using an internal I2C
bus. One can interface with the SCMD using tty uart commands, SPI or
I2C. The driver in this commit adds a kernel driver for the I2C and
SPI interfaces. The command line utility provides a set of
convenience commands that support most of the functions of the SCMD
and is able to use the tty uart mode, SPI user land or the included
kernel driver in a uniform manor.

The use of the SCMD module is mostly for small robots and the like,
but it can control anything that is controllable by voltage.
 1.27 19-Jan-2020  thorpej Remove HIPPI support and the esh(4) driver that uses it. There have not
been any users of HIPPI for some time, and it is unlikely to be resurrected.
 1.26 25-Nov-2017  jmcneill branches: 1.26.4; 1.26.12;
Add driver for QEMU Firmware Configuration device.

This interface allows the host to pass various data items and files to
the guest OS.
 1.25 04-Jun-2016  nonaka Add NVMe command passthrough support.
 1.24 11-Dec-2005  christos branches: 1.24.120; 1.24.140;
merge ktrace-lwp.
 1.23 11-Jan-2005  joff Replace hd44780_subr.h to hd44780var.h and install to userland.
 1.22 13-Oct-2003  dyoung Install athioctl.h, defining ioctls for Atheros 802.11a/b/g radios.
 1.21 13-May-2003  thorpej branches: 1.21.2;
Add support for the user-generated command interface and event logging
required by the ICP-Vortex management tools. Many thanks to Achim Leubner
at ICP-Vortex for a few bug fixes and for testing.
 1.20 06-May-2001  ichiro divided into PCMCIA attachment and common code of wi.
since if_wi_ieee.h does not depend for pcmcia,
sys/dev/pcmcia/if_wi_ieee.h was moved to sys/dev/ic/wi_ieee.h .
 1.19 11-Apr-2001  wiz re-add bt8xx.h (needed for fxtv, without which bktr is pretty much useless)
 1.18 11-Apr-2001  jdolecek Only install headers which are actually used by our userland. This
saves about 2.2MB under /usr/include/dev/. Discussed on tech-kern@
recently.

I HOPE to get the list right. The headers I left in are ones
used for MI tools and those whose usage I discovered by grep over tree sources.
Feel free to put needed includes back in if you encounter anything which
should not be removed from lists.
 1.17 10-Apr-2001  mjacob Add isp_ioctl.h.
 1.16 25-Feb-2001  ad branches: 1.16.2;
Remove mlxvar.h, which was added for no apparent reason.
 1.15 18-Feb-2001  taca Add mlxvar.h as include files to install.
 1.14 10-Feb-2001  thorpej Register definitions for the D-Link DL10019 and DL10022 Ethernet
chips. These are NE2000-compatible chips with an MII interface
on them for media.
 1.13 04-Feb-2001  ad Add a driver for the Mylex DAC960 family (including DEC SWXCR).
 1.12 09-Jun-2000  onoe branches: 1.12.2;
cleanup haeders.
add opt_awi.h to define AWI_DEBUG, AWI_WEP_ARC4.
show the firmware version at attach.
create a framework to support WEP (encryption code is not included for now).
a new wiconfig compatible ioctl interface replaced the awictl interface.
fix memory leak in selecting AP
fix bugs in ESSID selection
changes from FreeBSD-current by Warner Losh:
revision 1.2
date: 2000/04/17 22:58:15; author: imp; state: Exp; lines: +16 -1
Provide mem* for compat with NetBSD to fix LINT
fixes from FreeBSD-current by Guido van Rooij:
revision 1.4
date: 2000/05/29 19:58:10; author: guido; state: Exp; lines: +5 -2
Fix a panic resulting from an obvious null pointer deref.
Apparently some other panics still exist in this driver, but with
this fix, it was at least possible to run the Nokia card at SANE 2000.
 1.11 07-May-2000  wiz branches: 1.11.2;
install bt8xx.h for bktr
 1.10 22-Mar-2000  onoe Update awi driver, which now supports AMD 79c930 based 802.11 DS cards
as well as 802.11 FH cards. Also, it can operate in infrastructure mode,
adhoc mode, and wi(4) (aka WaveLAN/IEEE) compatible adhoc mode.
 1.9 20-Mar-2000  ad Install cac{reg,var}.h.
 1.8 18-Mar-2000  mycroft Move some code around in preparation for nca_pcmcia.
 1.7 15-Mar-2000  sommerfeld Catch up to rearranged aic7*.h files
 1.6 04-Dec-1999  sommerfeld Fix "make includes" since pckbc moved to dev/ic from dev/isa
(Hi, Jason!)
 1.5 05-Oct-1999  itohy branches: 1.5.2; 1.5.8;
opl3sa3.h -> opl3sa3reg.h
 1.4 29-Sep-1999  ad Install dptreg.h, dptvar.h.
 1.3 30-Jan-1999  minoura branches: 1.3.2;
MC68450 DMAC regs.
 1.2 30-Oct-1998  nisimura - Add filenames for VDAC/cursor sprite hardware descriptions; bt431reg.h,
bt459reg.h, bt463reg.h and ims332.h as pointed by Klaus Klein.
 1.1 12-Jun-1998  cgd Rework the way kernel include files are installed. In the new method,
as with user-land programs, include files are installed by each directory
in the tree that has includes to install. (This allows more flexibility
as to what gets installed, makes 'partial installs' easier, and gives us
more options as to which machines' includes get installed at any given
time.) The old SYS_INCLUDES={symlinks,copies} behaviours are _both_
still supported, though at least one bug in the 'symlinks' case is
fixed by this change. Include files can't be build before installation,
so directories that have includes as targets (e.g. dev/pci) have to move
those targets into a different Makefile.
 1.3.2.1 08-Feb-2000  he Apply patch (requested by ad):
Install dptreg.h and dptvar.h.
 1.5.8.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.5.2.3 21-Apr-2001  bouyer Sync with HEAD
 1.5.2.2 11-Feb-2001  bouyer Sync with HEAD.
 1.5.2.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.11.2.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.12.2.1 26-Oct-2001  jhawk Pull up via patch (requested by windsor):
Move mlxio.h and mlxreg.h from dev/pci/Makefile to dev/ic/Makefile
 1.16.2.1 21-Jun-2001  nathanw Catch up to -current.
 1.21.2.4 17-Jan-2005  skrll Sync with HEAD.
 1.21.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.21.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.21.2.1 03-Aug-2004  skrll Sync with HEAD
 1.24.140.1 09-Jul-2016  skrll Sync with HEAD
 1.24.120.1 03-Dec-2017  jdolecek update from HEAD
 1.26.12.1 25-Jan-2020  ad Sync with head.
 1.26.4.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.29.2.1 02-Aug-2025  perseant Sync with HEAD
 1.5 03-Dec-2021  andvar fix various typos in comments, log messages and documentation.
 1.4 24-Nov-2006  christos fix spelling of accommodate; from Zapher.
 1.3 27-Feb-2005  perry branches: 1.3.4; 1.3.32; 1.3.34;
nuke trailing whitespace
 1.2 11-Jun-2001  wiz branches: 1.2.22; 1.2.30; 1.2.32;
Fix various misspellings of compatible/compatibility.
 1.1 25-Oct-1998  christos branches: 1.1.24;
PR/6274: John Ruschmeyer: Add support for the ncr53c80 driver on the i386.
 1.1.24.1 21-Jun-2001  nathanw Catch up to -current.
 1.2.32.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.2.30.1 29-Apr-2005  kent sync with -current
 1.2.22.1 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.3.34.1 10-Dec-2006  yamt sync with head.
 1.3.32.1 12-Jan-2007  ad Sync with head.
 1.3.4.1 30-Dec-2006  yamt sync with head.
 1.50 21-Oct-2025  pgoyette Give these a chance of building - avoid ST_NODEV redefinition
 1.49 07-Aug-2021  thorpej Merge thorpej-cfargs2.
 1.48 24-Apr-2021  thorpej branches: 1.48.8;
Merge thorpej-cfargs branch:

Simplify and make extensible the config_search() / config_found() /
config_attach() interfaces: rather than having different variants for
which arguments you want pass along, just have a single call that
takes a variadic list of tag-value arguments.

Adjust all call sites:
- Simplify wherever possible; don't pass along arguments that aren't
actually needed.
- Don't be explicit about what interface attribute is attaching if
the device only has one. (More simplification.)
- Add a config_probe() function to be used in indirect configuiration
situations, making is visibly easier to see when indirect config is
in play, and allowing for future change in semantics. (As of now,
this is just a wrapper around config_match(), but that is an
implementation detail.)

Remove unnecessary or redundant interface attributes where they're not
needed.

There are currently 5 "cfargs" defined:
- CFARG_SUBMATCH (submatch function for direct config)
- CFARG_SEARCH (search function for indirect config)
- CFARG_IATTR (interface attribte)
- CFARG_LOCATORS (locators array)
- CFARG_DEVHANDLE (devhandle_t - wraps OFW, ACPI, etc. handles)

...and a sentinel value CFARG_EOL.

Add some extra sanity checking to ensure that interface attributes
aren't ambiguous.

Use CFARG_DEVHANDLE in MI FDT, OFW, and ACPI code, and macppc and shark
ports to associate those device handles with device_t instance. This
will trickle trough to more places over time (need back-end for pre-OFW
Sun OBP; any others?).
 1.47 10-Nov-2019  chs branches: 1.47.10;
in many device attach paths, allocate memory with M_WAITOK instead of M_NOWAIT
and remove code to handle failures that can no longer happen.
 1.46 28-Oct-2017  riastradh branches: 1.46.4;
Kill some more extern struct cfdriver declarations.

Down with externs in .c!
 1.45 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).
 1.44 27-Oct-2012  chs branches: 1.44.14; 1.44.18;
split device_t/softc for all remaining drivers.
replace "struct device *" with "device_t".
use device_xname(), device_unit(), etc.
 1.43 13-Nov-2010  uebayasi branches: 1.43.8; 1.43.18;
Don't pull in the whole uvm(9) API to access only PAGE_SIZE and
some other constants. These are provided by sys/param.h now.
 1.42 16-Dec-2008  christos branches: 1.42.6;
replace bitmask_snprintf(9) with snprintb(3)
 1.41 02-Oct-2008  sborrill branches: 1.41.2;
Add support for >2TB arrays and implement raw I/O mode which is a
requirement for this.

N.B. Still to do - move dump on ld to 64-bit disk addresses
 1.40 08-Jun-2008  tsutsui branches: 1.40.4;
Replace device_lookup() with device_lookup_private() on getting softc
for future device_t/softc spilt.
 1.39 28-Apr-2008  martin branches: 1.39.2;
Remove clause 3 and 4 from TNF licenses
 1.38 08-Apr-2008  cegger branches: 1.38.2; 1.38.4;
use aprint_*_dev and device_xname
 1.37 21-Oct-2007  briggs branches: 1.37.16;
Use AAC_PREALLOCATE_FIBS with the softc as a parameter to catch up with
revision 1.10 of aacvar.h.
 1.36 19-Oct-2007  ad machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.35 09-Jul-2007  ad branches: 1.35.6; 1.35.8; 1.35.12;
Merge some of the less invasive changes from the vmlocking branch:

- kthread, callout, devsw API changes
- select()/poll() improvements
- miscellaneous MT safety improvements
 1.34 05-Jun-2007  briggs Bring in changes from FreeBSD...
* Allocate commands on-demand.
* Update a bunch of constants and some structures.
* Use __attribute__ ((__packed__)) instead of __packed to be consistent.
* Support more commands for devices that can apparently handle them.
* Support a "new comm. interface" present in more recent Adaptec
firmware. This reduces the amount of PCI bus traffic in handling
commands.
* Support larger commands going to the adapter--if the adapter can
support them.
* Support 64-bit commands for archs where sizeof(bus_addr_t) > 4 and
for adapters that advertise SGMAP64.
* Handle the WINDOW4G option and NO4GB quirk by excluding 2G-4G window
unless we have the WINDOW4G capability without the NO4GB quirk.
* Ask the adapter more about its capabilities and try to use those if
they seem sane.
* Do our bus_dmamap_sync() inside dequeue_fib instead of following,
since we have the information that we need there.
* Provide access functions for some adapters that I haven't seen yet
(MIPS-based "Rocket" adapters). Not yet used.
 1.33 26-May-2007  briggs Clear interrupt status at once instead of piecemeal.
Enable a few more bits in the I/O requested by ld and check for the fast
response bit when reading back from the queue.
Both changes come from reading the FreeBSD driver and testing on a Dell
CERC SATA controller.
 1.32 26-May-2007  briggs Import code from FreeBSD to tell the controller how much physical RAM the
system has. This has the (scary-because-we've-been-running-so-long-
without-it) commit message (for the first version of the change):
Tell the controller how much physical memory we have. Without this
there was a chance that our DMA regions would collide with the
memory window used by the cache on the controller. The result would
be massive data corruption. This seemed to mainly affect systems with
>2GB of memory.
 1.31 24-May-2007  briggs Some changes from the FreeBSD driver:
* Include definitions of adapter-initiated fibs.
* Send aifs back to the adapter after we receive them.
* Use indexes instead of pointers in 32-bit hardware registers.
* If we get a message that there's a printf from the adapter, but we have
a NUL in the first character of the printf string, change the NUL to a
space.
 1.30 04-Mar-2007  christos branches: 1.30.2; 1.30.4;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.29 16-Nov-2006  christos branches: 1.29.2; 1.29.4; 1.29.8;
__unused removal on arguments; approved by core.
 1.28 12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.27 04-Mar-2006  thorpej branches: 1.27.14; 1.27.16;
LP54 -> LP64 in a comment.
 1.26 27-Dec-2005  chs branches: 1.26.4; 1.26.6;
use %z when printing a sizeof.
 1.25 26-Nov-2005  jdolecek Add some casts to make this compile on amd64 (and perhaps other LP64
architectures). Part of PR kern/30456.

The binary object file on i386 confirmed to be exactly the same before
and after the change.
 1.24 26-Nov-2005  jdolecek fix aac_print_fib() to compile with AAC_DEBUG; noncompilable "%16D" printf
format replaced by explicit hexadecimal dump of the first 32 bytes of fip->data
 1.23 25-Aug-2005  drochner branches: 1.23.6;
kill a number of autoconf submatch functions which follow the
standard scheme:
if (<configured> != <wildcard> && <configured> != <real>)
then fail
else
ask device match function

This is handled by config_stdsubmatch() now.
 1.22 25-Aug-2005  drochner replace the "locdesc_t" structure carrying the number of locators
explicitely by a plain integer array
the length in now known to all relevant parties, so this avoids
duplication of information, and we can allocate that thing in
drivers without hacks
 1.21 20-Jun-2005  darcy branches: 1.21.2;
Fix another portability issue. Part of PR kern/30456.
 1.20 20-Jun-2005  darcy Fix some printf statements to make them more portable. Doesn't completely
fix PR kern/30456 but fixes part of it.
 1.19 30-May-2005  christos - add missing const
- fix variable shadowing
- remove unneeded casts
 1.18 12-Mar-2005  darcy Add to XXX comment for future reference.
 1.17 01-Mar-2005  briggs * Remove aif_get_mailboxstatus() from the aac_interface structure. Replace
with aif_get_mailbox(). Make it return uint32_t instead of 'int'.
* Add an AAC_GET_MAILBOX() macro and change AAC_GET_MAILBOXSTATUS() to use
that.
* Update the Dell PERC 2QC quirk code to use AAC_GET_MAILBOX instead of the
StrongARM-specific code. While StrongARM access is correct for that card,
it's a bad example of how to access the mailbox registers.
* Add the GETINFO command and use it to get and display the card's
supported options at a verbose level during attachment.
 1.16 27-Feb-2005  perry nuke trailing whitespace
 1.15 15-Feb-2005  briggs Be more verbose at attachment. Display kernel revision and add
the monitor revision and adapter serial number at a "verbose" level.
Add the total adapter RAM at "normal" level.
 1.14 14-Jan-2005  scw branches: 1.14.2; 1.14.4;
Cast away a couple of "assignment makes pointer from integer without a cast"
warnings.
 1.13 13-Sep-2004  drochner a round of autoconf cleanup:
-convert submatch() style functions (passed to config_search() or
config_found_sm()) to the locator passing variants
-pass interface attributes in some cases
-make submatch() functions look uniformly as far as possible
-avoid macros which just hide cfdata members, and reduce dependencies
on "locators.h"
 1.12 24-Aug-2004  thorpej Use ANSI function decls and more use of static.
 1.11 20-Mar-2004  christos Remove extraneous ; from OpenBSD.
 1.10 09-Dec-2003  ad Mirror change made in FreeBSD, rev 1.39 of aac.c. May address PR 23574.
bzero out the sync command buffer when sending commands. This was causing
problems when enumerating multiple arrays.
 1.9 03-May-2003  wiz branches: 1.9.2;
DMA, not dma nor Dma.
 1.8 31-Jan-2003  thorpej Use aprint_*().
 1.7 01-Jan-2003  thorpej Use aprint_normal() in cfprint routines.
 1.6 25-Nov-2002  fvdl Actually, back out previous. Better have it not compile on LP64 to show
that it's broken for that case.
 1.5 25-Nov-2002  fvdl Add some hideous casts to get this to compile on LP64. Doesn't look like
it has a chance of working, though.
 1.4 27-Sep-2002  thorpej Introduce a new routine, config_match(), which invokes the
cfattach->ca_match function in behalf of the caller. Use it
rather than invoking cfattach->ca_match directly.
 1.3 01-Jun-2002  lukem branches: 1.3.2; 1.3.4;
SIMPLEQ rototill:
- implement SIMPLEQ_REMOVE(head, elm, type, field). whilst it's O(n),
this mirrors the functionality of SLIST_REMOVE() (the other
singly-linked list type) and FreeBSD's STAILQ_REMOVE()
- remove the unnecessary elm arg from SIMPLEQ_REMOVE_HEAD().
this mirrors the functionality of SLIST_REMOVE_HEAD() (the other
singly-linked list type) and FreeBSD's STAILQ_REMOVE_HEAD()
- remove notes about SIMPLEQ not supporting arbitrary element removal
- use SIMPLEQ_FOREACH() instead of home-grown for loops
- use SIMPLEQ_EMPTY() appropriately
- use SIMPLEQ_*() instead of accessing sqh_first,sqh_last,sqe_next directly
- reorder manual page; be consistent about how the types are listed
- other minor cleanups
 1.2 31-May-2002  thorpej Fix a pasto in printf arguments which resulted in the aac kernel
version being mis-reported.
 1.1 26-Apr-2002  ad branches: 1.1.2;
Add a driver for Adaptec FSA RAID controllers, as often found in Dell
servers. Based on the FreeBSD/OpenBSD versions.
 1.1.2.1 20-Jun-2002  gehenna catch up with -current.
 1.3.4.3 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.3.4.2 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.3.4.1 01-Jun-2002  jdolecek file aac.c was added on branch kqueue on 2002-06-23 17:46:06 +0000
 1.3.2.4 03-Jan-2003  thorpej Sync with HEAD.
 1.3.2.3 18-Oct-2002  nathanw Catch up to -current.
 1.3.2.2 20-Jun-2002  nathanw Catch up to -current.
 1.3.2.1 01-Jun-2002  nathanw file aac.c was added on branch nathanw_sa on 2002-06-20 03:44:26 +0000
 1.9.2.10 11-Dec-2005  christos Sync with head.
 1.9.2.9 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.9.2.8 01-Apr-2005  skrll Sync with HEAD.
 1.9.2.7 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.9.2.6 15-Feb-2005  skrll Sync with HEAD.
 1.9.2.5 17-Jan-2005  skrll Sync with HEAD.
 1.9.2.4 21-Sep-2004  skrll Fix the sync with head I botched.
 1.9.2.3 18-Sep-2004  skrll Sync with HEAD.
 1.9.2.2 25-Aug-2004  skrll Sync with HEAD.
 1.9.2.1 03-Aug-2004  skrll Sync with HEAD
 1.14.4.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.14.2.1 29-Apr-2005  kent sync with -current
 1.21.2.4 27-Oct-2007  yamt sync with head.
 1.21.2.3 03-Sep-2007  yamt sync with head.
 1.21.2.2 30-Dec-2006  yamt sync with head.
 1.21.2.1 21-Jun-2006  yamt sync with head.
 1.23.6.1 29-Nov-2005  yamt sync with head.
 1.26.6.1 22-Apr-2006  simonb Sync with head.
 1.26.4.1 09-Sep-2006  rpaulo sync with head
 1.27.16.2 10-Dec-2006  yamt sync with head.
 1.27.16.1 22-Oct-2006  yamt sync with head
 1.27.14.1 18-Nov-2006  ad Sync with head.
 1.29.8.1 06-Jan-2008  wrstuden Catch up to netbsd-4.0 release.
 1.29.4.1 12-Mar-2007  rmind Sync with HEAD.
 1.29.2.2 03-Oct-2008  jdc Pull up revisions:
src/sys/dev/ic/aac.c 1.41 via patch
src/sys/dev/ic/aacreg.h 1.13 via patch
src/sys/dev/ic/aacvar.h 1.13 via patch
src/sys/dev/ic/ld_aac.c 1.22 via patch
(requested by sborrill in ticket #1208).
 1.29.2.1 25-Nov-2007  xtraeme Pull up following revision(s) (requested by briggs in ticket #990):
sys/dev/ic/aac_tables.h: revision 1.5 (patch)
sys/dev/ic/aac.c: revision 1.31 (patch)
sys/dev/ic/aac.c: revision 1.32 (patch)
sys/dev/ic/aac.c: revision 1.33 (patch)
sys/dev/ic/aac.c: revision 1.34 (patch)
sys/arch/amd64/conf/INSTALL: revision 1.70 (patch)
sys/dev/ic/aac.c: revision 1.37 (patch)
sys/dev/ic/aacreg.h: revision 1.6 (patch)
sys/dev/ic/aacreg.h: revision 1.7 (patch)
sys/dev/ic/aacreg.h: revision 1.8 (patch)
sys/dev/ic/aacreg.h: revision 1.9 (patch)
sys/dev/pci/aac_pci.c: revision 1.21 (patch)
sys/dev/ic/aacvar.h: revision 1.10 (patch)
sys/dev/ic/aacvar.h: revision 1.9 (patch)
sys/arch/amd64/conf/GENERIC: revision 1.144 (patch)
sys/dev/ic/ld_aac.c: revision 1.14 (patch)
sys/dev/ic/ld_aac.c: revision 1.15 (patch)
Compile and run on amd64 and on >2GB RAM.
 1.30.4.1 11-Jul-2007  mjf Sync with head.
 1.30.2.3 23-Oct-2007  ad Sync with head.
 1.30.2.2 09-Jun-2007  ad Sync with head.
 1.30.2.1 27-May-2007  ad Sync with head.
 1.35.12.1 25-Oct-2007  bouyer Sync with HEAD.
 1.35.8.1 06-Nov-2007  matt sync with HEAD
 1.35.6.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.37.16.4 17-Jan-2009  mjf Sync with HEAD.
 1.37.16.3 05-Oct-2008  mjf Sync with HEAD.
 1.37.16.2 29-Jun-2008  mjf Sync with HEAD.
 1.37.16.1 02-Jun-2008  mjf Sync with HEAD.
 1.38.4.2 04-May-2009  yamt sync with head.
 1.38.4.1 16-May-2008  yamt sync with head.
 1.38.2.2 17-Jun-2008  yamt sync with head.
 1.38.2.1 18-May-2008  yamt sync with head.
 1.39.2.2 10-Oct-2008  skrll Sync with HEAD.
 1.39.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.40.4.1 19-Oct-2008  haad Sync with HEAD.
 1.41.2.1 19-Jan-2009  skrll Sync with HEAD.
 1.42.6.1 05-Mar-2011  rmind sync with head
 1.43.18.2 03-Dec-2017  jdolecek update from HEAD
 1.43.18.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.43.8.1 30-Oct-2012  yamt sync with head
 1.44.18.1 04-Nov-2016  pgoyette Sync with HEAD
 1.44.14.1 05-Oct-2016  skrll Sync with HEAD
 1.46.4.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.47.10.2 22-Mar-2021  thorpej Audit CFARG_IATTR in config_found() calls, and remove it in situations
where the interface attribute is not ambiguous.
 1.47.10.1 22-Mar-2021  thorpej Mechanical conversion of config_found_sm_loc() -> config_found().
CFARG_IATTR usage needs to be audited.
 1.48.8.1 04-Aug-2021  thorpej Adapt to CFARGS().
 1.6 02-Feb-2024  andvar s/maintenace/maintenance/ in command status code description.
 1.5 05-Jun-2007  briggs Bring in changes from FreeBSD...
* Allocate commands on-demand.
* Update a bunch of constants and some structures.
* Use __attribute__ ((__packed__)) instead of __packed to be consistent.
* Support more commands for devices that can apparently handle them.
* Support a "new comm. interface" present in more recent Adaptec
firmware. This reduces the amount of PCI bus traffic in handling
commands.
* Support larger commands going to the adapter--if the adapter can
support them.
* Support 64-bit commands for archs where sizeof(bus_addr_t) > 4 and
for adapters that advertise SGMAP64.
* Handle the WINDOW4G option and NO4GB quirk by excluding 2G-4G window
unless we have the WINDOW4G capability without the NO4GB quirk.
* Ask the adapter more about its capabilities and try to use those if
they seem sane.
* Do our bus_dmamap_sync() inside dequeue_fib instead of following,
since we have the information that we need there.
* Provide access functions for some adapters that I haven't seen yet
(MIPS-based "Rocket" adapters). Not yet used.
 1.4 11-Dec-2005  christos branches: 1.4.24; 1.4.30; 1.4.32; 1.4.38;
merge ktrace-lwp.
 1.3 15-Feb-2005  briggs branches: 1.3.6;
Identify Intel 80303 cpu variant.
 1.2 23-Aug-2004  thorpej branches: 1.2.4; 1.2.6;
Protect against multiple inclusion.
 1.1 26-Apr-2002  ad branches: 1.1.6; 1.1.8; 1.1.14;
Add a driver for Adaptec FSA RAID controllers, as often found in Dell
servers. Based on the FreeBSD/OpenBSD versions.
 1.1.14.4 15-Feb-2005  skrll Sync with HEAD.
 1.1.14.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.1.14.2 18-Sep-2004  skrll Sync with HEAD.
 1.1.14.1 25-Aug-2004  skrll Sync with HEAD.
 1.1.8.2 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.1.8.1 26-Apr-2002  jdolecek file aac_tables.h was added on branch kqueue on 2002-06-23 17:46:07 +0000
 1.1.6.2 20-Jun-2002  nathanw Catch up to -current.
 1.1.6.1 26-Apr-2002  nathanw file aac_tables.h was added on branch nathanw_sa on 2002-06-20 03:44:26 +0000
 1.2.6.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.2.4.1 29-Apr-2005  kent sync with -current
 1.3.6.1 03-Sep-2007  yamt sync with head.
 1.4.38.1 06-Jan-2008  wrstuden Catch up to netbsd-4.0 release.
 1.4.32.1 11-Jul-2007  mjf Sync with head.
 1.4.30.1 09-Jun-2007  ad Sync with head.
 1.4.24.1 25-Nov-2007  xtraeme Pull up following revision(s) (requested by briggs in ticket #990):
sys/dev/ic/aac_tables.h: revision 1.5 (patch)
sys/dev/ic/aac.c: revision 1.31 (patch)
sys/dev/ic/aac.c: revision 1.32 (patch)
sys/dev/ic/aac.c: revision 1.33 (patch)
sys/dev/ic/aac.c: revision 1.34 (patch)
sys/arch/amd64/conf/INSTALL: revision 1.70 (patch)
sys/dev/ic/aac.c: revision 1.37 (patch)
sys/dev/ic/aacreg.h: revision 1.6 (patch)
sys/dev/ic/aacreg.h: revision 1.7 (patch)
sys/dev/ic/aacreg.h: revision 1.8 (patch)
sys/dev/ic/aacreg.h: revision 1.9 (patch)
sys/dev/pci/aac_pci.c: revision 1.21 (patch)
sys/dev/ic/aacvar.h: revision 1.10 (patch)
sys/dev/ic/aacvar.h: revision 1.9 (patch)
sys/arch/amd64/conf/GENERIC: revision 1.144 (patch)
sys/dev/ic/ld_aac.c: revision 1.14 (patch)
sys/dev/ic/ld_aac.c: revision 1.15 (patch)
Compile and run on amd64 and on >2GB RAM.
 1.15 02-Feb-2024  andvar s/Staus/Status/ in comments.
 1.14 10-Dec-2021  andvar s/occured/occurred/ in comments, log messages and man pages.
 1.13 02-Oct-2008  sborrill Add support for >2TB arrays and implement raw I/O mode which is a
requirement for this.

N.B. Still to do - move dump on ld to 64-bit disk addresses
 1.12 08-Sep-2008  gmcgarry Replace most gcc-specific __attribute__ uses with BSD-style sys/cdef.h
preprocessor macros.
 1.11 28-Apr-2008  martin branches: 1.11.2; 1.11.6;
Remove clause 3 and 4 from TNF licenses
 1.10 25-Dec-2007  perry branches: 1.10.6; 1.10.8; 1.10.10;
Convert many of the uses of __attribute__ to equivalent
__packed, __unused and __dead macros from cdefs.h
 1.9 05-Jun-2007  briggs branches: 1.9.8; 1.9.14; 1.9.16; 1.9.20;
Bring in changes from FreeBSD...
* Allocate commands on-demand.
* Update a bunch of constants and some structures.
* Use __attribute__ ((__packed__)) instead of __packed to be consistent.
* Support more commands for devices that can apparently handle them.
* Support a "new comm. interface" present in more recent Adaptec
firmware. This reduces the amount of PCI bus traffic in handling
commands.
* Support larger commands going to the adapter--if the adapter can
support them.
* Support 64-bit commands for archs where sizeof(bus_addr_t) > 4 and
for adapters that advertise SGMAP64.
* Handle the WINDOW4G option and NO4GB quirk by excluding 2G-4G window
unless we have the WINDOW4G capability without the NO4GB quirk.
* Ask the adapter more about its capabilities and try to use those if
they seem sane.
* Do our bus_dmamap_sync() inside dequeue_fib instead of following,
since we have the information that we need there.
* Provide access functions for some adapters that I haven't seen yet
(MIPS-based "Rocket" adapters). Not yet used.
 1.8 26-May-2007  briggs Import code from FreeBSD to tell the controller how much physical RAM the
system has. This has the (scary-because-we've-been-running-so-long-
without-it) commit message (for the first version of the change):
Tell the controller how much physical memory we have. Without this
there was a chance that our DMA regions would collide with the
memory window used by the cache on the controller. The result would
be massive data corruption. This seemed to mainly affect systems with
>2GB of memory.
 1.7 26-May-2007  briggs Don't use pointers in device structures.
Bring in some newer stuff for the init structure from FreeBSD.
 1.6 24-May-2007  briggs Some changes from the FreeBSD driver:
* Include definitions of adapter-initiated fibs.
* Send aifs back to the adapter after we receive them.
* Use indexes instead of pointers in 32-bit hardware registers.
* If we get a message that there's a printf from the adapter, but we have
a NUL in the first character of the printf string, change the NUL to a
space.
 1.5 11-Dec-2005  christos branches: 1.5.24; 1.5.30; 1.5.32; 1.5.38;
merge ktrace-lwp.
 1.4 01-Mar-2005  briggs branches: 1.4.4;
* Remove aif_get_mailboxstatus() from the aac_interface structure. Replace
with aif_get_mailbox(). Make it return uint32_t instead of 'int'.
* Add an AAC_GET_MAILBOX() macro and change AAC_GET_MAILBOXSTATUS() to use
that.
* Update the Dell PERC 2QC quirk code to use AAC_GET_MAILBOX instead of the
StrongARM-specific code. While StrongARM access is correct for that card,
it's a bad example of how to access the mailbox registers.
* Add the GETINFO command and use it to get and display the card's
supported options at a verbose level during attachment.
 1.3 27-Feb-2005  perry nuke trailing whitespace
 1.2 15-Feb-2005  briggs Identify Intel 80303 cpu variant.
 1.1 26-Apr-2002  ad branches: 1.1.6; 1.1.8; 1.1.14; 1.1.22; 1.1.24;
Add a driver for Adaptec FSA RAID controllers, as often found in Dell
servers. Based on the FreeBSD/OpenBSD versions.
 1.1.24.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.1.22.1 29-Apr-2005  kent sync with -current
 1.1.14.2 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.1.14.1 15-Feb-2005  skrll Sync with HEAD.
 1.1.8.2 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.1.8.1 26-Apr-2002  jdolecek file aacreg.h was added on branch kqueue on 2002-06-23 17:46:07 +0000
 1.1.6.2 20-Jun-2002  nathanw Catch up to -current.
 1.1.6.1 26-Apr-2002  nathanw file aacreg.h was added on branch nathanw_sa on 2002-06-20 03:44:26 +0000
 1.4.4.2 21-Jan-2008  yamt sync with head
 1.4.4.1 03-Sep-2007  yamt sync with head.
 1.5.38.1 06-Jan-2008  wrstuden Catch up to netbsd-4.0 release.
 1.5.32.1 11-Jul-2007  mjf Sync with head.
 1.5.30.2 09-Jun-2007  ad Sync with head.
 1.5.30.1 27-May-2007  ad Sync with head.
 1.5.24.2 03-Oct-2008  jdc Pull up revisions:
src/sys/dev/ic/aac.c 1.41 via patch
src/sys/dev/ic/aacreg.h 1.13 via patch
src/sys/dev/ic/aacvar.h 1.13 via patch
src/sys/dev/ic/ld_aac.c 1.22 via patch
(requested by sborrill in ticket #1208).
 1.5.24.1 25-Nov-2007  xtraeme Pull up following revision(s) (requested by briggs in ticket #990):
sys/dev/ic/aac_tables.h: revision 1.5 (patch)
sys/dev/ic/aac.c: revision 1.31 (patch)
sys/dev/ic/aac.c: revision 1.32 (patch)
sys/dev/ic/aac.c: revision 1.33 (patch)
sys/dev/ic/aac.c: revision 1.34 (patch)
sys/arch/amd64/conf/INSTALL: revision 1.70 (patch)
sys/dev/ic/aac.c: revision 1.37 (patch)
sys/dev/ic/aacreg.h: revision 1.6 (patch)
sys/dev/ic/aacreg.h: revision 1.7 (patch)
sys/dev/ic/aacreg.h: revision 1.8 (patch)
sys/dev/ic/aacreg.h: revision 1.9 (patch)
sys/dev/pci/aac_pci.c: revision 1.21 (patch)
sys/dev/ic/aacvar.h: revision 1.10 (patch)
sys/dev/ic/aacvar.h: revision 1.9 (patch)
sys/arch/amd64/conf/GENERIC: revision 1.144 (patch)
sys/dev/ic/ld_aac.c: revision 1.14 (patch)
sys/dev/ic/ld_aac.c: revision 1.15 (patch)
Compile and run on amd64 and on >2GB RAM.
 1.9.20.1 02-Jan-2008  bouyer Sync with HEAD
 1.9.16.1 26-Dec-2007  ad Sync with head.
 1.9.14.1 18-Feb-2008  mjf Sync with HEAD.
 1.9.8.1 09-Jan-2008  matt sync with HEAD
 1.10.10.2 04-May-2009  yamt sync with head.
 1.10.10.1 16-May-2008  yamt sync with head.
 1.10.8.1 18-May-2008  yamt sync with head.
 1.10.6.3 05-Oct-2008  mjf Sync with HEAD.
 1.10.6.2 28-Sep-2008  mjf Sync with HEAD.
 1.10.6.1 02-Jun-2008  mjf Sync with HEAD.
 1.11.6.1 19-Oct-2008  haad Sync with HEAD.
 1.11.2.2 10-Oct-2008  skrll Sync with HEAD.
 1.11.2.1 24-Sep-2008  wrstuden Merge in changes between wrstuden-revivesa-base-2 and
wrstuden-revivesa-base-3.
 1.15 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).
 1.14 27-Oct-2012  chs branches: 1.14.14; 1.14.18;
split device_t/softc for all remaining drivers.
replace "struct device *" with "device_t".
use device_xname(), device_unit(), etc.
 1.13 02-Oct-2008  sborrill branches: 1.13.28; 1.13.38;
Add support for >2TB arrays and implement raw I/O mode which is a
requirement for this.

N.B. Still to do - move dump on ld to 64-bit disk addresses
 1.12 28-Apr-2008  martin branches: 1.12.2; 1.12.6;
Remove clause 3 and 4 from TNF licenses
 1.11 15-Dec-2007  perry branches: 1.11.6; 1.11.8; 1.11.10;
__FUNCTION__ -> __func__
 1.10 20-Oct-2007  briggs branches: 1.10.4; 1.10.8;
Preallocate all of our FIBs. This needs more work, but currently avoids
a case where we could need more FIBs and try to allocate them inside an
interrupt handler, which is sub-par--a problem pointed out ages ago by ad@.
 1.9 05-Jun-2007  briggs branches: 1.9.6; 1.9.8; 1.9.12;
Bring in changes from FreeBSD...
* Allocate commands on-demand.
* Update a bunch of constants and some structures.
* Use __attribute__ ((__packed__)) instead of __packed to be consistent.
* Support more commands for devices that can apparently handle them.
* Support a "new comm. interface" present in more recent Adaptec
firmware. This reduces the amount of PCI bus traffic in handling
commands.
* Support larger commands going to the adapter--if the adapter can
support them.
* Support 64-bit commands for archs where sizeof(bus_addr_t) > 4 and
for adapters that advertise SGMAP64.
* Handle the WINDOW4G option and NO4GB quirk by excluding 2G-4G window
unless we have the WINDOW4G capability without the NO4GB quirk.
* Ask the adapter more about its capabilities and try to use those if
they seem sane.
* Do our bus_dmamap_sync() inside dequeue_fib instead of following,
since we have the information that we need there.
* Provide access functions for some adapters that I haven't seen yet
(MIPS-based "Rocket" adapters). Not yet used.
 1.8 11-Dec-2005  christos branches: 1.8.24; 1.8.30; 1.8.32; 1.8.38;
merge ktrace-lwp.
 1.7 30-May-2005  christos branches: 1.7.2;
- add missing const
- fix variable shadowing
- remove unneeded casts
 1.6 01-Mar-2005  briggs * Remove aif_get_mailboxstatus() from the aac_interface structure. Replace
with aif_get_mailbox(). Make it return uint32_t instead of 'int'.
* Add an AAC_GET_MAILBOX() macro and change AAC_GET_MAILBOXSTATUS() to use
that.
* Update the Dell PERC 2QC quirk code to use AAC_GET_MAILBOX instead of the
StrongARM-specific code. While StrongARM access is correct for that card,
it's a bad example of how to access the mailbox registers.
* Add the GETINFO command and use it to get and display the card's
supported options at a verbose level during attachment.
 1.5 27-Feb-2005  perry nuke trailing whitespace
 1.4 13-Sep-2004  drochner branches: 1.4.4; 1.4.6;
a round of autoconf cleanup:
-convert submatch() style functions (passed to config_search() or
config_found_sm()) to the locator passing variants
-pass interface attributes in some cases
-make submatch() functions look uniformly as far as possible
-avoid macros which just hide cfdata members, and reduce dependencies
on "locators.h"
 1.3 24-Aug-2004  thorpej Use ANSI function decls and more use of static.
 1.2 02-Nov-2003  wiz branches: 1.2.4;
Fix some typos. From Tom Cosgrove via jmc@openbsd.
 1.1 26-Apr-2002  ad branches: 1.1.6; 1.1.8; 1.1.14;
Add a driver for Adaptec FSA RAID controllers, as often found in Dell
servers. Based on the FreeBSD/OpenBSD versions.
 1.1.14.6 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.1.14.5 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.1.14.4 21-Sep-2004  skrll Fix the sync with head I botched.
 1.1.14.3 18-Sep-2004  skrll Sync with HEAD.
 1.1.14.2 25-Aug-2004  skrll Sync with HEAD.
 1.1.14.1 03-Aug-2004  skrll Sync with HEAD
 1.1.8.2 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.1.8.1 26-Apr-2002  jdolecek file aacvar.h was added on branch kqueue on 2002-06-23 17:46:07 +0000
 1.1.6.2 20-Jun-2002  nathanw Catch up to -current.
 1.1.6.1 26-Apr-2002  nathanw file aacvar.h was added on branch nathanw_sa on 2002-06-20 03:44:26 +0000
 1.2.4.1 13-May-2005  riz Pull up a patch to add a quirk that was missed in ticket #1402.
(Adds a quirk)
 1.4.6.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.4.4.1 29-Apr-2005  kent sync with -current
 1.7.2.3 21-Jan-2008  yamt sync with head
 1.7.2.2 27-Oct-2007  yamt sync with head.
 1.7.2.1 03-Sep-2007  yamt sync with head.
 1.8.38.1 06-Jan-2008  wrstuden Catch up to netbsd-4.0 release.
 1.8.32.1 11-Jul-2007  mjf Sync with head.
 1.8.30.1 09-Jun-2007  ad Sync with head.
 1.8.24.2 03-Oct-2008  jdc Pull up revisions:
src/sys/dev/ic/aac.c 1.41 via patch
src/sys/dev/ic/aacreg.h 1.13 via patch
src/sys/dev/ic/aacvar.h 1.13 via patch
src/sys/dev/ic/ld_aac.c 1.22 via patch
(requested by sborrill in ticket #1208).
 1.8.24.1 25-Nov-2007  xtraeme Pull up following revision(s) (requested by briggs in ticket #990):
sys/dev/ic/aac_tables.h: revision 1.5 (patch)
sys/dev/ic/aac.c: revision 1.31 (patch)
sys/dev/ic/aac.c: revision 1.32 (patch)
sys/dev/ic/aac.c: revision 1.33 (patch)
sys/dev/ic/aac.c: revision 1.34 (patch)
sys/arch/amd64/conf/INSTALL: revision 1.70 (patch)
sys/dev/ic/aac.c: revision 1.37 (patch)
sys/dev/ic/aacreg.h: revision 1.6 (patch)
sys/dev/ic/aacreg.h: revision 1.7 (patch)
sys/dev/ic/aacreg.h: revision 1.8 (patch)
sys/dev/ic/aacreg.h: revision 1.9 (patch)
sys/dev/pci/aac_pci.c: revision 1.21 (patch)
sys/dev/ic/aacvar.h: revision 1.10 (patch)
sys/dev/ic/aacvar.h: revision 1.9 (patch)
sys/arch/amd64/conf/GENERIC: revision 1.144 (patch)
sys/dev/ic/ld_aac.c: revision 1.14 (patch)
sys/dev/ic/ld_aac.c: revision 1.15 (patch)
Compile and run on amd64 and on >2GB RAM.
 1.9.12.1 25-Oct-2007  bouyer Sync with HEAD.
 1.9.8.2 09-Jan-2008  matt sync with HEAD
 1.9.8.1 06-Nov-2007  matt sync with HEAD
 1.9.6.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.10.8.1 02-Jan-2008  bouyer Sync with HEAD
 1.10.4.1 26-Dec-2007  ad Sync with head.
 1.11.10.2 04-May-2009  yamt sync with head.
 1.11.10.1 16-May-2008  yamt sync with head.
 1.11.8.1 18-May-2008  yamt sync with head.
 1.11.6.2 05-Oct-2008  mjf Sync with HEAD.
 1.11.6.1 02-Jun-2008  mjf Sync with HEAD.
 1.12.6.1 19-Oct-2008  haad Sync with HEAD.
 1.12.2.1 10-Oct-2008  skrll Sync with HEAD.
 1.13.38.2 03-Dec-2017  jdolecek update from HEAD
 1.13.38.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.13.28.1 30-Oct-2012  yamt sync with head
 1.14.18.1 04-Nov-2016  pgoyette Sync with HEAD
 1.14.14.1 05-Oct-2016  skrll Sync with HEAD
 1.100 18-Oct-2020  rin Fix undefined behaviors found by kUBSan.
Tested on VirtualBox with amd64 kernel.
 1.99 28-Nov-2019  isaki Use NULL for pointer.
 1.98 08-May-2019  isaki Merge isaki-audio2 branch, the overhaul of audio subsystem.
- Interrupt-oriented system rather than thread-oriented.
- Improve stability, quality and performance.
- Split playback and record cleanly. Improve halfduplex support.
- Many bugs are fixed including deadlocks, resource leaks, abuses, etc.
- Simplify audio filter mechanism. The encoding/channels/frequency
conversions are completely handled in the upper layer. So the hard-
ware driver only converts its hardware encoding (if necessary).
- audio_hw_if changes:
- Obsoletes query_encoding and add query_format instead.
- Obsoletes set_params and add set_format instead.
- Remove drain, setfd, mappage.
- The call sequences are changed.
- ioctl AUDIO_GETFD/SETFD, AUDIO_GETCHAN/SETCHAN are obsoleted.
- ioctl AUDIO_{QUERY,GET,SET}FORMAT are introduced.
- cleanup config attributes: au*conv and mulaw.
- All hardware drivers should follow it (I've done as much as possible).

Some file paths are changed:
- dev/audio.c -> dev/audio/audio.c (rewritten)
- dev/audiovar.h -> dev/audio/audiovar.h
- dev/audio_dai.h -> dev/audio/audio_dai.h
- dev/audio_if.h -> dev/audio/audio_if.h
- dev/audiobell.c -> dev/audio/audiobell.c
- dev/audiobellvar.h -> dev/audio/audiobellvar.h
- dev/mulaw.[ch] -> dev/audio/mulaw.[ch] + dev/audio/alaw.c
 1.97 28-Jul-2017  nat branches: 1.97.4; 1.97.8;
Mixer device bounds checking.

Analysis by Ilja van Sprundel.
 1.96 04-Apr-2015  christos branches: 1.96.10;
fix memory leak, found by Brainy.
XXX: is there anything else that we need to cleanup at this point?
 1.95 27-Oct-2012  chs branches: 1.95.12; 1.95.14;
split device_t/softc for all remaining drivers.
replace "struct device *" with "device_t".
use device_xname(), device_unit(), etc.
 1.94 02-Jun-2012  dsl branches: 1.94.2;
Add some pre-processor magic to verify that the type of the data item
passed to sysctl_createv() actually matches the declared type for
the item itself.
In the places where the caller specifies a function and a structure
address (typically the 'softc') an explicit (void *) cast is now needed.
Fixes bugs in sys/dev/acpi/asus_acpi.c sys/dev/bluetooth/bcsp.c
sys/kern/vfs_bio.c sys/miscfs/syncfs/sync_subr.c and setting
AcpiGbl_EnableAmlDebugObject.
(mostly passing the address of a uint64_t when typed as CTLTYPE_INT).
I've test built quite a few kernels, but there may be some unfixed MD
fallout. Most likely passing &char[] to char *.
Also add CTLFLAG_UNSIGNED for unsiged decimals - not set yet.
 1.93 27-Nov-2011  mbalmer Add the Avance Logic ALC203 code, found on e.g. alix3d3 boards.
 1.92 23-Nov-2011  jmcneill Merge jmcneill-audiomp3 branch, which is derived from ad-audiomp2. From
the original ad-audiomp branch notes:

Add MP locking to the audio drivers.

Making the audio drivers MP safe is necessary before efforts
can be made to make the VM system MP safe.

The are two locks per device instance, an ISR lock and
a character device lock. The ISR lock replaces calls to
splaudio()/splx(), and will be held across calls to device
methods which were called at splaudio() before (e.g.
trigger_output). The character device lock is held across
calls to nearly all of the methods, excluding some only
used for initialization, e.g. get_locks.

Welcome to 5.99.57.
 1.91 13-Jul-2009  kiyohara branches: 1.91.12; 1.91.14;
Support UCB1400.
It tested on GUMSTIX with audiostix. However GUMSTIX needs more ad-hoc patch.
 1.90 12-May-2009  cegger struct device * -> device_t, no functional changes intended.
 1.89 16-Dec-2008  christos branches: 1.89.2;
replace bitmask_snprintf(9) with snprintb(3)
 1.88 24-Jun-2008  gmcgarry branches: 1.88.4; 1.88.8;
Array range designated initializers are a gcc extension. Replace with
explicit initialization with zeros, although it probably isn't necessary.
 1.87 08-Apr-2008  cegger branches: 1.87.4; 1.87.6; 1.87.8;
use aprint_*_dev and device_xname
 1.86 21-Feb-2007  thorpej branches: 1.86.2; 1.86.38;
Replace the Mach-derived boolean_t type with the C99 bool type. A
future commit will replace use of TRUE and FALSE with true and false.
 1.85 16-Feb-2007  alc branches: 1.85.2;
Update documentation URL. Previous one was leading to a "Page not found".
 1.84 02-Sep-2006  christos add missing initializers
 1.83 23-Aug-2006  kent implement auto-detection of volume resolutions
 1.82 26-Jul-2006  kent add capability to support for S/PDIF.
If a codec supports for AC'97 S/PDIF, it will have an mixer "spdif.enable."
However, we can't change the value of the mixer without AC'97 host
driver's support.
 1.81 10-May-2006  uebayasi Update URLs to ASAHI KASEI CODECs.
 1.80 15-Apr-2006  jmcneill * Add a flag AC97_HOST_INVERTED_EAMP. (kern/18880, kern/24488).
* Make reset callback optional; not all devices need it. (port-i386/14260, kern/12603, kern/12723, kern/24957).
 1.79 11-Dec-2005  christos branches: 1.79.4; 1.79.6; 1.79.8; 1.79.10; 1.79.12;
merge ktrace-lwp.
 1.78 06-Nov-2005  rpaulo Add "Conexant CXT48". This should have a more meaningful name, but I
couldn't find it. So, I added this because it's better than printing
"unknown codec". When we find a more decent name later, we can change this.
 1.77 27-Sep-2005  simonb Add SigmaTel STAC9752/53 codec ID.
 1.76 20-Jun-2005  atatat branches: 1.76.2;
Change the rest of the sysctl subsystem to use const consistently.
The __UNCONST macro is now used only where necessary and the RW macros
are gone. Most of the changes here are consumers of the
sysctl_createv(9) interface that now takes a pair of const pointers
which used not to be.
 1.75 30-May-2005  christos - add missing const
- fix variable shadowing
- remove unneeded casts
 1.74 11-May-2005  scw Add a heuristic to test if an audio CODEC's AC97_REG_POWER register supports
the AC97_POWER_ANL bit.

The heuristic simply checks if AC97_REG_POWER's AC97_POWER_MIXER bit can
be set, implying the CODEC can control power to its mixer. If the bit
reads back as zero after we set it, assume ANL is reserved.

Without this patch, some CODECs (e.g. Philips UCB1400) will experience long
delays during attach and resume while the driver waits for a bit which will
never set.

Thanks to jmcneill@ for reviewing this WRT AC97 modem power control.
 1.73 12-Apr-2005  jmcneill * Reduce timeout for codec powerup
* Return ENXIO from ac97_attach_type if the modem codec fails to power-on.
This will prevent broken AC97 modems *cough*Conexant*cough* from giving
the impression that they will actually work.
 1.72 12-Apr-2005  jmcneill Don't touch AC97_REG_RESET if we're dealing with a modem (modems use
AC97_REG_EXT_MODEM_ID instead). Also set the default audio rate to 8000;
12000 was a stupid choice since we don't actually support it in the driver
yet.
 1.71 11-Apr-2005  jmcneill Add ac97_attach_type(), to allow the hw driver to skip probes for audio or
modem devices. ac97_attach now calls ac97_attach_type() with
AC97_CODEC_TYPE_AUDIO, for backwords compatibility.
 1.70 08-Apr-2005  jmcneill Add identifiers for Intel ICH3 AC'97 modems and CXT33 modem codecs, from
Nicolas Joly <njoly _at_ pasteur _dot_ fr>.
 1.69 07-Apr-2005  jmcneill AC'97 modems don't have the same mixer controls as audio devices. Treat
them differently. Mixers are built depending on the features returned
in the ext_mid -- any combination of LINE1, LINE2, and HANDSET.
 1.68 04-Apr-2005  jmcneill * Add more AC97 modem registers (from AC'97 revision 2.2)
* Add sysctls to control the modem's off-hook status (work in progress)
 1.67 04-Apr-2005  jmcneill * Add support for skipping either the modem or audio AC'97 probes
via host_flags: AC97_HOST_SKIP_AUDIO, AC97_HOST_SKIP_MODEM
* If we're dealing with a modem codec, print the extended modem
capabilities.
* Add basic AC'97 modem initialization support.
* Add some (but not all) AC'97 modem registers. More will be added later.
 1.66 10-Jan-2005  kent branches: 1.66.2;
merge kent-audio1 branch, which introduces audio filter pipeline to the MI
audio framework


Summary of changes:

* struct audio_params
- remove sw_code, factor, factor_denom, hw_sample_rate,
hw_encoding ,hw_precision, and hw_channels. Conversion information
is conveyed by stream_filter_list_t.
- change the type of sample_rate: u_long -> u_int
- add `validbits,' which represents the valid data size in
precision bits. It is required in order to distinguish 24/32bit
from 24/24bit or 32/32bit.

* audio_hw_if
- add two parameters to set_params()
stream_filter_list_t *pfil, stream_filter_list *rfil
A HW driver should set filter recipes for requested formats
- constify audio_params parameters of trigger_output() and
trigger_input(). They represent audio formats for the hardware.
- make open() and close() optional
- add int (AUMODE_PLAY or AUMODE_RECORD) and audio_params_t parameters
to round_blocksize()

* sw_code is replaced with stream_filter_t.
stream_filer_t converts audio data in an input buffer and writes
into another output buffer unlike sw_code, which converts data in
single buffer.
converters in dev/auconv.c, dev/mulaw.c, dev/aurateconv.c,
dev/tc/bba.c, dev/ic/msm6258.c, and arch/arm/iomd/vidcaudio.c are
reimplemented as stream_filter_t

* MI audio
- audiosetinfo() builds filter pipelines from stream_filter_list_t
filled by audio_hw_if::set_params()
- audiosetinfo() returns with EINVAL if mmapped and set_params()
requests filters
- audio_write(), audio_pint(), and audio_rint() invoke a filter
pipeline.
- ioctl() for FIONREAD, AUDIO_WSEEK, AUDIO_GETIOFFS,
AUDIO_GETOOFFS, and audio_prinfo::{seek,samples} for
AUDIO_GETINFO handle values for a buffer nearest to userland.

* add `struct device *' parameter to ac97_attach()

* all of audio HW drivers follow audio_hw_if and ac97 changes
 1.65 08-Nov-2004  kent branches: 1.65.2;
- nuke __P()
- add ac97_codec_if_vtbl::detach()
 1.64 17-Oct-2004  kent make sure of readiness of an AC'97 codec by writing a value and
reading it. There is a codec which is not operational just
after power states become ready.

PR#26457
 1.63 12-Oct-2004  kent split outputs.tone to outputs.bass and outputs.treble

from OpenBSD
 1.62 22-Sep-2004  kent ac97_host_if::reset() returns non-zero value if codec reset fails, and
ac97 is not attached in that case.

PR: kern/26973
 1.61 28-Aug-2004  kent add debug code for ac97_write().
It is enabled by defining AC97_IO_DEBUG.
 1.60 24-Aug-2004  thorpej Use ANSI function decls and more use of static.
 1.59 20-Aug-2004  kent Check power states after codec reset. This change fixes a
resume problem on some boards.
Patch provided by Joachim Thiemann in PR kern/26457
 1.58 08-Aug-2004  kent VT1616i support
 1.57 08-Aug-2004  kent correct the mask value for CMI9739
 1.56 08-Aug-2004  kent recognize CMI9739 codec.
 1.55 07-Aug-2004  kent AD1888 support.
PR kern/25949
 1.54 07-Aug-2004  kent recognize ALC655/658/850
 1.53 01-Jun-2004  mrg - update URLs for sigmatel.
- add entry for "SigmaTel STAC9758/59" (seen on a new emuxki card)
 1.52 24-Nov-2003  kent branches: 1.52.2;
An ICH board needs reading AC97_REG_RESET before reading AC97_VENDOR_ID.
(why?)
http://mail-index.netbsd.org/current-users/2003/11/22/0007.html
 1.51 22-Nov-2003  kent AD1985 codec needs the same quirk as AD1980.
The patch was provided by Lars Heidieker.
 1.50 22-Nov-2003  kent Cosmetic changes
- ANSIfy
- no argument names in prototypes
- variable declaration with initialization
 1.49 28-Sep-2003  cube Change the way of setting a port value so that a change too small to
fit in the number of bits used for the port still does something.

This fixes PR pkg/18741 for ac97-based hardware. Other audio drivers
might need a similar fix.
 1.48 28-Sep-2003  kent codec id for AD1985
 1.47 11-Sep-2003  jmmv After initialization of the AD1980 codec, swap master and surround volume
controls. As it was before, the master volume control in all mixer programs
did nothing. It seems that this codec is not correctly wired in (almost?)
all motherboards.

Patch by Quentin Garnier. Fixes first part of PR kern/22548.
 1.46 08-Sep-2003  kent Correct flag names of AD1980
 1.45 07-Sep-2003  kent Codec id ADS 0x70 is AD1980, not AD1981.
http://mail-index.netbsd.org/tech-kern/2003/09/03/0005.html
 1.44 07-Sep-2003  kent Use bitmask_snprintf() for printing ext id features.
 1.43 13-Jun-2003  kent branches: 1.43.2;
Add AD1981-specific initialization.
The patch provided by Lars Heideker.

PR: kern/20368
 1.42 11-Jun-2003  scw In ac97_restore_shadow(), make sure to restore the codec's extended
control register if we configured it during ac97_attach().
 1.41 03-Mar-2003  bsh add Philips UCB1400
 1.40 31-Jan-2003  thorpej Use aprint_*().
 1.39 20-Jan-2003  simonb Remove variable that is only assigned too but not referenced.
 1.38 26-Dec-2002  matt Recognize AD1981 codec (0x41445370). XXX name is a guess but it follows
the existing pattern.
 1.37 06-Nov-2002  kent Fix LR contrary problem of mixer and record gain polarity
problem. The change is based on the patches in PR kern/12878 by
Zdenek Salvet and PR kern/18901 by SUNAKAWA Hirokatsu.
 1.36 06-Nov-2002  kent Add codec IDs for AD1981B, STAC9750/51, and STAC9766/67.
Whitespace.
 1.35 22-Oct-2002  kent Correct codec id of VT1611A.
Add codec id of VT1616.

ALC650 codec specific chagne:
Add outputs.surround.mixtofront,
outputs.center.mixtofront, and outputs.lfe.mixtofront.

VT1616 codec specific change:
Add outputs.surround.mixtofront,
outputs.center.mixtofront, and outputs.lfe.mixtofront.
(Not tested)

XXX: We should provide ac97(4) manual page and describe
codec-specific features.
 1.34 16-Oct-2002  kent Add all vendor/codec IDs which OpenBSD has and NetBSD doesn't have.
 1.33 14-Oct-2002  kent Mixer changes:
- Add "outputs.surround", "outputs.center", and "outputs.lfe"
- If the codec is not capable of a feature, mixer variables
about the feature is not created. For example, no
"outputs.tone" for a codec without tone control.
- Set the following mixer values in ac97_attach():
outputs.master=127,127
outputs.master.mute=off
outputs.headphones.mute=off
outputs.surround=127,127
outputs.surround.mute=off
outputs.center=127
outputs.center.mute=off
outputs.lfe=127
outputs.lfe.mute=off
inputs.dac.mute=off
inputs.cd.mute=off
inputs.line.mute=off
inputs.aux.mute=off
inputs.video.mute=off
record.volume.mute=off
because the default setting of AC'97 codec (all mutes are on,
and maximum volume) is troublesome.
- Make "char*" parameters of ac97_get_portnum_by_name() "const char*"

Codec ID changes:
- If a codec ID is unknown but its vendor ID is known,
ac97_attach() prints the vendor name like "dev0: <vendor name>
unknown (0xXXXXXXXX) codec;"
- Add IDs of Asahi Kasei AK4542, AK4544, AK4544A, AK4545,
Realtek ALC100
- Correct a vendor name: "Advance Logic" -> "Avance Logic"
- Add capability of codec-specific initialization

ac97_attach():
- CDAC, SDAC, and LDAC are eanabled.
- DELAY() before mixer settings. ThinkPad X24 needs it.

ALC650 codec specific change:
- Add "outputs.surround.lineinjack" to switch the line-in jack
to the surround output
- Add "outputs.center.micjack" and "outputs.lfe.micjack" (alias
of "outputs.center.micjack") to switch the mic jack to the
center/lfe output.
 1.32 11-Oct-2002  kent ac97_attach(): Restore the default rate value after VRA checking.
This change might solve PR kern/18613.
 1.31 09-Oct-2002  kent Add 'mask' member to the struct ac97_codecid.
Cirrus Logic Crystal codec uses lower three bits in ID for a
revision number. We should mask an actual ID value before
matching to this table.
 1.30 08-Oct-2002  pooka fill in name for TriTech unknown: TR28602
 1.29 08-Oct-2002  kent If the codec is fixed-rate, ac97_set_rate() returns 48kHz.
 1.28 08-Oct-2002  kent Add IDs for YMF743-S and YMF753-S.

ac97_attach(): Enable VRA/VRM if the codec is capable of them.

The struct ac97_softc keeps the clock of the codec, the basic
features flag (the value of AC97_REG_RESET), and the extended
features flag (the value of AC97_REG_EXT_AUDIO_ID).

ac97_codec_if: Add get_extcaps(), set_rate(), and set_clock()
methods.
 1.27 06-Oct-2002  kent Add some constant symbols for AC97 registers and values based on OpenBSD.
Rename some symbols to sync with OpenBSD:
AC97_REG_EXTENDED_ID
-> AC97_REG_EXT_AUDIO_ID
AC97_REG_EXTENDED_STATUS
-> AC97_REG_EXT_AUDIO_CTRL
AC97_CODEC_DOES_VRA/AC97_ENAB_VRA
-> AC97_EXT_AUDIO_VRA
AC97_CODEC_DOES_MICVRA/AC97_ENAB_MICVRA
-> AC97_EXT_AUDIO_VRM

ac97feature: "mic channel" -> "dedicated mic channel"
ac97_attach(): print extended capabilities; VRA, DRA, SPDIF, VRM, CDAC,
SDAC, LDAC.
 1.26 04-Oct-2002  joda more device names
 1.25 05-Jul-2002  joda add a couple of Analog device names
 1.24 23-Jan-2002  ichiro branches: 1.24.8; 1.24.10;
It corrected forgetting to attach ","
 1.23 12-Jan-2002  tsutsui Call malloc(9) with M_ZERO flag instead of memset() after malloc().
 1.22 06-Jan-2002  jmcneill For cosmetic reasons, add 'ESS Technology ES1921' to the table of codec Ids.
 1.21 13-Nov-2001  lukem add/cleanup RCSID
 1.20 07-Jul-2001  thorpej branches: 1.20.2;
bcopy -> memcpy
 1.19 29-Apr-2001  erh Set the delta for the particular source so telling mixerctl to decrease the
volume (using --) adjusts it far enough to stick.
 1.18 18-Jan-2001  jdolecek branches: 1.18.2;
constify
 1.17 09-Jan-2001  rh Add new AC97_HOST_SWAPPED_CHANNELS host flag that causes left and right
mixer channels to be swapped (required for hardware that has wiring
reversed).
 1.16 05-Jan-2001  augustss Add some codecs.
 1.15 05-Nov-2000  thorpej branches: 1.15.2;
Feh, fix st00p1d braino in last.
 1.14 04-Nov-2000  thorpej Shadow the AC'97 codec registers. This adds two capabilities:
* support devices that crash when reading the codec registers; a flags
interface is added to the host interface and one flag is defined
(AC97_HOST_DONT_READ).
* new API (restore_ports) for restoring the user's settings. This
can be useful after an APM resume after a suspend to disk.

From OpenBSD.
 1.13 04-Nov-2000  thorpej Add some more codec IDs. From OpenBSD.
 1.12 14-Jul-2000  soren Merge-o.
 1.11 06-Jun-2000  soren branches: 1.11.2;
Make ID printing a little more robust in case of problems reading
AC97 registers.
 1.10 15-May-2000  thorpej branches: 1.10.2;
Move register definitions into ac97reg.h
 1.9 15-May-2000  thorpej ac97.h -> ac97var.h
 1.8 28-Apr-2000  augustss Unmute some mixer controls by default. From OpenBSD.
 1.7 26-Apr-2000  thorpej Recognize the Crystal CS4297A codec, and add a couple of macros
to manipulate AC97 codec IDs.
 1.6 15-Mar-2000  augustss Fix an uninitialized variable. From Krister Walfridsson <cato@df.lth.se>
 1.5 24-Nov-1999  augustss branches: 1.5.2;
Change CS4297 id entry.
 1.4 20-Nov-1999  augustss Print the PnP id of unknown codecs.
 1.3 02-Nov-1999  augustss branches: 1.3.4;
Shorten some delay()s. From WITEK Wnuk <witek@atari.org>
 1.2 02-Nov-1999  soren Clean up attachment printing a bit.
 1.1 27-Oct-1999  augustss Add AC97 mixer/codec support. From OpenBSD and FreeBSD.
 1.3.4.2 15-Nov-1999  fvdl Sync with -current
 1.3.4.1 02-Nov-1999  fvdl file ac97.c was added on branch fvdl-softdep on 1999-11-15 00:40:22 +0000
 1.5.2.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.10.2.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.11.2.5 09-Feb-2002  he Pull up revision 1.24 (requested by ichiro):
Add accidentally omitted comma.
 1.11.2.4 24-Jan-2002  he Pull up revision 1.22 (requested by he):
Add driver for the ESS Allegro-1 / Maestro-3 audio hardware.
 1.11.2.3 03-May-2001  he Pull down revision 1.19 (requested by he):
Previous pull-up was a bit too aggressive, causing a compile
problem. Sorry.
 1.11.2.2 03-May-2001  he Pull up revisions 1.13-1.19 (requested by skrll and he):
Add a driver for the ESS Technology Maestro-1/2/2E AC97 audio chips,
ES1968 and ES1978.
 1.11.2.1 03-Sep-2000  soren Pull up rev 1.12:
> date: 2000/07/14 21:09:45; author: soren; state: Exp; lines: +2 -2
> Merge-o (printf format mistake).
 1.15.2.6 11-Feb-2001  bouyer Sync with HEAD.
 1.15.2.5 18-Jan-2001  bouyer Sync with head (for UBC+NFS fixes, mostly).
 1.15.2.4 05-Jan-2001  bouyer Sync with HEAD
 1.15.2.3 22-Nov-2000  bouyer Sync with HEAD.
 1.15.2.2 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.15.2.1 05-Nov-2000  bouyer file ac97.c was added on branch thorpej_scsipi on 2000-11-20 11:40:03 +0000
 1.18.2.9 29-Dec-2002  thorpej Sync with HEAD.
 1.18.2.8 11-Nov-2002  nathanw Catch up to -current
 1.18.2.7 18-Oct-2002  nathanw Catch up to -current.
 1.18.2.6 01-Aug-2002  nathanw Catch up to -current.
 1.18.2.5 28-Feb-2002  nathanw Catch up to -current.
 1.18.2.4 11-Jan-2002  nathanw More catchup.
 1.18.2.3 14-Nov-2001  nathanw Catch up to -current.
 1.18.2.2 24-Aug-2001  nathanw Catch up with -current.
 1.18.2.1 21-Jun-2001  nathanw Catch up to -current.
 1.20.2.3 06-Sep-2002  jdolecek sync kqueue branch with HEAD
 1.20.2.2 11-Feb-2002  jdolecek Sync w/ -current.
 1.20.2.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.24.10.1 11-Dec-2002  he Pull up revision 1.37 (via patch, requested by kent in ticket #980):
Fix LR reversal problem of mixer and record gain
polarity problem. Based on PR#12878 and PR#18901.
 1.24.8.1 15-Jul-2002  gehenna catch up with -current.
 1.43.2.11 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.43.2.10 17-Jan-2005  skrll Sync with HEAD.
 1.43.2.9 14-Nov-2004  skrll Sync with HEAD.
 1.43.2.8 19-Oct-2004  skrll Sync with HEAD
 1.43.2.7 24-Sep-2004  skrll Sync with HEAD.
 1.43.2.6 21-Sep-2004  skrll Fix the sync with head I botched.
 1.43.2.5 18-Sep-2004  skrll Sync with HEAD.
 1.43.2.4 03-Sep-2004  skrll Sync with HEAD
 1.43.2.3 25-Aug-2004  skrll Sync with HEAD.
 1.43.2.2 12-Aug-2004  skrll Sync with HEAD.
 1.43.2.1 03-Aug-2004  skrll Sync with HEAD
 1.52.2.3 22-Sep-2004  jmc Pullup rev 1.62 (requested by kent in ticket #867)

ac97_host_if::reset() returns non-zero value if codec reset fails, and
ac97 is not attached in that case. PR#26973
 1.52.2.2 10-Sep-2004  tron Pull up revision 1.59 (requested by kent in ticket #823):
Check power states after codec reset. This change fixes a
resume problem on some boards.
Patch provided by Joachim Thiemann in PR kern/26457
 1.52.2.1 12-Aug-2004  jmc Pullup rev 1.54-1.58 (requested by kent in ticket #758)

Support for some AC'97 codecs
 1.65.2.2 02-Jan-2005  kent unify to uintXX_t
 1.65.2.1 02-Jan-2005  kent * add "struct device *" parameter to ac97_attach() as discussion in tech-kern
* change the type of sampling rate parameter of ac97_set_rate():
u_long * -> u_int *
* other cosmetic changes
 1.66.2.1 29-Apr-2005  kent sync with -current
 1.76.2.3 26-Feb-2007  yamt sync with head.
 1.76.2.2 30-Dec-2006  yamt sync with head.
 1.76.2.1 21-Jun-2006  yamt sync with head.
 1.79.12.1 24-May-2006  tron Merge 2006-05-24 NetBSD-current into the "peter-altq" branch.
 1.79.10.2 11-May-2006  elad sync with head
 1.79.10.1 19-Apr-2006  elad sync with head.
 1.79.8.3 03-Sep-2006  yamt sync with head.
 1.79.8.2 11-Aug-2006  yamt sync with head
 1.79.8.1 24-May-2006  yamt sync with head.
 1.79.6.2 01-Jun-2006  kardel Sync with head.
 1.79.6.1 22-Apr-2006  simonb Sync with head.
 1.79.4.1 09-Sep-2006  rpaulo sync with head
 1.85.2.1 27-Feb-2007  yamt - sync with head.
- move sched_changepri back to kern_synch.c as it doesn't know PPQ anymore.
 1.86.38.3 17-Jan-2009  mjf Sync with HEAD.
 1.86.38.2 29-Jun-2008  mjf Sync with HEAD.
 1.86.38.1 02-Jun-2008  mjf Sync with HEAD.
 1.86.2.1 27-Feb-2007  ad Add MP locking for audio drivers.
 1.87.8.1 27-Jun-2008  simonb Sync with head.
 1.87.6.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.87.4.3 18-Jul-2009  yamt sync with head.
 1.87.4.2 16-May-2009  yamt sync with head
 1.87.4.1 04-May-2009  yamt sync with head.
 1.88.8.1 07-Dec-2008  ad Ressurect the ad-audiomp branch at request of matt@.

With this commit:

- core audio subsystem made MPSAFE
- eap, btsco drivers made MPSAFE

TODO:

- midi
- convert remaining drivers
 1.88.4.1 19-Jan-2009  skrll Sync with HEAD.
 1.89.2.2 23-Jul-2009  jym Sync with HEAD.
 1.89.2.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.91.14.1 19-Nov-2011  jmcneill port ad-audiomp2 branch changes to 5.99.56
todo:
- port ad-audiomp2 pcppi changes
- these drivers need to be fixed:
- emuxki
- gcscaudio
- hdafg
- uaudio
- umidi
- MD audio drivers
 1.91.12.2 30-Oct-2012  yamt sync with head
 1.91.12.1 17-Apr-2012  yamt sync with head
 1.94.2.2 03-Dec-2017  jdolecek update from HEAD
 1.94.2.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.95.14.2 28-Aug-2017  skrll Sync with HEAD
 1.95.14.1 06-Apr-2015  skrll Sync with HEAD
 1.95.12.2 09-Aug-2017  snj Pull up following revision(s) (requested by nat in ticket #1460):
sys/dev/auconv.c: revision 1.30 via patch
sys/dev/ic/ac97.c: revision 1.97 via patch
sys/dev/pci/azalia_codec.c: revision 1.81 via patch
Mixer device bounds checking.
Analysis by Ilja van Sprundel.
 1.95.12.1 05-Jul-2015  snj branches: 1.95.12.1.2; 1.95.12.1.6;
Pull up following revision(s) (requested by maxv in ticket #858):
sys/dev/ic/ac97.c: revision 1.96
fix memory leak, found by Brainy.
XXX: is there anything else that we need to cleanup at this point?
 1.95.12.1.6.1 09-Aug-2017  snj Pull up following revision(s) (requested by nat in ticket #1460):
sys/dev/auconv.c: revision 1.30 via patch
sys/dev/ic/ac97.c: revision 1.97 via patch
sys/dev/pci/azalia_codec.c: revision 1.81 via patch
Mixer device bounds checking.
Analysis by Ilja van Sprundel.
 1.95.12.1.2.1 09-Aug-2017  snj Pull up following revision(s) (requested by nat in ticket #1460):
sys/dev/auconv.c: revision 1.30 via patch
sys/dev/ic/ac97.c: revision 1.97 via patch
sys/dev/pci/azalia_codec.c: revision 1.81 via patch
Mixer device bounds checking.
Analysis by Ilja van Sprundel.
 1.96.10.1 01-Aug-2017  snj Pull up following revision(s) (requested by nat in ticket #166):
sys/dev/auconv.c: revision 1.30
sys/dev/audio.c: revision 1.372
sys/dev/ic/ac97.c: revision 1.97
sys/dev/pci/azalia_codec.c: revision 1.81
Mixer device bounds checking.
Analysis by Ilja van Sprundel.
 1.97.8.1 04-May-2019  isaki Move dev/audio_if.h -> dev/audio/audio_if.h
 1.97.4.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.97.4.1 10-Jun-2019  christos Sync with HEAD
 1.2 15-May-2000  thorpej ac97.h -> ac97var.h
 1.1 27-Oct-1999  augustss branches: 1.1.4; 1.1.6;
Add AC97 mixer/codec support. From OpenBSD and FreeBSD.
 1.1.6.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.1.4.2 15-Nov-1999  fvdl Sync with -current
 1.1.4.1 27-Oct-1999  fvdl file ac97.h was added on branch fvdl-softdep on 1999-11-15 00:40:22 +0000
 1.14 09-Apr-2018  jmcneill Add AC-link slot assignment definitions.
 1.13 11-Dec-2005  christos branches: 1.13.162;
merge ktrace-lwp.
 1.12 08-Apr-2005  jmcneill Add AC'97 1.x 'Modem Line Codec support' capability bit definition.
 1.11 04-Apr-2005  jmcneill * Add more AC97 modem registers (from AC'97 revision 2.2)
* Add sysctls to control the modem's off-hook status (work in progress)
 1.10 04-Apr-2005  jmcneill * Add support for skipping either the modem or audio AC'97 probes
via host_flags: AC97_HOST_SKIP_AUDIO, AC97_HOST_SKIP_MODEM
* If we're dealing with a modem codec, print the extended modem
capabilities.
* Add basic AC'97 modem initialization support.
* Add some (but not all) AC'97 modem registers. More will be added later.
 1.9 07-Sep-2003  kent branches: 1.9.8;
Use bitmask_snprintf() for printing ext id features.
 1.8 12-Oct-2002  kent branches: 1.8.6;
Correct spelling. VENDER -> VENDOR
 1.7 12-Oct-2002  kent Add AC97_CAPS_* and AC97_VENDER_ID_MASK from OpenBSD.
 1.6 06-Oct-2002  kent Add some constant symbols for AC97 registers and values based on OpenBSD.
Rename some symbols to sync with OpenBSD:
AC97_REG_EXTENDED_ID
-> AC97_REG_EXT_AUDIO_ID
AC97_REG_EXTENDED_STATUS
-> AC97_REG_EXT_AUDIO_CTRL
AC97_CODEC_DOES_VRA/AC97_ENAB_VRA
-> AC97_EXT_AUDIO_VRA
AC97_CODEC_DOES_MICVRA/AC97_ENAB_MICVRA
-> AC97_EXT_AUDIO_VRM

ac97feature: "mic channel" -> "dedicated mic channel"
ac97_attach(): print extended capabilities; VRA, DRA, SPDIF, VRM, CDAC,
SDAC, LDAC.
 1.5 06-Oct-2002  kent Correct MICVRA values: 0x0004 -> 0x0008
 1.4 02-Feb-2002  augustss Make auich support variable rate codec, and suspend/resume.
From URA Hiroshi in PR kern/15431 (partly from OpenBSD).
 1.3 05-Jan-2001  augustss branches: 1.3.2; 1.3.4;
Add definitions for some bits in ID and STATUS regs.
 1.2 28-Nov-2000  thorpej Define additional AC'97 registers.
 1.1 15-May-2000  thorpej branches: 1.1.4; 1.1.6;
Move register definitions into ac97reg.h
 1.1.6.4 05-Jan-2001  bouyer Sync with HEAD
 1.1.6.3 08-Dec-2000  bouyer Sync with HEAD.
 1.1.6.2 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.1.6.1 15-May-2000  bouyer file ac97reg.h was added on branch thorpej_scsipi on 2000-11-20 11:40:03 +0000
 1.1.4.1 24-Jan-2002  he Pull up revisions 1.2-1.3 (requested by he):
Add driver for the ESS Allegro-1 / Maestro-3 audio hardware.
 1.3.4.1 11-Feb-2002  jdolecek Sync w/ -current.
 1.3.2.2 18-Oct-2002  nathanw Catch up to -current.
 1.3.2.1 28-Feb-2002  nathanw Catch up to -current.
 1.8.6.4 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.8.6.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.8.6.2 18-Sep-2004  skrll Sync with HEAD.
 1.8.6.1 03-Aug-2004  skrll Sync with HEAD
 1.9.8.1 29-Apr-2005  kent sync with -current
 1.13.162.1 16-Apr-2018  pgoyette Sync with HEAD, resolve some conflicts
 1.23 27-Oct-2012  chs split device_t/softc for all remaining drivers.
replace "struct device *" with "device_t".
use device_xname(), device_unit(), etc.
 1.22 23-Nov-2011  jmcneill branches: 1.22.8;
Merge jmcneill-audiomp3 branch, which is derived from ad-audiomp2. From
the original ad-audiomp branch notes:

Add MP locking to the audio drivers.

Making the audio drivers MP safe is necessary before efforts
can be made to make the VM system MP safe.

The are two locks per device instance, an ISR lock and
a character device lock. The ISR lock replaces calls to
splaudio()/splx(), and will be held across calls to device
methods which were called at splaudio() before (e.g.
trigger_output). The character device lock is held across
calls to nearly all of the methods, excluding some only
used for initialization, e.g. get_locks.

Welcome to 5.99.57.
 1.21 12-May-2009  cegger branches: 1.21.12; 1.21.14;
struct device * -> device_t, no functional changes intended.
 1.20 21-Feb-2007  thorpej branches: 1.20.2; 1.20.42; 1.20.56; 1.20.58;
Replace the Mach-derived boolean_t type with the C99 bool type. A
future commit will replace use of TRUE and FALSE with true and false.
 1.19 26-Jul-2006  kent branches: 1.19.10;
add capability to support for S/PDIF.
If a codec supports for AC'97 S/PDIF, it will have an mixer "spdif.enable."
However, we can't change the value of the mixer without AC'97 host
driver's support.
 1.18 15-Apr-2006  jmcneill * Add a flag AC97_HOST_INVERTED_EAMP. (kern/18880, kern/24488).
* Make reset callback optional; not all devices need it. (port-i386/14260, kern/12603, kern/12723, kern/24957).
 1.17 11-Dec-2005  christos branches: 1.17.4; 1.17.6; 1.17.8; 1.17.10; 1.17.12;
merge ktrace-lwp.
 1.16 11-Apr-2005  jmcneill branches: 1.16.2;
Add ac97_attach_type(), to allow the hw driver to skip probes for audio or
modem devices. ac97_attach now calls ac97_attach_type() with
AC97_CODEC_TYPE_AUDIO, for backwords compatibility.
 1.15 04-Apr-2005  jmcneill * Add support for skipping either the modem or audio AC'97 probes
via host_flags: AC97_HOST_SKIP_AUDIO, AC97_HOST_SKIP_MODEM
* If we're dealing with a modem codec, print the extended modem
capabilities.
* Add basic AC'97 modem initialization support.
* Add some (but not all) AC'97 modem registers. More will be added later.
 1.14 10-Jan-2005  kent branches: 1.14.2;
merge kent-audio1 branch, which introduces audio filter pipeline to the MI
audio framework


Summary of changes:

* struct audio_params
- remove sw_code, factor, factor_denom, hw_sample_rate,
hw_encoding ,hw_precision, and hw_channels. Conversion information
is conveyed by stream_filter_list_t.
- change the type of sample_rate: u_long -> u_int
- add `validbits,' which represents the valid data size in
precision bits. It is required in order to distinguish 24/32bit
from 24/24bit or 32/32bit.

* audio_hw_if
- add two parameters to set_params()
stream_filter_list_t *pfil, stream_filter_list *rfil
A HW driver should set filter recipes for requested formats
- constify audio_params parameters of trigger_output() and
trigger_input(). They represent audio formats for the hardware.
- make open() and close() optional
- add int (AUMODE_PLAY or AUMODE_RECORD) and audio_params_t parameters
to round_blocksize()

* sw_code is replaced with stream_filter_t.
stream_filer_t converts audio data in an input buffer and writes
into another output buffer unlike sw_code, which converts data in
single buffer.
converters in dev/auconv.c, dev/mulaw.c, dev/aurateconv.c,
dev/tc/bba.c, dev/ic/msm6258.c, and arch/arm/iomd/vidcaudio.c are
reimplemented as stream_filter_t

* MI audio
- audiosetinfo() builds filter pipelines from stream_filter_list_t
filled by audio_hw_if::set_params()
- audiosetinfo() returns with EINVAL if mmapped and set_params()
requests filters
- audio_write(), audio_pint(), and audio_rint() invoke a filter
pipeline.
- ioctl() for FIONREAD, AUDIO_WSEEK, AUDIO_GETIOFFS,
AUDIO_GETOOFFS, and audio_prinfo::{seek,samples} for
AUDIO_GETINFO handle values for a buffer nearest to userland.

* add `struct device *' parameter to ac97_attach()

* all of audio HW drivers follow audio_hw_if and ac97 changes
 1.13 22-Dec-2004  reinoud Add convenience macro AC97_HAS_SPDIF to check if SPDIF output is supported
in the codec in the line of AC97_IS_4CH and AC97_IS_FIXED_RATE macro's.
 1.12 10-Nov-2004  kent branches: 1.12.2;
move IS_FIXED_RATE(), SUPPORTS_4CH(), and SUPPORTS_6CH to ac97var.h
 1.11 08-Nov-2004  kent - nuke __P()
- add ac97_codec_if_vtbl::detach()
 1.10 22-Sep-2004  kent ac97_host_if::reset() returns non-zero value if codec reset fails, and
ac97 is not attached in that case.

PR: kern/26973
 1.9 23-Aug-2004  thorpej Protect against multiple inclusion.
 1.8 08-Jul-2003  itojun branches: 1.8.2;
function prototype must not have variable name
 1.7 14-Oct-2002  kent branches: 1.7.6;
Mixer changes:
- Add "outputs.surround", "outputs.center", and "outputs.lfe"
- If the codec is not capable of a feature, mixer variables
about the feature is not created. For example, no
"outputs.tone" for a codec without tone control.
- Set the following mixer values in ac97_attach():
outputs.master=127,127
outputs.master.mute=off
outputs.headphones.mute=off
outputs.surround=127,127
outputs.surround.mute=off
outputs.center=127
outputs.center.mute=off
outputs.lfe=127
outputs.lfe.mute=off
inputs.dac.mute=off
inputs.cd.mute=off
inputs.line.mute=off
inputs.aux.mute=off
inputs.video.mute=off
record.volume.mute=off
because the default setting of AC'97 codec (all mutes are on,
and maximum volume) is troublesome.
- Make "char*" parameters of ac97_get_portnum_by_name() "const char*"

Codec ID changes:
- If a codec ID is unknown but its vendor ID is known,
ac97_attach() prints the vendor name like "dev0: <vendor name>
unknown (0xXXXXXXXX) codec;"
- Add IDs of Asahi Kasei AK4542, AK4544, AK4544A, AK4545,
Realtek ALC100
- Correct a vendor name: "Advance Logic" -> "Avance Logic"
- Add capability of codec-specific initialization

ac97_attach():
- CDAC, SDAC, and LDAC are eanabled.
- DELAY() before mixer settings. ThinkPad X24 needs it.

ALC650 codec specific change:
- Add "outputs.surround.lineinjack" to switch the line-in jack
to the surround output
- Add "outputs.center.micjack" and "outputs.lfe.micjack" (alias
of "outputs.center.micjack") to switch the mic jack to the
center/lfe output.
 1.6 08-Oct-2002  kent Add IDs for YMF743-S and YMF753-S.

ac97_attach(): Enable VRA/VRM if the codec is capable of them.

The struct ac97_softc keeps the clock of the codec, the basic
features flag (the value of AC97_REG_RESET), and the extended
features flag (the value of AC97_REG_EXT_AUDIO_ID).

ac97_codec_if: Add get_extcaps(), set_rate(), and set_clock()
methods.
 1.5 31-Dec-2001  thorpej Move the declaration of an enum to avoid an "unnamed field not allowed"
warning in gcc 3.1.
 1.4 07-May-2001  lukem branches: 1.4.2;
delint
 1.3 09-Jan-2001  rh branches: 1.3.2;
Add new AC97_HOST_SWAPPED_CHANNELS host flag that causes left and right
mixer channels to be swapped (required for hardware that has wiring
reversed).
 1.2 04-Nov-2000  thorpej branches: 1.2.2;
Shadow the AC'97 codec registers. This adds two capabilities:
* support devices that crash when reading the codec registers; a flags
interface is added to the host interface and one flag is defined
(AC97_HOST_DONT_READ).
* new API (restore_ports) for restoring the user's settings. This
can be useful after an APM resume after a suspend to disk.

From OpenBSD.
 1.1 15-May-2000  thorpej branches: 1.1.4;
ac97.h -> ac97var.h
 1.1.4.1 03-May-2001  he Pull up revisions 1.2-1.3 (requested by skrll):
Add a driver for the ESS Technology Maestro-1/2/2E AC97 audio chips,
ES1968 and ES1978.
 1.2.2.4 18-Jan-2001  bouyer Sync with head (for UBC+NFS fixes, mostly).
 1.2.2.3 22-Nov-2000  bouyer Sync with HEAD.
 1.2.2.2 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.2.2.1 04-Nov-2000  bouyer file ac97var.h was added on branch thorpej_scsipi on 2000-11-20 11:40:03 +0000
 1.3.2.3 18-Oct-2002  nathanw Catch up to -current.
 1.3.2.2 08-Jan-2002  nathanw Catch up to -current.
 1.3.2.1 21-Jun-2001  nathanw Catch up to -current.
 1.4.2.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.7.6.8 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.7.6.7 17-Jan-2005  skrll Sync with HEAD.
 1.7.6.6 14-Nov-2004  skrll Sync with HEAD.
 1.7.6.5 24-Sep-2004  skrll Sync with HEAD.
 1.7.6.4 21-Sep-2004  skrll Fix the sync with head I botched.
 1.7.6.3 18-Sep-2004  skrll Sync with HEAD.
 1.7.6.2 25-Aug-2004  skrll Sync with HEAD.
 1.7.6.1 03-Aug-2004  skrll Sync with HEAD
 1.8.2.1 22-Sep-2004  jmc Pullup rev 1.10 (requested by kent in ticket #867)

ac97_host_if::reset() returns non-zero value if codec reset fails, and
ac97 is not attached in that case. PR#26973
 1.12.2.1 02-Jan-2005  kent * add "struct device *" parameter to ac97_attach() as discussion in tech-kern
* change the type of sampling rate parameter of ac97_set_rate():
u_long * -> u_int *
* other cosmetic changes
 1.14.2.1 29-Apr-2005  kent sync with -current
 1.16.2.3 26-Feb-2007  yamt sync with head.
 1.16.2.2 30-Dec-2006  yamt sync with head.
 1.16.2.1 21-Jun-2006  yamt sync with head.
 1.17.12.1 24-May-2006  tron Merge 2006-05-24 NetBSD-current into the "peter-altq" branch.
 1.17.10.1 19-Apr-2006  elad sync with head.
 1.17.8.2 11-Aug-2006  yamt sync with head
 1.17.8.1 24-May-2006  yamt sync with head.
 1.17.6.1 22-Apr-2006  simonb Sync with head.
 1.17.4.1 09-Sep-2006  rpaulo sync with head
 1.19.10.1 27-Feb-2007  yamt - sync with head.
- move sched_changepri back to kern_synch.c as it doesn't know PPQ anymore.
 1.20.58.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.20.56.1 07-Dec-2008  ad Ressurect the ad-audiomp branch at request of matt@.

With this commit:

- core audio subsystem made MPSAFE
- eap, btsco drivers made MPSAFE

TODO:

- midi
- convert remaining drivers
 1.20.42.1 16-May-2009  yamt sync with head
 1.20.2.1 27-Feb-2007  ad Add MP locking for audio drivers.
 1.21.14.1 19-Nov-2011  jmcneill port ad-audiomp2 branch changes to 5.99.56
todo:
- port ad-audiomp2 pcppi changes
- these drivers need to be fixed:
- emuxki
- gcscaudio
- hdafg
- uaudio
- umidi
- MD audio drivers
 1.21.12.2 30-Oct-2012  yamt sync with head
 1.21.12.1 17-Apr-2012  yamt sync with head
 1.22.8.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.8 18-Aug-2009  dyoung Let us detach ichlpcib(4) and its children.

XXX More testing is needed. I've tested this on a Dell Dimension 3000,
XXX but that system does not attach every possible device that I try to
XXX detach with this code:

ichlpcib0 at pci0 dev 31 function 0
ichlpcib0: vendor 0x8086 product 0x24d0 (rev. 0x02)
timecounter: Timecounter "ichlpcib0" frequency 3579545 Hz quality 1000
ichlpcib0: 24-bit timer
ichlpcib0: TCO (watchdog) timer configured.
isa0 at ichlpcib0
 1.7 12-May-2009  cegger struct device * -> device_t, no functional changes intended.
 1.6 08-Apr-2008  cegger branches: 1.6.4; 1.6.18;
use aprint_*_dev and device_xname
 1.5 20-Jan-2008  joerg branches: 1.5.6;
Now that __HAVE_TIMECOUNTER and __HAVE_GENERIC_TODR are invariants,
remove the conditionals and the code associated with the undef case.
 1.4 19-Oct-2007  ad branches: 1.4.2; 1.4.8;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.3 27-Aug-2007  xtraeme branches: 1.3.2; 1.3.6;
Add missing __KERNEL_RCSID().
 1.2 27-Aug-2007  xtraeme Cosmetic: "device %d-bit timer" -> "device: %d-bit timer".
 1.1 26-Jun-2006  drochner branches: 1.1.2; 1.1.6; 1.1.10; 1.1.16; 1.1.22; 1.1.32; 1.1.36;
add some common code to support the ACPI power management timer
independly of ACPI
 1.1.36.2 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.1.36.1 03-Sep-2007  jmcneill Sync with HEAD.
 1.1.32.1 03-Sep-2007  skrll Sync with HEAD.
 1.1.22.2 23-Oct-2007  ad Sync with head.
 1.1.22.1 09-Oct-2007  ad Sync with head.
 1.1.16.5 21-Jan-2008  yamt sync with head
 1.1.16.4 27-Oct-2007  yamt sync with head.
 1.1.16.3 03-Sep-2007  yamt sync with head.
 1.1.16.2 30-Dec-2006  yamt sync with head.
 1.1.16.1 26-Jun-2006  yamt file acpipmtimer.c was added on branch yamt-lazymbuf on 2006-12-30 20:48:00 +0000
 1.1.10.2 09-Sep-2006  rpaulo sync with head
 1.1.10.1 26-Jun-2006  rpaulo file acpipmtimer.c was added on branch rpaulo-netinet-merge-pcb on 2006-09-09 02:50:00 +0000
 1.1.6.2 11-Aug-2006  yamt sync with head
 1.1.6.1 26-Jun-2006  yamt file acpipmtimer.c was added on branch yamt-pdpolicy on 2006-08-11 15:44:10 +0000
 1.1.2.2 13-Jul-2006  gdamore Merge from HEAD.
 1.1.2.1 26-Jun-2006  gdamore file acpipmtimer.c was added on branch gdamore-uart on 2006-07-13 17:49:22 +0000
 1.3.6.1 25-Oct-2007  bouyer Sync with HEAD.
 1.3.2.2 23-Mar-2008  matt sync with HEAD
 1.3.2.1 06-Nov-2007  matt sync with HEAD
 1.4.8.1 23-Jan-2008  bouyer Sync with HEAD.
 1.4.2.1 18-Feb-2008  mjf Sync with HEAD.
 1.5.6.1 02-Jun-2008  mjf Sync with HEAD.
 1.6.18.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.6.4.2 19-Aug-2009  yamt sync with head.
 1.6.4.1 16-May-2009  yamt sync with head
 1.3 18-Aug-2009  dyoung Let us detach ichlpcib(4) and its children.

XXX More testing is needed. I've tested this on a Dell Dimension 3000,
XXX but that system does not attach every possible device that I try to
XXX detach with this code:

ichlpcib0 at pci0 dev 31 function 0
ichlpcib0: vendor 0x8086 product 0x24d0 (rev. 0x02)
timecounter: Timecounter "ichlpcib0" frequency 3579545 Hz quality 1000
ichlpcib0: 24-bit timer
ichlpcib0: TCO (watchdog) timer configured.
isa0 at ichlpcib0
 1.2 12-May-2009  cegger struct device * -> device_t, no functional changes intended.
 1.1 26-Jun-2006  drochner branches: 1.1.2; 1.1.6; 1.1.10; 1.1.16; 1.1.66; 1.1.82;
add some common code to support the ACPI power management timer
independly of ACPI
 1.1.82.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.1.66.2 19-Aug-2009  yamt sync with head.
 1.1.66.1 16-May-2009  yamt sync with head
 1.1.16.2 30-Dec-2006  yamt sync with head.
 1.1.16.1 26-Jun-2006  yamt file acpipmtimer.h was added on branch yamt-lazymbuf on 2006-12-30 20:48:01 +0000
 1.1.10.2 09-Sep-2006  rpaulo sync with head
 1.1.10.1 26-Jun-2006  rpaulo file acpipmtimer.h was added on branch rpaulo-netinet-merge-pcb on 2006-09-09 02:50:00 +0000
 1.1.6.2 11-Aug-2006  yamt sync with head
 1.1.6.1 26-Jun-2006  yamt file acpipmtimer.h was added on branch yamt-pdpolicy on 2006-08-11 15:44:10 +0000
 1.1.2.2 13-Jul-2006  gdamore Merge from HEAD.
 1.1.2.1 26-Jun-2006  gdamore file acpipmtimer.h was added on branch gdamore-uart on 2006-07-13 17:49:22 +0000
 1.1 13-Apr-2007  jmcneill branches: 1.1.2; 1.1.4; 1.1.6; 1.1.16;
Add AD1843 codec register defenitions, from OpenBSD.
 1.1.16.2 03-Sep-2007  yamt sync with head.
 1.1.16.1 13-Apr-2007  yamt file ad1843reg.h was added on branch yamt-lazymbuf on 2007-09-03 14:34:11 +0000
 1.1.6.2 11-Jul-2007  mjf Sync with head.
 1.1.6.1 13-Apr-2007  mjf file ad1843reg.h was added on branch mjf-ufs-trans on 2007-07-11 20:05:37 +0000
 1.1.4.2 09-Jun-2007  ad Sync with head.
 1.1.4.1 13-Apr-2007  ad file ad1843reg.h was added on branch vmlocking on 2007-06-09 21:37:12 +0000
 1.1.2.2 15-Apr-2007  yamt sync with head.
 1.1.2.1 13-Apr-2007  yamt file ad1843reg.h was added on branch yamt-idlelwp on 2007-04-15 16:03:21 +0000
 1.34 09-Feb-2024  andvar fix spelling mistakes, mainly in comments and log messages.
 1.33 29-Feb-2020  isaki Remove rounding by 4 bytes on round_blocksize().
For drivers which supports only 16bit * 2channels sampling,
rounding by 4 bytes no longer meaningful.
 1.32 08-May-2019  isaki branches: 1.32.4;
Merge isaki-audio2 branch, the overhaul of audio subsystem.
- Interrupt-oriented system rather than thread-oriented.
- Improve stability, quality and performance.
- Split playback and record cleanly. Improve halfduplex support.
- Many bugs are fixed including deadlocks, resource leaks, abuses, etc.
- Simplify audio filter mechanism. The encoding/channels/frequency
conversions are completely handled in the upper layer. So the hard-
ware driver only converts its hardware encoding (if necessary).
- audio_hw_if changes:
- Obsoletes query_encoding and add query_format instead.
- Obsoletes set_params and add set_format instead.
- Remove drain, setfd, mappage.
- The call sequences are changed.
- ioctl AUDIO_GETFD/SETFD, AUDIO_GETCHAN/SETCHAN are obsoleted.
- ioctl AUDIO_{QUERY,GET,SET}FORMAT are introduced.
- cleanup config attributes: au*conv and mulaw.
- All hardware drivers should follow it (I've done as much as possible).

Some file paths are changed:
- dev/audio.c -> dev/audio/audio.c (rewritten)
- dev/audiovar.h -> dev/audio/audiovar.h
- dev/audio_dai.h -> dev/audio/audio_dai.h
- dev/audio_if.h -> dev/audio/audio_if.h
- dev/audiobell.c -> dev/audio/audiobell.c
- dev/audiobellvar.h -> dev/audio/audiobellvar.h
- dev/mulaw.[ch] -> dev/audio/mulaw.[ch] + dev/audio/alaw.c
 1.31 23-Nov-2011  jmcneill branches: 1.31.50; 1.31.54;
Merge jmcneill-audiomp3 branch, which is derived from ad-audiomp2. From
the original ad-audiomp branch notes:

Add MP locking to the audio drivers.

Making the audio drivers MP safe is necessary before efforts
can be made to make the VM system MP safe.

The are two locks per device instance, an ISR lock and
a character device lock. The ISR lock replaces calls to
splaudio()/splx(), and will be held across calls to device
methods which were called at splaudio() before (e.g.
trigger_output). The character device lock is held across
calls to nearly all of the methods, excluding some only
used for initialization, e.g. get_locks.

Welcome to 5.99.57.
 1.30 27-Apr-2011  plunky branches: 1.30.4; 1.30.6;
drop 'external' inline here, to avoid C99 vs GNU differences
 1.29 28-Apr-2008  martin branches: 1.29.12; 1.29.22; 1.29.28;
Remove clause 3 and 4 from TNF licenses
 1.28 28-Apr-2008  garbled Minor fixes to some of these files:
Add recognition for the CS4232C revision chip. (0xa2)
Make ic/ad1848.c compile with AUDIO_DEBUG
Add a needed machine/bus.h include to ic/cs4231.c
Add a few additional register defines to ic/cs4231reg.h
 1.27 11-Dec-2007  martin branches: 1.27.8; 1.27.10; 1.27.12;
const'ify ad1848 devmap.
 1.26 19-Oct-2007  ad branches: 1.26.4; 1.26.6; 1.26.8;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.25 16-Nov-2006  christos branches: 1.25.8; 1.25.22; 1.25.24; 1.25.28;
__unused removal on arguments; approved by core.
 1.24 12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.23 03-Sep-2006  christos branches: 1.23.2; 1.23.4;
avoid empty if statements
 1.22 24-Dec-2005  perry branches: 1.22.4; 1.22.8;
Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.21 11-Dec-2005  christos merge ktrace-lwp.
 1.20 15-Jan-2005  kent branches: 1.20.10;
ansify and KNF
 1.19 10-Jan-2005  kent merge kent-audio1 branch, which introduces audio filter pipeline to the MI
audio framework


Summary of changes:

* struct audio_params
- remove sw_code, factor, factor_denom, hw_sample_rate,
hw_encoding ,hw_precision, and hw_channels. Conversion information
is conveyed by stream_filter_list_t.
- change the type of sample_rate: u_long -> u_int
- add `validbits,' which represents the valid data size in
precision bits. It is required in order to distinguish 24/32bit
from 24/24bit or 32/32bit.

* audio_hw_if
- add two parameters to set_params()
stream_filter_list_t *pfil, stream_filter_list *rfil
A HW driver should set filter recipes for requested formats
- constify audio_params parameters of trigger_output() and
trigger_input(). They represent audio formats for the hardware.
- make open() and close() optional
- add int (AUMODE_PLAY or AUMODE_RECORD) and audio_params_t parameters
to round_blocksize()

* sw_code is replaced with stream_filter_t.
stream_filer_t converts audio data in an input buffer and writes
into another output buffer unlike sw_code, which converts data in
single buffer.
converters in dev/auconv.c, dev/mulaw.c, dev/aurateconv.c,
dev/tc/bba.c, dev/ic/msm6258.c, and arch/arm/iomd/vidcaudio.c are
reimplemented as stream_filter_t

* MI audio
- audiosetinfo() builds filter pipelines from stream_filter_list_t
filled by audio_hw_if::set_params()
- audiosetinfo() returns with EINVAL if mmapped and set_params()
requests filters
- audio_write(), audio_pint(), and audio_rint() invoke a filter
pipeline.
- ioctl() for FIONREAD, AUDIO_WSEEK, AUDIO_GETIOFFS,
AUDIO_GETOOFFS, and audio_prinfo::{seek,samples} for
AUDIO_GETINFO handle values for a buffer nearest to userland.

* add `struct device *' parameter to ac97_attach()

* all of audio HW drivers follow audio_hw_if and ac97 changes
 1.18 24-Aug-2004  thorpej branches: 1.18.2;
Use ANSI function decls and more use of static.
 1.17 21-Feb-2003  tsutsui branches: 1.17.2;
hz -> Hz
 1.16 06-Jan-2003  wiz synchronous, not syncronous.
 1.15 22-Aug-2002  martin Add a mixerctl to mute the internal (mono) speaker via
"mixerctl -w monitor.mono=off".

From Sung-Won Chung, slightly modified. All errors by me.
 1.14 23-Mar-2002  itohy branches: 1.14.2;
Add wait-for-ready code between setting MCE and changing data format,
which is required by OPL3-SA2 (YMF711) chip.
Fixes PR kern/14819.
 1.13 06-Mar-2002  itohy Fix ADPCM playback/recording.
 1.12 13-Nov-2001  lukem add/cleanup RCSID
 1.11 04-Nov-2001  itohy AD1845 on my AlphaStation 255 doesn't match the AD1845 doc.
Try to detect AD1845 (unfortunately this is not always correct)
and work around the problems.
 1.10 18-Jan-2001  jdolecek branches: 1.10.2; 1.10.4; 1.10.8;
constify
 1.9 01-Nov-1999  augustss branches: 1.9.6;
Make little endian and big endian version of all functions
that deal with 16 bit samples. Let the drivers decide which ones
to use.
 1.8 12-Oct-1999  thorpej branches: 1.8.2; 1.8.4;
Bound one auto-calibration loop that was missed in previous rounds of
changes.

Yay, audio on my Dell laptop works again.
 1.7 05-Oct-1999  itohy branches: 1.7.2;
- Fix wait for ready code.
- Mute wave output, not the mixer output, on changing CODEC settings.
- Add support for muting wave output while playback or monitoring is inactive.
- Change formula of calculating gain so that all the levels should be
used equally (the old code uses the min/max gain only at 0/255).
- Cleanup
 1.6 06-Sep-1999  rh Add mode 3 support for newer CS423X chips. Modify probe to correctly
distinguish between CS4236, CS4236B, and CS4237B.
 1.5 18-Feb-1999  mycroft Add separate halt_input and halt_output methods in ad1848_isa, which disable
the DMA channel.
 1.4 17-Feb-1999  mycroft Use the trigger interface, and clean up a pile of cruft.
 1.3 27-Aug-1998  pk Move a few prototypes.
Whitespace cleanup.
 1.2 26-Aug-1998  pk debug level 0
 1.1 25-Aug-1998  pk The new MI part of the AD1848 driver.
 1.7.2.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.8.4.1 15-Nov-1999  fvdl Sync with -current
 1.8.2.2 11-Feb-2001  bouyer Sync with HEAD.
 1.8.2.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.9.6.1 27-Mar-2002  he Pull up revisions 1.10-1.14 (requested by itohy):
Several changes to wss-compatible audio devices:
o Fix ADPCM playback/recording
o Add explicit support for OPL3-SA2 (YMF711), fixes PR#14819
o Add AD1845 support
o other minor bugfixes and cleanups
 1.10.8.1 12-Nov-2001  thorpej Sync the thorpej-mips-cache branch with -current.
 1.10.4.4 06-Sep-2002  jdolecek sync kqueue branch with HEAD
 1.10.4.3 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.10.4.2 16-Mar-2002  jdolecek Catch up with -current.
 1.10.4.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.10.2.4 07-Jan-2003  thorpej Sync with HEAD.
 1.10.2.3 27-Aug-2002  nathanw Catch up to -current.
 1.10.2.2 01-Apr-2002  nathanw Catch up to -current.
(CVS: It's not just a program. It's an adventure!)
 1.10.2.1 14-Nov-2001  nathanw Catch up to -current.
 1.14.2.1 29-Aug-2002  gehenna catch up with -current.
 1.17.2.4 17-Jan-2005  skrll Sync with HEAD.
 1.17.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.17.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.17.2.1 25-Aug-2004  skrll Sync with HEAD.
 1.18.2.3 09-Jan-2005  kent audio_hw_if change
* make open() and close() optional
* add int (AUMODE_PLAY or AUMODE_RECORD) and audio_params_t parameters
to round_blocksize()
 1.18.2.2 03-Jan-2005  kent * remove stream_filter_list_append and stream_filter_list_prepend
* add stream_filter_list_t::{append(), prepend(), set()}
 1.18.2.1 03-Jan-2005  kent * adopt the filter pipeline framework

* ic/ad1848.c, isa/ess.c, isa/sbdsp.c
remove direct call of set_params() for the default encoding.
It should be called by the MI audio framework.
 1.20.10.4 21-Jan-2008  yamt sync with head
 1.20.10.3 27-Oct-2007  yamt sync with head.
 1.20.10.2 30-Dec-2006  yamt sync with head.
 1.20.10.1 21-Jun-2006  yamt sync with head.
 1.22.8.1 03-Sep-2006  yamt sync with head.
 1.22.4.1 09-Sep-2006  rpaulo sync with head
 1.23.4.2 10-Dec-2006  yamt sync with head.
 1.23.4.1 22-Oct-2006  yamt sync with head
 1.23.2.1 18-Nov-2006  ad Sync with head.
 1.25.28.1 25-Oct-2007  bouyer Sync with HEAD.
 1.25.24.2 09-Jan-2008  matt sync with HEAD
 1.25.24.1 06-Nov-2007  matt sync with HEAD
 1.25.22.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.25.8.1 23-Oct-2007  ad Sync with head.
 1.26.8.1 13-Dec-2007  bouyer Sync with HEAD
 1.26.6.1 11-Dec-2007  yamt sync with head.
 1.26.4.1 26-Dec-2007  ad Sync with head.
 1.27.12.1 16-May-2008  yamt sync with head.
 1.27.10.1 18-May-2008  yamt sync with head.
 1.27.8.1 02-Jun-2008  mjf Sync with HEAD.
 1.29.28.1 06-Jun-2011  jruoho Sync with HEAD.
 1.29.22.1 31-May-2011  rmind sync with head
 1.29.12.2 12-Dec-2008  ad Checkpoint work in progress.
 1.29.12.1 11-Dec-2008  ad Checkpoint work in progress.
 1.30.6.1 19-Nov-2011  jmcneill port ad-audiomp2 branch changes to 5.99.56
todo:
- port ad-audiomp2 pcppi changes
- these drivers need to be fixed:
- emuxki
- gcscaudio
- hdafg
- uaudio
- umidi
- MD audio drivers
 1.30.4.1 17-Apr-2012  yamt sync with head
 1.31.54.2 04-May-2019  isaki Move dev/audio_if.h -> dev/audio/audio_if.h
 1.31.54.1 21-Apr-2019  isaki Adapt ad1848/cs4231 families to audio2.
 1.31.50.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.31.50.1 10-Jun-2019  christos Sync with HEAD
 1.32.4.1 29-Feb-2020  ad Sync with head.
 1.10 06-Apr-2003  wiz Respect the law: Use A-law and mu-law as spellings as far as easily possible.
Inspired by Igor Sobrado in PR 19680.
 1.9 30-Sep-1999  itohy Fix MIX_ATTEN_MASK value so that monitoring should work correctly.
 1.8 06-Sep-1999  rh Add mode 3 support for newer CS423X chips. Modify probe to correctly
distinguish between CS4236, CS4236B, and CS4237B.
 1.7 27-Aug-1998  pk Add selected `%b' bits.
 1.6 27-Aug-1998  pk Add missing entries and make it slightly more verbose.
 1.5 28-Jul-1998  augustss Fix obsolete code in waiting for calibration on the ad1848.
(Sigh, the ad1848 driver should be rewritten.)
 1.4 07-May-1997  augustss Oops, forgot this in previous commit.
 1.3 19-Mar-1997  mikel normalize off-by-four ad1848 register offsets.
 1.2 13-Mar-1997  mikel fix various AD1848/PSS misfeatures; from Jason Baker in PR kern/2045.
also did some misc cleanup of my own.
 1.1 07-Jul-1995  brezak add support for cs4231
 1.20 29-Feb-2020  isaki Remove rounding by 4 bytes on round_blocksize().
For drivers which supports only 16bit * 2channels sampling,
rounding by 4 bytes no longer meaningful.
 1.19 08-May-2019  isaki branches: 1.19.4;
Merge isaki-audio2 branch, the overhaul of audio subsystem.
- Interrupt-oriented system rather than thread-oriented.
- Improve stability, quality and performance.
- Split playback and record cleanly. Improve halfduplex support.
- Many bugs are fixed including deadlocks, resource leaks, abuses, etc.
- Simplify audio filter mechanism. The encoding/channels/frequency
conversions are completely handled in the upper layer. So the hard-
ware driver only converts its hardware encoding (if necessary).
- audio_hw_if changes:
- Obsoletes query_encoding and add query_format instead.
- Obsoletes set_params and add set_format instead.
- Remove drain, setfd, mappage.
- The call sequences are changed.
- ioctl AUDIO_GETFD/SETFD, AUDIO_GETCHAN/SETCHAN are obsoleted.
- ioctl AUDIO_{QUERY,GET,SET}FORMAT are introduced.
- cleanup config attributes: au*conv and mulaw.
- All hardware drivers should follow it (I've done as much as possible).

Some file paths are changed:
- dev/audio.c -> dev/audio/audio.c (rewritten)
- dev/audiovar.h -> dev/audio/audiovar.h
- dev/audio_dai.h -> dev/audio/audio_dai.h
- dev/audio_if.h -> dev/audio/audio_if.h
- dev/audiobell.c -> dev/audio/audiobell.c
- dev/audiobellvar.h -> dev/audio/audiobellvar.h
- dev/mulaw.[ch] -> dev/audio/mulaw.[ch] + dev/audio/alaw.c
 1.18 23-Nov-2011  jmcneill branches: 1.18.50; 1.18.54;
Merge jmcneill-audiomp3 branch, which is derived from ad-audiomp2. From
the original ad-audiomp branch notes:

Add MP locking to the audio drivers.

Making the audio drivers MP safe is necessary before efforts
can be made to make the VM system MP safe.

The are two locks per device instance, an ISR lock and
a character device lock. The ISR lock replaces calls to
splaudio()/splx(), and will be held across calls to device
methods which were called at splaudio() before (e.g.
trigger_output). The character device lock is held across
calls to nearly all of the methods, excluding some only
used for initialization, e.g. get_locks.

Welcome to 5.99.57.
 1.17 02-Jun-2011  christos branches: 1.17.2; 1.17.4;
split audiocs
 1.16 28-Apr-2008  martin branches: 1.16.12; 1.16.22; 1.16.28; 1.16.32;
Remove clause 3 and 4 from TNF licenses
 1.15 11-Dec-2007  martin branches: 1.15.8; 1.15.10; 1.15.12;
const'ify ad1848 devmap.
 1.14 11-Dec-2005  christos branches: 1.14.28; 1.14.46; 1.14.56; 1.14.58; 1.14.60;
merge ktrace-lwp.
 1.13 29-May-2005  christos branches: 1.13.2;
- sprinkle const.
- avoid variable shadowing.
 1.12 15-Jan-2005  kent ansify and KNF
 1.11 10-Jan-2005  kent merge kent-audio1 branch, which introduces audio filter pipeline to the MI
audio framework


Summary of changes:

* struct audio_params
- remove sw_code, factor, factor_denom, hw_sample_rate,
hw_encoding ,hw_precision, and hw_channels. Conversion information
is conveyed by stream_filter_list_t.
- change the type of sample_rate: u_long -> u_int
- add `validbits,' which represents the valid data size in
precision bits. It is required in order to distinguish 24/32bit
from 24/24bit or 32/32bit.

* audio_hw_if
- add two parameters to set_params()
stream_filter_list_t *pfil, stream_filter_list *rfil
A HW driver should set filter recipes for requested formats
- constify audio_params parameters of trigger_output() and
trigger_input(). They represent audio formats for the hardware.
- make open() and close() optional
- add int (AUMODE_PLAY or AUMODE_RECORD) and audio_params_t parameters
to round_blocksize()

* sw_code is replaced with stream_filter_t.
stream_filer_t converts audio data in an input buffer and writes
into another output buffer unlike sw_code, which converts data in
single buffer.
converters in dev/auconv.c, dev/mulaw.c, dev/aurateconv.c,
dev/tc/bba.c, dev/ic/msm6258.c, and arch/arm/iomd/vidcaudio.c are
reimplemented as stream_filter_t

* MI audio
- audiosetinfo() builds filter pipelines from stream_filter_list_t
filled by audio_hw_if::set_params()
- audiosetinfo() returns with EINVAL if mmapped and set_params()
requests filters
- audio_write(), audio_pint(), and audio_rint() invoke a filter
pipeline.
- ioctl() for FIONREAD, AUDIO_WSEEK, AUDIO_GETIOFFS,
AUDIO_GETOOFFS, and audio_prinfo::{seek,samples} for
AUDIO_GETINFO handle values for a buffer nearest to userland.

* add `struct device *' parameter to ac97_attach()

* all of audio HW drivers follow audio_hw_if and ac97 changes
 1.10 26-Aug-2002  martin branches: 1.10.6; 1.10.10;
Give arrays in the softc indexed by channel number the right size
and define a symbolic name for the number of channels.
 1.9 22-Aug-2002  martin Add a mixerctl to mute the internal (mono) speaker via
"mixerctl -w monitor.mono=off".

From Sung-Won Chung, slightly modified. All errors by me.
 1.8 04-Nov-2001  itohy branches: 1.8.8;
AD1845 on my AlphaStation 255 doesn't match the AD1845 doc.
Try to detect AD1845 (unfortunately this is not always correct)
and work around the problems.
 1.7 26-Jun-2000  simonb branches: 1.7.2; 1.7.4; 1.7.8;
Change the kernel mmap interface so that the offset to map is an
"off_t" and the return value is a "paddr_t" to allow mappings
at offsets past 2^31 bytes. Somewhat inspired by FreeBSD, which
only changed the offset to a "vm_offset_t".

Includes updates for the i386, pc532 and sh3 mmmmap from Jason Thorpe.
 1.6 05-Oct-1999  itohy branches: 1.6.2; 1.6.12;
Add support for muting wave output while playback or monitoring is inactive.
Cleanup.
 1.5 06-Sep-1999  rh Add mode 3 support for newer CS423X chips. Modify probe to correctly
distinguish between CS4236, CS4236B, and CS4237B.
 1.4 18-Feb-1999  mycroft Add separate halt_input and halt_output methods in ad1848_isa, which disable
the DMA channel.
 1.3 17-Feb-1999  mycroft Use the trigger interface, and clean up a pile of cruft.
 1.2 27-Aug-1998  pk Move a few prototypes.
Whitespace cleanup.
 1.1 25-Aug-1998  pk The new MI part of the AD1848 driver.
 1.6.12.2 27-Mar-2002  he Pull up revision 1.8 (requested by itohy):
Several changes to wss-compatible audio devices:
o Fix ADPCM playback/recording
o Add explicit support for OPL3-SA2 (YMF711), fixes PR#14819
o Add AD1845 support
o other minor bugfixes and cleanups
 1.6.12.1 30-Jun-2000  simonb Pull up mmap paddr_t/off_t changes from trunk.
 1.6.2.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.7.8.1 12-Nov-2001  thorpej Sync the thorpej-mips-cache branch with -current.
 1.7.4.2 06-Sep-2002  jdolecek sync kqueue branch with HEAD
 1.7.4.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.7.2.2 27-Aug-2002  nathanw Catch up to -current.
 1.7.2.1 14-Nov-2001  nathanw Catch up to -current.
 1.8.8.1 29-Aug-2002  gehenna catch up with -current.
 1.10.10.2 09-Jan-2005  kent audio_hw_if change
* make open() and close() optional
* add int (AUMODE_PLAY or AUMODE_RECORD) and audio_params_t parameters
to round_blocksize()
 1.10.10.1 03-Jan-2005  kent * adopt the filter pipeline framework

* ic/ad1848.c, isa/ess.c, isa/sbdsp.c
remove direct call of set_params() for the default encoding.
It should be called by the MI audio framework.
 1.10.6.2 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.10.6.1 17-Jan-2005  skrll Sync with HEAD.
 1.13.2.1 21-Jan-2008  yamt sync with head
 1.14.60.1 13-Dec-2007  bouyer Sync with HEAD
 1.14.58.1 11-Dec-2007  yamt sync with head.
 1.14.56.1 26-Dec-2007  ad Sync with head.
 1.14.46.1 09-Jan-2008  matt sync with HEAD
 1.14.28.1 27-Feb-2007  ad Add MP locking for audio drivers.
 1.15.12.1 16-May-2008  yamt sync with head.
 1.15.10.1 18-May-2008  yamt sync with head.
 1.15.8.1 02-Jun-2008  mjf Sync with HEAD.
 1.16.32.1 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.16.28.1 06-Jun-2011  jruoho Sync with HEAD.
 1.16.22.1 12-Jun-2011  rmind sync with head
 1.16.12.2 12-Dec-2008  ad Checkpoint work in progress.
 1.16.12.1 11-Dec-2008  ad Checkpoint work in progress.
 1.17.4.1 19-Nov-2011  jmcneill port ad-audiomp2 branch changes to 5.99.56
todo:
- port ad-audiomp2 pcppi changes
- these drivers need to be fixed:
- emuxki
- gcscaudio
- hdafg
- uaudio
- umidi
- MD audio drivers
 1.17.2.1 17-Apr-2012  yamt sync with head
 1.18.54.2 04-May-2019  isaki Remove obsoleted methods in audio_hw_if.
- drain: is handled in audio upper layer now.
- mappage: is handled in audio upper layer now.
- setfd: no one uses and it's meaningless now.
 1.18.54.1 21-Apr-2019  isaki Adapt ad1848/cs4231 families to audio2.
 1.18.50.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.18.50.1 10-Jun-2019  christos Sync with HEAD
 1.19.4.1 29-Feb-2020  ad Sync with head.
 1.53 25-Sep-2022  thorpej Remove unnecessary include of <sys/malloc.h>.
 1.52 07-Aug-2021  thorpej Merge thorpej-cfargs2.
 1.51 24-Apr-2021  thorpej branches: 1.51.8;
Merge thorpej-cfargs branch:

Simplify and make extensible the config_search() / config_found() /
config_attach() interfaces: rather than having different variants for
which arguments you want pass along, just have a single call that
takes a variadic list of tag-value arguments.

Adjust all call sites:
- Simplify wherever possible; don't pass along arguments that aren't
actually needed.
- Don't be explicit about what interface attribute is attaching if
the device only has one. (More simplification.)
- Add a config_probe() function to be used in indirect configuiration
situations, making is visibly easier to see when indirect config is
in play, and allowing for future change in semantics. (As of now,
this is just a wrapper around config_match(), but that is an
implementation detail.)

Remove unnecessary or redundant interface attributes where they're not
needed.

There are currently 5 "cfargs" defined:
- CFARG_SUBMATCH (submatch function for direct config)
- CFARG_SEARCH (search function for indirect config)
- CFARG_IATTR (interface attribte)
- CFARG_LOCATORS (locators array)
- CFARG_DEVHANDLE (devhandle_t - wraps OFW, ACPI, etc. handles)

...and a sentinel value CFARG_EOL.

Add some extra sanity checking to ensure that interface attributes
aren't ambiguous.

Use CFARG_DEVHANDLE in MI FDT, OFW, and ACPI code, and macppc and shark
ports to associate those device handles with device_t instance. This
will trickle trough to more places over time (need back-end for pre-OFW
Sun OBP; any others?).
 1.50 15-Dec-2019  tsutsui branches: 1.50.10;
Remove clause 3 and 4 leftovers from TNF licenses in more sources.

Confirmed by martin@ in PR/54760.
 1.49 06-Oct-2019  uwe Get rid of bogus ASC_CALLBACK typedef. Use the real callback type
(which is almost ASC_ISR_CALLBACK). Since we no longer need the
casting dance we can get rid of the temporary variables, and since we
don't need the temporary variables we don't need the ASC_ISR_CALLBACK
typedef either. Found by gcc8 -Wcast-function-type.
 1.48 29-Aug-2018  rin branches: 1.48.6;
Note added for a strange value of residual counts in successful read/write.
Seems like a H/W bug. The best thing we can do would be to leave the code as is.

No binary changes.
 1.47 14-Jul-2016  msaitoh branches: 1.47.16; 1.47.18;
KNF. No functional change.
 1.46 27-Oct-2012  chs branches: 1.46.14;
split device_t/softc for all remaining drivers.
replace "struct device *" with "device_t".
use device_xname(), device_unit(), etc.
 1.45 13-Nov-2010  uebayasi branches: 1.45.8; 1.45.18;
Don't pull in the whole uvm(9) API to access only PAGE_SIZE and
some other constants. These are provided by sys/param.h now.
 1.44 23-Nov-2009  rmind branches: 1.44.4;
Remove some unecessary includes sys/user.h header.
 1.43 14-Mar-2009  dsl Change about 4500 of the K&R function definitions to ANSI ones.
There are still about 1600 left, but they have ',' or /* ... */
in the actual variable definitions - which my awk script doesn't handle.
There are also many that need () -> (void).
(The script does handle misordered arguments.)
 1.42 08-Apr-2008  cegger branches: 1.42.4; 1.42.12; 1.42.18;
use aprint_*_dev and device_xname
 1.41 19-Oct-2007  ad branches: 1.41.16;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.40 09-Jul-2007  ad branches: 1.40.6; 1.40.8; 1.40.12;
Merge some of the less invasive changes from the vmlocking branch:

- kthread, callout, devsw API changes
- select()/poll() improvements
- miscellaneous MT safety improvements
 1.39 04-Mar-2007  christos branches: 1.39.2; 1.39.4;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.38 17-Aug-2006  christos branches: 1.38.8;
Fix all the -D*DEBUG* code that it was rotting away and did not even compile.
Mostly from Arnaud Lacombe, many thanks!
 1.37 11-Dec-2005  christos branches: 1.37.4; 1.37.8;
merge ktrace-lwp.
 1.36 27-Feb-2005  perry branches: 1.36.4;
nuke trailing whitespace
 1.35 21-Feb-2005  thorpej Part 1 of a cleanup pass over the SCSI subsystem. The aim is to name
everything "scsi_*", since we really are talking about the SCSI command
set, ATAPI transport not withstanding. Improve the names of many structures,
and prepend "SCSI_" onto all SCSI command opcodes. Place items described
by the SCSI Primary Commands document into scsi_spc.h.
 1.34 04-Feb-2005  perry de-__P
 1.33 03-May-2003  wiz branches: 1.33.2; 1.33.10; 1.33.12;
DMA, not dma nor Dma.
 1.32 31-Jan-2003  thorpej Use aprint_*().
 1.31 05-Apr-2002  bouyer Implement mstohz() as discussed on tech-kern, and use it in SCSI drivers
to convert xs->timeout to callout() parameter.
 1.30 15-Nov-2001  lukem don't need <sys/types.h> when including <sys/param.h>
 1.29 13-Nov-2001  lukem add/cleanup RCSID
 1.28 19-Jul-2001  thorpej Use BUS_DMA_READ and BUS_DMA_WRITE in some obvious places.
 1.27 07-Jul-2001  thorpej branches: 1.27.2;
bzero -> memset
 1.26 09-Jun-2001  briggs If the adapter is returning a selection timeout, then we should be
returning XS_SELTIMEOUT, not XS_TIMEOUT. Pointed out by Andrew Doran.
 1.25 09-Jun-2001  briggs Patches from takashi.yamamoto@bigfoot.com in kern/13139.
- Set XS_TIMEOUT on a selection timeout condition.
- Do not bother to call AscStartChip() in AscResetChipAndScsiBus()--
just clear the chip status.
- Make sure address is word-aligned in AscWriteLramByte().

Tested on my adv (AdvanSys ABP-9xxUA) with CRW8424S and UMAX SuperVista S-12.
Earlier versions of the system would get stuck trying to recover from error
conditions when the CD-RW drive was in heavy use. I have not seen that
behavior with these small patches.
 1.24 25-Apr-2001  bouyer Pull up the thorpej_scsipi branch to main branch.
This is a completely rewritten scsipi_xfer execution engine, and the
associated changes to HBA drivers. Overview of changes & features:
- All xfers are queued in the mid-layer, rather than doing so in an
ad-hoc fashion in individual adapter drivers.
- Adapter/channel resource management in the mid-layer, avoids even trying
to start running an xfer if the adapter/channel doesn't have the resources.
- Better communication between the mid-layer and the adapters.
- Asynchronous event notification mechanism from adapter to mid-layer and
peripherals.
- Better peripheral queue management: freeze/thaw, sorted requeueing during
recovery, etc.
- Clean separation of peripherals, adapters, and adapter channels (no more
scsipi_link).
- Kernel thread for each scsipi_channel makes error recovery much easier
(no more dealing with interrupt context when recovering from an error).
- Mid-layer support for tagged queueing: commands can have the tag type
set explicitly, tag IDs are allocated in the mid-layer (thus eliminating
the need to use buggy tag ID allocation schemes in many adapter drivers).
- support for QUEUE FULL and CHECK CONDITION status in mid-layer; the command
will be requeued, or a REQUEST SENSE will be sent as appropriate.

Just before the merge syssrc has been tagged with thorpej_scsipi_beforemerge
 1.23 27-Mar-2001  bouyer Cast to u_int64_t when computing callout argument, to avoid int overflow.
Fixes kern/12471.
 1.22 08-Mar-2001  thorpej Preliminary support for detaching an "adv" instance. This
could use some more work.

Derived from kern/12341, takashi.yamamoto@bigfoot.com.
 1.21 07-Mar-2001  thorpej Add BUS_DMA_STREAMING to data transfer maps.
 1.20 14-Nov-2000  thorpej branches: 1.20.2;
NBPG -> PAGE_SIZE
 1.19 11-Aug-2000  tls Make our policy WRT tagged queueing consistent and sane: ordered tags for sync writes, simple tags for all else. Should make ahc and adv a bit more reliable (metadata writes won't get reordered incorrectly...) and isp a bit more performant (it was using ordered tags all the time).
 1.18 28-Jun-2000  mrg remove include of <vm/vm.h>. <vm/vm.h> -> <uvm/uvm_extern.h>
 1.17 26-Jun-2000  mrg remove redundant vm includes.
 1.16 23-Mar-2000  thorpej branches: 1.16.4;
New callout mechanism with two major improvements over the old
timeout()/untimeout() API:
- Clients supply callout handle storage, thus eliminating problems of
resource allocation.
- Insertion and removal of callouts is constant time, important as
this facility is used quite a lot in the kernel.

The old timeout()/untimeout() API has been removed from the kernel.
 1.15 12-Feb-2000  thorpej If we got an xfer from our backlog queue, don't allow sleeping; we're in
interrupt context.

XXX This is fixed properly in the thorpej_scsipi branch, but that won't
be ready for 1.5, I don't think.
 1.14 30-Sep-1999  thorpej branches: 1.14.2;
Update for SCSPI changes.
 1.13 07-Aug-1999  thorpej Fix a problem uncovered by attempting to compile on the Alpha: overrun_buf
was being initialized to a KVA, when we really wanted a DMA address. Change
the code to allocate the overrun buffer with the control blocks, and
properly initialize overrun_buf.

Note that overrun_buf cannot actually be shared between all boards; DMA safe
memory could vary from bus to bus.

Garbage-collect two functions which are no longer used because of the
above changes.
 1.12 06-Jun-1999  dante Add support for ISA, EISA and ISApnp cards
Fixed a bus reset bug which shows on arm32
 1.11 04-Mar-1999  dante branches: 1.11.4;
fix second level interrupt handler to allow 64 bits pointers
 1.10 25-Feb-1999  dante Fix AdvanSys Narrow driver to work on Alpha
 1.9 09-Dec-1998  thorpej Update for changed scsipi_xfer struct.
 1.8 05-Dec-1998  mjacob Update HBAs to incorporate the new max_lun property.
 1.7 19-Nov-1998  thorpej Adapt to the new scsipi_adapter interface.
 1.6 28-Oct-1998  dante Add support for macppc.
Very special thanks to Itsumi Tsutsui for his invaluable collaboration.
 1.5 10-Oct-1998  thorpej Garbage-collect the open_target_lu and close_target_lu entry points from
struct scsipi_adapter; they were not used.

Add a scsipi_ioctl entry point to struct scsipi_adapter. This will be
used to issue ioctl commands to the host adapters.

Inspired by PR #6090, from Matt Jacob.
 1.4 26-Sep-1998  dante Remove Wide boards references
Adjust copyright

At this time this driver support the following AdvanSys boards:
- ABP-9xx
- ABP-9xxU
- ABP-9xxUA
 1.3 09-Sep-1998  thorpej Protect Debugger() call a'la uha driver. PR #6070, Gary D. Duzan.
 1.2 29-Aug-1998  dante Add rcs id
 1.1 26-Aug-1998  dante Add AdvanSys 930U and 940U SCSI controllers
 1.11.4.1 21-Jun-1999  thorpej Sync w/ -current.
 1.14.2.9 21-Apr-2001  bouyer Sync with HEAD
 1.14.2.8 12-Mar-2001  bouyer Sync with HEAD.
 1.14.2.7 15-Jan-2001  bouyer req_sense_length is dead.
 1.14.2.6 22-Nov-2000  bouyer Sync with HEAD.
 1.14.2.5 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.14.2.4 26-Oct-1999  thorpej Update for:

Deal a little more gracefully with the fact that xfer mode parameters
are for the I_T Nexus, and make all xfer mode updates `async events'.
 1.14.2.3 20-Oct-1999  thorpej Eliminate sleeping from adapter routines.
 1.14.2.2 19-Oct-1999  thorpej Don't sleep waiting for a CCB; if we get to the CCB allocation phase, we're
guaranteed to have one.
 1.14.2.1 19-Oct-1999  thorpej Adapt to scsipi API changes.
 1.16.4.1 11-Aug-2000  tls Pull up tagged queueing policy changes: now we use ordered tags for sync writes, simple tags for reads and async writes.
 1.20.2.6 17-Apr-2002  nathanw Catch up to -current.
 1.20.2.5 08-Jan-2002  nathanw Catch up to -current.
 1.20.2.4 14-Nov-2001  nathanw Catch up to -current.
 1.20.2.3 24-Aug-2001  nathanw Catch up with -current.
 1.20.2.2 21-Jun-2001  nathanw Catch up to -current.
 1.20.2.1 09-Apr-2001  nathanw Catch up with -current.
 1.27.2.3 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.27.2.2 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.27.2.1 03-Aug-2001  lukem update to -current
 1.33.12.2 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.33.12.1 12-Feb-2005  yamt sync with head.
 1.33.10.1 29-Apr-2005  kent sync with -current
 1.33.2.2 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.33.2.1 04-Feb-2005  skrll Sync with HEAD.
 1.36.4.3 27-Oct-2007  yamt sync with head.
 1.36.4.2 03-Sep-2007  yamt sync with head.
 1.36.4.1 30-Dec-2006  yamt sync with head.
 1.37.8.1 03-Sep-2006  yamt sync with head.
 1.37.4.1 09-Sep-2006  rpaulo sync with head
 1.38.8.1 12-Mar-2007  rmind Sync with HEAD.
 1.39.4.1 11-Jul-2007  mjf Sync with head.
 1.39.2.2 23-Oct-2007  ad Sync with head.
 1.39.2.1 01-Jul-2007  ad Adapt to callout API change.
 1.40.12.1 25-Oct-2007  bouyer Sync with HEAD.
 1.40.8.1 06-Nov-2007  matt sync with HEAD
 1.40.6.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.41.16.1 02-Jun-2008  mjf Sync with HEAD.
 1.42.18.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.42.12.1 28-Apr-2009  skrll Sync with HEAD.
 1.42.4.2 11-Mar-2010  yamt sync with head
 1.42.4.1 04-May-2009  yamt sync with head.
 1.44.4.1 05-Mar-2011  rmind sync with head
 1.45.18.2 03-Dec-2017  jdolecek update from HEAD
 1.45.18.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.45.8.1 30-Oct-2012  yamt sync with head
 1.46.14.1 05-Oct-2016  skrll Sync with HEAD
 1.47.18.3 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.47.18.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.47.18.1 10-Jun-2019  christos Sync with HEAD
 1.47.16.1 06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.48.6.1 18-Dec-2019  martin Pull up following revision(s) (requested by tsutsui in ticket #570):

sys/compat/netbsd32/netbsd32_compat_50_sysv.c: revision 1.3
sys/dev/raidframe/rf_compat50.h: revision 1.6
sys/arch/emips/emips/bus_space.c: revision 1.3
sys/compat/net/if.h: revision 1.5
sys/arch/emips/stand/common/bootinfo.c: revision 1.2
sys/compat/common/sysv_msg_50.c: revision 1.5
sys/compat/common/kern_time_30.c: revision 1.8
sys/arch/emips/stand/common/bootinfo.h: revision 1.2
sys/arch/ia64/include/bus.h: revision 1.4
sys/arch/ia64/ia64/bus_space.c: revision 1.2
sys/compat/common/sysv_shm_50.c: revision 1.5
sys/dev/ic/adw.h: revision 1.15
sys/compat/common/uipc_syscalls_50.c: revision 1.10
sys/arch/emips/ebus/flash_ebus.c: revision 1.22
sys/dev/ic/adv.h: revision 1.15
sys/dev/ic/adwmcode.c: revision 1.18
sys/dev/ic/advlib.c: revision 1.29
sys/arch/hpcarm/include/kloader.h: revision 1.3
sys/dev/usb/uberry.c: revision 1.16
sys/compat/common/sysv_sem_50.c: revision 1.5
sys/compat/netbsd32/netbsd32_compat_50.c: revision 1.43
sys/dev/ic/advlib.h: revision 1.21
sys/dev/ic/adv.c: revision 1.50
sys/compat/netinet6/in6_var.h: revision 1.5
sys/arch/hpc/stand/hpcboot/arm/arm_sa1100_asm.asm: revision 1.2
sys/arch/emips/include/loadfile_machdep.h: revision 1.3
sys/arch/emips/stand/common/prom_iface.c: revision 1.7
sys/dev/ic/adw.c: revision 1.56
sys/dev/ic/adwmcode.h: revision 1.12
sys/dev/ic/advmcode.c: revision 1.10
sys/arch/emips/ebus/ace_ebus.c: revision 1.22
sys/compat/netbsd32/netbsd32_compat_60.c: revision 1.5
sys/dev/raidframe/rf_compat50.c: revision 1.13
sys/arch/x68k/dev/intiovar.h: revision 1.15
sys/dev/usb/uipad.c: revision 1.8
sys/arch/zaurus/include/kloader.h: revision 1.3
sys/arch/emips/stand/common/bootxx.c: revision 1.2
sys/dev/ic/adwlib.h: revision 1.23
sys/dev/ic/adwlib.c: revision 1.44
sys/compat/netbsd32/netbsd32_compat_16.c: revision 1.3
sys/arch/amigappc/include/intr.h: revision 1.27
sys/arch/x68k/dev/mfp.c: revision 1.27
sys/arch/arm/at91/at91dbgu.c: revision 1.17
sys/dev/ic/advmcode.h: revision 1.7
sys/compat/ultrix/ultrix_exec.h: revision 1.7
sys/compat/common/vfs_syscalls_50.c: revision 1.24
sys/arch/mips/cavium/octeon_dma.c: revision 1.3
sys/arch/hpc/stand/hpcboot/arm/arm_pxa2x0_asm.asm: revision 1.2

Remove clause 3 and 4 from TNF licenses.
Ok'ed by martin@ in PR/54760.

Remove clause 3 and 4 leftovers from TNF licenses in more sources.
Confirmed by martin@ in PR/54760.
 1.50.10.1 21-Mar-2021  thorpej Give config_found() the same variadic arguments treatment as
config_search(). This commit only adds the CFARG_EOL sentinel
to the existing config_found() calls. Conversion of config_found_sm_loc()
and config_found_ia() call sites will be in subsequent commits.
 1.51.8.1 04-Aug-2021  thorpej Adapt to CFARGS().
 1.1 20-Nov-2000  bouyer branches: 1.1.2;
file adv.c.orig was initially added on branch thorpej_scsipi.
 1.1.2.2 20-Nov-2000  bouyer Ops, these shouldn't be there !
 1.1.2.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.15 15-Dec-2019  tsutsui Remove clause 3 and 4 leftovers from TNF licenses in more sources.

Confirmed by martin@ in PR/54760.
 1.14 06-Oct-2019  uwe Get rid of bogus ASC_CALLBACK typedef. Use the real callback type
(which is almost ASC_ISR_CALLBACK). Since we no longer need the
casting dance we can get rid of the temporary variables, and since we
don't need the temporary variables we don't need the ASC_ISR_CALLBACK
typedef either. Found by gcc8 -Wcast-function-type.
 1.13 11-Dec-2005  christos branches: 1.13.164; 1.13.170;
merge ktrace-lwp.
 1.12 27-Feb-2005  perry nuke trailing whitespace
 1.11 21-Feb-2005  thorpej Part 1 of a cleanup pass over the SCSI subsystem. The aim is to name
everything "scsi_*", since we really are talking about the SCSI command
set, ATAPI transport not withstanding. Improve the names of many structures,
and prepend "SCSI_" onto all SCSI command opcodes. Place items described
by the SCSI Primary Commands document into scsi_spc.h.
 1.10 04-Feb-2005  perry de-__P
 1.9 08-Jul-2003  itojun branches: 1.9.8; 1.9.10;
function prototype must not have variable name
 1.8 08-Mar-2001  thorpej branches: 1.8.22;
Preliminary support for detaching an "adv" instance. This
could use some more work.

Derived from kern/12341, takashi.yamamoto@bigfoot.com.
 1.7 23-Mar-2000  thorpej branches: 1.7.6;
New callout mechanism with two major improvements over the old
timeout()/untimeout() API:
- Clients supply callout handle storage, thus eliminating problems of
resource allocation.
- Insertion and removal of callouts is constant time, important as
this facility is used quite a lot in the kernel.

The old timeout()/untimeout() API has been removed from the kernel.
 1.6 07-Aug-1999  thorpej branches: 1.6.2;
Fix a problem uncovered by attempting to compile on the Alpha: overrun_buf
was being initialized to a KVA, when we really wanted a DMA address. Change
the code to allocate the overrun buffer with the control blocks, and
properly initialize overrun_buf.

Note that overrun_buf cannot actually be shared between all boards; DMA safe
memory could vary from bus to bus.

Garbage-collect two functions which are no longer used because of the
above changes.
 1.5 04-Mar-1999  dante fix second level interrupt handler to allow 64 bits pointers
 1.4 25-Feb-1999  dante Fix AdvanSys Narrow driver to work on Alpha
 1.3 26-Sep-1998  dante Remove Wide boards references
Adjust copyright

At this time this driver support the following AdvanSys boards:
- ABP-9xx
- ABP-9xxU
- ABP-9xxUA
 1.2 29-Aug-1998  dante Add rcs id
 1.1 26-Aug-1998  dante Add AdvanSys 930U and 940U SCSI controllers
 1.6.2.2 12-Mar-2001  bouyer Sync with HEAD.
 1.6.2.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.7.6.1 09-Apr-2001  nathanw Catch up with -current.
 1.8.22.5 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.8.22.4 04-Feb-2005  skrll Sync with HEAD.
 1.8.22.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.8.22.2 18-Sep-2004  skrll Sync with HEAD.
 1.8.22.1 03-Aug-2004  skrll Sync with HEAD
 1.9.10.2 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.9.10.1 12-Feb-2005  yamt sync with head.
 1.9.8.1 29-Apr-2005  kent sync with -current
 1.13.170.1 18-Dec-2019  martin Pull up following revision(s) (requested by tsutsui in ticket #570):

sys/compat/netbsd32/netbsd32_compat_50_sysv.c: revision 1.3
sys/dev/raidframe/rf_compat50.h: revision 1.6
sys/arch/emips/emips/bus_space.c: revision 1.3
sys/compat/net/if.h: revision 1.5
sys/arch/emips/stand/common/bootinfo.c: revision 1.2
sys/compat/common/sysv_msg_50.c: revision 1.5
sys/compat/common/kern_time_30.c: revision 1.8
sys/arch/emips/stand/common/bootinfo.h: revision 1.2
sys/arch/ia64/include/bus.h: revision 1.4
sys/arch/ia64/ia64/bus_space.c: revision 1.2
sys/compat/common/sysv_shm_50.c: revision 1.5
sys/dev/ic/adw.h: revision 1.15
sys/compat/common/uipc_syscalls_50.c: revision 1.10
sys/arch/emips/ebus/flash_ebus.c: revision 1.22
sys/dev/ic/adv.h: revision 1.15
sys/dev/ic/adwmcode.c: revision 1.18
sys/dev/ic/advlib.c: revision 1.29
sys/arch/hpcarm/include/kloader.h: revision 1.3
sys/dev/usb/uberry.c: revision 1.16
sys/compat/common/sysv_sem_50.c: revision 1.5
sys/compat/netbsd32/netbsd32_compat_50.c: revision 1.43
sys/dev/ic/advlib.h: revision 1.21
sys/dev/ic/adv.c: revision 1.50
sys/compat/netinet6/in6_var.h: revision 1.5
sys/arch/hpc/stand/hpcboot/arm/arm_sa1100_asm.asm: revision 1.2
sys/arch/emips/include/loadfile_machdep.h: revision 1.3
sys/arch/emips/stand/common/prom_iface.c: revision 1.7
sys/dev/ic/adw.c: revision 1.56
sys/dev/ic/adwmcode.h: revision 1.12
sys/dev/ic/advmcode.c: revision 1.10
sys/arch/emips/ebus/ace_ebus.c: revision 1.22
sys/compat/netbsd32/netbsd32_compat_60.c: revision 1.5
sys/dev/raidframe/rf_compat50.c: revision 1.13
sys/arch/x68k/dev/intiovar.h: revision 1.15
sys/dev/usb/uipad.c: revision 1.8
sys/arch/zaurus/include/kloader.h: revision 1.3
sys/arch/emips/stand/common/bootxx.c: revision 1.2
sys/dev/ic/adwlib.h: revision 1.23
sys/dev/ic/adwlib.c: revision 1.44
sys/compat/netbsd32/netbsd32_compat_16.c: revision 1.3
sys/arch/amigappc/include/intr.h: revision 1.27
sys/arch/x68k/dev/mfp.c: revision 1.27
sys/arch/arm/at91/at91dbgu.c: revision 1.17
sys/dev/ic/advmcode.h: revision 1.7
sys/compat/ultrix/ultrix_exec.h: revision 1.7
sys/compat/common/vfs_syscalls_50.c: revision 1.24
sys/arch/mips/cavium/octeon_dma.c: revision 1.3
sys/arch/hpc/stand/hpcboot/arm/arm_pxa2x0_asm.asm: revision 1.2

Remove clause 3 and 4 from TNF licenses.
Ok'ed by martin@ in PR/54760.

Remove clause 3 and 4 leftovers from TNF licenses in more sources.
Confirmed by martin@ in PR/54760.
 1.13.164.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.13.164.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.31 24-May-2024  andvar s/borad/board/ in comments.
 1.30 25-Sep-2022  thorpej Remove unnecessary include of <sys/malloc.h>.
 1.29 15-Dec-2019  tsutsui Remove clause 3 and 4 leftovers from TNF licenses in more sources.

Confirmed by martin@ in PR/54760.
 1.28 06-Oct-2019  uwe Get rid of bogus ASC_CALLBACK typedef. Use the real callback type
(which is almost ASC_ISR_CALLBACK). Since we no longer need the
casting dance we can get rid of the temporary variables, and since we
don't need the temporary variables we don't need the ASC_ISR_CALLBACK
typedef either. Found by gcc8 -Wcast-function-type.
 1.27 13-Nov-2010  uebayasi branches: 1.27.60; 1.27.66;
Don't pull in the whole uvm(9) API to access only PAGE_SIZE and
some other constants. These are provided by sys/param.h now.
 1.26 19-Oct-2007  ad branches: 1.26.42;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.25 16-Nov-2006  christos branches: 1.25.8; 1.25.22; 1.25.24; 1.25.28;
__unused removal on arguments; approved by core.
 1.24 12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.23 11-Dec-2005  christos branches: 1.23.20; 1.23.22;
merge ktrace-lwp.
 1.22 31-May-2005  christos branches: 1.22.2;
avoid variable shadow.
 1.21 30-May-2005  christos - add missing const
- fix variable shadowing
- remove unneeded casts
 1.20 27-Feb-2005  perry nuke trailing whitespace
 1.19 02-Nov-2003  wiz branches: 1.19.8; 1.19.10;
Fix some typos. From Tom Cosgrove via jmc@openbsd.
 1.18 15-Nov-2001  lukem branches: 1.18.16;
don't need <sys/types.h> when including <sys/param.h>
 1.17 13-Nov-2001  lukem add/cleanup RCSID
 1.16 09-Jun-2001  briggs branches: 1.16.2;
Patches from takashi.yamamoto@bigfoot.com in kern/13139.
- Set XS_TIMEOUT on a selection timeout condition.
- Do not bother to call AscStartChip() in AscResetChipAndScsiBus()--
just clear the chip status.
- Make sure address is word-aligned in AscWriteLramByte().

Tested on my adv (AdvanSys ABP-9xxUA) with CRW8424S and UMAX SuperVista S-12.
Earlier versions of the system would get stuck trying to recover from error
conditions when the CD-RW drive was in heavy use. I have not seen that
behavior with these small patches.
 1.15 30-Apr-2001  lukem remove some lint, including ansifying funcs
 1.14 25-Apr-2001  bouyer Pull up the thorpej_scsipi branch to main branch.
This is a completely rewritten scsipi_xfer execution engine, and the
associated changes to HBA drivers. Overview of changes & features:
- All xfers are queued in the mid-layer, rather than doing so in an
ad-hoc fashion in individual adapter drivers.
- Adapter/channel resource management in the mid-layer, avoids even trying
to start running an xfer if the adapter/channel doesn't have the resources.
- Better communication between the mid-layer and the adapters.
- Asynchronous event notification mechanism from adapter to mid-layer and
peripherals.
- Better peripheral queue management: freeze/thaw, sorted requeueing during
recovery, etc.
- Clean separation of peripherals, adapters, and adapter channels (no more
scsipi_link).
- Kernel thread for each scsipi_channel makes error recovery much easier
(no more dealing with interrupt context when recovering from an error).
- Mid-layer support for tagged queueing: commands can have the tag type
set explicitly, tag IDs are allocated in the mid-layer (thus eliminating
the need to use buggy tag ID allocation schemes in many adapter drivers).
- support for QUEUE FULL and CHECK CONDITION status in mid-layer; the command
will be requeued, or a REQUEST SENSE will be sent as appropriate.

Just before the merge syssrc has been tagged with thorpej_scsipi_beforemerge
 1.13 28-Jun-2000  mrg branches: 1.13.2;
remove include of <vm/vm.h>. <vm/vm.h> -> <uvm/uvm_extern.h>
 1.12 26-Jun-2000  mrg remove redundant vm includes.
 1.11 07-Aug-1999  thorpej branches: 1.11.2;
Fix a problem uncovered by attempting to compile on the Alpha: overrun_buf
was being initialized to a KVA, when we really wanted a DMA address. Change
the code to allocate the overrun buffer with the control blocks, and
properly initialize overrun_buf.

Note that overrun_buf cannot actually be shared between all boards; DMA safe
memory could vary from bus to bus.

Garbage-collect two functions which are no longer used because of the
above changes.
 1.10 12-Jun-1999  dante Clean up some stuff
Remove chip version check
Now compile again on 68k based systems
 1.9 06-Jun-1999  dante Add support for ISA, EISA and ISApnp cards
Fixed a bus reset bug which shows on arm32
 1.8 25-Feb-1999  dante branches: 1.8.4;
Fix AdvanSys Narrow driver to work on Alpha
 1.7 28-Oct-1998  dante Add support for macppc.
Very special thanks to Itsumi Tsutsui for his invaluable collaboration.
 1.6 14-Oct-1998  dante Remove some debugging printf
 1.5 13-Oct-1998  dante Change the way uCode is loaded into board LRAM, to let it work on macppc.
 1.4 26-Sep-1998  dante Remove Wide boards references
Adjust copyright

At this time this driver support the following AdvanSys boards:
- ABP-9xx
- ABP-9xxU
- ABP-9xxUA
 1.3 29-Aug-1998  dante Add rcs id
 1.2 28-Aug-1998  thorpej Add braces to make egcs happy.
 1.1 26-Aug-1998  dante Add AdvanSys 930U and 940U SCSI controllers
 1.8.4.1 21-Jun-1999  thorpej Sync w/ -current.
 1.11.2.2 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.11.2.1 19-Oct-1999  thorpej Adapt to scsipi API changes.
 1.13.2.3 08-Jan-2002  nathanw Catch up to -current.
 1.13.2.2 14-Nov-2001  nathanw Catch up to -current.
 1.13.2.1 21-Jun-2001  nathanw Catch up to -current.
 1.16.2.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.18.16.5 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.18.16.4 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.18.16.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.18.16.2 18-Sep-2004  skrll Sync with HEAD.
 1.18.16.1 03-Aug-2004  skrll Sync with HEAD
 1.19.10.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.19.8.1 29-Apr-2005  kent sync with -current
 1.22.2.1 27-Oct-2007  yamt sync with head.
 1.23.22.2 10-Dec-2006  yamt sync with head.
 1.23.22.1 22-Oct-2006  yamt sync with head
 1.23.20.1 18-Nov-2006  ad Sync with head.
 1.25.28.1 25-Oct-2007  bouyer Sync with HEAD.
 1.25.24.1 06-Nov-2007  matt sync with HEAD
 1.25.22.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.25.8.1 23-Oct-2007  ad Sync with head.
 1.26.42.1 05-Mar-2011  rmind sync with head
 1.27.66.1 18-Dec-2019  martin Pull up following revision(s) (requested by tsutsui in ticket #570):

sys/compat/netbsd32/netbsd32_compat_50_sysv.c: revision 1.3
sys/dev/raidframe/rf_compat50.h: revision 1.6
sys/arch/emips/emips/bus_space.c: revision 1.3
sys/compat/net/if.h: revision 1.5
sys/arch/emips/stand/common/bootinfo.c: revision 1.2
sys/compat/common/sysv_msg_50.c: revision 1.5
sys/compat/common/kern_time_30.c: revision 1.8
sys/arch/emips/stand/common/bootinfo.h: revision 1.2
sys/arch/ia64/include/bus.h: revision 1.4
sys/arch/ia64/ia64/bus_space.c: revision 1.2
sys/compat/common/sysv_shm_50.c: revision 1.5
sys/dev/ic/adw.h: revision 1.15
sys/compat/common/uipc_syscalls_50.c: revision 1.10
sys/arch/emips/ebus/flash_ebus.c: revision 1.22
sys/dev/ic/adv.h: revision 1.15
sys/dev/ic/adwmcode.c: revision 1.18
sys/dev/ic/advlib.c: revision 1.29
sys/arch/hpcarm/include/kloader.h: revision 1.3
sys/dev/usb/uberry.c: revision 1.16
sys/compat/common/sysv_sem_50.c: revision 1.5
sys/compat/netbsd32/netbsd32_compat_50.c: revision 1.43
sys/dev/ic/advlib.h: revision 1.21
sys/dev/ic/adv.c: revision 1.50
sys/compat/netinet6/in6_var.h: revision 1.5
sys/arch/hpc/stand/hpcboot/arm/arm_sa1100_asm.asm: revision 1.2
sys/arch/emips/include/loadfile_machdep.h: revision 1.3
sys/arch/emips/stand/common/prom_iface.c: revision 1.7
sys/dev/ic/adw.c: revision 1.56
sys/dev/ic/adwmcode.h: revision 1.12
sys/dev/ic/advmcode.c: revision 1.10
sys/arch/emips/ebus/ace_ebus.c: revision 1.22
sys/compat/netbsd32/netbsd32_compat_60.c: revision 1.5
sys/dev/raidframe/rf_compat50.c: revision 1.13
sys/arch/x68k/dev/intiovar.h: revision 1.15
sys/dev/usb/uipad.c: revision 1.8
sys/arch/zaurus/include/kloader.h: revision 1.3
sys/arch/emips/stand/common/bootxx.c: revision 1.2
sys/dev/ic/adwlib.h: revision 1.23
sys/dev/ic/adwlib.c: revision 1.44
sys/compat/netbsd32/netbsd32_compat_16.c: revision 1.3
sys/arch/amigappc/include/intr.h: revision 1.27
sys/arch/x68k/dev/mfp.c: revision 1.27
sys/arch/arm/at91/at91dbgu.c: revision 1.17
sys/dev/ic/advmcode.h: revision 1.7
sys/compat/ultrix/ultrix_exec.h: revision 1.7
sys/compat/common/vfs_syscalls_50.c: revision 1.24
sys/arch/mips/cavium/octeon_dma.c: revision 1.3
sys/arch/hpc/stand/hpcboot/arm/arm_pxa2x0_asm.asm: revision 1.2

Remove clause 3 and 4 from TNF licenses.
Ok'ed by martin@ in PR/54760.

Remove clause 3 and 4 leftovers from TNF licenses in more sources.
Confirmed by martin@ in PR/54760.
 1.27.60.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.27.60.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.1 20-Nov-2000  bouyer branches: 1.1.2;
file advlib.c.orig was initially added on branch thorpej_scsipi.
 1.1.2.2 20-Nov-2000  bouyer Ops, these shouldn't be there !
 1.1.2.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.22 27-Dec-2019  msaitoh s/transef/transfer/ in comment.
 1.21 15-Dec-2019  tsutsui Remove clause 3 and 4 leftovers from TNF licenses in more sources.

Confirmed by martin@ in PR/54760.
 1.20 06-Oct-2019  uwe Get rid of bogus ASC_CALLBACK typedef. Use the real callback type
(which is almost ASC_ISR_CALLBACK). Since we no longer need the
casting dance we can get rid of the temporary variables, and since we
don't need the temporary variables we don't need the ASC_ISR_CALLBACK
typedef either. Found by gcc8 -Wcast-function-type.
 1.19 27-Oct-2012  chs branches: 1.19.38; 1.19.44;
split device_t/softc for all remaining drivers.
replace "struct device *" with "device_t".
use device_xname(), device_unit(), etc.
 1.18 24-Aug-2012  msaitoh branches: 1.18.2;
Fix typos
 1.17 11-Dec-2005  christos branches: 1.17.110;
merge ktrace-lwp.
 1.16 27-Feb-2005  perry nuke trailing whitespace
 1.15 04-Feb-2005  perry de-__P
 1.14 13-Feb-2004  wiz branches: 1.14.8; 1.14.10;
Spell length with h after t. Inspired by a commit by brad@openbsd.
 1.13 25-Apr-2001  bouyer branches: 1.13.22;
Pull up the thorpej_scsipi branch to main branch.
This is a completely rewritten scsipi_xfer execution engine, and the
associated changes to HBA drivers. Overview of changes & features:
- All xfers are queued in the mid-layer, rather than doing so in an
ad-hoc fashion in individual adapter drivers.
- Adapter/channel resource management in the mid-layer, avoids even trying
to start running an xfer if the adapter/channel doesn't have the resources.
- Better communication between the mid-layer and the adapters.
- Asynchronous event notification mechanism from adapter to mid-layer and
peripherals.
- Better peripheral queue management: freeze/thaw, sorted requeueing during
recovery, etc.
- Clean separation of peripherals, adapters, and adapter channels (no more
scsipi_link).
- Kernel thread for each scsipi_channel makes error recovery much easier
(no more dealing with interrupt context when recovering from an error).
- Mid-layer support for tagged queueing: commands can have the tag type
set explicitly, tag IDs are allocated in the mid-layer (thus eliminating
the need to use buggy tag ID allocation schemes in many adapter drivers).
- support for QUEUE FULL and CHECK CONDITION status in mid-layer; the command
will be requeued, or a REQUEST SENSE will be sent as appropriate.

Just before the merge syssrc has been tagged with thorpej_scsipi_beforemerge
 1.12 08-Mar-2001  thorpej Preliminary support for detaching an "adv" instance. This
could use some more work.

Derived from kern/12341, takashi.yamamoto@bigfoot.com.
 1.11 07-Aug-1999  thorpej branches: 1.11.2; 1.11.14;
Fix a problem uncovered by attempting to compile on the Alpha: overrun_buf
was being initialized to a KVA, when we really wanted a DMA address. Change
the code to allocate the overrun buffer with the control blocks, and
properly initialize overrun_buf.

Note that overrun_buf cannot actually be shared between all boards; DMA safe
memory could vary from bus to bus.

Garbage-collect two functions which are no longer used because of the
above changes.
 1.10 06-Jun-1999  dante Add support for ISA, EISA and ISApnp cards
Fixed a bus reset bug which shows on arm32
 1.9 04-Mar-1999  dante branches: 1.9.4;
fix second level interrupt handler to allow 64 bits pointers
 1.8 25-Feb-1999  dante Fix AdvanSys Narrow driver to work on Alpha
 1.7 09-Dec-1998  thorpej Update for changed scsipi_xfer struct.
 1.6 19-Nov-1998  thorpej Adapt to the new scsipi_adapter interface.
 1.5 28-Oct-1998  dante Add support for macppc.
Very special thanks to Itsumi Tsutsui for his invaluable collaboration.
 1.4 06-Oct-1998  dante Make AdvanSys narrow driver compile on BIG_ENDIAN machines.
Thanks to Izumi Tsutsui
 1.3 26-Sep-1998  dante Remove Wide boards references
Adjust copyright

At this time this driver support the following AdvanSys boards:
- ABP-9xx
- ABP-9xxU
- ABP-9xxUA
 1.2 29-Aug-1998  dante Add rcs id
 1.1 26-Aug-1998  dante Add AdvanSys 930U and 940U SCSI controllers
 1.9.4.1 21-Jun-1999  thorpej Sync w/ -current.
 1.11.14.2 21-Jun-2001  nathanw Catch up to -current.
 1.11.14.1 09-Apr-2001  nathanw Catch up with -current.
 1.11.2.2 12-Mar-2001  bouyer Sync with HEAD.
 1.11.2.1 19-Oct-1999  thorpej Adapt to scsipi API changes.
 1.13.22.5 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.13.22.4 04-Feb-2005  skrll Sync with HEAD.
 1.13.22.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.13.22.2 18-Sep-2004  skrll Sync with HEAD.
 1.13.22.1 03-Aug-2004  skrll Sync with HEAD
 1.14.10.2 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.14.10.1 12-Feb-2005  yamt sync with head.
 1.14.8.1 29-Apr-2005  kent sync with -current
 1.17.110.1 30-Oct-2012  yamt sync with head
 1.18.2.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.19.44.1 18-Dec-2019  martin Pull up following revision(s) (requested by tsutsui in ticket #570):

sys/compat/netbsd32/netbsd32_compat_50_sysv.c: revision 1.3
sys/dev/raidframe/rf_compat50.h: revision 1.6
sys/arch/emips/emips/bus_space.c: revision 1.3
sys/compat/net/if.h: revision 1.5
sys/arch/emips/stand/common/bootinfo.c: revision 1.2
sys/compat/common/sysv_msg_50.c: revision 1.5
sys/compat/common/kern_time_30.c: revision 1.8
sys/arch/emips/stand/common/bootinfo.h: revision 1.2
sys/arch/ia64/include/bus.h: revision 1.4
sys/arch/ia64/ia64/bus_space.c: revision 1.2
sys/compat/common/sysv_shm_50.c: revision 1.5
sys/dev/ic/adw.h: revision 1.15
sys/compat/common/uipc_syscalls_50.c: revision 1.10
sys/arch/emips/ebus/flash_ebus.c: revision 1.22
sys/dev/ic/adv.h: revision 1.15
sys/dev/ic/adwmcode.c: revision 1.18
sys/dev/ic/advlib.c: revision 1.29
sys/arch/hpcarm/include/kloader.h: revision 1.3
sys/dev/usb/uberry.c: revision 1.16
sys/compat/common/sysv_sem_50.c: revision 1.5
sys/compat/netbsd32/netbsd32_compat_50.c: revision 1.43
sys/dev/ic/advlib.h: revision 1.21
sys/dev/ic/adv.c: revision 1.50
sys/compat/netinet6/in6_var.h: revision 1.5
sys/arch/hpc/stand/hpcboot/arm/arm_sa1100_asm.asm: revision 1.2
sys/arch/emips/include/loadfile_machdep.h: revision 1.3
sys/arch/emips/stand/common/prom_iface.c: revision 1.7
sys/dev/ic/adw.c: revision 1.56
sys/dev/ic/adwmcode.h: revision 1.12
sys/dev/ic/advmcode.c: revision 1.10
sys/arch/emips/ebus/ace_ebus.c: revision 1.22
sys/compat/netbsd32/netbsd32_compat_60.c: revision 1.5
sys/dev/raidframe/rf_compat50.c: revision 1.13
sys/arch/x68k/dev/intiovar.h: revision 1.15
sys/dev/usb/uipad.c: revision 1.8
sys/arch/zaurus/include/kloader.h: revision 1.3
sys/arch/emips/stand/common/bootxx.c: revision 1.2
sys/dev/ic/adwlib.h: revision 1.23
sys/dev/ic/adwlib.c: revision 1.44
sys/compat/netbsd32/netbsd32_compat_16.c: revision 1.3
sys/arch/amigappc/include/intr.h: revision 1.27
sys/arch/x68k/dev/mfp.c: revision 1.27
sys/arch/arm/at91/at91dbgu.c: revision 1.17
sys/dev/ic/advmcode.h: revision 1.7
sys/compat/ultrix/ultrix_exec.h: revision 1.7
sys/compat/common/vfs_syscalls_50.c: revision 1.24
sys/arch/mips/cavium/octeon_dma.c: revision 1.3
sys/arch/hpc/stand/hpcboot/arm/arm_pxa2x0_asm.asm: revision 1.2

Remove clause 3 and 4 from TNF licenses.
Ok'ed by martin@ in PR/54760.

Remove clause 3 and 4 leftovers from TNF licenses in more sources.
Confirmed by martin@ in PR/54760.
 1.19.38.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.19.38.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.1 20-Nov-2000  bouyer branches: 1.1.2;
file advlib.h.orig was initially added on branch thorpej_scsipi.
 1.1.2.2 20-Nov-2000  bouyer Ops, these shouldn't be there !
 1.1.2.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.10 15-Dec-2019  tsutsui Remove clause 3 and 4 leftovers from TNF licenses in more sources.

Confirmed by martin@ in PR/54760.
 1.9 11-Dec-2005  christos branches: 1.9.164; 1.9.170;
merge ktrace-lwp.
 1.8 27-Feb-2005  perry nuke trailing whitespace
 1.7 13-Feb-2004  wiz branches: 1.7.8; 1.7.10;
Uppercase CPU, plural is CPUs.
 1.6 02-Nov-2003  wiz Fix some typos. From Tom Cosgrove via jmc@openbsd.
 1.5 13-Nov-2001  lukem branches: 1.5.16;
add/cleanup RCSID
 1.4 18-Jan-2001  jdolecek branches: 1.4.2; 1.4.4;
constify
 1.3 26-Sep-1998  dante branches: 1.3.12;
Remove Wide boards references
Adjust copyright

At this time this driver support the following AdvanSys boards:
- ABP-9xx
- ABP-9xxU
- ABP-9xxUA
 1.2 29-Aug-1998  dante Add rcs id
 1.1 26-Aug-1998  dante Add AdvanSys 930U and 940U SCSI controllers
 1.3.12.1 11-Feb-2001  bouyer Sync with HEAD.
 1.4.4.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.4.2.1 14-Nov-2001  nathanw Catch up to -current.
 1.5.16.4 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.5.16.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.5.16.2 18-Sep-2004  skrll Sync with HEAD.
 1.5.16.1 03-Aug-2004  skrll Sync with HEAD
 1.7.10.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.7.8.1 29-Apr-2005  kent sync with -current
 1.9.170.1 18-Dec-2019  martin Pull up following revision(s) (requested by tsutsui in ticket #570):

sys/compat/netbsd32/netbsd32_compat_50_sysv.c: revision 1.3
sys/dev/raidframe/rf_compat50.h: revision 1.6
sys/arch/emips/emips/bus_space.c: revision 1.3
sys/compat/net/if.h: revision 1.5
sys/arch/emips/stand/common/bootinfo.c: revision 1.2
sys/compat/common/sysv_msg_50.c: revision 1.5
sys/compat/common/kern_time_30.c: revision 1.8
sys/arch/emips/stand/common/bootinfo.h: revision 1.2
sys/arch/ia64/include/bus.h: revision 1.4
sys/arch/ia64/ia64/bus_space.c: revision 1.2
sys/compat/common/sysv_shm_50.c: revision 1.5
sys/dev/ic/adw.h: revision 1.15
sys/compat/common/uipc_syscalls_50.c: revision 1.10
sys/arch/emips/ebus/flash_ebus.c: revision 1.22
sys/dev/ic/adv.h: revision 1.15
sys/dev/ic/adwmcode.c: revision 1.18
sys/dev/ic/advlib.c: revision 1.29
sys/arch/hpcarm/include/kloader.h: revision 1.3
sys/dev/usb/uberry.c: revision 1.16
sys/compat/common/sysv_sem_50.c: revision 1.5
sys/compat/netbsd32/netbsd32_compat_50.c: revision 1.43
sys/dev/ic/advlib.h: revision 1.21
sys/dev/ic/adv.c: revision 1.50
sys/compat/netinet6/in6_var.h: revision 1.5
sys/arch/hpc/stand/hpcboot/arm/arm_sa1100_asm.asm: revision 1.2
sys/arch/emips/include/loadfile_machdep.h: revision 1.3
sys/arch/emips/stand/common/prom_iface.c: revision 1.7
sys/dev/ic/adw.c: revision 1.56
sys/dev/ic/adwmcode.h: revision 1.12
sys/dev/ic/advmcode.c: revision 1.10
sys/arch/emips/ebus/ace_ebus.c: revision 1.22
sys/compat/netbsd32/netbsd32_compat_60.c: revision 1.5
sys/dev/raidframe/rf_compat50.c: revision 1.13
sys/arch/x68k/dev/intiovar.h: revision 1.15
sys/dev/usb/uipad.c: revision 1.8
sys/arch/zaurus/include/kloader.h: revision 1.3
sys/arch/emips/stand/common/bootxx.c: revision 1.2
sys/dev/ic/adwlib.h: revision 1.23
sys/dev/ic/adwlib.c: revision 1.44
sys/compat/netbsd32/netbsd32_compat_16.c: revision 1.3
sys/arch/amigappc/include/intr.h: revision 1.27
sys/arch/x68k/dev/mfp.c: revision 1.27
sys/arch/arm/at91/at91dbgu.c: revision 1.17
sys/dev/ic/advmcode.h: revision 1.7
sys/compat/ultrix/ultrix_exec.h: revision 1.7
sys/compat/common/vfs_syscalls_50.c: revision 1.24
sys/arch/mips/cavium/octeon_dma.c: revision 1.3
sys/arch/hpc/stand/hpcboot/arm/arm_pxa2x0_asm.asm: revision 1.2

Remove clause 3 and 4 from TNF licenses.
Ok'ed by martin@ in PR/54760.

Remove clause 3 and 4 leftovers from TNF licenses in more sources.
Confirmed by martin@ in PR/54760.
 1.9.164.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.7 15-Dec-2019  tsutsui Remove clause 3 and 4 leftovers from TNF licenses in more sources.

Confirmed by martin@ in PR/54760.
 1.6 11-Dec-2005  christos branches: 1.6.164; 1.6.170;
merge ktrace-lwp.
 1.5 27-Feb-2005  perry nuke trailing whitespace
 1.4 18-Jan-2001  jdolecek branches: 1.4.24; 1.4.32; 1.4.34;
constify
 1.3 26-Sep-1998  dante branches: 1.3.12;
Remove Wide boards references
Adjust copyright

At this time this driver support the following AdvanSys boards:
- ABP-9xx
- ABP-9xxU
- ABP-9xxUA
 1.2 29-Aug-1998  dante Add rcs id
 1.1 26-Aug-1998  dante Add AdvanSys 930U and 940U SCSI controllers
 1.3.12.1 11-Feb-2001  bouyer Sync with HEAD.
 1.4.34.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.4.32.1 29-Apr-2005  kent sync with -current
 1.4.24.1 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.6.170.1 18-Dec-2019  martin Pull up following revision(s) (requested by tsutsui in ticket #570):

sys/compat/netbsd32/netbsd32_compat_50_sysv.c: revision 1.3
sys/dev/raidframe/rf_compat50.h: revision 1.6
sys/arch/emips/emips/bus_space.c: revision 1.3
sys/compat/net/if.h: revision 1.5
sys/arch/emips/stand/common/bootinfo.c: revision 1.2
sys/compat/common/sysv_msg_50.c: revision 1.5
sys/compat/common/kern_time_30.c: revision 1.8
sys/arch/emips/stand/common/bootinfo.h: revision 1.2
sys/arch/ia64/include/bus.h: revision 1.4
sys/arch/ia64/ia64/bus_space.c: revision 1.2
sys/compat/common/sysv_shm_50.c: revision 1.5
sys/dev/ic/adw.h: revision 1.15
sys/compat/common/uipc_syscalls_50.c: revision 1.10
sys/arch/emips/ebus/flash_ebus.c: revision 1.22
sys/dev/ic/adv.h: revision 1.15
sys/dev/ic/adwmcode.c: revision 1.18
sys/dev/ic/advlib.c: revision 1.29
sys/arch/hpcarm/include/kloader.h: revision 1.3
sys/dev/usb/uberry.c: revision 1.16
sys/compat/common/sysv_sem_50.c: revision 1.5
sys/compat/netbsd32/netbsd32_compat_50.c: revision 1.43
sys/dev/ic/advlib.h: revision 1.21
sys/dev/ic/adv.c: revision 1.50
sys/compat/netinet6/in6_var.h: revision 1.5
sys/arch/hpc/stand/hpcboot/arm/arm_sa1100_asm.asm: revision 1.2
sys/arch/emips/include/loadfile_machdep.h: revision 1.3
sys/arch/emips/stand/common/prom_iface.c: revision 1.7
sys/dev/ic/adw.c: revision 1.56
sys/dev/ic/adwmcode.h: revision 1.12
sys/dev/ic/advmcode.c: revision 1.10
sys/arch/emips/ebus/ace_ebus.c: revision 1.22
sys/compat/netbsd32/netbsd32_compat_60.c: revision 1.5
sys/dev/raidframe/rf_compat50.c: revision 1.13
sys/arch/x68k/dev/intiovar.h: revision 1.15
sys/dev/usb/uipad.c: revision 1.8
sys/arch/zaurus/include/kloader.h: revision 1.3
sys/arch/emips/stand/common/bootxx.c: revision 1.2
sys/dev/ic/adwlib.h: revision 1.23
sys/dev/ic/adwlib.c: revision 1.44
sys/compat/netbsd32/netbsd32_compat_16.c: revision 1.3
sys/arch/amigappc/include/intr.h: revision 1.27
sys/arch/x68k/dev/mfp.c: revision 1.27
sys/arch/arm/at91/at91dbgu.c: revision 1.17
sys/dev/ic/advmcode.h: revision 1.7
sys/compat/ultrix/ultrix_exec.h: revision 1.7
sys/compat/common/vfs_syscalls_50.c: revision 1.24
sys/arch/mips/cavium/octeon_dma.c: revision 1.3
sys/arch/hpc/stand/hpcboot/arm/arm_pxa2x0_asm.asm: revision 1.2

Remove clause 3 and 4 from TNF licenses.
Ok'ed by martin@ in PR/54760.

Remove clause 3 and 4 leftovers from TNF licenses in more sources.
Confirmed by martin@ in PR/54760.
 1.6.164.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.59 07-Aug-2021  thorpej Merge thorpej-cfargs2.
 1.58 24-Jul-2021  andvar branches: 1.58.2;
Fix all remaining typos, mainly in comments but also in few definitions and log messages, reported by me in PR kern/54889.
Also fixed some additional typos in comments, found on review of same files or typos.
 1.57 24-Apr-2021  thorpej branches: 1.57.2;
Merge thorpej-cfargs branch:

Simplify and make extensible the config_search() / config_found() /
config_attach() interfaces: rather than having different variants for
which arguments you want pass along, just have a single call that
takes a variadic list of tag-value arguments.

Adjust all call sites:
- Simplify wherever possible; don't pass along arguments that aren't
actually needed.
- Don't be explicit about what interface attribute is attaching if
the device only has one. (More simplification.)
- Add a config_probe() function to be used in indirect configuiration
situations, making is visibly easier to see when indirect config is
in play, and allowing for future change in semantics. (As of now,
this is just a wrapper around config_match(), but that is an
implementation detail.)

Remove unnecessary or redundant interface attributes where they're not
needed.

There are currently 5 "cfargs" defined:
- CFARG_SUBMATCH (submatch function for direct config)
- CFARG_SEARCH (search function for indirect config)
- CFARG_IATTR (interface attribte)
- CFARG_LOCATORS (locators array)
- CFARG_DEVHANDLE (devhandle_t - wraps OFW, ACPI, etc. handles)

...and a sentinel value CFARG_EOL.

Add some extra sanity checking to ensure that interface attributes
aren't ambiguous.

Use CFARG_DEVHANDLE in MI FDT, OFW, and ACPI code, and macppc and shark
ports to associate those device handles with device_t instance. This
will trickle trough to more places over time (need back-end for pre-OFW
Sun OBP; any others?).
 1.56 15-Dec-2019  tsutsui branches: 1.56.10;
Remove clause 3 and 4 leftovers from TNF licenses in more sources.

Confirmed by martin@ in PR/54760.
 1.55 06-Oct-2019  uwe Get rid of bogus ADW_CALLBACK typedef. Use the real callback types
directly. Since we no longer need the casting dance we can get rid of
ADW_ISR_CALLBACK and ADW_ASYNC_CALLBACK typedefs too. The diff for
adwlib.h looks larger than it is b/c we need to reorder structure
definitions for the proper callback declaration. Found by gcc8
-Wcast-function-type.
 1.54 14-Jul-2016  msaitoh branches: 1.54.18; 1.54.24;
KNF. No functional change.
 1.53 07-Jul-2016  msaitoh KNF. Remove extra spaces. No functional change.
 1.52 27-Oct-2012  chs branches: 1.52.14;
split device_t/softc for all remaining drivers.
replace "struct device *" with "device_t".
use device_xname(), device_unit(), etc.
 1.51 13-Nov-2010  uebayasi branches: 1.51.8; 1.51.18;
Don't pull in the whole uvm(9) API to access only PAGE_SIZE and
some other constants. These are provided by sys/param.h now.
 1.50 23-Nov-2009  rmind branches: 1.50.4;
Remove some unecessary includes sys/user.h header.
 1.49 08-Apr-2008  cegger branches: 1.49.4;
use aprint_*_dev and device_xname
 1.48 19-Oct-2007  ad branches: 1.48.16;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.47 04-Mar-2007  christos branches: 1.47.2; 1.47.14; 1.47.16; 1.47.20;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.46 11-Dec-2005  christos branches: 1.46.26;
merge ktrace-lwp.
 1.45 27-Feb-2005  perry branches: 1.45.4;
nuke trailing whitespace
 1.44 21-Feb-2005  thorpej Part 1 of a cleanup pass over the SCSI subsystem. The aim is to name
everything "scsi_*", since we really are talking about the SCSI command
set, ATAPI transport not withstanding. Improve the names of many structures,
and prepend "SCSI_" onto all SCSI command opcodes. Place items described
by the SCSI Primary Commands document into scsi_spc.h.
 1.43 02-Nov-2003  wiz branches: 1.43.8; 1.43.10;
Fix some typos. From Tom Cosgrove via jmc@openbsd.
 1.42 21-Oct-2003  fvdl Correct NULL abuse.
 1.41 18-Sep-2003  mycroft nluns should be 8, not 7.
 1.40 03-May-2003  wiz branches: 1.40.2;
DMA, not dma nor Dma.
 1.39 31-Jan-2003  thorpej Use aprint_*().
 1.38 05-Apr-2002  bouyer Implement mstohz() as discussed on tech-kern, and use it in SCSI drivers
to convert xs->timeout to callout() parameter.
 1.37 15-Nov-2001  lukem don't need <sys/types.h> when including <sys/param.h>
 1.36 13-Nov-2001  lukem add/cleanup RCSID
 1.35 29-Aug-2001  briggs Ensure that data accessed by the ADW driver in memory is in
little-endian byte-order. This should work out to be a no-op
for LE systems, and allows BE systems to use the board.

Tested on PPC, reviewed by Dante.

NOTE: The board/microcode does have a BIG_ENDIAN mode of operation,
but it's not well-documented. That might be interesting to investigate
at some point in the future, though.
 1.34 31-Jul-2001  dante change\n\tswitch (scsiq->host_status)\nto\n\tswitch (scsiq->scsi_status)\nin adw_isr_callback()
 1.33 19-Jul-2001  thorpej Use BUS_DMA_READ and BUS_DMA_WRITE in some obvious places.
 1.32 07-Jul-2001  thorpej branches: 1.32.2;
bzero -> memset
 1.31 07-Jul-2001  thorpej bcopy -> memcpy
 1.30 30-Apr-2001  lukem remove some lint, including ansifying funcs
 1.29 25-Apr-2001  bouyer Pull up the thorpej_scsipi branch to main branch.
This is a completely rewritten scsipi_xfer execution engine, and the
associated changes to HBA drivers. Overview of changes & features:
- All xfers are queued in the mid-layer, rather than doing so in an
ad-hoc fashion in individual adapter drivers.
- Adapter/channel resource management in the mid-layer, avoids even trying
to start running an xfer if the adapter/channel doesn't have the resources.
- Better communication between the mid-layer and the adapters.
- Asynchronous event notification mechanism from adapter to mid-layer and
peripherals.
- Better peripheral queue management: freeze/thaw, sorted requeueing during
recovery, etc.
- Clean separation of peripherals, adapters, and adapter channels (no more
scsipi_link).
- Kernel thread for each scsipi_channel makes error recovery much easier
(no more dealing with interrupt context when recovering from an error).
- Mid-layer support for tagged queueing: commands can have the tag type
set explicitly, tag IDs are allocated in the mid-layer (thus eliminating
the need to use buggy tag ID allocation schemes in many adapter drivers).
- support for QUEUE FULL and CHECK CONDITION status in mid-layer; the command
will be requeued, or a REQUEST SENSE will be sent as appropriate.

Just before the merge syssrc has been tagged with thorpej_scsipi_beforemerge
 1.28 07-Mar-2001  thorpej Add BUS_DMA_STREAMING to data transfer maps.
 1.27 11-Feb-2001  hpeyerl branches: 1.27.2;
Fix for kern/12114 and kern/12158 Advansys DMA errors.
Reported by Bob Bernstein who heard from Kenneth Westerback that this
might be the problem. Tested by HP.
 1.26 14-Nov-2000  thorpej NBPG -> PAGE_SIZE
 1.25 28-Jun-2000  mrg remove include of <vm/vm.h>. <vm/vm.h> -> <uvm/uvm_extern.h>
 1.24 26-Jun-2000  mrg remove redundant vm includes.
 1.23 27-May-2000  dante branches: 1.23.2;
Change AdwInitCarriers in adwmcode.c
Add new AdwInitCarriers prototype in adwmcode.h
All of the supported adapters are now initialized calling a unique common
function
 1.22 26-May-2000  dante branches: 1.22.2;
Fix a bug introduced in last commit which caused a painc due to
re-enqueueing an already free ccb.
Prepare the background to have a unique initialization function for
all of the supported host adapters.
Rename a lot of #define in a more sane way.
Move Carriers initialization and defines in adwmcode.{c,h}
Don't lose Carrier nodes in case of a BUS/Chip reset explicitly invoked
after a DMA failure.

XXX - DMA failure still arise when AdvanSys U[2]W host adapters are used
in conjunction with Intel 82443BX Host Bridge/Controller (rev. 0x03).
!?!Have to understand why!?!
 1.21 14-May-2000  dante Handle better the status codes.
Add a way to instruct the upper layer to don't bother w/ new requests if/when a device queue is full/busy or the device is unavailabale at that time
Use scsipi_inquiry_data instead of its own inquiry structure
 1.20 10-May-2000  dante Change adw_isr_callback() status handler
Add a catch for DMA Error which show up on Intel 82443BX Host Bridge/Controller (rev. 0x03). This doesn't fix the problem, but reset the SCSI bus and reinitialize the host adapter
Minor cosmetical changes

Thanks a lot to Greg Oster and Andan Lauber
 1.19 08-May-2000  dante Change the way ADW_CARRIER is allocated and handled.
Increased ADW_MAX_CCB to 63 and ADW_MAX_CARRIER to 253
Print WDTR/SDTR negotiation result per target
Protect AdvISR() inside splbio()/splx() pair
Add a pending queue to keep track of all the CCBs that are being executed by the host adapter.
Rewrote timeout handler in a more efficient way:
After 3 timeout now the SCSI is resetted and all pending queues not completed are now reenqueued in the waiting queue so to get executed just after the BUS Reset (hoping that resetting the SCSI BUS and reinitializing the adapter could solve the problem).
 1.18 03-May-2000  thorpej Slight change to previous.
 1.17 03-May-2000  thorpej Don't return an uninitialized error code.
 1.16 30-Apr-2000  dante Add new microcode for all of the supported boards.
Fix minor glitches.
Add preliminary support for ASB-3940U3W host adapters; it might work w/ autotermination on.
ASB-3940U3W support is not yet tested due to lack of board.
 1.15 23-Mar-2000  thorpej New callout mechanism with two major improvements over the old
timeout()/untimeout() API:
- Clients supply callout handle storage, thus eliminating problems of
resource allocation.
- Insertion and removal of callouts is constant time, important as
this facility is used quite a lot in the kernel.

The old timeout()/untimeout() API has been removed from the kernel.
 1.14 12-Feb-2000  thorpej If we got an xfer from our backlog queue, don't allow sleeping; we're in
interrupt context.

XXX This is fixed properly in the thorpej_scsipi branch, but that won't
be ready for 1.5, I don't think.
 1.13 03-Feb-2000  dante Add AdvanSys U2W (LVD) boards support
 1.12 30-Sep-1999  thorpej branches: 1.12.2;
Update for SCSPI changes.
 1.11 11-Sep-1999  dante Rewrote error handlers. Now they are solid.
Increesed considerably the speed of the driver removing superfluous splbio/splx functions.
 1.10 17-Aug-1999  thorpej The CCB already contains its DMA address, so no need to recompute it
over and over.
 1.9 16-Aug-1999  thorpej Fix several LP64 problems, and clear up kernel pointer vs. physical
address confusion. This driver now works on the Alpha.
 1.8 04-Mar-1999  dante fix second level interrupt handler to allow 64 bits pointers
 1.7 23-Feb-1999  dante Fixed AdvanSys Ultra Wide driver to work on Alpha.
 1.6 09-Dec-1998  thorpej Update for changed scsipi_xfer struct.
 1.5 05-Dec-1998  mjacob Update HBAs to incorporate the new max_lun property.
 1.4 19-Nov-1998  thorpej Adapt to the new scsipi_adapter interface.
 1.3 10-Oct-1998  thorpej Garbage-collect the open_target_lu and close_target_lu entry points from
struct scsipi_adapter; they were not used.

Add a scsipi_ioctl entry point to struct scsipi_adapter. This will be
used to issue ioctl commands to the host adapters.

Inspired by PR #6090, from Matt Jacob.
 1.2 26-Sep-1998  dante Change sources to be KNF
 1.1 26-Sep-1998  dante Add support for AdvanSys Ultra Wide boards ABP-9xxUW
 1.12.2.8 23-Mar-2001  bouyer Make compile again.
 1.12.2.7 12-Mar-2001  bouyer Sync with HEAD.
 1.12.2.6 22-Nov-2000  bouyer Sync with HEAD.
 1.12.2.5 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.12.2.4 26-Oct-1999  thorpej Update for:

Deal a little more gracefully with the fact that xfer mode parameters
are for the I_T Nexus, and make all xfer mode updates `async events'.
 1.12.2.3 20-Oct-1999  thorpej Eliminate sleeping from adapter routines.
 1.12.2.2 19-Oct-1999  thorpej Don't sleep waiting for a CCB; if we get to the CCB allocation phase, we're
guaranteed to have one.
 1.12.2.1 19-Oct-1999  thorpej Adapt to scsipi API changes.
 1.22.2.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.23.2.1 26-Feb-2001  he Pull up revision 1.27 (requested by thorpej):
Fix for ``Advansys DMA errors''. Fixes PR#12114 and PR#12158.
 1.27.2.7 17-Apr-2002  nathanw Catch up to -current.
 1.27.2.6 08-Jan-2002  nathanw Catch up to -current.
 1.27.2.5 14-Nov-2001  nathanw Catch up to -current.
 1.27.2.4 21-Sep-2001  nathanw Catch up to -current.
 1.27.2.3 24-Aug-2001  nathanw Catch up with -current.
 1.27.2.2 21-Jun-2001  nathanw Catch up to -current.
 1.27.2.1 09-Apr-2001  nathanw Catch up with -current.
 1.32.2.4 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.32.2.3 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.32.2.2 13-Sep-2001  thorpej Update the kqueue branch to HEAD.
 1.32.2.1 03-Aug-2001  lukem update to -current
 1.40.2.4 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.40.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.40.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.40.2.1 03-Aug-2004  skrll Sync with HEAD
 1.43.10.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.43.8.1 29-Apr-2005  kent sync with -current
 1.45.4.2 27-Oct-2007  yamt sync with head.
 1.45.4.1 03-Sep-2007  yamt sync with head.
 1.46.26.1 12-Mar-2007  rmind Sync with HEAD.
 1.47.20.1 25-Oct-2007  bouyer Sync with HEAD.
 1.47.16.1 06-Nov-2007  matt sync with HEAD
 1.47.14.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.47.2.1 23-Oct-2007  ad Sync with head.
 1.48.16.1 02-Jun-2008  mjf Sync with HEAD.
 1.49.4.1 11-Mar-2010  yamt sync with head
 1.50.4.1 05-Mar-2011  rmind sync with head
 1.51.18.2 03-Dec-2017  jdolecek update from HEAD
 1.51.18.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.51.8.1 30-Oct-2012  yamt sync with head
 1.52.14.2 05-Oct-2016  skrll Sync with HEAD
 1.52.14.1 09-Jul-2016  skrll Sync with HEAD
 1.54.24.1 18-Dec-2019  martin Pull up following revision(s) (requested by tsutsui in ticket #570):

sys/compat/netbsd32/netbsd32_compat_50_sysv.c: revision 1.3
sys/dev/raidframe/rf_compat50.h: revision 1.6
sys/arch/emips/emips/bus_space.c: revision 1.3
sys/compat/net/if.h: revision 1.5
sys/arch/emips/stand/common/bootinfo.c: revision 1.2
sys/compat/common/sysv_msg_50.c: revision 1.5
sys/compat/common/kern_time_30.c: revision 1.8
sys/arch/emips/stand/common/bootinfo.h: revision 1.2
sys/arch/ia64/include/bus.h: revision 1.4
sys/arch/ia64/ia64/bus_space.c: revision 1.2
sys/compat/common/sysv_shm_50.c: revision 1.5
sys/dev/ic/adw.h: revision 1.15
sys/compat/common/uipc_syscalls_50.c: revision 1.10
sys/arch/emips/ebus/flash_ebus.c: revision 1.22
sys/dev/ic/adv.h: revision 1.15
sys/dev/ic/adwmcode.c: revision 1.18
sys/dev/ic/advlib.c: revision 1.29
sys/arch/hpcarm/include/kloader.h: revision 1.3
sys/dev/usb/uberry.c: revision 1.16
sys/compat/common/sysv_sem_50.c: revision 1.5
sys/compat/netbsd32/netbsd32_compat_50.c: revision 1.43
sys/dev/ic/advlib.h: revision 1.21
sys/dev/ic/adv.c: revision 1.50
sys/compat/netinet6/in6_var.h: revision 1.5
sys/arch/hpc/stand/hpcboot/arm/arm_sa1100_asm.asm: revision 1.2
sys/arch/emips/include/loadfile_machdep.h: revision 1.3
sys/arch/emips/stand/common/prom_iface.c: revision 1.7
sys/dev/ic/adw.c: revision 1.56
sys/dev/ic/adwmcode.h: revision 1.12
sys/dev/ic/advmcode.c: revision 1.10
sys/arch/emips/ebus/ace_ebus.c: revision 1.22
sys/compat/netbsd32/netbsd32_compat_60.c: revision 1.5
sys/dev/raidframe/rf_compat50.c: revision 1.13
sys/arch/x68k/dev/intiovar.h: revision 1.15
sys/dev/usb/uipad.c: revision 1.8
sys/arch/zaurus/include/kloader.h: revision 1.3
sys/arch/emips/stand/common/bootxx.c: revision 1.2
sys/dev/ic/adwlib.h: revision 1.23
sys/dev/ic/adwlib.c: revision 1.44
sys/compat/netbsd32/netbsd32_compat_16.c: revision 1.3
sys/arch/amigappc/include/intr.h: revision 1.27
sys/arch/x68k/dev/mfp.c: revision 1.27
sys/arch/arm/at91/at91dbgu.c: revision 1.17
sys/dev/ic/advmcode.h: revision 1.7
sys/compat/ultrix/ultrix_exec.h: revision 1.7
sys/compat/common/vfs_syscalls_50.c: revision 1.24
sys/arch/mips/cavium/octeon_dma.c: revision 1.3
sys/arch/hpc/stand/hpcboot/arm/arm_pxa2x0_asm.asm: revision 1.2

Remove clause 3 and 4 from TNF licenses.
Ok'ed by martin@ in PR/54760.

Remove clause 3 and 4 leftovers from TNF licenses in more sources.
Confirmed by martin@ in PR/54760.
 1.54.18.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.54.18.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.56.10.1 21-Mar-2021  thorpej Give config_found() the same variadic arguments treatment as
config_search(). This commit only adds the CFARG_EOL sentinel
to the existing config_found() calls. Conversion of config_found_sm_loc()
and config_found_ia() call sites will be in subsequent commits.
 1.57.2.1 01-Aug-2021  thorpej Sync with HEAD.
 1.58.2.1 04-Aug-2021  thorpej Adapt to CFARGS().
 1.15 15-Dec-2019  tsutsui Remove clause 3 and 4 leftovers from TNF licenses in more sources.

Confirmed by martin@ in PR/54760.
 1.14 11-Dec-2005  christos branches: 1.14.164; 1.14.170;
merge ktrace-lwp.
 1.13 27-Feb-2005  perry nuke trailing whitespace
 1.12 21-Feb-2005  thorpej Part 1 of a cleanup pass over the SCSI subsystem. The aim is to name
everything "scsi_*", since we really are talking about the SCSI command
set, ATAPI transport not withstanding. Improve the names of many structures,
and prepend "SCSI_" onto all SCSI command opcodes. Place items described
by the SCSI Primary Commands document into scsi_spc.h.
 1.11 04-Feb-2005  perry de-__P
 1.10 08-Jul-2003  itojun branches: 1.10.8; 1.10.10;
function prototype must not have variable name
 1.9 26-May-2000  dante branches: 1.9.28;
Fix a bug introduced in last commit which caused a painc due to
re-enqueueing an already free ccb.
Prepare the background to have a unique initialization function for
all of the supported host adapters.
Rename a lot of #define in a more sane way.
Move Carriers initialization and defines in adwmcode.{c,h}
Don't lose Carrier nodes in case of a BUS/Chip reset explicitly invoked
after a DMA failure.

XXX - DMA failure still arise when AdvanSys U[2]W host adapters are used
in conjunction with Intel 82443BX Host Bridge/Controller (rev. 0x03).
!?!Have to understand why!?!
 1.8 10-May-2000  dante Change adw_isr_callback() status handler
Add a catch for DMA Error which show up on Intel 82443BX Host Bridge/Controller (rev. 0x03). This doesn't fix the problem, but reset the SCSI bus and reinitialize the host adapter
Minor cosmetical changes

Thanks a lot to Greg Oster and Andan Lauber
 1.7 08-May-2000  dante Change the way ADW_CARRIER is allocated and handled.
Increased ADW_MAX_CCB to 63 and ADW_MAX_CARRIER to 253
Print WDTR/SDTR negotiation result per target
Protect AdvISR() inside splbio()/splx() pair
Add a pending queue to keep track of all the CCBs that are being executed by the host adapter.
Rewrote timeout handler in a more efficient way:
After 3 timeout now the SCSI is resetted and all pending queues not completed are now reenqueued in the waiting queue so to get executed just after the BUS Reset (hoping that resetting the SCSI BUS and reinitializing the adapter could solve the problem).
 1.6 30-Apr-2000  dante Add new microcode for all of the supported boards.
Fix minor glitches.
Add preliminary support for ASB-3940U3W host adapters; it might work w/ autotermination on.
ASB-3940U3W support is not yet tested due to lack of board.
 1.5 03-Feb-2000  dante Add AdvanSys U2W (LVD) boards support
 1.4 11-Sep-1999  dante branches: 1.4.2;
Rewrote error handlers. Now they are solid.
Increesed considerably the speed of the driver removing superfluous splbio/splx functions.
 1.3 16-Aug-1999  thorpej Fix several LP64 problems, and clear up kernel pointer vs. physical
address confusion. This driver now works on the Alpha.
 1.2 23-Feb-1999  dante Fixed AdvanSys Ultra Wide driver to work on Alpha.
 1.1 26-Sep-1998  dante Add support for AdvanSys Ultra Wide boards ABP-9xxUW
 1.4.2.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.9.28.5 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.9.28.4 04-Feb-2005  skrll Sync with HEAD.
 1.9.28.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.9.28.2 18-Sep-2004  skrll Sync with HEAD.
 1.9.28.1 03-Aug-2004  skrll Sync with HEAD
 1.10.10.2 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.10.10.1 12-Feb-2005  yamt sync with head.
 1.10.8.1 29-Apr-2005  kent sync with -current
 1.14.170.1 18-Dec-2019  martin Pull up following revision(s) (requested by tsutsui in ticket #570):

sys/compat/netbsd32/netbsd32_compat_50_sysv.c: revision 1.3
sys/dev/raidframe/rf_compat50.h: revision 1.6
sys/arch/emips/emips/bus_space.c: revision 1.3
sys/compat/net/if.h: revision 1.5
sys/arch/emips/stand/common/bootinfo.c: revision 1.2
sys/compat/common/sysv_msg_50.c: revision 1.5
sys/compat/common/kern_time_30.c: revision 1.8
sys/arch/emips/stand/common/bootinfo.h: revision 1.2
sys/arch/ia64/include/bus.h: revision 1.4
sys/arch/ia64/ia64/bus_space.c: revision 1.2
sys/compat/common/sysv_shm_50.c: revision 1.5
sys/dev/ic/adw.h: revision 1.15
sys/compat/common/uipc_syscalls_50.c: revision 1.10
sys/arch/emips/ebus/flash_ebus.c: revision 1.22
sys/dev/ic/adv.h: revision 1.15
sys/dev/ic/adwmcode.c: revision 1.18
sys/dev/ic/advlib.c: revision 1.29
sys/arch/hpcarm/include/kloader.h: revision 1.3
sys/dev/usb/uberry.c: revision 1.16
sys/compat/common/sysv_sem_50.c: revision 1.5
sys/compat/netbsd32/netbsd32_compat_50.c: revision 1.43
sys/dev/ic/advlib.h: revision 1.21
sys/dev/ic/adv.c: revision 1.50
sys/compat/netinet6/in6_var.h: revision 1.5
sys/arch/hpc/stand/hpcboot/arm/arm_sa1100_asm.asm: revision 1.2
sys/arch/emips/include/loadfile_machdep.h: revision 1.3
sys/arch/emips/stand/common/prom_iface.c: revision 1.7
sys/dev/ic/adw.c: revision 1.56
sys/dev/ic/adwmcode.h: revision 1.12
sys/dev/ic/advmcode.c: revision 1.10
sys/arch/emips/ebus/ace_ebus.c: revision 1.22
sys/compat/netbsd32/netbsd32_compat_60.c: revision 1.5
sys/dev/raidframe/rf_compat50.c: revision 1.13
sys/arch/x68k/dev/intiovar.h: revision 1.15
sys/dev/usb/uipad.c: revision 1.8
sys/arch/zaurus/include/kloader.h: revision 1.3
sys/arch/emips/stand/common/bootxx.c: revision 1.2
sys/dev/ic/adwlib.h: revision 1.23
sys/dev/ic/adwlib.c: revision 1.44
sys/compat/netbsd32/netbsd32_compat_16.c: revision 1.3
sys/arch/amigappc/include/intr.h: revision 1.27
sys/arch/x68k/dev/mfp.c: revision 1.27
sys/arch/arm/at91/at91dbgu.c: revision 1.17
sys/dev/ic/advmcode.h: revision 1.7
sys/compat/ultrix/ultrix_exec.h: revision 1.7
sys/compat/common/vfs_syscalls_50.c: revision 1.24
sys/arch/mips/cavium/octeon_dma.c: revision 1.3
sys/arch/hpc/stand/hpcboot/arm/arm_pxa2x0_asm.asm: revision 1.2

Remove clause 3 and 4 from TNF licenses.
Ok'ed by martin@ in PR/54760.

Remove clause 3 and 4 leftovers from TNF licenses in more sources.
Confirmed by martin@ in PR/54760.
 1.14.164.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.45 25-Sep-2022  thorpej Remove unnecessary include of <sys/malloc.h>.
 1.44 15-Dec-2019  tsutsui Remove clause 3 and 4 leftovers from TNF licenses in more sources.

Confirmed by martin@ in PR/54760.
 1.43 06-Oct-2019  uwe Get rid of bogus ADW_CALLBACK typedef. Use the real callback types
directly. Since we no longer need the casting dance we can get rid of
ADW_ISR_CALLBACK and ADW_ASYNC_CALLBACK typedefs too. The diff for
adwlib.h looks larger than it is b/c we need to reorder structure
definitions for the proper callback declaration. Found by gcc8
-Wcast-function-type.
 1.42 03-Feb-2019  mrg branches: 1.42.4;
- add or adjust /* FALLTHROUGH */ where appropriate
- add __unreachable() after functions that can return but won't in
this case, and thus can't be marked __dead easily
 1.41 12-Sep-2013  martin branches: 1.41.30;
Remove unused ppr_able variable.
 1.40 13-Nov-2010  uebayasi branches: 1.40.8; 1.40.18; 1.40.22;
Don't pull in the whole uvm(9) API to access only PAGE_SIZE and
some other constants. These are provided by sys/param.h now.
 1.39 14-Mar-2009  dsl branches: 1.39.4;
Change about 4500 of the K&R function definitions to ANSI ones.
There are still about 1600 left, but they have ',' or /* ... */
in the actual variable definitions - which my awk script doesn't handle.
There are also many that need () -> (void).
(The script does handle misordered arguments.)
 1.38 19-Oct-2007  ad branches: 1.38.20; 1.38.28; 1.38.34;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.37 27-Aug-2006  christos branches: 1.37.12; 1.37.26; 1.37.28; 1.37.32;
complete declarations
 1.36 21-May-2006  christos void casts to functions whose return values are ignored.
 1.35 11-Dec-2005  christos branches: 1.35.4; 1.35.6; 1.35.8; 1.35.12; 1.35.14;
merge ktrace-lwp.
 1.34 30-May-2005  christos branches: 1.34.2;
- add missing const
- fix variable shadowing
- remove unneeded casts
 1.33 27-Feb-2005  perry nuke trailing whitespace
 1.32 04-Feb-2005  perry de-__P
 1.31 02-Nov-2003  wiz branches: 1.31.8; 1.31.10;
Fix some typos. From Tom Cosgrove via jmc@openbsd.
 1.30 30-Oct-2003  simonb Remove some assigned-to but otherwise unused variables.
 1.29 29-Oct-2003  mycroft Return EINVAL rather than stepping off a null pointer.
 1.28 25-Oct-2003  christos Fix uninitialized variable warning.
 1.27 25-Oct-2003  christos Fix uninitialized variable warnings
 1.26 21-Oct-2003  fvdl Correct NULL abuse.
 1.25 21-Feb-2003  tsutsui branches: 1.25.2;
hz -> Hz
 1.24 15-Nov-2001  lukem don't need <sys/types.h> when including <sys/param.h>
 1.23 13-Nov-2001  lukem add/cleanup RCSID
 1.22 29-Aug-2001  briggs Ensure that data accessed by the ADW driver in memory is in
little-endian byte-order. This should work out to be a no-op
for LE systems, and allows BE systems to use the board.

Tested on PPC, reviewed by Dante.

NOTE: The board/microcode does have a BIG_ENDIAN mode of operation,
but it's not well-documented. That might be interesting to investigate
at some point in the future, though.
 1.21 30-Apr-2001  lukem branches: 1.21.2;
use #if 0 rather than // or /* to comment out blocks of code
 1.20 04-Jul-2000  itojun branches: 1.20.2;
sync with sys/dev/ic/adwlib.h change (s/ADV_TICKLE/ADW_TICKLE/)
not sure if it is right. comments?
 1.19 28-Jun-2000  mrg remove include of <vm/vm.h>. <vm/vm.h> -> <uvm/uvm_extern.h>
 1.18 26-Jun-2000  mrg remove redundant vm includes.
 1.17 27-May-2000  dante Change AdwInitCarriers in adwmcode.c
Add new AdwInitCarriers prototype in adwmcode.h
All of the supported adapters are now initialized calling a unique common
function
 1.16 26-May-2000  dante branches: 1.16.2;
Fix a bug introduced in last commit which caused a painc due to
re-enqueueing an already free ccb.
Prepare the background to have a unique initialization function for
all of the supported host adapters.
Rename a lot of #define in a more sane way.
Move Carriers initialization and defines in adwmcode.{c,h}
Don't lose Carrier nodes in case of a BUS/Chip reset explicitly invoked
after a DMA failure.

XXX - DMA failure still arise when AdvanSys U[2]W host adapters are used
in conjunction with Intel 82443BX Host Bridge/Controller (rev. 0x03).
!?!Have to understand why!?!
 1.15 15-May-2000  dante Cosmetic change
 1.14 14-May-2000  dante Fix a typo
 1.13 14-May-2000  dante Handle better the status codes.
Add a way to instruct the upper layer to don't bother w/ new requests if/when a device queue is full/busy or the device is unavailabale at that time
Use scsipi_inquiry_data instead of its own inquiry structure
 1.12 10-May-2000  dante Change adw_isr_callback() status handler
Add a catch for DMA Error which show up on Intel 82443BX Host Bridge/Controller (rev. 0x03). This doesn't fix the problem, but reset the SCSI bus and reinitialize the host adapter
Minor cosmetical changes

Thanks a lot to Greg Oster and Andan Lauber
 1.11 08-May-2000  dante Change the way ADW_CARRIER is allocated and handled.
Increased ADW_MAX_CCB to 63 and ADW_MAX_CARRIER to 253
Print WDTR/SDTR negotiation result per target
Protect AdvISR() inside splbio()/splx() pair
Add a pending queue to keep track of all the CCBs that are being executed by the host adapter.
Rewrote timeout handler in a more efficient way:
After 3 timeout now the SCSI is resetted and all pending queues not completed are now reenqueued in the waiting queue so to get executed just after the BUS Reset (hoping that resetting the SCSI BUS and reinitializing the adapter could solve the problem).
 1.10 30-Apr-2000  dante Add new microcode for all of the supported boards.
Fix minor glitches.
Add preliminary support for ASB-3940U3W host adapters; it might work w/ autotermination on.
ASB-3940U3W support is not yet tested due to lack of board.
 1.9 04-Feb-2000  dante Fix "unused variable" warning when FAILSAFE option is defined
 1.8 04-Feb-2000  dante Fix a compilation bug due to a missing parenthesys
 1.7 03-Feb-2000  dante Add AdvanSys U2W (LVD) boards support
 1.6 15-Nov-1999  dante Let user enable/disable WDTR, SDTR and Tag Queuing from kernel config file
 1.5 16-Aug-1999  thorpej branches: 1.5.2; 1.5.8;
Fix several LP64 problems, and clear up kernel pointer vs. physical
address confusion. This driver now works on the Alpha.
 1.4 07-Aug-1999  thorpej Fix a typo.
 1.3 23-Feb-1999  dante Fixed AdvanSys Ultra Wide driver to work on Alpha.
 1.2 26-Sep-1998  dante Change sources to be KNF
 1.1 26-Sep-1998  dante Add support for AdvanSys Ultra Wide boards ABP-9xxUW
 1.5.8.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.5.2.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.16.2.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.20.2.4 08-Jan-2002  nathanw Catch up to -current.
 1.20.2.3 14-Nov-2001  nathanw Catch up to -current.
 1.20.2.2 21-Sep-2001  nathanw Catch up to -current.
 1.20.2.1 21-Jun-2001  nathanw Catch up to -current.
 1.21.2.2 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.21.2.1 13-Sep-2001  thorpej Update the kqueue branch to HEAD.
 1.25.2.6 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.25.2.5 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.25.2.4 04-Feb-2005  skrll Sync with HEAD.
 1.25.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.25.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.25.2.1 03-Aug-2004  skrll Sync with HEAD
 1.31.10.2 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.31.10.1 12-Feb-2005  yamt sync with head.
 1.31.8.1 29-Apr-2005  kent sync with -current
 1.34.2.3 27-Oct-2007  yamt sync with head.
 1.34.2.2 30-Dec-2006  yamt sync with head.
 1.34.2.1 21-Jun-2006  yamt sync with head.
 1.35.14.1 19-Jun-2006  chap Sync with head.
 1.35.12.1 24-May-2006  tron Merge 2006-05-24 NetBSD-current into the "peter-altq" branch.
 1.35.8.2 03-Sep-2006  yamt sync with head.
 1.35.8.1 24-May-2006  yamt sync with head.
 1.35.6.1 01-Jun-2006  kardel Sync with head.
 1.35.4.1 09-Sep-2006  rpaulo sync with head
 1.37.32.1 25-Oct-2007  bouyer Sync with HEAD.
 1.37.28.1 06-Nov-2007  matt sync with HEAD
 1.37.26.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.37.12.1 23-Oct-2007  ad Sync with head.
 1.38.34.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.38.28.1 28-Apr-2009  skrll Sync with HEAD.
 1.38.20.1 04-May-2009  yamt sync with head.
 1.39.4.1 05-Mar-2011  rmind sync with head
 1.40.22.1 18-May-2014  rmind sync with head
 1.40.18.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.40.8.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.41.30.3 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.41.30.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.41.30.1 10-Jun-2019  christos Sync with HEAD
 1.42.4.1 18-Dec-2019  martin Pull up following revision(s) (requested by tsutsui in ticket #570):

sys/compat/netbsd32/netbsd32_compat_50_sysv.c: revision 1.3
sys/dev/raidframe/rf_compat50.h: revision 1.6
sys/arch/emips/emips/bus_space.c: revision 1.3
sys/compat/net/if.h: revision 1.5
sys/arch/emips/stand/common/bootinfo.c: revision 1.2
sys/compat/common/sysv_msg_50.c: revision 1.5
sys/compat/common/kern_time_30.c: revision 1.8
sys/arch/emips/stand/common/bootinfo.h: revision 1.2
sys/arch/ia64/include/bus.h: revision 1.4
sys/arch/ia64/ia64/bus_space.c: revision 1.2
sys/compat/common/sysv_shm_50.c: revision 1.5
sys/dev/ic/adw.h: revision 1.15
sys/compat/common/uipc_syscalls_50.c: revision 1.10
sys/arch/emips/ebus/flash_ebus.c: revision 1.22
sys/dev/ic/adv.h: revision 1.15
sys/dev/ic/adwmcode.c: revision 1.18
sys/dev/ic/advlib.c: revision 1.29
sys/arch/hpcarm/include/kloader.h: revision 1.3
sys/dev/usb/uberry.c: revision 1.16
sys/compat/common/sysv_sem_50.c: revision 1.5
sys/compat/netbsd32/netbsd32_compat_50.c: revision 1.43
sys/dev/ic/advlib.h: revision 1.21
sys/dev/ic/adv.c: revision 1.50
sys/compat/netinet6/in6_var.h: revision 1.5
sys/arch/hpc/stand/hpcboot/arm/arm_sa1100_asm.asm: revision 1.2
sys/arch/emips/include/loadfile_machdep.h: revision 1.3
sys/arch/emips/stand/common/prom_iface.c: revision 1.7
sys/dev/ic/adw.c: revision 1.56
sys/dev/ic/adwmcode.h: revision 1.12
sys/dev/ic/advmcode.c: revision 1.10
sys/arch/emips/ebus/ace_ebus.c: revision 1.22
sys/compat/netbsd32/netbsd32_compat_60.c: revision 1.5
sys/dev/raidframe/rf_compat50.c: revision 1.13
sys/arch/x68k/dev/intiovar.h: revision 1.15
sys/dev/usb/uipad.c: revision 1.8
sys/arch/zaurus/include/kloader.h: revision 1.3
sys/arch/emips/stand/common/bootxx.c: revision 1.2
sys/dev/ic/adwlib.h: revision 1.23
sys/dev/ic/adwlib.c: revision 1.44
sys/compat/netbsd32/netbsd32_compat_16.c: revision 1.3
sys/arch/amigappc/include/intr.h: revision 1.27
sys/arch/x68k/dev/mfp.c: revision 1.27
sys/arch/arm/at91/at91dbgu.c: revision 1.17
sys/dev/ic/advmcode.h: revision 1.7
sys/compat/ultrix/ultrix_exec.h: revision 1.7
sys/compat/common/vfs_syscalls_50.c: revision 1.24
sys/arch/mips/cavium/octeon_dma.c: revision 1.3
sys/arch/hpc/stand/hpcboot/arm/arm_pxa2x0_asm.asm: revision 1.2

Remove clause 3 and 4 from TNF licenses.
Ok'ed by martin@ in PR/54760.

Remove clause 3 and 4 leftovers from TNF licenses in more sources.
Confirmed by martin@ in PR/54760.
 1.23 15-Dec-2019  tsutsui Remove clause 3 and 4 leftovers from TNF licenses in more sources.

Confirmed by martin@ in PR/54760.
 1.22 06-Oct-2019  uwe Get rid of bogus ADW_CALLBACK typedef. Use the real callback types
directly. Since we no longer need the casting dance we can get rid of
ADW_ISR_CALLBACK and ADW_ASYNC_CALLBACK typedefs too. The diff for
adwlib.h looks larger than it is b/c we need to reorder structure
definitions for the proper callback declaration. Found by gcc8
-Wcast-function-type.
 1.21 27-Oct-2012  chs branches: 1.21.38; 1.21.44;
split device_t/softc for all remaining drivers.
replace "struct device *" with "device_t".
use device_xname(), device_unit(), etc.
 1.20 24-Aug-2012  msaitoh branches: 1.20.2;
Fix typos
 1.19 11-Dec-2005  christos branches: 1.19.110;
merge ktrace-lwp.
 1.18 27-Feb-2005  perry nuke trailing whitespace
 1.17 21-Feb-2005  thorpej Part 1 of a cleanup pass over the SCSI subsystem. The aim is to name
everything "scsi_*", since we really are talking about the SCSI command
set, ATAPI transport not withstanding. Improve the names of many structures,
and prepend "SCSI_" onto all SCSI command opcodes. Place items described
by the SCSI Primary Commands document into scsi_spc.h.
 1.16 04-Feb-2005  perry de-__P
 1.15 25-Apr-2001  bouyer branches: 1.15.22; 1.15.30; 1.15.32;
Pull up the thorpej_scsipi branch to main branch.
This is a completely rewritten scsipi_xfer execution engine, and the
associated changes to HBA drivers. Overview of changes & features:
- All xfers are queued in the mid-layer, rather than doing so in an
ad-hoc fashion in individual adapter drivers.
- Adapter/channel resource management in the mid-layer, avoids even trying
to start running an xfer if the adapter/channel doesn't have the resources.
- Better communication between the mid-layer and the adapters.
- Asynchronous event notification mechanism from adapter to mid-layer and
peripherals.
- Better peripheral queue management: freeze/thaw, sorted requeueing during
recovery, etc.
- Clean separation of peripherals, adapters, and adapter channels (no more
scsipi_link).
- Kernel thread for each scsipi_channel makes error recovery much easier
(no more dealing with interrupt context when recovering from an error).
- Mid-layer support for tagged queueing: commands can have the tag type
set explicitly, tag IDs are allocated in the mid-layer (thus eliminating
the need to use buggy tag ID allocation schemes in many adapter drivers).
- support for QUEUE FULL and CHECK CONDITION status in mid-layer; the command
will be requeued, or a REQUEST SENSE will be sent as appropriate.

Just before the merge syssrc has been tagged with thorpej_scsipi_beforemerge
 1.14 03-Jul-2000  dante branches: 1.14.2;
Fix a off-by-one error in sc_freeze_dev[].
Thanks to kwesterback@home.com
 1.13 27-May-2000  dante Change AdwInitCarriers in adwmcode.c
Add new AdwInitCarriers prototype in adwmcode.h
All of the supported adapters are now initialized calling a unique common
function
 1.12 26-May-2000  dante branches: 1.12.2;
Fix a bug introduced in last commit which caused a painc due to
re-enqueueing an already free ccb.
Prepare the background to have a unique initialization function for
all of the supported host adapters.
Rename a lot of #define in a more sane way.
Move Carriers initialization and defines in adwmcode.{c,h}
Don't lose Carrier nodes in case of a BUS/Chip reset explicitly invoked
after a DMA failure.

XXX - DMA failure still arise when AdvanSys U[2]W host adapters are used
in conjunction with Intel 82443BX Host Bridge/Controller (rev. 0x03).
!?!Have to understand why!?!
 1.11 14-May-2000  dante Handle better the status codes.
Add a way to instruct the upper layer to don't bother w/ new requests if/when a device queue is full/busy or the device is unavailabale at that time
Use scsipi_inquiry_data instead of its own inquiry structure
 1.10 10-May-2000  dante Change adw_isr_callback() status handler
Add a catch for DMA Error which show up on Intel 82443BX Host Bridge/Controller (rev. 0x03). This doesn't fix the problem, but reset the SCSI bus and reinitialize the host adapter
Minor cosmetical changes

Thanks a lot to Greg Oster and Andan Lauber
 1.9 08-May-2000  dante Change the way ADW_CARRIER is allocated and handled.
Increased ADW_MAX_CCB to 63 and ADW_MAX_CARRIER to 253
Print WDTR/SDTR negotiation result per target
Protect AdvISR() inside splbio()/splx() pair
Add a pending queue to keep track of all the CCBs that are being executed by the host adapter.
Rewrote timeout handler in a more efficient way:
After 3 timeout now the SCSI is resetted and all pending queues not completed are now reenqueued in the waiting queue so to get executed just after the BUS Reset (hoping that resetting the SCSI BUS and reinitializing the adapter could solve the problem).
 1.8 30-Apr-2000  dante Add new microcode for all of the supported boards.
Fix minor glitches.
Add preliminary support for ASB-3940U3W host adapters; it might work w/ autotermination on.
ASB-3940U3W support is not yet tested due to lack of board.
 1.7 03-Feb-2000  dante Add AdvanSys U2W (LVD) boards support
 1.6 16-Aug-1999  thorpej branches: 1.6.2;
Fix several LP64 problems, and clear up kernel pointer vs. physical
address confusion. This driver now works on the Alpha.
 1.5 04-Mar-1999  dante fix second level interrupt handler to allow 64 bits pointers
 1.4 23-Feb-1999  dante Fixed AdvanSys Ultra Wide driver to work on Alpha.
 1.3 09-Dec-1998  thorpej Update for changed scsipi_xfer struct.
 1.2 19-Nov-1998  thorpej Adapt to the new scsipi_adapter interface.
 1.1 26-Sep-1998  dante Add support for AdvanSys Ultra Wide boards ABP-9xxUW
 1.6.2.2 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.6.2.1 19-Oct-1999  thorpej Adapt to scsipi API changes.
 1.12.2.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.14.2.1 21-Jun-2001  nathanw Catch up to -current.
 1.15.32.2 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.15.32.1 12-Feb-2005  yamt sync with head.
 1.15.30.1 29-Apr-2005  kent sync with -current
 1.15.22.2 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.15.22.1 04-Feb-2005  skrll Sync with HEAD.
 1.19.110.1 30-Oct-2012  yamt sync with head
 1.20.2.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.21.44.1 18-Dec-2019  martin Pull up following revision(s) (requested by tsutsui in ticket #570):

sys/compat/netbsd32/netbsd32_compat_50_sysv.c: revision 1.3
sys/dev/raidframe/rf_compat50.h: revision 1.6
sys/arch/emips/emips/bus_space.c: revision 1.3
sys/compat/net/if.h: revision 1.5
sys/arch/emips/stand/common/bootinfo.c: revision 1.2
sys/compat/common/sysv_msg_50.c: revision 1.5
sys/compat/common/kern_time_30.c: revision 1.8
sys/arch/emips/stand/common/bootinfo.h: revision 1.2
sys/arch/ia64/include/bus.h: revision 1.4
sys/arch/ia64/ia64/bus_space.c: revision 1.2
sys/compat/common/sysv_shm_50.c: revision 1.5
sys/dev/ic/adw.h: revision 1.15
sys/compat/common/uipc_syscalls_50.c: revision 1.10
sys/arch/emips/ebus/flash_ebus.c: revision 1.22
sys/dev/ic/adv.h: revision 1.15
sys/dev/ic/adwmcode.c: revision 1.18
sys/dev/ic/advlib.c: revision 1.29
sys/arch/hpcarm/include/kloader.h: revision 1.3
sys/dev/usb/uberry.c: revision 1.16
sys/compat/common/sysv_sem_50.c: revision 1.5
sys/compat/netbsd32/netbsd32_compat_50.c: revision 1.43
sys/dev/ic/advlib.h: revision 1.21
sys/dev/ic/adv.c: revision 1.50
sys/compat/netinet6/in6_var.h: revision 1.5
sys/arch/hpc/stand/hpcboot/arm/arm_sa1100_asm.asm: revision 1.2
sys/arch/emips/include/loadfile_machdep.h: revision 1.3
sys/arch/emips/stand/common/prom_iface.c: revision 1.7
sys/dev/ic/adw.c: revision 1.56
sys/dev/ic/adwmcode.h: revision 1.12
sys/dev/ic/advmcode.c: revision 1.10
sys/arch/emips/ebus/ace_ebus.c: revision 1.22
sys/compat/netbsd32/netbsd32_compat_60.c: revision 1.5
sys/dev/raidframe/rf_compat50.c: revision 1.13
sys/arch/x68k/dev/intiovar.h: revision 1.15
sys/dev/usb/uipad.c: revision 1.8
sys/arch/zaurus/include/kloader.h: revision 1.3
sys/arch/emips/stand/common/bootxx.c: revision 1.2
sys/dev/ic/adwlib.h: revision 1.23
sys/dev/ic/adwlib.c: revision 1.44
sys/compat/netbsd32/netbsd32_compat_16.c: revision 1.3
sys/arch/amigappc/include/intr.h: revision 1.27
sys/arch/x68k/dev/mfp.c: revision 1.27
sys/arch/arm/at91/at91dbgu.c: revision 1.17
sys/dev/ic/advmcode.h: revision 1.7
sys/compat/ultrix/ultrix_exec.h: revision 1.7
sys/compat/common/vfs_syscalls_50.c: revision 1.24
sys/arch/mips/cavium/octeon_dma.c: revision 1.3
sys/arch/hpc/stand/hpcboot/arm/arm_pxa2x0_asm.asm: revision 1.2

Remove clause 3 and 4 from TNF licenses.
Ok'ed by martin@ in PR/54760.

Remove clause 3 and 4 leftovers from TNF licenses in more sources.
Confirmed by martin@ in PR/54760.
 1.21.38.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.21.38.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.1 20-Nov-2000  bouyer branches: 1.1.2;
file adwlib.h.orig was initially added on branch thorpej_scsipi.
 1.1.2.2 20-Nov-2000  bouyer Ops, these shouldn't be there !
 1.1.2.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.19 25-Sep-2022  thorpej Remove unnecessary include of <sys/malloc.h>.
 1.18 15-Dec-2019  tsutsui Remove clause 3 and 4 leftovers from TNF licenses in more sources.

Confirmed by martin@ in PR/54760.
 1.17 23-Nov-2009  rmind branches: 1.17.64; 1.17.70;
Remove some unecessary includes sys/user.h header.
 1.16 14-Mar-2009  dsl Change about 4500 of the K&R function definitions to ANSI ones.
There are still about 1600 left, but they have ',' or /* ... */
in the actual variable definitions - which my awk script doesn't handle.
There are also many that need () -> (void).
(The script does handle misordered arguments.)
 1.15 19-Oct-2007  ad branches: 1.15.20; 1.15.28; 1.15.34;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.14 11-Dec-2005  christos branches: 1.14.30; 1.14.44; 1.14.46; 1.14.50;
merge ktrace-lwp.
 1.13 27-Feb-2005  perry branches: 1.13.4;
nuke trailing whitespace
 1.12 13-Feb-2004  wiz branches: 1.12.8; 1.12.10;
Uppercase CPU, plural is CPUs.
 1.11 21-Oct-2003  fvdl Correct NULL abuse.
 1.10 15-Nov-2001  lukem branches: 1.10.16;
don't need <sys/types.h> when including <sys/param.h>
 1.9 13-Nov-2001  lukem add/cleanup RCSID
 1.8 07-Jul-2001  thorpej branches: 1.8.2;
bzero -> memset
 1.7 28-Jun-2000  mrg branches: 1.7.2;
remove include of <vm/vm.h>. <vm/vm.h> -> <uvm/uvm_extern.h>
 1.6 26-Jun-2000  mrg remove redundant vm includes.
 1.5 27-May-2000  dante Change AdwInitCarriers in adwmcode.c
Add new AdwInitCarriers prototype in adwmcode.h
All of the supported adapters are now initialized calling a unique common
function
 1.4 26-May-2000  dante branches: 1.4.2;
Fix a bug introduced in last commit which caused a painc due to
re-enqueueing an already free ccb.
Prepare the background to have a unique initialization function for
all of the supported host adapters.
Rename a lot of #define in a more sane way.
Move Carriers initialization and defines in adwmcode.{c,h}
Don't lose Carrier nodes in case of a BUS/Chip reset explicitly invoked
after a DMA failure.

XXX - DMA failure still arise when AdvanSys U[2]W host adapters are used
in conjunction with Intel 82443BX Host Bridge/Controller (rev. 0x03).
!?!Have to understand why!?!
 1.3 30-Apr-2000  dante Add new microcode for all of the supported boards.
Fix minor glitches.
Add preliminary support for ASB-3940U3W host adapters; it might work w/ autotermination on.
ASB-3940U3W support is not yet tested due to lack of board.
 1.2 03-Feb-2000  dante Add AdvanSys U2W (LVD) boards support
 1.1 26-Sep-1998  dante branches: 1.1.12;
Add support for AdvanSys Ultra Wide boards ABP-9xxUW
 1.1.12.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.4.2.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.7.2.3 08-Jan-2002  nathanw Catch up to -current.
 1.7.2.2 14-Nov-2001  nathanw Catch up to -current.
 1.7.2.1 24-Aug-2001  nathanw Catch up with -current.
 1.8.2.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.10.16.4 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.10.16.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.10.16.2 18-Sep-2004  skrll Sync with HEAD.
 1.10.16.1 03-Aug-2004  skrll Sync with HEAD
 1.12.10.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.12.8.1 29-Apr-2005  kent sync with -current
 1.13.4.1 27-Oct-2007  yamt sync with head.
 1.14.50.1 25-Oct-2007  bouyer Sync with HEAD.
 1.14.46.1 06-Nov-2007  matt sync with HEAD
 1.14.44.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.14.30.1 23-Oct-2007  ad Sync with head.
 1.15.34.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.15.28.1 28-Apr-2009  skrll Sync with HEAD.
 1.15.20.2 11-Mar-2010  yamt sync with head
 1.15.20.1 04-May-2009  yamt sync with head.
 1.17.70.1 18-Dec-2019  martin Pull up following revision(s) (requested by tsutsui in ticket #570):

sys/compat/netbsd32/netbsd32_compat_50_sysv.c: revision 1.3
sys/dev/raidframe/rf_compat50.h: revision 1.6
sys/arch/emips/emips/bus_space.c: revision 1.3
sys/compat/net/if.h: revision 1.5
sys/arch/emips/stand/common/bootinfo.c: revision 1.2
sys/compat/common/sysv_msg_50.c: revision 1.5
sys/compat/common/kern_time_30.c: revision 1.8
sys/arch/emips/stand/common/bootinfo.h: revision 1.2
sys/arch/ia64/include/bus.h: revision 1.4
sys/arch/ia64/ia64/bus_space.c: revision 1.2
sys/compat/common/sysv_shm_50.c: revision 1.5
sys/dev/ic/adw.h: revision 1.15
sys/compat/common/uipc_syscalls_50.c: revision 1.10
sys/arch/emips/ebus/flash_ebus.c: revision 1.22
sys/dev/ic/adv.h: revision 1.15
sys/dev/ic/adwmcode.c: revision 1.18
sys/dev/ic/advlib.c: revision 1.29
sys/arch/hpcarm/include/kloader.h: revision 1.3
sys/dev/usb/uberry.c: revision 1.16
sys/compat/common/sysv_sem_50.c: revision 1.5
sys/compat/netbsd32/netbsd32_compat_50.c: revision 1.43
sys/dev/ic/advlib.h: revision 1.21
sys/dev/ic/adv.c: revision 1.50
sys/compat/netinet6/in6_var.h: revision 1.5
sys/arch/hpc/stand/hpcboot/arm/arm_sa1100_asm.asm: revision 1.2
sys/arch/emips/include/loadfile_machdep.h: revision 1.3
sys/arch/emips/stand/common/prom_iface.c: revision 1.7
sys/dev/ic/adw.c: revision 1.56
sys/dev/ic/adwmcode.h: revision 1.12
sys/dev/ic/advmcode.c: revision 1.10
sys/arch/emips/ebus/ace_ebus.c: revision 1.22
sys/compat/netbsd32/netbsd32_compat_60.c: revision 1.5
sys/dev/raidframe/rf_compat50.c: revision 1.13
sys/arch/x68k/dev/intiovar.h: revision 1.15
sys/dev/usb/uipad.c: revision 1.8
sys/arch/zaurus/include/kloader.h: revision 1.3
sys/arch/emips/stand/common/bootxx.c: revision 1.2
sys/dev/ic/adwlib.h: revision 1.23
sys/dev/ic/adwlib.c: revision 1.44
sys/compat/netbsd32/netbsd32_compat_16.c: revision 1.3
sys/arch/amigappc/include/intr.h: revision 1.27
sys/arch/x68k/dev/mfp.c: revision 1.27
sys/arch/arm/at91/at91dbgu.c: revision 1.17
sys/dev/ic/advmcode.h: revision 1.7
sys/compat/ultrix/ultrix_exec.h: revision 1.7
sys/compat/common/vfs_syscalls_50.c: revision 1.24
sys/arch/mips/cavium/octeon_dma.c: revision 1.3
sys/arch/hpc/stand/hpcboot/arm/arm_pxa2x0_asm.asm: revision 1.2

Remove clause 3 and 4 from TNF licenses.
Ok'ed by martin@ in PR/54760.

Remove clause 3 and 4 leftovers from TNF licenses in more sources.
Confirmed by martin@ in PR/54760.
 1.17.64.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.12 15-Dec-2019  tsutsui Remove clause 3 and 4 leftovers from TNF licenses in more sources.

Confirmed by martin@ in PR/54760.
 1.11 11-Dec-2005  christos branches: 1.11.164; 1.11.170;
merge ktrace-lwp.
 1.10 27-Feb-2005  perry nuke trailing whitespace
 1.9 04-Feb-2005  perry de-__P
 1.8 21-Feb-2003  tsutsui branches: 1.8.2; 1.8.10; 1.8.12;
hz -> Hz
 1.7 29-Aug-2001  briggs Ensure that data accessed by the ADW driver in memory is in
little-endian byte-order. This should work out to be a no-op
for LE systems, and allows BE systems to use the board.

Tested on PPC, reviewed by Dante.

NOTE: The board/microcode does have a BIG_ENDIAN mode of operation,
but it's not well-documented. That might be interesting to investigate
at some point in the future, though.
 1.6 18-Jan-2001  jdolecek branches: 1.6.2; 1.6.4;
constify
 1.5 27-May-2000  dante Change AdwInitCarriers in adwmcode.c
Add new AdwInitCarriers prototype in adwmcode.h
All of the supported adapters are now initialized calling a unique common
function
 1.4 26-May-2000  dante branches: 1.4.2;
Fix a bug introduced in last commit which caused a painc due to
re-enqueueing an already free ccb.
Prepare the background to have a unique initialization function for
all of the supported host adapters.
Rename a lot of #define in a more sane way.
Move Carriers initialization and defines in adwmcode.{c,h}
Don't lose Carrier nodes in case of a BUS/Chip reset explicitly invoked
after a DMA failure.

XXX - DMA failure still arise when AdvanSys U[2]W host adapters are used
in conjunction with Intel 82443BX Host Bridge/Controller (rev. 0x03).
!?!Have to understand why!?!
 1.3 30-Apr-2000  dante Add new microcode for all of the supported boards.
Fix minor glitches.
Add preliminary support for ASB-3940U3W host adapters; it might work w/ autotermination on.
ASB-3940U3W support is not yet tested due to lack of board.
 1.2 03-Feb-2000  dante Add AdvanSys U2W (LVD) boards support
 1.1 26-Sep-1998  dante branches: 1.1.12;
Add support for AdvanSys Ultra Wide boards ABP-9xxUW
 1.1.12.2 11-Feb-2001  bouyer Sync with HEAD.
 1.1.12.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.4.2.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.6.4.1 13-Sep-2001  thorpej Update the kqueue branch to HEAD.
 1.6.2.1 21-Sep-2001  nathanw Catch up to -current.
 1.8.12.2 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.8.12.1 12-Feb-2005  yamt sync with head.
 1.8.10.1 29-Apr-2005  kent sync with -current
 1.8.2.2 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.8.2.1 04-Feb-2005  skrll Sync with HEAD.
 1.11.170.1 18-Dec-2019  martin Pull up following revision(s) (requested by tsutsui in ticket #570):

sys/compat/netbsd32/netbsd32_compat_50_sysv.c: revision 1.3
sys/dev/raidframe/rf_compat50.h: revision 1.6
sys/arch/emips/emips/bus_space.c: revision 1.3
sys/compat/net/if.h: revision 1.5
sys/arch/emips/stand/common/bootinfo.c: revision 1.2
sys/compat/common/sysv_msg_50.c: revision 1.5
sys/compat/common/kern_time_30.c: revision 1.8
sys/arch/emips/stand/common/bootinfo.h: revision 1.2
sys/arch/ia64/include/bus.h: revision 1.4
sys/arch/ia64/ia64/bus_space.c: revision 1.2
sys/compat/common/sysv_shm_50.c: revision 1.5
sys/dev/ic/adw.h: revision 1.15
sys/compat/common/uipc_syscalls_50.c: revision 1.10
sys/arch/emips/ebus/flash_ebus.c: revision 1.22
sys/dev/ic/adv.h: revision 1.15
sys/dev/ic/adwmcode.c: revision 1.18
sys/dev/ic/advlib.c: revision 1.29
sys/arch/hpcarm/include/kloader.h: revision 1.3
sys/dev/usb/uberry.c: revision 1.16
sys/compat/common/sysv_sem_50.c: revision 1.5
sys/compat/netbsd32/netbsd32_compat_50.c: revision 1.43
sys/dev/ic/advlib.h: revision 1.21
sys/dev/ic/adv.c: revision 1.50
sys/compat/netinet6/in6_var.h: revision 1.5
sys/arch/hpc/stand/hpcboot/arm/arm_sa1100_asm.asm: revision 1.2
sys/arch/emips/include/loadfile_machdep.h: revision 1.3
sys/arch/emips/stand/common/prom_iface.c: revision 1.7
sys/dev/ic/adw.c: revision 1.56
sys/dev/ic/adwmcode.h: revision 1.12
sys/dev/ic/advmcode.c: revision 1.10
sys/arch/emips/ebus/ace_ebus.c: revision 1.22
sys/compat/netbsd32/netbsd32_compat_60.c: revision 1.5
sys/dev/raidframe/rf_compat50.c: revision 1.13
sys/arch/x68k/dev/intiovar.h: revision 1.15
sys/dev/usb/uipad.c: revision 1.8
sys/arch/zaurus/include/kloader.h: revision 1.3
sys/arch/emips/stand/common/bootxx.c: revision 1.2
sys/dev/ic/adwlib.h: revision 1.23
sys/dev/ic/adwlib.c: revision 1.44
sys/compat/netbsd32/netbsd32_compat_16.c: revision 1.3
sys/arch/amigappc/include/intr.h: revision 1.27
sys/arch/x68k/dev/mfp.c: revision 1.27
sys/arch/arm/at91/at91dbgu.c: revision 1.17
sys/dev/ic/advmcode.h: revision 1.7
sys/compat/ultrix/ultrix_exec.h: revision 1.7
sys/compat/common/vfs_syscalls_50.c: revision 1.24
sys/arch/mips/cavium/octeon_dma.c: revision 1.3
sys/arch/hpc/stand/hpcboot/arm/arm_pxa2x0_asm.asm: revision 1.2

Remove clause 3 and 4 from TNF licenses.
Ok'ed by martin@ in PR/54760.

Remove clause 3 and 4 leftovers from TNF licenses in more sources.
Confirmed by martin@ in PR/54760.
 1.11.164.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.66 25-Sep-2022  thorpej Remove unnecessary include of <sys/malloc.h>.
 1.65 07-Aug-2021  thorpej Merge thorpej-cfargs2.
 1.64 24-Apr-2021  thorpej branches: 1.64.8;
Merge thorpej-cfargs branch:

Simplify and make extensible the config_search() / config_found() /
config_attach() interfaces: rather than having different variants for
which arguments you want pass along, just have a single call that
takes a variadic list of tag-value arguments.

Adjust all call sites:
- Simplify wherever possible; don't pass along arguments that aren't
actually needed.
- Don't be explicit about what interface attribute is attaching if
the device only has one. (More simplification.)
- Add a config_probe() function to be used in indirect configuiration
situations, making is visibly easier to see when indirect config is
in play, and allowing for future change in semantics. (As of now,
this is just a wrapper around config_match(), but that is an
implementation detail.)

Remove unnecessary or redundant interface attributes where they're not
needed.

There are currently 5 "cfargs" defined:
- CFARG_SUBMATCH (submatch function for direct config)
- CFARG_SEARCH (search function for indirect config)
- CFARG_IATTR (interface attribte)
- CFARG_LOCATORS (locators array)
- CFARG_DEVHANDLE (devhandle_t - wraps OFW, ACPI, etc. handles)

...and a sentinel value CFARG_EOL.

Add some extra sanity checking to ensure that interface attributes
aren't ambiguous.

Use CFARG_DEVHANDLE in MI FDT, OFW, and ACPI code, and macppc and shark
ports to associate those device handles with device_t instance. This
will trickle trough to more places over time (need back-end for pre-OFW
Sun OBP; any others?).
 1.63 14-Jul-2016  msaitoh branches: 1.63.34;
KNF. No functional change.
 1.62 11-Jul-2016  msaitoh KNF. No functional change.
 1.61 13-Nov-2010  uebayasi branches: 1.61.18; 1.61.36;
Don't pull in the whole uvm(9) API to access only PAGE_SIZE and
some other constants. These are provided by sys/param.h now.
 1.60 23-Nov-2009  rmind branches: 1.60.4;
Remove some unecessary includes sys/user.h header.
 1.59 21-Sep-2009  tsutsui Split device_t/softc. Tested on AHA-1542CF.
 1.58 14-Mar-2009  dsl Change about 4500 of the K&R function definitions to ANSI ones.
There are still about 1600 left, but they have ',' or /* ... */
in the actual variable definitions - which my awk script doesn't handle.
There are also many that need () -> (void).
(The script does handle misordered arguments.)
 1.57 28-Apr-2008  martin branches: 1.57.8; 1.57.14;
Remove clause 3 and 4 from TNF licenses
 1.56 08-Apr-2008  cegger branches: 1.56.2; 1.56.4;
use aprint_*_dev and device_xname
 1.55 29-Mar-2008  ad Check the status registers for garbage before wasting seconds trying to
reset a board that isn't present.
 1.54 19-Oct-2007  ad branches: 1.54.16;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.53 04-Mar-2007  christos branches: 1.53.2; 1.53.14; 1.53.16; 1.53.20;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.52 16-Nov-2006  christos branches: 1.52.4;
__unused removal on arguments; approved by core.
 1.51 12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.50 17-Aug-2006  christos branches: 1.50.2; 1.50.4;
Fix all the -D*DEBUG* code that it was rotting away and did not even compile.
Mostly from Arnaud Lacombe, many thanks!
 1.49 24-Dec-2005  perry branches: 1.49.4; 1.49.8;
Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.48 11-Dec-2005  christos merge ktrace-lwp.
 1.47 27-Feb-2005  perry branches: 1.47.4;
nuke trailing whitespace
 1.46 21-Feb-2005  thorpej Part 1 of a cleanup pass over the SCSI subsystem. The aim is to name
everything "scsi_*", since we really are talking about the SCSI command
set, ATAPI transport not withstanding. Improve the names of many structures,
and prepend "SCSI_" onto all SCSI command opcodes. Place items described
by the SCSI Primary Commands document into scsi_spc.h.
 1.45 07-Dec-2004  thorpej branches: 1.45.2; 1.45.4;
Don't use "struct scsi_generic" in a hardware-defined structure. Instead,
use an array of 12 bytes. Check the incoming CDB to see that it will fit,
and print and error and fail the command if it won't.
 1.44 24-Aug-2004  thorpej Use ANSI function decls and more use of static.
 1.43 02-Nov-2003  wiz branches: 1.43.4;
Fix some typos. From Tom Cosgrove via jmc@openbsd.
 1.42 31-Oct-2003  reinoud Rollback
 1.41 31-Oct-2003  reinoud Make it compile under gcc 2.95 again. I guess the initialisers were
stripped in the NULL = 0 -> NULL = (void *) 0 conversion.
 1.40 03-May-2003  wiz branches: 1.40.2;
DMA, not dma nor Dma.
 1.39 05-Apr-2002  bouyer Implement mstohz() as discussed on tech-kern, and use it in SCSI drivers
to convert xs->timeout to callout() parameter.
 1.38 15-Nov-2001  lukem don't need <sys/types.h> when including <sys/param.h>
 1.37 13-Nov-2001  lukem add/cleanup RCSID
 1.36 20-Aug-2001  wiz precede, not preceed.
 1.35 19-Jul-2001  thorpej Use BUS_DMA_READ and BUS_DMA_WRITE in some obvious places.
 1.34 07-Jul-2001  thorpej branches: 1.34.2;
bzero -> memset
 1.33 07-Jul-2001  thorpej bcopy -> memcpy
 1.32 02-May-2001  bouyer Don't forget to init chan_bustype.
 1.31 25-Apr-2001  bouyer Pull up the thorpej_scsipi branch to main branch.
This is a completely rewritten scsipi_xfer execution engine, and the
associated changes to HBA drivers. Overview of changes & features:
- All xfers are queued in the mid-layer, rather than doing so in an
ad-hoc fashion in individual adapter drivers.
- Adapter/channel resource management in the mid-layer, avoids even trying
to start running an xfer if the adapter/channel doesn't have the resources.
- Better communication between the mid-layer and the adapters.
- Asynchronous event notification mechanism from adapter to mid-layer and
peripherals.
- Better peripheral queue management: freeze/thaw, sorted requeueing during
recovery, etc.
- Clean separation of peripherals, adapters, and adapter channels (no more
scsipi_link).
- Kernel thread for each scsipi_channel makes error recovery much easier
(no more dealing with interrupt context when recovering from an error).
- Mid-layer support for tagged queueing: commands can have the tag type
set explicitly, tag IDs are allocated in the mid-layer (thus eliminating
the need to use buggy tag ID allocation schemes in many adapter drivers).
- support for QUEUE FULL and CHECK CONDITION status in mid-layer; the command
will be requeued, or a REQUEST SENSE will be sent as appropriate.

Just before the merge syssrc has been tagged with thorpej_scsipi_beforemerge
 1.30 07-Mar-2001  thorpej Add BUS_DMA_STREAMING to data transfer maps.
 1.29 14-Nov-2000  thorpej branches: 1.29.2;
NBPG -> PAGE_SIZE
 1.28 30-Mar-2000  augustss Remove register declarations.
 1.27 23-Mar-2000  thorpej Remove bogus callout_init(), pointed out by soren@netbsd.org.
 1.26 23-Mar-2000  thorpej New callout mechanism with two major improvements over the old
timeout()/untimeout() API:
- Clients supply callout handle storage, thus eliminating problems of
resource allocation.
- Insertion and removal of callouts is constant time, important as
this facility is used quite a lot in the kernel.

The old timeout()/untimeout() API has been removed from the kernel.
 1.25 12-Feb-2000  thorpej If we got an xfer from our backlog queue, don't allow sleeping; we're in
interrupt context.

XXX This is fixed properly in the thorpej_scsipi branch, but that won't
be ready for 1.5, I don't think.
 1.24 30-Sep-1999  thorpej branches: 1.24.2;
Update for SCSPI changes.
 1.23 15-Apr-1999  mjl Correct wrong board IDs (used ID definition from FreeBSD)
 1.22 09-Dec-1998  thorpej branches: 1.22.6;
Update for changed scsipi_xfer struct.
 1.21 05-Dec-1998  mjacob Update HBAs to incorporate the new max_lun property.
 1.20 19-Nov-1998  thorpej Adapt to the new scsipi_adapter interface.
 1.19 10-Oct-1998  thorpej Garbage-collect the open_target_lu and close_target_lu entry points from
struct scsipi_adapter; they were not used.

Add a scsipi_ioctl entry point to struct scsipi_adapter. This will be
used to issue ioctl commands to the host adapters.

Inspired by PR #6090, from Matt Jacob.
 1.18 17-Aug-1998  mycroft Assign my copyrights to TNF.
 1.17 04-Jul-1998  jonathan defopt DDB.
 1.16 29-Apr-1998  thorpej Sync with recent change made to bha.c by mjacob:

Cute buglet: you can end up with zero CCBs if there were no targets
seen by the adapter. Always leave a minimum so the adapter can
finish attaching- it may be there w/o targets for a reason.
 1.15 09-Feb-1998  thorpej - Perform all necessary bus_dmamap_sync() operations.
- Greatly simplify allocation and DMA mapping of the mailbox and ccbs.
- Be more robust against resource shortage errors, and report errors better.
 1.14 04-Feb-1998  thorpej Add offset and length parameters to bus_dmamap_sync(), used for specifiying
partial syncs of a DMA mapping.
 1.13 04-Feb-1998  thorpej Add dm_mapsize to bus_dmamap_t and rename BUS_DMAMEM_NOSYNC to
BUS_DMA_COHERENT.
 1.12 30-Jan-1998  thorpej Use offsetof() from libkern.h
 1.11 12-Jan-1998  thorpej Adjust for config changes.
 1.10 04-Nov-1997  thorpej Implement a simple queueing mechanism that makes these drivers much
more robust in resource shortage situations, basically identical to
code I added to the "ahc" driver some time ago.

Thanks to Brad Spencer for the testing help.
 1.9 28-Oct-1997  thorpej When creating ccbs, be a little more informative about why we couldn't
should creation/initialization of a ccb fail. Also, don't panic in
these situations. Instead, simply return an error condition and allow
the caller to deal with it. It may be the case that we were able to
create one ccb what we can grab, and continue to hobble along.
 1.8 28-Oct-1997  thorpej Fix a couple of errors in aha_create_ccbs():
- Don't ever let the number of CCBs be creater than AHA_CCB_MAX.
- Fix a fencepost that caused the last CCB allocated to never be put
on the freelist.
 1.7 27-Aug-1997  bouyer branches: 1.7.4;
Merge scsipi branch in the mainline. This add support for ATAPI devices
(currently only CD-ROM drives on i386). The sys/dev/scsipi system provides 2
busses to which devices can attach (scsibus and atapibus). This needed to
change some include files and structure names in the low level scsi drivers.
 1.6 25-Jun-1997  hannken branches: 1.6.2; 1.6.4;
Adjust the number of ccbs allocated during initialization.
Every ccb locks 64k of memory for dma buffers.
Instead of AHA_CCB_MAX ccbs using 1MByte only sc_link.openings ccbs
per device are allocated. Thus we now use only 128KByte per device present.
 1.5 06-Jun-1997  thorpej Pull thorpej-bus-dma branch into mainline.
 1.4 28-Mar-1997  mycroft branches: 1.4.2;
Use a temporary data structure for holding probe information, rather than a
full softc.
 1.3 15-Mar-1997  is New ARP system, supports IPv4 over any hardware link.

Some of the stuff (e.g., rarpd, bootpd, dhcpd etc., libsa) still will
only support Ethernet. Tcpdump itself should be ok, but libpcap needs
lot of work.

For the detailed change history, look at the commit log entries for
the is-newarp branch.
 1.2 26-Feb-1997  sommerfe branches: 1.2.2;
Fix PR3260: cosmetic glitch in aha autoconf output.
 1.1 07-Feb-1997  mycroft Move the aha ISA probe functions into a separate file.
 1.2.2.2 12-Mar-1997  is Merge in changes from Trunk
 1.2.2.1 26-Feb-1997  is file aha.c was added on branch is-newarp on 1997-03-12 21:22:00 +0000
 1.4.2.2 17-May-1997  thorpej Update for bus_dmamem_alloc() changes.
 1.4.2.1 13-May-1997  thorpej Convert to use bus dma.
 1.6.4.1 27-Aug-1997  thorpej Update marc-pcmcia branch from trunk.
 1.6.2.1 01-Jul-1997  bouyer Updates for new scsipi subsystem. Actally known to work on i386 and sparc.
 1.7.4.2 04-Nov-1997  thorpej Pull up from trunk: add a queueing mechanism to make this much more
robust in resource shortage conditions.
 1.7.4.1 28-Oct-1997  thorpej Pull up from trunk: fix fencepost errors in ccb allocation and be
more verbose/robust when ccb allocation/initialization fails.
 1.22.6.1 21-Jun-1999  thorpej Sync w/ -current.
 1.24.2.8 12-Mar-2001  bouyer Sync with HEAD.
 1.24.2.7 22-Nov-2000  bouyer Sync with HEAD.
 1.24.2.6 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.24.2.5 01-Nov-1999  thorpej Fixup the SC_DEBUG() stuff for the new world order.
 1.24.2.4 26-Oct-1999  thorpej Update for:

Deal a little more gracefully with the fact that xfer mode parameters
are for the I_T Nexus, and make all xfer mode updates `async events'.
 1.24.2.3 20-Oct-1999  thorpej Eliminate sleeping from adapter routines.
 1.24.2.2 19-Oct-1999  thorpej Don't sleep waiting for a CCB; if we get to the CCB allocation phase, we're
guaranteed to have one.
 1.24.2.1 19-Oct-1999  thorpej Adapt to scsipi API changes.
 1.29.2.6 17-Apr-2002  nathanw Catch up to -current.
 1.29.2.5 08-Jan-2002  nathanw Catch up to -current.
 1.29.2.4 14-Nov-2001  nathanw Catch up to -current.
 1.29.2.3 24-Aug-2001  nathanw Catch up with -current.
 1.29.2.2 21-Jun-2001  nathanw Catch up to -current.
 1.29.2.1 09-Apr-2001  nathanw Catch up with -current.
 1.34.2.4 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.34.2.3 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.34.2.2 25-Aug-2001  thorpej Merge Aug 24 -current into the kqueue branch.
 1.34.2.1 03-Aug-2001  lukem update to -current
 1.40.2.6 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.40.2.5 18-Dec-2004  skrll Sync with HEAD.
 1.40.2.4 21-Sep-2004  skrll Fix the sync with head I botched.
 1.40.2.3 18-Sep-2004  skrll Sync with HEAD.
 1.40.2.2 25-Aug-2004  skrll Sync with HEAD.
 1.40.2.1 03-Aug-2004  skrll Sync with HEAD
 1.43.4.1 02-Apr-2005  he Pull up revision 1.45 (requested by thorpej in ticket #1022):
Don't use "struct scsi_generic" in a hardware-defined structure.
Instead, use an array of 12 bytes. Check the incoming CDB to see
that it will fit, and print and error and fail the command if it
won't.
 1.45.4.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.45.2.1 29-Apr-2005  kent sync with -current
 1.47.4.4 27-Oct-2007  yamt sync with head.
 1.47.4.3 03-Sep-2007  yamt sync with head.
 1.47.4.2 30-Dec-2006  yamt sync with head.
 1.47.4.1 21-Jun-2006  yamt sync with head.
 1.49.8.1 03-Sep-2006  yamt sync with head.
 1.49.4.1 09-Sep-2006  rpaulo sync with head
 1.50.4.2 10-Dec-2006  yamt sync with head.
 1.50.4.1 22-Oct-2006  yamt sync with head
 1.50.2.1 18-Nov-2006  ad Sync with head.
 1.52.4.1 12-Mar-2007  rmind Sync with HEAD.
 1.53.20.1 25-Oct-2007  bouyer Sync with HEAD.
 1.53.16.1 06-Nov-2007  matt sync with HEAD
 1.53.14.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.53.2.1 23-Oct-2007  ad Sync with head.
 1.54.16.2 02-Jun-2008  mjf Sync with HEAD.
 1.54.16.1 03-Apr-2008  mjf Sync with HEAD.
 1.56.4.3 11-Mar-2010  yamt sync with head
 1.56.4.2 04-May-2009  yamt sync with head.
 1.56.4.1 16-May-2008  yamt sync with head.
 1.56.2.1 18-May-2008  yamt sync with head.
 1.57.14.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.57.8.1 28-Apr-2009  skrll Sync with HEAD.
 1.60.4.1 05-Mar-2011  rmind sync with head
 1.61.36.1 05-Oct-2016  skrll Sync with HEAD
 1.61.18.1 03-Dec-2017  jdolecek update from HEAD
 1.63.34.1 21-Mar-2021  thorpej Give config_found() the same variadic arguments treatment as
config_search(). This commit only adds the CFARG_EOL sentinel
to the existing config_found() calls. Conversion of config_found_sm_loc()
and config_found_ia() call sites will be in subsequent commits.
 1.64.8.1 04-Aug-2021  thorpej Adapt to CFARGS().
 1.1 20-Nov-2000  bouyer branches: 1.1.2;
file aha.c.orig was initially added on branch thorpej_scsipi.
 1.1.2.2 20-Nov-2000  bouyer Ops, these shouldn't be there !
 1.1.2.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.15 10-May-2008  martin Years in license are four digits
 1.14 28-Apr-2008  martin branches: 1.14.2;
Remove clause 3 and 4 from TNF licenses
 1.13 29-Mar-2008  ad branches: 1.13.2; 1.13.4;
Check the status registers for garbage before wasting seconds trying to
reset a board that isn't present.
 1.12 11-Dec-2005  christos branches: 1.12.70;
merge ktrace-lwp.
 1.11 21-Feb-2005  thorpej Part 1 of a cleanup pass over the SCSI subsystem. The aim is to name
everything "scsi_*", since we really are talking about the SCSI command
set, ATAPI transport not withstanding. Improve the names of many structures,
and prepend "SCSI_" onto all SCSI command opcodes. Place items described
by the SCSI Primary Commands document into scsi_spc.h.
 1.10 07-Dec-2004  thorpej branches: 1.10.2; 1.10.4;
Don't use "struct scsi_generic" in a hardware-defined structure. Instead,
use an array of 12 bytes. Check the incoming CDB to see that it will fit,
and print and error and fail the command if it won't.
 1.9 15-Apr-1999  mjl branches: 1.9.36; 1.9.42;
Correct wrong board IDs (used ID definition from FreeBSD)
 1.8 17-Aug-1998  mycroft branches: 1.8.8;
Assign my copyrights to TNF.
 1.7 09-Feb-1998  thorpej - Perform all necessary bus_dmamap_sync() operations.
- Greatly simplify allocation and DMA mapping of the mailbox and ccbs.
- Be more robust against resource shortage errors, and report errors better.
 1.6 09-Sep-1997  mycroft Make `hashkey' unsigned.
 1.5 27-Aug-1997  bouyer Merge scsipi branch in the mainline. This add support for ATAPI devices
(currently only CD-ROM drives on i386). The sys/dev/scsipi system provides 2
busses to which devices can attach (scsibus and atapibus). This needed to
change some include files and structure names in the low level scsi drivers.
 1.4 25-Jun-1997  hannken branches: 1.4.2; 1.4.4;
Adjust the number of ccbs allocated during initialization.
Every ccb locks 64k of memory for dma buffers.
Instead of AHA_CCB_MAX ccbs using 1MByte only sc_link.openings ccbs
per device are allocated. Thus we now use only 128KByte per device present.
 1.3 06-Jun-1997  thorpej Pull thorpej-bus-dma branch into mainline.
 1.2 15-Mar-1997  is branches: 1.2.2;
New ARP system, supports IPv4 over any hardware link.

Some of the stuff (e.g., rarpd, bootpd, dhcpd etc., libsa) still will
only support Ethernet. Tcpdump itself should be ok, but libpcap needs
lot of work.

For the detailed change history, look at the commit log entries for
the is-newarp branch.
 1.1 07-Feb-1997  mycroft branches: 1.1.4;
Move the aha ISA probe functions into a separate file.
 1.1.4.2 12-Mar-1997  is Merge in changes from Trunk
 1.1.4.1 07-Feb-1997  is file ahareg.h was added on branch is-newarp on 1997-03-12 21:22:05 +0000
 1.2.2.1 13-May-1997  thorpej Convert to use bus dma.
 1.4.4.2 16-Sep-1997  thorpej Update marc-pcmcia branch from trunk.
 1.4.4.1 27-Aug-1997  thorpej Update marc-pcmcia branch from trunk.
 1.4.2.1 01-Jul-1997  bouyer Updates for new scsipi subsystem. Actally known to work on i386 and sparc.
 1.8.8.1 21-Jun-1999  thorpej Sync w/ -current.
 1.9.42.1 02-Apr-2005  he Pull up revision 1.10 (requested by thorpej in ticket #1022):
Don't use "struct scsi_generic" in a hardware-defined structure.
Instead, use an array of 12 bytes. Check the incoming CDB to see
that it will fit, and print and error and fail the command if it
won't.
 1.9.36.2 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.9.36.1 18-Dec-2004  skrll Sync with HEAD.
 1.10.4.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.10.2.1 29-Apr-2005  kent sync with -current
 1.12.70.2 02-Jun-2008  mjf Sync with HEAD.
 1.12.70.1 03-Apr-2008  mjf Sync with HEAD.
 1.13.4.1 16-May-2008  yamt sync with head.
 1.13.2.1 18-May-2008  yamt sync with head.
 1.14.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.15 21-Sep-2009  tsutsui Split device_t/softc. Tested on AHA-1542CF.
 1.14 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.13 11-Dec-2005  christos branches: 1.13.70; 1.13.72; 1.13.74;
merge ktrace-lwp.
 1.12 24-Aug-2004  thorpej Use ANSI function decls and more use of static.
 1.11 25-Apr-2001  bouyer branches: 1.11.22;
Pull up the thorpej_scsipi branch to main branch.
This is a completely rewritten scsipi_xfer execution engine, and the
associated changes to HBA drivers. Overview of changes & features:
- All xfers are queued in the mid-layer, rather than doing so in an
ad-hoc fashion in individual adapter drivers.
- Adapter/channel resource management in the mid-layer, avoids even trying
to start running an xfer if the adapter/channel doesn't have the resources.
- Better communication between the mid-layer and the adapters.
- Asynchronous event notification mechanism from adapter to mid-layer and
peripherals.
- Better peripheral queue management: freeze/thaw, sorted requeueing during
recovery, etc.
- Clean separation of peripherals, adapters, and adapter channels (no more
scsipi_link).
- Kernel thread for each scsipi_channel makes error recovery much easier
(no more dealing with interrupt context when recovering from an error).
- Mid-layer support for tagged queueing: commands can have the tag type
set explicitly, tag IDs are allocated in the mid-layer (thus eliminating
the need to use buggy tag ID allocation schemes in many adapter drivers).
- support for QUEUE FULL and CHECK CONDITION status in mid-layer; the command
will be requeued, or a REQUEST SENSE will be sent as appropriate.

Just before the merge syssrc has been tagged with thorpej_scsipi_beforemerge
 1.10 09-Dec-1998  thorpej branches: 1.10.10; 1.10.22;
Update for changed scsipi_xfer struct.
 1.9 19-Nov-1998  thorpej Adapt to the new scsipi_adapter interface.
 1.8 15-Aug-1998  mycroft Assign my copyrights to TNF.
 1.7 09-Feb-1998  thorpej - Perform all necessary bus_dmamap_sync() operations.
- Greatly simplify allocation and DMA mapping of the mailbox and ccbs.
- Be more robust against resource shortage errors, and report errors better.
 1.6 04-Nov-1997  thorpej Implement a simple queueing mechanism that makes these drivers much
more robust in resource shortage situations, basically identical to
code I added to the "ahc" driver some time ago.

Thanks to Brad Spencer for the testing help.
 1.5 27-Aug-1997  bouyer branches: 1.5.4;
Merge scsipi branch in the mainline. This add support for ATAPI devices
(currently only CD-ROM drives on i386). The sys/dev/scsipi system provides 2
busses to which devices can attach (scsibus and atapibus). This needed to
change some include files and structure names in the low level scsi drivers.
 1.4 06-Jun-1997  thorpej branches: 1.4.2; 1.4.4;
Pull thorpej-bus-dma branch into mainline.
 1.3 28-Mar-1997  mycroft branches: 1.3.2;
Use a temporary data structure for holding probe information, rather than a
full softc.
 1.2 15-Mar-1997  is New ARP system, supports IPv4 over any hardware link.

Some of the stuff (e.g., rarpd, bootpd, dhcpd etc., libsa) still will
only support Ethernet. Tcpdump itself should be ok, but libpcap needs
lot of work.

For the detailed change history, look at the commit log entries for
the is-newarp branch.
 1.1 07-Feb-1997  mycroft branches: 1.1.4;
Move the aha ISA probe functions into a separate file.
 1.1.4.2 12-Mar-1997  is Merge in changes from Trunk
 1.1.4.1 07-Feb-1997  is file ahavar.h was added on branch is-newarp on 1997-03-12 21:22:09 +0000
 1.3.2.1 13-May-1997  thorpej Convert to use bus dma.
 1.4.4.1 27-Aug-1997  thorpej Update marc-pcmcia branch from trunk.
 1.4.2.1 01-Jul-1997  bouyer Updates for new scsipi subsystem. Actally known to work on i386 and sparc.
 1.5.4.1 04-Nov-1997  thorpej Pull up from trunk: add a queueing mechanism to make this much more
robust in resource shortage conditions.
 1.10.22.1 21-Jun-2001  nathanw Catch up to -current.
 1.10.10.1 19-Oct-1999  thorpej Adapt to scsipi API changes.
 1.11.22.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.11.22.2 18-Sep-2004  skrll Sync with HEAD.
 1.11.22.1 25-Aug-2004  skrll Sync with HEAD.
 1.13.74.2 11-Mar-2010  yamt sync with head
 1.13.74.1 16-May-2008  yamt sync with head.
 1.13.72.1 18-May-2008  yamt sync with head.
 1.13.70.1 02-Jun-2008  mjf Sync with HEAD.
 1.1 20-Nov-2000  bouyer branches: 1.1.2;
file ahavar.h.orig was initially added on branch thorpej_scsipi.
 1.1.2.2 20-Nov-2000  bouyer Ops, these shouldn't be there !
 1.1.2.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.108 10-Sep-2023  abs Rework AHCISATA_EXTRA_DELAY for kern/56737

- Remove AHCI_QUIRK_EXTRA_DELAY as issue appears to be drive and
not controller related
- Replace AHCISATA_EXTRA_DELAY with AHCISATA_REMOVE_EXTRA_DELAY,
so defaulting to enabling the extra delay, as the downside of
slower probing on systems which do not need it is less than having
other systems intermittently fail to probe and attach drives
- Also allow disabling extra delay with AHCISATA_EXTRA_DELAY_MS = 0

We should return to this code to work out which of the extra delays
are needed, and how long they need to be. It may be that faster
systems are more likely to trigger the issue (I've only seen it on
a 13th gen i7-13700, though only tested on a limited set)

XXX pullup -10
 1.107 01-Aug-2022  mlelstv branches: 1.107.4;
Revert last accidental commits.
 1.106 01-Aug-2022  mlelstv Also fix shift values for SCT constants.
 1.105 19-Nov-2021  rin ahcisata(4): Introduce AHCI_QUIRK_EXTRA_DELAY quirk for devices that
need extra delays as done by AHCISATA_EXTRA_DELAY option.

Enable this quirk for "C600/X79 AHCI". Also add commented out quirk
entries for "Bay Trail SATA (AHCI)" and "Mobile AHCI SATA Controller",
for which non-reproducible failures worked around by extra delays have
been reported.

500 ms of delays inserted by these option/quirk may be too much. Add
AHCISATA_EXTRA_DELAY_MS option to adjust number of delays in ms, like:

----
options AHCISATA_EXTRA_DELAY_MS=200
----

Thanks prlw1@ and jun@ for testing!
 1.104 10-Nov-2021  msaitoh s/endianess/endianness/
 1.103 11-Oct-2021  jmcneill ahcisata: remove excessive delays from drive probe path

There are a handful of inexplicable 500ms delays introduced to the drive
detect path in this driver, slowing boot. They can be re-enabled with
options AHCISATA_EXTRA_DELAY, but should not be enabled for normal kernels.
If a delay does need to be introduced in these places, the value should
either be more carefully selected or the scope limited to hardware that
requires the extra delay.
 1.102 05-Oct-2021  rin PR kern/56403

Fix kernel freeze for wdc(4) variants with ATAC_CAP_NOIRQ:

(1) Change ata_xfer_ops:c_poll from void to int function. When it returns
ATAPOLL_AGAIN, let ata_xfer_start() iterate itself again.

(2) Let wdc_ata_bio_poll() return ATAPOLL_AGAIN until ATA_ITSDONE is
achieved.

A similar change has been made for mvsata(4) (see mvsata_bio_poll()),
and no functional changes for other devices.

This is how the drivers worked before jdolecek-ncq branch was merged.

Note that this changes are less likely to cause infinite recursion:

(1) wdc_ata_bio_intr() called from wdc_ata_bio_poll() asserts ATA_ITSDONE
in its error handling paths via wdc_ata_bio_done().

(2) Return value from c_start (= wdc_ata_bio_start()) is checked in
ata_xfer_start().

Therefore, errors encountered in ata_xfer_ops:c_poll and c_start routines
terminate the recursion for wdc(4). The situation is similar for mvsata(4).

Still, there is a possibility where ata_xfer_start() takes long time to
finish a normal operation. This can result in a delayed response for lower
priority interrupts. But, I've never observed such a situation, even when
heavy thrashing takes place for swap partition in wd(4).

"Go ahead" by jdolecek@.
 1.101 03-Sep-2021  mrg revert "make ahcisata(4) work on rk3399 (rockpro64)" from 23-06-2021.

this problem is known to affect more than AHCI, and a more general
solution has been commited now.
 1.100 07-Aug-2021  thorpej Merge thorpej-cfargs2.
 1.99 23-Jun-2021  mrg branches: 1.99.2;
make ahcisata(4) work on rk3399 (rockpro64)

on rk3399, a marvell 9230 ahci sata card consistently takes between
1213 and 1216 milliseconds, the ahci spec says this should complete
in 1000 or fewer.

add a "pcie-reset-ms" uint32 property that ahcisata defaults to 1000
if not set, and the rockchip platform code sets to 2000.


ok @jmcneill
 1.98 24-Apr-2021  thorpej branches: 1.98.2;
Merge thorpej-cfargs branch:

Simplify and make extensible the config_search() / config_found() /
config_attach() interfaces: rather than having different variants for
which arguments you want pass along, just have a single call that
takes a variadic list of tag-value arguments.

Adjust all call sites:
- Simplify wherever possible; don't pass along arguments that aren't
actually needed.
- Don't be explicit about what interface attribute is attaching if
the device only has one. (More simplification.)
- Add a config_probe() function to be used in indirect configuiration
situations, making is visibly easier to see when indirect config is
in play, and allowing for future change in semantics. (As of now,
this is just a wrapper around config_match(), but that is an
implementation detail.)

Remove unnecessary or redundant interface attributes where they're not
needed.

There are currently 5 "cfargs" defined:
- CFARG_SUBMATCH (submatch function for direct config)
- CFARG_SEARCH (search function for indirect config)
- CFARG_IATTR (interface attribte)
- CFARG_LOCATORS (locators array)
- CFARG_DEVHANDLE (devhandle_t - wraps OFW, ACPI, etc. handles)

...and a sentinel value CFARG_EOL.

Add some extra sanity checking to ensure that interface attributes
aren't ambiguous.

Use CFARG_DEVHANDLE in MI FDT, OFW, and ACPI code, and macppc and shark
ports to associate those device handles with device_t instance. This
will trickle trough to more places over time (need back-end for pre-OFW
Sun OBP; any others?).
 1.97 04-Mar-2021  skrll branches: 1.97.2;
Use BUS_ADDR_{LO,HI}32. NFC.
 1.96 04-Mar-2021  skrll Use __BIT(). NFC.
 1.95 11-Jan-2021  skrll KNF
 1.94 29-Dec-2020  skrll Some more whitespace consistency / KNF
 1.93 29-Dec-2020  skrll Function declaration formating whitespace consistency. NFCI.
 1.92 28-Dec-2020  jmcneill Remove the AHCI_QUIRK_SKIP_RESET quirk now that the underlying issue is
fixed.
 1.91 28-Dec-2020  jmcneill Make sure to ack IS after PxIS when polling and when using multiple MSI-X
messages.
 1.90 27-Dec-2020  jmcneill AHCI 1.3.1 section 5.5.3 "Processing Completed Commands" says that we
should clear PxIS before IS.IPS.
 1.89 26-Dec-2020  jmcneill ahci_intr: use ffs in the port bitmask instead of looping over all 32 bits
 1.88 26-Dec-2020  jmcneill AHCI 1.3.1 specification says that it is good practice for system software
to 'zero-out' the memory allocated and referenced by PxCLB and PxFB.
 1.87 25-Dec-2020  skrll Trailing whitespace
 1.86 25-Dec-2020  skrll Use designated initializers for struct ata_bustype
 1.85 20-Dec-2020  jmcneill Retry clearing WDCTL_RST a few times before giving up. Makes SATA work in
Solidrun Honeycomb LX2K.
 1.84 19-Dec-2020  jmcneill ahci_exec_fis: wait for the correct amount of time when AT_WAIT is set
 1.83 13-Apr-2020  jdolecek branches: 1.83.2;
fix use-after-free for ata xfer on bio submission found by KASAN

driver ata_bio hooks read parts of the xfer after ata_exec_xfer()
call in order to determine return value, change so that the hook
doesn't return any value - callers do not care already,
as all I/O requests are asynchronous

this problem was uncovered by recent change for wd(4) to not hold
wd mutex during ata_bio call, the interrupt for the xfer might
thus actually fire immediately

adjust also ata_exec_command driver hooks similarily - remove all
completion and waiting logic from drivers, upper layer ata code
using AT_WAIT/AT_POLL changed to call ata_wait_cmd() itself

PR kern/55169 by Nick Hudson
 1.82 19-Feb-2020  riastradh branches: 1.82.4;
C99 initializers for scsipi_bustype. No functional change intended.
 1.81 18-Jan-2020  simonb Add new AHCI_QUIRK_BADNCQ quick for controllers that have issues with
NCQ on (some) drives. Enable this quirk for ATI (AMD) SB600/SB700
controllers. Alternate fix for kern/54790 and kern/54855.

ok jdolecek@, tested on my SB700 chipset and tsutsui's SB600 chipset.
 1.80 27-Dec-2019  msaitoh branches: 1.80.2;
s/transfered/transferred/
 1.79 22-Dec-2019  jmcneill When resetting a drive, if the command list is running and CLO is not
supported, attempt to stop the drive first and fail gracefully if that
fails instead of triggering a KASSERT on DIAGNOSTIC kernels.
 1.78 29-Sep-2019  jakllsch Use AHCI_RFIS_SYNC in ahci_cmd_complete() AT_READREG case.

Ensures CPU sees the current device to host FIS before parsing.
 1.77 29-Sep-2019  jakllsch Use AHCI_CMDTBL_SYNC in ahci_exec_fis() to ensure hardware sees the
command FIS.
 1.76 29-Sep-2019  jakllsch Ensure cmdh_prdtl is 0 in ahci_do_reset_drive().

(I'm probably just being paranoid here.)
 1.75 07-Apr-2019  bouyer branches: 1.75.4;
If Command List Override is not supported by the controller, the FIS setting
the WDC_RST bit will fail if the drive already has BSY or DRQ set.
In this case, reset the channel and retry the drive reset.
With this, the drive reset will succeed after a atactl sleep command on
a controller without the CLO feature.
 1.74 18-Jan-2019  jdolecek revert rev 1.73 - while it apparently helped Christos case, it re-broke
the disk detection on several other systems, so need something else
 1.73 12-Jan-2019  jdolecek partially back-off rev. 1.68 - when the drive reset for port 15 fails,
on some systems controller isn't actually able to process further commands,
it's really necessary to do explicitely reset for drive 0 too

towards resolution of PR kern/53307
 1.72 07-Dec-2018  jdolecek add optional hook for intr establish when active port is attached, export
ahci_intr_port() in form suitable for interrupt hanlder, and probe for GHC
MRSM flag as courtesy for use by the intr hook

towards multi-vector MSI/MSI-X support
 1.71 20-Nov-2018  jdolecek s/failing/failed/ for the aprint_error()
 1.70 20-Nov-2018  jdolecek also set WDCTL_4BIT for the softreset, seems this one is actually also
required to fully resolve the problem

PR kern/48214 PR kern/53307 PR kern/53524
 1.69 19-Nov-2018  jdolecek during SRST (softreset), make a short delay between the RST set and
clear; SATA specifies minimum 5 usec for the toggle period, and
some controllers (seems usually on AMD motherboards) actually require it

this fixes the 'clearing WDCTL_RST failed' error in PR kern/53307
and PR kern/53524

confirmed working on a ASUS Prime A320M-K mainboard by me, and by Patrick
Welche on another Ryzen system

XXX pullup-8
 1.68 19-Nov-2018  jdolecek if softreset during PMP detection fails, disable PMP, reset port and continue
with sig detected after the initial COMRESET

this does not yet fix the infamous 'clearing WDCTL_RST failed', but at least
now the disk is detected and usable when it happens

tested on AMD system with ASUS Prime A320M-K, similar to one from PR kern/53524
 1.67 19-Nov-2018  jdolecek consistently use the SATA correct 'port %d' instead of 'channel', some
whitespace fixes
 1.66 02-Nov-2018  jdolecek fix ahci_detach() to count the ports propertly (same as attach), to avoid
triggerring panic when disks are plugged to non-adjacent ports - this should
fix panic reported by Masanobu SAITOH on current-users

also fix different miscounting of ports in ahci_setup_ports() and
ahci_reprobe_drives()
 1.65 24-Oct-2018  jdolecek detach the controller itself on shutdown; adjust to not detach already
detached atabus/channel
 1.64 22-Oct-2018  jdolecek Merge jdolecek-ncqfixes branch

- ata_xfer's are dynamicall allocated as needed using a pool, no longer
limited to number of possible openings supported by controller; dump
and recovery paths use dedicated pre-allocated storage
- moved callouts and condvars from ata_xfer to queue or channel, so that
ata_xfer does not need special initialization
- slot allocation now done when xfer is being activated, uncoupled
from memory allocation; active slots are no longer tracked by controller
code
- channel and drive reset is done always via the atabus thread, and
now executes with channel locked the whole time
- NCQ recovery moved to shared function, and run via the thread also
- added some workarounds for buggy error recovery AHCI emulation in QEMU
and Parallels

designed to primarily fix kern/52614, but might also help with kern/47041
and kern/53183
 1.63 18-Sep-2018  jdolecek fix ata_xfer leak on drive probe
 1.62 09-Jul-2018  kamil branches: 1.62.2;
Avoid undefined behavior of signedness bit shift in ahcisata_core.c

sys/dev/ic/ahcisata_core.c:365:31, left shift of 1 by 31 places cannot be represented in type 'int'
sys/dev/ic/ahcisata_core.c:558:16, left shift of 1 by 31 places cannot be represented in type 'int'

Detected with Kernel Undefined Behavior Sanitizer.

This code could be refactored in future and switched to ISSET(9) API,
instead of reinventing the common functionality.
 1.61 08-Jul-2018  jdolecek whitespace fix
 1.60 11-Nov-2017  jdolecek branches: 1.60.2; 1.60.4;
change several of error logs in ahci_intr_port() to use AHCIDEBUG_PRINT()
so they don't show unless debugging; e.g. the AHCI_P_IX_TFES seems to be
triggered normally by ATAPI with 'Media Change' error

adresses 'dmesg spam: ahcisata0 port 1: active 2 is 0x40000001 tfd 0x2051'
thread by Stefan Hertenberger on current-users@
 1.59 20-Oct-2017  jdolecek move ata_queue_alloc(1) and ata_queue_free() calls to ata_channel_init()
and ata_channel_destroy() respectively, to make attachment code simpler,
and to make it easier to spot special queue manipulation like cmdide(4)

on topic of PR kern/52606
 1.58 07-Oct-2017  jdolecek Merge support for SATA NCQ (Native Command Queueing) from jdolecek-ncq branch

ATA subsystem was changed to support several outstanding commands, and use
NCQ xfers if supported by both the controller and the disk, including NCQ
error recovery. Set NCQ high priority for BPRIO_TIMECRITICAL xfers
if supported. Added FUA support.

Done some work towards MP-safe, all ATA code tsleep()/wakeup() replaced
by condvars, and switched most code from spl* to mutexes (separate
wd(4) and ata channel lock).

Introduced new option WD_CHAOS_MONKEY to facilitate testing of error
handling, fixed several uncovered issues. Also fixed several problems
with kernel dump to wd(4) disk.

Tested with ahcisata(4), mvsata(4), siisata(4), piixide(4) on amd64,
with and without port multiplier, both disk and ATAPI devices; other
drivers and archs mechanically adjusted and compile-tested. NCQ is
supported for ahcisata(4) and siisata(4) for any controller, for
mvsata(4) only Gen IIe ones for now. Also enabled ATAPI support in
mvsata(4).

Thanks to Matt Thomas for initial ATA infrastructure patch, and
Jonathan A.Kollasch for siisata(4) NCQ changes and general testing.

Also fixes PR kern/43169 (wd(4)); and PR kern/11811, PR kern/47041,
PR kern/51979 (kernel dump)
 1.57 03-Jun-2016  jmcneill branches: 1.57.6;
PR kern/51211: atactl atabus0 reset causes a panic on Tegra K1

Fix an issue where ahci_reset_channel calls ahci_channel_start with clo=1
even if CAP.SCLO=0.
 1.56 02-May-2016  christos move scsipi_strvis -> libkern:strnvisx()
change the prototype to match userland
fix sizes of strings passed to it
 1.55 11-Nov-2015  jakllsch Only sync and unload dma map in ahci_atapi_complete() if appropriate.

Fixes ahcisata atapi cd(4) on arm (specifically, JETSONTK1), which insists
that a zero-length dmamap can not be synced.
 1.54 24-May-2015  jmcneill Add AHCI_QUIRK_SKIP_RESET quirk to allow for skipping the drive reset
sequence in ahci_do_reset_drive.
 1.53 04-Dec-2014  joerg Increase reset delay in polling mode to 10ms per loop. It seems like
AHCI on the Cubietruck doesn't like the tigther loop.

PR 49448.
 1.52 23-Nov-2014  joerg branches: 1.52.2;
Provide the timeout argument to ahci_exec_fis in ms. Use 1ms delays
when we are not allowed to sleep, full ticks otherwise.

Bump the timeout for reset to 100ms, 10ms is not enough on the
Cubietruck.
 1.51 24-Feb-2014  jmcneill - Only enable AHCI mode if it is not already enabled.
- Add support for capturing initial CAP/CAP2/PI regs before reset (and
restoring them afterwords)
- Add optional callbacks for channel_start / channel_stop.
 1.50 08-Sep-2013  matt Allow the attachment to override ahci_ports.
Keep ACHI_PI cached in the softc.
 1.49 08-Sep-2013  matt If there is only 1 port, don't say "1 ports".
Add a debug printf after reading the active ports.
 1.48 22-Jun-2013  matt branches: 1.48.2;
Make sure dynamically allocated channel_queue struct are zero-filled.
 1.47 03-Apr-2013  bouyer Fix kernel dump on ahci controller, by making sure we won't sleep
while dumping:
- introduce ata_delay() which either use delay() or kpause()
depending on flags. use it in sata_reset_interface() and
some ahci functions
- kill ATA_NOSLEEP, it was tested but never set. use ATA_POLL instead.
- reduce delay while polling in ahci, to speed up the dump

Should fix PR kern/41095
 1.46 02-Feb-2013  matt Use __SHIFTOUT to simplify an expression.
 1.45 26-Oct-2012  bouyer Workaround PR kern/47097: use delay() instead of tsleep() ahci_do_reset_drive()
if not called with AT_WAIT.
The right fix here is to change the ata layer to reset the drive from
thread context, to avoid a 0.5 delay() in interrupt context when a drive
fails.
 1.44 27-Sep-2012  matt Add some more debugging messages.
 1.43 20-Aug-2012  bouyer branches: 1.43.2;
Fix typo, pointed out by Markus W Kilbinger
 1.42 20-Aug-2012  bouyer Fix AHCI_QUIRK_BADPMPRESET: when reset fails for drive 15, stop, clear
errors and restart the channel before retrying with drive 0.
Should fix the problem of drives not detected any more reported by
Markus W Kilbinger on current-users.
 1.41 10-Aug-2012  bouyer Work around some SATA PMP issues in some AHCI controllers by either
disabling PMP entirely, or special handling in the reset function.
Controller list from linux and FreeBSD.
 1.40 31-Jul-2012  bouyer Apply back changes that were reverted on Jul 24 and Jul 26 (general ata/wdc
cleanup and SATA PMP support), now that I'm back to fix the fallouts.
 1.39 26-Jul-2012  jakllsch Revert, with intention of restoring in a less invasive way, the SATA Port
Multiplier code.

ok christos@
 1.38 24-Jul-2012  jakllsch Revert dsl@'s changes of Sun, 15 Jul 2012 10:55:35 +0000 and
Sun, 15 Jul 2012 10:56:50 +0000, excepting the kernel version bump.
First step in reverting regressions to ata(4) subsystem during the addition of
port multiplier support.
 1.37 15-Jul-2012  dsl Some namespace protection (and add greppablity).
Prefix the DRIVE_ and DRIVET_ constants from atavar.h with ATA_.
Don't use an enum for drive_type - you don't know how big it will be.
Move driver_type to avoid implicit structure padding (esp on arm).
This change is purely lexical and mechanical.

Update to 6.99.9 - this wasn't done when the SATA PMP changes
were made - I'm sure they warranted a bump.
 1.36 09-Jul-2012  dsl This a 'quick fix' for the breakage in rev 1.35.
Patch from Manuel on current-users mailing list.
Probably requires further investigation, but is a little nicer than
reverting the previous change.
 1.35 02-Jul-2012  bouyer Add sata Port MultiPlier (PMP) support to the ata bus layer,
as described in
http://mail-index.netbsd.org/tech-kern/2012/06/23/msg013442.html
PMP support in integrated to the atabus layer.
struct ata_channel's ch_drive[] is not dynamically allocated, and ch_ndrive
(renamed to ch_ndrives) closely reflects the size of the ch_drive[] array.
Add helper functions atabus_alloc_drives() and atabus_free_drives()
to manage ch_drive[]/ch_ndrives.
Add wdc_maxdrives to struct wdc_softc so that bus front-end can specify
how much drive they really support (master/slave or single).
ata_reset_drive() callback gains a uint32_t *sigp argument which,
when not NULL, will contain the signature of the device being reset.
While there, some cosmetic changes:
- added a drive_type enum to ata_drive_datas, and stop encoding the
probed drive type in drive_flags (we were out of drive flags anyway).
- rename DRIVE_ATAPIST to DRIVE_ATAPIDSCW to better reflect what this
really is
- remove ata_channel->ata_drives, it's redundant with the pointer in
ata_drive_datas
- factor out the interpretation of SATA signatures in sata_interpet_sig()

propagate these changes to the ATA HBA drivers, and add support for PMP
to ahcisata(4) and siisata(4).

Thanks to:
- Protocase (http://www.protocase.com/) which provided a system
with lots of controllers, SATA PMP and drive slots
- Conservation Genomics Laboratory, Department of Biology, New Mexico State
University for hosting the above system
- Brook Milligan, who set up remote access and has been very responsive
when SATA cable move was needed
 1.34 20-Apr-2012  bouyer Add a bustype_async_event_xfer_mode() callback to scsipi_bustype (which can
be NULL), so that transport-specific details of transfer mode setting/printing
can be handled more easily.
Move scsipi_async_event_xfer_mode() and scsipi_print_xfer_mode() to
scsi_base.c and split in parallel scsi and FC/SAS parts.
size of struct scsipi_bustype has changed, welcome to 6.99.5
 1.33 10-Jan-2012  jakllsch branches: 1.33.4;
When a port reset fails, it is important to know which port.
 1.32 20-Aug-2011  jakllsch branches: 1.32.2; 1.32.6;
Rework version printout to be more future proof.
Rework features printout using snprintb.
 1.31 10-Jan-2011  tsutsui Don't call bus_dmamap_load(9) and bus_dmamap_sync(9) on command xfers
if (AT_READ|AT_WRITE) in ata_c->flags is set but ata_c->bcount is zero.
Someone actually tries to put such a command and it causes
DIAGNOSTIC panic in x86/bus_dma.c:_bus_dmamap_sync().
I think bus_dma(9) API itself may allow calls with mapsize==0
but there are many MD code that asserts offset>=mapsize or len==0.

The problem is reported and fix is confirmed by Takuro KUBOTA
with XEN DOM0 kernel (which has options DIAGNOSTIC).
 1.30 13-Nov-2010  uebayasi Don't pull in the whole uvm(9) API to access only PAGE_SIZE and
some other constants. These are provided by sys/param.h now.
 1.29 27-Jul-2010  jakllsch Support detachment of ahcisata(4).
Use use 64-bit DMA tag (where available) for ahcisata(4) at jmide(4).
Beginnings of detach/resume support for jmide(4).
Sprinkle static. Misc. little changes.
 1.28 20-Jul-2010  jakllsch Prepare ahcisata(4) to work with 64-bit bus_dma_tag_t.
 1.27 20-Jul-2010  jakllsch Convert ahcisata(4) to C99 exact-width integer types.
 1.26 07-Apr-2010  jakllsch satafis:
- Add function to parse RDH FIS for use in implementing AT_READREG.
- Correct and clean up some structure definitions.
- Sprinkle a bit of const.
- Remove dependency on <dev/ic/wdcreg.h>, WDCTL_4BIT doesn't seem
to be specified by any recent ATA standard, and it seems to make
no difference in practice.
- Stop using WDSD_IBM, these bits have been obsolete since before SATA.

siisata:
- Implement AT_READREG.
- Reap now-unneeded <dev/ic/wdcreg.h>.
- Whitespace and slight debug code cleanup.
- Some possibly-uncessary code reordering.

ahcisata:
- Implement AT_READREG.
- Reap now-unneeded <dev/ic/wdcreg.h>.
 1.25 12-Mar-2010  jakllsch branches: 1.25.2;
ata(4) expects IDENTIFY data to be in host endianess.
Logic borrowed from siisata(4) (which I've confirmed works on sparc64).
Should fix PR kern/39659.
 1.24 10-Mar-2010  bouyer ahcisata_core.c 1.23 cause long drive probe (31s, reported by
Roy Marples), or other devices misbehavior probably due to interrupts issues
(reported by Jukka Ruohonen). Back it out and do the following changes:
- clear port interrupt register before ahci_channel_start() which enables
interrupts
- wait 500ms after sata_reset_interface() before touching SERROR register.
This is what seems to fix the issue I'm seeming on ESB2 controller.
- The 31s delay didn't cause the probe to fail because of a mismatch
in loop index comparison; use a #define for delay after reset
instead of numeric values, to avoid this kind of bugs in the
future.
 1.23 23-Feb-2010  bouyer Move ahci_channel_start() after BSY has cleared (what seems to matter
here is not touching SError while BSY is asserted). Fix random
behavior (serial console corruption/misfunction, misbehavior of USB
controllers, crasy interrupts crashing the Xen hypervisor, ...)
of Intel ESB2 controller with some brand of hitachi drives.
 1.22 21-Nov-2009  jakllsch branches: 1.22.2;
Change bus_space_subregion() size for each SATA PHY register from 1 to 4,
as we do a bus_space_read_4() within these subregions.
 1.21 19-Oct-2009  bouyer Remove closes 3 & 4 from my licence. Lots of thanks to Soren Jacobsen
for the booring work !
 1.20 17-Jun-2009  jakllsch Use abstracted FIS code for ahcisata(4). Have the FIS code pre-zero the FIS.
 1.19 12-Feb-2009  bouyer When an error is reported on a write, data may have been transfered
to the device's cache anyway and so cmdh_prdbc reports a completed
transfer. If we use it to update ata_bio->bcount this has 2 conseqences:
- the automatic LBA48 workaround doesn't qick in because bcount is used
to compute the last sector of the transfer (wd(4) part of kern/40569)
- wd(4) will report a B_ERROR buffer with a b_resid of 0, which panics
a DIAGNOSTIC kernel
Fix by ignoring cmdh_prdbc if we had a write with errors, and in this case
leave ata_bio->bcount at its initial value.

While there use NOERROR instead of 0 for ata_bio->error (cosmetic).

thanks to Matthias Scheler for tests.
 1.18 03-Oct-2008  bouyer branches: 1.18.2; 1.18.4; 1.18.8;
Make sure the adapter is ready to accept FISs before bringing the PHY up.
Wait for the BSY bit to clear in the status register.
Makes the cdrom drive probe properly on a ATI SB600 controller in AHCI
mode.
 1.17 01-Aug-2008  dillo Increase delay after channel reset from 100ms to 500ms, suggested by bouyer.
Fixes unreliable drive detection on NVIDIA MCP67.
 1.16 07-Jun-2008  bouyer branches: 1.16.4;
For ATAPI, in addition to storing the short sense, report a SCSI_CHECK
condition, to that the scsipi layer will issue a request sense.
 1.15 07-May-2008  bouyer branches: 1.15.2;
Wait 100ms after we resseting the PHY and found that a device is preent.
Some device seems to need a bit of delay before being ready to accept a
command (such as my SATA cdrom drive) May fix port-i386/38548.
As a bonus this makes the dmesg output prettier, by not mixing PHY
status with ATA/ATAPI probe.
 1.14 24-Mar-2008  cube branches: 1.14.2; 1.14.4;
Split device_t and softc for atapibus(4).
 1.13 18-Mar-2008  cube Split device_t and softc for ATA devices, as well as wd(4). Other
cosmetic changes where appropriate.
 1.12 11-Feb-2008  xtraeme branches: 1.12.2; 1.12.6;
Attach ahcisata(4) to any RAID controller that supports AHCI, and make it
pass the ATAC_CAP_RAID capability for them. ok'ed by bouyer@.
 1.11 25-Jan-2008  xtraeme Make it print the correct version for AHCI 1.2 controllers.
 1.10 04-Dec-2007  spz try fixing up broken revision string again
 1.9 04-Dec-2007  spz fix up broken revision string
 1.8 12-Nov-2007  bouyer Add ATAPI support to ahcisata(4). lightly tested with a DVD burner, by
mounting a CD and reading from it, and blanking a DVD-RW using cdrecord.
 1.7 12-Nov-2007  joerg Merge refactoring from jmcneill-pm.
 1.6 11-Nov-2007  bouyer Move a delay() inside a loop, so that the 1s delay is really 1s.
 1.5 16-Sep-2007  bouyer branches: 1.5.4; 1.5.6;
Fix various error handling bugs:
- the value of the ATA error register would be computed wrongly, leading to
bogus error values reported to wd(4)
- the channel would not always be restarted after an error, so the next
command would not be handled by the controller
- a timeout condition would not be properly reported to wd(4), leading
to a short transfer instead of a reset/retry
these bugs would cause a AHCI SATA channel to be stalled (no more command
processed) after a "ID not found" or "Aborted command" error reported by the
drive.
 1.4 09-Jul-2007  ad branches: 1.4.2; 1.4.8; 1.4.10; 1.4.12; 1.4.14; 1.4.16;
Merge some of the less invasive changes from the vmlocking branch:

- kthread, callout, devsw API changes
- select()/poll() improvements
- miscellaneous MT safety improvements
 1.3 25-Jun-2007  bouyer We're not ready to handle ATAPI yet so just claim there's no drive to the
upper layer. This should work around a NULL pointer dereference when
an ATAPI device is detected on a AHCI device.
 1.2 21-Jun-2007  fvdl * Add bus_dmamap_sync calls for cmd structure.
* During initialization, use the right port index when setting up the
physical pointers for a port. Fixes issue with non-contigous ports.

Reviewed by Manuel.
 1.1 12-May-2007  bouyer branches: 1.1.2; 1.1.4;
Split the ahcisata driver in pci front-end and bus-independant back-end.
 1.1.4.5 09-Oct-2007  ad Sync with head.
 1.1.4.4 15-Jul-2007  ad Sync with head.
 1.1.4.3 09-Jun-2007  ad Sync with head.
 1.1.4.2 09-Jun-2007  ad Sync with head.
 1.1.4.1 12-May-2007  ad file ahcisata_core.c was added on branch vmlocking on 2007-06-09 21:37:13 +0000
 1.1.2.2 17-May-2007  yamt sync with head.
 1.1.2.1 12-May-2007  yamt file ahcisata_core.c was added on branch yamt-idlelwp on 2007-05-17 13:41:24 +0000
 1.4.16.7 24-Mar-2008  yamt sync with head.
 1.4.16.6 11-Feb-2008  yamt sync with head.
 1.4.16.5 04-Feb-2008  yamt sync with head.
 1.4.16.4 15-Nov-2007  yamt sync with head.
 1.4.16.3 27-Oct-2007  yamt sync with head.
 1.4.16.2 03-Sep-2007  yamt sync with head.
 1.4.16.1 09-Jul-2007  yamt file ahcisata_core.c was added on branch yamt-lazymbuf on 2007-09-03 14:34:13 +0000
 1.4.14.4 03-Jun-2008  skrll Sync with netbsd-4.
 1.4.14.3 23-Sep-2007  wrstuden Sync with somewhat-recent netbsd-4.
 1.4.14.2 03-Sep-2007  wrstuden Sync w/ NetBSD-4-RC_1
 1.4.14.1 09-Jul-2007  wrstuden file ahcisata_core.c was added on branch wrstuden-fixsa on 2007-09-03 07:04:22 +0000
 1.4.12.7 26-Feb-2009  snj Pull up following revision(s) (requested by bouyer in ticket #1277):
sys/dev/ic/ahcisata_core.c: revision 1.19
When an error is reported on a write, data may have been transfered
to the device's cache anyway and so cmdh_prdbc reports a completed
transfer. If we use it to update ata_bio->bcount this has 2 conseqences:
- the automatic LBA48 workaround doesn't qick in because bcount is used
to compute the last sector of the transfer (wd(4) part of kern/40569)
- wd(4) will report a B_ERROR buffer with a b_resid of 0, which panics
a DIAGNOSTIC kernel
Fix by ignoring cmdh_prdbc if we had a write with errors, and in this case
leave ata_bio->bcount at its initial value.
While there use NOERROR instead of 0 for ata_bio->error (cosmetic).
thanks to Matthias Scheler for tests.
 1.4.12.6 23-Mar-2008  jdc Pull up revision 1.8 (requested by bouyer in ticket #1085).

Add ATAPI support to ahcisata(4). lightly tested with a DVD burner, by
mounting a CD and reading from it, and blanking a DVD-RW using cdrecord.
 1.4.12.5 23-Mar-2008  jdc Pull up revision 1.6 (requested by bouyer in ticket #1082).

Move a delay() inside a loop, so that the 1s delay is really 1s.
 1.4.12.4 16-Sep-2007  xtraeme branches: 1.4.12.4.4;
Pull up following revision(s) (requested by bouyer in ticket #882):
sys/dev/ic/ahcisata_core.c: revision 1.5
sys/dev/ic/ahcisatareg.h: revision 1.2

Fix various error handling bugs:
- the value of the ATA error register would be computed wrongly, leading to
bogus error values reported to wd(4)
- the channel would not always be restarted after an error, so the next
command would not be handled by the controller
- a timeout condition would not be properly reported to wd(4), leading
to a short transfer instead of a reset/retry
these bugs would cause a AHCI SATA channel to be stalled (no more command
processed) after a "ID not found" or "Aborted command" error reported by the
drive.
 1.4.12.3 31-Aug-2007  pavel Pull up following revision(s) (requested by bouyer in ticket #746):
sys/dev/ic/ahcisata_core.c: revision 1.2
* Add bus_dmamap_sync calls for cmd structure.
* During initialization, use the right port index when setting up the
physical pointers for a port. Fixes issue with non-contigous ports.
Reviewed by Manuel.
 1.4.12.2 31-Aug-2007  pavel Pull up following revision(s) (requested by bouyer in ticket #678):
distrib/sets/lists/man/mi: revision 1.1001
doc/CHANGES: revision 1.853 via patch
share/man/man4/Makefile: revision 1.428
share/man/man4/jmide.4: revision 1.1
sys/arch/amd64/conf/GENERIC: revision 1.143
sys/arch/amd64/conf/INSTALL: revision 1.69
sys/arch/i386/conf/GENERIC: revision 1.827
sys/arch/i386/conf/INSTALL_LARGE: revision 1.2 via patch
sys/arch/i386/conf/XEN2_DOM0: revision 1.26
sys/conf/files: revision 1.844 via patch
sys/dev/ic/ahcisata_core.c: revision 1.1 via patch
sys/dev/ic/ahcisata_core.c: revision 1.3
sys/dev/ic/ahcisatareg.h: revision 1.1
sys/dev/ic/ahcisatavar.h: revision 1.1
sys/dev/pci/ahcisata.c: delete
sys/dev/pci/ahcisatareg.h: delete
sys/dev/pci/ahcisata_pci.c: revision 1.1
sys/dev/pci/files.pci: revision 1.287-1.288
sys/dev/pci/jmide.c: revision 1.1-1.2
sys/dev/pci/jmide_reg.h: revision 1.1
sys/dev/pci/pcidevs: revision 1.878
Add JMicron Technology vendor ID, and their current PCIe SATA/PATA
controllers.

Split the ahcisata driver in pci front-end and bus-independant back-end.
add jmide(4), a driver for the JMicron Technology JMB36x PCIe to SATA II/PATA
controllers. These controllers can be found on add-on PCIe cards, or
on some motherboards to provide the PATA connectivity (e.g. some intel
ICH8-based motherboards).
Thanks to JMicron Technology for providing me documentation and
different sample boards for this work.

Move mapping of AHCI register so that jmide knows if it fails, and avoids
calling ahci_intr() (which would cause a panic).
Try to use the pciide function for SATA drives if attaching ahci fails (this
doesn't seems to work though, it may be BIOS dependant).
Thanks to Gary Duzan for testing multiple pacthes.

We're not ready to handle ATAPI yet so just claim there's no drive to the
upper layer. This should work around a NULL pointer dereference when
an ATAPI device is detected on a AHCI device.
 1.4.12.1 09-Jul-2007  pavel file ahcisata_core.c was added on branch netbsd-4 on 2007-08-31 20:09:23 +0000
 1.4.12.4.4.1 26-Feb-2009  snj Pull up following revision(s) (requested by bouyer in ticket #1277):
sys/dev/ic/ahcisata_core.c: revision 1.19
When an error is reported on a write, data may have been transfered
to the device's cache anyway and so cmdh_prdbc reports a completed
transfer. If we use it to update ata_bio->bcount this has 2 conseqences:
- the automatic LBA48 workaround doesn't qick in because bcount is used
to compute the last sector of the transfer (wd(4) part of kern/40569)
- wd(4) will report a B_ERROR buffer with a b_resid of 0, which panics
a DIAGNOSTIC kernel
Fix by ignoring cmdh_prdbc if we had a write with errors, and in this case
leave ata_bio->bcount at its initial value.
While there use NOERROR instead of 0 for ata_bio->error (cosmetic).
thanks to Matthias Scheler for tests.
 1.4.10.3 23-Mar-2008  matt sync with HEAD
 1.4.10.2 09-Jan-2008  matt sync with HEAD
 1.4.10.1 06-Nov-2007  matt sync with HEAD
 1.4.8.4 09-Dec-2007  jmcneill Sync with HEAD.
 1.4.8.3 14-Nov-2007  joerg Sync with HEAD.
 1.4.8.2 02-Oct-2007  joerg Sync with HEAD.
 1.4.8.1 04-Aug-2007  he Factor out the hardware initialization code in ahcisata_core.c,
and provide them to the pci frontend, which has now grown its own
softc and a power management handler.

There may be one too many re-initializations done on resume (witness
the multiple kernel messages from ahcisata), but at least this is
sufficient to get the Lenovo T60 to come out of resume with a
working disk controller and disk.
 1.4.2.2 11-Jul-2007  mjf Sync with head.
 1.4.2.1 09-Jul-2007  mjf file ahcisata_core.c was added on branch mjf-ufs-trans on 2007-07-11 20:05:37 +0000
 1.5.6.3 18-Feb-2008  mjf Sync with HEAD.
 1.5.6.2 08-Dec-2007  mjf Sync with HEAD.
 1.5.6.1 19-Nov-2007  mjf Sync with HEAD.
 1.5.4.1 13-Nov-2007  bouyer Sync with HEAD
 1.12.6.5 05-Oct-2008  mjf Sync with HEAD.
 1.12.6.4 28-Sep-2008  mjf Sync with HEAD.
 1.12.6.3 29-Jun-2008  mjf Sync with HEAD.
 1.12.6.2 02-Jun-2008  mjf Sync with HEAD.
 1.12.6.1 03-Apr-2008  mjf Sync with HEAD.
 1.12.2.1 24-Mar-2008  keiichi sync with head.
 1.14.4.5 11-Aug-2010  yamt sync with head.
 1.14.4.4 11-Mar-2010  yamt sync with head
 1.14.4.3 20-Jun-2009  yamt sync with head
 1.14.4.2 04-May-2009  yamt sync with head.
 1.14.4.1 16-May-2008  yamt sync with head.
 1.14.2.2 17-Jun-2008  yamt sync with head.
 1.14.2.1 18-May-2008  yamt sync with head.
 1.15.2.3 10-Oct-2008  skrll Sync with HEAD.
 1.15.2.2 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.15.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.16.4.1 19-Oct-2008  haad Sync with HEAD.
 1.18.8.2 23-Jul-2009  jym Sync with HEAD.
 1.18.8.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.18.4.5 16-Jan-2011  bouyer Pull up following revision(s) (requested by tsutsui in ticket #1530):
sys/dev/ic/ahcisata_core.c: revision 1.31
Don't call bus_dmamap_load(9) and bus_dmamap_sync(9) on command xfers
if (AT_READ|AT_WRITE) in ata_c->flags is set but ata_c->bcount is zero.
Someone actually tries to put such a command and it causes
DIAGNOSTIC panic in x86/bus_dma.c:_bus_dmamap_sync().
I think bus_dma(9) API itself may allow calls with mapsize==0
but there are many MD code that asserts offset>=mapsize or len==0.
The problem is reported and fix is confirmed by Takuro KUBOTA
with XEN DOM0 kernel (which has options DIAGNOSTIC).
 1.18.4.4 28-Mar-2010  snj branches: 1.18.4.4.4;
Pull up following revision(s) (requested by bouyer in ticket #1317):
sys/dev/ic/ahcisata_core.c: revision 1.23, 1.24
Move ahci_channel_start() after BSY has cleared (what seems to matter
here is not touching SError while BSY is asserted). Fix random
behavior (serial console corruption/misfunction, misbehavior of USB
controllers, crasy interrupts crashing the Xen hypervisor, ...)
of Intel ESB2 controller with some brand of hitachi drives.
--
ahcisata_core.c 1.23 cause long drive probe (31s, reported by
Roy Marples), or other devices misbehavior probably due to interrupts issues
(reported by Jukka Ruohonen). Back it out and do the following changes:
- clear port interrupt register before ahci_channel_start() which enables
interrupts
- wait 500ms after sata_reset_interface() before touching SERROR register.
This is what seems to fix the issue I'm seeming on ESB2 controller.
- The 31s delay didn't cause the probe to fail because of a mismatch
in loop index comparison; use a #define for delay after reset
instead of numeric values, to avoid this kind of bugs in the
future.
 1.18.4.3 07-Mar-2010  sborrill Backout ticket 1317 until problems reported in -current are fixed:
http://mail-index.netbsd.org/current-users/2010/03/04/msg012810.html
 1.18.4.2 06-Mar-2010  sborrill Pull up the following revisions(s) (requested by bouyer in ticket #1317):
sys/dev/ic/ahcisata_core.c: revision 1.23

Move ahci_channel_start() after BSY has cleared (do not touch SError while
BSY is asserted). Fixes random behaviour of Intel ESB2 controller with some
models of Hitachi drives (serial console corruption/misfunction, misbehavior
of USB controllers, crazy interrupts crashing the Xen hypervisor, etc.).
 1.18.4.1 19-Feb-2009  snj branches: 1.18.4.1.4;
Pull up following revision(s) (requested by bouyer in ticket #455):
sys/dev/ic/ahcisata_core.c: revision 1.19
When an error is reported on a write, data may have been transfered
to the device's cache anyway and so cmdh_prdbc reports a completed
transfer. If we use it to update ata_bio->bcount this has 2 conseqences:
- the automatic LBA48 workaround doesn't qick in because bcount is used
to compute the last sector of the transfer (wd(4) part of kern/40569)
- wd(4) will report a B_ERROR buffer with a b_resid of 0, which panics
a DIAGNOSTIC kernel
Fix by ignoring cmdh_prdbc if we had a write with errors, and in this case
leave ata_bio->bcount at its initial value.
While there use NOERROR instead of 0 for ata_bio->error (cosmetic).
thanks to Matthias Scheler for tests.
 1.18.4.4.4.1 14-Oct-2011  matt revision 1.25
date: 2010/03/12 19:03:14; author: jakllsch; state: Exp; lines: +13 -2
ata(4) expects IDENTIFY data to be in host endianess.
Logic borrowed from siisata(4) (which I've confirmed works on sparc64).
 1.18.4.1.4.2 24-Mar-2014  matt Merge needed changes from HEAD for cubie
 1.18.4.1.4.1 21-Apr-2010  matt sync to netbsd-5
 1.18.2.1 03-Mar-2009  skrll Sync with HEAD.
 1.22.2.2 17-Aug-2010  uebayasi Sync with HEAD.
 1.22.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.25.2.2 05-Mar-2011  rmind sync with head
 1.25.2.1 30-May-2010  rmind sync with head
 1.32.6.2 29-Apr-2012  mrg sync to latest -current.
 1.32.6.1 18-Feb-2012  mrg merge to -current.
 1.32.2.4 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.32.2.3 30-Oct-2012  yamt sync with head
 1.32.2.2 23-May-2012  yamt sync with head.
 1.32.2.1 17-Apr-2012  yamt sync with head
 1.33.4.1 03-Dec-2012  matt Pullup changes in rev 1.44.
 1.43.2.6 03-Dec-2017  jdolecek update from HEAD
 1.43.2.5 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.43.2.4 23-Jun-2013  tls resync from head
 1.43.2.3 25-Feb-2013  tls resync with head
 1.43.2.2 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.43.2.1 09-Oct-2012  bouyer Support transfers of up to MACHINE_MAXPHYS in all pciide variants, and ahci.
wd(4) limits its maxphys depending on the drives's capability (64k sectors
for LBA48, 256 sectors for LBA and 128 sectors for older devices).

I assumed all pciide controllers could do MACHINE_MAXPHYS transfers, but
this may not be true. The capabilities of each controller variants should be
looked at more closely.
 1.48.2.1 18-May-2014  rmind sync with head
 1.52.2.5 09-Jul-2016  skrll Sync with HEAD
 1.52.2.4 29-May-2016  skrll Sync with HEAD
 1.52.2.3 27-Dec-2015  skrll Sync with HEAD (as of 26th Dec)
 1.52.2.2 06-Jun-2015  skrll Sync with HEAD
 1.52.2.1 06-Apr-2015  skrll Sync with HEAD
 1.57.6.29 19-Sep-2017  jdolecek replace all remaining tsleep()/wakeup() calls with condition variables, or
calls to ata_delay(), as appropriate; change ata_delay() to require the
channel lock on entry, and pass the lock to kpause() for unlocking while
sleeping
 1.57.6.28 19-Sep-2017  jdolecek seems the CMD/CCS slot is always zero at least under QEMU for successful
polled commands, so go back to using it only on error path; while the value
seems good on real hardware, there is no good reason for register read anyway
 1.57.6.27 10-Sep-2017  jdolecek refactor code so that xfer c_start() hook is called with channel mutex held,
and hence the controller submit code no longer relies on spl

tested all the affected drivers - wdc (via piixide), ahci, mvsata, siisata,
both disk and atapi I/O
 1.57.6.26 12-Aug-2017  jdolecek do not reset drive after successful NCQ error recovery
 1.57.6.25 01-Aug-2017  jdolecek fix logic bug in processing of finished commands - mask of active
commands can change during the loop as c_intr() callback can queue
new commands, so the interrupt routine should only mark as finished
those which were actually active before the loop started; otherwise
the code marked as finished commands which were just started, and
being executed by HBA, leading to all sorts of data corruption

while here mark the active mask volatile, as it is modified from
interrupt context

this fixes for good the random crashes, short reads, and fatal command
errors which I've been tracing down for past couple weeks

thanks to Jonathan (jakllsch@) for testing, and a script to easily
triggered the condition, and led to this bug being finally found and squashed
 1.57.6.24 29-Jul-2017  jdolecek whitespace
 1.57.6.23 29-Jul-2017  jdolecek make compile without AHCI_DEBUG
 1.57.6.22 29-Jul-2017  jdolecek make ahci_channel_recover() non-static, so that it's visible in backtrace,
and can set a separate breakpoint there
 1.57.6.21 29-Jul-2017  jdolecek do not do the drive reset on non-fatal recovery - spec explicitely says
says the READ LOG EXT should only be done when neither COMRESET nor software
reset was done, and indeed it returns junk in this case

use C_RECOVERY slot for drive reset, so that it now will always succeed
in getting a slot, in cases when it would be necessary

adjust code and comments on the recovery path to explain better what's going on

with this AHCI error recovery works with real hardware without timeouts again
 1.57.6.20 23-Jul-2017  jdolecek rework the error handling and recovery, so that errors during the recovery
are handled correctly, and the recovery more closely follows the spec

this fixes e.g. NCQ error handling under QEMU, which doesn't implement
READ LOG EXT - previous code actually made the call 'succeed', returning bogus
(zero) slot/error/status

finished xfers are still handled before entering recovery (with channel frozen)
to avoid unnecessary retries
 1.57.6.19 21-Jul-2017  jdolecek use free slot for drive reset, rather than always using slot zero; if we can't
get the slot, fallback to channel reset as usual

note this increases the odds of not being able to do the reset, when all slots
happen to be active

this is in same area as problem reported by PR kern/52372 but I
don't believe that this change actually make any change for it - during
probe/attach there shouldn't be any paralell request with drive reset
 1.57.6.18 19-Jul-2017  jdolecek update error handling:
- switch to ata_timeout()
- stop using ch_status/ch_error for passing state/error, stop setting
ATACH_IRQ_WAIT in ch_flags; pass the state via the last parameter
to c_intr() routine
- add NCQ recovery and KILL_REQUEUE
- only call atastart() in c_intr() if there was no error

ahcisata-specific tweaks:
- add some handling for PM in the error recovery using FBS register,
according to spec it should be independant of actual FBSS feature; untested
as my hw doesn't support PM
 1.57.6.17 27-Jun-2017  jdolecek attend error paths, more strict asserts and code consistency

- atastart() and ata_kill_pending() now KASSERT() that all xfers on queue
have same channel
- inactive xfers are killed via new reason KILL_GONE_INACTIVE, controller
code must not call any resource deactivation in that case
- c_intr() must call ata_waitdrain_xfer_check() as first thing, and must not
further touch any xfer structures on exit path; any resource cleanup
is supposed to be done in c_kill_xfer()
- c_kill_xfer() should never call atastart()
- ata_waitdrain_check() removed, replaced by ata_waitdrain_xfer_check()
- ATA_DRIVE_WAITDRAIN handling converted to use condvar
- removed unused ata_c callback
 1.57.6.16 21-Jun-2017  jdolecek change ata_queue_hwslot_to_xfer() and ata_queue_get_active_xfer() to take
ata_channel instead of ata_queue as parameter, and lock the channel while
traversing the queue
 1.57.6.15 20-Jun-2017  jdolecek remove ata queue downsizing - every device, attached to the same channel,
uses slots according to it's own limits

wdc code changed to expect maximum one active xfer, and not check number
of openings in the channel; this is to facilitate using wdc functions
for e.g. handling of atapi commands for drivers which support both ATAPI
and NCQ
 1.57.6.14 19-Jun-2017  jdolecek add ata_channel lock, use it to protect queue manipulation (only that for now);
add ata_channel_detach() to destroy the locks

change ata_get_xfer() so that it can wait for xfer, convert all on-stack
xfer code to use the blocking variant

fix siisata_reset_drive() to use polled reset and not try ata_activate_xfer(),
convert drive probe code also over from slot0 XXX to ata_get_xfer()

drive reset and PMP now works on siisata(4) too; changes tested also
on piixide(4), ahci(4), mvsata(4)
 1.57.6.13 16-Jun-2017  jdolecek adjust reset channel and dump paths
- channel reset now always kills active transfer, even on dump path, but
now doesn't touch the queued waiting transfers; also kill_xfer hook is
always called, so that HBA can free any private xfer resources and thus
the dump request has chance to work
- kill_xfer routines now always call ata_deactivate_xfer(); added KASSERT()s
to ata_free_xfer() to expect deactivated xfer
- when called during channel reset before dump, ata_kill_active() drops
any queued waiting transfers without processing
- do not (re)queue any transfers in wddone() when dumping
- kill AT_RST_NOCMD flag

This should also hopefully fix the 'polled command has been queued' panic
as reported in:
PR kern/11811 by John Hawkinson
PR kern/47041 by Taylor R Campbell
PR kern/51979 by Martin Husemann

dump tested working with piixide(4) and ahci(4). mvsata(4) dump times out,
but otherwise tested working, will be fixed separately. siisata(4) mechanically
changed and not tested.
 1.57.6.12 25-Apr-2017  jdolecek make compile without DIAGNOSTIC
 1.57.6.11 24-Apr-2017  jdolecek only clear the bcount for NCQ case when the transfer actually ended w/o error
 1.57.6.10 24-Apr-2017  jdolecek do not use PRD Byte Count for queued commands to determine number of bytes
actually transferred; it should not be used and is not guaranteed to be
valid according to AHCI spec, underflow is always invalid for queued cmds

this fixes my ls problem under QEMU
 1.57.6.9 24-Apr-2017  jdolecek adjust error handling in interrupt handler - finish the successfully
finished xfers, and iterate to error out all the unfinished ones
 1.57.6.8 20-Apr-2017  jakllsch Don't bail out of handling interrupts at the first inactive slot.

Appears to fix the frequent timeouts issue.
 1.57.6.7 19-Apr-2017  jdolecek adjust ata code to support more than one active command, including the
timeout handling, add support for NCQ commands

move probe for NCQ and number of tags to middle layer, negotiate mutual
support between drive and controller

implement NCQ support in ahci(4)
 1.57.6.6 15-Apr-2017  jdolecek use xfer->c_slot instead of slot = 0

fix ahci_bio_complete() calls - last param is reason, not slot
 1.57.6.5 15-Apr-2017  jdolecek ahci_intr_port(): use same code on both the error and non-error path for
for getting the slot and skipping interrupts for non-active slots
 1.57.6.4 15-Apr-2017  jdolecek pass also ata_command via ata_xfer, callers of ata_exec_command() is now
responsible for allocation/disposal of the structure

change code to allocate ata_xfer for commands on stack same way as previously
the ata_command were, using c_slot 0; adjust asserts so that it would allow
several xfers with same c_slot, as long as only one such transfer is active
at a time
 1.57.6.3 15-Apr-2017  jdolecek make ata_xfer's allocated as part of ata_queue and make it include ata_bio;
they are pre-allocated on attach and ata_get_xfer() now never sleep, drop the
pool

modify wd(4) to file the bio requests using the xfers and hence
make it possible to have more than one active I/O request in flight;
ata_bio callback doesn't need to allocate any memory any more,
require it to never return ATACMD_TRY_AGAIN

move lp, badsect, multi from ata_bio to ata_drive_datas, as they are per-drive,
not per transfer

drop unused drv atac_claim_hw/atac_free_hw hooks, and also drop again ata_bio
c_hwslot
 1.57.6.2 11-Apr-2017  jdolecek fix to not access active_xfer directly
 1.57.6.1 10-Apr-2017  jdolecek ATA infrastructure improvements to eventually support more outstanding
commands

patch by Matt Thomas
 1.60.4.4 21-Apr-2020  martin Sync with HEAD
 1.60.4.3 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.60.4.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.60.4.1 10-Jun-2019  christos Sync with HEAD
 1.60.2.6 26-Jan-2019  pgoyette Sync with HEAD
 1.60.2.5 18-Jan-2019  pgoyette Synch with HEAD
 1.60.2.4 26-Dec-2018  pgoyette Sync with HEAD, resolve a few conflicts
 1.60.2.3 26-Nov-2018  pgoyette Sync with HEAD, resolve a couple of conflicts
 1.60.2.2 30-Sep-2018  pgoyette Ssync with HEAD
 1.60.2.1 28-Jul-2018  pgoyette Sync with HEAD
 1.62.2.10 15-Oct-2018  jdolecek change the SATA/NCQ recovery to run in the atabus thread
 1.62.2.9 11-Oct-2018  jdolecek refactor shared parts of the SATA error recovery into new function
ata_recovery_resume() and use for ahcisata/siisata/mvsata, also replace
per-controller hold/unhold with generic version

move the shared recovery code into separate file ata_recovery.c
 1.62.2.8 07-Oct-2018  jdolecek move atastart() call after xfer deactivation during ATA command completion,
so that it's executed after the slot is freed
 1.62.2.7 04-Oct-2018  jdolecek further channel locking pass for reset
 1.62.2.6 03-Oct-2018  jdolecek change channel reset and drive reset for all ATA controllers to always
run via thread, and with channel lock held the whole time; the queue is
frozen while reset is pending

for this repurpose ata_reset_channel() into new ata_thread_run()

also adjust some device printfs to not leak xfer pointer, and avoid
aprint_* for non-autoconf messages
 1.62.2.5 22-Sep-2018  jdolecek separate ata_xfer slot allocation and the memory allocation, so that
there can be more queued xfers than number of supported slots by controller,
and use a pool instead of custom pre-allocation

primarily to help PR kern/52614

remove no longer needed custom wd(4) logic for flush cache

switch also wd(4) trim/suspend/setcache/wdioctlstrategy to sleep waiting
for the memory, they are all called from process context and this
avoids spurious failures
 1.62.2.4 17-Sep-2018  jdolecek move ATAPI-only members of ata_xfer to an union struct to further save space
 1.62.2.3 17-Sep-2018  jdolecek move low-level protocol handlers hooks from ata_xfer to separate struct,
initialized statically

primarily to reduce ata_xfer struct size, but also improves readibility,
and enforces consistency
 1.62.2.2 01-Sep-2018  jdolecek only call ata_deactivate_xfer() once completely done with the active
xfer in controller code (i.e. after bus_dmamap_sync() et.al.), so that
the command slot is safe to be reused immediatelly after deactivate
 1.62.2.1 31-Aug-2018  jdolecek refactor ata_xfer to be just dumb structure; move all callouts/condvars out

retry callout to wd(4); reset callout and the active/cmd finish condvars
to channel queue; change code using the condvars so it works if there
are multiple waiters

simplify the async wait code for cmds, replace ata_wait_xfer()/ata_wake_xfer()
with ata_wait_cmd()

fix the callout_invoking/ack race handling code for timeouts to
actually have chance to work; change mvsata(4) to use generic timeout func

towards resolution of kern/52614
 1.75.4.5 30-Dec-2022  martin Pull up following revision(s) (requested by tsutsui in ticket #1557):

sys/dev/ic/ahcisata_core.c: revision 1.83
sys/dev/ic/ahcisata_core.c: revision 1.102
sys/dev/ata/ata.c: revision 1.164
sys/dev/ata/ata_wdc.c: revision 1.115
sys/dev/ata/ata_recovery.c: revision 1.4
sys/dev/ic/siisata.c: revision 1.42
sys/dev/ic/wdc.c: revision 1.308
sys/dev/ic/mvsata.c: revision 1.56
sys/dev/scsipi/atapi_wdc.c: revision 1.138
sys/dev/ic/siisata.c: revision 1.49
sys/dev/ata/atavar.h: revision 1.105
sys/dev/ata/wd.c: revision 1.460
sys/dev/ata/ata.c: revision 1.155
sys/dev/ata/wd.c: revision 1.462
sys/dev/ata/atavar.h: revision 1.109
sys/dev/ata/satapmp_subr.c: revision 1.16
sys/dev/ic/wdc.c: revision 1.299
sys/dev/ic/ahcisata_core.c: revision 1.93
sys/dev/ata/ata_wdc.c: revision 1.120
sys/dev/ic/wdcvar.h: revision 1.100
sys/dev/scsipi/atapi_wdc.c: revision 1.141
sys/dev/ic/mvsata.c: revision 1.61
sys/dev/usb/umass_isdata.c (apply patch)

drop wd lock in wdstart1() before calling the ata_bio hook; when called
from ata thread context, that can still need to sleep for wdc attachments
in wdcwait()

fix use-after-free for ata xfer on bio submission found by KASAN
driver ata_bio hooks read parts of the xfer after ata_exec_xfer()
call in order to determine return value, change so that the hook
doesn't return any value - callers do not care already,
as all I/O requests are asynchronous

this problem was uncovered by recent change for wd(4) to not hold
wd mutex during ata_bio call, the interrupt for the xfer might
thus actually fire immediately

adjust also ata_exec_command driver hooks similarily - remove all
completion and waiting logic from drivers, upper layer ata code
using AT_WAIT/AT_POLL changed to call ata_wait_cmd() itself
PR kern/55169 by Nick Hudson

Function declaration formating whitespace consistency. NFCI.

PR kern/56403
Fix kernel freeze for wdc(4) variants with ATAC_CAP_NOIRQ:

(1) Change ata_xfer_ops:c_poll from void to int function. When it returns
ATAPOLL_AGAIN, let ata_xfer_start() iterate itself again.
(2) Let wdc_ata_bio_poll() return ATAPOLL_AGAIN until ATA_ITSDONE is
achieved.

A similar change has been made for mvsata(4) (see mvsata_bio_poll()),
and no functional changes for other devices.

This is how the drivers worked before jdolecek-ncq branch was merged.
Note that this changes are less likely to cause infinite recursion:

(1) wdc_ata_bio_intr() called from wdc_ata_bio_poll() asserts ATA_ITSDONE
in its error handling paths via wdc_ata_bio_done().
(2) Return value from c_start (= wdc_ata_bio_start()) is checked in
ata_xfer_start().

Therefore, errors encountered in ata_xfer_ops:c_poll and c_start routines
terminate the recursion for wdc(4). The situation is similar for mvsata(4).

Still, there is a possibility where ata_xfer_start() takes long time to
finish a normal operation. This can result in a delayed response for lower
priority interrupts. But, I've never observed such a situation, even when
heavy thrashing takes place for swap partition in wd(4).
"Go ahead" by jdolecek@.
 1.75.4.4 30-Dec-2020  martin Pull up following revision(s) (requested by jmcneill in ticket #1167):

sys/dev/ic/ahcisata_core.c: revision 1.84
sys/dev/ic/ahcisata_core.c: revision 1.85
sys/dev/ic/ahcisata_core.c: revision 1.88
sys/dev/ic/ahcisata_core.c: revision 1.89
sys/arch/arm/nvidia/tegra_ahcisata.c: revision 1.13
sys/dev/ic/ahcisatavar.h: revision 1.26
sys/dev/ic/ahcisata_core.c: revision 1.90
sys/dev/ic/ahcisata_core.c: revision 1.91
sys/dev/ic/ahcisata_core.c: revision 1.92
sys/dev/ata/satareg.h: revision 1.6

ahci_exec_fis: wait for the correct amount of time when AT_WAIT is set

Retry clearing WDCTL_RST a few times before giving up. Makes SATA work in
Solidrun Honeycomb LX2K.

AHCI 1.3.1 specification says that it is good practice for system software
to 'zero-out' the memory allocated and referenced by PxCLB and PxFB.

ahci_intr: use ffs in the port bitmask instead of looping over all 32 bits

AHCI 1.3.1 section 5.5.3 "Processing Completed Commands" says that we
should clear PxIS before IS.IPS.

Add G3 and DevSleep definitions. This changes the mask used by
SControl_IPM_NONE from 0x3 to 0x7.

Make sure to ack IS after PxIS when polling and when using multiple MSI-X
messages.

Remove the AHCI_QUIRK_SKIP_RESET quirk now that the underlying issue is
fixed.
 1.75.4.3 21-Jan-2020  martin Pull up following revision(s) (requested by simonb in ticket #630):

sys/dev/ic/ahcisatavar.h: revision 1.24
sys/dev/pci/ahcisata_pci.c: revision 1.57
sys/dev/ic/ahcisata_core.c: revision 1.81

Add new AHCI_QUIRK_BADNCQ quick for controllers that have issues with
NCQ on (some) drives. Enable this quirk for ATI (AMD) SB600/SB700
controllers. Alternate fix for kern/54790 and kern/54855.
ok jdolecek@, tested on my SB700 chipset and tsutsui's SB600 chipset.
 1.75.4.2 24-Dec-2019  martin Pull up following revision(s) (requested by jmcneill in ticket #576):

sys/dev/ic/ahcisata_core.c: revision 1.79

When resetting a drive, if the command list is running and CLO is not
supported, attempt to stop the drive first and fail gracefully if that
fails instead of triggering a KASSERT on DIAGNOSTIC kernels.
 1.75.4.1 23-Oct-2019  martin Pull up following revision(s) (requested by jdolecek in ticket #357):

sys/dev/ic/ahcisata_core.c: revision 1.76

Ensure cmdh_prdtl is 0 in ahci_do_reset_drive().
(I'm probably just being paranoid here.)
 1.80.2.2 29-Feb-2020  ad Sync with head.
 1.80.2.1 25-Jan-2020  ad Sync with head.
 1.82.4.1 20-Apr-2020  bouyer Sync with HEAD
 1.83.2.2 03-Apr-2021  thorpej Sync with HEAD.
 1.83.2.1 03-Jan-2021  thorpej Sync w/ HEAD.
 1.97.2.1 02-Apr-2021  thorpej config_found_ia() -> config_found() w/ CFARG_IATTR.
 1.98.2.1 01-Aug-2021  thorpej Sync with HEAD.
 1.99.2.1 04-Aug-2021  thorpej Adapt to CFARGS().
 1.107.4.1 11-Sep-2023  martin Pull up following revision(s) (requested by abs in ticket #366):

sys/dev/pci/ahcisata_pci.c: revision 1.70
sys/dev/ic/ahcisata_core.c: revision 1.108
sys/dev/ic/ahcisatavar.h: revision 1.28
sys/conf/files: revision 1.1309

Rework AHCISATA_EXTRA_DELAY for kern/56737
- Remove AHCI_QUIRK_EXTRA_DELAY as issue appears to be drive and
not controller related
- Replace AHCISATA_EXTRA_DELAY with AHCISATA_REMOVE_EXTRA_DELAY,
so defaulting to enabling the extra delay, as the downside of
slower probing on systems which do not need it is less than having
other systems intermittently fail to probe and attach drives
- Also allow disabling extra delay with AHCISATA_EXTRA_DELAY_MS = 0

We should return to this code to work out which of the extra delays
are needed, and how long they need to be. It may be that faster
systems are more likely to trigger the issue (I've only seen it on
a 13th gen i7-13700, though only tested on a limited set)
 1.17 07-Jan-2025  andvar fix various typos in commments.
 1.16 24-Jul-2021  andvar branches: 1.16.16;
Fix all remaining typos, mainly in comments but also in few definitions and log messages, reported by me in PR kern/54889.
Also fixed some additional typos in comments, found on review of same files or typos.
 1.15 14-Jan-2019  jdolecek branches: 1.15.16;
fix typo in comment
 1.14 03-Dec-2018  jdolecek fix typo in comment, NFC
 1.13 07-Oct-2017  jdolecek branches: 1.13.2; 1.13.4;
Merge support for SATA NCQ (Native Command Queueing) from jdolecek-ncq branch

ATA subsystem was changed to support several outstanding commands, and use
NCQ xfers if supported by both the controller and the disk, including NCQ
error recovery. Set NCQ high priority for BPRIO_TIMECRITICAL xfers
if supported. Added FUA support.

Done some work towards MP-safe, all ATA code tsleep()/wakeup() replaced
by condvars, and switched most code from spl* to mutexes (separate
wd(4) and ata channel lock).

Introduced new option WD_CHAOS_MONKEY to facilitate testing of error
handling, fixed several uncovered issues. Also fixed several problems
with kernel dump to wd(4) disk.

Tested with ahcisata(4), mvsata(4), siisata(4), piixide(4) on amd64,
with and without port multiplier, both disk and ATAPI devices; other
drivers and archs mechanically adjusted and compile-tested. NCQ is
supported for ahcisata(4) and siisata(4) for any controller, for
mvsata(4) only Gen IIe ones for now. Also enabled ATAPI support in
mvsata(4).

Thanks to Matt Thomas for initial ATA infrastructure patch, and
Jonathan A.Kollasch for siisata(4) NCQ changes and general testing.

Also fixes PR kern/43169 (wd(4)); and PR kern/11811, PR kern/47041,
PR kern/51979 (kernel dump)
 1.12 17-Oct-2012  matt branches: 1.12.26;
Fix an errant define.
 1.11 02-Nov-2011  jakllsch branches: 1.11.2; 1.11.12;
Additionally apply __aligned(8) to all __packed hardware data structures.
(The hardware actually requires much larger alignment on these structures
(128 to 1024 bytes), but 8 is big enough for the compiler to generate more
efficient code on strict alignment architectures.)
 1.10 20-Aug-2011  jakllsch Add new CAP2 and BOHC registers.
 1.9 20-Aug-2011  jakllsch Adjust and add AHCI_CAP_IS values.
 1.8 20-Aug-2011  jakllsch Rework version printout to be more future proof.
Rework features printout using snprintb.
 1.7 20-Jul-2010  jakllsch Prepare ahcisata(4) to work with 64-bit bus_dma_tag_t.
 1.6 20-Jul-2010  jakllsch Convert ahcisata(4) to C99 exact-width integer types.
 1.5 19-Oct-2009  bouyer branches: 1.5.2; 1.5.4;
Remove closes 3 & 4 from my licence. Lots of thanks to Soren Jacobsen
for the booring work !
 1.4 25-Jan-2008  xtraeme branches: 1.4.10; 1.4.28;
Make it print the correct version for AHCI 1.2 controllers.
 1.3 25-Dec-2007  perry Convert many of the uses of __attribute__ to equivalent
__packed, __unused and __dead macros from cdefs.h
 1.2 16-Sep-2007  bouyer branches: 1.2.6; 1.2.8; 1.2.12;
Fix various error handling bugs:
- the value of the ATA error register would be computed wrongly, leading to
bogus error values reported to wd(4)
- the channel would not always be restarted after an error, so the next
command would not be handled by the controller
- a timeout condition would not be properly reported to wd(4), leading
to a short transfer instead of a reset/retry
these bugs would cause a AHCI SATA channel to be stalled (no more command
processed) after a "ID not found" or "Aborted command" error reported by the
drive.
 1.1 12-May-2007  bouyer branches: 1.1.2; 1.1.4; 1.1.6; 1.1.12; 1.1.14; 1.1.16; 1.1.18; 1.1.20;
Split the ahcisata driver in pci front-end and bus-independant back-end.
 1.1.20.5 04-Feb-2008  yamt sync with head.
 1.1.20.4 21-Jan-2008  yamt sync with head
 1.1.20.3 27-Oct-2007  yamt sync with head.
 1.1.20.2 03-Sep-2007  yamt sync with head.
 1.1.20.1 12-May-2007  yamt file ahcisatareg.h was added on branch yamt-lazymbuf on 2007-09-03 14:34:14 +0000
 1.1.18.3 23-Sep-2007  wrstuden Sync with somewhat-recent netbsd-4.
 1.1.18.2 03-Sep-2007  wrstuden Sync w/ NetBSD-4-RC_1
 1.1.18.1 12-May-2007  wrstuden file ahcisatareg.h was added on branch wrstuden-fixsa on 2007-09-03 07:04:22 +0000
 1.1.16.3 16-Sep-2007  xtraeme Pull up following revision(s) (requested by bouyer in ticket #882):
sys/dev/ic/ahcisata_core.c: revision 1.5
sys/dev/ic/ahcisatareg.h: revision 1.2

Fix various error handling bugs:
- the value of the ATA error register would be computed wrongly, leading to
bogus error values reported to wd(4)
- the channel would not always be restarted after an error, so the next
command would not be handled by the controller
- a timeout condition would not be properly reported to wd(4), leading
to a short transfer instead of a reset/retry
these bugs would cause a AHCI SATA channel to be stalled (no more command
processed) after a "ID not found" or "Aborted command" error reported by the
drive.
 1.1.16.2 31-Aug-2007  pavel Pull up following revision(s) (requested by bouyer in ticket #678):
distrib/sets/lists/man/mi: revision 1.1001
doc/CHANGES: revision 1.853 via patch
share/man/man4/Makefile: revision 1.428
share/man/man4/jmide.4: revision 1.1
sys/arch/amd64/conf/GENERIC: revision 1.143
sys/arch/amd64/conf/INSTALL: revision 1.69
sys/arch/i386/conf/GENERIC: revision 1.827
sys/arch/i386/conf/INSTALL_LARGE: revision 1.2 via patch
sys/arch/i386/conf/XEN2_DOM0: revision 1.26
sys/conf/files: revision 1.844 via patch
sys/dev/ic/ahcisata_core.c: revision 1.1 via patch
sys/dev/ic/ahcisata_core.c: revision 1.3
sys/dev/ic/ahcisatareg.h: revision 1.1
sys/dev/ic/ahcisatavar.h: revision 1.1
sys/dev/pci/ahcisata.c: delete
sys/dev/pci/ahcisatareg.h: delete
sys/dev/pci/ahcisata_pci.c: revision 1.1
sys/dev/pci/files.pci: revision 1.287-1.288
sys/dev/pci/jmide.c: revision 1.1-1.2
sys/dev/pci/jmide_reg.h: revision 1.1
sys/dev/pci/pcidevs: revision 1.878
Add JMicron Technology vendor ID, and their current PCIe SATA/PATA
controllers.

Split the ahcisata driver in pci front-end and bus-independant back-end.
add jmide(4), a driver for the JMicron Technology JMB36x PCIe to SATA II/PATA
controllers. These controllers can be found on add-on PCIe cards, or
on some motherboards to provide the PATA connectivity (e.g. some intel
ICH8-based motherboards).
Thanks to JMicron Technology for providing me documentation and
different sample boards for this work.

Move mapping of AHCI register so that jmide knows if it fails, and avoids
calling ahci_intr() (which would cause a panic).
Try to use the pciide function for SATA drives if attaching ahci fails (this
doesn't seems to work though, it may be BIOS dependant).
Thanks to Gary Duzan for testing multiple pacthes.

We're not ready to handle ATAPI yet so just claim there's no drive to the
upper layer. This should work around a NULL pointer dereference when
an ATAPI device is detected on a AHCI device.
 1.1.16.1 12-May-2007  pavel file ahcisatareg.h was added on branch netbsd-4 on 2007-08-31 20:09:23 +0000
 1.1.14.3 23-Mar-2008  matt sync with HEAD
 1.1.14.2 09-Jan-2008  matt sync with HEAD
 1.1.14.1 06-Nov-2007  matt sync with HEAD
 1.1.12.1 02-Oct-2007  joerg Sync with HEAD.
 1.1.6.2 11-Jul-2007  mjf Sync with head.
 1.1.6.1 12-May-2007  mjf file ahcisatareg.h was added on branch mjf-ufs-trans on 2007-07-11 20:05:38 +0000
 1.1.4.3 09-Oct-2007  ad Sync with head.
 1.1.4.2 09-Jun-2007  ad Sync with head.
 1.1.4.1 12-May-2007  ad file ahcisatareg.h was added on branch vmlocking on 2007-06-09 21:37:13 +0000
 1.1.2.2 17-May-2007  yamt sync with head.
 1.1.2.1 12-May-2007  yamt file ahcisatareg.h was added on branch yamt-idlelwp on 2007-05-17 13:41:25 +0000
 1.2.12.1 02-Jan-2008  bouyer Sync with HEAD
 1.2.8.1 26-Dec-2007  ad Sync with head.
 1.2.6.1 18-Feb-2008  mjf Sync with HEAD.
 1.4.28.1 24-Mar-2014  matt Merge needed changes from HEAD for cubie
 1.4.10.2 11-Aug-2010  yamt sync with head.
 1.4.10.1 11-Mar-2010  yamt sync with head
 1.5.4.1 05-Mar-2011  rmind sync with head
 1.5.2.1 17-Aug-2010  uebayasi Sync with HEAD.
 1.11.12.3 03-Dec-2017  jdolecek update from HEAD
 1.11.12.2 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.11.12.1 09-Oct-2012  bouyer Support transfers of up to MACHINE_MAXPHYS in all pciide variants, and ahci.
wd(4) limits its maxphys depending on the drives's capability (64k sectors
for LBA48, 256 sectors for LBA and 128 sectors for older devices).

I assumed all pciide controllers could do MACHINE_MAXPHYS transfers, but
this may not be true. The capabilities of each controller variants should be
looked at more closely.
 1.11.2.1 30-Oct-2012  yamt sync with head
 1.12.26.2 29-Jul-2017  jdolecek fix AHCI_P_CMD_CCS_SHIFT - must shift only by 8, otherwise the result would
be always 0
 1.12.26.1 19-Jul-2017  jdolecek update error handling:
- switch to ata_timeout()
- stop using ch_status/ch_error for passing state/error, stop setting
ATACH_IRQ_WAIT in ch_flags; pass the state via the last parameter
to c_intr() routine
- add NCQ recovery and KILL_REQUEUE
- only call atastart() in c_intr() if there was no error

ahcisata-specific tweaks:
- add some handling for PM in the error recovery using FBS register,
according to spec it should be independant of actual FBSS feature; untested
as my hw doesn't support PM
 1.13.4.1 10-Jun-2019  christos Sync with HEAD
 1.13.2.2 18-Jan-2019  pgoyette Synch with HEAD
 1.13.2.1 26-Dec-2018  pgoyette Sync with HEAD, resolve a few conflicts
 1.15.16.1 01-Aug-2021  thorpej Sync with HEAD.
 1.16.16.1 02-Aug-2025  perseant Sync with HEAD
 1.28 10-Sep-2023  abs Rework AHCISATA_EXTRA_DELAY for kern/56737

- Remove AHCI_QUIRK_EXTRA_DELAY as issue appears to be drive and
not controller related
- Replace AHCISATA_EXTRA_DELAY with AHCISATA_REMOVE_EXTRA_DELAY,
so defaulting to enabling the extra delay, as the downside of
slower probing on systems which do not need it is less than having
other systems intermittently fail to probe and attach drives
- Also allow disabling extra delay with AHCISATA_EXTRA_DELAY_MS = 0

We should return to this code to work out which of the extra delays
are needed, and how long they need to be. It may be that faster
systems are more likely to trigger the issue (I've only seen it on
a 13th gen i7-13700, though only tested on a limited set)

XXX pullup -10
 1.27 19-Nov-2021  rin branches: 1.27.4;
ahcisata(4): Introduce AHCI_QUIRK_EXTRA_DELAY quirk for devices that
need extra delays as done by AHCISATA_EXTRA_DELAY option.

Enable this quirk for "C600/X79 AHCI". Also add commented out quirk
entries for "Bay Trail SATA (AHCI)" and "Mobile AHCI SATA Controller",
for which non-reproducible failures worked around by extra delays have
been reported.

500 ms of delays inserted by these option/quirk may be too much. Add
AHCISATA_EXTRA_DELAY_MS option to adjust number of delays in ms, like:

----
options AHCISATA_EXTRA_DELAY_MS=200
----

Thanks prlw1@ and jun@ for testing!
 1.26 28-Dec-2020  jmcneill Remove the AHCI_QUIRK_SKIP_RESET quirk now that the underlying issue is
fixed.
 1.25 25-Dec-2020  skrll Trailing whitespace
 1.24 18-Jan-2020  simonb branches: 1.24.6;
Add new AHCI_QUIRK_BADNCQ quick for controllers that have issues with
NCQ on (some) drives. Enable this quirk for ATI (AMD) SB600/SB700
controllers. Alternate fix for kern/54790 and kern/54855.

ok jdolecek@, tested on my SB700 chipset and tsutsui's SB600 chipset.
 1.23 29-Sep-2019  jakllsch branches: 1.23.2;
Make AHCI_RFIS_SYNC macro (currently unused) compile.
 1.22 14-Jan-2019  jdolecek branches: 1.22.4;
nothing handles AHCI_QUIRK_BADPMPRESET quirk, remove and change all entries
using it (ATI SB600/SB700) to instead use AHCI_QUIRK_BADPMP
 1.21 07-Dec-2018  jdolecek add optional hook for intr establish when active port is attached, export
ahci_intr_port() in form suitable for interrupt hanlder, and probe for GHC
MRSM flag as courtesy for use by the intr hook

towards multi-vector MSI/MSI-X support
 1.20 24-Oct-2018  jdolecek detach the controller itself on shutdown; adjust to not detach already
detached atabus/channel
 1.19 22-Oct-2018  jdolecek Merge jdolecek-ncqfixes branch

- ata_xfer's are dynamicall allocated as needed using a pool, no longer
limited to number of possible openings supported by controller; dump
and recovery paths use dedicated pre-allocated storage
- moved callouts and condvars from ata_xfer to queue or channel, so that
ata_xfer does not need special initialization
- slot allocation now done when xfer is being activated, uncoupled
from memory allocation; active slots are no longer tracked by controller
code
- channel and drive reset is done always via the atabus thread, and
now executes with channel locked the whole time
- NCQ recovery moved to shared function, and run via the thread also
- added some workarounds for buggy error recovery AHCI emulation in QEMU
and Parallels

designed to primarily fix kern/52614, but might also help with kern/47041
and kern/53183
 1.18 07-Oct-2017  jdolecek branches: 1.18.2; 1.18.4; 1.18.6;
Merge support for SATA NCQ (Native Command Queueing) from jdolecek-ncq branch

ATA subsystem was changed to support several outstanding commands, and use
NCQ xfers if supported by both the controller and the disk, including NCQ
error recovery. Set NCQ high priority for BPRIO_TIMECRITICAL xfers
if supported. Added FUA support.

Done some work towards MP-safe, all ATA code tsleep()/wakeup() replaced
by condvars, and switched most code from spl* to mutexes (separate
wd(4) and ata channel lock).

Introduced new option WD_CHAOS_MONKEY to facilitate testing of error
handling, fixed several uncovered issues. Also fixed several problems
with kernel dump to wd(4) disk.

Tested with ahcisata(4), mvsata(4), siisata(4), piixide(4) on amd64,
with and without port multiplier, both disk and ATAPI devices; other
drivers and archs mechanically adjusted and compile-tested. NCQ is
supported for ahcisata(4) and siisata(4) for any controller, for
mvsata(4) only Gen IIe ones for now. Also enabled ATAPI support in
mvsata(4).

Thanks to Matt Thomas for initial ATA infrastructure patch, and
Jonathan A.Kollasch for siisata(4) NCQ changes and general testing.

Also fixes PR kern/43169 (wd(4)); and PR kern/11811, PR kern/47041,
PR kern/51979 (kernel dump)
 1.17 24-May-2015  jmcneill branches: 1.17.6;
Add AHCI_QUIRK_SKIP_RESET quirk to allow for skipping the drive reset
sequence in ahci_do_reset_drive.
 1.16 24-Feb-2014  jmcneill branches: 1.16.6;
- Only enable AHCI mode if it is not already enabled.
- Add support for capturing initial CAP/CAP2/PI regs before reset (and
restoring them afterwords)
- Add optional callbacks for channel_start / channel_stop.
 1.15 08-Sep-2013  matt Allow the attachment to override ahci_ports.
Keep ACHI_PI cached in the softc.
 1.14 20-Sep-2012  matt branches: 1.14.2;
sc_ahci_cap should be uint32_t
 1.13 20-Aug-2012  bouyer branches: 1.13.2;
Fix typo, pointed out by Markus W Kilbinger
 1.12 13-Aug-2012  bouyer Give AHCI_QUIRK_BADPMPRESET its own bit. Pointed out by Chuck Silvers, thanks !
 1.11 10-Aug-2012  bouyer Work around some SATA PMP issues in some AHCI controllers by either
disabling PMP entirely, or special handling in the reset function.
Controller list from linux and FreeBSD.
 1.10 31-Jul-2012  bouyer Apply back changes that were reverted on Jul 24 and Jul 26 (general ata/wdc
cleanup and SATA PMP support), now that I'm back to fix the fallouts.
 1.9 26-Jul-2012  jakllsch Revert, with intention of restoring in a less invasive way, the SATA Port
Multiplier code.

ok christos@
 1.8 02-Jul-2012  bouyer Add sata Port MultiPlier (PMP) support to the ata bus layer,
as described in
http://mail-index.netbsd.org/tech-kern/2012/06/23/msg013442.html
PMP support in integrated to the atabus layer.
struct ata_channel's ch_drive[] is not dynamically allocated, and ch_ndrive
(renamed to ch_ndrives) closely reflects the size of the ch_drive[] array.
Add helper functions atabus_alloc_drives() and atabus_free_drives()
to manage ch_drive[]/ch_ndrives.
Add wdc_maxdrives to struct wdc_softc so that bus front-end can specify
how much drive they really support (master/slave or single).
ata_reset_drive() callback gains a uint32_t *sigp argument which,
when not NULL, will contain the signature of the device being reset.
While there, some cosmetic changes:
- added a drive_type enum to ata_drive_datas, and stop encoding the
probed drive type in drive_flags (we were out of drive flags anyway).
- rename DRIVE_ATAPIST to DRIVE_ATAPIDSCW to better reflect what this
really is
- remove ata_channel->ata_drives, it's redundant with the pointer in
ata_drive_datas
- factor out the interpretation of SATA signatures in sata_interpet_sig()

propagate these changes to the ATA HBA drivers, and add support for PMP
to ahcisata(4) and siisata(4).

Thanks to:
- Protocase (http://www.protocase.com/) which provided a system
with lots of controllers, SATA PMP and drive slots
- Conservation Genomics Laboratory, Department of Biology, New Mexico State
University for hosting the above system
- Brook Milligan, who set up remote access and has been very responsive
when SATA cable move was needed
 1.7 27-Jul-2010  jakllsch branches: 1.7.8;
Support detachment of ahcisata(4).
Use use 64-bit DMA tag (where available) for ahcisata(4) at jmide(4).
Beginnings of detach/resume support for jmide(4).
Sprinkle static. Misc. little changes.
 1.6 20-Jul-2010  jakllsch Convert ahcisata(4) to C99 exact-width integer types.
 1.5 19-Oct-2009  bouyer branches: 1.5.2; 1.5.4;
Remove closes 3 & 4 from my licence. Lots of thanks to Soren Jacobsen
for the booring work !
 1.4 18-Mar-2008  cube branches: 1.4.4; 1.4.22;
Split device_t and softc for ATA devices, as well as wd(4). Other
cosmetic changes where appropriate.
 1.3 11-Feb-2008  xtraeme branches: 1.3.2; 1.3.6;
Attach ahcisata(4) to any RAID controller that supports AHCI, and make it
pass the ATAC_CAP_RAID capability for them. ok'ed by bouyer@.
 1.2 12-Nov-2007  joerg Merge refactoring from jmcneill-pm.
 1.1 12-May-2007  bouyer branches: 1.1.2; 1.1.4; 1.1.6; 1.1.12; 1.1.14; 1.1.16; 1.1.18; 1.1.20; 1.1.24; 1.1.26;
Split the ahcisata driver in pci front-end and bus-independant back-end.
 1.1.26.2 18-Feb-2008  mjf Sync with HEAD.
 1.1.26.1 19-Nov-2007  mjf Sync with HEAD.
 1.1.24.1 13-Nov-2007  bouyer Sync with HEAD
 1.1.20.5 24-Mar-2008  yamt sync with head.
 1.1.20.4 11-Feb-2008  yamt sync with head.
 1.1.20.3 15-Nov-2007  yamt sync with head.
 1.1.20.2 03-Sep-2007  yamt sync with head.
 1.1.20.1 12-May-2007  yamt file ahcisatavar.h was added on branch yamt-lazymbuf on 2007-09-03 14:34:14 +0000
 1.1.18.2 03-Sep-2007  wrstuden Sync w/ NetBSD-4-RC_1
 1.1.18.1 12-May-2007  wrstuden file ahcisatavar.h was added on branch wrstuden-fixsa on 2007-09-03 07:04:23 +0000
 1.1.16.2 31-Aug-2007  pavel Pull up following revision(s) (requested by bouyer in ticket #678):
distrib/sets/lists/man/mi: revision 1.1001
doc/CHANGES: revision 1.853 via patch
share/man/man4/Makefile: revision 1.428
share/man/man4/jmide.4: revision 1.1
sys/arch/amd64/conf/GENERIC: revision 1.143
sys/arch/amd64/conf/INSTALL: revision 1.69
sys/arch/i386/conf/GENERIC: revision 1.827
sys/arch/i386/conf/INSTALL_LARGE: revision 1.2 via patch
sys/arch/i386/conf/XEN2_DOM0: revision 1.26
sys/conf/files: revision 1.844 via patch
sys/dev/ic/ahcisata_core.c: revision 1.1 via patch
sys/dev/ic/ahcisata_core.c: revision 1.3
sys/dev/ic/ahcisatareg.h: revision 1.1
sys/dev/ic/ahcisatavar.h: revision 1.1
sys/dev/pci/ahcisata.c: delete
sys/dev/pci/ahcisatareg.h: delete
sys/dev/pci/ahcisata_pci.c: revision 1.1
sys/dev/pci/files.pci: revision 1.287-1.288
sys/dev/pci/jmide.c: revision 1.1-1.2
sys/dev/pci/jmide_reg.h: revision 1.1
sys/dev/pci/pcidevs: revision 1.878
Add JMicron Technology vendor ID, and their current PCIe SATA/PATA
controllers.

Split the ahcisata driver in pci front-end and bus-independant back-end.
add jmide(4), a driver for the JMicron Technology JMB36x PCIe to SATA II/PATA
controllers. These controllers can be found on add-on PCIe cards, or
on some motherboards to provide the PATA connectivity (e.g. some intel
ICH8-based motherboards).
Thanks to JMicron Technology for providing me documentation and
different sample boards for this work.

Move mapping of AHCI register so that jmide knows if it fails, and avoids
calling ahci_intr() (which would cause a panic).
Try to use the pciide function for SATA drives if attaching ahci fails (this
doesn't seems to work though, it may be BIOS dependant).
Thanks to Gary Duzan for testing multiple pacthes.

We're not ready to handle ATAPI yet so just claim there's no drive to the
upper layer. This should work around a NULL pointer dereference when
an ATAPI device is detected on a AHCI device.
 1.1.16.1 12-May-2007  pavel file ahcisatavar.h was added on branch netbsd-4 on 2007-08-31 20:09:24 +0000
 1.1.14.2 23-Mar-2008  matt sync with HEAD
 1.1.14.1 09-Jan-2008  matt sync with HEAD
 1.1.12.1 04-Aug-2007  he Factor out the hardware initialization code in ahcisata_core.c,
and provide them to the pci frontend, which has now grown its own
softc and a power management handler.

There may be one too many re-initializations done on resume (witness
the multiple kernel messages from ahcisata), but at least this is
sufficient to get the Lenovo T60 to come out of resume with a
working disk controller and disk.
 1.1.6.2 11-Jul-2007  mjf Sync with head.
 1.1.6.1 12-May-2007  mjf file ahcisatavar.h was added on branch mjf-ufs-trans on 2007-07-11 20:05:39 +0000
 1.1.4.2 09-Jun-2007  ad Sync with head.
 1.1.4.1 12-May-2007  ad file ahcisatavar.h was added on branch vmlocking on 2007-06-09 21:37:13 +0000
 1.1.2.2 17-May-2007  yamt sync with head.
 1.1.2.1 12-May-2007  yamt file ahcisatavar.h was added on branch yamt-idlelwp on 2007-05-17 13:41:25 +0000
 1.3.6.1 03-Apr-2008  mjf Sync with HEAD.
 1.3.2.1 24-Mar-2008  keiichi sync with head.
 1.4.22.1 24-Mar-2014  matt Merge needed changes from HEAD for cubie
 1.4.4.2 11-Aug-2010  yamt sync with head.
 1.4.4.1 11-Mar-2010  yamt sync with head
 1.5.4.1 05-Mar-2011  rmind sync with head
 1.5.2.1 17-Aug-2010  uebayasi Sync with HEAD.
 1.7.8.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.7.8.1 30-Oct-2012  yamt sync with head
 1.13.2.3 03-Dec-2017  jdolecek update from HEAD
 1.13.2.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.13.2.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.14.2.1 18-May-2014  rmind sync with head
 1.16.6.1 06-Jun-2015  skrll Sync with HEAD
 1.17.6.3 01-Aug-2017  jdolecek fix logic bug in processing of finished commands - mask of active
commands can change during the loop as c_intr() callback can queue
new commands, so the interrupt routine should only mark as finished
those which were actually active before the loop started; otherwise
the code marked as finished commands which were just started, and
being executed by HBA, leading to all sorts of data corruption

while here mark the active mask volatile, as it is modified from
interrupt context

this fixes for good the random crashes, short reads, and fatal command
errors which I've been tracing down for past couple weeks

thanks to Jonathan (jakllsch@) for testing, and a script to easily
triggered the condition, and led to this bug being finally found and squashed
 1.17.6.2 29-Jul-2017  jdolecek make compile without AHCI_DEBUG
 1.17.6.1 19-Jul-2017  jdolecek update error handling:
- switch to ata_timeout()
- stop using ch_status/ch_error for passing state/error, stop setting
ATACH_IRQ_WAIT in ch_flags; pass the state via the last parameter
to c_intr() routine
- add NCQ recovery and KILL_REQUEUE
- only call atastart() in c_intr() if there was no error

ahcisata-specific tweaks:
- add some handling for PM in the error recovery using FBS register,
according to spec it should be independant of actual FBSS feature; untested
as my hw doesn't support PM
 1.18.6.1 11-Oct-2018  jdolecek refactor shared parts of the SATA error recovery into new function
ata_recovery_resume() and use for ahcisata/siisata/mvsata, also replace
per-controller hold/unhold with generic version

move the shared recovery code into separate file ata_recovery.c
 1.18.4.3 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.18.4.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.18.4.1 10-Jun-2019  christos Sync with HEAD
 1.18.2.3 18-Jan-2019  pgoyette Synch with HEAD
 1.18.2.2 26-Dec-2018  pgoyette Sync with HEAD, resolve a few conflicts
 1.18.2.1 26-Nov-2018  pgoyette Sync with HEAD, resolve a couple of conflicts
 1.22.4.2 30-Dec-2020  martin Pull up following revision(s) (requested by jmcneill in ticket #1167):

sys/dev/ic/ahcisata_core.c: revision 1.84
sys/dev/ic/ahcisata_core.c: revision 1.85
sys/dev/ic/ahcisata_core.c: revision 1.88
sys/dev/ic/ahcisata_core.c: revision 1.89
sys/arch/arm/nvidia/tegra_ahcisata.c: revision 1.13
sys/dev/ic/ahcisatavar.h: revision 1.26
sys/dev/ic/ahcisata_core.c: revision 1.90
sys/dev/ic/ahcisata_core.c: revision 1.91
sys/dev/ic/ahcisata_core.c: revision 1.92
sys/dev/ata/satareg.h: revision 1.6

ahci_exec_fis: wait for the correct amount of time when AT_WAIT is set

Retry clearing WDCTL_RST a few times before giving up. Makes SATA work in
Solidrun Honeycomb LX2K.

AHCI 1.3.1 specification says that it is good practice for system software
to 'zero-out' the memory allocated and referenced by PxCLB and PxFB.

ahci_intr: use ffs in the port bitmask instead of looping over all 32 bits

AHCI 1.3.1 section 5.5.3 "Processing Completed Commands" says that we
should clear PxIS before IS.IPS.

Add G3 and DevSleep definitions. This changes the mask used by
SControl_IPM_NONE from 0x3 to 0x7.

Make sure to ack IS after PxIS when polling and when using multiple MSI-X
messages.

Remove the AHCI_QUIRK_SKIP_RESET quirk now that the underlying issue is
fixed.
 1.22.4.1 21-Jan-2020  martin Pull up following revision(s) (requested by simonb in ticket #630):

sys/dev/ic/ahcisatavar.h: revision 1.24
sys/dev/pci/ahcisata_pci.c: revision 1.57
sys/dev/ic/ahcisata_core.c: revision 1.81

Add new AHCI_QUIRK_BADNCQ quick for controllers that have issues with
NCQ on (some) drives. Enable this quirk for ATI (AMD) SB600/SB700
controllers. Alternate fix for kern/54790 and kern/54855.
ok jdolecek@, tested on my SB700 chipset and tsutsui's SB600 chipset.
 1.23.2.1 25-Jan-2020  ad Sync with head.
 1.24.6.1 03-Jan-2021  thorpej Sync w/ HEAD.
 1.27.4.1 11-Sep-2023  martin Pull up following revision(s) (requested by abs in ticket #366):

sys/dev/pci/ahcisata_pci.c: revision 1.70
sys/dev/ic/ahcisata_core.c: revision 1.108
sys/dev/ic/ahcisatavar.h: revision 1.28
sys/conf/files: revision 1.1309

Rework AHCISATA_EXTRA_DELAY for kern/56737
- Remove AHCI_QUIRK_EXTRA_DELAY as issue appears to be drive and
not controller related
- Replace AHCISATA_EXTRA_DELAY with AHCISATA_REMOVE_EXTRA_DELAY,
so defaulting to enabling the extra delay, as the downside of
slower probing on systems which do not need it is less than having
other systems intermittently fail to probe and attach drives
- Also allow disabling extra delay with AHCISATA_EXTRA_DELAY_MS = 0

We should return to this code to work out which of the extra delays
are needed, and how long they need to be. It may be that faster
systems are more likely to trigger the issue (I've only seen it on
a 13th gen i7-13700, though only tested on a limited set)
 1.107 10-May-2023  riastradh aic(4): Use config_detach_children.
 1.106 05-Apr-2023  andvar s/esssentially/essentially/ in comment.
 1.105 01-Jan-2022  andvar fix typos in comments, mainly basicly -> basically.
 1.104 07-Aug-2021  thorpej Merge thorpej-cfargs2.
 1.103 24-Apr-2021  thorpej branches: 1.103.8;
Merge thorpej-cfargs branch:

Simplify and make extensible the config_search() / config_found() /
config_attach() interfaces: rather than having different variants for
which arguments you want pass along, just have a single call that
takes a variadic list of tag-value arguments.

Adjust all call sites:
- Simplify wherever possible; don't pass along arguments that aren't
actually needed.
- Don't be explicit about what interface attribute is attaching if
the device only has one. (More simplification.)
- Add a config_probe() function to be used in indirect configuiration
situations, making is visibly easier to see when indirect config is
in play, and allowing for future change in semantics. (As of now,
this is just a wrapper around config_match(), but that is an
implementation detail.)

Remove unnecessary or redundant interface attributes where they're not
needed.

There are currently 5 "cfargs" defined:
- CFARG_SUBMATCH (submatch function for direct config)
- CFARG_SEARCH (search function for indirect config)
- CFARG_IATTR (interface attribte)
- CFARG_LOCATORS (locators array)
- CFARG_DEVHANDLE (devhandle_t - wraps OFW, ACPI, etc. handles)

...and a sentinel value CFARG_EOL.

Add some extra sanity checking to ensure that interface attributes
aren't ambiguous.

Use CFARG_DEVHANDLE in MI FDT, OFW, and ACPI code, and macppc and shark
ports to associate those device handles with device_t instance. This
will trickle trough to more places over time (need back-end for pre-OFW
Sun OBP; any others?).
 1.102 03-Sep-2018  riastradh branches: 1.102.14;
Rename min/max -> uimin/uimax for better honesty.

These functions are defined on unsigned int. The generic name
min/max should not silently truncate to 32 bits on 64-bit systems.
This is purely a name change -- no functional change intended.

HOWEVER! Some subsystems have

#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))

even though our standard name for that is MIN/MAX. Although these
may invite multiple evaluation bugs, these do _not_ cause integer
truncation.

To avoid `fixing' these cases, I first changed the name in libkern,
and then compile-tested every file where min/max occurred in order to
confirm that it failed -- and thus confirm that nothing shadowed
min/max -- before changing it.

I have left a handful of bootloaders that are too annoying to
compile-test, and some dead code:

cobalt ews4800mips hp300 hppa ia64 luna68k vax
acorn32/if_ie.c (not included in any kernels)
macppc/if_gm.c (superseded by gem(4))

It should be easy to fix the fallout once identified -- this way of
doing things fails safe, and the goal here, after all, is to _avoid_
silent integer truncations, not introduce them.

Maybe one day we can reintroduce min/max as type-generic things that
never silently truncate. But we should avoid doing that for a while,
so that existing code has a chance to be detected by the compiler for
conversion to uimin/uimax without changing the semantics until we can
properly audit it all. (Who knows, maybe in some cases integer
truncation is actually intended!)
 1.101 28-Oct-2017  riastradh branches: 1.101.2; 1.101.4;
Kill some more extern struct cfdriver declarations.

Down with externs in .c!
 1.100 11-Jan-2017  skrll adatper -> adapter
 1.99 23-Nov-2009  rmind branches: 1.99.22; 1.99.40; 1.99.44;
Remove some unecessary includes sys/user.h header.
 1.98 12-Nov-2009  dyoung Remove superfluous activation hook.
 1.97 22-Sep-2009  tsutsui Split device_t/softc. Tested on AHA-1520B at ISA and ISAPnP.

XXX: ISA attachment shouldn't match cards in ISAPnP mode.
 1.96 12-May-2009  cegger struct device * -> device_t, no functional changes intended.
 1.95 11-Jun-2008  drochner branches: 1.95.10;
don't use cfdriver_t->cd_devs directly
 1.94 08-Apr-2008  cegger branches: 1.94.2; 1.94.4; 1.94.6; 1.94.8;
use aprint_*_dev and device_xname
 1.93 19-Oct-2007  ad branches: 1.93.16;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.92 16-Nov-2006  christos branches: 1.92.8; 1.92.22; 1.92.24; 1.92.28;
__unused removal on arguments; approved by core.
 1.91 12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.90 28-Aug-2006  xtraeme branches: 1.90.2; 1.90.4;
Remove unused variable 'periph' to make this build.
 1.89 27-Aug-2006  christos typo
 1.88 27-Aug-2006  christos ifdef out unreachable code.
 1.87 20-Feb-2006  thorpej branches: 1.87.2;
Use device_is_active() rather than testing dv_flags for DVF_ACTIVE
directly.
 1.86 24-Dec-2005  perry branches: 1.86.2; 1.86.4; 1.86.6;
Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.85 11-Dec-2005  christos merge ktrace-lwp.
 1.84 27-Feb-2005  perry branches: 1.84.4;
nuke trailing whitespace
 1.83 21-Feb-2005  thorpej Part 1 of a cleanup pass over the SCSI subsystem. The aim is to name
everything "scsi_*", since we really are talking about the SCSI command
set, ATAPI transport not withstanding. Improve the names of many structures,
and prepend "SCSI_" onto all SCSI command opcodes. Place items described
by the SCSI Primary Commands document into scsi_spc.h.
 1.82 24-Aug-2004  thorpej branches: 1.82.4; 1.82.6;
Use ANSI function decls and more use of static.
 1.81 07-Aug-2004  mycroft Copy a bug fix from spc. If the target transferred too much, we would return
a bogus residual count.
 1.80 02-Nov-2003  wiz Fix some typos. From Tom Cosgrove via jmc@openbsd.
 1.79 21-Feb-2003  tsutsui branches: 1.79.2;
hz -> Hz
 1.78 05-Apr-2002  bouyer Implement mstohz() as discussed on tech-kern, and use it in SCSI drivers
to convert xs->timeout to callout() parameter.
 1.77 15-Nov-2001  lukem don't need <sys/types.h> when including <sys/param.h>
 1.76 13-Nov-2001  lukem add/cleanup RCSID
 1.75 04-Nov-2001  tsutsui Use common macro to check message length.
 1.74 07-Jul-2001  thorpej branches: 1.74.2; 1.74.6;
bzero -> memset
 1.73 07-Jul-2001  thorpej bcopy -> memcpy
 1.72 30-Apr-2001  lukem delint
 1.71 25-Apr-2001  bouyer Pull up the thorpej_scsipi branch to main branch.
This is a completely rewritten scsipi_xfer execution engine, and the
associated changes to HBA drivers. Overview of changes & features:
- All xfers are queued in the mid-layer, rather than doing so in an
ad-hoc fashion in individual adapter drivers.
- Adapter/channel resource management in the mid-layer, avoids even trying
to start running an xfer if the adapter/channel doesn't have the resources.
- Better communication between the mid-layer and the adapters.
- Asynchronous event notification mechanism from adapter to mid-layer and
peripherals.
- Better peripheral queue management: freeze/thaw, sorted requeueing during
recovery, etc.
- Clean separation of peripherals, adapters, and adapter channels (no more
scsipi_link).
- Kernel thread for each scsipi_channel makes error recovery much easier
(no more dealing with interrupt context when recovering from an error).
- Mid-layer support for tagged queueing: commands can have the tag type
set explicitly, tag IDs are allocated in the mid-layer (thus eliminating
the need to use buggy tag ID allocation schemes in many adapter drivers).
- support for QUEUE FULL and CHECK CONDITION status in mid-layer; the command
will be requeued, or a REQUEST SENSE will be sent as appropriate.

Just before the merge syssrc has been tagged with thorpej_scsipi_beforemerge
 1.70 05-May-2000  matt branches: 1.70.6;
LP64 printf fix. (I wish size_t was unsigned long on all platforms).
 1.69 30-Mar-2000  augustss Remove register declarations.
 1.68 30-Mar-2000  simonb Delete redundant decl of aicattach(), it's in aic6360var.h.
 1.67 23-Mar-2000  thorpej New callout mechanism with two major improvements over the old
timeout()/untimeout() API:
- Clients supply callout handle storage, thus eliminating problems of
resource allocation.
- Insertion and removal of callouts is constant time, important as
this facility is used quite a lot in the kernel.

The old timeout()/untimeout() API has been removed from the kernel.
 1.66 20-Mar-2000  enami - Test the generic device active flag instead of home grown one.
- Test also it in wdcintr.
 1.65 30-Oct-1999  enami Add and delete a reference to an adapter at aicattach(), to make sure
that the adapter is disabled even if it wasn't enabled/disabled during
configuring its children. This fixes the bug that if an aic pcmcia card
is inserted in a slot during boot, further attaching of any card on the
slot fails once the card is removed.
 1.64 20-Oct-1999  enami Cancel active transfers on aic/wdc detach.
Also makes LS-120 drive works for me again.
 1.63 30-Sep-1999  thorpej branches: 1.63.2; 1.63.4; 1.63.6;
Update for SCSPI changes.
 1.62 26-Sep-1999  enami Allow to detach aic, but turned off by default. The patchable variable
aic_dodetach controlls this.
 1.61 05-Dec-1998  mjacob Update HBAs to incorporate the new max_lun property.
 1.60 19-Nov-1998  thorpej Adapt to the new scsipi_adapter interface.
 1.59 10-Oct-1998  thorpej Garbage-collect the open_target_lu and close_target_lu entry points from
struct scsipi_adapter; they were not used.

Add a scsipi_ioctl entry point to struct scsipi_adapter. This will be
used to issue ioctl commands to the host adapters.

Inspired by PR #6090, from Matt Jacob.
 1.58 04-Jul-1998  jonathan defopt DDB.
 1.57 23-May-1998  matt Changes so that these compile on NetBSD/alpha as well as NetBSD/i386.
 1.56 13-Jan-1998  enami Don't include <machine/pio.h> and <dev/isa/isavar.h>. Instead,
include <machine/bus.h> directly.
 1.55 12-Jan-1998  thorpej Adjust for config changes.
 1.54 06-Oct-1997  christos branches: 1.54.2;
From Enami Tsugutomo: Busify and split the aic6360 driver.
 1.53 27-Aug-1997  bouyer Merge scsipi branch in the mainline. This add support for ATAPI devices
(currently only CD-ROM drives on i386). The sys/dev/scsipi system provides 2
busses to which devices can attach (scsibus and atapibus). This needed to
change some include files and structure names in the low level scsi drivers.
 1.52 10-Dec-1996  thorpej branches: 1.52.8; 1.52.10;
Fill in sc_link.max_target
 1.51 13-Oct-1996  christos backout kprintf changes
 1.50 10-Oct-1996  christos printf -> kprintf, sprintf -> ksprintf
 1.49 28-Aug-1996  cgd (1) set scsi_link channel to either the appropriate channel (if a
multi-channel driver), or to SCSI_CHANNEL_ONLY_ONE if a
single-channel driver.
(2) use scsiprint() rather than a locally-defined autoconfig print
function, and kill any locally-defined print function.
 1.48 27-Aug-1996  cgd change cfprint_t type definition to take a const char *, rather than
a char *, because that's what was really intended, and because
if the print function modifies the string, various things could become
unhappy (so the string should _not_ be modified).
 1.47 18-Jun-1996  mycroft Remove some unneeded FIFO flushes and reorder some register changes per the
6360 manual. Turn off synchronous negotiation.
 1.46 12-May-1996  mycroft Use intr.h.
 1.45 29-Apr-1996  christos - prototype fixes
 1.44 11-Apr-1996  cgd update for addition of a machine-dependent cookie as the first argument
to isa_intr_{,dis}establish().
 1.43 03-Apr-1996  mycroft Minor optimization, and do a CLRCH after (re)selection just to be safe.
 1.42 03-Apr-1996  mycroft * Change message priorities so that ABORT comes after IDENTIFY.
* Add an ACB_RESET flag, so that a BUS DEVICE RESET can be queued within the
driver.
* If ACB_ABORT or ACB_RESET is set during reselection, schedule a message and
assert ATN.
* Optimize aic_datain_pio(), aic_dataout_pio() and aicintr() somewhat.
* Schedule a timeout only when we select the target, so that commands can't
time out prematurely.
 1.41 01-Apr-1996  mycroft Several things:
1) If we get an unexpected disconnect, issue a REQUEST SENSE, as recommended
by the SCSI-2 spec. If the target created a contingent allegiance condition,
this will clear it. Also, if it happened while sending a SDTR or WDTR message,
disable negotiation for that target.
2) Since some lame devices still don't deal correctly, make sure we deassert
ATN if our last message out is interrupted. If we get a MESSAGE PARITY ERROR,
we'll reassert ATN anyway. This should ensure that we never have to send a
MESSAGE NO OPERATION.
3) Set AIC_ABORTING only when actually sending a BUS DEVICE RESET or ABORT,
so we get better error detection.
4) Other internal reorganization of no consequence.
 1.40 30-Mar-1996  mycroft Use `{in.out}b(iobase + ...' rather than including the base address in
the register definitions.
 1.39 17-Mar-1996  thorpej New device attachment scheme:

- split softc size and match/attach out from cfdriver into
a new struct cfattach.

- new "attach" directive for files.*. May specify the name of
the cfattach structure, so that devices may be easily attached
to parents with different autoconfiguration semantics.
 1.38 24-Dec-1995  mycroft The IST_* and IPL_* constants are not bus-specific; don't treat them as such.
Change splimp -> splnet in Ethernet, ARCnet, and FDDI drivers.
 1.37 30-Nov-1995  jtc merge in changes from 1.1 release branch
 1.36 03-Oct-1995  mycroft branches: 1.36.2;
Modularize the CCB/MSCP/ACB/ECB handling a little. No functional changes.
 1.35 26-Sep-1995  thorpej Don't declare Debugger(). It's handled in <sys/systm.h>
 1.34 14-Sep-1995  pk Make *print() a message if no scsibus was attached. Also, return something
valid.
 1.33 12-Aug-1995  mycroft minphys() functions really should return void.
 1.32 24-Jul-1995  cgd update SCSI minphys routines' definitions to match standard minphys()
definition and usage.
 1.31 17-Apr-1995  cgd clean up several ISA device interfaces: autoconfiguration, header
inclusion, and interrupt configuration. more work still needs to be done,
but it's getting better...
 1.30 02-Feb-1995  mycroft Comment a potential bit of lossage.
 1.29 01-Feb-1995  mycroft Various:
* Make synchronous negotiation work.
* Use the bitbucket when the target requests too much data.
* Loop in aicintr() until we get to a state where we have to wait.
 1.28 01-Feb-1995  mycroft Correct some more of the synchronous stuff, and omit it completely if
AIC_USE_SYNCHRONOUS is 0.
 1.27 01-Feb-1995  mycroft Various:
* Always enable disconnection.
* Add some more per-controller variables: initiator ID, clock frequency,
min and max sync period.
* Correct sync period calculations.
* Remove sc_progress.
* Move most of the reselection handling into a separate function.
* Remove some outdated comments.
* Remove message bytes from FIFO even when dropping them on the floor.
* Some cosmetic cleanup.
 1.26 13-Jan-1995  mycroft Simplify some sanity checks.
 1.25 07-Jan-1995  mycroft Don't print line numbers in most of the diagnostics.
 1.24 07-Jan-1995  mycroft Cosmetic changes, to look more like the new esp.c will.
 1.23 03-Jan-1995  mycroft Add interrupt sharing types.
 1.22 31-Dec-1994  mycroft Fix non-serious typo.
 1.21 28-Dec-1994  mycroft Numerous changes. Many bugs fixed, better autoconfig, a few new features.
 1.20 30-Nov-1994  mycroft Don't stall the queue on CHECK SENSE if we get a reselect while selecting.
 1.19 29-Nov-1994  mycroft Fix a null pointer reference.
 1.18 29-Nov-1994  mycroft Add an assertion mechanism to check for more abnormal conditions.
 1.17 29-Nov-1994  mycroft For consistency...
 1.16 29-Nov-1994  mycroft Handle BUS FREE phase a little differently, to get better error detection. Other
cleanup.
 1.15 29-Nov-1994  mycroft Disable debugging breakpoints by default.
 1.14 29-Nov-1994  mycroft * Redo most of the message and phase state machines. Multiple pending
message outs should now work correctly (including retransmissions).
Multiple messages ins should be more efficient. Missing REQ after
reselection phase should now (correctly) cause a wait with ENREQINIT
set.

* Abstract out the reselection out sequence, and use it directly to
get sense info. (This is somewhat faster than the generic done/sched
sequence.)

* If there are no ACBs available, wait interruptibly for one.

* Leave the interrupt registers alone during message in/out; just
watch for phase change. Don't (incorrectly) reenable interrupts
during data in/out; defer that to aicintr().

* Handle command pointer per SCSI 2 spec.

* Other minor coding improvements.
 1.13 18-Nov-1994  mycroft Convert port, IRQ, and DRQ numbers to ints.
 1.12 04-Nov-1994  mycroft No longer needs icu.h.
 1.11 04-Nov-1994  mycroft Change all of the uses of IRQ{0-15} and bit masks to use plain numbers
rather than bit shifting.
 1.10 03-Nov-1994  mycroft Update to match autoconfig code.
 1.9 27-Oct-1994  cgd new RCS ID format.
 1.8 17-Oct-1994  cgd change, requested by Jarle Greipsland
 1.7 08-Aug-1994  mycroft Minor update.
 1.6 07-Aug-1994  mycroft Avoid using DFIFOHF, which doesn't exist on 6260 chips. Turn off
AIC_USE_DWORDS by default.
 1.5 05-May-1994  cgd branches: 1.5.2;
lots of changes: prototype migration, move lots of variables, definitions,
and structure elements around. kill some unnecessary type and macro
definitions. standardize clock handling. More changes than you'd want.
 1.4 03-May-1994  mycroft Fix argument to aic_sched_msgout() is several places, and condense some code.
 1.3 29-Apr-1994  cgd change timeout/untimeout/wakeup/sleep/tsleep args to void *
 1.2 26-Apr-1994  mycroft Style nits.
 1.1 26-Apr-1994  mycroft Add Adaptec 6360 driver from Jarle Greipsland, with some changes by me.
 1.5.2.3 17-Oct-1994  cgd from trunk
 1.5.2.2 08-Aug-1994  mycroft update from trunk
 1.5.2.1 07-Aug-1994  mycroft update from trunk
 1.36.2.1 18-Oct-1995  pk Add missing parentheses (from Jarle Greipsland; PR#1603).
 1.52.10.1 27-Aug-1997  thorpej Update marc-pcmcia branch from trunk.
 1.52.8.1 01-Jul-1997  bouyer Updates for new scsipi subsystem. Actally known to work on i386 and sparc.
 1.54.2.2 14-Oct-1997  thorpej Update marc-pcmcia branch from trunk.
 1.54.2.1 06-Oct-1997  thorpej file aic6360.c was added on branch marc-pcmcia on 1997-10-14 10:22:17 +0000
 1.63.6.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.63.4.1 15-Nov-1999  fvdl Sync with -current
 1.63.2.5 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.63.2.4 26-Oct-1999  thorpej Update for:

Deal a little more gracefully with the fact that xfer mode parameters
are for the I_T Nexus, and make all xfer mode updates `async events'.
 1.63.2.3 20-Oct-1999  thorpej Sync w/ trunk.
 1.63.2.2 19-Oct-1999  thorpej Don't sleep waiting for a CCB; if we get to the CCB allocation phase, we're
guaranteed to have one.
 1.63.2.1 19-Oct-1999  thorpej Adapt to scsipi API changes.
 1.70.6.5 17-Apr-2002  nathanw Catch up to -current.
 1.70.6.4 08-Jan-2002  nathanw Catch up to -current.
 1.70.6.3 14-Nov-2001  nathanw Catch up to -current.
 1.70.6.2 24-Aug-2001  nathanw Catch up with -current.
 1.70.6.1 21-Jun-2001  nathanw Catch up to -current.
 1.74.6.1 12-Nov-2001  thorpej Sync the thorpej-mips-cache branch with -current.
 1.74.2.2 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.74.2.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.79.2.6 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.79.2.5 21-Sep-2004  skrll Fix the sync with head I botched.
 1.79.2.4 18-Sep-2004  skrll Sync with HEAD.
 1.79.2.3 25-Aug-2004  skrll Sync with HEAD.
 1.79.2.2 12-Aug-2004  skrll Sync with HEAD.
 1.79.2.1 03-Aug-2004  skrll Sync with HEAD
 1.82.6.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.82.4.1 29-Apr-2005  kent sync with -current
 1.84.4.3 27-Oct-2007  yamt sync with head.
 1.84.4.2 30-Dec-2006  yamt sync with head.
 1.84.4.1 21-Jun-2006  yamt sync with head.
 1.86.6.1 22-Apr-2006  simonb Sync with head.
 1.86.4.1 09-Sep-2006  rpaulo sync with head
 1.86.2.1 01-Mar-2006  yamt sync with head.
 1.87.2.1 03-Sep-2006  yamt sync with head.
 1.90.4.2 10-Dec-2006  yamt sync with head.
 1.90.4.1 22-Oct-2006  yamt sync with head
 1.90.2.1 18-Nov-2006  ad Sync with head.
 1.92.28.1 25-Oct-2007  bouyer Sync with HEAD.
 1.92.24.1 06-Nov-2007  matt sync with HEAD
 1.92.22.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.92.8.1 23-Oct-2007  ad Sync with head.
 1.93.16.2 29-Jun-2008  mjf Sync with HEAD.
 1.93.16.1 02-Jun-2008  mjf Sync with HEAD.
 1.94.8.1 18-Jun-2008  simonb Sync with head.
 1.94.6.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.94.4.3 11-Mar-2010  yamt sync with head
 1.94.4.2 16-May-2009  yamt sync with head
 1.94.4.1 04-May-2009  yamt sync with head.
 1.94.2.1 17-Jun-2008  yamt sync with head.
 1.95.10.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.99.44.1 20-Mar-2017  pgoyette Sync with HEAD
 1.99.40.1 05-Feb-2017  skrll Sync with HEAD
 1.99.22.1 03-Dec-2017  jdolecek update from HEAD
 1.101.4.1 10-Jun-2019  christos Sync with HEAD
 1.101.2.1 06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.102.14.1 21-Mar-2021  thorpej Give config_found() the same variadic arguments treatment as
config_search(). This commit only adds the CFARG_EOL sentinel
to the existing config_found() calls. Conversion of config_found_sm_loc()
and config_found_ia() call sites will be in subsequent commits.
 1.103.8.1 04-Aug-2021  thorpej Adapt to CFARGS().
 1.1 20-Nov-2000  bouyer branches: 1.1.2;
file aic6360.c.orig was initially added on branch thorpej_scsipi.
 1.1.2.2 20-Nov-2000  bouyer Ops, these shouldn't be there !
 1.1.2.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.3 11-Dec-2005  christos merge ktrace-lwp.
 1.2 17-Nov-2003  wiz Various typo fixes from Jonathon Gray via jmc@openbsd.
 1.1 06-Oct-1997  christos branches: 1.1.2; 1.1.52;
From Enami Tsugutomo: Busify and split the aic6360 driver.
 1.1.52.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.1.52.2 18-Sep-2004  skrll Sync with HEAD.
 1.1.52.1 03-Aug-2004  skrll Sync with HEAD
 1.1.2.2 14-Oct-1997  thorpej Update marc-pcmcia branch from trunk.
 1.1.2.1 06-Oct-1997  thorpej file aic6360reg.h was added on branch marc-pcmcia on 1997-10-14 10:22:19 +0000
 1.17 01-Jan-2022  andvar fix typos in comments, mainly basicly -> basically.
 1.16 22-Sep-2009  tsutsui Don't declare ISA specific aic_isa_attach() in MI header, and
also make local functions in aic_isa.c static.
 1.15 22-Sep-2009  tsutsui Split device_t/softc. Tested on AHA-1520B at ISA and ISAPnP.

XXX: ISA attachment shouldn't match cards in ISAPnP mode.
 1.14 12-May-2009  cegger struct device * -> device_t, no functional changes intended.
 1.13 08-Apr-2008  cegger branches: 1.13.4; 1.13.18;
use aprint_*_dev and device_xname
 1.12 11-Dec-2005  christos branches: 1.12.70;
merge ktrace-lwp.
 1.11 07-Dec-2004  thorpej Use "struct scsipi_command" in internal command structures so that
we have enough space for 16-byte CDBs.
 1.10 24-Aug-2004  thorpej Use ANSI function decls and more use of static.
 1.9 30-Apr-2001  lukem branches: 1.9.22;
delint
 1.8 25-Apr-2001  bouyer Pull up the thorpej_scsipi branch to main branch.
This is a completely rewritten scsipi_xfer execution engine, and the
associated changes to HBA drivers. Overview of changes & features:
- All xfers are queued in the mid-layer, rather than doing so in an
ad-hoc fashion in individual adapter drivers.
- Adapter/channel resource management in the mid-layer, avoids even trying
to start running an xfer if the adapter/channel doesn't have the resources.
- Better communication between the mid-layer and the adapters.
- Asynchronous event notification mechanism from adapter to mid-layer and
peripherals.
- Better peripheral queue management: freeze/thaw, sorted requeueing during
recovery, etc.
- Clean separation of peripherals, adapters, and adapter channels (no more
scsipi_link).
- Kernel thread for each scsipi_channel makes error recovery much easier
(no more dealing with interrupt context when recovering from an error).
- Mid-layer support for tagged queueing: commands can have the tag type
set explicitly, tag IDs are allocated in the mid-layer (thus eliminating
the need to use buggy tag ID allocation schemes in many adapter drivers).
- support for QUEUE FULL and CHECK CONDITION status in mid-layer; the command
will be requeued, or a REQUEST SENSE will be sent as appropriate.

Just before the merge syssrc has been tagged with thorpej_scsipi_beforemerge
 1.7 20-Mar-2000  enami branches: 1.7.6;
- Test the generic device active flag instead of home grown one.
- Test also it in wdcintr.
 1.6 07-Jan-2000  nisimura Remove tinfo_t symbols which result in never used global common variables.
 1.5 20-Oct-1999  enami Cancel active transfers on aic/wdc detach.
Also makes LS-120 drive works for me again.
 1.4 26-Sep-1999  enami branches: 1.4.2; 1.4.4; 1.4.6;
Allow to detach aic, but turned off by default. The patchable variable
aic_dodetach controlls this.
 1.3 19-Nov-1998  thorpej Adapt to the new scsipi_adapter interface.
 1.2 16-Oct-1997  enami Remove interrupt handler cookie from aic_softc.
 1.1 06-Oct-1997  christos branches: 1.1.2;
From Enami Tsugutomo: Busify and split the aic6360 driver.
 1.1.2.2 14-Oct-1997  thorpej Update marc-pcmcia branch from trunk.
 1.1.2.1 06-Oct-1997  thorpej file aic6360var.h was added on branch marc-pcmcia on 1997-10-14 10:22:20 +0000
 1.4.6.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.4.4.1 15-Nov-1999  fvdl Sync with -current
 1.4.2.3 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.4.2.2 20-Oct-1999  thorpej Sync w/ trunk.
 1.4.2.1 19-Oct-1999  thorpej Adapt to scsipi API changes.
 1.7.6.1 21-Jun-2001  nathanw Catch up to -current.
 1.9.22.4 18-Dec-2004  skrll Sync with HEAD.
 1.9.22.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.9.22.2 18-Sep-2004  skrll Sync with HEAD.
 1.9.22.1 25-Aug-2004  skrll Sync with HEAD.
 1.12.70.1 02-Jun-2008  mjf Sync with HEAD.
 1.13.18.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.13.4.2 11-Mar-2010  yamt sync with head
 1.13.4.1 16-May-2009  yamt sync with head
 1.1 20-Nov-2000  bouyer branches: 1.1.2;
file aic6360var.h.orig was initially added on branch thorpej_scsipi.
 1.1.2.2 20-Nov-2000  bouyer Ops, these shouldn't be there !
 1.1.2.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.47 29-Jun-2024  riastradh if_stats(9): Add ifp argument to if_stat..._ref.

This will enable us to pass the ifp through to a dtrace probe inside.

No functional change intended in this change, but this is an API
change visible to modules so it shouldn't be pulled up.

PR kern/58377
 1.46 02-Feb-2024  andvar fix various typos in comments.
 1.45 25-Sep-2022  thorpej Remove unnecessary include of <sys/malloc.h>.
 1.44 15-Mar-2020  thorpej Don't bother with IFF_OACTIVE.
 1.43 12-Mar-2020  thorpej Add support for MBUFTRACE.
 1.42 07-Feb-2020  thorpej Use callout_setfunc() / callout_schedule().
 1.41 29-Jan-2020  thorpej Adopt <net/if_stats.h>.
 1.40 30-Oct-2019  msaitoh branches: 1.40.2;
if_percpuq(9) automatically increments if_ipackets, so don't add number of
RX frames from device's statistics counter to if_ipackets to avoid double
count.
 1.39 28-May-2019  msaitoh branches: 1.39.2;
Use ETHER_LOCK()/ETHER_UNLOCK() for all ethernet drivers to protect ec_multi*.
 1.38 23-May-2019  msaitoh No functional change:
- Simplify MII structure initialization and reference.
- u_int*_t -> uint*_t.
- KNF
 1.37 22-Jan-2019  msaitoh Change MII PHY read/write API from:

int (*mii_readreg_t)(device_t, int, int);
void (*mii_writereg_t)(device_t, int, int, int);
to:

int (*mii_readreg_t)(device_t, int, int, uint16_t *);
int (*mii_writereg_t)(device_t, int, int, uint16_t);

Now we can test if a read/write operation failed or not by the return value.

In 802.3 spec says that the PHY shall not respond to read/write transaction
to the unimplemented register(22.2.4.3). Detecting timeout can be used to
check whether a register is implemented or not (if the register conforms to
the spec). ukphy(4) can be used this for MII_MMDACR and MII_MMDAADR.

Note that I noticed that the following code do infinite loop in the
read/wirte function. If it accesses unimplemented PHY register, it will hang.
It should be fixed:

arm/at91/at91emac.c
arm/ep93xx/epe.c
arm/omap/omapl1x_emac.c
mips/ralink/ralink_eth.c
arch/powerpc/booke/dev/pq3etsec.c(read)
dev/cadence/if_cemac.c <- hkenken
dev/ic/lan9118.c


Tested with the following device:

axe+ukphy
axe+rgephy
axen+rgephy (tested by Andrius V)
wm+atphy
wm+ukphy
wm+igphy
wm+ihphy
wm+makphy
sk+makphy
sk+brgphy
sk+gentbi
msk+makphy
sip+icsphy
sip+ukphy
re+rgephy
bge+brgphy
bnx+brgphy
gsip+gphyter
rtk+rlphy
fxp+inphy (tested by Andrius V)
tlp+acphy
ex+exphy
epic+qsphy
vge+ciphy (tested by Andrius V)
vr+ukphy (tested by Andrius V)
vte+ukphy (tested by Andrius V)

Not tested (MAC):
arm:at91emac
arm:cemac
arm:epe
arm:geminigmac
arm:enet
arm:cpsw
arm:emac(omac)
arm:emac(sunxi)
arm:npe
evbppc:temac
macppc:bm
macppc:gm
mips:aumac
mips:ae
mips:cnmac
mips:reth
mips:sbmac
playstation2:smap
powerpc:tsec
powerpc:emac(ibm4xx)
sgimips:mec
sparc:be
sf
ne(ax88190, dl10019)
awge
ep
gem
hme
smsh
mtd
sm
age
alc
ale
bce
cas
et
jme
lii
nfe
pcn
ste
stge
tl
xi
aue
mue
smsc
udav
url

Not tested (PHY):
amhphy
bmtphy
dmphy
etphy
glxtphy
ikphy
iophy
lxtphy
nsphyter
pnaphy
rdcphy
sqphy
tlphy
tqphy
urlphy
 1.36 26-Jun-2018  msaitoh branches: 1.36.2;
Implement the BPF direction filter (BIOC[GS]DIRECTION). It provides backward
compatibility with BIOC[GS]SEESENT ioctl. The userland interface is the same
as FreeBSD.

This change also fixes a bug that the direction is misunderstand on some
environment by passing the direction to bpf_mtap*() instead of checking
m->m_pkthdr.rcvif.
 1.35 23-May-2017  ozaki-r branches: 1.35.2; 1.35.8;
Apply deferred if_start to more drivers

And annotate some XXX_start as it runs in softint to clarify that
it doesn't need deferred if_start.
 1.34 15-Dec-2016  ozaki-r Move bpf_mtap and if_ipackets++ on Rx of each driver to percpuq if_input

The benefits of the change are:
- We can reduce codes
- We can provide the same behavior between drivers
- Where/When if_ipackets is counted up
- Note that some drivers still update packet statistics in their own
way (periodical update)
- Moved bpf_mtap run in softint
- This makes it easy to MP-ify bpf

Proposed on tech-kern and tech-net
 1.33 07-Jul-2016  msaitoh branches: 1.33.2;
KNF. Remove extra spaces. No functional change.
 1.32 10-Jun-2016  ozaki-r Introduce m_set_rcvif and m_reset_rcvif

The API is used to set (or reset) a received interface of a mbuf.
They are counterpart of m_get_rcvif, which will come in another
commit, hide internal of rcvif operation, and reduce the diff of
the upcoming change.

No functional change.
 1.31 09-Feb-2016  ozaki-r Introduce softint-based if_input

This change intends to run the whole network stack in softint context
(or normal LWP), not hardware interrupt context. Note that the work is
still incomplete by this change; to that end, we also have to softint-ify
if_link_state_change (and bpf) which can still run in hardware interrupt.

This change softint-ifies at ifp->if_input that is called from
each device driver (and ieee80211_input) to ensure Layer 2 runs
in softint (e.g., ether_input and bridge_input). To this end,
we provide a framework (called percpuq) that utlizes softint(9)
and percpu ifqueues. With this patch, rxintr of most drivers just
queues received packets and schedules a softint, and the softint
dequeues packets and does rest packet processing.

To minimize changes to each driver, percpuq is allocated in struct
ifnet for now and that is initialized by default (in if_attach).
We probably have to move percpuq to softc of each driver, but it's
future work. At this point, only wm(4) has percpuq in its softc
as a reference implementation.

Additional information including performance numbers can be found
in the thread at tech-kern@ and tech-net@:
http://mail-index.netbsd.org/tech-kern/2016/01/14/msg019997.html

Acknowledgment: riastradh@ greatly helped this work.
Thank you very much!
 1.30 27-Oct-2012  chs branches: 1.30.14;
split device_t/softc for all remaining drivers.
replace "struct device *" with "device_t".
use device_xname(), device_unit(), etc.
 1.29 22-Jul-2012  matt branches: 1.29.2;
Fix mii_statchg to take a 'struct ifnet *' instead of device_t. This fixes
problem with a common MDIO bus used for multiple interfaces.
Some drivers converted to CFATTACL_DECL_NEW.
 1.28 13-Nov-2010  uebayasi branches: 1.28.8;
Don't pull in the whole uvm(9) API to access only PAGE_SIZE and
some other constants. These are provided by sys/param.h now.
 1.27 05-Apr-2010  joerg Push the bpf_ops usage back into bpf.h. Push the common ifp->if_bpf
check into the inline functions as well the fourth argument for
bpf_attach.
 1.26 19-Jan-2010  pooka branches: 1.26.2; 1.26.4;
Redefine bpf linkage through an always present op vector, i.e.
#if NBPFILTER is no longer required in the client. This change
doesn't yet add support for loading bpf as a module, since drivers
can register before bpf is attached. However, callers of bpf can
now be modularized.

Dynamically loadable bpf could probably be done fairly easily with
coordination from the stub driver and the real driver by registering
attachments in the stub before the real driver is loaded and doing
a handoff. ... and I'm not going to ponder the depths of unload
here.

Tested with i386/MONOLITHIC, modified MONOLITHIC without bpf and rump.
 1.25 27-Sep-2009  tsutsui Replace shutdownhook_establish(9) with pmf_device_register1(9).
Compile test only.
 1.24 12-May-2009  cegger struct device * -> device_t, no functional changes intended.
 1.23 28-Apr-2008  martin branches: 1.23.14;
Remove clause 3 and 4 from TNF licenses
 1.22 08-Apr-2008  cegger branches: 1.22.2; 1.22.4;
use aprint_*_dev and device_xname
 1.21 12-Mar-2008  dyoung sf_stop: clear IFF_RUNNING before disabling.
 1.20 19-Jan-2008  dyoung branches: 1.20.2; 1.20.6;
Make many ethernet drivers share the common code for MII media
handling, ether_mediastatus() and ether_mediachange(). Check for
a non-ENXIO error return from mii_mediachg(). (ENXIO indicates
that a PHY is suspended.)

This patch shrinks the source code size by 979 lines. There was
a 5100-byte savings on the NetBSD/i386 kernel configuration, ALL.

I have made a few miscellaneous changes, too:

gem(4): use LIST_EMPTY(), LIST_FOREACH().
mtd(4): handle media ioctls, for a change!
axe(4): do not track link status in sc->axe_link any longer
nfe(4), aue(4), axe(4), udav(4), url(4): do not reset all PHYs
on a change of media

Except for the change to mtd(4), no functional changes are intended.

XXX This patch affects more architectures than I can feasibly
XXX compile and run. I have compiled macppc, sparc64, i386. I
XXX have run the patches on i386 boxen with bnx(4) and sip(4).
XXX Compiling and running on evbmips (MERAKI, ADM5120) is in
XXX progress.
 1.19 19-Oct-2007  ad branches: 1.19.2; 1.19.8;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.18 26-Aug-2007  dyoung branches: 1.18.2; 1.18.6;
Constify.
 1.17 09-Jul-2007  ad branches: 1.17.2; 1.17.6;
Merge some of the less invasive changes from the vmlocking branch:

- kthread, callout, devsw API changes
- select()/poll() improvements
- miscellaneous MT safety improvements
 1.16 04-Mar-2007  christos branches: 1.16.2; 1.16.4;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.15 24-Dec-2005  perry branches: 1.15.26;
Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.14 11-Dec-2005  christos merge ktrace-lwp.
 1.13 27-Feb-2005  perry branches: 1.13.4;
nuke trailing whitespace
 1.12 30-Oct-2004  thorpej branches: 1.12.4; 1.12.6;
When adding/deleting multicast addresses, only whack the address
filter if the interface is marked RUNNING.

Fixes kern/27678.
 1.11 24-Aug-2004  thorpej Use ANSI function decls and more use of static.
 1.10 25-Oct-2003  christos branches: 1.10.4;
Fix uninitialized variable warnings
 1.9 21-Dec-2002  kristerw branches: 1.9.2;
sf_copy_small is not used anywhere. Remove.
 1.8 07-Nov-2002  thorpej Fix signed/unsigned comparison warnings.
 1.7 22-Oct-2002  fair Change the "dontcare bits" argument to ifmedia_init() to IFM_IMASK
so that it is possible select PHY instances other than the first
one (instance zero), if there is more than one PHY attached.
 1.6 03-May-2002  thorpej Bump the number of Tx DMA segments from 7 to 15 (the zero-copy socket
code sometimes sees more than 7).
 1.5 13-Nov-2001  lukem add/cleanup RCSID
 1.4 23-Jul-2001  thorpej Make sure to initialize the all Rx descriptors properly in *_init()
even if mbufs for them are already allocated.
 1.3 19-Jul-2001  thorpej Use BUS_DMA_READ and BUS_DMA_WRITE in some obvious places.
 1.2 05-Jul-2001  thorpej branches: 1.2.2;
Fix variable names in the strict-alignment case.
 1.1 18-Jun-2001  thorpej branches: 1.1.2;
Add support for the Adaptec AIC-6915 10/100 Ethernet. This is
a 64-bit PCI chip, available in 1, 2, and 4 port models.
 1.1.2.7 29-Dec-2002  thorpej Sync with HEAD.
 1.1.2.6 11-Nov-2002  nathanw Catch up to -current
 1.1.2.5 20-Jun-2002  nathanw Catch up to -current.
 1.1.2.4 14-Nov-2001  nathanw Catch up to -current.
 1.1.2.3 24-Aug-2001  nathanw Catch up with -current.
 1.1.2.2 21-Jun-2001  nathanw Catch up to -current.
 1.1.2.1 18-Jun-2001  nathanw file aic6915.c was added on branch nathanw_sa on 2001-06-21 20:02:03 +0000
 1.2.2.3 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.2.2.2 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.2.2.1 03-Aug-2001  lukem update to -current
 1.9.2.6 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.9.2.5 02-Nov-2004  skrll Sync with HEAD.
 1.9.2.4 21-Sep-2004  skrll Fix the sync with head I botched.
 1.9.2.3 18-Sep-2004  skrll Sync with HEAD.
 1.9.2.2 25-Aug-2004  skrll Sync with HEAD.
 1.9.2.1 03-Aug-2004  skrll Sync with HEAD
 1.10.4.1 24-Jan-2005  he Pull up revision 1.12 (requested by thorpej in ticket #939):
When adding or deleting multicast addresses, only change
the address filter if the interface is marked RUNNING.
Fixes PR#27678.
 1.12.6.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.12.4.1 29-Apr-2005  kent sync with -current
 1.13.4.5 17-Mar-2008  yamt sync with head.
 1.13.4.4 21-Jan-2008  yamt sync with head
 1.13.4.3 27-Oct-2007  yamt sync with head.
 1.13.4.2 03-Sep-2007  yamt sync with head.
 1.13.4.1 21-Jun-2006  yamt sync with head.
 1.15.26.1 12-Mar-2007  rmind Sync with HEAD.
 1.16.4.1 11-Jul-2007  mjf Sync with head.
 1.16.2.3 23-Oct-2007  ad Sync with head.
 1.16.2.2 09-Oct-2007  ad Sync with head.
 1.16.2.1 01-Jul-2007  ad Adapt to callout API change.
 1.17.6.2 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.17.6.1 03-Sep-2007  jmcneill Sync with HEAD.
 1.17.2.1 03-Sep-2007  skrll Sync with HEAD.
 1.18.6.1 25-Oct-2007  bouyer Sync with HEAD.
 1.18.2.2 23-Mar-2008  matt sync with HEAD
 1.18.2.1 06-Nov-2007  matt sync with HEAD
 1.19.8.1 20-Jan-2008  bouyer Sync with HEAD
 1.19.2.1 18-Feb-2008  mjf Sync with HEAD.
 1.20.6.2 02-Jun-2008  mjf Sync with HEAD.
 1.20.6.1 03-Apr-2008  mjf Sync with HEAD.
 1.20.2.1 24-Mar-2008  keiichi sync with head.
 1.22.4.4 11-Aug-2010  yamt sync with head.
 1.22.4.3 11-Mar-2010  yamt sync with head
 1.22.4.2 16-May-2009  yamt sync with head
 1.22.4.1 16-May-2008  yamt sync with head.
 1.22.2.1 18-May-2008  yamt sync with head.
 1.23.14.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.26.4.2 05-Mar-2011  rmind sync with head
 1.26.4.1 30-May-2010  rmind sync with head
 1.26.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.28.8.1 30-Oct-2012  yamt sync with head
 1.29.2.2 03-Dec-2017  jdolecek update from HEAD
 1.29.2.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.30.14.4 28-Aug-2017  skrll Sync with HEAD
 1.30.14.3 05-Feb-2017  skrll Sync with HEAD
 1.30.14.2 09-Jul-2016  skrll Sync with HEAD
 1.30.14.1 19-Mar-2016  skrll Sync with HEAD
 1.33.2.1 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.35.8.2 26-Jan-2019  pgoyette Sync with HEAD
 1.35.8.1 28-Jul-2018  pgoyette Sync with HEAD
 1.35.2.1 06-Nov-2019  martin Pull up following revision(s) (requested by msaitoh in ticket #1427):

sys/arch/arm/broadcom/bcm53xx_eth.c: revision 1.39
sys/dev/pcmcia/if_xi.c: revision 1.91
sys/dev/ic/aic6915.c: revision 1.40
sys/dev/pci/if_tl.c: revision 1.117
sys/arch/arm/gemini/gemini_gmac.c: revision 1.18
sys/dev/ic/elinkxl.c: revision 1.133
sys/dev/pci/if_ste.c: revision 1.57
sys/dev/pci/if_alc.c: revision 1.43
sys/dev/pci/if_stge.c: revision 1.72
sys/dev/pci/if_ale.c: revision 1.34
sys/dev/pci/if_age.c: revision 1.62
sys/dev/pci/if_txp.c: revision 1.60
sys/dev/ic/i82557.c: revision 1.156
sys/dev/pci/if_vte.c: revision 1.27
sys/arch/powerpc/booke/dev/pq3etsec.c: revision 1.47
sys/arch/arm/gemini/if_gpn.c: revision 1.13

if_percpuq(9) and ether_input() automatically increment if_ipackets, so don't add number of
RX frames from device's statistics counter to if_ipackets to avoid double
count.
 1.36.2.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.36.2.1 10-Jun-2019  christos Sync with HEAD
 1.39.2.1 06-Nov-2019  martin Pull up following revision(s) (requested by msaitoh in ticket #403):

sys/arch/arm/broadcom/bcm53xx_eth.c: revision 1.39
sys/dev/pcmcia/if_xi.c: revision 1.91
sys/dev/ic/aic6915.c: revision 1.40
sys/dev/pci/if_tl.c: revision 1.117
sys/arch/arm/gemini/gemini_gmac.c: revision 1.18
sys/dev/ic/elinkxl.c: revision 1.133
sys/dev/pci/if_ste.c: revision 1.57
sys/dev/pci/if_alc.c: revision 1.43
sys/dev/pci/if_stge.c: revision 1.72
sys/dev/pci/if_ale.c: revision 1.34
sys/dev/pci/if_age.c: revision 1.62
sys/dev/pci/if_txp.c: revision 1.60
sys/dev/ic/i82557.c: revision 1.156
sys/dev/pci/if_vte.c: revision 1.27
sys/arch/powerpc/booke/dev/pq3etsec.c: revision 1.47
sys/arch/arm/gemini/if_gpn.c: revision 1.13

if_percpuq(9) and ether_input() automatically increment if_ipackets, so don't add number of
RX frames from device's statistics counter to if_ipackets to avoid double
count.
 1.40.2.1 29-Feb-2020  ad Sync with head.
 1.7 04-May-2022  andvar s/entires/entries/
 1.6 01-Aug-2019  msaitoh Use unsinged when initialize the transmit completion ring to avoid undefined
behavior. Found by kUBSan.
 1.5 28-Apr-2008  martin branches: 1.5.88; 1.5.94;
Remove clause 3 and 4 from TNF licenses
 1.4 11-Dec-2005  christos branches: 1.4.70; 1.4.72; 1.4.74;
merge ktrace-lwp.
 1.3 07-Jul-2005  thorpej Remove the __packed__ attribute from these structures. Everything is
naturally aligned anyway, and __packed__ just causes the compiler to
generate slower code.
 1.2 03-May-2002  thorpej branches: 1.2.10; 1.2.26;
Bump the number of Tx DMA segments from 7 to 15 (the zero-copy socket
code sometimes sees more than 7).
 1.1 18-Jun-2001  thorpej branches: 1.1.2; 1.1.4;
Add support for the Adaptec AIC-6915 10/100 Ethernet. This is
a 64-bit PCI chip, available in 1, 2, and 4 port models.
 1.1.4.1 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.1.2.3 20-Jun-2002  nathanw Catch up to -current.
 1.1.2.2 21-Jun-2001  nathanw Catch up to -current.
 1.1.2.1 18-Jun-2001  nathanw file aic6915reg.h was added on branch nathanw_sa on 2001-06-21 20:02:04 +0000
 1.2.26.1 21-Jun-2006  yamt sync with head.
 1.2.10.1 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.4.74.1 16-May-2008  yamt sync with head.
 1.4.72.1 18-May-2008  yamt sync with head.
 1.4.70.1 02-Jun-2008  mjf Sync with HEAD.
 1.5.94.1 31-Jan-2020  martin Pull up following revision(s) (requested by msaitoh in ticket #672):

sys/dev/ic/tulip.c: revision 1.198
sys/dev/pci/if_jme.c: revision 1.45
sys/dev/pci/agp.c: revision 1.86
sys/dev/pci/if_lii.c: revision 1.27
sys/dev/acpi/thinkpad_acpi.c: revision 1.47
sys/dev/scsipi/scsipi_base.c: revision 1.183
sys/dev/ic/aic6915reg.h: revision 1.6

Fix undefined behavior in thinkpad_mask_init(). Found by kUBSan.

Use unsigned when initialize the transmit completion ring to avoid undefined
behavior. Found by kUBSan.

Avoid undefined behavior when setting multicast address. found by kUBSan.

Use unsigned to avoid undefined behavior in agpattach(). Found by kUBSan.

Avoid undefined behavior in jme_mii_write(). Found by kUBSan.

Use unsigned to avoid undefined behavior in lii_setmulti().

Use unsigned to avoid undefined behavior in scsipi_{get,put}_tag().

Found by kUBSan.
 1.5.88.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.5 04-May-2022  andvar s/entires/entries/
 1.4 27-Oct-2012  chs split device_t/softc for all remaining drivers.
replace "struct device *" with "device_t".
use device_xname(), device_unit(), etc.
 1.3 27-Sep-2009  tsutsui branches: 1.3.12; 1.3.22;
Replace shutdownhook_establish(9) with pmf_device_register1(9).
Compile test only.
 1.2 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.1 18-Jun-2001  thorpej branches: 1.1.2; 1.1.122; 1.1.124; 1.1.126;
Add support for the Adaptec AIC-6915 10/100 Ethernet. This is
a 64-bit PCI chip, available in 1, 2, and 4 port models.
 1.1.126.2 11-Mar-2010  yamt sync with head
 1.1.126.1 16-May-2008  yamt sync with head.
 1.1.124.1 18-May-2008  yamt sync with head.
 1.1.122.1 02-Jun-2008  mjf Sync with HEAD.
 1.1.2.2 21-Jun-2001  nathanw Catch up to -current.
 1.1.2.1 18-Jun-2001  nathanw file aic6915var.h was added on branch nathanw_sa on 2001-06-21 20:02:05 +0000
 1.3.22.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.3.12.1 30-Oct-2012  yamt sync with head
 1.8 14-Mar-2009  dsl Change about 4500 of the K&R function definitions to ANSI ones.
There are still about 1600 left, but they have ',' or /* ... */
in the actual variable definitions - which my awk script doesn't handle.
There are also many that need () -> (void).
(The script does handle misordered arguments.)
 1.7 19-Oct-2007  ad branches: 1.7.20; 1.7.28; 1.7.34;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.6 11-Dec-2005  christos branches: 1.6.30; 1.6.44; 1.6.46; 1.6.50;
merge ktrace-lwp.
 1.5 27-Feb-2005  perry branches: 1.5.4;
nuke trailing whitespace
 1.4 18-Oct-2003  tsutsui branches: 1.4.8; 1.4.10;
Fix some attach messages for new ahc(4).
 1.3 19-Apr-2003  fvdl branches: 1.3.2;
Newer adaptec 7xxx driver. Written by Justin Gibbs for FreeBSD. Ported to
NetBSD by Pascal Renauld at Network Storage Solutions, Inc.
Some modifications by me.
 1.2 13-Nov-2001  lukem add/cleanup RCSID
 1.1 15-Mar-2000  fvdl branches: 1.1.6; 1.1.8; 1.1.10;
Common code for EISA and VL frontends for the ahc driver, split off
by Noriyuki Soda when updating for the new ahc driver.
 1.1.10.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.1.8.1 14-Nov-2001  nathanw Catch up to -current.
 1.1.6.2 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.1.6.1 15-Mar-2000  bouyer file aic77xx.c was added on branch thorpej_scsipi on 2000-11-20 11:40:18 +0000
 1.3.2.4 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.3.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.3.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.3.2.1 03-Aug-2004  skrll Sync with HEAD
 1.4.10.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.4.8.1 29-Apr-2005  kent sync with -current
 1.5.4.1 27-Oct-2007  yamt sync with head.
 1.6.50.1 25-Oct-2007  bouyer Sync with HEAD.
 1.6.46.1 06-Nov-2007  matt sync with HEAD
 1.6.44.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.6.30.1 23-Oct-2007  ad Sync with head.
 1.7.34.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.7.28.1 28-Apr-2009  skrll Sync with HEAD.
 1.7.20.1 04-May-2009  yamt sync with head.
 1.1 15-Mar-2000  fvdl branches: 1.1.6;
Common code for EISA and VL frontends for the ahc driver, split off
by Noriyuki Soda when updating for the new ahc driver.
 1.1.6.2 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.1.6.1 15-Mar-2000  bouyer file aic77xxreg.h was added on branch thorpej_scsipi on 2000-11-20 11:40:18 +0000
 1.3 11-Dec-2005  christos merge ktrace-lwp.
 1.2 04-Feb-2005  perry de-__P
 1.1 15-Mar-2000  fvdl branches: 1.1.6; 1.1.30; 1.1.38; 1.1.40;
Common code for EISA and VL frontends for the ahc driver, split off
by Noriyuki Soda when updating for the new ahc driver.
 1.1.40.1 12-Feb-2005  yamt sync with head.
 1.1.38.1 29-Apr-2005  kent sync with -current
 1.1.30.1 04-Feb-2005  skrll Sync with HEAD.
 1.1.6.2 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.1.6.1 15-Mar-2000  bouyer file aic77xxvar.h was added on branch thorpej_scsipi on 2000-11-20 11:40:18 +0000
 1.70 02-Feb-2024  andvar fix various typos in comments.
 1.69 01-Aug-2023  andvar s/diable/disable/ in comments.
 1.68 23-May-2022  andvar s/boundries/boundaries/, s/itterate/iterate/ and few more typos.
 1.67 22-May-2022  andvar fix various small typos, mainly in comments.
 1.66 16-Apr-2022  andvar s/strickly/strictly/
 1.65 07-Apr-2022  andvar fix various typos in comments.
 1.64 08-Mar-2022  andvar fix few typos in comments.
 1.63 05-Dec-2021  msaitoh Fix typo again... s/Expilcitly/Explicitly/
 1.62 05-Dec-2021  msaitoh s/runable/runnable/
 1.61 05-Dec-2021  msaitoh s/programatic/programmatic/ in comment.
 1.60 05-Dec-2021  msaitoh s/explcit/expilcit/ in comment.
 1.59 25-Oct-2021  ryo fix "error: stack usage might be unbounded [-Werror=stack-usage=]" with COPTS=-O0
 1.58 16-Sep-2021  andvar fix typos in word "successful".
 1.57 24-Jul-2021  andvar Fix all remaining typos, mainly in comments but also in few definitions and log messages, reported by me in PR kern/54889.
Also fixed some additional typos in comments, found on review of same files or typos.
 1.56 27-Jun-2020  jdolecek branches: 1.56.6;
constify, NFCI
 1.55 27-Jun-2020  jdolecek small constify
 1.54 27-Jun-2020  jdolecek mark ahc_loadseq()/ahd_loadseq() as __noinline to avoid 'stack usage
might get unbounded' - seems the variable-length array using const variable
is misinterpreted as unbounded when inlined
 1.53 27-Dec-2019  msaitoh s/sucess/success/ in comment.
 1.52 10-Nov-2019  chs in many device attach paths, allocate memory with M_WAITOK instead of M_NOWAIT
and remove code to handle failures that can no longer happen.
 1.51 04-Feb-2019  mrg add or adjust fallthru comments.
 1.50 18-Oct-2014  snj branches: 1.50.20;
src is too big these days to tolerate superfluous apostrophes. It's
"its", people!
 1.49 17-Apr-2014  christos put back missing arg
 1.48 17-Apr-2014  christos CID/1203192, CID/1203193: Out of bounds read
 1.47 27-Mar-2014  christos branches: 1.47.2;
cleanup debugging printfs to avoid overflow
 1.46 17-Oct-2013  christos - remove unused variables
- move variables inside ifdef sections
- ifdef notdef unused code
- use __USE for debugging variables
 1.45 02-Jul-2011  mrg branches: 1.45.2; 1.45.12; 1.45.16;
avoid -Wenum-compare issue.
 1.44 03-Sep-2009  tsutsui - wrap long lines
- remove unnecessary casts against void pointers
 1.43 02-Sep-2009  tsutsui TAB vs space cleanup.
 1.42 02-Sep-2009  tsutsui Replace shutdownhook_establish(9) with pmf_device_register1(9).
Untested, but mostly copied from ahc(4).

This may fix reboot failure problem on ahd(4) after pmf(9) merge:
http://mail-index.NetBSD.org/current-users/2007/12/10/0008.html
which was also seen on old ahc(4):
http://mail-index.NetBSD.org/port-sgimips/2008/01/05/msg000003.html
 1.41 18-Mar-2009  cegger bzero -> memset
 1.40 14-Mar-2009  dsl ANSIfy another 1261 function definitions.
The only ones left in sys are beyond by sed script!
(or in sys/dist or sys/external)
Mostly they have function pointer parameters.
 1.39 14-Mar-2009  dsl Change about 4500 of the K&R function definitions to ANSI ones.
There are still about 1600 left, but they have ',' or /* ... */
in the actual variable definitions - which my awk script doesn't handle.
There are also many that need () -> (void).
(The script does handle misordered arguments.)
 1.38 21-Mar-2008  dyoung branches: 1.38.4; 1.38.10; 1.38.12; 1.38.18;
Use aprint_*_dev(), and device_xname(). Constify a bit.
 1.37 04-Mar-2007  christos branches: 1.37.16; 1.37.32; 1.37.36;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.36 16-Nov-2006  christos branches: 1.36.4;
__unused removal on arguments; approved by core.
 1.35 12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.34 08-Mar-2006  lukem branches: 1.34.10; 1.34.12;
Use the SI capitalization for "Hz", "kHz", and "MHz" in comments and strings.
Add a space between numbers and Hz unit.
 1.33 24-Dec-2005  perry branches: 1.33.4; 1.33.6; 1.33.8; 1.33.10;
Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.32 28-Nov-2005  bouyer Don't call alloc_scb() (which can call bus_dmamem_alloc/map) from
ADAPTER_REQ_RUN_XFER context (which can be interrupt context), defer this
to the ADAPTER_REQ_GROW_RESOURCES callback.
Fix a panic in uvm reported by John R. Shannon on port-xen; patch tested on
ahc by me and on ahd by John.
 1.31 30-May-2005  christos branches: 1.31.2; 1.31.8;
- add missing const
- fix variable shadowing
- remove unneeded casts
 1.30 27-Feb-2005  perry branches: 1.30.2;
nuke trailing whitespace
 1.29 21-Feb-2005  thorpej Part 1 of a cleanup pass over the SCSI subsystem. The aim is to name
everything "scsi_*", since we really are talking about the SCSI command
set, ATAPI transport not withstanding. Improve the names of many structures,
and prepend "SCSI_" onto all SCSI command opcodes. Place items described
by the SCSI Primary Commands document into scsi_spc.h.
 1.28 21-Apr-2004  itojun branches: 1.28.4; 1.28.6;
avoid unbounded sprintf(), use snprintf()
 1.27 13-Feb-2004  wiz branches: 1.27.2; 1.27.4; 1.27.6;
Uppercase CPU, plural is CPUs.
 1.26 02-Nov-2003  wiz Fix some typos. From Tom Cosgrove via jmc@openbsd.
 1.25 10-Oct-2003  fvdl Don't zap the lower 16 bits of the command/status register when clear
error bits.
 1.24 10-Oct-2003  briggs Properly clear any latched errors before re-enabling SERR/PERR for PCI-X
in ahd_reset().
 1.23 30-Sep-2003  briggs Make sure that we don't blow away the enables in ahd_reset() on PCI-X.
 1.22 02-Sep-2003  fvdl * Make the ahc and ahd probes more alike.
* Remove some redundant code.
* ahd: Don't initiate negotiation for a discovery xs when the negotiation goal
is set. Just looking at the auto_negotiate mask is enough, and it can
cause an endless loop if the request gets requeued (happens with a
of a PPR negotiation, which ends with a busfree).
 1.21 29-Aug-2003  thorpej Apply the following change from 06/28/2003 04:46:54 by gibbs to the
FreeBSD ahd driver:

Fix a race condition in the flushing of commands that
have completed across the bus but not to the host before
processing of an exception condition (busfree, bus reset,
etc.). When flushing the controller of completed commands,
we also look for packetized commands that have completed
with good status and are stored in the "good status fifo".
The hardware will post to the good status fifo even if
data for that command is still active in a FIFO. In
one particular failure case, a command outstanding on the
bus reconnected, transferred data into a FIFO, and provided
good status while the host driver was processing an expected
busfree event (PPR message negotiation). This resulted in
an entry in the good status fifo that we completed, but
since the sequencer was paused, the data in the data FIFO
for this command had never been transferred to the host.
Once the busfree processing was complete, the sequencer
was unpaused, and the data completed its transfer to the
host. In some instances, the client for the data was notified
of the completion and attempted to view the data before
it arrived. This case only occurred during FreeBSD's
multi-target probe of the SCSI bus while some devices are
negotiating to go packetized and some devices are already
running in packetized.

The fix is to run and FIFOs active with a context in the
good status fifo to completion before completing the command
to the SCSI layer. This requies duplicating the FIFO rundown
operations in the host driver that would usually be handled
by the firmware, but there is no other alternative.

Don't blindly shutdown the SCB dma engine when restarting
the sequencer. We may be killing an operation that is
not supposed to be cancelled. The cases where we need to
shutdown these dma engines are already handled elsewhere in
the driver.

Fix a few more ahd_in?() -> ahd_in?_scbram() instances.
 1.20 29-Aug-2003  thorpej Apply the following change from 06/28/2003 04:45:25 by gibbs to the
FreeBSD ahd driver:

aic79xx.h:
Add softc flag to indicate that we have seen at
least one selection since the last bus reset or
SE/LVD bus change.

aic79xx.c:
Fix a few style nits.

In ahd_update_pending_scbs(), only touch card registers
once we have found an SCB that needs to be updated.
This removes lots of clutter from PCI traces taken of
error recovery performed by the driver.

Short circuit the first selection iocell workaround handler
if we've run once since the last bus reset or iocell change.
This also removes clutter from PCI traces.

Note if completions are pending in the qoutfifo when we dump
card state.
 1.19 29-Aug-2003  thorpej Apply the following change from 06/28/2003 04:42:11 by gibbs to the
FreeBSD ahd driver:

Correct a typo in a comment.

Add a comment in ahd_clear_critical_sections() about
our need to leave ENBUSFREE set in SIMODE1 while single
stepping.

Re-arrange some delay loops so that we always perform
a read after any register write and before the delay.
This should make the delay loop more accurate.

When completing message processing for a packetized
commention, return the controller to a state where
invalid non-packetized phases will still cause protocol
violations. These are the same operations as those
performed in the clear_target_state routine in the
firmware.

Now that we have a chip with working ABORTPENDING
support (the 7901B), comment out the automatic use
of this feature until we can adequately test it.
The previous checkin updated the bug mask for the
7901B so this code was exercised.

When resetting the bus, perform an ahd_flush_device_writes()
call so that our reset assertion delay is acurately
timed from when the reset bit is written to the controller.
 1.18 29-Aug-2003  thorpej Apply the following change from 07-23-2003 22:06:34 by gibbs to the
FreeBSD ahd driver:

Add parenthesis so that we get all of the bits all
of the contents of the CCSCBCTL register into our
local varaible. The other bits are used in later tests.
This avoids a potential deadlock in ahd_run_qoutfifo()
if we happen to catch the DMA engine in just the right
state.
 1.17 29-Aug-2003  thorpej Apply the following change from 07/06/2003 23:53:39 by gibbs to the
FreeBSD ahd driver:

When single stepping, only leave ENBUSFREE enabled
if it was already enabled. We don't want to set it
when it shouldn't be set, we just don't want to
inadvertantly turn it off. This should fix a recent
report of the aic7xxx driver repeatedly complaining of
"unexpected busfree while idle" in one configuration.
 1.16 29-Aug-2003  thorpej Apply the following change made 06/06/2003 23:51:13 by gibbs to the
FreeBSD ahd driver:

Work around SCSI spec violation by the Quantum Atlas 10K.
This drive delays going async after receiving a WDTR
message. We now send an SDTR message after a WDTR even
if our goal is to go async. This should work even for
confused devices.

If we get an unexpected busfree when attempting a WDTR
or SDTR, only set the goal negotiation parameters we were
trying to negotiate to off. This means that should a WDTR
message fail, we will still try an SDTR if our goal is
non-async.

Fix a few more places where we were looking at goal.period
instead of goal.offset for determining if we should be
negotiating sync. This should not have any impact on
our behavior, but the offset is more definitive and should
be used.
 1.15 29-Aug-2003  thorpej Apply the following change from 6/6/2003 23:48:18 by gibbs to the
FreeBSD ahd driver:

aic7770.c:
aic79xx.c:
aic79xx.h:
aic79xx_pci.c:
aic7xxx.c:
aic7xxx.h:
aic7xxx_pci.c:
Switch ah?_reset() to take an additional "reinit" argument.
Use this instead of init_level to determin if the chip
should be fully reinitialized after a chip reset. This
is required so that ah?_shutdown() can reset the chip
without side-effects.
 1.14 29-Aug-2003  thorpej Update FreeBSD RCS ID for last.
 1.13 29-Aug-2003  thorpej Apply the following change from 5/30/2003 02:15:15 made by scottl to the
FreeBSD ahd driver:

aic79xx.c:
Use the special LUNLEN_SINGLE_LEVEL constant for
post Rev A4 hardware for single byte luns. Without
this change, Rev B hardware would place the single
byte of lun data in byte 0 of the lun structure when
it should be in byte 1. Since there are few if any
devices on the market that support multiple luns in
target mode, the corrupted lun field (which was only
corrupted for non-zero luns) wasn't hurting us.

Approved by: re (rwatson)
 1.12 29-Aug-2003  thorpej Apply the following change made on 5/26/2003 21:43:29 by gibbs to the
FreeBSD ahd driver:

aic79xx.c:
aic79xx_osm.h:
aic7xxx_osm.h:
Explicitly define functions that take no arguments
with "(void)"

Approved by: RE
 1.11 29-Aug-2003  thorpej Apply the following change made on 5/26/2003 21:26:51 by gibbs to the
FreeBSD ahd driver:

Correct/Simplify ignore wide residue message handling

aic79xx.c:
In ahd_handle_ign_wide_residue():
o Use SCB_XFERLEN_ODD SCB field to determine transfer
"oddness" rather than the DATA_COUNT_ODD logic.
SCB_XFERLEN_ODD is toggled on every ignore wide
residue message so that multiple ignore wide residue
messages for the same transaction are properly supported.
o If the sg list has been exausted, the sequencer
doesn't bother to update the residual data count
since it is known to be zero. Perform the zeroing
manually before calculating the remaining data count.
o Use multibyte in/out macros instead of shifting/masking
by hand.

aic79xx_inline.h:
In ahd_setup_scb_common(), setup the SCB_XFERLEN_ODD field.

aic79xx.reg:
Use the SCB_TASK_ATTRIBUTE field as a bit field in the
non-packetized case. We currently only define one bit,
SCB_XFERLEN_ODD.

Remove the ODD_SEG bit field that was used to carry the odd
transfer length information through the SG cache. This
is obviated by SCB_XFERLEN_ODD field.

Remove the DATA_COUNT_ODD scratch ram byte that was used
dynamicaly compute data transfer oddness. This is obviated
by SCB_XFERLEN_ODD field.

aic79xx.seq:
Remove all updates to the DATA_COUNT_ODD scratch ram field.
Remove all uses of ODD_SEG. These two save quite a few
sequencer instructions.

Use SCB_XFERLEN_ODD to validate the end of transfer
ignore wide residue message case.
 1.10 29-Aug-2003  thorpej Apply the following change made 5/26/2003 21:18:48 by gibbs to the
FreeBSD ahd driver:

Change hadling of the Rev. A packetized lun output bug
to be more efficient by having the sequencer copy the
single byte of valid lun data into the long lun field.

aic79xx.c:
Memset our hardware SCB to 0 so that untouched
fields don't confuse diagnostic output. With the
old method for handling the Rev A bug, if the long
lun field was not 0, this could result in bogus
lun information being sent to drives.

Use the same SCB transfer size for all chip types
now that the long lun is not DMA'ed to the chip.

aic79xx.seq:
Add code to copy lun information for Rev.A hardware.

aic79xx_inline.h:
Remove host update of the long_lun field on every
packetized command.
 1.9 29-Aug-2003  thorpej Apply the following change checked in 2003/05/04 00:20:07 by gibbs
to the FreeBSD ahd driver:

Correct spelling errors.

Switch to handling bad SCSI status as a sequencer interrupt
instead of having the kernel proccess these failures via
the completion queue. This is done because:

o The old scheme required us to pause the sequencer and clear
critical sections for each SCB. It seems that these pause
actions, if coincident with a sequencer FIFO interrupt, would
result in a FIFO interrupt getting lost or directing to the
wrong FIFO. This caused hangs when the driver was stressed
under high "queue full" loads.
o The completion code assumed that it was always called with
the sequencer running. This may not be the case in timeout
processing where completions occur manually via
ahd_pause_and_flushwork().
o With this scheme, the extra expense of clearing critical
sections is avoided since the sequencer will only self pause
once all pending selections have cleared and it is not in
a critical section.

aic79xx.c
Add code to handle the new BAD_SCB_STATUS sequencer
interrupt code. This just redirects the SCB through
the already existing ahd_complete_scb() code path.
Remove code in ahd_handle_scsi_status() that paused
the sequencer, made sure that no selections where
pending, and cleared critical sections. Bad
status SCBs are now only processed when all of these
conditions are true.

aic79xx.reg:
Add the BAD_SCB_STATUS sequencer interrupt code.

aic79xx.seq:
When completing an SCB upload to the host, if
we are doing this because the SCB contains non-zero
SCSI status, defer completing the SCB until there
are no pending selection events. When completing
these SCBs, use the new BAD_SCB_STATUS sequencer
interrupt. For all other uploaded SCBs (currently
only for underruns), the SCB is completed via the
normal done queue. Additionally, keep the SCB that
is currently being uploaded on the COMPLETE_DMA_SCB
list until the dma is completed, not just until the
DMA is started. This ensures that the DMA is restarted
properly should the host disable the DMA transfer for
some reason.

In our RevA workaround for Maxtor drives, guard against
the host pausing us while trying to pause I/O until the
first data-valid REQ by clearing the current snapshot
so that we can tell if the transfer has completed prior
to us noticing the REQINIT status.

In cfg4data_intr, shave off an instruction before getting
the data path running by adding an entrypoint to the
overrun handler to also increment the FIFO use count.

In the overrun handler, be sure to clear our LONGJMP
address in both exit paths.

Perform a few sequencer optimizations.

aic79xx.c:
Print the full path from the SCB when a packetized
status overrun occurs.

Remove references to LONGJMP_SCB which is being
removed from firmware usage.

Print the new SCB_FIFO_USE_COUNT field in the
per-SCB section of ahd_dump_card_state(). The
SCB_TAG field is now re-used by the sequencer,
so it no longer makes sense to reference this
field in the kernel driver.

aic79xx.h:
Re-arrange fields in the hardware SCB from largest
size type to smallest. This makes it easier to
move fields without changing field alignment.

The hardware scb tag field is now down near the
"spare" portion of the SCB to facilitate reuse
by the sequencer.

aic79xx.reg:
Remove LONGJMP_ADDR.

Rearrange SCB fields to match aic79xx.h.
Add SCB_FIFO_USE_COUNT as the first byte
of the SCB_TAG field.

aic79xx.seq:
Add a per-SCB "Fifos in use count" field and use
it to determine when it is safe (all data posted)
to deliver status back to the host. The old method
involved polling one or both FIFOs to verify that
the current task did not have pending data. This
makes running down the GSFIFO very cheap, so we
will empty the GSFIFO in one idle loop pass in
all cases.

Use this simplification of the completion process
to prune down the data FIFO teardown sequencer for
packetized transfers. Much more code is now shared
between the data residual and transfer complete cases.

Correct some issues in the packetized status handler.
It used to be possible to CLRCHN our FIFO before status
had fully transferred to the host. We also failed to
handle NONPACKREQ phases that could occur should a CRC
error occur during transmission of the status data packet.

Correct a few big endian issues:

aic79xx.c:
aic79xx_inline.h:
aic79xx_pci.c:
aic79xx_osm.c:
o Always get the SCB's tag via the SCB_GET_TAG acccessor
o Add missing use of byte swapping macros when touching
hscb fields.
o Don't double swap SEEPROM data when it is printed.
Correct a big-endian bug. We cannot assign a
o When assigning a 32bit LE variable to a 64bit LE
variable, we must be explict about how the words
of the 64bit LE variable are initialized. Cast to
(uint32_t*) to do this.

aic79xx.c:
In ahd_clear_critical_section(), hit CRLSCSIINT
after restoring the interrupt masks to avoid what
appears to be a glitch on SCSIINT. Any real SCSIINT
status will be persistent and will immidiately
reset SCSIINT. This clear should only get rid of
spurious SCSIINTs.

This glitch was the cause of the "Unexpected PKT busfree"
status that occurred under high queue full loads

Call ahd_fini_scbdata() after shutdown so that
any ahd_chip_init() routine that might access
SCB data will not access free'd memory.

Reset the bus on an IOERR since the chip doesn't
seem to reset to the new voltage level without
this.
Change offset calculation for scatter gather maps
so that the calculation is correct if an integral
multiple of sg lists does not fit in the allocation
size.

Adjust bus dma tag for data buffers based on 39BIT
addressing flag in our softc.

Use the QFREEZE count to simplify ahd_pause_and_flushworkd().
We can thus rely on the sequencer eventually clearing ENSELO.

In ahd_abort_scbs(), fix a bug that could potentially
corrupt sequencer state. The saved SCB was being
restored in the SCSI mode instead of the saved mode.
It turns out that the SCB did not need to be saved at all
as the scbptr is already restored by all subroutines
called during this function that modify that register.

aic79xx.c:
aic79xx.h:
aic79xx_pci.c:
Add support for parsing the seeprom vital product
data. The VPD data are currently unused.

aic79xx.h:
aic79xx.seq:
aic79xx_pci.c:
Add a firmware workaround to make the LED blink
brighter during packetized operations on the H2A.

aic79xx_inline.h:
The host does not use timer interrupts, so don't
gate our decision on whether or not to unpause
the sequencer on whether or not a timer interrupt
is pending.
 1.8 28-Aug-2003  thorpej Make sure we consistently report DT when sending an xfer mode async event.
 1.7 26-Jul-2003  thorpej Make this work on systems where bus_dmamap_sync() is not a noop.
In particular, when doing the "swap hscbs" trick, the scb must
reference the correct hscb_map when it gets a new hscb, otherwise
when you go to sync an hscb later, you could end up using the wrong
dmamap.

In order to make this work, we have to convert the shared_data stuff
to use a map_node, because of the "sentinel" trick played with the
initial "next_hscb".

This driver now works on XScale-based platforms.
 1.6 14-Jul-2003  lukem add missing __KERNEL_RCSID()
 1.5 14-May-2003  wiz branches: 1.5.2;
Correct spelling of coalesce. (Will forward to Justin Gibbs.)
 1.4 03-May-2003  wiz DMA, not dma nor Dma.
 1.3 21-Apr-2003  fvdl Remove unused variable.
 1.2 21-Apr-2003  fvdl Remove trigraph.
 1.1 21-Apr-2003  fvdl ahd, driver for Adaptec 790x U320 controllers. Originally by Justin Gibbs
for FreeBSD, ported to NetBSD by Pascal Renauld, Network Storage Solutions,
Inc, plus a bunch of changes by me.

This driver is as yet untested in this final form, it will be added
to config files when it has been tested.
 1.5.2.6 11-Dec-2005  christos Sync with head.
 1.5.2.5 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.5.2.4 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.5.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.5.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.5.2.1 03-Aug-2004  skrll Sync with HEAD
 1.27.6.1 16-Dec-2005  jmc Pullup rev 1.32 (requested by bouyer in ticket #10177)

Don't call alloc_scb() (which can call bus_dmamem_alloc/map) from
ADAPTER_REQ_RUN_XFER context (which can be interrupt context), defer this
to the ADAPTER_REQ_GROW_RESOURCES callback. Fixes a panic in uvm.
 1.27.4.1 16-Dec-2005  jmc Pullup rev 1.32 (requested by bouyer in ticket #10177)

Don't call alloc_scb() (which can call bus_dmamem_alloc/map) from
ADAPTER_REQ_RUN_XFER context (which can be interrupt context), defer this
to the ADAPTER_REQ_GROW_RESOURCES callback. Fixes a panic in uvm.
 1.27.2.1 16-Dec-2005  jmc Pullup rev 1.32 (requested by bouyer in ticket #10177)

Don't call alloc_scb() (which can call bus_dmamem_alloc/map) from
ADAPTER_REQ_RUN_XFER context (which can be interrupt context), defer this
to the ADAPTER_REQ_GROW_RESOURCES callback. Fixes a panic in uvm.
 1.28.6.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.28.4.1 29-Apr-2005  kent sync with -current
 1.30.2.1 29-Nov-2005  tron Pull up following revision(s) (requested by bouyer in ticket #1014):
sys/dev/ic/aic7xxx.c: revision 1.117
sys/dev/ic/aic79xxvar.h: revision 1.20
sys/dev/ic/aic79xx_osm.c: revision 1.13
sys/dev/ic/aic7xxx_inline.h: revision 1.7
sys/dev/ic/aic79xx.c: revision 1.32
sys/dev/ic/aic7xxx_osm.c: revision 1.19
sys/dev/ic/aic7xxxvar.h: revision 1.50
Don't call alloc_scb() (which can call bus_dmamem_alloc/map) from
ADAPTER_REQ_RUN_XFER context (which can be interrupt context), defer this
to the ADAPTER_REQ_GROW_RESOURCES callback.
Fix a panic in uvm reported by John R. Shannon on port-xen; patch tested on
ahc by me and on ahd by John.
 1.31.8.1 29-Nov-2005  yamt sync with head.
 1.31.2.4 24-Mar-2008  yamt sync with head.
 1.31.2.3 03-Sep-2007  yamt sync with head.
 1.31.2.2 30-Dec-2006  yamt sync with head.
 1.31.2.1 21-Jun-2006  yamt sync with head.
 1.33.10.1 19-Apr-2006  elad sync with head.
 1.33.8.1 13-Mar-2006  yamt sync with head.
 1.33.6.1 22-Apr-2006  simonb Sync with head.
 1.33.4.1 09-Sep-2006  rpaulo sync with head
 1.34.12.2 10-Dec-2006  yamt sync with head.
 1.34.12.1 22-Oct-2006  yamt sync with head
 1.34.10.1 18-Nov-2006  ad Sync with head.
 1.36.4.1 12-Mar-2007  rmind Sync with HEAD.
 1.37.36.1 03-Apr-2008  mjf Sync with HEAD.
 1.37.32.1 24-Mar-2008  keiichi sync with head.
 1.37.16.1 23-Mar-2008  matt sync with HEAD
 1.38.18.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.38.12.1 28-Apr-2009  skrll Sync with HEAD.
 1.38.10.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.38.4.2 16-Sep-2009  yamt sync with head
 1.38.4.1 04-May-2009  yamt sync with head.
 1.45.16.1 18-May-2014  rmind sync with head
 1.45.12.2 03-Dec-2017  jdolecek update from HEAD
 1.45.12.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.45.2.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.47.2.1 10-Aug-2014  tls Rebase.
 1.50.20.3 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.50.20.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.50.20.1 10-Jun-2019  christos Sync with HEAD
 1.56.6.1 01-Aug-2021  thorpej Sync with HEAD.
 1.24 13-Aug-2021  andvar fix typos in words "pointer" and s/fram /frame/
 1.23 08-Feb-2020  msaitoh Apply FreeBSD r357300:

> aic7xxx(4): Fix unintended sign extension in ahd_inq()
>
> ahd_inb() returns type uint8_t. The shift left by untyped 24 implicitly
> promotes the result to type (signed) int. Then the binary OR with uint64_t
> values sign-extends the integer. If bit 31 of the read value happened to be
> set, the 64-bit result would have all upper 32 bits set to 1 due to OR.
> This is clearly not intended.
>
> Reported by: Coverity
> CID: 980473 (old one!)
 1.22 27-Apr-2013  kardel branches: 1.22.36; 1.22.44;
fix panic due to physaddr instead of offset being passed to ahd_dmamap_sync
 1.21 03-Apr-2013  christos undo previous commit of unrelated debugging.
 1.20 03-Apr-2013  christos instead of ifnet use ethercom.
 1.19 05-Sep-2009  tsutsui branches: 1.19.12; 1.19.22;
Remove unnecessary casts against void pointers.
 1.18 02-Sep-2009  tsutsui TAB vs space cleanup.
 1.17 15-Mar-2009  cegger ansify function definitions
 1.16 21-Mar-2008  dyoung branches: 1.16.4; 1.16.12; 1.16.18;
Use aprint_*_dev(), and device_xname(). Constify a bit.
 1.15 16-Nov-2006  christos branches: 1.15.24; 1.15.44; 1.15.48;
__unused removal on arguments; approved by core.
 1.14 12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.13 16-Feb-2006  perry branches: 1.13.14; 1.13.16;
Change "inline" back to "__inline" in .h files -- C99 is still too
new, and some apps compile things in C89 mode. C89 keywords stay.

As per core@.
 1.12 24-Dec-2005  perry branches: 1.12.2; 1.12.4; 1.12.6;
Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.11 11-Dec-2005  christos merge ktrace-lwp.
 1.10 27-Feb-2005  perry branches: 1.10.4;
nuke trailing whitespace
 1.9 02-Nov-2003  wiz branches: 1.9.8; 1.9.10;
Fix some typos. From Tom Cosgrove via jmc@openbsd.
 1.8 29-Aug-2003  thorpej Apply the following change from 06/28/2003 04:43:19 by gibbs to the
FreeBSD ahd driver:

Implement ahd_inq_scbram() and change the implemention
of ahd_inl_scbram to use ahd_inw_scbram instead of
ahd_inb_scbram().
 1.7 29-Aug-2003  thorpej Apply the following change made on 5/26/2003 21:26:51 by gibbs to the
FreeBSD ahd driver:

Correct/Simplify ignore wide residue message handling

aic79xx.c:
In ahd_handle_ign_wide_residue():
o Use SCB_XFERLEN_ODD SCB field to determine transfer
"oddness" rather than the DATA_COUNT_ODD logic.
SCB_XFERLEN_ODD is toggled on every ignore wide
residue message so that multiple ignore wide residue
messages for the same transaction are properly supported.
o If the sg list has been exausted, the sequencer
doesn't bother to update the residual data count
since it is known to be zero. Perform the zeroing
manually before calculating the remaining data count.
o Use multibyte in/out macros instead of shifting/masking
by hand.

aic79xx_inline.h:
In ahd_setup_scb_common(), setup the SCB_XFERLEN_ODD field.

aic79xx.reg:
Use the SCB_TASK_ATTRIBUTE field as a bit field in the
non-packetized case. We currently only define one bit,
SCB_XFERLEN_ODD.

Remove the ODD_SEG bit field that was used to carry the odd
transfer length information through the SG cache. This
is obviated by SCB_XFERLEN_ODD field.

Remove the DATA_COUNT_ODD scratch ram byte that was used
dynamicaly compute data transfer oddness. This is obviated
by SCB_XFERLEN_ODD field.

aic79xx.seq:
Remove all updates to the DATA_COUNT_ODD scratch ram field.
Remove all uses of ODD_SEG. These two save quite a few
sequencer instructions.

Use SCB_XFERLEN_ODD to validate the end of transfer
ignore wide residue message case.
 1.6 29-Aug-2003  thorpej Apply the following change made 5/26/2003 21:18:48 by gibbs to the
FreeBSD ahd driver:

Change hadling of the Rev. A packetized lun output bug
to be more efficient by having the sequencer copy the
single byte of valid lun data into the long lun field.

aic79xx.c:
Memset our hardware SCB to 0 so that untouched
fields don't confuse diagnostic output. With the
old method for handling the Rev A bug, if the long
lun field was not 0, this could result in bogus
lun information being sent to drives.

Use the same SCB transfer size for all chip types
now that the long lun is not DMA'ed to the chip.

aic79xx.seq:
Add code to copy lun information for Rev.A hardware.

aic79xx_inline.h:
Remove host update of the long_lun field on every
packetized command.
 1.5 29-Aug-2003  thorpej Apply the following change checked in 2003/05/04 00:20:07 by gibbs
to the FreeBSD ahd driver:

Correct spelling errors.

Switch to handling bad SCSI status as a sequencer interrupt
instead of having the kernel proccess these failures via
the completion queue. This is done because:

o The old scheme required us to pause the sequencer and clear
critical sections for each SCB. It seems that these pause
actions, if coincident with a sequencer FIFO interrupt, would
result in a FIFO interrupt getting lost or directing to the
wrong FIFO. This caused hangs when the driver was stressed
under high "queue full" loads.
o The completion code assumed that it was always called with
the sequencer running. This may not be the case in timeout
processing where completions occur manually via
ahd_pause_and_flushwork().
o With this scheme, the extra expense of clearing critical
sections is avoided since the sequencer will only self pause
once all pending selections have cleared and it is not in
a critical section.

aic79xx.c
Add code to handle the new BAD_SCB_STATUS sequencer
interrupt code. This just redirects the SCB through
the already existing ahd_complete_scb() code path.
Remove code in ahd_handle_scsi_status() that paused
the sequencer, made sure that no selections where
pending, and cleared critical sections. Bad
status SCBs are now only processed when all of these
conditions are true.

aic79xx.reg:
Add the BAD_SCB_STATUS sequencer interrupt code.

aic79xx.seq:
When completing an SCB upload to the host, if
we are doing this because the SCB contains non-zero
SCSI status, defer completing the SCB until there
are no pending selection events. When completing
these SCBs, use the new BAD_SCB_STATUS sequencer
interrupt. For all other uploaded SCBs (currently
only for underruns), the SCB is completed via the
normal done queue. Additionally, keep the SCB that
is currently being uploaded on the COMPLETE_DMA_SCB
list until the dma is completed, not just until the
DMA is started. This ensures that the DMA is restarted
properly should the host disable the DMA transfer for
some reason.

In our RevA workaround for Maxtor drives, guard against
the host pausing us while trying to pause I/O until the
first data-valid REQ by clearing the current snapshot
so that we can tell if the transfer has completed prior
to us noticing the REQINIT status.

In cfg4data_intr, shave off an instruction before getting
the data path running by adding an entrypoint to the
overrun handler to also increment the FIFO use count.

In the overrun handler, be sure to clear our LONGJMP
address in both exit paths.

Perform a few sequencer optimizations.

aic79xx.c:
Print the full path from the SCB when a packetized
status overrun occurs.

Remove references to LONGJMP_SCB which is being
removed from firmware usage.

Print the new SCB_FIFO_USE_COUNT field in the
per-SCB section of ahd_dump_card_state(). The
SCB_TAG field is now re-used by the sequencer,
so it no longer makes sense to reference this
field in the kernel driver.

aic79xx.h:
Re-arrange fields in the hardware SCB from largest
size type to smallest. This makes it easier to
move fields without changing field alignment.

The hardware scb tag field is now down near the
"spare" portion of the SCB to facilitate reuse
by the sequencer.

aic79xx.reg:
Remove LONGJMP_ADDR.

Rearrange SCB fields to match aic79xx.h.
Add SCB_FIFO_USE_COUNT as the first byte
of the SCB_TAG field.

aic79xx.seq:
Add a per-SCB "Fifos in use count" field and use
it to determine when it is safe (all data posted)
to deliver status back to the host. The old method
involved polling one or both FIFOs to verify that
the current task did not have pending data. This
makes running down the GSFIFO very cheap, so we
will empty the GSFIFO in one idle loop pass in
all cases.

Use this simplification of the completion process
to prune down the data FIFO teardown sequencer for
packetized transfers. Much more code is now shared
between the data residual and transfer complete cases.

Correct some issues in the packetized status handler.
It used to be possible to CLRCHN our FIFO before status
had fully transferred to the host. We also failed to
handle NONPACKREQ phases that could occur should a CRC
error occur during transmission of the status data packet.

Correct a few big endian issues:

aic79xx.c:
aic79xx_inline.h:
aic79xx_pci.c:
aic79xx_osm.c:
o Always get the SCB's tag via the SCB_GET_TAG acccessor
o Add missing use of byte swapping macros when touching
hscb fields.
o Don't double swap SEEPROM data when it is printed.
Correct a big-endian bug. We cannot assign a
o When assigning a 32bit LE variable to a 64bit LE
variable, we must be explict about how the words
of the 64bit LE variable are initialized. Cast to
(uint32_t*) to do this.

aic79xx.c:
In ahd_clear_critical_section(), hit CRLSCSIINT
after restoring the interrupt masks to avoid what
appears to be a glitch on SCSIINT. Any real SCSIINT
status will be persistent and will immidiately
reset SCSIINT. This clear should only get rid of
spurious SCSIINTs.

This glitch was the cause of the "Unexpected PKT busfree"
status that occurred under high queue full loads

Call ahd_fini_scbdata() after shutdown so that
any ahd_chip_init() routine that might access
SCB data will not access free'd memory.

Reset the bus on an IOERR since the chip doesn't
seem to reset to the new voltage level without
this.
Change offset calculation for scatter gather maps
so that the calculation is correct if an integral
multiple of sg lists does not fit in the allocation
size.

Adjust bus dma tag for data buffers based on 39BIT
addressing flag in our softc.

Use the QFREEZE count to simplify ahd_pause_and_flushworkd().
We can thus rely on the sequencer eventually clearing ENSELO.

In ahd_abort_scbs(), fix a bug that could potentially
corrupt sequencer state. The saved SCB was being
restored in the SCSI mode instead of the saved mode.
It turns out that the SCB did not need to be saved at all
as the scbptr is already restored by all subroutines
called during this function that modify that register.

aic79xx.c:
aic79xx.h:
aic79xx_pci.c:
Add support for parsing the seeprom vital product
data. The VPD data are currently unused.

aic79xx.h:
aic79xx.seq:
aic79xx_pci.c:
Add a firmware workaround to make the LED blink
brighter during packetized operations on the H2A.

aic79xx_inline.h:
The host does not use timer interrupts, so don't
gate our decision on whether or not to unpause
the sequencer on whether or not a timer interrupt
is pending.
 1.4 26-Jul-2003  thorpej Make this work on systems where bus_dmamap_sync() is not a noop.
In particular, when doing the "swap hscbs" trick, the scb must
reference the correct hscb_map when it gets a new hscb, otherwise
when you go to sync an hscb later, you could end up using the wrong
dmamap.

In order to make this work, we have to convert the shared_data stuff
to use a map_node, because of the "sentinel" trick played with the
initial "next_hscb".

This driver now works on XScale-based platforms.
 1.3 08-Jul-2003  itojun function prototype must not have variable name
 1.2 03-May-2003  wiz branches: 1.2.2;
DMA, not dma nor Dma.
 1.1 21-Apr-2003  fvdl Add file that I missed when adding the ahd driver.
 1.2.2.4 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.2.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.2.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.2.2.1 03-Aug-2004  skrll Sync with HEAD
 1.9.10.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.9.8.1 29-Apr-2005  kent sync with -current
 1.10.4.2 24-Mar-2008  yamt sync with head.
 1.10.4.1 30-Dec-2006  yamt sync with head.
 1.12.6.1 22-Apr-2006  simonb Sync with head.
 1.12.4.1 09-Sep-2006  rpaulo sync with head
 1.12.2.1 18-Feb-2006  yamt sync with head.
 1.13.16.2 10-Dec-2006  yamt sync with head.
 1.13.16.1 22-Oct-2006  yamt sync with head
 1.13.14.1 18-Nov-2006  ad Sync with head.
 1.15.48.1 03-Apr-2008  mjf Sync with HEAD.
 1.15.44.1 24-Mar-2008  keiichi sync with head.
 1.15.24.1 23-Mar-2008  matt sync with HEAD
 1.16.18.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.16.12.1 28-Apr-2009  skrll Sync with HEAD.
 1.16.4.2 16-Sep-2009  yamt sync with head
 1.16.4.1 04-May-2009  yamt sync with head.
 1.19.22.1 23-Jun-2013  tls resync from head
 1.19.12.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.22.44.1 29-Feb-2020  ad Sync with head.
 1.22.36.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.36 07-Aug-2021  thorpej Merge thorpej-cfargs2.
 1.35 24-Apr-2021  thorpej branches: 1.35.8;
Merge thorpej-cfargs branch:

Simplify and make extensible the config_search() / config_found() /
config_attach() interfaces: rather than having different variants for
which arguments you want pass along, just have a single call that
takes a variadic list of tag-value arguments.

Adjust all call sites:
- Simplify wherever possible; don't pass along arguments that aren't
actually needed.
- Don't be explicit about what interface attribute is attaching if
the device only has one. (More simplification.)
- Add a config_probe() function to be used in indirect configuiration
situations, making is visibly easier to see when indirect config is
in play, and allowing for future change in semantics. (As of now,
this is just a wrapper around config_match(), but that is an
implementation detail.)

Remove unnecessary or redundant interface attributes where they're not
needed.

There are currently 5 "cfargs" defined:
- CFARG_SUBMATCH (submatch function for direct config)
- CFARG_SEARCH (search function for indirect config)
- CFARG_IATTR (interface attribte)
- CFARG_LOCATORS (locators array)
- CFARG_DEVHANDLE (devhandle_t - wraps OFW, ACPI, etc. handles)

...and a sentinel value CFARG_EOL.

Add some extra sanity checking to ensure that interface attributes
aren't ambiguous.

Use CFARG_DEVHANDLE in MI FDT, OFW, and ACPI code, and macppc and shark
ports to associate those device handles with device_t instance. This
will trickle trough to more places over time (need back-end for pre-OFW
Sun OBP; any others?).
 1.34 10-Nov-2019  chs branches: 1.34.10;
in many device attach paths, allocate memory with M_WAITOK instead of M_NOWAIT
and remove code to handle failures that can no longer happen.
 1.33 14-Jul-2016  msaitoh branches: 1.33.18;
- Use aprint*() instead of printf() in xxx_attach().
- Add missing aprint_naive("\n");
- KNF
 1.32 17-Oct-2013  christos branches: 1.32.6;
- remove unused variables
- move variables inside ifdef sections
- ifdef notdef unused code
- use __USE for debugging variables
 1.31 24-Feb-2010  dyoung branches: 1.31.10; 1.31.20; 1.31.24;
A pointer typedef entails trading too much flexibility to declare const
and non-const types, and the kernel uses both const and non-const
PMF qualifiers and device suspensors, so change the pmf_qual_t and
device_suspensor_t typedefs from "pointers to const" to non-pointer,
non-const types.
 1.30 08-Jan-2010  dyoung branches: 1.30.2;
Expand PMF_FN_* macros.
 1.29 26-Sep-2009  tsutsui Split device_t/softc. Tested on aic7901A.
 1.28 05-Sep-2009  tsutsui Make ahd_detach() take struct ahd_softc * rather than device_t
as well as ahd_attach(). (currently no backend calls it though)
 1.27 05-Sep-2009  tsutsui Use device_private() to get softc.
 1.26 05-Sep-2009  tsutsui - use local ahd_name() to print device name
- pass proper device_t types to config(9) functions
 1.25 05-Sep-2009  tsutsui Remove unnecessary casts against void pointers.
 1.24 02-Sep-2009  tsutsui Fix harmless pasto. (ahc -> ahd)
 1.23 02-Sep-2009  tsutsui TAB vs space cleanup.
 1.22 02-Sep-2009  tsutsui Replace shutdownhook_establish(9) with pmf_device_register1(9).
Untested, but mostly copied from ahc(4).

This may fix reboot failure problem on ahd(4) after pmf(9) merge:
http://mail-index.NetBSD.org/current-users/2007/12/10/0008.html
which was also seen on old ahc(4):
http://mail-index.NetBSD.org/port-sgimips/2008/01/05/msg000003.html
 1.21 12-May-2009  cegger struct device * -> device_t, no functional changes intended.
 1.20 24-Jun-2008  gmcgarry branches: 1.20.10;
Fix prototype of ahd_send_async(). Pull in dev/ic/aic7xxx_cam.h to get ac_code.
 1.19 08-Apr-2008  cegger branches: 1.19.4; 1.19.6; 1.19.8;
use aprint_*_dev and device_xname
 1.18 04-Mar-2007  christos branches: 1.18.36;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.17 16-Nov-2006  christos branches: 1.17.4;
__unused removal on arguments; approved by core.
 1.16 12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.15 10-Apr-2006  bouyer branches: 1.15.8; 1.15.10;
Don't use ppr_options uninitialized. Coverity ID 2506.
 1.14 05-Dec-2005  bouyer branches: 1.14.4; 1.14.6; 1.14.8; 1.14.10; 1.14.12;
Wrap debug printf in AHC_DEBUG. Pointed out by Izumi Tsutsui.
 1.13 28-Nov-2005  bouyer Don't call alloc_scb() (which can call bus_dmamem_alloc/map) from
ADAPTER_REQ_RUN_XFER context (which can be interrupt context), defer this
to the ADAPTER_REQ_GROW_RESOURCES callback.
Fix a panic in uvm reported by John R. Shannon on port-xen; patch tested on
ahc by me and on ahd by John.
 1.12 27-Feb-2005  perry branches: 1.12.2; 1.12.4; 1.12.10;
nuke trailing whitespace
 1.11 21-Feb-2005  thorpej Part 1 of a cleanup pass over the SCSI subsystem. The aim is to name
everything "scsi_*", since we really are talking about the SCSI command
set, ATAPI transport not withstanding. Improve the names of many structures,
and prepend "SCSI_" onto all SCSI command opcodes. Place items described
by the SCSI Primary Commands document into scsi_spc.h.
 1.10 04-Oct-2004  fvdl branches: 1.10.4; 1.10.6;
Don't use sizeof on a pointer when you mean the whole structure.
 1.9 04-Oct-2004  fvdl No need to print out sense data just because it happened to arrive in
a pkt. Wrap that in AHD_DEBUG.
 1.8 21-Apr-2004  itojun avoid unbounded sprintf(), use snprintf()
 1.7 30-Oct-2003  simonb branches: 1.7.2; 1.7.4; 1.7.6;
Remove some assigned-to but otherwise unused variables.
 1.6 02-Sep-2003  fvdl * Make the ahc and ahd probes more alike.
* Remove some redundant code.
* ahd: Don't initiate negotiation for a discovery xs when the negotiation goal
is set. Just looking at the auto_negotiate mask is enough, and it can
cause an endless loop if the request gets requeued (happens with a
of a PPR negotiation, which ends with a busfree).
 1.5 29-Aug-2003  thorpej Apply the following change checked in 2003/05/04 00:20:07 by gibbs
to the FreeBSD ahd driver:

Correct spelling errors.

Switch to handling bad SCSI status as a sequencer interrupt
instead of having the kernel proccess these failures via
the completion queue. This is done because:

o The old scheme required us to pause the sequencer and clear
critical sections for each SCB. It seems that these pause
actions, if coincident with a sequencer FIFO interrupt, would
result in a FIFO interrupt getting lost or directing to the
wrong FIFO. This caused hangs when the driver was stressed
under high "queue full" loads.
o The completion code assumed that it was always called with
the sequencer running. This may not be the case in timeout
processing where completions occur manually via
ahd_pause_and_flushwork().
o With this scheme, the extra expense of clearing critical
sections is avoided since the sequencer will only self pause
once all pending selections have cleared and it is not in
a critical section.

aic79xx.c
Add code to handle the new BAD_SCB_STATUS sequencer
interrupt code. This just redirects the SCB through
the already existing ahd_complete_scb() code path.
Remove code in ahd_handle_scsi_status() that paused
the sequencer, made sure that no selections where
pending, and cleared critical sections. Bad
status SCBs are now only processed when all of these
conditions are true.

aic79xx.reg:
Add the BAD_SCB_STATUS sequencer interrupt code.

aic79xx.seq:
When completing an SCB upload to the host, if
we are doing this because the SCB contains non-zero
SCSI status, defer completing the SCB until there
are no pending selection events. When completing
these SCBs, use the new BAD_SCB_STATUS sequencer
interrupt. For all other uploaded SCBs (currently
only for underruns), the SCB is completed via the
normal done queue. Additionally, keep the SCB that
is currently being uploaded on the COMPLETE_DMA_SCB
list until the dma is completed, not just until the
DMA is started. This ensures that the DMA is restarted
properly should the host disable the DMA transfer for
some reason.

In our RevA workaround for Maxtor drives, guard against
the host pausing us while trying to pause I/O until the
first data-valid REQ by clearing the current snapshot
so that we can tell if the transfer has completed prior
to us noticing the REQINIT status.

In cfg4data_intr, shave off an instruction before getting
the data path running by adding an entrypoint to the
overrun handler to also increment the FIFO use count.

In the overrun handler, be sure to clear our LONGJMP
address in both exit paths.

Perform a few sequencer optimizations.

aic79xx.c:
Print the full path from the SCB when a packetized
status overrun occurs.

Remove references to LONGJMP_SCB which is being
removed from firmware usage.

Print the new SCB_FIFO_USE_COUNT field in the
per-SCB section of ahd_dump_card_state(). The
SCB_TAG field is now re-used by the sequencer,
so it no longer makes sense to reference this
field in the kernel driver.

aic79xx.h:
Re-arrange fields in the hardware SCB from largest
size type to smallest. This makes it easier to
move fields without changing field alignment.

The hardware scb tag field is now down near the
"spare" portion of the SCB to facilitate reuse
by the sequencer.

aic79xx.reg:
Remove LONGJMP_ADDR.

Rearrange SCB fields to match aic79xx.h.
Add SCB_FIFO_USE_COUNT as the first byte
of the SCB_TAG field.

aic79xx.seq:
Add a per-SCB "Fifos in use count" field and use
it to determine when it is safe (all data posted)
to deliver status back to the host. The old method
involved polling one or both FIFOs to verify that
the current task did not have pending data. This
makes running down the GSFIFO very cheap, so we
will empty the GSFIFO in one idle loop pass in
all cases.

Use this simplification of the completion process
to prune down the data FIFO teardown sequencer for
packetized transfers. Much more code is now shared
between the data residual and transfer complete cases.

Correct some issues in the packetized status handler.
It used to be possible to CLRCHN our FIFO before status
had fully transferred to the host. We also failed to
handle NONPACKREQ phases that could occur should a CRC
error occur during transmission of the status data packet.

Correct a few big endian issues:

aic79xx.c:
aic79xx_inline.h:
aic79xx_pci.c:
aic79xx_osm.c:
o Always get the SCB's tag via the SCB_GET_TAG acccessor
o Add missing use of byte swapping macros when touching
hscb fields.
o Don't double swap SEEPROM data when it is printed.
Correct a big-endian bug. We cannot assign a
o When assigning a 32bit LE variable to a 64bit LE
variable, we must be explict about how the words
of the 64bit LE variable are initialized. Cast to
(uint32_t*) to do this.

aic79xx.c:
In ahd_clear_critical_section(), hit CRLSCSIINT
after restoring the interrupt masks to avoid what
appears to be a glitch on SCSIINT. Any real SCSIINT
status will be persistent and will immidiately
reset SCSIINT. This clear should only get rid of
spurious SCSIINTs.

This glitch was the cause of the "Unexpected PKT busfree"
status that occurred under high queue full loads

Call ahd_fini_scbdata() after shutdown so that
any ahd_chip_init() routine that might access
SCB data will not access free'd memory.

Reset the bus on an IOERR since the chip doesn't
seem to reset to the new voltage level without
this.
Change offset calculation for scatter gather maps
so that the calculation is correct if an integral
multiple of sg lists does not fit in the allocation
size.

Adjust bus dma tag for data buffers based on 39BIT
addressing flag in our softc.

Use the QFREEZE count to simplify ahd_pause_and_flushworkd().
We can thus rely on the sequencer eventually clearing ENSELO.

In ahd_abort_scbs(), fix a bug that could potentially
corrupt sequencer state. The saved SCB was being
restored in the SCSI mode instead of the saved mode.
It turns out that the SCB did not need to be saved at all
as the scbptr is already restored by all subroutines
called during this function that modify that register.

aic79xx.c:
aic79xx.h:
aic79xx_pci.c:
Add support for parsing the seeprom vital product
data. The VPD data are currently unused.

aic79xx.h:
aic79xx.seq:
aic79xx_pci.c:
Add a firmware workaround to make the LED blink
brighter during packetized operations on the H2A.

aic79xx_inline.h:
The host does not use timer interrupts, so don't
gate our decision on whether or not to unpause
the sequencer on whether or not a timer interrupt
is pending.
 1.4 14-Jul-2003  lukem add missing __KERNEL_RCSID()
 1.3 21-Apr-2003  fvdl branches: 1.3.2;
Reset bus in attach, not at first access.
 1.2 21-Apr-2003  fvdl Set/report DT a bit more correctly.
 1.1 21-Apr-2003  fvdl ahd, driver for Adaptec 790x U320 controllers. Originally by Justin Gibbs
for FreeBSD, ported to NetBSD by Pascal Renauld, Network Storage Solutions,
Inc, plus a bunch of changes by me.

This driver is as yet untested in this final form, it will be added
to config files when it has been tested.
 1.3.2.6 11-Dec-2005  christos Sync with head.
 1.3.2.5 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.3.2.4 19-Oct-2004  skrll Sync with HEAD
 1.3.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.3.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.3.2.1 03-Aug-2004  skrll Sync with HEAD
 1.7.6.1 16-Dec-2005  jmc Pullup rev 1.13-1.14 (requested by bouyer in ticket #10177)

Don't call alloc_scb() (which can call bus_dmamem_alloc/map) from
ADAPTER_REQ_RUN_XFER context (which can be interrupt context), defer this
to the ADAPTER_REQ_GROW_RESOURCES callback. Fixes a panic in uvm.
 1.7.4.1 16-Dec-2005  jmc Pullup rev 1.13-1.14 (requested by bouyer in ticket #10177)

Don't call alloc_scb() (which can call bus_dmamem_alloc/map) from
ADAPTER_REQ_RUN_XFER context (which can be interrupt context), defer this
to the ADAPTER_REQ_GROW_RESOURCES callback. Fixes a panic in uvm.
 1.7.2.1 16-Dec-2005  jmc Pullup rev 1.13-1.14 (requested by bouyer in ticket #10177)

Don't call alloc_scb() (which can call bus_dmamem_alloc/map) from
ADAPTER_REQ_RUN_XFER context (which can be interrupt context), defer this
to the ADAPTER_REQ_GROW_RESOURCES callback. Fixes a panic in uvm.
 1.10.6.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.10.4.1 29-Apr-2005  kent sync with -current
 1.12.10.1 29-Nov-2005  yamt sync with head.
 1.12.4.2 03-Sep-2007  yamt sync with head.
 1.12.4.1 21-Jun-2006  yamt sync with head.
 1.12.2.2 07-Dec-2005  tron Pull up following revision(s) (requested by bouyer in ticket #1033):
sys/dev/ic/aic7xxx_osm.c: revision 1.20
sys/dev/ic/aic79xx_osm.c: revision 1.14
Wrap debug printf in AHC_DEBUG. Pointed out by Izumi Tsutsui.
 1.12.2.1 29-Nov-2005  tron Pull up following revision(s) (requested by bouyer in ticket #1014):
sys/dev/ic/aic7xxx.c: revision 1.117
sys/dev/ic/aic79xxvar.h: revision 1.20
sys/dev/ic/aic79xx_osm.c: revision 1.13
sys/dev/ic/aic7xxx_inline.h: revision 1.7
sys/dev/ic/aic79xx.c: revision 1.32
sys/dev/ic/aic7xxx_osm.c: revision 1.19
sys/dev/ic/aic7xxxvar.h: revision 1.50
Don't call alloc_scb() (which can call bus_dmamem_alloc/map) from
ADAPTER_REQ_RUN_XFER context (which can be interrupt context), defer this
to the ADAPTER_REQ_GROW_RESOURCES callback.
Fix a panic in uvm reported by John R. Shannon on port-xen; patch tested on
ahc by me and on ahd by John.
 1.14.12.1 24-May-2006  tron Merge 2006-05-24 NetBSD-current into the "peter-altq" branch.
 1.14.10.1 19-Apr-2006  elad sync with head.
 1.14.8.1 11-Apr-2006  yamt sync with head
 1.14.6.1 22-Apr-2006  simonb Sync with head.
 1.14.4.1 09-Sep-2006  rpaulo sync with head
 1.15.10.2 10-Dec-2006  yamt sync with head.
 1.15.10.1 22-Oct-2006  yamt sync with head
 1.15.8.1 18-Nov-2006  ad Sync with head.
 1.17.4.1 12-Mar-2007  rmind Sync with HEAD.
 1.18.36.2 29-Jun-2008  mjf Sync with HEAD.
 1.18.36.1 02-Jun-2008  mjf Sync with HEAD.
 1.19.8.1 27-Jun-2008  simonb Sync with head.
 1.19.6.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.19.4.4 11-Mar-2010  yamt sync with head
 1.19.4.3 16-Sep-2009  yamt sync with head
 1.19.4.2 16-May-2009  yamt sync with head
 1.19.4.1 04-May-2009  yamt sync with head.
 1.20.10.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.30.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.31.24.1 18-May-2014  rmind sync with head
 1.31.20.2 03-Dec-2017  jdolecek update from HEAD
 1.31.20.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.31.10.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.32.6.1 05-Oct-2016  skrll Sync with HEAD
 1.33.18.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.34.10.1 21-Mar-2021  thorpej Give config_found() the same variadic arguments treatment as
config_search(). This commit only adds the CFARG_EOL sentinel
to the existing config_found() calls. Conversion of config_found_sm_loc()
and config_found_ia() call sites will be in subsequent commits.
 1.35.8.1 04-Aug-2021  thorpej Adapt to CFARGS().
 1.24 28-Feb-2025  andvar Fix various typos in comments.
 1.23 03-Apr-2013  christos branches: 1.23.74;
undo previous commit of unrelated debugging.
 1.22 03-Apr-2013  christos instead of ifnet use ethercom.
 1.21 13-Nov-2010  uebayasi Don't pull in the whole uvm(9) API to access only PAGE_SIZE and
some other constants. These are provided by sys/param.h now.
 1.20 26-Sep-2009  tsutsui branches: 1.20.4;
Split device_t/softc. Tested on aic7901A.
 1.19 05-Sep-2009  tsutsui Make ahd_detach() take struct ahd_softc * rather than device_t
as well as ahd_attach(). (currently no backend calls it though)
 1.18 02-Sep-2009  tsutsui TAB vs space cleanup.
 1.17 12-May-2009  cegger struct device * -> device_t, no functional changes intended.
 1.16 24-Jun-2008  gmcgarry branches: 1.16.10;
Fix prototype of ahd_send_async(). Pull in dev/ic/aic7xxx_cam.h to get ac_code.
 1.15 08-Apr-2008  cegger branches: 1.15.4; 1.15.6; 1.15.8;
use aprint_*_dev and device_xname
 1.14 19-Oct-2007  ad branches: 1.14.16;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.13 09-Jul-2007  ad branches: 1.13.6; 1.13.8; 1.13.12;
Merge some of the less invasive changes from the vmlocking branch:

- kthread, callout, devsw API changes
- select()/poll() improvements
- miscellaneous MT safety improvements
 1.12 16-Nov-2006  christos branches: 1.12.8; 1.12.10;
__unused removal on arguments; approved by core.
 1.11 12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.10 16-Feb-2006  perry branches: 1.10.14; 1.10.16;
Change "inline" back to "__inline" in .h files -- C99 is still too
new, and some apps compile things in C89 mode. C89 keywords stay.

As per core@.
 1.9 24-Dec-2005  perry branches: 1.9.2; 1.9.4; 1.9.6;
Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.8 11-Dec-2005  christos merge ktrace-lwp.
 1.7 27-Feb-2005  perry branches: 1.7.4;
nuke trailing whitespace
 1.6 21-Feb-2005  thorpej Part 1 of a cleanup pass over the SCSI subsystem. The aim is to name
everything "scsi_*", since we really are talking about the SCSI command
set, ATAPI transport not withstanding. Improve the names of many structures,
and prepend "SCSI_" onto all SCSI command opcodes. Place items described
by the SCSI Primary Commands document into scsi_spc.h.
 1.5 02-Nov-2003  wiz branches: 1.5.8; 1.5.10;
Fix some typos. From Tom Cosgrove via jmc@openbsd.
 1.4 29-Aug-2003  thorpej Apply the following change made on 5/26/2003 21:43:29 by gibbs to the
FreeBSD ahd driver:

aic79xx.c:
aic79xx_osm.h:
aic7xxx_osm.h:
Explicitly define functions that take no arguments
with "(void)"

Approved by: RE
 1.3 08-Jul-2003  itojun function prototype must not have variable name
 1.2 03-May-2003  wiz branches: 1.2.2;
DMA, not dma nor Dma.
 1.1 21-Apr-2003  fvdl ahd, driver for Adaptec 790x U320 controllers. Originally by Justin Gibbs
for FreeBSD, ported to NetBSD by Pascal Renauld, Network Storage Solutions,
Inc, plus a bunch of changes by me.

This driver is as yet untested in this final form, it will be added
to config files when it has been tested.
 1.2.2.4 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.2.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.2.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.2.2.1 03-Aug-2004  skrll Sync with HEAD
 1.5.10.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.5.8.1 29-Apr-2005  kent sync with -current
 1.7.4.3 27-Oct-2007  yamt sync with head.
 1.7.4.2 03-Sep-2007  yamt sync with head.
 1.7.4.1 30-Dec-2006  yamt sync with head.
 1.9.6.1 22-Apr-2006  simonb Sync with head.
 1.9.4.1 09-Sep-2006  rpaulo sync with head
 1.9.2.1 18-Feb-2006  yamt sync with head.
 1.10.16.2 10-Dec-2006  yamt sync with head.
 1.10.16.1 22-Oct-2006  yamt sync with head
 1.10.14.1 18-Nov-2006  ad Sync with head.
 1.12.10.1 11-Jul-2007  mjf Sync with head.
 1.12.8.2 23-Oct-2007  ad Sync with head.
 1.12.8.1 01-Jul-2007  ad Adapt to callout API change.
 1.13.12.1 25-Oct-2007  bouyer Sync with HEAD.
 1.13.8.1 06-Nov-2007  matt sync with HEAD
 1.13.6.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.14.16.2 29-Jun-2008  mjf Sync with HEAD.
 1.14.16.1 02-Jun-2008  mjf Sync with HEAD.
 1.15.8.1 27-Jun-2008  simonb Sync with head.
 1.15.6.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.15.4.4 11-Mar-2010  yamt sync with head
 1.15.4.3 16-Sep-2009  yamt sync with head
 1.15.4.2 16-May-2009  yamt sync with head
 1.15.4.1 04-May-2009  yamt sync with head.
 1.16.10.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.20.4.1 05-Mar-2011  rmind sync with head
 1.23.74.1 02-Aug-2025  perseant Sync with HEAD
 1.30 08-Feb-2024  andvar s/sharable/shareable in comments and documentation.
 1.29 15-Oct-2021  andvar fix typos in comments.
 1.28 22-Aug-2021  andvar fix typos in comments, add missing RCSID.
 1.27 26-Sep-2009  tsutsui Split device_t/softc. Tested on aic7901A.
 1.26 03-Sep-2009  tsutsui Remove now unused *shutdown_hook from softc.
 1.25 02-Sep-2009  tsutsui TAB vs space cleanup.
 1.24 12-May-2009  cegger struct device * -> device_t, no functional changes intended.
 1.23 21-Mar-2008  dyoung branches: 1.23.4; 1.23.18;
Use aprint_*_dev(), and device_xname(). Constify a bit.
 1.22 16-Feb-2006  perry branches: 1.22.40; 1.22.60; 1.22.64;
Change "inline" back to "__inline" in .h files -- C99 is still too
new, and some apps compile things in C89 mode. C89 keywords stay.

As per core@.
 1.21 24-Dec-2005  perry branches: 1.21.2; 1.21.4; 1.21.6;
Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.20 28-Nov-2005  bouyer Don't call alloc_scb() (which can call bus_dmamem_alloc/map) from
ADAPTER_REQ_RUN_XFER context (which can be interrupt context), defer this
to the ADAPTER_REQ_GROW_RESOURCES callback.
Fix a panic in uvm reported by John R. Shannon on port-xen; patch tested on
ahc by me and on ahd by John.
 1.19 28-Jun-2005  thorpej branches: 1.19.2; 1.19.8;
Remove some extern decls for PCI-specific stuff that are private to
the PCI front-end.
 1.18 30-May-2005  christos - add missing const
- fix variable shadowing
- remove unneeded casts
 1.17 27-Feb-2005  perry branches: 1.17.2;
nuke trailing whitespace
 1.16 21-Apr-2004  itojun branches: 1.16.4; 1.16.6;
avoid unbounded sprintf(), use snprintf()
 1.15 19-Apr-2004  wiz Spell removable with only two es. Inspired by jmc@openbsd.
 1.14 02-Nov-2003  wiz branches: 1.14.2; 1.14.4; 1.14.6;
Fix some typos. From Tom Cosgrove via jmc@openbsd.
 1.13 08-Oct-2003  fvdl Cap the transfer size at MAXPHYS, the driver won't get bigger requests
than that. Allocating 16M per SCB is silly (as pointed out by
Frederick Bruckman).
 1.12 02-Sep-2003  fvdl * Make the ahc and ahd probes more alike.
* Remove some redundant code.
* ahd: Don't initiate negotiation for a discovery xs when the negotiation goal
is set. Just looking at the auto_negotiate mask is enough, and it can
cause an endless loop if the request gets requeued (happens with a
of a PPR negotiation, which ends with a busfree).
 1.11 29-Aug-2003  thorpej Apply the following change from 06/28/2003 04:45:25 by gibbs to the
FreeBSD ahd driver:

aic79xx.h:
Add softc flag to indicate that we have seen at
least one selection since the last bus reset or
SE/LVD bus change.

aic79xx.c:
Fix a few style nits.

In ahd_update_pending_scbs(), only touch card registers
once we have found an SCB that needs to be updated.
This removes lots of clutter from PCI traces taken of
error recovery performed by the driver.

Short circuit the first selection iocell workaround handler
if we've run once since the last bus reset or iocell change.
This also removes clutter from PCI traces.

Note if completions are pending in the qoutfifo when we dump
card state.
 1.10 29-Aug-2003  thorpej Apply the following change from 06/28/2003 04:39:49 by gibbs to the
FreeBSD ahd driver:

aic79xx.h:
Add a 7901A specific feature definition.

aic79xx_pci.c:
Split out the general aic790X setup into it's own
setup handler that works on single and dual controllers.
Adjust all other PCI setup handlers to initialize the
chips basic features and type before calling the generic
handler.

Turn off a few Rev B workarounds that are not required
on the 7901B.
 1.9 29-Aug-2003  thorpej Apply the following change from 05/30/2003 02:14:22 made by scottl to the
FreeBSD ahd driver:

Fix a reported case of severe data corruption:

aic79xx.h:
aic79xx.reg:
Return the SCB_TAG field to 16byte alignment.
It seems that on some PCI systems, SCBs are not
transferred correctly to the controller with
the previous placement of the SCB_TAG field.

Approved by: re (rwatson)
 1.8 29-Aug-2003  thorpej Apply the following change from 6/6/2003 23:48:18 by gibbs to the
FreeBSD ahd driver:

aic7770.c:
aic79xx.c:
aic79xx.h:
aic79xx_pci.c:
aic7xxx.c:
aic7xxx.h:
aic7xxx_pci.c:
Switch ah?_reset() to take an additional "reinit" argument.
Use this instead of init_level to determin if the chip
should be fully reinitialized after a chip reset. This
is required so that ah?_shutdown() can reset the chip
without side-effects.
 1.7 29-Aug-2003  thorpej Apply the following change checked in 2003/05/04 00:20:07 by gibbs
to the FreeBSD ahd driver:

Correct spelling errors.

Switch to handling bad SCSI status as a sequencer interrupt
instead of having the kernel proccess these failures via
the completion queue. This is done because:

o The old scheme required us to pause the sequencer and clear
critical sections for each SCB. It seems that these pause
actions, if coincident with a sequencer FIFO interrupt, would
result in a FIFO interrupt getting lost or directing to the
wrong FIFO. This caused hangs when the driver was stressed
under high "queue full" loads.
o The completion code assumed that it was always called with
the sequencer running. This may not be the case in timeout
processing where completions occur manually via
ahd_pause_and_flushwork().
o With this scheme, the extra expense of clearing critical
sections is avoided since the sequencer will only self pause
once all pending selections have cleared and it is not in
a critical section.

aic79xx.c
Add code to handle the new BAD_SCB_STATUS sequencer
interrupt code. This just redirects the SCB through
the already existing ahd_complete_scb() code path.
Remove code in ahd_handle_scsi_status() that paused
the sequencer, made sure that no selections where
pending, and cleared critical sections. Bad
status SCBs are now only processed when all of these
conditions are true.

aic79xx.reg:
Add the BAD_SCB_STATUS sequencer interrupt code.

aic79xx.seq:
When completing an SCB upload to the host, if
we are doing this because the SCB contains non-zero
SCSI status, defer completing the SCB until there
are no pending selection events. When completing
these SCBs, use the new BAD_SCB_STATUS sequencer
interrupt. For all other uploaded SCBs (currently
only for underruns), the SCB is completed via the
normal done queue. Additionally, keep the SCB that
is currently being uploaded on the COMPLETE_DMA_SCB
list until the dma is completed, not just until the
DMA is started. This ensures that the DMA is restarted
properly should the host disable the DMA transfer for
some reason.

In our RevA workaround for Maxtor drives, guard against
the host pausing us while trying to pause I/O until the
first data-valid REQ by clearing the current snapshot
so that we can tell if the transfer has completed prior
to us noticing the REQINIT status.

In cfg4data_intr, shave off an instruction before getting
the data path running by adding an entrypoint to the
overrun handler to also increment the FIFO use count.

In the overrun handler, be sure to clear our LONGJMP
address in both exit paths.

Perform a few sequencer optimizations.

aic79xx.c:
Print the full path from the SCB when a packetized
status overrun occurs.

Remove references to LONGJMP_SCB which is being
removed from firmware usage.

Print the new SCB_FIFO_USE_COUNT field in the
per-SCB section of ahd_dump_card_state(). The
SCB_TAG field is now re-used by the sequencer,
so it no longer makes sense to reference this
field in the kernel driver.

aic79xx.h:
Re-arrange fields in the hardware SCB from largest
size type to smallest. This makes it easier to
move fields without changing field alignment.

The hardware scb tag field is now down near the
"spare" portion of the SCB to facilitate reuse
by the sequencer.

aic79xx.reg:
Remove LONGJMP_ADDR.

Rearrange SCB fields to match aic79xx.h.
Add SCB_FIFO_USE_COUNT as the first byte
of the SCB_TAG field.

aic79xx.seq:
Add a per-SCB "Fifos in use count" field and use
it to determine when it is safe (all data posted)
to deliver status back to the host. The old method
involved polling one or both FIFOs to verify that
the current task did not have pending data. This
makes running down the GSFIFO very cheap, so we
will empty the GSFIFO in one idle loop pass in
all cases.

Use this simplification of the completion process
to prune down the data FIFO teardown sequencer for
packetized transfers. Much more code is now shared
between the data residual and transfer complete cases.

Correct some issues in the packetized status handler.
It used to be possible to CLRCHN our FIFO before status
had fully transferred to the host. We also failed to
handle NONPACKREQ phases that could occur should a CRC
error occur during transmission of the status data packet.

Correct a few big endian issues:

aic79xx.c:
aic79xx_inline.h:
aic79xx_pci.c:
aic79xx_osm.c:
o Always get the SCB's tag via the SCB_GET_TAG acccessor
o Add missing use of byte swapping macros when touching
hscb fields.
o Don't double swap SEEPROM data when it is printed.
Correct a big-endian bug. We cannot assign a
o When assigning a 32bit LE variable to a 64bit LE
variable, we must be explict about how the words
of the 64bit LE variable are initialized. Cast to
(uint32_t*) to do this.

aic79xx.c:
In ahd_clear_critical_section(), hit CRLSCSIINT
after restoring the interrupt masks to avoid what
appears to be a glitch on SCSIINT. Any real SCSIINT
status will be persistent and will immidiately
reset SCSIINT. This clear should only get rid of
spurious SCSIINTs.

This glitch was the cause of the "Unexpected PKT busfree"
status that occurred under high queue full loads

Call ahd_fini_scbdata() after shutdown so that
any ahd_chip_init() routine that might access
SCB data will not access free'd memory.

Reset the bus on an IOERR since the chip doesn't
seem to reset to the new voltage level without
this.
Change offset calculation for scatter gather maps
so that the calculation is correct if an integral
multiple of sg lists does not fit in the allocation
size.

Adjust bus dma tag for data buffers based on 39BIT
addressing flag in our softc.

Use the QFREEZE count to simplify ahd_pause_and_flushworkd().
We can thus rely on the sequencer eventually clearing ENSELO.

In ahd_abort_scbs(), fix a bug that could potentially
corrupt sequencer state. The saved SCB was being
restored in the SCSI mode instead of the saved mode.
It turns out that the SCB did not need to be saved at all
as the scbptr is already restored by all subroutines
called during this function that modify that register.

aic79xx.c:
aic79xx.h:
aic79xx_pci.c:
Add support for parsing the seeprom vital product
data. The VPD data are currently unused.

aic79xx.h:
aic79xx.seq:
aic79xx_pci.c:
Add a firmware workaround to make the LED blink
brighter during packetized operations on the H2A.

aic79xx_inline.h:
The host does not use timer interrupts, so don't
gate our decision on whether or not to unpause
the sequencer on whether or not a timer interrupt
is pending.
 1.6 26-Jul-2003  thorpej Make this work on systems where bus_dmamap_sync() is not a noop.
In particular, when doing the "swap hscbs" trick, the scb must
reference the correct hscb_map when it gets a new hscb, otherwise
when you go to sync an hscb later, you could end up using the wrong
dmamap.

In order to make this work, we have to convert the shared_data stuff
to use a map_node, because of the "sentinel" trick played with the
initial "next_hscb".

This driver now works on XScale-based platforms.
 1.5 08-Jul-2003  itojun function prototype must not have variable name
 1.4 14-May-2003  wiz branches: 1.4.2;
Correct spelling of coalesce. (Will forward to Justin Gibbs.)
 1.3 03-May-2003  wiz DMA, not dma nor Dma.
 1.2 21-Apr-2003  fvdl Reset bus in attach, not at first access.
 1.1 21-Apr-2003  fvdl ahd, driver for Adaptec 790x U320 controllers. Originally by Justin Gibbs
for FreeBSD, ported to NetBSD by Pascal Renauld, Network Storage Solutions,
Inc, plus a bunch of changes by me.

This driver is as yet untested in this final form, it will be added
to config files when it has been tested.
 1.4.2.4 11-Dec-2005  christos Sync with head.
 1.4.2.3 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.4.2.2 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.4.2.1 03-Aug-2004  skrll Sync with HEAD
 1.14.6.1 16-Dec-2005  jmc Pullup rev 1.20 (requested by bouyer in ticket #10177)

Don't call alloc_scb() (which can call bus_dmamem_alloc/map) from
ADAPTER_REQ_RUN_XFER context (which can be interrupt context), defer this
to the ADAPTER_REQ_GROW_RESOURCES callback. Fixes a panic in uvm.
 1.14.4.1 16-Dec-2005  jmc Pullup rev 1.20 (requested by bouyer in ticket #10177)

Don't call alloc_scb() (which can call bus_dmamem_alloc/map) from
ADAPTER_REQ_RUN_XFER context (which can be interrupt context), defer this
to the ADAPTER_REQ_GROW_RESOURCES callback. Fixes a panic in uvm.
 1.14.2.1 16-Dec-2005  jmc Pullup rev 1.20 (requested by bouyer in ticket #10177)

Don't call alloc_scb() (which can call bus_dmamem_alloc/map) from
ADAPTER_REQ_RUN_XFER context (which can be interrupt context), defer this
to the ADAPTER_REQ_GROW_RESOURCES callback. Fixes a panic in uvm.
 1.16.6.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.16.4.1 29-Apr-2005  kent sync with -current
 1.17.2.1 29-Nov-2005  tron Pull up following revision(s) (requested by bouyer in ticket #1014):
sys/dev/ic/aic7xxx.c: revision 1.117
sys/dev/ic/aic79xxvar.h: revision 1.20
sys/dev/ic/aic79xx_osm.c: revision 1.13
sys/dev/ic/aic7xxx_inline.h: revision 1.7
sys/dev/ic/aic79xx.c: revision 1.32
sys/dev/ic/aic7xxx_osm.c: revision 1.19
sys/dev/ic/aic7xxxvar.h: revision 1.50
Don't call alloc_scb() (which can call bus_dmamem_alloc/map) from
ADAPTER_REQ_RUN_XFER context (which can be interrupt context), defer this
to the ADAPTER_REQ_GROW_RESOURCES callback.
Fix a panic in uvm reported by John R. Shannon on port-xen; patch tested on
ahc by me and on ahd by John.
 1.19.8.1 29-Nov-2005  yamt sync with head.
 1.19.2.2 24-Mar-2008  yamt sync with head.
 1.19.2.1 21-Jun-2006  yamt sync with head.
 1.21.6.1 22-Apr-2006  simonb Sync with head.
 1.21.4.1 09-Sep-2006  rpaulo sync with head
 1.21.2.1 18-Feb-2006  yamt sync with head.
 1.22.64.1 03-Apr-2008  mjf Sync with HEAD.
 1.22.60.1 24-Mar-2008  keiichi sync with head.
 1.22.40.1 23-Mar-2008  matt sync with HEAD
 1.23.18.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.23.4.3 11-Mar-2010  yamt sync with head
 1.23.4.2 16-Sep-2009  yamt sync with head
 1.23.4.1 16-May-2009  yamt sync with head
 1.148 02-Feb-2024  andvar fix various typos in comments.
 1.147 27-Jun-2022  andvar fix various typos in comments.
 1.146 23-May-2022  andvar s/boundries/boundaries/, s/itterate/iterate/ and few more typos.
 1.145 25-Oct-2021  ryo fix "error: stack usage might be unbounded [-Werror=stack-usage=]" with COPTS=-O0
 1.144 16-Sep-2021  andvar fix typos in word "successful".
 1.143 24-Jul-2021  andvar Fix all remaining typos, mainly in comments but also in few definitions and log messages, reported by me in PR kern/54889.
Also fixed some additional typos in comments, found on review of same files or typos.
 1.142 27-Jun-2020  jdolecek branches: 1.142.6;
constify, NFCI
 1.141 27-Jun-2020  jdolecek small constify
 1.140 27-Jun-2020  jdolecek mark ahc_loadseq()/ahd_loadseq() as __noinline to avoid 'stack usage
might get unbounded' - seems the variable-length array using const variable
is misinterpreted as unbounded when inlined
 1.139 27-Dec-2019  msaitoh s/sucess/success/ in comment.
 1.138 27-Dec-2019  msaitoh s/saftey/safety/
 1.137 10-Nov-2019  chs in many device attach paths, allocate memory with M_WAITOK instead of M_NOWAIT
and remove code to handle failures that can no longer happen.
 1.136 04-Jun-2019  msaitoh Fix typo (s/recevie/receive/).
 1.135 04-Feb-2019  mrg add or adjust fallthru comments.
 1.134 02-Apr-2018  rin branches: 1.134.2;
Use ahc_freedmamem() for consistency. No functional change intended.
 1.133 02-Apr-2018  rin Initialize ahc->shared_data_size appropriately. Fix panic when detach.
 1.132 07-Feb-2015  christos branches: 1.132.16;
don't leak pdata. Reported by:
http://www.m00nbsd.net/ae123a9bae03f7dde5c6d654412daf5a.html#Report-4
 1.131 27-Mar-2014  christos branches: 1.131.4; 1.131.6;
cleanup debugging printfs to avoid overflow
 1.130 03-Sep-2009  tsutsui branches: 1.130.12; 1.130.22; 1.130.26;
Remove whitespaces between tabs.
 1.129 03-Sep-2009  tsutsui Misc cosmetics:
- remove c++ style comment
- wrap long lines
- remove unnecessary casts against void pointers
 1.128 14-Mar-2009  dsl ANSIfy another 1261 function definitions.
The only ones left in sys are beyond by sed script!
(or in sys/dist or sys/external)
Mostly they have function pointer parameters.
 1.127 14-Mar-2009  dsl Change about 4500 of the K&R function definitions to ANSI ones.
There are still about 1600 left, but they have ',' or /* ... */
in the actual variable definitions - which my awk script doesn't handle.
There are also many that need () -> (void).
(The script does handle misordered arguments.)
 1.126 11-Feb-2008  dyoung branches: 1.126.10; 1.126.16; 1.126.18; 1.126.24;
Constify ahc_set_name(), ahc_name(). Do not free(9) memory that
may not belong to us.
 1.125 28-Jan-2008  macallan get rid of the shutdown hook, add suspend and resume handlers instead
XXX: ahc_suspend panics here so suspend calls ahc_shutdown and resume does
nothing.
This fixes a hangup and subsequent panic which occured when the shutdown hooks
were called and /afterwards/ the sd suspend handler tried to flush caches
through an already shut down ahc.
 1.124 04-Mar-2007  christos branches: 1.124.16; 1.124.22;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.123 16-Nov-2006  christos branches: 1.123.4;
__unused removal on arguments; approved by core.
 1.122 12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.121 21-May-2006  christos branches: 1.121.6; 1.121.8;
void casts to functions whose return values are ignored.
 1.120 15-Apr-2006  tsutsui branches: 1.120.2;
Add AHC_USETARGETDEFAULTS to ahc_flag, which enables to
use default target (but not for host) device settings on
ahc(4) interface without its SEEPROM (mostly on-board one).

This flag could be useful if host's BIOS (firmware) initializes
ahc(4) chip with some conservative (async, no tagged queuing etc.)
target settings for minimum support to load its primary loader etc.,
and it will be enabled in each attachment according to MD device
properties(9). Currently this property is set only on sgimips for
O2 on-board aic7880 adapters.

No objection on tech-kern (and netbsd-bugs), and closes PR kern/23276.
 1.119 14-Mar-2006  tsutsui branches: 1.119.2;
TAB/space cleanup.
 1.118 25-Feb-2006  wiz branches: 1.118.2; 1.118.4;
Fix typos, reported by Alexey Dobriyan ("Gathered from Linux"),
forwarded by jmc@openbsd.
 1.117 28-Nov-2005  bouyer branches: 1.117.2; 1.117.4; 1.117.6;
Don't call alloc_scb() (which can call bus_dmamem_alloc/map) from
ADAPTER_REQ_RUN_XFER context (which can be interrupt context), defer this
to the ADAPTER_REQ_GROW_RESOURCES callback.
Fix a panic in uvm reported by John R. Shannon on port-xen; patch tested on
ahc by me and on ahd by John.
 1.116 10-Sep-2005  tsutsui branches: 1.116.6;
The length member in struct scsi_request_sense is uint8_t so
no need to swap byteorder.
Whele here, change style of some byteswap ops from
foo = bar();
foo = ahc_htole32(foo);
to
foo = ahc_htole32(bar());

XXX: I leave ahc_htole32() usage for union ins_formats for now
XXX: though it may be better to use byte-shift ops rather than byteswap.
 1.115 19-Aug-2005  bouyer We can't free struct ahc_softc on NetBSD either, because it comes from
config(9). Fix a corruption on alldevs list when an ahc device fails to
initialise.
 1.114 30-May-2005  christos branches: 1.114.2;
- add missing const
- fix variable shadowing
- remove unneeded casts
 1.113 12-May-2005  augustss Let ahc_createdmamem() return -1 on error instead of an error code, since
the users of that function test on <0 to look for an error.
Again, from a person that wishes to remain anonymous.
 1.112 27-Feb-2005  perry branches: 1.112.2;
nuke trailing whitespace
 1.111 21-Feb-2005  thorpej Part 1 of a cleanup pass over the SCSI subsystem. The aim is to name
everything "scsi_*", since we really are talking about the SCSI command
set, ATAPI transport not withstanding. Improve the names of many structures,
and prepend "SCSI_" onto all SCSI command opcodes. Place items described
by the SCSI Primary Commands document into scsi_spc.h.
 1.110 21-Apr-2004  itojun branches: 1.110.4; 1.110.6;
avoid unbounded sprintf(), use snprintf()
 1.109 13-Feb-2004  wiz branches: 1.109.2; 1.109.4;
Uppercase CPU, plural is CPUs.
 1.108 02-Nov-2003  wiz Fix some typos. From Tom Cosgrove via jmc@openbsd.
 1.107 07-Oct-2003  fvdl OR in ahc->sc_dmaflags when passed to bus_dmamap_create() in ahc_alloc_scbs(),
in order to pass _ISADMA_32BIT if needed. Should fix SCB allocation
failure for 2842 VL cards.
 1.106 14-Jul-2003  lukem add missing __KERNEL_RCSID()
 1.105 03-May-2003  wiz branches: 1.105.2;
DMA, not dma nor Dma.
 1.104 25-Apr-2003  fvdl Do the right thing in the case of an attach error. From Manuel Bouyer.
 1.103 23-Apr-2003  tls Correct use of MAXBSIZE where MAXPHYS was intended. This is a necessary
first step towards per-device MAXPHYS, and has the beneficial side effect
of allowing clustering to MAXPHYS even on systems that need to run with
a reduced MAXBSIZE to get more metadata buffers.
 1.102 21-Apr-2003  fvdl Remove unused variable.
 1.101 21-Apr-2003  fvdl Avoid trigraph in string.
 1.100 21-Apr-2003  fvdl Add NetBSD RCS Id.
 1.99 20-Apr-2003  fvdl Fix ahc_print_registers some more.
 1.98 20-Apr-2003  fvdl Fix ahc_print_register up.
 1.97 20-Apr-2003  bjh21 Use %lu format and (u_long) cast when printing size_t.
 1.96 19-Apr-2003  fvdl Newer adaptec 7xxx driver. Written by Justin Gibbs for FreeBSD. Ported to
NetBSD by Pascal Renauld at Network Storage Solutions, Inc.
Some modifications by me.
 1.95 31-Jan-2003  thorpej Use aprint_*().
 1.94 28-Jan-2003  wiz success, not sucess. Noted by mjl.
 1.93 20-Jan-2003  simonb The Double-Semi-Colon Police.
 1.92 06-Jan-2003  wiz successful with only one l.
 1.91 27-Sep-2002  provos remove trailing \n in panic(). approved perry.
 1.90 30-Aug-2002  abs Fix AHC_NO_TAGS to actually disable tagged queuing, and document.
 1.89 31-May-2002  thorpej Remove shadow decl of num_errors which exactly duplicated the file-scope
decl.
 1.88 05-Apr-2002  bouyer branches: 1.88.2; 1.88.4;
Implement mstohz() as discussed on tech-kern, and use it in SCSI drivers
to convert xs->timeout to callout() parameter.
 1.87 16-Jan-2002  ichiro some resources was released at the time of detach.
 1.86 16-Jan-2002  ichiro add detach/activate routine
 1.85 12-Jan-2002  tsutsui Call malloc(9) with M_ZERO flag instead of memset() after malloc().
 1.84 28-Nov-2001  lukem use #ifdef DDB (for consistency with the rest of the kernel)
 1.83 13-Nov-2001  lukem add/cleanup RCSID
 1.82 14-Oct-2001  chs avoid overflow in timeout calculations.
 1.81 21-Sep-2001  elric Fixed AHC_DEBUG on 64 bit arches with a bit of casting in a printf.
Added a message to help me debug a problem that I'm having. The
printf is protected by AHC_DEBUG.
 1.80 16-Sep-2001  wiz Spell 'occurred' with two 'r's.
 1.79 19-Jul-2001  thorpej branches: 1.79.2;
Use BUS_DMA_READ and BUS_DMA_WRITE in some obvious places.
 1.78 08-Jul-2001  wiz branches: 1.78.2;
Correct various misspellings of 'transfer' and inflected forms.
 1.77 07-Jul-2001  thorpej bzero -> memset
 1.76 07-Jul-2001  thorpej bcopy -> memcpy
 1.75 04-Jul-2001  wiz Fix typo in comment.
 1.74 26-Jun-2001  bouyer Make it compile with SCSIPI_DEBUG
 1.73 19-Jun-2001  wiz `accessible' only has one `a'.
 1.72 27-Apr-2001  bouyer Stopgap measure for PR kern/12762: cut the number of openings per device
to 16 or 4 (depending on capabilities of adapter), as it was before
thorpej_scsipi integration
Waiting feedback to known whenever the problem with openings set to AHC_SCB_MAX
existed before.
 1.71 26-Apr-2001  bouyer Redo xfer sync/wide/tag notification again: we need to notify upper layer
that we can do tag.
Start sync/wide nego at first command, but wait ADAPTER_REQ_SET_XFER_MODE
to notify upper level.
 1.70 25-Apr-2001  bouyer Pull up the thorpej_scsipi branch to main branch.
This is a completely rewritten scsipi_xfer execution engine, and the
associated changes to HBA drivers. Overview of changes & features:
- All xfers are queued in the mid-layer, rather than doing so in an
ad-hoc fashion in individual adapter drivers.
- Adapter/channel resource management in the mid-layer, avoids even trying
to start running an xfer if the adapter/channel doesn't have the resources.
- Better communication between the mid-layer and the adapters.
- Asynchronous event notification mechanism from adapter to mid-layer and
peripherals.
- Better peripheral queue management: freeze/thaw, sorted requeueing during
recovery, etc.
- Clean separation of peripherals, adapters, and adapter channels (no more
scsipi_link).
- Kernel thread for each scsipi_channel makes error recovery much easier
(no more dealing with interrupt context when recovering from an error).
- Mid-layer support for tagged queueing: commands can have the tag type
set explicitly, tag IDs are allocated in the mid-layer (thus eliminating
the need to use buggy tag ID allocation schemes in many adapter drivers).
- support for QUEUE FULL and CHECK CONDITION status in mid-layer; the command
will be requeued, or a REQUEST SENSE will be sent as appropriate.

Just before the merge syssrc has been tagged with thorpej_scsipi_beforemerge
 1.69 14-Apr-2001  ross Fix for kernel alignment crash reported on port-alpha. A developer went on
a happy code sweep (in the kernel!) and constified a random selection of
kernel objects. This changed the alignment of the previously-aligned-by-
accident seqprog array, and exposed a lurking bug. I can't decide if this
is good or bad.
 1.68 09-Apr-2001  fvdl Fix missing splx calls. One of them from OpenBSD.
 1.67 07-Mar-2001  thorpej Add BUS_DMA_STREAMING to data transfer maps.
 1.66 24-Feb-2001  cgd branches: 1.66.2;
C requires that labels be followed by statements.
 1.65 05-Feb-2001  chs expose the definitions of MIN() and MAX() in sys/param.h to the kernel
and use those in favor of a dozen copies scattered around the source tree.
 1.64 22-Jan-2001  jdolecek make patches[] const
 1.63 18-Jan-2001  jdolecek constify
 1.62 02-Dec-2000  fvdl Add AHC_NO_TAGS option to switch off tagged queueing. Done because
tagged queueing has a severe performance impact (60%) on write
throughput with UBC. Needs investigation.
 1.61 14-Nov-2000  thorpej NBPG -> PAGE_SIZE
 1.60 11-Aug-2000  tls Make our policy WRT tagged queueing consistent and sane: ordered tags for sync writes, simple tags for all else. Should make ahc and adv a bit more reliable (metadata writes won't get reordered incorrectly...) and isp a bit more performant (it was using ordered tags all the time).
 1.59 29-Jun-2000  pk #include "opt_ahc.h"
 1.58 28-Jun-2000  mrg remove include of <vm/vm.h>. <vm/vm.h> -> <uvm/uvm_extern.h>
 1.57 26-Jun-2000  fvdl Remove debugging code that wasn't supposed to be in the commit of version 1.55
 1.56 26-Jun-2000  mrg remove redundant vm includes.
 1.55 04-Jun-2000  fvdl branches: 1.55.2;
Fix wrong test for (software) queue blocked condition.
 1.54 29-May-2000  fvdl Obey the "Reset SCSI bus at startup" EEPROM setting.
 1.53 28-May-2000  fvdl Don't bother searching the qinfifo for SCBs to requeue in the BUSY
and QUEUE FULL cases; this is already done for all BAD_STATUS cases.

Make sure to requeue the SCB in the above cases internally in the driver,
the SCSI layer doesn't know how to deal with it properly.
 1.52 27-May-2000  fvdl When a bus is accessed for the first time, reset it. Without this,
some devices may not be found if the BIOS (which would normally
do the reset at startup) is disabled. Should really be done from the SCSI
layer.

Implement the SCBUSIORESET ioctl.
 1.51 25-May-2000  fvdl branches: 1.51.2;
Be sure to not use tagged queueing for a few commands.
 1.50 23-May-2000  soren Make AHC_DEBUG compile.
 1.49 22-May-2000  fvdl Don't try to re-enable tags once they have been disabled because of a
MSG_REJECT from the target. Obey the NOTAG quirk.
 1.48 19-May-2000  thorpej NULL != 0
 1.47 14-May-2000  dante Reflect changes in scsipi_inquiry_data structure: "flags" field is now named "flags3"
 1.46 25-Mar-2000  fvdl We can use openings = 16 here; this won't even exhaust the number of
allocated SCBs for 16 targets, and it's a noticeable difference.
 1.45 25-Mar-2000  fvdl Do simple tagged queueing, enabled by default.
 1.44 23-Mar-2000  thorpej New callout mechanism with two major improvements over the old
timeout()/untimeout() API:
- Clients supply callout handle storage, thus eliminating problems of
resource allocation.
- Insertion and removal of callouts is constant time, important as
this facility is used quite a lot in the kernel.

The old timeout()/untimeout() API has been removed from the kernel.
 1.43 16-Mar-2000  fvdl Do bus-specific interrupt handling (i.e. ahc_pci_intr) via a bus_intr
field in the softc, instead of relying on NPCI > 0. This would
prevent things from compiling if PCI buses were in the config file,
but ahc was attached only to something else than the PCI bus.
 1.42 15-Mar-2000  fvdl New ahc driver, a port of Justin Gibbs' FreeBSD driver. This adds
support for the U2W chips, and U160 controllers.
 1.41 12-Feb-2000  thorpej If we got an xfer from our backlog queue, don't allow sleeping; we're in
interrupt context.

XXX This is fixed properly in the thorpej_scsipi branch, but that won't
be ready for 1.5, I don't think.
 1.40 03-Feb-2000  thorpej In ahc_intr(), if initialization failed, don't try to service the
interrupt.
 1.39 26-Jan-2000  thorpej Back out a change I didn't intend to commit.
 1.38 26-Jan-2000  thorpej Split the code that reads the SEEPROM into its own file.
 1.37 30-Sep-1999  thorpej branches: 1.37.2;
Update for SCSPI changes.
 1.36 21-Sep-1999  danw Add a brief delay after resetting the card before checking to see if
it's done resetting. Trying to read registers off the card while it's
unresponsive can cause a machine check on some platforms/busses.
 1.35 19-Feb-1999  leo branches: 1.35.2;
This one needs <machine/bswap.h> too.
 1.34 09-Dec-1998  thorpej Update for changed scsipi_xfer struct.
 1.33 05-Dec-1998  mjacob Update HBAs to incorporate the new max_lun property.
 1.32 19-Nov-1998  thorpej Adapt to the new scsipi_adapter interface.
 1.31 10-Oct-1998  thorpej Garbage-collect the open_target_lu and close_target_lu entry points from
struct scsipi_adapter; they were not used.

Add a scsipi_ioctl entry point to struct scsipi_adapter. This will be
used to issue ioctl commands to the host adapters.

Inspired by PR #6090, from Matt Jacob.
 1.30 13-Aug-1998  eeh Merge paddr_t changes into the main branch.
 1.29 16-Apr-1998  leo branches: 1.29.2;
Do endian swaps where appropriate. This is currently dependent on 'BYTE_ORDER'
since the driver only supports little endian busses.
 1.28 16-Mar-1998  leo Use bus-dma functions.
 1.27 12-Jan-1998  thorpej Adjust for config changes.
 1.26 09-Oct-1997  jtk fix warnings when -DAHC_DEBUG
 1.25 27-Aug-1997  bouyer Merge scsipi branch in the mainline. This add support for ATAPI devices
(currently only CD-ROM drives on i386). The sys/dev/scsipi system provides 2
busses to which devices can attach (scsibus and atapibus). This needed to
change some include files and structure names in the low level scsi drivers.
 1.24 09-Jun-1997  thorpej branches: 1.24.2; 1.24.4;
It's perfectly normal for an older (e.g. pre SCSI-2) device to send
MESSAGE_REJECT in response to SDTR or WDTR. Because of this, the
printfs that indicate refusal of sync/wide negotiation are unneeded
in normal operation. In the __NetBSD__ case, disable them by default.
They, like the other extra-verbose ahc driver boot messages, may be
reenabled with "options DEBUG". The behavior in the !__NetBSD__ case
is unchanged.
 1.23 10-Apr-1997  cgd clean these up (mostly rename bus_space_{tag,handle}_t variables) so that
this code makes equal sense for memory and I/O space, prefer to map
the PCI front end via memory space (conditionalized on a patchable kernel
variable), and do a bit of other random NetBSD-specific cleanup. (These
changes were sent to Justin Gibbs on March 28.)
 1.22 13-Mar-1997  cgd fixes from Matt Jacob so that these can compile and run on the Alpha.
(aic7xxx has been tested and works on the Alpha, bha has not yet been
tested on thne Alpha.)
 1.21 09-Mar-1997  mikel fix some spelling errors noticed by Charles Kane <ckane@mipos2.intel.com>.
fix some more noticed by myself; all are in comments or strings.
 1.20 20-Feb-1997  mikel make sure max_target is initialized for both buses on multibus parts;
from Anders Hjalmarsson in PR 3103.
 1.19 10-Dec-1996  thorpej branches: 1.19.4;
Fill in sc_link.max_target
 1.18 02-Dec-1996  thorpej Implement a simple scsi xfer queue to avoid presenting a resource
shortage to the upper scsi layers, which don't (yet) deal well with
resource shortages.
 1.17 21-Oct-1996  thorpej New bus.h implementation/interface:
- No more distinction between i/o-mapped and memory-mapped
devices. It's all "bus space" now, and space tags
differentiate the space with finer grain than the
bus chipset tag.
- Add memory barrier methods.
- Implement space alloc/free methods.
- Implement region read/write methods (like memcpy to/from
bus space).
This interface provides a better abstraction for dealing with
machine-independent chipset drivers.
 1.16 13-Oct-1996  christos backout kprintf changes
 1.15 10-Oct-1996  christos - printf -> kprintf, sprintf -> ksprintf
- add an #ifdef FreeBSD for an unused variable
 1.14 08-Oct-1996  gibbs dev/microcode/aic7xxx/aic7xxx.seq,
dev/microcode/aic7xxx_seq.h,
dev/ic/aic7xxxreg.h:
Remove intrinsic knowledge about SDTR and WDTR messages and replace it
with a generic message system that allows the kernel driver to handle
SDTR, WDTR and any other type of extended message it chooses too. This
makes the sequencer code much simpler, makes extended message handling
debuggable since the bulk of the work is in the kernel driver, and saves
lots of instruction space.

Regen microcode header file.

dev/ic/aic7xxx.c, dev/ic/aic7xxxvar.h:
Add code to handle WDTR and SDTR negotiation in light of the changes in
the message interface to the sequencer. Don't reject targets that
negotiate async by sending an SDTR with a 0 offset. Use an sdtr message
with 0,0 to negotiate async when a target suggests a period that is too
long for us to handle. Some tape and cdrom drives don't like us doing
the message reject that we did in the past.

Fix a problem with handing the QUEUE FULL condition.

Fix a race condition (most likely the cause of the SCB paging problems) that
might allow the sequencer to get unpaused before the condition that caused
it to be paused (a SEQINT) was handled.

Race condition pointed out by Doug Ledford <dledford@dialnet.net> and
by "Dan Willis" <dan@plutotech.com>.

dev/pci/ahc_pci.c:
Add support for the 2940AU, an aic7860 based controller.

dev/pci/pcidevs.h, dev/pci/pcidevs_data.h:
Add product IDs for the 2940AU, aic7860 and aic7855.

Regen data file.

scsi/scsi_message.h:
Add MSG_EXT_SDTR_LEN and MSG_EXT_WDTR_LEN - the length of bytes in these
extended messages.

Thanks to Chuck Cranor <chuck@maria.wustl.edu> for testing these changes
out for me.
 1.13 28-Aug-1996  thorpej Quiet the ahc driver down a bit by only enabling some of less useful
messages #if defined(DEBUG) in the NetBSD case.
 1.12 28-Aug-1996  cgd (1) set scsi_link channel to either the appropriate channel (if a
multi-channel driver), or to SCSI_CHANNEL_ONLY_ONE if a
single-channel driver.
(2) use scsiprint() rather than a locally-defined autoconfig print
function, and kill any locally-defined print function.
 1.11 27-Aug-1996  cgd change cfprint_t type definition to take a const char *, rather than
a char *, because that's what was really intended, and because
if the print function modifies the string, various things could become
unhappy (so the string should _not_ be modified).
 1.10 10-Aug-1996  mycroft Look for the sequencer code in the right place.
 1.9 10-Jul-1996  explorer Updates to aic7xxx driver ; from pr port-i386/2600
 1.8 20-May-1996  thorpej branches: 1.8.4;
RCS Id police.
 1.7 16-May-1996  mycroft Replace STAILQ with SIMPLEQ.
 1.6 16-May-1996  mycroft New version, with changes from Justin Gibbs and Noriyuki Soda.
 1.5 29-Mar-1996  mycroft Eliminate random warnings.
 1.4 28-Mar-1996  mycroft Really implement ahcprint().
 1.3 25-Feb-1996  cgd don't need isa/isareg.h or pci/pci{reg,var}.h.
 1.2 13-Jan-1996  thorpej Add the "ahe" driver, autoconfiguration support for the aic7xxx-based
Adaptec 2[78]4x SCSI controllers, from Michael Graff <explorer@flame.org>.
Fixes PR #1594 from Noriyuki Soda <soda@sra.co.jp> in a different way.
 1.1 09-Oct-1995  mycroft Add an Adaptec 2940 driver, by John Aycock and Justin Gibbs, ported to NetBSD by Stefan
Grefen, with several bug fixes by me.
 1.8.4.3 04-Mar-1997  mycroft Fix slight biff in previous.
 1.8.4.2 04-Mar-1997  mycroft Pull up latest ahc driver. Fixes several bugs.
 1.8.4.1 18-Jul-1996  jtc Pulled up from rev 1.9, ahc fixes
 1.19.4.1 12-Mar-1997  is Merge in changes from Trunk
 1.24.4.2 14-Oct-1997  thorpej Update marc-pcmcia branch from trunk.
 1.24.4.1 27-Aug-1997  thorpej Update marc-pcmcia branch from trunk.
 1.24.2.1 01-Jul-1997  bouyer Updates for new scsipi subsystem. Actally known to work on i386 and sparc.
 1.29.2.1 30-Jul-1998  eeh Split vm_offset_t and vm_size_t into paddr_t, psize_t, vaddr_t, and vsize_t.
 1.35.2.1 21-Nov-1999  he Pull up revision 1.36 (requested by danw):
Add a brief delay after resetting the chip before checking to see
if it's done. Trying to talk to the chip while it is unresponsive
can cause a "machine check" on some platforms/busses.
 1.37.2.17 25-Apr-2001  bouyer Revert back to starting sync/wide negotiation at the first command,
instead of waiting for ADAPTER_REQ_XFER_MODE: as the BIOS may have
negotiated sync/wide, and we don't reset the channel, all async/narrow
xfers would fail until the channel is reset.
 1.37.2.16 21-Apr-2001  bouyer Sync with HEAD
 1.37.2.15 03-Apr-2001  bouyer Call ahc_update_xfer_mode() from ahc_action() when no sync/wide negotiation
is going to happen.
 1.37.2.14 02-Apr-2001  bouyer Use the tag type passed from upper level. Tag number is still handled locally
as they're allocated statically to ccbs.
Don't decide ourselve which commands shall run tagged or untagged; the
upper level does this for us.
 1.37.2.13 02-Apr-2001  bouyer Second part of port to thorpej_scsipi: use ADAPTER_REQ_SET_XFER_MODE to start
sync/wide nego and use tagged queuing; report modes to upper level via
scsipi_async_event().
 1.37.2.12 02-Apr-2001  bouyer Port to thorpej_scsipi, first pass. Doesn't handle ADAPTER_REQ_SET_XFER_MODE
and doesn't report its xfer mode yet, so tagged queuing isn't used yet.
 1.37.2.11 12-Mar-2001  bouyer Sync with HEAD.
 1.37.2.10 11-Feb-2001  bouyer Sync with HEAD.
 1.37.2.9 08-Dec-2000  bouyer Sync with HEAD.
 1.37.2.8 22-Nov-2000  bouyer Sync with HEAD.
 1.37.2.7 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.37.2.6 01-Nov-1999  thorpej Fixup the SC_DEBUG() stuff for the new world order.
 1.37.2.5 29-Oct-1999  thorpej Adapt to the tagged thorpej_scsipi tagged queueing interface.
 1.37.2.4 26-Oct-1999  thorpej Update for:

Deal a little more gracefully with the fact that xfer mode parameters
are for the I_T Nexus, and make all xfer mode updates `async events'.
 1.37.2.3 20-Oct-1999  thorpej Eliminate sleeping from adapter routines.
 1.37.2.2 19-Oct-1999  thorpej Don't sleep waiting for a CCB; if we get to the CCB allocation phase, we're
guaranteed to have one.
 1.37.2.1 19-Oct-1999  thorpej Adapt to scsipi API changes.
 1.51.2.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.55.2.3 11-Aug-2000  tls Pull up tagged queueing policy changes: now we use ordered tags for sync writes, simple tags for reads and async writes.
 1.55.2.2 30-Jun-2000  thorpej Pull up rev. 1.59:
#include "opt_ahc.h"
 1.55.2.1 27-Jun-2000  fvdl Remove debugging code that wasn't meant for prime time.
 1.66.2.14 07-Jan-2003  thorpej Sync with HEAD.
 1.66.2.13 18-Oct-2002  nathanw Catch up to -current.
 1.66.2.12 17-Sep-2002  nathanw Catch up to -current.
 1.66.2.11 20-Jun-2002  nathanw Catch up to -current.
 1.66.2.10 17-Apr-2002  nathanw Catch up to -current.
 1.66.2.9 28-Feb-2002  nathanw Catch up to -current.
 1.66.2.8 08-Jan-2002  nathanw Catch up to -current.
 1.66.2.7 14-Nov-2001  nathanw Catch up to -current.
 1.66.2.6 22-Oct-2001  nathanw Catch up to -current.
 1.66.2.5 26-Sep-2001  nathanw Catch up to -current.
Again.
 1.66.2.4 21-Sep-2001  nathanw Catch up to -current.
 1.66.2.3 24-Aug-2001  nathanw Catch up with -current.
 1.66.2.2 21-Jun-2001  nathanw Catch up to -current.
 1.66.2.1 09-Apr-2001  nathanw Catch up with -current.
 1.78.2.6 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.78.2.5 06-Sep-2002  jdolecek sync kqueue branch with HEAD
 1.78.2.4 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.78.2.3 11-Feb-2002  jdolecek Sync w/ -current.
 1.78.2.2 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.78.2.1 03-Aug-2001  lukem update to -current
 1.79.2.1 01-Oct-2001  fvdl Catch up with -current.
 1.88.4.2 26-Aug-2003  tron Pull up revision 1.103 via patch (requested by tls in ticket #1434):
Correct use of MAXBSIZE where MAXPHYS was intended. This is a necessary
first step towards per-device MAXPHYS, and has the beneficial side effect
of allowing clustering to MAXPHYS even on systems that need to run with
a reduced MAXBSIZE to get more metadata buffers.
 1.88.4.1 01-Sep-2002  lukem Pull up revision 1.90 (requested by abs in ticket #751):
Fix AHC_NO_TAGS to actually disable tagged queuing, and document.
 1.88.2.2 31-Aug-2002  gehenna catch up with -current.
 1.88.2.1 20-Jun-2002  gehenna catch up with -current.
 1.105.2.6 11-Dec-2005  christos Sync with head.
 1.105.2.5 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.105.2.4 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.105.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.105.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.105.2.1 03-Aug-2004  skrll Sync with HEAD
 1.109.4.2 16-Dec-2005  jmc Pullup rev 1.117 (requested by bouyer in ticket #10177)

Don't call alloc_scb() (which can call bus_dmamem_alloc/map) from
ADAPTER_REQ_RUN_XFER context (which can be interrupt context), defer this
to the ADAPTER_REQ_GROW_RESOURCES callback. Fixes a panic in uvm.
 1.109.4.1 22-Aug-2005  riz branches: 1.109.4.1.2;
Pull up following revision(s) (requested by bouyer in ticket #5590):
sys/dev/ic/aic7xxx.c: revision 1.115
We can't free struct ahc_softc on NetBSD either, because it comes from
config(9). Fix a corruption on alldevs list when an ahc device fails to
initialise.
 1.109.4.1.2.1 16-Dec-2005  jmc Pullup rev 1.117 (requested by bouyer in ticket #10177)

Don't call alloc_scb() (which can call bus_dmamem_alloc/map) from
ADAPTER_REQ_RUN_XFER context (which can be interrupt context), defer this
to the ADAPTER_REQ_GROW_RESOURCES callback. Fixes a panic in uvm.
 1.109.2.1 16-Dec-2005  jmc Pullup rev 1.117 (requested by bouyer in ticket #10177)

Don't call alloc_scb() (which can call bus_dmamem_alloc/map) from
ADAPTER_REQ_RUN_XFER context (which can be interrupt context), defer this
to the ADAPTER_REQ_GROW_RESOURCES callback. Fixes a panic in uvm.
 1.110.6.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.110.4.1 29-Apr-2005  kent sync with -current
 1.112.2.2 29-Nov-2005  tron Pull up following revision(s) (requested by bouyer in ticket #1014):
sys/dev/ic/aic7xxx.c: revision 1.117
sys/dev/ic/aic79xxvar.h: revision 1.20
sys/dev/ic/aic79xx_osm.c: revision 1.13
sys/dev/ic/aic7xxx_inline.h: revision 1.7
sys/dev/ic/aic79xx.c: revision 1.32
sys/dev/ic/aic7xxx_osm.c: revision 1.19
sys/dev/ic/aic7xxxvar.h: revision 1.50
Don't call alloc_scb() (which can call bus_dmamem_alloc/map) from
ADAPTER_REQ_RUN_XFER context (which can be interrupt context), defer this
to the ADAPTER_REQ_GROW_RESOURCES callback.
Fix a panic in uvm reported by John R. Shannon on port-xen; patch tested on
ahc by me and on ahd by John.
 1.112.2.1 24-Aug-2005  riz Pull up following revision(s) (requested by bouyer in ticket #686):
sys/dev/ic/aic7xxx.c: revision 1.115
We can't free struct ahc_softc on NetBSD either, because it comes from
config(9). Fix a corruption on alldevs list when an ahc device fails to
initialise.
 1.114.2.5 27-Feb-2008  yamt sync with head.
 1.114.2.4 04-Feb-2008  yamt sync with head.
 1.114.2.3 03-Sep-2007  yamt sync with head.
 1.114.2.2 30-Dec-2006  yamt sync with head.
 1.114.2.1 21-Jun-2006  yamt sync with head.
 1.116.6.1 29-Nov-2005  yamt sync with head.
 1.117.6.2 01-Jun-2006  kardel Sync with head.
 1.117.6.1 22-Apr-2006  simonb Sync with head.
 1.117.4.1 09-Sep-2006  rpaulo sync with head
 1.117.2.1 01-Mar-2006  yamt sync with head.
 1.118.4.1 19-Apr-2006  elad sync with head.
 1.118.2.2 24-May-2006  yamt sync with head.
 1.118.2.1 01-Apr-2006  yamt sync with head.
 1.119.2.1 24-May-2006  tron Merge 2006-05-24 NetBSD-current into the "peter-altq" branch.
 1.120.2.1 19-Jun-2006  chap Sync with head.
 1.121.8.2 10-Dec-2006  yamt sync with head.
 1.121.8.1 22-Oct-2006  yamt sync with head
 1.121.6.1 18-Nov-2006  ad Sync with head.
 1.123.4.1 12-Mar-2007  rmind Sync with HEAD.
 1.124.22.1 18-Feb-2008  mjf Sync with HEAD.
 1.124.16.1 23-Mar-2008  matt sync with HEAD
 1.126.24.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.126.18.1 28-Apr-2009  skrll Sync with HEAD.
 1.126.16.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.126.10.2 16-Sep-2009  yamt sync with head
 1.126.10.1 04-May-2009  yamt sync with head.
 1.130.26.1 18-May-2014  rmind sync with head
 1.130.22.2 03-Dec-2017  jdolecek update from HEAD
 1.130.22.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.130.12.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.131.6.1 06-Apr-2015  skrll Sync with HEAD
 1.131.4.1 16-Feb-2015  martin Pull up following revision(s) (requested by maxv in ticket #520):
sys/ufs/chfs/ebh.c: revision 1.6
sys/dev/sdmmc/sdmmc_mem.c: revision 1.33
sys/dev/ic/aic7xxx.c: revision 1.132
sys/fs/nfs/common/krpc_subr.c: revision 1.2
sys/modules/lua/lua.c: revision 1.16
sys/fs/udf/udf_subr.c: revision 1.128
sys/ufs/chfs/chfs_scan.c: revision 1.6
sys/dev/ic/an.c: revision 1.62

Fix six memory leaks and two inconsistencies.
 1.132.16.1 07-Apr-2018  pgoyette Sync with HEAD. 77 conflicts resolved - all of them $NetBSD$
 1.134.2.3 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.134.2.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.134.2.1 10-Jun-2019  christos Sync with HEAD
 1.142.6.1 01-Aug-2021  thorpej Sync with HEAD.
 1.6 01-Jan-2022  msaitoh s/sytem/system/
 1.5 30-Oct-2016  mlelstv CAM status values are used as xs_status and must be mapped to XS values.
Add the missing mapping for CAM_CMD_TIMEOUT.
 1.4 14-Mar-2006  tsutsui branches: 1.4.110; 1.4.130; 1.4.134;
TAB/space cleanup.
 1.3 20-Apr-2003  fvdl branches: 1.3.18; 1.3.32; 1.3.34; 1.3.36; 1.3.38;
Get rid of AHC_LUN_WILDCARD, making differences with FreeBSD smaller.
 1.2 19-Apr-2003  fvdl NetBSD RCS Ids.
 1.1 19-Apr-2003  fvdl Newer adaptec 7xxx driver. Written by Justin Gibbs for FreeBSD. Ported to
NetBSD by Pascal Renauld at Network Storage Solutions, Inc.
Some modifications by me.
 1.3.38.1 19-Apr-2006  elad sync with head.
 1.3.36.1 01-Apr-2006  yamt sync with head.
 1.3.34.1 22-Apr-2006  simonb Sync with head.
 1.3.32.1 09-Sep-2006  rpaulo sync with head
 1.3.18.1 21-Jun-2006  yamt sync with head.
 1.4.134.1 04-Nov-2016  pgoyette Sync with HEAD
 1.4.130.1 05-Dec-2016  skrll Sync with HEAD
 1.4.110.1 03-Dec-2017  jdolecek update from HEAD
 1.15 19-Apr-2018  christos s/static inline/static __inline/g for consistency.
 1.14 15-Mar-2009  cegger branches: 1.14.62;
ansify function definitions
 1.13 11-Feb-2008  dyoung branches: 1.13.10; 1.13.18; 1.13.24;
Constify ahc_set_name(), ahc_name(). Do not free(9) memory that
may not belong to us.
 1.12 16-Nov-2006  christos branches: 1.12.24; 1.12.30;
__unused removal on arguments; approved by core.
 1.11 12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.10 14-Mar-2006  tsutsui branches: 1.10.10; 1.10.12;
TAB/space cleanup.
 1.9 16-Feb-2006  perry branches: 1.9.2; 1.9.4;
Change "inline" back to "__inline" in .h files -- C99 is still too
new, and some apps compile things in C89 mode. C89 keywords stay.

As per core@.
 1.8 24-Dec-2005  perry branches: 1.8.2; 1.8.4; 1.8.6;
Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.7 28-Nov-2005  bouyer Don't call alloc_scb() (which can call bus_dmamem_alloc/map) from
ADAPTER_REQ_RUN_XFER context (which can be interrupt context), defer this
to the ADAPTER_REQ_GROW_RESOURCES callback.
Fix a panic in uvm reported by John R. Shannon on port-xen; patch tested on
ahc by me and on ahd by John.
 1.6 27-Feb-2005  perry branches: 1.6.2; 1.6.4; 1.6.10;
nuke trailing whitespace
 1.5 21-Feb-2005  thorpej Part 1 of a cleanup pass over the SCSI subsystem. The aim is to name
everything "scsi_*", since we really are talking about the SCSI command
set, ATAPI transport not withstanding. Improve the names of many structures,
and prepend "SCSI_" onto all SCSI command opcodes. Place items described
by the SCSI Primary Commands document into scsi_spc.h.
 1.4 02-Nov-2003  wiz branches: 1.4.2; 1.4.6; 1.4.8; 1.4.10; 1.4.14;
Fix some typos. From Tom Cosgrove via jmc@openbsd.
 1.3 03-May-2003  wiz branches: 1.3.2;
DMA, not dma nor Dma.
 1.2 19-Apr-2003  fvdl NetBSD RCS Ids.
 1.1 19-Apr-2003  fvdl Newer adaptec 7xxx driver. Written by Justin Gibbs for FreeBSD. Ported to
NetBSD by Pascal Renauld at Network Storage Solutions, Inc.
Some modifications by me.
 1.3.2.5 11-Dec-2005  christos Sync with head.
 1.3.2.4 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.3.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.3.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.3.2.1 03-Aug-2004  skrll Sync with HEAD
 1.4.14.1 16-Dec-2005  jmc Pullup rev 1.7 (requested by bouyer in ticket #10177)

Don't call alloc_scb() (which can call bus_dmamem_alloc/map) from
ADAPTER_REQ_RUN_XFER context (which can be interrupt context), defer this
to the ADAPTER_REQ_GROW_RESOURCES callback. Fixes a panic in uvm.
 1.4.10.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.4.8.1 29-Apr-2005  kent sync with -current
 1.4.6.1 16-Dec-2005  jmc Pullup rev 1.7 (requested by bouyer in ticket #10177)

Don't call alloc_scb() (which can call bus_dmamem_alloc/map) from
ADAPTER_REQ_RUN_XFER context (which can be interrupt context), defer this
to the ADAPTER_REQ_GROW_RESOURCES callback. Fixes a panic in uvm.
 1.4.2.1 16-Dec-2005  jmc Pullup rev 1.7 (requested by bouyer in ticket #10177)

Don't call alloc_scb() (which can call bus_dmamem_alloc/map) from
ADAPTER_REQ_RUN_XFER context (which can be interrupt context), defer this
to the ADAPTER_REQ_GROW_RESOURCES callback. Fixes a panic in uvm.
 1.6.10.1 29-Nov-2005  yamt sync with head.
 1.6.4.3 27-Feb-2008  yamt sync with head.
 1.6.4.2 30-Dec-2006  yamt sync with head.
 1.6.4.1 21-Jun-2006  yamt sync with head.
 1.6.2.1 29-Nov-2005  tron Pull up following revision(s) (requested by bouyer in ticket #1014):
sys/dev/ic/aic7xxx.c: revision 1.117
sys/dev/ic/aic79xxvar.h: revision 1.20
sys/dev/ic/aic79xx_osm.c: revision 1.13
sys/dev/ic/aic7xxx_inline.h: revision 1.7
sys/dev/ic/aic79xx.c: revision 1.32
sys/dev/ic/aic7xxx_osm.c: revision 1.19
sys/dev/ic/aic7xxxvar.h: revision 1.50
Don't call alloc_scb() (which can call bus_dmamem_alloc/map) from
ADAPTER_REQ_RUN_XFER context (which can be interrupt context), defer this
to the ADAPTER_REQ_GROW_RESOURCES callback.
Fix a panic in uvm reported by John R. Shannon on port-xen; patch tested on
ahc by me and on ahd by John.
 1.8.6.1 22-Apr-2006  simonb Sync with head.
 1.8.4.1 09-Sep-2006  rpaulo sync with head
 1.8.2.1 18-Feb-2006  yamt sync with head.
 1.9.4.1 19-Apr-2006  elad sync with head.
 1.9.2.1 01-Apr-2006  yamt sync with head.
 1.10.12.2 10-Dec-2006  yamt sync with head.
 1.10.12.1 22-Oct-2006  yamt sync with head
 1.10.10.1 18-Nov-2006  ad Sync with head.
 1.12.30.1 18-Feb-2008  mjf Sync with HEAD.
 1.12.24.1 23-Mar-2008  matt sync with HEAD
 1.13.24.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.13.18.1 28-Apr-2009  skrll Sync with HEAD.
 1.13.10.1 04-May-2009  yamt sync with head.
 1.14.62.1 22-Apr-2018  pgoyette Sync with HEAD
 1.43 01-Aug-2023  andvar fix various typos in comments.
 1.42 23-Feb-2022  andvar fix various typos in comments, mainly immediatly/immediately/,
as well shared and recently fixed typos in OpenBSD code by Jonathan Grey.
 1.41 07-Aug-2021  thorpej Merge thorpej-cfargs2.
 1.40 24-Apr-2021  thorpej branches: 1.40.8;
Merge thorpej-cfargs branch:

Simplify and make extensible the config_search() / config_found() /
config_attach() interfaces: rather than having different variants for
which arguments you want pass along, just have a single call that
takes a variadic list of tag-value arguments.

Adjust all call sites:
- Simplify wherever possible; don't pass along arguments that aren't
actually needed.
- Don't be explicit about what interface attribute is attaching if
the device only has one. (More simplification.)
- Add a config_probe() function to be used in indirect configuiration
situations, making is visibly easier to see when indirect config is
in play, and allowing for future change in semantics. (As of now,
this is just a wrapper around config_match(), but that is an
implementation detail.)

Remove unnecessary or redundant interface attributes where they're not
needed.

There are currently 5 "cfargs" defined:
- CFARG_SUBMATCH (submatch function for direct config)
- CFARG_SEARCH (search function for indirect config)
- CFARG_IATTR (interface attribte)
- CFARG_LOCATORS (locators array)
- CFARG_DEVHANDLE (devhandle_t - wraps OFW, ACPI, etc. handles)

...and a sentinel value CFARG_EOL.

Add some extra sanity checking to ensure that interface attributes
aren't ambiguous.

Use CFARG_DEVHANDLE in MI FDT, OFW, and ACPI code, and macppc and shark
ports to associate those device handles with device_t instance. This
will trickle trough to more places over time (need back-end for pre-OFW
Sun OBP; any others?).
 1.39 10-Nov-2019  chs branches: 1.39.10;
in many device attach paths, allocate memory with M_WAITOK instead of M_NOWAIT
and remove code to handle failures that can no longer happen.
 1.38 30-Oct-2016  mlelstv branches: 1.38.16;
Error recovery stops normal queue processing but didn't resume it
when the recovery succeeded. Add the missing calls to scsipi_channel_thaw
similar to kern/41867.
 1.37 24-Feb-2010  dyoung branches: 1.37.20; 1.37.38; 1.37.42;
A pointer typedef entails trading too much flexibility to declare const
and non-const types, and the kernel uses both const and non-const
PMF qualifiers and device suspensors, so change the pmf_qual_t and
device_suspensor_t typedefs from "pointers to const" to non-pointer,
non-const types.
 1.36 08-Jan-2010  dyoung branches: 1.36.2;
Expand PMF_FN_* macros.
 1.35 22-Sep-2009  tsutsui - wrap long lines
- remove unnecessary casts against void pointers
 1.34 12-Sep-2009  tsutsui Fix warnings by -Wpointer-sign, which is disabled by default. PR kern/33965
 1.33 02-Sep-2009  tsutsui Call ahc_shutdown() during system shutdown via pmf_device_register1(9),
as well as pre-pmf(9)'fied kernel did via shutdownhook_establish(9).
Tested on O2.

ahc_suspend() and ahc_resume() are still disabled due to lack of hardware.
Anyone who can test Cardbus APA-1480?
 1.32 02-Sep-2009  tsutsui Call pmf_device_register(9) in ahc_attahc() rather than ahc_pci_attach()
since pmf_device_deregister(9) is called from ahc_detach() so that
cardbus backend also gets proper pmf(9) calls.
PCI backend is tested on on O2, but cardbus is untested.
 1.31 16-May-2009  tsutsui Make ahc_detach() take struct ahc_softc * as well as ahc_attach()
and remove bogus casts around ahc_detach().

XXX: There is a pmf_device_deregister(9) call in ahc_detach()
XXX: while there is no pmf_device_register(9) in ahc_attach().
XXX: It looks more pmf(9) stuff is required for cardbus detach.
 1.30 12-May-2009  cegger struct device * -> device_t, no functional changes intended.
 1.29 07-May-2009  rjs Use device_private().
 1.28 05-May-2009  cegger device_t/softc split
 1.27 08-Apr-2008  cegger branches: 1.27.4; 1.27.18;
use aprint_*_dev and device_xname
 1.26 28-Jan-2008  macallan branches: 1.26.6;
get rid of the shutdown hook, add suspend and resume handlers instead
XXX: ahc_suspend panics here so suspend calls ahc_shutdown and resume does
nothing.
This fixes a hangup and subsequent panic which occured when the shutdown hooks
were called and /afterwards/ the sd suspend handler tried to flush caches
through an already shut down ahc.
 1.25 04-Mar-2007  christos branches: 1.25.16; 1.25.22;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.24 16-Nov-2006  christos branches: 1.24.4;
__unused removal on arguments; approved by core.
 1.23 12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.22 10-Apr-2006  bouyer branches: 1.22.8; 1.22.10;
Don't use ppr_option uninitialized. Coverity ID 2504.
 1.21 14-Mar-2006  tsutsui branches: 1.21.2;
TAB/space cleanup.
 1.20 05-Dec-2005  bouyer branches: 1.20.4; 1.20.6; 1.20.8; 1.20.10;
Wrap debug printf in AHC_DEBUG. Pointed out by Izumi Tsutsui.
 1.19 28-Nov-2005  bouyer Don't call alloc_scb() (which can call bus_dmamem_alloc/map) from
ADAPTER_REQ_RUN_XFER context (which can be interrupt context), defer this
to the ADAPTER_REQ_GROW_RESOURCES callback.
Fix a panic in uvm reported by John R. Shannon on port-xen; patch tested on
ahc by me and on ahd by John.
 1.18 10-Sep-2005  tsutsui branches: 1.18.6;
Replace a magic number with proper macro.
 1.17 30-May-2005  christos branches: 1.17.2;
- add missing const
- fix variable shadowing
- remove unneeded casts
 1.16 27-Feb-2005  perry branches: 1.16.2;
nuke trailing whitespace
 1.15 21-Apr-2004  itojun branches: 1.15.4; 1.15.6;
avoid unbounded sprintf(), use snprintf()
 1.14 02-Nov-2003  wiz branches: 1.14.2; 1.14.4; 1.14.6;
Fix some typos. From Tom Cosgrove via jmc@openbsd.
 1.13 30-Oct-2003  simonb Remove some assigned-to but otherwise unused variables.
 1.12 01-Oct-2003  fvdl Reenable negotiation by default for discovery commands, until I figure out
what the issue is.
 1.11 02-Sep-2003  fvdl * Make the ahc and ahd probes more alike.
* Remove some redundant code.
* ahd: Don't initiate negotiation for a discovery xs when the negotiation goal
is set. Just looking at the auto_negotiate mask is enough, and it can
cause an endless loop if the request gets requeued (happens with a
of a PPR negotiation, which ends with a busfree).
 1.10 14-Jul-2003  lukem add missing __KERNEL_RCSID()
 1.9 19-Jun-2003  bouyer branches: 1.9.2;
Make sure we pass the current state of the driver to scsipi_async_event(),
not the request from the mid-layer.
Fix kern/21893 from Anthony Mallet.
 1.8 01-May-2003  fvdl Don't reference channel_b if it's not a twin channel adapter.
From MINOURA Makoto.
 1.7 21-Apr-2003  fvdl Reset channel(s) in ahc_attach, rather than at first access.
 1.6 21-Apr-2003  fvdl Set/report DT a bit more correctly.
 1.5 20-Apr-2003  fvdl Pick the right channel in the reset ioctl.
 1.4 20-Apr-2003  fvdl Resurrect change from previous ahc driver version: reset channel (unless
configured not to in the BIOS) on first access.
 1.3 20-Apr-2003  fvdl Delay ahc_free until after shutdown hook disestablish.
 1.2 19-Apr-2003  fvdl NetBSD RCS Ids.
 1.1 19-Apr-2003  fvdl Newer adaptec 7xxx driver. Written by Justin Gibbs for FreeBSD. Ported to
NetBSD by Pascal Renauld at Network Storage Solutions, Inc.
Some modifications by me.
 1.9.2.6 11-Dec-2005  christos Sync with head.
 1.9.2.5 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.9.2.4 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.9.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.9.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.9.2.1 03-Aug-2004  skrll Sync with HEAD
 1.14.6.1 16-Dec-2005  jmc Pullup rev 1.19-1.20 (requested by bouyer in ticket #10177)

Don't call alloc_scb() (which can call bus_dmamem_alloc/map) from
ADAPTER_REQ_RUN_XFER context (which can be interrupt context), defer this
to the ADAPTER_REQ_GROW_RESOURCES callback. Fixes a panic in uvm.
 1.14.4.1 16-Dec-2005  jmc Pullup rev 1.19-1.20 (requested by bouyer in ticket #10177)

Don't call alloc_scb() (which can call bus_dmamem_alloc/map) from
ADAPTER_REQ_RUN_XFER context (which can be interrupt context), defer this
to the ADAPTER_REQ_GROW_RESOURCES callback. Fixes a panic in uvm.
 1.14.2.1 16-Dec-2005  jmc Pullup rev 1.19-1.20 (requested by bouyer in ticket #10177)

Don't call alloc_scb() (which can call bus_dmamem_alloc/map) from
ADAPTER_REQ_RUN_XFER context (which can be interrupt context), defer this
to the ADAPTER_REQ_GROW_RESOURCES callback. Fixes a panic in uvm.
 1.15.6.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.15.4.1 29-Apr-2005  kent sync with -current
 1.16.2.2 07-Dec-2005  tron Pull up following revision(s) (requested by bouyer in ticket #1033):
sys/dev/ic/aic7xxx_osm.c: revision 1.20
sys/dev/ic/aic79xx_osm.c: revision 1.14
Wrap debug printf in AHC_DEBUG. Pointed out by Izumi Tsutsui.
 1.16.2.1 29-Nov-2005  tron Pull up following revision(s) (requested by bouyer in ticket #1014):
sys/dev/ic/aic7xxx.c: revision 1.117
sys/dev/ic/aic79xxvar.h: revision 1.20
sys/dev/ic/aic79xx_osm.c: revision 1.13
sys/dev/ic/aic7xxx_inline.h: revision 1.7
sys/dev/ic/aic79xx.c: revision 1.32
sys/dev/ic/aic7xxx_osm.c: revision 1.19
sys/dev/ic/aic7xxxvar.h: revision 1.50
Don't call alloc_scb() (which can call bus_dmamem_alloc/map) from
ADAPTER_REQ_RUN_XFER context (which can be interrupt context), defer this
to the ADAPTER_REQ_GROW_RESOURCES callback.
Fix a panic in uvm reported by John R. Shannon on port-xen; patch tested on
ahc by me and on ahd by John.
 1.17.2.4 04-Feb-2008  yamt sync with head.
 1.17.2.3 03-Sep-2007  yamt sync with head.
 1.17.2.2 30-Dec-2006  yamt sync with head.
 1.17.2.1 21-Jun-2006  yamt sync with head.
 1.18.6.1 29-Nov-2005  yamt sync with head.
 1.20.10.1 19-Apr-2006  elad sync with head.
 1.20.8.2 11-Apr-2006  yamt sync with head
 1.20.8.1 01-Apr-2006  yamt sync with head.
 1.20.6.1 22-Apr-2006  simonb Sync with head.
 1.20.4.1 09-Sep-2006  rpaulo sync with head
 1.21.2.1 24-May-2006  tron Merge 2006-05-24 NetBSD-current into the "peter-altq" branch.
 1.22.10.2 10-Dec-2006  yamt sync with head.
 1.22.10.1 22-Oct-2006  yamt sync with head
 1.22.8.1 18-Nov-2006  ad Sync with head.
 1.24.4.1 12-Mar-2007  rmind Sync with HEAD.
 1.25.22.1 18-Feb-2008  mjf Sync with HEAD.
 1.25.16.1 23-Mar-2008  matt sync with HEAD
 1.26.6.1 02-Jun-2008  mjf Sync with HEAD.
 1.27.18.2 23-Jul-2009  jym Sync with HEAD.
 1.27.18.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.27.4.3 11-Mar-2010  yamt sync with head
 1.27.4.2 16-Sep-2009  yamt sync with head
 1.27.4.1 16-May-2009  yamt sync with head
 1.36.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.37.42.1 04-Nov-2016  pgoyette Sync with HEAD
 1.37.38.1 05-Dec-2016  skrll Sync with HEAD
 1.37.20.1 03-Dec-2017  jdolecek update from HEAD
 1.38.16.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.39.10.1 21-Mar-2021  thorpej Give config_found() the same variadic arguments treatment as
config_search(). This commit only adds the CFARG_EOL sentinel
to the existing config_found() calls. Conversion of config_found_sm_loc()
and config_found_ia() call sites will be in subsequent commits.
 1.40.8.1 04-Aug-2021  thorpej Adapt to CFARGS().
 1.26 28-Feb-2025  andvar Fix various typos in comments.
 1.25 13-Nov-2010  uebayasi branches: 1.25.98;
Don't pull in the whole uvm(9) API to access only PAGE_SIZE and
some other constants. These are provided by sys/param.h now.
 1.24 16-May-2009  tsutsui branches: 1.24.4;
Make ahc_detach() take struct ahc_softc * as well as ahc_attach()
and remove bogus casts around ahc_detach().

XXX: There is a pmf_device_deregister(9) call in ahc_detach()
XXX: while there is no pmf_device_register(9) in ahc_attach().
XXX: It looks more pmf(9) stuff is required for cardbus detach.
 1.23 12-May-2009  cegger struct device * -> device_t, no functional changes intended.
 1.22 05-May-2009  cegger device_t/softc split
 1.21 15-Mar-2009  cegger ansify function definitions
 1.20 08-Apr-2008  cegger branches: 1.20.4; 1.20.12; 1.20.18;
use aprint_*_dev and device_xname
 1.19 19-Oct-2007  ad branches: 1.19.16;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.18 09-Jul-2007  ad branches: 1.18.6; 1.18.8; 1.18.12;
Merge some of the less invasive changes from the vmlocking branch:

- kthread, callout, devsw API changes
- select()/poll() improvements
- miscellaneous MT safety improvements
 1.17 16-Nov-2006  christos branches: 1.17.8; 1.17.10;
__unused removal on arguments; approved by core.
 1.16 12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.15 21-May-2006  christos branches: 1.15.6; 1.15.8;
void casts to functions whose return values are ignored.
 1.14 14-Mar-2006  tsutsui branches: 1.14.2; 1.14.4;
Oops, fix botch in previous.
 1.13 14-Mar-2006  tsutsui TAB/space cleanup.
 1.12 16-Feb-2006  perry branches: 1.12.2; 1.12.4;
Change "inline" back to "__inline" in .h files -- C99 is still too
new, and some apps compile things in C89 mode. C89 keywords stay.

As per core@.
 1.11 24-Dec-2005  perry branches: 1.11.2; 1.11.4; 1.11.6;
Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.10 11-Dec-2005  christos merge ktrace-lwp.
 1.9 27-Feb-2005  perry branches: 1.9.4;
nuke trailing whitespace
 1.8 21-Feb-2005  thorpej Part 1 of a cleanup pass over the SCSI subsystem. The aim is to name
everything "scsi_*", since we really are talking about the SCSI command
set, ATAPI transport not withstanding. Improve the names of many structures,
and prepend "SCSI_" onto all SCSI command opcodes. Place items described
by the SCSI Primary Commands document into scsi_spc.h.
 1.7 02-Nov-2003  wiz branches: 1.7.8; 1.7.10;
Fix some typos. From Tom Cosgrove via jmc@openbsd.
 1.6 08-Jul-2003  itojun function prototype must not have variable name
 1.5 04-May-2003  kristerw branches: 1.5.2;
Change the type of the 'code' parameter of ahc_send_async() from u_int
to ac_code to agree with the function definition.
 1.4 03-May-2003  wiz DMA, not dma nor Dma.
 1.3 20-Apr-2003  fvdl Actually define ahc_htole and reverse macros.
 1.2 19-Apr-2003  fvdl NetBSD RCS Ids.
 1.1 19-Apr-2003  fvdl Newer adaptec 7xxx driver. Written by Justin Gibbs for FreeBSD. Ported to
NetBSD by Pascal Renauld at Network Storage Solutions, Inc.
Some modifications by me.
 1.5.2.4 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.5.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.5.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.5.2.1 03-Aug-2004  skrll Sync with HEAD
 1.7.10.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.7.8.1 29-Apr-2005  kent sync with -current
 1.9.4.4 27-Oct-2007  yamt sync with head.
 1.9.4.3 03-Sep-2007  yamt sync with head.
 1.9.4.2 30-Dec-2006  yamt sync with head.
 1.9.4.1 21-Jun-2006  yamt sync with head.
 1.11.6.2 01-Jun-2006  kardel Sync with head.
 1.11.6.1 22-Apr-2006  simonb Sync with head.
 1.11.4.1 09-Sep-2006  rpaulo sync with head
 1.11.2.1 18-Feb-2006  yamt sync with head.
 1.12.4.1 19-Apr-2006  elad sync with head.
 1.12.2.2 24-May-2006  yamt sync with head.
 1.12.2.1 01-Apr-2006  yamt sync with head.
 1.14.4.1 19-Jun-2006  chap Sync with head.
 1.14.2.1 24-May-2006  tron Merge 2006-05-24 NetBSD-current into the "peter-altq" branch.
 1.15.8.2 10-Dec-2006  yamt sync with head.
 1.15.8.1 22-Oct-2006  yamt sync with head
 1.15.6.1 18-Nov-2006  ad Sync with head.
 1.17.10.1 11-Jul-2007  mjf Sync with head.
 1.17.8.2 23-Oct-2007  ad Sync with head.
 1.17.8.1 01-Jul-2007  ad Adapt to callout API change.
 1.18.12.1 25-Oct-2007  bouyer Sync with HEAD.
 1.18.8.1 06-Nov-2007  matt sync with HEAD
 1.18.6.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.19.16.1 02-Jun-2008  mjf Sync with HEAD.
 1.20.18.2 23-Jul-2009  jym Sync with HEAD.
 1.20.18.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.20.12.1 28-Apr-2009  skrll Sync with HEAD.
 1.20.4.2 16-May-2009  yamt sync with head
 1.20.4.1 04-May-2009  yamt sync with head.
 1.24.4.1 05-Mar-2011  rmind sync with head
 1.25.98.1 02-Aug-2025  perseant Sync with HEAD
 1.14 25-Sep-2022  thorpej Remove unnecessary include of <sys/malloc.h>.
 1.13 14-Mar-2009  dsl Change about 4500 of the K&R function definitions to ANSI ones.
There are still about 1600 left, but they have ',' or /* ... */
in the actual variable definitions - which my awk script doesn't handle.
There are also many that need () -> (void).
(The script does handle misordered arguments.)
 1.12 19-Oct-2007  ad branches: 1.12.20; 1.12.28; 1.12.34;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.11 11-Dec-2005  christos branches: 1.11.30; 1.11.44; 1.11.46; 1.11.50;
merge ktrace-lwp.
 1.10 27-Feb-2005  perry branches: 1.10.4;
nuke trailing whitespace
 1.9 04-Dec-2003  keihan branches: 1.9.8; 1.9.10;
netbsd.org -> NetBSD.org

This was the last commit of this kind to src/sys, which is now totally
"NetBSD.org clean". Thanks for the patiance, and sorry for all the commits.
 1.8 02-May-2003  dyoung branches: 1.8.2;
Adapt SMC 93cx6 library so that it will work with both 8- and 32-bit
registers. This is so that I can read an SMC 93cx6 through the
32-bit registers of the ADMtek ADM8211 802.11 wireless MAC.

Adapt aic to choose 8-bit registers.
 1.7 19-Apr-2003  fvdl Newer adaptec 7xxx driver. Written by Justin Gibbs for FreeBSD. Ported to
NetBSD by Pascal Renauld at Network Storage Solutions, Inc.
Some modifications by me.
 1.6 13-Nov-2001  lukem add/cleanup RCSID
 1.5 30-Apr-2001  lukem branches: 1.5.2;
delint
 1.4 24-Sep-2000  jdolecek branches: 1.4.2; 1.4.4;
use new generic bootverbose instead of local definition
 1.3 06-Jun-2000  soren Only wait 100 ms instead of 1 s for the SEEPROM to come ready. This is
still plenty for cards with SEEPROM's and reduces the delay on platforms
without, which conveniently also avoids triggering the O2 watchdog timer.
 1.2 15-Mar-2000  fvdl branches: 1.2.2;
New ahc driver, a port of Justin Gibbs' FreeBSD driver. This adds
support for the U2W chips, and U160 controllers.
 1.1 26-Jan-2000  thorpej Split the code that reads the SEEPROM into its own file.
 1.2.2.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.4.4.2 14-Nov-2001  nathanw Catch up to -current.
 1.4.4.1 21-Jun-2001  nathanw Catch up to -current.
 1.4.2.2 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.4.2.1 24-Sep-2000  bouyer file aic7xxx_seeprom.c was added on branch thorpej_scsipi on 2000-11-20 11:40:20 +0000
 1.5.2.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.8.2.4 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.8.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.8.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.8.2.1 03-Aug-2004  skrll Sync with HEAD
 1.9.10.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.9.8.1 29-Apr-2005  kent sync with -current
 1.10.4.1 27-Oct-2007  yamt sync with head.
 1.11.50.1 25-Oct-2007  bouyer Sync with HEAD.
 1.11.46.1 06-Nov-2007  matt sync with HEAD
 1.11.44.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.11.30.1 23-Oct-2007  ad Sync with head.
 1.12.34.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.12.28.1 28-Apr-2009  skrll Sync with HEAD.
 1.12.20.1 04-May-2009  yamt sync with head.
 1.7 15-Mar-2000  fvdl New ahc driver, a port of Justin Gibbs' FreeBSD driver. This adds
support for the U2W chips, and U160 controllers.
 1.6 03-Jul-1998  mjacob branches: 1.6.14;
Patches from Justin that handle some REV B AIC7880 problems
 1.5 09-Mar-1997  mikel fix some spelling errors noticed by Charles Kane <ckane@mipos2.intel.com>.
fix some more noticed by myself; all are in comments or strings.
 1.4 08-Oct-1996  gibbs branches: 1.4.4;
dev/microcode/aic7xxx/aic7xxx.seq,
dev/microcode/aic7xxx_seq.h,
dev/ic/aic7xxxreg.h:
Remove intrinsic knowledge about SDTR and WDTR messages and replace it
with a generic message system that allows the kernel driver to handle
SDTR, WDTR and any other type of extended message it chooses too. This
makes the sequencer code much simpler, makes extended message handling
debuggable since the bulk of the work is in the kernel driver, and saves
lots of instruction space.

Regen microcode header file.

dev/ic/aic7xxx.c, dev/ic/aic7xxxvar.h:
Add code to handle WDTR and SDTR negotiation in light of the changes in
the message interface to the sequencer. Don't reject targets that
negotiate async by sending an SDTR with a 0 offset. Use an sdtr message
with 0,0 to negotiate async when a target suggests a period that is too
long for us to handle. Some tape and cdrom drives don't like us doing
the message reject that we did in the past.

Fix a problem with handing the QUEUE FULL condition.

Fix a race condition (most likely the cause of the SCB paging problems) that
might allow the sequencer to get unpaused before the condition that caused
it to be paused (a SEQINT) was handled.

Race condition pointed out by Doug Ledford <dledford@dialnet.net> and
by "Dan Willis" <dan@plutotech.com>.

dev/pci/ahc_pci.c:
Add support for the 2940AU, an aic7860 based controller.

dev/pci/pcidevs.h, dev/pci/pcidevs_data.h:
Add product IDs for the 2940AU, aic7860 and aic7855.

Regen data file.

scsi/scsi_message.h:
Add MSG_EXT_SDTR_LEN and MSG_EXT_WDTR_LEN - the length of bytes in these
extended messages.

Thanks to Chuck Cranor <chuck@maria.wustl.edu> for testing these changes
out for me.
 1.3 10-Jul-1996  explorer Updates to aic7xxx driver ; from pr port-i386/2600
 1.2 20-May-1996  thorpej branches: 1.2.4;
RCS Id police.
 1.1 16-May-1996  mycroft New version, with changes from Justin Gibbs and Noriyuki Soda.
 1.2.4.2 04-Mar-1997  mycroft Pull up latest ahc driver. Fixes several bugs.
 1.2.4.1 18-Jul-1996  jtc Pulled up from rev 1.3, ahc fixes
 1.4.4.1 12-Mar-1997  is Merge in changes from Trunk
 1.6.14.1 20-Nov-2000  bouyer Remove files that are no longer on the trunck, and commit Makefile which
I forgot in the batch of commits.
 1.59 08-Feb-2024  andvar s/sharable/shareable in comments and documentation.
 1.58 22-Aug-2021  andvar fix typos in comments, add missing RCSID.
 1.57 12-May-2009  cegger struct device * -> device_t, no functional changes intended.
 1.56 05-May-2009  cegger device_t/softc split
 1.55 11-Feb-2008  dyoung branches: 1.55.10; 1.55.24;
Constify ahc_set_name(), ahc_name(). Do not free(9) memory that
may not belong to us.
 1.54 28-Jan-2008  macallan get rid of the shutdown hook, add suspend and resume handlers instead
XXX: ahc_suspend panics here so suspend calls ahc_shutdown and resume does
nothing.
This fixes a hangup and subsequent panic which occured when the shutdown hooks
were called and /afterwards/ the sd suspend handler tried to flush caches
through an already shut down ahc.
 1.53 11-May-2006  mrg branches: 1.53.34; 1.53.40;
don't declare ahc_pci_ident_table[] and ahc_num_pci_devs extern, they aren't.
 1.52 15-Apr-2006  tsutsui Add AHC_USETARGETDEFAULTS to ahc_flag, which enables to
use default target (but not for host) device settings on
ahc(4) interface without its SEEPROM (mostly on-board one).

This flag could be useful if host's BIOS (firmware) initializes
ahc(4) chip with some conservative (async, no tagged queuing etc.)
target settings for minimum support to load its primary loader etc.,
and it will be enabled in each attachment according to MD device
properties(9). Currently this property is set only on sgimips for
O2 on-board aic7880 adapters.

No objection on tech-kern (and netbsd-bugs), and closes PR kern/23276.
 1.51 14-Mar-2006  tsutsui branches: 1.51.2;
TAB/space cleanup.
 1.50 28-Nov-2005  bouyer branches: 1.50.4; 1.50.6; 1.50.8; 1.50.10;
Don't call alloc_scb() (which can call bus_dmamem_alloc/map) from
ADAPTER_REQ_RUN_XFER context (which can be interrupt context), defer this
to the ADAPTER_REQ_GROW_RESOURCES callback.
Fix a panic in uvm reported by John R. Shannon on port-xen; patch tested on
ahc by me and on ahd by John.
 1.49 28-Jun-2005  thorpej branches: 1.49.2; 1.49.8;
Remove some extern decls for PCI-specific stuff that are private to
the PCI front-end.
 1.48 30-May-2005  christos - add missing const
- fix variable shadowing
- remove unneeded casts
 1.47 27-Feb-2005  perry branches: 1.47.2;
nuke trailing whitespace
 1.46 21-Feb-2005  thorpej Part 1 of a cleanup pass over the SCSI subsystem. The aim is to name
everything "scsi_*", since we really are talking about the SCSI command
set, ATAPI transport not withstanding. Improve the names of many structures,
and prepend "SCSI_" onto all SCSI command opcodes. Place items described
by the SCSI Primary Commands document into scsi_spc.h.
 1.45 21-Apr-2004  itojun branches: 1.45.4; 1.45.6;
avoid unbounded sprintf(), use snprintf()
 1.44 19-Apr-2004  wiz Spell removable with only two es. Inspired by jmc@openbsd.
 1.43 02-Nov-2003  wiz branches: 1.43.2; 1.43.4; 1.43.6;
Fix some typos. From Tom Cosgrove via jmc@openbsd.
 1.42 08-Oct-2003  fvdl Cap the transfer size at MAXPHYS, the driver won't get bigger requests
than that. Allocating 16M per SCB is silly (as pointed out by
Frederick Bruckman).
 1.41 02-Sep-2003  fvdl * Make the ahc and ahd probes more alike.
* Remove some redundant code.
* ahd: Don't initiate negotiation for a discovery xs when the negotiation goal
is set. Just looking at the auto_negotiate mask is enough, and it can
cause an endless loop if the request gets requeued (happens with a
of a PPR negotiation, which ends with a busfree).
 1.40 08-Jul-2003  itojun function prototype must not have variable name
 1.39 14-May-2003  wiz branches: 1.39.2;
summarize with two m.
 1.38 03-May-2003  wiz DMA, not dma nor Dma.
 1.37 21-Apr-2003  fvdl Reset channel(s) in ahc_attach, rather than at first access.
 1.36 20-Apr-2003  fvdl Resurrect change from previous ahc driver version: reset channel (unless
configured not to in the BIOS) on first access.
 1.35 20-Apr-2003  fvdl Fix some AHC_DEBUG printf cases, and undef AHC_DEBUG.
 1.34 20-Apr-2003  fvdl Get rid of AHC_LUN_WILDCARD, making differences with FreeBSD smaller.
 1.33 19-Apr-2003  fvdl Newer adaptec 7xxx driver. Written by Justin Gibbs for FreeBSD. Ported to
NetBSD by Pascal Renauld at Network Storage Solutions, Inc.
Some modifications by me.
 1.32 07-Dec-2002  ichiro delete definition of STAILQ_ENTRY

previous defined sys/sys/queue.h
 1.31 11-Feb-2002  wiz explicitly, with two l.
 1.30 16-Jan-2002  ichiro add detach/activate routine
 1.29 04-Jul-2001  wiz branches: 1.29.2;
Fix typo in comment.
 1.28 30-Apr-2001  lukem delint
 1.27 25-Apr-2001  bouyer Pull up the thorpej_scsipi branch to main branch.
This is a completely rewritten scsipi_xfer execution engine, and the
associated changes to HBA drivers. Overview of changes & features:
- All xfers are queued in the mid-layer, rather than doing so in an
ad-hoc fashion in individual adapter drivers.
- Adapter/channel resource management in the mid-layer, avoids even trying
to start running an xfer if the adapter/channel doesn't have the resources.
- Better communication between the mid-layer and the adapters.
- Asynchronous event notification mechanism from adapter to mid-layer and
peripherals.
- Better peripheral queue management: freeze/thaw, sorted requeueing during
recovery, etc.
- Clean separation of peripherals, adapters, and adapter channels (no more
scsipi_link).
- Kernel thread for each scsipi_channel makes error recovery much easier
(no more dealing with interrupt context when recovering from an error).
- Mid-layer support for tagged queueing: commands can have the tag type
set explicitly, tag IDs are allocated in the mid-layer (thus eliminating
the need to use buggy tag ID allocation schemes in many adapter drivers).
- support for QUEUE FULL and CHECK CONDITION status in mid-layer; the command
will be requeued, or a REQUEST SENSE will be sent as appropriate.

Just before the merge syssrc has been tagged with thorpej_scsipi_beforemerge
 1.26 05-Feb-2001  chs branches: 1.26.2;
expose the definitions of MIN() and MAX() in sys/param.h to the kernel
and use those in favor of a dozen copies scattered around the source tree.
 1.25 18-Jan-2001  jdolecek constify
 1.24 27-May-2000  fvdl When a bus is accessed for the first time, reset it. Without this,
some devices may not be found if the BIOS (which would normally
do the reset at startup) is disabled. Should really be done from the SCSI
layer.

Implement the SCBUSIORESET ioctl.
 1.23 22-May-2000  fvdl branches: 1.23.2;
Don't try to re-enable tags once they have been disabled because of a
MSG_REJECT from the target. Obey the NOTAG quirk.
 1.22 16-Mar-2000  fvdl Do bus-specific interrupt handling (i.e. ahc_pci_intr) via a bus_intr
field in the softc, instead of relying on NPCI > 0. This would
prevent things from compiling if PCI buses were in the config file,
but ahc was attached only to something else than the PCI bus.
 1.21 15-Mar-2000  fvdl New ahc driver, a port of Justin Gibbs' FreeBSD driver. This adds
support for the U2W chips, and U160 controllers.
 1.20 26-Jan-2000  thorpej Split the code that reads the SEEPROM into its own file.
 1.19 09-Dec-1998  thorpej branches: 1.19.10;
Update for changed scsipi_xfer struct.
 1.18 19-Nov-1998  thorpej Adapt to the new scsipi_adapter interface.
 1.17 22-Jun-1998  sommerfe defopt a bunch of AHC specific options
 1.16 16-Apr-1998  leo Use a stream method for AHC_OUTSL when possible.
 1.15 16-Mar-1998  leo Use bus-dma functions.
 1.14 27-Aug-1997  bouyer Merge scsipi branch in the mainline. This add support for ATAPI devices
(currently only CD-ROM drives on i386). The sys/dev/scsipi system provides 2
busses to which devices can attach (scsibus and atapibus). This needed to
change some include files and structure names in the low level scsi drivers.
 1.13 10-Apr-1997  cgd branches: 1.13.2; 1.13.4;
clean these up (mostly rename bus_space_{tag,handle}_t variables) so that
this code makes equal sense for memory and I/O space, prefer to map
the PCI front end via memory space (conditionalized on a patchable kernel
variable), and do a bit of other random NetBSD-specific cleanup. (These
changes were sent to Justin Gibbs on March 28.)
 1.12 13-Mar-1997  cgd fixes from Matt Jacob so that these can compile and run on the Alpha.
(aic7xxx has been tested and works on the Alpha, bha has not yet been
tested on thne Alpha.)
 1.11 02-Dec-1996  thorpej Implement a simple scsi xfer queue to avoid presenting a resource
shortage to the upper scsi layers, which don't (yet) deal well with
resource shortages.
 1.10 21-Oct-1996  thorpej New bus.h implementation/interface:
- No more distinction between i/o-mapped and memory-mapped
devices. It's all "bus space" now, and space tags
differentiate the space with finer grain than the
bus chipset tag.
- Add memory barrier methods.
- Implement space alloc/free methods.
- Implement region read/write methods (like memcpy to/from
bus space).
This interface provides a better abstraction for dealing with
machine-independent chipset drivers.
 1.9 08-Oct-1996  gibbs dev/microcode/aic7xxx/aic7xxx.seq,
dev/microcode/aic7xxx_seq.h,
dev/ic/aic7xxxreg.h:
Remove intrinsic knowledge about SDTR and WDTR messages and replace it
with a generic message system that allows the kernel driver to handle
SDTR, WDTR and any other type of extended message it chooses too. This
makes the sequencer code much simpler, makes extended message handling
debuggable since the bulk of the work is in the kernel driver, and saves
lots of instruction space.

Regen microcode header file.

dev/ic/aic7xxx.c, dev/ic/aic7xxxvar.h:
Add code to handle WDTR and SDTR negotiation in light of the changes in
the message interface to the sequencer. Don't reject targets that
negotiate async by sending an SDTR with a 0 offset. Use an sdtr message
with 0,0 to negotiate async when a target suggests a period that is too
long for us to handle. Some tape and cdrom drives don't like us doing
the message reject that we did in the past.

Fix a problem with handing the QUEUE FULL condition.

Fix a race condition (most likely the cause of the SCB paging problems) that
might allow the sequencer to get unpaused before the condition that caused
it to be paused (a SEQINT) was handled.

Race condition pointed out by Doug Ledford <dledford@dialnet.net> and
by "Dan Willis" <dan@plutotech.com>.

dev/pci/ahc_pci.c:
Add support for the 2940AU, an aic7860 based controller.

dev/pci/pcidevs.h, dev/pci/pcidevs_data.h:
Add product IDs for the 2940AU, aic7860 and aic7855.

Regen data file.

scsi/scsi_message.h:
Add MSG_EXT_SDTR_LEN and MSG_EXT_WDTR_LEN - the length of bytes in these
extended messages.

Thanks to Chuck Cranor <chuck@maria.wustl.edu> for testing these changes
out for me.
 1.8 10-Jul-1996  explorer Updates to aic7xxx driver ; from pr port-i386/2600
 1.7 20-May-1996  thorpej branches: 1.7.4;
RCS Id police.
 1.6 16-May-1996  mycroft Replace STAILQ with SIMPLEQ.
 1.5 16-May-1996  mycroft Replace STAILQ with SIMPLEQ.
 1.4 16-May-1996  mycroft New version, with changes from Justin Gibbs and Noriyuki Soda.
 1.3 29-Mar-1996  mycroft Eliminate random warnings.
 1.2 14-Mar-1996  cgd RCS Id police
 1.1 09-Oct-1995  mycroft Add an Adaptec 2940 driver, by John Aycock and Justin Gibbs, ported to NetBSD by Stefan
Grefen, with several bug fixes by me.
 1.7.4.2 04-Mar-1997  mycroft Pull up latest ahc driver. Fixes several bugs.
 1.7.4.1 18-Jul-1996  jtc Pulled up from rev 1.8, ahc fixes
 1.13.4.1 27-Aug-1997  thorpej Update marc-pcmcia branch from trunk.
 1.13.2.1 01-Jul-1997  bouyer Updates for new scsipi subsystem. Actally known to work on i386 and sparc.
 1.19.10.6 25-Apr-2001  bouyer Revert back to starting sync/wide negotiation at the first command,
instead of waiting for ADAPTER_REQ_XFER_MODE: as the BIOS may have
negotiated sync/wide, and we don't reset the channel, all async/narrow
xfers would fail until the channel is reset.
 1.19.10.5 02-Apr-2001  bouyer Second part of port to thorpej_scsipi: use ADAPTER_REQ_SET_XFER_MODE to start
sync/wide nego and use tagged queuing; report modes to upper level via
scsipi_async_event().
 1.19.10.4 02-Apr-2001  bouyer Port to thorpej_scsipi, first pass. Doesn't handle ADAPTER_REQ_SET_XFER_MODE
and doesn't report its xfer mode yet, so tagged queuing isn't used yet.
 1.19.10.3 11-Feb-2001  bouyer Sync with HEAD.
 1.19.10.2 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.19.10.1 19-Oct-1999  thorpej Adapt to scsipi API changes.
 1.23.2.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.26.2.4 11-Dec-2002  thorpej Sync with HEAD.
 1.26.2.3 28-Feb-2002  nathanw Catch up to -current.
 1.26.2.2 24-Aug-2001  nathanw Catch up with -current.
 1.26.2.1 21-Jun-2001  nathanw Catch up to -current.
 1.29.2.2 16-Mar-2002  jdolecek Catch up with -current.
 1.29.2.1 11-Feb-2002  jdolecek Sync w/ -current.
 1.39.2.6 11-Dec-2005  christos Sync with head.
 1.39.2.5 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.39.2.4 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.39.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.39.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.39.2.1 03-Aug-2004  skrll Sync with HEAD
 1.43.6.1 16-Dec-2005  jmc Pullup rev 1.50 (requested by bouyer in ticket #10177)

Don't call alloc_scb() (which can call bus_dmamem_alloc/map) from
ADAPTER_REQ_RUN_XFER context (which can be interrupt context), defer this
to the ADAPTER_REQ_GROW_RESOURCES callback. Fixes a panic in uvm.
 1.43.4.1 16-Dec-2005  jmc Pullup rev 1.50 (requested by bouyer in ticket #10177)

Don't call alloc_scb() (which can call bus_dmamem_alloc/map) from
ADAPTER_REQ_RUN_XFER context (which can be interrupt context), defer this
to the ADAPTER_REQ_GROW_RESOURCES callback. Fixes a panic in uvm.
 1.43.2.1 16-Dec-2005  jmc Pullup rev 1.50 (requested by bouyer in ticket #10177)

Don't call alloc_scb() (which can call bus_dmamem_alloc/map) from
ADAPTER_REQ_RUN_XFER context (which can be interrupt context), defer this
to the ADAPTER_REQ_GROW_RESOURCES callback. Fixes a panic in uvm.
 1.45.6.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.45.4.1 29-Apr-2005  kent sync with -current
 1.47.2.1 29-Nov-2005  tron Pull up following revision(s) (requested by bouyer in ticket #1014):
sys/dev/ic/aic7xxx.c: revision 1.117
sys/dev/ic/aic79xxvar.h: revision 1.20
sys/dev/ic/aic79xx_osm.c: revision 1.13
sys/dev/ic/aic7xxx_inline.h: revision 1.7
sys/dev/ic/aic79xx.c: revision 1.32
sys/dev/ic/aic7xxx_osm.c: revision 1.19
sys/dev/ic/aic7xxxvar.h: revision 1.50
Don't call alloc_scb() (which can call bus_dmamem_alloc/map) from
ADAPTER_REQ_RUN_XFER context (which can be interrupt context), defer this
to the ADAPTER_REQ_GROW_RESOURCES callback.
Fix a panic in uvm reported by John R. Shannon on port-xen; patch tested on
ahc by me and on ahd by John.
 1.49.8.1 29-Nov-2005  yamt sync with head.
 1.49.2.3 27-Feb-2008  yamt sync with head.
 1.49.2.2 04-Feb-2008  yamt sync with head.
 1.49.2.1 21-Jun-2006  yamt sync with head.
 1.50.10.2 11-May-2006  elad sync with head
 1.50.10.1 19-Apr-2006  elad sync with head.
 1.50.8.2 24-May-2006  yamt sync with head.
 1.50.8.1 01-Apr-2006  yamt sync with head.
 1.50.6.2 01-Jun-2006  kardel Sync with head.
 1.50.6.1 22-Apr-2006  simonb Sync with head.
 1.50.4.1 09-Sep-2006  rpaulo sync with head
 1.51.2.1 24-May-2006  tron Merge 2006-05-24 NetBSD-current into the "peter-altq" branch.
 1.53.40.1 18-Feb-2008  mjf Sync with HEAD.
 1.53.34.1 23-Mar-2008  matt sync with HEAD
 1.55.24.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.55.10.1 16-May-2009  yamt sync with head
 1.5 19-Oct-2009  rmind Drop 3rd and 4th clauses from David Young's license.
Reviewed and approved by dyoung@ (copyright holder).
 1.4 08-Mar-2006  dyoung branches: 1.4.64;
Change macro names to avoid collisions:

BIT -> __BIT
BITS -> __BITS
 1.3 11-Dec-2005  christos branches: 1.3.4; 1.3.6; 1.3.8; 1.3.10;
merge ktrace-lwp.
 1.2 27-Feb-2005  perry branches: 1.2.4;
nuke trailing whitespace
 1.1 21-Jul-2004  dyoung branches: 1.1.2; 1.1.6; 1.1.8;
Add register definitions for the Airoha AL2210
synthesizer/transceiver/power amplifier. The ADMtek ADM8211C is
sometimes paired with this chip. This the first step toward
supporting the ADMtek ADM8211C-based products.
 1.1.8.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.1.6.1 29-Apr-2005  kent sync with -current
 1.1.2.5 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.1.2.4 21-Sep-2004  skrll Fix the sync with head I botched.
 1.1.2.3 18-Sep-2004  skrll Sync with HEAD.
 1.1.2.2 03-Aug-2004  skrll Sync with HEAD
 1.1.2.1 21-Jul-2004  skrll file al2210reg.h was added on branch ktrace-lwp on 2004-08-03 10:46:10 +0000
 1.2.4.1 21-Jun-2006  yamt sync with head.
 1.3.10.1 19-Apr-2006  elad sync with head.
 1.3.8.1 13-Mar-2006  yamt sync with head.
 1.3.6.1 22-Apr-2006  simonb Sync with head.
 1.3.4.1 09-Sep-2006  rpaulo sync with head
 1.4.64.1 11-Mar-2010  yamt sync with head
 1.60 12-Sep-2020  isaki Improve am7930 family drivers to share more code.
audioamd(4) on sparc, vsaudio(4) on vax, and bba(4) are.
- Remove complex and useless callbacks: onopen, onclose, and
indirect_{read,write}. This makes audioamd and vsaudio almost the same.
- Remove (already disabled) assembly fast interrupt path from audioamd(4).
cf. http://mail-index.netbsd.org/source-changes/2009/12/19/msg004585.html
- Use trigger_* method rather than start_* method. It's more suitable.
vsaudio(4) was tested by naru@, bba(4) was tested by tsutsui@.
 1.59 08-Jun-2019  isaki Clean get_props().
- Make get_props() return AUDIO_PROP_{PLAYBACK,CAPTURE} properly.
This eliminates need for audio.c to take care of such (old)
drivers which don't return both of PLAYBACK and CAPTURE.
- All get_props() doesn't need to return AUDIO_PROP_MMAP.
It is handled in the audio layer now.
 1.58 08-May-2019  isaki Merge isaki-audio2 branch, the overhaul of audio subsystem.
- Interrupt-oriented system rather than thread-oriented.
- Improve stability, quality and performance.
- Split playback and record cleanly. Improve halfduplex support.
- Many bugs are fixed including deadlocks, resource leaks, abuses, etc.
- Simplify audio filter mechanism. The encoding/channels/frequency
conversions are completely handled in the upper layer. So the hard-
ware driver only converts its hardware encoding (if necessary).
- audio_hw_if changes:
- Obsoletes query_encoding and add query_format instead.
- Obsoletes set_params and add set_format instead.
- Remove drain, setfd, mappage.
- The call sequences are changed.
- ioctl AUDIO_GETFD/SETFD, AUDIO_GETCHAN/SETCHAN are obsoleted.
- ioctl AUDIO_{QUERY,GET,SET}FORMAT are introduced.
- cleanup config attributes: au*conv and mulaw.
- All hardware drivers should follow it (I've done as much as possible).

Some file paths are changed:
- dev/audio.c -> dev/audio/audio.c (rewritten)
- dev/audiovar.h -> dev/audio/audiovar.h
- dev/audio_dai.h -> dev/audio/audio_dai.h
- dev/audio_if.h -> dev/audio/audio_if.h
- dev/audiobell.c -> dev/audio/audiobell.c
- dev/audiobellvar.h -> dev/audio/audiobellvar.h
- dev/mulaw.[ch] -> dev/audio/mulaw.[ch] + dev/audio/alaw.c
 1.57 29-Aug-2017  isaki branches: 1.57.4; 1.57.8;
Fix two typos. pfil -> rfil for recording.
One was introduced a month ago and the other was 12 years ago.
 1.56 27-Jul-2017  nat Add a null_filter to help with the audio autoconfig of pmax.

Tested by flxd@.
 1.55 25-Jun-2017  nat Set hw parameters for linear to ulaw filters.

Tested by flxd@.
 1.54 25-Jun-2017  nat rfill and pfill mixed up.
 1.53 28-Dec-2016  nat branches: 1.53.8;
Add slinear encoding. Tested by flxd@

Addresses PR kern/51703: audio fails to attach if hardware can't do CD
quality.

Autoconfiguration of hw paramaters to be done later. For now it is
possibile to set 8 bits precision 8000 Hz 1 channel via sysctls.
 1.52 20-Dec-2014  jklos branches: 1.52.2;
Remove autoconf.h include from am7930.c as per Matt Thomas so
vax/include/autoconf.h isn't necessary.
 1.51 23-Nov-2011  jmcneill branches: 1.51.8; 1.51.26;
Merge jmcneill-audiomp3 branch, which is derived from ad-audiomp2. From
the original ad-audiomp branch notes:

Add MP locking to the audio drivers.

Making the audio drivers MP safe is necessary before efforts
can be made to make the VM system MP safe.

The are two locks per device instance, an ISR lock and
a character device lock. The ISR lock replaces calls to
splaudio()/splx(), and will be held across calls to device
methods which were called at splaudio() before (e.g.
trigger_output). The character device lock is held across
calls to nearly all of the methods, excluding some only
used for initialization, e.g. get_locks.

Welcome to 5.99.57.
 1.50 19-Oct-2007  ad branches: 1.50.54; 1.50.56;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.49 11-Dec-2005  christos branches: 1.49.30; 1.49.44; 1.49.46; 1.49.50;
merge ktrace-lwp.
 1.48 22-May-2005  christos branches: 1.48.2;
No 0x in front of %p...
 1.47 15-Jan-2005  kent ansify and KNF
 1.46 10-Jan-2005  kent merge kent-audio1 branch, which introduces audio filter pipeline to the MI
audio framework


Summary of changes:

* struct audio_params
- remove sw_code, factor, factor_denom, hw_sample_rate,
hw_encoding ,hw_precision, and hw_channels. Conversion information
is conveyed by stream_filter_list_t.
- change the type of sample_rate: u_long -> u_int
- add `validbits,' which represents the valid data size in
precision bits. It is required in order to distinguish 24/32bit
from 24/24bit or 32/32bit.

* audio_hw_if
- add two parameters to set_params()
stream_filter_list_t *pfil, stream_filter_list *rfil
A HW driver should set filter recipes for requested formats
- constify audio_params parameters of trigger_output() and
trigger_input(). They represent audio formats for the hardware.
- make open() and close() optional
- add int (AUMODE_PLAY or AUMODE_RECORD) and audio_params_t parameters
to round_blocksize()

* sw_code is replaced with stream_filter_t.
stream_filer_t converts audio data in an input buffer and writes
into another output buffer unlike sw_code, which converts data in
single buffer.
converters in dev/auconv.c, dev/mulaw.c, dev/aurateconv.c,
dev/tc/bba.c, dev/ic/msm6258.c, and arch/arm/iomd/vidcaudio.c are
reimplemented as stream_filter_t

* MI audio
- audiosetinfo() builds filter pipelines from stream_filter_list_t
filled by audio_hw_if::set_params()
- audiosetinfo() returns with EINVAL if mmapped and set_params()
requests filters
- audio_write(), audio_pint(), and audio_rint() invoke a filter
pipeline.
- ioctl() for FIONREAD, AUDIO_WSEEK, AUDIO_GETIOFFS,
AUDIO_GETOOFFS, and audio_prinfo::{seek,samples} for
AUDIO_GETINFO handle values for a buffer nearest to userland.

* add `struct device *' parameter to ac97_attach()

* all of audio HW drivers follow audio_hw_if and ac97 changes
 1.45 09-Jul-2004  mycroft branches: 1.45.2;
Remove junk code.
 1.44 13-Nov-2001  lukem branches: 1.44.16;
add/cleanup RCSID
 1.43 02-May-2000  augustss branches: 1.43.6; 1.43.8;
Make am7930 driver machine independent. PR 10032 from Gregory McGarry.
 1.42 30-Mar-2000  augustss Remove register declarations.
 1.41 14-Mar-1999  jonathan branches: 1.41.8;
Use bus_space tags and handles, embedded in MD hooks AM7930_{READ_WRITE}_REG
to handle MD delay and bus padding. Tested on sparc2 by David Brownlee.

Should use regmaps, but that breaks sparc pDMA assembly code.
 1.40 28-Aug-1998  pk Nuke Dprintf; fix formats.
 1.39 24-Jun-1998  jonathan Split arch/sparc/dev/amd7930.c into:
* MI sys/dev/ic/{am7930.c,am7930var.h} chipset driver
* sparc frontend.
Presere revision history (this time).

TODO: bus.h'ify, and padded register mappings.
 1.38 07-May-1998  kleink Fix some arithmetics lossage on typeless pointers.
 1.37 30-Mar-1998  pk Replace direct `sparc_bus_map()' calls with bus space map method.
 1.36 21-Mar-1998  pk Account for changed bus attachment scheme.
 1.35 12-Jan-1998  thorpej Update for changes to config.
 1.34 06-Dec-1997  chuck fix mixer code that was clearly untested:
- allow get/set of enums SUNAUDIO_SOURCE and SUNAUDIO_OUTPUT rather
than returning EINVAL
- add missing SUNAUDIO_MONITOR_CLASS case in query_devinfo
- convert SUNAUDIO_MONITOR case from a MIXER_CLASS to a MIXER_VALUE
like it is supposed to be
- the labels for outputs/record class were swapped: fix it

this patch allows "mixerctl" to work properly on a sparc
 1.33 19-Oct-1997  christos branches: 1.33.2;
Make this compile again.
 1.32 19-Oct-1997  augustss Make the audio API (almost) SunOS compatible.
The changes is to allow some limited mixer manipulation through
the audio device (instead of the mixer device).
This rendered 4 methods in audio_hw_if unused so garbage collect these.
 1.31 11-Oct-1997  mycroft AudioC[A-Z] -> AudioC[a-z]
AudioElinear -> AudioEslinear
 1.30 27-Aug-1997  augustss Change match routine to use "audio" as the ROM name.
 1.29 27-Aug-1997  augustss Fix prototype for amd7930_set_params.
 1.28 24-Aug-1997  augustss - Change audio_hw_if a little: set_param now sets the play and record modes
at the same time instead by using two different calls. This enables
it to check more easily if the combined mode is all right.
- Improve the error checking in audio.c.
- Add a new audio property, AUDIO_PROP_INDEPENDENT, show if the
play and record settings are independent.
- Fix some buglets in audio.c.
 1.27 19-Aug-1997  augustss Change the MI audio driver so it attaches to the MD driver in the
normal way. This requires adding a line to the config files to
get audio to work again.
 1.26 31-Jul-1997  augustss Audio changes:
- Change the way attach and open works to allow multiple audio
devices.
- Split the mulaw.c file into two to avoid dragging in mulaw
convertsion when they are not needed. Add 16 bit alaw/mulaw tables.
- Change the way audio properties are gotten.
- Recognize more versions os SoundBlaster.
 1.25 28-Jul-1997  augustss branches: 1.25.2;
Audio: Remove the machine dependant code I put in audio.c by mistake.
This adds another method to audio_hw_if. Also remove a field from
audio_hw_if that was not read-only.
 1.24 27-Jul-1997  augustss audio: Simplify handling of AUDIO_SETFD and committing of encoding mode.
 1.23 27-Jul-1997  augustss Changes to the sudio system:
- It is now possible to handle devices that want "looping" DMA,
e.g. the SoundBlaster correctly. The WSS and SB drivers use this.
To do this several new methods were introduced in audio_hw_if.
- Different silence handling (forced by previous change).
- The audio driver can now be mmap()-ed, but due to problems in
the VM system only for writing for now.
- The OSS (Linux) audio emulation takes advantage of some of the
new features.
 1.22 24-May-1997  pk Remove all `bustype' arguments from map[io]dev() and REG2PHYS().
 1.21 15-May-1997  pk Tweak gain curve (from nsayer@kfu.com; PR#2909)
 1.20 09-May-1997  augustss Change the interface between high and lowlevel audio drivers again:
Set the encoding parameters slightly differently.
Remove the SW encoding/decodinf functions from this interface
and move them to the audio_parameter struct; this is both more efficient
and flexible.
 1.19 07-May-1997  augustss Convert to new orthogonal audio encoding scheme and implement
some of the new encodings. The change to ioctl AUDIO_GETENC is
NOT backwards compatible.
 1.18 29-Apr-1997  augustss Change the interface between the high and low level audio drivers
so that all audio encoding parameters are set at once. This simplifies
the interface and make error checking easier.
 1.17 20-Mar-1997  mycroft Implement set_format.
 1.16 13-Mar-1997  mycroft Don't share the silence block between devices. Make silence filling work for
more encodings, and make it device-independent. From Lennart Augustsson, in
PR kern/3305.
 1.15 10-Dec-1996  pk Comply with recent autoconfiguration changes. Diffs graciously
supplied by Chris Demetriou.
 1.14 01-Nov-1996  pk Drop in a sun4m version of AUDIO_SET_SWINTR; thanks to Nick Sayer for
the reminder.
 1.13 13-Oct-1996  christos backout previous kprintf change
 1.12 11-Oct-1996  christos printf -> kprintf, sprintf -> ksprintf
 1.11 28-May-1996  mrg count audio interupts (from OpenBSD).
 1.10 31-Mar-1996  pk Various cleanup; mostly trailing spaces/tabs.
 1.9 17-Mar-1996  thorpej New device attachment scheme:

- split softc size and match/attach out from cfdriver into
a new struct cfattach.

- new "attach" directive for files.*. May specify the name of
the cfattach structure, so that devices may be easily attached
to parents with different autoconfiguration semantics.
 1.8 14-Mar-1996  christos Bring prototypes into scope and fix compiler warnings.
 1.7 25-Feb-1996  pk Use CPU-type macros
 1.6 19-Feb-1996  pk Fix typo; pointed out by jtk.
 1.5 11-Dec-1995  pk Adapt to changed mapiodev() interface.
 1.4 19-Jul-1995  brezak Change DEBUG-->AUDIO_DEBUG. PR# port-sparc/1241
 1.3 28-Jun-1995  cgd note that most of dev/ic's contents have changed names
 1.2 04-May-1995  pk Add `evcnt' field.
 1.1 25-Apr-1995  pk New audio driver from Rolf Grossmann.
 1.25.2.4 14-Oct-1997  thorpej Update marc-pcmcia branch from trunk.
 1.25.2.3 01-Sep-1997  thorpej Update marc-pcmcia branch from trunk.
 1.25.2.2 27-Aug-1997  thorpej Update marc-pcmcia branch from trunk.
 1.25.2.1 23-Aug-1997  thorpej Update marc-pcmcia branch from trunk.
 1.33.2.1 09-Dec-1997  thorpej Sync w/ trunk: fix mixer code (chuck)
 1.41.8.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.43.8.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.43.6.1 14-Nov-2001  nathanw Catch up to -current.
 1.44.16.5 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.44.16.4 17-Jan-2005  skrll Sync with HEAD.
 1.44.16.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.44.16.2 18-Sep-2004  skrll Sync with HEAD.
 1.44.16.1 03-Aug-2004  skrll Sync with HEAD
 1.45.2.2 09-Jan-2005  kent audio_hw_if change
* make open() and close() optional
* add int (AUMODE_PLAY or AUMODE_RECORD) and audio_params_t parameters
to round_blocksize()
 1.45.2.1 03-Jan-2005  kent adopt the filter pipeline framework
 1.48.2.1 27-Oct-2007  yamt sync with head.
 1.49.50.1 25-Oct-2007  bouyer Sync with HEAD.
 1.49.46.1 06-Nov-2007  matt sync with HEAD
 1.49.44.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.49.30.1 23-Oct-2007  ad Sync with head.
 1.50.56.2 20-Nov-2011  mrg IPL_SCHED is enough.
 1.50.56.1 20-Nov-2011  mrg port the am7930 drivers to audiomp. sparc and pmax GENERIC builds,
but i am unable to test these drivers.
 1.50.54.1 17-Apr-2012  yamt sync with head
 1.51.26.3 28-Aug-2017  skrll Sync with HEAD
 1.51.26.2 05-Feb-2017  skrll Sync with HEAD
 1.51.26.1 06-Apr-2015  skrll Sync with HEAD
 1.51.8.1 03-Dec-2017  jdolecek update from HEAD
 1.52.2.1 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.53.8.2 01-Aug-2017  snj Pull up following revision(s) (requested by nat in ticket #165):
sys/dev/auconv.c: revision 1.29
sys/dev/auconv.h: revision 1.19
sys/dev/ic/am7930.c: revision 1.56
Add a null_filter to help with the audio autoconfig of pmax.
Tested by flxd@.
 1.53.8.1 30-Jun-2017  snj Pull up following revision(s) (requested by nat in ticket #68):
sys/dev/ic/am7930.c: revision 1.54
sys/dev/ic/am7930.c: revision 1.55
rfill and pfill mixed up.
--
Set hw parameters for linear to ulaw filters.
Tested by flxd@.
 1.57.8.2 04-May-2019  isaki Move dev/audio_if.h -> dev/audio/audio_if.h
 1.57.8.1 22-Apr-2019  isaki Adapt am7930 families to audio2.
- Remove {input/output}_conv stuff from am7930_glue.
Filter pipelines for user encoding are not necessary in audio2
so the driver only needs to handle its hardware encoding.
- audioamd/vsaudio use an ordinal linear-mulaw conversion filter
and bba requires special one. dev/audio/mulaw.c supports this
variant just for bba. It might not a good way for bba but it
keeps all other drivers simple.
- Tested on vsaudio(4) by naru@, bba(4) by tsutsui@ (a few months ago).
Thanks!
 1.57.4.1 10-Jun-2019  christos Sync with HEAD
 1.7 11-Dec-2005  christos merge ktrace-lwp.
 1.6 15-Jan-2005  kent ansify and KNF
 1.5 08-May-2000  mycroft branches: 1.5.28;
Make the SPARC audioamd driver at least *compile*. Well, the C code, that is.
*sigh*
 1.4 02-May-2000  augustss Make am7930 driver machine independent. PR 10032 from Gregory McGarry.
 1.3 14-Mar-1999  jonathan branches: 1.3.8;
Use bus_space tags and handles, embedded in MD hooks AM7930_{READ_WRITE}_REG
to handle MD delay and bus padding. Tested on sparc2 by David Brownlee.

Should use regmaps, but that breaks sparc pDMA assembly code.
 1.2 24-Jun-1998  jonathan Split sparc am7930 driver into sparc attach and "MI" sys/dev/ic/am7930
chipset driver. Needs bus'ifying and register-access.
 1.1 24-Apr-1995  pk AMD9730 telephony chip (used to be sparc/dev/bsd_audioreg.h).
 1.3.8.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.5.28.1 17-Jan-2005  skrll Sync with HEAD.
 1.15 12-Sep-2020  isaki Improve am7930 family drivers to share more code.
audioamd(4) on sparc, vsaudio(4) on vax, and bba(4) are.
- Remove complex and useless callbacks: onopen, onclose, and
indirect_{read,write}. This makes audioamd and vsaudio almost the same.
- Remove (already disabled) assembly fast interrupt path from audioamd(4).
cf. http://mail-index.netbsd.org/source-changes/2009/12/19/msg004585.html
- Use trigger_* method rather than start_* method. It's more suitable.
vsaudio(4) was tested by naru@, bba(4) was tested by tsutsui@.
 1.14 08-May-2019  isaki Merge isaki-audio2 branch, the overhaul of audio subsystem.
- Interrupt-oriented system rather than thread-oriented.
- Improve stability, quality and performance.
- Split playback and record cleanly. Improve halfduplex support.
- Many bugs are fixed including deadlocks, resource leaks, abuses, etc.
- Simplify audio filter mechanism. The encoding/channels/frequency
conversions are completely handled in the upper layer. So the hard-
ware driver only converts its hardware encoding (if necessary).
- audio_hw_if changes:
- Obsoletes query_encoding and add query_format instead.
- Obsoletes set_params and add set_format instead.
- Remove drain, setfd, mappage.
- The call sequences are changed.
- ioctl AUDIO_GETFD/SETFD, AUDIO_GETCHAN/SETCHAN are obsoleted.
- ioctl AUDIO_{QUERY,GET,SET}FORMAT are introduced.
- cleanup config attributes: au*conv and mulaw.
- All hardware drivers should follow it (I've done as much as possible).

Some file paths are changed:
- dev/audio.c -> dev/audio/audio.c (rewritten)
- dev/audiovar.h -> dev/audio/audiovar.h
- dev/audio_dai.h -> dev/audio/audio_dai.h
- dev/audio_if.h -> dev/audio/audio_if.h
- dev/audiobell.c -> dev/audio/audiobell.c
- dev/audiobellvar.h -> dev/audio/audiobellvar.h
- dev/mulaw.[ch] -> dev/audio/mulaw.[ch] + dev/audio/alaw.c
 1.13 23-Nov-2011  jmcneill branches: 1.13.50; 1.13.54;
Merge jmcneill-audiomp3 branch, which is derived from ad-audiomp2. From
the original ad-audiomp branch notes:

Add MP locking to the audio drivers.

Making the audio drivers MP safe is necessary before efforts
can be made to make the VM system MP safe.

The are two locks per device instance, an ISR lock and
a character device lock. The ISR lock replaces calls to
splaudio()/splx(), and will be held across calls to device
methods which were called at splaudio() before (e.g.
trigger_output). The character device lock is held across
calls to nearly all of the methods, excluding some only
used for initialization, e.g. get_locks.

Welcome to 5.99.57.
 1.12 04-Jun-2011  tsutsui branches: 1.12.2; 1.12.4;
Split device_t/softc of am7930. No crash on TME and GXemul.
 1.11 11-Dec-2005  christos branches: 1.11.98; 1.11.104; 1.11.108;
merge ktrace-lwp.
 1.10 15-Jan-2005  kent ansify and KNF
 1.9 10-Jan-2005  kent merge kent-audio1 branch, which introduces audio filter pipeline to the MI
audio framework


Summary of changes:

* struct audio_params
- remove sw_code, factor, factor_denom, hw_sample_rate,
hw_encoding ,hw_precision, and hw_channels. Conversion information
is conveyed by stream_filter_list_t.
- change the type of sample_rate: u_long -> u_int
- add `validbits,' which represents the valid data size in
precision bits. It is required in order to distinguish 24/32bit
from 24/24bit or 32/32bit.

* audio_hw_if
- add two parameters to set_params()
stream_filter_list_t *pfil, stream_filter_list *rfil
A HW driver should set filter recipes for requested formats
- constify audio_params parameters of trigger_output() and
trigger_input(). They represent audio formats for the hardware.
- make open() and close() optional
- add int (AUMODE_PLAY or AUMODE_RECORD) and audio_params_t parameters
to round_blocksize()

* sw_code is replaced with stream_filter_t.
stream_filer_t converts audio data in an input buffer and writes
into another output buffer unlike sw_code, which converts data in
single buffer.
converters in dev/auconv.c, dev/mulaw.c, dev/aurateconv.c,
dev/tc/bba.c, dev/ic/msm6258.c, and arch/arm/iomd/vidcaudio.c are
reimplemented as stream_filter_t

* MI audio
- audiosetinfo() builds filter pipelines from stream_filter_list_t
filled by audio_hw_if::set_params()
- audiosetinfo() returns with EINVAL if mmapped and set_params()
requests filters
- audio_write(), audio_pint(), and audio_rint() invoke a filter
pipeline.
- ioctl() for FIONREAD, AUDIO_WSEEK, AUDIO_GETIOFFS,
AUDIO_GETOOFFS, and audio_prinfo::{seek,samples} for
AUDIO_GETINFO handle values for a buffer nearest to userland.

* add `struct device *' parameter to ac97_attach()

* all of audio HW drivers follow audio_hw_if and ac97 changes
 1.8 09-Jul-2004  mycroft branches: 1.8.2;
Remove junk code.
 1.7 02-May-2000  augustss branches: 1.7.28;
Make am7930 driver machine independent. PR 10032 from Gregory McGarry.
 1.6 14-Mar-1999  jonathan branches: 1.6.8;
Use bus_space tags and handles, embedded in MD hooks AM7930_{READ_WRITE}_REG
to handle MD delay and bus padding. Tested on sparc2 by David Brownlee.

Should use regmaps, but that breaks sparc pDMA assembly code.
 1.5 24-Jun-1998  jonathan Split arch/sparc/dev/amd7930.c into:
* MI sys/dev/ic/{am7930.c,am7930var.h} chipset driver
* sparc frontend.
Presere revision history (this time).

TODO: bus.h'ify, and padded register mappings.
 1.4 19-Oct-1997  augustss Make the audio API (almost) SunOS compatible.
The changes is to allow some limited mixer manipulation through
the audio device (instead of the mixer device).
This rendered 4 methods in audio_hw_if unused so garbage collect these.
 1.3 01-Feb-1996  mycroft LOCORE -> _LOCORE
 1.2 04-May-1995  pk Add `evcnt' field.
 1.1 25-Apr-1995  pk New audio driver from Rolf Grossmann.
 1.6.8.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.7.28.4 17-Jan-2005  skrll Sync with HEAD.
 1.7.28.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.7.28.2 18-Sep-2004  skrll Sync with HEAD.
 1.7.28.1 03-Aug-2004  skrll Sync with HEAD
 1.8.2.2 09-Jan-2005  kent audio_hw_if change
* make open() and close() optional
* add int (AUMODE_PLAY or AUMODE_RECORD) and audio_params_t parameters
to round_blocksize()
 1.8.2.1 03-Jan-2005  kent adopt the filter pipeline framework
 1.11.108.1 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.11.104.1 06-Jun-2011  jruoho Sync with HEAD.
 1.11.98.1 12-Jun-2011  rmind sync with head
 1.12.4.1 20-Nov-2011  mrg port the am7930 drivers to audiomp. sparc and pmax GENERIC builds,
but i am unable to test these drivers.
 1.12.2.1 17-Apr-2012  yamt sync with head
 1.13.54.1 22-Apr-2019  isaki Adapt am7930 families to audio2.
- Remove {input/output}_conv stuff from am7930_glue.
Filter pipelines for user encoding are not necessary in audio2
so the driver only needs to handle its hardware encoding.
- audioamd/vsaudio use an ordinal linear-mulaw conversion filter
and bba requires special one. dev/audio/mulaw.c supports this
variant just for bba. It might not a good way for bba but it
keeps all other drivers simple.
- Tested on vsaudio(4) by naru@, bba(4) by tsutsui@ (a few months ago).
Thanks!
 1.13.50.1 10-Jun-2019  christos Sync with HEAD
 1.84 25-Sep-2022  thorpej Remove unnecessary include of <sys/malloc.h>.
 1.83 20-Oct-2020  roy le(4): add link status change reporting to drivers which support it

Reviewed by thorpej@
Tested by martin@
 1.82 19-Mar-2020  thorpej Don't bother with IFF_OACTIVE. Just keep processing so long as
sc->sc_no_td is less than sc->sc_ntbuf.
 1.81 29-Jan-2020  thorpej Adopt <net/if_stats.h>.
 1.80 28-Nov-2019  isaki branches: 1.80.2;
Use NULL for pointer.
 1.79 26-Jun-2018  msaitoh branches: 1.79.2;
Implement the BPF direction filter (BIOC[GS]DIRECTION). It provides backward
compatibility with BIOC[GS]SEESENT ioctl. The userland interface is the same
as FreeBSD.

This change also fixes a bug that the direction is misunderstand on some
environment by passing the direction to bpf_mtap*() instead of checking
m->m_pkthdr.rcvif.
 1.78 22-Jun-2018  msaitoh It's not required to include net/bpfdesc.h. Remove it.
 1.77 23-May-2017  ozaki-r branches: 1.77.2; 1.77.8;
Fix builds
 1.76 23-May-2017  ozaki-r Apply deferred if_start to more drivers

And annotate some XXX_start as it runs in softint to clarify that
it doesn't need deferred if_start.
 1.75 13-Apr-2015  riastradh Convert sys/dev to use <sys/rndsource.h>.
 1.74 02-Feb-2012  tls branches: 1.74.6; 1.74.24;
Entropy-pool implementation move and cleanup.

1) Move core entropy-pool code and source/sink/sample management code
to sys/kern from sys/dev.

2) Remove use of NRND as test for presence of entropy-pool code throughout
source tree.

3) Remove use of RND_ENABLED in device drivers as microoptimization to
avoid expensive operations on disabled entropy sources; make the
rnd_add calls do this directly so all callers benefit.

4) Fix bug in recent rnd_add_data()/rnd_add_uint32() changes that might
have lead to slight entropy overestimation for some sources.

5) Add new source types for environmental sensors, power sensors, VM
system events, and skew between clocks, with a sample implementation
for each.

ok releng to go in before the branch due to the difficulty of later
pullup (widespread #ifdef removal and moved files). Tested with release
builds on amd64 and evbarm and live testing on amd64.
 1.73 05-Apr-2010  joerg branches: 1.73.8; 1.73.12;
Push the bpf_ops usage back into bpf.h. Push the common ifp->if_bpf
check into the inline functions as well the fourth argument for
bpf_attach.
 1.72 19-Jan-2010  pooka branches: 1.72.2; 1.72.4;
Redefine bpf linkage through an always present op vector, i.e.
#if NBPFILTER is no longer required in the client. This change
doesn't yet add support for loading bpf as a module, since drivers
can register before bpf is attached. However, callers of bpf can
now be modularized.

Dynamically loadable bpf could probably be done fairly easily with
coordination from the stub driver and the real driver by registering
attachments in the stub before the real driver is loaded and doing
a handoff. ... and I'm not going to ponder the depths of unload
here.

Tested with i386/MONOLITHIC, modified MONOLITHIC without bpf and rump.
 1.71 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.70 04-Apr-2008  tsutsui branches: 1.70.2; 1.70.4;
Split device_t/softc for le(4) and variants and misc cosmetic changes.
 1.69 26-Aug-2007  dyoung branches: 1.69.22;
Constify.
 1.68 11-Dec-2005  christos branches: 1.68.30; 1.68.40; 1.68.44;
merge ktrace-lwp.
 1.67 27-Feb-2005  perry branches: 1.67.4;
nuke trailing whitespace
 1.66 24-Aug-2004  thorpej branches: 1.66.4; 1.66.6;
Use ANSI function decls and more use of static.
 1.65 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22364, verified by myself.
 1.64 13-Nov-2001  lukem branches: 1.64.16;
add/cleanup RCSID
 1.63 07-Jul-2001  thorpej branches: 1.63.2;
bcopy -> memcpy
 1.62 30-May-2001  mrg use _KERNEL_OPT
 1.61 14-Dec-2000  thorpej branches: 1.61.2;
ALTQ'ify.
 1.60 28-Sep-2000  tsutsui 6 -> ETHER_ADDR_LEN
 1.59 24-Sep-2000  jdolecek am7990[0]_intr(): only print the "entering with isr=XX" debug message
if compiled with LEDEBUG > 1
 1.58 16-Apr-2000  matt only print packets if debug > 1
 1.57 30-Mar-2000  augustss Remove register declarations.
 1.56 01-Dec-1999  thorpej Quiet down the "excessive collision" messages w/ LEDEBUG. None of the other
Ethernet drivers really report this quite as loudly as this did.
 1.55 29-Oct-1999  ragge DEC specifies that dealing with CSR0 in the interrupt routine must be
done in a special order. Do that here also, but for now inside #ifdef vax
because of the (possible) impact on other arch's.
Now vaxen without IOMMU can use the MI LANCE driver.
 1.54 15-Aug-1998  mycroft branches: 1.54.4; 1.54.12; 1.54.14; 1.54.16;
Assign my copyrights to TNF.
 1.53 08-Aug-1998  mycroft Use splnet, not splimp.
 1.52 24-Jul-1998  drochner remove unneeded typecast
 1.51 21-Jul-1998  drochner Split the LANCE driver into a part specific to the classic chip with
24-bit DMA addresses, and an independant part.
Implement support for the 32-bit mode in the newer (79c9xx) chips.
 1.50 07-Jul-1998  drochner from OpenBSD:
date: 1998/06/24 20:05:03; author: deraadt; state: Exp; lines: +4 -4
initialization error; joel@wmi.com

(affects debug printout only)
 1.49 05-Jul-1998  jonathan defopt NS, NSIP.
 1.48 05-Jul-1998  jonathan defopt LLC
 1.47 05-Jul-1998  jonathan defopt CCITT.
 1.46 05-Jul-1998  jonathan defopt INET, NETATALK.
 1.45 04-Jul-1998  jonathan defopt DDB.
 1.44 07-Jun-1998  fair the AM7990 is a controller, not a "card"; repair a misleading diagnostic.
 1.43 29-Mar-1998  mycroft Oops; make the table const.
 1.42 29-Mar-1998  mycroft Use a 4-bit table to speed up the CRC even further, without increasing the
code size too much.
 1.41 29-Mar-1998  mycroft Optimize the address CRC routines a bit.
 1.40 12-Jan-1998  thorpej Adjust for config changes.
 1.39 15-Oct-1997  gwr Bring back the optimized ether_cmp() that was lost when the
LLADDR() changes went in. Mainly relevant on the Sun3/50,
where LANCE_REVC_BUG has to be defined. Tested on sparc.
 1.38 13-Oct-1997  explorer o Make usage of /dev/random dependant on
pseudo-device rnd # /dev/random and in-kernel generator
in config files.

o Add declaration to all architectures.

o Clean up copyright message in rnd.c, rnd.h, and rndpool.c to include
that this code is derived in part from Ted Tyso's linux code.
 1.37 10-Oct-1997  explorer Add hooks to insert timing info into the random system
 1.36 05-Oct-1997  thorpej Copyright assigned to The NetBSD Foundation.
 1.35 28-Apr-1997  mycroft branches: 1.35.4;
Oops; forgot to GC the last mbuf allocated when out of clusters.
 1.34 25-Apr-1997  jonathan Pad of first mbuf in chain, even if it's a cluster (pr 3536).
Garbage-collect padding of header mbuf.
 1.33 24-Apr-1997  mycroft Fix typo in previous.
 1.32 24-Apr-1997  mycroft Do not force the initial part of a packet into a separate mbuf.
 1.31 24-Apr-1997  mycroft If we fail to allocate a cluster to hold a large packet, simply
drop it rather than using a chain of tiny mbufs.
 1.30 04-Apr-1997  pk Remove alignment requirement of ether_cmp(): turn it into a series of
byte comparisons. Compare the ethernet addresses backwards on the
assumption that address number byte 6 has the most random distribution,
so packets not for us spend the least time in here.
 1.29 27-Mar-1997  veego - new hardware reset hook, mainly for PCnet-ISA cards (79c960)
- new MD variable: sc_initmodemedia, 79c960 cards can select
between two ports, but this needs to be done in the MI init mode page
- new defines for PCnet-ISA cards (79c960)
 1.28 17-Mar-1997  is Signed shifts are evil.
Thanks to Michael Smith for reporting, Jason Thorpe for pointing to the
report, doing a quick workaround which pointed me to the right code part and
for testing the final fix.
 1.27 17-Mar-1997  thorpej - Add support for media selection via if_media. If the front-end
does not supply media types, default to the "manual" type.
- Clean up the ETHER_CMP stuff slightly.
- Keep track of our carrier status, for media status requests.
 1.26 15-Mar-1997  is New ARP system, supports IPv4 over any hardware link.

Some of the stuff (e.g., rarpd, bootpd, dhcpd etc., libsa) still will
only support Ethernet. Tcpdump itself should be ok, but libpcap needs
lot of work.

For the detailed change history, look at the commit log entries for
the is-newarp branch.
 1.25 09-Mar-1997  leo - Turn the sc_[tr]bufaddr fields into arrays of addresses instead of just
the base address. This allows for a more flexible layout of buffers
in the Lance's memory.
- Add a new element 'sc_saved_csr0' to am7990_softc. It's value is or-ed
with the current csr0 value in the am7990_intr() function. This allowes
for a 'deferred' interrupt sceme.
 1.24 06-Dec-1996  pk branches: 1.24.4;
Deal with Lance memory size 132KB (sparc `lebuffer' devices use this size).
 1.23 19-Nov-1996  gwr Use ether_cmp() on the sun3 (for the "le" driver - 3/50, 3/60)
because those have to assume LANCE_REVC_BUG, which causes the
driver to compare Ethernet addresses on every received frame.
 1.22 13-Oct-1996  christos backout kprintf changes
 1.21 10-Oct-1996  christos - printf -> kprintf, sprintf -> ksprintf
 1.20 05-Jul-1996  abrown Add a new function hook sc_nocarrier() to am7990_softc. If non-null, this
function is called when carrier is lost in lieu of a console message.
This is used by the sparc port to switch media types on Sun4m machines
if the appropriate link flags are set by ifconfig (see following commit
message). Should not affect ports that do not use sc_nocarrier().
 1.19 07-May-1996  thorpej Make the MI LANCE driver standalone, and use cfattach to resolve
naming conflicts between bus attachments on ports that can have
multiple instances of the LANCE.

Changed struct ifnet to have a pointer to the softc of the underlying
device and a printable "external name" (name + unit number), thus eliminating
if_name and if_unit. Updated interface to (*if_watchdog)() and (*if_start)()
to take a struct ifnet *, rather than a unit number.
 1.18 22-Apr-1996  christos Add a hardware dependent initialization function lehwinit()
 1.17 18-Apr-1996  cgd change LANCE copy & zero functions' names to start with amd7990_, and
remove their 'integrate' (usually defined to be 'static') keywords.
when lance drivers are split up by attachment, more than one file will
reference the copy/zero functions (i.e. not just the file that pulls in
am7990.c... and eventually inclusion of am7990.c should go away entirely).
 1.16 09-Apr-1996  pk Make this compile if LEDEBUG id defined.
 1.15 08-Apr-1996  jonathan Fixes for -Wall -Wmissing-prototypes:
remove unused variable "xfer" from the copy{to,from}buf_gap2() functions.
 1.14 26-Mar-1996  mycroft Format police.
 1.13 26-Mar-1996  gwr Allow the machine-dependent code to define a fast comparsion function
for ethernet addresses via the macro ETHER_CMP. (see sun3/dev/if_le.c)
Add a comment explaining the LANCE_REVC_BUG work-around section.
 1.12 16-Mar-1996  christos Make operator precedence explicit by parethesizing.
 1.11 14-Mar-1996  christos Bring prototypes into scope.
 1.10 02-Jan-1996  thorpej Back out the rint/tint hook stuff, and remove need to LEINTR_UNIT. The
hp300 was the last to use it.
 1.9 30-Dec-1995  thorpej Add hooks at the top of the tint and rint functions, conditionally called
if the CPP symbols LE_TINT_HOOK and LE_RINT_HOOK are defined, respectively.
The hooks are called by jumping though the sc_tint_hook and sc_rint_hook
members of the softc, and take the softc as an argument. Only ports which
need these hooks need to declare them in the softc.
 1.8 11-Dec-1995  mycroft Make lewatchdog() take an int, not a short.
 1.7 11-Dec-1995  mycroft Fix typo, and eliminate some unneeded local variables.
 1.6 11-Dec-1995  mycroft Make several informational messages #ifdef LEDEBUG.
 1.5 10-Dec-1995  mycroft Change format of probe messages slightly.
Add work-around for LANCE rev. C bug, iff LANCE_REVC_BUG is defined.
 1.4 25-Nov-1995  cgd allow bus-specific lance drivers to use machine-independent buffer/descriptor
copy functions, and convert isa and pmax drivers to do so.
 1.3 24-Jul-1995  mycroft Fix pasto.
 1.2 24-Jul-1995  mycroft Copy changes from ISA version.
 1.1 28-Jun-1995  cgd add charles's mostly-machine-independent lance driver, which is used
by the Alpha port.
 1.24.4.4 12-Mar-1997  is Merge in changes from Trunk
 1.24.4.3 10-Mar-1997  is netinet/if_ether.h => netinet/if_inarp.h
 1.24.4.2 27-Feb-1997  is Clean up a bit. No need to set sc_enaddr from SIOCSIFADDR; nothing reads this
after ether_ifattach().
 1.24.4.1 21-Feb-1997  is Transform to the new world order.
 1.35.4.1 14-Oct-1997  thorpej Update marc-pcmcia branch from trunk.
 1.54.16.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.54.14.1 15-Nov-1999  fvdl Sync with -current
 1.54.12.2 05-Jan-2001  bouyer Sync with HEAD
 1.54.12.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.54.4.1 11-Dec-1998  kenh The beginnings of interface detach support. Still some bugs, but mostly
works for me.

This work was originally by Bill Studenmund, and cleaned up by me.
 1.61.2.3 14-Nov-2001  nathanw Catch up to -current.
 1.61.2.2 24-Aug-2001  nathanw Catch up with -current.
 1.61.2.1 21-Jun-2001  nathanw Catch up to -current.
 1.63.2.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.64.16.5 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.64.16.4 21-Sep-2004  skrll Fix the sync with head I botched.
 1.64.16.3 18-Sep-2004  skrll Sync with HEAD.
 1.64.16.2 25-Aug-2004  skrll Sync with HEAD.
 1.64.16.1 03-Aug-2004  skrll Sync with HEAD
 1.66.6.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.66.4.1 29-Apr-2005  kent sync with -current
 1.67.4.1 03-Sep-2007  yamt sync with head.
 1.68.44.1 03-Sep-2007  jmcneill Sync with HEAD.
 1.68.40.1 03-Sep-2007  skrll Sync with HEAD.
 1.68.30.1 09-Oct-2007  ad Sync with head.
 1.69.22.1 02-Jun-2008  mjf Sync with HEAD.
 1.70.4.3 11-Aug-2010  yamt sync with head.
 1.70.4.2 11-Mar-2010  yamt sync with head
 1.70.4.1 16-May-2008  yamt sync with head.
 1.70.2.1 18-May-2008  yamt sync with head.
 1.72.4.1 30-May-2010  rmind sync with head
 1.72.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.73.12.1 18-Feb-2012  mrg merge to -current.
 1.73.8.1 17-Apr-2012  yamt sync with head
 1.74.24.2 28-Aug-2017  skrll Sync with HEAD
 1.74.24.1 06-Jun-2015  skrll Sync with HEAD
 1.74.6.1 03-Dec-2017  jdolecek update from HEAD
 1.77.8.2 28-Jul-2018  pgoyette Sync with HEAD
 1.77.8.1 25-Jun-2018  pgoyette Sync with HEAD
 1.77.2.1 26-Jul-2018  snj Pull up following revision(s) (requested by msaitoh in ticket #938):
sys/arch/acorn32/podulebus/if_ie.c: revision 1.41
sys/arch/amiga/dev/if_es.c: revision 1.58
sys/arch/amiga/dev/if_qn.c: revision 1.45
sys/arch/arm/at91/at91emac.c: revision 1.20
sys/arch/arm/ep93xx/epe.c: revision 1.37
sys/arch/emips/ebus/if_le_ebus.c: revision 1.14
sys/arch/emips/ebus/if_le_ebus.c: revision 1.15
sys/arch/mac68k/dev/if_mc.c: revision 1.46
sys/arch/macppc/dev/am79c950.c: revision 1.39
sys/arch/newsmips/apbus/if_sn.c: revision 1.40
sys/arch/next68k/dev/mb8795.c: revision 1.59
sys/arch/playstation2/dev/if_smap.c: revision 1.25
sys/arch/playstation2/dev/if_smap.c: revision 1.26
sys/arch/sun2/dev/if_ec.c: revision 1.28
sys/arch/sun3/dev/if_ie.c: revision 1.63
sys/arch/x68k/dev/if_ne_intio.c: revision 1.19
sys/arch/xen/xen/if_xennet_xenbus.c: revision 1.75
sys/arch/xen/xen/xennetback_xenbus.c: revision 1.63
sys/dev/bi/if_ni.c: revision 1.45
sys/dev/cadence/if_cemac.c: revision 1.12
sys/dev/ic/am7990.c: revision 1.78
sys/dev/ic/am79900.c: revision 1.27
sys/dev/ic/an.c: revision 1.67
sys/dev/ic/cs89x0.c: revision 1.40
sys/dev/ic/dm9000.c: revision 1.13
sys/dev/ic/dm9000.c: revision 1.14
sys/dev/ic/dp8390.c: revision 1.88
sys/dev/ic/elink3.c: revision 1.141
sys/dev/ic/elinkxl.c: revision 1.122
sys/dev/ic/hme.c: revision 1.98
sys/dev/ic/i82586.c: revision 1.77
sys/dev/ic/lance.c: revision 1.53
sys/dev/ic/mb86950.c: revision 1.27
sys/dev/ic/mb86960.c: revision 1.86
sys/dev/ic/mtd803.c: revision 1.34
sys/dev/ic/pdq_ifsubr.c: revision 1.59
sys/dev/ic/rrunner.c: revision 1.86
sys/dev/ic/seeq8005.c: revision 1.58
sys/dev/ic/sgec.c: revision 1.47
sys/dev/ic/smc90cx6.c: revision 1.72
sys/dev/ic/smc91cxx.c: revision 1.96
sys/dev/ic/tropic.c: revision 1.49
sys/dev/ic/wi.c: revision 1.245
sys/dev/isa/if_eg.c: revision 1.93
sys/dev/isa/if_el.c: revision 1.95
sys/dev/isa/if_iy.c: revision 1.101
sys/dev/ofw/ofnet.c: revision 1.58
sys/dev/pci/if_alc.c: revision 1.27
sys/dev/pci/if_de.c: revision 1.152
sys/dev/pci/if_fpa.c: revision 1.61
sys/dev/pci/if_jme.c: revision 1.34
sys/dev/pci/if_tl.c: revision 1.108
sys/dev/pci/if_vte.c: revision 1.19
sys/dev/pci/ixgbe/ixgbe.h: revision 1.50
sys/dev/pcmcia/if_cnw.c: revision 1.62
sys/dev/pcmcia/if_malo_pcmcia.c: revision 1.17
sys/dev/pcmcia/if_ray.c: revision 1.89
sys/dev/pcmcia/if_xi.c: revision 1.81
sys/dev/pcmcia/mhzc.c: revision 1.51
sys/dev/pcmcia/xirc.c: revision 1.34
sys/dev/qbus/if_de.c: revision 1.33
sys/dev/qbus/if_qe.c: revision 1.78
sys/dev/qbus/if_qt.c: revision 1.22
sys/dev/sbus/be.c: revision 1.87
sys/dev/sbus/qe.c: revision 1.68
sys/dev/scsipi/if_se.c: revision 1.96
sys/dev/usb/if_atu.c: revision 1.59
sys/net/if_l2tp.c: revision 1.28 via patch
sys/net/if_ppp.c: revision 1.160
It's not required to include net/bpfdesc.h. Remove it.
--
Simplify like other drivers. NULL check of ifp->if_bpf is done in
bpf_mtap(), so it's not required to do it here.
--
Remove duplicated inclusion of net/bpf.h.
--
Remove duplicated inclusion of net/bpf.h.
--
Simplify bpf_mtap() call. No functional change.
 1.79.2.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.80.2.1 29-Feb-2020  ad Sync with head.
 1.2 28-Jun-1995  cgd these have moved to more appropriate names
 1.1 11-Apr-1995  mycroft LANCE register definitions, plus some utility macros for the machine-
independent driver.
 1.32 25-Sep-2022  thorpej Remove unnecessary include of <sys/malloc.h>.
 1.31 20-Oct-2020  roy le(4): add link status change reporting to drivers which support it

Reviewed by thorpej@
Tested by martin@
 1.30 19-Mar-2020  thorpej Don't bother with IFF_OACTIVE. Just keep processing so long as
sc->sc_no_td is less than sc->sc_ntbuf.
 1.29 04-Feb-2020  skrll Adopt <net/if_stats.h>
 1.28 26-Jun-2018  msaitoh branches: 1.28.2; 1.28.10;
Implement the BPF direction filter (BIOC[GS]DIRECTION). It provides backward
compatibility with BIOC[GS]SEESENT ioctl. The userland interface is the same
as FreeBSD.

This change also fixes a bug that the direction is misunderstand on some
environment by passing the direction to bpf_mtap*() instead of checking
m->m_pkthdr.rcvif.
 1.27 22-Jun-2018  msaitoh It's not required to include net/bpfdesc.h. Remove it.
 1.26 23-May-2017  ozaki-r branches: 1.26.2; 1.26.8;
Fix builds
 1.25 23-May-2017  ozaki-r Apply deferred if_start to more drivers

And annotate some XXX_start as it runs in softint to clarify that
it doesn't need deferred if_start.
 1.24 13-Apr-2015  riastradh Convert sys/dev to use <sys/rndsource.h>.
 1.23 02-Feb-2012  tls branches: 1.23.6; 1.23.24;
Entropy-pool implementation move and cleanup.

1) Move core entropy-pool code and source/sink/sample management code
to sys/kern from sys/dev.

2) Remove use of NRND as test for presence of entropy-pool code throughout
source tree.

3) Remove use of RND_ENABLED in device drivers as microoptimization to
avoid expensive operations on disabled entropy sources; make the
rnd_add calls do this directly so all callers benefit.

4) Fix bug in recent rnd_add_data()/rnd_add_uint32() changes that might
have lead to slight entropy overestimation for some sources.

5) Add new source types for environmental sensors, power sensors, VM
system events, and skew between clocks, with a sample implementation
for each.

ok releng to go in before the branch due to the difficulty of later
pullup (widespread #ifdef removal and moved files). Tested with release
builds on amd64 and evbarm and live testing on amd64.
 1.22 05-Apr-2010  joerg branches: 1.22.8; 1.22.12;
Push the bpf_ops usage back into bpf.h. Push the common ifp->if_bpf
check into the inline functions as well the fourth argument for
bpf_attach.
 1.21 19-Jan-2010  pooka branches: 1.21.2; 1.21.4;
Redefine bpf linkage through an always present op vector, i.e.
#if NBPFILTER is no longer required in the client. This change
doesn't yet add support for loading bpf as a module, since drivers
can register before bpf is attached. However, callers of bpf can
now be modularized.

Dynamically loadable bpf could probably be done fairly easily with
coordination from the stub driver and the real driver by registering
attachments in the stub before the real driver is loaded and doing
a handoff. ... and I'm not going to ponder the depths of unload
here.

Tested with i386/MONOLITHIC, modified MONOLITHIC without bpf and rump.
 1.20 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.19 04-Apr-2008  tsutsui branches: 1.19.2; 1.19.4;
Split device_t/softc for le(4) and variants and misc cosmetic changes.
 1.18 26-Aug-2007  dyoung branches: 1.18.22;
Constify.
 1.17 24-Dec-2005  perry branches: 1.17.30; 1.17.40; 1.17.44;
Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.16 11-Dec-2005  christos merge ktrace-lwp.
 1.15 27-Feb-2005  perry branches: 1.15.4;
nuke trailing whitespace
 1.14 24-Aug-2004  thorpej branches: 1.14.4; 1.14.6;
Use ANSI function decls and more use of static.
 1.13 24-Mar-2004  thorpej My copyright on this file is assigned to TNF.
 1.12 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22364, verified by myself.
 1.11 13-Nov-2001  lukem branches: 1.11.16;
add/cleanup RCSID
 1.10 07-Jul-2001  thorpej branches: 1.10.2;
bcopy -> memcpy
 1.9 30-May-2001  mrg use _KERNEL_OPT
 1.8 14-Dec-2000  thorpej branches: 1.8.2;
ALTQ'ify.
 1.7 28-Sep-2000  tsutsui 6 -> ETHER_ADDR_LEN
 1.6 24-Sep-2000  jdolecek am7990[0]_intr(): only print the "entering with isr=XX" debug message
if compiled with LEDEBUG > 1
 1.5 30-Mar-2000  augustss Remove register declarations.
 1.4 01-Dec-1999  thorpej Quiet down the "excessive collision" messages w/ LEDEBUG. None of the other
Ethernet drivers really report this quite as loudly as this did.
 1.3 08-Aug-1998  mycroft branches: 1.3.4; 1.3.12; 1.3.18;
Use splnet, not splimp.
 1.2 24-Jul-1998  drochner add random generator hook
 1.1 21-Jul-1998  drochner Split the LANCE driver into a part specific to the classic chip with
24-bit DMA addresses, and an independant part.
Implement support for the 32-bit mode in the newer (79c9xx) chips.
 1.3.18.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.3.12.2 05-Jan-2001  bouyer Sync with HEAD
 1.3.12.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.3.4.1 11-Dec-1998  kenh The beginnings of interface detach support. Still some bugs, but mostly
works for me.

This work was originally by Bill Studenmund, and cleaned up by me.
 1.8.2.3 14-Nov-2001  nathanw Catch up to -current.
 1.8.2.2 24-Aug-2001  nathanw Catch up with -current.
 1.8.2.1 21-Jun-2001  nathanw Catch up to -current.
 1.10.2.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.11.16.5 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.11.16.4 21-Sep-2004  skrll Fix the sync with head I botched.
 1.11.16.3 18-Sep-2004  skrll Sync with HEAD.
 1.11.16.2 25-Aug-2004  skrll Sync with HEAD.
 1.11.16.1 03-Aug-2004  skrll Sync with HEAD
 1.14.6.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.14.4.1 29-Apr-2005  kent sync with -current
 1.15.4.2 03-Sep-2007  yamt sync with head.
 1.15.4.1 21-Jun-2006  yamt sync with head.
 1.17.44.1 03-Sep-2007  jmcneill Sync with HEAD.
 1.17.40.1 03-Sep-2007  skrll Sync with HEAD.
 1.17.30.1 09-Oct-2007  ad Sync with head.
 1.18.22.1 02-Jun-2008  mjf Sync with HEAD.
 1.19.4.3 11-Aug-2010  yamt sync with head.
 1.19.4.2 11-Mar-2010  yamt sync with head
 1.19.4.1 16-May-2008  yamt sync with head.
 1.19.2.1 18-May-2008  yamt sync with head.
 1.21.4.1 30-May-2010  rmind sync with head
 1.21.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.22.12.1 18-Feb-2012  mrg merge to -current.
 1.22.8.1 17-Apr-2012  yamt sync with head
 1.23.24.2 28-Aug-2017  skrll Sync with HEAD
 1.23.24.1 06-Jun-2015  skrll Sync with HEAD
 1.23.6.1 03-Dec-2017  jdolecek update from HEAD
 1.26.8.2 28-Jul-2018  pgoyette Sync with HEAD
 1.26.8.1 25-Jun-2018  pgoyette Sync with HEAD
 1.26.2.1 26-Jul-2018  snj Pull up following revision(s) (requested by msaitoh in ticket #938):
sys/arch/acorn32/podulebus/if_ie.c: revision 1.41
sys/arch/amiga/dev/if_es.c: revision 1.58
sys/arch/amiga/dev/if_qn.c: revision 1.45
sys/arch/arm/at91/at91emac.c: revision 1.20
sys/arch/arm/ep93xx/epe.c: revision 1.37
sys/arch/emips/ebus/if_le_ebus.c: revision 1.14
sys/arch/emips/ebus/if_le_ebus.c: revision 1.15
sys/arch/mac68k/dev/if_mc.c: revision 1.46
sys/arch/macppc/dev/am79c950.c: revision 1.39
sys/arch/newsmips/apbus/if_sn.c: revision 1.40
sys/arch/next68k/dev/mb8795.c: revision 1.59
sys/arch/playstation2/dev/if_smap.c: revision 1.25
sys/arch/playstation2/dev/if_smap.c: revision 1.26
sys/arch/sun2/dev/if_ec.c: revision 1.28
sys/arch/sun3/dev/if_ie.c: revision 1.63
sys/arch/x68k/dev/if_ne_intio.c: revision 1.19
sys/arch/xen/xen/if_xennet_xenbus.c: revision 1.75
sys/arch/xen/xen/xennetback_xenbus.c: revision 1.63
sys/dev/bi/if_ni.c: revision 1.45
sys/dev/cadence/if_cemac.c: revision 1.12
sys/dev/ic/am7990.c: revision 1.78
sys/dev/ic/am79900.c: revision 1.27
sys/dev/ic/an.c: revision 1.67
sys/dev/ic/cs89x0.c: revision 1.40
sys/dev/ic/dm9000.c: revision 1.13
sys/dev/ic/dm9000.c: revision 1.14
sys/dev/ic/dp8390.c: revision 1.88
sys/dev/ic/elink3.c: revision 1.141
sys/dev/ic/elinkxl.c: revision 1.122
sys/dev/ic/hme.c: revision 1.98
sys/dev/ic/i82586.c: revision 1.77
sys/dev/ic/lance.c: revision 1.53
sys/dev/ic/mb86950.c: revision 1.27
sys/dev/ic/mb86960.c: revision 1.86
sys/dev/ic/mtd803.c: revision 1.34
sys/dev/ic/pdq_ifsubr.c: revision 1.59
sys/dev/ic/rrunner.c: revision 1.86
sys/dev/ic/seeq8005.c: revision 1.58
sys/dev/ic/sgec.c: revision 1.47
sys/dev/ic/smc90cx6.c: revision 1.72
sys/dev/ic/smc91cxx.c: revision 1.96
sys/dev/ic/tropic.c: revision 1.49
sys/dev/ic/wi.c: revision 1.245
sys/dev/isa/if_eg.c: revision 1.93
sys/dev/isa/if_el.c: revision 1.95
sys/dev/isa/if_iy.c: revision 1.101
sys/dev/ofw/ofnet.c: revision 1.58
sys/dev/pci/if_alc.c: revision 1.27
sys/dev/pci/if_de.c: revision 1.152
sys/dev/pci/if_fpa.c: revision 1.61
sys/dev/pci/if_jme.c: revision 1.34
sys/dev/pci/if_tl.c: revision 1.108
sys/dev/pci/if_vte.c: revision 1.19
sys/dev/pci/ixgbe/ixgbe.h: revision 1.50
sys/dev/pcmcia/if_cnw.c: revision 1.62
sys/dev/pcmcia/if_malo_pcmcia.c: revision 1.17
sys/dev/pcmcia/if_ray.c: revision 1.89
sys/dev/pcmcia/if_xi.c: revision 1.81
sys/dev/pcmcia/mhzc.c: revision 1.51
sys/dev/pcmcia/xirc.c: revision 1.34
sys/dev/qbus/if_de.c: revision 1.33
sys/dev/qbus/if_qe.c: revision 1.78
sys/dev/qbus/if_qt.c: revision 1.22
sys/dev/sbus/be.c: revision 1.87
sys/dev/sbus/qe.c: revision 1.68
sys/dev/scsipi/if_se.c: revision 1.96
sys/dev/usb/if_atu.c: revision 1.59
sys/net/if_l2tp.c: revision 1.28 via patch
sys/net/if_ppp.c: revision 1.160
It's not required to include net/bpfdesc.h. Remove it.
--
Simplify like other drivers. NULL check of ifp->if_bpf is done in
bpf_mtap(), so it's not required to do it here.
--
Remove duplicated inclusion of net/bpf.h.
--
Remove duplicated inclusion of net/bpf.h.
--
Simplify bpf_mtap() call. No functional change.
 1.28.10.1 29-Feb-2020  ad Sync with head.
 1.28.2.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.10 11-Oct-2019  msaitoh Use unsigned to avoid undefined behavior. Found by kUBSan.
 1.9 28-Apr-2008  martin branches: 1.9.88; 1.9.94;
Remove clause 3 and 4 from TNF licenses
 1.8 11-Dec-2005  christos branches: 1.8.70; 1.8.72; 1.8.74;
merge ktrace-lwp.
 1.7 27-Feb-2005  perry nuke trailing whitespace
 1.6 02-Nov-2003  wiz branches: 1.6.8; 1.6.10;
Fix some typos. From Tom Cosgrove via jmc@openbsd.
 1.5 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22364, verified by myself.
 1.4 24-Aug-2001  thorpej branches: 1.4.20;
Oops, TMD/RMD byte count masks were one bit shy (and it makes a big
difference when the value in the field is actually the two's complement
of the buffer length).
 1.3 21-Aug-2001  thorpej More PCnet-PCI/ILACC bits.
 1.2 15-Aug-1998  mycroft branches: 1.2.24; 1.2.26;
Assign my copyrights to TNF.
 1.1 21-Jul-1998  drochner Split the LANCE driver into a part specific to the classic chip with
24-bit DMA addresses, and an independant part.
Implement support for the 32-bit mode in the newer (79c9xx) chips.
 1.2.26.1 25-Aug-2001  thorpej Merge Aug 24 -current into the kqueue branch.
 1.2.24.2 21-Sep-2001  nathanw Catch up to -current.
 1.2.24.1 24-Aug-2001  nathanw Catch up with -current.
 1.4.20.4 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.4.20.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.4.20.2 18-Sep-2004  skrll Sync with HEAD.
 1.4.20.1 03-Aug-2004  skrll Sync with HEAD
 1.6.10.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.6.8.1 29-Apr-2005  kent sync with -current
 1.8.74.1 16-May-2008  yamt sync with head.
 1.8.72.1 18-May-2008  yamt sync with head.
 1.8.70.1 02-Jun-2008  mjf Sync with HEAD.
 1.9.94.1 31-Jan-2020  martin Pull up following revision(s) (requested by msaitoh in ticket #671):

sys/dev/pci/if_bce.c: revision 1.53
sys/dev/pci/pccbbreg.h: revision 1.16
sys/dev/ic/rt2860.c: revision 1.34
sys/dev/pci/if_alc.c: revision 1.45
sys/dev/pci/if_mcx.c: revision 1.5
sys/dev/pci/if_pcn.c: revision 1.72
sys/dev/pci/if_ale.c: revision 1.37
sys/dev/pci/if_age.c: revision 1.65
sys/dev/ieee1394/fwohcireg.h: revision 1.20
sys/dev/ieee1394/fwohci.c: revision 1.143
sys/dev/ieee1394/firewire.c: revision 1.49
sys/dev/ic/am79900reg.h: revision 1.10

Use unsigned to avoid undefined behavior. Found by kUBSan.
 1.9.88.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.5 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.4 11-Dec-2005  christos branches: 1.4.70; 1.4.72; 1.4.74;
merge ktrace-lwp.
 1.3 24-Aug-2004  thorpej Use ANSI function decls and more use of static.
 1.2 15-Aug-1998  mycroft branches: 1.2.46;
Assign my copyrights to TNF.
 1.1 21-Jul-1998  drochner Split the LANCE driver into a part specific to the classic chip with
24-bit DMA addresses, and an independant part.
Implement support for the 32-bit mode in the newer (79c9xx) chips.
 1.2.46.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.2.46.2 18-Sep-2004  skrll Sync with HEAD.
 1.2.46.1 25-Aug-2004  skrll Sync with HEAD.
 1.4.74.1 16-May-2008  yamt sync with head.
 1.4.72.1 18-May-2008  yamt sync with head.
 1.4.70.1 02-Jun-2008  mjf Sync with HEAD.
 1.13 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.12 25-Dec-2007  perry branches: 1.12.6; 1.12.8; 1.12.10;
Convert many of the uses of __attribute__ to equivalent
__packed, __unused and __dead macros from cdefs.h
 1.11 11-Dec-2005  christos branches: 1.11.46; 1.11.52; 1.11.56; 1.11.60;
merge ktrace-lwp.
 1.10 27-Feb-2005  perry branches: 1.10.4;
nuke trailing whitespace
 1.9 17-Feb-2005  tsutsui Add __attribute__((__packed__)) to DMA descriptor declarations.
 1.8 02-Nov-2003  wiz branches: 1.8.8; 1.8.10;
Fix some typos. From Tom Cosgrove via jmc@openbsd.
 1.7 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22364, verified by myself.
 1.6 15-Aug-1998  mycroft branches: 1.6.46;
Assign my copyrights to TNF.
 1.5 21-Jul-1998  drochner Split the LANCE driver into a part specific to the classic chip with
24-bit DMA addresses, and an independant part.
Implement support for the 32-bit mode in the newer (79c9xx) chips.
 1.4 27-Mar-1997  veego - new hardware reset hook, mainly for PCnet-ISA cards (79c960)
- new MD variable: sc_initmodemedia, 79c960 cards can select
between two ports, but this needs to be done in the MI init mode page
- new defines for PCnet-ISA cards (79c960)
 1.3 15-Mar-1997  is New ARP system, supports IPv4 over any hardware link.

Some of the stuff (e.g., rarpd, bootpd, dhcpd etc., libsa) still will
only support Ethernet. Tcpdump itself should be ok, but libpcap needs
lot of work.

For the detailed change history, look at the commit log entries for
the is-newarp branch.
 1.2 09-Mar-1997  leo - Turn the sc_[tr]bufaddr fields into arrays of addresses instead of just
the base address. This allows for a more flexible layout of buffers
in the Lance's memory.
- Add a new element 'sc_saved_csr0' to am7990_softc. It's value is or-ed
with the current csr0 value in the am7990_intr() function. This allowes
for a 'deferred' interrupt sceme.
 1.1 11-Apr-1995  mycroft branches: 1.1.8;
LANCE register definitions, plus some utility macros for the machine-
independent driver.
 1.1.8.1 12-Mar-1997  is Merge in changes from Trunk
 1.6.46.4 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.6.46.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.6.46.2 18-Sep-2004  skrll Sync with HEAD.
 1.6.46.1 03-Aug-2004  skrll Sync with HEAD
 1.8.10.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.8.8.1 29-Apr-2005  kent sync with -current
 1.10.4.1 21-Jan-2008  yamt sync with head
 1.11.60.1 02-Jan-2008  bouyer Sync with HEAD
 1.11.56.1 26-Dec-2007  ad Sync with head.
 1.11.52.1 18-Feb-2008  mjf Sync with HEAD.
 1.11.46.1 09-Jan-2008  matt sync with HEAD
 1.12.10.1 16-May-2008  yamt sync with head.
 1.12.8.1 18-May-2008  yamt sync with head.
 1.12.6.1 02-Jun-2008  mjf Sync with HEAD.
 1.24 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.23 11-Dec-2005  christos branches: 1.23.70; 1.23.72; 1.23.74;
merge ktrace-lwp.
 1.22 24-Aug-2004  thorpej Use ANSI function decls and more use of static.
 1.21 15-Aug-1998  mycroft branches: 1.21.46;
Assign my copyrights to TNF.
 1.20 21-Jul-1998  drochner Split the LANCE driver into a part specific to the classic chip with
24-bit DMA addresses, and an independant part.
Implement support for the 32-bit mode in the newer (79c9xx) chips.
 1.19 04-Jul-1998  jonathan defopt DDB.
 1.18 12-Jan-1998  thorpej Adjust for config changes.
 1.17 15-Oct-1997  explorer minor formatting change
 1.16 13-Oct-1997  explorer o Make usage of /dev/random dependant on
pseudo-device rnd # /dev/random and in-kernel generator
in config files.

o Add declaration to all architectures.

o Clean up copyright message in rnd.c, rnd.h, and rndpool.c to include
that this code is derived in part from Ted Tyso's linux code.
 1.15 10-Oct-1997  explorer Add hooks to insert timing info into the random system
 1.14 05-Oct-1997  thorpej Copyright assigned to The NetBSD Foundation.
 1.13 27-Mar-1997  veego branches: 1.13.4;
- new hardware reset hook, mainly for PCnet-ISA cards (79c960)
- new MD variable: sc_initmodemedia, 79c960 cards can select
between two ports, but this needs to be done in the MI init mode page
- new defines for PCnet-ISA cards (79c960)
 1.12 17-Mar-1997  thorpej - Add support for media selection via if_media. If the front-end
does not supply media types, default to the "manual" type.
- Clean up the ETHER_CMP stuff slightly.
- Keep track of our carrier status, for media status requests.
 1.11 15-Mar-1997  is New ARP system, supports IPv4 over any hardware link.

Some of the stuff (e.g., rarpd, bootpd, dhcpd etc., libsa) still will
only support Ethernet. Tcpdump itself should be ok, but libpcap needs
lot of work.

For the detailed change history, look at the commit log entries for
the is-newarp branch.
 1.10 09-Mar-1997  leo - Turn the sc_[tr]bufaddr fields into arrays of addresses instead of just
the base address. This allows for a more flexible layout of buffers
in the Lance's memory.
- Add a new element 'sc_saved_csr0' to am7990_softc. It's value is or-ed
with the current csr0 value in the am7990_intr() function. This allowes
for a 'deferred' interrupt sceme.
 1.9 15-Jan-1997  gwr branches: 1.9.2;
fix alignment again for m68k
 1.8 05-Jul-1996  abrown branches: 1.8.2;
Add a new function hook sc_nocarrier() to am7990_softc. If non-null, this
function is called when carrier is lost in lieu of a console message.
This is used by the sparc port to switch media types on Sun4m machines
if the appropriate link flags are set by ifconfig (see following commit
message). Should not affect ports that do not use sc_nocarrier().
 1.7 07-May-1996  thorpej Make the MI LANCE driver standalone, and use cfattach to resolve
naming conflicts between bus attachments on ports that can have
multiple instances of the LANCE.

Changed struct ifnet to have a pointer to the softc of the underlying
device and a printable "external name" (name + unit number), thus eliminating
if_name and if_unit. Updated interface to (*if_watchdog)() and (*if_start)()
to take a struct ifnet *, rather than a unit number.
 1.6 22-Apr-1996  christos Add a hardware dependent initialization function lehwinit()
 1.5 18-Apr-1996  cgd change LANCE copy & zero functions' names to start with amd7990_, and
remove their 'integrate' (usually defined to be 'static') keywords.
when lance drivers are split up by attachment, more than one file will
reference the copy/zero functions (i.e. not just the file that pulls in
am7990.c... and eventually inclusion of am7990.c should go away entirely).
 1.4 14-Mar-1996  christos Bring prototypes into scope.
 1.3 11-Dec-1995  mycroft Make lewatchdog() take an int, not a short.
 1.2 25-Nov-1995  cgd allow bus-specific lance drivers to use machine-independent buffer/descriptor
copy functions, and convert isa and pmax drivers to do so.
 1.1 28-Jun-1995  cgd add charles's mostly-machine-independent lance driver, which is used
by the Alpha port.
 1.8.2.1 18-Jan-1997  thorpej Update from trunk.
 1.9.2.2 12-Mar-1997  is Merge in changes from Trunk
 1.9.2.1 21-Feb-1997  is Transform to the new world order.
 1.13.4.1 14-Oct-1997  thorpej Update marc-pcmcia branch from trunk.
 1.21.46.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.21.46.2 18-Sep-2004  skrll Sync with HEAD.
 1.21.46.1 25-Aug-2004  skrll Sync with HEAD.
 1.23.74.1 16-May-2008  yamt sync with head.
 1.23.72.1 18-May-2008  yamt sync with head.
 1.23.70.1 02-Jun-2008  mjf Sync with HEAD.
 1.16 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.15 19-Oct-2007  ad branches: 1.15.16; 1.15.18; 1.15.20;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.14 11-Dec-2005  christos branches: 1.14.30; 1.14.44; 1.14.46; 1.14.50;
merge ktrace-lwp.
 1.13 27-Feb-2005  perry branches: 1.13.4;
nuke trailing whitespace
 1.12 11-Mar-2004  jmc branches: 1.12.8; 1.12.10;
Provide standard workaround for \!defined __BUS_SPACE_HAS_STREAM_METHODS
 1.11 08-Mar-2004  dyoung Fix endianness bug to make awi(4) work on macppc (and other big-endian
machines).
 1.10 13-Feb-2004  dyoung KNF. Change

static
void mem_write_2(...)

to

static void
mem_write_2(...)
 1.9 15-Jan-2004  onoe ANSIfy.
 1.8 04-Oct-2003  dyoung For memory-mapped access, get the endianness right on big-endian
hosts. This makes awi work marginally better (although it's still
broken) on my Powerbook.
 1.7 13-Nov-2001  lukem branches: 1.7.16;
add/cleanup RCSID
 1.6 04-Jul-2000  onoe branches: 1.6.2; 1.6.4; 1.6.6;
Remove unneeded include <sys/kernel.h> from FreeBSD by <phk@freebsd.org>
 1.5 23-Mar-2000  onoe While am79c930 controller allows unaligned access, bus_space_read/write
must be aligned. So awi_read/write_2/4 issues multiple bsr1/bsw1 when
unaligned.
 1.4 22-Mar-2000  onoe Update awi driver, which now supports AMD 79c930 based 802.11 DS cards
as well as 802.11 FH cards. Also, it can operate in infrastructure mode,
adhoc mode, and wi(4) (aka WaveLAN/IEEE) compatible adhoc mode.
 1.3 17-Feb-2000  sommerfeld awi: rewrite to be higher performance.
 1.2 05-Nov-1999  sommerfeld branches: 1.2.2; 1.2.4; 1.2.6;
Add rcsid's
 1.1 04-Nov-1999  sommerfeld Minimally functional driver for the am79c930 802.11 controller chip).
Working well enough to support dhcp; i'm doing this commit using the
interface.

Supports FH only. Does not yet do ad-hoc mode; works in
infrastructure mode. Not yet tested in environments with multiple
access points.
 1.2.6.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.2.4.2 15-Nov-1999  fvdl Sync with -current
 1.2.4.1 05-Nov-1999  fvdl file am79c930.c was added on branch fvdl-softdep on 1999-11-15 00:40:25 +0000
 1.2.2.2 05-Nov-1999  sommerfeld Add rcsid's
 1.2.2.1 05-Nov-1999  sommerfeld file am79c930.c was added on branch comdex-fall-1999 on 1999-11-05 05:13:37 +0000
 1.6.6.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.6.4.1 14-Nov-2001  nathanw Catch up to -current.
 1.6.2.2 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.6.2.1 04-Jul-2000  bouyer file am79c930.c was added on branch thorpej_scsipi on 2000-11-20 11:40:21 +0000
 1.7.16.4 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.7.16.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.7.16.2 18-Sep-2004  skrll Sync with HEAD.
 1.7.16.1 03-Aug-2004  skrll Sync with HEAD
 1.12.10.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.12.8.1 29-Apr-2005  kent sync with -current
 1.13.4.1 27-Oct-2007  yamt sync with head.
 1.14.50.1 25-Oct-2007  bouyer Sync with HEAD.
 1.14.46.1 06-Nov-2007  matt sync with HEAD
 1.14.44.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.14.30.1 23-Oct-2007  ad Sync with head.
 1.15.20.1 16-May-2008  yamt sync with head.
 1.15.18.1 18-May-2008  yamt sync with head.
 1.15.16.1 02-Jun-2008  mjf Sync with HEAD.
 1.9 18-Aug-2025  andvar Fix various typos, mainly in comments:
s/invaid/invalid/
s/instad/instead/
s/wich/with/
s/tranform/transform/
s/tranmist/transmit/
s/tranceiver/transceiver/
s/Tranparent/Transparent/
s/tranlated/translated/
s/tranfer/transfer/
s/tranmissions/transmissions/
s/condtions/conditions/
s/Recient/Recent/
 1.8 05-Dec-2021  msaitoh s/from from/from/ in comment.
 1.7 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.6 11-Dec-2005  christos branches: 1.6.70; 1.6.72; 1.6.74;
merge ktrace-lwp.
 1.5 27-Feb-2005  perry nuke trailing whitespace
 1.4 02-Nov-2003  wiz branches: 1.4.8; 1.4.10;
Fix some typos. From Tom Cosgrove via jmc@openbsd.
 1.3 22-Mar-2000  onoe branches: 1.3.6; 1.3.30;
Update awi driver, which now supports AMD 79c930 based 802.11 DS cards
as well as 802.11 FH cards. Also, it can operate in infrastructure mode,
adhoc mode, and wi(4) (aka WaveLAN/IEEE) compatible adhoc mode.
 1.2 05-Nov-1999  sommerfeld branches: 1.2.2; 1.2.4; 1.2.6;
Add rcsid's
 1.1 04-Nov-1999  sommerfeld Minimally functional driver for the am79c930 802.11 controller chip).
Working well enough to support dhcp; i'm doing this commit using the
interface.

Supports FH only. Does not yet do ad-hoc mode; works in
infrastructure mode. Not yet tested in environments with multiple
access points.
 1.2.6.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.2.4.2 15-Nov-1999  fvdl Sync with -current
 1.2.4.1 05-Nov-1999  fvdl file am79c930reg.h was added on branch fvdl-softdep on 1999-11-15 00:40:26 +0000
 1.2.2.2 05-Nov-1999  sommerfeld Add rcsid's
 1.2.2.1 05-Nov-1999  sommerfeld file am79c930reg.h was added on branch comdex-fall-1999 on 1999-11-05 05:13:37 +0000
 1.3.30.4 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.3.30.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.3.30.2 18-Sep-2004  skrll Sync with HEAD.
 1.3.30.1 03-Aug-2004  skrll Sync with HEAD
 1.3.6.2 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.3.6.1 22-Mar-2000  bouyer file am79c930reg.h was added on branch thorpej_scsipi on 2000-11-20 11:40:22 +0000
 1.4.10.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.4.8.1 29-Apr-2005  kent sync with -current
 1.6.74.1 16-May-2008  yamt sync with head.
 1.6.72.1 18-May-2008  yamt sync with head.
 1.6.70.1 02-Jun-2008  mjf Sync with HEAD.
 1.6 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.5 11-Dec-2005  christos branches: 1.5.70; 1.5.72; 1.5.74;
merge ktrace-lwp.
 1.4 27-Feb-2005  perry nuke trailing whitespace
 1.3 15-Jan-2004  onoe branches: 1.3.8; 1.3.10;
ANSIfy.
 1.2 05-Nov-1999  sommerfeld branches: 1.2.2; 1.2.4; 1.2.6; 1.2.12; 1.2.36;
Add rcsid's
 1.1 04-Nov-1999  sommerfeld Minimally functional driver for the am79c930 802.11 controller chip).
Working well enough to support dhcp; i'm doing this commit using the
interface.

Supports FH only. Does not yet do ad-hoc mode; works in
infrastructure mode. Not yet tested in environments with multiple
access points.
 1.2.36.4 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.2.36.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.2.36.2 18-Sep-2004  skrll Sync with HEAD.
 1.2.36.1 03-Aug-2004  skrll Sync with HEAD
 1.2.12.2 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.2.12.1 05-Nov-1999  bouyer file am79c930var.h was added on branch thorpej_scsipi on 2000-11-20 11:40:22 +0000
 1.2.6.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.2.4.2 15-Nov-1999  fvdl Sync with -current
 1.2.4.1 05-Nov-1999  fvdl file am79c930var.h was added on branch fvdl-softdep on 1999-11-15 00:40:26 +0000
 1.2.2.2 05-Nov-1999  sommerfeld Add rcsid's
 1.2.2.1 05-Nov-1999  sommerfeld file am79c930var.h was added on branch comdex-fall-1999 on 1999-11-05 05:13:37 +0000
 1.3.10.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.3.8.1 29-Apr-2005  kent sync with -current
 1.5.74.1 16-May-2008  yamt sync with head.
 1.5.72.1 18-May-2008  yamt sync with head.
 1.5.70.1 02-Jun-2008  mjf Sync with HEAD.
 1.4 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.3 11-Dec-2005  christos branches: 1.3.70; 1.3.72; 1.3.74;
merge ktrace-lwp.
 1.2 27-Feb-2005  perry nuke trailing whitespace
 1.1 10-Apr-2001  fredette branches: 1.1.2; 1.1.4; 1.1.26; 1.1.34; 1.1.36;
Added.
 1.1.36.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.1.34.1 29-Apr-2005  kent sync with -current
 1.1.26.1 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.1.4.2 21-Jun-2001  nathanw Catch up to -current.
 1.1.4.1 10-Apr-2001  nathanw file am9513reg.h was added on branch nathanw_sa on 2001-06-21 20:02:12 +0000
 1.1.2.2 21-Apr-2001  bouyer Sync with HEAD
 1.1.2.1 10-Apr-2001  bouyer file am9513reg.h was added on branch thorpej_scsipi on 2001-04-21 17:48:26 +0000
 1.3.74.1 16-May-2008  yamt sync with head.
 1.3.72.1 18-May-2008  yamt sync with head.
 1.3.70.1 02-Jun-2008  mjf Sync with HEAD.
 1.2 28-Jun-1995  cgd these have moved to more appropriate names
 1.1 24-Apr-1995  pk AMD9730 telephony chip (used to be sparc/dev/bsd_audioreg.h).
 1.5 19-Mar-2022  riastradh rnd(9): Omit needless locks in various HWRNG drivers.

Now that the rnd(9) API guarantees serial callbacks, we can simplify
everything a bit more.

(Some drivers like hifn(4) and sun8icrypto(4) still use locks to
coordinate with other parts of the driver to submit requests to and
process responses from the device.)
 1.4 19-Mar-2022  riastradh rnd(9): Adjust IPL of locks used by rndsource callbacks.

These no longer ever run from hard interrupt context or with a spin
lock held, so there is no longer any need to have them at IPL_VM to
block hard interrupts. Instead, lower them to IPL_SOFTSERIAL.
 1.3 23-Aug-2021  mrg avoid an infinite loop if reading data fails.

system hung hard on an "AMD E2-7110 APU with AMD Radeon R2 Graphics"
CPU, as the read fails continually and the loop continues.
 1.2 30-Apr-2020  riastradh rnd_attach_source calls the callback itself now.

No need for every driver to explicitly call it to prime the pool.

Eliminate now-unused <sys/rndpool.h>.
 1.1 19-Oct-2018  jakllsch branches: 1.1.2; 1.1.6;
Add amdccp(4) driver for AMD Cryptographic Coprocessor, as found on the
A11xx Opterons. Driver currently provides RNG service only.
 1.1.6.2 10-Jun-2019  christos Sync with HEAD
 1.1.6.1 19-Oct-2018  christos file amdccp.c was added on branch phil-wifi on 2019-06-10 22:07:10 +0000
 1.1.2.2 20-Oct-2018  pgoyette Sync with head
 1.1.2.1 19-Oct-2018  pgoyette file amdccp.c was added on branch pgoyette-compat on 2018-10-20 06:58:31 +0000
 1.2 19-Mar-2022  riastradh rnd(9): Omit needless locks in various HWRNG drivers.

Now that the rnd(9) API guarantees serial callbacks, we can simplify
everything a bit more.

(Some drivers like hifn(4) and sun8icrypto(4) still use locks to
coordinate with other parts of the driver to submit requests to and
process responses from the device.)
 1.1 19-Oct-2018  jakllsch branches: 1.1.2; 1.1.6;
Add amdccp(4) driver for AMD Cryptographic Coprocessor, as found on the
A11xx Opterons. Driver currently provides RNG service only.
 1.1.6.2 10-Jun-2019  christos Sync with HEAD
 1.1.6.1 19-Oct-2018  christos file amdccpvar.h was added on branch phil-wifi on 2019-06-10 22:07:10 +0000
 1.1.2.2 20-Oct-2018  pgoyette Sync with head
 1.1.2.1 19-Oct-2018  pgoyette file amdccpvar.h was added on branch pgoyette-compat on 2018-10-20 06:58:31 +0000
 1.76 21-Sep-2021  christos don't opencode kauth_cred_get()
 1.75 16-Jun-2021  riastradh if_attach and if_initialize cannot fail, don't test return value

These were originally made failable back in 2017 when if_initialize
allocated a softint in every interface for link state changes, so
that it could fail gracefully instead of panicking:

https://mail-index.NetBSD.org/source-changes/2017/10/23/msg089053.html

However, this spawned many seldom- or never-tested error branches,
which are risky to have around. And that softint in every interface
has since been replaced by a single global workqueue, because link
state changes require thread context but not low latency or high
throughput:

https://mail-index.NetBSD.org/source-changes/2020/02/06/msg113759.html

So there is no longer any reason for if_initialize to fail. (The
subroutine if_stats_init can't fail because percpu_alloc can't fail
either.)

There is a snag: the softint_establish in if_percpuq_create could
fail, potentially leading to bad consequences later on trying to use
the softint. This change doesn't introduce any new bugs because of
the snag -- if_percpuq_attach was already broken. However, the snag
can be better addressed without spawning error branches, either by
using a single softint or making softints less scarce.

(Separate commit will change the signatures of if_attach and
if_initialize to return void, scheduled to ride whatever is the next
convenient kernel bump.)

Patch and testing on amd64 and evbmips64-eb by maya@; commit message
soliloquy, and compile-testing on evbppc/i386/earmv7hf, by me.
 1.74 11-Jun-2021  jdc Add a missing htole16() around the length passed to bpf_mtap2().
Allows `tcpdump` to work on BE machines without panicing the kernel.
 1.73 29-Jan-2020  thorpej branches: 1.73.10;
Adopt <net/if_stats.h>.
 1.72 23-Sep-2019  maxv branches: 1.72.2;
Move the timeout check out of the loop, otherwise it is never reached.
Found by the lgtm bot.
 1.71 20-Sep-2019  maxv Don't use the same iterator in a nested loop. (How could this work?)

Found by the lgtm bot.
 1.70 05-Feb-2019  msaitoh Remove very old IFF_NOTRAILERS flag.
 1.69 03-Sep-2018  riastradh Rename min/max -> uimin/uimax for better honesty.

These functions are defined on unsigned int. The generic name
min/max should not silently truncate to 32 bits on 64-bit systems.
This is purely a name change -- no functional change intended.

HOWEVER! Some subsystems have

#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))

even though our standard name for that is MIN/MAX. Although these
may invite multiple evaluation bugs, these do _not_ cause integer
truncation.

To avoid `fixing' these cases, I first changed the name in libkern,
and then compile-tested every file where min/max occurred in order to
confirm that it failed -- and thus confirm that nothing shadowed
min/max -- before changing it.

I have left a handful of bootloaders that are too annoying to
compile-test, and some dead code:

cobalt ews4800mips hp300 hppa ia64 luna68k vax
acorn32/if_ie.c (not included in any kernels)
macppc/if_gm.c (superseded by gem(4))

It should be easy to fix the fallout once identified -- this way of
doing things fails safe, and the goal here, after all, is to _avoid_
silent integer truncations, not introduce them.

Maybe one day we can reintroduce min/max as type-generic things that
never silently truncate. But we should avoid doing that for a while,
so that existing code has a chance to be detected by the compiler for
conversion to uimin/uimax without changing the semantics until we can
properly audit it all. (Who knows, maybe in some cases integer
truncation is actually intended!)
 1.68 26-Jun-2018  msaitoh branches: 1.68.2;
Implement the BPF direction filter (BIOC[GS]DIRECTION). It provides backward
compatibility with BIOC[GS]SEESENT ioctl. The userland interface is the same
as FreeBSD.

This change also fixes a bug that the direction is misunderstand on some
environment by passing the direction to bpf_mtap*() instead of checking
m->m_pkthdr.rcvif.
 1.67 22-Jun-2018  msaitoh It's not required to include net/bpfdesc.h. Remove it.
 1.66 23-Oct-2017  msaitoh branches: 1.66.2;
If error occured in the attach function, free resources and return.
 1.65 23-May-2017  ozaki-r branches: 1.65.2;
Apply deferred if_start to more drivers

And annotate some XXX_start as it runs in softint to clarify that
it doesn't need deferred if_start.
 1.64 02-Feb-2017  nonaka wlan interfaces make interrupt routine running on softint context.

see http://mail-index.netbsd.org/tech-kern/2016/12/06/msg021281.html

tested device:
* ath at pci: AR5212, AR5424
* athn at pci: AR9287
* ipw at pci: 2100BG
* iwi at pci: 2915ABG
* iwm at pci: 3165, 7260, 8260
* iwn at pci: 4945, 6235
* ral at pci: RT2560
* rtwn at pci: RTL8192CE
 1.63 10-Jun-2016  ozaki-r branches: 1.63.2; 1.63.4;
Introduce m_set_rcvif and m_reset_rcvif

The API is used to set (or reset) a received interface of a mbuf.
They are counterpart of m_get_rcvif, which will come in another
commit, hide internal of rcvif operation, and reduce the diff of
the upcoming change.

No functional change.
 1.62 07-Feb-2015  christos set error. Reported by;
http://www.m00nbsd.net/ae123a9bae03f7dde5c6d654412daf5a.html#Report-4
 1.61 25-Feb-2014  pooka branches: 1.61.4; 1.61.6;
Ensure that the top level sysctl nodes (kern, vfs, net, ...) exist before
the sysctl link sets are processed, and remove redundancy.

Shaves >13kB off of an amd64 GENERIC, not to mention >1k duplicate
lines of code.
 1.60 12-Sep-2013  martin Eliminate (mostly) unused "ostate" variable
 1.59 05-Apr-2010  joerg branches: 1.59.8; 1.59.18; 1.59.22;
Push the bpf_ops usage back into bpf.h. Push the common ifp->if_bpf
check into the inline functions as well the fourth argument for
bpf_attach.
 1.58 19-Jan-2010  pooka branches: 1.58.2; 1.58.4;
Redefine bpf linkage through an always present op vector, i.e.
#if NBPFILTER is no longer required in the client. This change
doesn't yet add support for loading bpf as a module, since drivers
can register before bpf is attached. However, callers of bpf can
now be modularized.

Dynamically loadable bpf could probably be done fairly easily with
coordination from the stub driver and the real driver by registering
attachments in the stub before the real driver is loaded and doing
a handoff. ... and I'm not going to ponder the depths of unload
here.

Tested with i386/MONOLITHIC, modified MONOLITHIC without bpf and rump.
 1.57 12-Nov-2009  dyoung Simplify activation hook. Replace each use of sc_invalid by either
calling config_deactivate(9) or device_is_active(9).
 1.56 12-May-2009  cegger struct device * -> device_t, no functional changes intended.
 1.55 15-Apr-2009  elad Remove a few KAUTH_GENERIC_ISSUSER in favor of more descriptive
alternatives.

Discussed on tech-kern:

http://mail-index.netbsd.org/tech-kern/2009/04/11/msg004798.html

Input from ad@, christos@, dyoung@, tsutsui@.

Okay ad@.
 1.54 12-Nov-2008  ad branches: 1.54.4;
Remove LKMs and switch to the module framework, pass 1.

Proposed on tech-kern@.
 1.53 07-Nov-2008  dyoung *** Summary ***

When a link-layer address changes (e.g., ifconfig ex0 link
02:de:ad:be:ef:02 active), send a gratuitous ARP and/or a Neighbor
Advertisement to update the network-/link-layer address bindings
on our LAN peers.

Refuse a change of ethernet address to the address 00:00:00:00:00:00
or to any multicast/broadcast address. (Thanks matt@.)

Reorder ifnet ioctl operations so that driver ioctls may inherit
the functions of their "class"---ether_ioctl(), fddi_ioctl(), et
cetera---and the class ioctls may inherit from the generic ioctl,
ifioctl_common(), but both driver- and class-ioctls may override
the generic behavior. Make network drivers share more code.

Distinguish a "factory" link-layer address from others for the
purposes of both protecting that address from deletion and computing
EUI64.

Return consistent, appropriate error codes from network drivers.

Improve readability. KNF.

*** Details ***

In if_attach(), always initialize the interface ioctl routine,
ifnet->if_ioctl, if the driver has not already initialized it.
Delete if_ioctl == NULL tests everywhere else, because it cannot
happen.

In the ioctl routines of network interfaces, inherit common ioctl
behaviors by calling either ifioctl_common() or whichever ioctl
routine is appropriate for the class of interface---e.g., ether_ioctl()
for ethernets.

Stop (ab)using SIOCSIFADDR and start to use SIOCINITIFADDR. In
the user->kernel interface, SIOCSIFADDR's argument was an ifreq,
but on the protocol->ifnet interface, SIOCSIFADDR's argument was
an ifaddr. That was confusing, and it would work against me as I
make it possible for a network interface to overload most ioctls.
On the protocol->ifnet interface, replace SIOCSIFADDR with
SIOCINITIFADDR. In ifioctl(), return EPERM if userland tries to
invoke SIOCINITIFADDR.

In ifioctl(), give the interface the first shot at handling most
interface ioctls, and give the protocol the second shot, instead
of the other way around. Finally, let compatibility code (COMPAT_OSOCK)
take a shot.

Pull device initialization out of switch statements under
SIOCINITIFADDR. For example, pull ..._init() out of any switch
statement that looks like this:

switch (...->sa_family) {
case ...:
..._init();
...
break;
...
default:
..._init();
...
break;
}

Rewrite many if-else clauses that handle all permutations of IFF_UP
and IFF_RUNNING to use a switch statement,

switch (x & (IFF_UP|IFF_RUNNING)) {
case 0:
...
break;
case IFF_RUNNING:
...
break;
case IFF_UP:
...
break;
case IFF_UP|IFF_RUNNING:
...
break;
}

unifdef lots of code containing #ifdef FreeBSD, #ifdef NetBSD, and
#ifdef SIOCSIFMTU, especially in fwip(4) and in ndis(4).

In ipw(4), remove an if_set_sadl() call that is out of place.

In nfe(4), reuse the jumbo MTU logic in ether_ioctl().

Let ethernets register a callback for setting h/w state such as
promiscuous mode and the multicast filter in accord with a change
in the if_flags: ether_set_ifflags_cb() registers a callback that
returns ENETRESET if the caller should reset the ethernet by calling
if_init(), 0 on success, != 0 on failure. Pull common code from
ex(4), gem(4), nfe(4), sip(4), tlp(4), vge(4) into ether_ioctl(),
and register if_flags callbacks for those drivers.

Return ENOTTY instead of EINVAL for inappropriate ioctls. In
zyd(4), use ENXIO instead of ENOTTY to indicate that the device is
not any longer attached.

Add to if_set_sadl() a boolean 'factory' argument that indicates
whether a link-layer address was assigned by the factory or some
other source. In a comment, recommend using the factory address
for generating an EUI64, and update in6_get_hw_ifid() to prefer a
factory address to any other link-layer address.

Add a routing message, RTM_LLINFO_UPD, that tells protocols to
update the binding of network-layer addresses to link-layer addresses.
Implement this message in IPv4 and IPv6 by sending a gratuitous
ARP or a neighbor advertisement, respectively. Generate RTM_LLINFO_UPD
messages on a change of an interface's link-layer address.

In ether_ioctl(), do not let SIOCALIFADDR set a link-layer address
that is broadcast/multicast or equal to 00:00:00:00:00:00.

Make ether_ioctl() call ifioctl_common() to handle ioctls that it
does not understand.

In gif(4), initialize if_softc and use it, instead of assuming that
the gif_softc and ifp overlap.

Let ifioctl_common() handle SIOCGIFADDR.

Sprinkle rtcache_invariants(), which checks on DIAGNOSTIC kernels
that certain invariants on a struct route are satisfied.

In agr(4), rewrite agr_ioctl_filter() to be a bit more explicit
about the ioctls that we do not allow on an agr(4) member interface.

bzero -> memset. Delete unnecessary casts to void *. Use
sockaddr_in_init() and sockaddr_in6_init(). Compare pointers with
NULL instead of "testing truth". Replace some instances of (type
*)0 with NULL. Change some K&R prototypes to ANSI C, and join
lines.
 1.52 03-Jul-2008  drochner branches: 1.52.2; 1.52.4;
split device/softc (tested with an@pcmcia)
 1.51 08-Apr-2008  cegger branches: 1.51.4; 1.51.6; 1.51.8;
use aprint_*_dev and device_xname
 1.50 09-Dec-2007  jmcneill branches: 1.50.10;
Merge jmcneill-pm branch.
 1.49 19-Oct-2007  ad branches: 1.49.4; 1.49.6;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.48 04-Mar-2007  christos branches: 1.48.2; 1.48.14; 1.48.16; 1.48.20;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.47 04-Jan-2007  elad branches: 1.47.2;
Consistent usage of KAUTH_GENERIC_ISSUSER.
 1.46 07-Oct-2006  peter Fix compilation with AN_DEBUG (use %zu instead of %d).
 1.45 21-Jul-2006  ad branches: 1.45.4; 1.45.6;
- Use the LWP cached credentials where sane.
- Minor cosmetic changes.
 1.44 26-May-2006  blymn Clean up bogus whitespace
 1.43 14-May-2006  elad branches: 1.43.2;
integrate kauth.
 1.42 12-Mar-2006  dyoung branches: 1.42.2;
NetBSD authorities apprehended and confiscated these leading spaces
pursuant to KNF regulation 100145.92, "All your leading ASCII-SP
is belong to us." The code was set up the ASCII-TAB.
 1.41 12-Mar-2006  dyoung Bug fix: fields in the radiotap header are little-endian, make it so.
 1.40 20-Feb-2006  thorpej branches: 1.40.2; 1.40.4;
Use device_is_active() rather than testing dv_flags for DVF_ACTIVE
directly.
 1.39 19-Feb-2006  dyoung Add radiotap support to an(4). From Eric Auge.
 1.38 11-Dec-2005  christos branches: 1.38.2; 1.38.4; 1.38.6;
merge ktrace-lwp.
 1.37 10-Jul-2005  dyoung Bring an_newstate up-to-date with net80211 conventions. Now an(4)
works again. Jonathan Perkins reported the bug and tested the
patch.
 1.36 06-Jul-2005  dyoung Historically, an(4), ath(4), atw(4), rtw(4), and wi(4) have printed
out their modes and rates at boot. Revert to the historical
behavior.
 1.35 22-Jun-2005  dyoung branches: 1.35.2;
Resolve conflicts in importation of 18-May-2005 ath(4) / net80211(9)
from FreeBSD. Introduce compatibility shims (sys/dev/ic/ath_netbsd.[ch],
sys/net80211/ieee80211_netbsd.[ch]). Update drivers (an, atu, atw,
awi, ipw, iwi, rtw, wi) for the new net80211(9) API.
 1.34 20-Jun-2005  atatat Change the rest of the sysctl subsystem to use const consistently.
The __UNCONST macro is now used only where necessary and the RW macros
are gone. Most of the changes here are consumers of the
sysctl_createv(9) interface that now takes a pair of const pointers
which used not to be.
 1.33 15-Jan-2005  dyoung Fix two bugs: frames were bogusly discarded with the complaint
"oversize frame." Also, some an(4) instances (esp. w/ firmware
version 5+) would not reliably interoperate with some Cisco APs.

Add a sysctl for enabling/disabling debugging.

The problem with Aironet AP interoperability was that the rx frame
'gap' will sometimes be loaded with the 802.2 SNAP header, and
sometimes omitted, when connected to a Cisco AP; an(4) was *always*
discarding the gap. The problem with "oversize frames" was an
off-by-2 error in the frame-length arithmetic.

While we're here, pad some RIDs to the length that new firmware
really expects.

Thanks to Jim Miller for his valuable bug reports and testing, and
to Dheeraj Reddy for RID-length patches. Some clues from various
Linux drivers for Cisco/Aironet cards led to the gap fix.
 1.32 24-Aug-2004  thorpej Use ANSI function decls and more use of static.
 1.31 10-Aug-2004  dyoung Make the node table into an LRU cache: least-recently used nodes
are at the end of the node queue. Change the reference-counting
discipline: ni->ni_refcnt indicates how many times net80211 has
granted ni to the driver. Every node in the table with ni_refcnt=0
is eligible to be garbage-collected. The mere presence of a node
in the table does not any longer indicate its auth/assoc state;
nodes have a ni_state variable, now. A sysctl,
net.link.ieee80211.maxnodecache, controls the maximum LRU cache
size.

While I am here, patch ieee80211_find_node_for_beacon to do a "best
match" by bssid/ssid/channel, not a "perfect match." This keeps
net80211 from caching duplicate nodes in the table.
 1.30 23-Jul-2004  mycroft IEEE80211_F_WEPON -> IEEE80211_F_PRIVACY
 1.29 28-Jan-2004  onoe branches: 1.29.2; 1.29.4; 1.29.6;
Adopt to new 802.11 framework.
Add support of version 5.30.17 firmware of PCMCIA 350 series.
MPI350 mini-PCI is NOT YET supported.
MONITOR mode is still not yet working.
 1.28 02-Nov-2003  wiz Fix some typos. From Tom Cosgrove via jmc@openbsd.
 1.27 13-Oct-2003  dyoung Switch an(4) to using the header files in the new 802.11 layer.
 1.26 05-Sep-2003  itojun add DIAGNOSTIC check for AN_DEFAULT_xx
 1.25 06-Jul-2003  dyoung Prepare to consolidate 802.11 media handling (which is handled in
code duplicated by each driver, now) into the 802.11 framework.
 1.24 31-Jan-2003  thorpej branches: 1.24.2;
Use aprint_*().
 1.23 27-Sep-2002  provos remove trailing \n in panic(). approved perry.
 1.22 23-Mar-2002  gmcgarry Remove FreeBSD RCSID.
 1.21 13-Nov-2001  lukem add/cleanup RCSID
 1.20 18-Jul-2001  onoe Do not copy first keys into four key entries; the bug was introduced in 1.17
 1.19 07-Jul-2001  thorpej branches: 1.19.2;
bcopy -> memcpy
 1.18 07-Jul-2001  thorpej bcmp -> memcmp
 1.17 29-Jun-2001  onoe Experimental support for LEAP, which is cisco's implementation of IEEE802.11
EAP in aironet firmware. Currently it seems that only cisco's RADIUS server
implements EAP for IEEE802.11, and the function is not tested at all.
 1.16 28-Jun-2001  onoe Do not re-enable after resume if interface is marked down.
 1.15 21-Jun-2001  onoe Add support for persistent key.
Fix promiscuous mode, taken from FreeBSD.
Fix to re-enable the card after suspend/resume.
Reflect current operational rate to if_media interface.
Avoid duplicate copy in transmit.
Move most of debug printfs into IFF_DEBUG.
Disable ANCACHE - designed for IPv4 only and no one use it.
Add IFF_ALLMULTI flags, as we don't have multicast filter.
Convert bzero/bcopy to memset/memcpy.
... sorry for jumbo commit.
 1.14 28-May-2001  onoe add a comment why IFF_PROMISC is handled separately for SIOCSIFFLAGS:
Handle special case for IFF_PROMISC. If only IFF_PROMISC
flag is changed, do not call an_init() to avoid initiating
reassociation to another access point. It is really
helpful for tcpdump(8).
 1.13 24-May-2001  itojun minor style
 1.12 24-May-2001  itojun correct multicast filter handling. without this, we cannot run IPv6 on an*.
 1.11 08-Mar-2001  thorpej Make sure data after the header is aligned, so that this works on
systems with strict alignment constraints.
kern/12356, Feico Dillema <feico@pasta.cs.uit.no>.
 1.10 21-Dec-2000  onoe branches: 1.10.2;
improve an_cmd() slightly:
- strip unnecessary loop to get command result status
- ack command after clearing busy bit

XXX: it still sometimes get timeout to get status(0xff50) or statistics(0xff68)
probably due to heavy load of firmware in receiving.
 1.9 19-Dec-2000  onoe cleanup attach procedure, use tsleep() instead of long delay (and ignore
timeouts).
stop driver after suspend.
XXX: should use command interrupt but no document...
XXX: status update sometimes failed perhaps due to collision.
(RID 0xff50 or 0xff68 access failed)
 1.8 14-Dec-2000  thorpej ALTQ'ify.
 1.7 14-Dec-2000  onoe Add PCI version of Aironet, not tested at all.
ISA/ISApnp version won't come since I don't know about isa...
 1.6 13-Dec-2000  onoe Support 80211NWKEY and 80211POWER ioctl.
 1.5 12-Dec-2000  onoe branches: 1.5.2; 1.5.4;
add support(?) for PC4500 which is a 2Mbps product.
Though ifconfig -m no longer show 5Mbps/11Mbps for PC4500 by this fix,
I cannot find how to set fixed transmit speed to the firmware.
FreeBSD version of driver apparently ignore the value set by ancontrol(8).
 1.4 12-Dec-2000  onoe cleanup headers: remove duplicate definition, split reg.h/var.h.
 1.3 12-Dec-2000  thorpej s/Ethernet/802.11/ when printing the address.
 1.2 11-Dec-2000  onoe To fix panic at "ifconfig an0 down",
define ANCACHE in if_an_pcmcia.c (XXX)
try not to access registers after interface down.
 1.1 11-Dec-2000  onoe Port 'an' driver for Aironet PC4500/PC4800 IEEE802.11 card from FreeBSD.
This is very adhoc work for IETF meeting.
- Since it seems that 'an' and 'wi' have similar hardware, low level
functions should be shared.
- There are PCI/ISA cards of Aironet but not supported yet.
- The wiconfig interface is changed so that wiconfig cannot be used.
- 'ancontrol' of FreeBSD is not ported.
- Only infrastructure mode is tested.
- WEP is not supported.

Though I only have an Aironet card, Cisco card should be expected to work.
 1.5.4.4 12-Mar-2001  bouyer Sync with HEAD.
 1.5.4.3 05-Jan-2001  bouyer Sync with HEAD
 1.5.4.2 13-Dec-2000  bouyer Sync with HEAD (for UBC fixes).
 1.5.4.1 12-Dec-2000  bouyer file an.c was added on branch thorpej_scsipi on 2000-12-13 15:50:00 +0000
 1.5.2.4 11-Mar-2001  he Pull up revision 1.11 (requested by thorpej):
Make sure data after header is aligned, so that this works on
architectures with strict alignment constraints. Fixes PR#12356.
 1.5.2.3 16-Dec-2000  he Apply patch (requested by he):
Fix multicast packet reception; handle corresponding ioctl().
 1.5.2.2 12-Dec-2000  he Pull up revisions 1.1-1.3 (plus patch, new, requested by he):
Add a driver for an(4), Aironet and Cisco wireless pcmcia cards.
 1.5.2.1 12-Dec-2000  he file an.c was added on branch netbsd-1-5 on 2000-12-12 21:25:42 +0000
 1.10.2.11 18-Oct-2002  nathanw Catch up to -current.
 1.10.2.10 12-Jul-2002  nathanw No longer need to pull in lwp.h; proc.h pulls it in for us.
 1.10.2.9 10-Jul-2002  nathanw Whitespace.
 1.10.2.8 24-Jun-2002  nathanw Curproc->curlwp renaming.

Change uses of "curproc->l_proc" back to "curproc", which is more like the
original use. Bare uses of "curproc" are now "curlwp".

"curproc" is now #defined in proc.h as ((curlwp) ? (curlwp)->l_proc) : NULL)
so that it is always safe to reference curproc (*de*referencing curproc
is another story, but that's always been true).
 1.10.2.7 01-Apr-2002  nathanw Catch up to -current.
(CVS: It's not just a program. It's an adventure!)
 1.10.2.6 14-Nov-2001  nathanw Catch up to -current.
 1.10.2.5 24-Aug-2001  nathanw A few files and lwp/proc conversions I missed in the last big update.
GENERIC runs again.
 1.10.2.4 24-Aug-2001  nathanw Catch up with -current.
 1.10.2.3 21-Jun-2001  nathanw Catch up to -current.
 1.10.2.2 09-Apr-2001  nathanw Catch up with -current.
 1.10.2.1 05-Mar-2001  nathanw Initial commit of scheduler activations and lightweight process support.
 1.19.2.4 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.19.2.3 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.19.2.2 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.19.2.1 03-Aug-2001  lukem update to -current
 1.24.2.7 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.24.2.6 17-Jan-2005  skrll Sync with HEAD.
 1.24.2.5 21-Sep-2004  skrll Fix the sync with head I botched.
 1.24.2.4 18-Sep-2004  skrll Sync with HEAD.
 1.24.2.3 25-Aug-2004  skrll Sync with HEAD.
 1.24.2.2 12-Aug-2004  skrll Sync with HEAD.
 1.24.2.1 03-Aug-2004  skrll Sync with HEAD
 1.29.6.1 01-Dec-2005  riz Pull up following revision(s) (requested by jnemeth in ticket #10159):
sys/dev/ic/an.c: revision 1.33 via patch
sys/dev/ic/anvar.h: revision 1.9 via patch
Fix two bugs: frames were bogusly discarded with the complaint
"oversize frame." Also, some an(4) instances (esp. w/ firmware
version 5+) would not reliably interoperate with some Cisco APs.
Add a sysctl for enabling/disabling debugging.
The problem with Aironet AP interoperability was that the rx frame
'gap' will sometimes be loaded with the 802.2 SNAP header, and
sometimes omitted, when connected to a Cisco AP; an(4) was *always*
discarding the gap. The problem with "oversize frames" was an
off-by-2 error in the frame-length arithmetic.
While we're here, pad some RIDs to the length that new firmware
really expects.
Thanks to Jim Miller for his valuable bug reports and testing, and
to Dheeraj Reddy for RID-length patches. Some clues from various
Linux drivers for Cisco/Aironet cards led to the gap fix.
 1.29.4.1 01-Dec-2005  riz Pull up following revision(s) (requested by jnemeth in ticket #10159):
sys/dev/ic/an.c: revision 1.33 via patch
sys/dev/ic/anvar.h: revision 1.9 via patch
Fix two bugs: frames were bogusly discarded with the complaint
"oversize frame." Also, some an(4) instances (esp. w/ firmware
version 5+) would not reliably interoperate with some Cisco APs.
Add a sysctl for enabling/disabling debugging.
The problem with Aironet AP interoperability was that the rx frame
'gap' will sometimes be loaded with the 802.2 SNAP header, and
sometimes omitted, when connected to a Cisco AP; an(4) was *always*
discarding the gap. The problem with "oversize frames" was an
off-by-2 error in the frame-length arithmetic.
While we're here, pad some RIDs to the length that new firmware
really expects.
Thanks to Jim Miller for his valuable bug reports and testing, and
to Dheeraj Reddy for RID-length patches. Some clues from various
Linux drivers for Cisco/Aironet cards led to the gap fix.
 1.29.2.1 01-Dec-2005  riz Pull up following revision(s) (requested by jnemeth in ticket #10159):
sys/dev/ic/an.c: revision 1.33 via patch
sys/dev/ic/anvar.h: revision 1.9 via patch
Fix two bugs: frames were bogusly discarded with the complaint
"oversize frame." Also, some an(4) instances (esp. w/ firmware
version 5+) would not reliably interoperate with some Cisco APs.
Add a sysctl for enabling/disabling debugging.
The problem with Aironet AP interoperability was that the rx frame
'gap' will sometimes be loaded with the 802.2 SNAP header, and
sometimes omitted, when connected to a Cisco AP; an(4) was *always*
discarding the gap. The problem with "oversize frames" was an
off-by-2 error in the frame-length arithmetic.
While we're here, pad some RIDs to the length that new firmware
really expects.
Thanks to Jim Miller for his valuable bug reports and testing, and
to Dheeraj Reddy for RID-length patches. Some clues from various
Linux drivers for Cisco/Aironet cards led to the gap fix.
 1.35.2.6 21-Jan-2008  yamt sync with head
 1.35.2.5 27-Oct-2007  yamt sync with head.
 1.35.2.4 03-Sep-2007  yamt sync with head.
 1.35.2.3 26-Feb-2007  yamt sync with head.
 1.35.2.2 30-Dec-2006  yamt sync with head.
 1.35.2.1 21-Jun-2006  yamt sync with head.
 1.38.6.2 01-Jun-2006  kardel Sync with head.
 1.38.6.1 22-Apr-2006  simonb Sync with head.
 1.38.4.1 09-Sep-2006  rpaulo sync with head
 1.38.2.1 01-Mar-2006  yamt sync with head.
 1.40.4.3 19-Apr-2006  elad sync with head.
 1.40.4.2 10-Mar-2006  elad generic_authorize() -> kauth_authorize_generic().
 1.40.4.1 08-Mar-2006  elad Adapt to kernel authorization KPI.
 1.40.2.4 11-Aug-2006  yamt sync with head
 1.40.2.3 26-Jun-2006  yamt sync with head.
 1.40.2.2 24-May-2006  yamt sync with head.
 1.40.2.1 13-Mar-2006  yamt sync with head.
 1.42.2.1 24-May-2006  tron Merge 2006-05-24 NetBSD-current into the "peter-altq" branch.
 1.43.2.1 19-Jun-2006  chap Sync with head.
 1.45.6.1 22-Oct-2006  yamt sync with head
 1.45.4.2 12-Jan-2007  ad Sync with head.
 1.45.4.1 18-Nov-2006  ad Sync with head.
 1.47.2.1 12-Mar-2007  rmind Sync with HEAD.
 1.48.20.1 25-Oct-2007  bouyer Sync with HEAD.
 1.48.16.2 09-Jan-2008  matt sync with HEAD
 1.48.16.1 06-Nov-2007  matt sync with HEAD
 1.48.14.2 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.48.14.1 04-Sep-2007  joerg Convert an(4) to new style power management.
 1.48.2.1 23-Oct-2007  ad Sync with head.
 1.49.6.1 11-Dec-2007  yamt sync with head.
 1.49.4.1 26-Dec-2007  ad Sync with head.
 1.50.10.3 17-Jan-2009  mjf Sync with HEAD.
 1.50.10.2 28-Sep-2008  mjf Sync with HEAD.
 1.50.10.1 02-Jun-2008  mjf Sync with HEAD.
 1.51.8.1 18-Jul-2008  simonb Sync with head.
 1.51.6.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.51.4.4 11-Aug-2010  yamt sync with head.
 1.51.4.3 11-Mar-2010  yamt sync with head
 1.51.4.2 16-May-2009  yamt sync with head
 1.51.4.1 04-May-2009  yamt sync with head.
 1.52.4.2 28-Apr-2009  skrll Sync with HEAD.
 1.52.4.1 19-Jan-2009  skrll Sync with HEAD.
 1.52.2.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.54.4.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.58.4.1 30-May-2010  rmind sync with head
 1.58.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.59.22.1 18-May-2014  rmind sync with head
 1.59.18.2 03-Dec-2017  jdolecek update from HEAD
 1.59.18.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.59.8.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.61.6.4 28-Aug-2017  skrll Sync with HEAD
 1.61.6.3 05-Feb-2017  skrll Sync with HEAD
 1.61.6.2 09-Jul-2016  skrll Sync with HEAD
 1.61.6.1 06-Apr-2015  skrll Sync with HEAD
 1.61.4.1 16-Feb-2015  martin Pull up following revision(s) (requested by maxv in ticket #520):
sys/ufs/chfs/ebh.c: revision 1.6
sys/dev/sdmmc/sdmmc_mem.c: revision 1.33
sys/dev/ic/aic7xxx.c: revision 1.132
sys/fs/nfs/common/krpc_subr.c: revision 1.2
sys/modules/lua/lua.c: revision 1.16
sys/fs/udf/udf_subr.c: revision 1.128
sys/ufs/chfs/chfs_scan.c: revision 1.6
sys/dev/ic/an.c: revision 1.62

Fix six memory leaks and two inconsistencies.
 1.63.4.1 21-Apr-2017  bouyer Sync with HEAD
 1.63.2.1 20-Mar-2017  pgoyette Sync with HEAD
 1.65.2.2 26-Jul-2018  snj Pull up following revision(s) (requested by msaitoh in ticket #938):
sys/arch/acorn32/podulebus/if_ie.c: revision 1.41
sys/arch/amiga/dev/if_es.c: revision 1.58
sys/arch/amiga/dev/if_qn.c: revision 1.45
sys/arch/arm/at91/at91emac.c: revision 1.20
sys/arch/arm/ep93xx/epe.c: revision 1.37
sys/arch/emips/ebus/if_le_ebus.c: revision 1.14
sys/arch/emips/ebus/if_le_ebus.c: revision 1.15
sys/arch/mac68k/dev/if_mc.c: revision 1.46
sys/arch/macppc/dev/am79c950.c: revision 1.39
sys/arch/newsmips/apbus/if_sn.c: revision 1.40
sys/arch/next68k/dev/mb8795.c: revision 1.59
sys/arch/playstation2/dev/if_smap.c: revision 1.25
sys/arch/playstation2/dev/if_smap.c: revision 1.26
sys/arch/sun2/dev/if_ec.c: revision 1.28
sys/arch/sun3/dev/if_ie.c: revision 1.63
sys/arch/x68k/dev/if_ne_intio.c: revision 1.19
sys/arch/xen/xen/if_xennet_xenbus.c: revision 1.75
sys/arch/xen/xen/xennetback_xenbus.c: revision 1.63
sys/dev/bi/if_ni.c: revision 1.45
sys/dev/cadence/if_cemac.c: revision 1.12
sys/dev/ic/am7990.c: revision 1.78
sys/dev/ic/am79900.c: revision 1.27
sys/dev/ic/an.c: revision 1.67
sys/dev/ic/cs89x0.c: revision 1.40
sys/dev/ic/dm9000.c: revision 1.13
sys/dev/ic/dm9000.c: revision 1.14
sys/dev/ic/dp8390.c: revision 1.88
sys/dev/ic/elink3.c: revision 1.141
sys/dev/ic/elinkxl.c: revision 1.122
sys/dev/ic/hme.c: revision 1.98
sys/dev/ic/i82586.c: revision 1.77
sys/dev/ic/lance.c: revision 1.53
sys/dev/ic/mb86950.c: revision 1.27
sys/dev/ic/mb86960.c: revision 1.86
sys/dev/ic/mtd803.c: revision 1.34
sys/dev/ic/pdq_ifsubr.c: revision 1.59
sys/dev/ic/rrunner.c: revision 1.86
sys/dev/ic/seeq8005.c: revision 1.58
sys/dev/ic/sgec.c: revision 1.47
sys/dev/ic/smc90cx6.c: revision 1.72
sys/dev/ic/smc91cxx.c: revision 1.96
sys/dev/ic/tropic.c: revision 1.49
sys/dev/ic/wi.c: revision 1.245
sys/dev/isa/if_eg.c: revision 1.93
sys/dev/isa/if_el.c: revision 1.95
sys/dev/isa/if_iy.c: revision 1.101
sys/dev/ofw/ofnet.c: revision 1.58
sys/dev/pci/if_alc.c: revision 1.27
sys/dev/pci/if_de.c: revision 1.152
sys/dev/pci/if_fpa.c: revision 1.61
sys/dev/pci/if_jme.c: revision 1.34
sys/dev/pci/if_tl.c: revision 1.108
sys/dev/pci/if_vte.c: revision 1.19
sys/dev/pci/ixgbe/ixgbe.h: revision 1.50
sys/dev/pcmcia/if_cnw.c: revision 1.62
sys/dev/pcmcia/if_malo_pcmcia.c: revision 1.17
sys/dev/pcmcia/if_ray.c: revision 1.89
sys/dev/pcmcia/if_xi.c: revision 1.81
sys/dev/pcmcia/mhzc.c: revision 1.51
sys/dev/pcmcia/xirc.c: revision 1.34
sys/dev/qbus/if_de.c: revision 1.33
sys/dev/qbus/if_qe.c: revision 1.78
sys/dev/qbus/if_qt.c: revision 1.22
sys/dev/sbus/be.c: revision 1.87
sys/dev/sbus/qe.c: revision 1.68
sys/dev/scsipi/if_se.c: revision 1.96
sys/dev/usb/if_atu.c: revision 1.59
sys/net/if_l2tp.c: revision 1.28 via patch
sys/net/if_ppp.c: revision 1.160
It's not required to include net/bpfdesc.h. Remove it.
--
Simplify like other drivers. NULL check of ifp->if_bpf is done in
bpf_mtap(), so it's not required to do it here.
--
Remove duplicated inclusion of net/bpf.h.
--
Remove duplicated inclusion of net/bpf.h.
--
Simplify bpf_mtap() call. No functional change.
 1.65.2.1 10-Dec-2017  snj Pull up following revision(s) (requested by msaitoh in ticket #427):
sys/arch/amiga/dev/if_bah_zbus.c: 1.17
sys/arch/arm/broadcom/bcm53xx_eth.c: 1.30
sys/arch/powerpc/booke/dev/pq3etsec.c: 1.32
sys/arch/usermode/dev/if_veth.c: 1.9
sys/dev/ic/an.c: 1.66
sys/dev/ic/athn.c: 1.17
sys/dev/ic/atw.c: 1.162
sys/dev/ic/bwi.c: 1.33
sys/dev/ic/dwc_gmac.c: 1.41-1.42
sys/dev/ic/malo.c: 1.10
sys/dev/ic/rt2560.c: 1.31
sys/dev/ic/rt2661.c: 1.36
sys/dev/ic/rt2860.c: 1.29
sys/dev/ic/rtw.c: 1.127
sys/dev/ic/rtwvar.h: 1.46
sys/dev/ic/smc90cx6.c: 1.71
sys/dev/ic/smc90cx6var.h: 1.12
sys/dev/ic/wi.c: 1.244
sys/dev/pci/if_ipw.c: 1.66
sys/dev/pci/if_iwi.c: 1.104
sys/dev/pci/if_iwm.c: 1.76
sys/dev/pci/if_iwn.c: 1.86
sys/dev/pci/if_rtwn.c: 1.13
sys/dev/pci/if_wm.c: 1.541
sys/dev/pci/if_wpi.c: 1.79
sys/dev/pci/ixgbe/ixgbe.c: 1.106
sys/dev/pci/ixgbe/ixv.c: 1.73 via patch
sys/dev/pcmcia/if_malo_pcmcia.c: 1.15
sys/dev/scsipi/if_se.c: 1.95
sys/dev/usb/if_upl.c: 1.60
sys/net/if.c: 1.396
sys/net/if.h: 1.241
sys/net/if_arc.h: 1.23
sys/net/if_arcsubr.c: 1.78
sys/net/if_bridge.c: 1.136-1.137
sys/net/if_etherip.c: 1.39
sys/net/if_faith.c: 1.56
sys/net/if_gif.c: 1.131
sys/net/if_loop.c: 1.96
sys/net/if_mpls.c: 1.30
sys/net/if_pppoe.c: 1.129
sys/net/if_srt.c: 1.27
sys/net/if_stf.c: 1.102
sys/net/if_tap.c: 1.100
sys/net/if_vlan.c: 1.105
sys/netinet/ip_carp.c: 1.91
sys/rump/net/lib/libshmif/if_shmem.c: 1.73-1.74
sys/rump/net/lib/libvirtif/if_virt.c: 1.55-1.56
if_initalize() and if_attach() failed when resource allocation failed
(e.g. allocating softint). Without this change, it panics. It's bad because
resource shortage really occured when a lot of pseudo interface is created.
To avoid this problem, don't panic and change return value of if_initialize()
and if_attach() to int. Caller fanction will be recover from error cleanly by
checking the return value.
Return if bah_attach_subr() failed.
If if_attach() failed in the attach function, return.
- If if_initialize() failed in the attach function, free resources and return.
- Add some missing frees in bridge_clone_destroy().
- KNF
If error occured in bcmeth_ccb_attach(), free resources and return.
If error occured in pq3etsec_attach(), free resources and return.
If error occured in the attach function, free resources and return.
- If if_initialize() failed in athn_attach(), free resources and return.
- Add missing pmf_event_deregister() in athn_detach().
- Free resources correctly on some errors in atw_attach().
- Use apint*() insread of printf() in the attach function.
If if_initialize() failed in the attach function, return.
- If if_initialize() failed in the attach function, free resources and return.
- Add missing dwc_gmac_free_dma_rings() and mutex_destroy() when attach
failed.
- If if_initialize() failed in the attach function, free resources and return.
- ifp is always not NULL in iwi_detach(). Check correctly with ifp->if_softc.
- If if_initialize() failed in the attach function, free resources and return.
- Fix error path in the attach function correctly.
If if_initialize() failed in the attach function, free resources and return.
If if_attach() failed in the attach function, free resources and return.
- If if_initialize() failed in the attach function, free resources and return.
- KNF
- If if_attach() failed in the attach function, free resources and return.
- KNF
Fix compile error.
Fix compile error.
We don't need '&mii', but just 'mii' for mii_detach().
Don't free sc_rthash twice
 1.66.2.3 06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.66.2.2 28-Jul-2018  pgoyette Sync with HEAD
 1.66.2.1 25-Jun-2018  pgoyette Sync with HEAD
 1.68.2.3 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.68.2.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.68.2.1 10-Jun-2019  christos Sync with HEAD
 1.72.2.1 29-Feb-2020  ad Sync with head.
 1.73.10.1 17-Jun-2021  thorpej Sync w/ HEAD.
 1.15 25-Dec-2007  perry Convert many of the uses of __attribute__ to equivalent
__packed, __unused and __dead macros from cdefs.h
 1.14 06-Apr-2007  rumble branches: 1.14.10; 1.14.16; 1.14.18; 1.14.22;
If we fail to attach, use the size determined by pci_mapreg_map() rather
than a constant, since this will be incorrect on some chips (MPI350) and
lead to a panic.
 1.13 19-Feb-2006  dyoung branches: 1.13.20; 1.13.24; 1.13.26;
Support newer firmwares. From Eric Auge.
 1.12 11-Dec-2005  christos branches: 1.12.2; 1.12.4; 1.12.6;
merge ktrace-lwp.
 1.11 15-Jan-2005  dyoung branches: 1.11.10;
Fix two bugs: frames were bogusly discarded with the complaint
"oversize frame." Also, some an(4) instances (esp. w/ firmware
version 5+) would not reliably interoperate with some Cisco APs.

Add a sysctl for enabling/disabling debugging.

The problem with Aironet AP interoperability was that the rx frame
'gap' will sometimes be loaded with the 802.2 SNAP header, and
sometimes omitted, when connected to a Cisco AP; an(4) was *always*
discarding the gap. The problem with "oversize frames" was an
off-by-2 error in the frame-length arithmetic.

While we're here, pad some RIDs to the length that new firmware
really expects.

Thanks to Jim Miller for his valuable bug reports and testing, and
to Dheeraj Reddy for RID-length patches. Some clues from various
Linux drivers for Cisco/Aironet cards led to the gap fix.
 1.10 28-Jan-2004  onoe Adopt to new 802.11 framework.
Add support of version 5.30.17 firmware of PCMCIA 350 series.
MPI350 mini-PCI is NOT YET supported.
MONITOR mode is still not yet working.
 1.9 02-Nov-2003  wiz Fix some typos. From Tom Cosgrove via jmc@openbsd.
 1.8 29-Jun-2001  onoe branches: 1.8.22;
Experimental support for LEAP, which is cisco's implementation of IEEE802.11
EAP in aironet firmware. Currently it seems that only cisco's RADIUS server
implements EAP for IEEE802.11, and the function is not tested at all.
 1.7 21-Jun-2001  onoe add definitions for LEAP stuff in 350 series.
fix the value for AN_802_3_OFFSET to 0x34 (no one uses)
 1.6 08-Mar-2001  thorpej Add additional padding to the status record, needed by the AIR-PCM342.
kern/12357, Feico Dillema <feico@pasta.cs.uit.no>.
 1.5 20-Dec-2000  onoe branches: 1.5.2;
move definition of AN_INTRS from anreg.h to anvar.h
strip off AN_EV_CMD from AN_INTRS because it causes severe performance
problem.
 1.4 19-Dec-2000  onoe cleanup attach procedure, use tsleep() instead of long delay (and ignore
timeouts).
stop driver after suspend.
XXX: should use command interrupt but no document...
XXX: status update sometimes failed perhaps due to collision.
(RID 0xff50 or 0xff68 access failed)
 1.3 12-Dec-2000  onoe branches: 1.3.2; 1.3.4;
cleanup headers: remove duplicate definition, split reg.h/var.h.
 1.2 11-Dec-2000  onoe To fix panic at "ifconfig an0 down",
define ANCACHE in if_an_pcmcia.c (XXX)
try not to access registers after interface down.
 1.1 11-Dec-2000  onoe Port 'an' driver for Aironet PC4500/PC4800 IEEE802.11 card from FreeBSD.
This is very adhoc work for IETF meeting.
- Since it seems that 'an' and 'wi' have similar hardware, low level
functions should be shared.
- There are PCI/ISA cards of Aironet but not supported yet.
- The wiconfig interface is changed so that wiconfig cannot be used.
- 'ancontrol' of FreeBSD is not ported.
- Only infrastructure mode is tested.
- WEP is not supported.

Though I only have an Aironet card, Cisco card should be expected to work.
 1.3.4.4 12-Mar-2001  bouyer Sync with HEAD.
 1.3.4.3 05-Jan-2001  bouyer Sync with HEAD
 1.3.4.2 13-Dec-2000  bouyer Sync with HEAD (for UBC fixes).
 1.3.4.1 12-Dec-2000  bouyer file anreg.h was added on branch thorpej_scsipi on 2000-12-13 15:50:00 +0000
 1.3.2.3 11-Mar-2001  he Pull up revision 1.6 (requested by thorpej):
Add additional padding needed by the AIR-PCM342. Fixes PR#12357.
 1.3.2.2 12-Dec-2000  he Pull up revisions 1.1-1.2 (new, requested by he):
Add a driver for an(4), Aironet and Cisco wireless pcmcia cards.
 1.3.2.1 12-Dec-2000  he file anreg.h was added on branch netbsd-1-5 on 2000-12-12 21:26:34 +0000
 1.5.2.2 24-Aug-2001  nathanw Catch up with -current.
 1.5.2.1 09-Apr-2001  nathanw Catch up with -current.
 1.8.22.4 17-Jan-2005  skrll Sync with HEAD.
 1.8.22.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.8.22.2 18-Sep-2004  skrll Sync with HEAD.
 1.8.22.1 03-Aug-2004  skrll Sync with HEAD
 1.11.10.3 21-Jan-2008  yamt sync with head
 1.11.10.2 03-Sep-2007  yamt sync with head.
 1.11.10.1 21-Jun-2006  yamt sync with head.
 1.12.6.1 22-Apr-2006  simonb Sync with head.
 1.12.4.1 09-Sep-2006  rpaulo sync with head
 1.12.2.1 01-Mar-2006  yamt sync with head.
 1.13.26.1 11-Jul-2007  mjf Sync with head.
 1.13.24.1 10-Apr-2007  ad Sync with head.
 1.13.20.1 15-Apr-2007  yamt sync with head.
 1.14.22.1 02-Jan-2008  bouyer Sync with HEAD
 1.14.18.1 26-Dec-2007  ad Sync with head.
 1.14.16.1 18-Feb-2008  mjf Sync with HEAD.
 1.14.10.1 09-Jan-2008  matt sync with HEAD
 1.22 05-Oct-2019  mrg remove __packed attribute from struct ieee80211_radiotap_header
and all the structures that include it.

this should not change anything while avoiding packed vs alignment
warnings from GCC 8, and potentially pessimised code generation
due to the packed marker (there are no misaligned members, just
that the per-device parts may end unaligned.)

all consumers of these members are done from the properly aligned
packet members directly, or, as a union with a 64 byte member,
also properly aligned. codegen didn't appear to change, except
for the definition of sizeof(struct driver_[rt]x_radiotap_header)
in debug info, which is not directly used anywhere.
 1.21 02-Feb-2017  nonaka branches: 1.21.14;
wlan interfaces make interrupt routine running on softint context.

see http://mail-index.netbsd.org/tech-kern/2016/12/06/msg021281.html

tested device:
* ath at pci: AR5212, AR5424
* athn at pci: AR9287
* ipw at pci: 2100BG
* iwi at pci: 2915ABG
* iwm at pci: 3165, 7260, 8260
* iwn at pci: 4945, 6235
* ral at pci: RT2560
* rtwn at pci: RTL8192CE
 1.20 17-Jan-2010  pooka branches: 1.20.22; 1.20.40; 1.20.44; 1.20.48;
Forward declare struct bpf_if and use that as the type for bpf_if
instead of "void *". Buys us oo times the type-safety for 0 times
the price.
(no functional change)
 1.19 12-Nov-2009  dyoung Simplify activation hook. Replace each use of sc_invalid by either
calling config_deactivate(9) or device_is_active(9).
 1.18 12-May-2009  cegger struct device * -> device_t, no functional changes intended.
 1.17 03-Jul-2008  drochner branches: 1.17.10;
split device/softc (tested with an@pcmcia)
 1.16 25-Dec-2007  perry branches: 1.16.6; 1.16.10; 1.16.12; 1.16.14;
Convert many of the uses of __attribute__ to equivalent
__packed, __unused and __dead macros from cdefs.h
 1.15 09-Dec-2007  jmcneill branches: 1.15.2;
Merge jmcneill-pm branch.
 1.14 04-Mar-2007  christos branches: 1.14.14; 1.14.16; 1.14.22; 1.14.24; 1.14.26;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.13 19-Feb-2006  dyoung branches: 1.13.20;
Add radiotap support to an(4). From Eric Auge.
 1.12 11-Dec-2005  christos branches: 1.12.2; 1.12.4; 1.12.6;
merge ktrace-lwp.
 1.11 22-Jun-2005  dyoung branches: 1.11.2;
Resolve conflicts in importation of 18-May-2005 ath(4) / net80211(9)
from FreeBSD. Introduce compatibility shims (sys/dev/ic/ath_netbsd.[ch],
sys/net80211/ieee80211_netbsd.[ch]). Update drivers (an, atu, atw,
awi, ipw, iwi, rtw, wi) for the new net80211(9) API.
 1.10 27-Feb-2005  perry nuke trailing whitespace
 1.9 15-Jan-2005  dyoung branches: 1.9.2; 1.9.4;
Fix two bugs: frames were bogusly discarded with the complaint
"oversize frame." Also, some an(4) instances (esp. w/ firmware
version 5+) would not reliably interoperate with some Cisco APs.

Add a sysctl for enabling/disabling debugging.

The problem with Aironet AP interoperability was that the rx frame
'gap' will sometimes be loaded with the 802.2 SNAP header, and
sometimes omitted, when connected to a Cisco AP; an(4) was *always*
discarding the gap. The problem with "oversize frames" was an
off-by-2 error in the frame-length arithmetic.

While we're here, pad some RIDs to the length that new firmware
really expects.

Thanks to Jim Miller for his valuable bug reports and testing, and
to Dheeraj Reddy for RID-length patches. Some clues from various
Linux drivers for Cisco/Aironet cards led to the gap fix.
 1.8 28-Jan-2004  onoe branches: 1.8.2; 1.8.6; 1.8.8;
Adopt to new 802.11 framework.
Add support of version 5.30.17 firmware of PCMCIA 350 series.
MPI350 mini-PCI is NOT YET supported.
MONITOR mode is still not yet working.
 1.7 29-Jun-2001  onoe branches: 1.7.22;
Experimental support for LEAP, which is cisco's implementation of IEEE802.11
EAP in aironet firmware. Currently it seems that only cisco's RADIUS server
implements EAP for IEEE802.11, and the function is not tested at all.
 1.6 21-Jun-2001  onoe Add support for persistent key.
Fix promiscuous mode, taken from FreeBSD.
Fix to re-enable the card after suspend/resume.
Reflect current operational rate to if_media interface.
Avoid duplicate copy in transmit.
Move most of debug printfs into IFF_DEBUG.
Disable ANCACHE - designed for IPv4 only and no one use it.
Add IFF_ALLMULTI flags, as we don't have multicast filter.
Convert bzero/bcopy to memset/memcpy.
... sorry for jumbo commit.
 1.5 20-Dec-2000  onoe branches: 1.5.2;
move definition of AN_INTRS from anreg.h to anvar.h
strip off AN_EV_CMD from AN_INTRS because it causes severe performance
problem.
 1.4 19-Dec-2000  onoe cleanup attach procedure, use tsleep() instead of long delay (and ignore
timeouts).
stop driver after suspend.
XXX: should use command interrupt but no document...
XXX: status update sometimes failed perhaps due to collision.
(RID 0xff50 or 0xff68 access failed)
 1.3 14-Dec-2000  onoe Add PCI version of Aironet, not tested at all.
ISA/ISApnp version won't come since I don't know about isa...
 1.2 12-Dec-2000  onoe branches: 1.2.2; 1.2.4;
cleanup headers: remove duplicate definition, split reg.h/var.h.
 1.1 11-Dec-2000  onoe Port 'an' driver for Aironet PC4500/PC4800 IEEE802.11 card from FreeBSD.
This is very adhoc work for IETF meeting.
- Since it seems that 'an' and 'wi' have similar hardware, low level
functions should be shared.
- There are PCI/ISA cards of Aironet but not supported yet.
- The wiconfig interface is changed so that wiconfig cannot be used.
- 'ancontrol' of FreeBSD is not ported.
- Only infrastructure mode is tested.
- WEP is not supported.

Though I only have an Aironet card, Cisco card should be expected to work.
 1.2.4.3 05-Jan-2001  bouyer Sync with HEAD
 1.2.4.2 13-Dec-2000  bouyer Sync with HEAD (for UBC fixes).
 1.2.4.1 12-Dec-2000  bouyer file anvar.h was added on branch thorpej_scsipi on 2000-12-13 15:50:01 +0000
 1.2.2.2 12-Dec-2000  he Pull up revision 1.1 (new, requested by he):
Add a driver for an(4), Aironet and Cisco wireless pcmcia cards.
 1.2.2.1 12-Dec-2000  he file anvar.h was added on branch netbsd-1-5 on 2000-12-12 21:26:08 +0000
 1.5.2.1 24-Aug-2001  nathanw Catch up with -current.
 1.7.22.6 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.7.22.5 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.7.22.4 17-Jan-2005  skrll Sync with HEAD.
 1.7.22.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.7.22.2 18-Sep-2004  skrll Sync with HEAD.
 1.7.22.1 03-Aug-2004  skrll Sync with HEAD
 1.8.8.1 01-Dec-2005  riz Pull up following revision(s) (requested by jnemeth in ticket #10159):
sys/dev/ic/an.c: revision 1.33 via patch
sys/dev/ic/anvar.h: revision 1.9 via patch
Fix two bugs: frames were bogusly discarded with the complaint
"oversize frame." Also, some an(4) instances (esp. w/ firmware
version 5+) would not reliably interoperate with some Cisco APs.
Add a sysctl for enabling/disabling debugging.
The problem with Aironet AP interoperability was that the rx frame
'gap' will sometimes be loaded with the 802.2 SNAP header, and
sometimes omitted, when connected to a Cisco AP; an(4) was *always*
discarding the gap. The problem with "oversize frames" was an
off-by-2 error in the frame-length arithmetic.
While we're here, pad some RIDs to the length that new firmware
really expects.
Thanks to Jim Miller for his valuable bug reports and testing, and
to Dheeraj Reddy for RID-length patches. Some clues from various
Linux drivers for Cisco/Aironet cards led to the gap fix.
 1.8.6.1 01-Dec-2005  riz Pull up following revision(s) (requested by jnemeth in ticket #10159):
sys/dev/ic/an.c: revision 1.33 via patch
sys/dev/ic/anvar.h: revision 1.9 via patch
Fix two bugs: frames were bogusly discarded with the complaint
"oversize frame." Also, some an(4) instances (esp. w/ firmware
version 5+) would not reliably interoperate with some Cisco APs.
Add a sysctl for enabling/disabling debugging.
The problem with Aironet AP interoperability was that the rx frame
'gap' will sometimes be loaded with the 802.2 SNAP header, and
sometimes omitted, when connected to a Cisco AP; an(4) was *always*
discarding the gap. The problem with "oversize frames" was an
off-by-2 error in the frame-length arithmetic.
While we're here, pad some RIDs to the length that new firmware
really expects.
Thanks to Jim Miller for his valuable bug reports and testing, and
to Dheeraj Reddy for RID-length patches. Some clues from various
Linux drivers for Cisco/Aironet cards led to the gap fix.
 1.8.2.1 01-Dec-2005  riz Pull up following revision(s) (requested by jnemeth in ticket #10159):
sys/dev/ic/an.c: revision 1.33 via patch
sys/dev/ic/anvar.h: revision 1.9 via patch
Fix two bugs: frames were bogusly discarded with the complaint
"oversize frame." Also, some an(4) instances (esp. w/ firmware
version 5+) would not reliably interoperate with some Cisco APs.
Add a sysctl for enabling/disabling debugging.
The problem with Aironet AP interoperability was that the rx frame
'gap' will sometimes be loaded with the 802.2 SNAP header, and
sometimes omitted, when connected to a Cisco AP; an(4) was *always*
discarding the gap. The problem with "oversize frames" was an
off-by-2 error in the frame-length arithmetic.
While we're here, pad some RIDs to the length that new firmware
really expects.
Thanks to Jim Miller for his valuable bug reports and testing, and
to Dheeraj Reddy for RID-length patches. Some clues from various
Linux drivers for Cisco/Aironet cards led to the gap fix.
 1.9.4.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.9.2.1 29-Apr-2005  kent sync with -current
 1.11.2.3 21-Jan-2008  yamt sync with head
 1.11.2.2 03-Sep-2007  yamt sync with head.
 1.11.2.1 21-Jun-2006  yamt sync with head.
 1.12.6.1 22-Apr-2006  simonb Sync with head.
 1.12.4.1 09-Sep-2006  rpaulo sync with head
 1.12.2.1 01-Mar-2006  yamt sync with head.
 1.13.20.1 12-Mar-2007  rmind Sync with HEAD.
 1.14.26.1 11-Dec-2007  yamt sync with head.
 1.14.24.1 26-Dec-2007  ad Sync with head.
 1.14.22.1 18-Feb-2008  mjf Sync with HEAD.
 1.14.16.1 09-Jan-2008  matt sync with HEAD
 1.14.14.1 04-Sep-2007  joerg Convert an(4) to new style power management.
 1.15.2.1 02-Jan-2008  bouyer Sync with HEAD
 1.16.14.1 18-Jul-2008  simonb Sync with head.
 1.16.12.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.16.10.3 11-Mar-2010  yamt sync with head
 1.16.10.2 16-May-2009  yamt sync with head
 1.16.10.1 04-May-2009  yamt sync with head.
 1.16.6.1 28-Sep-2008  mjf Sync with HEAD.
 1.17.10.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.20.48.1 21-Apr-2017  bouyer Sync with HEAD
 1.20.44.1 20-Mar-2017  pgoyette Sync with HEAD
 1.20.40.1 05-Feb-2017  skrll Sync with HEAD
 1.20.22.1 03-Dec-2017  jdolecek update from HEAD
 1.21.14.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.6 11-Dec-2023  mlelstv Output is always 16bit, the internal audio data type may differ.
 1.5 19-Dec-2021  riastradh rkdrm: Convert to atomic modesetting, as needed for bridges.


Author: Jared McNeill <jmcneill@invisible.ca>
Committer: Taylor R Campbell <riastradh@NetBSD.org>
 1.4 19-Dec-2021  riastradh Sort includes.
 1.3 19-Dec-2021  riastradh Get drm to build on arm64 again.


Author: Jared McNeill <jmcneill@NetBSD.org>
Committer: Taylor R Campbell <riastradh@NetBSD.org>
 1.2 04-Jan-2020  jmcneill branches: 1.2.4; 1.2.8;
Emit PMFE_DISPLAY_{ON,OFF} events in response to DPMS requests.
 1.1 19-Dec-2019  jakllsch add Analogix DisplayPort core driver
 1.2.8.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.2.8.1 04-Jan-2020  martin file anx_dp.c was added on branch phil-wifi on 2020-04-08 14:08:06 +0000
 1.2.4.2 21-Jan-2020  martin Pull up following revision(s) (requested by mrg in ticket #616):

sys/dev/ic/anx_dp.c: revision 1.2
sys/arch/evbarm/conf/GENERIC64: revision 1.126
sys/dev/ic/anx_dp.h: revision 1.1
sys/arch/evbarm/conf/GENERIC64: revision 1.128
sys/dev/ic/anx_dp.h: revision 1.2
sys/dev/fdt/dwcmmc_fdt.c: revision 1.9
sys/dev/i2c/cwfg.c: revision 1.1
sys/conf/files: revision 1.1247
sys/dev/fdt/pwm_backlight.c: revision 1.5
sys/dev/fdt/pwm_backlight.c: revision 1.6
sys/arch/arm/rockchip/rk3399_cru.c: revision 1.14
sys/arch/arm/rockchip/rk3399_cru.c: revision 1.15
sys/arch/arm/rockchip/rk3399_cru.c: revision 1.16
sys/arch/arm/rockchip/rk3399_cru.c: revision 1.17
sys/dev/ic/dwc_mmc.c: revision 1.20
sys/arch/arm/rockchip/rk3399_cru.c: revision 1.18
sys/arch/arm/rockchip/rk3399_cru.c: revision 1.19
sys/dev/usb/usbdevs: revision 1.775
sys/arch/arm/rockchip/rk_dwhdmi.c: revision 1.4
sys/dev/fdt/simple_amplifier.c: revision 1.1
sys/dev/i2c/files.i2c: revision 1.105
sys/arch/evbarm/conf/GENERIC64: revision 1.117
sys/arch/evbarm/conf/GENERIC64: revision 1.118
sys/dev/i2c/files.i2c: revision 1.107
sys/dev/fdt/files.fdt: revision 1.49
sys/arch/arm/rockchip/rk_anxdp.c: revision 1.1
sys/dev/ic/dwc_mmc_var.h: revision 1.9
sys/dev/i2c/rkpmic.c: revision 1.4
sys/arch/arm/rockchip/rk_anxdp.c: revision 1.2
sys/dev/i2c/rkpmic.c: revision 1.5
sys/dev/i2c/rkpmic.c: revision 1.6
sys/arch/arm/rockchip/rk_vop.c: revision 1.4
sys/arch/arm/rockchip/rk_vop.c: revision 1.5
sys/dev/i2c/rkpmic.c: revision 1.8
sys/arch/arm/dts/rk3399-pinebook-pro.dts: revision 1.1
sys/dev/usb/ums.c: revision 1.96 (via patch)
sys/arch/arm/rockchip/rk_pwm.c: revision 1.3
sys/arch/arm/dts/rk3399-pinebook-pro.dts: revision 1.2
sys/dev/i2c/es8316ac.c: revision 1.1
sys/dev/fdt/dwcmmc_fdt.c: revision 1.10
sys/dev/i2c/es8316ac.c: revision 1.2
sys/dev/fdt/fdt_panel.c: revision 1.1
sys/dev/ic/dwc_mmc.c: revision 1.18
sys/dev/fdt/fdt_panel.c: revision 1.2
sys/dev/ic/dwc_mmc.c: revision 1.19
sys/arch/arm/dts/rk3399-rockpro64.dts: revision 1.10
sys/dev/fdt/fdt_port.c: revision 1.5
sys/dev/ic/dwc_mmc_var.h: revision 1.10
sys/dev/fdt/fdt_port.c: revision 1.6
sys/arch/evbarm/conf/GENERIC64: revision 1.122
sys/dev/ic/dwc_mmc_var.h: revision 1.11
sys/dev/fdt/files.fdt: revision 1.50
sys/arch/evbarm/conf/GENERIC64: revision 1.123
sys/arch/arm/rockchip/rk_i2s.c: revision 1.2
sys/arch/arm/rockchip/files.rockchip: revision 1.23
sys/arch/evbarm/conf/GENERIC64: revision 1.124
sys/dev/ic/anx_dp.c: revision 1.1

rkpmic: add RTC support; register w/ todr(9)
rkpmic: correct delay
Add support for SDIO interrupts.
fix copy/paste error in mux_pll_src_cpll_gpll_ppll_parents[]
add RK3399 eDP clocks
add RK3399 DisplayPort clocks
style fix/KNF
rk3399_cru: implement dclk_vop0_frac and dclk_vop1_frac
Move drm_encoder from rkvop(4) to the SoC-layer output pipe drivers (rk_dwhdmi).
rkvop: set stride using virtual framebuffer width instead of display mode
rk3399_cru: Reparent dclk_vop[01] to gpll via dclk_vop[01]_frac.
The previous source of dclk_vop[01] was vpll via dclk_vop[01]_div.
vpll is apparently used directly as a pixel clock source for the
HDMI PHY, and we don't want the other VOP's dclk changing out from
under it because we can't handle finding a replacement clock source
with the right rate yet.
gpll happens to run at 594MHz, which works well as a basis for pixel
clocks.
Linux suggests that the source clock of the fractional divider needs
to be more than twenty times greater than the resulting clock (or some
intermediate clock?) for output stability. This may not be the case
with 594MHz and the common pixel clocks I see used by displays in my
area of the wild, but it works for now.
add Analogix DisplayPort core driver
add Rockchip (RK3399) glue for Analogix DisplayPort core
add anxdp(4)
Add another panel@fdt driver, this time for DRM-style panels.
To do: migrate away from other panel driver.
enable panel at fdt drivers
paper over the rkpwm get_conf function that otherwise doesn't seem to
let things work
add template bits for optional eDP panel on RockPro64
Abort panel driver attach if required regulator is missing.
Add clk provider
Add Pinebook Pro dts, from Manjaro Linux.
https://gitlab.manjaro.org/tsys/linux-pinebook-pro/blob/877ca0e7283596f37845de50dc36bff5b88b91e1/arch/arm64/boot/dts/rockchip/rk3399-pinebook-pro.dts
+ rk3399-pinebook-pro.dts
Attach mmcpwrseq resource earlier
dwcmmc improvements:
- Use mmcpwrseq resources if available
- Only set 4- or 8-bit mode if specified in the dt properties
- Add quirk for implementations with inverted power enable logic
- Support switching signal voltage between 1.8V and 3.3V
- Fix a clock divider issue on Rockchip SoCs
Fix performance regression with previous
Quiet chatty printfs
No need to print all supported levels at attach, print the range and total number of steps
Disable SPI for now (rkspi driver hangs at boot)
Add driver for simple-audio-amplifier binding
Add driver for Everest Semi ES8316 Low Power Audio CODEC
add es8316, simpleamp
Avoid sleeping while the audio intr lock is held.
If the rockchip,system-power-controller property is present, try to power off with the PMIC
Add HAILUCK keyboard (product 1e)
Add a quirk for the HAILUCK USB keyboard / touchpad device with product 1e.
The keyboard does not function properly unless the touchpad's intr endpoint
is active.
Add driver for CellWise CW2015 Fuel Gauge IC.
add cwfg
Emit PMFE_DISPLAY_{ON,OFF} events in response to DPMS requests.
If the backlight node does not have an enable gpio, set the lowest duty
cycle to turn the display off instead.
Attach psci as early as possible. This allows other power controllers to
register their own poweroff / reset callbacks with a higher preference.
Add 2000 MHz to available armclkb rates
Remove debug printfs
 1.2.4.1 04-Jan-2020  martin file anx_dp.c was added on branch netbsd-9 on 2020-01-21 10:39:58 +0000
 1.5 19-Dec-2021  riastradh rkdrm: Convert to atomic modesetting, as needed for bridges.


Author: Jared McNeill <jmcneill@invisible.ca>
Committer: Taylor R Campbell <riastradh@NetBSD.org>
 1.4 19-Dec-2021  riastradh Sort includes.
 1.3 19-Dec-2021  riastradh Get drm to build on arm64 again.


Author: Jared McNeill <jmcneill@NetBSD.org>
Committer: Taylor R Campbell <riastradh@NetBSD.org>
 1.2 04-Jan-2020  jmcneill branches: 1.2.4; 1.2.8;
Emit PMFE_DISPLAY_{ON,OFF} events in response to DPMS requests.
 1.1 19-Dec-2019  jakllsch add Analogix DisplayPort core driver
 1.2.8.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.2.8.1 04-Jan-2020  martin file anx_dp.h was added on branch phil-wifi on 2020-04-08 14:08:06 +0000
 1.2.4.2 21-Jan-2020  martin Pull up following revision(s) (requested by mrg in ticket #616):

sys/dev/ic/anx_dp.c: revision 1.2
sys/arch/evbarm/conf/GENERIC64: revision 1.126
sys/dev/ic/anx_dp.h: revision 1.1
sys/arch/evbarm/conf/GENERIC64: revision 1.128
sys/dev/ic/anx_dp.h: revision 1.2
sys/dev/fdt/dwcmmc_fdt.c: revision 1.9
sys/dev/i2c/cwfg.c: revision 1.1
sys/conf/files: revision 1.1247
sys/dev/fdt/pwm_backlight.c: revision 1.5
sys/dev/fdt/pwm_backlight.c: revision 1.6
sys/arch/arm/rockchip/rk3399_cru.c: revision 1.14
sys/arch/arm/rockchip/rk3399_cru.c: revision 1.15
sys/arch/arm/rockchip/rk3399_cru.c: revision 1.16
sys/arch/arm/rockchip/rk3399_cru.c: revision 1.17
sys/dev/ic/dwc_mmc.c: revision 1.20
sys/arch/arm/rockchip/rk3399_cru.c: revision 1.18
sys/arch/arm/rockchip/rk3399_cru.c: revision 1.19
sys/dev/usb/usbdevs: revision 1.775
sys/arch/arm/rockchip/rk_dwhdmi.c: revision 1.4
sys/dev/fdt/simple_amplifier.c: revision 1.1
sys/dev/i2c/files.i2c: revision 1.105
sys/arch/evbarm/conf/GENERIC64: revision 1.117
sys/arch/evbarm/conf/GENERIC64: revision 1.118
sys/dev/i2c/files.i2c: revision 1.107
sys/dev/fdt/files.fdt: revision 1.49
sys/arch/arm/rockchip/rk_anxdp.c: revision 1.1
sys/dev/ic/dwc_mmc_var.h: revision 1.9
sys/dev/i2c/rkpmic.c: revision 1.4
sys/arch/arm/rockchip/rk_anxdp.c: revision 1.2
sys/dev/i2c/rkpmic.c: revision 1.5
sys/dev/i2c/rkpmic.c: revision 1.6
sys/arch/arm/rockchip/rk_vop.c: revision 1.4
sys/arch/arm/rockchip/rk_vop.c: revision 1.5
sys/dev/i2c/rkpmic.c: revision 1.8
sys/arch/arm/dts/rk3399-pinebook-pro.dts: revision 1.1
sys/dev/usb/ums.c: revision 1.96 (via patch)
sys/arch/arm/rockchip/rk_pwm.c: revision 1.3
sys/arch/arm/dts/rk3399-pinebook-pro.dts: revision 1.2
sys/dev/i2c/es8316ac.c: revision 1.1
sys/dev/fdt/dwcmmc_fdt.c: revision 1.10
sys/dev/i2c/es8316ac.c: revision 1.2
sys/dev/fdt/fdt_panel.c: revision 1.1
sys/dev/ic/dwc_mmc.c: revision 1.18
sys/dev/fdt/fdt_panel.c: revision 1.2
sys/dev/ic/dwc_mmc.c: revision 1.19
sys/arch/arm/dts/rk3399-rockpro64.dts: revision 1.10
sys/dev/fdt/fdt_port.c: revision 1.5
sys/dev/ic/dwc_mmc_var.h: revision 1.10
sys/dev/fdt/fdt_port.c: revision 1.6
sys/arch/evbarm/conf/GENERIC64: revision 1.122
sys/dev/ic/dwc_mmc_var.h: revision 1.11
sys/dev/fdt/files.fdt: revision 1.50
sys/arch/evbarm/conf/GENERIC64: revision 1.123
sys/arch/arm/rockchip/rk_i2s.c: revision 1.2
sys/arch/arm/rockchip/files.rockchip: revision 1.23
sys/arch/evbarm/conf/GENERIC64: revision 1.124
sys/dev/ic/anx_dp.c: revision 1.1

rkpmic: add RTC support; register w/ todr(9)
rkpmic: correct delay
Add support for SDIO interrupts.
fix copy/paste error in mux_pll_src_cpll_gpll_ppll_parents[]
add RK3399 eDP clocks
add RK3399 DisplayPort clocks
style fix/KNF
rk3399_cru: implement dclk_vop0_frac and dclk_vop1_frac
Move drm_encoder from rkvop(4) to the SoC-layer output pipe drivers (rk_dwhdmi).
rkvop: set stride using virtual framebuffer width instead of display mode
rk3399_cru: Reparent dclk_vop[01] to gpll via dclk_vop[01]_frac.
The previous source of dclk_vop[01] was vpll via dclk_vop[01]_div.
vpll is apparently used directly as a pixel clock source for the
HDMI PHY, and we don't want the other VOP's dclk changing out from
under it because we can't handle finding a replacement clock source
with the right rate yet.
gpll happens to run at 594MHz, which works well as a basis for pixel
clocks.
Linux suggests that the source clock of the fractional divider needs
to be more than twenty times greater than the resulting clock (or some
intermediate clock?) for output stability. This may not be the case
with 594MHz and the common pixel clocks I see used by displays in my
area of the wild, but it works for now.
add Analogix DisplayPort core driver
add Rockchip (RK3399) glue for Analogix DisplayPort core
add anxdp(4)
Add another panel@fdt driver, this time for DRM-style panels.
To do: migrate away from other panel driver.
enable panel at fdt drivers
paper over the rkpwm get_conf function that otherwise doesn't seem to
let things work
add template bits for optional eDP panel on RockPro64
Abort panel driver attach if required regulator is missing.
Add clk provider
Add Pinebook Pro dts, from Manjaro Linux.
https://gitlab.manjaro.org/tsys/linux-pinebook-pro/blob/877ca0e7283596f37845de50dc36bff5b88b91e1/arch/arm64/boot/dts/rockchip/rk3399-pinebook-pro.dts
+ rk3399-pinebook-pro.dts
Attach mmcpwrseq resource earlier
dwcmmc improvements:
- Use mmcpwrseq resources if available
- Only set 4- or 8-bit mode if specified in the dt properties
- Add quirk for implementations with inverted power enable logic
- Support switching signal voltage between 1.8V and 3.3V
- Fix a clock divider issue on Rockchip SoCs
Fix performance regression with previous
Quiet chatty printfs
No need to print all supported levels at attach, print the range and total number of steps
Disable SPI for now (rkspi driver hangs at boot)
Add driver for simple-audio-amplifier binding
Add driver for Everest Semi ES8316 Low Power Audio CODEC
add es8316, simpleamp
Avoid sleeping while the audio intr lock is held.
If the rockchip,system-power-controller property is present, try to power off with the PMIC
Add HAILUCK keyboard (product 1e)
Add a quirk for the HAILUCK USB keyboard / touchpad device with product 1e.
The keyboard does not function properly unless the touchpad's intr endpoint
is active.
Add driver for CellWise CW2015 Fuel Gauge IC.
add cwfg
Emit PMFE_DISPLAY_{ON,OFF} events in response to DPMS requests.
If the backlight node does not have an enable gpio, set the lowest duty
cycle to turn the display off instead.
Attach psci as early as possible. This allows other power controllers to
register their own poweroff / reset callbacks with a higher preference.
Add 2000 MHz to available armclkb rates
Remove debug printfs
 1.2.4.1 04-Jan-2020  martin file anx_dp.h was added on branch netbsd-9 on 2020-01-21 10:39:58 +0000
 1.6 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.5 11-Dec-2005  christos branches: 1.5.70; 1.5.72; 1.5.74;
merge ktrace-lwp.
 1.4 10-Sep-2003  uwe Define APC DMA registers as offsets for bus space ops, so that we can
avoid linear mapping. Actually, cs4231_sbus.c is already converted to
not use linear mapping of DMA registers, but it uses quick and
disgusting hack.
 1.3 12-Mar-2002  uwe branches: 1.3.12;
Rework the driver to add EBus DMA support and improve APC DMA support.
Audio-related stuff is left almost intact.

* support audiocs at ebus playback and capture
tested on krups and u5 (thanks, martin)
* make first attempt at supporting audiocs at sbus capture
* nb: full-duplex is not tested
* while here, fix CSAUDIO_MONITOR_MUTE to be of CSAUDIO_MONITOR_CLASS
i.e. outputs.monitor.mute -> monitor.monitor.mute

Ok by pk, eeh.
 1.2 16-Jun-2000  pk branches: 1.2.4; 1.2.6;
Comply with bus_dma(9) specs.
 1.1 05-Jun-1999  mrg branches: 1.1.2; 1.1.4; 1.1.12;
split sbus audiocs code up so we can share it with the ebus. XXX ebus DMA is probably different.
 1.1.12.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.1.4.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.1.2.1 21-Jun-1999  thorpej Sync w/ -current.
 1.2.6.1 16-Mar-2002  jdolecek Catch up with -current.
 1.2.4.1 01-Apr-2002  nathanw Catch up to -current.
(CVS: It's not just a program. It's an adventure!)
 1.3.12.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.3.12.2 18-Sep-2004  skrll Sync with HEAD.
 1.3.12.1 03-Aug-2004  skrll Sync with HEAD
 1.5.74.1 16-May-2008  yamt sync with head.
 1.5.72.1 18-May-2008  yamt sync with head.
 1.5.70.1 02-Jun-2008  mjf Sync with HEAD.
 1.9 08-Aug-2023  mrg fix array vs pointer function declaration.

also, in some callers, and make sure to provide all the accessed
backing for a string array.

found by GCC 12.
 1.8 07-Aug-2021  thorpej Merge thorpej-cfargs2.
 1.7 24-Apr-2021  thorpej branches: 1.7.8;
Merge thorpej-cfargs branch:

Simplify and make extensible the config_search() / config_found() /
config_attach() interfaces: rather than having different variants for
which arguments you want pass along, just have a single call that
takes a variadic list of tag-value arguments.

Adjust all call sites:
- Simplify wherever possible; don't pass along arguments that aren't
actually needed.
- Don't be explicit about what interface attribute is attaching if
the device only has one. (More simplification.)
- Add a config_probe() function to be used in indirect configuiration
situations, making is visibly easier to see when indirect config is
in play, and allowing for future change in semantics. (As of now,
this is just a wrapper around config_match(), but that is an
implementation detail.)

Remove unnecessary or redundant interface attributes where they're not
needed.

There are currently 5 "cfargs" defined:
- CFARG_SUBMATCH (submatch function for direct config)
- CFARG_SEARCH (search function for indirect config)
- CFARG_IATTR (interface attribte)
- CFARG_LOCATORS (locators array)
- CFARG_DEVHANDLE (devhandle_t - wraps OFW, ACPI, etc. handles)

...and a sentinel value CFARG_EOL.

Add some extra sanity checking to ensure that interface attributes
aren't ambiguous.

Use CFARG_DEVHANDLE in MI FDT, OFW, and ACPI code, and macppc and shark
ports to associate those device handles with device_t instance. This
will trickle trough to more places over time (need back-end for pre-OFW
Sun OBP; any others?).
 1.6 25-Apr-2014  riastradh branches: 1.6.2; 1.6.4; 1.6.8; 1.6.50;
Fix binary search logic.

Doesn't matter for the one user of this, but still.
 1.5 01-Apr-2014  riastradh branches: 1.5.2;
Fix copypasta error in apple_smc_write_key_4: uint32_t, not uint16_t.
 1.4 01-Apr-2014  riastradh Polish the Apple SMC code with commentary and little fixes.
 1.3 01-Apr-2014  riastradh Rework Apple SMC device attachment goo again.

Less bookkeeping at the expense of iteration over all devices when
rescanning applesmc.
 1.2 01-Apr-2014  riastradh Rework Apple SMC attachment goo and split into multiple modules.

The four modules are apple_smc for the core functions, apple_smc_acpi
for attachment at acpi, and apple_smc_fan & apple_smc_temp for stuff
on the SMC.

Seems like there's a lot more bookkeeping necessary to maintain
children of an applesmc device implemented by loadable modules.
Maybe there's a better way I just haven't figured out yet.
 1.1 01-Apr-2014  riastradh First draft of drivers for the Apple System Management Controller.

Device interface derived by reading the Linux driver source code and
<http:///www.parhelia.ch/blog/statics/k3_keys.html> as of 2012-12-05.

Includes support for attaching fan and temperature sensors to sysmon.
No accelerometer yet.

Compile-tested only, based on some run-testing of experiments from
userland. Module attachment is not quite finished, so it won't work
yet.
 1.5.2.1 10-Aug-2014  tls Rebase.
 1.6.50.5 05-Apr-2021  thorpej config_match() -> config_probe() for the straight-forward indirect config
cases. There are still a few odd balls using config_match() which should
be sorted out later.
 1.6.50.4 04-Apr-2021  thorpej CFARG_SUBMATCH -> CFARG_SEARCH for the indirect configuration uses.
 1.6.50.3 03-Apr-2021  thorpej config_attach_loc() -> config_attach() with CFARG_LOCATORS argument.
 1.6.50.2 28-Mar-2021  thorpej This driver only has a single interface attribute, so no need to be expicit
about it. That interface attribute has no locators, so don't pass them
to config_search().
 1.6.50.1 20-Mar-2021  thorpej The proliferation if config_search_*() and config_found_*() combinations
is a little absurd, so begin to tidy this up:

- Introduce a new cfarg_t enumerated type, that defines the types of
tag-value variadic arguments that can be passed to the various
config_*() functions (CFARG_SUBMATCH, CFARG_IATTR, and CFARG_LOCATORS,
for now, plus a CFARG_EOL sentinel).
- Collapse config_search_*() into config_search() that takes these
variadic arguments.
- Convert all call sites of config_search_*() to the new signature.
Noticed several incorrect usages along the way, which will be
audited in a future commit.
 1.6.8.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.6.8.1 25-Apr-2014  tls file apple_smc.c was added on branch tls-maxphys on 2014-08-20 00:03:37 +0000
 1.6.4.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.6.4.1 25-Apr-2014  yamt file apple_smc.c was added on branch yamt-pagecache on 2014-05-22 11:40:21 +0000
 1.6.2.2 18-May-2014  rmind sync with head
 1.6.2.1 25-Apr-2014  rmind file apple_smc.c was added on branch rmind-smpnet on 2014-05-18 17:45:37 +0000
 1.7.8.1 04-Aug-2021  thorpej Adapt to CFARGS().
 1.3 01-Apr-2014  riastradh branches: 1.3.4; 1.3.6; 1.3.10;
Rework Apple SMC device attachment goo again.

Less bookkeeping at the expense of iteration over all devices when
rescanning applesmc.
 1.2 01-Apr-2014  riastradh Rework Apple SMC attachment goo and split into multiple modules.

The four modules are apple_smc for the core functions, apple_smc_acpi
for attachment at acpi, and apple_smc_fan & apple_smc_temp for stuff
on the SMC.

Seems like there's a lot more bookkeeping necessary to maintain
children of an applesmc device implemented by loadable modules.
Maybe there's a better way I just haven't figured out yet.
 1.1 01-Apr-2014  riastradh First draft of drivers for the Apple System Management Controller.

Device interface derived by reading the Linux driver source code and
<http:///www.parhelia.ch/blog/statics/k3_keys.html> as of 2012-12-05.

Includes support for attaching fan and temperature sensors to sysmon.
No accelerometer yet.

Compile-tested only, based on some run-testing of experiments from
userland. Module attachment is not quite finished, so it won't work
yet.
 1.3.10.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.3.10.1 01-Apr-2014  tls file apple_smc.h was added on branch tls-maxphys on 2014-08-20 00:03:37 +0000
 1.3.6.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.3.6.1 01-Apr-2014  yamt file apple_smc.h was added on branch yamt-pagecache on 2014-05-22 11:40:21 +0000
 1.3.4.2 18-May-2014  rmind sync with head
 1.3.4.1 01-Apr-2014  rmind file apple_smc.h was added on branch rmind-smpnet on 2014-05-18 17:45:37 +0000
 1.6 29-Jun-2022  mlelstv Don't unregister sensors twice.
 1.5 23-Apr-2015  pgoyette Update module dependencies for all the existing modules that depend on sysmon components.
 1.4 01-Apr-2014  riastradh branches: 1.4.4; 1.4.6; 1.4.10; 1.4.12;
Polish the Apple SMC code with commentary and little fixes.
 1.3 01-Apr-2014  riastradh Rework Apple SMC device attachment goo again.

Less bookkeeping at the expense of iteration over all devices when
rescanning applesmc.
 1.2 01-Apr-2014  riastradh Rework Apple SMC attachment goo and split into multiple modules.

The four modules are apple_smc for the core functions, apple_smc_acpi
for attachment at acpi, and apple_smc_fan & apple_smc_temp for stuff
on the SMC.

Seems like there's a lot more bookkeeping necessary to maintain
children of an applesmc device implemented by loadable modules.
Maybe there's a better way I just haven't figured out yet.
 1.1 01-Apr-2014  riastradh First draft of drivers for the Apple System Management Controller.

Device interface derived by reading the Linux driver source code and
<http:///www.parhelia.ch/blog/statics/k3_keys.html> as of 2012-12-05.

Includes support for attaching fan and temperature sensors to sysmon.
No accelerometer yet.

Compile-tested only, based on some run-testing of experiments from
userland. Module attachment is not quite finished, so it won't work
yet.
 1.4.12.1 06-Jun-2015  skrll Sync with HEAD
 1.4.10.3 03-Dec-2017  jdolecek update from HEAD
 1.4.10.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.4.10.1 01-Apr-2014  tls file apple_smc_fan.c was added on branch tls-maxphys on 2014-08-20 00:03:37 +0000
 1.4.6.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.4.6.1 01-Apr-2014  yamt file apple_smc_fan.c was added on branch yamt-pagecache on 2014-05-22 11:40:21 +0000
 1.4.4.2 18-May-2014  rmind sync with head
 1.4.4.1 01-Apr-2014  rmind file apple_smc_fan.c was added on branch rmind-smpnet on 2014-05-18 17:45:37 +0000
 1.7 08-Aug-2023  mrg fix array vs pointer function declaration.

also, in some callers, and make sure to provide all the accessed
backing for a string array.

found by GCC 12.
 1.6 29-Jun-2022  mlelstv Don't unregister sensors twice.
 1.5 23-Apr-2015  pgoyette Update module dependencies for all the existing modules that depend on sysmon components.
 1.4 01-Apr-2014  riastradh branches: 1.4.4; 1.4.6; 1.4.10; 1.4.12;
Polish the Apple SMC code with commentary and little fixes.
 1.3 01-Apr-2014  riastradh Rework Apple SMC device attachment goo again.

Less bookkeeping at the expense of iteration over all devices when
rescanning applesmc.
 1.2 01-Apr-2014  riastradh Rework Apple SMC attachment goo and split into multiple modules.

The four modules are apple_smc for the core functions, apple_smc_acpi
for attachment at acpi, and apple_smc_fan & apple_smc_temp for stuff
on the SMC.

Seems like there's a lot more bookkeeping necessary to maintain
children of an applesmc device implemented by loadable modules.
Maybe there's a better way I just haven't figured out yet.
 1.1 01-Apr-2014  riastradh First draft of drivers for the Apple System Management Controller.

Device interface derived by reading the Linux driver source code and
<http:///www.parhelia.ch/blog/statics/k3_keys.html> as of 2012-12-05.

Includes support for attaching fan and temperature sensors to sysmon.
No accelerometer yet.

Compile-tested only, based on some run-testing of experiments from
userland. Module attachment is not quite finished, so it won't work
yet.
 1.4.12.1 06-Jun-2015  skrll Sync with HEAD
 1.4.10.3 03-Dec-2017  jdolecek update from HEAD
 1.4.10.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.4.10.1 01-Apr-2014  tls file apple_smc_temp.c was added on branch tls-maxphys on 2014-08-20 00:03:37 +0000
 1.4.6.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.4.6.1 01-Apr-2014  yamt file apple_smc_temp.c was added on branch yamt-pagecache on 2014-05-22 11:40:21 +0000
 1.4.4.2 18-May-2014  rmind sync with head
 1.4.4.1 01-Apr-2014  rmind file apple_smc_temp.c was added on branch rmind-smpnet on 2014-05-18 17:45:37 +0000
 1.1 01-Apr-2014  riastradh branches: 1.1.4; 1.1.6; 1.1.10;
First draft of drivers for the Apple System Management Controller.

Device interface derived by reading the Linux driver source code and
<http:///www.parhelia.ch/blog/statics/k3_keys.html> as of 2012-12-05.

Includes support for attaching fan and temperature sensors to sysmon.
No accelerometer yet.

Compile-tested only, based on some run-testing of experiments from
userland. Module attachment is not quite finished, so it won't work
yet.
 1.1.10.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.1.10.1 01-Apr-2014  tls file apple_smcreg.h was added on branch tls-maxphys on 2014-08-20 00:03:37 +0000
 1.1.6.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.1.6.1 01-Apr-2014  yamt file apple_smcreg.h was added on branch yamt-pagecache on 2014-05-22 11:40:21 +0000
 1.1.4.2 18-May-2014  rmind sync with head
 1.1.4.1 01-Apr-2014  rmind file apple_smcreg.h was added on branch rmind-smpnet on 2014-05-18 17:45:37 +0000
 1.4 01-Apr-2014  riastradh branches: 1.4.4; 1.4.6; 1.4.10;
Polish the Apple SMC code with commentary and little fixes.
 1.3 01-Apr-2014  riastradh Rework Apple SMC device attachment goo again.

Less bookkeeping at the expense of iteration over all devices when
rescanning applesmc.
 1.2 01-Apr-2014  riastradh Rework Apple SMC attachment goo and split into multiple modules.

The four modules are apple_smc for the core functions, apple_smc_acpi
for attachment at acpi, and apple_smc_fan & apple_smc_temp for stuff
on the SMC.

Seems like there's a lot more bookkeeping necessary to maintain
children of an applesmc device implemented by loadable modules.
Maybe there's a better way I just haven't figured out yet.
 1.1 01-Apr-2014  riastradh First draft of drivers for the Apple System Management Controller.

Device interface derived by reading the Linux driver source code and
<http:///www.parhelia.ch/blog/statics/k3_keys.html> as of 2012-12-05.

Includes support for attaching fan and temperature sensors to sysmon.
No accelerometer yet.

Compile-tested only, based on some run-testing of experiments from
userland. Module attachment is not quite finished, so it won't work
yet.
 1.4.10.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.4.10.1 01-Apr-2014  tls file apple_smcvar.h was added on branch tls-maxphys on 2014-08-20 00:03:37 +0000
 1.4.6.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.4.6.1 01-Apr-2014  yamt file apple_smcvar.h was added on branch yamt-pagecache on 2014-05-22 11:40:21 +0000
 1.4.4.2 18-May-2014  rmind sync with head
 1.4.4.1 01-Apr-2014  rmind file apple_smcvar.h was added on branch rmind-smpnet on 2014-05-18 17:45:37 +0000
 1.4 31-May-2022  andvar fix various typos in comments, documentation and messages.
 1.3 08-Jun-2019  isaki Clean get_props().
- Make get_props() return AUDIO_PROP_{PLAYBACK,CAPTURE} properly.
This eliminates need for audio.c to take care of such (old)
drivers which don't return both of PLAYBACK and CAPTURE.
- All get_props() doesn't need to return AUDIO_PROP_MMAP.
It is handled in the audio layer now.
 1.2 08-May-2019  isaki Merge isaki-audio2 branch, the overhaul of audio subsystem.
- Interrupt-oriented system rather than thread-oriented.
- Improve stability, quality and performance.
- Split playback and record cleanly. Improve halfduplex support.
- Many bugs are fixed including deadlocks, resource leaks, abuses, etc.
- Simplify audio filter mechanism. The encoding/channels/frequency
conversions are completely handled in the upper layer. So the hard-
ware driver only converts its hardware encoding (if necessary).
- audio_hw_if changes:
- Obsoletes query_encoding and add query_format instead.
- Obsoletes set_params and add set_format instead.
- Remove drain, setfd, mappage.
- The call sequences are changed.
- ioctl AUDIO_GETFD/SETFD, AUDIO_GETCHAN/SETCHAN are obsoleted.
- ioctl AUDIO_{QUERY,GET,SET}FORMAT are introduced.
- cleanup config attributes: au*conv and mulaw.
- All hardware drivers should follow it (I've done as much as possible).

Some file paths are changed:
- dev/audio.c -> dev/audio/audio.c (rewritten)
- dev/audiovar.h -> dev/audio/audiovar.h
- dev/audio_dai.h -> dev/audio/audio_dai.h
- dev/audio_if.h -> dev/audio/audio_if.h
- dev/audiobell.c -> dev/audio/audiobell.c
- dev/audiobellvar.h -> dev/audio/audiobellvar.h
- dev/mulaw.[ch] -> dev/audio/mulaw.[ch] + dev/audio/alaw.c
 1.1 24-Aug-2014  tsutsui branches: 1.1.2; 1.1.20; 1.1.24; 1.1.28;
Add new arcofi(4) audio driver for NetBSD/hp300, ported from OpenBSD.

The arcofi(4) is a driver for the HP "Audio1" device
(Siemens PSB 2160 "ARCOFI" phone quality audio chip)
found on the HP9000/425e and HP9000/{705,710,745,747} models
(but only hp300 attachment is ported for now).
The chip supports 8-bit mono 8kHz U-law, A-law and
16-bit mono slinear_be formats.

The old HP9000/425e playing tunes with this new arcofi(4) audio driver
was also demonstrated at Open Source Conference 2014 Shimane.
 1.1.28.6 04-May-2019  isaki Move dev/audio_if.h -> dev/audio/audio_if.h
 1.1.28.5 04-May-2019  isaki Remove simple flags that indicate whether the device is opened.
These are handled in the upper layer now.
 1.1.28.4 04-May-2019  isaki Remove obsoleted methods in audio_hw_if.
- drain: is handled in audio upper layer now.
- mappage: is handled in audio upper layer now.
- setfd: no one uses and it's meaningless now.
 1.1.28.3 21-Apr-2019  isaki Oops, add accidentally dropped chunks.
 1.1.28.2 21-Apr-2019  isaki Adapt to audio2.
- Use mulaw as default format. HW supports slinear_be:16 actually
but it's hard to use due to several hardware restrictions.
- Improve data transfer and interrupt.
Tested by tsutsui@ (a few months ago). Thank you.
 1.1.28.1 21-Apr-2019  isaki Use C99 style struct initializer to audio_format.
 1.1.24.1 10-Jun-2019  christos Sync with HEAD
 1.1.20.2 03-Dec-2017  jdolecek update from HEAD
 1.1.20.1 24-Aug-2014  jdolecek file arcofi.c was added on branch tls-maxphys on 2017-12-03 11:37:03 +0000
 1.1.2.2 29-Aug-2014  martin Pull up following revision(s) (requested by tsutsui in ticket #62):
sys/arch/hp300/conf/files.hp300: revision 1.89
share/man/man4/arcofi.4: revision 1.1
share/man/man4/arcofi.4: revision 1.2
share/man/man4/Makefile: revision 1.617
sys/arch/hp300/hp300/intr.c: revision 1.41
sys/conf/files: revision 1.1100
sys/arch/hp300/hp300/locore.s: revision 1.171
distrib/sets/lists/man/mi: revision 1.1486
sys/dev/ic/arcofivar.h: revision 1.1
sys/arch/hp300/conf/majors.hp300: revision 1.26
sys/arch/hp300/dev/arcofi_dio.c: revision 1.1
sys/arch/hp300/conf/GENERIC: revision 1.188
sys/dev/ic/arcofi.c: revision 1.1
Add new arcofi(4) audio driver for NetBSD/hp300, ported from OpenBSD.
The arcofi(4) is a driver for the HP "Audio1" device
(Siemens PSB 2160 "ARCOFI" phone quality audio chip)
found on the HP9000/425e and HP9000/{705,710,745,747} models
(but only hp300 attachment is ported for now).
The chip supports 8-bit mono 8kHz U-law, A-law and
16-bit mono slinear_be formats.
The old HP9000/425e playing tunes with this new arcofi(4) audio driver
was also demonstrated at Open Source Conference 2014 Shimane.
Add a man page for arcofi(4) driver. From OpenBSD.
Fix date.
 1.1.2.1 24-Aug-2014  martin file arcofi.c was added on branch netbsd-7 on 2014-08-29 11:42:15 +0000
 1.2 08-May-2019  isaki Merge isaki-audio2 branch, the overhaul of audio subsystem.
- Interrupt-oriented system rather than thread-oriented.
- Improve stability, quality and performance.
- Split playback and record cleanly. Improve halfduplex support.
- Many bugs are fixed including deadlocks, resource leaks, abuses, etc.
- Simplify audio filter mechanism. The encoding/channels/frequency
conversions are completely handled in the upper layer. So the hard-
ware driver only converts its hardware encoding (if necessary).
- audio_hw_if changes:
- Obsoletes query_encoding and add query_format instead.
- Obsoletes set_params and add set_format instead.
- Remove drain, setfd, mappage.
- The call sequences are changed.
- ioctl AUDIO_GETFD/SETFD, AUDIO_GETCHAN/SETCHAN are obsoleted.
- ioctl AUDIO_{QUERY,GET,SET}FORMAT are introduced.
- cleanup config attributes: au*conv and mulaw.
- All hardware drivers should follow it (I've done as much as possible).

Some file paths are changed:
- dev/audio.c -> dev/audio/audio.c (rewritten)
- dev/audiovar.h -> dev/audio/audiovar.h
- dev/audio_dai.h -> dev/audio/audio_dai.h
- dev/audio_if.h -> dev/audio/audio_if.h
- dev/audiobell.c -> dev/audio/audiobell.c
- dev/audiobellvar.h -> dev/audio/audiobellvar.h
- dev/mulaw.[ch] -> dev/audio/mulaw.[ch] + dev/audio/alaw.c
 1.1 24-Aug-2014  tsutsui branches: 1.1.2; 1.1.20; 1.1.24; 1.1.28;
Add new arcofi(4) audio driver for NetBSD/hp300, ported from OpenBSD.

The arcofi(4) is a driver for the HP "Audio1" device
(Siemens PSB 2160 "ARCOFI" phone quality audio chip)
found on the HP9000/425e and HP9000/{705,710,745,747} models
(but only hp300 attachment is ported for now).
The chip supports 8-bit mono 8kHz U-law, A-law and
16-bit mono slinear_be formats.

The old HP9000/425e playing tunes with this new arcofi(4) audio driver
was also demonstrated at Open Source Conference 2014 Shimane.
 1.1.28.2 04-May-2019  isaki Remove simple flags that indicate whether the device is opened.
These are handled in the upper layer now.
 1.1.28.1 21-Apr-2019  isaki Adapt to audio2.
- Use mulaw as default format. HW supports slinear_be:16 actually
but it's hard to use due to several hardware restrictions.
- Improve data transfer and interrupt.
Tested by tsutsui@ (a few months ago). Thank you.
 1.1.24.1 10-Jun-2019  christos Sync with HEAD
 1.1.20.2 03-Dec-2017  jdolecek update from HEAD
 1.1.20.1 24-Aug-2014  jdolecek file arcofivar.h was added on branch tls-maxphys on 2017-12-03 11:37:03 +0000
 1.1.2.2 29-Aug-2014  martin Pull up following revision(s) (requested by tsutsui in ticket #62):
sys/arch/hp300/conf/files.hp300: revision 1.89
share/man/man4/arcofi.4: revision 1.1
share/man/man4/arcofi.4: revision 1.2
share/man/man4/Makefile: revision 1.617
sys/arch/hp300/hp300/intr.c: revision 1.41
sys/conf/files: revision 1.1100
sys/arch/hp300/hp300/locore.s: revision 1.171
distrib/sets/lists/man/mi: revision 1.1486
sys/dev/ic/arcofivar.h: revision 1.1
sys/arch/hp300/conf/majors.hp300: revision 1.26
sys/arch/hp300/dev/arcofi_dio.c: revision 1.1
sys/arch/hp300/conf/GENERIC: revision 1.188
sys/dev/ic/arcofi.c: revision 1.1
Add new arcofi(4) audio driver for NetBSD/hp300, ported from OpenBSD.
The arcofi(4) is a driver for the HP "Audio1" device
(Siemens PSB 2160 "ARCOFI" phone quality audio chip)
found on the HP9000/425e and HP9000/{705,710,745,747} models
(but only hp300 attachment is ported for now).
The chip supports 8-bit mono 8kHz U-law, A-law and
16-bit mono slinear_be formats.
The old HP9000/425e playing tunes with this new arcofi(4) audio driver
was also demonstrated at Open Source Conference 2014 Shimane.
Add a man page for arcofi(4) driver. From OpenBSD.
Fix date.
 1.1.2.1 24-Aug-2014  martin file arcofivar.h was added on branch netbsd-7 on 2014-08-29 11:42:15 +0000
 1.20 05-Jul-2024  rin sys: Drop redundant NULL check before m_freem(9)

m_freem(9) safely has accepted NULL argument at least since 4.2BSD:
https://www.tuhs.org/cgi-bin/utree.pl?file=4.2BSD/usr/src/sys/sys/uipc_mbuf.c

Compile-tested on amd64/ALL.

Suggested by knakahara@
 1.19 18-Mar-2022  riastradh branches: 1.19.10;
net80211: Use getticks(), not hardclock_ticks.

Less extern in .c this way too.
 1.18 07-Sep-2020  mrg in ar5008_set_viterbi_mask() be sure to initialise m[0].
 1.17 29-Jan-2020  thorpej Adopt <net/if_stats.h>.
 1.16 10-Nov-2019  chs branches: 1.16.2;
in many device attach paths, allocate memory with M_WAITOK instead of M_NOWAIT
and remove code to handle failures that can no longer happen.
 1.15 26-Jun-2018  msaitoh branches: 1.15.2;
Implement the BPF direction filter (BIOC[GS]DIRECTION). It provides backward
compatibility with BIOC[GS]SEESENT ioctl. The userland interface is the same
as FreeBSD.

This change also fixes a bug that the direction is misunderstand on some
environment by passing the direction to bpf_mtap*() instead of checking
m->m_pkthdr.rcvif.
 1.14 01-Feb-2018  maxv branches: 1.14.2;
Replace ovbcopy -> memmove, same.
 1.13 23-May-2017  ozaki-r Apply deferred if_start to more drivers

And annotate some XXX_start as it runs in softint to clarify that
it doesn't need deferred if_start.
 1.12 02-Feb-2017  nonaka wlan interfaces make interrupt routine running on softint context.

see http://mail-index.netbsd.org/tech-kern/2016/12/06/msg021281.html

tested device:
* ath at pci: AR5212, AR5424
* athn at pci: AR9287
* ipw at pci: 2100BG
* iwi at pci: 2915ABG
* iwm at pci: 3165, 7260, 8260
* iwn at pci: 4945, 6235
* ral at pci: RT2560
* rtwn at pci: RTL8192CE
 1.11 10-Jun-2016  ozaki-r branches: 1.11.2; 1.11.4;
Introduce m_set_rcvif and m_reset_rcvif

The API is used to set (or reset) a received interface of a mbuf.
They are counterpart of m_get_rcvif, which will come in another
commit, hide internal of rcvif operation, and reduce the diff of
the upcoming change.

No functional change.
 1.10 09-Mar-2016  christos PR/50926: David Binderman: Fix wrong paren
 1.9 30-May-2015  jmcneill disable interrupts when we get an rfsilent event, and make sure to clear intr sync cause register
 1.8 24-May-2015  matt remove errant &
 1.7 24-May-2015  matt Use bus_dmamap_load instead of bus_dmamap_load_raw
 1.6 23-Feb-2014  christos branches: 1.6.4; 1.6.8;
use aprint.
 1.5 22-Oct-2013  skrll Avoid "declaration of 'delay' shadows a global declaration" by renaming
the local variable.
 1.4 17-Oct-2013  christos - remove unused variables
- move variables inside ifdef sections
- ifdef notdef unused code
- use __USE for debugging variables
 1.3 06-Apr-2013  martin branches: 1.3.4; 1.3.6;
Debounce the "wlan button pressed" event via pmf PMFE_RADIO_OFF so we
can run the pmf stuff in thread context.
 1.2 03-Apr-2013  christos instead of ifnet use ethercom.
 1.1 30-Mar-2013  christos This is the initial port of OpenBSD's athn(4) driver. It supports
quite a few Atheros 802.11n devices. See the athn(4) manpage for a
list.

This port has only been tested with a TP-LINK TL-WN722N USB adapter
which has an AR9271 chipset (VENDOR: 0x0cf3, PRODUCT: 0x9271). The
BSS, Monitor, and HostAP modes all seem to work on that adapter,
though the later has not been tested much.

The driver also supports PCI and CardBUS devices, but those interfaces
are completely untested and probably won't work at this point.

If someone can provide me with other adapters that should be
supported, particularly PCI or CardBUS adapters, or tell me where I
can get one cheaply, I would be happy to try to get the driver working
on those devices as well.
 1.3.6.1 18-May-2014  rmind sync with head
 1.3.4.4 03-Dec-2017  jdolecek update from HEAD
 1.3.4.3 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.3.4.2 23-Jun-2013  tls resync from head
 1.3.4.1 06-Apr-2013  tls file arn5008.c was added on branch tls-maxphys on 2013-06-23 06:20:17 +0000
 1.6.8.5 28-Aug-2017  skrll Sync with HEAD
 1.6.8.4 05-Feb-2017  skrll Sync with HEAD
 1.6.8.3 09-Jul-2016  skrll Sync with HEAD
 1.6.8.2 19-Mar-2016  skrll Sync with HEAD
 1.6.8.1 06-Jun-2015  skrll Sync with HEAD
 1.6.4.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.6.4.1 23-Feb-2014  yamt file arn5008.c was added on branch yamt-pagecache on 2014-05-22 11:40:21 +0000
 1.11.4.1 21-Apr-2017  bouyer Sync with HEAD
 1.11.2.1 20-Mar-2017  pgoyette Sync with HEAD
 1.14.2.1 28-Jul-2018  pgoyette Sync with HEAD
 1.15.2.3 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.15.2.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.15.2.1 12-Jul-2018  phil State save. New kernel config for this brach only. TESTWIFI does
produce a kernel. It is not working. athn files not compiling yet
and commented out of the TESTWIFI kernel, which only has urtwn 802.11
driver enabled. ieee80211_alq.c and ieee80211_ddb.c not compiling yet.
 1.16.2.1 29-Feb-2020  ad Sync with head.
 1.19.10.1 02-Aug-2025  perseant Sync with HEAD
 1.2 01-Aug-2023  mrg fix simple mis-matched function prototype and definitions.

most of these are like, eg

void foo(int[2]);

with either of these

void foo(int*) { ... }
void foo(int[]) { ... }

in some cases (such as stat or utimes* calls found in our header files),
we now match standard definition from opengroup.

found by GCC 12.
 1.1 30-Mar-2013  christos branches: 1.1.4; 1.1.12;
This is the initial port of OpenBSD's athn(4) driver. It supports
quite a few Atheros 802.11n devices. See the athn(4) manpage for a
list.

This port has only been tested with a TP-LINK TL-WN722N USB adapter
which has an AR9271 chipset (VENDOR: 0x0cf3, PRODUCT: 0x9271). The
BSS, Monitor, and HostAP modes all seem to work on that adapter,
though the later has not been tested much.

The driver also supports PCI and CardBUS devices, but those interfaces
are completely untested and probably won't work at this point.

If someone can provide me with other adapters that should be
supported, particularly PCI or CardBUS adapters, or tell me where I
can get one cheaply, I would be happy to try to get the driver working
on those devices as well.
 1.1.12.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.1.12.1 30-Mar-2013  yamt file arn5008.h was added on branch yamt-pagecache on 2014-05-22 11:40:21 +0000
 1.1.4.2 23-Jun-2013  tls resync from head
 1.1.4.1 30-Mar-2013  tls file arn5008.h was added on branch tls-maxphys on 2013-06-23 06:20:17 +0000
 1.1 30-Mar-2013  christos branches: 1.1.4; 1.1.12;
This is the initial port of OpenBSD's athn(4) driver. It supports
quite a few Atheros 802.11n devices. See the athn(4) manpage for a
list.

This port has only been tested with a TP-LINK TL-WN722N USB adapter
which has an AR9271 chipset (VENDOR: 0x0cf3, PRODUCT: 0x9271). The
BSS, Monitor, and HostAP modes all seem to work on that adapter,
though the later has not been tested much.

The driver also supports PCI and CardBUS devices, but those interfaces
are completely untested and probably won't work at this point.

If someone can provide me with other adapters that should be
supported, particularly PCI or CardBUS adapters, or tell me where I
can get one cheaply, I would be happy to try to get the driver working
on those devices as well.
 1.1.12.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.1.12.1 30-Mar-2013  yamt file arn5008reg.h was added on branch yamt-pagecache on 2014-05-22 11:40:21 +0000
 1.1.4.2 23-Jun-2013  tls resync from head
 1.1.4.1 30-Mar-2013  tls file arn5008reg.h was added on branch tls-maxphys on 2013-06-23 06:20:17 +0000
 1.3 25-Sep-2022  thorpej Remove unnecessary include of <sys/malloc.h>.
 1.2 03-Apr-2013  christos branches: 1.2.4; 1.2.12;
instead of ifnet use ethercom.
 1.1 30-Mar-2013  christos This is the initial port of OpenBSD's athn(4) driver. It supports
quite a few Atheros 802.11n devices. See the athn(4) manpage for a
list.

This port has only been tested with a TP-LINK TL-WN722N USB adapter
which has an AR9271 chipset (VENDOR: 0x0cf3, PRODUCT: 0x9271). The
BSS, Monitor, and HostAP modes all seem to work on that adapter,
though the later has not been tested much.

The driver also supports PCI and CardBUS devices, but those interfaces
are completely untested and probably won't work at this point.

If someone can provide me with other adapters that should be
supported, particularly PCI or CardBUS adapters, or tell me where I
can get one cheaply, I would be happy to try to get the driver working
on those devices as well.
 1.2.12.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.2.12.1 03-Apr-2013  yamt file arn5416.c was added on branch yamt-pagecache on 2014-05-22 11:40:21 +0000
 1.2.4.2 23-Jun-2013  tls resync from head
 1.2.4.1 03-Apr-2013  tls file arn5416.c was added on branch tls-maxphys on 2013-06-23 06:20:17 +0000
 1.1 30-Mar-2013  christos branches: 1.1.4; 1.1.12;
This is the initial port of OpenBSD's athn(4) driver. It supports
quite a few Atheros 802.11n devices. See the athn(4) manpage for a
list.

This port has only been tested with a TP-LINK TL-WN722N USB adapter
which has an AR9271 chipset (VENDOR: 0x0cf3, PRODUCT: 0x9271). The
BSS, Monitor, and HostAP modes all seem to work on that adapter,
though the later has not been tested much.

The driver also supports PCI and CardBUS devices, but those interfaces
are completely untested and probably won't work at this point.

If someone can provide me with other adapters that should be
supported, particularly PCI or CardBUS adapters, or tell me where I
can get one cheaply, I would be happy to try to get the driver working
on those devices as well.
 1.1.12.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.1.12.1 30-Mar-2013  yamt file arn5416.h was added on branch yamt-pagecache on 2014-05-22 11:40:21 +0000
 1.1.4.2 23-Jun-2013  tls resync from head
 1.1.4.1 30-Mar-2013  tls file arn5416.h was added on branch tls-maxphys on 2013-06-23 06:20:17 +0000
 1.1 30-Mar-2013  christos branches: 1.1.4; 1.1.12;
This is the initial port of OpenBSD's athn(4) driver. It supports
quite a few Atheros 802.11n devices. See the athn(4) manpage for a
list.

This port has only been tested with a TP-LINK TL-WN722N USB adapter
which has an AR9271 chipset (VENDOR: 0x0cf3, PRODUCT: 0x9271). The
BSS, Monitor, and HostAP modes all seem to work on that adapter,
though the later has not been tested much.

The driver also supports PCI and CardBUS devices, but those interfaces
are completely untested and probably won't work at this point.

If someone can provide me with other adapters that should be
supported, particularly PCI or CardBUS adapters, or tell me where I
can get one cheaply, I would be happy to try to get the driver working
on those devices as well.
 1.1.12.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.1.12.1 30-Mar-2013  yamt file arn5416reg.h was added on branch yamt-pagecache on 2014-05-22 11:40:21 +0000
 1.1.4.2 23-Jun-2013  tls resync from head
 1.1.4.1 30-Mar-2013  tls file arn5416reg.h was added on branch tls-maxphys on 2013-06-23 06:20:17 +0000
 1.18 24-Sep-2025  andvar s/oder/order/ in comments.
 1.17 05-Jul-2024  rin sys: Drop redundant NULL check before m_freem(9)

m_freem(9) safely has accepted NULL argument at least since 4.2BSD:
https://www.tuhs.org/cgi-bin/utree.pl?file=4.2BSD/usr/src/sys/sys/uipc_mbuf.c

Compile-tested on amd64/ALL.

Suggested by knakahara@
 1.16 01-Aug-2023  mrg branches: 1.16.6;
fix simple mis-matched function prototype and definitions.

most of these are like, eg

void foo(int[2]);

with either of these

void foo(int*) { ... }
void foo(int[]) { ... }

in some cases (such as stat or utimes* calls found in our header files),
we now match standard definition from opengroup.

found by GCC 12.
 1.15 29-Jan-2020  thorpej Adopt <net/if_stats.h>.
 1.14 10-Nov-2019  chs branches: 1.14.2;
in many device attach paths, allocate memory with M_WAITOK instead of M_NOWAIT
and remove code to handle failures that can no longer happen.
 1.13 26-Jun-2018  msaitoh branches: 1.13.2;
Implement the BPF direction filter (BIOC[GS]DIRECTION). It provides backward
compatibility with BIOC[GS]SEESENT ioctl. The userland interface is the same
as FreeBSD.

This change also fixes a bug that the direction is misunderstand on some
environment by passing the direction to bpf_mtap*() instead of checking
m->m_pkthdr.rcvif.
 1.12 01-Feb-2018  maxv branches: 1.12.2;
Replace ovbcopy -> memmove, same.
 1.11 23-May-2017  ozaki-r Apply deferred if_start to more drivers

And annotate some XXX_start as it runs in softint to clarify that
it doesn't need deferred if_start.
 1.10 02-Feb-2017  nonaka wlan interfaces make interrupt routine running on softint context.

see http://mail-index.netbsd.org/tech-kern/2016/12/06/msg021281.html

tested device:
* ath at pci: AR5212, AR5424
* athn at pci: AR9287
* ipw at pci: 2100BG
* iwi at pci: 2915ABG
* iwm at pci: 3165, 7260, 8260
* iwn at pci: 4945, 6235
* ral at pci: RT2560
* rtwn at pci: RTL8192CE
 1.9 10-Jun-2016  ozaki-r branches: 1.9.2; 1.9.4;
Introduce m_set_rcvif and m_reset_rcvif

The API is used to set (or reset) a received interface of a mbuf.
They are counterpart of m_get_rcvif, which will come in another
commit, hide internal of rcvif operation, and reduce the diff of
the upcoming change.

No functional change.
 1.8 09-Mar-2016  christos PR/50927: David Binderman: Fix wrong paren
 1.7 24-May-2015  matt Use bus_dmamap_load instead of bus_dmamap_load_raw
 1.6 23-Feb-2014  christos branches: 1.6.4; 1.6.8;
use aprint.
 1.5 22-Oct-2013  skrll Avoid "declaration of 'delay' shadows a global declaration" by renaming
the local variable.
 1.4 17-Oct-2013  christos - remove unused variables
- move variables inside ifdef sections
- ifdef notdef unused code
- use __USE for debugging variables
 1.3 06-Apr-2013  martin branches: 1.3.4; 1.3.6;
Debounce the "wlan button pressed" event via pmf PMFE_RADIO_OFF so we
can run the pmf stuff in thread context.
 1.2 03-Apr-2013  christos instead of ifnet use ethercom.
 1.1 30-Mar-2013  christos This is the initial port of OpenBSD's athn(4) driver. It supports
quite a few Atheros 802.11n devices. See the athn(4) manpage for a
list.

This port has only been tested with a TP-LINK TL-WN722N USB adapter
which has an AR9271 chipset (VENDOR: 0x0cf3, PRODUCT: 0x9271). The
BSS, Monitor, and HostAP modes all seem to work on that adapter,
though the later has not been tested much.

The driver also supports PCI and CardBUS devices, but those interfaces
are completely untested and probably won't work at this point.

If someone can provide me with other adapters that should be
supported, particularly PCI or CardBUS adapters, or tell me where I
can get one cheaply, I would be happy to try to get the driver working
on those devices as well.
 1.3.6.1 18-May-2014  rmind sync with head
 1.3.4.4 03-Dec-2017  jdolecek update from HEAD
 1.3.4.3 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.3.4.2 23-Jun-2013  tls resync from head
 1.3.4.1 06-Apr-2013  tls file arn9003.c was added on branch tls-maxphys on 2013-06-23 06:20:17 +0000
 1.6.8.5 28-Aug-2017  skrll Sync with HEAD
 1.6.8.4 05-Feb-2017  skrll Sync with HEAD
 1.6.8.3 09-Jul-2016  skrll Sync with HEAD
 1.6.8.2 19-Mar-2016  skrll Sync with HEAD
 1.6.8.1 06-Jun-2015  skrll Sync with HEAD
 1.6.4.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.6.4.1 23-Feb-2014  yamt file arn9003.c was added on branch yamt-pagecache on 2014-05-22 11:40:21 +0000
 1.9.4.1 21-Apr-2017  bouyer Sync with HEAD
 1.9.2.1 20-Mar-2017  pgoyette Sync with HEAD
 1.12.2.1 28-Jul-2018  pgoyette Sync with HEAD
 1.13.2.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.13.2.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.14.2.1 29-Feb-2020  ad Sync with head.
 1.16.6.1 02-Aug-2025  perseant Sync with HEAD
 1.2 01-Aug-2023  mrg fix simple mis-matched function prototype and definitions.

most of these are like, eg

void foo(int[2]);

with either of these

void foo(int*) { ... }
void foo(int[]) { ... }

in some cases (such as stat or utimes* calls found in our header files),
we now match standard definition from opengroup.

found by GCC 12.
 1.1 30-Mar-2013  christos branches: 1.1.4; 1.1.12;
This is the initial port of OpenBSD's athn(4) driver. It supports
quite a few Atheros 802.11n devices. See the athn(4) manpage for a
list.

This port has only been tested with a TP-LINK TL-WN722N USB adapter
which has an AR9271 chipset (VENDOR: 0x0cf3, PRODUCT: 0x9271). The
BSS, Monitor, and HostAP modes all seem to work on that adapter,
though the later has not been tested much.

The driver also supports PCI and CardBUS devices, but those interfaces
are completely untested and probably won't work at this point.

If someone can provide me with other adapters that should be
supported, particularly PCI or CardBUS adapters, or tell me where I
can get one cheaply, I would be happy to try to get the driver working
on those devices as well.
 1.1.12.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.1.12.1 30-Mar-2013  yamt file arn9003.h was added on branch yamt-pagecache on 2014-05-22 11:40:21 +0000
 1.1.4.2 23-Jun-2013  tls resync from head
 1.1.4.1 30-Mar-2013  tls file arn9003.h was added on branch tls-maxphys on 2013-06-23 06:20:17 +0000
 1.1 30-Mar-2013  christos branches: 1.1.4; 1.1.12;
This is the initial port of OpenBSD's athn(4) driver. It supports
quite a few Atheros 802.11n devices. See the athn(4) manpage for a
list.

This port has only been tested with a TP-LINK TL-WN722N USB adapter
which has an AR9271 chipset (VENDOR: 0x0cf3, PRODUCT: 0x9271). The
BSS, Monitor, and HostAP modes all seem to work on that adapter,
though the later has not been tested much.

The driver also supports PCI and CardBUS devices, but those interfaces
are completely untested and probably won't work at this point.

If someone can provide me with other adapters that should be
supported, particularly PCI or CardBUS adapters, or tell me where I
can get one cheaply, I would be happy to try to get the driver working
on those devices as well.
 1.1.12.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.1.12.1 30-Mar-2013  yamt file arn9003reg.h was added on branch yamt-pagecache on 2014-05-22 11:40:21 +0000
 1.1.4.2 23-Jun-2013  tls resync from head
 1.1.4.1 30-Mar-2013  tls file arn9003reg.h was added on branch tls-maxphys on 2013-06-23 06:20:17 +0000
 1.3 25-Sep-2022  thorpej Remove unnecessary include of <sys/malloc.h>.
 1.2 03-Apr-2013  christos branches: 1.2.4; 1.2.12;
instead of ifnet use ethercom.
 1.1 30-Mar-2013  christos This is the initial port of OpenBSD's athn(4) driver. It supports
quite a few Atheros 802.11n devices. See the athn(4) manpage for a
list.

This port has only been tested with a TP-LINK TL-WN722N USB adapter
which has an AR9271 chipset (VENDOR: 0x0cf3, PRODUCT: 0x9271). The
BSS, Monitor, and HostAP modes all seem to work on that adapter,
though the later has not been tested much.

The driver also supports PCI and CardBUS devices, but those interfaces
are completely untested and probably won't work at this point.

If someone can provide me with other adapters that should be
supported, particularly PCI or CardBUS adapters, or tell me where I
can get one cheaply, I would be happy to try to get the driver working
on those devices as well.
 1.2.12.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.2.12.1 03-Apr-2013  yamt file arn9280.c was added on branch yamt-pagecache on 2014-05-22 11:40:21 +0000
 1.2.4.2 23-Jun-2013  tls resync from head
 1.2.4.1 03-Apr-2013  tls file arn9280.c was added on branch tls-maxphys on 2013-06-23 06:20:17 +0000
 1.1 30-Mar-2013  christos branches: 1.1.4; 1.1.12;
This is the initial port of OpenBSD's athn(4) driver. It supports
quite a few Atheros 802.11n devices. See the athn(4) manpage for a
list.

This port has only been tested with a TP-LINK TL-WN722N USB adapter
which has an AR9271 chipset (VENDOR: 0x0cf3, PRODUCT: 0x9271). The
BSS, Monitor, and HostAP modes all seem to work on that adapter,
though the later has not been tested much.

The driver also supports PCI and CardBUS devices, but those interfaces
are completely untested and probably won't work at this point.

If someone can provide me with other adapters that should be
supported, particularly PCI or CardBUS adapters, or tell me where I
can get one cheaply, I would be happy to try to get the driver working
on those devices as well.
 1.1.12.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.1.12.1 30-Mar-2013  yamt file arn9280.h was added on branch yamt-pagecache on 2014-05-22 11:40:21 +0000
 1.1.4.2 23-Jun-2013  tls resync from head
 1.1.4.1 30-Mar-2013  tls file arn9280.h was added on branch tls-maxphys on 2013-06-23 06:20:17 +0000
 1.1 30-Mar-2013  christos branches: 1.1.4; 1.1.12;
This is the initial port of OpenBSD's athn(4) driver. It supports
quite a few Atheros 802.11n devices. See the athn(4) manpage for a
list.

This port has only been tested with a TP-LINK TL-WN722N USB adapter
which has an AR9271 chipset (VENDOR: 0x0cf3, PRODUCT: 0x9271). The
BSS, Monitor, and HostAP modes all seem to work on that adapter,
though the later has not been tested much.

The driver also supports PCI and CardBUS devices, but those interfaces
are completely untested and probably won't work at this point.

If someone can provide me with other adapters that should be
supported, particularly PCI or CardBUS adapters, or tell me where I
can get one cheaply, I would be happy to try to get the driver working
on those devices as well.
 1.1.12.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.1.12.1 30-Mar-2013  yamt file arn9280reg.h was added on branch yamt-pagecache on 2014-05-22 11:40:21 +0000
 1.1.4.2 23-Jun-2013  tls resync from head
 1.1.4.1 30-Mar-2013  tls file arn9280reg.h was added on branch tls-maxphys on 2013-06-23 06:20:17 +0000
 1.5 25-Sep-2022  thorpej Remove unnecessary include of <sys/malloc.h>.
 1.4 25-Jul-2019  msaitoh Avoid undefined behavior. Found by KUBSan. Some of errors are still remaining.
 1.3 17-Oct-2013  christos branches: 1.3.4; 1.3.32;
- remove unused variables
- move variables inside ifdef sections
- ifdef notdef unused code
- use __USE for debugging variables
 1.2 03-Apr-2013  christos branches: 1.2.4; 1.2.6;
instead of ifnet use ethercom.
 1.1 30-Mar-2013  christos This is the initial port of OpenBSD's athn(4) driver. It supports
quite a few Atheros 802.11n devices. See the athn(4) manpage for a
list.

This port has only been tested with a TP-LINK TL-WN722N USB adapter
which has an AR9271 chipset (VENDOR: 0x0cf3, PRODUCT: 0x9271). The
BSS, Monitor, and HostAP modes all seem to work on that adapter,
though the later has not been tested much.

The driver also supports PCI and CardBUS devices, but those interfaces
are completely untested and probably won't work at this point.

If someone can provide me with other adapters that should be
supported, particularly PCI or CardBUS adapters, or tell me where I
can get one cheaply, I would be happy to try to get the driver working
on those devices as well.
 1.2.6.1 18-May-2014  rmind sync with head
 1.2.4.3 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.2.4.2 23-Jun-2013  tls resync from head
 1.2.4.1 03-Apr-2013  tls file arn9285.c was added on branch tls-maxphys on 2013-06-23 06:20:17 +0000
 1.3.32.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.3.4.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.3.4.1 17-Oct-2013  yamt file arn9285.c was added on branch yamt-pagecache on 2014-05-22 11:40:21 +0000
 1.1 30-Mar-2013  christos branches: 1.1.4; 1.1.12;
This is the initial port of OpenBSD's athn(4) driver. It supports
quite a few Atheros 802.11n devices. See the athn(4) manpage for a
list.

This port has only been tested with a TP-LINK TL-WN722N USB adapter
which has an AR9271 chipset (VENDOR: 0x0cf3, PRODUCT: 0x9271). The
BSS, Monitor, and HostAP modes all seem to work on that adapter,
though the later has not been tested much.

The driver also supports PCI and CardBUS devices, but those interfaces
are completely untested and probably won't work at this point.

If someone can provide me with other adapters that should be
supported, particularly PCI or CardBUS adapters, or tell me where I
can get one cheaply, I would be happy to try to get the driver working
on those devices as well.
 1.1.12.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.1.12.1 30-Mar-2013  yamt file arn9285.h was added on branch yamt-pagecache on 2014-05-22 11:40:21 +0000
 1.1.4.2 23-Jun-2013  tls resync from head
 1.1.4.1 30-Mar-2013  tls file arn9285.h was added on branch tls-maxphys on 2013-06-23 06:20:17 +0000
 1.1 30-Mar-2013  christos branches: 1.1.4; 1.1.12;
This is the initial port of OpenBSD's athn(4) driver. It supports
quite a few Atheros 802.11n devices. See the athn(4) manpage for a
list.

This port has only been tested with a TP-LINK TL-WN722N USB adapter
which has an AR9271 chipset (VENDOR: 0x0cf3, PRODUCT: 0x9271). The
BSS, Monitor, and HostAP modes all seem to work on that adapter,
though the later has not been tested much.

The driver also supports PCI and CardBUS devices, but those interfaces
are completely untested and probably won't work at this point.

If someone can provide me with other adapters that should be
supported, particularly PCI or CardBUS adapters, or tell me where I
can get one cheaply, I would be happy to try to get the driver working
on those devices as well.
 1.1.12.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.1.12.1 30-Mar-2013  yamt file arn9285reg.h was added on branch yamt-pagecache on 2014-05-22 11:40:21 +0000
 1.1.4.2 23-Jun-2013  tls resync from head
 1.1.4.1 30-Mar-2013  tls file arn9285reg.h was added on branch tls-maxphys on 2013-06-23 06:20:17 +0000
 1.4 25-Sep-2022  thorpej Remove unnecessary include of <sys/malloc.h>.
 1.3 17-Oct-2013  christos branches: 1.3.4;
- remove unused variables
- move variables inside ifdef sections
- ifdef notdef unused code
- use __USE for debugging variables
 1.2 03-Apr-2013  christos branches: 1.2.4; 1.2.6;
instead of ifnet use ethercom.
 1.1 30-Mar-2013  christos This is the initial port of OpenBSD's athn(4) driver. It supports
quite a few Atheros 802.11n devices. See the athn(4) manpage for a
list.

This port has only been tested with a TP-LINK TL-WN722N USB adapter
which has an AR9271 chipset (VENDOR: 0x0cf3, PRODUCT: 0x9271). The
BSS, Monitor, and HostAP modes all seem to work on that adapter,
though the later has not been tested much.

The driver also supports PCI and CardBUS devices, but those interfaces
are completely untested and probably won't work at this point.

If someone can provide me with other adapters that should be
supported, particularly PCI or CardBUS adapters, or tell me where I
can get one cheaply, I would be happy to try to get the driver working
on those devices as well.
 1.2.6.1 18-May-2014  rmind sync with head
 1.2.4.3 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.2.4.2 23-Jun-2013  tls resync from head
 1.2.4.1 03-Apr-2013  tls file arn9287.c was added on branch tls-maxphys on 2013-06-23 06:20:17 +0000
 1.3.4.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.3.4.1 17-Oct-2013  yamt file arn9287.c was added on branch yamt-pagecache on 2014-05-22 11:40:21 +0000
 1.1 30-Mar-2013  christos branches: 1.1.4; 1.1.12;
This is the initial port of OpenBSD's athn(4) driver. It supports
quite a few Atheros 802.11n devices. See the athn(4) manpage for a
list.

This port has only been tested with a TP-LINK TL-WN722N USB adapter
which has an AR9271 chipset (VENDOR: 0x0cf3, PRODUCT: 0x9271). The
BSS, Monitor, and HostAP modes all seem to work on that adapter,
though the later has not been tested much.

The driver also supports PCI and CardBUS devices, but those interfaces
are completely untested and probably won't work at this point.

If someone can provide me with other adapters that should be
supported, particularly PCI or CardBUS adapters, or tell me where I
can get one cheaply, I would be happy to try to get the driver working
on those devices as well.
 1.1.12.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.1.12.1 30-Mar-2013  yamt file arn9287.h was added on branch yamt-pagecache on 2014-05-22 11:40:21 +0000
 1.1.4.2 23-Jun-2013  tls resync from head
 1.1.4.1 30-Mar-2013  tls file arn9287.h was added on branch tls-maxphys on 2013-06-23 06:20:17 +0000
 1.1 30-Mar-2013  christos branches: 1.1.4; 1.1.12;
This is the initial port of OpenBSD's athn(4) driver. It supports
quite a few Atheros 802.11n devices. See the athn(4) manpage for a
list.

This port has only been tested with a TP-LINK TL-WN722N USB adapter
which has an AR9271 chipset (VENDOR: 0x0cf3, PRODUCT: 0x9271). The
BSS, Monitor, and HostAP modes all seem to work on that adapter,
though the later has not been tested much.

The driver also supports PCI and CardBUS devices, but those interfaces
are completely untested and probably won't work at this point.

If someone can provide me with other adapters that should be
supported, particularly PCI or CardBUS adapters, or tell me where I
can get one cheaply, I would be happy to try to get the driver working
on those devices as well.
 1.1.12.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.1.12.1 30-Mar-2013  yamt file arn9287reg.h was added on branch yamt-pagecache on 2014-05-22 11:40:21 +0000
 1.1.4.2 23-Jun-2013  tls resync from head
 1.1.4.1 30-Mar-2013  tls file arn9287reg.h was added on branch tls-maxphys on 2013-06-23 06:20:17 +0000
 1.4 25-Sep-2022  thorpej Remove unnecessary include of <sys/malloc.h>.
 1.3 22-Jan-2014  matt branches: 1.3.4; 1.3.32;
swap16 -> bswap16 swap32 -> bswap32
 1.2 03-Apr-2013  christos branches: 1.2.4; 1.2.6;
instead of ifnet use ethercom.
 1.1 30-Mar-2013  christos This is the initial port of OpenBSD's athn(4) driver. It supports
quite a few Atheros 802.11n devices. See the athn(4) manpage for a
list.

This port has only been tested with a TP-LINK TL-WN722N USB adapter
which has an AR9271 chipset (VENDOR: 0x0cf3, PRODUCT: 0x9271). The
BSS, Monitor, and HostAP modes all seem to work on that adapter,
though the later has not been tested much.

The driver also supports PCI and CardBUS devices, but those interfaces
are completely untested and probably won't work at this point.

If someone can provide me with other adapters that should be
supported, particularly PCI or CardBUS adapters, or tell me where I
can get one cheaply, I would be happy to try to get the driver working
on those devices as well.
 1.2.6.1 18-May-2014  rmind sync with head
 1.2.4.3 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.2.4.2 23-Jun-2013  tls resync from head
 1.2.4.1 03-Apr-2013  tls file arn9380.c was added on branch tls-maxphys on 2013-06-23 06:20:17 +0000
 1.3.32.1 12-Jul-2018  phil State save. New kernel config for this brach only. TESTWIFI does
produce a kernel. It is not working. athn files not compiling yet
and commented out of the TESTWIFI kernel, which only has urtwn 802.11
driver enabled. ieee80211_alq.c and ieee80211_ddb.c not compiling yet.
 1.3.4.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.3.4.1 22-Jan-2014  yamt file arn9380.c was added on branch yamt-pagecache on 2014-05-22 11:40:21 +0000
 1.1 30-Mar-2013  christos branches: 1.1.4; 1.1.12;
This is the initial port of OpenBSD's athn(4) driver. It supports
quite a few Atheros 802.11n devices. See the athn(4) manpage for a
list.

This port has only been tested with a TP-LINK TL-WN722N USB adapter
which has an AR9271 chipset (VENDOR: 0x0cf3, PRODUCT: 0x9271). The
BSS, Monitor, and HostAP modes all seem to work on that adapter,
though the later has not been tested much.

The driver also supports PCI and CardBUS devices, but those interfaces
are completely untested and probably won't work at this point.

If someone can provide me with other adapters that should be
supported, particularly PCI or CardBUS adapters, or tell me where I
can get one cheaply, I would be happy to try to get the driver working
on those devices as well.
 1.1.12.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.1.12.1 30-Mar-2013  yamt file arn9380.h was added on branch yamt-pagecache on 2014-05-22 11:40:21 +0000
 1.1.4.2 23-Jun-2013  tls resync from head
 1.1.4.1 30-Mar-2013  tls file arn9380.h was added on branch tls-maxphys on 2013-06-23 06:20:17 +0000
 1.1 30-Mar-2013  christos branches: 1.1.4; 1.1.12;
This is the initial port of OpenBSD's athn(4) driver. It supports
quite a few Atheros 802.11n devices. See the athn(4) manpage for a
list.

This port has only been tested with a TP-LINK TL-WN722N USB adapter
which has an AR9271 chipset (VENDOR: 0x0cf3, PRODUCT: 0x9271). The
BSS, Monitor, and HostAP modes all seem to work on that adapter,
though the later has not been tested much.

The driver also supports PCI and CardBUS devices, but those interfaces
are completely untested and probably won't work at this point.

If someone can provide me with other adapters that should be
supported, particularly PCI or CardBUS adapters, or tell me where I
can get one cheaply, I would be happy to try to get the driver working
on those devices as well.
 1.1.12.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.1.12.1 30-Mar-2013  yamt file arn9380reg.h was added on branch yamt-pagecache on 2014-05-22 11:40:21 +0000
 1.1.4.2 23-Jun-2013  tls resync from head
 1.1.4.1 30-Mar-2013  tls file arn9380reg.h was added on branch tls-maxphys on 2013-06-23 06:20:17 +0000
 1.4 04-Oct-2002  tsutsui - Merge dev/ic/ate_subr.c into dev/ic/mb86960.c since it only has EEPROM
read function which can also be used for other MB86965 based boards.
- Rewrite EEPROM read function as per 93C06 EEPROM datasheet.
- Misc cleanup.
 1.3 28-Sep-2002  tsutsui Move AT1700/RE2000 EEPROM definitions from isa/if_fereg.h to ic/ate_subr.h.

XXX Maybe all stuff in ate_subr.* should be merged into ic/mb86960*.[ch].
 1.2 13-Nov-2001  lukem add/cleanup RCSID
 1.1 31-Mar-2001  jdolecek branches: 1.1.2; 1.1.4; 1.1.6;
Prepare for MCA attachment:
* split off sharable stuff to dev/ic/ate_subr.[ch], move ate(4) device
definition to conf/files
* cosmetic: attach with ate_isa
 1.1.6.2 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.1.6.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.1.4.2 21-Apr-2001  bouyer Sync with HEAD
 1.1.4.1 31-Mar-2001  bouyer file ate_subr.c was added on branch thorpej_scsipi on 2001-04-21 17:48:26 +0000
 1.1.2.4 18-Oct-2002  nathanw Catch up to -current.
 1.1.2.3 14-Nov-2001  nathanw Catch up to -current.
 1.1.2.2 09-Apr-2001  nathanw Catch up with -current.
 1.1.2.1 31-Mar-2001  nathanw file ate_subr.c was added on branch nathanw_sa on 2001-04-09 01:56:09 +0000
 1.4 04-Oct-2002  tsutsui - Merge dev/ic/ate_subr.c into dev/ic/mb86960.c since it only has EEPROM
read function which can also be used for other MB86965 based boards.
- Rewrite EEPROM read function as per 93C06 EEPROM datasheet.
- Misc cleanup.
 1.3 28-Sep-2002  tsutsui Move AT1700/RE2000 EEPROM definitions from isa/if_fereg.h to ic/ate_subr.h.

XXX Maybe all stuff in ate_subr.* should be merged into ic/mb86960*.[ch].
 1.2 31-Mar-2001  jdolecek branches: 1.2.2; 1.2.4; 1.2.6;
fix the copyright - Charles's name was added here by mistake, use
standard TNF cookie instead
 1.1 31-Mar-2001  jdolecek Prepare for MCA attachment:
* split off sharable stuff to dev/ic/ate_subr.[ch], move ate(4) device
definition to conf/files
* cosmetic: attach with ate_isa
 1.2.6.1 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.2.4.2 21-Apr-2001  bouyer Sync with HEAD
 1.2.4.1 31-Mar-2001  bouyer file ate_subr.h was added on branch thorpej_scsipi on 2001-04-21 17:48:27 +0000
 1.2.2.3 18-Oct-2002  nathanw Catch up to -current.
 1.2.2.2 09-Apr-2001  nathanw Catch up with -current.
 1.2.2.1 31-Mar-2001  nathanw file ate_subr.h was added on branch nathanw_sa on 2001-04-09 01:56:09 +0000
 1.140 04-Oct-2025  thorpej Use device_{get,set}prop_bool() for "pmf-no-powerdown".
 1.139 05-Jul-2024  rin sys: Drop redundant NULL check before m_freem(9)

m_freem(9) safely has accepted NULL argument at least since 4.2BSD:
https://www.tuhs.org/cgi-bin/utree.pl?file=4.2BSD/usr/src/sys/sys/uipc_mbuf.c

Compile-tested on amd64/ALL.

Suggested by knakahara@
 1.138 06-Nov-2021  msaitoh branches: 1.138.10;
Fix typo in comment. s/notifcation/notification/
 1.137 21-Sep-2021  christos don't opencode kauth_cred_get()
 1.136 09-Aug-2021  andvar fix various typos in compatibility, mainly in comments.
 1.135 12-Jun-2021  riastradh ath(4): Use config_deactivate; don't abuse autoconf private dv_flags.
 1.134 13-Apr-2021  mrg branches: 1.134.2;
use correct enum types for various functions.
 1.133 16-Nov-2020  msaitoh branches: 1.133.2;
s/reseting/resetting/
 1.132 22-Jul-2020  msaitoh branches: 1.132.2;
s/reseting/resetting/
 1.131 12-Jun-2020  thorpej pmf-powerdown == false --> pmf-no-powerdown == true
 1.130 29-Jan-2020  thorpej Adopt <net/if_stats.h>.
 1.129 17-Dec-2019  christos branches: 1.129.2;
Protect network ioctls from non-authorized users. (Ilja Van Sprundel)
 1.128 10-Nov-2019  chs in many device attach paths, allocate memory with M_WAITOK instead of M_NOWAIT
and remove code to handle failures that can no longer happen.
 1.127 28-May-2019  msaitoh branches: 1.127.2;
Use ETHER_LOCK()/ETHER_UNLOCK() for all ethernet drivers to protect ec_multi*.
 1.126 23-May-2019  msaitoh Whitespace fix (mainly tabify).
 1.125 23-May-2019  msaitoh -No functional change:
- KNF
- u_int*_t -> uint*_t.
 1.124 26-Jun-2018  msaitoh branches: 1.124.2;
Implement the BPF direction filter (BIOC[GS]DIRECTION). It provides backward
compatibility with BIOC[GS]SEESENT ioctl. The userland interface is the same
as FreeBSD.

This change also fixes a bug that the direction is misunderstand on some
environment by passing the direction to bpf_mtap*() instead of checking
m->m_pkthdr.rcvif.
 1.123 02-Feb-2017  nonaka branches: 1.123.6; 1.123.12;
wlan interfaces make interrupt routine running on softint context.

see http://mail-index.netbsd.org/tech-kern/2016/12/06/msg021281.html

tested device:
* ath at pci: AR5212, AR5424
* athn at pci: AR9287
* ipw at pci: 2100BG
* iwi at pci: 2915ABG
* iwm at pci: 3165, 7260, 8260
* iwn at pci: 4945, 6235
* ral at pci: RT2560
* rtwn at pci: RTL8192CE
 1.122 10-Jun-2016  ozaki-r branches: 1.122.2; 1.122.4;
Introduce m_set_rcvif and m_reset_rcvif

The API is used to set (or reset) a received interface of a mbuf.
They are counterpart of m_get_rcvif, which will come in another
commit, hide internal of rcvif operation, and reduce the diff of
the upcoming change.

No functional change.
 1.121 26-May-2016  ozaki-r Introduce M_CLEARCTX and use it instead of open-coding rcvif

No functional change.
 1.120 26-May-2016  ozaki-r Use M_GETCTX

No functional change.
 1.119 08-Apr-2016  roy Revert prior.
 1.118 06-Apr-2016  roy Fix rssi
 1.117 18-Oct-2014  snj branches: 1.117.2;
src is too big these days to tolerate superfluous apostrophes. It's
"its", people!
 1.116 12-Sep-2013  martin branches: 1.116.4; 1.116.6; 1.116.10;
Remove unused variable
 1.115 27-Jan-2013  jmcneill branches: 1.115.2;
don't transmit while in a key change is in progress
 1.114 08-Nov-2012  dyoung Use NetBSD's own KASSERT() and KASSERTMSG() instead of #undef and re-#defining
KASSERT(), which is awkward at best.
 1.113 28-Nov-2011  jmcneill branches: 1.113.8;
SVN r220966 from FreeBSD:

Fix a corner-case of interrupt handling which resulted in potentially
spurious (and fatal) interrupt errors.
 1.112 07-Oct-2011  dyoung branches: 1.112.2;
Get rid of the "I don't know what I was thinking / somebody should have
stopped me / does anybody read source-changes?" ATH_LOCK()/ATH_UNLOCK()
and bracket with splnet()/splx() instead. This is still not *good*,
since ifnet ioctls are not (yet) synchronized, but could be no worse
than what we have, now. Survives light testing with my (forthcoming)
ifnet ioctl synchronization patch.
 1.111 07-Mar-2011  cegger Get improvements from FreeBSD-current (January 2011).
Successfully tested with WEP, WPA and WPA2 on AR9285.
Reviewed by jmcneill@
 1.110 20-Feb-2011  jmcneill support building as a module
 1.109 05-Apr-2010  joerg branches: 1.109.2; 1.109.4;
Push the bpf_ops usage back into bpf.h. Push the common ifp->if_bpf
check into the inline functions as well the fourth argument for
bpf_attach.
 1.108 19-Jan-2010  pooka branches: 1.108.2; 1.108.4;
Redefine bpf linkage through an always present op vector, i.e.
#if NBPFILTER is no longer required in the client. This change
doesn't yet add support for loading bpf as a module, since drivers
can register before bpf is attached. However, callers of bpf can
now be modularized.

Dynamically loadable bpf could probably be done fairly easily with
coordination from the stub driver and the real driver by registering
attachments in the stub before the real driver is loaded and doing
a handoff. ... and I'm not going to ponder the depths of unload
here.

Tested with i386/MONOLITHIC, modified MONOLITHIC without bpf and rump.
 1.107 16-Sep-2009  dyoung In pmf(9), improve the implementation of device self-suspension
and make suspension by self, by drvctl(8), and by ACPI system sleep
play nice together. Start solidifying some temporary API changes.

1. Extract a new header file, <sys/device_if.h>, from <sys/device.h> and
#include it from <sys/pmf.h> instead of <sys/device.h> to break the
circular dependency between <sys/device.h> and <sys/pmf.h>.

2. Introduce pmf_qual_t, an aggregate of qualifications on a PMF
suspend/resume call. Start to replace instances of PMF_FN_PROTO,
PMF_FN_ARGS, et cetera, with a pmf_qual_t.

3. Introduce the notion of a "suspensor," an entity that holds a
device in suspension. More than one suspensor may hold a device
at once. A device stays suspended as long as at least one
suspensor holds it. A device resumes when the last suspensor
releases it.

Currently, the kernel defines three suspensors,

3a the system-suspensor: for system suspension, initiated
by 'sysctl -w machdep.sleep_state=3', by lid closure, by
power-button press, et cetera,

3b the drvctl-suspensor: for device suspension by /dev/drvctl
ioctl, e.g., drvctl -S sip0.

3c the system self-suspensor: for device drivers that suspend
themselves and their children. Several drivers for network
interfaces put the network device to sleep while it is not
administratively up, that is, after the kernel calls if_stop(,
1). The self-suspensor should not be used directly. See
the description of suspensor delegates, below.

A suspensor can have one or more "delegates". A suspensor can
release devices that its delegates hold suspended. Right now,
only the system self-suspensor has delegates. For each device
that a self-suspending driver attaches, it creates the device's
self-suspensor, a delegate of the system self-suspensor.

Suspensors stop a system-wide suspend/resume cycle from waking
devices that the operator put to sleep with drvctl before the cycle.
They also help self-suspension to work more simply, safely, and in
accord with expectations.

4. Add the notion of device activation level, devact_level_t,
and a routine for checking the current activation level,
device_activation(). Current activation levels are DEVACT_LEVEL_BUS,
DEVACT_LEVEL_DRIVER, and DEVACT_LEVEL_CLASS, which respectively
indicate that the device's bus is active, that the bus and device are
active, and that the bus, device, and the functions of the device's
class (network, audio) are active.

Suspend/resume calls can be qualified with a devact_level_t.
The power-management framework treats a devact_level_t that
qualifies a device suspension as the device's current activation
level; it only runs hooks to reduce the activation level from
the presumed current level to the fully suspended state. The
framework treats a devact_level_t qualifying device resumption
as the target activation level; it only runs hooks to raise the
activation level to the target.

5. Use pmf_qual_t, devact_level_t, and self-suspensors in several
drivers.

6. Temporarily add an unused power-management workqueue that I will
remove or replace, soon.
 1.106 02-Aug-2009  jmcneill - fix TKIP, changes adapted from FreeBSD
- reduce diffs between FreeBSD and NetBSD athvar.h
 1.105 11-Dec-2008  alc Doh! What should have happened happens ...

Restore the check to see if the chip does MIC correctly when
WME is turned on. Btw, define IEEE80211_C_WME_TKIPMIC and fix build :/
 1.104 11-Dec-2008  alc Sync ath(4) with the new HAL, mostly based on <jmcneill>'s patches.

Everything should be fine again !
 1.103 07-Nov-2008  dyoung *** Summary ***

When a link-layer address changes (e.g., ifconfig ex0 link
02:de:ad:be:ef:02 active), send a gratuitous ARP and/or a Neighbor
Advertisement to update the network-/link-layer address bindings
on our LAN peers.

Refuse a change of ethernet address to the address 00:00:00:00:00:00
or to any multicast/broadcast address. (Thanks matt@.)

Reorder ifnet ioctl operations so that driver ioctls may inherit
the functions of their "class"---ether_ioctl(), fddi_ioctl(), et
cetera---and the class ioctls may inherit from the generic ioctl,
ifioctl_common(), but both driver- and class-ioctls may override
the generic behavior. Make network drivers share more code.

Distinguish a "factory" link-layer address from others for the
purposes of both protecting that address from deletion and computing
EUI64.

Return consistent, appropriate error codes from network drivers.

Improve readability. KNF.

*** Details ***

In if_attach(), always initialize the interface ioctl routine,
ifnet->if_ioctl, if the driver has not already initialized it.
Delete if_ioctl == NULL tests everywhere else, because it cannot
happen.

In the ioctl routines of network interfaces, inherit common ioctl
behaviors by calling either ifioctl_common() or whichever ioctl
routine is appropriate for the class of interface---e.g., ether_ioctl()
for ethernets.

Stop (ab)using SIOCSIFADDR and start to use SIOCINITIFADDR. In
the user->kernel interface, SIOCSIFADDR's argument was an ifreq,
but on the protocol->ifnet interface, SIOCSIFADDR's argument was
an ifaddr. That was confusing, and it would work against me as I
make it possible for a network interface to overload most ioctls.
On the protocol->ifnet interface, replace SIOCSIFADDR with
SIOCINITIFADDR. In ifioctl(), return EPERM if userland tries to
invoke SIOCINITIFADDR.

In ifioctl(), give the interface the first shot at handling most
interface ioctls, and give the protocol the second shot, instead
of the other way around. Finally, let compatibility code (COMPAT_OSOCK)
take a shot.

Pull device initialization out of switch statements under
SIOCINITIFADDR. For example, pull ..._init() out of any switch
statement that looks like this:

switch (...->sa_family) {
case ...:
..._init();
...
break;
...
default:
..._init();
...
break;
}

Rewrite many if-else clauses that handle all permutations of IFF_UP
and IFF_RUNNING to use a switch statement,

switch (x & (IFF_UP|IFF_RUNNING)) {
case 0:
...
break;
case IFF_RUNNING:
...
break;
case IFF_UP:
...
break;
case IFF_UP|IFF_RUNNING:
...
break;
}

unifdef lots of code containing #ifdef FreeBSD, #ifdef NetBSD, and
#ifdef SIOCSIFMTU, especially in fwip(4) and in ndis(4).

In ipw(4), remove an if_set_sadl() call that is out of place.

In nfe(4), reuse the jumbo MTU logic in ether_ioctl().

Let ethernets register a callback for setting h/w state such as
promiscuous mode and the multicast filter in accord with a change
in the if_flags: ether_set_ifflags_cb() registers a callback that
returns ENETRESET if the caller should reset the ethernet by calling
if_init(), 0 on success, != 0 on failure. Pull common code from
ex(4), gem(4), nfe(4), sip(4), tlp(4), vge(4) into ether_ioctl(),
and register if_flags callbacks for those drivers.

Return ENOTTY instead of EINVAL for inappropriate ioctls. In
zyd(4), use ENXIO instead of ENOTTY to indicate that the device is
not any longer attached.

Add to if_set_sadl() a boolean 'factory' argument that indicates
whether a link-layer address was assigned by the factory or some
other source. In a comment, recommend using the factory address
for generating an EUI64, and update in6_get_hw_ifid() to prefer a
factory address to any other link-layer address.

Add a routing message, RTM_LLINFO_UPD, that tells protocols to
update the binding of network-layer addresses to link-layer addresses.
Implement this message in IPv4 and IPv6 by sending a gratuitous
ARP or a neighbor advertisement, respectively. Generate RTM_LLINFO_UPD
messages on a change of an interface's link-layer address.

In ether_ioctl(), do not let SIOCALIFADDR set a link-layer address
that is broadcast/multicast or equal to 00:00:00:00:00:00.

Make ether_ioctl() call ifioctl_common() to handle ioctls that it
does not understand.

In gif(4), initialize if_softc and use it, instead of assuming that
the gif_softc and ifp overlap.

Let ifioctl_common() handle SIOCGIFADDR.

Sprinkle rtcache_invariants(), which checks on DIAGNOSTIC kernels
that certain invariants on a struct route are satisfied.

In agr(4), rewrite agr_ioctl_filter() to be a bit more explicit
about the ioctls that we do not allow on an agr(4) member interface.

bzero -> memset. Delete unnecessary casts to void *. Use
sockaddr_in_init() and sockaddr_in6_init(). Compare pointers with
NULL instead of "testing truth". Replace some instances of (type
*)0 with NULL. Change some K&R prototypes to ANSI C, and join
lines.
 1.102 09-Jul-2008  joerg branches: 1.102.2; 1.102.4; 1.102.8;
- device/softc split for ath(4)
 1.101 17-Jun-2008  dyoung branches: 1.101.2;
Repair a discrepancy between the 802.11 standard and ath(4) operation
where transmit fragmentation is concerned.

Extract from ath_tx_start() the code for subtracting padding from
the packet length, creating subroutine deduct_pad_bytes(). Note
that the arithmetic in deduct_pad_bytes() is suspicious.

Use deduct_pad_bytes() to repair the computation of the 802.11
Duration field for fragments. The computation used to leave out
the FCS, among other things.

Some discrepancies between ath(4) operation and the standard may
still remain. According to my observations, the gaps between
transmitted fragments may be approximately 8 microseconds too long.
 1.100 04-May-2008  rumble branches: 1.100.2; 1.100.4;
If a device transmit timeout occurs and sc_txintrperiod is greater than
one, throttle it down before the reset. This way the user need not know
the magic `hw.ath0.txintrperiod=1' fix if the default value is too high
for their machine.
 1.99 12-Mar-2008  dyoung branches: 1.99.2; 1.99.4;
Use device_t and its accessors throughout. Use aprint_*_dev().

Improve PMF-ability.

Add a 'flags' argument to suspend/resume handlers and
callers such as pmf_system_suspend().

Define a flag, PMF_F_SELF, which indicates to PMF that a
device is suspending/resuming itself. Add helper routines,
pmf_device_suspend_self(dev) and pmf_device_resume_self(dev),
that call pmf_device_suspend(dev, PMF_F_SELF) and
pmf_device_resume(dev, PMF_F_SELF), respectively. Use
PMF_F_SELF to suspend/resume self in ath(4), audio(4),
rtw(4), and sip(4).

In ath(4) and in rtw(4), replace the icky sc_enable/sc_disable
callbacks, provided by the bus front-end, with
self-suspension/resumption. Also, clean up the bus
front-ends. Make sure that the interrupt handler is
disestablished during suspension. Get rid of driver-private
flags (e.g., RTW_F_ENABLED, ath_softc->sc_invalid); use
device_is_active()/device_has_power() calls, instead.

In the network-class suspend handler, call if_stop(, 0)
instead of if_stop(, 1), because the latter is superfluous
(bus- and driver-suspension hooks will 'disable' the NIC),
and it may cause recursion.

In the network-class resume handler, prevent infinite
recursion through if_init() by getting out early if we are
self-suspending (PMF_F_SELF).

rtw(4) improvements:

Destroy rtw(4) callouts when we detach it. Make rtw at
pci detachable. Print some more information with the "rx
frame too long" warning.

Remove activate() methods:

Get rid of rtw_activate() and ath_activate(). The device
activate() methods are not good for much these days.

Make ath at cardbus resume with crypto functions intact:

Introduce a boolean device property, "pmf-powerdown". If
pmf-powerdown is present and false, it indicates that a
bus back-end should not remove power from a device.

Honor this property in cardbus_child_suspend().

Set this property to 'false' in ath_attach(), since removing
power from an ath at cardbus seems to lobotomize the WPA
crypto engine. XXX Should the pmf-powerdown property
propagate toward the root of the device tree?

Miscellaneous ath(4) changes:

Warn if ath(4) tries to write crypto keys to suspended
hardware.

Reduce differences between FreeBSD and NetBSD in ath(4)
multicast filter setup.

Make ath_printrxbuf() print an rx descriptor's status &
key index, to help debug crypto errors.

Shorten a staircase in ath_ioctl(). Don't check for
ieee80211_ioctl() return code ERESTART, it never happens.
 1.98 04-Jan-2008  ad branches: 1.98.2; 1.98.6;
Start detangling lock.h from intr.h. This is likely to cause short term
breakage, but the mess of dependencies has been regularly breaking the
build recently anyhow.
 1.97 22-Dec-2007  dyoung Remove the remnants of the powerhooks.
 1.96 14-Dec-2007  dyoung Exit from ath_init() with EBUSY if the device does not have power.
 1.95 13-Dec-2007  dyoung Back out previous my previous change, it stops device resumption
entirely.
 1.94 13-Dec-2007  dyoung Do not reinitialize the NIC while it is suspended.
 1.93 09-Dec-2007  jmcneill branches: 1.93.2;
Merge jmcneill-pm branch.
 1.92 27-Nov-2007  dyoung branches: 1.92.2; 1.92.4;
Bug fix: in ath_init(), if ath_enable() fails, ATH_UNLOCK() before
returning.
 1.91 26-Nov-2007  dyoung Don't process the CAB queue twice in ath_tx_proc_q0123.
 1.90 26-Nov-2007  dyoung Eliminate redundant check for read-only mbuf data, since
M_TRAILINGSPACE() does a more complete check on NetBSD.
 1.89 26-Nov-2007  dyoung Bug fix: restore antenna diversity settings after reset.
 1.88 26-Nov-2007  dyoung Use device_xname(). Make device_printf() take a device_t argument.
Add __attribute__((__format__(__printf__,2,3))) to device_printf()
so that the compiler will help us detect bad arguments.

Retire unused subroutine m_defrag(), and unused declaration m_getcl().
 1.87 19-Oct-2007  ad branches: 1.87.2;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.86 01-Sep-2007  dyoung branches: 1.86.4;
Change a bazillion occurrences of code resembling this,

error = (cmd == SIOCADDMULTI) ?
ether_addmulti(ifr, &sc->sc_ec) :
ether_delmulti(ifr, &sc->sc_ec);

if (error == ENETRESET) {

to this,

if ((error = ether_ioctl(ifp, cmd, data)) == ENETRESET) {

which does the same thing.

(A bazillion is a very large number. This seems to make the i386
ALL kernel smaller by 3kB to 4kB.)

Use ifreq_getaddr() twice in es(4).

Whitespace nits.
 1.85 29-Aug-2007  dyoung Constify: LLADDR() -> CLLADDR().
 1.84 17-Jul-2007  dyoung branches: 1.84.2; 1.84.6; 1.84.8;
Suppress spurious timeouts and avoid wedging in OACTIVE state:

1 Set or clear OACTIVE as transmit buffers are depleted or
replenished, respectively. Do not use 802.11 acknowledgements
as a criteria for clearing OACTIVE.

2 Let each transmit queue count down to timeout independently,
and get rid of the shared countdown (sc_tx_timer). When
we add a packet to a transmit queue, restart the queue's
countdown. Stop a transmit queue's countdown when the
queue empties.
 1.83 17-Apr-2007  dyoung Plug an mbuf leak. Found by inspection.

Do not clear IFF_OACTIVE and reset the transmit watchdog timer
unless we have actually freed some transmit resources. This prevents
my wireless routers from needlessly entering ath_start() without
any transmit resources. If the MAC's transmitter has frozen, also,
then the driver will take the "out of xmit buffers" path in
ath_start(), which sets OACTIVE without activating the transmit
watchdog. That freezes the transmit path until the driver is reset.

XXX The "out of xmit buffers" path in ath_start() needs more
XXX attention.
 1.82 04-Mar-2007  christos branches: 1.82.2; 1.82.4;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.81 29-Jan-2007  hubertf branches: 1.81.2;
Remove more duplicate headers.
Patch by Slava Semushin <slava.semushin@gmail.com>

Again, this was tested by comparing obj files from a pristine and a patched
source tree against an i386/ALL kernel, and also for src/sbin/fsck_ffs,
src/sbin/fsdb and src/usr.sbin/makefs. Only changes in assert() line numbers
were detected in 'objdump -d' output.
 1.80 09-Jan-2007  dyoung ath-specific support for 802.11 fragmentation. From Sam Leffler.

Screen-scraped by me from the WWW source browser at perforce.freebsd.org.
 1.79 16-Nov-2006  christos __unused removal on arguments; approved by core.
 1.78 12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.77 24-Sep-2006  jmcneill Add "name" parameter to powerhook_establish, to aid debugging. No objections
on tech-kern@
 1.76 14-Jul-2006  seanb branches: 1.76.4; 1.76.6;
Consistently establish / disestablish shutdown hook
in the bus layer and remove from common ath_attach().
Having it in both layers (on some bus architectures)
was causing a double call to ath_stop() on shutdown
which in turn was tickling the bus lockup described
therin on slower machines.
 1.75 08-Jun-2006  gdamore Print bus_addr_t using PRIx64 (casting to uint64_t), which fixes builds
on 32-bit sparc (which have 64-bit bus_addr_t, but only 32-bit pointers.)
 1.74 05-Jun-2006  gdamore Import new HAL 0.9.17.2. Approved by sam@

New HAL includes some driver changes to register accesses.
Adds support for WLAN devices on AR5312 family devices.
Adds support 32-bit SPARC ath devices (untested).
ath enabled in SPARC64 GENERIC builds.
This HAL is tested and known to work for i386 PCI devices, SPARC64 PCI devices,
and AR5312 WiSoC devices. MIPS PCI devices appear to be busted (possibly only
on Alchemy hardware, unconfirmed), and cardbus support is untested due to
lack of test hardware.

Please report any new problems with this import to garrett@.
 1.73 26-May-2006  blymn Clean up bogus whitespace
 1.72 11-May-2006  mrg branches: 1.72.2;
cast the return value of several macros that evaluate to "(func() == FOO)"
to (void) to avoid "computed value not used" warnings.
 1.71 14-Apr-2006  christos Coverity CID 725: Remove dead code.
 1.70 02-Apr-2006  gdamore Reorganize ath layout as requested by sam@ and suggested by dyoung@ in
http://mail-index.netbsd.org/tech-net/2006/03/15/0000.html.

The new layout almost precisely matches FreeBSD, and should make
future imports much easier.

At the same time, import the current 0.9.16.16 HAL from FreeBSD. According
to sam@, this is the proper version we should be using.
 1.69 08-Mar-2006  lukem branches: 1.69.2;
Use the SI capitalization for "Hz", "kHz", and "MHz" in comments and strings.
Add a space between numbers and Hz unit.
 1.68 02-Mar-2006  dyoung branches: 1.68.2; 1.68.4;
Miscellaneous ath(4) and net80211 updates and bug-fixes coming from
sam@ and various open source repositories:

ath(4):

Ignore "phantom" beacon misses: should stabilize connections
to access points (no more ceaseless link-UP/DOWN indications).
Also, re-synchronize beacon timer using the TSF in the
first beacon received after joining a BSS---this should
also help suppress spurious beacon misses. I am hopeful
that this will help ath(4) lossage reported by perry@ and
smb@.

Add new configuration through sysctl.

Use a shorter calibration interval until IQ calibration
finishes.

Report antenna noise through radiotap.

Rudiments of Radar Detection / Dynamic Frequency Selection.

Update to HAL version 0.9.16.13.

Update open sources for changes to the HAL API.

Add HALs for additional architectures: add big-endian ELF
HALs for sparc64 and for PowerPC. Also add a Alpha HAL.
These new HALs are untested under NetBSD.

ath(4) + net80211:

Make the multicast transmit rate configurable by ioctl.

Miscellaneous bug fixes.
 1.67 27-Feb-2006  dyoung Quiet ath(4) when debug output is enabled with the hw.athX.debug
sysctl: only print messages pertaining to transmission when
ATH_DEBUG_XMIT is set, instead of printing them when ATH_DEBUG_ANY
is set.

Patch via Sam Leffler.
 1.66 24-Dec-2005  perry branches: 1.66.2; 1.66.4; 1.66.6;
Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.65 03-Dec-2005  rpaulo s/NBFILTER/NBPFILTER
 1.64 03-Dec-2005  rpaulo Make this compile without bpf(4).
 1.63 24-Nov-2005  dyoung Put the microsecond timestamp in the radiotap header for received
frames.
 1.62 23-Nov-2005  dyoung Non-functional change: a missing '}' in an #ifdef __FreeBSD__
section confuses ctags(1), so I add the '}'.
 1.61 18-Nov-2005  skrll Resolve conflicts.
 1.60 14-Oct-2005  gdt branches: 1.60.6;
When bringing an interface up, and thus perhaps having just powered it
on (e.g. cardbus), write the wep keys to the card. Fixes problem of
receiving gibberish if one has set wep keys before bringing the
interface up, and also after ifconfig ath0 down; ifconfig ath0 up.

(Tested with current from 20050926 with local mods, and discussed with
sam@ and dyoung@. This is not 100% right, but significantly better
than before. Really we should have an interator in net80211 to repush
all key state, include per-node keys.)
 1.59 13-Sep-2005  martin The entity passed to the HAL as a HAL_BUS_HANDLE needs to be an integral
or pointer type. So on sparc64 (and maybe others too?) where
bus_space_handle_t is a struct, pass the address of the bus_space_handle_t
and adjust the register access functions accordingly.

While there, slightly optimize the bus_space_* usage in the register
access functions and macros.
 1.58 21-Aug-2005  dyoung Remove redundant ath_tsf_extend subroutine. Use ath_extend_tsf,
instead. This reduces diffs with FreeBSD as a side-effect.
 1.57 27-Jul-2005  dyoung A few fixes affecting user control of the transmit/receive antenna,
and antenna diversity:

Check the hardware capabilities---transmit power control (TPC),
antenna diversity---before setting up the sysctls that control
those capabilities. Previously, the TPC and ant. diversity sysctls
were not setup because ath_sysctlattach was called before sc_hastpc
and sc_hasdiversity were initialized, so users could not view/control
antenna diversity or TPC settings, even on hardware with those
capabilities.

Obey the user's transmit-antenna selection even when sending IBSS
beacons on hardware with VEOL capability; for all other hardware/modes,
only switch transmit antennas after every four beacons if the user
has not selected a transmit antenna---i.e., they chose antenna 1
or 2 instead of 0 ("auto").
 1.56 27-Jul-2005  dyoung Cosmetic: remove an out-dated "note to self."
 1.55 26-Jul-2005  dyoung Resolve conflicts.
 1.54 06-Jul-2005  dyoung Historically, an(4), ath(4), atw(4), rtw(4), and wi(4) have printed
out their modes and rates at boot. Revert to the historical
behavior.
 1.53 03-Jul-2005  dyoung branches: 1.53.2;
Locking changes.

+ Synchronize ath_calibrate() with ATH_LOCK()/ATH_UNLOCK(). Thanks
to Steve Woodford for suggesting this fix. This patch stops
ath(4) from generating messages "hardware error; resetting" while
Steve's D-Link DWL-AG650 card is operating (kern/28385). The
MiniPCI wireless adapter on one of my Soekris boards also operates
more reliably following this patch.

+ Use ATH_LOCK_IMPL() and family to synchronize access to the
transmit queue, also.
 1.52 03-Jul-2005  dyoung Create per-instance sysctl nodes for ath(4), e.g., hw.ath0.debug,
hw.ath1.debug.
 1.51 03-Jul-2005  dyoung Bug fix: send all multicast data frames at the lowest possible data
rate, with short preamble turned *off*. Fixes IBSS operation,
where multicast frames were sent at the highest possible rate with
short preamble turned *on*, so the likelihood of reception was
relatively low, and there was no chance for stations w/o short
preamble capability to receive the frames.

XXX This is a quick fix that I will revisit very soon. Multicast
data frames are eligible to be sent with short preamble in
IEEE80211_M_STA, IEEE80211_M_HOSTAP modes. An AP knows who all of
its peers are at all times, so it can make an intelligent decision.
Ditto the AP client.

XXX The rate adaptation should be involved in choosing short/long
preamble. Also, we can make a reasonable choice of a higher
multicast data rate based on statistics gathered by the rate
adaptation module.
 1.50 03-Jul-2005  dyoung Cosmetic: repair indentation.
 1.49 30-Jun-2005  dyoung Fix $FreeBSD$ RCS IDs, which gave me a real shock when their revision
numbers moved backwards.
 1.48 22-Jun-2005  martin Remove unused <atomic.h> include; add <sys/device.h> includes where
needed.
 1.47 22-Jun-2005  dyoung Resolve conflicts in importation of 18-May-2005 ath(4) / net80211(9)
from FreeBSD. Introduce compatibility shims (sys/dev/ic/ath_netbsd.[ch],
sys/net80211/ieee80211_netbsd.[ch]). Update drivers (an, atu, atw,
awi, ipw, iwi, rtw, wi) for the new net80211(9) API.
 1.46 20-Jun-2005  atatat Change the rest of the sysctl subsystem to use const consistently.
The __UNCONST macro is now used only where necessary and the RW macros
are gone. Most of the changes here are consumers of the
sysctl_createv(9) interface that now takes a pair of const pointers
which used not to be.
 1.45 27-Feb-2005  perry nuke trailing whitespace
 1.44 19-Jan-2005  dyoung branches: 1.44.2;
For a proper IBSS merge, we have to discard the old beacon packet,
create and queue a new one that carries the new BSSID. I mined
net80211 in FreeBSD for the solution, which is to make an
IEEE80211_S_RUN->IEEE80211_S_RUN state transition---ath_newstate
discards the old beacon packet creates a new one by calling
ath_beacon_alloc.

I tested the merge as follows. Starting at my desk on the second
floor of the building where I work:

soekris% ifconfig ath0 mediaopt adhoc ssid zzz chan 11 down

powerbook% ifconfig rtw0 mediaopt adhoc ssid zzz chan 11 up

soekris% sleep 25; ifconfig ath0 up

I raced to the elevator with my Powerbook, pressed the "Down"
button, got in, and pressed "Floor 1." At the first floor:

powerbook% ifconfig rtw0 | grep bssid
bssid 02:p:p:p:p:p chan 11

I waited 25 seconds. I pressed "Floor 2." At Floor 2, I returned to my desk.
I checked to make sure that the Soekris console read:

soekris% ath0: creating bss 02:s:s:s:s:s
ath0: bss merge 02:s:s:s:s:s -> 02:p:p:p:p:p

0:s:s:s:s:s is the Soekris' WLAN MAC. 0:p:p:p:p:p is the Powerbook's
WLAN MAC. Each created an ad hoc-mode BSSID from its WLAN MAC by
OR'ing 0x2 with the first octet.

My Powerbook created a network while the Soekris radio was off.
The Soekris radio turned on while I was in the 802.11-impervious
elevator with my Powerbook. When I returned to the second floor,
the Soekris "heard" beacons from my Powerbook as the elevator door
opened. Since the Powerbook's network was approximately 25 seconds
older than the Soekris', and since it had the same SSID (zzz) as
the Soekris', the Soekris merged with the Powerbook's network (by
setting its BSSID) as it should.
 1.43 16-Jan-2005  dyoung branches: 1.43.2;
It's necessary to stop DMA on the beacon ring and reconfigure the
beacon after an IBSS merge, or else beacons transmissions may not
resume like we expect. From Sam Leffler.
 1.42 04-Jan-2005  dyoung In ad hoc mode, start the ath rate adaptation with the lowest, most
robust transmit bit rate. From Greg Troxel.
 1.41 04-Jan-2005  dyoung IBSS-merge clean-up, inspired by some Linux patches from Jon Anderson
(mail@janderson.ca): remove ieee80211_ibss_merge's TSFT argument.
Do the TSFT comparison in the drivers (ath, atw). Remove a lot of
extraneous debug statements from ieee80211_ibss_merge.

Set the ieee80211_node's state to IEEE80211_STA_BSS after it's been
copied to the ic_bss, not before.

In struct ieee80211_node, make the ni_tstamp field a union of a
uint64_t and the 8 TSF octets so that it's easier to compare a
neighbor's TSF with the local TSF.

Log IBSS merges (Greg Troxel's suggestion). Also log IBSS creation.
These are rare and important events that deserve to be logged.
 1.40 27-Dec-2004  dyoung Disconnect the "stop transmitter/receiver" function from the
"power-off NIC" function, by adding a 'disable' argument to ath_stop.
Pass disable=0 to ath_stop() at the top of ath_init, so that we
don't power-off the Cardbus slot before resetting the HAL. Thanks
to Greg Troxel for his analysis of this bug.
 1.39 28-Sep-2004  yamt ath_getmbuf: check MCLGET failure.
 1.38 07-Sep-2004  enami ath_debug is bitmask and takes much wider value than 0, 1, or 2.
 1.37 18-Aug-2004  dyoung Hubert Feyrer points out that hw.ath.countrycode really ought to
be writeable. Make hw.ath.outdoor writeable while I am here.
 1.36 10-Aug-2004  dyoung IBSS fixes: get IBSS beacon generation right. Merge with a same-SSID,
same-channel IBSS.
 1.35 10-Aug-2004  dyoung Make the node table into an LRU cache: least-recently used nodes
are at the end of the node queue. Change the reference-counting
discipline: ni->ni_refcnt indicates how many times net80211 has
granted ni to the driver. Every node in the table with ni_refcnt=0
is eligible to be garbage-collected. The mere presence of a node
in the table does not any longer indicate its auth/assoc state;
nodes have a ni_state variable, now. A sysctl,
net.link.ieee80211.maxnodecache, controls the maximum LRU cache
size.

While I am here, patch ieee80211_find_node_for_beacon to do a "best
match" by bssid/ssid/channel, not a "perfect match." This keeps
net80211 from caching duplicate nodes in the table.
 1.34 08-Aug-2004  yamt ath_init1: return EIO rather than -1 on a failure of ath_hal_reset.
-1 isn't appropriate for if_init.
 1.33 03-Aug-2004  dyoung Synchronize with the WEP code in madwifi. Konstantin KABASSANOV
verified for me that this fixes his WEP problems. The HAL ABI for
WEP had changed.
 1.32 30-Jul-2004  mycroft branches: 1.32.2;
Only discard beacons in AHDEMO mode, where we ignore management frames
completely. In particular, accept them in monitor mode (where we generally
aren't doing anything unless we're in promiscuous mode anyway) and host-AP
mode (where we want to see neighbor APs).
 1.31 28-Jul-2004  dyoung Finalize import of the Atheros HAL 0.9.9.13, bringing ath(4)
up-to-date where the HAL API changed.
 1.30 23-Jul-2004  mycroft Cleanup of ieee80211_node from madwifi:
* Don't use ifp pointers; use ieee80211com.
* Implement the locking macros that are used under FreeBSD and Linux.
 1.29 23-Jul-2004  mycroft IEEE80211_F_WEPON -> IEEE80211_F_PRIVACY
 1.28 22-Jul-2004  mycroft Support promiscuous mode for an AP too(!).
 1.27 31-May-2004  dyoung No need for ath_start to set the WEP bit in the frame header, the
802.11 layer does it for us.
 1.26 25-May-2004  atatat Remaining sysctl descriptions under hw subtree (ath and bge)
 1.25 30-Apr-2004  dyoung From FreeBSD. Lots has changed. I lazily yank text from the
FreeBSD commit log:
 1.24 27-Mar-2004  atatat branches: 1.24.2;
GC ath_node_root as well, but modify to work around the single
(tightly scoped) reason for recording the node address by recording
the assigned number. Dink pci/if_bge.c to match, since ic/ath.c was
used as the archetype.
 1.23 24-Mar-2004  atatat Tango on sysctl_createv() and flags. The flags have all been renamed,
and sysctl_createv() now uses more arguments.
 1.22 15-Mar-2004  dyoung Move the ath(4) sysctls to hw.ath from ath.
 1.21 13-Mar-2004  dyoung Enable extended channel set.

Add some debug code for printing the HAL's notion of available
channels if hw.ath.debug = 1.
 1.20 01-Mar-2004  dyoung Attach the ath(4) sysctls:

ath.dwell: channel dwell time (ms) for AP/station scanning
ath.calibrate: chip calibration interval (secs)
ath.outdoor: enable/disable outdoor operation
ath.countrycode: (opaque?) country code
ath.regdomain: (opaque?) regulatory domain
ath.debug: 0 (no debug messages), 1 (some messages), 2 (all messages)
 1.19 29-Feb-2004  dyoung Update ath(4)'s Hardware Abstraction Layer (HAL) to version 0.9.6.11.

Both the API and ABI changed, hence the changes to so many .c and
.h files.
 1.18 16-Dec-2003  dyoung Synchronize with FreeBSD:

* add constants to enums

* HAL update: stops panics, fixes ad hoc-mode beacons, some API
changes

* get and use mac/phy/rf front-end revision codes

* add a custom ath(4) ic_node_getrssi callback which does RSSI
averaging

* do not immediately scan, but re-associate after missing beacons.

* bug fix: don't if_init after detach.

* HAL diagnostics ioctl, SIOCGATHDIAG

* send DS parameters element in beacons

* const-ify some pointers

* consolidate rx-filter settings into ath_calcrxfilter

* abstract FreeBSD `ticks', NetBSD `hardclock_ticks' with ATH_TICKS()

* misc. other changes
 1.17 07-Dec-2003  dyoung In _STA mode, don't panic when a stray beacon-miss interrupt is
received. Instead, ignore it. It's normal for a stray to come
during the transition to monitor mode.
 1.16 16-Nov-2003  dyoung So that the internal bridge works in AP mode, call ath_start after
processing Rx packets.
 1.15 02-Nov-2003  wiz Fix some typos. From Tom Cosgrove via jmc@openbsd.
 1.14 02-Nov-2003  dyoung Use ieee80211_find_rxnode to attribute Rx packets to the write
ieee80211_node. This reduces code duplication. It will help us
support passive scanning and rate adaptation.
 1.13 21-Oct-2003  yamt don't swap powerhook and shutdownhook.
 1.12 16-Oct-2003  dyoung Fix WEP transmission, too. From FreeBSD/Sam Leffler.
 1.11 16-Oct-2003  dyoung ath(4) failed to detect when the number of DMA segments exceeded
the number of descriptors, because of a disparity between the
bus_dmamap_load_mbuf implementation in FreeBSD and NetBSD. Now I
cover up the difference using ath_dmamap_load_mbuf.

Thanks Enami Tsugutomo for diagnosing this.
 1.10 16-Oct-2003  ichiro add {shutdownhook,powerhook}disestablish()
 1.9 15-Oct-2003  itojun add $NetBSD$
 1.8 15-Oct-2003  enami Return 0 on SIOC{ADD,DEL}MULTI.
 1.7 15-Oct-2003  itojun s/printf/DPRINTF/ for ath_rate_ctl()
 1.6 15-Oct-2003  dyoung Fix WEP reception.
 1.5 15-Oct-2003  enami Port multicast handling to NetBSD. Addresses PR23151.
 1.4 14-Oct-2003  dyoung Do not index arrays using enum constants, since enums can be
re-ordered and extended. Instead, use a switch-statement or a
key->value table with appropriate bounds-checking.
 1.3 14-Oct-2003  ichiro add support ath on cardbus
- implement power management
 1.2 13-Oct-2003  dyoung NetBSD/FreeBSD compatibility changes NetBSD, especially
locking, mbuf
 1.1 07-Oct-2003  dyoung branches: 1.1.1;
Initial revision
 1.1.1.6 18-Nov-2005  skrll Import FreeBSD's ath(4) of 1-nov-2005
 1.1.1.5 26-Jul-2005  dyoung Import FreeBSD's ath(4) of 2005-07-11
 1.1.1.4 21-Jun-2005  dyoung Import FreeBSD's ath(4) of 2005-05-18
 1.1.1.3 29-Apr-2004  dyoung Import FreeBSD's ath of 28-apr-2004
 1.1.1.2 15-Dec-2003  dyoung Import FreeBSD's ath of 12-dec-2003
 1.1.1.1 07-Oct-2003  dyoung Initial import of ath(4) from FreeBSD.
 1.24.2.3 22-Aug-2004  tron Pull up revision 1.37 (requested by dyoung in ticket #772):
Hubert Feyrer points out that hw.ath.countrycode really ought to
be writeable. Make hw.ath.outdoor writeable while I am here.
 1.24.2.2 23-Jul-2004  he Pull up revision 1.28 (requested by mycroft in ticket #693):
Support promiscuous mode for an AP too(!).
 1.24.2.1 29-May-2004  tron Pull up revision 1.26 (requested by atatat in ticket #392):
Remaining sysctl descriptions under hw subtree (ath and bge)
 1.32.2.12 11-Dec-2005  christos Sync with head.
 1.32.2.11 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.32.2.10 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.32.2.9 24-Jan-2005  skrll Sync with HEAD.
 1.32.2.8 17-Jan-2005  skrll Sync with HEAD.
 1.32.2.7 19-Oct-2004  skrll Sync with HEAD
 1.32.2.6 21-Sep-2004  skrll Fix the sync with head I botched.
 1.32.2.5 18-Sep-2004  skrll Sync with HEAD.
 1.32.2.4 25-Aug-2004  skrll Sync with HEAD.
 1.32.2.3 12-Aug-2004  skrll Sync with HEAD.
 1.32.2.2 03-Aug-2004  skrll Sync with HEAD
 1.32.2.1 30-Jul-2004  skrll file ath.c was added on branch ktrace-lwp on 2004-08-03 10:46:10 +0000
 1.43.2.2 29-Apr-2005  kent sync with -current
 1.43.2.1 16-Jan-2005  kent file ath.c was added on branch kent-audio2 on 2005-04-29 11:28:49 +0000
 1.44.2.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.53.2.8 17-Mar-2008  yamt sync with head.
 1.53.2.7 21-Jan-2008  yamt sync with head
 1.53.2.6 07-Dec-2007  yamt sync with head
 1.53.2.5 27-Oct-2007  yamt sync with head.
 1.53.2.4 03-Sep-2007  yamt sync with head.
 1.53.2.3 26-Feb-2007  yamt sync with head.
 1.53.2.2 30-Dec-2006  yamt sync with head.
 1.53.2.1 21-Jun-2006  yamt sync with head.
 1.60.6.2 29-Nov-2005  yamt sync with head.
 1.60.6.1 22-Nov-2005  yamt sync with head.
 1.66.6.3 07-Jun-2006  kardel Sync with head.
 1.66.6.2 01-Jun-2006  kardel Sync with head.
 1.66.6.1 22-Apr-2006  simonb Sync with head.
 1.66.4.1 09-Sep-2006  rpaulo sync with head
 1.66.2.1 01-Mar-2006  yamt sync with head.
 1.68.4.1 19-Apr-2006  elad sync with head.
 1.68.2.5 11-Aug-2006  yamt sync with head
 1.68.2.4 26-Jun-2006  yamt sync with head.
 1.68.2.3 24-May-2006  yamt sync with head.
 1.68.2.2 11-Apr-2006  yamt sync with head
 1.68.2.1 13-Mar-2006  yamt sync with head.
 1.69.2.1 24-May-2006  tron Merge 2006-05-24 NetBSD-current into the "peter-altq" branch.
 1.72.2.1 19-Jun-2006  chap Sync with head.
 1.76.6.2 10-Dec-2006  yamt sync with head.
 1.76.6.1 22-Oct-2006  yamt sync with head
 1.76.4.3 01-Feb-2007  ad Sync with head.
 1.76.4.2 12-Jan-2007  ad Sync with head.
 1.76.4.1 18-Nov-2006  ad Sync with head.
 1.81.2.2 07-May-2007  yamt sync with head.
 1.81.2.1 12-Mar-2007  rmind Sync with HEAD.
 1.82.4.1 11-Jul-2007  mjf Sync with head.
 1.82.2.4 23-Oct-2007  ad Sync with head.
 1.82.2.3 09-Oct-2007  ad Sync with head.
 1.82.2.2 20-Aug-2007  ad Sync with HEAD.
 1.82.2.1 27-May-2007  ad Sync with head.
 1.84.8.3 23-Mar-2008  matt sync with HEAD
 1.84.8.2 09-Jan-2008  matt sync with HEAD
 1.84.8.1 06-Nov-2007  matt sync with HEAD
 1.84.6.5 27-Nov-2007  joerg Sync with HEAD. amd64 Xen support needs testing.
 1.84.6.4 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.84.6.3 01-Oct-2007  joerg Extend device API by device_power_private and device_power_set_private.
The latter is a temporary mean until the pnp_register API itself is
overhault. This functions allow a generic power handler to store its
state independent of the driver.

Use this and revamp the PCI power handling. Pretty much all PCI devices
had power handlers that did the same thing, generalize this in
pci_generic_power_register/deregister and the handler. This interface
offers callbacks for the drivers to save and restore state on
transistions. After a long discussion with jmcneill@ it was considered
to be powerful enough until evidence is shown that devices can handle
D1/D2 with less code and higher speed than without the full
save/restore. The generic code is carefully written to handle device
without PCI-PM support and ensure that the correct registers are written
to when D3 loses all state.

Reimplement the generic PCI network device handling on
top of PCI generic power handling.

Introduce pci_disable_retry as used and implemented locally at least by
ath(4) and iwi(4). Use it in this drivers to restore behaviour from
before the introduction of generic PCI network handling.

Convert all PCI drivers that were using pnp_register to the new
framework. The only exception is vga(4) as it is commonly used as
console device. Add a note therein that this should be fixed later.
 1.84.6.2 03-Sep-2007  jmcneill Sync with HEAD.
 1.84.6.1 23-Aug-2007  joerg Convert ath(4) to new style power management.
Remove the resetting of the PCI retry register on resume,
the restored configuration should have it already.
 1.84.2.1 03-Sep-2007  skrll Sync with HEAD.
 1.86.4.1 25-Oct-2007  bouyer Sync with HEAD.
 1.87.2.3 18-Feb-2008  mjf Sync with HEAD.
 1.87.2.2 27-Dec-2007  mjf Sync with HEAD.
 1.87.2.1 08-Dec-2007  mjf Sync with HEAD.
 1.92.4.1 11-Dec-2007  yamt sync with head.
 1.92.2.1 26-Dec-2007  ad Sync with head.
 1.93.2.2 08-Jan-2008  bouyer Sync with HEAD
 1.93.2.1 02-Jan-2008  bouyer Sync with HEAD
 1.98.6.5 17-Jan-2009  mjf Sync with HEAD.
 1.98.6.4 28-Sep-2008  mjf Sync with HEAD.
 1.98.6.3 29-Jun-2008  mjf Sync with HEAD.
 1.98.6.2 02-Jun-2008  mjf Sync with HEAD.
 1.98.6.1 03-Apr-2008  mjf Sync with HEAD.
 1.98.2.1 24-Mar-2008  keiichi sync with head.
 1.99.4.5 11-Aug-2010  yamt sync with head.
 1.99.4.4 11-Mar-2010  yamt sync with head
 1.99.4.3 19-Aug-2009  yamt sync with head.
 1.99.4.2 04-May-2009  yamt sync with head.
 1.99.4.1 16-May-2008  yamt sync with head.
 1.99.2.2 17-Jun-2008  yamt sync with head.
 1.99.2.1 18-May-2008  yamt sync with head.
 1.100.4.2 18-Jul-2008  simonb Sync with head.
 1.100.4.1 18-Jun-2008  simonb Sync with head.
 1.100.2.2 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.100.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.101.2.2 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.101.2.1 19-Oct-2008  haad Sync with HEAD.
 1.102.8.1 21-Apr-2010  matt sync to netbsd-5
 1.102.4.2 07-Aug-2009  snj Pull up following revision(s) (requested by jmcneill in ticket #775):
sys/dev/ic/ath.c: revision 1.106
sys/dev/ic/athvar.h: revision 1.28
- fix TKIP, changes adapted from FreeBSD
- reduce diffs between FreeBSD and NetBSD athvar.h
 1.102.4.1 07-Aug-2009  snj Apply patch (requested by jmcneill in ticket 775):
Update to the open source atheros HAL.
 1.102.2.1 19-Jan-2009  skrll Sync with HEAD.
 1.108.4.3 21-Apr-2011  rmind sync with head
 1.108.4.2 05-Mar-2011  rmind sync with head
 1.108.4.1 30-May-2010  rmind sync with head
 1.108.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.109.4.1 05-Mar-2011  bouyer Sync with HEAD
 1.109.2.1 06-Jun-2011  jruoho Sync with HEAD.
 1.112.2.3 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.112.2.2 16-Jan-2013  yamt sync with (a bit old) head
 1.112.2.1 17-Apr-2012  yamt sync with head
 1.113.8.4 03-Dec-2017  jdolecek update from HEAD
 1.113.8.3 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.113.8.2 25-Feb-2013  tls resync with head
 1.113.8.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.115.2.1 18-May-2014  rmind sync with head
 1.116.10.1 17-Dec-2019  martin Pull up following revision(s) (requested by christos in ticket #1718):

sys/dev/ic/ath.c: revision 1.129

Protect network ioctls from non-authorized users. (Ilja Van Sprundel)
 1.116.6.1 17-Dec-2019  martin Pull up following revision(s) (requested by christos in ticket #1718):

sys/dev/ic/ath.c: revision 1.129

Protect network ioctls from non-authorized users. (Ilja Van Sprundel)
 1.116.4.1 17-Dec-2019  martin Pull up following revision(s) (requested by christos in ticket #1718):

sys/dev/ic/ath.c: revision 1.129

Protect network ioctls from non-authorized users. (Ilja Van Sprundel)
 1.117.2.4 05-Feb-2017  skrll Sync with HEAD
 1.117.2.3 09-Jul-2016  skrll Sync with HEAD
 1.117.2.2 29-May-2016  skrll Sync with HEAD
 1.117.2.1 22-Apr-2016  skrll Sync with HEAD
 1.122.4.1 21-Apr-2017  bouyer Sync with HEAD
 1.122.2.1 20-Mar-2017  pgoyette Sync with HEAD
 1.123.12.1 28-Jul-2018  pgoyette Sync with HEAD
 1.123.6.1 17-Dec-2019  martin Pull up following revision(s) (requested by christos in ticket #1475):

sys/dev/ic/ath.c: revision 1.129

Protect network ioctls from non-authorized users. (Ilja Van Sprundel)
 1.124.2.3 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.124.2.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.124.2.1 10-Jun-2019  christos Sync with HEAD
 1.127.2.1 17-Dec-2019  martin Pull up following revision(s) (requested by christos in ticket #569):

sys/dev/usb/if_umb.c: revision 1.10
sys/net/if.c: revision 1.466
sys/dev/ic/ath.c: revision 1.129

Protect network ioctls from non-authorized users. (Ilja Van Sprundel)
 1.129.2.1 29-Feb-2020  ad Sync with head.
 1.132.2.1 14-Dec-2020  thorpej Sync w/ HEAD.
 1.133.2.1 17-Apr-2021  thorpej Sync with HEAD.
 1.134.2.1 17-Jun-2021  thorpej Sync w/ HEAD.
 1.138.10.1 02-Aug-2025  perseant Sync with HEAD
 1.23 25-Sep-2022  thorpej Remove unnecessary include of <sys/malloc.h>.
 1.22 25-Feb-2014  pooka Ensure that the top level sysctl nodes (kern, vfs, net, ...) exist before
the sysctl link sets are processed, and remove redundancy.

Shaves >13kB off of an amd64 GENERIC, not to mention >1k duplicate
lines of code.
 1.21 17-Jul-2011  joerg branches: 1.21.2; 1.21.12; 1.21.16;
Retire varargs.h support. Move machine/stdarg.h logic into MI
sys/stdarg.h and expect compiler to provide proper builtins, defaulting
to the GCC interface. lint still has a special fallback.
Reduce abuse of _BSD_VA_LIST_ by defining __va_list by default and
derive va_list as required by standards.
 1.20 07-Mar-2011  cegger Get improvements from FreeBSD-current (January 2011).
Successfully tested with WEP, WPA and WPA2 on AR9285.
Reviewed by jmcneill@
 1.19 20-Feb-2011  jmcneill support building as a module
 1.18 21-Jan-2011  dyoung Move device_printf() from ath_netbsd.c to subr_prf.c for reuse in a new
driver.
 1.17 19-Oct-2009  rmind branches: 1.17.4; 1.17.6; 1.17.8;
Drop 3rd and 4th clauses from David Young's license.
Reviewed and approved by dyoung@ (copyright holder).
 1.16 12-Nov-2008  ad Remove LKMs and switch to the module framework, pass 1.

Proposed on tech-kern@.
 1.15 09-Jul-2008  joerg branches: 1.15.2;
- device/softc split for ath(4)
 1.14 08-Apr-2008  cegger branches: 1.14.4; 1.14.6; 1.14.8; 1.14.10;
use aprint_*_dev and device_xname
 1.13 04-Jan-2008  ad branches: 1.13.6;
Start detangling lock.h from intr.h. This is likely to cause short term
breakage, but the mess of dependencies has been regularly breaking the
build recently anyhow.
 1.12 26-Nov-2007  dyoung branches: 1.12.6;
Use device_xname(). Make device_printf() take a device_t argument.
Add __attribute__((__format__(__printf__,2,3))) to device_printf()
so that the compiler will help us detect bad arguments.

Retire unused subroutine m_defrag(), and unused declaration m_getcl().
 1.11 19-Oct-2007  ad branches: 1.11.2;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.10 04-Mar-2007  christos branches: 1.10.2; 1.10.14; 1.10.16; 1.10.20;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.9 29-Jan-2007  hubertf branches: 1.9.2;
Remove more duplicate headers.
Patch by Slava Semushin <slava.semushin@gmail.com>

Again, this was tested by comparing obj files from a pristine and a patched
source tree against an i386/ALL kernel, and also for src/sbin/fsck_ffs,
src/sbin/fsdb and src/usr.sbin/makefs. Only changes in assert() line numbers
were detected in 'objdump -d' output.
 1.8 11-May-2006  mrg branches: 1.8.8;
cast the return value of several macros that evaluate to "(func() == FOO)"
to (void) to avoid "computed value not used" warnings.
 1.7 02-Mar-2006  dyoung branches: 1.7.2; 1.7.6;
Miscellaneous ath(4) and net80211 updates and bug-fixes coming from
sam@ and various open source repositories:

ath(4):

Ignore "phantom" beacon misses: should stabilize connections
to access points (no more ceaseless link-UP/DOWN indications).
Also, re-synchronize beacon timer using the TSF in the
first beacon received after joining a BSS---this should
also help suppress spurious beacon misses. I am hopeful
that this will help ath(4) lossage reported by perry@ and
smb@.

Add new configuration through sysctl.

Use a shorter calibration interval until IQ calibration
finishes.

Report antenna noise through radiotap.

Rudiments of Radar Detection / Dynamic Frequency Selection.

Update to HAL version 0.9.16.13.

Update open sources for changes to the HAL API.

Add HALs for additional architectures: add big-endian ELF
HALs for sparc64 and for PowerPC. Also add a Alpha HAL.
These new HALs are untested under NetBSD.

ath(4) + net80211:

Make the multicast transmit rate configurable by ioctl.

Miscellaneous bug fixes.
 1.6 05-Feb-2006  xtraeme Add missing $NetBSD$ tags and __KERNEL_RCSID().
 1.5 18-Nov-2005  skrll branches: 1.5.2; 1.5.4; 1.5.6;
Adapt drivers to the new net80211(9).

Most of this is from dyoung@. Thanks!
 1.4 28-Jul-2005  dyoung branches: 1.4.6; 1.4.8;
Export ath_sysctl_instance for the SampleRate rate-control module
to use.

Also, add sysctl helper macro SYSCTL_PFX_INT (for SampleRate) that
prepends an arbitrary prefix to the sysctl name, instead of sc->sc_
like SYSCTL_INT. Factor with SYSCTL_INT.
 1.3 03-Jul-2005  dyoung branches: 1.3.2;
Create per-instance sysctl nodes for ath(4), e.g., hw.ath0.debug,
hw.ath1.debug.
 1.2 22-Jun-2005  martin Remove unused <atomic.h> include; add <sys/device.h> includes where
needed.
 1.1 22-Jun-2005  dyoung Resolve conflicts in importation of 18-May-2005 ath(4) / net80211(9)
from FreeBSD. Introduce compatibility shims (sys/dev/ic/ath_netbsd.[ch],
sys/net80211/ieee80211_netbsd.[ch]). Update drivers (an, atu, atw,
awi, ipw, iwi, rtw, wi) for the new net80211(9) API.
 1.3.2.6 21-Jan-2008  yamt sync with head
 1.3.2.5 07-Dec-2007  yamt sync with head
 1.3.2.4 27-Oct-2007  yamt sync with head.
 1.3.2.3 03-Sep-2007  yamt sync with head.
 1.3.2.2 26-Feb-2007  yamt sync with head.
 1.3.2.1 21-Jun-2006  yamt sync with head.
 1.4.8.1 22-Nov-2005  yamt sync with head.
 1.4.6.3 11-Dec-2005  christos Sync with head.
 1.4.6.2 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.4.6.1 28-Jul-2005  skrll file ath_netbsd.c was added on branch ktrace-lwp on 2005-11-10 14:04:13 +0000
 1.5.6.2 01-Jun-2006  kardel Sync with head.
 1.5.6.1 22-Apr-2006  simonb Sync with head.
 1.5.4.1 09-Sep-2006  rpaulo sync with head
 1.5.2.1 18-Feb-2006  yamt sync with head.
 1.7.6.1 24-May-2006  tron Merge 2006-05-24 NetBSD-current into the "peter-altq" branch.
 1.7.2.1 24-May-2006  yamt sync with head.
 1.8.8.1 01-Feb-2007  ad Sync with head.
 1.9.2.1 12-Mar-2007  rmind Sync with HEAD.
 1.10.20.1 25-Oct-2007  bouyer Sync with HEAD.
 1.10.16.2 09-Jan-2008  matt sync with HEAD
 1.10.16.1 06-Nov-2007  matt sync with HEAD
 1.10.14.2 27-Nov-2007  joerg Sync with HEAD. amd64 Xen support needs testing.
 1.10.14.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.10.2.1 23-Oct-2007  ad Sync with head.
 1.11.2.2 18-Feb-2008  mjf Sync with HEAD.
 1.11.2.1 08-Dec-2007  mjf Sync with HEAD.
 1.12.6.1 08-Jan-2008  bouyer Sync with HEAD
 1.13.6.3 17-Jan-2009  mjf Sync with HEAD.
 1.13.6.2 28-Sep-2008  mjf Sync with HEAD.
 1.13.6.1 02-Jun-2008  mjf Sync with HEAD.
 1.14.10.2 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.14.10.1 19-Oct-2008  haad Sync with HEAD.
 1.14.8.1 18-Jul-2008  simonb Sync with head.
 1.14.6.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.14.4.2 11-Mar-2010  yamt sync with head
 1.14.4.1 04-May-2009  yamt sync with head.
 1.15.2.1 19-Jan-2009  skrll Sync with HEAD.
 1.17.8.2 05-Mar-2011  bouyer Sync with HEAD
 1.17.8.1 08-Feb-2011  bouyer Sync with HEAD
 1.17.6.1 06-Jun-2011  jruoho Sync with HEAD.
 1.17.4.2 21-Apr-2011  rmind sync with head
 1.17.4.1 05-Mar-2011  rmind sync with head
 1.21.16.1 18-May-2014  rmind sync with head
 1.21.12.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.21.2.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.16 02-Feb-2017  nonaka wlan interfaces make interrupt routine running on softint context.

see http://mail-index.netbsd.org/tech-kern/2016/12/06/msg021281.html

tested device:
* ath at pci: AR5212, AR5424
* athn at pci: AR9287
* ipw at pci: 2100BG
* iwi at pci: 2915ABG
* iwm at pci: 3165, 7260, 8260
* iwn at pci: 4945, 6235
* ral at pci: RT2560
* rtwn at pci: RTL8192CE
 1.15 27-Jan-2013  jmcneill branches: 1.15.14; 1.15.18; 1.15.22;
don't transmit while in a key change is in progress
 1.14 08-Nov-2012  dyoung Use NetBSD's own KASSERT() and KASSERTMSG() instead of #undef and re-#defining
KASSERT(), which is awkward at best.
 1.13 02-Jun-2012  dsl branches: 1.13.2;
Add some pre-processor magic to verify that the type of the data item
passed to sysctl_createv() actually matches the declared type for
the item itself.
In the places where the caller specifies a function and a structure
address (typically the 'softc') an explicit (void *) cast is now needed.
Fixes bugs in sys/dev/acpi/asus_acpi.c sys/dev/bluetooth/bcsp.c
sys/kern/vfs_bio.c sys/miscfs/syncfs/sync_subr.c and setting
AcpiGbl_EnableAmlDebugObject.
(mostly passing the address of a uint64_t when typed as CTLTYPE_INT).
I've test built quite a few kernels, but there may be some unfixed MD
fallout. Most likely passing &char[] to char *.
Also add CTLFLAG_UNSIGNED for unsiged decimals - not set yet.
 1.12 07-Oct-2011  dyoung branches: 1.12.2;
Get rid of the "I don't know what I was thinking / somebody should have
stopped me / does anybody read source-changes?" ATH_LOCK()/ATH_UNLOCK()
and bracket with splnet()/splx() instead. This is still not *good*,
since ifnet ioctls are not (yet) synchronized, but could be no worse
than what we have, now. Survives light testing with my (forthcoming)
ifnet ioctl synchronization patch.
 1.11 21-Jan-2011  dyoung Move device_printf() from ath_netbsd.c to subr_prf.c for reuse in a new
driver.
 1.10 19-Mar-2010  dyoung branches: 1.10.2; 1.10.4;
Don't pick up the <sys/sysctl.h> definitions by chance,
but #include here.
 1.9 19-Oct-2009  rmind branches: 1.9.2; 1.9.4;
Drop 3rd and 4th clauses from David Young's license.
Reviewed and approved by dyoung@ (copyright holder).
 1.8 26-Nov-2007  dyoung branches: 1.8.18;
Eliminate redundant check for read-only mbuf data, since
M_TRAILINGSPACE() does a more complete check on NetBSD.
 1.7 26-Nov-2007  dyoung Use device_xname(). Make device_printf() take a device_t argument.
Add __attribute__((__format__(__printf__,2,3))) to device_printf()
so that the compiler will help us detect bad arguments.

Retire unused subroutine m_defrag(), and unused declaration m_getcl().
 1.6 09-Jul-2007  ad branches: 1.6.6; 1.6.8; 1.6.14;
Merge some of the less invasive changes from the vmlocking branch:

- kthread, callout, devsw API changes
- select()/poll() improvements
- miscellaneous MT safety improvements
 1.5 05-Feb-2006  xtraeme branches: 1.5.24; 1.5.26;
Add missing $NetBSD$ tags and __KERNEL_RCSID().
 1.4 28-Jul-2005  dyoung branches: 1.4.6; 1.4.10; 1.4.12; 1.4.14;
Export ath_sysctl_instance for the SampleRate rate-control module
to use.

Also, add sysctl helper macro SYSCTL_PFX_INT (for SampleRate) that
prepends an arbitrary prefix to the sysctl name, instead of sc->sc_
like SYSCTL_INT. Factor with SYSCTL_INT.
 1.3 10-Jul-2005  dyoung Cosmetic: the '_type' argument to ATH_LOCK_IMPL and family is more
properly called '_obj'.
 1.2 03-Jul-2005  dyoung branches: 1.2.2;
Locking changes.

+ Synchronize ath_calibrate() with ATH_LOCK()/ATH_UNLOCK(). Thanks
to Steve Woodford for suggesting this fix. This patch stops
ath(4) from generating messages "hardware error; resetting" while
Steve's D-Link DWL-AG650 card is operating (kern/28385). The
MiniPCI wireless adapter on one of my Soekris boards also operates
more reliably following this patch.

+ Use ATH_LOCK_IMPL() and family to synchronize access to the
transmit queue, also.
 1.1 22-Jun-2005  dyoung Resolve conflicts in importation of 18-May-2005 ath(4) / net80211(9)
from FreeBSD. Introduce compatibility shims (sys/dev/ic/ath_netbsd.[ch],
sys/net80211/ieee80211_netbsd.[ch]). Update drivers (an, atu, atw,
awi, ipw, iwi, rtw, wi) for the new net80211(9) API.
 1.2.2.3 07-Dec-2007  yamt sync with head
 1.2.2.2 03-Sep-2007  yamt sync with head.
 1.2.2.1 21-Jun-2006  yamt sync with head.
 1.4.14.1 22-Apr-2006  simonb Sync with head.
 1.4.12.1 09-Sep-2006  rpaulo sync with head
 1.4.10.1 18-Feb-2006  yamt sync with head.
 1.4.6.2 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.4.6.1 28-Jul-2005  skrll file ath_netbsd.h was added on branch ktrace-lwp on 2005-11-10 14:04:13 +0000
 1.5.26.1 11-Jul-2007  mjf Sync with head.
 1.5.24.1 01-Jul-2007  ad Adapt to callout API change.
 1.6.14.1 08-Dec-2007  mjf Sync with HEAD.
 1.6.8.1 09-Jan-2008  matt sync with HEAD
 1.6.6.1 27-Nov-2007  joerg Sync with HEAD. amd64 Xen support needs testing.
 1.8.18.2 11-Aug-2010  yamt sync with head.
 1.8.18.1 11-Mar-2010  yamt sync with head
 1.9.4.2 05-Mar-2011  rmind sync with head
 1.9.4.1 30-May-2010  rmind sync with head
 1.9.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.10.4.1 08-Feb-2011  bouyer Sync with HEAD
 1.10.2.1 06-Jun-2011  jruoho Sync with HEAD.
 1.12.2.3 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.12.2.2 16-Jan-2013  yamt sync with (a bit old) head
 1.12.2.1 30-Oct-2012  yamt sync with head
 1.13.2.3 03-Dec-2017  jdolecek update from HEAD
 1.13.2.2 25-Feb-2013  tls resync with head
 1.13.2.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.15.22.1 21-Apr-2017  bouyer Sync with HEAD
 1.15.18.1 20-Mar-2017  pgoyette Sync with HEAD
 1.15.14.1 05-Feb-2017  skrll Sync with HEAD
 1.2 22-Jun-2005  dyoung Resolve conflicts in importation of 18-May-2005 ath(4) / net80211(9)
from FreeBSD. Introduce compatibility shims (sys/dev/ic/ath_netbsd.[ch],
sys/net80211/ieee80211_netbsd.[ch]). Update drivers (an, atu, atw,
awi, ipw, iwi, rtw, wi) for the new net80211(9) API.
 1.1 13-Oct-2003  dyoung branches: 1.1.4;
A compatibility layer to smooth differences between NetBSD and
FreeBSD for ath(4).

XXX Nobody with FreeBSD has signed off on this, so it may change
XXX or go away entirely.
 1.1.4.3 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.1.4.2 03-Aug-2004  skrll Sync with HEAD
 1.1.4.1 13-Oct-2003  skrll file athcompat.c was added on branch ktrace-lwp on 2004-08-03 10:46:10 +0000
 1.4 22-Jun-2005  dyoung Resolve conflicts in importation of 18-May-2005 ath(4) / net80211(9)
from FreeBSD. Introduce compatibility shims (sys/dev/ic/ath_netbsd.[ch],
sys/net80211/ieee80211_netbsd.[ch]). Update drivers (an, atu, atw,
awi, ipw, iwi, rtw, wi) for the new net80211(9) API.
 1.3 16-Dec-2003  dyoung branches: 1.3.4;
Synchronize with FreeBSD:

* add constants to enums

* HAL update: stops panics, fixes ad hoc-mode beacons, some API
changes

* get and use mac/phy/rf front-end revision codes

* add a custom ath(4) ic_node_getrssi callback which does RSSI
averaging

* do not immediately scan, but re-associate after missing beacons.

* bug fix: don't if_init after detach.

* HAL diagnostics ioctl, SIOCGATHDIAG

* send DS parameters element in beacons

* const-ify some pointers

* consolidate rx-filter settings into ath_calcrxfilter

* abstract FreeBSD `ticks', NetBSD `hardclock_ticks' with ATH_TICKS()

* misc. other changes
 1.2 16-Oct-2003  dyoung ath(4) failed to detect when the number of DMA segments exceeded
the number of descriptors, because of a disparity between the
bus_dmamap_load_mbuf implementation in FreeBSD and NetBSD. Now I
cover up the difference using ath_dmamap_load_mbuf.

Thanks Enami Tsugutomo for diagnosing this.
 1.1 13-Oct-2003  dyoung A compatibility layer to smooth differences between NetBSD and
FreeBSD for ath(4).

XXX Nobody with FreeBSD has signed off on this, so it may change
XXX or go away entirely.
 1.3.4.3 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.3.4.2 03-Aug-2004  skrll Sync with HEAD
 1.3.4.1 16-Dec-2003  skrll file athcompat.h was added on branch ktrace-lwp on 2004-08-03 10:46:10 +0000
 1.17 28-Oct-2017  riastradh Add some #includes to make a few more header files compile.
 1.16 06-Sep-2015  dholland More on PR 41200: headers that declare ioctls should include sys/ioccom.h.
This covers (I think) all the MI headers outside of external/ (and dist/).
 1.15 03-Aug-2014  wiz branches: 1.15.4;
defintion -> definition
 1.14 04-Mar-2007  christos branches: 1.14.86; 1.14.102;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.13 07-Oct-2006  gdt branches: 1.13.4;
Use IEEE80211_RADIOTAP_DBM_ANTSIGNAL (and NOISE) instead of DB,
because the Atheros values are at least close.
(discussed on tech-net)
 1.12 27-Mar-2006  dyoung branches: 1.12.8; 1.12.10;
Fix my typo in ath(4)'s radiotap presence field (receive direction)
so that the signal and noise are in dB, not dBm. Since dBm signal
and noise come before the antenna field, the capture fields were
in the wrong order. That made for some astonishing (and wrong)
radiotap captures. dB signal and noise come after the antenna
field, so everything is in the right order, now.
 1.11 02-Mar-2006  dyoung branches: 1.11.2; 1.11.4; 1.11.6;
Miscellaneous ath(4) and net80211 updates and bug-fixes coming from
sam@ and various open source repositories:

ath(4):

Ignore "phantom" beacon misses: should stabilize connections
to access points (no more ceaseless link-UP/DOWN indications).
Also, re-synchronize beacon timer using the TSF in the
first beacon received after joining a BSS---this should
also help suppress spurious beacon misses. I am hopeful
that this will help ath(4) lossage reported by perry@ and
smb@.

Add new configuration through sysctl.

Use a shorter calibration interval until IQ calibration
finishes.

Report antenna noise through radiotap.

Rudiments of Radar Detection / Dynamic Frequency Selection.

Update to HAL version 0.9.16.13.

Update open sources for changes to the HAL API.

Add HALs for additional architectures: add big-endian ELF
HALs for sparc64 and for PowerPC. Also add a Alpha HAL.
These new HALs are untested under NetBSD.

ath(4) + net80211:

Make the multicast transmit rate configurable by ioctl.

Miscellaneous bug fixes.
 1.10 24-Nov-2005  dyoung branches: 1.10.4; 1.10.6;
Put the microsecond timestamp in the radiotap header for received
frames.
 1.9 26-Jul-2005  dyoung branches: 1.9.6;
Resolve conflicts.
 1.8 30-Jun-2005  dyoung branches: 1.8.2;
Fix $FreeBSD$ RCS IDs, which gave me a real shock when their revision
numbers moved backwards.
 1.7 22-Jun-2005  dyoung Resolve conflicts in importation of 18-May-2005 ath(4) / net80211(9)
from FreeBSD. Introduce compatibility shims (sys/dev/ic/ath_netbsd.[ch],
sys/net80211/ieee80211_netbsd.[ch]). Update drivers (an, atu, atw,
awi, ipw, iwi, rtw, wi) for the new net80211(9) API.
 1.6 28-Jul-2004  dyoung branches: 1.6.2;
Finalize import of the Atheros HAL 0.9.9.13, bringing ath(4)
up-to-date where the HAL API changed.
 1.5 30-Apr-2004  dyoung Sync with FreeBSD. Again, I lazily pull from the FreeBSD commit
log.
 1.4 03-Mar-2004  dyoung Oops, ath(4) tells dBm signal, not dB signal.
 1.3 16-Dec-2003  dyoung Synchronize with FreeBSD:

* add constants to enums

* HAL update: stops panics, fixes ad hoc-mode beacons, some API
changes

* get and use mac/phy/rf front-end revision codes

* add a custom ath(4) ic_node_getrssi callback which does RSSI
averaging

* do not immediately scan, but re-associate after missing beacons.

* bug fix: don't if_init after detach.

* HAL diagnostics ioctl, SIOCGATHDIAG

* send DS parameters element in beacons

* const-ify some pointers

* consolidate rx-filter settings into ath_calcrxfilter

* abstract FreeBSD `ticks', NetBSD `hardclock_ticks' with ATH_TICKS()

* misc. other changes
 1.2 15-Oct-2003  itojun add $NetBSD$
 1.1 07-Oct-2003  dyoung branches: 1.1.1;
Initial revision
 1.1.1.4 21-Jun-2005  dyoung Import FreeBSD's ath(4) of 2005-05-18
 1.1.1.3 29-Apr-2004  dyoung Import FreeBSD's ath of 28-apr-2004
 1.1.1.2 15-Dec-2003  dyoung Import FreeBSD's ath of 12-dec-2003
 1.1.1.1 07-Oct-2003  dyoung Initial import of ath(4) from FreeBSD.
 1.6.2.6 11-Dec-2005  christos Sync with head.
 1.6.2.5 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.6.2.4 21-Sep-2004  skrll Fix the sync with head I botched.
 1.6.2.3 18-Sep-2004  skrll Sync with HEAD.
 1.6.2.2 03-Aug-2004  skrll Sync with HEAD
 1.6.2.1 28-Jul-2004  skrll file athioctl.h was added on branch ktrace-lwp on 2004-08-03 10:46:10 +0000
 1.8.2.3 03-Sep-2007  yamt sync with head.
 1.8.2.2 30-Dec-2006  yamt sync with head.
 1.8.2.1 21-Jun-2006  yamt sync with head.
 1.9.6.1 29-Nov-2005  yamt sync with head.
 1.10.6.1 22-Apr-2006  simonb Sync with head.
 1.10.4.1 09-Sep-2006  rpaulo sync with head
 1.11.6.1 28-Mar-2006  tron Merge 2006-03-28 NetBSD-current into the "peter-altq" branch.
 1.11.4.1 19-Apr-2006  elad sync with head.
 1.11.2.1 01-Apr-2006  yamt sync with head.
 1.12.10.1 22-Oct-2006  yamt sync with head
 1.12.8.1 18-Nov-2006  ad Sync with head.
 1.13.4.1 12-Mar-2007  rmind Sync with HEAD.
 1.14.102.1 10-Aug-2014  tls Rebase.
 1.14.86.2 03-Dec-2017  jdolecek update from HEAD
 1.14.86.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.15.4.1 22-Sep-2015  skrll Sync with HEAD
 1.26 18-Mar-2022  riastradh net80211: Use getticks(), not hardclock_ticks.

Less extern in .c this way too.
 1.25 16-Jun-2021  riastradh if_attach and if_initialize cannot fail, don't test return value

These were originally made failable back in 2017 when if_initialize
allocated a softint in every interface for link state changes, so
that it could fail gracefully instead of panicking:

https://mail-index.NetBSD.org/source-changes/2017/10/23/msg089053.html

However, this spawned many seldom- or never-tested error branches,
which are risky to have around. And that softint in every interface
has since been replaced by a single global workqueue, because link
state changes require thread context but not low latency or high
throughput:

https://mail-index.NetBSD.org/source-changes/2020/02/06/msg113759.html

So there is no longer any reason for if_initialize to fail. (The
subroutine if_stats_init can't fail because percpu_alloc can't fail
either.)

There is a snag: the softint_establish in if_percpuq_create could
fail, potentially leading to bad consequences later on trying to use
the softint. This change doesn't introduce any new bugs because of
the snag -- if_percpuq_attach was already broken. However, the snag
can be better addressed without spawning error branches, either by
using a single softint or making softints less scarce.

(Separate commit will change the signatures of if_attach and
if_initialize to return void, scheduled to ride whatever is the next
convenient kernel bump.)

Patch and testing on amd64 and evbmips64-eb by maya@; commit message
soliloquy, and compile-testing on evbppc/i386/earmv7hf, by me.
 1.24 15-Nov-2020  mlelstv branches: 1.24.4;
Don't unlock without having taken the lock.
 1.23 29-Jan-2020  thorpej branches: 1.23.6;
Adopt <net/if_stats.h>.
 1.22 25-Jul-2019  msaitoh branches: 1.22.4;
Avoid undefined behavior. Found by KUBSan. Some of errors are still remaining.
 1.21 28-May-2019  msaitoh Use ETHER_LOCK()/ETHER_UNLOCK() for all ethernet drivers to protect ec_multi*.
 1.20 28-May-2019  msaitoh Modify to use athn_set_multi().
 1.19 24-May-2019  msaitoh KNF. No functional change.
 1.18 26-Jun-2018  msaitoh branches: 1.18.2;
Implement the BPF direction filter (BIOC[GS]DIRECTION). It provides backward
compatibility with BIOC[GS]SEESENT ioctl. The userland interface is the same
as FreeBSD.

This change also fixes a bug that the direction is misunderstand on some
environment by passing the direction to bpf_mtap*() instead of checking
m->m_pkthdr.rcvif.
 1.17 23-Oct-2017  msaitoh branches: 1.17.2;
- If if_initialize() failed in athn_attach(), free resources and return.
- Add missing pmf_event_deregister() in athn_detach().
 1.16 11-Apr-2017  jmcneill branches: 1.16.4;
Disable interrupts before returning from isr, and re-enable them when the
soft interrupt handler returns. Fixes an interrupt storm on Tegra K1.
ok christos@
 1.15 02-Feb-2017  nonaka wlan interfaces make interrupt routine running on softint context.

see http://mail-index.netbsd.org/tech-kern/2016/12/06/msg021281.html

tested device:
* ath at pci: AR5212, AR5424
* athn at pci: AR9287
* ipw at pci: 2100BG
* iwi at pci: 2915ABG
* iwm at pci: 3165, 7260, 8260
* iwn at pci: 4945, 6235
* ral at pci: RT2560
* rtwn at pci: RTL8192CE
 1.14 21-Jan-2017  skrll Pull across from nick-nhusb.

Some locking fixing, MPification and an attach fix
 1.13 26-May-2016  ozaki-r branches: 1.13.2; 1.13.4;
Use M_GETCTX

No functional change.
 1.12 17-Nov-2015  jakllsch Revert changes of athn.c r1.8.

- aprint_normal is correct for the attach message
- KNF adjustments in code we sync with upstream are a nuisance
- aprint_error{,_dev}() is inappropriate for use in runtime code
 1.11 22-Sep-2015  joerg Avoid left-shift of negative values.
 1.10 24-Jul-2014  riz branches: 1.10.4;
Fix last change (pa_calib_ticks should be sc_pa_calib_ticks).
 1.9 24-Jul-2014  christos sync with OpenBSD
 1.8 23-Feb-2014  christos branches: 1.8.2; 1.8.4;
use aprint.
 1.7 17-Oct-2013  christos - remove unused variables
- move variables inside ifdef sections
- ifdef notdef unused code
- use __USE for debugging variables
 1.6 24-Jun-2013  martin branches: 1.6.2;
Stopgap for PR kern/47957: when reinitializing the chip in if_timeout,
avoid pmf operations as we are called from softint context.

This is not a 100% solution, since we still may end up panicing if
initialization fails.

Instead of hacking around it on a per driver level, wouldn't it be better
to have a single global workqueue and dispatch the if_slowtimo() calls
via that?
 1.5 10-Apr-2013  christos branches: 1.5.4;
sort prototypes.
 1.4 06-Apr-2013  martin Fix return type and value of athn_resume (true for success, not 0 for no
error).
Avoid endless recursion in athn_init when the device had been suspended
via pmf_device_recursive_resume -> athn_resume -> athn_init.
Avoid touching the hardware when the device is not fully powered up yet.
 1.3 06-Apr-2013  martin Debounce the "wlan button pressed" event via pmf PMFE_RADIO_OFF so we
can run the pmf stuff in thread context.
 1.2 05-Apr-2013  martin Cleanup attach message slightly
 1.1 30-Mar-2013  christos This is the initial port of OpenBSD's athn(4) driver. It supports
quite a few Atheros 802.11n devices. See the athn(4) manpage for a
list.

This port has only been tested with a TP-LINK TL-WN722N USB adapter
which has an AR9271 chipset (VENDOR: 0x0cf3, PRODUCT: 0x9271). The
BSS, Monitor, and HostAP modes all seem to work on that adapter,
though the later has not been tested much.

The driver also supports PCI and CardBUS devices, but those interfaces
are completely untested and probably won't work at this point.

If someone can provide me with other adapters that should be
supported, particularly PCI or CardBUS adapters, or tell me where I
can get one cheaply, I would be happy to try to get the driver working
on those devices as well.
 1.5.4.4 03-Dec-2017  jdolecek update from HEAD
 1.5.4.3 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.5.4.2 23-Jun-2013  tls resync from head
 1.5.4.1 10-Apr-2013  tls file athn.c was added on branch tls-maxphys on 2013-06-23 06:20:17 +0000
 1.6.2.1 18-May-2014  rmind sync with head
 1.8.4.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.8.4.1 23-Feb-2014  yamt file athn.c was added on branch yamt-pagecache on 2014-05-22 11:40:22 +0000
 1.8.2.1 10-Aug-2014  tls Rebase.
 1.10.4.5 28-Aug-2017  skrll Sync with HEAD
 1.10.4.4 05-Feb-2017  skrll Sync with HEAD
 1.10.4.3 28-Dec-2016  skrll Various improvements

- override the method before calling athn_attach -> if_attach -> interface
announce
- locking fixes for htc/wmi
- some MPificaton
 1.10.4.2 29-May-2016  skrll Sync with HEAD
 1.10.4.1 27-Dec-2015  skrll Sync with HEAD (as of 26th Dec)
 1.13.4.1 21-Apr-2017  bouyer Sync with HEAD
 1.13.2.2 26-Apr-2017  pgoyette Sync with HEAD
 1.13.2.1 20-Mar-2017  pgoyette Sync with HEAD
 1.16.4.1 10-Dec-2017  snj Pull up following revision(s) (requested by msaitoh in ticket #427):
sys/arch/amiga/dev/if_bah_zbus.c: 1.17
sys/arch/arm/broadcom/bcm53xx_eth.c: 1.30
sys/arch/powerpc/booke/dev/pq3etsec.c: 1.32
sys/arch/usermode/dev/if_veth.c: 1.9
sys/dev/ic/an.c: 1.66
sys/dev/ic/athn.c: 1.17
sys/dev/ic/atw.c: 1.162
sys/dev/ic/bwi.c: 1.33
sys/dev/ic/dwc_gmac.c: 1.41-1.42
sys/dev/ic/malo.c: 1.10
sys/dev/ic/rt2560.c: 1.31
sys/dev/ic/rt2661.c: 1.36
sys/dev/ic/rt2860.c: 1.29
sys/dev/ic/rtw.c: 1.127
sys/dev/ic/rtwvar.h: 1.46
sys/dev/ic/smc90cx6.c: 1.71
sys/dev/ic/smc90cx6var.h: 1.12
sys/dev/ic/wi.c: 1.244
sys/dev/pci/if_ipw.c: 1.66
sys/dev/pci/if_iwi.c: 1.104
sys/dev/pci/if_iwm.c: 1.76
sys/dev/pci/if_iwn.c: 1.86
sys/dev/pci/if_rtwn.c: 1.13
sys/dev/pci/if_wm.c: 1.541
sys/dev/pci/if_wpi.c: 1.79
sys/dev/pci/ixgbe/ixgbe.c: 1.106
sys/dev/pci/ixgbe/ixv.c: 1.73 via patch
sys/dev/pcmcia/if_malo_pcmcia.c: 1.15
sys/dev/scsipi/if_se.c: 1.95
sys/dev/usb/if_upl.c: 1.60
sys/net/if.c: 1.396
sys/net/if.h: 1.241
sys/net/if_arc.h: 1.23
sys/net/if_arcsubr.c: 1.78
sys/net/if_bridge.c: 1.136-1.137
sys/net/if_etherip.c: 1.39
sys/net/if_faith.c: 1.56
sys/net/if_gif.c: 1.131
sys/net/if_loop.c: 1.96
sys/net/if_mpls.c: 1.30
sys/net/if_pppoe.c: 1.129
sys/net/if_srt.c: 1.27
sys/net/if_stf.c: 1.102
sys/net/if_tap.c: 1.100
sys/net/if_vlan.c: 1.105
sys/netinet/ip_carp.c: 1.91
sys/rump/net/lib/libshmif/if_shmem.c: 1.73-1.74
sys/rump/net/lib/libvirtif/if_virt.c: 1.55-1.56
if_initalize() and if_attach() failed when resource allocation failed
(e.g. allocating softint). Without this change, it panics. It's bad because
resource shortage really occured when a lot of pseudo interface is created.
To avoid this problem, don't panic and change return value of if_initialize()
and if_attach() to int. Caller fanction will be recover from error cleanly by
checking the return value.
Return if bah_attach_subr() failed.
If if_attach() failed in the attach function, return.
- If if_initialize() failed in the attach function, free resources and return.
- Add some missing frees in bridge_clone_destroy().
- KNF
If error occured in bcmeth_ccb_attach(), free resources and return.
If error occured in pq3etsec_attach(), free resources and return.
If error occured in the attach function, free resources and return.
- If if_initialize() failed in athn_attach(), free resources and return.
- Add missing pmf_event_deregister() in athn_detach().
- Free resources correctly on some errors in atw_attach().
- Use apint*() insread of printf() in the attach function.
If if_initialize() failed in the attach function, return.
- If if_initialize() failed in the attach function, free resources and return.
- Add missing dwc_gmac_free_dma_rings() and mutex_destroy() when attach
failed.
- If if_initialize() failed in the attach function, free resources and return.
- ifp is always not NULL in iwi_detach(). Check correctly with ifp->if_softc.
- If if_initialize() failed in the attach function, free resources and return.
- Fix error path in the attach function correctly.
If if_initialize() failed in the attach function, free resources and return.
If if_attach() failed in the attach function, free resources and return.
- If if_initialize() failed in the attach function, free resources and return.
- KNF
- If if_attach() failed in the attach function, free resources and return.
- KNF
Fix compile error.
Fix compile error.
We don't need '&mii', but just 'mii' for mii_detach().
Don't free sc_rthash twice
 1.17.2.1 28-Jul-2018  pgoyette Sync with HEAD
 1.18.2.4 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.18.2.3 08-Apr-2020  martin Merge changes from current as of 20200406
 1.18.2.2 10-Jun-2019  christos Sync with HEAD
 1.18.2.1 12-Jul-2018  phil State save. New kernel config for this brach only. TESTWIFI does
produce a kernel. It is not working. athn files not compiling yet
and commented out of the TESTWIFI kernel, which only has urtwn 802.11
driver enabled. ieee80211_alq.c and ieee80211_ddb.c not compiling yet.
 1.22.4.1 29-Feb-2020  ad Sync with head.
 1.23.6.1 14-Dec-2020  thorpej Sync w/ HEAD.
 1.24.4.1 17-Jun-2021  thorpej Sync w/ HEAD.
 1.2 25-Jul-2019  msaitoh Avoid undefined behavior. Found by KUBSan. Some of errors are still remaining.
 1.1 30-Mar-2013  christos branches: 1.1.4; 1.1.12; 1.1.40;
This is the initial port of OpenBSD's athn(4) driver. It supports
quite a few Atheros 802.11n devices. See the athn(4) manpage for a
list.

This port has only been tested with a TP-LINK TL-WN722N USB adapter
which has an AR9271 chipset (VENDOR: 0x0cf3, PRODUCT: 0x9271). The
BSS, Monitor, and HostAP modes all seem to work on that adapter,
though the later has not been tested much.

The driver also supports PCI and CardBUS devices, but those interfaces
are completely untested and probably won't work at this point.

If someone can provide me with other adapters that should be
supported, particularly PCI or CardBUS adapters, or tell me where I
can get one cheaply, I would be happy to try to get the driver working
on those devices as well.
 1.1.40.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.1.12.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.1.12.1 30-Mar-2013  yamt file athnreg.h was added on branch yamt-pagecache on 2014-05-22 11:40:22 +0000
 1.1.4.2 23-Jun-2013  tls resync from head
 1.1.4.1 30-Mar-2013  tls file athnreg.h was added on branch tls-maxphys on 2013-06-23 06:20:17 +0000
 1.8 05-Oct-2019  mrg remove __packed attribute from struct ieee80211_radiotap_header
and all the structures that include it.

this should not change anything while avoiding packed vs alignment
warnings from GCC 8, and potentially pessimised code generation
due to the packed marker (there are no misaligned members, just
that the per-device parts may end unaligned.)

all consumers of these members are done from the properly aligned
packet members directly, or, as a union with a 64 byte member,
also properly aligned. codegen didn't appear to change, except
for the definition of sizeof(struct driver_[rt]x_radiotap_header)
in debug info, which is not directly used anywhere.
 1.7 13-Sep-2019  msaitoh if_flags is neither int nor short. It's unsigned short.
 1.6 02-Feb-2017  nonaka branches: 1.6.14;
wlan interfaces make interrupt routine running on softint context.

see http://mail-index.netbsd.org/tech-kern/2016/12/06/msg021281.html

tested device:
* ath at pci: AR5212, AR5424
* athn at pci: AR9287
* ipw at pci: 2100BG
* iwi at pci: 2915ABG
* iwm at pci: 3165, 7260, 8260
* iwn at pci: 4945, 6235
* ral at pci: RT2560
* rtwn at pci: RTL8192CE
 1.5 27-Nov-2015  jmcneill branches: 1.5.2; 1.5.4;
Pull in changes from OpenBSD r1.34:
> Fix values of AR9003 Rx queue software indexes. Both indexes were zero,
> which is obviously not intended given how they are used in the ar9003 code.
> No currently working athn(4) devices are affected by this change.
 1.4 06-Apr-2013  martin branches: 1.4.4; 1.4.12; 1.4.16;
Fix return type and value of athn_resume (true for success, not 0 for no
error).
Avoid endless recursion in athn_init when the device had been suspended
via pmf_device_recursive_resume -> athn_resume -> athn_init.
Avoid touching the hardware when the device is not fully powered up yet.
 1.3 03-Apr-2013  christos instead of ifnet use ethercom.
 1.2 30-Mar-2013  christos Use only one set of EDCA variables
 1.1 30-Mar-2013  christos This is the initial port of OpenBSD's athn(4) driver. It supports
quite a few Atheros 802.11n devices. See the athn(4) manpage for a
list.

This port has only been tested with a TP-LINK TL-WN722N USB adapter
which has an AR9271 chipset (VENDOR: 0x0cf3, PRODUCT: 0x9271). The
BSS, Monitor, and HostAP modes all seem to work on that adapter,
though the later has not been tested much.

The driver also supports PCI and CardBUS devices, but those interfaces
are completely untested and probably won't work at this point.

If someone can provide me with other adapters that should be
supported, particularly PCI or CardBUS adapters, or tell me where I
can get one cheaply, I would be happy to try to get the driver working
on those devices as well.
 1.4.16.2 05-Feb-2017  skrll Sync with HEAD
 1.4.16.1 27-Dec-2015  skrll Sync with HEAD (as of 26th Dec)
 1.4.12.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.4.12.1 06-Apr-2013  yamt file athnvar.h was added on branch yamt-pagecache on 2014-05-22 11:40:22 +0000
 1.4.4.3 03-Dec-2017  jdolecek update from HEAD
 1.4.4.2 23-Jun-2013  tls resync from head
 1.4.4.1 06-Apr-2013  tls file athnvar.h was added on branch tls-maxphys on 2013-06-23 06:20:17 +0000
 1.5.4.1 21-Apr-2017  bouyer Sync with HEAD
 1.5.2.1 20-Mar-2017  pgoyette Sync with HEAD
 1.6.14.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.13 10-Nov-2019  chs in many device attach paths, allocate memory with M_WAITOK instead of M_NOWAIT
and remove code to handle failures that can no longer happen.
 1.12 08-Nov-2012  dyoung branches: 1.12.38;
Use NetBSD's own KASSERT() and KASSERTMSG() instead of #undef and re-#defining
KASSERT(), which is awkward at best.
 1.11 11-Dec-2008  alc branches: 1.11.14; 1.11.24;
Sync ath(4) with the new HAL, mostly based on <jmcneill>'s patches.

Everything should be fine again !
 1.10 04-Jan-2008  ad branches: 1.10.6; 1.10.10; 1.10.16; 1.10.18; 1.10.20; 1.10.26;
Start detangling lock.h from intr.h. This is likely to cause short term
breakage, but the mess of dependencies has been regularly breaking the
build recently anyhow.
 1.9 19-Oct-2007  ad branches: 1.9.2; 1.9.8;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.8 02-Apr-2006  gdamore branches: 1.8.18; 1.8.32; 1.8.34; 1.8.38;
Reorganize ath layout as requested by sam@ and suggested by dyoung@ in
http://mail-index.netbsd.org/tech-net/2006/03/15/0000.html.

The new layout almost precisely matches FreeBSD, and should make
future imports much easier.

At the same time, import the current 0.9.16.16 HAL from FreeBSD. According
to sam@, this is the proper version we should be using.
 1.7 02-Mar-2006  dyoung branches: 1.7.2; 1.7.4; 1.7.6;
Miscellaneous ath(4) and net80211 updates and bug-fixes coming from
sam@ and various open source repositories:

ath(4):

Ignore "phantom" beacon misses: should stabilize connections
to access points (no more ceaseless link-UP/DOWN indications).
Also, re-synchronize beacon timer using the TSF in the
first beacon received after joining a BSS---this should
also help suppress spurious beacon misses. I am hopeful
that this will help ath(4) lossage reported by perry@ and
smb@.

Add new configuration through sysctl.

Use a shorter calibration interval until IQ calibration
finishes.

Report antenna noise through radiotap.

Rudiments of Radar Detection / Dynamic Frequency Selection.

Update to HAL version 0.9.16.13.

Update open sources for changes to the HAL API.

Add HALs for additional architectures: add big-endian ELF
HALs for sparc64 and for PowerPC. Also add a Alpha HAL.
These new HALs are untested under NetBSD.

ath(4) + net80211:

Make the multicast transmit rate configurable by ioctl.

Miscellaneous bug fixes.
 1.6 05-Feb-2006  xtraeme Add missing $NetBSD$ tags and __KERNEL_RCSID().
 1.5 18-Nov-2005  skrll branches: 1.5.2; 1.5.4; 1.5.6;
Resolve conflicts.
 1.4 26-Jul-2005  dyoung branches: 1.4.6; 1.4.8;
Resolve conflicts.
 1.3 30-Jun-2005  dyoung branches: 1.3.2;
Fix $FreeBSD$ RCS IDs, which gave me a real shock when their revision
numbers moved backwards.
 1.2 22-Jun-2005  dyoung Resolve conflicts in importation of 18-May-2005 ath(4) / net80211(9)
from FreeBSD. Introduce compatibility shims (sys/dev/ic/ath_netbsd.[ch],
sys/net80211/ieee80211_netbsd.[ch]). Update drivers (an, atu, atw,
awi, ipw, iwi, rtw, wi) for the new net80211(9) API.
 1.1 21-Jun-2005  dyoung branches: 1.1.1;
Initial revision
 1.1.1.3 18-Nov-2005  skrll Import FreeBSD's ath(4) of 1-nov-2005
 1.1.1.2 26-Jul-2005  dyoung Import FreeBSD's ath(4) of 2005-07-11
 1.1.1.1 21-Jun-2005  dyoung Import FreeBSD's ath(4) of 2005-05-18
 1.3.2.3 21-Jan-2008  yamt sync with head
 1.3.2.2 27-Oct-2007  yamt sync with head.
 1.3.2.1 21-Jun-2006  yamt sync with head.
 1.4.8.1 22-Nov-2005  yamt sync with head.
 1.4.6.3 11-Dec-2005  christos Sync with head.
 1.4.6.2 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.4.6.1 26-Jul-2005  skrll file athrate-amrr.c was added on branch ktrace-lwp on 2005-11-10 14:04:13 +0000
 1.5.6.1 22-Apr-2006  simonb Sync with head.
 1.5.4.1 09-Sep-2006  rpaulo sync with head
 1.5.2.1 18-Feb-2006  yamt sync with head.
 1.7.6.1 24-May-2006  tron Merge 2006-05-24 NetBSD-current into the "peter-altq" branch.
 1.7.4.1 19-Apr-2006  elad sync with head.
 1.7.2.1 11-Apr-2006  yamt sync with head
 1.8.38.1 25-Oct-2007  bouyer Sync with HEAD.
 1.8.34.2 09-Jan-2008  matt sync with HEAD
 1.8.34.1 06-Nov-2007  matt sync with HEAD
 1.8.32.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.8.18.1 23-Oct-2007  ad Sync with head.
 1.9.8.1 08-Jan-2008  bouyer Sync with HEAD
 1.9.2.1 18-Feb-2008  mjf Sync with HEAD.
 1.10.26.1 21-Apr-2010  matt sync to netbsd-5
 1.10.20.1 07-Aug-2009  snj Apply patch (requested by jmcneill in ticket 775):
Update to the open source atheros HAL.
 1.10.18.1 19-Jan-2009  skrll Sync with HEAD.
 1.10.16.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.10.10.1 04-May-2009  yamt sync with head.
 1.10.6.1 17-Jan-2009  mjf Sync with HEAD.
 1.11.24.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.11.14.1 16-Jan-2013  yamt sync with (a bit old) head
 1.12.38.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.2 05-Feb-2006  xtraeme Add missing $NetBSD$ tags and __KERNEL_RCSID().
 1.1 21-Jun-2005  dyoung branches: 1.1.1;
Initial revision
 1.1.1.1 21-Jun-2005  dyoung branches: 1.1.1.1.2; 1.1.1.1.8; 1.1.1.1.12; 1.1.1.1.14; 1.1.1.1.16;
Import FreeBSD's ath(4) of 2005-05-18
 1.1.1.1.16.1 22-Apr-2006  simonb Sync with head.
 1.1.1.1.14.1 09-Sep-2006  rpaulo sync with head
 1.1.1.1.12.1 18-Feb-2006  yamt sync with head.
 1.1.1.1.8.2 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.1.1.1.8.1 21-Jun-2005  skrll file athrate-amrr.h was added on branch ktrace-lwp on 2005-11-10 14:04:13 +0000
 1.1.1.1.2.1 21-Jun-2006  yamt sync with head.
 1.16 10-Nov-2019  chs in many device attach paths, allocate memory with M_WAITOK instead of M_NOWAIT
and remove code to handle failures that can no longer happen.
 1.15 08-Nov-2012  dyoung branches: 1.15.38;
Use NetBSD's own KASSERT() and KASSERTMSG() instead of #undef and re-#defining
KASSERT(), which is awkward at best.
 1.14 27-Mar-2009  dyoung branches: 1.14.12; 1.14.22;
Make this build on -current.
 1.13 11-Dec-2008  alc branches: 1.13.2;
Sync ath(4) with the new HAL, mostly based on <jmcneill>'s patches.

Everything should be fine again !
 1.12 04-Jan-2008  ad branches: 1.12.6; 1.12.10; 1.12.16; 1.12.18; 1.12.20; 1.12.26;
Start detangling lock.h from intr.h. This is likely to cause short term
breakage, but the mess of dependencies has been regularly breaking the
build recently anyhow.
 1.11 26-Nov-2007  dyoung branches: 1.11.6;
Make this compile. Use callout_init() instead of ATH_CALLOUT_INIT(),
since callout_init() on FreeBSD and NetBSD are the same, now.
 1.10 19-Oct-2007  ad branches: 1.10.2;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.9 02-Apr-2006  gdamore branches: 1.9.18; 1.9.32; 1.9.34; 1.9.38;
Reorganize ath layout as requested by sam@ and suggested by dyoung@ in
http://mail-index.netbsd.org/tech-net/2006/03/15/0000.html.

The new layout almost precisely matches FreeBSD, and should make
future imports much easier.

At the same time, import the current 0.9.16.16 HAL from FreeBSD. According
to sam@, this is the proper version we should be using.
 1.8 02-Mar-2006  dyoung branches: 1.8.2; 1.8.4; 1.8.6;
Miscellaneous ath(4) and net80211 updates and bug-fixes coming from
sam@ and various open source repositories:

ath(4):

Ignore "phantom" beacon misses: should stabilize connections
to access points (no more ceaseless link-UP/DOWN indications).
Also, re-synchronize beacon timer using the TSF in the
first beacon received after joining a BSS---this should
also help suppress spurious beacon misses. I am hopeful
that this will help ath(4) lossage reported by perry@ and
smb@.

Add new configuration through sysctl.

Use a shorter calibration interval until IQ calibration
finishes.

Report antenna noise through radiotap.

Rudiments of Radar Detection / Dynamic Frequency Selection.

Update to HAL version 0.9.16.13.

Update open sources for changes to the HAL API.

Add HALs for additional architectures: add big-endian ELF
HALs for sparc64 and for PowerPC. Also add a Alpha HAL.
These new HALs are untested under NetBSD.

ath(4) + net80211:

Make the multicast transmit rate configurable by ioctl.

Miscellaneous bug fixes.
 1.7 05-Feb-2006  xtraeme Add missing $NetBSD$ tags and __KERNEL_RCSID().
 1.6 18-Nov-2005  skrll branches: 1.6.2; 1.6.4; 1.6.6;
Resolve conflicts.
 1.5 26-Jul-2005  dyoung branches: 1.5.6; 1.5.8;
Resolve conflicts.
 1.4 30-Jun-2005  dyoung branches: 1.4.2;
Fix $FreeBSD$ RCS IDs, which gave me a real shock when their revision
numbers moved backwards.
 1.3 22-Jun-2005  martin Remove unused <atomic.h> include; add <sys/device.h> includes where
needed.
 1.2 22-Jun-2005  dyoung Resolve conflicts in importation of 18-May-2005 ath(4) / net80211(9)
from FreeBSD. Introduce compatibility shims (sys/dev/ic/ath_netbsd.[ch],
sys/net80211/ieee80211_netbsd.[ch]). Update drivers (an, atu, atw,
awi, ipw, iwi, rtw, wi) for the new net80211(9) API.
 1.1 21-Jun-2005  dyoung branches: 1.1.1;
Initial revision
 1.1.1.3 18-Nov-2005  skrll Import FreeBSD's ath(4) of 1-nov-2005
 1.1.1.2 26-Jul-2005  dyoung Import FreeBSD's ath(4) of 2005-07-11
 1.1.1.1 21-Jun-2005  dyoung Import FreeBSD's ath(4) of 2005-05-18
 1.4.2.4 21-Jan-2008  yamt sync with head
 1.4.2.3 07-Dec-2007  yamt sync with head
 1.4.2.2 27-Oct-2007  yamt sync with head.
 1.4.2.1 21-Jun-2006  yamt sync with head.
 1.5.8.1 22-Nov-2005  yamt sync with head.
 1.5.6.3 11-Dec-2005  christos Sync with head.
 1.5.6.2 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.5.6.1 26-Jul-2005  skrll file athrate-onoe.c was added on branch ktrace-lwp on 2005-11-10 14:04:14 +0000
 1.6.6.1 22-Apr-2006  simonb Sync with head.
 1.6.4.1 09-Sep-2006  rpaulo sync with head
 1.6.2.1 18-Feb-2006  yamt sync with head.
 1.8.6.1 24-May-2006  tron Merge 2006-05-24 NetBSD-current into the "peter-altq" branch.
 1.8.4.1 19-Apr-2006  elad sync with head.
 1.8.2.1 11-Apr-2006  yamt sync with head
 1.9.38.1 25-Oct-2007  bouyer Sync with HEAD.
 1.9.34.2 09-Jan-2008  matt sync with HEAD
 1.9.34.1 06-Nov-2007  matt sync with HEAD
 1.9.32.2 27-Nov-2007  joerg Sync with HEAD. amd64 Xen support needs testing.
 1.9.32.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.9.18.1 23-Oct-2007  ad Sync with head.
 1.10.2.2 18-Feb-2008  mjf Sync with HEAD.
 1.10.2.1 08-Dec-2007  mjf Sync with HEAD.
 1.11.6.1 08-Jan-2008  bouyer Sync with HEAD
 1.12.26.1 21-Apr-2010  matt sync to netbsd-5
 1.12.20.1 07-Aug-2009  snj Apply patch (requested by jmcneill in ticket 775):
Update to the open source atheros HAL.
 1.12.18.2 28-Apr-2009  skrll Sync with HEAD.
 1.12.18.1 19-Jan-2009  skrll Sync with HEAD.
 1.12.16.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.12.10.1 04-May-2009  yamt sync with head.
 1.12.6.1 17-Jan-2009  mjf Sync with HEAD.
 1.13.2.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.14.22.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.14.12.1 16-Jan-2013  yamt sync with (a bit old) head
 1.15.38.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.2 05-Feb-2006  xtraeme Add missing $NetBSD$ tags and __KERNEL_RCSID().
 1.1 21-Jun-2005  dyoung branches: 1.1.1;
Initial revision
 1.1.1.1 21-Jun-2005  dyoung branches: 1.1.1.1.2; 1.1.1.1.8; 1.1.1.1.12; 1.1.1.1.14; 1.1.1.1.16;
Import FreeBSD's ath(4) of 2005-05-18
 1.1.1.1.16.1 22-Apr-2006  simonb Sync with head.
 1.1.1.1.14.1 09-Sep-2006  rpaulo sync with head
 1.1.1.1.12.1 18-Feb-2006  yamt sync with head.
 1.1.1.1.8.2 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.1.1.1.8.1 21-Jun-2005  skrll file athrate-onoe.h was added on branch ktrace-lwp on 2005-11-10 14:04:14 +0000
 1.1.1.1.2.1 21-Jun-2006  yamt sync with head.
 1.21 09-Aug-2021  andvar s/alway /always/
 1.20 10-Nov-2019  chs in many device attach paths, allocate memory with M_WAITOK instead of M_NOWAIT
and remove code to handle failures that can no longer happen.
 1.19 08-Nov-2012  dyoung branches: 1.19.38;
Use NetBSD's own KASSERT() and KASSERTMSG() instead of #undef and re-#defining
KASSERT(), which is awkward at best.
 1.18 20-Feb-2011  jmcneill branches: 1.18.4; 1.18.14;
support building as a module
 1.17 11-Dec-2008  alc branches: 1.17.6; 1.17.8; 1.17.10;
Sync ath(4) with the new HAL, mostly based on <jmcneill>'s patches.

Everything should be fine again !
 1.16 09-Jul-2008  joerg branches: 1.16.2; 1.16.4; 1.16.10;
- device/softc split for ath(4)
 1.15 08-Apr-2008  cegger branches: 1.15.4; 1.15.6; 1.15.8; 1.15.10;
use aprint_*_dev and device_xname
 1.14 04-Jan-2008  ad branches: 1.14.6;
Start detangling lock.h from intr.h. This is likely to cause short term
breakage, but the mess of dependencies has been regularly breaking the
build recently anyhow.
 1.13 19-Oct-2007  ad branches: 1.13.2; 1.13.8;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.12 16-Nov-2006  christos branches: 1.12.8; 1.12.22; 1.12.24; 1.12.28;
__unused removal on arguments; approved by core.
 1.11 12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.10 14-Apr-2006  christos branches: 1.10.8; 1.10.10;
Coverty CID 1317: Avoid negative index.
 1.9 02-Apr-2006  gdamore Reorganize ath layout as requested by sam@ and suggested by dyoung@ in
http://mail-index.netbsd.org/tech-net/2006/03/15/0000.html.

The new layout almost precisely matches FreeBSD, and should make
future imports much easier.

At the same time, import the current 0.9.16.16 HAL from FreeBSD. According
to sam@, this is the proper version we should be using.
 1.8 02-Mar-2006  dyoung branches: 1.8.2; 1.8.4; 1.8.6;
Miscellaneous ath(4) and net80211 updates and bug-fixes coming from
sam@ and various open source repositories:

ath(4):

Ignore "phantom" beacon misses: should stabilize connections
to access points (no more ceaseless link-UP/DOWN indications).
Also, re-synchronize beacon timer using the TSF in the
first beacon received after joining a BSS---this should
also help suppress spurious beacon misses. I am hopeful
that this will help ath(4) lossage reported by perry@ and
smb@.

Add new configuration through sysctl.

Use a shorter calibration interval until IQ calibration
finishes.

Report antenna noise through radiotap.

Rudiments of Radar Detection / Dynamic Frequency Selection.

Update to HAL version 0.9.16.13.

Update open sources for changes to the HAL API.

Add HALs for additional architectures: add big-endian ELF
HALs for sparc64 and for PowerPC. Also add a Alpha HAL.
These new HALs are untested under NetBSD.

ath(4) + net80211:

Make the multicast transmit rate configurable by ioctl.

Miscellaneous bug fixes.
 1.7 05-Feb-2006  xtraeme Add missing $NetBSD$ tags and __KERNEL_RCSID().
 1.6 24-Dec-2005  perry branches: 1.6.2; 1.6.4; 1.6.6;
Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.5 18-Nov-2005  skrll Resolve conflicts.
 1.4 25-Oct-2005  martin branches: 1.4.2; 1.4.4;
Add missing <sys/device.h> include.
XXX - this is handled inconsistently accross the ath* files, maybe we
should move it to ath_netbsd.h and be done?
 1.3 28-Jul-2005  dyoung branches: 1.3.2;
Fix variable shadowing, sysctl attachment, ident(1) strings,
#includes so that the SampleRate rate-control algorithm will build
on NetBSD.
 1.2 22-Jun-2005  dyoung branches: 1.2.2;
Resolve conflicts in importation of 18-May-2005 ath(4) / net80211(9)
from FreeBSD. Introduce compatibility shims (sys/dev/ic/ath_netbsd.[ch],
sys/net80211/ieee80211_netbsd.[ch]). Update drivers (an, atu, atw,
awi, ipw, iwi, rtw, wi) for the new net80211(9) API.
 1.1 21-Jun-2005  dyoung branches: 1.1.1;
Initial revision
 1.1.1.2 18-Nov-2005  skrll Import FreeBSD's ath(4) of 1-nov-2005
 1.1.1.1 21-Jun-2005  dyoung Import FreeBSD's ath(4) of 2005-05-18
 1.2.2.4 21-Jan-2008  yamt sync with head
 1.2.2.3 27-Oct-2007  yamt sync with head.
 1.2.2.2 30-Dec-2006  yamt sync with head.
 1.2.2.1 21-Jun-2006  yamt sync with head.
 1.3.2.1 26-Oct-2005  yamt sync with head
 1.4.4.1 22-Nov-2005  yamt sync with head.
 1.4.2.3 11-Dec-2005  christos Sync with head.
 1.4.2.2 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.4.2.1 25-Oct-2005  skrll file athrate-sample.c was added on branch ktrace-lwp on 2005-11-10 14:04:14 +0000
 1.6.6.1 22-Apr-2006  simonb Sync with head.
 1.6.4.1 09-Sep-2006  rpaulo sync with head
 1.6.2.1 18-Feb-2006  yamt sync with head.
 1.8.6.1 24-May-2006  tron Merge 2006-05-24 NetBSD-current into the "peter-altq" branch.
 1.8.4.1 19-Apr-2006  elad sync with head.
 1.8.2.2 24-May-2006  yamt sync with head.
 1.8.2.1 11-Apr-2006  yamt sync with head
 1.10.10.2 10-Dec-2006  yamt sync with head.
 1.10.10.1 22-Oct-2006  yamt sync with head
 1.10.8.1 18-Nov-2006  ad Sync with head.
 1.12.28.1 25-Oct-2007  bouyer Sync with HEAD.
 1.12.24.2 09-Jan-2008  matt sync with HEAD
 1.12.24.1 06-Nov-2007  matt sync with HEAD
 1.12.22.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.12.8.1 23-Oct-2007  ad Sync with head.
 1.13.8.1 08-Jan-2008  bouyer Sync with HEAD
 1.13.2.1 18-Feb-2008  mjf Sync with HEAD.
 1.14.6.3 17-Jan-2009  mjf Sync with HEAD.
 1.14.6.2 28-Sep-2008  mjf Sync with HEAD.
 1.14.6.1 02-Jun-2008  mjf Sync with HEAD.
 1.15.10.2 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.15.10.1 19-Oct-2008  haad Sync with HEAD.
 1.15.8.1 18-Jul-2008  simonb Sync with head.
 1.15.6.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.15.4.1 04-May-2009  yamt sync with head.
 1.16.10.1 21-Apr-2010  matt sync to netbsd-5
 1.16.4.1 07-Aug-2009  snj Apply patch (requested by jmcneill in ticket 775):
Update to the open source atheros HAL.
 1.16.2.1 19-Jan-2009  skrll Sync with HEAD.
 1.17.10.1 05-Mar-2011  bouyer Sync with HEAD
 1.17.8.1 06-Jun-2011  jruoho Sync with HEAD.
 1.17.6.1 05-Mar-2011  rmind sync with head
 1.18.14.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.18.4.1 16-Jan-2013  yamt sync with (a bit old) head
 1.19.38.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.4 08-Nov-2012  dyoung Use NetBSD's own KASSERT() and KASSERTMSG() instead of #undef and re-#defining
KASSERT(), which is awkward at best.
 1.3 02-Mar-2006  dyoung branches: 1.3.104; 1.3.114;
Miscellaneous ath(4) and net80211 updates and bug-fixes coming from
sam@ and various open source repositories:

ath(4):

Ignore "phantom" beacon misses: should stabilize connections
to access points (no more ceaseless link-UP/DOWN indications).
Also, re-synchronize beacon timer using the TSF in the
first beacon received after joining a BSS---this should
also help suppress spurious beacon misses. I am hopeful
that this will help ath(4) lossage reported by perry@ and
smb@.

Add new configuration through sysctl.

Use a shorter calibration interval until IQ calibration
finishes.

Report antenna noise through radiotap.

Rudiments of Radar Detection / Dynamic Frequency Selection.

Update to HAL version 0.9.16.13.

Update open sources for changes to the HAL API.

Add HALs for additional architectures: add big-endian ELF
HALs for sparc64 and for PowerPC. Also add a Alpha HAL.
These new HALs are untested under NetBSD.

ath(4) + net80211:

Make the multicast transmit rate configurable by ioctl.

Miscellaneous bug fixes.
 1.2 05-Feb-2006  xtraeme Add missing $NetBSD$ tags and __KERNEL_RCSID().
 1.1 21-Jun-2005  dyoung branches: 1.1.1;
Initial revision
 1.1.1.1 21-Jun-2005  dyoung branches: 1.1.1.1.2; 1.1.1.1.8; 1.1.1.1.12; 1.1.1.1.14; 1.1.1.1.16;
Import FreeBSD's ath(4) of 2005-05-18
 1.1.1.1.16.1 22-Apr-2006  simonb Sync with head.
 1.1.1.1.14.1 09-Sep-2006  rpaulo sync with head
 1.1.1.1.12.1 18-Feb-2006  yamt sync with head.
 1.1.1.1.8.2 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.1.1.1.8.1 21-Jun-2005  skrll file athrate-sample.h was added on branch ktrace-lwp on 2005-11-10 14:04:14 +0000
 1.1.1.1.2.1 21-Jun-2006  yamt sync with head.
 1.3.114.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.3.104.1 16-Jan-2013  yamt sync with (a bit old) head
 1.3 18-Oct-2014  snj src is too big these days to tolerate superfluous apostrophes. It's
"its", people!
 1.2 05-Feb-2006  xtraeme branches: 1.2.114;
Add missing $NetBSD$ tags and __KERNEL_RCSID().
 1.1 21-Jun-2005  dyoung branches: 1.1.1;
Initial revision
 1.1.1.1 21-Jun-2005  dyoung branches: 1.1.1.1.2; 1.1.1.1.8; 1.1.1.1.12; 1.1.1.1.14; 1.1.1.1.16;
Import FreeBSD's ath(4) of 2005-05-18
 1.1.1.1.16.1 22-Apr-2006  simonb Sync with head.
 1.1.1.1.14.1 09-Sep-2006  rpaulo sync with head
 1.1.1.1.12.1 18-Feb-2006  yamt sync with head.
 1.1.1.1.8.2 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.1.1.1.8.1 21-Jun-2005  skrll file athrate.h was added on branch ktrace-lwp on 2005-11-10 14:04:14 +0000
 1.1.1.1.2.1 21-Jun-2006  yamt sync with head.
 1.2.114.1 03-Dec-2017  jdolecek update from HEAD
 1.36 27-Jan-2013  jmcneill don't transmit while in a key change is in progress
 1.35 07-Oct-2011  dyoung branches: 1.35.2; 1.35.12;
Get rid of the "I don't know what I was thinking / somebody should have
stopped me / does anybody read source-changes?" ATH_LOCK()/ATH_UNLOCK()
and bracket with splnet()/splx() instead. This is still not *good*,
since ifnet ioctls are not (yet) synchronized, but could be no worse
than what we have, now. Survives light testing with my (forthcoming)
ifnet ioctl synchronization patch.
 1.34 07-Mar-2011  cegger Get improvements from FreeBSD-current (January 2011).
Successfully tested with WEP, WPA and WPA2 on AR9285.
Reviewed by jmcneill@
 1.33 19-Mar-2010  dyoung branches: 1.33.2;
Don't pick up the network-interface, ethernet, and 802.11-related
definitions by chance (or by the bus-specific front-end #including them!).
#include them here, instead.
 1.32 14-Mar-2010  dyoung branches: 1.32.2;
Use device_suspensor_t instead of struct device_suspensor.
 1.31 24-Feb-2010  dyoung A pointer typedef entails trading too much flexibility to declare const
and non-const types, and the kernel uses both const and non-const
PMF qualifiers and device suspensors, so change the pmf_qual_t and
device_suspensor_t typedefs from "pointers to const" to non-pointer,
non-const types.
 1.30 17-Jan-2010  pooka branches: 1.30.2;
Forward declare struct bpf_if and use that as the type for bpf_if
instead of "void *". Buys us oo times the type-safety for 0 times
the price.
(no functional change)
 1.29 16-Sep-2009  dyoung In pmf(9), improve the implementation of device self-suspension
and make suspension by self, by drvctl(8), and by ACPI system sleep
play nice together. Start solidifying some temporary API changes.

1. Extract a new header file, <sys/device_if.h>, from <sys/device.h> and
#include it from <sys/pmf.h> instead of <sys/device.h> to break the
circular dependency between <sys/device.h> and <sys/pmf.h>.

2. Introduce pmf_qual_t, an aggregate of qualifications on a PMF
suspend/resume call. Start to replace instances of PMF_FN_PROTO,
PMF_FN_ARGS, et cetera, with a pmf_qual_t.

3. Introduce the notion of a "suspensor," an entity that holds a
device in suspension. More than one suspensor may hold a device
at once. A device stays suspended as long as at least one
suspensor holds it. A device resumes when the last suspensor
releases it.

Currently, the kernel defines three suspensors,

3a the system-suspensor: for system suspension, initiated
by 'sysctl -w machdep.sleep_state=3', by lid closure, by
power-button press, et cetera,

3b the drvctl-suspensor: for device suspension by /dev/drvctl
ioctl, e.g., drvctl -S sip0.

3c the system self-suspensor: for device drivers that suspend
themselves and their children. Several drivers for network
interfaces put the network device to sleep while it is not
administratively up, that is, after the kernel calls if_stop(,
1). The self-suspensor should not be used directly. See
the description of suspensor delegates, below.

A suspensor can have one or more "delegates". A suspensor can
release devices that its delegates hold suspended. Right now,
only the system self-suspensor has delegates. For each device
that a self-suspending driver attaches, it creates the device's
self-suspensor, a delegate of the system self-suspensor.

Suspensors stop a system-wide suspend/resume cycle from waking
devices that the operator put to sleep with drvctl before the cycle.
They also help self-suspension to work more simply, safely, and in
accord with expectations.

4. Add the notion of device activation level, devact_level_t,
and a routine for checking the current activation level,
device_activation(). Current activation levels are DEVACT_LEVEL_BUS,
DEVACT_LEVEL_DRIVER, and DEVACT_LEVEL_CLASS, which respectively
indicate that the device's bus is active, that the bus and device are
active, and that the bus, device, and the functions of the device's
class (network, audio) are active.

Suspend/resume calls can be qualified with a devact_level_t.
The power-management framework treats a devact_level_t that
qualifies a device suspension as the device's current activation
level; it only runs hooks to reduce the activation level from
the presumed current level to the fully suspended state. The
framework treats a devact_level_t qualifying device resumption
as the target activation level; it only runs hooks to raise the
activation level to the target.

5. Use pmf_qual_t, devact_level_t, and self-suspensors in several
drivers.

6. Temporarily add an unused power-management workqueue that I will
remove or replace, soon.
 1.28 02-Aug-2009  jmcneill - fix TKIP, changes adapted from FreeBSD
- reduce diffs between FreeBSD and NetBSD athvar.h
 1.27 12-May-2009  cegger struct device * -> device_t, no functional changes intended.
 1.26 11-Dec-2008  alc branches: 1.26.2;
Sync ath(4) with the new HAL, mostly based on <jmcneill>'s patches.

Everything should be fine again !
 1.25 09-Jul-2008  joerg branches: 1.25.2; 1.25.4; 1.25.10;
- device/softc split for ath(4)
 1.24 12-Mar-2008  dyoung branches: 1.24.4; 1.24.6; 1.24.8; 1.24.10;
Use device_t and its accessors throughout. Use aprint_*_dev().

Improve PMF-ability.

Add a 'flags' argument to suspend/resume handlers and
callers such as pmf_system_suspend().

Define a flag, PMF_F_SELF, which indicates to PMF that a
device is suspending/resuming itself. Add helper routines,
pmf_device_suspend_self(dev) and pmf_device_resume_self(dev),
that call pmf_device_suspend(dev, PMF_F_SELF) and
pmf_device_resume(dev, PMF_F_SELF), respectively. Use
PMF_F_SELF to suspend/resume self in ath(4), audio(4),
rtw(4), and sip(4).

In ath(4) and in rtw(4), replace the icky sc_enable/sc_disable
callbacks, provided by the bus front-end, with
self-suspension/resumption. Also, clean up the bus
front-ends. Make sure that the interrupt handler is
disestablished during suspension. Get rid of driver-private
flags (e.g., RTW_F_ENABLED, ath_softc->sc_invalid); use
device_is_active()/device_has_power() calls, instead.

In the network-class suspend handler, call if_stop(, 0)
instead of if_stop(, 1), because the latter is superfluous
(bus- and driver-suspension hooks will 'disable' the NIC),
and it may cause recursion.

In the network-class resume handler, prevent infinite
recursion through if_init() by getting out early if we are
self-suspending (PMF_F_SELF).

rtw(4) improvements:

Destroy rtw(4) callouts when we detach it. Make rtw at
pci detachable. Print some more information with the "rx
frame too long" warning.

Remove activate() methods:

Get rid of rtw_activate() and ath_activate(). The device
activate() methods are not good for much these days.

Make ath at cardbus resume with crypto functions intact:

Introduce a boolean device property, "pmf-powerdown". If
pmf-powerdown is present and false, it indicates that a
bus back-end should not remove power from a device.

Honor this property in cardbus_child_suspend().

Set this property to 'false' in ath_attach(), since removing
power from an ath at cardbus seems to lobotomize the WPA
crypto engine. XXX Should the pmf-powerdown property
propagate toward the root of the device tree?

Miscellaneous ath(4) changes:

Warn if ath(4) tries to write crypto keys to suspended
hardware.

Reduce differences between FreeBSD and NetBSD in ath(4)
multicast filter setup.

Make ath_printrxbuf() print an rx descriptor's status &
key index, to help debug crypto errors.

Shorten a staircase in ath_ioctl(). Don't check for
ieee80211_ioctl() return code ERESTART, it never happens.
 1.23 22-Dec-2007  dyoung branches: 1.23.2; 1.23.6;
Remove the remnants of the powerhooks.
 1.22 09-Dec-2007  jmcneill branches: 1.22.2;
Merge jmcneill-pm branch.
 1.21 17-Jul-2007  dyoung branches: 1.21.6; 1.21.8; 1.21.16; 1.21.18;
Suppress spurious timeouts and avoid wedging in OACTIVE state:

1 Set or clear OACTIVE as transmit buffers are depleted or
replenished, respectively. Do not use 802.11 acknowledgements
as a criteria for clearing OACTIVE.

2 Let each transmit queue count down to timeout independently,
and get rid of the shared countdown (sc_tx_timer). When
we add a packet to a transmit queue, restart the queue's
countdown. Stop a transmit queue's countdown when the
queue empties.
 1.20 04-Mar-2007  christos branches: 1.20.2;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.19 14-Jul-2006  seanb branches: 1.19.10;
Consistently establish / disestablish shutdown hook
in the bus layer and remove from common ath_attach().
Having it in both layers (on some bus architectures)
was causing a double call to ath_stop() on shutdown
which in turn was tickling the bus lockup described
therin on slower machines.
 1.18 05-Jun-2006  gdamore Import new HAL 0.9.17.2. Approved by sam@

New HAL includes some driver changes to register accesses.
Adds support for WLAN devices on AR5312 family devices.
Adds support 32-bit SPARC ath devices (untested).
ath enabled in SPARC64 GENERIC builds.
This HAL is tested and known to work for i386 PCI devices, SPARC64 PCI devices,
and AR5312 WiSoC devices. MIPS PCI devices appear to be busted (possibly only
on Alchemy hardware, unconfirmed), and cardbus support is untested due to
lack of test hardware.

Please report any new problems with this import to garrett@.
 1.17 26-May-2006  blymn Clean up bogus whitespace
 1.16 02-Apr-2006  gdamore branches: 1.16.2;
Reorganize ath layout as requested by sam@ and suggested by dyoung@ in
http://mail-index.netbsd.org/tech-net/2006/03/15/0000.html.

The new layout almost precisely matches FreeBSD, and should make
future imports much easier.

At the same time, import the current 0.9.16.16 HAL from FreeBSD. According
to sam@, this is the proper version we should be using.
 1.15 02-Mar-2006  dyoung branches: 1.15.2; 1.15.4; 1.15.6;
Miscellaneous ath(4) and net80211 updates and bug-fixes coming from
sam@ and various open source repositories:

ath(4):

Ignore "phantom" beacon misses: should stabilize connections
to access points (no more ceaseless link-UP/DOWN indications).
Also, re-synchronize beacon timer using the TSF in the
first beacon received after joining a BSS---this should
also help suppress spurious beacon misses. I am hopeful
that this will help ath(4) lossage reported by perry@ and
smb@.

Add new configuration through sysctl.

Use a shorter calibration interval until IQ calibration
finishes.

Report antenna noise through radiotap.

Rudiments of Radar Detection / Dynamic Frequency Selection.

Update to HAL version 0.9.16.13.

Update open sources for changes to the HAL API.

Add HALs for additional architectures: add big-endian ELF
HALs for sparc64 and for PowerPC. Also add a Alpha HAL.
These new HALs are untested under NetBSD.

ath(4) + net80211:

Make the multicast transmit rate configurable by ioctl.

Miscellaneous bug fixes.
 1.14 18-Nov-2005  skrll branches: 1.14.4; 1.14.6;
Resolve conflicts.
 1.13 26-Jul-2005  dyoung branches: 1.13.6;
Resolve conflicts.
 1.12 30-Jun-2005  dyoung branches: 1.12.2;
Fix $FreeBSD$ RCS IDs, which gave me a real shock when their revision
numbers moved backwards.
 1.11 22-Jun-2005  dyoung Resolve conflicts in importation of 18-May-2005 ath(4) / net80211(9)
from FreeBSD. Introduce compatibility shims (sys/dev/ic/ath_netbsd.[ch],
sys/net80211/ieee80211_netbsd.[ch]). Update drivers (an, atu, atw,
awi, ipw, iwi, rtw, wi) for the new net80211(9) API.
 1.10 10-Aug-2004  dyoung IBSS fixes: get IBSS beacon generation right. Merge with a same-SSID,
same-channel IBSS.
 1.9 28-Jul-2004  dyoung branches: 1.9.2;
Finalize import of the Atheros HAL 0.9.9.13, bringing ath(4)
up-to-date where the HAL API changed.
 1.8 30-Apr-2004  dyoung Sync with FreeBSD. Here are the changes FreeBSD has made:
 1.7 29-Feb-2004  dyoung Update ath(4)'s Hardware Abstraction Layer (HAL) to version 0.9.6.11.

Both the API and ABI changed, hence the changes to so many .c and
.h files.
 1.6 16-Dec-2003  dyoung Synchronize with FreeBSD:

* add constants to enums

* HAL update: stops panics, fixes ad hoc-mode beacons, some API
changes

* get and use mac/phy/rf front-end revision codes

* add a custom ath(4) ic_node_getrssi callback which does RSSI
averaging

* do not immediately scan, but re-associate after missing beacons.

* bug fix: don't if_init after detach.

* HAL diagnostics ioctl, SIOCGATHDIAG

* send DS parameters element in beacons

* const-ify some pointers

* consolidate rx-filter settings into ath_calcrxfilter

* abstract FreeBSD `ticks', NetBSD `hardclock_ticks' with ATH_TICKS()

* misc. other changes
 1.5 16-Oct-2003  ichiro add {shutdownhook,powerhook}disestablish()
 1.4 15-Oct-2003  itojun add $NetBSD$
 1.3 14-Oct-2003  ichiro add support ath on cardbus
- implement power management
 1.2 13-Oct-2003  dyoung Miscellaneous changes for NetBSD compatibility.
 1.1 07-Oct-2003  dyoung branches: 1.1.1;
Initial revision
 1.1.1.6 18-Nov-2005  skrll Import FreeBSD's ath(4) of 1-nov-2005
 1.1.1.5 26-Jul-2005  dyoung Import FreeBSD's ath(4) of 2005-07-11
 1.1.1.4 21-Jun-2005  dyoung Import FreeBSD's ath(4) of 2005-05-18
 1.1.1.3 29-Apr-2004  dyoung Import FreeBSD's ath of 28-apr-2004
 1.1.1.2 15-Dec-2003  dyoung Import FreeBSD's ath of 12-dec-2003
 1.1.1.1 07-Oct-2003  dyoung Initial import of ath(4) from FreeBSD.
 1.9.2.7 11-Dec-2005  christos Sync with head.
 1.9.2.6 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.9.2.5 21-Sep-2004  skrll Fix the sync with head I botched.
 1.9.2.4 18-Sep-2004  skrll Sync with HEAD.
 1.9.2.3 12-Aug-2004  skrll Sync with HEAD.
 1.9.2.2 03-Aug-2004  skrll Sync with HEAD
 1.9.2.1 28-Jul-2004  skrll file athvar.h was added on branch ktrace-lwp on 2004-08-03 10:46:10 +0000
 1.12.2.5 17-Mar-2008  yamt sync with head.
 1.12.2.4 21-Jan-2008  yamt sync with head
 1.12.2.3 03-Sep-2007  yamt sync with head.
 1.12.2.2 30-Dec-2006  yamt sync with head.
 1.12.2.1 21-Jun-2006  yamt sync with head.
 1.13.6.1 22-Nov-2005  yamt sync with head.
 1.14.6.3 07-Jun-2006  kardel Sync with head.
 1.14.6.2 01-Jun-2006  kardel Sync with head.
 1.14.6.1 22-Apr-2006  simonb Sync with head.
 1.14.4.1 09-Sep-2006  rpaulo sync with head
 1.15.6.1 24-May-2006  tron Merge 2006-05-24 NetBSD-current into the "peter-altq" branch.
 1.15.4.1 19-Apr-2006  elad sync with head.
 1.15.2.3 11-Aug-2006  yamt sync with head
 1.15.2.2 26-Jun-2006  yamt sync with head.
 1.15.2.1 11-Apr-2006  yamt sync with head
 1.16.2.1 19-Jun-2006  chap Sync with head.
 1.19.10.1 12-Mar-2007  rmind Sync with HEAD.
 1.20.2.1 20-Aug-2007  ad Sync with HEAD.
 1.21.18.1 11-Dec-2007  yamt sync with head.
 1.21.16.1 26-Dec-2007  ad Sync with head.
 1.21.8.2 23-Mar-2008  matt sync with HEAD
 1.21.8.1 09-Jan-2008  matt sync with HEAD
 1.21.6.2 01-Oct-2007  joerg Extend device API by device_power_private and device_power_set_private.
The latter is a temporary mean until the pnp_register API itself is
overhault. This functions allow a generic power handler to store its
state independent of the driver.

Use this and revamp the PCI power handling. Pretty much all PCI devices
had power handlers that did the same thing, generalize this in
pci_generic_power_register/deregister and the handler. This interface
offers callbacks for the drivers to save and restore state on
transistions. After a long discussion with jmcneill@ it was considered
to be powerful enough until evidence is shown that devices can handle
D1/D2 with less code and higher speed than without the full
save/restore. The generic code is carefully written to handle device
without PCI-PM support and ensure that the correct registers are written
to when D3 loses all state.

Reimplement the generic PCI network device handling on
top of PCI generic power handling.

Introduce pci_disable_retry as used and implemented locally at least by
ath(4) and iwi(4). Use it in this drivers to restore behaviour from
before the introduction of generic PCI network handling.

Convert all PCI drivers that were using pnp_register to the new
framework. The only exception is vga(4) as it is commonly used as
console device. Add a note therein that this should be fixed later.
 1.21.6.1 23-Aug-2007  joerg Convert ath(4) to new style power management.
Remove the resetting of the PCI retry register on resume,
the restored configuration should have it already.
 1.22.2.1 02-Jan-2008  bouyer Sync with HEAD
 1.23.6.3 17-Jan-2009  mjf Sync with HEAD.
 1.23.6.2 28-Sep-2008  mjf Sync with HEAD.
 1.23.6.1 03-Apr-2008  mjf Sync with HEAD.
 1.23.2.1 24-Mar-2008  keiichi sync with head.
 1.24.10.2 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.24.10.1 19-Oct-2008  haad Sync with HEAD.
 1.24.8.1 18-Jul-2008  simonb Sync with head.
 1.24.6.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.24.4.5 11-Aug-2010  yamt sync with head.
 1.24.4.4 11-Mar-2010  yamt sync with head
 1.24.4.3 19-Aug-2009  yamt sync with head.
 1.24.4.2 16-May-2009  yamt sync with head
 1.24.4.1 04-May-2009  yamt sync with head.
 1.25.10.1 21-Apr-2010  matt sync to netbsd-5
 1.25.4.2 07-Aug-2009  snj Pull up following revision(s) (requested by jmcneill in ticket #775):
sys/dev/ic/ath.c: revision 1.106
sys/dev/ic/athvar.h: revision 1.28
- fix TKIP, changes adapted from FreeBSD
- reduce diffs between FreeBSD and NetBSD athvar.h
 1.25.4.1 07-Aug-2009  snj Apply patch (requested by jmcneill in ticket 775):
Update to the open source atheros HAL.
 1.25.2.1 19-Jan-2009  skrll Sync with HEAD.
 1.26.2.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.30.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.32.2.2 21-Apr-2011  rmind sync with head
 1.32.2.1 30-May-2010  rmind sync with head
 1.33.2.1 06-Jun-2011  jruoho Sync with HEAD.
 1.35.12.1 25-Feb-2013  tls resync with head
 1.35.2.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.42 29-Jul-2025  andvar Fix few typos in comments.
 1.41 01-Nov-2022  andvar branches: 1.41.8;
s/varaible/variable/ and s/varible/variable/ in comments.
 1.40 03-Dec-2021  andvar fix various typos in comments, log messages and documentation.
 1.39 07-Aug-2021  thorpej Merge thorpej-cfargs2.
 1.38 24-Apr-2021  thorpej branches: 1.38.8;
Merge thorpej-cfargs branch:

Simplify and make extensible the config_search() / config_found() /
config_attach() interfaces: rather than having different variants for
which arguments you want pass along, just have a single call that
takes a variadic list of tag-value arguments.

Adjust all call sites:
- Simplify wherever possible; don't pass along arguments that aren't
actually needed.
- Don't be explicit about what interface attribute is attaching if
the device only has one. (More simplification.)
- Add a config_probe() function to be used in indirect configuiration
situations, making is visibly easier to see when indirect config is
in play, and allowing for future change in semantics. (As of now,
this is just a wrapper around config_match(), but that is an
implementation detail.)

Remove unnecessary or redundant interface attributes where they're not
needed.

There are currently 5 "cfargs" defined:
- CFARG_SUBMATCH (submatch function for direct config)
- CFARG_SEARCH (search function for indirect config)
- CFARG_IATTR (interface attribte)
- CFARG_LOCATORS (locators array)
- CFARG_DEVHANDLE (devhandle_t - wraps OFW, ACPI, etc. handles)

...and a sentinel value CFARG_EOL.

Add some extra sanity checking to ensure that interface attributes
aren't ambiguous.

Use CFARG_DEVHANDLE in MI FDT, OFW, and ACPI code, and macppc and shark
ports to associate those device handles with device_t instance. This
will trickle trough to more places over time (need back-end for pre-OFW
Sun OBP; any others?).
 1.37 16-Nov-2020  msaitoh branches: 1.37.2;
s/reseting/resetting/
 1.36 22-Jul-2020  msaitoh branches: 1.36.2;
s/reseting/resetting/
 1.35 27-Dec-2019  msaitoh s/transfered/transferred/
 1.34 03-Sep-2018  riastradh Rename min/max -> uimin/uimax for better honesty.

These functions are defined on unsigned int. The generic name
min/max should not silently truncate to 32 bits on 64-bit systems.
This is purely a name change -- no functional change intended.

HOWEVER! Some subsystems have

#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))

even though our standard name for that is MIN/MAX. Although these
may invite multiple evaluation bugs, these do _not_ cause integer
truncation.

To avoid `fixing' these cases, I first changed the name in libkern,
and then compile-tested every file where min/max occurred in order to
confirm that it failed -- and thus confirm that nothing shadowed
min/max -- before changing it.

I have left a handful of bootloaders that are too annoying to
compile-test, and some dead code:

cobalt ews4800mips hp300 hppa ia64 luna68k vax
acorn32/if_ie.c (not included in any kernels)
macppc/if_gm.c (superseded by gem(4))

It should be easy to fix the fallout once identified -- this way of
doing things fails safe, and the goal here, after all, is to _avoid_
silent integer truncations, not introduce them.

Maybe one day we can reintroduce min/max as type-generic things that
never silently truncate. But we should avoid doing that for a while,
so that existing code has a chance to be detected by the compiler for
conversion to uimin/uimax without changing the semantics until we can
properly audit it all. (Who knows, maybe in some cases integer
truncation is actually intended!)
 1.33 01-Jun-2017  chs branches: 1.33.8; 1.33.10;
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.
 1.32 13-Jul-2014  dholland branches: 1.32.4;
"peripheral", not "peripherial".
 1.31 04-Jun-2014  wiz Remove set-but-unused variable.
From John D. Baker on current-users.
 1.30 26-May-2011  jakllsch branches: 1.30.14; 1.30.28;
Convert malloc(9) to kmem(9) in atppc(4).
(Intended to have been part of previous commit.)
 1.29 26-May-2011  jakllsch Convert ltsleep() in atppc(4) to modern interfaces.

Reviewed by rmind@.
 1.28 16-Dec-2008  christos branches: 1.28.6; 1.28.8;
replace bitmask_snprintf(9) with snprintb(3)
 1.27 18-Apr-2008  cegger branches: 1.27.4; 1.27.12;
Fix panics at boot and some other misc bugs. From Hans Rosenfeld.
 1.26 15-Apr-2008  cegger device_t / softc split. From Hans Rosenfeld
 1.25 08-Apr-2008  cegger use aprint_*_dev and device_xname
 1.24 19-Oct-2007  ad branches: 1.24.16;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.23 04-Mar-2007  christos branches: 1.23.2; 1.23.14; 1.23.16; 1.23.20;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.22 25-Dec-2006  wiz branches: 1.22.2;
Spell "separate" correctly. From Zafer Aydogan.
 1.21 29-May-2006  drochner branches: 1.21.6;
Remove passing of an uninitialized variable found by gcc4.
(The variable was not used by the called function, so remove the
argument completely.)
 1.20 10-May-2006  drochner branches: 1.20.2;
remove spl and locking stuff from interrupt handler
 1.19 11-Dec-2005  christos branches: 1.19.4; 1.19.6; 1.19.8; 1.19.10; 1.19.12;
merge ktrace-lwp.
 1.18 13-Sep-2004  drochner branches: 1.18.12;
a round of autoconf cleanup:
-convert submatch() style functions (passed to config_search() or
config_found_sm()) to the locator passing variants
-pass interface attributes in some cases
-make submatch() functions look uniformly as far as possible
-avoid macros which just hide cfdata members, and reduce dependencies
on "locators.h"
 1.17 24-Aug-2004  thorpej Use ANSI function decls and more use of static.
 1.16 21-Apr-2004  drochner branches: 1.16.2;
initialize the lock
 1.15 24-Feb-2004  drochner The interrupt claim stuff is broken -- data buffers
and external interrupt handlers should be completely
unrelated.
For now, just remove the obvious culprit in the nibble/ps2
case to make NTP pps signal capturing work again.
External handlers should be passed to the lower level,
and they should have full power and responsibility if
they are installed, and their lavel should be selected
by the frontend.
Being here, comment out <machine/intr.h> - it is not
used yet, and do some more conmetic cleanup.
 1.14 24-Feb-2004  wiz occured -> occurred. From Peter Postma.
 1.13 10-Feb-2004  jdolecek add Gary Thorpe copyright notice
 1.12 10-Feb-2004  jdolecek fix atppcintr() to support shared interrupts properly
problem found and fix provided by Paul Shupak
 1.11 03-Feb-2004  jdolecek some style changes - g/c redundant cast, simplify code in atppc_read_ivar()
 1.10 28-Jan-2004  jdolecek don't limit size of DMA transfer by size of FIFO
problem reported and fix provided in PR kern/24200 by Paul Shupak
 1.9 28-Jan-2004  drochner -make it compile with ATPPC_DEBUG
-minor cleanup (whitespace, avoid a typecast)
 1.8 25-Jan-2004  jdolecek print the parallel port capabilities and FIFO attributes always,
not just with ATPPC_DEBUG/ATPPC_VERBOSE
remove the printf("\n") on start of atppc_sc_attach()
 1.7 25-Jan-2004  bjh21 Remove dollar signs from foreign RCSIDs per doc/3RDPARTY.
Add __KERNEL_RCSID() to .c files.
 1.6 22-Jan-2004  jdolecek Resurrect "dev" variable from atppc_sc_attach() removed in rev 1.4
(#ifdef ATPPC_DEBUG), so that this compiles with the option set

Fixes PR kern/24193 by Paul Shupak
 1.5 22-Jan-2004  jdolecek Reset the service bit of ECP register, so that write threshold would
be identified correctly
Problem reported and fix provided in PR kern/24185 by Paul Shupak
 1.4 22-Jan-2004  bjh21 Remove unused "dev" variable from atppc_sc_attach().
Remove unused include of <dev/isa/isavar.h>, which fails on non-ISA platforms.
 1.3 21-Jan-2004  bjh21 Add RCSID comments.
 1.2 20-Jan-2004  jdolecek make compile - fix print formats
 1.1 19-Jan-2004  jdolecek branches: 1.1.1;
Initial revision
 1.1.1.1 19-Jan-2004  jdolecek Import Gary Thorpe's netbsd-ppbus 1.3. This is NetBSD port
of FreeBSD Parallel Port Bus framework. Work in progress.
 1.16.2.5 21-Sep-2004  skrll Fix the sync with head I botched.
 1.16.2.4 18-Sep-2004  skrll Sync with HEAD.
 1.16.2.3 25-Aug-2004  skrll Sync with HEAD.
 1.16.2.2 03-Aug-2004  skrll Sync with HEAD
 1.16.2.1 21-Apr-2004  skrll file atppc.c was added on branch ktrace-lwp on 2004-08-03 10:46:10 +0000
 1.18.12.4 27-Oct-2007  yamt sync with head.
 1.18.12.3 03-Sep-2007  yamt sync with head.
 1.18.12.2 30-Dec-2006  yamt sync with head.
 1.18.12.1 21-Jun-2006  yamt sync with head.
 1.19.12.1 24-May-2006  tron Merge 2006-05-24 NetBSD-current into the "peter-altq" branch.
 1.19.10.1 11-May-2006  elad sync with head
 1.19.8.2 26-Jun-2006  yamt sync with head.
 1.19.8.1 24-May-2006  yamt sync with head.
 1.19.6.1 01-Jun-2006  kardel Sync with head.
 1.19.4.1 09-Sep-2006  rpaulo sync with head
 1.20.2.1 19-Jun-2006  chap Sync with head.
 1.21.6.1 12-Jan-2007  ad Sync with head.
 1.22.2.1 12-Mar-2007  rmind Sync with HEAD.
 1.23.20.1 25-Oct-2007  bouyer Sync with HEAD.
 1.23.16.1 06-Nov-2007  matt sync with HEAD
 1.23.14.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.23.2.1 23-Oct-2007  ad Sync with head.
 1.24.16.2 17-Jan-2009  mjf Sync with HEAD.
 1.24.16.1 02-Jun-2008  mjf Sync with HEAD.
 1.27.12.1 19-Jan-2009  skrll Sync with HEAD.
 1.27.4.1 04-May-2009  yamt sync with head.
 1.28.8.1 06-Jun-2011  jruoho Sync with HEAD.
 1.28.6.1 31-May-2011  rmind sync with head
 1.30.28.1 10-Aug-2014  tls Rebase.
 1.30.14.2 03-Dec-2017  jdolecek update from HEAD
 1.30.14.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.32.4.1 28-Aug-2017  skrll Sync with HEAD
 1.33.10.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.33.10.1 10-Jun-2019  christos Sync with HEAD
 1.33.8.1 06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.36.2.1 14-Dec-2020  thorpej Sync w/ HEAD.
 1.37.2.1 21-Mar-2021  thorpej Give config_found() the same variadic arguments treatment as
config_search(). This commit only adds the CFARG_EOL sentinel
to the existing config_found() calls. Conversion of config_found_sm_loc()
and config_found_ia() call sites will be in subsequent commits.
 1.38.8.1 04-Aug-2021  thorpej Adapt to CFARGS().
 1.41.8.1 02-Aug-2025  perseant Sync with HEAD
 1.6 15-Sep-2016  jdolecek remove last isolated islands using BUS_SPACE_BARRIER_SYNC and
BUS_SPACE_BARRIER_X_BEFORE_X - these were only ever defined for mips and ia64,
and never actually implemented even there
 1.5 11-Dec-2005  christos branches: 1.5.120; 1.5.140; 1.5.144;
merge ktrace-lwp.
 1.4 27-Feb-2005  perry nuke trailing whitespace
 1.3 25-Jan-2004  bjh21 branches: 1.3.4; 1.3.10; 1.3.12;
Remove dollar signs from foreign RCSIDs per doc/3RDPARTY.
Add __KERNEL_RCSID() to .c files.
 1.2 21-Jan-2004  bjh21 Add RCSID comments.
 1.1 19-Jan-2004  jdolecek branches: 1.1.1;
Initial revision
 1.1.1.1 19-Jan-2004  jdolecek Import Gary Thorpe's netbsd-ppbus 1.3. This is NetBSD port
of FreeBSD Parallel Port Bus framework. Work in progress.
 1.3.12.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.3.10.1 29-Apr-2005  kent sync with -current
 1.3.4.5 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.3.4.4 21-Sep-2004  skrll Fix the sync with head I botched.
 1.3.4.3 18-Sep-2004  skrll Sync with HEAD.
 1.3.4.2 03-Aug-2004  skrll Sync with HEAD
 1.3.4.1 25-Jan-2004  skrll file atppcreg.h was added on branch ktrace-lwp on 2004-08-03 10:46:10 +0000
 1.5.144.1 04-Nov-2016  pgoyette Sync with HEAD
 1.5.140.1 05-Oct-2016  skrll Sync with HEAD
 1.5.120.1 03-Dec-2017  jdolecek update from HEAD
 1.13 13-Aug-2024  andvar s/Thresold/Threshold/ in comments.
 1.12 26-May-2011  jakllsch branches: 1.12.94;
Convert ltsleep() in atppc(4) to modern interfaces.

Reviewed by rmind@.
 1.11 01-May-2008  cegger branches: 1.11.22; 1.11.28;
compile-fix with MULTIPROCESSOR. From Hans Rosenfeld.
 1.10 15-Apr-2008  cegger branches: 1.10.2; 1.10.4;
device_t / softc split. From Hans Rosenfeld
 1.9 19-Oct-2007  ad branches: 1.9.16;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.8 04-Mar-2007  christos branches: 1.8.2; 1.8.14; 1.8.16; 1.8.20;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.7 11-Dec-2005  christos branches: 1.7.26;
merge ktrace-lwp.
 1.6 27-Feb-2005  perry branches: 1.6.4;
nuke trailing whitespace
 1.5 04-Feb-2005  perry de-__P
 1.4 21-Apr-2004  drochner branches: 1.4.2; 1.4.6; 1.4.8;
initialize the lock
 1.3 25-Jan-2004  bjh21 Remove dollar signs from foreign RCSIDs per doc/3RDPARTY.
Add __KERNEL_RCSID() to .c files.
 1.2 21-Jan-2004  bjh21 Add RCSID comments.
 1.1 19-Jan-2004  jdolecek branches: 1.1.1;
Initial revision
 1.1.1.1 19-Jan-2004  jdolecek Import Gary Thorpe's netbsd-ppbus 1.3. This is NetBSD port
of FreeBSD Parallel Port Bus framework. Work in progress.
 1.4.8.2 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.4.8.1 12-Feb-2005  yamt sync with head.
 1.4.6.1 29-Apr-2005  kent sync with -current
 1.4.2.6 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.4.2.5 04-Feb-2005  skrll Sync with HEAD.
 1.4.2.4 21-Sep-2004  skrll Fix the sync with head I botched.
 1.4.2.3 18-Sep-2004  skrll Sync with HEAD.
 1.4.2.2 03-Aug-2004  skrll Sync with HEAD
 1.4.2.1 21-Apr-2004  skrll file atppcvar.h was added on branch ktrace-lwp on 2004-08-03 10:46:10 +0000
 1.6.4.2 27-Oct-2007  yamt sync with head.
 1.6.4.1 03-Sep-2007  yamt sync with head.
 1.7.26.1 12-Mar-2007  rmind Sync with HEAD.
 1.8.20.1 25-Oct-2007  bouyer Sync with HEAD.
 1.8.16.1 06-Nov-2007  matt sync with HEAD
 1.8.14.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.8.2.1 23-Oct-2007  ad Sync with head.
 1.9.16.1 02-Jun-2008  mjf Sync with HEAD.
 1.10.4.1 16-May-2008  yamt sync with head.
 1.10.2.1 18-May-2008  yamt sync with head.
 1.11.28.1 06-Jun-2011  jruoho Sync with HEAD.
 1.11.22.1 31-May-2011  rmind sync with head
 1.12.94.1 02-Aug-2025  perseant Sync with HEAD
 1.12 28-Oct-2017  riastradh Kill some more extern struct cfdriver declarations.

Down with externs in .c!
 1.11 23-Nov-2011  jmcneill branches: 1.11.8;
Merge jmcneill-audiomp3 branch, which is derived from ad-audiomp2. From
the original ad-audiomp branch notes:

Add MP locking to the audio drivers.

Making the audio drivers MP safe is necessary before efforts
can be made to make the VM system MP safe.

The are two locks per device instance, an ISR lock and
a character device lock. The ISR lock replaces calls to
splaudio()/splx(), and will be held across calls to device
methods which were called at splaudio() before (e.g.
trigger_output). The character device lock is held across
calls to nearly all of the methods, excluding some only
used for initialization, e.g. get_locks.

Welcome to 5.99.57.
 1.10 07-Apr-2009  dyoung branches: 1.10.12; 1.10.14;
Make pcppi(4) detach the "speaker" from attimer(4), so that the
corresponding attimer(4) resource is not perpetually busy: now it
is possible to detach and to reattach pcppi(4). Make attimer(4)'s
device-detachment hook return EBUSY if pcppi(4) is still attached, so
that pcppi(4) cannot end up with a dangling pointer to attimer(4).
 1.9 12-Jun-2008  cegger branches: 1.9.4; 1.9.8; 1.9.10;
use device_lookup_private to get softc
 1.8 29-Apr-2008  martin branches: 1.8.2; 1.8.4;
Convert to new 2 clause license
 1.7 04-Mar-2008  cube branches: 1.7.2; 1.7.4;
- Split device_t and softc for pcppi(4) and attimer(4)
- Change the attimer <-> pcppi communication using device_t so that
pcppi(4) doesn't have to know about the contents of struct attimer_softc.

XXX pcppi's childdet function is completely wrong. This has to be
XXX revisited later.
 1.6 03-Jan-2008  dyoung branches: 1.6.2; 1.6.6;
Detach attimer at acpi, attimer at isa.
 1.5 09-Dec-2007  jmcneill branches: 1.5.2;
Merge jmcneill-pm branch.
 1.4 19-Oct-2007  ad branches: 1.4.2; 1.4.4; 1.4.6;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.3 10-Sep-2007  cube branches: 1.3.4;
Remove 3rd clause and my name from all the licences which were only in my
name.
 1.2 11-Dec-2005  christos branches: 1.2.30; 1.2.44; 1.2.46;
merge ktrace-lwp.
 1.1 25-Mar-2005  cube branches: 1.1.2; 1.1.4; 1.1.6; 1.1.8;
Add attimer(4) driver, with ISA and ACPI attachments.

attimer(4) is the new body of the part of pcppi(4) that mapped the TIMER1
register to set the pitch of the bell. It was necessary to separate them
in order to have a working ACPI attachment (as the two appear as different
devices in the ACPI structures).
 1.1.8.3 17-Mar-2008  yamt sync with head.
 1.1.8.2 21-Jan-2008  yamt sync with head
 1.1.8.1 27-Oct-2007  yamt sync with head.
 1.1.6.2 29-Apr-2005  kent sync with -current
 1.1.6.1 25-Mar-2005  kent file attimer.c was added on branch kent-audio2 on 2005-04-29 11:28:49 +0000
 1.1.4.2 01-Apr-2005  skrll Sync with HEAD.
 1.1.4.1 25-Mar-2005  skrll file attimer.c was added on branch ktrace-lwp on 2005-04-01 14:29:52 +0000
 1.1.2.2 26-Mar-2005  yamt sync with head.
 1.1.2.1 25-Mar-2005  yamt file attimer.c was added on branch yamt-km on 2005-03-26 18:19:19 +0000
 1.2.46.3 23-Mar-2008  matt sync with HEAD
 1.2.46.2 09-Jan-2008  matt sync with HEAD
 1.2.46.1 06-Nov-2007  matt sync with HEAD
 1.2.44.5 08-Dec-2007  jmcneill Rename pnp(9) -> pmf(9), as requested by many.
 1.2.44.4 06-Nov-2007  joerg Refactor PNP API:
- Make suspend/resume directly a device functionality. It consists of
three layers (class logic, device logic, bus logic), all of them being
optional. This replaces D0/D3 transitions.
- device_is_active returns true if the device was not disabled and was
not suspended (even partially), device_is_enabled returns true if the
device was enabled.
- Change pnp_global_transition into pnp_system_suspend and
pnp_system_resume. Before running any suspend/resume handlers, check
that all currently attached devices support power management and bail
out otherwise. The latter is not done for the shutdown/panic case.
- Make the former bus-specific generic network handlers a class handler.
- Make PNP message like volume up/down/toogle PNP events. Each device
can register what events they are interested in and whether the handler
should be global or not.
- Introduce device_active API for devices to mark themselve in use from
either the system or the device. Use this to implement the idle handling
for audio and input devices. This is intended to replace most ad-hoc
watchdogs as well.
- Fix somes situations in which audio resume would lose mixer settings.
- Make USB host controllers better deal with suspend in the light of
shared interrupts.
- Flush filesystem cache on suspend.
- Flush disk caches on suspend. Put ATA disks into standby on suspend as
well.
- Adopt drivers to use the new PNP API.
- Fix a critical bug in the generic cardbus layer that made D0->D3
break.
- Fix ral(4) to set if_stop.
- Convert cbb(4) to the new PNP API.
- Apply the PCI Express SCI fix on resume again.
 1.2.44.3 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.2.44.2 02-Oct-2007  joerg Sync with HEAD.
 1.2.44.1 05-Aug-2007  jmcneill Certain devices either don't require a power handler, or are restored
on resume outside of the pnp power management framework. For such devices,
introduce the null power handler, pnp_generic_power.
 1.2.30.2 23-Oct-2007  ad Sync with head.
 1.2.30.1 09-Oct-2007  ad Sync with head.
 1.3.4.1 25-Oct-2007  bouyer Sync with HEAD.
 1.4.6.1 11-Dec-2007  yamt sync with head.
 1.4.4.1 26-Dec-2007  ad Sync with head.
 1.4.2.1 18-Feb-2008  mjf Sync with HEAD.
 1.5.2.1 08-Jan-2008  bouyer Sync with HEAD
 1.6.6.3 29-Jun-2008  mjf Sync with HEAD.
 1.6.6.2 02-Jun-2008  mjf Sync with HEAD.
 1.6.6.1 03-Apr-2008  mjf Sync with HEAD.
 1.6.2.1 24-Mar-2008  keiichi sync with head.
 1.7.4.2 04-May-2009  yamt sync with head.
 1.7.4.1 16-May-2008  yamt sync with head.
 1.7.2.2 17-Jun-2008  yamt sync with head.
 1.7.2.1 18-May-2008  yamt sync with head.
 1.8.4.1 18-Jun-2008  simonb Sync with head.
 1.8.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.9.10.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.9.8.1 09-Dec-2008  ad Checkpoint work on MIDI.
 1.9.4.1 28-Apr-2009  skrll Sync with HEAD.
 1.10.14.1 19-Nov-2011  jmcneill port ad-audiomp2 branch changes to 5.99.56
todo:
- port ad-audiomp2 pcppi changes
- these drivers need to be fixed:
- emuxki
- gcscaudio
- hdafg
- uaudio
- umidi
- MD audio drivers
 1.10.12.1 17-Apr-2012  yamt sync with head
 1.11.8.1 03-Dec-2017  jdolecek update from HEAD
 1.7 07-Apr-2009  dyoung Make pcppi(4) detach the "speaker" from attimer(4), so that the
corresponding attimer(4) resource is not perpetually busy: now it
is possible to detach and to reattach pcppi(4). Make attimer(4)'s
device-detachment hook return EBUSY if pcppi(4) is still attached, so
that pcppi(4) cannot end up with a dangling pointer to attimer(4).
 1.6 29-Apr-2008  martin branches: 1.6.8; 1.6.14;
Convert to new 2 clause license
 1.5 04-Mar-2008  cube branches: 1.5.2; 1.5.4;
- Split device_t and softc for pcppi(4) and attimer(4)
- Change the attimer <-> pcppi communication using device_t so that
pcppi(4) doesn't have to know about the contents of struct attimer_softc.

XXX pcppi's childdet function is completely wrong. This has to be
XXX revisited later.
 1.4 03-Jan-2008  dyoung branches: 1.4.2; 1.4.6;
Detach attimer at acpi, attimer at isa.
 1.3 10-Sep-2007  cube branches: 1.3.6; 1.3.12;
Remove 3rd clause and my name from all the licences which were only in my
name.
 1.2 11-Dec-2005  christos branches: 1.2.30; 1.2.44; 1.2.46;
merge ktrace-lwp.
 1.1 25-Mar-2005  cube branches: 1.1.2; 1.1.4; 1.1.6; 1.1.8;
Add attimer(4) driver, with ISA and ACPI attachments.

attimer(4) is the new body of the part of pcppi(4) that mapped the TIMER1
register to set the pitch of the bell. It was necessary to separate them
in order to have a working ACPI attachment (as the two appear as different
devices in the ACPI structures).
 1.1.8.3 17-Mar-2008  yamt sync with head.
 1.1.8.2 21-Jan-2008  yamt sync with head
 1.1.8.1 27-Oct-2007  yamt sync with head.
 1.1.6.2 29-Apr-2005  kent sync with -current
 1.1.6.1 25-Mar-2005  kent file attimervar.h was added on branch kent-audio2 on 2005-04-29 11:28:49 +0000
 1.1.4.2 01-Apr-2005  skrll Sync with HEAD.
 1.1.4.1 25-Mar-2005  skrll file attimervar.h was added on branch ktrace-lwp on 2005-04-01 14:29:52 +0000
 1.1.2.2 26-Mar-2005  yamt sync with head.
 1.1.2.1 25-Mar-2005  yamt file attimervar.h was added on branch yamt-km on 2005-03-26 18:19:19 +0000
 1.2.46.3 23-Mar-2008  matt sync with HEAD
 1.2.46.2 09-Jan-2008  matt sync with HEAD
 1.2.46.1 06-Nov-2007  matt sync with HEAD
 1.2.44.1 02-Oct-2007  joerg Sync with HEAD.
 1.2.30.1 09-Oct-2007  ad Sync with head.
 1.3.12.1 08-Jan-2008  bouyer Sync with HEAD
 1.3.6.1 18-Feb-2008  mjf Sync with HEAD.
 1.4.6.2 02-Jun-2008  mjf Sync with HEAD.
 1.4.6.1 03-Apr-2008  mjf Sync with HEAD.
 1.4.2.1 24-Mar-2008  keiichi sync with head.
 1.5.4.2 04-May-2009  yamt sync with head.
 1.5.4.1 16-May-2008  yamt sync with head.
 1.5.2.1 18-May-2008  yamt sync with head.
 1.6.14.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.6.8.1 28-Apr-2009  skrll Sync with HEAD.
 1.172 21-Sep-2021  christos don't opencode kauth_cred_get()
 1.171 16-Jun-2021  riastradh if_attach and if_initialize cannot fail, don't test return value

These were originally made failable back in 2017 when if_initialize
allocated a softint in every interface for link state changes, so
that it could fail gracefully instead of panicking:

https://mail-index.NetBSD.org/source-changes/2017/10/23/msg089053.html

However, this spawned many seldom- or never-tested error branches,
which are risky to have around. And that softint in every interface
has since been replaced by a single global workqueue, because link
state changes require thread context but not low latency or high
throughput:

https://mail-index.NetBSD.org/source-changes/2020/02/06/msg113759.html

So there is no longer any reason for if_initialize to fail. (The
subroutine if_stats_init can't fail because percpu_alloc can't fail
either.)

There is a snag: the softint_establish in if_percpuq_create could
fail, potentially leading to bad consequences later on trying to use
the softint. This change doesn't introduce any new bugs because of
the snag -- if_percpuq_attach was already broken. However, the snag
can be better addressed without spawning error branches, either by
using a single softint or making softints less scarce.

(Separate commit will change the signatures of if_attach and
if_initialize to return void, scheduled to ride whatever is the next
convenient kernel bump.)

Patch and testing on amd64 and evbmips64-eb by maya@; commit message
soliloquy, and compile-testing on evbppc/i386/earmv7hf, by me.
 1.170 29-Jan-2020  thorpej branches: 1.170.10;
Adopt <net/if_stats.h>.
 1.169 10-Nov-2019  chs branches: 1.169.2;
in many device attach paths, allocate memory with M_WAITOK instead of M_NOWAIT
and remove code to handle failures that can no longer happen.
 1.168 28-May-2019  msaitoh Use ETHER_LOCK()/ETHER_UNLOCK() for all ethernet drivers to protect ec_multi*.
 1.167 23-May-2019  msaitoh Whitespace fix (mainly tabify).
 1.166 23-May-2019  msaitoh -No functional change:
- KNF
- u_int*_t -> uint*_t.
 1.165 05-Feb-2019  msaitoh Remove very old IFF_NOTRAILERS flag.
 1.164 26-Jun-2018  msaitoh branches: 1.164.2;
Implement the BPF direction filter (BIOC[GS]DIRECTION). It provides backward
compatibility with BIOC[GS]SEESENT ioctl. The userland interface is the same
as FreeBSD.

This change also fixes a bug that the direction is misunderstand on some
environment by passing the direction to bpf_mtap*() instead of checking
m->m_pkthdr.rcvif.
 1.163 01-May-2018  maya GC private 802.11 rateset declarations, use the standard ones.

Build tested only.
 1.162 23-Oct-2017  msaitoh branches: 1.162.2;
- Free resources correctly on some errors in atw_attach().
- Use apint*() insread of printf() in the attach function.
 1.161 02-Feb-2017  nonaka branches: 1.161.6;
wlan interfaces make interrupt routine running on softint context.

see http://mail-index.netbsd.org/tech-kern/2016/12/06/msg021281.html

tested device:
* ath at pci: AR5212, AR5424
* athn at pci: AR9287
* ipw at pci: 2100BG
* iwi at pci: 2915ABG
* iwm at pci: 3165, 7260, 8260
* iwn at pci: 4945, 6235
* ral at pci: RT2560
* rtwn at pci: RTL8192CE
 1.160 10-Jun-2016  ozaki-r branches: 1.160.2; 1.160.4;
Introduce m_set_rcvif and m_reset_rcvif

The API is used to set (or reset) a received interface of a mbuf.
They are counterpart of m_get_rcvif, which will come in another
commit, hide internal of rcvif operation, and reduce the diff of
the upcoming change.

No functional change.
 1.159 26-May-2016  ozaki-r Introduce M_CLEARCTX and use it instead of open-coding rcvif

No functional change.
 1.158 26-May-2016  ozaki-r Use M_GETCTX

No functional change.
 1.157 26-Jan-2016  christos PR/50692: David Binderman: Set the right wake up bits.
 1.156 22-Nov-2013  riz branches: 1.156.6;
Put back and properly mark a variable which is used iff ATW_DEBUG.
 1.155 17-Oct-2013  christos - remove unused variables
- move variables inside ifdef sections
- ifdef notdef unused code
- use __USE for debugging variables
 1.154 14-Sep-2013  joerg Don't include atw_hw_decrypted, it is not used. Keep it for
documentation purposes.
 1.153 02-Apr-2011  mbalmer branches: 1.153.4; 1.153.14; 1.153.18;
Fix misplaced parenthesis. From henning.petersen@t-online.de, thanks.
 1.152 13-Nov-2010  uebayasi branches: 1.152.2;
Include sys/proc.h for curproc.
 1.151 05-Apr-2010  joerg Push the bpf_ops usage back into bpf.h. Push the common ifp->if_bpf
check into the inline functions as well the fourth argument for
bpf_attach.
 1.150 24-Feb-2010  dyoung branches: 1.150.2;
A pointer typedef entails trading too much flexibility to declare const
and non-const types, and the kernel uses both const and non-const
PMF qualifiers and device suspensors, so change the pmf_qual_t and
device_suspensor_t typedefs from "pointers to const" to non-pointer,
non-const types.
 1.149 19-Jan-2010  pooka branches: 1.149.2;
Redefine bpf linkage through an always present op vector, i.e.
#if NBPFILTER is no longer required in the client. This change
doesn't yet add support for loading bpf as a module, since drivers
can register before bpf is attached. However, callers of bpf can
now be modularized.

Dynamically loadable bpf could probably be done fairly easily with
coordination from the stub driver and the real driver by registering
attachments in the stub before the real driver is loaded and doing
a handoff. ... and I'm not going to ponder the depths of unload
here.

Tested with i386/MONOLITHIC, modified MONOLITHIC without bpf and rump.
 1.148 08-Jan-2010  dyoung Expand PMF_FN_* macros.
 1.147 12-Nov-2009  dyoung Simplify activation hook.
 1.146 16-Sep-2009  dyoung In pmf(9), improve the implementation of device self-suspension
and make suspension by self, by drvctl(8), and by ACPI system sleep
play nice together. Start solidifying some temporary API changes.

1. Extract a new header file, <sys/device_if.h>, from <sys/device.h> and
#include it from <sys/pmf.h> instead of <sys/device.h> to break the
circular dependency between <sys/device.h> and <sys/pmf.h>.

2. Introduce pmf_qual_t, an aggregate of qualifications on a PMF
suspend/resume call. Start to replace instances of PMF_FN_PROTO,
PMF_FN_ARGS, et cetera, with a pmf_qual_t.

3. Introduce the notion of a "suspensor," an entity that holds a
device in suspension. More than one suspensor may hold a device
at once. A device stays suspended as long as at least one
suspensor holds it. A device resumes when the last suspensor
releases it.

Currently, the kernel defines three suspensors,

3a the system-suspensor: for system suspension, initiated
by 'sysctl -w machdep.sleep_state=3', by lid closure, by
power-button press, et cetera,

3b the drvctl-suspensor: for device suspension by /dev/drvctl
ioctl, e.g., drvctl -S sip0.

3c the system self-suspensor: for device drivers that suspend
themselves and their children. Several drivers for network
interfaces put the network device to sleep while it is not
administratively up, that is, after the kernel calls if_stop(,
1). The self-suspensor should not be used directly. See
the description of suspensor delegates, below.

A suspensor can have one or more "delegates". A suspensor can
release devices that its delegates hold suspended. Right now,
only the system self-suspensor has delegates. For each device
that a self-suspending driver attaches, it creates the device's
self-suspensor, a delegate of the system self-suspensor.

Suspensors stop a system-wide suspend/resume cycle from waking
devices that the operator put to sleep with drvctl before the cycle.
They also help self-suspension to work more simply, safely, and in
accord with expectations.

4. Add the notion of device activation level, devact_level_t,
and a routine for checking the current activation level,
device_activation(). Current activation levels are DEVACT_LEVEL_BUS,
DEVACT_LEVEL_DRIVER, and DEVACT_LEVEL_CLASS, which respectively
indicate that the device's bus is active, that the bus and device are
active, and that the bus, device, and the functions of the device's
class (network, audio) are active.

Suspend/resume calls can be qualified with a devact_level_t.
The power-management framework treats a devact_level_t that
qualifies a device suspension as the device's current activation
level; it only runs hooks to reduce the activation level from
the presumed current level to the fully suspended state. The
framework treats a devact_level_t qualifying device resumption
as the target activation level; it only runs hooks to raise the
activation level to the target.

5. Use pmf_qual_t, devact_level_t, and self-suspensors in several
drivers.

6. Temporarily add an unused power-management workqueue that I will
remove or replace, soon.
 1.145 13-Sep-2009  dyoung Experimental support for fragmentation and RTS/CTS.

Delete unused atw_voodoo and constants.

Export Tx/Rx statistics with evcnt(9).

Correct the Short Inter-Frame Space (SIFS) that we write to ADM8211's
registers; I do not recall if that corrected the SIFS that I observed
"on the air." Use the constant IEEE80211_DUR_DS_EIFS to configure
the ADM8211's EIFS, instead of writing the same "magic" number,
0x64, that my reference driver wrote.

Do not clear OACTIVE in atw_init(), because atw_stop() cleared it
previously by calling atw_txdrain().

Use the net80211 short-preamble flag and instead of ATW_SHPREAMBLE.

Add an ADM8211 workaround from the reference driver, atw_workaround1(),
but don't compile it right now.

In at_intr(), don't stop processing the interrupt status after
restarting the receive ring, but process Tx interrupt status. If
a packet's Tx lifetime is exceeded, reinitialize the device to get
packets moving again. If the Tx FIFO underflows, restart the
transmitter, not the receiver!

Avoid losing synchronization with the Rx ring by replicating one
of Charles Hannum's fixes to rtw(4) here: receiving a management
packet may, as a side-effect, reset the Rx ring, so refer to the
softc's Rx ring pointer, sc_rxptr, every time through the loop in
atw_rxintr(), instead of refering to a pointer on the stack, i.

Re-synchronize DMA after reading the OWN bit on an Rx/Tx descriptor.
XXX This needs more work.

Reset sc_tx_timer as Tx descriptors are reclaimed from the device.

Shorten staircases in atw_watchdog().

Remove from softc an unused member, sc_intr_ack.
 1.144 05-Sep-2009  tsutsui Invert logic around nested pmf(9) registrations for readability.
 1.143 26-May-2009  dyoung Wrap some long lines. No functional change intended.
 1.142 16-Dec-2008  christos branches: 1.142.2;
replace bitmask_snprintf(9) with snprintb(3)
 1.141 07-Nov-2008  dyoung *** Summary ***

When a link-layer address changes (e.g., ifconfig ex0 link
02:de:ad:be:ef:02 active), send a gratuitous ARP and/or a Neighbor
Advertisement to update the network-/link-layer address bindings
on our LAN peers.

Refuse a change of ethernet address to the address 00:00:00:00:00:00
or to any multicast/broadcast address. (Thanks matt@.)

Reorder ifnet ioctl operations so that driver ioctls may inherit
the functions of their "class"---ether_ioctl(), fddi_ioctl(), et
cetera---and the class ioctls may inherit from the generic ioctl,
ifioctl_common(), but both driver- and class-ioctls may override
the generic behavior. Make network drivers share more code.

Distinguish a "factory" link-layer address from others for the
purposes of both protecting that address from deletion and computing
EUI64.

Return consistent, appropriate error codes from network drivers.

Improve readability. KNF.

*** Details ***

In if_attach(), always initialize the interface ioctl routine,
ifnet->if_ioctl, if the driver has not already initialized it.
Delete if_ioctl == NULL tests everywhere else, because it cannot
happen.

In the ioctl routines of network interfaces, inherit common ioctl
behaviors by calling either ifioctl_common() or whichever ioctl
routine is appropriate for the class of interface---e.g., ether_ioctl()
for ethernets.

Stop (ab)using SIOCSIFADDR and start to use SIOCINITIFADDR. In
the user->kernel interface, SIOCSIFADDR's argument was an ifreq,
but on the protocol->ifnet interface, SIOCSIFADDR's argument was
an ifaddr. That was confusing, and it would work against me as I
make it possible for a network interface to overload most ioctls.
On the protocol->ifnet interface, replace SIOCSIFADDR with
SIOCINITIFADDR. In ifioctl(), return EPERM if userland tries to
invoke SIOCINITIFADDR.

In ifioctl(), give the interface the first shot at handling most
interface ioctls, and give the protocol the second shot, instead
of the other way around. Finally, let compatibility code (COMPAT_OSOCK)
take a shot.

Pull device initialization out of switch statements under
SIOCINITIFADDR. For example, pull ..._init() out of any switch
statement that looks like this:

switch (...->sa_family) {
case ...:
..._init();
...
break;
...
default:
..._init();
...
break;
}

Rewrite many if-else clauses that handle all permutations of IFF_UP
and IFF_RUNNING to use a switch statement,

switch (x & (IFF_UP|IFF_RUNNING)) {
case 0:
...
break;
case IFF_RUNNING:
...
break;
case IFF_UP:
...
break;
case IFF_UP|IFF_RUNNING:
...
break;
}

unifdef lots of code containing #ifdef FreeBSD, #ifdef NetBSD, and
#ifdef SIOCSIFMTU, especially in fwip(4) and in ndis(4).

In ipw(4), remove an if_set_sadl() call that is out of place.

In nfe(4), reuse the jumbo MTU logic in ether_ioctl().

Let ethernets register a callback for setting h/w state such as
promiscuous mode and the multicast filter in accord with a change
in the if_flags: ether_set_ifflags_cb() registers a callback that
returns ENETRESET if the caller should reset the ethernet by calling
if_init(), 0 on success, != 0 on failure. Pull common code from
ex(4), gem(4), nfe(4), sip(4), tlp(4), vge(4) into ether_ioctl(),
and register if_flags callbacks for those drivers.

Return ENOTTY instead of EINVAL for inappropriate ioctls. In
zyd(4), use ENXIO instead of ENOTTY to indicate that the device is
not any longer attached.

Add to if_set_sadl() a boolean 'factory' argument that indicates
whether a link-layer address was assigned by the factory or some
other source. In a comment, recommend using the factory address
for generating an EUI64, and update in6_get_hw_ifid() to prefer a
factory address to any other link-layer address.

Add a routing message, RTM_LLINFO_UPD, that tells protocols to
update the binding of network-layer addresses to link-layer addresses.
Implement this message in IPv4 and IPv6 by sending a gratuitous
ARP or a neighbor advertisement, respectively. Generate RTM_LLINFO_UPD
messages on a change of an interface's link-layer address.

In ether_ioctl(), do not let SIOCALIFADDR set a link-layer address
that is broadcast/multicast or equal to 00:00:00:00:00:00.

Make ether_ioctl() call ifioctl_common() to handle ioctls that it
does not understand.

In gif(4), initialize if_softc and use it, instead of assuming that
the gif_softc and ifp overlap.

Let ifioctl_common() handle SIOCGIFADDR.

Sprinkle rtcache_invariants(), which checks on DIAGNOSTIC kernels
that certain invariants on a struct route are satisfied.

In agr(4), rewrite agr_ioctl_filter() to be a bit more explicit
about the ioctls that we do not allow on an agr(4) member interface.

bzero -> memset. Delete unnecessary casts to void *. Use
sockaddr_in_init() and sockaddr_in6_init(). Compare pointers with
NULL instead of "testing truth". Replace some instances of (type
*)0 with NULL. Change some K&R prototypes to ANSI C, and join
lines.
 1.140 09-Jul-2008  joerg branches: 1.140.2;
- device/softc split
 1.139 30-Apr-2008  ad branches: 1.139.2; 1.139.4; 1.139.6;
Make various bits of debug code compile again.
 1.138 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.137 08-Apr-2008  cegger branches: 1.137.2; 1.137.4;
use aprint_*_dev and device_xname
 1.136 11-Mar-2008  dyoung Prepare for PMF self-suspension: in the if_stop() methods, clear
IFF_UP and IFF_RUNNING before running the 'disable' step, instead
of after. Soon I will handle the 'disable' step by calling into
PMF, which may call if_stop(, 0). Ordinarily, that is harmless.
This change lets the if_stop() routines exit early when they find
on entry that IFF_RUNNING is not set.
 1.135 07-Mar-2008  dyoung Use device_t and accessors. Use PMF instead of legacy power
management. Establish the shutdown hook using PMF.
 1.134 16-Nov-2007  dyoung branches: 1.134.10; 1.134.14;
Count received frames, Rx PLCP errors, Rx FCS (CRC32) errors, and
Rx ICV errors using evcnt(9).

In promiscuous mode, and when scanning (hmm), ask the NIC for bad
packets (e.g., those that do not pass CRC32). Pass bad packets to
radiotap listeners. Pass packets to radiotap listeners before
stripping FCS. Re-order operations in atw_rxintr() to accomplish
all of this without passing bad packets up to net80211.

Set radiotap channel once in atw_tune() instead of in atw_rxintr().

Fix an endianness bug: it_len is little-endian, but bpf_mtap2()'s
argument needs to be in host order.
 1.133 16-Nov-2007  dyoung Cosmetic: rename some variables and constants. Move some constants
from atw.c to atwreg.h.
 1.132 16-Nov-2007  dyoung Replace some magic numbers with HFA3861A register names.

Do not alias the Rx descriptor word ar_ctl to ar_rssi with a #define.
Instead, call the member ar_ctlrssi.

Convert the ugly macro ATW_RXDESC_INIT() to an inline subroutine,
atw_rxdesc_init().

Do not load an empty IEEE80211_RADIOTAP_FLAGS field into the Tx
radiotap header.
 1.131 15-Nov-2007  dyoung Use __arraycount().
 1.130 19-Oct-2007  ad branches: 1.130.2;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.129 29-Sep-2007  scw branches: 1.129.2;
s/NPBFILTER/NBPFILTER/ in some #endif comments. No functional change.
 1.128 01-Sep-2007  dyoung branches: 1.128.2;
Change a bazillion occurrences of code resembling this,

error = (cmd == SIOCADDMULTI) ?
ether_addmulti(ifr, &sc->sc_ec) :
ether_delmulti(ifr, &sc->sc_ec);

if (error == ENETRESET) {

to this,

if ((error = ether_ioctl(ifp, cmd, data)) == ENETRESET) {

which does the same thing.

(A bazillion is a very large number. This seems to make the i386
ALL kernel smaller by 3kB to 4kB.)

Use ifreq_getaddr() twice in es(4).

Whitespace nits.
 1.127 09-Jul-2007  ad branches: 1.127.2; 1.127.6; 1.127.8;
Merge some of the less invasive changes from the vmlocking branch:

- kthread, callout, devsw API changes
- select()/poll() improvements
- miscellaneous MT safety improvements
 1.126 04-Mar-2007  christos branches: 1.126.2; 1.126.4;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.125 24-Nov-2006  christos branches: 1.125.4;
fix spelling of accommodate; from Zapher.
 1.124 16-Nov-2006  christos __unused removal on arguments; approved by core.
 1.123 13-Nov-2006  dyoung Stop using typeof() in the bit-twiddling macros, per yamt@'s
suggestion. This change requires that I use the __PRIuBITS format
string in atw and rtw, so do that.
 1.122 12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.121 04-Oct-2006  christos prevent empty if.
 1.120 24-Sep-2006  jmcneill Add "name" parameter to powerhook_establish, to aid debugging. No objections
on tech-kern@
 1.119 31-Aug-2006  dyoung branches: 1.119.2; 1.119.4;
Per discussion on tech-kern and tech-userlevel, move the bit-twiddling
macros, __BIT, __BITS, SHIFTIN, SHIFTOUT, and __arraycount() from
lib/libkern/libkern.h to sys/cdefs.h. Add a __-prefix to SHIFTIN
and SHIFTOUT, and add a manual page for the bit-twiddling macros,
bits(3).

Make the __BIT and __BITS macros "widthless," as best I can, by
changing their type to uintmax_t from uint32_t. XXX The manual
page lags this change by a bit.

Define __PRIxBIT and __PRIxBITS printf(3) format strings.
 1.118 17-Aug-2006  christos Fix all the -D*DEBUG* code that it was rotting away and did not even compile.
Mostly from Arnaud Lacombe, many thanks!
 1.117 06-Apr-2006  dyoung In atw_start, do not initialize lasttx with -1, but initialize it
with the next free transmit descriptor. Now, it is more obvious
that lasttx is not an illegal negative index into the descriptor
ring. Remove a superfluous assertion.

Addresses Coverity CID 1319.
 1.116 06-Apr-2006  dyoung Correct sc_bbptype, sc_rftype bounds checks. Fixes Coverity CID
1541.
 1.115 28-Mar-2006  dyoung Revamp ieee80211_get_rate. Now it does not use the rateset in the
ic->ic_bss, but it uses the rateset in its new ieee80211_node
argument, instead. If the rate is fixed by ic->ic_fixed_rate, but
the fixed rate is not in the node's rateset, choose a reasonable
default: prefer the lowest basic rate or, if there is no basic
rate, prefer the lowest rate, period.

Change a printf complaint to a debug message.

Adapt drivers to suit new ieee80211_get_rate calling convention.

XXX I really need to replace ieee80211_get_rate with a bitrate
XXX adaptation algorithm. Soon, soon....
 1.114 12-Mar-2006  dyoung branches: 1.114.2;
Note in radiotap header file and manual page that radiotap fields
are little-endian. Fix wi(4) and atw(4) to reflect this fact.
 1.113 08-Mar-2006  lukem Use the SI capitalization for "Hz", "kHz", and "MHz" in comments and strings.
Add a space between numbers and Hz unit.
 1.112 08-Mar-2006  dyoung Change macro names to avoid collisions:

BIT -> __BIT
BITS -> __BITS
 1.111 08-Mar-2006  dyoung Straggler from previous commit: rename macro LSHIFT->SHIFTIN.
 1.110 08-Mar-2006  dyoung Move my bit-twiddling macros to libkern.h from my drivers, where
I had duplicated them. Improve the macros' names. Simplify their
implementation.

A brief description of each macro is below.

BIT(n): Return a bitmask with bit m set, where the least
significant bit is bit 0.

BITS(m, n): Return a bitmask with bits m through n, inclusive,
set. It does not matter whether m>n or m<=n.
The least significant bit is bit 0.

A "bitfield" is a span of consecutive bits defined by a
bitmask, where 1s select the bits in the bitfield. SHIFTIN,
SHIFTOUT, and SHIFTOUT_MASK help read and write bitfields
from device registers.

SHIFTIN(v, mask): Left-shift bits `v' into the bitfield
defined by `mask', and return them. No
side-effects.

SHIFTOUT(v, mask): Extract and return the bitfield selected
by `mask' from `v', right-shifting the
bits so that the rightmost selected bit
is at bit 0. No side-effects.

SHIFTOUT_MASK(mask): Right-shift the bits in `mask' so that
the rightmost non-zero bit is at bit
0. This is useful for finding the
greatest unsigned value that a bitfield
can hold. No side-effects. Note that
SHIFTOUT_MASK(m) = SHIFTOUT(m, m).

Examples:

/*
* Register definitions taken from the RFMD RF3000 manual.
*/
#define RF3000_GAINCTL 0x11 /* TX variable gain control */
#define RF3000_GAINCTL_TXVGC_MASK BITS(7, 2)
#define RF3000_GAINCTL_SCRAMBLER BIT(1)

/*
* Shift the transmit power into the transmit-power field of the
* gain-control register and write it to the baseband processor.
*/
atw_rf3000_write(sc, RF3000_GAINCTL,
SHIFTIN(txpower, RF3000_GAINCTL_TXVGC_MASK));


/*
* Register definitions taken from the ADMtek ADM8211 manual.
*
*/
#define ATW_RXSTAT_OWN BIT(31) /* 1: NIC may fill descriptor */
/* ... */
#define ATW_RXSTAT_DA1 BIT(17) /* DA bit 1, admin'd address */
#define ATW_RXSTAT_DA0 BIT(16) /* DA bit 0, group address */
#define ATW_RXSTAT_RXDR_MASK BITS(15,12) /* RX data rate */
#define ATW_RXSTAT_FL_MASK BITS(11,0) /* RX frame length, last
* descriptor only
*/

/* Extract the frame length from the Rx descriptor's
* status field.
*/
len = SHIFTOUT(rxstat, ATW_RXSTAT_FL_MASK);
 1.109 20-Feb-2006  thorpej branches: 1.109.2; 1.109.4;
Use device_is_active() rather than testing dv_flags for DVF_ACTIVE
directly.
 1.108 19-Feb-2006  dyoung ADM8211 hardware WEP is not working (probably due to a bug in 802.11
Duration / PLCP Length calculation), so temporarily switch to
software WEP, which is working.
 1.107 18-Feb-2006  dyoung When atw_enable is called, power may have been removed and re-applied,
so invalidate the WEP SRAM to force us to write the keys back to
the hardware.
 1.106 18-Feb-2006  dyoung Fix serious regression in AP-client mode: program adapter's BSSID
as we enter the IEEE80211_S_AUTH and IEEE80211_S_ASSOC states, so
that we don't send 802.11 Authentication and Association frames
with BSSID=00:00:00:00:00:00.
 1.105 29-Dec-2005  dyoung branches: 1.105.2; 1.105.4; 1.105.6;
Remove declaration of deleted subroutine, atw_change_ibss().
 1.104 29-Dec-2005  dyoung Extract subroutine is_running().

If ieee80211_ioctl() returns ERESTART, reinitialize interface with
atw_init().

Don't discard the error returned by atw_init() in atw_media_change().
 1.103 29-Dec-2005  dyoung atw_start() need not update IFF_OACTIVE if it hasn't put a new
packet on the transmit ring, so don't do that.
 1.102 29-Dec-2005  dyoung Assert consistency of IFF_OACTIVE / out of sw/hw transmit descriptors
state.
 1.101 29-Dec-2005  dyoung Always tickle the Receive Demand Register (ATW_RDR) after re-enabling
the receiver.
 1.100 29-Dec-2005  dyoung A couple changes to the hardware reset:

Wait for the SWR bit in ATW_PAR to turn to 0, instead of waiting
for the whole register to turn to 0.

For ease of comparison with a reference driver, re-order operations.
 1.99 29-Dec-2005  dyoung Cosmetic: make a three-step staircase out of a four-step staircase.
 1.98 29-Dec-2005  dyoung Revamp state machine:

1 Only stop beacon generation on an ->INIT transition.

2 Merge AUTH and ASSOC cases, they do the same thing (tune
a new channel).

3 Start beacon generation in IBSS, AP, *and* "adhoc demo"
mode.

Cosmetic tweak: rewrap a statement.
 1.97 29-Dec-2005  dyoung Adapt atw(4) to the new IBSS merge idiom, where ieee80211_ibss_merge()
does not return ENETRESET to indicate the station should adopt a
new BSSID, but it triggers a RUN->RUN transition, instead.
 1.96 29-Dec-2005  dyoung Delete atw_media_status(). Let SIOCGIFMEDIA call ieee80211_media_status()
directly for media status.
 1.95 29-Dec-2005  dyoung Use the fragmentation threshold in the ieee80211com.

XXX Need to condition on frame type = data.
 1.94 29-Dec-2005  dyoung In atw_init(), always call atw_write_wep() to write the WEP state
to the h/w. This prevents a spurious call to atw_write_wep() later,
in IEEE80211_S_RUN state, when net80211 times-out ieee80211_nodes.
It is important to avoid a spurious atw_write_wep() call because
in IBSS mode, at least, WEP re-initialization reliably locks up
the transmitter.

XXX There must be a bug in atw_write_wep() that causes it to lock
XXX up the transmitter. I will revisit it later.
 1.93 29-Dec-2005  dyoung In atw(4), use ieee80211_compute_duration() to compute IEEE 802.11
Duration and PLCP Length fields, and delete the abominable
atw_frame_setdurs() subroutine.

Make rtw(4) use the new ieee80211_compute_duration() calling
convention.

Add an ieee80211_key argument to ieee80211_compute_duration() and
lightly constify arguments. Get the crypto header length from the
key argument instead of blithely assuming a WEP header. Add some
inline documentation. Account for data padding (IEEE80211_F_DATAPAD).
 1.92 24-Dec-2005  perry Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.91 23-Nov-2005  dyoung Misc. bug fixes:

1 Reset both IFF_OACTIVE and the transmit watchdog timer in
appropriate places to avoid both wedging the transmit section
and spurious transmit timeouts.

2 Reset IFF_ALLMULTI at the top of atw_filter_setup so that the
NIC will filter the multicast packets we are not interested in
after we come out of promiscuous mode.

3 In atw_txdrain, count drained transmit descriptors to avoid
descriptor exhaustion.
 1.90 18-Nov-2005  skrll Adapt drivers to the new net80211(9).

Most of this is from dyoung@. Thanks!
 1.89 07-Jul-2005  dyoung branches: 1.89.6;
Don't write WEP keys to the chip unless it is enabled.

Suspend and restart the transmit/receive engines while writing WEP
keys.
 1.88 06-Jul-2005  dyoung Historically, an(4), ath(4), atw(4), rtw(4), and wi(4) have printed
out their modes and rates at boot. Revert to the historical
behavior.
 1.87 26-Jun-2005  dyoung branches: 1.87.2;
Do not build AP support if 'options IEEE80211_NO_HOSTAP' is in the
kernel configuration.
 1.86 25-Jun-2005  dyoung Cosmetic: join lines.
 1.85 22-Jun-2005  dyoung Resolve conflicts in importation of 18-May-2005 ath(4) / net80211(9)
from FreeBSD. Introduce compatibility shims (sys/dev/ic/ath_netbsd.[ch],
sys/net80211/ieee80211_netbsd.[ch]). Update drivers (an, atu, atw,
awi, ipw, iwi, rtw, wi) for the new net80211(9) API.
 1.84 27-Feb-2005  perry nuke trailing whitespace
 1.83 31-Jan-2005  thorpej Eliminate use of M_HASFCS.
 1.82 04-Jan-2005  dyoung branches: 1.82.2; 1.82.4;
IBSS-merge clean-up, inspired by some Linux patches from Jon Anderson
(mail@janderson.ca): remove ieee80211_ibss_merge's TSFT argument.
Do the TSFT comparison in the drivers (ath, atw). Remove a lot of
extraneous debug statements from ieee80211_ibss_merge.

Set the ieee80211_node's state to IEEE80211_STA_BSS after it's been
copied to the ic_bss, not before.

In struct ieee80211_node, make the ni_tstamp field a union of a
uint64_t and the 8 TSF octets so that it's easier to compare a
neighbor's TSF with the local TSF.

Log IBSS merges (Greg Troxel's suggestion). Also log IBSS creation.
These are rare and important events that deserve to be logged.
 1.81 27-Dec-2004  mycroft Replace d_plcp_svc with d_residue. The latter is the number of whole
empty/unused octets to fill out the data time slot. The value is constrained
by math to 0 for <= 5.5Mb, 0-1 for 11Mb, and 0-2 for 22Mb. It is used to
signal to the MAC that there is residue.
 1.80 30-Oct-2004  thorpej When adding/deleting multicast addresses, only whack the address
filter if the interface is marked RUNNING.

Fixes kern/27678.
 1.79 10-Aug-2004  dyoung Make the node table into an LRU cache: least-recently used nodes
are at the end of the node queue. Change the reference-counting
discipline: ni->ni_refcnt indicates how many times net80211 has
granted ni to the driver. Every node in the table with ni_refcnt=0
is eligible to be garbage-collected. The mere presence of a node
in the table does not any longer indicate its auth/assoc state;
nodes have a ni_state variable, now. A sysctl,
net.link.ieee80211.maxnodecache, controls the maximum LRU cache
size.

While I am here, patch ieee80211_find_node_for_beacon to do a "best
match" by bssid/ssid/channel, not a "perfect match." This keeps
net80211 from caching duplicate nodes in the table.
 1.78 28-Jul-2004  dyoung branches: 1.78.2;
Vastly simplify ieee80211_ibss_merge, eliminating the needless
callbacks. Change the reference IBSS-merge implementation in atw
to match.
 1.77 27-Jul-2004  dyoung Cancel scan callout when the device detaches. Pointed out by Todd
Miller.
 1.76 24-Jul-2004  dyoung Pull the IBSS merge logic out of atw and into net80211, since ath
will eventually share it.

In the IBSS merge logic, check conditions in a different order so
that they run faster in the common case---no merge. Fix the
rate-limiting on the debug outputs (enabled by IFF_LINK0).
 1.75 24-Jul-2004  dyoung Doh, we really do need to set bit ATW_NAR_MM in ATW_NAR, or else
no multicast packets are let through.
 1.74 24-Jul-2004  dyoung Add atw_nar_init, atw_next_scan prototypes (thanks Todd Miller)
and sort prototypes.

In-line atw_tsft.
 1.73 23-Jul-2004  mycroft Cleanup of ieee80211_node from madwifi:
* Don't use ifp pointers; use ieee80211com.
* Implement the locking macros that are used under FreeBSD and Linux.
 1.72 23-Jul-2004  mycroft Fix mismerge.
 1.71 23-Jul-2004  mycroft IEEE80211_F_WEPON -> IEEE80211_F_PRIVACY
 1.70 23-Jul-2004  dyoung Instrument atw(4) delays so that I can experiment and shorten the
conservative delays that I derived from the reference driver.
 1.69 23-Jul-2004  dyoung Print and store Cardbus/PCI revision number.

Begin conditioning device configuration on revision number. Four
revisions are known:

1.1/1.5 -> ADM8211A,
2.0 -> ADM8211B,
3.0 -> ADM8211C.

The B and C parts, which are not supported yet, have AP capability.
 1.68 23-Jul-2004  dyoung Fix IBSS merges in atw(4).
 1.67 23-Jul-2004  dyoung Use the new SRAM size constants.
 1.66 16-Jul-2004  dyoung The RSSI field in the Rx descriptor is the unadulterated content
of the DIVCTL/RSSI register on the RF3000 baseband. Mask all but
the RSSI bits.
 1.65 15-Jul-2004  dyoung Insist that callers use atw_write_sram to copy even-length buffers
to even offsets in the ADM8211 SRAM.

assert->KASSERT
 1.64 15-Jul-2004  dyoung Totally revamp device initialization using clue from the reference
driver. I also have re-organized the code a lot.
 1.63 15-Jul-2004  dyoung Totally revamp device resets using clue from the reference driver.
 1.62 15-Jul-2004  dyoung Make atw_read_srom static.
 1.61 15-Jul-2004  dyoung Re-organize, add new, and remove old prototypes.
 1.60 15-Jul-2004  dyoung Once again, stop calling the bus front-end's interrupt-acknowledgement
callback.
 1.59 15-Jul-2004  dyoung Totally revamp the way that I program the synthesizer and baseband.
 1.58 15-Jul-2004  dyoung Take the paranoia out of the code for writing baseband registers.
 1.57 15-Jul-2004  dyoung Simplify the Rx filter setup, following the AL981 code in tlp(4).
 1.56 15-Jul-2004  dyoung Countdown correctly to the Target Beacon Transmission Time.
Borrowing an idea from the reference driver, use no 64-bit arithmetic.
 1.55 15-Jul-2004  dyoung In atw_start_beacon, set CAP0 as well as BCNT and CAP1.
 1.54 15-Jul-2004  dyoung Simplify IBSS merge code.
 1.53 15-Jul-2004  dyoung Only write the SSID buffer to the ADM8211 SRAM up to the end of
the SSID, not up to the end of the buffer. Given the (too
conservative?) delays involved, this should save some time when we
join a new network.
 1.52 15-Jul-2004  dyoung Change the order in which I write the BSSID registers on the ADM8211,
to match the reference driver. This probably does not make any
functional difference.
 1.51 15-Jul-2004  dyoung Set up the Tx descriptor ring more safely. Fix an endianness bug.
"It's a wonder this ever worked." (Actually, it's not.)
 1.50 15-Jul-2004  dyoung Re-synchronize TSFT after an IBSS merge.
 1.49 15-Jul-2004  dyoung Delay for tens of milliseconds lot after writing the Network Access
Register. I am slavishly imitating the reference driver, here.
I will come back and lower the delays later.
 1.48 15-Jul-2004  dyoung In the transmit interrupt handler, do not unnecessarily synchronize
all the descriptors for a buffer chain. Just synchronize the last
one, which has the interesting stuff.

I still synchronize all the descriptors for the buffer chain if
super-verbose debugging is enabled, since the driver will print
all the descriptors for the chain.
 1.47 15-Jul-2004  dyoung Remove a less-than-helpful comment.
 1.46 15-Jul-2004  dyoung Clamp the length of a received packet, just in case the chip lies.
 1.45 15-Jul-2004  dyoung When super-verbose debugging is enabled, convert Rx descriptors'
endianness before printing them.
 1.44 15-Jul-2004  dyoung Delete some dead code.

Don't call back into the bus-specific code for resets any longer.
It does not seem to be necessary.
 1.43 15-Jul-2004  dyoung During scans, initialize the BSSID to ff:ff:ff:ff:ff:ff before
sending the first probe request.
 1.42 15-Jul-2004  dyoung Clear dead code out of atw_clear_sram.
 1.41 15-Jul-2004  dyoung Don't send data packets until the interface is in state RUN. This
stops ARP and IPv6 Neighbor Discovery packets from trickling out
the interface before it is time.
 1.40 15-Jul-2004  dyoung I'm not treating the lost beacon count specially any more. It is
kind of a dumb way to track the link condition, anyway....
 1.39 15-Jul-2004  dyoung Rid atw of some dead code and some test instrumentation.
 1.38 15-Jul-2004  dyoung In ad hoc mode, don't set the mysterious EA bit in the Network
Access Register. ADMtek's reference driver does not use it at all,
and it does not seem to make any difference whether I leave it in
or take it out.
 1.37 23-Jun-2004  dyoung Only drain the transmit queue if we are idling the transmit section.
 1.36 23-Jun-2004  dyoung After we wait for the MAC's transmit section to idle, drain the
transmit queue and cancel the watchdog timer. This ends the annoying
"atw0: transmit timeout" messages that disrupted my WiFi tonight.
 1.35 23-Jun-2004  dyoung Fix a commit-o: handle all cases in the switch-statement.
 1.34 23-Jun-2004  dyoung Don't skip the reset! atw was not getting reset at device attachment.
atw seems to work better now that it gets this right: for one thing,
the RSSI can be seen to change as I walk around the office with my
laptop.

Thanks to Todd C. Miller for pointing out my mistake.
 1.33 23-Jun-2004  dyoung Fix typo: change ATW_RFTYPE_RFMD and family to ATW_BBPTYPE_RFMD.

This does not make any functional difference: each manufacturer's
RF type-number is the same as its BBP type-number.
 1.32 06-Jun-2004  dyoung In ad hoc mode, ignore the MAC's link up/down indication, since it
does not appear to be reliable.
 1.31 05-Jun-2004  dyoung No need to detect and exit on short 802.11 packets, since
ieee80211_input will do that (and tap the packet).
 1.30 31-May-2004  dyoung It's only necessary to set do_encrypt in one place, so do that.
 1.29 31-May-2004  dyoung Cosmetic: fix comment typo, change bit-test style.
 1.28 31-May-2004  dyoung Name the shift, txpower << 2 -> LSHIFT(txpower, RF3000_GAINCTL_TXVGC_MASK).
 1.27 31-May-2004  dyoung Wrap a line. Remove a useless comment.
 1.26 31-May-2004  dyoung Describe Tx/Rx state a little better using clue from the ADM8211C/CR
datasheet.
 1.25 31-May-2004  dyoung Use bpf_mtap2.
 1.24 17-Feb-2004  dyoung branches: 1.24.2;
Move the RF Microdevices RF3000 & Silicon Laboratories SI4126/SI4136
register sets into their own header files for re-use by future
drivers.
 1.23 29-Jan-2004  dyoung Get rid of __P.
 1.22 29-Jan-2004  dyoung Only pass 802.11 frames up if they are greater than the minimum
size or else if monitor mode is enabled.
 1.21 29-Jan-2004  dyoung Avoid division by zero when computing the link-lost lost-beacons
threshold.
 1.20 29-Jan-2004  dyoung Deal with the RSSI as an unsigned value.
 1.19 13-Jan-2004  dyoung NetBSD's KASSERT takes just one argument while FreeBSD's takes two,
so I have added IASSERT(cond, complaint) to the compatibility header
file and s/KASSERT/IASSERT/'d.
 1.18 10-Jan-2004  dyoung Rounding to the nearest multiple of 2 with roundup(constant, 2) is
easier to read than `constant + 1'.
 1.17 10-Jan-2004  dyoung In atw_rf3000_tune, enable I/O with the modem and RF front-end
"just in time" instead of at the top of the function.
 1.16 10-Jan-2004  dyoung Do not set IEEE80211_F_IBSSON in hostap mode. Treat hostap-mode
when the link condition changes by returning.

Note that hostap mode still does not work in atw, and ADMtek has
told me that the hardware will not support it, but I remain hopeful.
 1.15 10-Jan-2004  dyoung Report received-early interrupt with a debug printf.

Print the Serial EEPROM and the MAC address it contains when
atw_debug > 0, because atw_debug > 1 is a little too strict.
 1.14 10-Jan-2004  dyoung Misc. cosmetic changes.

Add a debug printf to the input path.
 1.13 10-Jan-2004  dyoung Use new docs provided by RFMD to give some meaning to
previously-undocumented registers and magic numbers on the RF3000
baseband.
 1.12 16-Nov-2003  dyoung Add data-link type DLT_IEEE802_11_RADIO to wi and atw. DLT_IEEE802_11_RADIO
lets you monitor radio stats like received signal strength, which
diversity antenna was used, channel/frequency, modulation, and data
rate.
 1.11 02-Nov-2003  dyoung No need to check which state we're changing FROM when we deactivate
the scan callout.
 1.10 02-Nov-2003  dyoung Get a clue from ath(4) and move the ieee80211_new_state() calls in
atw_init to one place.
 1.9 02-Nov-2003  dyoung Fix thinko that breaks IBSS merges in atw(4). sc->sc_opmode !=
ic->ic_opmode!
 1.8 02-Nov-2003  dyoung Use ieee80211_find_rxnode to attribute Rx packets to the write
ieee80211_node. This reduces code duplication. It will help us
support passive scanning and rate adaptation.
 1.7 25-Oct-2003  christos make this compile again. I should really rename the FreeBSD KASSERT to
KASSERT2 or something.
 1.6 25-Oct-2003  christos KASSERT takes 2 arguments here.
 1.5 25-Oct-2003  christos Fix uninitialized variable warnings
 1.4 16-Oct-2003  dyoung Cosmetic change: shorten 6 lines to 2.
 1.3 13-Oct-2003  dyoung Adapt atw(4) to the new 802.11 layer.

Simplify atw_start, atw_newstate.

Synchronize access to atw_start by bracketing the call to
ieee80211_next_scan in atw_next_scan with splnet()/splx().
 1.2 20-Sep-2003  dyoung Allow channels 1-14 in MMK2, for real. Fixes PR 22530 from
FUKAUMI Naoki.
 1.1 06-Jul-2003  dyoung Oops. Add the atw(4) sources, too.
 1.24.2.2 27-Jun-2004  jdc branches: 1.24.2.2.2;
Pull up revisions 1.36-1.37 (requested by dyoung in ticket #552).

After we wait for the MAC's transmit section to idle, drain the
transmit queue and cancel the watchdog timer. This ends the annoying
"atw0: transmit timeout" messages that disrupted my WiFi tonight.


Only drain the transmit queue if we are idling the transmit section.
 1.24.2.1 27-Jun-2004  jdc Pull up revision 1.34 (requested by dyoung in ticket #551).

Don't skip the reset! atw was not getting reset at device attachment.
atw seems to work better now that it gets this right: for one thing,
the RSSI can be seen to change as I walk around the office with my
laptop.

Thanks to Todd C. Miller for pointing out my mistake.
 1.24.2.2.2.1 24-Jan-2005  he Pull up revision 1.80 (requested by thorpej in ticket #939):
When adding or deleting multicast addresses, only change
the address filter if the interface is marked RUNNING.
Fixes PR#27678.
 1.78.2.11 11-Dec-2005  christos Sync with head.
 1.78.2.10 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.78.2.9 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.78.2.8 04-Feb-2005  skrll Sync with HEAD.
 1.78.2.7 17-Jan-2005  skrll Sync with HEAD.
 1.78.2.6 02-Nov-2004  skrll Sync with HEAD.
 1.78.2.5 21-Sep-2004  skrll Fix the sync with head I botched.
 1.78.2.4 18-Sep-2004  skrll Sync with HEAD.
 1.78.2.3 12-Aug-2004  skrll Sync with HEAD.
 1.78.2.2 03-Aug-2004  skrll Sync with HEAD
 1.78.2.1 28-Jul-2004  skrll file atw.c was added on branch ktrace-lwp on 2004-08-03 10:46:11 +0000
 1.82.4.2 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.82.4.1 12-Feb-2005  yamt sync with head.
 1.82.2.1 29-Apr-2005  kent sync with -current
 1.87.2.6 17-Mar-2008  yamt sync with head.
 1.87.2.5 07-Dec-2007  yamt sync with head
 1.87.2.4 27-Oct-2007  yamt sync with head.
 1.87.2.3 03-Sep-2007  yamt sync with head.
 1.87.2.2 30-Dec-2006  yamt sync with head.
 1.87.2.1 21-Jun-2006  yamt sync with head.
 1.89.6.2 29-Nov-2005  yamt sync with head.
 1.89.6.1 22-Nov-2005  yamt sync with head.
 1.105.6.1 22-Apr-2006  simonb Sync with head.
 1.105.4.1 09-Sep-2006  rpaulo sync with head
 1.105.2.1 01-Mar-2006  yamt sync with head.
 1.109.4.1 19-Apr-2006  elad sync with head.
 1.109.2.4 03-Sep-2006  yamt sync with head.
 1.109.2.3 11-Apr-2006  yamt sync with head
 1.109.2.2 01-Apr-2006  yamt sync with head.
 1.109.2.1 13-Mar-2006  yamt sync with head.
 1.114.2.2 24-May-2006  tron Merge 2006-05-24 NetBSD-current into the "peter-altq" branch.
 1.114.2.1 28-Mar-2006  tron Merge 2006-03-28 NetBSD-current into the "peter-altq" branch.
 1.119.4.2 10-Dec-2006  yamt sync with head.
 1.119.4.1 22-Oct-2006  yamt sync with head
 1.119.2.2 12-Jan-2007  ad Sync with head.
 1.119.2.1 18-Nov-2006  ad Sync with head.
 1.125.4.1 12-Mar-2007  rmind Sync with HEAD.
 1.126.4.1 11-Jul-2007  mjf Sync with head.
 1.126.2.3 23-Oct-2007  ad Sync with head.
 1.126.2.2 09-Oct-2007  ad Sync with head.
 1.126.2.1 01-Jul-2007  ad Adapt to callout API change.
 1.127.8.3 23-Mar-2008  matt sync with HEAD
 1.127.8.2 09-Jan-2008  matt sync with HEAD
 1.127.8.1 06-Nov-2007  matt sync with HEAD
 1.127.6.4 21-Nov-2007  joerg Sync with HEAD.
 1.127.6.3 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.127.6.2 02-Oct-2007  joerg Sync with HEAD.
 1.127.6.1 03-Sep-2007  jmcneill Sync with HEAD.
 1.127.2.1 03-Sep-2007  skrll Sync with HEAD.
 1.128.2.1 06-Oct-2007  yamt sync with head.
 1.129.2.2 18-Nov-2007  bouyer Sync with HEAD
 1.129.2.1 25-Oct-2007  bouyer Sync with HEAD.
 1.130.2.1 19-Nov-2007  mjf Sync with HEAD.
 1.134.14.4 17-Jan-2009  mjf Sync with HEAD.
 1.134.14.3 28-Sep-2008  mjf Sync with HEAD.
 1.134.14.2 02-Jun-2008  mjf Sync with HEAD.
 1.134.14.1 03-Apr-2008  mjf Sync with HEAD.
 1.134.10.1 24-Mar-2008  keiichi sync with head.
 1.137.4.6 11-Aug-2010  yamt sync with head.
 1.137.4.5 11-Mar-2010  yamt sync with head
 1.137.4.4 16-Sep-2009  yamt sync with head
 1.137.4.3 20-Jun-2009  yamt sync with head
 1.137.4.2 04-May-2009  yamt sync with head.
 1.137.4.1 16-May-2008  yamt sync with head.
 1.137.2.1 18-May-2008  yamt sync with head.
 1.139.6.2 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.139.6.1 19-Oct-2008  haad Sync with HEAD.
 1.139.4.1 18-Jul-2008  simonb Sync with head.
 1.139.2.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.140.2.1 19-Jan-2009  skrll Sync with HEAD.
 1.142.2.1 23-Jul-2009  jym Sync with HEAD.
 1.149.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.150.2.3 21-Apr-2011  rmind sync with head
 1.150.2.2 05-Mar-2011  rmind sync with head
 1.150.2.1 30-May-2010  rmind sync with head
 1.152.2.1 06-Jun-2011  jruoho Sync with HEAD.
 1.153.18.1 18-May-2014  rmind sync with head
 1.153.14.2 03-Dec-2017  jdolecek update from HEAD
 1.153.14.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.153.4.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.156.6.4 05-Feb-2017  skrll Sync with HEAD
 1.156.6.3 09-Jul-2016  skrll Sync with HEAD
 1.156.6.2 29-May-2016  skrll Sync with HEAD
 1.156.6.1 19-Mar-2016  skrll Sync with HEAD
 1.160.4.1 21-Apr-2017  bouyer Sync with HEAD
 1.160.2.1 20-Mar-2017  pgoyette Sync with HEAD
 1.161.6.1 10-Dec-2017  snj Pull up following revision(s) (requested by msaitoh in ticket #427):
sys/arch/amiga/dev/if_bah_zbus.c: 1.17
sys/arch/arm/broadcom/bcm53xx_eth.c: 1.30
sys/arch/powerpc/booke/dev/pq3etsec.c: 1.32
sys/arch/usermode/dev/if_veth.c: 1.9
sys/dev/ic/an.c: 1.66
sys/dev/ic/athn.c: 1.17
sys/dev/ic/atw.c: 1.162
sys/dev/ic/bwi.c: 1.33
sys/dev/ic/dwc_gmac.c: 1.41-1.42
sys/dev/ic/malo.c: 1.10
sys/dev/ic/rt2560.c: 1.31
sys/dev/ic/rt2661.c: 1.36
sys/dev/ic/rt2860.c: 1.29
sys/dev/ic/rtw.c: 1.127
sys/dev/ic/rtwvar.h: 1.46
sys/dev/ic/smc90cx6.c: 1.71
sys/dev/ic/smc90cx6var.h: 1.12
sys/dev/ic/wi.c: 1.244
sys/dev/pci/if_ipw.c: 1.66
sys/dev/pci/if_iwi.c: 1.104
sys/dev/pci/if_iwm.c: 1.76
sys/dev/pci/if_iwn.c: 1.86
sys/dev/pci/if_rtwn.c: 1.13
sys/dev/pci/if_wm.c: 1.541
sys/dev/pci/if_wpi.c: 1.79
sys/dev/pci/ixgbe/ixgbe.c: 1.106
sys/dev/pci/ixgbe/ixv.c: 1.73 via patch
sys/dev/pcmcia/if_malo_pcmcia.c: 1.15
sys/dev/scsipi/if_se.c: 1.95
sys/dev/usb/if_upl.c: 1.60
sys/net/if.c: 1.396
sys/net/if.h: 1.241
sys/net/if_arc.h: 1.23
sys/net/if_arcsubr.c: 1.78
sys/net/if_bridge.c: 1.136-1.137
sys/net/if_etherip.c: 1.39
sys/net/if_faith.c: 1.56
sys/net/if_gif.c: 1.131
sys/net/if_loop.c: 1.96
sys/net/if_mpls.c: 1.30
sys/net/if_pppoe.c: 1.129
sys/net/if_srt.c: 1.27
sys/net/if_stf.c: 1.102
sys/net/if_tap.c: 1.100
sys/net/if_vlan.c: 1.105
sys/netinet/ip_carp.c: 1.91
sys/rump/net/lib/libshmif/if_shmem.c: 1.73-1.74
sys/rump/net/lib/libvirtif/if_virt.c: 1.55-1.56
if_initalize() and if_attach() failed when resource allocation failed
(e.g. allocating softint). Without this change, it panics. It's bad because
resource shortage really occured when a lot of pseudo interface is created.
To avoid this problem, don't panic and change return value of if_initialize()
and if_attach() to int. Caller fanction will be recover from error cleanly by
checking the return value.
Return if bah_attach_subr() failed.
If if_attach() failed in the attach function, return.
- If if_initialize() failed in the attach function, free resources and return.
- Add some missing frees in bridge_clone_destroy().
- KNF
If error occured in bcmeth_ccb_attach(), free resources and return.
If error occured in pq3etsec_attach(), free resources and return.
If error occured in the attach function, free resources and return.
- If if_initialize() failed in athn_attach(), free resources and return.
- Add missing pmf_event_deregister() in athn_detach().
- Free resources correctly on some errors in atw_attach().
- Use apint*() insread of printf() in the attach function.
If if_initialize() failed in the attach function, return.
- If if_initialize() failed in the attach function, free resources and return.
- Add missing dwc_gmac_free_dma_rings() and mutex_destroy() when attach
failed.
- If if_initialize() failed in the attach function, free resources and return.
- ifp is always not NULL in iwi_detach(). Check correctly with ifp->if_softc.
- If if_initialize() failed in the attach function, free resources and return.
- Fix error path in the attach function correctly.
If if_initialize() failed in the attach function, free resources and return.
If if_attach() failed in the attach function, free resources and return.
- If if_initialize() failed in the attach function, free resources and return.
- KNF
- If if_attach() failed in the attach function, free resources and return.
- KNF
Fix compile error.
Fix compile error.
We don't need '&mii', but just 'mii' for mii_detach().
Don't free sc_rthash twice
 1.162.2.2 28-Jul-2018  pgoyette Sync with HEAD
 1.162.2.1 02-May-2018  pgoyette Synch with HEAD
 1.164.2.3 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.164.2.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.164.2.1 10-Jun-2019  christos Sync with HEAD
 1.169.2.1 29-Feb-2020  ad Sync with head.
 1.170.10.1 17-Jun-2021  thorpej Sync w/ HEAD.
 1.23 06-Feb-2009  dyoung Define some bitfields that come from a reference driver.
 1.22 08-Sep-2008  gmcgarry branches: 1.22.2;
Replace most gcc-specific __attribute__ uses with BSD-style sys/cdef.h
preprocessor macros.
 1.21 12-Jun-2008  dyoung branches: 1.21.2;
Elaborate on a comment.
 1.20 04-May-2008  martin branches: 1.20.2; 1.20.4;
Move to standard TNF 2 clause license
 1.19 16-Nov-2007  dyoung branches: 1.19.14; 1.19.16; 1.19.18;
Cosmetic: rename some variables and constants. Move some constants
from atw.c to atwreg.h.
 1.18 16-Nov-2007  dyoung Replace some magic numbers with HFA3861A register names.

Do not alias the Rx descriptor word ar_ctl to ar_rssi with a #define.
Instead, call the member ar_ctlrssi.

Convert the ugly macro ATW_RXDESC_INIT() to an inline subroutine,
atw_rxdesc_init().

Do not load an empty IEEE80211_RADIOTAP_FLAGS field into the Tx
radiotap header.
 1.17 09-Jan-2007  dyoung branches: 1.17.18; 1.17.20; 1.17.24; 1.17.26;
Let the compiler know it should both pack the members of the rx/tx
descriptors without any padding between, and use 4-byte alignment.
 1.16 26-Nov-2006  dyoung Add 'volatile' to rx/tx descriptor fields.
 1.15 31-Aug-2006  dyoung branches: 1.15.2; 1.15.4;
Per discussion on tech-kern and tech-userlevel, move the bit-twiddling
macros, __BIT, __BITS, SHIFTIN, SHIFTOUT, and __arraycount() from
lib/libkern/libkern.h to sys/cdefs.h. Add a __-prefix to SHIFTIN
and SHIFTOUT, and add a manual page for the bit-twiddling macros,
bits(3).

Make the __BIT and __BITS macros "widthless," as best I can, by
changing their type to uintmax_t from uint32_t. XXX The manual
page lags this change by a bit.

Define __PRIxBIT and __PRIxBITS printf(3) format strings.
 1.14 08-Mar-2006  dyoung Change macro names to avoid collisions:

BIT -> __BIT
BITS -> __BITS
 1.13 08-Mar-2006  dyoung Move my bit-twiddling macros to libkern.h from my drivers, where
I had duplicated them. Improve the macros' names. Simplify their
implementation.

A brief description of each macro is below.

BIT(n): Return a bitmask with bit m set, where the least
significant bit is bit 0.

BITS(m, n): Return a bitmask with bits m through n, inclusive,
set. It does not matter whether m>n or m<=n.
The least significant bit is bit 0.

A "bitfield" is a span of consecutive bits defined by a
bitmask, where 1s select the bits in the bitfield. SHIFTIN,
SHIFTOUT, and SHIFTOUT_MASK help read and write bitfields
from device registers.

SHIFTIN(v, mask): Left-shift bits `v' into the bitfield
defined by `mask', and return them. No
side-effects.

SHIFTOUT(v, mask): Extract and return the bitfield selected
by `mask' from `v', right-shifting the
bits so that the rightmost selected bit
is at bit 0. No side-effects.

SHIFTOUT_MASK(mask): Right-shift the bits in `mask' so that
the rightmost non-zero bit is at bit
0. This is useful for finding the
greatest unsigned value that a bitfield
can hold. No side-effects. Note that
SHIFTOUT_MASK(m) = SHIFTOUT(m, m).

Examples:

/*
* Register definitions taken from the RFMD RF3000 manual.
*/
#define RF3000_GAINCTL 0x11 /* TX variable gain control */
#define RF3000_GAINCTL_TXVGC_MASK BITS(7, 2)
#define RF3000_GAINCTL_SCRAMBLER BIT(1)

/*
* Shift the transmit power into the transmit-power field of the
* gain-control register and write it to the baseband processor.
*/
atw_rf3000_write(sc, RF3000_GAINCTL,
SHIFTIN(txpower, RF3000_GAINCTL_TXVGC_MASK));


/*
* Register definitions taken from the ADMtek ADM8211 manual.
*
*/
#define ATW_RXSTAT_OWN BIT(31) /* 1: NIC may fill descriptor */
/* ... */
#define ATW_RXSTAT_DA1 BIT(17) /* DA bit 1, admin'd address */
#define ATW_RXSTAT_DA0 BIT(16) /* DA bit 0, group address */
#define ATW_RXSTAT_RXDR_MASK BITS(15,12) /* RX data rate */
#define ATW_RXSTAT_FL_MASK BITS(11,0) /* RX frame length, last
* descriptor only
*/

/* Extract the frame length from the Rx descriptor's
* status field.
*/
len = SHIFTOUT(rxstat, ATW_RXSTAT_FL_MASK);
 1.12 11-Dec-2005  christos branches: 1.12.4; 1.12.6; 1.12.8; 1.12.10;
merge ktrace-lwp.
 1.11 27-Feb-2005  perry branches: 1.11.4;
nuke trailing whitespace
 1.10 23-Jul-2004  dyoung branches: 1.10.2; 1.10.6; 1.10.8;
Improve register definitions and slightly demystify some magic
numbers.
 1.9 15-Jul-2004  dyoung Refine some register definitions.
 1.8 31-May-2004  dyoung Define several new registers for the ADM8211C/CR parts. Improve
old register descriptions.
 1.7 17-Feb-2004  dyoung Move the RF Microdevices RF3000 & Silicon Laboratories SI4126/SI4136
register sets into their own header files for re-use by future
drivers.
 1.6 29-Jan-2004  dyoung Fix whitespace in Si4126 register definitions.
 1.5 29-Jan-2004  dyoung Wrap the bit-twiddling macros so that they don't get redefined if
more than one header file defines them.
 1.4 10-Jan-2004  dyoung Use new docs provided by RFMD to give some meaning to
previously-undocumented registers and magic numbers on the RF3000
baseband.
 1.3 07-Dec-2003  dyoung Make the MASK_TO_SHIFT expression less "tall." Hopefully helps
work-around the gcc bug reported by Erik Osheim.
 1.2 13-Oct-2003  dyoung Why don't I make up my mind? No need to left-shift the country
codes when I right-shift the country-code register! Fixes a bug
reported by Dan Carosone: regulatory domain "ETSI" registered as
domain "Spain/Other", so he could only tune channels 10 and 11.
 1.1 06-Jul-2003  dyoung Oops. Add the atw(4) sources, too.
 1.10.8.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.10.6.1 29-Apr-2005  kent sync with -current
 1.10.2.5 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.10.2.4 21-Sep-2004  skrll Fix the sync with head I botched.
 1.10.2.3 18-Sep-2004  skrll Sync with HEAD.
 1.10.2.2 03-Aug-2004  skrll Sync with HEAD
 1.10.2.1 23-Jul-2004  skrll file atwreg.h was added on branch ktrace-lwp on 2004-08-03 10:46:11 +0000
 1.11.4.4 07-Dec-2007  yamt sync with head
 1.11.4.3 26-Feb-2007  yamt sync with head.
 1.11.4.2 30-Dec-2006  yamt sync with head.
 1.11.4.1 21-Jun-2006  yamt sync with head.
 1.12.10.1 19-Apr-2006  elad sync with head.
 1.12.8.2 03-Sep-2006  yamt sync with head.
 1.12.8.1 13-Mar-2006  yamt sync with head.
 1.12.6.1 22-Apr-2006  simonb Sync with head.
 1.12.4.1 09-Sep-2006  rpaulo sync with head
 1.15.4.1 10-Dec-2006  yamt sync with head.
 1.15.2.1 12-Jan-2007  ad Sync with head.
 1.17.26.1 19-Nov-2007  mjf Sync with HEAD.
 1.17.24.1 18-Nov-2007  bouyer Sync with HEAD
 1.17.20.1 09-Jan-2008  matt sync with HEAD
 1.17.18.1 21-Nov-2007  joerg Sync with HEAD.
 1.19.18.2 04-May-2009  yamt sync with head.
 1.19.18.1 16-May-2008  yamt sync with head.
 1.19.16.2 17-Jun-2008  yamt sync with head.
 1.19.16.1 18-May-2008  yamt sync with head.
 1.19.14.3 28-Sep-2008  mjf Sync with HEAD.
 1.19.14.2 29-Jun-2008  mjf Sync with HEAD.
 1.19.14.1 02-Jun-2008  mjf Sync with HEAD.
 1.20.4.1 18-Jun-2008  simonb Sync with head.
 1.20.2.2 24-Sep-2008  wrstuden Merge in changes between wrstuden-revivesa-base-2 and
wrstuden-revivesa-base-3.
 1.20.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.21.2.1 19-Oct-2008  haad Sync with HEAD.
 1.22.2.1 03-Mar-2009  skrll Sync with HEAD.
 1.40 05-Oct-2019  mrg remove __packed attribute from struct ieee80211_radiotap_header
and all the structures that include it.

this should not change anything while avoiding packed vs alignment
warnings from GCC 8, and potentially pessimised code generation
due to the packed marker (there are no misaligned members, just
that the per-device parts may end unaligned.)

all consumers of these members are done from the properly aligned
packet members directly, or, as a union with a 64 byte member,
also properly aligned. codegen didn't appear to change, except
for the definition of sizeof(struct driver_[rt]x_radiotap_header)
in debug info, which is not directly used anywhere.
 1.39 19-Apr-2018  christos branches: 1.39.2;
s/static inline/static __inline/g for consistency.
 1.38 02-Feb-2017  nonaka branches: 1.38.12;
wlan interfaces make interrupt routine running on softint context.

see http://mail-index.netbsd.org/tech-kern/2016/12/06/msg021281.html

tested device:
* ath at pci: AR5212, AR5424
* athn at pci: AR9287
* ipw at pci: 2100BG
* iwi at pci: 2915ABG
* iwm at pci: 3165, 7260, 8260
* iwn at pci: 4945, 6235
* ral at pci: RT2560
* rtwn at pci: RTL8192CE
 1.37 14-Mar-2010  dyoung branches: 1.37.20; 1.37.38; 1.37.42; 1.37.46;
Use device_suspensor_t instead of struct device_suspensor.
 1.36 24-Feb-2010  dyoung A pointer typedef entails trading too much flexibility to declare const
and non-const types, and the kernel uses both const and non-const
PMF qualifiers and device suspensors, so change the pmf_qual_t and
device_suspensor_t typedefs from "pointers to const" to non-pointer,
non-const types.
 1.35 17-Jan-2010  pooka branches: 1.35.2;
Forward declare struct bpf_if and use that as the type for bpf_if
instead of "void *". Buys us oo times the type-safety for 0 times
the price.
(no functional change)
 1.34 08-Jan-2010  dyoung Expand PMF_FN_* macros.
 1.33 16-Sep-2009  dyoung In pmf(9), improve the implementation of device self-suspension
and make suspension by self, by drvctl(8), and by ACPI system sleep
play nice together. Start solidifying some temporary API changes.

1. Extract a new header file, <sys/device_if.h>, from <sys/device.h> and
#include it from <sys/pmf.h> instead of <sys/device.h> to break the
circular dependency between <sys/device.h> and <sys/pmf.h>.

2. Introduce pmf_qual_t, an aggregate of qualifications on a PMF
suspend/resume call. Start to replace instances of PMF_FN_PROTO,
PMF_FN_ARGS, et cetera, with a pmf_qual_t.

3. Introduce the notion of a "suspensor," an entity that holds a
device in suspension. More than one suspensor may hold a device
at once. A device stays suspended as long as at least one
suspensor holds it. A device resumes when the last suspensor
releases it.

Currently, the kernel defines three suspensors,

3a the system-suspensor: for system suspension, initiated
by 'sysctl -w machdep.sleep_state=3', by lid closure, by
power-button press, et cetera,

3b the drvctl-suspensor: for device suspension by /dev/drvctl
ioctl, e.g., drvctl -S sip0.

3c the system self-suspensor: for device drivers that suspend
themselves and their children. Several drivers for network
interfaces put the network device to sleep while it is not
administratively up, that is, after the kernel calls if_stop(,
1). The self-suspensor should not be used directly. See
the description of suspensor delegates, below.

A suspensor can have one or more "delegates". A suspensor can
release devices that its delegates hold suspended. Right now,
only the system self-suspensor has delegates. For each device
that a self-suspending driver attaches, it creates the device's
self-suspensor, a delegate of the system self-suspensor.

Suspensors stop a system-wide suspend/resume cycle from waking
devices that the operator put to sleep with drvctl before the cycle.
They also help self-suspension to work more simply, safely, and in
accord with expectations.

4. Add the notion of device activation level, devact_level_t,
and a routine for checking the current activation level,
device_activation(). Current activation levels are DEVACT_LEVEL_BUS,
DEVACT_LEVEL_DRIVER, and DEVACT_LEVEL_CLASS, which respectively
indicate that the device's bus is active, that the bus and device are
active, and that the bus, device, and the functions of the device's
class (network, audio) are active.

Suspend/resume calls can be qualified with a devact_level_t.
The power-management framework treats a devact_level_t that
qualifies a device suspension as the device's current activation
level; it only runs hooks to reduce the activation level from
the presumed current level to the fully suspended state. The
framework treats a devact_level_t qualifying device resumption
as the target activation level; it only runs hooks to raise the
activation level to the target.

5. Use pmf_qual_t, devact_level_t, and self-suspensors in several
drivers.

6. Temporarily add an unused power-management workqueue that I will
remove or replace, soon.
 1.32 13-Sep-2009  dyoung Experimental support for fragmentation and RTS/CTS.

Delete unused atw_voodoo and constants.

Export Tx/Rx statistics with evcnt(9).

Correct the Short Inter-Frame Space (SIFS) that we write to ADM8211's
registers; I do not recall if that corrected the SIFS that I observed
"on the air." Use the constant IEEE80211_DUR_DS_EIFS to configure
the ADM8211's EIFS, instead of writing the same "magic" number,
0x64, that my reference driver wrote.

Do not clear OACTIVE in atw_init(), because atw_stop() cleared it
previously by calling atw_txdrain().

Use the net80211 short-preamble flag and instead of ATW_SHPREAMBLE.

Add an ADM8211 workaround from the reference driver, atw_workaround1(),
but don't compile it right now.

In at_intr(), don't stop processing the interrupt status after
restarting the receive ring, but process Tx interrupt status. If
a packet's Tx lifetime is exceeded, reinitialize the device to get
packets moving again. If the Tx FIFO underflows, restart the
transmitter, not the receiver!

Avoid losing synchronization with the Rx ring by replicating one
of Charles Hannum's fixes to rtw(4) here: receiving a management
packet may, as a side-effect, reset the Rx ring, so refer to the
softc's Rx ring pointer, sc_rxptr, every time through the loop in
atw_rxintr(), instead of refering to a pointer on the stack, i.

Re-synchronize DMA after reading the OWN bit on an Rx/Tx descriptor.
XXX This needs more work.

Reset sc_tx_timer as Tx descriptors are reclaimed from the device.

Shorten staircases in atw_watchdog().

Remove from softc an unused member, sc_intr_ack.
 1.31 12-May-2009  cegger struct device * -> device_t, no functional changes intended.
 1.30 09-Jul-2008  joerg branches: 1.30.8;
- device/softc split
 1.29 04-May-2008  martin branches: 1.29.2; 1.29.4; 1.29.6;
Move to standard TNF 2 clause license
 1.28 07-Mar-2008  dyoung branches: 1.28.2; 1.28.4;
Use device_t and accessors. Use PMF instead of legacy power
management. Establish the shutdown hook using PMF.
 1.27 25-Dec-2007  perry branches: 1.27.2; 1.27.6;
Convert many of the uses of __attribute__ to equivalent
__packed, __unused and __dead macros from cdefs.h
 1.26 16-Nov-2007  dyoung branches: 1.26.2; 1.26.6;
Count received frames, Rx PLCP errors, Rx FCS (CRC32) errors, and
Rx ICV errors using evcnt(9).

In promiscuous mode, and when scanning (hmm), ask the NIC for bad
packets (e.g., those that do not pass CRC32). Pass bad packets to
radiotap listeners. Pass packets to radiotap listeners before
stripping FCS. Re-order operations in atw_rxintr() to accomplish
all of this without passing bad packets up to net80211.

Set radiotap channel once in atw_tune() instead of in atw_rxintr().

Fix an endianness bug: it_len is little-endian, but bpf_mtap2()'s
argument needs to be in host order.
 1.25 16-Nov-2007  dyoung Use uintXX_t instead of u_intXX_t.
 1.24 16-Nov-2007  dyoung Replace some magic numbers with HFA3861A register names.

Do not alias the Rx descriptor word ar_ctl to ar_rssi with a #define.
Instead, call the member ar_ctlrssi.

Convert the ugly macro ATW_RXDESC_INIT() to an inline subroutine,
atw_rxdesc_init().

Do not load an empty IEEE80211_RADIOTAP_FLAGS field into the Tx
radiotap header.
 1.23 04-Mar-2007  christos branches: 1.23.14; 1.23.16; 1.23.20; 1.23.22;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.22 31-Aug-2006  dyoung branches: 1.22.8;
Per discussion on tech-kern and tech-userlevel, move the bit-twiddling
macros, __BIT, __BITS, SHIFTIN, SHIFTOUT, and __arraycount() from
lib/libkern/libkern.h to sys/cdefs.h. Add a __-prefix to SHIFTIN
and SHIFTOUT, and add a manual page for the bit-twiddling macros,
bits(3).

Make the __BIT and __BITS macros "widthless," as best I can, by
changing their type to uintmax_t from uint32_t. XXX The manual
page lags this change by a bit.

Define __PRIxBIT and __PRIxBITS printf(3) format strings.
 1.21 08-Mar-2006  dyoung Change macro names to avoid collisions:

BIT -> __BIT
BITS -> __BITS
 1.20 08-Mar-2006  dyoung Move my bit-twiddling macros to libkern.h from my drivers, where
I had duplicated them. Improve the macros' names. Simplify their
implementation.

A brief description of each macro is below.

BIT(n): Return a bitmask with bit m set, where the least
significant bit is bit 0.

BITS(m, n): Return a bitmask with bits m through n, inclusive,
set. It does not matter whether m>n or m<=n.
The least significant bit is bit 0.

A "bitfield" is a span of consecutive bits defined by a
bitmask, where 1s select the bits in the bitfield. SHIFTIN,
SHIFTOUT, and SHIFTOUT_MASK help read and write bitfields
from device registers.

SHIFTIN(v, mask): Left-shift bits `v' into the bitfield
defined by `mask', and return them. No
side-effects.

SHIFTOUT(v, mask): Extract and return the bitfield selected
by `mask' from `v', right-shifting the
bits so that the rightmost selected bit
is at bit 0. No side-effects.

SHIFTOUT_MASK(mask): Right-shift the bits in `mask' so that
the rightmost non-zero bit is at bit
0. This is useful for finding the
greatest unsigned value that a bitfield
can hold. No side-effects. Note that
SHIFTOUT_MASK(m) = SHIFTOUT(m, m).

Examples:

/*
* Register definitions taken from the RFMD RF3000 manual.
*/
#define RF3000_GAINCTL 0x11 /* TX variable gain control */
#define RF3000_GAINCTL_TXVGC_MASK BITS(7, 2)
#define RF3000_GAINCTL_SCRAMBLER BIT(1)

/*
* Shift the transmit power into the transmit-power field of the
* gain-control register and write it to the baseband processor.
*/
atw_rf3000_write(sc, RF3000_GAINCTL,
SHIFTIN(txpower, RF3000_GAINCTL_TXVGC_MASK));


/*
* Register definitions taken from the ADMtek ADM8211 manual.
*
*/
#define ATW_RXSTAT_OWN BIT(31) /* 1: NIC may fill descriptor */
/* ... */
#define ATW_RXSTAT_DA1 BIT(17) /* DA bit 1, admin'd address */
#define ATW_RXSTAT_DA0 BIT(16) /* DA bit 0, group address */
#define ATW_RXSTAT_RXDR_MASK BITS(15,12) /* RX data rate */
#define ATW_RXSTAT_FL_MASK BITS(11,0) /* RX frame length, last
* descriptor only
*/

/* Extract the frame length from the Rx descriptor's
* status field.
*/
len = SHIFTOUT(rxstat, ATW_RXSTAT_FL_MASK);
 1.19 29-Dec-2005  dyoung branches: 1.19.4; 1.19.6; 1.19.8; 1.19.10;
Cosmetic: shift atw flags right by 4 bits.
 1.18 29-Dec-2005  dyoung In atw(4), use ieee80211_compute_duration() to compute IEEE 802.11
Duration and PLCP Length fields, and delete the abominable
atw_frame_setdurs() subroutine.

Make rtw(4) use the new ieee80211_compute_duration() calling
convention.

Add an ieee80211_key argument to ieee80211_compute_duration() and
lightly constify arguments. Get the crypto header length from the
key argument instead of blithely assuming a WEP header. Add some
inline documentation. Account for data padding (IEEE80211_F_DATAPAD).
 1.17 11-Dec-2005  christos merge ktrace-lwp.
 1.16 22-Jun-2005  dyoung branches: 1.16.2;
Resolve conflicts in importation of 18-May-2005 ath(4) / net80211(9)
from FreeBSD. Introduce compatibility shims (sys/dev/ic/ath_netbsd.[ch],
sys/net80211/ieee80211_netbsd.[ch]). Update drivers (an, atu, atw,
awi, ipw, iwi, rtw, wi) for the new net80211(9) API.
 1.15 19-Dec-2004  dyoung Remove from atw(4) all of the 802.11 duration #defines that I just
moved to sys/net80211/ieee80211.h.
 1.14 24-Jul-2004  dyoung branches: 1.14.2;
Pull the IBSS merge logic out of atw and into net80211, since ath
will eventually share it.

In the IBSS merge logic, check conditions in a different order so
that they run faster in the common case---no merge. Fix the
rate-limiting on the debug outputs (enabled by IFF_LINK0).
 1.13 23-Jul-2004  dyoung Print and store Cardbus/PCI revision number.

Begin conditioning device configuration on revision number. Four
revisions are known:

1.1/1.5 -> ADM8211A,
2.0 -> ADM8211B,
3.0 -> ADM8211C.

The B and C parts, which are not supported yet, have AP capability.
 1.12 23-Jul-2004  dyoung Use the new SRAM size constants.
 1.11 15-Jul-2004  dyoung Simplify receive descriptor setup.
 1.10 15-Jul-2004  dyoung I'm not treating the lost beacon count specially any more. It is
kind of a dumb way to track the link condition, anyway....
 1.9 23-Jun-2004  dyoung The ADM8211C uses a different BBP type-number for RFMD parts than
the original ADM8211.
 1.8 29-Jan-2004  dyoung Get rid of __P.
 1.7 29-Jan-2004  dyoung Add atw_pci_enable, atw_pci_disable. Fixes a panic at "ifconfig
down" that was reported by Darren Reed.
 1.6 10-Jan-2004  dyoung Get rid of empty #if 0/#endif stanza.
 1.5 07-Dec-2003  dyoung Updates to 802.11 radiotap. The _DB_ flags were used everywhere to
denote a signed dBm Rx power, so rename them to _DBM_ and change
the signedness. Add new _DB_ flags for unsigned Rx power measured
from an arbitrary reference.

Try to synchronize net80211/ieee80211_radiotap.h with my tcpdump
sources (which public tcpdump has not seen, yet) and with FreeBSD.
 1.4 07-Dec-2003  dyoung Cosmetic: add some whitespace for readability.
 1.3 16-Nov-2003  dyoung Add data-link type DLT_IEEE802_11_RADIO to wi and atw. DLT_IEEE802_11_RADIO
lets you monitor radio stats like received signal strength, which
diversity antenna was used, channel/frequency, modulation, and data
rate.
 1.2 13-Oct-2003  dyoung Adapt atw(4) to the new 802.11 layer.

Simplify atw_start, atw_newstate.

Synchronize access to atw_start by bracketing the call to
ieee80211_next_scan in atw_next_scan with splnet()/splx().
 1.1 06-Jul-2003  dyoung Oops. Add the atw(4) sources, too.
 1.14.2.6 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.14.2.5 17-Jan-2005  skrll Sync with HEAD.
 1.14.2.4 21-Sep-2004  skrll Fix the sync with head I botched.
 1.14.2.3 18-Sep-2004  skrll Sync with HEAD.
 1.14.2.2 03-Aug-2004  skrll Sync with HEAD
 1.14.2.1 24-Jul-2004  skrll file atwvar.h was added on branch ktrace-lwp on 2004-08-03 10:46:11 +0000
 1.16.2.6 17-Mar-2008  yamt sync with head.
 1.16.2.5 21-Jan-2008  yamt sync with head
 1.16.2.4 07-Dec-2007  yamt sync with head
 1.16.2.3 03-Sep-2007  yamt sync with head.
 1.16.2.2 30-Dec-2006  yamt sync with head.
 1.16.2.1 21-Jun-2006  yamt sync with head.
 1.19.10.1 19-Apr-2006  elad sync with head.
 1.19.8.2 03-Sep-2006  yamt sync with head.
 1.19.8.1 13-Mar-2006  yamt sync with head.
 1.19.6.1 22-Apr-2006  simonb Sync with head.
 1.19.4.1 09-Sep-2006  rpaulo sync with head
 1.22.8.1 12-Mar-2007  rmind Sync with HEAD.
 1.23.22.2 18-Feb-2008  mjf Sync with HEAD.
 1.23.22.1 19-Nov-2007  mjf Sync with HEAD.
 1.23.20.1 18-Nov-2007  bouyer Sync with HEAD
 1.23.16.2 23-Mar-2008  matt sync with HEAD
 1.23.16.1 09-Jan-2008  matt sync with HEAD
 1.23.14.1 21-Nov-2007  joerg Sync with HEAD.
 1.26.6.1 02-Jan-2008  bouyer Sync with HEAD
 1.26.2.1 26-Dec-2007  ad Sync with head.
 1.27.6.3 28-Sep-2008  mjf Sync with HEAD.
 1.27.6.2 02-Jun-2008  mjf Sync with HEAD.
 1.27.6.1 03-Apr-2008  mjf Sync with HEAD.
 1.27.2.1 24-Mar-2008  keiichi sync with head.
 1.28.4.6 11-Aug-2010  yamt sync with head.
 1.28.4.5 11-Mar-2010  yamt sync with head
 1.28.4.4 16-Sep-2009  yamt sync with head
 1.28.4.3 16-May-2009  yamt sync with head
 1.28.4.2 04-May-2009  yamt sync with head.
 1.28.4.1 16-May-2008  yamt sync with head.
 1.28.2.1 18-May-2008  yamt sync with head.
 1.29.6.1 19-Oct-2008  haad Sync with HEAD.
 1.29.4.1 18-Jul-2008  simonb Sync with head.
 1.29.2.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.30.8.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.35.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.37.46.1 21-Apr-2017  bouyer Sync with HEAD
 1.37.42.1 20-Mar-2017  pgoyette Sync with HEAD
 1.37.38.1 05-Feb-2017  skrll Sync with HEAD
 1.37.20.1 03-Dec-2017  jdolecek update from HEAD
 1.38.12.1 22-Apr-2018  pgoyette Sync with HEAD
 1.39.2.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.104 09-Jul-2025  andvar Fix typos in comments:
s/mulicast/multicast/
s/muticast/multicast/
s/muliplicator/multiplicator/
s/muti-precision/multi-precision/
 1.103 30-Dec-2024  christos convert to pmf. reviewed by riastradh@
 1.102 05-Jul-2024  rin sys: Drop redundant NULL check before m_freem(9)

m_freem(9) safely has accepted NULL argument at least since 4.2BSD:
https://www.tuhs.org/cgi-bin/utree.pl?file=4.2BSD/usr/src/sys/sys/uipc_mbuf.c

Compile-tested on amd64/ALL.

Suggested by knakahara@
 1.101 25-Sep-2022  thorpej branches: 1.101.10;
Remove unnecessary include of <sys/malloc.h>.
 1.100 29-Jan-2020  thorpej Adopt <net/if_stats.h>.
 1.99 05-Dec-2019  msaitoh branches: 1.99.2;
Remove SIOC[GS]IFMEDIA because ieee80211_ioctl() does the same thing.
 1.98 28-May-2019  msaitoh Use ETHER_LOCK()/ETHER_UNLOCK() for all ethernet drivers to protect ec_multi*.
 1.97 23-May-2019  msaitoh -No functional change:
- KNF
- u_int*_t -> uint*_t.
 1.96 26-Apr-2019  msaitoh No functional change:
- u_int_{8,16,32}_t -> uint_{8,16,32}_t
- KNF.
- Tabify.
- Remove extra space.
 1.95 05-Feb-2019  msaitoh Remove very old IFF_NOTRAILERS flag.
 1.94 26-Jun-2018  msaitoh branches: 1.94.2;
Implement the BPF direction filter (BIOC[GS]DIRECTION). It provides backward
compatibility with BIOC[GS]SEESENT ioctl. The userland interface is the same
as FreeBSD.

This change also fixes a bug that the direction is misunderstand on some
environment by passing the direction to bpf_mtap*() instead of checking
m->m_pkthdr.rcvif.
 1.93 23-Jun-2018  maxv constify
 1.92 23-May-2017  ozaki-r branches: 1.92.8;
Apply deferred if_start to more drivers

And annotate some XXX_start as it runs in softint to clarify that
it doesn't need deferred if_start.
 1.91 02-Feb-2017  nonaka wlan interfaces make interrupt routine running on softint context.

see http://mail-index.netbsd.org/tech-kern/2016/12/06/msg021281.html

tested device:
* ath at pci: AR5212, AR5424
* athn at pci: AR9287
* ipw at pci: 2100BG
* iwi at pci: 2915ABG
* iwm at pci: 3165, 7260, 8260
* iwn at pci: 4945, 6235
* ral at pci: RT2560
* rtwn at pci: RTL8192CE
 1.90 10-Jun-2016  ozaki-r branches: 1.90.2; 1.90.4;
Introduce m_set_rcvif and m_reset_rcvif

The API is used to set (or reset) a received interface of a mbuf.
They are counterpart of m_get_rcvif, which will come in another
commit, hide internal of rcvif operation, and reduce the diff of
the upcoming change.

No functional change.
 1.89 26-May-2016  ozaki-r Use M_GETCTX

No functional change.
 1.88 27-Oct-2012  chs branches: 1.88.14;
split device_t/softc for all remaining drivers.
replace "struct device *" with "device_t".
use device_xname(), device_unit(), etc.
 1.87 05-Apr-2010  joerg branches: 1.87.8; 1.87.18;
Push the bpf_ops usage back into bpf.h. Push the common ifp->if_bpf
check into the inline functions as well the fourth argument for
bpf_attach.
 1.86 19-Jan-2010  pooka branches: 1.86.2; 1.86.4;
Redefine bpf linkage through an always present op vector, i.e.
#if NBPFILTER is no longer required in the client. This change
doesn't yet add support for loading bpf as a module, since drivers
can register before bpf is attached. However, callers of bpf can
now be modularized.

Dynamically loadable bpf could probably be done fairly easily with
coordination from the stub driver and the real driver by registering
attachments in the stub before the real driver is loaded and doing
a handoff. ... and I'm not going to ponder the depths of unload
here.

Tested with i386/MONOLITHIC, modified MONOLITHIC without bpf and rump.
 1.85 12-Nov-2009  dyoung Simplify activation hook. Replace each use of sc_invalid by either
calling config_deactivate(9) or device_is_active(9).
 1.84 15-Sep-2009  dyoung To ease a future device_t/softc split, se device_private() instead
of casting device_t to softc.
 1.83 15-Sep-2009  dyoung unifdef -D__NetBSD__ -U__FreeBSD__.

No functional change intended.
 1.82 12-May-2009  cegger struct device * -> device_t, no functional changes intended.
 1.81 07-Nov-2008  dyoung branches: 1.81.4;
*** Summary ***

When a link-layer address changes (e.g., ifconfig ex0 link
02:de:ad:be:ef:02 active), send a gratuitous ARP and/or a Neighbor
Advertisement to update the network-/link-layer address bindings
on our LAN peers.

Refuse a change of ethernet address to the address 00:00:00:00:00:00
or to any multicast/broadcast address. (Thanks matt@.)

Reorder ifnet ioctl operations so that driver ioctls may inherit
the functions of their "class"---ether_ioctl(), fddi_ioctl(), et
cetera---and the class ioctls may inherit from the generic ioctl,
ifioctl_common(), but both driver- and class-ioctls may override
the generic behavior. Make network drivers share more code.

Distinguish a "factory" link-layer address from others for the
purposes of both protecting that address from deletion and computing
EUI64.

Return consistent, appropriate error codes from network drivers.

Improve readability. KNF.

*** Details ***

In if_attach(), always initialize the interface ioctl routine,
ifnet->if_ioctl, if the driver has not already initialized it.
Delete if_ioctl == NULL tests everywhere else, because it cannot
happen.

In the ioctl routines of network interfaces, inherit common ioctl
behaviors by calling either ifioctl_common() or whichever ioctl
routine is appropriate for the class of interface---e.g., ether_ioctl()
for ethernets.

Stop (ab)using SIOCSIFADDR and start to use SIOCINITIFADDR. In
the user->kernel interface, SIOCSIFADDR's argument was an ifreq,
but on the protocol->ifnet interface, SIOCSIFADDR's argument was
an ifaddr. That was confusing, and it would work against me as I
make it possible for a network interface to overload most ioctls.
On the protocol->ifnet interface, replace SIOCSIFADDR with
SIOCINITIFADDR. In ifioctl(), return EPERM if userland tries to
invoke SIOCINITIFADDR.

In ifioctl(), give the interface the first shot at handling most
interface ioctls, and give the protocol the second shot, instead
of the other way around. Finally, let compatibility code (COMPAT_OSOCK)
take a shot.

Pull device initialization out of switch statements under
SIOCINITIFADDR. For example, pull ..._init() out of any switch
statement that looks like this:

switch (...->sa_family) {
case ...:
..._init();
...
break;
...
default:
..._init();
...
break;
}

Rewrite many if-else clauses that handle all permutations of IFF_UP
and IFF_RUNNING to use a switch statement,

switch (x & (IFF_UP|IFF_RUNNING)) {
case 0:
...
break;
case IFF_RUNNING:
...
break;
case IFF_UP:
...
break;
case IFF_UP|IFF_RUNNING:
...
break;
}

unifdef lots of code containing #ifdef FreeBSD, #ifdef NetBSD, and
#ifdef SIOCSIFMTU, especially in fwip(4) and in ndis(4).

In ipw(4), remove an if_set_sadl() call that is out of place.

In nfe(4), reuse the jumbo MTU logic in ether_ioctl().

Let ethernets register a callback for setting h/w state such as
promiscuous mode and the multicast filter in accord with a change
in the if_flags: ether_set_ifflags_cb() registers a callback that
returns ENETRESET if the caller should reset the ethernet by calling
if_init(), 0 on success, != 0 on failure. Pull common code from
ex(4), gem(4), nfe(4), sip(4), tlp(4), vge(4) into ether_ioctl(),
and register if_flags callbacks for those drivers.

Return ENOTTY instead of EINVAL for inappropriate ioctls. In
zyd(4), use ENXIO instead of ENOTTY to indicate that the device is
not any longer attached.

Add to if_set_sadl() a boolean 'factory' argument that indicates
whether a link-layer address was assigned by the factory or some
other source. In a comment, recommend using the factory address
for generating an EUI64, and update in6_get_hw_ifid() to prefer a
factory address to any other link-layer address.

Add a routing message, RTM_LLINFO_UPD, that tells protocols to
update the binding of network-layer addresses to link-layer addresses.
Implement this message in IPv4 and IPv6 by sending a gratuitous
ARP or a neighbor advertisement, respectively. Generate RTM_LLINFO_UPD
messages on a change of an interface's link-layer address.

In ether_ioctl(), do not let SIOCALIFADDR set a link-layer address
that is broadcast/multicast or equal to 00:00:00:00:00:00.

Make ether_ioctl() call ifioctl_common() to handle ioctls that it
does not understand.

In gif(4), initialize if_softc and use it, instead of assuming that
the gif_softc and ifp overlap.

Let ifioctl_common() handle SIOCGIFADDR.

Sprinkle rtcache_invariants(), which checks on DIAGNOSTIC kernels
that certain invariants on a struct route are satisfied.

In agr(4), rewrite agr_ioctl_filter() to be a bit more explicit
about the ioctls that we do not allow on an agr(4) member interface.

bzero -> memset. Delete unnecessary casts to void *. Use
sockaddr_in_init() and sockaddr_in6_init(). Compare pointers with
NULL instead of "testing truth". Replace some instances of (type
*)0 with NULL. Change some K&R prototypes to ANSI C, and join
lines.
 1.80 16-May-2008  dyoung branches: 1.80.4; 1.80.6;
Remove some #ifdef __FreeBSD__ code.
 1.79 28-Apr-2008  martin branches: 1.79.2;
Remove clause 3 and 4 from TNF licenses
 1.78 08-Apr-2008  cegger branches: 1.78.2; 1.78.4;
use aprint_*_dev and device_xname
 1.77 19-Oct-2007  ad branches: 1.77.16;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.76 01-Sep-2007  dyoung branches: 1.76.4;
Change a bazillion occurrences of code resembling this,

error = (cmd == SIOCADDMULTI) ?
ether_addmulti(ifr, &sc->sc_ec) :
ether_delmulti(ifr, &sc->sc_ec);

if (error == ENETRESET) {

to this,

if ((error = ether_ioctl(ifp, cmd, data)) == ENETRESET) {

which does the same thing.

(A bazillion is a very large number. This seems to make the i386
ALL kernel smaller by 3kB to 4kB.)

Use ifreq_getaddr() twice in es(4).

Whitespace nits.
 1.75 26-Aug-2007  dyoung branches: 1.75.2;
Constify: LLADDR -> CLLADDR. I'm aiming here to make it easier to
identify sockaddr_dl abuse that remains in the kernel, especially
the potential for overwriting memory past the end of a sockaddr_dl
with, e.g., memcpy(LLADDR(), ...).
 1.74 04-Mar-2007  christos branches: 1.74.2; 1.74.10; 1.74.14;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.73 04-Oct-2006  christos branches: 1.73.4;
prevent empty body in if.
 1.72 24-Sep-2006  jmcneill Add "name" parameter to powerhook_establish, to aid debugging. No objections
on tech-kern@
 1.71 28-Aug-2006  christos branches: 1.71.2; 1.71.4;
add missing initializer
 1.70 14-Apr-2006  christos Coverity CID 726: Remove bogus test. ni was checked for not NULL lines above,
and the if condition tries to free ni!
 1.69 11-Dec-2005  christos branches: 1.69.4; 1.69.6; 1.69.8; 1.69.10; 1.69.12;
merge ktrace-lwp.
 1.68 22-Jun-2005  dyoung branches: 1.68.2;
Resolve conflicts in importation of 18-May-2005 ath(4) / net80211(9)
from FreeBSD. Introduce compatibility shims (sys/dev/ic/ath_netbsd.[ch],
sys/net80211/ieee80211_netbsd.[ch]). Update drivers (an, atu, atw,
awi, ipw, iwi, rtw, wi) for the new net80211(9) API.
 1.67 27-Feb-2005  perry nuke trailing whitespace
 1.66 30-Oct-2004  thorpej branches: 1.66.4; 1.66.6;
When adding/deleting multicast addresses, only whack the address
filter if the interface is marked RUNNING.

Fixes kern/27678.
 1.65 10-Aug-2004  dyoung Make the node table into an LRU cache: least-recently used nodes
are at the end of the node queue. Change the reference-counting
discipline: ni->ni_refcnt indicates how many times net80211 has
granted ni to the driver. Every node in the table with ni_refcnt=0
is eligible to be garbage-collected. The mere presence of a node
in the table does not any longer indicate its auth/assoc state;
nodes have a ni_state variable, now. A sysctl,
net.link.ieee80211.maxnodecache, controls the maximum LRU cache
size.

While I am here, patch ieee80211_find_node_for_beacon to do a "best
match" by bssid/ssid/channel, not a "perfect match." This keeps
net80211 from caching duplicate nodes in the table.
 1.64 23-Jul-2004  mycroft Cleanup of ieee80211_node from madwifi:
* Don't use ifp pointers; use ieee80211com.
* Implement the locking macros that are used under FreeBSD and Linux.
 1.63 23-Jul-2004  mycroft IEEE80211_F_WEPON -> IEEE80211_F_PRIVACY
 1.62 16-Jan-2004  onoe branches: 1.62.4;
Do not return EINPROGRESS but 0 in awi_newstate, since the EINPROGRESS
handling was changed in net80211 framework.
This fix wiconfig -D awi0 to work again for DS phys.
XXX FH phys takes 20 seconds to complete scan, so wiconfig timed out.
 1.61 15-Jan-2004  onoe Correct beacon (src/bssid) for hostap and adhoc mode.
 1.60 15-Jan-2004  onoe Fix: panic when rate is specified but chan is left unspecified.
Add FreeBSD glues to share drivers.
 1.59 04-Dec-2003  keihan netbsd.org -> NetBSD.org

This was the last commit of this kind to src/sys, which is now totally
"NetBSD.org clean". Thanks for the patiance, and sorry for all the commits.
 1.58 02-Nov-2003  wiz Fix some typos. From Tom Cosgrove via jmc@openbsd.
 1.57 02-Nov-2003  dyoung Use ieee80211_find_rxnode to attribute Rx packets to the write
ieee80211_node. This reduces code duplication. It will help us
support passive scanning and rate adaptation.
 1.56 30-Oct-2003  simonb Remove some assigned-to but otherwise unused variables.
 1.55 15-Oct-2003  simonb Re-order a little so that there's no unreachable code in this block.
 1.54 13-Oct-2003  dyoung Adapt awi(4) to the new 802.11 layer.
 1.53 06-Jul-2003  dyoung Still more consolidation of 802.11 media-handling, moving moving
common code from awi and wi into the 802.11 framework. Inspired by
Sam Leffler's patches to FreeBSD.
 1.52 25-Feb-2003  dyoung branches: 1.52.2;
Add support for Prism monitor mode. From Kevin Lahey
<kml@patheticgeek.net>.

This patch does NOT add monitor mode support for the Lucent radios.

awi(4) was only modified for compatibility with the new mediaopt.
It does NOT support monitor mode.

Tested by Kevin, Daniel Carosone, and I.
 1.51 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.50 01-Oct-2002  onoe Allow SIOCSIFADDR with AF_LINK and WI_RID_MAC_NODE (wiconfig -m)
to set MAC address.
 1.49 30-Sep-2002  onoe old lucent adhoc-demo mode (adhoc,flag0 or wiconfig -p 3) wasn't handled
correctly. To avoid massive extra code in each driver, now if_iee80211subr.c
also handles non-standard old lucent adhoc-demo mode.
This also fixes PR 14227.
 1.48 30-Sep-2002  onoe re-enable IBSS creation.
 1.47 27-Sep-2002  onoe Add support for SIOC[SG]80211BSSID, SIOC[SG]80211CHANNEL.
Change the name of structure ieee80211_bss to ieee80211_node, which is
used for management of stations in hostap mode, and peers in ibss mode.
Split off ic_opmode, ic_phytype from ic_flags.
Preparation to merge 'wi' driver into 80211subr.c.
 1.46 03-Sep-2002  onoe Several fixes hostap for awi driver:
- aging ang clear inactivity stations
- DTIM field in beacon/probe response.
- ignore IFF_PROMISC for hostap mode, since 802.11 has 3 address fields,
so that promisc mode is not required for AP function.
 1.45 02-Sep-2002  onoe Add experimental support of Host-AP mode for awi driver.
It works also with WEP enabled.
But aging the associated clients is not implemented yet, so that the number
of clients may increase unlimitedly..
 1.44 28-Aug-2002  onoe Attach another DLTs for bpf: DLT_IEEE802_11 to capture raw 802.11 frame.
 1.43 05-Aug-2002  onoe Fix IBSS for awi driver.
 1.42 25-Jul-2002  onoe Set desired ESSID for probe request.
 1.41 13-Nov-2001  lukem branches: 1.41.8;
add/cleanup RCSID
 1.40 20-Sep-2001  onoe Move IBSS creation stuff from awi to ieee80211.
 1.39 19-Sep-2001  onoe Fix for FH infrastructure mode.
XXX: FH chanset should be calculated by FH hop pattern, but BayStack 650 AP
always specify chanset to fixed value 1. The previous code try to this
hack into awi driver, but it is insufficient because the chanset value
in awi driver may change while scan and it may be different from the
value in receiving beacon/probe-response. So we save encoded FH chanset
into channel in 802.11 common bss information for now.
 1.38 18-Sep-2001  onoe Fix register offset of SYNC_SET for FH phy.
 1.37 18-Sep-2001  onoe Move IEEE 802.11 MAC management functions from awi driver to
if_ieee80211subr.c, which can be shared between any IEEE 802.11
drivers.
However, most of current working IEEE 802.11b wireless LAN cards
have rich firmware and we cannot have a control to management frames
for such cards.

IBSS creation is now supported for the awi driver.
 1.36 26-Jul-2001  wiz branches: 1.36.2;
issueing -> issuing
 1.35 28-Jun-2001  onoe branches: 1.35.2;
Do not re-enable the driver after resume if the interface is marked down.
Change the first argument of awi_init/awi_stop from struct awi_softc to
struct ifnet to match the definition if_init/if_stop, though we don't
use ether_ioctl() yet.
 1.34 26-Jun-2001  onoe restore awi_power() to reenable awi after resume.
... forgot why it is disabled...
 1.33 25-Jun-2001  onoe AWI_DEBUG only:
awi_dump_pkt dumps packet before encryption in transmit.
 1.32 25-Jun-2001  onoe Fix capability information in association request to reflect ESS/IBSS mode.
This fix is required to interoperate with Cisco's access point.
 1.31 25-Jun-2001  onoe cleanup unnecessary include files.
 1.30 18-Dec-2000  thorpej branches: 1.30.2;
Remove an IF_PREPEND() that slipped through.
 1.29 14-Dec-2000  thorpej ALTQ'ify.
 1.28 26-Nov-2000  takemura Add new powerhook argument values, PWR_SOFTSUSPEND, PWR_SOFTSTANDBY and
PWR_SOFTRESUME. Apm calls powerhook with the values in normal interrupt
priority level while others are protected with splhigh().
 1.27 15-Nov-2000  thorpej branches: 1.27.2;
Move bpfattach()/bpfdetach() calls into ether_ifattach()/ether_ifdetach().
 1.26 21-Jul-2000  onoe add support for SIOCS80211NWKEY and SIOCG80211NWKEY.
 1.25 19-Jul-2000  onoe moved the check priviledge for SIOCS80211NWID from each driver to ifioctl().
it also fixes the problem that non-priviledged user can change nwid
for wi and ray drivers.
 1.24 11-Jul-2000  onoe Indicate WEP capability to association request when WEP is enabled.
Without this fix, some (IEEE802.11 conformant) APs will send data to this
station without using WEP.
 1.23 10-Jul-2000  onoe do not allow non-priviledged user to change nwid via ifconfig.
 1.22 10-Jul-2000  onoe move associated/synced/no-recent-beacons messages to IFF_DEBUG.
 1.21 05-Jul-2000  onoe change the argument of SIOCS80211NWID and SIOCG80211NWID ioctls from
u_int8_t array to struct ieee80211_nwid to prepend length field.
The length field is necessary because IEEE 802.11 spec doesn't prohibit
even '\0' for SSID.
Though the name and the value of SIOC... macro is unchanged, this change
breaks binary compatibility. The only affected userland program on the
tree is ifconfig(8).
As Jason suggested on tech-net, it is better than live with problems
since there are no releases for this ioctls yet.
 1.20 04-Jul-2000  onoe Support WEP functions for awi driver.
arc4 implementation by Kalle Kaukonen has been added.
define "wlan" in files.
XXX: only awi depends on wlan for now.
Allow authentication for adhoc (IBSS) mode.
Disable adhoc mode without bssid (mediaopt adhoc,flag0) for FH radio.
FH cannot work without synchronization by beacons.
Align IP header for ethernet encapsulation (IFF_FLAG0) mode.
Print available access points for IFF_DEBUG.
 1.19 09-Jun-2000  onoe branches: 1.19.2;
Restore the original copyright notice by Bill Sommerfeld
<sommerfeld@netbsd.org> since it is based on the original code.
 1.18 09-Jun-2000  onoe cleanup haeders.
add opt_awi.h to define AWI_DEBUG, AWI_WEP_ARC4.
show the firmware version at attach.
create a framework to support WEP (encryption code is not included for now).
a new wiconfig compatible ioctl interface replaced the awictl interface.
fix memory leak in selecting AP
fix bugs in ESSID selection
changes from FreeBSD-current by Warner Losh:
revision 1.2
date: 2000/04/17 22:58:15; author: imp; state: Exp; lines: +16 -1
Provide mem* for compat with NetBSD to fix LINT
fixes from FreeBSD-current by Guido van Rooij:
revision 1.4
date: 2000/05/29 19:58:10; author: guido; state: Exp; lines: +5 -2
Fix a panic resulting from an obvious null pointer deref.
Apparently some other panics still exist in this driver, but with
this fix, it was at least possible to run the Nokia card at SANE 2000.
 1.17 29-May-2000  jhawk For all network drivers that call ether_ifattach(), and also
have _detach() functions:
Ensure that softc keeps state about whether the attach succeeded,
and make the detach function return immediately if the attach did
not complete.
 1.16 27-Mar-2000  onoe branches: 1.16.2;
Fix multicast filter to set IFF_ALLMULTI flag properly. Also clear
unused group address from filter.
 1.15 27-Mar-2000  onoe Do not try to lock out MAC until the firmware correctly start up, to avoid
"awi: failed to lock interrupt" message when IRQ are shared with other
devices [PR kern/9660]
 1.14 27-Mar-2000  onoe backout changes between 1.10 and 1.12 to re-enable awictl stuff.
Actually, it is partially duplicated with SIOC[GS]IFMEDIA and
SIOC[GS]80211NWID ioctls currently supported. But I'd like to leave it
until configuration interface for common 802.11 stuff will be cleaned up.
 1.13 26-Mar-2000  itojun don't call if_deactivate with NULL ifp.
sc->sc_ifp can be NULL if awi_pcmcia_attach() fails, so you will see panic
if you remove a card which fails on attach.
 1.12 23-Mar-2000  mycroft GC unused variable.
 1.11 23-Mar-2000  mycroft Remove AWICTL stuff that is obsoleted by SIOC[SG]IFMEDIA and SIOC[SG]80211NWID.
Also, disable AWICTL completely until awictl.h appears.
 1.10 22-Mar-2000  onoe Update awi driver, which now supports AMD 79c930 based 802.11 DS cards
as well as 802.11 FH cards. Also, it can operate in infrastructure mode,
adhoc mode, and wi(4) (aka WaveLAN/IEEE) compatible adhoc mode.
 1.9 17-Feb-2000  sommerfeld Add detach support.
Light cleanup.
 1.8 09-Nov-1999  sommerfeld branches: 1.8.2; 1.8.4;
Completely rewrite receive processing to avoid sleep-deprivation-induced
brain damage and infinite loops, and lousy RTTs

Also, flush tx queues when reassociating with AP and when taking the
interface down.
 1.7 08-Nov-1999  sommerfeld avoid touching freed mbuf after allocation failure.
 1.6 08-Nov-1999  sommerfeld add a bunch of debug printfs under IFF_DEBUG and IFF_LINK2;
turn on IFF_DEBUG to trace the management protocol goo.
turn on IFF_LINK2 as well to see beacons.
 1.5 08-Nov-1999  sommerfeld misc cleanups; seems to work a little better in a dense-AP environment now.
1) ignore probe requests rather than printing "unknown mgmt subtype"
(cosmetic)
2) don't panic if mget of the 2nd mbuf in a chain fails (patch from MCR)
(though that whole function badly needs to be rewritten)
3) be a little more tenacious about hanging on to an access point.
 1.4 06-Nov-1999  sommerfeld branches: 1.4.2;
Extract MAC address from CIS data in pcmcia front end.
Fix multicast address manipulation.
ipv6 now works through this driver.
 1.3 05-Nov-1999  sommerfeld Add rcsid's
 1.2 04-Nov-1999  sommerfeld Conditionalize so this builds on 1.4.x..
 1.1 04-Nov-1999  sommerfeld Minimally functional driver for the am79c930 802.11 controller chip).
Working well enough to support dhcp; i'm doing this commit using the
interface.

Supports FH only. Does not yet do ad-hoc mode; works in
infrastructure mode. Not yet tested in environments with multiple
access points.
 1.4.2.2 06-Nov-1999  sommerfeld Extract MAC address from CIS data in pcmcia front end.
Fix multicast address manipulation.
ipv6 now works through this driver.
 1.4.2.1 06-Nov-1999  sommerfeld file awi.c was added on branch comdex-fall-1999 on 1999-11-06 16:43:54 +0000
 1.8.4.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.8.2.2 15-Nov-1999  fvdl Sync with -current
 1.8.2.1 09-Nov-1999  fvdl file awi.c was added on branch fvdl-softdep on 1999-11-15 00:40:27 +0000
 1.16.2.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.19.2.5 06-May-2001  he Pull up revision 1.28 (requested by he):
Add new powerhook argument values, PWR_SOFTSUSPEND, PWR_SOFTSTANDBY and
PWR_SOFTRESUME. Apm calls powerhook with the values in normal interrupt
priority level while others are protected with splhigh().
 1.19.2.4 21-Jul-2000  onoe Pullup 802.11 stuff (approved by jhawk)
- add support for nwkey to ifconfig
basesrc/sbin/ifconfig/ifconfig.c 1.88
basesrc/sbin/ifconfig/ifconfig.8 1.39
syssrc/sys/dev/ic/awi.c 1.26
syssrc/sys/dev/ic/awi_wep.c 1.3
syssrc/sys/dev/ic/awivar.h 1.12
syssrc/sys/dev/pcmcia/if_wi.c 1.26
syssrc/sys/net/if.c 1.69
syssrc/sys/net/if_ieee80211.h 1.5
 1.19.2.3 21-Jul-2000  onoe Pullup 802.11 stuff (approved by jhawk)
- move debug message to IFF_DEBUG
syssrc/sys/dev/ic/awi.c 1.22
 1.19.2.2 21-Jul-2000  onoe Pullups 802.11 stuff (approved by jhawk)
- allow non-string nwid settings
basesrc/sbin/ifconfig/ifconfig.c 1.82-1.86
basesrc/sbin/ifconfig/ifconfig.8 1.37
syssrc/sys/dev/ic/awi.c 1.21
syssrc/sys/dev/pcmcia/if_ray.c 1.21
syssrc/sys/dev/pcmcia/if_wi.c 1.23
syssrc/sys/dev/pcmcia/if_wivar.h 1.10
syssrc/sys/net/if_ieee80211.h 1.4
 1.19.2.1 14-Jul-2000  onoe Pull up revision 1.20,1.24 (approved by thorpej)
Add WEP support for awi driver.
 1.27.2.5 05-Jan-2001  bouyer Sync with HEAD
 1.27.2.4 08-Dec-2000  bouyer Sync with HEAD.
 1.27.2.3 22-Nov-2000  bouyer Sync with HEAD.
 1.27.2.2 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.27.2.1 15-Nov-2000  bouyer file awi.c was added on branch thorpej_scsipi on 2000-11-20 11:40:22 +0000
 1.30.2.8 18-Oct-2002  nathanw Catch up to -current.
 1.30.2.7 17-Sep-2002  nathanw Catch up to -current.
 1.30.2.6 13-Aug-2002  nathanw Catch up to -current.
 1.30.2.5 01-Aug-2002  nathanw Catch up to -current.
 1.30.2.4 24-Jun-2002  nathanw Curproc->curlwp renaming.

Change uses of "curproc->l_proc" back to "curproc", which is more like the
original use. Bare uses of "curproc" are now "curlwp".

"curproc" is now #defined in proc.h as ((curlwp) ? (curlwp)->l_proc) : NULL)
so that it is always safe to reference curproc (*de*referencing curproc
is another story, but that's always been true).
 1.30.2.3 14-Nov-2001  nathanw Catch up to -current.
 1.30.2.2 21-Sep-2001  nathanw Catch up to -current.
 1.30.2.1 24-Aug-2001  nathanw Catch up with -current.
 1.35.2.4 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.35.2.3 06-Sep-2002  jdolecek sync kqueue branch with HEAD
 1.35.2.2 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.35.2.1 03-Aug-2001  lukem update to -current
 1.36.2.1 01-Oct-2001  fvdl Catch up with -current.
 1.41.8.1 29-Aug-2002  gehenna catch up with -current.
 1.52.2.7 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.52.2.6 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.52.2.5 02-Nov-2004  skrll Sync with HEAD.
 1.52.2.4 21-Sep-2004  skrll Fix the sync with head I botched.
 1.52.2.3 18-Sep-2004  skrll Sync with HEAD.
 1.52.2.2 12-Aug-2004  skrll Sync with HEAD.
 1.52.2.1 03-Aug-2004  skrll Sync with HEAD
 1.62.4.1 24-Jan-2005  he Pull up revision 1.66 (requested by thorpej in ticket #939):
When adding or deleting multicast addresses, only change
the address filter if the interface is marked RUNNING.
Fixes PR#27678.
 1.66.6.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.66.4.1 29-Apr-2005  kent sync with -current
 1.68.2.4 27-Oct-2007  yamt sync with head.
 1.68.2.3 03-Sep-2007  yamt sync with head.
 1.68.2.2 30-Dec-2006  yamt sync with head.
 1.68.2.1 21-Jun-2006  yamt sync with head.
 1.69.12.1 24-May-2006  tron Merge 2006-05-24 NetBSD-current into the "peter-altq" branch.
 1.69.10.1 19-Apr-2006  elad sync with head.
 1.69.8.2 03-Sep-2006  yamt sync with head.
 1.69.8.1 24-May-2006  yamt sync with head.
 1.69.6.1 22-Apr-2006  simonb Sync with head.
 1.69.4.1 09-Sep-2006  rpaulo sync with head
 1.71.4.1 22-Oct-2006  yamt sync with head
 1.71.2.1 18-Nov-2006  ad Sync with head.
 1.73.4.1 12-Mar-2007  rmind Sync with HEAD.
 1.74.14.2 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.74.14.1 03-Sep-2007  jmcneill Sync with HEAD.
 1.74.10.1 03-Sep-2007  skrll Sync with HEAD.
 1.74.2.2 23-Oct-2007  ad Sync with head.
 1.74.2.1 09-Oct-2007  ad Sync with head.
 1.75.2.1 06-Nov-2007  matt sync with HEAD
 1.76.4.1 25-Oct-2007  bouyer Sync with HEAD.
 1.77.16.2 17-Jan-2009  mjf Sync with HEAD.
 1.77.16.1 02-Jun-2008  mjf Sync with HEAD.
 1.78.4.6 11-Aug-2010  yamt sync with head.
 1.78.4.5 11-Mar-2010  yamt sync with head
 1.78.4.4 16-Sep-2009  yamt sync with head
 1.78.4.3 16-May-2009  yamt sync with head
 1.78.4.2 04-May-2009  yamt sync with head.
 1.78.4.1 16-May-2008  yamt sync with head.
 1.78.2.1 18-May-2008  yamt sync with head.
 1.79.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.80.6.1 19-Jan-2009  skrll Sync with HEAD.
 1.80.4.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.81.4.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.86.4.1 30-May-2010  rmind sync with head
 1.86.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.87.18.2 03-Dec-2017  jdolecek update from HEAD
 1.87.18.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.87.8.1 30-Oct-2012  yamt sync with head
 1.88.14.4 28-Aug-2017  skrll Sync with HEAD
 1.88.14.3 05-Feb-2017  skrll Sync with HEAD
 1.88.14.2 09-Jul-2016  skrll Sync with HEAD
 1.88.14.1 29-May-2016  skrll Sync with HEAD
 1.90.4.1 21-Apr-2017  bouyer Sync with HEAD
 1.90.2.1 20-Mar-2017  pgoyette Sync with HEAD
 1.92.8.2 28-Jul-2018  pgoyette Sync with HEAD
 1.92.8.1 25-Jun-2018  pgoyette Sync with HEAD
 1.94.2.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.94.2.1 10-Jun-2019  christos Sync with HEAD
 1.99.2.1 29-Feb-2020  ad Sync with head.
 1.101.10.1 02-Aug-2025  perseant Sync with HEAD
 1.10 18-Sep-2001  onoe Move IEEE 802.11 MAC management functions from awi driver to
if_ieee80211subr.c, which can be shared between any IEEE 802.11
drivers.
However, most of current working IEEE 802.11b wireless LAN cards
have rich firmware and we cannot have a control to management frames
for such cards.

IBSS creation is now supported for the awi driver.
 1.9 26-Jul-2001  jdolecek branches: 1.9.2;
make local variable 'len' in awi_wep_setnkey() size_t (hence unsigned)
this one is merely cosmetic, no functional change
 1.8 28-Jun-2001  onoe branches: 1.8.2;
Do not re-enable the driver after resume if the interface is marked down.
Change the first argument of awi_init/awi_stop from struct awi_softc to
struct ifnet to match the definition if_init/if_stop, though we don't
use ether_ioctl() yet.
 1.7 25-Jun-2001  onoe Fix keyid bit position of encrypted packet to make non-first key usable.
 1.6 25-Jun-2001  onoe cleanup unnecessary include files.
 1.5 18-Jan-2001  jdolecek branches: 1.5.2;
constify
 1.4 14-Aug-2000  onoe branches: 1.4.2;
Make sure to reset length of data (len) and offset of mbuf (mlen) when
CRC is splitted into two mbufs in receiving. This fixes panic or hangup
in arc4_encrypt() when WEP is enabled on awi.
 1.3 21-Jul-2000  onoe add support for SIOCS80211NWKEY and SIOCG80211NWKEY.
 1.2 04-Jul-2000  onoe Support WEP functions for awi driver.
 1.1 09-Jun-2000  onoe branches: 1.1.2; 1.1.4;
cleanup haeders.
add opt_awi.h to define AWI_DEBUG, AWI_WEP_ARC4.
show the firmware version at attach.
create a framework to support WEP (encryption code is not included for now).
a new wiconfig compatible ioctl interface replaced the awictl interface.
fix memory leak in selecting AP
fix bugs in ESSID selection
changes from FreeBSD-current by Warner Losh:
revision 1.2
date: 2000/04/17 22:58:15; author: imp; state: Exp; lines: +16 -1
Provide mem* for compat with NetBSD to fix LINT
fixes from FreeBSD-current by Guido van Rooij:
revision 1.4
date: 2000/05/29 19:58:10; author: guido; state: Exp; lines: +5 -2
Fix a panic resulting from an obvious null pointer deref.
Apparently some other panics still exist in this driver, but with
this fix, it was at least possible to run the Nokia card at SANE 2000.
 1.1.4.2 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.1.4.1 09-Jun-2000  minoura file awi_wep.c was added on branch minoura-xpg4dl on 2000-06-22 17:06:36 +0000
 1.1.2.2 21-Jul-2000  onoe Pullup 802.11 stuff (approved by jhawk)
- add support for nwkey to ifconfig
basesrc/sbin/ifconfig/ifconfig.c 1.88
basesrc/sbin/ifconfig/ifconfig.8 1.39
syssrc/sys/dev/ic/awi.c 1.26
syssrc/sys/dev/ic/awi_wep.c 1.3
syssrc/sys/dev/ic/awivar.h 1.12
syssrc/sys/dev/pcmcia/if_wi.c 1.26
syssrc/sys/net/if.c 1.69
syssrc/sys/net/if_ieee80211.h 1.5
 1.1.2.1 14-Jul-2000  onoe Pull up revision 1.2 (approved by thorpej)
Add WEP support for awi driver.
 1.4.2.3 11-Feb-2001  bouyer Sync with HEAD.
 1.4.2.2 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.4.2.1 14-Aug-2000  bouyer file awi_wep.c was added on branch thorpej_scsipi on 2000-11-20 11:40:22 +0000
 1.5.2.3 28-Feb-2002  nathanw Catch up to -current.
 1.5.2.2 24-Aug-2001  nathanw Catch up with -current.
 1.5.2.1 05-Mar-2001  nathanw Initial commit of scheduler activations and lightweight process support.
 1.8.2.2 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.8.2.1 03-Aug-2001  lukem update to -current
 1.9.2.1 01-Oct-2001  fvdl Catch up with -current.
 1.8 18-Sep-2001  onoe Move IEEE 802.11 MAC management functions from awi driver to
if_ieee80211subr.c, which can be shared between any IEEE 802.11
drivers.
However, most of current working IEEE 802.11b wireless LAN cards
have rich firmware and we cannot have a control to management frames
for such cards.

IBSS creation is now supported for the awi driver.
 1.7 28-Jun-2001  onoe branches: 1.7.2; 1.7.4;
Do not re-enable the driver after resume if the interface is marked down.
Change the first argument of awi_init/awi_stop from struct awi_softc to
struct ifnet to match the definition if_init/if_stop, though we don't
use ether_ioctl() yet.
 1.6 25-Jun-2001  onoe add stubs for wiconfig(8).
 1.5 25-Jun-2001  onoe cleanup unnecessary include files.
 1.4 06-May-2001  ichiro divided into PCMCIA attachment and common code of wi.
since if_wi_ieee.h does not depend for pcmcia,
sys/dev/pcmcia/if_wi_ieee.h was moved to sys/dev/ic/wi_ieee.h .
 1.3 06-Jul-2000  onoe branches: 1.3.2; 1.3.4;
do not show wep keys to non-root users.
 1.2 04-Jul-2000  onoe Support WEP functions for awi driver.
arc4 implementation by Kalle Kaukonen has been added.
define "wlan" in files.
XXX: only awi depends on wlan for now.
Allow authentication for adhoc (IBSS) mode.
Disable adhoc mode without bssid (mediaopt adhoc,flag0) for FH radio.
FH cannot work without synchronization by beacons.
Align IP header for ethernet encapsulation (IFF_FLAG0) mode.
Print available access points for IFF_DEBUG.
 1.1 09-Jun-2000  onoe branches: 1.1.2; 1.1.4;
cleanup haeders.
add opt_awi.h to define AWI_DEBUG, AWI_WEP_ARC4.
show the firmware version at attach.
create a framework to support WEP (encryption code is not included for now).
a new wiconfig compatible ioctl interface replaced the awictl interface.
fix memory leak in selecting AP
fix bugs in ESSID selection
changes from FreeBSD-current by Warner Losh:
revision 1.2
date: 2000/04/17 22:58:15; author: imp; state: Exp; lines: +16 -1
Provide mem* for compat with NetBSD to fix LINT
fixes from FreeBSD-current by Guido van Rooij:
revision 1.4
date: 2000/05/29 19:58:10; author: guido; state: Exp; lines: +5 -2
Fix a panic resulting from an obvious null pointer deref.
Apparently some other panics still exist in this driver, but with
this fix, it was at least possible to run the Nokia card at SANE 2000.
 1.1.4.2 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.1.4.1 09-Jun-2000  minoura file awi_wicfg.c was added on branch minoura-xpg4dl on 2000-06-22 17:06:36 +0000
 1.1.2.1 14-Jul-2000  onoe Pull up revision 1.2-1.3 (approved by thorpej)
Add WEP support for awi driver.
 1.3.4.5 28-Feb-2002  nathanw Catch up to -current.
 1.3.4.4 24-Aug-2001  nathanw A few files and lwp/proc conversions I missed in the last big update.
GENERIC runs again.
 1.3.4.3 24-Aug-2001  nathanw Catch up with -current.
 1.3.4.2 21-Jun-2001  nathanw Catch up to -current.
 1.3.4.1 05-Mar-2001  nathanw Initial commit of scheduler activations and lightweight process support.
 1.3.2.2 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.3.2.1 06-Jul-2000  bouyer file awi_wicfg.c was added on branch thorpej_scsipi on 2000-11-20 11:40:23 +0000
 1.7.4.1 01-Oct-2001  fvdl Catch up with -current.
 1.7.2.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.2 09-Jun-2000  onoe cleanup haeders.
add opt_awi.h to define AWI_DEBUG, AWI_WEP_ARC4.
show the firmware version at attach.
create a framework to support WEP (encryption code is not included for now).
a new wiconfig compatible ioctl interface replaced the awictl interface.
fix memory leak in selecting AP
fix bugs in ESSID selection
changes from FreeBSD-current by Warner Losh:
revision 1.2
date: 2000/04/17 22:58:15; author: imp; state: Exp; lines: +16 -1
Provide mem* for compat with NetBSD to fix LINT
fixes from FreeBSD-current by Guido van Rooij:
revision 1.4
date: 2000/05/29 19:58:10; author: guido; state: Exp; lines: +5 -2
Fix a panic resulting from an obvious null pointer deref.
Apparently some other panics still exist in this driver, but with
this fix, it was at least possible to run the Nokia card at SANE 2000.
 1.1 23-Mar-2000  onoe branches: 1.1.2;
Sorry I forgot to commit this file..
 1.1.2.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.12 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.11 25-Dec-2007  perry branches: 1.11.6; 1.11.8; 1.11.10;
Convert many of the uses of __attribute__ to equivalent
__packed, __unused and __dead macros from cdefs.h
 1.10 11-Dec-2005  christos branches: 1.10.46; 1.10.52; 1.10.56; 1.10.60;
merge ktrace-lwp.
 1.9 27-Feb-2005  perry branches: 1.9.4;
nuke trailing whitespace
 1.8 20-Jan-2003  simonb branches: 1.8.2; 1.8.10; 1.8.12;
The Double-Semi-Colon Police.
 1.7 03-Sep-2002  onoe Several fixes hostap for awi driver:
- aging ang clear inactivity stations
- DTIM field in beacon/probe response.
- ignore IFF_PROMISC for hostap mode, since 802.11 has 3 address fields,
so that promisc mode is not required for AP function.
 1.6 05-Aug-2002  onoe Fix IBSS for awi driver.
 1.5 18-Sep-2001  onoe branches: 1.5.10;
Move IEEE 802.11 MAC management functions from awi driver to
if_ieee80211subr.c, which can be shared between any IEEE 802.11
drivers.
However, most of current working IEEE 802.11b wireless LAN cards
have rich firmware and we cannot have a control to management frames
for such cards.

IBSS creation is now supported for the awi driver.
 1.4 12-Jun-2001  wiz branches: 1.4.2; 1.4.4;
receive, not recieve
 1.3 22-Mar-2000  onoe branches: 1.3.6; 1.3.8;
Update awi driver, which now supports AMD 79c930 based 802.11 DS cards
as well as 802.11 FH cards. Also, it can operate in infrastructure mode,
adhoc mode, and wi(4) (aka WaveLAN/IEEE) compatible adhoc mode.
 1.2 05-Nov-1999  sommerfeld branches: 1.2.2; 1.2.4; 1.2.6;
Add rcsid's
 1.1 04-Nov-1999  sommerfeld Minimally functional driver for the am79c930 802.11 controller chip).
Working well enough to support dhcp; i'm doing this commit using the
interface.

Supports FH only. Does not yet do ad-hoc mode; works in
infrastructure mode. Not yet tested in environments with multiple
access points.
 1.2.6.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.2.4.2 15-Nov-1999  fvdl Sync with -current
 1.2.4.1 05-Nov-1999  fvdl file awireg.h was added on branch fvdl-softdep on 1999-11-15 00:40:27 +0000
 1.2.2.2 05-Nov-1999  sommerfeld Add rcsid's
 1.2.2.1 05-Nov-1999  sommerfeld file awireg.h was added on branch comdex-fall-1999 on 1999-11-05 05:13:37 +0000
 1.3.8.4 17-Sep-2002  nathanw Catch up to -current.
 1.3.8.3 13-Aug-2002  nathanw Catch up to -current.
 1.3.8.2 21-Sep-2001  nathanw Catch up to -current.
 1.3.8.1 21-Jun-2001  nathanw Catch up to -current.
 1.3.6.2 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.3.6.1 22-Mar-2000  bouyer file awireg.h was added on branch thorpej_scsipi on 2000-11-20 11:40:23 +0000
 1.4.4.1 01-Oct-2001  fvdl Catch up with -current.
 1.4.2.2 06-Sep-2002  jdolecek sync kqueue branch with HEAD
 1.4.2.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.5.10.1 29-Aug-2002  gehenna catch up with -current.
 1.8.12.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.8.10.1 29-Apr-2005  kent sync with -current
 1.8.2.1 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.9.4.1 21-Jan-2008  yamt sync with head
 1.10.60.1 02-Jan-2008  bouyer Sync with HEAD
 1.10.56.1 26-Dec-2007  ad Sync with head.
 1.10.52.1 18-Feb-2008  mjf Sync with HEAD.
 1.10.46.1 09-Jan-2008  matt sync with HEAD
 1.11.10.1 16-May-2008  yamt sync with head.
 1.11.8.1 18-May-2008  yamt sync with head.
 1.11.6.1 02-Jun-2008  mjf Sync with HEAD.
 1.29 30-Dec-2024  christos convert to pmf. reviewed by riastradh@
 1.28 02-Feb-2017  nonaka branches: 1.28.52;
wlan interfaces make interrupt routine running on softint context.

see http://mail-index.netbsd.org/tech-kern/2016/12/06/msg021281.html

tested device:
* ath at pci: AR5212, AR5424
* athn at pci: AR9287
* ipw at pci: 2100BG
* iwi at pci: 2915ABG
* iwm at pci: 3165, 7260, 8260
* iwn at pci: 4945, 6235
* ral at pci: RT2560
* rtwn at pci: RTL8192CE
 1.27 27-Oct-2012  chs branches: 1.27.14; 1.27.18; 1.27.22;
split device_t/softc for all remaining drivers.
replace "struct device *" with "device_t".
use device_xname(), device_unit(), etc.
 1.26 12-Nov-2009  dyoung branches: 1.26.12; 1.26.22;
Simplify activation hook. Replace each use of sc_invalid by either
calling config_deactivate(9) or device_is_active(9).
 1.25 15-Sep-2009  dyoung unifdef -D__NetBSD__ -U__FreeBSD__.

No functional change intended.
 1.24 12-May-2009  cegger struct device * -> device_t, no functional changes intended.
 1.23 28-Apr-2008  martin branches: 1.23.14;
Remove clause 3 and 4 from TNF licenses
 1.22 11-Dec-2005  christos branches: 1.22.70; 1.22.72; 1.22.74;
merge ktrace-lwp.
 1.21 22-Jun-2005  dyoung Resolve conflicts in importation of 18-May-2005 ath(4) / net80211(9)
from FreeBSD. Introduce compatibility shims (sys/dev/ic/ath_netbsd.[ch],
sys/net80211/ieee80211_netbsd.[ch]). Update drivers (an, atu, atw,
awi, ipw, iwi, rtw, wi) for the new net80211(9) API.
 1.20 15-Jan-2004  onoe Fix: panic when rate is specified but chan is left unspecified.
Add FreeBSD glues to share drivers.
 1.19 13-Oct-2003  dyoung Adapt awi(4) to the new 802.11 layer.
 1.18 06-Jul-2003  dyoung Still more consolidation of 802.11 media-handling, moving moving
common code from awi and wi into the 802.11 framework. Inspired by
Sam Leffler's patches to FreeBSD.
 1.17 30-Sep-2002  onoe branches: 1.17.6;
old lucent adhoc-demo mode (adhoc,flag0 or wiconfig -p 3) wasn't handled
correctly. To avoid massive extra code in each driver, now if_iee80211subr.c
also handles non-standard old lucent adhoc-demo mode.
This also fixes PR 14227.
 1.16 19-Sep-2001  onoe Fix for FH infrastructure mode.
XXX: FH chanset should be calculated by FH hop pattern, but BayStack 650 AP
always specify chanset to fixed value 1. The previous code try to this
hack into awi driver, but it is insufficient because the chanset value
in awi driver may change while scan and it may be different from the
value in receiving beacon/probe-response. So we save encoded FH chanset
into channel in 802.11 common bss information for now.
 1.15 18-Sep-2001  onoe Move IEEE 802.11 MAC management functions from awi driver to
if_ieee80211subr.c, which can be shared between any IEEE 802.11
drivers.
However, most of current working IEEE 802.11b wireless LAN cards
have rich firmware and we cannot have a control to management frames
for such cards.

IBSS creation is now supported for the awi driver.
 1.14 28-Jun-2001  onoe branches: 1.14.2; 1.14.4;
Do not re-enable the driver after resume if the interface is marked down.
Change the first argument of awi_init/awi_stop from struct awi_softc to
struct ifnet to match the definition if_init/if_stop, though we don't
use ether_ioctl() yet.
 1.13 18-Jan-2001  jdolecek branches: 1.13.2;
constify
 1.12 21-Jul-2000  onoe branches: 1.12.2;
add support for SIOCS80211NWKEY and SIOCG80211NWKEY.
 1.11 04-Jul-2000  onoe Support WEP functions for awi driver.
arc4 implementation by Kalle Kaukonen has been added.
define "wlan" in files.
XXX: only awi depends on wlan for now.
Allow authentication for adhoc (IBSS) mode.
Disable adhoc mode without bssid (mediaopt adhoc,flag0) for FH radio.
FH cannot work without synchronization by beacons.
Align IP header for ethernet encapsulation (IFF_FLAG0) mode.
Print available access points for IFF_DEBUG.
 1.10 09-Jun-2000  onoe branches: 1.10.2;
Restore the original copyright notice by Bill Sommerfeld
<sommerfeld@netbsd.org> since it is based on the original code.
 1.9 09-Jun-2000  onoe cleanup haeders.
add opt_awi.h to define AWI_DEBUG, AWI_WEP_ARC4.
show the firmware version at attach.
create a framework to support WEP (encryption code is not included for now).
a new wiconfig compatible ioctl interface replaced the awictl interface.
fix memory leak in selecting AP
fix bugs in ESSID selection
changes from FreeBSD-current by Warner Losh:
revision 1.2
date: 2000/04/17 22:58:15; author: imp; state: Exp; lines: +16 -1
Provide mem* for compat with NetBSD to fix LINT
fixes from FreeBSD-current by Guido van Rooij:
revision 1.4
date: 2000/05/29 19:58:10; author: guido; state: Exp; lines: +5 -2
Fix a panic resulting from an obvious null pointer deref.
Apparently some other panics still exist in this driver, but with
this fix, it was at least possible to run the Nokia card at SANE 2000.
 1.8 29-May-2000  jhawk For all network drivers that call ether_ifattach(), and also
have _detach() functions:
Ensure that softc keeps state about whether the attach succeeded,
and make the detach function return immediately if the attach did
not complete.
 1.7 27-Mar-2000  onoe branches: 1.7.2;
Do not try to lock out MAC until the firmware correctly start up, to avoid
"awi: failed to lock interrupt" message when IRQ are shared with other
devices [PR kern/9660]
 1.6 22-Mar-2000  onoe Update awi driver, which now supports AMD 79c930 based 802.11 DS cards
as well as 802.11 FH cards. Also, it can operate in infrastructure mode,
adhoc mode, and wi(4) (aka WaveLAN/IEEE) compatible adhoc mode.
 1.5 17-Feb-2000  sommerfeld Add detach support.
Light cleanup.
 1.4 09-Nov-1999  sommerfeld branches: 1.4.2; 1.4.4;
Completely rewrite receive processing to avoid sleep-deprivation-induced
brain damage and infinite loops, and lousy RTTs

Also, flush tx queues when reassociating with AP and when taking the
interface down.
 1.3 06-Nov-1999  sommerfeld branches: 1.3.2;
Extract MAC address from CIS data in pcmcia front end.
Fix multicast address manipulation.
ipv6 now works through this driver.
 1.2 05-Nov-1999  sommerfeld Add rcsid's
 1.1 04-Nov-1999  sommerfeld Minimally functional driver for the am79c930 802.11 controller chip).
Working well enough to support dhcp; i'm doing this commit using the
interface.

Supports FH only. Does not yet do ad-hoc mode; works in
infrastructure mode. Not yet tested in environments with multiple
access points.
 1.3.2.2 06-Nov-1999  sommerfeld Extract MAC address from CIS data in pcmcia front end.
Fix multicast address manipulation.
ipv6 now works through this driver.
 1.3.2.1 06-Nov-1999  sommerfeld file awivar.h was added on branch comdex-fall-1999 on 1999-11-06 16:43:55 +0000
 1.4.4.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.4.2.2 15-Nov-1999  fvdl Sync with -current
 1.4.2.1 09-Nov-1999  fvdl file awivar.h was added on branch fvdl-softdep on 1999-11-15 00:40:28 +0000
 1.7.2.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.10.2.2 21-Jul-2000  onoe Pullup 802.11 stuff (approved by jhawk)
- add support for nwkey to ifconfig
basesrc/sbin/ifconfig/ifconfig.c 1.88
basesrc/sbin/ifconfig/ifconfig.8 1.39
syssrc/sys/dev/ic/awi.c 1.26
syssrc/sys/dev/ic/awi_wep.c 1.3
syssrc/sys/dev/ic/awivar.h 1.12
syssrc/sys/dev/pcmcia/if_wi.c 1.26
syssrc/sys/net/if.c 1.69
syssrc/sys/net/if_ieee80211.h 1.5
 1.10.2.1 14-Jul-2000  onoe Pull up revision 1.11 (approved by thorpej)
Add WEP support for awi driver.
 1.12.2.3 11-Feb-2001  bouyer Sync with HEAD.
 1.12.2.2 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.12.2.1 21-Jul-2000  bouyer file awivar.h was added on branch thorpej_scsipi on 2000-11-20 11:40:23 +0000
 1.13.2.3 18-Oct-2002  nathanw Catch up to -current.
 1.13.2.2 21-Sep-2001  nathanw Catch up to -current.
 1.13.2.1 24-Aug-2001  nathanw Catch up with -current.
 1.14.4.1 01-Oct-2001  fvdl Catch up with -current.
 1.14.2.2 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.14.2.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.17.6.4 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.17.6.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.17.6.2 18-Sep-2004  skrll Sync with HEAD.
 1.17.6.1 03-Aug-2004  skrll Sync with HEAD
 1.22.74.4 11-Mar-2010  yamt sync with head
 1.22.74.3 16-Sep-2009  yamt sync with head
 1.22.74.2 16-May-2009  yamt sync with head
 1.22.74.1 16-May-2008  yamt sync with head.
 1.22.72.1 18-May-2008  yamt sync with head.
 1.22.70.1 02-Jun-2008  mjf Sync with HEAD.
 1.23.14.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.26.22.2 03-Dec-2017  jdolecek update from HEAD
 1.26.22.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.26.12.1 30-Oct-2012  yamt sync with head
 1.27.22.1 21-Apr-2017  bouyer Sync with HEAD
 1.27.18.1 20-Mar-2017  pgoyette Sync with HEAD
 1.27.14.1 05-Feb-2017  skrll Sync with HEAD
 1.28.52.1 02-Aug-2025  perseant Sync with HEAD
 1.18 01-Jul-2021  thorpej Make sure the media / mii members in struct ethercom are initialized
so that the media-related ioctls work. Problem reported by Björn Johannesson
on current-users@.

XXX pullup-9
 1.17 30-Jun-2021  thorpej Fix a couple of problems with MII-equipped NE2000 derivatives reported by
Björn Johannesson on current-users@:

- Re-factor dp8390_stop() into dp8390_halt() (that does the stuff to
halt the hardware) and dp8390_stop() (which alls dp8390_halt() before
calling mii_down() via sc->sc_stop_card()). This prevents us from
calling mii_down() before all of the interface data structures have
been set up, which these days can trip a KASSERT().

- Add a 1-second timer to call mii_tick(), and enable it in the
sc->sc_init_card() callback, and cancel it in the sc->sc_stop_card()
and sc->sc_media_fini() callbacks. This is actually a long-standing
bug that previously didn't have much practical effect, but causes
problems with dhcpcd's link live-ness detection logic.
 1.16 04-Feb-2020  thorpej branches: 1.16.10;
Use ifmedia_fini().
 1.15 29-May-2019  msaitoh branches: 1.15.2; 1.15.4;
No functional change:
- Simplify MII structure initialization and reference.
- KNF
 1.14 29-May-2019  msaitoh Whitespace fix. No functional change.
 1.13 22-Jan-2019  msaitoh Change MII PHY read/write API from:

int (*mii_readreg_t)(device_t, int, int);
void (*mii_writereg_t)(device_t, int, int, int);
to:

int (*mii_readreg_t)(device_t, int, int, uint16_t *);
int (*mii_writereg_t)(device_t, int, int, uint16_t);

Now we can test if a read/write operation failed or not by the return value.

In 802.3 spec says that the PHY shall not respond to read/write transaction
to the unimplemented register(22.2.4.3). Detecting timeout can be used to
check whether a register is implemented or not (if the register conforms to
the spec). ukphy(4) can be used this for MII_MMDACR and MII_MMDAADR.

Note that I noticed that the following code do infinite loop in the
read/wirte function. If it accesses unimplemented PHY register, it will hang.
It should be fixed:

arm/at91/at91emac.c
arm/ep93xx/epe.c
arm/omap/omapl1x_emac.c
mips/ralink/ralink_eth.c
arch/powerpc/booke/dev/pq3etsec.c(read)
dev/cadence/if_cemac.c <- hkenken
dev/ic/lan9118.c


Tested with the following device:

axe+ukphy
axe+rgephy
axen+rgephy (tested by Andrius V)
wm+atphy
wm+ukphy
wm+igphy
wm+ihphy
wm+makphy
sk+makphy
sk+brgphy
sk+gentbi
msk+makphy
sip+icsphy
sip+ukphy
re+rgephy
bge+brgphy
bnx+brgphy
gsip+gphyter
rtk+rlphy
fxp+inphy (tested by Andrius V)
tlp+acphy
ex+exphy
epic+qsphy
vge+ciphy (tested by Andrius V)
vr+ukphy (tested by Andrius V)
vte+ukphy (tested by Andrius V)

Not tested (MAC):
arm:at91emac
arm:cemac
arm:epe
arm:geminigmac
arm:enet
arm:cpsw
arm:emac(omac)
arm:emac(sunxi)
arm:npe
evbppc:temac
macppc:bm
macppc:gm
mips:aumac
mips:ae
mips:cnmac
mips:reth
mips:sbmac
playstation2:smap
powerpc:tsec
powerpc:emac(ibm4xx)
sgimips:mec
sparc:be
sf
ne(ax88190, dl10019)
awge
ep
gem
hme
smsh
mtd
sm
age
alc
ale
bce
cas
et
jme
lii
nfe
pcn
ste
stge
tl
xi
aue
mue
smsc
udav
url

Not tested (PHY):
amhphy
bmtphy
dmphy
etphy
glxtphy
ikphy
iophy
lxtphy
nsphyter
pnaphy
rdcphy
sqphy
tlphy
tqphy
urlphy
 1.12 22-Jul-2012  matt branches: 1.12.38; 1.12.40;
Fix mii_statchg to take a 'struct ifnet *' instead of device_t. This fixes
problem with a common MDIO bus used for multiple interfaces.
Some drivers converted to CFATTACL_DECL_NEW.
 1.11 28-Apr-2008  martin branches: 1.11.34;
Remove clause 3 and 4 from TNF licenses
 1.10 12-Mar-2008  cube branches: 1.10.2; 1.10.4;
Split device_t and softc for the NE2000 Ethernet chip and all its variants
and attachments. Use device_t accessors, correct types, and ANSIfy when
appropriate.
 1.9 19-Jan-2008  dyoung branches: 1.9.2; 1.9.6;
Make many ethernet drivers share the common code for MII media
handling, ether_mediastatus() and ether_mediachange(). Check for
a non-ENXIO error return from mii_mediachg(). (ENXIO indicates
that a PHY is suspended.)

This patch shrinks the source code size by 979 lines. There was
a 5100-byte savings on the NetBSD/i386 kernel configuration, ALL.

I have made a few miscellaneous changes, too:

gem(4): use LIST_EMPTY(), LIST_FOREACH().
mtd(4): handle media ioctls, for a change!
axe(4): do not track link status in sc->axe_link any longer
nfe(4), aue(4), axe(4), udav(4), url(4): do not reset all PHYs
on a change of media

Except for the change to mtd(4), no functional changes are intended.

XXX This patch affects more architectures than I can feasibly
XXX compile and run. I have compiled macppc, sparc64, i386. I
XXX have run the patches on i386 boxen with bnx(4) and sip(4).
XXX Compiling and running on evbmips (MERAKI, ADM5120) is in
XXX progress.
 1.8 19-Oct-2007  ad branches: 1.8.2; 1.8.8;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.7 16-Nov-2006  christos branches: 1.7.8; 1.7.22; 1.7.24; 1.7.28;
__unused removal on arguments; approved by core.
 1.6 12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.5 11-Dec-2005  christos branches: 1.5.20; 1.5.22;
merge ktrace-lwp.
 1.4 24-Aug-2004  thorpej branches: 1.4.12;
Use ANSI function decls and more use of static.
 1.3 22-Oct-2002  fair branches: 1.3.6;
Change the "dontcare bits" argument to ifmedia_init() to IFM_IMASK
so that it is possible select PHY instances other than the first
one (instance zero), if there is more than one PHY attached.
 1.2 13-Nov-2001  lukem add/cleanup RCSID
 1.1 04-Aug-2001  enami branches: 1.1.2; 1.1.4;
MII access routines for ASIX AX88190.
 1.1.4.3 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.1.4.2 25-Aug-2001  thorpej Merge Aug 24 -current into the kqueue branch.
 1.1.4.1 04-Aug-2001  thorpej file ax88190.c was added on branch kqueue on 2001-08-25 06:16:12 +0000
 1.1.2.4 11-Nov-2002  nathanw Catch up to -current
 1.1.2.3 14-Nov-2001  nathanw Catch up to -current.
 1.1.2.2 24-Aug-2001  nathanw Catch up with -current.
 1.1.2.1 04-Aug-2001  nathanw file ax88190.c was added on branch nathanw_sa on 2001-08-24 00:09:17 +0000
 1.3.6.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.3.6.2 18-Sep-2004  skrll Sync with HEAD.
 1.3.6.1 25-Aug-2004  skrll Sync with HEAD.
 1.4.12.4 17-Mar-2008  yamt sync with head.
 1.4.12.3 21-Jan-2008  yamt sync with head
 1.4.12.2 27-Oct-2007  yamt sync with head.
 1.4.12.1 30-Dec-2006  yamt sync with head.
 1.5.22.2 10-Dec-2006  yamt sync with head.
 1.5.22.1 22-Oct-2006  yamt sync with head
 1.5.20.1 18-Nov-2006  ad Sync with head.
 1.7.28.1 25-Oct-2007  bouyer Sync with HEAD.
 1.7.24.2 23-Mar-2008  matt sync with HEAD
 1.7.24.1 06-Nov-2007  matt sync with HEAD
 1.7.22.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.7.8.1 23-Oct-2007  ad Sync with head.
 1.8.8.1 20-Jan-2008  bouyer Sync with HEAD
 1.8.2.1 18-Feb-2008  mjf Sync with HEAD.
 1.9.6.2 02-Jun-2008  mjf Sync with HEAD.
 1.9.6.1 03-Apr-2008  mjf Sync with HEAD.
 1.9.2.1 24-Mar-2008  keiichi sync with head.
 1.10.4.1 16-May-2008  yamt sync with head.
 1.10.2.1 18-May-2008  yamt sync with head.
 1.11.34.1 30-Oct-2012  yamt sync with head
 1.12.40.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.12.40.1 10-Jun-2019  christos Sync with HEAD
 1.12.38.1 26-Jan-2019  pgoyette Sync with HEAD
 1.15.4.1 29-Feb-2020  ad Sync with head.
 1.15.2.1 03-Jul-2021  martin Pull up following revision(s) (requested by thorpej in ticket #1311):

sys/dev/ic/dp8390.c: revision 1.99
sys/dev/ic/dl10019.c: revision 1.17
sys/dev/ic/ax88190.c: revision 1.18

Make sure the media / mii members in struct ethercom are initialized
so that the media-related ioctls work. Problem reported by Bj�rn Johannesson
on current-users@.

XXX pullup-9
 1.16.10.1 01-Aug-2021  thorpej Sync with HEAD.
 1.4 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.3 11-Dec-2005  christos branches: 1.3.70; 1.3.72; 1.3.74;
merge ktrace-lwp.
 1.2 22-Oct-2003  christos support for NE2000_TYPE_AX88790 from
Yong-Jhen Hong yongjhen at alqualonde dot org
 1.1 04-Aug-2001  enami branches: 1.1.2; 1.1.4; 1.1.24;
MII access routines for ASIX AX88190.
 1.1.24.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.1.24.2 18-Sep-2004  skrll Sync with HEAD.
 1.1.24.1 03-Aug-2004  skrll Sync with HEAD
 1.1.4.2 25-Aug-2001  thorpej Merge Aug 24 -current into the kqueue branch.
 1.1.4.1 04-Aug-2001  thorpej file ax88190reg.h was added on branch kqueue on 2001-08-25 06:16:12 +0000
 1.1.2.2 24-Aug-2001  nathanw Catch up with -current.
 1.1.2.1 04-Aug-2001  nathanw file ax88190reg.h was added on branch nathanw_sa on 2001-08-24 00:09:17 +0000
 1.3.74.1 16-May-2008  yamt sync with head.
 1.3.72.1 18-May-2008  yamt sync with head.
 1.3.70.1 02-Jun-2008  mjf Sync with HEAD.
 1.2 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.1 04-Aug-2001  enami branches: 1.1.2; 1.1.4; 1.1.122; 1.1.124; 1.1.126;
MII access routines for ASIX AX88190.
 1.1.126.1 16-May-2008  yamt sync with head.
 1.1.124.1 18-May-2008  yamt sync with head.
 1.1.122.1 02-Jun-2008  mjf Sync with HEAD.
 1.1.4.2 25-Aug-2001  thorpej Merge Aug 24 -current into the kqueue branch.
 1.1.4.1 04-Aug-2001  thorpej file ax88190var.h was added on branch kqueue on 2001-08-25 06:16:13 +0000
 1.1.2.2 24-Aug-2001  nathanw Catch up with -current.
 1.1.2.1 04-Aug-2001  nathanw file ax88190var.h was added on branch nathanw_sa on 2001-08-24 00:09:17 +0000
 1.23 04-Oct-2025  thorpej Add a shared function to query the common properties used for configuring
an Ethernet address.
 1.22 06-Oct-2024  skrll Don't use obsoleted if_flags / IFF_ALLMULTI instead set / clear
ec_flags / ETHER_F_ALLMULTI.
 1.21 04-Oct-2024  skrll Fix a problem noted by Taylor...

touching if_flags is forbidden in this context (no IFNET_LOCK guaranteed)
sc_promisc should be cached when if_flags changes, not when
SIOCADDMULTI/SIOCDELMULTI runs

by caching if_flags in sc_if_flags via a ifflags_cb.
 1.20 15-Sep-2024  skrll genet(4): Remove the non-MP-safe scaffolding.
 1.19 25-Aug-2024  mlelstv Fix off-by-one.
 1.18 25-Aug-2024  mlelstv Fix mbuf leak.
Minor optimizations for send queue.
 1.17 25-Aug-2024  mlelstv Fix MBUFTRACE
 1.16 25-Aug-2024  mlelstv Don't mix endianess and MAC address layout.
 1.15 25-Aug-2024  skrll Whitespace
 1.14 18-Sep-2022  thorpej branches: 1.14.10;
Eliminate use of IFF_OACTIVE.
 1.13 01-Aug-2022  mlelstv Revert last accidental commits.
 1.12 01-Aug-2022  mlelstv Also fix shift values for SCT constants.
 1.11 31-Dec-2021  riastradh sys: Use if_init wrapper function.

Exception: Not in kern_pmf.c, for the kind of silly reason that it
avoids having kern_pmf.c refer to symbols defined only in net; this
avoids a pain in the rump.
 1.10 10-Aug-2021  jmcneill Clear IFF_OACTIVE in genet_txintr (bug introduced in r1.8) and don't
sync DMA maps with size 0.
 1.9 03-May-2021  rin genet(4): Add support for rnd(9).
 1.8 08-Mar-2021  mlelstv branches: 1.8.4;
Compute CRC for all segments of a multi-buffer packet.
Add interrupt mitigation for transmit and receive.
Use separate transmit lock.
Fix some error paths.
 1.7 27-Jun-2020  jmcneill branches: 1.7.2;
prop_data_data_nocopy -> prop_data_value
 1.6 25-May-2020  jmcneill Improve RGMII TX / RX delay handling, from OpenBSD.
 1.5 29-Mar-2020  jmcneill branches: 1.5.2;
Try to use the existing HW address programmed into the device if possible.
 1.4 29-Mar-2020  jmcneill Avoid "hole in RX ring" condition by ensuring a new mbuf is available
before using an existing one.
 1.3 27-Feb-2020  jmcneill branches: 1.3.2;
Explicit format string for snprintf, spotted by tnn@
 1.2 22-Feb-2020  jmcneill Add support for hardware rx filters.
 1.1 22-Feb-2020  jmcneill Add support for Broadcom GENET v5 ethernet controller as found on the
Raspberry Pi 4 (BCM2711).
 1.3.2.2 29-Feb-2020  ad Sync with head.
 1.3.2.1 27-Feb-2020  ad file bcmgenet.c was added on branch ad-namecache on 2020-02-29 20:19:08 +0000
 1.5.2.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.5.2.1 29-Mar-2020  martin file bcmgenet.c was added on branch phil-wifi on 2020-04-08 14:08:06 +0000
 1.7.2.1 03-Apr-2021  thorpej Sync with HEAD.
 1.8.4.1 13-May-2021  thorpej Sync with HEAD.
 1.14.10.1 02-Aug-2025  perseant Sync with HEAD
 1.4 08-Mar-2021  mlelstv Compute CRC for all segments of a multi-buffer packet.
Add interrupt mitigation for transmit and receive.
Use separate transmit lock.
Fix some error paths.
 1.3 25-Apr-2020  jmcneill branches: 1.3.2;
Add missing receive error status bit definitions, from Robert Sprowson in
PR# kern/55199
 1.2 22-Feb-2020  jmcneill branches: 1.2.2; 1.2.6; 1.2.8;
Add support for hardware rx filters.
 1.1 22-Feb-2020  jmcneill Add support for Broadcom GENET v5 ethernet controller as found on the
Raspberry Pi 4 (BCM2711).
 1.2.8.1 25-Apr-2020  bouyer Sync with bouyer-xenpvh-base2 (HEAD)
 1.2.6.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.2.6.1 22-Feb-2020  martin file bcmgenetreg.h was added on branch phil-wifi on 2020-04-08 14:08:06 +0000
 1.2.2.2 29-Feb-2020  ad Sync with head.
 1.2.2.1 22-Feb-2020  ad file bcmgenetreg.h was added on branch ad-namecache on 2020-02-29 20:19:08 +0000
 1.3.2.1 03-Apr-2021  thorpej Sync with HEAD.
 1.6 04-Oct-2024  skrll Fix a problem noted by Taylor...

touching if_flags is forbidden in this context (no IFNET_LOCK guaranteed)
sc_promisc should be cached when if_flags changes, not when
SIOCADDMULTI/SIOCDELMULTI runs

by caching if_flags in sc_if_flags via a ifflags_cb.
 1.5 15-Sep-2024  skrll genet(4): Remove the non-MP-safe scaffolding.
 1.4 03-May-2021  rin branches: 1.4.20;
genet(4): Add support for rnd(9).
 1.3 08-Mar-2021  mlelstv branches: 1.3.4;
Compute CRC for all segments of a multi-buffer packet.
Add interrupt mitigation for transmit and receive.
Use separate transmit lock.
Fix some error paths.
 1.2 25-May-2020  jmcneill branches: 1.2.2;
Improve RGMII TX / RX delay handling, from OpenBSD.
 1.1 22-Feb-2020  jmcneill branches: 1.1.2; 1.1.6;
Add support for Broadcom GENET v5 ethernet controller as found on the
Raspberry Pi 4 (BCM2711).
 1.1.6.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.1.6.1 22-Feb-2020  martin file bcmgenetvar.h was added on branch phil-wifi on 2020-04-08 14:08:06 +0000
 1.1.2.2 29-Feb-2020  ad Sync with head.
 1.1.2.1 22-Feb-2020  ad file bcmgenetvar.h was added on branch ad-namecache on 2020-02-29 20:19:08 +0000
 1.2.2.1 03-Apr-2021  thorpej Sync with HEAD.
 1.3.4.1 13-May-2021  thorpej Sync with HEAD.
 1.4.20.1 02-Aug-2025  perseant Sync with HEAD
 1.80 25-Sep-2022  thorpej Remove unnecessary include of <sys/malloc.h>.
 1.79 07-Aug-2021  thorpej Merge thorpej-cfargs2.
 1.78 24-Apr-2021  thorpej branches: 1.78.8;
Merge thorpej-cfargs branch:

Simplify and make extensible the config_search() / config_found() /
config_attach() interfaces: rather than having different variants for
which arguments you want pass along, just have a single call that
takes a variadic list of tag-value arguments.

Adjust all call sites:
- Simplify wherever possible; don't pass along arguments that aren't
actually needed.
- Don't be explicit about what interface attribute is attaching if
the device only has one. (More simplification.)
- Add a config_probe() function to be used in indirect configuiration
situations, making is visibly easier to see when indirect config is
in play, and allowing for future change in semantics. (As of now,
this is just a wrapper around config_match(), but that is an
implementation detail.)

Remove unnecessary or redundant interface attributes where they're not
needed.

There are currently 5 "cfargs" defined:
- CFARG_SUBMATCH (submatch function for direct config)
- CFARG_SEARCH (search function for indirect config)
- CFARG_IATTR (interface attribte)
- CFARG_LOCATORS (locators array)
- CFARG_DEVHANDLE (devhandle_t - wraps OFW, ACPI, etc. handles)

...and a sentinel value CFARG_EOL.

Add some extra sanity checking to ensure that interface attributes
aren't ambiguous.

Use CFARG_DEVHANDLE in MI FDT, OFW, and ACPI code, and macppc and shark
ports to associate those device handles with device_t instance. This
will trickle trough to more places over time (need back-end for pre-OFW
Sun OBP; any others?).
 1.77 26-Feb-2017  jdolecek branches: 1.77.30;
got 'bad mbi comp_stat 5' during DIOCGCACHE under Parallels, according
to linux driver it's possible status when controller thinks the CCB is invalid;
handle same as BHA_MBI_ABORT/BHA_MBI_UNKNOWN i.e. just clear the CCB anyway
 1.76 14-Jul-2016  msaitoh branches: 1.76.2; 1.76.4;
KNF. No functional change.
 1.75 27-Oct-2012  chs branches: 1.75.14;
split device_t/softc for all remaining drivers.
replace "struct device *" with "device_t".
use device_xname(), device_unit(), etc.
 1.74 13-Nov-2010  uebayasi branches: 1.74.8; 1.74.18;
Don't pull in the whole uvm(9) API to access only PAGE_SIZE and
some other constants. These are provided by sys/param.h now.
 1.73 27-Jul-2010  jakllsch printf() size_t with 'z' format modifier in debug code.
 1.72 23-Nov-2009  rmind branches: 1.72.2; 1.72.4;
Remove some unecessary includes sys/user.h header.
 1.71 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.70 08-Apr-2008  cegger branches: 1.70.2; 1.70.4;
use aprint_*_dev and device_xname
 1.69 19-Oct-2007  ad branches: 1.69.16;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.68 04-Mar-2007  christos branches: 1.68.2; 1.68.14; 1.68.16; 1.68.20;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.67 17-Aug-2006  christos branches: 1.67.8;
Fix all the -D*DEBUG* code that it was rotting away and did not even compile.
Mostly from Arnaud Lacombe, many thanks!
 1.66 21-May-2006  christos void casts to functions whose return values are ignored.
 1.65 24-Dec-2005  perry branches: 1.65.4; 1.65.6; 1.65.8; 1.65.12; 1.65.14;
Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.64 11-Dec-2005  christos merge ktrace-lwp.
 1.63 22-May-2005  christos branches: 1.63.2;
No 0x in front of %p...
 1.62 27-Feb-2005  perry nuke trailing whitespace
 1.61 07-Dec-2004  thorpej branches: 1.61.2; 1.61.4;
Fix a straggling reference to "struct scsi_generic" in some debug-only
code.
 1.60 07-Dec-2004  thorpej Don't use "struct scsi_generic" in a hardware-defined structure. Instead,
use an array of 12 bytes. Check the incoming CDB to see that it will fit,
and print and error and fail the command if it won't.
 1.59 24-Aug-2004  thorpej Use ANSI function decls and more use of static.
 1.58 22-Apr-2004  itojun sprintf -> snprintf
 1.57 02-Nov-2003  wiz branches: 1.57.4;
Fix some typos. From Tom Cosgrove via jmc@openbsd.
 1.56 31-Oct-2003  reinoud Rollback
 1.55 31-Oct-2003  reinoud Make it compile under gcc 2.95 again. I guess the initialisers were
stripped in the NULL = 0 -> NULL = (void *) 0 conversion.
 1.54 03-May-2003  wiz branches: 1.54.2;
DMA, not dma nor Dma.
 1.53 16-Apr-2003  thorpej * Change the APIs that handle the sync period to work with 100ths of ns,
rather than 10ths of ns. This is necessary in order to represent
Ultra320 SCSI.
* Add Ultra320 SCSI to the scsipi_syncparams[] table.

We're not going to bother bumping any version numbers with this change; only
the "hba" driver uses scsipi_sync_period_to_factor(), and the uses of
scsipi_sync_factor_to_period() are all internal to the scsipi code. Most
things just pass the factor around, which is unchanged by this.

Reviewed by Frank van der Linden.
 1.52 31-Jan-2003  thorpej Use aprint_*().
 1.51 06-Jan-2003  wiz compatibility, not compatiblity.
 1.50 25-Nov-2002  thorpej Avoid a strict-alias warning.
 1.49 05-Apr-2002  bouyer Implement mstohz() as discussed on tech-kern, and use it in SCSI drivers
to convert xs->timeout to callout() parameter.
 1.48 15-Nov-2001  lukem don't need <sys/types.h> when including <sys/param.h>
 1.47 13-Nov-2001  lukem add/cleanup RCSID
 1.46 20-Aug-2001  wiz precede, not preceed.
 1.45 19-Jul-2001  thorpej Use BUS_DMA_READ and BUS_DMA_WRITE in some obvious places.
 1.44 07-Jul-2001  thorpej branches: 1.44.2;
bcopy -> memcpy
 1.43 03-May-2001  ross Split pci and eisa/isa attachment calls, plus misc cleanup.
 1.42 25-Apr-2001  bouyer Pull up the thorpej_scsipi branch to main branch.
This is a completely rewritten scsipi_xfer execution engine, and the
associated changes to HBA drivers. Overview of changes & features:
- All xfers are queued in the mid-layer, rather than doing so in an
ad-hoc fashion in individual adapter drivers.
- Adapter/channel resource management in the mid-layer, avoids even trying
to start running an xfer if the adapter/channel doesn't have the resources.
- Better communication between the mid-layer and the adapters.
- Asynchronous event notification mechanism from adapter to mid-layer and
peripherals.
- Better peripheral queue management: freeze/thaw, sorted requeueing during
recovery, etc.
- Clean separation of peripherals, adapters, and adapter channels (no more
scsipi_link).
- Kernel thread for each scsipi_channel makes error recovery much easier
(no more dealing with interrupt context when recovering from an error).
- Mid-layer support for tagged queueing: commands can have the tag type
set explicitly, tag IDs are allocated in the mid-layer (thus eliminating
the need to use buggy tag ID allocation schemes in many adapter drivers).
- support for QUEUE FULL and CHECK CONDITION status in mid-layer; the command
will be requeued, or a REQUEST SENSE will be sent as appropriate.

Just before the merge syssrc has been tagged with thorpej_scsipi_beforemerge
 1.41 07-Mar-2001  thorpej Add BUS_DMA_STREAMING to data transfer maps.
 1.40 21-Nov-2000  soren branches: 1.40.2;
Reduce probe noise.
 1.39 14-Nov-2000  thorpej NBPG -> PAGE_SIZE
 1.38 03-Oct-2000  simonb Revert rev 1.31 of bha.c (and associtated changes in the headers and
config glue files).

Fixes PR kern/9841. Tested by Tracy J. Di Marco White with a bt948
and 6 disks.
 1.37 28-Jun-2000  mrg remove include of <vm/vm.h>. <vm/vm.h> -> <uvm/uvm_extern.h>
 1.36 30-Mar-2000  augustss branches: 1.36.4;
Remove register declarations.
 1.35 23-Mar-2000  thorpej New callout mechanism with two major improvements over the old
timeout()/untimeout() API:
- Clients supply callout handle storage, thus eliminating problems of
resource allocation.
- Insertion and removal of callouts is constant time, important as
this facility is used quite a lot in the kernel.

The old timeout()/untimeout() API has been removed from the kernel.
 1.34 12-Feb-2000  thorpej If we got an xfer from our backlog queue, don't allow sleeping; we're in
interrupt context.

XXX This is fixed properly in the thorpej_scsipi branch, but that won't
be ready for 1.5, I don't think.
 1.33 09-Oct-1999  mycroft branches: 1.33.2;
Fix prototype of bha_ccb_phsy_kv() so this compiled on the Mac again.
 1.32 01-Oct-1999  thorpej branches: 1.32.2;
Fix compilation of ISA bha front-end. PR #8528, Takahiro Kambe.
 1.31 30-Sep-1999  thorpej Rework the Buslogic SCSI driver in preparation for some pending improvements
to the SCSIPI subsystem.
- Determine more characteristics about the board, including the number
of concurrent commands that the processor can execute at a time.
- Rework memory allocation strategy so that we can do dynamic pre-allocation
of resources according to workload.

Thanks to the Linux Buslogic driver for having some useful comments.
 1.30 14-Jan-1999  ross Random compile nits in BHADEBUG code.
 1.29 09-Dec-1998  thorpej Update for changed scsipi_xfer struct.
 1.28 05-Dec-1998  mjacob Update HBAs to incorporate the new max_lun property.
 1.27 19-Nov-1998  thorpej Adapt to the new scsipi_adapter interface.
 1.26 10-Oct-1998  thorpej Garbage-collect the open_target_lu and close_target_lu entry points from
struct scsipi_adapter; they were not used.

Add a scsipi_ioctl entry point to struct scsipi_adapter. This will be
used to issue ioctl commands to the host adapters.

Inspired by PR #6090, from Matt Jacob.
 1.25 17-Aug-1998  mycroft Assign my copyrights to TNF.
 1.24 04-Jul-1998  jonathan defopt DDB.
 1.23 28-Apr-1998  mjacob Cute buglet: you can end up with zero CCBs if there were no targets
seen by the adapter. Always leave a minimum so the adapter can
finish attaching- it may be there w/o targets for a reason.
 1.22 06-Feb-1998  thorpej - Perform all necessary bus_dmamap_sync() operations.
- Greatly simplify allocation and DMA mapping of the mailbox and ccbs.
- Be more robust against resource shortage errors, and report errors better.
 1.21 04-Feb-1998  thorpej Add offset and length parameters to bus_dmamap_sync(), used for specifiying
partial syncs of a DMA mapping.
 1.20 04-Feb-1998  thorpej Add dm_mapsize to bus_dmamap_t and rename BUS_DMAMEM_NOSYNC to
BUS_DMA_COHERENT.
 1.19 28-Jan-1998  thorpej Use offsetof() from libkern.h
 1.18 12-Jan-1998  thorpej Adjust for config changes.
 1.17 04-Nov-1997  thorpej Implement a simple queueing mechanism that makes these drivers much
more robust in resource shortage situations, basically identical to
code I added to the "ahc" driver some time ago.

Thanks to Brad Spencer for the testing help.
 1.16 28-Oct-1997  thorpej When creating ccbs, be a little more informative about why we couldn't
shoud creation/initialization of a ccb fail. Also, don't panic in
these situations. Instead, simply return an error condition and allow
the caller to deal with it. It may be the case that we were able to
create one ccb what we can grab, and continue to hobble along.
 1.15 28-Oct-1997  thorpej Syncronize with changes to aha.c:

Adjust the number of ccbs allocated during initialization.
Every ccb could potentially lock 64k of memory for dma buffers if bounce
buffers are used. Instead of BHA_CCB_MAX ccbs using 2MByte, only
sc_link.openings ccbs per device are allocated. Thus we now use only
256KByte per device present.
(hannken)

Fix a couple of errors in bha_create_ccbs():
- Don't ever let the number of CCBs be creater than BHA_CCB_MAX.
- Fix a fencepost that caused the last CCB allocated to never be put
on the freelist.
(thorpej)
 1.14 27-Aug-1997  bouyer branches: 1.14.4;
Merge scsipi branch in the mainline. This add support for ATAPI devices
(currently only CD-ROM drives on i386). The sys/dev/scsipi system provides 2
busses to which devices can attach (scsibus and atapibus). This needed to
change some include files and structure names in the low level scsi drivers.
 1.13 06-Jun-1997  thorpej branches: 1.13.2; 1.13.4;
Pull thorpej-bus-dma branch into mainline.
 1.12 11-Apr-1997  thorpej branches: 1.12.2;
Initialize the scsi_link before calling bha_init(), since that is how
we check for "wide controller" now.
 1.11 28-Mar-1997  mycroft Use a temporary data structure for holding probe information, rather than a
full softc.
 1.10 13-Mar-1997  cgd fixes from Matt Jacob so that these can compile and run on the Alpha.
(aic7xxx has been tested and works on the Alpha, bha has not yet been
tested on thne Alpha.)
 1.9 17-Jan-1997  mycroft Remove a previous gratuitous change, and KNF police.
 1.8 20-Dec-1996  thorpej Deal with targets > 7 on wide Buslogic controllers. Remember the "wide"
bit from the extended setup inquiry and key off it to:
- Force synchronous negotiation on targs > 7.
- Read additional information returned by wide cards on inquire setup.
- Read sync period on targs > 7.
- Display sync period/offset on targs > 7.
- Set scsi_link.max_target to 15.
cvs: ----------------------------------------------------------------------
 1.7 10-Dec-1996  thorpej Fill in sc_link.max_target
 1.6 28-Nov-1996  thorpej The MODIFY_IOPORT command does not generate an HACC (command complete)
signal; don't wait for it.

Add a "clarification" cast to the last argument to bha_cmd() in
bha_disable_isacompat().
 1.5 05-Nov-1996  jonathan * Add command struct and modifier definitions for controlling the
ISA-compatible port space of PCI buslogic cards.

* Add call to bha_pci.c to disable the ISA-compatible ports of a PCI
device. The ISA-compatible ports are enabled by default, which
causes the card to be autoconfigured a second time as an ISA device,
which appears to deadlock the card.

* Change bha_cmd() to return the number of bytes it actually received
in response to a command, or -1 on error.

* Use heuristics (checking for bha-only registers, and checking the size
of the response to BHA_INQURE_EXTENDED) to bha_find, to make sure the
bha driver never matches an aha (Adaptec 1542 or compatible) device.

A single kernel should now boot on either Adaptec or BusLogic controllers,
provided we always probe for BusLogic devices before Adaptec devices,
but this has not yet been verified.
 1.4 21-Oct-1996  thorpej New bus.h implementation/interface:
- No more distinction between i/o-mapped and memory-mapped
devices. It's all "bus space" now, and space tags
differentiate the space with finer grain than the
bus chipset tag.
- Add memory barrier methods.
- Implement space alloc/free methods.
- Implement region read/write methods (like memcpy to/from
bus space).
This interface provides a better abstraction for dealing with
machine-independent chipset drivers.
 1.3 13-Oct-1996  christos backout kprintf changes
 1.2 10-Oct-1996  christos - printf -> kprintf, sprintf -> ksprintf
- ifdef unused variable
 1.1 31-Aug-1996  mycroft Split the BusLogic driver apart, and rename it to `bha (like BSDi).
 1.12.2.2 17-May-1997  thorpej Update for bus_dmamem_alloc() changes.
 1.12.2.1 13-May-1997  thorpej Convert to use bus dma.
 1.13.4.1 27-Aug-1997  thorpej Update marc-pcmcia branch from trunk.
 1.13.2.1 01-Jul-1997  bouyer Updates for new scsipi subsystem. Actally known to work on i386 and sparc.
 1.14.4.2 04-Nov-1997  thorpej Pull up from trunk: add a queueing mechanism to make this much more
robust in resource shortage conditions.
 1.14.4.1 28-Oct-1997  thorpej Pull up from trunk: fix fencepost errors in ccb allocation and be
more verbose/robust when ccb allocation/initialization fails.
 1.32.2.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.33.2.10 27-Mar-2001  bouyer Convert these drivers to thorpej_scsipi (untested).
 1.33.2.9 12-Mar-2001  bouyer Sync with HEAD.
 1.33.2.8 22-Nov-2000  bouyer Sync with HEAD.
 1.33.2.7 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.33.2.6 01-Nov-1999  thorpej Fixup the SC_DEBUG() stuff for the new world order.
 1.33.2.5 26-Oct-1999  thorpej Update for:

Deal a little more gracefully with the fact that xfer mode parameters
are for the I_T Nexus, and make all xfer mode updates `async events'.
 1.33.2.4 20-Oct-1999  thorpej Eliminate sleeping from adapter routines.
 1.33.2.3 19-Oct-1999  thorpej Brain'o.
 1.33.2.2 19-Oct-1999  thorpej Don't sleep waiting for a CCB; if we get to the CCB allocation phase, we're
guaranteed to have one.
 1.33.2.1 19-Oct-1999  thorpej Adapt to scsipi API changes, and add Tagged Queueing support.
 1.36.4.1 04-Oct-2000  simonb Pull up rev 1.38 (approved by thorpej):
Revert rev 1.31 of bha.c (and associtated changes in the headers and
config glue files).

Fixes PR kern/9841. Tested by Tracy J. Di Marco White with a bt948
and 6 disks.
 1.40.2.8 07-Jan-2003  thorpej Sync with HEAD.
 1.40.2.7 11-Dec-2002  thorpej Sync with HEAD.
 1.40.2.6 17-Apr-2002  nathanw Catch up to -current.
 1.40.2.5 08-Jan-2002  nathanw Catch up to -current.
 1.40.2.4 14-Nov-2001  nathanw Catch up to -current.
 1.40.2.3 24-Aug-2001  nathanw Catch up with -current.
 1.40.2.2 21-Jun-2001  nathanw Catch up to -current.
 1.40.2.1 09-Apr-2001  nathanw Catch up with -current.
 1.44.2.4 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.44.2.3 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.44.2.2 25-Aug-2001  thorpej Merge Aug 24 -current into the kqueue branch.
 1.44.2.1 03-Aug-2001  lukem update to -current
 1.54.2.7 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.54.2.6 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.54.2.5 18-Dec-2004  skrll Sync with HEAD.
 1.54.2.4 21-Sep-2004  skrll Fix the sync with head I botched.
 1.54.2.3 18-Sep-2004  skrll Sync with HEAD.
 1.54.2.2 25-Aug-2004  skrll Sync with HEAD.
 1.54.2.1 03-Aug-2004  skrll Sync with HEAD
 1.57.4.2 02-Apr-2005  he Pull up revision 1.61 (requested by thorpej in ticket #1023):
Fix a straggling reference to "struct scsi_generic" in
some debug-only code.
 1.57.4.1 02-Apr-2005  he Pull up revision 1.60 (requested by thorpej in ticket #1022):
Don't use "struct scsi_generic" in a hardware-defined structure.
Instead, use an array of 12 bytes. Check the incoming CDB to see
that it will fit, and print and error and fail the command if it
won't.
 1.61.4.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.61.2.1 29-Apr-2005  kent sync with -current
 1.63.2.4 27-Oct-2007  yamt sync with head.
 1.63.2.3 03-Sep-2007  yamt sync with head.
 1.63.2.2 30-Dec-2006  yamt sync with head.
 1.63.2.1 21-Jun-2006  yamt sync with head.
 1.65.14.1 19-Jun-2006  chap Sync with head.
 1.65.12.1 24-May-2006  tron Merge 2006-05-24 NetBSD-current into the "peter-altq" branch.
 1.65.8.2 03-Sep-2006  yamt sync with head.
 1.65.8.1 24-May-2006  yamt sync with head.
 1.65.6.1 01-Jun-2006  kardel Sync with head.
 1.65.4.1 09-Sep-2006  rpaulo sync with head
 1.67.8.1 12-Mar-2007  rmind Sync with HEAD.
 1.68.20.1 25-Oct-2007  bouyer Sync with HEAD.
 1.68.16.1 06-Nov-2007  matt sync with HEAD
 1.68.14.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.68.2.1 23-Oct-2007  ad Sync with head.
 1.69.16.1 02-Jun-2008  mjf Sync with HEAD.
 1.70.4.3 11-Aug-2010  yamt sync with head.
 1.70.4.2 11-Mar-2010  yamt sync with head
 1.70.4.1 16-May-2008  yamt sync with head.
 1.70.2.1 18-May-2008  yamt sync with head.
 1.72.4.1 05-Mar-2011  rmind sync with head
 1.72.2.1 17-Aug-2010  uebayasi Sync with HEAD.
 1.74.18.2 03-Dec-2017  jdolecek update from HEAD
 1.74.18.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.74.8.1 30-Oct-2012  yamt sync with head
 1.75.14.2 28-Aug-2017  skrll Sync with HEAD
 1.75.14.1 05-Oct-2016  skrll Sync with HEAD
 1.76.4.1 21-Apr-2017  bouyer Sync with HEAD
 1.76.2.1 20-Mar-2017  pgoyette Sync with HEAD
 1.77.30.1 21-Mar-2021  thorpej Give config_found() the same variadic arguments treatment as
config_search(). This commit only adds the CFARG_EOL sentinel
to the existing config_found() calls. Conversion of config_found_sm_loc()
and config_found_ia() call sites will be in subsequent commits.
 1.78.8.1 04-Aug-2021  thorpej Adapt to CFARGS().
 1.21 26-Feb-2017  jdolecek got 'bad mbi comp_stat 5' during DIOCGCACHE under Parallels, according
to linux driver it's possible status when controller thinks the CCB is invalid;
handle same as BHA_MBI_ABORT/BHA_MBI_UNKNOWN i.e. just clear the CCB anyway
 1.20 28-Apr-2008  martin branches: 1.20.44; 1.20.64; 1.20.68; 1.20.72;
Remove clause 3 and 4 from TNF licenses
 1.19 11-Dec-2005  christos branches: 1.19.70; 1.19.72; 1.19.74;
merge ktrace-lwp.
 1.18 21-Feb-2005  thorpej Part 1 of a cleanup pass over the SCSI subsystem. The aim is to name
everything "scsi_*", since we really are talking about the SCSI command
set, ATAPI transport not withstanding. Improve the names of many structures,
and prepend "SCSI_" onto all SCSI command opcodes. Place items described
by the SCSI Primary Commands document into scsi_spc.h.
 1.17 02-Nov-2003  wiz branches: 1.17.8; 1.17.10;
Fix some typos. From Tom Cosgrove via jmc@openbsd.
 1.16 25-Apr-2001  bouyer branches: 1.16.22;
Pull up the thorpej_scsipi branch to main branch.
This is a completely rewritten scsipi_xfer execution engine, and the
associated changes to HBA drivers. Overview of changes & features:
- All xfers are queued in the mid-layer, rather than doing so in an
ad-hoc fashion in individual adapter drivers.
- Adapter/channel resource management in the mid-layer, avoids even trying
to start running an xfer if the adapter/channel doesn't have the resources.
- Better communication between the mid-layer and the adapters.
- Asynchronous event notification mechanism from adapter to mid-layer and
peripherals.
- Better peripheral queue management: freeze/thaw, sorted requeueing during
recovery, etc.
- Clean separation of peripherals, adapters, and adapter channels (no more
scsipi_link).
- Kernel thread for each scsipi_channel makes error recovery much easier
(no more dealing with interrupt context when recovering from an error).
- Mid-layer support for tagged queueing: commands can have the tag type
set explicitly, tag IDs are allocated in the mid-layer (thus eliminating
the need to use buggy tag ID allocation schemes in many adapter drivers).
- support for QUEUE FULL and CHECK CONDITION status in mid-layer; the command
will be requeued, or a REQUEST SENSE will be sent as appropriate.

Just before the merge syssrc has been tagged with thorpej_scsipi_beforemerge
 1.15 03-Oct-2000  simonb branches: 1.15.2;
Revert rev 1.31 of bha.c (and associtated changes in the headers and
config glue files).

Fixes PR kern/9841. Tested by Tracy J. Di Marco White with a bt948
and 6 disks.
 1.14 23-Dec-1999  wrstuden branches: 1.14.4;
Make the bitfields in here work on big-endian machines. How this ever
worked is unclear.

Patch from thorpej, tested by me.
 1.13 30-Sep-1999  thorpej branches: 1.13.2;
Rework the Buslogic SCSI driver in preparation for some pending improvements
to the SCSIPI subsystem.
- Determine more characteristics about the board, including the number
of concurrent commands that the processor can execute at a time.
- Rework memory allocation strategy so that we can do dynamic pre-allocation
of resources according to workload.

Thanks to the Linux Buslogic driver for having some useful comments.
 1.12 17-Aug-1998  mycroft Assign my copyrights to TNF.
 1.11 06-Feb-1998  thorpej - Perform all necessary bus_dmamap_sync() operations.
- Greatly simplify allocation and DMA mapping of the mailbox and ccbs.
- Be more robust against resource shortage errors, and report errors better.
 1.10 28-Oct-1997  thorpej Reply from an INQUIRE DEVICES is a lun map.
 1.9 09-Sep-1997  mycroft branches: 1.9.2;
Make `hashkey' unsigned.
 1.8 27-Aug-1997  bouyer Merge scsipi branch in the mainline. This add support for ATAPI devices
(currently only CD-ROM drives on i386). The sys/dev/scsipi system provides 2
busses to which devices can attach (scsibus and atapibus). This needed to
change some include files and structure names in the low level scsi drivers.
 1.7 06-Jun-1997  thorpej branches: 1.7.2; 1.7.4;
Pull thorpej-bus-dma branch into mainline.
 1.6 04-Jan-1997  jonathan branches: 1.6.8;
typo in definition of extended-geometry register.
 1.5 20-Dec-1996  thorpej Deal with targets > 7 on wide Buslogic controllers. Remember the "wide"
bit from the extended setup inquiry and key off it to:
- Force synchronous negotiation on targs > 7.
- Read additional information returned by wide cards on inquire setup.
- Read sync period on targs > 7.
- Display sync period/offset on targs > 7.
- Set scsi_link.max_target to 15.
cvs: ----------------------------------------------------------------------
 1.4 20-Dec-1996  jonathan Add missing fields to the extended_inquire reply struct.
Fixes probing of aha154x's, and provides wide/ultra bits for the MI scsi code.
 1.3 05-Nov-1996  jonathan * Add command struct and modifier definitions for controlling the
ISA-compatible port space of PCI buslogic cards.

* Add call to bha_pci.c to disable the ISA-compatible ports of a PCI
device. The ISA-compatible ports are enabled by default, which
causes the card to be autoconfigured a second time as an ISA device,
which appears to deadlock the card.

* Change bha_cmd() to return the number of bytes it actually received
in response to a command, or -1 on error.

* Use heuristics (checking for bha-only registers, and checking the size
of the response to BHA_INQURE_EXTENDED) to bha_find, to make sure the
bha driver never matches an aha (Adaptec 1542 or compatible) device.

A single kernel should now boot on either Adaptec or BusLogic controllers,
provided we always probe for BusLogic devices before Adaptec devices,
but this has not yet been verified.
 1.2 01-Sep-1996  mycroft Minor changes.
 1.1 31-Aug-1996  mycroft Split the BusLogic driver apart, and rename it to `bha (like BSDi).
 1.6.8.1 13-May-1997  thorpej Convert to use bus dma.
 1.7.4.2 16-Sep-1997  thorpej Update marc-pcmcia branch from trunk.
 1.7.4.1 27-Aug-1997  thorpej Update marc-pcmcia branch from trunk.
 1.7.2.1 01-Jul-1997  bouyer Updates for new scsipi subsystem. Actally known to work on i386 and sparc.
 1.9.2.1 29-Oct-1997  thorpej Pull up from trunk: reply from INQUIRE DEVICES is a lun map.
 1.13.2.3 27-Mar-2001  bouyer Convert these drivers to thorpej_scsipi (untested).
 1.13.2.2 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.13.2.1 19-Oct-1999  thorpej Adapt to scsipi API changes, and add Tagged Queueing support.
 1.14.4.1 04-Oct-2000  simonb Pull up rev 1.15 (approved by thorpej):
Revert rev 1.31 of bha.c (and associtated changes in the headers and
config glue files).

Fixes PR kern/9841. Tested by Tracy J. Di Marco White with a bt948
and 6 disks.
 1.15.2.1 21-Jun-2001  nathanw Catch up to -current.
 1.16.22.4 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.16.22.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.16.22.2 18-Sep-2004  skrll Sync with HEAD.
 1.16.22.1 03-Aug-2004  skrll Sync with HEAD
 1.17.10.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.17.8.1 29-Apr-2005  kent sync with -current
 1.19.74.1 16-May-2008  yamt sync with head.
 1.19.72.1 18-May-2008  yamt sync with head.
 1.19.70.1 02-Jun-2008  mjf Sync with HEAD.
 1.20.72.1 21-Apr-2017  bouyer Sync with HEAD
 1.20.68.1 20-Mar-2017  pgoyette Sync with HEAD
 1.20.64.1 28-Aug-2017  skrll Sync with HEAD
 1.20.44.1 03-Dec-2017  jdolecek update from HEAD
 1.25 27-Oct-2012  chs split device_t/softc for all remaining drivers.
replace "struct device *" with "device_t".
use device_xname(), device_unit(), etc.
 1.24 28-Apr-2008  martin branches: 1.24.34; 1.24.44;
Remove clause 3 and 4 from TNF licenses
 1.23 11-Dec-2005  christos branches: 1.23.70; 1.23.72; 1.23.74;
merge ktrace-lwp.
 1.22 24-Aug-2004  thorpej Use ANSI function decls and more use of static.
 1.21 03-May-2001  ross branches: 1.21.22;
Split pci and eisa/isa attachment calls, plus misc cleanup.
 1.20 25-Apr-2001  bouyer Pull up the thorpej_scsipi branch to main branch.
This is a completely rewritten scsipi_xfer execution engine, and the
associated changes to HBA drivers. Overview of changes & features:
- All xfers are queued in the mid-layer, rather than doing so in an
ad-hoc fashion in individual adapter drivers.
- Adapter/channel resource management in the mid-layer, avoids even trying
to start running an xfer if the adapter/channel doesn't have the resources.
- Better communication between the mid-layer and the adapters.
- Asynchronous event notification mechanism from adapter to mid-layer and
peripherals.
- Better peripheral queue management: freeze/thaw, sorted requeueing during
recovery, etc.
- Clean separation of peripherals, adapters, and adapter channels (no more
scsipi_link).
- Kernel thread for each scsipi_channel makes error recovery much easier
(no more dealing with interrupt context when recovering from an error).
- Mid-layer support for tagged queueing: commands can have the tag type
set explicitly, tag IDs are allocated in the mid-layer (thus eliminating
the need to use buggy tag ID allocation schemes in many adapter drivers).
- support for QUEUE FULL and CHECK CONDITION status in mid-layer; the command
will be requeued, or a REQUEST SENSE will be sent as appropriate.

Just before the merge syssrc has been tagged with thorpej_scsipi_beforemerge
 1.19 03-Oct-2000  simonb branches: 1.19.2;
Revert rev 1.31 of bha.c (and associtated changes in the headers and
config glue files).

Fixes PR kern/9841. Tested by Tracy J. Di Marco White with a bt948
and 6 disks.
 1.18 19-Apr-2000  enami branches: 1.18.4;
Calculate an offset of mailbox_in correctly by renaming BHA_MBO_OFFSET
to BHA_MBX_OFFSET and using it also for mailbox_in. Since all mailboxes
should be placed in a single continuous memory due to a hardware limitation,
an offset of any mailbox can be/should be calculated using a same expression.
 1.17 27-Mar-2000  kleink Cosmetical nit in previous.
 1.16 26-Mar-2000  kleink Merge parts of chs-ubc2 into the trunk:
* Remove the casts to vaddr_t from the round_page() and trunc_page() macros to
make them type-generic, which is necessary i.e. to operate on file offsets
without truncating them.
* In due course, cast pointer arguments to these macros to an appropriate
integral type (paddr_t, vaddr_t).

Originally done by Chuck Silvers, updated by myself.
 1.15 01-Oct-1999  thorpej branches: 1.15.2;
Fix compilation of ISA bha front-end. PR #8528, Takahiro Kambe.
 1.14 30-Sep-1999  thorpej Rework the Buslogic SCSI driver in preparation for some pending improvements
to the SCSIPI subsystem.
- Determine more characteristics about the board, including the number
of concurrent commands that the processor can execute at a time.
- Rework memory allocation strategy so that we can do dynamic pre-allocation
of resources according to workload.

Thanks to the Linux Buslogic driver for having some useful comments.
 1.13 09-Dec-1998  thorpej Update for changed scsipi_xfer struct.
 1.12 19-Nov-1998  thorpej Adapt to the new scsipi_adapter interface.
 1.11 15-Aug-1998  mycroft Assign my copyrights to TNF.
 1.10 06-Feb-1998  thorpej - Perform all necessary bus_dmamap_sync() operations.
- Greatly simplify allocation and DMA mapping of the mailbox and ccbs.
- Be more robust against resource shortage errors, and report errors better.
 1.9 04-Nov-1997  thorpej Implement a simple queueing mechanism that makes these drivers much
more robust in resource shortage situations, basically identical to
code I added to the "ahc" driver some time ago.

Thanks to Brad Spencer for the testing help.
 1.8 27-Aug-1997  bouyer branches: 1.8.4;
Merge scsipi branch in the mainline. This add support for ATAPI devices
(currently only CD-ROM drives on i386). The sys/dev/scsipi system provides 2
busses to which devices can attach (scsibus and atapibus). This needed to
change some include files and structure names in the low level scsi drivers.
 1.7 06-Jun-1997  thorpej branches: 1.7.2; 1.7.4;
Pull thorpej-bus-dma branch into mainline.
 1.6 28-Mar-1997  mycroft branches: 1.6.2;
Use a temporary data structure for holding probe information, rather than a
full softc.
 1.5 20-Dec-1996  thorpej Deal with targets > 7 on wide Buslogic controllers. Remember the "wide"
bit from the extended setup inquiry and key off it to:
- Force synchronous negotiation on targs > 7.
- Read additional information returned by wide cards on inquire setup.
- Read sync period on targs > 7.
- Display sync period/offset on targs > 7.
- Set scsi_link.max_target to 15.
cvs: ----------------------------------------------------------------------
 1.4 05-Nov-1996  jonathan * Add command struct and modifier definitions for controlling the
ISA-compatible port space of PCI buslogic cards.

* Add call to bha_pci.c to disable the ISA-compatible ports of a PCI
device. The ISA-compatible ports are enabled by default, which
causes the card to be autoconfigured a second time as an ISA device,
which appears to deadlock the card.

* Change bha_cmd() to return the number of bytes it actually received
in response to a command, or -1 on error.

* Use heuristics (checking for bha-only registers, and checking the size
of the response to BHA_INQURE_EXTENDED) to bha_find, to make sure the
bha driver never matches an aha (Adaptec 1542 or compatible) device.

A single kernel should now boot on either Adaptec or BusLogic controllers,
provided we always probe for BusLogic devices before Adaptec devices,
but this has not yet been verified.
 1.3 21-Oct-1996  thorpej New bus.h implementation/interface:
- No more distinction between i/o-mapped and memory-mapped
devices. It's all "bus space" now, and space tags
differentiate the space with finer grain than the
bus chipset tag.
- Add memory barrier methods.
- Implement space alloc/free methods.
- Implement region read/write methods (like memcpy to/from
bus space).
This interface provides a better abstraction for dealing with
machine-independent chipset drivers.
 1.2 01-Sep-1996  mycroft Minor changes.
 1.1 31-Aug-1996  mycroft Split the BusLogic driver apart, and rename it to `bha (like BSDi).
 1.6.2.1 13-May-1997  thorpej Convert to use bus dma.
 1.7.4.1 27-Aug-1997  thorpej Update marc-pcmcia branch from trunk.
 1.7.2.1 01-Jul-1997  bouyer Updates for new scsipi subsystem. Actally known to work on i386 and sparc.
 1.8.4.1 04-Nov-1997  thorpej Pull up from trunk: add a queueing mechanism to make this much more
robust in resource shortage conditions.
 1.15.2.3 27-Mar-2001  bouyer Convert these drivers to thorpej_scsipi (untested).
 1.15.2.2 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.15.2.1 19-Oct-1999  thorpej Adapt to scsipi API changes, and add Tagged Queueing support.
 1.18.4.1 04-Oct-2000  simonb Pull up rev 1.19 (approved by thorpej):
Revert rev 1.31 of bha.c (and associtated changes in the headers and
config glue files).

Fixes PR kern/9841. Tested by Tracy J. Di Marco White with a bt948
and 6 disks.
 1.19.2.1 21-Jun-2001  nathanw Catch up to -current.
 1.21.22.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.21.22.2 18-Sep-2004  skrll Sync with HEAD.
 1.21.22.1 25-Aug-2004  skrll Sync with HEAD.
 1.23.74.1 16-May-2008  yamt sync with head.
 1.23.72.1 18-May-2008  yamt sync with head.
 1.23.70.1 02-Jun-2008  mjf Sync with HEAD.
 1.24.44.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.24.34.1 30-Oct-2012  yamt sync with head
 1.4 13-Sep-2025  thorpej Re-reactor more common code.
 1.3 13-Sep-2025  thorpej Don't put SPI- or I2C-specific stuff in common code.
 1.2 16-Apr-2023  brad Do not create the sysctl tree if the initial setup of the chip fails.
 1.1 03-Dec-2022  brad branches: 1.1.2;


Split the BMP280 / BME280 driver into common code and create I2C and
SPI attachments.
 1.1.2.1 20-Apr-2023  martin Pull up following revision(s) (requested by brad in ticket #144):

sys/dev/ic/bmx280.c: revision 1.2

Do not create the sysctl tree if the initial setup of the chip fails.
 1.1 03-Dec-2022  brad Split the BMP280 / BME280 driver into common code and create I2C and
SPI attachments.
 1.3 13-Sep-2025  thorpej Re-reactor more common code.
 1.2 13-Sep-2025  thorpej Don't put SPI- or I2C-specific stuff in common code.
 1.1 03-Dec-2022  brad Split the BMP280 / BME280 driver into common code and create I2C and
SPI attachments.
 1.3 11-Dec-2005  christos merge ktrace-lwp.
 1.2 27-Feb-2005  perry nuke trailing whitespace
 1.1 28-Oct-1998  nisimura branches: 1.1.46; 1.1.54; 1.1.56;
- Brooktree Bt459 135 MHz Monolithic CMOS 256x64 Color Palette RAMDAC.
- Brooktree Bt431 Monolithic CMOS 64x64 Pixel Cursor Generator.
- Inmos IMS G332 Color Video Controller.
 1.1.56.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.1.54.1 29-Apr-2005  kent sync with -current
 1.1.46.1 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.4 11-Dec-2005  christos merge ktrace-lwp.
 1.3 27-Feb-2005  perry nuke trailing whitespace
 1.2 15-Dec-1999  ad branches: 1.2.28; 1.2.36; 1.2.38;
- Change prefix for Bt459 register defs to BT459_IREG to indicate that
these are indirectly accessed registers.
- Add defs for directly accessed registers to bt459reg.h.
 1.1 28-Oct-1998  nisimura branches: 1.1.12; 1.1.18;
- Brooktree Bt459 135 MHz Monolithic CMOS 256x64 Color Palette RAMDAC.
- Brooktree Bt431 Monolithic CMOS 64x64 Pixel Cursor Generator.
- Inmos IMS G332 Color Video Controller.
 1.1.18.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.1.12.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.2.38.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.2.36.1 29-Apr-2005  kent sync with -current
 1.2.28.1 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.1 24-Jun-2010  macallan branches: 1.1.2; 1.1.4; 1.1.6;
register definitions for Brooktree Bt461 and Bt462 RAMDACs, used on CG12 and
others
 1.1.6.2 17-Aug-2010  uebayasi Sync with HEAD.
 1.1.6.1 24-Jun-2010  uebayasi file bt462reg.h was added on branch uebayasi-xip on 2010-08-17 06:46:09 +0000
 1.1.4.2 11-Aug-2010  yamt sync with head.
 1.1.4.1 24-Jun-2010  yamt file bt462reg.h was added on branch yamt-nfs-mp on 2010-08-11 22:53:24 +0000
 1.1.2.2 03-Jul-2010  rmind sync with head
 1.1.2.1 24-Jun-2010  rmind file bt462reg.h was added on branch rmind-uvmplock on 2010-07-03 01:19:35 +0000
 1.18 24-Jan-2018  riastradh Fix integer overflows noted by Silvio Cesare of InfoSect.

Someone^TM should name these idioms so we can eliminate this class of
copypasta bug.
 1.17 24-Jun-2013  riastradh Use static inline. Fixes i386/ALL and something else I've forgetten.
 1.16 12-Feb-2012  matt branches: 1.16.6;
Change old-style function defintions to C89 prototypes.

Approved by releng.
 1.15 13-Nov-2010  uebayasi branches: 1.15.8; 1.15.12;
Don't pull in the whole uvm(9) API to access only PAGE_SIZE and
some other constants. These are provided by sys/param.h now.
 1.14 14-Mar-2009  dsl branches: 1.14.4;
Change about 4500 of the K&R function definitions to ANSI ones.
There are still about 1600 left, but they have ',' or /* ... */
in the actual variable definitions - which my awk script doesn't handle.
There are also many that need () -> (void).
(The script does handle misordered arguments.)
 1.13 28-Apr-2008  martin branches: 1.13.8; 1.13.14;
Remove clause 3 and 4 from TNF licenses
 1.12 11-Dec-2005  christos branches: 1.12.70; 1.12.72; 1.12.74;
merge ktrace-lwp.
 1.11 27-Feb-2005  perry nuke trailing whitespace
 1.10 04-Feb-2005  perry de-__P
 1.9 13-Nov-2003  chs branches: 1.9.8; 1.9.10;
eliminate uvm_useracc() in favor of checking the return value of
copyin() or copyout().

uvm_useracc() tells us whether the mapping permissions allow access to
the desired part of an address space, and many callers assume that
this is the same as knowing whether an attempt to access that part of
the address space will succeed. however, access to user space can
fail for reasons other than insufficient permission, most notably that
paging in any non-resident data can fail due to i/o errors. most of
the callers of uvm_useracc() make the above incorrect assumption. the
rest are all misguided optimizations, which optimize for the case
where an operation will fail. we'd rather optimize for operations
succeeding, in which case we should just attempt the access and handle
failures due to insufficient permissions the same way we handle i/o
errors. since there appear to be no good uses of uvm_useracc(), we'll
just remove it.
 1.8 03-Aug-2002  itojun branches: 1.8.6;
correct range check, have overflow check, fix type mismatches,
for cmap args and some other calls. from openbsd
 1.7 12-Dec-2001  elric branches: 1.7.8; 1.7.10;
Update the ramdac interface to be allow the setting of dotclocks. This is
required to support the driver in ibm561.c.
 1.6 13-Nov-2001  lukem add/cleanup RCSID
 1.5 18-Sep-2001  wiz Give initiali[sz]e all the "i"s it deserves.
 1.4 05-Aug-2001  jdolecek branches: 1.4.2;
remove unnecessary casts, make variable types consistent with the
respective wsdisplay_cmap member
no functional change, stylistic only
 1.3 28-Jun-2000  mrg branches: 1.3.2; 1.3.4; 1.3.6;
remove include of <vm/vm.h>. <vm/vm.h> -> <uvm/uvm_extern.h>
 1.2 13-Jun-2000  nathanw Arrange to use the right RAMDAC cookie at console initialization time.

[I thought I committed this months ago....]
 1.1 02-Apr-2000  nathanw branches: 1.1.2;
Move bt463 code to dev/ic and adapt to the new ramdac interface.
Set default window type to 24-bit truecolor.
Correctly set pseudocolor mode.
 1.1.2.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.3.6.3 06-Sep-2002  jdolecek sync kqueue branch with HEAD
 1.3.6.2 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.3.6.1 25-Aug-2001  thorpej Merge Aug 24 -current into the kqueue branch.
 1.3.4.5 13-Aug-2002  nathanw Catch up to -current.
 1.3.4.4 08-Jan-2002  nathanw Catch up to -current.
 1.3.4.3 14-Nov-2001  nathanw Catch up to -current.
 1.3.4.2 21-Sep-2001  nathanw Catch up to -current.
 1.3.4.1 24-Aug-2001  nathanw Catch up with -current.
 1.3.2.2 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.3.2.1 28-Jun-2000  bouyer file bt463.c was added on branch thorpej_scsipi on 2000-11-20 11:40:24 +0000
 1.4.2.1 01-Oct-2001  fvdl Catch up with -current.
 1.7.10.1 07-Aug-2002  lukem Pull up revision 1.8 (requested by itojun in ticket #616):
correct range check, have overflow check, fix type mismatches,
for cmap args and some other calls. from openbsd
 1.7.8.1 29-Aug-2002  gehenna catch up with -current.
 1.8.6.5 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.8.6.4 04-Feb-2005  skrll Sync with HEAD.
 1.8.6.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.8.6.2 18-Sep-2004  skrll Sync with HEAD.
 1.8.6.1 03-Aug-2004  skrll Sync with HEAD
 1.9.10.2 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.9.10.1 12-Feb-2005  yamt sync with head.
 1.9.8.1 29-Apr-2005  kent sync with -current
 1.12.74.2 04-May-2009  yamt sync with head.
 1.12.74.1 16-May-2008  yamt sync with head.
 1.12.72.1 18-May-2008  yamt sync with head.
 1.12.70.1 02-Jun-2008  mjf Sync with HEAD.
 1.13.14.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.13.8.1 28-Apr-2009  skrll Sync with HEAD.
 1.14.4.1 05-Mar-2011  rmind sync with head
 1.15.12.1 18-Feb-2012  mrg merge to -current.
 1.15.8.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.15.8.1 17-Apr-2012  yamt sync with head
 1.16.6.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.2 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.1 18-Aug-1998  thorpej branches: 1.1.144; 1.1.146; 1.1.148;
Registers for the Brooktree Bt463 RAMDAC.
 1.1.148.1 16-May-2008  yamt sync with head.
 1.1.146.1 18-May-2008  yamt sync with head.
 1.1.144.1 02-Jun-2008  mjf Sync with HEAD.
 1.4 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.3 11-Dec-2005  christos branches: 1.3.70; 1.3.72; 1.3.74;
merge ktrace-lwp.
 1.2 04-Feb-2005  perry de-__P
 1.1 02-Apr-2000  nathanw branches: 1.1.6; 1.1.30; 1.1.38; 1.1.40;
Move bt463 code to dev/ic and adapt to the new ramdac interface.
Set default window type to 24-bit truecolor.
Correctly set pseudocolor mode.
 1.1.40.1 12-Feb-2005  yamt sync with head.
 1.1.38.1 29-Apr-2005  kent sync with -current
 1.1.30.1 04-Feb-2005  skrll Sync with HEAD.
 1.1.6.2 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.1.6.1 02-Apr-2000  bouyer file bt463var.h was added on branch thorpej_scsipi on 2000-11-20 11:40:24 +0000
 1.3.74.1 16-May-2008  yamt sync with head.
 1.3.72.1 18-May-2008  yamt sync with head.
 1.3.70.1 02-Jun-2008  mjf Sync with HEAD.
 1.18 24-Jan-2018  riastradh Fix integer overflows noted by Silvio Cesare of InfoSect.

Someone^TM should name these idioms so we can eliminate this class of
copypasta bug.
 1.17 24-Jun-2013  riastradh Use static inline. Fixes i386/ALL and something else I've forgetten.
 1.16 12-Feb-2012  matt branches: 1.16.6;
Change old-style function defintions to C89 prototypes.

Approved by releng.
 1.15 13-Nov-2010  uebayasi branches: 1.15.8; 1.15.12;
Don't pull in the whole uvm(9) API to access only PAGE_SIZE and
some other constants. These are provided by sys/param.h now.
 1.14 14-Mar-2009  dsl branches: 1.14.4;
Change about 4500 of the K&R function definitions to ANSI ones.
There are still about 1600 left, but they have ',' or /* ... */
in the actual variable definitions - which my awk script doesn't handle.
There are also many that need () -> (void).
(The script does handle misordered arguments.)
 1.13 11-Dec-2005  christos branches: 1.13.74; 1.13.84; 1.13.90;
merge ktrace-lwp.
 1.12 27-Feb-2005  perry nuke trailing whitespace
 1.11 04-Feb-2005  perry de-__P
 1.10 13-Nov-2003  chs branches: 1.10.8; 1.10.10;
eliminate uvm_useracc() in favor of checking the return value of
copyin() or copyout().

uvm_useracc() tells us whether the mapping permissions allow access to
the desired part of an address space, and many callers assume that
this is the same as knowing whether an attempt to access that part of
the address space will succeed. however, access to user space can
fail for reasons other than insufficient permission, most notably that
paging in any non-resident data can fail due to i/o errors. most of
the callers of uvm_useracc() make the above incorrect assumption. the
rest are all misguided optimizations, which optimize for the case
where an operation will fail. we'd rather optimize for operations
succeeding, in which case we should just attempt the access and handle
failures due to insufficient permissions the same way we handle i/o
errors. since there appear to be no good uses of uvm_useracc(), we'll
just remove it.
 1.9 03-Aug-2002  itojun branches: 1.9.6;
correct range check, have overflow check, fix type mismatches,
for cmap args and some other calls. from openbsd
 1.8 12-Dec-2001  elric branches: 1.8.8; 1.8.10;
Update the ramdac interface to be allow the setting of dotclocks. This is
required to support the driver in ibm561.c.
 1.7 13-Nov-2001  lukem add/cleanup RCSID
 1.6 18-Sep-2001  wiz Give initiali[sz]e all the "i"s it deserves.
 1.5 05-Aug-2001  jdolecek branches: 1.5.2;
remove unnecessary casts, make variable types consistent with the
respective wsdisplay_cmap member
no functional change, stylistic only
 1.4 07-Jul-2001  thorpej branches: 1.4.2;
bzero -> memset
 1.3 28-Jun-2000  mrg branches: 1.3.2; 1.3.4;
remove include of <vm/vm.h>. <vm/vm.h> -> <uvm/uvm_extern.h>
 1.2 02-Apr-2000  nathanw Adapt to change in ramdac interface.
 1.1 04-Mar-2000  elric Graphics card independant Bt485 code, derived from dev/pci/tga_bt485.c.
 1.3.4.5 13-Aug-2002  nathanw Catch up to -current.
 1.3.4.4 08-Jan-2002  nathanw Catch up to -current.
 1.3.4.3 14-Nov-2001  nathanw Catch up to -current.
 1.3.4.2 21-Sep-2001  nathanw Catch up to -current.
 1.3.4.1 24-Aug-2001  nathanw Catch up with -current.
 1.3.2.2 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.3.2.1 28-Jun-2000  bouyer file bt485.c was added on branch thorpej_scsipi on 2000-11-20 11:40:25 +0000
 1.4.2.3 06-Sep-2002  jdolecek sync kqueue branch with HEAD
 1.4.2.2 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.4.2.1 25-Aug-2001  thorpej Merge Aug 24 -current into the kqueue branch.
 1.5.2.1 01-Oct-2001  fvdl Catch up with -current.
 1.8.10.1 07-Aug-2002  lukem Pull up revision 1.9 (requested by itojun in ticket #616):
correct range check, have overflow check, fix type mismatches,
for cmap args and some other calls. from openbsd
 1.8.8.1 29-Aug-2002  gehenna catch up with -current.
 1.9.6.5 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.9.6.4 04-Feb-2005  skrll Sync with HEAD.
 1.9.6.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.9.6.2 18-Sep-2004  skrll Sync with HEAD.
 1.9.6.1 03-Aug-2004  skrll Sync with HEAD
 1.10.10.2 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.10.10.1 12-Feb-2005  yamt sync with head.
 1.10.8.1 29-Apr-2005  kent sync with -current
 1.13.90.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.13.84.1 28-Apr-2009  skrll Sync with HEAD.
 1.13.74.1 04-May-2009  yamt sync with head.
 1.14.4.1 05-Mar-2011  rmind sync with head
 1.15.12.1 18-Feb-2012  mrg merge to -current.
 1.15.8.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.15.8.1 17-Apr-2012  yamt sync with head
 1.16.6.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.3 11-Dec-2005  christos merge ktrace-lwp.
 1.2 27-Feb-2005  perry nuke trailing whitespace
 1.1 15-Apr-1998  drochner branches: 1.1.48; 1.1.56; 1.1.58;
The "mi" TGA driver. It's still not of much use on anything but alpha
because it depends on initialization by the firmware.
Further, an mi mmap() is needed...
 1.1.58.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.1.56.1 29-Apr-2005  kent sync with -current
 1.1.48.1 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.4 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.3 11-Dec-2005  christos branches: 1.3.70; 1.3.72; 1.3.74;
merge ktrace-lwp.
 1.2 04-Feb-2005  perry de-__P
 1.1 04-Mar-2000  elric branches: 1.1.6; 1.1.30; 1.1.38; 1.1.40;
Graphics card independant Bt485 code, derived from dev/pci/tga_bt485.c.
 1.1.40.1 12-Feb-2005  yamt sync with head.
 1.1.38.1 29-Apr-2005  kent sync with -current
 1.1.30.1 04-Feb-2005  skrll Sync with HEAD.
 1.1.6.2 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.1.6.1 04-Mar-2000  bouyer file bt485var.h was added on branch thorpej_scsipi on 2000-11-20 11:40:25 +0000
 1.3.74.1 16-May-2008  yamt sync with head.
 1.3.72.1 18-May-2008  yamt sync with head.
 1.3.70.1 02-Jun-2008  mjf Sync with HEAD.
 1.9 16-Jan-2008  jmcneill Don't assume that sizeof(long) == sizeof(int); makes bktr work on amd64.
 1.8 04-Mar-2007  christos branches: 1.8.16; 1.8.22; 1.8.28;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.7 03-May-2003  wiz branches: 1.7.18; 1.7.54; 1.7.56; 1.7.60;
DMA, not dma nor Dma.
 1.6 12-Mar-2003  wiz Merge first bktr-sf import.
 1.5 21-Feb-2003  tsutsui hz -> Hz
 1.4 30-Dec-2000  wiz Fix pasto in comment.
 1.3 30-Dec-2000  wiz Merge 2.18 to trunk.
 1.2 07-May-2000  wiz branches: 1.2.6;
multiple inclusion protection
 1.1 07-May-2000  wiz branches: 1.1.1;
Initial revision
 1.1.1.4 12-Mar-2003  wiz Import of current state of bktr(4) in sourceforge repository.
Changes since last import:
. lots of whitespace cleanups
. typo fixes (e.g. hz, compatibilty)
. fix brightness ioctl return value
. wait for int ready using DELAY() instead of tight loop
 1.1.1.3 30-Dec-2000  wiz Import release 2.18 of the bktr driver. Changes since 2.17:
o Add new ioctls to allow userland programs fuller access to the I2C
bus, BT848_MSP_READ BT848_MSP_WRITE and BT848_MSP_RESET.
o Add tuner type 0x2a. Remove 0x2c which was incorrect.
o Christian Gusenbauer <Christian.Gusenbauer@netway.at> added support
for audio on Hauppauge cards without the audio mux. The MSP is used
for audio selection. (the 44xxx models)
 1.1.1.2 28-Oct-2000  wiz Import release 2.17 of the bktr driver.
Changes: Integration of some NetBSD changes. (FreeBSD version now is also
usable as a KLD (~= LKM).)
 1.1.1.1 07-May-2000  wiz Import of (finally busspaced) bktr-driver from FreeBSD (part 2).
This version is from the location specified in the README, modified
by bktr2netbsd, to be committed later.
 1.2.6.3 05-Jan-2001  bouyer Sync with HEAD
 1.2.6.2 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.2.6.1 07-May-2000  bouyer file bt8xx.h was added on branch thorpej_scsipi on 2000-11-20 11:40:25 +0000
 1.7.60.1 03-Jun-2008  skrll Sync with netbsd-4.
 1.7.56.1 12-Mar-2007  rmind Sync with HEAD.
 1.7.54.1 21-Jan-2008  bouyer Pull up following revision(s) (requested by jmcneill in ticket #1046):
sys/dev/pci/bktr/bktr_reg.h: revision 1.18
sys/dev/pci/bktr/bktr_audio.c: revision 1.18
sys/dev/pci/bktr/bktr_os.c: revision 1.49
sys/dev/pci/bktr/bktr_core.c: revision 1.46
sys/dev/ic/bt8xx.h: revision 1.9
sys/dev/pci/bktr/bktr_core.h: revision 1.10
Don't assume that sizeof(long) == sizeof(int); makes bktr work on amd64.
 1.7.18.2 21-Jan-2008  yamt sync with head
 1.7.18.1 03-Sep-2007  yamt sync with head.
 1.8.28.1 19-Jan-2008  bouyer Sync with HEAD
 1.8.22.1 18-Feb-2008  mjf Sync with HEAD.
 1.8.16.1 23-Mar-2008  matt sync with HEAD
 1.36 31-Dec-2023  gutteridge bwfm.c: KNF a comment (spaces->tabs)
 1.35 01-Aug-2023  mrg fix simple mis-matched function prototype and definitions.

most of these are like, eg

void foo(int[2]);

with either of these

void foo(int*) { ... }
void foo(int[]) { ... }

in some cases (such as stat or utimes* calls found in our header files),
we now match standard definition from opengroup.

found by GCC 12.
 1.34 04-Dec-2022  mlelstv Make power save mode configurable by ifconfig, now defaults to non-powersave
like other interfaces.
Remove cargo-culted check for manual roaming.
 1.33 03-Dec-2022  mlelstv Fix bug in protocol parser that often caused fatal 'checksum error'.
Defer power save setting to interface start.
More verbose on errors.
Allow build without FDT.
 1.32 14-Mar-2022  mlelstv Add OpenBSD to code to optionally load CLM (Country Locale Matrix) files.
 1.31 16-Jun-2021  riastradh if_attach and if_initialize cannot fail, don't test return value

These were originally made failable back in 2017 when if_initialize
allocated a softint in every interface for link state changes, so
that it could fail gracefully instead of panicking:

https://mail-index.NetBSD.org/source-changes/2017/10/23/msg089053.html

However, this spawned many seldom- or never-tested error branches,
which are risky to have around. And that softint in every interface
has since been replaced by a single global workqueue, because link
state changes require thread context but not low latency or high
throughput:

https://mail-index.NetBSD.org/source-changes/2020/02/06/msg113759.html

So there is no longer any reason for if_initialize to fail. (The
subroutine if_stats_init can't fail because percpu_alloc can't fail
either.)

There is a snag: the softint_establish in if_percpuq_create could
fail, potentially leading to bad consequences later on trying to use
the softint. This change doesn't introduce any new bugs because of
the snag -- if_percpuq_attach was already broken. However, the snag
can be better addressed without spawning error branches, either by
using a single softint or making softints less scarce.

(Separate commit will change the signatures of if_attach and
if_initialize to return void, scheduled to ride whatever is the next
convenient kernel bump.)

Patch and testing on amd64 and evbmips64-eb by maya@; commit message
soliloquy, and compile-testing on evbppc/i386/earmv7hf, by me.
 1.30 13-Apr-2021  mrg branches: 1.30.2;
remove extra line that clearly isn't meant to be there and may trigger
uninitialised reads of variables.
 1.29 22-Jul-2020  riastradh branches: 1.29.4;
bwfm: Switch from pcq to pool_cache.

pcq_get is required to be serialized, but it's far from clear that it
is serialized here.
 1.28 22-Jul-2020  riastradh Add include guards and appropriate includes to bwfmreg.h, bwfmvar.h.

No functional change intended.
 1.27 22-Jul-2020  riastradh Sort #includes. Nix trailing whitespace.

No functional change intended.
 1.26 13-Jul-2020  mrg move some of the patching of callbacks and other data after
ieee80211_ifattach() but before if_deferred_start_init().

may fix panic i saw in after restarting wpa_supplicant.

from mlelstv.
 1.25 30-May-2020  jdolecek discussed with thorpej@, and it seems it's better to allocate the bss
alignment buffer statically (as part of softc) just to be sure to not
affect performance
 1.24 30-May-2020  jdolecek reduce stack usage in bwfm_rx_event_cb(), can use KM_SLEEP because
this is called from workqueue handler (i.e. thread context)
 1.23 30-May-2020  jdolecek constify, and make static where possible
 1.22 25-Mar-2020  thorpej Add a file type entry for CLM files.
 1.21 25-Mar-2020  thorpej - Refactor the firmware loading code into a set of common routines in the
core driver that understand how to find model-specific files before the
generic files. This greatly simplifies the firmware loading procedure
in each of the bus front ends. Adding additional firmware file types
(such as CLM files) much simpler.
- Make firmware image selection table-driven rather than a set of switch()
and if() statements.
- Add several additional firmware image entries.
 1.20 29-Jan-2020  thorpej Adopt <net/if_stats.h>.
 1.19 27-Dec-2019  msaitoh branches: 1.19.2;
s/suport/support/
 1.18 28-Oct-2019  mlelstv More code from OpenBSD
no need to splnet() when enqueing packets
explicit structure padding
make internal functions static

also prepare for GPIO interrupts.
 1.17 03-Oct-2019  jmcneill If firmware is connected in HT or VHT mode, report it to SIOCGIFMEDIA
 1.16 02-Sep-2019  mlelstv tagging work queue as MPSAFE was premature. Revert.
 1.15 01-Sep-2019  mlelstv From OpenBSD:
- move event handling to workqueue
- check for save/restore capability
Tag work queue as MPsafe and increase length.
Juse use bpf_mtap(), the 802.11 encapsulation is handled by firmware.
 1.14 02-Sep-2018  maya branches: 1.14.2; 1.14.6;
Initialize if_stop so suspend won't jump to NULL.
 1.13 01-Sep-2018  riastradh bwfm has only one tx descriptor; limit mbuf chains to one segment.

PR kern/53287

Can't use m_defrag because it always yields two segments.

Discussion on tech-net:
https://mail-index.netbsd.org/tech-net/2018/09/01/msg007031.html

Diagnosed and tested by maya.
 1.12 26-Jun-2018  msaitoh branches: 1.12.2;
Implement the BPF direction filter (BIOC[GS]DIRECTION). It provides backward
compatibility with BIOC[GS]SEESENT ioctl. The userland interface is the same
as FreeBSD.

This change also fixes a bug that the direction is misunderstand on some
environment by passing the direction to bpf_mtap*() instead of checking
m->m_pkthdr.rcvif.
 1.11 11-May-2018  maya sync with openbsd bwfm to some extent.

add a txcheck
set chip active/passive for more kinds of chips
add wrapper around setting active/passive
detect chip RAM
make bwfm_rx take an mbuf
 1.10 16-Jan-2018  maxv branches: 1.10.2;
Prepend 'sp_' to the name of the fields, so that they can easily be found
via NXR or grep.
 1.9 16-Jan-2018  maxv Mmh refix previous, we also need to make sure frm[1] is there.
 1.8 16-Jan-2018  maxv Fix overflow, noted by Maya.
 1.7 18-Dec-2017  jmcneill Support promiscuous mode
 1.6 18-Dec-2017  jmcneill Use ieee80211_media_status
 1.5 18-Dec-2017  jmcneill Stop the device at attach in case it was previously initialized
 1.4 23-Oct-2017  jmcneill branches: 1.4.2;
Initialize txrate to 0 for new associations; firmware handles rate adaptation for us
 1.3 23-Oct-2017  msaitoh If if_initialize() failed in the attach function, free resources and return.
 1.2 20-Oct-2017  jmcneill Fix an alignment problem with scan results within an escan event
 1.1 19-Oct-2017  jmcneill Add driver for Broadcom 802.11a/b/g/n/ac USB wireless devices, based on
the OpenBSD bwfm(4) driver.
 1.4.2.2 03-Dec-2017  jdolecek update from HEAD
 1.4.2.1 23-Oct-2017  jdolecek file bwfm.c was added on branch tls-maxphys on 2017-12-03 11:37:03 +0000
 1.10.2.3 06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.10.2.2 28-Jul-2018  pgoyette Sync with HEAD
 1.10.2.1 21-May-2018  pgoyette Sync with HEAD
 1.12.2.3 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.12.2.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.12.2.1 10-Jun-2019  christos Sync with HEAD
 1.14.6.3 17-Aug-2020  martin Pull up following revision(s) (requested by mrg in ticket #1052):

sys/dev/ic/bwfm.c: revision 1.28
sys/dev/ic/bwfm.c: revision 1.29
sys/dev/sdmmc/if_bwfm_sdio.c: revision 1.22
sys/dev/ic/bwfmreg.h: revision 1.7
sys/dev/ic/bwfmvar.h: revision 1.11
sys/dev/ic/bwfmvar.h: revision 1.12
(all via patch)

Add include guards and appropriate includes to bwfmreg.h, bwfmvar.h.

No functional change intended.

Need <sys/kmem.h> for kmem_*.

Currently accidentally side-loaded by <sys/pcq.h>.

bwfm: Switch from pcq to pool_cache.
pcq_get is required to be serialized, but it's far from clear that it
is serialized here.
 1.14.6.2 09-Aug-2020  martin Pull up following revision(s) (requested by mrg in ticket #1042):

sys/dev/sdmmc/if_bwfm_sdio.c: revision 1.19
sys/dev/sdmmc/ld_sdmmc.c: revision 1.38
sys/dev/sdmmc/sdmmcvar.h: revision 1.35
sys/dev/sdmmc/if_bwfm_sdio.c: revision 1.5
sys/dev/ic/bwfm.c: revision 1.26
sys/dev/ic/bwfm.c: revision 1.27
sys/dev/sdmmc/if_bwfm_sdio.c: revision 1.20
sys/dev/sdmmc/if_bwfm_sdio.c: revision 1.21
sys/dev/sdmmc/sdmmc_io.c: revision 1.20
sys/dev/sdmmc/sdmmc_mem.c: revision 1.72
sys/dev/sdmmc/sdmmc.c: revision 1.40
sys/dev/sdmmc/sdmmc_ioreg.h: revision 1.6
sys/dev/sdmmc/if_bwfm_sdio.c: revision 1.16

Don't pass empty mbufs to the network stack.

Avoid changing signedness bit with << in sdmmc_ioreg.h
Reported by <prlw1>

If the controller doesn't support switch func (opcode 6) then skip
setting this but continue with other settings. This allows us to use
a card, albeit at a lower speed.

Fix races in sdmmc tasks and teach ld@sdmmc to abort xfers on detach.
- Teach sdmmc_add_task to queue it only if not already queued.
- Remove now-redundant logic to avoid repeated queueing elsewhere.
- Teach sdmmc_del_task to wait until task has completed.
- Call sdmmc_del_task in various needful places.
- Replace abuse of pcq by a lock and a tailq.
(pcq is multi-producer, _single_-consumer, but there are potentially
multiple consumers here and really only one producer.)
- Teach ld_sdmmc to abort xfers on detach.
(Mechanism is kinda kludgey but it'll do for now; any effort one is
tempted to spend overhauling this should be spent overhauling sdmmc
to support proper asynchronous commands.)
- Make sure ld_sdmmc_discard either returns failure or eventually calls
ldenddiscard.

XXX Currently ld_sdmmc_detach aborts xfers _before_ ldbegindetach has
has committed to detaching or not. This is currently necessary to
avoid a deadlock because ldbegindetach waits for xfers to drain --
which strikes me as wrong; ldbegindetach shouldn't wait for anything,
and should only make the decision to commit to detaching or not so
the caller can decide whether to abort xfers before we actually wait
for them in ldenddetach.

XXX pullup -- although this changes some kernel symbols (sdmmc_add_task
and sdmmc_del_task), it shouldn't affect any existing modules; the only
module that uses sdmmc is ld_sdmmc.kmod, which is `.if 0' in the build
so there shouldn't be any of them floating around.

Make this work on big endian machines

move some of the patching of callbacks and other data after
ieee80211_ifattach() but before if_deferred_start_init().
may fix panic i saw in after restarting wpa_supplicant.
from mlelstv.

only ask for SDPCMD_INTSTATUS_HMB_SW_MASK and SDPCMD_INTSTATUS_CHIPACTIVE
interrupts, not all of them. we only ack these ones.
mostly fixes pinebookpro wifi hard hangs. still is problematic and can
trigger interrupt storm that appears as a hard hang without NET_MPSAFE,
and a follow up, less clearly right, change will reduce that to a soft
hang of the interface that can be cleared with 'ifconfig bwfm0 down up',
and even often recovers itself now.

clear all interrupts, not just those we expect from the hostintmask.
this removes the final hard hang i have seen in pinebookpro wifi,
though one may still need to 'ifconfig bwfm0 down up' occasionally,
so we still have bugs to fix here (the hang is usually associated
with 'checksum error' from bwfm/sdio.)

Sort #includes. Nix trailing whitespace.
No functional change intended.
 1.14.6.1 25-Feb-2020  martin Pull up following revision(s) (requested by mrg in ticket #717):

sys/dev/fdt/dwcmmc_fdt.c 1.11
sys/dev/ic/bwfm.c 1.15-1.18
sys/dev/ic/bwfmreg.h 1.4-1.6
sys/dev/ic/bwfmvar.h 1.4,1.5
sys/dev/ic/dwc_mmc.c 1.21,1.22
sys/dev/ic/dwc_mmc_reg.h 1.8,1.9,1.12,1.13
sys/dev/pcmcia/pcmciareg.h 1.11
sys/dev/sdmmc/if_bwfm_sdio.c 1.4,1.6-1.12
sys/dev/sdmmc/if_bwfm_sdio.h 1.1,1.2
sys/dev/sdmmc/sdhc.c 1.105,1.106
sys/dev/sdmmc/sdmmc.c 1.37,1.39
sys/dev/sdmmc/sdmmc_cis.c 1.6,1.8
sys/dev/sdmmc/sdmmc_io.c 1.15-1.19
sys/dev/sdmmc/sdmmc_ioreg.h 1.4,1.5
sys/dev/sdmmc/sdmmc_mem.c 1.69-1.71
sys/dev/sdmmc/sdmmcdevs 1.5-1.8
sys/dev/sdmmc/sdmmcvar.h 1.31,1.33,1.34
sys/net/if_media.h 1.66

Add Broadcom devices
-
Fix typo
-
add PCMCIA_CISTPL_SDIO definition.
-
From OpenBSD:
- move event handling to workqueue
- check for save/restore capability
-
Tag work queue as MPsafe and increase length.
-
Juse use bpf_mtap(), the 802.11 encapsulation is handled by firmware.
-
From OpenBSD:
- support block length per function
- add functions to read/write regions
-
Decode (but not use) SDIO tuple in CIS.
-
Fix locking.
-
Add more SDIO defines (partially from version 3.0).
-
From OpenBSD:
- All the missing pieces (firmware load, chip setup, protocol handling)
TX queue and interrupt handling via sdmmc_task.
-
Fix locking.
-
Fix packet parsing.
-
Add parser for original firmware config files.
-
tagging work queue as MPSAFE was premature. Revert.
-
SD_IO_RW_EXTENDED is a data transfer command, so set ADTC flag instead of AC
Use correct function to verify if a task has been queued. Avoids race
that can corrupt the task queue.
-
More register definitions.
-
Add IFM_IEEE80211_VHT subtype, IFM_IEEE80211_11AC operating mode, and missing descriptions
-
If firmware is connected in HT or VHT mode, report it to SIOCGIFMEDIA
-
white space police.

Skip setting power when the voltage doesn't change.
Also increase some timeouts.
-
Add and use sdmmc_pause to avoid long-term busy waits.
-
Add sdio abort function.
-
Additional error messages.
-
Print parameters for SDIO devices.
-
Minor cosmetics.
-
Simplyfy sdmmc_io_set_blocklen function signature by dropping the
extra softc pointer. Aligns with OpenBSD.
-
Missing commit for sdio abort function.
-
More code from OpenBSD
-
no need to splnet() when enqueing packets
-
explicit structure padding
-
make internal functions static
-
also prepare for GPIO interrupts.
-
Avoid warnings for tautological shifts as sole conditional.
-
Follow the Linux driver an use the FDT "compatible" property to build a
filename for the nvram config file, fall back to the standard filename.
E.g.
[Caching 123 nodes and 1093 properties]
compatible 73696e6f 766f6970 2c627069 2d6d322d "sinovoip,bpi-m2-
0010: 7a65726f 00...... ........ ........ zero"
0015: 616c6c77 696e6e65 722c7375 6e38692d "allwinner,sun8i-
0025: 68322d70 6c757300 ........ ........ h2-plus"
interrupt-parent 00000001 ........ ........ ........ ....
model 42616e61 6e612050 69204250 492d4d32 "Banana Pi BPI-M2
0010: 2d5a6572 6f00.... ........ ........ -Zero"
name 00...... ........ ........ ........ ""
serial-number 30326330 30303432 65636431 36376566 02c00042ecd167ef
0010: 00...... ........ ........ ........ .
-rw-r--r-- 1 root wheel 875 Nov 2 12:06 brcmfmac43430-sdio.AP6212.txt
lrwxr-xr-x 1 root wheel 29 Dec 30 16:19 brcmfmac43430-sdio.sinovoip,bpi-m2-zero.txt -> brcmfmac43430-sdio.AP6212.txt
-rw-r--r-- 1 root wheel 874 Jun 30 2019 brcmfmac43430-sdio.raspberrypi,3-model-b.txt
-rw-r--r-- 1 root wheel 1864 Jun 30 2019 brcmfmac43455-sdio.raspberrypi,3-model-b-plus.txt
lrwxr-xr-x 1 root wheel 29 Dec 30 11:24 brcmfmac43455-sdio.raspberrypi,4-model-b-plus.txt -> brcmfmac43455-sdio.raspberrypi,3-model-b-plus.txt
-
Add product ID for Broadcom BCM43455
-
Use correct firmware for BCM43456
-
size check was backwards.
-
Be less noisy for some commands.
-
Fix DWC_MMC_INT_SDIO_INT bit
-
dwc_mmc fixes:
- Rockchip uses a different SDIO int bit, so take this into consideration
- Avoid unnecessary resets and always wait for resets to complete
- kpause instead of delay while holding spinlock
- Do not attempt autostop for SD_IO_RW_EXTENDED commands
- Allow for sub-blklen byte counts for single block transfers
-
More SDIO stability and performance fixes
 1.14.2.2 31-Oct-2018  martin Backport of bfwm code, requested by maya in ticket #1072:

sys/dev/ic/bwfm.c 1.14
sys/dev/ic/bwfmreg.h 1.3
sys/dev/ic/bwfmvar.h 1.3
sys/dev/pci/if_bwfm_pci.c 1.4
sys/dev/pci/if_bwfm_pci.h 1.8
sys/dev/usb/if_bwfm_usb.c 1.8

via patch.
 1.14.2.1 02-Sep-2018  martin file bwfm.c was added on branch netbsd-8 on 2018-10-31 09:23:00 +0000
 1.19.2.1 29-Feb-2020  ad Sync with head.
 1.29.4.1 17-Apr-2021  thorpej Sync with HEAD.
 1.30.2.1 17-Jun-2021  thorpej Sync w/ HEAD.
 1.8 14-Mar-2022  mlelstv Add OpenBSD to code to optionally load CLM (Country Locale Matrix) files.
 1.7 22-Jul-2020  riastradh Add include guards and appropriate includes to bwfmreg.h, bwfmvar.h.

No functional change intended.
 1.6 28-Oct-2019  mlelstv More code from OpenBSD
no need to splnet() when enqueing packets
explicit structure padding
make internal functions static

also prepare for GPIO interrupts.
 1.5 03-Oct-2019  jmcneill If firmware is connected in HT or VHT mode, report it to SIOCGIFMEDIA
 1.4 01-Sep-2019  mlelstv From OpenBSD:
- move event handling to workqueue
- check for save/restore capability
Tag work queue as MPsafe and increase length.
Juse use bpf_mtap(), the 802.11 encapsulation is handled by firmware.
 1.3 11-May-2018  maya branches: 1.3.2; 1.3.6; 1.3.10;
sync with openbsd bwfm to some extent.

add a txcheck
set chip active/passive for more kinds of chips
add wrapper around setting active/passive
detect chip RAM
make bwfm_rx take an mbuf
 1.2 20-Oct-2017  jmcneill branches: 1.2.2; 1.2.4;
Set maximum supported bwfm_bss_info length
 1.1 19-Oct-2017  jmcneill Add driver for Broadcom 802.11a/b/g/n/ac USB wireless devices, based on
the OpenBSD bwfm(4) driver.
 1.2.4.1 21-May-2018  pgoyette Sync with HEAD
 1.2.2.2 03-Dec-2017  jdolecek update from HEAD
 1.2.2.1 20-Oct-2017  jdolecek file bwfmreg.h was added on branch tls-maxphys on 2017-12-03 11:37:03 +0000
 1.3.10.2 17-Aug-2020  martin Pull up following revision(s) (requested by mrg in ticket #1052):

sys/dev/ic/bwfm.c: revision 1.28
sys/dev/ic/bwfm.c: revision 1.29
sys/dev/sdmmc/if_bwfm_sdio.c: revision 1.22
sys/dev/ic/bwfmreg.h: revision 1.7
sys/dev/ic/bwfmvar.h: revision 1.11
sys/dev/ic/bwfmvar.h: revision 1.12
(all via patch)

Add include guards and appropriate includes to bwfmreg.h, bwfmvar.h.

No functional change intended.

Need <sys/kmem.h> for kmem_*.

Currently accidentally side-loaded by <sys/pcq.h>.

bwfm: Switch from pcq to pool_cache.
pcq_get is required to be serialized, but it's far from clear that it
is serialized here.
 1.3.10.1 25-Feb-2020  martin Pull up following revision(s) (requested by mrg in ticket #717):

sys/dev/fdt/dwcmmc_fdt.c 1.11
sys/dev/ic/bwfm.c 1.15-1.18
sys/dev/ic/bwfmreg.h 1.4-1.6
sys/dev/ic/bwfmvar.h 1.4,1.5
sys/dev/ic/dwc_mmc.c 1.21,1.22
sys/dev/ic/dwc_mmc_reg.h 1.8,1.9,1.12,1.13
sys/dev/pcmcia/pcmciareg.h 1.11
sys/dev/sdmmc/if_bwfm_sdio.c 1.4,1.6-1.12
sys/dev/sdmmc/if_bwfm_sdio.h 1.1,1.2
sys/dev/sdmmc/sdhc.c 1.105,1.106
sys/dev/sdmmc/sdmmc.c 1.37,1.39
sys/dev/sdmmc/sdmmc_cis.c 1.6,1.8
sys/dev/sdmmc/sdmmc_io.c 1.15-1.19
sys/dev/sdmmc/sdmmc_ioreg.h 1.4,1.5
sys/dev/sdmmc/sdmmc_mem.c 1.69-1.71
sys/dev/sdmmc/sdmmcdevs 1.5-1.8
sys/dev/sdmmc/sdmmcvar.h 1.31,1.33,1.34
sys/net/if_media.h 1.66

Add Broadcom devices
-
Fix typo
-
add PCMCIA_CISTPL_SDIO definition.
-
From OpenBSD:
- move event handling to workqueue
- check for save/restore capability
-
Tag work queue as MPsafe and increase length.
-
Juse use bpf_mtap(), the 802.11 encapsulation is handled by firmware.
-
From OpenBSD:
- support block length per function
- add functions to read/write regions
-
Decode (but not use) SDIO tuple in CIS.
-
Fix locking.
-
Add more SDIO defines (partially from version 3.0).
-
From OpenBSD:
- All the missing pieces (firmware load, chip setup, protocol handling)
TX queue and interrupt handling via sdmmc_task.
-
Fix locking.
-
Fix packet parsing.
-
Add parser for original firmware config files.
-
tagging work queue as MPSAFE was premature. Revert.
-
SD_IO_RW_EXTENDED is a data transfer command, so set ADTC flag instead of AC
Use correct function to verify if a task has been queued. Avoids race
that can corrupt the task queue.
-
More register definitions.
-
Add IFM_IEEE80211_VHT subtype, IFM_IEEE80211_11AC operating mode, and missing descriptions
-
If firmware is connected in HT or VHT mode, report it to SIOCGIFMEDIA
-
white space police.

Skip setting power when the voltage doesn't change.
Also increase some timeouts.
-
Add and use sdmmc_pause to avoid long-term busy waits.
-
Add sdio abort function.
-
Additional error messages.
-
Print parameters for SDIO devices.
-
Minor cosmetics.
-
Simplyfy sdmmc_io_set_blocklen function signature by dropping the
extra softc pointer. Aligns with OpenBSD.
-
Missing commit for sdio abort function.
-
More code from OpenBSD
-
no need to splnet() when enqueing packets
-
explicit structure padding
-
make internal functions static
-
also prepare for GPIO interrupts.
-
Avoid warnings for tautological shifts as sole conditional.
-
Follow the Linux driver an use the FDT "compatible" property to build a
filename for the nvram config file, fall back to the standard filename.
E.g.
[Caching 123 nodes and 1093 properties]
compatible 73696e6f 766f6970 2c627069 2d6d322d "sinovoip,bpi-m2-
0010: 7a65726f 00...... ........ ........ zero"
0015: 616c6c77 696e6e65 722c7375 6e38692d "allwinner,sun8i-
0025: 68322d70 6c757300 ........ ........ h2-plus"
interrupt-parent 00000001 ........ ........ ........ ....
model 42616e61 6e612050 69204250 492d4d32 "Banana Pi BPI-M2
0010: 2d5a6572 6f00.... ........ ........ -Zero"
name 00...... ........ ........ ........ ""
serial-number 30326330 30303432 65636431 36376566 02c00042ecd167ef
0010: 00...... ........ ........ ........ .
-rw-r--r-- 1 root wheel 875 Nov 2 12:06 brcmfmac43430-sdio.AP6212.txt
lrwxr-xr-x 1 root wheel 29 Dec 30 16:19 brcmfmac43430-sdio.sinovoip,bpi-m2-zero.txt -> brcmfmac43430-sdio.AP6212.txt
-rw-r--r-- 1 root wheel 874 Jun 30 2019 brcmfmac43430-sdio.raspberrypi,3-model-b.txt
-rw-r--r-- 1 root wheel 1864 Jun 30 2019 brcmfmac43455-sdio.raspberrypi,3-model-b-plus.txt
lrwxr-xr-x 1 root wheel 29 Dec 30 11:24 brcmfmac43455-sdio.raspberrypi,4-model-b-plus.txt -> brcmfmac43455-sdio.raspberrypi,3-model-b-plus.txt
-
Add product ID for Broadcom BCM43455
-
Use correct firmware for BCM43456
-
size check was backwards.
-
Be less noisy for some commands.
-
Fix DWC_MMC_INT_SDIO_INT bit
-
dwc_mmc fixes:
- Rockchip uses a different SDIO int bit, so take this into consideration
- Avoid unnecessary resets and always wait for resets to complete
- kpause instead of delay while holding spinlock
- Do not attempt autostop for SD_IO_RW_EXTENDED commands
- Allow for sub-blklen byte counts for single block transfers
-
More SDIO stability and performance fixes
 1.3.6.2 31-Oct-2018  martin Backport of bfwm code, requested by maya in ticket #1072:

sys/dev/ic/bwfm.c 1.14
sys/dev/ic/bwfmreg.h 1.3
sys/dev/ic/bwfmvar.h 1.3
sys/dev/pci/if_bwfm_pci.c 1.4
sys/dev/pci/if_bwfm_pci.h 1.8
sys/dev/usb/if_bwfm_usb.c 1.8

via patch.
 1.3.6.1 11-May-2018  martin file bwfmreg.h was added on branch netbsd-8 on 2018-10-31 09:23:00 +0000
 1.3.2.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.14 03-Dec-2022  mlelstv Fix bug in protocol parser that often caused fatal 'checksum error'.
Defer power save setting to interface start.
More verbose on errors.
Allow build without FDT.
 1.13 14-Mar-2022  mlelstv Add OpenBSD to code to optionally load CLM (Country Locale Matrix) files.
 1.12 22-Jul-2020  riastradh bwfm: Switch from pcq to pool_cache.

pcq_get is required to be serialized, but it's far from clear that it
is serialized here.
 1.11 22-Jul-2020  riastradh Add include guards and appropriate includes to bwfmreg.h, bwfmvar.h.

No functional change intended.
 1.10 30-May-2020  jdolecek discussed with thorpej@, and it seems it's better to allocate the bss
alignment buffer statically (as part of softc) just to be sure to not
affect performance
 1.9 30-May-2020  jdolecek constify, and make static where possible
 1.8 25-Mar-2020  thorpej Add a file type entry for CLM files.
 1.7 25-Mar-2020  thorpej - Refactor the firmware loading code into a set of common routines in the
core driver that understand how to find model-specific files before the
generic files. This greatly simplifies the firmware loading procedure
in each of the bus front ends. Adding additional firmware file types
(such as CLM files) much simpler.
- Make firmware image selection table-driven rather than a set of switch()
and if() statements.
- Add several additional firmware image entries.
 1.6 22-Mar-2020  thorpej Add a few more chip ID.
 1.5 28-Oct-2019  mlelstv More code from OpenBSD
no need to splnet() when enqueing packets
explicit structure padding
make internal functions static

also prepare for GPIO interrupts.
 1.4 01-Sep-2019  mlelstv From OpenBSD:
- move event handling to workqueue
- check for save/restore capability
Tag work queue as MPsafe and increase length.
Juse use bpf_mtap(), the 802.11 encapsulation is handled by firmware.
 1.3 01-Sep-2018  riastradh branches: 1.3.2; 1.3.6;
bwfm has only one tx descriptor; limit mbuf chains to one segment.

PR kern/53287

Can't use m_defrag because it always yields two segments.

Discussion on tech-net:
https://mail-index.netbsd.org/tech-net/2018/09/01/msg007031.html

Diagnosed and tested by maya.
 1.2 11-May-2018  maya branches: 1.2.2;
sync with openbsd bwfm to some extent.

add a txcheck
set chip active/passive for more kinds of chips
add wrapper around setting active/passive
detect chip RAM
make bwfm_rx take an mbuf
 1.1 19-Oct-2017  jmcneill branches: 1.1.2; 1.1.4;
Add driver for Broadcom 802.11a/b/g/n/ac USB wireless devices, based on
the OpenBSD bwfm(4) driver.
 1.1.4.2 06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.1.4.1 21-May-2018  pgoyette Sync with HEAD
 1.1.2.2 03-Dec-2017  jdolecek update from HEAD
 1.1.2.1 19-Oct-2017  jdolecek file bwfmvar.h was added on branch tls-maxphys on 2017-12-03 11:37:03 +0000
 1.2.2.3 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.2.2.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.2.2.1 10-Jun-2019  christos Sync with HEAD
 1.3.6.2 17-Aug-2020  martin Pull up following revision(s) (requested by mrg in ticket #1052):

sys/dev/ic/bwfm.c: revision 1.28
sys/dev/ic/bwfm.c: revision 1.29
sys/dev/sdmmc/if_bwfm_sdio.c: revision 1.22
sys/dev/ic/bwfmreg.h: revision 1.7
sys/dev/ic/bwfmvar.h: revision 1.11
sys/dev/ic/bwfmvar.h: revision 1.12
(all via patch)

Add include guards and appropriate includes to bwfmreg.h, bwfmvar.h.

No functional change intended.

Need <sys/kmem.h> for kmem_*.

Currently accidentally side-loaded by <sys/pcq.h>.

bwfm: Switch from pcq to pool_cache.
pcq_get is required to be serialized, but it's far from clear that it
is serialized here.
 1.3.6.1 25-Feb-2020  martin Pull up following revision(s) (requested by mrg in ticket #717):

sys/dev/fdt/dwcmmc_fdt.c 1.11
sys/dev/ic/bwfm.c 1.15-1.18
sys/dev/ic/bwfmreg.h 1.4-1.6
sys/dev/ic/bwfmvar.h 1.4,1.5
sys/dev/ic/dwc_mmc.c 1.21,1.22
sys/dev/ic/dwc_mmc_reg.h 1.8,1.9,1.12,1.13
sys/dev/pcmcia/pcmciareg.h 1.11
sys/dev/sdmmc/if_bwfm_sdio.c 1.4,1.6-1.12
sys/dev/sdmmc/if_bwfm_sdio.h 1.1,1.2
sys/dev/sdmmc/sdhc.c 1.105,1.106
sys/dev/sdmmc/sdmmc.c 1.37,1.39
sys/dev/sdmmc/sdmmc_cis.c 1.6,1.8
sys/dev/sdmmc/sdmmc_io.c 1.15-1.19
sys/dev/sdmmc/sdmmc_ioreg.h 1.4,1.5
sys/dev/sdmmc/sdmmc_mem.c 1.69-1.71
sys/dev/sdmmc/sdmmcdevs 1.5-1.8
sys/dev/sdmmc/sdmmcvar.h 1.31,1.33,1.34
sys/net/if_media.h 1.66

Add Broadcom devices
-
Fix typo
-
add PCMCIA_CISTPL_SDIO definition.
-
From OpenBSD:
- move event handling to workqueue
- check for save/restore capability
-
Tag work queue as MPsafe and increase length.
-
Juse use bpf_mtap(), the 802.11 encapsulation is handled by firmware.
-
From OpenBSD:
- support block length per function
- add functions to read/write regions
-
Decode (but not use) SDIO tuple in CIS.
-
Fix locking.
-
Add more SDIO defines (partially from version 3.0).
-
From OpenBSD:
- All the missing pieces (firmware load, chip setup, protocol handling)
TX queue and interrupt handling via sdmmc_task.
-
Fix locking.
-
Fix packet parsing.
-
Add parser for original firmware config files.
-
tagging work queue as MPSAFE was premature. Revert.
-
SD_IO_RW_EXTENDED is a data transfer command, so set ADTC flag instead of AC
Use correct function to verify if a task has been queued. Avoids race
that can corrupt the task queue.
-
More register definitions.
-
Add IFM_IEEE80211_VHT subtype, IFM_IEEE80211_11AC operating mode, and missing descriptions
-
If firmware is connected in HT or VHT mode, report it to SIOCGIFMEDIA
-
white space police.

Skip setting power when the voltage doesn't change.
Also increase some timeouts.
-
Add and use sdmmc_pause to avoid long-term busy waits.
-
Add sdio abort function.
-
Additional error messages.
-
Print parameters for SDIO devices.
-
Minor cosmetics.
-
Simplyfy sdmmc_io_set_blocklen function signature by dropping the
extra softc pointer. Aligns with OpenBSD.
-
Missing commit for sdio abort function.
-
More code from OpenBSD
-
no need to splnet() when enqueing packets
-
explicit structure padding
-
make internal functions static
-
also prepare for GPIO interrupts.
-
Avoid warnings for tautological shifts as sole conditional.
-
Follow the Linux driver an use the FDT "compatible" property to build a
filename for the nvram config file, fall back to the standard filename.
E.g.
[Caching 123 nodes and 1093 properties]
compatible 73696e6f 766f6970 2c627069 2d6d322d "sinovoip,bpi-m2-
0010: 7a65726f 00...... ........ ........ zero"
0015: 616c6c77 696e6e65 722c7375 6e38692d "allwinner,sun8i-
0025: 68322d70 6c757300 ........ ........ h2-plus"
interrupt-parent 00000001 ........ ........ ........ ....
model 42616e61 6e612050 69204250 492d4d32 "Banana Pi BPI-M2
0010: 2d5a6572 6f00.... ........ ........ -Zero"
name 00...... ........ ........ ........ ""
serial-number 30326330 30303432 65636431 36376566 02c00042ecd167ef
0010: 00...... ........ ........ ........ .
-rw-r--r-- 1 root wheel 875 Nov 2 12:06 brcmfmac43430-sdio.AP6212.txt
lrwxr-xr-x 1 root wheel 29 Dec 30 16:19 brcmfmac43430-sdio.sinovoip,bpi-m2-zero.txt -> brcmfmac43430-sdio.AP6212.txt
-rw-r--r-- 1 root wheel 874 Jun 30 2019 brcmfmac43430-sdio.raspberrypi,3-model-b.txt
-rw-r--r-- 1 root wheel 1864 Jun 30 2019 brcmfmac43455-sdio.raspberrypi,3-model-b-plus.txt
lrwxr-xr-x 1 root wheel 29 Dec 30 11:24 brcmfmac43455-sdio.raspberrypi,4-model-b-plus.txt -> brcmfmac43455-sdio.raspberrypi,3-model-b-plus.txt
-
Add product ID for Broadcom BCM43455
-
Use correct firmware for BCM43456
-
size check was backwards.
-
Be less noisy for some commands.
-
Fix DWC_MMC_INT_SDIO_INT bit
-
dwc_mmc fixes:
- Rockchip uses a different SDIO int bit, so take this into consideration
- Avoid unnecessary resets and always wait for resets to complete
- kpause instead of delay while holding spinlock
- Do not attempt autostop for SD_IO_RW_EXTENDED commands
- Allow for sub-blklen byte counts for single block transfers
-
More SDIO stability and performance fixes
 1.3.2.2 31-Oct-2018  martin Backport of bfwm code, requested by maya in ticket #1072:

sys/dev/ic/bwfm.c 1.14
sys/dev/ic/bwfmreg.h 1.3
sys/dev/ic/bwfmvar.h 1.3
sys/dev/pci/if_bwfm_pci.c 1.4
sys/dev/pci/if_bwfm_pci.h 1.8
sys/dev/usb/if_bwfm_usb.c 1.8

via patch.
 1.3.2.1 01-Sep-2018  martin file bwfmvar.h was added on branch netbsd-8 on 2018-10-31 09:23:00 +0000
 1.45 23-Oct-2025  jmcneill bwi: AMRR fix, PCI/cardbus interrupt fix, and other enhancements.

- Fix AMRR by passing the correct "retry count" to _bwi_txeof() from
bwi_txeof(). While here, cleanup parsing of BWI_TXSTATUS_0 fields to
make the code more readable.
- IPL_SOFTNET is enough for PIO locks and workqueues, no need for IPL_NET
- Extend the SDIO bus intr_mask fix to all busses, I'd be amazed if
PCI or Cardbus devices worked at all with the old code.
- Since we only load firmware from disk once, only log the firmware
revision once. Previously it was being printed every time bwi_init was
called.
 1.44 19-Oct-2025  jmcneill bwi: Retry SDIO common regwin probe a few times before giving up.

It seems that on some systems, we need to read the SDIO common regwin ID
register more than once to properly identify it. Try a couple of times
before giving up.

This makes bwi(4) attach on my red Wii.
 1.43 16-Feb-2025  jmcneill branches: 1.43.2;
bwi: Remove a delay() loop in the PIO RX path.
 1.42 15-Feb-2025  jmcneill bwi: Update rate control statistics on txeof to enable AMRR.
 1.41 20-Jan-2025  christos fix uninitialized
 1.40 19-Jan-2025  jmcneill bwi(4): Add support for Nintendo Wii WLAN.

Adapt the bwi(4) driver to support SDIO attachment and driving TX/RX using
PIO instead of DMA since the latter is not supported on SDIO busses.
 1.39 12-Jan-2025  jmcneill bwi: Remove unnecessary pcivar.h include
 1.38 16-Jun-2021  riastradh branches: 1.38.10; 1.38.16;
if_attach and if_initialize cannot fail, don't test return value

These were originally made failable back in 2017 when if_initialize
allocated a softint in every interface for link state changes, so
that it could fail gracefully instead of panicking:

https://mail-index.NetBSD.org/source-changes/2017/10/23/msg089053.html

However, this spawned many seldom- or never-tested error branches,
which are risky to have around. And that softint in every interface
has since been replaced by a single global workqueue, because link
state changes require thread context but not low latency or high
throughput:

https://mail-index.NetBSD.org/source-changes/2020/02/06/msg113759.html

So there is no longer any reason for if_initialize to fail. (The
subroutine if_stats_init can't fail because percpu_alloc can't fail
either.)

There is a snag: the softint_establish in if_percpuq_create could
fail, potentially leading to bad consequences later on trying to use
the softint. This change doesn't introduce any new bugs because of
the snag -- if_percpuq_attach was already broken. However, the snag
can be better addressed without spawning error branches, either by
using a single softint or making softints less scarce.

(Separate commit will change the signatures of if_attach and
if_initialize to return void, scheduled to ride whatever is the next
convenient kernel bump.)

Patch and testing on amd64 and evbmips64-eb by maya@; commit message
soliloquy, and compile-testing on evbppc/i386/earmv7hf, by me.
 1.37 29-Jan-2020  thorpej branches: 1.37.10;
Adopt <net/if_stats.h>.
 1.36 22-Dec-2018  maxv branches: 1.36.6;
Replace: M_COPY_PKTHDR -> m_copy_pkthdr. No functional change, since the
former is a macro to the latter.
 1.35 25-Jul-2018  msaitoh Initialize some members in a mbuf which is on stack.
 1.34 26-Jun-2018  msaitoh branches: 1.34.2;
Implement the BPF direction filter (BIOC[GS]DIRECTION). It provides backward
compatibility with BIOC[GS]SEESENT ioctl. The userland interface is the same
as FreeBSD.

This change also fixes a bug that the direction is misunderstand on some
environment by passing the direction to bpf_mtap*() instead of checking
m->m_pkthdr.rcvif.
 1.33 23-Oct-2017  msaitoh branches: 1.33.2;
If if_initialize() failed in the attach function, return.
 1.32 29-Jul-2017  riastradh Check for M_EXT in m->m_flags, whether m is NULL, after MCLGET.

From Ilja Van Sprundel.
 1.31 02-Feb-2017  nonaka branches: 1.31.6;
wlan interfaces make interrupt routine running on softint context.

see http://mail-index.netbsd.org/tech-kern/2016/12/06/msg021281.html

tested device:
* ath at pci: AR5212, AR5424
* athn at pci: AR9287
* ipw at pci: 2100BG
* iwi at pci: 2915ABG
* iwm at pci: 3165, 7260, 8260
* iwn at pci: 4945, 6235
* ral at pci: RT2560
* rtwn at pci: RTL8192CE
 1.30 10-Jun-2016  ozaki-r branches: 1.30.2; 1.30.4;
Introduce m_set_rcvif and m_reset_rcvif

The API is used to set (or reset) a received interface of a mbuf.
They are counterpart of m_get_rcvif, which will come in another
commit, hide internal of rcvif operation, and reduce the diff of
the upcoming change.

No functional change.
 1.29 26-May-2016  ozaki-r Introduce M_CLEARCTX and use it instead of open-coding rcvif

No functional change.
 1.28 26-May-2016  ozaki-r Use M_GETCTX

No functional change.
 1.27 02-Mar-2016  christos PR/50882: David Binderman: Remove redundant code.
 1.26 10-Apr-2015  maxv Fix a double free. "Suggested" by Brainy.

ok rjs@ riastradh@
 1.25 07-Jan-2015  ozaki-r Pass a correct firmware size (instead of 0) to firmware_free

firmware_free now uses kmem_free(9) instead of free(9),
so we need to pass a correct size to it.
 1.24 25-Feb-2014  pooka branches: 1.24.4; 1.24.6;
Ensure that the top level sysctl nodes (kern, vfs, net, ...) exist before
the sysctl link sets are processed, and remove redundancy.

Shaves >13kB off of an amd64 GENERIC, not to mention >1k duplicate
lines of code.
 1.23 17-Oct-2013  christos - remove unused variables
- move variables inside ifdef sections
- ifdef notdef unused code
- use __USE for debugging variables
 1.22 25-Apr-2012  nakayama branches: 1.22.2; 1.22.4;
Fix alignment and endian bugs observed on sparc64.
Also apply some minor fix from FreeBSD.

Tested with Buffalo WLI-CB-G54 (BCM4306) and WLI3-CB-G54L (BCM4318)
on i386 and sparc64.
 1.21 14-Apr-2012  nakayama Remove duplicate code.
 1.20 12-Apr-2012  nakayama - Add pmf(9) suspend, resume to bwi(4) cardbus front end.
- Apply cardbus code cleanups.
 1.19 15-Mar-2012  bouyer Fix array overflow, found by gcc -O3.
 1.18 10-Oct-2011  njoly branches: 1.18.2; 1.18.6; 1.18.8; 1.18.12; 1.18.14;
Kill local definition of __unused attribute.
 1.17 28-Jan-2011  pooka Don't BWI_DEBUG by default + comment cleanup.

requested by Taylor R. Campbell (driver submitter)
 1.16 16-Apr-2010  dyoung branches: 1.16.2; 1.16.4;
#include <sys/bus.h> instead of <machine/bus.h>. No functional change
intended.
 1.15 05-Apr-2010  joerg Push the bpf_ops usage back into bpf.h. Push the common ifp->if_bpf
check into the inline functions as well the fourth argument for
bpf_attach.
 1.14 24-Feb-2010  dyoung branches: 1.14.2;
A pointer typedef entails trading too much flexibility to declare const
and non-const types, and the kernel uses both const and non-const
PMF qualifiers and device suspensors, so change the pmf_qual_t and
device_suspensor_t typedefs from "pointers to const" to non-pointer,
non-const types.
 1.13 19-Jan-2010  pooka branches: 1.13.2;
Redefine bpf linkage through an always present op vector, i.e.
#if NBPFILTER is no longer required in the client. This change
doesn't yet add support for loading bpf as a module, since drivers
can register before bpf is attached. However, callers of bpf can
now be modularized.

Dynamically loadable bpf could probably be done fairly easily with
coordination from the stub driver and the real driver by registering
attachments in the stub before the real driver is loaded and doing
a handoff. ... and I'm not going to ponder the depths of unload
here.

Tested with i386/MONOLITHIC, modified MONOLITHIC without bpf and rump.
 1.12 08-Jan-2010  dyoung Expand PMF_FN_* macros.
 1.11 25-Jul-2009  cegger use __arraycount, kill N() macro.
 1.10 26-Apr-2009  cegger branches: 1.10.2;
device_t/softc split
 1.9 23-Apr-2009  kefren Add power hooks. Proposed a couple of days ago on tech-kern@, no
objections received. Tested on Dell Inspiron 2200 with BCM4318
 1.8 18-Apr-2009  tsutsui Remove extra whitespace added by a stupid tool.
XXX: more in src/sys/arch
 1.7 18-Mar-2009  cegger bcopy -> memcpy
 1.6 18-Mar-2009  cegger bzero -> memset
 1.5 23-Feb-2009  cube I smell rotting code. (Give a chance to the user to at least set the flags
of the interface, if not use it because it otherwise doesn't work.)
 1.4 10-Jan-2009  cegger branches: 1.4.2; 1.4.4; 1.4.6;
use new exported constants from net80211.
no functional change.
 1.3 10-Jan-2009  cegger BCM4328 has MAC rev 12.
XXX Driver now tells me, this chip has unsupported PHY type 4.
 1.2 09-Jan-2009  macallan Fix previous screwup.
This is the real bwi driver.
Ported by Taylor R. Campbell
 1.1 09-Jan-2009  macallan A driver for Broadcom BCM4302 wlan controllers, otherwise known as
Airport Extreme.
Ported from Dragonfly and OpenBSD by Urban Boquist
 1.4.6.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.4.4.4 28-Apr-2009  skrll Sync with HEAD.
 1.4.4.3 03-Mar-2009  skrll Sync with HEAD.
 1.4.4.2 19-Jan-2009  skrll Sync with HEAD.
 1.4.4.1 10-Jan-2009  skrll file bwi.c was added on branch nick-hppapmap on 2009-01-19 13:17:54 +0000
 1.4.2.2 17-Jan-2009  mjf Sync with HEAD.
 1.4.2.1 10-Jan-2009  mjf file bwi.c was added on branch mjf-devfs2 on 2009-01-17 13:28:54 +0000
 1.10.2.5 11-Aug-2010  yamt sync with head.
 1.10.2.4 11-Mar-2010  yamt sync with head
 1.10.2.3 19-Aug-2009  yamt sync with head.
 1.10.2.2 04-May-2009  yamt sync with head.
 1.10.2.1 26-Apr-2009  yamt file bwi.c was added on branch yamt-nfs-mp on 2009-05-04 08:12:40 +0000
 1.13.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.14.2.2 05-Mar-2011  rmind sync with head
 1.14.2.1 30-May-2010  rmind sync with head
 1.16.4.1 08-Feb-2011  bouyer Sync with HEAD
 1.16.2.1 06-Jun-2011  jruoho Sync with HEAD.
 1.18.14.1 19-Aug-2017  snj Pull up following revision(s) (requested by mrg in ticket #1478):
sys/dev/ic/bwi.c: revision 1.32
Check for M_EXT in m->m_flags, whether m is NULL, after MCLGET.
From Ilja Van Sprundel.
 1.18.12.1 19-Aug-2017  snj Pull up following revision(s) (requested by mrg in ticket #1478):
sys/dev/ic/bwi.c: revision 1.32
Check for M_EXT in m->m_flags, whether m is NULL, after MCLGET.
From Ilja Van Sprundel.
 1.18.8.1 19-Aug-2017  snj Pull up following revision(s) (requested by mrg in ticket #1478):
sys/dev/ic/bwi.c: revision 1.32
Check for M_EXT in m->m_flags, whether m is NULL, after MCLGET.
From Ilja Van Sprundel.
 1.18.6.2 29-Apr-2012  mrg sync to latest -current.
 1.18.6.1 05-Apr-2012  mrg sync to latest -current.
 1.18.2.3 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.18.2.2 23-May-2012  yamt sync with head.
 1.18.2.1 17-Apr-2012  yamt sync with head
 1.22.4.1 18-May-2014  rmind sync with head
 1.22.2.2 03-Dec-2017  jdolecek update from HEAD
 1.22.2.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.24.6.7 28-Aug-2017  skrll Sync with HEAD
 1.24.6.6 05-Feb-2017  skrll Sync with HEAD
 1.24.6.5 09-Jul-2016  skrll Sync with HEAD
 1.24.6.4 29-May-2016  skrll Sync with HEAD
 1.24.6.3 19-Mar-2016  skrll Sync with HEAD
 1.24.6.2 06-Jun-2015  skrll Sync with HEAD
 1.24.6.1 06-Apr-2015  skrll Sync with HEAD
 1.24.4.2 12-Aug-2017  snj Pull up following revision(s) (requested by mrg in ticket #1474):
sys/dev/ic/bwi.c: revision 1.32
Check for M_EXT in m->m_flags, whether m is NULL, after MCLGET.
From Ilja Van Sprundel.
 1.24.4.1 21-Apr-2015  snj branches: 1.24.4.1.2; 1.24.4.1.6;
Pull up following revision(s) (requested by maxv in ticket #713):
sys/dev/ic/bwi.c: revision 1.26
sys/nfs/krpc_subr.c: revision 1.38
Fix uninitialized variable.
Found by The Brainy Code Scanner in FreeBSD.
--
Fix a double free. "Suggested" by Brainy.
ok rjs@ riastradh@
 1.24.4.1.6.1 12-Aug-2017  snj Pull up following revision(s) (requested by mrg in ticket #1474):
sys/dev/ic/bwi.c: revision 1.32
Check for M_EXT in m->m_flags, whether m is NULL, after MCLGET.
From Ilja Van Sprundel.
 1.24.4.1.2.1 12-Aug-2017  snj Pull up following revision(s) (requested by mrg in ticket #1474):
sys/dev/ic/bwi.c: revision 1.32
Check for M_EXT in m->m_flags, whether m is NULL, after MCLGET.
From Ilja Van Sprundel.
 1.30.4.1 21-Apr-2017  bouyer Sync with HEAD
 1.30.2.1 20-Mar-2017  pgoyette Sync with HEAD
 1.31.6.2 10-Dec-2017  snj Pull up following revision(s) (requested by msaitoh in ticket #427):
sys/arch/amiga/dev/if_bah_zbus.c: 1.17
sys/arch/arm/broadcom/bcm53xx_eth.c: 1.30
sys/arch/powerpc/booke/dev/pq3etsec.c: 1.32
sys/arch/usermode/dev/if_veth.c: 1.9
sys/dev/ic/an.c: 1.66
sys/dev/ic/athn.c: 1.17
sys/dev/ic/atw.c: 1.162
sys/dev/ic/bwi.c: 1.33
sys/dev/ic/dwc_gmac.c: 1.41-1.42
sys/dev/ic/malo.c: 1.10
sys/dev/ic/rt2560.c: 1.31
sys/dev/ic/rt2661.c: 1.36
sys/dev/ic/rt2860.c: 1.29
sys/dev/ic/rtw.c: 1.127
sys/dev/ic/rtwvar.h: 1.46
sys/dev/ic/smc90cx6.c: 1.71
sys/dev/ic/smc90cx6var.h: 1.12
sys/dev/ic/wi.c: 1.244
sys/dev/pci/if_ipw.c: 1.66
sys/dev/pci/if_iwi.c: 1.104
sys/dev/pci/if_iwm.c: 1.76
sys/dev/pci/if_iwn.c: 1.86
sys/dev/pci/if_rtwn.c: 1.13
sys/dev/pci/if_wm.c: 1.541
sys/dev/pci/if_wpi.c: 1.79
sys/dev/pci/ixgbe/ixgbe.c: 1.106
sys/dev/pci/ixgbe/ixv.c: 1.73 via patch
sys/dev/pcmcia/if_malo_pcmcia.c: 1.15
sys/dev/scsipi/if_se.c: 1.95
sys/dev/usb/if_upl.c: 1.60
sys/net/if.c: 1.396
sys/net/if.h: 1.241
sys/net/if_arc.h: 1.23
sys/net/if_arcsubr.c: 1.78
sys/net/if_bridge.c: 1.136-1.137
sys/net/if_etherip.c: 1.39
sys/net/if_faith.c: 1.56
sys/net/if_gif.c: 1.131
sys/net/if_loop.c: 1.96
sys/net/if_mpls.c: 1.30
sys/net/if_pppoe.c: 1.129
sys/net/if_srt.c: 1.27
sys/net/if_stf.c: 1.102
sys/net/if_tap.c: 1.100
sys/net/if_vlan.c: 1.105
sys/netinet/ip_carp.c: 1.91
sys/rump/net/lib/libshmif/if_shmem.c: 1.73-1.74
sys/rump/net/lib/libvirtif/if_virt.c: 1.55-1.56
if_initalize() and if_attach() failed when resource allocation failed
(e.g. allocating softint). Without this change, it panics. It's bad because
resource shortage really occured when a lot of pseudo interface is created.
To avoid this problem, don't panic and change return value of if_initialize()
and if_attach() to int. Caller fanction will be recover from error cleanly by
checking the return value.
Return if bah_attach_subr() failed.
If if_attach() failed in the attach function, return.
- If if_initialize() failed in the attach function, free resources and return.
- Add some missing frees in bridge_clone_destroy().
- KNF
If error occured in bcmeth_ccb_attach(), free resources and return.
If error occured in pq3etsec_attach(), free resources and return.
If error occured in the attach function, free resources and return.
- If if_initialize() failed in athn_attach(), free resources and return.
- Add missing pmf_event_deregister() in athn_detach().
- Free resources correctly on some errors in atw_attach().
- Use apint*() insread of printf() in the attach function.
If if_initialize() failed in the attach function, return.
- If if_initialize() failed in the attach function, free resources and return.
- Add missing dwc_gmac_free_dma_rings() and mutex_destroy() when attach
failed.
- If if_initialize() failed in the attach function, free resources and return.
- ifp is always not NULL in iwi_detach(). Check correctly with ifp->if_softc.
- If if_initialize() failed in the attach function, free resources and return.
- Fix error path in the attach function correctly.
If if_initialize() failed in the attach function, free resources and return.
If if_attach() failed in the attach function, free resources and return.
- If if_initialize() failed in the attach function, free resources and return.
- KNF
- If if_attach() failed in the attach function, free resources and return.
- KNF
Fix compile error.
Fix compile error.
We don't need '&mii', but just 'mii' for mii_detach().
Don't free sc_rthash twice
 1.31.6.1 05-Aug-2017  snj Pull up following revision(s) (requested by spz in ticket #187):
sys/dev/ic/bwi.c: revision 1.32
Check for M_EXT in m->m_flags, whether m is NULL, after MCLGET.
From Ilja Van Sprundel.
 1.33.2.2 26-Dec-2018  pgoyette Sync with HEAD, resolve a few conflicts
 1.33.2.1 28-Jul-2018  pgoyette Sync with HEAD
 1.34.2.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.34.2.1 10-Jun-2019  christos Sync with HEAD
 1.36.6.1 29-Feb-2020  ad Sync with head.
 1.37.10.1 17-Jun-2021  thorpej Sync w/ HEAD.
 1.38.16.1 02-Aug-2025  perseant Sync with HEAD
 1.38.10.5 26-Oct-2025  martin Pull up following revision(s) (requested by jmcneill in ticket #1182):

sys/dev/ic/bwi.c: revision 1.45
sys/dev/ic/bwireg.h: revision 1.6
sys/dev/ic/bwivar.h: revision 1.12

bwi: AMRR fix, PCI/cardbus interrupt fix, and other enhancements.
- Fix AMRR by passing the correct "retry count" to _bwi_txeof() from
bwi_txeof(). While here, cleanup parsing of BWI_TXSTATUS_0 fields to
make the code more readable.
- IPL_SOFTNET is enough for PIO locks and workqueues, no need for IPL_NET
- Extend the SDIO bus intr_mask fix to all busses, I'd be amazed if
PCI or Cardbus devices worked at all with the old code.
- Since we only load firmware from disk once, only log the firmware
revision once. Previously it was being printed every time bwi_init was
called.
 1.38.10.4 20-Oct-2025  martin Pull up following revision(s) (requested by jmcneill in ticket #1179):

sys/dev/ic/bwi.c: revision 1.44

bwi: Retry SDIO common regwin probe a few times before giving up.

It seems that on some systems, we need to read the SDIO common regwin ID
register more than once to properly identify it. Try a couple of times
before giving up.

This makes bwi(4) attach on my red Wii.
 1.38.10.3 22-Feb-2025  martin Pull up following revision(s) (requested by jmcneill in ticket #1062):

sys/dev/ic/bwi.c: revision 1.43

bwi: Remove a delay() loop in the PIO RX path.
 1.38.10.2 22-Feb-2025  martin Pull up following revision(s) (requested by jmcneill in ticket #1058):

sys/dev/ic/bwi.c: revision 1.42

bwi: Update rate control statistics on txeof to enable AMRR.
 1.38.10.1 02-Feb-2025  martin Pull up following revision(s) (requested by jmcneill in ticket #1041):

sys/dev/ic/bwi.c: revision 1.40
share/man/man4/bwi.4: revision 1.15
sys/dev/sdmmc/if_bwi_sdio.c: revision 1.1
sys/dev/ic/bwi.c: revision 1.41
sys/dev/sdmmc/sdmmcvar.h: revision 1.38
sys/dev/ic/bwireg.h: revision 1.5
sys/dev/ic/bwi.c: revision 1.39
sys/dev/ic/bwivar.h: revision 1.11
sys/dev/sdmmc/sdmmc_cis.c: revision 1.10
sys/dev/sdmmc/files.sdmmc: revision 1.6
sys/arch/evbppc/conf/WII: revision 1.7

bwi: Remove unnecessary pcivar.h include

sdmmc: Capture lan_nid and expose sdmmc_cisptr
LAN NID contains the MAC address for networking adapters.
Device drivers may want to processor vendor specific tuple codes, so
expose sdmmc_cisptr to help this.

bwi(4): Add support for Nintendo Wii WLAN.

Adapt the bwi(4) driver to support SDIO attachment and driving TX/RX using
PIO instead of DMA since the latter is not supported on SDIO busses.

fix uninitialized
 1.43.2.2 26-Oct-2025  martin Pull up following revision(s) (requested by jmcneill in ticket #69):

sys/dev/ic/bwi.c: revision 1.45
sys/dev/ic/bwireg.h: revision 1.6
sys/dev/ic/bwivar.h: revision 1.12

bwi: AMRR fix, PCI/cardbus interrupt fix, and other enhancements.
- Fix AMRR by passing the correct "retry count" to _bwi_txeof() from
bwi_txeof(). While here, cleanup parsing of BWI_TXSTATUS_0 fields to
make the code more readable.
- IPL_SOFTNET is enough for PIO locks and workqueues, no need for IPL_NET
- Extend the SDIO bus intr_mask fix to all busses, I'd be amazed if
PCI or Cardbus devices worked at all with the old code.
- Since we only load firmware from disk once, only log the firmware
revision once. Previously it was being printed every time bwi_init was
called.
 1.43.2.1 20-Oct-2025  martin Pull up following revision(s) (requested by jmcneill in ticket #65):

sys/dev/ic/bwi.c: revision 1.44

bwi: Retry SDIO common regwin probe a few times before giving up.

It seems that on some systems, we need to read the SDIO common regwin ID
register more than once to properly identify it. Try a couple of times
before giving up.

This makes bwi(4) attach on my red Wii.
 1.6 23-Oct-2025  jmcneill bwi: AMRR fix, PCI/cardbus interrupt fix, and other enhancements.

- Fix AMRR by passing the correct "retry count" to _bwi_txeof() from
bwi_txeof(). While here, cleanup parsing of BWI_TXSTATUS_0 fields to
make the code more readable.
- IPL_SOFTNET is enough for PIO locks and workqueues, no need for IPL_NET
- Extend the SDIO bus intr_mask fix to all busses, I'd be amazed if
PCI or Cardbus devices worked at all with the old code.
- Since we only load firmware from disk once, only log the firmware
revision once. Previously it was being printed every time bwi_init was
called.
 1.5 19-Jan-2025  jmcneill branches: 1.5.2;
bwi(4): Add support for Nintendo Wii WLAN.

Adapt the bwi(4) driver to support SDIO attachment and driving TX/RX using
PIO instead of DMA since the latter is not supported on SDIO busses.
 1.4 18-May-2020  msaitoh branches: 1.4.20; 1.4.26;
Fix typo in comment.
 1.3 28-Jan-2009  sborrill branches: 1.3.4;
Correct PHY types (5 is LP, _not_ N).
 1.2 09-Jan-2009  macallan branches: 1.2.2; 1.2.4;
Fix previous screwup.
This is the real bwi driver.
Ported by Taylor R. Campbell
 1.1 09-Jan-2009  macallan A driver for Broadcom BCM4302 wlan controllers, otherwise known as
Airport Extreme.
Ported from Dragonfly and OpenBSD by Urban Boquist
 1.2.4.3 03-Mar-2009  skrll Sync with HEAD.
 1.2.4.2 19-Jan-2009  skrll Sync with HEAD.
 1.2.4.1 09-Jan-2009  skrll file bwireg.h was added on branch nick-hppapmap on 2009-01-19 13:17:54 +0000
 1.2.2.2 17-Jan-2009  mjf Sync with HEAD.
 1.2.2.1 09-Jan-2009  mjf file bwireg.h was added on branch mjf-devfs2 on 2009-01-17 13:28:55 +0000
 1.3.4.2 04-May-2009  yamt sync with head.
 1.3.4.1 28-Jan-2009  yamt file bwireg.h was added on branch yamt-nfs-mp on 2009-05-04 08:12:41 +0000
 1.4.26.1 02-Aug-2025  perseant Sync with HEAD
 1.4.20.2 26-Oct-2025  martin Pull up following revision(s) (requested by jmcneill in ticket #1182):

sys/dev/ic/bwi.c: revision 1.45
sys/dev/ic/bwireg.h: revision 1.6
sys/dev/ic/bwivar.h: revision 1.12

bwi: AMRR fix, PCI/cardbus interrupt fix, and other enhancements.
- Fix AMRR by passing the correct "retry count" to _bwi_txeof() from
bwi_txeof(). While here, cleanup parsing of BWI_TXSTATUS_0 fields to
make the code more readable.
- IPL_SOFTNET is enough for PIO locks and workqueues, no need for IPL_NET
- Extend the SDIO bus intr_mask fix to all busses, I'd be amazed if
PCI or Cardbus devices worked at all with the old code.
- Since we only load firmware from disk once, only log the firmware
revision once. Previously it was being printed every time bwi_init was
called.
 1.4.20.1 02-Feb-2025  martin Pull up following revision(s) (requested by jmcneill in ticket #1041):

sys/dev/ic/bwi.c: revision 1.40
share/man/man4/bwi.4: revision 1.15
sys/dev/sdmmc/if_bwi_sdio.c: revision 1.1
sys/dev/ic/bwi.c: revision 1.41
sys/dev/sdmmc/sdmmcvar.h: revision 1.38
sys/dev/ic/bwireg.h: revision 1.5
sys/dev/ic/bwi.c: revision 1.39
sys/dev/ic/bwivar.h: revision 1.11
sys/dev/sdmmc/sdmmc_cis.c: revision 1.10
sys/dev/sdmmc/files.sdmmc: revision 1.6
sys/arch/evbppc/conf/WII: revision 1.7

bwi: Remove unnecessary pcivar.h include

sdmmc: Capture lan_nid and expose sdmmc_cisptr
LAN NID contains the MAC address for networking adapters.
Device drivers may want to processor vendor specific tuple codes, so
expose sdmmc_cisptr to help this.

bwi(4): Add support for Nintendo Wii WLAN.

Adapt the bwi(4) driver to support SDIO attachment and driving TX/RX using
PIO instead of DMA since the latter is not supported on SDIO busses.

fix uninitialized
 1.5.2.1 26-Oct-2025  martin Pull up following revision(s) (requested by jmcneill in ticket #69):

sys/dev/ic/bwi.c: revision 1.45
sys/dev/ic/bwireg.h: revision 1.6
sys/dev/ic/bwivar.h: revision 1.12

bwi: AMRR fix, PCI/cardbus interrupt fix, and other enhancements.
- Fix AMRR by passing the correct "retry count" to _bwi_txeof() from
bwi_txeof(). While here, cleanup parsing of BWI_TXSTATUS_0 fields to
make the code more readable.
- IPL_SOFTNET is enough for PIO locks and workqueues, no need for IPL_NET
- Extend the SDIO bus intr_mask fix to all busses, I'd be amazed if
PCI or Cardbus devices worked at all with the old code.
- Since we only load firmware from disk once, only log the firmware
revision once. Previously it was being printed every time bwi_init was
called.
 1.12 23-Oct-2025  jmcneill bwi: AMRR fix, PCI/cardbus interrupt fix, and other enhancements.

- Fix AMRR by passing the correct "retry count" to _bwi_txeof() from
bwi_txeof(). While here, cleanup parsing of BWI_TXSTATUS_0 fields to
make the code more readable.
- IPL_SOFTNET is enough for PIO locks and workqueues, no need for IPL_NET
- Extend the SDIO bus intr_mask fix to all busses, I'd be amazed if
PCI or Cardbus devices worked at all with the old code.
- Since we only load firmware from disk once, only log the firmware
revision once. Previously it was being printed every time bwi_init was
called.
 1.11 19-Jan-2025  jmcneill branches: 1.11.2;
bwi(4): Add support for Nintendo Wii WLAN.

Adapt the bwi(4) driver to support SDIO attachment and driving TX/RX using
PIO instead of DMA since the latter is not supported on SDIO busses.
 1.10 02-Feb-2017  nonaka branches: 1.10.46; 1.10.52;
wlan interfaces make interrupt routine running on softint context.

see http://mail-index.netbsd.org/tech-kern/2016/12/06/msg021281.html

tested device:
* ath at pci: AR5212, AR5424
* athn at pci: AR9287
* ipw at pci: 2100BG
* iwi at pci: 2915ABG
* iwm at pci: 3165, 7260, 8260
* iwn at pci: 4945, 6235
* ral at pci: RT2560
* rtwn at pci: RTL8192CE
 1.9 12-Apr-2012  nakayama branches: 1.9.2; 1.9.16; 1.9.20; 1.9.24;
- Add pmf(9) suspend, resume to bwi(4) cardbus front end.
- Apply cardbus code cleanups.
 1.8 15-Oct-2011  dholland branches: 1.8.2; 1.8.6;
"return f();" where both f and the enclosing function return void is
sometimes convenient. But, it's not standard, so don't do it.
 1.7 24-Feb-2010  dyoung A pointer typedef entails trading too much flexibility to declare const
and non-const types, and the kernel uses both const and non-const
PMF qualifiers and device suspensors, so change the pmf_qual_t and
device_suspensor_t typedefs from "pointers to const" to non-pointer,
non-const types.
 1.6 19-Jan-2010  pooka branches: 1.6.2;
Redefine bpf linkage through an always present op vector, i.e.
#if NBPFILTER is no longer required in the client. This change
doesn't yet add support for loading bpf as a module, since drivers
can register before bpf is attached. However, callers of bpf can
now be modularized.

Dynamically loadable bpf could probably be done fairly easily with
coordination from the stub driver and the real driver by registering
attachments in the stub before the real driver is loaded and doing
a handoff. ... and I'm not going to ponder the depths of unload
here.

Tested with i386/MONOLITHIC, modified MONOLITHIC without bpf and rump.
 1.5 08-Jan-2010  dyoung Expand PMF_FN_* macros.
 1.4 26-Apr-2009  cegger branches: 1.4.2;
device_t/softc split
 1.3 23-Apr-2009  kefren Add power hooks. Proposed a couple of days ago on tech-kern@, no
objections received. Tested on Dell Inspiron 2200 with BCM4318
 1.2 09-Jan-2009  macallan branches: 1.2.2; 1.2.4; 1.2.6;
Fix previous screwup.
This is the real bwi driver.
Ported by Taylor R. Campbell
 1.1 09-Jan-2009  macallan A driver for Broadcom BCM4302 wlan controllers, otherwise known as
Airport Extreme.
Ported from Dragonfly and OpenBSD by Urban Boquist
 1.2.6.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.2.4.3 28-Apr-2009  skrll Sync with HEAD.
 1.2.4.2 19-Jan-2009  skrll Sync with HEAD.
 1.2.4.1 09-Jan-2009  skrll file bwivar.h was added on branch nick-hppapmap on 2009-01-19 13:17:54 +0000
 1.2.2.2 17-Jan-2009  mjf Sync with HEAD.
 1.2.2.1 09-Jan-2009  mjf file bwivar.h was added on branch mjf-devfs2 on 2009-01-17 13:28:55 +0000
 1.4.2.3 11-Mar-2010  yamt sync with head
 1.4.2.2 04-May-2009  yamt sync with head.
 1.4.2.1 26-Apr-2009  yamt file bwivar.h was added on branch yamt-nfs-mp on 2009-05-04 08:12:41 +0000
 1.6.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.8.6.1 29-Apr-2012  mrg sync to latest -current.
 1.8.2.1 17-Apr-2012  yamt sync with head
 1.9.24.1 21-Apr-2017  bouyer Sync with HEAD
 1.9.20.1 20-Mar-2017  pgoyette Sync with HEAD
 1.9.16.1 05-Feb-2017  skrll Sync with HEAD
 1.9.2.1 03-Dec-2017  jdolecek update from HEAD
 1.10.52.1 02-Aug-2025  perseant Sync with HEAD
 1.10.46.2 26-Oct-2025  martin Pull up following revision(s) (requested by jmcneill in ticket #1182):

sys/dev/ic/bwi.c: revision 1.45
sys/dev/ic/bwireg.h: revision 1.6
sys/dev/ic/bwivar.h: revision 1.12

bwi: AMRR fix, PCI/cardbus interrupt fix, and other enhancements.
- Fix AMRR by passing the correct "retry count" to _bwi_txeof() from
bwi_txeof(). While here, cleanup parsing of BWI_TXSTATUS_0 fields to
make the code more readable.
- IPL_SOFTNET is enough for PIO locks and workqueues, no need for IPL_NET
- Extend the SDIO bus intr_mask fix to all busses, I'd be amazed if
PCI or Cardbus devices worked at all with the old code.
- Since we only load firmware from disk once, only log the firmware
revision once. Previously it was being printed every time bwi_init was
called.
 1.10.46.1 02-Feb-2025  martin Pull up following revision(s) (requested by jmcneill in ticket #1041):

sys/dev/ic/bwi.c: revision 1.40
share/man/man4/bwi.4: revision 1.15
sys/dev/sdmmc/if_bwi_sdio.c: revision 1.1
sys/dev/ic/bwi.c: revision 1.41
sys/dev/sdmmc/sdmmcvar.h: revision 1.38
sys/dev/ic/bwireg.h: revision 1.5
sys/dev/ic/bwi.c: revision 1.39
sys/dev/ic/bwivar.h: revision 1.11
sys/dev/sdmmc/sdmmc_cis.c: revision 1.10
sys/dev/sdmmc/files.sdmmc: revision 1.6
sys/arch/evbppc/conf/WII: revision 1.7

bwi: Remove unnecessary pcivar.h include

sdmmc: Capture lan_nid and expose sdmmc_cisptr
LAN NID contains the MAC address for networking adapters.
Device drivers may want to processor vendor specific tuple codes, so
expose sdmmc_cisptr to help this.

bwi(4): Add support for Nintendo Wii WLAN.

Adapt the bwi(4) driver to support SDIO attachment and driving TX/RX using
PIO instead of DMA since the latter is not supported on SDIO busses.

fix uninitialized
 1.11.2.1 26-Oct-2025  martin Pull up following revision(s) (requested by jmcneill in ticket #69):

sys/dev/ic/bwi.c: revision 1.45
sys/dev/ic/bwireg.h: revision 1.6
sys/dev/ic/bwivar.h: revision 1.12

bwi: AMRR fix, PCI/cardbus interrupt fix, and other enhancements.
- Fix AMRR by passing the correct "retry count" to _bwi_txeof() from
bwi_txeof(). While here, cleanup parsing of BWI_TXSTATUS_0 fields to
make the code more readable.
- IPL_SOFTNET is enough for PIO locks and workqueues, no need for IPL_NET
- Extend the SDIO bus intr_mask fix to all busses, I'd be amazed if
PCI or Cardbus devices worked at all with the old code.
- Since we only load firmware from disk once, only log the firmware
revision once. Previously it was being printed every time bwi_init was
called.
 1.11 19-Oct-2000  ad Update for lsu; untested.
 1.10 01-Sep-2000  ad The `cac' driver now frees CCBs on our behalf.
 1.9 06-Jul-2000  thorpej Use device_lookup().
 1.8 20-Jun-2000  ad Feck.
 1.7 13-Jun-2000  ad branches: 1.7.2;
Use my proper name.
 1.6 12-Jun-2000  ad Fix a couple of pastos.
 1.5 16-May-2000  thorpej branches: 1.5.2;
Nuke dk_establish() from orbit except from those ports which still use
it to determine the boot device: mvme68k, pc532, macppc, ofppc. Those
platforms should be changed to use device_register(). In the mean time,
those ports defined __BROKEN_DK_ESTABLISH.
 1.4 29-Mar-2000  ad Spelling error.
 1.3 21-Mar-2000  ad Pass xfer size to disk_unbusy().
 1.2 20-Mar-2000  ad - Remove dead code.
- Make synchronous writes optional, disabled by default (*way* too slow).
- Handle case where dm_nsegs > CAC_SG_SIZE.
- Fix a couple of silly bugs.
- Fix use of __attribute__((__packed__));
 1.1 16-Mar-2000  ad Driver for Compaq array controllers and disks (cac(4)/ca(4)).
 1.5.2.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.7.2.4 25-Oct-2001  he Pull up file removal (requested by ad):
Add Mylex DACC960, CAC-EISA, and I2O block/SCSI drivers.
 1.7.2.3 10-May-2001  he Apply patch (requested by he):
Allow this to build on systems which do not define __HAVE_OLD_DISKLABEL.
 1.7.2.2 01-May-2001  he Apply patch (requested by fvdl):
Increase the number of BSD disklabel partitions on i386 to 16.
 1.7.2.1 21-Jun-2000  ad Pull-up revision 1.8: fix pasto.
 1.64 10-Feb-2024  andvar s/musn't/mustn't/ in comments.
 1.63 07-Aug-2021  thorpej Merge thorpej-cfargs2.
 1.62 24-Apr-2021  thorpej branches: 1.62.8;
Merge thorpej-cfargs branch:

Simplify and make extensible the config_search() / config_found() /
config_attach() interfaces: rather than having different variants for
which arguments you want pass along, just have a single call that
takes a variadic list of tag-value arguments.

Adjust all call sites:
- Simplify wherever possible; don't pass along arguments that aren't
actually needed.
- Don't be explicit about what interface attribute is attaching if
the device only has one. (More simplification.)
- Add a config_probe() function to be used in indirect configuiration
situations, making is visibly easier to see when indirect config is
in play, and allowing for future change in semantics. (As of now,
this is just a wrapper around config_match(), but that is an
implementation detail.)

Remove unnecessary or redundant interface attributes where they're not
needed.

There are currently 5 "cfargs" defined:
- CFARG_SUBMATCH (submatch function for direct config)
- CFARG_SEARCH (search function for indirect config)
- CFARG_IATTR (interface attribte)
- CFARG_LOCATORS (locators array)
- CFARG_DEVHANDLE (devhandle_t - wraps OFW, ACPI, etc. handles)

...and a sentinel value CFARG_EOL.

Add some extra sanity checking to ensure that interface attributes
aren't ambiguous.

Use CFARG_DEVHANDLE in MI FDT, OFW, and ACPI code, and macppc and shark
ports to associate those device handles with device_t instance. This
will trickle trough to more places over time (need back-end for pre-OFW
Sun OBP; any others?).
 1.61 10-Nov-2019  chs branches: 1.61.10;
in many device attach paths, allocate memory with M_WAITOK instead of M_NOWAIT
and remove code to handle failures that can no longer happen.
 1.60 08-May-2019  cnst bio(4) drivers: remove noop fallthrough-to-default bio(4) cmd cases

* Makes it easier to do code/feature analysis by not having
extra noop code/symbols spattered around.

* Only an issue in cac(4) and ciss(4); other drivers don't do this.

* No binary changes.
 1.59 03-Sep-2018  riastradh Rename min/max -> uimin/uimax for better honesty.

These functions are defined on unsigned int. The generic name
min/max should not silently truncate to 32 bits on 64-bit systems.
This is purely a name change -- no functional change intended.

HOWEVER! Some subsystems have

#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))

even though our standard name for that is MIN/MAX. Although these
may invite multiple evaluation bugs, these do _not_ cause integer
truncation.

To avoid `fixing' these cases, I first changed the name in libkern,
and then compile-tested every file where min/max occurred in order to
confirm that it failed -- and thus confirm that nothing shadowed
min/max -- before changing it.

I have left a handful of bootloaders that are too annoying to
compile-test, and some dead code:

cobalt ews4800mips hp300 hppa ia64 luna68k vax
acorn32/if_ie.c (not included in any kernels)
macppc/if_gm.c (superseded by gem(4))

It should be easy to fix the fallout once identified -- this way of
doing things fails safe, and the goal here, after all, is to _avoid_
silent integer truncations, not introduce them.

Maybe one day we can reintroduce min/max as type-generic things that
never silently truncate. But we should avoid doing that for a while,
so that existing code has a chance to be detected by the compiler for
conversion to uimin/uimax without changing the semantics until we can
properly audit it all. (Who knows, maybe in some cases integer
truncation is actually intended!)
 1.58 28-Oct-2017  riastradh branches: 1.58.2; 1.58.4;
Kill some more extern struct cfdriver declarations.

Down with externs in .c!
 1.57 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).
 1.56 07-Jul-2016  msaitoh branches: 1.56.2;
KNF. Remove extra spaces. No functional change.
 1.55 12-Mar-2015  christos Dedup the conversion of bioc_disk and bioc_vol to envsys_data_t
 1.54 27-Oct-2012  chs branches: 1.54.14;
split device_t/softc for all remaining drivers.
replace "struct device *" with "device_t".
use device_xname(), device_unit(), etc.
 1.53 20-Jun-2011  pgoyette branches: 1.53.2; 1.53.12;
Initialize current value for ENVSYS_DRIVE sensors
 1.52 20-Jun-2011  pgoyette Initializes sensors states before registering.
 1.51 13-Nov-2010  uebayasi branches: 1.51.6;
Don't pull in the whole uvm(9) API to access only PAGE_SIZE and
some other constants. These are provided by sys/param.h now.
 1.50 14-Mar-2010  pgoyette branches: 1.50.2;
Remove setting of edata->monitor since that member no longer exists.
 1.49 12-May-2009  cegger branches: 1.49.2;
struct device * -> device_t, no functional changes intended.
 1.48 18-Mar-2009  cegger bzero -> memset
 1.47 08-Jun-2008  tsutsui branches: 1.47.6; 1.47.12;
Replace device_lookup() with device_lookup_private() on getting softc
for future device_t/softc spilt.
 1.46 28-Apr-2008  martin branches: 1.46.2;
Remove clause 3 and 4 from TNF licenses
 1.45 08-Apr-2008  cegger branches: 1.45.2; 1.45.4;
use aprint_*_dev and device_xname
 1.44 14-Mar-2008  mhitch Initial bio(4) support; only volume status is handled. The driver doesn't
yet know about physical drives. Derived from the OpenBSD ciss(4) bio(4)
support.
 1.43 05-Dec-2007  ad branches: 1.43.8; 1.43.12;
Match the docs: MUTEX_DRIVER/SPIN are now only for porting code written
for Solaris.
 1.42 19-Oct-2007  ad branches: 1.42.2; 1.42.4;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.41 09-Jul-2007  ad branches: 1.41.6; 1.41.8; 1.41.12;
Merge some of the less invasive changes from the vmlocking branch:

- kthread, callout, devsw API changes
- select()/poll() improvements
- miscellaneous MT safety improvements
 1.40 04-Mar-2007  christos branches: 1.40.2; 1.40.4;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.39 09-Feb-2007  ad branches: 1.39.2;
Merge newlock2 to head.
 1.38 29-Dec-2006  ad - Print number of channels and firmware revision.
- Cut polling delay to make crashdumps faster.
 1.37 28-Nov-2006  ad Improve error handling. Related to PR/21900.
 1.36 16-Nov-2006  christos __unused removal on arguments; approved by core.
 1.35 12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.34 29-Jan-2006  dsl branches: 1.34.18; 1.34.20;
Make almost everything #include <sys/bswap.h> instead of <machine/bswap.h>
The bswap.h and endian.h files are all rather incestuous, but I want to
get the constant folding stuff into one place - sys/bswap.h
 1.33 11-Dec-2005  christos branches: 1.33.2;
merge ktrace-lwp.
 1.32 25-Aug-2005  drochner kill a number of autoconf submatch functions which follow the
standard scheme:
if (<configured> != <wildcard> && <configured> != <real>)
then fail
else
ask device match function

This is handled by config_stdsubmatch() now.
 1.31 25-Aug-2005  drochner replace the "locdesc_t" structure carrying the number of locators
explicitely by a plain integer array
the length in now known to all relevant parties, so this avoids
duplication of information, and we can allocate that thing in
drivers without hacks
 1.30 30-May-2005  christos branches: 1.30.2;
- add missing const
- fix variable shadowing
- remove unneeded casts
 1.29 27-Feb-2005  perry nuke trailing whitespace
 1.28 13-Sep-2004  drochner branches: 1.28.4; 1.28.6;
a round of autoconf cleanup:
-convert submatch() style functions (passed to config_search() or
config_found_sm()) to the locator passing variants
-pass interface attributes in some cases
-make submatch() functions look uniformly as far as possible
-avoid macros which just hide cfdata members, and reduce dependencies
on "locators.h"
 1.27 24-Aug-2004  thorpej Use ANSI function decls and more use of static.
 1.26 05-Dec-2003  pk cac_cmd:
* don't let cac_ccb_alloc() sleep since it regularly runs in an
interrupt context
* return EAGAIN instead EBUSY (or -1), which is what the upper ld
layer expects to get on transient resource shortages.
* ignore error from cac_ccb_start(), since a `fifo full' condition is
handled internally in the lower layer, i.e. the transaction started
from ldstart() has been queued at the lower layer and must be taken
off ld's disk queue.
 1.25 31-Jan-2003  thorpej branches: 1.25.2;
Use aprint_*().
 1.24 06-Jan-2003  wiz specified, not specifed.
 1.23 01-Jan-2003  thorpej Use aprint_normal() in cfprint routines.
 1.22 27-Sep-2002  thorpej Introduce a new routine, config_match(), which invokes the
cfattach->ca_match function in behalf of the caller. Use it
rather than invoking cfattach->ca_match directly.
 1.21 01-Jun-2002  lukem SIMPLEQ rototill:
- implement SIMPLEQ_REMOVE(head, elm, type, field). whilst it's O(n),
this mirrors the functionality of SLIST_REMOVE() (the other
singly-linked list type) and FreeBSD's STAILQ_REMOVE()
- remove the unnecessary elm arg from SIMPLEQ_REMOVE_HEAD().
this mirrors the functionality of SLIST_REMOVE_HEAD() (the other
singly-linked list type) and FreeBSD's STAILQ_REMOVE_HEAD()
- remove notes about SIMPLEQ not supporting arbitrary element removal
- use SIMPLEQ_FOREACH() instead of home-grown for loops
- use SIMPLEQ_EMPTY() appropriately
- use SIMPLEQ_*() instead of accessing sqh_first,sqh_last,sqe_next directly
- reorder manual page; be consistent about how the types are listed
- other minor cleanups
 1.20 25-Jan-2002  ad branches: 1.20.8;
- Always validate the return value read from the outbound FIFO.
- Copy access method info into the softc so we don't double dereference.
- Remove static on functions.
 1.19 13-Nov-2001  lukem add/cleanup RCSID
 1.18 19-Jul-2001  thorpej Use BUS_DMA_READ and BUS_DMA_WRITE in some obvious places.
 1.17 07-Mar-2001  thorpej branches: 1.17.2;
Add BUS_DMA_STREAMING to data transfer maps.
 1.16 11-Dec-2000  ad branches: 1.16.2;
Report soft-errors-per-unit once per minute at most.
 1.15 14-Nov-2000  thorpej branches: 1.15.2;
NBPG -> PAGE_SIZE
 1.14 08-Nov-2000  ad Move lsu stuff to more logical locations, and push queueing into the lsu
driver.
 1.13 19-Oct-2000  ad Update for lsu; untested.
 1.12 08-Sep-2000  ad - Set CCB_ACTIVE flag in all cases when DIAGNOSTIC is defined.
- Correct arguments to bus_dmamap_create().
 1.11 01-Sep-2000  ad FLUSH_CACHE will not return until complete.
 1.10 01-Sep-2000  ad - Interface cleanup. static, const in places.
- Pull in linkage useful for both PCI and EISA boards from cac_pci.c.
- cac_ccb_done() now frees the done CCB if the CCB callback completes.
- Model-specific linkage is now responsible for DMA synchronization.
- Use wakeup_one() in cac_ccb_free().
- Start synchronous commands `manually'.
- Add one hardware check in DIAGNOSTIC case.
- Improve error messages.
- Start firmware background tasks on controllers that need it.
 1.9 31-Jul-2000  ad Previous would have misbehaved if polled commands overlapped.
 1.8 24-Jul-2000  ad Increase polled command timeout to 2s.
 1.7 06-Jul-2000  thorpej Use device_lookup().
 1.6 13-Jun-2000  ad branches: 1.6.2;
Use my proper name.
 1.5 03-May-2000  thorpej branches: 1.5.2;
Fill in ccb->ccb_req.sgcount with the value that's guaranteed to
be initialized.
 1.4 26-Apr-2000  ad - Rearrange some spl*() calls to be as intended.
- Scan cac_cd in cac_shutdown(), don't use a SIMPLEQ.
 1.3 24-Mar-2000  ad Remove paraniod debug check that was mistakenly committed.
 1.2 20-Mar-2000  ad - Remove dead code.
- Make synchronous writes optional, disabled by default (*way* too slow).
- Handle case where dm_nsegs > CAC_SG_SIZE.
- Fix a couple of silly bugs.
- Fix use of __attribute__((__packed__));
 1.1 16-Mar-2000  ad Driver for Compaq array controllers and disks (cac(4)/ca(4)).
 1.5.2.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.6.2.4 29-Jan-2002  he Pull up revisions 1.20 (requested by ad):
Some fixes:
o Always validate return value read from outbound FIFO
o Copy access method into to softc to avoid double dereference
o Remove static on functions
Fixes PR#14453.
 1.6.2.3 25-Oct-2001  he Pull up revisions 1.10-1.18 (via patch, requested by ad):
Add Mylex DACC960, CAC-EISA, and I2O block/SCSI drivers.
 1.6.2.2 09-Aug-2000  ad Pull up revision 1.9 (approved by releng-1-5):
Previous would have misbehaved if polled commands overlapped.
 1.6.2.1 26-Jul-2000  ad Pull up revision 1.8 (approved by releng):
Increase polled command timeout to 2s.
 1.15.2.5 12-Mar-2001  bouyer Sync with HEAD.
 1.15.2.4 13-Dec-2000  bouyer Sync with HEAD (for UBC fixes).
 1.15.2.3 22-Nov-2000  bouyer Sync with HEAD.
 1.15.2.2 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.15.2.1 14-Nov-2000  bouyer file cac.c was added on branch thorpej_scsipi on 2000-11-20 11:40:25 +0000
 1.16.2.8 07-Jan-2003  thorpej Sync with HEAD.
 1.16.2.7 03-Jan-2003  thorpej Sync with HEAD.
 1.16.2.6 18-Oct-2002  nathanw Catch up to -current.
 1.16.2.5 20-Jun-2002  nathanw Catch up to -current.
 1.16.2.4 28-Feb-2002  nathanw Catch up to -current.
 1.16.2.3 14-Nov-2001  nathanw Catch up to -current.
 1.16.2.2 24-Aug-2001  nathanw Catch up with -current.
 1.16.2.1 09-Apr-2001  nathanw Catch up with -current.
 1.17.2.5 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.17.2.4 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.17.2.3 11-Feb-2002  jdolecek Sync w/ -current.
 1.17.2.2 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.17.2.1 03-Aug-2001  lukem update to -current
 1.20.8.1 20-Jun-2002  gehenna catch up with -current.
 1.25.2.6 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.25.2.5 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.25.2.4 21-Sep-2004  skrll Fix the sync with head I botched.
 1.25.2.3 18-Sep-2004  skrll Sync with HEAD.
 1.25.2.2 25-Aug-2004  skrll Sync with HEAD.
 1.25.2.1 03-Aug-2004  skrll Sync with HEAD
 1.28.6.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.28.4.1 29-Apr-2005  kent sync with -current
 1.30.2.7 17-Mar-2008  yamt sync with head.
 1.30.2.6 07-Dec-2007  yamt sync with head
 1.30.2.5 27-Oct-2007  yamt sync with head.
 1.30.2.4 03-Sep-2007  yamt sync with head.
 1.30.2.3 26-Feb-2007  yamt sync with head.
 1.30.2.2 30-Dec-2006  yamt sync with head.
 1.30.2.1 21-Jun-2006  yamt sync with head.
 1.33.2.1 01-Feb-2006  yamt sync with head.
 1.34.20.2 10-Dec-2006  yamt sync with head.
 1.34.20.1 22-Oct-2006  yamt sync with head
 1.34.18.3 15-Jan-2007  ad MP locking.
 1.34.18.2 12-Jan-2007  ad Sync with head.
 1.34.18.1 18-Nov-2006  ad Sync with head.
 1.39.2.1 12-Mar-2007  rmind Sync with HEAD.
 1.40.4.1 11-Jul-2007  mjf Sync with head.
 1.40.2.2 23-Oct-2007  ad Sync with head.
 1.40.2.1 21-Mar-2007  ad GC the simplelock/spinlock debugging stuff.
 1.41.12.1 25-Oct-2007  bouyer Sync with HEAD.
 1.41.8.3 23-Mar-2008  matt sync with HEAD
 1.41.8.2 09-Jan-2008  matt sync with HEAD
 1.41.8.1 06-Nov-2007  matt sync with HEAD
 1.41.6.2 09-Dec-2007  jmcneill Sync with HEAD.
 1.41.6.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.42.4.1 08-Dec-2007  ad Sync with head.
 1.42.2.1 08-Dec-2007  mjf Sync with HEAD.
 1.43.12.3 29-Jun-2008  mjf Sync with HEAD.
 1.43.12.2 02-Jun-2008  mjf Sync with HEAD.
 1.43.12.1 03-Apr-2008  mjf Sync with HEAD.
 1.43.8.1 24-Mar-2008  keiichi sync with head.
 1.45.4.4 11-Aug-2010  yamt sync with head.
 1.45.4.3 16-May-2009  yamt sync with head
 1.45.4.2 04-May-2009  yamt sync with head.
 1.45.4.1 16-May-2008  yamt sync with head.
 1.45.2.2 17-Jun-2008  yamt sync with head.
 1.45.2.1 18-May-2008  yamt sync with head.
 1.46.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.47.12.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.47.6.1 28-Apr-2009  skrll Sync with HEAD.
 1.49.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.50.2.1 05-Mar-2011  rmind sync with head
 1.51.6.1 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.53.12.2 03-Dec-2017  jdolecek update from HEAD
 1.53.12.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.53.2.1 30-Oct-2012  yamt sync with head
 1.54.14.3 05-Oct-2016  skrll Sync with HEAD
 1.54.14.2 09-Jul-2016  skrll Sync with HEAD
 1.54.14.1 06-Apr-2015  skrll Sync with HEAD
 1.56.2.1 04-Nov-2016  pgoyette Sync with HEAD
 1.58.4.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.58.4.1 10-Jun-2019  christos Sync with HEAD
 1.58.2.1 06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.61.10.3 28-Mar-2021  thorpej Correct the names of the arguments passed to cac_rescan(), and update
a local variable to avoid a name collision. Also, no need to be explcit
about our interface attribute, since we carry only one.
 1.61.10.2 22-Mar-2021  thorpej Audit CFARG_IATTR in config_found() calls, and remove it in situations
where the interface attribute is not ambiguous.
 1.61.10.1 22-Mar-2021  thorpej Mechanical conversion of config_found_sm_loc() -> config_found().
CFARG_IATTR usage needs to be audited.
 1.62.8.1 04-Aug-2021  thorpej Adapt to CFARGS().
 1.12 01-Nov-2022  andvar s/faild/failed/ in comments and messages.
 1.11 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.10 14-Mar-2008  mhitch branches: 1.10.2; 1.10.4;
Initial bio(4) support; only volume status is handled. The driver doesn't
yet know about physical drives. Derived from the OpenBSD ciss(4) bio(4)
support.
 1.9 25-Dec-2007  perry branches: 1.9.2; 1.9.6;
Convert many of the uses of __attribute__ to equivalent
__packed, __unused and __dead macros from cdefs.h
 1.8 28-Nov-2006  ad branches: 1.8.24; 1.8.30; 1.8.34; 1.8.38;
Improve error handling. Related to PR/21900.
 1.7 11-Dec-2005  christos branches: 1.7.20; 1.7.22;
merge ktrace-lwp.
 1.6 27-Feb-2005  perry branches: 1.6.4;
nuke trailing whitespace
 1.5 10-Jan-2001  ad branches: 1.5.24; 1.5.32; 1.5.34;
Make this work with the SA 431 and 42xx series controllers.
 1.4 01-Sep-2000  ad branches: 1.4.2;
- Move convenience macros from cacreg.h to cacvar.h.
- Define EISA board register set and some other magic numbers.
- Add missing elements to `struct cac_controller_info'.
 1.3 13-Jun-2000  ad branches: 1.3.2;
Use my proper name.
 1.2 20-Mar-2000  ad branches: 1.2.2;
- Remove dead code.
- Make synchronous writes optional, disabled by default (*way* too slow).
- Handle case where dm_nsegs > CAC_SG_SIZE.
- Fix a couple of silly bugs.
- Fix use of __attribute__((__packed__));
 1.1 16-Mar-2000  ad Driver for Compaq array controllers and disks (cac(4)/ca(4)).
 1.2.2.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.3.2.1 25-Oct-2001  he Pull up revisions 1.4-1.5 (via patch, requested by ad):
Add Mylex DACC960, CAC-EISA, and I2O block/SCSI drivers.
 1.4.2.3 18-Jan-2001  bouyer Sync with head (for UBC+NFS fixes, mostly).
 1.4.2.2 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.4.2.1 01-Sep-2000  bouyer file cacreg.h was added on branch thorpej_scsipi on 2000-11-20 11:40:25 +0000
 1.5.34.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.5.32.1 29-Apr-2005  kent sync with -current
 1.5.24.1 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.6.4.3 17-Mar-2008  yamt sync with head.
 1.6.4.2 21-Jan-2008  yamt sync with head
 1.6.4.1 30-Dec-2006  yamt sync with head.
 1.7.22.1 10-Dec-2006  yamt sync with head.
 1.7.20.1 12-Jan-2007  ad Sync with head.
 1.8.38.1 02-Jan-2008  bouyer Sync with HEAD
 1.8.34.1 26-Dec-2007  ad Sync with head.
 1.8.30.1 18-Feb-2008  mjf Sync with HEAD.
 1.8.24.2 23-Mar-2008  matt sync with HEAD
 1.8.24.1 09-Jan-2008  matt sync with HEAD
 1.9.6.2 02-Jun-2008  mjf Sync with HEAD.
 1.9.6.1 03-Apr-2008  mjf Sync with HEAD.
 1.9.2.1 24-Mar-2008  keiichi sync with head.
 1.10.4.1 16-May-2008  yamt sync with head.
 1.10.2.1 18-May-2008  yamt sync with head.
 1.21 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).
 1.20 27-Oct-2012  chs branches: 1.20.14; 1.20.18;
split device_t/softc for all remaining drivers.
replace "struct device *" with "device_t".
use device_xname(), device_unit(), etc.
 1.19 12-May-2009  cegger branches: 1.19.12; 1.19.22;
struct device * -> device_t, no functional changes intended.
 1.18 28-Apr-2008  martin branches: 1.18.14;
Remove clause 3 and 4 from TNF licenses
 1.17 14-Mar-2008  mhitch branches: 1.17.2; 1.17.4;
Initial bio(4) support; only volume status is handled. The driver doesn't
yet know about physical drives. Derived from the OpenBSD ciss(4) bio(4)
support.
 1.16 27-Jun-2007  mhitch branches: 1.16.8; 1.16.24; 1.16.28;
CAC_GET4() was incorrectly defined, fix it. Not used currently, but bio(4)
support I'm working on does.
 1.15 04-Mar-2007  christos branches: 1.15.2; 1.15.4;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.14 09-Feb-2007  ad branches: 1.14.2;
Merge newlock2 to head.
 1.13 28-Dec-2006  ad Bump the hardware queue depth up to 256.
 1.12 11-Dec-2005  christos branches: 1.12.20;
merge ktrace-lwp.
 1.11 27-Feb-2005  perry branches: 1.11.4;
nuke trailing whitespace
 1.10 13-Sep-2004  drochner branches: 1.10.4; 1.10.6;
a round of autoconf cleanup:
-convert submatch() style functions (passed to config_search() or
config_found_sm()) to the locator passing variants
-pass interface attributes in some cases
-make submatch() functions look uniformly as far as possible
-avoid macros which just hide cfdata members, and reduce dependencies
on "locators.h"
 1.9 25-Jan-2002  ad branches: 1.9.16;
- Always validate the return value read from the outbound FIFO.
- Copy access method info into the softc so we don't double dereference.
- Remove static on functions.
 1.8 08-Nov-2000  ad branches: 1.8.2; 1.8.4; 1.8.6;
Move lsu stuff to more logical locations, and push queueing into the lsu
driver.
 1.7 19-Oct-2000  ad Update for lsu; untested.
 1.6 01-Sep-2000  ad - Interface cleanup. static, const in places.
- Move convenience macros from cacreg.h to cacvar.h.
- Add one hardware check in DIAGNOSTIC case.
- Declare `cac_l0'.
 1.5 13-Jun-2000  ad branches: 1.5.2;
Use my proper name.
 1.4 04-May-2000  ad branches: 1.4.2;
Oops, nuke unused structure member.
 1.3 26-Apr-2000  ad - Bump xfer size limit to the maximum allowable.
- 20 CCBs is enough to maintain a constantly stuffed inbound FIFO.
 1.2 16-Mar-2000  ad Remove unneeded field in 'struct cac_ccb'.
 1.1 16-Mar-2000  ad Driver for Compaq array controllers and disks (cac(4)/ca(4)).
 1.4.2.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.5.2.2 29-Jan-2002  he Pull up revision 1.9 (requested by ad):
Some fixes:
o Always validate return value read from outbound FIFO
o Copy access method into to softc to avoid double dereference
o Remove static on functions
Fixes PR#14453.
 1.5.2.1 25-Oct-2001  he Pull up revisions 1.6-1.8 (requested by ad):
Add Mylex DACC960, CAC-EISA, and I2O block/SCSI drivers.
 1.8.6.1 11-Feb-2002  jdolecek Sync w/ -current.
 1.8.4.1 28-Feb-2002  nathanw Catch up to -current.
 1.8.2.3 22-Nov-2000  bouyer Sync with HEAD.
 1.8.2.2 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.8.2.1 08-Nov-2000  bouyer file cacvar.h was added on branch thorpej_scsipi on 2000-11-20 11:40:25 +0000
 1.9.16.3 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.9.16.2 21-Sep-2004  skrll Fix the sync with head I botched.
 1.9.16.1 18-Sep-2004  skrll Sync with HEAD.
 1.10.6.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.10.4.1 29-Apr-2005  kent sync with -current
 1.11.4.4 17-Mar-2008  yamt sync with head.
 1.11.4.3 03-Sep-2007  yamt sync with head.
 1.11.4.2 26-Feb-2007  yamt sync with head.
 1.11.4.1 30-Dec-2006  yamt sync with head.
 1.12.20.2 15-Jan-2007  ad MP locking.
 1.12.20.1 12-Jan-2007  ad Sync with head.
 1.14.2.1 12-Mar-2007  rmind Sync with HEAD.
 1.15.4.1 11-Jul-2007  mjf Sync with head.
 1.15.2.1 15-Jul-2007  ad Sync with head.
 1.16.28.2 02-Jun-2008  mjf Sync with HEAD.
 1.16.28.1 03-Apr-2008  mjf Sync with HEAD.
 1.16.24.1 24-Mar-2008  keiichi sync with head.
 1.16.8.1 23-Mar-2008  matt sync with HEAD
 1.17.4.2 16-May-2009  yamt sync with head
 1.17.4.1 16-May-2008  yamt sync with head.
 1.17.2.1 18-May-2008  yamt sync with head.
 1.18.14.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.19.22.2 03-Dec-2017  jdolecek update from HEAD
 1.19.22.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.19.12.1 30-Oct-2012  yamt sync with head
 1.20.18.1 04-Nov-2016  pgoyette Sync with HEAD
 1.20.14.1 05-Oct-2016  skrll Sync with HEAD
 1.7 05-Feb-2024  andvar fix various typos in comments.
 1.6 30-May-2022  andvar s/identifing/identifying/ and s/multipler/multiplier/ in comments.
 1.5 02-Jul-2008  plunky change licence of my old code to two-clause BSD licence
remove my name from advertising list
 1.4 11-Dec-2005  christos branches: 1.4.70; 1.4.74; 1.4.76; 1.4.78;
merge ktrace-lwp.
 1.3 02-Nov-2003  wiz Fix some typos. From Tom Cosgrove via jmc@openbsd.
 1.2 20-May-1998  pk branches: 1.2.48;
Erase spurious end-of-comment.
 1.1 20-May-1998  pk Cirrus Logic CD1190 parallel port chip definitions; from Iain Hibbert.
 1.2.48.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.2.48.2 18-Sep-2004  skrll Sync with HEAD.
 1.2.48.1 03-Aug-2004  skrll Sync with HEAD
 1.4.78.1 03-Jul-2008  simonb Sync with head.
 1.4.76.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.4.74.1 04-May-2009  yamt sync with head.
 1.4.70.1 02-Jul-2008  mjf Sync with HEAD.
 1.3 28-Jun-1995  cgd move to more appropriate (...reg.h) names.
 1.2 27-Oct-1994  cgd new RCS ID format.
 1.1 06-Oct-1993  andrew Goes with the new cy driver.
 1.6 11-Dec-2005  christos merge ktrace-lwp.
 1.5 27-Feb-2005  perry nuke trailing whitespace
 1.4 20-May-1998  pk branches: 1.4.48; 1.4.56; 1.4.58;
Add CD1400_PAR_FIFO_SIZE.
 1.3 24-Sep-1996  christos New Cyclades driver from Timo Rossi
 1.2 27-Oct-1994  cgd new RCS ID format.
 1.1 06-Oct-1993  andrew Goes with the new cy driver.
 1.4.58.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.4.56.1 29-Apr-2005  kent sync with -current
 1.4.48.1 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.33 02-Jun-2024  andvar fix various typos in word `interrupt', mainly in comments.
 1.32 02-Feb-2024  andvar fix various typos in comments.
 1.31 25-Jul-2014  dholland Add d_discard to all struct cdevsw instances I could find.

All have been set to "nodiscard"; some should get a real implementation.
 1.30 16-Mar-2014  dholland branches: 1.30.2;
Change (mostly mechanically) every cdevsw/bdevsw I can find to use
designated initializers.

I have not built every extant kernel so I have probably broken at
least one build; however I've also found and fixed some wrong
cdevsw/bdevsw entries so even if so I think we come out ahead.
 1.29 27-Oct-2012  chs branches: 1.29.2;
split device_t/softc for all remaining drivers.
replace "struct device *" with "device_t".
use device_xname(), device_unit(), etc.
 1.28 24-Apr-2011  rmind branches: 1.28.4; 1.28.14;
Rename ttymalloc() to tty_alloc(), and ttyfree() to tty_free() for
consistency. Remove some unnecessary malloc.h inclusions as well.
 1.27 14-Mar-2009  dsl branches: 1.27.4; 1.27.6;
Change about 4500 of the K&R function definitions to ANSI ones.
There are still about 1600 left, but they have ',' or /* ... */
in the actual variable definitions - which my awk script doesn't handle.
There are also many that need () -> (void).
(The script does handle misordered arguments.)
 1.26 12-Jun-2008  cegger branches: 1.26.4; 1.26.10;
use device_lookup_private to get softc
 1.25 29-May-2008  mrg branches: 1.25.2;
remove clause #3 from my license where there are no other
copyright holders involved.
 1.24 28-Apr-2008  martin branches: 1.24.2;
Remove clause 3 and 4 from TNF licenses
 1.23 08-Apr-2008  cegger branches: 1.23.2; 1.23.4;
use aprint_*_dev and device_xname
 1.22 19-Nov-2007  ad branches: 1.22.14;
- Factor out too many copies of the same bit of tty code.
- Fix another tty signalling/wakeup problem.
 1.21 19-Oct-2007  ad branches: 1.21.2;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.20 08-Oct-2007  ad branches: 1.20.2;
Use the softint API.
 1.19 04-Mar-2007  christos branches: 1.19.2; 1.19.14; 1.19.16; 1.19.18;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.18 01-Oct-2006  elad branches: 1.18.4;
More from Matt Fleming:

Adapt to KAUTH_DEVICE_TTY_PRIVSET and KAUTH_DEVICE_TTY_OPEN.
 1.17 01-Oct-2006  elad Adapt MD code to KAUTH_DEVICE_TTY_OPEN, batch #2 from Matt Fleming, thanks!

Also, add forgotten splx() calls in some places.
 1.16 21-Jul-2006  ad branches: 1.16.4; 1.16.6;
- Use the LWP cached credentials where sane.
- Minor cosmetic changes.
 1.15 08-Jun-2006  simonb Unwrap a not-too-long line.
 1.14 14-May-2006  elad branches: 1.14.2;
integrate kauth.
 1.13 24-Dec-2005  perry branches: 1.13.4; 1.13.6; 1.13.8; 1.13.10; 1.13.12;
Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.12 11-Dec-2005  christos merge ktrace-lwp.
 1.11 06-Sep-2005  kleink Change the driver open function's conditional for overriding exclusive tty
use from checking the proc's uid to suser(9), and account for the use of
privileges. Noted by David Holland in PR kern/31126.
 1.10 27-Feb-2005  perry branches: 1.10.4;
nuke trailing whitespace
 1.9 07-Aug-2003  agc branches: 1.9.8; 1.9.10;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22364, verified by myself.
 1.8 06-Jan-2003  wiz branches: 1.8.2;
interrupt with two rs.
 1.7 01-Jan-2003  mrg make cd18xx_ccr_wait() actually wait for the CCR to settle.
 1.6 28-Dec-2002  mrg tweak some comments
 1.5 23-Oct-2002  jdolecek merge kqueue branch into -current

kqueue provides a stateful and efficient event notification framework
currently supported events include socket, file, directory, fifo,
pipe, tty and device changes, and monitoring of processes and signals

kqueue is supported by all writable filesystems in NetBSD tree
(with exception of Coda) and all device drivers supporting poll(2)

based on work done by Jonathan Lemon for FreeBSD
initial NetBSD port done by Luke Mewburn and Jason Thorpe
 1.4 06-Sep-2002  gehenna Merge the gehenna-devsw branch into the trunk.

This merge changes the device switch tables from static array to
dynamically generated by config(8).

- All device switches is defined as a constant structure in device drivers.

- The new grammer ``device-major'' is introduced to ``files''.

device-major <prefix> char <num> [block <num>] [<rules>]

- All device major numbers must be listed up in port dependent majors.<arch>
by using this grammer.

- Added the new naming convention.
The name of the device switch must be <prefix>_[bc]devsw for auto-generation
of device switch tables.

- The backward compatibility of loading block/character device
switch by LKM framework is broken. This is necessary to convert
from block/character device major to device name in runtime and vice versa.

- The restriction to assign device major by LKM is completely removed.
We don't need to reserve LKM entries for dynamic loading of device switch.

- In compile time, device major numbers list is packed into the kernel and
the LKM framework will refer it to assign device major number dynamically.
 1.3 17-Mar-2002  atatat branches: 1.3.4;
Convert ioctl code to use EPASSTHROUGH instead of -1 or ENOTTY for
indicating an unhandled "command". ERESTART is -1, which can lead to
confusion. ERESTART has been moved to -3 and EPASSTHROUGH has been
placed at -4. No ioctl code should now return -1 anywhere. The
ioctl() system call is now properly restartable.
 1.2 13-Nov-2001  lukem branches: 1.2.2;
add/cleanup RCSID
 1.1 03-Oct-2001  mrg branches: 1.1.2; 1.1.4;
add a backend serial driver for the cirrus logic CL-CD180/1864/1865
8 port chip. this is used in several sbus (sparc) serial boards, as
well as an 8 port isa card from riscom. sio16 (sbus) frontend coming
shortly.

this is heavily based on the com and zs drivers.
 1.1.4.3 13-Oct-2001  fvdl Revert the t_dev -> t_devvp change in struct tty. The way that tty
structs are currently used (especially by console ttys) aren't
ready for it, and this will require quite a few changes.
 1.1.4.2 11-Oct-2001  fvdl Catch up with -current. Fix some bogons in the sparc64 kbd/ms
attach code. cd18xx conversion provided by mrg.
 1.1.4.1 03-Oct-2001  fvdl file cd18xx.c was added on branch thorpej-devvp on 2001-10-11 00:02:02 +0000
 1.1.2.9 07-Jan-2003  thorpej Sync with HEAD.
 1.1.2.8 03-Jan-2003  thorpej Sync with HEAD.
 1.1.2.7 29-Dec-2002  thorpej Sync with HEAD.
 1.1.2.6 11-Nov-2002  nathanw Catch up to -current
 1.1.2.5 17-Sep-2002  nathanw Catch up to -current.
 1.1.2.4 01-Apr-2002  nathanw Catch up to -current.
(CVS: It's not just a program. It's an adventure!)
 1.1.2.3 14-Nov-2001  nathanw Catch up to -current.
 1.1.2.2 08-Oct-2001  nathanw Catch up to -current.
 1.1.2.1 03-Oct-2001  nathanw file cd18xx.c was added on branch nathanw_sa on 2001-10-08 20:10:58 +0000
 1.2.2.4 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.2.2.3 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.2.2.2 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.2.2.1 13-Nov-2001  thorpej file cd18xx.c was added on branch kqueue on 2002-01-10 19:54:18 +0000
 1.3.4.1 16-May-2002  gehenna Add the character device switch.
 1.8.2.5 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.8.2.4 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.8.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.8.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.8.2.1 03-Aug-2004  skrll Sync with HEAD
 1.9.10.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.9.8.1 29-Apr-2005  kent sync with -current
 1.10.4.5 07-Dec-2007  yamt sync with head
 1.10.4.4 27-Oct-2007  yamt sync with head.
 1.10.4.3 03-Sep-2007  yamt sync with head.
 1.10.4.2 30-Dec-2006  yamt sync with head.
 1.10.4.1 21-Jun-2006  yamt sync with head.
 1.13.12.1 24-May-2006  tron Merge 2006-05-24 NetBSD-current into the "peter-altq" branch.
 1.13.10.2 10-Mar-2006  elad generic_authorize() -> kauth_authorize_generic().
 1.13.10.1 08-Mar-2006  elad Adapt to kernel authorization KPI.
 1.13.8.3 11-Aug-2006  yamt sync with head
 1.13.8.2 26-Jun-2006  yamt sync with head.
 1.13.8.1 24-May-2006  yamt sync with head.
 1.13.6.1 01-Jun-2006  kardel Sync with head.
 1.13.4.1 09-Sep-2006  rpaulo sync with head
 1.14.2.1 19-Jun-2006  chap Sync with head.
 1.16.6.1 22-Oct-2006  yamt sync with head
 1.16.4.1 18-Nov-2006  ad Sync with head.
 1.18.4.1 12-Mar-2007  rmind Sync with HEAD.
 1.19.18.1 14-Oct-2007  yamt sync with head.
 1.19.16.2 09-Jan-2008  matt sync with HEAD
 1.19.16.1 06-Nov-2007  matt sync with HEAD
 1.19.14.2 21-Nov-2007  joerg Sync with HEAD.
 1.19.14.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.19.2.2 23-Oct-2007  ad Sync with head.
 1.19.2.1 17-Jun-2007  ad - Increase the number of thread priorities from 128 to 256. How the space
is set up is to be revisited.
- Implement soft interrupts as kernel threads. A generic implementation
is provided, with hooks for fast-path MD code that can run the interrupt
threads over the top of other threads executing in the kernel.
- Split vnode::v_flag into three fields, depending on how the flag is
locked (by the interlock, by the vnode lock, by the file system).
- Miscellaneous locking fixes and improvements.
 1.20.2.2 21-Nov-2007  bouyer Sync with HEAD
 1.20.2.1 25-Oct-2007  bouyer Sync with HEAD.
 1.21.2.1 08-Dec-2007  mjf Sync with HEAD.
 1.22.14.2 29-Jun-2008  mjf Sync with HEAD.
 1.22.14.1 02-Jun-2008  mjf Sync with HEAD.
 1.23.4.2 04-May-2009  yamt sync with head.
 1.23.4.1 16-May-2008  yamt sync with head.
 1.23.2.3 17-Jun-2008  yamt sync with head.
 1.23.2.2 04-Jun-2008  yamt sync with head
 1.23.2.1 18-May-2008  yamt sync with head.
 1.24.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.25.2.1 18-Jun-2008  simonb Sync with head.
 1.26.10.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.26.4.1 28-Apr-2009  skrll Sync with HEAD.
 1.27.6.1 06-Jun-2011  jruoho Sync with HEAD.
 1.27.4.1 31-May-2011  rmind sync with head
 1.28.14.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.28.14.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.28.4.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.28.4.1 30-Oct-2012  yamt sync with head
 1.29.2.1 18-May-2014  rmind sync with head
 1.30.2.1 10-Aug-2014  tls Rebase.
 1.6 06-May-2023  andvar few more typos in the word "register", mainly s/resister/register/.
In one comment I assume that it was meant to be pull-up resistor.
 1.5 30-Dec-2022  andvar s/mdoem/modem/
 1.4 29-May-2008  mrg remove clause #3 from my license where there are no other
copyright holders involved.
 1.3 11-Dec-2005  christos branches: 1.3.70; 1.3.72; 1.3.74; 1.3.76;
merge ktrace-lwp.
 1.2 02-Nov-2003  wiz Fix some typos. From Tom Cosgrove via jmc@openbsd.
 1.1 03-Oct-2001  mrg branches: 1.1.2; 1.1.4; 1.1.8; 1.1.24;
add a backend serial driver for the cirrus logic CL-CD180/1864/1865
8 port chip. this is used in several sbus (sparc) serial boards, as
well as an 8 port isa card from riscom. sio16 (sbus) frontend coming
shortly.

this is heavily based on the com and zs drivers.
 1.1.24.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.1.24.2 18-Sep-2004  skrll Sync with HEAD.
 1.1.24.1 03-Aug-2004  skrll Sync with HEAD
 1.1.8.2 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.1.8.1 03-Oct-2001  thorpej file cd18xxreg.h was added on branch kqueue on 2002-01-10 19:54:18 +0000
 1.1.4.2 11-Oct-2001  fvdl Catch up with -current. Fix some bogons in the sparc64 kbd/ms
attach code. cd18xx conversion provided by mrg.
 1.1.4.1 03-Oct-2001  fvdl file cd18xxreg.h was added on branch thorpej-devvp on 2001-10-11 00:02:02 +0000
 1.1.2.2 08-Oct-2001  nathanw Catch up to -current.
 1.1.2.1 03-Oct-2001  nathanw file cd18xxreg.h was added on branch nathanw_sa on 2001-10-08 20:10:59 +0000
 1.3.76.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.3.74.1 04-May-2009  yamt sync with head.
 1.3.72.1 04-Jun-2008  yamt sync with head
 1.3.70.1 02-Jun-2008  mjf Sync with HEAD.
 1.5 15-Nov-2014  christos centralize the dialout/call unit macros.
 1.4 27-Oct-2012  chs split device_t/softc for all remaining drivers.
replace "struct device *" with "device_t".
use device_xname(), device_unit(), etc.
 1.3 18-Jul-2011  mrg branches: 1.3.2; 1.3.12;
convert the remaining dev/sbus drivers to CFATTACH_DECL_NEW, cfdata_t
and device_t, including the pci frontend and backend for en(4).
 1.2 29-May-2008  mrg remove clause #3 from my license where there are no other
copyright holders involved.
 1.1 03-Oct-2001  mrg branches: 1.1.2; 1.1.4; 1.1.8; 1.1.122; 1.1.124; 1.1.126; 1.1.128;
add a backend serial driver for the cirrus logic CL-CD180/1864/1865
8 port chip. this is used in several sbus (sparc) serial boards, as
well as an 8 port isa card from riscom. sio16 (sbus) frontend coming
shortly.

this is heavily based on the com and zs drivers.
 1.1.128.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.1.126.1 04-May-2009  yamt sync with head.
 1.1.124.1 04-Jun-2008  yamt sync with head
 1.1.122.1 02-Jun-2008  mjf Sync with HEAD.
 1.1.8.2 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.1.8.1 03-Oct-2001  thorpej file cd18xxvar.h was added on branch kqueue on 2002-01-10 19:54:19 +0000
 1.1.4.2 11-Oct-2001  fvdl Catch up with -current. Fix some bogons in the sparc64 kbd/ms
attach code. cd18xx conversion provided by mrg.
 1.1.4.1 03-Oct-2001  fvdl file cd18xxvar.h was added on branch thorpej-devvp on 2001-10-11 00:02:02 +0000
 1.1.2.2 08-Oct-2001  nathanw Catch up to -current.
 1.1.2.1 03-Oct-2001  nathanw file cd18xxvar.h was added on branch nathanw_sa on 2001-10-08 20:10:59 +0000
 1.3.12.2 03-Dec-2017  jdolecek update from HEAD
 1.3.12.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.3.2.1 30-Oct-2012  yamt sync with head
 1.1 05-Nov-2022  jmcneill Add driver for Cadence I2C controller.
 1.1 05-Nov-2022  jmcneill Add driver for Cadence I2C controller.
 1.56 19-Feb-2024  msaitoh ciss(4): Fix panic when the number of logical drive is zero.

Currently, this drives requires at least one logical drive.
If there is no any logical volume, don't attach the driver.
 1.55 17-Aug-2023  andvar fix typos in comments.
 1.54 29-May-2022  rin Audit unload/unmap v.s. free against DMA buffer for sys/dev;
make sure that bus_dmamap_unload(9) [or bus_dmamap_destroy(9)] or
bus_dmamem_unmap(9) are preceding to freeing DMA buffer, if it is
loaded or mapped, respectively.

This is mandatory for some archs. See, e.g.:

http://www.nerv.org/netbsd/?q=id:20210511T013030Z.013443cc790088147e4beed43f53dedabeaf9312
http://www.nerv.org/netbsd/?q=id:20220511T172220Z.561179f0b6fcc5b9cd73e274f69d74e2ce9e4c93

For some drivers, resource leaks for error paths are fixed at
the same time.

XXX XXX XXX
Compile test only (at least one arch per driver).
 1.53 01-Jan-2022  msaitoh s/assoicate/associate/
 1.52 07-Aug-2021  thorpej Merge thorpej-cfargs2.
 1.51 24-Apr-2021  thorpej branches: 1.51.8;
Merge thorpej-cfargs branch:

Simplify and make extensible the config_search() / config_found() /
config_attach() interfaces: rather than having different variants for
which arguments you want pass along, just have a single call that
takes a variadic list of tag-value arguments.

Adjust all call sites:
- Simplify wherever possible; don't pass along arguments that aren't
actually needed.
- Don't be explicit about what interface attribute is attaching if
the device only has one. (More simplification.)
- Add a config_probe() function to be used in indirect configuiration
situations, making is visibly easier to see when indirect config is
in play, and allowing for future change in semantics. (As of now,
this is just a wrapper around config_match(), but that is an
implementation detail.)

Remove unnecessary or redundant interface attributes where they're not
needed.

There are currently 5 "cfargs" defined:
- CFARG_SUBMATCH (submatch function for direct config)
- CFARG_SEARCH (search function for indirect config)
- CFARG_IATTR (interface attribte)
- CFARG_LOCATORS (locators array)
- CFARG_DEVHANDLE (devhandle_t - wraps OFW, ACPI, etc. handles)

...and a sentinel value CFARG_EOL.

Add some extra sanity checking to ensure that interface attributes
aren't ambiguous.

Use CFARG_DEVHANDLE in MI FDT, OFW, and ACPI code, and macppc and shark
ports to associate those device handles with device_t instance. This
will trickle trough to more places over time (need back-end for pre-OFW
Sun OBP; any others?).
 1.50 16-Jul-2020  jdolecek branches: 1.50.4;
revert the conversion to STAILQ, it broke execution of commands
 1.49 14-Jul-2020  jdolecek remove CISS_NO_INTERRUPT_HACK, discussed with joerg@ and spz@
 1.48 14-Jul-2020  jdolecek remove ccb_sc to save memory, no need to store pointer to sc in ccb
 1.47 14-Jul-2020  jdolecek use STAILQ for ccb lists to save some memory, doubly-linked list is not needed
 1.46 14-Jul-2020  jdolecek only copy the actual command length in ciss_scsi_cmd(), instead of always
copying CISS_MAX_CDB bytes

Fixes reading past buffer memory triggered e.g. on kernel dump, reported
by KASAN:
ASan: Unauthorized Access In ...: Addr ... [16 bytes, read, RedZonePartial]

also do not pre-zero the cdb before copying cmd to it, there is no need for it
 1.45 14-Jul-2020  jdolecek g/c #if 0'ed ciss_scsi_raw_cmd()
 1.44 14-Jul-2020  jdolecek add support for PERFORMANT mode, and allow MSI/MSI-X (only) for adapters which
support it

code adapted from FreeBSD, but with fix for setting the performant bit
and pull count on command submittion as seen in hpsa Linux driver

tested with INTx and MSI-X on HP Smart Array 11

thanks to Andreas Gustafsson for initial testing, and providing
access to test machine
 1.43 10-Jul-2020  jdolecek remove write-only sc_ccbq, and unused sc_ccbdone
 1.42 15-May-2020  maxv hardclock_ticks -> getticks()
 1.41 10-Nov-2019  chs in many device attach paths, allocate memory with M_WAITOK instead of M_NOWAIT
and remove code to handle failures that can no longer happen.
 1.40 08-May-2019  cnst bio(4) drivers: remove noop fallthrough-to-default bio(4) cmd cases

* Makes it easier to do code/feature analysis by not having
extra noop code/symbols spattered around.

* Only an issue in cac(4) and ciss(4); other drivers don't do this.

* No binary changes.
 1.39 03-Sep-2018  riastradh Rename min/max -> uimin/uimax for better honesty.

These functions are defined on unsigned int. The generic name
min/max should not silently truncate to 32 bits on 64-bit systems.
This is purely a name change -- no functional change intended.

HOWEVER! Some subsystems have

#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))

even though our standard name for that is MIN/MAX. Although these
may invite multiple evaluation bugs, these do _not_ cause integer
truncation.

To avoid `fixing' these cases, I first changed the name in libkern,
and then compile-tested every file where min/max occurred in order to
confirm that it failed -- and thus confirm that nothing shadowed
min/max -- before changing it.

I have left a handful of bootloaders that are too annoying to
compile-test, and some dead code:

cobalt ews4800mips hp300 hppa ia64 luna68k vax
acorn32/if_ie.c (not included in any kernels)
macppc/if_gm.c (superseded by gem(4))

It should be easy to fix the fallout once identified -- this way of
doing things fails safe, and the goal here, after all, is to _avoid_
silent integer truncations, not introduce them.

Maybe one day we can reintroduce min/max as type-generic things that
never silently truncate. But we should avoid doing that for a while,
so that existing code has a chance to be detected by the compiler for
conversion to uimin/uimax without changing the semantics until we can
properly audit it all. (Who knows, maybe in some cases integer
truncation is actually intended!)
 1.38 12-Feb-2018  joerg branches: 1.38.2; 1.38.4;
Add a new option CISS_NO_INTERRUPT_HACK for driving ciss(4) by callouts.
This is intended as workaround for certain Xen issues with dom0 kernels
and will likely want to have a high HZ value as well for decent
performance.
 1.37 28-Jul-2017  riastradh Reject negative indices from userland.

From Ilja Van Sprundel.
 1.36 14-Jul-2016  msaitoh branches: 1.36.10;
- Use aprint*() instead of printf() in xxx_attach().
- Add missing aprint_naive("\n");
- KNF
 1.35 12-Mar-2015  christos use hardclock_ticks; pointed out by hannken.
 1.34 12-Mar-2015  christos Untangle the poll/wait/timeout code in ciss_cmd() Tested on a DL-360.
 1.33 12-Mar-2015  christos Dedup the conversion of bioc_disk and bioc_vol to envsys_data_t
 1.32 17-Oct-2013  christos branches: 1.32.4; 1.32.6; 1.32.8; 1.32.12;
- remove unused variables
- move variables inside ifdef sections
- ifdef notdef unused code
- use __USE for debugging variables
 1.31 13-Oct-2013  christos make the driver able to send scsi commands; now the disks are found.
it was converted incorrectly to device_t.
 1.30 12-Oct-2013  christos - add 64 bit fifo support
- handle fibrilation better
 1.29 27-Oct-2012  chs branches: 1.29.2;
split device_t/softc for all remaining drivers.
replace "struct device *" with "device_t".
use device_xname(), device_unit(), etc.
 1.28 23-Sep-2012  chs don't try to handle sensors if there aren't any.
 1.27 20-Jun-2011  pgoyette branches: 1.27.2; 1.27.8; 1.27.12; 1.27.14;
Initialize current value for ENVSYS_DRIVE sensors
 1.26 20-Jun-2011  pgoyette Initializes sensors states before registering.
 1.25 16-May-2011  mhitch branches: 1.25.2;
I was allowing adapt_max_periph to use all available command slots, which
easily exceeds the maximum of 256 tags used by the scsipi layer because
the tag information from the scsipi layer was ignored and all the tagging
is handled implicitly internal to ciss(4). But with the DIAGNOSTIC option,
the scsipi layer does a check for > 256 tags and will panic. So, lets just
limit the adapt_max_periph to 256 so the scsipi layer won't try to user more.
 1.24 13-Nov-2010  uebayasi branches: 1.24.2;
Don't pull in the whole uvm(9) API to access only PAGE_SIZE and
some other constants. These are provided by sys/param.h now.
 1.23 07-Sep-2010  mhitch Fix a performance problem with the ciss(4) driver. NetBSD does common
queueing at the scsipi midlayer, and if the midlayer is not requested to
enable tagged queueing, the midlayer will only queue one command to the
adapter driver for each device. The SmartArray adapter is capable of
handling multiple commands, and in the rather common case where there is
no battery backup and no write cache, doing single write commands is very
slow. The SmartArray adapter runs much better when several commands can
be issued to a device.

This has been observed and discussed in several list threads, notably:
http://mail-index.NetBSD.org/netbsd-users/2008/10/01/msg002083.html
http://mail-index.NetBSD.org/tech-kern/2008/11/30/msg003704.html

This also addresses PR kern/39686.

To enable tagged queueing, the adapter driver responds to the midlayer
request to set the transfer mode. However, the SmartArray does not respond
to the SCSI INQUIRY command with an ANSII field of 2 or more, so the
scsipi midlayer will ignore the CmdQue bit in the flags3 field of the
inquiry data. This fix will patch the inquiry data so set the ANSII field
to 2, and responds to the midlayer request to set the transfer mode by
requesting tagged queueing.

In addition, the original port of the driver did not set up the adapter
parameters correctly as mentioned in the second list thread mentioned
above. The adapt_openings is the total number of commands that the
adapter will accept rather than the number of commands divided by the
number of logical drives. Also, the adapt_max_periph is the maximum number
of commands which can be queued per peripheral device, not the number of
logical drives [which in the case of a single logical drive limited the
number of commands queued to 1].

I'm also suppressing an error message for invalid commands if the error
was due to the SCSI_SYNCHRONIZE_CACHE_10 command, since that command is
not supported by the SmartArray adapter, but used with wapbl(4) meta-data
journaling. Setting the ANSII version to 2 to allow enabling tagged queueing
also enables the use of the SCSI_SYNCHRONIZE_CACHE_10 command.
 1.22 27-Jul-2010  jakllsch Print size_t with 'z' in debug code.
 1.21 26-Jul-2010  jym Add PAE to ALL kernel, so that most paddr_t format string errors get caught
during compilation.

While here, fix the compilation for ALL.
 1.20 14-Mar-2010  pgoyette branches: 1.20.2;
Remove setting of edata->monitor since that member no longer exists.
 1.19 12-May-2009  cegger branches: 1.19.2;
struct device * -> device_t, no functional changes intended.
 1.18 18-Apr-2009  tsutsui Remove extra whitespace added by a stupid tool.
XXX: more in src/sys/arch
 1.17 18-Mar-2009  cegger bcopy -> memcpy
 1.16 18-Mar-2009  cegger bzero -> memset
 1.15 13-Feb-2009  bouyer More printf format fixes.
 1.14 04-Sep-2008  he branches: 1.14.2; 1.14.4; 1.14.8; 1.14.10;
Adopt a fix from OpenBSD, revision 1.30 in their CVS repository.
To paraphrase:
Some ciss(4) firmwares use different physical drive addressing, resulting
in bioctl(8) functions not being available.
Tested on both types of controller.
 1.13 04-Sep-2008  mhitch Limit the number of luns to 1, since the SCSI device ciss(4) presents
doesn't appear to luns and later controllers would respond to probe
requests for luns > 0.
 1.12 25-May-2008  mhitch branches: 1.12.4;
Add bio(4) support, heavily from OpenBSD. The driver doesn't know which
physical drives belong to which logical drive, so all the physical drives
will show up for logical drive 0, and also appear for logical drives that
are rebuilding so that the rebuild state will show the physical drive
being rebuilt. Locking for the scratch buffer is currently missing - system
quickly quits responding when I try to lock the buffer with mutex_{enter,exit}().
 1.11 08-Apr-2008  cegger branches: 1.11.2; 1.11.4; 1.11.6;
use aprint_*_dev and device_xname
 1.10 15-Dec-2007  perry branches: 1.10.6;
__FUNCTION__ -> __func__
 1.9 19-Oct-2007  ad branches: 1.9.4; 1.9.8;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.8 09-Jul-2007  ad branches: 1.8.6; 1.8.8; 1.8.12;
Merge some of the less invasive changes from the vmlocking branch:

- kthread, callout, devsw API changes
- select()/poll() improvements
- miscellaneous MT safety improvements
 1.7 04-Mar-2007  christos branches: 1.7.2; 1.7.4;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.6 16-Nov-2006  christos branches: 1.6.4;
__unused removal on arguments; approved by core.
 1.5 12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.4 04-Oct-2006  christos fix empty if body.
 1.3 27-May-2006  he branches: 1.3.4; 1.3.8; 1.3.10; 1.3.12;
Remove setting of xs_status to XS_STS_DONE before calling scspi_done().
After revision 1.135 of scsipi_base.c, it's a big no-no to set
XS_STS_DONE before calling scsipi_done(). Besides, scsipi_done()
sets XS_STS_DONE itself after checking that it's not already set.

This puts this driver back in working order; before this change
the probe of the logical drives would cause a hang.
 1.2 15-Apr-2006  martti branches: 1.2.2; 1.2.4; 1.2.6;
Merged changes between OpenBSD rev 1.13 and 1.14.
 1.1 21-Mar-2006  he branches: 1.1.2; 1.1.4; 1.1.6; 1.1.8;
Add a driver, ciss(4), for the HP/Compaq drivers using the newer
"Command Interface to SCSI-3 Support" command interface. Driver
ported from OpenBSD by Tonnerre Lombard -- thanks!
 1.1.8.4 26-Jun-2006  yamt sync with head.
 1.1.8.3 24-May-2006  yamt sync with head.
 1.1.8.2 11-Apr-2006  yamt sync files somehow mis-tagged by yamt-pdpolicy-base2.
 1.1.8.1 21-Mar-2006  yamt file ciss.c was added on branch yamt-pdpolicy on 2006-04-11 12:20:52 +0000
 1.1.6.3 21-Apr-2006  tron Pull up following revision(s) (requested by martti in ticket #10451):
sys/dev/ic/ciss.c: revision 1.2
Merged changes between OpenBSD rev 1.13 and 1.14.
 1.1.6.2 11-Apr-2006  riz Pull up following revision(s) (requested by he in ticket #10409):
sys/dev/ic/cissreg.h: revision 1.1
sys/dev/pci/ciss_pci.c: revision 1.1
sys/dev/ic/cissvar.h: revision 1.1
sys/dev/pci/files.pci: revision 1.245
sys/dev/ic/ciss.c: revision 1.1 via patch
Add a driver, ciss(4), for the HP/Compaq drivers using the newer
"Command Interface to SCSI-3 Support" command interface. Driver
ported from OpenBSD by Tonnerre Lombard -- thanks!
 1.1.6.1 21-Mar-2006  riz file ciss.c was added on branch netbsd-2 on 2006-04-11 01:15:22 +0000
 1.1.4.3 21-Apr-2006  tron Pull up following revision(s) (requested by martti in ticket #1275):
sys/dev/ic/ciss.c: revision 1.2
Merged changes between OpenBSD rev 1.13 and 1.14.
 1.1.4.2 08-Apr-2006  tron Pull up following revision(s) (requested by he in ticket #1247):
sys/dev/ic/cissreg.h: revision 1.1
sys/dev/pci/ciss_pci.c: revision 1.1
sys/dev/ic/cissvar.h: revision 1.1
sys/dev/pci/files.pci: revision 1.245
sys/dev/ic/ciss.c: revision 1.1
Add a driver, ciss(4), for the HP/Compaq drivers using the newer
"Command Interface to SCSI-3 Support" command interface. Driver
ported from OpenBSD by Tonnerre Lombard -- thanks!
 1.1.4.1 21-Mar-2006  tron file ciss.c was added on branch netbsd-3 on 2006-04-08 23:31:38 +0000
 1.1.2.3 24-May-2006  tron Merge 2006-05-24 NetBSD-current into the "peter-altq" branch.
 1.1.2.2 28-Mar-2006  tron Merge 2006-03-28 NetBSD-current into the "peter-altq" branch.
 1.1.2.1 21-Mar-2006  tron file ciss.c was added on branch peter-altq on 2006-03-28 09:42:11 +0000
 1.2.6.1 19-Jun-2006  chap Sync with head.
 1.2.4.3 01-Jun-2006  kardel Sync with head.
 1.2.4.2 22-Apr-2006  simonb Sync with head.
 1.2.4.1 15-Apr-2006  simonb file ciss.c was added on branch simonb-timecounters on 2006-04-22 11:38:55 +0000
 1.2.2.2 19-Apr-2006  elad sync with head.
 1.2.2.1 15-Apr-2006  elad file ciss.c was added on branch elad-kernelauth on 2006-04-19 03:24:38 +0000
 1.3.12.2 10-Dec-2006  yamt sync with head.
 1.3.12.1 22-Oct-2006  yamt sync with head
 1.3.10.2 09-Sep-2006  rpaulo sync with head
 1.3.10.1 27-May-2006  rpaulo file ciss.c was added on branch rpaulo-netinet-merge-pcb on 2006-09-09 02:50:01 +0000
 1.3.8.1 18-Nov-2006  ad Sync with head.
 1.3.4.6 21-Jan-2008  yamt sync with head
 1.3.4.5 27-Oct-2007  yamt sync with head.
 1.3.4.4 03-Sep-2007  yamt sync with head.
 1.3.4.3 30-Dec-2006  yamt sync with head.
 1.3.4.2 21-Jun-2006  yamt sync with head.
 1.3.4.1 27-May-2006  yamt file ciss.c was added on branch yamt-lazymbuf on 2006-06-21 15:02:53 +0000
 1.6.4.1 12-Mar-2007  rmind Sync with HEAD.
 1.7.4.1 11-Jul-2007  mjf Sync with head.
 1.7.2.2 23-Oct-2007  ad Sync with head.
 1.7.2.1 01-Jul-2007  ad Adapt to callout API change.
 1.8.12.1 25-Oct-2007  bouyer Sync with HEAD.
 1.8.8.2 09-Jan-2008  matt sync with HEAD
 1.8.8.1 06-Nov-2007  matt sync with HEAD
 1.8.6.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.9.8.1 02-Jan-2008  bouyer Sync with HEAD
 1.9.4.1 26-Dec-2007  ad Sync with head.
 1.10.6.2 28-Sep-2008  mjf Sync with HEAD.
 1.10.6.1 02-Jun-2008  mjf Sync with HEAD.
 1.11.6.2 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.11.6.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.11.4.4 09-Oct-2010  yamt sync with head
 1.11.4.3 11-Aug-2010  yamt sync with head.
 1.11.4.2 16-May-2009  yamt sync with head
 1.11.4.1 04-May-2009  yamt sync with head.
 1.11.2.1 04-Jun-2008  yamt sync with head
 1.12.4.1 19-Oct-2008  haad Sync with HEAD.
 1.14.10.1 26-Jul-2009  snj branches: 1.14.10.1.2;
Pull up following revision(s) (requested by dholland in ticket #874):
sys/dev/ic/ciss.c: revision 1.15
sys/dev/isa/isadma.c: revision 1.59
sys/dev/usb/ulpt.c: revision 1.82
sys/dev/ic/tcic2.c: revision 1.31
sys/dev/isa/if_ntwoc_isa.c: revision 1.18
sys/dev/pci/if_sk.c: revision 1.57
sys/dev/pcmcia/if_cnw.c: revision 1.46
More printf format fixes.
 1.14.10.1.2.1 21-Apr-2010  matt sync to netbsd-5
 1.14.8.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.14.4.3 02-Nov-2011  riz Pull up following revision(s) (requested by mhitch in ticket #1674):
sys/dev/ic/ciss.c: revision 1.25
I was allowing adapt_max_periph to use all available command slots, which
easily exceeds the maximum of 256 tags used by the scsipi layer because
the tag information from the scsipi layer was ignored and all the tagging
is handled implicitly internal to ciss(4). But with the DIAGNOSTIC option,
the scsipi layer does a check for > 256 tags and will panic. So, lets just
limit the adapt_max_periph to 256 so the scsipi layer won't try to user more.
 1.14.4.2 21-Nov-2010  riz Pull up following revision(s) (requested by pettai in ticket #1452):
sys/dev/ic/ciss.c: revision 1.23
Fix a performance problem with the ciss(4) driver. NetBSD does common
queueing at the scsipi midlayer, and if the midlayer is not requested to
enable tagged queueing, the midlayer will only queue one command to the
adapter driver for each device. The SmartArray adapter is capable of
handling multiple commands, and in the rather common case where there is
no battery backup and no write cache, doing single write commands is very
slow. The SmartArray adapter runs much better when several commands can
be issued to a device.
This has been observed and discussed in several list threads, notably:
http://mail-index.NetBSD.org/netbsd-users/2008/10/01/msg002083.html
http://mail-index.NetBSD.org/tech-kern/2008/11/30/msg003704.html
This also addresses PR kern/39686.
To enable tagged queueing, the adapter driver responds to the midlayer
request to set the transfer mode. However, the SmartArray does not respond
to the SCSI INQUIRY command with an ANSII field of 2 or more, so the
scsipi midlayer will ignore the CmdQue bit in the flags3 field of the
inquiry data. This fix will patch the inquiry data so set the ANSII field
to 2, and responds to the midlayer request to set the transfer mode by
requesting tagged queueing.
In addition, the original port of the driver did not set up the adapter
parameters correctly as mentioned in the second list thread mentioned
above. The adapt_openings is the total number of commands that the
adapter will accept rather than the number of commands divided by the
number of logical drives. Also, the adapt_max_periph is the maximum number
of commands which can be queued per peripheral device, not the number of
logical drives [which in the case of a single logical drive limited the
number of commands queued to 1].
I'm also suppressing an error message for invalid commands if the error
was due to the SCSI_SYNCHRONIZE_CACHE_10 command, since that command is
not supported by the SmartArray adapter, but used with wapbl(4) meta-data
journaling. Setting the ANSII version to 2 to allow enabling tagged queueing
also enables the use of the SCSI_SYNCHRONIZE_CACHE_10 command.
 1.14.4.1 26-Jul-2009  snj Pull up following revision(s) (requested by dholland in ticket #874):
sys/dev/ic/ciss.c: revision 1.15
sys/dev/isa/isadma.c: revision 1.59
sys/dev/usb/ulpt.c: revision 1.82
sys/dev/ic/tcic2.c: revision 1.31
sys/dev/isa/if_ntwoc_isa.c: revision 1.18
sys/dev/pci/if_sk.c: revision 1.57
sys/dev/pcmcia/if_cnw.c: revision 1.46
More printf format fixes.
 1.14.2.2 28-Apr-2009  skrll Sync with HEAD.
 1.14.2.1 03-Mar-2009  skrll Sync with HEAD.
 1.19.2.3 22-Oct-2010  uebayasi Sync with HEAD (-D20101022).
 1.19.2.2 17-Aug-2010  uebayasi Sync with HEAD.
 1.19.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.20.2.2 31-May-2011  rmind sync with head
 1.20.2.1 05-Mar-2011  rmind sync with head
 1.24.2.1 06-Jun-2011  jruoho Sync with HEAD.
 1.25.2.1 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.27.14.2 19-Aug-2017  snj Pull up following revision(s) (requested by mrg in ticket #1486):
sys/dev/ic/ciss.c: revision 1.37
Reject negative indices from userland.
 1.27.14.1 22-Nov-2012  riz Pull up following revision(s) (requested by chs in ticket #687):
sys/dev/ic/ciss.c: revision 1.28
don't try to handle sensors if there aren't any.
 1.27.12.3 03-Dec-2017  jdolecek update from HEAD
 1.27.12.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.27.12.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.27.8.2 19-Aug-2017  snj Pull up following revision(s) (requested by mrg in ticket #1486):
sys/dev/ic/ciss.c: revision 1.37
Reject negative indices from userland.
 1.27.8.1 22-Nov-2012  riz branches: 1.27.8.1.2;
Pull up following revision(s) (requested by chs in ticket #687):
sys/dev/ic/ciss.c: revision 1.28
don't try to handle sensors if there aren't any.
 1.27.8.1.2.1 19-Aug-2017  snj Pull up following revision(s) (requested by mrg in ticket #1486):
sys/dev/ic/ciss.c: revision 1.37
Reject negative indices from userland.
 1.27.2.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.27.2.1 30-Oct-2012  yamt sync with head
 1.29.2.1 18-May-2014  rmind sync with head
 1.32.12.1 12-Aug-2017  snj Pull up following revision(s) (requested by mrg in ticket #1483):
sys/dev/ic/ciss.c: revision 1.37
Reject negative indices from userland.
 1.32.8.1 12-Aug-2017  snj Pull up following revision(s) (requested by mrg in ticket #1483):
sys/dev/ic/ciss.c: revision 1.37
Reject negative indices from userland.
 1.32.6.3 28-Aug-2017  skrll Sync with HEAD
 1.32.6.2 05-Oct-2016  skrll Sync with HEAD
 1.32.6.1 06-Apr-2015  skrll Sync with HEAD
 1.32.4.1 12-Aug-2017  snj Pull up following revision(s) (requested by mrg in ticket #1483):
sys/dev/ic/ciss.c: revision 1.37
Reject negative indices from userland.
 1.36.10.2 09-Apr-2018  bouyer Pull up following revision(s) (requested by spz in ticket #708):
sys/conf/files: revision 1.1194
sys/dev/ic/cissvar.h: revision 1.7
sys/dev/ic/ciss.c: revision 1.38
sys/dev/pci/ciss_pci.c: revision 1.14
sys/arch/amd64/conf/ALL: revision 1.81
Add a new option CISS_NO_INTERRUPT_HACK for driving ciss(4) by callouts.
This is intended as workaround for certain Xen issues with dom0 kernels
and will likely want to have a high HZ value as well for decent
performance.
 1.36.10.1 09-Aug-2017  snj Pull up following revision(s) (requested by spz in ticket #196):
sys/dev/ic/ciss.c: revision 1.37
Reject negative indices from userland.
 1.38.4.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.38.4.1 10-Jun-2019  christos Sync with HEAD
 1.38.2.1 06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.50.4.1 21-Mar-2021  thorpej Give config_found() the same variadic arguments treatment as
config_search(). This commit only adds the CFARG_EOL sentinel
to the existing config_found() calls. Conversion of config_found_sm_loc()
and config_found_ia() call sites will be in subsequent commits.
 1.51.8.1 04-Aug-2021  thorpej Adapt to CFARGS().
 1.11 01-Nov-2022  andvar s/faild/failed/ in comments and messages.
 1.10 16-Jul-2020  jdolecek make sure the alignment of ciss_cmd matches KASSERT() in ciss_cmd()
 1.9 16-Jul-2020  jdolecek revert the conversion to STAILQ, it broke execution of commands
 1.8 14-Jul-2020  jdolecek remove ccb_sc to save memory, no need to store pointer to sc in ccb
 1.7 14-Jul-2020  jdolecek use STAILQ for ccb lists to save some memory, doubly-linked list is not needed
 1.6 14-Jul-2020  jdolecek add support for PERFORMANT mode, and allow MSI/MSI-X (only) for adapters which
support it

code adapted from FreeBSD, but with fix for setting the performant bit
and pull count on command submittion as seen in hpsa Linux driver

tested with INTx and MSI-X on HP Smart Array 11

thanks to Andreas Gustafsson for initial testing, and providing
access to test machine
 1.5 17-Jun-2016  christos rename intr bits
 1.4 12-Oct-2013  christos branches: 1.4.6;
- add 64 bit fifo support
- handle fibrilation better
 1.3 18-Oct-2008  bouyer branches: 1.3.28; 1.3.38; 1.3.44;
kern/39757 from mishka@:
Bump CISS_MAX_CDB from 12 to 16 bytes. For volumes larger than 2TB,
the scsipi layer will have to use 16 bytes SCSI commands, which would be
rejected by ciss. The cdb buffer already 16 bytes long, and a look at the
FreeBSD driver shows there's no reasons to limit SCSI commands to 12 bytes.
 1.2 25-May-2008  mhitch branches: 1.2.4;
Add bio(4) support, heavily from OpenBSD. The driver doesn't know which
physical drives belong to which logical drive, so all the physical drives
will show up for logical drive 0, and also appear for logical drives that
are rebuilding so that the rebuild state will show the physical drive
being rebuilt. Locking for the scratch buffer is currently missing - system
quickly quits responding when I try to lock the buffer with mutex_{enter,exit}().
 1.1 21-Mar-2006  he branches: 1.1.2; 1.1.4; 1.1.6; 1.1.8; 1.1.10; 1.1.12; 1.1.18; 1.1.24; 1.1.74; 1.1.76; 1.1.78; 1.1.80;
Add a driver, ciss(4), for the HP/Compaq drivers using the newer
"Command Interface to SCSI-3 Support" command interface. Driver
ported from OpenBSD by Tonnerre Lombard -- thanks!
 1.1.80.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.1.78.1 04-May-2009  yamt sync with head.
 1.1.76.1 04-Jun-2008  yamt sync with head
 1.1.74.2 17-Jan-2009  mjf Sync with HEAD.
 1.1.74.1 02-Jun-2008  mjf Sync with HEAD.
 1.1.24.2 09-Sep-2006  rpaulo sync with head
 1.1.24.1 21-Mar-2006  rpaulo file cissreg.h was added on branch rpaulo-netinet-merge-pcb on 2006-09-09 02:50:01 +0000
 1.1.18.2 21-Jun-2006  yamt sync with head.
 1.1.18.1 21-Mar-2006  yamt file cissreg.h was added on branch yamt-lazymbuf on 2006-06-21 15:02:53 +0000
 1.1.12.2 22-Apr-2006  simonb Sync with head.
 1.1.12.1 21-Mar-2006  simonb file cissreg.h was added on branch simonb-timecounters on 2006-04-22 11:38:55 +0000
 1.1.10.2 19-Apr-2006  elad sync with head.
 1.1.10.1 21-Mar-2006  elad file cissreg.h was added on branch elad-kernelauth on 2006-04-19 03:24:38 +0000
 1.1.8.2 11-Apr-2006  yamt sync files somehow mis-tagged by yamt-pdpolicy-base2.
 1.1.8.1 21-Mar-2006  yamt file cissreg.h was added on branch yamt-pdpolicy on 2006-04-11 12:20:52 +0000
 1.1.6.2 11-Apr-2006  riz Pull up following revision(s) (requested by he in ticket #10409):
sys/dev/ic/cissreg.h: revision 1.1
sys/dev/pci/ciss_pci.c: revision 1.1
sys/dev/ic/cissvar.h: revision 1.1
sys/dev/pci/files.pci: revision 1.245
sys/dev/ic/ciss.c: revision 1.1 via patch
Add a driver, ciss(4), for the HP/Compaq drivers using the newer
"Command Interface to SCSI-3 Support" command interface. Driver
ported from OpenBSD by Tonnerre Lombard -- thanks!
 1.1.6.1 21-Mar-2006  riz file cissreg.h was added on branch netbsd-2 on 2006-04-11 01:15:22 +0000
 1.1.4.2 08-Apr-2006  tron Pull up following revision(s) (requested by he in ticket #1247):
sys/dev/ic/cissreg.h: revision 1.1
sys/dev/pci/ciss_pci.c: revision 1.1
sys/dev/ic/cissvar.h: revision 1.1
sys/dev/pci/files.pci: revision 1.245
sys/dev/ic/ciss.c: revision 1.1
Add a driver, ciss(4), for the HP/Compaq drivers using the newer
"Command Interface to SCSI-3 Support" command interface. Driver
ported from OpenBSD by Tonnerre Lombard -- thanks!
 1.1.4.1 21-Mar-2006  tron file cissreg.h was added on branch netbsd-3 on 2006-04-08 23:31:38 +0000
 1.1.2.2 28-Mar-2006  tron Merge 2006-03-28 NetBSD-current into the "peter-altq" branch.
 1.1.2.1 21-Mar-2006  tron file cissreg.h was added on branch peter-altq on 2006-03-28 09:42:11 +0000
 1.2.4.1 19-Oct-2008  haad Sync with HEAD.
 1.3.44.1 18-May-2014  rmind sync with head
 1.3.38.2 03-Dec-2017  jdolecek update from HEAD
 1.3.38.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.3.28.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.4.6.1 09-Jul-2016  skrll Sync with HEAD
 1.11 15-Jul-2020  jdolecek g/c unused sc_channel_raw, sc_adapter_raw
 1.10 14-Jul-2020  jdolecek remove CISS_NO_INTERRUPT_HACK, discussed with joerg@ and spz@
 1.9 14-Jul-2020  jdolecek add support for PERFORMANT mode, and allow MSI/MSI-X (only) for adapters which
support it

code adapted from FreeBSD, but with fix for setting the performant bit
and pull count on command submittion as seen in hpsa Linux driver

tested with INTx and MSI-X on HP Smart Array 11

thanks to Andreas Gustafsson for initial testing, and providing
access to test machine
 1.8 10-Jul-2020  jdolecek remove write-only sc_ccbq, and unused sc_ccbdone
 1.7 12-Feb-2018  joerg Add a new option CISS_NO_INTERRUPT_HACK for driving ciss(4) by callouts.
This is intended as workaround for certain Xen issues with dom0 kernels
and will likely want to have a high HZ value as well for decent
performance.
 1.6 12-Oct-2013  christos branches: 1.6.22;
- add 64 bit fifo support
- handle fibrilation better
 1.5 27-Oct-2012  chs branches: 1.5.2;
split device_t/softc for all remaining drivers.
replace "struct device *" with "device_t".
use device_xname(), device_unit(), etc.
 1.4 12-May-2009  cegger branches: 1.4.12; 1.4.22;
struct device * -> device_t, no functional changes intended.
 1.3 25-May-2008  mhitch branches: 1.3.12;
Add bio(4) support, heavily from OpenBSD. The driver doesn't know which
physical drives belong to which logical drive, so all the physical drives
will show up for logical drive 0, and also appear for logical drives that
are rebuilding so that the rebuild state will show the physical drive
being rebuilt. Locking for the scratch buffer is currently missing - system
quickly quits responding when I try to lock the buffer with mutex_{enter,exit}().
 1.2 04-Mar-2007  christos branches: 1.2.36; 1.2.38; 1.2.40; 1.2.42;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.1 21-Mar-2006  he branches: 1.1.2; 1.1.4; 1.1.6; 1.1.8; 1.1.10; 1.1.12; 1.1.18; 1.1.24; 1.1.30;
Add a driver, ciss(4), for the HP/Compaq drivers using the newer
"Command Interface to SCSI-3 Support" command interface. Driver
ported from OpenBSD by Tonnerre Lombard -- thanks!
 1.1.30.1 12-Mar-2007  rmind Sync with HEAD.
 1.1.24.2 09-Sep-2006  rpaulo sync with head
 1.1.24.1 21-Mar-2006  rpaulo file cissvar.h was added on branch rpaulo-netinet-merge-pcb on 2006-09-09 02:50:01 +0000
 1.1.18.3 03-Sep-2007  yamt sync with head.
 1.1.18.2 21-Jun-2006  yamt sync with head.
 1.1.18.1 21-Mar-2006  yamt file cissvar.h was added on branch yamt-lazymbuf on 2006-06-21 15:02:53 +0000
 1.1.12.2 22-Apr-2006  simonb Sync with head.
 1.1.12.1 21-Mar-2006  simonb file cissvar.h was added on branch simonb-timecounters on 2006-04-22 11:38:55 +0000
 1.1.10.2 19-Apr-2006  elad sync with head.
 1.1.10.1 21-Mar-2006  elad file cissvar.h was added on branch elad-kernelauth on 2006-04-19 03:24:38 +0000
 1.1.8.2 11-Apr-2006  yamt sync files somehow mis-tagged by yamt-pdpolicy-base2.
 1.1.8.1 21-Mar-2006  yamt file cissvar.h was added on branch yamt-pdpolicy on 2006-04-11 12:20:52 +0000
 1.1.6.2 11-Apr-2006  riz Pull up following revision(s) (requested by he in ticket #10409):
sys/dev/ic/cissreg.h: revision 1.1
sys/dev/pci/ciss_pci.c: revision 1.1
sys/dev/ic/cissvar.h: revision 1.1
sys/dev/pci/files.pci: revision 1.245
sys/dev/ic/ciss.c: revision 1.1 via patch
Add a driver, ciss(4), for the HP/Compaq drivers using the newer
"Command Interface to SCSI-3 Support" command interface. Driver
ported from OpenBSD by Tonnerre Lombard -- thanks!
 1.1.6.1 21-Mar-2006  riz file cissvar.h was added on branch netbsd-2 on 2006-04-11 01:15:22 +0000
 1.1.4.2 08-Apr-2006  tron Pull up following revision(s) (requested by he in ticket #1247):
sys/dev/ic/cissreg.h: revision 1.1
sys/dev/pci/ciss_pci.c: revision 1.1
sys/dev/ic/cissvar.h: revision 1.1
sys/dev/pci/files.pci: revision 1.245
sys/dev/ic/ciss.c: revision 1.1
Add a driver, ciss(4), for the HP/Compaq drivers using the newer
"Command Interface to SCSI-3 Support" command interface. Driver
ported from OpenBSD by Tonnerre Lombard -- thanks!
 1.1.4.1 21-Mar-2006  tron file cissvar.h was added on branch netbsd-3 on 2006-04-08 23:31:38 +0000
 1.1.2.2 28-Mar-2006  tron Merge 2006-03-28 NetBSD-current into the "peter-altq" branch.
 1.1.2.1 21-Mar-2006  tron file cissvar.h was added on branch peter-altq on 2006-03-28 09:42:11 +0000
 1.2.42.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.2.40.2 16-May-2009  yamt sync with head
 1.2.40.1 04-May-2009  yamt sync with head.
 1.2.38.1 04-Jun-2008  yamt sync with head
 1.2.36.1 02-Jun-2008  mjf Sync with HEAD.
 1.3.12.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.4.22.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.4.22.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.4.12.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.4.12.1 30-Oct-2012  yamt sync with head
 1.5.2.1 18-May-2014  rmind sync with head
 1.6.22.1 09-Apr-2018  bouyer Pull up following revision(s) (requested by spz in ticket #708):
sys/conf/files: revision 1.1194
sys/dev/ic/cissvar.h: revision 1.7
sys/dev/ic/ciss.c: revision 1.38
sys/dev/pci/ciss_pci.c: revision 1.14
sys/arch/amd64/conf/ALL: revision 1.81
Add a new option CISS_NO_INTERRUPT_HACK for driving ciss(4) by callouts.
This is intended as workaround for certain Xen issues with dom0 kernels
and will likely want to have a high HZ value as well for decent
performance.
 1.54 10-Nov-2019  chs in many device attach paths, allocate memory with M_WAITOK instead of M_NOWAIT
and remove code to handle failures that can no longer happen.
 1.53 03-Sep-2018  riastradh Rename min/max -> uimin/uimax for better honesty.

These functions are defined on unsigned int. The generic name
min/max should not silently truncate to 32 bits on 64-bit systems.
This is purely a name change -- no functional change intended.

HOWEVER! Some subsystems have

#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))

even though our standard name for that is MIN/MAX. Although these
may invite multiple evaluation bugs, these do _not_ cause integer
truncation.

To avoid `fixing' these cases, I first changed the name in libkern,
and then compile-tested every file where min/max occurred in order to
confirm that it failed -- and thus confirm that nothing shadowed
min/max -- before changing it.

I have left a handful of bootloaders that are too annoying to
compile-test, and some dead code:

cobalt ews4800mips hp300 hppa ia64 luna68k vax
acorn32/if_ie.c (not included in any kernels)
macppc/if_gm.c (superseded by gem(4))

It should be easy to fix the fallout once identified -- this way of
doing things fails safe, and the goal here, after all, is to _avoid_
silent integer truncations, not introduce them.

Maybe one day we can reintroduce min/max as type-generic things that
never silently truncate. But we should avoid doing that for a while,
so that existing code has a chance to be detected by the compiler for
conversion to uimin/uimax without changing the semantics until we can
properly audit it all. (Who knows, maybe in some cases integer
truncation is actually intended!)
 1.52 28-Oct-2017  riastradh branches: 1.52.2; 1.52.4;
Kill some more extern struct cfdriver declarations.

Down with externs in .c!
 1.51 15-Nov-2014  christos centralize the dialout/call unit macros.
 1.50 18-Oct-2014  snj src is too big these days to tolerate superfluous apostrophes. It's
"its", people!
 1.49 25-Jul-2014  dholland Add d_discard to all struct cdevsw instances I could find.

All have been set to "nodiscard"; some should get a real implementation.
 1.48 25-Mar-2014  christos branches: 1.48.2;
fix unused/uninitialized
 1.47 16-Mar-2014  dholland Change (mostly mechanically) every cdevsw/bdevsw I can find to use
designated initializers.

I have not built every extant kernel so I have probably broken at
least one build; however I've also found and fixed some wrong
cdevsw/bdevsw entries so even if so I think we come out ahead.
 1.46 27-Oct-2012  chs branches: 1.46.2;
split device_t/softc for all remaining drivers.
replace "struct device *" with "device_t".
use device_xname(), device_unit(), etc.
 1.45 01-Oct-2011  chs branches: 1.45.2; 1.45.12;
fix build errors with gcc 4.5.
 1.44 24-Apr-2011  rmind Rename ttymalloc() to tty_alloc(), and ttyfree() to tty_free() for
consistency. Remove some unnecessary malloc.h inclusions as well.
 1.43 23-Nov-2009  rmind branches: 1.43.4; 1.43.6;
Remove some unecessary includes sys/user.h header.
 1.42 14-Mar-2009  dsl ANSIfy another 1261 function definitions.
The only ones left in sys are beyond by sed script!
(or in sys/dist or sys/external)
Mostly they have function pointer parameters.
 1.41 14-Mar-2009  dsl Change about 4500 of the K&R function definitions to ANSI ones.
There are still about 1600 left, but they have ',' or /* ... */
in the actual variable definitions - which my awk script doesn't handle.
There are also many that need () -> (void).
(The script does handle misordered arguments.)
 1.40 17-Jun-2008  he branches: 1.40.4; 1.40.10;
Typo correction to restore buildability.
 1.39 11-Jun-2008  cegger - use device_lookup_private to get softc
- ansify
 1.38 28-Apr-2008  martin branches: 1.38.2; 1.38.4;
Remove clause 3 and 4 from TNF licenses
 1.37 08-Apr-2008  cegger branches: 1.37.2; 1.37.4;
use aprint_*_dev and device_xname
 1.36 19-Nov-2007  ad branches: 1.36.14;
- Factor out too many copies of the same bit of tty code.
- Fix another tty signalling/wakeup problem.
 1.35 19-Oct-2007  ad branches: 1.35.2;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.34 08-Oct-2007  ad branches: 1.34.2;
Use the softint API.
 1.33 14-Jul-2007  ad branches: 1.33.6; 1.33.8; 1.33.10;
Generic soft interrupts are mandatory.
 1.32 04-Mar-2007  christos branches: 1.32.2;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.31 01-Oct-2006  elad branches: 1.31.4;
More from Matt Fleming:

Adapt to KAUTH_DEVICE_TTY_PRIVSET and KAUTH_DEVICE_TTY_OPEN.
 1.30 01-Oct-2006  elad Adapt MD code to KAUTH_DEVICE_TTY_OPEN, batch #2 from Matt Fleming, thanks!

Also, add forgotten splx() calls in some places.
 1.29 21-Jul-2006  ad branches: 1.29.4; 1.29.6;
- Use the LWP cached credentials where sane.
- Minor cosmetic changes.
 1.28 14-May-2006  elad integrate kauth.
 1.27 07-Mar-2006  he branches: 1.27.2; 1.27.4;
Remove another instance of the SET/CLR/ISSET macro tripelet, now
found in <sys/types.h>.
 1.26 11-Dec-2005  christos branches: 1.26.4; 1.26.6; 1.26.8;
merge ktrace-lwp.
 1.25 06-Sep-2005  kleink Change the driver open function's conditional for overriding exclusive tty
use from checking the proc's uid to suser(9), and account for the use of
privileges. Noted by David Holland in PR kern/31126.

Also, dispose of a redundant (and unreachable) instance of that check.
 1.24 27-Feb-2005  perry branches: 1.24.4;
nuke trailing whitespace
 1.23 04-Feb-2005  perry de-__P
 1.22 23-Oct-2002  jdolecek branches: 1.22.6; 1.22.14; 1.22.16;
merge kqueue branch into -current

kqueue provides a stateful and efficient event notification framework
currently supported events include socket, file, directory, fifo,
pipe, tty and device changes, and monitoring of processes and signals

kqueue is supported by all writable filesystems in NetBSD tree
(with exception of Coda) and all device drivers supporting poll(2)

based on work done by Jonathan Lemon for FreeBSD
initial NetBSD port done by Luke Mewburn and Jason Thorpe
 1.21 06-Sep-2002  gehenna Merge the gehenna-devsw branch into the trunk.

This merge changes the device switch tables from static array to
dynamically generated by config(8).

- All device switches is defined as a constant structure in device drivers.

- The new grammer ``device-major'' is introduced to ``files''.

device-major <prefix> char <num> [block <num>] [<rules>]

- All device major numbers must be listed up in port dependent majors.<arch>
by using this grammer.

- Added the new naming convention.
The name of the device switch must be <prefix>_[bc]devsw for auto-generation
of device switch tables.

- The backward compatibility of loading block/character device
switch by LKM framework is broken. This is necessary to convert
from block/character device major to device name in runtime and vice versa.

- The restriction to assign device major by LKM is completely removed.
We don't need to reserve LKM entries for dynamic loading of device switch.

- In compile time, device major numbers list is packed into the kernel and
the LKM framework will refer it to assign device major number dynamically.
 1.20 17-Mar-2002  atatat branches: 1.20.4;
Convert ioctl code to use EPASSTHROUGH instead of -1 or ENOTTY for
indicating an unhandled "command". ERESTART is -1, which can lead to
confusion. ERESTART has been moved to -3 and EPASSTHROUGH has been
placed at -4. No ioctl code should now return -1 anywhere. The
ioctl() system call is now properly restartable.
 1.19 15-Nov-2001  lukem don't need <sys/types.h> when including <sys/param.h>
 1.18 13-Nov-2001  lukem add/cleanup RCSID
 1.17 12-Jul-2001  scw branches: 1.17.2;
Call clmpcc_init() when setting up the console to get the chip into
a known state.

For some reason, "Bug" on mvme68k can't be relied upon to leave it
in a good enough state for our console routines...
 1.16 02-May-2001  scw branches: 1.16.2;
Add `l_poll' to `struct linesw' and provide an xxxpoll() entry point
in each tty driver to indirect through it.

This allows tty line-disciplines to handle poll(2) system calls.
 1.15 14-Jan-2001  thorpej branches: 1.15.2;
Rename __GENERIC_SOFT_INTERRUPTS to __HAVE_GENERIC_SOFT_INTERRUPTS,
and place the definition in <machine/types.h>. This can now be used
as a flag to indicate whether or not <machine/intr.h> can be included
to get the generic soft interrupt API.
 1.14 01-Nov-2000  eeh Adapt to the new line discipline scheme.
 1.13 20-Jul-2000  scw Take advantage of generic soft interrupts, if available.
 1.12 15-Jul-2000  scw Fix a typo in the `device_lookup()' changes.
 1.11 06-Jul-2000  thorpej Use device_lookup().
 1.10 19-Mar-2000  scw branches: 1.10.4;
The soft-interrupt handler now returns void.
 1.9 28-Nov-1999  scw Don't bother spinning in the console 'putc' routine for the transmitter
to become idle; it actually doesn't matter as the chip takes care of
this for us. It would also spin endlessly in certain circumstances
during shutdown.

While I'm here, (finally) add code to allow sending BREAK characters.
 1.8 11-Nov-1999  scw Zero is a valid value for ch_tcor and ch_rcor, so be a bit more conservative
when deciding if the baud-rate should be changed. (Spotted by Bruce Martin)
Also fix the mask used when setting the Rx FIFO threshold to zero. I don't
yet understand how the Rx side worked with the code as it was. ;-}
 1.7 18-Sep-1999  scw branches: 1.7.2; 1.7.4; 1.7.8;
Minor optimisation.
 1.6 01-Aug-1999  scw Re-work the Tx side to avoid calling into the tty layer at
interrupt time. This was the cause of the 'mmu fault' panics
seen by several people, as the Tx interrupt is at a higher
priority that spltty().
 1.5 03-Apr-1999  scw Fix a problem where no Tx Empty interrupt ever happened if CTS
was deasserted and we wanted to change parameters to -crtscts
This effectively stalled the transmitter since with TS_BUSY set
we only change parameters during the Tx interrupt handler.
 1.4 21-Feb-1999  scw branches: 1.4.2;
Don't update the CORx registers unless they really have changed.
Also make console Tx handling wait until the Tx FIFO has drained and
the shift-register is empty before sending console characters.
 1.3 20-Feb-1999  scw That #define splserial() really didn't want to be there...
 1.2 20-Feb-1999  scw Delay serial port parameter changes until the Tx FIFO has emptied.
 1.1 13-Feb-1999  scw New MI front-end for the Cirrus Logic CD240[01] Multi-protocol
Communications Controller.

This is still a work in progress, but it is functional enough to
be usable.
 1.4.2.4 29-Nov-1999  he Pull up revisions 1.7 and 1.9 (requested by scw):
Fix a bug where the console 'putc' routine would spin endlessly
under certain circumstances during shutdown. In addition, the driver
is now able to generate BREAK.
 1.4.2.3 21-Nov-1999  he Pull up revision 1.8 (requested by scw):
Fix a problem with changing baud rate to > 9600, and a problem
with setting the Rx FIFO threshold register.
 1.4.2.2 10-Sep-1999  he Pull up revision 1.6:
Fix panics seen by some people during mvme167 installation. (scw)
 1.4.2.1 05-Apr-1999  scw branches: 1.4.2.1.2;
Pullup 1.5 from trunk.
 1.4.2.1.2.2 02-Aug-1999  thorpej Update from trunk.
 1.4.2.1.2.1 21-Jun-1999  thorpej Sync w/ -current.
 1.7.8.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.7.4.1 15-Nov-1999  fvdl Sync with -current
 1.7.2.3 18-Jan-2001  bouyer Sync with head (for UBC+NFS fixes, mostly).
 1.7.2.2 22-Nov-2000  bouyer Sync with HEAD.
 1.7.2.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.10.4.2 29-Jul-2000  scw Fix the previous pullup; I botched the patch.
Approved by: thorpej and jhawk
 1.10.4.1 22-Jul-2000  scw Pullup from trunk: 1.13
Approved by: thorpej

Make use of generic soft interrupts, when available.
 1.15.2.7 11-Nov-2002  nathanw Catch up to -current
 1.15.2.6 17-Sep-2002  nathanw Catch up to -current.
 1.15.2.5 01-Apr-2002  nathanw Catch up to -current.
(CVS: It's not just a program. It's an adventure!)
 1.15.2.4 08-Jan-2002  nathanw Catch up to -current.
 1.15.2.3 14-Nov-2001  nathanw Catch up to -current.
 1.15.2.2 24-Aug-2001  nathanw Catch up with -current.
 1.15.2.1 21-Jun-2001  nathanw Catch up to -current.
 1.16.2.4 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.16.2.3 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.16.2.2 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.16.2.1 03-Aug-2001  lukem update to -current
 1.17.2.2 13-Oct-2001  fvdl Revert the t_dev -> t_devvp change in struct tty. The way that tty
structs are currently used (especially by console ttys) aren't
ready for it, and this will require quite a few changes.
 1.17.2.1 10-Oct-2001  fvdl Convert all remaining devices.
 1.20.4.1 16-May-2002  gehenna Add the character device switch.
 1.22.16.2 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.22.16.1 12-Feb-2005  yamt sync with head.
 1.22.14.1 29-Apr-2005  kent sync with -current
 1.22.6.4 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.22.6.3 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.22.6.2 04-Feb-2005  skrll Sync with HEAD.
 1.22.6.1 26-Jan-2005  skrll Adapt to branch.
 1.24.4.5 07-Dec-2007  yamt sync with head
 1.24.4.4 27-Oct-2007  yamt sync with head.
 1.24.4.3 03-Sep-2007  yamt sync with head.
 1.24.4.2 30-Dec-2006  yamt sync with head.
 1.24.4.1 21-Jun-2006  yamt sync with head.
 1.26.8.3 11-Aug-2006  yamt sync with head
 1.26.8.2 24-May-2006  yamt sync with head.
 1.26.8.1 13-Mar-2006  yamt sync with head.
 1.26.6.2 01-Jun-2006  kardel Sync with head.
 1.26.6.1 22-Apr-2006  simonb Sync with head.
 1.26.4.1 09-Sep-2006  rpaulo sync with head
 1.27.4.1 24-May-2006  tron Merge 2006-05-24 NetBSD-current into the "peter-altq" branch.
 1.27.2.3 10-Mar-2006  elad generic_authorize() -> kauth_authorize_generic().
 1.27.2.2 08-Mar-2006  elad Adapt to kernel authorization KPI.
 1.27.2.1 07-Mar-2006  elad file clmpcc.c was added on branch elad-kernelauth on 2006-03-08 01:44:48 +0000
 1.29.6.1 22-Oct-2006  yamt sync with head
 1.29.4.1 18-Nov-2006  ad Sync with head.
 1.31.4.1 12-Mar-2007  rmind Sync with HEAD.
 1.32.2.2 23-Oct-2007  ad Sync with head.
 1.32.2.1 17-Jun-2007  ad - Increase the number of thread priorities from 128 to 256. How the space
is set up is to be revisited.
- Implement soft interrupts as kernel threads. A generic implementation
is provided, with hooks for fast-path MD code that can run the interrupt
threads over the top of other threads executing in the kernel.
- Split vnode::v_flag into three fields, depending on how the flag is
locked (by the interlock, by the vnode lock, by the file system).
- Miscellaneous locking fixes and improvements.
 1.33.10.1 14-Oct-2007  yamt sync with head.
 1.33.8.2 09-Jan-2008  matt sync with HEAD
 1.33.8.1 06-Nov-2007  matt sync with HEAD
 1.33.6.2 21-Nov-2007  joerg Sync with HEAD.
 1.33.6.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.34.2.2 21-Nov-2007  bouyer Sync with HEAD
 1.34.2.1 25-Oct-2007  bouyer Sync with HEAD.
 1.35.2.1 08-Dec-2007  mjf Sync with HEAD.
 1.36.14.2 29-Jun-2008  mjf Sync with HEAD.
 1.36.14.1 02-Jun-2008  mjf Sync with HEAD.
 1.37.4.3 11-Mar-2010  yamt sync with head
 1.37.4.2 04-May-2009  yamt sync with head.
 1.37.4.1 16-May-2008  yamt sync with head.
 1.37.2.2 17-Jun-2008  yamt sync with head.
 1.37.2.1 18-May-2008  yamt sync with head.
 1.38.4.1 18-Jun-2008  simonb Sync with head.
 1.38.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.40.10.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.40.4.1 28-Apr-2009  skrll Sync with HEAD.
 1.43.6.1 06-Jun-2011  jruoho Sync with HEAD.
 1.43.4.1 31-May-2011  rmind sync with head
 1.45.12.3 03-Dec-2017  jdolecek update from HEAD
 1.45.12.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.45.12.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.45.2.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.45.2.1 30-Oct-2012  yamt sync with head
 1.46.2.1 18-May-2014  rmind sync with head
 1.48.2.1 10-Aug-2014  tls Rebase.
 1.52.4.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.52.4.1 10-Jun-2019  christos Sync with HEAD
 1.52.2.1 06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.4 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.3 28-Nov-1999  scw branches: 1.3.126; 1.3.128; 1.3.130;
Don't bother spinning in the console 'putc' routine for the transmitter
to become idle; it actually doesn't matter as the chip takes care of
this for us. It would also spin endlessly in certain circumstances
during shutdown.

While I'm here, (finally) add code to allow sending BREAK characters.
 1.2 01-Aug-1999  scw branches: 1.2.2; 1.2.8;
Re-work the Tx side to avoid calling into the tty layer at
interrupt time. This was the cause of the 'mmu fault' panics
seen by several people, as the Tx interrupt is at a higher
priority that spltty().
 1.1 13-Feb-1999  scw branches: 1.1.2; 1.1.4;
New MI front-end for the Cirrus Logic CD240[01] Multi-protocol
Communications Controller.

This is still a work in progress, but it is functional enough to
be usable.
 1.1.4.1 02-Aug-1999  thorpej Update from trunk.
 1.1.2.2 29-Nov-1999  he Pull up revision 1.3 (requested by scw):
Fix a bug where the console 'putc' routine would spin endlessly
under certain circumstances during shutdown. In addition, the driver
is now able to generate BREAK.
 1.1.2.1 10-Sep-1999  he Pull up revision 1.2:
Fix panics seen by some people during mvme167 installation. (scw)
 1.2.8.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.2.2.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.3.130.1 16-May-2008  yamt sync with head.
 1.3.128.1 18-May-2008  yamt sync with head.
 1.3.126.1 02-Jun-2008  mjf Sync with HEAD.
 1.13 27-Oct-2012  chs split device_t/softc for all remaining drivers.
replace "struct device *" with "device_t".
use device_xname(), device_unit(), etc.
 1.12 28-Apr-2008  martin branches: 1.12.34; 1.12.44;
Remove clause 3 and 4 from TNF licenses
 1.11 14-Jul-2007  ad branches: 1.11.28; 1.11.30; 1.11.32;
Generic soft interrupts are mandatory.
 1.10 11-Dec-2005  christos branches: 1.10.30;
merge ktrace-lwp.
 1.9 04-Feb-2005  perry branches: 1.9.6;
de-__P
 1.8 02-Nov-2003  wiz branches: 1.8.8; 1.8.10;
Fix some typos. From Tom Cosgrove via jmc@openbsd.
 1.7 10-Jun-2001  scw branches: 1.7.22;
Forgot to commit this as part of the mvme68k evcnt(9) changes.
 1.6 14-Jan-2001  thorpej branches: 1.6.2;
Rename __GENERIC_SOFT_INTERRUPTS to __HAVE_GENERIC_SOFT_INTERRUPTS,
and place the definition in <machine/types.h>. This can now be used
as a flag to indicate whether or not <machine/intr.h> can be included
to get the generic soft interrupt API.
 1.5 20-Jul-2000  scw Take advantage of generic soft interrupts, if available.
 1.4 19-Mar-2000  scw branches: 1.4.4;
The soft-interrupt handler now returns void.
 1.3 01-Aug-1999  scw branches: 1.3.2;
Re-work the Tx side to avoid calling into the tty layer at
interrupt time. This was the cause of the 'mmu fault' panics
seen by several people, as the Tx interrupt is at a higher
priority that spltty().
 1.2 20-Feb-1999  scw branches: 1.2.2; 1.2.4;
Delay serial port parameter changes until the Tx FIFO has emptied.
 1.1 13-Feb-1999  scw New MI front-end for the Cirrus Logic CD240[01] Multi-protocol
Communications Controller.

This is still a work in progress, but it is functional enough to
be usable.
 1.2.4.1 02-Aug-1999  thorpej Update from trunk.
 1.2.2.1 10-Sep-1999  he Pull up revision 1.3:
Fix panics seen by some people during mvme167 installation. (scw)
 1.3.2.2 18-Jan-2001  bouyer Sync with head (for UBC+NFS fixes, mostly).
 1.3.2.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.4.4.1 22-Jul-2000  scw Pullup from trunk: 1.5
Approved by: thorpej

Make use of generic soft interrupts, when available.
 1.6.2.1 21-Jun-2001  nathanw Catch up to -current.
 1.7.22.4 04-Feb-2005  skrll Sync with HEAD.
 1.7.22.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.7.22.2 18-Sep-2004  skrll Sync with HEAD.
 1.7.22.1 03-Aug-2004  skrll Sync with HEAD
 1.8.10.1 12-Feb-2005  yamt sync with head.
 1.8.8.1 29-Apr-2005  kent sync with -current
 1.9.6.1 03-Sep-2007  yamt sync with head.
 1.10.30.1 15-Jul-2007  ad Sync with head.
 1.11.32.1 16-May-2008  yamt sync with head.
 1.11.30.1 18-May-2008  yamt sync with head.
 1.11.28.1 02-Jun-2008  mjf Sync with HEAD.
 1.12.44.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.12.34.1 30-Oct-2012  yamt sync with head
 1.389 24-Oct-2025  brad A driver for the NXP SC16IS7xx family of UART chips. This family is
mostly a 16C450 with features from the 16C550, 16C650 and 16C750 and
makes use of src/sys/dev/ic/com.c for much of the heavy lifting.

A BIG difference is that the chip family is attached via a I2C or SPI
bus and is in no way, shape or form, attached to the computer via a
computer bus.

Since spin locks are not allowed to be held while calling to the I2C
or SPI framework com.c grew a new hw feature flag where it could be
run at something other than a hard IP level and doesn't hold spin lock
(for very long). In particular, IPL_SOFTSERIAL. This method is
enabled via a hw feature flag and should not effect any other use of
com.c. Other changes with this new method of use include the use of
workqueues and such.

A further feature added to com.c was the abilty to take advantage of
the MCR prescaler that is present in the SC16IS7xx family and likely
present in the 16C650. This prescaler is tried if the baud rate
requested can not be met with the frequency oscillator that the chip is
built with.

The chip family does not use any particular frequency oscillator for
the baud rate generator. In order to deal with this the frequency can
be set via sysctl, a kernel option or with a FDT overlay if that is
supported.

Most of the features of the chip family are supported including the
gpio pins via gpiobus(4) that are present with some of the family
members.

The chip can attach via I2C or SPI and can make sure of FDT if that is
present in the system.

This chip family has been around for quite some time and there are a
number of breakout boards on Amazon. It is also reasonably priced and
you can roll your own board if you can perform simple SMD soldering as
very few additional components are required.
 1.388 12-Feb-2025  imil Set a skip_attach_delay property to "true" for com port in virtual machines
to avoid a delay(10000) at attach
 1.387 09-Feb-2025  skrll Trailing whitespace
 1.386 20-Jan-2025  martin Backout previous, this needs to be done differently
 1.385 20-Jan-2025  imil Avoid delay(10000) for virtual machines
 1.384 11-Apr-2023  riastradh branches: 1.384.6;
com(4): Note ttylock in comment, not tty_lock.
 1.383 11-Apr-2023  riastradh com(4): Note timecounter_lock in lock order comments.
 1.382 09-Dec-2022  knakahara Revert com.c:r1.381 because i386/qemu cannot boot. Pointed out by gson@n.o and martin@n.o.
 1.381 08-Dec-2022  knakahara Fix hang up writing /dev/console rarely in specific environments.

Some BMC seems to require these syncronous operations. If not,
it does not send transmit completion interrupts for some reason.
 1.380 03-Dec-2022  skrll KNF a comment
 1.379 26-Oct-2022  riastradh ddb/db_active.h: New home for extern db_active.

This can be included unconditionally, and db_active can then be
queried unconditionally; if DDB is not in the kernel, then db_active
is a constant zero. Reduces need for #include opt_ddb.h, #ifdef DDB.
 1.378 03-Oct-2022  riastradh com(4): Nix quirky `integrate' macro.

Just use `static inline' like everything else.
 1.377 03-Oct-2022  riastradh com(4): Omit needless spltty in comstart.

This is called either via tp->t_oproc, which is done with tty_lock
held (thus, at IPL_VM = IPL_TTY), or from comparam which is called at
IPL_TTY, either via comopen or tp->t_param.
 1.376 03-Oct-2022  riastradh com(4): Nix dead code.

This was introduced in rev. 1.292, whose commit message was...
`Delete dead code.' I guess December 6, 2009 was Opposite Day?
 1.375 03-Oct-2022  riastradh com(4): Comment on lock order.
 1.374 03-Oct-2022  riastradh com(4): Update confusing comment from decades ago to reflect now.

No functional change.
 1.373 12-Nov-2021  jmcneill com: Add support for 32-bit IO accesses.
 1.372 30-Oct-2021  jmcneill For the DW APB busy bit workaround, only attempt to re-apply LCR and DLB
settings for non-console devices. In the console case, simply clear the
busy bit and continue. Fixes an interrupt storm observed on Macchiatobin.
 1.371 21-Oct-2021  jmcneill Restore 16-byte FIFO for ns16550a, accidentally lost in r1.344.

Spotted by msaitoh. Thanks!
 1.370 20-Oct-2021  jmcneill - microtime -> microuptime
- avoid kpause with timeo=0
 1.369 14-Oct-2021  jmcneill - use microtime instead of getmicrotime, suggested by thorpej
- use ttclos for wchan even though we are sleeping in comopen now
 1.368 12-Oct-2021  kre Note that while sleeping (HUPCL), time passes.
Try to avoid the otherwise infinite loop.
 1.367 12-Oct-2021  kre Now Jason has made this build, avoid a 50+ year
sleep to implement HUPCL.
 1.366 11-Oct-2021  jmcneill com: speed up close with HUPCL set

Instead of incurring a 1s penalty on close of a com device with HUPCL set,
defer the sleep until the next open, and only sleep if necessary.

This has a side effect of making `ttyflags -a` with a default install not
pause for 1s for every non-console com device, which happens every boot
via /etc/rc.d/ttys.
 1.365 31-Jul-2021  tnn only read cpr register if we're going to use the value
 1.364 30-Jul-2021  tnn com(4): fix FIFO for DW_APB on Allwinner A20 (got broken by com.c 1.360)

Older DesignWare UARTs do not advertise their FIFO length so we must
provide it via device properties.
 1.363 25-Mar-2021  rin branches: 1.363.2;
Introduce COM_HW_BROKEN_ETXRDY bit in sc_hwflags; push TX queue if
possible in comintr() even if IIR_NOPEND is asserted.

Combined with sc_poll_ticks, this flag works around HW bug, by which
ETXRDY interrupts are (sometimes) lost.
 1.362 25-Mar-2021  rin Introduce sc_poll_ticks and obsolete COM_HW_POLL bit in sc_hwflags.
Polling is scheduled at every sc_poll_ticks ticks.

This is useful to work around H/W bug, by which interrupts are lost
*sometimes*; interrupt-based I/O mostly works and no need for polling
every counter ticks.
 1.361 30-Sep-2020  jmcneill branches: 1.361.2; 1.361.4;
Set sc_fifolen=1 for the no fifo case
 1.360 28-Sep-2020  jmcneill Auto-detect DW APB UART FIFO length and print the FIFO length when enabled
instead of just "working fifo".
 1.359 26-May-2020  martin Make the readahead-while-sending-output code conditional in
com_common_putc(), only erquest readahead before interrupts are enabled
and when called from comcnputc().
Fixes PR kern/55286.
 1.358 01-May-2020  simonb Get rid of needless __predict_true() and move a comment slightly.
 1.357 01-Feb-2020  skrll Use designated initializers
 1.356 10-Nov-2019  chs branches: 1.356.2;
in many device attach paths, allocate memory with M_WAITOK instead of M_NOWAIT
and remove code to handle failures that can no longer happen.
 1.355 11-Jan-2019  thorpej Simplify regmap initialization, and fix an regmap issue that
affected TI OMAP (LCR register would get clobbered due to
using the wrong offset for the MDR1 register) reported by Lwazi Dube
(who also found the root cause).
 1.354 11-Dec-2018  thorpej Add a convenience function, com_init_regs_stride(), that shifts the register
offsets and size by the specified amount. Use in front-ends as appropriate.
 1.353 09-Dec-2018  thorpej sparc64 doesn't have a scalar bus_space_handle_t, so cope with this.
Also, add a comment about why we're using the dummy / nil space handle
in the first place.
 1.352 08-Dec-2018  thorpej Remove the COM_REGMAP option -- just use it all the time. While here,
garbage-collect the COM_FUNCMAP and COM_AU1X00 options, as there are
not used anywhere.
 1.351 08-Dec-2018  thorpej Clean up initialization of com_regs structure, in preparation for
some additional changers.
 1.350 30-Nov-2018  jmcneill Add support for com(4) without an interrupt by setting the COM_HW_POLL flag
 1.349 28-Nov-2018  jmcneill Add support for a "force_console" property, where when set, reuses the console dev configuration
 1.348 27-May-2018  jmcneill branches: 1.348.2;
Rename COM_TYPE_SUNXI -> COM_TYPE_DW_APB
 1.347 08-Apr-2018  jmcneill Remove COM_AWIN option
 1.346 04-Dec-2017  bouyer branches: 1.346.2;
Put back SUNXI definitions in the COM_REGMAP case; com.c uses them
without #ifdef COM_AWIN.
To be safe, expand the register map to 42 entries.
 1.345 31-Oct-2017  martin As discussed on tech-kern: define a new tty internal state flag: TS_KERN_ONLY

Implement it in a few tty drivers. If this flag is set, the underlying
hardware is used by another driver and userland has no right to open
it. A few uses will appear soon in sys/dev/sun/sun{kbd,ms}.c.
 1.344 29-Oct-2017  jmcneill Make all of the COM_xxx type options runtime selectable. Kernel configs
with the existing options (COM_16650, COM_16750, COM_AWIN, COM_HAYESP, and
COM_PXA2X0) will select the correct type in com_attach_subr. New code
should specify the com type by passing COM_TYPE_xxx to comcnattach and/or
setting sc_type.
 1.343 28-Oct-2017  riastradh Kill some more extern struct cfdriver declarations.

Down with externs in .c!
 1.342 10-Aug-2017  nat Report AUXUART fifo size on rpi3 to 1 byte. This prevents bluetooth
errors using the h5 protocol.
 1.341 31-Jul-2017  jmcneill Broadcom AUX UART doesn't seem to set LSR RXRDY bit when data is available
in the RX FIFO.
 1.340 31-Jul-2017  jmcneill Add COM_TYPE_BCMAUXUART type for BCM2835 AUX UART.
 1.339 27-May-2016  bouyer branches: 1.339.10;
The UART in the allwiner SoCs is not full-compatible with the 16550, and
it's not a 16750 either. Like the 16750 it has the IIR_BUSY interrupt,
which is triggered when writing to LCR while the chip
can't accept it. But unlike the 16750, it has a specific register,
HALT, to allow writing to the LCR and divisor registers, and then
commit the changes.
Tested on an A20 SoC, changing the baud rate while keeping the
tty device open and incoming data.
 1.338 14-Dec-2015  jmcneill Fix TX FIFO on Tegra
 1.337 02-Nov-2015  christos PR/50395: Vicente Chaves de Melo: Loss of characters in serial port
communication between gdb and kgdb_stub: switch to line break interrupt
both when entering KGDB and also on shutdown so we can re-enter the debugger
with BREAK.
 1.336 04-May-2015  jmcneill For Tegra K1, set IE_RX_TIMEOUT (bit 4) in IER register. RX_TIMEOUT occurs
when data has been sitting in the Rx FIFO for more than 4 character times
without being read because there is not enough data to reach the trigger
level. With this change, enable FIFO usage for Tegra UARTs.
 1.335 04-May-2015  macallan fix pasto, use SET() and CLR()
thanks jmcneill@
 1.334 03-May-2015  jmcneill add COM_TYPE_TEGRA
 1.333 13-Apr-2015  riastradh Convert sys/dev to use <sys/rndsource.h>.
 1.332 07-Mar-2015  skrll KNF
 1.331 07-Mar-2015  skrll Fix build.

Hi mipsallan
 1.330 07-Mar-2015  macallan more Ingenic support:
- make sure we always set FIFO_UART_ON
- deal with the absence of DCD support
- enable the TX FIFO timeout interrupt
- set COM_HW_NOIEN
- pretend the FIFO is only 16 bytes deep ( supposed to be 64 but I get
overruns with that )
now this works as CI20 console
 1.329 22-Nov-2014  macallan branches: 1.329.2;
deal with quirk in Ingenic UARTs
( they have a bit in the FIFO control register which turns the entire
port off if not set )
 1.328 15-Nov-2014  christos centralize the dialout/call unit macros.
 1.327 10-Aug-2014  tls branches: 1.327.2;
Merge tls-earlyentropy branch into HEAD.
 1.326 25-Jul-2014  dholland Add d_discard to all struct cdevsw instances I could find.

All have been set to "nodiscard"; some should get a real implementation.
 1.325 08-Apr-2014  christos Clear dtr on transition from !0 to 0, and set it on the opposite.
This leaves dtr alone in the normal case.
 1.324 06-Apr-2014  christos PR/48720: John Kelly: com driver does not allow B0 to be set. The code to
handle B0 was commented out for no reason given at revision 1.99. POSIX
mandates to hangup on B0:
http://pubs.opengroup.org/onlinepubs/9699919799/functions/tcsetattr.html
 1.323 16-Mar-2014  dholland branches: 1.323.2;
Change (mostly mechanically) every cdevsw/bdevsw I can find to use
designated initializers.

I have not built every extant kernel so I have probably broken at
least one build; however I've also found and fixed some wrong
cdevsw/bdevsw entries so even if so I think we come out ahead.
 1.322 22-Dec-2013  matt Now that cngetc supports -1 as a return value from the cn_getc routine,
let cngetc loop until a character is available so it can call the critpoll
hooks.
 1.321 16-Dec-2013  skrll Use #if defined in previous.
 1.320 16-Dec-2013  htodd Fix build.
 1.319 15-Dec-2013  mbalmer lcr is only used when COM_16650 is defined; unbreak the build
 1.318 15-Dec-2013  skrll Only attempt to set 64byte fifo for 16750 when COM_16750 is defined.

Hi kiyohara.

PR/48359 NetBSD/cobalt 6.99.25 GENERIC kernel freeze at initializing com0
 1.317 03-Oct-2013  kiyohara Revirt 'Move the Marvell extension to com_mv.c' at Sun Sep 1 04:51:24 UTC 2013.
build test only.
 1.316 12-Sep-2013  martin Minor tweaks for newer gcc
 1.315 03-Sep-2013  jmcneill no EFR on tl16c750, use AFE bit on MCR reg instead for flow control
 1.314 01-Sep-2013  kiyohara Add support 16750 64Byte FIFO. But not test.
 1.313 01-Sep-2013  kiyohara Move the Marvell extension to com_mv.c.
 1.312 27-Jul-2013  kiyohara As for the console of ns16750, comintr() may be called before comopen().
If sc_lcr is not initialized at this time, console will be in an ugly state.
 1.311 27-Jul-2013  kiyohara Remove white-spaces, null-line and new-line.
 1.310 01-May-2013  mlelstv branches: 1.310.4;
For a polled console incoming characters are buffered on output.
The buffer is never passed to the regular tty routines and can
survive from early boot to halt where it is read by the "press
any continue to reboot" loops.
As a workaround, just kill the read-ahead buffer when switching
from and to polled mode.
 1.309 20-Apr-2013  rkujawa Add support for 16750 style UARTs. Activated by defining COM_16750.

Obtained from Marvell, Semihalf.
 1.308 24-Feb-2013  matt Initialize t_softc.
 1.307 10-Jan-2013  macallan don't try to become console if we get is_console=false as device property
 1.306 21-May-2012  skrll branches: 1.306.2;
Remove empty line.
 1.305 22-Apr-2012  christos don't include <sys/rnd.h> before we define cn_trap, because it might bring
in <sys/systm.h>
 1.304 02-Feb-2012  tls branches: 1.304.2;
Entropy-pool implementation move and cleanup.

1) Move core entropy-pool code and source/sink/sample management code
to sys/kern from sys/dev.

2) Remove use of NRND as test for presence of entropy-pool code throughout
source tree.

3) Remove use of RND_ENABLED in device drivers as microoptimization to
avoid expensive operations on disabled entropy sources; make the
rnd_add calls do this directly so all callers benefit.

4) Fix bug in recent rnd_add_data()/rnd_add_uint32() changes that might
have lead to slight entropy overestimation for some sources.

5) Add new source types for environmental sensors, power sensors, VM
system events, and skew between clocks, with a sample implementation
for each.

ok releng to go in before the branch due to the difficulty of later
pullup (widespread #ifdef removal and moved files). Tested with release
builds on amd64 and evbarm and live testing on amd64.
 1.303 27-Nov-2011  jakllsch branches: 1.303.2;
more whitespace and comment spelling fixes
 1.302 27-Nov-2011  jakllsch whitespace consistency adjustment
 1.301 28-May-2011  matt branches: 1.301.4;
Allow COM_TOLERANCE to be tweakable. If comspeed returns an invalid
rate, don't use that error value to set the speed.
 1.300 24-Apr-2011  rmind Rename ttymalloc() to tty_alloc(), and ttyfree() to tty_free() for
consistency. Remove some unnecessary malloc.h inclusions as well.
 1.299 22-Jan-2011  tsutsui Revert part of changes in rev 1.298:
- it breaks cobalt's serial console as mentioned in PR port-cobalt/44292
- MCR_PRESCALE doesn't affect unless EFR_EFCR is set in the EFR register
- even if MCR_PRESCALE is enabled we should define appropriate sc_type
variants and BRG values should be adjusted in comspeed() per sc_type
- sc_frequency should be adjusted in MD attachment if necessary
Tested on cobalt by several people, ok from jklos@
 1.298 20-Jul-2010  jklos branches: 1.298.2; 1.298.4;
Add support for 16650's prescaler from Frank Wille. Tested with
IOblix on Amiga.
 1.297 19-Apr-2010  dyoung Add default implementations for bus_space_is_equal(9),
bus_space_tag_create(9), and bus_space_tag_destroy(9). Use
bus_space_is_equal(9) throughout the kernel to compare
bus_space_tag_t's. Tested on i386 and on sparc64.
 1.296 22-Mar-2010  dyoung MI code should not compare bus_space_tag_t! Introduce tags_are_equal()
for "comparing" two bus_space_tag_t's. It is always true.

Everywhere that com(4) compares two tags, it compares to I/O base
addresses, too; comparing the base addresses should suffice.

TBD Clean this up more thoroughly.
 1.295 24-Feb-2010  dyoung branches: 1.295.2;
A pointer typedef entails trading too much flexibility to declare const
and non-const types, and the kernel uses both const and non-const
PMF qualifiers and device suspensors, so change the pmf_qual_t and
device_suspensor_t typedefs from "pointers to const" to non-pointer,
non-const types.
 1.294 09-Jan-2010  tsutsui branches: 1.294.2;
To print bus_addr_t value, cast it to u_long rather than size_t.
 1.293 08-Jan-2010  dyoung Expand PMF_FN_* macros.
 1.292 06-Dec-2009  dyoung Delete dead code.
 1.291 23-Nov-2009  rmind Remove some unecessary includes sys/user.h header.
 1.290 12-Nov-2009  dyoung Remove some dead code.
 1.289 12-Nov-2009  dyoung Move the code in com_activate() to com_detach(), where it always
belonged. Remove com_activate().

Consolidate information about the console on com(4) in a new struct
comcons_info.

Support detachment & re-attachment of a system console on com(4).
Re-attachment is somehow incomplete. Ideally, if some other device
could take over as console, it would, but we're not quite there,
yet.
 1.288 06-May-2009  cegger add KASSERT to identify when PR kern/40734 happens again.
It happened to me twice and to Emmanuel Dreyfus (reported on port-amd64 ML)
 1.287 03-Jan-2009  yamt branches: 1.287.2;
remove extra semicolons.
 1.286 25-Oct-2008  matt branches: 1.286.2; 1.286.10; 1.286.14;
Simplify NOERS case. Revert most changes back to 1.283.
 1.285 25-Oct-2008  tsutsui Fix a botch in an FIFO check for 16650.
 1.284 25-Oct-2008  he Replace a "type" with "sc->sc_type" to make this build again for cobalt
(and I'm sure a few others as well).
 1.283 24-Oct-2008  matt Add support for 16550 chips without an Enhanced Register Set.
 1.282 14-Jul-2008  matt Remove OMAP gunk in com_activate, it's not needed.

Spotted by Matthias Drochner.
 1.281 28-Apr-2008  matt branches: 1.281.2; 1.281.4; 1.281.6;
More forgotten changes from matt-armv6.
 1.280 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.279 21-Apr-2008  ad branches: 1.279.2;
Make ntp, pmc, reboot, sysarch, time syscalls MPSAFE.
 1.278 11-Apr-2008  tsutsui branches: 1.278.2;
If it's a high speed, trim the trigger level down to prevent overflows,
as comment says. The piece of code was removed in rev 1.230,
but it looks an error on reverting of rev 1.228.
 1.277 14-Mar-2008  cube Fix compilation under options RND_COM and COM_DEBUG.
Reported by Kurt Schreiner on current-users@.
 1.276 14-Mar-2008  cube Split device_t and softc for all com(4) devices (well, everything that
uses a com_softc backend). Use proper types and ansify where appropriate.
 1.275 07-Mar-2008  dyoung In com_detach(), don't destroy the lock twice.
 1.274 07-Mar-2008  dyoung Use device_t and its accessors.
 1.273 29-Feb-2008  dyoung Use pmf_device_register1() instead of shutdownhook_establish() to
register com_cleanup() as the shutdown hook.

Add a generic suspend routine. Suspend and resume com@isa.

Protect against dereferencing a NULL softc in comioctl().

Destroy both a mutex and a callout in com_detach().

Cosmetic: use aprint_*_dev(). Use PMF_FN_ARGS, PMF_FN_PROTO.
 1.272 28-Jan-2008  dyoung branches: 1.272.2; 1.272.6;
Do not allow the system console to detach, because that will lead
to a panic.
 1.271 24-Jan-2008  ad Destroy mutex when detaching. PR kern/37819.
 1.270 20-Jan-2008  joerg Now that __HAVE_TIMECOUNTER and __HAVE_GENERIC_TODR are invariants,
remove the conditionals and the code associated with the undef case.
 1.269 05-Jan-2008  ad Work around com hangs with pcmcia. PR kern/37462.
 1.268 14-Dec-2007  dyoung Add a resume handler for com@isa, using Jared McNeill's suggested
code from current-users. com@acpi, et cetera, remain to be done.
 1.267 05-Dec-2007  ad branches: 1.267.4;
Match the docs: MUTEX_DRIVER/SPIN are now only for porting code written
for Solaris.
 1.266 19-Nov-2007  ad branches: 1.266.2;
- Factor out too many copies of the same bit of tty code.
- Fix another tty signalling/wakeup problem.
 1.265 19-Oct-2007  ad branches: 1.265.2;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.264 17-Oct-2007  ad branches: 1.264.2;
Reapply rev 1.262 and add a comment about it.
 1.263 08-Oct-2007  ad Merge from vmlocking: use mutexes and the softint API.
 1.262 16-Aug-2007  martin branches: 1.262.2; 1.262.4;
Remove all locking from com_enable_debugport() - it is either called at
attach time, where we don't need further locking, or from comopen(),
where the caller does proper locking already.
 1.261 14-Jul-2007  ad branches: 1.261.2; 1.261.6;
Generic soft interrupts are mandatory.
 1.260 09-Jul-2007  ad Merge some of the less invasive changes from the vmlocking branch:

- kthread, callout, devsw API changes
- select()/poll() improvements
- miscellaneous MT safety improvements
 1.259 04-Mar-2007  christos branches: 1.259.2; 1.259.4;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.258 10-Jan-2007  cube branches: 1.258.2;
Make COM_HAYESP compile again. It assumes no register mapping is needed.
 1.257 10-Dec-2006  uwe aprint_naive("\n") to terminate "Found" line for quiet boot.
Use aprint_error to report that we are unable to establish power hook.
 1.256 16-Nov-2006  christos __unused removal on arguments; approved by core.
 1.255 12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.254 01-Oct-2006  elad More from Matt Fleming:

Adapt to KAUTH_DEVICE_TTY_PRIVSET and KAUTH_DEVICE_TTY_OPEN.
 1.253 01-Oct-2006  elad Adapt MD code to KAUTH_DEVICE_TTY_OPEN, batch #2 from Matt Fleming, thanks!

Also, add forgotten splx() calls in some places.
 1.252 24-Sep-2006  jmcneill Add "name" parameter to powerhook_establish, to aid debugging. No objections
on tech-kern@
 1.251 08-Aug-2006  mrg branches: 1.251.2; 1.251.4;
fix a GCC uninitialised variable warning only seen at -O3.
 1.250 22-Jul-2006  elad branches: 1.250.2;
oops, no 'p' here. from xtraeme@.
 1.249 22-Jul-2006  elad don't call kauth_authorize_generic() when holding a lock, from yamt@.
 1.248 21-Jul-2006  ad - Use the LWP cached credentials where sane.
- Minor cosmetic changes.
 1.247 13-Jul-2006  gdamore Add an option COM_REGMAP to allow com(4) to use an array of register indices.
This allows us to convert aucom to just another com attachment, and cleanup
some code in the com_arbus.c.

Additionally, we use a common com_cleanup routine rather than having a
zillion copies of it in the attachment points.

This has been tested on a number architectures, and it has been shown to get
close to comparable performance when COM_REGMAP is defined, and comparable
when it is not defined.

Approved by core@. Fixes PR port-evbmips/32362.
 1.246 25-Jun-2006  jmcneill Make sure that a powerhook was successfully established before trying to
disestablish it on detach.
 1.245 25-Jun-2006  perry Add a power hook for the com device.
 1.244 07-Jun-2006  kardel branches: 1.244.2;
merge FreeBSD timecounters from branch simonb-timecounters
- struct timeval time is gone
time.tv_sec -> time_second
- struct timeval mono_time is gone
mono_time.tv_sec -> time_uptime
- access to time via
{get,}{micro,nano,bin}time()
get* versions are fast but less precise
- support NTP nanokernel implementation (NTP API 4)
- further reading:
Timecounter Paper: http://phk.freebsd.dk/pubs/timecounter.pdf
NTP Nanokernel: http://www.eecis.udel.edu/~mills/ntp/html/kern.html
 1.243 14-May-2006  elad branches: 1.243.2;
integrate kauth.
 1.242 28-Mar-2006  thorpej Use device_unit().
 1.241 20-Feb-2006  thorpej branches: 1.241.2; 1.241.4; 1.241.6;
Use device_is_active() rather than testing dv_flags for DVF_ACTIVE
directly.
 1.240 08-Jan-2006  dsl branches: 1.240.2; 1.240.4;
Save console baud rate as both the input and output rates.
This is what I thought I'd done in rev 1.237
 1.239 27-Dec-2005  chs branches: 1.239.2;
remove the COM_MPLOCK option. always include the spinlock in the softc
and always call the simple_* locking functions. the locking functions
are compiled out if they are not needed anyway, so a separate option
for this doesn't gain anything.

this also fixes the serial console on my alpha ES40 (which doesn't make much
sense since the com driver should still be under the big lock on alpha,
but whatever).
 1.238 11-Dec-2005  christos merge ktrace-lwp.
 1.237 06-Nov-2005  dsl Explicitly default the input baud rate (c_ispeed) to the output baud rate (c_ospeed)
instead of setting it to zero. Otherwise nothing ever sets it unless some code
explicitly changes the baud rate. For a serial console (in particular) we want
to use the baud rate set by the bios (or whatever) and used by theboot code.
This is the way it was before a 'new version of com driver' was added in 1997 (rev 1.99)
 1.236 06-Sep-2005  kleink Change the driver open function's conditional for overriding exclusive tty
use from checking the proc's uid to suser(9), and account for the use of
privileges. Noted by David Holland in PR kern/31126.
 1.235 04-Sep-2005  kleink Make COM_DEBUG compile again in the wake of -Wwrite-strings;
from Nicolas Joly in PR kern/31141.
 1.234 21-Jun-2005  ws branches: 1.234.2;
PR-30566: Poll must not return <sys/errno.h> values.
Start with those places I can easily test.
 1.233 12-Jun-2005  tls Revert the part of revision 1.228 that made HW_NO_TXPRELOAD the default:
it appears to break output on the Soekris net4501, which is a rather
popular platform.

This should fix PR kern/29612 -- if not, I will probably revert it again.
 1.232 27-Feb-2005  perry branches: 1.232.2;
nuke trailing whitespace
 1.231 09-Aug-2004  mycroft branches: 1.231.4; 1.231.6;
Do an extra read of the IIR during initialization, just to ack any pending
interrupt.
 1.230 04-Jul-2004  mycroft Back off the trigger level a little. Testing shows that it's not terribly
reliable at 14.
 1.229 04-Jul-2004  mycroft Minor simplification.
 1.228 04-Jul-2004  mycroft Incorporate 4 changes that have been suggested:
* At high speed, set the FIFO trigger to the maximum value to reduce interrupt
load. PR 15448.
* Handler the case of IIR=RXRDY and LSR=!LSR_RCV_MASK differently, to avoid a
hang with some chips. PR 21184, and possibly PR 10974 and PR 8248.
* Remove the extra wait at the end of com_common_putc(), after writing a
character out, so that we get another TXRDY interrupt. This prevents stalls
when normal output and kernel output are mixed. PR 4263.
* Do not "preload" the TX FIFO; wait for a TXRDY interrupt to come in after
enabling it.
 1.227 01-May-2004  thorpej Rename the COM16650 option to COM_16650, for consistency with other
com variant options.
 1.226 01-May-2004  thorpej Wait just a little longer for console output to finish when we're
attaching the console uart.
 1.225 05-Apr-2004  enami Fix race condition introduced in rev 1.189; after the change, if there is
THRE interrupt occurs between the LSR read and IIR read, we won't see the
LSR_TXRDY bit when testing it in the variable `lsr' and we don't interrupted
again (as the corresponding bit in the IIR is cleared by reading, except
for some broken device).

Tested by Matthias Scheler and me, reviewed by Allen Briggs.
Closes PR#25010.
 1.224 23-Jan-2004  simonb branches: 1.224.2;
Fix NTP PPSAPI support (enabled with "options PPS_SYNC"):

From PR kern/13702 from Charles Carvalho. Tested on alpha and
i386 with a Laipac TF10 PPS-capable GPS. The com.c change was
copied wholesale from Charles' z8530tty.c patch.
 1.223 12-Nov-2003  simonb Use just "type" and not "sc->sc_type" in cominit().

Pointed out by Shoichi Miyake in private mail.
 1.222 08-Nov-2003  simonb Make comsoft_callout static; it's not referenced outside this file.
 1.221 06-Nov-2003  simonb Be consistent with other COM_TYPE_PXA2x0 checks.
 1.220 06-Nov-2003  simonb White space nit.
 1.219 03-Sep-2003  simonb Add missing semicolon.
 1.218 01-Sep-2003  christos fix debugging printfs
 1.217 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22364, verified by myself.
 1.216 29-Jun-2003  fvdl branches: 1.216.2;
Back out the lwp/ktrace changes. They contained a lot of colateral damage,
and need to be examined and discussed more.
 1.215 29-Jun-2003  simonb Restore parentheses around return value that were removed with the
previous commit.
 1.214 28-Jun-2003  darrenr Pass lwp pointers throughtout the kernel, as required, so that the lwpid can
be inserted into ktrace records. The general change has been to replace
"struct proc *" with "struct lwp *" in various function prototypes, pass
the lwp through and use l_proc to get the process pointer when needed.

Bump the kernel rev up to 1.6V
 1.213 23-Jun-2003  martin Make sure to include opt_foo.h if a defflag option FOO is used.
 1.212 18-Jun-2003  bsh in cominit(), turn on UUE bit in IER register if it is PXA2x0's
built-in UART.
 1.211 15-Jun-2003  simonb Wrap some long lines.
 1.210 14-Jun-2003  thorpej Also pass a type argument to comcnattach() and com_kgdb_attach().
comspeed() (and thus cominit()) may need this information.
 1.209 14-Jun-2003  thorpej Introduce a new "type" field in the softc which is used to indicate
the general UART type. Currently, we have "normal", "hayesp" and
"pxa2x0" types. Replace the corresponding hw flags with the new type
values.
 1.208 05-Jun-2003  scw Add support, via a kernel config file option, for the 16550-compatible
com ports found on Intel PXA2x0 processors.

Re-arrange the code which detects the FIFO configuration to defer
printing until _after_ com_fifo is cleared. Some supposedly compatible
chips clear the Tx/Rx FIFOs when this happens, resulting in previous
output being lost.
 1.207 18-May-2003  fvdl Inialize sc_tty->t_dev early for serial console, so that cn_check_magic
will match in the case of a break before the console was opened for the
first time. Makes BREAKing into DDB work (again) as soon as interrupts
are enabled.
 1.206 28-Apr-2003  briggs Allow the console to be used for kgdb if both DDB and KGDB are defined.
 1.205 21-Apr-2003  gson Ignore input when the port is not open. This change is functionally
identical to the patch in kern/6502 (which is hereby fixed), but
modelled after the corresponding fix to the 8530 driver in
z8530tty.c revision 1.60 to maintain consistency with that driver.
 1.204 14-Mar-2003  simonb Fix some white-space niggles.
 1.203 06-Mar-2003  matt Add cn_halt and cn_flush entries to consdevs. (needed for dma-only console
devices).
 1.202 31-Jan-2003  thorpej Use aprint_*().
 1.201 07-Nov-2002  thorpej Fix signed/unsigned comparison warnings.
 1.200 23-Oct-2002  jdolecek merge kqueue branch into -current

kqueue provides a stateful and efficient event notification framework
currently supported events include socket, file, directory, fifo,
pipe, tty and device changes, and monitoring of processes and signals

kqueue is supported by all writable filesystems in NetBSD tree
(with exception of Coda) and all device drivers supporting poll(2)

based on work done by Jonathan Lemon for FreeBSD
initial NetBSD port done by Luke Mewburn and Jason Thorpe
 1.199 06-Sep-2002  gehenna Merge the gehenna-devsw branch into the trunk.

This merge changes the device switch tables from static array to
dynamically generated by config(8).

- All device switches is defined as a constant structure in device drivers.

- The new grammer ``device-major'' is introduced to ``files''.

device-major <prefix> char <num> [block <num>] [<rules>]

- All device major numbers must be listed up in port dependent majors.<arch>
by using this grammer.

- Added the new naming convention.
The name of the device switch must be <prefix>_[bc]devsw for auto-generation
of device switch tables.

- The backward compatibility of loading block/character device
switch by LKM framework is broken. This is necessary to convert
from block/character device major to device name in runtime and vice versa.

- The restriction to assign device major by LKM is completely removed.
We don't need to reserve LKM entries for dynamic loading of device switch.

- In compile time, device major numbers list is packed into the kernel and
the LKM framework will refer it to assign device major number dynamically.
 1.198 29-Jul-2002  simonb Don't name parameters in a function declaration.
 1.197 29-Jul-2002  simonb ANSIfy, KNF.
 1.196 13-Apr-2002  christos branches: 1.196.2; 1.196.4;
PR/16058: Tero Kivinen: Don't free rbuf or detach tty if rbuf allocation
failed during attach phase.
 1.195 12-Apr-2002  thorpej * Add a new hwflag, COM_HW_NO_TXPRELOAD, which tells comstart() to
not pre-load the chip's Tx buffer, but instead waits for the Tx Ready
interrupt to transmit the first chunk of data.
* On the IOP310, set COM_HW_NO_TXPRELOAD, rather than COM_HW_TXFIFO_DISABLE.

This solves the "UART hangs" problem on the Npwr in a nicer way (i.e. we
get to use the FIFO, whee). The COM_HW_NO_TXPRELOAD happens to match the
Linux 16550 driver's Tx algorithm, and the "UART hang" was never observed
on the Npwr running Linux.

Eventually, we might want to eliminate the COM_HW_NO_TXPRELOAD, and simply
always use its algorithm. But it should be tested on more 16x50 variants
before we do that.

Kudos to Valeriy Ushakov <uwe@netbsd.org> for pointing out this solution
(which also happens to fix the stray UART interrupt issue on the Krups
Javastation), and to Allen Briggs <briggs@netbsd.org> for experimenting
with various methods of fixing this.
 1.194 17-Mar-2002  atatat Convert ioctl code to use EPASSTHROUGH instead of -1 or ENOTTY for
indicating an unhandled "command". ERESTART is -1, which can lead to
confusion. ERESTART has been moved to -3 and EPASSTHROUGH has been
placed at -4. No ioctl code should now return -1 anywhere. The
ioctl() system call is now properly restartable.
 1.193 20-Nov-2001  lukem - pull in opt_kgdb.h where necessary
- replace opt_kgdb_machdep.h with opt_kgdb.h
- defparam opt_kgdb.h:
KGDB_DEV KGDB_DEVNAME KGDB_DEVADDR KGDB_DEVRATE KGDB_DEVMODE
- move from opt_ddbparam.h to opt_ddb.h:
DDB_FROMCONSOLE DDB_ONPANIC DDB_HISTORY_SIZE DDB_BREAK_CHAR SYMTAB_SPACE
- replace KGDBDEV with KGDB_DEV
- replace KGDBADDR with KGDB_DEVADDR
- replace KGDBMODE with KGDB_DEVMODE
- replace KGDBRATE with KGDB_DEVRATE
- use `9600' instead of `0x2580' for 9600 baud rate
- use correct quotes for options KGDB_DEVNAME="\"com\""
- use correct quotes for options KGDB_DEV="17*256+0"
- remove unnecessary dependancy on Makefile for kgdb_stub.o
- minor whitespace cleanup
 1.192 15-Nov-2001  lukem don't need <sys/types.h> when including <sys/param.h>
 1.191 13-Nov-2001  lukem add/cleanup RCSID
 1.190 05-Nov-2001  fvdl Initialize the cn_magic goo for kgdb (bah, that should really not
be necessary).
 1.189 17-Sep-2001  briggs branches: 1.189.2;
Patch to handle odd behavior from exar ST16C1550 UART. It does not set
IIR_NOPEND if the TXRDY condition is true. Apparently, other chips do
not take TXRDY into account in the IIR_NOPEND case.

Also remove useless assignment (iir = IIR_NOPEND;) in one case.

No response from patch posted on tech-kern 29Aug2001.
 1.188 27-Aug-2001  enami branches: 1.188.2;
For hayes esp card, set prescaler if specified rate is grater than 115200.
 1.187 22-Aug-2001  simonb Cosmetic cleanups:
- cominit() is local to com.c, remove prototype from comvar.h.
- Don't prototype comstop(), cdev_decl(com) does this.
- Don't use a block device switch table declaration(!).
- No need to include "com.h".
 1.186 20-Jun-2001  uwe branches: 1.186.2;
Convert to use cnmagic(9). Unifdef DDB and DDB_BREAK_CHAR.
While I'm here, s/ungetc/readahead/ in com_common_* because that's
what it _really_ is, "ungetc" is a very confusing name.
 1.185 30-May-2001  lukem add missing #include "opt_kgdb.h"
 1.184 02-May-2001  scw Add `l_poll' to `struct linesw' and provide an xxxpoll() entry point
in each tty driver to indirect through it.

This allows tty line-disciplines to handle poll(2) system calls.
 1.183 14-Jan-2001  thorpej branches: 1.183.2;
Rename __GENERIC_SOFT_INTERRUPTS to __HAVE_GENERIC_SOFT_INTERRUPTS,
and place the definition in <machine/types.h>. This can now be used
as a flag to indicate whether or not <machine/intr.h> can be included
to get the generic soft interrupt API.
 1.182 18-Nov-2000  sommerfeld Initialize ring buffer pointers when the ring buffer is allocated.
(comsoft() can be invoked before comopen() on serial consoles; a character
received before the console is opened "for real" can result in a fatal trap
unless the ring buffer pointers are initialized early)
 1.181 01-Nov-2000  eeh Adapt to the new line discipline scheme.
 1.180 26-Sep-2000  sommerfeld Add missing '&& defined(COM_MPLOCK)'
 1.179 23-Sep-2000  sommerfeld Add `COM_MPLOCK' option to use a device-instance-specific spinlocks
when running at splserial(). This is a temporary measure (until
there's a MP-safe interrupt handling structure); until then, it should
be used when MULTIPROCESSOR and IPL_SERIAL > IPL_SCHED.
 1.178 22-Sep-2000  eeh paddr_t -> bus_addr_t.
 1.177 21-Sep-2000  eeh Support for SPARC machines with `su' devices.
 1.176 17-Sep-2000  toshii Change tiocm_to_{com,zs}'s second argument to u_long to match with
the type in their caller.
 1.175 18-Aug-2000  sommerfeld Avoid calling tsleep when running above splhigh()
 1.174 03-Aug-2000  jeffs Add options DDB_BREAK_CHAR. This overrides break on the serial console
break character with the supplied one. This is useful for cases where
break is hard to generate, or you are connected to a PC that "sends"
breaks when power cycled. For this mode in com, interpret break char
in the polling section, which allows entry into the debugger before
the tty is opened. Only supported in the com driver currently.
 1.173 06-Jul-2000  thorpej Use device_lookup().
 1.172 03-May-2000  thorpej Remove unnecessary junk on #undef line that some C preprocessors
get cranky about.
 1.171 30-Mar-2000  simonb Delete redundant decl of com_attach_subr(), it's in comvar.h.
 1.170 23-Mar-2000  thorpej New callout mechanism with two major improvements over the old
timeout()/untimeout() API:
- Clients supply callout handle storage, thus eliminating problems of
resource allocation.
- Insertion and removal of callouts is constant time, important as
this facility is used quite a lot in the kernel.

The old timeout()/untimeout() API has been removed from the kernel.
 1.169 06-Mar-2000  thorpej - Implement cnbell() -- ring the console bell. The cn_bell entrypoint
is optional.
- Add cn_bell to statically allocated consdevs as appropriate.
 1.168 07-Feb-2000  jonathan Fix thinko in previous revision: it wouldn't catch deassert.
Revert the code inside the new test to the previous-but-one revision.
 1.167 06-Feb-2000  jonathan Check for DCD status change interrupts which signal PPS events, even
if the line discipline is ignoring carrier (e.g., via comparam()'s
setting of sc->sc_msr_mask). Move PPS timestamp outside the normal
status-change processing, and ignore sc_msr_mask when testing
for PPS events.
 1.166 23-Jan-2000  soda kluge to make this work with NEC M403 (arc/magnum).
 1.165 21-Dec-1999  drochner set carrier early if used as console or kgdb line, fixes PR kern/6547
by Andreas Gustafsson, gson@iengines.com
 1.164 22-Nov-1999  sommerfeld defopt COM_DEBUG, COM_HAYESP, and COM16650
 1.163 04-Nov-1999  jonathan Update user-level PPS-API to match -05 draft.
Change PPS_<xxx> ioctls to PPS_IOC_<xxx>.
 1.162 15-Oct-1999  jonathan branches: 1.162.2; 1.162.4;
Fix nanosecond/microsecond botch in PPSAPI:
remove bogus TIMESPEC_TO_TIMEVAL() after applying any {assert,clear} offset.
 1.161 19-Apr-1999  ross branches: 1.161.2;
Get rid of delay() in com_common_putc() because the Shark delay() is borked
and can't be called until after the timers are setup. (It should not use
a timer, or it should have a fallback algorithm.)
 1.160 18-Apr-1999  thorpej Revert revision 1.159. The correct answer was not to re-break the
serial console support, but rather to fix the Shark delay().
 1.159 31-Mar-1999  mrg branches: 1.159.2;
back date this file to version 1.155 which works on the shark.
 1.158 29-Mar-1999  mycroft Nuke bogus extra variable, too.
 1.157 29-Mar-1999  mycroft Fix bogons in previous change:
* The fact that IIR_NOPEND was not set on entry does *not* mean that no
transmission was in progress. Besides, we don't want to throw away receive
interrupts either.
* In the !clearirq case, we didn't splx().
 1.156 29-Mar-1999  ross Mods to com_common_putc(). When doing kprintf() or kgdb output:
1. don't clear the irq unless it was clear before transmitting
2. also do various bus_space_barrier() ops
Stops console from freezing when kprintf interrupts tty driver output.
 1.155 28-Feb-1999  explorer Update to slightly altered rnd_attach_source() api
 1.154 12-Feb-1999  drochner make the probe stricter to catch cases where the chipset doesn't pull
the data lines to "high" for not-existant devices
 1.153 03-Feb-1999  mycroft Separate the tiocm code into functions, like the z8530 code, and fix the same
DTR bug.
 1.152 03-Feb-1999  mycroft Fix an inconsistency: PPS was turned off on first open, but the mode may have
still claimed it was enabled.
 1.151 03-Feb-1999  mycroft Slight redux in PPS code.
 1.150 26-Jan-1999  drochner Debugger() -> console_debugger() to honour the ddb_fromconsole sysctl
 1.149 18-Nov-1998  thorpej Add support for detaching "com" instances.
 1.148 16-Sep-1998  is Garbage collect unused 3rd parameter to comprobe1().
 1.147 09-Sep-1998  thorpej Don't use M_WAITOK to allocate the ring buffer; we could be in interrupt
context. Reported by Lennart Augustsson.
 1.146 15-Aug-1998  mycroft Assign my copyrights to TNF.
 1.145 04-Jul-1998  jonathan defopt DDB.
 1.144 10-Jun-1998  jonathan PPS support from April, reworked and extended to match the PPS-API
Internet Draft (draft-mogul-pps-api-02.txt).
 1.143 22-Mar-1998  mycroft Move the code to wait for carrier on a tty into a common function, since it
depends only on device-independent state bits.
Implement SunOS-style `dialout' devices.
 1.142 21-Mar-1998  mycroft Remove a bogus initializer.
 1.141 21-Mar-1998  mycroft Replace TS_WOPEN with t_wopen, per mail on tech-kern.
 1.140 25-Feb-1998  ross Add dummy }} after comsoft() to keep ctags(1) bashing on.
 1.139 22-Feb-1998  enami Disable the device if we fail to open and nobody else has the device open.
(Thanks Charles and Marc for your advices).
 1.138 22-Feb-1998  mycroft Fix bonehead error in previous change.
 1.137 19-Feb-1998  mycroft Remove stray label from last change.
 1.136 19-Feb-1998  mycroft Arrange to call com_break() and com_modem() at splserial().
It's simpler this way. Really.
 1.135 09-Feb-1998  thorpej Fix serial console support, which was broken by the previous revision:
- In the console getc routine, block until a character becomes ready
(no, really, we mean it). This routine should _never_ time out.
- In the console putc routine, if the UART has trouble, do NOT proceed
to print a diagnostic message, which would recursively invoke the
console putc routine ad nauseum.
 1.134 06-Feb-1998  enami Restore system priority level before return from comopen().
 1.133 02-Feb-1998  cgd change #ifdefs keying on "alpha" to key on "__NO_SOFT_SERIAL_INTERRUPT"
instead, and define that on NetBSD/alpha and NetBSD/arm32.
 1.132 02-Feb-1998  cgd Implement a flag to indicate that the driver attached correctly.
This is useful in the case where an attachment's probe routine
verifies that there is indeed hardware present but something goes
"wrong" in the attach causing the device to be unusable. (Without
keeping track of this, in that case incorrect ports could be
accessed or uninitted pointers could be deferenced on open or at
other times.)
 1.131 01-Feb-1998  marc split com_attach_subr into attach stuff and per-open initialization stuff
add timeouts to all splserial() while loops so bugs elsewhere don't cause
the com driver to wedge the machine
add power management support
 1.130 12-Jan-1998  thorpej Adjust for config changes.
 1.129 16-Dec-1997  mycroft Don't do anything in comparam() if the line speed and flags are the same.
 1.128 03-Nov-1997  mycroft Slight optimization in soft input routine.
 1.127 03-Nov-1997  mycroft Mostly cosmetic and performance changes:
* Make the ring buffer size and water marks patchable, and allocate the buffer
separately.
* Do the ttymalloc() at attach time.
* Reorganize the receive buffer so the status and data pair are next to each
other. This is slightly faster.
* Make sure we actually do turn off interrupts in comclose() if we have DDB
configured and it's not the console. (D'oh!!!!)
* When we exhaust the current transmit run, turn off transmit interrupts in
comintr(), so we're fairly sure we don't get another one.
* Nuke the silly lsrmap[] idea; it's slower in the normal case.
* Cache the l_rint pointer in the soft interrupt routine.
 1.126 02-Nov-1997  mycroft Slight code rearrangement.
 1.125 02-Nov-1997  mycroft Slight code rearrangement.
 1.124 02-Nov-1997  mycroft Rearrange *param() slightly to eliminate a spl.
Also fix another comment regarding DTR.
 1.123 02-Nov-1997  mycroft Add another splserial()/splzs().
 1.122 02-Nov-1997  mycroft Minimize some spl regions slightly.
 1.121 01-Nov-1997  mycroft Correct a comment regarding our behaviour with DTR.
 1.120 01-Nov-1997  mycroft Add additional splserial()s in comopen() and comclose(). These are not
necessary on the i386 port, but may be on others.
 1.119 29-Oct-1997  drochner Print probe result after the LCR is restored. Otherwise, bad
things happen if we are the console.
Restore to the prevoius value (not to hardwired 8N1) because this
could be set by the serial console initialization.
Closed PR kern/4373 (Dave Huang)
 1.118 21-Oct-1997  fvdl branches: 1.118.2;
Make 16650 probe optional on COM16650 define. It breaks on some
multiport Startech chips.
 1.117 19-Oct-1997  mycroft Initialize the IER to 0 in com_attach_subr().
 1.116 19-Oct-1997  fvdl Add 16650 hardware flowcontrol support. Basically PR 3844 from
Dave Huang <khym@bga.com>, with added check for broken early versions
of the 16650, taken from the Linux driver.

This should be extended to use, for example, higher trigger levels for
the bigger 16650 FIFO, and its capability for using a smaller divisor
and thus higher speeds. But this patch is very useful for 16650 users
already.
 1.115 19-Oct-1997  explorer Add hooks for entropy collection. Right now, you must place
options RND_COM
in your kernel config file (along with the
pseudo-device rnd
line) to enable this. If results are positive, I will make this enabled
by default.
 1.114 18-Oct-1997  is Use long long in bitrate tolerance computation, else we'll overflow for
higher than standard-pc chip clocks.
 1.113 16-Oct-1997  thorpej branches: 1.113.2;
"com" driver files copied by repository copy magick to sys/dev/ic, and
adjusted for their new home.
 1.112 03-Oct-1997  mikel fix missing com_kgdb_attached() argdecl, from Michael C. Richardson in PR 4196
 1.111 30-Sep-1997  christos Add TIOCM{BI{C,S},{S,G}ET} from revision 1.98. As Charles says these
interfaces are slightly broken and should be obsoleted, but some programs
are using them and also they are useful for debugging.
 1.110 19-Sep-1997  enami Cosmetic Changes; make coding style closer to other part of this file.
(This version is identical with version 1.109 except whitespace changes.)
 1.109 16-Sep-1997  is Support for the upcoming NetBSD/Amiga Hypercom driver family:
* support chip clocks != COM_FREQ, by introducing sc_frequency (for the
mainline code) and adding a frequency parameter right after the rate
parameter to comcnattach() and com_kgdb_attach().
- Make com_isa and com_multi initialize sc_frequency to COM_FREQ.
- Make i386/machdep.c and alpha/dec_xxx.c call com*attach() with the freq.
parameter.
* supio_attach_args get two more fields: a sc_ipl and a sc_arg, both ints.
- com_supio uses the first for interupt establishment (all childs will, as
soon as they exist) and the 2nd for sc_frequency.
- drsupio passes sc_ipl alway as 5, and for the "com"s, sc_arg as 16*115200
- hyper will pass sc_ipl as 6, and sc_arg as 16 * 460800
 1.108 27-Aug-1997  is Make this work with __GENERIC_SOFT_INTERRUPTS.
 1.107 24-Aug-1997  drochner Check for KGDB port == console port in a consistent way.
 1.106 23-Aug-1997  drochner clean up the serial console / KGDB attachment:
-put all early console / KGDB initialization into 1 exported function
(com_*_attach()) each, dont use global variables anymore
-use the passed tcflag_t for port settings instead of hardwiring 8N1
-at autoconfiguration attach time, decide if the attaching device is
already console / KGDB by comparing bus tag and base addr (cgd's wish)
-export a function "com_is_console()" for use by driver frontends for
this comparision
-delay setting of cn_tab->cn_dev until autoconfiguration attach
to get the minor number right
-delete unused comcnprobe() and comcninit()
 1.105 16-Aug-1997  drochner Bring back the "comconsattached" flag. It is necessary for starred
com devices (on non "__BROKEN_INDIRECT_CONFIG" ISA).
 1.104 14-Aug-1997  drochner -Export variables needed for system console initialization.
-Enable line break interrupt for DDB on a serial console.
-Share initialization code between DDB and KGDB.
 1.103 12-Aug-1997  drochner KGDB improvements:
-Separate KGDB port initialization and softc related stuff to allow
KGDB to be attached in early system startup, before autoconfiguration.
-Export the variables needed by md code to hand-craft bus tag/handle.
-Fix initialization to enable interrupt by line break.
-Call DDB/KGDB at line break (move DDB call from the softirq handler
to the hard handler because it should work without a tty attached too).
 1.102 05-Jul-1997  thorpej branches: 1.102.2;
Add support for remote serial KGDB.
 1.101 15-Jun-1997  mycroft Implement a better backpressure mechanism so that data is collected
in the driver's buffer if the tty buffer is full. If the driver's buffer
becomes full, turn off receive interrupts until it drains a bit.
 1.100 26-May-1997  mycroft Remove unneeded call to comstop() in commsrint(). This fixes a problem
where the driver would sometimes retransmit bytes.
 1.99 04-Apr-1997  mycroft New version of com driver. Uses a different queueing mechanism and a split
hardware/software interrupt mechanism for improved performance. Many odd
protocols bugs also fixed.
 1.98 04-Apr-1997  mycroft comdefaultrate -> comconsrate
comconsbah -> comconsioh
Only use comconsrate on the console.
 1.97 30-Jan-1997  cgd don't clobber IER in cominit(). (suggested by mycroft.)
 1.96 14-Dec-1996  mycroft If attaching the console, reinitialize it immediately.
 1.95 14-Dec-1996  mycroft Turn off the baud rate changing optimization.
 1.94 05-Dec-1996  cgd update these so they compile whether or not __BROKEN_INDIRECT_CONFIG
is defined.
 1.93 13-Nov-1996  cgd move cominit() prototype to comvar.h, so that ports which use 'com'
for serial console, but don't use the (i386-specific)
comcninit()/comcnprobe() functions, can do the right thing.
 1.92 22-Oct-1996  cgd add missing argument to bus_space_map in ESP code
 1.91 21-Oct-1996  thorpej New bus.h implementation/interface:
- No more distinction between i/o-mapped and memory-mapped
devices. It's all "bus space" now, and space tags
differentiate the space with finer grain than the
bus chipset tag.
- Add memory barrier methods.
- Implement space alloc/free methods.
- Implement region read/write methods (like memcpy to/from
bus space).
This interface provides a better abstraction for dealing with
machine-independent chipset drivers.
 1.90 13-Oct-1996  christos backout kprintf changes
 1.89 10-Oct-1996  christos printf -> kprintf, sprintf -> ksprintf
 1.88 06-Oct-1996  mycroft If we get a RXRDY interrupt, but RXRDY is not set in the LSR, briefly set IER
to 0. This fixes a condition where some UARTs send an infinite stream of
RXRDY interrupts.
 1.87 06-Oct-1996  mycroft Serial console changes:
* Enable FIFO with trigger level 1.
* Set DTR and RTS so terminals are happy.
 1.86 05-Sep-1996  mycroft compoll() -> comsoft()
 1.85 02-Sep-1996  mycroft tty stop functions really should return void, not int, and certainly not both.
 1.84 10-Jul-1996  cgd move DDB-only label inside an #ifdef, so that -Wall works
 1.83 30-May-1996  cgd add tty_attach() where appropriate.
 1.82 12-May-1996  mycroft branches: 1.82.4;
Use intr.h.
 1.81 05-May-1996  christos Move comintr() prototype to comvar.h; needed by the multi-port cards.
 1.80 29-Apr-1996  christos - prototype fixes
 1.79 15-Apr-1996  cgd define and export the global variable "comconscflag", the default tty
'cflag' for the console. Normally set to TTYDEF_CFLAG, may be
overridden by machine-dependent console attachment code, as necessary.
(Alpha uses it to set cs8 -parenb.) Files including comvar.h now
need to include <sys/termios.h>, because comconscflag is of type
tcflag_t.
 1.78 11-Apr-1996  cgd update for addition of a machine-dependent cookie as the first argument
to isa_intr_{,dis}establish().
 1.77 17-Mar-1996  cgd Add #ifdef's at the right places, on NCOM_ISA and NCOM_COMMULTI, to
only include the relevant code in the probe & attach functions. Still
one probe and one attach function, with #ifdefs, but this is a step
in the right direction and saves a few hundred bytes (ooh, ahh!).
 1.76 17-Mar-1996  thorpej New device attachment scheme:

- split softc size and match/attach out from cfdriver into
a new struct cfattach.

- new "attach" directive for files.*. May specify the name of
the cfattach structure, so that devices may be easily attached
to parents with different autoconfiguration semantics.
 1.75 10-Mar-1996  cgd convert these to use new <machine/bus.h> interfaces. This involved
substantial reworking of the multi-port drivers, as they need to frob
bits in the io-port spaces of their children. As a result, the
commulti->com attachment interface is substantially more complex.
(This may be fixable in the future by making some of the code common,
but as long as io-port allocation checking is planned, it's necessary.)
 1.74 09-Mar-1996  cgd include comvar.h for comprobe1() prototype
 1.73 26-Feb-1996  scottr Fix typo (PR 2123, from Michael VanLoon)
 1.72 20-Feb-1996  mycroft Add more debugging code.
 1.71 19-Feb-1996  mycroft Update copyright notice.
 1.70 19-Feb-1996  mycroft Set IER_ETXRDY before outputting any bytes, to prevent race condition.
 1.69 19-Feb-1996  mycroft Handle break more correctly.
Make IER_ETXRDY track TS_BUSY. (Prevents a loop in comintr() if no output
is available.)
Add a bunch of debugging code.
 1.68 18-Feb-1996  mycroft Fix a race condition where we might stop outputting if a write follows a
flush too closely.
 1.67 17-Feb-1996  mycroft Add some text describing the UART lossage worked around in the previous.
 1.66 17-Feb-1996  mycroft Drain the transmitter FIFO before changing the baud rate or FIFO depth
registers. Fixes PR 2046.
Also, if COMCONSOLE is defined, expect CONSPEED to be the baud rate.
 1.65 10-Feb-1996  christos Hayes ESP patches [from PR database]
 1.64 14-Jan-1996  christos Hayes ESP support from Michael Van Loon, with minor cleanups. Tested on
a single port ESP card; works great!
 1.63 24-Dec-1995  mycroft The IST_* and IPL_* constants are not bus-specific; don't treat them as such.
Change splimp -> splnet in Ethernet, ARCnet, and FDDI drivers.
 1.62 15-Oct-1995  mycroft Use SET(), CLR(), and ISSET() macros.
Rename CFCR to LCR, and cache its value.
Check MSR before transmitting, for better flow control.
Preserve LCR_SBREAK inside comparam().
 1.61 04-Jul-1995  mycroft Fix a condition where ttywait() wouldn't be woken up. Also, short-circuit
the case of no pending input in compoll().
 1.60 28-Jun-1995  cgd note that most of dev/ic's contents have changed names
 1.59 05-Jun-1995  mycroft Various:
* Check for CTS in the correct register.
* Only do a selwakeup() if we output something.
* Don't make assumptions about what TTYDISC does.
 1.58 04-Jun-1995  mycroft Handle BREAK correctly when not entering DDB.
 1.57 04-Jun-1995  mycroft Add an input FIFO, and fix several flow control problems. Based on code from
Felix A. Croes.
 1.56 01-Jun-1995  jtc Changed ns82450 to ns8250 and dropped ns82550 from probe console messages.
 1.55 28-May-1995  mycroft Only use the `no pending interrupt' bit in the IIR; the other bits
are too unreliable on clone chips.
 1.54 12-May-1995  cgd (1) conditionalize debugger usage in comeint with DDB, not COMCONSOLE;
latter would lead to undefined symbols if DDB not defined.
(2) check for break on console, and therefore debugger entry (if ddb
in kernel) earlier, so that the device doesn't need to be open.
(3) return immediately after breaking into the debugger in comeint().
(4) only do the normal character input routine in comintr if receive
mask yeilds _EXACLTY_ LSR_RXRDY. if there's only a receive
error, or there's a receive error _and_ a received character,
do comeint().
(former two by me. latter two from Bob Baron <rvb@cs.cmu.edu>.)
 1.53 28-Apr-1995  hpeyerl <break> --> ddb if defined(comconsole).
(if you have a serial console and you hit break, you get ddb).
 1.52 19-Apr-1995  mycroft Fix thinko in previous change.
 1.51 19-Apr-1995  mycroft Garbage collect #includes.
 1.50 19-Apr-1995  mycroft Implement comtty().
 1.49 17-Apr-1995  cgd clean up several ISA device interfaces: autoconfiguration, header
inclusion, and interrupt configuration. more work still needs to be done,
but it's getting better...
 1.48 10-Apr-1995  mycroft Most of the console functions return void. Also change interrupt logic
slightly.
 1.47 29-Jan-1995  cgd lip service to making ISA support machine-independent. This is the first
round: moving the drivers into a machine-independent directory.
Some drivers (e.g. fd.c) not moved because they use other pc features (e.g.
CMOS settings), and none of the non-driver files moved, because they're
still pretty much PC specific. eventually (when other ports with ISA
busses really start using this code), more 'high-level' ISA support will
live here.
 1.46 29-Jan-1995  cgd use chip headers in /dev/ic
 1.45 11-Jan-1995  pk Explicitly test the RXRDY status bit on incoming characters.
 1.44 04-Jan-1995  mycroft Fix oversight in previous.
 1.43 03-Jan-1995  mycroft Add interrupt sharing types.
 1.42 25-Nov-1994  mycroft Minor update for new autoconfig.
 1.41 18-Nov-1994  mycroft Convert port, IRQ, and DRQ numbers to ints.
 1.40 03-Nov-1994  mycroft Update to match autoconfig code.
 1.39 30-Oct-1994  cgd be more careful with types, also pull in headers where necessary.
 1.38 27-Oct-1994  cgd new RCS ID format.
 1.37 26-Oct-1994  mycroft Implement *cnpollc().
 1.36 16-Sep-1994  mycroft Only reset FIFO if changing baud rate. From John Kohl (slightly edited).
 1.35 24-Aug-1994  mycroft Set the FIFO threshold based on the receive speed, per Mark Weaver.
 1.34 21-Aug-1994  mycroft Look for MDMBUF in cflag, not lflag.
 1.33 07-Aug-1994  mycroft Count up the silo overflows and only log a warning at most once per minute.
 1.32 31-Jul-1994  mycroft Bug fixes from Mark Weaver.
 1.31 10-Apr-1994  cgd branches: 1.31.2;
allow MDMBUF flags to be set (oops)
 1.30 07-Apr-1994  mycroft Implement dynamic IRQ configuration and IRQ sharing. Inline spl*() calls.
Reorganize and clean up the relevant code.
 1.29 29-Mar-1994  mycroft Updates for new autoconfig.
 1.28 25-Mar-1994  mycroft Fix off-by-one error in comopen() unit number sanity check. From Brian de
Alwis.
 1.27 23-Mar-1994  mycroft Some stylistic cleanup, and a very minor speedup.
 1.26 23-Mar-1994  cgd add AST-style serial multiport support, from Roland McGrath
<roland@@frob.com>. Needs light clean by Mr. I386, but mostly
OK. For some reason, Bad Things (TM) happened on the last cvs commit.
 1.25 18-Mar-1994  cgd add reasonable support for MDMBUF output flow control. input to be done later
 1.24 12-Mar-1994  cgd copy appropriate hardware config bits from config's flags
 1.23 12-Mar-1994  cgd fix some of the last; thanks to charles for looking it over...
 1.22 12-Mar-1994  cgd support new ioctls. fix the way CRTSCTS is used, etc. Seperate 'hardware'
and 'software' flags. beginnings of multiport support.
 1.21 08-Mar-1994  mycroft Major cleanup and many bugs fixed; based in part on Brad Huntting's version
for BSD/386. More to be done when the low-level interrupt system is replaced.
 1.20 06-Mar-1994  mycroft DELAY() --> delay(). This is not a macro.
 1.19 09-Feb-1994  mycroft All ioctl routines take a struct proc * now.
 1.18 01-Feb-1994  cgd oops
 1.17 01-Feb-1994  cgd new cons.h location, etc.
 1.16 30-Jan-1994  ws Traditional behaviour is to reset all modes if device isn't open already
 1.15 13-Jan-1994  mycroft Junk comselect(); it's the same at ttselect().
 1.14 20-Dec-1993  mycroft Canonicalize all #includes, and add pio.h where appropriate.
 1.13 29-Sep-1993  cgd ifdef out the ttyfree()'s, so that fill_eproc doesn't panic when
a process's session still holds a ref to a tty which has been deallocated
and reused.
 1.12 29-Aug-1993  deraadt branches: 1.12.2;
tty XXstart() routines return void
 1.11 12-Jul-1993  mycroft Change tty code to use clist interface, but with ring buffer implementation.
Also, fix a couple of bugs in tty.c and pccons.c, and some gross kluginess
in the hp300 stuff.
 1.10 07-Jul-1993  deraadt pccons.c now dynamically allocates it's "struct tty"
cons.c's "struct tty *cn_tty" wasn't used by any of the kernel, and goes away.
 1.9 06-Jun-1993  cgd make getc() and ungetc() be rb{un,}getc(), so getc() and ungetc()
don't conflict w/ansi prototypes...
 1.8 26-May-1993  deraadt tty dynamic allocation
 1.7 18-May-1993  cgd make kernel select interface be one-stop shopping & clean it all up.
 1.6 10-Apr-1993  glass fixed to be compliant, subservient, and to take advantage of the newly
hacked config(8)
 1.5 09-Apr-1993  cgd have probe return size of io space on successful return, rather
than simply 1.
 1.4 08-Apr-1993  deraadt dmesg output at boottime now tries to print out information as
soon as it is available. The output looks much more like Sunos.
 1.3 27-Mar-1993  cgd moved closing #endif to include comselect
 1.2 21-Mar-1993  cgd after 0.2.2 "stable" patches applied
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.12.2.17 01-Feb-1994  mycroft Updates from main branch.
 1.12.2.16 29-Oct-1993  mycroft Minor cleanup.
 1.12.2.15 29-Oct-1993  mycroft c_cflag is a tcflag_t, not a u_char. (Duh.)
 1.12.2.14 18-Oct-1993  mycroft Fix a small typo.
 1.12.2.13 18-Oct-1993  mycroft Check bits in the fifo reg during probe to make sure they are on.
 1.12.2.12 17-Oct-1993  mycroft Minor cleanup.
 1.12.2.11 16-Oct-1993  mycroft Add missing dv_class entry to cfdrivers, and use dv_xname where appropriate.
 1.12.2.10 15-Oct-1993  mycroft Nuke a wakeup() I left in accidentally.
 1.12.2.9 15-Oct-1993  mycroft Flush any pending I/O on open. After a transmit interrupt, don't call
comstart() if TS_FLUSH is set.
 1.12.2.8 13-Oct-1993  mycroft Use stupid indirection to avoid a compiler warning.
 1.12.2.7 12-Oct-1993  mycroft Minor cleanup.
 1.12.2.6 11-Oct-1993  mycroft #include pio.h where needed, and remove cpufunc.h.
 1.12.2.5 07-Oct-1993  mycroft Don't #include isa.h.
 1.12.2.4 06-Oct-1993  mycroft Change comforceintr() to not use loopback. Change attach messages.
 1.12.2.3 30-Sep-1993  mycroft Change some uses of IRQUNK to IRQNONE. #include isa.h and icu.h.
 1.12.2.2 30-Sep-1993  mycroft clock.c: Remove unnecessary casts.
com.c: Update for new config. Add bis() and bic() macros like BSDI's.
Add comspeed() and tiocm_xxx2mcr() from BSDI.
comreg.h: Add COM_FREQ, COM_TOLERANCE, and COM_NPORTS.
fd.c: Remove casts and clean up fdioctl().
[lm]ms.c: Add necessary gunk to [lm]ms_softc and remove casts.
 1.12.2.1 14-Sep-1993  mycroft New i386 code.
 1.31.2.5 16-Sep-1994  cgd from trunk.
 1.31.2.4 24-Aug-1994  mycroft update from trunk
 1.31.2.3 21-Aug-1994  mycroft update from trunk
 1.31.2.2 07-Aug-1994  mycroft update from trunk
 1.31.2.1 01-Aug-1994  cgd From trunk.
 1.82.4.3 16-Feb-1997  rat Patch supplied by Charles Hannmum.
 1.82.4.2 10-Dec-1996  mycroft From trunk:
Set serial port parameters sanely for a serial console.
 1.82.4.1 02-Jun-1996  mrg pull up tty stats "bug fix".
 1.102.2.4 14-Oct-1997  thorpej Update marc-pcmcia branch from trunk.
 1.102.2.3 22-Sep-1997  thorpej Update marc-pcmcia branch from trunk.
 1.102.2.2 27-Aug-1997  thorpej Update marc-pcmcia branch from trunk.
 1.102.2.1 23-Aug-1997  thorpej Update marc-pcmcia branch from trunk.
 1.113.2.2 16-Oct-1997  thorpej Sync w/ trunk.
 1.113.2.1 16-Oct-1997  thorpej file com.c was added on branch marc-pcmcia on 1997-10-16 00:04:07 +0000
 1.118.2.5 05-May-1998  mycroft Pull up 1.136-1.138, per request of scottr.
 1.118.2.4 17-Dec-1997  mellon Pull rev 1.129 up from trunk (mycroft)
 1.118.2.3 04-Nov-1997  mellon Pull up rev 1.120 through 1.128 (mycroft)
 1.118.2.2 30-Oct-1997  mellon Pull rev 1.119 up from trunk (drochner)
 1.118.2.1 21-Oct-1997  mellon file com.c was added on branch netbsd-1-3 on 1997-10-30 23:22:55 +0000
 1.159.2.4 08-Feb-2000  he Pull up revisions 1.167-1.168 (requested by jonathan):
Properly catch PPS signals on DCD transitions, even if DCD is
otherwise ignored.
 1.159.2.3 20-Jan-2000  he Pull up revisions 1.162-1.163 (requested by jonathan):
Fix TIMEVAL/TIMESPEC botches and update to the -05 draft version
of the PPS-API specification.
 1.159.2.2 05-Jan-2000  he Pull up revision 1.165 (requested by drochner):
Set carrier early enough for a serial console or kgdb to work
with hardware handshake. Fixes PR#6547.
 1.159.2.1 19-Apr-1999  perry branches: 1.159.2.1.2;
pullup 1.159->1.161 -- requested by ross. apparently fixes critical bugs on
a number of ports.
 1.159.2.1.2.1 21-Jun-1999  thorpej Sync w/ -current.
 1.161.2.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.162.4.1 15-Nov-1999  fvdl Sync with -current
 1.162.2.3 18-Jan-2001  bouyer Sync with head (for UBC+NFS fixes, mostly).
 1.162.2.2 22-Nov-2000  bouyer Sync with HEAD.
 1.162.2.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.183.2.11 11-Nov-2002  nathanw Catch up to -current
 1.183.2.10 17-Sep-2002  nathanw Catch up to -current.
 1.183.2.9 01-Aug-2002  nathanw Catch up to -current.
 1.183.2.8 17-Apr-2002  nathanw Catch up to -current.
 1.183.2.7 01-Apr-2002  nathanw Catch up to -current.
(CVS: It's not just a program. It's an adventure!)
 1.183.2.6 08-Jan-2002  nathanw Catch up to -current.
 1.183.2.5 14-Nov-2001  nathanw Catch up to -current.
 1.183.2.4 21-Sep-2001  nathanw Catch up to -current.
 1.183.2.3 24-Aug-2001  nathanw Catch up with -current.
 1.183.2.2 21-Jun-2001  nathanw Catch up to -current.
 1.183.2.1 05-Mar-2001  nathanw Initial commit of scheduler activations and lightweight process support.
 1.186.2.6 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.186.2.5 06-Sep-2002  jdolecek sync kqueue branch with HEAD
 1.186.2.4 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.186.2.3 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.186.2.2 13-Sep-2001  thorpej Update the kqueue branch to HEAD.
 1.186.2.1 25-Aug-2001  thorpej Merge Aug 24 -current into the kqueue branch.
 1.188.2.5 13-Oct-2001  fvdl Revert the t_dev -> t_devvp change in struct tty. The way that tty
structs are currently used (especially by console ttys) aren't
ready for it, and this will require quite a few changes.
 1.188.2.4 01-Oct-2001  fvdl Catch up with -current.
 1.188.2.3 26-Sep-2001  fvdl * add a VCLONED vnode flag that indicates a vnode representing a cloned
device.
* rename REVOKEALL to REVOKEALIAS, and add a REVOKECLONE flag, to pass
to VOP_REVOKE
* the revoke system call will revoke all aliases, as before, but not the
clones
* vdevgone is called when detaching a device, so make it use REVOKECLONE
to get rid of all clones as well
* clean up all uses of VOP_OPEN wrt. locking.
* add a few VOPS to spec_vnops that need to do something when it's a
clone vnode (access and getattr)
* add a copy of the vnode vattr structure of the original 'master' vnode
to the specinfo of a cloned vnode. could possibly redirect getattr to
the 'master' vnode, but this has issues with revoke
* add a vdev_reassignvp function that disassociates a vnode from its
original device, and reassociates it with the specified dev_t. to be
used by cloning devices only, in case a new minor is allocated.
* change all direct references in drivers to v_devcookie and v_rdev
to vdev_privdata(vp) and vdev_rdev(vp). for diagnostic purposes
when debugging race conditions that still exist wrt. locking and
revoking vnodes.
* make the locking state of a vnode consistent when passed to
d_open and d_close (unlocked). locked would be better, but has
some deadlock issues
 1.188.2.2 18-Sep-2001  fvdl Various changes to make cloning devices possible:

* Add an extra argument (struct vnode **) to VOP_OPEN. If it is
not NULL, specfs will create a cloned (aliased) vnode during
the call, and return it there. The caller should release and
unlock the original vnode if a new vnode was returned. The
new vnode is returned locked.

* Add a flag field to the cdevsw and bdevsw structures.
DF_CLONING indicates that it wants a new vnode for each
open (XXX is there a better way? devprop?)

* If a device is cloning, always call the close entry
point for a VOP_CLOSE.


Also, rewrite cons.c to do the right thing with vnodes. Use VOPs
rather then direct device entry calls. Suggested by mycroft@

Light to moderate testing done an i386 system (arch doesn't matter
though, these are MI changes).
 1.188.2.1 07-Sep-2001  thorpej Commit my "devvp" changes to the thorpej-devvp branch. This
replaces the use of dev_t in most places with a struct vnode *.

This will form the basic infrastructure for real cloning device
support (besides being architecurally cleaner -- it'll be good
to get away from using numbers to represent objects).
 1.189.2.1 12-Nov-2001  thorpej Sync the thorpej-mips-cache branch with -current.
 1.196.4.1 06-Apr-2004  tron Pull up revision 1.225 (requested by enami in ticket #1658):
Fix race condition introduced in rev 1.189; after the change, if there is
THRE interrupt occurs between the LSR read and IIR read, we won't see the
LSR_TXRDY bit when testing it in the variable `lsr' and we don't interrupted
again (as the corresponding bit in the IIR is cleared by reading, except
for some broken device).
Tested by Matthias Scheler and me, reviewed by Allen Briggs.
Closes PR#25010.
 1.196.2.2 29-Aug-2002  gehenna catch up with -current.
 1.196.2.1 16-May-2002  gehenna Add the character device switch.
Replace the access to devsw table with calling devsw API.
 1.216.2.7 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.216.2.6 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.216.2.5 21-Sep-2004  skrll Fix the sync with head I botched.
 1.216.2.4 18-Sep-2004  skrll Sync with HEAD.
 1.216.2.3 12-Aug-2004  skrll Sync with HEAD.
 1.216.2.2 03-Aug-2004  skrll Sync with HEAD
 1.216.2.1 02-Jul-2003  darrenr Apply the aborted ktrace-lwp changes to a specific branch. This is just for
others to review, I'm concerned that patch fuziness may have resulted in some
errant code being generated but I'll look at that later by comparing the diff
from the base to the branch with the file I attempt to apply to it. This will,
at the very least, put the changes in a better context for others to review
them and attempt to tinker with removing passing of 'struct lwp' through
the kernel.
 1.224.2.2 05-Jul-2004  he branches: 1.224.2.2.2;
Pull up revisions 1.228-1.230 (requested by mycroft in ticket #603):
Incorporate 4 changes:
o At high speed, set the FIFO trigger to a higher
value to reduce interrupt load. Fixes PR#15448.
o Handle the case of IIR=RXRDY and LSR=!LSR_RCV_MASK
differently, to avoid a hang with some chips. Fixes
PR#21184, and possibly PR#10974 and PR#8248.
o Remove the extra wait at the end of com_common_putc(),
after writing a character out, so that we get another
TXRDY interrupt. This prevents stalls when normal
output and kernel output are mixed. Fixes PR#4263.
o Do not ``preload'' the TX FIFO; wait for a TXRDY
interrupt to come in after enabling it.
 1.224.2.1 06-Apr-2004  jmc Pullup rev 1.225 (requested by enami in ticket #70)

Fix race condition introduced in rev 1.189; after the change, if there is
THRE interrupt occurs between the LSR read and IIR read, we won't see the
LSR_TXRDY bit when testing it in the variable 'lsr' and we don't get
interrupted again (as the corresponding bit in the IIR is cleared by reading,
except for some broken devices). PR#25010
 1.224.2.2.2.1 01-Dec-2007  bouyer Pull up following revision(s) (requested by is in ticket #11394):
sys/dev/ic/com.c: revision 1.233
Revert the part of revision 1.228 that made HW_NO_TXPRELOAD the default:
it appears to break output on the Soekris net4501, which is a rather
popular platform.
This should fix PR kern/29612.
 1.231.6.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.231.4.1 29-Apr-2005  kent sync with -current
 1.232.2.1 01-Dec-2007  bouyer Pull up following revision(s) (requested by is in ticket #1882):
sys/dev/ic/com.c: revision 1.233
Revert the part of revision 1.228 that made HW_NO_TXPRELOAD the default:
it appears to break output on the Soekris net4501, which is a rather
popular platform.
This should fix PR kern/29612.
 1.234.2.9 17-Mar-2008  yamt sync with head.
 1.234.2.8 04-Feb-2008  yamt sync with head.
 1.234.2.7 21-Jan-2008  yamt sync with head
 1.234.2.6 07-Dec-2007  yamt sync with head
 1.234.2.5 27-Oct-2007  yamt sync with head.
 1.234.2.4 03-Sep-2007  yamt sync with head.
 1.234.2.3 26-Feb-2007  yamt sync with head.
 1.234.2.2 30-Dec-2006  yamt sync with head.
 1.234.2.1 21-Jun-2006  yamt sync with head.
 1.239.2.2 01-Mar-2006  yamt sync with head.
 1.239.2.1 15-Jan-2006  yamt sync with head.
 1.240.4.3 01-Jun-2006  kardel Sync with head.
 1.240.4.2 22-Apr-2006  simonb Sync with head.
 1.240.4.1 04-Feb-2006  simonb Adapt for timecounters and newer PPS API.
 1.240.2.1 09-Sep-2006  rpaulo sync with head
 1.241.6.2 24-May-2006  tron Merge 2006-05-24 NetBSD-current into the "peter-altq" branch.
 1.241.6.1 31-Mar-2006  tron Merge 2006-03-31 NetBSD-current into the "peter-altq" branch.
 1.241.4.3 19-Apr-2006  elad sync with head.
 1.241.4.2 10-Mar-2006  elad generic_authorize() -> kauth_authorize_generic().
 1.241.4.1 08-Mar-2006  elad Adapt to kernel authorization KPI.
 1.241.2.4 11-Aug-2006  yamt sync with head
 1.241.2.3 26-Jun-2006  yamt sync with head.
 1.241.2.2 24-May-2006  yamt sync with head.
 1.241.2.1 01-Apr-2006  yamt sync with head.
 1.243.2.1 19-Jun-2006  chap Sync with head.
 1.244.2.6 13-Jul-2006  gdamore Merge from HEAD.
 1.244.2.5 17-Jun-2006  gdamore Yes, I'm restoring COM_INIT_REGS and removing the compatibility #define's
for sc_iot and friends. Those defines break things, like say ast.c, where
comvar.h is included, but a local sc_iot structure member is also used.
 1.244.2.4 17-Jun-2006  gdamore Per tsutsui@, I'm removing COM_INIT_REGS, and adding a flag to make the
map initialization automatic. This breaks this whole tree again, so I pretty
much have to start over going back thru old code to make it all compatible.
 1.244.2.3 16-Jun-2006  gdamore KNF per simonb@ consisting of:
regs.xx -> regs.cr_xxx
wrap COM_INIT_REGS body with do { } while (0);)
Convert INB/OUTB macros to CSR_READ/CSR_WRITE macros per tsutsui@.
 1.244.2.2 15-Jun-2006  gdamore Fix a type where comconsregs was defined twice, and comkgdregs was missing.
Thanks to simonb@ Doh!
 1.244.2.1 15-Jun-2006  gdamore Initial com framework changes. These changes bust *all* com consumers, but
follow-up commits shortly will fix many of them, so that i386, sparc, and
some evbmips ports at least work.
 1.250.2.1 07-Sep-2006  riz Pull up following revision(s) (requested by martin in ticket #118):
sys/dev/ic/com.c: revision 1.251
fix a GCC uninitialised variable warning only seen at -O3.
 1.251.4.2 10-Dec-2006  yamt sync with head.
 1.251.4.1 22-Oct-2006  yamt sync with head
 1.251.2.2 12-Jan-2007  ad Sync with head.
 1.251.2.1 18-Nov-2006  ad Sync with head.
 1.258.2.1 12-Mar-2007  rmind Sync with HEAD.
 1.259.4.1 11-Jul-2007  mjf Sync with head.
 1.259.2.3 23-Oct-2007  ad Sync with head.
 1.259.2.2 01-Jul-2007  ad - Generic soft interrupts are mandatory, remove the kludges.
- Adapt to callout API change.
- Use mutexes.
 1.259.2.1 17-Jun-2007  ad - Increase the number of thread priorities from 128 to 256. How the space
is set up is to be revisited.
- Implement soft interrupts as kernel threads. A generic implementation
is provided, with hooks for fast-path MD code that can run the interrupt
threads over the top of other threads executing in the kernel.
- Split vnode::v_flag into three fields, depending on how the flag is
locked (by the interlock, by the vnode lock, by the file system).
- Miscellaneous locking fixes and improvements.
 1.261.6.4 09-Dec-2007  jmcneill Sync with HEAD.
 1.261.6.3 21-Nov-2007  joerg Sync with HEAD.
 1.261.6.2 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.261.6.1 03-Sep-2007  jmcneill Sync with HEAD.
 1.261.2.1 03-Sep-2007  skrll Sync with HEAD.
 1.262.4.2 18-Oct-2007  yamt sync with head.
 1.262.4.1 14-Oct-2007  yamt sync with head.
 1.262.2.4 23-Mar-2008  matt sync with HEAD
 1.262.2.3 09-Jan-2008  matt sync with HEAD
 1.262.2.2 06-Nov-2007  matt sync with HEAD
 1.262.2.1 29-Oct-2007  matt Add support for OMAP specific com type.
 1.264.2.2 21-Nov-2007  bouyer Sync with HEAD
 1.264.2.1 25-Oct-2007  bouyer Sync with HEAD.
 1.265.2.3 18-Feb-2008  mjf Sync with HEAD.
 1.265.2.2 27-Dec-2007  mjf Sync with HEAD.
 1.265.2.1 08-Dec-2007  mjf Sync with HEAD.
 1.266.2.2 26-Dec-2007  ad Sync with head.
 1.266.2.1 08-Dec-2007  ad Sync with head.
 1.267.4.3 23-Jan-2008  bouyer Sync with HEAD.
 1.267.4.2 08-Jan-2008  bouyer Sync with HEAD
 1.267.4.1 02-Jan-2008  bouyer Sync with HEAD
 1.272.6.4 17-Jan-2009  mjf Sync with HEAD.
 1.272.6.3 28-Sep-2008  mjf Sync with HEAD.
 1.272.6.2 02-Jun-2008  mjf Sync with HEAD.
 1.272.6.1 03-Apr-2008  mjf Sync with HEAD.
 1.272.2.1 24-Mar-2008  keiichi sync with head.
 1.278.2.1 18-May-2008  yamt sync with head.
 1.279.2.5 11-Aug-2010  yamt sync with head.
 1.279.2.4 11-Mar-2010  yamt sync with head
 1.279.2.3 16-May-2009  yamt sync with head
 1.279.2.2 04-May-2009  yamt sync with head.
 1.279.2.1 16-May-2008  yamt sync with head.
 1.281.6.2 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.281.6.1 19-Oct-2008  haad Sync with HEAD.
 1.281.4.1 18-Jul-2008  simonb Sync with head.
 1.281.2.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.286.14.1 07-Jan-2011  matt Let's cons.c poll and so don't loop until a chacater becomes available.
 1.286.10.2 20-May-2011  matt Fix early boot on AU1x type com ports.
 1.286.10.1 13-Sep-2009  cliff when attaching com, (frequency == -1) means leave the BRG divisor as-is
(inherit values established by firmware)
 1.286.2.1 19-Jan-2009  skrll Sync with HEAD.
 1.287.2.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.294.2.2 17-Aug-2010  uebayasi Sync with HEAD.
 1.294.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.295.2.3 31-May-2011  rmind sync with head
 1.295.2.2 05-Mar-2011  rmind sync with head
 1.295.2.1 30-May-2010  rmind sync with head
 1.298.4.1 08-Feb-2011  bouyer Sync with HEAD
 1.298.2.1 06-Jun-2011  jruoho Sync with HEAD.
 1.301.4.4 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.301.4.3 23-Jan-2013  yamt sync with head
 1.301.4.2 23-May-2012  yamt sync with head.
 1.301.4.1 17-Apr-2012  yamt sync with head
 1.303.2.3 02-Jun-2012  mrg sync to latest -current.
 1.303.2.2 29-Apr-2012  mrg sync to latest -current.
 1.303.2.1 18-Feb-2012  mrg merge to -current.
 1.304.2.1 22-Apr-2012  riz Pull up following revision(s) (requested by christos in ticket #190):
sys/dev/ic/com.c: revision 1.305
don't include<sys/rnd.h> before we define cn_trap, because it might bring
in<sys/systm.h>
 1.306.2.4 03-Dec-2017  jdolecek update from HEAD
 1.306.2.3 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.306.2.2 23-Jun-2013  tls resync from head
 1.306.2.1 25-Feb-2013  tls resync with head
 1.310.4.2 18-May-2014  rmind sync with head
 1.310.4.1 28-Aug-2013  rmind sync with head
 1.323.2.2 10-Aug-2014  tls Rebase.
 1.323.2.1 07-Apr-2014  tls Be a little more clear and consistent about harvesting entropy from devices:

1) deprecate RND_FLAG_NO_ESTIMATE

2) define RND_FLAG_COLLECT_TIME, RND_FLAG_COLLECT_VALUE

3) define RND_FLAG_ESTIMATE_TIME, RND_FLAG_ESTIMATE_VALUE

4) define RND_FLAG_DEFAULT: RND_FLAG_COLLECT_TIME|
RND_FLAG_COLLECT_VALUE|RND_FLAG_ESTIMATE_TIME

5) Make entropy harvesting from environmental sensors a little more generic
and remove it from individual sensor drivers.

6) Remove individual open-coded delta-estimators for values from a few
places in the tree (uvm, environmental drivers).

7) 0 -> RND_FLAG_DEFAULT, actually gather entropy from various drivers
that had stubbed out code, other minor cleanups.
 1.327.2.1 22-Jun-2016  snj Pull up following revision(s) (requested by bouyer in ticket #1178):
sys/arch/arm/allwinner/files.awin: revision 1.36
sys/conf/files: revision 1.1159
sys/dev/ic/com.c: revision 1.339
sys/dev/ic/comreg.h: revision 1.25
sys/dev/ic/comvar.h: revision 1.82
sys/dev/ic/ns16550reg.h: revision 1.11
The UART in the allwiner SoCs is not full-compatible with the 16550, and
it's not a 16750 either. Like the 16750 it has the IIR_BUSY interrupt,
which is triggered when writing to LCR while the chip
can't accept it. But unlike the 16750, it has a specific register,
HALT, to allow writing to the LCR and divisor registers, and then
commit the changes.
Tested on an A20 SoC, changing the baud rate while keeping the
tty device open and incoming data.
 1.329.2.5 28-Aug-2017  skrll Sync with HEAD
 1.329.2.4 29-May-2016  skrll Sync with HEAD
 1.329.2.3 27-Dec-2015  skrll Sync with HEAD (as of 26th Dec)
 1.329.2.2 06-Jun-2015  skrll Sync with HEAD
 1.329.2.1 06-Apr-2015  skrll Sync with HEAD
 1.339.10.1 06-Nov-2017  snj Pull up following revision(s) (requested by martin in ticket #338):
sys/arch/sparc64/dev/sab.c: revision 1.55
sys/dev/ic/com.c: revision 1.345
sys/dev/ic/z8530tty.c: revision 1.132
sys/dev/sun/sunkbd.c: revision 1.30
sys/dev/sun/sunms.c: revision 1.33
sys/sys/tty.h: revision 1.94
As discussed on tech-kern: define a new tty internal state flag: TS_KERN_ONLY
Implement it in a few tty drivers. If this flag is set, the underlying
hardware is used by another driver and userland has no right to open
it. A few uses will appear soon in sys/dev/sun/sun{kbd,ms}.c.
--
PR port-sparc64/52622: mark the parent device as TS_KERN_ONLY,
so userland will not touch it (and change serial params w/o our
control).
 1.346.2.4 18-Jan-2019  pgoyette Synch with HEAD
 1.346.2.3 26-Dec-2018  pgoyette Sync with HEAD, resolve a few conflicts
 1.346.2.2 25-Jun-2018  pgoyette Sync with HEAD
 1.346.2.1 16-Apr-2018  pgoyette Sync with HEAD, resolve some conflicts
 1.348.2.3 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.348.2.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.348.2.1 10-Jun-2019  christos Sync with HEAD
 1.356.2.1 29-Feb-2020  ad Sync with head.
 1.361.4.1 03-Apr-2021  thorpej Sync with HEAD.
 1.361.2.1 03-Apr-2021  thorpej Sync with HEAD.
 1.363.2.1 01-Aug-2021  thorpej Sync with HEAD.
 1.384.6.1 02-Aug-2025  perseant Sync with HEAD
 1.12 08-Dec-2018  thorpej Clean up initialization of com_regs structure, in preparation for
some additional changers.
 1.11 28-Apr-2008  martin branches: 1.11.86; 1.11.88;
Remove clause 3 and 4 from TNF licenses
 1.10 14-Mar-2008  cube branches: 1.10.2; 1.10.4;
Split device_t and softc for all com(4) devices (well, everything that
uses a com_softc backend). Use proper types and ansify where appropriate.
 1.9 19-Oct-2007  ad branches: 1.9.12; 1.9.16;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.8 16-Aug-2006  gdamore branches: 1.8.12; 1.8.26; 1.8.28; 1.8.32;
2nd try. Fix errors (hopefully) that prevented this from compiling. This
has not been tested, as I lack the tools necessary to build this (and can't
bootstrap pmppc toolchain for some reason.)

Requested by garbled@
 1.7 13-Jul-2006  gdamore branches: 1.7.2;
Add an option COM_REGMAP to allow com(4) to use an array of register indices.
This allows us to convert aucom to just another com attachment, and cleanup
some code in the com_arbus.c.

Additionally, we use a common com_cleanup routine rather than having a
zillion copies of it in the attachment points.

This has been tested on a number architectures, and it has been shown to get
close to comparable performance when COM_REGMAP is defined, and comparable
when it is not defined.

Approved by core@. Fixes PR port-evbmips/32362.
 1.6 11-Dec-2005  christos branches: 1.6.4; 1.6.8; 1.6.16;
merge ktrace-lwp.
 1.5 14-Jul-2003  lukem branches: 1.5.16;
add missing __KERNEL_RCSID()
 1.4 02-Oct-2002  thorpej branches: 1.4.6;
Add trailing ; to CFATTACH_DECL.
 1.3 30-Sep-2002  thorpej Use CFATTACH_DECL().
 1.2 27-Sep-2002  thorpej Declare all cfattach structures const.
 1.1 21-May-2002  augustss branches: 1.1.4; 1.1.6; 1.1.8;
Add a driver for the IBM CPC700 chip. This chip is a host bridge for
PowerPC and provides a PCI-host bridge, interrupt controller, two com ports,
two IIC ports, a timer, and a DRAM controller.
The driver supports PCI, interrupts and com ports.
 1.1.8.3 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.1.8.2 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.1.8.1 21-May-2002  jdolecek file com_cpcbus.c was added on branch kqueue on 2002-06-23 17:46:17 +0000
 1.1.6.3 18-Oct-2002  nathanw Catch up to -current.
 1.1.6.2 20-Jun-2002  nathanw Catch up to -current.
 1.1.6.1 21-May-2002  nathanw file com_cpcbus.c was added on branch nathanw_sa on 2002-06-20 03:44:30 +0000
 1.1.4.2 30-May-2002  gehenna Catch up with -current.
 1.1.4.1 21-May-2002  gehenna file com_cpcbus.c was added on branch gehenna-devsw on 2002-05-30 14:45:31 +0000
 1.4.6.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.4.6.2 18-Sep-2004  skrll Sync with HEAD.
 1.4.6.1 03-Aug-2004  skrll Sync with HEAD
 1.5.16.3 17-Mar-2008  yamt sync with head.
 1.5.16.2 27-Oct-2007  yamt sync with head.
 1.5.16.1 30-Dec-2006  yamt sync with head.
 1.6.16.4 16-Aug-2006  gdamore Fix a problem (hopefully) that prevented this from compiling. Noticed
by garbled@. This is only used on pmppc (as far as I can tell). I can't
test this, and I don't even know that it compiles properly (because I
can't bootstrap a powerpc toolchain), but it can't be any worse than it is
now (it doesn't compile). Hopefully this will fix the problem.

Reviewed and approved (but not tested!) by garbled@.
 1.6.16.3 17-Jun-2006  gdamore Undo the undo. Restore COM_INIT_REGS.
 1.6.16.2 17-Jun-2006  gdamore Undo COM_INIT_REGS.
 1.6.16.1 16-Jun-2006  gdamore More com(4) variants that I missed earlier. Thanks to tsutsui@ for pointing
this out.
 1.6.8.2 03-Sep-2006  yamt sync with head.
 1.6.8.1 11-Aug-2006  yamt sync with head
 1.6.4.1 09-Sep-2006  rpaulo sync with head
 1.7.2.1 01-Sep-2006  tron Pull up following revision(s) (requested by garbled in ticket #88):
sys/dev/ic/com_cpcbus.c: revision 1.8
2nd try. Fix errors (hopefully) that prevented this from compiling. This
has not been tested, as I lack the tools necessary to build this (and can't
bootstrap pmppc toolchain for some reason.)
Requested by garbled@
 1.8.32.1 25-Oct-2007  bouyer Sync with HEAD.
 1.8.28.2 23-Mar-2008  matt sync with HEAD
 1.8.28.1 06-Nov-2007  matt sync with HEAD
 1.8.26.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.8.12.1 23-Oct-2007  ad Sync with head.
 1.9.16.2 02-Jun-2008  mjf Sync with HEAD.
 1.9.16.1 03-Apr-2008  mjf Sync with HEAD.
 1.9.12.1 24-Mar-2008  keiichi sync with head.
 1.10.4.1 16-May-2008  yamt sync with head.
 1.10.2.1 18-May-2008  yamt sync with head.
 1.11.88.1 10-Jun-2019  christos Sync with HEAD
 1.11.86.1 26-Dec-2018  pgoyette Sync with HEAD, resolve a few conflicts
 1.13 11-Nov-2019  msaitoh Remove acorn26's upc(4) devices.
 1.12 08-Dec-2018  thorpej Clean up initialization of com_regs structure, in preparation for
some additional changers.
 1.11 25-Jan-2009  bjh21 branches: 1.11.64; 1.11.66;
The introduction of config_stdsubmatch() lost an important feature of
upc_submatch() whereby it made sure that the correct driver attached.
Since this didn't really belong in the submatch function anyway,
reintroduce it in the match functions for upc's children.

This allows my A5000 to find at least one of its hard disks.
 1.10 14-Mar-2008  cube branches: 1.10.4; 1.10.12; 1.10.14;
Split device_t and softc for all com(4) devices (well, everything that
uses a com_softc backend). Use proper types and ansify where appropriate.
 1.9 19-Oct-2007  ad branches: 1.9.12; 1.9.16;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.8 13-Jul-2006  gdamore branches: 1.8.14; 1.8.28; 1.8.30; 1.8.34;
Add an option COM_REGMAP to allow com(4) to use an array of register indices.
This allows us to convert aucom to just another com attachment, and cleanup
some code in the com_arbus.c.

Additionally, we use a common com_cleanup routine rather than having a
zillion copies of it in the attachment points.

This has been tested on a number architectures, and it has been shown to get
close to comparable performance when COM_REGMAP is defined, and comparable
when it is not defined.

Approved by core@. Fixes PR port-evbmips/32362.
 1.7 11-Dec-2005  christos branches: 1.7.4; 1.7.8; 1.7.16;
merge ktrace-lwp.
 1.6 27-Feb-2005  perry branches: 1.6.4;
nuke trailing whitespace
 1.5 02-Oct-2002  thorpej branches: 1.5.6; 1.5.14; 1.5.16;
Add trailing ; to CFATTACH_DECL.
 1.4 30-Sep-2002  thorpej Use CFATTACH_DECL().
 1.3 27-Sep-2002  thorpej Declare all cfattach structures const.
 1.2 13-Nov-2001  lukem add/cleanup RCSID
 1.1 16-Aug-2000  bjh21 branches: 1.1.2; 1.1.4; 1.1.6;
Basic driver for CHIPS 82C710 Universal Peripheral Controller and friends,
as used on later arm26 system (A5000, A4, A3010, A3020, A4000).

What we have got:
...
upc0 at iobus0 base 0x010000: config state bb 87 1c 00 00
fdc at upc0 offset 0x3f4 not configured
wdc0 at upc0 offset 0x1f0
lpt0 at upc0 offset 0x278
com0 at upc0 offset 0x3f8: ns8250 or ns16450, no fifo
...

What we haven't got:
- FDC support (found, but not configured).
- Clearing lpt interrupts on arm26 systems (needs help from IOEB).
- A upc(4) manual page.
- More than minimal testing (my A3020s don't have root devices).
- A proper probe routine (arm26 can't use one anyway).
 1.1.6.2 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.1.6.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.1.4.2 18-Oct-2002  nathanw Catch up to -current.
 1.1.4.1 14-Nov-2001  nathanw Catch up to -current.
 1.1.2.2 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.1.2.1 16-Aug-2000  bouyer file com_upc.c was added on branch thorpej_scsipi on 2000-11-20 11:40:27 +0000
 1.5.16.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.5.14.1 29-Apr-2005  kent sync with -current
 1.5.6.1 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.6.4.3 17-Mar-2008  yamt sync with head.
 1.6.4.2 27-Oct-2007  yamt sync with head.
 1.6.4.1 30-Dec-2006  yamt sync with head.
 1.7.16.1 16-Jun-2006  gdamore More com(4) variants that I missed earlier. Thanks to tsutsui@ for pointing
this out.
 1.7.8.1 11-Aug-2006  yamt sync with head
 1.7.4.1 09-Sep-2006  rpaulo sync with head
 1.8.34.1 25-Oct-2007  bouyer Sync with HEAD.
 1.8.30.2 23-Mar-2008  matt sync with HEAD
 1.8.30.1 06-Nov-2007  matt sync with HEAD
 1.8.28.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.8.14.1 23-Oct-2007  ad Sync with head.
 1.9.16.1 03-Apr-2008  mjf Sync with HEAD.
 1.9.12.1 24-Mar-2008  keiichi sync with head.
 1.10.14.1 02-Feb-2009  snj Pull up following revision(s) (requested by bjh21 in ticket #335):
sys/dev/ic/com_upc.c: revision 1.11
sys/dev/ic/lpt_upc.c: revision 1.10
sys/dev/ic/wdc_upc.c: revision 1.26
The introduction of config_stdsubmatch() lost an important feature of
upc_submatch() whereby it made sure that the correct driver attached.
Since this didn't really belong in the submatch function anyway,
reintroduce it in the match functions for upc's children.
This allows my A5000 to find at least one of its hard disks.
 1.10.12.1 03-Mar-2009  skrll Sync with HEAD.
 1.10.4.1 04-May-2009  yamt sync with head.
 1.11.66.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.11.66.1 10-Jun-2019  christos Sync with HEAD
 1.11.64.1 26-Dec-2018  pgoyette Sync with HEAD, resolve a few conflicts
 1.28 06-Oct-2022  riastradh com(4): Add include guards.
 1.27 28-Sep-2020  jmcneill Auto-detect DW APB UART FIFO length and print the FIFO length when enabled
instead of just "working fifo".
 1.26 29-Oct-2017  jmcneill Make all of the COM_xxx type options runtime selectable. Kernel configs
with the existing options (COM_16650, COM_16750, COM_AWIN, COM_HAYESP, and
COM_PXA2X0) will select the correct type in com_attach_subr. New code
should specify the com type by passing COM_TYPE_xxx to comcnattach and/or
setting sc_type.
 1.25 27-May-2016  bouyer The UART in the allwiner SoCs is not full-compatible with the 16550, and
it's not a 16750 either. Like the 16750 it has the IIR_BUSY interrupt,
which is triggered when writing to LCR while the chip
can't accept it. But unlike the 16750, it has a specific register,
HALT, to allow writing to the LCR and divisor registers, and then
commit the changes.
Tested on an A20 SoC, changing the baud rate while keeping the
tty device open and incoming data.
 1.24 07-Mar-2015  macallan more Ingenic support:
- make sure we always set FIFO_UART_ON
- deal with the absence of DCD support
- enable the TX FIFO timeout interrupt
- set COM_HW_NOIEN
- pretend the FIFO is only 16 bytes deep ( supposed to be 64 but I get
overruns with that )
now this works as CI20 console
 1.23 22-Nov-2014  macallan branches: 1.23.2;
deal with quirk in Ingenic UARTs
( they have a bit in the FIFO control register which turns the entire
port off if not set )
 1.22 03-Oct-2013  kiyohara branches: 1.22.4;
Revirt 'Move the Marvell extension to com_mv.c' at Sun Sep 1 04:51:24 UTC 2013.
build test only.
 1.21 03-Sep-2013  jmcneill no EFR on tl16c750, use AFE bit on MCR reg instead for flow control
 1.20 01-Sep-2013  kiyohara Add support 16750 64Byte FIFO. But not test.
 1.19 01-Sep-2013  kiyohara Move the Marvell extension to com_mv.c.
 1.18 20-Apr-2013  rkujawa branches: 1.18.4;
Add support for 16750 style UARTs. Activated by defining COM_16750.

Obtained from Marvell, Semihalf.
 1.17 28-May-2011  matt branches: 1.17.4; 1.17.14;
Allow COM_TOLERANCE to be tweakable. If comspeed returns an invalid
rate, don't use that error value to set the speed.
 1.16 20-Jul-2010  jklos branches: 1.16.2;
Add support for 16650's prescaler from Frank Wille. Tested with
IOblix on Amiga.
 1.15 28-Apr-2008  matt branches: 1.15.18; 1.15.20; 1.15.22;
More forgotten changes from matt-armv6.
 1.14 11-Dec-2005  christos branches: 1.14.46; 1.14.70; 1.14.72; 1.14.74;
merge ktrace-lwp.
 1.13 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22364, verified by myself.
 1.12 05-Jun-2003  scw branches: 1.12.2;
Add support, via a kernel config file option, for the 16550-compatible
com ports found on Intel PXA2x0 processors.

Re-arrange the code which detects the FIFO configuration to defer
printing until _after_ com_fifo is cleared. Some supposedly compatible
chips clear the Tx/Rx FIFOs when this happens, resulting in previous
output being lost.
 1.11 19-Oct-1997  fvdl Add 16650 hardware flowcontrol support. Basically PR 3844 from
Dave Huang <khym@bga.com>, with added check for broken early versions
of the 16650, taken from the Linux driver.

This should be extended to use, for example, higher trigger levels for
the bigger 16650 FIFO, and its capability for using a smaller divisor
and thus higher speeds. But this patch is very useful for 16650 users
already.
 1.10 15-Oct-1997  thorpej branches: 1.10.2;
Garbage-collect some old i386 console stuff that is no longer used, and
add a comment about something to be fixed later.
 1.9 06-Sep-1996  mycroft branches: 1.9.10;
Wrap the definitions of CONADDR and CONUNIT in #ifndef.
 1.8 05-Feb-1996  scottr branches: 1.8.4;
Document this file better, mostly from John Vinopal
<banshee@gabriella.resort.com>. Closes PR #1864.
 1.7 15-Oct-1995  mycroft Use SET(), CLR(), and ISSET() macros.
Rename CFCR to LCR, and cache its value.
Check MSR before transmitting, for better flow control.
Preserve LCR_SBREAK inside comparam().
 1.6 28-Jun-1995  cgd note that most of dev/ic's contents have changed names
 1.5 29-Jan-1995  cgd use chip headers in /dev/ic
 1.4 27-Oct-1994  cgd new RCS ID format.
 1.3 08-Mar-1994  mycroft Major cleanup and many bugs fixed; based in part on Brad Huntting's version
for BSD/386. More to be done when the low-level interrupt system is replaced.
 1.2 22-May-1993  cgd branches: 1.2.4;
add rcsids to everything and clean up headers
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.2.4.2 17-Oct-1993  mycroft Minor cleanup.
 1.2.4.1 30-Sep-1993  mycroft clock.c: Remove unnecessary casts.
com.c: Update for new config. Add bis() and bic() macros like BSDI's.
Add comspeed() and tiocm_xxx2mcr() from BSDI.
comreg.h: Add COM_FREQ, COM_TOLERANCE, and COM_NPORTS.
fd.c: Remove casts and clean up fdioctl().
[lm]ms.c: Add necessary gunk to [lm]ms_softc and remove casts.
 1.8.4.1 10-Dec-1996  mycroft From trunk:
Allow CONADDR and CONUNIT to be overridden in the config file.
 1.9.10.1 15-Oct-1997  thorpej Sync w/ trunk.
 1.10.2.2 16-Oct-1997  thorpej Sync w/ trunk.
 1.10.2.1 15-Oct-1997  thorpej file comreg.h was added on branch marc-pcmcia on 1997-10-16 00:04:14 +0000
 1.12.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.12.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.12.2.1 03-Aug-2004  skrll Sync with HEAD
 1.14.74.2 11-Aug-2010  yamt sync with head.
 1.14.74.1 16-May-2008  yamt sync with head.
 1.14.72.1 18-May-2008  yamt sync with head.
 1.14.70.1 02-Jun-2008  mjf Sync with HEAD.
 1.14.46.1 29-Oct-2007  matt Add support for OMAP specific com type.
 1.15.22.2 31-May-2011  rmind sync with head
 1.15.22.1 05-Mar-2011  rmind sync with head
 1.15.20.1 17-Aug-2010  uebayasi Sync with HEAD.
 1.15.18.1 14-Feb-2014  matt defparam COM_TOLERANCE
 1.16.2.1 06-Jun-2011  jruoho Sync with HEAD.
 1.17.14.3 03-Dec-2017  jdolecek update from HEAD
 1.17.14.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.17.14.1 23-Jun-2013  tls resync from head
 1.17.4.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.18.4.1 18-May-2014  rmind sync with head
 1.22.4.1 22-Jun-2016  snj Pull up following revision(s) (requested by bouyer in ticket #1178):
sys/arch/arm/allwinner/files.awin: revision 1.36
sys/conf/files: revision 1.1159
sys/dev/ic/com.c: revision 1.339
sys/dev/ic/comreg.h: revision 1.25
sys/dev/ic/comvar.h: revision 1.82
sys/dev/ic/ns16550reg.h: revision 1.11
The UART in the allwiner SoCs is not full-compatible with the 16550, and
it's not a 16750 either. Like the 16750 it has the IIR_BUSY interrupt,
which is triggered when writing to LCR while the chip
can't accept it. But unlike the 16750, it has a specific register,
HALT, to allow writing to the LCR and divisor registers, and then
commit the changes.
Tested on an A20 SoC, changing the baud rate while keeping the
tty device open and incoming data.
 1.23.2.2 29-May-2016  skrll Sync with HEAD
 1.23.2.1 06-Apr-2015  skrll Sync with HEAD
 1.99 24-Oct-2025  brad A driver for the NXP SC16IS7xx family of UART chips. This family is
mostly a 16C450 with features from the 16C550, 16C650 and 16C750 and
makes use of src/sys/dev/ic/com.c for much of the heavy lifting.

A BIG difference is that the chip family is attached via a I2C or SPI
bus and is in no way, shape or form, attached to the computer via a
computer bus.

Since spin locks are not allowed to be held while calling to the I2C
or SPI framework com.c grew a new hw feature flag where it could be
run at something other than a hard IP level and doesn't hold spin lock
(for very long). In particular, IPL_SOFTSERIAL. This method is
enabled via a hw feature flag and should not effect any other use of
com.c. Other changes with this new method of use include the use of
workqueues and such.

A further feature added to com.c was the abilty to take advantage of
the MCR prescaler that is present in the SC16IS7xx family and likely
present in the 16C650. This prescaler is tried if the baud rate
requested can not be met with the frequency oscillator that the chip is
built with.

The chip family does not use any particular frequency oscillator for
the baud rate generator. In order to deal with this the frequency can
be set via sysctl, a kernel option or with a FDT overlay if that is
supported.

Most of the features of the chip family are supported including the
gpio pins via gpiobus(4) that are present with some of the family
members.

The chip can attach via I2C or SPI and can make sure of FDT if that is
present in the system.

This chip family has been around for quite some time and there are a
number of breakout boards on Amazon. It is also reasonably priced and
you can roll your own board if you can perform simple SMD soldering as
very few additional components are required.
 1.98 08-Oct-2022  riastradh com(4): Omit never-used sc_vendor_workaround member.
 1.97 06-Oct-2022  riastradh com(4): Add include guards.
 1.96 12-Nov-2021  jmcneill com: Add support for 32-bit IO accesses.
 1.95 12-Oct-2021  thorpej Fix the build by adding 'sc_hup_pending' member to com_softc that
was apparently forgotten.
 1.94 25-Mar-2021  rin Introduce COM_HW_BROKEN_ETXRDY bit in sc_hwflags; push TX queue if
possible in comintr() even if IIR_NOPEND is asserted.

Combined with sc_poll_ticks, this flag works around HW bug, by which
ETXRDY interrupts are (sometimes) lost.
 1.93 25-Mar-2021  rin Introduce sc_poll_ticks and obsolete COM_HW_POLL bit in sc_hwflags.
Polling is scheduled at every sc_poll_ticks ticks.

This is useful to work around H/W bug, by which interrupts are lost
*sometimes*; interrupt-based I/O mostly works and no need for polling
every counter ticks.
 1.92 11-Jan-2019  thorpej branches: 1.92.12; 1.92.14;
Simplify regmap initialization, and fix an regmap issue that
affected TI OMAP (LCR register would get clobbered due to
using the wrong offset for the MDR1 register) reported by Lwazi Dube
(who also found the root cause).
 1.91 11-Dec-2018  thorpej Add a convenience function, com_init_regs_stride(), that shifts the register
offsets and size by the specified amount. Use in front-ends as appropriate.
 1.90 08-Dec-2018  thorpej Remove the COM_REGMAP option -- just use it all the time. While here,
garbage-collect the COM_FUNCMAP and COM_AU1X00 options, as there are
not used anywhere.
 1.89 08-Dec-2018  thorpej Clean up initialization of com_regs structure, in preparation for
some additional changers.
 1.88 30-Nov-2018  jmcneill Add support for com(4) without an interrupt by setting the COM_HW_POLL flag
 1.87 27-May-2018  jmcneill branches: 1.87.2;
Rename COM_TYPE_SUNXI -> COM_TYPE_DW_APB
 1.86 04-Dec-2017  bouyer branches: 1.86.2;
Put back SUNXI definitions in the COM_REGMAP case; com.c uses them
without #ifdef COM_AWIN.
To be safe, expand the register map to 42 entries.
 1.85 04-Dec-2017  bouyer Make it clear that SUNXI registers are not defined/supported in the
COM_REGMAP case
 1.84 29-Oct-2017  jmcneill Make all of the COM_xxx type options runtime selectable. Kernel configs
with the existing options (COM_16650, COM_16750, COM_AWIN, COM_HAYESP, and
COM_PXA2X0) will select the correct type in com_attach_subr. New code
should specify the com type by passing COM_TYPE_xxx to comcnattach and/or
setting sc_type.
 1.83 31-Jul-2017  jmcneill Add COM_TYPE_BCMAUXUART type for BCM2835 AUX UART.
 1.82 27-May-2016  bouyer The UART in the allwiner SoCs is not full-compatible with the 16550, and
it's not a 16750 either. Like the 16750 it has the IIR_BUSY interrupt,
which is triggered when writing to LCR while the chip
can't accept it. But unlike the 16750, it has a specific register,
HALT, to allow writing to the LCR and divisor registers, and then
commit the changes.
Tested on an A20 SoC, changing the baud rate while keeping the
tty device open and incoming data.
 1.81 03-May-2015  jmcneill add COM_TYPE_TEGRA
 1.80 13-Apr-2015  riastradh Convert sys/dev to use <sys/rndsource.h>.
 1.79 22-Nov-2014  macallan branches: 1.79.2;
deal with quirk in Ingenic UARTs
( they have a bit in the FIFO control register which turns the entire
port off if not set )
 1.78 03-Oct-2013  kiyohara branches: 1.78.4;
Revirt 'Move the Marvell extension to com_mv.c' at Sun Sep 1 04:51:24 UTC 2013.
build test only.
 1.77 03-Sep-2013  jmcneill no EFR on tl16c750, use AFE bit on MCR reg instead for flow control
 1.76 01-Sep-2013  kiyohara Move the Marvell extension to com_mv.c.
 1.75 17-Jul-2013  soren Fix COM_16750 build for non-COM_REGMAP platforms.
 1.74 20-Apr-2013  rkujawa branches: 1.74.4; 1.74.6;
Add support for 16750 style UARTs. Activated by defining COM_16750.

Obtained from Marvell, Semihalf.
 1.73 02-Feb-2012  tls branches: 1.73.6;
Entropy-pool implementation move and cleanup.

1) Move core entropy-pool code and source/sink/sample management code
to sys/kern from sys/dev.

2) Remove use of NRND as test for presence of entropy-pool code throughout
source tree.

3) Remove use of RND_ENABLED in device drivers as microoptimization to
avoid expensive operations on disabled entropy sources; make the
rnd_add calls do this directly so all callers benefit.

4) Fix bug in recent rnd_add_data()/rnd_add_uint32() changes that might
have lead to slight entropy overestimation for some sources.

5) Add new source types for environmental sensors, power sensors, VM
system events, and skew between clocks, with a sample implementation
for each.

ok releng to go in before the branch due to the difficulty of later
pullup (widespread #ifdef removal and moved files). Tested with release
builds on amd64 and evbarm and live testing on amd64.
 1.72 19-Nov-2011  tls branches: 1.72.2;
First step of random number subsystem rework described in
<20111022023242.BA26F14A158@mail.netbsd.org>. This change includes
the following:

An initial cleanup and minor reorganization of the entropy pool
code in sys/dev/rnd.c and sys/dev/rndpool.c. Several bugs are
fixed. Some effort is made to accumulate entropy more quickly at
boot time.

A generic interface, "rndsink", is added, for stream generators to
request that they be re-keyed with good quality entropy from the pool
as soon as it is available.

The arc4random()/arc4randbytes() implementation in libkern is
adjusted to use the rndsink interface for rekeying, which helps
address the problem of low-quality keys at boot time.

An implementation of the FIPS 140-2 statistical tests for random
number generator quality is provided (libkern/rngtest.c). This
is based on Greg Rose's implementation from Qualcomm.

A new random stream generator, nist_ctr_drbg, is provided. It is
based on an implementation of the NIST SP800-90 CTR_DRBG by
Henric Jungheim. This generator users AES in a modified counter
mode to generate a backtracking-resistant random stream.

An abstraction layer, "cprng", is provided for in-kernel consumers
of randomness. The arc4random/arc4randbytes API is deprecated for
in-kernel use. It is replaced by "cprng_strong". The current
cprng_fast implementation wraps the existing arc4random
implementation. The current cprng_strong implementation wraps the
new CTR_DRBG implementation. Both interfaces are rekeyed from
the entropy pool automatically at intervals justifiable from best
current cryptographic practice.

In some quick tests, cprng_fast() is about the same speed as
the old arc4randbytes(), and cprng_strong() is about 20% faster
than rnd_extract_data(). Performance is expected to improve.

The AES code in src/crypto/rijndael is no longer an optional
kernel component, as it is required by cprng_strong, which is
not an optional kernel component.

The entropy pool output is subjected to the rngtest tests at
startup time; if it fails, the system will reboot. There is
approximately a 3/10000 chance of a false positive from these
tests. Entropy pool _input_ from hardware random numbers is
subjected to the rngtest tests at attach time, as well as the
FIPS continuous-output test, to detect bad or stuck hardware
RNGs; if any are detected, they are detached, but the system
continues to run.

A problem with rndctl(8) is fixed -- datastructures with
pointers in arrays are no longer passed to userspace (this
was not a security problem, but rather a major issue for
compat32). A new kernel will require a new rndctl.

The sysctl kern.arandom() and kern.urandom() nodes are hooked
up to the new generators, but the /dev/*random pseudodevices
are not, yet.

Manual pages for the new kernel interfaces are forthcoming.
 1.71 13-Nov-2010  uebayasi branches: 1.71.8;
Some missing sys/device.h dependencies.
 1.70 24-Feb-2010  dyoung branches: 1.70.2;
A pointer typedef entails trading too much flexibility to declare const
and non-const types, and the kernel uses both const and non-const
PMF qualifiers and device suspensors, so change the pmf_qual_t and
device_suspensor_t typedefs from "pointers to const" to non-pointer,
non-const types.
 1.69 08-Jan-2010  dyoung branches: 1.69.2;
Expand PMF_FN_* macros.
 1.68 12-Nov-2009  dyoung Delete definition of com_activate(), it's been removed.
 1.67 12-Nov-2009  dyoung Move the code in com_activate() to com_detach(), where it always
belonged. Remove com_activate().

Consolidate information about the console on com(4) in a new struct
comcons_info.

Support detachment & re-attachment of a system console on com(4).
Re-attachment is somehow incomplete. Ideally, if some other device
could take over as console, it would, but we're not quite there,
yet.
 1.66 27-May-2009  rjs Put back CVS header.
 1.65 12-May-2009  cegger struct device * -> device_t, no functional changes intended.
 1.64 03-May-2009  tsutsui Make COM_RING_SIZE configurable by kernel config(5).
 1.63 24-Oct-2008  matt branches: 1.63.8;
Add support for 16550 chips without an Enhanced Register Set.
 1.62 28-Apr-2008  matt branches: 1.62.6;
More forgotten changes from matt-armv6.
 1.61 14-Mar-2008  cube branches: 1.61.2; 1.61.4;
Split device_t and softc for all com(4) devices (well, everything that
uses a com_softc backend). Use proper types and ansify where appropriate.
 1.60 29-Feb-2008  dyoung Use pmf_device_register1() instead of shutdownhook_establish() to
register com_cleanup() as the shutdown hook.

Add a generic suspend routine. Suspend and resume com@isa.

Protect against dereferencing a NULL softc in comioctl().

Destroy both a mutex and a callout in com_detach().

Cosmetic: use aprint_*_dev(). Use PMF_FN_ARGS, PMF_FN_PROTO.
 1.59 20-Jan-2008  joerg branches: 1.59.2; 1.59.6;
Now that __HAVE_TIMECOUNTER and __HAVE_GENERIC_TODR are invariants,
remove the conditionals and the code associated with the undef case.
 1.58 14-Dec-2007  dyoung Add a resume handler for com@isa, using Jared McNeill's suggested
code from current-users. com@acpi, et cetera, remain to be done.
 1.57 17-Oct-2007  ad branches: 1.57.4; 1.57.6; 1.57.10;
Make it build without IPL_SERIAL.
 1.56 08-Oct-2007  ad Merge from vmlocking: use mutexes and the softint API.
 1.55 14-Jul-2007  ad branches: 1.55.6; 1.55.8; 1.55.10;
Generic soft interrupts are mandatory.
 1.54 13-Jul-2006  gdamore branches: 1.54.14;
Add an option COM_REGMAP to allow com(4) to use an array of register indices.
This allows us to convert aucom to just another com attachment, and cleanup
some code in the com_arbus.c.

Additionally, we use a common com_cleanup routine rather than having a
zillion copies of it in the attachment points.

This has been tested on a number architectures, and it has been shown to get
close to comparable performance when COM_REGMAP is defined, and comparable
when it is not defined.

Approved by core@. Fixes PR port-evbmips/32362.
 1.53 25-Jun-2006  perry Add a power hook for the com device.
 1.52 07-Jun-2006  kardel branches: 1.52.2;
merge FreeBSD timecounters from branch simonb-timecounters
- struct timeval time is gone
time.tv_sec -> time_second
- struct timeval mono_time is gone
mono_time.tv_sec -> time_uptime
- access to time via
{get,}{micro,nano,bin}time()
get* versions are fast but less precise
- support NTP nanokernel implementation (NTP API 4)
- further reading:
Timecounter Paper: http://phk.freebsd.dk/pubs/timecounter.pdf
NTP Nanokernel: http://www.eecis.udel.edu/~mills/ntp/html/kern.html
 1.51 05-Mar-2006  christos branches: 1.51.6;
cleanup more SET/CLR/ISSET lossage
 1.50 27-Dec-2005  chs branches: 1.50.4; 1.50.6; 1.50.8;
remove the COM_MPLOCK option. always include the spinlock in the softc
and always call the simple_* locking functions. the locking functions
are compiled out if they are not needed anyway, so a separate option
for this doesn't gain anything.

this also fixes the serial console on my alpha ES40 (which doesn't make much
sense since the com driver should still be under the big lock on alpha,
but whatever).
 1.49 11-Dec-2005  christos merge ktrace-lwp.
 1.48 04-Feb-2005  perry branches: 1.48.6;
de-__P
 1.47 08-Nov-2003  simonb branches: 1.47.8; 1.47.10;
Add (as yet unused) COM_TYPE_AU1x00.
 1.46 14-Jun-2003  thorpej branches: 1.46.2;
Also pass a type argument to comcnattach() and com_kgdb_attach().
comspeed() (and thus cominit()) may need this information.
 1.45 14-Jun-2003  thorpej Introduce a new "type" field in the softc which is used to indicate
the general UART type. Currently, we have "normal", "hayesp" and
"pxa2x0" types. Replace the corresponding hw flags with the new type
values.
 1.44 05-Jun-2003  scw Add support, via a kernel config file option, for the 16550-compatible
com ports found on Intel PXA2x0 processors.

Re-arrange the code which detects the FIFO configuration to defer
printing until _after_ com_fifo is cleared. Some supposedly compatible
chips clear the Tx/Rx FIFOs when this happens, resulting in previous
output being lost.
 1.43 12-Apr-2002  thorpej * Add a new hwflag, COM_HW_NO_TXPRELOAD, which tells comstart() to
not pre-load the chip's Tx buffer, but instead waits for the Tx Ready
interrupt to transmit the first chunk of data.
* On the IOP310, set COM_HW_NO_TXPRELOAD, rather than COM_HW_TXFIFO_DISABLE.

This solves the "UART hangs" problem on the Npwr in a nicer way (i.e. we
get to use the FIFO, whee). The COM_HW_NO_TXPRELOAD happens to match the
Linux 16550 driver's Tx algorithm, and the "UART hang" was never observed
on the Npwr running Linux.

Eventually, we might want to eliminate the COM_HW_NO_TXPRELOAD, and simply
always use its algorithm. But it should be tested on more 16x50 variants
before we do that.

Kudos to Valeriy Ushakov <uwe@netbsd.org> for pointing out this solution
(which also happens to fix the stray UART interrupt issue on the Krups
Javastation), and to Allen Briggs <briggs@netbsd.org> for experimenting
with various methods of fixing this.
 1.42 27-Aug-2001  enami For hayes esp card, set prescaler if specified rate is grater than 115200.
 1.41 22-Aug-2001  simonb Cosmetic cleanups:
- cominit() is local to com.c, remove prototype from comvar.h.
- Don't prototype comstop(), cdev_decl(com) does this.
- Don't use a block device switch table declaration(!).
- No need to include "com.h".
 1.40 30-May-2001  lukem branches: 1.40.2;
add missing #include "opt_kgdb.h"
 1.39 14-Jan-2001  thorpej branches: 1.39.2;
Rename __GENERIC_SOFT_INTERRUPTS to __HAVE_GENERIC_SOFT_INTERRUPTS,
and place the definition in <machine/types.h>. This can now be used
as a flag to indicate whether or not <machine/intr.h> can be included
to get the generic soft interrupt API.
 1.38 07-Jan-2001  sommerfeld Make certain we see COM_MPLOCK, MULTIPROCESSOR, and LOCKDEBUG
to avoid any confusion about whether or not we have a lock in the softc.
 1.37 06-Oct-2000  nathanw Change int->bus_addr_t in com_kgdb_attach() prototype.
Compiles again with KGDB enabled.
 1.36 23-Sep-2000  sommerfeld Add `COM_MPLOCK' option to use a device-instance-specific spinlocks
when running at splserial(). This is a temporary measure (until
there's a MP-safe interrupt handling structure); until then, it should
be used when MULTIPROCESSOR and IPL_SERIAL > IPL_SCHED.
 1.35 23-Sep-2000  bjh21 paddr_t -> bus_addr_t in prototypes too.
 1.34 22-Sep-2000  eeh paddr_t -> bus_addr_t.
 1.33 21-Sep-2000  eeh Support for SPARC machines with `su' devices.
 1.32 23-Mar-2000  thorpej New callout mechanism with two major improvements over the old
timeout()/untimeout() API:
- Clients supply callout handle storage, thus eliminating problems of
resource allocation.
- Insertion and removal of callouts is constant time, important as
this facility is used quite a lot in the kernel.

The old timeout()/untimeout() API has been removed from the kernel.
 1.31 23-Jan-2000  soda kluge to make this work with NEC M403 (arc/magnum).
 1.30 03-Feb-1999  mycroft branches: 1.30.8;
Slight redux in PPS code.
 1.29 18-Nov-1998  thorpej Add support for detaching "com" instances.
 1.28 21-Sep-1998  matt Add softserial to the alpha port. This significantly improved PPP
throughput on com ports.
 1.27 16-Sep-1998  is Garbage collect unused 3rd parameter to comprobe1().
 1.26 11-Sep-1998  jonathan Add arc as a target platform.
 1.25 05-Sep-1998  mark arm32 now supports soft serial interrupts.
 1.24 11-Jun-1998  thorpej Pull in <sys/timepps.h> here so that other things that include comvar.h
will compile.
 1.23 10-Jun-1998  jonathan PPS support from April, reworked and extended to match the PPS-API
Internet Draft (draft-mogul-pps-api-02.txt).
 1.22 02-Feb-1998  cgd change #ifdefs keying on "alpha" to key on "__NO_SOFT_SERIAL_INTERRUPT"
instead, and define that on NetBSD/alpha and NetBSD/arm32.
 1.21 02-Feb-1998  cgd Implement a flag to indicate that the driver attached correctly.
This is useful in the case where an attachment's probe routine
verifies that there is indeed hardware present but something goes
"wrong" in the attach causing the device to be unusable. (Without
keeping track of this, in that case incorrect ports could be
accessed or uninitted pointers could be deferenced on open or at
other times.)
 1.20 01-Feb-1998  marc add power management hooks to softc
 1.19 03-Nov-1997  mycroft Mostly cosmetic and performance changes:
* Make the ring buffer size and water marks patchable, and allocate the buffer
separately.
* Do the ttymalloc() at attach time.
* Reorganize the receive buffer so the status and data pair are next to each
other. This is slightly faster.
* Make sure we actually do turn off interrupts in comclose() if we have DDB
configured and it's not the console. (D'oh!!!!)
* When we exhaust the current transmit run, turn off transmit interrupts in
comintr(), so we're fairly sure we don't get another one.
* Nuke the silly lsrmap[] idea; it's slower in the normal case.
* Cache the l_rint pointer in the soft interrupt routine.
 1.18 19-Oct-1997  fvdl branches: 1.18.2;
Add 16650 hardware flowcontrol support. Basically PR 3844 from
Dave Huang <khym@bga.com>, with added check for broken early versions
of the 16650, taken from the Linux driver.

This should be extended to use, for example, higher trigger levels for
the bigger 16650 FIFO, and its capability for using a smaller divisor
and thus higher speeds. But this patch is very useful for 16650 users
already.
 1.17 19-Oct-1997  explorer Add hooks for entropy collection. Right now, you must place
options RND_COM
in your kernel config file (along with the
pseudo-device rnd
line) to enable this. If results are positive, I will make this enabled
by default.
 1.16 15-Oct-1997  thorpej branches: 1.16.2;
Pulldown from marc-pcmcia branch.
 1.15 16-Sep-1997  is Support for the upcoming NetBSD/Amiga Hypercom driver family:
* support chip clocks != COM_FREQ, by introducing sc_frequency (for the
mainline code) and adding a frequency parameter right after the rate
parameter to comcnattach() and com_kgdb_attach().
- Make com_isa and com_multi initialize sc_frequency to COM_FREQ.
- Make i386/machdep.c and alpha/dec_xxx.c call com*attach() with the freq.
parameter.
* supio_attach_args get two more fields: a sc_ipl and a sc_arg, both ints.
- com_supio uses the first for interupt establishment (all childs will, as
soon as they exist) and the 2nd for sc_frequency.
- drsupio passes sc_ipl alway as 5, and for the "com"s, sc_arg as 16*115200
- hyper will pass sc_ipl as 6, and sc_arg as 16 * 460800
 1.14 23-Aug-1997  drochner clean up the serial console / KGDB attachment:
-put all early console / KGDB initialization into 1 exported function
(com_*_attach()) each, dont use global variables anymore
-use the passed tcflag_t for port settings instead of hardwiring 8N1
-at autoconfiguration attach time, decide if the attaching device is
already console / KGDB by comparing bus tag and base addr (cgd's wish)
-export a function "com_is_console()" for use by driver frontends for
this comparision
-delay setting of cn_tab->cn_dev until autoconfiguration attach
to get the minor number right
-delete unused comcnprobe() and comcninit()
 1.13 14-Aug-1997  drochner -Export variables needed for system console initialization.
-Enable line break interrupt for DDB on a serial console.
-Share initialization code between DDB and KGDB.
 1.12 12-Aug-1997  drochner KGDB improvements:
-Separate KGDB port initialization and softc related stuff to allow
KGDB to be attached in early system startup, before autoconfiguration.
-Export the variables needed by md code to hand-craft bus tag/handle.
-Fix initialization to enable interrupt by line break.
-Call DDB/KGDB at line break (move DDB call from the softirq handler
to the hard handler because it should work without a tty attached too).
 1.11 05-Jul-1997  thorpej branches: 1.11.2;
Add support for remote serial KGDB.
 1.10 15-Jun-1997  mycroft Implement a better backpressure mechanism so that data is collected
in the driver's buffer if the tty buffer is full. If the driver's buffer
becomes full, turn off receive interrupts until it drains a bit.
 1.9 24-May-1997  thorpej Where _is_ that brick when you need it?!
 1.8 04-Apr-1997  mycroft New version of com driver. Uses a different queueing mechanism and a split
hardware/software interrupt mechanism for improved performance. Many odd
protocols bugs also fixed.
 1.7 13-Nov-1996  cgd move cominit() prototype to comvar.h, so that ports which use 'com'
for serial console, but don't use the (i386-specific)
comcninit()/comcnprobe() functions, can do the right thing.
 1.6 21-Oct-1996  thorpej New bus.h implementation/interface:
- No more distinction between i/o-mapped and memory-mapped
devices. It's all "bus space" now, and space tags
differentiate the space with finer grain than the
bus chipset tag.
- Add memory barrier methods.
- Implement space alloc/free methods.
- Implement region read/write methods (like memcpy to/from
bus space).
This interface provides a better abstraction for dealing with
machine-independent chipset drivers.
 1.5 05-May-1996  christos Move comintr() prototype to comvar.h; needed by the multi-port cards.
 1.4 15-Apr-1996  cgd define and export the global variable "comconscflag", the default tty
'cflag' for the console. Normally set to TTYDEF_CFLAG, may be
overridden by machine-dependent console attachment code, as necessary.
(Alpha uses it to set cs8 -parenb.) Files including comvar.h now
need to include <sys/termios.h>, because comconscflag is of type
tcflag_t.
 1.3 10-Mar-1996  cgd convert these to use new <machine/bus.h> interfaces. This involved
substantial reworking of the multi-port drivers, as they need to frob
bits in the io-port spaces of their children. As a result, the
commulti->com attachment interface is substantially more complex.
(This may be fixable in the future by making some of the code common,
but as long as io-port allocation checking is planned, it's necessary.)
 1.2 09-Mar-1996  cgd Fix copyright year
 1.1 09-Mar-1996  cgd define the common structure used to attach 'com' units as slaves to
multiport cards. prototype comprobe1(), which is used by multiport card
drivers.
 1.11.2.5 15-Oct-1997  thorpej Move a few bus-specific things into bus-specific softc structures and
nesting a com_softc within them.
 1.11.2.4 22-Sep-1997  thorpej Update marc-pcmcia branch from trunk.
 1.11.2.3 27-Aug-1997  thorpej Update marc-pcmcia branch from trunk.
 1.11.2.2 23-Aug-1997  thorpej Update marc-pcmcia branch from trunk.
 1.11.2.1 30-Jul-1997  marc added pcmcia infrastructure and a few devices
 1.16.2.2 16-Oct-1997  thorpej Sync w/ trunk.
 1.16.2.1 15-Oct-1997  thorpej file comvar.h was added on branch marc-pcmcia on 1997-10-16 00:04:18 +0000
 1.18.2.1 04-Nov-1997  mellon Pull rev 1.19 up from trunk (mycroft)
 1.30.8.2 18-Jan-2001  bouyer Sync with head (for UBC+NFS fixes, mostly).
 1.30.8.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.39.2.3 17-Apr-2002  nathanw Catch up to -current.
 1.39.2.2 21-Sep-2001  nathanw Catch up to -current.
 1.39.2.1 21-Jun-2001  nathanw Catch up to -current.
 1.40.2.3 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.40.2.2 13-Sep-2001  thorpej Update the kqueue branch to HEAD.
 1.40.2.1 25-Aug-2001  thorpej Merge Aug 24 -current into the kqueue branch.
 1.46.2.4 04-Feb-2005  skrll Sync with HEAD.
 1.46.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.46.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.46.2.1 03-Aug-2004  skrll Sync with HEAD
 1.47.10.1 12-Feb-2005  yamt sync with head.
 1.47.8.1 29-Apr-2005  kent sync with -current
 1.48.6.6 17-Mar-2008  yamt sync with head.
 1.48.6.5 21-Jan-2008  yamt sync with head
 1.48.6.4 27-Oct-2007  yamt sync with head.
 1.48.6.3 03-Sep-2007  yamt sync with head.
 1.48.6.2 30-Dec-2006  yamt sync with head.
 1.48.6.1 21-Jun-2006  yamt sync with head.
 1.50.8.3 11-Aug-2006  yamt sync with head
 1.50.8.2 26-Jun-2006  yamt sync with head.
 1.50.8.1 13-Mar-2006  yamt sync with head.
 1.50.6.2 22-Apr-2006  simonb Sync with head.
 1.50.6.1 04-Feb-2006  simonb Adapt for timecounters and newer PPS API.
 1.50.4.1 09-Sep-2006  rpaulo sync with head
 1.51.6.1 19-Jun-2006  chap Sync with head.
 1.52.2.6 13-Jul-2006  gdamore Merge from HEAD.
 1.52.2.5 17-Jun-2006  gdamore Yes, I'm restoring COM_INIT_REGS and removing the compatibility #define's
for sc_iot and friends. Those defines break things, like say ast.c, where
comvar.h is included, but a local sc_iot structure member is also used.
 1.52.2.4 17-Jun-2006  gdamore Per tsutsui@, I'm removing COM_INIT_REGS, and adding a flag to make the
map initialization automatic. This breaks this whole tree again, so I pretty
much have to start over going back thru old code to make it all compatible.
 1.52.2.3 16-Jun-2006  gdamore "make the \'s pretty". hi simon.
 1.52.2.2 16-Jun-2006  gdamore KNF per simonb@ consisting of:
regs.xx -> regs.cr_xxx
wrap COM_INIT_REGS body with do { } while (0);)
Convert INB/OUTB macros to CSR_READ/CSR_WRITE macros per tsutsui@.
 1.52.2.1 15-Jun-2006  gdamore Initial com framework changes. These changes bust *all* com consumers, but
follow-up commits shortly will fix many of them, so that i386, sparc, and
some evbmips ports at least work.
 1.54.14.2 23-Oct-2007  ad Sync with head.
 1.54.14.1 01-Jul-2007  ad - Generic soft interrupts are mandatory, remove the kludges.
- Adapt to callout API change.
- Use mutexes.
 1.55.10.2 18-Oct-2007  yamt sync with head.
 1.55.10.1 14-Oct-2007  yamt sync with head.
 1.55.8.4 23-Mar-2008  matt sync with HEAD
 1.55.8.3 09-Jan-2008  matt sync with HEAD
 1.55.8.2 06-Nov-2007  matt sync with HEAD
 1.55.8.1 29-Oct-2007  matt Add support for OMAP specific com type.
 1.55.6.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.57.10.2 23-Jan-2008  bouyer Sync with HEAD.
 1.57.10.1 02-Jan-2008  bouyer Sync with HEAD
 1.57.6.1 26-Dec-2007  ad Sync with head.
 1.57.4.1 18-Feb-2008  mjf Sync with HEAD.
 1.59.6.3 17-Jan-2009  mjf Sync with HEAD.
 1.59.6.2 02-Jun-2008  mjf Sync with HEAD.
 1.59.6.1 03-Apr-2008  mjf Sync with HEAD.
 1.59.2.1 24-Mar-2008  keiichi sync with head.
 1.61.4.5 11-Mar-2010  yamt sync with head
 1.61.4.4 20-Jun-2009  yamt sync with head
 1.61.4.3 16-May-2009  yamt sync with head
 1.61.4.2 04-May-2009  yamt sync with head.
 1.61.4.1 16-May-2008  yamt sync with head.
 1.61.2.1 18-May-2008  yamt sync with head.
 1.62.6.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.63.8.2 23-Jul-2009  jym Sync with HEAD.
 1.63.8.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.69.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.70.2.1 05-Mar-2011  rmind sync with head
 1.71.8.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.71.8.1 17-Apr-2012  yamt sync with head
 1.72.2.1 18-Feb-2012  mrg merge to -current.
 1.73.6.3 03-Dec-2017  jdolecek update from HEAD
 1.73.6.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.73.6.1 23-Jun-2013  tls resync from head
 1.74.6.1 23-Jul-2013  riastradh sync with HEAD
 1.74.4.2 18-May-2014  rmind sync with head
 1.74.4.1 28-Aug-2013  rmind sync with head
 1.78.4.1 22-Jun-2016  snj Pull up following revision(s) (requested by bouyer in ticket #1178):
sys/arch/arm/allwinner/files.awin: revision 1.36
sys/conf/files: revision 1.1159
sys/dev/ic/com.c: revision 1.339
sys/dev/ic/comreg.h: revision 1.25
sys/dev/ic/comvar.h: revision 1.82
sys/dev/ic/ns16550reg.h: revision 1.11
The UART in the allwiner SoCs is not full-compatible with the 16550, and
it's not a 16750 either. Like the 16750 it has the IIR_BUSY interrupt,
which is triggered when writing to LCR while the chip
can't accept it. But unlike the 16750, it has a specific register,
HALT, to allow writing to the LCR and divisor registers, and then
commit the changes.
Tested on an A20 SoC, changing the baud rate while keeping the
tty device open and incoming data.
 1.79.2.3 28-Aug-2017  skrll Sync with HEAD
 1.79.2.2 29-May-2016  skrll Sync with HEAD
 1.79.2.1 06-Jun-2015  skrll Sync with HEAD
 1.86.2.3 18-Jan-2019  pgoyette Synch with HEAD
 1.86.2.2 26-Dec-2018  pgoyette Sync with HEAD, resolve a few conflicts
 1.86.2.1 25-Jun-2018  pgoyette Sync with HEAD
 1.87.2.1 10-Jun-2019  christos Sync with HEAD
 1.92.14.1 03-Apr-2021  thorpej Sync with HEAD.
 1.92.12.1 03-Apr-2021  thorpej Sync with HEAD.
 1.24 25-Sep-2022  thorpej Remove unnecessary include of <sys/malloc.h>.
 1.23 07-Aug-2021  thorpej Merge thorpej-cfargs2.
 1.22 24-Apr-2021  thorpej branches: 1.22.8;
Merge thorpej-cfargs branch:

Simplify and make extensible the config_search() / config_found() /
config_attach() interfaces: rather than having different variants for
which arguments you want pass along, just have a single call that
takes a variadic list of tag-value arguments.

Adjust all call sites:
- Simplify wherever possible; don't pass along arguments that aren't
actually needed.
- Don't be explicit about what interface attribute is attaching if
the device only has one. (More simplification.)
- Add a config_probe() function to be used in indirect configuiration
situations, making is visibly easier to see when indirect config is
in play, and allowing for future change in semantics. (As of now,
this is just a wrapper around config_match(), but that is an
implementation detail.)

Remove unnecessary or redundant interface attributes where they're not
needed.

There are currently 5 "cfargs" defined:
- CFARG_SUBMATCH (submatch function for direct config)
- CFARG_SEARCH (search function for indirect config)
- CFARG_IATTR (interface attribte)
- CFARG_LOCATORS (locators array)
- CFARG_DEVHANDLE (devhandle_t - wraps OFW, ACPI, etc. handles)

...and a sentinel value CFARG_EOL.

Add some extra sanity checking to ensure that interface attributes
aren't ambiguous.

Use CFARG_DEVHANDLE in MI FDT, OFW, and ACPI code, and macppc and shark
ports to associate those device handles with device_t instance. This
will trickle trough to more places over time (need back-end for pre-OFW
Sun OBP; any others?).
 1.21 07-Jul-2020  thorpej branches: 1.21.4;
Overhaul the interface to pci_configure_bus():
- Don't expose how PCI bus configuration resource management is implemented.
Provide a new resource provider API:

==> pciconf_resource_init() -- Initialize a PCI configuration resources
container.
==> pciconf_resource_add() -- Add a PCI configuration resource to the
container (I/O, MEM, or prefetchable MEM). Multiple resources of
each type may be added.
==> pciconf_resource_fini() -- Tear down the PCI configurtation resources
container once the bus has been configured.

This is much easier to use than the previous method of providing an
extent map for each kind of resource, and works better for e.g. ACPI
platforms that provide potentially multiple PCI resources in tables
provided by firmware.

- Re-implement PCI configuration resource management using vmem arenas,
rather than extent maps.
 1.20 14-Jun-2020  chs replace EX_NOWAIT with EX_WAITOK in device attach methods.
remove checks for failures that can no longer occur.
 1.19 27-Jan-2012  para converting extent(9) from malloc(9) to kmem(9)
preceding kmem-vmem-pool-uvm patch

releng@ acknowledged
 1.18 17-May-2011  dyoung branches: 1.18.4; 1.18.8;
PCI_FLAGS_IO_ENABLED and PCI_FLAGS_MEM_ENABLED changed their functional
role in NetBSD (drivers are no longer supposed to write these to
pa_flags) without changing name. Correct that.

Rename PCI_FLAGS_IO_ENABLED to PCI_FLAGS_IO_OKAY and
PCI_FLAGS_MEM_ENABLED to PCI_FLAGS_MEM_OKAY, thus making their names
consistent with the other PCI flags and poisoning 3rd-party driver
sources that use the flags in the old bad way.

This patch produces no binary changes in this set of PCI kernels when
they are compiled w/o 'options DIAGNOSTIC' and w/ -V MKREPRO=yes:

algor P4032 P5064 P6032
alpha GENERIC
amd64 GENERIC XEN3_DOM0
arc GENERIC
atari HADES MILAN-PCIIDE
bebox GENERIC
cats GENERIC
cobalt GENERIC
evbarm-el ADI_BRH ARMADILLO9 CP3100 GEMINI GEMINI_MASTER GEMINI_SLAVE
evbarm-el GUMSTIX HDL_G IMX31LITE INTEGRATOR IQ31244 IQ80310 IQ80321
evbarm-el IXDP425 IXM1200 KUROBOX_PRO
evbarm-el LUBBOCK MARVELL_NAS NAPPI NSLU2 SHEEVAPLUG SMDK2800 TEAMASA_NPWR
evbarm-el TEAMASA_NPWR_FC TS7200 TWINTAIL ZAO425
evbmips-el AP30 DBAU1500 DBAU1550 MALTA MERAKI MTX-1 OMSAL400 RB153 WGT624V3
evbmips64-el XLSATX
evbppc EV64260 MPC8536DS MPC8548CDS OPENBLOCKS200 OPENBLOCKS266
evbppc OPENBLOCKS266_OPT P2020RDB PMPPC RB800 WALNUT
hp700 GENERIC
i386 ALL XEN3_DOM0 XEN3_DOMU
ibmnws GENERIC
iyonix GENERIC
landisk GENERIC
macppc GENERIC
mvmeppc GENERIC
netwinder GENERIC
ofppc GENERIC
prep GENERIC
sandpoint GENERIC
sbmips-el GENERIC
sgimips GENERIC32_IP2x GENERIC32_IP3x
sparc GENERIC_SUN4U KRUPS
sparc64 GENERIC
 1.17 10-Dec-2010  matt branches: 1.17.2;
When attaching a PCI bus, the pci chipset is not optional.
 1.16 12-May-2009  cegger branches: 1.16.4;
struct device * -> device_t, no functional changes intended.
 1.15 12-May-2009  cegger struct cfdata * -> cfdata_t, no functional changes intended.
 1.14 28-Apr-2008  martin branches: 1.14.14; 1.14.22;
Remove clause 3 and 4 from TNF licenses
 1.13 08-Apr-2008  cegger branches: 1.13.2; 1.13.4;
use aprint_*_dev and device_xname
 1.12 19-Oct-2007  ad branches: 1.12.16;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.11 11-Dec-2005  christos branches: 1.11.30; 1.11.44; 1.11.46; 1.11.50;
merge ktrace-lwp.
 1.10 26-Aug-2005  drochner s/locdesc_t/int/g
 1.9 27-Feb-2005  perry branches: 1.9.4;
nuke trailing whitespace
 1.8 30-Aug-2004  drochner branches: 1.8.4; 1.8.6;
Phase out the use of a string as first "attach args" member to control
which bustype should be attached with a specific call to config_found()
(from a "mainbus" or a bus bridge).
Do it for isa/eisa/mca and pci/agp for now. These buses all attach to
an mi interface attribute "isabus", "eisabus" etc., and the autoconf
framework now allows to specify an interface attribute on config_found()
and config_search(), which limits the search of matching config data
to these which attach to that specific attribute.
So we basically have to call config_found_ia(..., "foobus", ...) where
such a bus is attached.
As a consequence, where a "mainbus" or alike also attaches other
devices (eg CPUs) which do not attach to a specific attribute yet,
we need at least pass an attribute name (different from "foobus") so
that the foo bus is not found at these places. This made some minor
changes necessary which are not obviously related to the mentioned buses.
 1.7 07-Nov-2003  augustss Program some bridge options.
 1.6 14-Jul-2003  lukem add missing __KERNEL_RCSID()
 1.5 01-Jan-2003  thorpej branches: 1.5.2;
Use aprint_normal() in cfprint routines.
 1.4 27-Sep-2002  thorpej Introduce a new routine, config_match(), which invokes the
cfattach->ca_match function in behalf of the caller. Use it
rather than invoking cfattach->ca_match directly.
 1.3 30-Jul-2002  augustss Remove warning about PCI bus configuration being broken since it
works now.
 1.2 13-Jun-2002  augustss branches: 1.2.2; 1.2.4;
Use consistent naming.
 1.1 21-May-2002  augustss branches: 1.1.4;
Add a driver for the IBM CPC700 chip. This chip is a host bridge for
PowerPC and provides a PCI-host bridge, interrupt controller, two com ports,
two IIC ports, a timer, and a DRAM controller.
The driver supports PCI, interrupts and com ports.
 1.1.4.4 29-Aug-2002  gehenna catch up with -current.
 1.1.4.3 20-Jun-2002  gehenna catch up with -current.
 1.1.4.2 30-May-2002  gehenna Catch up with -current.
 1.1.4.1 21-May-2002  gehenna file cpc700.c was added on branch gehenna-devsw on 2002-05-30 14:45:32 +0000
 1.2.4.4 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.2.4.3 06-Sep-2002  jdolecek sync kqueue branch with HEAD
 1.2.4.2 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.2.4.1 13-Jun-2002  jdolecek file cpc700.c was added on branch kqueue on 2002-06-23 17:46:17 +0000
 1.2.2.5 03-Jan-2003  thorpej Sync with HEAD.
 1.2.2.4 18-Oct-2002  nathanw Catch up to -current.
 1.2.2.3 01-Aug-2002  nathanw Catch up to -current.
 1.2.2.2 20-Jun-2002  nathanw Catch up to -current.
 1.2.2.1 13-Jun-2002  nathanw file cpc700.c was added on branch nathanw_sa on 2002-06-20 03:44:30 +0000
 1.5.2.6 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.5.2.5 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.5.2.4 21-Sep-2004  skrll Fix the sync with head I botched.
 1.5.2.3 18-Sep-2004  skrll Sync with HEAD.
 1.5.2.2 03-Sep-2004  skrll Sync with HEAD
 1.5.2.1 03-Aug-2004  skrll Sync with HEAD
 1.8.6.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.8.4.1 29-Apr-2005  kent sync with -current
 1.9.4.2 27-Oct-2007  yamt sync with head.
 1.9.4.1 21-Jun-2006  yamt sync with head.
 1.11.50.1 25-Oct-2007  bouyer Sync with HEAD.
 1.11.46.1 06-Nov-2007  matt sync with HEAD
 1.11.44.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.11.30.1 23-Oct-2007  ad Sync with head.
 1.12.16.1 02-Jun-2008  mjf Sync with HEAD.
 1.13.4.2 16-May-2009  yamt sync with head
 1.13.4.1 16-May-2008  yamt sync with head.
 1.13.2.1 18-May-2008  yamt sync with head.
 1.14.22.1 07-Jan-2011  matt pci_chipset_tag_t can't be NULL.
 1.14.14.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.16.4.2 31-May-2011  rmind sync with head
 1.16.4.1 05-Mar-2011  rmind sync with head
 1.17.2.1 06-Jun-2011  jruoho Sync with HEAD.
 1.18.8.1 18-Feb-2012  mrg merge to -current.
 1.18.4.1 17-Apr-2012  yamt sync with head
 1.21.4.2 02-Apr-2021  thorpej config_found_ia() -> config_found() w/ CFARG_IATTR.
 1.21.4.1 22-Mar-2021  thorpej Mechanical conversion of config_found_sm_loc() -> config_found().
CFARG_IATTR usage needs to be audited.
 1.22.8.1 04-Aug-2021  thorpej Adapt to CFARGS().
 1.5 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.4 11-Dec-2005  christos branches: 1.4.70; 1.4.72; 1.4.74;
merge ktrace-lwp.
 1.3 07-Nov-2003  augustss Add some more defines.
 1.2 23-Jan-2003  augustss branches: 1.2.2;
Add processor interface register definitions.
 1.1 21-May-2002  augustss branches: 1.1.4; 1.1.6; 1.1.8;
Add a driver for the IBM CPC700 chip. This chip is a host bridge for
PowerPC and provides a PCI-host bridge, interrupt controller, two com ports,
two IIC ports, a timer, and a DRAM controller.
The driver supports PCI, interrupts and com ports.
 1.1.8.2 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.1.8.1 21-May-2002  jdolecek file cpc700reg.h was added on branch kqueue on 2002-06-23 17:46:17 +0000
 1.1.6.2 20-Jun-2002  nathanw Catch up to -current.
 1.1.6.1 21-May-2002  nathanw file cpc700reg.h was added on branch nathanw_sa on 2002-06-20 03:44:30 +0000
 1.1.4.2 30-May-2002  gehenna Catch up with -current.
 1.1.4.1 21-May-2002  gehenna file cpc700reg.h was added on branch gehenna-devsw on 2002-05-30 14:45:33 +0000
 1.2.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.2.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.2.2.1 03-Aug-2004  skrll Sync with HEAD
 1.4.74.1 16-May-2008  yamt sync with head.
 1.4.72.1 18-May-2008  yamt sync with head.
 1.4.70.1 02-Jun-2008  mjf Sync with HEAD.
 1.4 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.3 11-Dec-2005  christos branches: 1.3.70; 1.3.72; 1.3.74;
merge ktrace-lwp.
 1.2 08-Jul-2003  itojun function prototype must not have variable name
 1.1 21-May-2002  augustss branches: 1.1.4; 1.1.6; 1.1.8; 1.1.14;
Add a driver for the IBM CPC700 chip. This chip is a host bridge for
PowerPC and provides a PCI-host bridge, interrupt controller, two com ports,
two IIC ports, a timer, and a DRAM controller.
The driver supports PCI, interrupts and com ports.
 1.1.14.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.1.14.2 18-Sep-2004  skrll Sync with HEAD.
 1.1.14.1 03-Aug-2004  skrll Sync with HEAD
 1.1.8.2 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.1.8.1 21-May-2002  jdolecek file cpc700uic.h was added on branch kqueue on 2002-06-23 17:46:17 +0000
 1.1.6.2 20-Jun-2002  nathanw Catch up to -current.
 1.1.6.1 21-May-2002  nathanw file cpc700uic.h was added on branch nathanw_sa on 2002-06-20 03:44:30 +0000
 1.1.4.2 30-May-2002  gehenna Catch up with -current.
 1.1.4.1 21-May-2002  gehenna file cpc700uic.h was added on branch gehenna-devsw on 2002-05-30 14:45:34 +0000
 1.3.74.1 16-May-2008  yamt sync with head.
 1.3.72.1 18-May-2008  yamt sync with head.
 1.3.70.1 02-Jun-2008  mjf Sync with HEAD.
 1.2 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.1 21-May-2002  augustss branches: 1.1.4; 1.1.6; 1.1.8; 1.1.112; 1.1.114; 1.1.116;
Add a driver for the IBM CPC700 chip. This chip is a host bridge for
PowerPC and provides a PCI-host bridge, interrupt controller, two com ports,
two IIC ports, a timer, and a DRAM controller.
The driver supports PCI, interrupts and com ports.
 1.1.116.1 16-May-2008  yamt sync with head.
 1.1.114.1 18-May-2008  yamt sync with head.
 1.1.112.1 02-Jun-2008  mjf Sync with HEAD.
 1.1.8.2 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.1.8.1 21-May-2002  jdolecek file cpc700var.h was added on branch kqueue on 2002-06-23 17:46:18 +0000
 1.1.6.2 20-Jun-2002  nathanw Catch up to -current.
 1.1.6.1 21-May-2002  nathanw file cpc700var.h was added on branch nathanw_sa on 2002-06-20 03:44:31 +0000
 1.1.4.2 30-May-2002  gehenna Catch up with -current.
 1.1.4.1 21-May-2002  gehenna file cpc700var.h was added on branch gehenna-devsw on 2002-05-30 14:45:35 +0000
 1.5 21-Dec-2017  macallan overhaul the dbri driver and make it work again in the New Order Of Things
- fix switching between control and data mode
- make sure interrupts can happen in control mode
- implement audioif.commit_settings()
- switch to control mode only if needed - for changes in sample rate or format
but not for things like volume control
should fix PR 52786
 1.4 05-May-2008  jmcneill branches: 1.4.62; 1.4.80;
Use 2-clause license.
 1.3 14-Mar-2007  macallan branches: 1.3.32; 1.3.34; 1.3.36;
sprinkle parentheses
 1.2 11-Dec-2005  christos branches: 1.2.18; 1.2.28; 1.2.32; 1.2.34;
merge ktrace-lwp.
 1.1 16-Jul-2005  macallan branches: 1.1.6;
driver for the audio part of SUNW,DBRI ISDN/audio controllers
 1.1.6.2 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.1.6.1 16-Jul-2005  skrll file cs4215reg.h was added on branch ktrace-lwp on 2005-11-10 14:04:14 +0000
 1.2.34.1 11-Jul-2007  mjf Sync with head.
 1.2.32.1 10-Apr-2007  ad Sync with head.
 1.2.28.1 24-Mar-2007  yamt sync with head.
 1.2.18.3 03-Sep-2007  yamt sync with head.
 1.2.18.2 21-Jun-2006  yamt sync with head.
 1.2.18.1 11-Dec-2005  yamt file cs4215reg.h was added on branch yamt-lazymbuf on 2006-06-21 15:02:54 +0000
 1.3.36.1 16-May-2008  yamt sync with head.
 1.3.34.1 18-May-2008  yamt sync with head.
 1.3.32.1 02-Jun-2008  mjf Sync with HEAD.
 1.4.80.1 13-Jan-2018  snj Pull up following revision(s) (requested by macallan in ticket #476):
sys/dev/sbus/dbrivar.h: revision 1.15
sys/dev/ic/cs4215reg.h: revision 1.5
sys/dev/sbus/dbri.c: revision 1.37
overhaul the dbri driver and make it work again in the New Order Of Things
- fix switching between control and data mode
- make sure interrupts can happen in control mode
- implement audioif.commit_settings()
- switch to control mode only if needed - for changes in sample rate or format
but not for things like volume control
should fix PR 52786
 1.4.62.1 21-Mar-2018  martin Pull up following revision(s) (requested by mrg in ticket #1586):
sys/dev/sbus/dbrivar.h: revision 1.14
sys/dev/sbus/dbrivar.h: revision 1.15
sys/dev/ic/cs4215reg.h: revision 1.5
sys/dev/sbus/dbri.c: revision 1.36
sys/dev/sbus/dbri.c: revision 1.37
sys/dev/sbus/dbri.c: revision 1.38

fix audiomp bugs:
- switch from tsleep/wakeup to condvar
- fix locking in a bunch of places. there were several locking
against myself issues.
also:
- don't let dbri_process_interrupt_buffer() loop more than once
over the array of intrs.

this fixes hangs when using audio on ss20 in -current, but does
not make audio work. it eventually times out with eg:
dbri0: switching to control mode timed out (0 f6)
and may leave a sample in the audio buffer repeating.

overhaul the dbri driver and make it work again in the New Order Of Things
- fix switching between control and data mode
- make sure interrupts can happen in control mode
- implement audioif.commit_settings()
- switch to control mode only if needed - for changes in sample rate or format
but not for things like volume control
should fix PR 52786

fix several KASSERT()s and locking in a few places.

fixes DIAGNOSTIC kernels and still plays.
 1.4 05-May-2008  jmcneill Use 2-clause license.
 1.3 08-Mar-2007  macallan branches: 1.3.36; 1.3.38; 1.3.40;
make the dbri driver work again
while there enforce some alignment rules, adjust some timeouts, retry when
probing the codec fails
 1.2 11-Dec-2005  christos branches: 1.2.18; 1.2.28;
merge ktrace-lwp.
 1.1 16-Jul-2005  macallan branches: 1.1.6;
driver for the audio part of SUNW,DBRI ISDN/audio controllers
 1.1.6.2 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.1.6.1 16-Jul-2005  skrll file cs4215var.h was added on branch ktrace-lwp on 2005-11-10 14:04:14 +0000
 1.2.28.1 12-Mar-2007  rmind Sync with HEAD.
 1.2.18.3 03-Sep-2007  yamt sync with head.
 1.2.18.2 21-Jun-2006  yamt sync with head.
 1.2.18.1 11-Dec-2005  yamt file cs4215var.h was added on branch yamt-lazymbuf on 2006-06-21 15:02:54 +0000
 1.3.40.1 16-May-2008  yamt sync with head.
 1.3.38.1 18-May-2008  yamt sync with head.
 1.3.36.1 02-Jun-2008  mjf Sync with HEAD.
 1.32 10-Nov-2019  chs in many device attach paths, allocate memory with M_WAITOK instead of M_NOWAIT
and remove code to handle failures that can no longer happen.
 1.31 08-Jun-2019  isaki Clean get_props().
- Make get_props() return AUDIO_PROP_{PLAYBACK,CAPTURE} properly.
This eliminates need for audio.c to take care of such (old)
drivers which don't return both of PLAYBACK and CAPTURE.
- All get_props() doesn't need to return AUDIO_PROP_MMAP.
It is handled in the audio layer now.
 1.30 08-May-2019  isaki Merge isaki-audio2 branch, the overhaul of audio subsystem.
- Interrupt-oriented system rather than thread-oriented.
- Improve stability, quality and performance.
- Split playback and record cleanly. Improve halfduplex support.
- Many bugs are fixed including deadlocks, resource leaks, abuses, etc.
- Simplify audio filter mechanism. The encoding/channels/frequency
conversions are completely handled in the upper layer. So the hard-
ware driver only converts its hardware encoding (if necessary).
- audio_hw_if changes:
- Obsoletes query_encoding and add query_format instead.
- Obsoletes set_params and add set_format instead.
- Remove drain, setfd, mappage.
- The call sequences are changed.
- ioctl AUDIO_GETFD/SETFD, AUDIO_GETCHAN/SETCHAN are obsoleted.
- ioctl AUDIO_{QUERY,GET,SET}FORMAT are introduced.
- cleanup config attributes: au*conv and mulaw.
- All hardware drivers should follow it (I've done as much as possible).

Some file paths are changed:
- dev/audio.c -> dev/audio/audio.c (rewritten)
- dev/audiovar.h -> dev/audio/audiovar.h
- dev/audio_dai.h -> dev/audio/audio_dai.h
- dev/audio_if.h -> dev/audio/audio_if.h
- dev/audiobell.c -> dev/audio/audiobell.c
- dev/audiobellvar.h -> dev/audio/audiobellvar.h
- dev/mulaw.[ch] -> dev/audio/mulaw.[ch] + dev/audio/alaw.c
 1.29 01-Jun-2017  chs branches: 1.29.10; 1.29.14;
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.
 1.28 28-Nov-2011  jmcneill branches: 1.28.8; 1.28.26;
PR# kern/45664: audio panic at detach

Pass the size of the structure to kmem_free, not the size of the DMA
buffer.
 1.27 23-Nov-2011  jmcneill Merge jmcneill-audiomp3 branch, which is derived from ad-audiomp2. From
the original ad-audiomp branch notes:

Add MP locking to the audio drivers.

Making the audio drivers MP safe is necessary before efforts
can be made to make the VM system MP safe.

The are two locks per device instance, an ISR lock and
a character device lock. The ISR lock replaces calls to
splaudio()/splx(), and will be held across calls to device
methods which were called at splaudio() before (e.g.
trigger_output). The character device lock is held across
calls to nearly all of the methods, excluding some only
used for initialization, e.g. get_locks.

Welcome to 5.99.57.
 1.26 02-Jun-2011  christos branches: 1.26.2; 1.26.4;
split audiocs
 1.25 16-Apr-2010  dyoung branches: 1.25.2; 1.25.6;
#include <sys/bus.h> instead of <machine/bus.h>. No functional change
intended.
 1.24 14-Jan-2010  macallan branches: 1.24.2; 1.24.4;
set a delta value on the master channel and move it to the outputs class so
volume control via PMF works
 1.23 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.22 28-Apr-2008  garbled Minor fixes to some of these files:
Add recognition for the CS4232C revision chip. (0xa2)
Make ic/ad1848.c compile with AUDIO_DEBUG
Add a needed machine/bus.h include to ic/cs4231.c
Add a few additional register defines to ic/cs4231reg.h
 1.21 08-Apr-2008  cegger branches: 1.21.2; 1.21.4;
use aprint_*_dev and device_xname
 1.20 11-Dec-2007  martin branches: 1.20.8;
const'ify ad1848 devmap.
 1.19 19-Oct-2007  ad branches: 1.19.4; 1.19.6; 1.19.8;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.18 11-Dec-2005  christos branches: 1.18.30; 1.18.44; 1.18.46; 1.18.50;
merge ktrace-lwp.
 1.17 15-Jan-2005  kent branches: 1.17.10;
ansify and KNF
 1.16 09-Jul-2004  petrov Remove unused variable.
 1.15 09-Jul-2004  mycroft Remove junk code.
 1.14 22-Apr-2004  itojun sprintf -> snprintf
 1.13 10-Sep-2003  uwe G/c cs4231_round_buffersize and cs4231_round_blocksize. The round_*
mehtods are DMA-specific, so don't belong here in the first place.
SBus and EBus glue already changed to do the right thing.
 1.12 03-May-2003  wiz branches: 1.12.2;
DMA, not dma nor Dma.
 1.11 01-Feb-2003  martin Clenup malloc signature change fallout.
 1.10 22-Aug-2002  martin Add a mixerctl to mute the internal (mono) speaker via
"mixerctl -w monitor.mono=off".

From Sung-Won Chung, slightly modified. All errors by me.
 1.9 22-Aug-2002  martin Argh! Remove accidently commited debug changes.
 1.8 22-Aug-2002  martin Fix output volume handling, port-sparc64/18033 from Sung-Won Chung.
 1.7 12-Mar-2002  uwe branches: 1.7.4;
Rework the driver to add EBus DMA support and improve APC DMA support.
Audio-related stuff is left almost intact.

* support audiocs at ebus playback and capture
tested on krups and u5 (thanks, martin)
* make first attempt at supporting audiocs at sbus capture
* nb: full-duplex is not tested
* while here, fix CSAUDIO_MONITOR_MUTE to be of CSAUDIO_MONITOR_CLASS
i.e. outputs.monitor.mute -> monitor.monitor.mute

Ok by pk, eeh.
 1.6 13-Nov-2001  lukem add/cleanup RCSID
 1.5 03-Oct-2001  augustss Add a new optional method, dev_ioctl, to the audio hardware driver interface.
It is called when an unrecognized ioctl() is performed on a device,
thus allowing ioctl()s that frob the hardware driver (like loading
microcode).
 1.4 16-Jun-2000  pk branches: 1.4.4; 1.4.6; 1.4.8;
Comply with bus_dma(9) specs.
 1.3 30-Mar-2000  augustss branches: 1.3.2;
Remove register declarations.
 1.2 28-Jan-2000  pk Reset audio chip on device open.
 1.1 05-Jun-1999  mrg branches: 1.1.2; 1.1.4;
split sbus audiocs code up so we can share it with the ebus. XXX ebus DMA is probably different.
 1.1.4.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.1.2.1 21-Jun-1999  thorpej Sync w/ -current.
 1.3.2.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.4.8.1 11-Oct-2001  fvdl Catch up with -current. Fix some bogons in the sparc64 kbd/ms
attach code. cd18xx conversion provided by mrg.
 1.4.6.3 06-Sep-2002  jdolecek sync kqueue branch with HEAD
 1.4.6.2 16-Mar-2002  jdolecek Catch up with -current.
 1.4.6.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.4.4.4 27-Aug-2002  nathanw Catch up to -current.
 1.4.4.3 01-Apr-2002  nathanw Catch up to -current.
(CVS: It's not just a program. It's an adventure!)
 1.4.4.2 14-Nov-2001  nathanw Catch up to -current.
 1.4.4.1 08-Oct-2001  nathanw Catch up to -current.
 1.7.4.1 29-Aug-2002  gehenna catch up with -current.
 1.12.2.4 17-Jan-2005  skrll Sync with HEAD.
 1.12.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.12.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.12.2.1 03-Aug-2004  skrll Sync with HEAD
 1.17.10.2 21-Jan-2008  yamt sync with head
 1.17.10.1 27-Oct-2007  yamt sync with head.
 1.18.50.1 25-Oct-2007  bouyer Sync with HEAD.
 1.18.46.2 09-Jan-2008  matt sync with HEAD
 1.18.46.1 06-Nov-2007  matt sync with HEAD
 1.18.44.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.18.30.1 23-Oct-2007  ad Sync with head.
 1.19.8.1 13-Dec-2007  bouyer Sync with HEAD
 1.19.6.1 11-Dec-2007  yamt sync with head.
 1.19.4.1 26-Dec-2007  ad Sync with head.
 1.20.8.1 02-Jun-2008  mjf Sync with HEAD.
 1.21.4.3 11-Aug-2010  yamt sync with head.
 1.21.4.2 11-Mar-2010  yamt sync with head
 1.21.4.1 16-May-2008  yamt sync with head.
 1.21.2.1 18-May-2008  yamt sync with head.
 1.24.4.2 12-Jun-2011  rmind sync with head
 1.24.4.1 30-May-2010  rmind sync with head
 1.24.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.25.6.1 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.25.2.1 06-Jun-2011  jruoho Sync with HEAD.
 1.26.4.1 20-Nov-2011  mrg make audiocs(4) compile. i don't have anything handy to actually test
this easily, but this was just updating the alloc/free to kmem and
hooking into ad1848_get_locks().
 1.26.2.1 17-Apr-2012  yamt sync with head
 1.28.26.1 28-Aug-2017  skrll Sync with HEAD
 1.28.8.1 03-Dec-2017  jdolecek update from HEAD
 1.29.14.1 04-May-2019  isaki Move dev/audio_if.h -> dev/audio/audio_if.h
 1.29.10.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.29.10.1 10-Jun-2019  christos Sync with HEAD
 1.12 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.11 28-Apr-2008  garbled Minor fixes to some of these files:
Add recognition for the CS4232C revision chip. (0xa2)
Make ic/ad1848.c compile with AUDIO_DEBUG
Add a needed machine/bus.h include to ic/cs4231.c
Add a few additional register defines to ic/cs4231reg.h
 1.10 11-Dec-2005  christos branches: 1.10.70; 1.10.72; 1.10.74;
merge ktrace-lwp.
 1.9 27-Feb-2005  perry nuke trailing whitespace
 1.8 07-Apr-1999  dbj branches: 1.8.36; 1.8.44; 1.8.46;
convert tabs to spaces in ascii art circuit diagram
 1.7 27-Aug-1998  pk branches: 1.7.8;
Add selected `%b' bits.
 1.6 27-Aug-1998  pk Add missing entries and make it slightly more verbose.
 1.5 09-Oct-1997  jtc Fix tipo inherited from old version of TNF copyright template.
 1.4 16-Feb-1996  mycroft branches: 1.4.12;
Remove incorrect comment. From Mike Long, PR 1277.
 1.3 05-Feb-1996  jtc Fix error in copyright notice
 1.2 05-Feb-1996  jtc Received copyright assignment
 1.1 07-Jul-1995  brezak add support for cs4231
 1.4.12.1 14-Oct-1997  thorpej Update marc-pcmcia branch from trunk.
 1.7.8.1 21-Jun-1999  thorpej Sync w/ -current.
 1.8.46.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.8.44.1 29-Apr-2005  kent sync with -current
 1.8.36.1 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.10.74.1 16-May-2008  yamt sync with head.
 1.10.72.1 18-May-2008  yamt sync with head.
 1.10.70.1 02-Jun-2008  mjf Sync with HEAD.
 1.10 23-Nov-2011  jmcneill Merge jmcneill-audiomp3 branch, which is derived from ad-audiomp2. From
the original ad-audiomp branch notes:

Add MP locking to the audio drivers.

Making the audio drivers MP safe is necessary before efforts
can be made to make the VM system MP safe.

The are two locks per device instance, an ISR lock and
a character device lock. The ISR lock replaces calls to
splaudio()/splx(), and will be held across calls to device
methods which were called at splaudio() before (e.g.
trigger_output). The character device lock is held across
calls to nearly all of the methods, excluding some only
used for initialization, e.g. get_locks.

Welcome to 5.99.57.
 1.9 02-Jun-2011  christos branches: 1.9.2; 1.9.4;
split audiocs
 1.8 28-Apr-2008  martin branches: 1.8.22; 1.8.28; 1.8.32;
Remove clause 3 and 4 from TNF licenses
 1.7 04-Mar-2007  christos branches: 1.7.36; 1.7.38; 1.7.40;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.6 11-Dec-2005  christos branches: 1.6.26;
merge ktrace-lwp.
 1.5 09-Jul-2004  mycroft branches: 1.5.12;
Remove junk code.
 1.4 10-Sep-2003  uwe G/c cs4231_round_buffersize and cs4231_round_blocksize. The round_*
mehtods are DMA-specific, so don't belong here in the first place.
SBus and EBus glue already changed to do the right thing.
 1.3 01-Feb-2003  martin branches: 1.3.2;
Clenup malloc signature change fallout.
 1.2 12-Mar-2002  uwe Rework the driver to add EBus DMA support and improve APC DMA support.
Audio-related stuff is left almost intact.

* support audiocs at ebus playback and capture
tested on krups and u5 (thanks, martin)
* make first attempt at supporting audiocs at sbus capture
* nb: full-duplex is not tested
* while here, fix CSAUDIO_MONITOR_MUTE to be of CSAUDIO_MONITOR_CLASS
i.e. outputs.monitor.mute -> monitor.monitor.mute

Ok by pk, eeh.
 1.1 05-Jun-1999  mrg branches: 1.1.2; 1.1.16; 1.1.18;
split sbus audiocs code up so we can share it with the ebus. XXX ebus DMA is probably different.
 1.1.18.1 16-Mar-2002  jdolecek Catch up with -current.
 1.1.16.1 01-Apr-2002  nathanw Catch up to -current.
(CVS: It's not just a program. It's an adventure!)
 1.1.2.1 21-Jun-1999  thorpej Sync w/ -current.
 1.3.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.3.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.3.2.1 03-Aug-2004  skrll Sync with HEAD
 1.5.12.1 03-Sep-2007  yamt sync with head.
 1.6.26.1 12-Mar-2007  rmind Sync with HEAD.
 1.7.40.1 16-May-2008  yamt sync with head.
 1.7.38.1 18-May-2008  yamt sync with head.
 1.7.36.1 02-Jun-2008  mjf Sync with HEAD.
 1.8.32.1 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.8.28.1 06-Jun-2011  jruoho Sync with HEAD.
 1.8.22.1 12-Jun-2011  rmind sync with head
 1.9.4.1 20-Nov-2011  mrg make audiocs(4) compile. i don't have anything handy to actually test
this easily, but this was just updating the alloc/free to kmem and
hooking into ad1848_get_locks().
 1.9.2.1 17-Apr-2012  yamt sync with head
 1.5 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.4 11-Dec-2005  christos branches: 1.4.70; 1.4.72; 1.4.74;
merge ktrace-lwp.
 1.3 04-Dec-2003  keihan netbsd.org -> NetBSD.org

This was the last commit of this kind to src/sys, which is now totally
"NetBSD.org clean". Thanks for the patiance, and sorry for all the commits.
 1.2 02-Nov-2003  wiz Fix some typos. From Tom Cosgrove via jmc@openbsd.
 1.1 06-Sep-1999  rh branches: 1.1.36;
Add mode 3 support for newer CS423X chips. Modify probe to correctly
distinguish between CS4236, CS4236B, and CS4237B.
 1.1.36.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.1.36.2 18-Sep-2004  skrll Sync with HEAD.
 1.1.36.1 03-Aug-2004  skrll Sync with HEAD
 1.4.74.1 16-May-2008  yamt sync with head.
 1.4.72.1 18-May-2008  yamt sync with head.
 1.4.70.1 02-Jun-2008  mjf Sync with HEAD.
 1.56 07-Jan-2025  andvar fix various typos in commments.
 1.55 29-Jun-2024  riastradh branches: 1.55.2;
if_stats(9): Add ifp argument to if_stat..._ref.

This will enable us to pass the ifp through to a dtrace probe inside.

No functional change intended in this change, but this is an API
change visible to modules so it shouldn't be pulled up.

PR kern/58377
 1.54 10-Feb-2024  andvar Fix various typos in comments, log messages and documentation.
 1.53 09-Feb-2024  andvar fix spelling mistakes, mainly in comments and log messages.
 1.52 18-Sep-2022  thorpej Eliminate use of IFF_OACTIVE. (This driver never even set it.)
 1.51 31-Jul-2021  andvar s/threshhold/threshold
 1.50 24-Jul-2021  andvar Fix all remaining typos, mainly in comments but also in few definitions and log messages, reported by me in PR kern/54889.
Also fixed some additional typos in comments, found on review of same files or typos.
 1.49 04-Feb-2020  thorpej branches: 1.49.10;
Use ifmedia_fini().
 1.48 29-Jan-2020  thorpej Adopt <net/if_stats.h>.
 1.47 29-May-2019  msaitoh branches: 1.47.4;
Even if we don't use MII(4), use the common path of SIOC[GS]IFMEDIA in
sys/net/if_ethersubr.c if we can.
- Add ec_ifmedia into struct ethercom.
- ec_mii in struct ethercom is kept and used as it is. It might be used in
future. Note that some Ethernet drivers which _DOESN'T_ use mii(4) use
ec_mii for keeping the if_media. Those should be changed in future.
 1.46 28-May-2019  msaitoh Use ETHER_LOCK()/ETHER_UNLOCK() for all ethernet drivers to protect ec_multi*.
 1.45 23-May-2019  msaitoh -No functional change:
- KNF
- u_int*_t -> uint*_t.
 1.44 26-Apr-2019  msaitoh No functional change:
- u_int_{8,16,32}_t -> uint_{8,16,32}_t
- KNF.
- Tabify.
- Remove extra space.
 1.43 25-Apr-2019  msaitoh No functional change:
- Use __arraycount().
- u_int_{8,16,32}_t -> uint_{8,16,32}_t
- KNF.
- Tabify.
- Remove extra space.
 1.42 05-Feb-2019  msaitoh Remove very old IFF_NOTRAILERS flag.
 1.41 26-Jun-2018  msaitoh branches: 1.41.2;
Implement the BPF direction filter (BIOC[GS]DIRECTION). It provides backward
compatibility with BIOC[GS]SEESENT ioctl. The userland interface is the same
as FreeBSD.

This change also fixes a bug that the direction is misunderstand on some
environment by passing the direction to bpf_mtap*() instead of checking
m->m_pkthdr.rcvif.
 1.40 22-Jun-2018  msaitoh It's not required to include net/bpfdesc.h. Remove it.
 1.39 07-Mar-2017  ozaki-r branches: 1.39.6; 1.39.12;
Apply deferred if_start (from maya@)

Fix PR kern/52023
 1.38 15-Dec-2016  ozaki-r branches: 1.38.2;
Move bpf_mtap and if_ipackets++ on Rx of each driver to percpuq if_input

The benefits of the change are:
- We can reduce codes
- We can provide the same behavior between drivers
- Where/When if_ipackets is counted up
- Note that some drivers still update packet statistics in their own
way (periodical update)
- Moved bpf_mtap run in softint
- This makes it easy to MP-ify bpf

Proposed on tech-kern and tech-net
 1.37 10-Jun-2016  ozaki-r branches: 1.37.2;
Introduce m_set_rcvif and m_reset_rcvif

The API is used to set (or reset) a received interface of a mbuf.
They are counterpart of m_get_rcvif, which will come in another
commit, hide internal of rcvif operation, and reduce the diff of
the upcoming change.

No functional change.
 1.36 09-Feb-2016  ozaki-r Introduce softint-based if_input

This change intends to run the whole network stack in softint context
(or normal LWP), not hardware interrupt context. Note that the work is
still incomplete by this change; to that end, we also have to softint-ify
if_link_state_change (and bpf) which can still run in hardware interrupt.

This change softint-ifies at ifp->if_input that is called from
each device driver (and ieee80211_input) to ensure Layer 2 runs
in softint (e.g., ether_input and bridge_input). To this end,
we provide a framework (called percpuq) that utlizes softint(9)
and percpu ifqueues. With this patch, rxintr of most drivers just
queues received packets and schedules a softint, and the softint
dequeues packets and does rest packet processing.

To minimize changes to each driver, percpuq is allocated in struct
ifnet for now and that is initialized by default (in if_attach).
We probably have to move percpuq to softc of each driver, but it's
future work. At this point, only wm(4) has percpuq in its softc
as a reference implementation.

Additional information including performance numbers can be found
in the thread at tech-kern@ and tech-net@:
http://mail-index.netbsd.org/tech-kern/2016/01/14/msg019997.html

Acknowledgment: riastradh@ greatly helped this work.
Thank you very much!
 1.35 13-Apr-2015  riastradh Convert sys/dev to use <sys/rndsource.h>.
 1.34 10-Aug-2014  tls branches: 1.34.4;
Merge tls-earlyentropy branch into HEAD.
 1.33 02-Feb-2012  tls branches: 1.33.6; 1.33.20;
Entropy-pool implementation move and cleanup.

1) Move core entropy-pool code and source/sink/sample management code
to sys/kern from sys/dev.

2) Remove use of NRND as test for presence of entropy-pool code throughout
source tree.

3) Remove use of RND_ENABLED in device drivers as microoptimization to
avoid expensive operations on disabled entropy sources; make the
rnd_add calls do this directly so all callers benefit.

4) Fix bug in recent rnd_add_data()/rnd_add_uint32() changes that might
have lead to slight entropy overestimation for some sources.

5) Add new source types for environmental sensors, power sensors, VM
system events, and skew between clocks, with a sample implementation
for each.

ok releng to go in before the branch due to the difficulty of later
pullup (widespread #ifdef removal and moved files). Tested with release
builds on amd64 and evbarm and live testing on amd64.
 1.32 13-Nov-2010  uebayasi branches: 1.32.8; 1.32.12;
Don't pull in the whole uvm(9) API to access only PAGE_SIZE and
some other constants. These are provided by sys/param.h now.
 1.31 05-Apr-2010  joerg Push the bpf_ops usage back into bpf.h. Push the common ifp->if_bpf
check into the inline functions as well the fourth argument for
bpf_attach.
 1.30 19-Jan-2010  pooka branches: 1.30.2; 1.30.4;
Redefine bpf linkage through an always present op vector, i.e.
#if NBPFILTER is no longer required in the client. This change
doesn't yet add support for loading bpf as a module, since drivers
can register before bpf is attached. However, callers of bpf can
now be modularized.

Dynamically loadable bpf could probably be done fairly easily with
coordination from the stub driver and the real driver by registering
attachments in the stub before the real driver is loaded and doing
a handoff. ... and I'm not going to ponder the depths of unload
here.

Tested with i386/MONOLITHIC, modified MONOLITHIC without bpf and rump.
 1.29 01-Dec-2009  dyoung Simplify the device activation routine.
 1.28 22-Sep-2009  tsutsui Make local functions static.
 1.27 22-Sep-2009  tsutsui Fix possible endian issue. Untested.
 1.26 22-Sep-2009  tsutsui Split device_t/softc. Tested only on cs at ofisa on shark.
 1.25 22-Sep-2009  tsutsui - replace shutdownhook_establish(9) with pmf_device_register1(9)
- remove powerhook_establish(9) because all stuff in cs_power()
will be handled in pmf_class_network

Briefly tested on CS8900 at ofisa on DNARD compatible.
 1.24 12-May-2009  cegger struct device * -> device_t, no functional changes intended.
 1.23 08-Apr-2008  cegger branches: 1.23.4; 1.23.18;
use aprint_*_dev and device_xname
 1.22 19-Oct-2007  ad branches: 1.22.16;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.21 04-Mar-2007  christos branches: 1.21.2; 1.21.14; 1.21.16; 1.21.20;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.20 24-Sep-2006  jmcneill branches: 1.20.4;
Add "name" parameter to powerhook_establish, to aid debugging. No objections
on tech-kern@
 1.19 18-Mar-2006  chris branches: 1.19.8; 1.19.10;
Fix eeprom == NULL and size test.

Fixes Coverity CID 1109: (sc)->eeprom_data tracked as NULL was
dereferenced.
 1.18 11-Dec-2005  christos branches: 1.18.4; 1.18.6; 1.18.8; 1.18.10; 1.18.12;
merge ktrace-lwp.
 1.17 30-May-2005  christos branches: 1.17.2;
- add missing const
- fix variable shadowing
- remove unneeded casts
 1.16 27-Feb-2005  perry nuke trailing whitespace
 1.15 30-Oct-2004  thorpej branches: 1.15.4; 1.15.6;
When adding/deleting multicast addresses, only whack the address
filter if the interface is marked RUNNING.

Fixes kern/27678.
 1.14 04-Jul-2004  chris Add the optional ability to parse the cs's eeprom data structure. I've made
it optional as I'm not able to confirm the eeprom format is the same on
earlier cs89x0's. Certainly the my 8920M and the data sheet for 8900A use the
same format.

This allows my RiscStation to examine the cs's eeprom to find it's mac
address, previously it was unable to do this, as the eeprom offsets were hard
coded for locating the mac address.
 1.13 10-Apr-2004  matt Don't set M_HASFCS. Rather than just print we got a bad packet length,
actually print out the length that was bad.
 1.12 24-Mar-2004  matt branches: 1.12.2;
Set the M_HASFCS flag on received traffic.
 1.11 30-Oct-2003  simonb Remove some assigned-to but otherwise unused variables.
 1.10 25-Oct-2003  christos Fix uninitialized variable warnings
 1.9 03-May-2003  wiz branches: 1.9.2;
DMA, not dma nor Dma.
 1.8 02-Feb-2003  wiz guarantee, not guarentee. Idea from miod@openbsd.
 1.7 06-Jan-2003  wiz interrupt with two rs.
 1.6 21-May-2002  augustss Make it possible to override the way register access is done.
This is needed for some really screwball attachments of the CS8900.
 1.5 14-May-2002  augustss branches: 1.5.2;
ANSIfy.
 1.4 18-Apr-2002  thorpej * Fix the CS_IS_ENABLED() logic so that it actually evaluates to
"true" at the appropriate times for non-PCMCIA interfaces. This
means that the ENETRESET path in cs_ioctl() now runs, thus fixing
multicast (and IPv6) on my Shark. Yay.

* Simplify cs_hash_index(): Rather than taking the bottom 6 bits of
a big-endian CRC32 and reversing them, just take the top 6 bits of
a little-endian CRC32.
 1.3 10-Feb-2002  pooka point sequioa.h to new location
 1.2 27-Nov-2001  yamt branches: 1.2.2; 1.2.4;
don't allocate a mbuf cluster if we don't need.
 1.1 26-Nov-2001  yamt move dev/isa/cs89x0{.c,{var,reg}.h} into dev/ic
and split isadma parts into /dev/isa/cs89x0isa*.
 1.2.4.4 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.2.4.3 16-Mar-2002  jdolecek Catch up with -current.
 1.2.4.2 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.2.4.1 27-Nov-2001  thorpej file cs89x0.c was added on branch kqueue on 2002-01-10 19:54:21 +0000
 1.2.2.5 07-Jan-2003  thorpej Sync with HEAD.
 1.2.2.4 20-Jun-2002  nathanw Catch up to -current.
 1.2.2.3 28-Feb-2002  nathanw Catch up to -current.
 1.2.2.2 08-Jan-2002  nathanw Catch up to -current.
 1.2.2.1 27-Nov-2001  nathanw file cs89x0.c was added on branch nathanw_sa on 2002-01-08 00:29:39 +0000
 1.5.2.1 30-May-2002  gehenna Catch up with -current.
 1.9.2.6 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.9.2.5 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.9.2.4 02-Nov-2004  skrll Sync with HEAD.
 1.9.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.9.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.9.2.1 03-Aug-2004  skrll Sync with HEAD
 1.12.2.1 07-Jul-2004  tron branches: 1.12.2.1.2;
Pull up revision 1.13 (requested by mycroft in ticket #610):
Don't set M_HASFCS. Rather than just print we got a bad packet length,
actually print out the length that was bad.
 1.12.2.1.2.1 24-Jan-2005  he Pull up revision 1.15 (requested by thorpej in ticket #939):
When adding or deleting multicast addresses, only change
the address filter if the interface is marked RUNNING.
Fixes PR#27678.
 1.15.6.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.15.4.1 29-Apr-2005  kent sync with -current
 1.17.2.4 27-Oct-2007  yamt sync with head.
 1.17.2.3 03-Sep-2007  yamt sync with head.
 1.17.2.2 30-Dec-2006  yamt sync with head.
 1.17.2.1 21-Jun-2006  yamt sync with head.
 1.18.12.1 28-Mar-2006  tron Merge 2006-03-28 NetBSD-current into the "peter-altq" branch.
 1.18.10.1 19-Apr-2006  elad sync with head.
 1.18.8.1 01-Apr-2006  yamt sync with head.
 1.18.6.1 22-Apr-2006  simonb Sync with head.
 1.18.4.1 09-Sep-2006  rpaulo sync with head
 1.19.10.1 22-Oct-2006  yamt sync with head
 1.19.8.1 18-Nov-2006  ad Sync with head.
 1.20.4.1 12-Mar-2007  rmind Sync with HEAD.
 1.21.20.1 25-Oct-2007  bouyer Sync with HEAD.
 1.21.16.1 06-Nov-2007  matt sync with HEAD
 1.21.14.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.21.2.1 23-Oct-2007  ad Sync with head.
 1.22.16.1 02-Jun-2008  mjf Sync with HEAD.
 1.23.18.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.23.4.3 11-Aug-2010  yamt sync with head.
 1.23.4.2 11-Mar-2010  yamt sync with head
 1.23.4.1 16-May-2009  yamt sync with head
 1.30.4.2 05-Mar-2011  rmind sync with head
 1.30.4.1 30-May-2010  rmind sync with head
 1.30.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.32.12.1 18-Feb-2012  mrg merge to -current.
 1.32.8.1 17-Apr-2012  yamt sync with head
 1.33.20.1 07-Apr-2014  tls Be a little more clear and consistent about harvesting entropy from devices:

1) deprecate RND_FLAG_NO_ESTIMATE

2) define RND_FLAG_COLLECT_TIME, RND_FLAG_COLLECT_VALUE

3) define RND_FLAG_ESTIMATE_TIME, RND_FLAG_ESTIMATE_VALUE

4) define RND_FLAG_DEFAULT: RND_FLAG_COLLECT_TIME|
RND_FLAG_COLLECT_VALUE|RND_FLAG_ESTIMATE_TIME

5) Make entropy harvesting from environmental sensors a little more generic
and remove it from individual sensor drivers.

6) Remove individual open-coded delta-estimators for values from a few
places in the tree (uvm, environmental drivers).

7) 0 -> RND_FLAG_DEFAULT, actually gather entropy from various drivers
that had stubbed out code, other minor cleanups.
 1.33.6.2 03-Dec-2017  jdolecek update from HEAD
 1.33.6.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.34.4.5 28-Aug-2017  skrll Sync with HEAD
 1.34.4.4 05-Feb-2017  skrll Sync with HEAD
 1.34.4.3 09-Jul-2016  skrll Sync with HEAD
 1.34.4.2 19-Mar-2016  skrll Sync with HEAD
 1.34.4.1 06-Jun-2015  skrll Sync with HEAD
 1.37.2.2 20-Mar-2017  pgoyette Sync with HEAD
 1.37.2.1 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.38.2.1 21-Apr-2017  bouyer Sync with HEAD
 1.39.12.2 28-Jul-2018  pgoyette Sync with HEAD
 1.39.12.1 25-Jun-2018  pgoyette Sync with HEAD
 1.39.6.1 26-Jul-2018  snj Pull up following revision(s) (requested by msaitoh in ticket #938):
sys/arch/acorn32/podulebus/if_ie.c: revision 1.41
sys/arch/amiga/dev/if_es.c: revision 1.58
sys/arch/amiga/dev/if_qn.c: revision 1.45
sys/arch/arm/at91/at91emac.c: revision 1.20
sys/arch/arm/ep93xx/epe.c: revision 1.37
sys/arch/emips/ebus/if_le_ebus.c: revision 1.14
sys/arch/emips/ebus/if_le_ebus.c: revision 1.15
sys/arch/mac68k/dev/if_mc.c: revision 1.46
sys/arch/macppc/dev/am79c950.c: revision 1.39
sys/arch/newsmips/apbus/if_sn.c: revision 1.40
sys/arch/next68k/dev/mb8795.c: revision 1.59
sys/arch/playstation2/dev/if_smap.c: revision 1.25
sys/arch/playstation2/dev/if_smap.c: revision 1.26
sys/arch/sun2/dev/if_ec.c: revision 1.28
sys/arch/sun3/dev/if_ie.c: revision 1.63
sys/arch/x68k/dev/if_ne_intio.c: revision 1.19
sys/arch/xen/xen/if_xennet_xenbus.c: revision 1.75
sys/arch/xen/xen/xennetback_xenbus.c: revision 1.63
sys/dev/bi/if_ni.c: revision 1.45
sys/dev/cadence/if_cemac.c: revision 1.12
sys/dev/ic/am7990.c: revision 1.78
sys/dev/ic/am79900.c: revision 1.27
sys/dev/ic/an.c: revision 1.67
sys/dev/ic/cs89x0.c: revision 1.40
sys/dev/ic/dm9000.c: revision 1.13
sys/dev/ic/dm9000.c: revision 1.14
sys/dev/ic/dp8390.c: revision 1.88
sys/dev/ic/elink3.c: revision 1.141
sys/dev/ic/elinkxl.c: revision 1.122
sys/dev/ic/hme.c: revision 1.98
sys/dev/ic/i82586.c: revision 1.77
sys/dev/ic/lance.c: revision 1.53
sys/dev/ic/mb86950.c: revision 1.27
sys/dev/ic/mb86960.c: revision 1.86
sys/dev/ic/mtd803.c: revision 1.34
sys/dev/ic/pdq_ifsubr.c: revision 1.59
sys/dev/ic/rrunner.c: revision 1.86
sys/dev/ic/seeq8005.c: revision 1.58
sys/dev/ic/sgec.c: revision 1.47
sys/dev/ic/smc90cx6.c: revision 1.72
sys/dev/ic/smc91cxx.c: revision 1.96
sys/dev/ic/tropic.c: revision 1.49
sys/dev/ic/wi.c: revision 1.245
sys/dev/isa/if_eg.c: revision 1.93
sys/dev/isa/if_el.c: revision 1.95
sys/dev/isa/if_iy.c: revision 1.101
sys/dev/ofw/ofnet.c: revision 1.58
sys/dev/pci/if_alc.c: revision 1.27
sys/dev/pci/if_de.c: revision 1.152
sys/dev/pci/if_fpa.c: revision 1.61
sys/dev/pci/if_jme.c: revision 1.34
sys/dev/pci/if_tl.c: revision 1.108
sys/dev/pci/if_vte.c: revision 1.19
sys/dev/pci/ixgbe/ixgbe.h: revision 1.50
sys/dev/pcmcia/if_cnw.c: revision 1.62
sys/dev/pcmcia/if_malo_pcmcia.c: revision 1.17
sys/dev/pcmcia/if_ray.c: revision 1.89
sys/dev/pcmcia/if_xi.c: revision 1.81
sys/dev/pcmcia/mhzc.c: revision 1.51
sys/dev/pcmcia/xirc.c: revision 1.34
sys/dev/qbus/if_de.c: revision 1.33
sys/dev/qbus/if_qe.c: revision 1.78
sys/dev/qbus/if_qt.c: revision 1.22
sys/dev/sbus/be.c: revision 1.87
sys/dev/sbus/qe.c: revision 1.68
sys/dev/scsipi/if_se.c: revision 1.96
sys/dev/usb/if_atu.c: revision 1.59
sys/net/if_l2tp.c: revision 1.28 via patch
sys/net/if_ppp.c: revision 1.160
It's not required to include net/bpfdesc.h. Remove it.
--
Simplify like other drivers. NULL check of ifp->if_bpf is done in
bpf_mtap(), so it's not required to do it here.
--
Remove duplicated inclusion of net/bpf.h.
--
Remove duplicated inclusion of net/bpf.h.
--
Simplify bpf_mtap() call. No functional change.
 1.41.2.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.41.2.1 10-Jun-2019  christos Sync with HEAD
 1.47.4.1 29-Feb-2020  ad Sync with head.
 1.49.10.1 01-Aug-2021  thorpej Sync with HEAD.
 1.55.2.1 02-Aug-2025  perseant Sync with HEAD
 1.4 10-Feb-2024  andvar fix various typos in comments and log messages.
 1.3 11-Dec-2005  christos merge ktrace-lwp.
 1.2 04-Feb-2004  augustss Add some EEPROM related defines.
 1.1 26-Nov-2001  yamt branches: 1.1.2; 1.1.4; 1.1.20;
move dev/isa/cs89x0{.c,{var,reg}.h} into dev/ic
and split isadma parts into /dev/isa/cs89x0isa*.
 1.1.20.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.1.20.2 18-Sep-2004  skrll Sync with HEAD.
 1.1.20.1 03-Aug-2004  skrll Sync with HEAD
 1.1.4.2 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.1.4.1 26-Nov-2001  thorpej file cs89x0reg.h was added on branch kqueue on 2002-01-10 19:54:21 +0000
 1.1.2.2 08-Jan-2002  nathanw Catch up to -current.
 1.1.2.1 26-Nov-2001  nathanw file cs89x0reg.h was added on branch nathanw_sa on 2002-01-08 00:29:40 +0000
 1.17 13-Apr-2015  riastradh Convert sys/dev to use <sys/rndsource.h>.
 1.16 02-Feb-2012  tls branches: 1.16.6; 1.16.24;
Entropy-pool implementation move and cleanup.

1) Move core entropy-pool code and source/sink/sample management code
to sys/kern from sys/dev.

2) Remove use of NRND as test for presence of entropy-pool code throughout
source tree.

3) Remove use of RND_ENABLED in device drivers as microoptimization to
avoid expensive operations on disabled entropy sources; make the
rnd_add calls do this directly so all callers benefit.

4) Fix bug in recent rnd_add_data()/rnd_add_uint32() changes that might
have lead to slight entropy overestimation for some sources.

5) Add new source types for environmental sensors, power sensors, VM
system events, and skew between clocks, with a sample implementation
for each.

ok releng to go in before the branch due to the difficulty of later
pullup (widespread #ifdef removal and moved files). Tested with release
builds on amd64 and evbarm and live testing on amd64.
 1.15 19-Nov-2011  tls branches: 1.15.2;
First step of random number subsystem rework described in
<20111022023242.BA26F14A158@mail.netbsd.org>. This change includes
the following:

An initial cleanup and minor reorganization of the entropy pool
code in sys/dev/rnd.c and sys/dev/rndpool.c. Several bugs are
fixed. Some effort is made to accumulate entropy more quickly at
boot time.

A generic interface, "rndsink", is added, for stream generators to
request that they be re-keyed with good quality entropy from the pool
as soon as it is available.

The arc4random()/arc4randbytes() implementation in libkern is
adjusted to use the rndsink interface for rekeying, which helps
address the problem of low-quality keys at boot time.

An implementation of the FIPS 140-2 statistical tests for random
number generator quality is provided (libkern/rngtest.c). This
is based on Greg Rose's implementation from Qualcomm.

A new random stream generator, nist_ctr_drbg, is provided. It is
based on an implementation of the NIST SP800-90 CTR_DRBG by
Henric Jungheim. This generator users AES in a modified counter
mode to generate a backtracking-resistant random stream.

An abstraction layer, "cprng", is provided for in-kernel consumers
of randomness. The arc4random/arc4randbytes API is deprecated for
in-kernel use. It is replaced by "cprng_strong". The current
cprng_fast implementation wraps the existing arc4random
implementation. The current cprng_strong implementation wraps the
new CTR_DRBG implementation. Both interfaces are rekeyed from
the entropy pool automatically at intervals justifiable from best
current cryptographic practice.

In some quick tests, cprng_fast() is about the same speed as
the old arc4randbytes(), and cprng_strong() is about 20% faster
than rnd_extract_data(). Performance is expected to improve.

The AES code in src/crypto/rijndael is no longer an optional
kernel component, as it is required by cprng_strong, which is
not an optional kernel component.

The entropy pool output is subjected to the rngtest tests at
startup time; if it fails, the system will reboot. There is
approximately a 3/10000 chance of a false positive from these
tests. Entropy pool _input_ from hardware random numbers is
subjected to the rngtest tests at attach time, as well as the
FIPS continuous-output test, to detect bad or stuck hardware
RNGs; if any are detected, they are detached, but the system
continues to run.

A problem with rndctl(8) is fixed -- datastructures with
pointers in arrays are no longer passed to userspace (this
was not a security problem, but rather a major issue for
compat32). A new kernel will require a new rndctl.

The sysctl kern.arandom() and kern.urandom() nodes are hooked
up to the new generators, but the /dev/*random pseudodevices
are not, yet.

Manual pages for the new kernel interfaces are forthcoming.
 1.14 22-Sep-2009  tsutsui branches: 1.14.12;
Split device_t/softc. Tested only on cs at ofisa on shark.
 1.13 22-Sep-2009  tsutsui - replace shutdownhook_establish(9) with pmf_device_register1(9)
- remove powerhook_establish(9) because all stuff in cs_power()
will be handled in pmf_class_network

Briefly tested on CS8900 at ofisa on DNARD compatible.
 1.12 12-May-2009  cegger struct device * -> device_t, no functional changes intended.
 1.11 16-Feb-2006  perry branches: 1.11.68; 1.11.84;
Change "inline" back to "__inline" in .h files -- C99 is still too
new, and some apps compile things in C89 mode. C89 keywords stay.

As per core@.
 1.10 24-Dec-2005  perry branches: 1.10.2; 1.10.4; 1.10.6;
__inline__ -> inline
 1.9 11-Dec-2005  christos merge ktrace-lwp.
 1.8 27-Feb-2005  perry branches: 1.8.4;
nuke trailing whitespace
 1.7 04-Jul-2004  chris branches: 1.7.4; 1.7.6;
Add the optional ability to parse the cs's eeprom data structure. I've made
it optional as I'm not able to confirm the eeprom format is the same on
earlier cs89x0's. Certainly the my 8920M and the data sheet for 8900A use the
same format.

This allows my RiscStation to examine the cs's eeprom to find it's mac
address, previously it was unable to do this, as the eeprom offsets were hard
coded for locating the mac address.
 1.6 08-Jul-2003  itojun function prototype must not have variable name
 1.5 03-May-2003  wiz branches: 1.5.2;
DMA, not dma nor Dma.
 1.4 06-Jan-2003  wiz interrupt with two rs.
 1.3 21-May-2002  augustss Make it possible to override the way register access is done.
This is needed for some really screwball attachments of the CS8900.
 1.2 14-May-2002  augustss branches: 1.2.2;
ANSIfy.
 1.1 26-Nov-2001  yamt branches: 1.1.2; 1.1.4;
move dev/isa/cs89x0{.c,{var,reg}.h} into dev/ic
and split isadma parts into /dev/isa/cs89x0isa*.
 1.1.4.3 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.1.4.2 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.1.4.1 26-Nov-2001  thorpej file cs89x0var.h was added on branch kqueue on 2002-01-10 19:54:22 +0000
 1.1.2.4 07-Jan-2003  thorpej Sync with HEAD.
 1.1.2.3 20-Jun-2002  nathanw Catch up to -current.
 1.1.2.2 08-Jan-2002  nathanw Catch up to -current.
 1.1.2.1 26-Nov-2001  nathanw file cs89x0var.h was added on branch nathanw_sa on 2002-01-08 00:29:40 +0000
 1.2.2.1 30-May-2002  gehenna Catch up with -current.
 1.5.2.4 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.5.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.5.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.5.2.1 03-Aug-2004  skrll Sync with HEAD
 1.7.6.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.7.4.1 29-Apr-2005  kent sync with -current
 1.8.4.1 21-Jun-2006  yamt sync with head.
 1.10.6.1 22-Apr-2006  simonb Sync with head.
 1.10.4.1 09-Sep-2006  rpaulo sync with head
 1.10.2.1 18-Feb-2006  yamt sync with head.
 1.11.84.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.11.68.2 11-Mar-2010  yamt sync with head
 1.11.68.1 16-May-2009  yamt sync with head
 1.14.12.1 17-Apr-2012  yamt sync with head
 1.15.2.1 18-Feb-2012  mrg merge to -current.
 1.16.24.1 06-Jun-2015  skrll Sync with HEAD
 1.16.6.1 03-Dec-2017  jdolecek update from HEAD
 1.15 07-Aug-2021  thorpej Merge thorpej-cfargs2.
 1.14 24-Apr-2021  thorpej branches: 1.14.8;
Merge thorpej-cfargs branch:

Simplify and make extensible the config_search() / config_found() /
config_attach() interfaces: rather than having different variants for
which arguments you want pass along, just have a single call that
takes a variadic list of tag-value arguments.

Adjust all call sites:
- Simplify wherever possible; don't pass along arguments that aren't
actually needed.
- Don't be explicit about what interface attribute is attaching if
the device only has one. (More simplification.)
- Add a config_probe() function to be used in indirect configuiration
situations, making is visibly easier to see when indirect config is
in play, and allowing for future change in semantics. (As of now,
this is just a wrapper around config_match(), but that is an
implementation detail.)

Remove unnecessary or redundant interface attributes where they're not
needed.

There are currently 5 "cfargs" defined:
- CFARG_SUBMATCH (submatch function for direct config)
- CFARG_SEARCH (search function for indirect config)
- CFARG_IATTR (interface attribte)
- CFARG_LOCATORS (locators array)
- CFARG_DEVHANDLE (devhandle_t - wraps OFW, ACPI, etc. handles)

...and a sentinel value CFARG_EOL.

Add some extra sanity checking to ensure that interface attributes
aren't ambiguous.

Use CFARG_DEVHANDLE in MI FDT, OFW, and ACPI code, and macppc and shark
ports to associate those device handles with device_t instance. This
will trickle trough to more places over time (need back-end for pre-OFW
Sun OBP; any others?).
 1.13 03-Feb-2017  macallan branches: 1.13.30;
some bugs in chipsfb_putchar_aa():
- fix 64bit padding for scanlines
- clean out latch for every scanline
now fonts with odd widths look right
 1.12 02-Feb-2017  macallan support anti-aliased fonts, glyphcache etc.
 1.11 26-Aug-2016  macallan branches: 1.11.2;
fix a bunch of bugs & tpyos in chipsfb_mmap() so wsfb can actually work
 1.10 04-Jan-2014  macallan branches: 1.10.6; 1.10.10;
__unuse the right function
( note to self - don't commit half asleep )
 1.9 03-Jan-2014  macallan do as joerg requested and mark an unused function __unused
 1.8 09-Oct-2013  macallan support WSDISPLAYIO_GET_FBINFO
 1.7 30-Jul-2013  macallan avoid uninitialized use of defattr
 1.6 22-Aug-2012  macallan branches: 1.6.2; 1.6.4;
- use R3G3B2 palette
- don't muck around in config registers that don't really concern us
 1.5 23-May-2012  macallan first step to fix PR 46461 - don't jump through a NULL pointer when we're
not the console but the firmware set up the graphics hardware anyway
 1.4 13-Mar-2012  elad Replace the remaining KAUTH_GENERIC_ISSUSER authorization calls with
something meaningful. All relevant documentation has been updated or
written.

Most of these changes were brought up in the following messages:

http://mail-index.netbsd.org/tech-kern/2012/01/18/msg012490.html
http://mail-index.netbsd.org/tech-kern/2012/01/19/msg012502.html
http://mail-index.netbsd.org/tech-kern/2012/02/17/msg012728.html

Thanks to christos, manu, njoly, and jmmv for input.

Huge thanks to pgoyette for spinning these changes through some build
cycles and ATF.
 1.3 11-Jan-2012  macallan use rasops_init(0, 0)
 1.2 23-Mar-2011  macallan branches: 1.2.4; 1.2.6; 1.2.10;
complete the driver/bus frontend split and make sure the driver can deal with
both PCI and VLB variants of the chip
 1.1 09-Feb-2011  macallan branches: 1.1.2; 1.1.4;
split out the bus-independent portions of chipsfb
 1.1.4.3 21-Apr-2011  rmind sync with head
 1.1.4.2 05-Mar-2011  rmind sync with head
 1.1.4.1 09-Feb-2011  rmind file ct65550.c was added on branch rmind-uvmplock on 2011-03-05 20:53:14 +0000
 1.1.2.2 17-Feb-2011  bouyer Sync with HEAD
 1.1.2.1 09-Feb-2011  bouyer file ct65550.c was added on branch bouyer-quota2 on 2011-02-17 12:00:12 +0000
 1.2.10.3 02-Jun-2012  mrg sync to latest -current.
 1.2.10.2 05-Apr-2012  mrg sync to latest -current.
 1.2.10.1 18-Feb-2012  mrg merge to -current.
 1.2.6.3 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.2.6.2 30-Oct-2012  yamt sync with head
 1.2.6.1 17-Apr-2012  yamt sync with head
 1.2.4.2 06-Jun-2011  jruoho Sync with HEAD.
 1.2.4.1 23-Mar-2011  jruoho file ct65550.c was added on branch jruoho-x86intr on 2011-06-06 09:07:52 +0000
 1.6.4.2 18-May-2014  rmind sync with head
 1.6.4.1 28-Aug-2013  rmind sync with head
 1.6.2.2 03-Dec-2017  jdolecek update from HEAD
 1.6.2.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.10.10.1 20-Mar-2017  pgoyette Sync with HEAD
 1.10.6.2 05-Feb-2017  skrll Sync with HEAD
 1.10.6.1 05-Oct-2016  skrll Sync with HEAD
 1.11.2.1 21-Apr-2017  bouyer Sync with HEAD
 1.13.30.1 21-Mar-2021  thorpej Give config_found() the same variadic arguments treatment as
config_search(). This commit only adds the CFARG_EOL sentinel
to the existing config_found() calls. Conversion of config_found_sm_loc()
and config_found_ia() call sites will be in subsequent commits.
 1.14.8.1 04-Aug-2021  thorpej Adapt to CFARGS().
 1.3 02-Feb-2017  macallan support anti-aliased fonts, glyphcache etc.
 1.2 23-Mar-2011  macallan branches: 1.2.4; 1.2.16; 1.2.34; 1.2.38; 1.2.42;
complete the driver/bus frontend split and make sure the driver can deal with
both PCI and VLB variants of the chip
 1.1 09-Feb-2011  macallan branches: 1.1.2; 1.1.4;
split out the bus-independent portions of chipsfb
 1.1.4.3 21-Apr-2011  rmind sync with head
 1.1.4.2 05-Mar-2011  rmind sync with head
 1.1.4.1 09-Feb-2011  rmind file ct65550reg.h was added on branch rmind-uvmplock on 2011-03-05 20:53:14 +0000
 1.1.2.2 17-Feb-2011  bouyer Sync with HEAD
 1.1.2.1 09-Feb-2011  bouyer file ct65550reg.h was added on branch bouyer-quota2 on 2011-02-17 12:00:12 +0000
 1.2.42.1 21-Apr-2017  bouyer Sync with HEAD
 1.2.38.1 20-Mar-2017  pgoyette Sync with HEAD
 1.2.34.1 05-Feb-2017  skrll Sync with HEAD
 1.2.16.1 03-Dec-2017  jdolecek update from HEAD
 1.2.4.2 06-Jun-2011  jruoho Sync with HEAD.
 1.2.4.1 23-Mar-2011  jruoho file ct65550reg.h was added on branch jruoho-x86intr on 2011-06-06 09:07:52 +0000
 1.3 02-Feb-2017  macallan support anti-aliased fonts, glyphcache etc.
 1.2 23-Mar-2011  macallan branches: 1.2.4; 1.2.16; 1.2.34; 1.2.38; 1.2.42;
complete the driver/bus frontend split and make sure the driver can deal with
both PCI and VLB variants of the chip
 1.1 09-Feb-2011  macallan branches: 1.1.2; 1.1.4;
split out the bus-independent portions of chipsfb
 1.1.4.3 21-Apr-2011  rmind sync with head
 1.1.4.2 05-Mar-2011  rmind sync with head
 1.1.4.1 09-Feb-2011  rmind file ct65550var.h was added on branch rmind-uvmplock on 2011-03-05 20:53:14 +0000
 1.1.2.2 17-Feb-2011  bouyer Sync with HEAD
 1.1.2.1 09-Feb-2011  bouyer file ct65550var.h was added on branch bouyer-quota2 on 2011-02-17 12:00:12 +0000
 1.2.42.1 21-Apr-2017  bouyer Sync with HEAD
 1.2.38.1 20-Mar-2017  pgoyette Sync with HEAD
 1.2.34.1 05-Feb-2017  skrll Sync with HEAD
 1.2.16.1 03-Dec-2017  jdolecek update from HEAD
 1.2.4.2 06-Jun-2011  jruoho Sync with HEAD.
 1.2.4.1 23-Mar-2011  jruoho file ct65550var.h was added on branch jruoho-x86intr on 2011-06-06 09:07:52 +0000
 1.63 26-Oct-2022  riastradh cy(4): Convert to ttylock/ttyunlock.
 1.62 10-Nov-2019  chs in many device attach paths, allocate memory with M_WAITOK instead of M_NOWAIT
and remove code to handle failures that can no longer happen.
 1.61 28-Oct-2017  riastradh branches: 1.61.4;
Kill some more extern struct cfdriver declarations.

Down with externs in .c!
 1.60 15-Nov-2014  christos centralize the dialout/call unit macros.
 1.59 25-Jul-2014  dholland Add d_discard to all struct cdevsw instances I could find.

All have been set to "nodiscard"; some should get a real implementation.
 1.58 24-Apr-2011  rmind branches: 1.58.14; 1.58.28;
Rename ttymalloc() to tty_alloc(), and ttyfree() to tty_free() for
consistency. Remove some unnecessary malloc.h inclusions as well.
 1.57 23-Nov-2009  rmind branches: 1.57.4; 1.57.6;
Remove some unecessary includes sys/user.h header.
 1.56 25-May-2008  ad Properly fix the "hanging in tty" bug that was worked around with cv_wakeup()
some time again.
 1.55 26-Mar-2008  matt branches: 1.55.2; 1.55.4; 1.55.6;
split device_t/softc. Use aprint_*_dev and device_xname.
switch to device_lookup_private.
 1.54 19-Nov-2007  ad branches: 1.54.14;
- Factor out too many copies of the same bit of tty code.
- Fix another tty signalling/wakeup problem.
 1.53 07-Nov-2007  ad Merge tty changes from the vmlocking branch.
 1.52 19-Oct-2007  ad branches: 1.52.2;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.51 09-Jul-2007  ad branches: 1.51.6; 1.51.8; 1.51.12;
Merge some of the less invasive changes from the vmlocking branch:

- kthread, callout, devsw API changes
- select()/poll() improvements
- miscellaneous MT safety improvements
 1.50 04-Mar-2007  christos branches: 1.50.2; 1.50.4;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.49 29-Jan-2007  hubertf branches: 1.49.2;
Remove more duplicate headers.
Patch by Slava Semushin <slava.semushin@gmail.com>

Again, this was tested by comparing obj files from a pristine and a patched
source tree against an i386/ALL kernel, and also for src/sbin/fsck_ffs,
src/sbin/fsdb and src/usr.sbin/makefs. Only changes in assert() line numbers
were detected in 'objdump -d' output.
 1.48 16-Nov-2006  christos __unused removal on arguments; approved by core.
 1.47 12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.46 01-Oct-2006  elad More from Matt Fleming:

Adapt to KAUTH_DEVICE_TTY_PRIVSET and KAUTH_DEVICE_TTY_OPEN.
 1.45 01-Oct-2006  elad Adapt MD code to KAUTH_DEVICE_TTY_OPEN, batch #2 from Matt Fleming, thanks!

Also, add forgotten splx() calls in some places.
 1.44 21-Jul-2006  ad branches: 1.44.4; 1.44.6;
- Use the LWP cached credentials where sane.
- Minor cosmetic changes.
 1.43 21-May-2006  christos void casts to functions whose return values are ignored.
 1.42 14-May-2006  elad branches: 1.42.2;
integrate kauth.
 1.41 14-May-2006  christos XXX: GCC uninitialized
 1.40 05-Mar-2006  christos branches: 1.40.2; 1.40.4;
cleanup more SET/CLR/ISSET lossage
 1.39 11-Dec-2005  christos branches: 1.39.4; 1.39.6; 1.39.8;
merge ktrace-lwp.
 1.38 06-Sep-2005  kleink Change the driver open function's conditional for overriding exclusive tty
use from checking the proc's uid to suser(9), and account for the use of
privileges. Noted by David Holland in PR kern/31126.
 1.37 27-Feb-2005  perry branches: 1.37.4;
nuke trailing whitespace
 1.36 31-Oct-2003  reinoud branches: 1.36.8; 1.36.10;
Rollback
 1.35 31-Oct-2003  reinoud Make it compile under gcc 2.95 again. Without the patch it gives an `might
be used uninitialised' warning.
 1.34 29-Oct-2003  mycroft Recode to remove bogus initializer.
 1.33 25-Oct-2003  christos Fix uninitialized variable warnings
 1.32 29-Jun-2003  fvdl branches: 1.32.2;
Back out the lwp/ktrace changes. They contained a lot of colateral damage,
and need to be examined and discussed more.
 1.31 28-Jun-2003  darrenr Pass lwp pointers throughtout the kernel, as required, so that the lwpid can
be inserted into ktrace records. The general change has been to replace
"struct proc *" with "struct lwp *" in various function prototypes, pass
the lwp through and use l_proc to get the process pointer when needed.

Bump the kernel rev up to 1.6V
 1.30 31-Jan-2003  thorpej Use aprint_*().
 1.29 06-Jan-2003  wiz successful with only one l.
 1.28 23-Oct-2002  jdolecek merge kqueue branch into -current

kqueue provides a stateful and efficient event notification framework
currently supported events include socket, file, directory, fifo,
pipe, tty and device changes, and monitoring of processes and signals

kqueue is supported by all writable filesystems in NetBSD tree
(with exception of Coda) and all device drivers supporting poll(2)

based on work done by Jonathan Lemon for FreeBSD
initial NetBSD port done by Luke Mewburn and Jason Thorpe
 1.27 06-Sep-2002  gehenna Merge the gehenna-devsw branch into the trunk.

This merge changes the device switch tables from static array to
dynamically generated by config(8).

- All device switches is defined as a constant structure in device drivers.

- The new grammer ``device-major'' is introduced to ``files''.

device-major <prefix> char <num> [block <num>] [<rules>]

- All device major numbers must be listed up in port dependent majors.<arch>
by using this grammer.

- Added the new naming convention.
The name of the device switch must be <prefix>_[bc]devsw for auto-generation
of device switch tables.

- The backward compatibility of loading block/character device
switch by LKM framework is broken. This is necessary to convert
from block/character device major to device name in runtime and vice versa.

- The restriction to assign device major by LKM is completely removed.
We don't need to reserve LKM entries for dynamic loading of device switch.

- In compile time, device major numbers list is packed into the kernel and
the LKM framework will refer it to assign device major number dynamically.
 1.26 17-Mar-2002  atatat branches: 1.26.4;
Convert ioctl code to use EPASSTHROUGH instead of -1 or ENOTTY for
indicating an unhandled "command". ERESTART is -1, which can lead to
confusion. ERESTART has been moved to -3 and EPASSTHROUGH has been
placed at -4. No ioctl code should now return -1 anywhere. The
ioctl() system call is now properly restartable.
 1.25 15-Nov-2001  lukem don't need <sys/types.h> when including <sys/param.h>
 1.24 13-Nov-2001  lukem add/cleanup RCSID
 1.23 07-Jul-2001  thorpej branches: 1.23.2; 1.23.4;
bzero -> memset
 1.22 02-May-2001  scw Add `l_poll' to `struct linesw' and provide an xxxpoll() entry point
in each tty driver to indirect through it.

This allows tty line-disciplines to handle poll(2) system calls.
 1.21 21-Jan-2001  thorpej branches: 1.21.2;
Untangle some spl-spaghetti in cy_modem_control().
 1.20 20-Jan-2001  thorpej Pack the minor numbers like the Cyclades-Z driver does, and
make the dialout bit compatible with the other serial drivers
(and with what MAKEDEV generates for dtyCYxxx).
 1.19 20-Jan-2001  thorpej Only need to pass a cy_softc * to cy_attach().
 1.18 20-Jan-2001  thorpej ANSI'ify.
 1.17 20-Jan-2001  thorpej Clean up the PCI attachment a bit, and adjust the other pieces
to suit.
 1.16 01-Nov-2000  eeh Adapt to the new line discipline scheme.
 1.15 08-Jul-2000  sommerfeld When receiving an rx interrupt on a closed or unconfigured port, read
the data out of the board anyway so it won't re-interrupt anyway.
Fix tested by C Kane <ckane@best.com>
 1.14 06-Jul-2000  thorpej Use device_lookup().
 1.13 29-May-2000  tsubai branches: 1.13.2;
* Support (not so) new cards. (only Cyclom-8YsP+ is tested)
* Make compilable with CY_DEBUG.
 1.12 23-Mar-2000  thorpej branches: 1.12.2;
New callout mechanism with two major improvements over the old
timeout()/untimeout() API:
- Clients supply callout handle storage, thus eliminating problems of
resource allocation.
- Insertion and removal of callouts is constant time, important as
this facility is used quite a lot in the kernel.

The old timeout()/untimeout() API has been removed from the kernel.
 1.11 09-Sep-1999  tron branches: 1.11.2;
Add support for Cyclade boards with new Risc II serial controller.
Patches supplies by C Kane in PR kern/7175.
 1.10 22-Mar-1998  mycroft branches: 1.10.8;
Fix error in previous change.
 1.9 21-Mar-1998  mjacob Well, I don't have a Cyclades board, but I needed the alpha kernels
to compile. I made the changes that seemed to make sense tracking the
shift from TS_WOPEN to tp->t_wopen- but they may be wrong. I wasn't
subscribed to tech-kern so I missed the discussion, and C. Hannum
was not particularly enlightening. Sorry if this isn't quite right.
 1.8 12-Jan-1998  thorpej Adjust for config changes.
 1.7 17-Jun-1997  cgd fix several bugs pointed out by Jarkko Torppa <torppa@cute.fi> in PR 3753:
(1) fix a printf format (%x to print int, not %lx).
(2) fix probe of 4th chip/16th channel (used to tell whether or not the
board is a 16- or 32-port board) by removing an incorrect offset so
that the code matched its comments. (!!!)
(3) fix storage of chip number in per-channel structure so that it actually
stores the chip number, rather than the chip offset. This allows the
driver to work with more than the first four channels (i.e. with chips
other than chip number 0, which happens to have an offset of zero). (!!!)
 1.6 13-Apr-1997  cgd clean up an autoconfiguration printf. Much more should be done
 1.5 21-Oct-1996  thorpej New bus.h implementation/interface:
- No more distinction between i/o-mapped and memory-mapped
devices. It's all "bus space" now, and space tags
differentiate the space with finer grain than the
bus chipset tag.
- Add memory barrier methods.
- Implement space alloc/free methods.
- Implement region read/write methods (like memcpy to/from
bus space).
This interface provides a better abstraction for dealing with
machine-independent chipset drivers.
 1.4 13-Oct-1996  christos backout kprintf changes
 1.3 10-Oct-1996  christos - printf -> kprintf, sprintf -> ksprintf
- fix a bug where tp was used before it was initialized
- remove unused variable
 1.2 26-Sep-1996  thorpej Use "cy_port_num" rather than "cy_port" where appropriate.
 1.1 24-Sep-1996  christos New Cyclades driver from Timo Rossi
 1.10.8.2 03-Jun-2000  he Pull up revision 1.13 (requested by tsubai):
Add support for PCI variants of Cyclom-4Y and -8Y cards.
Also fixes PR#7175 (new serial controller).
 1.10.8.1 03-Jun-2000  he Pull up revision 1.11 (requested by tsubai):
Add support for PCI variants of Cyclom-4Y and -8Y cards.
 1.11.2.3 11-Feb-2001  bouyer Sync with HEAD.
 1.11.2.2 22-Nov-2000  bouyer Sync with HEAD.
 1.11.2.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.12.2.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.13.2.1 10-Nov-2000  tv Pullup 1.15 [sommerfeld]:
When receiving an rx interrupt on a closed or unconfigured port, read
the data out of the board anyway so it won't re-interrupt anyway.
Fix tested by C Kane <ckane@best.com>
 1.21.2.8 07-Jan-2003  thorpej Sync with HEAD.
 1.21.2.7 11-Nov-2002  nathanw Catch up to -current
 1.21.2.6 17-Sep-2002  nathanw Catch up to -current.
 1.21.2.5 01-Apr-2002  nathanw Catch up to -current.
(CVS: It's not just a program. It's an adventure!)
 1.21.2.4 08-Jan-2002  nathanw Catch up to -current.
 1.21.2.3 14-Nov-2001  nathanw Catch up to -current.
 1.21.2.2 24-Aug-2001  nathanw Catch up with -current.
 1.21.2.1 21-Jun-2001  nathanw Catch up to -current.
 1.23.4.3 13-Oct-2001  fvdl Revert the t_dev -> t_devvp change in struct tty. The way that tty
structs are currently used (especially by console ttys) aren't
ready for it, and this will require quite a few changes.
 1.23.4.2 26-Sep-2001  fvdl * add a VCLONED vnode flag that indicates a vnode representing a cloned
device.
* rename REVOKEALL to REVOKEALIAS, and add a REVOKECLONE flag, to pass
to VOP_REVOKE
* the revoke system call will revoke all aliases, as before, but not the
clones
* vdevgone is called when detaching a device, so make it use REVOKECLONE
to get rid of all clones as well
* clean up all uses of VOP_OPEN wrt. locking.
* add a few VOPS to spec_vnops that need to do something when it's a
clone vnode (access and getattr)
* add a copy of the vnode vattr structure of the original 'master' vnode
to the specinfo of a cloned vnode. could possibly redirect getattr to
the 'master' vnode, but this has issues with revoke
* add a vdev_reassignvp function that disassociates a vnode from its
original device, and reassociates it with the specified dev_t. to be
used by cloning devices only, in case a new minor is allocated.
* change all direct references in drivers to v_devcookie and v_rdev
to vdev_privdata(vp) and vdev_rdev(vp). for diagnostic purposes
when debugging race conditions that still exist wrt. locking and
revoking vnodes.
* make the locking state of a vnode consistent when passed to
d_open and d_close (unlocked). locked would be better, but has
some deadlock issues
 1.23.4.1 07-Sep-2001  thorpej Commit my "devvp" changes to the thorpej-devvp branch. This
replaces the use of dev_t in most places with a struct vnode *.

This will form the basic infrastructure for real cloning device
support (besides being architecurally cleaner -- it'll be good
to get away from using numbers to represent objects).
 1.23.2.3 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.23.2.2 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.23.2.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.26.4.1 16-May-2002  gehenna Add the character device switch.
 1.32.2.6 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.32.2.5 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.32.2.4 21-Sep-2004  skrll Fix the sync with head I botched.
 1.32.2.3 18-Sep-2004  skrll Sync with HEAD.
 1.32.2.2 03-Aug-2004  skrll Sync with HEAD
 1.32.2.1 02-Jul-2003  darrenr Apply the aborted ktrace-lwp changes to a specific branch. This is just for
others to review, I'm concerned that patch fuziness may have resulted in some
errant code being generated but I'll look at that later by comparing the diff
from the base to the branch with the file I attempt to apply to it. This will,
at the very least, put the changes in a better context for others to review
them and attempt to tinker with removing passing of 'struct lwp' through
the kernel.
 1.36.10.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.36.8.1 29-Apr-2005  kent sync with -current
 1.37.4.7 07-Dec-2007  yamt sync with head
 1.37.4.6 15-Nov-2007  yamt sync with head.
 1.37.4.5 27-Oct-2007  yamt sync with head.
 1.37.4.4 03-Sep-2007  yamt sync with head.
 1.37.4.3 26-Feb-2007  yamt sync with head.
 1.37.4.2 30-Dec-2006  yamt sync with head.
 1.37.4.1 21-Jun-2006  yamt sync with head.
 1.39.8.3 11-Aug-2006  yamt sync with head
 1.39.8.2 24-May-2006  yamt sync with head.
 1.39.8.1 13-Mar-2006  yamt sync with head.
 1.39.6.2 01-Jun-2006  kardel Sync with head.
 1.39.6.1 22-Apr-2006  simonb Sync with head.
 1.39.4.1 09-Sep-2006  rpaulo sync with head
 1.40.4.1 24-May-2006  tron Merge 2006-05-24 NetBSD-current into the "peter-altq" branch.
 1.40.2.2 10-Mar-2006  elad generic_authorize() -> kauth_authorize_generic().
 1.40.2.1 08-Mar-2006  elad Adapt to kernel authorization KPI.
 1.42.2.1 19-Jun-2006  chap Sync with head.
 1.44.6.2 10-Dec-2006  yamt sync with head.
 1.44.6.1 22-Oct-2006  yamt sync with head
 1.44.4.2 01-Feb-2007  ad Sync with head.
 1.44.4.1 18-Nov-2006  ad Sync with head.
 1.49.2.1 12-Mar-2007  rmind Sync with HEAD.
 1.50.4.1 11-Jul-2007  mjf Sync with head.
 1.50.2.4 23-Oct-2007  ad Sync with head.
 1.50.2.3 19-Oct-2007  ad Replace the tty locks with a global tty_lock.
 1.50.2.2 01-Jul-2007  ad Adapt to callout API change.
 1.50.2.1 05-Apr-2007  ad Compile fixes.
 1.51.12.3 21-Nov-2007  bouyer Sync with HEAD
 1.51.12.2 13-Nov-2007  bouyer Sync with HEAD
 1.51.12.1 25-Oct-2007  bouyer Sync with HEAD.
 1.51.8.3 09-Jan-2008  matt sync with HEAD
 1.51.8.2 08-Nov-2007  matt sync with -HEAD
 1.51.8.1 06-Nov-2007  matt sync with HEAD
 1.51.6.3 21-Nov-2007  joerg Sync with HEAD.
 1.51.6.2 11-Nov-2007  joerg Sync with HEAD.
 1.51.6.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.52.2.2 08-Dec-2007  mjf Sync with HEAD.
 1.52.2.1 19-Nov-2007  mjf Sync with HEAD.
 1.54.14.2 02-Jun-2008  mjf Sync with HEAD.
 1.54.14.1 03-Apr-2008  mjf Sync with HEAD.
 1.55.6.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.55.4.2 11-Mar-2010  yamt sync with head
 1.55.4.1 04-May-2009  yamt sync with head.
 1.55.2.1 04-Jun-2008  yamt sync with head
 1.57.6.1 06-Jun-2011  jruoho Sync with HEAD.
 1.57.4.1 31-May-2011  rmind sync with head
 1.58.28.1 10-Aug-2014  tls Rebase.
 1.58.14.2 03-Dec-2017  jdolecek update from HEAD
 1.58.14.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.61.4.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.5 11-Dec-2005  christos merge ktrace-lwp.
 1.4 27-Feb-2005  perry nuke trailing whitespace
 1.3 29-May-2000  tsubai branches: 1.3.26; 1.3.34; 1.3.36;
* Support (not so) new cards. (only Cyclom-8YsP+ is tested)
* Make compilable with CY_DEBUG.
 1.2 09-Sep-1999  tron branches: 1.2.2; 1.2.10;
Add support for Cyclade boards with new Risc II serial controller.
Patches supplies by C Kane in PR kern/7175.
 1.1 24-Sep-1996  christos branches: 1.1.22;
New Cyclades driver from Timo Rossi
 1.1.22.1 03-Jun-2000  he Pull up revisions 1.2-1.3 (requested by tsubai):
Add support for PCI variants of Cyclom-4Y and -8Y cards.
Also fixes PR#7175 (new serial controller).
 1.2.10.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.2.2.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.3.36.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.3.34.1 29-Apr-2005  kent sync with -current
 1.3.26.1 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.9 26-Mar-2008  matt split device_t/softc. Use aprint_*_dev and device_xname.
switch to device_lookup_private.
 1.8 20-Jan-2001  thorpej branches: 1.8.122;
Pack the minor numbers like the Cyclades-Z driver does, and
make the dialout bit compatible with the other serial drivers
(and with what MAKEDEV generates for dtyCYxxx).
 1.7 20-Jan-2001  thorpej Only need to pass a cy_softc * to cy_attach().
 1.6 20-Jan-2001  thorpej ANSI'ify.
 1.5 09-Sep-1999  tron branches: 1.5.2;
Add support for Cyclade boards with new Risc II serial controller.
Patches supplies by C Kane in PR kern/7175.
 1.4 17-Jun-1997  cgd branches: 1.4.16;
the port number is the low 5 bits of the minor. That means that it should
be masked with 0x1f (the low 5 bits), rather than 0x0f (the low four bits).
Pointed out by Jarkko Torppa <torppa@cute.fi> in PR 3753.
 1.3 13-Apr-1997  cgd don't bother keeping around the i/o tag. It's useless by itself, and
without other significant changes to this driver wouldn't be particularly
useful to keep around permanently anyway.
 1.2 21-Oct-1996  thorpej New bus.h implementation/interface:
- No more distinction between i/o-mapped and memory-mapped
devices. It's all "bus space" now, and space tags
differentiate the space with finer grain than the
bus chipset tag.
- Add memory barrier methods.
- Implement space alloc/free methods.
- Implement region read/write methods (like memcpy to/from
bus space).
This interface provides a better abstraction for dealing with
machine-independent chipset drivers.
 1.1 24-Sep-1996  christos New Cyclades driver from Timo Rossi
 1.4.16.1 03-Jun-2000  he Pull up revision 1.5 (requested by tsubai):
Add support for PCI variants of Cyclom-4Y and -8Y cards.
Also fixes PR#7175 (new serial controller).
 1.5.2.1 11-Feb-2001  bouyer Sync with HEAD.
 1.8.122.1 03-Apr-2008  mjf Sync with HEAD.
 1.33 19-Sep-2018  maxv Remove daic(4), it has never been functional.

ok martin@
 1.32 30-Aug-2015  martin branches: 1.32.16; 1.32.18;
Remove double spl(x), found by brainy.
 1.31 27-Oct-2012  chs branches: 1.31.14;
split device_t/softc for all remaining drivers.
replace "struct device *" with "device_t".
use device_xname(), device_unit(), etc.
 1.30 27-Jul-2010  martin branches: 1.30.8; 1.30.18;
Make it compile again
 1.29 12-May-2009  cegger branches: 1.29.2; 1.29.4;
struct device * -> device_t, no functional changes intended.
 1.28 14-Mar-2009  dsl Change about 4500 of the K&R function definitions to ANSI ones.
There are still about 1600 left, but they have ',' or /* ... */
in the actual variable definitions - which my awk script doesn't handle.
There are also many that need () -> (void).
(The script does handle misordered arguments.)
 1.27 28-Apr-2008  martin branches: 1.27.8; 1.27.14;
Remove clause 3 and 4 from TNF licenses
 1.26 08-Apr-2008  cegger branches: 1.26.2; 1.26.4;
use aprint_*_dev and device_xname
 1.25 19-Oct-2007  ad branches: 1.25.16;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.24 25-Feb-2007  martin branches: 1.24.4; 1.24.16; 1.24.18; 1.24.22;
Make it at least compile again (const propagation)
 1.23 11-Dec-2005  christos branches: 1.23.26;
merge ktrace-lwp.
 1.22 27-Feb-2005  perry branches: 1.22.4;
nuke trailing whitespace
 1.21 04-Feb-2005  perry de-__P
 1.20 13-Aug-2004  pooka branches: 1.20.4; 1.20.6;
kill "magic" number
 1.19 22-Apr-2004  itojun sprintf -> snprintf
 1.18 24-Feb-2004  wiz parameter with two es. From Peter Postma.
 1.17 04-Dec-2003  keihan netbsd.org -> NetBSD.org

This was the last commit of this kind to src/sys, which is now totally
"NetBSD.org clean". Thanks for the patiance, and sorry for all the commits.
 1.16 02-Nov-2003  wiz Fix some typos. From Tom Cosgrove via jmc@openbsd.
 1.15 07-Oct-2003  martin Adapt to recent PRI changes.
 1.14 06-Apr-2003  wiz branches: 1.14.2;
Respect the law: Use A-law and mu-law as spellings as far as easily possible.
Inspired by Igor Sobrado in PR 19680.
 1.13 04-Feb-2003  martin Fix swapped malloc parameters - caught by recent malloce(9) changes.
 1.12 14-Apr-2002  martin Fix copyright notice.
 1.11 30-Mar-2002  martin Avoid duplicate expensive lookups by passing a pointer to the call
descriptor/a pointer to the layer 3 state directly to driver functions,
instead of their ID/index.
 1.10 29-Mar-2002  martin Split BRI attaching into two phases, so lower layer drivers can get their
BRI identifier and L3 driver state early on, then finish initializing and
announce the controller to userland when it's ready.
 1.9 25-Mar-2002  martin Fix confusion about the return value from the internal MI probe routine.
Make the ISA probe actually (silently) fail if no card is found.

XXX - need to aquire the SBUS variant of this card some day or have
Jaromir find an MCA one.
 1.8 24-Mar-2002  martin Now that we have all the pieces of the puzzle available start to unriddle
and move them in their proper places.

Move the BRI registry from layer 2 (duh!) to layer 4, so active cards
(which don't have layer 3 or layer 2 in their driver). Remove all remaining
hard coded controller and driver types. Remove any arbitrary hard coded
limits, at least those that show up in the internal API.

This fixes PR 15950.
 1.7 22-Mar-2002  martin Bring the daic driver into the new ISDN world order.
Enable active card support in the ISDN subsystem. (Had been disabled since
it couldn't be tested before.)
 1.6 15-Nov-2001  lukem don't need <sys/types.h> when including <sys/param.h>
 1.5 13-Nov-2001  lukem add/cleanup RCSID
 1.4 07-Jul-2001  thorpej branches: 1.4.2;
bzero -> memset
 1.3 07-Jul-2001  thorpej bcopy -> memcpy
 1.2 13-Jun-2001  wiz withough -> without
 1.1 05-Jan-2001  martin branches: 1.1.1;
Initial revision
 1.1.1.1 05-Jan-2001  martin branches: 1.1.1.1.2; 1.1.1.1.4;
Initial import of ISDN4BSD release 0.96
 1.1.1.1.4.6 17-Apr-2002  nathanw Catch up to -current.
 1.1.1.1.4.5 01-Apr-2002  nathanw Catch up to -current.
(CVS: It's not just a program. It's an adventure!)
 1.1.1.1.4.4 08-Jan-2002  nathanw Catch up to -current.
 1.1.1.1.4.3 14-Nov-2001  nathanw Catch up to -current.
 1.1.1.1.4.2 24-Aug-2001  nathanw Catch up with -current.
 1.1.1.1.4.1 21-Jun-2001  nathanw Catch up to -current.
 1.1.1.1.2.2 05-Jan-2001  bouyer Sync with HEAD
 1.1.1.1.2.1 05-Jan-2001  bouyer file daic.c was added on branch thorpej_scsipi on 2001-01-05 17:35:35 +0000
 1.4.2.2 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.4.2.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.14.2.6 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.14.2.5 04-Feb-2005  skrll Sync with HEAD.
 1.14.2.4 21-Sep-2004  skrll Fix the sync with head I botched.
 1.14.2.3 18-Sep-2004  skrll Sync with HEAD.
 1.14.2.2 25-Aug-2004  skrll Sync with HEAD.
 1.14.2.1 03-Aug-2004  skrll Sync with HEAD
 1.20.6.2 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.20.6.1 12-Feb-2005  yamt sync with head.
 1.20.4.1 29-Apr-2005  kent sync with -current
 1.22.4.2 27-Oct-2007  yamt sync with head.
 1.22.4.1 03-Sep-2007  yamt sync with head.
 1.23.26.1 27-Feb-2007  yamt - sync with head.
- move sched_changepri back to kern_synch.c as it doesn't know PPQ anymore.
 1.24.22.1 25-Oct-2007  bouyer Sync with HEAD.
 1.24.18.1 06-Nov-2007  matt sync with HEAD
 1.24.16.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.24.4.1 23-Oct-2007  ad Sync with head.
 1.25.16.1 02-Jun-2008  mjf Sync with HEAD.
 1.26.4.4 11-Aug-2010  yamt sync with head.
 1.26.4.3 16-May-2009  yamt sync with head
 1.26.4.2 04-May-2009  yamt sync with head.
 1.26.4.1 16-May-2008  yamt sync with head.
 1.26.2.1 18-May-2008  yamt sync with head.
 1.27.14.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.27.8.1 28-Apr-2009  skrll Sync with HEAD.
 1.29.4.1 05-Mar-2011  rmind sync with head
 1.29.2.1 17-Aug-2010  uebayasi Sync with HEAD.
 1.30.18.2 03-Dec-2017  jdolecek update from HEAD
 1.30.18.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.30.8.1 30-Oct-2012  yamt sync with head
 1.31.14.1 22-Sep-2015  skrll Sync with HEAD
 1.32.18.1 10-Jun-2019  christos Sync with HEAD
 1.32.16.1 30-Sep-2018  pgoyette Ssync with HEAD
 1.7 19-Sep-2018  maxv Remove daic(4), it has never been functional.

ok martin@
 1.6 28-Apr-2008  martin branches: 1.6.86; 1.6.88;
Remove clause 3 and 4 from TNF licenses
 1.5 11-Dec-2005  christos branches: 1.5.70; 1.5.72; 1.5.74;
merge ktrace-lwp.
 1.4 04-Dec-2003  keihan netbsd.org -> NetBSD.org

This was the last commit of this kind to src/sys, which is now totally
"NetBSD.org clean". Thanks for the patiance, and sorry for all the commits.
 1.3 14-Apr-2002  martin branches: 1.3.10;
Fix copyright notice.
 1.2 13-Jun-2001  wiz branches: 1.2.2;
withough -> without
 1.1 05-Jan-2001  martin branches: 1.1.1;
Initial revision
 1.1.1.1 05-Jan-2001  martin branches: 1.1.1.1.2; 1.1.1.1.4;
Initial import of ISDN4BSD release 0.96
 1.1.1.1.4.2 17-Apr-2002  nathanw Catch up to -current.
 1.1.1.1.4.1 21-Jun-2001  nathanw Catch up to -current.
 1.1.1.1.2.2 05-Jan-2001  bouyer Sync with HEAD
 1.1.1.1.2.1 05-Jan-2001  bouyer file daicreg.h was added on branch thorpej_scsipi on 2001-01-05 17:35:35 +0000
 1.2.2.1 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.3.10.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.3.10.2 18-Sep-2004  skrll Sync with HEAD.
 1.3.10.1 03-Aug-2004  skrll Sync with HEAD
 1.5.74.1 16-May-2008  yamt sync with head.
 1.5.72.1 18-May-2008  yamt sync with head.
 1.5.70.1 02-Jun-2008  mjf Sync with HEAD.
 1.6.88.1 10-Jun-2019  christos Sync with HEAD
 1.6.86.1 30-Sep-2018  pgoyette Ssync with HEAD
 1.13 19-Sep-2018  maxv Remove daic(4), it has never been functional.

ok martin@
 1.12 27-Oct-2012  chs branches: 1.12.36; 1.12.38;
split device_t/softc for all remaining drivers.
replace "struct device *" with "device_t".
use device_xname(), device_unit(), etc.
 1.11 12-May-2009  cegger branches: 1.11.12; 1.11.22;
struct device * -> device_t, no functional changes intended.
 1.10 28-Apr-2008  martin branches: 1.10.14;
Remove clause 3 and 4 from TNF licenses
 1.9 11-Dec-2005  christos branches: 1.9.70; 1.9.72; 1.9.74;
merge ktrace-lwp.
 1.8 27-Feb-2005  perry nuke trailing whitespace
 1.7 04-Feb-2005  perry de-__P
 1.6 04-Dec-2003  keihan branches: 1.6.8; 1.6.10;
netbsd.org -> NetBSD.org

This was the last commit of this kind to src/sys, which is now totally
"NetBSD.org clean". Thanks for the patiance, and sorry for all the commits.
 1.5 14-Apr-2002  martin branches: 1.5.10;
Fix copyright notice.
 1.4 24-Mar-2002  martin Now that we have all the pieces of the puzzle available start to unriddle
and move them in their proper places.

Move the BRI registry from layer 2 (duh!) to layer 4, so active cards
(which don't have layer 3 or layer 2 in their driver). Remove all remaining
hard coded controller and driver types. Remove any arbitrary hard coded
limits, at least those that show up in the internal API.

This fixes PR 15950.
 1.3 22-Mar-2002  martin Bring the daic driver into the new ISDN world order.
Enable active card support in the ISDN subsystem. (Had been disabled since
it couldn't be tested before.)
 1.2 13-Jun-2001  wiz branches: 1.2.2;
withough -> without
 1.1 05-Jan-2001  martin branches: 1.1.1;
Initial revision
 1.1.1.1 05-Jan-2001  martin branches: 1.1.1.1.2; 1.1.1.1.4;
Initial import of ISDN4BSD release 0.96
 1.1.1.1.4.3 17-Apr-2002  nathanw Catch up to -current.
 1.1.1.1.4.2 01-Apr-2002  nathanw Catch up to -current.
(CVS: It's not just a program. It's an adventure!)
 1.1.1.1.4.1 21-Jun-2001  nathanw Catch up to -current.
 1.1.1.1.2.2 05-Jan-2001  bouyer Sync with HEAD
 1.1.1.1.2.1 05-Jan-2001  bouyer file daicvar.h was added on branch thorpej_scsipi on 2001-01-05 17:35:35 +0000
 1.2.2.1 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.5.10.5 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.5.10.4 04-Feb-2005  skrll Sync with HEAD.
 1.5.10.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.5.10.2 18-Sep-2004  skrll Sync with HEAD.
 1.5.10.1 03-Aug-2004  skrll Sync with HEAD
 1.6.10.2 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.6.10.1 12-Feb-2005  yamt sync with head.
 1.6.8.1 29-Apr-2005  kent sync with -current
 1.9.74.2 16-May-2009  yamt sync with head
 1.9.74.1 16-May-2008  yamt sync with head.
 1.9.72.1 18-May-2008  yamt sync with head.
 1.9.70.1 02-Jun-2008  mjf Sync with HEAD.
 1.10.14.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.11.22.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.11.12.1 30-Oct-2012  yamt sync with head
 1.12.38.1 10-Jun-2019  christos Sync with HEAD
 1.12.36.1 30-Sep-2018  pgoyette Ssync with HEAD
 1.21 17-Jan-2022  andvar fix typos in comments, mainly s/foward/forward/.
 1.20 13-Aug-2021  andvar fix typos in words "pointer" and s/fram /frame/
 1.19 11-Dec-2005  christos merge ktrace-lwp.
 1.18 27-Feb-2005  perry nuke trailing whitespace
 1.17 02-Nov-2003  wiz branches: 1.17.8; 1.17.10;
Fix some typos. From Tom Cosgrove via jmc@openbsd.
 1.16 13-Jun-2001  wiz branches: 1.16.22;
withough -> without
 1.15 22-May-1998  matt branches: 1.15.26;
Change 21040 modes slightly. Prevent infinite autosense loop of 21143 that
is not connected. Make TULIP_STS_LINFAIL only valid for chips with that
status bit defined.
 1.14 27-Feb-1998  mycroft Remove some duplicate definitions.
 1.13 17-Oct-1997  matt EN1207 definitions
 1.12 15-Oct-1997  matt Some changes to get the 21142/21143 to work in 10Mb/s mode.
 1.11 08-Jun-1997  thorpej Put back Matt Thomas's revision ID, per PR 3723, submitted by
enami tsugutomo <enami@ba2.so-net.or.jp>.
 1.10 06-Jun-1997  mellon Clean up conflicts during merge (thomas de-970603)
 1.9 17-Mar-1997  thorpej Resolve conflicts from merge.
 1.8 11-Jan-1997  thorpej Merge into mainline, tidy up some debug code.
 1.7 23-Dec-1995  tls merge latest Thomas version with our minimal changes
 1.6 19-Aug-1995  cgd fix botch in one of my previous imports
 1.5 17-Aug-1995  cgd clean up 7/26 de snapshot import
 1.4 24-Jul-1995  cgd merge changes from update
 1.3 05-Jun-1995  cgd do the right thing with fixed-size types.
 1.2 05-Jun-1995  cgd kill old Id and Log. add NetBSD Id
 1.1 05-Jun-1995  cgd branches: 1.1.1;
Initial revision
 1.1.1.8 25-Aug-1997  thorpej Import the 970703 snapshot of Matt Thomas's "de" driver.
 1.1.1.7 06-Jun-1997  mellon Matt Thomas's if_de driver, 1997/6/3 snapshot
 1.1.1.6 17-Mar-1997  thorpej New DEC Tulip driver from Matt Thomas <matt@3am-software.com>.
Highligts:
- Supports media selection via if_media
- Support for Asante and better support for ZNYX boards
- Support for 21143 chips (such as found on the DE500-BA)
- Should be able to pick the BNC on the on-board 21040-based
interface in DEC Multias.
- Squish a bug here and there.
 1.1.1.5 11-Jan-1997  thorpej Update from Matt Thomas <matt@3am-software.com>. Supports more
Tulip-based cards, including new SMC and Kingston cards.
 1.1.1.4 14-Dec-1995  tls 95/12/12 snapshot of Matt Thomas's 'de' driver
 1.1.1.3 17-Aug-1995  cgd Matt Thomas's dc21040 'de' driver, July 26, '95 snapshot.
 1.1.1.2 24-Jul-1995  cgd latest from matt thomas; right name this time.
 1.1.1.1 05-Jun-1995  cgd dc21040 driver, from Matt Thomas
 1.15.26.1 21-Jun-2001  nathanw Catch up to -current.
 1.16.22.4 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.16.22.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.16.22.2 18-Sep-2004  skrll Sync with HEAD.
 1.16.22.1 03-Aug-2004  skrll Sync with HEAD
 1.17.10.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.17.8.1 29-Apr-2005  kent sync with -current
 1.1 11-Feb-2023  tsutsui branches: 1.1.2;
Port rasops'fied smg(4) framebuffer driver for VS3100 from OpenBSD/vax.

This allows using more fonts other than 8x15 pixels on smg(4).
Tested on my VAXstation 3100/m30.

Note the bitorder of smg(4) VRAM is LSB first (i.e. LSBit is the
most left side pixel) and this requires more complicated changes
to bitmask ops in MI rasops(9) because several LE machines have
VRAMs whose MSBit is connected to the most left side pixel,
but for now I prepared smg(4) specific putchar and cursor ops
based on old luna68k omrasops.
 1.1.2.2 15-Feb-2023  martin Pull up following revision(s) (requested by tsutsui in ticket #86):

sys/arch/vax/vsa/smg.c: revision 1.64
sys/arch/vax/vsa/maskbits.h: revision 1.1
sys/dev/ic/dc503reg.h: revision 1.1

Port rasops'fied smg(4) framebuffer driver for VS3100 from OpenBSD/vax.

This allows using more fonts other than 8x15 pixels on smg(4).
Tested on my VAXstation 3100/m30.

Note the bitorder of smg(4) VRAM is LSB first (i.e. LSBit is the
most left side pixel) and this requires more complicated changes
to bitmask ops in MI rasops(9) because several LE machines have
VRAMs whose MSBit is connected to the most left side pixel,
but for now I prepared smg(4) specific putchar and cursor ops
based on old luna68k omrasops.
 1.1.2.1 11-Feb-2023  martin file dc503reg.h was added on branch netbsd-10 on 2023-02-15 19:14:50 +0000
 1.3 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.2 13-Nov-2001  lukem branches: 1.2.114; 1.2.116; 1.2.118;
add/cleanup RCSID
 1.1 04-Mar-2000  elric branches: 1.1.6; 1.1.8; 1.1.10;
Definitions of standard TGA monitors as used by DEC.
 1.1.10.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.1.8.1 14-Nov-2001  nathanw Catch up to -current.
 1.1.6.2 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.1.6.1 04-Mar-2000  bouyer file decmonitors.c was added on branch thorpej_scsipi on 2000-11-20 11:40:29 +0000
 1.2.118.1 16-May-2008  yamt sync with head.
 1.2.116.1 18-May-2008  yamt sync with head.
 1.2.114.1 02-Jun-2008  mjf Sync with HEAD.
 1.19 07-Aug-2021  thorpej Merge thorpej-cfargs2.
 1.18 24-Apr-2021  thorpej branches: 1.18.8;
Merge thorpej-cfargs branch:

Simplify and make extensible the config_search() / config_found() /
config_attach() interfaces: rather than having different variants for
which arguments you want pass along, just have a single call that
takes a variadic list of tag-value arguments.

Adjust all call sites:
- Simplify wherever possible; don't pass along arguments that aren't
actually needed.
- Don't be explicit about what interface attribute is attaching if
the device only has one. (More simplification.)
- Add a config_probe() function to be used in indirect configuiration
situations, making is visibly easier to see when indirect config is
in play, and allowing for future change in semantics. (As of now,
this is just a wrapper around config_match(), but that is an
implementation detail.)

Remove unnecessary or redundant interface attributes where they're not
needed.

There are currently 5 "cfargs" defined:
- CFARG_SUBMATCH (submatch function for direct config)
- CFARG_SEARCH (search function for indirect config)
- CFARG_IATTR (interface attribte)
- CFARG_LOCATORS (locators array)
- CFARG_DEVHANDLE (devhandle_t - wraps OFW, ACPI, etc. handles)

...and a sentinel value CFARG_EOL.

Add some extra sanity checking to ensure that interface attributes
aren't ambiguous.

Use CFARG_DEVHANDLE in MI FDT, OFW, and ACPI code, and macppc and shark
ports to associate those device handles with device_t instance. This
will trickle trough to more places over time (need back-end for pre-OFW
Sun OBP; any others?).
 1.17 28-Apr-2008  martin branches: 1.17.104;
Remove clause 3 and 4 from TNF licenses
 1.16 04-Apr-2008  tsutsui branches: 1.16.2; 1.16.4;
Split device_t/softc for le(4) and variants and misc cosmetic changes.
 1.15 19-Oct-2007  ad branches: 1.15.16;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.14 16-Nov-2006  christos branches: 1.14.8; 1.14.22; 1.14.24; 1.14.28;
__unused removal on arguments; approved by core.
 1.13 12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.12 25-Mar-2006  thorpej branches: 1.12.8; 1.12.10;
Use device_parent().
 1.11 11-Dec-2005  christos branches: 1.11.4; 1.11.6; 1.11.8; 1.11.10; 1.11.12;
merge ktrace-lwp.
 1.10 07-Aug-2003  agc branches: 1.10.16;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22364, verified by myself.
 1.9 01-Jan-2003  thorpej branches: 1.9.2;
Use aprint_normal() in cfprint routines.
 1.8 02-Oct-2002  thorpej Add trailing ; to CFATTACH_DECL.
 1.7 30-Sep-2002  thorpej Use CFATTACH_DECL().
 1.6 27-Sep-2002  thorpej Declare all cfattach structures const.
 1.5 27-Sep-2002  thorpej Rather than referencing the cfdriver directly in the cfdata entries,
instead use a string naming the driver. The cfdriver is then looked
up in a list which is built at run-time.
 1.4 13-Nov-2001  lukem add/cleanup RCSID
 1.3 08-Jul-2001  thorpej branches: 1.3.2;
Remove unnecessary include files, from Onno van der Linden.
 1.2 12-Jun-2001  thorpej Don't need INET or NS includes here.
 1.1 11-Aug-2000  thorpej branches: 1.1.2; 1.1.4; 1.1.6;
Add support for the DEC DE422 Ethernet, which is a DEPCA
attached to the EISA bus. This board is commonly found
on Alpha Jensen systems.
 1.1.6.5 03-Jan-2003  thorpej Sync with HEAD.
 1.1.6.4 18-Oct-2002  nathanw Catch up to -current.
 1.1.6.3 14-Nov-2001  nathanw Catch up to -current.
 1.1.6.2 24-Aug-2001  nathanw Catch up with -current.
 1.1.6.1 21-Jun-2001  nathanw Catch up to -current.
 1.1.4.2 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.1.4.1 11-Aug-2000  bouyer file depca.c was added on branch thorpej_scsipi on 2000-11-20 11:40:29 +0000
 1.1.2.2 11-Aug-2000  thorpej Pullup from trunk:
Add support for the DEC DE422 Ethernet, which is a DEPCA
attached to the EISA bus. This board is commonly found
on Alpha Jensen systems.
 1.1.2.1 11-Aug-2000  thorpej file depca.c was added on branch netbsd-1-5 on 2000-08-11 18:16:49 +0000
 1.3.2.2 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.3.2.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.9.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.9.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.9.2.1 03-Aug-2004  skrll Sync with HEAD
 1.10.16.2 27-Oct-2007  yamt sync with head.
 1.10.16.1 21-Jun-2006  yamt sync with head.
 1.11.12.1 28-Mar-2006  tron Merge 2006-03-28 NetBSD-current into the "peter-altq" branch.
 1.11.10.1 19-Apr-2006  elad sync with head.
 1.11.8.1 01-Apr-2006  yamt sync with head.
 1.11.6.1 22-Apr-2006  simonb Sync with head.
 1.11.4.1 09-Sep-2006  rpaulo sync with head
 1.12.10.2 10-Dec-2006  yamt sync with head.
 1.12.10.1 22-Oct-2006  yamt sync with head
 1.12.8.1 18-Nov-2006  ad Sync with head.
 1.14.28.1 25-Oct-2007  bouyer Sync with HEAD.
 1.14.24.1 06-Nov-2007  matt sync with HEAD
 1.14.22.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.14.8.1 23-Oct-2007  ad Sync with head.
 1.15.16.1 02-Jun-2008  mjf Sync with HEAD.
 1.16.4.1 16-May-2008  yamt sync with head.
 1.16.2.1 18-May-2008  yamt sync with head.
 1.17.104.1 21-Mar-2021  thorpej Give config_found() the same variadic arguments treatment as
config_search(). This commit only adds the CFARG_EOL sentinel
to the existing config_found() calls. Conversion of config_found_sm_loc()
and config_found_ia() call sites will be in subsequent commits.
 1.18.8.1 04-Aug-2021  thorpej Adapt to CFARGS().
 1.4 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.3 11-Dec-2005  christos branches: 1.3.70; 1.3.72; 1.3.74;
merge ktrace-lwp.
 1.2 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22364, verified by myself.
 1.1 11-Aug-2000  thorpej branches: 1.1.2; 1.1.4; 1.1.28;
Add support for the DEC DE422 Ethernet, which is a DEPCA
attached to the EISA bus. This board is commonly found
on Alpha Jensen systems.
 1.1.28.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.1.28.2 18-Sep-2004  skrll Sync with HEAD.
 1.1.28.1 03-Aug-2004  skrll Sync with HEAD
 1.1.4.2 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.1.4.1 11-Aug-2000  bouyer file depcareg.h was added on branch thorpej_scsipi on 2000-11-20 11:40:30 +0000
 1.1.2.2 11-Aug-2000  thorpej Pullup from trunk:
Add support for the DEC DE422 Ethernet, which is a DEPCA
attached to the EISA bus. This board is commonly found
on Alpha Jensen systems.
 1.1.2.1 11-Aug-2000  thorpej file depcareg.h was added on branch netbsd-1-5 on 2000-08-11 18:16:49 +0000
 1.3.74.1 16-May-2008  yamt sync with head.
 1.3.72.1 18-May-2008  yamt sync with head.
 1.3.70.1 02-Jun-2008  mjf Sync with HEAD.
 1.6 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.5 04-Apr-2008  tsutsui branches: 1.5.2; 1.5.4;
Split device_t/softc for le(4) and variants and misc cosmetic changes.
 1.4 11-Dec-2005  christos branches: 1.4.70;
merge ktrace-lwp.
 1.3 27-Feb-2005  perry nuke trailing whitespace
 1.2 07-Aug-2003  agc branches: 1.2.8; 1.2.10;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22364, verified by myself.
 1.1 11-Aug-2000  thorpej branches: 1.1.2; 1.1.4; 1.1.28;
Add support for the DEC DE422 Ethernet, which is a DEPCA
attached to the EISA bus. This board is commonly found
on Alpha Jensen systems.
 1.1.28.4 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.1.28.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.1.28.2 18-Sep-2004  skrll Sync with HEAD.
 1.1.28.1 03-Aug-2004  skrll Sync with HEAD
 1.1.4.2 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.1.4.1 11-Aug-2000  bouyer file depcavar.h was added on branch thorpej_scsipi on 2000-11-20 11:40:30 +0000
 1.1.2.2 11-Aug-2000  thorpej Pullup from trunk:
Add support for the DEC DE422 Ethernet, which is a DEPCA
attached to the EISA bus. This board is commonly found
on Alpha Jensen systems.
 1.1.2.1 11-Aug-2000  thorpej file depcavar.h was added on branch netbsd-1-5 on 2000-08-11 18:16:50 +0000
 1.2.10.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.2.8.1 29-Apr-2005  kent sync with -current
 1.4.70.1 02-Jun-2008  mjf Sync with HEAD.
 1.5.4.1 16-May-2008  yamt sync with head.
 1.5.2.1 18-May-2008  yamt sync with head.
 1.17 01-Jul-2021  thorpej Make sure the media / mii members in struct ethercom are initialized
so that the media-related ioctls work. Problem reported by Björn Johannesson
on current-users@.

XXX pullup-9
 1.16 30-Jun-2021  thorpej Fix a couple of problems with MII-equipped NE2000 derivatives reported by
Björn Johannesson on current-users@:

- Re-factor dp8390_stop() into dp8390_halt() (that does the stuff to
halt the hardware) and dp8390_stop() (which alls dp8390_halt() before
calling mii_down() via sc->sc_stop_card()). This prevents us from
calling mii_down() before all of the interface data structures have
been set up, which these days can trip a KASSERT().

- Add a 1-second timer to call mii_tick(), and enable it in the
sc->sc_init_card() callback, and cancel it in the sc->sc_stop_card()
and sc->sc_media_fini() callbacks. This is actually a long-standing
bug that previously didn't have much practical effect, but causes
problems with dhcpcd's link live-ness detection logic.
 1.15 04-Feb-2020  thorpej branches: 1.15.10;
Use ifmedia_fini().
 1.14 29-May-2019  msaitoh branches: 1.14.2; 1.14.4;
No functional change:
- Simplify MII structure initialization and reference.
- KNF
 1.13 22-Jan-2019  msaitoh Change MII PHY read/write API from:

int (*mii_readreg_t)(device_t, int, int);
void (*mii_writereg_t)(device_t, int, int, int);
to:

int (*mii_readreg_t)(device_t, int, int, uint16_t *);
int (*mii_writereg_t)(device_t, int, int, uint16_t);

Now we can test if a read/write operation failed or not by the return value.

In 802.3 spec says that the PHY shall not respond to read/write transaction
to the unimplemented register(22.2.4.3). Detecting timeout can be used to
check whether a register is implemented or not (if the register conforms to
the spec). ukphy(4) can be used this for MII_MMDACR and MII_MMDAADR.

Note that I noticed that the following code do infinite loop in the
read/wirte function. If it accesses unimplemented PHY register, it will hang.
It should be fixed:

arm/at91/at91emac.c
arm/ep93xx/epe.c
arm/omap/omapl1x_emac.c
mips/ralink/ralink_eth.c
arch/powerpc/booke/dev/pq3etsec.c(read)
dev/cadence/if_cemac.c <- hkenken
dev/ic/lan9118.c


Tested with the following device:

axe+ukphy
axe+rgephy
axen+rgephy (tested by Andrius V)
wm+atphy
wm+ukphy
wm+igphy
wm+ihphy
wm+makphy
sk+makphy
sk+brgphy
sk+gentbi
msk+makphy
sip+icsphy
sip+ukphy
re+rgephy
bge+brgphy
bnx+brgphy
gsip+gphyter
rtk+rlphy
fxp+inphy (tested by Andrius V)
tlp+acphy
ex+exphy
epic+qsphy
vge+ciphy (tested by Andrius V)
vr+ukphy (tested by Andrius V)
vte+ukphy (tested by Andrius V)

Not tested (MAC):
arm:at91emac
arm:cemac
arm:epe
arm:geminigmac
arm:enet
arm:cpsw
arm:emac(omac)
arm:emac(sunxi)
arm:npe
evbppc:temac
macppc:bm
macppc:gm
mips:aumac
mips:ae
mips:cnmac
mips:reth
mips:sbmac
playstation2:smap
powerpc:tsec
powerpc:emac(ibm4xx)
sgimips:mec
sparc:be
sf
ne(ax88190, dl10019)
awge
ep
gem
hme
smsh
mtd
sm
age
alc
ale
bce
cas
et
jme
lii
nfe
pcn
ste
stge
tl
xi
aue
mue
smsc
udav
url

Not tested (PHY):
amhphy
bmtphy
dmphy
etphy
glxtphy
ikphy
iophy
lxtphy
nsphyter
pnaphy
rdcphy
sqphy
tlphy
tqphy
urlphy
 1.12 22-Jul-2012  matt branches: 1.12.38; 1.12.40;
Fix mii_statchg to take a 'struct ifnet *' instead of device_t. This fixes
problem with a common MDIO bus used for multiple interfaces.
Some drivers converted to CFATTACL_DECL_NEW.
 1.11 28-Apr-2008  martin branches: 1.11.34;
Remove clause 3 and 4 from TNF licenses
 1.10 12-Mar-2008  cube branches: 1.10.2; 1.10.4;
Split device_t and softc for the NE2000 Ethernet chip and all its variants
and attachments. Use device_t accessors, correct types, and ANSIfy when
appropriate.
 1.9 19-Jan-2008  dyoung branches: 1.9.2; 1.9.6;
Make many ethernet drivers share the common code for MII media
handling, ether_mediastatus() and ether_mediachange(). Check for
a non-ENXIO error return from mii_mediachg(). (ENXIO indicates
that a PHY is suspended.)

This patch shrinks the source code size by 979 lines. There was
a 5100-byte savings on the NetBSD/i386 kernel configuration, ALL.

I have made a few miscellaneous changes, too:

gem(4): use LIST_EMPTY(), LIST_FOREACH().
mtd(4): handle media ioctls, for a change!
axe(4): do not track link status in sc->axe_link any longer
nfe(4), aue(4), axe(4), udav(4), url(4): do not reset all PHYs
on a change of media

Except for the change to mtd(4), no functional changes are intended.

XXX This patch affects more architectures than I can feasibly
XXX compile and run. I have compiled macppc, sparc64, i386. I
XXX have run the patches on i386 boxen with bnx(4) and sip(4).
XXX Compiling and running on evbmips (MERAKI, ADM5120) is in
XXX progress.
 1.8 19-Oct-2007  ad branches: 1.8.2; 1.8.8;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.7 22-Oct-2002  fair branches: 1.7.22; 1.7.64; 1.7.78; 1.7.80; 1.7.84;
Change the "dontcare bits" argument to ifmedia_init() to IFM_IMASK
so that it is possible select PHY instances other than the first
one (instance zero), if there is more than one PHY attached.
 1.6 13-Nov-2001  lukem add/cleanup RCSID
 1.5 08-Jul-2001  thorpej branches: 1.5.2;
Remove unnecessary include files, from Onno van der Linden.
 1.4 05-Jul-2001  thorpej D'oh, use the right bitbang ops for the DL10022, pointed out by
Masanori Kanaoka <kanaoka@ann.hi-ho.ne.jp>.
 1.3 12-Jun-2001  thorpej Don't need INET or NS includes here.
 1.2 03-Jun-2001  thorpej Use the correct bitbang ops on the DL10022 (oops!).
 1.1 13-Feb-2001  thorpej branches: 1.1.2; 1.1.4;
Support for the MII on the D-Link DL10019/DL10022 NE2000-compatible
Ethernet chips.
 1.1.4.2 12-Mar-2001  bouyer Sync with HEAD.
 1.1.4.1 13-Feb-2001  bouyer file dl10019.c was added on branch thorpej_scsipi on 2001-03-12 13:30:16 +0000
 1.1.2.4 11-Nov-2002  nathanw Catch up to -current
 1.1.2.3 14-Nov-2001  nathanw Catch up to -current.
 1.1.2.2 24-Aug-2001  nathanw Catch up with -current.
 1.1.2.1 21-Jun-2001  nathanw Catch up to -current.
 1.5.2.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.7.84.1 25-Oct-2007  bouyer Sync with HEAD.
 1.7.80.2 23-Mar-2008  matt sync with HEAD
 1.7.80.1 06-Nov-2007  matt sync with HEAD
 1.7.78.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.7.64.1 23-Oct-2007  ad Sync with head.
 1.7.22.3 17-Mar-2008  yamt sync with head.
 1.7.22.2 21-Jan-2008  yamt sync with head
 1.7.22.1 27-Oct-2007  yamt sync with head.
 1.8.8.1 20-Jan-2008  bouyer Sync with HEAD
 1.8.2.1 18-Feb-2008  mjf Sync with HEAD.
 1.9.6.2 02-Jun-2008  mjf Sync with HEAD.
 1.9.6.1 03-Apr-2008  mjf Sync with HEAD.
 1.9.2.1 24-Mar-2008  keiichi sync with head.
 1.10.4.1 16-May-2008  yamt sync with head.
 1.10.2.1 18-May-2008  yamt sync with head.
 1.11.34.1 30-Oct-2012  yamt sync with head
 1.12.40.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.12.40.1 10-Jun-2019  christos Sync with HEAD
 1.12.38.1 26-Jan-2019  pgoyette Sync with HEAD
 1.14.4.1 29-Feb-2020  ad Sync with head.
 1.14.2.1 03-Jul-2021  martin Pull up following revision(s) (requested by thorpej in ticket #1311):

sys/dev/ic/dp8390.c: revision 1.99
sys/dev/ic/dl10019.c: revision 1.17
sys/dev/ic/ax88190.c: revision 1.18

Make sure the media / mii members in struct ethercom are initialized
so that the media-related ioctls work. Problem reported by Bj�rn Johannesson
on current-users@.

XXX pullup-9
 1.15.10.1 01-Aug-2021  thorpej Sync with HEAD.
 1.2 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.1 10-Feb-2001  thorpej branches: 1.1.2; 1.1.124; 1.1.126; 1.1.128;
Register definitions for the D-Link DL10019 and DL10022 Ethernet
chips. These are NE2000-compatible chips with an MII interface
on them for media.
 1.1.128.1 16-May-2008  yamt sync with head.
 1.1.126.1 18-May-2008  yamt sync with head.
 1.1.124.1 02-Jun-2008  mjf Sync with HEAD.
 1.1.2.2 11-Feb-2001  bouyer Sync with HEAD.
 1.1.2.1 10-Feb-2001  bouyer file dl10019reg.h was added on branch thorpej_scsipi on 2001-02-11 19:15:28 +0000
 1.2 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.1 13-Feb-2001  thorpej branches: 1.1.4; 1.1.124; 1.1.126; 1.1.128;
Support for the MII on the D-Link DL10019/DL10022 NE2000-compatible
Ethernet chips.
 1.1.128.1 16-May-2008  yamt sync with head.
 1.1.126.1 18-May-2008  yamt sync with head.
 1.1.124.1 02-Jun-2008  mjf Sync with HEAD.
 1.1.4.2 12-Mar-2001  bouyer Sync with HEAD.
 1.1.4.1 13-Feb-2001  bouyer file dl10019var.h was added on branch thorpej_scsipi on 2001-03-12 13:30:16 +0000
 1.41 04-Oct-2025  thorpej Add a shared function to query the common properties used for configuring
an Ethernet address.
 1.40 09-Jul-2025  andvar Fix typos in comments:
s/mulicast/multicast/
s/muticast/multicast/
s/muliplicator/multiplicator/
s/muti-precision/multi-precision/
 1.39 25-Jun-2025  andvar s/collosion/collision/ in comment.
 1.38 01-Dec-2024  andvar s/availble/available/ in comment.
 1.37 07-Sep-2024  andvar spelling and grammar fixes, mainly in comments.
 1.36 07-Jul-2023  martin branches: 1.36.6;
Fix locking error when setting the multicast filter to accept all
multicast frames, pointed out by Lwazi Dube.
 1.35 25-Sep-2022  thorpej Remove unnecessary include of <sys/malloc.h>.
 1.34 18-Sep-2022  thorpej Eliminate use of IFF_OACTIVE.
 1.33 31-Dec-2021  riastradh sys: Use if_init wrapper function.

Exception: Not in kern_pmf.c, for the kind of silly reason that it
avoids having kern_pmf.c refer to symbols defined only in net; this
avoids a pain in the rump.
 1.32 05-Dec-2021  msaitoh s/receieve/receive/
 1.31 10-Nov-2021  msaitoh s/endianess/endianness/
 1.30 11-Sep-2021  andvar Add missing double p and d for stopped and overriden accordingly.
Fix few more typos along the way, mainly in copy-pasted comments.
 1.29 27-Jun-2020  jmcneill prop_data_data_nocopy -> prop_data_value
 1.28 02-Apr-2020  nisimura add aprint_debug_dev() call for CI20
 1.27 02-Apr-2020  skrll Fix evmips CI20 build
 1.26 31-Mar-2020  nisimura fix negated loop condition. make break when reset.
 1.25 31-Mar-2020  nisimura add comment to clearify hw nature
 1.24 31-Mar-2020  nisimura - reorgazine the entire structure to utilise ifmedia(4)/mii(4) and
redefine starting point of debug.
- nuke duplicated standard MII register definition. Davicom PHY extension
is defined in dev/mii/dmphyreg.h
 1.23 29-Mar-2020  nisimura reorganise rcv frame address filter code
 1.22 29-Jan-2020  thorpej Adopt <net/if_stats.h>.
 1.21 29-May-2019  msaitoh branches: 1.21.4;
Even if we don't use MII(4), use the common path of SIOC[GS]IFMEDIA in
sys/net/if_ethersubr.c if we can.
- Add ec_ifmedia into struct ethercom.
- ec_mii in struct ethercom is kept and used as it is. It might be used in
future. Note that some Ethernet drivers which _DOESN'T_ use mii(4) use
ec_mii for keeping the if_media. Those should be changed in future.
 1.20 28-May-2019  msaitoh Use ETHER_LOCK()/ETHER_UNLOCK() for all ethernet drivers to protect ec_multi*.
 1.19 23-May-2019  msaitoh Whitespace fix (mainly tabify).
 1.18 23-May-2019  msaitoh -No functional change:
- KNF
- u_int*_t -> uint*_t.
 1.17 24-Apr-2019  msaitoh KNF. No functional change.
 1.16 05-Feb-2019  msaitoh Remove very old IFF_NOTRAILERS flag.
 1.15 26-Jun-2018  msaitoh branches: 1.15.2;
Implement the BPF direction filter (BIOC[GS]DIRECTION). It provides backward
compatibility with BIOC[GS]SEESENT ioctl. The userland interface is the same
as FreeBSD.

This change also fixes a bug that the direction is misunderstand on some
environment by passing the direction to bpf_mtap*() instead of checking
m->m_pkthdr.rcvif.
 1.14 22-Jun-2018  msaitoh Simplify like other drivers. NULL check of ifp->if_bpf is done in
bpf_mtap(), so it's not required to do it here.
 1.13 22-Jun-2018  msaitoh It's not required to include net/bpfdesc.h. Remove it.
 1.12 29-Jul-2017  riastradh branches: 1.12.2;
Check for MCLGET failure in dme_alloc_receive_buffer.

From Ilja Van Sprundel.
 1.11 15-Dec-2016  ozaki-r branches: 1.11.8;
Move bpf_mtap and if_ipackets++ on Rx of each driver to percpuq if_input

The benefits of the change are:
- We can reduce codes
- We can provide the same behavior between drivers
- Where/When if_ipackets is counted up
- Note that some drivers still update packet statistics in their own
way (periodical update)
- Moved bpf_mtap run in softint
- This makes it easy to MP-ify bpf

Proposed on tech-kern and tech-net
 1.10 10-Jun-2016  ozaki-r branches: 1.10.2;
Introduce m_set_rcvif and m_reset_rcvif

The API is used to set (or reset) a received interface of a mbuf.
They are counterpart of m_get_rcvif, which will come in another
commit, hide internal of rcvif operation, and reduce the diff of
the upcoming change.

No functional change.
 1.9 09-Feb-2016  ozaki-r Introduce softint-based if_input

This change intends to run the whole network stack in softint context
(or normal LWP), not hardware interrupt context. Note that the work is
still incomplete by this change; to that end, we also have to softint-ify
if_link_state_change (and bpf) which can still run in hardware interrupt.

This change softint-ifies at ifp->if_input that is called from
each device driver (and ieee80211_input) to ensure Layer 2 runs
in softint (e.g., ether_input and bridge_input). To this end,
we provide a framework (called percpuq) that utlizes softint(9)
and percpu ifqueues. With this patch, rxintr of most drivers just
queues received packets and schedules a softint, and the softint
dequeues packets and does rest packet processing.

To minimize changes to each driver, percpuq is allocated in struct
ifnet for now and that is initialized by default (in if_attach).
We probably have to move percpuq to softc of each driver, but it's
future work. At this point, only wm(4) has percpuq in its softc
as a reference implementation.

Additional information including performance numbers can be found
in the thread at tech-kern@ and tech-net@:
http://mail-index.netbsd.org/tech-kern/2016/01/14/msg019997.html

Acknowledgment: riastradh@ greatly helped this work.
Thank you very much!
 1.8 12-Jun-2015  macallan actually check the return value from m_gethdr() and deal with errors
now we no longer segfault in dme_allocate_buffer()
 1.7 14-Mar-2015  macallan KNF police
 1.6 10-Mar-2015  macallan support 8bit mode, needed for ci20
 1.5 26-Nov-2014  skrll branches: 1.5.2;
Appease gcc 4.8 - from Greg Willatt in private email.
 1.4 28-Jan-2012  nisimura branches: 1.4.2; 1.4.6; 1.4.8; 1.4.16; 1.4.22;

- add DM9000 internal PHY manipulating routines.
- now capable of auto-negotiation, use this as default media selection.
- add multicast filter support.
- code cleanup.

Code update from Paul Fleischer.
 1.3 30-Jun-2011  wiz branches: 1.3.2; 1.3.6;
dependant -> dependent
 1.2 10-Sep-2010  ahoka branches: 1.2.2; 1.2.4; 1.2.10;
remove debug leftover
 1.1 08-Sep-2010  ahoka Driver for Davicom DM9000 ethernet chips.

Written by Paul Fleischer, minor modifications by me.
 1.2.10.2 05-Mar-2011  rmind sync with head
 1.2.10.1 10-Sep-2010  rmind file dm9000.c was added on branch rmind-uvmplock on 2011-03-05 20:53:14 +0000
 1.2.4.2 22-Oct-2010  uebayasi Sync with HEAD (-D20101022).
 1.2.4.1 10-Sep-2010  uebayasi file dm9000.c was added on branch uebayasi-xip on 2010-10-22 07:21:56 +0000
 1.2.2.2 09-Oct-2010  yamt sync with head
 1.2.2.1 10-Sep-2010  yamt file dm9000.c was added on branch yamt-nfs-mp on 2010-10-09 03:32:06 +0000
 1.3.6.1 18-Feb-2012  mrg merge to -current.
 1.3.2.1 17-Apr-2012  yamt sync with head
 1.4.22.2 12-Aug-2017  snj Pull up following revision(s) (requested by mrg in ticket #1473):
sys/dev/ic/dm9000.c: revision 1.12
Check for MCLGET failure in dme_alloc_receive_buffer.
From Ilja Van Sprundel.
 1.4.22.1 02-Jan-2015  martin branches: 1.4.22.1.2; 1.4.22.1.6;
Pull up following revision(s) (requested by skrll in ticket #365):
sys/dev/ic/dm9000.c: revision 1.5
sys/arch/arm/s3c2xx0/s3c2440_sdi.c: revision 1.3
Appease gcc 4.8 - from Greg Willatt in private email.
 1.4.22.1.6.1 12-Aug-2017  snj Pull up following revision(s) (requested by mrg in ticket #1473):
sys/dev/ic/dm9000.c: revision 1.12
Check for MCLGET failure in dme_alloc_receive_buffer.
From Ilja Van Sprundel.
 1.4.22.1.2.1 12-Aug-2017  snj Pull up following revision(s) (requested by mrg in ticket #1473):
sys/dev/ic/dm9000.c: revision 1.12
Check for MCLGET failure in dme_alloc_receive_buffer.
From Ilja Van Sprundel.
 1.4.16.1 18-Aug-2017  snj Pull up following revision(s) (requested by mrg in ticket #1477):
sys/dev/ic/dm9000.c: revision 1.12
Check for MCLGET failure in dme_alloc_receive_buffer.
From Ilja Van Sprundel.
 1.4.8.1 18-Aug-2017  snj Pull up following revision(s) (requested by mrg in ticket #1477):
sys/dev/ic/dm9000.c: revision 1.12
Check for MCLGET failure in dme_alloc_receive_buffer.
From Ilja Van Sprundel.
 1.4.6.1 03-Dec-2017  jdolecek update from HEAD
 1.4.2.1 18-Aug-2017  snj Pull up following revision(s) (requested by mrg in ticket #1477):
sys/dev/ic/dm9000.c: revision 1.12
Check for MCLGET failure in dme_alloc_receive_buffer.
From Ilja Van Sprundel.
 1.5.2.6 28-Aug-2017  skrll Sync with HEAD
 1.5.2.5 05-Feb-2017  skrll Sync with HEAD
 1.5.2.4 09-Jul-2016  skrll Sync with HEAD
 1.5.2.3 19-Mar-2016  skrll Sync with HEAD
 1.5.2.2 22-Sep-2015  skrll Sync with HEAD
 1.5.2.1 06-Apr-2015  skrll Sync with HEAD
 1.10.2.1 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.11.8.2 26-Jul-2018  snj Pull up following revision(s) (requested by msaitoh in ticket #938):
sys/arch/acorn32/podulebus/if_ie.c: revision 1.41
sys/arch/amiga/dev/if_es.c: revision 1.58
sys/arch/amiga/dev/if_qn.c: revision 1.45
sys/arch/arm/at91/at91emac.c: revision 1.20
sys/arch/arm/ep93xx/epe.c: revision 1.37
sys/arch/emips/ebus/if_le_ebus.c: revision 1.14
sys/arch/emips/ebus/if_le_ebus.c: revision 1.15
sys/arch/mac68k/dev/if_mc.c: revision 1.46
sys/arch/macppc/dev/am79c950.c: revision 1.39
sys/arch/newsmips/apbus/if_sn.c: revision 1.40
sys/arch/next68k/dev/mb8795.c: revision 1.59
sys/arch/playstation2/dev/if_smap.c: revision 1.25
sys/arch/playstation2/dev/if_smap.c: revision 1.26
sys/arch/sun2/dev/if_ec.c: revision 1.28
sys/arch/sun3/dev/if_ie.c: revision 1.63
sys/arch/x68k/dev/if_ne_intio.c: revision 1.19
sys/arch/xen/xen/if_xennet_xenbus.c: revision 1.75
sys/arch/xen/xen/xennetback_xenbus.c: revision 1.63
sys/dev/bi/if_ni.c: revision 1.45
sys/dev/cadence/if_cemac.c: revision 1.12
sys/dev/ic/am7990.c: revision 1.78
sys/dev/ic/am79900.c: revision 1.27
sys/dev/ic/an.c: revision 1.67
sys/dev/ic/cs89x0.c: revision 1.40
sys/dev/ic/dm9000.c: revision 1.13
sys/dev/ic/dm9000.c: revision 1.14
sys/dev/ic/dp8390.c: revision 1.88
sys/dev/ic/elink3.c: revision 1.141
sys/dev/ic/elinkxl.c: revision 1.122
sys/dev/ic/hme.c: revision 1.98
sys/dev/ic/i82586.c: revision 1.77
sys/dev/ic/lance.c: revision 1.53
sys/dev/ic/mb86950.c: revision 1.27
sys/dev/ic/mb86960.c: revision 1.86
sys/dev/ic/mtd803.c: revision 1.34
sys/dev/ic/pdq_ifsubr.c: revision 1.59
sys/dev/ic/rrunner.c: revision 1.86
sys/dev/ic/seeq8005.c: revision 1.58
sys/dev/ic/sgec.c: revision 1.47
sys/dev/ic/smc90cx6.c: revision 1.72
sys/dev/ic/smc91cxx.c: revision 1.96
sys/dev/ic/tropic.c: revision 1.49
sys/dev/ic/wi.c: revision 1.245
sys/dev/isa/if_eg.c: revision 1.93
sys/dev/isa/if_el.c: revision 1.95
sys/dev/isa/if_iy.c: revision 1.101
sys/dev/ofw/ofnet.c: revision 1.58
sys/dev/pci/if_alc.c: revision 1.27
sys/dev/pci/if_de.c: revision 1.152
sys/dev/pci/if_fpa.c: revision 1.61
sys/dev/pci/if_jme.c: revision 1.34
sys/dev/pci/if_tl.c: revision 1.108
sys/dev/pci/if_vte.c: revision 1.19
sys/dev/pci/ixgbe/ixgbe.h: revision 1.50
sys/dev/pcmcia/if_cnw.c: revision 1.62
sys/dev/pcmcia/if_malo_pcmcia.c: revision 1.17
sys/dev/pcmcia/if_ray.c: revision 1.89
sys/dev/pcmcia/if_xi.c: revision 1.81
sys/dev/pcmcia/mhzc.c: revision 1.51
sys/dev/pcmcia/xirc.c: revision 1.34
sys/dev/qbus/if_de.c: revision 1.33
sys/dev/qbus/if_qe.c: revision 1.78
sys/dev/qbus/if_qt.c: revision 1.22
sys/dev/sbus/be.c: revision 1.87
sys/dev/sbus/qe.c: revision 1.68
sys/dev/scsipi/if_se.c: revision 1.96
sys/dev/usb/if_atu.c: revision 1.59
sys/net/if_l2tp.c: revision 1.28 via patch
sys/net/if_ppp.c: revision 1.160
It's not required to include net/bpfdesc.h. Remove it.
--
Simplify like other drivers. NULL check of ifp->if_bpf is done in
bpf_mtap(), so it's not required to do it here.
--
Remove duplicated inclusion of net/bpf.h.
--
Remove duplicated inclusion of net/bpf.h.
--
Simplify bpf_mtap() call. No functional change.
 1.11.8.1 05-Aug-2017  snj Pull up following revision(s) (requested by spz in ticket #186):
sys/dev/ic/dm9000.c: revision 1.12
Check for MCLGET failure in dme_alloc_receive_buffer.
From Ilja Van Sprundel.
 1.12.2.2 28-Jul-2018  pgoyette Sync with HEAD
 1.12.2.1 25-Jun-2018  pgoyette Sync with HEAD
 1.15.2.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.15.2.1 10-Jun-2019  christos Sync with HEAD
 1.21.4.1 29-Feb-2020  ad Sync with head.
 1.36.6.1 02-Aug-2025  perseant Sync with HEAD
 1.12 05-Jul-2024  andvar s/vender/vendor/ in comments, log message and fw ohci register property.
 1.11 25-Mar-2023  andvar branches: 1.11.6;
s/deteced/detected/ and s/couner/counter/ in comments.
 1.10 31-May-2022  andvar s/longeset/longest/ and s/collsion/collision/ in comments.
 1.9 31-May-2022  andvar s/disbale/disable/ and s/enbale/enable/ in comments. also one more typo fix.
 1.8 31-May-2022  andvar fix various typos in comments, documentation and messages.
 1.7 21-Oct-2021  andvar fix various typos, mainly in comments, but also in man pages and log messages.
 1.6 08-Oct-2020  nisimura add DM9000A register definitions
 1.5 08-Oct-2020  nisimura improve register descriptions
 1.4 31-Mar-2020  nisimura - reorgazine the entire structure to utilise ifmedia(4)/mii(4) and
redefine starting point of debug.
- nuke duplicated standard MII register definition. Davicom PHY extension
is defined in dev/mii/dmphyreg.h
 1.3 30-Mar-2020  nisimura DM9000 add register description
 1.2 28-Jan-2012  nisimura branches: 1.2.48;

- add DM9000 internal PHY manipulating routines.
- now capable of auto-negotiation, use this as default media selection.
- add multicast filter support.
- code cleanup.

Code update from Paul Fleischer.
 1.1 08-Sep-2010  ahoka branches: 1.1.2; 1.1.4; 1.1.10; 1.1.14; 1.1.18;
Driver for Davicom DM9000 ethernet chips.

Written by Paul Fleischer, minor modifications by me.
 1.1.18.1 18-Feb-2012  mrg merge to -current.
 1.1.14.1 17-Apr-2012  yamt sync with head
 1.1.10.2 05-Mar-2011  rmind sync with head
 1.1.10.1 08-Sep-2010  rmind file dm9000reg.h was added on branch rmind-uvmplock on 2011-03-05 20:53:14 +0000
 1.1.4.2 22-Oct-2010  uebayasi Sync with HEAD (-D20101022).
 1.1.4.1 08-Sep-2010  uebayasi file dm9000reg.h was added on branch uebayasi-xip on 2010-10-22 07:21:56 +0000
 1.1.2.2 09-Oct-2010  yamt sync with head
 1.1.2.1 08-Sep-2010  yamt file dm9000reg.h was added on branch yamt-nfs-mp on 2010-10-09 03:32:06 +0000
 1.2.48.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.11.6.1 02-Aug-2025  perseant Sync with HEAD
 1.7 29-May-2020  rin Make this compile again. Not tested.
 1.6 31-Mar-2020  nisimura - reorgazine the entire structure to utilise ifmedia(4)/mii(4) and
redefine starting point of debug.
- nuke duplicated standard MII register definition. Davicom PHY extension
is defined in dev/mii/dmphyreg.h
 1.5 05-Mar-2020  riastradh Revert "Include opt_diagnostic.h for DIAGNOSTIC."

This did not do what I thought it did. opt_diagnostic.h is only for
the unused _DIAGNOSTIC, which seems like an abortive attempt to
incrementally convert DIAGNOSTIC to an opt_*.h option rather than a
command-line option.
 1.4 05-Mar-2020  riastradh Include opt_diagnostic.h for DIAGNOSTIC.

...at least, in header files, which may not have already included
libkern.h.
 1.3 19-Apr-2018  christos branches: 1.3.2;
s/static inline/static __inline/g for consistency.
 1.2 28-Jan-2012  nisimura branches: 1.2.46;

- add DM9000 internal PHY manipulating routines.
- now capable of auto-negotiation, use this as default media selection.
- add multicast filter support.
- code cleanup.

Code update from Paul Fleischer.
 1.1 08-Sep-2010  ahoka branches: 1.1.2; 1.1.4; 1.1.10; 1.1.14; 1.1.18;
Driver for Davicom DM9000 ethernet chips.

Written by Paul Fleischer, minor modifications by me.
 1.1.18.1 18-Feb-2012  mrg merge to -current.
 1.1.14.1 17-Apr-2012  yamt sync with head
 1.1.10.2 05-Mar-2011  rmind sync with head
 1.1.10.1 08-Sep-2010  rmind file dm9000var.h was added on branch rmind-uvmplock on 2011-03-05 20:53:14 +0000
 1.1.4.2 22-Oct-2010  uebayasi Sync with HEAD (-D20101022).
 1.1.4.1 08-Sep-2010  uebayasi file dm9000var.h was added on branch uebayasi-xip on 2010-10-22 07:21:57 +0000
 1.1.2.2 09-Oct-2010  yamt sync with head
 1.1.2.1 08-Sep-2010  yamt file dm9000var.h was added on branch yamt-nfs-mp on 2010-10-09 03:32:06 +0000
 1.2.46.1 22-Apr-2018  pgoyette Sync with HEAD
 1.3.2.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.101 29-Jun-2024  riastradh if_stats(9): Add ifp argument to if_stat..._ref.

This will enable us to pass the ifp through to a dtrace probe inside.

No functional change intended in this change, but this is an API
change visible to modules so it shouldn't be pulled up.

PR kern/58377
 1.100 18-Sep-2022  thorpej Eliminate use of IFF_OACTIVE.
 1.99 01-Jul-2021  thorpej Make sure the media / mii members in struct ethercom are initialized
so that the media-related ioctls work. Problem reported by Björn Johannesson
on current-users@.

XXX pullup-9
 1.98 30-Jun-2021  thorpej Fix a couple of problems with MII-equipped NE2000 derivatives reported by
Björn Johannesson on current-users@:

- Re-factor dp8390_stop() into dp8390_halt() (that does the stuff to
halt the hardware) and dp8390_stop() (which alls dp8390_halt() before
calling mii_down() via sc->sc_stop_card()). This prevents us from
calling mii_down() before all of the interface data structures have
been set up, which these days can trip a KASSERT().

- Add a 1-second timer to call mii_tick(), and enable it in the
sc->sc_init_card() callback, and cancel it in the sc->sc_stop_card()
and sc->sc_media_fini() callbacks. This is actually a long-standing
bug that previously didn't have much practical effect, but causes
problems with dhcpcd's link live-ness detection logic.
 1.97 04-Feb-2020  thorpej branches: 1.97.10;
Use ifmedia_fini().
 1.96 29-Jan-2020  thorpej Adopt <net/if_stats.h>.
 1.95 29-May-2019  msaitoh branches: 1.95.2; 1.95.4;
Even if we don't use MII(4), use the common path of SIOC[GS]IFMEDIA in
sys/net/if_ethersubr.c if we can.
- Add ec_ifmedia into struct ethercom.
- ec_mii in struct ethercom is kept and used as it is. It might be used in
future. Note that some Ethernet drivers which _DOESN'T_ use mii(4) use
ec_mii for keeping the if_media. Those should be changed in future.
 1.94 28-May-2019  msaitoh Use ETHER_LOCK()/ETHER_UNLOCK() for all ethernet drivers to protect ec_multi*.
 1.93 26-Apr-2019  msaitoh No functional change:
- u_int_{8,16,32}_t -> uint_{8,16,32}_t
- KNF.
- Tabify.
- Remove extra space.
 1.92 05-Feb-2019  msaitoh Remove very old IFF_NOTRAILERS flag.
 1.91 03-Sep-2018  riastradh Rename min/max -> uimin/uimax for better honesty.

These functions are defined on unsigned int. The generic name
min/max should not silently truncate to 32 bits on 64-bit systems.
This is purely a name change -- no functional change intended.

HOWEVER! Some subsystems have

#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))

even though our standard name for that is MIN/MAX. Although these
may invite multiple evaluation bugs, these do _not_ cause integer
truncation.

To avoid `fixing' these cases, I first changed the name in libkern,
and then compile-tested every file where min/max occurred in order to
confirm that it failed -- and thus confirm that nothing shadowed
min/max -- before changing it.

I have left a handful of bootloaders that are too annoying to
compile-test, and some dead code:

cobalt ews4800mips hp300 hppa ia64 luna68k vax
acorn32/if_ie.c (not included in any kernels)
macppc/if_gm.c (superseded by gem(4))

It should be easy to fix the fallout once identified -- this way of
doing things fails safe, and the goal here, after all, is to _avoid_
silent integer truncations, not introduce them.

Maybe one day we can reintroduce min/max as type-generic things that
never silently truncate. But we should avoid doing that for a while,
so that existing code has a chance to be detected by the compiler for
conversion to uimin/uimax without changing the semantics until we can
properly audit it all. (Who knows, maybe in some cases integer
truncation is actually intended!)
 1.90 15-Jul-2018  maxv Retire ipkdb entirely. The option was removed from the config files
yesterday.

ok kamil christos
 1.89 26-Jun-2018  msaitoh branches: 1.89.2;
Implement the BPF direction filter (BIOC[GS]DIRECTION). It provides backward
compatibility with BIOC[GS]SEESENT ioctl. The userland interface is the same
as FreeBSD.

This change also fixes a bug that the direction is misunderstand on some
environment by passing the direction to bpf_mtap*() instead of checking
m->m_pkthdr.rcvif.
 1.88 22-Jun-2018  msaitoh It's not required to include net/bpfdesc.h. Remove it.
 1.87 23-May-2017  ozaki-r branches: 1.87.2; 1.87.8;
Apply deferred if_start to more drivers

And annotate some XXX_start as it runs in softint to clarify that
it doesn't need deferred if_start.
 1.86 15-Dec-2016  ozaki-r Move bpf_mtap and if_ipackets++ on Rx of each driver to percpuq if_input

The benefits of the change are:
- We can reduce codes
- We can provide the same behavior between drivers
- Where/When if_ipackets is counted up
- Note that some drivers still update packet statistics in their own
way (periodical update)
- Moved bpf_mtap run in softint
- This makes it easy to MP-ify bpf

Proposed on tech-kern and tech-net
 1.85 10-Jun-2016  ozaki-r branches: 1.85.2;
Introduce m_set_rcvif and m_reset_rcvif

The API is used to set (or reset) a received interface of a mbuf.
They are counterpart of m_get_rcvif, which will come in another
commit, hide internal of rcvif operation, and reduce the diff of
the upcoming change.

No functional change.
 1.84 20-Apr-2016  knakahara Apply mbuf initialize function to stack mbuf used as M_PKTHDR.

It is required to prevent unexpected behavior in future works abount m_pkthdr.
 1.83 09-Feb-2016  ozaki-r Introduce softint-based if_input

This change intends to run the whole network stack in softint context
(or normal LWP), not hardware interrupt context. Note that the work is
still incomplete by this change; to that end, we also have to softint-ify
if_link_state_change (and bpf) which can still run in hardware interrupt.

This change softint-ifies at ifp->if_input that is called from
each device driver (and ieee80211_input) to ensure Layer 2 runs
in softint (e.g., ether_input and bridge_input). To this end,
we provide a framework (called percpuq) that utlizes softint(9)
and percpu ifqueues. With this patch, rxintr of most drivers just
queues received packets and schedules a softint, and the softint
dequeues packets and does rest packet processing.

To minimize changes to each driver, percpuq is allocated in struct
ifnet for now and that is initialized by default (in if_attach).
We probably have to move percpuq to softc of each driver, but it's
future work. At this point, only wm(4) has percpuq in its softc
as a reference implementation.

Additional information including performance numbers can be found
in the thread at tech-kern@ and tech-net@:
http://mail-index.netbsd.org/tech-kern/2016/01/14/msg019997.html

Acknowledgment: riastradh@ greatly helped this work.
Thank you very much!
 1.82 13-Apr-2015  riastradh Convert sys/dev to use <sys/rndsource.h>.
 1.81 10-Aug-2014  tls branches: 1.81.4;
Merge tls-earlyentropy branch into HEAD.
 1.80 02-Feb-2012  tls branches: 1.80.6; 1.80.20;
Entropy-pool implementation move and cleanup.

1) Move core entropy-pool code and source/sink/sample management code
to sys/kern from sys/dev.

2) Remove use of NRND as test for presence of entropy-pool code throughout
source tree.

3) Remove use of RND_ENABLED in device drivers as microoptimization to
avoid expensive operations on disabled entropy sources; make the
rnd_add calls do this directly so all callers benefit.

4) Fix bug in recent rnd_add_data()/rnd_add_uint32() changes that might
have lead to slight entropy overestimation for some sources.

5) Add new source types for environmental sensors, power sensors, VM
system events, and skew between clocks, with a sample implementation
for each.

ok releng to go in before the branch due to the difficulty of later
pullup (widespread #ifdef removal and moved files). Tested with release
builds on amd64 and evbarm and live testing on amd64.
 1.79 11-Apr-2010  tsutsui branches: 1.79.8; 1.79.12;
Fix botched logic in ipkdb part in rev 1.77 (KNF misc).
 1.78 05-Apr-2010  joerg Push the bpf_ops usage back into bpf.h. Push the common ifp->if_bpf
check into the inline functions as well the fourth argument for
bpf_attach.
 1.77 27-Feb-2010  tsutsui branches: 1.77.2;
KNF, misc cosmetics.
 1.76 27-Feb-2010  tsutsui Always call device dependent functions via pointers rather than
using conditionals to switch inline functions for modern processors.
 1.75 27-Feb-2010  tsutsui Also fix a wrong mem_ring calculation in dp8390_ipkdb_attach().
 1.74 24-Feb-2010  tsutsui Fix a wrong calculation bug around RX ring buffer memory address
slipped in about sixteen years ago. Fortunately, it had been working
for ages because some devices used address zero and other devices
ignored wrong higher bits.

Tested on we(4) (SMC Elite Ultra) and ne(4) (NE2000 compatible
named UL0001) on ISA.
Note FreeBSD also uses the same correct value in their ed(4) driver.
 1.73 19-Jan-2010  pooka branches: 1.73.2;
Redefine bpf linkage through an always present op vector, i.e.
#if NBPFILTER is no longer required in the client. This change
doesn't yet add support for loading bpf as a module, since drivers
can register before bpf is attached. However, callers of bpf can
now be modularized.

Dynamically loadable bpf could probably be done fairly easily with
coordination from the stub driver and the real driver by registering
attachments in the stub before the real driver is loaded and doing
a handoff. ... and I'm not going to ponder the depths of unload
here.

Tested with i386/MONOLITHIC, modified MONOLITHIC without bpf and rump.
 1.72 06-Dec-2009  dyoung Simplify device-activation hooks.
 1.71 12-May-2009  cegger struct device * -> device_t, no functional changes intended.
 1.70 14-Mar-2009  dsl Change about 4500 of the K&R function definitions to ANSI ones.
There are still about 1600 left, but they have ',' or /* ... */
in the actual variable definitions - which my awk script doesn't handle.
There are also many that need () -> (void).
(The script does handle misordered arguments.)
 1.69 07-Nov-2008  dyoung branches: 1.69.4;
*** Summary ***

When a link-layer address changes (e.g., ifconfig ex0 link
02:de:ad:be:ef:02 active), send a gratuitous ARP and/or a Neighbor
Advertisement to update the network-/link-layer address bindings
on our LAN peers.

Refuse a change of ethernet address to the address 00:00:00:00:00:00
or to any multicast/broadcast address. (Thanks matt@.)

Reorder ifnet ioctl operations so that driver ioctls may inherit
the functions of their "class"---ether_ioctl(), fddi_ioctl(), et
cetera---and the class ioctls may inherit from the generic ioctl,
ifioctl_common(), but both driver- and class-ioctls may override
the generic behavior. Make network drivers share more code.

Distinguish a "factory" link-layer address from others for the
purposes of both protecting that address from deletion and computing
EUI64.

Return consistent, appropriate error codes from network drivers.

Improve readability. KNF.

*** Details ***

In if_attach(), always initialize the interface ioctl routine,
ifnet->if_ioctl, if the driver has not already initialized it.
Delete if_ioctl == NULL tests everywhere else, because it cannot
happen.

In the ioctl routines of network interfaces, inherit common ioctl
behaviors by calling either ifioctl_common() or whichever ioctl
routine is appropriate for the class of interface---e.g., ether_ioctl()
for ethernets.

Stop (ab)using SIOCSIFADDR and start to use SIOCINITIFADDR. In
the user->kernel interface, SIOCSIFADDR's argument was an ifreq,
but on the protocol->ifnet interface, SIOCSIFADDR's argument was
an ifaddr. That was confusing, and it would work against me as I
make it possible for a network interface to overload most ioctls.
On the protocol->ifnet interface, replace SIOCSIFADDR with
SIOCINITIFADDR. In ifioctl(), return EPERM if userland tries to
invoke SIOCINITIFADDR.

In ifioctl(), give the interface the first shot at handling most
interface ioctls, and give the protocol the second shot, instead
of the other way around. Finally, let compatibility code (COMPAT_OSOCK)
take a shot.

Pull device initialization out of switch statements under
SIOCINITIFADDR. For example, pull ..._init() out of any switch
statement that looks like this:

switch (...->sa_family) {
case ...:
..._init();
...
break;
...
default:
..._init();
...
break;
}

Rewrite many if-else clauses that handle all permutations of IFF_UP
and IFF_RUNNING to use a switch statement,

switch (x & (IFF_UP|IFF_RUNNING)) {
case 0:
...
break;
case IFF_RUNNING:
...
break;
case IFF_UP:
...
break;
case IFF_UP|IFF_RUNNING:
...
break;
}

unifdef lots of code containing #ifdef FreeBSD, #ifdef NetBSD, and
#ifdef SIOCSIFMTU, especially in fwip(4) and in ndis(4).

In ipw(4), remove an if_set_sadl() call that is out of place.

In nfe(4), reuse the jumbo MTU logic in ether_ioctl().

Let ethernets register a callback for setting h/w state such as
promiscuous mode and the multicast filter in accord with a change
in the if_flags: ether_set_ifflags_cb() registers a callback that
returns ENETRESET if the caller should reset the ethernet by calling
if_init(), 0 on success, != 0 on failure. Pull common code from
ex(4), gem(4), nfe(4), sip(4), tlp(4), vge(4) into ether_ioctl(),
and register if_flags callbacks for those drivers.

Return ENOTTY instead of EINVAL for inappropriate ioctls. In
zyd(4), use ENXIO instead of ENOTTY to indicate that the device is
not any longer attached.

Add to if_set_sadl() a boolean 'factory' argument that indicates
whether a link-layer address was assigned by the factory or some
other source. In a comment, recommend using the factory address
for generating an EUI64, and update in6_get_hw_ifid() to prefer a
factory address to any other link-layer address.

Add a routing message, RTM_LLINFO_UPD, that tells protocols to
update the binding of network-layer addresses to link-layer addresses.
Implement this message in IPv4 and IPv6 by sending a gratuitous
ARP or a neighbor advertisement, respectively. Generate RTM_LLINFO_UPD
messages on a change of an interface's link-layer address.

In ether_ioctl(), do not let SIOCALIFADDR set a link-layer address
that is broadcast/multicast or equal to 00:00:00:00:00:00.

Make ether_ioctl() call ifioctl_common() to handle ioctls that it
does not understand.

In gif(4), initialize if_softc and use it, instead of assuming that
the gif_softc and ifp overlap.

Let ifioctl_common() handle SIOCGIFADDR.

Sprinkle rtcache_invariants(), which checks on DIAGNOSTIC kernels
that certain invariants on a struct route are satisfied.

In agr(4), rewrite agr_ioctl_filter() to be a bit more explicit
about the ioctls that we do not allow on an agr(4) member interface.

bzero -> memset. Delete unnecessary casts to void *. Use
sockaddr_in_init() and sockaddr_in6_init(). Compare pointers with
NULL instead of "testing truth". Replace some instances of (type
*)0 with NULL. Change some K&R prototypes to ANSI C, and join
lines.
 1.68 12-Mar-2008  cube branches: 1.68.4; 1.68.10; 1.68.12; 1.68.14;
Split device_t and softc for the NE2000 Ethernet chip and all its variants
and attachments. Use device_t accessors, correct types, and ANSIfy when
appropriate.
 1.67 23-Feb-2008  dyoung Convert a complicated if/else if/else chain to a switch statement
that is a bit more readable.

ENODEV and ENOTTY are appropriate error codes for indicating
unsupported ioctls, but EINVAL is definitely not! If an operation
is not supported, return ENODEV instead of EINVAL.
 1.66 19-Oct-2007  ad branches: 1.66.12; 1.66.16;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.65 01-Sep-2007  dyoung branches: 1.65.4;
Change a bazillion occurrences of code resembling this,

error = (cmd == SIOCADDMULTI) ?
ether_addmulti(ifr, &sc->sc_ec) :
ether_delmulti(ifr, &sc->sc_ec);

if (error == ENETRESET) {

to this,

if ((error = ether_ioctl(ifp, cmd, data)) == ENETRESET) {

which does the same thing.

(A bazillion is a very large number. This seems to make the i386
ALL kernel smaller by 3kB to 4kB.)

Use ifreq_getaddr() twice in es(4).

Whitespace nits.
 1.64 26-Aug-2007  dyoung branches: 1.64.2;
Constify: LLADDR -> CLLADDR. I'm aiming here to make it easier to
identify sockaddr_dl abuse that remains in the kernel, especially
the potential for overwriting memory past the end of a sockaddr_dl
with, e.g., memcpy(LLADDR(), ...).
 1.63 04-Mar-2007  christos branches: 1.63.2; 1.63.10; 1.63.14;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.62 13-Jan-2007  cube branches: 1.62.2;
Make the IPKDB code compile.
 1.61 16-Nov-2006  christos __unused removal on arguments; approved by core.
 1.60 12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.59 07-Sep-2006  dogcow branches: 1.59.2; 1.59.4;
remove more vestiges of CCITT, LLC, HDLC, NS, and NSIP.
 1.58 20-Feb-2006  thorpej branches: 1.58.2;
Use device_is_active() rather than testing dv_flags for DVF_ACTIVE
directly.
 1.57 24-Dec-2005  perry branches: 1.57.2; 1.57.4; 1.57.6;
__inline__ -> inline
 1.56 11-Dec-2005  christos merge ktrace-lwp.
 1.55 04-Feb-2005  perry branches: 1.55.6;
de-__P
 1.54 30-Oct-2004  thorpej branches: 1.54.4; 1.54.6;
When adding/deleting multicast addresses, only whack the address
filter if the interface is marked RUNNING.

Fixes kern/27678.
 1.53 16-Sep-2004  martin Do not count ipackets twice. From Dave Barnes in PR port-i386/26906.
 1.52 15-Jan-2003  bouyer branches: 1.52.2; 1.52.6;
Zero out the NIC memory when padding packet to ETHER_MIN_LEN-ETHER_CRC_LEN
sc->write_mbuf now return len of buffer, including padding.
Tested with a PCI ne2000.
 1.51 21-Dec-2002  kristerw Move dp8390_debug to the #ifdef DEBUG section.
 1.50 27-Sep-2002  provos remove trailing \n in panic(). approved perry.
 1.49 13-Nov-2001  lukem branches: 1.49.10;
add/cleanup RCSID
 1.48 16-Sep-2001  wiz Spell 'occurred' with two 'r's.
 1.47 09-Aug-2001  thorpej branches: 1.47.2;
There is no need to use M_EOR here.
 1.46 07-Jul-2001  thorpej branches: 1.46.2;
bcopy -> memcpy, strcpy
 1.45 07-Jul-2001  thorpej bcmp -> memcmp
 1.44 12-Feb-2001  thorpej branches: 1.44.2;
Add a "stop_card", which is the opposite of "init_card", and
call it from dp8390_stop().
 1.43 12-Feb-2001  thorpej Print the Ethernet address before attaching media.
 1.42 12-Feb-2001  thorpej Adjust the way that media is initialized on DP8390-compatible
chips. The dp8390_softc now has media_init and media_fini
function pointers that do the work.
 1.41 14-Dec-2000  thorpej ALTQ'ify.
 1.40 15-Nov-2000  thorpej Move bpfattach()/bpfdetach() calls into ether_ifattach()/ether_ifdetach().
 1.39 17-Oct-2000  bouyer Support ETHERCAP_VLAN_MTU. It seems the chip doesn't check the frame size.
Tested with a NetVin 5000 and a WD8013EBT.
 1.38 01-Oct-2000  thorpej Move the check for "promisc + unicast + not for us" into ether_input(),
and change Ethernet drivers to always pass all received frames to
ether_input() (with a few exceptions, which are documented in the
code).
 1.37 29-May-2000  jhawk branches: 1.37.2;
For all network drivers that call ether_ifattach(), and also
have _detach() functions:
Ensure that softc keeps state about whether the attach succeeded,
and make the detach function return immediately if the attach did
not complete.
 1.36 12-May-2000  thorpej branches: 1.36.2;
Use ether_crc32_be().
 1.35 22-Mar-2000  ws Make IPKDB working again.
Add support for i386 debugging and pci-based ne2000 boards.
 1.34 22-Mar-2000  ws Add bus_space_barrier.
Add DELAY in some busy loops to allow the dma engine to actually do something
(neccessary on fast processors).
 1.33 09-Feb-2000  enami ASIX AX88190 support (Planex FNW-3700-T and Melco LPC3-TX) from FreeBSD/PAO3.
 1.32 09-Feb-2000  enami - Since all resources are mandatory, no need to manage individually.
- KNF some code.
- Factor out some code into function.
- Disestablish an interrupt handler when failed to enable card power.
 1.31 02-Feb-2000  itojun handle attach failure in ne/pcmcia more carefully. (otherwise we'll
have trouble on detach)
 1.30 02-Feb-2000  itojun use a bit more standard (sys/device.h) prototype for {dp8390,ne2000}_detach().
 1.29 02-Feb-2000  enami - Check also DVF_ACTIVE bit in dp8390_intr.
- Delete ifmedia instances on detach.
 1.28 02-Feb-2000  itojun implement if_detach code for ne/pcmcia.
XXX still incomplete, ne_pcmcia_detach() commented out for safery - please test
 1.27 27-Sep-1999  enami branches: 1.27.2;
Support Planex Communications Inc, FNW-3600-T.
 1.26 25-Aug-1999  thorpej When padding short packets on transmit, don't include the CRC length
in the computation. kern/8194.
 1.25 23-Jun-1999  abs In xxx_mediachange(), if there is no callback to the front-end, just
return 0 instead of EINVAL. In this case, there will only be one media
type, and the upper-level if_media code will ensure that the user is
setting to that type.
This matches changes Jason made a while back to sys/dev/ic/lance.c
 1.24 18-May-1999  thorpej Rework layer 2 protocol input routines. Instead of calling e.g. ether_input()
directly, call the function pointer (*if_input)(ifp, m). The input routine
expects the packet header to be at the head of the packet, and will adjust
as necessary. Privatize the layer 2 input and output routines, allowing
*_ifattach() to set them up as appropriate.
 1.23 25-Mar-1999  thorpej branches: 1.23.4;
Use ETHER_*_LEN constants from <net/if_ether.h> instead of defining them
ourselves.
 1.22 28-Feb-1999  explorer Update to slightly altered rnd_attach_source() api
 1.21 17-Feb-1999  thorpej Avoid initializing the interface in the SIOCSIFFLAGS if ! UP and ! RUNNING.
 1.20 07-Feb-1999  thorpej Add entropy gathering.
 1.19 12-Dec-1998  mycroft Slight simplification to previous.
 1.18 11-Dec-1998  bad Simplify the code dealing with the mbuf chain in dp8390_get().
 1.17 11-Dec-1998  bad Change a comment to reflect reality.
 1.16 18-Nov-1998  thorpej branches: 1.16.2;
Now that the *_activate() functions don't do things which are attachment
specific, move them into the chipset drivers.
 1.15 17-Nov-1998  thorpej Expose the "enable" and "disable" functions so that the front-ends can
access them.
 1.14 12-Nov-1998  mycroft If we get a TX interrupt with no packets buffered, ignore it. This can occur
if the chip is reset while transmitting.

XXX
This occurs at boot time because the SIOCADDMULTI always resets the interface
when adding the `all hosts groups' -- usually while the ARP packet is being
transmitted. All drivers should be fixed to not reset the interface when
changing the multicast filter, if possible.
 1.13 05-Jul-1998  jonathan defopt NS, NSIP.
 1.12 05-Jul-1998  jonathan defopt INET, NETATALK.
 1.11 27-Jan-1998  thorpej Fudge the start of the data pointer of the first mbuf in the chain when
reading a packet, ensuring that the data after the Ethernet header will
be aligned. Part of PR #4595, from Andreas Johansson <ajo@wopr.campus.luth.se>
 1.10 03-Nov-1997  thorpej Fix a think'o in ifmedia initialization.
 1.9 02-Nov-1997  scottr Fix a serious problem in dp8390_write_mbuf(), noticed by Jason Thorpe:
after we've written out the contents of the mbuf, increment the transmit
buffer offset by m->m_len.
 1.8 02-Nov-1997  thorpej Add ifmedia support via callbacks to the front-end.
 1.7 15-Oct-1997  thorpej branches: 1.7.2;
Pulldown from marc-pcmcia branch: minor tweaks to make this a completely
bus-independent driver, and garbage collect a few unnecessary things
from the softc.
 1.6 15-Oct-1997  explorer back out previous change (committed in error)
 1.5 15-Oct-1997  explorer Add and/or update rnd_*() hooks
 1.4 24-Aug-1997  scottr Conditionalize DEBUG printf on dp8390_debug. Pointed out by Jonathan
Stone.
 1.3 30-Apr-1997  scottr branches: 1.3.4;
Fix typo in last change.
 1.2 30-Apr-1997  scottr Remove the use16bit softc field, replacing the functionality with dcr_reg.
This allows the front end to override the default DCR (byte-wide DMA,
x86 byte order, 8-byte FIFO) with different transfer size, byte order, DMA
parameters, and FIFO threshhold. If the loopback select bit is not set for
normal operation, the default is used instead.

Inspired by thoughts from Bernd Ernesti.
 1.1 29-Apr-1997  scottr Machine-independent driver for DP8390/WD83C690-based Ethernet controller.
Derived from the ISA if_ed driver and the mac68k if_ae driver.
 1.3.4.4 14-Oct-1997  thorpej Rearrange the disable functions slightly so that an interface that
interfaces that don't have a disable hook will never be marked "disabled".

Now, once an interface has been marked "enabled" by the enable function,
it will remain marked as such for the duration of the kernel's lifetime.
 1.3.4.3 14-Oct-1997  thorpej Add power management hooks.
 1.3.4.2 14-Oct-1997  thorpej - Don't assume NIC-addressable memory starts at 0. Compute the first
transmit page based on mem_start.
- Garbage-collect the "typestr" and "type" stuff. Let the front-end
print information about the card model, and the "type" stuff has all
been replaced by function pointers, anyhow.
- Generalize the interrupt handler (i.e. don't take mac68k-specific
arguements; that front-end should set up a wrapper interrupt handler).
- Fix the NIC_GET() and NIC_PUT() macros so that they work with more
implementations of bus_space(9).
 1.3.4.1 27-Aug-1997  thorpej Update marc-pcmcia branch from trunk.
 1.7.2.5 15-Nov-1998  cgd pull up rev 1.14 from trunk (mycroft)
 1.7.2.4 29-Jan-1998  mellon Pull up 1.11 (thorpej)
 1.7.2.3 05-Nov-1997  thorpej Pull up from trunk: Add ifmedia support.
 1.7.2.2 03-Nov-1997  thorpej Back changes from revision 1.8 out of this file; they should have never
been pulled into the branch.
 1.7.2.1 02-Nov-1997  mellon Pull rev 1.8 and 1.9 up from trunk (thorpej) (scottr)
 1.16.2.1 11-Dec-1998  kenh The beginnings of interface detach support. Still some bugs, but mostly
works for me.

This work was originally by Bill Studenmund, and cleaned up by me.
 1.23.4.2 01-Jul-1999  thorpej Sync w/ -current.
 1.23.4.1 21-Jun-1999  thorpej Sync w/ -current.
 1.27.2.4 12-Mar-2001  bouyer Sync with HEAD.
 1.27.2.3 05-Jan-2001  bouyer Sync with HEAD
 1.27.2.2 22-Nov-2000  bouyer Sync with HEAD.
 1.27.2.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.36.2.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.37.2.1 31-Dec-2000  jhawk Pull up revision 1.39 (requested by bouyer):
Add support for 802.1Q virtual LANs.
 1.44.2.6 17-Jan-2003  thorpej Sync with HEAD.
 1.44.2.5 29-Dec-2002  thorpej Sync with HEAD.
 1.44.2.4 18-Oct-2002  nathanw Catch up to -current.
 1.44.2.3 14-Nov-2001  nathanw Catch up to -current.
 1.44.2.2 21-Sep-2001  nathanw Catch up to -current.
 1.44.2.1 24-Aug-2001  nathanw Catch up with -current.
 1.46.2.3 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.46.2.2 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.46.2.1 25-Aug-2001  thorpej Merge Aug 24 -current into the kqueue branch.
 1.47.2.1 01-Oct-2001  fvdl Catch up with -current.
 1.49.10.1 27-Jan-2003  jmc Pullup revisions 1.51-1.52 (requested by bouyer in ticket #1096)
Zero out the NIC memory when padding packet to
ETHER_MIN_LEN-ETHER_CRC_LEN sc->write_mbuf now return len of
buffer, including padding.
 1.52.6.1 24-Jan-2005  he Pull up revision 1.54 (requested by thorpej in ticket #939):
When adding or deleting multicast addresses, only change
the address filter if the interface is marked RUNNING.
Fixes PR#27678.
 1.52.2.4 04-Feb-2005  skrll Sync with HEAD.
 1.52.2.3 02-Nov-2004  skrll Sync with HEAD.
 1.52.2.2 21-Sep-2004  skrll Fix the sync with head I botched.
 1.52.2.1 18-Sep-2004  skrll Sync with HEAD.
 1.54.6.1 12-Feb-2005  yamt sync with head.
 1.54.4.1 29-Apr-2005  kent sync with -current
 1.55.6.7 17-Mar-2008  yamt sync with head.
 1.55.6.6 27-Feb-2008  yamt sync with head.
 1.55.6.5 27-Oct-2007  yamt sync with head.
 1.55.6.4 03-Sep-2007  yamt sync with head.
 1.55.6.3 26-Feb-2007  yamt sync with head.
 1.55.6.2 30-Dec-2006  yamt sync with head.
 1.55.6.1 21-Jun-2006  yamt sync with head.
 1.57.6.1 22-Apr-2006  simonb Sync with head.
 1.57.4.1 09-Sep-2006  rpaulo sync with head
 1.57.2.1 01-Mar-2006  yamt sync with head.
 1.58.2.1 14-Sep-2006  yamt sync with head.
 1.59.4.2 10-Dec-2006  yamt sync with head.
 1.59.4.1 22-Oct-2006  yamt sync with head
 1.59.2.2 01-Feb-2007  ad Sync with head.
 1.59.2.1 18-Nov-2006  ad Sync with head.
 1.62.2.1 12-Mar-2007  rmind Sync with HEAD.
 1.63.14.2 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.63.14.1 03-Sep-2007  jmcneill Sync with HEAD.
 1.63.10.1 03-Sep-2007  skrll Sync with HEAD.
 1.63.2.2 23-Oct-2007  ad Sync with head.
 1.63.2.1 09-Oct-2007  ad Sync with head.
 1.64.2.2 23-Mar-2008  matt sync with HEAD
 1.64.2.1 06-Nov-2007  matt sync with HEAD
 1.65.4.1 25-Oct-2007  bouyer Sync with HEAD.
 1.66.16.2 17-Jan-2009  mjf Sync with HEAD.
 1.66.16.1 03-Apr-2008  mjf Sync with HEAD.
 1.66.12.1 24-Mar-2008  keiichi sync with head.
 1.68.14.1 20-Nov-2010  riz Pull up following revision(s) (requested by tsutsui in ticket #1367):
sys/dev/ic/ne2000var.h: revision 1.25
sys/arch/atari/conf/MILAN.in: revision 1.24
sys/arch/atari/conf/MILAN.in: revision 1.25
sys/dev/ic/ne2000.c: revision 1.71
sys/dev/ic/ne2000.c: revision 1.72
sys/arch/atari/dev/if_ne_mb.c: revision 1.1
sys/arch/atari/dev/if_ne_mb.c: revision 1.2
sys/arch/atari/conf/MILAN-PCIIDE: revision 1.69
sys/arch/atari/conf/HADES.in: revision 1.10
sys/arch/atari/conf/HADES.in: revision 1.11
sys/arch/x68k/dev/if_ne_neptune.c: revision 1.20
sys/dev/isa/if_ne_isa.c: revision 1.27
sys/arch/atari/atari/autoconf.c: revision 1.57
sys/dev/ic/ne2000.c: revision 1.62
sys/dev/isapnp/if_ne_isapnp.c: revision 1.27
sys/arch/atari/conf/files.atari: revision 1.117
sys/arch/atari/conf/HADES: revision 1.88
sys/arch/atari/conf/GENERIC.in: revision 1.85
sys/dev/ic/ne2000.c: revision 1.65
sys/dev/ic/ne2000.c: revision 1.66
sys/dev/ic/ne2000.c: revision 1.68
sys/arch/atari/conf/MILAN-ISAIDE: revision 1.65
distrib/notes/atari/hardware: revision 1.24
sys/conf/files: revision 1.980
sys/dev/ic/ne2000var.h: revision 1.21
sys/arch/x68k/dev/if_ne_intio.c: revision 1.16
sys/dev/ic/dp8390.c: revision 1.74
sys/dev/ic/dp8390.c: revision 1.75
Added NE2000 with 8bit bus width support.
reviewd by tsutsui@ at tech-kern ML.
Fix a wrong calculation bug around RX ring buffer memory address
slipped in about sixteen years ago. Fortunately, it had been working
for ages because some devices used address zero and other devices
ignored wrong higher bits.
Tested on we(4) (SMC Elite Ultra) and ne(4) (NE2000 compatible
named UL0001) on ISA.
Note FreeBSD also uses the same correct value in their ed(4) driver.
Now dp8390_config() calculates mem_ring correctly so
no longer need to override it in ne2000_attach().
Use roundup2() in <sys/param.h> rather than a conditional.
Also fix a wrong mem_ring calculation in dp8390_ipkdb_attach().
Put several fixes to ne(4) driver for better 8 bit mode support,
especially on RTL8019AS which is also used for non-ISA local bus of
embedded controllers and some m68k machines like atari and x68k.
* move RTL8019 probe and attach code from each bus attachment
to MI ne2000_detect() and ne2000_attach()
* change a method for backend and attachment to specify 8 bit mode
to use a new sc->sc_quirk member, instead of sc->sc_dmawidth
* handle more NE2000 8 bit mode specific settings, including
bus_space(9) access width and available size of buffer memory
* add a function to detect NE2000 8 bit mode
(disabled by default, but enalbed by options NE2000_DETECT_8BIT
to avoid possible regression on various ISA clones)
* fix ipkdb attachment accordingly (untested)
Tested on two NE2000 ISA variants (RTL8019AS and another clone named UL0001)
in both 8 bit and 16 bit mode on i386. "Looks good" from nonaka@.
See my post on tech-kern for details:
http://mail-index.NetBSD.org/tech-kern/2010/02/26/msg007423.html
No need to override mem_ring value in ne2000_ipkdb_attach()
since a wrong calculation in dp8390_ipkdb_attach() was fixed.
Don't warn about DMA timeout during probe.
Add support for the EtherNEC.
The EtherNEC is yet another user designed device for Atari machines,
an NE2000 based ISA board connected to Atari's ROM cartridge slot with
simple but ingenious interface and cartridge port adapter, and
it's the most available network solution for the old Atari machines.
See following pages for more details about EtherNEC:
http://hardware.atari.org/ether/
http://home.arcor.de/thomas.redelberger/prj/atari/etherne/
http://www.freemint.org/ethernec/ethernec.html
Also note EtherNEC.
Use callout_schedule(9) rather than callout_reset(9) on polling
as callout(9) man says.
Remove EtherNEC from HADES and MILAN.
They have ISA so no one will bother to connect ISA NE2000 via EtherNEC.
Regen from HADES.in rev 1.11 and MILAN.in rev 1.25:
Remove EtherNEC from HADES and MILAN.
They have ISA so no one will bother to connect ISA NE2000 via EtherNEC.
 1.68.12.2 28-Apr-2009  skrll Sync with HEAD.
 1.68.12.1 19-Jan-2009  skrll Sync with HEAD.
 1.68.10.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.68.4.4 11-Aug-2010  yamt sync with head.
 1.68.4.3 11-Mar-2010  yamt sync with head
 1.68.4.2 16-May-2009  yamt sync with head
 1.68.4.1 04-May-2009  yamt sync with head.
 1.69.4.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.73.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.77.2.1 30-May-2010  rmind sync with head
 1.79.12.1 18-Feb-2012  mrg merge to -current.
 1.79.8.1 17-Apr-2012  yamt sync with head
 1.80.20.1 07-Apr-2014  tls Be a little more clear and consistent about harvesting entropy from devices:

1) deprecate RND_FLAG_NO_ESTIMATE

2) define RND_FLAG_COLLECT_TIME, RND_FLAG_COLLECT_VALUE

3) define RND_FLAG_ESTIMATE_TIME, RND_FLAG_ESTIMATE_VALUE

4) define RND_FLAG_DEFAULT: RND_FLAG_COLLECT_TIME|
RND_FLAG_COLLECT_VALUE|RND_FLAG_ESTIMATE_TIME

5) Make entropy harvesting from environmental sensors a little more generic
and remove it from individual sensor drivers.

6) Remove individual open-coded delta-estimators for values from a few
places in the tree (uvm, environmental drivers).

7) 0 -> RND_FLAG_DEFAULT, actually gather entropy from various drivers
that had stubbed out code, other minor cleanups.
 1.80.6.2 03-Dec-2017  jdolecek update from HEAD
 1.80.6.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.81.4.6 28-Aug-2017  skrll Sync with HEAD
 1.81.4.5 05-Feb-2017  skrll Sync with HEAD
 1.81.4.4 09-Jul-2016  skrll Sync with HEAD
 1.81.4.3 22-Apr-2016  skrll Sync with HEAD
 1.81.4.2 19-Mar-2016  skrll Sync with HEAD
 1.81.4.1 06-Jun-2015  skrll Sync with HEAD
 1.85.2.1 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.87.8.3 06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.87.8.2 28-Jul-2018  pgoyette Sync with HEAD
 1.87.8.1 25-Jun-2018  pgoyette Sync with HEAD
 1.87.2.1 26-Jul-2018  snj Pull up following revision(s) (requested by msaitoh in ticket #938):
sys/arch/acorn32/podulebus/if_ie.c: revision 1.41
sys/arch/amiga/dev/if_es.c: revision 1.58
sys/arch/amiga/dev/if_qn.c: revision 1.45
sys/arch/arm/at91/at91emac.c: revision 1.20
sys/arch/arm/ep93xx/epe.c: revision 1.37
sys/arch/emips/ebus/if_le_ebus.c: revision 1.14
sys/arch/emips/ebus/if_le_ebus.c: revision 1.15
sys/arch/mac68k/dev/if_mc.c: revision 1.46
sys/arch/macppc/dev/am79c950.c: revision 1.39
sys/arch/newsmips/apbus/if_sn.c: revision 1.40
sys/arch/next68k/dev/mb8795.c: revision 1.59
sys/arch/playstation2/dev/if_smap.c: revision 1.25
sys/arch/playstation2/dev/if_smap.c: revision 1.26
sys/arch/sun2/dev/if_ec.c: revision 1.28
sys/arch/sun3/dev/if_ie.c: revision 1.63
sys/arch/x68k/dev/if_ne_intio.c: revision 1.19
sys/arch/xen/xen/if_xennet_xenbus.c: revision 1.75
sys/arch/xen/xen/xennetback_xenbus.c: revision 1.63
sys/dev/bi/if_ni.c: revision 1.45
sys/dev/cadence/if_cemac.c: revision 1.12
sys/dev/ic/am7990.c: revision 1.78
sys/dev/ic/am79900.c: revision 1.27
sys/dev/ic/an.c: revision 1.67
sys/dev/ic/cs89x0.c: revision 1.40
sys/dev/ic/dm9000.c: revision 1.13
sys/dev/ic/dm9000.c: revision 1.14
sys/dev/ic/dp8390.c: revision 1.88
sys/dev/ic/elink3.c: revision 1.141
sys/dev/ic/elinkxl.c: revision 1.122
sys/dev/ic/hme.c: revision 1.98
sys/dev/ic/i82586.c: revision 1.77
sys/dev/ic/lance.c: revision 1.53
sys/dev/ic/mb86950.c: revision 1.27
sys/dev/ic/mb86960.c: revision 1.86
sys/dev/ic/mtd803.c: revision 1.34
sys/dev/ic/pdq_ifsubr.c: revision 1.59
sys/dev/ic/rrunner.c: revision 1.86
sys/dev/ic/seeq8005.c: revision 1.58
sys/dev/ic/sgec.c: revision 1.47
sys/dev/ic/smc90cx6.c: revision 1.72
sys/dev/ic/smc91cxx.c: revision 1.96
sys/dev/ic/tropic.c: revision 1.49
sys/dev/ic/wi.c: revision 1.245
sys/dev/isa/if_eg.c: revision 1.93
sys/dev/isa/if_el.c: revision 1.95
sys/dev/isa/if_iy.c: revision 1.101
sys/dev/ofw/ofnet.c: revision 1.58
sys/dev/pci/if_alc.c: revision 1.27
sys/dev/pci/if_de.c: revision 1.152
sys/dev/pci/if_fpa.c: revision 1.61
sys/dev/pci/if_jme.c: revision 1.34
sys/dev/pci/if_tl.c: revision 1.108
sys/dev/pci/if_vte.c: revision 1.19
sys/dev/pci/ixgbe/ixgbe.h: revision 1.50
sys/dev/pcmcia/if_cnw.c: revision 1.62
sys/dev/pcmcia/if_malo_pcmcia.c: revision 1.17
sys/dev/pcmcia/if_ray.c: revision 1.89
sys/dev/pcmcia/if_xi.c: revision 1.81
sys/dev/pcmcia/mhzc.c: revision 1.51
sys/dev/pcmcia/xirc.c: revision 1.34
sys/dev/qbus/if_de.c: revision 1.33
sys/dev/qbus/if_qe.c: revision 1.78
sys/dev/qbus/if_qt.c: revision 1.22
sys/dev/sbus/be.c: revision 1.87
sys/dev/sbus/qe.c: revision 1.68
sys/dev/scsipi/if_se.c: revision 1.96
sys/dev/usb/if_atu.c: revision 1.59
sys/net/if_l2tp.c: revision 1.28 via patch
sys/net/if_ppp.c: revision 1.160
It's not required to include net/bpfdesc.h. Remove it.
--
Simplify like other drivers. NULL check of ifp->if_bpf is done in
bpf_mtap(), so it's not required to do it here.
--
Remove duplicated inclusion of net/bpf.h.
--
Remove duplicated inclusion of net/bpf.h.
--
Simplify bpf_mtap() call. No functional change.
 1.89.2.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.89.2.1 10-Jun-2019  christos Sync with HEAD
 1.95.4.1 29-Feb-2020  ad Sync with head.
 1.95.2.1 03-Jul-2021  martin Pull up following revision(s) (requested by thorpej in ticket #1311):

sys/dev/ic/dp8390.c: revision 1.99
sys/dev/ic/dl10019.c: revision 1.17
sys/dev/ic/ax88190.c: revision 1.18

Make sure the media / mii members in struct ethercom are initialized
so that the media-related ioctls work. Problem reported by Bj�rn Johannesson
on current-users@.

XXX pullup-9
 1.97.10.1 01-Aug-2021  thorpej Sync with HEAD.
 1.1 20-Nov-2000  bouyer branches: 1.1.2;
file dp8390.c.orig was initially added on branch thorpej_scsipi.
 1.1.2.2 20-Nov-2000  bouyer Ops, these shouldn't be there !
 1.1.2.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.3 28-Jun-1995  cgd move to more appropriate (...reg.h) names.
 1.2 12-Apr-1995  mycroft Take endianness into account in ed_ring.
 1.1 11-Apr-1995  mycroft Move NIC register definitions to a global location.
 1.4 19-Oct-2007  ad machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.3 11-Dec-2005  christos branches: 1.3.30; 1.3.44; 1.3.46; 1.3.50;
merge ktrace-lwp.
 1.2 27-Feb-2005  perry branches: 1.2.4;
nuke trailing whitespace
 1.1 16-Dec-2001  bjh21 branches: 1.1.2; 1.1.4; 1.1.20; 1.1.28; 1.1.30;
if_media support for the DP83905 AT/LANTIC (a souped-up DP8390).
 1.1.30.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.1.28.1 29-Apr-2005  kent sync with -current
 1.1.20.1 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.1.4.2 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.1.4.1 16-Dec-2001  thorpej file dp83905.c was added on branch kqueue on 2002-01-10 19:54:24 +0000
 1.1.2.2 08-Jan-2002  nathanw Catch up to -current.
 1.1.2.1 16-Dec-2001  nathanw file dp83905.c was added on branch nathanw_sa on 2002-01-08 00:29:41 +0000
 1.2.4.1 27-Oct-2007  yamt sync with head.
 1.3.50.1 25-Oct-2007  bouyer Sync with HEAD.
 1.3.46.1 06-Nov-2007  matt sync with HEAD
 1.3.44.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.3.30.1 23-Oct-2007  ad Sync with head.
 1.1 14-Dec-2001  bjh21 branches: 1.1.2; 1.1.4;
Register definitions for the NatSemi DP83905 AT/LANTIC, as used in many
podulebus Ethernet cards.
 1.1.4.2 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.1.4.1 14-Dec-2001  thorpej file dp83905reg.h was added on branch kqueue on 2002-01-10 19:54:24 +0000
 1.1.2.2 08-Jan-2002  nathanw Catch up to -current.
 1.1.2.1 14-Dec-2001  nathanw file dp83905reg.h was added on branch nathanw_sa on 2002-01-08 00:29:41 +0000
 1.3 11-Dec-2005  christos merge ktrace-lwp.
 1.2 27-Feb-2005  perry nuke trailing whitespace
 1.1 16-Dec-2001  bjh21 branches: 1.1.2; 1.1.4; 1.1.20; 1.1.28; 1.1.30;
if_media support for the DP83905 AT/LANTIC (a souped-up DP8390).
 1.1.30.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.1.28.1 29-Apr-2005  kent sync with -current
 1.1.20.1 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.1.4.2 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.1.4.1 16-Dec-2001  thorpej file dp83905var.h was added on branch kqueue on 2002-01-10 19:54:24 +0000
 1.1.2.2 08-Jan-2002  nathanw Catch up to -current.
 1.1.2.1 16-Dec-2001  nathanw file dp83905var.h was added on branch nathanw_sa on 2002-01-08 00:29:41 +0000
 1.9 14-Oct-2012  phx ed_ring structure is no longer needed for compatibility, as the last
device driver using it (amiga/ed(4)) has been converted now.
 1.8 11-Dec-2005  christos branches: 1.8.110; 1.8.116; 1.8.120;
merge ktrace-lwp.
 1.7 27-Feb-2005  perry nuke trailing whitespace
 1.6 02-Nov-2003  wiz branches: 1.6.8; 1.6.10;
Fix some typos. From Tom Cosgrove via jmc@openbsd.
 1.5 09-Feb-2000  enami branches: 1.5.28;
ASIX AX88190 support (Planex FNW-3700-T and Melco LPC3-TX) from FreeBSD/PAO3.
 1.4 27-Oct-1998  thorpej branches: 1.4.12;
Define a "page 3", used on some chips which emulate a dp8390, but also
provide extensions.
 1.3 29-Apr-1997  scottr Machine-independent driver for DP8390/WD83C690-based Ethernet controller.
Derived from the ISA if_ed driver and the mac68k if_ae driver.
 1.2 12-Apr-1995  mycroft Take endianness into account in ed_ring.
 1.1 11-Apr-1995  mycroft Move NIC register definitions to a global location.
 1.4.12.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.5.28.4 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.5.28.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.5.28.2 18-Sep-2004  skrll Sync with HEAD.
 1.5.28.1 03-Aug-2004  skrll Sync with HEAD
 1.6.10.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.6.8.1 29-Apr-2005  kent sync with -current
 1.8.120.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.8.116.1 22-Nov-2012  riz Pull up following revision(s) (requested by phx in ticket #681):
sys/arch/amiga/dev/if_edreg.h: file removal
sys/dev/ic/dp8390reg.h: revision 1.9
sys/arch/amiga/conf/files.amiga: revision 1.161
sys/arch/amiga/dev/if_ed_zbus.c: revision 1.1
sys/arch/amiga/dev/if_ed_zbus.c: revision 1.2
sys/arch/amiga/dev/if_ed.c: file removal
New ed(4) device driver for Hydra and ASDG Zorro2 bus network cards.
This driver is based on the MI dp8390 backend.
Fixed receiving of odd-length packets. Driver works now perfectly.
Thanks to Harald Meinzer for providing me with a Hydra for a few days.
ed_ring structure is no longer needed for compatibility, as the last
device driver using it (amiga/ed(4)) has been converted now.
 1.8.110.1 30-Oct-2012  yamt sync with head
 1.38 05-Feb-2024  andvar fix various typos in comments.
 1.37 02-Feb-2024  andvar s/tranceiver/transceiver/ in comment and definition.
 1.36 09-Aug-2021  andvar fix various typos in compatibility, mainly in comments.
 1.35 30-Jun-2021  thorpej Fix a couple of problems with MII-equipped NE2000 derivatives reported by
Björn Johannesson on current-users@:

- Re-factor dp8390_stop() into dp8390_halt() (that does the stuff to
halt the hardware) and dp8390_stop() (which alls dp8390_halt() before
calling mii_down() via sc->sc_stop_card()). This prevents us from
calling mii_down() before all of the interface data structures have
been set up, which these days can trip a KASSERT().

- Add a 1-second timer to call mii_tick(), and enable it in the
sc->sc_init_card() callback, and cancel it in the sc->sc_stop_card()
and sc->sc_media_fini() callbacks. This is actually a long-standing
bug that previously didn't have much practical effect, but causes
problems with dhcpcd's link live-ness detection logic.
 1.34 15-Jul-2018  maxv branches: 1.34.18;
Retire ipkdb entirely. The option was removed from the config files
yesterday.

ok kamil christos
 1.33 13-Apr-2015  riastradh branches: 1.33.16; 1.33.18;
Convert sys/dev to use <sys/rndsource.h>.
 1.32 02-Feb-2012  tls branches: 1.32.6; 1.32.24;
Entropy-pool implementation move and cleanup.

1) Move core entropy-pool code and source/sink/sample management code
to sys/kern from sys/dev.

2) Remove use of NRND as test for presence of entropy-pool code throughout
source tree.

3) Remove use of RND_ENABLED in device drivers as microoptimization to
avoid expensive operations on disabled entropy sources; make the
rnd_add calls do this directly so all callers benefit.

4) Fix bug in recent rnd_add_data()/rnd_add_uint32() changes that might
have lead to slight entropy overestimation for some sources.

5) Add new source types for environmental sensors, power sensors, VM
system events, and skew between clocks, with a sample implementation
for each.

ok releng to go in before the branch due to the difficulty of later
pullup (widespread #ifdef removal and moved files). Tested with release
builds on amd64 and evbarm and live testing on amd64.
 1.31 19-Nov-2011  tls branches: 1.31.2;
First step of random number subsystem rework described in
<20111022023242.BA26F14A158@mail.netbsd.org>. This change includes
the following:

An initial cleanup and minor reorganization of the entropy pool
code in sys/dev/rnd.c and sys/dev/rndpool.c. Several bugs are
fixed. Some effort is made to accumulate entropy more quickly at
boot time.

A generic interface, "rndsink", is added, for stream generators to
request that they be re-keyed with good quality entropy from the pool
as soon as it is available.

The arc4random()/arc4randbytes() implementation in libkern is
adjusted to use the rndsink interface for rekeying, which helps
address the problem of low-quality keys at boot time.

An implementation of the FIPS 140-2 statistical tests for random
number generator quality is provided (libkern/rngtest.c). This
is based on Greg Rose's implementation from Qualcomm.

A new random stream generator, nist_ctr_drbg, is provided. It is
based on an implementation of the NIST SP800-90 CTR_DRBG by
Henric Jungheim. This generator users AES in a modified counter
mode to generate a backtracking-resistant random stream.

An abstraction layer, "cprng", is provided for in-kernel consumers
of randomness. The arc4random/arc4randbytes API is deprecated for
in-kernel use. It is replaced by "cprng_strong". The current
cprng_fast implementation wraps the existing arc4random
implementation. The current cprng_strong implementation wraps the
new CTR_DRBG implementation. Both interfaces are rekeyed from
the entropy pool automatically at intervals justifiable from best
current cryptographic practice.

In some quick tests, cprng_fast() is about the same speed as
the old arc4randbytes(), and cprng_strong() is about 20% faster
than rnd_extract_data(). Performance is expected to improve.

The AES code in src/crypto/rijndael is no longer an optional
kernel component, as it is required by cprng_strong, which is
not an optional kernel component.

The entropy pool output is subjected to the rngtest tests at
startup time; if it fails, the system will reboot. There is
approximately a 3/10000 chance of a false positive from these
tests. Entropy pool _input_ from hardware random numbers is
subjected to the rngtest tests at attach time, as well as the
FIPS continuous-output test, to detect bad or stuck hardware
RNGs; if any are detected, they are detached, but the system
continues to run.

A problem with rndctl(8) is fixed -- datastructures with
pointers in arrays are no longer passed to userspace (this
was not a security problem, but rather a major issue for
compat32). A new kernel will require a new rndctl.

The sysctl kern.arandom() and kern.urandom() nodes are hooked
up to the new generators, but the /dev/*random pseudodevices
are not, yet.

Manual pages for the new kernel interfaces are forthcoming.
 1.30 12-May-2009  cegger branches: 1.30.12;
struct device * -> device_t, no functional changes intended.
 1.29 12-Mar-2008  cube branches: 1.29.4; 1.29.18;
Split device_t and softc for the NE2000 Ethernet chip and all its variants
and attachments. Use device_t accessors, correct types, and ANSIfy when
appropriate.
 1.28 04-Mar-2007  christos branches: 1.28.16; 1.28.32; 1.28.36;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.27 11-Dec-2005  christos branches: 1.27.26;
merge ktrace-lwp.
 1.26 26-Feb-2005  bsh branches: 1.26.4;
ASIX AX88796 is an NE2000 compatible ethernet chip, but doesn't seem to
have "remote DMA complete bit" is ISR. So, don't wait for ISR.RDC bit
after writing a packet.
 1.25 04-Feb-2005  perry de-__P
 1.24 02-Nov-2003  wiz branches: 1.24.8; 1.24.10;
Fix some typos. From Tom Cosgrove via jmc@openbsd.
 1.23 12-Feb-2001  thorpej branches: 1.23.24;
Add a "stop_card", which is the opposite of "init_card", and
call it from dp8390_stop().
 1.22 12-Feb-2001  thorpej Adjust the way that media is initialized on DP8390-compatible
chips. The dp8390_softc now has media_init and media_fini
function pointers that do the work.
 1.21 10-Feb-2001  thorpej Include MII glue here -- some DP8390-compatible chips have MII
interfaces on them (scary, eh?)
 1.20 28-Sep-2000  tsutsui 6 -> ETHER_ADDR_LEN
 1.19 29-May-2000  jhawk For all network drivers that call ether_ifattach(), and also
have _detach() functions:
Ensure that softc keeps state about whether the attach succeeded,
and make the detach function return immediately if the attach did
not complete.
 1.18 22-Mar-2000  ws branches: 1.18.2;
Make IPKDB working again.
Add support for i386 debugging and pci-based ne2000 boards.
 1.17 22-Mar-2000  ws Add bus_space_barrier.
Add DELAY in some busy loops to allow the dma engine to actually do something
(neccessary on fast processors).
 1.16 09-Feb-2000  enami ASIX AX88190 support (Planex FNW-3700-T and Melco LPC3-TX) from FreeBSD/PAO3.
 1.15 09-Feb-2000  enami - Since all resources are mandatory, no need to manage individually.
- KNF some code.
- Factor out some code into function.
- Disestablish an interrupt handler when failed to enable card power.
 1.14 02-Feb-2000  itojun handle attach failure in ne/pcmcia more carefully. (otherwise we'll
have trouble on detach)
 1.13 02-Feb-2000  itojun use a bit more standard (sys/device.h) prototype for {dp8390,ne2000}_detach().
 1.12 02-Feb-2000  itojun implement if_detach code for ne/pcmcia.
XXX still incomplete, ne_pcmcia_detach() commented out for safery - please test
 1.11 07-Feb-1999  thorpej branches: 1.11.8;
Add entropy gathering.
 1.10 18-Nov-1998  thorpej branches: 1.10.2;
Now that the *_activate() functions don't do things which are attachment
specific, move them into the chipset drivers.
 1.9 17-Nov-1998  thorpej Expose the "enable" and "disable" functions so that the front-ends can
access them.
 1.8 12-Aug-1998  scottr Support Cabletron Ethernet card, from John Marohn in PR 5762.
 1.7 05-Nov-1997  thorpej is790 u_char -> int.
 1.6 02-Nov-1997  thorpej Add ifmedia support via callbacks to the front-end.
 1.5 15-Oct-1997  thorpej branches: 1.5.2;
Pulldown from marc-pcmcia branch: minor tweaks to make this a completely
bus-independent driver, and garbage collect a few unnecessary things
from the softc.
 1.4 15-Oct-1997  explorer back out previous change (committed in error)
 1.3 15-Oct-1997  explorer minor formatting change
 1.2 30-Apr-1997  scottr branches: 1.2.4;
Remove the use16bit softc field, replacing the functionality with dcr_reg.
This allows the front end to override the default DCR (byte-wide DMA,
x86 byte order, 8-byte FIFO) with different transfer size, byte order, DMA
parameters, and FIFO threshhold. If the loopback select bit is not set for
normal operation, the default is used instead.

Inspired by thoughts from Bernd Ernesti.
 1.1 29-Apr-1997  scottr Machine-independent driver for DP8390/WD83C690-based Ethernet controller.
Derived from the ISA if_ed driver and the mac68k if_ae driver.
 1.2.4.2 14-Oct-1997  thorpej Add power management hooks.
 1.2.4.1 14-Oct-1997  thorpej - Don't assume NIC-addressable memory starts at 0. Compute the first
transmit page based on mem_start.
- Garbage-collect the "typestr" and "type" stuff. Let the front-end
print information about the card model, and the "type" stuff has all
been replaced by function pointers, anyhow.
- Generalize the interrupt handler (i.e. don't take mac68k-specific
arguements; that front-end should set up a wrapper interrupt handler).
- Fix the NIC_GET() and NIC_PUT() macros so that they work with more
implementations of bus_space(9).
 1.5.2.1 05-Nov-1997  thorpej Pull up from trunk: Add ifmedia support.
 1.10.2.1 11-Dec-1998  kenh The beginnings of interface detach support. Still some bugs, but mostly
works for me.

This work was originally by Bill Studenmund, and cleaned up by me.
 1.11.8.3 12-Mar-2001  bouyer Sync with HEAD.
 1.11.8.2 11-Feb-2001  bouyer Sync with HEAD.
 1.11.8.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.18.2.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.23.24.5 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.23.24.4 04-Feb-2005  skrll Sync with HEAD.
 1.23.24.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.23.24.2 18-Sep-2004  skrll Sync with HEAD.
 1.23.24.1 03-Aug-2004  skrll Sync with HEAD
 1.24.10.2 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.24.10.1 12-Feb-2005  yamt sync with head.
 1.24.8.1 29-Apr-2005  kent sync with -current
 1.26.4.2 17-Mar-2008  yamt sync with head.
 1.26.4.1 03-Sep-2007  yamt sync with head.
 1.27.26.1 12-Mar-2007  rmind Sync with HEAD.
 1.28.36.1 03-Apr-2008  mjf Sync with HEAD.
 1.28.32.1 24-Mar-2008  keiichi sync with head.
 1.28.16.1 23-Mar-2008  matt sync with HEAD
 1.29.18.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.29.4.1 16-May-2009  yamt sync with head
 1.30.12.1 17-Apr-2012  yamt sync with head
 1.31.2.1 18-Feb-2012  mrg merge to -current.
 1.32.24.1 06-Jun-2015  skrll Sync with HEAD
 1.32.6.1 03-Dec-2017  jdolecek update from HEAD
 1.33.18.1 10-Jun-2019  christos Sync with HEAD
 1.33.16.1 28-Jul-2018  pgoyette Sync with HEAD
 1.34.18.1 01-Aug-2021  thorpej Sync with HEAD.
 1.50 29-Jun-2024  riastradh if_stats(9): Add ifp argument to if_stat..._ref.

This will enable us to pass the ifp through to a dtrace probe inside.

No functional change intended in this change, but this is an API
change visible to modules so it shouldn't be pulled up.

PR kern/58377
 1.49 25-Sep-2022  thorpej Remove unnecessary include of <sys/malloc.h>.
 1.48 25-Jun-2022  tsutsui Pass proper status values to rnd_add_uint32(9) as rnd(9) man page claims.
 1.47 20-Feb-2021  rin sn(4): Add rnd(9) support.
 1.46 15-Mar-2020  thorpej branches: 1.46.4;
Don't bother with IFF_OACTIVE.
 1.45 29-Jan-2020  thorpej Adopt <net/if_stats.h>.
 1.44 28-May-2019  msaitoh branches: 1.44.4;
Use ETHER_LOCK()/ETHER_UNLOCK() for all ethernet drivers to protect ec_multi*.
 1.43 23-May-2019  msaitoh -No functional change:
- KNF
- u_int*_t -> uint*_t.
 1.42 26-Jun-2018  msaitoh branches: 1.42.2;
Implement the BPF direction filter (BIOC[GS]DIRECTION). It provides backward
compatibility with BIOC[GS]SEESENT ioctl. The userland interface is the same
as FreeBSD.

This change also fixes a bug that the direction is misunderstand on some
environment by passing the direction to bpf_mtap*() instead of checking
m->m_pkthdr.rcvif.
 1.41 29-Jul-2017  riastradh branches: 1.41.2;
Plug mbuf leak on MCLGET failure in sonic_rxintr.

From Ilja Van Sprundel.
 1.40 23-May-2017  ozaki-r branches: 1.40.2;
Apply deferred if_start to more drivers

And annotate some XXX_start as it runs in softint to clarify that
it doesn't need deferred if_start.
 1.39 15-Dec-2016  ozaki-r Move bpf_mtap and if_ipackets++ on Rx of each driver to percpuq if_input

The benefits of the change are:
- We can reduce codes
- We can provide the same behavior between drivers
- Where/When if_ipackets is counted up
- Note that some drivers still update packet statistics in their own
way (periodical update)
- Moved bpf_mtap run in softint
- This makes it easy to MP-ify bpf

Proposed on tech-kern and tech-net
 1.38 10-Jun-2016  ozaki-r branches: 1.38.2;
Introduce m_set_rcvif and m_reset_rcvif

The API is used to set (or reset) a received interface of a mbuf.
They are counterpart of m_get_rcvif, which will come in another
commit, hide internal of rcvif operation, and reduce the diff of
the upcoming change.

No functional change.
 1.37 09-Feb-2016  ozaki-r Introduce softint-based if_input

This change intends to run the whole network stack in softint context
(or normal LWP), not hardware interrupt context. Note that the work is
still incomplete by this change; to that end, we also have to softint-ify
if_link_state_change (and bpf) which can still run in hardware interrupt.

This change softint-ifies at ifp->if_input that is called from
each device driver (and ieee80211_input) to ensure Layer 2 runs
in softint (e.g., ether_input and bridge_input). To this end,
we provide a framework (called percpuq) that utlizes softint(9)
and percpu ifqueues. With this patch, rxintr of most drivers just
queues received packets and schedules a softint, and the softint
dequeues packets and does rest packet processing.

To minimize changes to each driver, percpuq is allocated in struct
ifnet for now and that is initialized by default (in if_attach).
We probably have to move percpuq to softc of each driver, but it's
future work. At this point, only wm(4) has percpuq in its softc
as a reference implementation.

Additional information including performance numbers can be found
in the thread at tech-kern@ and tech-net@:
http://mail-index.netbsd.org/tech-kern/2016/01/14/msg019997.html

Acknowledgment: riastradh@ greatly helped this work.
Thank you very much!
 1.36 25-Oct-2013  martin branches: 1.36.4; 1.36.6; 1.36.8; 1.36.12;
Remove unused stuff
 1.35 13-Nov-2010  uebayasi branches: 1.35.8; 1.35.14; 1.35.18; 1.35.20; 1.35.22; 1.35.28;
Don't pull in the whole uvm(9) API to access only PAGE_SIZE and
some other constants. These are provided by sys/param.h now.
 1.34 05-Apr-2010  joerg Push the bpf_ops usage back into bpf.h. Push the common ifp->if_bpf
check into the inline functions as well the fourth argument for
bpf_attach.
 1.33 19-Jan-2010  pooka branches: 1.33.2; 1.33.4;
Redefine bpf linkage through an always present op vector, i.e.
#if NBPFILTER is no longer required in the client. This change
doesn't yet add support for loading bpf as a module, since drivers
can register before bpf is attached. However, callers of bpf can
now be modularized.

Dynamically loadable bpf could probably be done fairly easily with
coordination from the stub driver and the real driver by registering
attachments in the stub before the real driver is loaded and doing
a handoff. ... and I'm not going to ponder the depths of unload
here.

Tested with i386/MONOLITHIC, modified MONOLITHIC without bpf and rump.
 1.32 02-Sep-2009  tsutsui Use a proper local variable.
 1.31 02-Sep-2009  tsutsui Make local functions static.
 1.30 02-Sep-2009  tsutsui Invert logic around nested pmf(9) registrations for readability.
 1.29 01-Sep-2009  tsutsui Also call pmf_class_network_register(9).
 1.28 01-Sep-2009  tsutsui Replace shutdownhook_establish(9) with pmf_device_register1(9).
 1.27 23-Aug-2008  tsutsui Fix typo in comment.
 1.26 28-Apr-2008  martin branches: 1.26.2; 1.26.6;
Remove clause 3 and 4 from TNF licenses
 1.25 23-Apr-2008  tsutsui branches: 1.25.2;
Split softc/device_t and misc cleanup for sn(4).
 1.24 19-Apr-2008  tsutsui The DP83932C manual says the CAM enable register (CER) can't be
accessed on normal operations and the CER should be set up
through the last entry in the CAM desciptor area and loaded
via LCAM command, so make our driver do so, though the previoius
code (writing CER directly) worked without problems.

Tested on sn at jazzio on arc (in 32bit mode) by me and
sn at nubus on mac68k (in 16bit mode) by Paul Ripke on port-mac68k.
 1.23 08-Apr-2008  cegger branches: 1.23.2;
use aprint_*_dev and device_xname
 1.22 14-Mar-2008  tsutsui Enable ETHERCAP_VLAN_MTU.
 1.21 12-Mar-2008  dyoung sonic_stop: clear IFF_RUNNING before disabling.
 1.20 19-Jan-2008  dyoung branches: 1.20.2; 1.20.6;
There is really no use for switch when there is no case labels
except for the default, so remove the enclosing switch and the
default label.
 1.19 19-Oct-2007  ad branches: 1.19.2; 1.19.8;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.18 26-Aug-2007  dyoung branches: 1.18.2; 1.18.6;
Constify: LLADDR -> CLLADDR. I'm aiming here to make it easier to
identify sockaddr_dl abuse that remains in the kernel, especially
the potential for overwriting memory past the end of a sockaddr_dl
with, e.g., memcpy(LLADDR(), ...).
 1.17 08-Jun-2007  tsutsui branches: 1.17.2; 1.17.6;
Set DCR_TFT[01] and DCR_RFT[01] bits of DCR register for TX/RX thresholds
in each MD attachment since optimized values could be machine dependent.
 1.16 02-Jun-2007  tsutsui In sonic_reset(), make sure to stop TX, RX and timer
and clear and disable all interrupts.
Required by mac68k obio sonic cards, and
no bad side effect on arc jazzio sonic.
 1.15 02-Jun-2007  tsutsui Sync tda_status and rda_status DMA descriptors also after they are polled
in interrupt handlers for systems which don't have BUS_DMA_COHERENT support.
 1.14 04-Mar-2007  christos branches: 1.14.2; 1.14.4;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.13 11-Dec-2005  christos branches: 1.13.26;
merge ktrace-lwp.
 1.12 27-Feb-2005  perry branches: 1.12.4;
nuke trailing whitespace
 1.11 31-Jan-2005  thorpej Eliminate use of M_HASFCS.
 1.10 30-Oct-2004  thorpej branches: 1.10.4; 1.10.6;
When adding/deleting multicast addresses, only whack the address
filter if the interface is marked RUNNING.

Fixes kern/27678.
 1.9 29-Oct-2003  tsutsui branches: 1.9.4;
Fix bogus GCC uninitialized variable warning.
 1.8 18-Jan-2003  tsutsui branches: 1.8.2;
When the extra pad buffer is used, the number of TX segments
should be incremented than dm_nsegs.
 1.7 18-Jan-2003  tsutsui Fix pasto and typos.
 1.6 15-Jan-2003  bouyer Use a properly zero'd buffer to pad the packet to ETHER_MIN_LEN-ETHER_CRC_LEN
 1.5 13-Nov-2001  lukem branches: 1.5.10;
add/cleanup RCSID
 1.4 23-Jul-2001  tsutsui branches: 1.4.2;
Make sure to initialize the all Rx descriptors properly in sonic_init()
even if mbuf for them are already allocated.
This fixes "receive descriptor exhausted" errors.
 1.3 19-Jul-2001  thorpej Use BUS_DMA_READ and BUS_DMA_WRITE in some obvious places.
 1.2 05-Jul-2001  thorpej branches: 1.2.2;
Do a little manual CSE, taking unneeded comparisons out of loops,
and shrinking the object code somewhat. On an R4400:

Before:
text data bss dec hex filename
16248 16 0 16264 3f88 dp83932.o

Before:
text data bss dec hex filename
14424 16 0 14440 3868 dp83932.o
 1.1 05-Jul-2001  thorpej A new DP83932 ``SONIC'' driver, which uses bus_dma(9) and does I/O
directly to mbufs. Handles both 32-bit and 16-bit, big- and little-
endian configurations of the chip (we could squeeze out some conditionals
yet, though).
 1.2.2.2 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.2.2.1 03-Aug-2001  lukem update to -current
 1.4.2.4 17-Jan-2003  thorpej Sync with HEAD.
 1.4.2.3 14-Nov-2001  nathanw Catch up to -current.
 1.4.2.2 24-Aug-2001  nathanw Catch up with -current.
 1.4.2.1 23-Jul-2001  nathanw file dp83932.c was added on branch nathanw_sa on 2001-08-24 00:09:21 +0000
 1.5.10.1 26-Jan-2003  he Pull up revisions 1.6-1.8 (requested by bouyer in ticket #1084):
Use a properly zeroed buffer to pad small packets to make sure
the chip doesn't send random data.
 1.8.2.6 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.8.2.5 04-Feb-2005  skrll Sync with HEAD.
 1.8.2.4 02-Nov-2004  skrll Sync with HEAD.
 1.8.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.8.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.8.2.1 03-Aug-2004  skrll Sync with HEAD
 1.9.4.1 24-Jan-2005  he Pull up revision 1.10 (requested by thorpej in ticket #939):
When adding or deleting multicast addresses, only change
the address filter if the interface is marked RUNNING.
Fixes PR#27678.
 1.10.6.2 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.10.6.1 12-Feb-2005  yamt sync with head.
 1.10.4.1 29-Apr-2005  kent sync with -current
 1.12.4.4 17-Mar-2008  yamt sync with head.
 1.12.4.3 21-Jan-2008  yamt sync with head
 1.12.4.2 27-Oct-2007  yamt sync with head.
 1.12.4.1 03-Sep-2007  yamt sync with head.
 1.13.26.1 12-Mar-2007  rmind Sync with HEAD.
 1.14.4.1 11-Jul-2007  mjf Sync with head.
 1.14.2.4 23-Oct-2007  ad Sync with head.
 1.14.2.3 09-Oct-2007  ad Sync with head.
 1.14.2.2 15-Jul-2007  ad Sync with head.
 1.14.2.1 09-Jun-2007  ad Sync with head.
 1.17.6.2 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.17.6.1 03-Sep-2007  jmcneill Sync with HEAD.
 1.17.2.1 03-Sep-2007  skrll Sync with HEAD.
 1.18.6.1 25-Oct-2007  bouyer Sync with HEAD.
 1.18.2.2 23-Mar-2008  matt sync with HEAD
 1.18.2.1 06-Nov-2007  matt sync with HEAD
 1.19.8.1 20-Jan-2008  bouyer Sync with HEAD
 1.19.2.1 18-Feb-2008  mjf Sync with HEAD.
 1.20.6.3 28-Sep-2008  mjf Sync with HEAD.
 1.20.6.2 02-Jun-2008  mjf Sync with HEAD.
 1.20.6.1 03-Apr-2008  mjf Sync with HEAD.
 1.20.2.1 24-Mar-2008  keiichi sync with head.
 1.23.2.1 18-May-2008  yamt sync with head.
 1.25.2.5 11-Aug-2010  yamt sync with head.
 1.25.2.4 11-Mar-2010  yamt sync with head
 1.25.2.3 16-Sep-2009  yamt sync with head
 1.25.2.2 04-May-2009  yamt sync with head.
 1.25.2.1 16-May-2008  yamt sync with head.
 1.26.6.1 19-Oct-2008  haad Sync with HEAD.
 1.26.2.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.33.4.2 05-Mar-2011  rmind sync with head
 1.33.4.1 30-May-2010  rmind sync with head
 1.33.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.35.28.1 18-Aug-2017  snj Pull up following revision(s) (requested by mrg in ticket #1476):
sys/dev/ic/dp83932.c: revision 1.41
Plug mbuf leak on MCLGET failure in sonic_rxintr.
From Ilja Van Sprundel.
 1.35.22.1 18-May-2014  rmind sync with head
 1.35.20.1 18-Aug-2017  snj Pull up following revision(s) (requested by mrg in ticket #1476):
sys/dev/ic/dp83932.c: revision 1.41
Plug mbuf leak on MCLGET failure in sonic_rxintr.
From Ilja Van Sprundel.
 1.35.18.2 03-Dec-2017  jdolecek update from HEAD
 1.35.18.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.35.14.1 18-Aug-2017  snj Pull up following revision(s) (requested by mrg in ticket #1476):
sys/dev/ic/dp83932.c: revision 1.41
Plug mbuf leak on MCLGET failure in sonic_rxintr.
From Ilja Van Sprundel.
 1.35.8.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.36.12.1 12-Aug-2017  snj Pull up following revision(s) (requested by mrg in ticket #1472):
sys/dev/ic/dp83932.c: revision 1.41
Plug mbuf leak on MCLGET failure in sonic_rxintr.
From Ilja Van Sprundel.
 1.36.8.1 12-Aug-2017  snj Pull up following revision(s) (requested by mrg in ticket #1472):
sys/dev/ic/dp83932.c: revision 1.41
Plug mbuf leak on MCLGET failure in sonic_rxintr.
From Ilja Van Sprundel.
 1.36.6.4 28-Aug-2017  skrll Sync with HEAD
 1.36.6.3 05-Feb-2017  skrll Sync with HEAD
 1.36.6.2 09-Jul-2016  skrll Sync with HEAD
 1.36.6.1 19-Mar-2016  skrll Sync with HEAD
 1.36.4.1 12-Aug-2017  snj Pull up following revision(s) (requested by mrg in ticket #1472):
sys/dev/ic/dp83932.c: revision 1.41
Plug mbuf leak on MCLGET failure in sonic_rxintr.
From Ilja Van Sprundel.
 1.38.2.1 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.40.2.1 05-Aug-2017  snj Pull up following revision(s) (requested by spz in ticket #185):
sys/dev/ic/dp83932.c: revision 1.41
Plug mbuf leak on MCLGET failure in sonic_rxintr.
From Ilja Van Sprundel.
 1.41.2.1 28-Jul-2018  pgoyette Sync with HEAD
 1.42.2.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.42.2.1 10-Jun-2019  christos Sync with HEAD
 1.44.4.1 29-Feb-2020  ad Sync with head.
 1.46.4.1 03-Apr-2021  thorpej Sync with HEAD.
 1.7 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.6 25-Dec-2007  perry branches: 1.6.6; 1.6.8; 1.6.10;
Convert many of the uses of __attribute__ to equivalent
__packed, __unused and __dead macros from cdefs.h
 1.5 02-Jun-2007  tsutsui branches: 1.5.8; 1.5.14; 1.5.16; 1.5.20;
In sonic_reset(), make sure to stop TX, RX and timer
and clear and disable all interrupts.
Required by mac68k obio sonic cards, and
no bad side effect on arc jazzio sonic.
 1.4 11-Dec-2005  christos branches: 1.4.30; 1.4.32;
merge ktrace-lwp.
 1.3 10-Nov-2003  wiz branches: 1.3.16;
Spell address with two d's. Inspired by similar changes in OpenBSD,
originating from Jonathon Gray and forwarded by jmc@openbsd.
 1.2 03-May-2002  thorpej branches: 1.2.10;
Bump the number of Tx DMA segments from 8 to 16 (the zero-copy socket
code sometimes sees more than 8).
 1.1 05-Jul-2001  thorpej branches: 1.1.2; 1.1.4;
A new DP83932 ``SONIC'' driver, which uses bus_dma(9) and does I/O
directly to mbufs. Handles both 32-bit and 16-bit, big- and little-
endian configurations of the chip (we could squeeze out some conditionals
yet, though).
 1.1.4.3 20-Jun-2002  nathanw Catch up to -current.
 1.1.4.2 24-Aug-2001  nathanw Catch up with -current.
 1.1.4.1 05-Jul-2001  nathanw file dp83932reg.h was added on branch nathanw_sa on 2001-08-24 00:09:21 +0000
 1.1.2.1 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.2.10.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.2.10.2 18-Sep-2004  skrll Sync with HEAD.
 1.2.10.1 03-Aug-2004  skrll Sync with HEAD
 1.3.16.2 21-Jan-2008  yamt sync with head
 1.3.16.1 03-Sep-2007  yamt sync with head.
 1.4.32.1 11-Jul-2007  mjf Sync with head.
 1.4.30.1 09-Jun-2007  ad Sync with head.
 1.5.20.1 02-Jan-2008  bouyer Sync with HEAD
 1.5.16.1 26-Dec-2007  ad Sync with head.
 1.5.14.1 18-Feb-2008  mjf Sync with HEAD.
 1.5.8.1 09-Jan-2008  matt sync with HEAD
 1.6.10.1 16-May-2008  yamt sync with head.
 1.6.8.1 18-May-2008  yamt sync with head.
 1.6.6.1 02-Jun-2008  mjf Sync with HEAD.
 1.13 20-Feb-2021  rin sn(4): Add rnd(9) support.
 1.12 01-Sep-2009  tsutsui branches: 1.12.78;
Replace shutdownhook_establish(9) with pmf_device_register1(9).
 1.11 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.10 23-Apr-2008  tsutsui branches: 1.10.2;
Split softc/device_t and misc cleanup for sn(4).
 1.9 19-Apr-2008  tsutsui The DP83932C manual says the CAM enable register (CER) can't be
accessed on normal operations and the CER should be set up
through the last entry in the CAM desciptor area and loaded
via LCAM command, so make our driver do so, though the previoius
code (writing CER directly) worked without problems.

Tested on sn at jazzio on arc (in 32bit mode) by me and
sn at nubus on mac68k (in 16bit mode) by Paul Ripke on port-mac68k.
 1.8 19-Apr-2008  tsutsui Fix a typo which is fatal on cards configured in 16 bit mode.
Problem is reported and fix is confirmed by Paul Ripke on port-mac68k.
 1.7 25-Dec-2007  perry branches: 1.7.6; 1.7.8;
Convert many of the uses of __attribute__ to equivalent
__packed, __unused and __dead macros from cdefs.h
 1.6 16-Feb-2006  perry branches: 1.6.40; 1.6.46; 1.6.50; 1.6.54;
Change "inline" back to "__inline" in .h files -- C99 is still too
new, and some apps compile things in C89 mode. C89 keywords stay.

As per core@.
 1.5 24-Dec-2005  perry branches: 1.5.2; 1.5.4; 1.5.6;
Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.4 15-Jan-2003  bouyer branches: 1.4.18;
Use a properly zero'd buffer to pad the packet to ETHER_MIN_LEN-ETHER_CRC_LEN
 1.3 06-Jul-2001  thorpej branches: 1.3.4; 1.3.18;
Fix a typo in htosonic32(), pointed out by soda@netbsd.org.
 1.2 05-Jul-2001  thorpej Do a little manual CSE, taking unneeded comparisons out of loops,
and shrinking the object code somewhat. On an R4400:

Before:
text data bss dec hex filename
16248 16 0 16264 3f88 dp83932.o

Before:
text data bss dec hex filename
14424 16 0 14440 3868 dp83932.o
 1.1 05-Jul-2001  thorpej A new DP83932 ``SONIC'' driver, which uses bus_dma(9) and does I/O
directly to mbufs. Handles both 32-bit and 16-bit, big- and little-
endian configurations of the chip (we could squeeze out some conditionals
yet, though).
 1.3.18.1 26-Jan-2003  he Pull up revision 1.4 (requested by bouyer in ticket #1084):
Use a properly zeroed buffer to pad small packets to make sure
the chip doesn't send random data.
 1.3.4.3 17-Jan-2003  thorpej Sync with HEAD.
 1.3.4.2 24-Aug-2001  nathanw Catch up with -current.
 1.3.4.1 06-Jul-2001  nathanw file dp83932var.h was added on branch nathanw_sa on 2001-08-24 00:09:21 +0000
 1.4.18.1 21-Jan-2008  yamt sync with head
 1.5.6.1 22-Apr-2006  simonb Sync with head.
 1.5.4.1 09-Sep-2006  rpaulo sync with head
 1.5.2.1 18-Feb-2006  yamt sync with head.
 1.6.54.1 02-Jan-2008  bouyer Sync with HEAD
 1.6.50.1 26-Dec-2007  ad Sync with head.
 1.6.46.1 18-Feb-2008  mjf Sync with HEAD.
 1.6.40.1 09-Jan-2008  matt sync with HEAD
 1.7.8.1 18-May-2008  yamt sync with head.
 1.7.6.1 02-Jun-2008  mjf Sync with HEAD.
 1.10.2.2 16-Sep-2009  yamt sync with head
 1.10.2.1 16-May-2008  yamt sync with head.
 1.12.78.1 03-Apr-2021  thorpej Sync with HEAD.
 1.79 10-Feb-2024  andvar s/musn't/mustn't/ in comments.
 1.78 10-Nov-2021  msaitoh s/certian/certain/ in comment.
 1.77 07-Aug-2021  thorpej Merge thorpej-cfargs2.
 1.76 24-Apr-2021  thorpej branches: 1.76.8;
Merge thorpej-cfargs branch:

Simplify and make extensible the config_search() / config_found() /
config_attach() interfaces: rather than having different variants for
which arguments you want pass along, just have a single call that
takes a variadic list of tag-value arguments.

Adjust all call sites:
- Simplify wherever possible; don't pass along arguments that aren't
actually needed.
- Don't be explicit about what interface attribute is attaching if
the device only has one. (More simplification.)
- Add a config_probe() function to be used in indirect configuiration
situations, making is visibly easier to see when indirect config is
in play, and allowing for future change in semantics. (As of now,
this is just a wrapper around config_match(), but that is an
implementation detail.)

Remove unnecessary or redundant interface attributes where they're not
needed.

There are currently 5 "cfargs" defined:
- CFARG_SUBMATCH (submatch function for direct config)
- CFARG_SEARCH (search function for indirect config)
- CFARG_IATTR (interface attribte)
- CFARG_LOCATORS (locators array)
- CFARG_DEVHANDLE (devhandle_t - wraps OFW, ACPI, etc. handles)

...and a sentinel value CFARG_EOL.

Add some extra sanity checking to ensure that interface attributes
aren't ambiguous.

Use CFARG_DEVHANDLE in MI FDT, OFW, and ACPI code, and macppc and shark
ports to associate those device handles with device_t instance. This
will trickle trough to more places over time (need back-end for pre-OFW
Sun OBP; any others?).
 1.75 03-Sep-2018  riastradh branches: 1.75.14;
Rename min/max -> uimin/uimax for better honesty.

These functions are defined on unsigned int. The generic name
min/max should not silently truncate to 32 bits on 64-bit systems.
This is purely a name change -- no functional change intended.

HOWEVER! Some subsystems have

#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))

even though our standard name for that is MIN/MAX. Although these
may invite multiple evaluation bugs, these do _not_ cause integer
truncation.

To avoid `fixing' these cases, I first changed the name in libkern,
and then compile-tested every file where min/max occurred in order to
confirm that it failed -- and thus confirm that nothing shadowed
min/max -- before changing it.

I have left a handful of bootloaders that are too annoying to
compile-test, and some dead code:

cobalt ews4800mips hp300 hppa ia64 luna68k vax
acorn32/if_ie.c (not included in any kernels)
macppc/if_gm.c (superseded by gem(4))

It should be easy to fix the fallout once identified -- this way of
doing things fails safe, and the goal here, after all, is to _avoid_
silent integer truncations, not introduce them.

Maybe one day we can reintroduce min/max as type-generic things that
never silently truncate. But we should avoid doing that for a while,
so that existing code has a chance to be detected by the compiler for
conversion to uimin/uimax without changing the semantics until we can
properly audit it all. (Who knows, maybe in some cases integer
truncation is actually intended!)
 1.74 28-Oct-2017  riastradh branches: 1.74.2; 1.74.4;
Kill some more extern struct cfdriver declarations.

Down with externs in .c!
 1.73 07-Jul-2016  msaitoh KNF. Remove extra spaces. No functional change.
 1.72 18-Oct-2014  snj branches: 1.72.2;
src is too big these days to tolerate superfluous apostrophes. It's
"its", people!
 1.71 25-Jul-2014  dholland Add d_discard to all struct cdevsw instances I could find.

All have been set to "nodiscard"; some should get a real implementation.
 1.70 16-Mar-2014  dholland branches: 1.70.2;
Change (mostly mechanically) every cdevsw/bdevsw I can find to use
designated initializers.

I have not built every extant kernel so I have probably broken at
least one build; however I've also found and fixed some wrong
cdevsw/bdevsw entries so even if so I think we come out ahead.
 1.69 12-Sep-2013  martin Remove unused variable
 1.68 27-Oct-2012  chs branches: 1.68.2;
split device_t/softc for all remaining drivers.
replace "struct device *" with "device_t".
use device_xname(), device_unit(), etc.
 1.67 15-Mar-2012  bouyer branches: 1.67.2;
Do not read past array end; found by gcc -O3
 1.66 07-Aug-2011  rmind branches: 1.66.2; 1.66.6;
Replace some wakeup_one(9) uses with mutex(9) or plain wakeup(9).
 1.65 01-Jul-2011  mrg apply some (uintptr_t) between pointer and int casting.
 1.64 13-Nov-2010  uebayasi Don't pull in the whole uvm(9) API to access only PAGE_SIZE and
some other constants. These are provided by sys/param.h now.
 1.63 21-Oct-2009  rmind branches: 1.63.4;
Remove uarea swap-out functionality:

- Addresses the issue described in PR/38828.
- Some simplification in threading and sleepq subsystems.
- Eliminates pmap_collect() and, as a side note, allows pmap optimisations.
- Eliminates XS_CTL_DATA_ONSTACK in scsipi code.
- Avoids few scans on LWP list and thus potentially long holds of proc_lock.
- Cuts ~1.5k lines of code. Reduces amd64 kernel size by ~4k.
- Removes __SWAP_BROKEN cases.

Tested on x86, mips, acorn32 (thanks <mpumford>) and partly tested on
acorn26 (thanks to <bjh21>).

Discussed on <tech-kern>, reviewed by <ad>.
 1.62 08-Jun-2008  tsutsui Replace device_lookup() with device_lookup_private() on getting softc
for future device_t/softc spilt.
 1.61 11-May-2008  ad Include machine/cputypes.h explicitly.
 1.60 28-Apr-2008  martin branches: 1.60.2;
Remove clause 3 and 4 from TNF licenses
 1.59 08-Apr-2008  cegger branches: 1.59.2; 1.59.4;
use aprint_*_dev and device_xname
 1.58 19-Oct-2007  ad branches: 1.58.16;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.57 09-Jul-2007  ad branches: 1.57.6; 1.57.8; 1.57.12;
Merge some of the less invasive changes from the vmlocking branch:

- kthread, callout, devsw API changes
- select()/poll() improvements
- miscellaneous MT safety improvements
 1.56 04-Mar-2007  christos branches: 1.56.2; 1.56.4;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.55 02-Dec-2006  elad branches: 1.55.2;
Change kauth(9) KPI for kauth_authorize_device_passthru() to add another
argument, u_long, serving as a bit-mask of generic requests for the
passthru request.

Discussed on tech-security@ and tech-kern@. Okay tls@.
 1.54 16-Nov-2006  christos branches: 1.54.2;
__unused removal on arguments; approved by core.
 1.53 08-Nov-2006  elad Replace securelevel checks with kauth(9) calls.
 1.52 12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.51 04-Oct-2006  christos fix empty if
 1.50 30-Aug-2006  christos branches: 1.50.2; 1.50.4;
fix incomplete initializer
 1.49 23-Aug-2006  christos Acting as Elad's keyboard:

Place the securelevel checks in their logical locations.
This will be clearer in the future when code changes to use kauth(9) calls.

input and okay ad@
 1.48 21-May-2006  christos void casts to functions whose return values are ignored.
 1.47 14-Apr-2006  christos branches: 1.47.2;
Coverity CID 1534: Fix bogus code and array overruns.
 1.46 24-Dec-2005  perry branches: 1.46.4; 1.46.6; 1.46.8; 1.46.10; 1.46.12;
__inline__ -> inline
 1.45 11-Dec-2005  christos merge ktrace-lwp.
 1.44 27-Feb-2005  perry branches: 1.44.4;
nuke trailing whitespace
 1.43 22-Apr-2004  itojun branches: 1.43.4; 1.43.6;
sprintf -> snprintf
 1.42 25-Oct-2003  christos Fix uninitialized variable warnings
 1.41 29-Jun-2003  fvdl branches: 1.41.2;
Back out the lwp/ktrace changes. They contained a lot of colateral damage,
and need to be examined and discussed more.
 1.40 28-Jun-2003  darrenr Pass lwp pointers throughtout the kernel, as required, so that the lwpid can
be inserted into ktrace records. The general change has been to replace
"struct proc *" with "struct lwp *" in various function prototypes, pass
the lwp through and use l_proc to get the process pointer when needed.

Bump the kernel rev up to 1.6V
 1.39 31-Jan-2003  thorpej Use aprint_*().
 1.38 28-Jan-2003  kleink Fix printf format warnings in previous.
 1.37 27-Jan-2003  ad Also save status info in the user command packet.
 1.36 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.35 10-Dec-2002  fvdl Use 0xff as the 'unknown processor type' (which is what Linux does).
 1.34 09-Dec-2002  ad Fix LP64 issues.
 1.33 07-Dec-2002  ad Implement the DPT EATA ioctl() interface.
 1.32 27-Sep-2002  provos remove trailing \n in panic(). approved perry.
 1.31 13-Nov-2001  lukem branches: 1.31.10;
add/cleanup RCSID
 1.30 19-Jul-2001  thorpej Use BUS_DMA_READ and BUS_DMA_WRITE in some obvious places.
 1.29 25-Apr-2001  bouyer branches: 1.29.2;
Pull up the thorpej_scsipi branch to main branch.
This is a completely rewritten scsipi_xfer execution engine, and the
associated changes to HBA drivers. Overview of changes & features:
- All xfers are queued in the mid-layer, rather than doing so in an
ad-hoc fashion in individual adapter drivers.
- Adapter/channel resource management in the mid-layer, avoids even trying
to start running an xfer if the adapter/channel doesn't have the resources.
- Better communication between the mid-layer and the adapters.
- Asynchronous event notification mechanism from adapter to mid-layer and
peripherals.
- Better peripheral queue management: freeze/thaw, sorted requeueing during
recovery, etc.
- Clean separation of peripherals, adapters, and adapter channels (no more
scsipi_link).
- Kernel thread for each scsipi_channel makes error recovery much easier
(no more dealing with interrupt context when recovering from an error).
- Mid-layer support for tagged queueing: commands can have the tag type
set explicitly, tag IDs are allocated in the mid-layer (thus eliminating
the need to use buggy tag ID allocation schemes in many adapter drivers).
- support for QUEUE FULL and CHECK CONDITION status in mid-layer; the command
will be requeued, or a REQUEST SENSE will be sent as appropriate.

Just before the merge syssrc has been tagged with thorpej_scsipi_beforemerge
 1.28 25-Mar-2001  ad Missing splx(). From OpenBSD.
 1.27 10-Mar-2001  briggs Make this work on a PowerPC system:

- Load the DMA address a byte at a time, and
- Use bus_space_read_stream_2() instead of bus_space_read_2() when reading
the byte-stream of configuration data from the card.

Sanity-checked on both i386 and sandpoint. Reviewed by ad.
 1.26 07-Mar-2001  thorpej Add BUS_DMA_STREAMING to data transfer maps.
 1.25 24-Feb-2001  cgd branches: 1.25.2;
Avoid sequence point issues.
 1.24 14-Nov-2000  thorpej NBPG -> PAGE_SIZE
 1.23 18-Jul-2000  ad Use device_lookup() and ditch TAILQ sillyness.
 1.22 13-Jun-2000  ad branches: 1.22.2;
Use my proper name.
 1.21 16-Mar-2000  ad branches: 1.21.2;
Match shutdown msg with that of cac.c.
 1.20 29-Feb-2000  ad Oops, pasto.
 1.19 24-Feb-2000  ad - Don't use bitfields.
- Cosmetic changes.
- Shut down all HBAs "simultaneously", not individually.
- Don't bother grokking HA_ST_MORE. It causes problems.
- Other bits and pieces.
 1.18 12-Feb-2000  thorpej If we got an xfer from our backlog queue, don't allow sleeping; we're in
interrupt context.

XXX This is fixed properly in the thorpej_scsipi branch, but that won't
be ready for 1.5, I don't think.
 1.17 16-Jan-2000  ad branches: 1.17.2;
Be consistant when printing haHHBA status.
 1.16 15-Jan-2000  ad Typo. Don't worry, nothing that will cause system instability or data
corruption.
 1.15 15-Jan-2000  ad Validate EATA signature in returned EATA configuration data before anything
else. More proper than important.
 1.14 01-Jan-2000  ad - Make sense out of comment on dpt_wait().
- Trivial streamlining of logic in dpt_poll().
 1.13 29-Nov-1999  ad - Don't use our own private endian conversion cruft (from OpenBSD).
- SmartRAID V is not and will never be an EATA board (from OpenBSD).
- Use dpt_outl() when issuing EATA command packet address to HBA.
- Fix a style nit.
- Fix a typo.
 1.12 23-Oct-1999  ad Prepare a little for the addition of an interface to user-space.
 1.11 20-Oct-1999  ad Nuke some silliness.
 1.10 20-Oct-1999  ad DPT_MORE_TIMEOUT was scaled wrong.
 1.9 19-Oct-1999  ad - Don't get stalled by a bogus HA_ST_MORE condition.
- Don't trust HA_ST_MORE again if the above situation occurs.
- Nuke bitfields in 'struct eata_sp'.
- Don't bother using scatter-gather if DMA map contains only 1 segment.
- Return TRY_AGAIN_LATER and not COMPLETE if an EATA command times out.
- Check SCSI status in dpt_inquire(), not just HBA status.
- Some cosmetic changes and sanity checks.
 1.8 04-Oct-1999  thorpej branches: 1.8.2; 1.8.4; 1.8.6;
Avoid silly namespace collision w/ some Alpha signal-related variables.
 1.7 01-Oct-1999  ad - Save SCSI status in the request.
- In dpt_intr(), if no interrupt is signalled but the HBA has indicated
that more data will be available soon (HA_ST_MORE), save a context switch
and wait for the data.
 1.6 30-Sep-1999  thorpej Update for SCSPI changes.
 1.5 30-Sep-1999  ad - Remove a couple of items from the TODO list.
- Add a debug check to dpt_poll() (CCB must have CCB_PRIVATE set).
 1.4 29-Sep-1999  ad - Move initial reset code into dpt_readcfg()
- Bus specific front-end is now responsible for reading EATA configuration
- EATA configuration data is now saved in the softc
- Make synchronous writes work properly
- Don't ignore HBA timeouts in dpt_cmd()
- Prefix eata_cfg's members with `ec_', not `dc_'
 1.3 28-Sep-1999  ad - Fix some comments.
- Synchronous writes musn't linger in the HBA's cache.
 1.2 28-Sep-1999  ad - Wait up to 2 seconds for HBA ready before executing CP_PIO_GETCFG
- Remove some unneeded memset() calls and assignments
- Fix comment on dpt_done_ccb()
 1.1 27-Sep-1999  ad A driver for DPT EATA SCSI adapters. dpt.c contains a brief TODO list.
 1.8.6.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.8.4.1 15-Nov-1999  fvdl Sync with -current
 1.8.2.15 01-Apr-2001  ad - Make this work.
- Restructure a bit.
- KNF, const.
 1.8.2.14 27-Mar-2001  bouyer Sync with HEAD.
 1.8.2.13 23-Mar-2001  bouyer Make compile again.
 1.8.2.12 12-Mar-2001  bouyer Sync with HEAD.
 1.8.2.11 22-Nov-2000  bouyer Sync with HEAD.
 1.8.2.10 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.8.2.9 01-Nov-1999  thorpej Fixup the SC_DEBUG() stuff for the new world order.
 1.8.2.8 26-Oct-1999  thorpej Update for:

Deal a little more gracefully with the fact that xfer mode parameters
are for the I_T Nexus, and make all xfer mode updates `async events'.
 1.8.2.7 20-Oct-1999  thorpej Sync w/ trunk.
 1.8.2.6 20-Oct-1999  thorpej Eliminate sleeping from adapter routines.
 1.8.2.5 20-Oct-1999  ad Sync w/ -current.
 1.8.2.4 19-Oct-1999  ad - Sync with -current (untested as yet).
- One cosmetic change.
 1.8.2.3 19-Oct-1999  thorpej Don't sleep waiting for a CCB; if we get to the CCB allocation phase, we're
guaranteed to have one.
 1.8.2.2 19-Oct-1999  ad Don't cast return value of config_found() to void, as it's not consistant with
the rest of the driver.
 1.8.2.1 19-Oct-1999  thorpej Adapt to scsipi API changes.
 1.17.2.2 17-Jan-2000  he Pull up revisions 1.1-1.17 + patch (requested by ad):
Add driver for DPT SmartCache and SmartRAID III or IV SCSI
adapters.
 1.17.2.1 16-Jan-2000  he file dpt.c was added on branch netbsd-1-4 on 2000-01-17 18:32:50 +0000
 1.21.2.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.22.2.1 13-Mar-2001  he Pull up revision 1.27 (requested by ad):
Make this work on a PowerPC system:
- Load the DMA address a byte at a time
- Use bus_space_read_stream_2() instead of bus_space_read_2() when
reading the byte-stream of configuration data from the card
 1.25.2.6 11-Dec-2002  thorpej Sync with HEAD.
 1.25.2.5 18-Oct-2002  nathanw Catch up to -current.
 1.25.2.4 14-Nov-2001  nathanw Catch up to -current.
 1.25.2.3 24-Aug-2001  nathanw Catch up with -current.
 1.25.2.2 21-Jun-2001  nathanw Catch up to -current.
 1.25.2.1 09-Apr-2001  nathanw Catch up with -current.
 1.29.2.3 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.29.2.2 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.29.2.1 03-Aug-2001  lukem update to -current
 1.31.10.3 09-Aug-2003  tron Pull up revision 1.38 (requested by jmc in ticket #1403):
Fix printf format warnings in previous.
 1.31.10.2 28-Jul-2003  he Pull up revision 1.37 (requested by ad in ticket #1130):
Also save status info in the user command packet.
 1.31.10.1 12-Dec-2002  he Apply patch (requested by ad in ticket #1031):
Implement DPT EATA ioctl interface.
 1.41.2.5 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.41.2.4 21-Sep-2004  skrll Fix the sync with head I botched.
 1.41.2.3 18-Sep-2004  skrll Sync with HEAD.
 1.41.2.2 03-Aug-2004  skrll Sync with HEAD
 1.41.2.1 02-Jul-2003  darrenr Apply the aborted ktrace-lwp changes to a specific branch. This is just for
others to review, I'm concerned that patch fuziness may have resulted in some
errant code being generated but I'll look at that later by comparing the diff
from the base to the branch with the file I attempt to apply to it. This will,
at the very least, put the changes in a better context for others to review
them and attempt to tinker with removing passing of 'struct lwp' through
the kernel.
 1.43.6.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.43.4.1 29-Apr-2005  kent sync with -current
 1.44.4.4 27-Oct-2007  yamt sync with head.
 1.44.4.3 03-Sep-2007  yamt sync with head.
 1.44.4.2 30-Dec-2006  yamt sync with head.
 1.44.4.1 21-Jun-2006  yamt sync with head.
 1.46.12.1 24-May-2006  tron Merge 2006-05-24 NetBSD-current into the "peter-altq" branch.
 1.46.10.1 19-Apr-2006  elad sync with head.
 1.46.8.2 03-Sep-2006  yamt sync with head.
 1.46.8.1 24-May-2006  yamt sync with head.
 1.46.6.2 01-Jun-2006  kardel Sync with head.
 1.46.6.1 22-Apr-2006  simonb Sync with head.
 1.46.4.1 09-Sep-2006  rpaulo sync with head
 1.47.2.1 19-Jun-2006  chap Sync with head.
 1.50.4.2 10-Dec-2006  yamt sync with head.
 1.50.4.1 22-Oct-2006  yamt sync with head
 1.50.2.2 12-Jan-2007  ad Sync with head.
 1.50.2.1 18-Nov-2006  ad Sync with head.
 1.54.2.1 04-Dec-2006  tron Pull up following revision(s) (requested by elad in ticket #247):
sys/dev/ic/dpt.c: revision 1.55
sys/dev/pci/amr.c: revision 1.43
sys/secmodel/bsd44/secmodel_bsd44_securelevel.c: revision 1.19
sys/dev/pci/mly.c: revision 1.33
share/man/man9/kauth.9: revision 1.37
sys/dev/ic/mlx.c: revision 1.49
sys/dev/ic/icp_ioctl.c: revision 1.14
sys/dev/i2o/iop.c: revision 1.62
sys/dev/pci/twe.c: revision 1.82
sys/sys/kauth.h: revision 1.25
sys/dev/i2o/dpti.c: revision 1.31
sys/kern/kern_auth.c: revision 1.33
sys/dev/tc/stic.c: revision 1.37
Change kauth(9) KPI for kauth_authorize_device_passthru() to add another
argument, u_long, serving as a bit-mask of generic requests for the
passthru request.
Discussed on tech-security@ and tech-kern@. Okay tls@.
 1.55.2.1 12-Mar-2007  rmind Sync with HEAD.
 1.56.4.1 11-Jul-2007  mjf Sync with head.
 1.56.2.2 23-Oct-2007  ad Sync with head.
 1.56.2.1 05-Apr-2007  ad Compile fixes.
 1.57.12.1 25-Oct-2007  bouyer Sync with HEAD.
 1.57.8.1 06-Nov-2007  matt sync with HEAD
 1.57.6.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.58.16.3 29-Jun-2008  mjf Sync with HEAD.
 1.58.16.2 02-Jun-2008  mjf Sync with HEAD.
 1.58.16.1 05-Apr-2008  mjf - add "file-system DEVFS" and "pseudo-device devfsctl" to conf/std seeing
as these are always needed.

- convert many, many drivers over to the New Devfs World Order. For a
list of device drivers yet to be converted see,
http://www.netbsd.org/~mjf/devfs-todo.html.

- add a new device_unregister_all(device_t) function to remove all device
names associated with a device_t, which saves us having to construct
device names when the driver is detached.

- add a DEV_AUDIO type for devices.
 1.59.4.3 11-Mar-2010  yamt sync with head
 1.59.4.2 04-May-2009  yamt sync with head.
 1.59.4.1 16-May-2008  yamt sync with head.
 1.59.2.2 17-Jun-2008  yamt sync with head.
 1.59.2.1 18-May-2008  yamt sync with head.
 1.60.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.63.4.1 05-Mar-2011  rmind sync with head
 1.66.6.1 05-Apr-2012  mrg sync to latest -current.
 1.66.2.3 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.66.2.2 30-Oct-2012  yamt sync with head
 1.66.2.1 17-Apr-2012  yamt sync with head
 1.67.2.3 03-Dec-2017  jdolecek update from HEAD
 1.67.2.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.67.2.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.68.2.1 18-May-2014  rmind sync with head
 1.70.2.1 10-Aug-2014  tls Rebase.
 1.72.2.1 09-Jul-2016  skrll Sync with HEAD
 1.74.4.1 10-Jun-2019  christos Sync with HEAD
 1.74.2.1 06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.75.14.1 21-Mar-2021  thorpej Give config_found() the same variadic arguments treatment as
config_search(). This commit only adds the CFARG_EOL sentinel
to the existing config_found() calls. Conversion of config_found_sm_loc()
and config_found_ia() call sites will be in subsequent commits.
 1.76.8.1 04-Aug-2021  thorpej Adapt to CFARGS().
 1.1 20-Nov-2000  bouyer branches: 1.1.2;
file dpt.c.orig was initially added on branch thorpej_scsipi.
 1.1.2.2 20-Nov-2000  bouyer Ops, these shouldn't be there !
 1.1.2.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.19 08-Sep-2008  gmcgarry Replace most gcc-specific __attribute__ uses with BSD-style sys/cdef.h
preprocessor macros.
 1.18 04-Mar-2007  christos branches: 1.18.36; 1.18.40; 1.18.42; 1.18.46;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.17 11-Dec-2005  christos branches: 1.17.26;
merge ktrace-lwp.
 1.16 27-Feb-2005  perry branches: 1.16.4;
nuke trailing whitespace
 1.15 04-Dec-2003  keihan branches: 1.15.8; 1.15.10;
netbsd.org -> NetBSD.org

This was the last commit of this kind to src/sys, which is now totally
"NetBSD.org clean". Thanks for the patiance, and sorry for all the commits.
 1.14 02-Nov-2003  wiz Fix some typos. From Tom Cosgrove via jmc@openbsd.
 1.13 27-Jan-2003  ad branches: 1.13.2;
Also save status info in the user command packet.
 1.12 28-Dec-2002  kristerw Remove a spurious ;.
 1.11 09-Dec-2002  ad Fix LP64 issues.
 1.10 25-Apr-2001  bouyer branches: 1.10.16;
Pull up the thorpej_scsipi branch to main branch.
This is a completely rewritten scsipi_xfer execution engine, and the
associated changes to HBA drivers. Overview of changes & features:
- All xfers are queued in the mid-layer, rather than doing so in an
ad-hoc fashion in individual adapter drivers.
- Adapter/channel resource management in the mid-layer, avoids even trying
to start running an xfer if the adapter/channel doesn't have the resources.
- Better communication between the mid-layer and the adapters.
- Asynchronous event notification mechanism from adapter to mid-layer and
peripherals.
- Better peripheral queue management: freeze/thaw, sorted requeueing during
recovery, etc.
- Clean separation of peripherals, adapters, and adapter channels (no more
scsipi_link).
- Kernel thread for each scsipi_channel makes error recovery much easier
(no more dealing with interrupt context when recovering from an error).
- Mid-layer support for tagged queueing: commands can have the tag type
set explicitly, tag IDs are allocated in the mid-layer (thus eliminating
the need to use buggy tag ID allocation schemes in many adapter drivers).
- support for QUEUE FULL and CHECK CONDITION status in mid-layer; the command
will be requeued, or a REQUEST SENSE will be sent as appropriate.

Just before the merge syssrc has been tagged with thorpej_scsipi_beforemerge
 1.9 13-Jun-2000  ad branches: 1.9.4;
Use my proper name.
 1.8 25-Mar-2000  ad branches: 1.8.2;
The bus_space stuff handles byte order conversions for us.
 1.7 24-Feb-2000  ad - Don't use bitfields.
- Cosmetic changes.
- Shut down all HBAs "simultaneously", not individually.
- Don't bother grokking HA_ST_MORE. It causes problems.
- Other bits and pieces.
 1.6 18-Jan-2000  ad Fix register offset problem. This should make EISA boards work correctly,
and is also needed for the ISA frontend (some time this week).
 1.5 29-Nov-1999  ad branches: 1.5.2;
- Don't use our own private endian conversion cruft (from OpenBSD).
- SmartRAID V is not and will never be an EATA board (from OpenBSD).
- Use dpt_outl() when issuing EATA command packet address to HBA.
- Fix a style nit.
- Fix a typo.
 1.4 19-Oct-1999  ad - Don't get stalled by a bogus HA_ST_MORE condition.
- Don't trust HA_ST_MORE again if the above situation occurs.
- Nuke bitfields in 'struct eata_sp'.
- Don't bother using scatter-gather if DMA map contains only 1 segment.
- Return TRY_AGAIN_LATER and not COMPLETE if an EATA command times out.
- Check SCSI status in dpt_inquire(), not just HBA status.
- Some cosmetic changes and sanity checks.
 1.3 01-Oct-1999  ad branches: 1.3.2; 1.3.4; 1.3.6;
Rename HA_ST_INDEX to HA_ST_MORE (More data available soon).
 1.2 29-Sep-1999  ad - Move initial reset code into dpt_readcfg()
- Bus specific front-end is now responsible for reading EATA configuration
- EATA configuration data is now saved in the softc
- Make synchronous writes work properly
- Don't ignore HBA timeouts in dpt_cmd()
- Prefix eata_cfg's members with `ec_', not `dc_'
 1.1 27-Sep-1999  ad A driver for DPT EATA SCSI adapters. dpt.c contains a brief TODO list.
 1.3.6.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.3.4.1 15-Nov-1999  fvdl Sync with -current
 1.3.2.3 01-Apr-2001  ad - Make this work.
- Restructure a bit.
- KNF, const.
 1.3.2.2 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.3.2.1 20-Oct-1999  thorpej Sync w/ trunk.
 1.5.2.3 18-Jan-2000  he Pull up revision 1.6 (requested by ad):
Fix register offset problem to make EISA boards work correctly.
 1.5.2.2 17-Jan-2000  he Pull up revision 1.1-1.5 + patch (requested by ad):
Add driver for DPT SmartCache and SmartRAID III or IV SCSI
adapters.
 1.5.2.1 29-Nov-1999  he file dptreg.h was added on branch netbsd-1-4 on 2000-01-17 18:34:32 +0000
 1.8.2.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.9.4.3 29-Dec-2002  thorpej Sync with HEAD.
 1.9.4.2 11-Dec-2002  thorpej Sync with HEAD.
 1.9.4.1 21-Jun-2001  nathanw Catch up to -current.
 1.10.16.2 28-Jul-2003  he Pull up revision 1.13 (requested by ad in ticket #1130):
Also save status info in the user command packet.
 1.10.16.1 12-Dec-2002  he Pull up revision 1.11 (requested by ad in ticket #1031):
Implement DPT EATA ioctl interface.
 1.13.2.4 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.13.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.13.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.13.2.1 03-Aug-2004  skrll Sync with HEAD
 1.15.10.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.15.8.1 29-Apr-2005  kent sync with -current
 1.16.4.1 03-Sep-2007  yamt sync with head.
 1.17.26.1 12-Mar-2007  rmind Sync with HEAD.
 1.18.46.1 19-Oct-2008  haad Sync with HEAD.
 1.18.42.1 24-Sep-2008  wrstuden Merge in changes between wrstuden-revivesa-base-2 and
wrstuden-revivesa-base-3.
 1.18.40.1 04-May-2009  yamt sync with head.
 1.18.36.1 28-Sep-2008  mjf Sync with HEAD.
 1.1 20-Nov-2000  bouyer branches: 1.1.2;
file dptreg.h.orig was initially added on branch thorpej_scsipi.
 1.1.2.2 20-Nov-2000  bouyer Ops, these shouldn't be there !
 1.1.2.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.16 27-Oct-2012  chs split device_t/softc for all remaining drivers.
replace "struct device *" with "device_t".
use device_xname(), device_unit(), etc.
 1.15 07-Aug-2011  rmind branches: 1.15.2; 1.15.12;
Replace some wakeup_one(9) uses with mutex(9) or plain wakeup(9).
 1.14 04-Mar-2007  christos Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.13 11-Dec-2005  christos branches: 1.13.26;
merge ktrace-lwp.
 1.12 27-Feb-2005  perry branches: 1.12.4;
nuke trailing whitespace
 1.11 21-Feb-2005  thorpej Part 1 of a cleanup pass over the SCSI subsystem. The aim is to name
everything "scsi_*", since we really are talking about the SCSI command
set, ATAPI transport not withstanding. Improve the names of many structures,
and prepend "SCSI_" onto all SCSI command opcodes. Place items described
by the SCSI Primary Commands document into scsi_spc.h.
 1.10 04-Dec-2003  keihan branches: 1.10.8; 1.10.10;
netbsd.org -> NetBSD.org

This was the last commit of this kind to src/sys, which is now totally
"NetBSD.org clean". Thanks for the patiance, and sorry for all the commits.
 1.9 07-Dec-2002  ad branches: 1.9.6;
Implement the DPT EATA ioctl() interface.
 1.8 25-Apr-2001  bouyer branches: 1.8.16;
Pull up the thorpej_scsipi branch to main branch.
This is a completely rewritten scsipi_xfer execution engine, and the
associated changes to HBA drivers. Overview of changes & features:
- All xfers are queued in the mid-layer, rather than doing so in an
ad-hoc fashion in individual adapter drivers.
- Adapter/channel resource management in the mid-layer, avoids even trying
to start running an xfer if the adapter/channel doesn't have the resources.
- Better communication between the mid-layer and the adapters.
- Asynchronous event notification mechanism from adapter to mid-layer and
peripherals.
- Better peripheral queue management: freeze/thaw, sorted requeueing during
recovery, etc.
- Clean separation of peripherals, adapters, and adapter channels (no more
scsipi_link).
- Kernel thread for each scsipi_channel makes error recovery much easier
(no more dealing with interrupt context when recovering from an error).
- Mid-layer support for tagged queueing: commands can have the tag type
set explicitly, tag IDs are allocated in the mid-layer (thus eliminating
the need to use buggy tag ID allocation schemes in many adapter drivers).
- support for QUEUE FULL and CHECK CONDITION status in mid-layer; the command
will be requeued, or a REQUEST SENSE will be sent as appropriate.

Just before the merge syssrc has been tagged with thorpej_scsipi_beforemerge
 1.7 13-Jun-2000  ad branches: 1.7.4;
Use my proper name.
 1.6 24-Feb-2000  ad branches: 1.6.2;
- Don't use bitfields.
- Cosmetic changes.
- Shut down all HBAs "simultaneously", not individually.
- Don't bother grokking HA_ST_MORE. It causes problems.
- Other bits and pieces.
 1.5 23-Oct-1999  ad branches: 1.5.4;
Prepare a little for the addition of an interface to user-space.
 1.4 04-Oct-1999  thorpej branches: 1.4.2; 1.4.4; 1.4.6;
Avoid silly namespace collision w/ some Alpha signal-related variables.
 1.3 29-Sep-1999  ad - Move initial reset code into dpt_readcfg()
- Bus specific front-end is now responsible for reading EATA configuration
- EATA configuration data is now saved in the softc
- Make synchronous writes work properly
- Don't ignore HBA timeouts in dpt_cmd()
- Prefix eata_cfg's members with `ec_', not `dc_'
 1.2 28-Sep-1999  ad - Add some profiling gunk.
- Add CCB_SYNC for CCBs where data must be written synchronously by the HBA.
 1.1 27-Sep-1999  ad A driver for DPT EATA SCSI adapters. dpt.c contains a brief TODO list.
 1.4.6.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.4.4.1 15-Nov-1999  fvdl Sync with -current
 1.4.2.3 01-Apr-2001  ad - Make this work.
- Restructure a bit.
- KNF, const.
 1.4.2.2 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.4.2.1 19-Oct-1999  thorpej Adapt to scsipi API changes.
 1.5.4.2 17-Jan-2000  he Pull up revisions 1.1-1.5 (requested by ad):
Add driver for DPT SmartCache and SmartRAID III or IV SCSI
adapters.
 1.5.4.1 23-Oct-1999  he file dptvar.h was added on branch netbsd-1-4 on 2000-01-17 18:34:54 +0000
 1.6.2.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.7.4.2 11-Dec-2002  thorpej Sync with HEAD.
 1.7.4.1 21-Jun-2001  nathanw Catch up to -current.
 1.8.16.1 12-Dec-2002  he Pull up revision 1.11 (requested by ad in ticket #1031):
Implement DPT EATA ioctl interface.
 1.9.6.4 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.9.6.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.9.6.2 18-Sep-2004  skrll Sync with HEAD.
 1.9.6.1 03-Aug-2004  skrll Sync with HEAD
 1.10.10.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.10.8.1 29-Apr-2005  kent sync with -current
 1.12.4.1 03-Sep-2007  yamt sync with head.
 1.13.26.1 12-Mar-2007  rmind Sync with HEAD.
 1.15.12.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.15.2.1 30-Oct-2012  yamt sync with head
 1.1 20-Nov-2000  bouyer branches: 1.1.2;
file dptvar.h.orig was initially added on branch thorpej_scsipi.
 1.1.2.2 20-Nov-2000  bouyer Ops, these shouldn't be there !
 1.1.2.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.10 12-Feb-2012  matt Change old-style function defintions to C89 prototypes.

Approved by releng.
 1.9 28-Apr-2008  martin branches: 1.9.34; 1.9.38;
Remove clause 3 and 4 from TNF licenses
 1.8 16-Feb-2006  perry branches: 1.8.64; 1.8.66; 1.8.68;
Change "inline" back to "__inline" in .h files -- C99 is still too
new, and some apps compile things in C89 mode. C89 keywords stay.

As per core@.
 1.7 11-Dec-2005  christos branches: 1.7.2; 1.7.4; 1.7.6;
merge ktrace-lwp.
 1.6 27-Feb-2005  perry branches: 1.6.4;
nuke trailing whitespace
 1.5 04-Feb-2005  perry de-__P
 1.4 24-Mar-2002  bjh21 branches: 1.4.10; 1.4.18; 1.4.20;
Mention the DS2401 Silicon Serial Number.
 1.3 16-Feb-1999  is branches: 1.3.20; 1.3.22;
Fix Copyright dates
 1.2 16-Feb-1999  is Assign my files to The NetBSD Foundation, Inc.
 1.1 06-Jul-1997  is * Command code definitions for the Dallas Semiconductor series of chips which
connect to their 1-wire bus like the DS2404 "EconoRAM Time Chip"
- and -
* Interface function definitions for this kind of chips. Currently only
low-level byte_read and _write, implenented as inline functions.
This functions take a struct ds_handle * (also defined here), which contains
pointers to bit-read/write and reset functions.
Eventually, prototypes for memory-access functions should go here, and the
1-wire bus should be made a BSD auto-configuration bus.
 1.3.22.1 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.3.20.1 01-Apr-2002  nathanw Catch up to -current.
(CVS: It's not just a program. It's an adventure!)
 1.4.20.2 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.4.20.1 12-Feb-2005  yamt sync with head.
 1.4.18.1 29-Apr-2005  kent sync with -current
 1.4.10.2 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.4.10.1 04-Feb-2005  skrll Sync with HEAD.
 1.6.4.1 21-Jun-2006  yamt sync with head.
 1.7.6.1 22-Apr-2006  simonb Sync with head.
 1.7.4.1 09-Sep-2006  rpaulo sync with head
 1.7.2.1 18-Feb-2006  yamt sync with head.
 1.8.68.1 16-May-2008  yamt sync with head.
 1.8.66.1 18-May-2008  yamt sync with head.
 1.8.64.1 02-Jun-2008  mjf Sync with HEAD.
 1.9.38.1 18-Feb-2012  mrg merge to -current.
 1.9.34.1 17-Apr-2012  yamt sync with head
 1.9 21-Oct-2021  andvar fix various typos, mainly in comments, but also in man pages and log messages.
 1.8 11-Dec-2005  christos merge ktrace-lwp.
 1.7 27-Feb-2005  perry nuke trailing whitespace
 1.6 04-Feb-2005  perry de-__P
 1.5 08-Jul-2003  itojun branches: 1.5.8; 1.5.10;
function prototype must not have variable name
 1.4 19-Jan-2003  rafal branches: 1.4.2;
Change DS1286 definitions to start with DS1286_ rather than DS_ so these and
DS1687 definitions are easier to distinguish.
 1.3 07-Jan-2003  rafal Fix tyop
 1.2 25-Feb-2002  kleink Update datasheet URLs.
 1.1 11-May-2001  thorpej branches: 1.1.2; 1.1.4;
Definitions for the Dallas Semiconductor DS1286/DS1386 Real Time Clock.

From Rafal K. Boni.
 1.1.4.1 16-Mar-2002  jdolecek Catch up with -current.
 1.1.2.4 07-Jan-2003  thorpej Sync with HEAD.
 1.1.2.3 28-Feb-2002  nathanw Catch up to -current.
 1.1.2.2 21-Jun-2001  nathanw Catch up to -current.
 1.1.2.1 11-May-2001  nathanw file ds1286reg.h was added on branch nathanw_sa on 2001-06-21 20:02:27 +0000
 1.4.2.5 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.4.2.4 04-Feb-2005  skrll Sync with HEAD.
 1.4.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.4.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.4.2.1 03-Aug-2004  skrll Sync with HEAD
 1.5.10.2 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.5.10.1 12-Feb-2005  yamt sync with head.
 1.5.8.1 29-Apr-2005  kent sync with -current
 1.13 20-May-2022  andvar s/auxillary/auxiliary/ in comments.
 1.12 21-Oct-2021  andvar fix various typos, mainly in comments, but also in man pages and log messages.
 1.11 08-Nov-2018  msaitoh "s/ an an / an /" in comment. No functional change.
 1.10 04-May-2008  martin branches: 1.10.86; 1.10.88;
Move to standard TNF 2 clause license
 1.9 26-Sep-2007  macallan branches: 1.9.18; 1.9.20; 1.9.22;
add a few more register definitions
 1.8 11-Dec-2005  christos branches: 1.8.30; 1.8.44; 1.8.46; 1.8.48;
merge ktrace-lwp.
 1.7 27-Feb-2005  perry branches: 1.7.4;
nuke trailing whitespace
 1.6 04-Feb-2005  perry de-__P
 1.5 01-Feb-2005  he There is no need to define DS1687_NVRAM_START twice.
 1.4 31-Jan-2005  simonb Fix a typo.
 1.3 08-Jul-2003  itojun branches: 1.3.8; 1.3.10;
function prototype must not have variable name
 1.2 18-Jan-2003  rafal branches: 1.2.2;
Add CMU license since this did start out as a copy of mc146818reg.h, which
is under the CMU license.
 1.1 18-Jan-2003  rafal Add register definitions for the Dallas Semiconductor DS1687 and succesors,
a series of Y2k-compliant multiplexed-bus RTC chips. At the lowest levels,
the DS1687 and successors are register-compatible with the MC146818(A) and
DS1287, but also provide Y2k-safe date storage and other extra bits, like a
silicon serial number and larger amounts of NVRAM.
 1.2.2.5 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.2.2.4 04-Feb-2005  skrll Sync with HEAD.
 1.2.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.2.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.2.2.1 03-Aug-2004  skrll Sync with HEAD
 1.3.10.2 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.3.10.1 12-Feb-2005  yamt sync with head.
 1.3.8.1 29-Apr-2005  kent sync with -current
 1.7.4.1 27-Oct-2007  yamt sync with head.
 1.8.48.1 06-Oct-2007  yamt sync with head.
 1.8.46.1 06-Nov-2007  matt sync with HEAD
 1.8.44.1 02-Oct-2007  joerg Sync with HEAD.
 1.8.30.1 09-Oct-2007  ad Sync with head.
 1.9.22.1 16-May-2008  yamt sync with head.
 1.9.20.1 18-May-2008  yamt sync with head.
 1.9.18.1 02-Jun-2008  mjf Sync with HEAD.
 1.10.88.1 10-Jun-2019  christos Sync with HEAD
 1.10.86.1 26-Nov-2018  pgoyette Sync with HEAD, resolve a couple of conflicts
 1.4 11-Apr-1995  mycroft This is deprecated.
 1.3 27-Oct-1994  cgd new RCS ID format.
 1.2 22-May-1993  cgd add rcsids to everything and clean up headers
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.12 09-Feb-2024  skrll Trailing whitespace
 1.11 11-Dec-2023  mlelstv Output is always 16bit, the internal audio data type may differ.
 1.10 25-Mar-2022  tnn dwhdmi: properly initialize connector atomic helper funcs (PR port-evbarm/56766)
 1.9 19-Dec-2021  riastradh Sort includes.
 1.8 19-Dec-2021  riastradh Get drm to build on arm64 again.


Author: Jared McNeill <jmcneill@NetBSD.org>
Committer: Taylor R Campbell <riastradh@NetBSD.org>
 1.7 22-Dec-2019  thorpej Cleanup i2c bus acquire / release, centralizing all of the logic into
iic_acquire_bus() / iic_release_bus(). "acquire" and "release" hooks
no longer need to be provided by back-end controller drivers (only if
they need special handling, e.g. powering on the i2c controller).
This results in the removal of a bunch of rendundant code from each
back-end controller driver.

Assert that we are not in hard interrupt context in iic_acquire_bus(),
iic_exec(), and iic_release_bus().
 1.6 23-Nov-2019  jmcneill Use actual hw mode, not proposed mode.
 1.5 23-Nov-2019  jmcneill Allow bus glue to setup DDC clocks
 1.4 16-Nov-2019  jmcneill Add software volume controls.
 1.3 16-Nov-2019  jmcneill Add I2S audio input support.
 1.2 09-Nov-2019  jmcneill Add support for internal DesignWare HDMI PHYs
 1.1 30-Jan-2019  jmcneill branches: 1.1.4; 1.1.6;
Add driver for Designware HDMI TX controller.
 1.1.6.2 25-Nov-2019  martin Pull up following revision(s) (requested by jmcneill in ticket #470):

sys/arch/arm/sunxi/sunxi_hdmiphy.c: revision 1.4
sys/arch/arm/sunxi/sun50i_a64_ccu.c: revision 1.16
sys/dev/ic/dw_hdmi.c: revision 1.5
sys/arch/arm/sunxi/sunxi_hdmiphy.h: revision 1.2
sys/arch/arm/sunxi/sun50i_a64_ccu.c: revision 1.17
sys/dev/ic/dw_hdmi.c: revision 1.6
sys/arch/arm/sunxi/sun50i_a64_ccu.c: revision 1.18
sys/arch/arm/sunxi/sun50i_a64_ccu.c: revision 1.19
sys/dev/ic/dw_hdmi.h: revision 1.5
sys/arch/arm/sunxi/sunxi_mixer.c: revision 1.8
sys/arch/arm/sunxi/sunxi_mixer.c: revision 1.9
sys/arch/arm/sunxi/sunxi_ccu.h: revision 1.22
sys/arch/arm/sunxi/sunxi_dwhdmi.c: revision 1.5
sys/arch/arm/sunxi/sunxi_dwhdmi.c: revision 1.6
sys/arch/arm/sunxi/sunxi_dwhdmi.c: revision 1.7
sys/arch/arm/sunxi/sunxi_dwhdmi.c: revision 1.8
sys/arch/arm/sunxi/sun50i_a64_ccu.c: revision 1.20
sys/arch/arm/sunxi/sunxi_mixer.c: revision 1.10
sys/arch/arm/dts/sun50i-a64-pinebook.dts: revision 1.17
sys/arch/arm/sunxi/sunxi_platform.c: revision 1.38
sys/dev/fdt/fdt_port.c: revision 1.3
sys/dev/fdt/fdt_port.c: revision 1.4
sys/arch/arm/sunxi/sunxi_ccu_fractional.c: revision 1.5
sys/arch/arm/sunxi/sunxi_lcdc.c: revision 1.7
sys/arch/arm/sunxi/sunxi_ccu_fractional.c: revision 1.6
sys/arch/arm/sunxi/sunxi_hdmiphy.c: revision 1.3

Fix CLK_BUS_HDMI bit

Enable TMDS clock

Store the flags passed to SUNXI_CCU_FRACTIONAL macro.
Previously the macro dropped the flags argument entirely, and did not
initialize the structure with it.

Allow bus glue to setup DDC clocks

Add TCON0 clock

HDMI PHY and TX share the same clocks. Do not enable clocks until both
reset resources have been deasserted. Explicitly set DDC clock dividers.
Honour SUNXI_CCU_FRACTIONAL_SET_ENABLE in fractional mode

Use fdtbus_get_reg to read "reg" property

Need to initialize the PHY before HPD sense and DDC will work

Set pixel clock on mode set

Set TCON1 parent to PLL_VIDEO1(1X)

Do not assume that an fb's pitch is width * 4 bytes.

Use actual hw mode, not proposed mode.

Set pre-divider M to 0 in fractional mode, as noted in user manual. Spotted by jak.

Support non-zero fb start pixels.

Set video PLLs to 297MHz

Do not assume the cursor pitch is the same as the primary fb

Enable HDMI and HDMI audio

Try to avoid changing hardware settings when the "nomodeset" kernel arg
is present.
 1.1.6.1 16-Nov-2019  martin Pull up following revision(s) (requested by jmcneill in ticket #427):

sys/dev/ic/dw_hdmi_phy.c: revision 1.2
sys/dev/ic/dw_hdmi.c: revision 1.4
sys/dev/fdt/ausoc.c: revision 1.5
sys/dev/ic/dw_hdmi.h: revision 1.2
sys/dev/ic/dw_hdmi.h: revision 1.3
sys/dev/ic/dw_hdmi.h: revision 1.4
sys/conf/files: revision 1.1242
sys/dev/fdt/fdtvar.h: revision 1.57
sys/arch/arm/rockchip/rk3399_cru.c: revision 1.11
sys/arch/arm/rockchip/rk3399_cru.c: revision 1.12
sys/arch/arm/rockchip/rk3399_cru.c: revision 1.13
sys/arch/evbarm/conf/GENERIC64: revision 1.110
sys/arch/arm/rockchip/rk_drm.c: revision 1.1
sys/arch/arm/rockchip/rk_drm.c: revision 1.2
sys/arch/evbarm/conf/GENERIC64: revision 1.112
sys/arch/arm/rockchip/rk_dwhdmi.c: revision 1.1
sys/dev/fdt/fdt_clock.c: revision 1.10
sys/arch/evbarm/conf/GENERIC64: revision 1.113
sys/arch/arm/rockchip/rk_dwhdmi.c: revision 1.2
sys/arch/arm/rockchip/rk_drm.h: revision 1.1
sys/arch/arm/rockchip/rk_dwhdmi.c: revision 1.3
sys/arch/arm/rockchip/rk_fb.c: revision 1.1
sys/arch/arm/dts/rk3399-rockpro64.dts: revision 1.9
sys/arch/arm/rockchip/rk_vop.c: revision 1.1
sys/arch/arm/rockchip/rk_vop.c: revision 1.2
sys/arch/arm/rockchip/rk_i2c.c: revision 1.6
sys/arch/arm/rockchip/rk_cru.h: revision 1.6
sys/arch/arm/rockchip/rk_cru.h: revision 1.7
sys/arch/arm/rockchip/rk_cru_composite.c: revision 1.4
sys/arch/arm/rockchip/rk_cru_composite.c: revision 1.5
sys/arch/arm/rockchip/files.rockchip: revision 1.21
sys/arch/arm/rockchip/rk_i2s.c: revision 1.1
sys/arch/arm/rockchip/files.rockchip: revision 1.22
sys/dev/ic/dw_hdmi.c: revision 1.2
sys/dev/ic/dw_hdmi_phy.c: revision 1.1
sys/dev/ic/dw_hdmi.c: revision 1.3

Support reads of more than 32 bytes in a single xfer.

Add support for internal DesignWare HDMI PHYs

Add fdtbus_clock_enable and fdtbus_clock_enable_index shortcuts

Add HDMI and VOP clocks

WIP display driver for Rockchip RK3399

Add (commented out) Rockchip display support

Select the correct MPLL and PHY settings for the requested pixel clock
Force DCLK_VOP0/1 dividers to 1 and select closest match when setting PLL
rates.

Fix typo in phy config table

Fix a few swapped fields

Remove debug output

Enable Rockchip display support

Set sysclk rate at set_format time, so the link set_format callback can read the new sysclk

Add I2S audio input support.
Add software volume controls.
Add support for I2S clocks.
Add driver for Rockchip I2S/PCM controller.
Enable HDMI audio on ROCKPro64
Add rki2s
Add audio support
 1.1.4.3 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.1.4.2 10-Jun-2019  christos Sync with HEAD
 1.1.4.1 30-Jan-2019  christos file dw_hdmi.c was added on branch phil-wifi on 2019-06-10 22:07:10 +0000
 1.8 19-Dec-2021  riastradh Sort includes.
 1.7 19-Dec-2021  riastradh Get drm to build on arm64 again.


Author: Jared McNeill <jmcneill@NetBSD.org>
Committer: Taylor R Campbell <riastradh@NetBSD.org>
 1.6 22-Dec-2019  thorpej Cleanup i2c bus acquire / release, centralizing all of the logic into
iic_acquire_bus() / iic_release_bus(). "acquire" and "release" hooks
no longer need to be provided by back-end controller drivers (only if
they need special handling, e.g. powering on the i2c controller).
This results in the removal of a bunch of rendundant code from each
back-end controller driver.

Assert that we are not in hard interrupt context in iic_acquire_bus(),
iic_exec(), and iic_release_bus().
 1.5 23-Nov-2019  jmcneill Allow bus glue to setup DDC clocks
 1.4 16-Nov-2019  jmcneill Add software volume controls.
 1.3 16-Nov-2019  jmcneill Add I2S audio input support.
 1.2 09-Nov-2019  jmcneill Add support for internal DesignWare HDMI PHYs
 1.1 30-Jan-2019  jmcneill branches: 1.1.4; 1.1.6;
Add driver for Designware HDMI TX controller.
 1.1.6.2 25-Nov-2019  martin Pull up following revision(s) (requested by jmcneill in ticket #470):

sys/arch/arm/sunxi/sunxi_hdmiphy.c: revision 1.4
sys/arch/arm/sunxi/sun50i_a64_ccu.c: revision 1.16
sys/dev/ic/dw_hdmi.c: revision 1.5
sys/arch/arm/sunxi/sunxi_hdmiphy.h: revision 1.2
sys/arch/arm/sunxi/sun50i_a64_ccu.c: revision 1.17
sys/dev/ic/dw_hdmi.c: revision 1.6
sys/arch/arm/sunxi/sun50i_a64_ccu.c: revision 1.18
sys/arch/arm/sunxi/sun50i_a64_ccu.c: revision 1.19
sys/dev/ic/dw_hdmi.h: revision 1.5
sys/arch/arm/sunxi/sunxi_mixer.c: revision 1.8
sys/arch/arm/sunxi/sunxi_mixer.c: revision 1.9
sys/arch/arm/sunxi/sunxi_ccu.h: revision 1.22
sys/arch/arm/sunxi/sunxi_dwhdmi.c: revision 1.5
sys/arch/arm/sunxi/sunxi_dwhdmi.c: revision 1.6
sys/arch/arm/sunxi/sunxi_dwhdmi.c: revision 1.7
sys/arch/arm/sunxi/sunxi_dwhdmi.c: revision 1.8
sys/arch/arm/sunxi/sun50i_a64_ccu.c: revision 1.20
sys/arch/arm/sunxi/sunxi_mixer.c: revision 1.10
sys/arch/arm/dts/sun50i-a64-pinebook.dts: revision 1.17
sys/arch/arm/sunxi/sunxi_platform.c: revision 1.38
sys/dev/fdt/fdt_port.c: revision 1.3
sys/dev/fdt/fdt_port.c: revision 1.4
sys/arch/arm/sunxi/sunxi_ccu_fractional.c: revision 1.5
sys/arch/arm/sunxi/sunxi_lcdc.c: revision 1.7
sys/arch/arm/sunxi/sunxi_ccu_fractional.c: revision 1.6
sys/arch/arm/sunxi/sunxi_hdmiphy.c: revision 1.3

Fix CLK_BUS_HDMI bit

Enable TMDS clock

Store the flags passed to SUNXI_CCU_FRACTIONAL macro.
Previously the macro dropped the flags argument entirely, and did not
initialize the structure with it.

Allow bus glue to setup DDC clocks

Add TCON0 clock

HDMI PHY and TX share the same clocks. Do not enable clocks until both
reset resources have been deasserted. Explicitly set DDC clock dividers.
Honour SUNXI_CCU_FRACTIONAL_SET_ENABLE in fractional mode

Use fdtbus_get_reg to read "reg" property

Need to initialize the PHY before HPD sense and DDC will work

Set pixel clock on mode set

Set TCON1 parent to PLL_VIDEO1(1X)

Do not assume that an fb's pitch is width * 4 bytes.

Use actual hw mode, not proposed mode.

Set pre-divider M to 0 in fractional mode, as noted in user manual. Spotted by jak.

Support non-zero fb start pixels.

Set video PLLs to 297MHz

Do not assume the cursor pitch is the same as the primary fb

Enable HDMI and HDMI audio

Try to avoid changing hardware settings when the "nomodeset" kernel arg
is present.
 1.1.6.1 16-Nov-2019  martin Pull up following revision(s) (requested by jmcneill in ticket #427):

sys/dev/ic/dw_hdmi_phy.c: revision 1.2
sys/dev/ic/dw_hdmi.c: revision 1.4
sys/dev/fdt/ausoc.c: revision 1.5
sys/dev/ic/dw_hdmi.h: revision 1.2
sys/dev/ic/dw_hdmi.h: revision 1.3
sys/dev/ic/dw_hdmi.h: revision 1.4
sys/conf/files: revision 1.1242
sys/dev/fdt/fdtvar.h: revision 1.57
sys/arch/arm/rockchip/rk3399_cru.c: revision 1.11
sys/arch/arm/rockchip/rk3399_cru.c: revision 1.12
sys/arch/arm/rockchip/rk3399_cru.c: revision 1.13
sys/arch/evbarm/conf/GENERIC64: revision 1.110
sys/arch/arm/rockchip/rk_drm.c: revision 1.1
sys/arch/arm/rockchip/rk_drm.c: revision 1.2
sys/arch/evbarm/conf/GENERIC64: revision 1.112
sys/arch/arm/rockchip/rk_dwhdmi.c: revision 1.1
sys/dev/fdt/fdt_clock.c: revision 1.10
sys/arch/evbarm/conf/GENERIC64: revision 1.113
sys/arch/arm/rockchip/rk_dwhdmi.c: revision 1.2
sys/arch/arm/rockchip/rk_drm.h: revision 1.1
sys/arch/arm/rockchip/rk_dwhdmi.c: revision 1.3
sys/arch/arm/rockchip/rk_fb.c: revision 1.1
sys/arch/arm/dts/rk3399-rockpro64.dts: revision 1.9
sys/arch/arm/rockchip/rk_vop.c: revision 1.1
sys/arch/arm/rockchip/rk_vop.c: revision 1.2
sys/arch/arm/rockchip/rk_i2c.c: revision 1.6
sys/arch/arm/rockchip/rk_cru.h: revision 1.6
sys/arch/arm/rockchip/rk_cru.h: revision 1.7
sys/arch/arm/rockchip/rk_cru_composite.c: revision 1.4
sys/arch/arm/rockchip/rk_cru_composite.c: revision 1.5
sys/arch/arm/rockchip/files.rockchip: revision 1.21
sys/arch/arm/rockchip/rk_i2s.c: revision 1.1
sys/arch/arm/rockchip/files.rockchip: revision 1.22
sys/dev/ic/dw_hdmi.c: revision 1.2
sys/dev/ic/dw_hdmi_phy.c: revision 1.1
sys/dev/ic/dw_hdmi.c: revision 1.3

Support reads of more than 32 bytes in a single xfer.

Add support for internal DesignWare HDMI PHYs

Add fdtbus_clock_enable and fdtbus_clock_enable_index shortcuts

Add HDMI and VOP clocks

WIP display driver for Rockchip RK3399

Add (commented out) Rockchip display support

Select the correct MPLL and PHY settings for the requested pixel clock
Force DCLK_VOP0/1 dividers to 1 and select closest match when setting PLL
rates.

Fix typo in phy config table

Fix a few swapped fields

Remove debug output

Enable Rockchip display support

Set sysclk rate at set_format time, so the link set_format callback can read the new sysclk

Add I2S audio input support.
Add software volume controls.
Add support for I2S clocks.
Add driver for Rockchip I2S/PCM controller.
Enable HDMI audio on ROCKPro64
Add rki2s
Add audio support
 1.1.4.3 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.1.4.2 10-Jun-2019  christos Sync with HEAD
 1.1.4.1 30-Jan-2019  christos file dw_hdmi.h was added on branch phil-wifi on 2019-06-10 22:07:10 +0000
 1.3 19-Dec-2021  riastradh Get drm to build on arm64 again.


Author: Jared McNeill <jmcneill@NetBSD.org>
Committer: Taylor R Campbell <riastradh@NetBSD.org>
 1.2 10-Nov-2019  jmcneill branches: 1.2.2; 1.2.10;
Select the correct MPLL and PHY settings for the requested pixel clock
 1.1 09-Nov-2019  jmcneill Add support for internal DesignWare HDMI PHYs
 1.2.10.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.2.10.1 10-Nov-2019  martin file dw_hdmi_phy.c was added on branch phil-wifi on 2020-04-13 08:04:21 +0000
 1.2.2.2 16-Nov-2019  martin Pull up following revision(s) (requested by jmcneill in ticket #427):

sys/dev/ic/dw_hdmi_phy.c: revision 1.2
sys/dev/ic/dw_hdmi.c: revision 1.4
sys/dev/fdt/ausoc.c: revision 1.5
sys/dev/ic/dw_hdmi.h: revision 1.2
sys/dev/ic/dw_hdmi.h: revision 1.3
sys/dev/ic/dw_hdmi.h: revision 1.4
sys/conf/files: revision 1.1242
sys/dev/fdt/fdtvar.h: revision 1.57
sys/arch/arm/rockchip/rk3399_cru.c: revision 1.11
sys/arch/arm/rockchip/rk3399_cru.c: revision 1.12
sys/arch/arm/rockchip/rk3399_cru.c: revision 1.13
sys/arch/evbarm/conf/GENERIC64: revision 1.110
sys/arch/arm/rockchip/rk_drm.c: revision 1.1
sys/arch/arm/rockchip/rk_drm.c: revision 1.2
sys/arch/evbarm/conf/GENERIC64: revision 1.112
sys/arch/arm/rockchip/rk_dwhdmi.c: revision 1.1
sys/dev/fdt/fdt_clock.c: revision 1.10
sys/arch/evbarm/conf/GENERIC64: revision 1.113
sys/arch/arm/rockchip/rk_dwhdmi.c: revision 1.2
sys/arch/arm/rockchip/rk_drm.h: revision 1.1
sys/arch/arm/rockchip/rk_dwhdmi.c: revision 1.3
sys/arch/arm/rockchip/rk_fb.c: revision 1.1
sys/arch/arm/dts/rk3399-rockpro64.dts: revision 1.9
sys/arch/arm/rockchip/rk_vop.c: revision 1.1
sys/arch/arm/rockchip/rk_vop.c: revision 1.2
sys/arch/arm/rockchip/rk_i2c.c: revision 1.6
sys/arch/arm/rockchip/rk_cru.h: revision 1.6
sys/arch/arm/rockchip/rk_cru.h: revision 1.7
sys/arch/arm/rockchip/rk_cru_composite.c: revision 1.4
sys/arch/arm/rockchip/rk_cru_composite.c: revision 1.5
sys/arch/arm/rockchip/files.rockchip: revision 1.21
sys/arch/arm/rockchip/rk_i2s.c: revision 1.1
sys/arch/arm/rockchip/files.rockchip: revision 1.22
sys/dev/ic/dw_hdmi.c: revision 1.2
sys/dev/ic/dw_hdmi_phy.c: revision 1.1
sys/dev/ic/dw_hdmi.c: revision 1.3

Support reads of more than 32 bytes in a single xfer.

Add support for internal DesignWare HDMI PHYs

Add fdtbus_clock_enable and fdtbus_clock_enable_index shortcuts

Add HDMI and VOP clocks

WIP display driver for Rockchip RK3399

Add (commented out) Rockchip display support

Select the correct MPLL and PHY settings for the requested pixel clock
Force DCLK_VOP0/1 dividers to 1 and select closest match when setting PLL
rates.

Fix typo in phy config table

Fix a few swapped fields

Remove debug output

Enable Rockchip display support

Set sysclk rate at set_format time, so the link set_format callback can read the new sysclk

Add I2S audio input support.
Add software volume controls.
Add support for I2S clocks.
Add driver for Rockchip I2S/PCM controller.
Enable HDMI audio on ROCKPro64
Add rki2s
Add audio support
 1.2.2.1 10-Nov-2019  martin file dw_hdmi_phy.c was added on branch netbsd-9 on 2019-11-16 16:48:25 +0000
 1.43 15-Oct-2025  thorpej Use device_getprop_{bool,uint}().
 1.42 04-Oct-2025  thorpej Add a shared function to query the common properties used for configuring
an Ethernet address.
 1.41 06-Oct-2024  skrll Don't check obsoleted IFF_ALLMULTI in eqos_ifflags_cb
 1.40 04-Oct-2024  skrll Fix a problem noted by Taylor...

touching if_flags is forbidden in this context (no IFNET_LOCK guaranteed)
sc_promisc should be cached when if_flags changes, not when
SIOCADDMULTI/SIOCDELMULTI runs

by caching if_flags in sc_if_flags via a ifflags_cb.
 1.39 14-Sep-2024  skrll Update sc_promisc in eqos_ioctl before calling eqos_setup_rxfilter so the
new value is used.
 1.38 26-Aug-2024  bsiegert dwc_eqos: grammar fix

If the MAC address has the multicast bit set, the driver outputs
"Clearing the multicast bit" instead of "Clear the multicast bit".
 1.37 05-Jul-2024  rin sys: Drop redundant NULL check before m_freem(9)

m_freem(9) safely has accepted NULL argument at least since 4.2BSD:
https://www.tuhs.org/cgi-bin/utree.pl?file=4.2BSD/usr/src/sys/sys/uipc_mbuf.c

Compile-tested on amd64/ALL.

Suggested by knakahara@
 1.36 10-Feb-2024  skrll branches: 1.36.2;
Fix an error message by removing an extra 'x'
 1.35 24-Dec-2023  skrll eqos(4): MP improvements

Remove the non-MP-safe scaffolding and pass MP safe flags for callout
and interrupt handlers.

Where we had #ifndef EQOS_MPSAFE splnet(), we also had EQOS_LOCK,
which implies splnet, so just remove the conditional splnet.
 1.34 13-Nov-2023  msaitoh eqos(4): Set bit 31 when writing MAC_ADDRESS0_HIGH register.
 1.33 02-Nov-2023  riastradh eqos(4): Fix multicast filter updates.

1. Don't touch the obsolete IFF_ALLMULTI.
2. Set ETHER_F_ALLMULTI if we're accepting all multicast addresses.
3. If any multicast entry range is not a single address, accept all
multicast addresses.
 1.32 02-Nov-2023  riastradh eqos(4): Fix locking around multicast filter updates.

- Can't touch if_flags without IFNET_LOCK.
- Can't take IFNET_LOCK in SIOCADDMULTI/SIOCDELMULTI path.

Instead, cache IFF_PROMISC and IFF_ALLMULTI on if_init under a lock we
can take in this path.

XXX Is IFF_ALLMULTI relevant any more? Hasn't it been moved to
ethercom flags?

XXX Should not take sc_lock around if_init/stop -- IFNET_LOCK is
enough. Should narrow scope of sc_lock to be just tick/mii/multi
stuff.
 1.31 02-Nov-2023  riastradh eqos(4): Don't touch if_flags in tx path.

Can't touch this without IFNET_LOCK.
 1.30 02-Nov-2023  riastradh eqos(4): Wait for callout to halt and make sure it stays halted.
 1.29 02-Nov-2023  msaitoh eqos(4): Fix typo in comment.
 1.28 29-Oct-2023  msaitoh eqos(4): Set flow control correctly.
 1.27 26-Oct-2023  msaitoh eqos(4): Set TX/RX DMA burst length to improve performance.
 1.26 26-Oct-2023  msaitoh eqos(4): Use EQOS_TXLOCK() more to be stable.

Fix a bug that sc_tx.{cur,next,queued} become inconsitent.
Use txlock when accessing TX data.
 1.25 23-Oct-2023  msaitoh eqos(4): Add sysctls for debugging.
 1.24 23-Oct-2023  msaitoh eqos(4): Add and modify some DPRINTF()s.
 1.23 23-Oct-2023  msaitoh eqos(4): KNF. No functional change.
 1.22 21-Oct-2023  skrll Trailing whitespace
 1.21 20-Oct-2023  msaitoh eqos(4): Fix compile error for arch that sizeof(bus_size_t) == 4 (i386).
 1.20 20-Oct-2023  msaitoh eqos(4): Accept if snpsver == 0x52. Tested with Intel Elkhart Lake.

TODO:
Multiqueue support.
Add watchdog timer.
Add detach function.
 1.19 20-Oct-2023  msaitoh eqos(4): Add missing clock range.
 1.18 20-Oct-2023  msaitoh eqos(4): Fix a bug that the MAC address is swapped.

Don't swap the MAC address in eqos_get_eaddr(). Other OSes except FreeBSD
(which was based on NetBSD's) don't swap it. With this change, my own
OnLogic Helix 330's MAC address becomes correct. The OUI is 84:8b:cd:4d.
It's owned by Logic Supply and they were acquired by OnLogic.
On Quartz64 with UEIF, the MAC address is wrongly set and the multicast
bit might be set. To do workaround, clear the bit if it's set.
 1.17 03-Jun-2023  andvar fix various typos in comments and messages.
 1.16 18-Sep-2022  thorpej branches: 1.16.4;
Eliminate use of IFF_OACTIVE.
 1.15 28-Aug-2022  skrll Sprinkle const
 1.14 25-Aug-2022  ryo add missing bus_dmamap_unload().
I deleted it in the previous commit, oops.
 1.13 24-Aug-2022  ryo jumboframe support for eqos(4)

Tested up to mtu=9000. Hardware may allow up to mtu=16364
(frame length=16382), but this has not been tested.

- Separate calls to eqos_setup_rxdesc() from eqos_setup_rxbuf().
if m_getcl() fails, discard the packets received at that time
and reuse for the next buffer.
- Restore m_adj(m, ETHER_ALIGN) with limited conditions.
Only if MCLBYTES is greater than 2050, so it is not normally aligned.
 1.12 24-Aug-2022  ryo rename EQOS_TDES3_* macro to EQOS_TDES3_{TX,RX}_*, and add more defs.

Avoid confusion because some definitions are different bits with the same name for TX and RX.
no functional changes.
 1.11 24-Aug-2022  ryo Giving up adjusting ETHER_ALIGN.

Even if the jumbo frame setting is off, eqos will DMA transfer frames of
2048 bytes or more in increments of 2048 bytes if they are received.
If the start position of the mbuf data is shifted by ETHER_ALIGN bytes
in m_adj(), up to 2048 bytes of data will be written from the +ETHER_ALIGN
position, causing overflow of the mbuf cluster.
 1.10 23-Aug-2022  ryo Fix eqos(4) to work on RK3588 as well.

- Several registers needed to be initialized
- Add some register definitions
 1.9 06-Aug-2022  martin PR 56948: fix multicast hash filter setup
 1.8 21-Jul-2022  martin Add some driver debugging infrastructure
 1.7 20-Jul-2022  martin When we init the hardware's rx/tx ring configuration we need to
adjust our internal state, as this implicitly resets the current
descriptor pointer.
Previously "ifconfig eqos0 down; ifconfig eqos0 up" made the interface
non-functional.
 1.6 16-Apr-2022  jmcneill eqos: Freeze counters to prevent unhandled interrupts
 1.5 13-Feb-2022  riastradh eqos(4): Nix trailing whitespace. No functional change.
 1.4 13-Feb-2022  riastradh eqos(4): membar_* is not appropriate here; use bus_dmamap_sync.
 1.3 09-Jan-2022  mrg eqos: handle the GMAC_MTL_INTERRUPT_STATUS register having something

drain a couple of registers that want either a read or a write-1-to-
clear bit, and keep track of how many happen via evcnt.

i had this trigger one time, but not since adding instrumentation to
see exactly it was saying (the GMAC_MTL_INTERRUPT_STATUS_Q0IS bit was
set, and it requires some handling now implemented.)

ok jmcneill
 1.2 08-Jan-2022  mrg eqos: interrupt evcnt and minor fix

there's basic interrupt evcnt, which is the parent for the rx and
tx interrupts, and 3 status interrupts, one of which has 7 more
subtypes (watchdog timeout, carrier missing/lost, etc.) as these
cases are evcnt counted now, make some debugging default off.

avoid removing bits from dma_status when rx/tx is handled, so that
later check of dma_status for non-zero does not trip. the two bits
in dma_status removed are never checked again besides the test that
may have failed (but probably doesn't as at least one other bit in
two other variables will be set.)

ok jmcneill
 1.1 03-Jan-2022  jmcneill Add driver for DesignWare Ethernet Quality-of-Service controller.
 1.16.4.2 03-Nov-2023  martin Pull up following revision(s) (requested by riastradh in ticket #453):

sys/dev/ic/dwc_eqos_var.h: revision 1.7
sys/dev/ic/dwc_eqos_var.h: revision 1.8
sys/dev/ic/dwc_eqos_var.h: revision 1.9
sys/dev/ic/dwc_eqos.c: revision 1.30
sys/dev/ic/dwc_eqos.c: revision 1.31
sys/dev/ic/dwc_eqos.c: revision 1.32
sys/dev/ic/dwc_eqos.c: revision 1.33

eqos(4): Wait for callout to halt and make sure it stays halted.

eqos(4): Don't touch if_flags in tx path.

Can't touch this without IFNET_LOCK.

eqos(4): Fix locking around multicast filter updates.
- Can't touch if_flags without IFNET_LOCK.
- Can't take IFNET_LOCK in SIOCADDMULTI/SIOCDELMULTI path.

Instead, cache IFF_PROMISC and IFF_ALLMULTI on if_init under a lock we
can take in this path.

XXX Is IFF_ALLMULTI relevant any more? Hasn't it been moved to
ethercom flags?

XXX Should not take sc_lock around if_init/stop -- IFNET_LOCK is
enough. Should narrow scope of sc_lock to be just tick/mii/multi
stuff.

eqos(4): Fix multicast filter updates.

1. Don't touch the obsolete IFF_ALLMULTI.
2. Set ETHER_F_ALLMULTI if we're accepting all multicast addresses.
3. If any multicast entry range is not a single address, accept all
multicast addresses.
 1.16.4.1 03-Nov-2023  martin Pull up following revision(s) (requested by msaitoh in ticket #446):

sys/dev/pci/if_eqos_pci.c: revision 1.3
sys/arch/i386/conf/GENERIC: revision 1.1251
sys/arch/i386/conf/GENERIC: revision 1.1252
sys/arch/amd64/conf/GENERIC: revision 1.607
sys/arch/amd64/conf/GENERIC: revision 1.608
sys/dev/ic/dwc_eqos.c: revision 1.20
sys/dev/ic/dwc_eqos.c: revision 1.21
share/man/man4/eqos.4: revision 1.2
sys/dev/ic/dwc_eqos.c: revision 1.22
sys/dev/ic/dwc_eqos_reg.h: revision 1.7
sys/dev/ic/dwc_eqos.c: revision 1.23
sys/dev/ic/dwc_eqos_reg.h: revision 1.8
sys/dev/ic/dwc_eqos.c: revision 1.24
sys/dev/ic/dwc_eqos.c: revision 1.25
sys/dev/ic/dwc_eqos.c: revision 1.26
sys/dev/ic/dwc_eqos.c: revision 1.27
sys/dev/ic/dwc_eqos_var.h: revision 1.5
sys/dev/ic/dwc_eqos.c: revision 1.28
sys/dev/ic/dwc_eqos_var.h: revision 1.6
sys/dev/ic/dwc_eqos.c: revision 1.29
sys/dev/ic/dwc_eqos.c: revision 1.18
sys/dev/ic/dwc_eqos.c: revision 1.19
sys/dev/pci/files.pci: revision 1.448
sys/dev/pci/if_eqos_pci.c: revision 1.1
sys/dev/pci/if_eqos_pci.c: revision 1.2

eqos(4): Fix definition of GMAC_MAC_HW_FEATURE1_RXFIFOSIZE.

eqos(4): Fix a bug that the MAC address is swapped.
Don't swap the MAC address in eqos_get_eaddr(). Other OSes except FreeBSD
(which was based on NetBSD's) don't swap it. With this change, my own
OnLogic Helix 330's MAC address becomes correct. The OUI is 84:8b:cd:4d.
It's owned by Logic Supply and they were acquired by OnLogic.

On Quartz64 with UEFI, the MAC address is wrongly set and the multicast
bit might be set. To do workaround, clear the bit if it's set.

eqos(4): Add missing clock range.

eqos(4): Accept if snpsver == 0x52. Tested with Intel Elkhart Lake.

TODO:
Multiqueue support.
Add watchdog timer.
Add detach function.

eqos(4): Add initial support for Intel Elkhart Lake internal Ethernet devices.
- Only tested on PSE SGMII 1G Ethernet MAC with MaxLinear GPY115.
- I don't know why dmat64 doesn't work. eqos_attach() have a special
code if EQOS_HW_FEATURE_ADDR64_32BIT(sc) is true, but it seems it doesn't
work.
- TODO:
Multiqueue support.
Detach support.

eqos(4): Fix compile error for arch that sizeof(bus_size_t) == 4 (i386).
Trailing whitespace

eqos(4): Disable eqos(4) by default because it's not stable on x86.

eqos(4): KNF. No functional change.

eqos(4): Add and modify some DPRINTF()s.

eqos(4): Add sysctls for debugging.

eqos(4): Use EQOS_TXLOCK() more to be stable.
Fix a bug that sc_tx.{cur,next,queued} become inconsitent.
Use txlock when accessing TX data.

eqos(4): Set TX/RX DMA burst length to improve performance.

eqos(4): Set flow control correctly.

eqos_pci: Limit to 32bit DMA only for PSE devices.

eqos(4): Fix typo in comment.
 1.36.2.1 02-Aug-2025  perseant Sync with HEAD
 1.10 13-Nov-2023  msaitoh eqos(4): Extend bitwidth of SYSBUS_MODE_{RD,WR}_OSR_LMT to 4bits.
 1.9 13-Nov-2023  msaitoh eqos(4): Set bit 31 when writing MAC_ADDRESS0_HIGH register.
 1.8 26-Oct-2023  msaitoh eqos(4): Set TX/RX DMA burst length to improve performance.
 1.7 17-Oct-2023  msaitoh eqos(4): Fix definition of GMAC_MAC_HW_FEATURE1_RXFIFOSIZE.
 1.6 24-Aug-2022  ryo branches: 1.6.4;
rename EQOS_TDES3_* macro to EQOS_TDES3_{TX,RX}_*, and add more defs.

Avoid confusion because some definitions are different bits with the same name for TX and RX.
no functional changes.
 1.5 23-Aug-2022  ryo Fix eqos(4) to work on RK3588 as well.

- Several registers needed to be initialized
- Add some register definitions
 1.4 17-Mar-2022  mrg add some register bits for interrupt control/error status.
(not yet used.)
 1.3 09-Jan-2022  mrg eqos: handle the GMAC_MTL_INTERRUPT_STATUS register having something

drain a couple of registers that want either a read or a write-1-to-
clear bit, and keep track of how many happen via evcnt.

i had this trigger one time, but not since adding instrumentation to
see exactly it was saying (the GMAC_MTL_INTERRUPT_STATUS_Q0IS bit was
set, and it requires some handling now implemented.)

ok jmcneill
 1.2 08-Jan-2022  mrg eqos: interrupt evcnt and minor fix

there's basic interrupt evcnt, which is the parent for the rx and
tx interrupts, and 3 status interrupts, one of which has 7 more
subtypes (watchdog timeout, carrier missing/lost, etc.) as these
cases are evcnt counted now, make some debugging default off.

avoid removing bits from dma_status when rx/tx is handled, so that
later check of dma_status for non-zero does not trip. the two bits
in dma_status removed are never checked again besides the test that
may have failed (but probably doesn't as at least one other bit in
two other variables will be set.)

ok jmcneill
 1.1 03-Jan-2022  jmcneill Add driver for DesignWare Ethernet Quality-of-Service controller.
 1.6.4.1 03-Nov-2023  martin Pull up following revision(s) (requested by msaitoh in ticket #446):

sys/dev/pci/if_eqos_pci.c: revision 1.3
sys/arch/i386/conf/GENERIC: revision 1.1251
sys/arch/i386/conf/GENERIC: revision 1.1252
sys/arch/amd64/conf/GENERIC: revision 1.607
sys/arch/amd64/conf/GENERIC: revision 1.608
sys/dev/ic/dwc_eqos.c: revision 1.20
sys/dev/ic/dwc_eqos.c: revision 1.21
share/man/man4/eqos.4: revision 1.2
sys/dev/ic/dwc_eqos.c: revision 1.22
sys/dev/ic/dwc_eqos_reg.h: revision 1.7
sys/dev/ic/dwc_eqos.c: revision 1.23
sys/dev/ic/dwc_eqos_reg.h: revision 1.8
sys/dev/ic/dwc_eqos.c: revision 1.24
sys/dev/ic/dwc_eqos.c: revision 1.25
sys/dev/ic/dwc_eqos.c: revision 1.26
sys/dev/ic/dwc_eqos.c: revision 1.27
sys/dev/ic/dwc_eqos_var.h: revision 1.5
sys/dev/ic/dwc_eqos.c: revision 1.28
sys/dev/ic/dwc_eqos_var.h: revision 1.6
sys/dev/ic/dwc_eqos.c: revision 1.29
sys/dev/ic/dwc_eqos.c: revision 1.18
sys/dev/ic/dwc_eqos.c: revision 1.19
sys/dev/pci/files.pci: revision 1.448
sys/dev/pci/if_eqos_pci.c: revision 1.1
sys/dev/pci/if_eqos_pci.c: revision 1.2

eqos(4): Fix definition of GMAC_MAC_HW_FEATURE1_RXFIFOSIZE.

eqos(4): Fix a bug that the MAC address is swapped.
Don't swap the MAC address in eqos_get_eaddr(). Other OSes except FreeBSD
(which was based on NetBSD's) don't swap it. With this change, my own
OnLogic Helix 330's MAC address becomes correct. The OUI is 84:8b:cd:4d.
It's owned by Logic Supply and they were acquired by OnLogic.

On Quartz64 with UEFI, the MAC address is wrongly set and the multicast
bit might be set. To do workaround, clear the bit if it's set.

eqos(4): Add missing clock range.

eqos(4): Accept if snpsver == 0x52. Tested with Intel Elkhart Lake.

TODO:
Multiqueue support.
Add watchdog timer.
Add detach function.

eqos(4): Add initial support for Intel Elkhart Lake internal Ethernet devices.
- Only tested on PSE SGMII 1G Ethernet MAC with MaxLinear GPY115.
- I don't know why dmat64 doesn't work. eqos_attach() have a special
code if EQOS_HW_FEATURE_ADDR64_32BIT(sc) is true, but it seems it doesn't
work.
- TODO:
Multiqueue support.
Detach support.

eqos(4): Fix compile error for arch that sizeof(bus_size_t) == 4 (i386).
Trailing whitespace

eqos(4): Disable eqos(4) by default because it's not stable on x86.

eqos(4): KNF. No functional change.

eqos(4): Add and modify some DPRINTF()s.

eqos(4): Add sysctls for debugging.

eqos(4): Use EQOS_TXLOCK() more to be stable.
Fix a bug that sc_tx.{cur,next,queued} become inconsitent.
Use txlock when accessing TX data.

eqos(4): Set TX/RX DMA burst length to improve performance.

eqos(4): Set flow control correctly.

eqos_pci: Limit to 32bit DMA only for PSE devices.

eqos(4): Fix typo in comment.
 1.11 04-Oct-2024  skrll Fix a problem noted by Taylor...

touching if_flags is forbidden in this context (no IFNET_LOCK guaranteed)
sc_promisc should be cached when if_flags changes, not when
SIOCADDMULTI/SIOCDELMULTI runs

by caching if_flags in sc_if_flags via a ifflags_cb.
 1.10 15-Sep-2024  skrll Remove unused struct eqos_softc member
 1.9 02-Nov-2023  riastradh branches: 1.9.6;
eqos(4): Fix locking around multicast filter updates.

- Can't touch if_flags without IFNET_LOCK.
- Can't take IFNET_LOCK in SIOCADDMULTI/SIOCDELMULTI path.

Instead, cache IFF_PROMISC and IFF_ALLMULTI on if_init under a lock we
can take in this path.

XXX Is IFF_ALLMULTI relevant any more? Hasn't it been moved to
ethercom flags?

XXX Should not take sc_lock around if_init/stop -- IFNET_LOCK is
enough. Should narrow scope of sc_lock to be just tick/mii/multi
stuff.
 1.8 02-Nov-2023  riastradh eqos(4): Don't touch if_flags in tx path.

Can't touch this without IFNET_LOCK.
 1.7 02-Nov-2023  riastradh eqos(4): Wait for callout to halt and make sure it stays halted.
 1.6 26-Oct-2023  msaitoh eqos(4): Set TX/RX DMA burst length to improve performance.
 1.5 23-Oct-2023  msaitoh eqos(4): Add sysctls for debugging.
 1.4 24-Aug-2022  ryo branches: 1.4.4;
jumboframe support for eqos(4)

Tested up to mtu=9000. Hardware may allow up to mtu=16364
(frame length=16382), but this has not been tested.

- Separate calls to eqos_setup_rxdesc() from eqos_setup_rxbuf().
if m_getcl() fails, discard the packets received at that time
and reuse for the next buffer.
- Restore m_adj(m, ETHER_ALIGN) with limited conditions.
Only if MCLBYTES is greater than 2050, so it is not normally aligned.
 1.3 09-Jan-2022  mrg eqos: handle the GMAC_MTL_INTERRUPT_STATUS register having something

drain a couple of registers that want either a read or a write-1-to-
clear bit, and keep track of how many happen via evcnt.

i had this trigger one time, but not since adding instrumentation to
see exactly it was saying (the GMAC_MTL_INTERRUPT_STATUS_Q0IS bit was
set, and it requires some handling now implemented.)

ok jmcneill
 1.2 08-Jan-2022  mrg eqos: interrupt evcnt and minor fix

there's basic interrupt evcnt, which is the parent for the rx and
tx interrupts, and 3 status interrupts, one of which has 7 more
subtypes (watchdog timeout, carrier missing/lost, etc.) as these
cases are evcnt counted now, make some debugging default off.

avoid removing bits from dma_status when rx/tx is handled, so that
later check of dma_status for non-zero does not trip. the two bits
in dma_status removed are never checked again besides the test that
may have failed (but probably doesn't as at least one other bit in
two other variables will be set.)

ok jmcneill
 1.1 03-Jan-2022  jmcneill Add driver for DesignWare Ethernet Quality-of-Service controller.
 1.4.4.2 03-Nov-2023  martin Pull up following revision(s) (requested by riastradh in ticket #453):

sys/dev/ic/dwc_eqos_var.h: revision 1.7
sys/dev/ic/dwc_eqos_var.h: revision 1.8
sys/dev/ic/dwc_eqos_var.h: revision 1.9
sys/dev/ic/dwc_eqos.c: revision 1.30
sys/dev/ic/dwc_eqos.c: revision 1.31
sys/dev/ic/dwc_eqos.c: revision 1.32
sys/dev/ic/dwc_eqos.c: revision 1.33

eqos(4): Wait for callout to halt and make sure it stays halted.

eqos(4): Don't touch if_flags in tx path.

Can't touch this without IFNET_LOCK.

eqos(4): Fix locking around multicast filter updates.
- Can't touch if_flags without IFNET_LOCK.
- Can't take IFNET_LOCK in SIOCADDMULTI/SIOCDELMULTI path.

Instead, cache IFF_PROMISC and IFF_ALLMULTI on if_init under a lock we
can take in this path.

XXX Is IFF_ALLMULTI relevant any more? Hasn't it been moved to
ethercom flags?

XXX Should not take sc_lock around if_init/stop -- IFNET_LOCK is
enough. Should narrow scope of sc_lock to be just tick/mii/multi
stuff.

eqos(4): Fix multicast filter updates.

1. Don't touch the obsolete IFF_ALLMULTI.
2. Set ETHER_F_ALLMULTI if we're accepting all multicast addresses.
3. If any multicast entry range is not a single address, accept all
multicast addresses.
 1.4.4.1 03-Nov-2023  martin Pull up following revision(s) (requested by msaitoh in ticket #446):

sys/dev/pci/if_eqos_pci.c: revision 1.3
sys/arch/i386/conf/GENERIC: revision 1.1251
sys/arch/i386/conf/GENERIC: revision 1.1252
sys/arch/amd64/conf/GENERIC: revision 1.607
sys/arch/amd64/conf/GENERIC: revision 1.608
sys/dev/ic/dwc_eqos.c: revision 1.20
sys/dev/ic/dwc_eqos.c: revision 1.21
share/man/man4/eqos.4: revision 1.2
sys/dev/ic/dwc_eqos.c: revision 1.22
sys/dev/ic/dwc_eqos_reg.h: revision 1.7
sys/dev/ic/dwc_eqos.c: revision 1.23
sys/dev/ic/dwc_eqos_reg.h: revision 1.8
sys/dev/ic/dwc_eqos.c: revision 1.24
sys/dev/ic/dwc_eqos.c: revision 1.25
sys/dev/ic/dwc_eqos.c: revision 1.26
sys/dev/ic/dwc_eqos.c: revision 1.27
sys/dev/ic/dwc_eqos_var.h: revision 1.5
sys/dev/ic/dwc_eqos.c: revision 1.28
sys/dev/ic/dwc_eqos_var.h: revision 1.6
sys/dev/ic/dwc_eqos.c: revision 1.29
sys/dev/ic/dwc_eqos.c: revision 1.18
sys/dev/ic/dwc_eqos.c: revision 1.19
sys/dev/pci/files.pci: revision 1.448
sys/dev/pci/if_eqos_pci.c: revision 1.1
sys/dev/pci/if_eqos_pci.c: revision 1.2

eqos(4): Fix definition of GMAC_MAC_HW_FEATURE1_RXFIFOSIZE.

eqos(4): Fix a bug that the MAC address is swapped.
Don't swap the MAC address in eqos_get_eaddr(). Other OSes except FreeBSD
(which was based on NetBSD's) don't swap it. With this change, my own
OnLogic Helix 330's MAC address becomes correct. The OUI is 84:8b:cd:4d.
It's owned by Logic Supply and they were acquired by OnLogic.

On Quartz64 with UEFI, the MAC address is wrongly set and the multicast
bit might be set. To do workaround, clear the bit if it's set.

eqos(4): Add missing clock range.

eqos(4): Accept if snpsver == 0x52. Tested with Intel Elkhart Lake.

TODO:
Multiqueue support.
Add watchdog timer.
Add detach function.

eqos(4): Add initial support for Intel Elkhart Lake internal Ethernet devices.
- Only tested on PSE SGMII 1G Ethernet MAC with MaxLinear GPY115.
- I don't know why dmat64 doesn't work. eqos_attach() have a special
code if EQOS_HW_FEATURE_ADDR64_32BIT(sc) is true, but it seems it doesn't
work.
- TODO:
Multiqueue support.
Detach support.

eqos(4): Fix compile error for arch that sizeof(bus_size_t) == 4 (i386).
Trailing whitespace

eqos(4): Disable eqos(4) by default because it's not stable on x86.

eqos(4): KNF. No functional change.

eqos(4): Add and modify some DPRINTF()s.

eqos(4): Add sysctls for debugging.

eqos(4): Use EQOS_TXLOCK() more to be stable.
Fix a bug that sc_tx.{cur,next,queued} become inconsitent.
Use txlock when accessing TX data.

eqos(4): Set TX/RX DMA burst length to improve performance.

eqos(4): Set flow control correctly.

eqos_pci: Limit to 32bit DMA only for PSE devices.

eqos(4): Fix typo in comment.
 1.9.6.1 02-Aug-2025  perseant Sync with HEAD
 1.97 04-Oct-2025  thorpej Add a shared function to query the common properties used for configuring
an Ethernet address.
 1.96 16-Feb-2025  jakllsch dwc_gmac: ETHER_ALIGN receive descriptors
 1.95 07-Sep-2024  andvar spelling and grammar fixes, mainly in comments.
 1.94 11-Aug-2024  riastradh awge(4): Narrow scope of `core' lock and rename to mcast lock.

Sprinkle locking notes.

Proposed at:

https://mail-index.netbsd.org/source-changes-d/2024/08/10/msg014251.html

Comment-only changes from the updated patch at:

https://mail-index.netbsd.org/source-changes-d/2024/08/10/msg014252.html
 1.93 10-Aug-2024  skrll awge(4): MP improvements

Remove the non-MP-safe scaffolding and make the locking less
coarse.
 1.92 10-Aug-2024  skrll Sprinkle some const
 1.91 27-Jul-2024  skrll Handle GMAC_MAC_Version's that include USERVER.
 1.90 14-Jul-2024  skrll Improve and add new debug output
 1.89 14-Jul-2024  skrll Fix some bus_dmamap_sync calls.
- ensure new descriptors are written before handing ownership of the
first in the list to the device.
- ensure descriptors are sync'ed before dumping them in
dwc_gmac_dump_[rt]x_desc
- don't sync the TX packet buffer twice (and not after we've passed
ownership of its TX descriptor)

Change some variable names to better reflect what they are while I'm here.
 1.88 05-Jul-2024  rin sys: Drop redundant NULL check before m_freem(9)

m_freem(9) safely has accepted NULL argument at least since 4.2BSD:
https://www.tuhs.org/cgi-bin/utree.pl?file=4.2BSD/usr/src/sys/sys/uipc_mbuf.c

Compile-tested on amd64/ALL.

Suggested by knakahara@
 1.87 16-Jun-2024  skrll branches: 1.87.2;
Misc whitespace
 1.86 14-Mar-2024  jakllsch Use ether_crc32_be() instead of having a local bitrev32() function to
munge ether_crc32_le() output when programming multicast filter.
 1.85 03-Mar-2024  skrll Reorder the bus_dmamap_sync sync operations

BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD to
BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE

for consistency.
 1.84 03-Mar-2024  skrll More KNF (whitespace around binary operators)
 1.83 27-Feb-2024  skrll Enforce the device 32 bit DMA limitation via bus_dmatag_subregion if bus
can address more than 4GB.
 1.82 27-Feb-2024  skrll KNF - spaces around binary operators.
 1.81 11-Feb-2024  skrll Fix spello in debug output
 1.80 20-Dec-2023  skrll Remove unnecssary #include
 1.79 01-Aug-2023  mrg fix simple mis-matched function prototype and definitions.

most of these are like, eg

void foo(int[2]);

with either of these

void foo(int*) { ... }
void foo(int[]) { ... }

in some cases (such as stat or utimes* calls found in our header files),
we now match standard definition from opengroup.

found by GCC 12.
 1.78 18-Sep-2022  thorpej Eliminate use of IFF_OACTIVE.
 1.77 09-Aug-2022  sekiya Turn off AWIN_GMAC_MAC_CONF_ACS, so that all received packets retain FCS
bytes.

ether_input() can now trust M_HASFCS to accurately represent the packet
contents.

Discussed on tech-net@
 1.76 05-Aug-2022  sekiya Do not unilaterally set M_HASFCS; this breaks protocols that lack CRC bytes
(such as AppleTalk).

Instead, remove/preserve the final four bytes in the packet ourselves on a per-
protocol basis, as we do in arch/arm/xscale/ixp425_if_npe.c (and dev/ic/gem.c,
and so forth).
 1.75 11-Sep-2021  andvar Add missing double p and d for stopped and overriden accordingly.
Fix few more typos along the way, mainly in copy-pasted comments.
 1.74 16-Jun-2021  riastradh if_attach and if_initialize cannot fail, don't test return value

These were originally made failable back in 2017 when if_initialize
allocated a softint in every interface for link state changes, so
that it could fail gracefully instead of panicking:

https://mail-index.NetBSD.org/source-changes/2017/10/23/msg089053.html

However, this spawned many seldom- or never-tested error branches,
which are risky to have around. And that softint in every interface
has since been replaced by a single global workqueue, because link
state changes require thread context but not low latency or high
throughput:

https://mail-index.NetBSD.org/source-changes/2020/02/06/msg113759.html

So there is no longer any reason for if_initialize to fail. (The
subroutine if_stats_init can't fail because percpu_alloc can't fail
either.)

There is a snag: the softint_establish in if_percpuq_create could
fail, potentially leading to bad consequences later on trying to use
the softint. This change doesn't introduce any new bugs because of
the snag -- if_percpuq_attach was already broken. However, the snag
can be better addressed without spawning error branches, either by
using a single softint or making softints less scarce.

(Separate commit will change the signatures of if_attach and
if_initialize to return void, scheduled to ride whatever is the next
convenient kernel bump.)

Patch and testing on amd64 and evbmips64-eb by maya@; commit message
soliloquy, and compile-testing on evbppc/i386/earmv7hf, by me.
 1.73 13-May-2021  msaitoh Cast to uint32_t to avoid undefined behavior in dwc_gmac_write_hwaddr().
Found by kUBSan.
 1.72 31-Dec-2020  ryo branches: 1.72.4; 1.72.6;
extend the timeout value. dwc_gmac_reset() sometimes takes more time.
 1.71 27-Jun-2020  jmcneill branches: 1.71.2;
prop_data_data_nocopy -> prop_data_value
 1.70 17-May-2020  chs Mask all the MMC counter interrupts if the MMC module is present.
 1.69 29-Jan-2020  thorpej Adopt <net/if_stats.h>.
 1.68 19-Oct-2019  tnn branches: 1.68.2;
awge: drop redundant m_adj(). Handled via uipc_mbuf.c r1.235 instead.
 1.67 15-Oct-2019  tnn correct pointer arithmetics
 1.66 15-Oct-2019  tnn awge: fix issue that caused rx packets to be corrupt with DIAGNOSTIC kernel

It seems the hardware can only reliably do rx DMA to addresses that are
dcache size aligned. This is hinted at by some GMAC data sheets but hard to
find an authoritative source.

on non-DIAGNOSTIC kernels we always implicitly get MCLBYTES-aligned mbuf
data pointers, but with the reintroduction of POOL_REDZONE for DIAGNOSTIC
we can get 8-byte alignment due to redzone padding. So align rx pointers to
64 bytes which should be good for both arm32 and aarch64.

While here change some bus_dmamap_load() to bus_dmamap_load_mbuf() and add
one missing bus_dmamap_sync(). Also fixes the code to not assume that
MCLBYTES == AWGE_MAX_PACKET. User may override MCLSHIFT in kernel config.
 1.65 13-Sep-2019  msaitoh if_flags is neither int nor short. It's unsigned short.
 1.64 21-Jul-2019  mrg branches: 1.64.2;
move DWCGMAC_MPSAFE into dwc_gmac_var.h and introduce an
additional define that is 0 or FDT_INTR_MPSAFE that the
frontends can use when passing to fdtbus_intr_establish().

with NET_MPSAFE enabled, this avoids hangs seen on rock64,
as well as finishing the MPSAFE port for this driver.

XXX: still don't know why the existing hangs occur.
 1.63 08-Jul-2019  msaitoh Add rnd(9) support.
 1.62 23-May-2019  msaitoh Whitespace fix (mainly tabify).
 1.61 23-May-2019  msaitoh -No functional change:
- KNF
- u_int*_t -> uint*_t.
 1.60 15-May-2019  ozaki-r Store IFF_ALLMULTI in ec_flags instead of if_flags to avoid data races

IFF_ALLMULTI is set/unset to if_flags via if_mcast_op. To avoid data races on
if_flags, IFNET_LOCK was added for if_mcast_op. Unfortunately it produces
a deadlock so we want to remove added IFNET_LOCK by avoiding the data races by
another approach.

This fix introduces ec_flags to struct ethercom and stores IFF_ALLMULTI to it.
ec_flags is protected by ETHER_LOCK and thus IFNET_LOCK is no longer necessary
for if_mcast_op. Note that the fix is applied only to MP-safe drivers that
the data races matter.

In the kernel, IFF_ALLMULTI is set by a driver and used by the driver itself.
So changing the storing place doesn't break anything. One exception is
ioctl(SIOCGIFFLAGS); we have to include IFF_ALLMULTI in a result if needed to
export the flag as well as before.

A upcoming commit will remove IFNET_LOCK.

PR kern/54189
 1.59 15-Apr-2019  ozaki-r Protect ether_multi list

Fix this driver because it can set IFEF_MPSAFE.
 1.58 07-Mar-2019  msaitoh Fix previous. Pass phy_id correctly.
 1.57 23-Feb-2019  martin Pass the phy ID to dwc_gmac_attach.
 1.56 22-Jan-2019  msaitoh Change MII PHY read/write API from:

int (*mii_readreg_t)(device_t, int, int);
void (*mii_writereg_t)(device_t, int, int, int);
to:

int (*mii_readreg_t)(device_t, int, int, uint16_t *);
int (*mii_writereg_t)(device_t, int, int, uint16_t);

Now we can test if a read/write operation failed or not by the return value.

In 802.3 spec says that the PHY shall not respond to read/write transaction
to the unimplemented register(22.2.4.3). Detecting timeout can be used to
check whether a register is implemented or not (if the register conforms to
the spec). ukphy(4) can be used this for MII_MMDACR and MII_MMDAADR.

Note that I noticed that the following code do infinite loop in the
read/wirte function. If it accesses unimplemented PHY register, it will hang.
It should be fixed:

arm/at91/at91emac.c
arm/ep93xx/epe.c
arm/omap/omapl1x_emac.c
mips/ralink/ralink_eth.c
arch/powerpc/booke/dev/pq3etsec.c(read)
dev/cadence/if_cemac.c <- hkenken
dev/ic/lan9118.c


Tested with the following device:

axe+ukphy
axe+rgephy
axen+rgephy (tested by Andrius V)
wm+atphy
wm+ukphy
wm+igphy
wm+ihphy
wm+makphy
sk+makphy
sk+brgphy
sk+gentbi
msk+makphy
sip+icsphy
sip+ukphy
re+rgephy
bge+brgphy
bnx+brgphy
gsip+gphyter
rtk+rlphy
fxp+inphy (tested by Andrius V)
tlp+acphy
ex+exphy
epic+qsphy
vge+ciphy (tested by Andrius V)
vr+ukphy (tested by Andrius V)
vte+ukphy (tested by Andrius V)

Not tested (MAC):
arm:at91emac
arm:cemac
arm:epe
arm:geminigmac
arm:enet
arm:cpsw
arm:emac(omac)
arm:emac(sunxi)
arm:npe
evbppc:temac
macppc:bm
macppc:gm
mips:aumac
mips:ae
mips:cnmac
mips:reth
mips:sbmac
playstation2:smap
powerpc:tsec
powerpc:emac(ibm4xx)
sgimips:mec
sparc:be
sf
ne(ax88190, dl10019)
awge
ep
gem
hme
smsh
mtd
sm
age
alc
ale
bce
cas
et
jme
lii
nfe
pcn
ste
stge
tl
xi
aue
mue
smsc
udav
url

Not tested (PHY):
amhphy
bmtphy
dmphy
etphy
glxtphy
ikphy
iophy
lxtphy
nsphyter
pnaphy
rdcphy
sqphy
tlphy
tqphy
urlphy
 1.55 08-Oct-2018  martin Bring back support for enhanced descriptor format in newer core versions.
Fix a few endian bugs and check the main core version before trying to
read the hardware feature mask. Only read the hardware feature register
if core version reported is >= 3.5 (all my older hardware reports 0).
With some hints and patches from jared, and ok from aymeric
 1.54 28-Sep-2018  aymeric Revert the recent support for enhanced descriptors until a viable solution is
found.

It broke at least Cubietruck, Orange Pi One, and maybe Rock64 ethernets in
different ways. Unfortunately it works on my Olinuxino Micro and Lime 2 so I
can't reproduce the bugs for now.

Should fix PR#53637
 1.53 17-Sep-2018  aymeric Add support for the enhanced descriptors feature.

This makes "recent" dwc gmac controllers, as found e.g. on the Cyclone V, work.
The change was also tested working on an Allwinner A20 which doesn't have the
feature.

No negative reaction on port-arm.
 1.52 18-Jul-2018  sevan Be consistent among ethernet drivers on the convention for printing ethernet
addresses.

NFC
 1.51 30-Jun-2018  jmcneill dwc_gmac_attach: return non-zero on failure
 1.50 26-Jun-2018  msaitoh branches: 1.50.2;
Implement the BPF direction filter (BIOC[GS]DIRECTION). It provides backward
compatibility with BIOC[GS]SEESENT ioctl. The userland interface is the same
as FreeBSD.

This change also fixes a bug that the direction is misunderstand on some
environment by passing the direction to bpf_mtap*() instead of checking
m->m_pkthdr.rcvif.
 1.49 18-Jun-2018  jmcneill Write MAC address high register before low register. Apparently the
hardware updates the filter when the low register is written.
 1.48 18-Jun-2018  jmcneill Clear IFF_RUNNING | IFF_OACTIVE when stopping interface.
 1.47 17-Jun-2018  jmcneill Avoid calling bus_dmamap_sync with len=0
 1.46 16-Jun-2018  jmcneill Add flag for disabling store-and-forward mode, and a callback for notifying
bus glue that the link speed has changed.
 1.45 21-Dec-2017  martin branches: 1.45.2;
Don't KASSERT that we are MPSAFE if ! DWCGMAC_MPSAFE
 1.44 19-Dec-2017  ozaki-r Don't set IFEF_MPSAFE unless NET_MPSAFE at this point

Because recent investigations show that interfaces with IFEF_MPSAFE need to
follow additional restrictions to work with the flag safely. We should enable it
on an interface by default only if the interface surely satisfies the
restrictions, which are described in if.h.

Note that enabling IFEF_MPSAFE solely gains a few benefit on performance because
the network stack is still serialized by the big kernel locks by default.
 1.43 16-Nov-2017  ozaki-r branches: 1.43.2;
Unify IFEF_*_MPSAFE into IFEF_MPSAFE

There are already two flags for if_output and if_start, however, it seems such
MPSAFE flags are eventually needed for all if_XXX operations. Having discrete
flags for each operation is wasteful of if_extflags bits. So let's unify
the flags into one: IFEF_MPSAFE.

Fortunately IFEF_*_MPSAFE flags have never been included in any releases, so
we can change them without breaking backward compatibility of the releases
(though the kernel version of -current should be bumped).

Note that if an interface have both MP-safe and non-MP-safe operations at a
time, we have to set the IFEF_MPSAFE flag and let callees of non-MP-safe
opeartions take the kernel lock.

Proposed on tech-kern@ and tech-net@
 1.42 23-Oct-2017  jakllsch We don't need '&mii', but just 'mii' for mii_detach().
 1.41 23-Oct-2017  msaitoh - If if_initialize() failed in the attach function, free resources and return.
- Add missing dwc_gmac_free_dma_rings() and mutex_destroy() when attach
failed.
 1.40 20-Feb-2017  ozaki-r branches: 1.40.6;
Apply deferred if_start to more drivers
 1.39 23-Jan-2017  skrll Use our ipq... sorry martin
 1.38 21-Jan-2017  skrll Merge from nick-nhusb - some MPification
 1.37 15-Dec-2016  ozaki-r branches: 1.37.2;
Move bpf_mtap and if_ipackets++ on Rx of each driver to percpuq if_input

The benefits of the change are:
- We can reduce codes
- We can provide the same behavior between drivers
- Where/When if_ipackets is counted up
- Note that some drivers still update packet statistics in their own
way (periodical update)
- Moved bpf_mtap run in softint
- This makes it easy to MP-ify bpf

Proposed on tech-kern and tech-net
 1.36 10-Jun-2016  ozaki-r branches: 1.36.2;
Introduce m_set_rcvif and m_reset_rcvif

The API is used to set (or reset) a received interface of a mbuf.
They are counterpart of m_get_rcvif, which will come in another
commit, hide internal of rcvif operation, and reduce the diff of
the upcoming change.

No functional change.
 1.35 09-Feb-2016  ozaki-r Introduce softint-based if_input

This change intends to run the whole network stack in softint context
(or normal LWP), not hardware interrupt context. Note that the work is
still incomplete by this change; to that end, we also have to softint-ify
if_link_state_change (and bpf) which can still run in hardware interrupt.

This change softint-ifies at ifp->if_input that is called from
each device driver (and ieee80211_input) to ensure Layer 2 runs
in softint (e.g., ether_input and bridge_input). To this end,
we provide a framework (called percpuq) that utlizes softint(9)
and percpu ifqueues. With this patch, rxintr of most drivers just
queues received packets and schedules a softint, and the softint
dequeues packets and does rest packet processing.

To minimize changes to each driver, percpuq is allocated in struct
ifnet for now and that is initialized by default (in if_attach).
We probably have to move percpuq to softc of each driver, but it's
future work. At this point, only wm(4) has percpuq in its softc
as a reference implementation.

Additional information including performance numbers can be found
in the thread at tech-kern@ and tech-net@:
http://mail-index.netbsd.org/tech-kern/2016/01/14/msg019997.html

Acknowledgment: riastradh@ greatly helped this work.
Thank you very much!
 1.34 21-Aug-2015  jmcneill No need to BUS_DMASYNC_PREREAD the transmit data buffer. Fixes "NFS writes
being corrupted?" issue on ODROID-C1 as seen on port-arm.
 1.33 12-Jun-2015  tnn Supports ETHERCAP_VLAN_MTU. ok martin@ PR#49967
 1.32 23-Feb-2015  martin Apply patch from FUKAUMI Naoki to fix ring buffer handling when the
ring fills completely.
 1.31 08-Jan-2015  jmcneill fix a couple txq fencepost issues, from FUKAUMI Naoki <fun@naobsd.org>
 1.30 05-Jan-2015  martin Fix index vs. count confusion when syncing a range of newly queued TX
descriptors. Pointed out by "naobsd" in private chat.
 1.29 07-Dec-2014  jmcneill if we dont have a mac address, make one up
 1.28 28-Nov-2014  martin branches: 1.28.2;
After handling an interrupt, try to handle more packets as we may have
space in the descriptor ring now.
Pointed out by Jared.
 1.27 23-Nov-2014  matt Fix bus_dmamap_sync usage.
 1.26 23-Nov-2014  martin Revert previous change to dwc_gmac_txintr() - while it looks strange at
first sight (and sorry I didn't spot it when reviewing), it is a small
optimization and actually correct.
Add a comment explaining it.
 1.25 22-Nov-2014  jmcneill - Add MII flow control support
- Set "disable jabber" and "auto padding/CRC stripping" bits in MAC conf
- Write intr mask to intr mask register, not status
- Setup both TX and RX burst modes
- Setup both TX and RX store & forward modes
- Correct an issue with the "end" descriptor passed to dwc_gmac_txdesc_sync
in dwc_gmac_tx_intr

ok martin@
 1.24 27-Oct-2014  skrll branches: 1.24.2;
Typo in comment
 1.23 26-Oct-2014  joerg Typo
 1.22 26-Oct-2014  martin Greatly simplify ioctl handling by fully relying on ether_ioctl and a
ifflags-change callback, together with a shadow copy of the last active
interface flags.
Fix ALLMULTI vs. PROMISC handling.
Fix mac hash filter calculation by reversing the crc bits (pointed out
by Jared).
 1.21 25-Oct-2014  joerg Fix typo. Use format string.
 1.20 21-Oct-2014  jmcneill multicast hash filter support
 1.19 20-Oct-2014  matt Set M_HASFCS does the frame does include the FCS in the length.
 1.18 20-Oct-2014  jmcneill add $NetBSD$ to top of files
 1.17 20-Oct-2014  martin Cosmetics - block interrupts while enabling different interrupt sources.
 1.16 20-Oct-2014  martin Consistently set the RX descriptors controll word - do not disable RX
interrupt and set chain mode. Now it does not run off the end of the
ring after 512 packets any more.
 1.15 20-Oct-2014  martin Cleanup debug code a bit.
 1.14 19-Oct-2014  jmcneill if we read an insane mac address from the chip, dont attach
 1.13 19-Oct-2014  jmcneill only set PR bit in frame filter if IFF_PROMISC is set, and set PM bit if IFF_ALLMULTI is set
 1.12 19-Oct-2014  jmcneill fix inverted logic with AWIN_GMAC_MAC_CONF_MIISEL bit; my cubieboard2 can talk to the network now!
 1.11 19-Oct-2014  martin Add more MAC filter setup, some DMA burst configuration (from jmcneill),
actually enable RX interrupts (spotted by jmcneill), add RX handling
code and debug code.
 1.10 13-Oct-2014  martin Do not flush/restart the TX engine after queuing packets, but instead
keep it running (it will stall when out of descriptors), and inform it
about new descriptors available by writing to the TXPOLL request register.
Add more debugging code.
 1.9 13-Oct-2014  martin When link status changes, update MAC configuration accordingly.
 1.8 08-Oct-2014  martin More interrupt handling, more debug code, less magic numbers.
 1.7 14-Sep-2014  martin Add (disabled) debug code.
Fix DMA descriptor link initialization.
 1.6 14-Sep-2014  martin Cleanup and __BIT()ify
 1.5 11-Sep-2014  martin Simplify device property handling by moving it into the core driver.
Overriding the MAC address now works again.
 1.4 09-Sep-2014  martin Remove debug printf, now that MII status changes work
 1.3 09-Sep-2014  martin Make the MII clock variable and passed in from the frontend.
 1.2 09-Sep-2014  martin Fix MII setup and interrupt handling, from Robert Swindell.
 1.1 08-Sep-2014  martin Add work-in-progress driver for the Designware GMAC core, found on some
allwinner chips.
 1.24.2.8 31-Aug-2015  snj Pull up following revision(s) (requested by jmcneill in ticket #958):
sys/dev/ic/dwc_gmac.c: revision 1.34
No need to BUS_DMASYNC_PREREAD the transmit data buffer. Fixes "NFS writes
being corrupted?" issue on ODROID-C1 as seen on port-arm.
 1.24.2.7 27-Feb-2015  snj Pull up following revision(s) (requested by martin in ticket #546):
sys/dev/ic/dwc_gmac.c: revision 1.32
Apply patch from FUKAUMI Naoki to fix ring buffer handling when the
ring fills completely.
 1.24.2.6 03-Feb-2015  bouyer Pull up following revision(s) (requested by snj in ticket #481):
sys/dev/ic/dwc_gmac_var.h: revision 1.6
sys/dev/ic/dwc_gmac_reg.h: revision 1.13
sys/dev/ic/dwc_gmac.c: revision 1.25
sys/dev/ic/dwc_gmac.c: revision 1.26
sys/dev/ic/dwc_gmac.c: revision 1.28
sys/dev/ic/dwc_gmac.c: revision 1.31
- Add MII flow control support
- Set "disable jabber" and "auto padding/CRC stripping" bits in MAC conf
- Write intr mask to intr mask register, not status
- Setup both TX and RX burst modes
- Setup both TX and RX store & forward modes
- Correct an issue with the "end" descriptor passed to dwc_gmac_txdesc_sync
in dwc_gmac_tx_intr
ok martin@
Revert previous change to dwc_gmac_txintr() - while it looks strange at
first sight (and sorry I didn't spot it when reviewing), it is a small
optimization and actually correct.
Add a comment explaining it.
After handling an interrupt, try to handle more packets as we may have
space in the descriptor ring now.
Pointed out by Jared.
fix a couple txq fencepost issues, from FUKAUMI Naoki <fun@naobsd.org>
 1.24.2.5 07-Jan-2015  msaitoh Pull up following revision(s) (requested by martin in ticket #383):
sys/dev/ic/dwc_gmac.c: revision 1.30
Fix index vs. count confusion when syncing a range of newly queued TX
descriptors. Pointed out by FUKAUMI Naoki in private chat.
 1.24.2.4 09-Dec-2014  martin Pull up following revision(s) (requested by jmcneill in ticket #300):
sys/dev/ic/dwc_gmac.c: revision 1.29
if we dont have a mac address, make one up
 1.24.2.3 25-Nov-2014  snj Pull up following revision(s) (requested by jmcneill in ticket #259):
sys/dev/ic/dwc_gmac.c: revision 1.27
Fix bus_dmamap_sync usage.
 1.24.2.2 09-Nov-2014  snj Pull up following revision(s) (requested by martin in ticket #189):
sys/dev/ic/dwc_gmac.c: revision 1.1-1.24
sys/dev/ic/dwc_gmac_reg.h: revision 1.1-1.12
sys/dev/ic/dwc_gmac_var.h: revision 1.1-1.5
Add support for Synopsis Designware GMAC ethernet core, as found on
various Allwiner boards and used by the awge(4) driver.
 1.24.2.1 27-Oct-2014  snj file dwc_gmac.c was added on branch netbsd-7 on 2014-11-09 19:06:57 +0000
 1.28.2.12 28-Aug-2017  skrll Sync with HEAD
 1.28.2.11 05-Feb-2017  skrll Sync with HEAD
 1.28.2.10 15-Jul-2016  skrll Protect sc_if_flags in dwc_gmac_ifflags_cb with the lock
 1.28.2.9 15-Jul-2016  skrll Define/assert IFEF_START_MPSAFE
 1.28.2.8 09-Jul-2016  skrll Sync with HEAD
 1.28.2.7 16-Jun-2016  skrll Fix indent botch that crept in
 1.28.2.6 12-Jun-2016  skrll Oops... use the ipq we created.
 1.28.2.5 12-Jun-2016  skrll Fix locking botch
 1.28.2.4 12-Jun-2016  skrll First pass at making this driver and attachments NET_MPSAFE aware.

I've not tested this yet.
 1.28.2.3 19-Mar-2016  skrll Sync with HEAD
 1.28.2.2 22-Sep-2015  skrll Sync with HEAD
 1.28.2.1 06-Apr-2015  skrll Sync with HEAD
 1.36.2.2 20-Mar-2017  pgoyette Sync with HEAD
 1.36.2.1 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.37.2.1 21-Apr-2017  bouyer Sync with HEAD
 1.40.6.5 12-Aug-2022  martin Pull up following revision(s) (requested by sekiya in ticket #1755):

sys/dev/ic/dwc_gmac.c: revision 1.76-1.77

Turn off AWIN_GMAC_MAC_CONF_ACS, so that all received packets retain FCS
bytes.
ether_input() can now trust M_HASFCS to accurately represent the packet
contents.

Discussed on tech-net@
 1.40.6.4 18-Jun-2018  martin Pull up following revision(s) (requested by jmcneill in ticket #885):

sys/dev/ic/dwc_gmac.c: revision 1.47

Avoid calling bus_dmamap_sync with len=0
 1.40.6.3 13-Jan-2018  snj Pull up following revision(s) (requested by martin in ticket #456):
sys/dev/ic/dwc_gmac.c: 1.45
Don't KASSERT that we are MPSAFE if ! DWCGMAC_MPSAFE
 1.40.6.2 02-Jan-2018  snj Pull up following revision(s) (requested by ozaki-r in ticket #456):
sys/arch/arm/sunxi/sunxi_emac.c: 1.9
sys/dev/ic/dwc_gmac.c: 1.43-1.44
sys/dev/pci/if_iwm.c: 1.75
sys/dev/pci/if_wm.c: 1.543
sys/dev/pci/ixgbe/ixgbe.c: 1.112
sys/dev/pci/ixgbe/ixv.c: 1.74
sys/kern/sys_socket.c: 1.75
sys/net/agr/if_agr.c: 1.43
sys/net/bpf.c: 1.219
sys/net/if.c: 1.397, 1.399, 1.401-1.403, 1.406-1.410, 1.412-1.416
sys/net/if.h: 1.242-1.247, 1.250, 1.252-1.257
sys/net/if_bridge.c: 1.140 via patch, 1.142-1.146
sys/net/if_etherip.c: 1.40
sys/net/if_ethersubr.c: 1.243, 1.246
sys/net/if_faith.c: 1.57
sys/net/if_gif.c: 1.132
sys/net/if_l2tp.c: 1.15, 1.17
sys/net/if_loop.c: 1.98-1.101
sys/net/if_media.c: 1.35
sys/net/if_pppoe.c: 1.131-1.132
sys/net/if_spppsubr.c: 1.176-1.177
sys/net/if_tun.c: 1.142
sys/net/if_vlan.c: 1.107, 1.109, 1.114-1.121
sys/net/npf/npf_ifaddr.c: 1.3
sys/net/npf/npf_os.c: 1.8-1.9
sys/net/rtsock.c: 1.230
sys/netcan/if_canloop.c: 1.3-1.5
sys/netinet/if_arp.c: 1.255
sys/netinet/igmp.c: 1.65
sys/netinet/in.c: 1.210-1.211
sys/netinet/in_pcb.c: 1.180
sys/netinet/ip_carp.c: 1.92, 1.94
sys/netinet/ip_flow.c: 1.81
sys/netinet/ip_input.c: 1.362
sys/netinet/ip_mroute.c: 1.147
sys/netinet/ip_output.c: 1.283, 1.285, 1.287
sys/netinet6/frag6.c: 1.61
sys/netinet6/in6.c: 1.251, 1.255
sys/netinet6/in6_pcb.c: 1.162
sys/netinet6/ip6_flow.c: 1.35
sys/netinet6/ip6_input.c: 1.183
sys/netinet6/ip6_output.c: 1.196
sys/netinet6/mld6.c: 1.90
sys/netinet6/nd6.c: 1.239-1.240
sys/netinet6/nd6_nbr.c: 1.139
sys/netinet6/nd6_rtr.c: 1.136
sys/netipsec/ipsec_output.c: 1.65
sys/rump/net/lib/libnetinet/netinet_component.c: 1.9-1.10
kmem_intr_free kmem_intr_[z]alloced memory
the underlying pools are the same but api-wise those should match
Unify IFEF_*_MPSAFE into IFEF_MPSAFE
There are already two flags for if_output and if_start, however, it seems such
MPSAFE flags are eventually needed for all if_XXX operations. Having discrete
flags for each operation is wasteful of if_extflags bits. So let's unify
the flags into one: IFEF_MPSAFE.
Fortunately IFEF_*_MPSAFE flags have never been included in any releases, so
we can change them without breaking backward compatibility of the releases
(though the kernel version of -current should be bumped).
Note that if an interface have both MP-safe and non-MP-safe operations at a
time, we have to set the IFEF_MPSAFE flag and let callees of non-MP-safe
opeartions take the kernel lock.
Proposed on tech-kern@ and tech-net@
Provide macros for softnet_lock and KERNEL_LOCK hiding NET_MPSAFE switch
It reduces C&P codes such as "#ifndef NET_MPSAFE KERNEL_LOCK(1, NULL); ..."
scattered all over the source code and makes it easy to identify remaining
KERNEL_LOCK and/or softnet_lock that are held even if NET_MPSAFE.
No functional change
Hold KERNEL_LOCK on if_ioctl selectively based on IFEF_MPSAFE
If IFEF_MPSAFE is set, hold the lock and otherwise don't hold.
This change requires additions of KERNEL_LOCK to subsequence functions from
if_ioctl such as ifmedia_ioctl and ifioctl_common to protect non-MP-safe
components.
Proposed on tech-kern@ and tech-net@
Ensure to hold if_ioctl_lock when calling if_flags_set
Fix locking against myself on ifpromisc
vlan_unconfig_locked could be called with holding if_ioctl_lock.
Ensure to not turn on IFF_RUNNING of an interface until its initialization completes
And ensure to turn off it before destruction as per IFF_RUNNING's description
"resource allocated". (The description is a bit doubtful though, I believe the
change is still proper.)
Ensure to hold if_ioctl_lock on if_up and if_down
One exception for if_down is if_detach; in the case the lock isn't needed
because it's guaranteed that no other one can access ifp at that point.
Make if_link_queue MP-safe if IFEF_MPSAFE
if_link_queue is a queue to store events of link state changes, which is
used to pass events from (typically) an interrupt handler to
if_link_state_change softint. The queue was protected by KERNEL_LOCK so far,
but if IFEF_MPSAFE is enabled, it becomes unsafe because (perhaps) an interrupt
handler of an interface with IFEF_MPSAFE doesn't take KERNEL_LOCK. Protect it
by a spin mutex.
Additionally with this change KERNEL_LOCK of if_link_state_change softint is
omitted if NET_MPSAFE is enabled.
Note that the spin mutex is now ifp->if_snd.ifq_lock as well as the case of
if_timer (see the comment).
Use IFADDR_WRITER_FOREACH instead of IFADDR_READER_FOREACH
At that point no other one modifies the list so IFADDR_READER_FOREACH
is unnecessary. Use of IFADDR_READER_FOREACH is harmless in general though,
if we try to detect contract violations of pserialize, using it violates
the contract. So avoid using it makes life easy.
Ensure to call if_addr_init with holding if_ioctl_lock
Get rid of outdated comments
Fix build of kernels without ether
By throwing out if_enable_vlan_mtu and if_disable_vlan_mtu that
created a unnecessary dependency from if.c to if_ethersubr.c.
PR kern/52790
Rename IFNET_LOCK to IFNET_GLOBAL_LOCK
IFNET_LOCK will be used in another lock, if_ioctl_lock (might be renamed then).
Wrap if_ioctl_lock with IFNET_* macros (NFC)
Also if_ioctl_lock perhaps needs to be renamed to something because it's now
not just for ioctl...
Reorder some destruction routines in if_detach
- Destroy if_ioctl_lock at the end of the if_detach because it's used in various
destruction routines
- Move psref_target_destroy after pr_purgeif because we want to use psref in
pr_purgeif (otherwise destruction procedures can be tricky)
Ensure to call if_mcast_op with holding IFNET_LOCK
Note that CARP doesn't deal with IFNET_LOCK yet.
Remove IFNET_GLOBAL_LOCK where it's unnecessary because IFNET_LOCK is held
Describe which lock is used to protect each member variable of struct ifnet
Requested by skrll@
Write a guideline for converting an interface to IFEF_MPSAFE
Requested by skrll@
Note that IFNET_LOCK must not be held in softint
Don't set IFEF_MPSAFE unless NET_MPSAFE at this point
Because recent investigations show that interfaces with IFEF_MPSAFE need to
follow additional restrictions to work with the flag safely. We should enable it
on an interface by default only if the interface surely satisfies the
restrictions, which are described in if.h.
Note that enabling IFEF_MPSAFE solely gains a few benefit on performance because
the network stack is still serialized by the big kernel locks by default.
 1.40.6.1 10-Dec-2017  snj Pull up following revision(s) (requested by msaitoh in ticket #427):
sys/arch/amiga/dev/if_bah_zbus.c: 1.17
sys/arch/arm/broadcom/bcm53xx_eth.c: 1.30
sys/arch/powerpc/booke/dev/pq3etsec.c: 1.32
sys/arch/usermode/dev/if_veth.c: 1.9
sys/dev/ic/an.c: 1.66
sys/dev/ic/athn.c: 1.17
sys/dev/ic/atw.c: 1.162
sys/dev/ic/bwi.c: 1.33
sys/dev/ic/dwc_gmac.c: 1.41-1.42
sys/dev/ic/malo.c: 1.10
sys/dev/ic/rt2560.c: 1.31
sys/dev/ic/rt2661.c: 1.36
sys/dev/ic/rt2860.c: 1.29
sys/dev/ic/rtw.c: 1.127
sys/dev/ic/rtwvar.h: 1.46
sys/dev/ic/smc90cx6.c: 1.71
sys/dev/ic/smc90cx6var.h: 1.12
sys/dev/ic/wi.c: 1.244
sys/dev/pci/if_ipw.c: 1.66
sys/dev/pci/if_iwi.c: 1.104
sys/dev/pci/if_iwm.c: 1.76
sys/dev/pci/if_iwn.c: 1.86
sys/dev/pci/if_rtwn.c: 1.13
sys/dev/pci/if_wm.c: 1.541
sys/dev/pci/if_wpi.c: 1.79
sys/dev/pci/ixgbe/ixgbe.c: 1.106
sys/dev/pci/ixgbe/ixv.c: 1.73 via patch
sys/dev/pcmcia/if_malo_pcmcia.c: 1.15
sys/dev/scsipi/if_se.c: 1.95
sys/dev/usb/if_upl.c: 1.60
sys/net/if.c: 1.396
sys/net/if.h: 1.241
sys/net/if_arc.h: 1.23
sys/net/if_arcsubr.c: 1.78
sys/net/if_bridge.c: 1.136-1.137
sys/net/if_etherip.c: 1.39
sys/net/if_faith.c: 1.56
sys/net/if_gif.c: 1.131
sys/net/if_loop.c: 1.96
sys/net/if_mpls.c: 1.30
sys/net/if_pppoe.c: 1.129
sys/net/if_srt.c: 1.27
sys/net/if_stf.c: 1.102
sys/net/if_tap.c: 1.100
sys/net/if_vlan.c: 1.105
sys/netinet/ip_carp.c: 1.91
sys/rump/net/lib/libshmif/if_shmem.c: 1.73-1.74
sys/rump/net/lib/libvirtif/if_virt.c: 1.55-1.56
if_initalize() and if_attach() failed when resource allocation failed
(e.g. allocating softint). Without this change, it panics. It's bad because
resource shortage really occured when a lot of pseudo interface is created.
To avoid this problem, don't panic and change return value of if_initialize()
and if_attach() to int. Caller fanction will be recover from error cleanly by
checking the return value.
Return if bah_attach_subr() failed.
If if_attach() failed in the attach function, return.
- If if_initialize() failed in the attach function, free resources and return.
- Add some missing frees in bridge_clone_destroy().
- KNF
If error occured in bcmeth_ccb_attach(), free resources and return.
If error occured in pq3etsec_attach(), free resources and return.
If error occured in the attach function, free resources and return.
- If if_initialize() failed in athn_attach(), free resources and return.
- Add missing pmf_event_deregister() in athn_detach().
- Free resources correctly on some errors in atw_attach().
- Use apint*() insread of printf() in the attach function.
If if_initialize() failed in the attach function, return.
- If if_initialize() failed in the attach function, free resources and return.
- Add missing dwc_gmac_free_dma_rings() and mutex_destroy() when attach
failed.
- If if_initialize() failed in the attach function, free resources and return.
- ifp is always not NULL in iwi_detach(). Check correctly with ifp->if_softc.
- If if_initialize() failed in the attach function, free resources and return.
- Fix error path in the attach function correctly.
If if_initialize() failed in the attach function, free resources and return.
If if_attach() failed in the attach function, free resources and return.
- If if_initialize() failed in the attach function, free resources and return.
- KNF
- If if_attach() failed in the attach function, free resources and return.
- KNF
Fix compile error.
Fix compile error.
We don't need '&mii', but just 'mii' for mii_detach().
Don't free sc_rthash twice
 1.43.2.2 03-Dec-2017  jdolecek update from HEAD
 1.43.2.1 16-Nov-2017  jdolecek file dwc_gmac.c was added on branch tls-maxphys on 2017-12-03 11:37:03 +0000
 1.45.2.5 26-Jan-2019  pgoyette Sync with HEAD
 1.45.2.4 20-Oct-2018  pgoyette Sync with head
 1.45.2.3 30-Sep-2018  pgoyette Ssync with HEAD
 1.45.2.2 28-Jul-2018  pgoyette Sync with HEAD
 1.45.2.1 25-Jun-2018  pgoyette Sync with HEAD
 1.50.2.3 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.50.2.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.50.2.1 10-Jun-2019  christos Sync with HEAD
 1.64.2.2 12-Aug-2022  martin Pull up following revision(s) (requested by sekiya in ticket #1499):

sys/dev/ic/dwc_gmac.c: revision 1.76-1.77

Turn off AWIN_GMAC_MAC_CONF_ACS, so that all received packets retain FCS
bytes.
ether_input() can now trust M_HASFCS to accurately represent the packet
contents.

Discussed on tech-net@
 1.64.2.1 11-Aug-2020  martin Pull up following revision(s) (requested by mrg in ticket #1045):

sys/kern/uipc_mbuf.c: revision 1.235
sys/dev/ic/dwc_gmac.c: revision 1.70
sys/dev/ic/dwc_gmac_reg.h: revision 1.20
sys/dev/ic/dwc_gmac.c: revision 1.66
sys/dev/ic/dwc_gmac.c: revision 1.67
sys/dev/ic/dwc_gmac.c: revision 1.68

awge: fix issue that caused rx packets to be corrupt with DIAGNOSTIC kernel

It seems the hardware can only reliably do rx DMA to addresses that are
dcache size aligned. This is hinted at by some GMAC data sheets but hard to
find an authoritative source.

on non-DIAGNOSTIC kernels we always implicitly get MCLBYTES-aligned mbuf
data pointers, but with the reintroduction of POOL_REDZONE for DIAGNOSTIC
we can get 8-byte alignment due to redzone padding. So align rx pointers to
64 bytes which should be good for both arm32 and aarch64.
While here change some bus_dmamap_load() to bus_dmamap_load_mbuf() and add
one missing bus_dmamap_sync(). Also fixes the code to not assume that
MCLBYTES == AWGE_MAX_PACKET. User may override MCLSHIFT in kernel config.
correct pointer arithmetics

mcl_cache: align items to COHERENCY_UNIT

Because we do cache incoherent DMA to/from mbufs we cannot safely share
share cache lines with adjacent items that may be concurrently accessed.

awge: drop redundant m_adj(). Handled via uipc_mbuf.c r1.235 instead.

Mask all the MMC counter interrupts if the MMC module is present.
 1.68.2.1 29-Feb-2020  ad Sync with head.
 1.71.2.1 03-Jan-2021  thorpej Sync w/ HEAD.
 1.72.6.1 31-May-2021  cjep sync with head
 1.72.4.1 17-Jun-2021  thorpej Sync w/ HEAD.
 1.87.2.1 02-Aug-2025  perseant Sync with HEAD
 1.24 19-Oct-2024  skrll #define<tab> consistency
 1.23 27-Jul-2024  skrll Handle GMAC_MAC_Version's that include USERVER.
 1.22 27-Feb-2024  skrll branches: 1.22.2;
Remove unused "SHIFT" defines. The "MASK" versions exist.
 1.21 11-May-2022  andvar fix various typos in comments.
 1.20 17-May-2020  chs Mask all the MMC counter interrupts if the MMC module is present.
 1.19 08-Oct-2018  martin branches: 1.19.4;
Bring back support for enhanced descriptor format in newer core versions.
Fix a few endian bugs and check the main core version before trying to
read the hardware feature mask. Only read the hardware feature register
if core version reported is >= 3.5 (all my older hardware reports 0).
With some hints and patches from jared, and ok from aymeric
 1.18 28-Sep-2018  aymeric Revert the recent support for enhanced descriptors until a viable solution is
found.

It broke at least Cubietruck, Orange Pi One, and maybe Rock64 ethernets in
different ways. Unfortunately it works on my Olinuxino Micro and Lime 2 so I
can't reproduce the bugs for now.

Should fix PR#53637
 1.17 17-Sep-2018  aymeric Add support for the enhanced descriptors feature.

This makes "recent" dwc gmac controllers, as found e.g. on the Cyclone V, work.
The change was also tested working on an Allwinner A20 which doesn't have the
feature.

No negative reaction on port-arm.
 1.16 16-Jun-2018  jmcneill branches: 1.16.2;
Add flag for disabling store-and-forward mode, and a callback for notifying
bus glue that the link speed has changed.
 1.15 21-Nov-2015  martin branches: 1.15.16; 1.15.18;
Fix an off by one in the bit definition for RX store and forward mode.
Pointed out by ganbold.
While there add a few other bits of the same register.
 1.14 28-Nov-2014  martin branches: 1.14.2;
Bits and values for checksum insertion controll
 1.13 22-Nov-2014  jmcneill - Add MII flow control support
- Set "disable jabber" and "auto padding/CRC stripping" bits in MAC conf
- Write intr mask to intr mask register, not status
- Setup both TX and RX burst modes
- Setup both TX and RX store & forward modes
- Correct an issue with the "end" descriptor passed to dwc_gmac_txdesc_sync
in dwc_gmac_tx_intr

ok martin@
 1.12 25-Oct-2014  joerg branches: 1.12.2;
Fix grammar
 1.11 21-Oct-2014  jmcneill multicast hash filter support
 1.10 20-Oct-2014  jmcneill add $NetBSD$ to top of files
 1.9 20-Oct-2014  martin The RXINT bit is a RX interrupt DISABLE bit.
 1.8 19-Oct-2014  martin Add more comments
 1.7 19-Oct-2014  martin Add more bits and comments, parts from jmcneill.
 1.6 18-Oct-2014  martin Fix GMAC_MII_CLKMASK and add a few clk setup bits for it.
 1.5 13-Oct-2014  martin Add MAC config register bit definitions
 1.4 08-Oct-2014  martin Fix a few bits, add more status bit definitions and some comments.
Remove driver specific preference definitions.
 1.3 14-Sep-2014  martin Cleanup and __BIT()ify
 1.2 09-Sep-2014  martin Make the MII clock variable and passed in from the frontend.
 1.1 08-Sep-2014  martin Add work-in-progress driver for the Designware GMAC core, found on some
allwinner chips.
 1.12.2.4 26-Dec-2015  snj Pull up following revision(s) (requested by jmcneill in ticket #1053):
sys/dev/ic/dwc_gmac_reg.h: revision 1.15
Fix an off by one in the bit definition for RX store and forward mode.
Pointed out by ganbold.
While there add a few other bits of the same register.
 1.12.2.3 03-Feb-2015  bouyer branches: 1.12.2.3.2;
Pull up following revision(s) (requested by snj in ticket #481):
sys/dev/ic/dwc_gmac_var.h: revision 1.6
sys/dev/ic/dwc_gmac_reg.h: revision 1.13
sys/dev/ic/dwc_gmac.c: revision 1.25
sys/dev/ic/dwc_gmac.c: revision 1.26
sys/dev/ic/dwc_gmac.c: revision 1.28
sys/dev/ic/dwc_gmac.c: revision 1.31
- Add MII flow control support
- Set "disable jabber" and "auto padding/CRC stripping" bits in MAC conf
- Write intr mask to intr mask register, not status
- Setup both TX and RX burst modes
- Setup both TX and RX store & forward modes
- Correct an issue with the "end" descriptor passed to dwc_gmac_txdesc_sync
in dwc_gmac_tx_intr
ok martin@
Revert previous change to dwc_gmac_txintr() - while it looks strange at
first sight (and sorry I didn't spot it when reviewing), it is a small
optimization and actually correct.
Add a comment explaining it.
After handling an interrupt, try to handle more packets as we may have
space in the descriptor ring now.
Pointed out by Jared.
fix a couple txq fencepost issues, from FUKAUMI Naoki <fun@naobsd.org>
 1.12.2.2 09-Nov-2014  snj Pull up following revision(s) (requested by martin in ticket #189):
sys/dev/ic/dwc_gmac.c: revision 1.1-1.24
sys/dev/ic/dwc_gmac_reg.h: revision 1.1-1.12
sys/dev/ic/dwc_gmac_var.h: revision 1.1-1.5
Add support for Synopsis Designware GMAC ethernet core, as found on
various Allwiner boards and used by the awge(4) driver.
 1.12.2.1 25-Oct-2014  snj file dwc_gmac_reg.h was added on branch netbsd-7 on 2014-11-09 19:06:57 +0000
 1.12.2.3.2.1 26-Dec-2015  snj Pull up following revision(s) (requested by jmcneill in ticket #1053):
sys/dev/ic/dwc_gmac_reg.h: revision 1.15
Fix an off by one in the bit definition for RX store and forward mode.
Pointed out by ganbold.
While there add a few other bits of the same register.
 1.14.2.1 27-Dec-2015  skrll Sync with HEAD (as of 26th Dec)
 1.15.18.3 20-Oct-2018  pgoyette Sync with head
 1.15.18.2 30-Sep-2018  pgoyette Ssync with HEAD
 1.15.18.1 25-Jun-2018  pgoyette Sync with HEAD
 1.15.16.2 03-Dec-2017  jdolecek update from HEAD
 1.15.16.1 21-Nov-2015  jdolecek file dwc_gmac_reg.h was added on branch tls-maxphys on 2017-12-03 11:37:03 +0000
 1.16.2.1 10-Jun-2019  christos Sync with HEAD
 1.19.4.1 11-Aug-2020  martin Pull up following revision(s) (requested by mrg in ticket #1045):

sys/kern/uipc_mbuf.c: revision 1.235
sys/dev/ic/dwc_gmac.c: revision 1.70
sys/dev/ic/dwc_gmac_reg.h: revision 1.20
sys/dev/ic/dwc_gmac.c: revision 1.66
sys/dev/ic/dwc_gmac.c: revision 1.67
sys/dev/ic/dwc_gmac.c: revision 1.68

awge: fix issue that caused rx packets to be corrupt with DIAGNOSTIC kernel

It seems the hardware can only reliably do rx DMA to addresses that are
dcache size aligned. This is hinted at by some GMAC data sheets but hard to
find an authoritative source.

on non-DIAGNOSTIC kernels we always implicitly get MCLBYTES-aligned mbuf
data pointers, but with the reintroduction of POOL_REDZONE for DIAGNOSTIC
we can get 8-byte alignment due to redzone padding. So align rx pointers to
64 bytes which should be good for both arm32 and aarch64.
While here change some bus_dmamap_load() to bus_dmamap_load_mbuf() and add
one missing bus_dmamap_sync(). Also fixes the code to not assume that
MCLBYTES == AWGE_MAX_PACKET. User may override MCLSHIFT in kernel config.
correct pointer arithmetics

mcl_cache: align items to COHERENCY_UNIT

Because we do cache incoherent DMA to/from mbufs we cannot safely share
share cache lines with adjacent items that may be concurrently accessed.

awge: drop redundant m_adj(). Handled via uipc_mbuf.c r1.235 instead.

Mask all the MMC counter interrupts if the MMC module is present.
 1.22.2.1 02-Aug-2025  perseant Sync with HEAD
 1.22 11-Aug-2024  riastradh awge(4): Narrow scope of `core' lock and rename to mcast lock.

Sprinkle locking notes.

Proposed at:

https://mail-index.netbsd.org/source-changes-d/2024/08/10/msg014251.html

Comment-only changes from the updated patch at:

https://mail-index.netbsd.org/source-changes-d/2024/08/10/msg014252.html
 1.21 10-Aug-2024  skrll awge(4): MP improvements

Remove the non-MP-safe scaffolding and make the locking less
coarse.
 1.20 08-Aug-2024  skrll KNF
 1.19 27-Feb-2024  skrll branches: 1.19.2;
Use __BIT.
 1.18 11-Feb-2024  skrll Fix a comment. arm32 stopped using 8K pages a long time ago.
 1.17 18-Sep-2022  thorpej Eliminate use of IFF_OACTIVE.
 1.16 13-Sep-2019  msaitoh if_flags is neither int nor short. It's unsigned short.
 1.15 21-Jul-2019  mrg move DWCGMAC_MPSAFE into dwc_gmac_var.h and introduce an
additional define that is 0 or FDT_INTR_MPSAFE that the
frontends can use when passing to fdtbus_intr_establish().

with NET_MPSAFE enabled, this avoids hangs seen on rock64,
as well as finishing the MPSAFE port for this driver.

XXX: still don't know why the existing hangs occur.
 1.14 08-Jul-2019  msaitoh Add rnd(9) support.
 1.13 23-Feb-2019  martin Pass the phy ID to dwc_gmac_attach.
 1.12 08-Oct-2018  martin Bring back support for enhanced descriptor format in newer core versions.
Fix a few endian bugs and check the main core version before trying to
read the hardware feature mask. Only read the hardware feature register
if core version reported is >= 3.5 (all my older hardware reports 0).
With some hints and patches from jared, and ok from aymeric
 1.11 28-Sep-2018  aymeric Revert the recent support for enhanced descriptors until a viable solution is
found.

It broke at least Cubietruck, Orange Pi One, and maybe Rock64 ethernets in
different ways. Unfortunately it works on my Olinuxino Micro and Lime 2 so I
can't reproduce the bugs for now.

Should fix PR#53637
 1.10 17-Sep-2018  aymeric Add support for the enhanced descriptors feature.

This makes "recent" dwc gmac controllers, as found e.g. on the Cyclone V, work.
The change was also tested working on an Allwinner A20 which doesn't have the
feature.

No negative reaction on port-arm.
 1.9 30-Jun-2018  jmcneill dwc_gmac_attach: return non-zero on failure
 1.8 16-Jun-2018  jmcneill branches: 1.8.2;
Add flag for disabling store-and-forward mode, and a callback for notifying
bus glue that the link speed has changed.
 1.7 21-Jan-2017  skrll branches: 1.7.12; 1.7.14;
Merge from nick-nhusb - some MPification
 1.6 22-Nov-2014  jmcneill branches: 1.6.2; 1.6.4; 1.6.6;
- Add MII flow control support
- Set "disable jabber" and "auto padding/CRC stripping" bits in MAC conf
- Write intr mask to intr mask register, not status
- Setup both TX and RX burst modes
- Setup both TX and RX store & forward modes
- Correct an issue with the "end" descriptor passed to dwc_gmac_txdesc_sync
in dwc_gmac_tx_intr

ok martin@
 1.5 26-Oct-2014  martin branches: 1.5.2;
Greatly simplify ioctl handling by fully relying on ether_ioctl and a
ifflags-change callback, together with a shadow copy of the last active
interface flags.
Fix ALLMULTI vs. PROMISC handling.
Fix mac hash filter calculation by reversing the crc bits (pointed out
by Jared).
 1.4 20-Oct-2014  jmcneill add $NetBSD$ to top of files
 1.3 11-Sep-2014  martin Simplify device property handling by moving it into the core driver.
Overriding the MAC address now works again.
 1.2 09-Sep-2014  martin Make the MII clock variable and passed in from the frontend.
 1.1 08-Sep-2014  martin Add work-in-progress driver for the Designware GMAC core, found on some
allwinner chips.
 1.5.2.3 03-Feb-2015  bouyer Pull up following revision(s) (requested by snj in ticket #481):
sys/dev/ic/dwc_gmac_var.h: revision 1.6
sys/dev/ic/dwc_gmac_reg.h: revision 1.13
sys/dev/ic/dwc_gmac.c: revision 1.25
sys/dev/ic/dwc_gmac.c: revision 1.26
sys/dev/ic/dwc_gmac.c: revision 1.28
sys/dev/ic/dwc_gmac.c: revision 1.31
- Add MII flow control support
- Set "disable jabber" and "auto padding/CRC stripping" bits in MAC conf
- Write intr mask to intr mask register, not status
- Setup both TX and RX burst modes
- Setup both TX and RX store & forward modes
- Correct an issue with the "end" descriptor passed to dwc_gmac_txdesc_sync
in dwc_gmac_tx_intr
ok martin@
Revert previous change to dwc_gmac_txintr() - while it looks strange at
first sight (and sorry I didn't spot it when reviewing), it is a small
optimization and actually correct.
Add a comment explaining it.
After handling an interrupt, try to handle more packets as we may have
space in the descriptor ring now.
Pointed out by Jared.
fix a couple txq fencepost issues, from FUKAUMI Naoki <fun@naobsd.org>
 1.5.2.2 09-Nov-2014  snj Pull up following revision(s) (requested by martin in ticket #189):
sys/dev/ic/dwc_gmac.c: revision 1.1-1.24
sys/dev/ic/dwc_gmac_reg.h: revision 1.1-1.12
sys/dev/ic/dwc_gmac_var.h: revision 1.1-1.5
Add support for Synopsis Designware GMAC ethernet core, as found on
various Allwiner boards and used by the awge(4) driver.
 1.5.2.1 26-Oct-2014  snj file dwc_gmac_var.h was added on branch netbsd-7 on 2014-11-09 19:06:57 +0000
 1.6.6.1 21-Apr-2017  bouyer Sync with HEAD
 1.6.4.1 20-Mar-2017  pgoyette Sync with HEAD
 1.6.2.1 12-Jun-2016  skrll First pass at making this driver and attachments NET_MPSAFE aware.

I've not tested this yet.
 1.7.14.4 20-Oct-2018  pgoyette Sync with head
 1.7.14.3 30-Sep-2018  pgoyette Ssync with HEAD
 1.7.14.2 28-Jul-2018  pgoyette Sync with HEAD
 1.7.14.1 25-Jun-2018  pgoyette Sync with HEAD
 1.7.12.2 03-Dec-2017  jdolecek update from HEAD
 1.7.12.1 21-Jan-2017  jdolecek file dwc_gmac_var.h was added on branch tls-maxphys on 2017-12-03 11:37:03 +0000
 1.8.2.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.8.2.1 10-Jun-2019  christos Sync with HEAD
 1.19.2.1 02-Aug-2025  perseant Sync with HEAD
 1.31 09-Feb-2024  skrll Restrict dwcmmc to 32bit DMA (<4GB) regardless of attachment
 1.30 09-Feb-2024  skrll Fix a typo in a comment
 1.29 09-Jan-2022  jmcneill dwcmmc: Add support for card detect using SDMMC_CDETECT register
 1.28 07-Aug-2021  thorpej Merge thorpej-cfargs2.
 1.27 24-Apr-2021  thorpej branches: 1.27.8;
Merge thorpej-cfargs branch:

Simplify and make extensible the config_search() / config_found() /
config_attach() interfaces: rather than having different variants for
which arguments you want pass along, just have a single call that
takes a variadic list of tag-value arguments.

Adjust all call sites:
- Simplify wherever possible; don't pass along arguments that aren't
actually needed.
- Don't be explicit about what interface attribute is attaching if
the device only has one. (More simplification.)
- Add a config_probe() function to be used in indirect configuiration
situations, making is visibly easier to see when indirect config is
in play, and allowing for future change in semantics. (As of now,
this is just a wrapper around config_match(), but that is an
implementation detail.)

Remove unnecessary or redundant interface attributes where they're not
needed.

There are currently 5 "cfargs" defined:
- CFARG_SUBMATCH (submatch function for direct config)
- CFARG_SEARCH (search function for indirect config)
- CFARG_IATTR (interface attribte)
- CFARG_LOCATORS (locators array)
- CFARG_DEVHANDLE (devhandle_t - wraps OFW, ACPI, etc. handles)

...and a sentinel value CFARG_EOL.

Add some extra sanity checking to ensure that interface attributes
aren't ambiguous.

Use CFARG_DEVHANDLE in MI FDT, OFW, and ACPI code, and macppc and shark
ports to associate those device handles with device_t instance. This
will trickle trough to more places over time (need back-end for pre-OFW
Sun OBP; any others?).
 1.26 20-Mar-2020  skrll branches: 1.26.6;
Disable thrctrl or now and note why
 1.25 20-Mar-2020  skrll Remember / use sc_verid
 1.24 20-Mar-2020  skrll Trailing whitespace
 1.23 19-Mar-2020  skrll Release the sc_intr_lock on error
 1.22 23-Jan-2020  jmcneill More SDIO stability and performance fixes
 1.21 22-Jan-2020  jmcneill dwc_mmc fixes:
- Rockchip uses a different SDIO int bit, so take this into consideration
- Avoid unnecessary resets and always wait for resets to complete
- kpause instead of delay while holding spinlock
- Do not attempt autostop for SD_IO_RW_EXTENDED commands
- Allow for sub-blklen byte counts for single block transfers
 1.20 01-Jan-2020  jmcneill branches: 1.20.2;
Fix performance regression with previous
 1.19 01-Jan-2020  jmcneill dwcmmc improvements:
- Use mmcpwrseq resources if available
- Only set 4- or 8-bit mode if specified in the dt properties
- Add quirk for implementations with inverted power enable logic
- Support switching signal voltage between 1.8V and 3.3V
- Fix a clock divider issue on Rockchip SoCs
 1.18 05-Oct-2019  jmcneill Add support for SDIO interrupts.
 1.17 28-Jul-2019  jmcneill branches: 1.17.2;
Fix infinite loop in dwc_mmc_exec_command error path
 1.16 30-Apr-2019  jmcneill Simplify card detect
 1.15 03-Sep-2018  riastradh Rename min/max -> uimin/uimax for better honesty.

These functions are defined on unsigned int. The generic name
min/max should not silently truncate to 32 bits on 64-bit systems.
This is purely a name change -- no functional change intended.

HOWEVER! Some subsystems have

#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))

even though our standard name for that is MIN/MAX. Although these
may invite multiple evaluation bugs, these do _not_ cause integer
truncation.

To avoid `fixing' these cases, I first changed the name in libkern,
and then compile-tested every file where min/max occurred in order to
confirm that it failed -- and thus confirm that nothing shadowed
min/max -- before changing it.

I have left a handful of bootloaders that are too annoying to
compile-test, and some dead code:

cobalt ews4800mips hp300 hppa ia64 luna68k vax
acorn32/if_ie.c (not included in any kernels)
macppc/if_gm.c (superseded by gem(4))

It should be easy to fix the fallout once identified -- this way of
doing things fails safe, and the goal here, after all, is to _avoid_
silent integer truncations, not introduce them.

Maybe one day we can reintroduce min/max as type-generic things that
never silently truncate. But we should avoid doing that for a while,
so that existing code has a chance to be detected by the compiler for
conversion to uimin/uimax without changing the semantics until we can
properly audit it all. (Who knows, maybe in some cases integer
truncation is actually intended!)
 1.14 02-Jul-2018  jmcneill Reduce 10 second timeouts to 2 seconds.
 1.13 19-Jun-2018  jmcneill branches: 1.13.2;
dwcmmc: set ciu clock rate rather than assuming fixed input rate
 1.12 10-Jun-2018  jmcneill If the bus glue does not provide values for fifo reg offset and
fifo depth, try to auto detect based on the chip version and
value already programmed into FIFOTH.
 1.11 19-Jun-2017  jmcneill branches: 1.11.4; 1.11.6;
More or less a rewrite of dwc_mmc, based on awin_mmc, adding DMA support.
 1.10 27-Dec-2015  jmcneill branches: 1.10.10;
remove DWC_MMC_DEBUG
 1.9 27-Dec-2015  jmcneill reduce timeouts, fix clk div calculation
 1.8 26-Dec-2015  jmcneill Dump registers on timeout and allow bus glue to override card detect func
 1.7 09-Aug-2015  jmcneill wait for command done status before doing pio transfer
 1.6 22-Jan-2015  jmcneill branches: 1.6.2;
when resetting controller, dont preserve DWC_MMC_CTRL_REG state. makes this work on my radxa lite
 1.5 17-Jan-2015  jmcneill improve intr reg debugging
 1.4 30-Dec-2014  jmcneill Fix inverted logic of card_detect_n bit, from FUKAUMI Naoki <fun@naobsd.org>.
 1.3 29-Dec-2014  jmcneill - Simplify clock setup
- Add DWC_MMC_F_FORCE_CLK flag, which forces updating clock for each
command (apparently required by Rockchip)
- Let bus glue limit the max clk speed used
 1.2 27-Dec-2014  jmcneill - Explicitly initialize CLKSRC register.
- Reset FIFO and DMA along with controller.
- Support chips with inverted PWREN logic.
- Enable RXDR and TXDR irqs.
- Set max clk based on supplied clock freq.
- Use external clk control as well as internal divisor to set clock rates.
Requires bus glue to implement sc_set_clkdiv callback.
 1.1 27-Dec-2014  jmcneill add DesignWare SD/MMC controller driver
 1.6.2.5 28-Aug-2017  skrll Sync with HEAD
 1.6.2.4 19-Mar-2016  skrll Sync with HEAD
 1.6.2.3 22-Sep-2015  skrll Sync with HEAD
 1.6.2.2 06-Apr-2015  skrll Sync with HEAD
 1.6.2.1 22-Jan-2015  skrll file dwc_mmc.c was added on branch nick-nhusb on 2015-04-06 15:18:09 +0000
 1.10.10.1 18-Jul-2017  snj Pull up following revision(s) (requested by jmcneill in ticket #114):
sys/arch/arm/samsung/exynos_intr.h: revision 1.3
sys/arch/arm/sunxi/sun8i_h3_ccu.c: revision 1.1
sys/arch/arm/sunxi/sun8i_h3_ccu.c: revision 1.2
sys/arch/arm/sunxi/sun8i_h3_ccu.c: revision 1.3
sys/arch/arm/sunxi/sunxi_gates.c: revision 1.1
distrib/utils/embedded/mkimage: revision 1.66
sys/arch/arm/sunxi/sun8i_h3_ccu.c: revision 1.4
sys/arch/arm/sunxi/sunxi_rsb.c: revision 1.1
sys/arch/arm/sunxi/sun8i_h3_ccu.c: revision 1.5
sys/arch/arm/sunxi/sun8i_h3_ccu.c: revision 1.6
sys/arch/arm/sunxi/sun8i_h3_ccu.c: revision 1.7
sys/dev/gpio/gpio.c: revision 1.59
sys/arch/arm/sunxi/sunxi_ccu_prediv.c: revision 1.1
sys/conf/Makefile.kern.inc: revision 1.257
sys/arch/evbarm/conf/ODROID-XU_INSTALL: file removal
sys/arch/arm/sunxi/sunxi_ccu_prediv.c: revision 1.2
sys/conf/Makefile.kern.inc: revision 1.258
sys/arch/arm/fdt/psci_fdt.h: revision 1.1
sys/arch/arm/sunxi/sunxi_resets.c: revision 1.1
sys/arch/evbarm/conf/files.sunxi: revision 1.1
sys/arch/evbarm/fdt/fdt_machdep.c: revision 1.8
sys/arch/evbarm/fdt/fdt_machdep.c: revision 1.9
sys/arch/arm/samsung/files.exynos: revision 1.22
distrib/utils/embedded/conf/armv7.conf: revision 1.13
sys/arch/arm/samsung/files.exynos: revision 1.23
sys/arch/evbarm/conf/std.tegra: revision 1.15
distrib/utils/embedded/conf/armv7.conf: revision 1.14
sys/arch/arm/samsung/files.exynos: revision 1.24
distrib/utils/embedded/conf/armv7.conf: revision 1.15
sys/arch/evbarm/sunxi/genassym.cf: revision 1.1
sys/arch/arm/samsung/exynos_fdt.c: file removal
sys/dev/fdt/fdt_pinctrl.c: revision 1.4
sys/arch/arm/samsung/exynos_sysmmu.c: revision 1.2
sys/arch/arm/sunxi/sun8i_h3_gpio.c: revision 1.1
sys/arch/arm/sunxi/sunxi_twi.c: revision 1.1
sys/dev/usb/ehci.c: revision 1.255
sys/arch/arm/sunxi/sunxi_twi.c: revision 1.2
sys/arch/arm/sunxi/sun8i_a83t_ccu.h: revision 1.1
sys/dev/ic/dwc_mmc.c: revision 1.11
sys/arch/arm/cortex/gic.c: revision 1.24
distrib/evbarm/instkernel/ramdisk/Makefile: revision 1.17
etc/etc.evbarm/Makefile.inc: revision 1.87
etc/etc.evbarm/Makefile.inc: revision 1.88
sys/arch/arm/fdt/gic_fdt.c: revision 1.5
etc/Makefile: revision 1.429
sys/arch/arm/fdt/gic_fdt.c: revision 1.6
sys/arch/arm/fdt/gic_fdt.c: revision 1.7
sys/arch/arm/sunxi/sunxi_gpio.c: revision 1.1
sys/arch/arm/sunxi/sunxi_gpio.c: revision 1.2
sys/arch/evbarm/conf/std.sunxi: revision 1.1
sys/arch/arm/sunxi/sunxi_gpio.c: revision 1.3
sys/arch/evbarm/conf/std.sunxi: revision 1.2
sys/arch/arm/sunxi/sunxi_gpio.c: revision 1.4
sys/arch/evbarm/conf/std.sunxi: revision 1.3
sys/arch/arm/sunxi/sunxi_gpio.c: revision 1.5
sys/arch/arm/sunxi/sunxi_ccu_div.c: revision 1.1
sys/dev/gpio/gpiovar.h: revision 1.17
sys/arch/arm/sunxi/sunxi_gpio.c: revision 1.6
sys/arch/arm/sunxi/sunxi_gpio.c: revision 1.7
sys/arch/arm/sunxi/sunxi_gpio.c: revision 1.8
sys/arch/arm/sunxi/sunxi_rsb.h: revision 1.1
sys/arch/arm/samsung/exynos_i2c.c: revision 1.12
sys/dev/fdt/fdtvar.h: revision 1.21
sys/arch/evbarm/sunxi/sunxi_start.S: revision 1.1
sys/arch/arm/samsung/exynos_i2c.c: revision 1.13
sys/dev/fdt/fdtvar.h: revision 1.22
sys/arch/evbarm/conf/SUNXI: revision 1.10
sys/dev/fdt/fdtvar.h: revision 1.23
sys/arch/evbarm/conf/SUNXI: revision 1.11
sys/dev/fdt/gpioleds.c: revision 1.1
sys/dev/fdt/fdtvar.h: revision 1.24
sys/arch/evbarm/conf/SUNXI: revision 1.12
sys/arch/evbarm/conf/SUNXI: revision 1.13
sys/arch/arm/cortex/gic.c: revision 1.30
sys/arch/evbarm/conf/SUNXI: revision 1.14
sys/arch/evbarm/conf/SUNXI: revision 1.15
sys/arch/evbarm/conf/SUNXI: revision 1.16
sys/arch/arm/sunxi/sunxi_emac.c: revision 1.1
etc/Makefile: revision 1.430
sys/arch/arm/sunxi/sunxi_emac.c: revision 1.2
etc/Makefile: revision 1.431
sys/arch/evbarm/conf/VEXPRESS_A15: revision 1.17
sys/arch/arm/sunxi/sunxi_emac.c: revision 1.3
sys/arch/arm/sunxi/sunxi_emac.c: revision 1.4
sys/arch/arm/samsung/exynos5422_clock.c: revision 1.6
sys/arch/arm/samsung/exynos_platform.c: revision 1.1
sys/dev/ofw/ofw_subr.c: revision 1.29
sys/arch/arm/samsung/exynos_platform.c: revision 1.2
sys/arch/evbarm/conf/mk.vexpress: revision 1.3
sys/arch/arm/samsung/exynos_platform.c: revision 1.3
sys/arch/evbarm/conf/mk.vexpress: revision 1.4
sys/arch/arm/samsung/exynos_platform.c: revision 1.4
sys/arch/arm/arm/psci.h: revision 1.1
sys/arch/arm/samsung/exynos_platform.c: revision 1.5
sys/arch/arm/samsung/exynos_platform.c: revision 1.6
sys/arch/evbarm/fdt/fdt_machdep.c: revision 1.10
external/bsd/mdocml/bin/mandoc/Makefile: revision 1.12
sys/dev/fdt/files.fdt: revision 1.17
sys/dev/fdt/files.fdt: revision 1.18
sys/dev/fdt/files.fdt: revision 1.19
sys/arch/arm/samsung/exynos_sscom.c: revision 1.8
sys/arch/arm/sunxi/sun8i_a83t_ccu.c: revision 1.1
sys/arch/arm/sunxi/sunxi_mmc.c: revision 1.1
sys/arch/arm/samsung/exynos_sscom.c: revision 1.9
sys/arch/arm/conf/files.arm: revision 1.133
sys/arch/arm/samsung/mct_var.h: revision 1.5
sys/arch/arm/sunxi/sunxi_platform.c: revision 1.1
sys/arch/arm/sunxi/sunxi_platform.c: revision 1.2
sys/arch/evbarm/conf/std.vexpress: revision 1.6
sys/arch/arm/sunxi/sunxi_platform.c: revision 1.3
sys/arch/arm/sunxi/sun6i_a31_gpio.c: revision 1.1
sys/arch/arm/sunxi/sunxi_platform.c: revision 1.4
sys/arch/arm/sunxi/sun6i_a31_gpio.c: revision 1.2
sys/arch/arm/sunxi/files.sunxi: revision 1.1
sys/dev/ofw/ofw_subr.c: revision 1.30
sys/arch/arm/sunxi/files.sunxi: revision 1.2
sys/dev/ofw/openfirm.h: revision 1.35
sys/arch/arm/sunxi/files.sunxi: revision 1.3
sys/dev/ofw/openfirm.h: revision 1.36
sys/arch/arm/sunxi/files.sunxi: revision 1.4
sys/arch/arm/sunxi/files.sunxi: revision 1.5
sys/arch/evbarm/exynos/exynos_machdep.c: file removal
sys/arch/arm/sunxi/sunxi_gpio.h: revision 1.1
sys/arch/arm/samsung/sscom.c: revision 1.9
sys/arch/arm/sunxi/files.sunxi: revision 1.6
sys/dev/fdt/ohci_fdt.c: revision 1.1
sys/arch/arm/sunxi/sunxi_usbphy.c: revision 1.1
sys/arch/arm/sunxi/sunxi_gpio.h: revision 1.2
sys/arch/arm/sunxi/files.sunxi: revision 1.7
sys/arch/arm/sunxi/sunxi_usbphy.c: revision 1.2
sys/arch/arm/sunxi/sunxi_gpio.h: revision 1.3
sys/arch/arm/sunxi/files.sunxi: revision 1.8
sys/arch/arm/sunxi/sunxi_usbphy.c: revision 1.3
sys/arch/arm/sunxi/files.sunxi: revision 1.9
sys/arch/arm/samsung/exynos_sscom.c: revision 1.10
sys/arch/evbarm/conf/mk.tegra: revision 1.5
sys/arch/arm/samsung/exynos_dwcmmc.c: revision 1.4
sys/arch/evbarm/conf/mk.tegra: revision 1.6
sys/arch/evbarm/conf/EXYNOS: revision 1.15
sys/arch/evbarm/conf/EXYNOS: revision 1.16
sys/arch/evbarm/conf/EXYNOS: revision 1.17
sys/arch/arm/sunxi/sunxi_ccu.c: revision 1.1
sys/arch/evbarm/conf/EXYNOS: revision 1.19
sys/arch/arm/sunxi/sunxi_ccu.c: revision 1.2
sys/arch/arm/sunxi/sunxi_ccu.c: revision 1.3
sys/arch/arm/sunxi/sunxi_ccu.c: revision 1.4
sys/arch/arm/sunxi/sunxi_ccu.c: revision 1.5
sys/arch/arm/sunxi/sunxi_emac.h: revision 1.1
sys/arch/evbarm/conf/mk.sunxi: revision 1.1
sys/arch/evbarm/include/bootconfig.h: revision 1.7
sys/arch/evbarm/conf/TEGRA: revision 1.24
sys/arch/arm/arm/psci.c: revision 1.1
sys/dev/led.c: revision 1.1
sys/dev/led.c: revision 1.2
sys/arch/arm/arm/psci_arm.S: revision 1.1
sys/arch/arm/sunxi/sunxi_ccu_gate.c: revision 1.1
sys/arch/arm/sunxi/sunxi_ccu_gate.c: revision 1.2
sys/dev/fdt/ehci_fdt.c: revision 1.1
sys/dev/fdt/ehci_fdt.c: revision 1.2
sys/arch/arm/sunxi/sun6i_a31_ccu.h: revision 1.1
sys/arch/evbarm/conf/EXYNOS: revision 1.21
sys/arch/arm/sunxi/files.sunxi: revision 1.10
sys/arch/arm/sunxi/files.sunxi: revision 1.11
sys/dev/fdt/fdtbus.c: revision 1.14
sys/arch/arm/sunxi/sunxi_mmc.h: revision 1.1
sys/arch/arm/samsung/exynos5422_dma.c: file removal
usr.bin/config/mkmakefile.c: revision 1.69
sys/conf/files: revision 1.1178
sys/arch/arm/sunxi/sunxi_platform.h: revision 1.1
sys/arch/evbarm/exynos/exynos_start.S: revision 1.4
sys/arch/arm/samsung/exynos_pinctrl.c: revision 1.11
sys/arch/arm/samsung/exynos_pinctrl.c: revision 1.12
sys/arch/arm/sunxi/sunxi_rtc.c: revision 1.1
sys/arch/arm/sunxi/sun8i_h3_ccu.h: revision 1.1
sys/arch/arm/samsung/exynos5410_clock.c: revision 1.1
sys/arch/arm/samsung/exynos5410_clock.c: revision 1.2
sys/arch/evbarm/conf/SUNXI: revision 1.1
external/bsd/elftosb/usr.sbin/elftosb/Makefile: revision 1.5
sys/arch/evbarm/conf/SUNXI: revision 1.2
sys/arch/arm/fdt/psci_fdt.c: revision 1.1
sys/arch/evbarm/conf/SUNXI: revision 1.3
sys/arch/evbarm/conf/SUNXI: revision 1.4
sys/arch/evbarm/conf/files.exynos: revision 1.3
sys/arch/evbarm/conf/SUNXI: revision 1.5
sys/arch/evbarm/conf/SUNXI: revision 1.6
sys/arch/arm/sunxi/sunxi_ccu_nm.c: revision 1.1
sys/dev/fdt/fixedfactorclock.c: revision 1.1
sys/dev/fdt/fdt_subr.c: revision 1.14
sys/arch/evbarm/conf/SUNXI: revision 1.7
sys/arch/arm/sunxi/sunxi_ccu_nm.c: revision 1.2
sys/arch/arm/sunxi/sun8i_a83t_gpio.c: revision 1.1
sys/dev/fdt/fdt_subr.c: revision 1.15
sys/arch/evbarm/conf/SUNXI: revision 1.8
sys/arch/arm/sunxi/sunxi_ccu_nm.c: revision 1.3
sys/dev/ic/dwc_mmc_reg.h: revision 1.6
sys/dev/fdt/fdt_subr.c: revision 1.16
sys/arch/evbarm/conf/SUNXI: revision 1.9
usr.bin/config/mkmakefile.c: revision 1.70
sys/dev/fdt/fdt_phy.c: revision 1.1
sys/arch/evbarm/conf/ODROID-XU: file removal
sys/arch/arm/fdt/arm_fdt.c: revision 1.4
sys/arch/arm/samsung/exynos_reg.h: revision 1.14
sys/conf/files: revision 1.1180
sys/arch/arm/samsung/exynos_reg.h: revision 1.15
sys/arch/arm/sunxi/sunxi_ccu.h: revision 1.1
sys/arch/arm/sunxi/sunxi_ccu.h: revision 1.2
sys/arch/arm/sunxi/sunxi_ccu.h: revision 1.3
sys/arch/arm/sunxi/sunxi_ccu.h: revision 1.4
sys/arch/arm/sunxi/sunxi_ccu.h: revision 1.5
sys/arch/arm/sunxi/sunxi_ccu.h: revision 1.6
sys/dev/ic/dwc_mmc_var.h: revision 1.6
sys/arch/arm/samsung/exynos_combiner.c: revision 1.7
sys/arch/evbarm/exynos/platform.h: revision 1.2
sys/arch/arm/fdt/files.fdt: revision 1.12
sys/arch/evbarm/conf/std.exynos: revision 1.2
sys/arch/evbarm/conf/std.exynos: revision 1.3
sys/arch/arm/rockchip/rockchip_dwcmmc.c: revision 1.6
sys/arch/arm/sunxi/sunxi_com.c: revision 1.1
sys/dev/led.h: revision 1.1
sys/arch/evbarm/conf/std.exynos: revision 1.5
sys/arch/arm/sunxi/sunxi_com.c: revision 1.2
sys/arch/evbarm/conf/files.evbarm: revision 1.26
usr.bin/config/defs.h: revision 1.99
sys/arch/arm/fdt/arm_fdtvar.h: revision 1.6
sys/arch/arm/samsung/exynos_soc.c: revision 1.32
sys/arch/arm/sunxi/sun6i_a31_ccu.c: revision 1.1
sys/arch/arm/sunxi/sun6i_a31_ccu.c: revision 1.2
sys/arch/arm/samsung/mct.c: revision 1.11
sys/arch/evbarm/conf/ODROID-U: file removal
sys/arch/arm/samsung/mct.c: revision 1.12
sys/arch/arm/sunxi/sunxi_ccu_nkmp.c: revision 1.1
sys/arch/arm/sunxi/sunxi_ccu_nkmp.c: revision 1.2
sys/arch/arm/sunxi/sunxi_ccu_nkmp.c: revision 1.3
sys/arch/arm/sunxi/sunxi_ccu_nkmp.c: revision 1.4
Get the EXYNOS kernel building again with recent FDT changes. Untested.
Use arm_fdt_cpu_hatch and add mmu entry for DTB
Fix exynos5 devmap, bootstrap, and implement early_putchar.
Calculate UART frequency based on bootloader config.
Fix KERNEL_BASE_PHYS (how did this ever work?)
Avoid divide-by-zero for unconfigured PLLs
Correctly initialize i2cbus attach args.
Add delay and enable mct timecounter.
Fix build w/o VERBOSE_INIT_ARM
Remove ODROID-U and ODROID-XU kernel configs as they no longer work.
- Replace CONSADDR with SSCOM2CONSOLE in example
- Remove gtmr (Exynos5422 uses mct)
- cinclude EXYNOS.local instead of TEGRA.local
Use fdtbus_intr_establish to hook in block interrupts instead of
intr_establish.
Simplify MCT; just enable it and then attach an ARMv7 generic timer.
Add support for building DTB files during kernel build, from christos.
build vexpress-v2p-ca15-tc1.dtb with the kernel
build tegra124-apalis-eval.dtb, tegra124-jetson-tk1.dtb, tegra124-nyan-big.dtb, tegra124-nyan-blaze.dtb, and tegra124-venice2.dtb with the kernel
Allow multiline makeoptions to work by quoting the newline..
Bump for quoting makeoptions with multiple lines.
un-c99
bump required config version for multiline makeoptions feature
Set DTS makeoption in kernel config
Assign DTB files to a variable so we can make -V DTB
put the dtb files with their kernels.
no need for debug printing.
Don't assume that CPU index = GIC CPU interface number. We can determine
the current CPU interface number by reading from the read-only
GICD_ITARGETSR0 through GICD_ITARGETSR7 registers.
This gets interrupts working on Exynos 5422, where the boot processor has
GIC CPU interface #4.
use -v to get the expanded variable.
Use -v to get the expanded variables.
Get baud rate from sclk_uartN instead of uartN. Print IRQ number at attach.
Fix PLL con0 register locations and add uart clocks
Disable exyortc for now, it doesn't work.
More or less a rewrite of dwc_mmc, based on awin_mmc, adding DMA support.
Update for new dwc_mmc driver
Fix dmesg
Add Exynos 5410 clock controller driver.
Fix a few typos in clock parent names for mmc clocks.
From jmcneill@
Update for new dwc_mmc driver
Implement platform reset for exynos5
Attach fdtbus to a /clocks node with no compatible string.
Add support for ARM Power State Coordination Interface (PSCI).
Support interrupt sharing.
Add initial support for Allwinner H3 SoC.
ARM Trusted Firmware reserves SGIs 8-15 for secure use. Even without ATF,
U-Boot on some platforms may use SGIs in this range for the PSCI
implementation.
Change ARMGIC_IPI_BASE to 0 from (16 - NIPI) and add a compile-time assert
to ensure that we don't end up with a conflict.
Add H3 MMC support
SD/MMC clock fixes
Add FDT PHY interface.
Add glue for generic ehci/ohci bindings.
Rename a variable, NFC.
Support parents in different clock domains.
Add USB stuff. Doesn't quite work yet.
Synopsys DesignWare APB UART needs "options COM_AWIN" for now.
Add i2c glue.
Add RTC driver.
PHY registers start at index 1. Now USB works.
Don't allow sharing edge and level triggered interrupts.
Add arm_fdt_memory_dump helper for dumping physical addresses from ddb
Print clocks with aprint_debug
Remove unused defines
Add fdtbus_get_string helper
Add of_search_compatible, which searches an array of compat_data structures
for a matching "compatible" entry matching the supplied OFW node. This
allows us to associate data with compatible strings.
Add driver for Allwinner Gigabit Ethernet (EMAC) as found in sun8i and
later family SoCs.
This is a port of my FreeBSD driver which has been confirmed to work on
Allwinner H3, A83T, and A64 SoCs.
Fix dmesg
Add basic support for Allwinner A31.
Add basic FDT GPIO support.
Fix the pinctrl api to match the spec. A pinctrl config can have more
than one xref, and an xref may have specifier data associated with it.
Enable sunxi pinctrl support
Adjust to new pinctrl API
Add P2WI/RSB driver, based on awin_p2wi.c.
Fix typo in a compat string.
Configure pin defaults at attach
No need to explicitly set pinctrl config 0 now
Fix some register definitions.
Disallow sharing between MPSAFE and non-MPSAFE handlers.
Add of_match_compat_data.
This routine searches an array of compat_data structures for a
matching "compatible" entry matching the supplied OFW node.
Add options __HAVE_CPU_UAREA_ALLOC_IDLELWP
Add support for reserved memory and MEMORY_DISK_DYNAMIC for FDT-based
kernels.
the extent code cannot use the full range of u_long,
so ignore the last page before 4GB too. ok jmcneill@
Copy install ramdisk to releasedir. Provide both a raw ffs and
Legacy U-Boot version of it.
Replace HUMMINGBIRD_A31 with SUNXI kernel on armv7.img and include .dtb
files for SUNXI and TEGRA kernels on the MSDOS partition.
Let the controller provide a default name for pins. This makes pins easier
to locate when we have multiple banks and a variable number of pins per
bank.
Attach gpio(4) to sunxigpio
Test for kernel build directory before reading DTB list
Add support for Allwinner A83T SoC.
Add A83T files
Fixup busdma sync and locking in the RX path. Disable batch RX/TX ints.
Fix AHB2 register definition and explicitly set AHB2 parent to PLL_PERIPH0/2 -- this gives us 50% more bus bandwidth for emac
Restore TX_INTERVAL_DEFAULT to 64
Drop the sunxi_emac_rx_batch feature. It was originally designed to
reduce the amount of mutex unlock/lock cycles during the RX path on
FreeBSD and if_input, but it is not required to drop the lock before
calling if_percpuq_enqueue on NetBSD.
Write back the data value instead of mask in sunxi_gpio_write
Add a helper for exposing LED controls via sysctl.
Add GPIO LED driver.
add gpioleds
Add misc. gates and resets driver, and explicitly enable PIO clocks
at attach.
Add fdtbus_get_string_index helper.
Add driver for fixed-factor clocks.
Add ffclock
Remove the requirement for ehci to attach after companion devices.
"go for it" - skrll@
Remove the hack to find companion devices and just assume 1 companion if
ETTF flag is not set.
Remove pass numbers for ehci/ohci now that the attach order no longer matters
Use unsigned char for ctype functions, suggested by christos
Add : to body of populate_sunxi to appease bash.
port-evbarm/52388: Fix number of args to a debug printf.
 1.11.6.3 06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.11.6.2 28-Jul-2018  pgoyette Sync with HEAD
 1.11.6.1 25-Jun-2018  pgoyette Sync with HEAD
 1.11.4.2 03-Dec-2017  jdolecek update from HEAD
 1.11.4.1 19-Jun-2017  jdolecek file dwc_mmc.c was added on branch tls-maxphys on 2017-12-03 11:37:03 +0000
 1.13.2.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.13.2.1 10-Jun-2019  christos Sync with HEAD
 1.17.2.3 21-Mar-2020  martin Pull up following revision(s) (requested by skrll in ticket #800):

sys/dev/ic/dwc_mmc_var.h: revision 1.14
sys/dev/ic/dwc_mmc_reg.h: revision 1.10
sys/dev/ic/dwc_mmc.c: revision 1.23
sys/dev/ic/dwc_mmc.c: revision 1.24
sys/dev/ic/dwc_mmc.c: revision 1.25
sys/dev/ic/dwc_mmc.c: revision 1.26

Release the sc_intr_lock on error

Trailing whitespace

Add DWC_MMC_VERID_280A

Remember / use sc_verid

Disable thrctrl or now and note why
 1.17.2.2 25-Feb-2020  martin Pull up following revision(s) (requested by mrg in ticket #717):

sys/dev/fdt/dwcmmc_fdt.c 1.11
sys/dev/ic/bwfm.c 1.15-1.18
sys/dev/ic/bwfmreg.h 1.4-1.6
sys/dev/ic/bwfmvar.h 1.4,1.5
sys/dev/ic/dwc_mmc.c 1.21,1.22
sys/dev/ic/dwc_mmc_reg.h 1.8,1.9,1.12,1.13
sys/dev/pcmcia/pcmciareg.h 1.11
sys/dev/sdmmc/if_bwfm_sdio.c 1.4,1.6-1.12
sys/dev/sdmmc/if_bwfm_sdio.h 1.1,1.2
sys/dev/sdmmc/sdhc.c 1.105,1.106
sys/dev/sdmmc/sdmmc.c 1.37,1.39
sys/dev/sdmmc/sdmmc_cis.c 1.6,1.8
sys/dev/sdmmc/sdmmc_io.c 1.15-1.19
sys/dev/sdmmc/sdmmc_ioreg.h 1.4,1.5
sys/dev/sdmmc/sdmmc_mem.c 1.69-1.71
sys/dev/sdmmc/sdmmcdevs 1.5-1.8
sys/dev/sdmmc/sdmmcvar.h 1.31,1.33,1.34
sys/net/if_media.h 1.66

Add Broadcom devices
-
Fix typo
-
add PCMCIA_CISTPL_SDIO definition.
-
From OpenBSD:
- move event handling to workqueue
- check for save/restore capability
-
Tag work queue as MPsafe and increase length.
-
Juse use bpf_mtap(), the 802.11 encapsulation is handled by firmware.
-
From OpenBSD:
- support block length per function
- add functions to read/write regions
-
Decode (but not use) SDIO tuple in CIS.
-
Fix locking.
-
Add more SDIO defines (partially from version 3.0).
-
From OpenBSD:
- All the missing pieces (firmware load, chip setup, protocol handling)
TX queue and interrupt handling via sdmmc_task.
-
Fix locking.
-
Fix packet parsing.
-
Add parser for original firmware config files.
-
tagging work queue as MPSAFE was premature. Revert.
-
SD_IO_RW_EXTENDED is a data transfer command, so set ADTC flag instead of AC
Use correct function to verify if a task has been queued. Avoids race
that can corrupt the task queue.
-
More register definitions.
-
Add IFM_IEEE80211_VHT subtype, IFM_IEEE80211_11AC operating mode, and missing descriptions
-
If firmware is connected in HT or VHT mode, report it to SIOCGIFMEDIA
-
white space police.

Skip setting power when the voltage doesn't change.
Also increase some timeouts.
-
Add and use sdmmc_pause to avoid long-term busy waits.
-
Add sdio abort function.
-
Additional error messages.
-
Print parameters for SDIO devices.
-
Minor cosmetics.
-
Simplyfy sdmmc_io_set_blocklen function signature by dropping the
extra softc pointer. Aligns with OpenBSD.
-
Missing commit for sdio abort function.
-
More code from OpenBSD
-
no need to splnet() when enqueing packets
-
explicit structure padding
-
make internal functions static
-
also prepare for GPIO interrupts.
-
Avoid warnings for tautological shifts as sole conditional.
-
Follow the Linux driver an use the FDT "compatible" property to build a
filename for the nvram config file, fall back to the standard filename.
E.g.
[Caching 123 nodes and 1093 properties]
compatible 73696e6f 766f6970 2c627069 2d6d322d "sinovoip,bpi-m2-
0010: 7a65726f 00...... ........ ........ zero"
0015: 616c6c77 696e6e65 722c7375 6e38692d "allwinner,sun8i-
0025: 68322d70 6c757300 ........ ........ h2-plus"
interrupt-parent 00000001 ........ ........ ........ ....
model 42616e61 6e612050 69204250 492d4d32 "Banana Pi BPI-M2
0010: 2d5a6572 6f00.... ........ ........ -Zero"
name 00...... ........ ........ ........ ""
serial-number 30326330 30303432 65636431 36376566 02c00042ecd167ef
0010: 00...... ........ ........ ........ .
-rw-r--r-- 1 root wheel 875 Nov 2 12:06 brcmfmac43430-sdio.AP6212.txt
lrwxr-xr-x 1 root wheel 29 Dec 30 16:19 brcmfmac43430-sdio.sinovoip,bpi-m2-zero.txt -> brcmfmac43430-sdio.AP6212.txt
-rw-r--r-- 1 root wheel 874 Jun 30 2019 brcmfmac43430-sdio.raspberrypi,3-model-b.txt
-rw-r--r-- 1 root wheel 1864 Jun 30 2019 brcmfmac43455-sdio.raspberrypi,3-model-b-plus.txt
lrwxr-xr-x 1 root wheel 29 Dec 30 11:24 brcmfmac43455-sdio.raspberrypi,4-model-b-plus.txt -> brcmfmac43455-sdio.raspberrypi,3-model-b-plus.txt
-
Add product ID for Broadcom BCM43455
-
Use correct firmware for BCM43456
-
size check was backwards.
-
Be less noisy for some commands.
-
Fix DWC_MMC_INT_SDIO_INT bit
-
dwc_mmc fixes:
- Rockchip uses a different SDIO int bit, so take this into consideration
- Avoid unnecessary resets and always wait for resets to complete
- kpause instead of delay while holding spinlock
- Do not attempt autostop for SD_IO_RW_EXTENDED commands
- Allow for sub-blklen byte counts for single block transfers
-
More SDIO stability and performance fixes
 1.17.2.1 21-Jan-2020  martin Pull up following revision(s) (requested by mrg in ticket #616):

sys/dev/ic/anx_dp.c: revision 1.2
sys/arch/evbarm/conf/GENERIC64: revision 1.126
sys/dev/ic/anx_dp.h: revision 1.1
sys/arch/evbarm/conf/GENERIC64: revision 1.128
sys/dev/ic/anx_dp.h: revision 1.2
sys/dev/fdt/dwcmmc_fdt.c: revision 1.9
sys/dev/i2c/cwfg.c: revision 1.1
sys/conf/files: revision 1.1247
sys/dev/fdt/pwm_backlight.c: revision 1.5
sys/dev/fdt/pwm_backlight.c: revision 1.6
sys/arch/arm/rockchip/rk3399_cru.c: revision 1.14
sys/arch/arm/rockchip/rk3399_cru.c: revision 1.15
sys/arch/arm/rockchip/rk3399_cru.c: revision 1.16
sys/arch/arm/rockchip/rk3399_cru.c: revision 1.17
sys/dev/ic/dwc_mmc.c: revision 1.20
sys/arch/arm/rockchip/rk3399_cru.c: revision 1.18
sys/arch/arm/rockchip/rk3399_cru.c: revision 1.19
sys/dev/usb/usbdevs: revision 1.775
sys/arch/arm/rockchip/rk_dwhdmi.c: revision 1.4
sys/dev/fdt/simple_amplifier.c: revision 1.1
sys/dev/i2c/files.i2c: revision 1.105
sys/arch/evbarm/conf/GENERIC64: revision 1.117
sys/arch/evbarm/conf/GENERIC64: revision 1.118
sys/dev/i2c/files.i2c: revision 1.107
sys/dev/fdt/files.fdt: revision 1.49
sys/arch/arm/rockchip/rk_anxdp.c: revision 1.1
sys/dev/ic/dwc_mmc_var.h: revision 1.9
sys/dev/i2c/rkpmic.c: revision 1.4
sys/arch/arm/rockchip/rk_anxdp.c: revision 1.2
sys/dev/i2c/rkpmic.c: revision 1.5
sys/dev/i2c/rkpmic.c: revision 1.6
sys/arch/arm/rockchip/rk_vop.c: revision 1.4
sys/arch/arm/rockchip/rk_vop.c: revision 1.5
sys/dev/i2c/rkpmic.c: revision 1.8
sys/arch/arm/dts/rk3399-pinebook-pro.dts: revision 1.1
sys/dev/usb/ums.c: revision 1.96 (via patch)
sys/arch/arm/rockchip/rk_pwm.c: revision 1.3
sys/arch/arm/dts/rk3399-pinebook-pro.dts: revision 1.2
sys/dev/i2c/es8316ac.c: revision 1.1
sys/dev/fdt/dwcmmc_fdt.c: revision 1.10
sys/dev/i2c/es8316ac.c: revision 1.2
sys/dev/fdt/fdt_panel.c: revision 1.1
sys/dev/ic/dwc_mmc.c: revision 1.18
sys/dev/fdt/fdt_panel.c: revision 1.2
sys/dev/ic/dwc_mmc.c: revision 1.19
sys/arch/arm/dts/rk3399-rockpro64.dts: revision 1.10
sys/dev/fdt/fdt_port.c: revision 1.5
sys/dev/ic/dwc_mmc_var.h: revision 1.10
sys/dev/fdt/fdt_port.c: revision 1.6
sys/arch/evbarm/conf/GENERIC64: revision 1.122
sys/dev/ic/dwc_mmc_var.h: revision 1.11
sys/dev/fdt/files.fdt: revision 1.50
sys/arch/evbarm/conf/GENERIC64: revision 1.123
sys/arch/arm/rockchip/rk_i2s.c: revision 1.2
sys/arch/arm/rockchip/files.rockchip: revision 1.23
sys/arch/evbarm/conf/GENERIC64: revision 1.124
sys/dev/ic/anx_dp.c: revision 1.1

rkpmic: add RTC support; register w/ todr(9)
rkpmic: correct delay
Add support for SDIO interrupts.
fix copy/paste error in mux_pll_src_cpll_gpll_ppll_parents[]
add RK3399 eDP clocks
add RK3399 DisplayPort clocks
style fix/KNF
rk3399_cru: implement dclk_vop0_frac and dclk_vop1_frac
Move drm_encoder from rkvop(4) to the SoC-layer output pipe drivers (rk_dwhdmi).
rkvop: set stride using virtual framebuffer width instead of display mode
rk3399_cru: Reparent dclk_vop[01] to gpll via dclk_vop[01]_frac.
The previous source of dclk_vop[01] was vpll via dclk_vop[01]_div.
vpll is apparently used directly as a pixel clock source for the
HDMI PHY, and we don't want the other VOP's dclk changing out from
under it because we can't handle finding a replacement clock source
with the right rate yet.
gpll happens to run at 594MHz, which works well as a basis for pixel
clocks.
Linux suggests that the source clock of the fractional divider needs
to be more than twenty times greater than the resulting clock (or some
intermediate clock?) for output stability. This may not be the case
with 594MHz and the common pixel clocks I see used by displays in my
area of the wild, but it works for now.
add Analogix DisplayPort core driver
add Rockchip (RK3399) glue for Analogix DisplayPort core
add anxdp(4)
Add another panel@fdt driver, this time for DRM-style panels.
To do: migrate away from other panel driver.
enable panel at fdt drivers
paper over the rkpwm get_conf function that otherwise doesn't seem to
let things work
add template bits for optional eDP panel on RockPro64
Abort panel driver attach if required regulator is missing.
Add clk provider
Add Pinebook Pro dts, from Manjaro Linux.
https://gitlab.manjaro.org/tsys/linux-pinebook-pro/blob/877ca0e7283596f37845de50dc36bff5b88b91e1/arch/arm64/boot/dts/rockchip/rk3399-pinebook-pro.dts
+ rk3399-pinebook-pro.dts
Attach mmcpwrseq resource earlier
dwcmmc improvements:
- Use mmcpwrseq resources if available
- Only set 4- or 8-bit mode if specified in the dt properties
- Add quirk for implementations with inverted power enable logic
- Support switching signal voltage between 1.8V and 3.3V
- Fix a clock divider issue on Rockchip SoCs
Fix performance regression with previous
Quiet chatty printfs
No need to print all supported levels at attach, print the range and total number of steps
Disable SPI for now (rkspi driver hangs at boot)
Add driver for simple-audio-amplifier binding
Add driver for Everest Semi ES8316 Low Power Audio CODEC
add es8316, simpleamp
Avoid sleeping while the audio intr lock is held.
If the rockchip,system-power-controller property is present, try to power off with the PMIC
Add HAILUCK keyboard (product 1e)
Add a quirk for the HAILUCK USB keyboard / touchpad device with product 1e.
The keyboard does not function properly unless the touchpad's intr endpoint
is active.
Add driver for CellWise CW2015 Fuel Gauge IC.
add cwfg
Emit PMFE_DISPLAY_{ON,OFF} events in response to DPMS requests.
If the backlight node does not have an enable gpio, set the lowest duty
cycle to turn the display off instead.
Attach psci as early as possible. This allows other power controllers to
register their own poweroff / reset callbacks with a higher preference.
Add 2000 MHz to available armclkb rates
Remove debug printfs
 1.20.2.1 25-Jan-2020  ad Sync with head.
 1.26.6.1 21-Mar-2021  thorpej Give config_found() the same variadic arguments treatment as
config_search(). This commit only adds the CFARG_EOL sentinel
to the existing config_found() calls. Conversion of config_found_sm_loc()
and config_found_ia() call sites will be in subsequent commits.
 1.27.8.1 04-Aug-2021  thorpej Adapt to CFARGS().
 1.11 09-Jan-2022  jmcneill dwcmmc: Add support for card detect using SDMMC_CDETECT register
 1.10 20-Mar-2020  skrll Add DWC_MMC_VERID_280A
 1.9 22-Jan-2020  jmcneill dwc_mmc fixes:
- Rockchip uses a different SDIO int bit, so take this into consideration
- Avoid unnecessary resets and always wait for resets to complete
- kpause instead of delay while holding spinlock
- Do not attempt autostop for SD_IO_RW_EXTENDED commands
- Allow for sub-blklen byte counts for single block transfers
 1.8 22-Jan-2020  jmcneill Fix DWC_MMC_INT_SDIO_INT bit
 1.7 16-Jun-2018  jmcneill branches: 1.7.2; 1.7.8; 1.7.10;
Add VERID reg bits
 1.6 19-Jun-2017  jmcneill branches: 1.6.4; 1.6.6;
More or less a rewrite of dwc_mmc, based on awin_mmc, adding DMA support.
 1.5 27-Dec-2015  jmcneill branches: 1.5.10;
add some extra regs
 1.4 17-Jan-2015  jmcneill branches: 1.4.2;
fix previous
 1.3 17-Jan-2015  jmcneill improve intr reg debugging
 1.2 27-Dec-2014  jmcneill - Explicitly initialize CLKSRC register.
- Reset FIFO and DMA along with controller.
- Support chips with inverted PWREN logic.
- Enable RXDR and TXDR irqs.
- Set max clk based on supplied clock freq.
- Use external clk control as well as internal divisor to set clock rates.
Requires bus glue to implement sc_set_clkdiv callback.
 1.1 27-Dec-2014  jmcneill add DesignWare SD/MMC controller driver
 1.4.2.4 28-Aug-2017  skrll Sync with HEAD
 1.4.2.3 19-Mar-2016  skrll Sync with HEAD
 1.4.2.2 06-Apr-2015  skrll Sync with HEAD
 1.4.2.1 17-Jan-2015  skrll file dwc_mmc_reg.h was added on branch nick-nhusb on 2015-04-06 15:18:09 +0000
 1.5.10.1 18-Jul-2017  snj Pull up following revision(s) (requested by jmcneill in ticket #114):
sys/arch/arm/samsung/exynos_intr.h: revision 1.3
sys/arch/arm/sunxi/sun8i_h3_ccu.c: revision 1.1
sys/arch/arm/sunxi/sun8i_h3_ccu.c: revision 1.2
sys/arch/arm/sunxi/sun8i_h3_ccu.c: revision 1.3
sys/arch/arm/sunxi/sunxi_gates.c: revision 1.1
distrib/utils/embedded/mkimage: revision 1.66
sys/arch/arm/sunxi/sun8i_h3_ccu.c: revision 1.4
sys/arch/arm/sunxi/sunxi_rsb.c: revision 1.1
sys/arch/arm/sunxi/sun8i_h3_ccu.c: revision 1.5
sys/arch/arm/sunxi/sun8i_h3_ccu.c: revision 1.6
sys/arch/arm/sunxi/sun8i_h3_ccu.c: revision 1.7
sys/dev/gpio/gpio.c: revision 1.59
sys/arch/arm/sunxi/sunxi_ccu_prediv.c: revision 1.1
sys/conf/Makefile.kern.inc: revision 1.257
sys/arch/evbarm/conf/ODROID-XU_INSTALL: file removal
sys/arch/arm/sunxi/sunxi_ccu_prediv.c: revision 1.2
sys/conf/Makefile.kern.inc: revision 1.258
sys/arch/arm/fdt/psci_fdt.h: revision 1.1
sys/arch/arm/sunxi/sunxi_resets.c: revision 1.1
sys/arch/evbarm/conf/files.sunxi: revision 1.1
sys/arch/evbarm/fdt/fdt_machdep.c: revision 1.8
sys/arch/evbarm/fdt/fdt_machdep.c: revision 1.9
sys/arch/arm/samsung/files.exynos: revision 1.22
distrib/utils/embedded/conf/armv7.conf: revision 1.13
sys/arch/arm/samsung/files.exynos: revision 1.23
sys/arch/evbarm/conf/std.tegra: revision 1.15
distrib/utils/embedded/conf/armv7.conf: revision 1.14
sys/arch/arm/samsung/files.exynos: revision 1.24
distrib/utils/embedded/conf/armv7.conf: revision 1.15
sys/arch/evbarm/sunxi/genassym.cf: revision 1.1
sys/arch/arm/samsung/exynos_fdt.c: file removal
sys/dev/fdt/fdt_pinctrl.c: revision 1.4
sys/arch/arm/samsung/exynos_sysmmu.c: revision 1.2
sys/arch/arm/sunxi/sun8i_h3_gpio.c: revision 1.1
sys/arch/arm/sunxi/sunxi_twi.c: revision 1.1
sys/dev/usb/ehci.c: revision 1.255
sys/arch/arm/sunxi/sunxi_twi.c: revision 1.2
sys/arch/arm/sunxi/sun8i_a83t_ccu.h: revision 1.1
sys/dev/ic/dwc_mmc.c: revision 1.11
sys/arch/arm/cortex/gic.c: revision 1.24
distrib/evbarm/instkernel/ramdisk/Makefile: revision 1.17
etc/etc.evbarm/Makefile.inc: revision 1.87
etc/etc.evbarm/Makefile.inc: revision 1.88
sys/arch/arm/fdt/gic_fdt.c: revision 1.5
etc/Makefile: revision 1.429
sys/arch/arm/fdt/gic_fdt.c: revision 1.6
sys/arch/arm/fdt/gic_fdt.c: revision 1.7
sys/arch/arm/sunxi/sunxi_gpio.c: revision 1.1
sys/arch/arm/sunxi/sunxi_gpio.c: revision 1.2
sys/arch/evbarm/conf/std.sunxi: revision 1.1
sys/arch/arm/sunxi/sunxi_gpio.c: revision 1.3
sys/arch/evbarm/conf/std.sunxi: revision 1.2
sys/arch/arm/sunxi/sunxi_gpio.c: revision 1.4
sys/arch/evbarm/conf/std.sunxi: revision 1.3
sys/arch/arm/sunxi/sunxi_gpio.c: revision 1.5
sys/arch/arm/sunxi/sunxi_ccu_div.c: revision 1.1
sys/dev/gpio/gpiovar.h: revision 1.17
sys/arch/arm/sunxi/sunxi_gpio.c: revision 1.6
sys/arch/arm/sunxi/sunxi_gpio.c: revision 1.7
sys/arch/arm/sunxi/sunxi_gpio.c: revision 1.8
sys/arch/arm/sunxi/sunxi_rsb.h: revision 1.1
sys/arch/arm/samsung/exynos_i2c.c: revision 1.12
sys/dev/fdt/fdtvar.h: revision 1.21
sys/arch/evbarm/sunxi/sunxi_start.S: revision 1.1
sys/arch/arm/samsung/exynos_i2c.c: revision 1.13
sys/dev/fdt/fdtvar.h: revision 1.22
sys/arch/evbarm/conf/SUNXI: revision 1.10
sys/dev/fdt/fdtvar.h: revision 1.23
sys/arch/evbarm/conf/SUNXI: revision 1.11
sys/dev/fdt/gpioleds.c: revision 1.1
sys/dev/fdt/fdtvar.h: revision 1.24
sys/arch/evbarm/conf/SUNXI: revision 1.12
sys/arch/evbarm/conf/SUNXI: revision 1.13
sys/arch/arm/cortex/gic.c: revision 1.30
sys/arch/evbarm/conf/SUNXI: revision 1.14
sys/arch/evbarm/conf/SUNXI: revision 1.15
sys/arch/evbarm/conf/SUNXI: revision 1.16
sys/arch/arm/sunxi/sunxi_emac.c: revision 1.1
etc/Makefile: revision 1.430
sys/arch/arm/sunxi/sunxi_emac.c: revision 1.2
etc/Makefile: revision 1.431
sys/arch/evbarm/conf/VEXPRESS_A15: revision 1.17
sys/arch/arm/sunxi/sunxi_emac.c: revision 1.3
sys/arch/arm/sunxi/sunxi_emac.c: revision 1.4
sys/arch/arm/samsung/exynos5422_clock.c: revision 1.6
sys/arch/arm/samsung/exynos_platform.c: revision 1.1
sys/dev/ofw/ofw_subr.c: revision 1.29
sys/arch/arm/samsung/exynos_platform.c: revision 1.2
sys/arch/evbarm/conf/mk.vexpress: revision 1.3
sys/arch/arm/samsung/exynos_platform.c: revision 1.3
sys/arch/evbarm/conf/mk.vexpress: revision 1.4
sys/arch/arm/samsung/exynos_platform.c: revision 1.4
sys/arch/arm/arm/psci.h: revision 1.1
sys/arch/arm/samsung/exynos_platform.c: revision 1.5
sys/arch/arm/samsung/exynos_platform.c: revision 1.6
sys/arch/evbarm/fdt/fdt_machdep.c: revision 1.10
external/bsd/mdocml/bin/mandoc/Makefile: revision 1.12
sys/dev/fdt/files.fdt: revision 1.17
sys/dev/fdt/files.fdt: revision 1.18
sys/dev/fdt/files.fdt: revision 1.19
sys/arch/arm/samsung/exynos_sscom.c: revision 1.8
sys/arch/arm/sunxi/sun8i_a83t_ccu.c: revision 1.1
sys/arch/arm/sunxi/sunxi_mmc.c: revision 1.1
sys/arch/arm/samsung/exynos_sscom.c: revision 1.9
sys/arch/arm/conf/files.arm: revision 1.133
sys/arch/arm/samsung/mct_var.h: revision 1.5
sys/arch/arm/sunxi/sunxi_platform.c: revision 1.1
sys/arch/arm/sunxi/sunxi_platform.c: revision 1.2
sys/arch/evbarm/conf/std.vexpress: revision 1.6
sys/arch/arm/sunxi/sunxi_platform.c: revision 1.3
sys/arch/arm/sunxi/sun6i_a31_gpio.c: revision 1.1
sys/arch/arm/sunxi/sunxi_platform.c: revision 1.4
sys/arch/arm/sunxi/sun6i_a31_gpio.c: revision 1.2
sys/arch/arm/sunxi/files.sunxi: revision 1.1
sys/dev/ofw/ofw_subr.c: revision 1.30
sys/arch/arm/sunxi/files.sunxi: revision 1.2
sys/dev/ofw/openfirm.h: revision 1.35
sys/arch/arm/sunxi/files.sunxi: revision 1.3
sys/dev/ofw/openfirm.h: revision 1.36
sys/arch/arm/sunxi/files.sunxi: revision 1.4
sys/arch/arm/sunxi/files.sunxi: revision 1.5
sys/arch/evbarm/exynos/exynos_machdep.c: file removal
sys/arch/arm/sunxi/sunxi_gpio.h: revision 1.1
sys/arch/arm/samsung/sscom.c: revision 1.9
sys/arch/arm/sunxi/files.sunxi: revision 1.6
sys/dev/fdt/ohci_fdt.c: revision 1.1
sys/arch/arm/sunxi/sunxi_usbphy.c: revision 1.1
sys/arch/arm/sunxi/sunxi_gpio.h: revision 1.2
sys/arch/arm/sunxi/files.sunxi: revision 1.7
sys/arch/arm/sunxi/sunxi_usbphy.c: revision 1.2
sys/arch/arm/sunxi/sunxi_gpio.h: revision 1.3
sys/arch/arm/sunxi/files.sunxi: revision 1.8
sys/arch/arm/sunxi/sunxi_usbphy.c: revision 1.3
sys/arch/arm/sunxi/files.sunxi: revision 1.9
sys/arch/arm/samsung/exynos_sscom.c: revision 1.10
sys/arch/evbarm/conf/mk.tegra: revision 1.5
sys/arch/arm/samsung/exynos_dwcmmc.c: revision 1.4
sys/arch/evbarm/conf/mk.tegra: revision 1.6
sys/arch/evbarm/conf/EXYNOS: revision 1.15
sys/arch/evbarm/conf/EXYNOS: revision 1.16
sys/arch/evbarm/conf/EXYNOS: revision 1.17
sys/arch/arm/sunxi/sunxi_ccu.c: revision 1.1
sys/arch/evbarm/conf/EXYNOS: revision 1.19
sys/arch/arm/sunxi/sunxi_ccu.c: revision 1.2
sys/arch/arm/sunxi/sunxi_ccu.c: revision 1.3
sys/arch/arm/sunxi/sunxi_ccu.c: revision 1.4
sys/arch/arm/sunxi/sunxi_ccu.c: revision 1.5
sys/arch/arm/sunxi/sunxi_emac.h: revision 1.1
sys/arch/evbarm/conf/mk.sunxi: revision 1.1
sys/arch/evbarm/include/bootconfig.h: revision 1.7
sys/arch/evbarm/conf/TEGRA: revision 1.24
sys/arch/arm/arm/psci.c: revision 1.1
sys/dev/led.c: revision 1.1
sys/dev/led.c: revision 1.2
sys/arch/arm/arm/psci_arm.S: revision 1.1
sys/arch/arm/sunxi/sunxi_ccu_gate.c: revision 1.1
sys/arch/arm/sunxi/sunxi_ccu_gate.c: revision 1.2
sys/dev/fdt/ehci_fdt.c: revision 1.1
sys/dev/fdt/ehci_fdt.c: revision 1.2
sys/arch/arm/sunxi/sun6i_a31_ccu.h: revision 1.1
sys/arch/evbarm/conf/EXYNOS: revision 1.21
sys/arch/arm/sunxi/files.sunxi: revision 1.10
sys/arch/arm/sunxi/files.sunxi: revision 1.11
sys/dev/fdt/fdtbus.c: revision 1.14
sys/arch/arm/sunxi/sunxi_mmc.h: revision 1.1
sys/arch/arm/samsung/exynos5422_dma.c: file removal
usr.bin/config/mkmakefile.c: revision 1.69
sys/conf/files: revision 1.1178
sys/arch/arm/sunxi/sunxi_platform.h: revision 1.1
sys/arch/evbarm/exynos/exynos_start.S: revision 1.4
sys/arch/arm/samsung/exynos_pinctrl.c: revision 1.11
sys/arch/arm/samsung/exynos_pinctrl.c: revision 1.12
sys/arch/arm/sunxi/sunxi_rtc.c: revision 1.1
sys/arch/arm/sunxi/sun8i_h3_ccu.h: revision 1.1
sys/arch/arm/samsung/exynos5410_clock.c: revision 1.1
sys/arch/arm/samsung/exynos5410_clock.c: revision 1.2
sys/arch/evbarm/conf/SUNXI: revision 1.1
external/bsd/elftosb/usr.sbin/elftosb/Makefile: revision 1.5
sys/arch/evbarm/conf/SUNXI: revision 1.2
sys/arch/arm/fdt/psci_fdt.c: revision 1.1
sys/arch/evbarm/conf/SUNXI: revision 1.3
sys/arch/evbarm/conf/SUNXI: revision 1.4
sys/arch/evbarm/conf/files.exynos: revision 1.3
sys/arch/evbarm/conf/SUNXI: revision 1.5
sys/arch/evbarm/conf/SUNXI: revision 1.6
sys/arch/arm/sunxi/sunxi_ccu_nm.c: revision 1.1
sys/dev/fdt/fixedfactorclock.c: revision 1.1
sys/dev/fdt/fdt_subr.c: revision 1.14
sys/arch/evbarm/conf/SUNXI: revision 1.7
sys/arch/arm/sunxi/sunxi_ccu_nm.c: revision 1.2
sys/arch/arm/sunxi/sun8i_a83t_gpio.c: revision 1.1
sys/dev/fdt/fdt_subr.c: revision 1.15
sys/arch/evbarm/conf/SUNXI: revision 1.8
sys/arch/arm/sunxi/sunxi_ccu_nm.c: revision 1.3
sys/dev/ic/dwc_mmc_reg.h: revision 1.6
sys/dev/fdt/fdt_subr.c: revision 1.16
sys/arch/evbarm/conf/SUNXI: revision 1.9
usr.bin/config/mkmakefile.c: revision 1.70
sys/dev/fdt/fdt_phy.c: revision 1.1
sys/arch/evbarm/conf/ODROID-XU: file removal
sys/arch/arm/fdt/arm_fdt.c: revision 1.4
sys/arch/arm/samsung/exynos_reg.h: revision 1.14
sys/conf/files: revision 1.1180
sys/arch/arm/samsung/exynos_reg.h: revision 1.15
sys/arch/arm/sunxi/sunxi_ccu.h: revision 1.1
sys/arch/arm/sunxi/sunxi_ccu.h: revision 1.2
sys/arch/arm/sunxi/sunxi_ccu.h: revision 1.3
sys/arch/arm/sunxi/sunxi_ccu.h: revision 1.4
sys/arch/arm/sunxi/sunxi_ccu.h: revision 1.5
sys/arch/arm/sunxi/sunxi_ccu.h: revision 1.6
sys/dev/ic/dwc_mmc_var.h: revision 1.6
sys/arch/arm/samsung/exynos_combiner.c: revision 1.7
sys/arch/evbarm/exynos/platform.h: revision 1.2
sys/arch/arm/fdt/files.fdt: revision 1.12
sys/arch/evbarm/conf/std.exynos: revision 1.2
sys/arch/evbarm/conf/std.exynos: revision 1.3
sys/arch/arm/rockchip/rockchip_dwcmmc.c: revision 1.6
sys/arch/arm/sunxi/sunxi_com.c: revision 1.1
sys/dev/led.h: revision 1.1
sys/arch/evbarm/conf/std.exynos: revision 1.5
sys/arch/arm/sunxi/sunxi_com.c: revision 1.2
sys/arch/evbarm/conf/files.evbarm: revision 1.26
usr.bin/config/defs.h: revision 1.99
sys/arch/arm/fdt/arm_fdtvar.h: revision 1.6
sys/arch/arm/samsung/exynos_soc.c: revision 1.32
sys/arch/arm/sunxi/sun6i_a31_ccu.c: revision 1.1
sys/arch/arm/sunxi/sun6i_a31_ccu.c: revision 1.2
sys/arch/arm/samsung/mct.c: revision 1.11
sys/arch/evbarm/conf/ODROID-U: file removal
sys/arch/arm/samsung/mct.c: revision 1.12
sys/arch/arm/sunxi/sunxi_ccu_nkmp.c: revision 1.1
sys/arch/arm/sunxi/sunxi_ccu_nkmp.c: revision 1.2
sys/arch/arm/sunxi/sunxi_ccu_nkmp.c: revision 1.3
sys/arch/arm/sunxi/sunxi_ccu_nkmp.c: revision 1.4
Get the EXYNOS kernel building again with recent FDT changes. Untested.
Use arm_fdt_cpu_hatch and add mmu entry for DTB
Fix exynos5 devmap, bootstrap, and implement early_putchar.
Calculate UART frequency based on bootloader config.
Fix KERNEL_BASE_PHYS (how did this ever work?)
Avoid divide-by-zero for unconfigured PLLs
Correctly initialize i2cbus attach args.
Add delay and enable mct timecounter.
Fix build w/o VERBOSE_INIT_ARM
Remove ODROID-U and ODROID-XU kernel configs as they no longer work.
- Replace CONSADDR with SSCOM2CONSOLE in example
- Remove gtmr (Exynos5422 uses mct)
- cinclude EXYNOS.local instead of TEGRA.local
Use fdtbus_intr_establish to hook in block interrupts instead of
intr_establish.
Simplify MCT; just enable it and then attach an ARMv7 generic timer.
Add support for building DTB files during kernel build, from christos.
build vexpress-v2p-ca15-tc1.dtb with the kernel
build tegra124-apalis-eval.dtb, tegra124-jetson-tk1.dtb, tegra124-nyan-big.dtb, tegra124-nyan-blaze.dtb, and tegra124-venice2.dtb with the kernel
Allow multiline makeoptions to work by quoting the newline..
Bump for quoting makeoptions with multiple lines.
un-c99
bump required config version for multiline makeoptions feature
Set DTS makeoption in kernel config
Assign DTB files to a variable so we can make -V DTB
put the dtb files with their kernels.
no need for debug printing.
Don't assume that CPU index = GIC CPU interface number. We can determine
the current CPU interface number by reading from the read-only
GICD_ITARGETSR0 through GICD_ITARGETSR7 registers.
This gets interrupts working on Exynos 5422, where the boot processor has
GIC CPU interface #4.
use -v to get the expanded variable.
Use -v to get the expanded variables.
Get baud rate from sclk_uartN instead of uartN. Print IRQ number at attach.
Fix PLL con0 register locations and add uart clocks
Disable exyortc for now, it doesn't work.
More or less a rewrite of dwc_mmc, based on awin_mmc, adding DMA support.
Update for new dwc_mmc driver
Fix dmesg
Add Exynos 5410 clock controller driver.
Fix a few typos in clock parent names for mmc clocks.
From jmcneill@
Update for new dwc_mmc driver
Implement platform reset for exynos5
Attach fdtbus to a /clocks node with no compatible string.
Add support for ARM Power State Coordination Interface (PSCI).
Support interrupt sharing.
Add initial support for Allwinner H3 SoC.
ARM Trusted Firmware reserves SGIs 8-15 for secure use. Even without ATF,
U-Boot on some platforms may use SGIs in this range for the PSCI
implementation.
Change ARMGIC_IPI_BASE to 0 from (16 - NIPI) and add a compile-time assert
to ensure that we don't end up with a conflict.
Add H3 MMC support
SD/MMC clock fixes
Add FDT PHY interface.
Add glue for generic ehci/ohci bindings.
Rename a variable, NFC.
Support parents in different clock domains.
Add USB stuff. Doesn't quite work yet.
Synopsys DesignWare APB UART needs "options COM_AWIN" for now.
Add i2c glue.
Add RTC driver.
PHY registers start at index 1. Now USB works.
Don't allow sharing edge and level triggered interrupts.
Add arm_fdt_memory_dump helper for dumping physical addresses from ddb
Print clocks with aprint_debug
Remove unused defines
Add fdtbus_get_string helper
Add of_search_compatible, which searches an array of compat_data structures
for a matching "compatible" entry matching the supplied OFW node. This
allows us to associate data with compatible strings.
Add driver for Allwinner Gigabit Ethernet (EMAC) as found in sun8i and
later family SoCs.
This is a port of my FreeBSD driver which has been confirmed to work on
Allwinner H3, A83T, and A64 SoCs.
Fix dmesg
Add basic support for Allwinner A31.
Add basic FDT GPIO support.
Fix the pinctrl api to match the spec. A pinctrl config can have more
than one xref, and an xref may have specifier data associated with it.
Enable sunxi pinctrl support
Adjust to new pinctrl API
Add P2WI/RSB driver, based on awin_p2wi.c.
Fix typo in a compat string.
Configure pin defaults at attach
No need to explicitly set pinctrl config 0 now
Fix some register definitions.
Disallow sharing between MPSAFE and non-MPSAFE handlers.
Add of_match_compat_data.
This routine searches an array of compat_data structures for a
matching "compatible" entry matching the supplied OFW node.
Add options __HAVE_CPU_UAREA_ALLOC_IDLELWP
Add support for reserved memory and MEMORY_DISK_DYNAMIC for FDT-based
kernels.
the extent code cannot use the full range of u_long,
so ignore the last page before 4GB too. ok jmcneill@
Copy install ramdisk to releasedir. Provide both a raw ffs and
Legacy U-Boot version of it.
Replace HUMMINGBIRD_A31 with SUNXI kernel on armv7.img and include .dtb
files for SUNXI and TEGRA kernels on the MSDOS partition.
Let the controller provide a default name for pins. This makes pins easier
to locate when we have multiple banks and a variable number of pins per
bank.
Attach gpio(4) to sunxigpio
Test for kernel build directory before reading DTB list
Add support for Allwinner A83T SoC.
Add A83T files
Fixup busdma sync and locking in the RX path. Disable batch RX/TX ints.
Fix AHB2 register definition and explicitly set AHB2 parent to PLL_PERIPH0/2 -- this gives us 50% more bus bandwidth for emac
Restore TX_INTERVAL_DEFAULT to 64
Drop the sunxi_emac_rx_batch feature. It was originally designed to
reduce the amount of mutex unlock/lock cycles during the RX path on
FreeBSD and if_input, but it is not required to drop the lock before
calling if_percpuq_enqueue on NetBSD.
Write back the data value instead of mask in sunxi_gpio_write
Add a helper for exposing LED controls via sysctl.
Add GPIO LED driver.
add gpioleds
Add misc. gates and resets driver, and explicitly enable PIO clocks
at attach.
Add fdtbus_get_string_index helper.
Add driver for fixed-factor clocks.
Add ffclock
Remove the requirement for ehci to attach after companion devices.
"go for it" - skrll@
Remove the hack to find companion devices and just assume 1 companion if
ETTF flag is not set.
Remove pass numbers for ehci/ohci now that the attach order no longer matters
Use unsigned char for ctype functions, suggested by christos
Add : to body of populate_sunxi to appease bash.
port-evbarm/52388: Fix number of args to a debug printf.
 1.6.6.1 25-Jun-2018  pgoyette Sync with HEAD
 1.6.4.2 03-Dec-2017  jdolecek update from HEAD
 1.6.4.1 19-Jun-2017  jdolecek file dwc_mmc_reg.h was added on branch tls-maxphys on 2017-12-03 11:37:03 +0000
 1.7.10.1 25-Jan-2020  ad Sync with head.
 1.7.8.2 21-Mar-2020  martin Pull up following revision(s) (requested by skrll in ticket #800):

sys/dev/ic/dwc_mmc_var.h: revision 1.14
sys/dev/ic/dwc_mmc_reg.h: revision 1.10
sys/dev/ic/dwc_mmc.c: revision 1.23
sys/dev/ic/dwc_mmc.c: revision 1.24
sys/dev/ic/dwc_mmc.c: revision 1.25
sys/dev/ic/dwc_mmc.c: revision 1.26

Release the sc_intr_lock on error

Trailing whitespace

Add DWC_MMC_VERID_280A

Remember / use sc_verid

Disable thrctrl or now and note why
 1.7.8.1 25-Feb-2020  martin Pull up following revision(s) (requested by mrg in ticket #717):

sys/dev/fdt/dwcmmc_fdt.c 1.11
sys/dev/ic/bwfm.c 1.15-1.18
sys/dev/ic/bwfmreg.h 1.4-1.6
sys/dev/ic/bwfmvar.h 1.4,1.5
sys/dev/ic/dwc_mmc.c 1.21,1.22
sys/dev/ic/dwc_mmc_reg.h 1.8,1.9,1.12,1.13
sys/dev/pcmcia/pcmciareg.h 1.11
sys/dev/sdmmc/if_bwfm_sdio.c 1.4,1.6-1.12
sys/dev/sdmmc/if_bwfm_sdio.h 1.1,1.2
sys/dev/sdmmc/sdhc.c 1.105,1.106
sys/dev/sdmmc/sdmmc.c 1.37,1.39
sys/dev/sdmmc/sdmmc_cis.c 1.6,1.8
sys/dev/sdmmc/sdmmc_io.c 1.15-1.19
sys/dev/sdmmc/sdmmc_ioreg.h 1.4,1.5
sys/dev/sdmmc/sdmmc_mem.c 1.69-1.71
sys/dev/sdmmc/sdmmcdevs 1.5-1.8
sys/dev/sdmmc/sdmmcvar.h 1.31,1.33,1.34
sys/net/if_media.h 1.66

Add Broadcom devices
-
Fix typo
-
add PCMCIA_CISTPL_SDIO definition.
-
From OpenBSD:
- move event handling to workqueue
- check for save/restore capability
-
Tag work queue as MPsafe and increase length.
-
Juse use bpf_mtap(), the 802.11 encapsulation is handled by firmware.
-
From OpenBSD:
- support block length per function
- add functions to read/write regions
-
Decode (but not use) SDIO tuple in CIS.
-
Fix locking.
-
Add more SDIO defines (partially from version 3.0).
-
From OpenBSD:
- All the missing pieces (firmware load, chip setup, protocol handling)
TX queue and interrupt handling via sdmmc_task.
-
Fix locking.
-
Fix packet parsing.
-
Add parser for original firmware config files.
-
tagging work queue as MPSAFE was premature. Revert.
-
SD_IO_RW_EXTENDED is a data transfer command, so set ADTC flag instead of AC
Use correct function to verify if a task has been queued. Avoids race
that can corrupt the task queue.
-
More register definitions.
-
Add IFM_IEEE80211_VHT subtype, IFM_IEEE80211_11AC operating mode, and missing descriptions
-
If firmware is connected in HT or VHT mode, report it to SIOCGIFMEDIA
-
white space police.

Skip setting power when the voltage doesn't change.
Also increase some timeouts.
-
Add and use sdmmc_pause to avoid long-term busy waits.
-
Add sdio abort function.
-
Additional error messages.
-
Print parameters for SDIO devices.
-
Minor cosmetics.
-
Simplyfy sdmmc_io_set_blocklen function signature by dropping the
extra softc pointer. Aligns with OpenBSD.
-
Missing commit for sdio abort function.
-
More code from OpenBSD
-
no need to splnet() when enqueing packets
-
explicit structure padding
-
make internal functions static
-
also prepare for GPIO interrupts.
-
Avoid warnings for tautological shifts as sole conditional.
-
Follow the Linux driver an use the FDT "compatible" property to build a
filename for the nvram config file, fall back to the standard filename.
E.g.
[Caching 123 nodes and 1093 properties]
compatible 73696e6f 766f6970 2c627069 2d6d322d "sinovoip,bpi-m2-
0010: 7a65726f 00...... ........ ........ zero"
0015: 616c6c77 696e6e65 722c7375 6e38692d "allwinner,sun8i-
0025: 68322d70 6c757300 ........ ........ h2-plus"
interrupt-parent 00000001 ........ ........ ........ ....
model 42616e61 6e612050 69204250 492d4d32 "Banana Pi BPI-M2
0010: 2d5a6572 6f00.... ........ ........ -Zero"
name 00...... ........ ........ ........ ""
serial-number 30326330 30303432 65636431 36376566 02c00042ecd167ef
0010: 00...... ........ ........ ........ .
-rw-r--r-- 1 root wheel 875 Nov 2 12:06 brcmfmac43430-sdio.AP6212.txt
lrwxr-xr-x 1 root wheel 29 Dec 30 16:19 brcmfmac43430-sdio.sinovoip,bpi-m2-zero.txt -> brcmfmac43430-sdio.AP6212.txt
-rw-r--r-- 1 root wheel 874 Jun 30 2019 brcmfmac43430-sdio.raspberrypi,3-model-b.txt
-rw-r--r-- 1 root wheel 1864 Jun 30 2019 brcmfmac43455-sdio.raspberrypi,3-model-b-plus.txt
lrwxr-xr-x 1 root wheel 29 Dec 30 11:24 brcmfmac43455-sdio.raspberrypi,4-model-b-plus.txt -> brcmfmac43455-sdio.raspberrypi,3-model-b-plus.txt
-
Add product ID for Broadcom BCM43455
-
Use correct firmware for BCM43456
-
size check was backwards.
-
Be less noisy for some commands.
-
Fix DWC_MMC_INT_SDIO_INT bit
-
dwc_mmc fixes:
- Rockchip uses a different SDIO int bit, so take this into consideration
- Avoid unnecessary resets and always wait for resets to complete
- kpause instead of delay while holding spinlock
- Do not attempt autostop for SD_IO_RW_EXTENDED commands
- Allow for sub-blklen byte counts for single block transfers
-
More SDIO stability and performance fixes
 1.7.2.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.15 09-Jan-2022  jmcneill dwcmmc: Add support for card detect using SDMMC_CDETECT register
 1.14 20-Mar-2020  skrll Remember / use sc_verid
 1.13 23-Jan-2020  jmcneill More SDIO stability and performance fixes
 1.12 22-Jan-2020  jmcneill dwc_mmc fixes:
- Rockchip uses a different SDIO int bit, so take this into consideration
- Avoid unnecessary resets and always wait for resets to complete
- kpause instead of delay while holding spinlock
- Do not attempt autostop for SD_IO_RW_EXTENDED commands
- Allow for sub-blklen byte counts for single block transfers
 1.11 01-Jan-2020  jmcneill branches: 1.11.2;
Fix performance regression with previous
 1.10 01-Jan-2020  jmcneill dwcmmc improvements:
- Use mmcpwrseq resources if available
- Only set 4- or 8-bit mode if specified in the dt properties
- Add quirk for implementations with inverted power enable logic
- Support switching signal voltage between 1.8V and 3.3V
- Fix a clock divider issue on Rockchip SoCs
 1.9 05-Oct-2019  jmcneill Add support for SDIO interrupts.
 1.8 30-Apr-2019  jmcneill branches: 1.8.2;
Simplify card detect
 1.7 19-Jun-2018  jmcneill branches: 1.7.2;
dwcmmc: set ciu clock rate rather than assuming fixed input rate
 1.6 19-Jun-2017  jmcneill branches: 1.6.4; 1.6.6;
More or less a rewrite of dwc_mmc, based on awin_mmc, adding DMA support.
 1.5 26-Dec-2015  jmcneill branches: 1.5.10;
Dump registers on timeout and allow bus glue to override card detect func
 1.4 30-Dec-2014  jmcneill branches: 1.4.2;
build fix
 1.3 29-Dec-2014  jmcneill - Simplify clock setup
- Add DWC_MMC_F_FORCE_CLK flag, which forces updating clock for each
command (apparently required by Rockchip)
- Let bus glue limit the max clk speed used
 1.2 27-Dec-2014  jmcneill - Explicitly initialize CLKSRC register.
- Reset FIFO and DMA along with controller.
- Support chips with inverted PWREN logic.
- Enable RXDR and TXDR irqs.
- Set max clk based on supplied clock freq.
- Use external clk control as well as internal divisor to set clock rates.
Requires bus glue to implement sc_set_clkdiv callback.
 1.1 27-Dec-2014  jmcneill add DesignWare SD/MMC controller driver
 1.4.2.4 28-Aug-2017  skrll Sync with HEAD
 1.4.2.3 19-Mar-2016  skrll Sync with HEAD
 1.4.2.2 06-Apr-2015  skrll Sync with HEAD
 1.4.2.1 30-Dec-2014  skrll file dwc_mmc_var.h was added on branch nick-nhusb on 2015-04-06 15:18:09 +0000
 1.5.10.1 18-Jul-2017  snj Pull up following revision(s) (requested by jmcneill in ticket #114):
sys/arch/arm/samsung/exynos_intr.h: revision 1.3
sys/arch/arm/sunxi/sun8i_h3_ccu.c: revision 1.1
sys/arch/arm/sunxi/sun8i_h3_ccu.c: revision 1.2
sys/arch/arm/sunxi/sun8i_h3_ccu.c: revision 1.3
sys/arch/arm/sunxi/sunxi_gates.c: revision 1.1
distrib/utils/embedded/mkimage: revision 1.66
sys/arch/arm/sunxi/sun8i_h3_ccu.c: revision 1.4
sys/arch/arm/sunxi/sunxi_rsb.c: revision 1.1
sys/arch/arm/sunxi/sun8i_h3_ccu.c: revision 1.5
sys/arch/arm/sunxi/sun8i_h3_ccu.c: revision 1.6
sys/arch/arm/sunxi/sun8i_h3_ccu.c: revision 1.7
sys/dev/gpio/gpio.c: revision 1.59
sys/arch/arm/sunxi/sunxi_ccu_prediv.c: revision 1.1
sys/conf/Makefile.kern.inc: revision 1.257
sys/arch/evbarm/conf/ODROID-XU_INSTALL: file removal
sys/arch/arm/sunxi/sunxi_ccu_prediv.c: revision 1.2
sys/conf/Makefile.kern.inc: revision 1.258
sys/arch/arm/fdt/psci_fdt.h: revision 1.1
sys/arch/arm/sunxi/sunxi_resets.c: revision 1.1
sys/arch/evbarm/conf/files.sunxi: revision 1.1
sys/arch/evbarm/fdt/fdt_machdep.c: revision 1.8
sys/arch/evbarm/fdt/fdt_machdep.c: revision 1.9
sys/arch/arm/samsung/files.exynos: revision 1.22
distrib/utils/embedded/conf/armv7.conf: revision 1.13
sys/arch/arm/samsung/files.exynos: revision 1.23
sys/arch/evbarm/conf/std.tegra: revision 1.15
distrib/utils/embedded/conf/armv7.conf: revision 1.14
sys/arch/arm/samsung/files.exynos: revision 1.24
distrib/utils/embedded/conf/armv7.conf: revision 1.15
sys/arch/evbarm/sunxi/genassym.cf: revision 1.1
sys/arch/arm/samsung/exynos_fdt.c: file removal
sys/dev/fdt/fdt_pinctrl.c: revision 1.4
sys/arch/arm/samsung/exynos_sysmmu.c: revision 1.2
sys/arch/arm/sunxi/sun8i_h3_gpio.c: revision 1.1
sys/arch/arm/sunxi/sunxi_twi.c: revision 1.1
sys/dev/usb/ehci.c: revision 1.255
sys/arch/arm/sunxi/sunxi_twi.c: revision 1.2
sys/arch/arm/sunxi/sun8i_a83t_ccu.h: revision 1.1
sys/dev/ic/dwc_mmc.c: revision 1.11
sys/arch/arm/cortex/gic.c: revision 1.24
distrib/evbarm/instkernel/ramdisk/Makefile: revision 1.17
etc/etc.evbarm/Makefile.inc: revision 1.87
etc/etc.evbarm/Makefile.inc: revision 1.88
sys/arch/arm/fdt/gic_fdt.c: revision 1.5
etc/Makefile: revision 1.429
sys/arch/arm/fdt/gic_fdt.c: revision 1.6
sys/arch/arm/fdt/gic_fdt.c: revision 1.7
sys/arch/arm/sunxi/sunxi_gpio.c: revision 1.1
sys/arch/arm/sunxi/sunxi_gpio.c: revision 1.2
sys/arch/evbarm/conf/std.sunxi: revision 1.1
sys/arch/arm/sunxi/sunxi_gpio.c: revision 1.3
sys/arch/evbarm/conf/std.sunxi: revision 1.2
sys/arch/arm/sunxi/sunxi_gpio.c: revision 1.4
sys/arch/evbarm/conf/std.sunxi: revision 1.3
sys/arch/arm/sunxi/sunxi_gpio.c: revision 1.5
sys/arch/arm/sunxi/sunxi_ccu_div.c: revision 1.1
sys/dev/gpio/gpiovar.h: revision 1.17
sys/arch/arm/sunxi/sunxi_gpio.c: revision 1.6
sys/arch/arm/sunxi/sunxi_gpio.c: revision 1.7
sys/arch/arm/sunxi/sunxi_gpio.c: revision 1.8
sys/arch/arm/sunxi/sunxi_rsb.h: revision 1.1
sys/arch/arm/samsung/exynos_i2c.c: revision 1.12
sys/dev/fdt/fdtvar.h: revision 1.21
sys/arch/evbarm/sunxi/sunxi_start.S: revision 1.1
sys/arch/arm/samsung/exynos_i2c.c: revision 1.13
sys/dev/fdt/fdtvar.h: revision 1.22
sys/arch/evbarm/conf/SUNXI: revision 1.10
sys/dev/fdt/fdtvar.h: revision 1.23
sys/arch/evbarm/conf/SUNXI: revision 1.11
sys/dev/fdt/gpioleds.c: revision 1.1
sys/dev/fdt/fdtvar.h: revision 1.24
sys/arch/evbarm/conf/SUNXI: revision 1.12
sys/arch/evbarm/conf/SUNXI: revision 1.13
sys/arch/arm/cortex/gic.c: revision 1.30
sys/arch/evbarm/conf/SUNXI: revision 1.14
sys/arch/evbarm/conf/SUNXI: revision 1.15
sys/arch/evbarm/conf/SUNXI: revision 1.16
sys/arch/arm/sunxi/sunxi_emac.c: revision 1.1
etc/Makefile: revision 1.430
sys/arch/arm/sunxi/sunxi_emac.c: revision 1.2
etc/Makefile: revision 1.431
sys/arch/evbarm/conf/VEXPRESS_A15: revision 1.17
sys/arch/arm/sunxi/sunxi_emac.c: revision 1.3
sys/arch/arm/sunxi/sunxi_emac.c: revision 1.4
sys/arch/arm/samsung/exynos5422_clock.c: revision 1.6
sys/arch/arm/samsung/exynos_platform.c: revision 1.1
sys/dev/ofw/ofw_subr.c: revision 1.29
sys/arch/arm/samsung/exynos_platform.c: revision 1.2
sys/arch/evbarm/conf/mk.vexpress: revision 1.3
sys/arch/arm/samsung/exynos_platform.c: revision 1.3
sys/arch/evbarm/conf/mk.vexpress: revision 1.4
sys/arch/arm/samsung/exynos_platform.c: revision 1.4
sys/arch/arm/arm/psci.h: revision 1.1
sys/arch/arm/samsung/exynos_platform.c: revision 1.5
sys/arch/arm/samsung/exynos_platform.c: revision 1.6
sys/arch/evbarm/fdt/fdt_machdep.c: revision 1.10
external/bsd/mdocml/bin/mandoc/Makefile: revision 1.12
sys/dev/fdt/files.fdt: revision 1.17
sys/dev/fdt/files.fdt: revision 1.18
sys/dev/fdt/files.fdt: revision 1.19
sys/arch/arm/samsung/exynos_sscom.c: revision 1.8
sys/arch/arm/sunxi/sun8i_a83t_ccu.c: revision 1.1
sys/arch/arm/sunxi/sunxi_mmc.c: revision 1.1
sys/arch/arm/samsung/exynos_sscom.c: revision 1.9
sys/arch/arm/conf/files.arm: revision 1.133
sys/arch/arm/samsung/mct_var.h: revision 1.5
sys/arch/arm/sunxi/sunxi_platform.c: revision 1.1
sys/arch/arm/sunxi/sunxi_platform.c: revision 1.2
sys/arch/evbarm/conf/std.vexpress: revision 1.6
sys/arch/arm/sunxi/sunxi_platform.c: revision 1.3
sys/arch/arm/sunxi/sun6i_a31_gpio.c: revision 1.1
sys/arch/arm/sunxi/sunxi_platform.c: revision 1.4
sys/arch/arm/sunxi/sun6i_a31_gpio.c: revision 1.2
sys/arch/arm/sunxi/files.sunxi: revision 1.1
sys/dev/ofw/ofw_subr.c: revision 1.30
sys/arch/arm/sunxi/files.sunxi: revision 1.2
sys/dev/ofw/openfirm.h: revision 1.35
sys/arch/arm/sunxi/files.sunxi: revision 1.3
sys/dev/ofw/openfirm.h: revision 1.36
sys/arch/arm/sunxi/files.sunxi: revision 1.4
sys/arch/arm/sunxi/files.sunxi: revision 1.5
sys/arch/evbarm/exynos/exynos_machdep.c: file removal
sys/arch/arm/sunxi/sunxi_gpio.h: revision 1.1
sys/arch/arm/samsung/sscom.c: revision 1.9
sys/arch/arm/sunxi/files.sunxi: revision 1.6
sys/dev/fdt/ohci_fdt.c: revision 1.1
sys/arch/arm/sunxi/sunxi_usbphy.c: revision 1.1
sys/arch/arm/sunxi/sunxi_gpio.h: revision 1.2
sys/arch/arm/sunxi/files.sunxi: revision 1.7
sys/arch/arm/sunxi/sunxi_usbphy.c: revision 1.2
sys/arch/arm/sunxi/sunxi_gpio.h: revision 1.3
sys/arch/arm/sunxi/files.sunxi: revision 1.8
sys/arch/arm/sunxi/sunxi_usbphy.c: revision 1.3
sys/arch/arm/sunxi/files.sunxi: revision 1.9
sys/arch/arm/samsung/exynos_sscom.c: revision 1.10
sys/arch/evbarm/conf/mk.tegra: revision 1.5
sys/arch/arm/samsung/exynos_dwcmmc.c: revision 1.4
sys/arch/evbarm/conf/mk.tegra: revision 1.6
sys/arch/evbarm/conf/EXYNOS: revision 1.15
sys/arch/evbarm/conf/EXYNOS: revision 1.16
sys/arch/evbarm/conf/EXYNOS: revision 1.17
sys/arch/arm/sunxi/sunxi_ccu.c: revision 1.1
sys/arch/evbarm/conf/EXYNOS: revision 1.19
sys/arch/arm/sunxi/sunxi_ccu.c: revision 1.2
sys/arch/arm/sunxi/sunxi_ccu.c: revision 1.3
sys/arch/arm/sunxi/sunxi_ccu.c: revision 1.4
sys/arch/arm/sunxi/sunxi_ccu.c: revision 1.5
sys/arch/arm/sunxi/sunxi_emac.h: revision 1.1
sys/arch/evbarm/conf/mk.sunxi: revision 1.1
sys/arch/evbarm/include/bootconfig.h: revision 1.7
sys/arch/evbarm/conf/TEGRA: revision 1.24
sys/arch/arm/arm/psci.c: revision 1.1
sys/dev/led.c: revision 1.1
sys/dev/led.c: revision 1.2
sys/arch/arm/arm/psci_arm.S: revision 1.1
sys/arch/arm/sunxi/sunxi_ccu_gate.c: revision 1.1
sys/arch/arm/sunxi/sunxi_ccu_gate.c: revision 1.2
sys/dev/fdt/ehci_fdt.c: revision 1.1
sys/dev/fdt/ehci_fdt.c: revision 1.2
sys/arch/arm/sunxi/sun6i_a31_ccu.h: revision 1.1
sys/arch/evbarm/conf/EXYNOS: revision 1.21
sys/arch/arm/sunxi/files.sunxi: revision 1.10
sys/arch/arm/sunxi/files.sunxi: revision 1.11
sys/dev/fdt/fdtbus.c: revision 1.14
sys/arch/arm/sunxi/sunxi_mmc.h: revision 1.1
sys/arch/arm/samsung/exynos5422_dma.c: file removal
usr.bin/config/mkmakefile.c: revision 1.69
sys/conf/files: revision 1.1178
sys/arch/arm/sunxi/sunxi_platform.h: revision 1.1
sys/arch/evbarm/exynos/exynos_start.S: revision 1.4
sys/arch/arm/samsung/exynos_pinctrl.c: revision 1.11
sys/arch/arm/samsung/exynos_pinctrl.c: revision 1.12
sys/arch/arm/sunxi/sunxi_rtc.c: revision 1.1
sys/arch/arm/sunxi/sun8i_h3_ccu.h: revision 1.1
sys/arch/arm/samsung/exynos5410_clock.c: revision 1.1
sys/arch/arm/samsung/exynos5410_clock.c: revision 1.2
sys/arch/evbarm/conf/SUNXI: revision 1.1
external/bsd/elftosb/usr.sbin/elftosb/Makefile: revision 1.5
sys/arch/evbarm/conf/SUNXI: revision 1.2
sys/arch/arm/fdt/psci_fdt.c: revision 1.1
sys/arch/evbarm/conf/SUNXI: revision 1.3
sys/arch/evbarm/conf/SUNXI: revision 1.4
sys/arch/evbarm/conf/files.exynos: revision 1.3
sys/arch/evbarm/conf/SUNXI: revision 1.5
sys/arch/evbarm/conf/SUNXI: revision 1.6
sys/arch/arm/sunxi/sunxi_ccu_nm.c: revision 1.1
sys/dev/fdt/fixedfactorclock.c: revision 1.1
sys/dev/fdt/fdt_subr.c: revision 1.14
sys/arch/evbarm/conf/SUNXI: revision 1.7
sys/arch/arm/sunxi/sunxi_ccu_nm.c: revision 1.2
sys/arch/arm/sunxi/sun8i_a83t_gpio.c: revision 1.1
sys/dev/fdt/fdt_subr.c: revision 1.15
sys/arch/evbarm/conf/SUNXI: revision 1.8
sys/arch/arm/sunxi/sunxi_ccu_nm.c: revision 1.3
sys/dev/ic/dwc_mmc_reg.h: revision 1.6
sys/dev/fdt/fdt_subr.c: revision 1.16
sys/arch/evbarm/conf/SUNXI: revision 1.9
usr.bin/config/mkmakefile.c: revision 1.70
sys/dev/fdt/fdt_phy.c: revision 1.1
sys/arch/evbarm/conf/ODROID-XU: file removal
sys/arch/arm/fdt/arm_fdt.c: revision 1.4
sys/arch/arm/samsung/exynos_reg.h: revision 1.14
sys/conf/files: revision 1.1180
sys/arch/arm/samsung/exynos_reg.h: revision 1.15
sys/arch/arm/sunxi/sunxi_ccu.h: revision 1.1
sys/arch/arm/sunxi/sunxi_ccu.h: revision 1.2
sys/arch/arm/sunxi/sunxi_ccu.h: revision 1.3
sys/arch/arm/sunxi/sunxi_ccu.h: revision 1.4
sys/arch/arm/sunxi/sunxi_ccu.h: revision 1.5
sys/arch/arm/sunxi/sunxi_ccu.h: revision 1.6
sys/dev/ic/dwc_mmc_var.h: revision 1.6
sys/arch/arm/samsung/exynos_combiner.c: revision 1.7
sys/arch/evbarm/exynos/platform.h: revision 1.2
sys/arch/arm/fdt/files.fdt: revision 1.12
sys/arch/evbarm/conf/std.exynos: revision 1.2
sys/arch/evbarm/conf/std.exynos: revision 1.3
sys/arch/arm/rockchip/rockchip_dwcmmc.c: revision 1.6
sys/arch/arm/sunxi/sunxi_com.c: revision 1.1
sys/dev/led.h: revision 1.1
sys/arch/evbarm/conf/std.exynos: revision 1.5
sys/arch/arm/sunxi/sunxi_com.c: revision 1.2
sys/arch/evbarm/conf/files.evbarm: revision 1.26
usr.bin/config/defs.h: revision 1.99
sys/arch/arm/fdt/arm_fdtvar.h: revision 1.6
sys/arch/arm/samsung/exynos_soc.c: revision 1.32
sys/arch/arm/sunxi/sun6i_a31_ccu.c: revision 1.1
sys/arch/arm/sunxi/sun6i_a31_ccu.c: revision 1.2
sys/arch/arm/samsung/mct.c: revision 1.11
sys/arch/evbarm/conf/ODROID-U: file removal
sys/arch/arm/samsung/mct.c: revision 1.12
sys/arch/arm/sunxi/sunxi_ccu_nkmp.c: revision 1.1
sys/arch/arm/sunxi/sunxi_ccu_nkmp.c: revision 1.2
sys/arch/arm/sunxi/sunxi_ccu_nkmp.c: revision 1.3
sys/arch/arm/sunxi/sunxi_ccu_nkmp.c: revision 1.4
Get the EXYNOS kernel building again with recent FDT changes. Untested.
Use arm_fdt_cpu_hatch and add mmu entry for DTB
Fix exynos5 devmap, bootstrap, and implement early_putchar.
Calculate UART frequency based on bootloader config.
Fix KERNEL_BASE_PHYS (how did this ever work?)
Avoid divide-by-zero for unconfigured PLLs
Correctly initialize i2cbus attach args.
Add delay and enable mct timecounter.
Fix build w/o VERBOSE_INIT_ARM
Remove ODROID-U and ODROID-XU kernel configs as they no longer work.
- Replace CONSADDR with SSCOM2CONSOLE in example
- Remove gtmr (Exynos5422 uses mct)
- cinclude EXYNOS.local instead of TEGRA.local
Use fdtbus_intr_establish to hook in block interrupts instead of
intr_establish.
Simplify MCT; just enable it and then attach an ARMv7 generic timer.
Add support for building DTB files during kernel build, from christos.
build vexpress-v2p-ca15-tc1.dtb with the kernel
build tegra124-apalis-eval.dtb, tegra124-jetson-tk1.dtb, tegra124-nyan-big.dtb, tegra124-nyan-blaze.dtb, and tegra124-venice2.dtb with the kernel
Allow multiline makeoptions to work by quoting the newline..
Bump for quoting makeoptions with multiple lines.
un-c99
bump required config version for multiline makeoptions feature
Set DTS makeoption in kernel config
Assign DTB files to a variable so we can make -V DTB
put the dtb files with their kernels.
no need for debug printing.
Don't assume that CPU index = GIC CPU interface number. We can determine
the current CPU interface number by reading from the read-only
GICD_ITARGETSR0 through GICD_ITARGETSR7 registers.
This gets interrupts working on Exynos 5422, where the boot processor has
GIC CPU interface #4.
use -v to get the expanded variable.
Use -v to get the expanded variables.
Get baud rate from sclk_uartN instead of uartN. Print IRQ number at attach.
Fix PLL con0 register locations and add uart clocks
Disable exyortc for now, it doesn't work.
More or less a rewrite of dwc_mmc, based on awin_mmc, adding DMA support.
Update for new dwc_mmc driver
Fix dmesg
Add Exynos 5410 clock controller driver.
Fix a few typos in clock parent names for mmc clocks.
From jmcneill@
Update for new dwc_mmc driver
Implement platform reset for exynos5
Attach fdtbus to a /clocks node with no compatible string.
Add support for ARM Power State Coordination Interface (PSCI).
Support interrupt sharing.
Add initial support for Allwinner H3 SoC.
ARM Trusted Firmware reserves SGIs 8-15 for secure use. Even without ATF,
U-Boot on some platforms may use SGIs in this range for the PSCI
implementation.
Change ARMGIC_IPI_BASE to 0 from (16 - NIPI) and add a compile-time assert
to ensure that we don't end up with a conflict.
Add H3 MMC support
SD/MMC clock fixes
Add FDT PHY interface.
Add glue for generic ehci/ohci bindings.
Rename a variable, NFC.
Support parents in different clock domains.
Add USB stuff. Doesn't quite work yet.
Synopsys DesignWare APB UART needs "options COM_AWIN" for now.
Add i2c glue.
Add RTC driver.
PHY registers start at index 1. Now USB works.
Don't allow sharing edge and level triggered interrupts.
Add arm_fdt_memory_dump helper for dumping physical addresses from ddb
Print clocks with aprint_debug
Remove unused defines
Add fdtbus_get_string helper
Add of_search_compatible, which searches an array of compat_data structures
for a matching "compatible" entry matching the supplied OFW node. This
allows us to associate data with compatible strings.
Add driver for Allwinner Gigabit Ethernet (EMAC) as found in sun8i and
later family SoCs.
This is a port of my FreeBSD driver which has been confirmed to work on
Allwinner H3, A83T, and A64 SoCs.
Fix dmesg
Add basic support for Allwinner A31.
Add basic FDT GPIO support.
Fix the pinctrl api to match the spec. A pinctrl config can have more
than one xref, and an xref may have specifier data associated with it.
Enable sunxi pinctrl support
Adjust to new pinctrl API
Add P2WI/RSB driver, based on awin_p2wi.c.
Fix typo in a compat string.
Configure pin defaults at attach
No need to explicitly set pinctrl config 0 now
Fix some register definitions.
Disallow sharing between MPSAFE and non-MPSAFE handlers.
Add of_match_compat_data.
This routine searches an array of compat_data structures for a
matching "compatible" entry matching the supplied OFW node.
Add options __HAVE_CPU_UAREA_ALLOC_IDLELWP
Add support for reserved memory and MEMORY_DISK_DYNAMIC for FDT-based
kernels.
the extent code cannot use the full range of u_long,
so ignore the last page before 4GB too. ok jmcneill@
Copy install ramdisk to releasedir. Provide both a raw ffs and
Legacy U-Boot version of it.
Replace HUMMINGBIRD_A31 with SUNXI kernel on armv7.img and include .dtb
files for SUNXI and TEGRA kernels on the MSDOS partition.
Let the controller provide a default name for pins. This makes pins easier
to locate when we have multiple banks and a variable number of pins per
bank.
Attach gpio(4) to sunxigpio
Test for kernel build directory before reading DTB list
Add support for Allwinner A83T SoC.
Add A83T files
Fixup busdma sync and locking in the RX path. Disable batch RX/TX ints.
Fix AHB2 register definition and explicitly set AHB2 parent to PLL_PERIPH0/2 -- this gives us 50% more bus bandwidth for emac
Restore TX_INTERVAL_DEFAULT to 64
Drop the sunxi_emac_rx_batch feature. It was originally designed to
reduce the amount of mutex unlock/lock cycles during the RX path on
FreeBSD and if_input, but it is not required to drop the lock before
calling if_percpuq_enqueue on NetBSD.
Write back the data value instead of mask in sunxi_gpio_write
Add a helper for exposing LED controls via sysctl.
Add GPIO LED driver.
add gpioleds
Add misc. gates and resets driver, and explicitly enable PIO clocks
at attach.
Add fdtbus_get_string_index helper.
Add driver for fixed-factor clocks.
Add ffclock
Remove the requirement for ehci to attach after companion devices.
"go for it" - skrll@
Remove the hack to find companion devices and just assume 1 companion if
ETTF flag is not set.
Remove pass numbers for ehci/ohci now that the attach order no longer matters
Use unsigned char for ctype functions, suggested by christos
Add : to body of populate_sunxi to appease bash.
port-evbarm/52388: Fix number of args to a debug printf.
 1.6.6.1 25-Jun-2018  pgoyette Sync with HEAD
 1.6.4.2 03-Dec-2017  jdolecek update from HEAD
 1.6.4.1 19-Jun-2017  jdolecek file dwc_mmc_var.h was added on branch tls-maxphys on 2017-12-03 11:37:03 +0000
 1.7.2.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.7.2.1 10-Jun-2019  christos Sync with HEAD
 1.8.2.3 21-Mar-2020  martin Pull up following revision(s) (requested by skrll in ticket #800):

sys/dev/ic/dwc_mmc_var.h: revision 1.14
sys/dev/ic/dwc_mmc_reg.h: revision 1.10
sys/dev/ic/dwc_mmc.c: revision 1.23
sys/dev/ic/dwc_mmc.c: revision 1.24
sys/dev/ic/dwc_mmc.c: revision 1.25
sys/dev/ic/dwc_mmc.c: revision 1.26

Release the sc_intr_lock on error

Trailing whitespace

Add DWC_MMC_VERID_280A

Remember / use sc_verid

Disable thrctrl or now and note why
 1.8.2.2 25-Feb-2020  martin Pull up following revision(s) (requested by mrg in ticket #717):

sys/dev/fdt/dwcmmc_fdt.c 1.11
sys/dev/ic/bwfm.c 1.15-1.18
sys/dev/ic/bwfmreg.h 1.4-1.6
sys/dev/ic/bwfmvar.h 1.4,1.5
sys/dev/ic/dwc_mmc.c 1.21,1.22
sys/dev/ic/dwc_mmc_reg.h 1.8,1.9,1.12,1.13
sys/dev/pcmcia/pcmciareg.h 1.11
sys/dev/sdmmc/if_bwfm_sdio.c 1.4,1.6-1.12
sys/dev/sdmmc/if_bwfm_sdio.h 1.1,1.2
sys/dev/sdmmc/sdhc.c 1.105,1.106
sys/dev/sdmmc/sdmmc.c 1.37,1.39
sys/dev/sdmmc/sdmmc_cis.c 1.6,1.8
sys/dev/sdmmc/sdmmc_io.c 1.15-1.19
sys/dev/sdmmc/sdmmc_ioreg.h 1.4,1.5
sys/dev/sdmmc/sdmmc_mem.c 1.69-1.71
sys/dev/sdmmc/sdmmcdevs 1.5-1.8
sys/dev/sdmmc/sdmmcvar.h 1.31,1.33,1.34
sys/net/if_media.h 1.66

Add Broadcom devices
-
Fix typo
-
add PCMCIA_CISTPL_SDIO definition.
-
From OpenBSD:
- move event handling to workqueue
- check for save/restore capability
-
Tag work queue as MPsafe and increase length.
-
Juse use bpf_mtap(), the 802.11 encapsulation is handled by firmware.
-
From OpenBSD:
- support block length per function
- add functions to read/write regions
-
Decode (but not use) SDIO tuple in CIS.
-
Fix locking.
-
Add more SDIO defines (partially from version 3.0).
-
From OpenBSD:
- All the missing pieces (firmware load, chip setup, protocol handling)
TX queue and interrupt handling via sdmmc_task.
-
Fix locking.
-
Fix packet parsing.
-
Add parser for original firmware config files.
-
tagging work queue as MPSAFE was premature. Revert.
-
SD_IO_RW_EXTENDED is a data transfer command, so set ADTC flag instead of AC
Use correct function to verify if a task has been queued. Avoids race
that can corrupt the task queue.
-
More register definitions.
-
Add IFM_IEEE80211_VHT subtype, IFM_IEEE80211_11AC operating mode, and missing descriptions
-
If firmware is connected in HT or VHT mode, report it to SIOCGIFMEDIA
-
white space police.

Skip setting power when the voltage doesn't change.
Also increase some timeouts.
-
Add and use sdmmc_pause to avoid long-term busy waits.
-
Add sdio abort function.
-
Additional error messages.
-
Print parameters for SDIO devices.
-
Minor cosmetics.
-
Simplyfy sdmmc_io_set_blocklen function signature by dropping the
extra softc pointer. Aligns with OpenBSD.
-
Missing commit for sdio abort function.
-
More code from OpenBSD
-
no need to splnet() when enqueing packets
-
explicit structure padding
-
make internal functions static
-
also prepare for GPIO interrupts.
-
Avoid warnings for tautological shifts as sole conditional.
-
Follow the Linux driver an use the FDT "compatible" property to build a
filename for the nvram config file, fall back to the standard filename.
E.g.
[Caching 123 nodes and 1093 properties]
compatible 73696e6f 766f6970 2c627069 2d6d322d "sinovoip,bpi-m2-
0010: 7a65726f 00...... ........ ........ zero"
0015: 616c6c77 696e6e65 722c7375 6e38692d "allwinner,sun8i-
0025: 68322d70 6c757300 ........ ........ h2-plus"
interrupt-parent 00000001 ........ ........ ........ ....
model 42616e61 6e612050 69204250 492d4d32 "Banana Pi BPI-M2
0010: 2d5a6572 6f00.... ........ ........ -Zero"
name 00...... ........ ........ ........ ""
serial-number 30326330 30303432 65636431 36376566 02c00042ecd167ef
0010: 00...... ........ ........ ........ .
-rw-r--r-- 1 root wheel 875 Nov 2 12:06 brcmfmac43430-sdio.AP6212.txt
lrwxr-xr-x 1 root wheel 29 Dec 30 16:19 brcmfmac43430-sdio.sinovoip,bpi-m2-zero.txt -> brcmfmac43430-sdio.AP6212.txt
-rw-r--r-- 1 root wheel 874 Jun 30 2019 brcmfmac43430-sdio.raspberrypi,3-model-b.txt
-rw-r--r-- 1 root wheel 1864 Jun 30 2019 brcmfmac43455-sdio.raspberrypi,3-model-b-plus.txt
lrwxr-xr-x 1 root wheel 29 Dec 30 11:24 brcmfmac43455-sdio.raspberrypi,4-model-b-plus.txt -> brcmfmac43455-sdio.raspberrypi,3-model-b-plus.txt
-
Add product ID for Broadcom BCM43455
-
Use correct firmware for BCM43456
-
size check was backwards.
-
Be less noisy for some commands.
-
Fix DWC_MMC_INT_SDIO_INT bit
-
dwc_mmc fixes:
- Rockchip uses a different SDIO int bit, so take this into consideration
- Avoid unnecessary resets and always wait for resets to complete
- kpause instead of delay while holding spinlock
- Do not attempt autostop for SD_IO_RW_EXTENDED commands
- Allow for sub-blklen byte counts for single block transfers
-
More SDIO stability and performance fixes
 1.8.2.1 21-Jan-2020  martin Pull up following revision(s) (requested by mrg in ticket #616):

sys/dev/ic/anx_dp.c: revision 1.2
sys/arch/evbarm/conf/GENERIC64: revision 1.126
sys/dev/ic/anx_dp.h: revision 1.1
sys/arch/evbarm/conf/GENERIC64: revision 1.128
sys/dev/ic/anx_dp.h: revision 1.2
sys/dev/fdt/dwcmmc_fdt.c: revision 1.9
sys/dev/i2c/cwfg.c: revision 1.1
sys/conf/files: revision 1.1247
sys/dev/fdt/pwm_backlight.c: revision 1.5
sys/dev/fdt/pwm_backlight.c: revision 1.6
sys/arch/arm/rockchip/rk3399_cru.c: revision 1.14
sys/arch/arm/rockchip/rk3399_cru.c: revision 1.15
sys/arch/arm/rockchip/rk3399_cru.c: revision 1.16
sys/arch/arm/rockchip/rk3399_cru.c: revision 1.17
sys/dev/ic/dwc_mmc.c: revision 1.20
sys/arch/arm/rockchip/rk3399_cru.c: revision 1.18
sys/arch/arm/rockchip/rk3399_cru.c: revision 1.19
sys/dev/usb/usbdevs: revision 1.775
sys/arch/arm/rockchip/rk_dwhdmi.c: revision 1.4
sys/dev/fdt/simple_amplifier.c: revision 1.1
sys/dev/i2c/files.i2c: revision 1.105
sys/arch/evbarm/conf/GENERIC64: revision 1.117
sys/arch/evbarm/conf/GENERIC64: revision 1.118
sys/dev/i2c/files.i2c: revision 1.107
sys/dev/fdt/files.fdt: revision 1.49
sys/arch/arm/rockchip/rk_anxdp.c: revision 1.1
sys/dev/ic/dwc_mmc_var.h: revision 1.9
sys/dev/i2c/rkpmic.c: revision 1.4
sys/arch/arm/rockchip/rk_anxdp.c: revision 1.2
sys/dev/i2c/rkpmic.c: revision 1.5
sys/dev/i2c/rkpmic.c: revision 1.6
sys/arch/arm/rockchip/rk_vop.c: revision 1.4
sys/arch/arm/rockchip/rk_vop.c: revision 1.5
sys/dev/i2c/rkpmic.c: revision 1.8
sys/arch/arm/dts/rk3399-pinebook-pro.dts: revision 1.1
sys/dev/usb/ums.c: revision 1.96 (via patch)
sys/arch/arm/rockchip/rk_pwm.c: revision 1.3
sys/arch/arm/dts/rk3399-pinebook-pro.dts: revision 1.2
sys/dev/i2c/es8316ac.c: revision 1.1
sys/dev/fdt/dwcmmc_fdt.c: revision 1.10
sys/dev/i2c/es8316ac.c: revision 1.2
sys/dev/fdt/fdt_panel.c: revision 1.1
sys/dev/ic/dwc_mmc.c: revision 1.18
sys/dev/fdt/fdt_panel.c: revision 1.2
sys/dev/ic/dwc_mmc.c: revision 1.19
sys/arch/arm/dts/rk3399-rockpro64.dts: revision 1.10
sys/dev/fdt/fdt_port.c: revision 1.5
sys/dev/ic/dwc_mmc_var.h: revision 1.10
sys/dev/fdt/fdt_port.c: revision 1.6
sys/arch/evbarm/conf/GENERIC64: revision 1.122
sys/dev/ic/dwc_mmc_var.h: revision 1.11
sys/dev/fdt/files.fdt: revision 1.50
sys/arch/evbarm/conf/GENERIC64: revision 1.123
sys/arch/arm/rockchip/rk_i2s.c: revision 1.2
sys/arch/arm/rockchip/files.rockchip: revision 1.23
sys/arch/evbarm/conf/GENERIC64: revision 1.124
sys/dev/ic/anx_dp.c: revision 1.1

rkpmic: add RTC support; register w/ todr(9)
rkpmic: correct delay
Add support for SDIO interrupts.
fix copy/paste error in mux_pll_src_cpll_gpll_ppll_parents[]
add RK3399 eDP clocks
add RK3399 DisplayPort clocks
style fix/KNF
rk3399_cru: implement dclk_vop0_frac and dclk_vop1_frac
Move drm_encoder from rkvop(4) to the SoC-layer output pipe drivers (rk_dwhdmi).
rkvop: set stride using virtual framebuffer width instead of display mode
rk3399_cru: Reparent dclk_vop[01] to gpll via dclk_vop[01]_frac.
The previous source of dclk_vop[01] was vpll via dclk_vop[01]_div.
vpll is apparently used directly as a pixel clock source for the
HDMI PHY, and we don't want the other VOP's dclk changing out from
under it because we can't handle finding a replacement clock source
with the right rate yet.
gpll happens to run at 594MHz, which works well as a basis for pixel
clocks.
Linux suggests that the source clock of the fractional divider needs
to be more than twenty times greater than the resulting clock (or some
intermediate clock?) for output stability. This may not be the case
with 594MHz and the common pixel clocks I see used by displays in my
area of the wild, but it works for now.
add Analogix DisplayPort core driver
add Rockchip (RK3399) glue for Analogix DisplayPort core
add anxdp(4)
Add another panel@fdt driver, this time for DRM-style panels.
To do: migrate away from other panel driver.
enable panel at fdt drivers
paper over the rkpwm get_conf function that otherwise doesn't seem to
let things work
add template bits for optional eDP panel on RockPro64
Abort panel driver attach if required regulator is missing.
Add clk provider
Add Pinebook Pro dts, from Manjaro Linux.
https://gitlab.manjaro.org/tsys/linux-pinebook-pro/blob/877ca0e7283596f37845de50dc36bff5b88b91e1/arch/arm64/boot/dts/rockchip/rk3399-pinebook-pro.dts
+ rk3399-pinebook-pro.dts
Attach mmcpwrseq resource earlier
dwcmmc improvements:
- Use mmcpwrseq resources if available
- Only set 4- or 8-bit mode if specified in the dt properties
- Add quirk for implementations with inverted power enable logic
- Support switching signal voltage between 1.8V and 3.3V
- Fix a clock divider issue on Rockchip SoCs
Fix performance regression with previous
Quiet chatty printfs
No need to print all supported levels at attach, print the range and total number of steps
Disable SPI for now (rkspi driver hangs at boot)
Add driver for simple-audio-amplifier binding
Add driver for Everest Semi ES8316 Low Power Audio CODEC
add es8316, simpleamp
Avoid sleeping while the audio intr lock is held.
If the rockchip,system-power-controller property is present, try to power off with the PMIC
Add HAILUCK keyboard (product 1e)
Add a quirk for the HAILUCK USB keyboard / touchpad device with product 1e.
The keyboard does not function properly unless the touchpad's intr endpoint
is active.
Add driver for CellWise CW2015 Fuel Gauge IC.
add cwfg
Emit PMFE_DISPLAY_{ON,OFF} events in response to DPMS requests.
If the backlight node does not have an enable gpio, set the lowest duty
cycle to turn the display off instead.
Attach psci as early as possible. This allows other power controllers to
register their own poweroff / reset callbacks with a higher preference.
Add 2000 MHz to available armclkb rates
Remove debug printfs
 1.11.2.1 25-Jan-2020  ad Sync with head.
 1.2 26-Apr-2019  jmcneill Remove Designware timer code. This was used by the old Rockchip port and
is no longer required.
 1.1 17-Jan-2015  jmcneill branches: 1.1.2; 1.1.18; 1.1.22;
Add driver for DesignWare 32-bit timer as found in Rockchip RK3066/PX2,
from FUKAUMI Naoki <fun@naobsd.org>
 1.1.22.1 10-Jun-2019  christos Sync with HEAD
 1.1.18.2 03-Dec-2017  jdolecek update from HEAD
 1.1.18.1 17-Jan-2015  jdolecek file dwc_tmr.c was added on branch tls-maxphys on 2017-12-03 11:37:03 +0000
 1.1.2.2 06-Apr-2015  skrll Sync with HEAD
 1.1.2.1 17-Jan-2015  skrll file dwc_tmr.c was added on branch nick-nhusb on 2015-04-06 15:18:09 +0000
 1.2 26-Apr-2019  jmcneill Remove Designware timer code. This was used by the old Rockchip port and
is no longer required.
 1.1 17-Jan-2015  jmcneill branches: 1.1.2; 1.1.18; 1.1.22;
Add driver for DesignWare 32-bit timer as found in Rockchip RK3066/PX2,
from FUKAUMI Naoki <fun@naobsd.org>
 1.1.22.1 10-Jun-2019  christos Sync with HEAD
 1.1.18.2 03-Dec-2017  jdolecek update from HEAD
 1.1.18.1 17-Jan-2015  jdolecek file dwc_tmr_reg.h was added on branch tls-maxphys on 2017-12-03 11:37:03 +0000
 1.1.2.2 06-Apr-2015  skrll Sync with HEAD
 1.1.2.1 17-Jan-2015  skrll file dwc_tmr_reg.h was added on branch nick-nhusb on 2015-04-06 15:18:09 +0000
 1.2 26-Apr-2019  jmcneill Remove Designware timer code. This was used by the old Rockchip port and
is no longer required.
 1.1 17-Jan-2015  jmcneill branches: 1.1.2; 1.1.18; 1.1.22;
Add driver for DesignWare 32-bit timer as found in Rockchip RK3066/PX2,
from FUKAUMI Naoki <fun@naobsd.org>
 1.1.22.1 10-Jun-2019  christos Sync with HEAD
 1.1.18.2 03-Dec-2017  jdolecek update from HEAD
 1.1.18.1 17-Jan-2015  jdolecek file dwc_tmr_var.h was added on branch tls-maxphys on 2017-12-03 11:37:03 +0000
 1.1.2.2 06-Apr-2015  skrll Sync with HEAD
 1.1.2.1 17-Jan-2015  skrll file dwc_tmr_var.h was added on branch nick-nhusb on 2015-04-06 15:18:09 +0000
 1.1 16-Apr-2023  jmcneill Separate DesignWare watchdog driver and FDT glue.
 1.1 16-Apr-2023  jmcneill Separate DesignWare watchdog driver and FDT glue.
 1.11 15-Sep-2025  thorpej Do the ACPI-specific get-child-devices dance in iic_attach(). This
obviously isn't ideal, but it funnels the issue into a central location
and provides for easier improvement later.
 1.10 09-Feb-2024  skrll Trailing whitespace
 1.9 19-Oct-2022  riastradh dwiic(4): Don't try processing interrupts before attach completes.

PR kern/57063
 1.8 14-Nov-2021  andvar fix few typos in comments and log message.
 1.7 23-Dec-2019  thorpej dwiic_i2c_exec(): No need to check 'cold' to force I2C_F_POLL; the i2c
upper layer does it for us.
 1.6 22-Dec-2019  thorpej Cleanup i2c bus acquire / release, centralizing all of the logic into
iic_acquire_bus() / iic_release_bus(). "acquire" and "release" hooks
no longer need to be provided by back-end controller drivers (only if
they need special handling, e.g. powering on the i2c controller).
This results in the removal of a bunch of rendundant code from each
back-end controller driver.

Assert that we are not in hard interrupt context in iic_acquire_bus(),
iic_exec(), and iic_release_bus().
 1.5 26-Sep-2018  jakllsch Add dwiic_fdt attachment for "snps,designware-i2c".
 1.4 26-Sep-2018  jakllsch Sync with OpenBSD src/sys/dev/ic/dwiic.c r1.4.

Makes split command+data write operations in the exec() function work.
 1.3 26-Sep-2018  jakllsch Correctly use device_printf() rather than aprint_error_dev() for errors
that can occur at runtime.
 1.2 25-Sep-2018  jakllsch return 0 on success of dwiic_i2c_acquire_bus(), not 1 (failure)
 1.1 10-Dec-2017  bouyer branches: 1.1.2; 1.1.4;
Add support for I2C designware controllers (as found in Intel PCH devices),
with a pci front-end.
The pci front-end is tied to ACPI and Intel-specific, so it's in arch/x86/pci
and not dev/pci.
Core driver from OpenBSD, PCI front-end by me.
 1.1.4.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.1.4.1 10-Jun-2019  christos Sync with HEAD
 1.1.2.1 30-Sep-2018  pgoyette Ssync with HEAD
 1.4 15-Sep-2025  thorpej Do the ACPI-specific get-child-devices dance in iic_attach(). This
obviously isn't ideal, but it funnels the issue into a central location
and provides for easier improvement later.
 1.3 19-Oct-2022  riastradh dwiic(4): Don't try processing interrupts before attach completes.

PR kern/57063
 1.2 26-Sep-2018  jakllsch Sync with OpenBSD src/sys/dev/ic/dwiic.c r1.4.

Makes split command+data write operations in the exec() function work.
 1.1 10-Dec-2017  bouyer branches: 1.1.2; 1.1.4;
Add support for I2C designware controllers (as found in Intel PCH devices),
with a pci front-end.
The pci front-end is tied to ACPI and Intel-specific, so it's in arch/x86/pci
and not dev/pci.
Core driver from OpenBSD, PCI front-end by me.
 1.1.4.1 10-Jun-2019  christos Sync with HEAD
 1.1.2.1 30-Sep-2018  pgoyette Ssync with HEAD
 1.154 05-Jul-2024  rin sys: Drop redundant NULL check before m_freem(9)

m_freem(9) safely has accepted NULL argument at least since 4.2BSD:
https://www.tuhs.org/cgi-bin/utree.pl?file=4.2BSD/usr/src/sys/sys/uipc_mbuf.c

Compile-tested on amd64/ALL.

Suggested by knakahara@
 1.153 11-Oct-2021  rin branches: 1.153.10;
epget: Tiny clean up for 16-bit buses.

- (offset & 1) must be zero, since IP header is aligned.

- Use bus_space_read_1(9) instead of bus_space_read_multi_1(9) for
single-byte read.
 1.152 07-Feb-2020  thorpej Use callout_setfunc() / callout_schedule().
 1.151 04-Feb-2020  thorpej Use ifmedia_fini().
 1.150 29-Jan-2020  thorpej Adopt <net/if_stats.h>.
 1.149 29-May-2019  msaitoh branches: 1.149.4;
No functional change:
- Simplify MII structure initialization and reference.
- KNF
 1.148 24-May-2019  msaitoh Whilespace fix. No functional change.
 1.147 22-Apr-2019  msaitoh In drivers which use MII(4) and have hook SIOC[GS]IFMEDIA which just pass to
ifmedia_ioctl(), the hook is not required because ether_ioctl has it
(if_ethersubr.c rev. 1.160). These drivers don't return ENETRESET in
ifmedia_ioctl(), so no functional change.
 1.146 05-Feb-2019  msaitoh Remove very old IFF_NOTRAILERS flag.
 1.145 03-Feb-2019  mrg - add or adjust /* FALLTHROUGH */ where appropriate
- add __unreachable() after functions that can return but won't in
this case, and thus can't be marked __dead easily
 1.144 22-Jan-2019  msaitoh Change MII PHY read/write API from:

int (*mii_readreg_t)(device_t, int, int);
void (*mii_writereg_t)(device_t, int, int, int);
to:

int (*mii_readreg_t)(device_t, int, int, uint16_t *);
int (*mii_writereg_t)(device_t, int, int, uint16_t);

Now we can test if a read/write operation failed or not by the return value.

In 802.3 spec says that the PHY shall not respond to read/write transaction
to the unimplemented register(22.2.4.3). Detecting timeout can be used to
check whether a register is implemented or not (if the register conforms to
the spec). ukphy(4) can be used this for MII_MMDACR and MII_MMDAADR.

Note that I noticed that the following code do infinite loop in the
read/wirte function. If it accesses unimplemented PHY register, it will hang.
It should be fixed:

arm/at91/at91emac.c
arm/ep93xx/epe.c
arm/omap/omapl1x_emac.c
mips/ralink/ralink_eth.c
arch/powerpc/booke/dev/pq3etsec.c(read)
dev/cadence/if_cemac.c <- hkenken
dev/ic/lan9118.c


Tested with the following device:

axe+ukphy
axe+rgephy
axen+rgephy (tested by Andrius V)
wm+atphy
wm+ukphy
wm+igphy
wm+ihphy
wm+makphy
sk+makphy
sk+brgphy
sk+gentbi
msk+makphy
sip+icsphy
sip+ukphy
re+rgephy
bge+brgphy
bnx+brgphy
gsip+gphyter
rtk+rlphy
fxp+inphy (tested by Andrius V)
tlp+acphy
ex+exphy
epic+qsphy
vge+ciphy (tested by Andrius V)
vr+ukphy (tested by Andrius V)
vte+ukphy (tested by Andrius V)

Not tested (MAC):
arm:at91emac
arm:cemac
arm:epe
arm:geminigmac
arm:enet
arm:cpsw
arm:emac(omac)
arm:emac(sunxi)
arm:npe
evbppc:temac
macppc:bm
macppc:gm
mips:aumac
mips:ae
mips:cnmac
mips:reth
mips:sbmac
playstation2:smap
powerpc:tsec
powerpc:emac(ibm4xx)
sgimips:mec
sparc:be
sf
ne(ax88190, dl10019)
awge
ep
gem
hme
smsh
mtd
sm
age
alc
ale
bce
cas
et
jme
lii
nfe
pcn
ste
stge
tl
xi
aue
mue
smsc
udav
url

Not tested (PHY):
amhphy
bmtphy
dmphy
etphy
glxtphy
ikphy
iophy
lxtphy
nsphyter
pnaphy
rdcphy
sqphy
tlphy
tqphy
urlphy
 1.143 03-Sep-2018  riastradh Rename min/max -> uimin/uimax for better honesty.

These functions are defined on unsigned int. The generic name
min/max should not silently truncate to 32 bits on 64-bit systems.
This is purely a name change -- no functional change intended.

HOWEVER! Some subsystems have

#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))

even though our standard name for that is MIN/MAX. Although these
may invite multiple evaluation bugs, these do _not_ cause integer
truncation.

To avoid `fixing' these cases, I first changed the name in libkern,
and then compile-tested every file where min/max occurred in order to
confirm that it failed -- and thus confirm that nothing shadowed
min/max -- before changing it.

I have left a handful of bootloaders that are too annoying to
compile-test, and some dead code:

cobalt ews4800mips hp300 hppa ia64 luna68k vax
acorn32/if_ie.c (not included in any kernels)
macppc/if_gm.c (superseded by gem(4))

It should be easy to fix the fallout once identified -- this way of
doing things fails safe, and the goal here, after all, is to _avoid_
silent integer truncations, not introduce them.

Maybe one day we can reintroduce min/max as type-generic things that
never silently truncate. But we should avoid doing that for a while,
so that existing code has a chance to be detected by the compiler for
conversion to uimin/uimax without changing the semantics until we can
properly audit it all. (Who knows, maybe in some cases integer
truncation is actually intended!)
 1.142 26-Jun-2018  msaitoh branches: 1.142.2;
Implement the BPF direction filter (BIOC[GS]DIRECTION). It provides backward
compatibility with BIOC[GS]SEESENT ioctl. The userland interface is the same
as FreeBSD.

This change also fixes a bug that the direction is misunderstand on some
environment by passing the direction to bpf_mtap*() instead of checking
m->m_pkthdr.rcvif.
 1.141 22-Jun-2018  msaitoh It's not required to include net/bpfdesc.h. Remove it.
 1.140 15-Dec-2016  ozaki-r branches: 1.140.8; 1.140.14;
Move bpf_mtap and if_ipackets++ on Rx of each driver to percpuq if_input

The benefits of the change are:
- We can reduce codes
- We can provide the same behavior between drivers
- Where/When if_ipackets is counted up
- Note that some drivers still update packet statistics in their own
way (periodical update)
- Moved bpf_mtap run in softint
- This makes it easy to MP-ify bpf

Proposed on tech-kern and tech-net
 1.139 02-Oct-2016  christos MFREE -> m_free
 1.138 10-Jun-2016  ozaki-r branches: 1.138.2;
Introduce m_set_rcvif and m_reset_rcvif

The API is used to set (or reset) a received interface of a mbuf.
They are counterpart of m_get_rcvif, which will come in another
commit, hide internal of rcvif operation, and reduce the diff of
the upcoming change.

No functional change.
 1.137 09-Feb-2016  ozaki-r Introduce softint-based if_input

This change intends to run the whole network stack in softint context
(or normal LWP), not hardware interrupt context. Note that the work is
still incomplete by this change; to that end, we also have to softint-ify
if_link_state_change (and bpf) which can still run in hardware interrupt.

This change softint-ifies at ifp->if_input that is called from
each device driver (and ieee80211_input) to ensure Layer 2 runs
in softint (e.g., ether_input and bridge_input). To this end,
we provide a framework (called percpuq) that utlizes softint(9)
and percpu ifqueues. With this patch, rxintr of most drivers just
queues received packets and schedules a softint, and the softint
dequeues packets and does rest packet processing.

To minimize changes to each driver, percpuq is allocated in struct
ifnet for now and that is initialized by default (in if_attach).
We probably have to move percpuq to softc of each driver, but it's
future work. At this point, only wm(4) has percpuq in its softc
as a reference implementation.

Additional information including performance numbers can be found
in the thread at tech-kern@ and tech-net@:
http://mail-index.netbsd.org/tech-kern/2016/01/14/msg019997.html

Acknowledgment: riastradh@ greatly helped this work.
Thank you very much!
 1.136 13-Apr-2015  riastradh Convert sys/dev to use <sys/rndsource.h>.
 1.135 10-Aug-2014  tls branches: 1.135.4;
Merge tls-earlyentropy branch into HEAD.
 1.134 27-Oct-2012  chs branches: 1.134.10;
split device_t/softc for all remaining drivers.
replace "struct device *" with "device_t".
use device_xname(), device_unit(), etc.
 1.133 22-Jul-2012  matt branches: 1.133.2;
Fix mii_statchg to take a 'struct ifnet *' instead of device_t. This fixes
problem with a common MDIO bus used for multiple interfaces.
Some drivers converted to CFATTACL_DECL_NEW.
 1.132 02-Feb-2012  tls Entropy-pool implementation move and cleanup.

1) Move core entropy-pool code and source/sink/sample management code
to sys/kern from sys/dev.

2) Remove use of NRND as test for presence of entropy-pool code throughout
source tree.

3) Remove use of RND_ENABLED in device drivers as microoptimization to
avoid expensive operations on disabled entropy sources; make the
rnd_add calls do this directly so all callers benefit.

4) Fix bug in recent rnd_add_data()/rnd_add_uint32() changes that might
have lead to slight entropy overestimation for some sources.

5) Add new source types for environmental sensors, power sensors, VM
system events, and skew between clocks, with a sample implementation
for each.

ok releng to go in before the branch due to the difficulty of later
pullup (widespread #ifdef removal and moved files). Tested with release
builds on amd64 and evbarm and live testing on amd64.
 1.131 05-Apr-2010  joerg branches: 1.131.8; 1.131.12;
Push the bpf_ops usage back into bpf.h. Push the common ifp->if_bpf
check into the inline functions as well the fourth argument for
bpf_attach.
 1.130 19-Jan-2010  pooka branches: 1.130.2; 1.130.4;
Redefine bpf linkage through an always present op vector, i.e.
#if NBPFILTER is no longer required in the client. This change
doesn't yet add support for loading bpf as a module, since drivers
can register before bpf is attached. However, callers of bpf can
now be modularized.

Dynamically loadable bpf could probably be done fairly easily with
coordination from the stub driver and the real driver by registering
attachments in the stub before the real driver is loaded and doing
a handoff. ... and I'm not going to ponder the depths of unload
here.

Tested with i386/MONOLITHIC, modified MONOLITHIC without bpf and rump.
 1.129 15-Sep-2009  dyoung Simplify activation routines: don't call mii_activate(), it's a
no-op. Don't block interrupts, if_deactivate() does it.
Compile-tested, only.
 1.128 05-Sep-2009  tsutsui Replace shutdownhook_establish(9) with pmf_device_register1(9) in
MI epconfig() and ep_detach(), and remove pmf(9) calls in pcmcia attachment.
Tested on ep0 at pci, but pcmcia attachment is untested.
 1.127 27-Aug-2008  christos device_t changes, pmf, minor knf.
 1.126 28-Apr-2008  martin branches: 1.126.2; 1.126.6;
Remove clause 3 and 4 from TNF licenses
 1.125 08-Apr-2008  cegger branches: 1.125.2; 1.125.4;
use aprint_*_dev and device_xname
 1.124 19-Oct-2007  ad branches: 1.124.16;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.123 27-Aug-2007  dyoung branches: 1.123.2; 1.123.6;
Constify: use CLLADDR() instead of LLADDR() wherever possible.
 1.122 09-Jul-2007  ad branches: 1.122.2; 1.122.6;
Merge some of the less invasive changes from the vmlocking branch:

- kthread, callout, devsw API changes
- select()/poll() improvements
- miscellaneous MT safety improvements
 1.121 04-Mar-2007  christos branches: 1.121.2; 1.121.4;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.120 16-Nov-2006  christos branches: 1.120.4;
__unused removal on arguments; approved by core.
 1.119 12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.118 07-Sep-2006  dogcow branches: 1.118.2; 1.118.4;
remove more vestiges of CCITT, LLC, HDLC, NS, and NSIP.
 1.117 11-Jul-2006  peter Add power hooks for "ep* at pcmcia?".

ok christos@
 1.116 07-Jun-2006  nakayama branches: 1.116.2;
Add void cast to functions whose return values are ignored.
 1.115 20-Feb-2006  thorpej branches: 1.115.2; 1.115.8;
Use device_is_active() rather than testing dv_flags for DVF_ACTIVE
directly.
 1.114 24-Dec-2005  perry branches: 1.114.2; 1.114.4; 1.114.6;
Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.113 11-Dec-2005  christos merge ktrace-lwp.
 1.112 30-May-2005  christos branches: 1.112.2;
- add missing const
- fix variable shadowing
- remove unneeded casts
 1.111 27-Feb-2005  perry nuke trailing whitespace
 1.110 04-Feb-2005  perry de-__P
 1.109 11-Jan-2005  briggs branches: 1.109.2; 1.109.4;
In epshutdown(), do not attempt to disable the interface when stopping it
because we're about to write to it again (with a global reset). Disable
the interface explicitly after the reset is written.
 1.108 30-Oct-2004  thorpej When adding/deleting multicast addresses, only whack the address
filter if the interface is marked RUNNING.

Fixes kern/27678.
 1.107 09-Aug-2004  mycroft Eliminate most 8-bit access. Just the data in/out path remains.
 1.106 31-Jan-2003  thorpej branches: 1.106.2; 1.106.6;
Use aprint_*().
 1.105 20-Jan-2003  simonb Remove variables that are only assigned too but not referenced.
 1.104 22-Oct-2002  fair Change the "dontcare bits" argument to ifmedia_init() to IFM_IMASK
so that it is possible select PHY instances other than the first
one (instance zero), if there is more than one PHY attached.
 1.103 08-Jun-2002  yamt make auto const variables static.
 1.102 28-Dec-2001  christos branches: 1.102.8;
Clean up the C_ and S_ constants. We don't really need two sets of them.
Also make the interrupt handler for older 3com cards look like the xl one.
I.e. don't ack the interrupt latch bit before checking if it is set.
At the same time, introduce constants for the watched interrupts, so that
we don't copy them all over the place.
 1.101 15-Dec-2001  soren Use bus_size_t's for bus space read/write offsets.
 1.100 13-Nov-2001  lukem add/cleanup RCSID
 1.99 10-Nov-2001  perry trivially rename some macro parameters to avoid lint warnings.
 1.98 16-Sep-2001  wiz branches: 1.98.2;
Spell 'occurred' with two 'r's.
 1.97 27-Jul-2001  thorpej branches: 1.97.2;
All CORKSCREWs have MII.
 1.96 20-Jul-2001  thorpej The EEPROM registers/bits are different on the Corkscrew (3c515). Adjust
for this.
 1.95 07-Jul-2001  thorpej branches: 1.95.2;
bzero -> memset
 1.94 07-Jul-2001  thorpej bcopy -> strcpy
 1.93 16-May-2001  jdolecek Make sure to allocate big enough mbuf data area before elevating
interrupt priority, to avoid allocating additional mbufs on
splsched(). Move some other misc bits out of splched()-guarded
section. This should make the code a bit more friendly wrt e.g.
clock interrupts. Sligh performance improvement was observed with
this change (like 1-2% on slow machine), even.

This also fixes ancient kern/2478 by Bill Sommerfeld.
 1.92 14-May-2001  jdolecek epintr(): eliminate write-only variable 'addrandom'
 1.91 14-May-2001  jdolecek remove unneeded #includes, fix typo
 1.90 14-May-2001  jdolecek do not use the synchronous read mode for MCA 3c529
 1.89 22-Mar-2001  jdolecek Add MCA ep(4) attachment, for 3Com 3c529-type cards. Tested with 3c529-TP,
provided to me by David Brownlee (thanks!).

Performance of this card is quite poor on my PS/2 with 386DX, like 100KB/s
at best, but as low as 5KB/s when transferring bigger files due to
packet overruns. It would be good to revisit this later, probably by
teaching the ic code to use RX Early.
 1.88 22-Mar-2001  jdolecek convert to use ether_ioctl()
fix bunch of typos
 1.87 21-Feb-2001  jdolecek branches: 1.87.2;
make some more constant arrays 'const'
 1.86 14-Dec-2000  thorpej ALTQ'ify.
 1.85 15-Nov-2000  thorpej Move bpfattach()/bpfdetach() calls into ether_ifattach()/ether_ifdetach().
 1.84 01-Oct-2000  thorpej Move the check for "promisc + unicast + not for us" into ether_input(),
and change Ethernet drivers to always pass all received frames to
ether_input() (with a few exceptions, which are documented in the
code).
 1.83 28-Sep-2000  tsutsui 6 -> ETHER_ADDR_LEN
 1.82 21-Aug-2000  thorpej Use splsched() instead of splhigh(), and explain why in a comment,
as well as document a pitfall of the approach being used.
 1.81 29-May-2000  jhawk For all network drivers that call ether_ifattach(), and also
have _detach() functions:
Ensure that softc keeps state about whether the attach succeeded,
and make the detach function return immediately if the attach did
not complete.
 1.80 07-May-2000  martin branches: 1.80.2;
Avoid stomping on the W0_CONFIG_CTRL register which seems not to be
implemented on EISA cards. This makes a 3Com 3C597 Fast Etherlink TX
work for me at last, fixing PR kern/7067.
 1.79 30-Mar-2000  augustss Remove register declarations.
 1.78 23-Mar-2000  thorpej New callout mechanism with two major improvements over the old
timeout()/untimeout() API:
- Clients supply callout handle storage, thus eliminating problems of
resource allocation.
- Insertion and removal of callouts is constant time, important as
this facility is used quite a lot in the kernel.

The old timeout()/untimeout() API has been removed from the kernel.
 1.77 06-Mar-2000  thorpej No longer necessary to futz with ifp->if_baudrate here.
 1.76 25-Feb-2000  itojun when change mbuf type, clear m_pkthdr so that we do not get panic with
old data in pointer fields. NOTE: we'll extend m_pkthdr field soon.

Wondering: do mbuf pre-allocation code in elink3.c really buy us much
performance? it comes with code duplicate/synchronization problem with
sys/mbuf.h...
 1.75 08-Feb-2000  enami - Bail out from attach stage if failed to enable card, number of iospace
or memspace is unexpected, failed to map iospace or failed to configure
the controller properly.
- Disestablish an interrupt handler if failed to enable card.
 1.74 03-Feb-2000  enami Detach MII if there is.
 1.73 02-Feb-2000  thorpej Don't dry to diving MIIF_NOISOLATE in the PHY drivers. Instead, pass
flags down from the parent to child vi mii_attach().
 1.72 02-Feb-2000  augustss Detach rnd source in ep_detach(). Check for DVF_ACTIVE in epintr();
 1.71 02-Feb-2000  augustss Make sure to untimeout() things on detach.
 1.70 02-Feb-2000  augustss Move detach operations around a little to simplify (and perhaps get it
right?). Prompted by Jason, itojun and myself.
 1.69 02-Feb-2000  thorpej Bring some order to the chaos which was the MII code function naming
"conventions".
 1.68 02-Feb-2000  augustss Make sure to get rid of shutdown hook and ttach media on detach.
 1.67 19-Nov-1999  thorpej Use the common MII bit-bang module.
 1.66 12-Nov-1999  thorpej Call mii_down() as appropriate.
 1.65 04-Nov-1999  thorpej Revert this part of rev 1.59:
- Be more conservative when resetting the interface after a transmit error.

It caused the interface to totally wedge on the (somewhat common) transmit
FIFO underrun condition.
 1.64 04-Nov-1999  thorpej Adapt to mii_phy_probe() change.
 1.63 30-Oct-1999  enami branches: 1.63.2;
remmove unncecessary empty line.
 1.62 30-Oct-1999  enami Call epstop at the beginning of epinit, especially to make sure that
ep_tick is untimeouted before new one is scheduled. This makes 3C574-TX
works at least in 10Mb/s mode.
 1.61 20-Oct-1999  enami fix typo in previous commit.
 1.60 20-Oct-1999  enami cosmetic changes before i do some functional changes.
 1.59 11-Oct-1999  thorpej branches: 1.59.2; 1.59.4;
- Encapsulate the EEPROM reading code into ep_read_eeprom(), and use
the correct "read eeprom" opcode on the RoadRunner (which has a larger
EEPROM, and thus needs a different opcode to make room for the larger
offsets).
- Reset and enable the MII before probing for PHYs, and reset and enable
the MII in epinit().
- Be more conservative when resetting the interface after a transmit error.

Based on PR #8331, from Ryoji KATO.

Closer on 3c574, probably will work fine with the 3CCFEM556BI (which
won't have an older rev TDK Semi PHY, and which was tested by the author
of the PR).
 1.58 18-May-1999  thorpej branches: 1.58.2;
Rework layer 2 protocol input routines. Instead of calling e.g. ether_input()
directly, call the function pointer (*if_input)(ifp, m). The input routine
expects the packet header to be at the head of the packet, and will adjust
as necessary. Privatize the layer 2 input and output routines, allowing
*_ifattach() to set them up as appropriate.
 1.57 20-Apr-1999  jonathan Calling DELAY() during polling for command completion of the normal
per-packet discard of every received packet increases latency and
decrease throughput. INstead, Spin on S_COMMAND_IN_PROGESS for enough
iterations as the expected time to completion. Only do DELAY()/poll
loops (as suggested by Jason Thorpe) if spinning fails.
Take PCI as fastest case and compute worst-case estimate.

Shorten DELAY() in S_COMMAND_COMPLETE polling-loop up 10, loop-count
down. to speed up epreset() completion (m/c filter change, ifup/ipdown, etc).
 1.56 19-Apr-1999  jonathan * Make doubly sure that the ep shutdownhooks are run at splnet() or above.
* Clear the `enabled' bit in the softc so late hardware interrupts
(e.g., just after the full reset) done as part of shutdown) are dropped.
* Eliminate loops that poll forever on S_COMMAND_IN_PROGRESS to complete.
Add inline function with bounded loopcount plus small delay, to avoid
bugs in EISA hardware which never sets S_COMMAND_IN_PROGRESS.
Use for both TX_RESET/RX_RESET/GLOBAL_RESET cmds, and polling for
discard-Rx completion
 1.55 13-Apr-1999  jonathan Endian-ness bugfix for elink3 on big-endian hosts.
Big-endian CPUs should use bus_space_{read,write}_multi_stream methods
to PIO packet data to NIC in 16-bit or 32-bit chunks.
Make it so.
Since we don't have stream methods on all ports yet (esp. i386), use
the bus_space_{read,write}_multi methods if the compile-time
stream-method feature-test macro is not set.
Originally from tsubai@netbsd.org, via HAYAKAWA koichi's cardbus patches.
 1.54 25-Mar-1999  thorpej branches: 1.54.2;
Use ETHER_*_LEN constants from <net/if_ether.h> instead of defining them
ourselves.
 1.53 28-Feb-1999  explorer Update to slightly altered rnd_attach_source() api
 1.52 17-Feb-1999  thorpej Avoid initializing the interface in the SIOCSIFFLAGS if ! UP and ! RUNNING.
 1.51 12-Dec-1998  mycroft Simplify argument to MGET(), to generate better code.
 1.50 18-Nov-1998  thorpej branches: 1.50.2;
Now that the *_activate() functions don't do things which are attachment
specific, move them into the chipset drivers.
 1.49 17-Nov-1998  thorpej Expose the "enable" and "disable" functions so that the front-ends can
access them.
 1.48 16-Nov-1998  thorpej Fix some whitespace lossage, canonicalize some media names.
 1.47 04-Nov-1998  fvdl Add the 'ex' driver, a DMA driver for 3Com 90x and 90xB cards. Rename
constants from EP_ to ELINK_ since they're now used in the ex driver as well.
 1.46 28-Aug-1998  thorpej When determining the default media on the Vortex/Boomerang, don't pick
the full-duplex variant. XXX We should check the EEPROM for "default to
full-duplex".
 1.45 26-Aug-1998  thorpej For non-MII Vortex/Boomerang, set full-duplex in the MAC CONTROL register
in epsetmedia() if full-duplex is selected (new feature on these cards!)

On MII Boomerangs, set the full-duplex bit in MAC CONTROL in the statchg
callback from the MII layer. Should fix full-duplex on these cards.
 1.44 17-Aug-1998  thorpej First-crack at RoadRunner (3c574-TX 10/100Mbps PCMCIA). Doens't yet use
any of the RoadRunner speed hacks.
 1.43 16-Aug-1998  thorpej Oops, back out something that I didn't intend to commit.
 1.42 15-Aug-1998  thorpej The 3c515 (Corkscrew) and 3c574 (RoadRunner) have their Window 1 registers
offset! Define an inline function to compute the Window 1 register offset
and use it.
 1.41 12-Aug-1998  thorpej Completely rewrite media selection. Add support for the MII/PHY on
the 3Com 3c905-TX and 3c905-T4. Fix handling of the MII on the
3c595-MII and 3c597-MII (can't talk to the PHYs on these cards; just
use "manual" for the external MII port).

Fixes kern/4782 (Chris Demetriou).
 1.40 05-Jul-1998  jonathan defopt NS, NSIP.
 1.39 05-Jul-1998  jonathan defopt INET, NETATALK.
 1.38 04-Mar-1998  augustss For the Rx:Tx split message change "(undefined)" to "3:5".
 1.37 12-Jan-1998  thorpej Adjust for config changes.
 1.36 18-Oct-1997  jonathan Protect #ifdef DEBUG printfs with a run-time teson a patchable variable
(epdebug), as per Jason Thorpe's comments.
 1.35 15-Oct-1997  explorer Add and/or update rnd_*() hooks
 1.34 14-Oct-1997  thorpej Pull down from marc-pcmcia branch:

Minor tweaks to deal with PCMCIA differences, and support for power
management.
 1.33 30-Jul-1997  jonathan Initialize local variable 'j' in eeprombusy() to pacify gcc -O (not -O2)
on i386.
 1.32 14-May-1997  thorpej branches: 1.32.4;
Make sure we're in register window 0 before attempting EEPROM access,
pointed out by Matthias Drochner.
 1.31 11-May-1997  jonathan Set TX-available threshhold in epinit() just before enabling interrupts,
so TX_AVAIL intrs are enabled for root-on-NFS kernels.
Tested (and required) on 3c595TX with root-on-NFS kernel booted from floppy.
 1.30 28-Apr-1997  mycroft Oops; forgot to GC the last mbuf allocated when out of clusters.
 1.29 27-Apr-1997  jonathan * Tidy PHY [sic] selection code in epsetmedia().

* epinit() had both explicit xcvr selection for 3c589 and a call
to epsetmedia(). The first is redundant; delete it, and EP_COAX_DEFAULT.

* Update comments to reflect 3c589 and 3c509B fixes. Fix typos.
 1.28 27-Apr-1997  veego - Replace the check for EP_BUS_PCMCIA in epsetmedia with a check for
EP_CHIPSET_3C509 and change it a bit so it works now with the 3c509
and still works with the 3c589.
- KNF
 1.27 24-Apr-1997  mycroft Fix typo in previous.
 1.26 24-Apr-1997  mycroft If we fail to allocate a cluster to hold a large packet, simply
drop it rather than using a chain of tiny mbufs.
 1.25 23-Apr-1997  cjs Smaller, cleaner code for aligning struct ip on receipt.
 1.24 22-Apr-1997  cjs Align struct ip on incoming packets for all types of cards, not just
32-bit ones.
 1.23 07-Apr-1997  jonathan Remove IFF_LINK[01] "connector" support.
Add if_media support. Still missing a software autosense FSM.
 1.22 30-Mar-1997  jonathan Add ifmedia hooks: include <ifmedia.h> and add sc_media to softc.
 1.21 15-Mar-1997  is New ARP system, supports IPv4 over any hardware link.

Some of the stuff (e.g., rarpd, bootpd, dhcpd etc., libsa) still will
only support Ethernet. Tcpdump itself should be ok, but libpcap needs
lot of work.

For the detailed change history, look at the commit log entries for
the is-newarp branch.
 1.20 18-Feb-1997  jonathan Move if_ep media-sense code from front ends to inside back end,
to prepare for if_media, and to support EISA 3c59x cards:

* change epconfig() to take a short that encodes the chipset
type (3c509, or Demon/Vortex/Boomerang).
* add distinct 3c509 and Demon/Vortex/Boomerang media-sense
functions to back end.
* Add EISA match/attach support for the 3c592 and 3c597
(Demon) cards as well as the 3c509-comatibl EISA 3c509/3c579.

* Assume that ISA and ISA PnP cards are 3c509-style, until
proof to the contrary (e.g. large packet support).

Tested on 3c595, 3c590, and 3c509b. Not tested on 3c515 or Demon.
 1.19 16-Feb-1997  jonathan * Add ep_complete_cmd() function, to issue commands that perform a reset
(RX_RESET, TX_RESET, GLOBAL_RESET).
Commands issued while a reset is in progress may be dropped. The driver
must wait until resets are complete; ep_complete_cmd() does so.
* Change RX_RESET, TX_RESET, GLOBAL_RESET to use ep_complete_cmd().

* Revert epconfig() to use inline RX_RESET, TX_RESET.
That avoids accidentally setting IFF_UP, which breaks both diskless boot,
and "halt" commands issued before the interface is brought up.
 1.18 31-Dec-1996  jonathan branches: 1.18.4;
Use DELAY() after doing a TX_RESET or RX_RESET command.
Newer boards (e.g., Vortex) take time to reset, and wedge on some machines.
Polling on S_COMMAND_IN_PROGRESS would be better, but that doesn't
work with xx_RESET commands on 3c509s.
 1.17 30-Dec-1996  jonathan * make sure 100mbit media-present bits don't collied with 3c509
CONFIG_CNTRL bits by making the "conn" argument to epconfig()
a u_int, not a u_int16_t, and by defining 100mbit media
bits in the upper 16 bits.

A redesigned interface that fixes this properly is in the pipeline.
 1.16 29-Dec-1996  jonathan * add epshutdown(), and establish as shutdown hook: see multiboot
comments in pr port-i386/2358: "if_ep/3C590 no longer working"
* Only call Vortex media-config code on PCI-attached devices, until
we know if it works on ISA and EISA large-packet devices also.
* Fix typo in printf of MAC address
 1.15 29-Dec-1996  jonathan * Add 100Mbit xcvr flags to epconfig():
look for 100mbit Xcvrs, print their names, add to ep_connectors.

* Print 10baseT as 10baseT, since media name (utp) is no longer a unique
transceiver type.

* Redo FIFO memory size printing, also show Tx/Rx split (xxx isa 3c509?).

* Print MAC address on a separate line, with 100Mbit media and fifo-ram
info it no longer fits on the same line as media types.

* Comment the fact that the "connection" media-selection code just doesn't
grok 100Mbit media.

* add code to look for 3c59x/3c90x media-select and autoconfig bits, though
we don't yet dynamically probe media when the autoconfig bit is set
(see previous bullet).

* XXX the whole connector/media code should be redone, perhaps a' la
the BSDI ifmedia design.
 1.14 07-Dec-1996  cjs Print the memory size on startup.
Add newline to `Interface disabled' printf and clean up formatting.
Change packet read/write code to align all reads and writes into
memory to an appropriate boundary for the I/O size. This also fixes
a bug where the trailing unaligned bytes (1-3 of them) would be
put in an additional mbuf even if there was enough space for them
in the one we were currently filling.
This has been tested on a 3c905 in an Alpha (32-bit I/O, alignment
required), a 3c905 in an i386 (32-bit I/O, alignment not required)
and a 3c509 in an i386 (16-bit I/O, alignment not required). It
should be tested on a 3c509 in an Alpha with an ISA bus, if somone
can manage to get the two items together.
There are still some bugs in the driver relating to initialisation;
on my Alpha with a 3c905 you need to do an `ifconfig ep0 down;
ifconfig ep0 up' after the initial ifconfig to make it start working.
Apparently there are also some problems with a 3c579 in an i386,
although a 3c905 in an i386 works just fine.
 1.13 22-Nov-1996  jonathan * 3c509s drop the low-oder bits of EP_THRESH_DISABLE (2047) on a write,
and the result reads back as zero. Mask probe code accordingly.
 1.12 17-Nov-1996  jonathan Fix for hanging 3com ``large packet'' (100Mbit) Etherlink-III devices:
* Add a slot in the softc, ep_pktlenshift, to indicate that
a board implements ``large packets'' (FDDI-sized frames) and
therefore implicitly shifts the argument to packet-length commands
by two bits to fit a 13-bit length in an 11-bit command argument field.

* Change the reset of station-mask filterto be independent of bus-type
(e.g.,. for 3c515)

* Replace the "2044" constant used to disable TX threshold interrupts
on 3c509-generation cards with a #define. Use 2047 instead,
since that works on the large-packet cards (Vortex, Demon, Boomerang)
and 2044 doesn't.

* Add code to epconfing to probe for large-packet support,
set the softc appropriately, and shift packet sizes in commands
by ep_pktlenshift to compensate for the implicit shift.

* Tweak the epconfig() code to avoid hanging on startup.
Set the Tx threshold to interrupt when there's space for
a maximal-sized ether frame, then do epinit() then epstop(),
instead of just the Tx and Rx reset. Required on at least a 3c595.

Tested on a 3c595, but not on 3c509-generation hardware.
 1.11 21-Oct-1996  thorpej New bus.h implementation/interface:
- No more distinction between i/o-mapped and memory-mapped
devices. It's all "bus space" now, and space tags
differentiate the space with finer grain than the
bus chipset tag.
- Add memory barrier methods.
- Implement space alloc/free methods.
- Implement region read/write methods (like memcpy to/from
bus space).
This interface provides a better abstraction for dealing with
machine-independent chipset drivers.
 1.10 13-Oct-1996  christos backout kprintf changes
 1.9 10-Oct-1996  christos - printf -> kprintf, sprintf -> ksprintf
 1.8 29-Sep-1996  christos Apply PR/2661 [from Jonathan Stone]
 1.7 14-May-1996  thorpej branches: 1.7.4;
Be more careful with types, and pull in <machine/intr.h>
 1.6 10-May-1996  thorpej Update Herb's e-mail address; beer.org feels a lot more friendly.
 1.5 07-May-1996  thorpej Changed struct ifnet to have a pointer to the softc of the underlying
device and a printable "external name" (name + unit number), thus eliminating
if_name and if_unit. Updated interface to (*if_watchdog)() and (*if_start)()
to take a struct ifnet *, rather than a unit number.
 1.4 03-May-1996  christos Move epstop prototype to the header file.
 1.3 03-May-1996  christos - include <sys/systm.h>
- fix prototype of epmbuffill()
- fix typo of epxstat -> eptxstat
 1.2 30-Apr-1996  thorpej Convert the Etherlink III (ep) driver to use <machine/bus.h>.
 1.1 25-Apr-1996  thorpej Break up the ep driver into isa, eisa, and pci front-ends and a
bus-independent core driver. Tested on all three bus types, including
an isa 3c509 masquerading as an eisa device (use ep* at eisa? slot ? in
your kernel config file to catch this one).
XXX Driver still needs to be converted to <machine/bus.h>
 1.7.4.2 19-Mar-1997  mycroft Pull up fix for `sniper bug', which can cause packets to be accepted erroneously.
 1.7.4.1 04-Mar-1997  mycroft Recognize 3c900 and 3c905 cards.
 1.18.4.4 09-Mar-1997  is netinet/if_ether.h => netinet/if_inarp.h
 1.18.4.3 27-Feb-1997  is Removed #include <route.h> and #include <netisr.h>. They're not needed, and
the latter will go away soon.
 1.18.4.2 20-Feb-1997  is Merged in recent changes from Trunk.
 1.18.4.1 07-Feb-1997  is Snapshot of new ARP code.

Our old ARP code was hardwired for 6-byte length medium
addresses, while the protocol is designed for any size.

This snapshot contains a first hack at getting rid of
Ethernet specific data structures. The ep driver is updated
(and tested on the PCI bus), the iy and fpa drivers have been
updated, but not real life tested yet.

If you want to test this with other drivers, you have to update
them first yourself, and probably tag the relevant directories.
Better contact me if you want to do this.
 1.32.4.9 14-Oct-1997  thorpej Garbage-collect a hack no longer needed since the compiler has been
fixed.
 1.32.4.8 14-Oct-1997  thorpej Rearrange the disable functions slightly so that an interface that
interfaces that don't have a disable hook will never be marked "disabled".

Now, once an interface has been marked "enabled" by the enable function,
it will remain marked as such for the duration of the kernel's lifetime.
 1.32.4.7 06-Oct-1997  thorpej Fix a brain-o in my last power management changes. Specifically, allow
the media callbacks to be used while the interface is powered off. If
the interface is powered off, return "none" in response to a "get media",
and in the case of "set media", just return success, since the init routine
will properly program the hardware when power is enabled. If we return
an error in the powered off case, ifconfig(8) will lose because it performs
the "set address" (which will enable power on a disabled interface) after
parsing the entire command line.
 1.32.4.6 29-Sep-1997  thorpej Fix a few bugs in the enable/disable hook logic:
- Place the code to enable/disable in functions and use them, rather than
duplicating it in a few places. Make sure the "enabled" flag is set
properly even if there is no hardware enable hook.
- Add additional checks for the "enabled" flag so that we don't attempt to
write hardware registers when the card power is turned off.
 1.32.4.5 29-Sep-1997  thorpej Make the "enable" and "disable" hooks take pointers to the softc, rather
than void * and a separately specified argument.
 1.32.4.4 27-Sep-1997  marc add calls to enable/disable hooks
 1.32.4.3 29-Aug-1997  thorpej Remove some highly machine-dependent debugging code.
 1.32.4.2 23-Aug-1997  thorpej Update marc-pcmcia branch from trunk.
 1.32.4.1 30-Jul-1997  marc added pcmcia infrastructure and a few devices
 1.50.2.1 11-Dec-1998  kenh The beginnings of interface detach support. Still some bugs, but mostly
works for me.

This work was originally by Bill Studenmund, and cleaned up by me.
 1.54.2.3 11-May-2000  he Pull up revision 1.80 (requested by martin):
Make the 3Com 3C597 Fast Etherlink TX EISA card work. Fixes PR#7067.
 1.54.2.2 06-Feb-2000  he Pull up revisions 1.59-1.63,1.65 (requested by enami):
Add support for the 3Com 3c574. Partially based on PR#8331.
 1.54.2.1 27-Apr-1999  perry branches: 1.54.2.1.2;
pullup 1.54->1.57 (Jonathan Stone)
 1.54.2.1.2.1 21-Jun-1999  thorpej Sync w/ -current.
 1.58.2.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.59.4.1 15-Nov-1999  fvdl Sync with -current
 1.59.2.6 27-Mar-2001  bouyer Sync with HEAD.
 1.59.2.5 12-Mar-2001  bouyer Sync with HEAD.
 1.59.2.4 05-Jan-2001  bouyer Sync with HEAD
 1.59.2.3 22-Nov-2000  bouyer Sync with HEAD.
 1.59.2.2 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.59.2.1 20-Oct-1999  thorpej Sync w/ trunk.
 1.63.2.1 05-Nov-1999  mycroft Pull up 1.65 manually, to skip over API changes.
 1.80.2.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.87.2.8 11-Nov-2002  nathanw Catch up to -current
 1.87.2.7 20-Jun-2002  nathanw Catch up to -current.
 1.87.2.6 08-Jan-2002  nathanw Catch up to -current.
 1.87.2.5 14-Nov-2001  nathanw Catch up to -current.
 1.87.2.4 21-Sep-2001  nathanw Catch up to -current.
 1.87.2.3 24-Aug-2001  nathanw Catch up with -current.
 1.87.2.2 21-Jun-2001  nathanw Catch up to -current.
 1.87.2.1 09-Apr-2001  nathanw Catch up with -current.
 1.95.2.3 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.95.2.2 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.95.2.1 03-Aug-2001  lukem update to -current
 1.97.2.1 01-Oct-2001  fvdl Catch up with -current.
 1.98.2.1 12-Nov-2001  thorpej Sync the thorpej-mips-cache branch with -current.
 1.102.8.1 20-Jun-2002  gehenna catch up with -current.
 1.106.6.1 24-Jan-2005  he Pull up revision 1.108 (requested by thorpej in ticket #939):
When adding or deleting multicast addresses, only change
the address filter if the interface is marked RUNNING.
Fixes PR#27678.
 1.106.2.8 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.106.2.7 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.106.2.6 04-Feb-2005  skrll Sync with HEAD.
 1.106.2.5 17-Jan-2005  skrll Sync with HEAD.
 1.106.2.4 02-Nov-2004  skrll Sync with HEAD.
 1.106.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.106.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.106.2.1 12-Aug-2004  skrll Sync with HEAD.
 1.109.4.2 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.109.4.1 12-Feb-2005  yamt sync with head.
 1.109.2.1 29-Apr-2005  kent sync with -current
 1.112.2.4 27-Oct-2007  yamt sync with head.
 1.112.2.3 03-Sep-2007  yamt sync with head.
 1.112.2.2 30-Dec-2006  yamt sync with head.
 1.112.2.1 21-Jun-2006  yamt sync with head.
 1.114.6.2 07-Jun-2006  kardel Sync with head.
 1.114.6.1 22-Apr-2006  simonb Sync with head.
 1.114.4.1 09-Sep-2006  rpaulo sync with head
 1.114.2.1 01-Mar-2006  yamt sync with head.
 1.115.8.1 19-Jun-2006  chap Sync with head.
 1.115.2.3 14-Sep-2006  yamt sync with head.
 1.115.2.2 11-Aug-2006  yamt sync with head
 1.115.2.1 26-Jun-2006  yamt sync with head.
 1.116.2.1 13-Jul-2006  gdamore Merge from HEAD.
 1.118.4.2 10-Dec-2006  yamt sync with head.
 1.118.4.1 22-Oct-2006  yamt sync with head
 1.118.2.1 18-Nov-2006  ad Sync with head.
 1.120.4.1 12-Mar-2007  rmind Sync with HEAD.
 1.121.4.1 11-Jul-2007  mjf Sync with head.
 1.121.2.3 23-Oct-2007  ad Sync with head.
 1.121.2.2 09-Oct-2007  ad Sync with head.
 1.121.2.1 01-Jul-2007  ad Adapt to callout API change.
 1.122.6.2 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.122.6.1 03-Sep-2007  jmcneill Sync with HEAD.
 1.122.2.1 03-Sep-2007  skrll Sync with HEAD.
 1.123.6.1 25-Oct-2007  bouyer Sync with HEAD.
 1.123.2.1 06-Nov-2007  matt sync with HEAD
 1.124.16.2 28-Sep-2008  mjf Sync with HEAD.
 1.124.16.1 02-Jun-2008  mjf Sync with HEAD.
 1.125.4.5 11-Aug-2010  yamt sync with head.
 1.125.4.4 11-Mar-2010  yamt sync with head
 1.125.4.3 16-Sep-2009  yamt sync with head
 1.125.4.2 04-May-2009  yamt sync with head.
 1.125.4.1 16-May-2008  yamt sync with head.
 1.125.2.1 18-May-2008  yamt sync with head.
 1.126.6.1 19-Oct-2008  haad Sync with HEAD.
 1.126.2.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.130.4.1 30-May-2010  rmind sync with head
 1.130.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.131.12.1 18-Feb-2012  mrg merge to -current.
 1.131.8.2 30-Oct-2012  yamt sync with head
 1.131.8.1 17-Apr-2012  yamt sync with head
 1.133.2.3 03-Dec-2017  jdolecek update from HEAD
 1.133.2.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.133.2.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.134.10.1 07-Apr-2014  tls Be a little more clear and consistent about harvesting entropy from devices:

1) deprecate RND_FLAG_NO_ESTIMATE

2) define RND_FLAG_COLLECT_TIME, RND_FLAG_COLLECT_VALUE

3) define RND_FLAG_ESTIMATE_TIME, RND_FLAG_ESTIMATE_VALUE

4) define RND_FLAG_DEFAULT: RND_FLAG_COLLECT_TIME|
RND_FLAG_COLLECT_VALUE|RND_FLAG_ESTIMATE_TIME

5) Make entropy harvesting from environmental sensors a little more generic
and remove it from individual sensor drivers.

6) Remove individual open-coded delta-estimators for values from a few
places in the tree (uvm, environmental drivers).

7) 0 -> RND_FLAG_DEFAULT, actually gather entropy from various drivers
that had stubbed out code, other minor cleanups.
 1.135.4.5 05-Feb-2017  skrll Sync with HEAD
 1.135.4.4 05-Oct-2016  skrll Sync with HEAD
 1.135.4.3 09-Jul-2016  skrll Sync with HEAD
 1.135.4.2 19-Mar-2016  skrll Sync with HEAD
 1.135.4.1 06-Jun-2015  skrll Sync with HEAD
 1.138.2.2 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.138.2.1 04-Nov-2016  pgoyette Sync with HEAD
 1.140.14.4 26-Jan-2019  pgoyette Sync with HEAD
 1.140.14.3 06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.140.14.2 28-Jul-2018  pgoyette Sync with HEAD
 1.140.14.1 25-Jun-2018  pgoyette Sync with HEAD
 1.140.8.1 26-Jul-2018  snj Pull up following revision(s) (requested by msaitoh in ticket #938):
sys/arch/acorn32/podulebus/if_ie.c: revision 1.41
sys/arch/amiga/dev/if_es.c: revision 1.58
sys/arch/amiga/dev/if_qn.c: revision 1.45
sys/arch/arm/at91/at91emac.c: revision 1.20
sys/arch/arm/ep93xx/epe.c: revision 1.37
sys/arch/emips/ebus/if_le_ebus.c: revision 1.14
sys/arch/emips/ebus/if_le_ebus.c: revision 1.15
sys/arch/mac68k/dev/if_mc.c: revision 1.46
sys/arch/macppc/dev/am79c950.c: revision 1.39
sys/arch/newsmips/apbus/if_sn.c: revision 1.40
sys/arch/next68k/dev/mb8795.c: revision 1.59
sys/arch/playstation2/dev/if_smap.c: revision 1.25
sys/arch/playstation2/dev/if_smap.c: revision 1.26
sys/arch/sun2/dev/if_ec.c: revision 1.28
sys/arch/sun3/dev/if_ie.c: revision 1.63
sys/arch/x68k/dev/if_ne_intio.c: revision 1.19
sys/arch/xen/xen/if_xennet_xenbus.c: revision 1.75
sys/arch/xen/xen/xennetback_xenbus.c: revision 1.63
sys/dev/bi/if_ni.c: revision 1.45
sys/dev/cadence/if_cemac.c: revision 1.12
sys/dev/ic/am7990.c: revision 1.78
sys/dev/ic/am79900.c: revision 1.27
sys/dev/ic/an.c: revision 1.67
sys/dev/ic/cs89x0.c: revision 1.40
sys/dev/ic/dm9000.c: revision 1.13
sys/dev/ic/dm9000.c: revision 1.14
sys/dev/ic/dp8390.c: revision 1.88
sys/dev/ic/elink3.c: revision 1.141
sys/dev/ic/elinkxl.c: revision 1.122
sys/dev/ic/hme.c: revision 1.98
sys/dev/ic/i82586.c: revision 1.77
sys/dev/ic/lance.c: revision 1.53
sys/dev/ic/mb86950.c: revision 1.27
sys/dev/ic/mb86960.c: revision 1.86
sys/dev/ic/mtd803.c: revision 1.34
sys/dev/ic/pdq_ifsubr.c: revision 1.59
sys/dev/ic/rrunner.c: revision 1.86
sys/dev/ic/seeq8005.c: revision 1.58
sys/dev/ic/sgec.c: revision 1.47
sys/dev/ic/smc90cx6.c: revision 1.72
sys/dev/ic/smc91cxx.c: revision 1.96
sys/dev/ic/tropic.c: revision 1.49
sys/dev/ic/wi.c: revision 1.245
sys/dev/isa/if_eg.c: revision 1.93
sys/dev/isa/if_el.c: revision 1.95
sys/dev/isa/if_iy.c: revision 1.101
sys/dev/ofw/ofnet.c: revision 1.58
sys/dev/pci/if_alc.c: revision 1.27
sys/dev/pci/if_de.c: revision 1.152
sys/dev/pci/if_fpa.c: revision 1.61
sys/dev/pci/if_jme.c: revision 1.34
sys/dev/pci/if_tl.c: revision 1.108
sys/dev/pci/if_vte.c: revision 1.19
sys/dev/pci/ixgbe/ixgbe.h: revision 1.50
sys/dev/pcmcia/if_cnw.c: revision 1.62
sys/dev/pcmcia/if_malo_pcmcia.c: revision 1.17
sys/dev/pcmcia/if_ray.c: revision 1.89
sys/dev/pcmcia/if_xi.c: revision 1.81
sys/dev/pcmcia/mhzc.c: revision 1.51
sys/dev/pcmcia/xirc.c: revision 1.34
sys/dev/qbus/if_de.c: revision 1.33
sys/dev/qbus/if_qe.c: revision 1.78
sys/dev/qbus/if_qt.c: revision 1.22
sys/dev/sbus/be.c: revision 1.87
sys/dev/sbus/qe.c: revision 1.68
sys/dev/scsipi/if_se.c: revision 1.96
sys/dev/usb/if_atu.c: revision 1.59
sys/net/if_l2tp.c: revision 1.28 via patch
sys/net/if_ppp.c: revision 1.160
It's not required to include net/bpfdesc.h. Remove it.
--
Simplify like other drivers. NULL check of ifp->if_bpf is done in
bpf_mtap(), so it's not required to do it here.
--
Remove duplicated inclusion of net/bpf.h.
--
Remove duplicated inclusion of net/bpf.h.
--
Simplify bpf_mtap() call. No functional change.
 1.142.2.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.142.2.1 10-Jun-2019  christos Sync with HEAD
 1.149.4.1 29-Feb-2020  ad Sync with head.
 1.153.10.1 02-Aug-2025  perseant Sync with HEAD
 1.31 05-Nov-2006  itohy Add definition for Tx Reclaim status (TXS_RECLAIM).
 1.30 25-Feb-2006  wiz branches: 1.30.14; 1.30.16;
Fix some typos.
 1.29 11-Dec-2005  christos branches: 1.29.2; 1.29.4; 1.29.6;
merge ktrace-lwp.
 1.28 27-Feb-2005  perry branches: 1.28.4;
nuke trailing whitespace
 1.27 09-Aug-2004  mycroft branches: 1.27.4; 1.27.6;
Eliminate most 8-bit access. Just the data in/out path remains.
 1.26 02-Nov-2003  wiz Fix some typos. From Tom Cosgrove via jmc@openbsd.
 1.25 28-Dec-2001  christos branches: 1.25.16;
Clean up the C_ and S_ constants. We don't really need two sets of them.
Also make the interrupt handler for older 3com cards look like the xl one.
I.e. don't ack the interrupt latch bit before checking if it is set.
At the same time, introduce constants for the watched interrupts, so that
we don't copy them all over the place.
 1.24 11-Nov-2001  christos merge duplicate register definitions.
 1.23 20-Jul-2001  thorpej branches: 1.23.4;
Add the ISA Bridge ASIC registers found on the Corkscrew (3c515).
 1.22 13-Mar-2000  soren branches: 1.22.6; 1.22.8;
Fix doubled 'the's in comments.
 1.21 11-Oct-1999  thorpej branches: 1.21.2;
Add some more RoadRunner bits. Partially from Ryoji KATO, PR #8331.
 1.20 28-Apr-1999  jonathan branches: 1.20.2;
Add EEPROM_SSI EEPROM field (hardware revision-level info).
 1.19 04-Nov-1998  fvdl branches: 1.19.6;
Add the 'ex' driver, a DMA driver for 3Com 90x and 90xB cards. Rename
constants from EP_ to ELINK_ since they're now used in the ex driver as well.
 1.18 26-Aug-1998  thorpej Define the full-duplex bit in the W3 MAC CONTROL register.
 1.17 15-Aug-1998  thorpej RoadRunner has a bit in Reset Options that must be set to enable the MII.
Define that bit.
 1.16 15-Aug-1998  thorpej Reset Options is in Window 3; correct a comment.
 1.15 15-Aug-1998  thorpej Define the RoadRunner FIFO count registers.
 1.14 12-Aug-1998  thorpej Completely rewrite media selection. Add support for the MII/PHY on
the 3Com 3c905-TX and 3c905-T4. Fix handling of the MII on the
3c595-MII and 3c597-MII (can't talk to the PHYs on these cards; just
use "manual" for the external MII port).

Fixes kern/4782 (Chris Demetriou).
 1.13 27-Apr-1997  veego Rename the PROD_ID to PROD_ID_3C509 to make it possible to add other
product id's, e.g. for the 3c515.
 1.12 07-Apr-1997  jonathan Remove IFF_LINK[01] "connector" support.
Add if_media support. Still missing a software autosense FSM.
 1.11 30-Dec-1996  jonathan * make sure 100mbit media-present bits don't collied with 3c509
CONFIG_CNTRL bits by making the "conn" argument to epconfig()
a u_int, not a u_int16_t, and by defining 100mbit media
bits in the upper 16 bits.

A redesigned interface that fixes this properly is in the pipeline.
 1.10 29-Dec-1996  jonathan * Expand softc sc_connectors field to 16 bits.
For now, we really only need 8 bits of media type.

* Add bogus definitions for 100mbit transcievers, to be set in the
"conn" argument to ep_config(). Should really use the same bits
as in EP_W0_CONFIG_CTRL bits, but I don't know what bits the 3c515
&c use for 100mbit media.

* Define bitflags for 100Mbit transceiver options in ep_connectors.

* Add definitions of powerup/powerdown commands. for interfaces with
power management. Should send a powerup after APM resume?

* Add definition of fragment-busmaster (vortex) START_DMA command.

* Add definition of PCI configuration-space media-present bits.
(really just EP_W3_RESET_OPTIONS remapped into pci config space.)

* Add comments describing what the #define's above are used for.
 1.9 29-Dec-1996  jonathan Define the contents of window 3's InternalConfig register.
 1.8 07-Dec-1996  cjs Add definition for internal config register.
 1.7 22-Nov-1996  jonathan * 3c509s drop the low-oder bits of EP_THRESH_DISABLE (2047) on a write,
and the result reads back as zero. Mask probe code accordingly.
 1.6 17-Nov-1996  jonathan Fix for hanging 3com ``large packet'' (100Mbit) Etherlink-III devices:
* Add a slot in the softc, ep_pktlenshift, to indicate that
a board implements ``large packets'' (FDDI-sized frames) and
therefore implicitly shifts the argument to packet-length commands
by two bits to fit a 13-bit length in an 11-bit command argument field.

* Change the reset of station-mask filterto be independent of bus-type
(e.g.,. for 3c515)

* Replace the "2044" constant used to disable TX threshold interrupts
on 3c509-generation cards with a #define. Use 2047 instead,
since that works on the large-packet cards (Vortex, Demon, Boomerang)
and 2044 doesn't.

* Add code to epconfing to probe for large-packet support,
set the softc appropriately, and shift packet sizes in commands
by ep_pktlenshift to compensate for the implicit shift.

* Tweak the epconfig() code to avoid hanging on startup.
Set the Tx threshold to interrupt when there's space for
a maximal-sized ether frame, then do epinit() then epstop(),
instead of just the Tx and Rx reset. Required on at least a 3c595.

Tested on a 3c595, but not on 3c509-generation hardware.
 1.5 21-Oct-1996  thorpej New bus.h implementation/interface:
- No more distinction between i/o-mapped and memory-mapped
devices. It's all "bus space" now, and space tags
differentiate the space with finer grain than the
bus chipset tag.
- Add memory barrier methods.
- Implement space alloc/free methods.
- Implement region read/write methods (like memcpy to/from
bus space).
This interface provides a better abstraction for dealing with
machine-independent chipset drivers.
 1.4 29-Sep-1996  christos Apply PR/2661 [from Jonathan Stone]
 1.3 10-May-1996  thorpej branches: 1.3.4;
Update Herb's e-mail address; beer.org feels a lot more friendly.
 1.2 30-Apr-1996  thorpej Convert the Etherlink III (ep) driver to use <machine/bus.h>.
 1.1 25-Apr-1996  thorpej Break up the ep driver into isa, eisa, and pci front-ends and a
bus-independent core driver. Tested on all three bus types, including
an isa 3c509 masquerading as an eisa device (use ep* at eisa? slot ? in
your kernel config file to catch this one).
XXX Driver still needs to be converted to <machine/bus.h>
 1.3.4.1 19-Mar-1997  mycroft Pull up fix for `sniper bug', which can cause packets to be accepted erroneously.
 1.19.6.2 06-Feb-2000  he Pull up revision 1.21 (requested by enami):
Add support for the 3Com 3c574. Partially based on PR#8331.
 1.19.6.1 28-Apr-1999  perry branches: 1.19.6.1.2;
pullup 1.19->1.20 (jonathan)
 1.19.6.1.2.1 21-Jun-1999  thorpej Sync w/ -current.
 1.20.2.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.21.2.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.22.8.2 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.22.8.1 03-Aug-2001  lukem update to -current
 1.22.6.3 08-Jan-2002  nathanw Catch up to -current.
 1.22.6.2 14-Nov-2001  nathanw Catch up to -current.
 1.22.6.1 24-Aug-2001  nathanw Catch up with -current.
 1.23.4.1 12-Nov-2001  thorpej Sync the thorpej-mips-cache branch with -current.
 1.25.16.5 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.25.16.4 21-Sep-2004  skrll Fix the sync with head I botched.
 1.25.16.3 18-Sep-2004  skrll Sync with HEAD.
 1.25.16.2 12-Aug-2004  skrll Sync with HEAD.
 1.25.16.1 03-Aug-2004  skrll Sync with HEAD
 1.27.6.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.27.4.1 29-Apr-2005  kent sync with -current
 1.28.4.2 30-Dec-2006  yamt sync with head.
 1.28.4.1 21-Jun-2006  yamt sync with head.
 1.29.6.1 22-Apr-2006  simonb Sync with head.
 1.29.4.1 09-Sep-2006  rpaulo sync with head
 1.29.2.1 01-Mar-2006  yamt sync with head.
 1.30.16.1 10-Dec-2006  yamt sync with head.
 1.30.14.1 18-Nov-2006  ad Sync with head.
 1.39 13-Apr-2015  riastradh Convert sys/dev to use <sys/rndsource.h>.
 1.38 02-Feb-2012  tls branches: 1.38.6; 1.38.24;
Entropy-pool implementation move and cleanup.

1) Move core entropy-pool code and source/sink/sample management code
to sys/kern from sys/dev.

2) Remove use of NRND as test for presence of entropy-pool code throughout
source tree.

3) Remove use of RND_ENABLED in device drivers as microoptimization to
avoid expensive operations on disabled entropy sources; make the
rnd_add calls do this directly so all callers benefit.

4) Fix bug in recent rnd_add_data()/rnd_add_uint32() changes that might
have lead to slight entropy overestimation for some sources.

5) Add new source types for environmental sensors, power sensors, VM
system events, and skew between clocks, with a sample implementation
for each.

ok releng to go in before the branch due to the difficulty of later
pullup (widespread #ifdef removal and moved files). Tested with release
builds on amd64 and evbarm and live testing on amd64.
 1.37 19-Nov-2011  tls branches: 1.37.2;
First step of random number subsystem rework described in
<20111022023242.BA26F14A158@mail.netbsd.org>. This change includes
the following:

An initial cleanup and minor reorganization of the entropy pool
code in sys/dev/rnd.c and sys/dev/rndpool.c. Several bugs are
fixed. Some effort is made to accumulate entropy more quickly at
boot time.

A generic interface, "rndsink", is added, for stream generators to
request that they be re-keyed with good quality entropy from the pool
as soon as it is available.

The arc4random()/arc4randbytes() implementation in libkern is
adjusted to use the rndsink interface for rekeying, which helps
address the problem of low-quality keys at boot time.

An implementation of the FIPS 140-2 statistical tests for random
number generator quality is provided (libkern/rngtest.c). This
is based on Greg Rose's implementation from Qualcomm.

A new random stream generator, nist_ctr_drbg, is provided. It is
based on an implementation of the NIST SP800-90 CTR_DRBG by
Henric Jungheim. This generator users AES in a modified counter
mode to generate a backtracking-resistant random stream.

An abstraction layer, "cprng", is provided for in-kernel consumers
of randomness. The arc4random/arc4randbytes API is deprecated for
in-kernel use. It is replaced by "cprng_strong". The current
cprng_fast implementation wraps the existing arc4random
implementation. The current cprng_strong implementation wraps the
new CTR_DRBG implementation. Both interfaces are rekeyed from
the entropy pool automatically at intervals justifiable from best
current cryptographic practice.

In some quick tests, cprng_fast() is about the same speed as
the old arc4randbytes(), and cprng_strong() is about 20% faster
than rnd_extract_data(). Performance is expected to improve.

The AES code in src/crypto/rijndael is no longer an optional
kernel component, as it is required by cprng_strong, which is
not an optional kernel component.

The entropy pool output is subjected to the rngtest tests at
startup time; if it fails, the system will reboot. There is
approximately a 3/10000 chance of a false positive from these
tests. Entropy pool _input_ from hardware random numbers is
subjected to the rngtest tests at attach time, as well as the
FIPS continuous-output test, to detect bad or stuck hardware
RNGs; if any are detected, they are detached, but the system
continues to run.

A problem with rndctl(8) is fixed -- datastructures with
pointers in arrays are no longer passed to userspace (this
was not a security problem, but rather a major issue for
compat32). A new kernel will require a new rndctl.

The sysctl kern.arandom() and kern.urandom() nodes are hooked
up to the new generators, but the /dev/*random pseudodevices
are not, yet.

Manual pages for the new kernel interfaces are forthcoming.
 1.36 05-Sep-2009  tsutsui branches: 1.36.12;
Replace shutdownhook_establish(9) with pmf_device_register1(9) in
MI epconfig() and ep_detach(), and remove pmf(9) calls in pcmcia attachment.
Tested on ep0 at pci, but pcmcia attachment is untested.
 1.35 27-Aug-2008  christos device_t changes, pmf, minor knf.
 1.34 11-Jul-2006  peter branches: 1.34.54; 1.34.58; 1.34.60; 1.34.64;
Add power hooks for "ep* at pcmcia?".

ok christos@
 1.33 11-Dec-2005  christos branches: 1.33.4; 1.33.8; 1.33.16;
merge ktrace-lwp.
 1.32 04-Feb-2005  perry branches: 1.32.6;
de-__P
 1.31 08-Jul-2003  itojun branches: 1.31.8; 1.31.10;
function prototype must not have variable name
 1.30 03-May-2003  wiz branches: 1.30.2;
DMA, not dma nor Dma.
 1.29 23-Jul-2001  thorpej Some whitespace cleanup.
 1.28 22-Mar-2001  jdolecek branches: 1.28.2;
Add MCA ep(4) attachment, for 3Com 3c529-type cards. Tested with 3c529-TP,
provided to me by David Brownlee (thanks!).

Performance of this card is quite poor on my PS/2 with 386DX, like 100KB/s
at best, but as low as 5KB/s when transferring bigger files due to
packet overruns. It would be good to revisit this later, probably by
teaching the ic code to use RX Early.
 1.27 22-Mar-2001  jdolecek convert to use ether_ioctl()
fix bunch of typos
 1.26 29-May-2000  jhawk branches: 1.26.4;
For all network drivers that call ether_ifattach(), and also
have _detach() functions:
Ensure that softc keeps state about whether the attach succeeded,
and make the detach function return immediately if the attach did
not complete.
 1.25 23-Mar-2000  thorpej branches: 1.25.2;
New callout mechanism with two major improvements over the old
timeout()/untimeout() API:
- Clients supply callout handle storage, thus eliminating problems of
resource allocation.
- Insertion and removal of callouts is constant time, important as
this facility is used quite a lot in the kernel.

The old timeout()/untimeout() API has been removed from the kernel.
 1.24 08-Feb-2000  enami - Bail out from attach stage if failed to enable card, number of iospace
or memspace is unexpected, failed to map iospace or failed to configure
the controller properly.
- Disestablish an interrupt handler if failed to enable card.
 1.23 02-Feb-2000  augustss Make sure to untimeout() things on detach.
 1.22 02-Feb-2000  augustss Make sure to get rid of shutdown hook and ttach media on detach.
 1.21 18-Nov-1998  thorpej branches: 1.21.2; 1.21.10;
Now that the *_activate() functions don't do things which are attachment
specific, move them into the chipset drivers.
 1.20 17-Nov-1998  thorpej Expose the "enable" and "disable" functions so that the front-ends can
access them.
 1.19 04-Nov-1998  fvdl Add the 'ex' driver, a DMA driver for 3Com 90x and 90xB cards. Rename
constants from EP_ to ELINK_ since they're now used in the ex driver as well.
 1.18 17-Aug-1998  thorpej First-crack at RoadRunner (3c574-TX 10/100Mbps PCMCIA). Doens't yet use
any of the RoadRunner speed hacks.
 1.17 15-Aug-1998  thorpej Define the Corkscrew chipset - used by the 3c515 ISA 10/100mbps cards.
 1.16 15-Aug-1998  thorpej Define the 3Com "RoadRunner" chipset; like the Boomerang, but for PCMCIA.
No DMA is wired up, it has a shared memory interface, and a FIFO buffer
which can be used to speed up PIO transfers. (The latter two are
PCMCIA-specific speed hacks to deal hide the performance lossage from
using a PCMCIA->PCI bridge internally.)
 1.15 12-Aug-1998  thorpej Completely rewrite media selection. Add support for the MII/PHY on
the 3Com 3c905-TX and 3c905-T4. Fix handling of the MII on the
3c595-MII and 3c597-MII (can't talk to the PHYs on these cards; just
use "manual" for the external MII port).

Fixes kern/4782 (Chris Demetriou).
 1.14 15-Oct-1997  explorer Add and/or update rnd_*() hooks
 1.13 14-Oct-1997  thorpej Pull down from marc-pcmcia branch:

Minor tweaks to deal with PCMCIA differences, and support for power
management.
 1.12 30-Mar-1997  jonathan branches: 1.12.4;
Add ifmedia hooks: include <ifmedia.h> and add sc_media to softc.
 1.11 15-Mar-1997  is New ARP system, supports IPv4 over any hardware link.

Some of the stuff (e.g., rarpd, bootpd, dhcpd etc., libsa) still will
only support Ethernet. Tcpdump itself should be ok, but libpcap needs
lot of work.

For the detailed change history, look at the commit log entries for
the is-newarp branch.
 1.10 18-Feb-1997  jonathan Move if_ep media-sense code from front ends to inside back end,
to prepare for if_media, and to support EISA 3c59x cards:

* change epconfig() to take a short that encodes the chipset
type (3c509, or Demon/Vortex/Boomerang).
* add distinct 3c509 and Demon/Vortex/Boomerang media-sense
functions to back end.
* Add EISA match/attach support for the 3c592 and 3c597
(Demon) cards as well as the 3c509-comatibl EISA 3c509/3c579.

* Assume that ISA and ISA PnP cards are 3c509-style, until
proof to the contrary (e.g. large packet support).

Tested on 3c595, 3c590, and 3c509b. Not tested on 3c515 or Demon.
 1.9 30-Dec-1996  jonathan branches: 1.9.4;
* make sure 100mbit media-present bits don't collied with 3c509
CONFIG_CNTRL bits by making the "conn" argument to epconfig()
a u_int, not a u_int16_t, and by defining 100mbit media
bits in the upper 16 bits.

A redesigned interface that fixes this properly is in the pipeline.
 1.8 29-Dec-1996  jonathan * Expand softc sc_connectors field to 16 bits.
For now, we really only need 8 bits of media type.

* Add bogus definitions for 100mbit transcievers, to be set in the
"conn" argument to ep_config(). Should really use the same bits
as in EP_W0_CONFIG_CTRL bits, but I don't know what bits the 3c515
&c use for 100mbit media.

* Define bitflags for 100Mbit transceiver options in ep_connectors.

* Add definitions of powerup/powerdown commands. for interfaces with
power management. Should send a powerup after APM resume?

* Add definition of fragment-busmaster (vortex) START_DMA command.

* Add definition of PCI configuration-space media-present bits.
(really just EP_W3_RESET_OPTIONS remapped into pci config space.)

* Add comments describing what the #define's above are used for.
 1.7 17-Nov-1996  jonathan Fix for hanging 3com ``large packet'' (100Mbit) Etherlink-III devices:
* Add a slot in the softc, ep_pktlenshift, to indicate that
a board implements ``large packets'' (FDDI-sized frames) and
therefore implicitly shifts the argument to packet-length commands
by two bits to fit a 13-bit length in an 11-bit command argument field.

* Change the reset of station-mask filterto be independent of bus-type
(e.g.,. for 3c515)

* Replace the "2044" constant used to disable TX threshold interrupts
on 3c509-generation cards with a #define. Use 2047 instead,
since that works on the large-packet cards (Vortex, Demon, Boomerang)
and 2044 doesn't.

* Add code to epconfing to probe for large-packet support,
set the softc appropriately, and shift packet sizes in commands
by ep_pktlenshift to compensate for the implicit shift.

* Tweak the epconfig() code to avoid hanging on startup.
Set the Tx threshold to interrupt when there's space for
a maximal-sized ether frame, then do epinit() then epstop(),
instead of just the Tx and Rx reset. Required on at least a 3c595.

Tested on a 3c595, but not on 3c509-generation hardware.
 1.6 21-Oct-1996  thorpej New bus.h implementation/interface:
- No more distinction between i/o-mapped and memory-mapped
devices. It's all "bus space" now, and space tags
differentiate the space with finer grain than the
bus chipset tag.
- Add memory barrier methods.
- Implement space alloc/free methods.
- Implement region read/write methods (like memcpy to/from
bus space).
This interface provides a better abstraction for dealing with
machine-independent chipset drivers.
 1.5 14-May-1996  thorpej branches: 1.5.4;
Be more careful with types, and pull in <machine/intr.h>
 1.4 10-May-1996  thorpej Update Herb's e-mail address; beer.org feels a lot more friendly.
 1.3 03-May-1996  christos Move epstop prototype to the header file.
 1.2 30-Apr-1996  thorpej Convert the Etherlink III (ep) driver to use <machine/bus.h>.
 1.1 25-Apr-1996  thorpej Break up the ep driver into isa, eisa, and pci front-ends and a
bus-independent core driver. Tested on all three bus types, including
an isa 3c509 masquerading as an eisa device (use ep* at eisa? slot ? in
your kernel config file to catch this one).
XXX Driver still needs to be converted to <machine/bus.h>
 1.5.4.1 04-Mar-1997  mycroft Recognize 3c900 and 3c905 cards.
 1.9.4.2 20-Feb-1997  is Merged in recent changes from Trunk.
 1.9.4.1 07-Feb-1997  is Snapshot of new ARP code.

Our old ARP code was hardwired for 6-byte length medium
addresses, while the protocol is designed for any size.

This snapshot contains a first hack at getting rid of
Ethernet specific data structures. The ep driver is updated
(and tested on the PCI bus), the iy and fpa drivers have been
updated, but not real life tested yet.

If you want to test this with other drivers, you have to update
them first yourself, and probably tag the relevant directories.
Better contact me if you want to do this.
 1.12.4.4 29-Sep-1997  thorpej Make the "enable" and "disable" hooks take pointers to the softc, rather
than void * and a separately specified argument.
 1.12.4.3 27-Sep-1997  marc add __P where needed
 1.12.4.2 27-Sep-1997  marc add enable/disable hooks to the ep softc
 1.12.4.1 30-Jul-1997  marc added pcmcia infrastructure and a few devices
 1.21.10.2 27-Mar-2001  bouyer Sync with HEAD.
 1.21.10.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.21.2.1 11-Dec-1998  kenh The beginnings of interface detach support. Still some bugs, but mostly
works for me.

This work was originally by Bill Studenmund, and cleaned up by me.
 1.25.2.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.26.4.2 24-Aug-2001  nathanw Catch up with -current.
 1.26.4.1 09-Apr-2001  nathanw Catch up with -current.
 1.28.2.1 03-Aug-2001  lukem update to -current
 1.30.2.4 04-Feb-2005  skrll Sync with HEAD.
 1.30.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.30.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.30.2.1 03-Aug-2004  skrll Sync with HEAD
 1.31.10.1 12-Feb-2005  yamt sync with head.
 1.31.8.1 29-Apr-2005  kent sync with -current
 1.32.6.1 30-Dec-2006  yamt sync with head.
 1.33.16.1 13-Jul-2006  gdamore Merge from HEAD.
 1.33.8.1 11-Aug-2006  yamt sync with head
 1.33.4.1 09-Sep-2006  rpaulo sync with head
 1.34.64.1 19-Oct-2008  haad Sync with HEAD.
 1.34.60.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.34.58.2 16-Sep-2009  yamt sync with head
 1.34.58.1 04-May-2009  yamt sync with head.
 1.34.54.1 28-Sep-2008  mjf Sync with HEAD.
 1.36.12.1 17-Apr-2012  yamt sync with head
 1.37.2.1 18-Feb-2012  mrg merge to -current.
 1.38.24.1 06-Jun-2015  skrll Sync with HEAD
 1.38.6.1 03-Dec-2017  jdolecek update from HEAD
 1.140 29-Jun-2024  riastradh if_stats(9): Add ifp argument to if_stat..._ref.

This will enable us to pass the ifp through to a dtrace probe inside.

No functional change intended in this change, but this is an API
change visible to modules so it shouldn't be pulled up.

PR kern/58377
 1.139 29-May-2022  rin Audit unload/unmap v.s. free against DMA buffer for sys/dev;
make sure that bus_dmamap_unload(9) [or bus_dmamap_destroy(9)] or
bus_dmamem_unmap(9) are preceding to freeing DMA buffer, if it is
loaded or mapped, respectively.

This is mandatory for some archs. See, e.g.:

http://www.nerv.org/netbsd/?q=id:20210511T013030Z.013443cc790088147e4beed43f53dedabeaf9312
http://www.nerv.org/netbsd/?q=id:20220511T172220Z.561179f0b6fcc5b9cd73e274f69d74e2ce9e4c93

For some drivers, resource leaks for error paths are fixed at
the same time.

XXX XXX XXX
Compile test only (at least one arch per driver).
 1.138 12-Mar-2020  thorpej Add support for MBUFTRACE.
 1.137 10-Feb-2020  msaitoh Restore an register read for RX_FRAMES_OK which was removed in rev. 1.133.
All statistics registers should be read to ACK the interrupt. Fixes PR#54920.

XXX pullup-[89]
 1.136 07-Feb-2020  thorpej Use callout_setfunc() / callout_schedule().
 1.135 04-Feb-2020  thorpej Use ifmedia_fini().
 1.134 29-Jan-2020  thorpej Adopt <net/if_stats.h>.
 1.133 30-Oct-2019  msaitoh branches: 1.133.2;
if_percpuq(9) automatically increments if_ipackets, so don't add number of
RX frames from device's statistics counter to if_ipackets to avoid double
count.
 1.132 13-Sep-2019  msaitoh if_flags is neither int nor short. It's unsigned short.
 1.131 28-May-2019  msaitoh branches: 1.131.2;
Use ETHER_LOCK()/ETHER_UNLOCK() for all ethernet drivers to protect ec_multi*.
 1.130 23-May-2019  msaitoh Whitespace fix (mainly tabify).
 1.129 23-May-2019  msaitoh No functional change:
- Simplify MII structure initialization and reference.
- u_int*_t -> uint*_t.
- KNF
 1.128 22-Apr-2019  msaitoh On drivers which use MII(4) and have hook SIOC[GS]IFMEDIA which just pass to
ifmedia_ioctl(), the hook is not required because ether_ioctl has it
(if_ethersubr.c rev. 1.160). These drivers don't return ENETRESET in
ifmedia_ioctl(), so no functional change.
 1.127 05-Feb-2019  msaitoh Remove very old IFF_NOTRAILERS flag.
 1.126 22-Jan-2019  msaitoh Change MII PHY read/write API from:

int (*mii_readreg_t)(device_t, int, int);
void (*mii_writereg_t)(device_t, int, int, int);
to:

int (*mii_readreg_t)(device_t, int, int, uint16_t *);
int (*mii_writereg_t)(device_t, int, int, uint16_t);

Now we can test if a read/write operation failed or not by the return value.

In 802.3 spec says that the PHY shall not respond to read/write transaction
to the unimplemented register(22.2.4.3). Detecting timeout can be used to
check whether a register is implemented or not (if the register conforms to
the spec). ukphy(4) can be used this for MII_MMDACR and MII_MMDAADR.

Note that I noticed that the following code do infinite loop in the
read/wirte function. If it accesses unimplemented PHY register, it will hang.
It should be fixed:

arm/at91/at91emac.c
arm/ep93xx/epe.c
arm/omap/omapl1x_emac.c
mips/ralink/ralink_eth.c
arch/powerpc/booke/dev/pq3etsec.c(read)
dev/cadence/if_cemac.c <- hkenken
dev/ic/lan9118.c


Tested with the following device:

axe+ukphy
axe+rgephy
axen+rgephy (tested by Andrius V)
wm+atphy
wm+ukphy
wm+igphy
wm+ihphy
wm+makphy
sk+makphy
sk+brgphy
sk+gentbi
msk+makphy
sip+icsphy
sip+ukphy
re+rgephy
bge+brgphy
bnx+brgphy
gsip+gphyter
rtk+rlphy
fxp+inphy (tested by Andrius V)
tlp+acphy
ex+exphy
epic+qsphy
vge+ciphy (tested by Andrius V)
vr+ukphy (tested by Andrius V)
vte+ukphy (tested by Andrius V)

Not tested (MAC):
arm:at91emac
arm:cemac
arm:epe
arm:geminigmac
arm:enet
arm:cpsw
arm:emac(omac)
arm:emac(sunxi)
arm:npe
evbppc:temac
macppc:bm
macppc:gm
mips:aumac
mips:ae
mips:cnmac
mips:reth
mips:sbmac
playstation2:smap
powerpc:tsec
powerpc:emac(ibm4xx)
sgimips:mec
sparc:be
sf
ne(ax88190, dl10019)
awge
ep
gem
hme
smsh
mtd
sm
age
alc
ale
bce
cas
et
jme
lii
nfe
pcn
ste
stge
tl
xi
aue
mue
smsc
udav
url

Not tested (PHY):
amhphy
bmtphy
dmphy
etphy
glxtphy
ikphy
iophy
lxtphy
nsphyter
pnaphy
rdcphy
sqphy
tlphy
tqphy
urlphy
 1.125 03-Sep-2018  riastradh Rename min/max -> uimin/uimax for better honesty.

These functions are defined on unsigned int. The generic name
min/max should not silently truncate to 32 bits on 64-bit systems.
This is purely a name change -- no functional change intended.

HOWEVER! Some subsystems have

#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))

even though our standard name for that is MIN/MAX. Although these
may invite multiple evaluation bugs, these do _not_ cause integer
truncation.

To avoid `fixing' these cases, I first changed the name in libkern,
and then compile-tested every file where min/max occurred in order to
confirm that it failed -- and thus confirm that nothing shadowed
min/max -- before changing it.

I have left a handful of bootloaders that are too annoying to
compile-test, and some dead code:

cobalt ews4800mips hp300 hppa ia64 luna68k vax
acorn32/if_ie.c (not included in any kernels)
macppc/if_gm.c (superseded by gem(4))

It should be easy to fix the fallout once identified -- this way of
doing things fails safe, and the goal here, after all, is to _avoid_
silent integer truncations, not introduce them.

Maybe one day we can reintroduce min/max as type-generic things that
never silently truncate. But we should avoid doing that for a while,
so that existing code has a chance to be detected by the compiler for
conversion to uimin/uimax without changing the semantics until we can
properly audit it all. (Who knows, maybe in some cases integer
truncation is actually intended!)
 1.124 26-Jun-2018  msaitoh branches: 1.124.2;
Implement the BPF direction filter (BIOC[GS]DIRECTION). It provides backward
compatibility with BIOC[GS]SEESENT ioctl. The userland interface is the same
as FreeBSD.

This change also fixes a bug that the direction is misunderstand on some
environment by passing the direction to bpf_mtap*() instead of checking
m->m_pkthdr.rcvif.
 1.123 23-Jun-2018  maxv constify
 1.122 22-Jun-2018  msaitoh It's not required to include net/bpfdesc.h. Remove it.
 1.121 20-Feb-2017  ozaki-r branches: 1.121.6; 1.121.12;
Apply deferred if_start to more drivers
 1.120 15-Dec-2016  ozaki-r branches: 1.120.2;
Move bpf_mtap and if_ipackets++ on Rx of each driver to percpuq if_input

The benefits of the change are:
- We can reduce codes
- We can provide the same behavior between drivers
- Where/When if_ipackets is counted up
- Note that some drivers still update packet statistics in their own
way (periodical update)
- Moved bpf_mtap run in softint
- This makes it easy to MP-ify bpf

Proposed on tech-kern and tech-net
 1.119 10-Jun-2016  ozaki-r branches: 1.119.2;
Introduce m_set_rcvif and m_reset_rcvif

The API is used to set (or reset) a received interface of a mbuf.
They are counterpart of m_get_rcvif, which will come in another
commit, hide internal of rcvif operation, and reduce the diff of
the upcoming change.

No functional change.
 1.118 09-Feb-2016  ozaki-r Introduce softint-based if_input

This change intends to run the whole network stack in softint context
(or normal LWP), not hardware interrupt context. Note that the work is
still incomplete by this change; to that end, we also have to softint-ify
if_link_state_change (and bpf) which can still run in hardware interrupt.

This change softint-ifies at ifp->if_input that is called from
each device driver (and ieee80211_input) to ensure Layer 2 runs
in softint (e.g., ether_input and bridge_input). To this end,
we provide a framework (called percpuq) that utlizes softint(9)
and percpu ifqueues. With this patch, rxintr of most drivers just
queues received packets and schedules a softint, and the softint
dequeues packets and does rest packet processing.

To minimize changes to each driver, percpuq is allocated in struct
ifnet for now and that is initialized by default (in if_attach).
We probably have to move percpuq to softc of each driver, but it's
future work. At this point, only wm(4) has percpuq in its softc
as a reference implementation.

Additional information including performance numbers can be found
in the thread at tech-kern@ and tech-net@:
http://mail-index.netbsd.org/tech-kern/2016/01/14/msg019997.html

Acknowledgment: riastradh@ greatly helped this work.
Thank you very much!
 1.117 13-Apr-2015  riastradh Convert sys/dev to use <sys/rndsource.h>.
 1.116 10-Aug-2014  tls branches: 1.116.4;
Merge tls-earlyentropy branch into HEAD.
 1.115 22-Jul-2012  matt branches: 1.115.2; 1.115.12;
Fix mii_statchg to take a 'struct ifnet *' instead of device_t. This fixes
problem with a common MDIO bus used for multiple interfaces.
Some drivers converted to CFATTACL_DECL_NEW.
 1.114 02-Feb-2012  tls Entropy-pool implementation move and cleanup.

1) Move core entropy-pool code and source/sink/sample management code
to sys/kern from sys/dev.

2) Remove use of NRND as test for presence of entropy-pool code throughout
source tree.

3) Remove use of RND_ENABLED in device drivers as microoptimization to
avoid expensive operations on disabled entropy sources; make the
rnd_add calls do this directly so all callers benefit.

4) Fix bug in recent rnd_add_data()/rnd_add_uint32() changes that might
have lead to slight entropy overestimation for some sources.

5) Add new source types for environmental sensors, power sensors, VM
system events, and skew between clocks, with a sample implementation
for each.

ok releng to go in before the branch due to the difficulty of later
pullup (widespread #ifdef removal and moved files). Tested with release
builds on amd64 and evbarm and live testing on amd64.
 1.113 13-Nov-2010  uebayasi branches: 1.113.8; 1.113.12;
Don't pull in the whole uvm(9) API to access only PAGE_SIZE and
some other constants. These are provided by sys/param.h now.
 1.112 05-Apr-2010  joerg Push the bpf_ops usage back into bpf.h. Push the common ifp->if_bpf
check into the inline functions as well the fourth argument for
bpf_attach.
 1.111 22-Mar-2010  dyoung Add a self-suspensor. It's not used, yet.

In ex_detach(), call ex_stop(), first. ex_stop() stops the callout.
Destroy the callout in ex_detach().
 1.110 19-Jan-2010  pooka branches: 1.110.2; 1.110.4;
Redefine bpf linkage through an always present op vector, i.e.
#if NBPFILTER is no longer required in the client. This change
doesn't yet add support for loading bpf as a module, since drivers
can register before bpf is attached. However, callers of bpf can
now be modularized.

Dynamically loadable bpf could probably be done fairly easily with
coordination from the stub driver and the real driver by registering
attachments in the stub before the real driver is loaded and doing
a handoff. ... and I'm not going to ponder the depths of unload
here.

Tested with i386/MONOLITHIC, modified MONOLITHIC without bpf and rump.
 1.109 15-Sep-2009  dyoung Simplify activation routines: don't call mii_activate(), it's a
no-op. Don't block interrupts, if_deactivate() does it.
Compile-tested, only.
 1.108 05-Sep-2009  tsutsui Invert logic around nested pmf(9) registrations for readability.
 1.107 03-Dec-2008  tsutsui Fix typo in comment.
 1.106 07-Nov-2008  dyoung *** Summary ***

When a link-layer address changes (e.g., ifconfig ex0 link
02:de:ad:be:ef:02 active), send a gratuitous ARP and/or a Neighbor
Advertisement to update the network-/link-layer address bindings
on our LAN peers.

Refuse a change of ethernet address to the address 00:00:00:00:00:00
or to any multicast/broadcast address. (Thanks matt@.)

Reorder ifnet ioctl operations so that driver ioctls may inherit
the functions of their "class"---ether_ioctl(), fddi_ioctl(), et
cetera---and the class ioctls may inherit from the generic ioctl,
ifioctl_common(), but both driver- and class-ioctls may override
the generic behavior. Make network drivers share more code.

Distinguish a "factory" link-layer address from others for the
purposes of both protecting that address from deletion and computing
EUI64.

Return consistent, appropriate error codes from network drivers.

Improve readability. KNF.

*** Details ***

In if_attach(), always initialize the interface ioctl routine,
ifnet->if_ioctl, if the driver has not already initialized it.
Delete if_ioctl == NULL tests everywhere else, because it cannot
happen.

In the ioctl routines of network interfaces, inherit common ioctl
behaviors by calling either ifioctl_common() or whichever ioctl
routine is appropriate for the class of interface---e.g., ether_ioctl()
for ethernets.

Stop (ab)using SIOCSIFADDR and start to use SIOCINITIFADDR. In
the user->kernel interface, SIOCSIFADDR's argument was an ifreq,
but on the protocol->ifnet interface, SIOCSIFADDR's argument was
an ifaddr. That was confusing, and it would work against me as I
make it possible for a network interface to overload most ioctls.
On the protocol->ifnet interface, replace SIOCSIFADDR with
SIOCINITIFADDR. In ifioctl(), return EPERM if userland tries to
invoke SIOCINITIFADDR.

In ifioctl(), give the interface the first shot at handling most
interface ioctls, and give the protocol the second shot, instead
of the other way around. Finally, let compatibility code (COMPAT_OSOCK)
take a shot.

Pull device initialization out of switch statements under
SIOCINITIFADDR. For example, pull ..._init() out of any switch
statement that looks like this:

switch (...->sa_family) {
case ...:
..._init();
...
break;
...
default:
..._init();
...
break;
}

Rewrite many if-else clauses that handle all permutations of IFF_UP
and IFF_RUNNING to use a switch statement,

switch (x & (IFF_UP|IFF_RUNNING)) {
case 0:
...
break;
case IFF_RUNNING:
...
break;
case IFF_UP:
...
break;
case IFF_UP|IFF_RUNNING:
...
break;
}

unifdef lots of code containing #ifdef FreeBSD, #ifdef NetBSD, and
#ifdef SIOCSIFMTU, especially in fwip(4) and in ndis(4).

In ipw(4), remove an if_set_sadl() call that is out of place.

In nfe(4), reuse the jumbo MTU logic in ether_ioctl().

Let ethernets register a callback for setting h/w state such as
promiscuous mode and the multicast filter in accord with a change
in the if_flags: ether_set_ifflags_cb() registers a callback that
returns ENETRESET if the caller should reset the ethernet by calling
if_init(), 0 on success, != 0 on failure. Pull common code from
ex(4), gem(4), nfe(4), sip(4), tlp(4), vge(4) into ether_ioctl(),
and register if_flags callbacks for those drivers.

Return ENOTTY instead of EINVAL for inappropriate ioctls. In
zyd(4), use ENXIO instead of ENOTTY to indicate that the device is
not any longer attached.

Add to if_set_sadl() a boolean 'factory' argument that indicates
whether a link-layer address was assigned by the factory or some
other source. In a comment, recommend using the factory address
for generating an EUI64, and update in6_get_hw_ifid() to prefer a
factory address to any other link-layer address.

Add a routing message, RTM_LLINFO_UPD, that tells protocols to
update the binding of network-layer addresses to link-layer addresses.
Implement this message in IPv4 and IPv6 by sending a gratuitous
ARP or a neighbor advertisement, respectively. Generate RTM_LLINFO_UPD
messages on a change of an interface's link-layer address.

In ether_ioctl(), do not let SIOCALIFADDR set a link-layer address
that is broadcast/multicast or equal to 00:00:00:00:00:00.

Make ether_ioctl() call ifioctl_common() to handle ioctls that it
does not understand.

In gif(4), initialize if_softc and use it, instead of assuming that
the gif_softc and ifp overlap.

Let ifioctl_common() handle SIOCGIFADDR.

Sprinkle rtcache_invariants(), which checks on DIAGNOSTIC kernels
that certain invariants on a struct route are satisfied.

In agr(4), rewrite agr_ioctl_filter() to be a bit more explicit
about the ioctls that we do not allow on an agr(4) member interface.

bzero -> memset. Delete unnecessary casts to void *. Use
sockaddr_in_init() and sockaddr_in6_init(). Compare pointers with
NULL instead of "testing truth". Replace some instances of (type
*)0 with NULL. Change some K&R prototypes to ANSI C, and join
lines.
 1.105 28-Apr-2008  martin branches: 1.105.6; 1.105.8;
Remove clause 3 and 4 from TNF licenses
 1.104 14-Apr-2008  cegger branches: 1.104.2; 1.104.4;
- ansify
- use POSIX integers
 1.103 14-Apr-2008  spz pretty up if_ex: pmf'ify, device split, and improve printing a bit too.

Reviewed and function-tested on if_ex_cardbus by cube (thanks).
Function-tested on if_ex_pci by myself.
 1.102 14-Apr-2008  cegger ansify
 1.101 08-Apr-2008  cegger use aprint_*_dev and device_xname
 1.100 07-Feb-2008  dyoung branches: 1.100.6;
Start patching up the kernel so that a network driver always has
the opportunity to handle an ioctl before generic ifioctl handling
occurs. This will ease extending the kernel and sharing of code
between drivers.

First steps: Make the signature of ifioctl_common() match struct
ifinet->if_ioctl. Convert SIOCSIFCAP and SIOCSIFMTU to the new
ifioctl() regime, throughout the kernel.
 1.99 19-Oct-2007  ad branches: 1.99.2;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.98 26-Aug-2007  dyoung branches: 1.98.2; 1.98.6;
Constify: LLADDR -> CLLADDR. I'm aiming here to make it easier to
identify sockaddr_dl abuse that remains in the kernel, especially
the potential for overwriting memory past the end of a sockaddr_dl
with, e.g., memcpy(LLADDR(), ...).
 1.97 09-Jul-2007  ad branches: 1.97.2; 1.97.6;
Merge some of the less invasive changes from the vmlocking branch:

- kthread, callout, devsw API changes
- select()/poll() improvements
- miscellaneous MT safety improvements
 1.96 04-Mar-2007  christos branches: 1.96.2; 1.96.4;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.95 12-Nov-2006  itohy branches: 1.95.4;
Oops, I didn't notice the file had been updated and overwrote
the changes in 1.93....
Rescue the changes in 1.93 (IPv4 checksum fix).
 1.94 12-Nov-2006  itohy - In some rare cases, both Tx Complete and Dn Complete bits are set.
I'm not sure what it exactly means, but at least, the packet in question
is reloaded in ex_txstat() and should not handle the Dn Complete event
at the moment --- it should be served on later interrupt.

- Reload packet on collision, too.
 1.93 12-Nov-2006  tsutsui Add a workaround for a hardware ip4csum-tx bug which would sometimes put
wrong IPv4 checksum on sending 21 or 22 byte IP packets.

See discussion on tech-kern and tech-net for details:
http://mail-index.netbsd.org/tech-kern/2006/11/04/0004.html
 1.92 05-Nov-2006  itohy Restart transmitter, not reset the entire chip, on transmission errors
like Tx underrun.
This should improve performance on such errors.

Handle fifo threshold properly --- actually it did not handled at all.
Note that the Tx Complete interrupts occur only on errors, and ex_txstat()
is not good place to increment sc->tx_succ_ok. Increase the sc->tx_succ_ok
count from 100 to 256, since the ex(4) does busmastering and underruns
should rarely happen in normal operations.

Possibly improve some situation for the hang-on-heavy-load problems,
such as kern/11450 and kern/27096.
 1.91 04-Nov-2006  tsutsui Preserve m_pkthdr.csum_flags in TX packets because
it could be lost if bus_dmamap_load_mbuf(9) returns EFBIG.
(though I've never seen the "too mamy segments" message
which indicates the packet has more than 32 fragments)
 1.90 29-Oct-2006  itohy Turn on PHY power earlier in the initialization.
This should make 3c575CT work and fix following PRs:

kern/12965: 3com 575CT does not work
port-i386/16295: Problems in pci routing table and ex0 (3c575c-tx) networking
 1.89 24-Sep-2006  jmcneill Add "name" parameter to powerhook_establish, to aid debugging. No objections
on tech-kern@
 1.88 21-May-2006  christos branches: 1.88.6; 1.88.8;
void casts to functions whose return values are ignored.
 1.87 20-Feb-2006  thorpej branches: 1.87.2; 1.87.6; 1.87.8;
Use device_is_active() rather than testing dv_flags for DVF_ACTIVE
directly.
 1.86 11-Dec-2005  christos branches: 1.86.2; 1.86.4; 1.86.6;
merge ktrace-lwp.
 1.85 23-Oct-2005  christos The previous change (to use bus_space_read_2), was broken because it was
reading from an odd offset. From Robert Elz
 1.84 04-Oct-2005  christos branches: 1.84.2;
PR/31455: Robert Elz: ex (905[BC]) cards can hang in -current kernels
- fix bus_space_read_1 -> bus_space_read_2 since revision 1.27 changed
the bit defines to assume 2 byte reads.
- Increment oerrors in case of collisions
- Clamp success counter to 100, instead of letting rotate freely.
 1.83 31-May-2005  christos branches: 1.83.2;
revert previous and fix LLADDR instead.
 1.82 31-May-2005  christos use const cast.
 1.81 30-May-2005  christos - add missing const
- fix variable shadowing
- remove unneeded casts
 1.80 02-May-2005  yamt split IFCAP_CSUM_xxx to IFCAP_CSUM_xxx_Rx and IFCAP_CSUM_xxx_Tx.
 1.79 27-Feb-2005  perry branches: 1.79.2;
nuke trailing whitespace
 1.78 06-Feb-2005  skrll Initialize 'error' in all cases in ioctl handler, otherwise it doesn't
compile (and of course might return garbage). [hi kim!]
 1.77 06-Feb-2005  kim If the interface is up and running, only modify the receive filter
when setting promiscuous or debug mode. This avoids resetting the
chip unnecessarily.

Fixes PR kern/29126.
 1.76 04-Feb-2005  perry de-__P
 1.75 30-Oct-2004  thorpej branches: 1.75.4; 1.75.6;
When adding/deleting multicast addresses, only whack the address
filter if the interface is marked RUNNING.

Fixes kern/27678.
 1.74 28-Sep-2004  yamt ex_add_rxbuf: use MRESETDATA macro.
 1.73 02-Jul-2004  bouyer Fix PR 25788 by Arto Huusko using a cleaned up version of the provided patch.
Not reading the mii media status if the interface isn't up doesn't hurt,
as the real media status isn't reported if the interface isn't up anyway
(checked on i386).
On my alpha500, I tracked down the machine check to the GO_WINDOW(4) at
line 1858 of elinkxl.c. It's possible that the problem which was fixed in
rev 1.72 was also the GO_WINDOW(4) used in the non-mii case. tr from ddb
and a single-step show different results, and I trust the single-step
one :)
 1.72 10-Nov-2003  drochner branches: 1.72.2;
Reading the (non-MII) media status if the card is not running yields
"0xffff" (eg on i386) or a machine check (on alpha).
So don't read the status if !(UP&RUNNING).
 1.71 06-Jul-2003  jdolecek actually do gather some randomness (if it's enabled)
modelled after what elink3.c does
 1.70 05-Jun-2003  dogcow branches: 1.70.2;
Some models of the 556B don't turn on the transmitter without magic
values getting written. Fix from FreeBSD; cf sys/pci/if_xl.c, rev 1.110
 1.69 09-May-2003  christos PR/13653: Onno van der Linden: Set tranceiver media properly.
 1.68 31-Jan-2003  thorpej Use aprint_*().
 1.67 09-Nov-2002  enami Fix multicast handling on 3C905B or later card;
- Handle IFF_ALLMULTI case correctly. This is necessary to mrouted working.
Tested by taca@netbsd.org.
- Clear unnecessary multicast hash bit. Otherwise, unnecessary multicast
packet is received. Tested by me with the 3C905C bought at akihabara.
It was 2980yen.

The code is written by fvdl@netbsd.org and me.
 1.66 22-Oct-2002  fair Change the "dontcare bits" argument to ifmedia_init() to IFM_IMASK
so that it is possible select PHY instances other than the first
one (instance zero), if there is more than one PHY attached.
 1.65 01-Jul-2002  thorpej In ex_shutdown(), call ex_enable() to make sure the interface is
powered up and the PCI configuration registers restored. If we
don't do this, the firmware on some machines gets REALLY confused.
 1.64 20-Jun-2002  itojun more proper fix to ex_disable.
 1.63 12-May-2002  wiz branches: 1.63.2; 1.63.4;
Spelling fixes, from Sergey Svishchev in kern/16650.
 1.62 06-Apr-2002  mhitch Interface byte counts are counted in ether_input() and ether_output(). Don't
count them when reading the NIC counters - it doubles the count. Read the
NIC counters to prevent counter overflow interrupts, but don't add them to
the interface counters. Don't bother reading the upper counts because they
are just latched when reading the totals.

Fixes final part of PR#11549.
 1.61 28-Dec-2001  christos Clean up the C_ and S_ constants. We don't really need two sets of them.
Also make the interrupt handler for older 3com cards look like the xl one.
I.e. don't ack the interrupt latch bit before checking if it is set.
At the same time, introduce constants for the watched interrupts, so that
we don't copy them all over the place.
 1.60 13-Nov-2001  lukem add/cleanup RCSID
 1.59 10-Nov-2001  perry trivially rename some macro parameters to avoid lint warnings.
 1.58 03-Oct-2001  yamt branches: 1.58.2;
ack intr only when intr is for us.
 1.57 01-Oct-2001  yamt avoid losing a desc on error.
 1.56 16-Sep-2001  wiz Spell 'occurred' with two 'r's.
 1.55 19-Jul-2001  thorpej branches: 1.55.2;
Use BUS_DMA_READ and BUS_DMA_WRITE in some obvious places.
 1.54 07-Jul-2001  thorpej branches: 1.54.2;
bzero -> memset
 1.53 07-Jul-2001  thorpej bcopy -> strcpy
 1.52 07-Jul-2001  thorpej bcmp -> memcmp
 1.51 12-Jun-2001  thorpej Don't need INET or NS includes here.
 1.50 02-Jun-2001  thorpej Implement support for IP/TCP/UDP checksum offloading provided by
network interfaces. This works by pre-computing the pseudo-header
checksum and caching it, delaying the actual checksum to ip_output()
if the hardware cannot perform the sum for us. In-bound checksums
can either be fully-checked by hardware, or summed up for final
verification by software. This method was modeled after how this
is done in FreeBSD, although the code is significantly different in
most places.

We don't delay checksums for IPv6/TCP, but we do take advantage of the
cached pseudo-header checksum.

Note: hardware-assisted checksumming defaults to "off". It is
enabled with ifconfig(8). See the manual page for details.

Implement hardware-assisted checksumming on the DP83820 Gigabit Ethernet,
3c90xB/3c90xC 10/100 Ethernet, and Alteon Tigon/Tigon2 Gigabit Ethernet.
 1.49 10-May-2001  fvdl Despite what the hardware docs say, the global reset command is not
done when the command-in-progress bit has been cleared. The 1ms
time that is mentioned also seems wrong; 20,000us is not enough
on at least one machine. So, do a delay(100000) in ex_reset.
Fortunately, this function is only called when the card is
attached or when hardware failure is suspected.

While here, only mask one 1 bit in the 'reset hack' case.
 1.48 26-Apr-2001  kanaoka - Fix typo in comment.
- Add (missed)powerhook_disestablish() in ex_detach().
- Sync with below. Original commit log message:
Add new powerhook argument values, PWR_SOFTSUSPEND, PWR_SOFTSTANDBY and
PWR_SOFTRESUME. Apm calls powerhook with the values in normal interrupt
priority level while others are protected with splhigh().
 1.47 30-Jan-2001  thorpej branches: 1.47.2;
Power management support for the CardBus Etherlink XL cards.
From Masanori Kanaoka <kanaoka@ann.hi-ho.ne.jp>.
 1.46 14-Dec-2000  thorpej ALTQ'ify.
 1.45 15-Nov-2000  thorpej Move bpfattach()/bpfdetach() calls into ether_ifattach()/ether_ifdetach().
 1.44 14-Nov-2000  thorpej NBPG -> PAGE_SIZE
 1.43 17-Oct-2000  bouyer Support ETHERCAP_VLAN_MTU by ignoring the EX_UPD_ERROR and EX_UPD_OVERSIZED
status bits. Tested with a 3c905-TX.
 1.42 11-Oct-2000  thorpej Use ether_ioctl().
 1.41 01-Oct-2000  thorpej Move the check for "promisc + unicast + not for us" into ether_input(),
and change Ethernet drivers to always pass all received frames to
ether_input() (with a few exceptions, which are documented in the
code).
 1.40 19-Sep-2000  fvdl Add support for the 3c555, 556 and 556B MiniPCI cards. Based on the
cardbus code and the FreeBSD xl driver.
 1.39 31-Aug-2000  haya Correct LED polarity bit. This bit and PHY power bit should be
defined in elinkxlreg.h.
 1.38 29-Aug-2000  haya Add support 3C[CX]FE575CT.
 1.37 25-Aug-2000  haya Access on ELINK_W3_INTERNAL_CONFIG register with 32-bit mode. Remove
16-bit access code. This register is 32-bit. 16-bit access with the
register causes data inconsistency (especially for CardBus cards).
 1.36 28-Jun-2000  mrg remove include of <vm/vm.h>. <vm/vm.h> -> <uvm/uvm_extern.h>
 1.35 27-Jun-2000  mrg remove redudant <vm/pmap.h> includes. <vm/pmap.h> -> <uvm/uvm_pmap.h>
 1.34 29-May-2000  jhawk branches: 1.34.2;
For all network drivers that call ether_ifattach(), and also
have _detach() functions:
Ensure that softc keeps state about whether the attach succeeded,
and make the detach function return immediately if the attach did
not complete.
 1.33 12-May-2000  thorpej branches: 1.33.2;
Use ether_crc32_be().
 1.32 12-May-2000  tsutsui Read upd_pktstatus from DMA buffer after bus_dmamap_sync() called.
 1.31 30-Mar-2000  augustss Remove register declarations.
 1.30 23-Mar-2000  thorpej New callout mechanism with two major improvements over the old
timeout()/untimeout() API:
- Clients supply callout handle storage, thus eliminating problems of
resource allocation.
- Insertion and removal of callouts is constant time, important as
this facility is used quite a lot in the kernel.

The old timeout()/untimeout() API has been removed from the kernel.
 1.29 06-Mar-2000  thorpej No longer necessary to futz with ifp->if_baudrate here.
 1.28 02-Mar-2000  enami Check if device is active in the interrupt handler and the one second
tick handler.
 1.27 01-Mar-2000  thorpej Amend previous; pay attention to EX_CONF_MII on deactivate, too.
 1.26 01-Mar-2000  thorpej Only detach PHYs if we have MII in the first place, and remove a bunch
of #if 0'd code which was copied from the Tulip driver.
 1.25 05-Feb-2000  augustss Support detach.
 1.24 02-Feb-2000  thorpej Don't dry to diving MIIF_NOISOLATE in the PHY drivers. Instead, pass
flags down from the parent to child vi mii_attach().
 1.23 02-Feb-2000  thorpej Bring some order to the chaos which was the MII code function naming
"conventions".
 1.22 18-Jan-2000  mycroft Rearrange ex_intr() to use C_INTR_LATCH the same way the ep driver does,
to prevent race conditions.
 1.21 12-Dec-1999  thorpej Use htole32() and le32toh().
 1.20 19-Nov-1999  bouyer Adapt printf format for 64bit stats counters.
 1.19 17-Nov-1999  thorpej Use the common MII bit-bang module.
 1.18 17-Nov-1999  thorpej Make the MII code match the `ep' driver's (*again*).
 1.17 12-Nov-1999  thorpej Call mii_down() as appropriate.
 1.16 04-Nov-1999  thorpej Adapt to mii_phy_probe() change.
 1.15 15-Oct-1999  haya branches: 1.15.2; 1.15.4;
This is the first check-in of CardBus driver. CardBus driver contains
CardBus bus stub, YENTA PCI-CardBus bridge (cbb), 3Com 3C575TX driver
(ex) and Intel fxp driver.

TODO:
o Conform to the KNF more strictly.
o Be unified with pcmcia code as much as possible.
o Add more drivers for CardBus card, such as APA-1480 or USB card.

The affected files are listed below.

sys/arch/i386/conf/files.i386
sys/arch/macppc/conf/files.macppc
sys/conf/files
sys/dev/ic/elinkxl.c
sys/dev/ic/elinkxlvar.h
sys/dev/ic/i82365.c
sys/dev/ic/i82365var.h
sys/dev/isa/i82365_isasubr.c
sys/dev/pci/files.pci
sys/dev/pcmcia/pcmcia.c
sys/dev/pcmcia/pcmciachip.h

The added files are listed below.

sys/arch/i386/conf/CARDBUS
sys/arch/i386/include/rbus_machdep.h
sys/arch/i386/i386/rbus_machdep.c
sys/arch/macppc/include/rbus_machdep.h
sys/arch/macppc/macppc/rbus_machdep.c
sys/dev/cardbus/if_ex_cardbus.c
sys/dev/cardbus/Makefile.cardbusdevs
sys/dev/cardbus/cardbus.c
sys/dev/cardbus/cardbus_map.c
sys/dev/cardbus/cardbusdevs
sys/dev/cardbus/cardbusdevs.h
sys/dev/cardbus/cardbusdevs_data.h
sys/dev/cardbus/cardbusvar.h
sys/dev/cardbus/cardslot.c
sys/dev/cardbus/cardslotvar.h
sys/dev/cardbus/devlist2h.awk
sys/dev/cardbus/files.cardbus
sys/dev/cardbus/if_fxp_cardbus.c
sys/dev/cardbus/pccardcis.h
sys/dev/cardbus/rbus.c
sys/dev/cardbus/rbus.h
sys/dev/pci/pccbb.c
sys/dev/pci/pccbbreg.h
sys/dev/pci/pccbbvar.h
 1.14 01-Sep-1999  fvdl branches: 1.14.2;
Select the right transceiver type when configuring the driver. Change the
timing for the mii code a bit. From Robert Elz / the FreeBSD xl driver.
 1.13 18-May-1999  thorpej Rework layer 2 protocol input routines. Instead of calling e.g. ether_input()
directly, call the function pointer (*if_input)(ifp, m). The input routine
expects the packet header to be at the head of the packet, and will adjust
as necessary. Privatize the layer 2 input and output routines, allowing
*_ifattach() to set them up as appropriate.
 1.12 14-May-1999  drochner The last change made the driver go into an interrupt loop after a while.
Obviously, the TX_DEFERRALS counter must be read.
 1.11 12-May-1999  thorpej Don't count deferrals as output errors. It's only a (single) output error
if an excessive number of deferrals causes the transmission to abort.
 1.10 28-Apr-1999  dean Fix for PR kern/7483: ex driver gets bogus MAC address with 3c905B
 1.9 26-Apr-1999  thorpej Make the 3Com Etherlink XL driver work on big-endian systems. From
Izumi Tsutsui, PR #7279.
 1.8 13-Apr-1999  jonathan Fix ex_read_eeprom() for 3c57x.
 1.7 29-Mar-1999  fvdl branches: 1.7.2;
Fix multicast hashing function. PR 7274, from Izumi Tsutsui
 1.6 25-Mar-1999  thorpej Use ETHER_*_LEN constants from <net/if_ether.h> instead of defining them
ourselves.
 1.5 28-Feb-1999  explorer Update to slightly altered rnd_attach_source() api
 1.4 17-Feb-1999  thorpej Avoid initializing the interface in the SIOCSIFFLAGS if ! UP and ! RUNNING.
 1.3 10-Jan-1999  drochner - Set up the interface watchdog timer on sends. This fixes the hangups
reported by Matthias Scheler <tron@lyssa.owl.de> in PR kern/6772.
- After receiving, check whether the receive DMA pointer became 0
what obviously happens if the list runs out of entries. Simply reinit
in this case. This fixes receive lockups after DDB use observed
by myself.
Unstall the receive engine if the ELINK_UPPKTSTATUS indicates that it
was stalled. (Don't know when this might happen. FreeBSD does so.)
 1.2 29-Nov-1998  thorpej Fix media probe on non-MII chips.
 1.1 04-Nov-1998  fvdl Add the 'ex' driver, a DMA driver for 3Com 90x and 90xB cards. Rename
constants from EP_ to ELINK_ since they're now used in the ex driver as well.
 1.7.2.4 18-Sep-1999  cgd pull up rev 1.14 from trunk (cgd):
Select the right tranceiver type when configuring the driver,
and change the timing for the MII code a bit. Fixes a problem
with MII not being reported correctly (PR#8363). (cgd)
 1.7.2.3 28-Apr-1999  perry branches: 1.7.2.3.2;
pullup 1.9->1.10 (Dean Huxley): fix kern/7483
 1.7.2.2 27-Apr-1999  perry pullup 1.8->1.9 (thorpej)
 1.7.2.1 27-Apr-1999  perry pullup 1.7->1.8 (Jonathan Stone)
 1.7.2.3.2.1 21-Jun-1999  thorpej Sync w/ -current.
 1.14.2.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.15.4.1 15-Nov-1999  fvdl Sync with -current
 1.15.2.4 11-Feb-2001  bouyer Sync with HEAD.
 1.15.2.3 05-Jan-2001  bouyer Sync with HEAD
 1.15.2.2 22-Nov-2000  bouyer Sync with HEAD.
 1.15.2.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.33.2.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.34.2.7 13-Feb-2002  he Apply patch (requested by joda):
Correct typo in previous pull-up.
 1.34.2.6 01-Jan-2002  he Pull up revisions 1.47-1.48 (via patch, requested by kanaoka):
Add Power Management support for Cardbus Etherlink XL cards, and
some cleanup.
 1.34.2.5 15-Nov-2001  he Pull up revision 1.39 (requested by haya):
Set correct bit for LED polarity. Affects CardBus cards, such
as 3c575[BC].
 1.34.2.4 15-May-2001  he Pull up revision 1.49 (requested by fvdl):
Wait longer after a card reset, avoids reading bad values from
the eeprom.
 1.34.2.3 20-Mar-2001  he Pull up revision 1.40 (via patch, requested by chuck):
Add support for the 3Com 3c555, 3c556 and 3c556B MiniPCI Ethernet
cards.
 1.34.2.2 31-Dec-2000  jhawk Pull up revision 1.43 via patch (requested by bouyer):
Add support for 802.1Q virtual LANs.
 1.34.2.1 01-Sep-2000  haya Pull up rev 1.37 and 1.38: Support 3C[CX]FE575CT.
This pullup is approved by <thorpej@netbsd.org>.
 1.47.2.10 11-Nov-2002  nathanw Catch up to -current
 1.47.2.9 01-Aug-2002  nathanw Catch up to -current.
 1.47.2.8 20-Jun-2002  nathanw Catch up to -current.
 1.47.2.7 17-Apr-2002  nathanw Catch up to -current.
 1.47.2.6 08-Jan-2002  nathanw Catch up to -current.
 1.47.2.5 14-Nov-2001  nathanw Catch up to -current.
 1.47.2.4 08-Oct-2001  nathanw Catch up to -current.
 1.47.2.3 21-Sep-2001  nathanw Catch up to -current.
 1.47.2.2 24-Aug-2001  nathanw Catch up with -current.
 1.47.2.1 21-Jun-2001  nathanw Catch up to -current.
 1.54.2.4 06-Sep-2002  jdolecek sync kqueue branch with HEAD
 1.54.2.3 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.54.2.2 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.54.2.1 03-Aug-2001  lukem update to -current
 1.55.2.2 11-Oct-2001  fvdl Catch up with -current. Fix some bogons in the sparc64 kbd/ms
attach code. cd18xx conversion provided by mrg.
 1.55.2.1 01-Oct-2001  fvdl Catch up with -current.
 1.58.2.1 12-Nov-2001  thorpej Sync the thorpej-mips-cache branch with -current.
 1.63.4.1 12-Dec-2002  he Pull up revision 1.67 (requested by taca in ticket #992):
Fix multicast handling on 3C905B or later card;
o Handle IFF_ALLMULTI case correctly. This is necessary
to mrouted working.
o Clear unnecessary multicast hash bit. Otherwise,
unnecessary multicast packet is received.
 1.63.2.1 15-Jul-2002  gehenna catch up with -current.
 1.70.2.10 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.70.2.9 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.70.2.8 07-Feb-2005  skrll Sunc with HEAD.
 1.70.2.7 06-Feb-2005  skrll Sync with HEAD.
 1.70.2.6 04-Feb-2005  skrll Sync with HEAD.
 1.70.2.5 02-Nov-2004  skrll Sync with HEAD.
 1.70.2.4 19-Oct-2004  skrll Sync with HEAD
 1.70.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.70.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.70.2.1 03-Aug-2004  skrll Sync with HEAD
 1.72.2.1 02-Jul-2004  he branches: 1.72.2.1.2;
Pull up revision 1.73 (requested by bouyer in ticket #581):
Make this driver work also on alpha systems, instead of
producing a machine check, by only reading the mii media
status if the interface is up. Fixes PR#25788.
 1.72.2.1.2.3 16-Dec-2006  bouyer Back out 1.72.2.1.2.2 (requested by itohy in ticket #10825)
The problem fixed by 1.85 (pulled up in ticket #5942) is an
inconsistency between elinkxl.c and elink3reg.h, that was introduced
by elink3reg.h rev 1.27. elink3reg.h in netbsd-2 branch is 1.26, and
pulling up the change made them inconsistent, and caused problem
kern/31455 that had not been in netbsd-2 branch.
 1.72.2.1.2.2 28-Oct-2005  jmc Pullup rev 1.85 (requested by christos in ticket #5942)
The previous change (to use bus_space_read_2), was broken because it was
reading from an odd offset.
 1.72.2.1.2.1 24-Jan-2005  he Pull up revision 1.75 (requested by thorpej in ticket #939):
When adding or deleting multicast addresses, only change
the address filter if the interface is marked RUNNING.
Fixes PR#27678.
 1.75.6.2 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.75.6.1 12-Feb-2005  yamt sync with head.
 1.75.4.1 29-Apr-2005  kent sync with -current
 1.79.2.2 28-Oct-2005  jmc Pullup rev 1.85 (requested by christos in ticket #913)
The previous change (to use bus_space_read_2), was broken because it was
reading from an odd offset.
 1.79.2.1 06-Oct-2005  tron Pull up following revision(s) (requested by christos in ticket #863):
sys/dev/ic/elinkxl.c: revision 1.84
PR/31455: Robert Elz: ex (905[BC]) cards can hang in -current kernels
- fix bus_space_read_1 -> bus_space_read_2 since revision 1.27 changed
the bit defines to assume 2 byte reads.
- Increment oerrors in case of collisions
- Clamp success counter to 100, instead of letting rotate freely.
 1.83.2.5 11-Feb-2008  yamt sync with head.
 1.83.2.4 27-Oct-2007  yamt sync with head.
 1.83.2.3 03-Sep-2007  yamt sync with head.
 1.83.2.2 30-Dec-2006  yamt sync with head.
 1.83.2.1 21-Jun-2006  yamt sync with head.
 1.84.2.1 26-Oct-2005  yamt sync with head
 1.86.6.2 01-Jun-2006  kardel Sync with head.
 1.86.6.1 22-Apr-2006  simonb Sync with head.
 1.86.4.1 09-Sep-2006  rpaulo sync with head
 1.86.2.1 01-Mar-2006  yamt sync with head.
 1.87.8.1 19-Jun-2006  chap Sync with head.
 1.87.6.1 24-May-2006  tron Merge 2006-05-24 NetBSD-current into the "peter-altq" branch.
 1.87.2.1 24-May-2006  yamt sync with head.
 1.88.8.2 10-Dec-2006  yamt sync with head.
 1.88.8.1 22-Oct-2006  yamt sync with head
 1.88.6.1 18-Nov-2006  ad Sync with head.
 1.95.4.1 12-Mar-2007  rmind Sync with HEAD.
 1.96.4.1 11-Jul-2007  mjf Sync with head.
 1.96.2.3 23-Oct-2007  ad Sync with head.
 1.96.2.2 09-Oct-2007  ad Sync with head.
 1.96.2.1 01-Jul-2007  ad Adapt to callout API change.
 1.97.6.2 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.97.6.1 03-Sep-2007  jmcneill Sync with HEAD.
 1.97.2.1 03-Sep-2007  skrll Sync with HEAD.
 1.98.6.1 25-Oct-2007  bouyer Sync with HEAD.
 1.98.2.2 23-Mar-2008  matt sync with HEAD
 1.98.2.1 06-Nov-2007  matt sync with HEAD
 1.99.2.1 18-Feb-2008  mjf Sync with HEAD.
 1.100.6.2 17-Jan-2009  mjf Sync with HEAD.
 1.100.6.1 02-Jun-2008  mjf Sync with HEAD.
 1.104.4.5 11-Aug-2010  yamt sync with head.
 1.104.4.4 11-Mar-2010  yamt sync with head
 1.104.4.3 16-Sep-2009  yamt sync with head
 1.104.4.2 04-May-2009  yamt sync with head.
 1.104.4.1 16-May-2008  yamt sync with head.
 1.104.2.1 18-May-2008  yamt sync with head.
 1.105.8.1 19-Jan-2009  skrll Sync with HEAD.
 1.105.6.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.110.4.2 05-Mar-2011  rmind sync with head
 1.110.4.1 30-May-2010  rmind sync with head
 1.110.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.113.12.1 18-Feb-2012  mrg merge to -current.
 1.113.8.2 30-Oct-2012  yamt sync with head
 1.113.8.1 17-Apr-2012  yamt sync with head
 1.115.12.1 07-Apr-2014  tls Be a little more clear and consistent about harvesting entropy from devices:

1) deprecate RND_FLAG_NO_ESTIMATE

2) define RND_FLAG_COLLECT_TIME, RND_FLAG_COLLECT_VALUE

3) define RND_FLAG_ESTIMATE_TIME, RND_FLAG_ESTIMATE_VALUE

4) define RND_FLAG_DEFAULT: RND_FLAG_COLLECT_TIME|
RND_FLAG_COLLECT_VALUE|RND_FLAG_ESTIMATE_TIME

5) Make entropy harvesting from environmental sensors a little more generic
and remove it from individual sensor drivers.

6) Remove individual open-coded delta-estimators for values from a few
places in the tree (uvm, environmental drivers).

7) 0 -> RND_FLAG_DEFAULT, actually gather entropy from various drivers
that had stubbed out code, other minor cleanups.
 1.115.2.2 03-Dec-2017  jdolecek update from HEAD
 1.115.2.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.116.4.5 28-Aug-2017  skrll Sync with HEAD
 1.116.4.4 05-Feb-2017  skrll Sync with HEAD
 1.116.4.3 09-Jul-2016  skrll Sync with HEAD
 1.116.4.2 19-Mar-2016  skrll Sync with HEAD
 1.116.4.1 06-Jun-2015  skrll Sync with HEAD
 1.119.2.2 20-Mar-2017  pgoyette Sync with HEAD
 1.119.2.1 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.120.2.1 21-Apr-2017  bouyer Sync with HEAD
 1.121.12.4 26-Jan-2019  pgoyette Sync with HEAD
 1.121.12.3 06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.121.12.2 28-Jul-2018  pgoyette Sync with HEAD
 1.121.12.1 25-Jun-2018  pgoyette Sync with HEAD
 1.121.6.3 11-Feb-2020  martin Pull up following revision(s) (requested by msaitoh in ticket #1501):

sys/dev/ic/elinkxl.c: revision 1.137

Restore an register read for RX_FRAMES_OK which was removed in rev. 1.133.

All statistics registers should be read to ACK the interrupt. Fixes PR#54920.
XXX pullup-[89]
 1.121.6.2 06-Nov-2019  martin Pull up following revision(s) (requested by msaitoh in ticket #1427):

sys/arch/arm/broadcom/bcm53xx_eth.c: revision 1.39
sys/dev/pcmcia/if_xi.c: revision 1.91
sys/dev/ic/aic6915.c: revision 1.40
sys/dev/pci/if_tl.c: revision 1.117
sys/arch/arm/gemini/gemini_gmac.c: revision 1.18
sys/dev/ic/elinkxl.c: revision 1.133
sys/dev/pci/if_ste.c: revision 1.57
sys/dev/pci/if_alc.c: revision 1.43
sys/dev/pci/if_stge.c: revision 1.72
sys/dev/pci/if_ale.c: revision 1.34
sys/dev/pci/if_age.c: revision 1.62
sys/dev/pci/if_txp.c: revision 1.60
sys/dev/ic/i82557.c: revision 1.156
sys/dev/pci/if_vte.c: revision 1.27
sys/arch/powerpc/booke/dev/pq3etsec.c: revision 1.47
sys/arch/arm/gemini/if_gpn.c: revision 1.13

if_percpuq(9) and ether_input() automatically increment if_ipackets, so don't add number of
RX frames from device's statistics counter to if_ipackets to avoid double
count.
 1.121.6.1 26-Jul-2018  snj Pull up following revision(s) (requested by msaitoh in ticket #938):
sys/arch/acorn32/podulebus/if_ie.c: revision 1.41
sys/arch/amiga/dev/if_es.c: revision 1.58
sys/arch/amiga/dev/if_qn.c: revision 1.45
sys/arch/arm/at91/at91emac.c: revision 1.20
sys/arch/arm/ep93xx/epe.c: revision 1.37
sys/arch/emips/ebus/if_le_ebus.c: revision 1.14
sys/arch/emips/ebus/if_le_ebus.c: revision 1.15
sys/arch/mac68k/dev/if_mc.c: revision 1.46
sys/arch/macppc/dev/am79c950.c: revision 1.39
sys/arch/newsmips/apbus/if_sn.c: revision 1.40
sys/arch/next68k/dev/mb8795.c: revision 1.59
sys/arch/playstation2/dev/if_smap.c: revision 1.25
sys/arch/playstation2/dev/if_smap.c: revision 1.26
sys/arch/sun2/dev/if_ec.c: revision 1.28
sys/arch/sun3/dev/if_ie.c: revision 1.63
sys/arch/x68k/dev/if_ne_intio.c: revision 1.19
sys/arch/xen/xen/if_xennet_xenbus.c: revision 1.75
sys/arch/xen/xen/xennetback_xenbus.c: revision 1.63
sys/dev/bi/if_ni.c: revision 1.45
sys/dev/cadence/if_cemac.c: revision 1.12
sys/dev/ic/am7990.c: revision 1.78
sys/dev/ic/am79900.c: revision 1.27
sys/dev/ic/an.c: revision 1.67
sys/dev/ic/cs89x0.c: revision 1.40
sys/dev/ic/dm9000.c: revision 1.13
sys/dev/ic/dm9000.c: revision 1.14
sys/dev/ic/dp8390.c: revision 1.88
sys/dev/ic/elink3.c: revision 1.141
sys/dev/ic/elinkxl.c: revision 1.122
sys/dev/ic/hme.c: revision 1.98
sys/dev/ic/i82586.c: revision 1.77
sys/dev/ic/lance.c: revision 1.53
sys/dev/ic/mb86950.c: revision 1.27
sys/dev/ic/mb86960.c: revision 1.86
sys/dev/ic/mtd803.c: revision 1.34
sys/dev/ic/pdq_ifsubr.c: revision 1.59
sys/dev/ic/rrunner.c: revision 1.86
sys/dev/ic/seeq8005.c: revision 1.58
sys/dev/ic/sgec.c: revision 1.47
sys/dev/ic/smc90cx6.c: revision 1.72
sys/dev/ic/smc91cxx.c: revision 1.96
sys/dev/ic/tropic.c: revision 1.49
sys/dev/ic/wi.c: revision 1.245
sys/dev/isa/if_eg.c: revision 1.93
sys/dev/isa/if_el.c: revision 1.95
sys/dev/isa/if_iy.c: revision 1.101
sys/dev/ofw/ofnet.c: revision 1.58
sys/dev/pci/if_alc.c: revision 1.27
sys/dev/pci/if_de.c: revision 1.152
sys/dev/pci/if_fpa.c: revision 1.61
sys/dev/pci/if_jme.c: revision 1.34
sys/dev/pci/if_tl.c: revision 1.108
sys/dev/pci/if_vte.c: revision 1.19
sys/dev/pci/ixgbe/ixgbe.h: revision 1.50
sys/dev/pcmcia/if_cnw.c: revision 1.62
sys/dev/pcmcia/if_malo_pcmcia.c: revision 1.17
sys/dev/pcmcia/if_ray.c: revision 1.89
sys/dev/pcmcia/if_xi.c: revision 1.81
sys/dev/pcmcia/mhzc.c: revision 1.51
sys/dev/pcmcia/xirc.c: revision 1.34
sys/dev/qbus/if_de.c: revision 1.33
sys/dev/qbus/if_qe.c: revision 1.78
sys/dev/qbus/if_qt.c: revision 1.22
sys/dev/sbus/be.c: revision 1.87
sys/dev/sbus/qe.c: revision 1.68
sys/dev/scsipi/if_se.c: revision 1.96
sys/dev/usb/if_atu.c: revision 1.59
sys/net/if_l2tp.c: revision 1.28 via patch
sys/net/if_ppp.c: revision 1.160
It's not required to include net/bpfdesc.h. Remove it.
--
Simplify like other drivers. NULL check of ifp->if_bpf is done in
bpf_mtap(), so it's not required to do it here.
--
Remove duplicated inclusion of net/bpf.h.
--
Remove duplicated inclusion of net/bpf.h.
--
Simplify bpf_mtap() call. No functional change.
 1.124.2.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.124.2.1 10-Jun-2019  christos Sync with HEAD
 1.131.2.2 11-Feb-2020  martin Pull up following revision(s) (requested by msaitoh in ticket #695):

sys/dev/ic/elinkxl.c: revision 1.137

Restore an register read for RX_FRAMES_OK which was removed in rev. 1.133.

All statistics registers should be read to ACK the interrupt. Fixes PR#54920.
XXX pullup-[89]
 1.131.2.1 06-Nov-2019  martin Pull up following revision(s) (requested by msaitoh in ticket #403):

sys/arch/arm/broadcom/bcm53xx_eth.c: revision 1.39
sys/dev/pcmcia/if_xi.c: revision 1.91
sys/dev/ic/aic6915.c: revision 1.40
sys/dev/pci/if_tl.c: revision 1.117
sys/arch/arm/gemini/gemini_gmac.c: revision 1.18
sys/dev/ic/elinkxl.c: revision 1.133
sys/dev/pci/if_ste.c: revision 1.57
sys/dev/pci/if_alc.c: revision 1.43
sys/dev/pci/if_stge.c: revision 1.72
sys/dev/pci/if_ale.c: revision 1.34
sys/dev/pci/if_age.c: revision 1.62
sys/dev/pci/if_txp.c: revision 1.60
sys/dev/ic/i82557.c: revision 1.156
sys/dev/pci/if_vte.c: revision 1.27
sys/arch/powerpc/booke/dev/pq3etsec.c: revision 1.47
sys/arch/arm/gemini/if_gpn.c: revision 1.13

if_percpuq(9) and ether_input() automatically increment if_ipackets, so don't add number of
RX frames from device's statistics counter to if_ipackets to avoid double
count.
 1.133.2.1 29-Feb-2020  ad Sync with head.
 1.15 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.14 04-Mar-2007  christos branches: 1.14.36; 1.14.38; 1.14.40;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.13 17-Nov-2006  tsutsui branches: 1.13.4;
Use ETHER_HDR_LEN rather than sizeof(struct ether_header).

BTW, should we have the similar ip4csum-tx bug workaround for fxp(4)?
 1.12 12-Nov-2006  tsutsui Add a workaround for a hardware ip4csum-tx bug which would sometimes put
wrong IPv4 checksum on sending 21 or 22 byte IP packets.

See discussion on tech-kern and tech-net for details:
http://mail-index.netbsd.org/tech-kern/2006/11/04/0004.html
 1.11 09-Nov-2002  enami branches: 1.11.22; 1.11.52; 1.11.54;
Fix multicast handling on 3C905B or later card;
- Handle IFF_ALLMULTI case correctly. This is necessary to mrouted working.
Tested by taca@netbsd.org.
- Clear unnecessary multicast hash bit. Otherwise, unnecessary multicast
packet is received. Tested by me with the 3C905C bought at akihabara.
It was 2980yen.

The code is written by fvdl@netbsd.org and me.
 1.10 28-Dec-2001  christos branches: 1.10.10;
Clean up the C_ and S_ constants. We don't really need two sets of them.
Also make the interrupt handler for older 3com cards look like the xl one.
I.e. don't ack the interrupt latch bit before checking if it is set.
At the same time, introduce constants for the watched interrupts, so that
we don't copy them all over the place.
 1.9 28-Nov-2001  christos ELINK_W4_UBYTESOK is 0x0d. This is probably why kim is getting x2 numbers
in stats.
 1.8 11-Nov-2001  christos merge duplicate register definitions.
 1.7 22-Jul-2001  wiz branches: 1.7.4;
seperate -> separate
 1.6 23-May-2001  fvdl branches: 1.6.2;
Add missing definitions for hw checksumming.
 1.5 03-May-2001  fvdl Bump values of the number of up- and downlaod descriptors such that
saturating a 100Mbit link will not lead to running out of them.
 1.4 17-Oct-2000  bouyer branches: 1.4.2;
Support ETHERCAP_VLAN_MTU by ignoring the EX_UPD_ERROR and EX_UPD_OVERSIZED
status bits. Tested with a 3c905-TX.
 1.3 19-Sep-2000  fvdl Add support for the 3c555, 556 and 556B MiniPCI cards. Based on the
cardbus code and the FreeBSD xl driver.
 1.2 01-Sep-1999  fvdl branches: 1.2.2; 1.2.12;
Select the right transceiver type when configuring the driver. Change the
timing for the mii code a bit. From Robert Elz / the FreeBSD xl driver.
 1.1 04-Nov-1998  fvdl branches: 1.1.6;
Add the 'ex' driver, a DMA driver for 3Com 90x and 90xB cards. Rename
constants from EP_ to ELINK_ since they're now used in the ex driver as well.
 1.1.6.1 18-Sep-1999  cgd pull up rev 1.2 from trunk (cgd):
Select the right tranceiver type when configuring the driver,
and change the timing for the MII code a bit. Fixes a problem
with MII not being reported correctly (PR#8363). (cgd)
 1.2.12.3 03-May-2001  he Pull up revision 1.5 (requested by fvdl):
Bump number of descriptors so that you will not run out of them
when saturating a 100Mbit/s link.
 1.2.12.2 20-Mar-2001  he Pull up revision 1.3 (via patch, requested by chuck):
Add support for the 3Com 3c555, 3c556 and 3c556B MiniPCI Ethernet
cards.
 1.2.12.1 31-Dec-2000  jhawk Pull up revision 1.4 (requested by bouyer):
Add support for 802.1Q virtual LANs.
 1.2.2.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.4.2.5 11-Nov-2002  nathanw Catch up to -current
 1.4.2.4 08-Jan-2002  nathanw Catch up to -current.
 1.4.2.3 14-Nov-2001  nathanw Catch up to -current.
 1.4.2.2 24-Aug-2001  nathanw Catch up with -current.
 1.4.2.1 21-Jun-2001  nathanw Catch up to -current.
 1.6.2.2 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.6.2.1 03-Aug-2001  lukem update to -current
 1.7.4.1 12-Nov-2001  thorpej Sync the thorpej-mips-cache branch with -current.
 1.10.10.1 12-Dec-2002  he Pull up revision 1.11 (requested by taca in ticket #992):
Fix multicast handling on 3C905B or later card;
o Handle IFF_ALLMULTI case correctly. This is necessary
to mrouted working.
o Clear unnecessary multicast hash bit. Otherwise,
unnecessary multicast packet is received.
 1.11.54.1 10-Dec-2006  yamt sync with head.
 1.11.52.2 12-Jan-2007  ad Sync with head.
 1.11.52.1 18-Nov-2006  ad Sync with head.
 1.11.22.2 03-Sep-2007  yamt sync with head.
 1.11.22.1 30-Dec-2006  yamt sync with head.
 1.13.4.1 12-Mar-2007  rmind Sync with HEAD.
 1.14.40.1 16-May-2008  yamt sync with head.
 1.14.38.1 18-May-2008  yamt sync with head.
 1.14.36.1 02-Jun-2008  mjf Sync with HEAD.
 1.26 13-Sep-2019  msaitoh if_flags is neither int nor short. It's unsigned short.
 1.25 13-Apr-2015  riastradh branches: 1.25.18;
Convert sys/dev to use <sys/rndsource.h>.
 1.24 02-Feb-2012  tls branches: 1.24.6; 1.24.24;
Entropy-pool implementation move and cleanup.

1) Move core entropy-pool code and source/sink/sample management code
to sys/kern from sys/dev.

2) Remove use of NRND as test for presence of entropy-pool code throughout
source tree.

3) Remove use of RND_ENABLED in device drivers as microoptimization to
avoid expensive operations on disabled entropy sources; make the
rnd_add calls do this directly so all callers benefit.

4) Fix bug in recent rnd_add_data()/rnd_add_uint32() changes that might
have lead to slight entropy overestimation for some sources.

5) Add new source types for environmental sensors, power sensors, VM
system events, and skew between clocks, with a sample implementation
for each.

ok releng to go in before the branch due to the difficulty of later
pullup (widespread #ifdef removal and moved files). Tested with release
builds on amd64 and evbarm and live testing on amd64.
 1.23 19-Nov-2011  tls branches: 1.23.2;
First step of random number subsystem rework described in
<20111022023242.BA26F14A158@mail.netbsd.org>. This change includes
the following:

An initial cleanup and minor reorganization of the entropy pool
code in sys/dev/rnd.c and sys/dev/rndpool.c. Several bugs are
fixed. Some effort is made to accumulate entropy more quickly at
boot time.

A generic interface, "rndsink", is added, for stream generators to
request that they be re-keyed with good quality entropy from the pool
as soon as it is available.

The arc4random()/arc4randbytes() implementation in libkern is
adjusted to use the rndsink interface for rekeying, which helps
address the problem of low-quality keys at boot time.

An implementation of the FIPS 140-2 statistical tests for random
number generator quality is provided (libkern/rngtest.c). This
is based on Greg Rose's implementation from Qualcomm.

A new random stream generator, nist_ctr_drbg, is provided. It is
based on an implementation of the NIST SP800-90 CTR_DRBG by
Henric Jungheim. This generator users AES in a modified counter
mode to generate a backtracking-resistant random stream.

An abstraction layer, "cprng", is provided for in-kernel consumers
of randomness. The arc4random/arc4randbytes API is deprecated for
in-kernel use. It is replaced by "cprng_strong". The current
cprng_fast implementation wraps the existing arc4random
implementation. The current cprng_strong implementation wraps the
new CTR_DRBG implementation. Both interfaces are rekeyed from
the entropy pool automatically at intervals justifiable from best
current cryptographic practice.

In some quick tests, cprng_fast() is about the same speed as
the old arc4randbytes(), and cprng_strong() is about 20% faster
than rnd_extract_data(). Performance is expected to improve.

The AES code in src/crypto/rijndael is no longer an optional
kernel component, as it is required by cprng_strong, which is
not an optional kernel component.

The entropy pool output is subjected to the rngtest tests at
startup time; if it fails, the system will reboot. There is
approximately a 3/10000 chance of a false positive from these
tests. Entropy pool _input_ from hardware random numbers is
subjected to the rngtest tests at attach time, as well as the
FIPS continuous-output test, to detect bad or stuck hardware
RNGs; if any are detected, they are detached, but the system
continues to run.

A problem with rndctl(8) is fixed -- datastructures with
pointers in arrays are no longer passed to userspace (this
was not a security problem, but rather a major issue for
compat32). A new kernel will require a new rndctl.

The sysctl kern.arandom() and kern.urandom() nodes are hooked
up to the new generators, but the /dev/*random pseudodevices
are not, yet.

Manual pages for the new kernel interfaces are forthcoming.
 1.22 22-Mar-2010  dyoung branches: 1.22.8;
ex_softc.ex_bustype is written but never read. Just get rid of it.
 1.21 22-Mar-2010  dyoung Add a self-suspensor. It's not used, yet.

In ex_detach(), call ex_stop(), first. ex_stop() stops the callout.
Destroy the callout in ex_detach().
 1.20 28-Apr-2008  martin branches: 1.20.20; 1.20.22;
Remove clause 3 and 4 from TNF licenses
 1.19 14-Apr-2008  spz branches: 1.19.2; 1.19.4;
pretty up if_ex: pmf'ify, device split, and improve printing a bit too.

Reviewed and function-tested on if_ex_cardbus by cube (thanks).
Function-tested on if_ex_pci by myself.
 1.18 04-Mar-2007  christos branches: 1.18.36;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.17 11-Dec-2005  christos branches: 1.17.26;
merge ktrace-lwp.
 1.16 06-Feb-2005  kim branches: 1.16.6;
If the interface is up and running, only modify the receive filter
when setting promiscuous or debug mode. This avoids resetting the
chip unnecessarily.

Fixes PR kern/29126.
 1.15 04-Feb-2005  perry de-__P
 1.14 05-Jun-2003  dogcow branches: 1.14.2; 1.14.10; 1.14.12;
Some models of the 556B don't turn on the transmitter without magic
values getting written. Fix from FreeBSD; cf sys/pci/if_xl.c, rev 1.110
 1.13 20-Jun-2002  itojun more proper fix to ex_disable.
 1.12 28-Dec-2001  christos branches: 1.12.8;
Clean up the C_ and S_ constants. We don't really need two sets of them.
Also make the interrupt handler for older 3com cards look like the xl one.
I.e. don't ack the interrupt latch bit before checking if it is set.
At the same time, introduce constants for the watched interrupts, so that
we don't copy them all over the place.
 1.11 25-Oct-2001  haya Prevent hang-up when a CardBus card is removed during the card is working.
 1.10 30-Jan-2001  thorpej branches: 1.10.2; 1.10.4; 1.10.8;
Power management support for the CardBus Etherlink XL cards.
From Masanori Kanaoka <kanaoka@ann.hi-ho.ne.jp>.
 1.9 11-Oct-2000  thorpej Use ether_ioctl().
 1.8 19-Sep-2000  fvdl Add support for the 3c555, 556 and 556B MiniPCI cards. Based on the
cardbus code and the FreeBSD xl driver.
 1.7 24-Aug-2000  haya Add flag defines for 3CCFE575BT and 3CCCFE575CT (CardBus cards).
 1.6 29-May-2000  jhawk branches: 1.6.2;
For all network drivers that call ether_ifattach(), and also
have _detach() functions:
Ensure that softc keeps state about whether the attach succeeded,
and make the detach function return immediately if the attach did
not complete.
 1.5 23-Mar-2000  thorpej branches: 1.5.2;
New callout mechanism with two major improvements over the old
timeout()/untimeout() API:
- Clients supply callout handle storage, thus eliminating problems of
resource allocation.
- Insertion and removal of callouts is constant time, important as
this facility is used quite a lot in the kernel.

The old timeout()/untimeout() API has been removed from the kernel.
 1.4 05-Feb-2000  augustss Support detach.
 1.3 15-Oct-1999  haya branches: 1.3.2;
This is the first check-in of CardBus driver. CardBus driver contains
CardBus bus stub, YENTA PCI-CardBus bridge (cbb), 3Com 3C575TX driver
(ex) and Intel fxp driver.

TODO:
o Conform to the KNF more strictly.
o Be unified with pcmcia code as much as possible.
o Add more drivers for CardBus card, such as APA-1480 or USB card.

The affected files are listed below.

sys/arch/i386/conf/files.i386
sys/arch/macppc/conf/files.macppc
sys/conf/files
sys/dev/ic/elinkxl.c
sys/dev/ic/elinkxlvar.h
sys/dev/ic/i82365.c
sys/dev/ic/i82365var.h
sys/dev/isa/i82365_isasubr.c
sys/dev/pci/files.pci
sys/dev/pcmcia/pcmcia.c
sys/dev/pcmcia/pcmciachip.h

The added files are listed below.

sys/arch/i386/conf/CARDBUS
sys/arch/i386/include/rbus_machdep.h
sys/arch/i386/i386/rbus_machdep.c
sys/arch/macppc/include/rbus_machdep.h
sys/arch/macppc/macppc/rbus_machdep.c
sys/dev/cardbus/if_ex_cardbus.c
sys/dev/cardbus/Makefile.cardbusdevs
sys/dev/cardbus/cardbus.c
sys/dev/cardbus/cardbus_map.c
sys/dev/cardbus/cardbusdevs
sys/dev/cardbus/cardbusdevs.h
sys/dev/cardbus/cardbusdevs_data.h
sys/dev/cardbus/cardbusvar.h
sys/dev/cardbus/cardslot.c
sys/dev/cardbus/cardslotvar.h
sys/dev/cardbus/devlist2h.awk
sys/dev/cardbus/files.cardbus
sys/dev/cardbus/if_fxp_cardbus.c
sys/dev/cardbus/pccardcis.h
sys/dev/cardbus/rbus.c
sys/dev/cardbus/rbus.h
sys/dev/pci/pccbb.c
sys/dev/pci/pccbbreg.h
sys/dev/pci/pccbbvar.h
 1.2 13-Apr-1999  jonathan branches: 1.2.2;
Fix ex_read_eeprom() for 3c57x.
 1.1 04-Nov-1998  fvdl branches: 1.1.6;
Add the 'ex' driver, a DMA driver for 3Com 90x and 90xB cards. Rename
constants from EP_ to ELINK_ since they're now used in the ex driver as well.
 1.1.6.1 27-Apr-1999  perry branches: 1.1.6.1.2;
pullup 1.1->1.2 (Jonathan Stone)
 1.1.6.1.2.1 21-Jun-1999  thorpej Sync w/ -current.
 1.2.2.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.3.2.2 11-Feb-2001  bouyer Sync with HEAD.
 1.3.2.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.5.2.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.6.2.3 01-Jan-2002  he Pull up revision 1.10 (requested by kanaoka):
Add Power Management support for Cardbus Etherlink XL cards, and
some cleanup.
 1.6.2.2 20-Mar-2001  he Pull up revision 1.8 (via patch, requested by chuck):
Add support for the 3Com 3c555, 3c556 and 3c556B MiniPCI Ethernet
cards.
 1.6.2.1 01-Sep-2000  haya Pull up rev 1.7: Support 3C[CX]FE575CT.
This pullup is approved by <thorpej@netbsd.org>.
 1.10.8.1 12-Nov-2001  thorpej Sync the thorpej-mips-cache branch with -current.
 1.10.4.2 06-Sep-2002  jdolecek sync kqueue branch with HEAD
 1.10.4.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.10.2.3 01-Aug-2002  nathanw Catch up to -current.
 1.10.2.2 08-Jan-2002  nathanw Catch up to -current.
 1.10.2.1 14-Nov-2001  nathanw Catch up to -current.
 1.12.8.1 15-Jul-2002  gehenna catch up with -current.
 1.14.12.1 12-Feb-2005  yamt sync with head.
 1.14.10.1 29-Apr-2005  kent sync with -current
 1.14.2.2 06-Feb-2005  skrll Sync with HEAD.
 1.14.2.1 04-Feb-2005  skrll Sync with HEAD.
 1.16.6.1 03-Sep-2007  yamt sync with head.
 1.17.26.1 12-Mar-2007  rmind Sync with HEAD.
 1.18.36.1 02-Jun-2008  mjf Sync with HEAD.
 1.19.4.2 11-Aug-2010  yamt sync with head.
 1.19.4.1 16-May-2008  yamt sync with head.
 1.19.2.1 18-May-2008  yamt sync with head.
 1.20.22.1 30-May-2010  rmind sync with head
 1.20.20.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.22.8.1 17-Apr-2012  yamt sync with head
 1.23.2.1 18-Feb-2012  mrg merge to -current.
 1.24.24.1 06-Jun-2015  skrll Sync with HEAD
 1.24.6.1 03-Dec-2017  jdolecek update from HEAD
 1.25.18.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.63 08-Feb-2024  andvar s/should't/shouldn't/ and s/mistmatch/mismatch/ in comments.
 1.62 02-Nov-2022  andvar s/ourselve/ourselves/ in comments.
 1.61 23-May-2022  andvar s/beggining/beginning/ in comments.
 1.60 23-Feb-2022  andvar fix various typos in comments, mainly immediatly/immediately/,
as well shared and recently fixed typos in OpenBSD code by Jonathan Grey.
 1.59 07-Aug-2021  thorpej Merge thorpej-cfargs2.
 1.58 24-Apr-2021  thorpej branches: 1.58.8;
Merge thorpej-cfargs branch:

Simplify and make extensible the config_search() / config_found() /
config_attach() interfaces: rather than having different variants for
which arguments you want pass along, just have a single call that
takes a variadic list of tag-value arguments.

Adjust all call sites:
- Simplify wherever possible; don't pass along arguments that aren't
actually needed.
- Don't be explicit about what interface attribute is attaching if
the device only has one. (More simplification.)
- Add a config_probe() function to be used in indirect configuiration
situations, making is visibly easier to see when indirect config is
in play, and allowing for future change in semantics. (As of now,
this is just a wrapper around config_match(), but that is an
implementation detail.)

Remove unnecessary or redundant interface attributes where they're not
needed.

There are currently 5 "cfargs" defined:
- CFARG_SUBMATCH (submatch function for direct config)
- CFARG_SEARCH (search function for indirect config)
- CFARG_IATTR (interface attribte)
- CFARG_LOCATORS (locators array)
- CFARG_DEVHANDLE (devhandle_t - wraps OFW, ACPI, etc. handles)

...and a sentinel value CFARG_EOL.

Add some extra sanity checking to ensure that interface attributes
aren't ambiguous.

Use CFARG_DEVHANDLE in MI FDT, OFW, and ACPI code, and macppc and shark
ports to associate those device handles with device_t instance. This
will trickle trough to more places over time (need back-end for pre-OFW
Sun OBP; any others?).
 1.57 02-Nov-2013  gson branches: 1.57.46;
Turn the "esiop_intr: I shouldn't be there !" panic into a printf
followed by a return from the interrupt handler. The condition is
triggered on some KVM virtual hosts, apparently harmlessly, and not
panicing makes it possible to boot a NetBSD GENERIC kernel on those
hosts. Also make the same change to siop to minimize divergence
between siop and esiop. Fixes PR kern/48277.
 1.56 30-Oct-2013  gson Fix incorrect function names in panic message strings.
 1.55 13-Nov-2010  uebayasi branches: 1.55.8; 1.55.14; 1.55.18; 1.55.22;
Don't pull in the whole uvm(9) API to access only PAGE_SIZE and
some other constants. These are provided by sys/param.h now.
 1.54 09-Sep-2010  jakllsch Allow e?siop_dump_script() to work with on-chip RAM. Prefix
DUMP_SCRIPT with SIOP_. Additionally, avoid undefining DEBUG,
condition on SIOP_DEBUG instead.
 1.53 02-May-2010  jakllsch Add (missing) newlines to error messages.
 1.52 09-Apr-2010  jakllsch Improve error paths in (e)siop_scsipi_request():

- When terminating the adapter request after the cmd has been removed
from the free list, put that cmd back on the free list before returing.
- Correctly indicate which bus_dma_load() failed.

Analysis and fix from Michael L. Hitch in PR/42844.
 1.51 11-Mar-2010  mrg branches: 1.51.2;
various aprint_* fixes.
 1.50 12-Feb-2010  dholland Make ESIOP_DEBUG compile (on some platforms? depends on bus definitions...)
From Chris Ross in PR 42792.
 1.49 19-Oct-2009  bouyer branches: 1.49.2;
Remove closes 3 & 4 from my licence. Lots of thanks to Soren Jacobsen
for the booring work !
 1.48 04-Sep-2009  tsutsui Remove unnecessary whitespace.
 1.47 16-May-2009  tsutsui Misc cleanup:
- some KNF
- u_intNN_t -> uintNN_t
- wrap long lines and fix indent
- remove return statements at the end of void functions
- use __arraycount()

XXX: many inconsistent aprint_error_dev(9) vs printf(9)
 1.46 15-May-2009  tsutsui Split device_t/softc.

No crash on:
esiop0 at pci0 dev 11 function 0: Symbios Logic 53c875 (ultra-wide scsi)
siop0 at pci0 dev 9 function 0: Symbios Logic 53c810a (fast scsi)
siop0 at gsc0 hpa 0xf0830000 path 2/0/7 irq 3 ipl 6: NCR53C720 rev 2
 1.45 15-Mar-2009  cegger ansify function definitions
 1.44 14-Mar-2009  dsl ANSIfy another 1261 function definitions.
The only ones left in sys are beyond by sed script!
(or in sys/dist or sys/external)
Mostly they have function pointer parameters.
 1.43 14-Mar-2009  dsl Change about 4500 of the K&R function definitions to ANSI ones.
There are still about 1600 left, but they have ',' or /* ... */
in the actual variable definitions - which my awk script doesn't handle.
There are also many that need () -> (void).
(The script does handle misordered arguments.)
 1.42 08-Apr-2008  cegger branches: 1.42.4; 1.42.12; 1.42.14; 1.42.18;
use aprint_*_dev and device_xname
 1.41 19-Oct-2007  ad branches: 1.41.16;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.40 30-Sep-2007  martin branches: 1.40.2;
Do not stop callouts on polled commands. Problem noticed by Chris Ross
when trying to do a kernel dump on sparc64.
Approved by Manuel Bouyer.
 1.39 04-Mar-2007  christos branches: 1.39.2; 1.39.14; 1.39.16; 1.39.18;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.38 02-Nov-2006  garbled branches: 1.38.4;
Comment out the debug options to siop, and change the undef to define.
This way they will be compiled by the i386 DEBUG kernel and tested.
 1.37 02-Nov-2006  garbled Make these compile when SIOP_DEBUG is enabled, by nuking the reference to
t_offset, which no longer seems to exist.
 1.36 29-Sep-2006  christos Coverity CID 3015: Check before using (from Arnaud Lacombe)
 1.35 24-Dec-2005  perry branches: 1.35.20; 1.35.22;
__inline__ -> inline
 1.34 18-Nov-2005  bouyer Some drives disconnect after the last data phase without a save data pointer
message. In such case we would not update resid with the proper value
(eventually resid would not be updated at all if there was only one data
phase). To fix this, have the script save the offset in the data tables at
disconnect time if there was a transfer, and use this to compute the resid
if the current offset is 0.
Problem reported and patch tested by edwin, Roy Bixler and YAMAMOTO Takashi.
Fix kern/31990 by YAMAMOTO Takashi.
 1.33 23-Mar-2005  bouyer branches: 1.33.2; 1.33.8;
Don't assume all LUNs are probed before scsipi sets the mode, and always check
if lun_tagtbl needs to be allocated. Patch from john heasley in kern/29603.
 1.32 04-Feb-2005  perry branches: 1.32.4;
de-__P
 1.31 20-May-2004  bouyer branches: 1.31.4; 1.31.6;
Rmove a redundant BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE, and fix
another one (POST -> PRE)
 1.30 17-May-2004  bouyer Add support for the Ignore Wide Residue SCSI message.
 1.29 17-May-2004  bouyer when an unexpected disconnect occurs only compute the resid; do the
real save data pointers when we get the message (or rather, at disconnect
time following the message).
Factor out code to do this, and to deal with xs->resid, in siop_common.c.
 1.28 17-May-2004  bouyer Properly compute xs->resid, instead of assuming it'll always be 0 when
a command is done.
 1.27 16-Mar-2004  bouyer branches: 1.27.4;
cbd -> cdb
Command Block Descriptor -> Command Descriptor Block
Pointed out by Allen Briggs.
 1.26 15-Mar-2004  bouyer Extract the code printing the CBD from scsipi_print_sense(), so that it's
usable in other context.
Use the new scsipi_print_cbd() to dump the command in case of timeout
in siop/esiop.
 1.25 10-Mar-2004  bouyer The real value of the message is in msgin, not
esiop_cmd->cmd_tables->msg_in[0], so print the correct value.
 1.24 02-Nov-2003  wiz Fix some typos. From Tom Cosgrove via jmc@openbsd.
 1.23 29-Oct-2003  mycroft XXX: gcc
 1.22 25-Oct-2003  christos Fix uninitialized variable warnings
 1.21 04-Aug-2003  bouyer Remove unused esiop_scsicmd() prototype.
 1.20 03-Jul-2003  drochner Avoid an obscure gcc3 complaint about
"dereferencing type-punned pointer" by a cast to "void *".
I don't completely understand the warning, but it helps.
 1.19 03-May-2003  wiz branches: 1.19.2;
DMA, not dma nor Dma.
 1.18 31-Jan-2003  thorpej Use aprint_*().
 1.17 18-Jul-2002  wiz Spell 'should' correctly.
 1.16 18-May-2002  bouyer branches: 1.16.2; 1.16.4; 1.16.6;
Be more verbose when returning XS_DRIVER_STUFFUP
 1.15 16-May-2002  thorpej Don't access a scsipi channel's periph table directly; use
scsipi_lookup_periph().
 1.14 04-May-2002  bouyer branches: 1.14.2;
More debug printfs.
 1.13 29-Apr-2002  bouyer Add a missing esiop_script_sync(), and debug messages improvements.
 1.12 27-Apr-2002  bouyer Use a u_int32_t in script RAM instead of the SEM bit in ISTAT to pass flags
between script and driver. This allows more than one flag, and is easier to
manage (we almost can't read/write istat outside of the irq handler).
 1.11 27-Apr-2002  bouyer Implement a ring for the completed commands. This avoid a (problematic only
if error occurs after status is collected) race condition
when using the status byte to detect completed commands (a command descriptor
could be recycled before the device disconnected), and make the
interrupt routine handling completed commands more efficient (no need to
scan target * lun * tag array any more).
 1.10 25-Apr-2002  bouyer It's not safe to access the SCNTL1 register while the SCRIPT is running.
On the 1010 this can wedge the chip. So abort the script instead.
the abort interrupt will trigger a bus reset.
 1.9 25-Apr-2002  bouyer - We can't share the per-lun DSA entry for untagged and tag table DSA;
there may be tagged commands still running when we queue a request sense
command.
Solve this by using 2 DSA entry per LUN
- Now that we have the command DSA before select, we can load T/L/Q in
SCRATCHC. This makes the selection timeout handler simpler.
- Avoid a race condition when setting the free flag in the cmd ring (see
comment in the script)
- don't forget to update the ID in the head of LUN table after a sync/wide
negotiation. This fixes the command timeout at the first data command
after negotiation (the bus reset handler did update the ID properly,
so subsequent commands were OK).
- for DMA interrupts, clear fifo if it's not empty. Leaving the fifo dirty
would prevent subsequent interrupts from coming in.
- Various improvements in debug messages
- misc cleanups.
 1.8 24-Apr-2002  bouyer For a new command, use the id in the command table and get rid of the ID in the
scheduler slot. This costs a few more instructions but divide the size of the
scheduler ring by 2, saving 1k of onboard RAM (a bus with 15 devices would
overflow the on-board RAM by 128 bytes).
 1.7 23-Apr-2002  bouyer More copyright fixes, pointed out by Thomas. Thanks !
 1.6 23-Apr-2002  bouyer - factor out parts of (e)siop_attach() to siop_common_attach()
- Add support for DT transfers (aka Ultra/160) in esiop

Note that DT transfers are not enabled for 53c1010-33 rev 0 yet; if I trust
FreeBSD it has a bug which prevent them to do DT properly.
From the same source there may be issues with some revs of 53c1010-66.
 1.5 23-Apr-2002  bouyer Bump the space for SCSI messages from 8 to 16 octets, as 8 may not be
enouth for IDENTIFY + TAG + PPR.
Get rid of constants in C code by use of a offsetof macro.
 1.4 23-Apr-2002  bouyer Enable software LED control based on LED0 feature, not #define.
For now, set the LED0 feature if SIOP_SYMLED is defined in siop_pci_common.c.
From Jason R Thorpe.
 1.3 22-Apr-2002  bouyer Adapt for script "wait MSG_OUT after select" change: now, when we get
selection timeout, SCRATCHE points to the slot which triggered the timeout,
not the next one.
 1.2 22-Apr-2002  bouyer Add support for tagged queuing to esiop (256 tags per device).
For this add another indirecton: the DSA in the LUN table points to
a table of DSA indexed by the tag number when tagged command is in use.
For non tagged command, the LUN DSA still points to the tables describing the
xfer directly.
 1.1 21-Apr-2002  bouyer First cut at a esiop driver (enhanced siop). Doesn't implement tagged queuing
yet.
If is restricted to SIOP which implement the load/store instruction, and
has 10 scratch registers (basically, 825 and newer, possibly 770).
It implements a different interface between host and script, using a real
ring for command starts, and improved support for reconnect which will allow
256 tag per device. It uses interrupt on the fly to signal complete command,
which allows several commands to be serviced per interrupt and doesn't require
the script to stop to signal command completion.
 1.14.2.2 20-Jul-2002  gehenna catch up with -current.
 1.14.2.1 30-May-2002  gehenna Catch up with -current.
 1.16.6.3 06-Sep-2002  jdolecek sync kqueue branch with HEAD
 1.16.6.2 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.16.6.1 18-May-2002  jdolecek file esiop.c was added on branch kqueue on 2002-06-23 17:46:22 +0000
 1.16.4.3 01-Aug-2002  nathanw Catch up to -current.
 1.16.4.2 20-Jun-2002  nathanw Catch up to -current.
 1.16.4.1 18-May-2002  nathanw file esiop.c was added on branch nathanw_sa on 2002-06-20 03:44:33 +0000
 1.16.2.7 14-Dec-2005  jmc Pullup via patch (requested in ticket #5957 by bouyer)
Some drives disconnect after the last data phase without a save data pointer
message. In such case we would not update resid with the proper value
(eventually resid would not be updated at all if there was only one data
phase). To fix this, have the script save the offset in the data tables at
disconnect time if there was a transfer, and use this to compute the resid
if the current offset is 0. PR#31990
 1.16.2.6 01-May-2005  tron Pull up revision 1.33 (requested by bouyer in ticket #5755):
Don't assume all LUNs are probed before scsipi sets the mode, and always check
if lun_tagtbl needs to be allocated. Patch from john heasley in kern/29603.
 1.16.2.5 19-Mar-2005  tron Pull up revision 1.31 (requested by bouyer in ticket #1752):
Rmove a redundant BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE, and fix
another one (POST -> PRE)
 1.16.2.4 19-Mar-2005  tron Pull up revision 1.30 (requested by bouyer in ticket #1751):
Add support for the Ignore Wide Residue SCSI message.
 1.16.2.3 17-Mar-2005  tron Pull up revision 1.29 (requested by bouyer in ticket #1750):
when an unexpected disconnect occurs only compute the resid; do the
real save data pointers when we get the message (or rather, at disconnect
time following the message).
Factor out code to do this, and to deal with xs->resid, in siop_common.c.
 1.16.2.2 17-Mar-2005  tron Pull up revision 1.28 (requested by bouyer in ticket #1749):
Properly compute xs->resid, instead of assuming it'll always be 0 when
a command is done.
 1.16.2.1 28-Mar-2004  jmc Pullup rev 1.25 (requested by bouyer in ticket #1633)

The real value of the message is in msgin, not esiop_cmd->cmd_tables->msg_in[0],
so print the correct value.
 1.19.2.6 11-Dec-2005  christos Sync with head.
 1.19.2.5 01-Apr-2005  skrll Sync with HEAD.
 1.19.2.4 04-Feb-2005  skrll Sync with HEAD.
 1.19.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.19.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.19.2.1 03-Aug-2004  skrll Sync with HEAD
 1.27.4.6 01-Dec-2005  riz Pull up following revision(s) (requested by bouyer in ticket #10168):
sys/dev/ic/siop.c: revision 1.79 via patch
sys/dev/ic/siopvar_common.h: revision 1.33 via patch
sys/dev/ic/esiopvar.h: revision 1.13 via patch
sys/dev/ic/esiop.c: revision 1.34 via patch
sys/dev/microcode/siop/esiop.ss: revision 1.20 via patch
sys/dev/ic/siopvar.h: revision 1.22 via patch
sys/dev/microcode/siop/siop.ss: revision 1.20 via patch
Some drives disconnect after the last data phase without a save data pointer
message. In such case we would not update resid with the proper value
(eventually resid would not be updated at all if there was only one data
phase). To fix this, have the script save the offset in the data tables at
disconnect time if there was a transfer, and use this to compute the resid
if the current offset is 0.
Problem reported and patch tested by edwin, Roy Bixler and YAMAMOTO Takashi.
Fix kern/31990 by YAMAMOTO Takashi.
 1.27.4.5 16-May-2005  riz branches: 1.27.4.5.2;
Pull up revision 1.33 (requested by bouyer in ticket #1514):
Don't assume all LUNs are probed before scsipi sets the mode, and always check
if lun_tagtbl needs to be allocated. Patch from john heasley in kern/29603.
 1.27.4.4 11-May-2005  snj Pull up revision 1.31 (requested by bouyer in ticket #1368):
Rmove a redundant BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE, and fix
another one (POST -> PRE)
 1.27.4.3 11-May-2005  snj Pull up revision 1.30 (requested by bouyer in ticket #1366):
Add support for the Ignore Wide Residue SCSI message.
 1.27.4.2 11-May-2005  snj Pull up revision 1.29 (requested by bouyer in ticket #1365):
when an unexpected disconnect occurs only compute the resid; do the
real save data pointers when we get the message (or rather, at disconnect
time following the message).
Factor out code to do this, and to deal with xs->resid, in siop_common.c.
 1.27.4.1 11-May-2005  snj Pull up revision 1.28 (requested by bouyer in ticket #1364):
Properly compute xs->resid, instead of assuming it'll always be 0 when
a command is done.
 1.27.4.5.2.1 01-Dec-2005  riz Pull up following revision(s) (requested by bouyer in ticket #10168):
sys/dev/ic/siop.c: revision 1.79 via patch
sys/dev/ic/siopvar_common.h: revision 1.33 via patch
sys/dev/ic/esiopvar.h: revision 1.13 via patch
sys/dev/ic/esiop.c: revision 1.34 via patch
sys/dev/microcode/siop/esiop.ss: revision 1.20 via patch
sys/dev/ic/siopvar.h: revision 1.22 via patch
sys/dev/microcode/siop/siop.ss: revision 1.20 via patch
Some drives disconnect after the last data phase without a save data pointer
message. In such case we would not update resid with the proper value
(eventually resid would not be updated at all if there was only one data
phase). To fix this, have the script save the offset in the data tables at
disconnect time if there was a transfer, and use this to compute the resid
if the current offset is 0.
Problem reported and patch tested by edwin, Roy Bixler and YAMAMOTO Takashi.
Fix kern/31990 by YAMAMOTO Takashi.
 1.31.6.2 26-Mar-2005  yamt sync with head.
 1.31.6.1 12-Feb-2005  yamt sync with head.
 1.31.4.1 29-Apr-2005  kent sync with -current
 1.32.4.2 21-Nov-2005  tron Pull up following revision(s) (requested by bouyer in ticket #973):
sys/dev/ic/siop.c: revision 1.79
sys/dev/ic/siopvar_common.h: revision 1.33
sys/dev/ic/esiopvar.h: revision 1.13
sys/dev/ic/esiop.c: revision 1.34
sys/dev/microcode/siop/esiop.ss: revision 1.20
sys/dev/ic/siopvar.h: revision 1.22
sys/dev/microcode/siop/siop.ss: revision 1.20
Some drives disconnect after the last data phase without a save data pointer
message. In such case we would not update resid with the proper value
(eventually resid would not be updated at all if there was only one data
phase). To fix this, have the script save the offset in the data tables at
disconnect time if there was a transfer, and use this to compute the resid
if the current offset is 0.
Problem reported and patch tested by edwin, Roy Bixler and YAMAMOTO Takashi.
Fix kern/31990 by YAMAMOTO Takashi.
 1.32.4.1 21-Apr-2005  tron Pull up revision 1.33 (requested by bouyer in ticket #171):
Don't assume all LUNs are probed before scsipi sets the mode, and always check
if lun_tagtbl needs to be allocated. Patch from john heasley in kern/29603.
 1.33.8.1 22-Nov-2005  yamt sync with head.
 1.33.2.4 27-Oct-2007  yamt sync with head.
 1.33.2.3 03-Sep-2007  yamt sync with head.
 1.33.2.2 30-Dec-2006  yamt sync with head.
 1.33.2.1 21-Jun-2006  yamt sync with head.
 1.35.22.2 10-Dec-2006  yamt sync with head.
 1.35.22.1 22-Oct-2006  yamt sync with head
 1.35.20.1 18-Nov-2006  ad Sync with head.
 1.38.4.1 12-Mar-2007  rmind Sync with HEAD.
 1.39.18.1 06-Oct-2007  yamt sync with head.
 1.39.16.1 06-Nov-2007  matt sync with HEAD
 1.39.14.2 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.39.14.1 02-Oct-2007  joerg Sync with HEAD.
 1.39.2.2 23-Oct-2007  ad Sync with head.
 1.39.2.1 09-Oct-2007  ad Sync with head.
 1.40.2.1 25-Oct-2007  bouyer Sync with HEAD.
 1.41.16.1 02-Jun-2008  mjf Sync with HEAD.
 1.42.18.2 23-Jul-2009  jym Sync with HEAD.
 1.42.18.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.42.14.2 20-Nov-2010  riz Fix patch from ticket 1390; bad merge from -current to netbsd-5.
 1.42.14.1 20-Nov-2010  riz Pull up following revision(s) (requested by mhitch in ticket #1390):
sys/dev/ic/siop.c: revision 1.95
sys/dev/ic/esiop.c: revision 1.52
Improve error paths in (e)siop_scsipi_request():
- When terminating the adapter request after the cmd has been removed
from the free list, put that cmd back on the free list before returing.
- Correctly indicate which bus_dma_load() failed.
Analysis and fix from Michael L. Hitch in PR/42844.
 1.42.12.1 28-Apr-2009  skrll Sync with HEAD.
 1.42.4.6 09-Oct-2010  yamt sync with head
 1.42.4.5 11-Aug-2010  yamt sync with head.
 1.42.4.4 11-Mar-2010  yamt sync with head
 1.42.4.3 16-Sep-2009  yamt sync with head
 1.42.4.2 16-May-2009  yamt sync with head
 1.42.4.1 04-May-2009  yamt sync with head.
 1.49.2.3 22-Oct-2010  uebayasi Sync with HEAD (-D20101022).
 1.49.2.2 17-Aug-2010  uebayasi Sync with HEAD.
 1.49.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.51.2.2 05-Mar-2011  rmind sync with head
 1.51.2.1 30-May-2010  rmind sync with head
 1.55.22.1 18-May-2014  rmind sync with head
 1.55.18.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.55.14.1 17-Nov-2013  bouyer Apply patch, requested by gson in ticket #981:
sys/dev/ic/esiop.c 1.57 via patch
Turn the "siop_intr: I shouldn't be there !" panic message in the
esiop driver into a printf followed by a return from the interrupt
handler. The condition is triggered on some KVM virtual hosts,
apparently harmlessly, and not panicing makes it possible to boot a
NetBSD GENERIC kernel on those hosts. Fixes PR kern/48277.
 1.55.8.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.57.46.1 21-Mar-2021  thorpej Give config_found() the same variadic arguments treatment as
config_search(). This commit only adds the CFARG_EOL sentinel
to the existing config_found() calls. Conversion of config_found_sm_loc()
and config_found_ia() call sites will be in subsequent commits.
 1.58.8.1 04-Aug-2021  thorpej Adapt to CFARGS().
 1.21 24-Aug-2012  msaitoh Fix typos
 1.20 19-Oct-2009  bouyer branches: 1.20.12;
Remove closes 3 & 4 from my licence. Lots of thanks to Soren Jacobsen
for the booring work !
 1.19 04-Sep-2009  tsutsui u_intNN_t -> uintNN_t
 1.18 04-Sep-2009  tsutsui Remove unnecessary whitespace.
 1.17 15-Mar-2009  cegger ansify function definitions
 1.16 25-Dec-2007  perry branches: 1.16.10; 1.16.18; 1.16.24;
Convert many of the uses of __attribute__ to equivalent
__packed, __unused and __dead macros from cdefs.h
 1.15 16-Feb-2006  perry branches: 1.15.40; 1.15.46; 1.15.50; 1.15.54;
Change "inline" back to "__inline" in .h files -- C99 is still too
new, and some apps compile things in C89 mode. C89 keywords stay.

As per core@.
 1.14 24-Dec-2005  perry branches: 1.14.2; 1.14.4; 1.14.6;
__inline__ -> inline
 1.13 18-Nov-2005  bouyer Some drives disconnect after the last data phase without a save data pointer
message. In such case we would not update resid with the proper value
(eventually resid would not be updated at all if there was only one data
phase). To fix this, have the script save the offset in the data tables at
disconnect time if there was a transfer, and use this to compute the resid
if the current offset is 0.
Problem reported and patch tested by edwin, Roy Bixler and YAMAMOTO Takashi.
Fix kern/31990 by YAMAMOTO Takashi.
 1.12 27-Feb-2005  perry branches: 1.12.2; 1.12.4; 1.12.10;
nuke trailing whitespace
 1.11 04-Feb-2005  perry de-__P
 1.10 17-May-2004  bouyer branches: 1.10.4; 1.10.6;
when an unexpected disconnect occurs only compute the resid; do the
real save data pointers when we get the message (or rather, at disconnect
time following the message).
Factor out code to do this, and to deal with xs->resid, in siop_common.c.
 1.9 17-May-2004  bouyer Properly compute xs->resid, instead of assuming it'll always be 0 when
a command is done.
 1.8 02-Nov-2003  wiz branches: 1.8.4;
Fix some typos. From Tom Cosgrove via jmc@openbsd.
 1.7 27-Apr-2002  bouyer branches: 1.7.4; 1.7.6; 1.7.8; 1.7.14;
Use a u_int32_t in script RAM instead of the SEM bit in ISTAT to pass flags
between script and driver. This allows more than one flag, and is easier to
manage (we almost can't read/write istat outside of the irq handler).
 1.6 27-Apr-2002  bouyer Implement a ring for the completed commands. This avoid a (problematic only
if error occurs after status is collected) race condition
when using the status byte to detect completed commands (a command descriptor
could be recycled before the device disconnected), and make the
interrupt routine handling completed commands more efficient (no need to
scan target * lun * tag array any more).
 1.5 25-Apr-2002  bouyer - We can't share the per-lun DSA entry for untagged and tag table DSA;
there may be tagged commands still running when we queue a request sense
command.
Solve this by using 2 DSA entry per LUN
- Now that we have the command DSA before select, we can load T/L/Q in
SCRATCHC. This makes the selection timeout handler simpler.
- Avoid a race condition when setting the free flag in the cmd ring (see
comment in the script)
- don't forget to update the ID in the head of LUN table after a sync/wide
negotiation. This fixes the command timeout at the first data command
after negotiation (the bus reset handler did update the ID properly,
so subsequent commands were OK).
- for DMA interrupts, clear fifo if it's not empty. Leaving the fifo dirty
would prevent subsequent interrupts from coming in.
- Various improvements in debug messages
- misc cleanups.
 1.4 24-Apr-2002  bouyer For a new command, use the id in the command table and get rid of the ID in the
scheduler slot. This costs a few more instructions but divide the size of the
scheduler ring by 2, saving 1k of onboard RAM (a bus with 15 devices would
overflow the on-board RAM by 128 bytes).
 1.3 23-Apr-2002  bouyer More copyright fixes, pointed out by Thomas. Thanks !
 1.2 22-Apr-2002  bouyer Add support for tagged queuing to esiop (256 tags per device).
For this add another indirecton: the DSA in the LUN table points to
a table of DSA indexed by the tag number when tagged command is in use.
For non tagged command, the LUN DSA still points to the tables describing the
xfer directly.
 1.1 21-Apr-2002  bouyer First cut at a esiop driver (enhanced siop). Doesn't implement tagged queuing
yet.
If is restricted to SIOP which implement the load/store instruction, and
has 10 scratch registers (basically, 825 and newer, possibly 770).
It implements a different interface between host and script, using a real
ring for command starts, and improved support for reconnect which will allow
256 tag per device. It uses interrupt on the fly to signal complete command,
which allows several commands to be serviced per interrupt and doesn't require
the script to stop to signal command completion.
 1.7.14.6 11-Dec-2005  christos Sync with head.
 1.7.14.5 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.7.14.4 04-Feb-2005  skrll Sync with HEAD.
 1.7.14.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.7.14.2 18-Sep-2004  skrll Sync with HEAD.
 1.7.14.1 03-Aug-2004  skrll Sync with HEAD
 1.7.8.2 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.7.8.1 27-Apr-2002  jdolecek file esiopvar.h was added on branch kqueue on 2002-06-23 17:46:22 +0000
 1.7.6.2 20-Jun-2002  nathanw Catch up to -current.
 1.7.6.1 27-Apr-2002  nathanw file esiopvar.h was added on branch nathanw_sa on 2002-06-20 03:44:34 +0000
 1.7.4.2 14-Dec-2005  jmc Pullup via patch (requested in ticket #5957 by bouyer)
Some drives disconnect after the last data phase without a save data pointer
message. In such case we would not update resid with the proper value
(eventually resid would not be updated at all if there was only one data
phase). To fix this, have the script save the offset in the data tables at
disconnect time if there was a transfer, and use this to compute the resid
if the current offset is 0. PR#31990
 1.7.4.1 17-Mar-2005  tron Pull up revision 1.9 (requested by bouyer in ticket #1749):
Properly compute xs->resid, instead of assuming it'll always be 0 when
a command is done.
 1.8.4.2 01-Dec-2005  riz Pull up following revision(s) (requested by bouyer in ticket #10168):
sys/dev/ic/siop.c: revision 1.79 via patch
sys/dev/ic/siopvar_common.h: revision 1.33 via patch
sys/dev/ic/esiopvar.h: revision 1.13 via patch
sys/dev/ic/esiop.c: revision 1.34 via patch
sys/dev/microcode/siop/esiop.ss: revision 1.20 via patch
sys/dev/ic/siopvar.h: revision 1.22 via patch
sys/dev/microcode/siop/siop.ss: revision 1.20 via patch
Some drives disconnect after the last data phase without a save data pointer
message. In such case we would not update resid with the proper value
(eventually resid would not be updated at all if there was only one data
phase). To fix this, have the script save the offset in the data tables at
disconnect time if there was a transfer, and use this to compute the resid
if the current offset is 0.
Problem reported and patch tested by edwin, Roy Bixler and YAMAMOTO Takashi.
Fix kern/31990 by YAMAMOTO Takashi.
 1.8.4.1 11-May-2005  snj branches: 1.8.4.1.2;
Pull up revision 1.9 (requested by bouyer in ticket #1364):
Properly compute xs->resid, instead of assuming it'll always be 0 when
a command is done.
 1.8.4.1.2.1 01-Dec-2005  riz Pull up following revision(s) (requested by bouyer in ticket #10168):
sys/dev/ic/siop.c: revision 1.79 via patch
sys/dev/ic/siopvar_common.h: revision 1.33 via patch
sys/dev/ic/esiopvar.h: revision 1.13 via patch
sys/dev/ic/esiop.c: revision 1.34 via patch
sys/dev/microcode/siop/esiop.ss: revision 1.20 via patch
sys/dev/ic/siopvar.h: revision 1.22 via patch
sys/dev/microcode/siop/siop.ss: revision 1.20 via patch
Some drives disconnect after the last data phase without a save data pointer
message. In such case we would not update resid with the proper value
(eventually resid would not be updated at all if there was only one data
phase). To fix this, have the script save the offset in the data tables at
disconnect time if there was a transfer, and use this to compute the resid
if the current offset is 0.
Problem reported and patch tested by edwin, Roy Bixler and YAMAMOTO Takashi.
Fix kern/31990 by YAMAMOTO Takashi.
 1.10.6.2 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.10.6.1 12-Feb-2005  yamt sync with head.
 1.10.4.1 29-Apr-2005  kent sync with -current
 1.12.10.1 22-Nov-2005  yamt sync with head.
 1.12.4.2 21-Jan-2008  yamt sync with head
 1.12.4.1 21-Jun-2006  yamt sync with head.
 1.12.2.1 21-Nov-2005  tron Pull up following revision(s) (requested by bouyer in ticket #973):
sys/dev/ic/siop.c: revision 1.79
sys/dev/ic/siopvar_common.h: revision 1.33
sys/dev/ic/esiopvar.h: revision 1.13
sys/dev/ic/esiop.c: revision 1.34
sys/dev/microcode/siop/esiop.ss: revision 1.20
sys/dev/ic/siopvar.h: revision 1.22
sys/dev/microcode/siop/siop.ss: revision 1.20
Some drives disconnect after the last data phase without a save data pointer
message. In such case we would not update resid with the proper value
(eventually resid would not be updated at all if there was only one data
phase). To fix this, have the script save the offset in the data tables at
disconnect time if there was a transfer, and use this to compute the resid
if the current offset is 0.
Problem reported and patch tested by edwin, Roy Bixler and YAMAMOTO Takashi.
Fix kern/31990 by YAMAMOTO Takashi.
 1.14.6.1 22-Apr-2006  simonb Sync with head.
 1.14.4.1 09-Sep-2006  rpaulo sync with head
 1.14.2.1 18-Feb-2006  yamt sync with head.
 1.15.54.1 02-Jan-2008  bouyer Sync with HEAD
 1.15.50.1 26-Dec-2007  ad Sync with head.
 1.15.46.1 18-Feb-2008  mjf Sync with HEAD.
 1.15.40.1 09-Jan-2008  matt sync with HEAD
 1.16.24.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.16.18.1 28-Apr-2009  skrll Sync with HEAD.
 1.16.10.3 11-Mar-2010  yamt sync with head
 1.16.10.2 16-Sep-2009  yamt sync with head
 1.16.10.1 04-May-2009  yamt sync with head.
 1.20.12.1 30-Oct-2012  yamt sync with head
 1.1 10-Oct-2014  uebayasi branches: 1.1.18;
Move athn definitions.
 1.1.18.2 03-Dec-2017  jdolecek update from HEAD
 1.1.18.1 10-Oct-2014  jdolecek file files.athn was added on branch tls-maxphys on 2017-12-03 11:37:03 +0000
 1.10 12-Apr-2008  tsutsui Split device_t/softc for MI mb86960, with misc cosmetics.
 1.9 08-Apr-2008  cegger use aprint_*_dev and device_xname
 1.8 19-Oct-2007  ad branches: 1.8.16;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.7 11-Dec-2005  christos branches: 1.7.30; 1.7.44; 1.7.46; 1.7.50;
merge ktrace-lwp.
 1.6 27-Feb-2005  perry branches: 1.6.4;
nuke trailing whitespace
 1.5 02-Jan-2005  tsutsui branches: 1.5.2; 1.5.4;
u_intNN_t -> uintNN_t
 1.4 25-Sep-2004  tsutsui Use ANSI function decls.
 1.3 30-Nov-2002  tsutsui branches: 1.3.6;
More cleanup of MI mb86960 driver:
- Add support for byte system bus mode. Based on patch in kern/17193 by
Christian Groessler, with some improvements by me.
- Rename sc_flags in mb86960_softc to sc_stat, rename "type" to sc_flags
to specify controller quirks and remove enum mb86960_type.
- Pass controller type via new sc_flags in mb86960_softc rather than
via an mb86960_attach() arg.
- Handle unaligned mbufs properly in mb86960_write_mbufs(). (from ne2000.c)
- Fix a signed/unsigned comparision warning.
- Add definitions of status bits in the RX packed header.
- Change types of some members in mb86960_softc.
 1.2 05-Oct-2002  tsutsui branches: 1.2.2;
Slightly modify attach messages.
 1.1 05-Oct-2002  tsutsui Overhaul of fmv(4) driver:
- Split if_fmv.c into MI/MD part and add ISA-PnP attachment for FMV-183.
(XXX FMV-184 is not tested. It would require extra media-select functions..)
- Fix probe functions of fmv_isa so that FMV-181A/182A will also match.
Fixes port-i386/9476.
 1.2.2.3 11-Dec-2002  thorpej Sync with HEAD.
 1.2.2.2 18-Oct-2002  nathanw Catch up to -current.
 1.2.2.1 05-Oct-2002  nathanw file fmv.c was added on branch nathanw_sa on 2002-10-18 02:41:50 +0000
 1.3.6.3 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.3.6.2 17-Jan-2005  skrll Sync with HEAD.
 1.3.6.1 19-Oct-2004  skrll Sync with HEAD
 1.5.4.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.5.2.1 29-Apr-2005  kent sync with -current
 1.6.4.1 27-Oct-2007  yamt sync with head.
 1.7.50.1 25-Oct-2007  bouyer Sync with HEAD.
 1.7.46.1 06-Nov-2007  matt sync with HEAD
 1.7.44.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.7.30.1 23-Oct-2007  ad Sync with head.
 1.8.16.1 02-Jun-2008  mjf Sync with HEAD.
 1.2 20-Jul-2024  andvar s/hardwar-cursor/hardware-cursor/, s/hardrare/hardware/ in comments.
 1.1 05-Oct-2002  tsutsui branches: 1.1.2; 1.1.236;
Overhaul of fmv(4) driver:
- Split if_fmv.c into MI/MD part and add ISA-PnP attachment for FMV-183.
(XXX FMV-184 is not tested. It would require extra media-select functions..)
- Fix probe functions of fmv_isa so that FMV-181A/182A will also match.
Fixes port-i386/9476.
 1.1.236.1 02-Aug-2025  perseant Sync with HEAD
 1.1.2.2 18-Oct-2002  nathanw Catch up to -current.
 1.1.2.1 05-Oct-2002  nathanw file fmvreg.h was added on branch nathanw_sa on 2002-10-18 02:41:50 +0000
 1.4 11-Dec-2005  christos merge ktrace-lwp.
 1.3 02-Jan-2005  tsutsui u_intNN_t -> uintNN_t
 1.2 25-Sep-2004  tsutsui Use ANSI function decls.
 1.1 05-Oct-2002  tsutsui branches: 1.1.2; 1.1.8;
Overhaul of fmv(4) driver:
- Split if_fmv.c into MI/MD part and add ISA-PnP attachment for FMV-183.
(XXX FMV-184 is not tested. It would require extra media-select functions..)
- Fix probe functions of fmv_isa so that FMV-181A/182A will also match.
Fixes port-i386/9476.
 1.1.8.2 17-Jan-2005  skrll Sync with HEAD.
 1.1.8.1 19-Oct-2004  skrll Sync with HEAD
 1.1.2.2 18-Oct-2002  nathanw Catch up to -current.
 1.1.2.1 05-Oct-2002  nathanw file fmvvar.h was added on branch nathanw_sa on 2002-10-18 02:41:50 +0000
 1.5 07-Aug-2021  thorpej Merge thorpej-cfargs2.
 1.4 24-Apr-2021  thorpej branches: 1.4.8;
Merge thorpej-cfargs branch:

Simplify and make extensible the config_search() / config_found() /
config_attach() interfaces: rather than having different variants for
which arguments you want pass along, just have a single call that
takes a variadic list of tag-value arguments.

Adjust all call sites:
- Simplify wherever possible; don't pass along arguments that aren't
actually needed.
- Don't be explicit about what interface attribute is attaching if
the device only has one. (More simplification.)
- Add a config_probe() function to be used in indirect configuiration
situations, making is visibly easier to see when indirect config is
in play, and allowing for future change in semantics. (As of now,
this is just a wrapper around config_match(), but that is an
implementation detail.)

Remove unnecessary or redundant interface attributes where they're not
needed.

There are currently 5 "cfargs" defined:
- CFARG_SUBMATCH (submatch function for direct config)
- CFARG_SEARCH (search function for indirect config)
- CFARG_IATTR (interface attribte)
- CFARG_LOCATORS (locators array)
- CFARG_DEVHANDLE (devhandle_t - wraps OFW, ACPI, etc. handles)

...and a sentinel value CFARG_EOL.

Add some extra sanity checking to ensure that interface attributes
aren't ambiguous.

Use CFARG_DEVHANDLE in MI FDT, OFW, and ACPI code, and macppc and shark
ports to associate those device handles with device_t instance. This
will trickle trough to more places over time (need back-end for pre-OFW
Sun OBP; any others?).
 1.3 02-Mar-2012  nonaka branches: 1.3.56;
fix attach message if wdt isn't attach.
 1.2 29-Aug-2011  bouyer branches: 1.2.2; 1.2.6;
Add a flags argument to gcscpcib_attach().
Add a flag argument which cause the waychdog to not be attached.
Use it to disable the watchdog on loongson-based platforms, where
the CS5536's reset output is not wired to the CPU reset line :(
 1.1 27-Aug-2011  bouyer Split gcscpcib into MI part, and MD pci attachement which is also in
charge of attaching the MD pcib device.
Will be used by the upcoming evbmips loongson support.
 1.2.6.3 06-Mar-2012  mrg sync to -current
 1.2.6.2 06-Mar-2012  mrg sync to -current
 1.2.6.1 04-Mar-2012  mrg sync to latest -current.
 1.2.2.1 17-Apr-2012  yamt sync with head
 1.3.56.1 02-Apr-2021  thorpej config_found_ia() -> config_found() w/ CFARG_IATTR.
 1.4.8.1 04-Aug-2021  thorpej Adapt to CFARGS().
 1.1 27-Aug-2011  bouyer Split gcscpcib into MI part, and MD pci attachement which is also in
charge of attaching the MD pcib device.
Will be used by the upcoming evbmips loongson support.
 1.2 29-Aug-2011  bouyer Add a flags argument to gcscpcib_attach().
Add a flag argument which cause the waychdog to not be attached.
Use it to disable the watchdog on loongson-based platforms, where
the CS5536's reset output is not wired to the CPU reset line :(
 1.1 27-Aug-2011  bouyer Split gcscpcib into MI part, and MD pci attachement which is also in
charge of attaching the MD pcib device.
Will be used by the upcoming evbmips loongson support.
 1.139 27-Apr-2025  gson Replace broken link to the GEM Gigabit Ethernet ASIC Specification
with a working archive.org link.
 1.138 05-Jul-2024  rin sys: Drop redundant NULL check before m_freem(9)

m_freem(9) safely has accepted NULL argument at least since 4.2BSD:
https://www.tuhs.org/cgi-bin/utree.pl?file=4.2BSD/usr/src/sys/sys/uipc_mbuf.c

Compile-tested on amd64/ALL.

Suggested by knakahara@
 1.137 29-Jun-2024  riastradh branches: 1.137.2;
if_stats(9): Add ifp argument to if_stat..._ref.

This will enable us to pass the ifp through to a dtrace probe inside.

No functional change intended in this change, but this is an API
change visible to modules so it shouldn't be pulled up.

PR kern/58377
 1.136 10-Feb-2024  andvar s/alloted/allotted/ in comments.
 1.135 25-Sep-2022  thorpej Remove unnecessary include of <sys/malloc.h>.
 1.134 10-Mar-2021  christos remove extra arguments
 1.133 30-Jan-2021  jdc Improve handling of receive overflows. When we get an overflow, don't
reset the chip if we are still receiving packets. Real overflows can
happen when network and CPU(s) are loaded, so the reset is not needed
in this case.
Add a counter to track receive overflows (when GEM_COUNTERS is defined).

This reverts some changes (always reset on overflow) from
PR port-sparc64/46260.
 1.132 15-Sep-2020  mrg branches: 1.132.2;
mii_detach() must come before ifmedia_fini(), otherwise mii_detach()
will have a NULL mutex and fault.

this appears to have been introduced in february, and may be a problem
in other drivers converted to use ifmedia_fini(). i've only fixed the
two that were faulting for me on sunblade 2000 during reboot.
 1.131 15-Jul-2020  msaitoh G.C. comment.
 1.130 15-Mar-2020  thorpej Don't bother with IFF_OACTIVE.
 1.129 01-Mar-2020  thorpej - Support 64-bit DMA addresses for the Tx and Rx ring addresses.
- g/c and unused define.
 1.128 07-Feb-2020  thorpej Use callout_setfunc() / callout_schedule().
 1.127 04-Feb-2020  thorpej Use ifmedia_fini().
 1.126 29-Jan-2020  christos compile without INET
 1.125 29-Jan-2020  thorpej Adopt <net/if_stats.h>.
 1.124 24-Dec-2019  msaitoh branches: 1.124.2;
Fix error path in gem(4)'s TX checksum offload.

- Avoid accessing free'd m0 on error. Use m_freem() instead of m_free().
Reported by maxv@.
- Tested by martin@, macallan@ and jdc@.
 1.123 04-Dec-2019  msaitoh From OpenBSD:
- Fix error message.
- Whitespace fix.
 1.122 04-Dec-2019  msaitoh Rename ifm to ife for struct ifmedia_entry *. No functional change.
 1.121 13-Sep-2019  msaitoh if_flags is neither int nor short. It's unsigned short.
 1.120 28-May-2019  msaitoh branches: 1.120.2;
s/recieve/receive/
 1.119 28-May-2019  msaitoh Use ETHER_LOCK()/ETHER_UNLOCK() for all ethernet drivers to protect ec_multi*.
 1.118 24-May-2019  msaitoh Whilespace fix. No functional change.
 1.117 23-May-2019  msaitoh No functional change:
- Simplify MII structure initialization and reference.
- u_int*_t -> uint*_t.
- KNF
 1.116 11-Apr-2019  msaitoh Fix yet another fiber mediachange fix. Not tested.
- Don't clear bits other than IFM_[FH]DX.
- Always reset PCS when any IFM_[FH]DX bit is changed.
 1.115 09-Apr-2019  msaitoh Fix a bug that media setting for fiber didn't work correctly. Not tested.
The BUGS section in gem(4) manpage says:

> BUGS
(snip)
> On the SX fibre variants of the hardware, the link will stay down if
> there is a duplex mismatch. Also, packet transmission may fail when in
> half-duplex mode.

Is the bug related to this fix?
 1.114 05-Feb-2019  msaitoh Remove very old IFF_NOTRAILERS flag.
 1.113 22-Jan-2019  msaitoh Change MII PHY read/write API from:

int (*mii_readreg_t)(device_t, int, int);
void (*mii_writereg_t)(device_t, int, int, int);
to:

int (*mii_readreg_t)(device_t, int, int, uint16_t *);
int (*mii_writereg_t)(device_t, int, int, uint16_t);

Now we can test if a read/write operation failed or not by the return value.

In 802.3 spec says that the PHY shall not respond to read/write transaction
to the unimplemented register(22.2.4.3). Detecting timeout can be used to
check whether a register is implemented or not (if the register conforms to
the spec). ukphy(4) can be used this for MII_MMDACR and MII_MMDAADR.

Note that I noticed that the following code do infinite loop in the
read/wirte function. If it accesses unimplemented PHY register, it will hang.
It should be fixed:

arm/at91/at91emac.c
arm/ep93xx/epe.c
arm/omap/omapl1x_emac.c
mips/ralink/ralink_eth.c
arch/powerpc/booke/dev/pq3etsec.c(read)
dev/cadence/if_cemac.c <- hkenken
dev/ic/lan9118.c


Tested with the following device:

axe+ukphy
axe+rgephy
axen+rgephy (tested by Andrius V)
wm+atphy
wm+ukphy
wm+igphy
wm+ihphy
wm+makphy
sk+makphy
sk+brgphy
sk+gentbi
msk+makphy
sip+icsphy
sip+ukphy
re+rgephy
bge+brgphy
bnx+brgphy
gsip+gphyter
rtk+rlphy
fxp+inphy (tested by Andrius V)
tlp+acphy
ex+exphy
epic+qsphy
vge+ciphy (tested by Andrius V)
vr+ukphy (tested by Andrius V)
vte+ukphy (tested by Andrius V)

Not tested (MAC):
arm:at91emac
arm:cemac
arm:epe
arm:geminigmac
arm:enet
arm:cpsw
arm:emac(omac)
arm:emac(sunxi)
arm:npe
evbppc:temac
macppc:bm
macppc:gm
mips:aumac
mips:ae
mips:cnmac
mips:reth
mips:sbmac
playstation2:smap
powerpc:tsec
powerpc:emac(ibm4xx)
sgimips:mec
sparc:be
sf
ne(ax88190, dl10019)
awge
ep
gem
hme
smsh
mtd
sm
age
alc
ale
bce
cas
et
jme
lii
nfe
pcn
ste
stge
tl
xi
aue
mue
smsc
udav
url

Not tested (PHY):
amhphy
bmtphy
dmphy
etphy
glxtphy
ikphy
iophy
lxtphy
nsphyter
pnaphy
rdcphy
sqphy
tlphy
tqphy
urlphy
 1.112 09-Jan-2019  msaitoh No functional change.
- u_int{16,32}_t -> uint{16,32}_t
- KNF.
 1.111 03-Sep-2018  riastradh Rename min/max -> uimin/uimax for better honesty.

These functions are defined on unsigned int. The generic name
min/max should not silently truncate to 32 bits on 64-bit systems.
This is purely a name change -- no functional change intended.

HOWEVER! Some subsystems have

#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))

even though our standard name for that is MIN/MAX. Although these
may invite multiple evaluation bugs, these do _not_ cause integer
truncation.

To avoid `fixing' these cases, I first changed the name in libkern,
and then compile-tested every file where min/max occurred in order to
confirm that it failed -- and thus confirm that nothing shadowed
min/max -- before changing it.

I have left a handful of bootloaders that are too annoying to
compile-test, and some dead code:

cobalt ews4800mips hp300 hppa ia64 luna68k vax
acorn32/if_ie.c (not included in any kernels)
macppc/if_gm.c (superseded by gem(4))

It should be easy to fix the fallout once identified -- this way of
doing things fails safe, and the goal here, after all, is to _avoid_
silent integer truncations, not introduce them.

Maybe one day we can reintroduce min/max as type-generic things that
never silently truncate. But we should avoid doing that for a while,
so that existing code has a chance to be detected by the compiler for
conversion to uimin/uimax without changing the semantics until we can
properly audit it all. (Who knows, maybe in some cases integer
truncation is actually intended!)
 1.110 26-Jun-2018  msaitoh branches: 1.110.2;
Implement the BPF direction filter (BIOC[GS]DIRECTION). It provides backward
compatibility with BIOC[GS]SEESENT ioctl. The userland interface is the same
as FreeBSD.

This change also fixes a bug that the direction is misunderstand on some
environment by passing the direction to bpf_mtap*() instead of checking
m->m_pkthdr.rcvif.
 1.109 28-Feb-2018  macallan branches: 1.109.2;
add workaround for PHY detection on Apple K2 GMAC
adapted from openbsd
 1.108 20-Feb-2017  ozaki-r Apply deferred if_start to more drivers
 1.107 15-Dec-2016  ozaki-r branches: 1.107.2;
Move bpf_mtap and if_ipackets++ on Rx of each driver to percpuq if_input

The benefits of the change are:
- We can reduce codes
- We can provide the same behavior between drivers
- Where/When if_ipackets is counted up
- Note that some drivers still update packet statistics in their own
way (periodical update)
- Moved bpf_mtap run in softint
- This makes it easy to MP-ify bpf

Proposed on tech-kern and tech-net
 1.106 10-Jun-2016  ozaki-r branches: 1.106.2;
Introduce m_set_rcvif and m_reset_rcvif

The API is used to set (or reset) a received interface of a mbuf.
They are counterpart of m_get_rcvif, which will come in another
commit, hide internal of rcvif operation, and reduce the diff of
the upcoming change.

No functional change.
 1.105 17-May-2016  jdc PR kern/46083

Track the start of each packet, so that we set the "Start of Frame" bit in
all the relevant transmit descriptors when enqueing multiple packets.

Patch from Valery Ushakov, slightly modified by me to handle debug output.

Tested on macppc/6.x and sparc64/7.99.x.
 1.104 09-Feb-2016  ozaki-r Introduce softint-based if_input

This change intends to run the whole network stack in softint context
(or normal LWP), not hardware interrupt context. Note that the work is
still incomplete by this change; to that end, we also have to softint-ify
if_link_state_change (and bpf) which can still run in hardware interrupt.

This change softint-ifies at ifp->if_input that is called from
each device driver (and ieee80211_input) to ensure Layer 2 runs
in softint (e.g., ether_input and bridge_input). To this end,
we provide a framework (called percpuq) that utlizes softint(9)
and percpu ifqueues. With this patch, rxintr of most drivers just
queues received packets and schedules a softint, and the softint
dequeues packets and does rest packet processing.

To minimize changes to each driver, percpuq is allocated in struct
ifnet for now and that is initialized by default (in if_attach).
We probably have to move percpuq to softc of each driver, but it's
future work. At this point, only wm(4) has percpuq in its softc
as a reference implementation.

Additional information including performance numbers can be found
in the thread at tech-kern@ and tech-net@:
http://mail-index.netbsd.org/tech-kern/2016/01/14/msg019997.html

Acknowledgment: riastradh@ greatly helped this work.
Thank you very much!
 1.103 30-Aug-2015  dholland Restore interrupts on error path. From maxv's brainy list.
 1.102 10-Aug-2014  tls branches: 1.102.2; 1.102.4; 1.102.6;
Merge tls-earlyentropy branch into HEAD.
 1.101 04-Feb-2013  jdc branches: 1.101.10;
Halt the RX watchdog callout when stopping.
 1.100 22-Jul-2012  matt branches: 1.100.2;
Fix mii_statchg to take a 'struct ifnet *' instead of device_t. This fixes
problem with a common MDIO bus used for multiple interfaces.
Some drivers converted to CFATTACL_DECL_NEW.
 1.99 02-Jul-2012  jdc Apply lockup fixes from Havard Eidnes/OpenBSD in PR port-sparc64/46260:
- add an additional watchdog for RX overflow
- re-initialise the chip on device timeout
Also alter the interrupt blanking rate to 8 packets, as per OpenSolaris.
 1.98 02-Feb-2012  tls branches: 1.98.2;
Entropy-pool implementation move and cleanup.

1) Move core entropy-pool code and source/sink/sample management code
to sys/kern from sys/dev.

2) Remove use of NRND as test for presence of entropy-pool code throughout
source tree.

3) Remove use of RND_ENABLED in device drivers as microoptimization to
avoid expensive operations on disabled entropy sources; make the
rnd_add calls do this directly so all callers benefit.

4) Fix bug in recent rnd_add_data()/rnd_add_uint32() changes that might
have lead to slight entropy overestimation for some sources.

5) Add new source types for environmental sensors, power sensors, VM
system events, and skew between clocks, with a sample implementation
for each.

ok releng to go in before the branch due to the difficulty of later
pullup (widespread #ifdef removal and moved files). Tested with release
builds on amd64 and evbarm and live testing on amd64.
 1.97 22-May-2011  jdc branches: 1.97.4; 1.97.8;
Fix corrupted packet problem on 100Mb/s half duplex links.
We need to set "echo disable" on the internal phy too, not just on the
external phy.
Tested on:
SUNW,Sun-Blade-2000
gem0 at pci0 dev 5 function 1: Sun Microsystems ERI Ethernet (rev. 0x01)
ukphy0 at gem0 phy 1: OUI 0x0006b8, model 0x000c, rev. 1

Setting pointed out by bad@.
 1.96 13-Nov-2010  uebayasi branches: 1.96.2;
Don't pull in the whole uvm(9) API to access only PAGE_SIZE and
some other constants. These are provided by sys/param.h now.
 1.95 12-May-2010  martin Use callout_halt() instead of callout_stop() - otherwise gem_detach() might
be too fast and run callout_destroy() while another cpu is still busy
in the callout.
 1.94 05-Apr-2010  joerg Push the bpf_ops usage back into bpf.h. Push the common ifp->if_bpf
check into the inline functions as well the fourth argument for
bpf_attach.
 1.93 24-Feb-2010  dyoung branches: 1.93.2;
A pointer typedef entails trading too much flexibility to declare const
and non-const types, and the kernel uses both const and non-const
PMF qualifiers and device suspensors, so change the pmf_qual_t and
device_suspensor_t typedefs from "pointers to const" to non-pointer,
non-const types.
 1.92 19-Jan-2010  pooka branches: 1.92.2;
Redefine bpf linkage through an always present op vector, i.e.
#if NBPFILTER is no longer required in the client. This change
doesn't yet add support for loading bpf as a module, since drivers
can register before bpf is attached. However, callers of bpf can
now be modularized.

Dynamically loadable bpf could probably be done fairly easily with
coordination from the stub driver and the real driver by registering
attachments in the stub before the real driver is loaded and doing
a handoff. ... and I'm not going to ponder the depths of unload
here.

Tested with i386/MONOLITHIC, modified MONOLITHIC without bpf and rump.
 1.91 11-Jan-2010  jdc Mask out (disable) gem interrupts on detach.
 1.90 08-Jan-2010  dyoung Expand PMF_FN_* macros.
 1.89 05-Dec-2009  jdc Really prefer the external over the internal PHY by checking only that
PHY address first. Avoid problem with bogus ukphy's attaching on the
internal PHY of the SB1000.

Also, take some quirks for internal, external or either MII PHY from
the OpenBSD driver.
 1.88 04-Dec-2009  martin Properly detach phys
 1.87 04-Dec-2009  jdc Only set 0x4FF in the transmit register for gigabit variants. Set 0x100
otherwise.
 1.86 04-Dec-2009  martin Fix a few nits in gem_detach:
Shuffle some bus_dmamem_ operations around, so they actually clean up
in the correct order.
Do not destroy a callout that might be stopped by if_detach later.
When detaching child devices fails, we have passed the point of no return
already, so complete our own cleanup and return the error in the end.
This happens for example when we have been unable to accomodate all phy
devices at attach time (and this is a separate bug).
 1.85 27-Jul-2009  dyoung Do a complete device_t/softc split for the PCI attachment. I have
not finished the device_t/softc split for the SBus attachment
because I don't have an SBus gem(4) to test with.

Convert from legacy shutdownhooks to a PMF shutdown hook. Add PMF
suspend/resume handlers.

Factor a detachment hook out of gem_attach(). During device
attachment, track which resources are reserved in sc_attach_state,
and release only those resources during detachment.

Tested on gem0 and gem1 at pci1 on a Sun Fire V120.
 1.84 12-May-2009  cegger struct device * -> device_t, no functional changes intended.
 1.83 16-Mar-2009  tsutsui Fix a bug in calculation of checksum deduction:
- To get 16 bit one's complement value from uint32_t variable,
higher 16 bits should be ignored.
- RFC 1624 describes methods to recalculate checksum field in headers,
i.e. one's complement of one's complement sum that could be 0x0000,
but we don't have to use the strategy to deduct one's complement sum
itself which won't be zero but should be 0xffff.

Found on debugging mec(4) on sgimips O2.
 1.82 14-Mar-2009  dsl ANSIfy another 1261 function definitions.
The only ones left in sys are beyond by sed script!
(or in sys/dist or sys/external)
Mostly they have function pointer parameters.
 1.81 14-Mar-2009  dsl Change about 4500 of the K&R function definitions to ANSI ones.
There are still about 1600 left, but they have ',' or /* ... */
in the actual variable definitions - which my awk script doesn't handle.
There are also many that need () -> (void).
(The script does handle misordered arguments.)
 1.80 16-Dec-2008  christos branches: 1.80.2;
replace bitmask_snprintf(9) with snprintb(3)
 1.79 07-Nov-2008  dyoung *** Summary ***

When a link-layer address changes (e.g., ifconfig ex0 link
02:de:ad:be:ef:02 active), send a gratuitous ARP and/or a Neighbor
Advertisement to update the network-/link-layer address bindings
on our LAN peers.

Refuse a change of ethernet address to the address 00:00:00:00:00:00
or to any multicast/broadcast address. (Thanks matt@.)

Reorder ifnet ioctl operations so that driver ioctls may inherit
the functions of their "class"---ether_ioctl(), fddi_ioctl(), et
cetera---and the class ioctls may inherit from the generic ioctl,
ifioctl_common(), but both driver- and class-ioctls may override
the generic behavior. Make network drivers share more code.

Distinguish a "factory" link-layer address from others for the
purposes of both protecting that address from deletion and computing
EUI64.

Return consistent, appropriate error codes from network drivers.

Improve readability. KNF.

*** Details ***

In if_attach(), always initialize the interface ioctl routine,
ifnet->if_ioctl, if the driver has not already initialized it.
Delete if_ioctl == NULL tests everywhere else, because it cannot
happen.

In the ioctl routines of network interfaces, inherit common ioctl
behaviors by calling either ifioctl_common() or whichever ioctl
routine is appropriate for the class of interface---e.g., ether_ioctl()
for ethernets.

Stop (ab)using SIOCSIFADDR and start to use SIOCINITIFADDR. In
the user->kernel interface, SIOCSIFADDR's argument was an ifreq,
but on the protocol->ifnet interface, SIOCSIFADDR's argument was
an ifaddr. That was confusing, and it would work against me as I
make it possible for a network interface to overload most ioctls.
On the protocol->ifnet interface, replace SIOCSIFADDR with
SIOCINITIFADDR. In ifioctl(), return EPERM if userland tries to
invoke SIOCINITIFADDR.

In ifioctl(), give the interface the first shot at handling most
interface ioctls, and give the protocol the second shot, instead
of the other way around. Finally, let compatibility code (COMPAT_OSOCK)
take a shot.

Pull device initialization out of switch statements under
SIOCINITIFADDR. For example, pull ..._init() out of any switch
statement that looks like this:

switch (...->sa_family) {
case ...:
..._init();
...
break;
...
default:
..._init();
...
break;
}

Rewrite many if-else clauses that handle all permutations of IFF_UP
and IFF_RUNNING to use a switch statement,

switch (x & (IFF_UP|IFF_RUNNING)) {
case 0:
...
break;
case IFF_RUNNING:
...
break;
case IFF_UP:
...
break;
case IFF_UP|IFF_RUNNING:
...
break;
}

unifdef lots of code containing #ifdef FreeBSD, #ifdef NetBSD, and
#ifdef SIOCSIFMTU, especially in fwip(4) and in ndis(4).

In ipw(4), remove an if_set_sadl() call that is out of place.

In nfe(4), reuse the jumbo MTU logic in ether_ioctl().

Let ethernets register a callback for setting h/w state such as
promiscuous mode and the multicast filter in accord with a change
in the if_flags: ether_set_ifflags_cb() registers a callback that
returns ENETRESET if the caller should reset the ethernet by calling
if_init(), 0 on success, != 0 on failure. Pull common code from
ex(4), gem(4), nfe(4), sip(4), tlp(4), vge(4) into ether_ioctl(),
and register if_flags callbacks for those drivers.

Return ENOTTY instead of EINVAL for inappropriate ioctls. In
zyd(4), use ENXIO instead of ENOTTY to indicate that the device is
not any longer attached.

Add to if_set_sadl() a boolean 'factory' argument that indicates
whether a link-layer address was assigned by the factory or some
other source. In a comment, recommend using the factory address
for generating an EUI64, and update in6_get_hw_ifid() to prefer a
factory address to any other link-layer address.

Add a routing message, RTM_LLINFO_UPD, that tells protocols to
update the binding of network-layer addresses to link-layer addresses.
Implement this message in IPv4 and IPv6 by sending a gratuitous
ARP or a neighbor advertisement, respectively. Generate RTM_LLINFO_UPD
messages on a change of an interface's link-layer address.

In ether_ioctl(), do not let SIOCALIFADDR set a link-layer address
that is broadcast/multicast or equal to 00:00:00:00:00:00.

Make ether_ioctl() call ifioctl_common() to handle ioctls that it
does not understand.

In gif(4), initialize if_softc and use it, instead of assuming that
the gif_softc and ifp overlap.

Let ifioctl_common() handle SIOCGIFADDR.

Sprinkle rtcache_invariants(), which checks on DIAGNOSTIC kernels
that certain invariants on a struct route are satisfied.

In agr(4), rewrite agr_ioctl_filter() to be a bit more explicit
about the ioctls that we do not allow on an agr(4) member interface.

bzero -> memset. Delete unnecessary casts to void *. Use
sockaddr_in_init() and sockaddr_in6_init(). Compare pointers with
NULL instead of "testing truth". Replace some instances of (type
*)0 with NULL. Change some K&R prototypes to ANSI C, and join
lines.
 1.78 15-Sep-2008  jdc branches: 1.78.2; 1.78.4; 1.78.6; 1.78.8;
Read the correct error status register on SBus cards.
Don't set infinite burst on SBus cards.
Changes based on information in the `Sbus GEM Specification':
http://mediacast.sun.com/users/Barton808/media/gem_sbus-1.pdf

SBus-based GEM cards (i.e. Sun X1140A) now work!
Tested with a X1140A card in a U1 and in a U2.
Thanks for martin@ for testing.
 1.77 04-May-2008  xtraeme branches: 1.77.2; 1.77.6;
mii_dev is a device_t now.
 1.76 08-Apr-2008  cegger branches: 1.76.2; 1.76.4;
use aprint_*_dev and device_xname
 1.75 11-Mar-2008  dyoung Prepare for PMF self-suspension: in the if_stop() methods, clear
IFF_UP and IFF_RUNNING before running the 'disable' step, instead
of after. Soon I will handle the 'disable' step by calling into
PMF, which may call if_stop(, 0). Ordinarily, that is harmless.
This change lets the if_stop() routines exit early when they find
on entry that IFF_RUNNING is not set.
 1.74 07-Feb-2008  dyoung branches: 1.74.2; 1.74.6;
Start patching up the kernel so that a network driver always has
the opportunity to handle an ioctl before generic ifioctl handling
occurs. This will ease extending the kernel and sharing of code
between drivers.

First steps: Make the signature of ifioctl_common() match struct
ifinet->if_ioctl. Convert SIOCSIFCAP and SIOCSIFMTU to the new
ifioctl() regime, throughout the kernel.
 1.73 01-Feb-2008  jdc Disable HW RX TCP4 checksums because it is buggy (it appears to only checksum
src IP, dst IP and packet len).

Also, remove the "MAC rx fault" redundant printf().
 1.72 22-Jan-2008  jdc Set the correct offset when using VLAN's.
 1.71 22-Jan-2008  jdc Also count excess or late collisions as output errors in gem_tint().
Count receive errors (as input errors) in gem_rint().
 1.70 20-Jan-2008  jdc Fix Apple gigabit gem interfaces by restoring some of the code from r1.67,
with some minor alterations to make Sun fibre cards work too.
Tested by aymeric@ and macallan@.
Fixes PR kern/37809.
 1.69 19-Jan-2008  dyoung Make many ethernet drivers share the common code for MII media
handling, ether_mediastatus() and ether_mediachange(). Check for
a non-ENXIO error return from mii_mediachg(). (ENXIO indicates
that a PHY is suspended.)

This patch shrinks the source code size by 979 lines. There was
a 5100-byte savings on the NetBSD/i386 kernel configuration, ALL.

I have made a few miscellaneous changes, too:

gem(4): use LIST_EMPTY(), LIST_FOREACH().
mtd(4): handle media ioctls, for a change!
axe(4): do not track link status in sc->axe_link any longer
nfe(4), aue(4), axe(4), udav(4), url(4): do not reset all PHYs
on a change of media

Except for the change to mtd(4), no functional changes are intended.

XXX This patch affects more architectures than I can feasibly
XXX compile and run. I have compiled macppc, sparc64, i386. I
XXX have run the patches on i386 boxen with bnx(4) and sip(4).
XXX Compiling and running on evbmips (MERAKI, ADM5120) is in
XXX progress.
 1.68 05-Jan-2008  jdc Add support for Sun PCI X1141A (SX fibre) cards, based on the GEM
documentation, experimentation and a previous patch from John Heasley.

Add improvements to the driver based on the GEM documentation and
from FreeBSD if_gem.c (rev 1.45).
 1.67 31-Dec-2007  dyoung Extract common debugging code from gem_tint() and gem_start(),
creating gem_txsoft_print().
 1.66 31-Dec-2007  dyoung In gem_tint(), synchronize the correct descriptors for a Tx packet:
synchronize the N descriptors starting with the packet's first
descriptor, not with its last. This ought to help the defined(GEM_DEBUG)
&& IFF_DEBUG case.
 1.65 31-Dec-2007  dyoung gem_start() pads a Tx packet to the minimum ethernet frame length
by adding a segment to the Tx chain. That entails using one more
descriptor. It did not synchronize the last descriptor.

In gem_start(), clarify and repair DMA synchronization of the Tx
descriptors. Sync them all.
 1.64 31-Dec-2007  dyoung gem_start() assigned last_txs, but never used it otherwise, so
remove it.
 1.63 31-Dec-2007  dyoung Cosmetic: remove superfluous parentheses, shorten staircase.
 1.62 31-Dec-2007  dyoung Re-order operations to ensure that if defined(GEM_DEBUG) && IFF_DEBUG,
gem_tint() prints a coherent set of descriptors that the NIC has
finished processing. See comments for more information. Compile-tested
on sparc64 and on macppc.
 1.61 29-Dec-2007  tsutsui Fix typo in comments.
 1.60 19-Oct-2007  ad branches: 1.60.2; 1.60.8;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.59 29-Sep-2007  scw branches: 1.59.2;
s/NPBFILTER/NBPFILTER/ in some #endif comments. No functional change.
 1.58 26-Aug-2007  dyoung branches: 1.58.2; 1.58.4;
Constify: LLADDR -> CLLADDR. I'm aiming here to make it easier to
identify sockaddr_dl abuse that remains in the kernel, especially
the potential for overwriting memory past the end of a sockaddr_dl
with, e.g., memcpy(LLADDR(), ...).
 1.57 09-Jul-2007  ad branches: 1.57.2; 1.57.6;
Merge some of the less invasive changes from the vmlocking branch:

- kthread, callout, devsw API changes
- select()/poll() improvements
- miscellaneous MT safety improvements
 1.56 12-Apr-2007  dyoung Make the members of the descriptors volatile, because the NIC and
the host share them.

Before breaking out of the loop over descriptors in gem_rint(),
DMA-resynchronize the first Rx descriptor we found that does not
belong to the host. We must avoid a cached descriptor "covering"
a descriptor in RAM, because the cached descriptor may say that
the descriptor still belongs to the NIC, when that is not true,
and the driver will hang.

XXX I believe this driver only works by luck on hosts that both
XXX have a cacheline size greater than the size of a descriptor
XXX (16 bytes) and lack DMA/cache coherency. I need to add some
XXX trickery to make sure that we don't scribble over the NIC's
XXX changes to a descriptor when we flush a cached descriptor to
XXX RAM with bus_dmamap_sync(9).
 1.55 12-Apr-2007  dyoung Use PRIx64 and PRIx32 format strings. Remark about lack of DMA
synchronization at some debug code that reads descriptors.
 1.54 04-Mar-2007  christos branches: 1.54.2; 1.54.4;
fix fallout from caddr_t changes.
 1.53 04-Mar-2007  christos Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.52 24-Nov-2006  christos branches: 1.52.2; 1.52.4; 1.52.8;
fix spelling of accommodate; from Zapher.
 1.51 24-Nov-2006  martin Ooops - make it compile again.
 1.50 24-Nov-2006  martin In preparation for gem @ sbus: split the GEM registers into two halfs
and provide a bus_space_handle_t for each. While there, fix a typo
in gem_bitwait().
 1.49 23-Nov-2006  martin Fix an obvious copy&pasto and make it compile with GEM_DEBUG.
 1.48 24-Sep-2006  jmcneill Add "name" parameter to powerhook_establish, to aid debugging. No objections
on tech-kern@
 1.47 05-Aug-2006  sanjayl branches: 1.47.4; 1.47.6;
1st cut of Powermac G5 support (uses bridge mode).
 1.46 26-May-2006  blymn Clean up bogus whitespace
 1.45 02-Jan-2006  heas branches: 1.45.2; 1.45.4; 1.45.6; 1.45.12;
Contribute to the rnd entropy pool (already attached as a source).
 1.44 11-Dec-2005  christos branches: 1.44.2;
merge ktrace-lwp.
 1.43 28-Oct-2005  christos - delete ugly debugging crap.
- remove bogus multicast handling [pointed out by thorpej]
and don't reset the chip on ENETRESET; ENETRESET is a sign
that only the multicast filter needs changing.
 1.42 28-Oct-2005  christos According to thorpej, we don't need to stop when we attach. But then again
we don't detach yet...
 1.41 28-Oct-2005  christos From FreeBSD:
- make a few functions static
- introduce gem_bitwait() to factor out some of the register wait code.
- add gem_stop() in attach
- some DEBUG should be GEM_DEBUG
- handle underrun, packet too long, and overflow errors by resetting the chip
- add handler in ioctl for add/del multi
- fix typo
Also:
- add a shadow sc_if_flags member so that we don't reset the chip if we
don't need to.
 1.40 16-May-2005  bouyer branches: 1.40.2; 1.40.4;
Pad small packets with a static buffer at the end of the S/G list.
Avoids leaking kernel memory when small packets are transmitted.
Tested on a ibook G4.
 1.39 02-May-2005  yamt split IFCAP_CSUM_xxx to IFCAP_CSUM_xxx_Rx and IFCAP_CSUM_xxx_Tx.
 1.38 05-Mar-2005  heas branches: 1.38.2;
Perform a s/w checksum for packets that are not the same length as the length
field of the IP header (ip->ip-len) indicates they should be. This handles
the case where an ethernet frame has been padded to meet the minimum ethernet
frame length or erroneously (my cisco switch unnecessarily adds 4 bytes to its
SYN). This padding will be included in the hardware checksum and may be
non-zero, thus making it incorrect.
 1.37 27-Feb-2005  perry nuke trailing whitespace
 1.36 21-Feb-2005  thorpej Define M_CSUM_DATA_IPv4_IPHL() and M_CSUM_DATA_IPv4_OFFSET() macros
to extract data from csum_data, rather than just open-coding it.
 1.35 20-Feb-2005  heas Have the MAC strip the ethernet FCS on rx so it is not included in the hardware
checksum and add code to support IPv4 TCP/UDP hardware checksums.
 1.34 04-Feb-2005  perry de-__P
 1.33 31-Jan-2005  thorpej Eliminate use of M_HASFCS.
 1.32 30-Oct-2004  thorpej branches: 1.32.4; 1.32.6;
When adding/deleting multicast addresses, only whack the address
filter if the interface is marked RUNNING.

Fixes kern/27678.
 1.31 17-Oct-2004  heas Adjust/add a few comments and add defines for PCS (aka GEM_MII) FSM and
interrupt registers.
drop some trailing WS.

no functional changes.
 1.30 26-Oct-2003  christos branches: 1.30.4;
Another possibly uninitialized lasttx
 1.29 26-Oct-2003  christos Don't return random garbage in the default case; return the smallest ring
descriptor instead.
 1.28 24-Aug-2003  chs make this build with GEM_DEBUG. fix rxhist counters.
 1.27 03-May-2003  wiz branches: 1.27.2;
DMA, not dma nor Dma.
 1.26 26-Feb-2003  matt Add MBUFTRACE kernel option.
Do a little mbuf rework while here. Change all uses of MGET*(*, M_WAIT, *)
to m_get*(M_WAIT, *). These are not performance critical and making them
call m_get saves considerable space. Add m_clget analogue of MCLGET and
make corresponding change for M_WAIT uses.
Modify netinet, gem, fxp, tulip, nfs to support MBUFTRACE.
Begin to change netstat to use sysctl.
 1.25 20-Feb-2003  matt Add a MIIF_FORCEANEG flag to be passed to mii_attach. This forces an
autonegotiation to take place if IFM_AUTO is selected in mii_media_set.
Make the gem driver use it. (XXX hme probably should use it but I can't
test that).
 1.24 31-Jan-2003  thorpej Use aprint_*().
 1.23 22-Oct-2002  fair Change the "dontcare bits" argument to ifmedia_init() to IFM_IMASK
so that it is possible select PHY instances other than the first
one (instance zero), if there is more than one PHY attached.
 1.22 28-Aug-2002  matt From OpenBSD:
- Fix one typo (instead of two disable_rx, one disable_rx and one disable_tx)
[The other bug fix isn't appropriate since the was OACTIVE is dealt with
has been changed in NetBSD.]
 1.21 01-Jun-2002  lukem SIMPLEQ rototill:
- implement SIMPLEQ_REMOVE(head, elm, type, field). whilst it's O(n),
this mirrors the functionality of SLIST_REMOVE() (the other
singly-linked list type) and FreeBSD's STAILQ_REMOVE()
- remove the unnecessary elm arg from SIMPLEQ_REMOVE_HEAD().
this mirrors the functionality of SLIST_REMOVE_HEAD() (the other
singly-linked list type) and FreeBSD's STAILQ_REMOVE_HEAD()
- remove notes about SIMPLEQ not supporting arbitrary element removal
- use SIMPLEQ_FOREACH() instead of home-grown for loops
- use SIMPLEQ_EMPTY() appropriately
- use SIMPLEQ_*() instead of accessing sqh_first,sqh_last,sqe_next directly
- reorder manual page; be consistent about how the types are listed
- other minor cleanups
 1.20 15-May-2002  matt branches: 1.20.2;
Let's put a s = splnet(); to match the splx(s); already in the routine.
(yes, we were doing an splx with an uninitialized variable).
 1.19 15-May-2002  matt Only enable detailed evcnts if GEM_COUNTERS is defined. But always count
interrupts.
 1.18 15-May-2002  matt Add evcnt stuff for interrupts.
Fix receiver lockups. When writing the RX Kick register, we need back up
on descriptor since we advanced one in the for loop. That will be the
last descriptor we haven't processed which is what we should write.
 1.17 14-May-2002  matt Fix initialization of GEM_RX_MAC_INTR. 1 means mask.
 1.16 11-May-2002  matt Supress RX_MAC interrupts regarding the FRAME_COUNT register.
 1.15 11-May-2002  matt Many fixes. Multicast hash filter works now. Autonegotiation with GigE
on Mac G4's now works. XXX Checksum offload still needs to be done.
 1.14 08-May-2002  matt If the detected media is gigabit, change the gem to use GMII mode otherwise
switch back to MII mode. Keep a sliding window for TX segments and when it
gets > 2/3 full, request a TX interrupt (window gets reset when the h/w TX
queue is empty). Add dv_xname to a few printfs. With the above changes,
the gem driver will now work on Macintoshes, even in GigE mode. On a 733
PowerMac G4 it gets ~355Mb/s TX and ~280Mb/s RX to/from an Alpha XP1000.

XXX mii autoselect is still flakey.
 1.13 29-Mar-2002  matt Correct a comment and cleanup slightly how the local ethernet is programmed
into the chip.
 1.12 19-Jan-2002  eeh Remove some obsolete code.
 1.11 17-Nov-2001  thorpej branches: 1.11.2;
Back out the last two changes I made to this driver -- some people
have reported lossage.
 1.10 13-Nov-2001  lukem add/cleanup RCSID
 1.9 21-Oct-2001  thorpej Reserve one descriptor at the end of the ring as a termination point,
to prevent the producer index from getting confused.
 1.8 20-Oct-2001  thorpej gem_init(): Don't call gem_mii_statchg() directly. Instead, call
gem_mediachange(). This will cause gem_mii_statchg() to be called
by the MII layer with the correct MII media state, so that speed
duplex parameters will be set properly.
 1.7 18-Oct-2001  thorpej Yet more cruft removal.
 1.6 18-Oct-2001  thorpej Remove more cruft left over from copying bits of other drivers.
 1.5 18-Oct-2001  thorpej Remove some more stuff left over from copying bits of the HME driver.
 1.4 18-Oct-2001  thorpej Manipulate the Tx desc pointer as 2 32-bit values, just as
we do with the Rx desc pointer, both for consistency, and
for platforms which don't have bus_space_*_8().
 1.3 01-Oct-2001  eeh Remove some debug messages.
 1.2 01-Oct-2001  eeh Increase receive ring to 128 entries and handle both endian devices.
 1.1 16-Sep-2001  eeh branches: 1.1.2; 1.1.4;
Driver for Sun GEM gigabit ethernet, Sun ERI 10/100, and Apple GMAC.
 1.1.4.3 11-Oct-2001  fvdl Catch up with -current. Fix some bogons in the sparc64 kbd/ms
attach code. cd18xx conversion provided by mrg.
 1.1.4.2 01-Oct-2001  fvdl Catch up with -current.
 1.1.4.1 16-Sep-2001  fvdl file gem.c was added on branch thorpej-devvp on 2001-10-01 12:45:35 +0000
 1.1.2.11 11-Nov-2002  nathanw Catch up to -current
 1.1.2.10 17-Sep-2002  nathanw Catch up to -current.
 1.1.2.9 20-Jun-2002  nathanw Catch up to -current.
 1.1.2.8 17-Apr-2002  nathanw Catch up to -current.
 1.1.2.7 28-Feb-2002  nathanw Catch up to -current.
 1.1.2.6 08-Jan-2002  nathanw Catch up to -current.
 1.1.2.5 14-Nov-2001  nathanw Catch up to -current.
 1.1.2.4 22-Oct-2001  nathanw Catch up to -current.
 1.1.2.3 08-Oct-2001  nathanw Catch up to -current.
 1.1.2.2 21-Sep-2001  nathanw Catch up to -current.
 1.1.2.1 16-Sep-2001  nathanw file gem.c was added on branch nathanw_sa on 2001-09-21 22:35:37 +0000
 1.11.2.5 06-Sep-2002  jdolecek sync kqueue branch with HEAD
 1.11.2.4 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.11.2.3 11-Feb-2002  jdolecek Sync w/ -current.
 1.11.2.2 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.11.2.1 17-Nov-2001  thorpej file gem.c was added on branch kqueue on 2002-01-10 19:54:29 +0000
 1.20.2.2 31-Aug-2002  gehenna catch up with -current.
 1.20.2.1 20-Jun-2002  gehenna catch up with -current.
 1.27.2.9 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.27.2.8 08-Mar-2005  skrll Sync with HEAD.
 1.27.2.7 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.27.2.6 04-Feb-2005  skrll Sync with HEAD.
 1.27.2.5 02-Nov-2004  skrll Sync with HEAD.
 1.27.2.4 19-Oct-2004  skrll Sync with HEAD
 1.27.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.27.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.27.2.1 03-Aug-2004  skrll Sync with HEAD
 1.30.4.2 21-Jun-2005  riz Pull up revision 1.40 (requested by bouyer in ticket #2006):
Pad small packets with a static buffer at the end of the S/G list.
Avoids leaking kernel memory when small packets are transmitted.
Tested on a ibook G4.
 1.30.4.1 24-Jan-2005  he Pull up revision 1.32 (requested by thorpej in ticket #939):
When adding or deleting multicast addresses, only change
the address filter if the interface is marked RUNNING.
Fixes PR#27678.
 1.32.6.2 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.32.6.1 12-Feb-2005  yamt sync with head.
 1.32.4.1 29-Apr-2005  kent sync with -current
 1.38.2.1 21-Jun-2005  tron Pull up revision 1.40 (requested by bouyer in ticket #484):
Pad small packets with a static buffer at the end of the S/G list.
Avoids leaking kernel memory when small packets are transmitted.
Tested on a ibook G4.
 1.40.4.1 02-Nov-2005  yamt sync with head.
 1.40.2.8 17-Mar-2008  yamt sync with head.
 1.40.2.7 11-Feb-2008  yamt sync with head.
 1.40.2.6 04-Feb-2008  yamt sync with head.
 1.40.2.5 21-Jan-2008  yamt sync with head
 1.40.2.4 27-Oct-2007  yamt sync with head.
 1.40.2.3 03-Sep-2007  yamt sync with head.
 1.40.2.2 30-Dec-2006  yamt sync with head.
 1.40.2.1 21-Jun-2006  yamt sync with head.
 1.44.2.1 15-Jan-2006  yamt sync with head.
 1.45.12.1 19-Jun-2006  chap Sync with head.
 1.45.6.2 11-Aug-2006  yamt sync with head
 1.45.6.1 26-Jun-2006  yamt sync with head.
 1.45.4.1 01-Jun-2006  kardel Sync with head.
 1.45.2.1 09-Sep-2006  rpaulo sync with head
 1.47.6.2 10-Dec-2006  yamt sync with head.
 1.47.6.1 22-Oct-2006  yamt sync with head
 1.47.4.2 12-Jan-2007  ad Sync with head.
 1.47.4.1 18-Nov-2006  ad Sync with head.
 1.52.8.1 03-Jun-2008  skrll Sync with netbsd-4.
 1.52.4.2 15-Apr-2007  yamt sync with head.
 1.52.4.1 12-Mar-2007  rmind Sync with HEAD.
 1.52.2.1 17-May-2008  bouyer Pull up following revision(s) (requested by jdc in ticket #1145):
src/share/man/man4/gem.4 1.5,1.6 via patch
src/sys/arch/sparc64/conf/GENERIC 1.97 via patch
src/sys/dev/ic/gem.c 1.59,1.61-1.68,1.70-1.73 via patch
src/sys/dev/ic/gemreg.h 1.11 via patch
src/sys/dev/ic/gemvar.h 1.16,1.18 via patch
src/sys/dev/mii/bmtphy.c 1.24 via patch
src/sys/dev/pci/if_gem_pci.c 1.25,1.27 via patch
src/sys/dev/pci/pcidevs 1.12 via patch
src/sys/dev/pci/pcidevs.h regenerate
src/sys/dev/pci/pcidevs_data.h regenerate
Add support for Sun PCI X1141A (SX fibre) cards.
Add improvements to the driver.
Disable HW UDP4 and RX TCP4 checksums because they are buggy (PR#34799)
Add improvements to bmtphy.
 1.54.4.1 11-Jul-2007  mjf Sync with head.
 1.54.2.4 23-Oct-2007  ad Sync with head.
 1.54.2.3 09-Oct-2007  ad Sync with head.
 1.54.2.2 01-Jul-2007  ad Adapt to callout API change.
 1.54.2.1 27-May-2007  ad Sync with head.
 1.57.6.3 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.57.6.2 02-Oct-2007  joerg Sync with HEAD.
 1.57.6.1 03-Sep-2007  jmcneill Sync with HEAD.
 1.57.2.1 03-Sep-2007  skrll Sync with HEAD.
 1.58.4.1 06-Oct-2007  yamt sync with head.
 1.58.2.3 23-Mar-2008  matt sync with HEAD
 1.58.2.2 09-Jan-2008  matt sync with HEAD
 1.58.2.1 06-Nov-2007  matt sync with HEAD
 1.59.2.1 25-Oct-2007  bouyer Sync with HEAD.
 1.60.8.4 23-Jan-2008  bouyer Sync with HEAD.
 1.60.8.3 20-Jan-2008  bouyer Sync with HEAD
 1.60.8.2 08-Jan-2008  bouyer Sync with HEAD
 1.60.8.1 02-Jan-2008  bouyer Sync with HEAD
 1.60.2.1 18-Feb-2008  mjf Sync with HEAD.
 1.74.6.4 17-Jan-2009  mjf Sync with HEAD.
 1.74.6.3 28-Sep-2008  mjf Sync with HEAD.
 1.74.6.2 02-Jun-2008  mjf Sync with HEAD.
 1.74.6.1 03-Apr-2008  mjf Sync with HEAD.
 1.74.2.1 24-Mar-2008  keiichi sync with head.
 1.76.4.6 11-Aug-2010  yamt sync with head.
 1.76.4.5 11-Mar-2010  yamt sync with head
 1.76.4.4 19-Aug-2009  yamt sync with head.
 1.76.4.3 16-May-2009  yamt sync with head
 1.76.4.2 04-May-2009  yamt sync with head.
 1.76.4.1 16-May-2008  yamt sync with head.
 1.76.2.1 18-May-2008  yamt sync with head.
 1.77.6.2 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.77.6.1 19-Oct-2008  haad Sync with HEAD.
 1.77.2.1 24-Sep-2008  wrstuden Merge in changes between wrstuden-revivesa-base-2 and
wrstuden-revivesa-base-3.
 1.78.8.1 21-Apr-2010  matt sync to netbsd-5
 1.78.6.1 18-Jun-2011  bouyer Pull up following revision(s) (requested by jdc in ticket #1632):
sys/dev/ic/gem.c: revision 1.97
Fix corrupted packet problem on 100Mb/s half duplex links.
We need to set "echo disable" on the internal phy too, not just on the
external phy.
Tested on:
SUNW,Sun-Blade-2000
gem0 at pci0 dev 5 function 1: Sun Microsystems ERI Ethernet (rev. 0x01)
ukphy0 at gem0 phy 1: OUI 0x0006b8, model 0x000c, rev. 1
Setting pointed out by bad@.
 1.78.4.3 15-Sep-2012  bouyer Pull up following revision(s) (requested by jdc in ticket #1789):
sys/dev/ic/gem.c: revision 1.99 via patch
sys/dev/ic/gemvar.h: revision 1.24 via patch
sys/dev/ic/gemreg.h: revision 1.15 via patch
Apply lockup fixes from Havard Eidnes/OpenBSD in PR port-sparc64/46260:
- add an additional watchdog for RX overflow
- re-initialise the chip on device timeout
Also alter the interrupt blanking rate to 8 packets, as per OpenSolaris.
 1.78.4.2 18-Jun-2011  bouyer Pull up following revision(s) (requested by jdc in ticket #1632):
sys/dev/ic/gem.c: revision 1.97
Fix corrupted packet problem on 100Mb/s half duplex links.
We need to set "echo disable" on the internal phy too, not just on the
external phy.
Tested on:
SUNW,Sun-Blade-2000
gem0 at pci0 dev 5 function 1: Sun Microsystems ERI Ethernet (rev. 0x01)
ukphy0 at gem0 phy 1: OUI 0x0006b8, model 0x000c, rev. 1
Setting pointed out by bad@.
 1.78.4.1 01-May-2009  snj branches: 1.78.4.1.2;
Pull up following revision(s) (requested by tsutsui in ticket #595):
sys/dev/ic/gem.c: revision 1.83
sys/dev/ic/hme.c: revision 1.73
Fix a bug in calculation of checksum deduction:
- To get 16 bit one's complement value from uint32_t variable,
higher 16 bits should be ignored.
- RFC 1624 describes methods to recalculate checksum field in headers,
i.e. one's complement of one's complement sum that could be 0x0000,
but we don't have to use the strategy to deduct one's complement sum
itself which won't be zero but should be 0xffff.
Found on debugging mec(4) on sgimips O2.
 1.78.4.1.2.1 18-Jun-2011  bouyer Pull up following revision(s) (requested by jdc in ticket #1632):
sys/dev/ic/gem.c: revision 1.97
Fix corrupted packet problem on 100Mb/s half duplex links.
We need to set "echo disable" on the internal phy too, not just on the
external phy.
Tested on:
SUNW,Sun-Blade-2000
gem0 at pci0 dev 5 function 1: Sun Microsystems ERI Ethernet (rev. 0x01)
ukphy0 at gem0 phy 1: OUI 0x0006b8, model 0x000c, rev. 1
Setting pointed out by bad@.
 1.78.2.2 28-Apr-2009  skrll Sync with HEAD.
 1.78.2.1 19-Jan-2009  skrll Sync with HEAD.
 1.80.2.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.92.2.2 17-Aug-2010  uebayasi Sync with HEAD.
 1.92.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.93.2.3 31-May-2011  rmind sync with head
 1.93.2.2 05-Mar-2011  rmind sync with head
 1.93.2.1 30-May-2010  rmind sync with head
 1.96.2.1 06-Jun-2011  jruoho Sync with HEAD.
 1.97.8.1 18-Feb-2012  mrg merge to -current.
 1.97.4.3 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.97.4.2 30-Oct-2012  yamt sync with head
 1.97.4.1 17-Apr-2012  yamt sync with head
 1.98.2.2 27-Aug-2016  bouyer Pull up following revision(s) (requested by jdc in ticket #1384):
sys/dev/ic/gem.c: revision 1.105
PR kern/46083
Track the start of each packet, so that we set the "Start of Frame" bit in
all the relevant transmit descriptors when enqueing multiple packets.
Patch from Valery Ushakov, slightly modified by me to handle debug output.
Tested on macppc/6.x and sparc64/7.99.x.
 1.98.2.1 05-Jul-2012  riz Pull up following revision(s) (requested by jdc in ticket #401):
sys/dev/ic/gem.c: revision 1.99
sys/dev/ic/gemvar.h: revision 1.24
sys/dev/ic/gemreg.h: revision 1.15
Apply lockup fixes from Havard Eidnes/OpenBSD in PR port-sparc64/46260:
- add an additional watchdog for RX overflow
- re-initialise the chip on device timeout
Also alter the interrupt blanking rate to 8 packets, as per OpenSolaris.
 1.100.2.3 03-Dec-2017  jdolecek update from HEAD
 1.100.2.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.100.2.1 25-Feb-2013  tls resync with head
 1.101.10.1 07-Apr-2014  tls Be a little more clear and consistent about harvesting entropy from devices:

1) deprecate RND_FLAG_NO_ESTIMATE

2) define RND_FLAG_COLLECT_TIME, RND_FLAG_COLLECT_VALUE

3) define RND_FLAG_ESTIMATE_TIME, RND_FLAG_ESTIMATE_VALUE

4) define RND_FLAG_DEFAULT: RND_FLAG_COLLECT_TIME|
RND_FLAG_COLLECT_VALUE|RND_FLAG_ESTIMATE_TIME

5) Make entropy harvesting from environmental sensors a little more generic
and remove it from individual sensor drivers.

6) Remove individual open-coded delta-estimators for values from a few
places in the tree (uvm, environmental drivers).

7) 0 -> RND_FLAG_DEFAULT, actually gather entropy from various drivers
that had stubbed out code, other minor cleanups.
 1.102.6.1 22-May-2016  martin Pull up following revision(s) (requested by jdc in ticket #1170):
sys/dev/ic/gem.c: revision 1.105
PR kern/46083
Track the start of each packet, so that we set the "Start of Frame" bit in
all the relevant transmit descriptors when enqueing multiple packets.
Patch from Valery Ushakov, slightly modified by me to handle debug output.
Tested on macppc/6.x and sparc64/7.99.x.
 1.102.4.6 28-Aug-2017  skrll Sync with HEAD
 1.102.4.5 05-Feb-2017  skrll Sync with HEAD
 1.102.4.4 09-Jul-2016  skrll Sync with HEAD
 1.102.4.3 29-May-2016  skrll Sync with HEAD
 1.102.4.2 19-Mar-2016  skrll Sync with HEAD
 1.102.4.1 22-Sep-2015  skrll Sync with HEAD
 1.102.2.1 22-May-2016  martin Pull up following revision(s) (requested by jdc in ticket #1170):
sys/dev/ic/gem.c: revision 1.105
PR kern/46083
Track the start of each packet, so that we set the "Start of Frame" bit in
all the relevant transmit descriptors when enqueing multiple packets.
Patch from Valery Ushakov, slightly modified by me to handle debug output.
Tested on macppc/6.x and sparc64/7.99.x.
 1.106.2.2 20-Mar-2017  pgoyette Sync with HEAD
 1.106.2.1 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.107.2.1 21-Apr-2017  bouyer Sync with HEAD
 1.109.2.4 26-Jan-2019  pgoyette Sync with HEAD
 1.109.2.3 18-Jan-2019  pgoyette Synch with HEAD
 1.109.2.2 06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.109.2.1 28-Jul-2018  pgoyette Sync with HEAD
 1.110.2.3 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.110.2.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.110.2.1 10-Jun-2019  christos Sync with HEAD
 1.120.2.1 08-Jan-2020  martin Pull up following revision(s) (requested by msaitoh in ticket #610):

sys/dev/ic/gem.c: revision 1.124

Fix error path in gem(4)'s TX checksum offload.

- Avoid accessing free'd m0 on error. Use m_freem() instead of m_free().
Reported by maxv@.
- Tested by martin@, macallan@ and jdc@.
 1.124.2.1 29-Feb-2020  ad Sync with head.
 1.132.2.1 03-Apr-2021  thorpej Sync with HEAD.
 1.137.2.1 02-Aug-2025  perseant Sync with HEAD
 1.16 17-Aug-2021  andvar fix multiplei repetitive typos in comments, messages and documentation. mainly because copy paste code big amount of files are affected.
 1.15 02-Jul-2012  jdc Apply lockup fixes from Havard Eidnes/OpenBSD in PR port-sparc64/46260:
- add an additional watchdog for RX overflow
- re-initialise the chip on device timeout
Also alter the interrupt blanking rate to 8 packets, as per OpenSolaris.
 1.14 15-Sep-2008  jdc branches: 1.14.4; 1.14.28; 1.14.34;
Minor corrections to the SBus definitions, from the `Sbus GEM Specification':
http://mediacast.sun.com/users/Barton808/media/gem_sbus-1.pdf
 1.13 07-May-2008  jdc branches: 1.13.2; 1.13.6;
Correct Sbus register definitions.
 1.12 06-May-2008  jdc Add some Sbus-specific definitions (more registers and more values in the
Sbus Config register).
 1.11 05-Jan-2008  jdc branches: 1.11.6; 1.11.8; 1.11.10;
Add support for Sun PCI X1141A (SX fibre) cards, based on the GEM
documentation, experimentation and a previous patch from John Heasley.

Add improvements to the driver based on the GEM documentation and
from FreeBSD if_gem.c (rev 1.45).
 1.10 12-Apr-2007  dyoung branches: 1.10.8; 1.10.14; 1.10.20;
Make the members of the descriptors volatile, because the NIC and
the host share them.

Before breaking out of the loop over descriptors in gem_rint(),
DMA-resynchronize the first Rx descriptor we found that does not
belong to the host. We must avoid a cached descriptor "covering"
a descriptor in RAM, because the cached descriptor may say that
the descriptor still belongs to the NIC, when that is not true,
and the driver will hang.

XXX I believe this driver only works by luck on hosts that both
XXX have a cacheline size greater than the size of a descriptor
XXX (16 bytes) and lack DMA/cache coherency. I need to add some
XXX trickery to make sure that we don't scribble over the NIC's
XXX changes to a descriptor when we flush a cached descriptor to
XXX RAM with bus_dmamap_sync(9).
 1.9 24-Nov-2006  martin branches: 1.9.2; 1.9.4; 1.9.8; 1.9.10; 1.9.16;
In preparation for gem @ sbus: split the GEM registers into two halfs
and provide a bus_space_handle_t for each. While there, fix a typo
in gem_bitwait().
 1.8 11-Dec-2005  christos branches: 1.8.20; 1.8.22;
merge ktrace-lwp.
 1.7 18-Feb-2005  heas branches: 1.7.6;
Adjust/add a few comments, add a few bitmask_snprintf formats, and add
register definitions for hardware checksums and the PCS (the fiber interface
version of a MII).
 1.6 17-Oct-2004  heas branches: 1.6.4; 1.6.6;
Adjust/add a few comments and add defines for PCS (aka GEM_MII) FSM and
interrupt registers.
drop some trailing WS.

no functional changes.
 1.5 02-Nov-2003  wiz Fix some typos. From Tom Cosgrove via jmc@openbsd.
 1.4 11-May-2002  matt branches: 1.4.10;
Many fixes. Multicast hash filter works now. Autonegotiation with GigE
on Mac G4's now works. XXX Checksum offload still needs to be done.
 1.3 08-May-2002  matt If the detected media is gigabit, change the gem to use GMII mode otherwise
switch back to MII mode. Keep a sliding window for TX segments and when it
gets > 2/3 full, request a TX interrupt (window gets reset when the h/w TX
queue is empty). Add dv_xname to a few printfs. With the above changes,
the gem driver will now work on Macintoshes, even in GigE mode. On a 733
PowerMac G4 it gets ~355Mb/s TX and ~280Mb/s RX to/from an Alpha XP1000.

XXX mii autoselect is still flakey.
 1.2 18-Oct-2001  thorpej branches: 1.2.4;
Manipulate the Tx desc pointer as 2 32-bit values, just as
we do with the Rx desc pointer, both for consistency, and
for platforms which don't have bus_space_*_8().
 1.1 16-Sep-2001  eeh branches: 1.1.2; 1.1.4;
Driver for Sun GEM gigabit ethernet, Sun ERI 10/100, and Apple GMAC.
 1.1.4.2 01-Oct-2001  fvdl Catch up with -current.
 1.1.4.1 16-Sep-2001  fvdl file gemreg.h was added on branch thorpej-devvp on 2001-10-01 12:45:35 +0000
 1.1.2.4 20-Jun-2002  nathanw Catch up to -current.
 1.1.2.3 22-Oct-2001  nathanw Catch up to -current.
 1.1.2.2 21-Sep-2001  nathanw Catch up to -current.
 1.1.2.1 16-Sep-2001  nathanw file gemreg.h was added on branch nathanw_sa on 2001-09-21 22:35:37 +0000
 1.2.4.3 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.2.4.2 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.2.4.1 18-Oct-2001  thorpej file gemreg.h was added on branch kqueue on 2002-01-10 19:54:29 +0000
 1.4.10.5 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.4.10.4 19-Oct-2004  skrll Sync with HEAD
 1.4.10.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.4.10.2 18-Sep-2004  skrll Sync with HEAD.
 1.4.10.1 03-Aug-2004  skrll Sync with HEAD
 1.6.6.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.6.4.1 29-Apr-2005  kent sync with -current
 1.7.6.3 21-Jan-2008  yamt sync with head
 1.7.6.2 03-Sep-2007  yamt sync with head.
 1.7.6.1 30-Dec-2006  yamt sync with head.
 1.8.22.1 10-Dec-2006  yamt sync with head.
 1.8.20.1 12-Jan-2007  ad Sync with head.
 1.9.16.1 03-Jun-2008  skrll Sync with netbsd-4.
 1.9.10.1 11-Jul-2007  mjf Sync with head.
 1.9.8.1 27-May-2007  ad Sync with head.
 1.9.4.1 15-Apr-2007  yamt sync with head.
 1.9.2.1 17-May-2008  bouyer Pull up following revision(s) (requested by jdc in ticket #1145):
src/share/man/man4/gem.4 1.5,1.6 via patch
src/sys/arch/sparc64/conf/GENERIC 1.97 via patch
src/sys/dev/ic/gem.c 1.59,1.61-1.68,1.70-1.73 via patch
src/sys/dev/ic/gemreg.h 1.11 via patch
src/sys/dev/ic/gemvar.h 1.16,1.18 via patch
src/sys/dev/mii/bmtphy.c 1.24 via patch
src/sys/dev/pci/if_gem_pci.c 1.25,1.27 via patch
src/sys/dev/pci/pcidevs 1.12 via patch
src/sys/dev/pci/pcidevs.h regenerate
src/sys/dev/pci/pcidevs_data.h regenerate
Add support for Sun PCI X1141A (SX fibre) cards.
Add improvements to the driver.
Disable HW UDP4 and RX TCP4 checksums because they are buggy (PR#34799)
Add improvements to bmtphy.
 1.10.20.1 08-Jan-2008  bouyer Sync with HEAD
 1.10.14.1 18-Feb-2008  mjf Sync with HEAD.
 1.10.8.1 09-Jan-2008  matt sync with HEAD
 1.11.10.2 04-May-2009  yamt sync with head.
 1.11.10.1 16-May-2008  yamt sync with head.
 1.11.8.1 18-May-2008  yamt sync with head.
 1.11.6.2 28-Sep-2008  mjf Sync with HEAD.
 1.11.6.1 02-Jun-2008  mjf Sync with HEAD.
 1.13.6.1 19-Oct-2008  haad Sync with HEAD.
 1.13.2.1 24-Sep-2008  wrstuden Merge in changes between wrstuden-revivesa-base-2 and
wrstuden-revivesa-base-3.
 1.14.34.1 05-Jul-2012  riz Pull up following revision(s) (requested by jdc in ticket #401):
sys/dev/ic/gem.c: revision 1.99
sys/dev/ic/gemvar.h: revision 1.24
sys/dev/ic/gemreg.h: revision 1.15
Apply lockup fixes from Havard Eidnes/OpenBSD in PR port-sparc64/46260:
- add an additional watchdog for RX overflow
- re-initialise the chip on device timeout
Also alter the interrupt blanking rate to 8 packets, as per OpenSolaris.
 1.14.28.1 30-Oct-2012  yamt sync with head
 1.14.4.1 15-Sep-2012  bouyer Pull up following revision(s) (requested by jdc in ticket #1789):
sys/dev/ic/gem.c: revision 1.99 via patch
sys/dev/ic/gemvar.h: revision 1.24 via patch
sys/dev/ic/gemreg.h: revision 1.15 via patch
Apply lockup fixes from Havard Eidnes/OpenBSD in PR port-sparc64/46260:
- add an additional watchdog for RX overflow
- re-initialise the chip on device timeout
Also alter the interrupt blanking rate to 8 packets, as per OpenSolaris.
 1.28 30-Jan-2021  jdc Improve handling of receive overflows. When we get an overflow, don't
reset the chip if we are still receiving packets. Real overflows can
happen when network and CPU(s) are loaded, so the reset is not needed
in this case.
Add a counter to track receive overflows (when GEM_COUNTERS is defined).

This reverts some changes (always reset on overflow) from
PR port-sparc64/46260.
 1.27 01-Mar-2020  thorpej branches: 1.27.6;
- Support 64-bit DMA addresses for the Tx and Rx ring addresses.
- g/c and unused define.
 1.26 13-Sep-2019  msaitoh if_flags is neither int nor short. It's unsigned short.
 1.25 13-Apr-2015  riastradh branches: 1.25.18;
Convert sys/dev to use <sys/rndsource.h>.
 1.24 02-Jul-2012  jdc branches: 1.24.2; 1.24.16;
Apply lockup fixes from Havard Eidnes/OpenBSD in PR port-sparc64/46260:
- add an additional watchdog for RX overflow
- re-initialise the chip on device timeout
Also alter the interrupt blanking rate to 8 packets, as per OpenSolaris.
 1.23 02-Feb-2012  tls branches: 1.23.2;
Entropy-pool implementation move and cleanup.

1) Move core entropy-pool code and source/sink/sample management code
to sys/kern from sys/dev.

2) Remove use of NRND as test for presence of entropy-pool code throughout
source tree.

3) Remove use of RND_ENABLED in device drivers as microoptimization to
avoid expensive operations on disabled entropy sources; make the
rnd_add calls do this directly so all callers benefit.

4) Fix bug in recent rnd_add_data()/rnd_add_uint32() changes that might
have lead to slight entropy overestimation for some sources.

5) Add new source types for environmental sensors, power sensors, VM
system events, and skew between clocks, with a sample implementation
for each.

ok releng to go in before the branch due to the difficulty of later
pullup (widespread #ifdef removal and moved files). Tested with release
builds on amd64 and evbarm and live testing on amd64.
 1.22 19-Nov-2011  tls branches: 1.22.2;
First step of random number subsystem rework described in
<20111022023242.BA26F14A158@mail.netbsd.org>. This change includes
the following:

An initial cleanup and minor reorganization of the entropy pool
code in sys/dev/rnd.c and sys/dev/rndpool.c. Several bugs are
fixed. Some effort is made to accumulate entropy more quickly at
boot time.

A generic interface, "rndsink", is added, for stream generators to
request that they be re-keyed with good quality entropy from the pool
as soon as it is available.

The arc4random()/arc4randbytes() implementation in libkern is
adjusted to use the rndsink interface for rekeying, which helps
address the problem of low-quality keys at boot time.

An implementation of the FIPS 140-2 statistical tests for random
number generator quality is provided (libkern/rngtest.c). This
is based on Greg Rose's implementation from Qualcomm.

A new random stream generator, nist_ctr_drbg, is provided. It is
based on an implementation of the NIST SP800-90 CTR_DRBG by
Henric Jungheim. This generator users AES in a modified counter
mode to generate a backtracking-resistant random stream.

An abstraction layer, "cprng", is provided for in-kernel consumers
of randomness. The arc4random/arc4randbytes API is deprecated for
in-kernel use. It is replaced by "cprng_strong". The current
cprng_fast implementation wraps the existing arc4random
implementation. The current cprng_strong implementation wraps the
new CTR_DRBG implementation. Both interfaces are rekeyed from
the entropy pool automatically at intervals justifiable from best
current cryptographic practice.

In some quick tests, cprng_fast() is about the same speed as
the old arc4randbytes(), and cprng_strong() is about 20% faster
than rnd_extract_data(). Performance is expected to improve.

The AES code in src/crypto/rijndael is no longer an optional
kernel component, as it is required by cprng_strong, which is
not an optional kernel component.

The entropy pool output is subjected to the rngtest tests at
startup time; if it fails, the system will reboot. There is
approximately a 3/10000 chance of a false positive from these
tests. Entropy pool _input_ from hardware random numbers is
subjected to the rngtest tests at attach time, as well as the
FIPS continuous-output test, to detect bad or stuck hardware
RNGs; if any are detected, they are detached, but the system
continues to run.

A problem with rndctl(8) is fixed -- datastructures with
pointers in arrays are no longer passed to userspace (this
was not a security problem, but rather a major issue for
compat32). A new kernel will require a new rndctl.

The sysctl kern.arandom() and kern.urandom() nodes are hooked
up to the new generators, but the /dev/*random pseudodevices
are not, yet.

Manual pages for the new kernel interfaces are forthcoming.
 1.21 24-Feb-2010  dyoung branches: 1.21.10;
A pointer typedef entails trading too much flexibility to declare const
and non-const types, and the kernel uses both const and non-const
PMF qualifiers and device suspensors, so change the pmf_qual_t and
device_suspensor_t typedefs from "pointers to const" to non-pointer,
non-const types.
 1.20 08-Jan-2010  dyoung branches: 1.20.2;
Expand PMF_FN_* macros.
 1.19 27-Jul-2009  dyoung Do a complete device_t/softc split for the PCI attachment. I have
not finished the device_t/softc split for the SBus attachment
because I don't have an SBus gem(4) to test with.

Convert from legacy shutdownhooks to a PMF shutdown hook. Add PMF
suspend/resume handlers.

Factor a detachment hook out of gem_attach(). During device
attachment, track which resources are reserved in sc_attach_state,
and release only those resources during detachment.

Tested on gem0 and gem1 at pci1 on a Sun Fire V120.
 1.18 01-Feb-2008  jdc branches: 1.18.10; 1.18.20;
Add GEM_IS_SUN macro, and chip revision to the softc.
 1.17 19-Jan-2008  dyoung Remove unused sc_media #define.
 1.16 05-Jan-2008  jdc Add support for Sun PCI X1141A (SX fibre) cards, based on the GEM
documentation, experimentation and a previous patch from John Heasley.

Add improvements to the driver based on the GEM documentation and
from FreeBSD if_gem.c (rev 1.45).
 1.15 24-Nov-2006  martin branches: 1.15.2; 1.15.16; 1.15.24; 1.15.30; 1.15.38;
In preparation for gem @ sbus: split the GEM registers into two halfs
and provide a bus_space_handle_t for each. While there, fix a typo
in gem_bitwait().
 1.14 11-Dec-2005  christos branches: 1.14.20; 1.14.22;
merge ktrace-lwp.
 1.13 28-Oct-2005  christos forgot to commit this.
 1.12 16-May-2005  bouyer branches: 1.12.2; 1.12.4;
Pad small packets with a static buffer at the end of the S/G list.
Avoids leaking kernel memory when small packets are transmitted.
Tested on a ibook G4.
 1.11 04-Feb-2005  perry branches: 1.11.4;
de-__P
 1.10 17-Oct-2004  heas branches: 1.10.4; 1.10.6;
Adjust/add a few comments and add defines for PCS (aka GEM_MII) FSM and
interrupt registers.
drop some trailing WS.

no functional changes.
 1.9 15-May-2002  matt branches: 1.9.10; 1.9.14;
Only enable detailed evcnts if GEM_COUNTERS is defined. But always count
interrupts.
 1.8 15-May-2002  matt Add evcnt stuff for interrupts.
Fix receiver lockups. When writing the RX Kick register, we need back up
on descriptor since we advanced one in the for loop. That will be the
last descriptor we haven't processed which is what we should write.
 1.7 11-May-2002  matt Many fixes. Multicast hash filter works now. Autonegotiation with GigE
on Mac G4's now works. XXX Checksum offload still needs to be done.
 1.6 08-May-2002  matt If the detected media is gigabit, change the gem to use GMII mode otherwise
switch back to MII mode. Keep a sliding window for TX segments and when it
gets > 2/3 full, request a TX interrupt (window gets reset when the h/w TX
queue is empty). Add dv_xname to a few printfs. With the above changes,
the gem driver will now work on Macintoshes, even in GigE mode. On a 733
PowerMac G4 it gets ~355Mb/s TX and ~280Mb/s RX to/from an Alpha XP1000.

XXX mii autoselect is still flakey.
 1.5 18-Oct-2001  thorpej branches: 1.5.4;
Yet more cruft removal.
 1.4 18-Oct-2001  thorpej Remove more cruft left over from copying bits of other drivers.
 1.3 18-Oct-2001  thorpej Remove some more stuff left over from copying bits of the HME driver.
 1.2 01-Oct-2001  eeh Increase receive ring to 128 entries and handle both endian devices.
 1.1 16-Sep-2001  eeh branches: 1.1.2; 1.1.4;
Driver for Sun GEM gigabit ethernet, Sun ERI 10/100, and Apple GMAC.
 1.1.4.3 11-Oct-2001  fvdl Catch up with -current. Fix some bogons in the sparc64 kbd/ms
attach code. cd18xx conversion provided by mrg.
 1.1.4.2 01-Oct-2001  fvdl Catch up with -current.
 1.1.4.1 16-Sep-2001  fvdl file gemvar.h was added on branch thorpej-devvp on 2001-10-01 12:45:36 +0000
 1.1.2.5 20-Jun-2002  nathanw Catch up to -current.
 1.1.2.4 22-Oct-2001  nathanw Catch up to -current.
 1.1.2.3 08-Oct-2001  nathanw Catch up to -current.
 1.1.2.2 21-Sep-2001  nathanw Catch up to -current.
 1.1.2.1 16-Sep-2001  nathanw file gemvar.h was added on branch nathanw_sa on 2001-09-21 22:35:37 +0000
 1.5.4.3 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.5.4.2 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.5.4.1 18-Oct-2001  thorpej file gemvar.h was added on branch kqueue on 2002-01-10 19:54:30 +0000
 1.9.14.1 21-Jun-2005  riz Pull up revision 1.12 (requested by bouyer in ticket #2006):
Pad small packets with a static buffer at the end of the S/G list.
Avoids leaking kernel memory when small packets are transmitted.
Tested on a ibook G4.
 1.9.10.3 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.9.10.2 04-Feb-2005  skrll Sync with HEAD.
 1.9.10.1 19-Oct-2004  skrll Sync with HEAD
 1.10.6.1 12-Feb-2005  yamt sync with head.
 1.10.4.1 29-Apr-2005  kent sync with -current
 1.11.4.1 21-Jun-2005  tron Pull up revision 1.12 (requested by bouyer in ticket #484):
Pad small packets with a static buffer at the end of the S/G list.
Avoids leaking kernel memory when small packets are transmitted.
Tested on a ibook G4.
 1.12.4.1 02-Nov-2005  yamt sync with head.
 1.12.2.4 04-Feb-2008  yamt sync with head.
 1.12.2.3 21-Jan-2008  yamt sync with head
 1.12.2.2 30-Dec-2006  yamt sync with head.
 1.12.2.1 21-Jun-2006  yamt sync with head.
 1.14.22.1 10-Dec-2006  yamt sync with head.
 1.14.20.1 12-Jan-2007  ad Sync with head.
 1.15.38.2 20-Jan-2008  bouyer Sync with HEAD
 1.15.38.1 08-Jan-2008  bouyer Sync with HEAD
 1.15.30.1 18-Feb-2008  mjf Sync with HEAD.
 1.15.24.2 23-Mar-2008  matt sync with HEAD
 1.15.24.1 09-Jan-2008  matt sync with HEAD
 1.15.16.1 03-Jun-2008  skrll Sync with netbsd-4.
 1.15.2.1 17-May-2008  bouyer Pull up following revision(s) (requested by jdc in ticket #1145):
src/share/man/man4/gem.4 1.5,1.6 via patch
src/sys/arch/sparc64/conf/GENERIC 1.97 via patch
src/sys/dev/ic/gem.c 1.59,1.61-1.68,1.70-1.73 via patch
src/sys/dev/ic/gemreg.h 1.11 via patch
src/sys/dev/ic/gemvar.h 1.16,1.18 via patch
src/sys/dev/mii/bmtphy.c 1.24 via patch
src/sys/dev/pci/if_gem_pci.c 1.25,1.27 via patch
src/sys/dev/pci/pcidevs 1.12 via patch
src/sys/dev/pci/pcidevs.h regenerate
src/sys/dev/pci/pcidevs_data.h regenerate
Add support for Sun PCI X1141A (SX fibre) cards.
Add improvements to the driver.
Disable HW UDP4 and RX TCP4 checksums because they are buggy (PR#34799)
Add improvements to bmtphy.
 1.18.20.1 15-Sep-2012  bouyer Pull up following revision(s) (requested by jdc in ticket #1789):
sys/dev/ic/gem.c: revision 1.99 via patch
sys/dev/ic/gemvar.h: revision 1.24 via patch
sys/dev/ic/gemreg.h: revision 1.15 via patch
Apply lockup fixes from Havard Eidnes/OpenBSD in PR port-sparc64/46260:
- add an additional watchdog for RX overflow
- re-initialise the chip on device timeout
Also alter the interrupt blanking rate to 8 packets, as per OpenSolaris.
 1.18.10.2 11-Mar-2010  yamt sync with head
 1.18.10.1 19-Aug-2009  yamt sync with head.
 1.20.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.21.10.2 30-Oct-2012  yamt sync with head
 1.21.10.1 17-Apr-2012  yamt sync with head
 1.22.2.1 18-Feb-2012  mrg merge to -current.
 1.23.2.1 05-Jul-2012  riz Pull up following revision(s) (requested by jdc in ticket #401):
sys/dev/ic/gem.c: revision 1.99
sys/dev/ic/gemvar.h: revision 1.24
sys/dev/ic/gemreg.h: revision 1.15
Apply lockup fixes from Havard Eidnes/OpenBSD in PR port-sparc64/46260:
- add an additional watchdog for RX overflow
- re-initialise the chip on device timeout
Also alter the interrupt blanking rate to 8 packets, as per OpenSolaris.
 1.24.16.1 06-Jun-2015  skrll Sync with HEAD
 1.24.2.1 03-Dec-2017  jdolecek update from HEAD
 1.25.18.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.25.18.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.27.6.1 03-Apr-2021  thorpej Sync with HEAD.
 1.2 04-Sep-2001  enami Add prescaler bit constant (missed in previous commit).
 1.1 10-Feb-1996  christos branches: 1.1.42; 1.1.44;
Hayes ESP register definition
 1.1.44.1 13-Sep-2001  thorpej Update the kqueue branch to HEAD.
 1.1.42.1 21-Sep-2001  nathanw Catch up to -current.
 1.24 08-Aug-2023  nat Avoid adding another member to the softc and use sc_flags instead.

NFCI.
 1.23 08-Aug-2023  nat Add a flag for output only devices and attachments.

It is necessary to skip the test for the device as output only attached
devices lack the ability for the device to be probed - such as the 1602 lcd
module.
 1.22 08-Aug-2023  nat Add a detach function.
 1.21 13-Nov-2010  uebayasi Don't pull in the whole uvm(9) API to access only PAGE_SIZE and
some other constants. These are provided by sys/param.h now.
 1.20 30-Aug-2009  tsutsui branches: 1.20.4;
Misc KNF.
 1.19 16-Mar-2009  dsl ANSIfy functions with function-pointer arguments
 1.18 14-Mar-2009  dsl ANSIfy another 1261 function definitions.
The only ones left in sys are beyond by sed script!
(or in sys/dist or sys/external)
Mostly they have function pointer parameters.
 1.17 14-Mar-2009  dsl Change about 4500 of the K&R function definitions to ANSI ones.
There are still about 1600 left, but they have ',' or /* ... */
in the actual variable definitions - which my awk script doesn't handle.
There are also many that need () -> (void).
(The script does handle misordered arguments.)
 1.16 19-Dec-2008  cegger branches: 1.16.2;
use M_ZERO on malloc() and remove subsequent bzero().
 1.15 10-Apr-2008  he branches: 1.15.4; 1.15.12;
Remove a now-spurious & so that this builds again (for cobalt).
 1.14 08-Apr-2008  cegger use aprint_*_dev and device_xname
 1.13 01-Nov-2007  tsutsui branches: 1.13.16;
Fix some random LCD corruption on cobalt:
- make sure to set HD_ROW1_ADDR before putting characters at the first line
in hd44780_ddram_redraw()
- use memmove(9) rather than bcopy(9) for possibly overlapped copies
 1.12 19-Oct-2007  ad machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.11 10-Jul-2007  ad branches: 1.11.6; 1.11.8; 1.11.12;
Adjust to match callout_init signature change.
 1.10 04-Mar-2007  christos branches: 1.10.2; 1.10.4;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.9 12-Apr-2006  jmmv branches: 1.9.12; 1.9.14; 1.9.18;
Add an extra cookie to the ioctl and mmap wsdisplay accessops that points
to the screen on which they are being called. The driver cannot guess
this by itself but it is needed to implement, at least, the getwschar and
putwschar functions in the correct place. There are no functional changes
yet.

Tested on i386 (vga, vga_raster, machfb, vesafb), macppc and sparc64.
Suggested and reviewed by macallan@.
 1.8 11-Dec-2005  christos branches: 1.8.4; 1.8.6; 1.8.8; 1.8.10; 1.8.12;
merge ktrace-lwp.
 1.7 14-Aug-2005  joff 4-line HD44780 LCD display support. Work needed for the NetBSD toaster port.

The HD44780 actually doesn't support 4 lines, but the 4 line displays
use two chips, one for the top two lines and one for the bottom
two lines. The chips share the databus, register-select, and write
signals but have separate enable signals.
 1.6 27-Feb-2005  perry branches: 1.6.4;
nuke trailing whitespace
 1.5 04-Feb-2005  joff Support wsdisplay(4) attachments of hd44780 LCD controllers
 1.4 11-Jan-2005  joff branches: 1.4.2; 1.4.4;
Replace hd44780_subr.h to hd44780var.h and install to userland.
 1.3 09-Jan-2005  joff Handle (i.e. don't lock up the kernel in hd44780_busy_wait) the case of the
LCD not being there.
 1.2 08-Jan-2005  joff Various improvements for connecting HD44780s using bit-banging style devices

o add sc_writereg and sc_readreg functions that get passed the hd44780_chip
struct and RS (register-select) signal
o add sc_dev to struct hd44780_chip so upper level read/write routines can get
back to their parent softc
o change TIMEOUT_XXX to HD_TIMEOUT_XXX
o remove sc_rread and sc_rwrite in favor of new sc_writereg and sc_readreg
o add new flag HD_UP to sc_flags that is set once 4bit/8bit mode selection
has been finalized.
o remove sc_irwrite, MD readreg/writereg should check state of HD_UP instead
 1.1 20-Jan-2003  soren branches: 1.1.2;
Driver for the Hitachi HD44780 used in many small LCD panels.
Written by Dennis Chernoivanov.
 1.1.2.5 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.1.2.4 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.1.2.3 09-Feb-2005  skrll Adapt to branch.
 1.1.2.2 04-Feb-2005  skrll Sync with HEAD.
 1.1.2.1 17-Jan-2005  skrll Sync with HEAD.
 1.4.4.2 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.4.4.1 12-Feb-2005  yamt sync with head.
 1.4.2.1 29-Apr-2005  kent sync with -current
 1.6.4.4 15-Nov-2007  yamt sync with head.
 1.6.4.3 27-Oct-2007  yamt sync with head.
 1.6.4.2 03-Sep-2007  yamt sync with head.
 1.6.4.1 21-Jun-2006  yamt sync with head.
 1.8.12.1 24-May-2006  tron Merge 2006-05-24 NetBSD-current into the "peter-altq" branch.
 1.8.10.1 19-Apr-2006  elad sync with head.
 1.8.8.1 24-May-2006  yamt sync with head.
 1.8.6.1 22-Apr-2006  simonb Sync with head.
 1.8.4.1 09-Sep-2006  rpaulo sync with head
 1.9.18.1 06-Jan-2008  wrstuden Catch up to netbsd-4.0 release.
 1.9.14.1 12-Mar-2007  rmind Sync with HEAD.
 1.9.12.1 04-Nov-2007  pavel Pull up following revision(s) (requested by tsutsui in ticket #975):
sys/dev/ic/hd44780_subr.c: revision 1.13
Fix some random LCD corruption on cobalt:
- make sure to set HD_ROW1_ADDR before putting characters at the first line
in hd44780_ddram_redraw()
- use memmove(9) rather than bcopy(9) for possibly overlapped copies
 1.10.4.1 11-Jul-2007  mjf Sync with head.
 1.10.2.2 23-Oct-2007  ad Sync with head.
 1.10.2.1 15-Jul-2007  ad Sync with head.
 1.11.12.2 13-Nov-2007  bouyer Sync with HEAD
 1.11.12.1 25-Oct-2007  bouyer Sync with HEAD.
 1.11.8.1 06-Nov-2007  matt sync with HEAD
 1.11.6.2 04-Nov-2007  jmcneill Sync with HEAD.
 1.11.6.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.13.16.2 17-Jan-2009  mjf Sync with HEAD.
 1.13.16.1 02-Jun-2008  mjf Sync with HEAD.
 1.15.12.2 28-Apr-2009  skrll Sync with HEAD.
 1.15.12.1 19-Jan-2009  skrll Sync with HEAD.
 1.15.4.2 16-Sep-2009  yamt sync with head
 1.15.4.1 04-May-2009  yamt sync with head.
 1.16.2.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.20.4.1 05-Mar-2011  rmind sync with head
 1.4 11-Jan-2005  joff Replace hd44780_subr.h to hd44780var.h and install to userland.
 1.3 09-Jan-2005  joff Handle (i.e. don't lock up the kernel in hd44780_busy_wait) the case of the
LCD not being there.
 1.2 08-Jan-2005  joff Various improvements for connecting HD44780s using bit-banging style devices

o add sc_writereg and sc_readreg functions that get passed the hd44780_chip
struct and RS (register-select) signal
o add sc_dev to struct hd44780_chip so upper level read/write routines can get
back to their parent softc
o change TIMEOUT_XXX to HD_TIMEOUT_XXX
o remove sc_rread and sc_rwrite in favor of new sc_writereg and sc_readreg
o add new flag HD_UP to sc_flags that is set once 4bit/8bit mode selection
has been finalized.
o remove sc_irwrite, MD readreg/writereg should check state of HD_UP instead
 1.1 20-Jan-2003  soren branches: 1.1.2;
Driver for the Hitachi HD44780 used in many small LCD panels.
Written by Dennis Chernoivanov.
 1.1.2.1 17-Jan-2005  skrll Sync with HEAD.
 1.4 30-Aug-2009  tsutsui Misc KNF.
 1.3 11-Dec-2005  christos branches: 1.3.74;
merge ktrace-lwp.
 1.2 08-Jan-2005  joff Change TIMEOUT_XXX to HD_TIMEOUT_XXX
 1.1 20-Jan-2003  soren branches: 1.1.2;
Driver for the Hitachi HD44780 used in many small LCD panels.
Written by Dennis Chernoivanov.
 1.1.2.1 17-Jan-2005  skrll Sync with HEAD.
 1.3.74.1 16-Sep-2009  yamt sync with head
 1.11 08-Aug-2023  nat Avoid adding another member to the softc and use sc_flags instead.

NFCI.
 1.10 08-Aug-2023  nat Add a flag for output only devices and attachments.

It is necessary to skip the test for the device as output only attached
devices lack the ability for the device to be probed - such as the 1602 lcd
module.
 1.9 08-Aug-2023  nat Add a detach function.
 1.8 06-Sep-2015  dholland More on PR 41200: headers that declare ioctls should include sys/ioccom.h.
This covers (I think) all the MI headers outside of external/ (and dist/).
 1.7 30-Aug-2009  tsutsui branches: 1.7.22; 1.7.40;
Misc KNF.
 1.6 12-May-2009  cegger struct device * -> device_t, no functional changes intended.
 1.5 04-Mar-2007  christos branches: 1.5.40; 1.5.56;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.4 11-Dec-2005  christos branches: 1.4.26;
merge ktrace-lwp.
 1.3 14-Aug-2005  joff 4-line HD44780 LCD display support. Work needed for the NetBSD toaster port.

The HD44780 actually doesn't support 4 lines, but the 4 line displays
use two chips, one for the top two lines and one for the bottom
two lines. The chips share the databus, register-select, and write
signals but have separate enable signals.
 1.2 04-Feb-2005  joff branches: 1.2.6;
Support wsdisplay(4) attachments of hd44780 LCD controllers
 1.1 11-Jan-2005  joff branches: 1.1.2; 1.1.4; 1.1.6;
Replace hd44780_subr.h to hd44780var.h and install to userland.
 1.1.6.1 12-Feb-2005  yamt sync with head.
 1.1.4.4 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.1.4.3 04-Feb-2005  skrll Sync with HEAD.
 1.1.4.2 17-Jan-2005  skrll Sync with HEAD.
 1.1.4.1 11-Jan-2005  skrll file hd44780var.h was added on branch ktrace-lwp on 2005-01-17 19:30:39 +0000
 1.1.2.1 29-Apr-2005  kent sync with -current
 1.2.6.2 03-Sep-2007  yamt sync with head.
 1.2.6.1 21-Jun-2006  yamt sync with head.
 1.4.26.1 12-Mar-2007  rmind Sync with HEAD.
 1.5.56.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.5.40.2 16-Sep-2009  yamt sync with head
 1.5.40.1 16-May-2009  yamt sync with head
 1.7.40.1 22-Sep-2015  skrll Sync with HEAD
 1.7.22.1 03-Dec-2017  jdolecek update from HEAD
 1.62 14-Sep-2024  andvar s/intterupt/interrupt/ in comments.
 1.61 14-Sep-2024  andvar s/intrerrupt/interrupt/ in documentation and comments.
gpioirq(4) typo was accidentally restored in the last commit.
 1.60 05-Jul-2024  rin sys: Drop redundant NULL check before m_freem(9)

m_freem(9) safely has accepted NULL argument at least since 4.2BSD:
https://www.tuhs.org/cgi-bin/utree.pl?file=4.2BSD/usr/src/sys/sys/uipc_mbuf.c

Compile-tested on amd64/ALL.

Suggested by knakahara@
 1.59 29-Jun-2024  riastradh branches: 1.59.2;
if_stats(9): Add ifp argument to if_stat..._ref.

This will enable us to pass the ifp through to a dtrace probe inside.

No functional change intended in this change, but this is an API
change visible to modules so it shouldn't be pulled up.

PR kern/58377
 1.58 10-Feb-2024  andvar s/indicies/indices/ in comments.
 1.57 03-Sep-2022  thorpej branches: 1.57.8;
Garbage-collect the remaining vestiges of netisr.
 1.56 17-Aug-2021  andvar fix multiplei repetitive typos in comments, messages and documentation. mainly because copy paste code big amount of files are affected.
 1.55 29-Jan-2020  thorpej Adopt <net/if_stats.h>.
 1.54 26-Jun-2018  msaitoh branches: 1.54.2; 1.54.10;
Implement the BPF direction filter (BIOC[GS]DIRECTION). It provides backward
compatibility with BIOC[GS]SEESENT ioctl. The userland interface is the same
as FreeBSD.

This change also fixes a bug that the direction is misunderstand on some
environment by passing the direction to bpf_mtap*() instead of checking
m->m_pkthdr.rcvif.
 1.53 20-Feb-2017  ozaki-r branches: 1.53.12;
Apply deferred if_start to more drivers
 1.52 24-Jan-2017  ozaki-r Defer bpf_mtap in Rx interrupt context to softint

bpf_mtap of some drivers is still called in hardware interrupt context.
We want to run them in softint as well as bpf_mtap of most drivers
(see if_percpuq_softint and if_input).

To this end, bpf_mtap_softint mechanism is implemented; it defers
bpf_mtap processing to a dedicated softint for a target driver.
By using the machanism, we can move bpf_mtap processing to softint
without changing target drivers much while it adds some overhead
on CPU and memory. Once target drivers are changed to softint-based,
we should return to normal bpf_mtap.

Proposed on tech-kern and tech-net
 1.51 15-Dec-2016  ozaki-r branches: 1.51.2;
Annotate bpf_mtap still running in Rx hardware interrupt with "XXX not in softint"
 1.50 10-Jun-2016  ozaki-r branches: 1.50.2;
Introduce m_set_rcvif and m_reset_rcvif

The API is used to set (or reset) a received interface of a mbuf.
They are counterpart of m_get_rcvif, which will come in another
commit, hide internal of rcvif operation, and reduce the diff of
the upcoming change.

No functional change.
 1.49 28-Apr-2016  ozaki-r Constify rtentry of if_output

We no longer need to change rtentry below if_output.

The change makes it clear where rtentries are changed (or not)
and helps forthcoming locking (os psrefing) rtentries.
 1.48 20-Apr-2016  knakahara IFQ_ENQUEUE refactor (3/3) : eliminate pktattr argument from IFQ_ENQUEUE caller
 1.47 05-Jun-2014  rmind branches: 1.47.4;
- Implement pktqueue interface for lockless IP input queue.
- Replace ipintrq and ip6intrq with the pktqueue mechanism.
- Eliminate kernel-lock from ipintr() and ip6intr().
- Some preparation work to push softnet_lock out of ipintr().

Discussed on tech-net.
 1.46 15-May-2014  msaitoh Save a NETISR_* value in a variable and call schednetisr() after enqueue
a packet for readability and future modification.
 1.45 14-Sep-2013  joerg branches: 1.45.2;
Put helper functions for debugging under the corresponding debug
options.
 1.44 01-Mar-2013  joerg branches: 1.44.6;
Retire OSI network stack. OK core@
 1.43 05-Apr-2010  joerg branches: 1.43.8; 1.43.18;
Push the bpf_ops usage back into bpf.h. Push the common ifp->if_bpf
check into the inline functions as well the fourth argument for
bpf_attach.
 1.42 19-Jan-2010  pooka branches: 1.42.2; 1.42.4;
Redefine bpf linkage through an always present op vector, i.e.
#if NBPFILTER is no longer required in the client. This change
doesn't yet add support for loading bpf as a module, since drivers
can register before bpf is attached. However, callers of bpf can
now be modularized.

Dynamically loadable bpf could probably be done fairly easily with
coordination from the stub driver and the real driver by registering
attachments in the stub before the real driver is loaded and doing
a handoff. ... and I'm not going to ponder the depths of unload
here.

Tested with i386/MONOLITHIC, modified MONOLITHIC without bpf and rump.
 1.41 14-Mar-2009  dsl Change about 4500 of the K&R function definitions to ANSI ones.
There are still about 1600 left, but they have ',' or /* ... */
in the actual variable definitions - which my awk script doesn't handle.
There are also many that need () -> (void).
(The script does handle misordered arguments.)
 1.40 07-Nov-2008  dyoung branches: 1.40.4;
*** Summary ***

When a link-layer address changes (e.g., ifconfig ex0 link
02:de:ad:be:ef:02 active), send a gratuitous ARP and/or a Neighbor
Advertisement to update the network-/link-layer address bindings
on our LAN peers.

Refuse a change of ethernet address to the address 00:00:00:00:00:00
or to any multicast/broadcast address. (Thanks matt@.)

Reorder ifnet ioctl operations so that driver ioctls may inherit
the functions of their "class"---ether_ioctl(), fddi_ioctl(), et
cetera---and the class ioctls may inherit from the generic ioctl,
ifioctl_common(), but both driver- and class-ioctls may override
the generic behavior. Make network drivers share more code.

Distinguish a "factory" link-layer address from others for the
purposes of both protecting that address from deletion and computing
EUI64.

Return consistent, appropriate error codes from network drivers.

Improve readability. KNF.

*** Details ***

In if_attach(), always initialize the interface ioctl routine,
ifnet->if_ioctl, if the driver has not already initialized it.
Delete if_ioctl == NULL tests everywhere else, because it cannot
happen.

In the ioctl routines of network interfaces, inherit common ioctl
behaviors by calling either ifioctl_common() or whichever ioctl
routine is appropriate for the class of interface---e.g., ether_ioctl()
for ethernets.

Stop (ab)using SIOCSIFADDR and start to use SIOCINITIFADDR. In
the user->kernel interface, SIOCSIFADDR's argument was an ifreq,
but on the protocol->ifnet interface, SIOCSIFADDR's argument was
an ifaddr. That was confusing, and it would work against me as I
make it possible for a network interface to overload most ioctls.
On the protocol->ifnet interface, replace SIOCSIFADDR with
SIOCINITIFADDR. In ifioctl(), return EPERM if userland tries to
invoke SIOCINITIFADDR.

In ifioctl(), give the interface the first shot at handling most
interface ioctls, and give the protocol the second shot, instead
of the other way around. Finally, let compatibility code (COMPAT_OSOCK)
take a shot.

Pull device initialization out of switch statements under
SIOCINITIFADDR. For example, pull ..._init() out of any switch
statement that looks like this:

switch (...->sa_family) {
case ...:
..._init();
...
break;
...
default:
..._init();
...
break;
}

Rewrite many if-else clauses that handle all permutations of IFF_UP
and IFF_RUNNING to use a switch statement,

switch (x & (IFF_UP|IFF_RUNNING)) {
case 0:
...
break;
case IFF_RUNNING:
...
break;
case IFF_UP:
...
break;
case IFF_UP|IFF_RUNNING:
...
break;
}

unifdef lots of code containing #ifdef FreeBSD, #ifdef NetBSD, and
#ifdef SIOCSIFMTU, especially in fwip(4) and in ndis(4).

In ipw(4), remove an if_set_sadl() call that is out of place.

In nfe(4), reuse the jumbo MTU logic in ether_ioctl().

Let ethernets register a callback for setting h/w state such as
promiscuous mode and the multicast filter in accord with a change
in the if_flags: ether_set_ifflags_cb() registers a callback that
returns ENETRESET if the caller should reset the ethernet by calling
if_init(), 0 on success, != 0 on failure. Pull common code from
ex(4), gem(4), nfe(4), sip(4), tlp(4), vge(4) into ether_ioctl(),
and register if_flags callbacks for those drivers.

Return ENOTTY instead of EINVAL for inappropriate ioctls. In
zyd(4), use ENXIO instead of ENOTTY to indicate that the device is
not any longer attached.

Add to if_set_sadl() a boolean 'factory' argument that indicates
whether a link-layer address was assigned by the factory or some
other source. In a comment, recommend using the factory address
for generating an EUI64, and update in6_get_hw_ifid() to prefer a
factory address to any other link-layer address.

Add a routing message, RTM_LLINFO_UPD, that tells protocols to
update the binding of network-layer addresses to link-layer addresses.
Implement this message in IPv4 and IPv6 by sending a gratuitous
ARP or a neighbor advertisement, respectively. Generate RTM_LLINFO_UPD
messages on a change of an interface's link-layer address.

In ether_ioctl(), do not let SIOCALIFADDR set a link-layer address
that is broadcast/multicast or equal to 00:00:00:00:00:00.

Make ether_ioctl() call ifioctl_common() to handle ioctls that it
does not understand.

In gif(4), initialize if_softc and use it, instead of assuming that
the gif_softc and ifp overlap.

Let ifioctl_common() handle SIOCGIFADDR.

Sprinkle rtcache_invariants(), which checks on DIAGNOSTIC kernels
that certain invariants on a struct route are satisfied.

In agr(4), rewrite agr_ioctl_filter() to be a bit more explicit
about the ioctls that we do not allow on an agr(4) member interface.

bzero -> memset. Delete unnecessary casts to void *. Use
sockaddr_in_init() and sockaddr_in6_init(). Compare pointers with
NULL instead of "testing truth". Replace some instances of (type
*)0 with NULL. Change some K&R prototypes to ANSI C, and join
lines.
 1.39 08-Apr-2008  cegger branches: 1.39.4; 1.39.10; 1.39.12;
use aprint_*_dev and device_xname
 1.38 19-Oct-2007  ad branches: 1.38.16;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.37 01-Sep-2007  dyoung branches: 1.37.4;
Use ifreq_setaddr(), ifreq_getaddr(), sockaddr_in_init(), and
sockaddr_copy(). Constify. Compare pointers with NULL, not 0.
Don't "test truth" of pointers, but compare with NULL.
 1.36 04-Mar-2007  christos branches: 1.36.2; 1.36.10; 1.36.14; 1.36.16;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.35 17-Feb-2007  dyoung KNF: de-__P, bzero -> memset, bcmp -> memcmp. Remove extraneous
parentheses in return statements.

Cosmetic: don't open-code TAILQ_FOREACH().

Cosmetic: change types of variables to avoid oodles of casts: in
in6_src.c, avoid casts by changing several route_in6 pointers
to struct route pointers. Remove unnecessary casts to caddr_t
elsewhere.

Pave the way for eliminating address family-specific route caches:
soon, struct route will not embed a sockaddr, but it will hold
a reference to an external sockaddr, instead. We will set the
destination sockaddr using rtcache_setdst(). (I created a stub
for it, but it isn't used anywhere, yet.) rtcache_free() will
free the sockaddr. I have extracted from rtcache_free() a helper
subroutine, rtcache_clear(). rtcache_clear() will "forget" a
cached route, but it will not forget the destination by releasing
the sockaddr. I use rtcache_clear() instead of rtcache_free()
in rtcache_update(), because rtcache_update() is not supposed
to forget the destination.

Constify:

1 Introduce const accessor for route->ro_dst, rtcache_getdst().

2 Constify the 'dst' argument to ifnet->if_output(). This
led me to constify a lot of code called by output routines.

3 Constify the sockaddr argument to protosw->pr_ctlinput. This
led me to constify a lot of code called by ctlinput routines.

4 Introduce const macros for converting from a generic sockaddr
to family-specific sockaddrs, e.g., sockaddr_in: satocsin6,
satocsin, et cetera.
 1.34 16-Nov-2006  christos branches: 1.34.4;
__unused removal on arguments; approved by core.
 1.33 12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.32 07-Jun-2006  kardel branches: 1.32.6; 1.32.8;
merge FreeBSD timecounters from branch simonb-timecounters
- struct timeval time is gone
time.tv_sec -> time_second
- struct timeval mono_time is gone
mono_time.tv_sec -> time_uptime
- access to time via
{get,}{micro,nano,bin}time()
get* versions are fast but less precise
- support NTP nanokernel implementation (NTP API 4)
- further reading:
Timecounter Paper: http://phk.freebsd.dk/pubs/timecounter.pdf
NTP Nanokernel: http://www.eecis.udel.edu/~mills/ntp/html/kern.html
 1.31 28-Mar-2006  thorpej branches: 1.31.2;
Use device_unit().
 1.30 11-Dec-2005  christos branches: 1.30.4; 1.30.6; 1.30.8; 1.30.10; 1.30.12;
merge ktrace-lwp.
 1.29 27-Feb-2005  perry branches: 1.29.4;
nuke trailing whitespace
 1.28 04-Feb-2005  perry de-__P
 1.27 22-Apr-2004  itojun branches: 1.27.4; 1.27.6;
sprintf -> snprintf
 1.26 24-Feb-2004  wiz becuase -> because. From Peter Postma.
 1.25 02-Nov-2003  wiz Fix some typos. From Tom Cosgrove via jmc@openbsd.
 1.24 30-Oct-2003  simonb Remove some assigned-to but otherwise unused variables.
 1.23 03-May-2003  wiz branches: 1.23.2;
DMA, not dma nor Dma.
 1.22 21-Feb-2003  tsutsui hz -> Hz
 1.21 05-Mar-2002  itojun bring in latest ALTQ from kjc. ALTQify some of the drivers.
 1.20 13-Nov-2001  lukem add/cleanup RCSID
 1.19 14-Aug-2001  mrg add (u_long) casts for sparc64.
 1.18 07-Jul-2001  thorpej branches: 1.18.2;
bcopy -> memcpy
 1.17 14-Jun-2001  itojun change the meaning of ifnet.if_lastchange to meet RFC1573 ifLastChange.
follows BSD/OS practice and ucd-snmp code (FreeBSD does it for specific
interfaces only).

was: if_lastchange get updated on every packet transmission/receipt.
now: if_lastchange get updated when IFF_UP is changed.
 1.16 12-Jun-2001  wiz underrun, not underun
 1.15 01-Mar-2001  itojun branches: 1.15.2;
IPv6 support, from fujiwara@rcac.tdi.co.jp
 1.14 17-Jan-2001  thorpej Fix a rather annoying problem where the sockaddr_dl which holds
the link level name for the interface (ifp->if_sadl) is allocated
before ifp->if_addrlen is initialized, which could lead to allocating
too little space for the link level address.

Do this by splitting allocation of the link level name out of
if_attach() and into if_alloc_sadl(), which is normally called
by functions like ether_ifattach(). Network interfaces which
don't have a link-specific attach routine must call if_alloc_sadl()
themselves (example: gif).

Link level names are freed by if_free_sadl(), which can be called
from e.g. ether_ifdetach(). Drivers never need call if_free_sadl()
themselves as if_detach() will do it if it is not already done.

While here, add the ability to pass an AF_LINK address to
SIOCSIFADDR in ether_ioctl() (this is what caused me to notice
the problem that the above fixes).
 1.13 18-Dec-2000  thorpej ALTQ'ify.
 1.12 12-Dec-2000  thorpej Adapt to bpfattach() changes, and further centralize the bpfattach()
and bpfdetach() calls into link-type subroutines where possible.
 1.11 09-Jan-2000  chopps remove unused llc from receive logic, protect use of llc header in tranmist
logic, fixes pr#9151
 1.10 09-Jan-2000  chopps rename hl_control to hl_ffb (friendly fudge byte) as per cisco insider
the belief is that this was used to align OSI clnp header fields better
 1.9 08-Jan-2000  chopps pass iso pdus to netiso
 1.8 04-Jan-2000  chopps convert to support non-dma IO (for the isa Riscom/N2).
allow the user to set and use the internal baud rate generator
fix the transmission ring logic to support more than 1 frame per interrupt
add autodetection of the base clock frequency.
cleanup the receive ring logic
support dynamically resizing the low-water mark on the fifo in response
to buffer underruns on transmit.
 1.7 23-Oct-1999  erh Add description of the hd64570 chip. Add brief description of this driver.
 1.6 19-Mar-1999  erh branches: 1.6.8; 1.6.10; 1.6.12;
Get the index on the buffer (in addition to the descriptor) correct.
 1.5 16-Mar-1999  erh Add a "+1" in sca_start which should fix the limit of 2 transmit buffers. Also, kill some duplicate code.
 1.4 09-Dec-1998  tls Fix bug that caused all ifp's to have if_xname ntwo0, which was rather inconvenient. Should use config_found on each port instead, but this works for the moment and it's quick.
 1.3 28-Oct-1998  kleink RCS Id police, canonicalize multiple-inclusion protection symbol names.
 1.2 08-Aug-1998  mycroft Use splnet, not splimp.
 1.1 26-Jul-1998  explorer add (hopefully) bus-independent hd64570 driver, for the Hitachi serial
controller chip.
 1.6.12.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.6.10.1 15-Nov-1999  fvdl Sync with -current
 1.6.8.5 12-Mar-2001  bouyer Sync with HEAD.
 1.6.8.4 18-Jan-2001  bouyer Sync with head (for UBC+NFS fixes, mostly).
 1.6.8.3 05-Jan-2001  bouyer Sync with HEAD
 1.6.8.2 13-Dec-2000  bouyer Sync with HEAD (for UBC fixes).
 1.6.8.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.15.2.4 01-Apr-2002  nathanw Catch up to -current.
(CVS: It's not just a program. It's an adventure!)
 1.15.2.3 14-Nov-2001  nathanw Catch up to -current.
 1.15.2.2 24-Aug-2001  nathanw Catch up with -current.
 1.15.2.1 21-Jun-2001  nathanw Catch up to -current.
 1.18.2.3 16-Mar-2002  jdolecek Catch up with -current.
 1.18.2.2 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.18.2.1 25-Aug-2001  thorpej Merge Aug 24 -current into the kqueue branch.
 1.23.2.5 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.23.2.4 04-Feb-2005  skrll Sync with HEAD.
 1.23.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.23.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.23.2.1 03-Aug-2004  skrll Sync with HEAD
 1.27.6.2 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.27.6.1 12-Feb-2005  yamt sync with head.
 1.27.4.1 29-Apr-2005  kent sync with -current
 1.29.4.5 27-Oct-2007  yamt sync with head.
 1.29.4.4 03-Sep-2007  yamt sync with head.
 1.29.4.3 26-Feb-2007  yamt sync with head.
 1.29.4.2 30-Dec-2006  yamt sync with head.
 1.29.4.1 21-Jun-2006  yamt sync with head.
 1.30.12.1 31-Mar-2006  tron Merge 2006-03-31 NetBSD-current into the "peter-altq" branch.
 1.30.10.1 19-Apr-2006  elad sync with head.
 1.30.8.2 26-Jun-2006  yamt sync with head.
 1.30.8.1 01-Apr-2006  yamt sync with head.
 1.30.6.2 22-Apr-2006  simonb Sync with head.
 1.30.6.1 04-Feb-2006  simonb Adapt for timecounters: mostly use get*time() and use "time_second"
instead of "time.tv_sec".
 1.30.4.1 09-Sep-2006  rpaulo sync with head
 1.31.2.1 19-Jun-2006  chap Sync with head.
 1.32.8.2 10-Dec-2006  yamt sync with head.
 1.32.8.1 22-Oct-2006  yamt sync with head
 1.32.6.1 18-Nov-2006  ad Sync with head.
 1.34.4.2 12-Mar-2007  rmind Sync with HEAD.
 1.34.4.1 27-Feb-2007  yamt - sync with head.
- move sched_changepri back to kern_synch.c as it doesn't know PPQ anymore.
 1.36.16.1 06-Nov-2007  matt sync with HEAD
 1.36.14.2 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.36.14.1 03-Sep-2007  jmcneill Sync with HEAD.
 1.36.10.1 03-Sep-2007  skrll Sync with HEAD.
 1.36.2.2 23-Oct-2007  ad Sync with head.
 1.36.2.1 09-Oct-2007  ad Sync with head.
 1.37.4.1 25-Oct-2007  bouyer Sync with HEAD.
 1.38.16.2 17-Jan-2009  mjf Sync with HEAD.
 1.38.16.1 02-Jun-2008  mjf Sync with HEAD.
 1.39.12.2 28-Apr-2009  skrll Sync with HEAD.
 1.39.12.1 19-Jan-2009  skrll Sync with HEAD.
 1.39.10.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.39.4.3 11-Aug-2010  yamt sync with head.
 1.39.4.2 11-Mar-2010  yamt sync with head
 1.39.4.1 04-May-2009  yamt sync with head.
 1.40.4.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.42.4.1 30-May-2010  rmind sync with head
 1.42.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.43.18.3 03-Dec-2017  jdolecek update from HEAD
 1.43.18.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.43.18.1 23-Jun-2013  tls resync from head
 1.43.8.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.44.6.1 18-May-2014  rmind sync with head
 1.45.2.1 10-Aug-2014  tls Rebase.
 1.47.4.5 28-Aug-2017  skrll Sync with HEAD
 1.47.4.4 05-Feb-2017  skrll Sync with HEAD
 1.47.4.3 09-Jul-2016  skrll Sync with HEAD
 1.47.4.2 29-May-2016  skrll Sync with HEAD
 1.47.4.1 22-Apr-2016  skrll Sync with HEAD
 1.50.2.2 20-Mar-2017  pgoyette Sync with HEAD
 1.50.2.1 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.51.2.1 21-Apr-2017  bouyer Sync with HEAD
 1.53.12.1 28-Jul-2018  pgoyette Sync with HEAD
 1.54.10.1 29-Feb-2020  ad Sync with head.
 1.54.2.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.57.8.1 16-Nov-2023  thorpej IFQ_CLASSIFY() -> ifq_classify_packet().
 1.59.2.1 02-Aug-2025  perseant Sync with HEAD
 1.15 18-Aug-2025  andvar Fix various typos, mainly in comments:
s/invaid/invalid/
s/instad/instead/
s/wich/with/
s/tranform/transform/
s/tranmist/transmit/
s/tranceiver/transceiver/
s/Tranparent/Transparent/
s/tranlated/translated/
s/tranfer/transfer/
s/tranmissions/transmissions/
s/condtions/conditions/
s/Recient/Recent/
 1.14 14-Sep-2024  andvar s/intrerrupt/interrupt/ in documentation and comments.
gpioirq(4) typo was accidentally restored in the last commit.
 1.13 06-Jul-2024  andvar Fix various typos in comments:
s/defininitions/definitions/
s/ininitialise/initialise/
s/collasped/collapsed/
s/optionaly/optionally/
 1.12 14-May-2024  andvar branches: 1.12.2;
fix recently committed typos by msaitoh in few more places, as well as few more.
mainly s/contigous/contiguous/ and s/miliseconds/milliseconds/ in comments.
 1.11 11-Dec-2005  christos merge ktrace-lwp.
 1.10 27-Feb-2005  perry nuke trailing whitespace
 1.9 02-Nov-2003  wiz branches: 1.9.8; 1.9.10;
boundary, not boundry. Inspired by Tom Cosgrove.
 1.8 12-Jun-2001  wiz branches: 1.8.22;
receive, not recieve
 1.7 12-Jun-2001  wiz underrun, not underun
 1.6 01-Mar-2001  itojun branches: 1.6.2;
IPv6 support, from fujiwara@rcac.tdi.co.jp
 1.5 09-Jan-2000  chopps rename hl_control to hl_ffb (friendly fudge byte) as per cisco insider
the belief is that this was used to align OSI clnp header fields better
 1.4 08-Jan-2000  chopps pass iso pdus to netiso
 1.3 04-Jan-2000  chopps convert to support non-dma IO (for the isa Riscom/N2).
allow the user to set and use the internal baud rate generator
fix the transmission ring logic to support more than 1 frame per interrupt
add autodetection of the base clock frequency.
cleanup the receive ring logic
support dynamically resizing the low-water mark on the fifo in response
to buffer underruns on transmit.
 1.2 28-Oct-1998  kleink branches: 1.2.12;
RCS Id police, canonicalize multiple-inclusion protection symbol names.
 1.1 26-Jul-1998  explorer add (hopefully) bus-independent hd64570 driver, for the Hitachi serial
controller chip.
 1.2.12.2 12-Mar-2001  bouyer Sync with HEAD.
 1.2.12.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.6.2.1 21-Jun-2001  nathanw Catch up to -current.
 1.8.22.4 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.8.22.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.8.22.2 18-Sep-2004  skrll Sync with HEAD.
 1.8.22.1 03-Aug-2004  skrll Sync with HEAD
 1.9.10.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.9.8.1 29-Apr-2005  kent sync with -current
 1.12.2.1 02-Aug-2025  perseant Sync with HEAD
 1.11 27-Oct-2012  chs split device_t/softc for all remaining drivers.
replace "struct device *" with "device_t".
use device_xname(), device_unit(), etc.
 1.10 27-Jul-2010  jakllsch branches: 1.10.8; 1.10.18;
Use bus_addr_t for physical addresses.
For some reason the driver will put virtual addresses in these variables,
so I'd say this still not quite right. Oh well, at least it compiles on LP64.
 1.9 19-Jan-2010  pooka branches: 1.9.2; 1.9.4;
Redefine bpf linkage through an always present op vector, i.e.
#if NBPFILTER is no longer required in the client. This change
doesn't yet add support for loading bpf as a module, since drivers
can register before bpf is attached. However, callers of bpf can
now be modularized.

Dynamically loadable bpf could probably be done fairly easily with
coordination from the stub driver and the real driver by registering
attachments in the stub before the real driver is loaded and doing
a handoff. ... and I'm not going to ponder the depths of unload
here.

Tested with i386/MONOLITHIC, modified MONOLITHIC without bpf and rump.
 1.8 04-Mar-2007  christos branches: 1.8.40;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.7 11-Dec-2005  christos branches: 1.7.26;
merge ktrace-lwp.
 1.6 08-Jul-2003  itojun branches: 1.6.16;
function prototype must not have variable name
 1.5 03-May-2003  wiz branches: 1.5.2;
DMA, not dma nor Dma.
 1.4 12-Dec-2000  thorpej Adapt to bpfattach() changes, and further centralize the bpfattach()
and bpfdetach() calls into link-type subroutines where possible.
 1.3 04-Jan-2000  chopps convert to support non-dma IO (for the isa Riscom/N2).
allow the user to set and use the internal baud rate generator
fix the transmission ring logic to support more than 1 frame per interrupt
add autodetection of the base clock frequency.
cleanup the receive ring logic
support dynamically resizing the low-water mark on the fifo in response
to buffer underruns on transmit.
 1.2 28-Oct-1998  kleink branches: 1.2.12;
RCS Id police, canonicalize multiple-inclusion protection symbol names.
 1.1 26-Jul-1998  explorer add (hopefully) bus-independent hd64570 driver, for the Hitachi serial
controller chip.
 1.2.12.2 13-Dec-2000  bouyer Sync with HEAD (for UBC fixes).
 1.2.12.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.5.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.5.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.5.2.1 03-Aug-2004  skrll Sync with HEAD
 1.6.16.1 03-Sep-2007  yamt sync with head.
 1.7.26.1 12-Mar-2007  rmind Sync with HEAD.
 1.8.40.2 11-Aug-2010  yamt sync with head.
 1.8.40.1 11-Mar-2010  yamt sync with head
 1.9.4.1 05-Mar-2011  rmind sync with head
 1.9.2.1 17-Aug-2010  uebayasi Sync with HEAD.
 1.10.18.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.10.8.1 30-Oct-2012  yamt sync with head
 1.4 19-Oct-2009  rmind Drop 3rd and 4th clauses from David Young's license.
Reviewed and approved by dyoung@ (copyright holder).
 1.3 16-Nov-2007  dyoung branches: 1.3.2; 1.3.4; 1.3.6; 1.3.10; 1.3.18; 1.3.28;
Define some more registers.
 1.2 16-Nov-2007  dyoung Add missing */, RCS Id, and license.
 1.1 16-Nov-2007  dyoung Add part of the Intersil HFA3861A register set so that eventually
I can remove magic numbers from atw(4).
 1.3.28.1 11-Mar-2010  yamt sync with head
 1.3.18.2 09-Jan-2008  matt sync with HEAD
 1.3.18.1 16-Nov-2007  matt file hfa3861areg.h was added on branch matt-armv6 on 2008-01-09 01:52:53 +0000
 1.3.10.2 07-Dec-2007  yamt sync with head
 1.3.10.1 16-Nov-2007  yamt file hfa3861areg.h was added on branch yamt-lazymbuf on 2007-12-07 17:29:54 +0000
 1.3.6.2 21-Nov-2007  joerg Sync with HEAD.
 1.3.6.1 16-Nov-2007  joerg file hfa3861areg.h was added on branch jmcneill-pm on 2007-11-21 21:54:52 +0000
 1.3.4.2 19-Nov-2007  mjf Sync with HEAD.
 1.3.4.1 16-Nov-2007  mjf file hfa3861areg.h was added on branch mjf-devfs on 2007-11-19 00:47:53 +0000
 1.3.2.2 18-Nov-2007  bouyer Sync with HEAD
 1.3.2.1 16-Nov-2007  bouyer file hfa3861areg.h was added on branch bouyer-xenamd64 on 2007-11-18 19:35:24 +0000
 1.110 29-Jun-2024  riastradh if_stats(9): Add ifp argument to if_stat..._ref.

This will enable us to pass the ifp through to a dtrace probe inside.

No functional change intended in this change, but this is an API
change visible to modules so it shouldn't be pulled up.

PR kern/58377
 1.109 29-May-2022  rin Audit unload/unmap v.s. free against DMA buffer for sys/dev;
make sure that bus_dmamap_unload(9) [or bus_dmamap_destroy(9)] or
bus_dmamem_unmap(9) are preceding to freeing DMA buffer, if it is
loaded or mapped, respectively.

This is mandatory for some archs. See, e.g.:

http://www.nerv.org/netbsd/?q=id:20210511T013030Z.013443cc790088147e4beed43f53dedabeaf9312
http://www.nerv.org/netbsd/?q=id:20220511T172220Z.561179f0b6fcc5b9cd73e274f69d74e2ce9e4c93

For some drivers, resource leaks for error paths are fixed at
the same time.

XXX XXX XXX
Compile test only (at least one arch per driver).
 1.108 12-Mar-2020  thorpej Add support for MBUFTRACE.
 1.107 07-Feb-2020  thorpej Use callout_setfunc() / callout_schedule().
 1.106 29-Jan-2020  thorpej Adopt <net/if_stats.h>.
 1.105 28-May-2019  msaitoh branches: 1.105.4;
Use ETHER_LOCK()/ETHER_UNLOCK() for all ethernet drivers to protect ec_multi*.
 1.104 23-May-2019  msaitoh Whitespace fix (mainly tabify).
 1.103 23-May-2019  msaitoh No functional change:
- Simplify MII structure initialization and reference.
- u_int*_t -> uint*_t.
- KNF
 1.102 05-Feb-2019  msaitoh Remove very old IFF_NOTRAILERS flag.
 1.101 22-Jan-2019  msaitoh Change MII PHY read/write API from:

int (*mii_readreg_t)(device_t, int, int);
void (*mii_writereg_t)(device_t, int, int, int);
to:

int (*mii_readreg_t)(device_t, int, int, uint16_t *);
int (*mii_writereg_t)(device_t, int, int, uint16_t);

Now we can test if a read/write operation failed or not by the return value.

In 802.3 spec says that the PHY shall not respond to read/write transaction
to the unimplemented register(22.2.4.3). Detecting timeout can be used to
check whether a register is implemented or not (if the register conforms to
the spec). ukphy(4) can be used this for MII_MMDACR and MII_MMDAADR.

Note that I noticed that the following code do infinite loop in the
read/wirte function. If it accesses unimplemented PHY register, it will hang.
It should be fixed:

arm/at91/at91emac.c
arm/ep93xx/epe.c
arm/omap/omapl1x_emac.c
mips/ralink/ralink_eth.c
arch/powerpc/booke/dev/pq3etsec.c(read)
dev/cadence/if_cemac.c <- hkenken
dev/ic/lan9118.c


Tested with the following device:

axe+ukphy
axe+rgephy
axen+rgephy (tested by Andrius V)
wm+atphy
wm+ukphy
wm+igphy
wm+ihphy
wm+makphy
sk+makphy
sk+brgphy
sk+gentbi
msk+makphy
sip+icsphy
sip+ukphy
re+rgephy
bge+brgphy
bnx+brgphy
gsip+gphyter
rtk+rlphy
fxp+inphy (tested by Andrius V)
tlp+acphy
ex+exphy
epic+qsphy
vge+ciphy (tested by Andrius V)
vr+ukphy (tested by Andrius V)
vte+ukphy (tested by Andrius V)

Not tested (MAC):
arm:at91emac
arm:cemac
arm:epe
arm:geminigmac
arm:enet
arm:cpsw
arm:emac(omac)
arm:emac(sunxi)
arm:npe
evbppc:temac
macppc:bm
macppc:gm
mips:aumac
mips:ae
mips:cnmac
mips:reth
mips:sbmac
playstation2:smap
powerpc:tsec
powerpc:emac(ibm4xx)
sgimips:mec
sparc:be
sf
ne(ax88190, dl10019)
awge
ep
gem
hme
smsh
mtd
sm
age
alc
ale
bce
cas
et
jme
lii
nfe
pcn
ste
stge
tl
xi
aue
mue
smsc
udav
url

Not tested (PHY):
amhphy
bmtphy
dmphy
etphy
glxtphy
ikphy
iophy
lxtphy
nsphyter
pnaphy
rdcphy
sqphy
tlphy
tqphy
urlphy
 1.100 03-Sep-2018  riastradh Rename min/max -> uimin/uimax for better honesty.

These functions are defined on unsigned int. The generic name
min/max should not silently truncate to 32 bits on 64-bit systems.
This is purely a name change -- no functional change intended.

HOWEVER! Some subsystems have

#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))

even though our standard name for that is MIN/MAX. Although these
may invite multiple evaluation bugs, these do _not_ cause integer
truncation.

To avoid `fixing' these cases, I first changed the name in libkern,
and then compile-tested every file where min/max occurred in order to
confirm that it failed -- and thus confirm that nothing shadowed
min/max -- before changing it.

I have left a handful of bootloaders that are too annoying to
compile-test, and some dead code:

cobalt ews4800mips hp300 hppa ia64 luna68k vax
acorn32/if_ie.c (not included in any kernels)
macppc/if_gm.c (superseded by gem(4))

It should be easy to fix the fallout once identified -- this way of
doing things fails safe, and the goal here, after all, is to _avoid_
silent integer truncations, not introduce them.

Maybe one day we can reintroduce min/max as type-generic things that
never silently truncate. But we should avoid doing that for a while,
so that existing code has a chance to be detected by the compiler for
conversion to uimin/uimax without changing the semantics until we can
properly audit it all. (Who knows, maybe in some cases integer
truncation is actually intended!)
 1.99 26-Jun-2018  msaitoh branches: 1.99.2;
Implement the BPF direction filter (BIOC[GS]DIRECTION). It provides backward
compatibility with BIOC[GS]SEESENT ioctl. The userland interface is the same
as FreeBSD.

This change also fixes a bug that the direction is misunderstand on some
environment by passing the direction to bpf_mtap*() instead of checking
m->m_pkthdr.rcvif.
 1.98 22-Jun-2018  msaitoh It's not required to include net/bpfdesc.h. Remove it.
 1.97 08-May-2018  pgoyette Fix mis-placed right paren. kern/53271
 1.96 23-May-2017  ozaki-r branches: 1.96.2; 1.96.8;
Apply deferred if_start to more drivers

And annotate some XXX_start as it runs in softint to clarify that
it doesn't need deferred if_start.
 1.95 15-Dec-2016  ozaki-r Move bpf_mtap and if_ipackets++ on Rx of each driver to percpuq if_input

The benefits of the change are:
- We can reduce codes
- We can provide the same behavior between drivers
- Where/When if_ipackets is counted up
- Note that some drivers still update packet statistics in their own
way (periodical update)
- Moved bpf_mtap run in softint
- This makes it easy to MP-ify bpf

Proposed on tech-kern and tech-net
 1.94 02-Oct-2016  christos MFREE -> m_free
 1.93 10-Jun-2016  ozaki-r branches: 1.93.2;
Introduce m_set_rcvif and m_reset_rcvif

The API is used to set (or reset) a received interface of a mbuf.
They are counterpart of m_get_rcvif, which will come in another
commit, hide internal of rcvif operation, and reduce the diff of
the upcoming change.

No functional change.
 1.92 09-Feb-2016  ozaki-r Introduce softint-based if_input

This change intends to run the whole network stack in softint context
(or normal LWP), not hardware interrupt context. Note that the work is
still incomplete by this change; to that end, we also have to softint-ify
if_link_state_change (and bpf) which can still run in hardware interrupt.

This change softint-ifies at ifp->if_input that is called from
each device driver (and ieee80211_input) to ensure Layer 2 runs
in softint (e.g., ether_input and bridge_input). To this end,
we provide a framework (called percpuq) that utlizes softint(9)
and percpu ifqueues. With this patch, rxintr of most drivers just
queues received packets and schedules a softint, and the softint
dequeues packets and does rest packet processing.

To minimize changes to each driver, percpuq is allocated in struct
ifnet for now and that is initialized by default (in if_attach).
We probably have to move percpuq to softc of each driver, but it's
future work. At this point, only wm(4) has percpuq in its softc
as a reference implementation.

Additional information including performance numbers can be found
in the thread at tech-kern@ and tech-net@:
http://mail-index.netbsd.org/tech-kern/2016/01/14/msg019997.html

Acknowledgment: riastradh@ greatly helped this work.
Thank you very much!
 1.91 13-Apr-2015  riastradh Convert sys/dev to use <sys/rndsource.h>.
 1.90 10-Aug-2014  tls branches: 1.90.2; 1.90.4;
Merge tls-earlyentropy branch into HEAD.
 1.89 22-Jul-2012  matt branches: 1.89.2; 1.89.12;
Fix mii_statchg to take a 'struct ifnet *' instead of device_t. This fixes
problem with a common MDIO bus used for multiple interfaces.
Some drivers converted to CFATTACL_DECL_NEW.
 1.88 24-Jun-2012  jdc PR kern/46424
Revert the part of revision 1.77 that altered the PHY attachment order.
 1.87 02-Feb-2012  tls branches: 1.87.2;
Entropy-pool implementation move and cleanup.

1) Move core entropy-pool code and source/sink/sample management code
to sys/kern from sys/dev.

2) Remove use of NRND as test for presence of entropy-pool code throughout
source tree.

3) Remove use of RND_ENABLED in device drivers as microoptimization to
avoid expensive operations on disabled entropy sources; make the
rnd_add calls do this directly so all callers benefit.

4) Fix bug in recent rnd_add_data()/rnd_add_uint32() changes that might
have lead to slight entropy overestimation for some sources.

5) Add new source types for environmental sensors, power sensors, VM
system events, and skew between clocks, with a sample implementation
for each.

ok releng to go in before the branch due to the difficulty of later
pullup (widespread #ifdef removal and moved files). Tested with release
builds on amd64 and evbarm and live testing on amd64.
 1.86 05-Apr-2010  joerg branches: 1.86.8; 1.86.12;
Push the bpf_ops usage back into bpf.h. Push the common ifp->if_bpf
check into the inline functions as well the fourth argument for
bpf_attach.
 1.85 19-Jan-2010  pooka branches: 1.85.2; 1.85.4;
Redefine bpf linkage through an always present op vector, i.e.
#if NBPFILTER is no longer required in the client. This change
doesn't yet add support for loading bpf as a module, since drivers
can register before bpf is attached. However, callers of bpf can
now be modularized.

Dynamically loadable bpf could probably be done fairly easily with
coordination from the stub driver and the real driver by registering
attachments in the stub before the real driver is loaded and doing
a handoff. ... and I'm not going to ponder the depths of unload
here.

Tested with i386/MONOLITHIC, modified MONOLITHIC without bpf and rump.
 1.84 03-Nov-2009  jakllsch Use hme_init() to provide a non-NULL ifp->if_init.
 1.83 19-Sep-2009  tsutsui Use common ether_crc32_le() for multicast hash.
 1.82 18-Sep-2009  tsutsui hme_reset() is no longer called from bus attachments so make it static.
 1.81 08-Sep-2009  tsutsui Make local functions static and remove a declaration that is also in hmevar.h.
Also comment out or remove declarations for #if 0'ed or nonexistent functions.
 1.80 08-Sep-2009  tsutsui - split out chip reset ops from hme_stop() into a new function
hme_chipreset() to make hme_stop() match struct ifnet API
- set ifp->if_timer in hme_start() if any TX packets are queued
- also clear ifp->if_timer and ifp->if_flags in hme_stop()
- replace shutdownhook_establish(9) with pmf_device_reigster1(9)
Briefly checked hme at pci.
 1.79 17-May-2009  tsutsui Split device_t/softc.
Tested PCI HME on i386. Sbus HME is compile test only.
 1.78 12-May-2009  cegger struct device * -> device_t, no functional changes intended.
 1.77 06-May-2009  jdc Check for internal PHY first, so that it always attaches first, even when
we have an MII transeiver attached.
Count all collision and error counters.
Handle counter overflow and RXTERR.

Tested on U60 HME, PCI HME (501-5019) and SBus Sunswift (501-2739)
 1.76 16-Apr-2009  tsutsui Some cosmetics in rxcsum code. Tested on i386.
 1.75 16-Apr-2009  tsutsui u_intNN_t -> uintNN_t
 1.74 29-Mar-2009  tsutsui Don't assume all RX packets have VLAN headers even if vlanif is configured.
Instead, always check ether_type and use appropriate offsets to adjust
the hardware RX sum value.

XXX: vlan(4) doesn't seem to use csum_data and csum_flags in mbufs anyway.
 1.73 16-Mar-2009  tsutsui Fix a bug in calculation of checksum deduction:
- To get 16 bit one's complement value from uint32_t variable,
higher 16 bits should be ignored.
- RFC 1624 describes methods to recalculate checksum field in headers,
i.e. one's complement of one's complement sum that could be 0x0000,
but we don't have to use the strategy to deduct one's complement sum
itself which won't be zero but should be 0xffff.

Found on debugging mec(4) on sgimips O2.
 1.72 14-Mar-2009  dsl ANSIfy another 1261 function definitions.
The only ones left in sys are beyond by sed script!
(or in sys/dist or sys/external)
Mostly they have function pointer parameters.
 1.71 14-Mar-2009  dsl Change about 4500 of the K&R function definitions to ANSI ones.
There are still about 1600 left, but they have ',' or /* ... */
in the actual variable definitions - which my awk script doesn't handle.
There are also many that need () -> (void).
(The script does handle misordered arguments.)
 1.70 07-Mar-2009  tsutsui Replace incorrect local ether_cmp() function with memcmp(9)
on checking multicast addresses, which is not so critical.
Noticed by FUKAUMI Naoki.
 1.69 07-Mar-2009  tsutsui Add an `else' missed in rev 1.49 otherwise RX hardware checksum on hme(4)
is not activated at all. Ok'ed by christos@, tested on macppc.
 1.68 16-Dec-2008  christos branches: 1.68.2;
replace bitmask_snprintf(9) with snprintb(3)
 1.67 07-Nov-2008  dyoung *** Summary ***

When a link-layer address changes (e.g., ifconfig ex0 link
02:de:ad:be:ef:02 active), send a gratuitous ARP and/or a Neighbor
Advertisement to update the network-/link-layer address bindings
on our LAN peers.

Refuse a change of ethernet address to the address 00:00:00:00:00:00
or to any multicast/broadcast address. (Thanks matt@.)

Reorder ifnet ioctl operations so that driver ioctls may inherit
the functions of their "class"---ether_ioctl(), fddi_ioctl(), et
cetera---and the class ioctls may inherit from the generic ioctl,
ifioctl_common(), but both driver- and class-ioctls may override
the generic behavior. Make network drivers share more code.

Distinguish a "factory" link-layer address from others for the
purposes of both protecting that address from deletion and computing
EUI64.

Return consistent, appropriate error codes from network drivers.

Improve readability. KNF.

*** Details ***

In if_attach(), always initialize the interface ioctl routine,
ifnet->if_ioctl, if the driver has not already initialized it.
Delete if_ioctl == NULL tests everywhere else, because it cannot
happen.

In the ioctl routines of network interfaces, inherit common ioctl
behaviors by calling either ifioctl_common() or whichever ioctl
routine is appropriate for the class of interface---e.g., ether_ioctl()
for ethernets.

Stop (ab)using SIOCSIFADDR and start to use SIOCINITIFADDR. In
the user->kernel interface, SIOCSIFADDR's argument was an ifreq,
but on the protocol->ifnet interface, SIOCSIFADDR's argument was
an ifaddr. That was confusing, and it would work against me as I
make it possible for a network interface to overload most ioctls.
On the protocol->ifnet interface, replace SIOCSIFADDR with
SIOCINITIFADDR. In ifioctl(), return EPERM if userland tries to
invoke SIOCINITIFADDR.

In ifioctl(), give the interface the first shot at handling most
interface ioctls, and give the protocol the second shot, instead
of the other way around. Finally, let compatibility code (COMPAT_OSOCK)
take a shot.

Pull device initialization out of switch statements under
SIOCINITIFADDR. For example, pull ..._init() out of any switch
statement that looks like this:

switch (...->sa_family) {
case ...:
..._init();
...
break;
...
default:
..._init();
...
break;
}

Rewrite many if-else clauses that handle all permutations of IFF_UP
and IFF_RUNNING to use a switch statement,

switch (x & (IFF_UP|IFF_RUNNING)) {
case 0:
...
break;
case IFF_RUNNING:
...
break;
case IFF_UP:
...
break;
case IFF_UP|IFF_RUNNING:
...
break;
}

unifdef lots of code containing #ifdef FreeBSD, #ifdef NetBSD, and
#ifdef SIOCSIFMTU, especially in fwip(4) and in ndis(4).

In ipw(4), remove an if_set_sadl() call that is out of place.

In nfe(4), reuse the jumbo MTU logic in ether_ioctl().

Let ethernets register a callback for setting h/w state such as
promiscuous mode and the multicast filter in accord with a change
in the if_flags: ether_set_ifflags_cb() registers a callback that
returns ENETRESET if the caller should reset the ethernet by calling
if_init(), 0 on success, != 0 on failure. Pull common code from
ex(4), gem(4), nfe(4), sip(4), tlp(4), vge(4) into ether_ioctl(),
and register if_flags callbacks for those drivers.

Return ENOTTY instead of EINVAL for inappropriate ioctls. In
zyd(4), use ENXIO instead of ENOTTY to indicate that the device is
not any longer attached.

Add to if_set_sadl() a boolean 'factory' argument that indicates
whether a link-layer address was assigned by the factory or some
other source. In a comment, recommend using the factory address
for generating an EUI64, and update in6_get_hw_ifid() to prefer a
factory address to any other link-layer address.

Add a routing message, RTM_LLINFO_UPD, that tells protocols to
update the binding of network-layer addresses to link-layer addresses.
Implement this message in IPv4 and IPv6 by sending a gratuitous
ARP or a neighbor advertisement, respectively. Generate RTM_LLINFO_UPD
messages on a change of an interface's link-layer address.

In ether_ioctl(), do not let SIOCALIFADDR set a link-layer address
that is broadcast/multicast or equal to 00:00:00:00:00:00.

Make ether_ioctl() call ifioctl_common() to handle ioctls that it
does not understand.

In gif(4), initialize if_softc and use it, instead of assuming that
the gif_softc and ifp overlap.

Let ifioctl_common() handle SIOCGIFADDR.

Sprinkle rtcache_invariants(), which checks on DIAGNOSTIC kernels
that certain invariants on a struct route are satisfied.

In agr(4), rewrite agr_ioctl_filter() to be a bit more explicit
about the ioctls that we do not allow on an agr(4) member interface.

bzero -> memset. Delete unnecessary casts to void *. Use
sockaddr_in_init() and sockaddr_in6_init(). Compare pointers with
NULL instead of "testing truth". Replace some instances of (type
*)0 with NULL. Change some K&R prototypes to ANSI C, and join
lines.
 1.66 04-May-2008  xtraeme branches: 1.66.6; 1.66.8; 1.66.10; 1.66.14;
device_t/softc split for all mii(4) devices, and other related
cosmetic changes.
 1.65 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.64 08-Apr-2008  cegger branches: 1.64.2; 1.64.4;
use aprint_*_dev and device_xname
 1.63 07-Feb-2008  dyoung branches: 1.63.6;
Start patching up the kernel so that a network driver always has
the opportunity to handle an ioctl before generic ifioctl handling
occurs. This will ease extending the kernel and sharing of code
between drivers.

First steps: Make the signature of ifioctl_common() match struct
ifinet->if_ioctl. Convert SIOCSIFCAP and SIOCSIFMTU to the new
ifioctl() regime, throughout the kernel.
 1.62 21-Jan-2008  dyoung Remove an unnecessary check that yields a spurious EINVAL during
initialization.
 1.61 19-Jan-2008  dyoung Make many ethernet drivers share the common code for MII media
handling, ether_mediastatus() and ether_mediachange(). Check for
a non-ENXIO error return from mii_mediachg(). (ENXIO indicates
that a PHY is suspended.)

This patch shrinks the source code size by 979 lines. There was
a 5100-byte savings on the NetBSD/i386 kernel configuration, ALL.

I have made a few miscellaneous changes, too:

gem(4): use LIST_EMPTY(), LIST_FOREACH().
mtd(4): handle media ioctls, for a change!
axe(4): do not track link status in sc->axe_link any longer
nfe(4), aue(4), axe(4), udav(4), url(4): do not reset all PHYs
on a change of media

Except for the change to mtd(4), no functional changes are intended.

XXX This patch affects more architectures than I can feasibly
XXX compile and run. I have compiled macppc, sparc64, i386. I
XXX have run the patches on i386 boxen with bnx(4) and sip(4).
XXX Compiling and running on evbmips (MERAKI, ADM5120) is in
XXX progress.
 1.60 19-Oct-2007  ad branches: 1.60.2; 1.60.8;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.59 01-Sep-2007  dyoung branches: 1.59.4;
Change a bazillion occurrences of code resembling this,

error = (cmd == SIOCADDMULTI) ?
ether_addmulti(ifr, &sc->sc_ec) :
ether_delmulti(ifr, &sc->sc_ec);

if (error == ENETRESET) {

to this,

if ((error = ether_ioctl(ifp, cmd, data)) == ENETRESET) {

which does the same thing.

(A bazillion is a very large number. This seems to make the i386
ALL kernel smaller by 3kB to 4kB.)

Use ifreq_getaddr() twice in es(4).

Whitespace nits.
 1.58 12-Jul-2007  martin branches: 1.58.2; 1.58.6; 1.58.8;
Do not stop a callout before it is initialized.
 1.57 09-Jul-2007  ad Merge some of the less invasive changes from the vmlocking branch:

- kthread, callout, devsw API changes
- select()/poll() improvements
- miscellaneous MT safety improvements
 1.56 04-Mar-2007  christos branches: 1.56.2; 1.56.4;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.55 24-Nov-2006  christos branches: 1.55.4;
fix spelling of accommodate; from Zapher.
 1.54 07-Sep-2006  dogcow branches: 1.54.2; 1.54.4;
remove more vestiges of CCITT, LLC, HDLC, NS, and NSIP.
 1.53 24-Dec-2005  perry branches: 1.53.4; 1.53.8;
__inline__ -> inline
 1.52 11-Dec-2005  christos merge ktrace-lwp.
 1.51 02-May-2005  yamt branches: 1.51.2;
split IFCAP_CSUM_xxx to IFCAP_CSUM_xxx_Rx and IFCAP_CSUM_xxx_Tx.
 1.50 17-Mar-2005  rafal Fix typo in HW checksum code -- check for TCP & UDP HW checksumming being
enabled rather than TCP twice.
 1.49 05-Mar-2005  heas branches: 1.49.2;
Perform a s/w checksum for packets that are not the same length as the length
field of the IP header (ip->ip-len) indicates they should be. This handles
the case where an ethernet frame has been padded to meet the minimum ethernet
frame length or erroneously (my cisco switch unnecessarily adds 4 bytes to its
SYN). This padding will be included in the hardware checksum and may be
non-zero, thus making it incorrect.
Also, clear csum_flags when we want a s/w checksum, since we may have started
down the h/w checksum path and determined that it was not usable.

While here, clean-up a few WS nits and ifdef INET the hardware checksum code.
 1.48 27-Feb-2005  perry nuke trailing whitespace
 1.47 21-Feb-2005  thorpej Define M_CSUM_DATA_IPv4_IPHL() and M_CSUM_DATA_IPv4_OFFSET() macros
to extract data from csum_data, rather than just open-coding it.
 1.46 18-Feb-2005  heas Add handling for hardware TCP/UDP checksums.
 1.45 18-Feb-2005  heas Handle interface IFF_DEBUG flags sooner in hme_ioctl and cache a copy of
sc_ethercom.ec_capenable such that we can properly adjust the max frame size
when vlan tagging is enabled/disabled.
 1.44 04-Feb-2005  perry de-__P
 1.43 30-Oct-2004  thorpej branches: 1.43.4; 1.43.6;
When adding/deleting multicast addresses, only whack the address
filter if the interface is marked RUNNING.

Fixes kern/27678.
 1.42 26-Oct-2004  heas GC some trailing WS.
 1.41 28-Jun-2004  heas do not reset the chip (and subsequently the phy) when unnecessary; that is,
for address changes, multicast filter changes, or adjusting promiscuous mode.
Fixes resetting the phy for things like start/stopping tcpdump.

ok petrov@, martin@, pk@
 1.40 21-Jan-2004  abs branches: 1.40.4;
If we are explicitly asked for entropy, provide it.
 1.39 03-Nov-2003  petrov Do not set HMEDEBUG as default mode.
 1.38 02-Nov-2003  wiz Fix some typos. From Tom Cosgrove via jmc@openbsd.
 1.37 03-May-2003  wiz branches: 1.37.2;
DMA, not dma nor Dma.
 1.36 26-Apr-2003  wiz Management, not managment. Mostly from jmc@openbsd.
 1.35 27-Feb-2003  pk Enable the MII output drivers in hme_mifinit() based on the currently
selected transceiver. Save and restore this setting in hme_mii_readreg()
and hme_mii_writereg().
 1.34 20-Feb-2003  petrov Use MIIF_FORCEANEG.
 1.33 13-Feb-2003  pk Preserve the current PHY select bit in the MIF configuration register
in mii_readreg()/mii_writereg(). Also restore this bit based on the
currently selected media instance every time we need to reinitialise
the interface.
 1.32 18-Dec-2002  martin Since we have to select one of the two possible PHYs when configuring
the MIF Configuration Register PHY_Select, there is no use in pretending
we could talk to both at the MII interface layer.

If both PHY are reported to be present, prefer the external one.

Remember this selection and enforce it in hme_mii_{read,write}reg.
This fixes problems with one of the dual hmes in Netra T1s.

From OpenBSD.
 1.31 22-Oct-2002  fair Change the "dontcare bits" argument to ifmedia_init() to IFM_IMASK
so that it is possible select PHY instances other than the first
one (instance zero), if there is more than one PHY attached.
 1.30 29-Aug-2002  martin Experimentation shows the hme chip is SIMPLEX if used in full-duplex
mode, but not otherwise.

This fixes PR 17523.
 1.29 05-May-2002  thorpej branches: 1.29.2;
hme_init(): call mii_mediachg() to make sure the current media is set.
 1.28 26-Nov-2001  tron Back out new "hme" driver because it causes a performance regression on
"netio" on an U5.
 1.27 26-Nov-2001  tron Bug fixes for VLAN handling supplied by Klaus Klein in private e-mail.
 1.26 25-Nov-2001  tron Pull in Jason Wright's latest changes to the "hme" driver from OpenBSD.
This supports direct DMA from and into mbuf cluster, and VLAN
handling is done a bit differently.
 1.25 13-Nov-2001  lukem add/cleanup RCSID
 1.24 22-Oct-2001  mrg fix a typo in the previous
 1.23 22-Oct-2001  mrg increase the value of _HME_NDESC from 32 to 128. it reduces the noise the
driver makes due to various bad status conditions.
 1.22 05-Oct-2001  thorpej Minor tidying up of the HME driver attach:
- Print nicer-looking message.
- Use bus_space_subregion() when appropriate, rather than arithmetic
on a bus_space_handle_t.
 1.21 07-Jul-2001  thorpej branches: 1.21.2; 1.21.4;
bcopy -> memcpy, strcpy
 1.20 14-Dec-2000  thorpej branches: 1.20.2;
ALTQ'ify.
 1.19 17-Nov-2000  bouyer Supports ETHERCAP_VLAN_MTU. Tested on sbus hme on Ultra/1.
Thanks to Andrei Petrov for the hint !
 1.18 15-Nov-2000  thorpej Move bpfattach()/bpfdetach() calls into ether_ifattach()/ether_ifdetach().
 1.17 20-Oct-2000  mrg ensure DMA mappings are not mapped streamable. fixes ethernet problems on
ultrasparc sbus class machines. from eeh.
 1.16 01-Oct-2000  thorpej Move the check for "promisc + unicast + not for us" into ether_input(),
and change Ethernet drivers to always pass all received frames to
ether_input() (with a few exceptions, which are documented in the
code).
 1.15 25-Jun-2000  eeh Get PCI HME working.
 1.14 15-Jun-2000  pk branches: 1.14.2;
Turn on the hash filter enable bit in the RX configuration register
when loading the multicast hash filter (noted by itojun@iijlab.net).
 1.13 18-May-2000  mrg branches: 1.13.2;
rearrange the order of bus_dma operations to be more like many other
drivers, at the suggestion of fvdl. also, use bus_dmamap_load() not
load_raw().
 1.12 18-May-2000  mrg do not pass a `boundary' argument to bus_dmamap_create(), particularly one
that is smaller than the `size' argument.
 1.11 09-May-2000  pk Conform bus_dmamem_{alloc,map} usage to bus_dma(9) specs.
 1.10 05-Apr-2000  mrg return if we can't map DMA buffers
 1.9 23-Mar-2000  thorpej New callout mechanism with two major improvements over the old
timeout()/untimeout() API:
- Clients supply callout handle storage, thus eliminating problems of
resource allocation.
- Insertion and removal of callouts is constant time, important as
this facility is used quite a lot in the kernel.

The old timeout()/untimeout() API has been removed from the kernel.
 1.8 14-Feb-2000  pk Bump receive buffer size up to the maximum DMA burst boundary.
 1.7 02-Feb-2000  thorpej Don't dry to diving MIIF_NOISOLATE in the PHY drivers. Instead, pass
flags down from the parent to child vi mii_attach().
 1.6 02-Feb-2000  thorpej Bring some order to the chaos which was the MII code function naming
"conventions".
 1.5 18-Dec-1999  pk Add support for selecting a PHY (i.e. built-in transceiver vs. external MII
device) by using media/instance parameters.
 1.4 17-Dec-1999  pk Avoid feeding negative values to the `roundup()' macro.
Configure the MII management interface earlier.
 1.3 15-Dec-1999  pk Correctly encode the configured number of buffer descriptors.
 1.2 14-Dec-1999  pk * Probe the MII device.
* Ask for an interesting set of interrupt conditions.
* Correct various other typos and omissions.
 1.1 27-Jun-1999  pk branches: 1.1.2; 1.1.4; 1.1.10;
HME ethernet driver.
Note: this is work in progress; needs testing and tweaking. mgr has
promised to do that..
 1.1.10.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.1.4.3 05-Jan-2001  bouyer Sync with HEAD
 1.1.4.2 22-Nov-2000  bouyer Sync with HEAD.
 1.1.4.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.1.2.2 01-Jul-1999  thorpej Sync w/ -current.
 1.1.2.1 27-Jun-1999  thorpej file hme.c was added on branch chs-ubc2 on 1999-07-01 23:32:27 +0000
 1.13.2.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.14.2.2 25-Oct-2000  tv Pullup 1.17 [mrg]:
ensure DMA mappings are not mapped streamable. fixes ethernet problems on
ultrasparc sbus class machines. from eeh.
 1.14.2.1 31-Jul-2000  mrg pull up 1.15 (approved by thorpej):
>Get PCI HME working.
 1.20.2.8 19-Dec-2002  thorpej Sync with HEAD.
 1.20.2.7 11-Nov-2002  nathanw Catch up to -current
 1.20.2.6 17-Sep-2002  nathanw Catch up to -current.
 1.20.2.5 20-Jun-2002  nathanw Catch up to -current.
 1.20.2.4 08-Jan-2002  nathanw Catch up to -current.
 1.20.2.3 14-Nov-2001  nathanw Catch up to -current.
 1.20.2.2 22-Oct-2001  nathanw Catch up to -current.
 1.20.2.1 24-Aug-2001  nathanw Catch up with -current.
 1.21.4.1 11-Oct-2001  fvdl Catch up with -current. Fix some bogons in the sparc64 kbd/ms
attach code. cd18xx conversion provided by mrg.
 1.21.2.3 06-Sep-2002  jdolecek sync kqueue branch with HEAD
 1.21.2.2 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.21.2.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.29.2.1 31-Aug-2002  gehenna catch up with -current.
 1.37.2.9 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.37.2.8 01-Apr-2005  skrll Sync with HEAD.
 1.37.2.7 08-Mar-2005  skrll Sync with HEAD.
 1.37.2.6 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.37.2.5 04-Feb-2005  skrll Sync with HEAD.
 1.37.2.4 02-Nov-2004  skrll Sync with HEAD.
 1.37.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.37.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.37.2.1 03-Aug-2004  skrll Sync with HEAD
 1.40.4.1 24-Jan-2005  he Pull up revision 1.43 (requested by thorpej in ticket #939):
When adding or deleting multicast addresses, only change
the address filter if the interface is marked RUNNING.
Fixes PR#27678.
 1.43.6.2 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.43.6.1 12-Feb-2005  yamt sync with head.
 1.43.4.1 29-Apr-2005  kent sync with -current
 1.49.2.1 27-May-2007  bouyer Pull up following revision(s) (requested by hubertf in ticket #1774):
sys/dev/ic/hme.c: revision 1.50
Fix typo in HW checksum code -- check for TCP & UDP HW checksumming being
enabled rather than TCP twice.
 1.51.2.7 11-Feb-2008  yamt sync with head.
 1.51.2.6 04-Feb-2008  yamt sync with head.
 1.51.2.5 21-Jan-2008  yamt sync with head
 1.51.2.4 27-Oct-2007  yamt sync with head.
 1.51.2.3 03-Sep-2007  yamt sync with head.
 1.51.2.2 30-Dec-2006  yamt sync with head.
 1.51.2.1 21-Jun-2006  yamt sync with head.
 1.53.8.1 14-Sep-2006  yamt sync with head.
 1.53.4.1 09-Sep-2006  rpaulo sync with head
 1.54.4.1 10-Dec-2006  yamt sync with head.
 1.54.2.1 12-Jan-2007  ad Sync with head.
 1.55.4.1 12-Mar-2007  rmind Sync with HEAD.
 1.56.4.1 11-Jul-2007  mjf Sync with head.
 1.56.2.4 23-Oct-2007  ad Sync with head.
 1.56.2.3 09-Oct-2007  ad Sync with head.
 1.56.2.2 15-Jul-2007  ad Sync with head.
 1.56.2.1 01-Jul-2007  ad Adapt to callout API change.
 1.58.8.2 23-Mar-2008  matt sync with HEAD
 1.58.8.1 06-Nov-2007  matt sync with HEAD
 1.58.6.2 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.58.6.1 03-Sep-2007  jmcneill Sync with HEAD.
 1.58.2.1 03-Sep-2007  skrll Sync with HEAD.
 1.59.4.1 25-Oct-2007  bouyer Sync with HEAD.
 1.60.8.2 23-Jan-2008  bouyer Sync with HEAD.
 1.60.8.1 20-Jan-2008  bouyer Sync with HEAD
 1.60.2.1 18-Feb-2008  mjf Sync with HEAD.
 1.63.6.2 17-Jan-2009  mjf Sync with HEAD.
 1.63.6.1 02-Jun-2008  mjf Sync with HEAD.
 1.64.4.7 11-Aug-2010  yamt sync with head.
 1.64.4.6 11-Mar-2010  yamt sync with head
 1.64.4.5 16-Sep-2009  yamt sync with head
 1.64.4.4 20-Jun-2009  yamt sync with head
 1.64.4.3 16-May-2009  yamt sync with head
 1.64.4.2 04-May-2009  yamt sync with head.
 1.64.4.1 16-May-2008  yamt sync with head.
 1.64.2.1 18-May-2008  yamt sync with head.
 1.66.14.1 21-Apr-2010  matt sync to netbsd-5
 1.66.10.4 13-Nov-2009  sborrill Pull up the following revisions(s) (requested by jakllsch in ticket #1133):
sys/dev/ic/hme.c: revision 1.84 via patch

Use hme_init() to provide a non-NULL ifp->if_init.
 1.66.10.3 01-May-2009  snj Pull up following revision(s) (requested by tsutsui in ticket #595):
sys/dev/ic/gem.c: revision 1.83
sys/dev/ic/hme.c: revision 1.73
Fix a bug in calculation of checksum deduction:
- To get 16 bit one's complement value from uint32_t variable,
higher 16 bits should be ignored.
- RFC 1624 describes methods to recalculate checksum field in headers,
i.e. one's complement of one's complement sum that could be 0x0000,
but we don't have to use the strategy to deduct one's complement sum
itself which won't be zero but should be 0xffff.
Found on debugging mec(4) on sgimips O2.
 1.66.10.2 01-May-2009  snj Pull up following revision(s) (requested by tsutsui in ticket #595):
sys/dev/ic/hme.c: revision 1.70
Replace incorrect local ether_cmp() function with memcmp(9)
on checking multicast addresses, which is not so critical.
Noticed by FUKAUMI Naoki.
 1.66.10.1 01-May-2009  snj Pull up following revision(s) (requested by tsutsui in ticket #595):
sys/dev/ic/hme.c: revision 1.69
Add an `else' missed in rev 1.49 otherwise RX hardware checksum on hme(4)
is not activated at all. Ok'ed by christos@, tested on macppc.
 1.66.8.2 28-Apr-2009  skrll Sync with HEAD.
 1.66.8.1 19-Jan-2009  skrll Sync with HEAD.
 1.66.6.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.68.2.2 23-Jul-2009  jym Sync with HEAD.
 1.68.2.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.85.4.1 30-May-2010  rmind sync with head
 1.85.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.86.12.1 18-Feb-2012  mrg merge to -current.
 1.86.8.2 30-Oct-2012  yamt sync with head
 1.86.8.1 17-Apr-2012  yamt sync with head
 1.87.2.2 14-May-2018  martin Pull up following revision(s) (requested by pgoyette in ticket #1548):

sys/dev/ic/hme.c: revision 1.97

Fix mis-placed right paren. kern/53271
 1.87.2.1 04-Jul-2012  riz Pull up following revision(s) (requested by jdc in ticket #368):
sys/dev/ic/hme.c: revision 1.88
share/man/man4/hme.4: revision 1.10
PR kern/46424
Revert the part of revision 1.77 that altered the PHY attachment order.
Note that the PHY instance changes when a MII transceiver is connected.
 1.89.12.1 07-Apr-2014  tls Be a little more clear and consistent about harvesting entropy from devices:

1) deprecate RND_FLAG_NO_ESTIMATE

2) define RND_FLAG_COLLECT_TIME, RND_FLAG_COLLECT_VALUE

3) define RND_FLAG_ESTIMATE_TIME, RND_FLAG_ESTIMATE_VALUE

4) define RND_FLAG_DEFAULT: RND_FLAG_COLLECT_TIME|
RND_FLAG_COLLECT_VALUE|RND_FLAG_ESTIMATE_TIME

5) Make entropy harvesting from environmental sensors a little more generic
and remove it from individual sensor drivers.

6) Remove individual open-coded delta-estimators for values from a few
places in the tree (uvm, environmental drivers).

7) 0 -> RND_FLAG_DEFAULT, actually gather entropy from various drivers
that had stubbed out code, other minor cleanups.
 1.89.2.2 03-Dec-2017  jdolecek update from HEAD
 1.89.2.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.90.4.6 28-Aug-2017  skrll Sync with HEAD
 1.90.4.5 05-Feb-2017  skrll Sync with HEAD
 1.90.4.4 05-Oct-2016  skrll Sync with HEAD
 1.90.4.3 09-Jul-2016  skrll Sync with HEAD
 1.90.4.2 19-Mar-2016  skrll Sync with HEAD
 1.90.4.1 06-Jun-2015  skrll Sync with HEAD
 1.90.2.1 14-May-2018  martin Pull up following revision(s) (requested by pgoyette in ticket #1604):

sys/dev/ic/hme.c: revision 1.97

Fix mis-placed right paren. kern/53271
 1.93.2.2 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.93.2.1 04-Nov-2016  pgoyette Sync with HEAD
 1.96.8.5 26-Jan-2019  pgoyette Sync with HEAD
 1.96.8.4 06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.96.8.3 28-Jul-2018  pgoyette Sync with HEAD
 1.96.8.2 25-Jun-2018  pgoyette Sync with HEAD
 1.96.8.1 21-May-2018  pgoyette Sync with HEAD
 1.96.2.2 26-Jul-2018  snj Pull up following revision(s) (requested by msaitoh in ticket #938):
sys/arch/acorn32/podulebus/if_ie.c: revision 1.41
sys/arch/amiga/dev/if_es.c: revision 1.58
sys/arch/amiga/dev/if_qn.c: revision 1.45
sys/arch/arm/at91/at91emac.c: revision 1.20
sys/arch/arm/ep93xx/epe.c: revision 1.37
sys/arch/emips/ebus/if_le_ebus.c: revision 1.14
sys/arch/emips/ebus/if_le_ebus.c: revision 1.15
sys/arch/mac68k/dev/if_mc.c: revision 1.46
sys/arch/macppc/dev/am79c950.c: revision 1.39
sys/arch/newsmips/apbus/if_sn.c: revision 1.40
sys/arch/next68k/dev/mb8795.c: revision 1.59
sys/arch/playstation2/dev/if_smap.c: revision 1.25
sys/arch/playstation2/dev/if_smap.c: revision 1.26
sys/arch/sun2/dev/if_ec.c: revision 1.28
sys/arch/sun3/dev/if_ie.c: revision 1.63
sys/arch/x68k/dev/if_ne_intio.c: revision 1.19
sys/arch/xen/xen/if_xennet_xenbus.c: revision 1.75
sys/arch/xen/xen/xennetback_xenbus.c: revision 1.63
sys/dev/bi/if_ni.c: revision 1.45
sys/dev/cadence/if_cemac.c: revision 1.12
sys/dev/ic/am7990.c: revision 1.78
sys/dev/ic/am79900.c: revision 1.27
sys/dev/ic/an.c: revision 1.67
sys/dev/ic/cs89x0.c: revision 1.40
sys/dev/ic/dm9000.c: revision 1.13
sys/dev/ic/dm9000.c: revision 1.14
sys/dev/ic/dp8390.c: revision 1.88
sys/dev/ic/elink3.c: revision 1.141
sys/dev/ic/elinkxl.c: revision 1.122
sys/dev/ic/hme.c: revision 1.98
sys/dev/ic/i82586.c: revision 1.77
sys/dev/ic/lance.c: revision 1.53
sys/dev/ic/mb86950.c: revision 1.27
sys/dev/ic/mb86960.c: revision 1.86
sys/dev/ic/mtd803.c: revision 1.34
sys/dev/ic/pdq_ifsubr.c: revision 1.59
sys/dev/ic/rrunner.c: revision 1.86
sys/dev/ic/seeq8005.c: revision 1.58
sys/dev/ic/sgec.c: revision 1.47
sys/dev/ic/smc90cx6.c: revision 1.72
sys/dev/ic/smc91cxx.c: revision 1.96
sys/dev/ic/tropic.c: revision 1.49
sys/dev/ic/wi.c: revision 1.245
sys/dev/isa/if_eg.c: revision 1.93
sys/dev/isa/if_el.c: revision 1.95
sys/dev/isa/if_iy.c: revision 1.101
sys/dev/ofw/ofnet.c: revision 1.58
sys/dev/pci/if_alc.c: revision 1.27
sys/dev/pci/if_de.c: revision 1.152
sys/dev/pci/if_fpa.c: revision 1.61
sys/dev/pci/if_jme.c: revision 1.34
sys/dev/pci/if_tl.c: revision 1.108
sys/dev/pci/if_vte.c: revision 1.19
sys/dev/pci/ixgbe/ixgbe.h: revision 1.50
sys/dev/pcmcia/if_cnw.c: revision 1.62
sys/dev/pcmcia/if_malo_pcmcia.c: revision 1.17
sys/dev/pcmcia/if_ray.c: revision 1.89
sys/dev/pcmcia/if_xi.c: revision 1.81
sys/dev/pcmcia/mhzc.c: revision 1.51
sys/dev/pcmcia/xirc.c: revision 1.34
sys/dev/qbus/if_de.c: revision 1.33
sys/dev/qbus/if_qe.c: revision 1.78
sys/dev/qbus/if_qt.c: revision 1.22
sys/dev/sbus/be.c: revision 1.87
sys/dev/sbus/qe.c: revision 1.68
sys/dev/scsipi/if_se.c: revision 1.96
sys/dev/usb/if_atu.c: revision 1.59
sys/net/if_l2tp.c: revision 1.28 via patch
sys/net/if_ppp.c: revision 1.160
It's not required to include net/bpfdesc.h. Remove it.
--
Simplify like other drivers. NULL check of ifp->if_bpf is done in
bpf_mtap(), so it's not required to do it here.
--
Remove duplicated inclusion of net/bpf.h.
--
Remove duplicated inclusion of net/bpf.h.
--
Simplify bpf_mtap() call. No functional change.
 1.96.2.1 09-May-2018  martin Pull up following revision(s) (requested by pgoyette in ticket #815):

sys/dev/ic/hme.c: revision 1.97

Fix mis-placed right paren. kern/53271
 1.99.2.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.99.2.1 10-Jun-2019  christos Sync with HEAD
 1.105.4.1 29-Feb-2020  ad Sync with head.
 1.23 05-Feb-2024  andvar fix various typos in comments.
 1.22 07-May-2009  jdc Add extra counter definitions (pointed out by Geoff Wing).
 1.21 16-Apr-2009  tsutsui u_intNN_t -> uintNN_t
 1.20 28-Apr-2008  martin branches: 1.20.8; 1.20.14;
Remove clause 3 and 4 from TNF licenses
 1.19 04-Mar-2007  christos branches: 1.19.36; 1.19.38; 1.19.40;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.18 11-Dec-2005  christos branches: 1.18.26;
merge ktrace-lwp.
 1.17 13-Feb-2005  heas branches: 1.17.6;
Add register definitions for hardware checksums, comments, and formats for
various register bitmask_snprintfs.
 1.16 02-Nov-2003  wiz branches: 1.16.8; 1.16.10;
Fix some typos. From Tom Cosgrove via jmc@openbsd.
 1.15 02-Jun-2003  petrov branches: 1.15.2;
Fix the previous patch of me.
 1.14 14-May-2003  petrov Move DTIMEXP and RFIFOVF warnings under control of HMEDEBUG.
PR port-sparc64/20280 by grant beattie.
 1.13 03-May-2003  wiz DMA, not dma nor Dma.
 1.12 07-May-2002  uwe Delint. Add /* CONSTCOND */. Add parens to macro argument to avoid
interesting interaction between cc -C and comma inside a comment after
macro definition.
 1.11 26-Nov-2001  tron Back out new "hme" driver because it causes a performance regression on
"netio" on an U5.
 1.10 26-Nov-2001  tron Bug fixes for VLAN handling supplied by Klaus Klein in private e-mail.
 1.9 25-Nov-2001  tron Pull in Jason Wright's latest changes to the "hme" driver from OpenBSD.
This supports direct DMA from and into mbuf cluster, and VLAN
handling is done a bit differently.
 1.8 30-Apr-2001  bouyer branches: 1.8.2;
remplace /*
*/
with
#ifdef notdef
#endif
to avoid:
../../../../dev/ic/hmereg.h:275: warning: `/*' within comment
 1.7 30-Apr-2001  lukem delint
 1.6 17-Nov-2000  bouyer branches: 1.6.2;
Supports ETHERCAP_VLAN_MTU. Tested on sbus hme on Ultra/1.
Thanks to Andrei Petrov for the hint !
 1.5 25-Jun-2000  eeh Get PCI HME working.
 1.4 28-Jan-2000  pk branches: 1.4.4;
Define the fixed hme PHY addresses.
 1.3 17-Dec-1999  pk Fix status bit symbols strings.
Rename MII receives enable bit to be in sync with the STP2002 datasheet.
 1.2 14-Dec-1999  pk Add a missing register offset.
 1.1 27-Jun-1999  pk branches: 1.1.2; 1.1.4; 1.1.10;
HME ethernet driver.
Note: this is work in progress; needs testing and tweaking. mgr has
promised to do that..
 1.1.10.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.1.4.2 22-Nov-2000  bouyer Sync with HEAD.
 1.1.4.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.1.2.2 01-Jul-1999  thorpej Sync w/ -current.
 1.1.2.1 27-Jun-1999  thorpej file hmereg.h was added on branch chs-ubc2 on 1999-07-01 23:32:27 +0000
 1.4.4.1 31-Jul-2000  mrg pull up 1.5 (approved by thorpej):
>Get PCI HME working.
 1.6.2.3 20-Jun-2002  nathanw Catch up to -current.
 1.6.2.2 08-Jan-2002  nathanw Catch up to -current.
 1.6.2.1 21-Jun-2001  nathanw Catch up to -current.
 1.8.2.2 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.8.2.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.15.2.4 15-Feb-2005  skrll Sync with HEAD.
 1.15.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.15.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.15.2.1 03-Aug-2004  skrll Sync with HEAD
 1.16.10.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.16.8.1 29-Apr-2005  kent sync with -current
 1.17.6.1 03-Sep-2007  yamt sync with head.
 1.18.26.1 12-Mar-2007  rmind Sync with HEAD.
 1.19.40.3 16-May-2009  yamt sync with head
 1.19.40.2 04-May-2009  yamt sync with head.
 1.19.40.1 16-May-2008  yamt sync with head.
 1.19.38.1 18-May-2008  yamt sync with head.
 1.19.36.1 02-Jun-2008  mjf Sync with HEAD.
 1.20.14.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.20.8.1 28-Apr-2009  skrll Sync with HEAD.
 1.24 13-Apr-2015  riastradh Convert sys/dev to use <sys/rndsource.h>.
 1.23 02-Feb-2012  tls branches: 1.23.6; 1.23.24;
Entropy-pool implementation move and cleanup.

1) Move core entropy-pool code and source/sink/sample management code
to sys/kern from sys/dev.

2) Remove use of NRND as test for presence of entropy-pool code throughout
source tree.

3) Remove use of RND_ENABLED in device drivers as microoptimization to
avoid expensive operations on disabled entropy sources; make the
rnd_add calls do this directly so all callers benefit.

4) Fix bug in recent rnd_add_data()/rnd_add_uint32() changes that might
have lead to slight entropy overestimation for some sources.

5) Add new source types for environmental sensors, power sensors, VM
system events, and skew between clocks, with a sample implementation
for each.

ok releng to go in before the branch due to the difficulty of later
pullup (widespread #ifdef removal and moved files). Tested with release
builds on amd64 and evbarm and live testing on amd64.
 1.22 19-Nov-2011  tls branches: 1.22.2;
First step of random number subsystem rework described in
<20111022023242.BA26F14A158@mail.netbsd.org>. This change includes
the following:

An initial cleanup and minor reorganization of the entropy pool
code in sys/dev/rnd.c and sys/dev/rndpool.c. Several bugs are
fixed. Some effort is made to accumulate entropy more quickly at
boot time.

A generic interface, "rndsink", is added, for stream generators to
request that they be re-keyed with good quality entropy from the pool
as soon as it is available.

The arc4random()/arc4randbytes() implementation in libkern is
adjusted to use the rndsink interface for rekeying, which helps
address the problem of low-quality keys at boot time.

An implementation of the FIPS 140-2 statistical tests for random
number generator quality is provided (libkern/rngtest.c). This
is based on Greg Rose's implementation from Qualcomm.

A new random stream generator, nist_ctr_drbg, is provided. It is
based on an implementation of the NIST SP800-90 CTR_DRBG by
Henric Jungheim. This generator users AES in a modified counter
mode to generate a backtracking-resistant random stream.

An abstraction layer, "cprng", is provided for in-kernel consumers
of randomness. The arc4random/arc4randbytes API is deprecated for
in-kernel use. It is replaced by "cprng_strong". The current
cprng_fast implementation wraps the existing arc4random
implementation. The current cprng_strong implementation wraps the
new CTR_DRBG implementation. Both interfaces are rekeyed from
the entropy pool automatically at intervals justifiable from best
current cryptographic practice.

In some quick tests, cprng_fast() is about the same speed as
the old arc4randbytes(), and cprng_strong() is about 20% faster
than rnd_extract_data(). Performance is expected to improve.

The AES code in src/crypto/rijndael is no longer an optional
kernel component, as it is required by cprng_strong, which is
not an optional kernel component.

The entropy pool output is subjected to the rngtest tests at
startup time; if it fails, the system will reboot. There is
approximately a 3/10000 chance of a false positive from these
tests. Entropy pool _input_ from hardware random numbers is
subjected to the rngtest tests at attach time, as well as the
FIPS continuous-output test, to detect bad or stuck hardware
RNGs; if any are detected, they are detached, but the system
continues to run.

A problem with rndctl(8) is fixed -- datastructures with
pointers in arrays are no longer passed to userspace (this
was not a security problem, but rather a major issue for
compat32). A new kernel will require a new rndctl.

The sysctl kern.arandom() and kern.urandom() nodes are hooked
up to the new generators, but the /dev/*random pseudodevices
are not, yet.

Manual pages for the new kernel interfaces are forthcoming.
 1.21 18-Sep-2009  tsutsui branches: 1.21.12;
hme_reset() is no longer called from bus attachments so make it static.
 1.20 08-Sep-2009  tsutsui - split out chip reset ops from hme_stop() into a new function
hme_chipreset() to make hme_stop() match struct ifnet API
- set ifp->if_timer in hme_start() if any TX packets are queued
- also clear ifp->if_timer and ifp->if_flags in hme_stop()
- replace shutdownhook_establish(9) with pmf_device_reigster1(9)
Briefly checked hme at pci.
 1.19 17-May-2009  tsutsui Split device_t/softc.
Tested PCI HME on i386. Sbus HME is compile test only.
 1.18 16-Apr-2009  tsutsui u_intNN_t -> uintNN_t
 1.17 28-Apr-2008  martin branches: 1.17.8; 1.17.14;
Remove clause 3 and 4 from TNF licenses
 1.16 19-Jan-2008  dyoung branches: 1.16.6; 1.16.8; 1.16.10;
Remove unused sc_media #define.
 1.15 04-Mar-2007  christos branches: 1.15.16; 1.15.22; 1.15.28;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.14 11-Dec-2005  christos branches: 1.14.26;
merge ktrace-lwp.
 1.13 18-Feb-2005  heas branches: 1.13.6;
Handle interface IFF_DEBUG flags sooner in hme_ioctl and cache a copy of
sc_ethercom.ec_capenable such that we can properly adjust the max frame size
when vlan tagging is enabled/disabled.
 1.12 04-Feb-2005  perry de-__P
 1.11 28-Jun-2004  heas branches: 1.11.4; 1.11.6;
do not reset the chip (and subsequently the phy) when unnecessary; that is,
for address changes, multicast filter changes, or adjusting promiscuous mode.
Fixes resetting the phy for things like start/stopping tcpdump.

ok petrov@, martin@, pk@
 1.10 13-Feb-2003  pk branches: 1.10.2;
Preserve the current PHY select bit in the MIF configuration register
in mii_readreg()/mii_writereg(). Also restore this bit based on the
currently selected media instance every time we need to reinitialise
the interface.
 1.9 18-Dec-2002  martin Since we have to select one of the two possible PHYs when configuring
the MIF Configuration Register PHY_Select, there is no use in pretending
we could talk to both at the MII interface layer.

If both PHY are reported to be present, prefer the external one.

Remember this selection and enforce it in hme_mii_{read,write}reg.
This fixes problems with one of the dual hmes in Netra T1s.

From OpenBSD.
 1.8 26-Nov-2001  tron Back out new "hme" driver because it causes a performance regression on
"netio" on an U5.
 1.7 25-Nov-2001  tron Pull in Jason Wright's latest changes to the "hme" driver from OpenBSD.
This supports direct DMA from and into mbuf cluster, and VLAN
handling is done a bit differently.
 1.6 28-Sep-2000  tsutsui branches: 1.6.2; 1.6.4;
6 -> ETHER_ADDR_LEN
 1.5 25-Jun-2000  eeh Make PCI HME work.
 1.4 09-May-2000  pk branches: 1.4.4;
Conform bus_dmamem_{alloc,map} usage to bus_dma(9) specs.
 1.3 23-Mar-2000  thorpej New callout mechanism with two major improvements over the old
timeout()/untimeout() API:
- Clients supply callout handle storage, thus eliminating problems of
resource allocation.
- Insertion and removal of callouts is constant time, important as
this facility is used quite a lot in the kernel.

The old timeout()/untimeout() API has been removed from the kernel.
 1.2 18-Dec-1999  pk Add support for selecting a PHY (i.e. built-in transceiver vs. external MII
device) by using media/instance parameters.
 1.1 27-Jun-1999  pk branches: 1.1.2; 1.1.4; 1.1.10;
HME ethernet driver.
Note: this is work in progress; needs testing and tweaking. mgr has
promised to do that..
 1.1.10.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.1.4.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.1.2.2 01-Jul-1999  thorpej Sync w/ -current.
 1.1.2.1 27-Jun-1999  thorpej file hmevar.h was added on branch chs-ubc2 on 1999-07-01 23:32:27 +0000
 1.4.4.1 31-Jul-2000  mrg pull up 1.5 (approved by thorpej):
>Get PCI HME working.
 1.6.4.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.6.2.2 19-Dec-2002  thorpej Sync with HEAD.
 1.6.2.1 08-Jan-2002  nathanw Catch up to -current.
 1.10.2.5 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.10.2.4 04-Feb-2005  skrll Sync with HEAD.
 1.10.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.10.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.10.2.1 03-Aug-2004  skrll Sync with HEAD
 1.11.6.2 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.11.6.1 12-Feb-2005  yamt sync with head.
 1.11.4.1 29-Apr-2005  kent sync with -current
 1.13.6.2 21-Jan-2008  yamt sync with head
 1.13.6.1 03-Sep-2007  yamt sync with head.
 1.14.26.1 12-Mar-2007  rmind Sync with HEAD.
 1.15.28.1 20-Jan-2008  bouyer Sync with HEAD
 1.15.22.1 18-Feb-2008  mjf Sync with HEAD.
 1.15.16.1 23-Mar-2008  matt sync with HEAD
 1.16.10.5 11-Mar-2010  yamt sync with head
 1.16.10.4 16-Sep-2009  yamt sync with head
 1.16.10.3 20-Jun-2009  yamt sync with head
 1.16.10.2 04-May-2009  yamt sync with head.
 1.16.10.1 16-May-2008  yamt sync with head.
 1.16.8.1 18-May-2008  yamt sync with head.
 1.16.6.1 02-Jun-2008  mjf Sync with HEAD.
 1.17.14.2 23-Jul-2009  jym Sync with HEAD.
 1.17.14.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.17.8.1 28-Apr-2009  skrll Sync with HEAD.
 1.21.12.1 17-Apr-2012  yamt sync with head
 1.22.2.1 18-Feb-2012  mrg merge to -current.
 1.23.24.1 06-Jun-2015  skrll Sync with HEAD
 1.23.6.1 03-Dec-2017  jdolecek update from HEAD
 1.18 20-Aug-2022  mlelstv It is possible to overflow the (low 32bit) HPET counter between hpet_attach
and TSC calibration if the boot is delayed for more than ~430 seconds (or
less, depending on HPET frequency). The result is a badly misconfigured
timecounter.

Change the measurement interval to ~1e6 HPET ticks (<100ms) during
the calibration to avoid the overflow. This introduces an error of
1ppm, compared to the previous unspecified but typical error of 0.1ppm.
But this is still much less than the guaranteed maximum frequency drift
of the HPET counter itself, which is 500ppm.
 1.17 16-May-2020  ad Store initial TSC/HPET readings for hpet0 only.
 1.16 08-May-2020  ad Fix the TSC timecounter (on the systems I have access to):

- Make the early i8254-based calculation of frequency a bit more accurate.

- Keep track of how far the HPET & TSC advance between HPET attach and
secondary CPU boot, and use to compute an accurate value before attaching
the timecounter. Initial idea from joerg@.

- When determining skew and drift between CPUs, make each measurement 1000
times and pick the lowest observed value. Increase the error threshold to
1000 clock cycles.

- Use the frequency computed on the boot CPU for secondary CPUs too.

- Remove cpu_counter_serializing().
 1.15 24-Apr-2020  ad On attach figure out how long a single read of the counter register takes
and use that for the adjustment in hpet_delay().
 1.14 23-Apr-2020  ad Implement a HPET based DELAY().
 1.13 31-Oct-2011  yamt branches: 1.13.66;
hpet:
- fix an integer overflow bug introduced by hpet.c rev.1.11.
- a workaround for AMD SB700 based systems, inspired from linux.
 1.12 29-Jul-2011  jakllsch Use one more bit of precision when calculating frequency from period.
This makes the 4-times-NTSC color carrier get calculated to a
correct 14318180Hz, instead of 14318179Hz, which seems a bit odd.
 1.11 15-Jun-2011  jruoho Modularize hpet(4). Works nicely with the multiple bus locations.
 1.10 24-Feb-2010  dyoung branches: 1.10.8;
A pointer typedef entails trading too much flexibility to declare const
and non-const types, and the kernel uses both const and non-const
PMF qualifiers and device suspensors, so change the pmf_qual_t and
device_suspensor_t typedefs from "pointers to const" to non-pointer,
non-const types.
 1.9 08-Jan-2010  dyoung branches: 1.9.2;
Expand PMF_FN_* macros.
 1.8 30-Sep-2009  njoly Be robust against an invalid timer period value.
 1.7 18-Aug-2009  dyoung Add a bus-independent detachment routine. In the attachment routine,
save some device state to restore during detachment.
 1.6 21-Mar-2008  xtraeme branches: 1.6.4; 1.6.14;
Split device_t/softc for ichlpcib(4) and all hpet consumers, plus
other related cosmetic changes.
 1.5 29-Feb-2008  dyoung Use PMF_FN_ARGS, PMF_FN_PROTO.
 1.4 09-Dec-2007  jmcneill branches: 1.4.6; 1.4.10;
Merge jmcneill-pm branch.
 1.3 01-Dec-2007  ad branches: 1.3.2; 1.3.4;
Noisy printf.
 1.2 19-Oct-2007  ad branches: 1.2.2;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.1 08-Mar-2007  njoly branches: 1.1.2; 1.1.4; 1.1.16; 1.1.18; 1.1.20; 1.1.24;
High Precision Event Timer driver, following Intel specifications.

Allow attachement at both ACPI (hpet@acpi) and AMD8111 LPC Controller
(hpet@amdpcib).

Requested by xtraeme, and tested by a few users.
 1.1.24.1 25-Oct-2007  bouyer Sync with HEAD.
 1.1.20.7 24-Mar-2008  yamt sync with head.
 1.1.20.6 17-Mar-2008  yamt sync with head.
 1.1.20.5 21-Jan-2008  yamt sync with head
 1.1.20.4 07-Dec-2007  yamt sync with head
 1.1.20.3 27-Oct-2007  yamt sync with head.
 1.1.20.2 03-Sep-2007  yamt sync with head.
 1.1.20.1 08-Mar-2007  yamt file hpet.c was added on branch yamt-lazymbuf on 2007-09-03 14:34:36 +0000
 1.1.18.3 23-Mar-2008  matt sync with HEAD
 1.1.18.2 09-Jan-2008  matt sync with HEAD
 1.1.18.1 06-Nov-2007  matt sync with HEAD
 1.1.16.5 08-Dec-2007  jmcneill Rename pnp(9) -> pmf(9), as requested by many.
 1.1.16.4 06-Nov-2007  joerg Refactor PNP API:
- Make suspend/resume directly a device functionality. It consists of
three layers (class logic, device logic, bus logic), all of them being
optional. This replaces D0/D3 transitions.
- device_is_active returns true if the device was not disabled and was
not suspended (even partially), device_is_enabled returns true if the
device was enabled.
- Change pnp_global_transition into pnp_system_suspend and
pnp_system_resume. Before running any suspend/resume handlers, check
that all currently attached devices support power management and bail
out otherwise. The latter is not done for the shutdown/panic case.
- Make the former bus-specific generic network handlers a class handler.
- Make PNP message like volume up/down/toogle PNP events. Each device
can register what events they are interested in and whether the handler
should be global or not.
- Introduce device_active API for devices to mark themselve in use from
either the system or the device. Use this to implement the idle handling
for audio and input devices. This is intended to replace most ad-hoc
watchdogs as well.
- Fix somes situations in which audio resume would lose mixer settings.
- Make USB host controllers better deal with suspend in the light of
shared interrupts.
- Flush filesystem cache on suspend.
- Flush disk caches on suspend. Put ATA disks into standby on suspend as
well.
- Adopt drivers to use the new PNP API.
- Fix a critical bug in the generic cardbus layer that made D0->D3
break.
- Fix ral(4) to set if_stop.
- Convert cbb(4) to the new PNP API.
- Apply the PCI Express SCI fix on resume again.
 1.1.16.3 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.1.16.2 04-Sep-2007  joerg Add a bunch of register defines for interrupts and periodic operation.
Rename HPET_MCOUNT to HPET_MCOUNT_LO. Don't bother the user that we
don't use the higher 32bit for the counter.
 1.1.16.1 03-Aug-2007  jmcneill Pull in power management changes from private branch.
 1.1.4.2 12-Mar-2007  rmind Sync with HEAD (missed new files in previous).
 1.1.4.1 08-Mar-2007  rmind file hpet.c was added on branch yamt-idlelwp on 2007-03-12 06:14:50 +0000
 1.1.2.1 23-Oct-2007  ad Sync with head.
 1.2.2.2 27-Dec-2007  mjf Sync with HEAD.
 1.2.2.1 08-Dec-2007  mjf Sync with HEAD.
 1.3.4.1 11-Dec-2007  yamt sync with head.
 1.3.2.1 26-Dec-2007  ad Sync with head.
 1.4.10.1 03-Apr-2008  mjf Sync with HEAD.
 1.4.6.1 24-Mar-2008  keiichi sync with head.
 1.6.14.1 25-Jan-2012  riz Pull up following revision(s) (requested by hannken in ticket #1715):
- Be robust against an invalid timer period value.
sys/dev/ic/hpetreg.h Rev. 1.4
sys/dev/ic/hpet.c Rev. 1.8

- Fix wrong definition of LAPIC_LEVEL_ASSERT / _MASK
sys/arch/x86/include/i82489reg.h Rev. 1.11

- Add virtio driver - speed up disk and network access in virtual environments
sys/arch/i386/conf/GENERIC Rev. 1.1055
sys/arch/i386/conf/ALL Rev. 1.325
sys/arch/amd64/conf/GENERIC Rev. 1.338
sys/dev/pci/files.pci Rev. 1.350
sys/dev/pci/if_vioif.c Rev. 0-1.2
sys/dev/pci/ld_virtio.c Rev. 0-1.4
sys/dev/pci/viomb.c Rev. 0-1.1
sys/dev/pci/virtio.c Rev. 0-1.3
sys/dev/pci/virtioreg.h Rev. 0-1.1
sys/dev/pci/virtiovar.h Rev. 0-1.1
distrib/sets/lists/man/mi Rev. 1.1352 and 1.1358
share/man/man4/Makefile Rev. 1.573 and 1.575
share/man/man4/ld.4 Rev. 1.19
share/man/man4/virtio.4 Rev. 0-1.4
share/man/man4/vioif.4 Rev. 0-1.2
share/man/man4/viomb.4 Rev. 0-1.2

Allow NetBSD to run unmodified under Linux/kvm.
 1.6.4.2 11-Mar-2010  yamt sync with head
 1.6.4.1 19-Aug-2009  yamt sync with head.
 1.9.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.10.8.1 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.13.66.1 25-Apr-2020  bouyer Sync with bouyer-xenpvh-base2 (HEAD)
 1.4 31-Oct-2011  yamt hpet:
- fix an integer overflow bug introduced by hpet.c rev.1.11.
- a workaround for AMD SB700 based systems, inspired from linux.
 1.3 15-Feb-2008  jmcneill branches: 1.3.20;
Add missing register definitions.
 1.2 09-Dec-2007  jmcneill Merge jmcneill-pm branch.
 1.1 08-Mar-2007  njoly branches: 1.1.4; 1.1.16; 1.1.18; 1.1.20; 1.1.26; 1.1.28; 1.1.30;
High Precision Event Timer driver, following Intel specifications.

Allow attachement at both ACPI (hpet@acpi) and AMD8111 LPC Controller
(hpet@amdpcib).

Requested by xtraeme, and tested by a few users.
 1.1.30.1 11-Dec-2007  yamt sync with head.
 1.1.28.1 26-Dec-2007  ad Sync with head.
 1.1.26.1 18-Feb-2008  mjf Sync with HEAD.
 1.1.20.4 27-Feb-2008  yamt sync with head.
 1.1.20.3 21-Jan-2008  yamt sync with head
 1.1.20.2 03-Sep-2007  yamt sync with head.
 1.1.20.1 08-Mar-2007  yamt file hpetreg.h was added on branch yamt-lazymbuf on 2007-09-03 14:34:36 +0000
 1.1.18.2 23-Mar-2008  matt sync with HEAD
 1.1.18.1 09-Jan-2008  matt sync with HEAD
 1.1.16.1 04-Sep-2007  joerg Add a bunch of register defines for interrupts and periodic operation.
Rename HPET_MCOUNT to HPET_MCOUNT_LO. Don't bother the user that we
don't use the higher 32bit for the counter.
 1.1.4.2 12-Mar-2007  rmind Sync with HEAD (missed new files in previous).
 1.1.4.1 08-Mar-2007  rmind file hpetreg.h was added on branch yamt-idlelwp on 2007-03-12 06:14:51 +0000
 1.3.20.1 25-Jan-2012  riz Pull up following revision(s) (requested by hannken in ticket #1715):
- Be robust against an invalid timer period value.
sys/dev/ic/hpetreg.h Rev. 1.4
sys/dev/ic/hpet.c Rev. 1.8

- Fix wrong definition of LAPIC_LEVEL_ASSERT / _MASK
sys/arch/x86/include/i82489reg.h Rev. 1.11

- Add virtio driver - speed up disk and network access in virtual environments
sys/arch/i386/conf/GENERIC Rev. 1.1055
sys/arch/i386/conf/ALL Rev. 1.325
sys/arch/amd64/conf/GENERIC Rev. 1.338
sys/dev/pci/files.pci Rev. 1.350
sys/dev/pci/if_vioif.c Rev. 0-1.2
sys/dev/pci/ld_virtio.c Rev. 0-1.4
sys/dev/pci/viomb.c Rev. 0-1.1
sys/dev/pci/virtio.c Rev. 0-1.3
sys/dev/pci/virtioreg.h Rev. 0-1.1
sys/dev/pci/virtiovar.h Rev. 0-1.1
distrib/sets/lists/man/mi Rev. 1.1352 and 1.1358
share/man/man4/Makefile Rev. 1.573 and 1.575
share/man/man4/ld.4 Rev. 1.19
share/man/man4/virtio.4 Rev. 0-1.4
share/man/man4/vioif.4 Rev. 0-1.2
share/man/man4/viomb.4 Rev. 0-1.2

Allow NetBSD to run unmodified under Linux/kvm.
 1.7 08-May-2020  ad Fix the TSC timecounter (on the systems I have access to):

- Make the early i8254-based calculation of frequency a bit more accurate.

- Keep track of how far the HPET & TSC advance between HPET attach and
secondary CPU boot, and use to compute an accurate value before attaching
the timecounter. Initial idea from joerg@.

- When determining skew and drift between CPUs, make each measurement 1000
times and pick the lowest observed value. Increase the error threshold to
1000 clock cycles.

- Use the frequency computed on the boot CPU for secondary CPUs too.

- Remove cpu_counter_serializing().
 1.6 24-Apr-2020  ad On attach figure out how long a single read of the counter register takes
and use that for the adjustment in hpet_delay().
 1.5 23-Apr-2020  ad Implement a HPET based DELAY().
 1.4 14-Jun-2011  jruoho branches: 1.4.66;
Add detach function.
 1.3 18-Aug-2009  dyoung branches: 1.3.10;
Add a bus-independent detachment routine. In the attachment routine,
save some device state to restore during detachment.
 1.2 21-Mar-2008  xtraeme branches: 1.2.4;
Split device_t/softc for ichlpcib(4) and all hpet consumers, plus
other related cosmetic changes.
 1.1 08-Mar-2007  njoly branches: 1.1.4; 1.1.18; 1.1.20; 1.1.40;
High Precision Event Timer driver, following Intel specifications.

Allow attachement at both ACPI (hpet@acpi) and AMD8111 LPC Controller
(hpet@amdpcib).

Requested by xtraeme, and tested by a few users.
 1.1.40.1 03-Apr-2008  mjf Sync with HEAD.
 1.1.20.3 24-Mar-2008  yamt sync with head.
 1.1.20.2 03-Sep-2007  yamt sync with head.
 1.1.20.1 08-Mar-2007  yamt file hpetvar.h was added on branch yamt-lazymbuf on 2007-09-03 14:34:37 +0000
 1.1.18.1 23-Mar-2008  matt sync with HEAD
 1.1.4.2 12-Mar-2007  rmind Sync with HEAD (missed new files in previous).
 1.1.4.1 08-Mar-2007  rmind file hpetvar.h was added on branch yamt-idlelwp on 2007-03-12 06:14:51 +0000
 1.2.4.1 19-Aug-2009  yamt sync with head.
 1.3.10.1 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.4.66.1 25-Apr-2020  bouyer Sync with bouyer-xenpvh-base2 (HEAD)
 1.17 22-Sep-2018  maxv Remove isic(4). It is part of ISDN, which we are now retiring.
 1.16 27-Oct-2012  chs branches: 1.16.36; 1.16.38;
split device_t/softc for all remaining drivers.
replace "struct device *" with "device_t".
use device_xname(), device_unit(), etc.
 1.15 17-Jul-2011  joerg branches: 1.15.2; 1.15.12;
Retire varargs.h support. Move machine/stdarg.h logic into MI
sys/stdarg.h and expect compiler to provide proper builtins, defaulting
to the GCC interface. lint still has a special fallback.
Reduce abuse of _BSD_VA_LIST_ by defining __va_list by default and
derive va_list as required by standards.
 1.14 08-Apr-2008  cegger use aprint_*_dev and device_xname
 1.13 19-Oct-2007  ad branches: 1.13.16;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.12 11-Dec-2005  christos branches: 1.12.30; 1.12.44; 1.12.46; 1.12.50;
merge ktrace-lwp.
 1.11 01-Jun-2005  drochner branches: 1.11.2;
quell cast-qual and shadow warnings
 1.10 27-Feb-2005  perry nuke trailing whitespace
 1.9 27-Sep-2002  provos branches: 1.9.6; 1.9.14; 1.9.16;
remove trailing \n in panic(). approved perry.
 1.8 21-May-2002  martin Uniformly pass a "struct isdn_l3_driver *" through layer 2, so we
do not have to search for that driver later while we already knew it
at layer 1.
 1.7 25-Mar-2002  martin branches: 1.7.2;
Now that we have all pieces in place (and enough granularity to specify
B-channel and D-channel drivers separately) split the Fritz!PCI card
driver out of the isic driver.

The new device is called "ifpci" and uses the same D-channel driver as the
isic devices, but has it's own B-channel driver.
 1.6 24-Mar-2002  martin Now that we have all the pieces of the puzzle available start to unriddle
and move them in their proper places.

Move the BRI registry from layer 2 (duh!) to layer 4, so active cards
(which don't have layer 3 or layer 2 in their driver). Remove all remaining
hard coded controller and driver types. Remove any arbitrary hard coded
limits, at least those that show up in the internal API.

This fixes PR 15950.
 1.5 17-Mar-2002  martin Remove all knowledge about specific application (layer 4) drivers from
the generic layer 4 and layer 3 management system.

This should make the layer 4 driver API LKM clean - finaly.

Make the Fritz!PCI driver work again after resent changes (oops!),
noted by Frank Kardel (PR 15948) and Matthias Scheeler.
 1.4 17-Mar-2002  martin Clean up the application (layer 4) driver vs. B channel driver interface.
One step further on the way to make layer 4 drivers LKMable.
 1.3 13-Nov-2001  lukem add/cleanup RCSID
 1.2 24-Mar-2001  martin branches: 1.2.2;
First step to cleanup the hardware driver <-> upper layers interface.
This now provides slightly more functionality than the FreeBSD layer1-newbus
interface. It was meant to be a simple change to one header and a few
c files, but the change rippled all through various stuff.

To prevent a change to the kernel<->userland interface right now the kernel
is now lying about card types to userland (but who cares). This will be fixed
when the userland interface changes, after layer 3 <-> layer 4 has been
fixed.

Functional changes:

Provide a clean interface for hardware drivers to attach to the upper
layers. This will need another small change in the B-channel handling
when a similar change to the layer 3 <-> layer 4 interface happens.

Avoid passing indices into global arrays of pointers around, instead pass
the pointers itself. Don't code hardware driver types by predefined magic
numbers (think LKM). Prepare for detachable drivers (think pcmcia).

While there remove some sets of function pointers always pointing to the
same function (meant to be the configurable set of D channel protocol
handlers). It is unlikely another supported D-channel protocol will fit into
that (maximal layer interface) abstraction. When we get support for another
protocol, we will need to come up with a workable interface. Besides, the
old implementation was, uhm, strange.
 1.1 20-Feb-2001  martin branches: 1.1.2; 1.1.4;
Filename cleanup: remove i4b_ prefixes outside sys/netisdn, last round.

Renamed in sys/dev/ic:
i4b_hscx.c -> hscx.c
i4b_hscx.h -> hscx.h
i4b_ipac.h -> ipac.h
i4b_isac.c -> isac.c
i4b_isac.h -> isac.h
i4b_isic.c -> isic.c
i4b_isicbchan.c -> isic_bchan.c
i4b_isicl1.c -> isic_l1.c
i4b_isicl1.h -> isic_l1.h
i4b_isicl1fsm.c -> isic_l1fsm.c
 1.1.4.3 27-Mar-2001  bouyer Sync with HEAD.
 1.1.4.2 12-Mar-2001  bouyer Sync with HEAD.
 1.1.4.1 20-Feb-2001  bouyer file hscx.c was added on branch thorpej_scsipi on 2001-03-12 13:30:19 +0000
 1.1.2.5 18-Oct-2002  nathanw Catch up to -current.
 1.1.2.4 20-Jun-2002  nathanw Catch up to -current.
 1.1.2.3 01-Apr-2002  nathanw Catch up to -current.
(CVS: It's not just a program. It's an adventure!)
 1.1.2.2 14-Nov-2001  nathanw Catch up to -current.
 1.1.2.1 09-Apr-2001  nathanw Catch up with -current.
 1.2.2.3 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.2.2.2 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.2.2.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.7.2.1 30-May-2002  gehenna Catch up with -current.
 1.9.16.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.9.14.1 29-Apr-2005  kent sync with -current
 1.9.6.2 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.9.6.1 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.11.2.1 27-Oct-2007  yamt sync with head.
 1.12.50.1 25-Oct-2007  bouyer Sync with HEAD.
 1.12.46.1 06-Nov-2007  matt sync with HEAD
 1.12.44.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.12.30.1 23-Oct-2007  ad Sync with head.
 1.13.16.1 02-Jun-2008  mjf Sync with HEAD.
 1.15.12.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.15.2.1 30-Oct-2012  yamt sync with head
 1.16.38.1 10-Jun-2019  christos Sync with HEAD
 1.16.36.1 30-Sep-2018  pgoyette Ssync with HEAD
 1.5 22-Sep-2018  maxv Remove isic(4). It is part of ISDN, which we are now retiring.
 1.4 07-Aug-2011  jakllsch branches: 1.4.52; 1.4.54;
Appease _LP64 build with GCC 4.5.
 1.3 11-Dec-2005  christos merge ktrace-lwp.
 1.2 27-Feb-2005  perry nuke trailing whitespace
 1.1 20-Feb-2001  martin branches: 1.1.4; 1.1.26; 1.1.34; 1.1.36;
Filename cleanup: remove i4b_ prefixes outside sys/netisdn, last round.

Renamed in sys/dev/ic:
i4b_hscx.c -> hscx.c
i4b_hscx.h -> hscx.h
i4b_ipac.h -> ipac.h
i4b_isac.c -> isac.c
i4b_isac.h -> isac.h
i4b_isic.c -> isic.c
i4b_isicbchan.c -> isic_bchan.c
i4b_isicl1.c -> isic_l1.c
i4b_isicl1.h -> isic_l1.h
i4b_isicl1fsm.c -> isic_l1fsm.c
 1.1.36.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.1.34.1 29-Apr-2005  kent sync with -current
 1.1.26.1 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.1.4.2 12-Mar-2001  bouyer Sync with HEAD.
 1.1.4.1 20-Feb-2001  bouyer file hscx.h was added on branch thorpej_scsipi on 2001-03-12 13:30:20 +0000
 1.4.54.1 10-Jun-2019  christos Sync with HEAD
 1.4.52.1 30-Sep-2018  pgoyette Ssync with HEAD
 1.4 20-Oct-2012  macallan don't sync after each drawing op, add functions to wait for the engine to get ready for more commands or idle
 1.3 29-Apr-2008  martin branches: 1.3.34; 1.3.44;
Convert to new 2 clause license
 1.2 19-Oct-2007  ad branches: 1.2.16; 1.2.18; 1.2.20;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.1 26-Aug-2007  macallan branches: 1.1.2; 1.1.4; 1.1.6; 1.1.8; 1.1.12; 1.1.14;
register definitions and some drawing routines for Number Nine Imagine 128
graphics controllers
 1.1.14.1 25-Oct-2007  bouyer Sync with HEAD.
 1.1.12.3 23-Oct-2007  ad Sync with head.
 1.1.12.2 09-Oct-2007  ad Sync with head.
 1.1.12.1 26-Aug-2007  ad file i128.c was added on branch vmlocking on 2007-10-09 13:41:25 +0000
 1.1.8.3 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.1.8.2 03-Sep-2007  jmcneill Sync with HEAD.
 1.1.8.1 26-Aug-2007  jmcneill file i128.c was added on branch jmcneill-pm on 2007-09-03 16:48:01 +0000
 1.1.6.3 27-Oct-2007  yamt sync with head.
 1.1.6.2 03-Sep-2007  yamt sync with head.
 1.1.6.1 26-Aug-2007  yamt file i128.c was added on branch yamt-lazymbuf on 2007-09-03 14:34:37 +0000
 1.1.4.2 03-Sep-2007  skrll Sync with HEAD.
 1.1.4.1 26-Aug-2007  skrll file i128.c was added on branch nick-csl-alignment on 2007-09-03 10:20:21 +0000
 1.1.2.1 06-Nov-2007  matt sync with HEAD
 1.2.20.1 16-May-2008  yamt sync with head.
 1.2.18.1 18-May-2008  yamt sync with head.
 1.2.16.1 02-Jun-2008  mjf Sync with HEAD.
 1.3.44.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.3.34.1 30-Oct-2012  yamt sync with head
 1.5 16-Apr-2020  rin Revert previous for now:
http://mail-index.netbsd.org/source-changes/2020/04/16/msg116278.html

The reasoning turned out to be wrong; __KERNEL_RCSID() in header files
does *not* overwrite RCSID in main source files. The real problem is that
it inserts its RCSID into *every* object files. However, it can be still
useful even if heavily duplicated.
 1.4 16-Apr-2020  rin Stop using __KERNEL_RCSID() in header files; it confuses ident(1) by
overwriting RCSID in main source files.

XXX
The first argument of __KERNEL_RCSID() is neglected for ELF. If we wish
to have RCSID of header files in kernel binary, we need something like
__FBSDID() macro in FreeBSD.
 1.3 29-Apr-2008  martin branches: 1.3.100;
Convert to new 2 clause license
 1.2 26-Aug-2007  macallan branches: 1.2.4; 1.2.6; 1.2.8; 1.2.12; 1.2.30; 1.2.32; 1.2.34;
add some comments
 1.1 26-Aug-2007  macallan register definitions and some drawing routines for Number Nine Imagine 128
graphics controllers
 1.2.34.1 16-May-2008  yamt sync with head.
 1.2.32.1 18-May-2008  yamt sync with head.
 1.2.30.1 02-Jun-2008  mjf Sync with HEAD.
 1.2.12.2 09-Oct-2007  ad Sync with head.
 1.2.12.1 26-Aug-2007  ad file i128reg.h was added on branch vmlocking on 2007-10-09 13:41:25 +0000
 1.2.8.2 03-Sep-2007  jmcneill Sync with HEAD.
 1.2.8.1 26-Aug-2007  jmcneill file i128reg.h was added on branch jmcneill-pm on 2007-09-03 16:48:02 +0000
 1.2.6.2 03-Sep-2007  yamt sync with head.
 1.2.6.1 26-Aug-2007  yamt file i128reg.h was added on branch yamt-lazymbuf on 2007-09-03 14:34:38 +0000
 1.2.4.2 03-Sep-2007  skrll Sync with HEAD.
 1.2.4.1 26-Aug-2007  skrll file i128reg.h was added on branch nick-csl-alignment on 2007-09-03 10:20:21 +0000
 1.3.100.1 20-Apr-2020  bouyer Sync with HEAD
 1.5 16-Apr-2020  rin Revert previous for now:
http://mail-index.netbsd.org/source-changes/2020/04/16/msg116278.html

The reasoning turned out to be wrong; __KERNEL_RCSID() in header files
does *not* overwrite RCSID in main source files. The real problem is that
it inserts its RCSID into *every* object files. However, it can be still
useful even if heavily duplicated.
 1.4 16-Apr-2020  rin Stop using __KERNEL_RCSID() in header files; it confuses ident(1) by
overwriting RCSID in main source files.

XXX
The first argument of __KERNEL_RCSID() is neglected for ELF. If we wish
to have RCSID of header files in kernel binary, we need something like
__FBSDID() macro in FreeBSD.
 1.3 20-Oct-2012  macallan branches: 1.3.50;
don't sync after each drawing op, add functions to wait for the engine to get ready for more commands or idle
 1.2 29-Apr-2008  martin branches: 1.2.34; 1.2.44;
Convert to new 2 clause license
 1.1 26-Aug-2007  macallan branches: 1.1.4; 1.1.6; 1.1.8; 1.1.12; 1.1.30; 1.1.32; 1.1.34;
register definitions and some drawing routines for Number Nine Imagine 128
graphics controllers
 1.1.34.1 16-May-2008  yamt sync with head.
 1.1.32.1 18-May-2008  yamt sync with head.
 1.1.30.1 02-Jun-2008  mjf Sync with HEAD.
 1.1.12.2 09-Oct-2007  ad Sync with head.
 1.1.12.1 26-Aug-2007  ad file i128var.h was added on branch vmlocking on 2007-10-09 13:41:25 +0000
 1.1.8.2 03-Sep-2007  jmcneill Sync with HEAD.
 1.1.8.1 26-Aug-2007  jmcneill file i128var.h was added on branch jmcneill-pm on 2007-09-03 16:48:02 +0000
 1.1.6.2 03-Sep-2007  yamt sync with head.
 1.1.6.1 26-Aug-2007  yamt file i128var.h was added on branch yamt-lazymbuf on 2007-09-03 14:34:38 +0000
 1.1.4.2 03-Sep-2007  skrll Sync with HEAD.
 1.1.4.1 26-Aug-2007  skrll file i128var.h was added on branch nick-csl-alignment on 2007-09-03 10:20:21 +0000
 1.2.44.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.2.34.1 30-Oct-2012  yamt sync with head
 1.3.50.1 20-Apr-2020  bouyer Sync with HEAD
 1.2 20-Feb-2001  martin Filename cleanup: remove i4b_ prefixes outside sys/netisdn, last round.

Renamed in sys/dev/ic:
i4b_hscx.c -> hscx.c
i4b_hscx.h -> hscx.h
i4b_ipac.h -> ipac.h
i4b_isac.c -> isac.c
i4b_isac.h -> isac.h
i4b_isic.c -> isic.c
i4b_isicbchan.c -> isic_bchan.c
i4b_isicl1.c -> isic_l1.c
i4b_isicl1.h -> isic_l1.h
i4b_isicl1fsm.c -> isic_l1fsm.c
 1.1 05-Jan-2001  martin branches: 1.1.1;
Initial revision
 1.1.1.1 05-Jan-2001  martin branches: 1.1.1.1.2;
Initial import of ISDN4BSD release 0.96
 1.1.1.1.2.3 12-Mar-2001  bouyer Sync with HEAD.
 1.1.1.1.2.2 05-Jan-2001  bouyer Sync with HEAD
 1.1.1.1.2.1 05-Jan-2001  bouyer file i4b_hscx.c was added on branch thorpej_scsipi on 2001-01-05 17:35:37 +0000
 1.2 20-Feb-2001  martin Filename cleanup: remove i4b_ prefixes outside sys/netisdn, last round.

Renamed in sys/dev/ic:
i4b_hscx.c -> hscx.c
i4b_hscx.h -> hscx.h
i4b_ipac.h -> ipac.h
i4b_isac.c -> isac.c
i4b_isac.h -> isac.h
i4b_isic.c -> isic.c
i4b_isicbchan.c -> isic_bchan.c
i4b_isicl1.c -> isic_l1.c
i4b_isicl1.h -> isic_l1.h
i4b_isicl1fsm.c -> isic_l1fsm.c
 1.1 05-Jan-2001  martin branches: 1.1.1;
Initial revision
 1.1.1.1 05-Jan-2001  martin branches: 1.1.1.1.2;
Initial import of ISDN4BSD release 0.96
 1.1.1.1.2.3 12-Mar-2001  bouyer Sync with HEAD.
 1.1.1.1.2.2 05-Jan-2001  bouyer Sync with HEAD
 1.1.1.1.2.1 05-Jan-2001  bouyer file i4b_hscx.h was added on branch thorpej_scsipi on 2001-01-05 17:35:37 +0000
 1.2 20-Feb-2001  martin Filename cleanup: remove i4b_ prefixes outside sys/netisdn, last round.

Renamed in sys/dev/ic:
i4b_hscx.c -> hscx.c
i4b_hscx.h -> hscx.h
i4b_ipac.h -> ipac.h
i4b_isac.c -> isac.c
i4b_isac.h -> isac.h
i4b_isic.c -> isic.c
i4b_isicbchan.c -> isic_bchan.c
i4b_isicl1.c -> isic_l1.c
i4b_isicl1.h -> isic_l1.h
i4b_isicl1fsm.c -> isic_l1fsm.c
 1.1 05-Jan-2001  martin branches: 1.1.1;
Initial revision
 1.1.1.1 05-Jan-2001  martin branches: 1.1.1.1.2;
Initial import of ISDN4BSD release 0.96
 1.1.1.1.2.3 12-Mar-2001  bouyer Sync with HEAD.
 1.1.1.1.2.2 05-Jan-2001  bouyer Sync with HEAD
 1.1.1.1.2.1 05-Jan-2001  bouyer file i4b_ipac.h was added on branch thorpej_scsipi on 2001-01-05 17:35:37 +0000
 1.2 20-Feb-2001  martin Filename cleanup: remove i4b_ prefixes outside sys/netisdn, last round.

Renamed in sys/dev/ic:
i4b_hscx.c -> hscx.c
i4b_hscx.h -> hscx.h
i4b_ipac.h -> ipac.h
i4b_isac.c -> isac.c
i4b_isac.h -> isac.h
i4b_isic.c -> isic.c
i4b_isicbchan.c -> isic_bchan.c
i4b_isicl1.c -> isic_l1.c
i4b_isicl1.h -> isic_l1.h
i4b_isicl1fsm.c -> isic_l1fsm.c
 1.1 05-Jan-2001  martin branches: 1.1.1;
Initial revision
 1.1.1.1 05-Jan-2001  martin branches: 1.1.1.1.2;
Initial import of ISDN4BSD release 0.96
 1.1.1.1.2.3 12-Mar-2001  bouyer Sync with HEAD.
 1.1.1.1.2.2 05-Jan-2001  bouyer Sync with HEAD
 1.1.1.1.2.1 05-Jan-2001  bouyer file i4b_isac.c was added on branch thorpej_scsipi on 2001-01-05 17:35:37 +0000
 1.2 20-Feb-2001  martin Filename cleanup: remove i4b_ prefixes outside sys/netisdn, last round.

Renamed in sys/dev/ic:
i4b_hscx.c -> hscx.c
i4b_hscx.h -> hscx.h
i4b_ipac.h -> ipac.h
i4b_isac.c -> isac.c
i4b_isac.h -> isac.h
i4b_isic.c -> isic.c
i4b_isicbchan.c -> isic_bchan.c
i4b_isicl1.c -> isic_l1.c
i4b_isicl1.h -> isic_l1.h
i4b_isicl1fsm.c -> isic_l1fsm.c
 1.1 05-Jan-2001  martin branches: 1.1.1;
Initial revision
 1.1.1.1 05-Jan-2001  martin branches: 1.1.1.1.2;
Initial import of ISDN4BSD release 0.96
 1.1.1.1.2.3 12-Mar-2001  bouyer Sync with HEAD.
 1.1.1.1.2.2 05-Jan-2001  bouyer Sync with HEAD
 1.1.1.1.2.1 05-Jan-2001  bouyer file i4b_isac.h was added on branch thorpej_scsipi on 2001-01-05 17:35:38 +0000
 1.3 20-Feb-2001  martin Filename cleanup: remove i4b_ prefixes outside sys/netisdn, last round.

Renamed in sys/dev/ic:
i4b_hscx.c -> hscx.c
i4b_hscx.h -> hscx.h
i4b_ipac.h -> ipac.h
i4b_isac.c -> isac.c
i4b_isac.h -> isac.h
i4b_isic.c -> isic.c
i4b_isicbchan.c -> isic_bchan.c
i4b_isicl1.c -> isic_l1.c
i4b_isicl1.h -> isic_l1.h
i4b_isicl1fsm.c -> isic_l1fsm.c
 1.2 07-Jan-2001  martin 64bit police.
Rumors say there are archs without ISA busses, so avoid including
(uneccesarily) isa bus headers in MI files.
XXX this is the minimal solution, layer interface calls will have
XXX to be revisited later
 1.1 05-Jan-2001  martin branches: 1.1.1;
Initial revision
 1.1.1.1 05-Jan-2001  martin branches: 1.1.1.1.2;
Initial import of ISDN4BSD release 0.96
 1.1.1.1.2.4 12-Mar-2001  bouyer Sync with HEAD.
 1.1.1.1.2.3 18-Jan-2001  bouyer Sync with head (for UBC+NFS fixes, mostly).
 1.1.1.1.2.2 05-Jan-2001  bouyer Sync with HEAD
 1.1.1.1.2.1 05-Jan-2001  bouyer file i4b_isic.c was added on branch thorpej_scsipi on 2001-01-05 17:35:38 +0000
 1.3 20-Feb-2001  martin Filename cleanup: remove i4b_ prefixes outside sys/netisdn, last round.

Renamed in sys/dev/ic:
i4b_hscx.c -> hscx.c
i4b_hscx.h -> hscx.h
i4b_ipac.h -> ipac.h
i4b_isac.c -> isac.c
i4b_isac.h -> isac.h
i4b_isic.c -> isic.c
i4b_isicbchan.c -> isic_bchan.c
i4b_isicl1.c -> isic_l1.c
i4b_isicl1.h -> isic_l1.h
i4b_isicl1fsm.c -> isic_l1fsm.c
 1.2 19-Jan-2001  martin Nuke all uses of splimp() in the isdn subsystem, replace by splnet().
 1.1 05-Jan-2001  martin branches: 1.1.1;
Initial revision
 1.1.1.1 05-Jan-2001  martin branches: 1.1.1.1.2;
Initial import of ISDN4BSD release 0.96
 1.1.1.1.2.4 12-Mar-2001  bouyer Sync with HEAD.
 1.1.1.1.2.3 11-Feb-2001  bouyer Sync with HEAD.
 1.1.1.1.2.2 05-Jan-2001  bouyer Sync with HEAD
 1.1.1.1.2.1 05-Jan-2001  bouyer file i4b_isicbchan.c was added on branch thorpej_scsipi on 2001-01-05 17:35:38 +0000
 1.4 20-Feb-2001  martin Filename cleanup: remove i4b_ prefixes outside sys/netisdn, last round.

Renamed in sys/dev/ic:
i4b_hscx.c -> hscx.c
i4b_hscx.h -> hscx.h
i4b_ipac.h -> ipac.h
i4b_isac.c -> isac.c
i4b_isac.h -> isac.h
i4b_isic.c -> isic.c
i4b_isicbchan.c -> isic_bchan.c
i4b_isicl1.c -> isic_l1.c
i4b_isicl1.h -> isic_l1.h
i4b_isicl1fsm.c -> isic_l1fsm.c
 1.3 19-Jan-2001  martin Nuke all uses of splimp() in the isdn subsystem, replace by splnet().
 1.2 07-Jan-2001  martin 64bit police.
Rumors say there are archs without ISA busses, so avoid including
(uneccesarily) isa bus headers in MI files.
XXX this is the minimal solution, layer interface calls will have
XXX to be revisited later
 1.1 05-Jan-2001  martin branches: 1.1.1;
Initial revision
 1.1.1.1 05-Jan-2001  martin branches: 1.1.1.1.2;
Initial import of ISDN4BSD release 0.96
 1.1.1.1.2.5 12-Mar-2001  bouyer Sync with HEAD.
 1.1.1.1.2.4 11-Feb-2001  bouyer Sync with HEAD.
 1.1.1.1.2.3 18-Jan-2001  bouyer Sync with head (for UBC+NFS fixes, mostly).
 1.1.1.1.2.2 05-Jan-2001  bouyer Sync with HEAD
 1.1.1.1.2.1 05-Jan-2001  bouyer file i4b_isicl1.c was added on branch thorpej_scsipi on 2001-01-05 17:35:38 +0000
 1.2 20-Feb-2001  martin Filename cleanup: remove i4b_ prefixes outside sys/netisdn, last round.

Renamed in sys/dev/ic:
i4b_hscx.c -> hscx.c
i4b_hscx.h -> hscx.h
i4b_ipac.h -> ipac.h
i4b_isac.c -> isac.c
i4b_isac.h -> isac.h
i4b_isic.c -> isic.c
i4b_isicbchan.c -> isic_bchan.c
i4b_isicl1.c -> isic_l1.c
i4b_isicl1.h -> isic_l1.h
i4b_isicl1fsm.c -> isic_l1fsm.c
 1.1 05-Jan-2001  martin branches: 1.1.1;
Initial revision
 1.1.1.1 05-Jan-2001  martin branches: 1.1.1.1.2;
Initial import of ISDN4BSD release 0.96
 1.1.1.1.2.3 12-Mar-2001  bouyer Sync with HEAD.
 1.1.1.1.2.2 05-Jan-2001  bouyer Sync with HEAD
 1.1.1.1.2.1 05-Jan-2001  bouyer file i4b_isicl1.h was added on branch thorpej_scsipi on 2001-01-05 17:35:38 +0000
 1.3 20-Feb-2001  martin Filename cleanup: remove i4b_ prefixes outside sys/netisdn, last round.

Renamed in sys/dev/ic:
i4b_hscx.c -> hscx.c
i4b_hscx.h -> hscx.h
i4b_ipac.h -> ipac.h
i4b_isac.c -> isac.c
i4b_isac.h -> isac.h
i4b_isic.c -> isic.c
i4b_isicbchan.c -> isic_bchan.c
i4b_isicl1.c -> isic_l1.c
i4b_isicl1.h -> isic_l1.h
i4b_isicl1fsm.c -> isic_l1fsm.c
 1.2 19-Jan-2001  martin Nuke all uses of splimp() in the isdn subsystem, replace by splnet().
 1.1 05-Jan-2001  martin branches: 1.1.1;
Initial revision
 1.1.1.1 05-Jan-2001  martin branches: 1.1.1.1.2;
Initial import of ISDN4BSD release 0.96
 1.1.1.1.2.4 12-Mar-2001  bouyer Sync with HEAD.
 1.1.1.1.2.3 11-Feb-2001  bouyer Sync with HEAD.
 1.1.1.1.2.2 05-Jan-2001  bouyer Sync with HEAD
 1.1.1.1.2.1 05-Jan-2001  bouyer file i4b_isicl1fsm.c was added on branch thorpej_scsipi on 2001-01-05 17:35:38 +0000
 1.7 28-Jun-1995  cgd move to more appropriate (...reg.h) names.
 1.6 21-Apr-1995  mycroft Add constants for some keyboard controller commands.
 1.5 27-Oct-1994  cgd new RCS ID format.
 1.4 02-Mar-1994  mycroft Add mouse gunk.
 1.3 02-Mar-1994  mycroft Set the keyboard to scancode table 1 rather than having the 8042 convert.
 1.2 22-May-1993  cgd branches: 1.2.4;
add rcsids to everything and clean up headers
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.2.4.1 12-Oct-1993  mycroft Minor cleanup.
 1.8 31-Jan-2002  uwe Fix KBS_WARM comment.
 1.7 18-Jan-1998  drochner branches: 1.7.26; 1.7.28;
Don't define absolute ISA addresses here but offsets into the
"controller window".
 1.6 21-Apr-1995  mycroft Add constants for some keyboard controller commands.
 1.5 27-Oct-1994  cgd new RCS ID format.
 1.4 02-Mar-1994  mycroft Add mouse gunk.
 1.3 02-Mar-1994  mycroft Set the keyboard to scancode table 1 rather than having the 8042 convert.
 1.2 22-May-1993  cgd branches: 1.2.4;
add rcsids to everything and clean up headers
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.2.4.1 12-Oct-1993  mycroft Minor cleanup.
 1.7.28.1 11-Feb-2002  jdolecek Sync w/ -current.
 1.7.26.1 28-Feb-2002  nathanw Catch up to -current.
 1.119 13-Feb-2024  andvar s/enqueing/enqueuing/ in debug messages (took a bait from recent Nick's commit)
s/occaision/occasion/ in comment.
 1.118 07-Aug-2021  thorpej Merge thorpej-cfargs2.
 1.117 24-Apr-2021  thorpej branches: 1.117.8;
Merge thorpej-cfargs branch:

Simplify and make extensible the config_search() / config_found() /
config_attach() interfaces: rather than having different variants for
which arguments you want pass along, just have a single call that
takes a variadic list of tag-value arguments.

Adjust all call sites:
- Simplify wherever possible; don't pass along arguments that aren't
actually needed.
- Don't be explicit about what interface attribute is attaching if
the device only has one. (More simplification.)
- Add a config_probe() function to be used in indirect configuiration
situations, making is visibly easier to see when indirect config is
in play, and allowing for future change in semantics. (As of now,
this is just a wrapper around config_match(), but that is an
implementation detail.)

Remove unnecessary or redundant interface attributes where they're not
needed.

There are currently 5 "cfargs" defined:
- CFARG_SUBMATCH (submatch function for direct config)
- CFARG_SEARCH (search function for indirect config)
- CFARG_IATTR (interface attribte)
- CFARG_LOCATORS (locators array)
- CFARG_DEVHANDLE (devhandle_t - wraps OFW, ACPI, etc. handles)

...and a sentinel value CFARG_EOL.

Add some extra sanity checking to ensure that interface attributes
aren't ambiguous.

Use CFARG_DEVHANDLE in MI FDT, OFW, and ACPI code, and macppc and shark
ports to associate those device handles with device_t instance. This
will trickle trough to more places over time (need back-end for pre-OFW
Sun OBP; any others?).
 1.116 13-Oct-2013  riz branches: 1.116.46;
Catch up to recent changes in config_pending_{incr,decr}().
 1.115 27-Oct-2012  chs branches: 1.115.2;
split device_t/softc for all remaining drivers.
replace "struct device *" with "device_t".
use device_xname(), device_unit(), etc.
 1.114 26-Jul-2011  dyoung branches: 1.114.2; 1.114.12;
Don't set the iobase and iosize members of pcmciabus_attach_args because
they're not used in any meaningful way.
 1.113 19-Apr-2010  dyoung Add default implementations for bus_space_is_equal(9),
bus_space_tag_create(9), and bus_space_tag_destroy(9). Use
bus_space_is_equal(9) throughout the kernel to compare
bus_space_tag_t's. Tested on i386 and on sparc64.
 1.112 22-Mar-2010  dyoung #if 0 some diagnostic code that compares two bus_space_tag_t's. MI code
should not compare an opaque type such as bus_space_tag_t!
 1.111 17-Sep-2009  tsutsui branches: 1.111.2; 1.111.4;
Misc KNF and cosmetics, and remove unnecessary casts etc.
 1.110 14-Sep-2009  tsutsui Use device_private(), proper types or variables for device_t and softc.
(not yet split though)

No crash on gxemul emulating hpcmips mobilepro.
 1.109 14-Sep-2009  tsutsui u_intNN_t -> uintNN_t
 1.108 05-Aug-2009  jun fix pcic kthread creation timing.
see http://mail-index.netbsd.org/current-users/2008/07/15/msg003526.html

fix kern/41791 & port-hpcmips/41164.
ok by uwe & tsutsui
 1.107 12-May-2009  cegger struct device * -> device_t, no functional changes intended.
 1.106 14-Mar-2009  dsl ANSIfy another 1261 function definitions.
The only ones left in sys are beyond by sed script!
(or in sys/dist or sys/external)
Mostly they have function pointer parameters.
 1.105 14-Mar-2009  dsl Change about 4500 of the K&R function definitions to ANSI ones.
There are still about 1600 left, but they have ',' or /* ... */
in the actual variable definitions - which my awk script doesn't handle.
There are also many that need () -> (void).
(The script does handle misordered arguments.)
 1.104 06-Mar-2009  hauke Workaround from jmcneill for a panic at shutdown.

Fixes PR kern/40947 and should be pulled up to netbsd-5.
 1.103 16-Dec-2008  christos branches: 1.103.2;
replace bitmask_snprintf(9) with snprintb(3)
 1.102 08-Apr-2008  cegger branches: 1.102.4; 1.102.12; 1.102.14; 1.102.18; 1.102.20;
use aprint_*_dev and device_xname
 1.101 05-Dec-2007  ad branches: 1.101.12;
lockmgr -> mutex
 1.100 19-Oct-2007  ad branches: 1.100.2; 1.100.4;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.99 09-Jul-2007  ad branches: 1.99.6; 1.99.8; 1.99.12;
Merge some of the less invasive changes from the vmlocking branch:

- kthread, callout, devsw API changes
- select()/poll() improvements
- miscellaneous MT safety improvements
 1.98 04-Mar-2007  christos branches: 1.98.2; 1.98.4;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.97 16-Nov-2006  christos branches: 1.97.4;
__unused removal on arguments; approved by core.
 1.96 12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.95 24-Sep-2006  jmcneill Add "name" parameter to powerhook_establish, to aid debugging. No objections
on tech-kern@
 1.94 14-Apr-2006  christos branches: 1.94.8; 1.94.10;
Coverity CID 1531: Clarify why we cannot overrun static here, and use
__arraycount() instead of #define constant.
 1.93 11-Dec-2005  christos branches: 1.93.4; 1.93.6; 1.93.8; 1.93.10; 1.93.12;
merge ktrace-lwp.
 1.92 25-Aug-2005  drochner kill a number of autoconf submatch functions which follow the
standard scheme:
if (<configured> != <wildcard> && <configured> != <real>)
then fail
else
ask device match function

This is handled by config_stdsubmatch() now.
 1.91 25-Aug-2005  drochner replace the "locdesc_t" structure carrying the number of locators
explicitely by a plain integer array
the length in now known to all relevant parties, so this avoids
duplication of information, and we can allocate that thing in
drivers without hacks
 1.90 30-May-2005  christos branches: 1.90.2;
- add missing const
- fix variable shadowing
- remove unneeded casts
 1.89 27-Feb-2005  perry nuke trailing whitespace
 1.88 04-Feb-2005  perry de-__P
 1.87 13-Sep-2004  drochner branches: 1.87.4; 1.87.6;
use locator passing versions of xxxsubmatch() and simplify the code by
using arithmetics instead of case statements
 1.86 16-Aug-2004  mycroft Simplify some manipulation of PCIC_INTR.
Further attempt to mitigate "bad Vcc" errors.
 1.85 16-Aug-2004  mycroft Some tweaks, per the PC Card spec:
* Assert RESET before powering off a socket.
* Turn on the output enable bit earlier so the interface actually drives CEn
and RESET.
* Tighten up the power-on timing a bit.
* Mention the specific timing values named in the spec.

For pccbb, be careful to always power off before zeroing PWRCTL.
 1.84 12-Aug-2004  mycroft Copyright maintenance.
 1.83 12-Aug-2004  mycroft Various cleanup:
* Clean up the socket state earlier in the attach process -- not relying on
the socket attachment to do it.
* Get rid of PCIC_LASTSTATE_HALF. It's pointless.
* In pcic_wait_ready(), also check for the card vanishing, like in pccbb.
* Assert #RESET before powering up the card, not after. (I think it was
actually okay because the value was left as 0 from a previous disable or
the initial socket attach, but...
* If the card fails to come ready, don't bother reinstating windows or
anything -- just power it down.
 1.82 11-Aug-2004  mycroft Nuke the address windows earlier, before the socket is powered up. Just in
case there are remnants left behind.
 1.81 11-Aug-2004  mycroft Be more liberal in torching the old state in the disable and settype routines.
 1.80 11-Aug-2004  mycroft Rather than having a call up from the low-level driver to get the card type,
instead have a call down from the PCMCIA mid-layer to set it. Use this from
pcmcia_function_enable(). (Currently the policy is the same, but this would
allow for more flexibility in deciding which mode to use.)

Now it is safe to hold the socket enabled during attach, so do that. Only
one enable/disable cycle to attach a card now!
 1.79 07-Aug-2004  mycroft Clear the "card type" bit when powering up the socket, to make it more robust
for memory cards.
 1.78 20-Jun-2004  thorpej Define and use pcmciabuscf_controller as an alias for
cf_loc[PCMCIABUSCF_CONTROLLER] and pcmciabuscf_socket
as an alias for cf_loc[PCMCIABUSCF_SOCKET].
 1.77 28-Dec-2003  christos make the printf statements on chip_io_map complete lines.
 1.76 12-Sep-2003  mycroft The Ricoh power hackery is not reliable -- many cards just do not have the
voltage sense wired. So, disable it and force the card to 5V by default.
Also, recode the hack to use the "direct Vcc" feature of the chip, letting
it manage the voltage directly, as this is supported on both the 296 and
396.
 1.75 05-Sep-2003  mycroft Several changes to eliminate bogus controllers and sockets from being found:

PCIC_VENDOR_NONE: New.
PCIC_VENDOR_CIRRUS_*: Collapse the 2 chips into one vendor ID.

pcic_ident_ok(): Check the ID revision field -- if it's 0, punt.

pcic_vendor(): Check the ID revision field -- if it's 0, or the ID register
is all-1s, assume there is no chip present. (Previously this would return
"Unknown controller" -- which, AFAICT, *never* resulted in a working device.)
Do the Cirrus check only after verifying that we got the Intel ID.

pcic_attach(): Use a priori knowledge of the Cirrus chips to determine the
number of sockets rather than trying (unsuccessfully) to probe. Also, just
blast all of PCIC_INTR -- we do this in pcic_deactivate_card() anyway.
 1.74 03-Sep-2003  mycroft Fix another place where we blasted PCIC_INTR_ENABLE.
 1.73 02-Sep-2003  mycroft If the frontend passes in sc->irq=0, set PCIC_INTR_ENABLE. Also, don't clear
that bit all over the bloody place
 1.72 31-Jan-2003  thorpej branches: 1.72.2;
Use aprint_*().
 1.71 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.70 01-Jan-2003  thorpej Use aprint_normal() in cfprint routines.
 1.69 24-Nov-2002  takemura 3.3V support for Ricoh 5C[23]96 parts from ngc@ff.iij4u.or.jp.
Preliminary bridge identification code from imp@village.org.
 1.68 22-Oct-2002  simonb In pcic_chip_socket_enable() we need to set "reg" ifdef PCICDEBUG as
well so we can print it out a little further on.
While here, remove an unreachable "return" statement.
 1.67 27-Sep-2002  thorpej Introduce a new routine, config_match(), which invokes the
cfattach->ca_match function in behalf of the caller. Use it
rather than invoking cfattach->ca_match directly.
 1.66 01-Jun-2002  lukem SIMPLEQ rototill:
- implement SIMPLEQ_REMOVE(head, elm, type, field). whilst it's O(n),
this mirrors the functionality of SLIST_REMOVE() (the other
singly-linked list type) and FreeBSD's STAILQ_REMOVE()
- remove the unnecessary elm arg from SIMPLEQ_REMOVE_HEAD().
this mirrors the functionality of SLIST_REMOVE_HEAD() (the other
singly-linked list type) and FreeBSD's STAILQ_REMOVE_HEAD()
- remove notes about SIMPLEQ not supporting arbitrary element removal
- use SIMPLEQ_FOREACH() instead of home-grown for loops
- use SIMPLEQ_EMPTY() appropriately
- use SIMPLEQ_*() instead of accessing sqh_first,sqh_last,sqe_next directly
- reorder manual page; be consistent about how the types are listed
- other minor cleanups
 1.65 15-Dec-2001  soren branches: 1.65.8;
To make dev/pcmcia work on platforms with 64-bit bus_addr_t and
32-bit bus_size_t (sparc), change the pcmcia_mem_map(9) offsetp
argument to bus_size_t as it is used as a bus_space offset.
 1.64 15-Nov-2001  lukem don't need <sys/types.h> when including <sys/param.h>
 1.63 13-Nov-2001  lukem add/cleanup RCSID
 1.62 21-Feb-2001  jdolecek branches: 1.62.2; 1.62.4;
make some more constant arrays 'const'
 1.61 09-Jul-2000  mycroft Add missing newlines in some messages.
Set Vpp the same as Vcc by default. We need to do more with voltage sense.
 1.60 28-Jun-2000  mrg remove include of <vm/vm.h>. <vm/vm.h> -> <uvm/uvm_extern.h>
 1.59 03-Apr-2000  cgd branches: 1.59.4;
actually put a _comment_ before the second read of the ident register
that Charles added in rev 1.58. Not only is it good programming practice
to explain magic, but code that looks like:

reg = pcic_read(h, PCIC_IDENT);
reg = pcic_read(h, PCIC_IDENT);

is _gonna_ be interpreted as a cut-n-paste error by someone eventually.
 1.58 02-Apr-2000  mycroft During the socket probe, read the ident register twice.
I don't understand why, but sometimes the clone chips in hpcmips boxes read
all-0s the first time.
 1.57 23-Mar-2000  thorpej New callout mechanism with two major improvements over the old
timeout()/untimeout() API:
- Clients supply callout handle storage, thus eliminating problems of
resource allocation.
- Insertion and removal of callouts is constant time, important as
this facility is used quite a lot in the kernel.

The old timeout()/untimeout() API has been removed from the kernel.
 1.56 27-Feb-2000  enami Remove no longer necessary workaround for hpcmips.
 1.55 27-Feb-2000  augustss Use DPRINTF for debug messages.
 1.54 27-Feb-2000  mycroft Some minor cleanup to the probe code.
 1.53 26-Feb-2000  thorpej Put a lock on the pcic, to serialize access to the chip during event
handling. This is important when multiple cards are present when
the system boots, as we use tsleep now instead of delay in various
places (delay used to provide serialization by virtue of not causing
a context switch).
 1.52 25-Feb-2000  mycroft Be even more careful about cleaning up the socket at boot time.
Also, nuke the windows when the socket is disabled. (They might be deallocated
and reallocated, and would thus cause a conflict.)
 1.51 25-Feb-2000  mycroft Disable all windows at boot time, to avoid conflicts when reading the CIS.
Also, GC a small bit of code that's inaccesible after the previous change.
 1.50 25-Feb-2000  mycroft If we fail to attach the socket driver, clear PCIC_FLAG_SOCKETP so that we
don't try to use the socket any further. (This will only happen if the user
explicitly unconfigured some of the sockets.)
 1.49 22-Feb-2000  enami Cosmetic changes.
 1.48 21-Feb-2000  dbj added wmesg argument to pcic_delay debug printout
 1.47 10-Feb-2000  chopps always map attr memory 8 bit, since its defined that way.
 1.46 05-Feb-2000  nathanw LP64 printf fixes.
 1.45 05-Feb-2000  enami Yet anothor workaround for hpcmips. I guess real problem is somewhere else...

With rev.1.37, my MobileGearII for DoCoMo finds both ne0 and wd0
even if pcic_delay_sleep is 1.
With rev 1.40, it fails to find wd0.
 1.44 04-Feb-2000  enami s/SYSTEM/SYSMEM/; so that this file compiles again.
 1.43 04-Feb-2000  joda fix previous broken commit of the 8-bit memory handling (spotted
by Christian Hopps); this will enable 16-bit memory accesses for devices
that can handle it
 1.42 04-Feb-2000  itojun cope with card insertion/removal during suspend-resume session.
(removal/ insertion after suspend and before resume)

How should we deal with card swaps?
 1.41 04-Feb-2000  chopps keep track of the enabled state of a socket
 1.40 03-Feb-2000  enami Remove temporary workaround for hpcmips. Now it works without it.
 1.39 03-Feb-2000  enami Cosmetic changes; remove unnecessary semi-colon.
 1.38 03-Feb-2000  chopps attempt to make this more like the std indicates
 1.37 02-Feb-2000  enami Fix typo; not PCIC_DEBUG but PCICDEBUG.
 1.36 02-Feb-2000  enami - No need to wait in pcic_chip_socket_disable. It was intended to keep
some period between disable and enable in spec, but is done in
pcic_chip_socket_disable. And we also disable socket in pcic_deactivate_card,
we should do it in another way if it is really necessary.
- Shorten the wait message so that ps(1) and ps in ddb be happy.
- Replace newly added long delay with sleep.
 1.35 02-Feb-2000  enami Cosmetic changes.
 1.34 02-Feb-2000  chopps do something more like pccbbs chip_enable. don't enable interrupts
until we have everything else setup..
 1.33 01-Feb-2000  chopps implement probing for available irqs on non-cirrus pcmcia controllers
including cardbus controllers running in pcic mode
 1.32 27-Jan-2000  enami Use delay by default on hpcmips for now.
 1.31 25-Jan-2000  chopps make the wait_ready loop use pcic_delay() (thus tsleep) too for cards
that take a while to become ready
 1.30 25-Jan-2000  enami Replace long delay with sleep.
 1.29 25-Jan-2000  enami Use config_pending and let the kernel thread to attach a card even on boot.
 1.28 13-Jan-2000  joda (pcic_chip_do_mem_map): handle 8-bit memory
 1.27 02-Jan-2000  sommerfeld minor KNF tweaks
 1.26 01-Jan-2000  sommerfeld On a cold suspend to disk, the Sony VAIO Z505 BIOS appears to not
preserve enough of the state of the PCIC to keep it interrupting on
card insertion/removal..

Add a power hook to notice if the CSC_INTR device register is zeroed
on resume, and if so, reset it to a sane value.
 1.25 15-Oct-1999  haya branches: 1.25.2;
This is the first check-in of CardBus driver. CardBus driver contains
CardBus bus stub, YENTA PCI-CardBus bridge (cbb), 3Com 3C575TX driver
(ex) and Intel fxp driver.

TODO:
o Conform to the KNF more strictly.
o Be unified with pcmcia code as much as possible.
o Add more drivers for CardBus card, such as APA-1480 or USB card.

The affected files are listed below.

sys/arch/i386/conf/files.i386
sys/arch/macppc/conf/files.macppc
sys/conf/files
sys/dev/ic/elinkxl.c
sys/dev/ic/elinkxlvar.h
sys/dev/ic/i82365.c
sys/dev/ic/i82365var.h
sys/dev/isa/i82365_isasubr.c
sys/dev/pci/files.pci
sys/dev/pcmcia/pcmcia.c
sys/dev/pcmcia/pcmciachip.h

The added files are listed below.

sys/arch/i386/conf/CARDBUS
sys/arch/i386/include/rbus_machdep.h
sys/arch/i386/i386/rbus_machdep.c
sys/arch/macppc/include/rbus_machdep.h
sys/arch/macppc/macppc/rbus_machdep.c
sys/dev/cardbus/if_ex_cardbus.c
sys/dev/cardbus/Makefile.cardbusdevs
sys/dev/cardbus/cardbus.c
sys/dev/cardbus/cardbus_map.c
sys/dev/cardbus/cardbusdevs
sys/dev/cardbus/cardbusdevs.h
sys/dev/cardbus/cardbusdevs_data.h
sys/dev/cardbus/cardbusvar.h
sys/dev/cardbus/cardslot.c
sys/dev/cardbus/cardslotvar.h
sys/dev/cardbus/devlist2h.awk
sys/dev/cardbus/files.cardbus
sys/dev/cardbus/if_fxp_cardbus.c
sys/dev/cardbus/pccardcis.h
sys/dev/cardbus/rbus.c
sys/dev/cardbus/rbus.h
sys/dev/pci/pccbb.c
sys/dev/pci/pccbbreg.h
sys/dev/pci/pccbbvar.h
 1.24 06-Jul-1999  thorpej branches: 1.24.2;
Make the kthread API a bit more friendly to loadable kernel modules.
 1.23 19-Feb-1999  mycroft branches: 1.23.4;
Oops; PCIC_INTR_ENABLE does something *very* different.
 1.22 19-Feb-1999  mycroft Yet another path where we need to set PCIC_INTR_ENABLE.
 1.21 01-Feb-1999  marc - make sure that sc->handle[i].flags is initialized in all cases
- check PCIC_FLAG_SOCKETP before disabling the CSC_INTR.
 1.20 21-Jan-1999  msaitoh Fix about insertion/removal event problem.
 1.19 01-Jan-1999  christos PR/6669: Michael Eriksson: pcic_chip_mem_alloc() can't handle large requests
 1.18 25-Dec-1998  msaitoh fix incorrect panic message
 1.17 20-Dec-1998  nathanw Fix up support for PCI attachments of pcic devices on i386 in general,
and the Cirrus Logic CL-PD6729 in particular.

From danw@mit.edu in PR port-i386/6436.
 1.16 27-Nov-1998  thorpej Update for new pcmciabus attribute.
 1.15 17-Nov-1998  thorpej Finish implementing interrupt-driven card insertion and removal support.

- Deactivate the card on removal and queue a REMOVAL event for the socket's
event thread to finish the detach.
- Queue an INSERTION event for the socket's event thread on insertion.

Implement a few missing infrastructure pieces to support this.

Hot swapping of PCMCIA cards now "works". (Not quite; things like network
devices need changes for their respestive subsystems. These changes are
coming soon...)
 1.14 16-Nov-1998  thorpej Implement a kernel thread per PCMCIA socket to handle card insertion and
removal events.
 1.13 09-Nov-1998  msaitoh Sorry, I forgot to revert "#if 0".
 1.12 05-Nov-1998  msaitoh fix pcic_chip_socket_enable() to works on more machines.
 1.11 15-Oct-1998  mycroft pcic_wait_ready(): If we didn't get READY, print out the current status.
 1.10 09-Jun-1998  thorpej Nuke __BROKEN_INDIRECT_CONFIG.
 1.9 05-May-1998  enami When changing power, wait enough to keep timing constraint
described in PCMCIA specification.
 1.8 01-Feb-1998  marc move pcic_wait_ready from i82365var.h to i82365.c
 1.7 12-Jan-1998  thorpej Adjust for config changes.
 1.6 19-Oct-1997  enami branches: 1.6.2;
Fix typo; hang binary operator at the end of previous line.
 1.5 19-Oct-1997  enami Include locators.h and use symbolic name comes from it.
 1.4 17-Oct-1997  enami Define width_names[] only when PCICDEBUG is defined.
 1.3 17-Oct-1997  enami No need to cast a generic pointer.
 1.2 16-Oct-1997  thorpej Pull marc-pcmcia branch down to trunk.
 1.1 30-Jul-1997  marc branches: 1.1.2;
file i82365.c was initially added on branch marc-pcmcia.
 1.1.2.16 17-Oct-1997  enami Define width_names[] only when PCICDEBUG is defined.
 1.1.2.15 16-Oct-1997  thorpej Copyright/license update.
 1.1.2.14 16-Oct-1997  thorpej Pass down the start and side of the i/o space allocation range to
the "pcmcia" layer so that drivers with Very Special i/o space allocation
needs can know what range they should be dealing with.
 1.1.2.13 16-Oct-1997  enami Handle the case PCMCIA_WIDTH_AUTO.
 1.1.2.12 16-Oct-1997  thorpej KNF, RCS IDs.
 1.1.2.11 14-Oct-1997  thorpej Allow the i/o address alignment to be specified in the call to
pcmcia_io_alloc(). If the caller does not care about the alignment, 0
should be passed.
 1.1.2.10 27-Sep-1997  marc add power management support.
 1.1.2.9 04-Sep-1997  jtk fix typo resulting from code cut&paste
 1.1.2.8 28-Aug-1997  marc Rip out all the isa-specific code, so this can be shared with a pci
attachment.
 1.1.2.7 23-Aug-1997  thorpej Add stub socket enable/disable functions.
 1.1.2.6 14-Aug-1997  jtk add PCIC_ALLOC_IOBASE option & patchable value, so hardware with
missing address lines can be configured to allocate addresses that work

fix case where irq on pcic? is hardwired in config file

print out port ranges used by configured devices
 1.1.2.5 11-Aug-1997  thorpej In the chip-level interrupt establish functions, check the pcmcia function's
configuration entry, making note of the interrupt sharing type. Pass the
correct type to isa_intr_alloc(), so that dynamically allocated interrupts
can be shared.

Also, provide a compile-time/patchable variable that sets the valid
IRQ mask for IRQ allocation, in order to deal with some chipsets that
seem to only allow one IRQ for PCMCIA devices.
 1.1.2.4 10-Aug-1997  thorpej Create a structure to encapsulate information about allocated i/o and
mem space on the pcmcia bus. Use this in chip-level window enable
functions rather than making assumptions about the bus space handles.
 1.1.2.3 31-Jul-1997  thorpej In pcic_chip_intr_establish():
- Update for additional "irqmask" argument.
- Don't attempt to allocate IRQs that are not in the PCIC's list of
valid IRQs.
- Clear the IRQ bits in the PCIC_INTR register value before OR'ing in
the new value, to avoid accidentally setting a bogus IRQ.

In pcic_chip_intr_disestablish():
- Before removing the interrupt handler, clear the IRQ and "enable" bits
in the PCIC_INTR register so that we don't get spurious interrupts
later.
 1.1.2.2 30-Jul-1997  thorpej If Really Verbse Debugging is compiled in, use a patchable variable to
turn the messages on/off, so you can clean up the output without rebuilding.
 1.1.2.1 30-Jul-1997  marc added pcmcia infrastructure and a few devices
 1.6.2.1 02-Feb-1999  cgd patch to improve PCMCIA card powerup sequence, assembled from
parts (but not all) of various revisions in -current. (msaitoh)
 1.23.4.1 02-Aug-1999  thorpej Update from trunk.
 1.24.2.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.25.2.2 12-Mar-2001  bouyer Sync with HEAD.
 1.25.2.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.59.4.1 27-Jul-2000  mycroft Approved by thorpej:
Set Vpp=Vcc.
Add missing newlines in some messages.

syssrc/sys/dev/ic/i82365.c 1.60 -> 1.61
 1.62.4.3 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.62.4.2 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.62.4.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.62.2.8 03-Jan-2003  thorpej Sync with HEAD.
 1.62.2.7 11-Dec-2002  thorpej Sync with HEAD.
 1.62.2.6 11-Nov-2002  nathanw Catch up to -current
 1.62.2.5 18-Oct-2002  nathanw Catch up to -current.
 1.62.2.4 24-Jun-2002  nathanw Curproc->curlwp renaming.

Change uses of "curproc->l_proc" back to "curproc", which is more like the
original use. Bare uses of "curproc" are now "curlwp".

"curproc" is now #defined in proc.h as ((curlwp) ? (curlwp)->l_proc) : NULL)
so that it is always safe to reference curproc (*de*referencing curproc
is another story, but that's always been true).
 1.62.2.3 20-Jun-2002  nathanw Catch up to -current.
 1.62.2.2 08-Jan-2002  nathanw Catch up to -current.
 1.62.2.1 14-Nov-2001  nathanw Catch up to -current.
 1.65.8.1 20-Jun-2002  gehenna catch up with -current.
 1.72.2.8 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.72.2.7 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.72.2.6 04-Feb-2005  skrll Sync with HEAD.
 1.72.2.5 21-Sep-2004  skrll Fix the sync with head I botched.
 1.72.2.4 18-Sep-2004  skrll Sync with HEAD.
 1.72.2.3 25-Aug-2004  skrll Sync with HEAD.
 1.72.2.2 12-Aug-2004  skrll Sync with HEAD.
 1.72.2.1 03-Aug-2004  skrll Sync with HEAD
 1.87.6.2 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.87.6.1 12-Feb-2005  yamt sync with head.
 1.87.4.1 29-Apr-2005  kent sync with -current
 1.90.2.5 07-Dec-2007  yamt sync with head
 1.90.2.4 27-Oct-2007  yamt sync with head.
 1.90.2.3 03-Sep-2007  yamt sync with head.
 1.90.2.2 30-Dec-2006  yamt sync with head.
 1.90.2.1 21-Jun-2006  yamt sync with head.
 1.93.12.1 24-May-2006  tron Merge 2006-05-24 NetBSD-current into the "peter-altq" branch.
 1.93.10.1 19-Apr-2006  elad sync with head.
 1.93.8.1 24-May-2006  yamt sync with head.
 1.93.6.1 22-Apr-2006  simonb Sync with head.
 1.93.4.1 09-Sep-2006  rpaulo sync with head
 1.94.10.2 10-Dec-2006  yamt sync with head.
 1.94.10.1 22-Oct-2006  yamt sync with head
 1.94.8.1 18-Nov-2006  ad Sync with head.
 1.97.4.1 12-Mar-2007  rmind Sync with HEAD.
 1.98.4.1 11-Jul-2007  mjf Sync with head.
 1.98.2.5 23-Oct-2007  ad Sync with head.
 1.98.2.4 01-Jul-2007  ad Adapt to callout API change.
 1.98.2.3 13-May-2007  ad - Pass the error number and residual count to biodone(), and let it handle
setting error indicators. Prepare to eliminate B_ERROR.
- Add a flag argument to brelse() to be set into the buf's flags, instead
of doing it directly. Typically used to set B_INVAL.
- Add a "struct cpu_info *" argument to kthread_create(), to be used to
create bound threads. Change "bool mpsafe" to "int flags".
- Allow exit of LWPs in the IDL state when (l != curlwp).
- More locking fixes & conversion to the new API.
 1.98.2.2 10-Apr-2007  ad Nuke the deferred kthread creation stuff, as it's no longer needed.
Pointed out by thorpej@.
 1.98.2.1 09-Apr-2007  ad - Add two new arguments to kthread_create1: pri_t pri, bool mpsafe.
- Fork kthreads off proc0 as new LWPs, not new processes.
 1.99.12.1 25-Oct-2007  bouyer Sync with HEAD.
 1.99.8.2 09-Jan-2008  matt sync with HEAD
 1.99.8.1 06-Nov-2007  matt sync with HEAD
 1.99.6.2 09-Dec-2007  jmcneill Sync with HEAD.
 1.99.6.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.100.4.1 08-Dec-2007  ad Sync with head.
 1.100.2.1 08-Dec-2007  mjf Sync with HEAD.
 1.101.12.2 17-Jan-2009  mjf Sync with HEAD.
 1.101.12.1 02-Jun-2008  mjf Sync with HEAD.
 1.102.20.1 21-Apr-2010  matt sync to netbsd-5
 1.102.18.1 14-Aug-2009  snj Pull up following revision(s) (requested by jun in ticket #899):
sys/dev/ic/i82365.c: revision 1.108
fix pcic kthread creation timing.
see http://mail-index.netbsd.org/current-users/2008/07/15/msg003526.html
fix kern/41791 & port-hpcmips/41164.
ok by uwe & tsutsui
 1.102.14.1 14-Aug-2009  snj Pull up following revision(s) (requested by jun in ticket #899):
sys/dev/ic/i82365.c: revision 1.108
fix pcic kthread creation timing.
see http://mail-index.netbsd.org/current-users/2008/07/15/msg003526.html
fix kern/41791 & port-hpcmips/41164.
ok by uwe & tsutsui
 1.102.12.2 28-Apr-2009  skrll Sync with HEAD.
 1.102.12.1 19-Jan-2009  skrll Sync with HEAD.
 1.102.4.6 11-Aug-2010  yamt sync with head.
 1.102.4.5 11-Mar-2010  yamt sync with head
 1.102.4.4 16-Sep-2009  yamt sync with head
 1.102.4.3 19-Aug-2009  yamt sync with head.
 1.102.4.2 16-May-2009  yamt sync with head
 1.102.4.1 04-May-2009  yamt sync with head.
 1.103.2.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.111.4.1 30-May-2010  rmind sync with head
 1.111.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.114.12.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.114.12.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.114.2.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.114.2.1 30-Oct-2012  yamt sync with head
 1.115.2.1 18-May-2014  rmind sync with head
 1.116.46.2 22-Mar-2021  thorpej Audit CFARG_IATTR in config_found() calls, and remove it in situations
where the interface attribute is not ambiguous.
 1.116.46.1 22-Mar-2021  thorpej Mechanical conversion of config_found_sm_loc() -> config_found().
CFARG_IATTR usage needs to be audited.
 1.117.8.1 04-Aug-2021  thorpej Adapt to CFARGS().
 1.10 11-Dec-2005  christos merge ktrace-lwp.
 1.9 06-Jul-2004  mycroft Add Cirrus register definitions, per PR 6172.
 1.8 12-Sep-2003  mycroft The Ricoh power hackery is not reliable -- many cards just do not have the
voltage sense wired. So, disable it and force the card to 5V by default.
Also, recode the hack to use the "direct Vcc" feature of the chip, letting
it manage the voltage directly, as this is supported on both the 296 and
396.
 1.7 24-Nov-2002  takemura branches: 1.7.6;
3.3V support for Ricoh 5C[23]96 parts from ngc@ff.iij4u.or.jp.
Preliminary bridge identification code from imp@village.org.
 1.6 28-Feb-2000  mycroft branches: 1.6.6;
Give the VPP bits better names.
 1.5 01-Feb-2000  chopps implement probing for available irqs on non-cirrus pcmcia controllers
including cardbus controllers running in pcic mode
 1.4 01-Jan-2000  sommerfeld On a cold suspend to disk, the Sony VAIO Z505 BIOS appears to not
preserve enough of the state of the PCIC to keep it interrupting on
card insertion/removal..

Add a power hook to notice if the CSC_INTR device register is zeroed
on resume, and if so, reset it to a sane value.
 1.3 20-Dec-1998  nathanw branches: 1.3.8;
Fix up support for PCI attachments of pcic devices on i386 in general,
and the Cirrus Logic CL-PD6729 in particular.

From danw@mit.edu in PR port-i386/6436.
 1.2 16-Oct-1997  thorpej Pull marc-pcmcia branch down to trunk.
 1.1 30-Jul-1997  marc branches: 1.1.2;
file i82365reg.h was initially added on branch marc-pcmcia.
 1.1.2.4 16-Oct-1997  thorpej Copyright/license update.
 1.1.2.3 16-Oct-1997  thorpej KNF, RCS IDs.
 1.1.2.2 27-Sep-1997  marc add defines for counts of number of IO and MEM windows
 1.1.2.1 30-Jul-1997  marc added pcmcia infrastructure and a few devices
 1.3.8.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.6.6.1 11-Dec-2002  thorpej Sync with HEAD.
 1.7.6.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.7.6.2 18-Sep-2004  skrll Sync with HEAD.
 1.7.6.1 03-Aug-2004  skrll Sync with HEAD
 1.33 14-Sep-2024  andvar s/intterupt/interrupt/ in comments.
 1.32 27-Oct-2012  chs branches: 1.32.76;
split device_t/softc for all remaining drivers.
replace "struct device *" with "device_t".
use device_xname(), device_unit(), etc.
 1.31 17-Sep-2009  tsutsui branches: 1.31.12; 1.31.22;
Misc KNF and cosmetics, and remove unnecessary casts etc.
 1.30 14-Sep-2009  tsutsui u_intNN_t -> uintNN_t
 1.29 12-May-2009  cegger struct device * -> device_t, no functional changes intended.
 1.28 05-Dec-2007  ad branches: 1.28.16; 1.28.30;
lockmgr -> mutex
 1.27 09-Jul-2007  ad branches: 1.27.6; 1.27.8; 1.27.14; 1.27.16;
Merge some of the less invasive changes from the vmlocking branch:

- kthread, callout, devsw API changes
- select()/poll() improvements
- miscellaneous MT safety improvements
 1.26 16-Feb-2006  perry branches: 1.26.24; 1.26.26;
Change "inline" back to "__inline" in .h files -- C99 is still too
new, and some apps compile things in C89 mode. C89 keywords stay.

As per core@.
 1.25 24-Dec-2005  perry branches: 1.25.2; 1.25.4; 1.25.6;
Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.24 11-Dec-2005  christos merge ktrace-lwp.
 1.23 30-May-2005  christos branches: 1.23.2;
- add missing const
- fix variable shadowing
- remove unneeded casts
 1.22 04-Feb-2005  perry de-__P
 1.21 13-Sep-2004  drochner branches: 1.21.4; 1.21.6;
use locator passing versions of xxxsubmatch() and simplify the code by
using arithmetics instead of case statements
 1.20 12-Aug-2004  mycroft Various cleanup:
* Clean up the socket state earlier in the attach process -- not relying on
the socket attachment to do it.
* Get rid of PCIC_LASTSTATE_HALF. It's pointless.
* In pcic_wait_ready(), also check for the card vanishing, like in pccbb.
* Assert #RESET before powering up the card, not after. (I think it was
actually okay because the value was left as 0 from a previous disable or
the initial socket attach, but...
* If the card fails to come ready, don't bother reinstating windows or
anything -- just power it down.
 1.19 11-Aug-2004  mycroft Rather than having a call up from the low-level driver to get the card type,
instead have a call down from the PCMCIA mid-layer to set it. Use this from
pcmcia_function_enable(). (Currently the policy is the same, but this would
allow for more flexibility in deciding which mode to use.)

Now it is safe to hold the socket enabled during attach, so do that. Only
one enable/disable cycle to attach a card now!
 1.18 05-Sep-2003  mycroft Several changes to eliminate bogus controllers and sockets from being found:

PCIC_VENDOR_NONE: New.
PCIC_VENDOR_CIRRUS_*: Collapse the 2 chips into one vendor ID.

pcic_ident_ok(): Check the ID revision field -- if it's 0, punt.

pcic_vendor(): Check the ID revision field -- if it's 0, or the ID register
is all-1s, assume there is no chip present. (Previously this would return
"Unknown controller" -- which, AFAICT, *never* resulted in a working device.)
Do the Cirrus check only after verifying that we got the Intel ID.

pcic_attach(): Use a priori knowledge of the Cirrus chips to determine the
number of sockets rather than trying (unsuccessfully) to probe. Also, just
blast all of PCIC_INTR -- we do this in pcic_deactivate_card() anyway.
 1.17 24-Nov-2002  takemura branches: 1.17.6;
3.3V support for Ricoh 5C[23]96 parts from ngc@ff.iij4u.or.jp.
Preliminary bridge identification code from imp@village.org.
 1.16 15-Dec-2001  soren To make dev/pcmcia work on platforms with 64-bit bus_addr_t and
32-bit bus_size_t (sparc), change the pcmcia_mem_map(9) offsetp
argument to bus_size_t as it is used as a bus_space offset.
 1.15 23-Mar-2000  thorpej branches: 1.15.6; 1.15.8;
New callout mechanism with two major improvements over the old
timeout()/untimeout() API:
- Clients supply callout handle storage, thus eliminating problems of
resource allocation.
- Insertion and removal of callouts is constant time, important as
this facility is used quite a lot in the kernel.

The old timeout()/untimeout() API has been removed from the kernel.
 1.14 26-Feb-2000  thorpej Put a lock on the pcic, to serialize access to the chip during event
handling. This is important when multiple cards are present when
the system boots, as we use tsleep now instead of delay in various
places (delay used to provide serialization by virtue of not causing
a context switch).
 1.13 22-Feb-2000  thorpej Don't use void * for chipset tags. Bad hacker, no biscuit.
 1.12 08-Feb-2000  mycroft Forgotten part of chopps\'s i82365_isasubr.c commit.
 1.11 04-Feb-2000  chopps keep track of the enabled state of a socket
 1.10 02-Feb-2000  enami Cosmetic changes.
 1.9 01-Feb-2000  chopps implement probing for available irqs on non-cirrus pcmcia controllers
including cardbus controllers running in pcic mode
 1.8 15-Oct-1999  haya branches: 1.8.2;
This is the first check-in of CardBus driver. CardBus driver contains
CardBus bus stub, YENTA PCI-CardBus bridge (cbb), 3Com 3C575TX driver
(ex) and Intel fxp driver.

TODO:
o Conform to the KNF more strictly.
o Be unified with pcmcia code as much as possible.
o Add more drivers for CardBus card, such as APA-1480 or USB card.

The affected files are listed below.

sys/arch/i386/conf/files.i386
sys/arch/macppc/conf/files.macppc
sys/conf/files
sys/dev/ic/elinkxl.c
sys/dev/ic/elinkxlvar.h
sys/dev/ic/i82365.c
sys/dev/ic/i82365var.h
sys/dev/isa/i82365_isasubr.c
sys/dev/pci/files.pci
sys/dev/pcmcia/pcmcia.c
sys/dev/pcmcia/pcmciachip.h

The added files are listed below.

sys/arch/i386/conf/CARDBUS
sys/arch/i386/include/rbus_machdep.h
sys/arch/i386/i386/rbus_machdep.c
sys/arch/macppc/include/rbus_machdep.h
sys/arch/macppc/macppc/rbus_machdep.c
sys/dev/cardbus/if_ex_cardbus.c
sys/dev/cardbus/Makefile.cardbusdevs
sys/dev/cardbus/cardbus.c
sys/dev/cardbus/cardbus_map.c
sys/dev/cardbus/cardbusdevs
sys/dev/cardbus/cardbusdevs.h
sys/dev/cardbus/cardbusdevs_data.h
sys/dev/cardbus/cardbusvar.h
sys/dev/cardbus/cardslot.c
sys/dev/cardbus/cardslotvar.h
sys/dev/cardbus/devlist2h.awk
sys/dev/cardbus/files.cardbus
sys/dev/cardbus/if_fxp_cardbus.c
sys/dev/cardbus/pccardcis.h
sys/dev/cardbus/rbus.c
sys/dev/cardbus/rbus.h
sys/dev/pci/pccbb.c
sys/dev/pci/pccbbreg.h
sys/dev/pci/pccbbvar.h
 1.7 21-Jan-1999  msaitoh branches: 1.7.8;
Fix about insertion/removal event problem.
 1.6 01-Jan-1999  christos PR/6669: Michael Eriksson: pcic_chip_mem_alloc() can't handle large requests
 1.5 16-Nov-1998  thorpej Implement a kernel thread per PCMCIA socket to handle card insertion and
removal events.
 1.4 23-May-1998  matt Changes so that these compile on NetBSD/alpha as well as NetBSD/i386.
 1.3 01-Feb-1998  marc move pcic_wait_ready to i82365.c
 1.2 16-Oct-1997  thorpej Pull marc-pcmcia branch down to trunk.
 1.1 28-Aug-1997  marc branches: 1.1.2;
file i82365var.h was initially added on branch marc-pcmcia.
 1.1.2.5 16-Oct-1997  thorpej Copyright/license update.
 1.1.2.4 16-Oct-1997  thorpej KNF, RCS IDs.
 1.1.2.3 14-Oct-1997  thorpej Allow the i/o address alignment to be specified in the call to
pcmcia_io_alloc(). If the caller does not care about the alignment, 0
should be passed.
 1.1.2.2 27-Sep-1997  marc add fields to pcic_handle for power management
add fields to pcic_softc for probing the io bus width
 1.1.2.1 28-Aug-1997  marc common declarations from i82365 driver bus split
 1.7.8.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.8.2.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.15.8.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.15.6.2 11-Dec-2002  thorpej Sync with HEAD.
 1.15.6.1 08-Jan-2002  nathanw Catch up to -current.
 1.17.6.7 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.17.6.6 04-Feb-2005  skrll Sync with HEAD.
 1.17.6.5 21-Sep-2004  skrll Fix the sync with head I botched.
 1.17.6.4 18-Sep-2004  skrll Sync with HEAD.
 1.17.6.3 25-Aug-2004  skrll Sync with HEAD.
 1.17.6.2 12-Aug-2004  skrll Sync with HEAD.
 1.17.6.1 03-Aug-2004  skrll Sync with HEAD
 1.21.6.1 12-Feb-2005  yamt sync with head.
 1.21.4.1 29-Apr-2005  kent sync with -current
 1.23.2.3 07-Dec-2007  yamt sync with head
 1.23.2.2 03-Sep-2007  yamt sync with head.
 1.23.2.1 21-Jun-2006  yamt sync with head.
 1.25.6.1 22-Apr-2006  simonb Sync with head.
 1.25.4.1 09-Sep-2006  rpaulo sync with head
 1.25.2.1 18-Feb-2006  yamt sync with head.
 1.26.26.1 11-Jul-2007  mjf Sync with head.
 1.26.24.1 09-Apr-2007  ad - Add two new arguments to kthread_create1: pri_t pri, bool mpsafe.
- Fork kthreads off proc0 as new LWPs, not new processes.
 1.27.16.1 08-Dec-2007  ad Sync with head.
 1.27.14.1 08-Dec-2007  mjf Sync with HEAD.
 1.27.8.1 09-Jan-2008  matt sync with HEAD
 1.27.6.1 09-Dec-2007  jmcneill Sync with HEAD.
 1.28.30.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.28.16.3 11-Mar-2010  yamt sync with head
 1.28.16.2 16-Sep-2009  yamt sync with head
 1.28.16.1 16-May-2009  yamt sync with head
 1.31.22.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.31.12.1 30-Oct-2012  yamt sync with head
 1.32.76.1 02-Aug-2025  perseant Sync with HEAD
 1.5 28-Jun-1995  cgd move to more appropriate (...reg.h) names.
 1.4 27-Oct-1994  cgd new RCS ID format.
 1.3 01-Mar-1994  mycroft New constants for setting and clearing masks.
 1.2 22-May-1993  cgd branches: 1.2.4;
add rcsids to everything and clean up headers
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.2.4.1 14-Oct-1993  mycroft Add some bits from the `single mask' register.
 1.8 11-Dec-2005  christos merge ktrace-lwp.
 1.7 27-Feb-2005  perry nuke trailing whitespace
 1.6 29-May-1997  mycroft branches: 1.6.56; 1.6.64; 1.6.66;
Add DMA37MD_DEMAND and DMA37MD_BLOCK.
 1.5 01-Mar-1996  mycroft Add bit definition for auto-initialize mode.
 1.4 27-Oct-1994  cgd new RCS ID format.
 1.3 01-Mar-1994  mycroft New constants for setting and clearing masks.
 1.2 22-May-1993  cgd branches: 1.2.4;
add rcsids to everything and clean up headers
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.2.4.1 14-Oct-1993  mycroft Add some bits from the `single mask' register.
 1.6.66.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.6.64.1 29-Apr-2005  kent sync with -current
 1.6.56.1 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.9 11-Dec-2005  christos merge ktrace-lwp.
 1.8 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22364, verified by myself.
 1.7 03-May-2003  wiz branches: 1.7.2;
DMA, not dma nor Dma.
 1.6 21-Feb-2003  tsutsui hz -> Hz
 1.5 19-Jan-1998  drochner define offsets into "register window" instead of absolute ISA addresses
for better use in a bus-ified environment
 1.4 27-Oct-1994  cgd new RCS ID format.
 1.3 15-Jun-1993  mycroft branches: 1.3.4;
Move definitions of TIMER_FREQ to timerreg.h, and fix value of CF for DELAY().
 1.2 22-May-1993  cgd add rcsids to everything and clean up headers
 1.1 23-Mar-1993  cgd added support for microtime routines by Steve McCanne (mccanne@ee.lbl.gov)
 1.3.4.2 24-Sep-1993  mycroft clock.c: Finish conversion. Make rtcput() work if VRT bit not set. Speed up
time conversion in delay().
fd.c: Minor changes to autoconfig. Use dv_parent rather than storing another
pointer to the fdc_softc in each fd_softc. Change disk label stuff for our
kernel.
icu.s: Make splx() and splnone() return previous cpl for now.
isa.c: Minor autoconfig changes.
isa.h: rtcin() is now nvram() and is declare in nvram.h. Make isaphysmem a
caddr_t.
pccons.c: XXXX: Maybe we should insist they open /dev/io now.
timerreg.h: #define TIMER_NPORTS.
wd.c: Delete unused wdnoreloc() and wddospart(), and use remaining two bits in
unit number. struct disk --> struct wd_softc. struct board --> struct
wdc_softc. Still needs much work.
 1.3.4.1 14-Sep-1993  mycroft New i386 code.
 1.7.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.7.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.7.2.1 03-Aug-2004  skrll Sync with HEAD
 1.162 29-Jun-2024  riastradh if_stats(9): Add ifp argument to if_stat..._ref.

This will enable us to pass the ifp through to a dtrace probe inside.

No functional change intended in this change, but this is an API
change visible to modules so it shouldn't be pulled up.

PR kern/58377
 1.161 09-Feb-2024  andvar fix spelling mistakes, mainly in comments and log messages.
 1.160 25-Jun-2022  tsutsui Pass proper status values to rnd_add_uint32(9) as rnd(9) man page claims.
 1.159 07-Feb-2020  thorpej Use callout_setfunc() / callout_schedule().
 1.158 04-Feb-2020  thorpej Use ifmedia_fini().
 1.157 29-Jan-2020  thorpej Adopt <net/if_stats.h>.
 1.156 30-Oct-2019  msaitoh branches: 1.156.2;
if_percpuq(9) automatically increments if_ipackets, so don't add number of
RX frames from device's statistics counter to if_ipackets to avoid double
count.
 1.155 20-Sep-2019  maxv Fix direction of the loop.

Found by the lgtm bot.
 1.154 09-Jul-2019  msaitoh branches: 1.154.2;
Don't automatically set ec_capenable's ETHERCAP_VLAN_HWTAGGING bit in
vlan_config() to make it user-controllable. Instead, set the bit in
xxx_attach().
 1.153 28-May-2019  msaitoh Use ETHER_LOCK()/ETHER_UNLOCK() for all ethernet drivers to protect ec_multi*.
 1.152 23-May-2019  msaitoh No functional change:
- Simplify MII structure initialization and reference.
- u_int*_t -> uint*_t.
- KNF
 1.151 22-Apr-2019  msaitoh In drivers which use MII(4) and have hook SIOC[GS]IFMEDIA which just pass to
ifmedia_ioctl(), the hook is not required because ether_ioctl has it
(if_ethersubr.c rev. 1.160). These drivers don't return ENETRESET in
ifmedia_ioctl(), so no functional change.
 1.150 22-Jan-2019  msaitoh Change MII PHY read/write API from:

int (*mii_readreg_t)(device_t, int, int);
void (*mii_writereg_t)(device_t, int, int, int);
to:

int (*mii_readreg_t)(device_t, int, int, uint16_t *);
int (*mii_writereg_t)(device_t, int, int, uint16_t);

Now we can test if a read/write operation failed or not by the return value.

In 802.3 spec says that the PHY shall not respond to read/write transaction
to the unimplemented register(22.2.4.3). Detecting timeout can be used to
check whether a register is implemented or not (if the register conforms to
the spec). ukphy(4) can be used this for MII_MMDACR and MII_MMDAADR.

Note that I noticed that the following code do infinite loop in the
read/wirte function. If it accesses unimplemented PHY register, it will hang.
It should be fixed:

arm/at91/at91emac.c
arm/ep93xx/epe.c
arm/omap/omapl1x_emac.c
mips/ralink/ralink_eth.c
arch/powerpc/booke/dev/pq3etsec.c(read)
dev/cadence/if_cemac.c <- hkenken
dev/ic/lan9118.c


Tested with the following device:

axe+ukphy
axe+rgephy
axen+rgephy (tested by Andrius V)
wm+atphy
wm+ukphy
wm+igphy
wm+ihphy
wm+makphy
sk+makphy
sk+brgphy
sk+gentbi
msk+makphy
sip+icsphy
sip+ukphy
re+rgephy
bge+brgphy
bnx+brgphy
gsip+gphyter
rtk+rlphy
fxp+inphy (tested by Andrius V)
tlp+acphy
ex+exphy
epic+qsphy
vge+ciphy (tested by Andrius V)
vr+ukphy (tested by Andrius V)
vte+ukphy (tested by Andrius V)

Not tested (MAC):
arm:at91emac
arm:cemac
arm:epe
arm:geminigmac
arm:enet
arm:cpsw
arm:emac(omac)
arm:emac(sunxi)
arm:npe
evbppc:temac
macppc:bm
macppc:gm
mips:aumac
mips:ae
mips:cnmac
mips:reth
mips:sbmac
playstation2:smap
powerpc:tsec
powerpc:emac(ibm4xx)
sgimips:mec
sparc:be
sf
ne(ax88190, dl10019)
awge
ep
gem
hme
smsh
mtd
sm
age
alc
ale
bce
cas
et
jme
lii
nfe
pcn
ste
stge
tl
xi
aue
mue
smsc
udav
url

Not tested (PHY):
amhphy
bmtphy
dmphy
etphy
glxtphy
ikphy
iophy
lxtphy
nsphyter
pnaphy
rdcphy
sqphy
tlphy
tqphy
urlphy
 1.149 26-Jun-2018  msaitoh branches: 1.149.2;
Implement the BPF direction filter (BIOC[GS]DIRECTION). It provides backward
compatibility with BIOC[GS]SEESENT ioctl. The userland interface is the same
as FreeBSD.

This change also fixes a bug that the direction is misunderstand on some
environment by passing the direction to bpf_mtap*() instead of checking
m->m_pkthdr.rcvif.
 1.148 26-Sep-2017  knakahara branches: 1.148.2;
VLAN ID uses pkthdr instead of mtag now. Contributed by s-yamaguchi@IIJ.

I just commit by proxy. Reviewed by joerg@n.o and christos@n.o, thanks.
See http://mail-index.netbsd.org/tech-net/2017/09/26/msg006459.html

XXX need pullup to -8 branch
 1.147 20-Feb-2017  ozaki-r branches: 1.147.6;
Apply deferred if_start to more drivers
 1.146 15-Dec-2016  ozaki-r branches: 1.146.2;
Move bpf_mtap and if_ipackets++ on Rx of each driver to percpuq if_input

The benefits of the change are:
- We can reduce codes
- We can provide the same behavior between drivers
- Where/When if_ipackets is counted up
- Note that some drivers still update packet statistics in their own
way (periodical update)
- Moved bpf_mtap run in softint
- This makes it easy to MP-ify bpf

Proposed on tech-kern and tech-net
 1.145 10-Jun-2016  ozaki-r branches: 1.145.2;
Introduce m_set_rcvif and m_reset_rcvif

The API is used to set (or reset) a received interface of a mbuf.
They are counterpart of m_get_rcvif, which will come in another
commit, hide internal of rcvif operation, and reduce the diff of
the upcoming change.

No functional change.
 1.144 09-Feb-2016  ozaki-r Introduce softint-based if_input

This change intends to run the whole network stack in softint context
(or normal LWP), not hardware interrupt context. Note that the work is
still incomplete by this change; to that end, we also have to softint-ify
if_link_state_change (and bpf) which can still run in hardware interrupt.

This change softint-ifies at ifp->if_input that is called from
each device driver (and ieee80211_input) to ensure Layer 2 runs
in softint (e.g., ether_input and bridge_input). To this end,
we provide a framework (called percpuq) that utlizes softint(9)
and percpu ifqueues. With this patch, rxintr of most drivers just
queues received packets and schedules a softint, and the softint
dequeues packets and does rest packet processing.

To minimize changes to each driver, percpuq is allocated in struct
ifnet for now and that is initialized by default (in if_attach).
We probably have to move percpuq to softc of each driver, but it's
future work. At this point, only wm(4) has percpuq in its softc
as a reference implementation.

Additional information including performance numbers can be found
in the thread at tech-kern@ and tech-net@:
http://mail-index.netbsd.org/tech-kern/2016/01/14/msg019997.html

Acknowledgment: riastradh@ greatly helped this work.
Thank you very much!
 1.143 13-Apr-2015  riastradh Convert sys/dev to use <sys/rndsource.h>.
 1.142 10-Aug-2014  tls branches: 1.142.4;
Merge tls-earlyentropy branch into HEAD.
 1.141 12-Sep-2013  martin branches: 1.141.2;
Remove unused variable
 1.140 22-Jul-2012  matt branches: 1.140.2; 1.140.4;
Fix mii_statchg to take a 'struct ifnet *' instead of device_t. This fixes
problem with a common MDIO bus used for multiple interfaces.
Some drivers converted to CFATTACL_DECL_NEW.
 1.139 02-Feb-2012  tls Entropy-pool implementation move and cleanup.

1) Move core entropy-pool code and source/sink/sample management code
to sys/kern from sys/dev.

2) Remove use of NRND as test for presence of entropy-pool code throughout
source tree.

3) Remove use of RND_ENABLED in device drivers as microoptimization to
avoid expensive operations on disabled entropy sources; make the
rnd_add calls do this directly so all callers benefit.

4) Fix bug in recent rnd_add_data()/rnd_add_uint32() changes that might
have lead to slight entropy overestimation for some sources.

5) Add new source types for environmental sensors, power sensors, VM
system events, and skew between clocks, with a sample implementation
for each.

ok releng to go in before the branch due to the difficulty of later
pullup (widespread #ifdef removal and moved files). Tested with release
builds on amd64 and evbarm and live testing on amd64.
 1.138 02-Sep-2011  msaitoh branches: 1.138.2; 1.138.6;
Add support for some fxp devices from FreeBSD and OpenBSD.
{Free,Open}BSD say that we have to do some work to make fxp
stable.
 1.137 30-Mar-2011  jakllsch IFF_PROMISC implys IFF_ALLMULTI.
Should fix PR#43186.
 1.136 13-Nov-2010  uebayasi branches: 1.136.2;
Include sys/proc.h for tsleep, wakeup.
 1.135 05-Apr-2010  joerg Push the bpf_ops usage back into bpf.h. Push the common ifp->if_bpf
check into the inline functions as well the fourth argument for
bpf_attach.
 1.134 22-Mar-2010  dyoung Check whether the fxp(4) actually attached before calling fxp_stop().
 1.133 22-Mar-2010  dyoung In fxp_detach(), fxp_stop(), first. fxp_stop() stops the callout.
Destroy the callout in fxp_detach().
 1.132 25-Feb-2010  dyoung branches: 1.132.2;
Make fxp at cardbus detach during shutdown.

Stop calling (*cardbus_ctrl) to enable bus mastering, I/O and memory
spaces on the CardBus bridge. cbb(4) always enables that stuff,
anyway. In the process, avoid remembering what BAR we mapped by
writing CARDBUS_{IO,MEM}_ENABLE to sc_cben or sc_cbenable, and
record the BAR in use sc_bar, instead.

Replace more CARDBUS_ constants with PCI_ constants.

Compile-tested, only.
 1.131 19-Jan-2010  pooka branches: 1.131.2;
Redefine bpf linkage through an always present op vector, i.e.
#if NBPFILTER is no longer required in the client. This change
doesn't yet add support for loading bpf as a module, since drivers
can register before bpf is attached. However, callers of bpf can
now be modularized.

Dynamically loadable bpf could probably be done fairly easily with
coordination from the stub driver and the real driver by registering
attachments in the stub before the real driver is loaded and doing
a handoff. ... and I'm not going to ponder the depths of unload
here.

Tested with i386/MONOLITHIC, modified MONOLITHIC without bpf and rump.
 1.130 15-Sep-2009  dyoung Simplify activation routines: don't call mii_activate(), it's a
no-op. Don't block interrupts, if_deactivate() does it.
Compile-tested, only.
 1.129 16-Mar-2009  tsutsui Pull a fix from hme.c rev 1.73 (to #if 0'ed out part):
> Fix a bug in calculation of checksum deduction:
> - To get 16 bit one's complement value from uint32_t variable,
> higher 16 bits should be ignored.
> - RFC 1624 describes methods to recalculate checksum field in headers,
> i.e. one's complement of one's complement sum that could be 0x0000,
> but we don't have to use the strategy to deduct one's complement sum
> itself which won't be zero but should be 0xffff.
 1.128 15-Mar-2009  tsutsui Tweak comments and conditionals about EXT_RFA and IPCB.
 1.127 11-Mar-2009  tsutsui u_intNN_t -> uintNN_t
 1.126 09-Mar-2009  tsutsui Computed checksum value by the FXPF_82559_RXCSUM feature includes data
in IP headers, so we have to deduct not only IP option headers but all
IP headers. But in TCP/UDP layer we can assume the IP header is valid
and a sum of the IP header part should be 0xffff, so we don't have to
bother to deduct it from the computed checksum.
 1.125 07-Mar-2009  tsutsui Add TCPv4/UDPv4 RX hardware checksum support for i82559 and later chips
which don't have EXT_RFA and IPCB support. From hme(4) driver and
FreeBSD's fxp(4). Tested on i82559.

XXX: Probably we should have a common function to parse RX packet headers
XXX: to handle a raw checksum value and share it among hme(4) and gem(4) etc.
 1.124 04-Mar-2009  tsutsui Use FXPF_EXT_RFA flag instead of FXPF_EXT_TXCB to see IPCB capability
because EXT_RFA for RX cksum is always available with IPCB for TX cksum
but i82558 and i82559 have only EXT_TXCB without IPCB.

Tested on the following fxp cards:
fxp0 at pci0 dev 14 function 0: Intel i82557 Ethernet, rev 2
fxp0 at pci0 dev 14 function 0: i82559 Ethernet, rev 8
fxp0 at pci0 dev 14 function 0: i82550 Ethernet, rev 12
 1.123 20-Feb-2009  mrg - remove FXPF_IPCB flag. it should always/only be used with the code
conditional on FXPF_EXT_TXCB, so, replace all uses with that
- for the pci frontend, reestablish some flags lost the the prior
changes and simplify one of the cases

this fixes PR 40677 and may fix PR 40431.
 1.122 18-Jan-2009  mrg branches: 1.122.2;
The PCI revision numbers are unique to a PCI vendor/product
ID pair. Misuse of the revision numbers was causing some of the chip
features to be disabled on some integrated Intel chips. So, move the
determination of the features into the bus frontend, where the
vendor/product ID is known. (Note: sc_rev should be removed. The
microcode patch stuff is also busted and needs to be fixed.) Also,
poll the actual flow control status in inphy, rather than making
assumptions.

contributed anonymously.
 1.121 05-Dec-2008  tsutsui Wrap long lines.
 1.120 04-Dec-2008  tsutsui Don't pass uint8_t values to le16toh() in fxp_rx_hwcksum().
fxp(4)'s RX hwcksum results weren't used at all on big endian machines.

Checked by i82550 and vmstat -ev on macppc GENERIC kernel with
options INET_CSUM_COUNTERS,TCP_CSUM_COUNTERS,UDP_CSUM_COUNTERS.
 1.119 04-Dec-2008  tsutsui Add a missed htole32() on the previous ip4csum-tx bug workaround.
 1.118 04-Dec-2008  tsutsui Sort Tx/Rx macro in previous.
 1.117 03-Dec-2008  tsutsui Add a workaround for hardware ip4csum-tx bug and enable it.
Confirmed on i82550 rev 12 and UDP fragment packets by ttcp(1).
 1.116 03-Dec-2008  tsutsui Call BUS_DMASYNC_PREREAD more strictly on polling DMA descriptors.
 1.115 31-Jul-2008  ws branches: 1.115.2; 1.115.4;
Calling fxp_init within the interrupt handler results in
a hang (continuous assertion of FXP_SCB_STATACK_RNR).
Instead do it in the ioctl routine after receiving a
signal from the interrupt handler.
 1.114 09-Jul-2008  joerg - device/softc split for fxp(4)
 1.113 28-Apr-2008  martin branches: 1.113.2; 1.113.4; 1.113.6;
Remove clause 3 and 4 from TNF licenses
 1.112 08-Apr-2008  cegger branches: 1.112.2; 1.112.4;
use aprint_*_dev and device_xname
 1.111 07-Feb-2008  dyoung branches: 1.111.6;
Start patching up the kernel so that a network driver always has
the opportunity to handle an ioctl before generic ifioctl handling
occurs. This will ease extending the kernel and sharing of code
between drivers.

First steps: Make the signature of ifioctl_common() match struct
ifinet->if_ioctl. Convert SIOCSIFCAP and SIOCSIFMTU to the new
ifioctl() regime, throughout the kernel.
 1.110 19-Jan-2008  dyoung Make many ethernet drivers share the common code for MII media
handling, ether_mediastatus() and ether_mediachange(). Check for
a non-ENXIO error return from mii_mediachg(). (ENXIO indicates
that a PHY is suspended.)

This patch shrinks the source code size by 979 lines. There was
a 5100-byte savings on the NetBSD/i386 kernel configuration, ALL.

I have made a few miscellaneous changes, too:

gem(4): use LIST_EMPTY(), LIST_FOREACH().
mtd(4): handle media ioctls, for a change!
axe(4): do not track link status in sc->axe_link any longer
nfe(4), aue(4), axe(4), udav(4), url(4): do not reset all PHYs
on a change of media

Except for the change to mtd(4), no functional changes are intended.

XXX This patch affects more architectures than I can feasibly
XXX compile and run. I have compiled macppc, sparc64, i386. I
XXX have run the patches on i386 boxen with bnx(4) and sip(4).
XXX Compiling and running on evbmips (MERAKI, ADM5120) is in
XXX progress.
 1.109 29-Dec-2007  tsutsui Fix typo in comments.
 1.108 17-Dec-2007  tsutsui Fix from YAMAGUCHI Takahiro in PR kern/30023:
Pass correct EEPROM address in fxp_write_eeprom().
 1.107 13-Dec-2007  degroote Remove the shutdown hook (pmf takes care about it already), as suggested by joerg@
 1.106 10-Dec-2007  degroote branches: 1.106.2;
Register fxp @ pci to the pmf framework
Kill reference to old powerhook framework.
 1.105 08-Dec-2007  tsutsui branches: 1.105.2;
Pull several fixes from OpenBSD's fxp.c:

Rev 1.41:
> use a nop with I bit set at the end of the tx chain. This avoids a race
> between status update and clearing the suspend bit on machines which can't
> write data smaller than 32bits at a time.
This should fix PR port-alpha/30560.

Rev 1.50:
> Fix nasty bug where driver would not correctly catch and handle an rnr
> condition when it was due to the the recieve buffers being exhausted with
> no packet transmits during that time. Symptom was that the fxp would
> simply stop interrupting for the next 15 seconds until the watchdog kicked
> in and reset the chip due to 15 seconds of inactivity, making the fxp very
> poorly behaved when hammered on hard.

Rev 1.61:
> Defer reinitialisation of the RU until after the interrupt handler has had
> a chance to process all pending packets, otherwise the chip may overwrite
> their mbuf clusters after we have freed them.
>
> Eliminates a race that can cause random pool corruption when reconfiguring
> an interface under heavy network load.

And one more change for RX sanity:
- put RU into suspend when the last RFA is processed.

These RNR/RU changes may fix pool corruption problems on fxp.

Tested on AlphaPC164 and i386 with i82559 and i82550.
 1.104 19-Oct-2007  ad branches: 1.104.2; 1.104.4;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.103 26-Aug-2007  dyoung branches: 1.103.2; 1.103.6;
Constify: LLADDR -> CLLADDR. I'm aiming here to make it easier to
identify sockaddr_dl abuse that remains in the kernel, especially
the potential for overwriting memory past the end of a sockaddr_dl
with, e.g., memcpy(LLADDR(), ...).
 1.102 09-Jul-2007  ad branches: 1.102.2; 1.102.6;
Merge some of the less invasive changes from the vmlocking branch:

- kthread, callout, devsw API changes
- select()/poll() improvements
- miscellaneous MT safety improvements
 1.101 04-Mar-2007  christos branches: 1.101.2; 1.101.4; 1.101.6;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.100 16-Nov-2006  christos branches: 1.100.2; 1.100.4; 1.100.8; 1.100.12;
__unused removal on arguments; approved by core.
 1.99 12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.98 24-Sep-2006  jmcneill Add "name" parameter to powerhook_establish, to aid debugging. No objections
on tech-kern@
 1.97 20-Feb-2006  thorpej branches: 1.97.14; 1.97.16;
Use device_is_active() rather than testing dv_flags for DVF_ACTIVE
directly.
 1.96 24-Dec-2005  perry branches: 1.96.2; 1.96.4; 1.96.6;
Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.95 11-Dec-2005  christos merge ktrace-lwp.
 1.94 15-Oct-2005  jdolecek use VLAN_OUTPUT_TAG()
 1.93 12-Oct-2005  abs Make receiver lock-up workaround conditional on setting link1, as we have
too many false positives - should address PR/30505
 1.92 12-Aug-2005  junyoung Make microcode loading work on big endian machines.
Reported and patch supplied by yongari@freebsd a long time ago.
 1.91 29-May-2005  christos branches: 1.91.2;
- sprinkle const.
- avoid variable shadowing.
 1.90 02-May-2005  yamt split IFCAP_CSUM_xxx to IFCAP_CSUM_xxx_Rx and IFCAP_CSUM_xxx_Tx.
 1.89 23-Nov-2004  thorpej branches: 1.89.10;
Use log() instead of printf().
 1.88 30-Oct-2004  thorpej When adding/deleting multicast addresses, only whack the address
filter if the interface is marked RUNNING.

Fixes kern/27678.
 1.87 20-Sep-2004  simonb Fix a typo in a comment.
 1.86 16-May-2004  thorpej Patch from HITOSHI Osada:
* Add PAUSE-related event counters.
* Return flow control bits in fxp_mii_mediastatus().
 1.85 16-May-2004  thorpej Patch from HITOSHI Osada:
* Newer chips do not need the receiver lock-up workaround; detect when it
is required.
 1.84 28-Apr-2004  briggs When we are recovering from a resource exhaustion on receive, make sure
that the RU is stopped before issuing an RU_START.
Fix suggested by Takahiro Kambe in PR kern/10622.
 1.83 28-Apr-2004  briggs Back out revision 1.82. It seems to cause a number of device timeouts
on x86 boxes. There must be a better way to deal with this that works
well for everyone. In the meantime, back out to the version that works
for more people.
 1.82 31-Mar-2004  briggs Be more careful about issuing CU_RESUME in fxp_start()--only doing
it if we think it's probably necessary. Then do it again in the
tx interrupt handler, if we again think it's necessary. This
reduces the number of commands we issue the chip. Prior to this
change, the i82550 (running without extended feature set, so like
a '559) would sometimes fail in fxp_scb_wait() prior to issuing
another CU_RESUME, resulting in
fxp0: WARNING: SCB timed out!
messages on the console, often followed by device timeouts.
 1.81 19-Feb-2004  yamt branches: 1.81.2;
support h/w assisted vlan tag insertion.
 1.80 19-Feb-2004  yamt support h/w assisted vlan tag removal.
 1.79 09-Feb-2004  hpeyerl On some 'fast' i386 motherboards, the timing between consecutive reads
and writes of the EEPROM are too fast so invalid data is returned. So we
increase the DELAY()s. The right thing would be to check a ready bit
on the E^2 if such a thing exists. (checked by potr)
 1.78 06-Dec-2003  yamt - disable ipv4 checksum offloading as it seems to have a problem.
- add comments to describe it.
 1.77 02-Nov-2003  wiz Fix some typos. From Tom Cosgrove via jmc@openbsd.
 1.76 01-Aug-2003  scw In fxp_intr(), bail early without touching any registers if sc_enabled is
zero, otherwise we could cause PCI master aborts if the card is in D3 power
state and we happen to share a PCI interrupt line with some other device.
 1.75 26-May-2003  yamt branches: 1.75.2;
ip/tcp/udp checksum offloading support for i82550.
largely from FreeBSD.
 1.74 25-May-2003  yamt check and MCLAIM correct mbuf in fxp_copy_small path.
 1.73 26-Feb-2003  matt Add MBUFTRACE kernel option.
Do a little mbuf rework while here. Change all uses of MGET*(*, M_WAIT, *)
to m_get*(M_WAIT, *). These are not performance critical and making them
call m_get saves considerable space. Add m_clget analogue of MCLGET and
make corresponding change for M_WAIT uses.
Modify netinet, gem, fxp, tulip, nfs to support MBUFTRACE.
Begin to change netstat to use sysctl.
 1.72 04-Feb-2003  thorpej Use bus_dmamap_load_mbuf() in fxp_add_rfabuf().
 1.71 31-Jan-2003  thorpej Use aprint_*().
 1.70 06-Jan-2003  wiz synchronous, not syncronous.
 1.69 15-Nov-2002  enami Cosmetic changes.
 1.68 07-Nov-2002  thorpej Fix signed/unsigned comparison warnings.
 1.67 22-Oct-2002  fair Change the "dontcare bits" argument to ifmedia_init() to IFM_IMASK
so that it is possible select PHY instances other than the first
one (instance zero), if there is more than one PHY attached.
 1.66 06-Jun-2002  he Add newlines to the WARNING messages printed for the dynamic standby bug.
 1.65 20-May-2002  mycroft branches: 1.65.2;
The FIX_RESUME_BUG hack does not work, so remove it.
Also, attempt to clarify the message slightly when updating the EEPROM.
 1.64 05-Apr-2002  thorpej branches: 1.64.2;
Add support for the "CPUSaver" receive interrupt mitigating microcode
on the following PRO/100 chips:

* i82558 step A4
* i82558 step B0
* i82559 step A0
* i82559S step A
* i82550
* i82550 step C

The interrupt delay is configurable on all microcodable chips. The
maximum "bundle" size (packet count) is configurable on all but the
i82558.

The microcode is enabled by setting IFF_LINK0 on the interface.

Derived from code in FreeBSD.
 1.63 04-Apr-2002  thorpej Address Intel 82801BA/82801BAM Specification Update, Errata #30:

The ICH on-board Ethernet and some i82559 chips have a bug which
will cause a PCI protocol violation if the chip receives a CU_RESUME
command as it is entering the IDLE state by deasserting #CLKRUN.
(This is the so-called "resume bug" that we previously had an incomplete
work-around for on ICH chipsets.)

The work-around is to disable Dynamic Standby Mode, such that the
chip will never deasert #CLKRUN. Dynamic Standby Mode is disabled
by clearing a bit in the EEPROM and updating the EEPROM (and EEPROM
checksum).

Unfortunately, the chip will only consult the EEPROM setting after
a PCI bus reset, so a system reboot is required once the EEPROM
has been updated (the EEPROM update only needs to happen once,
and the driver usses a warning instructing the user to reboot the
system once the work-around has been applied).

Issue pointed out by David Brownlee, and code more-or-less lifted
from FreeBSD.
 1.62 04-Apr-2002  thorpej Move the code which shifts bits into the EEPROM into its own function.
 1.61 13-Nov-2001  lukem add/cleanup RCSID
 1.60 16-Sep-2001  wiz Spell 'occurred' with two 'r's.
 1.59 06-Aug-2001  enami branches: 1.59.2;
Advertize pause capability (802.3x flow control) to peer.
 1.58 19-Jul-2001  thorpej Use BUS_DMA_READ and BUS_DMA_WRITE in some obvious places.
 1.57 07-Jul-2001  thorpej branches: 1.57.2;
bzero -> memset
 1.56 07-Jul-2001  thorpej bcopy -> strcpy
 1.55 15-Jun-2001  thorpej Split the Tx and Rx interrupt routines into separate functions,
and add some (optional) event counters.
 1.54 12-Jun-2001  thorpej Don't need INET or NS includes here.
 1.53 02-Jun-2001  thorpej Define some extra configuration block bits used on the i82550 (a.k.a.
PRO 100/S), including the extended RFA format. Don't hard-code the
RFA size to allow us to use the extended format in the future.
 1.52 22-May-2001  thorpej Some changes from the new FreeBSD `fxp' driver:
- Add some additional config block bits for the i82558/i82559.
- Change the config block template to only fill in the must-be-one
reserved bits, leave fxp_init() to fill in all the important things.
- On the i82558/i82559, we can use "Receive Long Frames" rather than
"Save Bad Frames" to support the VLAN MTU.
- Use 802.3x flow control on the i82558/i82559. This is all handled
transparently by the hardware. When in promiscuous mode, allow
wire-watchers to see the flow control frames.
- Use the Extended TxCB format on the i82558/i82559. This places two
Transmit Buffer Descriptors directly in the TxCB, which should cover
the vast majority of packets transmitted. This saves PCI transactions
that would otherwise be required to fetch the TBD list.

With the tansmit queue length changes from yesterday, this gets us up to
11.5MB/s TCP transmit speed, out of an absolute maximum of 12MB/s possible
on a 100Mb/s link.
 1.51 22-May-2001  thorpej A little slight cleanup.
 1.50 21-May-2001  thorpej Re-arrange the transmit control data somewhat so that we can
use the extended TxCB format (that change will happen later).
 1.49 21-May-2001  thorpej Sigh, typo in last.
 1.48 21-May-2001  thorpej Fix non-fatal typo -- CB_NOP -> CU_NOP in the ICH work-around (they
have the same value).
 1.47 21-May-2001  thorpej The 82801BA built-in Ethernet has a bug which requires us to
issue a NOP before a CU_RESUME when in 10baseT mode. Handle
this.
 1.46 21-May-2001  thorpej ANSI'ify.
 1.45 16-May-2001  lukem delint: remove volatile from fxp_mdi_read() decl
 1.44 19-Dec-2000  thorpej branches: 1.44.2;
Fix a problem with the ALTQ changes that can cause bogus memory
refernces. Problem reported by Luke Mewburn.
 1.43 14-Dec-2000  thorpej ALTQ'ify.
 1.42 26-Nov-2000  takemura Add new powerhook argument values, PWR_SOFTSUSPEND, PWR_SOFTSTANDBY and
PWR_SOFTRESUME. Apm calls powerhook with the values in normal interrupt
priority level while others are protected with splhigh().
 1.41 15-Nov-2000  thorpej Move bpfattach()/bpfdetach() calls into ether_ifattach()/ether_ifdetach().
 1.40 11-Oct-2000  thorpej Use ether_ioctl().
 1.39 03-Oct-2000  thorpej Support ETHERCAP_VLAN_MTU by doing extra error checking upon packet
reception and saving other "bad frames" (i.e. ones that are larger
than the standard Ethernet frame length) if we have VLANs configured
on the interface.
 1.38 01-Oct-2000  thorpej Move the check for "promisc + unicast + not for us" into ether_input(),
and change Ethernet drivers to always pass all received frames to
ether_input() (with a few exceptions, which are documented in the
code).
 1.37 28-Sep-2000  tsutsui 6 -> ETHER_ADDR_LEN
 1.36 29-Jun-2000  thorpej Since the RFA is allocated in a normal mbuf, as opposed to DMA-safe
memory that is explicitly mapped in a DMA-coherent manner, we must
make sure to PREREAD sync the RFA after noticing a clear "complete"
bit. Without this, the clear bit will linger in the cache, and the
CPU will not notice when the chip updates the bit via DMA later.

From Izumi Tsutsui on port-arm32@netbsd.org.
 1.35 28-Jun-2000  mrg remove include of <vm/vm.h>. <vm/vm.h> -> <uvm/uvm_extern.h>
 1.34 29-May-2000  jhawk branches: 1.34.2;
For all network drivers that call ether_ifattach(), and also
have _detach() functions:
Ensure that softc keeps state about whether the attach succeeded,
and make the detach function return immediately if the attach did
not complete.
 1.33 27-May-2000  tsutsui branches: 1.33.2;
Increase delay on EEPROM access.
CATS sometimes cannot read MAC address correctly.
 1.32 26-May-2000  tsutsui Call bus_dmamap_sync() properly before/after reading fcd_stats
in fxp_control_data.
 1.31 24-May-2000  soren Make two previous changes more correct, as shown by Izumi Tsutsui.
 1.30 24-May-2000  soren The EEPROM is little-endian.
 1.29 24-May-2000  soren Fix DMA status reading on big-endian systems. From Sanjay Lal on port-macppc.
 1.28 24-May-2000  soren And a newline after error string.
 1.27 19-May-2000  jhawk Calibrate the timeouts from rev 1.26 by using DELAY(1) so their
values are less machine-dependant. Fixes port-i386/10141, where
spurrious timeouts were being seen.
Also note the line numbers of the timeouts so it can be determined
which is being seen (via __LINE__).
 1.26 12-May-2000  jhawk Catch some potentially infinite loops in while() loops if the chip happens
to "go insane" and never complete some operations (dmasync, etc.).
 1.25 30-Mar-2000  simonb Delete redundant decls of fxp_enable(), fxp_disable() - they're in
i82557var.h.
 1.24 23-Mar-2000  thorpej New callout mechanism with two major improvements over the old
timeout()/untimeout() API:
- Clients supply callout handle storage, thus eliminating problems of
resource allocation.
- Insertion and removal of callouts is constant time, important as
this facility is used quite a lot in the kernel.

The old timeout()/untimeout() API has been removed from the kernel.
 1.23 20-Mar-2000  thorpej Get rid of the powerhook when we detach.
 1.22 06-Mar-2000  thorpej No longer necessary to futz with ifp->if_baudrate here.
 1.21 28-Feb-2000  joda (fxp_init): don't clear the FXPF_MII flag as this results in a panic
when detaching
 1.20 12-Feb-2000  enami Add activate routine and check device active flag also in one second
tick handler.
 1.19 12-Feb-2000  enami Cosmetic changes.
 1.18 09-Feb-2000  joda add detach code
 1.17 02-Feb-2000  thorpej Don't dry to diving MIIF_NOISOLATE in the PHY drivers. Instead, pass
flags down from the parent to child vi mii_attach().
 1.16 02-Feb-2000  thorpej Bring some order to the chaos which was the MII code function naming
"conventions".
 1.15 12-Dec-1999  thorpej Take a stab at making this work on big-endian systems.
 1.14 04-Dec-1999  sommerfeld change comment to mention that this driver also handles the '558 and '559
 1.13 19-Nov-1999  joda try to do a better job of figuring out the EEPROM size; the old code
didn't work on (some?) 557-based cards
 1.12 12-Nov-1999  thorpej Call mii_down() as appropriate.
 1.11 04-Nov-1999  thorpej Adapt to mii_phy_probe() change.
 1.10 30-Oct-1999  sommerfeld Add enable/disable support and EEPROM size selection, prerequisites
for getting the cardbus fxp attachment to work.

Tested on the built-in 82559 in a VAIO Z505S.

From Johan Danielsson / PR8631; changed slightly to KNF.
 1.9 28-Oct-1999  sommerfeld Fix suspend/resume-related problems observed on fxp0 on Sony Z505S:

Symptoms: system would crash with "data modified on free list" pool
panic from the mbuf cluster pool shortly after a resume. The cluster
in question contained a valid 82557 receive descriptor and an IP
packet. Happened sporadically in normal use. Easiest way for me to
reproduce it was to run tcpdump and a flood ping and do a
suspend/resume cycle or two.

Changes:
- in interrupt handler, if the interface isn't in IFF_RUNNING state,
just ack interrupts and return; don't try to receive packets, queue
new descriptors, etc., etc.,
- add power control hook to take interface down on suspend,
and restart it (if it was up) on resume.
- tweaks to fxp_stop and fxp_shutdown to avoid recursive panics due
to the (now fixed) bug.
 1.8 05-Aug-1999  thorpej branches: 1.8.2; 1.8.4; 1.8.6;
Since we have to go through fxp_init() to properly handle IFF_ALLMULTI
anyway, take advantage of this and greatly simplify the programming
of the multicast filter. This solves the last reported "device timeout"
problem with this driver.
 1.7 04-Aug-1999  thorpej Almost completely rewrite the receive logic, making it as close as possible
to the EPIC/100 driver's (adjusting for the fact that Intel Ethernet chips
are from Pluto):
* Don't allocate receive buffers until the interface is actually brought
up, and release all of them if the interface is taken down.
* Add a knob (defaults to off) which will copy an incoming packet to
a single header mbuf if it is small enough to fit in one, rather than
burning an entire cluster on it. Note that this change will be mostly
moot if/when sbcompress() is changed to handle compressing clusters.

Simplify some of the receive list logic:
* Rather than using a homegrown queue and additional software RX descriptors,
use an ifqueue to queue receive buffers, and M_{GET,SET}CTX() to hook DMA
maps and receive buffers together.

Clean up a bit:
* Macroize a bunch of things to make the code a bit easier to follow.
 1.6 04-Aug-1999  thorpej Only tick the MII if we are using it.
 1.5 04-Aug-1999  thorpej Be a little less selective in the transmit interrupt path.
 1.4 03-Aug-1999  thorpej Use the Interrupt bit in the command block to generate interrupts, rather
than interrupting after every Command Unit Not Active event.
 1.3 03-Aug-1999  thorpej Don't bother with interrupt-driven multicast setup.
 1.2 03-Aug-1999  thorpej Completely rewrite the transmit logic, making it look more like the
EPIC/100 driver's. Also, fix the "all multicast" logic. Also do some
general cleanup.
 1.1 20-Jun-1999  thorpej branches: 1.1.2;
Bus-independent back-end driver for Intel i82557 fast Ethernet chips.
 1.1.2.2 01-Jul-1999  thorpej Sync w/ -current.
 1.1.2.1 20-Jun-1999  thorpej file i82557.c was added on branch chs-ubc2 on 1999-07-01 23:32:28 +0000
 1.8.6.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.8.4.1 15-Nov-1999  fvdl Sync with -current
 1.8.2.4 05-Jan-2001  bouyer Sync with HEAD
 1.8.2.3 08-Dec-2000  bouyer Sync with HEAD.
 1.8.2.2 22-Nov-2000  bouyer Sync with HEAD.
 1.8.2.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.33.2.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.34.2.4 06-Jun-2002  he Pull up revisions 1.45-1.53,1.55-1.57,1.60,1.62-1.63,1.65-1.66 (via patch,
requested by mycroft):
Work around a bug which can cause some machines to randomly hang.
Drag along performance improvements and improved hardware support.
 1.34.2.3 06-May-2001  he Pull up revision 1.42 (via patch, requested by he):
Add new powerhook argument values, PWR_SOFTSUSPEND, PWR_SOFTSTANDBY and
PWR_SOFTRESUME. Apm calls powerhook with the values in normal interrupt
priority level while others are protected with splhigh().
 1.34.2.2 31-Dec-2000  jhawk Pull up revision 1.39 (requested by bouyer):
Add support for 802.1Q virtual LANs.
 1.34.2.1 29-Jun-2000  thorpej Pull up rev. 1.36:
Since the RFA is allocated in a normal mbuf, as opposed to DMA-safe
memory that is explicitly mapped in a DMA-coherent manner, we must
make sure to PREREAD sync the RFA after noticing a clear "complete"
bit. Without this, the clear bit will linger in the cache, and the
CPU will not notice when the chip updates the bit via DMA later.

>From Izumi Tsutsui on port-arm32@netbsd.org.
 1.44.2.9 07-Jan-2003  thorpej Sync with HEAD.
 1.44.2.8 11-Dec-2002  thorpej Sync with HEAD.
 1.44.2.7 11-Nov-2002  nathanw Catch up to -current
 1.44.2.6 20-Jun-2002  nathanw Catch up to -current.
 1.44.2.5 17-Apr-2002  nathanw Catch up to -current.
 1.44.2.4 14-Nov-2001  nathanw Catch up to -current.
 1.44.2.3 21-Sep-2001  nathanw Catch up to -current.
 1.44.2.2 24-Aug-2001  nathanw Catch up with -current.
 1.44.2.1 21-Jun-2001  nathanw Catch up to -current.
 1.57.2.4 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.57.2.3 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.57.2.2 25-Aug-2001  thorpej Merge Aug 24 -current into the kqueue branch.
 1.57.2.1 03-Aug-2001  lukem update to -current
 1.59.2.1 01-Oct-2001  fvdl Catch up with -current.
 1.64.2.2 20-Jun-2002  gehenna catch up with -current.
 1.64.2.1 30-May-2002  gehenna Catch up with -current.
 1.65.2.2 17-Jun-2003  msaitoh Pullup rev. 1.74 via patch (requested by yamt in ticket #1296):
Fix of possible null pointer dereferences.
 1.65.2.1 10-Jun-2002  tv Pull up revision 1.66 (requested by 197 in ticket #0):
Add newlines to the WARNING messages printed for the dynamic standby bug.
 1.75.2.7 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.75.2.6 29-Nov-2004  skrll Sync with HEAD.
 1.75.2.5 02-Nov-2004  skrll Sync with HEAD.
 1.75.2.4 24-Sep-2004  skrll Sync with HEAD.
 1.75.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.75.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.75.2.1 03-Aug-2004  skrll Sync with HEAD
 1.81.2.2 28-Apr-2004  tron branches: 1.81.2.2.2;
Pull up revision 1.83 (requested by briggs in ticket #218):
Back out revision 1.82. It seems to cause a number of device timeouts
on x86 boxes. There must be a better way to deal with this that works
well for everyone. In the meantime, back out to the version that works
for more people.
 1.81.2.1 01-Apr-2004  jmc Pullup rev 1.82 (requested by briggs in ticket #45)

Be more careful about issuing CU_RESUME in fxp_start()--only doing
it if we think it's probably necessary. Then do it again in the
tx interrupt handler, if we again think it's necessary. This
reduces the number of commands we issue the chip. Prior to this
change, the i82550 (running without extended feature set, so like
a '559) would sometimes fail in fxp_scb_wait() prior to issuing
another CU_RESUME, resulting in
fxp0: WARNING: SCB timed out!
messages on the console, often followed by device timeouts.
 1.81.2.2.2.2 24-Aug-2005  riz Pull up following revision(s) (requested by junyoung in ticket #5608):
sys/dev/ic/i82557.c: revision 1.92 via patch
Make microcode loading work on big endian machines.
Reported and patch supplied by yongari@freebsd a long time ago.
 1.81.2.2.2.1 24-Jan-2005  he Pull up revision 1.88 (requested by thorpej in ticket #939):
When adding or deleting multicast addresses, only change
the address filter if the interface is marked RUNNING.
Fixes PR#27678.
 1.89.10.2 15-Oct-2005  riz Pull up following revision(s) (requested by abs in ticket #886):
sys/dev/ic/i82557.c: revision 1.93
Make receiver lock-up workaround conditional on setting link1, as we have
too many false positives - should address PR/30505
 1.89.10.1 16-Aug-2005  tron Pull up revision 1.92 via patch (requested by junyoung in ticket #666):
Make microcode loading work on big endian machines.
Reported and patch supplied by yongari@freebsd a long time ago.
 1.91.2.6 11-Feb-2008  yamt sync with head.
 1.91.2.5 21-Jan-2008  yamt sync with head
 1.91.2.4 27-Oct-2007  yamt sync with head.
 1.91.2.3 03-Sep-2007  yamt sync with head.
 1.91.2.2 30-Dec-2006  yamt sync with head.
 1.91.2.1 21-Jun-2006  yamt sync with head.
 1.96.6.1 22-Apr-2006  simonb Sync with head.
 1.96.4.1 09-Sep-2006  rpaulo sync with head
 1.96.2.1 01-Mar-2006  yamt sync with head.
 1.97.16.2 10-Dec-2006  yamt sync with head.
 1.97.16.1 22-Oct-2006  yamt sync with head
 1.97.14.1 18-Nov-2006  ad Sync with head.
 1.100.12.1 02-Feb-2008  riz Pull up following revision(s) (requested by tsutsui in ticket #1028):
sys/dev/ic/i82557reg.h: revision 1.19
sys/dev/ic/i82557var.h: revision 1.36
sys/dev/ic/i82557.c: revision 1.105
Pull several fixes from OpenBSD's fxp.c:
Rev 1.41:
use a nop with I bit set at the end of the tx chain. This avoids a race
between status update and clearing the suspend bit on machines which can't
write data smaller than 32bits at a time.
This should fix PR port-alpha/30560.
Rev 1.50:
Fix nasty bug where driver would not correctly catch and handle an rnr
condition when it was due to the the recieve buffers being exhausted with
no packet transmits during that time. Symptom was that the fxp would
simply stop interrupting for the next 15 seconds until the watchdog kicked
in and reset the chip due to 15 seconds of inactivity, making the fxp very
poorly behaved when hammered on hard.
Rev 1.61:
Defer reinitialisation of the RU until after the interrupt handler has had
a chance to process all pending packets, otherwise the chip may overwrite
their mbuf clusters after we have freed them.
Eliminates a race that can cause random pool corruption when reconfiguring
an interface under heavy network load.
And one more change for RX sanity:
- put RU into suspend when the last RFA is processed.
These RNR/RU changes may fix pool corruption problems on fxp.
Tested on AlphaPC164 and i386 with i82559 and i82550.
 1.100.8.1 03-Jun-2008  skrll Sync with netbsd-4.
 1.100.4.1 12-Mar-2007  rmind Sync with HEAD.
 1.100.2.1 02-Feb-2008  riz Pull up following revision(s) (requested by tsutsui in ticket #1028):
sys/dev/ic/i82557reg.h: revision 1.19
sys/dev/ic/i82557var.h: revision 1.36
sys/dev/ic/i82557.c: revision 1.105
Pull several fixes from OpenBSD's fxp.c:
Rev 1.41:
use a nop with I bit set at the end of the tx chain. This avoids a race
between status update and clearing the suspend bit on machines which can't
write data smaller than 32bits at a time.
This should fix PR port-alpha/30560.
Rev 1.50:
Fix nasty bug where driver would not correctly catch and handle an rnr
condition when it was due to the the recieve buffers being exhausted with
no packet transmits during that time. Symptom was that the fxp would
simply stop interrupting for the next 15 seconds until the watchdog kicked
in and reset the chip due to 15 seconds of inactivity, making the fxp very
poorly behaved when hammered on hard.
Rev 1.61:
Defer reinitialisation of the RU until after the interrupt handler has had
a chance to process all pending packets, otherwise the chip may overwrite
their mbuf clusters after we have freed them.
Eliminates a race that can cause random pool corruption when reconfiguring
an interface under heavy network load.
And one more change for RX sanity:
- put RU into suspend when the last RFA is processed.
These RNR/RU changes may fix pool corruption problems on fxp.
Tested on AlphaPC164 and i386 with i82559 and i82550.
 1.101.6.1 09-Dec-2007  reinoud Pullup to HEAD
 1.101.4.1 11-Jul-2007  mjf Sync with head.
 1.101.2.3 23-Oct-2007  ad Sync with head.
 1.101.2.2 09-Oct-2007  ad Sync with head.
 1.101.2.1 01-Jul-2007  ad Adapt to callout API change.
 1.102.6.3 09-Dec-2007  jmcneill Sync with HEAD.
 1.102.6.2 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.102.6.1 03-Sep-2007  jmcneill Sync with HEAD.
 1.102.2.1 03-Sep-2007  skrll Sync with HEAD.
 1.103.6.1 25-Oct-2007  bouyer Sync with HEAD.
 1.103.2.3 23-Mar-2008  matt sync with HEAD
 1.103.2.2 09-Jan-2008  matt sync with HEAD
 1.103.2.1 06-Nov-2007  matt sync with HEAD
 1.104.4.2 26-Dec-2007  ad Sync with head.
 1.104.4.1 08-Dec-2007  ad Sync with head.
 1.104.2.1 18-Feb-2008  mjf Sync with HEAD.
 1.105.2.1 11-Dec-2007  yamt sync with head.
 1.106.2.3 20-Jan-2008  bouyer Sync with HEAD
 1.106.2.2 02-Jan-2008  bouyer Sync with HEAD
 1.106.2.1 13-Dec-2007  bouyer Sync with HEAD
 1.111.6.3 17-Jan-2009  mjf Sync with HEAD.
 1.111.6.2 28-Sep-2008  mjf Sync with HEAD.
 1.111.6.1 02-Jun-2008  mjf Sync with HEAD.
 1.112.4.5 11-Aug-2010  yamt sync with head.
 1.112.4.4 11-Mar-2010  yamt sync with head
 1.112.4.3 16-Sep-2009  yamt sync with head
 1.112.4.2 04-May-2009  yamt sync with head.
 1.112.4.1 16-May-2008  yamt sync with head.
 1.112.2.1 18-May-2008  yamt sync with head.
 1.113.6.2 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.113.6.1 19-Oct-2008  haad Sync with HEAD.
 1.113.4.1 18-Jul-2008  simonb Sync with head.
 1.113.2.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.115.4.1 14-Dec-2008  bouyer Pull up following revision(s) (requested by tsutsui in ticket #181):
sys/dev/ic/i82557.c: revision 1.116-1.120
sys/dev/ic/i82557reg.h: revision 1.21
sys/dev/ic/i82557var.h: revision 1.41
doc/CHANGES: patch
Call BUS_DMASYNC_PREREAD more strictly on polling DMA descriptors.
Add a workaround for hardware ip4csum-tx bug and enable it.
Confirmed on i82550 rev 12 and UDP fragment packets by ttcp(1).
Sort Tx/Rx macro in previous.
Add a missed htole32() on the previous ip4csum-tx bug workaround.
Don't pass uint8_t values to le16toh() in fxp_rx_hwcksum().
fxp(4)'s RX hwcksum results weren't used at all on big endian machines.
Checked by i82550 and vmstat -ev on macppc GENERIC kernel with
options INET_CSUM_COUNTERS,TCP_CSUM_COUNTERS,UDP_CSUM_COUNTERS.
 1.115.2.3 28-Apr-2009  skrll Sync with HEAD.
 1.115.2.2 03-Mar-2009  skrll Sync with HEAD.
 1.115.2.1 19-Jan-2009  skrll Sync with HEAD.
 1.122.2.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.131.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.132.2.3 21-Apr-2011  rmind sync with head
 1.132.2.2 05-Mar-2011  rmind sync with head
 1.132.2.1 30-May-2010  rmind sync with head
 1.136.2.1 06-Jun-2011  jruoho Sync with HEAD.
 1.138.6.1 18-Feb-2012  mrg merge to -current.
 1.138.2.3 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.138.2.2 30-Oct-2012  yamt sync with head
 1.138.2.1 17-Apr-2012  yamt sync with head
 1.140.4.1 18-May-2014  rmind sync with head
 1.140.2.2 03-Dec-2017  jdolecek update from HEAD
 1.140.2.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.141.2.1 07-Apr-2014  tls Be a little more clear and consistent about harvesting entropy from devices:

1) deprecate RND_FLAG_NO_ESTIMATE

2) define RND_FLAG_COLLECT_TIME, RND_FLAG_COLLECT_VALUE

3) define RND_FLAG_ESTIMATE_TIME, RND_FLAG_ESTIMATE_VALUE

4) define RND_FLAG_DEFAULT: RND_FLAG_COLLECT_TIME|
RND_FLAG_COLLECT_VALUE|RND_FLAG_ESTIMATE_TIME

5) Make entropy harvesting from environmental sensors a little more generic
and remove it from individual sensor drivers.

6) Remove individual open-coded delta-estimators for values from a few
places in the tree (uvm, environmental drivers).

7) 0 -> RND_FLAG_DEFAULT, actually gather entropy from various drivers
that had stubbed out code, other minor cleanups.
 1.142.4.5 28-Aug-2017  skrll Sync with HEAD
 1.142.4.4 05-Feb-2017  skrll Sync with HEAD
 1.142.4.3 09-Jul-2016  skrll Sync with HEAD
 1.142.4.2 19-Mar-2016  skrll Sync with HEAD
 1.142.4.1 06-Jun-2015  skrll Sync with HEAD
 1.145.2.2 20-Mar-2017  pgoyette Sync with HEAD
 1.145.2.1 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.146.2.1 21-Apr-2017  bouyer Sync with HEAD
 1.147.6.2 06-Nov-2019  martin Pull up following revision(s) (requested by msaitoh in ticket #1427):

sys/arch/arm/broadcom/bcm53xx_eth.c: revision 1.39
sys/dev/pcmcia/if_xi.c: revision 1.91
sys/dev/ic/aic6915.c: revision 1.40
sys/dev/pci/if_tl.c: revision 1.117
sys/arch/arm/gemini/gemini_gmac.c: revision 1.18
sys/dev/ic/elinkxl.c: revision 1.133
sys/dev/pci/if_ste.c: revision 1.57
sys/dev/pci/if_alc.c: revision 1.43
sys/dev/pci/if_stge.c: revision 1.72
sys/dev/pci/if_ale.c: revision 1.34
sys/dev/pci/if_age.c: revision 1.62
sys/dev/pci/if_txp.c: revision 1.60
sys/dev/ic/i82557.c: revision 1.156
sys/dev/pci/if_vte.c: revision 1.27
sys/arch/powerpc/booke/dev/pq3etsec.c: revision 1.47
sys/arch/arm/gemini/if_gpn.c: revision 1.13

if_percpuq(9) and ether_input() automatically increment if_ipackets, so don't add number of
RX frames from device's statistics counter to if_ipackets to avoid double
count.
 1.147.6.1 24-Oct-2017  snj Pull up following revision(s) (requested by knakahara in ticket #302):
sys/arch/powerpc/booke/dev/pq3etsec.c: 1.30-1.31
sys/arch/x86/pci/if_vmx.c: 1.20
sys/dev/ic/i82557.c: 1.148
sys/dev/ic/rtl8169.c: 1.152
sys/dev/pci/cxgb/cxgb_sge.c: 1.5
sys/dev/pci/if_age.c: 1.51
sys/dev/pci/if_alc.c: 1.25
sys/dev/pci/if_ale.c: 1.23
sys/dev/pci/if_bge.c: 1.311
sys/dev/pci/if_bge.c: 1.312
sys/dev/pci/if_bnx.c: 1.62
sys/dev/pci/if_jme.c: 1.32
sys/dev/pci/if_nfe.c: 1.64
sys/dev/pci/if_sip.c: 1.167
sys/dev/pci/if_stge.c: 1.63-1.64
sys/dev/pci/if_ti.c: 1.102
sys/dev/pci/if_txp.c: 1.48
sys/dev/pci/if_vge.c: 1.61
sys/dev/pci/if_wm.c: 1.538
sys/dev/pci/ixgbe/ix_txrx.c: 1.29 via patch
sys/net/agr/if_agrether_hash.c: 1.4
sys/net/if_ether.h: 1.67-1.68
sys/net/if_ethersubr.c: 1.244
sys/net/if_vlan.c: 1.100
sys/net80211/ieee80211_input.c: 1.89
sys/net80211/ieee80211_output.c: 1.59
sys/sys/mbuf.h: 1.171
VLAN ID uses pkthdr instead of mtag now. Contributed by s-yamaguchi@IIJ.
I just commit by proxy. Reviewed by joerg@n.o and christos@n.o, thanks.
See http://mail-index.netbsd.org/tech-net/2017/09/26/msg006459.html
--
only get vtag when we have vtag like the other drivers.
--
- only get the vtag if we have it like the other drivers
- mask the hardware vlan tag
--
- add a constant for the vlan mask.
- enforce that we have a tag before we get it.
only get vtag when we have vtag like the other drivers.
like if_bge.c:1.312 and if_stge.c:1.64.
fixed by s-yamaguchi@IIJ, thanks.
 1.148.2.2 26-Jan-2019  pgoyette Sync with HEAD
 1.148.2.1 28-Jul-2018  pgoyette Sync with HEAD
 1.149.2.3 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.149.2.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.149.2.1 10-Jun-2019  christos Sync with HEAD
 1.154.2.2 06-Nov-2019  martin Pull up following revision(s) (requested by msaitoh in ticket #403):

sys/arch/arm/broadcom/bcm53xx_eth.c: revision 1.39
sys/dev/pcmcia/if_xi.c: revision 1.91
sys/dev/ic/aic6915.c: revision 1.40
sys/dev/pci/if_tl.c: revision 1.117
sys/arch/arm/gemini/gemini_gmac.c: revision 1.18
sys/dev/ic/elinkxl.c: revision 1.133
sys/dev/pci/if_ste.c: revision 1.57
sys/dev/pci/if_alc.c: revision 1.43
sys/dev/pci/if_stge.c: revision 1.72
sys/dev/pci/if_ale.c: revision 1.34
sys/dev/pci/if_age.c: revision 1.62
sys/dev/pci/if_txp.c: revision 1.60
sys/dev/ic/i82557.c: revision 1.156
sys/dev/pci/if_vte.c: revision 1.27
sys/arch/powerpc/booke/dev/pq3etsec.c: revision 1.47
sys/arch/arm/gemini/if_gpn.c: revision 1.13

if_percpuq(9) and ether_input() automatically increment if_ipackets, so don't add number of
RX frames from device's statistics counter to if_ipackets to avoid double
count.
 1.154.2.1 22-Sep-2019  martin Pull up following revision(s) (requested by maxv in ticket #217):

sys/dev/ic/i82557.c: revision 1.155

Fix direction of the loop.
 1.156.2.1 29-Feb-2020  ad Sync with head.
 1.25 02-Sep-2011  msaitoh Add support for some fxp devices from FreeBSD and OpenBSD.
{Free,Open}BSD say that we have to do some work to make fxp
stable.
 1.24 17-Apr-2009  tsutsui Check revisions and print names of i82551/i82551ER, per Intel manual.
 1.23 11-Mar-2009  tsutsui u_intNN_t -> uintNN_t
 1.22 20-Feb-2009  mrg - remove FXPF_IPCB flag. it should always/only be used with the code
conditional on FXPF_EXT_TXCB, so, replace all uses with that
- for the pci frontend, reestablish some flags lost the the prior
changes and simplify one of the cases

this fixes PR 40677 and may fix PR 40431.
 1.21 03-Dec-2008  tsutsui branches: 1.21.4;
Add a workaround for hardware ip4csum-tx bug and enable it.
Confirmed on i82550 rev 12 and UDP fragment packets by ttcp(1).
 1.20 28-Apr-2008  martin branches: 1.20.6; 1.20.8; 1.20.10;
Remove clause 3 and 4 from TNF licenses
 1.19 08-Dec-2007  tsutsui branches: 1.19.12; 1.19.14; 1.19.16;
Pull several fixes from OpenBSD's fxp.c:

Rev 1.41:
> use a nop with I bit set at the end of the tx chain. This avoids a race
> between status update and clearing the suspend bit on machines which can't
> write data smaller than 32bits at a time.
This should fix PR port-alpha/30560.

Rev 1.50:
> Fix nasty bug where driver would not correctly catch and handle an rnr
> condition when it was due to the the recieve buffers being exhausted with
> no packet transmits during that time. Symptom was that the fxp would
> simply stop interrupting for the next 15 seconds until the watchdog kicked
> in and reset the chip due to 15 seconds of inactivity, making the fxp very
> poorly behaved when hammered on hard.

Rev 1.61:
> Defer reinitialisation of the RU until after the interrupt handler has had
> a chance to process all pending packets, otherwise the chip may overwrite
> their mbuf clusters after we have freed them.
>
> Eliminates a race that can cause random pool corruption when reconfiguring
> an interface under heavy network load.

And one more change for RX sanity:
- put RU into suspend when the last RFA is processed.

These RNR/RU changes may fix pool corruption problems on fxp.

Tested on AlphaPC164 and i386 with i82559 and i82550.
 1.18 11-Dec-2005  christos branches: 1.18.24; 1.18.34; 1.18.38; 1.18.44; 1.18.46; 1.18.56; 1.18.58;
merge ktrace-lwp.
 1.17 29-May-2005  christos branches: 1.17.2;
- sprinkle const.
- avoid variable shadowing.
 1.16 27-Feb-2005  perry nuke trailing whitespace
 1.15 16-May-2004  thorpej branches: 1.15.4; 1.15.6;
Patch from HITOSHI Osada:
* Add PAUSE-related event counters.
* Return flow control bits in fxp_mii_mediastatus().
 1.14 19-Feb-2004  yamt support h/w assisted vlan tag removal.
 1.13 02-Nov-2003  wiz deferred, not deffered. Inspired by Tom Cosgrove.
 1.12 26-May-2003  yamt branches: 1.12.2;
ip/tcp/udp checksum offloading support for i82550.
largely from FreeBSD.
 1.11 05-Apr-2002  thorpej Define the command block used for loading microcode into the chip.
 1.10 02-Jun-2001  thorpej branches: 1.10.2;
Define some extra configuration block bits used on the i82550 (a.k.a.
PRO 100/S), including the extended RFA format. Don't hard-code the
RFA size to allow us to use the extended format in the future.
 1.9 25-May-2001  hannken Fix two typos in the BYTE_ORDER != LITTLE_ENDIAN case.
 1.8 22-May-2001  thorpej Some changes from the new FreeBSD `fxp' driver:
- Add some additional config block bits for the i82558/i82559.
- Change the config block template to only fill in the must-be-one
reserved bits, leave fxp_init() to fill in all the important things.
- On the i82558/i82559, we can use "Receive Long Frames" rather than
"Save Bad Frames" to support the VLAN MTU.
- Use 802.3x flow control on the i82558/i82559. This is all handled
transparently by the hardware. When in promiscuous mode, allow
wire-watchers to see the flow control frames.
- Use the Extended TxCB format on the i82558/i82559. This places two
Transmit Buffer Descriptors directly in the TxCB, which should cover
the vast majority of packets transmitted. This saves PCI transactions
that would otherwise be required to fetch the TBD list.

With the tansmit queue length changes from yesterday, this gets us up to
11.5MB/s TCP transmit speed, out of an absolute maximum of 12MB/s possible
on a 100Mb/s link.
 1.7 22-May-2001  thorpej Report 82558, 82559, etc. based on chip revision. Also, remember which
revsion we have for feature enables later.
 1.6 22-May-2001  thorpej A little slight cleanup.
 1.5 22-May-2001  thorpej Add some additional register definitions, from FreeBSD.
 1.4 21-May-2001  thorpej Re-arrange the transmit control data somewhat so that we can
use the extended TxCB format (that change will happen later).
 1.3 12-Dec-1999  thorpej branches: 1.3.4; 1.3.6;
Take a stab at making this work on big-endian systems.
 1.2 03-Aug-1999  thorpej branches: 1.2.2; 1.2.8;
Completely rewrite the transmit logic, making it look more like the
EPIC/100 driver's. Also, fix the "all multicast" logic. Also do some
general cleanup.
 1.1 20-Jun-1999  thorpej branches: 1.1.2;
Bus-independent back-end driver for Intel i82557 fast Ethernet chips.
 1.1.2.2 01-Jul-1999  thorpej Sync w/ -current.
 1.1.2.1 20-Jun-1999  thorpej file i82557reg.h was added on branch chs-ubc2 on 1999-07-01 23:32:28 +0000
 1.2.8.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.2.2.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.3.6.2 17-Apr-2002  nathanw Catch up to -current.
 1.3.6.1 21-Jun-2001  nathanw Catch up to -current.
 1.3.4.1 06-Jun-2002  he Pull up revisions 1.4-1.10 (requested by mycroft):
Work around a bug which can cause some machines to randomly hang.
Drag along performance improvements and improved hardware support.
 1.10.2.1 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.12.2.5 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.12.2.4 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.12.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.12.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.12.2.1 03-Aug-2004  skrll Sync with HEAD
 1.15.6.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.15.4.1 29-Apr-2005  kent sync with -current
 1.17.2.1 21-Jan-2008  yamt sync with head
 1.18.58.1 02-Feb-2008  riz Pull up following revision(s) (requested by tsutsui in ticket #1028):
sys/dev/ic/i82557reg.h: revision 1.19
sys/dev/ic/i82557var.h: revision 1.36
sys/dev/ic/i82557.c: revision 1.105
Pull several fixes from OpenBSD's fxp.c:
Rev 1.41:
use a nop with I bit set at the end of the tx chain. This avoids a race
between status update and clearing the suspend bit on machines which can't
write data smaller than 32bits at a time.
This should fix PR port-alpha/30560.
Rev 1.50:
Fix nasty bug where driver would not correctly catch and handle an rnr
condition when it was due to the the recieve buffers being exhausted with
no packet transmits during that time. Symptom was that the fxp would
simply stop interrupting for the next 15 seconds until the watchdog kicked
in and reset the chip due to 15 seconds of inactivity, making the fxp very
poorly behaved when hammered on hard.
Rev 1.61:
Defer reinitialisation of the RU until after the interrupt handler has had
a chance to process all pending packets, otherwise the chip may overwrite
their mbuf clusters after we have freed them.
Eliminates a race that can cause random pool corruption when reconfiguring
an interface under heavy network load.
And one more change for RX sanity:
- put RU into suspend when the last RFA is processed.
These RNR/RU changes may fix pool corruption problems on fxp.
Tested on AlphaPC164 and i386 with i82559 and i82550.
 1.18.56.1 08-Dec-2007  ad Sync with head.
 1.18.46.1 09-Jan-2008  matt sync with HEAD
 1.18.44.1 09-Dec-2007  jmcneill Sync with HEAD.
 1.18.38.1 03-Jun-2008  skrll Sync with netbsd-4.
 1.18.34.1 09-Dec-2007  reinoud Pullup to HEAD
 1.18.24.1 02-Feb-2008  riz Pull up following revision(s) (requested by tsutsui in ticket #1028):
sys/dev/ic/i82557reg.h: revision 1.19
sys/dev/ic/i82557var.h: revision 1.36
sys/dev/ic/i82557.c: revision 1.105
Pull several fixes from OpenBSD's fxp.c:
Rev 1.41:
use a nop with I bit set at the end of the tx chain. This avoids a race
between status update and clearing the suspend bit on machines which can't
write data smaller than 32bits at a time.
This should fix PR port-alpha/30560.
Rev 1.50:
Fix nasty bug where driver would not correctly catch and handle an rnr
condition when it was due to the the recieve buffers being exhausted with
no packet transmits during that time. Symptom was that the fxp would
simply stop interrupting for the next 15 seconds until the watchdog kicked
in and reset the chip due to 15 seconds of inactivity, making the fxp very
poorly behaved when hammered on hard.
Rev 1.61:
Defer reinitialisation of the RU until after the interrupt handler has had
a chance to process all pending packets, otherwise the chip may overwrite
their mbuf clusters after we have freed them.
Eliminates a race that can cause random pool corruption when reconfiguring
an interface under heavy network load.
And one more change for RX sanity:
- put RU into suspend when the last RFA is processed.
These RNR/RU changes may fix pool corruption problems on fxp.
Tested on AlphaPC164 and i386 with i82559 and i82550.
 1.19.16.2 04-May-2009  yamt sync with head.
 1.19.16.1 16-May-2008  yamt sync with head.
 1.19.14.1 18-May-2008  yamt sync with head.
 1.19.12.2 17-Jan-2009  mjf Sync with HEAD.
 1.19.12.1 02-Jun-2008  mjf Sync with HEAD.
 1.20.10.1 14-Dec-2008  bouyer Pull up following revision(s) (requested by tsutsui in ticket #181):
sys/dev/ic/i82557.c: revision 1.116-1.120
sys/dev/ic/i82557reg.h: revision 1.21
sys/dev/ic/i82557var.h: revision 1.41
doc/CHANGES: patch
Call BUS_DMASYNC_PREREAD more strictly on polling DMA descriptors.
Add a workaround for hardware ip4csum-tx bug and enable it.
Confirmed on i82550 rev 12 and UDP fragment packets by ttcp(1).
Sort Tx/Rx macro in previous.
Add a missed htole32() on the previous ip4csum-tx bug workaround.
Don't pass uint8_t values to le16toh() in fxp_rx_hwcksum().
fxp(4)'s RX hwcksum results weren't used at all on big endian machines.
Checked by i82550 and vmstat -ev on macppc GENERIC kernel with
options INET_CSUM_COUNTERS,TCP_CSUM_COUNTERS,UDP_CSUM_COUNTERS.
 1.20.8.3 28-Apr-2009  skrll Sync with HEAD.
 1.20.8.2 03-Mar-2009  skrll Sync with HEAD.
 1.20.8.1 19-Jan-2009  skrll Sync with HEAD.
 1.20.6.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.21.4.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.52 13-Apr-2015  riastradh Convert sys/dev to use <sys/rndsource.h>.
 1.51 22-Nov-2014  joerg branches: 1.51.2;
Replace void * cast with proper __UNVOLATILE.
 1.50 02-Feb-2012  tls branches: 1.50.6; 1.50.22;
Entropy-pool implementation move and cleanup.

1) Move core entropy-pool code and source/sink/sample management code
to sys/kern from sys/dev.

2) Remove use of NRND as test for presence of entropy-pool code throughout
source tree.

3) Remove use of RND_ENABLED in device drivers as microoptimization to
avoid expensive operations on disabled entropy sources; make the
rnd_add calls do this directly so all callers benefit.

4) Fix bug in recent rnd_add_data()/rnd_add_uint32() changes that might
have lead to slight entropy overestimation for some sources.

5) Add new source types for environmental sensors, power sensors, VM
system events, and skew between clocks, with a sample implementation
for each.

ok releng to go in before the branch due to the difficulty of later
pullup (widespread #ifdef removal and moved files). Tested with release
builds on amd64 and evbarm and live testing on amd64.
 1.49 19-Nov-2011  tls branches: 1.49.2;
First step of random number subsystem rework described in
<20111022023242.BA26F14A158@mail.netbsd.org>. This change includes
the following:

An initial cleanup and minor reorganization of the entropy pool
code in sys/dev/rnd.c and sys/dev/rndpool.c. Several bugs are
fixed. Some effort is made to accumulate entropy more quickly at
boot time.

A generic interface, "rndsink", is added, for stream generators to
request that they be re-keyed with good quality entropy from the pool
as soon as it is available.

The arc4random()/arc4randbytes() implementation in libkern is
adjusted to use the rndsink interface for rekeying, which helps
address the problem of low-quality keys at boot time.

An implementation of the FIPS 140-2 statistical tests for random
number generator quality is provided (libkern/rngtest.c). This
is based on Greg Rose's implementation from Qualcomm.

A new random stream generator, nist_ctr_drbg, is provided. It is
based on an implementation of the NIST SP800-90 CTR_DRBG by
Henric Jungheim. This generator users AES in a modified counter
mode to generate a backtracking-resistant random stream.

An abstraction layer, "cprng", is provided for in-kernel consumers
of randomness. The arc4random/arc4randbytes API is deprecated for
in-kernel use. It is replaced by "cprng_strong". The current
cprng_fast implementation wraps the existing arc4random
implementation. The current cprng_strong implementation wraps the
new CTR_DRBG implementation. Both interfaces are rekeyed from
the entropy pool automatically at intervals justifiable from best
current cryptographic practice.

In some quick tests, cprng_fast() is about the same speed as
the old arc4randbytes(), and cprng_strong() is about 20% faster
than rnd_extract_data(). Performance is expected to improve.

The AES code in src/crypto/rijndael is no longer an optional
kernel component, as it is required by cprng_strong, which is
not an optional kernel component.

The entropy pool output is subjected to the rngtest tests at
startup time; if it fails, the system will reboot. There is
approximately a 3/10000 chance of a false positive from these
tests. Entropy pool _input_ from hardware random numbers is
subjected to the rngtest tests at attach time, as well as the
FIPS continuous-output test, to detect bad or stuck hardware
RNGs; if any are detected, they are detached, but the system
continues to run.

A problem with rndctl(8) is fixed -- datastructures with
pointers in arrays are no longer passed to userspace (this
was not a security problem, but rather a major issue for
compat32). A new kernel will require a new rndctl.

The sysctl kern.arandom() and kern.urandom() nodes are hooked
up to the new generators, but the /dev/*random pseudodevices
are not, yet.

Manual pages for the new kernel interfaces are forthcoming.
 1.48 25-Feb-2010  dyoung branches: 1.48.10;
Make fxp at cardbus detach during shutdown.

Stop calling (*cardbus_ctrl) to enable bus mastering, I/O and memory
spaces on the CardBus bridge. cbb(4) always enables that stuff,
anyway. In the process, avoid remembering what BAR we mapped by
writing CARDBUS_{IO,MEM}_ENABLE to sc_cben or sc_cbenable, and
record the BAR in use sc_bar, instead.

Replace more CARDBUS_ constants with PCI_ constants.

Compile-tested, only.
 1.47 12-May-2009  cegger branches: 1.47.2;
struct device * -> device_t, no functional changes intended.
 1.46 15-Mar-2009  tsutsui Adjust comments about sc_flags.
 1.45 11-Mar-2009  tsutsui u_intNN_t -> uintNN_t
 1.44 07-Mar-2009  tsutsui Add TCPv4/UDPv4 RX hardware checksum support for i82559 and later chips
which don't have EXT_RFA and IPCB support. From hme(4) driver and
FreeBSD's fxp(4). Tested on i82559.

XXX: Probably we should have a common function to parse RX packet headers
XXX: to handle a raw checksum value and share it among hme(4) and gem(4) etc.
 1.43 20-Feb-2009  mrg - remove FXPF_IPCB flag. it should always/only be used with the code
conditional on FXPF_EXT_TXCB, so, replace all uses with that
- for the pci frontend, reestablish some flags lost the the prior
changes and simplify one of the cases

this fixes PR 40677 and may fix PR 40431.
 1.42 18-Jan-2009  mrg branches: 1.42.2;
The PCI revision numbers are unique to a PCI vendor/product
ID pair. Misuse of the revision numbers was causing some of the chip
features to be disabled on some integrated Intel chips. So, move the
determination of the features into the bus frontend, where the
vendor/product ID is known. (Note: sc_rev should be removed. The
microcode patch stuff is also busted and needs to be fixed.) Also,
poll the actual flow control status in inphy, rather than making
assumptions.

contributed anonymously.
 1.41 03-Dec-2008  tsutsui Add a workaround for hardware ip4csum-tx bug and enable it.
Confirmed on i82550 rev 12 and UDP fragment packets by ttcp(1).
 1.40 09-Jul-2008  joerg branches: 1.40.2; 1.40.4;
- device/softc split for fxp(4)
 1.39 28-Apr-2008  martin branches: 1.39.2; 1.39.4; 1.39.6;
Remove clause 3 and 4 from TNF licenses
 1.38 13-Dec-2007  degroote branches: 1.38.6; 1.38.8; 1.38.10;
Remove the shutdown hook (pmf takes care about it already), as suggested by joerg@
 1.37 10-Dec-2007  degroote branches: 1.37.2;
Register fxp @ pci to the pmf framework
Kill reference to old powerhook framework.
 1.36 08-Dec-2007  tsutsui branches: 1.36.2;
Pull several fixes from OpenBSD's fxp.c:

Rev 1.41:
> use a nop with I bit set at the end of the tx chain. This avoids a race
> between status update and clearing the suspend bit on machines which can't
> write data smaller than 32bits at a time.
This should fix PR port-alpha/30560.

Rev 1.50:
> Fix nasty bug where driver would not correctly catch and handle an rnr
> condition when it was due to the the recieve buffers being exhausted with
> no packet transmits during that time. Symptom was that the fxp would
> simply stop interrupting for the next 15 seconds until the watchdog kicked
> in and reset the chip due to 15 seconds of inactivity, making the fxp very
> poorly behaved when hammered on hard.

Rev 1.61:
> Defer reinitialisation of the RU until after the interrupt handler has had
> a chance to process all pending packets, otherwise the chip may overwrite
> their mbuf clusters after we have freed them.
>
> Eliminates a race that can cause random pool corruption when reconfiguring
> an interface under heavy network load.

And one more change for RX sanity:
- put RU into suspend when the last RFA is processed.

These RNR/RU changes may fix pool corruption problems on fxp.

Tested on AlphaPC164 and i386 with i82559 and i82550.
 1.35 11-Dec-2005  christos branches: 1.35.24; 1.35.34; 1.35.38; 1.35.44; 1.35.46; 1.35.56; 1.35.58;
merge ktrace-lwp.
 1.34 27-Feb-2005  perry branches: 1.34.4;
nuke trailing whitespace
 1.33 16-May-2004  thorpej branches: 1.33.4; 1.33.6;
Patch from HITOSHI Osada:
* Add PAUSE-related event counters.
* Return flow control bits in fxp_mii_mediastatus().
 1.32 16-May-2004  thorpej Patch from HITOSHI Osada:
* Newer chips do not need the receiver lock-up workaround; detect when it
is required.
 1.31 26-May-2003  yamt branches: 1.31.2;
ip/tcp/udp checksum offloading support for i82550.
largely from FreeBSD.
 1.30 29-Sep-2002  wiz "definitions" has lots of 'i's, but that's not reason to leave one out.
 1.29 20-May-2002  mycroft The FIX_RESUME_BUG hack does not work, so remove it.
Also, attempt to clarify the message slightly when updating the EEPROM.
 1.28 03-May-2002  thorpej branches: 1.28.2;
Bump the number of Tx DMA segments from 8 to 16 (the zero-copy socket
code sometimes sees more than 8).
 1.27 05-Apr-2002  thorpej Add support for the "CPUSaver" receive interrupt mitigating microcode
on the following PRO/100 chips:

* i82558 step A4
* i82558 step B0
* i82559 step A0
* i82559S step A
* i82550
* i82550 step C

The interrupt delay is configurable on all microcodable chips. The
maximum "bundle" size (packet count) is configurable on all but the
i82558.

The microcode is enabled by setting IFF_LINK0 on the interface.

Derived from code in FreeBSD.
 1.26 15-Jun-2001  thorpej branches: 1.26.2;
Split the Tx and Rx interrupt routines into separate functions,
and add some (optional) event counters.
 1.25 12-Jun-2001  wiz receive, not recieve
 1.24 02-Jun-2001  thorpej Define some extra configuration block bits used on the i82550 (a.k.a.
PRO 100/S), including the extended RFA format. Don't hard-code the
RFA size to allow us to use the extended format in the future.
 1.23 22-May-2001  thorpej Some changes from the new FreeBSD `fxp' driver:
- Add some additional config block bits for the i82558/i82559.
- Change the config block template to only fill in the must-be-one
reserved bits, leave fxp_init() to fill in all the important things.
- On the i82558/i82559, we can use "Receive Long Frames" rather than
"Save Bad Frames" to support the VLAN MTU.
- Use 802.3x flow control on the i82558/i82559. This is all handled
transparently by the hardware. When in promiscuous mode, allow
wire-watchers to see the flow control frames.
- Use the Extended TxCB format on the i82558/i82559. This places two
Transmit Buffer Descriptors directly in the TxCB, which should cover
the vast majority of packets transmitted. This saves PCI transactions
that would otherwise be required to fetch the TBD list.

With the tansmit queue length changes from yesterday, this gets us up to
11.5MB/s TCP transmit speed, out of an absolute maximum of 12MB/s possible
on a 100Mb/s link.
 1.22 22-May-2001  thorpej Report 82558, 82559, etc. based on chip revision. Also, remember which
revsion we have for feature enables later.
 1.21 22-May-2001  thorpej A little slight cleanup.
 1.20 21-May-2001  thorpej Re-arrange the transmit control data somewhat so that we can
use the extended TxCB format (that change will happen later).
 1.19 21-May-2001  thorpej Change NTXSEGS from 16 to 8, and the TXQUEUE len from 128 to 256. Also
increase the number of Rx buffers from 64 to 128.

These mirror some performance tweaks made to the sip(4) driver.
 1.18 21-May-2001  thorpej The 82801BA built-in Ethernet has a bug which requires us to
issue a NOP before a CU_RESUME when in 10baseT mode. Handle
this.
 1.17 21-May-2001  thorpej ANSI'ify.
 1.16 29-May-2000  jhawk branches: 1.16.2; 1.16.4;
For all network drivers that call ether_ifattach(), and also
have _detach() functions:
Ensure that softc keeps state about whether the attach succeeded,
and make the detach function return immediately if the attach did
not complete.
 1.15 26-May-2000  tsutsui branches: 1.15.2;
Call bus_dmamap_sync() properly before/after reading fcd_stats
in fxp_control_data.
 1.14 12-May-2000  jhawk sc_ih (interrupt cookie) is not pci-specific data
and needs to remain in fxp_softc rather than fxp_pci_softc;
otherwise we break cardbus.
 1.13 12-May-2000  jhawk Move pci-specific data to fxp_pci_softc from fxp_pci_softc.
Add some more pci-specific data to fxp_pci_softc.
 1.12 23-Mar-2000  thorpej New callout mechanism with two major improvements over the old
timeout()/untimeout() API:
- Clients supply callout handle storage, thus eliminating problems of
resource allocation.
- Insertion and removal of callouts is constant time, important as
this facility is used quite a lot in the kernel.

The old timeout()/untimeout() API has been removed from the kernel.
 1.11 12-Feb-2000  enami Add activate routine and check device active flag also in one second
tick handler.
 1.10 09-Feb-2000  joda add detach code
 1.9 12-Dec-1999  thorpej Take a stab at making this work on big-endian systems.
 1.8 30-Oct-1999  sommerfeld Add enable/disable support and EEPROM size selection, prerequisites
for getting the cardbus fxp attachment to work.

Tested on the built-in 82559 in a VAIO Z505S.

From Johan Danielsson / PR8631; changed slightly to KNF.
 1.7 28-Oct-1999  sommerfeld Fix suspend/resume-related problems observed on fxp0 on Sony Z505S:

Symptoms: system would crash with "data modified on free list" pool
panic from the mbuf cluster pool shortly after a resume. The cluster
in question contained a valid 82557 receive descriptor and an IP
packet. Happened sporadically in normal use. Easiest way for me to
reproduce it was to run tcpdump and a flood ping and do a
suspend/resume cycle or two.

Changes:
- in interrupt handler, if the interface isn't in IFF_RUNNING state,
just ack interrupts and return; don't try to receive packets, queue
new descriptors, etc., etc.,
- add power control hook to take interface down on suspend,
and restart it (if it was up) on resume.
- tweaks to fxp_stop and fxp_shutdown to avoid recursive panics due
to the (now fixed) bug.
 1.6 05-Aug-1999  thorpej branches: 1.6.2; 1.6.4; 1.6.6;
Since we have to go through fxp_init() to properly handle IFF_ALLMULTI
anyway, take advantage of this and greatly simplify the programming
of the multicast filter. This solves the last reported "device timeout"
problem with this driver.
 1.5 04-Aug-1999  thorpej Almost completely rewrite the receive logic, making it as close as possible
to the EPIC/100 driver's (adjusting for the fact that Intel Ethernet chips
are from Pluto):
* Don't allocate receive buffers until the interface is actually brought
up, and release all of them if the interface is taken down.
* Add a knob (defaults to off) which will copy an incoming packet to
a single header mbuf if it is small enough to fit in one, rather than
burning an entire cluster on it. Note that this change will be mostly
moot if/when sbcompress() is changed to handle compressing clusters.

Simplify some of the receive list logic:
* Rather than using a homegrown queue and additional software RX descriptors,
use an ifqueue to queue receive buffers, and M_{GET,SET}CTX() to hook DMA
maps and receive buffers together.

Clean up a bit:
* Macroize a bunch of things to make the code a bit easier to follow.
 1.4 04-Aug-1999  thorpej Only tick the MII if we are using it.
 1.3 03-Aug-1999  thorpej G/c a flag.
 1.2 03-Aug-1999  thorpej Completely rewrite the transmit logic, making it look more like the
EPIC/100 driver's. Also, fix the "all multicast" logic. Also do some
general cleanup.
 1.1 20-Jun-1999  thorpej branches: 1.1.2;
Bus-independent back-end driver for Intel i82557 fast Ethernet chips.
 1.1.2.2 01-Jul-1999  thorpej Sync w/ -current.
 1.1.2.1 20-Jun-1999  thorpej file i82557var.h was added on branch chs-ubc2 on 1999-07-01 23:32:29 +0000
 1.6.6.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.6.4.1 15-Nov-1999  fvdl Sync with -current
 1.6.2.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.15.2.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.16.4.4 18-Oct-2002  nathanw Catch up to -current.
 1.16.4.3 20-Jun-2002  nathanw Catch up to -current.
 1.16.4.2 17-Apr-2002  nathanw Catch up to -current.
 1.16.4.1 21-Jun-2001  nathanw Catch up to -current.
 1.16.2.1 06-Jun-2002  he Pull up revisions 1.17-1.26,1.29 (via patch, requested by mycroft):
Work around a bug which can cause some machines to randomly hang.
Drag along performance improvements and improved hardware support.
 1.26.2.2 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.26.2.1 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.28.2.1 30-May-2002  gehenna Catch up with -current.
 1.31.2.4 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.31.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.31.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.31.2.1 03-Aug-2004  skrll Sync with HEAD
 1.33.6.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.33.4.1 29-Apr-2005  kent sync with -current
 1.34.4.1 21-Jan-2008  yamt sync with head
 1.35.58.1 02-Feb-2008  riz Pull up following revision(s) (requested by tsutsui in ticket #1028):
sys/dev/ic/i82557reg.h: revision 1.19
sys/dev/ic/i82557var.h: revision 1.36
sys/dev/ic/i82557.c: revision 1.105
Pull several fixes from OpenBSD's fxp.c:
Rev 1.41:
use a nop with I bit set at the end of the tx chain. This avoids a race
between status update and clearing the suspend bit on machines which can't
write data smaller than 32bits at a time.
This should fix PR port-alpha/30560.
Rev 1.50:
Fix nasty bug where driver would not correctly catch and handle an rnr
condition when it was due to the the recieve buffers being exhausted with
no packet transmits during that time. Symptom was that the fxp would
simply stop interrupting for the next 15 seconds until the watchdog kicked
in and reset the chip due to 15 seconds of inactivity, making the fxp very
poorly behaved when hammered on hard.
Rev 1.61:
Defer reinitialisation of the RU until after the interrupt handler has had
a chance to process all pending packets, otherwise the chip may overwrite
their mbuf clusters after we have freed them.
Eliminates a race that can cause random pool corruption when reconfiguring
an interface under heavy network load.
And one more change for RX sanity:
- put RU into suspend when the last RFA is processed.
These RNR/RU changes may fix pool corruption problems on fxp.
Tested on AlphaPC164 and i386 with i82559 and i82550.
 1.35.56.2 26-Dec-2007  ad Sync with head.
 1.35.56.1 08-Dec-2007  ad Sync with head.
 1.35.46.1 09-Jan-2008  matt sync with HEAD
 1.35.44.1 09-Dec-2007  jmcneill Sync with HEAD.
 1.35.38.1 03-Jun-2008  skrll Sync with netbsd-4.
 1.35.34.1 09-Dec-2007  reinoud Pullup to HEAD
 1.35.24.1 02-Feb-2008  riz Pull up following revision(s) (requested by tsutsui in ticket #1028):
sys/dev/ic/i82557reg.h: revision 1.19
sys/dev/ic/i82557var.h: revision 1.36
sys/dev/ic/i82557.c: revision 1.105
Pull several fixes from OpenBSD's fxp.c:
Rev 1.41:
use a nop with I bit set at the end of the tx chain. This avoids a race
between status update and clearing the suspend bit on machines which can't
write data smaller than 32bits at a time.
This should fix PR port-alpha/30560.
Rev 1.50:
Fix nasty bug where driver would not correctly catch and handle an rnr
condition when it was due to the the recieve buffers being exhausted with
no packet transmits during that time. Symptom was that the fxp would
simply stop interrupting for the next 15 seconds until the watchdog kicked
in and reset the chip due to 15 seconds of inactivity, making the fxp very
poorly behaved when hammered on hard.
Rev 1.61:
Defer reinitialisation of the RU until after the interrupt handler has had
a chance to process all pending packets, otherwise the chip may overwrite
their mbuf clusters after we have freed them.
Eliminates a race that can cause random pool corruption when reconfiguring
an interface under heavy network load.
And one more change for RX sanity:
- put RU into suspend when the last RFA is processed.
These RNR/RU changes may fix pool corruption problems on fxp.
Tested on AlphaPC164 and i386 with i82559 and i82550.
 1.36.2.1 11-Dec-2007  yamt sync with head.
 1.37.2.1 13-Dec-2007  bouyer Sync with HEAD
 1.38.10.4 11-Mar-2010  yamt sync with head
 1.38.10.3 16-May-2009  yamt sync with head
 1.38.10.2 04-May-2009  yamt sync with head.
 1.38.10.1 16-May-2008  yamt sync with head.
 1.38.8.1 18-May-2008  yamt sync with head.
 1.38.6.3 17-Jan-2009  mjf Sync with HEAD.
 1.38.6.2 28-Sep-2008  mjf Sync with HEAD.
 1.38.6.1 02-Jun-2008  mjf Sync with HEAD.
 1.39.6.2 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.39.6.1 19-Oct-2008  haad Sync with HEAD.
 1.39.4.1 18-Jul-2008  simonb Sync with head.
 1.39.2.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.40.4.1 14-Dec-2008  bouyer Pull up following revision(s) (requested by tsutsui in ticket #181):
sys/dev/ic/i82557.c: revision 1.116-1.120
sys/dev/ic/i82557reg.h: revision 1.21
sys/dev/ic/i82557var.h: revision 1.41
doc/CHANGES: patch
Call BUS_DMASYNC_PREREAD more strictly on polling DMA descriptors.
Add a workaround for hardware ip4csum-tx bug and enable it.
Confirmed on i82550 rev 12 and UDP fragment packets by ttcp(1).
Sort Tx/Rx macro in previous.
Add a missed htole32() on the previous ip4csum-tx bug workaround.
Don't pass uint8_t values to le16toh() in fxp_rx_hwcksum().
fxp(4)'s RX hwcksum results weren't used at all on big endian machines.
Checked by i82550 and vmstat -ev on macppc GENERIC kernel with
options INET_CSUM_COUNTERS,TCP_CSUM_COUNTERS,UDP_CSUM_COUNTERS.
 1.40.2.3 28-Apr-2009  skrll Sync with HEAD.
 1.40.2.2 03-Mar-2009  skrll Sync with HEAD.
 1.40.2.1 19-Jan-2009  skrll Sync with HEAD.
 1.42.2.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.47.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.48.10.1 17-Apr-2012  yamt sync with head
 1.49.2.1 18-Feb-2012  mrg merge to -current.
 1.50.22.1 15-May-2015  snj Pull up following revision(s) (requested by joerg in ticket #772):
sys/arch/arm/amlogic/amlogic_genfb.c: revision 1.4
sys/arch/arm/arm/disassem.c: revision 1.25
sys/arch/arm/omap/am335x_cm_padconf.c: revision 1.3
sys/arch/arm/omap/sitara_cm.h: revision 1.2
sys/dev/ic/i82557var.h: revision 1.51
sys/dev/ic/rtl8169.c: revision 1.143
sys/dev/ieee1394/fwcrom.c: revision 1.17
sys/external/bsd/dwc2/dwc2.c: revision 1.32
dwc2_hubd appears to be unused so #if 0 it in order to appease clang
--
Preserve const.
--
No reason not to make the string const.
--
Drop unnecessary-but-harmful casts.
--
Replace void * cast with proper __UNVOLATILE.
--
Preserve const.
--
amlogic_genfb_hdmi_write_4 is currently unused, mark it as such.
 1.50.6.1 03-Dec-2017  jdolecek update from HEAD
 1.51.2.1 06-Jun-2015  skrll Sync with HEAD
 1.91 09-Feb-2024  andvar fix spelling mistakes, mainly in comments and log messages.
 1.90 24-Oct-2021  andvar fix various typos in comments, mainly copypasta.
 1.89 19-Mar-2020  thorpej Don't bother with IFF_OACTIVE. Just keep processing so long as
sc->xmit_busy is less than NTXBUF.
 1.88 29-Jan-2020  thorpej Adopt <net/if_stats.h>.
 1.87 10-Nov-2019  chs branches: 1.87.2;
in many device attach paths, allocate memory with M_WAITOK instead of M_NOWAIT
and remove code to handle failures that can no longer happen.
 1.86 21-Oct-2019  msaitoh if_percpuq(9) automatically increments if_ipackets, so don't increment it in
the driver itself to prevent double count.
 1.85 29-May-2019  msaitoh branches: 1.85.2;
Even if we don't use MII(4), use the common path of SIOC[GS]IFMEDIA in
sys/net/if_ethersubr.c if we can.
- Add ec_ifmedia into struct ethercom.
- ec_mii in struct ethercom is kept and used as it is. It might be used in
future. Note that some Ethernet drivers which _DOESN'T_ use mii(4) use
ec_mii for keeping the if_media. Those should be changed in future.
 1.84 28-May-2019  msaitoh Use ETHER_LOCK()/ETHER_UNLOCK() for all ethernet drivers to protect ec_multi*.
 1.83 23-May-2019  msaitoh Whitespace fix (mainly tabify).
 1.82 23-May-2019  msaitoh -No functional change:
- Simplify struct ethercom's pointer near ETHER_FIRST_MULTI().
- Simplify MII structure initialization.
- u_int*_t -> uint*_t.
- KNF
 1.81 26-Apr-2019  msaitoh No functional change:
- u_int_{8,16,32}_t -> uint_{8,16,32}_t
- KNF.
- Tabify.
- Remove extra space.
 1.80 05-Feb-2019  msaitoh Remove very old IFF_NOTRAILERS flag.
 1.79 03-Sep-2018  riastradh Rename min/max -> uimin/uimax for better honesty.

These functions are defined on unsigned int. The generic name
min/max should not silently truncate to 32 bits on 64-bit systems.
This is purely a name change -- no functional change intended.

HOWEVER! Some subsystems have

#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))

even though our standard name for that is MIN/MAX. Although these
may invite multiple evaluation bugs, these do _not_ cause integer
truncation.

To avoid `fixing' these cases, I first changed the name in libkern,
and then compile-tested every file where min/max occurred in order to
confirm that it failed -- and thus confirm that nothing shadowed
min/max -- before changing it.

I have left a handful of bootloaders that are too annoying to
compile-test, and some dead code:

cobalt ews4800mips hp300 hppa ia64 luna68k vax
acorn32/if_ie.c (not included in any kernels)
macppc/if_gm.c (superseded by gem(4))

It should be easy to fix the fallout once identified -- this way of
doing things fails safe, and the goal here, after all, is to _avoid_
silent integer truncations, not introduce them.

Maybe one day we can reintroduce min/max as type-generic things that
never silently truncate. But we should avoid doing that for a while,
so that existing code has a chance to be detected by the compiler for
conversion to uimin/uimax without changing the semantics until we can
properly audit it all. (Who knows, maybe in some cases integer
truncation is actually intended!)
 1.78 26-Jun-2018  msaitoh branches: 1.78.2;
Implement the BPF direction filter (BIOC[GS]DIRECTION). It provides backward
compatibility with BIOC[GS]SEESENT ioctl. The userland interface is the same
as FreeBSD.

This change also fixes a bug that the direction is misunderstand on some
environment by passing the direction to bpf_mtap*() instead of checking
m->m_pkthdr.rcvif.
 1.77 22-Jun-2018  msaitoh It's not required to include net/bpfdesc.h. Remove it.
 1.76 20-Feb-2017  ozaki-r branches: 1.76.6; 1.76.12;
Apply deferred if_start to more drivers
 1.75 15-Dec-2016  ozaki-r branches: 1.75.2;
Move bpf_mtap and if_ipackets++ on Rx of each driver to percpuq if_input

The benefits of the change are:
- We can reduce codes
- We can provide the same behavior between drivers
- Where/When if_ipackets is counted up
- Note that some drivers still update packet statistics in their own
way (periodical update)
- Moved bpf_mtap run in softint
- This makes it easy to MP-ify bpf

Proposed on tech-kern and tech-net
 1.74 14-Jul-2016  msaitoh branches: 1.74.2;
- Use aprint*() more in xxx_attach().
- Add missing aprint_naive("\n").
- Remove extra spaces and tabs.
- KNF.
 1.73 11-Jul-2016  msaitoh KNF. No functional change.
 1.72 10-Jun-2016  ozaki-r Introduce m_set_rcvif and m_reset_rcvif

The API is used to set (or reset) a received interface of a mbuf.
They are counterpart of m_get_rcvif, which will come in another
commit, hide internal of rcvif operation, and reduce the diff of
the upcoming change.

No functional change.
 1.71 09-Feb-2016  ozaki-r Introduce softint-based if_input

This change intends to run the whole network stack in softint context
(or normal LWP), not hardware interrupt context. Note that the work is
still incomplete by this change; to that end, we also have to softint-ify
if_link_state_change (and bpf) which can still run in hardware interrupt.

This change softint-ifies at ifp->if_input that is called from
each device driver (and ieee80211_input) to ensure Layer 2 runs
in softint (e.g., ether_input and bridge_input). To this end,
we provide a framework (called percpuq) that utlizes softint(9)
and percpu ifqueues. With this patch, rxintr of most drivers just
queues received packets and schedules a softint, and the softint
dequeues packets and does rest packet processing.

To minimize changes to each driver, percpuq is allocated in struct
ifnet for now and that is initialized by default (in if_attach).
We probably have to move percpuq to softc of each driver, but it's
future work. At this point, only wm(4) has percpuq in its softc
as a reference implementation.

Additional information including performance numbers can be found
in the thread at tech-kern@ and tech-net@:
http://mail-index.netbsd.org/tech-kern/2016/01/14/msg019997.html

Acknowledgment: riastradh@ greatly helped this work.
Thank you very much!
 1.70 02-Jul-2011  mrg branches: 1.70.12; 1.70.30;
listen to GCC 4.5 and change "!!x | y" into "(!!x) | y".
 1.69 03-Jun-2011  tsutsui Split device_t/softc of i82586. No crash on TME emulating sun2.
 1.68 05-Apr-2010  joerg branches: 1.68.2; 1.68.6;
Push the bpf_ops usage back into bpf.h. Push the common ifp->if_bpf
check into the inline functions as well the fourth argument for
bpf_attach.
 1.67 19-Jan-2010  pooka branches: 1.67.2; 1.67.4;
Redefine bpf linkage through an always present op vector, i.e.
#if NBPFILTER is no longer required in the client. This change
doesn't yet add support for loading bpf as a module, since drivers
can register before bpf is attached. However, callers of bpf can
now be modularized.

Dynamically loadable bpf could probably be done fairly easily with
coordination from the stub driver and the real driver by registering
attachments in the stub before the real driver is loaded and doing
a handoff. ... and I'm not going to ponder the depths of unload
here.

Tested with i386/MONOLITHIC, modified MONOLITHIC without bpf and rump.
 1.66 14-Mar-2009  dsl ANSIfy another 1261 function definitions.
The only ones left in sys are beyond by sed script!
(or in sys/dist or sys/external)
Mostly they have function pointer parameters.
 1.65 14-Mar-2009  dsl Change about 4500 of the K&R function definitions to ANSI ones.
There are still about 1600 left, but they have ',' or /* ... */
in the actual variable definitions - which my awk script doesn't handle.
There are also many that need () -> (void).
(The script does handle misordered arguments.)
 1.64 16-Dec-2008  christos branches: 1.64.2;
replace bitmask_snprintf(9) with snprintb(3)
 1.63 07-Nov-2008  dyoung *** Summary ***

When a link-layer address changes (e.g., ifconfig ex0 link
02:de:ad:be:ef:02 active), send a gratuitous ARP and/or a Neighbor
Advertisement to update the network-/link-layer address bindings
on our LAN peers.

Refuse a change of ethernet address to the address 00:00:00:00:00:00
or to any multicast/broadcast address. (Thanks matt@.)

Reorder ifnet ioctl operations so that driver ioctls may inherit
the functions of their "class"---ether_ioctl(), fddi_ioctl(), et
cetera---and the class ioctls may inherit from the generic ioctl,
ifioctl_common(), but both driver- and class-ioctls may override
the generic behavior. Make network drivers share more code.

Distinguish a "factory" link-layer address from others for the
purposes of both protecting that address from deletion and computing
EUI64.

Return consistent, appropriate error codes from network drivers.

Improve readability. KNF.

*** Details ***

In if_attach(), always initialize the interface ioctl routine,
ifnet->if_ioctl, if the driver has not already initialized it.
Delete if_ioctl == NULL tests everywhere else, because it cannot
happen.

In the ioctl routines of network interfaces, inherit common ioctl
behaviors by calling either ifioctl_common() or whichever ioctl
routine is appropriate for the class of interface---e.g., ether_ioctl()
for ethernets.

Stop (ab)using SIOCSIFADDR and start to use SIOCINITIFADDR. In
the user->kernel interface, SIOCSIFADDR's argument was an ifreq,
but on the protocol->ifnet interface, SIOCSIFADDR's argument was
an ifaddr. That was confusing, and it would work against me as I
make it possible for a network interface to overload most ioctls.
On the protocol->ifnet interface, replace SIOCSIFADDR with
SIOCINITIFADDR. In ifioctl(), return EPERM if userland tries to
invoke SIOCINITIFADDR.

In ifioctl(), give the interface the first shot at handling most
interface ioctls, and give the protocol the second shot, instead
of the other way around. Finally, let compatibility code (COMPAT_OSOCK)
take a shot.

Pull device initialization out of switch statements under
SIOCINITIFADDR. For example, pull ..._init() out of any switch
statement that looks like this:

switch (...->sa_family) {
case ...:
..._init();
...
break;
...
default:
..._init();
...
break;
}

Rewrite many if-else clauses that handle all permutations of IFF_UP
and IFF_RUNNING to use a switch statement,

switch (x & (IFF_UP|IFF_RUNNING)) {
case 0:
...
break;
case IFF_RUNNING:
...
break;
case IFF_UP:
...
break;
case IFF_UP|IFF_RUNNING:
...
break;
}

unifdef lots of code containing #ifdef FreeBSD, #ifdef NetBSD, and
#ifdef SIOCSIFMTU, especially in fwip(4) and in ndis(4).

In ipw(4), remove an if_set_sadl() call that is out of place.

In nfe(4), reuse the jumbo MTU logic in ether_ioctl().

Let ethernets register a callback for setting h/w state such as
promiscuous mode and the multicast filter in accord with a change
in the if_flags: ether_set_ifflags_cb() registers a callback that
returns ENETRESET if the caller should reset the ethernet by calling
if_init(), 0 on success, != 0 on failure. Pull common code from
ex(4), gem(4), nfe(4), sip(4), tlp(4), vge(4) into ether_ioctl(),
and register if_flags callbacks for those drivers.

Return ENOTTY instead of EINVAL for inappropriate ioctls. In
zyd(4), use ENXIO instead of ENOTTY to indicate that the device is
not any longer attached.

Add to if_set_sadl() a boolean 'factory' argument that indicates
whether a link-layer address was assigned by the factory or some
other source. In a comment, recommend using the factory address
for generating an EUI64, and update in6_get_hw_ifid() to prefer a
factory address to any other link-layer address.

Add a routing message, RTM_LLINFO_UPD, that tells protocols to
update the binding of network-layer addresses to link-layer addresses.
Implement this message in IPv4 and IPv6 by sending a gratuitous
ARP or a neighbor advertisement, respectively. Generate RTM_LLINFO_UPD
messages on a change of an interface's link-layer address.

In ether_ioctl(), do not let SIOCALIFADDR set a link-layer address
that is broadcast/multicast or equal to 00:00:00:00:00:00.

Make ether_ioctl() call ifioctl_common() to handle ioctls that it
does not understand.

In gif(4), initialize if_softc and use it, instead of assuming that
the gif_softc and ifp overlap.

Let ifioctl_common() handle SIOCGIFADDR.

Sprinkle rtcache_invariants(), which checks on DIAGNOSTIC kernels
that certain invariants on a struct route are satisfied.

In agr(4), rewrite agr_ioctl_filter() to be a bit more explicit
about the ioctls that we do not allow on an agr(4) member interface.

bzero -> memset. Delete unnecessary casts to void *. Use
sockaddr_in_init() and sockaddr_in6_init(). Compare pointers with
NULL instead of "testing truth". Replace some instances of (type
*)0 with NULL. Change some K&R prototypes to ANSI C, and join
lines.
 1.62 28-Apr-2008  martin branches: 1.62.6; 1.62.8;
Remove clause 3 and 4 from TNF licenses
 1.61 08-Apr-2008  cegger branches: 1.61.2; 1.61.4;
use aprint_*_dev and device_xname
 1.60 19-Oct-2007  ad branches: 1.60.16;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.59 27-Aug-2007  dyoung branches: 1.59.2; 1.59.6;
Constify: use CLLADDR() instead of LLADDR() wherever possible.
 1.58 04-Mar-2007  christos branches: 1.58.2; 1.58.10; 1.58.14;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.57 16-Nov-2006  christos branches: 1.57.4;
__unused removal on arguments; approved by core.
 1.56 12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.55 24-Dec-2005  perry branches: 1.55.20; 1.55.22;
__inline__ -> inline
 1.54 24-Dec-2005  perry Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.53 11-Dec-2005  christos merge ktrace-lwp.
 1.52 30-May-2005  christos branches: 1.52.2;
- add missing const
- fix variable shadowing
- remove unneeded casts
 1.51 27-Feb-2005  perry nuke trailing whitespace
 1.50 04-Feb-2005  perry de-__P
 1.49 30-Oct-2004  thorpej branches: 1.49.4; 1.49.6;
When adding/deleting multicast addresses, only whack the address
filter if the interface is marked RUNNING.

Fixes kern/27678.
 1.48 02-Nov-2003  wiz branches: 1.48.4;
Fix some typos. From Tom Cosgrove via jmc@openbsd.
 1.47 14-Sep-2003  junyoung Remove duplicate lines.
 1.46 27-Jan-2003  bouyer branches: 1.46.2;
Ops, initialise len before using it.
Also, the minimum frame len is ETHER_MIN_LEN - ETHER_CRC_LEN.
 1.45 15-Jan-2003  bouyer Use a properly zero'd buffer to pad the packet to ETHER_MIN_LEN-ETHER_CRC_LEN
 1.44 27-Sep-2002  provos remove trailing \n in panic(). approved perry.
 1.43 14-Jun-2002  thorpej Use M_IFMADDR instead of M_IPMADDR. From John Franklin, kern/16251.
 1.42 26-Nov-2001  fredette branches: 1.42.8; 1.42.10;
Added macros for the bits in the SYSBUS byte, and macros
for the i82596 PORT access interface, from the documentation
for that chip. These help clarify writes to the SYSBUS
part of the SCP, and PORT usage by i82596-aware drivers.
 1.41 13-Nov-2001  lukem add/cleanup RCSID
 1.40 13-Nov-2001  lukem cleanup RCSID
 1.39 07-Jul-2001  thorpej branches: 1.39.2;
bcopy -> memcpy, strcpy
 1.38 07-Jul-2001  thorpej bcmp -> memcmp
 1.37 09-Apr-2001  bjh21 ether_ioctl() expects i82586_init() to return an errno. Have it do so
(admittedly only EIO at present).
 1.36 10-Mar-2001  jdolecek add 'why' argument to the channel attention hook function; this argument
is similar to the one passed to hwreset hook function
 1.35 10-Mar-2001  jdolecek improve the error messages for IE_TDR_OPEN & IE_TDR_SHORT
 1.34 22-Jan-2001  bjh21 branches: 1.34.2;
Patch from PR kern/8001, submitted by Rafal Boni.

This adds support for EtherExpress/16 cards with 16k of RAM, and in the
process adds general support for PIO mode on these cards. This entails
changing the way the i82586 driver handles bus barriers, since it doesn't
allow for strange cases like this.

This has been tested on the i386 port with the 'ix' driver in both
16KB (which was the source of the problem) and 32KB modes, as well
as with the 'ef' driver. I've tested it (briefly) with 'ei' on arm26
as well. In theory, drivers other than 'ix' should follow precisely the
same code paths as before.
 1.33 14-Dec-2000  thorpej ALTQ'ify.
 1.32 15-Nov-2000  thorpej Move bpfattach()/bpfdetach() calls into ether_ifattach()/ether_ifdetach().
 1.31 04-Nov-2000  scw Invert the sense of i82586_init()'s return value so that
it matches what ether_ioctl() expects.
 1.30 02-Nov-2000  bjh21 Remove unnecessary includes.
Add a compiled-in RCSID.
 1.29 02-Nov-2000  bjh21 Convert to using ether_ioctl().
G/C huge swathes of unused code and outdated comments.
 1.28 01-Oct-2000  thorpej Move the check for "promisc + unicast + not for us" into ether_input(),
and change Ethernet drivers to always pass all received frames to
ether_input() (with a few exceptions, which are documented in the
code).
 1.27 11-May-2000  bjh21 Fixes from PR 9838:
Only access board memory using the front-end functions.
Add hook for clearing latched interrupts.
Corrent debugging printf of ethertype on LE systems.
Make it possible to us I82586_DEBUG as a kernel option.

Tested on arm26 and mvme68k.
 1.26 30-Mar-2000  augustss Remove register declarations.
 1.25 23-Aug-1999  pk branches: 1.25.2;
Disable inclusion of debugging code by default.
Turn compile-time flag I82586_DEBUG into a boolean switch.
 1.24 23-Aug-1999  pk Do not report "spurious interrupts"; this is a relic of the PC-only
days of this driver.
 1.23 23-Jun-1999  abs In xxx_mediachange(), if there is no callback to the front-end, just
return 0 instead of EINVAL. In this case, there will only be one media
type, and the upper-level if_media code will ensure that the user is
setting to that type.
This matches changes Jason made a while back to sys/dev/ic/lance.c
 1.22 21-May-1999  pk Since we're now prepending the ethernet header to mbuf on incoming
packets, make sure to align the data after the ethernet header.
 1.21 18-May-1999  thorpej Rework layer 2 protocol input routines. Instead of calling e.g. ether_input()
directly, call the function pointer (*if_input)(ifp, m). The input routine
expects the packet header to be at the head of the packet, and will adjust
as necessary. Privatize the layer 2 input and output routines, allowing
*_ifattach() to set them up as appropriate.
 1.20 17-Feb-1999  thorpej branches: 1.20.2; 1.20.4;
Avoid initializing the interface in the SIOCSIFFLAGS if ! UP and ! RUNNING.
 1.19 12-Dec-1998  mycroft Simplify the copy loops a bit.
 1.18 15-Aug-1998  mycroft branches: 1.18.4;
Assign my copyrights to TNF.
 1.17 15-Aug-1998  mycroft Assign copyright to TNF.
 1.16 15-Aug-1998  mycroft Make copyright notices with my name consistent.
 1.15 05-Jul-1998  jonathan defopt NS, NSIP.
 1.14 05-Jul-1998  jonathan defopt INET, NETATALK.
 1.13 04-Jun-1998  pk Check for the ether broadcast address in promiscuous mode (PR#5527).
 1.12 28-Feb-1998  pk Remove `NEW_I82586'
 1.11 01-Feb-1998  kleink Fix two harmless typographical errors in a comment.
 1.10 15-Jan-1998  pk Elaborate on "receiver not ready" conditions; we don't need a full reset
in most cases.

Move "async command" state into the softc structure.
 1.9 10-Jan-1998  pk * Fix a train-load of bugs, mostly present in one of these categories:
- "out of resource" errors cause receive buffer chain corruption
- resets can confuse the interrupt handler
- multi-cast setup causes receive buffer chain corruption
- shared memory setup incomplete

* Enhance effiency by avoiding unnecessary shared memory access,
improved handling of receive frame & buffer descriptors, and
introducing an `asynchronous' option when issuing 82586 commands.

* Exclusively use offsets relative to the bus handle representing the shared
memory area to formulate accesses to the chip's data-structures. The
front-ends provide glue functions that cater to the chip's endian-
sensitivity, to perform the actual device access (note: single-byte
accesses are done here using `bus_space_{read,write}_1()').
This concludes the transformation into a bus-independent driver module.
 1.8 06-Jan-1998  perry RCSID Police.
 1.7 13-Dec-1997  pk Changes from Rafal Boni to accommodate ISA driver front-ends.
 1.6 01-Aug-1997  pk Provide an alternative method of transmitting frames that avoids sending
a command to the 82586 for every frame to be transmitted. Instead, a
single command sets off the execution of a chain of commands consisting
of alternate XMITs and NO-OPs, where the link fields in the NO-OPs are
set to loop back onto themselves until the next XMIT is ready to go.
This trick found on a Linux WEB page.

All this induces reasonable transmission performance in my old multibus
adapter. The receiver performance is still abysmal..
 1.5 29-Jul-1997  pk branches: 1.5.2;
Some more cleanup and synchronization with ISA version.
Also make a start at using bus_* macros (just bus_barrier() for now).
 1.4 28-Jul-1997  pk No need to send two copies to the bpf tap when sending.
 1.3 28-Jul-1997  pk Bring over assorted changes applied to the ISA ie driver over time.
Fix some inaccuracies in the ring-scan code.
 1.2 23-Jul-1997  pk Kill a bogon in timeout loop.
 1.1 22-Jul-1997  pk First cut at a MI i82586 chip driver.
 1.5.2.1 23-Aug-1997  thorpej Update marc-pcmcia branch from trunk.
 1.18.4.1 11-Dec-1998  kenh The beginnings of interface detach support. Still some bugs, but mostly
works for me.

This work was originally by Bill Studenmund, and cleaned up by me.
 1.20.4.2 01-Jul-1999  thorpej Sync w/ -current.
 1.20.4.1 21-Jun-1999  thorpej Sync w/ -current.
 1.20.2.1 10-Sep-1999  he Pull up revision 1.24:
Remove a spurious printf() from the interrupt handler which got
triggered when sharing the interrupt level with other devices. (pk)
 1.25.2.6 21-Apr-2001  bouyer Sync with HEAD
 1.25.2.5 12-Mar-2001  bouyer Sync with HEAD.
 1.25.2.4 11-Feb-2001  bouyer Sync with HEAD.
 1.25.2.3 05-Jan-2001  bouyer Sync with HEAD
 1.25.2.2 22-Nov-2000  bouyer Sync with HEAD.
 1.25.2.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.34.2.8 17-Jan-2003  thorpej Sync with HEAD.
 1.34.2.7 18-Oct-2002  nathanw Catch up to -current.
 1.34.2.6 20-Jun-2002  nathanw Catch up to -current.
 1.34.2.5 08-Jan-2002  nathanw Catch up to -current.
 1.34.2.4 14-Nov-2001  nathanw Catch up to -current.
 1.34.2.3 24-Aug-2001  nathanw Catch up with -current.
 1.34.2.2 21-Jun-2001  nathanw Catch up to -current.
 1.34.2.1 09-Apr-2001  nathanw Catch up with -current.
 1.39.2.3 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.39.2.2 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.39.2.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.42.10.2 28-Jan-2003  jmc Pullup revisions 1.44-1.46 (requested by bouyer in ticket #1085)
Use a properly zero'd buffer to pad the packet to
ETHER_MIN_LEN-ETHER_CRC_LEN.
 1.42.10.1 14-Jun-2002  lukem Pull up revision 1.43 (requested by thorpej in ticket #274):
Use M_IFMADDR instead of M_IPMADDR. From John Franklin, kern/16251.
 1.42.8.1 20-Jun-2002  gehenna catch up with -current.
 1.46.2.7 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.46.2.6 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.46.2.5 04-Feb-2005  skrll Sync with HEAD.
 1.46.2.4 02-Nov-2004  skrll Sync with HEAD.
 1.46.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.46.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.46.2.1 03-Aug-2004  skrll Sync with HEAD
 1.48.4.1 24-Jan-2005  he Pull up revision 1.49 (requested by thorpej in ticket #939):
When adding or deleting multicast addresses, only change
the address filter if the interface is marked RUNNING.
Fixes PR#27678.
 1.49.6.2 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.49.6.1 12-Feb-2005  yamt sync with head.
 1.49.4.1 29-Apr-2005  kent sync with -current
 1.52.2.4 27-Oct-2007  yamt sync with head.
 1.52.2.3 03-Sep-2007  yamt sync with head.
 1.52.2.2 30-Dec-2006  yamt sync with head.
 1.52.2.1 21-Jun-2006  yamt sync with head.
 1.55.22.2 10-Dec-2006  yamt sync with head.
 1.55.22.1 22-Oct-2006  yamt sync with head
 1.55.20.1 18-Nov-2006  ad Sync with head.
 1.57.4.1 12-Mar-2007  rmind Sync with HEAD.
 1.58.14.2 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.58.14.1 03-Sep-2007  jmcneill Sync with HEAD.
 1.58.10.1 03-Sep-2007  skrll Sync with HEAD.
 1.58.2.2 23-Oct-2007  ad Sync with head.
 1.58.2.1 09-Oct-2007  ad Sync with head.
 1.59.6.1 25-Oct-2007  bouyer Sync with HEAD.
 1.59.2.1 06-Nov-2007  matt sync with HEAD
 1.60.16.2 17-Jan-2009  mjf Sync with HEAD.
 1.60.16.1 02-Jun-2008  mjf Sync with HEAD.
 1.61.4.4 11-Aug-2010  yamt sync with head.
 1.61.4.3 11-Mar-2010  yamt sync with head
 1.61.4.2 04-May-2009  yamt sync with head.
 1.61.4.1 16-May-2008  yamt sync with head.
 1.61.2.1 18-May-2008  yamt sync with head.
 1.62.8.2 28-Apr-2009  skrll Sync with HEAD.
 1.62.8.1 19-Jan-2009  skrll Sync with HEAD.
 1.62.6.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.64.2.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.67.4.2 12-Jun-2011  rmind sync with head
 1.67.4.1 30-May-2010  rmind sync with head
 1.67.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.68.6.1 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.68.2.1 06-Jun-2011  jruoho Sync with HEAD.
 1.70.30.5 28-Aug-2017  skrll Sync with HEAD
 1.70.30.4 05-Feb-2017  skrll Sync with HEAD
 1.70.30.3 05-Oct-2016  skrll Sync with HEAD
 1.70.30.2 09-Jul-2016  skrll Sync with HEAD
 1.70.30.1 19-Mar-2016  skrll Sync with HEAD
 1.70.12.1 03-Dec-2017  jdolecek update from HEAD
 1.74.2.2 20-Mar-2017  pgoyette Sync with HEAD
 1.74.2.1 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.75.2.1 21-Apr-2017  bouyer Sync with HEAD
 1.76.12.3 06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.76.12.2 28-Jul-2018  pgoyette Sync with HEAD
 1.76.12.1 25-Jun-2018  pgoyette Sync with HEAD
 1.76.6.2 24-Oct-2019  martin Pull up following revision(s) (requested by msaitoh in ticket #1416):

sys/dev/ic/i82586.c: revision 1.86
sys/arch/arm/ep93xx/epe.c: revision 1.45
sys/dev/pcmcia/if_cnw.c: revision 1.66
sys/arch/mac68k/nubus/if_netdock_nubus.c: revision 1.31
sys/dev/qbus/if_il.c: revision 1.36
sys/dev/pcmcia/if_ray.c: revision 1.95
sys/dev/qbus/if_qt.c: revision 1.24

if_percpuq(9) automatically increments if_ipackets, so don't increment it in
the driver itself to prevent double count.
 1.76.6.1 26-Jul-2018  snj Pull up following revision(s) (requested by msaitoh in ticket #938):
sys/arch/acorn32/podulebus/if_ie.c: revision 1.41
sys/arch/amiga/dev/if_es.c: revision 1.58
sys/arch/amiga/dev/if_qn.c: revision 1.45
sys/arch/arm/at91/at91emac.c: revision 1.20
sys/arch/arm/ep93xx/epe.c: revision 1.37
sys/arch/emips/ebus/if_le_ebus.c: revision 1.14
sys/arch/emips/ebus/if_le_ebus.c: revision 1.15
sys/arch/mac68k/dev/if_mc.c: revision 1.46
sys/arch/macppc/dev/am79c950.c: revision 1.39
sys/arch/newsmips/apbus/if_sn.c: revision 1.40
sys/arch/next68k/dev/mb8795.c: revision 1.59
sys/arch/playstation2/dev/if_smap.c: revision 1.25
sys/arch/playstation2/dev/if_smap.c: revision 1.26
sys/arch/sun2/dev/if_ec.c: revision 1.28
sys/arch/sun3/dev/if_ie.c: revision 1.63
sys/arch/x68k/dev/if_ne_intio.c: revision 1.19
sys/arch/xen/xen/if_xennet_xenbus.c: revision 1.75
sys/arch/xen/xen/xennetback_xenbus.c: revision 1.63
sys/dev/bi/if_ni.c: revision 1.45
sys/dev/cadence/if_cemac.c: revision 1.12
sys/dev/ic/am7990.c: revision 1.78
sys/dev/ic/am79900.c: revision 1.27
sys/dev/ic/an.c: revision 1.67
sys/dev/ic/cs89x0.c: revision 1.40
sys/dev/ic/dm9000.c: revision 1.13
sys/dev/ic/dm9000.c: revision 1.14
sys/dev/ic/dp8390.c: revision 1.88
sys/dev/ic/elink3.c: revision 1.141
sys/dev/ic/elinkxl.c: revision 1.122
sys/dev/ic/hme.c: revision 1.98
sys/dev/ic/i82586.c: revision 1.77
sys/dev/ic/lance.c: revision 1.53
sys/dev/ic/mb86950.c: revision 1.27
sys/dev/ic/mb86960.c: revision 1.86
sys/dev/ic/mtd803.c: revision 1.34
sys/dev/ic/pdq_ifsubr.c: revision 1.59
sys/dev/ic/rrunner.c: revision 1.86
sys/dev/ic/seeq8005.c: revision 1.58
sys/dev/ic/sgec.c: revision 1.47
sys/dev/ic/smc90cx6.c: revision 1.72
sys/dev/ic/smc91cxx.c: revision 1.96
sys/dev/ic/tropic.c: revision 1.49
sys/dev/ic/wi.c: revision 1.245
sys/dev/isa/if_eg.c: revision 1.93
sys/dev/isa/if_el.c: revision 1.95
sys/dev/isa/if_iy.c: revision 1.101
sys/dev/ofw/ofnet.c: revision 1.58
sys/dev/pci/if_alc.c: revision 1.27
sys/dev/pci/if_de.c: revision 1.152
sys/dev/pci/if_fpa.c: revision 1.61
sys/dev/pci/if_jme.c: revision 1.34
sys/dev/pci/if_tl.c: revision 1.108
sys/dev/pci/if_vte.c: revision 1.19
sys/dev/pci/ixgbe/ixgbe.h: revision 1.50
sys/dev/pcmcia/if_cnw.c: revision 1.62
sys/dev/pcmcia/if_malo_pcmcia.c: revision 1.17
sys/dev/pcmcia/if_ray.c: revision 1.89
sys/dev/pcmcia/if_xi.c: revision 1.81
sys/dev/pcmcia/mhzc.c: revision 1.51
sys/dev/pcmcia/xirc.c: revision 1.34
sys/dev/qbus/if_de.c: revision 1.33
sys/dev/qbus/if_qe.c: revision 1.78
sys/dev/qbus/if_qt.c: revision 1.22
sys/dev/sbus/be.c: revision 1.87
sys/dev/sbus/qe.c: revision 1.68
sys/dev/scsipi/if_se.c: revision 1.96
sys/dev/usb/if_atu.c: revision 1.59
sys/net/if_l2tp.c: revision 1.28 via patch
sys/net/if_ppp.c: revision 1.160
It's not required to include net/bpfdesc.h. Remove it.
--
Simplify like other drivers. NULL check of ifp->if_bpf is done in
bpf_mtap(), so it's not required to do it here.
--
Remove duplicated inclusion of net/bpf.h.
--
Remove duplicated inclusion of net/bpf.h.
--
Simplify bpf_mtap() call. No functional change.
 1.78.2.3 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.78.2.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.78.2.1 10-Jun-2019  christos Sync with HEAD
 1.85.2.1 23-Oct-2019  martin Pull up following revision(s) (requested by msaitoh in ticket #371):

sys/dev/ic/i82586.c: revision 1.86
sys/arch/arm/ep93xx/epe.c: revision 1.45
sys/dev/pcmcia/if_cnw.c: revision 1.66
sys/arch/mac68k/nubus/if_netdock_nubus.c: revision 1.31
sys/arch/arm/sunxi/sunxi_can.c: revision 1.2
sys/dev/qbus/if_il.c: revision 1.36
sys/dev/pcmcia/if_ray.c: revision 1.95
sys/dev/qbus/if_qt.c: revision 1.24

if_ipackets is incremented in can_input(), so don't increment it in
sunxi_can_rx_intr to prevent double count. OK'd by bouyer@.

if_percpuq(9) automatically increments if_ipackets, so don't increment it in
the driver itself to prevent double count.
 1.87.2.1 29-Feb-2020  ad Sync with head.
 1.6 28-Jun-1995  cgd move to more appropriate (...reg.h) names.
 1.5 04-Apr-1995  mycroft Rename a few constants to match the chip documentation.
 1.4 03-Apr-1995  mycroft Some pseudo-random cleanup, and try to start transmitting packets quicker.
 1.3 23-Jan-1995  mycroft Various changes from Rafal Boni to improve performance and reliability. Also,
clean up the formatting a little more.
 1.2 27-Oct-1994  cgd new RCS ID format.
 1.1 08-Nov-1993  mycroft A slightly unfinished i82586 driver, based on Garrett Wollman's.
 1.13 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.12 04-Mar-2007  christos branches: 1.12.36; 1.12.38; 1.12.40;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.11 11-Dec-2005  christos branches: 1.11.26;
merge ktrace-lwp.
 1.10 27-Feb-2005  perry branches: 1.10.4;
nuke trailing whitespace
 1.9 26-Nov-2001  fredette branches: 1.9.16; 1.9.24; 1.9.26;
Added macros for the bits in the SYSBUS byte, and macros
for the i82596 PORT access interface, from the documentation
for that chip. These help clarify writes to the SYSBUS
part of the SCP, and PORT usage by i82596-aware drivers.
 1.8 10-Mar-2001  jdolecek branches: 1.8.2;
improve description of IE_TDR_OPEN & IE_TDR_SHORT a bit
 1.7 28-Feb-1998  pk branches: 1.7.14; 1.7.26;
Remove `_NEW_I82586' tag; all drivers using this file have been converted.
 1.6 10-Jan-1998  pk * Rename a bunch of chip definitions for consistency.

* Abolish C structures to access chip data-structures; instead use macros
that take indices and offsets relative to the bus handle representing
the chip's resources.

* Include the old version of this file wholesale, until all drivers
have been updated to use the MI 82586 code.
 1.5 04-Apr-1995  mycroft Rename a few constants to match the chip documentation.
 1.4 03-Apr-1995  mycroft Some pseudo-random cleanup, and try to start transmitting packets quicker.
 1.3 23-Jan-1995  mycroft Various changes from Rafal Boni to improve performance and reliability. Also,
clean up the formatting a little more.
 1.2 27-Oct-1994  cgd new RCS ID format.
 1.1 08-Nov-1993  mycroft A slightly unfinished i82586 driver, based on Garrett Wollman's.
 1.7.26.2 08-Jan-2002  nathanw Catch up to -current.
 1.7.26.1 09-Apr-2001  nathanw Catch up with -current.
 1.7.14.1 12-Mar-2001  bouyer Sync with HEAD.
 1.8.2.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.9.26.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.9.24.1 29-Apr-2005  kent sync with -current
 1.9.16.1 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.10.4.1 03-Sep-2007  yamt sync with head.
 1.11.26.1 12-Mar-2007  rmind Sync with HEAD.
 1.12.40.1 16-May-2008  yamt sync with head.
 1.12.38.1 18-May-2008  yamt sync with head.
 1.12.36.1 02-Jun-2008  mjf Sync with HEAD.
 1.24 09-Feb-2024  andvar fix spelling mistakes, mainly in comments and log messages.
 1.23 03-Jun-2011  tsutsui Split device_t/softc of i82586. No crash on TME emulating sun2.
 1.22 28-Apr-2008  martin branches: 1.22.22; 1.22.28; 1.22.32;
Remove clause 3 and 4 from TNF licenses
 1.21 11-Dec-2005  christos branches: 1.21.70; 1.21.72; 1.21.74;
merge ktrace-lwp.
 1.20 30-May-2005  christos - add missing const
- fix variable shadowing
- remove unneeded casts
 1.19 04-Feb-2005  perry de-__P
 1.18 02-Nov-2003  wiz branches: 1.18.8; 1.18.10;
Fix some typos. From Tom Cosgrove via jmc@openbsd.
 1.17 08-Jul-2003  itojun function prototype must not have variable name
 1.16 10-Mar-2001  jdolecek branches: 1.16.22;
add 'why' argument to the channel attention hook function; this argument
is similar to the one passed to hwreset hook function
 1.15 22-Jan-2001  bjh21 branches: 1.15.2;
Patch from PR kern/8001, submitted by Rafal Boni.

This adds support for EtherExpress/16 cards with 16k of RAM, and in the
process adds general support for PIO mode on these cards. This entails
changing the way the i82586 driver handles bus barriers, since it doesn't
allow for strange cases like this.

This has been tested on the i386 port with the 'ix' driver in both
16KB (which was the source of the problem) and 32KB modes, as well
as with the 'ef' driver. I've tested it (briefly) with 'ei' on arm26
as well. In theory, drivers other than 'ix' should follow precisely the
same code paths as before.
 1.14 11-May-2000  bjh21 Fixes from PR 9838:
Only access board memory using the front-end functions.
Add hook for clearing latched interrupts.
Corrent debugging printf of ethertype on LE systems.
Make it possible to us I82586_DEBUG as a kernel option.

Tested on arm26 and mvme68k.
 1.13 09-May-2000  pk Conform bus_dmamem_{alloc,map} usage to bus_dma(9) specs.
 1.12 23-Aug-1999  pk branches: 1.12.2;
Disable inclusion of debugging code by default.
Turn compile-time flag I82586_DEBUG into a boolean switch.
 1.11 25-Mar-1999  thorpej Use ETHER_*_LEN constants from <net/if_ether.h> instead of defining them
ourselves.
 1.10 15-Aug-1998  mycroft Assign my copyrights to TNF.
 1.9 15-Aug-1998  mycroft Make copyright notices with my name consistent.
 1.8 15-Jan-1998  pk Move "async command" state in here.
 1.7 10-Jan-1998  pk * Fix a train-load of bugs, mostly present in one of these categories:
- "out of resource" errors cause receive buffer chain corruption
- resets can confuse the interrupt handler
- multi-cast setup causes receive buffer chain corruption
- shared memory setup incomplete

* Enhance effiency by avoiding unnecessary shared memory access,
improved handling of receive frame & buffer descriptors, and
introducing an `asynchronous' option when issuing 82586 commands.

* Exclusively use offsets relative to the bus handle representing the shared
memory area to formulate accesses to the chip's data-structures. The
front-ends provide glue functions that cater to the chip's endian-
sensitivity, to perform the actual device access (note: single-byte
accesses are done here using `bus_space_{read,write}_1()').
This concludes the transformation into a bus-independent driver module.
 1.6 06-Jan-1998  perry RCSID Police.
 1.5 13-Dec-1997  pk Changes from Rafal Boni to accommodate ISA driver front-ends.
 1.4 01-Aug-1997  pk Add `nop' commands to chain with the `xmit's.
 1.3 29-Jul-1997  pk branches: 1.3.2;
Some more cleanup and synchronization with ISA version.
Also make a start at using bus_* macros (just bus_barrier() for now).
 1.2 28-Jul-1997  pk Bring over assorted changes applied to the ISA ie driver over time.
Fix some inaccuracies in the ring-scan code.
 1.1 22-Jul-1997  pk First cut at a MI i82586 chip driver.
 1.3.2.1 23-Aug-1997  thorpej Update marc-pcmcia branch from trunk.
 1.12.2.3 12-Mar-2001  bouyer Sync with HEAD.
 1.12.2.2 11-Feb-2001  bouyer Sync with HEAD.
 1.12.2.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.15.2.1 09-Apr-2001  nathanw Catch up with -current.
 1.16.22.5 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.16.22.4 04-Feb-2005  skrll Sync with HEAD.
 1.16.22.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.16.22.2 18-Sep-2004  skrll Sync with HEAD.
 1.16.22.1 03-Aug-2004  skrll Sync with HEAD
 1.18.10.1 12-Feb-2005  yamt sync with head.
 1.18.8.1 29-Apr-2005  kent sync with -current
 1.21.74.1 16-May-2008  yamt sync with head.
 1.21.72.1 18-May-2008  yamt sync with head.
 1.21.70.1 02-Jun-2008  mjf Sync with HEAD.
 1.22.32.1 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.22.28.1 06-Jun-2011  jruoho Sync with HEAD.
 1.22.22.1 12-Jun-2011  rmind sync with head
 1.10 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.9 04-Mar-2007  tsutsui branches: 1.9.36; 1.9.38; 1.9.40;
Fix EEPP_INTMAP values, as per my ISA EtherExpress PRO/10.
(though it still has some other problem)
 1.8 11-Dec-2005  christos branches: 1.8.26;
merge ktrace-lwp.
 1.7 27-Feb-2005  perry branches: 1.7.4;
nuke trailing whitespace
 1.6 06-Jan-2003  wiz branches: 1.6.2; 1.6.10; 1.6.12;
interrupt with two rs.
 1.5 16-Mar-2001  is Don't need to use the hash filter for a single individual address; make
sure concurrent receive processing is disabled.
 1.4 16-Feb-1999  is branches: 1.4.8; 1.4.20;
Fix Copyright dates
 1.3 16-Feb-1999  is Assign my files to The NetBSD Foundation, Inc.
 1.2 28-Jul-1998  is Add some constants.
 1.1 06-May-1996  is Add "iy" driver for Ethernet ISA boards using the Intel i82595 chip, e.g.
(and only tested on) Intel Etherexpress PRO. Should work on any i82595 ISA
board which uses an EEPROM for config information; NETBLKID not yet supported.
TODO: change to BUS interface, add multicast support.
 1.4.20.2 07-Jan-2003  thorpej Sync with HEAD.
 1.4.20.1 09-Apr-2001  nathanw Catch up with -current.
 1.4.8.1 27-Mar-2001  bouyer Sync with HEAD.
 1.6.12.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.6.10.1 29-Apr-2005  kent sync with -current
 1.6.2.1 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.7.4.1 03-Sep-2007  yamt sync with head.
 1.8.26.1 12-Mar-2007  rmind Sync with HEAD.
 1.9.40.1 16-May-2008  yamt sync with head.
 1.9.38.1 18-May-2008  yamt sync with head.
 1.9.36.1 02-Jun-2008  mjf Sync with HEAD.
 1.48 05-Jul-2024  rin sys: Drop redundant NULL check before m_freem(9)

m_freem(9) safely has accepted NULL argument at least since 4.2BSD:
https://www.tuhs.org/cgi-bin/utree.pl?file=4.2BSD/usr/src/sys/sys/uipc_mbuf.c

Compile-tested on amd64/ALL.

Suggested by knakahara@
 1.47 06-Jul-2022  andvar branches: 1.47.10;
s/ponters/pointers/
 1.46 29-May-2022  rin Audit unload/unmap v.s. free against DMA buffer for sys/dev;
make sure that bus_dmamap_unload(9) [or bus_dmamap_destroy(9)] or
bus_dmamem_unmap(9) are preceding to freeing DMA buffer, if it is
loaded or mapped, respectively.

This is mandatory for some archs. See, e.g.:

http://www.nerv.org/netbsd/?q=id:20210511T013030Z.013443cc790088147e4beed43f53dedabeaf9312
http://www.nerv.org/netbsd/?q=id:20220511T172220Z.561179f0b6fcc5b9cd73e274f69d74e2ce9e4c93

For some drivers, resource leaks for error paths are fixed at
the same time.

XXX XXX XXX
Compile test only (at least one arch per driver).
 1.45 10-Nov-2021  msaitoh s/endianess/endianness/
 1.44 04-Feb-2020  thorpej Use ifmedia_fini().
 1.43 29-Jan-2020  thorpej Adopt <net/if_stats.h>.
 1.42 29-May-2019  msaitoh branches: 1.42.4;
Even if we don't use MII(4), use the common path of SIOC[GS]IFMEDIA in
sys/net/if_ethersubr.c if we can.
- Add ec_ifmedia into struct ethercom.
- ec_mii in struct ethercom is kept and used as it is. It might be used in
future. Note that some Ethernet drivers which _DOESN'T_ use mii(4) use
ec_mii for keeping the if_media. Those should be changed in future.
 1.41 28-May-2019  msaitoh Use ETHER_LOCK()/ETHER_UNLOCK() for all ethernet drivers to protect ec_multi*.
 1.40 26-Apr-2019  msaitoh No functional change:
- u_int_{8,16,32}_t -> uint_{8,16,32}_t
- KNF.
- Tabify.
- Remove extra space.
 1.39 09-Apr-2019  msaitoh KNF. No functional change.
 1.38 26-Jun-2018  msaitoh branches: 1.38.2;
Implement the BPF direction filter (BIOC[GS]DIRECTION). It provides backward
compatibility with BIOC[GS]SEESENT ioctl. The userland interface is the same
as FreeBSD.

This change also fixes a bug that the direction is misunderstand on some
environment by passing the direction to bpf_mtap*() instead of checking
m->m_pkthdr.rcvif.
 1.37 29-Jul-2017  riastradh branches: 1.37.2;
Null out sc_rx_mbuf[i] after m_freem to avoid double-free later.

From Ilja Van Sprundel.

Also null out sc_tx_mbuf[i] after m_freem, out of paranoia.

XXX Not entirely clear to how tx mbufs are freed, but no way to test
this since it's ews4800mips- and hp700-only, so not keen to make any
more elaborate changes...
 1.36 20-Feb-2017  ozaki-r branches: 1.36.6;
Apply deferred if_start to more drivers
 1.35 15-Dec-2016  ozaki-r branches: 1.35.2;
Move bpf_mtap and if_ipackets++ on Rx of each driver to percpuq if_input

The benefits of the change are:
- We can reduce codes
- We can provide the same behavior between drivers
- Where/When if_ipackets is counted up
- Note that some drivers still update packet statistics in their own
way (periodical update)
- Moved bpf_mtap run in softint
- This makes it easy to MP-ify bpf

Proposed on tech-kern and tech-net
 1.34 10-Jun-2016  ozaki-r branches: 1.34.2;
Introduce m_set_rcvif and m_reset_rcvif

The API is used to set (or reset) a received interface of a mbuf.
They are counterpart of m_get_rcvif, which will come in another
commit, hide internal of rcvif operation, and reduce the diff of
the upcoming change.

No functional change.
 1.33 09-Feb-2016  ozaki-r Introduce softint-based if_input

This change intends to run the whole network stack in softint context
(or normal LWP), not hardware interrupt context. Note that the work is
still incomplete by this change; to that end, we also have to softint-ify
if_link_state_change (and bpf) which can still run in hardware interrupt.

This change softint-ifies at ifp->if_input that is called from
each device driver (and ieee80211_input) to ensure Layer 2 runs
in softint (e.g., ether_input and bridge_input). To this end,
we provide a framework (called percpuq) that utlizes softint(9)
and percpu ifqueues. With this patch, rxintr of most drivers just
queues received packets and schedules a softint, and the softint
dequeues packets and does rest packet processing.

To minimize changes to each driver, percpuq is allocated in struct
ifnet for now and that is initialized by default (in if_attach).
We probably have to move percpuq to softc of each driver, but it's
future work. At this point, only wm(4) has percpuq in its softc
as a reference implementation.

Additional information including performance numbers can be found
in the thread at tech-kern@ and tech-net@:
http://mail-index.netbsd.org/tech-kern/2016/01/14/msg019997.html

Acknowledgment: riastradh@ greatly helped this work.
Thank you very much!
 1.32 21-Feb-2015  martin Fix multicast handling (and while there a bogus memcpy).
Fixes PR kern/49472, patch from Nick Hudson.
 1.31 24-Feb-2014  skrll branches: 1.31.4; 1.31.6;
Rename NetBSD/hp700 to NetBSD/hppa.

Unfortunately our VCS isn't very helpful here.
 1.30 09-Dec-2013  wiz Fix typo ("then" instead of "than")
 1.29 05-Apr-2010  joerg branches: 1.29.8; 1.29.14; 1.29.18; 1.29.20; 1.29.22; 1.29.28;
Push the bpf_ops usage back into bpf.h. Push the common ifp->if_bpf
check into the inline functions as well the fourth argument for
bpf_attach.
 1.28 19-Jan-2010  pooka branches: 1.28.2; 1.28.4;
Redefine bpf linkage through an always present op vector, i.e.
#if NBPFILTER is no longer required in the client. This change
doesn't yet add support for loading bpf as a module, since drivers
can register before bpf is attached. However, callers of bpf can
now be modularized.

Dynamically loadable bpf could probably be done fairly easily with
coordination from the stub driver and the real driver by registering
attachments in the stub before the real driver is loaded and doing
a handoff. ... and I'm not going to ponder the depths of unload
here.

Tested with i386/MONOLITHIC, modified MONOLITHIC without bpf and rump.
 1.27 13-May-2009  tsutsui Pass correct size (after padding) to bus_dmamap_sync(9) for RX mbufs
in iee_intr(). Fixes panic on DIAGNOSTIC kernel reported by skrll@.
 1.26 10-May-2009  tsutsui - adjust comments for the previous change
- wrap a long comment
- remove a trailing whitespace
 1.25 10-May-2009  tsutsui Misc bus_dma(9) related cleanup:
- calculate each descriptor sizes and offsets in iee_attach() and store them
into softc, rather than re-calculating them everywhere via macros
- prepare macros to sync DMA shmem per each descriptor
- sync only necessary descriptors in iee_intr() and iee_start()
- make sure SCB_FOO macros take softc as an arg properly
- use bus_dmamap_load_mbuf(9) for RX mbufs
- put 2 byte alignments to RX mbufs

XXX: still slower than ie(4) in i82586 compat mode on HP9000 735/125.
 1.24 09-May-2009  tsutsui Fix more pasto botch.
 1.23 09-May-2009  tsutsui Remove (wrong) function names by pasto from attach failure messages.
 1.22 09-May-2009  tsutsui Also check if cache line alignment is power of two in KASSERT().
 1.21 09-May-2009  tsutsui Move allocation of DMA shared memory with bus_dma(9) ops
from MD attachments to MI iee_attach().
Tested on HP9000 735/125. Compile test only on ews4800mips.

XXX: more strict bus_dmamap_sync(9) calls are required in various places.
 1.20 05-May-2009  tsutsui Add support for i82596 Rev A chip which doesn't have the enhanced 32 bit
big endian mode:
- add IEE_REV_A flag to indicate if chip support the 32 bit BE mode or not
- add IEE_SWAPA32() macro and use it on necessary 32 bit DMA pointers
- rename IEE_SWAP() macro for the SCP address pointer and statistics
counters which require word swap even on Rev B/C chips to IEE_SWAP32()
for clarification
- add comments about these BE mode quirks

Tested on HP9000 735/125 by me and also tested on 715/50 by skrll@
with netbsd-5 branch, and fixes MI part of PR port-hp700/35531.
 1.19 04-Apr-2008  tsutsui branches: 1.19.4; 1.19.18;
Split device_t/softc for iee(4), with misc cosmetic changes.
 1.18 19-Oct-2007  ad branches: 1.18.16;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.17 26-Aug-2007  dyoung branches: 1.17.2; 1.17.6;
Constify: LLADDR -> CLLADDR. I'm aiming here to make it easier to
identify sockaddr_dl abuse that remains in the kernel, especially
the potential for overwriting memory past the end of a sockaddr_dl
with, e.g., memcpy(LLADDR(), ...).
 1.16 17-Apr-2007  skrll branches: 1.16.2; 1.16.6;
Remove bogus if_drain. If an attempt to reclaim mbufs was made the
interface was marked down.

Should fix PR 31540.
 1.15 04-Mar-2007  christos branches: 1.15.2; 1.15.4;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.14 12-Jul-2006  skrll branches: 1.14.8; 1.14.10;
Note this driver is for the i82596CA and i82596DX/SX chips and provide
links to documentation on developers.intel.com
 1.13 08-Jul-2006  skrll KNF some comments and whitespace.
 1.12 08-Jul-2006  skrll Spelling in comments. No functional change.
 1.11 11-Dec-2005  christos branches: 1.11.4; 1.11.8; 1.11.16;
merge ktrace-lwp.
 1.10 07-Jun-2005  skrll branches: 1.10.2;
Fix typo.
 1.9 02-Jun-2005  he Adapt to -Wcast-qual by adding a const and using __UNVOLATILE() in
a couple of places where memcpy() is used.
 1.8 27-Feb-2005  perry nuke trailing whitespace
 1.7 18-Feb-2005  tsutsui u_intNN_t -> uintNN_t
 1.6 17-Feb-2005  tsutsui Account ifp->if_opackets and ifp->if_collisions.
 1.5 17-Feb-2005  tsutsui Remove unneeded includes.
 1.4 30-Oct-2004  thorpej branches: 1.4.4; 1.4.6;
iee_ioctl(): Make this look like other drivers, fixing a missing "splx(s)"
as a side-effect. Don't bother handling IFF_PROMISC here, because
ether_ioctl() already calls (*if_init)() to handle flags changes.

When adding/deleting multicast addresses, only whack the address
filter if the interface is marked RUNNING.

Fixes kern/27678.
 1.3 30-Oct-2004  thorpej When adding/deleting multicast addresses, only whack the address
filter if the interface is marked RUNNING.

Fixes kern/27678.
 1.2 26-Aug-2004  jkunz Remove race conditions caused by the CPU cache of PA7100 CPUs.
 1.1 12-Mar-2004  jkunz branches: 1.1.4; 1.1.6;
Import MI part of new Intel i82596 Ethernet driver.
 1.1.6.2 30-Jan-2005  he Pull up revision 1.4 (requested by thorpej in ticket #943):
Make iee_ioctl() look more like other drivers, and fix a
missing splx(s) as a side-effect. Don't bother handling
IFF_PROMISC here, because ether_ioctl() already calls
(*if_init)() to handle flag changes.
When adding or deleting multicast addresses, only change
the address filter if the interface is marked RUNNING.
Fixes PR#27678.
 1.1.6.1 24-Jan-2005  he Pull up revision 1.3 (requested by thorpej in ticket #939):
When adding or deleting multicast addresses, only change
the address filter if the interface is marked RUNNING.
Fixes PR#27678.
 1.1.4.8 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.1.4.7 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.1.4.6 02-Nov-2004  skrll Sync with HEAD.
 1.1.4.5 21-Sep-2004  skrll Fix the sync with head I botched.
 1.1.4.4 18-Sep-2004  skrll Sync with HEAD.
 1.1.4.3 03-Sep-2004  skrll Sync with HEAD
 1.1.4.2 03-Aug-2004  skrll Sync with HEAD
 1.1.4.1 12-Mar-2004  skrll file i82596.c was added on branch ktrace-lwp on 2004-08-03 10:46:15 +0000
 1.4.6.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.4.4.1 29-Apr-2005  kent sync with -current
 1.10.2.3 27-Oct-2007  yamt sync with head.
 1.10.2.2 03-Sep-2007  yamt sync with head.
 1.10.2.1 30-Dec-2006  yamt sync with head.
 1.11.16.1 13-Jul-2006  gdamore Merge from HEAD.
 1.11.8.1 11-Aug-2006  yamt sync with head
 1.11.4.1 09-Sep-2006  rpaulo sync with head
 1.14.10.2 07-May-2007  yamt sync with head.
 1.14.10.1 12-Mar-2007  rmind Sync with HEAD.
 1.14.8.1 20-Apr-2007  bouyer Pull up following revision(s) (requested by skrll in ticket #580):
sys/dev/ic/i82596.c: revision 1.16
Remove bogus if_drain. If an attempt to reclaim mbufs was made the
interface was marked down. Should fix PR 31540.
 1.15.4.1 11-Jul-2007  mjf Sync with head.
 1.15.2.3 23-Oct-2007  ad Sync with head.
 1.15.2.2 09-Oct-2007  ad Sync with head.
 1.15.2.1 27-May-2007  ad Sync with head.
 1.16.6.2 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.16.6.1 03-Sep-2007  jmcneill Sync with HEAD.
 1.16.2.1 03-Sep-2007  skrll Sync with HEAD.
 1.17.6.1 25-Oct-2007  bouyer Sync with HEAD.
 1.17.2.1 06-Nov-2007  matt sync with HEAD
 1.18.16.1 02-Jun-2008  mjf Sync with HEAD.
 1.19.18.2 23-Jul-2009  jym Sync with HEAD.
 1.19.18.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.19.4.3 11-Aug-2010  yamt sync with head.
 1.19.4.2 11-Mar-2010  yamt sync with head
 1.19.4.1 16-May-2009  yamt sync with head
 1.28.4.1 30-May-2010  rmind sync with head
 1.28.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.29.28.1 18-Aug-2017  snj Pull up following revision(s) (requested by mrg in ticket #1475):
sys/dev/ic/i82596.c: revision 1.37
Null out sc_rx_mbuf[i] after m_freem to avoid double-free later.
From Ilja Van Sprundel.
Also null out sc_tx_mbuf[i] after m_freem, out of paranoia.
XXX Not entirely clear to how tx mbufs are freed, but no way to test
this since it's ews4800mips- and hp700-only, so not keen to make any
more elaborate changes...
 1.29.22.1 18-May-2014  rmind sync with head
 1.29.20.1 18-Aug-2017  snj Pull up following revision(s) (requested by mrg in ticket #1475):
sys/dev/ic/i82596.c: revision 1.37
Null out sc_rx_mbuf[i] after m_freem to avoid double-free later.
From Ilja Van Sprundel.
Also null out sc_tx_mbuf[i] after m_freem, out of paranoia.
XXX Not entirely clear to how tx mbufs are freed, but no way to test
this since it's ews4800mips- and hp700-only, so not keen to make any
more elaborate changes...
 1.29.18.2 03-Dec-2017  jdolecek update from HEAD
 1.29.18.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.29.14.1 18-Aug-2017  snj Pull up following revision(s) (requested by mrg in ticket #1475):
sys/dev/ic/i82596.c: revision 1.37
Null out sc_rx_mbuf[i] after m_freem to avoid double-free later.
From Ilja Van Sprundel.
Also null out sc_tx_mbuf[i] after m_freem, out of paranoia.
XXX Not entirely clear to how tx mbufs are freed, but no way to test
this since it's ews4800mips- and hp700-only, so not keen to make any
more elaborate changes...
 1.29.8.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.31.6.5 28-Aug-2017  skrll Sync with HEAD
 1.31.6.4 05-Feb-2017  skrll Sync with HEAD
 1.31.6.3 09-Jul-2016  skrll Sync with HEAD
 1.31.6.2 19-Mar-2016  skrll Sync with HEAD
 1.31.6.1 06-Apr-2015  skrll Sync with HEAD
 1.31.4.2 12-Aug-2017  snj Pull up following revision(s) (requested by mrg in ticket #1471):
sys/dev/ic/i82596.c: revision 1.37
Null out sc_rx_mbuf[i] after m_freem to avoid double-free later.
From Ilja Van Sprundel.
Also null out sc_tx_mbuf[i] after m_freem, out of paranoia.
XXX Not entirely clear to how tx mbufs are freed, but no way to test
this since it's ews4800mips- and hp700-only, so not keen to make any
more elaborate changes...
 1.31.4.1 21-Feb-2015  martin branches: 1.31.4.1.2; 1.31.4.1.6;
Pull up following revision(s) (requested by skrll in ticket #540):
sys/dev/ic/i82596.c: revision 1.32
Fix multicast handling.
Fixes PR kern/49472, patch from Nick Hudson.
 1.31.4.1.6.1 12-Aug-2017  snj Pull up following revision(s) (requested by mrg in ticket #1471):
sys/dev/ic/i82596.c: revision 1.37
Null out sc_rx_mbuf[i] after m_freem to avoid double-free later.
From Ilja Van Sprundel.
Also null out sc_tx_mbuf[i] after m_freem, out of paranoia.
XXX Not entirely clear to how tx mbufs are freed, but no way to test
this since it's ews4800mips- and hp700-only, so not keen to make any
more elaborate changes...
 1.31.4.1.2.1 12-Aug-2017  snj Pull up following revision(s) (requested by mrg in ticket #1471):
sys/dev/ic/i82596.c: revision 1.37
Null out sc_rx_mbuf[i] after m_freem to avoid double-free later.
From Ilja Van Sprundel.
Also null out sc_tx_mbuf[i] after m_freem, out of paranoia.
XXX Not entirely clear to how tx mbufs are freed, but no way to test
this since it's ews4800mips- and hp700-only, so not keen to make any
more elaborate changes...
 1.34.2.2 20-Mar-2017  pgoyette Sync with HEAD
 1.34.2.1 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.35.2.1 21-Apr-2017  bouyer Sync with HEAD
 1.36.6.1 05-Aug-2017  snj Pull up following revision(s) (requested by spz in ticket #184):
sys/dev/ic/i82596.c: revision 1.37
Null out sc_rx_mbuf[i] after m_freem to avoid double-free later.
From Ilja Van Sprundel.
Also null out sc_tx_mbuf[i] after m_freem, out of paranoia.
XXX Not entirely clear to how tx mbufs are freed, but no way to test
this since it's ews4800mips- and hp700-only, so not keen to make any
more elaborate changes...
 1.37.2.1 28-Jul-2018  pgoyette Sync with HEAD
 1.38.2.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.38.2.1 10-Jun-2019  christos Sync with HEAD
 1.42.4.1 29-Feb-2020  ad Sync with head.
 1.47.10.1 02-Aug-2025  perseant Sync with HEAD
 1.4 05-Apr-2008  skrll Typo in comment.
 1.3 08-Jul-2006  skrll branches: 1.3.54;
Spelling in comments. No functional change.
 1.2 11-Dec-2005  christos branches: 1.2.4; 1.2.8; 1.2.16;
merge ktrace-lwp.
 1.1 12-Mar-2004  jkunz branches: 1.1.4; 1.1.18;
Import MI part of new Intel i82596 Ethernet driver.
 1.1.18.1 30-Dec-2006  yamt sync with head.
 1.1.4.4 21-Sep-2004  skrll Fix the sync with head I botched.
 1.1.4.3 18-Sep-2004  skrll Sync with HEAD.
 1.1.4.2 03-Aug-2004  skrll Sync with HEAD
 1.1.4.1 12-Mar-2004  skrll file i82596reg.h was added on branch ktrace-lwp on 2004-08-03 10:46:15 +0000
 1.2.16.1 13-Jul-2006  gdamore Merge from HEAD.
 1.2.8.1 11-Aug-2006  yamt sync with head
 1.2.4.1 09-Sep-2006  rpaulo sync with head
 1.3.54.1 02-Jun-2008  mjf Sync with HEAD.
 1.16 26-Feb-2025  andvar s/Cont/Count/ in comment.
 1.15 01-Dec-2009  skrll branches: 1.15.102;
Spell busy correctly.
 1.14 10-May-2009  tsutsui Misc bus_dma(9) related cleanup:
- calculate each descriptor sizes and offsets in iee_attach() and store them
into softc, rather than re-calculating them everywhere via macros
- prepare macros to sync DMA shmem per each descriptor
- sync only necessary descriptors in iee_intr() and iee_start()
- make sure SCB_FOO macros take softc as an arg properly
- use bus_dmamap_load_mbuf(9) for RX mbufs
- put 2 byte alignments to RX mbufs

XXX: still slower than ie(4) in i82586 compat mode on HP9000 735/125.
 1.13 09-May-2009  tsutsui Use roundup2() macro to calculate cache line aligned offsets of
DMA descriptor members in shared memory.
The previous ones could return wrong values if cache line size is
smaller than structures, and we can assume cache line size is
power of two to avoid division ops.
 1.12 09-May-2009  tsutsui Move allocation of DMA shared memory with bus_dma(9) ops
from MD attachments to MI iee_attach().
Tested on HP9000 735/125. Compile test only on ews4800mips.

XXX: more strict bus_dmamap_sync(9) calls are required in various places.
 1.11 05-May-2009  tsutsui Add support for i82596 Rev A chip which doesn't have the enhanced 32 bit
big endian mode:
- add IEE_REV_A flag to indicate if chip support the 32 bit BE mode or not
- add IEE_SWAPA32() macro and use it on necessary 32 bit DMA pointers
- rename IEE_SWAP() macro for the SCP address pointer and statistics
counters which require word swap even on Rev B/C chips to IEE_SWAP32()
for clarification
- add comments about these BE mode quirks

Tested on HP9000 735/125 by me and also tested on 715/50 by skrll@
with netbsd-5 branch, and fixes MI part of PR port-hp700/35531.
 1.10 04-Apr-2008  tsutsui branches: 1.10.4; 1.10.18;
Split device_t/softc for iee(4), with misc cosmetic changes.
 1.9 25-Dec-2007  perry branches: 1.9.6;
Convert many of the uses of __attribute__ to equivalent
__packed, __unused and __dead macros from cdefs.h
 1.8 04-Mar-2007  tsutsui branches: 1.8.16; 1.8.22; 1.8.24; 1.8.28;
Use (uint8_t *) for shared memory address.
 1.7 04-Mar-2007  christos Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.6 08-Jul-2006  skrll branches: 1.6.10;
Spelling in comments. No functional change.
 1.5 11-Dec-2005  christos branches: 1.5.4; 1.5.8; 1.5.16;
merge ktrace-lwp.
 1.4 03-Jun-2005  skrll branches: 1.4.2;
const fallout.
 1.3 18-Feb-2005  tsutsui u_intNN_t -> uintNN_t
 1.2 17-Feb-2005  tsutsui Add __attribute__((__packed__)) to structure declarations of DMA descriptors.
Checked on 712/60. (hmm, I wonder how does it work before...)
 1.1 12-Mar-2004  jkunz branches: 1.1.4; 1.1.10; 1.1.12;
Import MI part of new Intel i82596 Ethernet driver.
 1.1.12.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.1.10.1 29-Apr-2005  kent sync with -current
 1.1.4.6 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.1.4.5 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.1.4.4 21-Sep-2004  skrll Fix the sync with head I botched.
 1.1.4.3 18-Sep-2004  skrll Sync with HEAD.
 1.1.4.2 03-Aug-2004  skrll Sync with HEAD
 1.1.4.1 12-Mar-2004  skrll file i82596var.h was added on branch ktrace-lwp on 2004-08-03 10:46:15 +0000
 1.4.2.3 21-Jan-2008  yamt sync with head
 1.4.2.2 03-Sep-2007  yamt sync with head.
 1.4.2.1 30-Dec-2006  yamt sync with head.
 1.5.16.1 13-Jul-2006  gdamore Merge from HEAD.
 1.5.8.1 11-Aug-2006  yamt sync with head
 1.5.4.1 09-Sep-2006  rpaulo sync with head
 1.6.10.1 12-Mar-2007  rmind Sync with HEAD.
 1.8.28.1 02-Jan-2008  bouyer Sync with HEAD
 1.8.24.1 26-Dec-2007  ad Sync with head.
 1.8.22.1 18-Feb-2008  mjf Sync with HEAD.
 1.8.16.1 09-Jan-2008  matt sync with HEAD
 1.9.6.1 02-Jun-2008  mjf Sync with HEAD.
 1.10.18.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.10.4.2 11-Mar-2010  yamt sync with head
 1.10.4.1 16-May-2009  yamt sync with head
 1.15.102.1 02-Aug-2025  perseant Sync with HEAD
 1.6 05-Dec-2024  andvar s/followied/followed/ in comment.
 1.5 09-Feb-2024  andvar branches: 1.5.2;
fix spelling mistakes, mainly in comments and log messages.
 1.4 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.3 12-May-2006  tsutsui branches: 1.3.58; 1.3.60; 1.3.62;
According to the i8259 manual, EOI, R, and SL bits belong to OCW2 register
so rename them OCW3_* -> OCW2_*.
 1.2 21-Jun-2001  thorpej branches: 1.2.4; 1.2.40; 1.2.54; 1.2.56; 1.2.58; 1.2.62;
Update, based on i8259a manual.
 1.1 21-Jun-2001  thorpej Add a long-needed register descripton file for the i8259 PIC.

This was taken from the PIIX4 manual, and thus doesn't have all
the legacy crap (relative to "modern" ISA PICs, anyway), so if
you have a real i8259 manual, fill in some more bits.
 1.2.62.1 24-May-2006  tron Merge 2006-05-24 NetBSD-current into the "peter-altq" branch.
 1.2.58.1 24-May-2006  yamt sync with head.
 1.2.56.1 01-Jun-2006  kardel Sync with head.
 1.2.54.1 09-Sep-2006  rpaulo sync with head
 1.2.40.1 21-Jun-2006  yamt sync with head.
 1.2.4.2 24-Aug-2001  nathanw Catch up with -current.
 1.2.4.1 21-Jun-2001  nathanw file i8259reg.h was added on branch nathanw_sa on 2001-08-24 00:09:25 +0000
 1.3.62.1 16-May-2008  yamt sync with head.
 1.3.60.1 18-May-2008  yamt sync with head.
 1.3.58.1 02-Jun-2008  mjf Sync with HEAD.
 1.5.2.1 02-Aug-2025  perseant Sync with HEAD
 1.17 12-Apr-2023  riastradh ichsmb(4), tco(4): Add support for TCO on newer Intel chipsets.

TCO (`Total Cost of Ownership', Intel's bizarre name for a watchdog
timer) used to hang off the Intel I/O platform controller hub's (ICH)
low-pin-count interface bridge (LPC IB), or ichlpcib(4). On newer
devices, it hangs off the ICH SMBus instead.

Tested on INTEL 100SERIES_SMB (works) and INTEL 100SERIES_LP_SMB
(doesn't work, still not sure why).

XXX kernel revbump: This breaks the module ABI -- tco(4) modules
older than the change to make ta_has_rcba into ta_version will
incorrectly attach at buses they do not understand. (However, the
tco(4) driver is statically built into GENERIC, so maybe it's safe
for pullup since the module wouldn't have worked anyway.)
 1.16 22-Sep-2022  riastradh branches: 1.16.4;
ichsmb(4): Remove confusing `lpcib_' prefix on register names.
 1.15 22-Sep-2022  riastradh tco(4): Nix PMC_TCO_BASE offset in TCO register definitions.

This just uses a subregion with PMC_TCO_BASE automatically applied.

No functional change intended.
 1.14 22-Sep-2022  riastradh tco(4): Use a subregion of the PMC registers for TCO registers.

This is an intermediate step that will let us decouple it from access
via PMBASE.
 1.13 22-Sep-2022  riastradh ichlpcib(4), tco(4): Take `lpcib_' off various names.

For PMC-specific ones, change `lpcib_' to `pmc_'. These are in a
separate PCI device in newer chipsets.

For TCO-specific ones, which may live in different places, whether at
their own base address or as an offset from PMBASE, just leave it as
`tco_' or `tcotimer'.

No functional change intended.
 1.12 26-Dec-2014  msaitoh Fix a bug that ichlpcib(4) maps I/O area incorrectly and then fails to attach
gpio. It might also fix ACPI related problem described in PR#48960:
- The LPCIB_PCI_PMBASE and LPCIB_PCI_GPIO register are alike PCI BAR but not
completely compatible with it. It's ok because the registers' addresses are
out of BAR0-BAR5(0x10-0x24) and are located in the device-dependent header.
The PMBASE and GPIO registers define the base address and the type but not
describe the size. The size is fixed to 128bytes. So use
pci_mapreg_submap().
- Make pci_mapreg_submap() extern again.
- Fix the calculation of the map size in pci_mapreg_submap().
 1.11 23-Jul-2010  jakllsch branches: 1.11.14; 1.11.18; 1.11.34; 1.11.36;
Finish cleaning up pchb from recent change.
Use fewer magic numbers in ichlpcib.
Slightly improve style conformance.
Update paths in cpp re-inclusion guards.
 1.10 27-Sep-2009  jakllsch branches: 1.10.2; 1.10.4;
gpio(4) support for Intel ICH southbridges.

Tested on Intel SS4200-E (ICH7), and Acorp 6A815EPD (ICH2) motherboards,
on amd64 and i386 ports respectively.

It should be noted that the majority of boards with ICH chips do not
expose the GPIO pins for off-board use. For instance, aside from the
three exposed-on-a-header pins on the 6A815EPD, another pin is also
used to control write protect on the FWH. The SS4200 exposes the GPIO
on a header that connects to the 10 LEDs on the front panel, as well
as a tact switch on the back panel.
 1.9 21-Sep-2009  jakllsch Add more-complete definitions of ICH GPIO-related registers.
While here, fix a typo in a register number.
 1.8 28-Apr-2008  martin branches: 1.8.10;
Remove clause 3 and 4 from TNF licenses
 1.7 09-Dec-2007  jmcneill branches: 1.7.10; 1.7.12; 1.7.14;
Merge jmcneill-pm branch.
 1.6 26-Aug-2007  xtraeme branches: 1.6.2; 1.6.10; 1.6.12;
Move the ICH SMB defs to dev/ic/i82801lpcreg.h, it's where it belongs.
This is to avoid code duplication.
 1.5 26-Aug-2007  xtraeme Some changes for the ichlpcib driver:

- Moved to x86/pci, so that EM64T systems running NetBSD/amd64 can use it.
- Added support for the TCO on ICH6 or newer chipsets, adapted from
FreeBSD.
- Added timecounter support for the power management timer, adapted from
OpenBSD.
- Plus some misc/cosmetic changes.

Thanks to yukonbob on irc@freenode for testing the TCO part on ICH4-M.
Tested by me with ICH7 too.
 1.4 16-Feb-2006  perry branches: 1.4.24; 1.4.34; 1.4.38;
Change "inline" back to "__inline" in .h files -- C99 is still too
new, and some apps compile things in C89 mode. C89 keywords stay.

As per core@.
 1.3 11-Dec-2005  christos branches: 1.3.2; 1.3.4; 1.3.6;
merge ktrace-lwp.
 1.2 31-Jul-2004  mrg branches: 1.2.2; 1.2.14;
add several definitions useful for ICH-based speedstep.
(from linux and freebsd.)
 1.1 14-Mar-2004  minoura Add Intel ICHn PCI-LPC bridge driver.
It is a pcib, but with sysmon watchdog support.
 1.2.14.3 21-Jan-2008  yamt sync with head
 1.2.14.2 03-Sep-2007  yamt sync with head.
 1.2.14.1 21-Jun-2006  yamt sync with head.
 1.2.2.4 21-Sep-2004  skrll Fix the sync with head I botched.
 1.2.2.3 18-Sep-2004  skrll Sync with HEAD.
 1.2.2.2 03-Aug-2004  skrll Sync with HEAD
 1.2.2.1 31-Jul-2004  skrll file i82801lpcreg.h was added on branch ktrace-lwp on 2004-08-03 10:46:15 +0000
 1.3.6.1 22-Apr-2006  simonb Sync with head.
 1.3.4.1 09-Sep-2006  rpaulo sync with head
 1.3.2.1 18-Feb-2006  yamt sync with head.
 1.4.38.2 04-Sep-2007  joerg Don't use a global variable to decide whether this is a ICH6+,
use a variable in the softc to determine whether the RCBA is supported.
Add generic HPET support for ICH5 and ICH6+.

This is not (yet) enabled by default, until someone adds the code to
not use the direct attachment if hpet was configured via ACPI.
 1.4.38.1 03-Sep-2007  jmcneill Sync with HEAD.
 1.4.34.1 03-Sep-2007  skrll Sync with HEAD.
 1.4.24.1 09-Oct-2007  ad Sync with head.
 1.6.12.1 11-Dec-2007  yamt sync with head.
 1.6.10.1 26-Dec-2007  ad Sync with head.
 1.6.2.1 09-Jan-2008  matt sync with HEAD
 1.7.14.3 11-Aug-2010  yamt sync with head.
 1.7.14.2 11-Mar-2010  yamt sync with head
 1.7.14.1 16-May-2008  yamt sync with head.
 1.7.12.1 18-May-2008  yamt sync with head.
 1.7.10.1 02-Jun-2008  mjf Sync with HEAD.
 1.8.10.1 23-Jan-2015  martin Pull up the following changes, requested by msaitoh in ticket #1942:

sys/arch/x86/pci/ichlpcib.c 1.40, 1.45 via patch
sys/dev/ic/i82801lpcreg.h 1.12
sys/dev/pci/pci_map.c 1.32 via patch

- Fix a bug that ichlpcib(4) maps I/O area incorrectly. It might also
fixes ACPI related problem described in PR#48960:
- The LPCIB_PCI_PMBASE and LPCIB_PCI_GPIO register are alike PCI BAR
but not completely compatible with it. It's ok because the
registers' addresses are out of BAR0-BAR5(0x10-0x24) and are
located in the device-dependent header. The PMBASE and GPIO
registers define the base address and the type but not describe
the size. The size is fixed to 128bytes. So use
pci_mapreg_submap().
- Fix the calculation of the map size in pci_mapreg_submap().
- Use '\n' at the end of aprint_error_dev() format strings.
 1.10.4.1 05-Mar-2011  rmind sync with head
 1.10.2.1 17-Aug-2010  uebayasi Sync with HEAD.
 1.11.36.1 06-Apr-2015  skrll Sync with HEAD
 1.11.34.1 08-Jan-2015  martin Pull up following revision(s) (requested by msaitoh in ticket #394):
sys/dev/pci/pcivar.h: revision 1.101
sys/dev/pci/pci_map.c: revision 1.32
sys/dev/ic/i82801lpcreg.h: revision 1.12
sys/arch/x86/pci/ichlpcib.c: revision 1.45
Fix a bug that ichlpcib(4) maps I/O area incorrectly and then fails to attach
gpio. It might also fix ACPI related problem described in PR#48960:
- The LPCIB_PCI_PMBASE and LPCIB_PCI_GPIO register are alike PCI BAR but not
completely compatible with it. It's ok because the registers' addresses are
out of BAR0-BAR5(0x10-0x24) and are located in the device-dependent header.
The PMBASE and GPIO registers define the base address and the type but not
describe the size. The size is fixed to 128bytes. So use
pci_mapreg_submap().
- Make pci_mapreg_submap() extern again.
- Fix the calculation of the map size in pci_mapreg_submap().
 1.11.18.1 03-Dec-2017  jdolecek update from HEAD
 1.11.14.1 16-Jan-2015  snj Pull up following revision(s) (requested by msaitoh in ticket #1229):
sys/arch/x86/pci/ichlpcib.c: revision 1.40, 1.45
sys/dev/pci/pcivar.h: revision 1.101
sys/dev/pci/pci_map.c: revision 1.32
sys/dev/ic/i82801lpcreg.h: revision 1.12
Use '\n' at the end of all aprint_error_dev() format strings.
--
Fix a bug that ichlpcib(4) maps I/O area incorrectly and then fails to attach
gpio. It might also fixes ACPI related problem described in PR#48960:
- The LPCIB_PCI_PMBASE and LPCIB_PCI_GPIO register are alike PCI BAR but not
completely compatible with it. It's ok because the registers' addresses are
out of BAR0-BAR5(0x10-0x24) and are located in the device-dependent header.
The PMBASE and GPIO registers define the base address and the type but not
describe the size. The size is fixed to 128bytes. So use
pci_mapreg_submap().
- Make pci_mapreg_submap() extern again.
- Fix the calculation of the map size in pci_mapreg_submap().
 1.16.4.1 01-Aug-2023  martin Pull up following revision(s) (requested by riastradh in ticket #282):

sys/dev/pci/ichsmb.c: revision 1.82
sys/arch/amd64/conf/GENERIC: revision 1.602
sys/arch/x86/pci/tco.c: revision 1.10
sys/arch/x86/pci/tco.h: revision 1.5
sys/arch/x86/pci/ichlpcib.c: revision 1.59
sys/dev/ic/i82801lpcreg.h: revision 1.17
sys/arch/x86/pci/files.pci: revision 1.27
sys/dev/pci/files.pci: revision 1.446

ichsmb(4), tco(4): Add support for TCO on newer Intel chipsets.

TCO (`Total Cost of Ownership', Intel's bizarre name for a watchdog
timer) used to hang off the Intel I/O platform controller hub's (ICH)
low-pin-count interface bridge (LPC IB), or ichlpcib(4). On newer
devices, it hangs off the ICH SMBus instead.
Tested on INTEL 100SERIES_SMB (works) and INTEL 100SERIES_LP_SMB
(doesn't work, still not sure why).

XXX kernel revbump: This breaks the module ABI -- tco(4) modules
older than the change to make ta_has_rcba into ta_version will
incorrectly attach at buses they do not understand. (However, the
tco(4) driver is statically built into GENERIC, so maybe it's safe
for pullup since the module wouldn't have worked anyway.)
 1.1 15-Jun-2011  jruoho branches: 1.1.2;
Factor out hpet(4) from ichlpcib(4).
 1.1.2.2 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.1.2.1 15-Jun-2011  cherry file i82801lpcvar.h was added on branch cherry-xenmp on 2011-06-23 14:19:59 +0000
 1.13 21-Sep-2018  maxv Remove iavc(4).
 1.12 23-Mar-2014  christos branches: 1.12.28; 1.12.30;
remove unused
 1.11 23-Mar-2014  christos remove unused
 1.10 29-May-2013  martin branches: 1.10.2;
Fix signature of capi_ll_control.
From Wolfgang Stukenbrock in PR kern/47863.
 1.9 27-Oct-2012  chs split device_t/softc for all remaining drivers.
replace "struct device *" with "device_t".
use device_xname(), device_unit(), etc.
 1.8 23-Jan-2009  christos branches: 1.8.14; 1.8.20; 1.8.24;
Make this compile &foo[0] does not work for void * :-) Wojciech Galazka
 1.7 08-Apr-2008  cegger branches: 1.7.4; 1.7.12; 1.7.14;
use aprint_*_dev and device_xname
 1.6 19-Oct-2007  ad branches: 1.6.16;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.5 16-Oct-2006  pooka branches: 1.5.8; 1.5.22; 1.5.24; 1.5.28;
* __unused games + other relevant fixes
* give me ANSI C or give me death (at least where it could be easily spotted)
 1.4 11-Dec-2005  christos branches: 1.4.20; 1.4.22;
merge ktrace-lwp.
 1.3 09-Jul-2005  christos make the isdn drivers compile again with -Wconst, -Wshadow
 1.2 27-Feb-2005  perry branches: 1.2.4;
nuke trailing whitespace
 1.1 25-Sep-2003  pooka branches: 1.1.4; 1.1.10; 1.1.12;
Add a driver for the CAPI-compliant AVM B1/T1 cards.

The driver backend is capable of supporting also ISA cards (no DMA)
and primary rate (PRI) cards in addition to the basic rate ones,
but I don't any to test on right now, so we don't support those
currently.

This code was originally written by Juha-Matti Liukkonen <jml@cubical.fi>
of Cubical Solutions Ltd. for FreeBSD, and was ported to NetBSD by
myself for the same company.
 1.1.12.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.1.10.1 29-Apr-2005  kent sync with -current
 1.1.4.6 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.1.4.5 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.1.4.4 21-Sep-2004  skrll Fix the sync with head I botched.
 1.1.4.3 18-Sep-2004  skrll Sync with HEAD.
 1.1.4.2 03-Aug-2004  skrll Sync with HEAD
 1.1.4.1 25-Sep-2003  skrll file iavc.c was added on branch ktrace-lwp on 2004-08-03 10:46:15 +0000
 1.2.4.3 27-Oct-2007  yamt sync with head.
 1.2.4.2 30-Dec-2006  yamt sync with head.
 1.2.4.1 21-Jun-2006  yamt sync with head.
 1.4.22.1 22-Oct-2006  yamt sync with head
 1.4.20.1 18-Nov-2006  ad Sync with head.
 1.5.28.1 25-Oct-2007  bouyer Sync with HEAD.
 1.5.24.1 06-Nov-2007  matt sync with HEAD
 1.5.22.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.5.8.1 23-Oct-2007  ad Sync with head.
 1.6.16.1 02-Jun-2008  mjf Sync with HEAD.
 1.7.14.1 02-Dec-2010  snj Pull up following revision(s) (requested by riz in ticket #1418):
sys/dev/ic/iavc.c: revision 1.8
Make this compile &foo[0] does not work for void * :-) Wojciech Galazka
 1.7.12.1 03-Mar-2009  skrll Sync with HEAD.
 1.7.4.1 04-May-2009  yamt sync with head.
 1.8.24.3 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.8.24.2 23-Jun-2013  tls resync from head
 1.8.24.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.8.20.1 13-Jun-2013  msaitoh Pull up following revision(s) (requested by martin in ticket #896):
sys/dev/ic/iavc.c: revision 1.10
sys/netisdn/i4b_capi_llif.c: revision 1.6
sys/netisdn/i4b_capi.h: revision 1.6
Fix signature of capi_ll_control.
From Wolfgang Stukenbrock in PR kern/47863.
 1.8.14.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.8.14.1 30-Oct-2012  yamt sync with head
 1.10.2.1 18-May-2014  rmind sync with head
 1.12.30.1 10-Jun-2019  christos Sync with HEAD
 1.12.28.1 30-Sep-2018  pgoyette Ssync with HEAD
 1.5 21-Sep-2018  maxv Remove iavc(4).
 1.4 16-Feb-2006  perry branches: 1.4.156; 1.4.158;
Change "inline" back to "__inline" in .h files -- C99 is still too
new, and some apps compile things in C89 mode. C89 keywords stay.

As per core@.
 1.3 24-Dec-2005  perry branches: 1.3.2; 1.3.4; 1.3.6;
Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.2 11-Dec-2005  christos merge ktrace-lwp.
 1.1 25-Sep-2003  pooka branches: 1.1.4;
Add a driver for the CAPI-compliant AVM B1/T1 cards.

The driver backend is capable of supporting also ISA cards (no DMA)
and primary rate (PRI) cards in addition to the basic rate ones,
but I don't any to test on right now, so we don't support those
currently.

This code was originally written by Juha-Matti Liukkonen <jml@cubical.fi>
of Cubical Solutions Ltd. for FreeBSD, and was ported to NetBSD by
myself for the same company.
 1.1.4.4 21-Sep-2004  skrll Fix the sync with head I botched.
 1.1.4.3 18-Sep-2004  skrll Sync with HEAD.
 1.1.4.2 03-Aug-2004  skrll Sync with HEAD
 1.1.4.1 25-Sep-2003  skrll file iavcreg.h was added on branch ktrace-lwp on 2004-08-03 10:46:15 +0000
 1.3.6.1 22-Apr-2006  simonb Sync with head.
 1.3.4.1 09-Sep-2006  rpaulo sync with head
 1.3.2.1 18-Feb-2006  yamt sync with head.
 1.4.158.1 10-Jun-2019  christos Sync with HEAD
 1.4.156.1 30-Sep-2018  pgoyette Ssync with HEAD
 1.6 21-Sep-2018  maxv Remove iavc(4).
 1.5 27-Oct-2012  chs branches: 1.5.36; 1.5.38;
split device_t/softc for all remaining drivers.
replace "struct device *" with "device_t".
use device_xname(), device_unit(), etc.
 1.4 04-Mar-2007  christos branches: 1.4.76; 1.4.86;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.3 11-Dec-2005  christos branches: 1.3.26;
merge ktrace-lwp.
 1.2 27-Feb-2005  perry branches: 1.2.4;
nuke trailing whitespace
 1.1 25-Sep-2003  pooka branches: 1.1.4; 1.1.10; 1.1.12;
Add a driver for the CAPI-compliant AVM B1/T1 cards.

The driver backend is capable of supporting also ISA cards (no DMA)
and primary rate (PRI) cards in addition to the basic rate ones,
but I don't any to test on right now, so we don't support those
currently.

This code was originally written by Juha-Matti Liukkonen <jml@cubical.fi>
of Cubical Solutions Ltd. for FreeBSD, and was ported to NetBSD by
myself for the same company.
 1.1.12.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.1.10.1 29-Apr-2005  kent sync with -current
 1.1.4.5 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.1.4.4 21-Sep-2004  skrll Fix the sync with head I botched.
 1.1.4.3 18-Sep-2004  skrll Sync with HEAD.
 1.1.4.2 03-Aug-2004  skrll Sync with HEAD
 1.1.4.1 25-Sep-2003  skrll file iavcvar.h was added on branch ktrace-lwp on 2004-08-03 10:46:15 +0000
 1.2.4.1 03-Sep-2007  yamt sync with head.
 1.3.26.1 12-Mar-2007  rmind Sync with HEAD.
 1.4.86.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.4.76.1 30-Oct-2012  yamt sync with head
 1.5.38.1 10-Jun-2019  christos Sync with HEAD
 1.5.36.1 30-Sep-2018  pgoyette Ssync with HEAD
 1.14 04-Dec-2020  thorpej - malloc(9) -> kmem(9)
- In ibm561_set_cmap(), allocating 3K on the stack is not polite; allocate
a temporary buffer for the cmap data using kmem_alloc().
 1.13 24-Jun-2020  jdolecek branches: 1.13.2;
actually stop using the stack variable
 1.12 24-Jun-2020  jdolecek avoid allocating almost 5k struct ibm561data on stack in ibm561_cninit();
it's too early for kmem_alloc(), so use static variable in BSS
 1.11 12-Feb-2012  matt Change old-style function defintions to C89 prototypes.

Approved by releng.
 1.10 13-Nov-2010  uebayasi branches: 1.10.8; 1.10.12;
Don't pull in the whole uvm(9) API to access only PAGE_SIZE and
some other constants. These are provided by sys/param.h now.
 1.9 14-Mar-2009  dsl branches: 1.9.4;
Change about 4500 of the K&R function definitions to ANSI ones.
There are still about 1600 left, but they have ',' or /* ... */
in the actual variable definitions - which my awk script doesn't handle.
There are also many that need () -> (void).
(The script does handle misordered arguments.)
 1.8 28-Apr-2008  martin branches: 1.8.8; 1.8.14;
Remove clause 3 and 4 from TNF licenses
 1.7 11-Dec-2005  christos branches: 1.7.70; 1.7.72; 1.7.74;
merge ktrace-lwp.
 1.6 04-Feb-2005  perry de-__P
 1.5 13-Nov-2003  chs branches: 1.5.8; 1.5.10;
eliminate uvm_useracc() in favor of checking the return value of
copyin() or copyout().

uvm_useracc() tells us whether the mapping permissions allow access to
the desired part of an address space, and many callers assume that
this is the same as knowing whether an attempt to access that part of
the address space will succeed. however, access to user space can
fail for reasons other than insufficient permission, most notably that
paging in any non-resident data can fail due to i/o errors. most of
the callers of uvm_useracc() make the above incorrect assumption. the
rest are all misguided optimizations, which optimize for the case
where an operation will fail. we'd rather optimize for operations
succeeding, in which case we should just attempt the access and handle
failures due to insufficient permissions the same way we handle i/o
errors. since there appear to be no good uses of uvm_useracc(), we'll
just remove it.
 1.4 14-Jul-2003  lukem add missing __KERNEL_RCSID()
 1.3 03-Aug-2002  itojun branches: 1.3.6;
correct range check, have overflow check, fix type mismatches,
for cmap args and some other calls. from openbsd
 1.2 12-Jan-2002  tsutsui branches: 1.2.8; 1.2.10;
Call malloc(9) with M_ZERO flag instead of memset() after malloc().
 1.1 12-Dec-2001  elric branches: 1.1.2; 1.1.4;
Initial support for the IBM RGB561 RAMDAC. This uses the same interface
as the Bt463 and Bt485 drivers.
 1.1.4.4 06-Sep-2002  jdolecek sync kqueue branch with HEAD
 1.1.4.3 11-Feb-2002  jdolecek Sync w/ -current.
 1.1.4.2 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.1.4.1 12-Dec-2001  thorpej file ibm561.c was added on branch kqueue on 2002-01-10 19:54:34 +0000
 1.1.2.4 13-Aug-2002  nathanw Catch up to -current.
 1.1.2.3 28-Feb-2002  nathanw Catch up to -current.
 1.1.2.2 08-Jan-2002  nathanw Catch up to -current.
 1.1.2.1 12-Dec-2001  nathanw file ibm561.c was added on branch nathanw_sa on 2002-01-08 00:29:47 +0000
 1.2.10.1 07-Aug-2002  lukem Pull up revision 1.3 (requested by itojun in ticket #616):
correct range check, have overflow check, fix type mismatches,
for cmap args and some other calls. from openbsd
 1.2.8.1 29-Aug-2002  gehenna catch up with -current.
 1.3.6.4 04-Feb-2005  skrll Sync with HEAD.
 1.3.6.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.3.6.2 18-Sep-2004  skrll Sync with HEAD.
 1.3.6.1 03-Aug-2004  skrll Sync with HEAD
 1.5.10.1 12-Feb-2005  yamt sync with head.
 1.5.8.1 29-Apr-2005  kent sync with -current
 1.7.74.2 04-May-2009  yamt sync with head.
 1.7.74.1 16-May-2008  yamt sync with head.
 1.7.72.1 18-May-2008  yamt sync with head.
 1.7.70.1 02-Jun-2008  mjf Sync with HEAD.
 1.8.14.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.8.8.1 28-Apr-2009  skrll Sync with HEAD.
 1.9.4.1 05-Mar-2011  rmind sync with head
 1.10.12.1 18-Feb-2012  mrg merge to -current.
 1.10.8.1 17-Apr-2012  yamt sync with head
 1.13.2.1 14-Dec-2020  thorpej Sync w/ HEAD.
 1.6 20-Oct-2012  macallan fix typo
 1.5 28-Apr-2008  martin branches: 1.5.34; 1.5.44;
Remove clause 3 and 4 from TNF licenses
 1.4 28-Aug-2007  macallan branches: 1.4.20; 1.4.22; 1.4.24;
fix typo
 1.3 27-Aug-2007  macallan add lots of register definitions from the IBM561 datasheet
 1.2 22-Dec-2001  elric branches: 1.2.2; 1.2.4; 1.2.36; 1.2.78; 1.2.88; 1.2.92; 1.2.94;
Hmmm. These were done this year, not 3 years ago.
 1.1 12-Dec-2001  elric Initial support for the IBM RGB561 RAMDAC. This uses the same interface
as the Bt463 and Bt485 drivers.
 1.2.94.1 06-Nov-2007  matt sync with HEAD
 1.2.92.1 03-Sep-2007  jmcneill Sync with HEAD.
 1.2.88.1 03-Sep-2007  skrll Sync with HEAD.
 1.2.78.1 09-Oct-2007  ad Sync with head.
 1.2.36.1 03-Sep-2007  yamt sync with head.
 1.2.4.2 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.2.4.1 22-Dec-2001  thorpej file ibm561reg.h was added on branch kqueue on 2002-01-10 19:54:34 +0000
 1.2.2.2 08-Jan-2002  nathanw Catch up to -current.
 1.2.2.1 22-Dec-2001  nathanw file ibm561reg.h was added on branch nathanw_sa on 2002-01-08 00:29:47 +0000
 1.4.24.1 16-May-2008  yamt sync with head.
 1.4.22.1 18-May-2008  yamt sync with head.
 1.4.20.1 02-Jun-2008  mjf Sync with HEAD.
 1.5.44.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.5.34.1 30-Oct-2012  yamt sync with head
 1.5 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.4 11-Dec-2005  christos branches: 1.4.70; 1.4.72; 1.4.74;
merge ktrace-lwp.
 1.3 04-Feb-2005  perry de-__P
 1.2 22-Dec-2001  elric branches: 1.2.2; 1.2.4; 1.2.20; 1.2.28; 1.2.30;
Hmmm. These were done this year, not 3 years ago.
 1.1 12-Dec-2001  elric Initial support for the IBM RGB561 RAMDAC. This uses the same interface
as the Bt463 and Bt485 drivers.
 1.2.30.1 12-Feb-2005  yamt sync with head.
 1.2.28.1 29-Apr-2005  kent sync with -current
 1.2.20.1 04-Feb-2005  skrll Sync with HEAD.
 1.2.4.2 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.2.4.1 22-Dec-2001  thorpej file ibm561var.h was added on branch kqueue on 2002-01-10 19:54:35 +0000
 1.2.2.2 08-Jan-2002  nathanw Catch up to -current.
 1.2.2.1 22-Dec-2001  nathanw file ibm561var.h was added on branch nathanw_sa on 2002-01-08 00:29:48 +0000
 1.4.74.1 16-May-2008  yamt sync with head.
 1.4.72.1 18-May-2008  yamt sync with head.
 1.4.70.1 02-Jun-2008  mjf Sync with HEAD.
 1.4 21-Aug-2021  andvar fix mainly same typos as in my previous commit but outside sys/dev/dm.
 1.3 14-Jun-2008  mjf Automatically detect the amount of installed RAM by reading the memory
bank registers from the PCI host bridge. Previously the RAM size was
hardcoded to 64MB.

Also fill out ibm82660reg.h with more definitions from the PowerPC to
PCI Bridge and Memory Controller User's Manual.

Many thanks to Tim Rightnour for helping with this patch.
 1.2 28-Apr-2008  martin branches: 1.2.2; 1.2.4;
Remove clause 3 and 4 from TNF licenses
 1.1 01-May-2007  garbled branches: 1.1.2; 1.1.4; 1.1.6; 1.1.16; 1.1.36; 1.1.38; 1.1.40;
Add a set of registers for the ibm 82660 pci bridge chip found in various
IBM powerpc machines.
 1.1.40.2 04-May-2009  yamt sync with head.
 1.1.40.1 16-May-2008  yamt sync with head.
 1.1.38.2 17-Jun-2008  yamt sync with head.
 1.1.38.1 18-May-2008  yamt sync with head.
 1.1.36.2 29-Jun-2008  mjf Sync with HEAD.
 1.1.36.1 02-Jun-2008  mjf Sync with HEAD.
 1.1.16.2 03-Sep-2007  yamt sync with head.
 1.1.16.1 01-May-2007  yamt file ibm82660reg.h was added on branch yamt-lazymbuf on 2007-09-03 14:34:42 +0000
 1.1.6.2 11-Jul-2007  mjf Sync with head.
 1.1.6.1 01-May-2007  mjf file ibm82660reg.h was added on branch mjf-ufs-trans on 2007-07-11 20:05:50 +0000
 1.1.4.2 09-Jun-2007  ad Sync with head.
 1.1.4.1 01-May-2007  ad file ibm82660reg.h was added on branch vmlocking on 2007-06-09 21:37:14 +0000
 1.1.2.2 07-May-2007  yamt sync with head.
 1.1.2.1 01-May-2007  yamt file ibm82660reg.h was added on branch yamt-idlelwp on 2007-05-07 10:55:26 +0000
 1.2.4.1 18-Jun-2008  simonb Sync with head.
 1.2.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.37 10-Apr-2022  andvar fix various typos in comments and output/log messages.
 1.36 07-Aug-2021  thorpej Merge thorpej-cfargs2.
 1.35 24-Apr-2021  thorpej branches: 1.35.8;
Merge thorpej-cfargs branch:

Simplify and make extensible the config_search() / config_found() /
config_attach() interfaces: rather than having different variants for
which arguments you want pass along, just have a single call that
takes a variadic list of tag-value arguments.

Adjust all call sites:
- Simplify wherever possible; don't pass along arguments that aren't
actually needed.
- Don't be explicit about what interface attribute is attaching if
the device only has one. (More simplification.)
- Add a config_probe() function to be used in indirect configuiration
situations, making is visibly easier to see when indirect config is
in play, and allowing for future change in semantics. (As of now,
this is just a wrapper around config_match(), but that is an
implementation detail.)

Remove unnecessary or redundant interface attributes where they're not
needed.

There are currently 5 "cfargs" defined:
- CFARG_SUBMATCH (submatch function for direct config)
- CFARG_SEARCH (search function for indirect config)
- CFARG_IATTR (interface attribte)
- CFARG_LOCATORS (locators array)
- CFARG_DEVHANDLE (devhandle_t - wraps OFW, ACPI, etc. handles)

...and a sentinel value CFARG_EOL.

Add some extra sanity checking to ensure that interface attributes
aren't ambiguous.

Use CFARG_DEVHANDLE in MI FDT, OFW, and ACPI code, and macppc and shark
ports to associate those device handles with device_t instance. This
will trickle trough to more places over time (need back-end for pre-OFW
Sun OBP; any others?).
 1.34 14-Aug-2020  chs branches: 1.34.4;
restore the initialization of icp->icp_ccbs that I removed by mistake.
 1.33 10-Nov-2019  chs in many device attach paths, allocate memory with M_WAITOK instead of M_NOWAIT
and remove code to handle failures that can no longer happen.
 1.32 18-Oct-2019  msaitoh s/initalize/initialize/ in comment or printf message.
 1.31 27-Oct-2012  chs branches: 1.31.38;
split device_t/softc for all remaining drivers.
replace "struct device *" with "device_t".
use device_xname(), device_unit(), etc.
 1.30 13-Nov-2010  uebayasi branches: 1.30.8; 1.30.18;
Don't pull in the whole uvm(9) API to access only PAGE_SIZE and
some other constants. These are provided by sys/param.h now.
 1.29 30-Apr-2008  ad branches: 1.29.22;
Make various bits of debug code compile again.
 1.28 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.27 08-Apr-2008  cegger branches: 1.27.2; 1.27.4;
use aprint_*_dev and device_xname
 1.26 19-Oct-2007  ad branches: 1.26.16;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.25 09-Jul-2007  ad branches: 1.25.6; 1.25.8; 1.25.12;
Merge some of the less invasive changes from the vmlocking branch:

- kthread, callout, devsw API changes
- select()/poll() improvements
- miscellaneous MT safety improvements
 1.24 11-Mar-2007  ad branches: 1.24.2;
Remove a use of lockmgr/LOCK_INITIALIZER.
 1.23 04-Mar-2007  christos branches: 1.23.2;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.22 16-Nov-2006  christos branches: 1.22.4;
__unused removal on arguments; approved by core.
 1.21 12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.20 07-Jun-2006  kardel branches: 1.20.6; 1.20.8;
merge FreeBSD timecounters from branch simonb-timecounters
- struct timeval time is gone
time.tv_sec -> time_second
- struct timeval mono_time is gone
mono_time.tv_sec -> time_uptime
- access to time via
{get,}{micro,nano,bin}time()
get* versions are fast but less precise
- support NTP nanokernel implementation (NTP API 4)
- further reading:
Timecounter Paper: http://phk.freebsd.dk/pubs/timecounter.pdf
NTP Nanokernel: http://www.eecis.udel.edu/~mills/ntp/html/kern.html
 1.19 28-Mar-2006  thorpej branches: 1.19.2;
Use device_unit().
 1.18 29-Jan-2006  dsl branches: 1.18.2; 1.18.4; 1.18.6; 1.18.8; 1.18.10;
Make almost everything #include <sys/bswap.h> instead of <machine/bswap.h>
The bswap.h and endian.h files are all rather incestuous, but I want to
get the constant folding stuff into one place - sys/bswap.h
 1.17 11-Dec-2005  christos branches: 1.17.2;
merge ktrace-lwp.
 1.16 25-Aug-2005  drochner kill a number of autoconf submatch functions which follow the
standard scheme:
if (<configured> != <wildcard> && <configured> != <real>)
then fail
else
ask device match function

This is handled by config_stdsubmatch() now.
 1.15 25-Aug-2005  drochner replace the "locdesc_t" structure carrying the number of locators
explicitely by a plain integer array
the length in now known to all relevant parties, so this avoids
duplication of information, and we can allocate that thing in
drivers without hacks
 1.14 27-Feb-2005  perry branches: 1.14.4;
nuke trailing whitespace
 1.13 13-Sep-2004  drochner branches: 1.13.4; 1.13.6;
a round of autoconf cleanup:
-convert submatch() style functions (passed to config_search() or
config_found_sm()) to the locator passing variants
-pass interface attributes in some cases
-make submatch() functions look uniformly as far as possible
-avoid macros which just hide cfdata members, and reduce dependencies
on "locators.h"
 1.12 29-Oct-2003  mycroft Remove bogus initializer, and fix a typo in a loop variable instead.
 1.11 25-Oct-2003  christos Fix uninitialized variable warnings
 1.10 13-Jun-2003  thorpej branches: 1.10.2;
Add support for dynamic rescan of cache service logical drives, using
the ioctl issued by the ICP RAID management libraries (used by the
storcon and iirconfig tools). This requires some infrastructure changes:
* Add a "service callback" mechanism that the ld driver (cache service)
and the iopsp driver (raw service) can register with the icp parent.
Right now this callback allows the children to adjust their notion of
how many command openings are available.
* Add a mutex around the icp ioctl handler, allowing only one thread
to execute an ioctl at a time.
* Add a way to freeze the controller command queue. We stop all I/O
while processing rescans (due to the semantics of icp_cmd()).
* Make icp_cmd() work when !cold.
* Add detach support to ld@icp.
 1.9 17-May-2003  thorpej Another fix from Achim Leubner @ ICP:

Test-busy *before* marking the controller as processing a user ioctl,
otherwise the command queue could stall permanently if test-busy returned
true.
 1.8 13-May-2003  thorpej Add support for the user-generated command interface and event logging
required by the ICP-Vortex management tools. Many thanks to Achim Leubner
at ICP-Vortex for a few bug fixes and for testing.
 1.7 31-Jan-2003  thorpej Use aprint_*().
 1.6 01-Jan-2003  thorpej Use aprint_normal() in cfprint routines.
 1.5 22-Oct-2002  simonb In icp_init(), initialise the "state" variable before incrementing it.
 1.4 27-Sep-2002  provos remove trailing \n in panic(). approved perry.
 1.3 27-Sep-2002  thorpej Introduce a new routine, config_match(), which invokes the
cfattach->ca_match function in behalf of the caller. Use it
rather than invoking cfattach->ca_match directly.
 1.2 01-Jun-2002  lukem branches: 1.2.2; 1.2.4;
SIMPLEQ rototill:
- implement SIMPLEQ_REMOVE(head, elm, type, field). whilst it's O(n),
this mirrors the functionality of SLIST_REMOVE() (the other
singly-linked list type) and FreeBSD's STAILQ_REMOVE()
- remove the unnecessary elm arg from SIMPLEQ_REMOVE_HEAD().
this mirrors the functionality of SLIST_REMOVE_HEAD() (the other
singly-linked list type) and FreeBSD's STAILQ_REMOVE_HEAD()
- remove notes about SIMPLEQ not supporting arbitrary element removal
- use SIMPLEQ_FOREACH() instead of home-grown for loops
- use SIMPLEQ_EMPTY() appropriately
- use SIMPLEQ_*() instead of accessing sqh_first,sqh_last,sqe_next directly
- reorder manual page; be consistent about how the types are listed
- other minor cleanups
 1.1 22-Apr-2002  ad branches: 1.1.2;
Add a driver for ICP-Vortex GDT and Intel Storage RAID controllers. Parts
taken from OpenBSD. Test hardware kindly provided by Intel. This still needs
management bits, and doesn't support older controllers, but that shouldn't
be hard to fix.
 1.1.2.1 20-Jun-2002  gehenna catch up with -current.
 1.2.4.3 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.2.4.2 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.2.4.1 01-Jun-2002  jdolecek file icp.c was added on branch kqueue on 2002-06-23 17:46:28 +0000
 1.2.2.5 03-Jan-2003  thorpej Sync with HEAD.
 1.2.2.4 11-Nov-2002  nathanw Catch up to -current
 1.2.2.3 18-Oct-2002  nathanw Catch up to -current.
 1.2.2.2 20-Jun-2002  nathanw Catch up to -current.
 1.2.2.1 01-Jun-2002  nathanw file icp.c was added on branch nathanw_sa on 2002-06-20 03:44:40 +0000
 1.10.2.5 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.10.2.4 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.10.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.10.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.10.2.1 03-Aug-2004  skrll Sync with HEAD
 1.13.6.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.13.4.1 29-Apr-2005  kent sync with -current
 1.14.4.3 27-Oct-2007  yamt sync with head.
 1.14.4.2 03-Sep-2007  yamt sync with head.
 1.14.4.1 21-Jun-2006  yamt sync with head.
 1.17.2.1 01-Feb-2006  yamt sync with head.
 1.18.10.1 31-Mar-2006  tron Merge 2006-03-31 NetBSD-current into the "peter-altq" branch.
 1.18.8.1 19-Apr-2006  elad sync with head.
 1.18.6.2 26-Jun-2006  yamt sync with head.
 1.18.6.1 01-Apr-2006  yamt sync with head.
 1.18.4.2 22-Apr-2006  simonb Sync with head.
 1.18.4.1 04-Feb-2006  simonb Adapt for timecounters: mostly use get*time() and use "time_second"
instead of "time.tv_sec".
 1.18.2.1 09-Sep-2006  rpaulo sync with head
 1.19.2.1 19-Jun-2006  chap Sync with head.
 1.20.8.2 10-Dec-2006  yamt sync with head.
 1.20.8.1 22-Oct-2006  yamt sync with head
 1.20.6.1 18-Nov-2006  ad Sync with head.
 1.22.4.1 12-Mar-2007  rmind Sync with HEAD.
 1.23.2.3 23-Oct-2007  ad Sync with head.
 1.23.2.2 01-Jul-2007  ad Adapt to callout API change.
 1.23.2.1 13-Mar-2007  ad Sync with head.
 1.24.2.1 11-Jul-2007  mjf Sync with head.
 1.25.12.1 25-Oct-2007  bouyer Sync with HEAD.
 1.25.8.1 06-Nov-2007  matt sync with HEAD
 1.25.6.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.26.16.1 02-Jun-2008  mjf Sync with HEAD.
 1.27.4.1 16-May-2008  yamt sync with head.
 1.27.2.1 18-May-2008  yamt sync with head.
 1.29.22.1 05-Mar-2011  rmind sync with head
 1.30.18.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.30.8.1 30-Oct-2012  yamt sync with head
 1.31.38.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.34.4.2 22-Mar-2021  thorpej Audit CFARG_IATTR in config_found() calls, and remove it in situations
where the interface attribute is not ambiguous.
 1.34.4.1 22-Mar-2021  thorpej Mechanical conversion of config_found_sm_loc() -> config_found().
CFARG_IATTR usage needs to be audited.
 1.35.8.1 04-Aug-2021  thorpej Adapt to CFARGS().
 1.23 21-Jan-2022  andvar s/compatile/compatible/
 1.22 28-Oct-2017  riastradh Kill some more extern struct cfdriver declarations.

Down with externs in .c!
 1.21 25-Jul-2014  dholland Add d_discard to all struct cdevsw instances I could find.

All have been set to "nodiscard"; some should get a real implementation.
 1.20 16-Mar-2014  dholland branches: 1.20.2;
Change (mostly mechanically) every cdevsw/bdevsw I can find to use
designated initializers.

I have not built every extant kernel so I have probably broken at
least one build; however I've also found and fixed some wrong
cdevsw/bdevsw entries so even if so I think we come out ahead.
 1.19 08-Jun-2008  tsutsui branches: 1.19.32; 1.19.42; 1.19.48;
Replace device_lookup() with device_lookup_private() on getting softc
for future device_t/softc spilt.
 1.18 28-Apr-2008  martin branches: 1.18.2;
Remove clause 3 and 4 from TNF licenses
 1.17 19-Oct-2007  ad branches: 1.17.16; 1.17.18; 1.17.20;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.16 11-Mar-2007  ad branches: 1.16.12; 1.16.14; 1.16.18;
Remove a use of lockmgr/LOCK_INITIALIZER.
 1.15 04-Mar-2007  christos branches: 1.15.2;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.14 02-Dec-2006  elad branches: 1.14.2;
Change kauth(9) KPI for kauth_authorize_device_passthru() to add another
argument, u_long, serving as a bit-mask of generic requests for the
passthru request.

Discussed on tech-security@ and tech-kern@. Okay tls@.
 1.13 16-Nov-2006  christos branches: 1.13.2;
__unused removal on arguments; approved by core.
 1.12 08-Nov-2006  elad Replace securelevel checks with kauth(9) calls.
 1.11 12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.10 30-Aug-2006  christos branches: 1.10.2; 1.10.4;
add missing initializer
 1.9 23-Aug-2006  christos Acting as Elad's keyboard:

Place the securelevel checks in their logical locations.
This will be clearer in the future when code changes to use kauth(9) calls.

input and okay ad@
 1.8 11-Dec-2005  christos branches: 1.8.4; 1.8.8;
merge ktrace-lwp.
 1.7 30-May-2005  christos branches: 1.7.2;
- add missing const
- fix variable shadowing
- remove unneeded casts
 1.6 27-Feb-2005  perry nuke trailing whitespace
 1.5 29-Jun-2003  fvdl branches: 1.5.2; 1.5.10; 1.5.12;
Back out the lwp/ktrace changes. They contained a lot of colateral damage,
and need to be examined and discussed more.
 1.4 29-Jun-2003  itojun lwp change lossage
 1.3 13-Jun-2003  thorpej Add support for dynamic rescan of cache service logical drives, using
the ioctl issued by the ICP RAID management libraries (used by the
storcon and iirconfig tools). This requires some infrastructure changes:
* Add a "service callback" mechanism that the ld driver (cache service)
and the iopsp driver (raw service) can register with the icp parent.
Right now this callback allows the children to adjust their notion of
how many command openings are available.
* Add a mutex around the icp ioctl handler, allowing only one thread
to execute an ioctl at a time.
* Add a way to freeze the controller command queue. We stop all I/O
while processing rescans (due to the semantics of icp_cmd()).
* Make icp_cmd() work when !cold.
* Add detach support to ld@icp.
 1.2 18-May-2003  thorpej Fail icpioctl() if securelevel > 1.
 1.1 13-May-2003  thorpej Add support for the user-generated command interface and event logging
required by the ICP-Vortex management tools. Many thanks to Achim Leubner
at ICP-Vortex for a few bug fixes and for testing.
 1.5.12.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.5.10.1 29-Apr-2005  kent sync with -current
 1.5.2.5 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.5.2.4 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.5.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.5.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.5.2.1 19-Aug-2003  skrll LWPify
 1.7.2.4 27-Oct-2007  yamt sync with head.
 1.7.2.3 03-Sep-2007  yamt sync with head.
 1.7.2.2 30-Dec-2006  yamt sync with head.
 1.7.2.1 21-Jun-2006  yamt sync with head.
 1.8.8.1 03-Sep-2006  yamt sync with head.
 1.8.4.1 09-Sep-2006  rpaulo sync with head
 1.10.4.2 10-Dec-2006  yamt sync with head.
 1.10.4.1 22-Oct-2006  yamt sync with head
 1.10.2.2 12-Jan-2007  ad Sync with head.
 1.10.2.1 18-Nov-2006  ad Sync with head.
 1.13.2.1 04-Dec-2006  tron Pull up following revision(s) (requested by elad in ticket #247):
sys/dev/ic/dpt.c: revision 1.55
sys/dev/pci/amr.c: revision 1.43
sys/secmodel/bsd44/secmodel_bsd44_securelevel.c: revision 1.19
sys/dev/pci/mly.c: revision 1.33
share/man/man9/kauth.9: revision 1.37
sys/dev/ic/mlx.c: revision 1.49
sys/dev/ic/icp_ioctl.c: revision 1.14
sys/dev/i2o/iop.c: revision 1.62
sys/dev/pci/twe.c: revision 1.82
sys/sys/kauth.h: revision 1.25
sys/dev/i2o/dpti.c: revision 1.31
sys/kern/kern_auth.c: revision 1.33
sys/dev/tc/stic.c: revision 1.37
Change kauth(9) KPI for kauth_authorize_device_passthru() to add another
argument, u_long, serving as a bit-mask of generic requests for the
passthru request.
Discussed on tech-security@ and tech-kern@. Okay tls@.
 1.14.2.1 12-Mar-2007  rmind Sync with HEAD.
 1.15.2.2 23-Oct-2007  ad Sync with head.
 1.15.2.1 13-Mar-2007  ad Sync with head.
 1.16.18.1 25-Oct-2007  bouyer Sync with HEAD.
 1.16.14.1 06-Nov-2007  matt sync with HEAD
 1.16.12.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.17.20.2 04-May-2009  yamt sync with head.
 1.17.20.1 16-May-2008  yamt sync with head.
 1.17.18.2 17-Jun-2008  yamt sync with head.
 1.17.18.1 18-May-2008  yamt sync with head.
 1.17.16.2 29-Jun-2008  mjf Sync with HEAD.
 1.17.16.1 02-Jun-2008  mjf Sync with HEAD.
 1.18.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.19.48.1 18-May-2014  rmind sync with head
 1.19.42.2 03-Dec-2017  jdolecek update from HEAD
 1.19.42.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.19.32.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.20.2.1 10-Aug-2014  tls Rebase.
 1.7 28-Oct-2017  riastradh Add some #includes to make a few more header files compile.
 1.6 25-Dec-2007  perry branches: 1.6.54;
Convert many of the uses of __attribute__ to equivalent
__packed, __unused and __dead macros from cdefs.h
 1.5 11-Dec-2005  christos branches: 1.5.46; 1.5.52; 1.5.56; 1.5.60;
merge ktrace-lwp.
 1.4 27-Feb-2005  perry branches: 1.4.4;
nuke trailing whitespace
 1.3 29-Jun-2003  thorpej branches: 1.3.2; 1.3.10; 1.3.12;
Correct the R-W'ness of GDT_IOCTL_DRVERS and GDT_IOCTL_CTRTYPE.
From Achim Leubner @ ICP.
 1.2 13-Jun-2003  thorpej Add support for dynamic rescan of cache service logical drives, using
the ioctl issued by the ICP RAID management libraries (used by the
storcon and iirconfig tools). This requires some infrastructure changes:
* Add a "service callback" mechanism that the ld driver (cache service)
and the iopsp driver (raw service) can register with the icp parent.
Right now this callback allows the children to adjust their notion of
how many command openings are available.
* Add a mutex around the icp ioctl handler, allowing only one thread
to execute an ioctl at a time.
* Add a way to freeze the controller command queue. We stop all I/O
while processing rescans (due to the semantics of icp_cmd()).
* Make icp_cmd() work when !cold.
* Add detach support to ld@icp.
 1.1 13-May-2003  thorpej Add support for the user-generated command interface and event logging
required by the ICP-Vortex management tools. Many thanks to Achim Leubner
at ICP-Vortex for a few bug fixes and for testing.
 1.3.12.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.3.10.1 29-Apr-2005  kent sync with -current
 1.3.2.1 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.4.4.1 21-Jan-2008  yamt sync with head
 1.5.60.1 02-Jan-2008  bouyer Sync with HEAD
 1.5.56.1 26-Dec-2007  ad Sync with head.
 1.5.52.1 18-Feb-2008  mjf Sync with HEAD.
 1.5.46.1 09-Jan-2008  matt sync with HEAD
 1.6.54.1 03-Dec-2017  jdolecek update from HEAD
 1.7 08-Sep-2008  gmcgarry Replace most gcc-specific __attribute__ uses with BSD-style sys/cdef.h
preprocessor macros.
 1.6 28-Apr-2008  martin branches: 1.6.2; 1.6.6;
Remove clause 3 and 4 from TNF licenses
 1.5 11-Dec-2005  christos branches: 1.5.70; 1.5.72; 1.5.74;
merge ktrace-lwp.
 1.4 27-Feb-2005  perry nuke trailing whitespace
 1.3 13-Jun-2003  thorpej branches: 1.3.2; 1.3.10; 1.3.12;
Add support for dynamic rescan of cache service logical drives, using
the ioctl issued by the ICP RAID management libraries (used by the
storcon and iirconfig tools). This requires some infrastructure changes:
* Add a "service callback" mechanism that the ld driver (cache service)
and the iopsp driver (raw service) can register with the icp parent.
Right now this callback allows the children to adjust their notion of
how many command openings are available.
* Add a mutex around the icp ioctl handler, allowing only one thread
to execute an ioctl at a time.
* Add a way to freeze the controller command queue. We stop all I/O
while processing rescans (due to the semantics of icp_cmd()).
* Make icp_cmd() work when !cold.
* Add detach support to ld@icp.
 1.2 13-May-2003  thorpej Add support for the user-generated command interface and event logging
required by the ICP-Vortex management tools. Many thanks to Achim Leubner
at ICP-Vortex for a few bug fixes and for testing.
 1.1 22-Apr-2002  ad branches: 1.1.6; 1.1.8;
Add a driver for ICP-Vortex GDT and Intel Storage RAID controllers. Parts
taken from OpenBSD. Test hardware kindly provided by Intel. This still needs
management bits, and doesn't support older controllers, but that shouldn't
be hard to fix.
 1.1.8.2 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.1.8.1 22-Apr-2002  jdolecek file icpreg.h was added on branch kqueue on 2002-06-23 17:46:28 +0000
 1.1.6.2 20-Jun-2002  nathanw Catch up to -current.
 1.1.6.1 22-Apr-2002  nathanw file icpreg.h was added on branch nathanw_sa on 2002-06-20 03:44:40 +0000
 1.3.12.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.3.10.1 29-Apr-2005  kent sync with -current
 1.3.2.1 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.5.74.2 04-May-2009  yamt sync with head.
 1.5.74.1 16-May-2008  yamt sync with head.
 1.5.72.1 18-May-2008  yamt sync with head.
 1.5.70.2 28-Sep-2008  mjf Sync with HEAD.
 1.5.70.1 02-Jun-2008  mjf Sync with HEAD.
 1.6.6.1 19-Oct-2008  haad Sync with HEAD.
 1.6.2.1 24-Sep-2008  wrstuden Merge in changes between wrstuden-revivesa-base-2 and
wrstuden-revivesa-base-3.
 1.29 16-Jan-2024  andvar Fix typos in word "particularly", in comments.
 1.28 07-Aug-2021  thorpej Merge thorpej-cfargs2.
 1.27 24-Apr-2021  thorpej branches: 1.27.8;
Merge thorpej-cfargs branch:

Simplify and make extensible the config_search() / config_found() /
config_attach() interfaces: rather than having different variants for
which arguments you want pass along, just have a single call that
takes a variadic list of tag-value arguments.

Adjust all call sites:
- Simplify wherever possible; don't pass along arguments that aren't
actually needed.
- Don't be explicit about what interface attribute is attaching if
the device only has one. (More simplification.)
- Add a config_probe() function to be used in indirect configuiration
situations, making is visibly easier to see when indirect config is
in play, and allowing for future change in semantics. (As of now,
this is just a wrapper around config_match(), but that is an
implementation detail.)

Remove unnecessary or redundant interface attributes where they're not
needed.

There are currently 5 "cfargs" defined:
- CFARG_SUBMATCH (submatch function for direct config)
- CFARG_SEARCH (search function for indirect config)
- CFARG_IATTR (interface attribte)
- CFARG_LOCATORS (locators array)
- CFARG_DEVHANDLE (devhandle_t - wraps OFW, ACPI, etc. handles)

...and a sentinel value CFARG_EOL.

Add some extra sanity checking to ensure that interface attributes
aren't ambiguous.

Use CFARG_DEVHANDLE in MI FDT, OFW, and ACPI code, and macppc and shark
ports to associate those device handles with device_t instance. This
will trickle trough to more places over time (need back-end for pre-OFW
Sun OBP; any others?).
 1.26 07-Mar-2014  skrll branches: 1.26.46;
Fix non-DIAGNOSTIC build
 1.25 27-Oct-2012  chs branches: 1.25.2;
split device_t/softc for all remaining drivers.
replace "struct device *" with "device_t".
use device_xname(), device_unit(), etc.
 1.24 13-Nov-2010  uebayasi branches: 1.24.8; 1.24.18;
Don't pull in the whole uvm(9) API to access only PAGE_SIZE and
some other constants. These are provided by sys/param.h now.
 1.23 12-May-2009  cegger branches: 1.23.4;
struct device * -> device_t, no functional changes intended.
 1.22 12-May-2009  cegger struct cfdata * -> cfdata_t, no functional changes intended.
 1.21 28-Apr-2008  martin branches: 1.21.14;
Remove clause 3 and 4 from TNF licenses
 1.20 08-Apr-2008  cegger branches: 1.20.2; 1.20.4;
use aprint_*_dev and device_xname
 1.19 04-Jan-2008  ad branches: 1.19.6;
Start detangling lock.h from intr.h. This is likely to cause short term
breakage, but the mess of dependencies has been regularly breaking the
build recently anyhow.
 1.18 19-Oct-2007  ad branches: 1.18.2; 1.18.8;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.17 04-Mar-2007  christos branches: 1.17.2; 1.17.14; 1.17.16; 1.17.20;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.16 16-Nov-2006  christos branches: 1.16.4;
__unused removal on arguments; approved by core.
 1.15 12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.14 25-Mar-2006  thorpej branches: 1.14.8; 1.14.10;
Use device_parent().
 1.13 29-Jan-2006  dsl branches: 1.13.2; 1.13.4; 1.13.6; 1.13.8; 1.13.10;
Make almost everything #include <sys/bswap.h> instead of <machine/bswap.h>
The bswap.h and endian.h files are all rather incestuous, but I want to
get the constant folding stuff into one place - sys/bswap.h
 1.12 11-Dec-2005  christos branches: 1.12.2;
merge ktrace-lwp.
 1.11 27-Feb-2005  perry branches: 1.11.4;
nuke trailing whitespace
 1.10 21-Feb-2005  thorpej Part 1 of a cleanup pass over the SCSI subsystem. The aim is to name
everything "scsi_*", since we really are talking about the SCSI command
set, ATAPI transport not withstanding. Improve the names of many structures,
and prepend "SCSI_" onto all SCSI command opcodes. Place items described
by the SCSI Primary Commands document into scsi_spc.h.
 1.9 18-Sep-2003  mycroft branches: 1.9.8; 1.9.10;
nluns should be 8, not 7.
 1.8 13-Jun-2003  thorpej branches: 1.8.2;
Add support for dynamic rescan of cache service logical drives, using
the ioctl issued by the ICP RAID management libraries (used by the
storcon and iirconfig tools). This requires some infrastructure changes:
* Add a "service callback" mechanism that the ld driver (cache service)
and the iopsp driver (raw service) can register with the icp parent.
Right now this callback allows the children to adjust their notion of
how many command openings are available.
* Add a mutex around the icp ioctl handler, allowing only one thread
to execute an ioctl at a time.
* Add a way to freeze the controller command queue. We stop all I/O
while processing rescans (due to the semantics of icp_cmd()).
* Make icp_cmd() work when !cold.
* Add detach support to ld@icp.
 1.7 13-May-2003  thorpej Add support for the user-generated command interface and event logging
required by the ICP-Vortex management tools. Many thanks to Achim Leubner
at ICP-Vortex for a few bug fixes and for testing.
 1.6 02-Oct-2002  thorpej Add trailing ; to CFATTACH_DECL.
 1.5 30-Sep-2002  thorpej Use CFATTACH_DECL().
 1.4 27-Sep-2002  thorpej Declare all cfattach structures const.
 1.3 27-Sep-2002  provos remove trailing \n in panic(). approved perry.
 1.2 25-Apr-2002  ad branches: 1.2.6; 1.2.8;
Set xs->error = XS_SENSE in the appropriate spot.
 1.1 22-Apr-2002  ad Add a driver for ICP-Vortex GDT and Intel Storage RAID controllers. Parts
taken from OpenBSD. Test hardware kindly provided by Intel. This still needs
management bits, and doesn't support older controllers, but that shouldn't
be hard to fix.
 1.2.8.3 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.2.8.2 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.2.8.1 25-Apr-2002  jdolecek file icpsp.c was added on branch kqueue on 2002-06-23 17:46:28 +0000
 1.2.6.3 18-Oct-2002  nathanw Catch up to -current.
 1.2.6.2 20-Jun-2002  nathanw Catch up to -current.
 1.2.6.1 25-Apr-2002  nathanw file icpsp.c was added on branch nathanw_sa on 2002-06-20 03:44:41 +0000
 1.8.2.4 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.8.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.8.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.8.2.1 03-Aug-2004  skrll Sync with HEAD
 1.9.10.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.9.8.1 29-Apr-2005  kent sync with -current
 1.11.4.5 21-Jan-2008  yamt sync with head
 1.11.4.4 27-Oct-2007  yamt sync with head.
 1.11.4.3 03-Sep-2007  yamt sync with head.
 1.11.4.2 30-Dec-2006  yamt sync with head.
 1.11.4.1 21-Jun-2006  yamt sync with head.
 1.12.2.1 01-Feb-2006  yamt sync with head.
 1.13.10.1 28-Mar-2006  tron Merge 2006-03-28 NetBSD-current into the "peter-altq" branch.
 1.13.8.1 19-Apr-2006  elad sync with head.
 1.13.6.1 01-Apr-2006  yamt sync with head.
 1.13.4.1 22-Apr-2006  simonb Sync with head.
 1.13.2.1 09-Sep-2006  rpaulo sync with head
 1.14.10.2 10-Dec-2006  yamt sync with head.
 1.14.10.1 22-Oct-2006  yamt sync with head
 1.14.8.1 18-Nov-2006  ad Sync with head.
 1.16.4.1 12-Mar-2007  rmind Sync with HEAD.
 1.17.20.1 25-Oct-2007  bouyer Sync with HEAD.
 1.17.16.2 09-Jan-2008  matt sync with HEAD
 1.17.16.1 06-Nov-2007  matt sync with HEAD
 1.17.14.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.17.2.1 23-Oct-2007  ad Sync with head.
 1.18.8.1 08-Jan-2008  bouyer Sync with HEAD
 1.18.2.1 18-Feb-2008  mjf Sync with HEAD.
 1.19.6.1 02-Jun-2008  mjf Sync with HEAD.
 1.20.4.2 16-May-2009  yamt sync with head
 1.20.4.1 16-May-2008  yamt sync with head.
 1.20.2.1 18-May-2008  yamt sync with head.
 1.21.14.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.23.4.1 05-Mar-2011  rmind sync with head
 1.24.18.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.24.18.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.24.8.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.24.8.1 30-Oct-2012  yamt sync with head
 1.25.2.1 18-May-2014  rmind sync with head
 1.26.46.1 21-Mar-2021  thorpej Give config_found() the same variadic arguments treatment as
config_search(). This commit only adds the CFARG_EOL sentinel
to the existing config_found() calls. Conversion of config_found_sm_loc()
and config_found_ia() call sites will be in subsequent commits.
 1.27.8.1 04-Aug-2021  thorpej Adapt to CFARGS().
 1.13 27-Oct-2012  chs split device_t/softc for all remaining drivers.
replace "struct device *" with "device_t".
use device_xname(), device_unit(), etc.
 1.12 12-May-2009  cegger branches: 1.12.12; 1.12.22;
struct device * -> device_t, no functional changes intended.
 1.11 29-Jan-2009  bouyer branches: 1.11.2;
As ic_ident is from 2 to ICP_NCCBS + 2, we need more than just ICP_NCCBS
sense structures in icp_scr map; otherwise we'll compute an offset past the
allocated memory (and past the end of the dmap map) from the ic_ident.
To be safe use ICP_NCCB_RESERVE instead of 2; as I'm not sure why
ICP_NCCB_RESERVE is 4.
 1.10 28-Apr-2008  martin branches: 1.10.8; 1.10.10;
Remove clause 3 and 4 from TNF licenses
 1.9 11-Mar-2007  ad branches: 1.9.34; 1.9.36; 1.9.38;
Remove a use of lockmgr/LOCK_INITIALIZER.
 1.8 04-Mar-2007  christos branches: 1.8.2;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.7 11-Dec-2005  christos branches: 1.7.26;
merge ktrace-lwp.
 1.6 27-Feb-2005  perry branches: 1.6.4;
nuke trailing whitespace
 1.5 21-Feb-2005  thorpej Part 1 of a cleanup pass over the SCSI subsystem. The aim is to name
everything "scsi_*", since we really are talking about the SCSI command
set, ATAPI transport not withstanding. Improve the names of many structures,
and prepend "SCSI_" onto all SCSI command opcodes. Place items described
by the SCSI Primary Commands document into scsi_spc.h.
 1.4 13-Sep-2004  drochner branches: 1.4.4; 1.4.6;
a round of autoconf cleanup:
-convert submatch() style functions (passed to config_search() or
config_found_sm()) to the locator passing variants
-pass interface attributes in some cases
-make submatch() functions look uniformly as far as possible
-avoid macros which just hide cfdata members, and reduce dependencies
on "locators.h"
 1.3 13-Jun-2003  thorpej branches: 1.3.2;
Add support for dynamic rescan of cache service logical drives, using
the ioctl issued by the ICP RAID management libraries (used by the
storcon and iirconfig tools). This requires some infrastructure changes:
* Add a "service callback" mechanism that the ld driver (cache service)
and the iopsp driver (raw service) can register with the icp parent.
Right now this callback allows the children to adjust their notion of
how many command openings are available.
* Add a mutex around the icp ioctl handler, allowing only one thread
to execute an ioctl at a time.
* Add a way to freeze the controller command queue. We stop all I/O
while processing rescans (due to the semantics of icp_cmd()).
* Make icp_cmd() work when !cold.
* Add detach support to ld@icp.
 1.2 13-May-2003  thorpej Add support for the user-generated command interface and event logging
required by the ICP-Vortex management tools. Many thanks to Achim Leubner
at ICP-Vortex for a few bug fixes and for testing.
 1.1 22-Apr-2002  ad branches: 1.1.6; 1.1.8;
Add a driver for ICP-Vortex GDT and Intel Storage RAID controllers. Parts
taken from OpenBSD. Test hardware kindly provided by Intel. This still needs
management bits, and doesn't support older controllers, but that shouldn't
be hard to fix.
 1.1.8.2 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.1.8.1 22-Apr-2002  jdolecek file icpvar.h was added on branch kqueue on 2002-06-23 17:46:29 +0000
 1.1.6.2 20-Jun-2002  nathanw Catch up to -current.
 1.1.6.1 22-Apr-2002  nathanw file icpvar.h was added on branch nathanw_sa on 2002-06-20 03:44:41 +0000
 1.3.2.3 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.3.2.2 21-Sep-2004  skrll Fix the sync with head I botched.
 1.3.2.1 18-Sep-2004  skrll Sync with HEAD.
 1.4.6.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.4.4.1 29-Apr-2005  kent sync with -current
 1.6.4.1 03-Sep-2007  yamt sync with head.
 1.7.26.1 12-Mar-2007  rmind Sync with HEAD.
 1.8.2.1 13-Mar-2007  ad Sync with head.
 1.9.38.3 16-May-2009  yamt sync with head
 1.9.38.2 04-May-2009  yamt sync with head.
 1.9.38.1 16-May-2008  yamt sync with head.
 1.9.36.1 18-May-2008  yamt sync with head.
 1.9.34.1 02-Jun-2008  mjf Sync with HEAD.
 1.10.10.1 02-Feb-2009  snj Pull up following revision(s) (requested by bouyer in ticket #375):
sys/dev/ic/icpvar.h: revision 1.11
As ic_ident is from 2 to ICP_NCCBS + 2, we need more than just ICP_NCCBS
sense structures in icp_scr map; otherwise we'll compute an offset past the
allocated memory (and past the end of the dmap map) from the ic_ident.
To be safe use ICP_NCCB_RESERVE instead of 2; as I'm not sure why
ICP_NCCB_RESERVE is 4.
 1.10.8.1 03-Mar-2009  skrll Sync with HEAD.
 1.11.2.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.12.22.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.12.12.1 30-Oct-2012  yamt sync with head
 1.7 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.6 11-Dec-2005  christos branches: 1.6.70; 1.6.72; 1.6.74;
merge ktrace-lwp.
 1.5 27-Feb-2005  perry nuke trailing whitespace
 1.4 09-Oct-1997  jtc branches: 1.4.50; 1.4.58; 1.4.60;
Fix tipo inherited from old version of TNF copyright template.
 1.3 05-Feb-1996  jtc branches: 1.3.12;
Fix error in copyright notice
 1.2 05-Feb-1996  jtc Received copyright assignment
 1.1 19-Jul-1995  brezak GUS audio driver from John Kohl.
 1.3.12.1 14-Oct-1997  thorpej Update marc-pcmcia branch from trunk.
 1.4.60.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.4.58.1 29-Apr-2005  kent sync with -current
 1.4.50.1 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.6.74.1 16-May-2008  yamt sync with head.
 1.6.72.1 18-May-2008  yamt sync with head.
 1.6.70.1 02-Jun-2008  mjf Sync with HEAD.
 1.5 07-Jan-2023  msaitoh Whitespace. No functional change.
 1.4 26-Mar-2022  riastradh branches: 1.4.4;
igpio(4): Use device_xname, not struct device members.
 1.3 26-Mar-2022  riastradh igpio(4): Nix trailing whitespace.

(setq show-trailing-whitespace t), M-x delete-trailing-whitespace
 1.2 24-Mar-2022  andvar s/interupt/interrupt/ in comments.
also add missing RCS ID in bcm53xx_reg.h and fix one more typo in there.
 1.1 24-Mar-2022  manu Add initial support for Intel GPIO chips
 1.4.4.1 23-Jan-2023  martin Pull up following revision(s) (requested by msaitoh in ticket #53):

sys/dev/ic/igpio.c: revision 1.5
sys/dev/ic/igpioreg.h: revision 1.3
sys/dev/ic/igpioreg.h: revision 1.4
sys/dev/ic/igpioreg.h: revision 1.5
sys/dev/ic/igpioreg.h: revision 1.6
sys/dev/ic/igpioreg.h: revision 1.7
sys/dev/ic/igpioreg.h: revision 1.8
sys/dev/ic/igpiovar.h: revision 1.2
share/man/man4/igpio.4: revision 1.3

Fix entries for Lewisburg.

One more fix for Lewisburg.

Modify comment. Whitespace. No functional change.

Whitespace. No functional change.

Whitespace. No functional change.

Move entries of Alder Lake-S and Tiger Lake-LP. No functional change.

igpio: Update pin definitions.
- Add Ice Lake-N(INT34C3)
- Add Raptor Lake-S(INTC1085).
- Add another Baytrail(INT33FC).
- Modify INTC1057. It was for Tiger Lake-LP and reused for Alder Lake-N.
- Fix pin group definitions for Sunrisepoint-LP, Tiger Lake-LP, Tiger Lake-H,
Alder Lake-P and Lewisburg.
- Modify pin group names for Coffee Lake-S, Sunrisepoint-H, Cannon Lake-LP
and Denverton.
- Add two missing entries to Ice Lake-LP's pin group table.
- Modify comment. INT3455 is Ice Lake-LP.
- Add comment.

igpio.4: Update list of supported devices.
 1.8 07-Jan-2023  msaitoh igpio: Update pin definitions.

- Add Ice Lake-N(INT34C3)
- Add Raptor Lake-S(INTC1085).
- Add another Baytrail(INT33FC).
- Modify INTC1057. It was for Tiger Lake-LP and reused for Alder Lake-N.
- Fix pin group definitions for Sunrisepoint-LP, Tiger Lake-LP, Tiger Lake-H,
Alder Lake-P and Lewisburg.
- Modify pin group names for Coffee Lake-S, Sunrisepoint-H, Cannon Lake-LP
and Denverton.
- Add two missing entries to Ice Lake-LP's pin group table.
- Modify comment. INT3455 is Ice Lake-LP.
- Add comment.
 1.7 07-Jan-2023  msaitoh Move entries of Alder Lake-S and Tiger Lake-LP. No functional change.
 1.6 07-Jan-2023  msaitoh Whitespace. No functional change.
 1.5 07-Jan-2023  msaitoh Modify comment. Whitespace. No functional change.
 1.4 07-Jan-2023  msaitoh One more fix for Lewisburg.
 1.3 07-Jan-2023  msaitoh Fix entries for Lewisburg.
 1.2 26-Mar-2022  riastradh branches: 1.2.4;
igpio(4): Nix trailing whitespace.

(setq show-trailing-whitespace t), M-x delete-trailing-whitespace
 1.1 24-Mar-2022  manu Add initial support for Intel GPIO chips
 1.2.4.1 23-Jan-2023  martin Pull up following revision(s) (requested by msaitoh in ticket #53):

sys/dev/ic/igpio.c: revision 1.5
sys/dev/ic/igpioreg.h: revision 1.3
sys/dev/ic/igpioreg.h: revision 1.4
sys/dev/ic/igpioreg.h: revision 1.5
sys/dev/ic/igpioreg.h: revision 1.6
sys/dev/ic/igpioreg.h: revision 1.7
sys/dev/ic/igpioreg.h: revision 1.8
sys/dev/ic/igpiovar.h: revision 1.2
share/man/man4/igpio.4: revision 1.3

Fix entries for Lewisburg.

One more fix for Lewisburg.

Modify comment. Whitespace. No functional change.

Whitespace. No functional change.

Whitespace. No functional change.

Move entries of Alder Lake-S and Tiger Lake-LP. No functional change.

igpio: Update pin definitions.
- Add Ice Lake-N(INT34C3)
- Add Raptor Lake-S(INTC1085).
- Add another Baytrail(INT33FC).
- Modify INTC1057. It was for Tiger Lake-LP and reused for Alder Lake-N.
- Fix pin group definitions for Sunrisepoint-LP, Tiger Lake-LP, Tiger Lake-H,
Alder Lake-P and Lewisburg.
- Modify pin group names for Coffee Lake-S, Sunrisepoint-H, Cannon Lake-LP
and Denverton.
- Add two missing entries to Ice Lake-LP's pin group table.
- Modify comment. INT3455 is Ice Lake-LP.
- Add comment.

igpio.4: Update list of supported devices.
 1.2 07-Jan-2023  msaitoh Whitespace. No functional change.
 1.1 24-Mar-2022  manu branches: 1.1.4;
Add initial support for Intel GPIO chips
 1.1.4.1 23-Jan-2023  martin Pull up following revision(s) (requested by msaitoh in ticket #53):

sys/dev/ic/igpio.c: revision 1.5
sys/dev/ic/igpioreg.h: revision 1.3
sys/dev/ic/igpioreg.h: revision 1.4
sys/dev/ic/igpioreg.h: revision 1.5
sys/dev/ic/igpioreg.h: revision 1.6
sys/dev/ic/igpioreg.h: revision 1.7
sys/dev/ic/igpioreg.h: revision 1.8
sys/dev/ic/igpiovar.h: revision 1.2
share/man/man4/igpio.4: revision 1.3

Fix entries for Lewisburg.

One more fix for Lewisburg.

Modify comment. Whitespace. No functional change.

Whitespace. No functional change.

Whitespace. No functional change.

Move entries of Alder Lake-S and Tiger Lake-LP. No functional change.

igpio: Update pin definitions.
- Add Ice Lake-N(INT34C3)
- Add Raptor Lake-S(INTC1085).
- Add another Baytrail(INT33FC).
- Modify INTC1057. It was for Tiger Lake-LP and reused for Alder Lake-N.
- Fix pin group definitions for Sunrisepoint-LP, Tiger Lake-LP, Tiger Lake-H,
Alder Lake-P and Lewisburg.
- Modify pin group names for Coffee Lake-S, Sunrisepoint-H, Cannon Lake-LP
and Denverton.
- Add two missing entries to Ice Lake-LP's pin group table.
- Modify comment. INT3455 is Ice Lake-LP.
- Add comment.

igpio.4: Update list of supported devices.
 1.60 07-Aug-2021  thorpej Merge thorpej-cfargs2.
 1.59 24-Apr-2021  thorpej branches: 1.59.8;
Merge thorpej-cfargs branch:

Simplify and make extensible the config_search() / config_found() /
config_attach() interfaces: rather than having different variants for
which arguments you want pass along, just have a single call that
takes a variadic list of tag-value arguments.

Adjust all call sites:
- Simplify wherever possible; don't pass along arguments that aren't
actually needed.
- Don't be explicit about what interface attribute is attaching if
the device only has one. (More simplification.)
- Add a config_probe() function to be used in indirect configuiration
situations, making is visibly easier to see when indirect config is
in play, and allowing for future change in semantics. (As of now,
this is just a wrapper around config_match(), but that is an
implementation detail.)

Remove unnecessary or redundant interface attributes where they're not
needed.

There are currently 5 "cfargs" defined:
- CFARG_SUBMATCH (submatch function for direct config)
- CFARG_SEARCH (search function for indirect config)
- CFARG_IATTR (interface attribte)
- CFARG_LOCATORS (locators array)
- CFARG_DEVHANDLE (devhandle_t - wraps OFW, ACPI, etc. handles)

...and a sentinel value CFARG_EOL.

Add some extra sanity checking to ensure that interface attributes
aren't ambiguous.

Use CFARG_DEVHANDLE in MI FDT, OFW, and ACPI code, and macppc and shark
ports to associate those device handles with device_t instance. This
will trickle trough to more places over time (need back-end for pre-OFW
Sun OBP; any others?).
 1.58 14-Mar-2018  maya branches: 1.58.18;
Don't left shift a negative, use unsigned for bit masks.
Appeases GCC 6 in some build configuration (ALL kernel)

ok uwe
 1.57 24-Jan-2018  riastradh branches: 1.57.2;
Fix integer overflows noted by Silvio Cesare of InfoSect.

Someone^TM should name these idioms so we can eliminate this class of
copypasta bug.
 1.56 25-Jan-2017  jakllsch Improve/fix igsfb(4) support for 15BPP.

Use howmany(depth, NBBY) instead of (depth >> 3), so that 15 bits maps
to 2 bytes instead of 1.

While here, in a nearly-identical change, don't hard-code 8BPP into the
CyberPro blitter.
 1.55 25-Jan-2017  jakllsch Map coprocessor registers before igsfb_hw_setup(), they are needed for
setting up the video mode.
 1.54 25-Jan-2017  jakllsch igsfb(4): use WSDISPLAY_BORDER_COLOR for overscan color
 1.53 14-Jul-2016  msaitoh branches: 1.53.2; 1.53.4;
- Use aprint*() instead of printf() in xxx_attach().
- Add missing aprint_naive("\n");
- KNF
 1.52 11-Jan-2012  macallan branches: 1.52.6; 1.52.24;
wsfont_matches() and wsfont_find() take an extra parameter now
 1.51 11-Jan-2012  macallan use rasops_init(0, 0)
 1.50 26-Jul-2011  mrg branches: 1.50.2; 1.50.6;
convert to device_t, cfdata_t and CFATTACH_DECL_NEW.
 1.49 12-May-2010  macallan set RI_NO_AUTO then attaching early, clear it otherwise
 1.48 24-Dec-2009  elad branches: 1.48.2; 1.48.4;
Change a comment. INSECURE has but one purpose.
 1.47 18-Nov-2009  macallan Make colour depths higher than 8bit work in X.
Now igsfb will switch to 16 or 32 bit colour when entering graphics mode,
depending on available video memory and the given mode.
While there re-initialize the colour map etc. when leaving graphics mode.
 1.46 11-Nov-2009  macallan add modeseting support. Now if there's a mode string in igsfb_devconfig the
driver will try to use it if at all possible, otherwise fall back to the old
hardcoded 1024x768x60 mode.
 1.45 10-Nov-2009  macallan add support for an optional machine-dependent mmap() method, so the bus
backend can do whatever voodoo necessary to the aperture, IO space etc.
Mainly for shark, to get around the weird ARM bus_space.
 1.44 08-Apr-2008  cegger branches: 1.44.4;
use aprint_*_dev and device_xname
 1.43 19-Oct-2007  ad branches: 1.43.16;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.42 04-Mar-2007  christos branches: 1.42.2; 1.42.14; 1.42.16; 1.42.20;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.41 13-Jan-2007  cube branches: 1.41.2;
The definition of bus_space_vaddr on i386 makes it inappropriate as the
first argument to memset(), so change the code very slightly to workaround
that.
 1.40 18-Aug-2006  uwe branches: 1.40.2;
G/c unnecessary includes.
 1.39 20-May-2006  mrg initialise pos.x and pos.y to appease GCC4.
 1.38 12-Apr-2006  jmmv branches: 1.38.2;
Add an extra cookie to the ioctl and mmap wsdisplay accessops that points
to the screen on which they are being called. The driver cannot guess
this by itself but it is needed to implement, at least, the getwschar and
putwschar functions in the correct place. There are no functional changes
yet.

Tested on i386 (vga, vga_raster, machfb, vesafb), macppc and sparc64.
Suggested and reviewed by macallan@.
 1.37 05-Apr-2006  uwe KNF: no parentheses around return value.
 1.36 05-Apr-2006  uwe ANSI'ify.
 1.35 04-Apr-2006  uwe Add dc_stride member to igsfb_devconfig.

Eliminate all mentions of rasops_info from igsfb_ioctl(), we have all
the information in igsfb_devconfig now. It's semantically correct to
serve that info from there, not from a cached copy in rasops_info.
 1.34 04-Apr-2006  uwe Use bus_space_vaddr() to get the address of the framebuffer.
 1.33 04-Apr-2006  uwe Use designated initializers for wsscreen structs. It takes less space
and is easier to read. While here, update function name in comment.
 1.32 04-Apr-2006  uwe Nuke delay() that sneaked in with one of old revisions. It's not
necessary.

When we attach as console on netwinder, the timer is not yet attached,
so delay() resorts to a busy loop. That loop takes BIGNUM seconds(!)
to complete. That makes you think the machine wedged.
 1.31 03-Apr-2006  uwe Fix indentation nits.
 1.30 03-Apr-2006  uwe Honor RI_FULLCLEAR in igsfb_accel_eraserows.
 1.29 03-Apr-2006  uwe Properly fix cursor sprite endianness problems: always build
cc_sprite[] in little-endian, as that's how the card wants it.

Tested on netwinder (hardware bswap) by myself, and on current krups
kernel (no bswap) and 3.0 krups kernel (software bswap) by macallan.
 1.28 24-Feb-2006  macallan branches: 1.28.2; 1.28.4; 1.28.6;
clear the whole screen on startup, fix an endianness mismatch when creating
the cursor sprite - this needs to be tested ( and probably fixed ) on a
netwinder.
 1.27 23-Feb-2006  macallan Add support for virtual consoles to igsfb.
Works fine on a Krups, needs testing on other ports.
 1.26 11-Dec-2005  christos branches: 1.26.2; 1.26.4; 1.26.6;
merge ktrace-lwp.
 1.25 01-Oct-2005  macallan revert unnecessary geometry changes, add missing {} so turning off the
cursor when leaving emulation mode and getting it back when re-entering really
works now.
 1.24 30-Sep-2005  uwe Minor KNF police.
 1.23 30-Sep-2005  macallan - turn off the hardware cursor when leaving WSDISPLAYIO_MODE_EMUL
- only lock the hardware cursor when not in WSDISPLAYIO_MODE_EMUL
- allow cursor position between 0 and (screen width + max. cursor width - 1),
same for height so it can move partially offscreen in all directions
 1.22 12-Sep-2005  macallan add a blank line before case WSDISPLAYIO_LINEBYTES
 1.21 12-Sep-2005  macallan add ioctl(WSDISPLAYIO_LINEBYTES) - needed by XFree's wsfb
 1.20 27-Feb-2005  perry branches: 1.20.4;
nuke trailing whitespace
 1.19 26-Nov-2004  uwe branches: 1.19.4; 1.19.6;
Use standard uintN_t types instead of home-grown u_intN_t types.
 1.18 26-Nov-2004  uwe Fix several typos in comments.
 1.17 13-Nov-2003  chs eliminate uvm_useracc() in favor of checking the return value of
copyin() or copyout().

uvm_useracc() tells us whether the mapping permissions allow access to
the desired part of an address space, and many callers assume that
this is the same as knowing whether an attempt to access that part of
the address space will succeed. however, access to user space can
fail for reasons other than insufficient permission, most notably that
paging in any non-resident data can fail due to i/o errors. most of
the callers of uvm_useracc() make the above incorrect assumption. the
rest are all misguided optimizations, which optimize for the case
where an operation will fail. we'd rather optimize for operations
succeeding, in which case we should just attempt the access and handle
failures due to insufficient permissions the same way we handle i/o
errors. since there appear to be no good uses of uvm_useracc(), we'll
just remove it.
 1.16 07-Nov-2003  uwe Supress bogus -Wuninitialized warnings.
 1.15 31-Aug-2003  uwe Comment change only, the ioctl is WSDISPLAYIO_PUTCMAP, not ..._SETCMAP.
The function is called igsfb_set_cmap() to follow the get/set/update
naming convention.
 1.14 24-Jun-2003  uwe branches: 1.14.2;
Only install accelerated rasops for CyberPro, we don't know yet how to
access the coprocessor on 1682 in Krups.
 1.13 10-Jun-2003  uwe Correct calculation of the blit src/dst for blits we do backwards.
 1.12 31-May-2003  uwe Implement accelerated text ops using graphic coprocessor.
 1.11 11-May-2003  uwe Use hardware sprite for the text mode cursor.
Fail cursor related ioctls with EBUSY while in text mode.

Don't do uvm_useracc checks before copyout, instead check copyout()
return value directly.

Minor cleanups.
 1.10 10-May-2003  uwe Don't need a separate bit expansion table for the cursor mask.
 1.9 10-May-2003  uwe Enforce that the cursor position and the hot spot are within bounds.
Constify a bit. Fix unsignedness of a few local variables.
 1.8 10-May-2003  uwe Redo attachment to support proper cnattach.
wscons on netwinder almost works now.
 1.7 12-Jan-2003  uwe Quick patch to allow the (only) screen to be configured with
wsconscfg(8) when it's not being used as the console.
 1.6 24-Sep-2002  uwe Add some preliminary support for setting up the CyberPro in Netwinder.
Setup sequence obtained from Krups OFW with some CyberPro-specific
magic from Linux driver. The driver still has a lot of hardcoded
stuff, but it is useful enough to bring up wscons on netwinder.

XXX: Proper console attachment needs to be written (the driver was
originally developed on sparc, where our approach to attaching console
is totally different).

Caveat emptor!
 1.5 03-Aug-2002  itojun correct range check, have overflow check, fix type mismatches,
for cmap args and some other calls. from openbsd
 1.4 21-Jul-2002  uwe Add definitions of IGS coprocessor registers (not used yet).
Always init chip via I/O space.
Map only I/O registers we actually need.
Automatically detect if we need to do bswapping
Add (untested) code to use automagic bswap on CyberPro.
Report video memory amount.
Report if/how bswapping is done.
 1.3 04-Jul-2002  junyoung alloc_attr -> allocattr

Approved by Matthias Drochner.
 1.2 05-Apr-2002  uwe branches: 1.2.2; 1.2.4; 1.2.6; 1.2.8;
Clean up includes.
 1.1 30-Mar-2002  uwe First cut at framebuffer driver for Integraphics Systems IGA1682.
It's not finished yet, but it can do enough to get wscons working for
Krups JavaStation.
 1.2.8.4 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.2.8.3 06-Sep-2002  jdolecek sync kqueue branch with HEAD
 1.2.8.2 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.2.8.1 05-Apr-2002  jdolecek file igsfb.c was added on branch kqueue on 2002-06-23 17:46:29 +0000
 1.2.6.1 07-Aug-2002  lukem Pull up revision 1.5 (requested by itojun in ticket #616):
correct range check, have overflow check, fix type mismatches,
for cmap args and some other calls. from openbsd
 1.2.4.2 29-Aug-2002  gehenna catch up with -current.
 1.2.4.1 15-Jul-2002  gehenna catch up with -current.
 1.2.2.6 15-Jan-2003  thorpej Sync with HEAD.
 1.2.2.5 18-Oct-2002  nathanw Catch up to -current.
 1.2.2.4 13-Aug-2002  nathanw Catch up to -current.
 1.2.2.3 01-Aug-2002  nathanw Catch up to -current.
 1.2.2.2 17-Apr-2002  nathanw Catch up to -current.
 1.2.2.1 05-Apr-2002  nathanw file igsfb.c was added on branch nathanw_sa on 2002-04-17 00:05:38 +0000
 1.14.2.7 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.14.2.6 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.14.2.5 27-Jan-2005  skrll Adapt to branch.
 1.14.2.4 29-Nov-2004  skrll Sync with HEAD.
 1.14.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.14.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.14.2.1 03-Aug-2004  skrll Sync with HEAD
 1.19.6.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.19.4.1 29-Apr-2005  kent sync with -current
 1.20.4.5 27-Oct-2007  yamt sync with head.
 1.20.4.4 03-Sep-2007  yamt sync with head.
 1.20.4.3 26-Feb-2007  yamt sync with head.
 1.20.4.2 30-Dec-2006  yamt sync with head.
 1.20.4.1 21-Jun-2006  yamt sync with head.
 1.26.6.2 01-Jun-2006  kardel Sync with head.
 1.26.6.1 22-Apr-2006  simonb Sync with head.
 1.26.4.1 09-Sep-2006  rpaulo sync with head
 1.26.2.1 01-Mar-2006  yamt sync with head.
 1.28.6.1 24-May-2006  tron Merge 2006-05-24 NetBSD-current into the "peter-altq" branch.
 1.28.4.1 19-Apr-2006  elad sync with head.
 1.28.2.3 03-Sep-2006  yamt sync with head.
 1.28.2.2 24-May-2006  yamt sync with head.
 1.28.2.1 11-Apr-2006  yamt sync with head
 1.38.2.1 19-Jun-2006  chap Sync with head.
 1.40.2.1 01-Feb-2007  ad Sync with head.
 1.41.2.1 12-Mar-2007  rmind Sync with HEAD.
 1.42.20.1 25-Oct-2007  bouyer Sync with HEAD.
 1.42.16.1 06-Nov-2007  matt sync with HEAD
 1.42.14.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.42.2.1 23-Oct-2007  ad Sync with head.
 1.43.16.1 02-Jun-2008  mjf Sync with HEAD.
 1.44.4.2 11-Aug-2010  yamt sync with head.
 1.44.4.1 11-Mar-2010  yamt sync with head
 1.48.4.1 30-May-2010  rmind sync with head
 1.48.2.1 17-Aug-2010  uebayasi Sync with HEAD.
 1.50.6.1 18-Feb-2012  mrg merge to -current.
 1.50.2.1 17-Apr-2012  yamt sync with head
 1.52.24.2 05-Feb-2017  skrll Sync with HEAD
 1.52.24.1 05-Oct-2016  skrll Sync with HEAD
 1.52.6.1 03-Dec-2017  jdolecek update from HEAD
 1.53.4.1 21-Apr-2017  bouyer Sync with HEAD
 1.53.2.1 20-Mar-2017  pgoyette Sync with HEAD
 1.57.2.1 15-Mar-2018  pgoyette Synch with HEAD
 1.58.18.1 21-Mar-2021  thorpej Give config_found() the same variadic arguments treatment as
config_search(). This commit only adds the CFARG_EOL sentinel
to the existing config_found() calls. Conversion of config_found_sm_loc()
and config_found_ia() call sites will be in subsequent commits.
 1.59.8.1 04-Aug-2021  thorpej Adapt to CFARGS().
 1.15 03-Sep-2018  riastradh Rename min/max -> uimin/uimax for better honesty.

These functions are defined on unsigned int. The generic name
min/max should not silently truncate to 32 bits on 64-bit systems.
This is purely a name change -- no functional change intended.

HOWEVER! Some subsystems have

#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))

even though our standard name for that is MIN/MAX. Although these
may invite multiple evaluation bugs, these do _not_ cause integer
truncation.

To avoid `fixing' these cases, I first changed the name in libkern,
and then compile-tested every file where min/max occurred in order to
confirm that it failed -- and thus confirm that nothing shadowed
min/max -- before changing it.

I have left a handful of bootloaders that are too annoying to
compile-test, and some dead code:

cobalt ews4800mips hp300 hppa ia64 luna68k vax
acorn32/if_ie.c (not included in any kernels)
macppc/if_gm.c (superseded by gem(4))

It should be easy to fix the fallout once identified -- this way of
doing things fails safe, and the goal here, after all, is to _avoid_
silent integer truncations, not introduce them.

Maybe one day we can reintroduce min/max as type-generic things that
never silently truncate. But we should avoid doing that for a while,
so that existing code has a chance to be detected by the compiler for
conversion to uimin/uimax without changing the semantics until we can
properly audit it all. (Who knows, maybe in some cases integer
truncation is actually intended!)
 1.14 03-Apr-2017  christos branches: 1.14.12; 1.14.14;
PR/52136: David Binderman: Rewrite loop to fix bounds check.
 1.13 25-Jan-2017  jakllsch Improve/fix igsfb(4) support for 15BPP.

Use howmany(depth, NBBY) instead of (depth >> 3), so that 15 bits maps
to 2 bytes instead of 1.

While here, in a nearly-identical change, don't hard-code 8BPP into the
CyberPro blitter.
 1.12 18-Nov-2009  macallan branches: 1.12.22; 1.12.40; 1.12.44; 1.12.48;
Make colour depths higher than 8bit work in X.
Now igsfb will switch to 16 or 32 bit colour when entering graphics mode,
depending on available video memory and the given mode.
While there re-initialize the colour map etc. when leaving graphics mode.
 1.11 18-Nov-2009  macallan Write something more sane into the pixel format register - it's not pixel size
in bytes although that works in 8 and 16 bit colour depth.
While there do some magic number reduction.
 1.10 11-Nov-2009  macallan add modeseting support. Now if there's a mode string in igsfb_devconfig the
driver will try to use it if at all possible, otherwise fall back to the old
hardcoded 1024x768x60 mode.
 1.9 19-Oct-2007  ad branches: 1.9.20;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.8 05-Apr-2006  uwe branches: 1.8.18; 1.8.32; 1.8.34; 1.8.38;
KNF: no parentheses around return value.
 1.7 05-Apr-2006  uwe ANSI'ify.
 1.6 23-Feb-2006  macallan branches: 1.6.2; 1.6.4; 1.6.6;
Add support for virtual consoles to igsfb.
Works fine on a Krups, needs testing on other ports.
 1.5 11-Dec-2005  christos branches: 1.5.2; 1.5.4; 1.5.6;
merge ktrace-lwp.
 1.4 26-Nov-2004  uwe branches: 1.4.12;
Use standard uintN_t types instead of home-grown u_intN_t types.
 1.3 30-May-2003  uwe branches: 1.3.2;
Oops, do not disable coprocessor in igsfb_init_ext.
 1.2 10-May-2003  uwe Redo attachment to support proper cnattach.
wscons on netwinder almost works now.
 1.1 24-Sep-2002  uwe branches: 1.1.2; 1.1.4;
Add some preliminary support for setting up the CyberPro in Netwinder.
Setup sequence obtained from Krups OFW with some CyberPro-specific
magic from Linux driver. The driver still has a lot of hardcoded
stuff, but it is useful enough to bring up wscons on netwinder.

XXX: Proper console attachment needs to be written (the driver was
originally developed on sparc, where our approach to attaching console
is totally different).

Caveat emptor!
 1.1.4.2 18-Oct-2002  nathanw Catch up to -current.
 1.1.4.1 24-Sep-2002  nathanw file igsfb_subr.c was added on branch nathanw_sa on 2002-10-18 02:41:53 +0000
 1.1.2.2 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.1.2.1 24-Sep-2002  jdolecek file igsfb_subr.c was added on branch kqueue on 2002-10-10 18:39:01 +0000
 1.3.2.1 29-Nov-2004  skrll Sync with HEAD.
 1.4.12.2 27-Oct-2007  yamt sync with head.
 1.4.12.1 21-Jun-2006  yamt sync with head.
 1.5.6.1 22-Apr-2006  simonb Sync with head.
 1.5.4.1 09-Sep-2006  rpaulo sync with head
 1.5.2.1 01-Mar-2006  yamt sync with head.
 1.6.6.1 24-May-2006  tron Merge 2006-05-24 NetBSD-current into the "peter-altq" branch.
 1.6.4.1 19-Apr-2006  elad sync with head.
 1.6.2.1 11-Apr-2006  yamt sync with head
 1.8.38.1 25-Oct-2007  bouyer Sync with HEAD.
 1.8.34.1 06-Nov-2007  matt sync with HEAD
 1.8.32.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.8.18.1 23-Oct-2007  ad Sync with head.
 1.9.20.1 11-Mar-2010  yamt sync with head
 1.12.48.1 21-Apr-2017  bouyer Sync with HEAD
 1.12.44.2 26-Apr-2017  pgoyette Sync with HEAD
 1.12.44.1 20-Mar-2017  pgoyette Sync with HEAD
 1.12.40.2 28-Aug-2017  skrll Sync with HEAD
 1.12.40.1 05-Feb-2017  skrll Sync with HEAD
 1.12.22.1 03-Dec-2017  jdolecek update from HEAD
 1.14.14.1 10-Jun-2019  christos Sync with HEAD
 1.14.12.1 06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.9 31-Jul-2023  andvar fix typos in comments, mainly s/denomalized/denormalized/.
 1.8 11-Nov-2009  macallan add modeseting support. Now if there's a mode string in igsfb_devconfig the
driver will try to use it if at all possible, otherwise fall back to the old
hardcoded 1024x768x60 mode.
 1.7 11-Dec-2005  christos branches: 1.7.74;
merge ktrace-lwp.
 1.6 27-Feb-2005  perry nuke trailing whitespace
 1.5 02-Nov-2003  wiz branches: 1.5.8; 1.5.10;
Fix some typos. From Tom Cosgrove via jmc@openbsd.
 1.4 31-May-2003  uwe branches: 1.4.2;
Correct coprocessor registers base.
Feh, manuals that lie...
 1.3 24-Sep-2002  uwe Add some preliminary support for setting up the CyberPro in Netwinder.
Setup sequence obtained from Krups OFW with some CyberPro-specific
magic from Linux driver. The driver still has a lot of hardcoded
stuff, but it is useful enough to bring up wscons on netwinder.

XXX: Proper console attachment needs to be written (the driver was
originally developed on sparc, where our approach to attaching console
is totally different).

Caveat emptor!
 1.2 21-Jul-2002  uwe Add definitions of IGS coprocessor registers (not used yet).
Always init chip via I/O space.
Map only I/O registers we actually need.
Automatically detect if we need to do bswapping
Add (untested) code to use automagic bswap on CyberPro.
Report video memory amount.
Report if/how bswapping is done.
 1.1 30-Mar-2002  uwe branches: 1.1.2; 1.1.4; 1.1.8;
First cut at framebuffer driver for Integraphics Systems IGA1682.
It's not finished yet, but it can do enough to get wscons working for
Krups JavaStation.
 1.1.8.4 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.1.8.3 06-Sep-2002  jdolecek sync kqueue branch with HEAD
 1.1.8.2 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.1.8.1 30-Mar-2002  jdolecek file igsfbreg.h was added on branch kqueue on 2002-06-23 17:46:30 +0000
 1.1.4.1 29-Aug-2002  gehenna catch up with -current.
 1.1.2.4 18-Oct-2002  nathanw Catch up to -current.
 1.1.2.3 01-Aug-2002  nathanw Catch up to -current.
 1.1.2.2 17-Apr-2002  nathanw Catch up to -current.
 1.1.2.1 30-Mar-2002  nathanw file igsfbreg.h was added on branch nathanw_sa on 2002-04-17 00:05:38 +0000
 1.4.2.4 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.4.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.4.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.4.2.1 03-Aug-2004  skrll Sync with HEAD
 1.5.10.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.5.8.1 29-Apr-2005  kent sync with -current
 1.7.74.1 11-Mar-2010  yamt sync with head
 1.20 26-Jul-2011  mrg convert to device_t, cfdata_t and CFATTACH_DECL_NEW.
 1.19 18-Nov-2009  macallan Make colour depths higher than 8bit work in X.
Now igsfb will switch to 16 or 32 bit colour when entering graphics mode,
depending on available video memory and the given mode.
While there re-initialize the colour map etc. when leaving graphics mode.
 1.18 11-Nov-2009  macallan add modeseting support. Now if there's a mode string in igsfb_devconfig the
driver will try to use it if at all possible, otherwise fall back to the old
hardcoded 1024x768x60 mode.
 1.17 10-Nov-2009  macallan add support for an optional machine-dependent mmap() method, so the bus
backend can do whatever voodoo necessary to the aperture, IO space etc.
Mainly for shark, to get around the weird ARM bus_space.
 1.16 05-Apr-2006  uwe branches: 1.16.62;
KNF: no parentheses around return value.
 1.15 05-Apr-2006  uwe ANSI'ify.
 1.14 04-Apr-2006  uwe Add dc_stride member to igsfb_devconfig.

Eliminate all mentions of rasops_info from igsfb_ioctl(), we have all
the information in igsfb_devconfig now. It's semantically correct to
serve that info from there, not from a cached copy in rasops_info.
 1.13 23-Feb-2006  macallan branches: 1.13.2; 1.13.4; 1.13.6;
Add support for virtual consoles to igsfb.
Works fine on a Krups, needs testing on other ports.
 1.12 16-Feb-2006  perry Change "inline" back to "__inline" in .h files -- C99 is still too
new, and some apps compile things in C89 mode. C89 keywords stay.

As per core@.
 1.11 24-Dec-2005  perry branches: 1.11.2; 1.11.4; 1.11.6;
__inline__ -> inline
 1.10 11-Dec-2005  christos merge ktrace-lwp.
 1.9 26-Nov-2004  uwe branches: 1.9.12;
Use standard uintN_t types instead of home-grown u_intN_t types.
 1.8 31-May-2003  uwe branches: 1.8.2;
Implement accelerated text ops using graphic coprocessor.
 1.7 11-May-2003  uwe Use hardware sprite for the text mode cursor.
Fail cursor related ioctls with EBUSY while in text mode.

Don't do uvm_useracc checks before copyout, instead check copyout()
return value directly.

Minor cleanups.
 1.6 10-May-2003  uwe Don't need a separate bit expansion table for the cursor mask.
 1.5 10-May-2003  uwe Redo attachment to support proper cnattach.
wscons on netwinder almost works now.
 1.4 12-Jan-2003  uwe Quick patch to allow the (only) screen to be configured with
wsconscfg(8) when it's not being used as the console.
 1.3 24-Sep-2002  uwe Add some preliminary support for setting up the CyberPro in Netwinder.
Setup sequence obtained from Krups OFW with some CyberPro-specific
magic from Linux driver. The driver still has a lot of hardcoded
stuff, but it is useful enough to bring up wscons on netwinder.

XXX: Proper console attachment needs to be written (the driver was
originally developed on sparc, where our approach to attaching console
is totally different).

Caveat emptor!
 1.2 21-Jul-2002  uwe Add definitions of IGS coprocessor registers (not used yet).
Always init chip via I/O space.
Map only I/O registers we actually need.
Automatically detect if we need to do bswapping
Add (untested) code to use automagic bswap on CyberPro.
Report video memory amount.
Report if/how bswapping is done.
 1.1 30-Mar-2002  uwe branches: 1.1.2; 1.1.4; 1.1.8;
First cut at framebuffer driver for Integraphics Systems IGA1682.
It's not finished yet, but it can do enough to get wscons working for
Krups JavaStation.
 1.1.8.4 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.1.8.3 06-Sep-2002  jdolecek sync kqueue branch with HEAD
 1.1.8.2 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.1.8.1 30-Mar-2002  jdolecek file igsfbvar.h was added on branch kqueue on 2002-06-23 17:46:30 +0000
 1.1.4.1 29-Aug-2002  gehenna catch up with -current.
 1.1.2.5 15-Jan-2003  thorpej Sync with HEAD.
 1.1.2.4 18-Oct-2002  nathanw Catch up to -current.
 1.1.2.3 01-Aug-2002  nathanw Catch up to -current.
 1.1.2.2 17-Apr-2002  nathanw Catch up to -current.
 1.1.2.1 30-Mar-2002  nathanw file igsfbvar.h was added on branch nathanw_sa on 2002-04-17 00:05:39 +0000
 1.8.2.1 29-Nov-2004  skrll Sync with HEAD.
 1.9.12.1 21-Jun-2006  yamt sync with head.
 1.11.6.1 22-Apr-2006  simonb Sync with head.
 1.11.4.1 09-Sep-2006  rpaulo sync with head
 1.11.2.2 01-Mar-2006  yamt sync with head.
 1.11.2.1 18-Feb-2006  yamt sync with head.
 1.13.6.1 24-May-2006  tron Merge 2006-05-24 NetBSD-current into the "peter-altq" branch.
 1.13.4.1 19-Apr-2006  elad sync with head.
 1.13.2.1 11-Apr-2006  yamt sync with head
 1.16.62.1 11-Mar-2010  yamt sync with head
 1.46 17-Apr-2025  andvar s/valdid/valid/ and s/valdiation/validation/ in comments.
 1.45 07-Aug-2021  thorpej branches: 1.45.12;
Merge thorpej-cfargs2.
 1.44 24-Apr-2021  thorpej branches: 1.44.8;
Merge thorpej-cfargs branch:

Simplify and make extensible the config_search() / config_found() /
config_attach() interfaces: rather than having different variants for
which arguments you want pass along, just have a single call that
takes a variadic list of tag-value arguments.

Adjust all call sites:
- Simplify wherever possible; don't pass along arguments that aren't
actually needed.
- Don't be explicit about what interface attribute is attaching if
the device only has one. (More simplification.)
- Add a config_probe() function to be used in indirect configuiration
situations, making is visibly easier to see when indirect config is
in play, and allowing for future change in semantics. (As of now,
this is just a wrapper around config_match(), but that is an
implementation detail.)

Remove unnecessary or redundant interface attributes where they're not
needed.

There are currently 5 "cfargs" defined:
- CFARG_SUBMATCH (submatch function for direct config)
- CFARG_SEARCH (search function for indirect config)
- CFARG_IATTR (interface attribte)
- CFARG_LOCATORS (locators array)
- CFARG_DEVHANDLE (devhandle_t - wraps OFW, ACPI, etc. handles)

...and a sentinel value CFARG_EOL.

Add some extra sanity checking to ensure that interface attributes
aren't ambiguous.

Use CFARG_DEVHANDLE in MI FDT, OFW, and ACPI code, and macppc and shark
ports to associate those device handles with device_t instance. This
will trickle trough to more places over time (need back-end for pre-OFW
Sun OBP; any others?).
 1.43 10-Nov-2019  chs branches: 1.43.10;
in many device attach paths, allocate memory with M_WAITOK instead of M_NOWAIT
and remove code to handle failures that can no longer happen.
 1.42 24-May-2011  joerg branches: 1.42.56;
Kill redundant ()
 1.41 13-Nov-2010  uebayasi branches: 1.41.2;
Don't pull in the whole uvm(9) API to access only PAGE_SIZE and
some other constants. These are provided by sys/param.h now.
 1.40 14-May-2008  tsutsui branches: 1.40.20;
Normalize my licenses.
 1.39 03-May-2008  tsutsui branches: 1.39.2;
Change my mail address to netbsd.org one.
 1.38 12-Apr-2008  tsutsui branches: 1.38.2; 1.38.4;
Split device_t/softc.
 1.37 08-Apr-2008  cegger use aprint_*_dev and device_xname
 1.36 19-Oct-2007  ad branches: 1.36.16;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.35 04-Mar-2007  christos branches: 1.35.2; 1.35.14; 1.35.16; 1.35.20;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.34 21-May-2006  christos branches: 1.34.12;
void casts to functions whose return values are ignored.
 1.33 14-Apr-2006  christos branches: 1.33.2;
Coverity CID 1099: Don't deref NULL if !DIAGNOSTIC
 1.32 19-Mar-2006  rtr avoid deref of NULL
coverity 2436 / run 6
 1.31 24-Dec-2005  perry branches: 1.31.4; 1.31.6; 1.31.8; 1.31.10; 1.31.12;
Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.30 11-Dec-2005  christos merge ktrace-lwp.
 1.29 30-May-2005  christos branches: 1.29.2;
- add missing const
- fix variable shadowing
- remove unneeded casts
 1.28 21-Feb-2005  thorpej Part 1 of a cleanup pass over the SCSI subsystem. The aim is to name
everything "scsi_*", since we really are talking about the SCSI command
set, ATAPI transport not withstanding. Improve the names of many structures,
and prepend "SCSI_" onto all SCSI command opcodes. Place items described
by the SCSI Primary Commands document into scsi_spc.h.
 1.27 02-Jan-2005  tsutsui branches: 1.27.2; 1.27.4;
u_intNN_t -> uintNN_t
 1.26 07-Dec-2004  thorpej When checking the CDB length, check against the field in the SCB
that we're actually storing it to.

XXX Should be re-examined; this is not actually a hardware-constrained
size with this driver.
 1.25 25-Sep-2004  tsutsui Use ANSI function decls.
 1.24 02-Nov-2003  wiz branches: 1.24.4;
Fix some typos. From Tom Cosgrove via jmc@openbsd.
 1.23 19-Oct-2003  simonb Remove unreachable break after return and goto statements.
 1.22 03-May-2003  wiz branches: 1.22.2;
DMA, not dma nor Dma.
 1.21 20-Jan-2003  simonb The Double-Semi-Colon Police.
 1.20 08-Dec-2002  jmc Put back MSG_IDENTIFY_LUNMASK (renamed to just be within the IHA namespace.
The definitions were not the same between the scsi_messages file and this
definition so simply removing it here and letting the other one be used
results in incorrect behavior (regardless of whether it made the code
compile....)
 1.19 14-Nov-2002  tsutsui Sync with copyright verbiage update of OpenBSD's iha(4).
 1.18 27-Sep-2002  provos remove trailing \n in panic(). approved perry.
 1.17 05-Apr-2002  bouyer Implement mstohz() as discussed on tech-kern, and use it in SCSI drivers
to convert xs->timeout to callout() parameter.
 1.16 15-Mar-2002  tsutsui Remove an arg name in prototype declaration.
 1.15 09-Feb-2002  tsutsui - rename struct iha_scsi_req_q -> struct iha_scb
- reorder some functions
- some more cosmetics
 1.14 16-Dec-2001  tsutsui malloc() + memset() -> malloc() with M_ZERO flag
 1.13 18-Nov-2001  tsutsui - Use MI ADAPTER_REQ_SET_XFER_MODE callback.
- Nuke some magic numbers.
 1.12 17-Nov-2001  tsutsui - make sure to call bus_dmamap_unload() even after request sense
- fix usage of scb flags
- misc cleanup
 1.11 13-Nov-2001  lukem add/cleanup RCSID
 1.10 29-Sep-2001  tsutsui Calculate offsets of sglist dinamically rather than use an static array
because PAGE_SIZE is not constant on some ports.
 1.9 27-Sep-2001  tsutsui Remove iha_minphys() and use minphys() instead.
 1.8 27-Jul-2001  tsutsui branches: 1.8.2;
Fix some comments and remove an unused define. Partially from OpenBSD.
 1.7 27-Jul-2001  tsutsui Pull up some changes from OpenBSD's iha.c rev 1.6:
- rename tul_* functions/variables iha_* for consistency
- disable updating EEPROM routine, which does not work anyway
- make iha_rate_tbl[] const
 1.6 27-Jul-2001  tsutsui Pull up some changes from OpenBSD's iha.c rev 1.5:
- minor code cleanups
- rename some functions for better consistensy/clarity
- consolidate extended message generation into new function
- a couple of minor code clarifications to eliminate extra return
statements and make absolutely sure actscb is NULL during a reselect
 1.5 19-Jul-2001  thorpej Use BUS_DMA_READ and BUS_DMA_WRITE in some obvious places.
 1.4 07-Jul-2001  thorpej branches: 1.4.2;
bzero -> memset
 1.3 07-Jun-2001  thorpej branches: 1.3.2;
Don't clear a callout on a scsipi_xfer that has been scsipi_done()'d.
 1.2 05-Jun-2001  tsutsui Make some functions __inline.
 1.1 03-Jun-2001  tsutsui Add a driver for the Initio INIC-940/950 PCI SCSI controllers.
Based on OpenBSD's iha driver, and modified some structures by me.

Tested on arc, i386 and macppc.
 1.3.2.11 11-Dec-2002  thorpej Sync with HEAD.
 1.3.2.10 18-Oct-2002  nathanw Catch up to -current.
 1.3.2.9 17-Apr-2002  nathanw Catch up to -current.
 1.3.2.8 01-Apr-2002  nathanw Catch up to -current.
(CVS: It's not just a program. It's an adventure!)
 1.3.2.7 28-Feb-2002  nathanw Catch up to -current.
 1.3.2.6 08-Jan-2002  nathanw Catch up to -current.
 1.3.2.5 14-Nov-2001  nathanw Catch up to -current.
 1.3.2.4 08-Oct-2001  nathanw Catch up to -current.
 1.3.2.3 24-Aug-2001  nathanw Catch up with -current.
 1.3.2.2 21-Jun-2001  nathanw Catch up to -current.
 1.3.2.1 07-Jun-2001  nathanw file iha.c was added on branch nathanw_sa on 2001-06-21 20:02:35 +0000
 1.4.2.5 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.4.2.4 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.4.2.3 16-Mar-2002  jdolecek Catch up with -current.
 1.4.2.2 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.4.2.1 03-Aug-2001  lukem update to -current
 1.8.2.1 01-Oct-2001  fvdl Catch up with -current.
 1.22.2.8 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.22.2.7 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.22.2.6 17-Jan-2005  skrll Sync with HEAD.
 1.22.2.5 18-Dec-2004  skrll Sync with HEAD.
 1.22.2.4 19-Oct-2004  skrll Sync with HEAD
 1.22.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.22.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.22.2.1 03-Aug-2004  skrll Sync with HEAD
 1.24.4.1 02-Apr-2005  he Pull up revision 1.26 (requested by thorpej in ticket #1021):
When checking the CDB length, check against the field
in the SCB that we're actually storing it to.
 1.27.4.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.27.2.1 29-Apr-2005  kent sync with -current
 1.29.2.3 27-Oct-2007  yamt sync with head.
 1.29.2.2 03-Sep-2007  yamt sync with head.
 1.29.2.1 21-Jun-2006  yamt sync with head.
 1.31.12.2 24-May-2006  tron Merge 2006-05-24 NetBSD-current into the "peter-altq" branch.
 1.31.12.1 28-Mar-2006  tron Merge 2006-03-28 NetBSD-current into the "peter-altq" branch.
 1.31.10.1 19-Apr-2006  elad sync with head.
 1.31.8.2 24-May-2006  yamt sync with head.
 1.31.8.1 01-Apr-2006  yamt sync with head.
 1.31.6.2 01-Jun-2006  kardel Sync with head.
 1.31.6.1 22-Apr-2006  simonb Sync with head.
 1.31.4.1 09-Sep-2006  rpaulo sync with head
 1.33.2.1 19-Jun-2006  chap Sync with head.
 1.34.12.1 12-Mar-2007  rmind Sync with HEAD.
 1.35.20.1 25-Oct-2007  bouyer Sync with HEAD.
 1.35.16.1 06-Nov-2007  matt sync with HEAD
 1.35.14.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.35.2.1 23-Oct-2007  ad Sync with head.
 1.36.16.1 02-Jun-2008  mjf Sync with HEAD.
 1.38.4.1 16-May-2008  yamt sync with head.
 1.38.2.1 18-May-2008  yamt sync with head.
 1.39.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.40.20.2 31-May-2011  rmind sync with head
 1.40.20.1 05-Mar-2011  rmind sync with head
 1.41.2.1 06-Jun-2011  jruoho Sync with HEAD.
 1.42.56.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.43.10.1 21-Mar-2021  thorpej Give config_found() the same variadic arguments treatment as
config_search(). This commit only adds the CFARG_EOL sentinel
to the existing config_found() calls. Conversion of config_found_sm_loc()
and config_found_ia() call sites will be in subsequent commits.
 1.44.8.1 04-Aug-2021  thorpej Adapt to CFARGS().
 1.45.12.1 02-Aug-2025  perseant Sync with HEAD
 1.9 03-May-2008  tsutsui Change my mail address to netbsd.org one.
 1.8 11-Dec-2005  christos branches: 1.8.70; 1.8.72; 1.8.74;
merge ktrace-lwp.
 1.7 02-Nov-2003  wiz Fix some typos. From Tom Cosgrove via jmc@openbsd.
 1.6 08-Dec-2002  jmc branches: 1.6.6;
Put back MSG_IDENTIFY_LUNMASK (renamed to just be within the IHA namespace.
The definitions were not the same between the scsi_messages file and this
definition so simply removing it here and letting the other one be used
results in incorrect behavior (regardless of whether it made the code
compile....)
 1.5 07-Dec-2002  tsutsui Remove local definition of MSG_IDENTIFY_LUNMASK, which is now defined in
MI dev/scsipi/scsi_message.h. Fixes kern/19313 from Lubomir Sedlacik.
 1.4 14-Nov-2002  tsutsui Sync with copyright verbiage update of OpenBSD's iha(4).
 1.3 17-Nov-2001  tsutsui - make sure to call bus_dmamap_unload() even after request sense
- fix usage of scb flags
- misc cleanup
 1.2 27-Jul-2001  tsutsui Fix some comments and remove an unused define. Partially from OpenBSD.
 1.1 03-Jun-2001  tsutsui branches: 1.1.2; 1.1.4;
Add a driver for the Initio INIC-940/950 PCI SCSI controllers.
Based on OpenBSD's iha driver, and modified some structures by me.

Tested on arc, i386 and macppc.
 1.1.4.2 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.1.4.1 03-Aug-2001  lukem update to -current
 1.1.2.5 11-Dec-2002  thorpej Sync with HEAD.
 1.1.2.4 08-Jan-2002  nathanw Catch up to -current.
 1.1.2.3 24-Aug-2001  nathanw Catch up with -current.
 1.1.2.2 21-Jun-2001  nathanw Catch up to -current.
 1.1.2.1 03-Jun-2001  nathanw file ihareg.h was added on branch nathanw_sa on 2001-06-21 20:02:36 +0000
 1.6.6.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.6.6.2 18-Sep-2004  skrll Sync with HEAD.
 1.6.6.1 03-Aug-2004  skrll Sync with HEAD
 1.8.74.1 16-May-2008  yamt sync with head.
 1.8.72.1 18-May-2008  yamt sync with head.
 1.8.70.1 02-Jun-2008  mjf Sync with HEAD.
 1.13 14-May-2008  tsutsui Normalize my licenses.
 1.12 03-May-2008  tsutsui branches: 1.12.2;
Change my mail address to netbsd.org one.
 1.11 12-Apr-2008  tsutsui branches: 1.11.2; 1.11.4;
Split device_t/softc.
 1.10 11-Dec-2005  christos branches: 1.10.70;
merge ktrace-lwp.
 1.9 02-Jan-2005  tsutsui u_intNN_t -> uintNN_t
 1.8 14-Nov-2002  tsutsui branches: 1.8.6;
Sync with copyright verbiage update of OpenBSD's iha(4).
 1.7 09-Feb-2002  tsutsui - rename struct iha_scsi_req_q -> struct iha_scb
- reorder some functions
- some more cosmetics
 1.6 17-Nov-2001  tsutsui - make sure to call bus_dmamap_unload() even after request sense
- fix usage of scb flags
- misc cleanup
 1.5 29-Sep-2001  tsutsui Calculate offsets of sglist dinamically rather than use an static array
because PAGE_SIZE is not constant on some ports.
 1.4 27-Sep-2001  tsutsui Adjust IHA_MAX_SG_ENTRIES since fragments of DMA buffer are not
more than (MAXPHYS / PAGE_SIZE + 1).
 1.3 27-Jul-2001  tsutsui branches: 1.3.2;
Fix some comments and remove an unused define. Partially from OpenBSD.
 1.2 09-Jun-2001  tsutsui branches: 1.2.2; 1.2.4;
Remove unused members from SCSI command block structure.
 1.1 03-Jun-2001  tsutsui Add a driver for the Initio INIC-940/950 PCI SCSI controllers.
Based on OpenBSD's iha driver, and modified some structures by me.

Tested on arc, i386 and macppc.
 1.2.4.3 16-Mar-2002  jdolecek Catch up with -current.
 1.2.4.2 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.2.4.1 03-Aug-2001  lukem update to -current
 1.2.2.7 11-Dec-2002  thorpej Sync with HEAD.
 1.2.2.6 28-Feb-2002  nathanw Catch up to -current.
 1.2.2.5 08-Jan-2002  nathanw Catch up to -current.
 1.2.2.4 08-Oct-2001  nathanw Catch up to -current.
 1.2.2.3 24-Aug-2001  nathanw Catch up with -current.
 1.2.2.2 21-Jun-2001  nathanw Catch up to -current.
 1.2.2.1 09-Jun-2001  nathanw file ihavar.h was added on branch nathanw_sa on 2001-06-21 20:02:37 +0000
 1.3.2.1 01-Oct-2001  fvdl Catch up with -current.
 1.8.6.1 17-Jan-2005  skrll Sync with HEAD.
 1.10.70.1 02-Jun-2008  mjf Sync with HEAD.
 1.11.4.1 16-May-2008  yamt sync with head.
 1.11.2.1 18-May-2008  yamt sync with head.
 1.12.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.13 27-Oct-2012  chs split device_t/softc for all remaining drivers.
replace "struct device *" with "device_t".
use device_xname(), device_unit(), etc.
 1.12 12-May-2009  cegger branches: 1.12.12; 1.12.22;
struct device * -> device_t, no functional changes intended.
 1.11 12-May-2009  cegger struct cfdata * -> cfdata_t, no functional changes intended.
 1.10 28-Apr-2008  martin branches: 1.10.14;
Remove clause 3 and 4 from TNF licenses
 1.9 08-Apr-2008  cegger branches: 1.9.2; 1.9.4;
use aprint_*_dev and device_xname
 1.8 19-Oct-2007  ad branches: 1.8.16;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.7 11-Dec-2005  christos branches: 1.7.30; 1.7.44; 1.7.46; 1.7.50;
merge ktrace-lwp.
 1.6 14-Jul-2003  lukem branches: 1.6.16;
add missing __KERNEL_RCSID()
 1.5 02-Oct-2002  thorpej branches: 1.5.6;
Add trailing ; to CFATTACH_DECL.
 1.4 30-Sep-2002  thorpej Use CFATTACH_DECL().
 1.3 27-Sep-2002  thorpej Declare all cfattach structures const.
 1.2 13-Jun-2002  augustss branches: 1.2.2; 1.2.4;
Use consistent naming.
 1.1 21-May-2002  augustss branches: 1.1.4;
Add a driver for the IBM CPC700 chip. This chip is a host bridge for
PowerPC and provides a PCI-host bridge, interrupt controller, two com ports,
two IIC ports, a timer, and a DRAM controller.
The driver supports PCI, interrupts and com ports.
 1.1.4.3 20-Jun-2002  gehenna catch up with -current.
 1.1.4.2 30-May-2002  gehenna Catch up with -current.
 1.1.4.1 21-May-2002  gehenna file iic_cpcbus.c was added on branch gehenna-devsw on 2002-05-30 14:45:42 +0000
 1.2.4.3 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.2.4.2 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.2.4.1 13-Jun-2002  jdolecek file iic_cpcbus.c was added on branch kqueue on 2002-06-23 17:46:32 +0000
 1.2.2.3 18-Oct-2002  nathanw Catch up to -current.
 1.2.2.2 20-Jun-2002  nathanw Catch up to -current.
 1.2.2.1 13-Jun-2002  nathanw file iic_cpcbus.c was added on branch nathanw_sa on 2002-06-20 03:44:42 +0000
 1.5.6.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.5.6.2 18-Sep-2004  skrll Sync with HEAD.
 1.5.6.1 03-Aug-2004  skrll Sync with HEAD
 1.6.16.1 27-Oct-2007  yamt sync with head.
 1.7.50.1 25-Oct-2007  bouyer Sync with HEAD.
 1.7.46.1 06-Nov-2007  matt sync with HEAD
 1.7.44.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.7.30.1 23-Oct-2007  ad Sync with head.
 1.8.16.1 02-Jun-2008  mjf Sync with HEAD.
 1.9.4.2 16-May-2009  yamt sync with head
 1.9.4.1 16-May-2008  yamt sync with head.
 1.9.2.1 18-May-2008  yamt sync with head.
 1.10.14.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.12.22.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.12.12.1 30-Oct-2012  yamt sync with head
 1.3 11-Dec-2005  christos merge ktrace-lwp.
 1.2 27-Feb-2005  perry nuke trailing whitespace
 1.1 28-Oct-1998  nisimura branches: 1.1.46; 1.1.54; 1.1.56;
- Brooktree Bt459 135 MHz Monolithic CMOS 256x64 Color Palette RAMDAC.
- Brooktree Bt431 Monolithic CMOS 64x64 Pixel Cursor Generator.
- Inmos IMS G332 Color Video Controller.
 1.1.56.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.1.54.1 29-Apr-2005  kent sync with -current
 1.1.46.1 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.14 07-Sep-2025  thorpej Change todr_chip_handle::cookie -> todr_chip_handle::todr_dev, and
make it a device_t. Upcoming functional changes will require the
device_t associated with a TODR device.

Change todr_chip_handle::bus_cookie -> todr_chip_handle::todr_devaux.
Nothing was using the old field, but I decided to keep it around just
in cause something needs it in the future.

And with these largely mechanical yet semantically meaningful changes,
thus spake the Oracle: "Welcome to NetBSD 11.99.2."
 1.13 07-Sep-2025  thorpej Remove unnecessary NULL-initialization of TODR handle fields.
 1.12 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.11 10-Jan-2008  tsutsui branches: 1.11.6; 1.11.8; 1.11.10;
Move todr_attach(9) calls from each MD attachment to MI intersil7170_attach().
 1.10 10-Jan-2008  tsutsui Use aprint_normal(9).
 1.9 19-Oct-2007  ad branches: 1.9.2; 1.9.8;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.8 04-Oct-2006  tsutsui branches: 1.8.8; 1.8.22; 1.8.24; 1.8.28;
Reorganize MI intersil7170(4) TOD clock driver:
- make intersil7170_softc more generic and allocate it during autoconf(9)
rather than MALLOC(9) in attachment
- put todr_chip_handle_t, year0 value, and the century adjustment flag
into the intersil7170_softc
- change the attachment function to just take the softc like mk48txx(4)
- split sys/dev/ic/intersil7170.h into intersil7170reg.h and intersil7170var.h
- cleanup some macro

Untested on real sun4 machines, but no objection on port-sparc
(and port-sun3) in three days.
 1.7 07-Sep-2006  gdamore branches: 1.7.2; 1.7.4;
Update to new friendlier todr entry points. While here, ANSIfy.
 1.6 04-Sep-2006  gdamore Remove unused todr_setcal/todr_getcal and all the assorted stub
implementations.
 1.5 11-Dec-2005  christos branches: 1.5.4; 1.5.8;
merge ktrace-lwp.
 1.4 04-Jun-2005  he branches: 1.4.2;
Fix the various todr_gettime() and todr_settime() fallouts from
-Wcast-qual differently, by instead changing the signatore of those
"functions" to take a "volatile struct timeval*" instead of a
"struct timeval*". Many places, these functions are called with
&time, and time is declared as volatile in <sys/kernel.h>. This
way we can get rid of all the ugly casts which now also triggered
warnings, and caused more code to be added to work around the
problem.

Reviewed by thorpej.
 1.3 05-Jul-2004  pk settime: round, instead of truncate, to the nearest second.
 1.2 13-Nov-2001  lukem branches: 1.2.16;
add/cleanup RCSID
 1.1 25-Jul-2000  pk branches: 1.1.2; 1.1.4; 1.1.6;
New time-of-day clock chip drivers. These implement the todr(9) interface.
 1.1.6.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.1.4.1 14-Nov-2001  nathanw Catch up to -current.
 1.1.2.2 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.1.2.1 25-Jul-2000  bouyer file intersil7170.c was added on branch thorpej_scsipi on 2000-11-20 11:40:37 +0000
 1.2.16.4 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.2.16.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.2.16.2 18-Sep-2004  skrll Sync with HEAD.
 1.2.16.1 03-Aug-2004  skrll Sync with HEAD
 1.4.2.3 21-Jan-2008  yamt sync with head
 1.4.2.2 27-Oct-2007  yamt sync with head.
 1.4.2.1 30-Dec-2006  yamt sync with head.
 1.5.8.1 14-Sep-2006  yamt sync with head.
 1.5.4.1 09-Sep-2006  rpaulo sync with head
 1.7.4.1 06-Oct-2006  tsutsui Sync files of recent sun3 and sun68k merge and intersil7170(4) changes
with HEAD to build sun3 kernel on this branch.
 1.7.2.1 18-Nov-2006  ad Sync with head.
 1.8.28.1 25-Oct-2007  bouyer Sync with HEAD.
 1.8.24.2 23-Mar-2008  matt sync with HEAD
 1.8.24.1 06-Nov-2007  matt sync with HEAD
 1.8.22.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.8.8.1 23-Oct-2007  ad Sync with head.
 1.9.8.1 10-Jan-2008  bouyer Sync with HEAD
 1.9.2.1 18-Feb-2008  mjf Sync with HEAD.
 1.11.10.1 16-May-2008  yamt sync with head.
 1.11.8.1 18-May-2008  yamt sync with head.
 1.11.6.1 02-Jun-2008  mjf Sync with HEAD.
 1.5 04-Oct-2006  tsutsui Reorganize MI intersil7170(4) TOD clock driver:
- make intersil7170_softc more generic and allocate it during autoconf(9)
rather than MALLOC(9) in attachment
- put todr_chip_handle_t, year0 value, and the century adjustment flag
into the intersil7170_softc
- change the attachment function to just take the softc like mk48txx(4)
- split sys/dev/ic/intersil7170.h into intersil7170reg.h and intersil7170var.h
- cleanup some macro

Untested on real sun4 machines, but no objection on port-sparc
(and port-sun3) in three days.
 1.4 11-Nov-2000  pk branches: 1.4.40; 1.4.70; 1.4.72;
Add note about time-of-day and interval timer programming on this chip
are combined into the same (write-only!) control register.
 1.3 03-Nov-2000  tsutsui Wrap function declaration with "#ifndef sun3/#endif"
because sun3 does not have bus_space(9) support and
it have not switched to MI intersil7170 driver.

XXX We should split this into intersil7170{reg,var}.h ?
 1.2 25-Jul-2000  pk New time-of-day clock chip drivers. These implement the todr(9) interface.
 1.1 02-May-1997  jeremy branches: 1.1.22;
Moved from arch/sun3/sun3 and changed according to implied references
in recent commits to sun3/clock.c and sun3x/clock.c by Gordon Ross.
 1.1.22.2 22-Nov-2000  bouyer Sync with HEAD.
 1.1.22.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.4.72.1 06-Oct-2006  tsutsui Sync files of recent sun3 and sun68k merge and intersil7170(4) changes
with HEAD to build sun3 kernel on this branch.
 1.4.70.1 18-Nov-2006  ad Sync with head.
 1.4.40.1 30-Dec-2006  yamt sync with head.
 1.2 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.1 04-Oct-2006  tsutsui branches: 1.1.2; 1.1.4; 1.1.8; 1.1.54; 1.1.56; 1.1.58;
Reorganize MI intersil7170(4) TOD clock driver:
- make intersil7170_softc more generic and allocate it during autoconf(9)
rather than MALLOC(9) in attachment
- put todr_chip_handle_t, year0 value, and the century adjustment flag
into the intersil7170_softc
- change the attachment function to just take the softc like mk48txx(4)
- split sys/dev/ic/intersil7170.h into intersil7170reg.h and intersil7170var.h
- cleanup some macro

Untested on real sun4 machines, but no objection on port-sparc
(and port-sun3) in three days.
 1.1.58.1 16-May-2008  yamt sync with head.
 1.1.56.1 18-May-2008  yamt sync with head.
 1.1.54.1 02-Jun-2008  mjf Sync with HEAD.
 1.1.8.2 30-Dec-2006  yamt sync with head.
 1.1.8.1 04-Oct-2006  yamt file intersil7170reg.h was added on branch yamt-lazymbuf on 2006-12-30 20:48:03 +0000
 1.1.4.2 18-Nov-2006  ad Sync with head.
 1.1.4.1 04-Oct-2006  ad file intersil7170reg.h was added on branch newlock2 on 2006-11-18 21:34:12 +0000
 1.1.2.2 06-Oct-2006  tsutsui Sync files of recent sun3 and sun68k merge and intersil7170(4) changes
with HEAD to build sun3 kernel on this branch.
 1.1.2.1 04-Oct-2006  tsutsui file intersil7170reg.h was added on branch yamt-splraiseipl on 2006-10-06 13:27:04 +0000
 1.4 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.3 29-Mar-2008  tsutsui branches: 1.3.2; 1.3.4;
Fix wrong type.
 1.2 28-Mar-2008  tsutsui Split device_t and softc for MI mk48txx(4) and intersil7170(4) clocks,
and other related misc cosmetics.
 1.1 04-Oct-2006  tsutsui branches: 1.1.2; 1.1.4; 1.1.8; 1.1.54;
Reorganize MI intersil7170(4) TOD clock driver:
- make intersil7170_softc more generic and allocate it during autoconf(9)
rather than MALLOC(9) in attachment
- put todr_chip_handle_t, year0 value, and the century adjustment flag
into the intersil7170_softc
- change the attachment function to just take the softc like mk48txx(4)
- split sys/dev/ic/intersil7170.h into intersil7170reg.h and intersil7170var.h
- cleanup some macro

Untested on real sun4 machines, but no objection on port-sparc
(and port-sun3) in three days.
 1.1.54.2 02-Jun-2008  mjf Sync with HEAD.
 1.1.54.1 03-Apr-2008  mjf Sync with HEAD.
 1.1.8.2 30-Dec-2006  yamt sync with head.
 1.1.8.1 04-Oct-2006  yamt file intersil7170var.h was added on branch yamt-lazymbuf on 2006-12-30 20:48:03 +0000
 1.1.4.2 18-Nov-2006  ad Sync with head.
 1.1.4.1 04-Oct-2006  ad file intersil7170var.h was added on branch newlock2 on 2006-11-18 21:34:12 +0000
 1.1.2.2 06-Oct-2006  tsutsui Sync files of recent sun3 and sun68k merge and intersil7170(4) changes
with HEAD to build sun3 kernel on this branch.
 1.1.2.1 04-Oct-2006  tsutsui file intersil7170var.h was added on branch yamt-splraiseipl on 2006-10-06 13:27:04 +0000
 1.3.4.1 16-May-2008  yamt sync with head.
 1.3.2.1 18-May-2008  yamt sync with head.
 1.44 05-Feb-2024  andvar triple "r" typos, mainly s/interrrupt/interrupt/ in comments and one definition.
 1.43 29-Feb-2020  isaki Remove rounding by 4 bytes on round_blocksize().
For drivers which supports only 16bit * 2channels sampling,
rounding by 4 bytes no longer meaningful.
 1.42 08-Jun-2019  isaki branches: 1.42.4;
Clean get_props().
- Make get_props() return AUDIO_PROP_{PLAYBACK,CAPTURE} properly.
This eliminates need for audio.c to take care of such (old)
drivers which don't return both of PLAYBACK and CAPTURE.
- All get_props() doesn't need to return AUDIO_PROP_MMAP.
It is handled in the audio layer now.
 1.41 08-May-2019  isaki Merge isaki-audio2 branch, the overhaul of audio subsystem.
- Interrupt-oriented system rather than thread-oriented.
- Improve stability, quality and performance.
- Split playback and record cleanly. Improve halfduplex support.
- Many bugs are fixed including deadlocks, resource leaks, abuses, etc.
- Simplify audio filter mechanism. The encoding/channels/frequency
conversions are completely handled in the upper layer. So the hard-
ware driver only converts its hardware encoding (if necessary).
- audio_hw_if changes:
- Obsoletes query_encoding and add query_format instead.
- Obsoletes set_params and add set_format instead.
- Remove drain, setfd, mappage.
- The call sequences are changed.
- ioctl AUDIO_GETFD/SETFD, AUDIO_GETCHAN/SETCHAN are obsoleted.
- ioctl AUDIO_{QUERY,GET,SET}FORMAT are introduced.
- cleanup config attributes: au*conv and mulaw.
- All hardware drivers should follow it (I've done as much as possible).

Some file paths are changed:
- dev/audio.c -> dev/audio/audio.c (rewritten)
- dev/audiovar.h -> dev/audio/audiovar.h
- dev/audio_dai.h -> dev/audio/audio_dai.h
- dev/audio_if.h -> dev/audio/audio_if.h
- dev/audiobell.c -> dev/audio/audiobell.c
- dev/audiobellvar.h -> dev/audio/audiobellvar.h
- dev/mulaw.[ch] -> dev/audio/mulaw.[ch] + dev/audio/alaw.c
 1.40 03-Feb-2019  mrg branches: 1.40.2;
add missing break; after case IW_LINE_IN_LVL case.
it was being overridden by the IW_REC_LVL case.
 1.39 14-Jul-2016  msaitoh branches: 1.39.18;
- Use aprint*() more in xxx_attach().
- Add missing aprint_naive("\n").
- Remove extra spaces and tabs.
- KNF.
 1.38 08-Nov-2013  christos branches: 1.38.6;
fix unused variable warnings
 1.37 27-Oct-2012  chs branches: 1.37.2;
split device_t/softc for all remaining drivers.
replace "struct device *" with "device_t".
use device_xname(), device_unit(), etc.
 1.36 24-Nov-2011  mrg branches: 1.36.8;
put back IPL_AUDIO and splaudio(), at the request of rmind. they are
aliases and now we can easily revert audio to IPL_VM if necessary,
without having to revert the whole branch.
 1.35 23-Nov-2011  jmcneill Merge jmcneill-audiomp3 branch, which is derived from ad-audiomp2. From
the original ad-audiomp branch notes:

Add MP locking to the audio drivers.

Making the audio drivers MP safe is necessary before efforts
can be made to make the VM system MP safe.

The are two locks per device instance, an ISR lock and
a character device lock. The ISR lock replaces calls to
splaudio()/splx(), and will be held across calls to device
methods which were called at splaudio() before (e.g.
trigger_output). The character device lock is held across
calls to nearly all of the methods, excluding some only
used for initialization, e.g. get_locks.

Welcome to 5.99.57.
 1.34 14-Mar-2009  dsl branches: 1.34.12; 1.34.14;
Change about 4500 of the K&R function definitions to ANSI ones.
There are still about 1600 left, but they have ',' or /* ... */
in the actual variable definitions - which my awk script doesn't handle.
There are also many that need () -> (void).
(The script does handle misordered arguments.)
 1.33 28-Apr-2008  martin branches: 1.33.8; 1.33.12; 1.33.14;
Remove clause 3 and 4 from TNF licenses
 1.32 08-Apr-2008  cegger branches: 1.32.2; 1.32.4;
use aprint_*_dev and device_xname
 1.31 19-Oct-2007  ad branches: 1.31.16;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.30 16-Nov-2006  christos branches: 1.30.8; 1.30.22; 1.30.24; 1.30.28;
__unused removal on arguments; approved by core.
 1.29 12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.28 08-Mar-2006  lukem branches: 1.28.10; 1.28.12;
Use the SI capitalization for "Hz", "kHz", and "MHz" in comments and strings.
Add a space between numbers and Hz unit.
 1.27 11-Dec-2005  christos branches: 1.27.4; 1.27.6; 1.27.8; 1.27.10;
merge ktrace-lwp.
 1.26 30-May-2005  christos branches: 1.26.2;
- add missing const
- fix variable shadowing
- remove unneeded casts
 1.25 15-Jan-2005  kent ansify and KNF
 1.24 10-Jan-2005  kent merge kent-audio1 branch, which introduces audio filter pipeline to the MI
audio framework


Summary of changes:

* struct audio_params
- remove sw_code, factor, factor_denom, hw_sample_rate,
hw_encoding ,hw_precision, and hw_channels. Conversion information
is conveyed by stream_filter_list_t.
- change the type of sample_rate: u_long -> u_int
- add `validbits,' which represents the valid data size in
precision bits. It is required in order to distinguish 24/32bit
from 24/24bit or 32/32bit.

* audio_hw_if
- add two parameters to set_params()
stream_filter_list_t *pfil, stream_filter_list *rfil
A HW driver should set filter recipes for requested formats
- constify audio_params parameters of trigger_output() and
trigger_input(). They represent audio formats for the hardware.
- make open() and close() optional
- add int (AUMODE_PLAY or AUMODE_RECORD) and audio_params_t parameters
to round_blocksize()

* sw_code is replaced with stream_filter_t.
stream_filer_t converts audio data in an input buffer and writes
into another output buffer unlike sw_code, which converts data in
single buffer.
converters in dev/auconv.c, dev/mulaw.c, dev/aurateconv.c,
dev/tc/bba.c, dev/ic/msm6258.c, and arch/arm/iomd/vidcaudio.c are
reimplemented as stream_filter_t

* MI audio
- audiosetinfo() builds filter pipelines from stream_filter_list_t
filled by audio_hw_if::set_params()
- audiosetinfo() returns with EINVAL if mmapped and set_params()
requests filters
- audio_write(), audio_pint(), and audio_rint() invoke a filter
pipeline.
- ioctl() for FIONREAD, AUDIO_WSEEK, AUDIO_GETIOFFS,
AUDIO_GETOOFFS, and audio_prinfo::{seek,samples} for
AUDIO_GETINFO handle values for a buffer nearest to userland.

* add `struct device *' parameter to ac97_attach()

* all of audio HW drivers follow audio_hw_if and ac97 changes
 1.23 09-Jul-2004  mycroft branches: 1.23.2;
Kill unused variable.
 1.22 09-Jul-2004  mycroft Remove some more code.
 1.21 09-Jul-2004  mycroft Slight code redux.
 1.20 22-Apr-2004  itojun sprintf -> snprintf
 1.19 30-Oct-2003  simonb Remove some assigned-to but otherwise unused variables.
 1.18 03-May-2003  wiz branches: 1.18.2;
DMA, not dma nor Dma.
 1.17 06-Apr-2003  wiz Respect the law: Use A-law and mu-law as spellings as far as easily possible.
Inspired by Igor Sobrado in PR 19680.
 1.16 01-Feb-2003  thorpej Add extensible malloc types, adapted from FreeBSD. This turns
malloc types into a structure, a pointer to which is passed around,
instead of an int constant. Allow the limit to be adjusted when the
malloc type is defined, or with a function call, as suggested by
Jonathan Stone.
 1.15 06-Feb-2002  pooka Remove inclusion of unused machine/cpufunc.h, it doesn't belong here anyways.
 1.14 13-Nov-2001  lukem add/cleanup RCSID
 1.13 26-Jun-2000  simonb branches: 1.13.2; 1.13.4;
Change the kernel mmap interface so that the offset to map is an
"off_t" and the return value is a "paddr_t" to allow mappings
at offsets past 2^31 bytes. Somewhat inspired by FreeBSD, which
only changed the offset to a "vm_offset_t".

Includes updates for the i386, pc532 and sh3 mmmmap from Jason Thorpe.
 1.12 07-Feb-2000  thorpej branches: 1.12.4;
Add a new function call to the ISA DMA API: isa_dmamaxsize(), which returns
the maximum transfer size for the specified DMA channel. Make all clients
of ISA DMA use this call to determine their maximum transfer size.
 1.11 17-Feb-1999  mycroft branches: 1.11.8;
Update comments.
 1.10 17-Feb-1999  mycroft Fix slight ommission in previous.
 1.9 17-Feb-1999  mycroft Pass the direction to the allocm and round_buffersize methods.
Some drivers need this to properly allocate DMAable memory.
 1.8 17-Aug-1998  augustss * Redo the way the way the MIDI driver attaches to audio devices.
* Improve the midisyn layer a little.
* Add a driver for the Yamaha OPL[23] FM synths.
The opl driver is not finished yet; it sounds pretty awful.

For some strange reason I cannot get any FM sound from my SB64 cards,
but a regular SB16 works fine.
 1.7 10-Jun-1998  bouyer Make this compile with the recent ISA DMA changes.
 1.6 20-Apr-1998  augustss Make probe message more consistent with usual practice.
From "Soren S. Jorvang" <soren@t.dk>.
 1.5 19-Oct-1997  augustss Make the audio API (almost) SunOS compatible.
The changes is to allow some limited mixer manipulation through
the audio device (instead of the mixer device).
This rendered 4 methods in audio_hw_if unused so garbage collect these.
 1.4 11-Oct-1997  mycroft branches: 1.4.2;
AudioElinear -> AudioEslinear
 1.3 11-Oct-1997  mycroft AudioC[A-Z] -> AudioC[a-z]
 1.2 09-Oct-1997  jtc Fix tipo inherited from old version of TNF copyright template.
 1.1 06-Oct-1997  augustss Driver for the Interwave audio chip used in the GUS PnP sound card.
 1.4.2.2 14-Oct-1997  thorpej Update marc-pcmcia branch from trunk.
 1.4.2.1 11-Oct-1997  thorpej file interwave.c was added on branch marc-pcmcia on 1997-10-14 10:22:31 +0000
 1.11.8.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.12.4.1 30-Jun-2000  simonb Pull up mmap paddr_t/off_t changes from trunk.
 1.13.4.2 11-Feb-2002  jdolecek Sync w/ -current.
 1.13.4.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.13.2.2 28-Feb-2002  nathanw Catch up to -current.
 1.13.2.1 14-Nov-2001  nathanw Catch up to -current.
 1.18.2.5 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.18.2.4 17-Jan-2005  skrll Sync with HEAD.
 1.18.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.18.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.18.2.1 03-Aug-2004  skrll Sync with HEAD
 1.23.2.3 09-Jan-2005  kent audio_hw_if change
* make open() and close() optional
* add int (AUMODE_PLAY or AUMODE_RECORD) and audio_params_t parameters
to round_blocksize()
 1.23.2.2 03-Jan-2005  kent * remove stream_filter_list_append and stream_filter_list_prepend
* add stream_filter_list_t::{append(), prepend(), set()}
 1.23.2.1 03-Jan-2005  kent * adopt the filter pipeline framework

* ic/ad1848.c, isa/ess.c, isa/sbdsp.c
remove direct call of set_params() for the default encoding.
It should be called by the MI audio framework.
 1.26.2.3 27-Oct-2007  yamt sync with head.
 1.26.2.2 30-Dec-2006  yamt sync with head.
 1.26.2.1 21-Jun-2006  yamt sync with head.
 1.27.10.1 19-Apr-2006  elad sync with head.
 1.27.8.1 13-Mar-2006  yamt sync with head.
 1.27.6.1 22-Apr-2006  simonb Sync with head.
 1.27.4.1 09-Sep-2006  rpaulo sync with head
 1.28.12.2 10-Dec-2006  yamt sync with head.
 1.28.12.1 22-Oct-2006  yamt sync with head
 1.28.10.1 18-Nov-2006  ad Sync with head.
 1.30.28.1 25-Oct-2007  bouyer Sync with HEAD.
 1.30.24.1 06-Nov-2007  matt sync with HEAD
 1.30.22.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.30.8.1 23-Oct-2007  ad Sync with head.
 1.31.16.1 02-Jun-2008  mjf Sync with HEAD.
 1.32.4.2 04-May-2009  yamt sync with head.
 1.32.4.1 16-May-2008  yamt sync with head.
 1.32.2.1 18-May-2008  yamt sync with head.
 1.33.14.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.33.12.2 13-Dec-2008  ad Missing get_locks() method.
 1.33.12.1 12-Dec-2008  ad Checkpoint work in progress.
 1.33.8.1 28-Apr-2009  skrll Sync with HEAD.
 1.34.14.1 19-Nov-2011  jmcneill port ad-audiomp2 branch changes to 5.99.56
todo:
- port ad-audiomp2 pcppi changes
- these drivers need to be fixed:
- emuxki
- gcscaudio
- hdafg
- uaudio
- umidi
- MD audio drivers
 1.34.12.3 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.34.12.2 30-Oct-2012  yamt sync with head
 1.34.12.1 17-Apr-2012  yamt sync with head
 1.36.8.3 03-Dec-2017  jdolecek update from HEAD
 1.36.8.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.36.8.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.37.2.1 18-May-2014  rmind sync with head
 1.38.6.1 05-Oct-2016  skrll Sync with HEAD
 1.39.18.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.39.18.1 10-Jun-2019  christos Sync with HEAD
 1.40.2.3 04-May-2019  isaki Move dev/audio_if.h -> dev/audio/audio_if.h
 1.40.2.2 04-May-2019  isaki Remove obsoleted methods in audio_hw_if.
- drain: is handled in audio upper layer now.
- mappage: is handled in audio upper layer now.
- setfd: no one uses and it's meaningless now.
 1.40.2.1 21-Apr-2019  isaki Adapt ad1848/cs4231 families to audio2.
 1.42.4.1 29-Feb-2020  ad Sync with head.
 1.10 09-Feb-2024  andvar fix spelling mistakes, mainly in comments and log messages.
 1.9 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.8 11-Dec-2005  christos branches: 1.8.70; 1.8.72; 1.8.74;
merge ktrace-lwp.
 1.7 15-Jan-2005  kent ansify and KNF
 1.6 03-May-2003  wiz branches: 1.6.2;
DMA, not dma nor Dma.
 1.5 06-Apr-2003  wiz Respect the law: Use A-law and mu-law as spellings as far as easily possible.
Inspired by Igor Sobrado in PR 19680.
 1.4 30-Apr-2001  lukem this is _C_ not _C++_, and // is NOT valid in _C_
 1.3 19-Oct-1997  augustss branches: 1.3.28;
Make the audio API (almost) SunOS compatible.
The changes is to allow some limited mixer manipulation through
the audio device (instead of the mixer device).
This rendered 4 methods in audio_hw_if unused so garbage collect these.
 1.2 09-Oct-1997  jtc branches: 1.2.2;
Fix tipo inherited from old version of TNF copyright template.
 1.1 06-Oct-1997  augustss Driver for the Interwave audio chip used in the GUS PnP sound card.
 1.2.2.2 14-Oct-1997  thorpej Update marc-pcmcia branch from trunk.
 1.2.2.1 09-Oct-1997  thorpej file interwavereg.h was added on branch marc-pcmcia on 1997-10-14 10:22:33 +0000
 1.3.28.1 21-Jun-2001  nathanw Catch up to -current.
 1.6.2.1 17-Jan-2005  skrll Sync with HEAD.
 1.8.74.1 16-May-2008  yamt sync with head.
 1.8.72.1 18-May-2008  yamt sync with head.
 1.8.70.1 02-Jun-2008  mjf Sync with HEAD.
 1.20 29-Feb-2020  isaki Remove rounding by 4 bytes on round_blocksize().
For drivers which supports only 16bit * 2channels sampling,
rounding by 4 bytes no longer meaningful.
 1.19 08-May-2019  isaki branches: 1.19.4;
Merge isaki-audio2 branch, the overhaul of audio subsystem.
- Interrupt-oriented system rather than thread-oriented.
- Improve stability, quality and performance.
- Split playback and record cleanly. Improve halfduplex support.
- Many bugs are fixed including deadlocks, resource leaks, abuses, etc.
- Simplify audio filter mechanism. The encoding/channels/frequency
conversions are completely handled in the upper layer. So the hard-
ware driver only converts its hardware encoding (if necessary).
- audio_hw_if changes:
- Obsoletes query_encoding and add query_format instead.
- Obsoletes set_params and add set_format instead.
- Remove drain, setfd, mappage.
- The call sequences are changed.
- ioctl AUDIO_GETFD/SETFD, AUDIO_GETCHAN/SETCHAN are obsoleted.
- ioctl AUDIO_{QUERY,GET,SET}FORMAT are introduced.
- cleanup config attributes: au*conv and mulaw.
- All hardware drivers should follow it (I've done as much as possible).

Some file paths are changed:
- dev/audio.c -> dev/audio/audio.c (rewritten)
- dev/audiovar.h -> dev/audio/audiovar.h
- dev/audio_dai.h -> dev/audio/audio_dai.h
- dev/audio_if.h -> dev/audio/audio_if.h
- dev/audiobell.c -> dev/audio/audiobell.c
- dev/audiobellvar.h -> dev/audio/audiobellvar.h
- dev/mulaw.[ch] -> dev/audio/mulaw.[ch] + dev/audio/alaw.c
 1.18 27-Oct-2012  chs branches: 1.18.38; 1.18.42;
split device_t/softc for all remaining drivers.
replace "struct device *" with "device_t".
use device_xname(), device_unit(), etc.
 1.17 23-Nov-2011  jmcneill branches: 1.17.8;
Merge jmcneill-audiomp3 branch, which is derived from ad-audiomp2. From
the original ad-audiomp branch notes:

Add MP locking to the audio drivers.

Making the audio drivers MP safe is necessary before efforts
can be made to make the VM system MP safe.

The are two locks per device instance, an ISR lock and
a character device lock. The ISR lock replaces calls to
splaudio()/splx(), and will be held across calls to device
methods which were called at splaudio() before (e.g.
trigger_output). The character device lock is held across
calls to nearly all of the methods, excluding some only
used for initialization, e.g. get_locks.

Welcome to 5.99.57.
 1.16 28-Apr-2008  martin branches: 1.16.12; 1.16.34; 1.16.36;
Remove clause 3 and 4 from TNF licenses
 1.15 11-Dec-2005  christos branches: 1.15.70; 1.15.72; 1.15.74;
merge ktrace-lwp.
 1.14 15-Jan-2005  kent ansify and KNF
 1.13 10-Jan-2005  kent merge kent-audio1 branch, which introduces audio filter pipeline to the MI
audio framework


Summary of changes:

* struct audio_params
- remove sw_code, factor, factor_denom, hw_sample_rate,
hw_encoding ,hw_precision, and hw_channels. Conversion information
is conveyed by stream_filter_list_t.
- change the type of sample_rate: u_long -> u_int
- add `validbits,' which represents the valid data size in
precision bits. It is required in order to distinguish 24/32bit
from 24/24bit or 32/32bit.

* audio_hw_if
- add two parameters to set_params()
stream_filter_list_t *pfil, stream_filter_list *rfil
A HW driver should set filter recipes for requested formats
- constify audio_params parameters of trigger_output() and
trigger_input(). They represent audio formats for the hardware.
- make open() and close() optional
- add int (AUMODE_PLAY or AUMODE_RECORD) and audio_params_t parameters
to round_blocksize()

* sw_code is replaced with stream_filter_t.
stream_filer_t converts audio data in an input buffer and writes
into another output buffer unlike sw_code, which converts data in
single buffer.
converters in dev/auconv.c, dev/mulaw.c, dev/aurateconv.c,
dev/tc/bba.c, dev/ic/msm6258.c, and arch/arm/iomd/vidcaudio.c are
reimplemented as stream_filter_t

* MI audio
- audiosetinfo() builds filter pipelines from stream_filter_list_t
filled by audio_hw_if::set_params()
- audiosetinfo() returns with EINVAL if mmapped and set_params()
requests filters
- audio_write(), audio_pint(), and audio_rint() invoke a filter
pipeline.
- ioctl() for FIONREAD, AUDIO_WSEEK, AUDIO_GETIOFFS,
AUDIO_GETOOFFS, and audio_prinfo::{seek,samples} for
AUDIO_GETINFO handle values for a buffer nearest to userland.

* add `struct device *' parameter to ac97_attach()

* all of audio HW drivers follow audio_hw_if and ac97 changes
 1.12 29-Oct-2004  yamt branches: 1.12.2;
constify audio_hw_if, midi_hw_if, and radio_hw_if.
 1.11 09-Jul-2004  mycroft Remove some more code.
 1.10 09-Jul-2004  mycroft Slight code redux.
 1.9 01-Feb-2003  thorpej branches: 1.9.2;
Add extensible malloc types, adapted from FreeBSD. This turns
malloc types into a structure, a pointer to which is passed around,
instead of an int constant. Allow the limit to be adjusted when the
malloc type is defined, or with a function call, as suggested by
Jonathan Stone.
 1.8 26-Jun-2000  simonb Change the kernel mmap interface so that the offset to map is an
"off_t" and the return value is a "paddr_t" to allow mappings
at offsets past 2^31 bytes. Somewhat inspired by FreeBSD, which
only changed the offset to a "vm_offset_t".

Includes updates for the i386, pc532 and sh3 mmmmap from Jason Thorpe.
 1.7 07-Feb-2000  thorpej branches: 1.7.4;
Add a new function call to the ISA DMA API: isa_dmamaxsize(), which returns
the maximum transfer size for the specified DMA channel. Make all clients
of ISA DMA use this call to determine their maximum transfer size.
 1.6 17-Feb-1999  mycroft branches: 1.6.8;
Update comments.
 1.5 17-Feb-1999  mycroft Pass the direction to the allocm and round_buffersize methods.
Some drivers need this to properly allocate DMAable memory.
 1.4 10-Jun-1998  bouyer Make this compile with the recent ISA DMA changes.
 1.3 19-Oct-1997  augustss Make the audio API (almost) SunOS compatible.
The changes is to allow some limited mixer manipulation through
the audio device (instead of the mixer device).
This rendered 4 methods in audio_hw_if unused so garbage collect these.
 1.2 09-Oct-1997  jtc branches: 1.2.2;
Fix tipo inherited from old version of TNF copyright template.
 1.1 06-Oct-1997  augustss Driver for the Interwave audio chip used in the GUS PnP sound card.
 1.2.2.2 14-Oct-1997  thorpej Update marc-pcmcia branch from trunk.
 1.2.2.1 09-Oct-1997  thorpej file interwavevar.h was added on branch marc-pcmcia on 1997-10-14 10:22:35 +0000
 1.6.8.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.7.4.1 30-Jun-2000  simonb Pull up mmap paddr_t/off_t changes from trunk.
 1.9.2.5 17-Jan-2005  skrll Sync with HEAD.
 1.9.2.4 02-Nov-2004  skrll Sync with HEAD.
 1.9.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.9.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.9.2.1 03-Aug-2004  skrll Sync with HEAD
 1.12.2.2 09-Jan-2005  kent audio_hw_if change
* make open() and close() optional
* add int (AUMODE_PLAY or AUMODE_RECORD) and audio_params_t parameters
to round_blocksize()
 1.12.2.1 03-Jan-2005  kent * adopt the filter pipeline framework

* ic/ad1848.c, isa/ess.c, isa/sbdsp.c
remove direct call of set_params() for the default encoding.
It should be called by the MI audio framework.
 1.15.74.1 16-May-2008  yamt sync with head.
 1.15.72.1 18-May-2008  yamt sync with head.
 1.15.70.1 02-Jun-2008  mjf Sync with HEAD.
 1.16.36.1 19-Nov-2011  jmcneill port ad-audiomp2 branch changes to 5.99.56
todo:
- port ad-audiomp2 pcppi changes
- these drivers need to be fixed:
- emuxki
- gcscaudio
- hdafg
- uaudio
- umidi
- MD audio drivers
 1.16.34.2 30-Oct-2012  yamt sync with head
 1.16.34.1 17-Apr-2012  yamt sync with head
 1.16.12.1 12-Dec-2008  ad Checkpoint work in progress.
 1.17.8.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.18.42.2 04-May-2019  isaki Remove obsoleted methods in audio_hw_if.
- drain: is handled in audio upper layer now.
- mappage: is handled in audio upper layer now.
- setfd: no one uses and it's meaningless now.
 1.18.42.1 21-Apr-2019  isaki Adapt ad1848/cs4231 families to audio2.
 1.18.38.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.18.38.1 10-Jun-2019  christos Sync with HEAD
 1.19.4.1 29-Feb-2020  ad Sync with head.
 1.5 22-Sep-2018  maxv Remove isic(4). It is part of ISDN, which we are now retiring.
 1.4 07-Aug-2011  jakllsch branches: 1.4.52; 1.4.54;
Appease _LP64 build with GCC 4.5.
 1.3 11-Dec-2005  christos merge ktrace-lwp.
 1.2 27-Feb-2005  perry nuke trailing whitespace
 1.1 20-Feb-2001  martin branches: 1.1.4; 1.1.26; 1.1.34; 1.1.36;
Filename cleanup: remove i4b_ prefixes outside sys/netisdn, last round.

Renamed in sys/dev/ic:
i4b_hscx.c -> hscx.c
i4b_hscx.h -> hscx.h
i4b_ipac.h -> ipac.h
i4b_isac.c -> isac.c
i4b_isac.h -> isac.h
i4b_isic.c -> isic.c
i4b_isicbchan.c -> isic_bchan.c
i4b_isicl1.c -> isic_l1.c
i4b_isicl1.h -> isic_l1.h
i4b_isicl1fsm.c -> isic_l1fsm.c
 1.1.36.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.1.34.1 29-Apr-2005  kent sync with -current
 1.1.26.1 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.1.4.2 12-Mar-2001  bouyer Sync with HEAD.
 1.1.4.1 20-Feb-2001  bouyer file ipac.h was added on branch thorpej_scsipi on 2001-03-12 13:30:24 +0000
 1.4.54.1 10-Jun-2019  christos Sync with HEAD
 1.4.52.1 30-Sep-2018  pgoyette Ssync with HEAD
 1.25 22-Sep-2018  maxv Remove isic(4). It is part of ISDN, which we are now retiring.
 1.24 27-Oct-2012  chs branches: 1.24.36; 1.24.38;
split device_t/softc for all remaining drivers.
replace "struct device *" with "device_t".
use device_xname(), device_unit(), etc.
 1.23 17-Jul-2011  joerg branches: 1.23.2; 1.23.12;
Retire varargs.h support. Move machine/stdarg.h logic into MI
sys/stdarg.h and expect compiler to provide proper builtins, defaulting
to the GCC interface. lint still has a special fallback.
Reduce abuse of _BSD_VA_LIST_ by defining __va_list by default and
derive va_list as required by standards.
 1.22 08-Apr-2008  cegger use aprint_*_dev and device_xname
 1.21 19-Oct-2007  ad branches: 1.21.16;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.20 11-Dec-2005  christos branches: 1.20.30; 1.20.44; 1.20.46; 1.20.50;
merge ktrace-lwp.
 1.19 27-Feb-2005  perry branches: 1.19.4;
nuke trailing whitespace
 1.18 27-Sep-2002  provos branches: 1.18.6; 1.18.14; 1.18.16;
remove trailing \n in panic(). approved perry.
 1.17 21-May-2002  martin Uniformly pass a "struct isdn_l3_driver *" through layer 2, so we
do not have to search for that driver later while we already knew it
at layer 1.
 1.16 29-Apr-2002  martin branches: 1.16.2;
Patches from Matthias Drochner, slightly modified by me:

Remove the clear-the-irq-after-enabling it dance (which had bad side
effects on some cards). Instead disble the ISAC receiver when we have
interrupts disabled. Adjust the interrupt handler to properly deal with
subtle differences of the ISAC implementation in IPAC chips.
 1.15 18-Apr-2002  martin Handle unexpected interrupts better.
 1.14 17-Apr-2002  martin When clearing interrupts, clear IPAC interrupts for cards that have
one.
 1.13 13-Apr-2002  martin When pruning state at interrupt enable time, also call the clearirq
routine for cards that provide it.
 1.12 13-Apr-2002  martin Defer initialization of the ISAC chip until we enable interrupts - it gets
into a strange failure mode if we do it with disabled interrupt. When
(re-)enabling interrupts reset transmitter and receiver and clear any
pending state.
 1.11 10-Apr-2002  martin Remove some redundant tries to disable interupts. We already avoided enabling
them.
Fix a stupid typo when enabling/disabling interrupts: we clear pending
interrupts when enabling, not disbling isac interrupts.
 1.10 08-Apr-2002  martin Combine sc_enabled and sc_dying into one field sc_intr_valid, they are used
for the same purpose (ignoring invalid interrupts).

For cards that are not able to stop all interrupts (or we don't know a way
to do that in software, at least) run the clearirq callback even when
ignoring an interrupt because we are not enabled. Otherwise the card would
stop interrupting.

Reserve a driver specific callout handle and an int value in the generic
isic_softc to allow card drivers to implement fancy blinkenlights.
 1.9 06-Apr-2002  martin Remove leftover from my first, incomplete attempt to cope with detaching
pcmcia cards. Now that pcmcia attachements properly handle the activate
callback, this is no longer needed (and is suspect to cause completely
unrelated problems.)
 1.8 01-Apr-2002  martin Do not bother to enable interrupts at attach time - we are going to disable
them again imediately
 1.7 27-Mar-2002  martin After Jason Thorpe explained to me how it is supposed to work, implement
(de)activate for pcmcia cards.
Implement detach/(de)activate for PCI cards.
Clean up internal state (free call-descriptors) if a controller is
detached while it has open connections.
 1.6 25-Mar-2002  martin Now that we have all pieces in place (and enough granularity to specify
B-channel and D-channel drivers separately) split the Fritz!PCI card
driver out of the isic driver.

The new device is called "ifpci" and uses the same D-channel driver as the
isic devices, but has it's own B-channel driver.
 1.5 25-Mar-2002  martin Make pcmcia cards detach properly.
Notify userland of attaching/detaching cards.
This partly fixes PR 15951.
 1.4 24-Mar-2002  martin Now that we have all the pieces of the puzzle available start to unriddle
and move them in their proper places.

Move the BRI registry from layer 2 (duh!) to layer 4, so active cards
(which don't have layer 3 or layer 2 in their driver). Remove all remaining
hard coded controller and driver types. Remove any arbitrary hard coded
limits, at least those that show up in the internal API.

This fixes PR 15950.
 1.3 13-Nov-2001  lukem add/cleanup RCSID
 1.2 24-Mar-2001  martin branches: 1.2.2;
First step to cleanup the hardware driver <-> upper layers interface.
This now provides slightly more functionality than the FreeBSD layer1-newbus
interface. It was meant to be a simple change to one header and a few
c files, but the change rippled all through various stuff.

To prevent a change to the kernel<->userland interface right now the kernel
is now lying about card types to userland (but who cares). This will be fixed
when the userland interface changes, after layer 3 <-> layer 4 has been
fixed.

Functional changes:

Provide a clean interface for hardware drivers to attach to the upper
layers. This will need another small change in the B-channel handling
when a similar change to the layer 3 <-> layer 4 interface happens.

Avoid passing indices into global arrays of pointers around, instead pass
the pointers itself. Don't code hardware driver types by predefined magic
numbers (think LKM). Prepare for detachable drivers (think pcmcia).

While there remove some sets of function pointers always pointing to the
same function (meant to be the configurable set of D channel protocol
handlers). It is unlikely another supported D-channel protocol will fit into
that (maximal layer interface) abstraction. When we get support for another
protocol, we will need to come up with a workable interface. Besides, the
old implementation was, uhm, strange.
 1.1 20-Feb-2001  martin branches: 1.1.2; 1.1.4;
Filename cleanup: remove i4b_ prefixes outside sys/netisdn, last round.

Renamed in sys/dev/ic:
i4b_hscx.c -> hscx.c
i4b_hscx.h -> hscx.h
i4b_ipac.h -> ipac.h
i4b_isac.c -> isac.c
i4b_isac.h -> isac.h
i4b_isic.c -> isic.c
i4b_isicbchan.c -> isic_bchan.c
i4b_isicl1.c -> isic_l1.c
i4b_isicl1.h -> isic_l1.h
i4b_isicl1fsm.c -> isic_l1fsm.c
 1.1.4.3 27-Mar-2001  bouyer Sync with HEAD.
 1.1.4.2 12-Mar-2001  bouyer Sync with HEAD.
 1.1.4.1 20-Feb-2001  bouyer file isac.c was added on branch thorpej_scsipi on 2001-03-12 13:30:24 +0000
 1.1.2.6 18-Oct-2002  nathanw Catch up to -current.
 1.1.2.5 20-Jun-2002  nathanw Catch up to -current.
 1.1.2.4 17-Apr-2002  nathanw Catch up to -current.
 1.1.2.3 01-Apr-2002  nathanw Catch up to -current.
(CVS: It's not just a program. It's an adventure!)
 1.1.2.2 14-Nov-2001  nathanw Catch up to -current.
 1.1.2.1 09-Apr-2001  nathanw Catch up with -current.
 1.2.2.3 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.2.2.2 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.2.2.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.16.2.1 30-May-2002  gehenna Catch up with -current.
 1.18.16.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.18.14.1 29-Apr-2005  kent sync with -current
 1.18.6.1 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.19.4.1 27-Oct-2007  yamt sync with head.
 1.20.50.1 25-Oct-2007  bouyer Sync with HEAD.
 1.20.46.1 06-Nov-2007  matt sync with HEAD
 1.20.44.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.20.30.1 23-Oct-2007  ad Sync with head.
 1.21.16.1 02-Jun-2008  mjf Sync with HEAD.
 1.23.12.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.23.2.1 30-Oct-2012  yamt sync with head
 1.24.38.1 10-Jun-2019  christos Sync with HEAD
 1.24.36.1 30-Sep-2018  pgoyette Ssync with HEAD
 1.5 22-Sep-2018  maxv Remove isic(4). It is part of ISDN, which we are now retiring.
 1.4 07-Aug-2011  jakllsch branches: 1.4.52; 1.4.54;
Appease _LP64 build with GCC 4.5.
 1.3 11-Dec-2005  christos merge ktrace-lwp.
 1.2 27-Feb-2005  perry nuke trailing whitespace
 1.1 20-Feb-2001  martin branches: 1.1.4; 1.1.26; 1.1.34; 1.1.36;
Filename cleanup: remove i4b_ prefixes outside sys/netisdn, last round.

Renamed in sys/dev/ic:
i4b_hscx.c -> hscx.c
i4b_hscx.h -> hscx.h
i4b_ipac.h -> ipac.h
i4b_isac.c -> isac.c
i4b_isac.h -> isac.h
i4b_isic.c -> isic.c
i4b_isicbchan.c -> isic_bchan.c
i4b_isicl1.c -> isic_l1.c
i4b_isicl1.h -> isic_l1.h
i4b_isicl1fsm.c -> isic_l1fsm.c
 1.1.36.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.1.34.1 29-Apr-2005  kent sync with -current
 1.1.26.1 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.1.4.2 12-Mar-2001  bouyer Sync with HEAD.
 1.1.4.1 20-Feb-2001  bouyer file isac.h was added on branch thorpej_scsipi on 2001-03-12 13:30:25 +0000
 1.4.54.1 10-Jun-2019  christos Sync with HEAD
 1.4.52.1 30-Sep-2018  pgoyette Ssync with HEAD
 1.8 22-Sep-2018  maxv Remove isic(4). It is part of ISDN, which we are now retiring.
 1.7 27-Oct-2012  chs branches: 1.7.36; 1.7.38;
split device_t/softc for all remaining drivers.
replace "struct device *" with "device_t".
use device_xname(), device_unit(), etc.
 1.6 08-Apr-2008  cegger branches: 1.6.38; 1.6.48;
use aprint_*_dev and device_xname
 1.5 19-Oct-2007  ad branches: 1.5.16;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.4 11-Dec-2005  christos branches: 1.4.30; 1.4.44; 1.4.46; 1.4.50;
merge ktrace-lwp.
 1.3 27-Feb-2005  perry branches: 1.3.4;
nuke trailing whitespace
 1.2 08-May-2003  martin branches: 1.2.2; 1.2.10; 1.2.12;
Add missing include.
Addresses parts of PR kern/21448 by Frank Kardel.
 1.1 25-Oct-2002  leo branches: 1.1.2;
Fritz!PCI v2.0 ISDN driver from FreeBSD.
 1.1.2.2 11-Nov-2002  nathanw Catch up to -current
 1.1.2.1 25-Oct-2002  nathanw file isacsx.c was added on branch nathanw_sa on 2002-11-11 22:09:34 +0000
 1.2.12.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.2.10.1 29-Apr-2005  kent sync with -current
 1.2.2.1 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.3.4.1 27-Oct-2007  yamt sync with head.
 1.4.50.1 25-Oct-2007  bouyer Sync with HEAD.
 1.4.46.1 06-Nov-2007  matt sync with HEAD
 1.4.44.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.4.30.1 23-Oct-2007  ad Sync with head.
 1.5.16.1 02-Jun-2008  mjf Sync with HEAD.
 1.6.48.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.6.38.1 30-Oct-2012  yamt sync with head
 1.7.38.1 10-Jun-2019  christos Sync with HEAD
 1.7.36.1 30-Sep-2018  pgoyette Ssync with HEAD
 1.6 22-Sep-2018  maxv Remove isic(4). It is part of ISDN, which we are now retiring.
 1.5 07-Aug-2011  jakllsch branches: 1.5.52; 1.5.54;
Another instance of REG_OFFSET that needs to be consistent with the rest.
 1.4 08-Sep-2008  gmcgarry Replace most gcc-specific __attribute__ uses with BSD-style sys/cdef.h
preprocessor macros.
 1.3 11-Dec-2005  christos branches: 1.3.70; 1.3.74; 1.3.76; 1.3.80;
merge ktrace-lwp.
 1.2 27-Feb-2005  perry nuke trailing whitespace
 1.1 25-Oct-2002  leo branches: 1.1.2; 1.1.8; 1.1.16; 1.1.18;
Fritz!PCI v2.0 ISDN driver from FreeBSD.
 1.1.18.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.1.16.1 29-Apr-2005  kent sync with -current
 1.1.8.1 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.1.2.2 11-Nov-2002  nathanw Catch up to -current
 1.1.2.1 25-Oct-2002  nathanw file isacsx.h was added on branch nathanw_sa on 2002-11-11 22:09:35 +0000
 1.3.80.1 19-Oct-2008  haad Sync with HEAD.
 1.3.76.1 24-Sep-2008  wrstuden Merge in changes between wrstuden-revivesa-base-2 and
wrstuden-revivesa-base-3.
 1.3.74.1 04-May-2009  yamt sync with head.
 1.3.70.1 28-Sep-2008  mjf Sync with HEAD.
 1.5.54.1 10-Jun-2019  christos Sync with HEAD
 1.5.52.1 30-Sep-2018  pgoyette Ssync with HEAD
 1.26 22-Sep-2018  maxv Remove isic(4). It is part of ISDN, which we are now retiring.
 1.25 27-Oct-2012  chs branches: 1.25.36; 1.25.38;
split device_t/softc for all remaining drivers.
replace "struct device *" with "device_t".
use device_xname(), device_unit(), etc.
 1.24 08-Apr-2008  cegger branches: 1.24.38; 1.24.48;
use aprint_*_dev and device_xname
 1.23 19-Oct-2007  ad branches: 1.23.16;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.22 11-Dec-2005  christos branches: 1.22.30; 1.22.44; 1.22.46; 1.22.50;
merge ktrace-lwp.
 1.21 27-Feb-2005  perry branches: 1.21.4;
nuke trailing whitespace
 1.20 03-Oct-2003  pooka branches: 1.20.8; 1.20.10;
Ready the kernel side of i4b for primary rate interface support by
removing assumptions that there are only two B channels and by
adding support for a varying number of channels.

Due to this, rename previously used isdn identified "bri" to "isdnif",
which better describes the current situation.
 1.19 06-Jan-2003  wiz branches: 1.19.2;
interrupt with two rs.
 1.18 21-May-2002  martin Uniformly pass a "struct isdn_l3_driver *" through layer 2, so we
do not have to search for that driver later while we already knew it
at layer 1.
 1.17 30-Apr-2002  martin branches: 1.17.2;
Do not mask/unmask interrupts on IPAC to clear the interrupt status.

It is unclear if this realy is needed and if, on which type of cards. I
haven't run accross a card that needs it yet. This may have been just
a copy & pasto from the ISAC interrupt handler carried over to IPAC.
 1.16 29-Apr-2002  martin Patches from Matthias Drochner, slightly modified by me:

Remove the clear-the-irq-after-enabling it dance (which had bad side
effects on some cards). Instead disble the ISAC receiver when we have
interrupts disabled. Adjust the interrupt handler to properly deal with
subtle differences of the ISAC implementation in IPAC chips.
 1.15 18-Apr-2002  martin Handle unexpected interrupts better.
 1.14 08-Apr-2002  martin Combine sc_enabled and sc_dying into one field sc_intr_valid, they are used
for the same purpose (ignoring invalid interrupts).

For cards that are not able to stop all interrupts (or we don't know a way
to do that in software, at least) run the clearirq callback even when
ignoring an interrupt because we are not enabled. Otherwise the card would
stop interrupting.

Reserve a driver specific callout handle and an int value in the generic
isic_softc to allow card drivers to implement fancy blinkenlights.
 1.13 06-Apr-2002  martin Remove leftover from my first, incomplete attempt to cope with detaching
pcmcia cards. Now that pcmcia attachements properly handle the activate
callback, this is no longer needed (and is suspect to cause completely
unrelated problems.)
 1.12 01-Apr-2002  martin Move isic_intr_enable to a file not depending on the HSCX driver, so
ifpci-only configurations build again.

Remove the now unused controller enable function from the passive drivers
l2<->l1 interface.
 1.11 30-Mar-2002  martin Be a nice citizen, enable interrupts only when we are ready to talk
to the ISDN (i.e. when userland has /dev/isdn open).
 1.10 30-Mar-2002  martin Avoid duplicate expensive lookups by passing a pointer to the call
descriptor/a pointer to the layer 3 state directly to driver functions,
instead of their ID/index.
 1.9 29-Mar-2002  martin Split BRI attaching into two phases, so lower layer drivers can get their
BRI identifier and L3 driver state early on, then finish initializing and
announce the controller to userland when it's ready.
 1.8 27-Mar-2002  martin After Jason Thorpe explained to me how it is supposed to work, implement
(de)activate for pcmcia cards.
Implement detach/(de)activate for PCI cards.
Clean up internal state (free call-descriptors) if a controller is
detached while it has open connections.
 1.7 25-Mar-2002  martin Now that we have all pieces in place (and enough granularity to specify
B-channel and D-channel drivers separately) split the Fritz!PCI card
driver out of the isic driver.

The new device is called "ifpci" and uses the same D-channel driver as the
isic devices, but has it's own B-channel driver.
 1.6 25-Mar-2002  martin Remove a leftover from the BRI registry at layer 2.
Initialize layer 2's idea of it's BRI id after attaching.
 1.5 25-Mar-2002  martin Make pcmcia cards detach properly.
Notify userland of attaching/detaching cards.
This partly fixes PR 15951.
 1.4 24-Mar-2002  martin Now that we have all the pieces of the puzzle available start to unriddle
and move them in their proper places.

Move the BRI registry from layer 2 (duh!) to layer 4, so active cards
(which don't have layer 3 or layer 2 in their driver). Remove all remaining
hard coded controller and driver types. Remove any arbitrary hard coded
limits, at least those that show up in the internal API.

This fixes PR 15950.
 1.3 13-Nov-2001  lukem add/cleanup RCSID
 1.2 24-Mar-2001  martin branches: 1.2.2;
First step to cleanup the hardware driver <-> upper layers interface.
This now provides slightly more functionality than the FreeBSD layer1-newbus
interface. It was meant to be a simple change to one header and a few
c files, but the change rippled all through various stuff.

To prevent a change to the kernel<->userland interface right now the kernel
is now lying about card types to userland (but who cares). This will be fixed
when the userland interface changes, after layer 3 <-> layer 4 has been
fixed.

Functional changes:

Provide a clean interface for hardware drivers to attach to the upper
layers. This will need another small change in the B-channel handling
when a similar change to the layer 3 <-> layer 4 interface happens.

Avoid passing indices into global arrays of pointers around, instead pass
the pointers itself. Don't code hardware driver types by predefined magic
numbers (think LKM). Prepare for detachable drivers (think pcmcia).

While there remove some sets of function pointers always pointing to the
same function (meant to be the configurable set of D channel protocol
handlers). It is unlikely another supported D-channel protocol will fit into
that (maximal layer interface) abstraction. When we get support for another
protocol, we will need to come up with a workable interface. Besides, the
old implementation was, uhm, strange.
 1.1 20-Feb-2001  martin branches: 1.1.2; 1.1.4;
Filename cleanup: remove i4b_ prefixes outside sys/netisdn, last round.

Renamed in sys/dev/ic:
i4b_hscx.c -> hscx.c
i4b_hscx.h -> hscx.h
i4b_ipac.h -> ipac.h
i4b_isac.c -> isac.c
i4b_isac.h -> isac.h
i4b_isic.c -> isic.c
i4b_isicbchan.c -> isic_bchan.c
i4b_isicl1.c -> isic_l1.c
i4b_isicl1.h -> isic_l1.h
i4b_isicl1fsm.c -> isic_l1fsm.c
 1.1.4.3 27-Mar-2001  bouyer Sync with HEAD.
 1.1.4.2 12-Mar-2001  bouyer Sync with HEAD.
 1.1.4.1 20-Feb-2001  bouyer file isic.c was added on branch thorpej_scsipi on 2001-03-12 13:30:25 +0000
 1.1.2.6 07-Jan-2003  thorpej Sync with HEAD.
 1.1.2.5 20-Jun-2002  nathanw Catch up to -current.
 1.1.2.4 17-Apr-2002  nathanw Catch up to -current.
 1.1.2.3 01-Apr-2002  nathanw Catch up to -current.
(CVS: It's not just a program. It's an adventure!)
 1.1.2.2 14-Nov-2001  nathanw Catch up to -current.
 1.1.2.1 09-Apr-2001  nathanw Catch up with -current.
 1.2.2.2 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.2.2.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.17.2.1 30-May-2002  gehenna Catch up with -current.
 1.19.2.4 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.19.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.19.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.19.2.1 03-Aug-2004  skrll Sync with HEAD
 1.20.10.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.20.8.1 29-Apr-2005  kent sync with -current
 1.21.4.2 27-Oct-2007  yamt sync with head.
 1.21.4.1 21-Jun-2006  yamt sync with head.
 1.22.50.1 25-Oct-2007  bouyer Sync with HEAD.
 1.22.46.1 06-Nov-2007  matt sync with HEAD
 1.22.44.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.22.30.1 23-Oct-2007  ad Sync with head.
 1.23.16.1 02-Jun-2008  mjf Sync with HEAD.
 1.24.48.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.24.38.1 30-Oct-2012  yamt sync with head
 1.25.38.1 10-Jun-2019  christos Sync with HEAD
 1.25.36.1 30-Sep-2018  pgoyette Ssync with HEAD
 1.16 22-Sep-2018  maxv Remove isic(4). It is part of ISDN, which we are now retiring.
 1.15 27-Oct-2012  chs branches: 1.15.36; 1.15.38;
split device_t/softc for all remaining drivers.
replace "struct device *" with "device_t".
use device_xname(), device_unit(), etc.
 1.14 17-Jul-2011  joerg branches: 1.14.2; 1.14.12;
Retire varargs.h support. Move machine/stdarg.h logic into MI
sys/stdarg.h and expect compiler to provide proper builtins, defaulting
to the GCC interface. lint still has a special fallback.
Reduce abuse of _BSD_VA_LIST_ by defining __va_list by default and
derive va_list as required by standards.
 1.13 08-Apr-2008  cegger use aprint_*_dev and device_xname
 1.12 19-Oct-2007  ad branches: 1.12.16;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.11 11-Dec-2005  christos branches: 1.11.30; 1.11.44; 1.11.46; 1.11.50;
merge ktrace-lwp.
 1.10 27-Feb-2005  perry branches: 1.10.4;
nuke trailing whitespace
 1.9 21-May-2002  martin branches: 1.9.8; 1.9.16; 1.9.18;
Uniformly pass a "struct isdn_l3_driver *" through layer 2, so we
do not have to search for that driver later while we already knew it
at layer 1.
 1.8 25-Mar-2002  martin branches: 1.8.2;
Now that we have all pieces in place (and enough granularity to specify
B-channel and D-channel drivers separately) split the Fritz!PCI card
driver out of the isic driver.

The new device is called "ifpci" and uses the same D-channel driver as the
isic devices, but has it's own B-channel driver.
 1.7 24-Mar-2002  martin Now that we have all the pieces of the puzzle available start to unriddle
and move them in their proper places.

Move the BRI registry from layer 2 (duh!) to layer 4, so active cards
(which don't have layer 3 or layer 2 in their driver). Remove all remaining
hard coded controller and driver types. Remove any arbitrary hard coded
limits, at least those that show up in the internal API.

This fixes PR 15950.
 1.6 17-Mar-2002  martin Remove all knowledge about specific application (layer 4) drivers from
the generic layer 4 and layer 3 management system.

This should make the layer 4 driver API LKM clean - finaly.

Make the Fritz!PCI driver work again after resent changes (oops!),
noted by Frank Kardel (PR 15948) and Matthias Scheeler.
 1.5 17-Mar-2002  martin Clean up the application (layer 4) driver vs. B channel driver interface.
One step further on the way to make layer 4 drivers LKMable.
 1.4 13-Nov-2001  lukem add/cleanup RCSID
 1.3 25-Mar-2001  is branches: 1.3.2;
improve readibility
 1.2 24-Mar-2001  martin First step to cleanup the hardware driver <-> upper layers interface.
This now provides slightly more functionality than the FreeBSD layer1-newbus
interface. It was meant to be a simple change to one header and a few
c files, but the change rippled all through various stuff.

To prevent a change to the kernel<->userland interface right now the kernel
is now lying about card types to userland (but who cares). This will be fixed
when the userland interface changes, after layer 3 <-> layer 4 has been
fixed.

Functional changes:

Provide a clean interface for hardware drivers to attach to the upper
layers. This will need another small change in the B-channel handling
when a similar change to the layer 3 <-> layer 4 interface happens.

Avoid passing indices into global arrays of pointers around, instead pass
the pointers itself. Don't code hardware driver types by predefined magic
numbers (think LKM). Prepare for detachable drivers (think pcmcia).

While there remove some sets of function pointers always pointing to the
same function (meant to be the configurable set of D channel protocol
handlers). It is unlikely another supported D-channel protocol will fit into
that (maximal layer interface) abstraction. When we get support for another
protocol, we will need to come up with a workable interface. Besides, the
old implementation was, uhm, strange.
 1.1 20-Feb-2001  martin branches: 1.1.2; 1.1.4;
Filename cleanup: remove i4b_ prefixes outside sys/netisdn, last round.

Renamed in sys/dev/ic:
i4b_hscx.c -> hscx.c
i4b_hscx.h -> hscx.h
i4b_ipac.h -> ipac.h
i4b_isac.c -> isac.c
i4b_isac.h -> isac.h
i4b_isic.c -> isic.c
i4b_isicbchan.c -> isic_bchan.c
i4b_isicl1.c -> isic_l1.c
i4b_isicl1.h -> isic_l1.h
i4b_isicl1fsm.c -> isic_l1fsm.c
 1.1.4.3 27-Mar-2001  bouyer Sync with HEAD.
 1.1.4.2 12-Mar-2001  bouyer Sync with HEAD.
 1.1.4.1 20-Feb-2001  bouyer file isic_bchan.c was added on branch thorpej_scsipi on 2001-03-12 13:30:25 +0000
 1.1.2.4 20-Jun-2002  nathanw Catch up to -current.
 1.1.2.3 01-Apr-2002  nathanw Catch up to -current.
(CVS: It's not just a program. It's an adventure!)
 1.1.2.2 14-Nov-2001  nathanw Catch up to -current.
 1.1.2.1 09-Apr-2001  nathanw Catch up with -current.
 1.3.2.2 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.3.2.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.8.2.1 30-May-2002  gehenna Catch up with -current.
 1.9.18.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.9.16.1 29-Apr-2005  kent sync with -current
 1.9.8.1 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.10.4.1 27-Oct-2007  yamt sync with head.
 1.11.50.1 25-Oct-2007  bouyer Sync with HEAD.
 1.11.46.1 06-Nov-2007  matt sync with HEAD
 1.11.44.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.11.30.1 23-Oct-2007  ad Sync with head.
 1.12.16.1 02-Jun-2008  mjf Sync with HEAD.
 1.14.12.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.14.2.1 30-Oct-2012  yamt sync with head
 1.15.38.1 10-Jun-2019  christos Sync with HEAD
 1.15.36.1 30-Sep-2018  pgoyette Ssync with HEAD
 1.20 22-Sep-2018  maxv Remove isic(4). It is part of ISDN, which we are now retiring.
 1.19 27-Oct-2012  chs branches: 1.19.36; 1.19.38;
split device_t/softc for all remaining drivers.
replace "struct device *" with "device_t".
use device_xname(), device_unit(), etc.
 1.18 08-Apr-2008  cegger branches: 1.18.38; 1.18.48;
use aprint_*_dev and device_xname
 1.17 19-Oct-2007  ad branches: 1.17.16;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.16 11-Dec-2005  christos branches: 1.16.30; 1.16.44; 1.16.46; 1.16.50;
merge ktrace-lwp.
 1.15 27-Feb-2005  perry branches: 1.15.4;
nuke trailing whitespace
 1.14 03-Oct-2003  pooka branches: 1.14.8; 1.14.10;
Ready the kernel side of i4b for primary rate interface support by
removing assumptions that there are only two B channels and by
adding support for a varying number of channels.

Due to this, rename previously used isdn identified "bri" to "isdnif",
which better describes the current situation.
 1.13 25-Oct-2002  leo branches: 1.13.6;
Fritz!PCI v2.0 ISDN driver from FreeBSD.
 1.12 21-May-2002  martin Uniformly pass a "struct isdn_l3_driver *" through layer 2, so we
do not have to search for that driver later while we already knew it
at layer 1.
 1.11 29-Apr-2002  martin branches: 1.11.2;
Patches from Matthias Drochner, slightly modified by me:

Remove the clear-the-irq-after-enabling it dance (which had bad side
effects on some cards). Instead disble the ISAC receiver when we have
interrupts disabled. Adjust the interrupt handler to properly deal with
subtle differences of the ISAC implementation in IPAC chips.
 1.10 13-Apr-2002  martin Defer initialization of the ISAC chip until we enable interrupts - it gets
into a strange failure mode if we do it with disabled interrupt. When
(re-)enabling interrupts reset transmitter and receiver and clear any
pending state.
 1.9 10-Apr-2002  martin Remove some redundant tries to disable interupts. We already avoided enabling
them.
Fix a stupid typo when enabling/disabling interrupts: we clear pending
interrupts when enabling, not disbling isac interrupts.
 1.8 08-Apr-2002  martin Combine sc_enabled and sc_dying into one field sc_intr_valid, they are used
for the same purpose (ignoring invalid interrupts).

For cards that are not able to stop all interrupts (or we don't know a way
to do that in software, at least) run the clearirq callback even when
ignoring an interrupt because we are not enabled. Otherwise the card would
stop interrupting.

Reserve a driver specific callout handle and an int value in the generic
isic_softc to allow card drivers to implement fancy blinkenlights.
 1.7 01-Apr-2002  martin Move isic_intr_enable to a file not depending on the HSCX driver, so
ifpci-only configurations build again.

Remove the now unused controller enable function from the passive drivers
l2<->l1 interface.
 1.6 30-Mar-2002  martin Be a nice citizen, enable interrupts only when we are ready to talk
to the ISDN (i.e. when userland has /dev/isdn open).
 1.5 30-Mar-2002  martin Add a command to layer 1 drivers to update LED state for controllers that
have status LEDs.
 1.4 24-Mar-2002  martin Now that we have all the pieces of the puzzle available start to unriddle
and move them in their proper places.

Move the BRI registry from layer 2 (duh!) to layer 4, so active cards
(which don't have layer 3 or layer 2 in their driver). Remove all remaining
hard coded controller and driver types. Remove any arbitrary hard coded
limits, at least those that show up in the internal API.

This fixes PR 15950.
 1.3 13-Nov-2001  lukem add/cleanup RCSID
 1.2 24-Mar-2001  martin branches: 1.2.2;
First step to cleanup the hardware driver <-> upper layers interface.
This now provides slightly more functionality than the FreeBSD layer1-newbus
interface. It was meant to be a simple change to one header and a few
c files, but the change rippled all through various stuff.

To prevent a change to the kernel<->userland interface right now the kernel
is now lying about card types to userland (but who cares). This will be fixed
when the userland interface changes, after layer 3 <-> layer 4 has been
fixed.

Functional changes:

Provide a clean interface for hardware drivers to attach to the upper
layers. This will need another small change in the B-channel handling
when a similar change to the layer 3 <-> layer 4 interface happens.

Avoid passing indices into global arrays of pointers around, instead pass
the pointers itself. Don't code hardware driver types by predefined magic
numbers (think LKM). Prepare for detachable drivers (think pcmcia).

While there remove some sets of function pointers always pointing to the
same function (meant to be the configurable set of D channel protocol
handlers). It is unlikely another supported D-channel protocol will fit into
that (maximal layer interface) abstraction. When we get support for another
protocol, we will need to come up with a workable interface. Besides, the
old implementation was, uhm, strange.
 1.1 20-Feb-2001  martin branches: 1.1.2; 1.1.4;
Filename cleanup: remove i4b_ prefixes outside sys/netisdn, last round.

Renamed in sys/dev/ic:
i4b_hscx.c -> hscx.c
i4b_hscx.h -> hscx.h
i4b_ipac.h -> ipac.h
i4b_isac.c -> isac.c
i4b_isac.h -> isac.h
i4b_isic.c -> isic.c
i4b_isicbchan.c -> isic_bchan.c
i4b_isicl1.c -> isic_l1.c
i4b_isicl1.h -> isic_l1.h
i4b_isicl1fsm.c -> isic_l1fsm.c
 1.1.4.3 27-Mar-2001  bouyer Sync with HEAD.
 1.1.4.2 12-Mar-2001  bouyer Sync with HEAD.
 1.1.4.1 20-Feb-2001  bouyer file isic_l1.c was added on branch thorpej_scsipi on 2001-03-12 13:30:25 +0000
 1.1.2.6 11-Nov-2002  nathanw Catch up to -current
 1.1.2.5 20-Jun-2002  nathanw Catch up to -current.
 1.1.2.4 17-Apr-2002  nathanw Catch up to -current.
 1.1.2.3 01-Apr-2002  nathanw Catch up to -current.
(CVS: It's not just a program. It's an adventure!)
 1.1.2.2 14-Nov-2001  nathanw Catch up to -current.
 1.1.2.1 09-Apr-2001  nathanw Catch up with -current.
 1.2.2.2 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.2.2.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.11.2.1 30-May-2002  gehenna Catch up with -current.
 1.13.6.4 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.13.6.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.13.6.2 18-Sep-2004  skrll Sync with HEAD.
 1.13.6.1 03-Aug-2004  skrll Sync with HEAD
 1.14.10.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.14.8.1 29-Apr-2005  kent sync with -current
 1.15.4.1 27-Oct-2007  yamt sync with head.
 1.16.50.1 25-Oct-2007  bouyer Sync with HEAD.
 1.16.46.1 06-Nov-2007  matt sync with HEAD
 1.16.44.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.16.30.1 23-Oct-2007  ad Sync with head.
 1.17.16.1 02-Jun-2008  mjf Sync with HEAD.
 1.18.48.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.18.38.1 30-Oct-2012  yamt sync with head
 1.19.38.1 10-Jun-2019  christos Sync with HEAD
 1.19.36.1 30-Sep-2018  pgoyette Ssync with HEAD
 1.22 22-Sep-2018  maxv Remove isic(4). It is part of ISDN, which we are now retiring.
 1.21 27-Oct-2012  chs branches: 1.21.36; 1.21.38;
split device_t/softc for all remaining drivers.
replace "struct device *" with "device_t".
use device_xname(), device_unit(), etc.
 1.20 11-Dec-2005  christos branches: 1.20.110; 1.20.120;
merge ktrace-lwp.
 1.19 13-Jun-2005  jmc Constify return string
 1.18 27-Feb-2005  perry nuke trailing whitespace
 1.17 04-Feb-2005  perry de-__P
 1.16 03-Oct-2003  pooka branches: 1.16.8; 1.16.10;
Ready the kernel side of i4b for primary rate interface support by
removing assumptions that there are only two B channels and by
adding support for a varying number of channels.

Due to this, rename previously used isdn identified "bri" to "isdnif",
which better describes the current situation.
 1.15 11-Jul-2003  drochner fixed botched prototype,
while being here clean up whitespace
 1.14 08-Jul-2003  itojun function prototype must not have variable name
 1.13 25-Oct-2002  leo branches: 1.13.6;
Fritz!PCI v2.0 ISDN driver from FreeBSD.
 1.12 10-Apr-2002  martin Remove some redundant tries to disable interupts. We already avoided enabling
them.
Fix a stupid typo when enabling/disabling interrupts: we clear pending
interrupts when enabling, not disbling isac interrupts.
 1.11 08-Apr-2002  martin Combine sc_enabled and sc_dying into one field sc_intr_valid, they are used
for the same purpose (ignoring invalid interrupts).

For cards that are not able to stop all interrupts (or we don't know a way
to do that in software, at least) run the clearirq callback even when
ignoring an interrupt because we are not enabled. Otherwise the card would
stop interrupting.

Reserve a driver specific callout handle and an int value in the generic
isic_softc to allow card drivers to implement fancy blinkenlights.
 1.10 06-Apr-2002  martin Remove leftover from my first, incomplete attempt to cope with detaching
pcmcia cards. Now that pcmcia attachements properly handle the activate
callback, this is no longer needed (and is suspect to cause completely
unrelated problems.)
 1.9 30-Mar-2002  martin Be a nice citizen, enable interrupts only when we are ready to talk
to the ISDN (i.e. when userland has /dev/isdn open).
 1.8 30-Mar-2002  martin Add a command to layer 1 drivers to update LED state for controllers that
have status LEDs.
 1.7 27-Mar-2002  martin After Jason Thorpe explained to me how it is supposed to work, implement
(de)activate for pcmcia cards.
Implement detach/(de)activate for PCI cards.
Clean up internal state (free call-descriptors) if a controller is
detached while it has open connections.
 1.6 25-Mar-2002  martin Now that we have all pieces in place (and enough granularity to specify
B-channel and D-channel drivers separately) split the Fritz!PCI card
driver out of the isic driver.

The new device is called "ifpci" and uses the same D-channel driver as the
isic devices, but has it's own B-channel driver.
 1.5 25-Mar-2002  martin Make pcmcia cards detach properly.
Notify userland of attaching/detaching cards.
This partly fixes PR 15951.
 1.4 24-Mar-2002  martin Now that we have all the pieces of the puzzle available start to unriddle
and move them in their proper places.

Move the BRI registry from layer 2 (duh!) to layer 4, so active cards
(which don't have layer 3 or layer 2 in their driver). Remove all remaining
hard coded controller and driver types. Remove any arbitrary hard coded
limits, at least those that show up in the internal API.

This fixes PR 15950.
 1.3 17-Mar-2002  martin Remove all knowledge about specific application (layer 4) drivers from
the generic layer 4 and layer 3 management system.

This should make the layer 4 driver API LKM clean - finaly.

Make the Fritz!PCI driver work again after resent changes (oops!),
noted by Frank Kardel (PR 15948) and Matthias Scheeler.
 1.2 24-Mar-2001  martin branches: 1.2.2;
First step to cleanup the hardware driver <-> upper layers interface.
This now provides slightly more functionality than the FreeBSD layer1-newbus
interface. It was meant to be a simple change to one header and a few
c files, but the change rippled all through various stuff.

To prevent a change to the kernel<->userland interface right now the kernel
is now lying about card types to userland (but who cares). This will be fixed
when the userland interface changes, after layer 3 <-> layer 4 has been
fixed.

Functional changes:

Provide a clean interface for hardware drivers to attach to the upper
layers. This will need another small change in the B-channel handling
when a similar change to the layer 3 <-> layer 4 interface happens.

Avoid passing indices into global arrays of pointers around, instead pass
the pointers itself. Don't code hardware driver types by predefined magic
numbers (think LKM). Prepare for detachable drivers (think pcmcia).

While there remove some sets of function pointers always pointing to the
same function (meant to be the configurable set of D channel protocol
handlers). It is unlikely another supported D-channel protocol will fit into
that (maximal layer interface) abstraction. When we get support for another
protocol, we will need to come up with a workable interface. Besides, the
old implementation was, uhm, strange.
 1.1 20-Feb-2001  martin branches: 1.1.2; 1.1.4;
Filename cleanup: remove i4b_ prefixes outside sys/netisdn, last round.

Renamed in sys/dev/ic:
i4b_hscx.c -> hscx.c
i4b_hscx.h -> hscx.h
i4b_ipac.h -> ipac.h
i4b_isac.c -> isac.c
i4b_isac.h -> isac.h
i4b_isic.c -> isic.c
i4b_isicbchan.c -> isic_bchan.c
i4b_isicl1.c -> isic_l1.c
i4b_isicl1.h -> isic_l1.h
i4b_isicl1fsm.c -> isic_l1fsm.c
 1.1.4.3 27-Mar-2001  bouyer Sync with HEAD.
 1.1.4.2 12-Mar-2001  bouyer Sync with HEAD.
 1.1.4.1 20-Feb-2001  bouyer file isic_l1.h was added on branch thorpej_scsipi on 2001-03-12 13:30:25 +0000
 1.1.2.4 11-Nov-2002  nathanw Catch up to -current
 1.1.2.3 17-Apr-2002  nathanw Catch up to -current.
 1.1.2.2 01-Apr-2002  nathanw Catch up to -current.
(CVS: It's not just a program. It's an adventure!)
 1.1.2.1 09-Apr-2001  nathanw Catch up with -current.
 1.2.2.1 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.13.6.6 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.13.6.5 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.13.6.4 04-Feb-2005  skrll Sync with HEAD.
 1.13.6.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.13.6.2 18-Sep-2004  skrll Sync with HEAD.
 1.13.6.1 03-Aug-2004  skrll Sync with HEAD
 1.16.10.2 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.16.10.1 12-Feb-2005  yamt sync with head.
 1.16.8.1 29-Apr-2005  kent sync with -current
 1.20.120.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.20.110.1 30-Oct-2012  yamt sync with head
 1.21.38.1 10-Jun-2019  christos Sync with HEAD
 1.21.36.1 30-Sep-2018  pgoyette Ssync with HEAD
 1.15 22-Sep-2018  maxv Remove isic(4). It is part of ISDN, which we are now retiring.
 1.14 17-Jul-2011  joerg branches: 1.14.52; 1.14.54;
Retire varargs.h support. Move machine/stdarg.h logic into MI
sys/stdarg.h and expect compiler to provide proper builtins, defaulting
to the GCC interface. lint still has a special fallback.
Reduce abuse of _BSD_VA_LIST_ by defining __va_list by default and
derive va_list as required by standards.
 1.13 19-Oct-2007  ad machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.12 11-Dec-2005  christos branches: 1.12.30; 1.12.44; 1.12.46; 1.12.50;
merge ktrace-lwp.
 1.11 01-Jun-2005  drochner branches: 1.11.2;
quell cast-qual and shadow warnings
 1.10 27-Feb-2005  perry nuke trailing whitespace
 1.9 29-Oct-2002  leo branches: 1.9.6; 1.9.14; 1.9.16;
Fix typo (isic_isac_recover -> isic_recover). Noticed by Matthias Drochner.
 1.8 25-Oct-2002  leo Fritz!PCI v2.0 ISDN driver from FreeBSD.
 1.7 27-Sep-2002  provos remove trailing \n in panic(). approved perry.
 1.6 04-Jun-2002  martin #if some tables and a helper function for debug output to make it
possible to compile this without ISDN debugging support.

Fixes PR kern/17161.
 1.5 21-May-2002  martin branches: 1.5.2;
Uniformly pass a "struct isdn_l3_driver *" through layer 2, so we
do not have to search for that driver later while we already knew it
at layer 1.
 1.4 24-Mar-2002  martin branches: 1.4.2;
Now that we have all the pieces of the puzzle available start to unriddle
and move them in their proper places.

Move the BRI registry from layer 2 (duh!) to layer 4, so active cards
(which don't have layer 3 or layer 2 in their driver). Remove all remaining
hard coded controller and driver types. Remove any arbitrary hard coded
limits, at least those that show up in the internal API.

This fixes PR 15950.
 1.3 13-Nov-2001  lukem add/cleanup RCSID
 1.2 24-Mar-2001  martin branches: 1.2.2;
First step to cleanup the hardware driver <-> upper layers interface.
This now provides slightly more functionality than the FreeBSD layer1-newbus
interface. It was meant to be a simple change to one header and a few
c files, but the change rippled all through various stuff.

To prevent a change to the kernel<->userland interface right now the kernel
is now lying about card types to userland (but who cares). This will be fixed
when the userland interface changes, after layer 3 <-> layer 4 has been
fixed.

Functional changes:

Provide a clean interface for hardware drivers to attach to the upper
layers. This will need another small change in the B-channel handling
when a similar change to the layer 3 <-> layer 4 interface happens.

Avoid passing indices into global arrays of pointers around, instead pass
the pointers itself. Don't code hardware driver types by predefined magic
numbers (think LKM). Prepare for detachable drivers (think pcmcia).

While there remove some sets of function pointers always pointing to the
same function (meant to be the configurable set of D channel protocol
handlers). It is unlikely another supported D-channel protocol will fit into
that (maximal layer interface) abstraction. When we get support for another
protocol, we will need to come up with a workable interface. Besides, the
old implementation was, uhm, strange.
 1.1 20-Feb-2001  martin branches: 1.1.2; 1.1.4;
Filename cleanup: remove i4b_ prefixes outside sys/netisdn, last round.

Renamed in sys/dev/ic:
i4b_hscx.c -> hscx.c
i4b_hscx.h -> hscx.h
i4b_ipac.h -> ipac.h
i4b_isac.c -> isac.c
i4b_isac.h -> isac.h
i4b_isic.c -> isic.c
i4b_isicbchan.c -> isic_bchan.c
i4b_isicl1.c -> isic_l1.c
i4b_isicl1.h -> isic_l1.h
i4b_isicl1fsm.c -> isic_l1fsm.c
 1.1.4.3 27-Mar-2001  bouyer Sync with HEAD.
 1.1.4.2 12-Mar-2001  bouyer Sync with HEAD.
 1.1.4.1 20-Feb-2001  bouyer file isic_l1fsm.c was added on branch thorpej_scsipi on 2001-03-12 13:30:25 +0000
 1.1.2.6 11-Nov-2002  nathanw Catch up to -current
 1.1.2.5 18-Oct-2002  nathanw Catch up to -current.
 1.1.2.4 20-Jun-2002  nathanw Catch up to -current.
 1.1.2.3 01-Apr-2002  nathanw Catch up to -current.
(CVS: It's not just a program. It's an adventure!)
 1.1.2.2 14-Nov-2001  nathanw Catch up to -current.
 1.1.2.1 09-Apr-2001  nathanw Catch up with -current.
 1.2.2.3 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.2.2.2 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.2.2.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.4.2.2 20-Jun-2002  gehenna catch up with -current.
 1.4.2.1 30-May-2002  gehenna Catch up with -current.
 1.5.2.1 05-Jun-2002  lukem Pull up revision 1.6 (requested by martin in ticket #161):
possible to compile this without ISDN debugging support.
Fixes PR kern/17161.
 1.9.16.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.9.14.1 29-Apr-2005  kent sync with -current
 1.9.6.2 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.9.6.1 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.11.2.1 27-Oct-2007  yamt sync with head.
 1.12.50.1 25-Oct-2007  bouyer Sync with HEAD.
 1.12.46.1 06-Nov-2007  matt sync with HEAD
 1.12.44.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.12.30.1 23-Oct-2007  ad Sync with head.
 1.14.54.1 10-Jun-2019  christos Sync with HEAD
 1.14.52.1 30-Sep-2018  pgoyette Ssync with HEAD
 1.135 12-Dec-2021  andvar fix various typos, mainly in comments.
 1.134 12-Dec-2021  andvar fix typos in word "request(s)".
 1.133 05-Dec-2021  rillig isp: fix typo in comment
 1.132 05-Dec-2021  msaitoh s/corret/correct/ in comment.
 1.131 21-Oct-2021  andvar fix various typos, mainly in comments, but also in man pages and log messages.
 1.130 19-Sep-2021  andvar fix various typos in comments, messages and documentation.
 1.129 11-Sep-2021  andvar Add missing double p and d for stopped and overriden accordingly.
Fix few more typos along the way, mainly in copy-pasted comments.
 1.128 06-Sep-2021  andvar fix various typos in comments.
 1.127 08-Feb-2018  dholland Typos.
 1.126 11-Mar-2017  maya Don't loop infinitely if the output pointer was changed
Untested, but the change done seems to match the comment above it

CID 980321
 1.125 14-Sep-2013  joerg branches: 1.125.6; 1.125.10; 1.125.14;
GC unused functions and variables.
 1.124 14-Sep-2013  martin Remove unused variables, use C99 open arrays for variable sized arrays
 1.123 27-Feb-2013  martin branches: 1.123.6;
Disable ICBOPT_FAST_POST for ISP 2100.
Fixes PR kern/47302. From Matthew Jacob.
 1.122 28-Feb-2011  mjacob branches: 1.122.4; 1.122.10; 1.122.14;
Update isp driver to be in sync with other platforms. Mostly very minor changes
with effectively zero impact on NetBSD.
 1.121 26-Mar-2010  mjacob branches: 1.121.2; 1.121.4;
Synchronize with other platforms:

Strongly architect handles so we can more easily detect bogus
handles. This switches us to a full 32 bits for all handles.

Handle the case of FC disks disappearing and then reappearing-
at least at the FC transport level.

Some better and finer control of debug and non-debug printouts.
 1.120 15-Jan-2010  mjacob branches: 1.120.2; 1.120.4;
Amazingly, we've been freeing a handle and then using that which it referred
to for years. Bad.
 1.119 05-Jan-2010  mbalmer Remove extra semicolons.
 1.118 03-Jan-2010  mjacob Add some more definitions appropriate for T10 standards
and use those cleaned up definitions.

Use 2100 style firmware loading if the load address and
load size is less than 64k. Some apparently buggy ROMs
out there choke otherwise.

Clean up some WWNN derivations from WWPN.
 1.117 25-Jun-2009  mjacob Update ISP driver to latest and greatest. Includes support for the 8Gb part.
 1.116 03-Jan-2009  yamt branches: 1.116.2;
remove extra semicolons.
 1.115 11-May-2008  mjacob branches: 1.115.6;
Make fc scratch acquisition something that can fail. Remove in_intr flag.
Otherwise synchronize with changes made due to other platforms.
 1.114 11-Mar-2008  mjacob branches: 1.114.2; 1.114.4; 1.114.6;
Checkpoint of some fairly major isp(4) rototilling.

Reintroduce more of a 'channel' concept in preparation for NP-IV support.
This gets rid of the chanA/chanB concept as the 2400 can have up to 128
virtual channels. Actually, with MID firmware you can also have the 2200
and 2300 support 'channels, but they do it with an FL-Port topology.
Because FC cards can now have 'channels', just about every support
function for fibre channel had to be redone to have a channel index
as well. Rototill isp_ioctl.h for channel stuff as well.

Pick up a lot of work about fabric management (hopefully better) and keep
work in place that will allow for dynamic attachment/detachment of devices
(if I can figure out how to make the midlayer support it).

Merge the target code with external trees. Eventually it might even
be sorted out on NetBSD.

Update some firmware stuff.
 1.113 07-Jul-2007  mjacob branches: 1.113.8; 1.113.24; 1.113.28;
Do a number of 24XX related fixes: fix the actual getting of initiator
status correctly (which we never were doing before). Add an underrun
checker for 24XX. The process of sorting this out led to a whole bunch
of endian surprises that had to be dealt with. Fix NVRAM endian issues
for the 24XX as well.

Do a little 2200 related cleanup- in particular, turn off complaints about
not finding a fast posting handle when running with RIO enabled- we are
somehow getting duplicate completions in this case. If we ignore them and
don't complain, all is well, and we actually start averaging > 2 commands
completed per interrupt.
 1.112 26-Jun-2007  mjacob When loading firmware for the 23XX and 24XX cards and DMA'ing it from
the request queue, remember to convert it to little endian format.
 1.111 24-May-2007  mjacob Major update to isp(4) driver to bring it in line with external sources.

The major changes are:

+ 4Gb (24XX) card support
+ Rewritten fabric and loop evaluation code
+ New f/w sets

The 4Gb changes required major rototilling, which caused a rewrite of
fabric and loop eval code. The latter can now be set up to tune for
dynamic device arrival/departure if the framework is set up for it,
or to be firm about waiting for devices.

Testing has been principally on amd64, i386 and sparc64 and seems to
not have broken things for me.
 1.110 16-Nov-2006  christos branches: 1.110.8; 1.110.10;
__unused removal on arguments; approved by core.
 1.109 12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.108 11-Dec-2005  christos branches: 1.108.20; 1.108.22;
merge ktrace-lwp.
 1.107 30-May-2005  christos branches: 1.107.2;
- add missing const
- fix variable shadowing
- remove unneeded casts
 1.106 27-Feb-2005  perry nuke trailing whitespace
 1.105 04-Dec-2003  keihan branches: 1.105.8; 1.105.10;
netbsd.org -> NetBSD.org

This was the last commit of this kind to src/sys, which is now totally
"NetBSD.org clean". Thanks for the patiance, and sorry for all the commits.
 1.104 02-Nov-2003  wiz Fix some typos. From Tom Cosgrove via jmc@openbsd.
 1.103 07-Aug-2003  mjacob Update from mainline: add ISP_NO_ZIO option. constify a few items.
LINT/ProPolice fixes from OpenBSD.

In isp_reinit, clear the port database.
 1.102 03-May-2003  wiz branches: 1.102.2;
DMA, not dma nor Dma.
 1.101 03-Mar-2003  mjacob Spelling fixes. Leave an example for how to set icbdelay timer for
ZIO operations. If we have ISP_FW_CRASH_DUMP defined, don't reinit
the chip on ISP_CONN_FATAL (that's up to the outer layers to do).
 1.100 25-Nov-2002  thorpej Avoid strict-alias warnings.
 1.99 18-Oct-2002  mjacob Add in (sight unseen) 10160 support.

Start doing the work necessary to support DAC (Dual Address Cycle)
environments. This allows for direct DMA to > 4GB memory from a PCI
card.

Lose STRNCAT over the side and use SNPRINTF instead.
 1.98 17-Aug-2002  mjacob If we're using ancient (pre 1.17.0) 2100 f/w (for the cards that cannot
load f/w images > 0x7fff words), set ISP_FW_ATTR_SCCLUN. We explicitly
don't believe we can find attributes if f/w is < 1.17.0, so we have to
set SCCLUN for the 1.15.37 f/w we're using manually- otherwise every
target will replicate itself across all 16 supported luns for non-SCCLUN
f/w.
 1.97 16-Aug-2002  mjacob Further fix problems with 23XX ISR handling and correctly initialize the
23XX to use ZIO in preference to fast posting.
 1.96 12-Aug-2002  mjacob Various changes to allow for overriding just loopid and/or iid.
Fix a random 23XX ISR reading bug. Be chattier about HBA_BOTCH
errors. More f/w cashdump layering.
 1.95 15-Jun-2002  mjacob Make sure we set maxluns even if isp_touched is already set.

Do a fallback on reading stuff from the fabric. Some devices/initiators
don't correctly register their type with the fabric nameserver. This
seems to be due to a misinterpretation of what TYPE should mean for a
CT_HDR. In any case, do a fallback to try and catch these misentered
entities.

Add some stuff for default framesize and throttle. Fix some buglets.
 1.94 17-May-2002  mjacob Fix seveeral issues- but the most important of which is that we have
to check if we get a RQCS_DATA_UNDERRUN - if we're an FC card, we may
not have RQCS_RU set- if it isn't set, we just lost a DATA XFR IU in the
middle of the exchange. In this case, we have to bomb out the whole xfer.
We had been getting silent data corruption before.
 1.93 20-Apr-2002  mjacob branches: 1.93.2;
Number of luns supported for SCC-2 is actually really 16384- top
3 bits are lun address modifiers.

Remove code that (incorrectly) thought it was asking the f/w to only
PLOGI if not already PLOGI'd. The current f/w documentation tells us
that we have this backwards.
 1.92 11-Apr-2002  mjacob Clean up a bit from the last checkin so that the correct result pointers
are used- didn't make a difference, but hey...

Put in commented out GFF_ID code- for use in future attempts to search
the fabric- this probably has to go thru the management server path.

Don't whine about handles we can't find if these are aborted commands
(we know we can't find the handles because we destroy handles after
a successful mailbox abort- we don't wait for the F/W to decide whether
it wants to return a status IOCB after this happens).
 1.91 04-Apr-2002  mjacob Redo fabric evaluation to not use GET ALL NEXT (GA_NXT). Switches seem
to be trying to wriggle out of supporting this well. Instead, use
GID_FT to get a list of Port IDs and then use GPN_ID/GNN_ID to find the
port and node wwn. This should make working on fabrics a bit cleaner and
more stable.

This also caused some cleanup of SNS subcommand canonicalization so that
we can actually check for FS_ACC and FS_RJT, and if we get an FS_RJT,
print out the reason and explanation codes.

We'll keep the old GA_NXT method around if people want to uncomment a
controlling definition in ispvar.h.

This also had us clean up ISPASYNC_FABRICDEV to use a local lportdb argument
and to have the caller explicitly say that a device is at the end of the
fabric list.
 1.90 22-Mar-2002  mjacob Handle Port Unavailable the same as Port Logout (i.e., send a LIP).

Unconst pointer to f/w in the ispdv structure. Too many compilers get
unhappy over our walking the array. Make casts as appropriate so that
initialization in structure is still happy.

Limit length of fabric to 256. This will all go away soon.

Do a cleaner case of keeping multiple CPUs/threads from reading the
same response queue entries.
 1.89 07-Mar-2002  mjacob Disable RIO (reduced interrupt operation) for 2200 boards- it seemed like
it worked- but I ran into a case with a 2204 where commands were being lost
right and left. Best be safe.

For target mode, or things called if we call isp_handle_other response- note
that we might have dropped locks by changing the output pointer so we bail
from the loop. It's the responsibility of the entity dropping the lock to
make sure that we let the f/w know we've read thus far into the response
queue (else we begin processing the same entries again- blech!).
 1.88 21-Feb-2002  mjacob Implement F/W crashdumps for 2200 && 2300 cards (kernel compile option).

Distinguish between 2312 and 2300 cards (they *are* different). Enable
RIO (Reduced Interrupt Operation) for the LVD cards (hey- I've seen
batched completions of the 30 commands at a time with this,....)...

If we get a Port Logout on local loop topologies, we have to force the
f/w to log back in. The easiest way (for us) to do this is to force
a LIP. This also will wake up the disk that probably just had a f/w crash.

Implement mailbox 'continuations'- this allows interrupts to re-drive
a mailbox command if it's one that just essentially repeats the previous
mailbox command (e.g., f/w download). This saves a boatload of sleep/wakeup
twitches.

If we're not a 2300 and we're about to return with a 'bogus interrupt'- check
the semaphore register to be non-zero at all and outgoing mailbox 0- this
seems to be where some of the lost ISP1080 commands came from.
 1.87 03-Jan-2002  mjacob Implement REDUCED INTERRUPT OPERATION usage for FC cards- this allows the
firmware to delay completion of commands so that it can attempt to batch
a bunch of completions at once- either returning 16 bit handles in mailbox
registers, or in a resposne queue entry that has a whole wad of 16 bit handles.

Distinguish between 2300 and 2312 chipsets- if only because the revisions
on the chips have different meanings.

Add more instrumentation plus ISP_GET_STATS and ISP_CLR_STATS ioctls.
Run up the maximum number of response queue entities we'll look at
per interrupt.

If we haven't set HBA role yet, always return success from isp_fc_runstate.
 1.86 14-Dec-2001  mjacob Major restructuring for swizzling to the request queue and unswizzling from
the response queue. Instead of the ad hoc ISP_SWIZZLE_REQUEST, we now have
a complete set of inline functions in isp_inline.h. Each platform is
responsible for providing just one of a set of ISP_IOX_{GET,PUT}{8,16,32}
macros.

The reason this needs to be done is that we need to have a single set of
functions that will work correctly on multiple architectures for both little
and big endian machines. It also needs to work correctly in the case that
we have the request or response queues in memory that has to be treated
specially (e.g., have ddi_dma_sync called on it for Solaris after we update
it or before we read from it).

One thing that falls out of this is that we no longer build requests in the
request queue itself. Instead, we build the request locally (e.g., on the
stack) and then as part of the swizzling operation, copy it to the request
queue entry we've allocated. I thought long and hard about whether this was
too expensive a change to make as it in a lot of cases requires an extra
copy. On balance, the flexbility is worth it. With any luck, the entry that
we build locally stays in a processor writeback cache (after all, it's only
64 bytes) so that the cost of actually flushing it to the memory area that is
the shared queue with the PCI device is not all that expensive. We may examine
this again and try to get clever in the future to try and avoid copies.

Another change that falls out of this is that MEMORYBARRIER should be taken
a lot more seriously. The macro ISP_ADD_REQUEST does a MEMORYBARRIER on the
entry being added. But there had been many other places this had been missing.
It's now very important that it be done.

For NetBSD, it does a ddi_dmamap_sync as appropriate. This gets us out of
the explicit ddi_dmamap_sync on the whole response queue that we did for SBus
cards at each interrupt.

Set things up so that platforms that cannot have an SBus don't get a lot of
the SBus code checks (dead coded out).

Additional changes:

Fix a longstanding buglet of sorts. When we get an entry via isp_getrqentry,
the iptr value that gets returned is the value we intend to eventually plug
into the ISP registers as the entry *one past* the last one we've written-
*not* the current entry we're updating. All along we've been calling sync
functions on the wrong index value. Argh. The 'fix' here is to rename all
'iptr' variables as 'nxti' to remember that this is the 'next' pointer-
not the current pointer.

Devote a single bit to mboxbsy- and set aside bits for output mbox registers
that we need to pick up- we can have at least one command which does not
have any defined output registers (MBOX_EXECUTE_FIRMWARE).

Explicitly decode GetAllNext SNS Response back *as* a GetAllNext response.
Otherwise, we won't unswizzle it correctly.

Nuke some additional __P macros.
 1.85 13-Nov-2001  lukem add/cleanup RCSID
 1.84 23-Oct-2001  mjacob tra-la, another QLogic f/w funny- this time with the 2300.
If we get a completion status of RQCS_QUEUE_FULL, it means
that the internal queues are full. Other QLogic boards set
the QFULL SCSI status. But *nooooooooooo*, not the 2300.
 1.83 23-Oct-2001  mjacob Comment out some redundant initializations to zero.
 1.82 20-Oct-2001  mjacob Protect against deranged fabric nameservers that spit out 10000 identical
port numbers.
 1.81 06-Oct-2001  mjacob Fix various 2300 GB issues related to chip errata and documentation
misunderstandings. We also now can report our connection rate.
 1.80 05-Sep-2001  mjacob branches: 1.80.2;
Clean up some issues wrt loaded f/w vs. resident f/w. We can tell
attributes of some variants of FC f/w (SCCLUN or not). Fake f/w
rev for SBus cards- the f/w versions we're using don't return
version in outgoing mailbox registers like they should.
 1.79 01-Sep-2001  mjacob Add support for 2 Gigabit cards (2300/2312). This necessitated a change
in how interrupts are down- the 23XX has not only a different place to check
for an interrupt, but unlike all other QLogic cards, you have to read the
status as a 32 bit word- not 16 bit words. Rather than have device specific
functions as called from the core module (in isp_intr), it makes more sense
to have the platform/bus modules do the gruntwork of splitting out the
isr, semaphore register and the first outgoing mailbox register (if needed)
*prior* to calling isp_intr (if calling isp_intr is necessary at all).
 1.78 06-Jul-2001  mjacob branches: 1.78.2;
Some whitespace cleanup. Initial forcelout support.

Fix longstanding bug where we should have been checking
against Channel B's settings to see whether to apply tag
usage. Oops.

Some more 2300 support- macroize access to request queue in/out pointers.
Firmware crashes now handled in platform outer code via an isp_async call.

If we get a LIP, and we're on a private or public loop, kill off all
active commands as if they had been killed by a 'SCSI Bus Reset'. I've
seen data corruption on commands that complete 'normally' after a LIP.
Bad.
 1.77 25-May-2001  mjacob Create a kernel thread for Fibre Channel cards. This is the new
way of doing business- modulo some startup spasms and peculiarities
of the way kthreads are started (*after* configuration, weird) and
some strangeness with the freeze/thaw code, what now happens is
that any of Loop Down, LIP, Loop Reset or Port Datbase or Name
Server Database Changed ASYNC events cause the queues to freeze
for this channel. The arrival of a Loop UP is not relevant.

What *is* relevant is that the Port Datbase or Name Server Changed
async event indicate that it's okay to go and (re)evaluate the
state of the FC link and (re)probe local loop and fabric membership.
We have a kthread do this because it's *sooooo* much nicer to be
able to sleep while doing the 130-250 mailbox commands it'll take
to re-evaluate things.

When the state is well known again, we can unfreeze the channel
queues. Then, as commands start arriving, we simply can start them
or bounce them with XS_SELTIMEOUT (if the device in question has
gone away). Previously, we did lazy evaluation, which meant that
if a change occurred, we would wait until the very *next* command
to go rebuild stuff.

The reason this is not sensible is:

a) Even with sleeping, you can hang up your system because you might be
making some poor stat(2) call pay the price of re-evaluating the whole
fabric.

b) If we ever really want to get to dynamic attachment/detachment, we
should find out sooner, rather than later, where things get to.

Split off ispminphys_1020 from ispminphys- a 1020 has a 24 bit limit-
not anything newer.

Re-enable LIPs and Loop Resets as async events- this allows the outer
layer to set policy about them.

Roll platform major && minor. Remove bogus waitq (no longer used).
Remove callout entry in softc (no longer used). Define some shorthands
for channels. Clean up a variety of cruft left over from the
thorpej_scsipi changeover.
 1.76 16-May-2001  mjacob beginning basic 2300 infrstructure support
 1.75 10-Apr-2001  mjacob Note one other place that bogus interrupts can be measured.
 1.74 05-Apr-2001  mjacob Change how SCSI defaults are latched if we're supporting Target Mode.
Make sure we pick up the channel for dual bus cards when enabling target
mode. Catch a silly null pointer dereference.
 1.73 14-Mar-2001  mjacob Update copyright date. ANSIfy isp.c (NetBSD was the holdout of all
the platforms this code runs on). Handles are now u_int16_t, so adjust
code as required.
 1.72 23-Feb-2001  mjacob branches: 1.72.2;
Fix a longstanding bug- we had the sense of what bit 14
for the ICB firmware options meant- *I* had taken it to
mean that if you set it, Node Name would be ignored and
derived from Port Name. Actually, it meant the opposite.
As a consequence- change ICBOPT_USE_PORTNAME to the
define ICBOPT_BOTH_WWNS- makes more sense.
 1.71 20-Feb-2001  mjacob Add ISPCTL_RUN_MBOXCMD control function and ISPASYNC_UNHANDLED_RESPONSE
async event. Call ISP_DUMPREGS on f/w erro. Correct problem in bitmap
for MBOX_DUMP_RAM.
 1.70 12-Feb-2001  mjacob Minor stuff:
Remove ISP2100_FABRIC defines- we always handle fabric now. Insert
isp_getmap helper function (for getting Loop Position map). Make
sure we (for our own benefit) mark req_state_flags with RQSF_GOT_SENSE
for Fibre Channel if we got sense data- the !*$)!*$)~*$)*$ Qlogic
f/w doesn't do so. Add ISPCTL_SCAN_FABRIC, ISPCTL_SCAN_LOOP, ISPCTL_SEND_LIP,
and ISPCTL_GET_POSMAP isp_control functions. Correctly send async notifications
upstream for changes in the name server, changes in the port database, and
f/w crashes. Correctly set topology when we get a ASYNC_PTPMODE event.

When resetting the Qlogic 2X00 units, reset the FPM (Fibre Protocol
Module) and FBM (Fibre Buffer Modules). Also remember to clear the
semaphore registers. Tell the RISC processor to not halt on FPM
parity errors.


Finally, use a new tag in the softc to store the opcode for the
last mailbox command used so we can report which opcode timed
out.

Major stuff:
Quite massively redo how we handle Loop events- we've now added several
intermediate states between LOOP_PDB_RCVD and LOOP_READY. This allows us
a lot finer control about how we scan fabric, whether we go further
than scanning fabric, how we look at the local loop, and whether we
merge entries at the level or not. This is the next to last step for
moving managing loop state out of the core module entirely (whereupon
loop && fabric events will simply freeze the command queue and a thread
will run to figure out what's changed and *it* will re-enable the queu).
This fine amount of control also gets us closer to having an external
policy engine decide which fabric devices we really want to log into.

Throw out the ISP_CFG_NOINIT silliness and instead go to the use of
adapter 'roles' to see whether one completes initialization or not
(mostly for Fibre Channel). The ultimate intent, btw, of all of this
is to have a warm standby adapter for failover reasons. Because
we do roles now, setting of Target Capable Class 3 service parameters
in the ICB for the 2x00 cards reflects from role. Also, in isp_start,
if we're not supporting an initiator role, we bounce outgoing commands
with a Selection Timeout error. Also clean out the TOGGLE_TMODE
goop for FC- there is no toggling of target mode like there is
for parallel SCSI cards.

Do more cleanup with respect to using target ids 0..125 in F-port
topologies. Also keep track of things which *were* fabric devices
so that when you rescan the fabric you can notify the outer layers
when fabric devices go away.

Only force a LOGOUT for fabric devices if they're still logged in
(i.e., you cat their Port Database entry. Clean up the Get All Next
scanning.
 1.69 09-Jan-2001  mjacob Use a SNS REGISTER FC4 TYPE subcommand to register with the name server.
This means we should be able to work with McData switches now. Change
ISPASYNC_PDB_CHANGED to ISPASYNC_LOGGED_INOUT (more descriptive). Allow
F-Port topologies to use target ids 0..125 to log into fabric devices.
Yet again fool around with defaul WWN stuff.
 1.68 30-Dec-2000  mjacob [ dummy checkin to add to previous CVS ]

It's probably not really a compiler bug- somebody pointed out
that it was the kernel making strings readonly. But I do think it's
a bug. The actual code was really more like:

char *revname;

...

revname = "2X00";

...
revname[1] = '2'; <<<<<<<<< BOOOM


The variable revname is not a const. If I had said

const char *revname = "2X00"
...
revname[1] = '2';

that would indeed be breaking const rules.
 1.67 30-Dec-2000  mjacob There's a compiler bug for sparc64 that makes the construct:

char *foo = "XXXX";
...
foo[1] = 'Y';

blow up (in the kernel) with the 2nd assignment. Work around it here-
it's probably just as well- I was spending more in cpu instructions doing
the assignment than I was saving in string space (it would have been
cheap on a pdp11 or a 68k- but the address loads and assignments on something
like sparc or alpha way outweigh the savings in space. Tsk.).
 1.66 28-Dec-2000  mjacob Apply nearly all of Bill Sommerfeld's -Wformat patches. The one
change I didn't take is the %llu format- I can't have a common
across multiple platform module assume a %ll argument capability-
which really pointed out that I shouldn't be trying to *print*
something which could long long.
 1.65 28-Dec-2000  mjacob Use the ISP_CFG_NOINIT flag to decide whether to complete the full init
process steps (this is used in some platforms where you want to bring
the adapter to ready (to get a WWN, e.g.) , but not engage either target
or initiator mode until some later time). Set the correct defaults WWNs.
 1.64 23-Dec-2000  wiz Fix pathnames in comment.
 1.63 09-Dec-2000  mjacob Finally fix this driver to be sensible about the ENDIAN dance. It's not
quite simply a question of the Qlogic being little endian and having
to have stuff swapped on big endian machines- it also has to do with the
fact that the SBus and PCI DMA layouts are wierd with respect to this.

At any rate, now finally fixed- works on Mac G4, tested it on a SS10
for sparc, checked on alpha to see if I've broken anything, and as
soon as I get another spare afternoon I'll finally install a sparc64
version which should just work (as it'll be like the Mac).
 1.62 16-Oct-2000  mjacob Clarify/cleanup how node and port names are derived from nvram. Remove
clause 2 of licence. Remember to print initiator ID (LOGINFO level).
 1.61 16-Aug-2000  mjacob Add some changes/notes suggested by eeh@netbsd.org (zero header of
response queue entry). Clean up some of the Fibre Channel completion
stuff so that thing we check actually match the current manual. There's
only one silly lossage that the manual doesn't cover at present- if
an FC command completes with SV (sense valid), the f/w does *not* s
et "GOT_STATUS" in the state bits- I guess they assume that you'd figure
out that if you have SENSE DATA you probably have a CHECK CONDITION. Still-
yet another fine f/w frotz from Qlogic. Add in an ISP_EXEC_THROTTLE
define to set a per-device execution throttle.
 1.60 14-Aug-2000  mjacob Add a maintenance note.

Clarify some startup SCSI mode settings. Insist that the FC f/w options
*must* have ICBOPT_PDBCHANGE_AE set (wasted a half day on this crock).

Make a specific comment in isp_start that the tags being selected for FC
cards, in lieu of any set by the outer layers, are there for safety's sake.
This removes the change from a previous commit.

For the ISP_TOGGLE_TMODE function, do a complete reset, not just an
isp_init (info from Solaris port). Make some cleanup changes for
code clarity.
 1.59 11-Aug-2000  tls Make our policy WRT tagged queueing consistent and sane: ordered tags for sync writes, simple tags for all else. Should make ahc and adv a bit more reliable (metadata writes won't get reordered incorrectly...) and isp a bit more performant (it was using ordered tags all the time).
 1.58 08-Aug-2000  mjacob Remove ispcmd_slow routine- SCBUSACCEL routine will set/clear tag/wide/sync.
Make some changes about where some things sit in the softc.
 1.57 01-Aug-2000  mjacob Core version 2.0 (platform version 1.0) rewrite of ISP driver. Some
interace cleanups, some new common functions. The major impact that
will be noticeable right away is that if you boot with not Fibre connected
to the FC cards, you no longer hang indefinitely.
 1.56 19-Jul-2000  mjacob fix mislabelled error case
 1.55 06-Jul-2000  mjacob Per advice from thorpej, reinstated some of Erik's changes.
 1.54 05-Jul-2000  mjacob Back out previous commit- the author is incorrect. There is no 'narrow'
Qlogic controller driven by this chipset. If they don't want the verbosity,
don't compile a DIAGNOSTIC kernel.

Major amount of mailbox command rewrites- hopefully should fix some of the
outstanding PRs.

Change header to note that this is no longer maintained at NASA/Ames.
 1.53 03-Jun-2000  fair branches: 1.53.2;
Change the debug level from 1 to 3 for "skipping target" diagnostic
which spews unreasonably for a Qlogic SCSI-2 narrow controller, which
does not have ID's above 7.
 1.52 13-May-2000  he branches: 1.52.2;
Update from Matthew Jacob:

Correctly account for F-port vs. F-port (no FLOGI_ACC) topologies.
Make sure we get a port database entry for the fabric name server.
Preserve fabric logins if the device didn't change across fabric
or port database changes, or the device has already logged into
us (e.g., for target/initiator dual role devices like Veritas
SANbox). Propagate class 3 service parameter changes where devices
can change roles.

Fix all occurrences of setting a sendmarker so that setting it
for one bus on dual bus cards doesn't wipe a pending sendmarker
for other busses on the same card :-;.

Comments added and clarifications made in some of the target mode code.
 1.51 21-Feb-2000  mjacob clen up some error messages
 1.50 19-Feb-2000  mjacob Remove residual and now broken !ISP_NO_FASTPOST_SCSI code (which was
turning back on fast posting!). Redo fabric (re)login loop- don't try
and log out ports that haven't been logged in. Do correct target id
shuffling so we just always find the target ID we want. Add in support
for > 12 byte commands for parallel SCSI. Handle some Dual Bus reset
stuff. Finally fix ABORT COMMAND to use the right 16 bit order of the
handle to abort.
 1.49 12-Feb-2000  mjacob Add in 12160 (Ultra3) support. Turn back on fast posting for the new
generateion parallel SCSI cards (1240/1080/1280/12160). Split up nvram
reading routines to be more readable. Fix topology reporting- 2200 has
connected topology in mailbox 6 when you're done getting your loop id
(supported: Private Loop (NL Port), N-Port, F-Port, FL-Port). The 2100
doens't report this, but we can synthesize it to be either NL-Port or
FL-Port. Add in some connection mode async events.
 1.48 14-Jan-2000  mjacob UltraMode is okay for SBus cards with chiptypes of 1020A.
 1.47 06-Jan-2000  mjacob Bump up level of some very verbose debugs so that SCSIDEBUG doesn't cause them
to print.
 1.46 06-Jan-2000  mjacob Bump default login time to 60 seconds. Move the spot at
which we claim we've seen the loop up at least once so
that we don't hang forever coming up. Add in the basics
for MI target mode stuff. Force the outer layers to deal
with a FCP response coming back that has a CHECK CONDITION
but no sense data.
 1.45 20-Dec-1999  mjacob clean up some f/w revision stuff. clean up some dualbus stuff.
 1.44 16-Dec-1999  mjacob Dual LVD (1280) support.
 1.43 04-Dec-1999  mjacob Some queue related functions now use a u_int16_t. Turn some messages into
CFGPRINTF messages. Clear up the f/w download slightly. If less than
rev 5 2100 chip, turn off loop fairness. Clean up a botch or two.
 1.42 28-Oct-1999  mjacob I was misinformed. I cannot get away from specifying tags for FC. Some devices
are happy w/o them- some are unhappy (IBM drives).
 1.41 26-Oct-1999  mjacob nuke a debug printout I thought was already gone
 1.40 22-Oct-1999  mjacob remember to initialize mailbox 2 for FC isp bus resets
 1.39 17-Oct-1999  mjacob branches: 1.39.2; 1.39.4;
Some stylistic changes, but also use the new INT_PENDING macro. Start
tracking LIP sequence numbers.
 1.38 14-Oct-1999  mjacob remove most target mode stuff. Change the arguments to the
isp_fastpost_complete function to include a handle. Do some
isr register debouncing. Use new inline functions for xflist
handle storage. Remove isp_dumpxflist function. Do some fixups
of NVRAM from some broken cards. Use Full Login after LIP option
for FC cards if f/w < 1.17 - there's a f/w bug that causes the
port database to not be actually refreshed for local loop devices!
Do the appropriate endian swizzling for the ICB. Ditto for SNS structures
(these are no-ops until UltraSparc PCI needs them).
 1.37 05-Jul-1999  mjacob branches: 1.37.2;
Change to approved NASA/Ames copyright. Add Fabric support. Fix SCCLUN support.
Add code that tries to track LoopID shifting.
 1.36 12-May-1999  mjacob Do a fairly large internal restructuring to accomodate dual-bus host adapters
(e.g., the 1240). Include the new 1080/1240 NVRAM layout reading code. Some
moderately significant mailbox changes were necessary also to accomodate a
second channel.
 1.35 04-Apr-1999  mjacob Make firmware revision a triple. Clean up some FC init stuff for
board versions with no BIOS. Separate mailbox interrupts from
IOCB interrupts. Read OUTMAILBOX5 while RISC_INT is active- not
after you clear it (potential race condition). Clear out older broken
BIG_ENDIAN goop. Don't negotiate narrow/async for LVD busses at startup
if already in LVD mode. Note usage of presumptive 1040C revision. For
all the LIP, PDB Changed, Loop UP/DOWN async events, mark fw state
as unknown as well as marking the need to do a getpdb on targets- after
a LIP for certain the f/w has to do PRLI/PLOGI for all targets again
and marking f/w state as unknown gives us a fighting chance to (start
to) hold up for that to complete.
 1.34 26-Mar-1999  mjacob branches: 1.34.2; 1.34.4;
add isp1080 support and some basic PDB change stuff
 1.33 17-Mar-1999  mjacob Update the driver with some infrastructure for the 1080. Fix an embarrassing
clock botch bug. Additional infrastructure for PDB change stuff.
 1.32 09-Feb-1999  mjacob Roll internal release tag. Print out if we're in a 64 bit PCI slot.
Use fast memory timing NVRAM parameter. Clean up and fix establishment
of default target parameters. Don't use NVRAM if are flagged as not to
do so (I had a busted NVRAM setup which I couldn't edit that enabled SYNC
mode but disabled disconnect/reconnect and wide!!). Fix delays after
resets. BUS resets not done in isp_init anymore- relegated to OS
specific outer layers. Fix a buglet where you can get in a loop for
a NULL xs in the completion list in isp_intr. Add in some defines that
can disable fast posting. Add in code for Loop Up/Loop Down events that
call into the outer layers as to what to do.
 1.31 30-Jan-1999  mjacob Implement and use Fast Posting for both parallel && fibre. Redo a bit of
the startup code. Implement a call to outer framework function so that
asynchronous events can be handled (e.g., speed negotiation, target mode).

Roll internal release tags.
 1.30 10-Jan-1999  mjacob + Some basic deadchip detection.
+ Enable FIFO bursts, but also detect bogus 1040A with busted FIFO.
+ Use new MEMZERO crossplatform define.
+ Handle RQCS_QUEUE_FULL status case and let upper layer parse SCSI ststus
byte if nonzero (should be 0x28- Queue Full status)
+ Fold ISP_NVRAM_FIFO_THRESHOLD_128 into isp_fifo_threshold tag.
 1.29 28-Dec-1998  mjacob clean up headers; move uninit/watch to outer layers
 1.28 05-Dec-1998  mjacob Update HBAs to incorporate the new max_lun property.
 1.27 17-Sep-1998  mjacob Several changes, including some stub fibre target mode stuff. Establish
a slightly different fibre startup (print ALPA now too). Change
the way that return values from dma setup is done. Make debug messages
out of some queue overflow situations. Turn PORT LOGGED OUT into
Selection Timeout equivlaent. On isp_restart actions don't blow off
the commands with HBA_BOTCH (XS_DRIVER_STUFFUP) - set them with HBA_BUSRESET
(which is defined as XS_DRIVER_STUFFUP until someone decides whether
the suggested change to the midlayer NetBSD is worthy of inclusion).
 1.26 10-Sep-1998  mjacob turn into a debug message an ABOUT F/W failure. Add ISPCTL_UPDATE_PARAMS isp_control case
 1.25 08-Sep-1998  mjacob Major reworking of initialization code, addition of NVRAM reading, usage
of device speed updating, etc... A lot of FC and other case statement
handling. Whew. Too much to really detail here.
 1.24 18-Jul-1998  mjacob Locking is now in the outer framework for isp_init/isp_reset- this allows
us to call isp_reset/isp_init internally with impunity.

Rename isp_phoenix to isp_restart and make it global. Clean it up a tad.

If we get an ASYNC_SYSTEM_ERROR code in isp_intr, call isp_restart and
return- the f/w is toasted at this point (usually), so we have to bring
things back to a known state.

In isp_mboxcmd, when we don't see the HOST_INT bit go clear, try and
find out if the isp is trying to tell us something and try again. This
may avoid a potential deadlock where the previous mailbox command hasn't
been cleared by the ISP.

In isp_init don't try and get device parameters if we already have them-
this typically doesn't work if we're in the middle of an isp_restart.
 1.23 15-Jul-1998  mjacob Some major thrashing to handle building for other than NetBSD.

There is one change of note- build a list of completing commands in
ispintr and then say you're done- this avoids some re-entrancy issues
that had surfaced.
 1.22 05-May-1998  mjacob there is an (unimportant) difference between 1020 && 1020A
 1.21 24-Mar-1998  mjacob some minor debug printout changes
 1.20 22-Mar-1998  mjacob update some debugging stuff- also turn off possible ULTRA mode for 1020s
 1.19 13-Feb-1998  thorpej Don't include <dev/scsipi/scsipi_conf.h> twice.
 1.18 28-Jan-1998  mjacob Fix for port-alpha/4903- always download f/w unless config flags say
no or we have no firmware to download.
 1.17 12-Jan-1998  thorpej Adjust for config changes.
 1.16 05-Dec-1997  mjacob Add a new async notification, and also fix a bug where the queue entry
wasn't getting fully zeroed as it should be.
 1.15 29-Sep-1997  mjacob branches: 1.15.2;
A little cleanup and print more error messages.
 1.14 13-Sep-1997  mjacob Wierd- well, what isn't with devices? Anyway, the type code for the ISP
chip on AlphaStation 500 is 2- which wasn't handled, and bad things happened
because the default case wasn't sane. Both are corrected now.
 1.13 10-Sep-1997  mjacob Some formatting cleanup, and for the ISP2100, the flags hadn't being set
quite right, but things worked okay anyhow.
 1.12 27-Aug-1997  bouyer Merge scsipi branch in the mainline. This add support for ATAPI devices
(currently only CD-ROM drives on i386). The sys/dev/scsipi system provides 2
busses to which devices can attach (scsibus and atapibus). This needed to
change some include files and structure names in the low level scsi drivers.
 1.11 16-Aug-1997  mjacob Merge foo.
 1.10 16-Aug-1997  mjacob *Major* differences to support the Qlogic 2100 (Fibre Channel PCI), as well
as being able to do microdifferentiation of the ISP SCSI chip; a couple of
bug fixes, and the beginnings of some watchdog support.
 1.9 28-Jul-1997  mjacob branches: 1.9.2;
Kudos and thanks to Mark Brinicombe (mark@causality.com): bug in waiting for
RISC_INT to be set after stuffing a mailbox.
 1.8 22-Jun-1997  mjacob branches: 1.8.2;
Hmm- seriously funny and sad bug: you need to directly establish the
clock rate for this board on Alpha/PCI systems. Under x86/PCI, the
board f/w will correctly tell you "I'm running at 60Mhz", so the code
that preserved that across a board reset (which would drop the chip
back to 40Mhz) worked fine. On the 8200, the chip was saying "I'm 40Mhz"-
which wasn't true. This turned out to be okay as long as you didn't have
any FAST or UltraFast targets- In fact, setting the chip to 40Mhz allowed
you to run up to 8Mhz SCSI. Unfortunately you die bigtime on the devices
that go faster than that. The fix here is to only use what the chip tells
you the clock rate is in the cases you don't really know (sbus is the
only case where this could be different, although with 66Mhz PCI coming up,
this may change).
 1.7 08-Jun-1997  thorpej - Simplify mailbox DMA setup, allowing the front-ends to allocate the
mailbox storage in a way they see fit.
- Define macros to index and size the request and result queue entries.
 1.6 01-Jun-1997  mjacob Finally found the cause of that nagging 'lost command' (for the first
command) bug: the initial response queue index is take from mbox 5,
not mbox 4, and mbox 5 wasn't getting initialized to zero.
 1.5 05-Apr-1997  mjacob Okay, Charles convinced me that XS_DRIVER_STUFFUP is better than XS_SELTIMEOUT.
 1.4 05-Apr-1997  mjacob A) Attempt to get clock rate from ISP chip prior to bashing it over the head
in reset. If none there, try and get from the bus/platform specific code.
If a nonzero value for either, set the clock rate. This is why the PCI
card versions weren't working- they need to be set at 60MHZ, rather than
the default 40MHZ (which worked fine for the internal ISP chips on the
Alpha 8X00).

B) If a isp_poll returns failure (command never completed) to the caller
and no error is set in the xs struct, set XS_SELTIMEOUT. And then call...

C) Added isp_lostcmd function to try and ask the ISP chip about it's current
state as well as the state of commands for a particular target/lun. This is
going along to try and figure out why the very first command to the ISP always
seems to get swallowed up.
 1.3 23-Mar-1997  cgd clean up isp_poll() so that it works more correctly. (Modeled on the version
in the BusLogic driver.)
 1.2 12-Mar-1997  cgd NetBSD RCS ID tweaks, a few comment block tweaks. Also, make copyright
notices consistent (per Matt Jacob).
 1.1 12-Mar-1997  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 12-Mar-1997  cgd ISP 10x0 driver from Matthew Jacob of NASA Ames Research Center.
(March 12, 1997 version).
 1.8.2.3 26-Aug-1997  bouyer Update from trunk.
 1.8.2.2 30-Jul-1997  bouyer Sync with trunk.
 1.8.2.1 01-Jul-1997  bouyer Updates for new scsipi subsystem. Actally known to work on i386 and sparc.
 1.9.2.4 14-Oct-1997  thorpej Update marc-pcmcia branch from trunk.
 1.9.2.3 16-Sep-1997  thorpej Update marc-pcmcia branch from trunk.
 1.9.2.2 27-Aug-1997  thorpej Update marc-pcmcia branch from trunk.
 1.9.2.1 23-Aug-1997  thorpej Update marc-pcmcia branch from trunk.
 1.15.2.2 07-Nov-1998  cgd pull up revs 1.16-1.17, 1.19-1.27 from trunk (mjacob)
 1.15.2.1 08-May-1998  mycroft Pull up 1.18, per request of cgd.
 1.34.4.2 02-Aug-1999  thorpej Update from trunk.
 1.34.4.1 21-Jun-1999  thorpej Sync w/ -current.
 1.34.2.2 13-May-2000  he Apply patch (requested by Matthew Jacob via he):
Correctly account for F-port vs. F-port (no FLOGI_ACC) topologies.
Make sure we get a port database entry for the fabric name server.
Preserve fabric logins if the device didn't change across fabric
or port database changes, or the device has already logged into
us (e.g., for target/initiator dual role devices like Veritas
SANbox). Propagate class 3 service parameter changes where devices
can change roles.

Fix all occurrences of setting a sendmarker so that setting it
for one bus on dual bus cards doesn't wipe a pending sendmarker
for other busses on the same card.

Comments added and clarifications made in some of the target mode code.

Add support for > 12 byte CDBs. Split out nvram reading into
per-card functions. Add proper Ultra2/Ultra3 support. Upgrade
firmware.
 1.34.2.1 08-Jan-2000  he Pull up revisions 1.35-1.47 (requested by mjacob):
Untangle Qlogic firmware copyright problems and update firmware.
Untangle some MD support issues for said firmware. Add 1280 (Dual
LVD), 1240 (Dual Ultra), 2200 (2nd Generation Qlogic FC chipset).
Fix some synchronous negotiation problems for parallel SCSI.
Firm up some Fabric Support issues.
 1.37.2.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.39.4.1 15-Nov-1999  fvdl Sync with -current
 1.39.2.8 21-Apr-2001  bouyer Sync with HEAD
 1.39.2.7 27-Mar-2001  bouyer Sync with HEAD.
 1.39.2.6 12-Mar-2001  bouyer Sync with HEAD.
 1.39.2.5 18-Jan-2001  bouyer Sync with head (for UBC+NFS fixes, mostly).
 1.39.2.4 05-Jan-2001  bouyer Sync with HEAD
 1.39.2.3 13-Dec-2000  bouyer Sync with HEAD (for UBC fixes).
 1.39.2.2 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.39.2.1 04-Feb-2000  thorpej - If the ISP's internal queues are full, don't synthesize a QFULL status,
but rather report it as a host adapter resource shortage.
- If the I_T_L's command queues are full, report that the target is busy
(with QFULL status).
 1.52.2.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.53.2.4 16-Mar-2001  he Pull up revisions 1.66-1.73 (requested by mjacob):
Add ISPCTL_RUN_MBOXCMD control function and ISPASYNC_UNHANDLED_RESPONSE
async event. Call ISP_DUMPREGS on f/w erro. Correct problem in
bitmap for MBOX_DUMP_RAM. Remove ISP2100_FABRIC defines. When
resetting the Qlogic 2X00 units, reset the FPM (Fibre Protocol
Module) and FBM (Fibre Buffer Modules). Massively redo how loop
events are handled. Throw out ISP_CFG_NOINIT and do HBA roles
instead. Use a SNS REGISTER FC4 TYPE subcommand to register with
the name server. Don't attempt to modify strings that the compiler
might have marked readonly. Bad ANSI! No Biscuit! Do some -Wformat
patches. Fix longstanding bug in ICB initialization of WWNs.
Handles are u_int16_t now. ANSIfy.
 1.53.2.3 25-Jan-2001  jhawk Pull up revisions 1.62-1.65 (requested by mjacob):
Add in correct SBus bursting; upgrade to 2.01.26 firmware; pull to latest
initiator mode level; make changes to WWN default handling; quiet
chatty boot messages; fix endian code so MacPPC works; fix bug in
lock recursion counter; fix bug which excluded all but NL-ports from
being logged into on a fabric.
 1.53.2.2 28-Aug-2000  mjacob Complete rewrite of internals for isp core version 2.0.
Pullup to netbsd-1-5 approved by thorpej@netbsd.org.
 1.53.2.1 11-Aug-2000  tls Pull up tagged queueing policy changes: now we use ordered tags for sync writes, simple tags for reads and async writes.
 1.72.2.17 11-Dec-2002  thorpej Sync with HEAD.
 1.72.2.16 11-Nov-2002  nathanw Catch up to -current
 1.72.2.15 27-Aug-2002  nathanw Catch up to -current.
 1.72.2.14 13-Aug-2002  nathanw Catch up to -current.
 1.72.2.13 20-Jun-2002  nathanw Catch up to -current.
 1.72.2.12 17-Apr-2002  nathanw Catch up to -current.
 1.72.2.11 01-Apr-2002  nathanw Catch up to -current.
(CVS: It's not just a program. It's an adventure!)
 1.72.2.10 28-Feb-2002  nathanw Correct a merge botch.
 1.72.2.9 28-Feb-2002  nathanw Catch up to -current.
 1.72.2.8 11-Jan-2002  nathanw More catchup.
 1.72.2.7 08-Jan-2002  nathanw Catch up to -current.
 1.72.2.6 14-Nov-2001  nathanw Catch up to -current.
 1.72.2.5 22-Oct-2001  nathanw Catch up to -current.
 1.72.2.4 21-Sep-2001  nathanw Catch up to -current.
 1.72.2.3 24-Aug-2001  nathanw Catch up with -current.
 1.72.2.2 21-Jun-2001  nathanw Catch up to -current.
 1.72.2.1 09-Apr-2001  nathanw Catch up with -current.
 1.78.2.5 06-Sep-2002  jdolecek sync kqueue branch with HEAD
 1.78.2.4 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.78.2.3 16-Mar-2002  jdolecek Catch up with -current.
 1.78.2.2 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.78.2.1 13-Sep-2001  thorpej Update the kqueue branch to HEAD.
 1.80.2.1 11-Oct-2001  fvdl Catch up with -current. Fix some bogons in the sparc64 kbd/ms
attach code. cd18xx conversion provided by mrg.
 1.93.2.3 29-Aug-2002  gehenna catch up with -current.
 1.93.2.2 20-Jun-2002  gehenna catch up with -current.
 1.93.2.1 30-May-2002  gehenna Catch up with -current.
 1.102.2.5 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.102.2.4 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.102.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.102.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.102.2.1 03-Aug-2004  skrll Sync with HEAD
 1.105.10.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.105.8.1 29-Apr-2005  kent sync with -current
 1.107.2.2 17-Mar-2008  yamt sync with head.
 1.107.2.1 03-Sep-2007  yamt sync with head.
 1.108.22.2 10-Dec-2006  yamt sync with head.
 1.108.22.1 22-Oct-2006  yamt sync with head
 1.108.20.1 18-Nov-2006  ad Sync with head.
 1.110.10.1 11-Jul-2007  mjf Sync with head.
 1.110.8.3 15-Jul-2007  ad Sync with head.
 1.110.8.2 15-Jul-2007  ad Sync with head.
 1.110.8.1 27-May-2007  ad Sync with head.
 1.113.28.3 17-Jan-2009  mjf Sync with HEAD.
 1.113.28.2 02-Jun-2008  mjf Sync with HEAD.
 1.113.28.1 03-Apr-2008  mjf Sync with HEAD.
 1.113.24.1 24-Mar-2008  keiichi sync with head.
 1.113.8.1 23-Mar-2008  matt sync with HEAD
 1.114.6.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.114.4.5 11-Aug-2010  yamt sync with head.
 1.114.4.4 11-Mar-2010  yamt sync with head
 1.114.4.3 18-Jul-2009  yamt sync with head.
 1.114.4.2 04-May-2009  yamt sync with head.
 1.114.4.1 16-May-2008  yamt sync with head.
 1.114.2.1 18-May-2008  yamt sync with head.
 1.115.6.1 19-Jan-2009  skrll Sync with HEAD.
 1.116.2.1 23-Jul-2009  jym Sync with HEAD.
 1.120.4.2 05-Mar-2011  rmind sync with head
 1.120.4.1 30-May-2010  rmind sync with head
 1.120.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.121.4.1 05-Mar-2011  bouyer Sync with HEAD
 1.121.2.1 06-Jun-2011  jruoho Sync with HEAD.
 1.122.14.3 03-Dec-2017  jdolecek update from HEAD
 1.122.14.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.122.14.1 23-Jun-2013  tls resync from head
 1.122.10.1 14-Mar-2013  riz Pull up following revision(s) (requested by martin in ticket #838):
sys/dev/ic/isp.c: revision 1.123
Disable ICBOPT_FAST_POST for ISP 2100.
Fixes PR kern/47302. From Matthew Jacob.
 1.122.4.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.123.6.1 18-May-2014  rmind sync with head
 1.125.14.1 21-Apr-2017  bouyer Sync with HEAD
 1.125.10.1 20-Mar-2017  pgoyette Sync with HEAD
 1.125.6.1 28-Aug-2017  skrll Sync with HEAD
 1.31 24-May-2007  mjacob Major update to isp(4) driver to bring it in line with external sources.

The major changes are:

+ 4Gb (24XX) card support
+ Rewritten fabric and loop evaluation code
+ New f/w sets

The 4Gb changes required major rototilling, which caused a rewrite of
fabric and loop eval code. The latter can now be set up to tune for
dynamic device arrival/departure if the framework is set up for it,
or to be firm about waiting for devices.

Testing has been principally on amd64, i386 and sparc64 and seems to
not have broken things for me.
 1.30 13-Jan-2007  cube branches: 1.30.6; 1.30.8;
Make it compile with all the options.
 1.29 16-Nov-2006  christos __unused removal on arguments; approved by core.
 1.28 12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.27 11-Dec-2005  christos branches: 1.27.20; 1.27.22;
merge ktrace-lwp.
 1.26 30-May-2005  christos branches: 1.26.2;
- add missing const
- fix variable shadowing
- remove unneeded casts
 1.25 27-Feb-2005  perry nuke trailing whitespace
 1.24 04-Dec-2003  keihan branches: 1.24.8; 1.24.10;
netbsd.org -> NetBSD.org

This was the last commit of this kind to src/sys, which is now totally
"NetBSD.org clean". Thanks for the patiance, and sorry for all the commits.
 1.23 07-Aug-2003  mjacob Clean out the 'fw' variable part of a CTIO2- the f/w doesn't actually
pass us back anything interesting here.
 1.22 18-Oct-2002  mjacob branches: 1.22.6;
Fix buglet in structure canonicalization of A64 commands.
 1.21 17-May-2002  mjacob Fix seveeral issues- but the most important of which is that we have
to check if we get a RQCS_DATA_UNDERRUN - if we're an FC card, we may
not have RQCS_RU set- if it isn't set, we just lost a DATA XFR IU in the
middle of the exchange. In this case, we have to bomb out the whole xfer.
We had been getting silent data corruption before.
 1.20 11-Apr-2002  mjacob branches: 1.20.2;
Clean up a bit from the last checkin so that the correct result pointers
are used- didn't make a difference, but hey...

Put in commented out GFF_ID code- for use in future attempts to search
the fabric- this probably has to go thru the management server path.

Don't whine about handles we can't find if these are aborted commands
(we know we can't find the handles because we destroy handles after
a successful mailbox abort- we don't wait for the F/W to decide whether
it wants to return a status IOCB after this happens).
 1.19 05-Apr-2002  mjacob Correct put of fc4_types to 32 bits, which is what it is.
 1.18 04-Apr-2002  mjacob Redo fabric evaluation to not use GET ALL NEXT (GA_NXT). Switches seem
to be trying to wriggle out of supporting this well. Instead, use
GID_FT to get a list of Port IDs and then use GPN_ID/GNN_ID to find the
port and node wwn. This should make working on fabrics a bit cleaner and
more stable.

This also caused some cleanup of SNS subcommand canonicalization so that
we can actually check for FS_ACC and FS_RJT, and if we get an FS_RJT,
print out the reason and explanation codes.

We'll keep the old GA_NXT method around if people want to uncomment a
controlling definition in ispvar.h.

This also had us clean up ISPASYNC_FABRICDEV to use a local lportdb argument
and to have the caller explicitly say that a device is at the end of the
fabric list.
 1.17 21-Feb-2002  mjacob Implement F/W crashdumps for 2200 && 2300 cards (kernel compile option).

Distinguish between 2312 and 2300 cards (they *are* different). Enable
RIO (Reduced Interrupt Operation) for the LVD cards (hey- I've seen
batched completions of the 30 commands at a time with this,....)...

If we get a Port Logout on local loop topologies, we have to force the
f/w to log back in. The easiest way (for us) to do this is to force
a LIP. This also will wake up the disk that probably just had a f/w crash.

Implement mailbox 'continuations'- this allows interrupts to re-drive
a mailbox command if it's one that just essentially repeats the previous
mailbox command (e.g., f/w download). This saves a boatload of sleep/wakeup
twitches.

If we're not a 2300 and we're about to return with a 'bogus interrupt'- check
the semaphore register to be non-zero at all and outgoing mailbox 0- this
seems to be where some of the lost ISP1080 commands came from.
 1.16 03-Jan-2002  mjacob Implement REDUCED INTERRUPT OPERATION usage for FC cards- this allows the
firmware to delay completion of commands so that it can attempt to batch
a bunch of completions at once- either returning 16 bit handles in mailbox
registers, or in a resposne queue entry that has a whole wad of 16 bit handles.

Distinguish between 2300 and 2312 chipsets- if only because the revisions
on the chips have different meanings.

Add more instrumentation plus ISP_GET_STATS and ISP_CLR_STATS ioctls.
Run up the maximum number of response queue entities we'll look at
per interrupt.

If we haven't set HBA role yet, always return success from isp_fc_runstate.
 1.15 14-Dec-2001  mjacob Major restructuring for swizzling to the request queue and unswizzling from
the response queue. Instead of the ad hoc ISP_SWIZZLE_REQUEST, we now have
a complete set of inline functions in isp_inline.h. Each platform is
responsible for providing just one of a set of ISP_IOX_{GET,PUT}{8,16,32}
macros.

The reason this needs to be done is that we need to have a single set of
functions that will work correctly on multiple architectures for both little
and big endian machines. It also needs to work correctly in the case that
we have the request or response queues in memory that has to be treated
specially (e.g., have ddi_dma_sync called on it for Solaris after we update
it or before we read from it).

One thing that falls out of this is that we no longer build requests in the
request queue itself. Instead, we build the request locally (e.g., on the
stack) and then as part of the swizzling operation, copy it to the request
queue entry we've allocated. I thought long and hard about whether this was
too expensive a change to make as it in a lot of cases requires an extra
copy. On balance, the flexbility is worth it. With any luck, the entry that
we build locally stays in a processor writeback cache (after all, it's only
64 bytes) so that the cost of actually flushing it to the memory area that is
the shared queue with the PCI device is not all that expensive. We may examine
this again and try to get clever in the future to try and avoid copies.

Another change that falls out of this is that MEMORYBARRIER should be taken
a lot more seriously. The macro ISP_ADD_REQUEST does a MEMORYBARRIER on the
entry being added. But there had been many other places this had been missing.
It's now very important that it be done.

For NetBSD, it does a ddi_dmamap_sync as appropriate. This gets us out of
the explicit ddi_dmamap_sync on the whole response queue that we did for SBus
cards at each interrupt.

Set things up so that platforms that cannot have an SBus don't get a lot of
the SBus code checks (dead coded out).

Additional changes:

Fix a longstanding buglet of sorts. When we get an entry via isp_getrqentry,
the iptr value that gets returned is the value we intend to eventually plug
into the ISP registers as the entry *one past* the last one we've written-
*not* the current entry we're updating. All along we've been calling sync
functions on the wrong index value. Argh. The 'fix' here is to rename all
'iptr' variables as 'nxti' to remember that this is the 'next' pointer-
not the current pointer.

Devote a single bit to mboxbsy- and set aside bits for output mbox registers
that we need to pick up- we can have at least one command which does not
have any defined output registers (MBOX_EXECUTE_FIRMWARE).

Explicitly decode GetAllNext SNS Response back *as* a GetAllNext response.
Otherwise, we won't unswizzle it correctly.

Nuke some additional __P macros.
 1.14 06-Jul-2001  mjacob branches: 1.14.2;
More 2300 support: macroize access to request/response in/out pointers.
 1.13 14-Mar-2001  mjacob Handles are now u_int16_t instead of u_int32_t. ANSIfy (NetBSD was the holdout).
 1.12 02-Mar-2001  mjacob branches: 1.12.2;
Fix isp_print_qentry to print all four lines- it's been broken for months.
 1.11 12-Feb-2001  mjacob Add isp_fc_runstate function- this function's purpose is to, in stages,
and depending on role, make sure link is up, scan the fabric (if we're
connected to a fabric), scan the local loop (if appropriate), merge
the results into the local port database then, check once again
to make sure we have f/w at FW_READY state and the the loopstate
is LOOP_READY.
 1.10 23-Dec-2000  wiz Fix pathnames in comment.
 1.9 27-Aug-2000  mjacob fix some missing initializations
 1.8 14-Aug-2000  mjacob Add a maintenance note. Add a cast to u_int16_t which will keep
Solaris lint && the SUNPro SC5.0 complier happy.
 1.7 01-Aug-2000  mjacob Core version 2.0 (platform version 1.0) rewrite of ISP driver. Some
interace cleanups, some new common functions. The major impact that
will be noticeable right away is that if you boot with not Fibre connected
to the FC cards, you no longer hang indefinitely.
 1.6 05-Jul-2000  mjacob Add back in a (corrected) isp_prtstst function.
 1.5 19-Feb-2000  mjacob branches: 1.5.4;
Cleanup some printaouts.
 1.4 06-Jan-2000  mjacob branches: 1.4.2;
add isp_print_qentry inline
 1.3 08-Dec-1999  mjacob branches: 1.3.2;
Respond to a crucial security alert.
 1.2 04-Dec-1999  mjacob Make sure we have a big enough buffer to sprintf into (noticed by
deraadt@openbsd.org).
 1.1 14-Oct-1999  mjacob branches: 1.1.2;
Add this file to contain common inline functions for use with the Qlogic
driver.
 1.1.2.4 27-Mar-2001  bouyer Sync with HEAD.
 1.1.2.3 12-Mar-2001  bouyer Sync with HEAD.
 1.1.2.2 05-Jan-2001  bouyer Sync with HEAD
 1.1.2.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.3.2.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.4.2.3 13-May-2000  he Apply patch (requested by Matthew Jacob via he):
Correctly account for F-port vs. F-port (no FLOGI_ACC) topologies.
Make sure we get a port database entry for the fabric name server.
Preserve fabric logins if the device didn't change across fabric
or port database changes, or the device has already logged into
us (e.g., for target/initiator dual role devices like Veritas
SANbox). Propagate class 3 service parameter changes where devices
can change roles.

Fix all occurrences of setting a sendmarker so that setting it
for one bus on dual bus cards doesn't wipe a pending sendmarker
for other busses on the same card.

Comments added and clarifications made in some of the target mode code.

Add support for > 12 byte CDBs. Split out nvram reading into
per-card functions. Add proper Ultra2/Ultra3 support. Upgrade
firmware.
 1.4.2.2 08-Jan-2000  he Pull up revisions 1.1-1.4 (requested by mjacob):
Untangle Qlogic firmware copyright problems and update firmware.
Untangle some MD support issues for said firmware. Add 1280 (Dual
LVD), 1240 (Dual Ultra), 2200 (2nd Generation Qlogic FC chipset).
Fix some synchronous negotiation problems for parallel SCSI.
Firm up some Fabric Support issues.
 1.4.2.1 06-Jan-2000  he file isp_inline.h was added on branch netbsd-1-4 on 2000-01-08 22:40:27 +0000
 1.5.4.2 16-Mar-2001  he Pull up revisions 1.10-1.13 (requested by mjacob):
Add isp_fc_runstate function. Fix pathnames in comment.
Fix isp_print_qentry function.
Handles are u_int16_t now. ANSIfy.
 1.5.4.1 28-Aug-2000  mjacob Complete rewrite of internals for isp core version 2.0.
Pullup to netbsd-1-5 approved by thorpej@netbsd.org.
 1.12.2.8 11-Nov-2002  nathanw Catch up to -current
 1.12.2.7 20-Jun-2002  nathanw Catch up to -current.
 1.12.2.6 17-Apr-2002  nathanw Catch up to -current.
 1.12.2.5 28-Feb-2002  nathanw Catch up to -current.
 1.12.2.4 11-Jan-2002  nathanw More catchup.
 1.12.2.3 08-Jan-2002  nathanw Catch up to -current.
 1.12.2.2 24-Aug-2001  nathanw Catch up with -current.
 1.12.2.1 09-Apr-2001  nathanw Catch up with -current.
 1.14.2.3 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.14.2.2 16-Mar-2002  jdolecek Catch up with -current.
 1.14.2.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.20.2.1 30-May-2002  gehenna Catch up with -current.
 1.22.6.5 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.22.6.4 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.22.6.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.22.6.2 18-Sep-2004  skrll Sync with HEAD.
 1.22.6.1 03-Aug-2004  skrll Sync with HEAD
 1.24.10.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.24.8.1 29-Apr-2005  kent sync with -current
 1.26.2.3 03-Sep-2007  yamt sync with head.
 1.26.2.2 26-Feb-2007  yamt sync with head.
 1.26.2.1 30-Dec-2006  yamt sync with head.
 1.27.22.2 10-Dec-2006  yamt sync with head.
 1.27.22.1 22-Oct-2006  yamt sync with head
 1.27.20.2 01-Feb-2007  ad Sync with head.
 1.27.20.1 18-Nov-2006  ad Sync with head.
 1.30.8.1 11-Jul-2007  mjf Sync with head.
 1.30.6.2 09-Jun-2007  ad Sync with head.
 1.30.6.1 27-May-2007  ad Sync with head.
 1.12 06-Sep-2015  dholland More on PR 41200: headers that declare ioctls should include sys/ioccom.h.
This covers (I think) all the MI headers outside of external/ (and dist/).
 1.11 11-Mar-2008  mjacob branches: 1.11.48; 1.11.68;
Checkpoint of some fairly major isp(4) rototilling.

Reintroduce more of a 'channel' concept in preparation for NP-IV support.
This gets rid of the chanA/chanB concept as the 2400 can have up to 128
virtual channels. Actually, with MID firmware you can also have the 2200
and 2300 support 'channels, but they do it with an FL-Port topology.
Because FC cards can now have 'channels', just about every support
function for fibre channel had to be redone to have a channel index
as well. Rototill isp_ioctl.h for channel stuff as well.

Pick up a lot of work about fabric management (hopefully better) and keep
work in place that will allow for dynamic attachment/detachment of devices
(if I can figure out how to make the midlayer support it).

Merge the target code with external trees. Eventually it might even
be sorted out on NetBSD.

Update some firmware stuff.
 1.10 24-May-2007  mjacob branches: 1.10.8; 1.10.24; 1.10.28;
Major update to isp(4) driver to bring it in line with external sources.

The major changes are:

+ 4Gb (24XX) card support
+ Rewritten fabric and loop evaluation code
+ New f/w sets

The 4Gb changes required major rototilling, which caused a rewrite of
fabric and loop eval code. The latter can now be set up to tune for
dynamic device arrival/departure if the framework is set up for it,
or to be firm about waiting for devices.

Testing has been principally on amd64, i386 and sparc64 and seems to
not have broken things for me.
 1.9 27-Aug-2006  christos branches: 1.9.12; 1.9.14;
#ifdef out unused ioctl (and wrong)
 1.8 27-Aug-2006  christos Fix typo
 1.7 11-Dec-2005  christos branches: 1.7.4; 1.7.8;
merge ktrace-lwp.
 1.6 27-Feb-2005  perry branches: 1.6.4;
nuke trailing whitespace
 1.5 12-Aug-2002  mjacob branches: 1.5.6; 1.5.14; 1.5.16;
Various changes to allow for overriding just loopid and/or iid.
Fix a random 23XX ISR reading bug. Be chattier about HBA_BOTCH
errors. More f/w cashdump layering.
 1.4 15-Jun-2002  mjacob Add support for ISP_FC_GETHINFO which can tell you connection topology,
current speed, loopid, etc.
 1.3 21-Feb-2002  mjacob branches: 1.3.8;
Implement F/W crashdumps for 2200 && 2300 cards (kernel compile option).

Distinguish between 2312 and 2300 cards (they *are* different). Enable
RIO (Reduced Interrupt Operation) for the LVD cards (hey- I've seen
batched completions of the 30 commands at a time with this,....)...

If we get a Port Logout on local loop topologies, we have to force the
f/w to log back in. The easiest way (for us) to do this is to force
a LIP. This also will wake up the disk that probably just had a f/w crash.

Implement mailbox 'continuations'- this allows interrupts to re-drive
a mailbox command if it's one that just essentially repeats the previous
mailbox command (e.g., f/w download). This saves a boatload of sleep/wakeup
twitches.

If we're not a 2300 and we're about to return with a 'bogus interrupt'- check
the semaphore register to be non-zero at all and outgoing mailbox 0- this
seems to be where some of the lost ISP1080 commands came from.
 1.2 03-Jan-2002  mjacob Implement REDUCED INTERRUPT OPERATION usage for FC cards- this allows the
firmware to delay completion of commands so that it can attempt to batch
a bunch of completions at once- either returning 16 bit handles in mailbox
registers, or in a resposne queue entry that has a whole wad of 16 bit handles.

Distinguish between 2300 and 2312 chipsets- if only because the revisions
on the chips have different meanings.

Add more instrumentation plus ISP_GET_STATS and ISP_CLR_STATS ioctls.
Run up the maximum number of response queue entities we'll look at
per interrupt.

If we haven't set HBA role yet, always return success from isp_fc_runstate.
 1.1 10-Apr-2001  mjacob branches: 1.1.2; 1.1.4; 1.1.6;
Add some HBA ioctl functions (LIP resets, rescan, setting debugging level).
 1.1.6.4 06-Sep-2002  jdolecek sync kqueue branch with HEAD
 1.1.6.3 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.1.6.2 16-Mar-2002  jdolecek Catch up with -current.
 1.1.6.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.1.4.6 13-Aug-2002  nathanw Catch up to -current.
 1.1.4.5 20-Jun-2002  nathanw Catch up to -current.
 1.1.4.4 28-Feb-2002  nathanw Catch up to -current.
 1.1.4.3 11-Jan-2002  nathanw More catchup.
 1.1.4.2 21-Jun-2001  nathanw Catch up to -current.
 1.1.4.1 10-Apr-2001  nathanw file isp_ioctl.h was added on branch nathanw_sa on 2001-06-21 20:02:42 +0000
 1.1.2.2 21-Apr-2001  bouyer Sync with HEAD
 1.1.2.1 10-Apr-2001  bouyer file isp_ioctl.h was added on branch thorpej_scsipi on 2001-04-21 17:48:32 +0000
 1.3.8.2 29-Aug-2002  gehenna catch up with -current.
 1.3.8.1 20-Jun-2002  gehenna catch up with -current.
 1.5.16.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.5.14.1 29-Apr-2005  kent sync with -current
 1.5.6.1 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.6.4.3 17-Mar-2008  yamt sync with head.
 1.6.4.2 03-Sep-2007  yamt sync with head.
 1.6.4.1 30-Dec-2006  yamt sync with head.
 1.7.8.1 03-Sep-2006  yamt sync with head.
 1.7.4.1 09-Sep-2006  rpaulo sync with head
 1.9.14.1 11-Jul-2007  mjf Sync with head.
 1.9.12.1 27-May-2007  ad Sync with head.
 1.10.28.1 03-Apr-2008  mjf Sync with HEAD.
 1.10.24.1 24-Mar-2008  keiichi sync with head.
 1.10.8.1 23-Mar-2008  matt sync with HEAD
 1.11.68.1 22-Sep-2015  skrll Sync with HEAD
 1.11.48.1 03-Dec-2017  jdolecek update from HEAD
 1.9 21-Oct-2021  andvar fix various typos, mainly in comments, but also in man pages and log messages.
 1.8 10-Jan-2019  martin When handles returned by the device do not match our expectations,
log more details.
 1.7 28-Feb-2011  mjacob branches: 1.7.54; 1.7.56;
Update isp driver to be in sync with other platforms. Mostly very minor changes
with effectively zero impact on NetBSD.
 1.6 26-Mar-2010  mjacob branches: 1.6.2; 1.6.4;
Synchronize with other platforms:

Strongly architect handles so we can more easily detect bogus
handles. This switches us to a full 32 bits for all handles.

Handle the case of FC disks disappearing and then reappearing-
at least at the FC transport level.

Some better and finer control of debug and non-debug printouts.
 1.5 05-Jan-2010  mbalmer branches: 1.5.2; 1.5.4;
Remove extra semicolons.
 1.4 25-Jun-2009  mjacob Update ISP driver to latest and greatest. Includes support for the 8Gb part.
 1.3 11-Mar-2008  mjacob branches: 1.3.4; 1.3.18;
Checkpoint of some fairly major isp(4) rototilling.

Reintroduce more of a 'channel' concept in preparation for NP-IV support.
This gets rid of the chanA/chanB concept as the 2400 can have up to 128
virtual channels. Actually, with MID firmware you can also have the 2200
and 2300 support 'channels, but they do it with an FL-Port topology.
Because FC cards can now have 'channels', just about every support
function for fibre channel had to be redone to have a channel index
as well. Rototill isp_ioctl.h for channel stuff as well.

Pick up a lot of work about fabric management (hopefully better) and keep
work in place that will allow for dynamic attachment/detachment of devices
(if I can figure out how to make the midlayer support it).

Merge the target code with external trees. Eventually it might even
be sorted out on NetBSD.

Update some firmware stuff.
 1.2 07-Jul-2007  mjacob branches: 1.2.2; 1.2.10; 1.2.12; 1.2.28; 1.2.32;
Do a number of 24XX related fixes: fix the actual getting of initiator
status correctly (which we never were doing before). Add an underrun
checker for 24XX. The process of sorting this out led to a whole bunch
of endian surprises that had to be dealt with. Fix NVRAM endian issues
for the 24XX as well.

Do a little 2200 related cleanup- in particular, turn off complaints about
not finding a fast posting handle when running with RIO enabled- we are
somehow getting duplicate completions in this case. If we ignore them and
don't complain, all is well, and we actually start averaging > 2 commands
completed per interrupt.
 1.1 24-May-2007  mjacob branches: 1.1.2;
Major update to isp(4) driver to bring it in line with external sources.

The major changes are:

+ 4Gb (24XX) card support
+ Rewritten fabric and loop evaluation code
+ New f/w sets

The 4Gb changes required major rototilling, which caused a rewrite of
fabric and loop eval code. The latter can now be set up to tune for
dynamic device arrival/departure if the framework is set up for it,
or to be firm about waiting for devices.

Testing has been principally on amd64, i386 and sparc64 and seems to
not have broken things for me.
 1.1.2.3 15-Jul-2007  ad Sync with head.
 1.1.2.2 09-Jun-2007  ad Sync with head.
 1.1.2.1 24-May-2007  ad file isp_library.c was added on branch vmlocking on 2007-06-09 21:37:15 +0000
 1.2.32.1 03-Apr-2008  mjf Sync with HEAD.
 1.2.28.1 24-Mar-2008  keiichi sync with head.
 1.2.12.3 17-Mar-2008  yamt sync with head.
 1.2.12.2 03-Sep-2007  yamt sync with head.
 1.2.12.1 07-Jul-2007  yamt file isp_library.c was added on branch yamt-lazymbuf on 2007-09-03 14:34:46 +0000
 1.2.10.1 23-Mar-2008  matt sync with HEAD
 1.2.2.2 11-Jul-2007  mjf Sync with head.
 1.2.2.1 07-Jul-2007  mjf file isp_library.c was added on branch mjf-ufs-trans on 2007-07-11 20:05:53 +0000
 1.3.18.1 23-Jul-2009  jym Sync with HEAD.
 1.3.4.3 11-Aug-2010  yamt sync with head.
 1.3.4.2 11-Mar-2010  yamt sync with head
 1.3.4.1 18-Jul-2009  yamt sync with head.
 1.5.4.2 05-Mar-2011  rmind sync with head
 1.5.4.1 30-May-2010  rmind sync with head
 1.5.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.6.4.1 05-Mar-2011  bouyer Sync with HEAD
 1.6.2.1 06-Jun-2011  jruoho Sync with HEAD.
 1.7.56.1 10-Jun-2019  christos Sync with HEAD
 1.7.54.1 18-Jan-2019  pgoyette Synch with HEAD
 1.4 26-Mar-2010  mjacob Synchronize with other platforms:

Strongly architect handles so we can more easily detect bogus
handles. This switches us to a full 32 bits for all handles.

Handle the case of FC disks disappearing and then reappearing-
at least at the FC transport level.

Some better and finer control of debug and non-debug printouts.
 1.3 25-Jun-2009  mjacob branches: 1.3.2; 1.3.4;
Update ISP driver to latest and greatest. Includes support for the 8Gb part.
 1.2 11-Mar-2008  mjacob branches: 1.2.4; 1.2.18;
Checkpoint of some fairly major isp(4) rototilling.

Reintroduce more of a 'channel' concept in preparation for NP-IV support.
This gets rid of the chanA/chanB concept as the 2400 can have up to 128
virtual channels. Actually, with MID firmware you can also have the 2200
and 2300 support 'channels, but they do it with an FL-Port topology.
Because FC cards can now have 'channels', just about every support
function for fibre channel had to be redone to have a channel index
as well. Rototill isp_ioctl.h for channel stuff as well.

Pick up a lot of work about fabric management (hopefully better) and keep
work in place that will allow for dynamic attachment/detachment of devices
(if I can figure out how to make the midlayer support it).

Merge the target code with external trees. Eventually it might even
be sorted out on NetBSD.

Update some firmware stuff.
 1.1 24-May-2007  mjacob branches: 1.1.2; 1.1.4; 1.1.12; 1.1.14; 1.1.30; 1.1.34;
Major update to isp(4) driver to bring it in line with external sources.

The major changes are:

+ 4Gb (24XX) card support
+ Rewritten fabric and loop evaluation code
+ New f/w sets

The 4Gb changes required major rototilling, which caused a rewrite of
fabric and loop eval code. The latter can now be set up to tune for
dynamic device arrival/departure if the framework is set up for it,
or to be firm about waiting for devices.

Testing has been principally on amd64, i386 and sparc64 and seems to
not have broken things for me.
 1.1.34.1 03-Apr-2008  mjf Sync with HEAD.
 1.1.30.1 24-Mar-2008  keiichi sync with head.
 1.1.14.3 17-Mar-2008  yamt sync with head.
 1.1.14.2 03-Sep-2007  yamt sync with head.
 1.1.14.1 24-May-2007  yamt file isp_library.h was added on branch yamt-lazymbuf on 2007-09-03 14:34:47 +0000
 1.1.12.1 23-Mar-2008  matt sync with HEAD
 1.1.4.2 11-Jul-2007  mjf Sync with head.
 1.1.4.1 24-May-2007  mjf file isp_library.h was added on branch mjf-ufs-trans on 2007-07-11 20:05:54 +0000
 1.1.2.2 09-Jun-2007  ad Sync with head.
 1.1.2.1 24-May-2007  ad file isp_library.h was added on branch vmlocking on 2007-06-09 21:37:15 +0000
 1.2.18.1 23-Jul-2009  jym Sync with HEAD.
 1.2.4.2 11-Aug-2010  yamt sync with head.
 1.2.4.1 18-Jul-2009  yamt sync with head.
 1.3.4.1 30-May-2010  rmind sync with head
 1.3.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.99 09-Feb-2024  andvar fix spelling mistakes, mainly in comments and log messages.
 1.98 07-Aug-2021  thorpej Merge thorpej-cfargs2.
 1.97 24-Apr-2021  thorpej branches: 1.97.8;
Merge thorpej-cfargs branch:

Simplify and make extensible the config_search() / config_found() /
config_attach() interfaces: rather than having different variants for
which arguments you want pass along, just have a single call that
takes a variadic list of tag-value arguments.

Adjust all call sites:
- Simplify wherever possible; don't pass along arguments that aren't
actually needed.
- Don't be explicit about what interface attribute is attaching if
the device only has one. (More simplification.)
- Add a config_probe() function to be used in indirect configuiration
situations, making is visibly easier to see when indirect config is
in play, and allowing for future change in semantics. (As of now,
this is just a wrapper around config_match(), but that is an
implementation detail.)

Remove unnecessary or redundant interface attributes where they're not
needed.

There are currently 5 "cfargs" defined:
- CFARG_SUBMATCH (submatch function for direct config)
- CFARG_SEARCH (search function for indirect config)
- CFARG_IATTR (interface attribte)
- CFARG_LOCATORS (locators array)
- CFARG_DEVHANDLE (devhandle_t - wraps OFW, ACPI, etc. handles)

...and a sentinel value CFARG_EOL.

Add some extra sanity checking to ensure that interface attributes
aren't ambiguous.

Use CFARG_DEVHANDLE in MI FDT, OFW, and ACPI code, and macppc and shark
ports to associate those device handles with device_t instance. This
will trickle trough to more places over time (need back-end for pre-OFW
Sun OBP; any others?).
 1.96 05-Dec-2020  thorpej branches: 1.96.2;
Remove unnecessary inclusion of <sys/timevar.h>.
 1.95 25-Sep-2019  maya branches: 1.95.8;
Make clang -Wformat-security happier by not passing a (constant) variable
as the format string,
const string msg; printf(msg)
-> printf("%s", msg);

the strings are all known and don't currently contain format variables.
 1.94 21-Sep-2019  maxv Remove unused function prototype. Reported by the lgtm bot.
 1.93 20-Sep-2019  christos declare printflike functions and fix another printf format.
also change 0x%x -> %#x.
 1.92 20-Sep-2019  maxv Fix argument.

Found by the lgtm bot.
 1.91 03-Feb-2019  mrg - add or adjust /* FALLTHROUGH */ where appropriate
- add __unreachable() after functions that can return but won't in
this case, and thus can't be marked __dead easily
 1.90 03-Sep-2018  riastradh Rename min/max -> uimin/uimax for better honesty.

These functions are defined on unsigned int. The generic name
min/max should not silently truncate to 32 bits on 64-bit systems.
This is purely a name change -- no functional change intended.

HOWEVER! Some subsystems have

#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))

even though our standard name for that is MIN/MAX. Although these
may invite multiple evaluation bugs, these do _not_ cause integer
truncation.

To avoid `fixing' these cases, I first changed the name in libkern,
and then compile-tested every file where min/max occurred in order to
confirm that it failed -- and thus confirm that nothing shadowed
min/max -- before changing it.

I have left a handful of bootloaders that are too annoying to
compile-test, and some dead code:

cobalt ews4800mips hp300 hppa ia64 luna68k vax
acorn32/if_ie.c (not included in any kernels)
macppc/if_gm.c (superseded by gem(4))

It should be easy to fix the fallout once identified -- this way of
doing things fails safe, and the goal here, after all, is to _avoid_
silent integer truncations, not introduce them.

Maybe one day we can reintroduce min/max as type-generic things that
never silently truncate. But we should avoid doing that for a while,
so that existing code has a chance to be detected by the compiler for
conversion to uimin/uimax without changing the semantics until we can
properly audit it all. (Who knows, maybe in some cases integer
truncation is actually intended!)
 1.89 28-Jul-2017  riastradh branches: 1.89.2; 1.89.4;
Reject out-of-bounds channel index.

From Ilja Van Sprundel.
 1.88 31-Dec-2014  christos branches: 1.88.10;
We can't sleep if we are called from the watchdog timeout.
 1.87 18-Oct-2014  snj branches: 1.87.2;
src is too big these days to tolerate superfluous apostrophes. It's
"its", people!
 1.86 21-Aug-2012  bouyer branches: 1.86.2; 1.86.14; 1.86.16; 1.86.20;
Properly fill the struct timeval before using it: a timeout in microseconds has
to be converted to seconds and microseconds.
Fix KASSERT("usec >= 0 && usec < 1000000") in tvtohz().
While there, simplify computation of to (avoids a timersub() in tvhzto()
and directly call tvtohz() with the interval).
 1.85 12-Dec-2011  jdc branches: 1.85.2; 1.85.4;
Fix:
panic: kernel diagnostic assertion "usec >= 0 && usec < 1000000" failed: file "/usr/src/sys/kern/subr_time.c", line 92
by using timeradd(), rather than our own code, in the timeout calculating
loop. Idea from joerg@.
 1.84 20-Sep-2010  mjacob branches: 1.84.8; 1.84.12;
Multiple channel devices *should* be working. Remove the debug code
that was avoiding finding out.
 1.83 26-Mar-2010  mjacob Synchronize with other platforms:

Strongly architect handles so we can more easily detect bogus
handles. This switches us to a full 32 bits for all handles.

Handle the case of FC disks disappearing and then reappearing-
at least at the FC transport level.

Some better and finer control of debug and non-debug printouts.
 1.82 11-Jan-2010  mjacob branches: 1.82.2; 1.82.4;
Keep track of what appear to be live Fibre Channel disks and store up the
Port WWNs for them as well as attaching them as a "port-wwn" property to
the device node in question. This allows MD code to find the boot device
on some platforms.

This is less clean than it should be. A better solution would be to make
some changes to the scsi infrastructure so that periphs can query and
use and store their own "native" transport addresses. However, that's
a much more invasive change and it is not clear how many ports or devices
really want or need that information (yet).
 1.81 07-Sep-2009  tsutsui Split device_t/softc.
Tested QLogic 1020 Fast Wide SCSI HBA at PCI.
Sbus attachment is untested, but not so much quirks in it.
 1.80 25-Jun-2009  mjacob Update ISP driver to latest and greatest. Includes support for the 8Gb part.
 1.79 12-May-2009  cegger struct device * -> device_t, no functional changes intended.
 1.78 15-Jul-2008  christos branches: 1.78.8;
Use more timespecs internally. From Alexander Shishkin and me.
Welcome to 4.99.70, 30 more to go for 100.
 1.77 08-Apr-2008  cegger branches: 1.77.4; 1.77.6; 1.77.8; 1.77.10;
use aprint_*_dev and device_xname
 1.76 11-Mar-2008  mjacob Checkpoint of some fairly major isp(4) rototilling.

Reintroduce more of a 'channel' concept in preparation for NP-IV support.
This gets rid of the chanA/chanB concept as the 2400 can have up to 128
virtual channels. Actually, with MID firmware you can also have the 2200
and 2300 support 'channels, but they do it with an FL-Port topology.
Because FC cards can now have 'channels', just about every support
function for fibre channel had to be redone to have a channel index
as well. Rototill isp_ioctl.h for channel stuff as well.

Pick up a lot of work about fabric management (hopefully better) and keep
work in place that will allow for dynamic attachment/detachment of devices
(if I can figure out how to make the midlayer support it).

Merge the target code with external trees. Eventually it might even
be sorted out on NetBSD.

Update some firmware stuff.
 1.75 09-Jul-2007  ad branches: 1.75.8; 1.75.24; 1.75.28;
Merge some of the less invasive changes from the vmlocking branch:

- kthread, callout, devsw API changes
- select()/poll() improvements
- miscellaneous MT safety improvements
 1.74 24-May-2007  mjacob Major update to isp(4) driver to bring it in line with external sources.

The major changes are:

+ 4Gb (24XX) card support
+ Rewritten fabric and loop evaluation code
+ New f/w sets

The 4Gb changes required major rototilling, which caused a rewrite of
fabric and loop eval code. The latter can now be set up to tune for
dynamic device arrival/departure if the framework is set up for it,
or to be firm about waiting for devices.

Testing has been principally on amd64, i386 and sparc64 and seems to
not have broken things for me.
 1.73 04-Mar-2007  christos branches: 1.73.2; 1.73.4;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.72 13-Jan-2007  cube branches: 1.72.2;
Make it compile with all the options.
 1.71 16-Nov-2006  christos __unused removal on arguments; approved by core.
 1.70 12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.69 30-Aug-2006  christos branches: 1.69.2; 1.69.4;
fix initializers.
 1.68 07-May-2006  jdc Remove call that sets XS_STS_DONE before we call scsipi_done().
This makes isp work again following the change in r1.135 of scsipi_base.c.
Also tested by David Hopper.
 1.67 11-Dec-2005  christos branches: 1.67.4; 1.67.6; 1.67.8; 1.67.10; 1.67.12;
merge ktrace-lwp.
 1.66 30-May-2005  christos branches: 1.66.2;
- add missing const
- fix variable shadowing
- remove unneeded casts
 1.65 27-Feb-2005  perry nuke trailing whitespace
 1.64 04-Dec-2003  keihan branches: 1.64.8; 1.64.10;
netbsd.org -> NetBSD.org

This was the last commit of this kind to src/sys, which is now totally
"NetBSD.org clean". Thanks for the patiance, and sorry for all the commits.
 1.63 02-Nov-2003  wiz Fix some typos. From Tom Cosgrove via jmc@openbsd.
 1.62 08-Oct-2003  pk In isp_fc_worker() reduce the timeout value used to poll for the link
status from 10 seconds to 250 milli seconds for the second and subsequent
attempts to determine the link status. This prevents unnecessary long
stalls after the device attach routines have completed.

Tested on a dual port QLogic 3212. Approved by mjacob@feral.com.
 1.61 27-Sep-2003  tls Remove NOSETTLE flag from channel in FibreChannel case. It makes sense that
it should be there, but in practice, on some systems an ugly race condition
rears its head: SCSI commands are issued before the FC thread ever runs, and
fail from then on forever. Yuck.
 1.60 07-Aug-2003  mjacob Note both active and nvram WWNN/WWPNs

Fix the bug where the thread worker constantly looped. It was a race as
to whether or not the thread fired up or a polled/probed command happened
first, or maybe it's due to other scsipi changes, but we never set the
value that caused the fc thread worker to actually go to sleep until an
initial loop up.

This was rather ugly as it consumed nearly all CPU time available from thence
on. Bad.
 1.59 21-Mar-2003  mjacob branches: 1.59.2;
Fibre Channel doesn't need bus reset settle time.
 1.58 25-Nov-2002  thorpej Avoid strict-alias warnings.
 1.57 01-Sep-2002  mjacob Do not enable interrupt driven mailbox commands for non-FC scsi.
 1.56 12-Aug-2002  mjacob Various changes to allow for overriding just loopid and/or iid.
Fix a random 23XX ISR reading bug. Be chattier about HBA_BOTCH
errors. More f/w cashdump layering.
 1.55 15-Jun-2002  mjacob Add support for ISP_FC_GETHINFO which can tell you connection topology,
current speed, loopid, etc.
 1.54 08-Jun-2002  yamt make auto const variables static.
 1.53 04-Apr-2002  mjacob branches: 1.53.2; 1.53.4;
Redo fabric evaluation to not use GET ALL NEXT (GA_NXT). Switches seem
to be trying to wriggle out of supporting this well. Instead, use
GID_FT to get a list of Port IDs and then use GPN_ID/GNN_ID to find the
port and node wwn. This should make working on fabrics a bit cleaner and
more stable.

This also caused some cleanup of SNS subcommand canonicalization so that
we can actually check for FS_ACC and FS_RJT, and if we get an FS_RJT,
print out the reason and explanation codes.

We'll keep the old GA_NXT method around if people want to uncomment a
controlling definition in ispvar.h.

This also had us clean up ISPASYNC_FABRICDEV to use a local lportdb argument
and to have the caller explicitly say that a device is at the end of the
fabric list.
 1.52 21-Feb-2002  mjacob Implement F/W crashdumps for 2200 && 2300 cards (kernel compile option).

Distinguish between 2312 and 2300 cards (they *are* different). Enable
RIO (Reduced Interrupt Operation) for the LVD cards (hey- I've seen
batched completions of the 30 commands at a time with this,....)...

If we get a Port Logout on local loop topologies, we have to force the
f/w to log back in. The easiest way (for us) to do this is to force
a LIP. This also will wake up the disk that probably just had a f/w crash.

Implement mailbox 'continuations'- this allows interrupts to re-drive
a mailbox command if it's one that just essentially repeats the previous
mailbox command (e.g., f/w download). This saves a boatload of sleep/wakeup
twitches.

If we're not a 2300 and we're about to return with a 'bogus interrupt'- check
the semaphore register to be non-zero at all and outgoing mailbox 0- this
seems to be where some of the lost ISP1080 commands came from.
 1.51 14-Dec-2001  mjacob Major restructuring for swizzling to the request queue and unswizzling from
the response queue. Instead of the ad hoc ISP_SWIZZLE_REQUEST, we now have
a complete set of inline functions in isp_inline.h. Each platform is
responsible for providing just one of a set of ISP_IOX_{GET,PUT}{8,16,32}
macros.

The reason this needs to be done is that we need to have a single set of
functions that will work correctly on multiple architectures for both little
and big endian machines. It also needs to work correctly in the case that
we have the request or response queues in memory that has to be treated
specially (e.g., have ddi_dma_sync called on it for Solaris after we update
it or before we read from it).

One thing that falls out of this is that we no longer build requests in the
request queue itself. Instead, we build the request locally (e.g., on the
stack) and then as part of the swizzling operation, copy it to the request
queue entry we've allocated. I thought long and hard about whether this was
too expensive a change to make as it in a lot of cases requires an extra
copy. On balance, the flexbility is worth it. With any luck, the entry that
we build locally stays in a processor writeback cache (after all, it's only
64 bytes) so that the cost of actually flushing it to the memory area that is
the shared queue with the PCI device is not all that expensive. We may examine
this again and try to get clever in the future to try and avoid copies.

Another change that falls out of this is that MEMORYBARRIER should be taken
a lot more seriously. The macro ISP_ADD_REQUEST does a MEMORYBARRIER on the
entry being added. But there had been many other places this had been missing.
It's now very important that it be done.

For NetBSD, it does a ddi_dmamap_sync as appropriate. This gets us out of
the explicit ddi_dmamap_sync on the whole response queue that we did for SBus
cards at each interrupt.

Set things up so that platforms that cannot have an SBus don't get a lot of
the SBus code checks (dead coded out).

Additional changes:

Fix a longstanding buglet of sorts. When we get an entry via isp_getrqentry,
the iptr value that gets returned is the value we intend to eventually plug
into the ISP registers as the entry *one past* the last one we've written-
*not* the current entry we're updating. All along we've been calling sync
functions on the wrong index value. Argh. The 'fix' here is to rename all
'iptr' variables as 'nxti' to remember that this is the 'next' pointer-
not the current pointer.

Devote a single bit to mboxbsy- and set aside bits for output mbox registers
that we need to pick up- we can have at least one command which does not
have any defined output registers (MBOX_EXECUTE_FIRMWARE).

Explicitly decode GetAllNext SNS Response back *as* a GetAllNext response.
Otherwise, we won't unswizzle it correctly.

Nuke some additional __P macros.
 1.50 13-Nov-2001  lukem add/cleanup RCSID
 1.49 28-Sep-2001  mjacob Now that we have a fixed thaw thingie- we can turn back on sleeping
on mailbox commands.
 1.48 05-Sep-2001  mjacob branches: 1.48.2;
Fix a misspelled error message.

Temp work around problems where if we allow for non-polled mailbox commands
we got nailed by hardclock calling is for a timed thaw. Basically, this
means we only enable non-polled mailbox commands in the FC kthread when it
calls isp_fc_runstate.
 1.47 01-Sep-2001  mjacob Add support for 2 Gigabit cards (2300/2312). This necessitated a change
in how interrupts are down- the 23XX has not only a different place to check
for an interrupt, but unlike all other QLogic cards, you have to read the
status as a 32 bit word- not 16 bit words. Rather than have device specific
functions as called from the core module (in isp_intr), it makes more sense
to have the platform/bus modules do the gruntwork of splitting out the
isr, semaphore register and the first outgoing mailbox register (if needed)
*prior* to calling isp_intr (if calling isp_intr is necessary at all).
 1.46 07-Jul-2001  mjacob branches: 1.46.2;
If I've told myself once, I've told myself 1000 times- *NEVER* commit
w/o test compiling first. Argh. I nuked one extra line that I shouldn't
have.
 1.45 06-Jul-2001  mjacob Defer turning off the no_mbox_ints flag until after the system is ready
for interrupts. Handle FW crashes in outer layer.
 1.44 25-May-2001  mjacob Create a kernel thread for Fibre Channel cards. This is the new
way of doing business- modulo some startup spasms and peculiarities
of the way kthreads are started (*after* configuration, weird) and
some strangeness with the freeze/thaw code, what now happens is
that any of Loop Down, LIP, Loop Reset or Port Datbase or Name
Server Database Changed ASYNC events cause the queues to freeze
for this channel. The arrival of a Loop UP is not relevant.

What *is* relevant is that the Port Datbase or Name Server Changed
async event indicate that it's okay to go and (re)evaluate the
state of the FC link and (re)probe local loop and fabric membership.
We have a kthread do this because it's *sooooo* much nicer to be
able to sleep while doing the 130-250 mailbox commands it'll take
to re-evaluate things.

When the state is well known again, we can unfreeze the channel
queues. Then, as commands start arriving, we simply can start them
or bounce them with XS_SELTIMEOUT (if the device in question has
gone away). Previously, we did lazy evaluation, which meant that
if a change occurred, we would wait until the very *next* command
to go rebuild stuff.

The reason this is not sensible is:

a) Even with sleeping, you can hang up your system because you might be
making some poor stat(2) call pay the price of re-evaluating the whole
fabric.

b) If we ever really want to get to dynamic attachment/detachment, we
should find out sooner, rather than later, where things get to.

Split off ispminphys_1020 from ispminphys- a 1020 has a 24 bit limit-
not anything newer.

Re-enable LIPs and Loop Resets as async events- this allows the outer
layer to set policy about them.

Roll platform major && minor. Remove bogus waitq (no longer used).
Remove callout entry in softc (no longer used). Define some shorthands
for channels. Clean up a variety of cruft left over from the
thorpej_scsipi changeover.
 1.43 16-May-2001  mjacob It's 'role None', not 'role No'.

Also, pay attention to the difference in the ISPASYNC_CHANGE_NOTIFY
between loop and fabric changes.
 1.42 25-Apr-2001  bouyer Pull up the thorpej_scsipi branch to main branch.
This is a completely rewritten scsipi_xfer execution engine, and the
associated changes to HBA drivers. Overview of changes & features:
- All xfers are queued in the mid-layer, rather than doing so in an
ad-hoc fashion in individual adapter drivers.
- Adapter/channel resource management in the mid-layer, avoids even trying
to start running an xfer if the adapter/channel doesn't have the resources.
- Better communication between the mid-layer and the adapters.
- Asynchronous event notification mechanism from adapter to mid-layer and
peripherals.
- Better peripheral queue management: freeze/thaw, sorted requeueing during
recovery, etc.
- Clean separation of peripherals, adapters, and adapter channels (no more
scsipi_link).
- Kernel thread for each scsipi_channel makes error recovery much easier
(no more dealing with interrupt context when recovering from an error).
- Mid-layer support for tagged queueing: commands can have the tag type
set explicitly, tag IDs are allocated in the mid-layer (thus eliminating
the need to use buggy tag ID allocation schemes in many adapter drivers).
- support for QUEUE FULL and CHECK CONDITION status in mid-layer; the command
will be requeued, or a REQUEST SENSE will be sent as appropriate.

Just before the merge syssrc has been tagged with thorpej_scsipi_beforemerge
 1.41 10-Apr-2001  mjacob Add initial implementation of ISP_SDBLEV, ISP_RESETHBA, ISP_FC_RESCAN,
ISP_FC_LIP and ISP_FC_GETDINFO ioctls.
 1.40 14-Mar-2001  mjacob Handles are now 16 bits. ANSIfy.
 1.39 12-Feb-2001  mjacob branches: 1.39.2;
Do some cleanup based upon adapter role- mainly not enabling interrupts
if we're ISP_ROLE_NONE. Change ISPASYNC_LOGGED_INOUT to ISPASYNC_PROMENADE.
Make sure we note if something is a fabric device.
 1.38 09-Jan-2001  mjacob ISPASYNC_PDB_CHANGED->ISPASYNC_LOGGED_INOUT. And also, ISPASYNC_CHANGE_NOTIFY
is for both local loop and fabric cases now.
 1.37 28-Dec-2000  mjacob Apply nearly all of Bill Sommerfeld's -Wformat patches. The one
change I didn't take is the %llu format- I can't have a common
across multiple platform module assume a %ll argument capability-
which really pointed out that I shouldn't be trying to *print*
something which could long long.
 1.36 28-Dec-2000  mjacob Turn ISP_LOCK/ISP_UNLOCK into ISP_ILOCK/ISP_IUNLOCK macros for routines
that are driven from a timeout (oops, they're on the interrupt stack).
 1.35 28-Dec-2000  mjacob Restore the change fvdl made. Sorry about not noticing it. The
header (about 'Maintainer') is supposed to help encourage folks
to coordinate with me.
 1.34 23-Dec-2000  wiz Fix pathnames in comment.
 1.33 09-Dec-2000  mjacob Finally fix this driver to be sensible about the ENDIAN dance. It's not
quite simply a question of the Qlogic being little endian and having
to have stuff swapped on big endian machines- it also has to do with the
fact that the SBus and PCI DMA layouts are wierd with respect to this.

At any rate, now finally fixed- works on Mac G4, tested it on a SS10
for sparc, checked on alpha to see if I've broken anything, and as
soon as I get another spare afternoon I'll finally install a sparc64
version which should just work (as it'll be like the Mac).
 1.32 04-Dec-2000  fvdl Remove uninitialized variable usage (it was redundant anyway).
 1.31 16-Oct-2000  mjacob Add in commented-out hiwater measurement.

Remove egregious older bug which had us refusing to log into
fabric devices unless they were NL ports. Whuff.
 1.30 14-Aug-2000  mjacob Add a maintenance note. Change all splbio's to use the ISP_LOCK/ISP_UNLOCK
or ISP_ILOCK/ISP_IUNLOCK macros.
 1.29 08-Aug-2000  mjacob Remove ispcmd_slow routine- SCBUSACCEL routine will set/clear tag/wide/sync.
Make some changes about where some things sit in the softc.
 1.28 01-Aug-2000  mjacob Core version 2.0 (platform version 1.0) rewrite of ISP driver. Some
interace cleanups, some new common functions. The major impact that
will be noticeable right away is that if you boot with not Fibre connected
to the FC cards, you no longer hang indefinitely.
 1.27 07-Jul-2000  mjacob Gah. Bad port from FreeBSD code (thanks Robert Elz) for setting
up default timeout for watchdogging commands.
 1.26 05-Jul-2000  mjacob Redo watchdogs to handle cases of false death of commands- time
each command now.. Get rid of SCCLUn stuff. Use an isp_done routine
to handle cases of watchdog and isp_done racing to completion.
 1.25 13-May-2000  he branches: 1.25.4;
Update from Matthew Jacob:

Correctly account for F-port vs. F-port (no FLOGI_ACC) topologies.
Make sure we get a port database entry for the fabric name server.
Preserve fabric logins if the device didn't change across fabric
or port database changes, or the device has already logged into
us (e.g., for target/initiator dual role devices like Veritas
SANbox). Propagate class 3 service parameter changes where devices
can change roles.

Fix all occurrences of setting a sendmarker so that setting it
for one bus on dual bus cards doesn't wipe a pending sendmarker
for other busses on the same card :-;.

Comments added and clarifications made in some of the target mode code.
 1.24 23-Mar-2000  thorpej New callout mechanism with two major improvements over the old
timeout()/untimeout() API:
- Clients supply callout handle storage, thus eliminating problems of
resource allocation.
- Insertion and removal of callouts is constant time, important as
this facility is used quite a lot in the kernel.

The old timeout()/untimeout() API has been removed from the kernel.
 1.23 12-Feb-2000  mjacob add 80 MHz case
 1.22 20-Dec-1999  mjacob clean unused fwrev stuff
 1.21 16-Dec-1999  mjacob Dual LVD (1280) support.
 1.20 05-Dec-1999  mjacob Oops. The compiler didn't catch this 'used before set'. Kudos
to Sean Doran for finding it and being nice in telling me.
 1.19 04-Dec-1999  mjacob (wow- I thought I'd already committed most of this).

Clean up some isp_attach time stuff- if ISP2100_FABRIC is defined try *really*
hard to make sure that we get the firmware state to FW_READY and see the
loop state where the Port Database is ready to be gathered- if we don't do
this it's unlikely we will be able to correctly query the nameserver because
we won't see that we're on a fabric.

Clean up the completely broken and stupid attempts to hot switch the
'slow' start routine out of the way. Sigh.

Turn speed announcements into CFGPRINTF functions (available only if DEBUG
defined).
 1.18 17-Oct-1999  mjacob branches: 1.18.2;
some comments added
 1.17 14-Oct-1999  mjacob Add in an ioctl entry point so scsictl mediated bus resets will work.
Redo how we start commands- do a 'slow' start function which then
looks to see when we're done the configuration process at which point
it *then* enables sync/wide mode. Set the max openings amount to the
true max openings- not a synthetic. Add a timeout driven command requeue
function so that Loop Down events well freeze things until a later point
in time where they might be restarted.
 1.16 30-Sep-1999  thorpej branches: 1.16.2;
Update for SCSIPI changes. Note that capabilities update is disabled
until Matt Jacob has a change to update the driver for the latest
firmware, etc. since update device parameters seems to fail once the
system is really up and running, and eventually causes the controller
to wedge. This may be due to a firmware bug.

Per discussion with Matt.
 1.15 05-Jul-1999  mjacob Change to approved NASA/Ames copyright. Add Fabric support. Fix SCCLUN support.
Add code that tries to track LoopID shifting.
 1.14 12-May-1999  mjacob Do a fairly large internal restructuring to accomodate dual-bus host adapters
(e.g., the 1240). Include the new 1080/1240 NVRAM layout reading code. Some
moderately significant mailbox changes were necessary also to accomodate a
second channel.
 1.13 04-Apr-1999  mjacob firmware revision now a triple
 1.12 26-Mar-1999  mjacob branches: 1.12.2; 1.12.4;
add isp1080 support and some basic PDB change stuff
 1.11 17-Mar-1999  mjacob Update the driver with some infrastructure for the 1080. Fix an embarrassing
clock botch bug. Additional infrastructure for PDB change stuff.
 1.10 09-Feb-1999  mjacob Do SCSI Bus resets in this layer (now). Don't do it for Fibre Channel yet
(we get LOOP DOWN events, and we'll hang on that at this time).

Add other isp_async cases- ISPASYNC_LOOP_DOWN and ISPASYNC_LOOP_UP. DOWN
will cause internal queuing until UP, whereupon a timeout will fire up
any pending xfers. It doesn't really keep commands from getting destroyed
by loop down events, but at least minimizes the damage. This was much
easier to implement with CAM.
 1.9 30-Jan-1999  mjacob Implement and use Fast Posting for both parallel && fibre. Redo a bit of
the startup code. Implement a call to outer framework function so that
asynchronous events can be handled (e.g., speed negotiation, target mode).

Roll internal release tags.
 1.8 28-Dec-1998  mjacob clean up headers; move uninit/watch to outer layers
 1.7 05-Dec-1998  mjacob Update BA for new max_lun parameter for SCSIbusses. Clearify maximum luns
for FC HB based upon a SCCLUN define (15 for normal- 255 out of a possible
65535 for SCCLUN). Propagate loopid as adapter_target.

Roll minor platform version. Roll core version number.

Update mailbox definitions with cleaner target mode structure definitions.
Clean up some ENDIAN stuff. Correct botched ISP2100_NVRAM_HARDLOOPID offset.
 1.6 19-Nov-1998  thorpej Adapt to the new scsipi_adapter interface.
 1.5 10-Oct-1998  thorpej branches: 1.5.2;
Garbage-collect the open_target_lu and close_target_lu entry points from
struct scsipi_adapter; they were not used.

Add a scsipi_ioctl entry point to struct scsipi_adapter. This will be
used to issue ioctl commands to the host adapters.

Inspired by PR #6090, from Matt Jacob.
 1.4 17-Sep-1998  mjacob cleanup header to be just NetBSD
 1.3 08-Sep-1998  mjacob add case for going from probetime to runtime speeds
 1.2 18-Jul-1998  mjacob fix bogus comments
 1.1 15-Jul-1998  mjacob NetBSD OS specific routines and definitions.
 1.5.2.2 07-Nov-1998  cgd pull up revs 1.1-1.5 from trunk (new file), and patch so that it works
in 1.3.x. (mjacob)
 1.5.2.1 10-Oct-1998  cgd file isp_netbsd.c was added on branch netbsd-1-3 on 1998-11-07 05:50:35 +0000
 1.12.4.2 02-Aug-1999  thorpej Update from trunk.
 1.12.4.1 21-Jun-1999  thorpej Sync w/ -current.
 1.12.2.2 13-May-2000  he Apply patch (requested by Matthew Jacob via he):
Correctly account for F-port vs. F-port (no FLOGI_ACC) topologies.
Make sure we get a port database entry for the fabric name server.
Preserve fabric logins if the device didn't change across fabric
or port database changes, or the device has already logged into
us (e.g., for target/initiator dual role devices like Veritas
SANbox). Propagate class 3 service parameter changes where devices
can change roles.

Fix all occurrences of setting a sendmarker so that setting it
for one bus on dual bus cards doesn't wipe a pending sendmarker
for other busses on the same card.

Comments added and clarifications made in some of the target mode code.

Add support for > 12 byte CDBs. Split out nvram reading into
per-card functions. Add proper Ultra2/Ultra3 support. Upgrade
firmware.
 1.12.2.1 08-Jan-2000  he Pull up revisions 1.13-1.15,1.17-1.22 (via patch, requested by mjacob):
Untangle Qlogic firmware copyright problems and update firmware.
Untangle some MD support issues for said firmware. Add 1280 (Dual
LVD), 1240 (Dual Ultra), 2200 (2nd Generation Qlogic FC chipset).
Fix some synchronous negotiation problems for parallel SCSI.
Firm up some Fabric Support issues.
 1.16.2.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.18.2.16 23-Apr-2001  mjacob Do some minor clenaups with respect to adapter and channel openings.
There's no need to set channel openings if you don't set a flag that
says to look at them.

Make sure that the adapt_max_periph value is, for now, less than the
possible SPI-2 tag count. We really need a flag that says "don't do
tags for me as the adatper generates its own". Set channel ID for
FC to MAX_FC_TARG (i.e., get it out of the way entirely).
 1.18.2.15 21-Apr-2001  bouyer Sync with HEAD
 1.18.2.14 06-Apr-2001  bouyer Hum, don't set max number of request per periph larger than 256.
 1.18.2.13 27-Mar-2001  bouyer Sync with HEAD.
 1.18.2.12 27-Mar-2001  bouyer Convert these drivers to thorpej_scsipi (untested).
 1.18.2.11 12-Mar-2001  bouyer Sync with HEAD.
 1.18.2.10 18-Jan-2001  bouyer Sync with head (for UBC+NFS fixes, mostly).
 1.18.2.9 05-Jan-2001  bouyer Sync with HEAD
 1.18.2.8 13-Dec-2000  bouyer Sync with HEAD (for UBC fixes).
 1.18.2.7 08-Dec-2000  bouyer Sync with HEAD.
 1.18.2.6 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.18.2.5 26-Oct-1999  thorpej Update for:

Deal a little more gracefully with the fact that xfer mode parameters
are for the I_T Nexus, and make all xfer mode updates `async events'.
 1.18.2.4 20-Oct-1999  thorpej - Eliminate sleeping from adapter routines.
- On a LOOP DOWN event, freeze the channel queue.
- On a LOOP UP event, do a timed thaw on the channel queue.
 1.18.2.3 19-Oct-1999  thorpej Use the ASYNC_EVENT_XFER_MODE callback.
 1.18.2.2 19-Oct-1999  thorpej Ooops, forgot to initialize a variable.
 1.18.2.1 19-Oct-1999  thorpej Adapt to scsipi API changes.
 1.25.4.3 16-Mar-2001  he Pull up revisions 1.36-1.40 (requested by mjacob):
Do some cleanup based upon adapter role - mainly not enabling
interrupts if we're ISP_ROLE_NONE. ISPASYNC_LOGGED_INOUT ->
ISPASYNC_PROMENADE. Make sure we note if something is a fabric
device. ISPASYNC_PDB_CHANGED -> ISPASYNC_LOGGED_INOUT. Add
-Wformat patches. Handles are 16 bits.
 1.25.4.2 25-Jan-2001  jhawk Pull up revisions 1.31-1.35 (requested by mjacob):
Add in correct SBus bursting; upgrade to 2.01.26 firmware; pull to latest
initiator mode level; make changes to WWN default handling; quiet
chatty boot messages; fix endian code so MacPPC works; fix bug in
lock recursion counter; fix bug which excluded all but NL-ports from
being logged into on a fabric.
 1.25.4.1 28-Aug-2000  mjacob Complete rewrite of internals for isp core version 2.0.
Pullup to netbsd-1-5 approved by thorpej@netbsd.org.
 1.39.2.13 11-Dec-2002  thorpej Sync with HEAD.
 1.39.2.12 17-Sep-2002  nathanw Catch up to -current.
 1.39.2.11 13-Aug-2002  nathanw Catch up to -current.
 1.39.2.10 20-Jun-2002  nathanw Catch up to -current.
 1.39.2.9 17-Apr-2002  nathanw Catch up to -current.
 1.39.2.8 28-Feb-2002  nathanw Catch up to -current.
 1.39.2.7 08-Jan-2002  nathanw Catch up to -current.
 1.39.2.6 14-Nov-2001  nathanw Catch up to -current.
 1.39.2.5 08-Oct-2001  nathanw Catch up to -current.
 1.39.2.4 21-Sep-2001  nathanw Catch up to -current.
 1.39.2.3 24-Aug-2001  nathanw Catch up with -current.
 1.39.2.2 21-Jun-2001  nathanw Catch up to -current.
 1.39.2.1 09-Apr-2001  nathanw Catch up with -current.
 1.46.2.5 06-Sep-2002  jdolecek sync kqueue branch with HEAD
 1.46.2.4 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.46.2.3 16-Mar-2002  jdolecek Catch up with -current.
 1.46.2.2 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.46.2.1 13-Sep-2001  thorpej Update the kqueue branch to HEAD.
 1.48.2.1 01-Oct-2001  fvdl Catch up with -current.
 1.53.4.1 01-Sep-2002  lukem Pull up revision 1.57 (requested by lukem for mjacob in ticket #757):
Do not enable interrupt driven mailbox commands for non-FC scsi.
 1.53.2.2 29-Aug-2002  gehenna catch up with -current.
 1.53.2.1 20-Jun-2002  gehenna catch up with -current.
 1.59.2.5 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.59.2.4 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.59.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.59.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.59.2.1 03-Aug-2004  skrll Sync with HEAD
 1.64.10.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.64.8.1 29-Apr-2005  kent sync with -current
 1.66.2.5 17-Mar-2008  yamt sync with head.
 1.66.2.4 03-Sep-2007  yamt sync with head.
 1.66.2.3 26-Feb-2007  yamt sync with head.
 1.66.2.2 30-Dec-2006  yamt sync with head.
 1.66.2.1 21-Jun-2006  yamt sync with head.
 1.67.12.1 24-May-2006  tron Merge 2006-05-24 NetBSD-current into the "peter-altq" branch.
 1.67.10.1 11-May-2006  elad sync with head
 1.67.8.2 03-Sep-2006  yamt sync with head.
 1.67.8.1 24-May-2006  yamt sync with head.
 1.67.6.1 01-Jun-2006  kardel Sync with head.
 1.67.4.1 09-Sep-2006  rpaulo sync with head
 1.69.4.2 10-Dec-2006  yamt sync with head.
 1.69.4.1 22-Oct-2006  yamt sync with head
 1.69.2.2 01-Feb-2007  ad Sync with head.
 1.69.2.1 18-Nov-2006  ad Sync with head.
 1.72.2.1 12-Mar-2007  rmind Sync with HEAD.
 1.73.4.1 11-Jul-2007  mjf Sync with head.
 1.73.2.7 15-Jul-2007  ad Sync with head.
 1.73.2.6 01-Jul-2007  ad Adapt to callout API change.
 1.73.2.5 09-Jun-2007  ad Sync with head.
 1.73.2.4 27-May-2007  ad Sync with head.
 1.73.2.3 13-May-2007  ad - Pass the error number and residual count to biodone(), and let it handle
setting error indicators. Prepare to eliminate B_ERROR.
- Add a flag argument to brelse() to be set into the buf's flags, instead
of doing it directly. Typically used to set B_INVAL.
- Add a "struct cpu_info *" argument to kthread_create(), to be used to
create bound threads. Change "bool mpsafe" to "int flags".
- Allow exit of LWPs in the IDL state when (l != curlwp).
- More locking fixes & conversion to the new API.
 1.73.2.2 10-Apr-2007  ad Nuke the deferred kthread creation stuff, as it's no longer needed.
Pointed out by thorpej@.
 1.73.2.1 09-Apr-2007  ad - Add two new arguments to kthread_create1: pri_t pri, bool mpsafe.
- Fork kthreads off proc0 as new LWPs, not new processes.
 1.75.28.3 28-Sep-2008  mjf Sync with HEAD.
 1.75.28.2 02-Jun-2008  mjf Sync with HEAD.
 1.75.28.1 03-Apr-2008  mjf Sync with HEAD.
 1.75.24.1 24-Mar-2008  keiichi sync with head.
 1.75.8.1 23-Mar-2008  matt sync with HEAD
 1.77.10.1 19-Oct-2008  haad Sync with HEAD.
 1.77.8.1 18-Jul-2008  simonb Sync with head.
 1.77.6.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.77.4.7 09-Oct-2010  yamt sync with head
 1.77.4.6 11-Aug-2010  yamt sync with head.
 1.77.4.5 11-Mar-2010  yamt sync with head
 1.77.4.4 16-Sep-2009  yamt sync with head
 1.77.4.3 18-Jul-2009  yamt sync with head.
 1.77.4.2 16-May-2009  yamt sync with head
 1.77.4.1 04-May-2009  yamt sync with head.
 1.78.8.2 23-Jul-2009  jym Sync with HEAD.
 1.78.8.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.82.4.2 05-Mar-2011  rmind sync with head
 1.82.4.1 30-May-2010  rmind sync with head
 1.82.2.2 22-Oct-2010  uebayasi Sync with HEAD (-D20101022).
 1.82.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.84.12.1 18-Feb-2012  mrg merge to -current.
 1.84.8.2 30-Oct-2012  yamt sync with head
 1.84.8.1 17-Apr-2012  yamt sync with head
 1.85.4.1 01-Nov-2012  matt sync with netbsd-6-0-RELEASE.
 1.85.2.2 19-Aug-2017  snj Pull up following revision(s) (requested by mrg in ticket #1485):
sys/dev/ic/isp_netbsd.c: revision 1.89
Reject out-of-bounds channel index.
From Ilja Van Sprundel.
 1.85.2.1 03-Sep-2012  riz branches: 1.85.2.1.2; 1.85.2.1.4;
Pull up following revision(s) (requested by bouyer in ticket #524):
sys/dev/ic/isp_netbsd.c: revision 1.86
Properly fill the struct timeval before using it: a timeout in microseconds has
to be converted to seconds and microseconds.
Fix KASSERT("usec >= 0 && usec < 1000000") in tvtohz().
While there, simplify computation of to (avoids a timersub() in tvhzto()
and directly call tvtohz() with the interval).
 1.85.2.1.4.1 19-Aug-2017  snj Pull up following revision(s) (requested by mrg in ticket #1485):
sys/dev/ic/isp_netbsd.c: revision 1.89
Reject out-of-bounds channel index.
From Ilja Van Sprundel.
 1.85.2.1.2.1 19-Aug-2017  snj Pull up following revision(s) (requested by mrg in ticket #1485):
sys/dev/ic/isp_netbsd.c: revision 1.89
Reject out-of-bounds channel index.
From Ilja Van Sprundel.
 1.86.20.1 12-Aug-2017  snj Pull up following revision(s) (requested by mrg in ticket #1482):
sys/dev/ic/isp_netbsd.c: revision 1.89
Reject out-of-bounds channel index.
From Ilja Van Sprundel.
 1.86.16.1 12-Aug-2017  snj Pull up following revision(s) (requested by mrg in ticket #1482):
sys/dev/ic/isp_netbsd.c: revision 1.89
Reject out-of-bounds channel index.
From Ilja Van Sprundel.
 1.86.14.1 12-Aug-2017  snj Pull up following revision(s) (requested by mrg in ticket #1482):
sys/dev/ic/isp_netbsd.c: revision 1.89
Reject out-of-bounds channel index.
From Ilja Van Sprundel.
 1.86.2.1 03-Dec-2017  jdolecek update from HEAD
 1.87.2.2 28-Aug-2017  skrll Sync with HEAD
 1.87.2.1 06-Apr-2015  skrll Sync with HEAD
 1.88.10.1 09-Aug-2017  snj Pull up following revision(s) (requested by spz in ticket #195):
sys/dev/ic/isp_netbsd.c: revision 1.89
Reject out-of-bounds channel index.
From Ilja Van Sprundel.
 1.89.4.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.89.4.1 10-Jun-2019  christos Sync with HEAD
 1.89.2.1 06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.95.8.1 14-Dec-2020  thorpej Sync w/ HEAD.
 1.96.2.1 21-Mar-2021  thorpej Give config_found() the same variadic arguments treatment as
config_search(). This commit only adds the CFARG_EOL sentinel
to the existing config_found() calls. Conversion of config_found_sm_loc()
and config_found_ia() call sites will be in subsequent commits.
 1.97.8.1 04-Aug-2021  thorpej Adapt to CFARGS().
 1.76 20-Sep-2019  christos declare printflike functions and fix another printf format.
also change 0x%x -> %#x.
 1.75 28-Aug-2015  joerg branches: 1.75.18;
Add parenthesis for a macro to prevent surprises when it is negated.
 1.74 17-Jul-2011  joerg branches: 1.74.12; 1.74.30;
Retire varargs.h support. Move machine/stdarg.h logic into MI
sys/stdarg.h and expect compiler to provide proper builtins, defaulting
to the GCC interface. lint still has a special fallback.
Reduce abuse of _BSD_VA_LIST_ by defining __va_list by default and
derive va_list as required by standards.
 1.73 28-Feb-2011  mjacob Update isp driver to be in sync with other platforms. Mostly very minor changes
with effectively zero impact on NetBSD.
 1.72 26-Mar-2010  mjacob branches: 1.72.2; 1.72.4;
Synchronize with other platforms:

Strongly architect handles so we can more easily detect bogus
handles. This switches us to a full 32 bits for all handles.

Handle the case of FC disks disappearing and then reappearing-
at least at the FC transport level.

Some better and finer control of debug and non-debug printouts.
 1.71 11-Jan-2010  mjacob branches: 1.71.2; 1.71.4;
Keep track of what appear to be live Fibre Channel disks and store up the
Port WWNs for them as well as attaching them as a "port-wwn" property to
the device node in question. This allows MD code to find the boot device
on some platforms.

This is less clean than it should be. A better solution would be to make
some changes to the scsi infrastructure so that periphs can query and
use and store their own "native" transport addresses. However, that's
a much more invasive change and it is not clear how many ports or devices
really want or need that information (yet).
 1.70 03-Dec-2009  mjacob Have as a backup at least *some* usable WWN.
 1.69 23-Nov-2009  rmind Remove some unecessary includes sys/user.h header.
 1.68 07-Sep-2009  tsutsui Split device_t/softc.
Tested QLogic 1020 Fast Wide SCSI HBA at PCI.
Sbus attachment is untested, but not so much quirks in it.
 1.67 25-Jun-2009  mjacob Update ISP driver to latest and greatest. Includes support for the 8Gb part.
 1.66 11-May-2008  mjacob branches: 1.66.12;
Make fc scratch acquisition something that can fail. Remove in_intr flag.
Otherwise synchronize with changes made due to other platforms.
 1.65 08-Apr-2008  cegger branches: 1.65.2; 1.65.4; 1.65.6;
use aprint_*_dev and device_xname
 1.64 11-Mar-2008  mjacob Checkpoint of some fairly major isp(4) rototilling.

Reintroduce more of a 'channel' concept in preparation for NP-IV support.
This gets rid of the chanA/chanB concept as the 2400 can have up to 128
virtual channels. Actually, with MID firmware you can also have the 2200
and 2300 support 'channels, but they do it with an FL-Port topology.
Because FC cards can now have 'channels', just about every support
function for fibre channel had to be redone to have a channel index
as well. Rototill isp_ioctl.h for channel stuff as well.

Pick up a lot of work about fabric management (hopefully better) and keep
work in place that will allow for dynamic attachment/detachment of devices
(if I can figure out how to make the midlayer support it).

Merge the target code with external trees. Eventually it might even
be sorted out on NetBSD.

Update some firmware stuff.
 1.63 19-Oct-2007  ad branches: 1.63.12; 1.63.16;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.62 09-Jul-2007  ad branches: 1.62.6; 1.62.8; 1.62.12;
Merge some of the less invasive changes from the vmlocking branch:

- kthread, callout, devsw API changes
- select()/poll() improvements
- miscellaneous MT safety improvements
 1.61 08-Jul-2007  mjacob Oh, dear, I didn't have an i386 or amd64 up and running and
missed a LITTLE ENDIAN version of a define.
 1.60 07-Jul-2007  mjacob Do a number of 24XX related fixes: fix the actual getting of initiator
status correctly (which we never were doing before). Add an underrun
checker for 24XX. The process of sorting this out led to a whole bunch
of endian surprises that had to be dealt with. Fix NVRAM endian issues
for the 24XX as well.

Do a little 2200 related cleanup- in particular, turn off complaints about
not finding a fast posting handle when running with RIO enabled- we are
somehow getting duplicate completions in this case. If we ignore them and
don't complain, all is well, and we actually start averaging > 2 commands
completed per interrupt.
 1.59 24-May-2007  mjacob Major update to isp(4) driver to bring it in line with external sources.

The major changes are:

+ 4Gb (24XX) card support
+ Rewritten fabric and loop evaluation code
+ New f/w sets

The 4Gb changes required major rototilling, which caused a rewrite of
fabric and loop eval code. The latter can now be set up to tune for
dynamic device arrival/departure if the framework is set up for it,
or to be firm about waiting for devices.

Testing has been principally on amd64, i386 and sparc64 and seems to
not have broken things for me.
 1.58 04-Mar-2007  christos branches: 1.58.2; 1.58.4;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.57 29-Mar-2006  thorpej branches: 1.57.14;
Remove isp_unit -- it is not used.
 1.56 16-Feb-2006  perry branches: 1.56.2; 1.56.4; 1.56.6;
Change "inline" back to "__inline" in .h files -- C99 is still too
new, and some apps compile things in C89 mode. C89 keywords stay.

As per core@.
 1.55 24-Dec-2005  perry branches: 1.55.2; 1.55.4; 1.55.6;
Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.54 11-Dec-2005  christos merge ktrace-lwp.
 1.53 27-Feb-2005  perry branches: 1.53.4;
nuke trailing whitespace
 1.52 04-Dec-2003  keihan branches: 1.52.8; 1.52.10;
netbsd.org -> NetBSD.org

This was the last commit of this kind to src/sys, which is now totally
"NetBSD.org clean". Thanks for the patiance, and sorry for all the commits.
 1.51 18-Oct-2002  mjacob branches: 1.51.6;
Slight cleanup to use ISP_MUSTPOLL macro in case we can ever fix the
issue about knowing when we're on the interrupt stack or not.
 1.50 04-Apr-2002  mjacob Redo fabric evaluation to not use GET ALL NEXT (GA_NXT). Switches seem
to be trying to wriggle out of supporting this well. Instead, use
GID_FT to get a list of Port IDs and then use GPN_ID/GNN_ID to find the
port and node wwn. This should make working on fabrics a bit cleaner and
more stable.

This also caused some cleanup of SNS subcommand canonicalization so that
we can actually check for FS_ACC and FS_RJT, and if we get an FS_RJT,
print out the reason and explanation codes.

We'll keep the old GA_NXT method around if people want to uncomment a
controlling definition in ispvar.h.

This also had us clean up ISPASYNC_FABRICDEV to use a local lportdb argument
and to have the caller explicitly say that a device is at the end of the
fabric list.
 1.49 31-Mar-2002  mjacob Thanks to Jason Wright of OpenBSD- spotted that the offsets were all wrong
for bus_dmamap_sync calls. They'd been blindly ported from Solaris which
had *one* dma map for the entire control space, so offset was incremented
for the Request, Response and FC Scratch spaces. Tsk. There are three maps
in NetBSD. I should probably make them one anyway.
 1.48 21-Feb-2002  mjacob Implement F/W crashdumps for 2200 && 2300 cards (kernel compile option).

Distinguish between 2312 and 2300 cards (they *are* different). Enable
RIO (Reduced Interrupt Operation) for the LVD cards (hey- I've seen
batched completions of the 30 commands at a time with this,....)...

If we get a Port Logout on local loop topologies, we have to force the
f/w to log back in. The easiest way (for us) to do this is to force
a LIP. This also will wake up the disk that probably just had a f/w crash.

Implement mailbox 'continuations'- this allows interrupts to re-drive
a mailbox command if it's one that just essentially repeats the previous
mailbox command (e.g., f/w download). This saves a boatload of sleep/wakeup
twitches.

If we're not a 2300 and we're about to return with a 'bogus interrupt'- check
the semaphore register to be non-zero at all and outgoing mailbox 0- this
seems to be where some of the lost ISP1080 commands came from.
 1.47 14-Dec-2001  mjacob Major restructuring for swizzling to the request queue and unswizzling from
the response queue. Instead of the ad hoc ISP_SWIZZLE_REQUEST, we now have
a complete set of inline functions in isp_inline.h. Each platform is
responsible for providing just one of a set of ISP_IOX_{GET,PUT}{8,16,32}
macros.

The reason this needs to be done is that we need to have a single set of
functions that will work correctly on multiple architectures for both little
and big endian machines. It also needs to work correctly in the case that
we have the request or response queues in memory that has to be treated
specially (e.g., have ddi_dma_sync called on it for Solaris after we update
it or before we read from it).

One thing that falls out of this is that we no longer build requests in the
request queue itself. Instead, we build the request locally (e.g., on the
stack) and then as part of the swizzling operation, copy it to the request
queue entry we've allocated. I thought long and hard about whether this was
too expensive a change to make as it in a lot of cases requires an extra
copy. On balance, the flexbility is worth it. With any luck, the entry that
we build locally stays in a processor writeback cache (after all, it's only
64 bytes) so that the cost of actually flushing it to the memory area that is
the shared queue with the PCI device is not all that expensive. We may examine
this again and try to get clever in the future to try and avoid copies.

Another change that falls out of this is that MEMORYBARRIER should be taken
a lot more seriously. The macro ISP_ADD_REQUEST does a MEMORYBARRIER on the
entry being added. But there had been many other places this had been missing.
It's now very important that it be done.

For NetBSD, it does a ddi_dmamap_sync as appropriate. This gets us out of
the explicit ddi_dmamap_sync on the whole response queue that we did for SBus
cards at each interrupt.

Set things up so that platforms that cannot have an SBus don't get a lot of
the SBus code checks (dead coded out).

Additional changes:

Fix a longstanding buglet of sorts. When we get an entry via isp_getrqentry,
the iptr value that gets returned is the value we intend to eventually plug
into the ISP registers as the entry *one past* the last one we've written-
*not* the current entry we're updating. All along we've been calling sync
functions on the wrong index value. Argh. The 'fix' here is to rename all
'iptr' variables as 'nxti' to remember that this is the 'next' pointer-
not the current pointer.

Devote a single bit to mboxbsy- and set aside bits for output mbox registers
that we need to pick up- we can have at least one command which does not
have any defined output registers (MBOX_EXECUTE_FIRMWARE).

Explicitly decode GetAllNext SNS Response back *as* a GetAllNext response.
Otherwise, we won't unswizzle it correctly.

Nuke some additional __P macros.
 1.46 01-Sep-2001  mjacob Add support for 2 Gigabit cards (2300/2312). This necessitated a change
in how interrupts are down- the 23XX has not only a different place to check
for an interrupt, but unlike all other QLogic cards, you have to read the
status as a 32 bit word- not 16 bit words. Rather than have device specific
functions as called from the core module (in isp_intr), it makes more sense
to have the platform/bus modules do the gruntwork of splitting out the
isr, semaphore register and the first outgoing mailbox register (if needed)
*prior* to calling isp_intr (if calling isp_intr is necessary at all).
 1.45 07-Jul-2001  thorpej branches: 1.45.2;
bzero -> memset
 1.44 07-Jul-2001  thorpej bcopy -> memcpy
 1.43 25-May-2001  mjacob Create a kernel thread for Fibre Channel cards. This is the new
way of doing business- modulo some startup spasms and peculiarities
of the way kthreads are started (*after* configuration, weird) and
some strangeness with the freeze/thaw code, what now happens is
that any of Loop Down, LIP, Loop Reset or Port Datbase or Name
Server Database Changed ASYNC events cause the queues to freeze
for this channel. The arrival of a Loop UP is not relevant.

What *is* relevant is that the Port Datbase or Name Server Changed
async event indicate that it's okay to go and (re)evaluate the
state of the FC link and (re)probe local loop and fabric membership.
We have a kthread do this because it's *sooooo* much nicer to be
able to sleep while doing the 130-250 mailbox commands it'll take
to re-evaluate things.

When the state is well known again, we can unfreeze the channel
queues. Then, as commands start arriving, we simply can start them
or bounce them with XS_SELTIMEOUT (if the device in question has
gone away). Previously, we did lazy evaluation, which meant that
if a change occurred, we would wait until the very *next* command
to go rebuild stuff.

The reason this is not sensible is:

a) Even with sleeping, you can hang up your system because you might be
making some poor stat(2) call pay the price of re-evaluating the whole
fabric.

b) If we ever really want to get to dynamic attachment/detachment, we
should find out sooner, rather than later, where things get to.

Split off ispminphys_1020 from ispminphys- a 1020 has a 24 bit limit-
not anything newer.

Re-enable LIPs and Loop Resets as async events- this allows the outer
layer to set policy about them.

Roll platform major && minor. Remove bogus waitq (no longer used).
Remove callout entry in softc (no longer used). Define some shorthands
for channels. Clean up a variety of cruft left over from the
thorpej_scsipi changeover.
 1.42 16-May-2001  mjacob Per helpful suggestion from LukeM- make INLINE usage consistent (and
use correct __inline format).
 1.41 16-May-2001  mjacob Long overdue- put locks on the usage of the mailbox command stuff. This
keeps us from stomping on ourselves.

Say we're in the middle of re-evaluating a loop (and sleeping) when a
command completes, or a timer refires, and this *other* thread decides
*it* wants to start re-evaluating the loop. Bad news.

We have to be a bit careful- if we can't acquire the MBOX semaphore at
interrupt level, we will simulate a host interface error. This is a bit
of a temp workaround. There's some work underway driven by a NetBSD
commercial user that will try and force most mailbox stuff into a
part A/part B interrupt driven model.
 1.40 25-Apr-2001  bouyer Pull up the thorpej_scsipi branch to main branch.
This is a completely rewritten scsipi_xfer execution engine, and the
associated changes to HBA drivers. Overview of changes & features:
- All xfers are queued in the mid-layer, rather than doing so in an
ad-hoc fashion in individual adapter drivers.
- Adapter/channel resource management in the mid-layer, avoids even trying
to start running an xfer if the adapter/channel doesn't have the resources.
- Better communication between the mid-layer and the adapters.
- Asynchronous event notification mechanism from adapter to mid-layer and
peripherals.
- Better peripheral queue management: freeze/thaw, sorted requeueing during
recovery, etc.
- Clean separation of peripherals, adapters, and adapter channels (no more
scsipi_link).
- Kernel thread for each scsipi_channel makes error recovery much easier
(no more dealing with interrupt context when recovering from an error).
- Mid-layer support for tagged queueing: commands can have the tag type
set explicitly, tag IDs are allocated in the mid-layer (thus eliminating
the need to use buggy tag ID allocation schemes in many adapter drivers).
- support for QUEUE FULL and CHECK CONDITION status in mid-layer; the command
will be requeued, or a REQUEST SENSE will be sent as appropriate.

Just before the merge syssrc has been tagged with thorpej_scsipi_beforemerge
 1.39 10-Apr-2001  mjacob Include isp_ioctl.h.
 1.38 14-Mar-2001  mjacob ANSIfy source.
 1.37 28-Feb-2001  mjacob branches: 1.37.2;
roll platform minor
 1.36 12-Feb-2001  mjacob Remove ISP2100_FABRIC (we're always fabric now). Fix usage of isp_lastmbxcmd
to report the mailbox command that times out. Fix isp_unswizzle_sns_rsp
which for reasons *I* find obscurer just doesn't work correctly on sparc64
with words past 128. I have no idea why this *does* work on SparcLinux.
 1.35 05-Jan-2001  mjacob (some of these changes were made in the previous revision- oops)
Say which mailbox command times out (polled or interrupting). Also,
give them a bit more time to timeout (5 seconds instead of 2).
 1.34 05-Jan-2001  mjacob Ian McDonnell <apriori@world.std.com> made me see the error of my ways.
*Cough*. Ahem. I hadn't been setting error to XS_SENSE when there was
a check condition. Major blunder.
 1.33 23-Dec-2000  wiz Fix pathnames in comment.
 1.32 09-Dec-2000  mjacob Finally fix this driver to be sensible about the ENDIAN dance. It's not
quite simply a question of the Qlogic being little endian and having
to have stuff swapped on big endian machines- it also has to do with the
fact that the SBus and PCI DMA layouts are wierd with respect to this.

At any rate, now finally fixed- works on Mac G4, tested it on a SS10
for sparc, checked on alpha to see if I've broken anything, and as
soon as I get another spare afternoon I'll finally install a sparc64
version which should just work (as it'll be like the Mac).
 1.31 14-Nov-2000  thorpej Pull in <uvm/uvm_extern.h>
 1.30 16-Oct-2000  mjacob Make changes relevant to changes in WWN defaults.

Also fix egregious bug where we would never decrement
the islocked recursion counter. I guess this means
that we don't recurse on this platform! All of this should
go away when we have real lock primitives to use in drivers.
 1.29 14-Aug-2000  mjacob Add a maintenance note. Move the single bit tags of islocked and
onintstack to be real integers. Add ISP_ILOCK/ISP_IUNLOCK macros.

Fix the isp_lock/isp_unlock inlines to stop being so embarrassingly
in error. Why, or why, can't I have mutex_enter/mutex_exit, pretty please?
 1.28 11-Aug-2000  tls Make our policy WRT tagged queueing consistent and sane: ordered tags for sync writes, simple tags for all else. Should make ahc and adv a bit more reliable (metadata writes won't get reordered incorrectly...) and isp a bit more performant (it was using ordered tags all the time).
 1.27 01-Aug-2000  mjacob Core version 2.0 (platform version 1.0) rewrite of ISP driver. Some
interace cleanups, some new common functions. The major impact that
will be noticeable right away is that if you boot with not Fibre connected
to the FC cards, you no longer hang indefinitely.
 1.26 05-Jul-2000  mjacob Roll platform minor. We are now always supporting ISP2100_FABRIC. Add
in new MBOX_WAIT_COMPLETE/MBOX_NOTIFY_COMPLETE macros (ready for SMPizing).
Define STRNCAT inline for our usage.

Stealing a bit of the xs_status flags to maintain command state that
is pertinent for the hBA- should really reserve them for private usage
in scsipiconf.h.
 1.25 28-Jun-2000  mrg remove include of <vm/vm.h>. <vm/vm.h> -> <uvm/uvm_extern.h>
 1.24 26-Jun-2000  mrg remove redundant vm includes.
 1.23 23-Mar-2000  thorpej branches: 1.23.4;
New callout mechanism with two major improvements over the old
timeout()/untimeout() API:
- Clients supply callout handle storage, thus eliminating problems of
resource allocation.
- Insertion and removal of callouts is constant time, important as
this facility is used quite a lot in the kernel.

The old timeout()/untimeout() API has been removed from the kernel.
 1.22 19-Feb-2000  mjacob Add in ISP_SWIZZLE_CONTINUATION macro.
 1.21 20-Dec-1999  mjacob restore (by request) CFGPRINTF to DIAGNOSTIC level kernels
 1.20 16-Dec-1999  mjacob Dual LVD (1280) support.
 1.19 04-Dec-1999  mjacob Rearrange defines to make the file diff cleaner with OpenBSD. Change CFGPRINTF
and default verbose levels. Add in a forced compile in f/w define unless
either IS_DISABLE_FW or ISP_COMPILE_FW defined.
 1.18 14-Oct-1999  mjacob branches: 1.18.2;
Roll platform version. Keep a bitmap of 'discovered' devices for SCSI adapters
so we'll know when it's time to switch from 'slow' command mode to normal.
Change some settings for configuration printfs and debug levels. Redo the
internal ispscsicmd return definitions and let isp_cmd translate them as
approrpriate to NetBSD values. Remove the inline functions from here- they're
now in isp_inline.h. Put in the start of the correct SWIZZLE/UNSWIZZLE
functions.
 1.17 30-Sep-1999  thorpej branches: 1.17.2;
Update for SCSIPI changes. Note that capabilities update is disabled
until Matt Jacob has a change to update the driver for the latest
firmware, etc. since update device parameters seems to fail once the
system is really up and running, and eventually causes the controller
to wedge. This may be due to a firmware bug.

Per discussion with Matt.
 1.16 07-Sep-1999  mjacob A useful discussion with Jason convinced me that I had selected the
wrong tag as the default tag to use- we should use ORDERED, no SIMPLE.
 1.15 05-Jul-1999  mjacob Change to approved NASA/Ames copyright. Add Fabric support. Fix SCCLUN support.
Add code that tries to track LoopID shifting.
 1.14 12-May-1999  mjacob Do a fairly large internal restructuring to accomodate dual-bus host adapters
(e.g., the 1240). Include the new 1080/1240 NVRAM layout reading code. Some
moderately significant mailbox changes were necessary also to accomodate a
second channel.
 1.13 04-Apr-1999  mjacob roll internal revs
 1.12 26-Mar-1999  mjacob branches: 1.12.2; 1.12.4;
add isp1080 support and some basic PDB change stuff
 1.11 17-Mar-1999  mjacob Update the driver with some infrastructure for the 1080. Fix an embarrassing
clock botch bug. Additional infrastructure for PDB change stuff.
 1.10 09-Feb-1999  mjacob Roll platform revision level. Add blocked flag and waitq to osinfo structure.
 1.9 30-Jan-1999  mjacob Implement and use Fast Posting for both parallel && fibre. Redo a bit of
the startup code. Implement a call to outer framework function so that
asynchronous events can be handled (e.g., speed negotiation, target mode).

Roll internal release tags.
 1.8 10-Jan-1999  mjacob cross platform define MEMZERO added
 1.7 28-Dec-1998  mjacob clean up headers; move uninit/watch to outer layers
 1.6 05-Dec-1998  mjacob Update BA for new max_lun parameter for SCSIbusses. Clearify maximum luns
for FC HB based upon a SCCLUN define (15 for normal- 255 out of a possible
65535 for SCCLUN). Propagate loopid as adapter_target.

Roll minor platform version. Roll core version number.

Update mailbox definitions with cleaner target mode structure definitions.
Clean up some ENDIAN stuff. Correct botched ISP2100_NVRAM_HARDLOOPID offset.
 1.5 19-Nov-1998  thorpej Adapt to the new scsipi_adapter interface.
 1.4 17-Sep-1998  mjacob branches: 1.4.2;
cleanup header to be just NetBSD
 1.3 08-Sep-1998  mjacob roll revision, change default tagging to simple tags
 1.2 18-Jul-1998  mjacob roll revision
 1.1 15-Jul-1998  mjacob NetBSD OS specific routines and definitions.
 1.4.2.2 07-Nov-1998  cgd pull up revs 1.1-1.4 from trunk (new file), and patch so that it works
in 1.3.x. (mjacob)
 1.4.2.1 17-Sep-1998  cgd file isp_netbsd.h was added on branch netbsd-1-3 on 1998-11-07 05:51:02 +0000
 1.12.4.2 02-Aug-1999  thorpej Update from trunk.
 1.12.4.1 21-Jun-1999  thorpej Sync w/ -current.
 1.12.2.2 13-May-2000  he Apply patch (requested by Matthew Jacob via he):
Correctly account for F-port vs. F-port (no FLOGI_ACC) topologies.
Make sure we get a port database entry for the fabric name server.
Preserve fabric logins if the device didn't change across fabric
or port database changes, or the device has already logged into
us (e.g., for target/initiator dual role devices like Veritas
SANbox). Propagate class 3 service parameter changes where devices
can change roles.

Fix all occurrences of setting a sendmarker so that setting it
for one bus on dual bus cards doesn't wipe a pending sendmarker
for other busses on the same card.

Comments added and clarifications made in some of the target mode code.

Add support for > 12 byte CDBs. Split out nvram reading into
per-card functions. Add proper Ultra2/Ultra3 support. Upgrade
firmware.
 1.12.2.1 08-Jan-2000  he Pull up revisions 1.13-1.16,1.18-1.21 (via patch, requested by mjacob):
Untangle Qlogic firmware copyright problems and update firmware.
Untangle some MD support issues for said firmware. Add 1280 (Dual
LVD), 1240 (Dual Ultra), 2200 (2nd Generation Qlogic FC chipset).
Fix some synchronous negotiation problems for parallel SCSI.
Firm up some Fabric Support issues.
 1.17.2.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.18.2.14 21-Apr-2001  bouyer Sync with HEAD
 1.18.2.13 27-Mar-2001  bouyer Ops, XS_CHANNEL() is channel number, not pointer to scsipi_channel.
 1.18.2.12 27-Mar-2001  bouyer Sync with HEAD.
 1.18.2.11 27-Mar-2001  bouyer Convert these drivers to thorpej_scsipi (untested).
 1.18.2.10 12-Mar-2001  bouyer Sync with HEAD.
 1.18.2.9 05-Jan-2001  bouyer Sync with HEAD
 1.18.2.8 13-Dec-2000  bouyer Sync with HEAD (for UBC fixes).
 1.18.2.7 22-Nov-2000  bouyer Sync with HEAD.
 1.18.2.6 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.18.2.5 04-Feb-2000  thorpej - If the ISP's internal queues are full, don't synthesize a QFULL status,
but rather report it as a host adapter resource shortage.
- If the I_T_L's command queues are full, report that the target is busy
(with QFULL status).
 1.18.2.4 01-Nov-1999  thorpej Fixup the SC_DEBUG() stuff for the new world order.
 1.18.2.3 20-Oct-1999  thorpej - Eliminate sleeping from adapter routines.
- On a LOOP DOWN event, freeze the channel queue.
- On a LOOP UP event, do a timed thaw on the channel queue.
 1.18.2.2 19-Oct-1999  thorpej Let the midlayer tell if we can use tagged queueing, and what sort of
tag to use.
 1.18.2.1 19-Oct-1999  thorpej Adapt to scsipi API changes.
 1.23.4.4 16-Mar-2001  he Pull up revisions 1.34-1.38 (requested by mjacob):
Remove ISP2100_FABRIC (we're always fabric now). Say which
mailbox command times out (polled or interrupting). Set error
to XS_SENSE when there is a check condition. Roll platform minor.
ANSIfy source.
 1.23.4.3 25-Jan-2001  jhawk Pull up revisions 1.30-1.33 (requested by mjacob):
Add in correct SBus bursting; upgrade to 2.01.26 firmware; pull to latest
initiator mode level; make changes to WWN default handling; quiet
chatty boot messages; fix endian code so MacPPC works; fix bug in
lock recursion counter; fix bug which excluded all but NL-ports from
being logged into on a fabric.
 1.23.4.2 28-Aug-2000  mjacob Complete rewrite of internals for isp core version 2.0.
Pullup to netbsd-1-5 approved by thorpej@netbsd.org.
 1.23.4.1 11-Aug-2000  tls Pull up tagged queueing policy changes: now we use ordered tags for sync writes, simple tags for reads and async writes.
 1.37.2.8 11-Nov-2002  nathanw Catch up to -current
 1.37.2.7 17-Apr-2002  nathanw Catch up to -current.
 1.37.2.6 28-Feb-2002  nathanw Catch up to -current.
 1.37.2.5 08-Jan-2002  nathanw Catch up to -current.
 1.37.2.4 21-Sep-2001  nathanw Catch up to -current.
 1.37.2.3 24-Aug-2001  nathanw Catch up with -current.
 1.37.2.2 21-Jun-2001  nathanw Catch up to -current.
 1.37.2.1 09-Apr-2001  nathanw Catch up with -current.
 1.45.2.4 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.45.2.3 16-Mar-2002  jdolecek Catch up with -current.
 1.45.2.2 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.45.2.1 13-Sep-2001  thorpej Update the kqueue branch to HEAD.
 1.51.6.4 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.51.6.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.51.6.2 18-Sep-2004  skrll Sync with HEAD.
 1.51.6.1 03-Aug-2004  skrll Sync with HEAD
 1.52.10.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.52.8.1 29-Apr-2005  kent sync with -current
 1.53.4.4 17-Mar-2008  yamt sync with head.
 1.53.4.3 27-Oct-2007  yamt sync with head.
 1.53.4.2 03-Sep-2007  yamt sync with head.
 1.53.4.1 21-Jun-2006  yamt sync with head.
 1.55.6.1 22-Apr-2006  simonb Sync with head.
 1.55.4.1 09-Sep-2006  rpaulo sync with head
 1.55.2.1 18-Feb-2006  yamt sync with head.
 1.56.6.1 31-Mar-2006  tron Merge 2006-03-31 NetBSD-current into the "peter-altq" branch.
 1.56.4.1 19-Apr-2006  elad sync with head.
 1.56.2.1 01-Apr-2006  yamt sync with head.
 1.57.14.1 12-Mar-2007  rmind Sync with HEAD.
 1.58.4.1 11-Jul-2007  mjf Sync with head.
 1.58.2.4 23-Oct-2007  ad Sync with head.
 1.58.2.3 15-Jul-2007  ad Sync with head.
 1.58.2.2 27-May-2007  ad Sync with head.
 1.58.2.1 09-Apr-2007  ad - Add two new arguments to kthread_create1: pri_t pri, bool mpsafe.
- Fork kthreads off proc0 as new LWPs, not new processes.
 1.62.12.1 25-Oct-2007  bouyer Sync with HEAD.
 1.62.8.2 23-Mar-2008  matt sync with HEAD
 1.62.8.1 06-Nov-2007  matt sync with HEAD
 1.62.6.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.63.16.2 02-Jun-2008  mjf Sync with HEAD.
 1.63.16.1 03-Apr-2008  mjf Sync with HEAD.
 1.63.12.1 24-Mar-2008  keiichi sync with head.
 1.65.6.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.65.4.5 11-Aug-2010  yamt sync with head.
 1.65.4.4 11-Mar-2010  yamt sync with head
 1.65.4.3 16-Sep-2009  yamt sync with head
 1.65.4.2 18-Jul-2009  yamt sync with head.
 1.65.4.1 16-May-2008  yamt sync with head.
 1.65.2.1 18-May-2008  yamt sync with head.
 1.66.12.1 23-Jul-2009  jym Sync with HEAD.
 1.71.4.2 05-Mar-2011  rmind sync with head
 1.71.4.1 30-May-2010  rmind sync with head
 1.71.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.72.4.1 05-Mar-2011  bouyer Sync with HEAD
 1.72.2.1 06-Jun-2011  jruoho Sync with HEAD.
 1.74.30.1 22-Sep-2015  skrll Sync with HEAD
 1.74.12.1 03-Dec-2017  jdolecek update from HEAD
 1.75.18.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.6 12-Dec-2021  andvar fix typos in word "request(s)".
 1.5 26-Mar-2010  mjacob Synchronize with other platforms:

Strongly architect handles so we can more easily detect bogus
handles. This switches us to a full 32 bits for all handles.

Handle the case of FC disks disappearing and then reappearing-
at least at the FC transport level.

Some better and finer control of debug and non-debug printouts.
 1.4 03-Jan-2010  mjacob branches: 1.4.2; 1.4.4;
Add some more definitions appropriate for T10 standards
and use those cleaned up definitions.

Use 2100 style firmware loading if the load address and
load size is less than 64k. Some apparently buggy ROMs
out there choke otherwise.

Clean up some WWNN derivations from WWPN.
 1.3 25-Jun-2009  mjacob Update ISP driver to latest and greatest. Includes support for the 8Gb part.
 1.2 11-Mar-2008  mjacob branches: 1.2.4; 1.2.18;
Checkpoint of some fairly major isp(4) rototilling.

Reintroduce more of a 'channel' concept in preparation for NP-IV support.
This gets rid of the chanA/chanB concept as the 2400 can have up to 128
virtual channels. Actually, with MID firmware you can also have the 2200
and 2300 support 'channels, but they do it with an FL-Port topology.
Because FC cards can now have 'channels', just about every support
function for fibre channel had to be redone to have a channel index
as well. Rototill isp_ioctl.h for channel stuff as well.

Pick up a lot of work about fabric management (hopefully better) and keep
work in place that will allow for dynamic attachment/detachment of devices
(if I can figure out how to make the midlayer support it).

Merge the target code with external trees. Eventually it might even
be sorted out on NetBSD.

Update some firmware stuff.
 1.1 24-May-2007  mjacob branches: 1.1.2; 1.1.4; 1.1.12; 1.1.14; 1.1.30; 1.1.34;
Major update to isp(4) driver to bring it in line with external sources.

The major changes are:

+ 4Gb (24XX) card support
+ Rewritten fabric and loop evaluation code
+ New f/w sets

The 4Gb changes required major rototilling, which caused a rewrite of
fabric and loop eval code. The latter can now be set up to tune for
dynamic device arrival/departure if the framework is set up for it,
or to be firm about waiting for devices.

Testing has been principally on amd64, i386 and sparc64 and seems to
not have broken things for me.
 1.1.34.1 03-Apr-2008  mjf Sync with HEAD.
 1.1.30.1 24-Mar-2008  keiichi sync with head.
 1.1.14.3 17-Mar-2008  yamt sync with head.
 1.1.14.2 03-Sep-2007  yamt sync with head.
 1.1.14.1 24-May-2007  yamt file isp_stds.h was added on branch yamt-lazymbuf on 2007-09-03 14:34:48 +0000
 1.1.12.1 23-Mar-2008  matt sync with HEAD
 1.1.4.2 11-Jul-2007  mjf Sync with head.
 1.1.4.1 24-May-2007  mjf file isp_stds.h was added on branch mjf-ufs-trans on 2007-07-11 20:05:56 +0000
 1.1.2.2 09-Jun-2007  ad Sync with head.
 1.1.2.1 24-May-2007  ad file isp_stds.h was added on branch vmlocking on 2007-06-09 21:37:16 +0000
 1.2.18.1 23-Jul-2009  jym Sync with HEAD.
 1.2.4.3 11-Aug-2010  yamt sync with head.
 1.2.4.2 11-Mar-2010  yamt sync with head
 1.2.4.1 18-Jul-2009  yamt sync with head.
 1.4.4.1 30-May-2010  rmind sync with head
 1.4.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.38 08-Sep-2024  rillig fix a/an grammar in obvious cases
 1.37 12-Dec-2021  andvar branches: 1.37.10;
fix various typos, mainly in comments.
 1.36 21-Aug-2021  andvar fix some more typos in comments/log messages, improve wording as well.
 1.35 03-Sep-2018  riastradh Rename min/max -> uimin/uimax for better honesty.

These functions are defined on unsigned int. The generic name
min/max should not silently truncate to 32 bits on 64-bit systems.
This is purely a name change -- no functional change intended.

HOWEVER! Some subsystems have

#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))

even though our standard name for that is MIN/MAX. Although these
may invite multiple evaluation bugs, these do _not_ cause integer
truncation.

To avoid `fixing' these cases, I first changed the name in libkern,
and then compile-tested every file where min/max occurred in order to
confirm that it failed -- and thus confirm that nothing shadowed
min/max -- before changing it.

I have left a handful of bootloaders that are too annoying to
compile-test, and some dead code:

cobalt ews4800mips hp300 hppa ia64 luna68k vax
acorn32/if_ie.c (not included in any kernels)
macppc/if_gm.c (superseded by gem(4))

It should be easy to fix the fallout once identified -- this way of
doing things fails safe, and the goal here, after all, is to _avoid_
silent integer truncations, not introduce them.

Maybe one day we can reintroduce min/max as type-generic things that
never silently truncate. But we should avoid doing that for a while,
so that existing code has a chance to be detected by the compiler for
conversion to uimin/uimax without changing the semantics until we can
properly audit it all. (Who knows, maybe in some cases integer
truncation is actually intended!)
 1.34 26-Mar-2010  mjacob branches: 1.34.58; 1.34.60;
Synchronize with other platforms:

Strongly architect handles so we can more easily detect bogus
handles. This switches us to a full 32 bits for all handles.

Handle the case of FC disks disappearing and then reappearing-
at least at the FC transport level.

Some better and finer control of debug and non-debug printouts.
 1.33 25-Jun-2009  mjacob branches: 1.33.2; 1.33.4;
Update ISP driver to latest and greatest. Includes support for the 8Gb part.
 1.32 30-Jun-2008  perry branches: 1.32.10;
__FUNCTION__ -> __func__
 1.31 11-Mar-2008  mjacob branches: 1.31.4; 1.31.6; 1.31.8;
Checkpoint of some fairly major isp(4) rototilling.

Reintroduce more of a 'channel' concept in preparation for NP-IV support.
This gets rid of the chanA/chanB concept as the 2400 can have up to 128
virtual channels. Actually, with MID firmware you can also have the 2200
and 2300 support 'channels, but they do it with an FL-Port topology.
Because FC cards can now have 'channels', just about every support
function for fibre channel had to be redone to have a channel index
as well. Rototill isp_ioctl.h for channel stuff as well.

Pick up a lot of work about fabric management (hopefully better) and keep
work in place that will allow for dynamic attachment/detachment of devices
(if I can figure out how to make the midlayer support it).

Merge the target code with external trees. Eventually it might even
be sorted out on NetBSD.

Update some firmware stuff.
 1.30 24-May-2007  mjacob branches: 1.30.8; 1.30.24; 1.30.28;
Major update to isp(4) driver to bring it in line with external sources.

The major changes are:

+ 4Gb (24XX) card support
+ Rewritten fabric and loop evaluation code
+ New f/w sets

The 4Gb changes required major rototilling, which caused a rewrite of
fabric and loop eval code. The latter can now be set up to tune for
dynamic device arrival/departure if the framework is set up for it,
or to be firm about waiting for devices.

Testing has been principally on amd64, i386 and sparc64 and seems to
not have broken things for me.
 1.29 13-Jan-2007  cube branches: 1.29.6; 1.29.8;
Make it compile with all the options.
 1.28 11-Dec-2005  christos branches: 1.28.20;
merge ktrace-lwp.
 1.27 27-Feb-2005  perry branches: 1.27.4;
nuke trailing whitespace
 1.26 04-Dec-2003  keihan branches: 1.26.8; 1.26.10;
netbsd.org -> NetBSD.org

This was the last commit of this kind to src/sys, which is now totally
"NetBSD.org clean". Thanks for the patiance, and sorry for all the commits.
 1.25 02-Nov-2003  wiz Fix some typos. From Tom Cosgrove via jmc@openbsd.
 1.24 07-Aug-2003  mjacob Various updates to sync with mainline code. Nothing of great significance
to NetBSD, yet.
 1.23 03-Mar-2003  mjacob branches: 1.23.2;
Propagate iid && rxid when we're putting back an ATIO for FC.

Spelling fixes.
 1.22 20-Jan-2003  simonb The Double-Semi-Colon Police.
 1.21 06-Jan-2003  wiz interrupt with two rs.
 1.20 18-Oct-2002  mjacob Some lint fixes.
 1.19 15-Jun-2002  mjacob keep target mode up to date.
 1.18 21-Feb-2002  mjacob branches: 1.18.8;
Implement F/W crashdumps for 2200 && 2300 cards (kernel compile option).

Distinguish between 2312 and 2300 cards (they *are* different). Enable
RIO (Reduced Interrupt Operation) for the LVD cards (hey- I've seen
batched completions of the 30 commands at a time with this,....)...

If we get a Port Logout on local loop topologies, we have to force the
f/w to log back in. The easiest way (for us) to do this is to force
a LIP. This also will wake up the disk that probably just had a f/w crash.

Implement mailbox 'continuations'- this allows interrupts to re-drive
a mailbox command if it's one that just essentially repeats the previous
mailbox command (e.g., f/w download). This saves a boatload of sleep/wakeup
twitches.

If we're not a 2300 and we're about to return with a 'bogus interrupt'- check
the semaphore register to be non-zero at all and outgoing mailbox 0- this
seems to be where some of the lost ISP1080 commands came from.
 1.17 14-Dec-2001  mjacob Major restructuring for swizzling to the request queue and unswizzling from
the response queue. Instead of the ad hoc ISP_SWIZZLE_REQUEST, we now have
a complete set of inline functions in isp_inline.h. Each platform is
responsible for providing just one of a set of ISP_IOX_{GET,PUT}{8,16,32}
macros.

The reason this needs to be done is that we need to have a single set of
functions that will work correctly on multiple architectures for both little
and big endian machines. It also needs to work correctly in the case that
we have the request or response queues in memory that has to be treated
specially (e.g., have ddi_dma_sync called on it for Solaris after we update
it or before we read from it).

One thing that falls out of this is that we no longer build requests in the
request queue itself. Instead, we build the request locally (e.g., on the
stack) and then as part of the swizzling operation, copy it to the request
queue entry we've allocated. I thought long and hard about whether this was
too expensive a change to make as it in a lot of cases requires an extra
copy. On balance, the flexbility is worth it. With any luck, the entry that
we build locally stays in a processor writeback cache (after all, it's only
64 bytes) so that the cost of actually flushing it to the memory area that is
the shared queue with the PCI device is not all that expensive. We may examine
this again and try to get clever in the future to try and avoid copies.

Another change that falls out of this is that MEMORYBARRIER should be taken
a lot more seriously. The macro ISP_ADD_REQUEST does a MEMORYBARRIER on the
entry being added. But there had been many other places this had been missing.
It's now very important that it be done.

For NetBSD, it does a ddi_dmamap_sync as appropriate. This gets us out of
the explicit ddi_dmamap_sync on the whole response queue that we did for SBus
cards at each interrupt.

Set things up so that platforms that cannot have an SBus don't get a lot of
the SBus code checks (dead coded out).

Additional changes:

Fix a longstanding buglet of sorts. When we get an entry via isp_getrqentry,
the iptr value that gets returned is the value we intend to eventually plug
into the ISP registers as the entry *one past* the last one we've written-
*not* the current entry we're updating. All along we've been calling sync
functions on the wrong index value. Argh. The 'fix' here is to rename all
'iptr' variables as 'nxti' to remember that this is the 'next' pointer-
not the current pointer.

Devote a single bit to mboxbsy- and set aside bits for output mbox registers
that we need to pick up- we can have at least one command which does not
have any defined output registers (MBOX_EXECUTE_FIRMWARE).

Explicitly decode GetAllNext SNS Response back *as* a GetAllNext response.
Otherwise, we won't unswizzle it correctly.

Nuke some additional __P macros.
 1.16 13-Nov-2001  lukem add/cleanup RCSID
 1.15 05-Sep-2001  mjacob Synchronize with FreeBSD/Linux.
 1.14 16-May-2001  mjacob branches: 1.14.2;
Keep up with the Joneses.... further synchronization for the eventual
implementation in NetBSD for target mode.
 1.13 05-Apr-2001  mjacob Keep up with the Joneses: sync with common core target mode code. Eventually
we'll do something with it here.
 1.12 14-Mar-2001  mjacob ANSIfy source.
 1.11 14-Mar-2001  mjacob Clean up license && copyright a tad. ct_reserved should now be more
properly called ct_syshandle.
 1.10 23-Dec-2000  wiz branches: 1.10.2;
Fix pathnames in comment.
 1.9 14-Aug-2000  mjacob branches: 1.9.2;
Add a maintenance note
 1.8 08-Aug-2000  mjacob Remove ispcmd_slow routine- SCBUSACCEL routine will set/clear tag/wide/sync.
Make some changes about where some things sit in the softc.
 1.7 01-Aug-2000  mjacob Core version 2.0 (platform version 1.0) rewrite of ISP driver. Some
interace cleanups, some new common functions. The major impact that
will be noticeable right away is that if you boot with not Fibre connected
to the FC cards, you no longer hang indefinitely.
 1.6 19-Jul-2000  mjacob zero result queue entry when done if debugging.
don't do an isp_notify_ack if we're not at run state.
 1.5 05-Jul-2000  mjacob pick up FreeBSD changes
 1.4 13-May-2000  he branches: 1.4.4;
Update from Matthew Jacob:

Correctly account for F-port vs. F-port (no FLOGI_ACC) topologies.
Make sure we get a port database entry for the fabric name server.
Preserve fabric logins if the device didn't change across fabric
or port database changes, or the device has already logged into
us (e.g., for target/initiator dual role devices like Veritas
SANbox). Propagate class 3 service parameter changes where devices
can change roles.

Fix all occurrences of setting a sendmarker so that setting it
for one bus on dual bus cards doesn't wipe a pending sendmarker
for other busses on the same card :-;.

Comments added and clarifications made in some of the target mode code.
 1.3 19-Feb-2000  mjacob Handle dual bus cases for immediate notify and enable lun commands.
 1.2 12-Feb-2000  mjacob some minor cleanups
 1.1 05-Jan-2000  mjacob Add in MI target mode code modules
 1.4.4.1 28-Aug-2000  mjacob Complete rewrite of internals for isp core version 2.0.
Pullup to netbsd-1-5 approved by thorpej@netbsd.org.
 1.9.2.5 21-Apr-2001  bouyer Sync with HEAD
 1.9.2.4 27-Mar-2001  bouyer Sync with HEAD.
 1.9.2.3 05-Jan-2001  bouyer Sync with HEAD
 1.9.2.2 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.9.2.1 14-Aug-2000  bouyer file isp_target.c was added on branch thorpej_scsipi on 2000-11-20 11:40:39 +0000
 1.10.2.9 07-Jan-2003  thorpej Sync with HEAD.
 1.10.2.8 11-Nov-2002  nathanw Catch up to -current
 1.10.2.7 20-Jun-2002  nathanw Catch up to -current.
 1.10.2.6 28-Feb-2002  nathanw Catch up to -current.
 1.10.2.5 08-Jan-2002  nathanw Catch up to -current.
 1.10.2.4 14-Nov-2001  nathanw Catch up to -current.
 1.10.2.3 21-Sep-2001  nathanw Catch up to -current.
 1.10.2.2 21-Jun-2001  nathanw Catch up to -current.
 1.10.2.1 09-Apr-2001  nathanw Catch up with -current.
 1.14.2.4 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.14.2.3 16-Mar-2002  jdolecek Catch up with -current.
 1.14.2.2 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.14.2.1 13-Sep-2001  thorpej Update the kqueue branch to HEAD.
 1.18.8.1 20-Jun-2002  gehenna catch up with -current.
 1.23.2.4 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.23.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.23.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.23.2.1 03-Aug-2004  skrll Sync with HEAD
 1.26.10.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.26.8.1 29-Apr-2005  kent sync with -current
 1.27.4.3 17-Mar-2008  yamt sync with head.
 1.27.4.2 03-Sep-2007  yamt sync with head.
 1.27.4.1 26-Feb-2007  yamt sync with head.
 1.28.20.1 01-Feb-2007  ad Sync with head.
 1.29.8.1 11-Jul-2007  mjf Sync with head.
 1.29.6.2 15-Jul-2007  ad Sync with head.
 1.29.6.1 27-May-2007  ad Sync with head.
 1.30.28.2 02-Jul-2008  mjf Sync with HEAD.
 1.30.28.1 03-Apr-2008  mjf Sync with HEAD.
 1.30.24.1 24-Mar-2008  keiichi sync with head.
 1.30.8.1 23-Mar-2008  matt sync with HEAD
 1.31.8.1 03-Jul-2008  simonb Sync with head.
 1.31.6.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.31.4.3 11-Aug-2010  yamt sync with head.
 1.31.4.2 18-Jul-2009  yamt sync with head.
 1.31.4.1 04-May-2009  yamt sync with head.
 1.32.10.1 23-Jul-2009  jym Sync with HEAD.
 1.33.4.1 30-May-2010  rmind sync with head
 1.33.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.34.60.1 10-Jun-2019  christos Sync with HEAD
 1.34.58.1 06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.37.10.1 02-Aug-2025  perseant Sync with HEAD
 1.27 01-Jun-2023  andvar fix various typos in comments.
 1.26 25-Jun-2009  mjacob Update ISP driver to latest and greatest. Includes support for the 8Gb part.
 1.25 11-Mar-2008  mjacob branches: 1.25.4; 1.25.18;
Checkpoint of some fairly major isp(4) rototilling.

Reintroduce more of a 'channel' concept in preparation for NP-IV support.
This gets rid of the chanA/chanB concept as the 2400 can have up to 128
virtual channels. Actually, with MID firmware you can also have the 2200
and 2300 support 'channels, but they do it with an FL-Port topology.
Because FC cards can now have 'channels', just about every support
function for fibre channel had to be redone to have a channel index
as well. Rototill isp_ioctl.h for channel stuff as well.

Pick up a lot of work about fabric management (hopefully better) and keep
work in place that will allow for dynamic attachment/detachment of devices
(if I can figure out how to make the midlayer support it).

Merge the target code with external trees. Eventually it might even
be sorted out on NetBSD.

Update some firmware stuff.
 1.24 24-May-2007  mjacob branches: 1.24.8; 1.24.24; 1.24.28;
Major update to isp(4) driver to bring it in line with external sources.

The major changes are:

+ 4Gb (24XX) card support
+ Rewritten fabric and loop evaluation code
+ New f/w sets

The 4Gb changes required major rototilling, which caused a rewrite of
fabric and loop eval code. The latter can now be set up to tune for
dynamic device arrival/departure if the framework is set up for it,
or to be firm about waiting for devices.

Testing has been principally on amd64, i386 and sparc64 and seems to
not have broken things for me.
 1.23 13-Jan-2007  cube branches: 1.23.6; 1.23.8;
Make it compile with all the options.
 1.22 11-Dec-2005  christos branches: 1.22.20;
merge ktrace-lwp.
 1.21 04-Dec-2003  keihan branches: 1.21.16;
netbsd.org -> NetBSD.org

This was the last commit of this kind to src/sys, which is now totally
"NetBSD.org clean". Thanks for the patiance, and sorry for all the commits.
 1.20 07-Aug-2003  mjacob Various updates to sync with mainline code. Nothing of great significance
to NetBSD, yet.
 1.19 12-Aug-2002  mjacob branches: 1.19.6;
Various changes to allow for overriding just loopid and/or iid.
Fix a random 23XX ISR reading bug. Be chattier about HBA_BOTCH
errors. More f/w cashdump layering.
 1.18 17-May-2002  mjacob Fix seveeral issues- but the most important of which is that we have
to check if we get a RQCS_DATA_UNDERRUN - if we're an FC card, we may
not have RQCS_RU set- if it isn't set, we just lost a DATA XFR IU in the
middle of the exchange. In this case, we have to bomb out the whole xfer.
We had been getting silent data corruption before.
 1.17 21-Feb-2002  mjacob branches: 1.17.8;
Implement F/W crashdumps for 2200 && 2300 cards (kernel compile option).

Distinguish between 2312 and 2300 cards (they *are* different). Enable
RIO (Reduced Interrupt Operation) for the LVD cards (hey- I've seen
batched completions of the 30 commands at a time with this,....)...

If we get a Port Logout on local loop topologies, we have to force the
f/w to log back in. The easiest way (for us) to do this is to force
a LIP. This also will wake up the disk that probably just had a f/w crash.

Implement mailbox 'continuations'- this allows interrupts to re-drive
a mailbox command if it's one that just essentially repeats the previous
mailbox command (e.g., f/w download). This saves a boatload of sleep/wakeup
twitches.

If we're not a 2300 and we're about to return with a 'bogus interrupt'- check
the semaphore register to be non-zero at all and outgoing mailbox 0- this
seems to be where some of the lost ISP1080 commands came from.
 1.16 14-Dec-2001  mjacob Major restructuring for swizzling to the request queue and unswizzling from
the response queue. Instead of the ad hoc ISP_SWIZZLE_REQUEST, we now have
a complete set of inline functions in isp_inline.h. Each platform is
responsible for providing just one of a set of ISP_IOX_{GET,PUT}{8,16,32}
macros.

The reason this needs to be done is that we need to have a single set of
functions that will work correctly on multiple architectures for both little
and big endian machines. It also needs to work correctly in the case that
we have the request or response queues in memory that has to be treated
specially (e.g., have ddi_dma_sync called on it for Solaris after we update
it or before we read from it).

One thing that falls out of this is that we no longer build requests in the
request queue itself. Instead, we build the request locally (e.g., on the
stack) and then as part of the swizzling operation, copy it to the request
queue entry we've allocated. I thought long and hard about whether this was
too expensive a change to make as it in a lot of cases requires an extra
copy. On balance, the flexbility is worth it. With any luck, the entry that
we build locally stays in a processor writeback cache (after all, it's only
64 bytes) so that the cost of actually flushing it to the memory area that is
the shared queue with the PCI device is not all that expensive. We may examine
this again and try to get clever in the future to try and avoid copies.

Another change that falls out of this is that MEMORYBARRIER should be taken
a lot more seriously. The macro ISP_ADD_REQUEST does a MEMORYBARRIER on the
entry being added. But there had been many other places this had been missing.
It's now very important that it be done.

For NetBSD, it does a ddi_dmamap_sync as appropriate. This gets us out of
the explicit ddi_dmamap_sync on the whole response queue that we did for SBus
cards at each interrupt.

Set things up so that platforms that cannot have an SBus don't get a lot of
the SBus code checks (dead coded out).

Additional changes:

Fix a longstanding buglet of sorts. When we get an entry via isp_getrqentry,
the iptr value that gets returned is the value we intend to eventually plug
into the ISP registers as the entry *one past* the last one we've written-
*not* the current entry we're updating. All along we've been calling sync
functions on the wrong index value. Argh. The 'fix' here is to rename all
'iptr' variables as 'nxti' to remember that this is the 'next' pointer-
not the current pointer.

Devote a single bit to mboxbsy- and set aside bits for output mbox registers
that we need to pick up- we can have at least one command which does not
have any defined output registers (MBOX_EXECUTE_FIRMWARE).

Explicitly decode GetAllNext SNS Response back *as* a GetAllNext response.
Otherwise, we won't unswizzle it correctly.

Nuke some additional __P macros.
 1.15 05-Sep-2001  mjacob Synchronize with FreeBSD/Linux.
 1.14 06-Jul-2001  mjacob branches: 1.14.2;
Minor comment update.
 1.13 16-May-2001  mjacob Keep up with the Joneses.... further synchronization for the eventual
implementation in NetBSD for target mode.
 1.12 05-Apr-2001  mjacob Keep up with the Joneses: sync with common core target mode code. Eventually
we'll do something with it here.
 1.11 14-Mar-2001  mjacob Clean up and update copyright (remove advertising clause). Clean
up header guard. Clean up structure definition for at2_entry so
it's correct rather than derived from at_entry- this is important
for unswizzling purposes. Add a whole bunch of unswizzle macros-
they're not quite right yet but at least they're a start. Note that
we now have, for at_entry, a 16 bit firmware handle as part of what
had been at_reserved- this is to correlate ATIOs with CTIOs- and
this must be carried along as part of a tag value to use with all
CTIOs we send in relation to this ATIO. ANSIfy.
 1.10 28-Dec-2000  mjacob branches: 1.10.2;
add two minor ATIO2 offsets
 1.9 23-Dec-2000  wiz Fix pathnames in comment.
 1.8 14-Aug-2000  mjacob branches: 1.8.2;
Add a maintenance note
 1.7 01-Aug-2000  mjacob Core version 2.0 (platform version 1.0) rewrite of ISP driver. Some
interace cleanups, some new common functions. The major impact that
will be noticeable right away is that if you boot with not Fibre connected
to the FC cards, you no longer hang indefinitely.
 1.6 19-Jul-2000  mjacob add some more CTIO flags
 1.5 05-Jul-2000  mjacob pick up FreeBSD changes
 1.4 13-May-2000  he branches: 1.4.4;
Update from Matthew Jacob:

Correctly account for F-port vs. F-port (no FLOGI_ACC) topologies.
Make sure we get a port database entry for the fabric name server.
Preserve fabric logins if the device didn't change across fabric
or port database changes, or the device has already logged into
us (e.g., for target/initiator dual role devices like Veritas
SANbox). Propagate class 3 service parameter changes where devices
can change roles.

Fix all occurrences of setting a sendmarker so that setting it
for one bus on dual bus cards doesn't wipe a pending sendmarker
for other busses on the same card :-;.

Comments added and clarifications made in some of the target mode code.
 1.3 19-Feb-2000  mjacob Fix ITDEBUG macro
 1.2 12-Feb-2000  mjacob A lot of cleanup and shrinkage. Some items moved to isp_tpublic.h.
 1.1 05-Jan-2000  mjacob Add in MI target mode code modules
 1.4.4.1 28-Aug-2000  mjacob Complete rewrite of internals for isp core version 2.0.
Pullup to netbsd-1-5 approved by thorpej@netbsd.org.
 1.8.2.5 21-Apr-2001  bouyer Sync with HEAD
 1.8.2.4 27-Mar-2001  bouyer Sync with HEAD.
 1.8.2.3 05-Jan-2001  bouyer Sync with HEAD
 1.8.2.2 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.8.2.1 14-Aug-2000  bouyer file isp_target.h was added on branch thorpej_scsipi on 2000-11-20 11:40:40 +0000
 1.10.2.8 13-Aug-2002  nathanw Catch up to -current.
 1.10.2.7 20-Jun-2002  nathanw Catch up to -current.
 1.10.2.6 28-Feb-2002  nathanw Catch up to -current.
 1.10.2.5 08-Jan-2002  nathanw Catch up to -current.
 1.10.2.4 21-Sep-2001  nathanw Catch up to -current.
 1.10.2.3 24-Aug-2001  nathanw Catch up with -current.
 1.10.2.2 21-Jun-2001  nathanw Catch up to -current.
 1.10.2.1 09-Apr-2001  nathanw Catch up with -current.
 1.14.2.5 06-Sep-2002  jdolecek sync kqueue branch with HEAD
 1.14.2.4 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.14.2.3 16-Mar-2002  jdolecek Catch up with -current.
 1.14.2.2 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.14.2.1 13-Sep-2001  thorpej Update the kqueue branch to HEAD.
 1.17.8.2 29-Aug-2002  gehenna catch up with -current.
 1.17.8.1 30-May-2002  gehenna Catch up with -current.
 1.19.6.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.19.6.2 18-Sep-2004  skrll Sync with HEAD.
 1.19.6.1 03-Aug-2004  skrll Sync with HEAD
 1.21.16.3 17-Mar-2008  yamt sync with head.
 1.21.16.2 03-Sep-2007  yamt sync with head.
 1.21.16.1 26-Feb-2007  yamt sync with head.
 1.22.20.1 01-Feb-2007  ad Sync with head.
 1.23.8.1 11-Jul-2007  mjf Sync with head.
 1.23.6.1 27-May-2007  ad Sync with head.
 1.24.28.1 03-Apr-2008  mjf Sync with HEAD.
 1.24.24.1 24-Mar-2008  keiichi sync with head.
 1.24.8.1 23-Mar-2008  matt sync with HEAD
 1.25.18.1 23-Jul-2009  jym Sync with HEAD.
 1.25.4.1 18-Jul-2009  yamt sync with head.
 1.21 12-Dec-2021  andvar fix various typos, mainly in comments.
 1.20 19-Aug-2020  msaitoh s/ be be / be /
 1.19 03-Jan-2010  mjacob Add some more definitions appropriate for T10 standards
and use those cleaned up definitions.

Use 2100 style firmware loading if the load address and
load size is less than 64k. Some apparently buggy ROMs
out there choke otherwise.

Clean up some WWNN derivations from WWPN.
 1.18 25-Jun-2009  mjacob Update ISP driver to latest and greatest. Includes support for the 8Gb part.
 1.17 11-May-2008  mjacob branches: 1.17.12;
Make fc scratch acquisition something that can fail. Remove in_intr flag.
Otherwise synchronize with changes made due to other platforms.
 1.16 11-Mar-2008  mjacob branches: 1.16.2; 1.16.4; 1.16.6;
Checkpoint of some fairly major isp(4) rototilling.

Reintroduce more of a 'channel' concept in preparation for NP-IV support.
This gets rid of the chanA/chanB concept as the 2400 can have up to 128
virtual channels. Actually, with MID firmware you can also have the 2200
and 2300 support 'channels, but they do it with an FL-Port topology.
Because FC cards can now have 'channels', just about every support
function for fibre channel had to be redone to have a channel index
as well. Rototill isp_ioctl.h for channel stuff as well.

Pick up a lot of work about fabric management (hopefully better) and keep
work in place that will allow for dynamic attachment/detachment of devices
(if I can figure out how to make the midlayer support it).

Merge the target code with external trees. Eventually it might even
be sorted out on NetBSD.

Update some firmware stuff.
 1.15 24-May-2007  mjacob branches: 1.15.8; 1.15.24; 1.15.28;
Major update to isp(4) driver to bring it in line with external sources.

The major changes are:

+ 4Gb (24XX) card support
+ Rewritten fabric and loop evaluation code
+ New f/w sets

The 4Gb changes required major rototilling, which caused a rewrite of
fabric and loop eval code. The latter can now be set up to tune for
dynamic device arrival/departure if the framework is set up for it,
or to be firm about waiting for devices.

Testing has been principally on amd64, i386 and sparc64 and seems to
not have broken things for me.
 1.14 11-Dec-2005  christos branches: 1.14.30; 1.14.32;
merge ktrace-lwp.
 1.13 27-Feb-2005  perry branches: 1.13.4;
nuke trailing whitespace
 1.12 04-Dec-2003  keihan branches: 1.12.8; 1.12.10;
netbsd.org -> NetBSD.org

This was the last commit of this kind to src/sys, which is now totally
"NetBSD.org clean". Thanks for the patiance, and sorry for all the commits.
 1.11 02-Nov-2003  wiz Fix some typos. From Tom Cosgrove via jmc@openbsd.
 1.10 07-Aug-2003  mjacob Various updates to sync with mainline code. Nothing of great significance
to NetBSD, yet.
 1.9 03-Mar-2003  mjacob branches: 1.9.2;
spelling
 1.8 14-Dec-2001  mjacob Major restructuring for swizzling to the request queue and unswizzling from
the response queue. Instead of the ad hoc ISP_SWIZZLE_REQUEST, we now have
a complete set of inline functions in isp_inline.h. Each platform is
responsible for providing just one of a set of ISP_IOX_{GET,PUT}{8,16,32}
macros.

The reason this needs to be done is that we need to have a single set of
functions that will work correctly on multiple architectures for both little
and big endian machines. It also needs to work correctly in the case that
we have the request or response queues in memory that has to be treated
specially (e.g., have ddi_dma_sync called on it for Solaris after we update
it or before we read from it).

One thing that falls out of this is that we no longer build requests in the
request queue itself. Instead, we build the request locally (e.g., on the
stack) and then as part of the swizzling operation, copy it to the request
queue entry we've allocated. I thought long and hard about whether this was
too expensive a change to make as it in a lot of cases requires an extra
copy. On balance, the flexbility is worth it. With any luck, the entry that
we build locally stays in a processor writeback cache (after all, it's only
64 bytes) so that the cost of actually flushing it to the memory area that is
the shared queue with the PCI device is not all that expensive. We may examine
this again and try to get clever in the future to try and avoid copies.

Another change that falls out of this is that MEMORYBARRIER should be taken
a lot more seriously. The macro ISP_ADD_REQUEST does a MEMORYBARRIER on the
entry being added. But there had been many other places this had been missing.
It's now very important that it be done.

For NetBSD, it does a ddi_dmamap_sync as appropriate. This gets us out of
the explicit ddi_dmamap_sync on the whole response queue that we did for SBus
cards at each interrupt.

Set things up so that platforms that cannot have an SBus don't get a lot of
the SBus code checks (dead coded out).

Additional changes:

Fix a longstanding buglet of sorts. When we get an entry via isp_getrqentry,
the iptr value that gets returned is the value we intend to eventually plug
into the ISP registers as the entry *one past* the last one we've written-
*not* the current entry we're updating. All along we've been calling sync
functions on the wrong index value. Argh. The 'fix' here is to rename all
'iptr' variables as 'nxti' to remember that this is the 'next' pointer-
not the current pointer.

Devote a single bit to mboxbsy- and set aside bits for output mbox registers
that we need to pick up- we can have at least one command which does not
have any defined output registers (MBOX_EXECUTE_FIRMWARE).

Explicitly decode GetAllNext SNS Response back *as* a GetAllNext response.
Otherwise, we won't unswizzle it correctly.

Nuke some additional __P macros.
 1.7 16-May-2001  mjacob branches: 1.7.2;
Keep up with the Joneses.... further synchronization for the eventual
implementation in NetBSD for target mode.
 1.6 14-Mar-2001  mjacob Clean up some comments. Expand usage of cd_reserved. Expand cd_tagval
to 32 bits so it can haul along this furshlugginer handle for parallel
SCSI as well as a regular vanilla 8 bit SCSI tag.
 1.5 23-Dec-2000  wiz branches: 1.5.2;
Fix pathnames in comment.
 1.4 14-Aug-2000  mjacob branches: 1.4.2;
Add a maintenance note
 1.3 13-May-2000  he branches: 1.3.4;
Update from Matthew Jacob:

Correctly account for F-port vs. F-port (no FLOGI_ACC) topologies.
Make sure we get a port database entry for the fabric name server.
Preserve fabric logins if the device didn't change across fabric
or port database changes, or the device has already logged into
us (e.g., for target/initiator dual role devices like Veritas
SANbox). Propagate class 3 service parameter changes where devices
can change roles.

Fix all occurrences of setting a sendmarker so that setting it
for one bus on dual bus cards doesn't wipe a pending sendmarker
for other busses on the same card :-;.

Comments added and clarifications made in some of the target mode code.
 1.2 19-Feb-2000  mjacob Clarify cd_resid tag.
 1.1 12-Feb-2000  mjacob add a more public shared i/f to target mode
 1.3.4.1 28-Aug-2000  mjacob Complete rewrite of internals for isp core version 2.0.
Pullup to netbsd-1-5 approved by thorpej@netbsd.org.
 1.4.2.4 27-Mar-2001  bouyer Sync with HEAD.
 1.4.2.3 05-Jan-2001  bouyer Sync with HEAD
 1.4.2.2 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.4.2.1 14-Aug-2000  bouyer file isp_tpublic.h was added on branch thorpej_scsipi on 2000-11-20 11:40:40 +0000
 1.5.2.3 08-Jan-2002  nathanw Catch up to -current.
 1.5.2.2 21-Jun-2001  nathanw Catch up to -current.
 1.5.2.1 09-Apr-2001  nathanw Catch up with -current.
 1.7.2.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.9.2.4 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.9.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.9.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.9.2.1 03-Aug-2004  skrll Sync with HEAD
 1.12.10.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.12.8.1 29-Apr-2005  kent sync with -current
 1.13.4.2 17-Mar-2008  yamt sync with head.
 1.13.4.1 03-Sep-2007  yamt sync with head.
 1.14.32.1 11-Jul-2007  mjf Sync with head.
 1.14.30.1 27-May-2007  ad Sync with head.
 1.15.28.2 02-Jun-2008  mjf Sync with HEAD.
 1.15.28.1 03-Apr-2008  mjf Sync with HEAD.
 1.15.24.1 24-Mar-2008  keiichi sync with head.
 1.15.8.1 23-Mar-2008  matt sync with HEAD
 1.16.6.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.16.4.3 11-Mar-2010  yamt sync with head
 1.16.4.2 18-Jul-2009  yamt sync with head.
 1.16.4.1 16-May-2008  yamt sync with head.
 1.16.2.1 18-May-2008  yamt sync with head.
 1.17.12.1 23-Jul-2009  jym Sync with HEAD.
 1.60 26-Apr-2025  andvar s/LIP Rset/LIP Reset/ in comment.
 1.59 02-Feb-2024  andvar branches: 1.59.2;
s/mangement/management/ in comments.
 1.58 21-Sep-2023  msaitoh s/ for for / for / in comment.
 1.57 24-Jan-2022  andvar remove double "with" in comments and usage text. Also fix one typo.
 1.56 14-Sep-2013  martin Remove unused variables, use C99 open arrays for variable sized arrays
 1.55 26-Mar-2010  mjacob branches: 1.55.8; 1.55.18; 1.55.22;
Synchronize with other platforms:

Strongly architect handles so we can more easily detect bogus
handles. This switches us to a full 32 bits for all handles.

Handle the case of FC disks disappearing and then reappearing-
at least at the FC transport level.

Some better and finer control of debug and non-debug printouts.
 1.54 03-Jan-2010  mjacob branches: 1.54.2; 1.54.4;
Add some more definitions appropriate for T10 standards
and use those cleaned up definitions.

Use 2100 style firmware loading if the load address and
load size is less than 64k. Some apparently buggy ROMs
out there choke otherwise.

Clean up some WWNN derivations from WWPN.
 1.53 25-Jun-2009  mjacob Update ISP driver to latest and greatest. Includes support for the 8Gb part.
 1.52 11-May-2008  mjacob branches: 1.52.12;
Make fc scratch acquisition something that can fail. Remove in_intr flag.
Otherwise synchronize with changes made due to other platforms.
 1.51 11-Mar-2008  mjacob branches: 1.51.2; 1.51.4; 1.51.6;
Checkpoint of some fairly major isp(4) rototilling.

Reintroduce more of a 'channel' concept in preparation for NP-IV support.
This gets rid of the chanA/chanB concept as the 2400 can have up to 128
virtual channels. Actually, with MID firmware you can also have the 2200
and 2300 support 'channels, but they do it with an FL-Port topology.
Because FC cards can now have 'channels', just about every support
function for fibre channel had to be redone to have a channel index
as well. Rototill isp_ioctl.h for channel stuff as well.

Pick up a lot of work about fabric management (hopefully better) and keep
work in place that will allow for dynamic attachment/detachment of devices
(if I can figure out how to make the midlayer support it).

Merge the target code with external trees. Eventually it might even
be sorted out on NetBSD.

Update some firmware stuff.
 1.50 24-May-2007  mjacob branches: 1.50.8; 1.50.24; 1.50.28;
Major update to isp(4) driver to bring it in line with external sources.

The major changes are:

+ 4Gb (24XX) card support
+ Rewritten fabric and loop evaluation code
+ New f/w sets

The 4Gb changes required major rototilling, which caused a rewrite of
fabric and loop eval code. The latter can now be set up to tune for
dynamic device arrival/departure if the framework is set up for it,
or to be firm about waiting for devices.

Testing has been principally on amd64, i386 and sparc64 and seems to
not have broken things for me.
 1.49 11-Dec-2005  christos branches: 1.49.30; 1.49.32;
merge ktrace-lwp.
 1.48 27-Feb-2005  perry branches: 1.48.4;
nuke trailing whitespace
 1.47 04-Dec-2003  keihan branches: 1.47.8; 1.47.10;
netbsd.org -> NetBSD.org

This was the last commit of this kind to src/sys, which is now totally
"NetBSD.org clean". Thanks for the patiance, and sorry for all the commits.
 1.46 25-Mar-2003  mjacob branches: 1.46.2;
Fix even stupider fix. It was, in fact, right the first time. Add
a comment clarifying things.
 1.45 03-Mar-2003  mjacob Fix egregious bug where we meant to use bit 5 (1<<5) instead of the
value of 5.
 1.44 18-Oct-2002  mjacob Add some A64 related support.
 1.43 16-Aug-2002  mjacob Further fix problems with 23XX ISR handling and correctly initialize the
23XX to use ZIO in preference to fast posting.
 1.42 12-Aug-2002  mjacob Various changes to allow for overriding just loopid and/or iid.
Fix a random 23XX ISR reading bug. Be chattier about HBA_BOTCH
errors. More f/w cashdump layering.
 1.41 17-May-2002  mjacob Fix seveeral issues- but the most important of which is that we have
to check if we get a RQCS_DATA_UNDERRUN - if we're an FC card, we may
not have RQCS_RU set- if it isn't set, we just lost a DATA XFR IU in the
middle of the exchange. In this case, we have to bomb out the whole xfer.
We had been getting silent data corruption before.
 1.40 11-Apr-2002  mjacob branches: 1.40.2;
Clean up a bit from the last checkin so that the correct result pointers
are used- didn't make a difference, but hey...

Put in commented out GFF_ID code- for use in future attempts to search
the fabric- this probably has to go thru the management server path.

Don't whine about handles we can't find if these are aborted commands
(we know we can't find the handles because we destroy handles after
a successful mailbox abort- we don't wait for the F/W to decide whether
it wants to return a status IOCB after this happens).
 1.39 04-Apr-2002  mjacob Redo fabric evaluation to not use GET ALL NEXT (GA_NXT). Switches seem
to be trying to wriggle out of supporting this well. Instead, use
GID_FT to get a list of Port IDs and then use GPN_ID/GNN_ID to find the
port and node wwn. This should make working on fabrics a bit cleaner and
more stable.

This also caused some cleanup of SNS subcommand canonicalization so that
we can actually check for FS_ACC and FS_RJT, and if we get an FS_RJT,
print out the reason and explanation codes.

We'll keep the old GA_NXT method around if people want to uncomment a
controlling definition in ispvar.h.

This also had us clean up ISPASYNC_FABRICDEV to use a local lportdb argument
and to have the caller explicitly say that a device is at the end of the
fabric list.
 1.38 21-Feb-2002  mjacob Implement F/W crashdumps for 2200 && 2300 cards (kernel compile option).

Distinguish between 2312 and 2300 cards (they *are* different). Enable
RIO (Reduced Interrupt Operation) for the LVD cards (hey- I've seen
batched completions of the 30 commands at a time with this,....)...

If we get a Port Logout on local loop topologies, we have to force the
f/w to log back in. The easiest way (for us) to do this is to force
a LIP. This also will wake up the disk that probably just had a f/w crash.

Implement mailbox 'continuations'- this allows interrupts to re-drive
a mailbox command if it's one that just essentially repeats the previous
mailbox command (e.g., f/w download). This saves a boatload of sleep/wakeup
twitches.

If we're not a 2300 and we're about to return with a 'bogus interrupt'- check
the semaphore register to be non-zero at all and outgoing mailbox 0- this
seems to be where some of the lost ISP1080 commands came from.
 1.37 03-Jan-2002  mjacob Implement REDUCED INTERRUPT OPERATION usage for FC cards- this allows the
firmware to delay completion of commands so that it can attempt to batch
a bunch of completions at once- either returning 16 bit handles in mailbox
registers, or in a resposne queue entry that has a whole wad of 16 bit handles.

Distinguish between 2300 and 2312 chipsets- if only because the revisions
on the chips have different meanings.

Add more instrumentation plus ISP_GET_STATS and ISP_CLR_STATS ioctls.
Run up the maximum number of response queue entities we'll look at
per interrupt.

If we haven't set HBA role yet, always return success from isp_fc_runstate.
 1.36 14-Dec-2001  mjacob Major restructuring for swizzling to the request queue and unswizzling from
the response queue. Instead of the ad hoc ISP_SWIZZLE_REQUEST, we now have
a complete set of inline functions in isp_inline.h. Each platform is
responsible for providing just one of a set of ISP_IOX_{GET,PUT}{8,16,32}
macros.

The reason this needs to be done is that we need to have a single set of
functions that will work correctly on multiple architectures for both little
and big endian machines. It also needs to work correctly in the case that
we have the request or response queues in memory that has to be treated
specially (e.g., have ddi_dma_sync called on it for Solaris after we update
it or before we read from it).

One thing that falls out of this is that we no longer build requests in the
request queue itself. Instead, we build the request locally (e.g., on the
stack) and then as part of the swizzling operation, copy it to the request
queue entry we've allocated. I thought long and hard about whether this was
too expensive a change to make as it in a lot of cases requires an extra
copy. On balance, the flexbility is worth it. With any luck, the entry that
we build locally stays in a processor writeback cache (after all, it's only
64 bytes) so that the cost of actually flushing it to the memory area that is
the shared queue with the PCI device is not all that expensive. We may examine
this again and try to get clever in the future to try and avoid copies.

Another change that falls out of this is that MEMORYBARRIER should be taken
a lot more seriously. The macro ISP_ADD_REQUEST does a MEMORYBARRIER on the
entry being added. But there had been many other places this had been missing.
It's now very important that it be done.

For NetBSD, it does a ddi_dmamap_sync as appropriate. This gets us out of
the explicit ddi_dmamap_sync on the whole response queue that we did for SBus
cards at each interrupt.

Set things up so that platforms that cannot have an SBus don't get a lot of
the SBus code checks (dead coded out).

Additional changes:

Fix a longstanding buglet of sorts. When we get an entry via isp_getrqentry,
the iptr value that gets returned is the value we intend to eventually plug
into the ISP registers as the entry *one past* the last one we've written-
*not* the current entry we're updating. All along we've been calling sync
functions on the wrong index value. Argh. The 'fix' here is to rename all
'iptr' variables as 'nxti' to remember that this is the 'next' pointer-
not the current pointer.

Devote a single bit to mboxbsy- and set aside bits for output mbox registers
that we need to pick up- we can have at least one command which does not
have any defined output registers (MBOX_EXECUTE_FIRMWARE).

Explicitly decode GetAllNext SNS Response back *as* a GetAllNext response.
Otherwise, we won't unswizzle it correctly.

Nuke some additional __P macros.
 1.35 06-Oct-2001  mjacob Fix various 2300 GB issues related to chip errata and documentation
misunderstandings. We also now can report our connection rate.
 1.34 01-Sep-2001  mjacob branches: 1.34.2;
Add support for 2 Gigabit cards (2300/2312). This necessitated a change
in how interrupts are down- the 23XX has not only a different place to check
for an interrupt, but unlike all other QLogic cards, you have to read the
status as a 32 bit word- not 16 bit words. Rather than have device specific
functions as called from the core module (in isp_intr), it makes more sense
to have the platform/bus modules do the gruntwork of splitting out the
isr, semaphore register and the first outgoing mailbox register (if needed)
*prior* to calling isp_intr (if calling isp_intr is necessary at all).
 1.33 06-Jul-2001  mjacob branches: 1.33.2;
Add some wads more definitions. Add macros for request/response queue
in/out pointer access.
 1.32 05-Apr-2001  mjacob Add a few opcodes for target mode. Define firmware attributes (for FC f/w).
 1.31 23-Feb-2001  mjacob branches: 1.31.2;
Fix a longstanding bug- we had the sense of what bit 14
for the ICB firmware options meant- *I* had taken it to
mean that if you set it, Node Name would be ignored and
derived from Port Name. Actually, it meant the opposite.
As a consequence- change ICBOPT_USE_PORTNAME to the
define ICBOPT_BOTH_WWNS- makes more sense.
 1.30 12-Feb-2001  mjacob Add structure defining FC-AL position maps. The only tool that I know of
that really uses this is luxadm(8) under Solaris.
 1.29 09-Jan-2001  mjacob Add some 2X00 specific state flags for status response entries. Add the
defines necessary for the REGISTER FC4 TYPE SNS subcommand.
 1.28 23-Dec-2000  wiz Fix pathnames in comment.
 1.27 16-Aug-2000  mjacob Change _res field in ispstatusreq_t to be req_response for FC.
Add some more FC specific response defines and split the response
defines into common, SCSI only and FC only cases.
 1.26 14-Aug-2000  mjacob Add a maintenance note
 1.25 01-Aug-2000  mjacob Core version 2.0 (platform version 1.0) rewrite of ISP driver. Some
interace cleanups, some new common functions. The major impact that
will be noticeable right away is that if you boot with not Fibre connected
to the FC cards, you no longer hang indefinitely.
 1.24 05-Jul-2000  mjacob add MBOX_GET_RESOURCE_COUNT command
 1.23 13-May-2000  he branches: 1.23.4;
Update from Matthew Jacob:

Correctly account for F-port vs. F-port (no FLOGI_ACC) topologies.
Make sure we get a port database entry for the fabric name server.
Preserve fabric logins if the device didn't change across fabric
or port database changes, or the device has already logged into
us (e.g., for target/initiator dual role devices like Veritas
SANbox). Propagate class 3 service parameter changes where devices
can change roles.

Fix all occurrences of setting a sendmarker so that setting it
for one bus on dual bus cards doesn't wipe a pending sendmarker
for other busses on the same card :-;.

Comments added and clarifications made in some of the target mode code.
 1.22 19-Feb-2000  mjacob Add in some mbox return codes that define when we've used up target
ids for doing fabric login. Define the 'Get All Next' SNS response
structure.
 1.21 12-Feb-2000  mjacob add some Qlogic 2200 point-to-point and extended ICBOPT definitions
 1.20 06-Jan-2000  mjacob add the enable target mode command, plus some minor fiddles
 1.19 14-Oct-1999  mjacob branches: 1.19.2;
Update FC icb type to have the variants for the 2200 (we don't use it
yet). Remove all target mode definitions.
 1.18 05-Jul-1999  mjacob branches: 1.18.2;
Change to approved NASA/Ames copyright. Add Fabric support. Fix SCCLUN support.
Add code that tries to track LoopID shifting.
 1.17 12-May-1999  mjacob add a few missing mbox commands
 1.16 04-Apr-1999  mjacob Remove incorrect BIG_ENDIAN defines and substitute in the SBus only macros
that will SBusify an isp header or the lun/target portions of a request IOCB-
and have these only valid iff __sparc__ (no non-sparc SBus machine that *I*
know about).
 1.15 26-Mar-1999  mjacob branches: 1.15.2; 1.15.4;
add isp1080 support and some basic PDB change stuff
 1.14 17-Mar-1999  mjacob Update the driver with some infrastructure for the 1080. Fix an embarrassing
clock botch bug. Additional infrastructure for PDB change stuff.
 1.13 09-Feb-1999  mjacob roll internal release tag
 1.12 30-Jan-1999  mjacob Implement and use Fast Posting for both parallel && fibre. Redo a bit of
the startup code. Implement a call to outer framework function so that
asynchronous events can be handled (e.g., speed negotiation, target mode).

Roll internal release tags.
 1.11 28-Dec-1998  mjacob clean up headers; move uninit/watch to outer layers
 1.10 05-Dec-1998  mjacob Update BA for new max_lun parameter for SCSIbusses. Clearify maximum luns
for FC HB based upon a SCCLUN define (15 for normal- 255 out of a possible
65535 for SCCLUN). Propagate loopid as adapter_target.

Roll minor platform version. Roll core version number.

Update mailbox definitions with cleaner target mode structure definitions.
Clean up some ENDIAN stuff. Correct botched ISP2100_NVRAM_HARDLOOPID offset.
 1.9 17-Sep-1998  mjacob add some target mode definitions
 1.8 08-Sep-1998  mjacob Move all ASYNC definitions here (after all, they're mailbox registers).

Clarify FC initialization control block. Add macros for setting WWN
into same. Add a wad more definitions in this area.
 1.7 18-Jul-1998  mjacob fix headers
 1.6 15-Jul-1998  mjacob Some major thrashing to handle building for other than NetBSD.

There is one change of note- build a list of completing commands in
ispintr and then say you're done- this avoids some re-entrancy issues
that had surfaced.
 1.5 29-Sep-1997  mjacob branches: 1.5.2;
A little cleanup and print more error messages.
 1.4 10-Sep-1997  mjacob (for the 2100) The flags weren't set in the right place, but things worked
anyway. Wierd. Also, a bit of cleanup.
 1.3 16-Aug-1997  mjacob Additional defines and structures necessary to support the Qlogic ISP 2100
Fibre Channel PCI card.
 1.2 12-Mar-1997  cgd branches: 1.2.4;
NetBSD RCS ID tweaks, a few comment block tweaks. Also, make copyright
notices consistent (per Matt Jacob).
 1.1 12-Mar-1997  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 12-Mar-1997  cgd ISP 10x0 driver from Matthew Jacob of NASA Ames Research Center.
(March 12, 1997 version).
 1.2.4.3 14-Oct-1997  thorpej Update marc-pcmcia branch from trunk.
 1.2.4.2 16-Sep-1997  thorpej Update marc-pcmcia branch from trunk.
 1.2.4.1 23-Aug-1997  thorpej Update marc-pcmcia branch from trunk.
 1.5.2.1 07-Nov-1998  cgd pull up revs 1.6-1.9 from trunk (mjacob)
 1.15.4.2 02-Aug-1999  thorpej Update from trunk.
 1.15.4.1 21-Jun-1999  thorpej Sync w/ -current.
 1.15.2.2 13-May-2000  he Apply patch (requested by Matthew Jacob via he):
Correctly account for F-port vs. F-port (no FLOGI_ACC) topologies.
Make sure we get a port database entry for the fabric name server.
Preserve fabric logins if the device didn't change across fabric
or port database changes, or the device has already logged into
us (e.g., for target/initiator dual role devices like Veritas
SANbox). Propagate class 3 service parameter changes where devices
can change roles.

Fix all occurrences of setting a sendmarker so that setting it
for one bus on dual bus cards doesn't wipe a pending sendmarker
for other busses on the same card.

Comments added and clarifications made in some of the target mode code.

Add support for > 12 byte CDBs. Split out nvram reading into
per-card functions. Add proper Ultra2/Ultra3 support. Upgrade
firmware.
 1.15.2.1 08-Jan-2000  he Pull up revisions 1.16-1.20 (requested by mjacob):
Untangle Qlogic firmware copyright problems and update firmware.
Untangle some MD support issues for said firmware. Add 1280 (Dual
LVD), 1240 (Dual Ultra), 2200 (2nd Generation Qlogic FC chipset).
Fix some synchronous negotiation problems for parallel SCSI.
Firm up some Fabric Support issues.
 1.18.2.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.19.2.5 21-Apr-2001  bouyer Sync with HEAD
 1.19.2.4 12-Mar-2001  bouyer Sync with HEAD.
 1.19.2.3 18-Jan-2001  bouyer Sync with head (for UBC+NFS fixes, mostly).
 1.19.2.2 05-Jan-2001  bouyer Sync with HEAD
 1.19.2.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.23.4.2 16-Mar-2001  he Pull up revisions 1.28-1.31 (requested by mjacob):
Add structure defining FC-AL position maps. Add some 2X00 specific
state flags for status response entries. Add the defines necessary
for the REGISTER FC4 TYPE SNS subcommand. Change ICBOPT_USE_PORTNAME
to ICBOPT_BOTH_WWNS.
 1.23.4.1 28-Aug-2000  mjacob Complete rewrite of internals for isp core version 2.0.
Pullup to netbsd-1-5 approved by thorpej@netbsd.org.
 1.31.2.12 11-Nov-2002  nathanw Catch up to -current
 1.31.2.11 27-Aug-2002  nathanw Catch up to -current.
 1.31.2.10 13-Aug-2002  nathanw Catch up to -current.
 1.31.2.9 20-Jun-2002  nathanw Catch up to -current.
 1.31.2.8 17-Apr-2002  nathanw Catch up to -current.
 1.31.2.7 28-Feb-2002  nathanw Catch up to -current.
 1.31.2.6 11-Jan-2002  nathanw More catchup.
 1.31.2.5 08-Jan-2002  nathanw Catch up to -current.
 1.31.2.4 22-Oct-2001  nathanw Catch up to -current.
 1.31.2.3 21-Sep-2001  nathanw Catch up to -current.
 1.31.2.2 24-Aug-2001  nathanw Catch up with -current.
 1.31.2.1 09-Apr-2001  nathanw Catch up with -current.
 1.33.2.5 06-Sep-2002  jdolecek sync kqueue branch with HEAD
 1.33.2.4 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.33.2.3 16-Mar-2002  jdolecek Catch up with -current.
 1.33.2.2 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.33.2.1 13-Sep-2001  thorpej Update the kqueue branch to HEAD.
 1.34.2.1 11-Oct-2001  fvdl Catch up with -current. Fix some bogons in the sparc64 kbd/ms
attach code. cd18xx conversion provided by mrg.
 1.40.2.2 29-Aug-2002  gehenna catch up with -current.
 1.40.2.1 30-May-2002  gehenna Catch up with -current.
 1.46.2.4 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.46.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.46.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.46.2.1 03-Aug-2004  skrll Sync with HEAD
 1.47.10.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.47.8.1 29-Apr-2005  kent sync with -current
 1.48.4.2 17-Mar-2008  yamt sync with head.
 1.48.4.1 03-Sep-2007  yamt sync with head.
 1.49.32.1 11-Jul-2007  mjf Sync with head.
 1.49.30.1 27-May-2007  ad Sync with head.
 1.50.28.2 02-Jun-2008  mjf Sync with HEAD.
 1.50.28.1 03-Apr-2008  mjf Sync with HEAD.
 1.50.24.1 24-Mar-2008  keiichi sync with head.
 1.50.8.1 23-Mar-2008  matt sync with HEAD
 1.51.6.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.51.4.4 11-Aug-2010  yamt sync with head.
 1.51.4.3 11-Mar-2010  yamt sync with head
 1.51.4.2 18-Jul-2009  yamt sync with head.
 1.51.4.1 16-May-2008  yamt sync with head.
 1.51.2.1 18-May-2008  yamt sync with head.
 1.52.12.1 23-Jul-2009  jym Sync with HEAD.
 1.54.4.1 30-May-2010  rmind sync with head
 1.54.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.55.22.1 18-May-2014  rmind sync with head
 1.55.18.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.55.8.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.59.2.1 02-Aug-2025  perseant Sync with HEAD
 1.35 03-May-2022  andvar fix various typos, mainly s/trasfering/transferring/ and s/theese/these/.
 1.34 26-Mar-2010  mjacob Synchronize with other platforms:

Strongly architect handles so we can more easily detect bogus
handles. This switches us to a full 32 bits for all handles.

Handle the case of FC disks disappearing and then reappearing-
at least at the FC transport level.

Some better and finer control of debug and non-debug printouts.
 1.33 25-Jun-2009  mjacob branches: 1.33.2; 1.33.4;
Update ISP driver to latest and greatest. Includes support for the 8Gb part.
 1.32 11-Mar-2008  mjacob branches: 1.32.4; 1.32.18;
Checkpoint of some fairly major isp(4) rototilling.

Reintroduce more of a 'channel' concept in preparation for NP-IV support.
This gets rid of the chanA/chanB concept as the 2400 can have up to 128
virtual channels. Actually, with MID firmware you can also have the 2200
and 2300 support 'channels, but they do it with an FL-Port topology.
Because FC cards can now have 'channels', just about every support
function for fibre channel had to be redone to have a channel index
as well. Rototill isp_ioctl.h for channel stuff as well.

Pick up a lot of work about fabric management (hopefully better) and keep
work in place that will allow for dynamic attachment/detachment of devices
(if I can figure out how to make the midlayer support it).

Merge the target code with external trees. Eventually it might even
be sorted out on NetBSD.

Update some firmware stuff.
 1.31 24-May-2007  mjacob branches: 1.31.8; 1.31.24; 1.31.28;
Major update to isp(4) driver to bring it in line with external sources.

The major changes are:

+ 4Gb (24XX) card support
+ Rewritten fabric and loop evaluation code
+ New f/w sets

The 4Gb changes required major rototilling, which caused a rewrite of
fabric and loop eval code. The latter can now be set up to tune for
dynamic device arrival/departure if the framework is set up for it,
or to be firm about waiting for devices.

Testing has been principally on amd64, i386 and sparc64 and seems to
not have broken things for me.
 1.30 11-Dec-2005  christos branches: 1.30.30; 1.30.32;
merge ktrace-lwp.
 1.29 04-Dec-2003  keihan branches: 1.29.16;
netbsd.org -> NetBSD.org

This was the last commit of this kind to src/sys, which is now totally
"NetBSD.org clean". Thanks for the patiance, and sorry for all the commits.
 1.28 02-Nov-2003  wiz Fix some typos. From Tom Cosgrove via jmc@openbsd.
 1.27 21-Feb-2002  mjacob branches: 1.27.16;
Implement F/W crashdumps for 2200 && 2300 cards (kernel compile option).

Distinguish between 2312 and 2300 cards (they *are* different). Enable
RIO (Reduced Interrupt Operation) for the LVD cards (hey- I've seen
batched completions of the 30 commands at a time with this,....)...

If we get a Port Logout on local loop topologies, we have to force the
f/w to log back in. The easiest way (for us) to do this is to force
a LIP. This also will wake up the disk that probably just had a f/w crash.

Implement mailbox 'continuations'- this allows interrupts to re-drive
a mailbox command if it's one that just essentially repeats the previous
mailbox command (e.g., f/w download). This saves a boatload of sleep/wakeup
twitches.

If we're not a 2300 and we're about to return with a 'bogus interrupt'- check
the semaphore register to be non-zero at all and outgoing mailbox 0- this
seems to be where some of the lost ISP1080 commands came from.
 1.26 01-Sep-2001  mjacob Add support for 2 Gigabit cards (2300/2312). This necessitated a change
in how interrupts are down- the 23XX has not only a different place to check
for an interrupt, but unlike all other QLogic cards, you have to read the
status as a 32 bit word- not 16 bit words. Rather than have device specific
functions as called from the core module (in isp_intr), it makes more sense
to have the platform/bus modules do the gruntwork of splitting out the
isr, semaphore register and the first outgoing mailbox register (if needed)
*prior* to calling isp_intr (if calling isp_intr is necessary at all).
 1.25 12-Feb-2001  mjacob branches: 1.25.2; 1.25.4;
Put in offset definitions for FPM and FBM registers, plus just enough
bits defined so we can reset them.
 1.24 23-Dec-2000  wiz Fix pathnames in comment.
 1.23 14-Aug-2000  mjacob Add a maintenance note
 1.22 01-Aug-2000  mjacob Core version 2.0 (platform version 1.0) rewrite of ISP driver. Some
interace cleanups, some new common functions. The major impact that
will be noticeable right away is that if you boot with not Fibre connected
to the FC cards, you no longer hang indefinitely.
 1.21 05-Jul-2000  mjacob Fix incorrect uint8_t vs. u_int8_t usage. Add in offset macros for outgoing
mailbox regs and a INT_PENDING_MASK macro.
 1.20 13-May-2000  he branches: 1.20.4;
Update from Matthew Jacob:

Correctly account for F-port vs. F-port (no FLOGI_ACC) topologies.
Make sure we get a port database entry for the fabric name server.
Preserve fabric logins if the device didn't change across fabric
or port database changes, or the device has already logged into
us (e.g., for target/initiator dual role devices like Veritas
SANbox). Propagate class 3 service parameter changes where devices
can change roles.

Fix all occurrences of setting a sendmarker so that setting it
for one bus on dual bus cards doesn't wipe a pending sendmarker
for other busses on the same card :-;.

Comments added and clarifications made in some of the target mode code.
 1.19 12-Feb-2000  mjacob add in 12160 (Ultra3) NVRAM definitions
 1.18 16-Dec-1999  mjacob Dual LVD (1280) support.
 1.17 17-Oct-1999  mjacob branches: 1.17.2;
add INT_PENDING macro
 1.16 05-Jul-1999  mjacob branches: 1.16.2;
Change to approved NASA/Ames copyright. Add Fabric support. Fix SCCLUN support.
Add code that tries to track LoopID shifting.
 1.15 12-May-1999  mjacob Do a fairly large internal restructuring to accomodate dual-bus host adapters
(e.g., the 1240). Include the new 1080/1240 NVRAM layout reading code. Some
moderately significant mailbox changes were necessary also to accomodate a
second channel.
 1.14 26-Mar-1999  mjacob branches: 1.14.2; 1.14.4;
add isp1080 support and some basic PDB change stuff
 1.13 17-Mar-1999  mjacob Update the driver with some infrastructure for the 1080. Fix an embarrassing
clock botch bug. Additional infrastructure for PDB change stuff.
 1.12 09-Feb-1999  mjacob fix a couple of NVRAM defines
 1.11 30-Jan-1999  mjacob Implement and use Fast Posting for both parallel && fibre. Redo a bit of
the startup code. Implement a call to outer framework function so that
asynchronous events can be handled (e.g., speed negotiation, target mode).

Roll internal release tags.
 1.10 28-Dec-1998  mjacob clean up headers; move uninit/watch to outer layers
 1.9 05-Dec-1998  mjacob Update BA for new max_lun parameter for SCSIbusses. Clearify maximum luns
for FC HB based upon a SCCLUN define (15 for normal- 255 out of a possible
65535 for SCCLUN). Propagate loopid as adapter_target.

Roll minor platform version. Roll core version number.

Update mailbox definitions with cleaner target mode structure definitions.
Clean up some ENDIAN stuff. Correct botched ISP2100_NVRAM_HARDLOOPID offset.
 1.8 17-Sep-1998  mjacob cleanup header to be just NetBSD
 1.7 08-Sep-1998  mjacob Add more ASYNC event codes here. Add NVRAM definitions.
 1.6 18-Jul-1998  mjacob fix headers
 1.5 15-Jul-1998  mjacob Some major thrashing to handle building for other than NetBSD.

There is one change of note- build a list of completing commands in
ispintr and then say you're done- this avoids some re-entrancy issues
that had surfaced.
 1.4 05-Dec-1997  mjacob new async code defined
 1.3 16-Aug-1997  mjacob branches: 1.3.4;
Differences necessary to support the Qlogic 2100 (Fibre Channel PCI
Card)
 1.2 12-Mar-1997  cgd branches: 1.2.4;
NetBSD RCS ID tweaks, a few comment block tweaks. Also, make copyright
notices consistent (per Matt Jacob).
 1.1 12-Mar-1997  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 12-Mar-1997  cgd ISP 10x0 driver from Matthew Jacob of NASA Ames Research Center.
(March 12, 1997 version).
 1.2.4.1 23-Aug-1997  thorpej Update marc-pcmcia branch from trunk.
 1.3.4.1 07-Nov-1998  cgd pull up revs 1.4-1.8 from trunk (mjacob)
 1.14.4.2 02-Aug-1999  thorpej Update from trunk.
 1.14.4.1 21-Jun-1999  thorpej Sync w/ -current.
 1.14.2.2 13-May-2000  he Apply patch (requested by Matthew Jacob via he):
Correctly account for F-port vs. F-port (no FLOGI_ACC) topologies.
Make sure we get a port database entry for the fabric name server.
Preserve fabric logins if the device didn't change across fabric
or port database changes, or the device has already logged into
us (e.g., for target/initiator dual role devices like Veritas
SANbox). Propagate class 3 service parameter changes where devices
can change roles.

Fix all occurrences of setting a sendmarker so that setting it
for one bus on dual bus cards doesn't wipe a pending sendmarker
for other busses on the same card.

Comments added and clarifications made in some of the target mode code.

Add support for > 12 byte CDBs. Split out nvram reading into
per-card functions. Add proper Ultra2/Ultra3 support. Upgrade
firmware.
 1.14.2.1 08-Jan-2000  he Pull up revisions 1.15-1.18 (requested by mjacob):
Untangle Qlogic firmware copyright problems and update firmware.
Untangle some MD support issues for said firmware. Add 1280 (Dual
LVD), 1240 (Dual Ultra), 2200 (2nd Generation Qlogic FC chipset).
Fix some synchronous negotiation problems for parallel SCSI.
Firm up some Fabric Support issues.
 1.16.2.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.17.2.3 12-Mar-2001  bouyer Sync with HEAD.
 1.17.2.2 05-Jan-2001  bouyer Sync with HEAD
 1.17.2.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.20.4.2 16-Mar-2001  he Pull up revisions 1.24-1.25 (requested by mjacob):
Put in offset definitions for FPM and FBM registers, plus just
enough bits defined so we can reset them. Add maintenance note.
 1.20.4.1 28-Aug-2000  mjacob Complete rewrite of internals for isp core version 2.0.
Pullup to netbsd-1-5 approved by thorpej@netbsd.org.
 1.25.4.2 16-Mar-2002  jdolecek Catch up with -current.
 1.25.4.1 13-Sep-2001  thorpej Update the kqueue branch to HEAD.
 1.25.2.2 28-Feb-2002  nathanw Catch up to -current.
 1.25.2.1 21-Sep-2001  nathanw Catch up to -current.
 1.27.16.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.27.16.2 18-Sep-2004  skrll Sync with HEAD.
 1.27.16.1 03-Aug-2004  skrll Sync with HEAD
 1.29.16.2 17-Mar-2008  yamt sync with head.
 1.29.16.1 03-Sep-2007  yamt sync with head.
 1.30.32.1 11-Jul-2007  mjf Sync with head.
 1.30.30.1 27-May-2007  ad Sync with head.
 1.31.28.1 03-Apr-2008  mjf Sync with HEAD.
 1.31.24.1 24-Mar-2008  keiichi sync with head.
 1.31.8.1 23-Mar-2008  matt sync with HEAD
 1.32.18.1 23-Jul-2009  jym Sync with HEAD.
 1.32.4.2 11-Aug-2010  yamt sync with head.
 1.32.4.1 18-Jul-2009  yamt sync with head.
 1.33.4.1 30-May-2010  rmind sync with head
 1.33.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.76 21-Sep-2023  msaitoh s/ for for / for / in comment.
 1.75 12-Apr-2022  andvar s/similarily/similarly/
 1.74 11-Sep-2021  andvar Add missing double p and d for stopped and overriden accordingly.
Fix few more typos along the way, mainly in copy-pasted comments.
 1.73 18-Oct-2014  snj src is too big these days to tolerate superfluous apostrophes. It's
"its", people!
 1.72 28-Feb-2011  mjacob branches: 1.72.14;
Update isp driver to be in sync with other platforms. Mostly very minor changes
with effectively zero impact on NetBSD.
 1.71 26-Mar-2010  mjacob branches: 1.71.2; 1.71.4;
Synchronize with other platforms:

Strongly architect handles so we can more easily detect bogus
handles. This switches us to a full 32 bits for all handles.

Handle the case of FC disks disappearing and then reappearing-
at least at the FC transport level.

Some better and finer control of debug and non-debug printouts.
 1.70 25-Jun-2009  mjacob branches: 1.70.2; 1.70.4;
Update ISP driver to latest and greatest. Includes support for the 8Gb part.
 1.69 11-May-2008  mjacob branches: 1.69.12;
Make fc scratch acquisition something that can fail. Remove in_intr flag.
Otherwise synchronize with changes made due to other platforms.
 1.68 11-Mar-2008  mjacob branches: 1.68.2; 1.68.4; 1.68.6;
Checkpoint of some fairly major isp(4) rototilling.

Reintroduce more of a 'channel' concept in preparation for NP-IV support.
This gets rid of the chanA/chanB concept as the 2400 can have up to 128
virtual channels. Actually, with MID firmware you can also have the 2200
and 2300 support 'channels, but they do it with an FL-Port topology.
Because FC cards can now have 'channels', just about every support
function for fibre channel had to be redone to have a channel index
as well. Rototill isp_ioctl.h for channel stuff as well.

Pick up a lot of work about fabric management (hopefully better) and keep
work in place that will allow for dynamic attachment/detachment of devices
(if I can figure out how to make the midlayer support it).

Merge the target code with external trees. Eventually it might even
be sorted out on NetBSD.

Update some firmware stuff.
 1.67 07-Jul-2007  mjacob branches: 1.67.8; 1.67.24; 1.67.28;
Do a number of 24XX related fixes: fix the actual getting of initiator
status correctly (which we never were doing before). Add an underrun
checker for 24XX. The process of sorting this out led to a whole bunch
of endian surprises that had to be dealt with. Fix NVRAM endian issues
for the 24XX as well.

Do a little 2200 related cleanup- in particular, turn off complaints about
not finding a fast posting handle when running with RIO enabled- we are
somehow getting duplicate completions in this case. If we ignore them and
don't complain, all is well, and we actually start averaging > 2 commands
completed per interrupt.
 1.66 24-May-2007  mjacob Major update to isp(4) driver to bring it in line with external sources.

The major changes are:

+ 4Gb (24XX) card support
+ Rewritten fabric and loop evaluation code
+ New f/w sets

The 4Gb changes required major rototilling, which caused a rewrite of
fabric and loop eval code. The latter can now be set up to tune for
dynamic device arrival/departure if the framework is set up for it,
or to be firm about waiting for devices.

Testing has been principally on amd64, i386 and sparc64 and seems to
not have broken things for me.
 1.65 04-Mar-2007  christos branches: 1.65.2; 1.65.4;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.64 11-Dec-2005  christos branches: 1.64.26;
merge ktrace-lwp.
 1.63 30-May-2005  christos branches: 1.63.2;
- add missing const
- fix variable shadowing
- remove unneeded casts
 1.62 27-Feb-2005  perry nuke trailing whitespace
 1.61 04-Dec-2003  keihan branches: 1.61.8; 1.61.10;
netbsd.org -> NetBSD.org

This was the last commit of this kind to src/sys, which is now totally
"NetBSD.org clean". Thanks for the patiance, and sorry for all the commits.
 1.60 03-May-2003  wiz branches: 1.60.2;
DMA, not dma nor Dma.
 1.59 18-Oct-2002  mjacob Remove ISP_DMA_ADDR_T as a 'type'. Instead, go off of whether
ISP_DAC_SUPPORTED is defined and do a real typedef for the size
of DMA addresses. ISP_DAC_SUPPORTED also decides how much of any
particular DMA address is significant.

Lose STRNCAT over the side.

Add in (sight unseen) 10160 support.
 1.58 16-Aug-2002  mjacob Further fix problems with 23XX ISR handling and correctly initialize the
23XX to use ZIO in preference to fast posting.
 1.57 12-Aug-2002  mjacob Various changes to allow for overriding just loopid and/or iid.
Fix a random 23XX ISR reading bug. Be chattier about HBA_BOTCH
errors. More f/w cashdump layering.
 1.56 15-Jun-2002  mjacob Roll version minor.

Add DEFAULT_FRAMESIZE/DEFAULT_EXEC_THROTTLE/ISPASYNC_FW_RESTARTED
defines.
 1.55 04-Apr-2002  mjacob branches: 1.55.2;
Redo fabric evaluation to not use GET ALL NEXT (GA_NXT). Switches seem
to be trying to wriggle out of supporting this well. Instead, use
GID_FT to get a list of Port IDs and then use GPN_ID/GNN_ID to find the
port and node wwn. This should make working on fabrics a bit cleaner and
more stable.

This also caused some cleanup of SNS subcommand canonicalization so that
we can actually check for FS_ACC and FS_RJT, and if we get an FS_RJT,
print out the reason and explanation codes.

We'll keep the old GA_NXT method around if people want to uncomment a
controlling definition in ispvar.h.

This also had us clean up ISPASYNC_FABRICDEV to use a local lportdb argument
and to have the caller explicitly say that a device is at the end of the
fabric list.
 1.54 22-Mar-2002  mjacob Handle Port Unavailable the same as Port Logout (i.e., send a LIP).

Unconst pointer to f/w in the ispdv structure. Too many compilers get
unhappy over our walking the array. Make casts as appropriate so that
initialization in structure is still happy.

Limit length of fabric to 256. This will all go away soon.

Do a cleaner case of keeping multiple CPUs/threads from reading the
same response queue entries.
 1.53 21-Feb-2002  mjacob Implement F/W crashdumps for 2200 && 2300 cards (kernel compile option).

Distinguish between 2312 and 2300 cards (they *are* different). Enable
RIO (Reduced Interrupt Operation) for the LVD cards (hey- I've seen
batched completions of the 30 commands at a time with this,....)...

If we get a Port Logout on local loop topologies, we have to force the
f/w to log back in. The easiest way (for us) to do this is to force
a LIP. This also will wake up the disk that probably just had a f/w crash.

Implement mailbox 'continuations'- this allows interrupts to re-drive
a mailbox command if it's one that just essentially repeats the previous
mailbox command (e.g., f/w download). This saves a boatload of sleep/wakeup
twitches.

If we're not a 2300 and we're about to return with a 'bogus interrupt'- check
the semaphore register to be non-zero at all and outgoing mailbox 0- this
seems to be where some of the lost ISP1080 commands came from.
 1.52 03-Jan-2002  mjacob Implement REDUCED INTERRUPT OPERATION usage for FC cards- this allows the
firmware to delay completion of commands so that it can attempt to batch
a bunch of completions at once- either returning 16 bit handles in mailbox
registers, or in a resposne queue entry that has a whole wad of 16 bit handles.

Distinguish between 2300 and 2312 chipsets- if only because the revisions
on the chips have different meanings.

Add more instrumentation plus ISP_GET_STATS and ISP_CLR_STATS ioctls.
Run up the maximum number of response queue entities we'll look at
per interrupt.

If we haven't set HBA role yet, always return success from isp_fc_runstate.
 1.51 14-Dec-2001  mjacob Major restructuring for swizzling to the request queue and unswizzling from
the response queue. Instead of the ad hoc ISP_SWIZZLE_REQUEST, we now have
a complete set of inline functions in isp_inline.h. Each platform is
responsible for providing just one of a set of ISP_IOX_{GET,PUT}{8,16,32}
macros.

The reason this needs to be done is that we need to have a single set of
functions that will work correctly on multiple architectures for both little
and big endian machines. It also needs to work correctly in the case that
we have the request or response queues in memory that has to be treated
specially (e.g., have ddi_dma_sync called on it for Solaris after we update
it or before we read from it).

One thing that falls out of this is that we no longer build requests in the
request queue itself. Instead, we build the request locally (e.g., on the
stack) and then as part of the swizzling operation, copy it to the request
queue entry we've allocated. I thought long and hard about whether this was
too expensive a change to make as it in a lot of cases requires an extra
copy. On balance, the flexbility is worth it. With any luck, the entry that
we build locally stays in a processor writeback cache (after all, it's only
64 bytes) so that the cost of actually flushing it to the memory area that is
the shared queue with the PCI device is not all that expensive. We may examine
this again and try to get clever in the future to try and avoid copies.

Another change that falls out of this is that MEMORYBARRIER should be taken
a lot more seriously. The macro ISP_ADD_REQUEST does a MEMORYBARRIER on the
entry being added. But there had been many other places this had been missing.
It's now very important that it be done.

For NetBSD, it does a ddi_dmamap_sync as appropriate. This gets us out of
the explicit ddi_dmamap_sync on the whole response queue that we did for SBus
cards at each interrupt.

Set things up so that platforms that cannot have an SBus don't get a lot of
the SBus code checks (dead coded out).

Additional changes:

Fix a longstanding buglet of sorts. When we get an entry via isp_getrqentry,
the iptr value that gets returned is the value we intend to eventually plug
into the ISP registers as the entry *one past* the last one we've written-
*not* the current entry we're updating. All along we've been calling sync
functions on the wrong index value. Argh. The 'fix' here is to rename all
'iptr' variables as 'nxti' to remember that this is the 'next' pointer-
not the current pointer.

Devote a single bit to mboxbsy- and set aside bits for output mbox registers
that we need to pick up- we can have at least one command which does not
have any defined output registers (MBOX_EXECUTE_FIRMWARE).

Explicitly decode GetAllNext SNS Response back *as* a GetAllNext response.
Otherwise, we won't unswizzle it correctly.

Nuke some additional __P macros.
 1.50 06-Oct-2001  mjacob Fix various 2300 GB issues related to chip errata and documentation
misunderstandings. We also now can report our connection rate.
 1.49 05-Sep-2001  mjacob branches: 1.49.2;
Synchronize with FreeBSD/Linux.
 1.48 01-Sep-2001  mjacob Add support for 2 Gigabit cards (2300/2312). This necessitated a change
in how interrupts are down- the 23XX has not only a different place to check
for an interrupt, but unlike all other QLogic cards, you have to read the
status as a 32 bit word- not 16 bit words. Rather than have device specific
functions as called from the core module (in isp_intr), it makes more sense
to have the platform/bus modules do the gruntwork of splitting out the
isr, semaphore register and the first outgoing mailbox register (if needed)
*prior* to calling isp_intr (if calling isp_intr is necessary at all).
 1.47 22-Jul-2001  wiz seperate -> separate
 1.46 06-Jul-2001  mjacob branches: 1.46.2;
White space cleanup. Fix oopslet about having overlapping loop states.
Handle FW crashes as an isp_async call. Reclaim a missing logging level
bit.
 1.45 22-May-2001  mjacob Add back in (again) ISPASYNC_LIP and ISPASYNC_LOOP_RESET async
notifications. Let each platform set policy as to what to do
with these.
 1.44 16-May-2001  mjacob beginning basic 2300 infrstructure support
 1.43 14-Mar-2001  mjacob Roll core minor. ANSify.
 1.42 20-Feb-2001  mjacob branches: 1.42.2;
Add ISPCTL_RUN_MBOXCMD control op and ISPASYNC_UNHANDLED_RESPONSE async event.
 1.41 12-Feb-2001  mjacob Eliminate ISP2100_FABRIC- we always allow for fabric now. Add an
isp_iid_set/isp_iid for fibre channel- this is because we now
fake a port database entry for ourselves. Add the additional loop
states between LOOP_PDB_RCVD and LOOP_READY.

Change and comment on a wad of Fibre Channel isp_control functions.
Change and comment on some of the ISPASYNC Fibre Channel events.

Add was_fabric_dev/fabric_dev tags to our local FC database structure
(so we can see rapidly whether something was a fabric device but is
now gone).

Add a tag which says what role this adapter should take. It can take
on the value of None, Target, Initiator or Both. None is useful for
warm failover purposes. Remove the ISP_CFG_NOINIT silliness since
a role of "None" does this.

Add a isp_lastmbxcmd tag to store the opcode for the last mailbox
command used.
 1.40 09-Jan-2001  mjacob ISPASYNC_PDB_CHANGED -> ISPASYNC_LOGGED_INOUT.
 1.39 28-Dec-2000  mjacob Apply nearly all of Bill Sommerfeld's -Wformat patches. The one
change I didn't take is the %llu format- I can't have a common
across multiple platform module assume a %ll argument capability-
which really pointed out that I shouldn't be trying to *print*
something which could long long.
 1.38 28-Dec-2000  mjacob add an ISP_CFG_NOINIT flag
 1.37 23-Dec-2000  wiz Fix pathnames in comment.
 1.36 09-Dec-2000  mjacob Finally fix this driver to be sensible about the ENDIAN dance. It's not
quite simply a question of the Qlogic being little endian and having
to have stuff swapped on big endian machines- it also has to do with the
fact that the SBus and PCI DMA layouts are wierd with respect to this.

At any rate, now finally fixed- works on Mac G4, tested it on a SS10
for sparc, checked on alpha to see if I've broken anything, and as
soon as I get another spare afternoon I'll finally install a sparc64
version which should just work (as it'll be like the Mac).
 1.35 16-Oct-2000  mjacob Change some of the WWN macros- eliminate PORT_FROM_NODE_WWN and make
sure we have a DEFAULT_{PORT,NODE}WWN and ISP_{NODE,PORT}WWN macro
as a requirement for all platforms.
 1.34 14-Aug-2000  mjacob Add a maintenance note. Fix QFREE and QAVAIL macros to match change in usage.
 1.33 08-Aug-2000  mjacob Remove ispcmd_slow routine- SCBUSACCEL routine will set/clear tag/wide/sync.
Make some changes about where some things sit in the softc.
 1.32 01-Aug-2000  mjacob Core version 2.0 (platform version 1.0) rewrite of ISP driver. Some
interace cleanups, some new common functions. The major impact that
will be noticeable right away is that if you boot with not Fibre connected
to the FC cards, you no longer hang indefinitely.
 1.31 05-Jul-2000  mjacob Roll core version. Get rid of dogactive (no longer used). Add in some
volatile flags (isp_mboxbsy- keeps a bitmask of expected output mailbox
registers) and storage for them (isp_mboxtmp). Get rid of macroized
LUN widths. This is determined at run time.
 1.30 13-May-2000  he branches: 1.30.4;
Update from Matthew Jacob:

Correctly account for F-port vs. F-port (no FLOGI_ACC) topologies.
Make sure we get a port database entry for the fabric name server.
Preserve fabric logins if the device didn't change across fabric
or port database changes, or the device has already logged into
us (e.g., for target/initiator dual role devices like Veritas
SANbox). Propagate class 3 service parameter changes where devices
can change roles.

Fix all occurrences of setting a sendmarker so that setting it
for one bus on dual bus cards doesn't wipe a pending sendmarker
for other busses on the same card :-;.

Comments added and clarifications made in some of the target mode code.
 1.29 12-Feb-2000  mjacob add in 12160 (Ultra3) related definitions
 1.28 06-Jan-2000  mjacob roll revision level and add some taret mode changes
 1.27 16-Dec-1999  mjacob Dual LVD (1280) support.
 1.26 04-Dec-1999  mjacob Roll core version minor. Clean out some target mode stuff. Respecify some
queue related functions to take u_int16_t's. Restructure the softc a bit.
 1.25 17-Oct-1999  mjacob branches: 1.25.2;
mostly stylistic
 1.24 14-Oct-1999  mjacob Roll minor version. Change how f/w revisions are stored. Add some
defines to get max luns for a card. Make sure the RESULT_QUEUE_LEN is not less
than 64- I've seen breakage with that. Move the temp port database stuff
into the softc (ick). Remove most of the target mode stuff. Make xflist
storage an external outer layer thing (since it will now be allocated based
upon the maximum commands that this HBA can support rather than request
queue size).
 1.23 05-Jul-1999  mjacob branches: 1.23.2;
Change to approved NASA/Ames copyright. Add Fabric support. Fix SCCLUN support.
Add code that tries to track LoopID shifting.
 1.22 12-May-1999  mjacob Do a fairly large internal restructuring to accomodate dual-bus host adapters
(e.g., the 1240). Include the new 1080/1240 NVRAM layout reading code. Some
moderately significant mailbox changes were necessary also to accomodate a
second channel.
 1.21 04-Apr-1999  mjacob Change f/w revision to major,minor,micro version. Add in ISP1040C definition.
 1.20 26-Mar-1999  mjacob branches: 1.20.2; 1.20.4;
add isp1080 support and some basic PDB change stuff
 1.19 17-Mar-1999  mjacob Update the driver with some infrastructure for the 1080. Fix an embarrassing
clock botch bug. Additional infrastructure for PDB change stuff.
 1.18 09-Feb-1999  mjacob Roll internal release tag. Roll core version minor. Fix broken DPARM_DEFAULT
define. Add a new config flag param (ISP_CFG_NONVRAM) whose intent it is
to cause NVRAM to be ignored. Add ISPASYNC_LOOP_DOWN and ISPASYNC_LOOP_UP
isp_async enums.
 1.17 30-Jan-1999  mjacob Implement and use Fast Posting for both parallel && fibre. Redo a bit of
the startup code. Implement a call to outer framework function so that
asynchronous events can be handled (e.g., speed negotiation, target mode).

Roll internal release tags.
 1.16 10-Jan-1999  mjacob bump isp_fifo_threshold tag top 3 bits
 1.15 28-Dec-1998  mjacob clean up headers; move uninit/watch to outer layers
 1.14 05-Dec-1998  mjacob Update BA for new max_lun parameter for SCSIbusses. Clearify maximum luns
for FC HB based upon a SCCLUN define (15 for normal- 255 out of a possible
65535 for SCCLUN). Propagate loopid as adapter_target.

Roll minor platform version. Roll core version number.

Update mailbox definitions with cleaner target mode structure definitions.
Clean up some ENDIAN stuff. Correct botched ISP2100_NVRAM_HARDLOOPID offset.
 1.13 17-Sep-1998  mjacob cleanup header to be just NetBSD, roll rev, change QDEPTH to QAVAIL macro
 1.12 10-Sep-1998  mjacob turn into a debug message an ABOUT F/W failure. Add ISPCTL_UPDATE_PARAMS isp_control case
 1.11 08-Sep-1998  mjacob Roll major revision. Change some definitions around. Add more current device
state stuff. Make DPARM flags full 16 bits (no shifting needed) and add
the 2 new ones for the 7.55 f/w.
 1.10 18-Jul-1998  mjacob roll core version number and add a global visible isp_restart function
 1.9 15-Jul-1998  mjacob Some major thrashing to handle building for other than NetBSD.

There is one change of note- build a list of completing commands in
ispintr and then say you're done- this avoids some re-entrancy issues
that had surfaced.
 1.8 05-May-1998  mjacob there is an (unimportant) difference between 1020 && 1020A
 1.7 27-Aug-1997  bouyer branches: 1.7.4;
Merge scsipi branch in the mainline. This add support for ATAPI devices
(currently only CD-ROM drives on i386). The sys/dev/scsipi system provides 2
busses to which devices can attach (scsibus and atapibus). This needed to
change some include files and structure names in the low level scsi drivers.
 1.6 16-Aug-1997  mjacob Defines and structures necessary to support the Qlogic 2100 (Fibre Channel
PCI card); Some additional defines to try and manage various flavors of
the SCSI host adapters (parameters for various SYNC modes).
 1.5 08-Jun-1997  thorpej branches: 1.5.2; 1.5.4;
- Simplify mailbox DMA setup, allowing the front-ends to allocate the
mailbox storage in a way they see fit.
- Define macros to index and size the request and result queue entries.
 1.4 05-Apr-1997  mjacob Need a bus/platform specific clock speed variable.
 1.3 13-Mar-1997  mycroft Make the microcode table const.
 1.2 12-Mar-1997  cgd NetBSD RCS ID tweaks, a few comment block tweaks. Also, make copyright
notices consistent (per Matt Jacob).
 1.1 12-Mar-1997  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 12-Mar-1997  cgd ISP 10x0 driver from Matthew Jacob of NASA Ames Research Center.
(March 12, 1997 version).
 1.5.4.2 27-Aug-1997  thorpej Update marc-pcmcia branch from trunk.
 1.5.4.1 23-Aug-1997  thorpej Update marc-pcmcia branch from trunk.
 1.5.2.2 26-Aug-1997  bouyer Update from trunk.
 1.5.2.1 01-Jul-1997  bouyer Updates for new scsipi subsystem. Actally known to work on i386 and sparc.
 1.7.4.1 07-Nov-1998  cgd pull up revs 1.8-1.13 from trunk (mjacob)
 1.20.4.2 02-Aug-1999  thorpej Update from trunk.
 1.20.4.1 21-Jun-1999  thorpej Sync w/ -current.
 1.20.2.2 13-May-2000  he Apply patch (requested by Matthew Jacob via he):
Correctly account for F-port vs. F-port (no FLOGI_ACC) topologies.
Make sure we get a port database entry for the fabric name server.
Preserve fabric logins if the device didn't change across fabric
or port database changes, or the device has already logged into
us (e.g., for target/initiator dual role devices like Veritas
SANbox). Propagate class 3 service parameter changes where devices
can change roles.

Fix all occurrences of setting a sendmarker so that setting it
for one bus on dual bus cards doesn't wipe a pending sendmarker
for other busses on the same card.

Comments added and clarifications made in some of the target mode code.

Add support for > 12 byte CDBs. Split out nvram reading into
per-card functions. Add proper Ultra2/Ultra3 support. Upgrade
firmware.
 1.20.2.1 08-Jan-2000  he Pull up revisions 1.21-1.28 (requested by mjacob):
Untangle Qlogic firmware copyright problems and update firmware.
Untangle some MD support issues for said firmware. Add 1280 (Dual
LVD), 1240 (Dual Ultra), 2200 (2nd Generation Qlogic FC chipset).
Fix some synchronous negotiation problems for parallel SCSI.
Firm up some Fabric Support issues.
 1.23.2.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.25.2.6 27-Mar-2001  bouyer Sync with HEAD.
 1.25.2.5 12-Mar-2001  bouyer Sync with HEAD.
 1.25.2.4 18-Jan-2001  bouyer Sync with head (for UBC+NFS fixes, mostly).
 1.25.2.3 05-Jan-2001  bouyer Sync with HEAD
 1.25.2.2 13-Dec-2000  bouyer Sync with HEAD (for UBC fixes).
 1.25.2.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.30.4.3 16-Mar-2001  he Pull up revisions 1.39-1.43 (requested by mjacob):
Add ISPCTL_RUN_MBOXCMD control op and ISPASYNC_UNHANDLED_RESPONSE
async event. Eliminate ISP2100_FABRIC. ISPASYNC_PDB_CHANGED ->
ISPASYNC_LOGGED_INOUT. Add -Wformat patches. Roll core minor.
ANSIfy.
 1.30.4.2 25-Jan-2001  jhawk Pull up revisions 1.36-1.38 (requested by mjacob):
Add in correct SBus bursting; upgrade to 2.01.26 firmware; pull to latest
initiator mode level; make changes to WWN default handling; quiet
chatty boot messages; fix endian code so MacPPC works; fix bug in
lock recursion counter; fix bug which excluded all but NL-ports from
being logged into on a fabric.
 1.30.4.1 28-Aug-2000  mjacob Complete rewrite of internals for isp core version 2.0.
Pullup to netbsd-1-5 approved by thorpej@netbsd.org.
 1.42.2.14 11-Nov-2002  nathanw Catch up to -current
 1.42.2.13 27-Aug-2002  nathanw Catch up to -current.
 1.42.2.12 13-Aug-2002  nathanw Catch up to -current.
 1.42.2.11 20-Jun-2002  nathanw Catch up to -current.
 1.42.2.10 17-Apr-2002  nathanw Catch up to -current.
 1.42.2.9 01-Apr-2002  nathanw Catch up to -current.
(CVS: It's not just a program. It's an adventure!)
 1.42.2.8 28-Feb-2002  nathanw Catch up to -current.
 1.42.2.7 11-Jan-2002  nathanw More catchup.
 1.42.2.6 08-Jan-2002  nathanw Catch up to -current.
 1.42.2.5 22-Oct-2001  nathanw Catch up to -current.
 1.42.2.4 21-Sep-2001  nathanw Catch up to -current.
 1.42.2.3 24-Aug-2001  nathanw Catch up with -current.
 1.42.2.2 21-Jun-2001  nathanw Catch up to -current.
 1.42.2.1 09-Apr-2001  nathanw Catch up with -current.
 1.46.2.6 06-Sep-2002  jdolecek sync kqueue branch with HEAD
 1.46.2.5 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.46.2.4 16-Mar-2002  jdolecek Catch up with -current.
 1.46.2.3 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.46.2.2 13-Sep-2001  thorpej Update the kqueue branch to HEAD.
 1.46.2.1 03-Aug-2001  lukem update to -current
 1.49.2.1 11-Oct-2001  fvdl Catch up with -current. Fix some bogons in the sparc64 kbd/ms
attach code. cd18xx conversion provided by mrg.
 1.55.2.2 29-Aug-2002  gehenna catch up with -current.
 1.55.2.1 20-Jun-2002  gehenna catch up with -current.
 1.60.2.5 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.60.2.4 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.60.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.60.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.60.2.1 03-Aug-2004  skrll Sync with HEAD
 1.61.10.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.61.8.1 29-Apr-2005  kent sync with -current
 1.63.2.2 17-Mar-2008  yamt sync with head.
 1.63.2.1 03-Sep-2007  yamt sync with head.
 1.64.26.1 12-Mar-2007  rmind Sync with HEAD.
 1.65.4.1 11-Jul-2007  mjf Sync with head.
 1.65.2.2 15-Jul-2007  ad Sync with head.
 1.65.2.1 27-May-2007  ad Sync with head.
 1.67.28.2 02-Jun-2008  mjf Sync with HEAD.
 1.67.28.1 03-Apr-2008  mjf Sync with HEAD.
 1.67.24.1 24-Mar-2008  keiichi sync with head.
 1.67.8.1 23-Mar-2008  matt sync with HEAD
 1.68.6.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.68.4.3 11-Aug-2010  yamt sync with head.
 1.68.4.2 18-Jul-2009  yamt sync with head.
 1.68.4.1 16-May-2008  yamt sync with head.
 1.68.2.1 18-May-2008  yamt sync with head.
 1.69.12.1 23-Jul-2009  jym Sync with HEAD.
 1.70.4.2 05-Mar-2011  rmind sync with head
 1.70.4.1 30-May-2010  rmind sync with head
 1.70.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.71.4.1 05-Mar-2011  bouyer Sync with HEAD
 1.71.2.1 06-Jun-2011  jruoho Sync with HEAD.
 1.72.14.1 03-Dec-2017  jdolecek update from HEAD
 1.21 28-Oct-2017  riastradh Kill some more extern struct cfdriver declarations.

Down with externs in .c!
 1.20 25-Jul-2014  dholland Add d_discard to all struct cdevsw instances I could find.

All have been set to "nodiscard"; some should get a real implementation.
 1.19 16-Mar-2014  dholland branches: 1.19.2;
Change (mostly mechanically) every cdevsw/bdevsw I can find to use
designated initializers.

I have not built every extant kernel so I have probably broken at
least one build; however I've also found and fixed some wrong
cdevsw/bdevsw entries so even if so I think we come out ahead.
 1.18 23-Nov-2011  jmcneill branches: 1.18.8; 1.18.12;
Merge jmcneill-audiomp3 branch, which is derived from ad-audiomp2. From
the original ad-audiomp branch notes:

Add MP locking to the audio drivers.

Making the audio drivers MP safe is necessary before efforts
can be made to make the VM system MP safe.

The are two locks per device instance, an ISR lock and
a character device lock. The ISR lock replaces calls to
splaudio()/splx(), and will be held across calls to device
methods which were called at splaudio() before (e.g.
trigger_output). The character device lock is held across
calls to nearly all of the methods, excluding some only
used for initialization, e.g. get_locks.

Welcome to 5.99.57.
 1.17 26-Mar-2008  xtraeme branches: 1.17.16; 1.17.38; 1.17.40;
Split device_t/softc for joy(4) and all its attachments. Also
use device_lookup_private() and related cosmetic changes.

Reviewed by cube@.
 1.16 01-Dec-2007  jmcneill branches: 1.16.14;
aprintify, on behalf of xtraeme
 1.15 19-Oct-2007  ad branches: 1.15.2;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.14 04-Mar-2007  christos branches: 1.14.2; 1.14.14; 1.14.16; 1.14.20;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.13 16-Nov-2006  christos branches: 1.13.4;
__unused removal on arguments; approved by core.
 1.12 12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.11 02-Sep-2006  christos branches: 1.11.2; 1.11.4;
add missing initializers
 1.10 28-Mar-2006  thorpej Use device_unit().
 1.9 11-Dec-2005  christos branches: 1.9.4; 1.9.6; 1.9.8; 1.9.10; 1.9.12;
merge ktrace-lwp.
 1.8 03-Aug-2004  drochner branches: 1.8.12;
implement device detach support
 1.7 08-Jul-2004  drochner Get rid of the arch dependencies for tome measurement - use microtime().
Works as well as before on my i386 (for want of a real joystick with a
50k resistor between pins 1 and 3).
 1.6 29-Jun-2003  fvdl branches: 1.6.2;
Back out the lwp/ktrace changes. They contained a lot of colateral damage,
and need to be examined and discussed more.
 1.5 28-Jun-2003  darrenr Pass lwp pointers throughtout the kernel, as required, so that the lwpid can
be inserted into ktrace records. The general change has been to replace
"struct proc *" with "struct lwp *" in various function prototypes, pass
the lwp through and use l_proc to get the process pointer when needed.

Bump the kernel rev up to 1.6V
 1.4 23-Oct-2002  jdolecek merge kqueue branch into -current

kqueue provides a stateful and efficient event notification framework
currently supported events include socket, file, directory, fifo,
pipe, tty and device changes, and monitoring of processes and signals

kqueue is supported by all writable filesystems in NetBSD tree
(with exception of Coda) and all device drivers supporting poll(2)

based on work done by Jonathan Lemon for FreeBSD
initial NetBSD port done by Luke Mewburn and Jason Thorpe
 1.3 06-Sep-2002  gehenna Merge the gehenna-devsw branch into the trunk.

This merge changes the device switch tables from static array to
dynamically generated by config(8).

- All device switches is defined as a constant structure in device drivers.

- The new grammer ``device-major'' is introduced to ``files''.

device-major <prefix> char <num> [block <num>] [<rules>]

- All device major numbers must be listed up in port dependent majors.<arch>
by using this grammer.

- Added the new naming convention.
The name of the device switch must be <prefix>_[bc]devsw for auto-generation
of device switch tables.

- The backward compatibility of loading block/character device
switch by LKM framework is broken. This is necessary to convert
from block/character device major to device name in runtime and vice versa.

- The restriction to assign device major by LKM is completely removed.
We don't need to reserve LKM entries for dynamic loading of device switch.

- In compile time, device major numbers list is packed into the kernel and
the LKM framework will refer it to assign device major number dynamically.
 1.2 03-Feb-2002  pooka branches: 1.2.2; 1.2.4; 1.2.12;
remove include of <machine/cpufunc.h>, it's not used here

fixes compile (at least) on arm32
 1.1 02-Feb-2002  jdolecek Reduce the massive code duplication regarding joy(4). Split it into
MI and MD parts, and make ISA/ISAPNP/PCI joy(4) attachments MI.
 1.2.12.1 16-May-2002  gehenna Add the character device switch.
 1.2.4.4 11-Nov-2002  nathanw Catch up to -current
 1.2.4.3 17-Sep-2002  nathanw Catch up to -current.
 1.2.4.2 28-Feb-2002  nathanw Catch up to -current.
 1.2.4.1 03-Feb-2002  nathanw file joy.c was added on branch nathanw_sa on 2002-02-28 04:13:27 +0000
 1.2.2.3 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.2.2.2 11-Feb-2002  jdolecek Sync w/ -current.
 1.2.2.1 03-Feb-2002  jdolecek file joy.c was added on branch kqueue on 2002-02-11 20:09:45 +0000
 1.6.2.5 21-Sep-2004  skrll Fix the sync with head I botched.
 1.6.2.4 18-Sep-2004  skrll Sync with HEAD.
 1.6.2.3 12-Aug-2004  skrll Sync with HEAD.
 1.6.2.2 03-Aug-2004  skrll Sync with HEAD
 1.6.2.1 02-Jul-2003  darrenr Apply the aborted ktrace-lwp changes to a specific branch. This is just for
others to review, I'm concerned that patch fuziness may have resulted in some
errant code being generated but I'll look at that later by comparing the diff
from the base to the branch with the file I attempt to apply to it. This will,
at the very least, put the changes in a better context for others to review
them and attempt to tinker with removing passing of 'struct lwp' through
the kernel.
 1.8.12.5 07-Dec-2007  yamt sync with head
 1.8.12.4 27-Oct-2007  yamt sync with head.
 1.8.12.3 03-Sep-2007  yamt sync with head.
 1.8.12.2 30-Dec-2006  yamt sync with head.
 1.8.12.1 21-Jun-2006  yamt sync with head.
 1.9.12.1 31-Mar-2006  tron Merge 2006-03-31 NetBSD-current into the "peter-altq" branch.
 1.9.10.1 19-Apr-2006  elad sync with head.
 1.9.8.2 03-Sep-2006  yamt sync with head.
 1.9.8.1 01-Apr-2006  yamt sync with head.
 1.9.6.1 22-Apr-2006  simonb Sync with head.
 1.9.4.1 09-Sep-2006  rpaulo sync with head
 1.11.4.2 10-Dec-2006  yamt sync with head.
 1.11.4.1 22-Oct-2006  yamt sync with head
 1.11.2.1 18-Nov-2006  ad Sync with head.
 1.13.4.1 12-Mar-2007  rmind Sync with HEAD.
 1.14.20.1 25-Oct-2007  bouyer Sync with HEAD.
 1.14.16.2 09-Jan-2008  matt sync with HEAD
 1.14.16.1 06-Nov-2007  matt sync with HEAD
 1.14.14.2 03-Dec-2007  joerg Sync with HEAD.
 1.14.14.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.14.2.1 23-Oct-2007  ad Sync with head.
 1.15.2.1 08-Dec-2007  mjf Sync with HEAD.
 1.16.14.3 06-Apr-2008  mjf - after some discussion with agc@ i agreed it would be a good idea to move
device_unregister_* to device_deregister_* to be more like the pmf(9)
functions, especially since a lot of the time the function calls are next
to each other.

- add device_register_name() support for dk(4).
 1.16.14.2 05-Apr-2008  mjf - add "file-system DEVFS" and "pseudo-device devfsctl" to conf/std seeing
as these are always needed.

- convert many, many drivers over to the New Devfs World Order. For a
list of device drivers yet to be converted see,
http://www.netbsd.org/~mjf/devfs-todo.html.

- add a new device_unregister_all(device_t) function to remove all device
names associated with a device_t, which saves us having to construct
device names when the driver is detached.

- add a DEV_AUDIO type for devices.
 1.16.14.1 03-Apr-2008  mjf Sync with HEAD.
 1.17.40.1 19-Nov-2011  jmcneill port ad-audiomp2 branch changes to 5.99.56
todo:
- port ad-audiomp2 pcppi changes
- these drivers need to be fixed:
- emuxki
- gcscaudio
- hdafg
- uaudio
- umidi
- MD audio drivers
 1.17.38.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.17.38.1 17-Apr-2012  yamt sync with head
 1.17.16.1 12-Dec-2008  ad Checkpoint work in progress.
 1.18.12.1 18-May-2014  rmind sync with head
 1.18.8.2 03-Dec-2017  jdolecek update from HEAD
 1.18.8.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.19.2.1 10-Aug-2014  tls Rebase.
 1.7 23-Nov-2011  jmcneill Merge jmcneill-audiomp3 branch, which is derived from ad-audiomp2. From
the original ad-audiomp branch notes:

Add MP locking to the audio drivers.

Making the audio drivers MP safe is necessary before efforts
can be made to make the VM system MP safe.

The are two locks per device instance, an ISR lock and
a character device lock. The ISR lock replaces calls to
splaudio()/splx(), and will be held across calls to device
methods which were called at splaudio() before (e.g.
trigger_output). The character device lock is held across
calls to nearly all of the methods, excluding some only
used for initialization, e.g. get_locks.

Welcome to 5.99.57.
 1.6 26-Mar-2008  xtraeme branches: 1.6.16; 1.6.38; 1.6.40;
Split device_t/softc for joy(4) and all its attachments. Also
use device_lookup_private() and related cosmetic changes.

Reviewed by cube@.
 1.5 11-Dec-2005  christos branches: 1.5.70;
merge ktrace-lwp.
 1.4 04-Feb-2005  perry de-__P
 1.3 03-Aug-2004  drochner branches: 1.3.4; 1.3.6;
implement device detach support
 1.2 08-Jul-2004  drochner Get rid of the arch dependencies for tome measurement - use microtime().
Works as well as before on my i386 (for want of a real joystick with a
50k resistor between pins 1 and 3).
 1.1 02-Feb-2002  jdolecek branches: 1.1.2; 1.1.4; 1.1.20;
Reduce the massive code duplication regarding joy(4). Split it into
MI and MD parts, and make ISA/ISAPNP/PCI joy(4) attachments MI.
 1.1.20.5 04-Feb-2005  skrll Sync with HEAD.
 1.1.20.4 21-Sep-2004  skrll Fix the sync with head I botched.
 1.1.20.3 18-Sep-2004  skrll Sync with HEAD.
 1.1.20.2 12-Aug-2004  skrll Sync with HEAD.
 1.1.20.1 03-Aug-2004  skrll Sync with HEAD
 1.1.4.2 28-Feb-2002  nathanw Catch up to -current.
 1.1.4.1 02-Feb-2002  nathanw file joyvar.h was added on branch nathanw_sa on 2002-02-28 04:13:28 +0000
 1.1.2.2 11-Feb-2002  jdolecek Sync w/ -current.
 1.1.2.1 02-Feb-2002  jdolecek file joyvar.h was added on branch kqueue on 2002-02-11 20:09:45 +0000
 1.3.6.1 12-Feb-2005  yamt sync with head.
 1.3.4.1 29-Apr-2005  kent sync with -current
 1.5.70.1 03-Apr-2008  mjf Sync with HEAD.
 1.6.40.1 19-Nov-2011  jmcneill port ad-audiomp2 branch changes to 5.99.56
todo:
- port ad-audiomp2 pcppi changes
- these drivers need to be fixed:
- emuxki
- gcscaudio
- hdafg
- uaudio
- umidi
- MD audio drivers
 1.6.38.1 17-Apr-2012  yamt sync with head
 1.6.16.1 12-Dec-2008  ad Checkpoint work in progress.
 1.36 29-Jan-2020  thorpej Adopt <net/if_stats.h>.
 1.35 30-May-2019  msaitoh branches: 1.35.4;
Simplify MII structure initialization and reference. No functional change.
 1.34 28-May-2019  msaitoh Use ETHER_LOCK()/ETHER_UNLOCK() for all ethernet drivers to protect ec_multi*.
 1.33 23-May-2019  msaitoh Whitespace fix (mainly tabify).
 1.32 23-May-2019  msaitoh -No functional change:
- KNF
- u_int*_t -> uint*_t.
 1.31 23-Apr-2019  msaitoh Fix compile error.
 1.30 22-Apr-2019  msaitoh On drivers which use MII(4) and have hook SIOC[GS]IFMEDIA which just pass to
ifmedia_ioctl(), the hook is not required because ether_ioctl has it
(if_ethersubr.c rev. 1.160). These drivers don't return ENETRESET in
ifmedia_ioctl(), so no functional change.
 1.29 22-Jan-2019  jmcneill Fix return type of lan9118_mii_readreg
 1.28 22-Jan-2019  msaitoh Change MII PHY read/write API from:

int (*mii_readreg_t)(device_t, int, int);
void (*mii_writereg_t)(device_t, int, int, int);
to:

int (*mii_readreg_t)(device_t, int, int, uint16_t *);
int (*mii_writereg_t)(device_t, int, int, uint16_t);

Now we can test if a read/write operation failed or not by the return value.

In 802.3 spec says that the PHY shall not respond to read/write transaction
to the unimplemented register(22.2.4.3). Detecting timeout can be used to
check whether a register is implemented or not (if the register conforms to
the spec). ukphy(4) can be used this for MII_MMDACR and MII_MMDAADR.

Note that I noticed that the following code do infinite loop in the
read/wirte function. If it accesses unimplemented PHY register, it will hang.
It should be fixed:

arm/at91/at91emac.c
arm/ep93xx/epe.c
arm/omap/omapl1x_emac.c
mips/ralink/ralink_eth.c
arch/powerpc/booke/dev/pq3etsec.c(read)
dev/cadence/if_cemac.c <- hkenken
dev/ic/lan9118.c


Tested with the following device:

axe+ukphy
axe+rgephy
axen+rgephy (tested by Andrius V)
wm+atphy
wm+ukphy
wm+igphy
wm+ihphy
wm+makphy
sk+makphy
sk+brgphy
sk+gentbi
msk+makphy
sip+icsphy
sip+ukphy
re+rgephy
bge+brgphy
bnx+brgphy
gsip+gphyter
rtk+rlphy
fxp+inphy (tested by Andrius V)
tlp+acphy
ex+exphy
epic+qsphy
vge+ciphy (tested by Andrius V)
vr+ukphy (tested by Andrius V)
vte+ukphy (tested by Andrius V)

Not tested (MAC):
arm:at91emac
arm:cemac
arm:epe
arm:geminigmac
arm:enet
arm:cpsw
arm:emac(omac)
arm:emac(sunxi)
arm:npe
evbppc:temac
macppc:bm
macppc:gm
mips:aumac
mips:ae
mips:cnmac
mips:reth
mips:sbmac
playstation2:smap
powerpc:tsec
powerpc:emac(ibm4xx)
sgimips:mec
sparc:be
sf
ne(ax88190, dl10019)
awge
ep
gem
hme
smsh
mtd
sm
age
alc
ale
bce
cas
et
jme
lii
nfe
pcn
ste
stge
tl
xi
aue
mue
smsc
udav
url

Not tested (PHY):
amhphy
bmtphy
dmphy
etphy
glxtphy
ikphy
iophy
lxtphy
nsphyter
pnaphy
rdcphy
sqphy
tlphy
tqphy
urlphy
 1.27 26-Jun-2018  msaitoh branches: 1.27.2;
Implement the BPF direction filter (BIOC[GS]DIRECTION). It provides backward
compatibility with BIOC[GS]SEESENT ioctl. The userland interface is the same
as FreeBSD.

This change also fixes a bug that the direction is misunderstand on some
environment by passing the direction to bpf_mtap*() instead of checking
m->m_pkthdr.rcvif.
 1.26 02-Jun-2017  jmcneill branches: 1.26.8;
Trigger a software interrupt if any packets were transmitted in
lan9118_start to workaround a possible issue where completion interrupts
are missed and the watchdog timer fires.
 1.25 01-Jun-2017  jmcneill Add flags to control IRQ polarity and buffer type. These can be set by
the bus glue to switch to active high and/or push-pull configurations.
 1.24 20-Feb-2017  ozaki-r Apply deferred if_start to more drivers
 1.23 15-Dec-2016  ozaki-r branches: 1.23.2;
Move bpf_mtap and if_ipackets++ on Rx of each driver to percpuq if_input

The benefits of the change are:
- We can reduce codes
- We can provide the same behavior between drivers
- Where/When if_ipackets is counted up
- Note that some drivers still update packet statistics in their own
way (periodical update)
- Moved bpf_mtap run in softint
- This makes it easy to MP-ify bpf

Proposed on tech-kern and tech-net
 1.22 10-Jun-2016  ozaki-r branches: 1.22.2;
Introduce m_set_rcvif and m_reset_rcvif

The API is used to set (or reset) a received interface of a mbuf.
They are counterpart of m_get_rcvif, which will come in another
commit, hide internal of rcvif operation, and reduce the diff of
the upcoming change.

No functional change.
 1.21 09-Feb-2016  ozaki-r Introduce softint-based if_input

This change intends to run the whole network stack in softint context
(or normal LWP), not hardware interrupt context. Note that the work is
still incomplete by this change; to that end, we also have to softint-ify
if_link_state_change (and bpf) which can still run in hardware interrupt.

This change softint-ifies at ifp->if_input that is called from
each device driver (and ieee80211_input) to ensure Layer 2 runs
in softint (e.g., ether_input and bridge_input). To this end,
we provide a framework (called percpuq) that utlizes softint(9)
and percpu ifqueues. With this patch, rxintr of most drivers just
queues received packets and schedules a softint, and the softint
dequeues packets and does rest packet processing.

To minimize changes to each driver, percpuq is allocated in struct
ifnet for now and that is initialized by default (in if_attach).
We probably have to move percpuq to softc of each driver, but it's
future work. At this point, only wm(4) has percpuq in its softc
as a reference implementation.

Additional information including performance numbers can be found
in the thread at tech-kern@ and tech-net@:
http://mail-index.netbsd.org/tech-kern/2016/01/14/msg019997.html

Acknowledgment: riastradh@ greatly helped this work.
Thank you very much!
 1.20 20-Apr-2015  kiyohara Backout r1.18.
Don't change IRQ porality. The Real-machines encounters interrupt storm.
OK slp@.

I assum configured it from boot-loader already. However need polarity
information, if not. Shall we implement to use prop_dictionary_{set,get}?

Also this case, re-initialized to LAN9118_IRQ_CFG without
LAN9118_IRQ_CFG_POL in lan9118_init(). I think, again interrupt storm on
QEMU.
 1.19 13-Apr-2015  riastradh Convert sys/dev to use <sys/rndsource.h>.
 1.18 09-Feb-2015  slp Configure interrupt polarity before enabling PHY.

This prevents a interrupt storm when running under QEMU.
 1.17 10-Aug-2014  tls branches: 1.17.4;
Merge tls-earlyentropy branch into HEAD.
 1.16 22-Jul-2012  matt branches: 1.16.2; 1.16.12;
Fix mii_statchg to take a 'struct ifnet *' instead of device_t. This fixes
problem with a common MDIO bus used for multiple interfaces.
Some drivers converted to CFATTACL_DECL_NEW.
 1.15 02-Feb-2012  tls Entropy-pool implementation move and cleanup.

1) Move core entropy-pool code and source/sink/sample management code
to sys/kern from sys/dev.

2) Remove use of NRND as test for presence of entropy-pool code throughout
source tree.

3) Remove use of RND_ENABLED in device drivers as microoptimization to
avoid expensive operations on disabled entropy sources; make the
rnd_add calls do this directly so all callers benefit.

4) Fix bug in recent rnd_add_data()/rnd_add_uint32() changes that might
have lead to slight entropy overestimation for some sources.

5) Add new source types for environmental sensors, power sensors, VM
system events, and skew between clocks, with a sample implementation
for each.

ok releng to go in before the branch due to the difficulty of later
pullup (widespread #ifdef removal and moved files). Tested with release
builds on amd64 and evbarm and live testing on amd64.
 1.14 05-Apr-2010  joerg branches: 1.14.8; 1.14.12;
Push the bpf_ops usage back into bpf.h. Push the common ifp->if_bpf
check into the inline functions as well the fourth argument for
bpf_attach.
 1.13 19-Jan-2010  pooka branches: 1.13.2; 1.13.4;
Redefine bpf linkage through an always present op vector, i.e.
#if NBPFILTER is no longer required in the client. This change
doesn't yet add support for loading bpf as a module, since drivers
can register before bpf is attached. However, callers of bpf can
now be modularized.

Dynamically loadable bpf could probably be done fairly easily with
coordination from the stub driver and the real driver by registering
attachments in the stub before the real driver is loaded and doing
a handoff. ... and I'm not going to ponder the depths of unload
here.

Tested with i386/MONOLITHIC, modified MONOLITHIC without bpf and rump.
 1.12 20-Dec-2009  kiyohara Set filter at lan9118_init() and lan9118_ioctl with SIOCSIFFLAGS.
 1.11 06-Dec-2009  kiyohara Split internal phy. We can use ukphy(4).
SMSC manufactures some PHY. This PHY is built into LAN9x18 Family.
 1.10 02-Dec-2009  kiyohara Maybe supported LAN9218 Family.
 1.9 29-Nov-2009  kiyohara Fix "+ 0x100" instead of "| 0x100" in the case ID 0x11[5678]A.
 1.8 29-Nov-2009  kiyohara Change print messages.
1. Use aprint instead of DPRINTF in swap mode.
2. Locates and vendor/LSI names 1-line print.
3. Also print (and maybe support) LAN92xx.
 1.7 29-Nov-2009  kiyohara Set mii_media_active in lan9118_ifm_change(). This is like ukphy_status().
Also LAN9118_TXS_NC is valid when if FDX.
 1.6 29-Nov-2009  kiyohara Fix register access to MII in lan9118_mii_readreg()/lan9118_mii_writereg().
 1.5 28-Nov-2009  kiyohara Comment out interrupt for LAN9118_INT_PHY_INT and LAN9118_INT_PME_INT. These
not support yet...
 1.4 28-Nov-2009  kiyohara Check mbuf size and buffers.
 1.3 28-Nov-2009  kiyohara Support mii_tick().
Thanks tsubai@.
 1.2 23-Nov-2009  kiyohara - Wait the ready 5sec, not 5msec.
- Set IFM_ACTIVE to ifm_status instead of ifm_active. ifconfig(8) always said
'no carrier'...
 1.1 09-Aug-2009  kiyohara branches: 1.1.2;
Support SMSC LAN9118 Family Ethernet interfaces device driver.
It tested on GUMSTIX only.
 1.1.2.4 11-Aug-2010  yamt sync with head.
 1.1.2.3 11-Mar-2010  yamt sync with head
 1.1.2.2 19-Aug-2009  yamt sync with head.
 1.1.2.1 09-Aug-2009  yamt file lan9118.c was added on branch yamt-nfs-mp on 2009-08-19 18:47:07 +0000
 1.13.4.1 30-May-2010  rmind sync with head
 1.13.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.14.12.1 18-Feb-2012  mrg merge to -current.
 1.14.8.2 30-Oct-2012  yamt sync with head
 1.14.8.1 17-Apr-2012  yamt sync with head
 1.16.12.1 07-Apr-2014  tls Be a little more clear and consistent about harvesting entropy from devices:

1) deprecate RND_FLAG_NO_ESTIMATE

2) define RND_FLAG_COLLECT_TIME, RND_FLAG_COLLECT_VALUE

3) define RND_FLAG_ESTIMATE_TIME, RND_FLAG_ESTIMATE_VALUE

4) define RND_FLAG_DEFAULT: RND_FLAG_COLLECT_TIME|
RND_FLAG_COLLECT_VALUE|RND_FLAG_ESTIMATE_TIME

5) Make entropy harvesting from environmental sensors a little more generic
and remove it from individual sensor drivers.

6) Remove individual open-coded delta-estimators for values from a few
places in the tree (uvm, environmental drivers).

7) 0 -> RND_FLAG_DEFAULT, actually gather entropy from various drivers
that had stubbed out code, other minor cleanups.
 1.16.2.2 03-Dec-2017  jdolecek update from HEAD
 1.16.2.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.17.4.6 28-Aug-2017  skrll Sync with HEAD
 1.17.4.5 05-Feb-2017  skrll Sync with HEAD
 1.17.4.4 09-Jul-2016  skrll Sync with HEAD
 1.17.4.3 19-Mar-2016  skrll Sync with HEAD
 1.17.4.2 06-Jun-2015  skrll Sync with HEAD
 1.17.4.1 06-Apr-2015  skrll Sync with HEAD
 1.22.2.2 20-Mar-2017  pgoyette Sync with HEAD
 1.22.2.1 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.23.2.1 21-Apr-2017  bouyer Sync with HEAD
 1.26.8.2 26-Jan-2019  pgoyette Sync with HEAD
 1.26.8.1 28-Jul-2018  pgoyette Sync with HEAD
 1.27.2.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.27.2.1 10-Jun-2019  christos Sync with HEAD
 1.35.4.1 29-Feb-2020  ad Sync with head.
 1.4 16-Mar-2024  andvar s/Broardcast/Broadcast/ in comment.
 1.3 27-Sep-2010  kiyohara Add some IDs. (9210/9211/9220/9221)
 1.2 02-Dec-2009  kiyohara branches: 1.2.2; 1.2.4;
Maybe supported LAN9218 Family.
 1.1 09-Aug-2009  kiyohara branches: 1.1.2;
Support SMSC LAN9118 Family Ethernet interfaces device driver.
It tested on GUMSTIX only.
 1.1.2.4 09-Oct-2010  yamt sync with head
 1.1.2.3 11-Mar-2010  yamt sync with head
 1.1.2.2 19-Aug-2009  yamt sync with head.
 1.1.2.1 09-Aug-2009  yamt file lan9118reg.h was added on branch yamt-nfs-mp on 2009-08-19 18:47:07 +0000
 1.2.4.1 05-Mar-2011  rmind sync with head
 1.2.2.1 22-Oct-2010  uebayasi Sync with HEAD (-D20101022).
 1.6 01-Jun-2017  jmcneill Add flags to control IRQ polarity and buffer type. These can be set by
the bus glue to switch to active high and/or push-pull configurations.
 1.5 13-Apr-2015  riastradh Convert sys/dev to use <sys/rndsource.h>.
 1.4 02-Feb-2012  tls branches: 1.4.6; 1.4.24;
Entropy-pool implementation move and cleanup.

1) Move core entropy-pool code and source/sink/sample management code
to sys/kern from sys/dev.

2) Remove use of NRND as test for presence of entropy-pool code throughout
source tree.

3) Remove use of RND_ENABLED in device drivers as microoptimization to
avoid expensive operations on disabled entropy sources; make the
rnd_add calls do this directly so all callers benefit.

4) Fix bug in recent rnd_add_data()/rnd_add_uint32() changes that might
have lead to slight entropy overestimation for some sources.

5) Add new source types for environmental sensors, power sensors, VM
system events, and skew between clocks, with a sample implementation
for each.

ok releng to go in before the branch due to the difficulty of later
pullup (widespread #ifdef removal and moved files). Tested with release
builds on amd64 and evbarm and live testing on amd64.
 1.3 19-Nov-2011  tls branches: 1.3.2;
First step of random number subsystem rework described in
<20111022023242.BA26F14A158@mail.netbsd.org>. This change includes
the following:

An initial cleanup and minor reorganization of the entropy pool
code in sys/dev/rnd.c and sys/dev/rndpool.c. Several bugs are
fixed. Some effort is made to accumulate entropy more quickly at
boot time.

A generic interface, "rndsink", is added, for stream generators to
request that they be re-keyed with good quality entropy from the pool
as soon as it is available.

The arc4random()/arc4randbytes() implementation in libkern is
adjusted to use the rndsink interface for rekeying, which helps
address the problem of low-quality keys at boot time.

An implementation of the FIPS 140-2 statistical tests for random
number generator quality is provided (libkern/rngtest.c). This
is based on Greg Rose's implementation from Qualcomm.

A new random stream generator, nist_ctr_drbg, is provided. It is
based on an implementation of the NIST SP800-90 CTR_DRBG by
Henric Jungheim. This generator users AES in a modified counter
mode to generate a backtracking-resistant random stream.

An abstraction layer, "cprng", is provided for in-kernel consumers
of randomness. The arc4random/arc4randbytes API is deprecated for
in-kernel use. It is replaced by "cprng_strong". The current
cprng_fast implementation wraps the existing arc4random
implementation. The current cprng_strong implementation wraps the
new CTR_DRBG implementation. Both interfaces are rekeyed from
the entropy pool automatically at intervals justifiable from best
current cryptographic practice.

In some quick tests, cprng_fast() is about the same speed as
the old arc4randbytes(), and cprng_strong() is about 20% faster
than rnd_extract_data(). Performance is expected to improve.

The AES code in src/crypto/rijndael is no longer an optional
kernel component, as it is required by cprng_strong, which is
not an optional kernel component.

The entropy pool output is subjected to the rngtest tests at
startup time; if it fails, the system will reboot. There is
approximately a 3/10000 chance of a false positive from these
tests. Entropy pool _input_ from hardware random numbers is
subjected to the rngtest tests at attach time, as well as the
FIPS continuous-output test, to detect bad or stuck hardware
RNGs; if any are detected, they are detached, but the system
continues to run.

A problem with rndctl(8) is fixed -- datastructures with
pointers in arrays are no longer passed to userspace (this
was not a security problem, but rather a major issue for
compat32). A new kernel will require a new rndctl.

The sysctl kern.arandom() and kern.urandom() nodes are hooked
up to the new generators, but the /dev/*random pseudodevices
are not, yet.

Manual pages for the new kernel interfaces are forthcoming.
 1.2 28-Nov-2009  kiyohara branches: 1.2.12;
Support mii_tick().
Thanks tsubai@.
 1.1 09-Aug-2009  kiyohara branches: 1.1.2;
Support SMSC LAN9118 Family Ethernet interfaces device driver.
It tested on GUMSTIX only.
 1.1.2.3 11-Mar-2010  yamt sync with head
 1.1.2.2 19-Aug-2009  yamt sync with head.
 1.1.2.1 09-Aug-2009  yamt file lan9118var.h was added on branch yamt-nfs-mp on 2009-08-19 18:47:07 +0000
 1.2.12.1 17-Apr-2012  yamt sync with head
 1.3.2.1 18-Feb-2012  mrg merge to -current.
 1.4.24.2 28-Aug-2017  skrll Sync with HEAD
 1.4.24.1 06-Jun-2015  skrll Sync with HEAD
 1.4.6.1 03-Dec-2017  jdolecek update from HEAD
 1.62 17-Nov-2024  hannken Fix typo in last commit: ec_rx_owner -> ec_rx_mowner

Kernels ALL/amd64 and ALL/i386 compile again.
 1.61 10-Nov-2024  mlelstv Handle MBUFTRACE
 1.60 29-Jan-2020  thorpej branches: 1.60.30;
Adopt <net/if_stats.h>.
 1.59 27-Dec-2019  msaitoh branches: 1.59.2;
s/expresion/expression/ in comment.
 1.58 29-May-2019  msaitoh Even if we don't use MII(4), use the common path of SIOC[GS]IFMEDIA in
sys/net/if_ethersubr.c if we can.
- Add ec_ifmedia into struct ethercom.
- ec_mii in struct ethercom is kept and used as it is. It might be used in
future. Note that some Ethernet drivers which _DOESN'T_ use mii(4) use
ec_mii for keeping the if_media. Those should be changed in future.
 1.57 28-May-2019  msaitoh Use ETHER_LOCK()/ETHER_UNLOCK() for all ethernet drivers to protect ec_multi*.
 1.56 23-May-2019  msaitoh No functional change:
- Change ac(was arpcom) to ec(ethercom)
- Simplify MII structure initialization.
- u_int*_t -> uint*_t.
- KNF
 1.55 05-Feb-2019  msaitoh Remove very old IFF_NOTRAILERS flag.
 1.54 03-Sep-2018  riastradh Rename min/max -> uimin/uimax for better honesty.

These functions are defined on unsigned int. The generic name
min/max should not silently truncate to 32 bits on 64-bit systems.
This is purely a name change -- no functional change intended.

HOWEVER! Some subsystems have

#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))

even though our standard name for that is MIN/MAX. Although these
may invite multiple evaluation bugs, these do _not_ cause integer
truncation.

To avoid `fixing' these cases, I first changed the name in libkern,
and then compile-tested every file where min/max occurred in order to
confirm that it failed -- and thus confirm that nothing shadowed
min/max -- before changing it.

I have left a handful of bootloaders that are too annoying to
compile-test, and some dead code:

cobalt ews4800mips hp300 hppa ia64 luna68k vax
acorn32/if_ie.c (not included in any kernels)
macppc/if_gm.c (superseded by gem(4))

It should be easy to fix the fallout once identified -- this way of
doing things fails safe, and the goal here, after all, is to _avoid_
silent integer truncations, not introduce them.

Maybe one day we can reintroduce min/max as type-generic things that
never silently truncate. But we should avoid doing that for a while,
so that existing code has a chance to be detected by the compiler for
conversion to uimin/uimax without changing the semantics until we can
properly audit it all. (Who knows, maybe in some cases integer
truncation is actually intended!)
 1.53 22-Jun-2018  msaitoh branches: 1.53.2;
It's not required to include net/bpfdesc.h. Remove it.
 1.52 15-Dec-2016  ozaki-r branches: 1.52.8; 1.52.14;
Move bpf_mtap and if_ipackets++ on Rx of each driver to percpuq if_input

The benefits of the change are:
- We can reduce codes
- We can provide the same behavior between drivers
- Where/When if_ipackets is counted up
- Note that some drivers still update packet statistics in their own
way (periodical update)
- Moved bpf_mtap run in softint
- This makes it easy to MP-ify bpf

Proposed on tech-kern and tech-net
 1.51 02-Oct-2016  christos MFREE -> m_free
 1.50 10-Jun-2016  ozaki-r branches: 1.50.2;
Introduce m_set_rcvif and m_reset_rcvif

The API is used to set (or reset) a received interface of a mbuf.
They are counterpart of m_get_rcvif, which will come in another
commit, hide internal of rcvif operation, and reduce the diff of
the upcoming change.

No functional change.
 1.49 09-Feb-2016  ozaki-r Introduce softint-based if_input

This change intends to run the whole network stack in softint context
(or normal LWP), not hardware interrupt context. Note that the work is
still incomplete by this change; to that end, we also have to softint-ify
if_link_state_change (and bpf) which can still run in hardware interrupt.

This change softint-ifies at ifp->if_input that is called from
each device driver (and ieee80211_input) to ensure Layer 2 runs
in softint (e.g., ether_input and bridge_input). To this end,
we provide a framework (called percpuq) that utlizes softint(9)
and percpu ifqueues. With this patch, rxintr of most drivers just
queues received packets and schedules a softint, and the softint
dequeues packets and does rest packet processing.

To minimize changes to each driver, percpuq is allocated in struct
ifnet for now and that is initialized by default (in if_attach).
We probably have to move percpuq to softc of each driver, but it's
future work. At this point, only wm(4) has percpuq in its softc
as a reference implementation.

Additional information including performance numbers can be found
in the thread at tech-kern@ and tech-net@:
http://mail-index.netbsd.org/tech-kern/2016/01/14/msg019997.html

Acknowledgment: riastradh@ greatly helped this work.
Thank you very much!
 1.48 13-Apr-2015  riastradh Convert sys/dev to use <sys/rndsource.h>.
 1.47 10-Aug-2014  tls branches: 1.47.4;
Merge tls-earlyentropy branch into HEAD.
 1.46 02-Feb-2012  tls branches: 1.46.6; 1.46.20;
Entropy-pool implementation move and cleanup.

1) Move core entropy-pool code and source/sink/sample management code
to sys/kern from sys/dev.

2) Remove use of NRND as test for presence of entropy-pool code throughout
source tree.

3) Remove use of RND_ENABLED in device drivers as microoptimization to
avoid expensive operations on disabled entropy sources; make the
rnd_add calls do this directly so all callers benefit.

4) Fix bug in recent rnd_add_data()/rnd_add_uint32() changes that might
have lead to slight entropy overestimation for some sources.

5) Add new source types for environmental sensors, power sensors, VM
system events, and skew between clocks, with a sample implementation
for each.

ok releng to go in before the branch due to the difficulty of later
pullup (widespread #ifdef removal and moved files). Tested with release
builds on amd64 and evbarm and live testing on amd64.
 1.45 05-Apr-2010  joerg branches: 1.45.8; 1.45.12;
Push the bpf_ops usage back into bpf.h. Push the common ifp->if_bpf
check into the inline functions as well the fourth argument for
bpf_attach.
 1.44 19-Jan-2010  pooka branches: 1.44.2; 1.44.4;
Redefine bpf linkage through an always present op vector, i.e.
#if NBPFILTER is no longer required in the client. This change
doesn't yet add support for loading bpf as a module, since drivers
can register before bpf is attached. However, callers of bpf can
now be modularized.

Dynamically loadable bpf could probably be done fairly easily with
coordination from the stub driver and the real driver by registering
attachments in the stub before the real driver is loaded and doing
a handoff. ... and I'm not going to ponder the depths of unload
here.

Tested with i386/MONOLITHIC, modified MONOLITHIC without bpf and rump.
 1.43 04-Sep-2009  tsutsui Replace shutdownhook_establish(9) with pmf_device_register1(9).
Tested on sun3x.
 1.42 07-Nov-2008  dyoung *** Summary ***

When a link-layer address changes (e.g., ifconfig ex0 link
02:de:ad:be:ef:02 active), send a gratuitous ARP and/or a Neighbor
Advertisement to update the network-/link-layer address bindings
on our LAN peers.

Refuse a change of ethernet address to the address 00:00:00:00:00:00
or to any multicast/broadcast address. (Thanks matt@.)

Reorder ifnet ioctl operations so that driver ioctls may inherit
the functions of their "class"---ether_ioctl(), fddi_ioctl(), et
cetera---and the class ioctls may inherit from the generic ioctl,
ifioctl_common(), but both driver- and class-ioctls may override
the generic behavior. Make network drivers share more code.

Distinguish a "factory" link-layer address from others for the
purposes of both protecting that address from deletion and computing
EUI64.

Return consistent, appropriate error codes from network drivers.

Improve readability. KNF.

*** Details ***

In if_attach(), always initialize the interface ioctl routine,
ifnet->if_ioctl, if the driver has not already initialized it.
Delete if_ioctl == NULL tests everywhere else, because it cannot
happen.

In the ioctl routines of network interfaces, inherit common ioctl
behaviors by calling either ifioctl_common() or whichever ioctl
routine is appropriate for the class of interface---e.g., ether_ioctl()
for ethernets.

Stop (ab)using SIOCSIFADDR and start to use SIOCINITIFADDR. In
the user->kernel interface, SIOCSIFADDR's argument was an ifreq,
but on the protocol->ifnet interface, SIOCSIFADDR's argument was
an ifaddr. That was confusing, and it would work against me as I
make it possible for a network interface to overload most ioctls.
On the protocol->ifnet interface, replace SIOCSIFADDR with
SIOCINITIFADDR. In ifioctl(), return EPERM if userland tries to
invoke SIOCINITIFADDR.

In ifioctl(), give the interface the first shot at handling most
interface ioctls, and give the protocol the second shot, instead
of the other way around. Finally, let compatibility code (COMPAT_OSOCK)
take a shot.

Pull device initialization out of switch statements under
SIOCINITIFADDR. For example, pull ..._init() out of any switch
statement that looks like this:

switch (...->sa_family) {
case ...:
..._init();
...
break;
...
default:
..._init();
...
break;
}

Rewrite many if-else clauses that handle all permutations of IFF_UP
and IFF_RUNNING to use a switch statement,

switch (x & (IFF_UP|IFF_RUNNING)) {
case 0:
...
break;
case IFF_RUNNING:
...
break;
case IFF_UP:
...
break;
case IFF_UP|IFF_RUNNING:
...
break;
}

unifdef lots of code containing #ifdef FreeBSD, #ifdef NetBSD, and
#ifdef SIOCSIFMTU, especially in fwip(4) and in ndis(4).

In ipw(4), remove an if_set_sadl() call that is out of place.

In nfe(4), reuse the jumbo MTU logic in ether_ioctl().

Let ethernets register a callback for setting h/w state such as
promiscuous mode and the multicast filter in accord with a change
in the if_flags: ether_set_ifflags_cb() registers a callback that
returns ENETRESET if the caller should reset the ethernet by calling
if_init(), 0 on success, != 0 on failure. Pull common code from
ex(4), gem(4), nfe(4), sip(4), tlp(4), vge(4) into ether_ioctl(),
and register if_flags callbacks for those drivers.

Return ENOTTY instead of EINVAL for inappropriate ioctls. In
zyd(4), use ENXIO instead of ENOTTY to indicate that the device is
not any longer attached.

Add to if_set_sadl() a boolean 'factory' argument that indicates
whether a link-layer address was assigned by the factory or some
other source. In a comment, recommend using the factory address
for generating an EUI64, and update in6_get_hw_ifid() to prefer a
factory address to any other link-layer address.

Add a routing message, RTM_LLINFO_UPD, that tells protocols to
update the binding of network-layer addresses to link-layer addresses.
Implement this message in IPv4 and IPv6 by sending a gratuitous
ARP or a neighbor advertisement, respectively. Generate RTM_LLINFO_UPD
messages on a change of an interface's link-layer address.

In ether_ioctl(), do not let SIOCALIFADDR set a link-layer address
that is broadcast/multicast or equal to 00:00:00:00:00:00.

Make ether_ioctl() call ifioctl_common() to handle ioctls that it
does not understand.

In gif(4), initialize if_softc and use it, instead of assuming that
the gif_softc and ifp overlap.

Let ifioctl_common() handle SIOCGIFADDR.

Sprinkle rtcache_invariants(), which checks on DIAGNOSTIC kernels
that certain invariants on a struct route are satisfied.

In agr(4), rewrite agr_ioctl_filter() to be a bit more explicit
about the ioctls that we do not allow on an agr(4) member interface.

bzero -> memset. Delete unnecessary casts to void *. Use
sockaddr_in_init() and sockaddr_in6_init(). Compare pointers with
NULL instead of "testing truth". Replace some instances of (type
*)0 with NULL. Change some K&R prototypes to ANSI C, and join
lines.
 1.41 28-Apr-2008  martin branches: 1.41.6; 1.41.8;
Remove clause 3 and 4 from TNF licenses
 1.40 04-Apr-2008  tsutsui branches: 1.40.2; 1.40.4;
Split device_t/softc for le(4) and variants and misc cosmetic changes.
 1.39 01-Sep-2007  dyoung branches: 1.39.20;
Change a bazillion occurrences of code resembling this,

error = (cmd == SIOCADDMULTI) ?
ether_addmulti(ifr, &sc->sc_ec) :
ether_delmulti(ifr, &sc->sc_ec);

if (error == ENETRESET) {

to this,

if ((error = ether_ioctl(ifp, cmd, data)) == ENETRESET) {

which does the same thing.

(A bazillion is a very large number. This seems to make the i386
ALL kernel smaller by 3kB to 4kB.)

Use ifreq_getaddr() twice in es(4).

Whitespace nits.
 1.38 04-Mar-2007  christos branches: 1.38.2; 1.38.10; 1.38.14; 1.38.16;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.37 16-Nov-2006  christos branches: 1.37.4;
__unused removal on arguments; approved by core.
 1.36 12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.35 07-Sep-2006  dogcow branches: 1.35.2; 1.35.4;
remove more vestiges of CCITT, LLC, HDLC, NS, and NSIP.
 1.34 24-Dec-2005  perry branches: 1.34.4; 1.34.8;
Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.33 11-Dec-2005  christos merge ktrace-lwp.
 1.32 27-Feb-2005  perry branches: 1.32.4;
nuke trailing whitespace
 1.31 04-Feb-2005  perry de-__P
 1.30 30-Oct-2004  thorpej branches: 1.30.4; 1.30.6;
When adding/deleting multicast addresses, only whack the address
filter if the interface is marked RUNNING.

Fixes kern/27678.
 1.29 07-Aug-2003  agc branches: 1.29.4;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22364, verified by myself.
 1.28 31-Jan-2003  pk branches: 1.28.2;
lance_init(): explicitly clearing the `initialisation done' bit in the
status register triggers an interrupt which we don't handle. Since the
driver doesn't depend on this status bit anywhere else, just leave it alone.
 1.27 03-Sep-2002  itojun drop garbage packet (due to chip bug) before injecting it to bpf.

make sure to behave as IFF_SIMPLEX, some lance chips does not behave as
IFF_SIMPLEX (e.g. vmware in outgoing multicast case).
http://mail-index.netbsd.org/tech-net/2001/05/16/0001.html
 1.26 13-Nov-2001  lukem add/cleanup RCSID
 1.25 07-Jul-2001  thorpej branches: 1.25.2;
bzero -> memset
 1.24 07-Jul-2001  thorpej bcopy -> memcpy, strcpy
 1.23 07-Jul-2001  thorpej bcmp -> memcmp
 1.22 19-Jun-2001  jdolecek The ifa is needed for CCITT&&LLC case, provide it in that case
 1.21 18-Jun-2001  onoe make it compilable: delete unused variable 'ifa' from lance_ioctl()
 1.20 18-Jun-2001  jdolecek Convert to use ether_ioctl() for SIOCSIFADDR and SIOCSIFFLAGS.
 1.19 30-May-2001  mrg use _KERNEL_OPT
 1.18 27-Apr-2001  jdolecek Don't panic if the memory size is "weird", but instead compute
reasonable transmit/receive buffer count.
This is needed for e.g. SKNET adapters, which use top 30 bytes of 16KB
memory to map registers and PROM and hence not all the memory is
available for buffers.
 1.17 14-Dec-2000  thorpej branches: 1.17.2;
ALTQ'ify.
 1.16 15-Nov-2000  thorpej Move bpfattach()/bpfdetach() calls into ether_ifattach()/ether_ifdetach().
 1.15 03-Nov-2000  tsutsui Make this compilie with LANCE_REVC_BUG.
 1.14 20-Oct-2000  bouyer Support ETHERCAP_VLAN_MTU. Tested on a sparc 2 with:
le0 at sbus0 slot 0 offset 0xc00000 level 5: address 00:00:3b:86:19:92
le0: 8 receive buffers, 2 transmit buffers
 1.13 01-Oct-2000  thorpej Move the check for "promisc + unicast + not for us" into ether_input(),
and change Ethernet drivers to always pass all received frames to
ether_input() (with a few exceptions, which are documented in the
code).
 1.12 12-May-2000  thorpej branches: 1.12.4;
Use ether_crc32_le().
 1.11 30-Mar-2000  augustss Remove register declarations.
 1.10 17-Nov-1999  simonb Move the "Attach the interface" section after printing the mac address
and buffer sizes. Stops the ipv6 attach info from messing up the
other driver info.
 1.9 18-May-1999  thorpej branches: 1.9.2; 1.9.8;
Rework layer 2 protocol input routines. Instead of calling e.g. ether_input()
directly, call the function pointer (*if_input)(ifp, m). The input routine
expects the packet header to be at the head of the packet, and will adjust
as necessary. Privatize the layer 2 input and output routines, allowing
*_ifattach() to set them up as appropriate.
 1.8 30-Apr-1999  thorpej In lance_mediachange(), if there is no callback to the front-end, just
return 0 instead of EINVAL. In this case, there will only be one media
type, and the upper-level if_media code will ensure that the user is setting
to that type.

In other words, don't require the front-end to provide the no-op.
 1.7 28-Feb-1999  explorer branches: 1.7.2;
Update to slightly altered rnd_attach_source() api
 1.6 17-Feb-1999  thorpej Avoid initializing the interface in the SIOCSIFFLAGS if ! UP and ! RUNNING.
 1.5 12-Dec-1998  mycroft Simplify the copy loops a bit.
 1.4 09-Dec-1998  leo branches: 1.4.2;
BVME410 ethernet driver by 'maximum entropy'.
 1.3 15-Aug-1998  mycroft Assign my copyrights to TNF.
 1.2 08-Aug-1998  mycroft Use splnet, not splimp.
 1.1 21-Jul-1998  drochner Split the LANCE driver into a part specific to the classic chip with
24-bit DMA addresses, and an independant part.
Implement support for the 32-bit mode in the newer (79c9xx) chips.
 1.4.2.1 11-Dec-1998  kenh The beginnings of interface detach support. Still some bugs, but mostly
works for me.

This work was originally by Bill Studenmund, and cleaned up by me.
 1.7.2.1 30-Apr-1999  perry branches: 1.7.2.1.2;
pullup 1.7->1.8 (thorpej)
 1.7.2.1.2.1 21-Jun-1999  thorpej Sync w/ -current.
 1.9.8.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.9.2.3 05-Jan-2001  bouyer Sync with HEAD
 1.9.2.2 22-Nov-2000  bouyer Sync with HEAD.
 1.9.2.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.12.4.1 31-Dec-2000  jhawk Pull up revision 1.14 (requested by bouyer):
Add support for 802.1Q virtual LANs.
 1.17.2.4 17-Sep-2002  nathanw Catch up to -current.
 1.17.2.3 14-Nov-2001  nathanw Catch up to -current.
 1.17.2.2 24-Aug-2001  nathanw Catch up with -current.
 1.17.2.1 21-Jun-2001  nathanw Catch up to -current.
 1.25.2.2 06-Sep-2002  jdolecek sync kqueue branch with HEAD
 1.25.2.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.28.2.6 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.28.2.5 04-Feb-2005  skrll Sync with HEAD.
 1.28.2.4 02-Nov-2004  skrll Sync with HEAD.
 1.28.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.28.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.28.2.1 03-Aug-2004  skrll Sync with HEAD
 1.29.4.1 24-Jan-2005  he Pull up revision 1.30 (requested by thorpej in ticket #939):
When adding or deleting multicast addresses, only change
the address filter if the interface is marked RUNNING.
Fixes PR#27678.
 1.30.6.2 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.30.6.1 12-Feb-2005  yamt sync with head.
 1.30.4.1 29-Apr-2005  kent sync with -current
 1.32.4.3 03-Sep-2007  yamt sync with head.
 1.32.4.2 30-Dec-2006  yamt sync with head.
 1.32.4.1 21-Jun-2006  yamt sync with head.
 1.34.8.1 14-Sep-2006  yamt sync with head.
 1.34.4.1 09-Sep-2006  rpaulo sync with head
 1.35.4.2 10-Dec-2006  yamt sync with head.
 1.35.4.1 22-Oct-2006  yamt sync with head
 1.35.2.1 18-Nov-2006  ad Sync with head.
 1.37.4.1 12-Mar-2007  rmind Sync with HEAD.
 1.38.16.1 06-Nov-2007  matt sync with HEAD
 1.38.14.1 03-Sep-2007  jmcneill Sync with HEAD.
 1.38.10.1 03-Sep-2007  skrll Sync with HEAD.
 1.38.2.1 09-Oct-2007  ad Sync with head.
 1.39.20.2 17-Jan-2009  mjf Sync with HEAD.
 1.39.20.1 02-Jun-2008  mjf Sync with HEAD.
 1.40.4.5 11-Aug-2010  yamt sync with head.
 1.40.4.4 11-Mar-2010  yamt sync with head
 1.40.4.3 16-Sep-2009  yamt sync with head
 1.40.4.2 04-May-2009  yamt sync with head.
 1.40.4.1 16-May-2008  yamt sync with head.
 1.40.2.1 18-May-2008  yamt sync with head.
 1.41.8.1 19-Jan-2009  skrll Sync with HEAD.
 1.41.6.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.44.4.1 30-May-2010  rmind sync with head
 1.44.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.45.12.1 18-Feb-2012  mrg merge to -current.
 1.45.8.1 17-Apr-2012  yamt sync with head
 1.46.20.1 07-Apr-2014  tls Be a little more clear and consistent about harvesting entropy from devices:

1) deprecate RND_FLAG_NO_ESTIMATE

2) define RND_FLAG_COLLECT_TIME, RND_FLAG_COLLECT_VALUE

3) define RND_FLAG_ESTIMATE_TIME, RND_FLAG_ESTIMATE_VALUE

4) define RND_FLAG_DEFAULT: RND_FLAG_COLLECT_TIME|
RND_FLAG_COLLECT_VALUE|RND_FLAG_ESTIMATE_TIME

5) Make entropy harvesting from environmental sensors a little more generic
and remove it from individual sensor drivers.

6) Remove individual open-coded delta-estimators for values from a few
places in the tree (uvm, environmental drivers).

7) 0 -> RND_FLAG_DEFAULT, actually gather entropy from various drivers
that had stubbed out code, other minor cleanups.
 1.46.6.2 03-Dec-2017  jdolecek update from HEAD
 1.46.6.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.47.4.5 05-Feb-2017  skrll Sync with HEAD
 1.47.4.4 05-Oct-2016  skrll Sync with HEAD
 1.47.4.3 09-Jul-2016  skrll Sync with HEAD
 1.47.4.2 19-Mar-2016  skrll Sync with HEAD
 1.47.4.1 06-Jun-2015  skrll Sync with HEAD
 1.50.2.2 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.50.2.1 04-Nov-2016  pgoyette Sync with HEAD
 1.52.14.2 06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.52.14.1 25-Jun-2018  pgoyette Sync with HEAD
 1.52.8.1 26-Jul-2018  snj Pull up following revision(s) (requested by msaitoh in ticket #938):
sys/arch/acorn32/podulebus/if_ie.c: revision 1.41
sys/arch/amiga/dev/if_es.c: revision 1.58
sys/arch/amiga/dev/if_qn.c: revision 1.45
sys/arch/arm/at91/at91emac.c: revision 1.20
sys/arch/arm/ep93xx/epe.c: revision 1.37
sys/arch/emips/ebus/if_le_ebus.c: revision 1.14
sys/arch/emips/ebus/if_le_ebus.c: revision 1.15
sys/arch/mac68k/dev/if_mc.c: revision 1.46
sys/arch/macppc/dev/am79c950.c: revision 1.39
sys/arch/newsmips/apbus/if_sn.c: revision 1.40
sys/arch/next68k/dev/mb8795.c: revision 1.59
sys/arch/playstation2/dev/if_smap.c: revision 1.25
sys/arch/playstation2/dev/if_smap.c: revision 1.26
sys/arch/sun2/dev/if_ec.c: revision 1.28
sys/arch/sun3/dev/if_ie.c: revision 1.63
sys/arch/x68k/dev/if_ne_intio.c: revision 1.19
sys/arch/xen/xen/if_xennet_xenbus.c: revision 1.75
sys/arch/xen/xen/xennetback_xenbus.c: revision 1.63
sys/dev/bi/if_ni.c: revision 1.45
sys/dev/cadence/if_cemac.c: revision 1.12
sys/dev/ic/am7990.c: revision 1.78
sys/dev/ic/am79900.c: revision 1.27
sys/dev/ic/an.c: revision 1.67
sys/dev/ic/cs89x0.c: revision 1.40
sys/dev/ic/dm9000.c: revision 1.13
sys/dev/ic/dm9000.c: revision 1.14
sys/dev/ic/dp8390.c: revision 1.88
sys/dev/ic/elink3.c: revision 1.141
sys/dev/ic/elinkxl.c: revision 1.122
sys/dev/ic/hme.c: revision 1.98
sys/dev/ic/i82586.c: revision 1.77
sys/dev/ic/lance.c: revision 1.53
sys/dev/ic/mb86950.c: revision 1.27
sys/dev/ic/mb86960.c: revision 1.86
sys/dev/ic/mtd803.c: revision 1.34
sys/dev/ic/pdq_ifsubr.c: revision 1.59
sys/dev/ic/rrunner.c: revision 1.86
sys/dev/ic/seeq8005.c: revision 1.58
sys/dev/ic/sgec.c: revision 1.47
sys/dev/ic/smc90cx6.c: revision 1.72
sys/dev/ic/smc91cxx.c: revision 1.96
sys/dev/ic/tropic.c: revision 1.49
sys/dev/ic/wi.c: revision 1.245
sys/dev/isa/if_eg.c: revision 1.93
sys/dev/isa/if_el.c: revision 1.95
sys/dev/isa/if_iy.c: revision 1.101
sys/dev/ofw/ofnet.c: revision 1.58
sys/dev/pci/if_alc.c: revision 1.27
sys/dev/pci/if_de.c: revision 1.152
sys/dev/pci/if_fpa.c: revision 1.61
sys/dev/pci/if_jme.c: revision 1.34
sys/dev/pci/if_tl.c: revision 1.108
sys/dev/pci/if_vte.c: revision 1.19
sys/dev/pci/ixgbe/ixgbe.h: revision 1.50
sys/dev/pcmcia/if_cnw.c: revision 1.62
sys/dev/pcmcia/if_malo_pcmcia.c: revision 1.17
sys/dev/pcmcia/if_ray.c: revision 1.89
sys/dev/pcmcia/if_xi.c: revision 1.81
sys/dev/pcmcia/mhzc.c: revision 1.51
sys/dev/pcmcia/xirc.c: revision 1.34
sys/dev/qbus/if_de.c: revision 1.33
sys/dev/qbus/if_qe.c: revision 1.78
sys/dev/qbus/if_qt.c: revision 1.22
sys/dev/sbus/be.c: revision 1.87
sys/dev/sbus/qe.c: revision 1.68
sys/dev/scsipi/if_se.c: revision 1.96
sys/dev/usb/if_atu.c: revision 1.59
sys/net/if_l2tp.c: revision 1.28 via patch
sys/net/if_ppp.c: revision 1.160
It's not required to include net/bpfdesc.h. Remove it.
--
Simplify like other drivers. NULL check of ifp->if_bpf is done in
bpf_mtap(), so it's not required to do it here.
--
Remove duplicated inclusion of net/bpf.h.
--
Remove duplicated inclusion of net/bpf.h.
--
Simplify bpf_mtap() call. No functional change.
 1.53.2.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.53.2.1 10-Jun-2019  christos Sync with HEAD
 1.59.2.1 29-Feb-2020  ad Sync with head.
 1.60.30.1 02-Aug-2025  perseant Sync with HEAD
 1.16 24-Jun-2023  msaitoh Fix typo in comment.
 1.15 22-May-2022  andvar fix various small typos, mainly in comments.
 1.14 08-Apr-2020  msaitoh Correctly spell "count".
 1.13 28-Apr-2008  martin branches: 1.13.88;
Remove clause 3 and 4 from TNF licenses
 1.12 11-Dec-2005  christos branches: 1.12.70; 1.12.72; 1.12.74;
merge ktrace-lwp.
 1.11 02-Nov-2003  wiz Fix some typos. From Tom Cosgrove via jmc@openbsd.
 1.10 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22364, verified by myself.
 1.9 03-Sep-2002  thorpej branches: 1.9.6;
Fix the PARTID for the original 79c970, from Dave Barnes, kern/18029.
 1.8 18-Sep-2001  wiz branches: 1.8.12;
Give initiali[sz]e all the "i"s it deserves.
 1.7 24-Aug-2001  thorpej branches: 1.7.2;
More useful definitions for CSR80.
 1.6 21-Aug-2001  thorpej Add some more PCnet-PCI registers.
 1.5 20-Aug-2001  itojun typo
 1.4 18-Aug-2001  thorpej Add Chip ID register values for various AMD PCnet parts.
 1.3 17-Feb-2000  thorpej branches: 1.3.6; 1.3.8;
Add a whole slew of registers found in the PCnet-PCI family.
 1.2 15-Aug-1998  mycroft branches: 1.2.12;
Assign my copyrights to TNF.
 1.1 21-Jul-1998  drochner Split the LANCE driver into a part specific to the classic chip with
24-bit DMA addresses, and an independant part.
Implement support for the 32-bit mode in the newer (79c9xx) chips.
 1.2.12.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.3.8.3 06-Sep-2002  jdolecek sync kqueue branch with HEAD
 1.3.8.2 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.3.8.1 25-Aug-2001  thorpej Merge Aug 24 -current into the kqueue branch.
 1.3.6.3 17-Sep-2002  nathanw Catch up to -current.
 1.3.6.2 21-Sep-2001  nathanw Catch up to -current.
 1.3.6.1 24-Aug-2001  nathanw Catch up with -current.
 1.7.2.1 01-Oct-2001  fvdl Catch up with -current.
 1.8.12.1 30-Nov-2002  he Pull up revision 1.9 (requested by thorpej in ticket #766):
Fix the PARTID for the original 79c970. Fixes PR#18029.
 1.9.6.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.9.6.2 18-Sep-2004  skrll Sync with HEAD.
 1.9.6.1 03-Aug-2004  skrll Sync with HEAD
 1.12.74.1 16-May-2008  yamt sync with head.
 1.12.72.1 18-May-2008  yamt sync with head.
 1.12.70.1 02-Jun-2008  mjf Sync with HEAD.
 1.13.88.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.16 13-Apr-2015  riastradh Convert sys/dev to use <sys/rndsource.h>.
 1.15 02-Feb-2012  tls branches: 1.15.6; 1.15.24;
Entropy-pool implementation move and cleanup.

1) Move core entropy-pool code and source/sink/sample management code
to sys/kern from sys/dev.

2) Remove use of NRND as test for presence of entropy-pool code throughout
source tree.

3) Remove use of RND_ENABLED in device drivers as microoptimization to
avoid expensive operations on disabled entropy sources; make the
rnd_add calls do this directly so all callers benefit.

4) Fix bug in recent rnd_add_data()/rnd_add_uint32() changes that might
have lead to slight entropy overestimation for some sources.

5) Add new source types for environmental sensors, power sensors, VM
system events, and skew between clocks, with a sample implementation
for each.

ok releng to go in before the branch due to the difficulty of later
pullup (widespread #ifdef removal and moved files). Tested with release
builds on amd64 and evbarm and live testing on amd64.
 1.14 19-Nov-2011  tls branches: 1.14.2;
First step of random number subsystem rework described in
<20111022023242.BA26F14A158@mail.netbsd.org>. This change includes
the following:

An initial cleanup and minor reorganization of the entropy pool
code in sys/dev/rnd.c and sys/dev/rndpool.c. Several bugs are
fixed. Some effort is made to accumulate entropy more quickly at
boot time.

A generic interface, "rndsink", is added, for stream generators to
request that they be re-keyed with good quality entropy from the pool
as soon as it is available.

The arc4random()/arc4randbytes() implementation in libkern is
adjusted to use the rndsink interface for rekeying, which helps
address the problem of low-quality keys at boot time.

An implementation of the FIPS 140-2 statistical tests for random
number generator quality is provided (libkern/rngtest.c). This
is based on Greg Rose's implementation from Qualcomm.

A new random stream generator, nist_ctr_drbg, is provided. It is
based on an implementation of the NIST SP800-90 CTR_DRBG by
Henric Jungheim. This generator users AES in a modified counter
mode to generate a backtracking-resistant random stream.

An abstraction layer, "cprng", is provided for in-kernel consumers
of randomness. The arc4random/arc4randbytes API is deprecated for
in-kernel use. It is replaced by "cprng_strong". The current
cprng_fast implementation wraps the existing arc4random
implementation. The current cprng_strong implementation wraps the
new CTR_DRBG implementation. Both interfaces are rekeyed from
the entropy pool automatically at intervals justifiable from best
current cryptographic practice.

In some quick tests, cprng_fast() is about the same speed as
the old arc4randbytes(), and cprng_strong() is about 20% faster
than rnd_extract_data(). Performance is expected to improve.

The AES code in src/crypto/rijndael is no longer an optional
kernel component, as it is required by cprng_strong, which is
not an optional kernel component.

The entropy pool output is subjected to the rngtest tests at
startup time; if it fails, the system will reboot. There is
approximately a 3/10000 chance of a false positive from these
tests. Entropy pool _input_ from hardware random numbers is
subjected to the rngtest tests at attach time, as well as the
FIPS continuous-output test, to detect bad or stuck hardware
RNGs; if any are detected, they are detached, but the system
continues to run.

A problem with rndctl(8) is fixed -- datastructures with
pointers in arrays are no longer passed to userspace (this
was not a security problem, but rather a major issue for
compat32). A new kernel will require a new rndctl.

The sysctl kern.arandom() and kern.urandom() nodes are hooked
up to the new generators, but the /dev/*random pseudodevices
are not, yet.

Manual pages for the new kernel interfaces are forthcoming.
 1.13 04-Sep-2009  tsutsui branches: 1.13.12;
Replace shutdownhook_establish(9) with pmf_device_register1(9).
Tested on sun3x.
 1.12 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.11 04-Apr-2008  tsutsui branches: 1.11.2; 1.11.4;
Split device_t/softc for le(4) and variants and misc cosmetic changes.
 1.10 11-Dec-2005  christos branches: 1.10.70;
merge ktrace-lwp.
 1.9 27-Feb-2005  perry nuke trailing whitespace
 1.8 04-Feb-2005  perry de-__P
 1.7 13-Feb-2004  wiz branches: 1.7.8; 1.7.10;
Uppercase CPU, plural is CPUs.
 1.6 29-Jun-2003  fvdl branches: 1.6.2;
Back out the lwp/ktrace changes. They contained a lot of colateral damage,
and need to be examined and discussed more.
 1.5 29-Jun-2003  jdolecek cosmetic - make sc_supmedia of struct lance_softc const
 1.4 18-Jun-2001  jdolecek Convert to use ether_ioctl() for SIOCSIFADDR and SIOCSIFFLAGS.
 1.3 28-Sep-2000  tsutsui branches: 1.3.2;
6 -> ETHER_ADDR_LEN
 1.2 15-Aug-1998  mycroft branches: 1.2.12;
Assign my copyrights to TNF.
 1.1 21-Jul-1998  drochner Split the LANCE driver into a part specific to the classic chip with
24-bit DMA addresses, and an independant part.
Implement support for the 32-bit mode in the newer (79c9xx) chips.
 1.2.12.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.3.2.1 21-Jun-2001  nathanw Catch up to -current.
 1.6.2.5 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.6.2.4 04-Feb-2005  skrll Sync with HEAD.
 1.6.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.6.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.6.2.1 03-Aug-2004  skrll Sync with HEAD
 1.7.10.2 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.7.10.1 12-Feb-2005  yamt sync with head.
 1.7.8.1 29-Apr-2005  kent sync with -current
 1.10.70.1 02-Jun-2008  mjf Sync with HEAD.
 1.11.4.2 16-Sep-2009  yamt sync with head
 1.11.4.1 16-May-2008  yamt sync with head.
 1.11.2.1 18-May-2008  yamt sync with head.
 1.13.12.1 17-Apr-2012  yamt sync with head
 1.14.2.1 18-Feb-2012  mrg merge to -current.
 1.15.24.1 06-Jun-2015  skrll Sync with HEAD
 1.15.6.1 03-Dec-2017  jdolecek update from HEAD
 1.7 14-May-2011  rmind Convert to mutex(9). Replace ltsleep with mtsleep.
 1.6 14-Mar-2009  dsl branches: 1.6.4; 1.6.6;
Change about 4500 of the K&R function definitions to ANSI ones.
There are still about 1600 left, but they have ',' or /* ... */
in the actual variable definitions - which my awk script doesn't handle.
There are also many that need () -> (void).
(The script does handle misordered arguments.)
 1.5 19-Oct-2007  ad branches: 1.5.20; 1.5.28; 1.5.34;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.4 11-Dec-2005  christos branches: 1.4.30; 1.4.44; 1.4.46; 1.4.50;
merge ktrace-lwp.
 1.3 27-Feb-2005  perry branches: 1.3.4;
nuke trailing whitespace
 1.2 20-Jan-2003  soren branches: 1.2.2; 1.2.10; 1.2.12;
Typo.
 1.1 20-Jan-2003  soren Attachment for the HD44780 display and keypad on the front of Cobalt machines.
 1.2.12.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.2.10.1 29-Apr-2005  kent sync with -current
 1.2.2.1 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.3.4.1 27-Oct-2007  yamt sync with head.
 1.4.50.1 25-Oct-2007  bouyer Sync with HEAD.
 1.4.46.1 06-Nov-2007  matt sync with HEAD
 1.4.44.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.4.30.1 23-Oct-2007  ad Sync with head.
 1.5.34.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.5.28.1 28-Apr-2009  skrll Sync with HEAD.
 1.5.20.1 04-May-2009  yamt sync with head.
 1.6.6.1 06-Jun-2011  jruoho Sync with HEAD.
 1.6.4.1 31-May-2011  rmind sync with head
 1.3 14-May-2011  rmind Convert to mutex(9). Replace ltsleep with mtsleep.
 1.2 23-Jun-2003  martin branches: 1.2.128; 1.2.134;
Make sure to include opt_foo.h if a defflag option FOO is used.
 1.1 20-Jan-2003  soren Attachment for the HD44780 display and keypad on the front of Cobalt machines.
 1.2.134.1 06-Jun-2011  jruoho Sync with HEAD.
 1.2.128.1 31-May-2011  rmind sync with head
 1.33 21-Oct-2025  pgoyette Give these a chance of building - avoid ST_NODEV redefinition
 1.32 13-Apr-2025  rin ld(4): Convert blkno argument for sc_dump() to daddr_t

PR kern/59153

(1) For backends that accept 64-bit block address, i.e.,
nvme(4), virtio(4), aac(4), iop(4), and mainbus(usermode/4),
this should enable to dump beyond 2Gi blocks.

(2) sdmmc(4) backend allows to dump up to the last block.

(3) For other backends, block address is handled as `int`.
Some of them may support blocks up to 4Gi, but I do not have
enough time to examine datasheets. So, continue to reject >2Gi
blocks as before.

XXX
This is KABI change, and cannot be pulled up into netbsd-{10,9}.

XXX
Compile-test only (for amd64/ALL) due to lack of large SSDs ;)

Thanks mlelstv@ for discussion and careful review!!
 1.31 30-Jul-2022  mlelstv branches: 1.31.10;
aprint_error_dev is for autoconfig messages, use device_printf instead.
 1.30 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).
 1.29 16-Sep-2016  jdolecek modify ldattach() to have default strategy as a parameter
 1.28 13-Apr-2015  riastradh branches: 1.28.2;
Convert sys/dev to use <sys/rndsource.h>.
 1.27 27-Oct-2012  chs branches: 1.27.14;
split device_t/softc for all remaining drivers.
replace "struct device *" with "device_t".
use device_xname(), device_unit(), etc.
 1.26 02-Feb-2012  tls branches: 1.26.6;
Entropy-pool implementation move and cleanup.

1) Move core entropy-pool code and source/sink/sample management code
to sys/kern from sys/dev.

2) Remove use of NRND as test for presence of entropy-pool code throughout
source tree.

3) Remove use of RND_ENABLED in device drivers as microoptimization to
avoid expensive operations on disabled entropy sources; make the
rnd_add calls do this directly so all callers benefit.

4) Fix bug in recent rnd_add_data()/rnd_add_uint32() changes that might
have lead to slight entropy overestimation for some sources.

5) Add new source types for environmental sensors, power sensors, VM
system events, and skew between clocks, with a sample implementation
for each.

ok releng to go in before the branch due to the difficulty of later
pullup (widespread #ifdef removal and moved files). Tested with release
builds on amd64 and evbarm and live testing on amd64.
 1.25 13-Nov-2010  uebayasi branches: 1.25.8; 1.25.12;
Don't pull in the whole uvm(9) API to access only PAGE_SIZE and
some other constants. These are provided by sys/param.h now.
 1.24 27-Jul-2010  jakllsch Rework debug printf invocation to not fail on LP64 so easily.
 1.23 12-May-2009  cegger branches: 1.23.2; 1.23.4;
struct device * -> device_t, no functional changes intended.
 1.22 02-Oct-2008  sborrill branches: 1.22.8;
Add support for >2TB arrays and implement raw I/O mode which is a
requirement for this.

N.B. Still to do - move dump on ld to 64-bit disk addresses
 1.21 09-Sep-2008  tron Complete device_t/softc split for the ld(4) attachments. This should
prevent crashes while attaching a drive.

Patch supplied by Juan RP in PR kern/39468.
 1.20 30-Apr-2008  ad branches: 1.20.2; 1.20.6;
Make various bits of debug code compile again.
 1.19 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.18 08-Apr-2008  cegger branches: 1.18.2; 1.18.4;
use aprint_*_dev and device_xname
 1.17 19-Oct-2007  ad branches: 1.17.16;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.16 29-Jul-2007  ad branches: 1.16.4; 1.16.6; 1.16.10; 1.16.12;
It's not a good idea for device drivers to modify b_flags, as they don't
need to understand the locking around that field. Instead of setting
B_ERROR, set b_error instead. b_error is 'owned' by whoever completes
the I/O request.
 1.15 05-Jun-2007  briggs branches: 1.15.2;
Bring in changes from FreeBSD...
* Allocate commands on-demand.
* Update a bunch of constants and some structures.
* Use __attribute__ ((__packed__)) instead of __packed to be consistent.
* Support more commands for devices that can apparently handle them.
* Support a "new comm. interface" present in more recent Adaptec
firmware. This reduces the amount of PCI bus traffic in handling
commands.
* Support larger commands going to the adapter--if the adapter can
support them.
* Support 64-bit commands for archs where sizeof(bus_addr_t) > 4 and
for adapters that advertise SGMAP64.
* Handle the WINDOW4G option and NO4GB quirk by excluding 2G-4G window
unless we have the WINDOW4G capability without the NO4GB quirk.
* Ask the adapter more about its capabilities and try to use those if
they seem sane.
* Do our bus_dmamap_sync() inside dequeue_fib instead of following,
since we have the information that we need there.
* Provide access functions for some adapters that I haven't seen yet
(MIPS-based "Rocket" adapters). Not yet used.
 1.14 26-May-2007  briggs Clear interrupt status at once instead of piecemeal.
Enable a few more bits in the I/O requested by ld and check for the fast
response bit when reading back from the queue.
Both changes come from reading the FreeBSD driver and testing on a Dell
CERC SATA controller.
 1.13 16-Nov-2006  christos branches: 1.13.2; 1.13.8; 1.13.10; 1.13.16;
__unused removal on arguments; approved by core.
 1.12 12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.11 25-Mar-2006  thorpej branches: 1.11.8; 1.11.10;
Use device_parent().
 1.10 29-Jan-2006  jdolecek branches: 1.10.2; 1.10.4; 1.10.6; 1.10.8; 1.10.10;
add cast to compile with AAC_DPRINTF
 1.9 11-Dec-2005  christos branches: 1.9.2;
merge ktrace-lwp.
 1.8 27-Feb-2005  perry branches: 1.8.4;
nuke trailing whitespace
 1.7 08-Feb-2005  briggs Use aprint_*() instead of printf() at attach time.
 1.6 28-Oct-2004  yamt branches: 1.6.4; 1.6.6;
move buffer queue related stuffs from buf.h to their own header, bufq.h.
 1.5 02-Oct-2002  thorpej branches: 1.5.6;
Add trailing ; to CFATTACH_DECL.
 1.4 30-Sep-2002  thorpej Use CFATTACH_DECL().
 1.3 27-Sep-2002  thorpej Declare all cfattach structures const.
 1.2 02-May-2002  ad branches: 1.2.6; 1.2.8;
Fix pasto.
 1.1 26-Apr-2002  ad Add a driver for Adaptec FSA RAID controllers, as often found in Dell
servers. Based on the FreeBSD/OpenBSD versions.
 1.2.8.3 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.2.8.2 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.2.8.1 02-May-2002  jdolecek file ld_aac.c was added on branch kqueue on 2002-06-23 17:46:41 +0000
 1.2.6.3 18-Oct-2002  nathanw Catch up to -current.
 1.2.6.2 20-Jun-2002  nathanw Catch up to -current.
 1.2.6.1 02-May-2002  nathanw file ld_aac.c was added on branch nathanw_sa on 2002-06-20 03:44:54 +0000
 1.5.6.3 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.5.6.2 09-Feb-2005  skrll Sync with HEAD.
 1.5.6.1 02-Nov-2004  skrll Sync with HEAD.
 1.6.6.2 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.6.6.1 12-Feb-2005  yamt sync with head.
 1.6.4.1 29-Apr-2005  kent sync with -current
 1.8.4.4 27-Oct-2007  yamt sync with head.
 1.8.4.3 03-Sep-2007  yamt sync with head.
 1.8.4.2 30-Dec-2006  yamt sync with head.
 1.8.4.1 21-Jun-2006  yamt sync with head.
 1.9.2.1 01-Feb-2006  yamt sync with head.
 1.10.10.1 28-Mar-2006  tron Merge 2006-03-28 NetBSD-current into the "peter-altq" branch.
 1.10.8.1 19-Apr-2006  elad sync with head.
 1.10.6.1 01-Apr-2006  yamt sync with head.
 1.10.4.1 22-Apr-2006  simonb Sync with head.
 1.10.2.1 09-Sep-2006  rpaulo sync with head
 1.11.10.2 10-Dec-2006  yamt sync with head.
 1.11.10.1 22-Oct-2006  yamt sync with head
 1.11.8.1 18-Nov-2006  ad Sync with head.
 1.13.16.1 06-Jan-2008  wrstuden Catch up to netbsd-4.0 release.
 1.13.10.1 11-Jul-2007  mjf Sync with head.
 1.13.8.5 23-Oct-2007  ad Sync with head.
 1.13.8.4 19-Aug-2007  ad - Back out the biodone() changes.
- Eliminate B_ERROR (from HEAD).
 1.13.8.3 09-Jun-2007  ad Sync with head.
 1.13.8.2 27-May-2007  ad Sync with head.
 1.13.8.1 13-May-2007  ad - Pass the error number and residual count to biodone(), and let it handle
setting error indicators. Prepare to eliminate B_ERROR.
- Add a flag argument to brelse() to be set into the buf's flags, instead
of doing it directly. Typically used to set B_INVAL.
- Add a "struct cpu_info *" argument to kthread_create(), to be used to
create bound threads. Change "bool mpsafe" to "int flags".
- Allow exit of LWPs in the IDL state when (l != curlwp).
- More locking fixes & conversion to the new API.
 1.13.2.2 03-Oct-2008  jdc Pull up revisions:
src/sys/dev/ic/aac.c 1.41 via patch
src/sys/dev/ic/aacreg.h 1.13 via patch
src/sys/dev/ic/aacvar.h 1.13 via patch
src/sys/dev/ic/ld_aac.c 1.22 via patch
(requested by sborrill in ticket #1208).
 1.13.2.1 25-Nov-2007  xtraeme Pull up following revision(s) (requested by briggs in ticket #990):
sys/dev/ic/aac_tables.h: revision 1.5 (patch)
sys/dev/ic/aac.c: revision 1.31 (patch)
sys/dev/ic/aac.c: revision 1.32 (patch)
sys/dev/ic/aac.c: revision 1.33 (patch)
sys/dev/ic/aac.c: revision 1.34 (patch)
sys/arch/amd64/conf/INSTALL: revision 1.70 (patch)
sys/dev/ic/aac.c: revision 1.37 (patch)
sys/dev/ic/aacreg.h: revision 1.6 (patch)
sys/dev/ic/aacreg.h: revision 1.7 (patch)
sys/dev/ic/aacreg.h: revision 1.8 (patch)
sys/dev/ic/aacreg.h: revision 1.9 (patch)
sys/dev/pci/aac_pci.c: revision 1.21 (patch)
sys/dev/ic/aacvar.h: revision 1.10 (patch)
sys/dev/ic/aacvar.h: revision 1.9 (patch)
sys/arch/amd64/conf/GENERIC: revision 1.144 (patch)
sys/dev/ic/ld_aac.c: revision 1.14 (patch)
sys/dev/ic/ld_aac.c: revision 1.15 (patch)
Compile and run on amd64 and on >2GB RAM.
 1.15.2.1 15-Aug-2007  skrll Sync with HEAD.
 1.16.12.2 29-Jul-2007  ad It's not a good idea for device drivers to modify b_flags, as they don't
need to understand the locking around that field. Instead of setting
B_ERROR, set b_error instead. b_error is 'owned' by whoever completes
the I/O request.
 1.16.12.1 29-Jul-2007  ad file ld_aac.c was added on branch matt-mips64 on 2007-07-29 12:50:21 +0000
 1.16.10.1 25-Oct-2007  bouyer Sync with HEAD.
 1.16.6.1 06-Nov-2007  matt sync with HEAD
 1.16.4.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.17.16.3 05-Oct-2008  mjf Sync with HEAD.
 1.17.16.2 28-Sep-2008  mjf Sync with HEAD.
 1.17.16.1 02-Jun-2008  mjf Sync with HEAD.
 1.18.4.4 11-Aug-2010  yamt sync with head.
 1.18.4.3 16-May-2009  yamt sync with head
 1.18.4.2 04-May-2009  yamt sync with head.
 1.18.4.1 16-May-2008  yamt sync with head.
 1.18.2.1 18-May-2008  yamt sync with head.
 1.20.6.1 19-Oct-2008  haad Sync with HEAD.
 1.20.2.2 10-Oct-2008  skrll Sync with HEAD.
 1.20.2.1 24-Sep-2008  wrstuden Merge in changes between wrstuden-revivesa-base-2 and
wrstuden-revivesa-base-3.
 1.22.8.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.23.4.1 05-Mar-2011  rmind sync with head
 1.23.2.1 17-Aug-2010  uebayasi Sync with HEAD.
 1.25.12.1 18-Feb-2012  mrg merge to -current.
 1.25.8.2 30-Oct-2012  yamt sync with head
 1.25.8.1 17-Apr-2012  yamt sync with head
 1.26.6.2 03-Dec-2017  jdolecek update from HEAD
 1.26.6.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.27.14.2 05-Oct-2016  skrll Sync with HEAD
 1.27.14.1 06-Jun-2015  skrll Sync with HEAD
 1.28.2.1 04-Nov-2016  pgoyette Sync with HEAD
 1.31.10.1 02-Aug-2025  perseant Sync with HEAD
 1.32 13-Apr-2025  rin ld(4): Convert blkno argument for sc_dump() to daddr_t

PR kern/59153

(1) For backends that accept 64-bit block address, i.e.,
nvme(4), virtio(4), aac(4), iop(4), and mainbus(usermode/4),
this should enable to dump beyond 2Gi blocks.

(2) sdmmc(4) backend allows to dump up to the last block.

(3) For other backends, block address is handled as `int`.
Some of them may support blocks up to 4Gi, but I do not have
enough time to examine datasheets. So, continue to reject >2Gi
blocks as before.

XXX
This is KABI change, and cannot be pulled up into netbsd-{10,9}.

XXX
Compile-test only (for amd64/ALL) due to lack of large SSDs ;)

Thanks mlelstv@ for discussion and careful review!!
 1.31 09-Aug-2017  mlelstv branches: 1.31.42;
While ld(4) is MP safe, many backends are not.

Add a flag for backends that are MP safe. Take KERNEL_LOCK when calling
into a backend that doesn't have the flag set. Do the same for the
discard routine.

Fixes PR 52462.
 1.30 27-Sep-2016  pgoyette branches: 1.30.8;
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).
 1.29 16-Sep-2016  jdolecek modify ldattach() to have default strategy as a parameter
 1.28 13-Apr-2015  riastradh branches: 1.28.2;
Convert sys/dev to use <sys/rndsource.h>.
 1.27 24-Feb-2012  mhitch branches: 1.27.2; 1.27.16;
Reserve a CCB for the driver. Stops the annoying cac0: unable to alloc CCB
messages.
 1.26 02-Feb-2012  tls branches: 1.26.2;
Entropy-pool implementation move and cleanup.

1) Move core entropy-pool code and source/sink/sample management code
to sys/kern from sys/dev.

2) Remove use of NRND as test for presence of entropy-pool code throughout
source tree.

3) Remove use of RND_ENABLED in device drivers as microoptimization to
avoid expensive operations on disabled entropy sources; make the
rnd_add calls do this directly so all callers benefit.

4) Fix bug in recent rnd_add_data()/rnd_add_uint32() changes that might
have lead to slight entropy overestimation for some sources.

5) Add new source types for environmental sensors, power sensors, VM
system events, and skew between clocks, with a sample implementation
for each.

ok releng to go in before the branch due to the difficulty of later
pullup (widespread #ifdef removal and moved files). Tested with release
builds on amd64 and evbarm and live testing on amd64.
 1.25 12-May-2009  cegger branches: 1.25.12; 1.25.16;
struct device * -> device_t, no functional changes intended.
 1.24 21-Mar-2009  ad Fix the *third* break to this driver from sloppy device_t conversion.
 1.23 04-Dec-2008  ad branches: 1.23.4;
PR kern/40099 device_t/softc split broke cac(4)/ld(4): panic: iostat_unbusy
 1.22 09-Sep-2008  tron branches: 1.22.2; 1.22.4;
Complete device_t/softc split for the ld(4) attachments. This should
prevent crashes while attaching a drive.

Patch supplied by Juan RP in PR kern/39468.
 1.21 28-Apr-2008  martin branches: 1.21.2; 1.21.6;
Remove clause 3 and 4 from TNF licenses
 1.20 08-Apr-2008  cegger branches: 1.20.2; 1.20.4;
use aprint_*_dev and device_xname
 1.19 19-Oct-2007  ad branches: 1.19.16;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.18 29-Jul-2007  ad branches: 1.18.4; 1.18.6; 1.18.10; 1.18.12;
It's not a good idea for device drivers to modify b_flags, as they don't
need to understand the locking around that field. Instead of setting
B_ERROR, set b_error instead. b_error is 'owned' by whoever completes
the I/O request.
 1.17 09-Feb-2007  ad branches: 1.17.6; 1.17.14;
Merge newlock2 to head.
 1.16 28-Nov-2006  ad Improve error handling. Related to PR/21900.
 1.15 16-Nov-2006  christos __unused removal on arguments; approved by core.
 1.14 12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.13 25-Mar-2006  thorpej branches: 1.13.8; 1.13.10;
Use device_parent().
 1.12 11-Dec-2005  christos branches: 1.12.4; 1.12.6; 1.12.8; 1.12.10; 1.12.12;
merge ktrace-lwp.
 1.11 27-Feb-2005  perry branches: 1.11.4;
nuke trailing whitespace
 1.10 08-Feb-2005  briggs Use aprint_*() instead of printf() at attach time.
 1.9 28-Oct-2004  yamt branches: 1.9.4; 1.9.6;
move buffer queue related stuffs from buf.h to their own header, bufq.h.
 1.8 02-Oct-2002  thorpej branches: 1.8.6;
Add trailing ; to CFATTACH_DECL.
 1.7 30-Sep-2002  thorpej Use CFATTACH_DECL().
 1.6 27-Sep-2002  thorpej Declare all cfattach structures const.
 1.5 25-Jan-2002  ad - Always validate the return value read from the outbound FIFO.
- Copy access method info into the softc so we don't double dereference.
- Remove static on functions.
 1.4 13-Nov-2001  lukem add/cleanup RCSID
 1.3 10-Jun-2001  ad branches: 1.3.2; 1.3.8;
Centralise the geometry fudge.
 1.2 11-Dec-2000  ad branches: 1.2.2;
Report soft-errors-per-unit once per minute at most.
 1.1 26-Nov-2000  ad branches: 1.1.2;
lsu -> ld, by popular request.
 1.1.2.3 13-Dec-2000  bouyer Sync with HEAD (for UBC fixes).
 1.1.2.2 08-Dec-2000  bouyer Sync with HEAD.
 1.1.2.1 26-Nov-2000  bouyer file ld_cac.c was added on branch thorpej_scsipi on 2000-12-08 09:12:23 +0000
 1.2.2.4 18-Oct-2002  nathanw Catch up to -current.
 1.2.2.3 28-Feb-2002  nathanw Catch up to -current.
 1.2.2.2 14-Nov-2001  nathanw Catch up to -current.
 1.2.2.1 21-Jun-2001  nathanw Catch up to -current.
 1.3.8.3 29-Jan-2002  he Pull up revision 1.5 (requested by ad):
Some fixes:
o Always validate return value read from outbound FIFO
o Copy access method into to softc to avoid double dereference
o Remove static on functions
Fixes PR#14453.
 1.3.8.2 25-Oct-2001  he Pull up revisions 1.1-1.3 (requested by ad):
Add Mylex DACC960, CAC-EISA, and I2O block/SCSI drivers.
 1.3.8.1 10-Jun-2001  he file ld_cac.c was added on branch netbsd-1-5 on 2001-10-25 17:54:04 +0000
 1.3.2.3 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.3.2.2 11-Feb-2002  jdolecek Sync w/ -current.
 1.3.2.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.8.6.3 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.8.6.2 09-Feb-2005  skrll Sync with HEAD.
 1.8.6.1 02-Nov-2004  skrll Sync with HEAD.
 1.9.6.2 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.9.6.1 12-Feb-2005  yamt sync with head.
 1.9.4.1 29-Apr-2005  kent sync with -current
 1.11.4.5 27-Oct-2007  yamt sync with head.
 1.11.4.4 03-Sep-2007  yamt sync with head.
 1.11.4.3 26-Feb-2007  yamt sync with head.
 1.11.4.2 30-Dec-2006  yamt sync with head.
 1.11.4.1 21-Jun-2006  yamt sync with head.
 1.12.12.1 28-Mar-2006  tron Merge 2006-03-28 NetBSD-current into the "peter-altq" branch.
 1.12.10.1 19-Apr-2006  elad sync with head.
 1.12.8.1 01-Apr-2006  yamt sync with head.
 1.12.6.1 22-Apr-2006  simonb Sync with head.
 1.12.4.1 09-Sep-2006  rpaulo sync with head
 1.13.10.2 10-Dec-2006  yamt sync with head.
 1.13.10.1 22-Oct-2006  yamt sync with head
 1.13.8.3 15-Jan-2007  ad MP locking.
 1.13.8.2 12-Jan-2007  ad Sync with head.
 1.13.8.1 18-Nov-2006  ad Sync with head.
 1.17.14.1 15-Aug-2007  skrll Sync with HEAD.
 1.17.6.3 23-Oct-2007  ad Sync with head.
 1.17.6.2 19-Aug-2007  ad - Back out the biodone() changes.
- Eliminate B_ERROR (from HEAD).
 1.17.6.1 13-May-2007  ad - Pass the error number and residual count to biodone(), and let it handle
setting error indicators. Prepare to eliminate B_ERROR.
- Add a flag argument to brelse() to be set into the buf's flags, instead
of doing it directly. Typically used to set B_INVAL.
- Add a "struct cpu_info *" argument to kthread_create(), to be used to
create bound threads. Change "bool mpsafe" to "int flags".
- Allow exit of LWPs in the IDL state when (l != curlwp).
- More locking fixes & conversion to the new API.
 1.18.12.2 29-Jul-2007  ad It's not a good idea for device drivers to modify b_flags, as they don't
need to understand the locking around that field. Instead of setting
B_ERROR, set b_error instead. b_error is 'owned' by whoever completes
the I/O request.
 1.18.12.1 29-Jul-2007  ad file ld_cac.c was added on branch matt-mips64 on 2007-07-29 12:50:21 +0000
 1.18.10.1 25-Oct-2007  bouyer Sync with HEAD.
 1.18.6.1 06-Nov-2007  matt sync with HEAD
 1.18.4.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.19.16.3 17-Jan-2009  mjf Sync with HEAD.
 1.19.16.2 28-Sep-2008  mjf Sync with HEAD.
 1.19.16.1 02-Jun-2008  mjf Sync with HEAD.
 1.20.4.3 16-May-2009  yamt sync with head
 1.20.4.2 04-May-2009  yamt sync with head.
 1.20.4.1 16-May-2008  yamt sync with head.
 1.20.2.1 18-May-2008  yamt sync with head.
 1.21.6.2 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.21.6.1 19-Oct-2008  haad Sync with HEAD.
 1.21.2.1 24-Sep-2008  wrstuden Merge in changes between wrstuden-revivesa-base-2 and
wrstuden-revivesa-base-3.
 1.22.4.2 24-Mar-2009  snj Pull up following revision(s) (requested by ad in ticket #599):
sys/dev/ic/ld_cac.c: revision 1.24
Fix the *third* break to this driver from sloppy device_t conversion.
 1.22.4.1 13-Dec-2008  bouyer Pull up following revision(s) (requested by mhitch in ticket #186):
sys/dev/ic/ld_cac.c: revision 1.23
PR kern/40099 device_t/softc split broke cac(4)/ld(4): panic: iostat_unbusy
 1.22.2.2 28-Apr-2009  skrll Sync with HEAD.
 1.22.2.1 19-Jan-2009  skrll Sync with HEAD.
 1.23.4.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.25.16.2 04-Mar-2012  mrg sync to latest -current.
 1.25.16.1 18-Feb-2012  mrg merge to -current.
 1.25.12.1 17-Apr-2012  yamt sync with head
 1.26.2.1 09-May-2012  riz Pull up following revision(s) (requested by macallan in ticket #240):
sys/dev/ic/ld_cac.c: revision 1.27
Reserve a CCB for the driver. Stops the annoying cac0: unable to alloc CCB
messages.
 1.27.16.3 28-Aug-2017  skrll Sync with HEAD
 1.27.16.2 05-Oct-2016  skrll Sync with HEAD
 1.27.16.1 06-Jun-2015  skrll Sync with HEAD
 1.27.2.1 03-Dec-2017  jdolecek update from HEAD
 1.28.2.1 04-Nov-2016  pgoyette Sync with HEAD
 1.30.8.1 01-Sep-2017  martin Pull up following revision(s) (requested by mlelstv in ticket #261):
sys/dev/sdmmc/ld_sdmmc.c: revision 1.32
sys/dev/sdmmc/ld_sdmmc.c: revision 1.33
sys/dev/sdmmc/ld_sdmmc.c: revision 1.34
sys/dev/sdmmc/sdmmc_mem.c: revision 1.62
sys/dev/i2o/ld_iop.c: revision 1.39
sys/dev/ld.c: revision 1.102
sys/dev/ld.c: revision 1.103
sys/dev/dksubr.c: revision 1.98
sys/dev/dksubr.c: revision 1.99
sys/dev/sdmmc/sdmmcvar.h: revision 1.29
sys/dev/ic/ld_nvme.c: revision 1.17
sys/dev/ldvar.h: revision 1.31
sys/dev/ldvar.h: revision 1.32
sys/dev/ic/ld_cac.c: revision 1.31
sys/dev/pci/ld_virtio.c: revision 1.16
While ld(4) is MP safe, many backends are not.
Add a flag for backends that are MP safe. Take KERNEL_LOCK when calling
into a backend that doesn't have the flag set. Do the same for the
discard routine.
Fixes PR 52462.
Defer sdmmc discard operations to the sdmmc task queue. Fixes a panic
introduced by ld.c r1.102.
validate length for discard operation and split operation when byte length
doesn't fit into 'int'.
make the sc_discard interface for the ld backend asynchronous and
signal completion through new callback lddiscardend. Use a standard
struct buf to pass disk address and range instead of two off_t values.
make lddiscard synchronous again. This is a requirement of the current
ffs discard code.
Initialize error also in the case where len=0, which just succeeds.
while here, assert that the len is indeed non-negative. this is already
confirmed by sys_fdiscard, but let's be sure.
reported by: GCC, but with different compile flags
 1.31.42.1 02-Aug-2025  perseant Sync with HEAD
 1.33 13-Apr-2025  rin ld(4): Convert blkno argument for sc_dump() to daddr_t

PR kern/59153

(1) For backends that accept 64-bit block address, i.e.,
nvme(4), virtio(4), aac(4), iop(4), and mainbus(usermode/4),
this should enable to dump beyond 2Gi blocks.

(2) sdmmc(4) backend allows to dump up to the last block.

(3) For other backends, block address is handled as `int`.
Some of them may support blocks up to 4Gi, but I do not have
enough time to examine datasheets. So, continue to reject >2Gi
blocks as before.

XXX
This is KABI change, and cannot be pulled up into netbsd-{10,9}.

XXX
Compile-test only (for amd64/ALL) due to lack of large SSDs ;)

Thanks mlelstv@ for discussion and careful review!!
 1.32 14-Aug-2020  chs branches: 1.32.26;
fix a bit that I missed in the device_t/softc split 8 years ago.
 1.31 27-Feb-2017  jdolecek refactor the ld(4) DIOCCACHESYNC hook into general ioctl hook, so that attachments
would be able to implement arbitrary other ioctls
 1.30 26-Feb-2017  jdolecek mark local functions static, similar to other ld(4) attachments
 1.29 27-Sep-2016  pgoyette branches: 1.29.2;
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).
 1.28 16-Sep-2016  jdolecek modify ldattach() to have default strategy as a parameter
 1.27 13-Apr-2015  riastradh branches: 1.27.2;
Convert sys/dev to use <sys/rndsource.h>.
 1.26 27-Oct-2012  chs branches: 1.26.14;
split device_t/softc for all remaining drivers.
replace "struct device *" with "device_t".
use device_xname(), device_unit(), etc.
 1.25 02-Feb-2012  tls branches: 1.25.6;
Entropy-pool implementation move and cleanup.

1) Move core entropy-pool code and source/sink/sample management code
to sys/kern from sys/dev.

2) Remove use of NRND as test for presence of entropy-pool code throughout
source tree.

3) Remove use of RND_ENABLED in device drivers as microoptimization to
avoid expensive operations on disabled entropy sources; make the
rnd_add calls do this directly so all callers benefit.

4) Fix bug in recent rnd_add_data()/rnd_add_uint32() changes that might
have lead to slight entropy overestimation for some sources.

5) Add new source types for environmental sensors, power sensors, VM
system events, and skew between clocks, with a sample implementation
for each.

ok releng to go in before the branch due to the difficulty of later
pullup (widespread #ifdef removal and moved files). Tested with release
builds on amd64 and evbarm and live testing on amd64.
 1.24 13-Nov-2010  uebayasi branches: 1.24.8; 1.24.12;
Don't pull in the whole uvm(9) API to access only PAGE_SIZE and
some other constants. These are provided by sys/param.h now.
 1.23 29-Jan-2009  bouyer branches: 1.23.6;
One more device_t/softc split fallout (a missing device_private()).
 1.22 09-Sep-2008  tron branches: 1.22.2; 1.22.4;
Complete device_t/softc split for the ld(4) attachments. This should
prevent crashes while attaching a drive.

Patch supplied by Juan RP in PR kern/39468.
 1.21 11-Aug-2008  simonb Add a flags argument to the ld(4) flush handlers, and call these with a
"poll" flag when called from ld_shutdown().

This is the infrastructure part of kern/38655 - in itself it doesn't
fix the panic referenced in that PR.

XXX: At least ld_twa.c and perhaps ld_iop.c and ld_icp.c need to
check for this new poll flag and do something useful.
 1.20 28-Apr-2008  martin branches: 1.20.2; 1.20.4; 1.20.6;
Remove clause 3 and 4 from TNF licenses
 1.19 08-Apr-2008  cegger branches: 1.19.2; 1.19.4;
use aprint_*_dev and device_xname
 1.18 19-Oct-2007  ad branches: 1.18.16;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.17 29-Jul-2007  ad branches: 1.17.4; 1.17.6; 1.17.10; 1.17.12;
It's not a good idea for device drivers to modify b_flags, as they don't
need to understand the locking around that field. Instead of setting
B_ERROR, set b_error instead. b_error is 'owned' by whoever completes
the I/O request.
 1.16 16-Nov-2006  christos branches: 1.16.8; 1.16.18;
__unused removal on arguments; approved by core.
 1.15 12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.14 28-Mar-2006  thorpej branches: 1.14.8; 1.14.10;
Use device_unit().
 1.13 25-Mar-2006  thorpej Use device_parent().
 1.12 11-Dec-2005  christos branches: 1.12.4; 1.12.6; 1.12.8; 1.12.10; 1.12.12;
merge ktrace-lwp.
 1.11 27-Feb-2005  perry branches: 1.11.4;
nuke trailing whitespace
 1.10 08-Feb-2005  briggs Use aprint_*() instead of printf() at attach time.
 1.9 28-Oct-2004  yamt branches: 1.9.4; 1.9.6;
move buffer queue related stuffs from buf.h to their own header, bufq.h.
 1.8 13-Jun-2003  thorpej branches: 1.8.2;
Add support for dynamic rescan of cache service logical drives, using
the ioctl issued by the ICP RAID management libraries (used by the
storcon and iirconfig tools). This requires some infrastructure changes:
* Add a "service callback" mechanism that the ld driver (cache service)
and the iopsp driver (raw service) can register with the icp parent.
Right now this callback allows the children to adjust their notion of
how many command openings are available.
* Add a mutex around the icp ioctl handler, allowing only one thread
to execute an ioctl at a time.
* Add a way to freeze the controller command queue. We stop all I/O
while processing rescans (due to the semantics of icp_cmd()).
* Make icp_cmd() work when !cold.
* Add detach support to ld@icp.
 1.7 07-Jun-2003  thorpej Always queue transfers in the ld driver to prevent transient resource
shortages in the back-ends from aborting transfers.

Reviewed by ad@.
 1.6 13-May-2003  thorpej Add support for the user-generated command interface and event logging
required by the ICP-Vortex management tools. Many thanks to Achim Leubner
at ICP-Vortex for a few bug fixes and for testing.
 1.5 02-Oct-2002  thorpej Add trailing ; to CFATTACH_DECL.
 1.4 30-Sep-2002  thorpej Use CFATTACH_DECL().
 1.3 27-Sep-2002  thorpej Declare all cfattach structures const.
 1.2 31-May-2002  thorpej branches: 1.2.2; 1.2.4;
Remove an unnecessary printf argument.
 1.1 22-Apr-2002  ad branches: 1.1.2; 1.1.4;
Add a driver for ICP-Vortex GDT and Intel Storage RAID controllers. Parts
taken from OpenBSD. Test hardware kindly provided by Intel. This still needs
management bits, and doesn't support older controllers, but that shouldn't
be hard to fix.
 1.1.4.1 12-Sep-2003  tron Pull up revision 1.2 (requested by martti in ticket #1458):
Remove an unnecessary printf argument.
 1.1.2.1 20-Jun-2002  gehenna catch up with -current.
 1.2.4.3 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.2.4.2 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.2.4.1 31-May-2002  jdolecek file ld_icp.c was added on branch kqueue on 2002-06-23 17:46:41 +0000
 1.2.2.3 18-Oct-2002  nathanw Catch up to -current.
 1.2.2.2 20-Jun-2002  nathanw Catch up to -current.
 1.2.2.1 31-May-2002  nathanw file ld_icp.c was added on branch nathanw_sa on 2002-06-20 03:44:54 +0000
 1.8.2.3 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.8.2.2 09-Feb-2005  skrll Sync with HEAD.
 1.8.2.1 02-Nov-2004  skrll Sync with HEAD.
 1.9.6.2 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.9.6.1 12-Feb-2005  yamt sync with head.
 1.9.4.1 29-Apr-2005  kent sync with -current
 1.11.4.4 27-Oct-2007  yamt sync with head.
 1.11.4.3 03-Sep-2007  yamt sync with head.
 1.11.4.2 30-Dec-2006  yamt sync with head.
 1.11.4.1 21-Jun-2006  yamt sync with head.
 1.12.12.2 31-Mar-2006  tron Merge 2006-03-31 NetBSD-current into the "peter-altq" branch.
 1.12.12.1 28-Mar-2006  tron Merge 2006-03-28 NetBSD-current into the "peter-altq" branch.
 1.12.10.1 19-Apr-2006  elad sync with head.
 1.12.8.1 01-Apr-2006  yamt sync with head.
 1.12.6.1 22-Apr-2006  simonb Sync with head.
 1.12.4.1 09-Sep-2006  rpaulo sync with head
 1.14.10.2 10-Dec-2006  yamt sync with head.
 1.14.10.1 22-Oct-2006  yamt sync with head
 1.14.8.1 18-Nov-2006  ad Sync with head.
 1.16.18.1 15-Aug-2007  skrll Sync with HEAD.
 1.16.8.3 23-Oct-2007  ad Sync with head.
 1.16.8.2 19-Aug-2007  ad - Back out the biodone() changes.
- Eliminate B_ERROR (from HEAD).
 1.16.8.1 13-May-2007  ad - Pass the error number and residual count to biodone(), and let it handle
setting error indicators. Prepare to eliminate B_ERROR.
- Add a flag argument to brelse() to be set into the buf's flags, instead
of doing it directly. Typically used to set B_INVAL.
- Add a "struct cpu_info *" argument to kthread_create(), to be used to
create bound threads. Change "bool mpsafe" to "int flags".
- Allow exit of LWPs in the IDL state when (l != curlwp).
- More locking fixes & conversion to the new API.
 1.17.12.2 29-Jul-2007  ad It's not a good idea for device drivers to modify b_flags, as they don't
need to understand the locking around that field. Instead of setting
B_ERROR, set b_error instead. b_error is 'owned' by whoever completes
the I/O request.
 1.17.12.1 29-Jul-2007  ad file ld_icp.c was added on branch matt-mips64 on 2007-07-29 12:50:21 +0000
 1.17.10.1 25-Oct-2007  bouyer Sync with HEAD.
 1.17.6.1 06-Nov-2007  matt sync with HEAD
 1.17.4.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.18.16.2 28-Sep-2008  mjf Sync with HEAD.
 1.18.16.1 02-Jun-2008  mjf Sync with HEAD.
 1.19.4.2 04-May-2009  yamt sync with head.
 1.19.4.1 16-May-2008  yamt sync with head.
 1.19.2.1 18-May-2008  yamt sync with head.
 1.20.6.1 19-Oct-2008  haad Sync with HEAD.
 1.20.4.2 11-Jun-2008  simonb Revert my suggested fix for kern/38655 - that shouldn't have snuck in
to this branch.
 1.20.4.1 10-Jun-2008  simonb Initial commit of Wasabi System's WAPBL (Write Ahead Physical Block
Logging) journaling code. Originally written by Darrin B. Jewell
while at Wasabi and updated to -current by Antti Kantee, Andy Doran,
Greg Oster and Simon Burge.

Still a number of issues - look in doc/BRANCHES for "simonb-wapbl"
for more info.
 1.20.2.2 24-Sep-2008  wrstuden Merge in changes between wrstuden-revivesa-base-2 and
wrstuden-revivesa-base-3.
 1.20.2.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.22.4.1 02-Feb-2009  snj Pull up following revision(s) (requested by bouyer in ticket #375):
sys/dev/ic/ld_icp.c: revision 1.23
One more device_t/softc split fallout (a missing device_private()).
 1.22.2.1 03-Mar-2009  skrll Sync with HEAD.
 1.23.6.1 05-Mar-2011  rmind sync with head
 1.24.12.1 18-Feb-2012  mrg merge to -current.
 1.24.8.2 30-Oct-2012  yamt sync with head
 1.24.8.1 17-Apr-2012  yamt sync with head
 1.25.6.2 03-Dec-2017  jdolecek update from HEAD
 1.25.6.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.26.14.3 28-Aug-2017  skrll Sync with HEAD
 1.26.14.2 05-Oct-2016  skrll Sync with HEAD
 1.26.14.1 06-Jun-2015  skrll Sync with HEAD
 1.27.2.2 20-Mar-2017  pgoyette Sync with HEAD
 1.27.2.1 04-Nov-2016  pgoyette Sync with HEAD
 1.29.2.1 21-Apr-2017  bouyer Sync with HEAD
 1.32.26.1 02-Aug-2025  perseant Sync with HEAD
 1.24 13-Apr-2025  rin ld(4): Convert blkno argument for sc_dump() to daddr_t

PR kern/59153

(1) For backends that accept 64-bit block address, i.e.,
nvme(4), virtio(4), aac(4), iop(4), and mainbus(usermode/4),
this should enable to dump beyond 2Gi blocks.

(2) sdmmc(4) backend allows to dump up to the last block.

(3) For other backends, block address is handled as `int`.
Some of them may support blocks up to 4Gi, but I do not have
enough time to examine datasheets. So, continue to reject >2Gi
blocks as before.

XXX
This is KABI change, and cannot be pulled up into netbsd-{10,9}.

XXX
Compile-test only (for amd64/ALL) due to lack of large SSDs ;)

Thanks mlelstv@ for discussion and careful review!!
 1.23 27-Sep-2016  pgoyette branches: 1.23.54;
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).
 1.22 16-Sep-2016  jdolecek modify ldattach() to have default strategy as a parameter
 1.21 13-Apr-2015  riastradh branches: 1.21.2;
Convert sys/dev to use <sys/rndsource.h>.
 1.20 02-Feb-2012  tls branches: 1.20.6; 1.20.24;
Entropy-pool implementation move and cleanup.

1) Move core entropy-pool code and source/sink/sample management code
to sys/kern from sys/dev.

2) Remove use of NRND as test for presence of entropy-pool code throughout
source tree.

3) Remove use of RND_ENABLED in device drivers as microoptimization to
avoid expensive operations on disabled entropy sources; make the
rnd_add calls do this directly so all callers benefit.

4) Fix bug in recent rnd_add_data()/rnd_add_uint32() changes that might
have lead to slight entropy overestimation for some sources.

5) Add new source types for environmental sensors, power sensors, VM
system events, and skew between clocks, with a sample implementation
for each.

ok releng to go in before the branch due to the difficulty of later
pullup (widespread #ifdef removal and moved files). Tested with release
builds on amd64 and evbarm and live testing on amd64.
 1.19 16-Jan-2009  mhitch branches: 1.19.14; 1.19.18;
Another missed part of the device_t/softc split. Fixes ld(4) devices
on mlx(4) controller.
 1.18 09-Sep-2008  tron branches: 1.18.2; 1.18.4;
Complete device_t/softc split for the ld(4) attachments. This should
prevent crashes while attaching a drive.

Patch supplied by Juan RP in PR kern/39468.
 1.17 28-Apr-2008  martin branches: 1.17.2; 1.17.6;
Remove clause 3 and 4 from TNF licenses
 1.16 08-Apr-2008  cegger branches: 1.16.2; 1.16.4;
use aprint_*_dev and device_xname
 1.15 19-Oct-2007  ad branches: 1.15.16;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.14 29-Jul-2007  ad branches: 1.14.4; 1.14.6; 1.14.10; 1.14.12;
It's not a good idea for device drivers to modify b_flags, as they don't
need to understand the locking around that field. Instead of setting
B_ERROR, set b_error instead. b_error is 'owned' by whoever completes
the I/O request.
 1.13 16-Nov-2006  christos branches: 1.13.8; 1.13.18;
__unused removal on arguments; approved by core.
 1.12 12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.11 25-Mar-2006  thorpej branches: 1.11.8; 1.11.10;
Use device_parent().
 1.10 11-Dec-2005  christos branches: 1.10.4; 1.10.6; 1.10.8; 1.10.10; 1.10.12;
merge ktrace-lwp.
 1.9 08-Feb-2005  briggs branches: 1.9.6;
Use aprint_*() instead of printf() at attach time.
 1.8 28-Oct-2004  yamt branches: 1.8.4; 1.8.6;
move buffer queue related stuffs from buf.h to their own header, bufq.h.
 1.7 02-Oct-2002  thorpej branches: 1.7.6;
Add trailing ; to CFATTACH_DECL.
 1.6 30-Sep-2002  thorpej Use CFATTACH_DECL().
 1.5 27-Sep-2002  thorpej Declare all cfattach structures const.
 1.4 26-Aug-2002  ad Handle aincent firmware as found on EISA/MCA boards. Untested.
 1.3 13-Nov-2001  lukem branches: 1.3.8; 1.3.10;
add/cleanup RCSID
 1.2 10-Jun-2001  ad branches: 1.2.2; 1.2.8;
Centralise the geometry fudge.
 1.1 04-Feb-2001  ad branches: 1.1.2; 1.1.4;
Add a driver for the Mylex DAC960 family (including DEC SWXCR).
 1.1.4.4 18-Oct-2002  nathanw Catch up to -current.
 1.1.4.3 27-Aug-2002  nathanw Catch up to -current.
 1.1.4.2 14-Nov-2001  nathanw Catch up to -current.
 1.1.4.1 21-Jun-2001  nathanw Catch up to -current.
 1.1.2.2 11-Feb-2001  bouyer Sync with HEAD.
 1.1.2.1 04-Feb-2001  bouyer file ld_mlx.c was added on branch thorpej_scsipi on 2001-02-11 19:15:32 +0000
 1.2.8.2 25-Oct-2001  he Pull up revisions 1.1-1.2 (requested by ad):
Add Mylex DACC960, CAC-EISA, and I2O block/SCSI drivers.
 1.2.8.1 10-Jun-2001  he file ld_mlx.c was added on branch netbsd-1-5 on 2001-10-25 17:53:47 +0000
 1.2.2.3 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.2.2.2 06-Sep-2002  jdolecek sync kqueue branch with HEAD
 1.2.2.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.3.10.1 28-Jul-2003  he Pull up revision 1.4 (requested by ad in ticket #1128):
Improve stability of the mlx driver.
o Better handling of old firmware
o Use correct mailbox length, fixes PR#14266
 1.3.8.1 29-Aug-2002  gehenna catch up with -current.
 1.7.6.2 09-Feb-2005  skrll Sync with HEAD.
 1.7.6.1 02-Nov-2004  skrll Sync with HEAD.
 1.8.6.1 12-Feb-2005  yamt sync with head.
 1.8.4.1 29-Apr-2005  kent sync with -current
 1.9.6.4 27-Oct-2007  yamt sync with head.
 1.9.6.3 03-Sep-2007  yamt sync with head.
 1.9.6.2 30-Dec-2006  yamt sync with head.
 1.9.6.1 21-Jun-2006  yamt sync with head.
 1.10.12.1 28-Mar-2006  tron Merge 2006-03-28 NetBSD-current into the "peter-altq" branch.
 1.10.10.1 19-Apr-2006  elad sync with head.
 1.10.8.1 01-Apr-2006  yamt sync with head.
 1.10.6.1 22-Apr-2006  simonb Sync with head.
 1.10.4.1 09-Sep-2006  rpaulo sync with head
 1.11.10.2 10-Dec-2006  yamt sync with head.
 1.11.10.1 22-Oct-2006  yamt sync with head
 1.11.8.1 18-Nov-2006  ad Sync with head.
 1.13.18.1 15-Aug-2007  skrll Sync with HEAD.
 1.13.8.3 23-Oct-2007  ad Sync with head.
 1.13.8.2 19-Aug-2007  ad - Back out the biodone() changes.
- Eliminate B_ERROR (from HEAD).
 1.13.8.1 13-May-2007  ad - Pass the error number and residual count to biodone(), and let it handle
setting error indicators. Prepare to eliminate B_ERROR.
- Add a flag argument to brelse() to be set into the buf's flags, instead
of doing it directly. Typically used to set B_INVAL.
- Add a "struct cpu_info *" argument to kthread_create(), to be used to
create bound threads. Change "bool mpsafe" to "int flags".
- Allow exit of LWPs in the IDL state when (l != curlwp).
- More locking fixes & conversion to the new API.
 1.14.12.2 29-Jul-2007  ad It's not a good idea for device drivers to modify b_flags, as they don't
need to understand the locking around that field. Instead of setting
B_ERROR, set b_error instead. b_error is 'owned' by whoever completes
the I/O request.
 1.14.12.1 29-Jul-2007  ad file ld_mlx.c was added on branch matt-mips64 on 2007-07-29 12:50:21 +0000
 1.14.10.1 25-Oct-2007  bouyer Sync with HEAD.
 1.14.6.1 06-Nov-2007  matt sync with HEAD
 1.14.4.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.15.16.3 17-Jan-2009  mjf Sync with HEAD.
 1.15.16.2 28-Sep-2008  mjf Sync with HEAD.
 1.15.16.1 02-Jun-2008  mjf Sync with HEAD.
 1.16.4.2 04-May-2009  yamt sync with head.
 1.16.4.1 16-May-2008  yamt sync with head.
 1.16.2.1 18-May-2008  yamt sync with head.
 1.17.6.1 19-Oct-2008  haad Sync with HEAD.
 1.17.2.1 24-Sep-2008  wrstuden Merge in changes between wrstuden-revivesa-base-2 and
wrstuden-revivesa-base-3.
 1.18.4.1 16-Jan-2009  bouyer Pull up following revision(s) (requested by mhitch in ticket #275):
sys/dev/ic/ld_mlx.c: revision 1.19
Another missed part of the device_t/softc split. Fixes ld(4) devices
on mlx(4) controller.
 1.18.2.1 19-Jan-2009  skrll Sync with HEAD.
 1.19.18.1 18-Feb-2012  mrg merge to -current.
 1.19.14.1 17-Apr-2012  yamt sync with head
 1.20.24.2 05-Oct-2016  skrll Sync with HEAD
 1.20.24.1 06-Jun-2015  skrll Sync with HEAD
 1.20.6.1 03-Dec-2017  jdolecek update from HEAD
 1.21.2.1 04-Nov-2016  pgoyette Sync with HEAD
 1.23.54.1 02-Aug-2025  perseant Sync with HEAD
 1.26 13-Apr-2025  rin ld(4): Convert blkno argument for sc_dump() to daddr_t

PR kern/59153

(1) For backends that accept 64-bit block address, i.e.,
nvme(4), virtio(4), aac(4), iop(4), and mainbus(usermode/4),
this should enable to dump beyond 2Gi blocks.

(2) sdmmc(4) backend allows to dump up to the last block.

(3) For other backends, block address is handled as `int`.
Some of them may support blocks up to 4Gi, but I do not have
enough time to examine datasheets. So, continue to reject >2Gi
blocks as before.

XXX
This is KABI change, and cannot be pulled up into netbsd-{10,9}.

XXX
Compile-test only (for amd64/ALL) due to lack of large SSDs ;)

Thanks mlelstv@ for discussion and careful review!!
 1.25 30-Jul-2022  mlelstv branches: 1.25.10;
aprint_error_dev is for autoconfig messages, use device_printf instead.
 1.24 22-Sep-2020  kardel PR kern/55674:
move name space availability check from ld_nvme.c:ld_nvme_attach()
to nvme.c:nvme_rescan().
this avoids allocation of ld(4) instances for every possible
name space, even if it is not usable. it also reduces the device
node flood generated from that strategy.
 1.23 01-Oct-2019  mlelstv Don't attach an ld device if the format descriptor is unsupported/unused.
 1.22 26-Apr-2019  mlelstv branches: 1.22.2;
Expose device type. You can query it with e.g. drvctl -p ld0 disk-info/type.

Missing in previous commit.
 1.21 01-Dec-2018  jdolecek support DIOCSCACHE + DKCACHE_WRITE if volatile write cache is present

fix the Get Features call for DIOCGCACHE to actually retrieve the current
value properly
 1.20 18-Apr-2018  nonaka branches: 1.20.2;
nvmectl(8): Add big-endian support.

from FreeBSD nvmecontolr(8) r329824.
 1.19 16-Mar-2018  jdolecek refactor the locking code around DIOCGCACHE handling to be reusable
for other infrequent commands

it uses single condvar for simplicity, and uses it both when waiting
for ccb or command completion - this is fine, since usually there
will be just one such command qeueued anyway

use this to finally properly implement DIOCCACHESYNC - return only after
the command is confirmed as completed by the controller
 1.18 23-Jan-2018  pgoyette branches: 1.18.2;
Add "bufq_fcfs" requirement to all those driver modules that explicitly
request it in their calls to bufq_alloc().
 1.17 09-Aug-2017  mlelstv branches: 1.17.2;
While ld(4) is MP safe, many backends are not.

Add a flag for backends that are MP safe. Take KERNEL_LOCK when calling
into a backend that doesn't have the flag set. Do the same for the
discard routine.

Fixes PR 52462.
 1.16 27-Apr-2017  jdolecek branches: 1.16.2;
do not attach nvme ld as randomness source - device is too fast, it overwhelms
the rndq handling code, and causes system crashes; gathering rnd there is
also bad idea from performance perspective
 1.15 05-Apr-2017  jdolecek branches: 1.15.4;
expose disk device FUA/DPO support via DIOCGCACHE, and allow the flags
to be set for I/O; implement support in sd(4) and nvme(4)

discussed on tech-kern
 1.14 28-Feb-2017  jdolecek change DIOCCACHESYNC to not issue the FLUSH command at all when the controller
has no volatile write cache
 1.13 28-Feb-2017  jdolecek implement DIOCGCACHE
 1.12 27-Feb-2017  jdolecek remote extra pasted line
 1.11 27-Feb-2017  jdolecek refactor the ld(4) DIOCCACHESYNC hook into general ioctl hook, so that attachments
would be able to implement arbitrary other ioctls
 1.10 01-Nov-2016  jdolecek branches: 1.10.2;
pass maxphys from device rather then assuming MAXPHYS; it's clipped in ld(4)
if bigger then MAXPHYS

multiply the queue size by number of queues for ld(4) sc_maxqueuecnt, so
that ld_diskstart() would try to use full capacity, instead of throttling
to one queue worth of commands
 1.9 20-Oct-2016  jdolecek revert rev. 1.7 - seems the polling damages command queue on live system
 1.8 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).
 1.7 20-Sep-2016  jdolecek cache flush call must wait for completion; cap wait to 60 seconds just in case
controller won't respond
 1.6 19-Sep-2016  jdolecek on further thought, just remove the separately allocated nvme_ns_context
altogether and fold into nvme_ccb; allocating this separately just isn't useful
 1.5 18-Sep-2016  jdolecek must use PR_NOWAIT also during ldattach()/dkwedge discover, our i/o is there
called with a spin lock held, which triggers LOCKDEBUG panic
 1.4 18-Sep-2016  jdolecek fix several bugs, make nvme(4) MPSAFE by default and also bump default
number of ioq from 128 to 1024; tested with VirtualBox and QEMU

* remove NVME_INTMC/NVME_INTMS writes in hw intr handler as this is not MPSAFE,
fortunately they don't seem to be necessary; shaves two register writes
* need to use full mutex_enter() in nvme_q_complete(), to avoid small
race between one handler exiting the loop and another entering
* for MSI, handover the command result processing to softintr; unfortunately
can't easily do that for INTx interrupts as they require doorbell write
to deassert
* unlock/relock q->q_cq_mtx before calling ccb_done to avoid potential deadlocks
* make sure to destroy queue mutexes when destroying the queue (LOCKDEBUG)
* make ns ctx pool per-device, so that it's deallocated properly on module
unload
* handle ctx allocation failure in ld_nvme_dobio()
* remove splbio() calls in ld_nvme_dobio() and sync, the paths are exercised
only for dump/shutdown, and that already disables interrupts
* free the ns ctx in ld_nvme_biodone() before calling lddone() to avoid
memory starvation, as lddone() can trigger another i/o request
* be more careful with using PR_WAITOK, the paths are called from interrupt
context and there we can't wait
 1.3 16-Sep-2016  jdolecek change nvme(4) ld to use fcfs as default strategy to lower i/o processing
overhead and hence lower latency; the sorting doesn't provide any benefit
for SSDs
 1.2 16-Sep-2016  jdolecek modify ldattach() to have default strategy as a parameter
 1.1 01-May-2016  nonaka branches: 1.1.2; 1.1.4;
Added nvme(4) for Non-Volatile Memory Host Controller Interface devices.
Ported from OpenBSD.
 1.1.4.3 26-Apr-2017  pgoyette Sync with HEAD
 1.1.4.2 20-Mar-2017  pgoyette Sync with HEAD
 1.1.4.1 04-Nov-2016  pgoyette Sync with HEAD
 1.1.2.5 28-Aug-2017  skrll Sync with HEAD
 1.1.2.4 05-Dec-2016  skrll Sync with HEAD
 1.1.2.3 05-Oct-2016  skrll Sync with HEAD
 1.1.2.2 29-May-2016  skrll Sync with HEAD
 1.1.2.1 01-May-2016  skrll file ld_nvme.c was added on branch nick-nhusb on 2016-05-29 08:44:21 +0000
 1.10.2.1 21-Apr-2017  bouyer Sync with HEAD
 1.15.4.1 02-May-2017  pgoyette Sync with HEAD - tag prg-localcount2-base1
 1.16.2.5 27-Sep-2020  martin Pull up following revision(s) (requested by kardel in ticket #1610):

sys/dev/ic/ld_nvme.c: revision 1.24 (patch)
sys/dev/ic/nvme.c: revision 1.50 (patch)

PR kern/55674:
move name space availability check from ld_nvme.c:ld_nvme_attach()
to nvme.c:nvme_rescan().
this avoids allocation of ld(4) instances for every possible
name space, even if it is not usable. it also reduces the device
node flood generated from that strategy.
 1.16.2.4 28-Oct-2019  martin Pull up following revision(s) (requested by mlelstv in ticket #1417):

sys/dev/ic/ld_nvme.c: revision 1.23

Don't attach an ld device if the format descriptor is unsupported/unused.
 1.16.2.3 19-Apr-2018  martin Pull up following revision(s) (requested by nonaka in ticket #781):

sbin/nvmectl/Makefile 1.4
sbin/nvmectl/bignum.c 1.2
sbin/nvmectl/devlist.c 1.3-1.5
sbin/nvmectl/firmware.c 1.3,1.4
sbin/nvmectl/identify.c 1.3-1.5
sbin/nvmectl/logpage.c 1.5-1.7
sbin/nvmectl/nvme.h 1.3
sbin/nvmectl/nvmectl.8 1.5
sbin/nvmectl/nvmectl.c 1.5-1.7
sbin/nvmectl/nvmectl.h 1.5-1.8
sbin/nvmectl/perftest.c 1.3-1.5
sbin/nvmectl/power.c 1.3,1.4
sbin/nvmectl/reset.c 1.2,1.3
sbin/nvmectl/util.c 1.1,1.2
sbin/nvmectl/wdc.c 1.2-1.4
sys/dev/ic/ld_nvme.c 1.20
sys/dev/ic/nvme.c 1.38,1.39
sys/dev/ic/nvmeio.h 1.2
sys/dev/ic/nvmereg.h 1.10,1.11
sys/dev/ic/nvmevar.h 1.16
sys/dev/pci/nvme_pci.c 1.20

nvmectl(8): Sync with FreeBSD nvmecontrol(8) r328763.

nvmectl(8): fix wdc command usage.

nvme(4): Added some delay before check RDY bit quirk when disabling device.
Pick from FreeBSD nvme(4) r326937.

Add some new structure fileds, opcodes and statuses from NVMe 1.3a.

nvmectl(8): Add big-endian support.
from FreeBSD nvmecontolr(8) r329824.

nvmectl(8): fix subcommand usage.

nvmectl(8): Remove some wdc subcommands from man page.
- wdc drive-log
- wdc get-crash-dump
- wdc purge
- wdc purge-monitor

Typos.

use setprogname()/getprogname(), do not hardcode the prognam name in fixed
strings
 1.16.2.2 18-Mar-2018  martin Pull up following revision(s) (requested by jdolecek in ticket #641):
sys/dev/ic/nvme.c: revision 1.34
sys/dev/ic/nvme.c: revision 1.35
sys/dev/ic/nvme.c: revision 1.36
sys/dev/ic/nvme.c: revision 1.37
sys/dev/ic/ld_nvme.c: revision 1.19
sys/dev/ic/nvmevar.h: revision 1.15

refactor the locking code around DIOCGCACHE handling to be reusable
for other infrequent commands,it uses single condvar for simplicity,
and uses it both when waiting for ccb or command completion - this
is fine, since usually there will be just one such command qeueued anyway
use this to finally properly implement DIOCCACHESYNC - return only after
the command is confirmed as completed by the controller.

switch handling of passthrough commands to use queue, instead of polling
should fix PR kern/53059 by Frank Kardel

fix passthrough command usage also in nvme_get_number_of_queues(), fixes
memory corruption and possible panic on boot

also remove now duplicate nvme_ccb_put() call from
nvme_get_number_of_queues()
 1.16.2.1 01-Sep-2017  martin Pull up following revision(s) (requested by mlelstv in ticket #261):
sys/dev/sdmmc/ld_sdmmc.c: revision 1.32
sys/dev/sdmmc/ld_sdmmc.c: revision 1.33
sys/dev/sdmmc/ld_sdmmc.c: revision 1.34
sys/dev/sdmmc/sdmmc_mem.c: revision 1.62
sys/dev/i2o/ld_iop.c: revision 1.39
sys/dev/ld.c: revision 1.102
sys/dev/ld.c: revision 1.103
sys/dev/dksubr.c: revision 1.98
sys/dev/dksubr.c: revision 1.99
sys/dev/sdmmc/sdmmcvar.h: revision 1.29
sys/dev/ic/ld_nvme.c: revision 1.17
sys/dev/ldvar.h: revision 1.31
sys/dev/ldvar.h: revision 1.32
sys/dev/ic/ld_cac.c: revision 1.31
sys/dev/pci/ld_virtio.c: revision 1.16
While ld(4) is MP safe, many backends are not.
Add a flag for backends that are MP safe. Take KERNEL_LOCK when calling
into a backend that doesn't have the flag set. Do the same for the
discard routine.
Fixes PR 52462.
Defer sdmmc discard operations to the sdmmc task queue. Fixes a panic
introduced by ld.c r1.102.
validate length for discard operation and split operation when byte length
doesn't fit into 'int'.
make the sc_discard interface for the ld backend asynchronous and
signal completion through new callback lddiscardend. Use a standard
struct buf to pass disk address and range instead of two off_t values.
make lddiscard synchronous again. This is a requirement of the current
ffs discard code.
Initialize error also in the case where len=0, which just succeeds.
while here, assert that the len is indeed non-negative. this is already
confirmed by sys_fdiscard, but let's be sure.
reported by: GCC, but with different compile flags
 1.17.2.2 03-Dec-2017  jdolecek update from HEAD
 1.17.2.1 09-Aug-2017  jdolecek file ld_nvme.c was added on branch tls-maxphys on 2017-12-03 11:37:03 +0000
 1.18.2.3 26-Dec-2018  pgoyette Sync with HEAD, resolve a few conflicts
 1.18.2.2 22-Apr-2018  pgoyette Sync with HEAD
 1.18.2.1 22-Mar-2018  pgoyette Synch with HEAD, resolve conflicts
 1.20.2.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.20.2.1 10-Jun-2019  christos Sync with HEAD
 1.22.2.2 27-Sep-2020  martin Pull up following revision(s) (requested by kardel in ticket #1094):

sys/dev/ic/ld_nvme.c: revision 1.24
sys/dev/ic/nvme.c: revision 1.50

PR kern/55674:
move name space availability check from ld_nvme.c:ld_nvme_attach()
to nvme.c:nvme_rescan().
this avoids allocation of ld(4) instances for every possible
name space, even if it is not usable. it also reduces the device
node flood generated from that strategy.
 1.22.2.1 28-Oct-2019  martin Pull up following revision(s) (requested by mlelstv in ticket #383):

sys/dev/ic/ld_nvme.c: revision 1.23

Don't attach an ld device if the format descriptor is unsupported/unused.
 1.25.10.1 02-Aug-2025  perseant Sync with HEAD
 1.56 25-Sep-2022  thorpej Remove unnecessary include of <sys/malloc.h>.
 1.55 29-Jan-2020  thorpej Adopt <net/if_stats.h>.
 1.54 29-May-2019  msaitoh branches: 1.54.4;
Even if we don't use MII(4), use the common path of SIOC[GS]IFMEDIA in
sys/net/if_ethersubr.c if we can.
- Add ec_ifmedia into struct ethercom.
- ec_mii in struct ethercom is kept and used as it is. It might be used in
future. Note that some Ethernet drivers which _DOESN'T_ use mii(4) use
ec_mii for keeping the if_media. Those should be changed in future.
 1.53 28-May-2019  msaitoh Use ETHER_LOCK()/ETHER_UNLOCK() for all ethernet drivers to protect ec_multi*.
 1.52 23-May-2019  msaitoh -No functional change:
- KNF
- u_int*_t -> uint*_t.
 1.51 24-Apr-2019  msaitoh KNF. No functional change.
 1.50 05-Feb-2019  msaitoh Remove very old IFF_NOTRAILERS flag.
 1.49 26-Jun-2018  msaitoh branches: 1.49.2;
Implement the BPF direction filter (BIOC[GS]DIRECTION). It provides backward
compatibility with BIOC[GS]SEESENT ioctl. The userland interface is the same
as FreeBSD.

This change also fixes a bug that the direction is misunderstand on some
environment by passing the direction to bpf_mtap*() instead of checking
m->m_pkthdr.rcvif.
 1.48 23-May-2017  ozaki-r branches: 1.48.8;
Apply deferred if_start to more drivers

And annotate some XXX_start as it runs in softint to clarify that
it doesn't need deferred if_start.
 1.47 15-Dec-2016  ozaki-r Move bpf_mtap and if_ipackets++ on Rx of each driver to percpuq if_input

The benefits of the change are:
- We can reduce codes
- We can provide the same behavior between drivers
- Where/When if_ipackets is counted up
- Note that some drivers still update packet statistics in their own
way (periodical update)
- Moved bpf_mtap run in softint
- This makes it easy to MP-ify bpf

Proposed on tech-kern and tech-net
 1.46 06-Dec-2016  ozaki-r Don't check if the frame is for us in the driver

It's done normally by ether_input now. And also if drop packets here,
bridge(4) doesn't work with the driver.
 1.45 10-Jun-2016  ozaki-r branches: 1.45.2;
Introduce m_set_rcvif and m_reset_rcvif

The API is used to set (or reset) a received interface of a mbuf.
They are counterpart of m_get_rcvif, which will come in another
commit, hide internal of rcvif operation, and reduce the diff of
the upcoming change.

No functional change.
 1.44 09-Feb-2016  ozaki-r Introduce softint-based if_input

This change intends to run the whole network stack in softint context
(or normal LWP), not hardware interrupt context. Note that the work is
still incomplete by this change; to that end, we also have to softint-ify
if_link_state_change (and bpf) which can still run in hardware interrupt.

This change softint-ifies at ifp->if_input that is called from
each device driver (and ieee80211_input) to ensure Layer 2 runs
in softint (e.g., ether_input and bridge_input). To this end,
we provide a framework (called percpuq) that utlizes softint(9)
and percpu ifqueues. With this patch, rxintr of most drivers just
queues received packets and schedules a softint, and the softint
dequeues packets and does rest packet processing.

To minimize changes to each driver, percpuq is allocated in struct
ifnet for now and that is initialized by default (in if_attach).
We probably have to move percpuq to softc of each driver, but it's
future work. At this point, only wm(4) has percpuq in its softc
as a reference implementation.

Additional information including performance numbers can be found
in the thread at tech-kern@ and tech-net@:
http://mail-index.netbsd.org/tech-kern/2016/01/14/msg019997.html

Acknowledgment: riastradh@ greatly helped this work.
Thank you very much!
 1.43 13-Apr-2015  riastradh Convert sys/dev to use <sys/rndsource.h>.
 1.42 10-Aug-2014  tls branches: 1.42.4;
Merge tls-earlyentropy branch into HEAD.
 1.41 27-Oct-2012  chs branches: 1.41.10;
split device_t/softc for all remaining drivers.
replace "struct device *" with "device_t".
use device_xname(), device_unit(), etc.
 1.40 02-Feb-2012  tls branches: 1.40.6;
Entropy-pool implementation move and cleanup.

1) Move core entropy-pool code and source/sink/sample management code
to sys/kern from sys/dev.

2) Remove use of NRND as test for presence of entropy-pool code throughout
source tree.

3) Remove use of RND_ENABLED in device drivers as microoptimization to
avoid expensive operations on disabled entropy sources; make the
rnd_add calls do this directly so all callers benefit.

4) Fix bug in recent rnd_add_data()/rnd_add_uint32() changes that might
have lead to slight entropy overestimation for some sources.

5) Add new source types for environmental sensors, power sensors, VM
system events, and skew between clocks, with a sample implementation
for each.

ok releng to go in before the branch due to the difficulty of later
pullup (widespread #ifdef removal and moved files). Tested with release
builds on amd64 and evbarm and live testing on amd64.
 1.39 13-Nov-2010  uebayasi branches: 1.39.8; 1.39.12;
Don't pull in the whole uvm(9) API to access only PAGE_SIZE and
some other constants. These are provided by sys/param.h now.
 1.38 05-Apr-2010  joerg Push the bpf_ops usage back into bpf.h. Push the common ifp->if_bpf
check into the inline functions as well the fourth argument for
bpf_attach.
 1.37 19-Jan-2010  pooka branches: 1.37.2; 1.37.4;
Redefine bpf linkage through an always present op vector, i.e.
#if NBPFILTER is no longer required in the client. This change
doesn't yet add support for loading bpf as a module, since drivers
can register before bpf is attached. However, callers of bpf can
now be modularized.

Dynamically loadable bpf could probably be done fairly easily with
coordination from the stub driver and the real driver by registering
attachments in the stub before the real driver is loaded and doing
a handoff. ... and I'm not going to ponder the depths of unload
here.

Tested with i386/MONOLITHIC, modified MONOLITHIC without bpf and rump.
 1.36 07-Nov-2008  dyoung *** Summary ***

When a link-layer address changes (e.g., ifconfig ex0 link
02:de:ad:be:ef:02 active), send a gratuitous ARP and/or a Neighbor
Advertisement to update the network-/link-layer address bindings
on our LAN peers.

Refuse a change of ethernet address to the address 00:00:00:00:00:00
or to any multicast/broadcast address. (Thanks matt@.)

Reorder ifnet ioctl operations so that driver ioctls may inherit
the functions of their "class"---ether_ioctl(), fddi_ioctl(), et
cetera---and the class ioctls may inherit from the generic ioctl,
ifioctl_common(), but both driver- and class-ioctls may override
the generic behavior. Make network drivers share more code.

Distinguish a "factory" link-layer address from others for the
purposes of both protecting that address from deletion and computing
EUI64.

Return consistent, appropriate error codes from network drivers.

Improve readability. KNF.

*** Details ***

In if_attach(), always initialize the interface ioctl routine,
ifnet->if_ioctl, if the driver has not already initialized it.
Delete if_ioctl == NULL tests everywhere else, because it cannot
happen.

In the ioctl routines of network interfaces, inherit common ioctl
behaviors by calling either ifioctl_common() or whichever ioctl
routine is appropriate for the class of interface---e.g., ether_ioctl()
for ethernets.

Stop (ab)using SIOCSIFADDR and start to use SIOCINITIFADDR. In
the user->kernel interface, SIOCSIFADDR's argument was an ifreq,
but on the protocol->ifnet interface, SIOCSIFADDR's argument was
an ifaddr. That was confusing, and it would work against me as I
make it possible for a network interface to overload most ioctls.
On the protocol->ifnet interface, replace SIOCSIFADDR with
SIOCINITIFADDR. In ifioctl(), return EPERM if userland tries to
invoke SIOCINITIFADDR.

In ifioctl(), give the interface the first shot at handling most
interface ioctls, and give the protocol the second shot, instead
of the other way around. Finally, let compatibility code (COMPAT_OSOCK)
take a shot.

Pull device initialization out of switch statements under
SIOCINITIFADDR. For example, pull ..._init() out of any switch
statement that looks like this:

switch (...->sa_family) {
case ...:
..._init();
...
break;
...
default:
..._init();
...
break;
}

Rewrite many if-else clauses that handle all permutations of IFF_UP
and IFF_RUNNING to use a switch statement,

switch (x & (IFF_UP|IFF_RUNNING)) {
case 0:
...
break;
case IFF_RUNNING:
...
break;
case IFF_UP:
...
break;
case IFF_UP|IFF_RUNNING:
...
break;
}

unifdef lots of code containing #ifdef FreeBSD, #ifdef NetBSD, and
#ifdef SIOCSIFMTU, especially in fwip(4) and in ndis(4).

In ipw(4), remove an if_set_sadl() call that is out of place.

In nfe(4), reuse the jumbo MTU logic in ether_ioctl().

Let ethernets register a callback for setting h/w state such as
promiscuous mode and the multicast filter in accord with a change
in the if_flags: ether_set_ifflags_cb() registers a callback that
returns ENETRESET if the caller should reset the ethernet by calling
if_init(), 0 on success, != 0 on failure. Pull common code from
ex(4), gem(4), nfe(4), sip(4), tlp(4), vge(4) into ether_ioctl(),
and register if_flags callbacks for those drivers.

Return ENOTTY instead of EINVAL for inappropriate ioctls. In
zyd(4), use ENXIO instead of ENOTTY to indicate that the device is
not any longer attached.

Add to if_set_sadl() a boolean 'factory' argument that indicates
whether a link-layer address was assigned by the factory or some
other source. In a comment, recommend using the factory address
for generating an EUI64, and update in6_get_hw_ifid() to prefer a
factory address to any other link-layer address.

Add a routing message, RTM_LLINFO_UPD, that tells protocols to
update the binding of network-layer addresses to link-layer addresses.
Implement this message in IPv4 and IPv6 by sending a gratuitous
ARP or a neighbor advertisement, respectively. Generate RTM_LLINFO_UPD
messages on a change of an interface's link-layer address.

In ether_ioctl(), do not let SIOCALIFADDR set a link-layer address
that is broadcast/multicast or equal to 00:00:00:00:00:00.

Make ether_ioctl() call ifioctl_common() to handle ioctls that it
does not understand.

In gif(4), initialize if_softc and use it, instead of assuming that
the gif_softc and ifp overlap.

Let ifioctl_common() handle SIOCGIFADDR.

Sprinkle rtcache_invariants(), which checks on DIAGNOSTIC kernels
that certain invariants on a struct route are satisfied.

In agr(4), rewrite agr_ioctl_filter() to be a bit more explicit
about the ioctls that we do not allow on an agr(4) member interface.

bzero -> memset. Delete unnecessary casts to void *. Use
sockaddr_in_init() and sockaddr_in6_init(). Compare pointers with
NULL instead of "testing truth". Replace some instances of (type
*)0 with NULL. Change some K&R prototypes to ANSI C, and join
lines.
 1.35 08-Apr-2008  cegger branches: 1.35.4; 1.35.10; 1.35.12;
use aprint_*_dev and device_xname
 1.34 19-Oct-2007  ad branches: 1.34.16;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.33 01-Sep-2007  dyoung branches: 1.33.4;
Change a bazillion occurrences of code resembling this,

error = (cmd == SIOCADDMULTI) ?
ether_addmulti(ifr, &sc->sc_ec) :
ether_delmulti(ifr, &sc->sc_ec);

if (error == ENETRESET) {

to this,

if ((error = ether_ioctl(ifp, cmd, data)) == ENETRESET) {

which does the same thing.

(A bazillion is a very large number. This seems to make the i386
ALL kernel smaller by 3kB to 4kB.)

Use ifreq_getaddr() twice in es(4).

Whitespace nits.
 1.32 04-Mar-2007  yamt branches: 1.32.2; 1.32.10; 1.32.14; 1.32.16;
fix fallout from caddr_t changes.
 1.31 04-Mar-2007  christos Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.30 07-Sep-2006  dogcow branches: 1.30.8;
remove more vestiges of CCITT, LLC, HDLC, NS, and NSIP.
 1.29 11-Dec-2005  christos branches: 1.29.4; 1.29.8;
merge ktrace-lwp.
 1.28 30-May-2005  christos branches: 1.28.2;
- add missing const
- fix variable shadowing
- remove unneeded casts
 1.27 27-Feb-2005  perry nuke trailing whitespace
 1.26 30-Oct-2004  thorpej branches: 1.26.4; 1.26.6;
When adding/deleting multicast addresses, only whack the address
filter if the interface is marked RUNNING.

Fixes kern/27678.
 1.25 02-Nov-2003  wiz branches: 1.25.4;
Fix some typos. From Tom Cosgrove via jmc@openbsd.
 1.24 01-Oct-2003  itojun avoid out-of-bounds memory access (array size out of sync). found by
openbsd 'bound' attribute.
 1.23 13-Nov-2001  lukem branches: 1.23.16;
add/cleanup RCSID
 1.22 07-Jul-2001  thorpej branches: 1.22.2;
bzero -> memset
 1.21 07-Jul-2001  thorpej bcopy -> memcpy, strcpy
 1.20 13-Jun-2001  wiz withough -> without
 1.19 30-Apr-2001  lukem remove trigraph
 1.18 14-Dec-2000  thorpej branches: 1.18.2;
ALTQ'ify.
 1.17 15-Nov-2000  thorpej Move bpfattach()/bpfdetach() calls into ether_ifattach()/ether_ifdetach().
 1.16 01-Oct-2000  thorpej Move the check for "promisc + unicast + not for us" into ether_input(),
and change Ethernet drivers to always pass all received frames to
ether_input() (with a few exceptions, which are documented in the
code).
 1.15 28-Jun-2000  mrg remove include of <vm/vm.h>. <vm/vm.h> -> <uvm/uvm_extern.h>
 1.14 12-May-2000  thorpej Use ether_crc32_le().
 1.13 06-Mar-2000  thorpej No longer necessary to futz with ifp->if_baudrate here.
 1.12 18-May-1999  thorpej branches: 1.12.2;
Rework layer 2 protocol input routines. Instead of calling e.g. ether_input()
directly, call the function pointer (*if_input)(ifp, m). The input routine
expects the packet header to be at the head of the packet, and will adjust
as necessary. Privatize the layer 2 input and output routines, allowing
*_ifattach() to set them up as appropriate.
 1.11 28-Feb-1999  explorer branches: 1.11.4;
Update to slightly altered rnd_attach_source() api
 1.10 05-Jul-1998  jonathan branches: 1.10.6;
defopt NS, NSIP.
 1.9 05-Jul-1998  jonathan defopt INET, NETATALK.
 1.8 14-May-1998  matt Fix alignment crashes on Alphas...
 1.7 30-Mar-1998  hannken Didn't compile: add variable `bit' removed by mycroft.
 1.6 29-Mar-1998  mycroft Oops; make the table const.
 1.5 29-Mar-1998  mycroft Use a 4-bit table to speed up the CRC even further, without increasing the
code size too much.
 1.4 29-Mar-1998  mycroft Optimize the address CRC routines a bit.
 1.3 12-Jan-1998  thorpej Adjust for config changes.
 1.2 15-Oct-1997  explorer Add and/or update rnd_*() hooks
 1.1 31-Jul-1997  matt branches: 1.1.2;
The bus-independent parts needed to support the DEC
EtherWORKS III cards (LEMAC): the DE203/DE204/DE205
 1.1.2.2 23-Aug-1997  thorpej Update marc-pcmcia branch from trunk.
 1.1.2.1 31-Jul-1997  thorpej file lemac.c was added on branch marc-pcmcia on 1997-08-23 07:13:00 +0000
 1.10.6.1 11-Dec-1998  kenh The beginnings of interface detach support. Still some bugs, but mostly
works for me.

This work was originally by Bill Studenmund, and cleaned up by me.
 1.11.4.1 21-Jun-1999  thorpej Sync w/ -current.
 1.12.2.3 05-Jan-2001  bouyer Sync with HEAD
 1.12.2.2 22-Nov-2000  bouyer Sync with HEAD.
 1.12.2.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.18.2.3 14-Nov-2001  nathanw Catch up to -current.
 1.18.2.2 24-Aug-2001  nathanw Catch up with -current.
 1.18.2.1 21-Jun-2001  nathanw Catch up to -current.
 1.22.2.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.23.16.6 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.23.16.5 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.23.16.4 02-Nov-2004  skrll Sync with HEAD.
 1.23.16.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.23.16.2 18-Sep-2004  skrll Sync with HEAD.
 1.23.16.1 03-Aug-2004  skrll Sync with HEAD
 1.25.4.1 24-Jan-2005  he Pull up revision 1.26 (requested by thorpej in ticket #939):
When adding or deleting multicast addresses, only change
the address filter if the interface is marked RUNNING.
Fixes PR#27678.
 1.26.6.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.26.4.1 29-Apr-2005  kent sync with -current
 1.28.2.3 27-Oct-2007  yamt sync with head.
 1.28.2.2 03-Sep-2007  yamt sync with head.
 1.28.2.1 30-Dec-2006  yamt sync with head.
 1.29.8.1 14-Sep-2006  yamt sync with head.
 1.29.4.1 09-Sep-2006  rpaulo sync with head
 1.30.8.1 12-Mar-2007  rmind Sync with HEAD.
 1.32.16.1 06-Nov-2007  matt sync with HEAD
 1.32.14.2 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.32.14.1 03-Sep-2007  jmcneill Sync with HEAD.
 1.32.10.1 03-Sep-2007  skrll Sync with HEAD.
 1.32.2.2 23-Oct-2007  ad Sync with head.
 1.32.2.1 09-Oct-2007  ad Sync with head.
 1.33.4.1 25-Oct-2007  bouyer Sync with HEAD.
 1.34.16.2 17-Jan-2009  mjf Sync with HEAD.
 1.34.16.1 02-Jun-2008  mjf Sync with HEAD.
 1.35.12.1 19-Jan-2009  skrll Sync with HEAD.
 1.35.10.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.35.4.3 11-Aug-2010  yamt sync with head.
 1.35.4.2 11-Mar-2010  yamt sync with head
 1.35.4.1 04-May-2009  yamt sync with head.
 1.37.4.2 05-Mar-2011  rmind sync with head
 1.37.4.1 30-May-2010  rmind sync with head
 1.37.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.39.12.1 18-Feb-2012  mrg merge to -current.
 1.39.8.2 30-Oct-2012  yamt sync with head
 1.39.8.1 17-Apr-2012  yamt sync with head
 1.40.6.3 03-Dec-2017  jdolecek update from HEAD
 1.40.6.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.40.6.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.41.10.1 07-Apr-2014  tls Be a little more clear and consistent about harvesting entropy from devices:

1) deprecate RND_FLAG_NO_ESTIMATE

2) define RND_FLAG_COLLECT_TIME, RND_FLAG_COLLECT_VALUE

3) define RND_FLAG_ESTIMATE_TIME, RND_FLAG_ESTIMATE_VALUE

4) define RND_FLAG_DEFAULT: RND_FLAG_COLLECT_TIME|
RND_FLAG_COLLECT_VALUE|RND_FLAG_ESTIMATE_TIME

5) Make entropy harvesting from environmental sensors a little more generic
and remove it from individual sensor drivers.

6) Remove individual open-coded delta-estimators for values from a few
places in the tree (uvm, environmental drivers).

7) 0 -> RND_FLAG_DEFAULT, actually gather entropy from various drivers
that had stubbed out code, other minor cleanups.
 1.42.4.5 28-Aug-2017  skrll Sync with HEAD
 1.42.4.4 05-Feb-2017  skrll Sync with HEAD
 1.42.4.3 09-Jul-2016  skrll Sync with HEAD
 1.42.4.2 19-Mar-2016  skrll Sync with HEAD
 1.42.4.1 06-Jun-2015  skrll Sync with HEAD
 1.45.2.1 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.48.8.1 28-Jul-2018  pgoyette Sync with HEAD
 1.49.2.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.49.2.1 10-Jun-2019  christos Sync with HEAD
 1.54.4.1 29-Feb-2020  ad Sync with head.
 1.6 24-Jul-2021  andvar Fix all remaining typos, mainly in comments but also in few definitions and log messages, reported by me in PR kern/54889.
Also fixed some additional typos in comments, found on review of same files or typos.
 1.5 11-Dec-2005  christos branches: 1.5.182;
merge ktrace-lwp.
 1.4 27-Feb-2005  perry nuke trailing whitespace
 1.3 02-Nov-2003  wiz branches: 1.3.8; 1.3.10;
Fix some typos. From Tom Cosgrove via jmc@openbsd.
 1.2 13-Jun-2001  wiz branches: 1.2.22;
withough -> without
 1.1 31-Jul-1997  matt branches: 1.1.2; 1.1.32;
The bus-independent parts needed to support the DEC
EtherWORKS III cards (LEMAC): the DE203/DE204/DE205
 1.1.32.1 21-Jun-2001  nathanw Catch up to -current.
 1.1.2.2 23-Aug-1997  thorpej Update marc-pcmcia branch from trunk.
 1.1.2.1 31-Jul-1997  thorpej file lemacreg.h was added on branch marc-pcmcia on 1997-08-23 07:13:02 +0000
 1.2.22.4 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.2.22.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.2.22.2 18-Sep-2004  skrll Sync with HEAD.
 1.2.22.1 03-Aug-2004  skrll Sync with HEAD
 1.3.10.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.3.8.1 29-Apr-2005  kent sync with -current
 1.5.182.1 01-Aug-2021  thorpej Sync with HEAD.
 1.13 13-Apr-2015  riastradh Convert sys/dev to use <sys/rndsource.h>.
 1.12 27-Oct-2012  chs branches: 1.12.14;
split device_t/softc for all remaining drivers.
replace "struct device *" with "device_t".
use device_xname(), device_unit(), etc.
 1.11 02-Feb-2012  tls branches: 1.11.6;
Entropy-pool implementation move and cleanup.

1) Move core entropy-pool code and source/sink/sample management code
to sys/kern from sys/dev.

2) Remove use of NRND as test for presence of entropy-pool code throughout
source tree.

3) Remove use of RND_ENABLED in device drivers as microoptimization to
avoid expensive operations on disabled entropy sources; make the
rnd_add calls do this directly so all callers benefit.

4) Fix bug in recent rnd_add_data()/rnd_add_uint32() changes that might
have lead to slight entropy overestimation for some sources.

5) Add new source types for environmental sensors, power sensors, VM
system events, and skew between clocks, with a sample implementation
for each.

ok releng to go in before the branch due to the difficulty of later
pullup (widespread #ifdef removal and moved files). Tested with release
builds on amd64 and evbarm and live testing on amd64.
 1.10 19-Nov-2011  tls branches: 1.10.2;
First step of random number subsystem rework described in
<20111022023242.BA26F14A158@mail.netbsd.org>. This change includes
the following:

An initial cleanup and minor reorganization of the entropy pool
code in sys/dev/rnd.c and sys/dev/rndpool.c. Several bugs are
fixed. Some effort is made to accumulate entropy more quickly at
boot time.

A generic interface, "rndsink", is added, for stream generators to
request that they be re-keyed with good quality entropy from the pool
as soon as it is available.

The arc4random()/arc4randbytes() implementation in libkern is
adjusted to use the rndsink interface for rekeying, which helps
address the problem of low-quality keys at boot time.

An implementation of the FIPS 140-2 statistical tests for random
number generator quality is provided (libkern/rngtest.c). This
is based on Greg Rose's implementation from Qualcomm.

A new random stream generator, nist_ctr_drbg, is provided. It is
based on an implementation of the NIST SP800-90 CTR_DRBG by
Henric Jungheim. This generator users AES in a modified counter
mode to generate a backtracking-resistant random stream.

An abstraction layer, "cprng", is provided for in-kernel consumers
of randomness. The arc4random/arc4randbytes API is deprecated for
in-kernel use. It is replaced by "cprng_strong". The current
cprng_fast implementation wraps the existing arc4random
implementation. The current cprng_strong implementation wraps the
new CTR_DRBG implementation. Both interfaces are rekeyed from
the entropy pool automatically at intervals justifiable from best
current cryptographic practice.

In some quick tests, cprng_fast() is about the same speed as
the old arc4randbytes(), and cprng_strong() is about 20% faster
than rnd_extract_data(). Performance is expected to improve.

The AES code in src/crypto/rijndael is no longer an optional
kernel component, as it is required by cprng_strong, which is
not an optional kernel component.

The entropy pool output is subjected to the rngtest tests at
startup time; if it fails, the system will reboot. There is
approximately a 3/10000 chance of a false positive from these
tests. Entropy pool _input_ from hardware random numbers is
subjected to the rngtest tests at attach time, as well as the
FIPS continuous-output test, to detect bad or stuck hardware
RNGs; if any are detected, they are detached, but the system
continues to run.

A problem with rndctl(8) is fixed -- datastructures with
pointers in arrays are no longer passed to userspace (this
was not a security problem, but rather a major issue for
compat32). A new kernel will require a new rndctl.

The sysctl kern.arandom() and kern.urandom() nodes are hooked
up to the new generators, but the /dev/*random pseudodevices
are not, yet.

Manual pages for the new kernel interfaces are forthcoming.
 1.9 11-Dec-2005  christos branches: 1.9.110;
merge ktrace-lwp.
 1.8 02-Nov-2003  wiz Fix some typos. From Tom Cosgrove via jmc@openbsd.
 1.7 08-Jul-2003  itojun function prototype must not have variable name
 1.6 13-Jun-2001  wiz branches: 1.6.22;
withough -> without
 1.5 15-May-2001  lukem delint: () protect some macro args
 1.4 28-Sep-2000  tsutsui branches: 1.4.2;
6 -> ETHER_ADDR_LEN
 1.3 14-May-1998  matt branches: 1.3.6; 1.3.14;
Fix alignment crashes on Alphas...
 1.2 15-Oct-1997  explorer Add and/or update rnd_*() hooks
 1.1 31-Jul-1997  matt branches: 1.1.2;
The bus-independent parts needed to support the DEC
EtherWORKS III cards (LEMAC): the DE203/DE204/DE205
 1.1.2.2 23-Aug-1997  thorpej Update marc-pcmcia branch from trunk.
 1.1.2.1 31-Jul-1997  thorpej file lemacvar.h was added on branch marc-pcmcia on 1997-08-23 07:13:02 +0000
 1.3.14.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.3.6.1 11-Dec-1998  kenh The beginnings of interface detach support. Still some bugs, but mostly
works for me.

This work was originally by Bill Studenmund, and cleaned up by me.
 1.4.2.1 21-Jun-2001  nathanw Catch up to -current.
 1.6.22.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.6.22.2 18-Sep-2004  skrll Sync with HEAD.
 1.6.22.1 03-Aug-2004  skrll Sync with HEAD
 1.9.110.2 30-Oct-2012  yamt sync with head
 1.9.110.1 17-Apr-2012  yamt sync with head
 1.10.2.1 18-Feb-2012  mrg merge to -current.
 1.11.6.2 03-Dec-2017  jdolecek update from HEAD
 1.11.6.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.12.14.1 06-Jun-2015  skrll Sync with HEAD
 1.3 11-Dec-2005  christos merge ktrace-lwp.
 1.2 14-Jul-2003  lukem add missing __KERNEL_RCSID()
 1.1 01-Jan-2002  augustss branches: 1.1.2; 1.1.4; 1.1.20;
Add support for radio cards. Written by Maxim Tsyplakov and Vladimir Popov
for OpenBSD, from where it was imported.
 1.1.20.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.1.20.2 18-Sep-2004  skrll Sync with HEAD.
 1.1.20.1 03-Aug-2004  skrll Sync with HEAD
 1.1.4.2 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.1.4.1 01-Jan-2002  thorpej file lm700x.c was added on branch kqueue on 2002-01-10 19:54:47 +0000
 1.1.2.2 08-Jan-2002  nathanw Catch up to -current.
 1.1.2.1 01-Jan-2002  nathanw file lm700x.c was added on branch nathanw_sa on 2002-01-08 00:29:55 +0000
 1.2 19-Oct-2007  ad machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.1 01-Jan-2002  augustss branches: 1.1.2; 1.1.4; 1.1.36; 1.1.78; 1.1.92; 1.1.94; 1.1.98;
Add support for radio cards. Written by Maxim Tsyplakov and Vladimir Popov
for OpenBSD, from where it was imported.
 1.1.98.1 25-Oct-2007  bouyer Sync with HEAD.
 1.1.94.1 06-Nov-2007  matt sync with HEAD
 1.1.92.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.1.78.1 23-Oct-2007  ad Sync with head.
 1.1.36.1 27-Oct-2007  yamt sync with head.
 1.1.4.2 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.1.4.1 01-Jan-2002  thorpej file lm700x.h was added on branch kqueue on 2002-01-10 19:54:47 +0000
 1.1.2.2 08-Jan-2002  nathanw Catch up to -current.
 1.1.2.1 01-Jan-2002  nathanw file lm700x.h was added on branch nathanw_sa on 2002-01-08 00:29:55 +0000
 1.82 03-Sep-2018  riastradh Rename min/max -> uimin/uimax for better honesty.

These functions are defined on unsigned int. The generic name
min/max should not silently truncate to 32 bits on 64-bit systems.
This is purely a name change -- no functional change intended.

HOWEVER! Some subsystems have

#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))

even though our standard name for that is MIN/MAX. Although these
may invite multiple evaluation bugs, these do _not_ cause integer
truncation.

To avoid `fixing' these cases, I first changed the name in libkern,
and then compile-tested every file where min/max occurred in order to
confirm that it failed -- and thus confirm that nothing shadowed
min/max -- before changing it.

I have left a handful of bootloaders that are too annoying to
compile-test, and some dead code:

cobalt ews4800mips hp300 hppa ia64 luna68k vax
acorn32/if_ie.c (not included in any kernels)
macppc/if_gm.c (superseded by gem(4))

It should be easy to fix the fallout once identified -- this way of
doing things fails safe, and the goal here, after all, is to _avoid_
silent integer truncations, not introduce them.

Maybe one day we can reintroduce min/max as type-generic things that
never silently truncate. But we should avoid doing that for a while,
so that existing code has a chance to be detected by the compiler for
conversion to uimin/uimax without changing the semantics until we can
properly audit it all. (Who knows, maybe in some cases integer
truncation is actually intended!)
 1.81 28-Oct-2017  riastradh branches: 1.81.2; 1.81.4;
Kill some more extern struct cfdriver declarations.

Down with externs in .c!
 1.80 25-Jul-2014  dholland Add d_discard to all struct cdevsw instances I could find.

All have been set to "nodiscard"; some should get a real implementation.
 1.79 16-Mar-2014  dholland branches: 1.79.2;
Change (mostly mechanically) every cdevsw/bdevsw I can find to use
designated initializers.

I have not built every extant kernel so I have probably broken at
least one build; however I've also found and fixed some wrong
cdevsw/bdevsw entries so even if so I think we come out ahead.
 1.78 25-Nov-2009  rmind branches: 1.78.12; 1.78.22; 1.78.26;
Remove IPL_LPT and IPL_IPI aliases, use the actual IPLs.
Fix some broken comments.
 1.77 23-Nov-2009  rmind Remove some unecessary includes sys/user.h header.
 1.76 14-Mar-2009  dsl Change about 4500 of the K&R function definitions to ANSI ones.
There are still about 1600 left, but they have ',' or /* ... */
in the actual variable definitions - which my awk script doesn't handle.
There are also many that need () -> (void).
(The script does handle misordered arguments.)
 1.75 10-Jun-2008  cegger branches: 1.75.4; 1.75.10;
device_private(device_lookup()) -> device_lookup_private()
ok cube@
 1.74 07-Mar-2008  cube branches: 1.74.2; 1.74.4; 1.74.6; 1.74.8;
Split the softc from the device_t for all lpt(4) variants and attachments
except the ppbus stuff (which doesn't compile) and ulpt(4) which is
unrelated and can be dealt with separately.

As usual, it comes with related cosmetic changes.
 1.73 22-Feb-2008  dyoung Add methods to detach lpt at isa.
 1.72 19-Oct-2007  ad branches: 1.72.12; 1.72.16;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.71 09-Oct-2007  ad branches: 1.71.2;
Defer wakeup() to a soft interrupt, since lptintr() can be called above
IPL_SCHED.
 1.70 09-Jul-2007  ad branches: 1.70.6; 1.70.8; 1.70.10;
Merge some of the less invasive changes from the vmlocking branch:

- kthread, callout, devsw API changes
- select()/poll() improvements
- miscellaneous MT safety improvements
 1.69 04-Mar-2007  christos branches: 1.69.2; 1.69.4;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.68 16-Nov-2006  christos branches: 1.68.4;
__unused removal on arguments; approved by core.
 1.67 12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.66 02-Sep-2006  christos branches: 1.66.2; 1.66.4;
Add missing initializer
 1.65 11-Dec-2005  christos branches: 1.65.4; 1.65.8;
merge ktrace-lwp.
 1.64 27-Feb-2005  perry branches: 1.64.4;
nuke trailing whitespace
 1.63 29-Jun-2003  fvdl branches: 1.63.2; 1.63.10; 1.63.12;
Back out the lwp/ktrace changes. They contained a lot of colateral damage,
and need to be examined and discussed more.
 1.62 28-Jun-2003  darrenr Pass lwp pointers throughtout the kernel, as required, so that the lwpid can
be inserted into ktrace records. The general change has been to replace
"struct proc *" with "struct lwp *" in various function prototypes, pass
the lwp through and use l_proc to get the process pointer when needed.

Bump the kernel rev up to 1.6V
 1.61 10-Dec-2002  rafal Make this work on fast platforms by making sure signals are held for at
least 1us. Documentation I've found for the simple (SPP) parallel port
mode says that data should be stable 500ns before STROBE, STROBE should
be pulsed for no less than 500ns, and that data should be stable another
500ns after STROBE has been de-asserted.

Makes lpt@ebus on my Sun Ultra5 work with my HP DeskJet 712C, at least in
polled mode. Thanks to Martin for astutely noting it was probably a bug
with STROBE being pulsed too quickly.
 1.60 23-Oct-2002  jdolecek merge kqueue branch into -current

kqueue provides a stateful and efficient event notification framework
currently supported events include socket, file, directory, fifo,
pipe, tty and device changes, and monitoring of processes and signals

kqueue is supported by all writable filesystems in NetBSD tree
(with exception of Coda) and all device drivers supporting poll(2)

based on work done by Jonathan Lemon for FreeBSD
initial NetBSD port done by Luke Mewburn and Jason Thorpe
 1.59 06-Sep-2002  gehenna Merge the gehenna-devsw branch into the trunk.

This merge changes the device switch tables from static array to
dynamically generated by config(8).

- All device switches is defined as a constant structure in device drivers.

- The new grammer ``device-major'' is introduced to ``files''.

device-major <prefix> char <num> [block <num>] [<rules>]

- All device major numbers must be listed up in port dependent majors.<arch>
by using this grammer.

- Added the new naming convention.
The name of the device switch must be <prefix>_[bc]devsw for auto-generation
of device switch tables.

- The backward compatibility of loading block/character device
switch by LKM framework is broken. This is necessary to convert
from block/character device major to device name in runtime and vice versa.

- The restriction to assign device major by LKM is completely removed.
We don't need to reserve LKM entries for dynamic loading of device switch.

- In compile time, device major numbers list is packed into the kernel and
the LKM framework will refer it to assign device major number dynamically.
 1.58 13-Nov-2001  lukem branches: 1.58.8;
add/cleanup RCSID
 1.57 06-Jul-2000  thorpej branches: 1.57.2; 1.57.4; 1.57.6;
Use device_lookup().
 1.56 23-Mar-2000  thorpej New callout mechanism with two major improvements over the old
timeout()/untimeout() API:
- Clients supply callout handle storage, thus eliminating problems of
resource allocation.
- Insertion and removal of callouts is constant time, important as
this facility is used quite a lot in the kernel.

The old timeout()/untimeout() API has been removed from the kernel.
 1.55 29-Mar-1999  perry branches: 1.55.8;
Replace the #ifdef'ed variable DELAYs with a pair of non-ifdefed
DELAY(1)'s. This should fix interrupt driven lpt driver hang and
reboot problems for the group of users who have experienced them, and
shouldn't hurt anyone else.
 1.54 25-Mar-1999  perry Add two #ifdef BROKEN_LPT_DELAY's in to the central write byte
& strobe cycle. These bracket DELAY()'s of BROKEN_LPT_DELAY
microseconds. This can be used to kludge around mysterious hangs and
reboots some users experience. The cause of these failures is still
not known, but is conjectured to be hardware bug originated failures
in the bus cycle.
 1.53 12-Feb-1999  thorpej Fix printf format problems on Alpha.
 1.52 14-Oct-1998  perry Stop spurious lpt messages from being printed -- approved by fvdl.
 1.51 15-Aug-1998  mycroft Make copyright notices with my name consistent.
 1.50 18-Jul-1998  is Switching dev/ic/lpt.c to use spllpt() instead of spltty(). It doesn't use
tty structures, and on some machines (namely the DraCo internal lpt, and some
multi-i/o boards for Amigas and DraCos), tying spltty to the pretty high printer
interupt level would hurt serial performance.

On all affected ports but Amiga, spllpt() has been defined in machine/intr.h
to be spltty(), thus preserving old behaviour. Portmasters are encouraged to
change is, if they feel something else is better (e.g., one of its own were
possible).
 1.49 02-Feb-1998  cgd Implement a flag to indicate that the driver attached correctly.
This is useful in the case where an attachment's probe routine
verifies that there is indeed hardware present but something goes
"wrong" in the attach causing the device to be unusable. (Without
keeping track of this, in that case incorrect ports could be
accessed or uninitted pointers could be deferenced on open or at
other times.)
 1.48 12-Jan-1998  thorpej Adjust for config changes.
 1.47 07-Dec-1997  thorpej Use malloc()/free(), not geteblk()/brelse(), for the device buffer.
 1.46 14-Oct-1997  is branches: 1.46.2;
Finalize the isa/lpt.c split:
The isa attachment code is in isa/lpt_isa.c now, which attaches to the
already created ic/lpt* files.
You don't need to change your config files, but you need to re-"config" if
using lpt at isa.
XXX The "lpt" device definition should be in sys/conf/files instead, but to
my knowledge, there are some ports which have private copies of lpt, and would
choke on that. No need to make people unhappy 7 days before release branching.
 1.45 27-Sep-1997  is branches: 1.45.2;
First part of splitting lpt.c, and the NetBSD/Amiga "supio" frontend. Needs
a bit more work to allow an ISA frontend.
 1.44 02-Sep-1997  mikel add missing argument to LPRINTF() declaration; from Geoff Wing in PR 4072.
I also made inclusion of LPRINTF() dependent solely on the symbol
LPTDEBUG, initialized lptdebug variable to 0 instead of 1, and
matched arguments to format strings in LPRINTF() calls.
 1.43 05-Dec-1996  cgd branches: 1.43.10;
update these so they compile whether or not __BROKEN_INDIRECT_CONFIG
is defined.
 1.42 21-Oct-1996  thorpej New bus.h implementation/interface:
- No more distinction between i/o-mapped and memory-mapped
devices. It's all "bus space" now, and space tags
differentiate the space with finer grain than the
bus chipset tag.
- Add memory barrier methods.
- Implement space alloc/free methods.
- Implement region read/write methods (like memcpy to/from
bus space).
This interface provides a better abstraction for dealing with
machine-independent chipset drivers.
 1.41 13-Oct-1996  christos backout kprintf changes
 1.40 10-Oct-1996  christos printf -> kprintf, sprintf -> ksprintf
 1.39 12-May-1996  mycroft Use intr.h.
 1.38 29-Apr-1996  christos - Fix gcc -Wall warnings
- BUG: if (error = ...() == EWOULDBLOCK)
 1.37 11-Apr-1996  cgd update for addition of a machine-dependent cookie as the first argument
to isa_intr_{,dis}establish().
 1.36 10-Apr-1996  mycroft Add explicit return types.
 1.35 18-Mar-1996  cgd since this driver tries to block its interrupt with spltty(), it must
attach that interrupt with IPL_TTY.
 1.34 17-Mar-1996  cgd clean up <machine/bus.h> changes a bit; no real functional change.
prototype lpt_port_test().
 1.33 17-Mar-1996  thorpej New device attachment scheme:

- split softc size and match/attach out from cfdriver into
a new struct cfattach.

- new "attach" directive for files.*. May specify the name of
the cfattach structure, so that devices may be easily attached
to parents with different autoconfiguration semantics.
 1.32 08-Mar-1996  cgd convert to use I/O mapping/access macros in <machine/bus.h>.
Mostly mechanical changes, except for probe/attach, which have
to map (and, in the case of probe, unmap) the I/O space that the
chip will use.
 1.31 24-Dec-1995  mycroft The IST_* and IPL_* constants are not bus-specific; don't treat them as such.
Change splimp -> splnet in Ethernet, ARCnet, and FDDI drivers.
 1.30 17-Apr-1995  cgd clean up several ISA device interfaces: autoconfiguration, header
inclusion, and interrupt configuration. more work still needs to be done,
but it's getting better...
 1.29 29-Jan-1995  cgd lip service to making ISA support machine-independent. This is the first
round: moving the drivers into a machine-independent directory.
Some drivers (e.g. fd.c) not moved because they use other pc features (e.g.
CMOS settings), and none of the non-driver files moved, because they're
still pretty much PC specific. eventually (when other ports with ISA
busses really start using this code), more 'high-level' ISA support will
live here.
 1.28 26-Jan-1995  mycroft Don't check the control port at all; too unreliable.
 1.27 22-Jan-1995  mycroft Rearrange tests so `offline' has higher priority than `out of paper'.
 1.26 03-Jan-1995  mycroft Add interrupt sharing types.
 1.25 18-Nov-1994  mycroft Convert port, IRQ, and DRQ numbers to ints.
 1.24 30-Oct-1994  cgd be more careful with types, also pull in headers where necessary.
 1.23 27-Oct-1994  cgd new RCS ID format.
 1.22 16-Jun-1994  mycroft branches: 1.22.2;
b_un.b_addr -> b_data
 1.21 27-May-1994  mycroft Only print the blasted messages *once* per error.
 1.20 23-May-1994  cgd turn off spontaneous printing of messages when DEBUG turned on
 1.19 05-May-1994  mycroft Remove now-bogus cast.
 1.18 05-May-1994  cgd lots of changes: prototype migration, move lots of variables, definitions,
and structure elements around. kill some unnecessary type and macro
definitions. standardize clock handling. More changes than you'd want.
 1.17 22-Apr-1994  mycroft Don't need isa.h.
 1.16 07-Apr-1994  mycroft Implement dynamic IRQ configuration and IRQ sharing. Inline spl*() calls.
Reorganize and clean up the relevant code.
 1.15 29-Mar-1994  mycroft Updates for new autoconfig.
 1.14 06-Mar-1994  mycroft DELAY() --> delay(). This is not a macro.
 1.13 19-Feb-1994  mycroft Speed it up a little...
 1.12 19-Feb-1994  mycroft Minor tweak of no importance.
 1.11 18-Feb-1994  mycroft Combined version from magnum branch. Somewhat faster and less buggy.
 1.10 09-Feb-1994  mycroft All ioctl routines take a struct proc * now.
 1.9 20-Dec-1993  mycroft Canonicalize all #includes, and add pio.h where appropriate.
 1.8 28-Sep-1993  cgd get rid of stray printfs (turn them into "lprintf"s)
 1.7 17-Jul-1993  mycroft branches: 1.7.4;
Make these files GCC 2 happy.
 1.6 15-Jun-1993  mycroft Ignore interrupts if the device isn't open. This prevents stray interrupts
from hosing the works. What a stupid architecture.
 1.5 05-Jun-1993  cgd patch from rgrimes to add delay to let data port stabilize, also
make "lpflag" unique to each driver
 1.4 22-May-1993  cgd add include of select.h if necessary for protos, or delete if extraneous
 1.3 18-May-1993  cgd make kernel select interface be one-stop shopping & clean it all up.
 1.2 07-May-1993  cgd fix lpt driver and add lpa driver. from 386bsd pk patch 133
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.7.4.18 16-Feb-1994  mycroft Avoid two minor race conditions; no real differences.
 1.7.4.17 29-Oct-1993  mycroft Force the printer closed even if the final pushbytes() fails.
 1.7.4.16 29-Oct-1993  mycroft Make sure pushbytes() returns 0 on success.
 1.7.4.15 29-Oct-1993  mycroft Ignore the bottom 3 bits when checking for printer ready.
 1.7.4.14 29-Oct-1993  mycroft Make some debugging code in the probe routines #ifdef DEBUG.
 1.7.4.13 27-Oct-1993  mycroft Add lptforceintr(), but disabled for now. Add some debugging code.
 1.7.4.12 18-Oct-1993  mycroft We can't determine lpt interrupts dynamically.
 1.7.4.11 17-Oct-1993  mycroft When an error occurs, at least say what it is before hanging.
 1.7.4.10 16-Oct-1993  mycroft Add missing dv_class entry to cfdrivers, and use dv_xname where appropriate.
 1.7.4.9 12-Oct-1993  mycroft Minor cleanup.
 1.7.4.8 11-Oct-1993  mycroft #include pio.h where needed, and remove cpufunc.h.
 1.7.4.7 07-Oct-1993  mycroft Don't #include isa.h.
 1.7.4.6 06-Oct-1993  mycroft Finish reformatting. Turn interrupt on or off as appropriate in lptopen().
 1.7.4.5 01-Oct-1993  mycroft #include "machine/cpu.h"
 1.7.4.4 30-Sep-1993  mycroft Change some uses of IRQUNK to IRQNONE. #include isa.h and icu.h.
 1.7.4.3 30-Sep-1993  mycroft clock.c: Remove unnecessary casts.
com.c: Update for new config. Add bis() and bic() macros like BSDI's.
Add comspeed() and tiocm_xxx2mcr() from BSDI.
comreg.h: Add COM_FREQ, COM_TOLERANCE, and COM_NPORTS.
fd.c: Remove casts and clean up fdioctl().
[lm]ms.c: Add necessary gunk to [lm]ms_softc and remove casts.
 1.7.4.2 29-Sep-1993  mycroft lms.c: Update for new config.
lpa.c: Defunct.
lpt.c: Update for new config. Fix handling of interrupted writes. Merge code
from lpa driver. Make all operations interruptible. Remove a few other
bogons.
lptreg.h: Add LPT_NPORTS.
pccons.c: Merge changes from trunk.
 1.7.4.1 14-Sep-1993  mycroft New i386 code.
 1.22.2.1 23-Nov-1994  cgd make sure to do an untimeout. for patch_04
 1.43.10.1 04-Sep-1997  thorpej Update marc-pcmcia branch from trunk.
 1.45.2.3 15-Oct-1997  thorpej Update marc-pcmcia branch from trunk.
 1.45.2.2 14-Oct-1997  thorpej Update marc-pcmcia branch from trunk.
 1.45.2.1 27-Sep-1997  thorpej file lpt.c was added on branch marc-pcmcia on 1997-10-14 10:22:47 +0000
 1.46.2.1 07-Dec-1997  thorpej Pull up from trunk: Use malloc()/free(), not geteblk()/brelse().
 1.55.8.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.57.6.2 26-Sep-2001  fvdl * add a VCLONED vnode flag that indicates a vnode representing a cloned
device.
* rename REVOKEALL to REVOKEALIAS, and add a REVOKECLONE flag, to pass
to VOP_REVOKE
* the revoke system call will revoke all aliases, as before, but not the
clones
* vdevgone is called when detaching a device, so make it use REVOKECLONE
to get rid of all clones as well
* clean up all uses of VOP_OPEN wrt. locking.
* add a few VOPS to spec_vnops that need to do something when it's a
clone vnode (access and getattr)
* add a copy of the vnode vattr structure of the original 'master' vnode
to the specinfo of a cloned vnode. could possibly redirect getattr to
the 'master' vnode, but this has issues with revoke
* add a vdev_reassignvp function that disassociates a vnode from its
original device, and reassociates it with the specified dev_t. to be
used by cloning devices only, in case a new minor is allocated.
* change all direct references in drivers to v_devcookie and v_rdev
to vdev_privdata(vp) and vdev_rdev(vp). for diagnostic purposes
when debugging race conditions that still exist wrt. locking and
revoking vnodes.
* make the locking state of a vnode consistent when passed to
d_open and d_close (unlocked). locked would be better, but has
some deadlock issues
 1.57.6.1 07-Sep-2001  thorpej Commit my "devvp" changes to the thorpej-devvp branch. This
replaces the use of dev_t in most places with a struct vnode *.

This will form the basic infrastructure for real cloning device
support (besides being architecurally cleaner -- it'll be good
to get away from using numbers to represent objects).
 1.57.4.2 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.57.4.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.57.2.4 11-Dec-2002  thorpej Sync with HEAD.
 1.57.2.3 11-Nov-2002  nathanw Catch up to -current
 1.57.2.2 17-Sep-2002  nathanw Catch up to -current.
 1.57.2.1 14-Nov-2001  nathanw Catch up to -current.
 1.58.8.1 16-May-2002  gehenna Add the character device switch.
 1.63.12.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.63.10.1 29-Apr-2005  kent sync with -current
 1.63.2.4 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.63.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.63.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.63.2.1 02-Jul-2003  darrenr Apply the aborted ktrace-lwp changes to a specific branch. This is just for
others to review, I'm concerned that patch fuziness may have resulted in some
errant code being generated but I'll look at that later by comparing the diff
from the base to the branch with the file I attempt to apply to it. This will,
at the very least, put the changes in a better context for others to review
them and attempt to tinker with removing passing of 'struct lwp' through
the kernel.
 1.64.4.6 17-Mar-2008  yamt sync with head.
 1.64.4.5 27-Feb-2008  yamt sync with head.
 1.64.4.4 27-Oct-2007  yamt sync with head.
 1.64.4.3 03-Sep-2007  yamt sync with head.
 1.64.4.2 30-Dec-2006  yamt sync with head.
 1.64.4.1 21-Jun-2006  yamt sync with head.
 1.65.8.1 03-Sep-2006  yamt sync with head.
 1.65.4.1 09-Sep-2006  rpaulo sync with head
 1.66.4.2 10-Dec-2006  yamt sync with head.
 1.66.4.1 22-Oct-2006  yamt sync with head
 1.66.2.1 18-Nov-2006  ad Sync with head.
 1.68.4.1 12-Mar-2007  rmind Sync with HEAD.
 1.69.4.1 11-Jul-2007  mjf Sync with head.
 1.69.2.3 23-Oct-2007  ad Sync with head.
 1.69.2.2 12-Oct-2007  ad Sync with head.
 1.69.2.1 01-Jul-2007  ad Adapt to callout API change.
 1.70.10.1 14-Oct-2007  yamt sync with head.
 1.70.8.2 23-Mar-2008  matt sync with HEAD
 1.70.8.1 06-Nov-2007  matt sync with HEAD
 1.70.6.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.71.2.1 25-Oct-2007  bouyer Sync with HEAD.
 1.72.16.4 29-Jun-2008  mjf Sync with HEAD.
 1.72.16.3 06-Apr-2008  mjf - after some discussion with agc@ i agreed it would be a good idea to move
device_unregister_* to device_deregister_* to be more like the pmf(9)
functions, especially since a lot of the time the function calls are next
to each other.

- add device_register_name() support for dk(4).
 1.72.16.2 05-Apr-2008  mjf - add "file-system DEVFS" and "pseudo-device devfsctl" to conf/std seeing
as these are always needed.

- convert many, many drivers over to the New Devfs World Order. For a
list of device drivers yet to be converted see,
http://www.netbsd.org/~mjf/devfs-todo.html.

- add a new device_unregister_all(device_t) function to remove all device
names associated with a device_t, which saves us having to construct
device names when the driver is detached.

- add a DEV_AUDIO type for devices.
 1.72.16.1 03-Apr-2008  mjf Sync with HEAD.
 1.72.12.1 24-Mar-2008  keiichi sync with head.
 1.74.8.1 18-Jun-2008  simonb Sync with head.
 1.74.6.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.74.4.2 11-Mar-2010  yamt sync with head
 1.74.4.1 04-May-2009  yamt sync with head.
 1.74.2.1 17-Jun-2008  yamt sync with head.
 1.75.10.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.75.4.1 28-Apr-2009  skrll Sync with HEAD.
 1.78.26.1 18-May-2014  rmind sync with head
 1.78.22.2 03-Dec-2017  jdolecek update from HEAD
 1.78.22.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.78.12.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.79.2.1 10-Aug-2014  tls Rebase.
 1.81.4.1 10-Jun-2019  christos Sync with HEAD
 1.81.2.1 06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.11 11-Nov-2019  msaitoh Remove acorn26's upc(4) devices.
 1.10 25-Jan-2009  bjh21 branches: 1.10.66;
The introduction of config_stdsubmatch() lost an important feature of
upc_submatch() whereby it made sure that the correct driver attached.
Since this didn't really belong in the submatch function anyway,
reintroduce it in the match functions for upc's children.

This allows my A5000 to find at least one of its hard disks.
 1.9 07-Mar-2008  cube branches: 1.9.4; 1.9.12; 1.9.14;
Split the softc from the device_t for all lpt(4) variants and attachments
except the ppbus stuff (which doesn't compile) and ulpt(4) which is
unrelated and can be dealt with separately.

As usual, it comes with related cosmetic changes.
 1.8 19-Oct-2007  ad branches: 1.8.12; 1.8.16;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.7 11-Dec-2005  christos branches: 1.7.30; 1.7.44; 1.7.46; 1.7.50;
merge ktrace-lwp.
 1.6 27-Feb-2005  perry branches: 1.6.4;
nuke trailing whitespace
 1.5 02-Oct-2002  thorpej branches: 1.5.6; 1.5.14; 1.5.16;
Add trailing ; to CFATTACH_DECL.
 1.4 30-Sep-2002  thorpej Use CFATTACH_DECL().
 1.3 27-Sep-2002  thorpej Declare all cfattach structures const.
 1.2 13-Nov-2001  lukem add/cleanup RCSID
 1.1 16-Aug-2000  bjh21 branches: 1.1.2; 1.1.4; 1.1.6;
Basic driver for CHIPS 82C710 Universal Peripheral Controller and friends,
as used on later arm26 system (A5000, A4, A3010, A3020, A4000).

What we have got:
...
upc0 at iobus0 base 0x010000: config state bb 87 1c 00 00
fdc at upc0 offset 0x3f4 not configured
wdc0 at upc0 offset 0x1f0
lpt0 at upc0 offset 0x278
com0 at upc0 offset 0x3f8: ns8250 or ns16450, no fifo
...

What we haven't got:
- FDC support (found, but not configured).
- Clearing lpt interrupts on arm26 systems (needs help from IOEB).
- A upc(4) manual page.
- More than minimal testing (my A3020s don't have root devices).
- A proper probe routine (arm26 can't use one anyway).
 1.1.6.2 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.1.6.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.1.4.2 18-Oct-2002  nathanw Catch up to -current.
 1.1.4.1 14-Nov-2001  nathanw Catch up to -current.
 1.1.2.2 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.1.2.1 16-Aug-2000  bouyer file lpt_upc.c was added on branch thorpej_scsipi on 2000-11-20 11:40:42 +0000
 1.5.16.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.5.14.1 29-Apr-2005  kent sync with -current
 1.5.6.1 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.6.4.2 17-Mar-2008  yamt sync with head.
 1.6.4.1 27-Oct-2007  yamt sync with head.
 1.7.50.1 25-Oct-2007  bouyer Sync with HEAD.
 1.7.46.2 23-Mar-2008  matt sync with HEAD
 1.7.46.1 06-Nov-2007  matt sync with HEAD
 1.7.44.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.7.30.1 23-Oct-2007  ad Sync with head.
 1.8.16.1 03-Apr-2008  mjf Sync with HEAD.
 1.8.12.1 24-Mar-2008  keiichi sync with head.
 1.9.14.1 02-Feb-2009  snj Pull up following revision(s) (requested by bjh21 in ticket #335):
sys/dev/ic/com_upc.c: revision 1.11
sys/dev/ic/lpt_upc.c: revision 1.10
sys/dev/ic/wdc_upc.c: revision 1.26
The introduction of config_stdsubmatch() lost an important feature of
upc_submatch() whereby it made sure that the correct driver attached.
Since this didn't really belong in the submatch function anyway,
reintroduce it in the match functions for upc's children.
This allows my A5000 to find at least one of its hard disks.
 1.9.12.1 03-Mar-2009  skrll Sync with HEAD.
 1.9.4.1 04-May-2009  yamt sync with head.
 1.10.66.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.10 02-May-2006  martin Fix some comments, mostly from Nenad Crnko in PR kern/33402.
 1.9 11-Dec-2005  christos branches: 1.9.4; 1.9.6; 1.9.8; 1.9.10; 1.9.12;
merge ktrace-lwp.
 1.8 27-Feb-2005  perry branches: 1.8.4;
nuke trailing whitespace
 1.7 07-Aug-2003  agc branches: 1.7.8; 1.7.10;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22364, verified by myself.
 1.6 06-Jan-2001  nathanw branches: 1.6.24;
Add description of the pinout of a standard DB-25 parallel port,
relative to the bits described here.
 1.5 23-Nov-1996  cgd branches: 1.5.2; 1.5.18;
Drop LPT_NPORTS to 4 from 8. Some lpt units require only 4 I/O ports
(e.g. from 0x3bc to 0x3bf, for example). Others may require more,
but until there's some special handling for them, 4 should be returned
so that on systems with I/O port accounting, the unit at 0x3bf can be
properly mapped, etc. (OK'd by mycroft.)
 1.4 27-Oct-1994  cgd new RCS ID format.
 1.3 18-Feb-1994  mycroft Combined version from magnum branch. Somewhat faster and less buggy.
 1.2 22-May-1993  cgd branches: 1.2.4;
add rcsids to everything and clean up headers
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.2.4.2 06-Oct-1993  mycroft Give #defines more mnemonic names, and fix comment for LPC_IENABLE.
 1.2.4.1 29-Sep-1993  mycroft lms.c: Update for new config.
lpa.c: Defunct.
lpt.c: Update for new config. Fix handling of interrupted writes. Merge code
from lpa driver. Make all operations interruptible. Remove a few other
bogons.
lptreg.h: Add LPT_NPORTS.
pccons.c: Merge changes from trunk.
 1.5.18.1 18-Jan-2001  bouyer Sync with head (for UBC+NFS fixes, mostly).
 1.5.2.1 14-Oct-1997  thorpej Update marc-pcmcia branch from trunk.
 1.6.24.4 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.6.24.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.6.24.2 18-Sep-2004  skrll Sync with HEAD.
 1.6.24.1 03-Aug-2004  skrll Sync with HEAD
 1.7.10.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.7.8.1 29-Apr-2005  kent sync with -current
 1.8.4.1 21-Jun-2006  yamt sync with head.
 1.9.12.1 24-May-2006  tron Merge 2006-05-24 NetBSD-current into the "peter-altq" branch.
 1.9.10.1 11-May-2006  elad sync with head
 1.9.8.1 24-May-2006  yamt sync with head.
 1.9.6.1 01-Jun-2006  kardel Sync with head.
 1.9.4.1 09-Sep-2006  rpaulo sync with head
 1.56 07-Mar-2008  cube Split the softc from the device_t for all lpt(4) variants and attachments
except the ppbus stuff (which doesn't compile) and ulpt(4) which is
unrelated and can be dealt with separately.

As usual, it comes with related cosmetic changes.
 1.55 22-Feb-2008  dyoung Add methods to detach lpt at isa.
 1.54 09-Oct-2007  ad branches: 1.54.14; 1.54.18;
Defer wakeup() to a soft interrupt, since lptintr() can be called above
IPL_SCHED.
 1.53 11-Dec-2005  christos branches: 1.53.30; 1.53.44; 1.53.46; 1.53.48;
merge ktrace-lwp.
 1.52 27-Feb-2005  perry branches: 1.52.4;
nuke trailing whitespace
 1.51 04-Feb-2005  perry de-__P
 1.50 23-Mar-2000  thorpej branches: 1.50.28; 1.50.36; 1.50.38;
New callout mechanism with two major improvements over the old
timeout()/untimeout() API:
- Clients supply callout handle storage, thus eliminating problems of
resource allocation.
- Insertion and removal of callouts is constant time, important as
this facility is used quite a lot in the kernel.

The old timeout()/untimeout() API has been removed from the kernel.
 1.49 15-Aug-1998  mycroft branches: 1.49.12;
Make copyright notices with my name consistent.
 1.48 02-Feb-1998  cgd Implement a flag to indicate that the driver attached correctly.
This is useful in the case where an attachment's probe routine
verifies that there is indeed hardware present but something goes
"wrong" in the attach causing the device to be unusable. (Without
keeping track of this, in that case incorrect ports could be
accessed or uninitted pointers could be deferenced on open or at
other times.)
 1.47 07-Dec-1997  thorpej Use malloc()/free(), not geteblk()/brelse(), for the device buffer.
 1.46 14-Oct-1997  is branches: 1.46.2;
Finalize the isa/lpt.c split:
The isa attachment code is in isa/lpt_isa.c now, which attaches to the
already created ic/lpt* files.
You don't need to change your config files, but you need to re-"config" if
using lpt at isa.
XXX The "lpt" device definition should be in sys/conf/files instead, but to
my knowledge, there are some ports which have private copies of lpt, and would
choke on that. No need to make people unhappy 7 days before release branching.
 1.45 27-Sep-1997  is branches: 1.45.2;
First part of splitting lpt.c, and the NetBSD/Amiga "supio" frontend. Needs
a bit more work to allow an ISA frontend.
 1.44 02-Sep-1997  mikel add missing argument to LPRINTF() declaration; from Geoff Wing in PR 4072.
I also made inclusion of LPRINTF() dependent solely on the symbol
LPTDEBUG, initialized lptdebug variable to 0 instead of 1, and
matched arguments to format strings in LPRINTF() calls.
 1.43 05-Dec-1996  cgd branches: 1.43.10;
update these so they compile whether or not __BROKEN_INDIRECT_CONFIG
is defined.
 1.42 21-Oct-1996  thorpej New bus.h implementation/interface:
- No more distinction between i/o-mapped and memory-mapped
devices. It's all "bus space" now, and space tags
differentiate the space with finer grain than the
bus chipset tag.
- Add memory barrier methods.
- Implement space alloc/free methods.
- Implement region read/write methods (like memcpy to/from
bus space).
This interface provides a better abstraction for dealing with
machine-independent chipset drivers.
 1.41 13-Oct-1996  christos backout kprintf changes
 1.40 10-Oct-1996  christos printf -> kprintf, sprintf -> ksprintf
 1.39 12-May-1996  mycroft Use intr.h.
 1.38 29-Apr-1996  christos - Fix gcc -Wall warnings
- BUG: if (error = ...() == EWOULDBLOCK)
 1.37 11-Apr-1996  cgd update for addition of a machine-dependent cookie as the first argument
to isa_intr_{,dis}establish().
 1.36 10-Apr-1996  mycroft Add explicit return types.
 1.35 18-Mar-1996  cgd since this driver tries to block its interrupt with spltty(), it must
attach that interrupt with IPL_TTY.
 1.34 17-Mar-1996  cgd clean up <machine/bus.h> changes a bit; no real functional change.
prototype lpt_port_test().
 1.33 17-Mar-1996  thorpej New device attachment scheme:

- split softc size and match/attach out from cfdriver into
a new struct cfattach.

- new "attach" directive for files.*. May specify the name of
the cfattach structure, so that devices may be easily attached
to parents with different autoconfiguration semantics.
 1.32 08-Mar-1996  cgd convert to use I/O mapping/access macros in <machine/bus.h>.
Mostly mechanical changes, except for probe/attach, which have
to map (and, in the case of probe, unmap) the I/O space that the
chip will use.
 1.31 24-Dec-1995  mycroft The IST_* and IPL_* constants are not bus-specific; don't treat them as such.
Change splimp -> splnet in Ethernet, ARCnet, and FDDI drivers.
 1.30 17-Apr-1995  cgd clean up several ISA device interfaces: autoconfiguration, header
inclusion, and interrupt configuration. more work still needs to be done,
but it's getting better...
 1.29 29-Jan-1995  cgd lip service to making ISA support machine-independent. This is the first
round: moving the drivers into a machine-independent directory.
Some drivers (e.g. fd.c) not moved because they use other pc features (e.g.
CMOS settings), and none of the non-driver files moved, because they're
still pretty much PC specific. eventually (when other ports with ISA
busses really start using this code), more 'high-level' ISA support will
live here.
 1.28 26-Jan-1995  mycroft Don't check the control port at all; too unreliable.
 1.27 22-Jan-1995  mycroft Rearrange tests so `offline' has higher priority than `out of paper'.
 1.26 03-Jan-1995  mycroft Add interrupt sharing types.
 1.25 18-Nov-1994  mycroft Convert port, IRQ, and DRQ numbers to ints.
 1.24 30-Oct-1994  cgd be more careful with types, also pull in headers where necessary.
 1.23 27-Oct-1994  cgd new RCS ID format.
 1.22 16-Jun-1994  mycroft branches: 1.22.2;
b_un.b_addr -> b_data
 1.21 27-May-1994  mycroft Only print the blasted messages *once* per error.
 1.20 23-May-1994  cgd turn off spontaneous printing of messages when DEBUG turned on
 1.19 05-May-1994  mycroft Remove now-bogus cast.
 1.18 05-May-1994  cgd lots of changes: prototype migration, move lots of variables, definitions,
and structure elements around. kill some unnecessary type and macro
definitions. standardize clock handling. More changes than you'd want.
 1.17 22-Apr-1994  mycroft Don't need isa.h.
 1.16 07-Apr-1994  mycroft Implement dynamic IRQ configuration and IRQ sharing. Inline spl*() calls.
Reorganize and clean up the relevant code.
 1.15 29-Mar-1994  mycroft Updates for new autoconfig.
 1.14 06-Mar-1994  mycroft DELAY() --> delay(). This is not a macro.
 1.13 19-Feb-1994  mycroft Speed it up a little...
 1.12 19-Feb-1994  mycroft Minor tweak of no importance.
 1.11 18-Feb-1994  mycroft Combined version from magnum branch. Somewhat faster and less buggy.
 1.10 09-Feb-1994  mycroft All ioctl routines take a struct proc * now.
 1.9 20-Dec-1993  mycroft Canonicalize all #includes, and add pio.h where appropriate.
 1.8 28-Sep-1993  cgd get rid of stray printfs (turn them into "lprintf"s)
 1.7 17-Jul-1993  mycroft branches: 1.7.4;
Make these files GCC 2 happy.
 1.6 15-Jun-1993  mycroft Ignore interrupts if the device isn't open. This prevents stray interrupts
from hosing the works. What a stupid architecture.
 1.5 05-Jun-1993  cgd patch from rgrimes to add delay to let data port stabilize, also
make "lpflag" unique to each driver
 1.4 22-May-1993  cgd add include of select.h if necessary for protos, or delete if extraneous
 1.3 18-May-1993  cgd make kernel select interface be one-stop shopping & clean it all up.
 1.2 07-May-1993  cgd fix lpt driver and add lpa driver. from 386bsd pk patch 133
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.7.4.18 16-Feb-1994  mycroft Avoid two minor race conditions; no real differences.
 1.7.4.17 29-Oct-1993  mycroft Force the printer closed even if the final pushbytes() fails.
 1.7.4.16 29-Oct-1993  mycroft Make sure pushbytes() returns 0 on success.
 1.7.4.15 29-Oct-1993  mycroft Ignore the bottom 3 bits when checking for printer ready.
 1.7.4.14 29-Oct-1993  mycroft Make some debugging code in the probe routines #ifdef DEBUG.
 1.7.4.13 27-Oct-1993  mycroft Add lptforceintr(), but disabled for now. Add some debugging code.
 1.7.4.12 18-Oct-1993  mycroft We can't determine lpt interrupts dynamically.
 1.7.4.11 17-Oct-1993  mycroft When an error occurs, at least say what it is before hanging.
 1.7.4.10 16-Oct-1993  mycroft Add missing dv_class entry to cfdrivers, and use dv_xname where appropriate.
 1.7.4.9 12-Oct-1993  mycroft Minor cleanup.
 1.7.4.8 11-Oct-1993  mycroft #include pio.h where needed, and remove cpufunc.h.
 1.7.4.7 07-Oct-1993  mycroft Don't #include isa.h.
 1.7.4.6 06-Oct-1993  mycroft Finish reformatting. Turn interrupt on or off as appropriate in lptopen().
 1.7.4.5 01-Oct-1993  mycroft #include "machine/cpu.h"
 1.7.4.4 30-Sep-1993  mycroft Change some uses of IRQUNK to IRQNONE. #include isa.h and icu.h.
 1.7.4.3 30-Sep-1993  mycroft clock.c: Remove unnecessary casts.
com.c: Update for new config. Add bis() and bic() macros like BSDI's.
Add comspeed() and tiocm_xxx2mcr() from BSDI.
comreg.h: Add COM_FREQ, COM_TOLERANCE, and COM_NPORTS.
fd.c: Remove casts and clean up fdioctl().
[lm]ms.c: Add necessary gunk to [lm]ms_softc and remove casts.
 1.7.4.2 29-Sep-1993  mycroft lms.c: Update for new config.
lpa.c: Defunct.
lpt.c: Update for new config. Fix handling of interrupted writes. Merge code
from lpa driver. Make all operations interruptible. Remove a few other
bogons.
lptreg.h: Add LPT_NPORTS.
pccons.c: Merge changes from trunk.
 1.7.4.1 14-Sep-1993  mycroft New i386 code.
 1.22.2.1 23-Nov-1994  cgd make sure to do an untimeout. for patch_04
 1.43.10.1 04-Sep-1997  thorpej Update marc-pcmcia branch from trunk.
 1.45.2.3 15-Oct-1997  thorpej Update marc-pcmcia branch from trunk.
 1.45.2.2 14-Oct-1997  thorpej Update marc-pcmcia branch from trunk.
 1.45.2.1 27-Sep-1997  thorpej file lptvar.h was added on branch marc-pcmcia on 1997-10-14 10:22:51 +0000
 1.46.2.1 07-Dec-1997  thorpej Pull up from trunk: Use malloc()/free(), not geteblk()/brelse().
 1.49.12.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.50.38.2 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.50.38.1 12-Feb-2005  yamt sync with head.
 1.50.36.1 29-Apr-2005  kent sync with -current
 1.50.28.2 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.50.28.1 04-Feb-2005  skrll Sync with HEAD.
 1.52.4.3 17-Mar-2008  yamt sync with head.
 1.52.4.2 27-Feb-2008  yamt sync with head.
 1.52.4.1 27-Oct-2007  yamt sync with head.
 1.53.48.1 14-Oct-2007  yamt sync with head.
 1.53.46.2 23-Mar-2008  matt sync with HEAD
 1.53.46.1 06-Nov-2007  matt sync with HEAD
 1.53.44.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.53.30.1 12-Oct-2007  ad Sync with head.
 1.54.18.1 03-Apr-2008  mjf Sync with HEAD.
 1.54.14.1 24-Mar-2008  keiichi sync with head.
 1.40 25-Sep-2022  thorpej Remove unnecessary include of <sys/malloc.h>.
 1.39 03-Sep-2018  riastradh Rename min/max -> uimin/uimax for better honesty.

These functions are defined on unsigned int. The generic name
min/max should not silently truncate to 32 bits on 64-bit systems.
This is purely a name change -- no functional change intended.

HOWEVER! Some subsystems have

#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))

even though our standard name for that is MIN/MAX. Although these
may invite multiple evaluation bugs, these do _not_ cause integer
truncation.

To avoid `fixing' these cases, I first changed the name in libkern,
and then compile-tested every file where min/max occurred in order to
confirm that it failed -- and thus confirm that nothing shadowed
min/max -- before changing it.

I have left a handful of bootloaders that are too annoying to
compile-test, and some dead code:

cobalt ews4800mips hp300 hppa ia64 luna68k vax
acorn32/if_ie.c (not included in any kernels)
macppc/if_gm.c (superseded by gem(4))

It should be easy to fix the fallout once identified -- this way of
doing things fails safe, and the goal here, after all, is to _avoid_
silent integer truncations, not introduce them.

Maybe one day we can reintroduce min/max as type-generic things that
never silently truncate. But we should avoid doing that for a while,
so that existing code has a chance to be detected by the compiler for
conversion to uimin/uimax without changing the semantics until we can
properly audit it all. (Who knows, maybe in some cases integer
truncation is actually intended!)
 1.38 27-Oct-2012  chs branches: 1.38.36; 1.38.38;
split device_t/softc for all remaining drivers.
replace "struct device *" with "device_t".
use device_xname(), device_unit(), etc.
 1.37 14-Nov-2010  uebayasi branches: 1.37.8; 1.37.18;
This actually uses only PAGE_SIZE, remove uvm/uvm_extern.h again.
 1.36 14-Nov-2010  uebayasi Yet another hidden uvmexp user.
 1.35 13-Nov-2010  uebayasi Don't pull in the whole uvm(9) API to access only PAGE_SIZE and
some other constants. These are provided by sys/param.h now.
 1.34 16-Dec-2008  christos branches: 1.34.6;
replace bitmask_snprintf(9) with snprintb(3)
 1.33 28-Apr-2008  martin branches: 1.33.8;
Remove clause 3 and 4 from TNF licenses
 1.32 13-Apr-2008  tsutsui branches: 1.32.2; 1.32.4;
Split device_t/softc for MI ncr53c9x and some related devices,
with various cleanup.
 1.31 08-Apr-2008  cegger use aprint_*_dev and device_xname
 1.30 19-Oct-2007  ad branches: 1.30.16;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.29 04-Mar-2007  christos branches: 1.29.2; 1.29.14; 1.29.16; 1.29.20;
fix fallout from caddr_t changes.
 1.28 04-Mar-2007  christos Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.27 11-Dec-2005  christos branches: 1.27.26;
merge ktrace-lwp.
 1.26 31-May-2005  christos branches: 1.26.2;
avoid variable shadow.
 1.25 27-Feb-2005  perry nuke trailing whitespace
 1.24 04-Feb-2005  perry de-__P
 1.23 03-May-2003  wiz branches: 1.23.2; 1.23.10; 1.23.12;
DMA, not dma nor Dma.
 1.22 01-Oct-2002  petrov Adjust residual counter for wide transfers.
 1.21 23-Sep-2002  chs don't print anything when attaching as part of a FAS.
it doesn't add any information and it messes up the autoconf output.
 1.20 15-Nov-2001  lukem branches: 1.20.10;
don't need <sys/types.h> when including <sys/param.h>
 1.19 13-Nov-2001  lukem add/cleanup RCSID
 1.18 04-Jun-2001  mrg branches: 1.18.2;
fix lint exposed by GCC 3.0 20010604 (prerelease).
 1.17 08-Apr-2001  tsutsui Make sure to print "\n" at the end of the attach line on non-DEBUG case.
 1.16 07-Apr-2001  tsutsui Fix some bus_dma(9) usage:
- bus_dmamap_sync() takes offset into the dmamap, not VA.
- Use BUS_DMA_STREAMING for the data dmamap, not BUS_DMA_COHERENT.
 1.15 29-Mar-2001  petrov fas support added
 1.14 14-Nov-2000  thorpej branches: 1.14.2;
NBPG -> PAGE_SIZE
 1.13 31-Oct-2000  eeh Clean up a #define that doesn't belong. Oops. That's what I get for
working this late.
 1.12 31-Oct-2000  eeh Get the bpp driver to work properly.
 1.11 04-Jul-2000  pk enet dma: claim interrupt as appropriate.
 1.10 12-Jun-2000  mrg KNF a line.
 1.9 14-Apr-2000  mrg branches: 1.9.2;
add some casts to (u_long) to shut up gcc
 1.8 05-Jun-1999  pk branches: 1.8.2;
Cast size_t to long for printf purposes.
 1.7 20-Apr-1999  pk Remove splbio()/splserial(), which should not try to protect bus_dma*(9)
internals.
 1.6 16-Apr-1999  pk Print register contents before we modify it.
 1.5 23-Mar-1999  pk branches: 1.5.2;
Check for Sbus slave access errors.
Call bus_dma_load() with elevated priority.
 1.4 21-Sep-1998  pk Parallel port support routines.
 1.3 06-Sep-1998  pk Use the new "%b" format for the various control register bits.
 1.2 01-Sep-1998  pk Typo in device Id mask.
 1.1 29-Aug-1998  pk LSI64854 DMA engine driver.
Currently used by Lance Ethernet and NCR SCSI front-ends on sparc/sparc64.
 1.5.2.2 23-Apr-1999  perry branches: 1.5.2.2.2;
pullup 1.6->1.7 (pk)
 1.5.2.1 17-Apr-1999  pk Pull up rev 1.6 from trunk
 1.5.2.2.2.1 21-Jun-1999  thorpej Sync w/ -current.
 1.8.2.3 21-Apr-2001  bouyer Sync with HEAD
 1.8.2.2 22-Nov-2000  bouyer Sync with HEAD.
 1.8.2.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.9.2.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.14.2.5 18-Oct-2002  nathanw Catch up to -current.
 1.14.2.4 08-Jan-2002  nathanw Catch up to -current.
 1.14.2.3 14-Nov-2001  nathanw Catch up to -current.
 1.14.2.2 21-Jun-2001  nathanw Catch up to -current.
 1.14.2.1 09-Apr-2001  nathanw Catch up with -current.
 1.18.2.2 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.18.2.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.20.10.1 22-Nov-2002  tron Pull up revision 1.21-1.22 (requested by martin in ticket #948):
Adjust residual counter for wide transfers.
 1.23.12.2 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.23.12.1 12-Feb-2005  yamt sync with head.
 1.23.10.1 29-Apr-2005  kent sync with -current
 1.23.2.3 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.23.2.2 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.23.2.1 04-Feb-2005  skrll Sync with HEAD.
 1.26.2.2 27-Oct-2007  yamt sync with head.
 1.26.2.1 03-Sep-2007  yamt sync with head.
 1.27.26.1 12-Mar-2007  rmind Sync with HEAD.
 1.29.20.1 25-Oct-2007  bouyer Sync with HEAD.
 1.29.16.1 06-Nov-2007  matt sync with HEAD
 1.29.14.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.29.2.1 23-Oct-2007  ad Sync with head.
 1.30.16.2 17-Jan-2009  mjf Sync with HEAD.
 1.30.16.1 02-Jun-2008  mjf Sync with HEAD.
 1.32.4.2 04-May-2009  yamt sync with head.
 1.32.4.1 16-May-2008  yamt sync with head.
 1.32.2.1 18-May-2008  yamt sync with head.
 1.33.8.1 19-Jan-2009  skrll Sync with HEAD.
 1.34.6.1 05-Mar-2011  rmind sync with head
 1.37.18.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.37.8.1 30-Oct-2012  yamt sync with head
 1.38.38.1 10-Jun-2019  christos Sync with HEAD
 1.38.36.1 06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.7 10-Mar-2024  rillig lsi64854reg: fix snprintb formats DDMACSR_BITS and PDMACSR_BITS
 1.6 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.5 29-Mar-2001  petrov branches: 1.5.120; 1.5.122; 1.5.124;
fas support added
 1.4 21-Sep-1998  pk branches: 1.4.12; 1.4.24;
Parallel port support routines.
 1.3 06-Sep-1998  pk Use the new "%b" format for the various control register bits.
 1.2 01-Sep-1998  pk Typo in device Id mask.
 1.1 29-Aug-1998  pk LSI64854 DMA engine driver.
Currently used by Lance Ethernet and NCR SCSI front-ends on sparc/sparc64.
 1.4.24.1 09-Apr-2001  nathanw Catch up with -current.
 1.4.12.1 21-Apr-2001  bouyer Sync with HEAD
 1.5.124.1 16-May-2008  yamt sync with head.
 1.5.122.1 18-May-2008  yamt sync with head.
 1.5.120.1 02-Jun-2008  mjf Sync with HEAD.
 1.13 27-Dec-2019  msaitoh s/suport/support/
 1.12 28-Apr-2008  martin branches: 1.12.88;
Remove clause 3 and 4 from TNF licenses
 1.11 13-Apr-2008  tsutsui branches: 1.11.2; 1.11.4;
Split device_t/softc for MI ncr53c9x and some related devices,
with various cleanup.
 1.10 04-Mar-2007  christos branches: 1.10.36;
fix fallout from caddr_t changes.
 1.9 04-Mar-2007  christos Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.8 11-Dec-2005  christos branches: 1.8.26;
merge ktrace-lwp.
 1.7 31-May-2005  christos branches: 1.7.2;
avoid variable shadow.
 1.6 04-Feb-2005  perry de-__P
 1.5 03-May-2003  wiz branches: 1.5.2; 1.5.10; 1.5.12;
DMA, not dma nor Dma.
 1.4 29-Mar-2001  petrov fas support added
 1.3 21-Sep-1998  pk branches: 1.3.12; 1.3.24;
Parallel port support routines.
 1.2 31-Aug-1998  pk macro argument protection.
 1.1 29-Aug-1998  pk LSI64854 DMA engine driver.
Currently used by Lance Ethernet and NCR SCSI front-ends on sparc/sparc64.
 1.3.24.1 09-Apr-2001  nathanw Catch up with -current.
 1.3.12.1 21-Apr-2001  bouyer Sync with HEAD
 1.5.12.1 12-Feb-2005  yamt sync with head.
 1.5.10.1 29-Apr-2005  kent sync with -current
 1.5.2.2 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.5.2.1 04-Feb-2005  skrll Sync with HEAD.
 1.7.2.1 03-Sep-2007  yamt sync with head.
 1.8.26.1 12-Mar-2007  rmind Sync with HEAD.
 1.10.36.1 02-Jun-2008  mjf Sync with HEAD.
 1.11.4.1 16-May-2008  yamt sync with head.
 1.11.2.1 18-May-2008  yamt sync with head.
 1.12.88.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.2 26-Nov-2000  ad lsu -> ld, by popular request.
 1.1 08-Nov-2000  ad branches: 1.1.2;
Move lsu stuff to more logical locations, and push queueing into the lsu
driver.
 1.1.2.3 08-Dec-2000  bouyer Sync with HEAD.
 1.1.2.2 22-Nov-2000  bouyer Sync with HEAD.
 1.1.2.1 08-Nov-2000  bouyer file lsu_cac.c was added on branch thorpej_scsipi on 2000-11-22 16:03:24 +0000
 1.21 07-Sep-2024  andvar spelling and grammar fixes, mainly in comments.
 1.20 24-Dec-2021  riastradh branches: 1.20.10;
malo(4): Fix line breaks in attach output.
 1.19 16-Jun-2021  riastradh if_attach and if_initialize cannot fail, don't test return value

These were originally made failable back in 2017 when if_initialize
allocated a softint in every interface for link state changes, so
that it could fail gracefully instead of panicking:

https://mail-index.NetBSD.org/source-changes/2017/10/23/msg089053.html

However, this spawned many seldom- or never-tested error branches,
which are risky to have around. And that softint in every interface
has since been replaced by a single global workqueue, because link
state changes require thread context but not low latency or high
throughput:

https://mail-index.NetBSD.org/source-changes/2020/02/06/msg113759.html

So there is no longer any reason for if_initialize to fail. (The
subroutine if_stats_init can't fail because percpu_alloc can't fail
either.)

There is a snag: the softint_establish in if_percpuq_create could
fail, potentially leading to bad consequences later on trying to use
the softint. This change doesn't introduce any new bugs because of
the snag -- if_percpuq_attach was already broken. However, the snag
can be better addressed without spawning error branches, either by
using a single softint or making softints less scarce.

(Separate commit will change the signatures of if_attach and
if_initialize to return void, scheduled to ride whatever is the next
convenient kernel bump.)

Patch and testing on amd64 and evbmips64-eb by maya@; commit message
soliloquy, and compile-testing on evbppc/i386/earmv7hf, by me.
 1.18 29-Jan-2020  thorpej branches: 1.18.10;
Adopt <net/if_stats.h>.
 1.17 10-Nov-2019  chs branches: 1.17.2;
in many device attach paths, allocate memory with M_WAITOK instead of M_NOWAIT
and remove code to handle failures that can no longer happen.
 1.16 22-Sep-2019  kamil Reduce always true comparison in malo_cmd_set_txpower()

powerlevel is already checked for >=30 in the previous condition.

Found by the lgtm bot.
 1.15 14-Dec-2018  jakllsch use callout_destroy in malo_detach, not callout_stop
 1.14 14-Dec-2018  jakllsch always use correct function to free our copy of the microcode
 1.13 03-Sep-2018  riastradh Rename min/max -> uimin/uimax for better honesty.

These functions are defined on unsigned int. The generic name
min/max should not silently truncate to 32 bits on 64-bit systems.
This is purely a name change -- no functional change intended.

HOWEVER! Some subsystems have

#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))

even though our standard name for that is MIN/MAX. Although these
may invite multiple evaluation bugs, these do _not_ cause integer
truncation.

To avoid `fixing' these cases, I first changed the name in libkern,
and then compile-tested every file where min/max occurred in order to
confirm that it failed -- and thus confirm that nothing shadowed
min/max -- before changing it.

I have left a handful of bootloaders that are too annoying to
compile-test, and some dead code:

cobalt ews4800mips hp300 hppa ia64 luna68k vax
acorn32/if_ie.c (not included in any kernels)
macppc/if_gm.c (superseded by gem(4))

It should be easy to fix the fallout once identified -- this way of
doing things fails safe, and the goal here, after all, is to _avoid_
silent integer truncations, not introduce them.

Maybe one day we can reintroduce min/max as type-generic things that
never silently truncate. But we should avoid doing that for a while,
so that existing code has a chance to be detected by the compiler for
conversion to uimin/uimax without changing the semantics until we can
properly audit it all. (Who knows, maybe in some cases integer
truncation is actually intended!)
 1.12 26-Jun-2018  msaitoh branches: 1.12.2;
Implement the BPF direction filter (BIOC[GS]DIRECTION). It provides backward
compatibility with BIOC[GS]SEESENT ioctl. The userland interface is the same
as FreeBSD.

This change also fixes a bug that the direction is misunderstand on some
environment by passing the direction to bpf_mtap*() instead of checking
m->m_pkthdr.rcvif.
 1.11 26-Jun-2018  msaitoh bpf_mtap*() after ieee80211_encap() should be bpf_mtap3() rather than
bpf_mtap(). bpf_mtap3() is for raw bpf.
 1.10 23-Oct-2017  msaitoh branches: 1.10.2;
If if_initialize() failed in the attach function, free resources and return.
 1.9 02-Feb-2017  nonaka branches: 1.9.6;
wlan interfaces make interrupt routine running on softint context.

see http://mail-index.netbsd.org/tech-kern/2016/12/06/msg021281.html

tested device:
* ath at pci: AR5212, AR5424
* athn at pci: AR9287
* ipw at pci: 2100BG
* iwi at pci: 2915ABG
* iwm at pci: 3165, 7260, 8260
* iwn at pci: 4945, 6235
* ral at pci: RT2560
* rtwn at pci: RTL8192CE
 1.8 10-Jun-2016  ozaki-r branches: 1.8.2; 1.8.4;
Introduce m_set_rcvif and m_reset_rcvif

The API is used to set (or reset) a received interface of a mbuf.
They are counterpart of m_get_rcvif, which will come in another
commit, hide internal of rcvif operation, and reduce the diff of
the upcoming change.

No functional change.
 1.7 26-May-2016  ozaki-r Introduce M_CLEARCTX and use it instead of open-coding rcvif

No functional change.
 1.6 26-May-2016  ozaki-r Use M_GETCTX

No functional change.
 1.5 11-Mar-2016  macallan malo_rx_desc::status is uint8_t, so don't try to endian-twiddle it
 1.4 11-Mar-2016  christos PR/50948: David Binderman: Fix misplaced parens
 1.3 05-Aug-2012  degroote branches: 1.3.2; 1.3.4; 1.3.18;
Add pmf(9) handler to malo(4) wireless driver
 1.2 30-Jul-2012  degroote Add missing $NetBSD$ tags and __KERNEL_RCSID().
 1.1 30-Jul-2012  degroote Add malo(4)@pci driver for Marvell Libertas wireless adaptor

Ported from OpenBSD
Known issues :
- contrary to OpenBSD one, only support pci at the moment, because I don't
have the necessary hardware to test PCMCIA / CARDUS Marvell Card
- not connected to pmf(9) (unable to test it)
 1.3.18.4 05-Feb-2017  skrll Sync with HEAD
 1.3.18.3 09-Jul-2016  skrll Sync with HEAD
 1.3.18.2 29-May-2016  skrll Sync with HEAD
 1.3.18.1 19-Mar-2016  skrll Sync with HEAD
 1.3.4.2 30-Oct-2012  yamt sync with head
 1.3.4.1 05-Aug-2012  yamt file malo.c was added on branch yamt-pagecache on 2012-10-30 17:21:05 +0000
 1.3.2.1 03-Dec-2017  jdolecek update from HEAD
 1.8.4.1 21-Apr-2017  bouyer Sync with HEAD
 1.8.2.1 20-Mar-2017  pgoyette Sync with HEAD
 1.9.6.2 31-Jul-2018  martin Pull up following revision(s) (requested by msaitoh in ticket #952):

sys/dev/ic/malo.c: revision 1.11

bpf_mtap*() after ieee80211_encap() should be bpf_mtap3() rather than
bpf_mtap(). bpf_mtap3() is for raw bpf.
 1.9.6.1 10-Dec-2017  snj Pull up following revision(s) (requested by msaitoh in ticket #427):
sys/arch/amiga/dev/if_bah_zbus.c: 1.17
sys/arch/arm/broadcom/bcm53xx_eth.c: 1.30
sys/arch/powerpc/booke/dev/pq3etsec.c: 1.32
sys/arch/usermode/dev/if_veth.c: 1.9
sys/dev/ic/an.c: 1.66
sys/dev/ic/athn.c: 1.17
sys/dev/ic/atw.c: 1.162
sys/dev/ic/bwi.c: 1.33
sys/dev/ic/dwc_gmac.c: 1.41-1.42
sys/dev/ic/malo.c: 1.10
sys/dev/ic/rt2560.c: 1.31
sys/dev/ic/rt2661.c: 1.36
sys/dev/ic/rt2860.c: 1.29
sys/dev/ic/rtw.c: 1.127
sys/dev/ic/rtwvar.h: 1.46
sys/dev/ic/smc90cx6.c: 1.71
sys/dev/ic/smc90cx6var.h: 1.12
sys/dev/ic/wi.c: 1.244
sys/dev/pci/if_ipw.c: 1.66
sys/dev/pci/if_iwi.c: 1.104
sys/dev/pci/if_iwm.c: 1.76
sys/dev/pci/if_iwn.c: 1.86
sys/dev/pci/if_rtwn.c: 1.13
sys/dev/pci/if_wm.c: 1.541
sys/dev/pci/if_wpi.c: 1.79
sys/dev/pci/ixgbe/ixgbe.c: 1.106
sys/dev/pci/ixgbe/ixv.c: 1.73 via patch
sys/dev/pcmcia/if_malo_pcmcia.c: 1.15
sys/dev/scsipi/if_se.c: 1.95
sys/dev/usb/if_upl.c: 1.60
sys/net/if.c: 1.396
sys/net/if.h: 1.241
sys/net/if_arc.h: 1.23
sys/net/if_arcsubr.c: 1.78
sys/net/if_bridge.c: 1.136-1.137
sys/net/if_etherip.c: 1.39
sys/net/if_faith.c: 1.56
sys/net/if_gif.c: 1.131
sys/net/if_loop.c: 1.96
sys/net/if_mpls.c: 1.30
sys/net/if_pppoe.c: 1.129
sys/net/if_srt.c: 1.27
sys/net/if_stf.c: 1.102
sys/net/if_tap.c: 1.100
sys/net/if_vlan.c: 1.105
sys/netinet/ip_carp.c: 1.91
sys/rump/net/lib/libshmif/if_shmem.c: 1.73-1.74
sys/rump/net/lib/libvirtif/if_virt.c: 1.55-1.56
if_initalize() and if_attach() failed when resource allocation failed
(e.g. allocating softint). Without this change, it panics. It's bad because
resource shortage really occured when a lot of pseudo interface is created.
To avoid this problem, don't panic and change return value of if_initialize()
and if_attach() to int. Caller fanction will be recover from error cleanly by
checking the return value.
Return if bah_attach_subr() failed.
If if_attach() failed in the attach function, return.
- If if_initialize() failed in the attach function, free resources and return.
- Add some missing frees in bridge_clone_destroy().
- KNF
If error occured in bcmeth_ccb_attach(), free resources and return.
If error occured in pq3etsec_attach(), free resources and return.
If error occured in the attach function, free resources and return.
- If if_initialize() failed in athn_attach(), free resources and return.
- Add missing pmf_event_deregister() in athn_detach().
- Free resources correctly on some errors in atw_attach().
- Use apint*() insread of printf() in the attach function.
If if_initialize() failed in the attach function, return.
- If if_initialize() failed in the attach function, free resources and return.
- Add missing dwc_gmac_free_dma_rings() and mutex_destroy() when attach
failed.
- If if_initialize() failed in the attach function, free resources and return.
- ifp is always not NULL in iwi_detach(). Check correctly with ifp->if_softc.
- If if_initialize() failed in the attach function, free resources and return.
- Fix error path in the attach function correctly.
If if_initialize() failed in the attach function, free resources and return.
If if_attach() failed in the attach function, free resources and return.
- If if_initialize() failed in the attach function, free resources and return.
- KNF
- If if_attach() failed in the attach function, free resources and return.
- KNF
Fix compile error.
Fix compile error.
We don't need '&mii', but just 'mii' for mii_detach().
Don't free sc_rthash twice
 1.10.2.3 26-Dec-2018  pgoyette Sync with HEAD, resolve a few conflicts
 1.10.2.2 06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.10.2.1 28-Jul-2018  pgoyette Sync with HEAD
 1.12.2.3 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.12.2.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.12.2.1 10-Jun-2019  christos Sync with HEAD
 1.17.2.1 29-Feb-2020  ad Sync with head.
 1.18.10.1 17-Jun-2021  thorpej Sync w/ HEAD.
 1.20.10.1 02-Aug-2025  perseant Sync with HEAD
 1.1 30-Jul-2012  degroote branches: 1.1.4;
Add malo(4)@pci driver for Marvell Libertas wireless adaptor

Ported from OpenBSD
Known issues :
- contrary to OpenBSD one, only support pci at the moment, because I don't
have the necessary hardware to test PCMCIA / CARDUS Marvell Card
- not connected to pmf(9) (unable to test it)
 1.1.4.2 30-Oct-2012  yamt sync with head
 1.1.4.1 30-Jul-2012  yamt file maloreg.h was added on branch yamt-pagecache on 2012-10-30 17:21:05 +0000
 1.4 05-Oct-2019  mrg remove __packed attribute from struct ieee80211_radiotap_header
and all the structures that include it.

this should not change anything while avoiding packed vs alignment
warnings from GCC 8, and potentially pessimised code generation
due to the packed marker (there are no misaligned members, just
that the per-device parts may end unaligned.)

all consumers of these members are done from the properly aligned
packet members directly, or, as a union with a 64 byte member,
also properly aligned. codegen didn't appear to change, except
for the definition of sizeof(struct driver_[rt]x_radiotap_header)
in debug info, which is not directly used anywhere.
 1.3 02-Feb-2017  nonaka branches: 1.3.14;
wlan interfaces make interrupt routine running on softint context.

see http://mail-index.netbsd.org/tech-kern/2016/12/06/msg021281.html

tested device:
* ath at pci: AR5212, AR5424
* athn at pci: AR9287
* ipw at pci: 2100BG
* iwi at pci: 2915ABG
* iwm at pci: 3165, 7260, 8260
* iwn at pci: 4945, 6235
* ral at pci: RT2560
* rtwn at pci: RTL8192CE
 1.2 05-Aug-2012  degroote branches: 1.2.2; 1.2.4; 1.2.18; 1.2.22; 1.2.26;
Add pmf(9) handler to malo(4) wireless driver
 1.1 30-Jul-2012  degroote Add malo(4)@pci driver for Marvell Libertas wireless adaptor

Ported from OpenBSD
Known issues :
- contrary to OpenBSD one, only support pci at the moment, because I don't
have the necessary hardware to test PCMCIA / CARDUS Marvell Card
- not connected to pmf(9) (unable to test it)
 1.2.26.1 21-Apr-2017  bouyer Sync with HEAD
 1.2.22.1 20-Mar-2017  pgoyette Sync with HEAD
 1.2.18.1 05-Feb-2017  skrll Sync with HEAD
 1.2.4.2 30-Oct-2012  yamt sync with head
 1.2.4.1 05-Aug-2012  yamt file malovar.h was added on branch yamt-pagecache on 2012-10-30 17:21:05 +0000
 1.2.2.1 03-Dec-2017  jdolecek update from HEAD
 1.3.14.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.7 19-Oct-2007  ad machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.6 09-Jul-2007  ad branches: 1.6.6; 1.6.8; 1.6.12;
Merge some of the less invasive changes from the vmlocking branch:

- kthread, callout, devsw API changes
- select()/poll() improvements
- miscellaneous MT safety improvements
 1.5 04-Mar-2007  christos branches: 1.5.2; 1.5.4;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.4 12-Dec-2005  christos branches: 1.4.26;
more proc -> lwp
 1.3 11-Dec-2005  christos merge ktrace-lwp.
 1.2 27-Feb-2005  perry branches: 1.2.4; 1.2.6;
nuke trailing whitespace
 1.1 31-Jan-2005  joff branches: 1.1.2; 1.1.4;
Matrix keypad wskbd(4) support. Matrix keypads are cheap/rugged user input
devices found in many embedded systems. They must be polled and
debounced in software. Should be able to handle any size matrix keypad, but
only tested with a 4x4 (16-key) device attached to the TS-7200 ARM embedded
board via the DIO header.
 1.1.4.3 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.1.4.2 12-Feb-2005  yamt sync with head.
 1.1.4.1 31-Jan-2005  yamt file matrixkp_subr.c was added on branch yamt-km on 2005-02-12 18:17:43 +0000
 1.1.2.3 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.1.2.2 04-Feb-2005  skrll Sync with HEAD.
 1.1.2.1 31-Jan-2005  skrll file matrixkp_subr.c was added on branch ktrace-lwp on 2005-02-04 11:45:26 +0000
 1.2.6.3 27-Oct-2007  yamt sync with head.
 1.2.6.2 03-Sep-2007  yamt sync with head.
 1.2.6.1 21-Jun-2006  yamt sync with head.
 1.2.4.2 29-Apr-2005  kent sync with -current
 1.2.4.1 27-Feb-2005  kent file matrixkp_subr.c was added on branch kent-audio2 on 2005-04-29 11:28:51 +0000
 1.4.26.1 12-Mar-2007  rmind Sync with HEAD.
 1.5.4.1 11-Jul-2007  mjf Sync with head.
 1.5.2.2 23-Oct-2007  ad Sync with head.
 1.5.2.1 01-Jul-2007  ad Adapt to callout API change.
 1.6.12.1 25-Oct-2007  bouyer Sync with HEAD.
 1.6.8.1 06-Nov-2007  matt sync with HEAD
 1.6.6.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.5 28-Jul-2012  matt extern is your friend. especially for variables in header files.
 1.4 12-May-2009  cegger branches: 1.4.12;
struct device * -> device_t, no functional changes intended.
 1.3 04-Mar-2007  christos branches: 1.3.40; 1.3.56;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.2 12-Dec-2005  christos branches: 1.2.26;
more proc -> lwp
 1.1 31-Jan-2005  joff branches: 1.1.2; 1.1.4; 1.1.10; 1.1.12;
Matrix keypad wskbd(4) support. Matrix keypads are cheap/rugged user input
devices found in many embedded systems. They must be polled and
debounced in software. Should be able to handle any size matrix keypad, but
only tested with a 4x4 (16-key) device attached to the TS-7200 ARM embedded
board via the DIO header.
 1.1.12.2 03-Sep-2007  yamt sync with head.
 1.1.12.1 21-Jun-2006  yamt sync with head.
 1.1.10.2 29-Apr-2005  kent sync with -current
 1.1.10.1 31-Jan-2005  kent file matrixkpvar.h was added on branch kent-audio2 on 2005-04-29 11:28:51 +0000
 1.1.4.2 12-Feb-2005  yamt sync with head.
 1.1.4.1 31-Jan-2005  yamt file matrixkpvar.h was added on branch yamt-km on 2005-02-12 18:17:43 +0000
 1.1.2.2 04-Feb-2005  skrll Sync with HEAD.
 1.1.2.1 31-Jan-2005  skrll file matrixkpvar.h was added on branch ktrace-lwp on 2005-02-04 11:45:26 +0000
 1.2.26.1 12-Mar-2007  rmind Sync with HEAD.
 1.3.56.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.3.40.1 16-May-2009  yamt sync with head
 1.4.12.1 30-Oct-2012  yamt sync with head
 1.8 19-Oct-2009  rmind Drop 3rd and 4th clauses from David Young's license.
Reviewed and approved by dyoung@ (copyright holder).
 1.7 31-Aug-2006  dyoung branches: 1.7.56;
Per discussion on tech-kern and tech-userlevel, move the bit-twiddling
macros, __BIT, __BITS, SHIFTIN, SHIFTOUT, and __arraycount() from
lib/libkern/libkern.h to sys/cdefs.h. Add a __-prefix to SHIFTIN
and SHIFTOUT, and add a manual page for the bit-twiddling macros,
bits(3).

Make the __BIT and __BITS macros "widthless," as best I can, by
changing their type to uintmax_t from uint32_t. XXX The manual
page lags this change by a bit.

Define __PRIxBIT and __PRIxBITS printf(3) format strings.
 1.6 14-May-2006  elad integrate kauth.
 1.5 08-Mar-2006  dyoung Change macro names to avoid collisions:

BIT -> __BIT
BITS -> __BITS
 1.4 08-Mar-2006  dyoung Move my bit-twiddling macros to libkern.h from my drivers, where
I had duplicated them. Improve the macros' names. Simplify their
implementation.

A brief description of each macro is below.

BIT(n): Return a bitmask with bit m set, where the least
significant bit is bit 0.

BITS(m, n): Return a bitmask with bits m through n, inclusive,
set. It does not matter whether m>n or m<=n.
The least significant bit is bit 0.

A "bitfield" is a span of consecutive bits defined by a
bitmask, where 1s select the bits in the bitfield. SHIFTIN,
SHIFTOUT, and SHIFTOUT_MASK help read and write bitfields
from device registers.

SHIFTIN(v, mask): Left-shift bits `v' into the bitfield
defined by `mask', and return them. No
side-effects.

SHIFTOUT(v, mask): Extract and return the bitfield selected
by `mask' from `v', right-shifting the
bits so that the rightmost selected bit
is at bit 0. No side-effects.

SHIFTOUT_MASK(mask): Right-shift the bits in `mask' so that
the rightmost non-zero bit is at bit
0. This is useful for finding the
greatest unsigned value that a bitfield
can hold. No side-effects. Note that
SHIFTOUT_MASK(m) = SHIFTOUT(m, m).

Examples:

/*
* Register definitions taken from the RFMD RF3000 manual.
*/
#define RF3000_GAINCTL 0x11 /* TX variable gain control */
#define RF3000_GAINCTL_TXVGC_MASK BITS(7, 2)
#define RF3000_GAINCTL_SCRAMBLER BIT(1)

/*
* Shift the transmit power into the transmit-power field of the
* gain-control register and write it to the baseband processor.
*/
atw_rf3000_write(sc, RF3000_GAINCTL,
SHIFTIN(txpower, RF3000_GAINCTL_TXVGC_MASK));


/*
* Register definitions taken from the ADMtek ADM8211 manual.
*
*/
#define ATW_RXSTAT_OWN BIT(31) /* 1: NIC may fill descriptor */
/* ... */
#define ATW_RXSTAT_DA1 BIT(17) /* DA bit 1, admin'd address */
#define ATW_RXSTAT_DA0 BIT(16) /* DA bit 0, group address */
#define ATW_RXSTAT_RXDR_MASK BITS(15,12) /* RX data rate */
#define ATW_RXSTAT_FL_MASK BITS(11,0) /* RX frame length, last
* descriptor only
*/

/* Extract the frame length from the Rx descriptor's
* status field.
*/
len = SHIFTOUT(rxstat, ATW_RXSTAT_FL_MASK);
 1.3 11-Dec-2005  christos branches: 1.3.4; 1.3.6; 1.3.8; 1.3.10;
merge ktrace-lwp.
 1.2 27-Feb-2005  perry branches: 1.2.4;
nuke trailing whitespace
 1.1 26-Sep-2004  dyoung branches: 1.1.2; 1.1.6; 1.1.8;
Add work-in-progress driver rtw(4) for Realtek RTL8180 MAC/baseband.

Add register definitions for Maxim MAX2820 and Philips SA2400 radio
front-ends.
 1.1.8.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.1.6.1 29-Apr-2005  kent sync with -current
 1.1.2.3 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.1.2.2 19-Oct-2004  skrll Sync with HEAD
 1.1.2.1 26-Sep-2004  skrll file max2820reg.h was added on branch ktrace-lwp on 2004-10-19 15:56:55 +0000
 1.2.4.2 30-Dec-2006  yamt sync with head.
 1.2.4.1 21-Jun-2006  yamt sync with head.
 1.3.10.1 19-Apr-2006  elad sync with head.
 1.3.8.2 03-Sep-2006  yamt sync with head.
 1.3.8.1 13-Mar-2006  yamt sync with head.
 1.3.6.1 22-Apr-2006  simonb Sync with head.
 1.3.4.1 09-Sep-2006  rpaulo sync with head
 1.7.56.1 11-Mar-2010  yamt sync with head
 1.35 31-Jul-2021  andvar fix more typos in style found one in file - check/fix them all.
 1.34 04-Feb-2020  thorpej branches: 1.34.10;
Use ifmedia_fini().
 1.33 29-Jan-2020  thorpej Adopt <net/if_stats.h>.
 1.32 29-May-2019  msaitoh branches: 1.32.4;
Even if we don't use MII(4), use the common path of SIOC[GS]IFMEDIA in
sys/net/if_ethersubr.c if we can.
- Add ec_ifmedia into struct ethercom.
- ec_mii in struct ethercom is kept and used as it is. It might be used in
future. Note that some Ethernet drivers which _DOESN'T_ use mii(4) use
ec_mii for keeping the if_media. Those should be changed in future.
 1.31 23-May-2019  msaitoh Whitespace fix (mainly tabify).
 1.30 24-Apr-2019  msaitoh KNF. No functional change.
 1.29 05-Feb-2019  msaitoh Remove very old IFF_NOTRAILERS flag.
 1.28 26-Jun-2018  msaitoh branches: 1.28.2;
Implement the BPF direction filter (BIOC[GS]DIRECTION). It provides backward
compatibility with BIOC[GS]SEESENT ioctl. The userland interface is the same
as FreeBSD.

This change also fixes a bug that the direction is misunderstand on some
environment by passing the direction to bpf_mtap*() instead of checking
m->m_pkthdr.rcvif.
 1.27 22-Jun-2018  msaitoh It's not required to include net/bpfdesc.h. Remove it.
 1.26 20-Feb-2017  ozaki-r branches: 1.26.6; 1.26.12;
Apply deferred if_start to more drivers
 1.25 15-Dec-2016  ozaki-r branches: 1.25.2;
Move bpf_mtap and if_ipackets++ on Rx of each driver to percpuq if_input

The benefits of the change are:
- We can reduce codes
- We can provide the same behavior between drivers
- Where/When if_ipackets is counted up
- Note that some drivers still update packet statistics in their own
way (periodical update)
- Moved bpf_mtap run in softint
- This makes it easy to MP-ify bpf

Proposed on tech-kern and tech-net
 1.24 10-Jun-2016  ozaki-r branches: 1.24.2;
Introduce m_set_rcvif and m_reset_rcvif

The API is used to set (or reset) a received interface of a mbuf.
They are counterpart of m_get_rcvif, which will come in another
commit, hide internal of rcvif operation, and reduce the diff of
the upcoming change.

No functional change.
 1.23 09-Feb-2016  ozaki-r Introduce softint-based if_input

This change intends to run the whole network stack in softint context
(or normal LWP), not hardware interrupt context. Note that the work is
still incomplete by this change; to that end, we also have to softint-ify
if_link_state_change (and bpf) which can still run in hardware interrupt.

This change softint-ifies at ifp->if_input that is called from
each device driver (and ieee80211_input) to ensure Layer 2 runs
in softint (e.g., ether_input and bridge_input). To this end,
we provide a framework (called percpuq) that utlizes softint(9)
and percpu ifqueues. With this patch, rxintr of most drivers just
queues received packets and schedules a softint, and the softint
dequeues packets and does rest packet processing.

To minimize changes to each driver, percpuq is allocated in struct
ifnet for now and that is initialized by default (in if_attach).
We probably have to move percpuq to softc of each driver, but it's
future work. At this point, only wm(4) has percpuq in its softc
as a reference implementation.

Additional information including performance numbers can be found
in the thread at tech-kern@ and tech-net@:
http://mail-index.netbsd.org/tech-kern/2016/01/14/msg019997.html

Acknowledgment: riastradh@ greatly helped this work.
Thank you very much!
 1.22 13-Apr-2015  riastradh Convert sys/dev to use <sys/rndsource.h>.
 1.21 10-Aug-2014  tls branches: 1.21.4;
Merge tls-earlyentropy branch into HEAD.
 1.20 27-Oct-2012  chs branches: 1.20.10;
split device_t/softc for all remaining drivers.
replace "struct device *" with "device_t".
use device_xname(), device_unit(), etc.
 1.19 02-Feb-2012  tls branches: 1.19.6;
Entropy-pool implementation move and cleanup.

1) Move core entropy-pool code and source/sink/sample management code
to sys/kern from sys/dev.

2) Remove use of NRND as test for presence of entropy-pool code throughout
source tree.

3) Remove use of RND_ENABLED in device drivers as microoptimization to
avoid expensive operations on disabled entropy sources; make the
rnd_add calls do this directly so all callers benefit.

4) Fix bug in recent rnd_add_data()/rnd_add_uint32() changes that might
have lead to slight entropy overestimation for some sources.

5) Add new source types for environmental sensors, power sensors, VM
system events, and skew between clocks, with a sample implementation
for each.

ok releng to go in before the branch due to the difficulty of later
pullup (widespread #ifdef removal and moved files). Tested with release
builds on amd64 and evbarm and live testing on amd64.
 1.18 05-Apr-2010  joerg branches: 1.18.8; 1.18.12;
Push the bpf_ops usage back into bpf.h. Push the common ifp->if_bpf
check into the inline functions as well the fourth argument for
bpf_attach.
 1.17 19-Jan-2010  pooka branches: 1.17.2; 1.17.4;
Redefine bpf linkage through an always present op vector, i.e.
#if NBPFILTER is no longer required in the client. This change
doesn't yet add support for loading bpf as a module, since drivers
can register before bpf is attached. However, callers of bpf can
now be modularized.

Dynamically loadable bpf could probably be done fairly easily with
coordination from the stub driver and the real driver by registering
attachments in the stub before the real driver is loaded and doing
a handoff. ... and I'm not going to ponder the depths of unload
here.

Tested with i386/MONOLITHIC, modified MONOLITHIC without bpf and rump.
 1.16 06-Dec-2009  dyoung Simplify device-activation hooks.
 1.15 12-May-2009  cegger struct device * -> device_t, no functional changes intended.
 1.14 14-Mar-2009  dsl Change about 4500 of the K&R function definitions to ANSI ones.
There are still about 1600 left, but they have ',' or /* ... */
in the actual variable definitions - which my awk script doesn't handle.
There are also many that need () -> (void).
(The script does handle misordered arguments.)
 1.13 14-Mar-2009  dsl Remove all the __P() from sys (excluding sys/dist)
Diff checked with grep and MK1 eyeball.
i386 and amd64 GENERIC and sys still build.
 1.12 07-Nov-2008  dyoung branches: 1.12.4;
*** Summary ***

When a link-layer address changes (e.g., ifconfig ex0 link
02:de:ad:be:ef:02 active), send a gratuitous ARP and/or a Neighbor
Advertisement to update the network-/link-layer address bindings
on our LAN peers.

Refuse a change of ethernet address to the address 00:00:00:00:00:00
or to any multicast/broadcast address. (Thanks matt@.)

Reorder ifnet ioctl operations so that driver ioctls may inherit
the functions of their "class"---ether_ioctl(), fddi_ioctl(), et
cetera---and the class ioctls may inherit from the generic ioctl,
ifioctl_common(), but both driver- and class-ioctls may override
the generic behavior. Make network drivers share more code.

Distinguish a "factory" link-layer address from others for the
purposes of both protecting that address from deletion and computing
EUI64.

Return consistent, appropriate error codes from network drivers.

Improve readability. KNF.

*** Details ***

In if_attach(), always initialize the interface ioctl routine,
ifnet->if_ioctl, if the driver has not already initialized it.
Delete if_ioctl == NULL tests everywhere else, because it cannot
happen.

In the ioctl routines of network interfaces, inherit common ioctl
behaviors by calling either ifioctl_common() or whichever ioctl
routine is appropriate for the class of interface---e.g., ether_ioctl()
for ethernets.

Stop (ab)using SIOCSIFADDR and start to use SIOCINITIFADDR. In
the user->kernel interface, SIOCSIFADDR's argument was an ifreq,
but on the protocol->ifnet interface, SIOCSIFADDR's argument was
an ifaddr. That was confusing, and it would work against me as I
make it possible for a network interface to overload most ioctls.
On the protocol->ifnet interface, replace SIOCSIFADDR with
SIOCINITIFADDR. In ifioctl(), return EPERM if userland tries to
invoke SIOCINITIFADDR.

In ifioctl(), give the interface the first shot at handling most
interface ioctls, and give the protocol the second shot, instead
of the other way around. Finally, let compatibility code (COMPAT_OSOCK)
take a shot.

Pull device initialization out of switch statements under
SIOCINITIFADDR. For example, pull ..._init() out of any switch
statement that looks like this:

switch (...->sa_family) {
case ...:
..._init();
...
break;
...
default:
..._init();
...
break;
}

Rewrite many if-else clauses that handle all permutations of IFF_UP
and IFF_RUNNING to use a switch statement,

switch (x & (IFF_UP|IFF_RUNNING)) {
case 0:
...
break;
case IFF_RUNNING:
...
break;
case IFF_UP:
...
break;
case IFF_UP|IFF_RUNNING:
...
break;
}

unifdef lots of code containing #ifdef FreeBSD, #ifdef NetBSD, and
#ifdef SIOCSIFMTU, especially in fwip(4) and in ndis(4).

In ipw(4), remove an if_set_sadl() call that is out of place.

In nfe(4), reuse the jumbo MTU logic in ether_ioctl().

Let ethernets register a callback for setting h/w state such as
promiscuous mode and the multicast filter in accord with a change
in the if_flags: ether_set_ifflags_cb() registers a callback that
returns ENETRESET if the caller should reset the ethernet by calling
if_init(), 0 on success, != 0 on failure. Pull common code from
ex(4), gem(4), nfe(4), sip(4), tlp(4), vge(4) into ether_ioctl(),
and register if_flags callbacks for those drivers.

Return ENOTTY instead of EINVAL for inappropriate ioctls. In
zyd(4), use ENXIO instead of ENOTTY to indicate that the device is
not any longer attached.

Add to if_set_sadl() a boolean 'factory' argument that indicates
whether a link-layer address was assigned by the factory or some
other source. In a comment, recommend using the factory address
for generating an EUI64, and update in6_get_hw_ifid() to prefer a
factory address to any other link-layer address.

Add a routing message, RTM_LLINFO_UPD, that tells protocols to
update the binding of network-layer addresses to link-layer addresses.
Implement this message in IPv4 and IPv6 by sending a gratuitous
ARP or a neighbor advertisement, respectively. Generate RTM_LLINFO_UPD
messages on a change of an interface's link-layer address.

In ether_ioctl(), do not let SIOCALIFADDR set a link-layer address
that is broadcast/multicast or equal to 00:00:00:00:00:00.

Make ether_ioctl() call ifioctl_common() to handle ioctls that it
does not understand.

In gif(4), initialize if_softc and use it, instead of assuming that
the gif_softc and ifp overlap.

Let ifioctl_common() handle SIOCGIFADDR.

Sprinkle rtcache_invariants(), which checks on DIAGNOSTIC kernels
that certain invariants on a struct route are satisfied.

In agr(4), rewrite agr_ioctl_filter() to be a bit more explicit
about the ioctls that we do not allow on an agr(4) member interface.

bzero -> memset. Delete unnecessary casts to void *. Use
sockaddr_in_init() and sockaddr_in6_init(). Compare pointers with
NULL instead of "testing truth". Replace some instances of (type
*)0 with NULL. Change some K&R prototypes to ANSI C, and join
lines.
 1.11 08-Apr-2008  cegger branches: 1.11.4; 1.11.10; 1.11.12;
use aprint_*_dev and device_xname
 1.10 19-Oct-2007  ad branches: 1.10.16;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.9 04-Mar-2007  christos branches: 1.9.2; 1.9.14; 1.9.16; 1.9.20;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.8 16-Nov-2006  christos branches: 1.8.4;
__unused removal on arguments; approved by core.
 1.7 12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.6 07-Sep-2006  dogcow branches: 1.6.2; 1.6.4;
remove more vestiges of CCITT, LLC, HDLC, NS, and NSIP.
 1.5 11-May-2006  mrg quell GCC 4.1 uninitialised variable warnings.
 1.4 10-May-2006  skrll Fix a bunch of cast lvalues.
 1.3 11-Dec-2005  christos branches: 1.3.4; 1.3.6; 1.3.8; 1.3.10; 1.3.12;
merge ktrace-lwp.
 1.2 03-Apr-2005  jdolecek branches: 1.2.2; 1.2.4; 1.2.10;
white space cleanup, some KNF, long line wrapup
 1.1 03-Apr-2005  jdolecek Add driver for MCA Tiara LANCard / Fujitsu mb86950 EtherStar. Driver provided
in PR kern/26899 by Dave Barnes.
 1.2.10.2 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.2.10.1 03-Apr-2005  skrll file mb86950.c was added on branch ktrace-lwp on 2005-11-10 14:04:15 +0000
 1.2.4.4 27-Oct-2007  yamt sync with head.
 1.2.4.3 03-Sep-2007  yamt sync with head.
 1.2.4.2 30-Dec-2006  yamt sync with head.
 1.2.4.1 21-Jun-2006  yamt sync with head.
 1.2.2.2 29-Apr-2005  kent sync with -current
 1.2.2.1 03-Apr-2005  kent file mb86950.c was added on branch kent-audio2 on 2005-04-29 11:28:51 +0000
 1.3.12.1 24-May-2006  tron Merge 2006-05-24 NetBSD-current into the "peter-altq" branch.
 1.3.10.1 11-May-2006  elad sync with head
 1.3.8.2 14-Sep-2006  yamt sync with head.
 1.3.8.1 24-May-2006  yamt sync with head.
 1.3.6.1 01-Jun-2006  kardel Sync with head.
 1.3.4.1 09-Sep-2006  rpaulo sync with head
 1.6.4.2 10-Dec-2006  yamt sync with head.
 1.6.4.1 22-Oct-2006  yamt sync with head
 1.6.2.1 18-Nov-2006  ad Sync with head.
 1.8.4.1 12-Mar-2007  rmind Sync with HEAD.
 1.9.20.1 25-Oct-2007  bouyer Sync with HEAD.
 1.9.16.1 06-Nov-2007  matt sync with HEAD
 1.9.14.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.9.2.1 23-Oct-2007  ad Sync with head.
 1.10.16.2 17-Jan-2009  mjf Sync with HEAD.
 1.10.16.1 02-Jun-2008  mjf Sync with HEAD.
 1.11.12.2 28-Apr-2009  skrll Sync with HEAD.
 1.11.12.1 19-Jan-2009  skrll Sync with HEAD.
 1.11.10.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.11.4.4 11-Aug-2010  yamt sync with head.
 1.11.4.3 11-Mar-2010  yamt sync with head
 1.11.4.2 16-May-2009  yamt sync with head
 1.11.4.1 04-May-2009  yamt sync with head.
 1.12.4.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.17.4.1 30-May-2010  rmind sync with head
 1.17.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.18.12.1 18-Feb-2012  mrg merge to -current.
 1.18.8.2 30-Oct-2012  yamt sync with head
 1.18.8.1 17-Apr-2012  yamt sync with head
 1.19.6.3 03-Dec-2017  jdolecek update from HEAD
 1.19.6.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.19.6.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.20.10.1 07-Apr-2014  tls Be a little more clear and consistent about harvesting entropy from devices:

1) deprecate RND_FLAG_NO_ESTIMATE

2) define RND_FLAG_COLLECT_TIME, RND_FLAG_COLLECT_VALUE

3) define RND_FLAG_ESTIMATE_TIME, RND_FLAG_ESTIMATE_VALUE

4) define RND_FLAG_DEFAULT: RND_FLAG_COLLECT_TIME|
RND_FLAG_COLLECT_VALUE|RND_FLAG_ESTIMATE_TIME

5) Make entropy harvesting from environmental sensors a little more generic
and remove it from individual sensor drivers.

6) Remove individual open-coded delta-estimators for values from a few
places in the tree (uvm, environmental drivers).

7) 0 -> RND_FLAG_DEFAULT, actually gather entropy from various drivers
that had stubbed out code, other minor cleanups.
 1.21.4.5 28-Aug-2017  skrll Sync with HEAD
 1.21.4.4 05-Feb-2017  skrll Sync with HEAD
 1.21.4.3 09-Jul-2016  skrll Sync with HEAD
 1.21.4.2 19-Mar-2016  skrll Sync with HEAD
 1.21.4.1 06-Jun-2015  skrll Sync with HEAD
 1.24.2.2 20-Mar-2017  pgoyette Sync with HEAD
 1.24.2.1 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.25.2.1 21-Apr-2017  bouyer Sync with HEAD
 1.26.12.2 28-Jul-2018  pgoyette Sync with HEAD
 1.26.12.1 25-Jun-2018  pgoyette Sync with HEAD
 1.26.6.1 26-Jul-2018  snj Pull up following revision(s) (requested by msaitoh in ticket #938):
sys/arch/acorn32/podulebus/if_ie.c: revision 1.41
sys/arch/amiga/dev/if_es.c: revision 1.58
sys/arch/amiga/dev/if_qn.c: revision 1.45
sys/arch/arm/at91/at91emac.c: revision 1.20
sys/arch/arm/ep93xx/epe.c: revision 1.37
sys/arch/emips/ebus/if_le_ebus.c: revision 1.14
sys/arch/emips/ebus/if_le_ebus.c: revision 1.15
sys/arch/mac68k/dev/if_mc.c: revision 1.46
sys/arch/macppc/dev/am79c950.c: revision 1.39
sys/arch/newsmips/apbus/if_sn.c: revision 1.40
sys/arch/next68k/dev/mb8795.c: revision 1.59
sys/arch/playstation2/dev/if_smap.c: revision 1.25
sys/arch/playstation2/dev/if_smap.c: revision 1.26
sys/arch/sun2/dev/if_ec.c: revision 1.28
sys/arch/sun3/dev/if_ie.c: revision 1.63
sys/arch/x68k/dev/if_ne_intio.c: revision 1.19
sys/arch/xen/xen/if_xennet_xenbus.c: revision 1.75
sys/arch/xen/xen/xennetback_xenbus.c: revision 1.63
sys/dev/bi/if_ni.c: revision 1.45
sys/dev/cadence/if_cemac.c: revision 1.12
sys/dev/ic/am7990.c: revision 1.78
sys/dev/ic/am79900.c: revision 1.27
sys/dev/ic/an.c: revision 1.67
sys/dev/ic/cs89x0.c: revision 1.40
sys/dev/ic/dm9000.c: revision 1.13
sys/dev/ic/dm9000.c: revision 1.14
sys/dev/ic/dp8390.c: revision 1.88
sys/dev/ic/elink3.c: revision 1.141
sys/dev/ic/elinkxl.c: revision 1.122
sys/dev/ic/hme.c: revision 1.98
sys/dev/ic/i82586.c: revision 1.77
sys/dev/ic/lance.c: revision 1.53
sys/dev/ic/mb86950.c: revision 1.27
sys/dev/ic/mb86960.c: revision 1.86
sys/dev/ic/mtd803.c: revision 1.34
sys/dev/ic/pdq_ifsubr.c: revision 1.59
sys/dev/ic/rrunner.c: revision 1.86
sys/dev/ic/seeq8005.c: revision 1.58
sys/dev/ic/sgec.c: revision 1.47
sys/dev/ic/smc90cx6.c: revision 1.72
sys/dev/ic/smc91cxx.c: revision 1.96
sys/dev/ic/tropic.c: revision 1.49
sys/dev/ic/wi.c: revision 1.245
sys/dev/isa/if_eg.c: revision 1.93
sys/dev/isa/if_el.c: revision 1.95
sys/dev/isa/if_iy.c: revision 1.101
sys/dev/ofw/ofnet.c: revision 1.58
sys/dev/pci/if_alc.c: revision 1.27
sys/dev/pci/if_de.c: revision 1.152
sys/dev/pci/if_fpa.c: revision 1.61
sys/dev/pci/if_jme.c: revision 1.34
sys/dev/pci/if_tl.c: revision 1.108
sys/dev/pci/if_vte.c: revision 1.19
sys/dev/pci/ixgbe/ixgbe.h: revision 1.50
sys/dev/pcmcia/if_cnw.c: revision 1.62
sys/dev/pcmcia/if_malo_pcmcia.c: revision 1.17
sys/dev/pcmcia/if_ray.c: revision 1.89
sys/dev/pcmcia/if_xi.c: revision 1.81
sys/dev/pcmcia/mhzc.c: revision 1.51
sys/dev/pcmcia/xirc.c: revision 1.34
sys/dev/qbus/if_de.c: revision 1.33
sys/dev/qbus/if_qe.c: revision 1.78
sys/dev/qbus/if_qt.c: revision 1.22
sys/dev/sbus/be.c: revision 1.87
sys/dev/sbus/qe.c: revision 1.68
sys/dev/scsipi/if_se.c: revision 1.96
sys/dev/usb/if_atu.c: revision 1.59
sys/net/if_l2tp.c: revision 1.28 via patch
sys/net/if_ppp.c: revision 1.160
It's not required to include net/bpfdesc.h. Remove it.
--
Simplify like other drivers. NULL check of ifp->if_bpf is done in
bpf_mtap(), so it's not required to do it here.
--
Remove duplicated inclusion of net/bpf.h.
--
Remove duplicated inclusion of net/bpf.h.
--
Simplify bpf_mtap() call. No functional change.
 1.28.2.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.28.2.1 10-Jun-2019  christos Sync with HEAD
 1.32.4.1 29-Feb-2020  ad Sync with head.
 1.34.10.1 01-Aug-2021  thorpej Sync with HEAD.
 1.3 11-Dec-2005  christos merge ktrace-lwp.
 1.2 03-Apr-2005  jdolecek branches: 1.2.2; 1.2.10;
white space cleanup, some KNF, long line wrapup
 1.1 03-Apr-2005  jdolecek Add driver for MCA Tiara LANCard / Fujitsu mb86950 EtherStar. Driver provided
in PR kern/26899 by Dave Barnes.
 1.2.10.2 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.2.10.1 03-Apr-2005  skrll file mb86950reg.h was added on branch ktrace-lwp on 2005-11-10 14:04:15 +0000
 1.2.2.2 29-Apr-2005  kent sync with -current
 1.2.2.1 03-Apr-2005  kent file mb86950reg.h was added on branch kent-audio2 on 2005-04-29 11:28:51 +0000
 1.9 14-Apr-2015  riastradh Include <sys/rndsource.h> where it is actually used.

I had removed <sys/rnd.h> from files that didn't mention anything of
the rnd(9) API. But they included other files which assumed
<sys/rnd.h> had already been included.
 1.8 27-Oct-2012  chs branches: 1.8.14;
split device_t/softc for all remaining drivers.
replace "struct device *" with "device_t".
use device_xname(), device_unit(), etc.
 1.7 02-Feb-2012  tls branches: 1.7.6;
Entropy-pool implementation move and cleanup.

1) Move core entropy-pool code and source/sink/sample management code
to sys/kern from sys/dev.

2) Remove use of NRND as test for presence of entropy-pool code throughout
source tree.

3) Remove use of RND_ENABLED in device drivers as microoptimization to
avoid expensive operations on disabled entropy sources; make the
rnd_add calls do this directly so all callers benefit.

4) Fix bug in recent rnd_add_data()/rnd_add_uint32() changes that might
have lead to slight entropy overestimation for some sources.

5) Add new source types for environmental sensors, power sensors, VM
system events, and skew between clocks, with a sample implementation
for each.

ok releng to go in before the branch due to the difficulty of later
pullup (widespread #ifdef removal and moved files). Tested with release
builds on amd64 and evbarm and live testing on amd64.
 1.6 19-Nov-2011  tls branches: 1.6.2;
First step of random number subsystem rework described in
<20111022023242.BA26F14A158@mail.netbsd.org>. This change includes
the following:

An initial cleanup and minor reorganization of the entropy pool
code in sys/dev/rnd.c and sys/dev/rndpool.c. Several bugs are
fixed. Some effort is made to accumulate entropy more quickly at
boot time.

A generic interface, "rndsink", is added, for stream generators to
request that they be re-keyed with good quality entropy from the pool
as soon as it is available.

The arc4random()/arc4randbytes() implementation in libkern is
adjusted to use the rndsink interface for rekeying, which helps
address the problem of low-quality keys at boot time.

An implementation of the FIPS 140-2 statistical tests for random
number generator quality is provided (libkern/rngtest.c). This
is based on Greg Rose's implementation from Qualcomm.

A new random stream generator, nist_ctr_drbg, is provided. It is
based on an implementation of the NIST SP800-90 CTR_DRBG by
Henric Jungheim. This generator users AES in a modified counter
mode to generate a backtracking-resistant random stream.

An abstraction layer, "cprng", is provided for in-kernel consumers
of randomness. The arc4random/arc4randbytes API is deprecated for
in-kernel use. It is replaced by "cprng_strong". The current
cprng_fast implementation wraps the existing arc4random
implementation. The current cprng_strong implementation wraps the
new CTR_DRBG implementation. Both interfaces are rekeyed from
the entropy pool automatically at intervals justifiable from best
current cryptographic practice.

In some quick tests, cprng_fast() is about the same speed as
the old arc4randbytes(), and cprng_strong() is about 20% faster
than rnd_extract_data(). Performance is expected to improve.

The AES code in src/crypto/rijndael is no longer an optional
kernel component, as it is required by cprng_strong, which is
not an optional kernel component.

The entropy pool output is subjected to the rngtest tests at
startup time; if it fails, the system will reboot. There is
approximately a 3/10000 chance of a false positive from these
tests. Entropy pool _input_ from hardware random numbers is
subjected to the rngtest tests at attach time, as well as the
FIPS continuous-output test, to detect bad or stuck hardware
RNGs; if any are detected, they are detached, but the system
continues to run.

A problem with rndctl(8) is fixed -- datastructures with
pointers in arrays are no longer passed to userspace (this
was not a security problem, but rather a major issue for
compat32). A new kernel will require a new rndctl.

The sysctl kern.arandom() and kern.urandom() nodes are hooked
up to the new generators, but the /dev/*random pseudodevices
are not, yet.

Manual pages for the new kernel interfaces are forthcoming.
 1.5 12-May-2009  cegger branches: 1.5.12;
struct device * -> device_t, no functional changes intended.
 1.4 14-Mar-2009  dsl Remove all the __P() from sys (excluding sys/dist)
Diff checked with grep and MK1 eyeball.
i386 and amd64 GENERIC and sys still build.
 1.3 11-Dec-2005  christos branches: 1.3.74; 1.3.84; 1.3.90;
merge ktrace-lwp.
 1.2 03-Apr-2005  jdolecek branches: 1.2.2; 1.2.10;
white space cleanup, some KNF, long line wrapup
 1.1 03-Apr-2005  jdolecek Add driver for MCA Tiara LANCard / Fujitsu mb86950 EtherStar. Driver provided
in PR kern/26899 by Dave Barnes.
 1.2.10.2 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.2.10.1 03-Apr-2005  skrll file mb86950var.h was added on branch ktrace-lwp on 2005-11-10 14:04:15 +0000
 1.2.2.2 29-Apr-2005  kent sync with -current
 1.2.2.1 03-Apr-2005  kent file mb86950var.h was added on branch kent-audio2 on 2005-04-29 11:28:51 +0000
 1.3.90.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.3.84.1 28-Apr-2009  skrll Sync with HEAD.
 1.3.74.2 16-May-2009  yamt sync with head
 1.3.74.1 04-May-2009  yamt sync with head.
 1.5.12.2 30-Oct-2012  yamt sync with head
 1.5.12.1 17-Apr-2012  yamt sync with head
 1.6.2.1 18-Feb-2012  mrg merge to -current.
 1.7.6.2 03-Dec-2017  jdolecek update from HEAD
 1.7.6.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.8.14.1 06-Jun-2015  skrll Sync with HEAD
 1.98 29-Jun-2024  riastradh if_stats(9): Add ifp argument to if_stat..._ref.

This will enable us to pass the ifp through to a dtrace probe inside.

No functional change intended in this change, but this is an API
change visible to modules so it shouldn't be pulled up.

PR kern/58377
 1.97 02-Jun-2023  andvar follow the steps of Andrew Doran (ad) commit and fix more s/loose/lose/ typos.
also s/beyound/beyond/ and few others along the way, mainly in comments.
 1.96 31-Jul-2021  andvar fix more typos in style found one in file - check/fix them all.
 1.95 04-Feb-2020  thorpej branches: 1.95.10;
Use ifmedia_fini().
 1.94 29-Jan-2020  thorpej Adopt <net/if_stats.h>.
 1.93 29-May-2019  msaitoh branches: 1.93.4;
Even if we don't use MII(4), use the common path of SIOC[GS]IFMEDIA in
sys/net/if_ethersubr.c if we can.
- Add ec_ifmedia into struct ethercom.
- ec_mii in struct ethercom is kept and used as it is. It might be used in
future. Note that some Ethernet drivers which _DOESN'T_ use mii(4) use
ec_mii for keeping the if_media. Those should be changed in future.
 1.92 28-May-2019  msaitoh Use ETHER_LOCK()/ETHER_UNLOCK() for all ethernet drivers to protect ec_multi*.
 1.91 23-May-2019  msaitoh -No functional change:
- KNF
- u_int*_t -> uint*_t.
 1.90 26-Apr-2019  msaitoh No functional change:
- u_int_{8,16,32}_t -> uint_{8,16,32}_t
- KNF.
- Tabify.
- Remove extra space.
 1.89 05-Feb-2019  msaitoh Remove very old IFF_NOTRAILERS flag.
 1.88 03-Sep-2018  riastradh Rename min/max -> uimin/uimax for better honesty.

These functions are defined on unsigned int. The generic name
min/max should not silently truncate to 32 bits on 64-bit systems.
This is purely a name change -- no functional change intended.

HOWEVER! Some subsystems have

#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))

even though our standard name for that is MIN/MAX. Although these
may invite multiple evaluation bugs, these do _not_ cause integer
truncation.

To avoid `fixing' these cases, I first changed the name in libkern,
and then compile-tested every file where min/max occurred in order to
confirm that it failed -- and thus confirm that nothing shadowed
min/max -- before changing it.

I have left a handful of bootloaders that are too annoying to
compile-test, and some dead code:

cobalt ews4800mips hp300 hppa ia64 luna68k vax
acorn32/if_ie.c (not included in any kernels)
macppc/if_gm.c (superseded by gem(4))

It should be easy to fix the fallout once identified -- this way of
doing things fails safe, and the goal here, after all, is to _avoid_
silent integer truncations, not introduce them.

Maybe one day we can reintroduce min/max as type-generic things that
never silently truncate. But we should avoid doing that for a while,
so that existing code has a chance to be detected by the compiler for
conversion to uimin/uimax without changing the semantics until we can
properly audit it all. (Who knows, maybe in some cases integer
truncation is actually intended!)
 1.87 26-Jun-2018  msaitoh branches: 1.87.2;
Implement the BPF direction filter (BIOC[GS]DIRECTION). It provides backward
compatibility with BIOC[GS]SEESENT ioctl. The userland interface is the same
as FreeBSD.

This change also fixes a bug that the direction is misunderstand on some
environment by passing the direction to bpf_mtap*() instead of checking
m->m_pkthdr.rcvif.
 1.86 22-Jun-2018  msaitoh It's not required to include net/bpfdesc.h. Remove it.
 1.85 23-May-2017  ozaki-r branches: 1.85.2; 1.85.8;
Apply deferred if_start to more drivers

And annotate some XXX_start as it runs in softint to clarify that
it doesn't need deferred if_start.
 1.84 15-Dec-2016  ozaki-r Move bpf_mtap and if_ipackets++ on Rx of each driver to percpuq if_input

The benefits of the change are:
- We can reduce codes
- We can provide the same behavior between drivers
- Where/When if_ipackets is counted up
- Note that some drivers still update packet statistics in their own
way (periodical update)
- Moved bpf_mtap run in softint
- This makes it easy to MP-ify bpf

Proposed on tech-kern and tech-net
 1.83 10-Jun-2016  ozaki-r branches: 1.83.2;
Introduce m_set_rcvif and m_reset_rcvif

The API is used to set (or reset) a received interface of a mbuf.
They are counterpart of m_get_rcvif, which will come in another
commit, hide internal of rcvif operation, and reduce the diff of
the upcoming change.

No functional change.
 1.82 09-Feb-2016  ozaki-r Introduce softint-based if_input

This change intends to run the whole network stack in softint context
(or normal LWP), not hardware interrupt context. Note that the work is
still incomplete by this change; to that end, we also have to softint-ify
if_link_state_change (and bpf) which can still run in hardware interrupt.

This change softint-ifies at ifp->if_input that is called from
each device driver (and ieee80211_input) to ensure Layer 2 runs
in softint (e.g., ether_input and bridge_input). To this end,
we provide a framework (called percpuq) that utlizes softint(9)
and percpu ifqueues. With this patch, rxintr of most drivers just
queues received packets and schedules a softint, and the softint
dequeues packets and does rest packet processing.

To minimize changes to each driver, percpuq is allocated in struct
ifnet for now and that is initialized by default (in if_attach).
We probably have to move percpuq to softc of each driver, but it's
future work. At this point, only wm(4) has percpuq in its softc
as a reference implementation.

Additional information including performance numbers can be found
in the thread at tech-kern@ and tech-net@:
http://mail-index.netbsd.org/tech-kern/2016/01/14/msg019997.html

Acknowledgment: riastradh@ greatly helped this work.
Thank you very much!
 1.81 13-Apr-2015  riastradh Convert sys/dev to use <sys/rndsource.h>.
 1.80 10-Aug-2014  tls branches: 1.80.4;
Merge tls-earlyentropy branch into HEAD.
 1.79 17-May-2013  mbalmer branches: 1.79.6;
gabage -> garbage, fix wording.
 1.78 02-Feb-2012  tls branches: 1.78.6;
Entropy-pool implementation move and cleanup.

1) Move core entropy-pool code and source/sink/sample management code
to sys/kern from sys/dev.

2) Remove use of NRND as test for presence of entropy-pool code throughout
source tree.

3) Remove use of RND_ENABLED in device drivers as microoptimization to
avoid expensive operations on disabled entropy sources; make the
rnd_add calls do this directly so all callers benefit.

4) Fix bug in recent rnd_add_data()/rnd_add_uint32() changes that might
have lead to slight entropy overestimation for some sources.

5) Add new source types for environmental sensors, power sensors, VM
system events, and skew between clocks, with a sample implementation
for each.

ok releng to go in before the branch due to the difficulty of later
pullup (widespread #ifdef removal and moved files). Tested with release
builds on amd64 and evbarm and live testing on amd64.
 1.77 05-Apr-2010  joerg branches: 1.77.8; 1.77.12;
Push the bpf_ops usage back into bpf.h. Push the common ifp->if_bpf
check into the inline functions as well the fourth argument for
bpf_attach.
 1.76 19-Jan-2010  pooka branches: 1.76.2; 1.76.4;
Redefine bpf linkage through an always present op vector, i.e.
#if NBPFILTER is no longer required in the client. This change
doesn't yet add support for loading bpf as a module, since drivers
can register before bpf is attached. However, callers of bpf can
now be modularized.

Dynamically loadable bpf could probably be done fairly easily with
coordination from the stub driver and the real driver by registering
attachments in the stub before the real driver is loaded and doing
a handoff. ... and I'm not going to ponder the depths of unload
here.

Tested with i386/MONOLITHIC, modified MONOLITHIC without bpf and rump.
 1.75 06-Dec-2009  dyoung Simplify device-activation hooks.
 1.74 12-Sep-2009  tsutsui Fix an incomplete device_xname change in rev 1.69. PR kern/41861
 1.73 12-May-2009  cegger struct device * -> device_t, no functional changes intended.
 1.72 16-Dec-2008  christos branches: 1.72.2;
replace bitmask_snprintf(9) with snprintb(3)
 1.71 07-Nov-2008  dyoung *** Summary ***

When a link-layer address changes (e.g., ifconfig ex0 link
02:de:ad:be:ef:02 active), send a gratuitous ARP and/or a Neighbor
Advertisement to update the network-/link-layer address bindings
on our LAN peers.

Refuse a change of ethernet address to the address 00:00:00:00:00:00
or to any multicast/broadcast address. (Thanks matt@.)

Reorder ifnet ioctl operations so that driver ioctls may inherit
the functions of their "class"---ether_ioctl(), fddi_ioctl(), et
cetera---and the class ioctls may inherit from the generic ioctl,
ifioctl_common(), but both driver- and class-ioctls may override
the generic behavior. Make network drivers share more code.

Distinguish a "factory" link-layer address from others for the
purposes of both protecting that address from deletion and computing
EUI64.

Return consistent, appropriate error codes from network drivers.

Improve readability. KNF.

*** Details ***

In if_attach(), always initialize the interface ioctl routine,
ifnet->if_ioctl, if the driver has not already initialized it.
Delete if_ioctl == NULL tests everywhere else, because it cannot
happen.

In the ioctl routines of network interfaces, inherit common ioctl
behaviors by calling either ifioctl_common() or whichever ioctl
routine is appropriate for the class of interface---e.g., ether_ioctl()
for ethernets.

Stop (ab)using SIOCSIFADDR and start to use SIOCINITIFADDR. In
the user->kernel interface, SIOCSIFADDR's argument was an ifreq,
but on the protocol->ifnet interface, SIOCSIFADDR's argument was
an ifaddr. That was confusing, and it would work against me as I
make it possible for a network interface to overload most ioctls.
On the protocol->ifnet interface, replace SIOCSIFADDR with
SIOCINITIFADDR. In ifioctl(), return EPERM if userland tries to
invoke SIOCINITIFADDR.

In ifioctl(), give the interface the first shot at handling most
interface ioctls, and give the protocol the second shot, instead
of the other way around. Finally, let compatibility code (COMPAT_OSOCK)
take a shot.

Pull device initialization out of switch statements under
SIOCINITIFADDR. For example, pull ..._init() out of any switch
statement that looks like this:

switch (...->sa_family) {
case ...:
..._init();
...
break;
...
default:
..._init();
...
break;
}

Rewrite many if-else clauses that handle all permutations of IFF_UP
and IFF_RUNNING to use a switch statement,

switch (x & (IFF_UP|IFF_RUNNING)) {
case 0:
...
break;
case IFF_RUNNING:
...
break;
case IFF_UP:
...
break;
case IFF_UP|IFF_RUNNING:
...
break;
}

unifdef lots of code containing #ifdef FreeBSD, #ifdef NetBSD, and
#ifdef SIOCSIFMTU, especially in fwip(4) and in ndis(4).

In ipw(4), remove an if_set_sadl() call that is out of place.

In nfe(4), reuse the jumbo MTU logic in ether_ioctl().

Let ethernets register a callback for setting h/w state such as
promiscuous mode and the multicast filter in accord with a change
in the if_flags: ether_set_ifflags_cb() registers a callback that
returns ENETRESET if the caller should reset the ethernet by calling
if_init(), 0 on success, != 0 on failure. Pull common code from
ex(4), gem(4), nfe(4), sip(4), tlp(4), vge(4) into ether_ioctl(),
and register if_flags callbacks for those drivers.

Return ENOTTY instead of EINVAL for inappropriate ioctls. In
zyd(4), use ENXIO instead of ENOTTY to indicate that the device is
not any longer attached.

Add to if_set_sadl() a boolean 'factory' argument that indicates
whether a link-layer address was assigned by the factory or some
other source. In a comment, recommend using the factory address
for generating an EUI64, and update in6_get_hw_ifid() to prefer a
factory address to any other link-layer address.

Add a routing message, RTM_LLINFO_UPD, that tells protocols to
update the binding of network-layer addresses to link-layer addresses.
Implement this message in IPv4 and IPv6 by sending a gratuitous
ARP or a neighbor advertisement, respectively. Generate RTM_LLINFO_UPD
messages on a change of an interface's link-layer address.

In ether_ioctl(), do not let SIOCALIFADDR set a link-layer address
that is broadcast/multicast or equal to 00:00:00:00:00:00.

Make ether_ioctl() call ifioctl_common() to handle ioctls that it
does not understand.

In gif(4), initialize if_softc and use it, instead of assuming that
the gif_softc and ifp overlap.

Let ifioctl_common() handle SIOCGIFADDR.

Sprinkle rtcache_invariants(), which checks on DIAGNOSTIC kernels
that certain invariants on a struct route are satisfied.

In agr(4), rewrite agr_ioctl_filter() to be a bit more explicit
about the ioctls that we do not allow on an agr(4) member interface.

bzero -> memset. Delete unnecessary casts to void *. Use
sockaddr_in_init() and sockaddr_in6_init(). Compare pointers with
NULL instead of "testing truth". Replace some instances of (type
*)0 with NULL. Change some K&R prototypes to ANSI C, and join
lines.
 1.70 12-Apr-2008  tsutsui branches: 1.70.4; 1.70.10; 1.70.12;
Split device_t/softc for MI mb86960, with misc cosmetics.
 1.69 08-Apr-2008  cegger use aprint_*_dev and device_xname
 1.68 19-Oct-2007  ad branches: 1.68.16;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.67 01-Sep-2007  dyoung branches: 1.67.4;
Change a bazillion occurrences of code resembling this,

error = (cmd == SIOCADDMULTI) ?
ether_addmulti(ifr, &sc->sc_ec) :
ether_delmulti(ifr, &sc->sc_ec);

if (error == ENETRESET) {

to this,

if ((error = ether_ioctl(ifp, cmd, data)) == ENETRESET) {

which does the same thing.

(A bazillion is a very large number. This seems to make the i386
ALL kernel smaller by 3kB to 4kB.)

Use ifreq_getaddr() twice in es(4).

Whitespace nits.
 1.66 04-Mar-2007  christos branches: 1.66.2; 1.66.10; 1.66.14; 1.66.16;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.65 07-Sep-2006  dogcow branches: 1.65.8;
remove more vestiges of CCITT, LLC, HDLC, NS, and NSIP.
 1.64 29-Mar-2006  thorpej Use device_cfdata().
 1.63 20-Feb-2006  thorpej branches: 1.63.2; 1.63.4; 1.63.6;
Use device_is_active() rather than testing dv_flags for DVF_ACTIVE
directly.
 1.62 24-Dec-2005  perry branches: 1.62.2; 1.62.4; 1.62.6;
__inline__ -> inline
 1.61 11-Dec-2005  christos merge ktrace-lwp.
 1.60 27-Feb-2005  perry branches: 1.60.4;
nuke trailing whitespace
 1.59 02-Jan-2005  tsutsui branches: 1.59.2; 1.59.4;
- use ANSI function decls
- remove __P()
- u_intNN_t -> uintNN_t
 1.58 30-Oct-2004  thorpej When adding/deleting multicast addresses, only whack the address
filter if the interface is marked RUNNING.

Fixes kern/27678.
 1.57 02-Nov-2003  wiz branches: 1.57.4;
Fix some typos. From Tom Cosgrove via jmc@openbsd.
 1.56 05-Feb-2003  tsutsui branches: 1.56.2;
It seems the LAN Adapter on dreamcast actually uses slow 150ns SRAM,
so handle it properly by an additional quirk flag in sc_flags.

The problem was reported by Pat Wendorf on port-dreamcast, and
the fix was suggested and confirmed by Christian Groessler.
 1.55 24-Dec-2002  tsutsui If the chip is in byte access mode for system bus, we should set
FE_D6_SBW_BYTE, not clearing FE_D6_SBW_WORD (which is zero).
Pointed out by Christian Groessler.
 1.54 30-Nov-2002  tsutsui More cleanup of MI mb86960 driver:
- Add support for byte system bus mode. Based on patch in kern/17193 by
Christian Groessler, with some improvements by me.
- Rename sc_flags in mb86960_softc to sc_stat, rename "type" to sc_flags
to specify controller quirks and remove enum mb86960_type.
- Pass controller type via new sc_flags in mb86960_softc rather than
via an mb86960_attach() arg.
- Handle unaligned mbufs properly in mb86960_write_mbufs(). (from ne2000.c)
- Fix a signed/unsigned comparision warning.
- Add definitions of status bits in the RX packed header.
- Change types of some members in mb86960_softc.
 1.53 04-Oct-2002  tsutsui - Merge dev/ic/ate_subr.c into dev/ic/mb86960.c since it only has EEPROM
read function which can also be used for other MB86965 based boards.
- Rewrite EEPROM read function as per 93C06 EEPROM datasheet.
- Misc cleanup.
 1.52 29-Sep-2002  tsutsui Fix chip identification bit definitions in DLC7 register,
from Christian Groessler on port-dreamcast.
 1.51 28-Sep-2002  tsutsui Remove unused FE_VERSION and FE_REG_VERSION.
 1.50 13-Nov-2001  lukem add/cleanup RCSID
 1.49 16-Sep-2001  wiz Spell 'occurred' with two 'r's.
 1.48 07-Jul-2001  thorpej branches: 1.48.2; 1.48.4;
bcopy -> memcpy, strcpy
 1.47 07-Jul-2001  thorpej bcmp -> memcmp
 1.46 12-Jun-2001  wiz retrieve, not retreive
 1.45 20-Jan-2001  lukem branches: 1.45.2;
consistently use FE_DEBUG (DEBUG was used a couple of places where it
was obvious that FE_DEBUG should have been used instead)
 1.44 14-Dec-2000  thorpej ALTQ'ify.
 1.43 15-Nov-2000  thorpej Move bpfattach()/bpfdetach() calls into ether_ifattach()/ether_ifdetach().
 1.42 01-Oct-2000  thorpej Move the check for "promisc + unicast + not for us" into ether_input(),
and change Ethernet drivers to always pass all received frames to
ether_input() (with a few exceptions, which are documented in the
code).
 1.41 09-Aug-2000  tv %b -> bitmask_snprintf()
 1.40 29-May-2000  jhawk For all network drivers that call ether_ifattach(), and also
have _detach() functions:
Ensure that softc keeps state about whether the attach succeeded,
and make the detach function return immediately if the attach did
not complete.
 1.39 12-May-2000  thorpej branches: 1.39.2;
Use ether_crc32_le().
 1.38 30-Mar-2000  augustss Remove register declarations.
 1.37 02-Feb-2000  enami Unhook the entropy source on detach.
 1.36 02-Feb-2000  enami Add detach support.
 1.35 13-Sep-1999  itojun branches: 1.35.2;
Merge in NetBSD/sh3 from cvs.kame.net repository.

Tree structure:
- sys/arch/sh3: sh3 generic code
As commented, in-chip device drivers are put into sys/arch/sh3/dev.
- sys/arch/evbsh3: sh3 evaluation boards (pure sh3 CPU, no fancy external HW)
- sys/arch/mmeye: Brains mmEye, www.brains.co.jp
MI source code includes couple of #ifdef for sh3-coff support.
(sh3 uses coff or elf)

Needs some more improvements, especialy in sys/arch/sh3/conf/files.sh3,
to compile the tree (due to last minute tree structure change).
 1.34 23-Jun-1999  abs In xxx_mediachange(), if there is no callback to the front-end, just
return 0 instead of EINVAL. In this case, there will only be one media
type, and the upper-level if_media code will ensure that the user is
setting to that type.
This matches changes Jason made a while back to sys/dev/ic/lance.c
 1.33 18-May-1999  thorpej Rework layer 2 protocol input routines. Instead of calling e.g. ether_input()
directly, call the function pointer (*if_input)(ifp, m). The input routine
expects the packet header to be at the head of the packet, and will adjust
as necessary. Privatize the layer 2 input and output routines, allowing
*_ifattach() to set them up as appropriate.
 1.32 25-Mar-1999  thorpej branches: 1.32.4;
Use ETHER_*_LEN constants from <net/if_ether.h> instead of defining them
ourselves. Subtract ETHER_CRC_LEN as necessary to get the same values
for these constants as were previously defined locally.
 1.31 28-Feb-1999  explorer Update to slightly altered rnd_attach_source() api
 1.30 17-Feb-1999  thorpej Avoid initializing the interface in the SIOCSIFFLAGS if ! UP and ! RUNNING.
 1.29 03-Dec-1998  pk branches: 1.29.2;
Cast bus_space_{read,write}_multi arguments.
 1.28 18-Nov-1998  thorpej Now that the *_activate() functions don't do things which are attachment
specific, move them into the chipset drivers.
 1.27 17-Nov-1998  thorpej Expose the "enable" and "disable" functions so that the front-ends can
access them.
 1.26 05-Jul-1998  jonathan defopt NS, NSIP.
 1.25 05-Jul-1998  jonathan defopt INET, NETATALK.
 1.24 29-Mar-1998  mycroft Oops; make the table const.
 1.23 29-Mar-1998  mycroft Use a 4-bit table to speed up the CRC even further, without increasing the
code size too much.
 1.22 29-Mar-1998  mycroft Optimize the address CRC routines a bit.
 1.21 22-Mar-1998  enami Split Fujitsu MB9696x based ethernet card driver into bus
dependent/independent code and bus.h'fied.
 1.20 12-Jan-1998  thorpej Update for config changes.
 1.19 05-Jan-1998  perry RCSID Police.
 1.18 15-Oct-1997  explorer Add and/or update rnd_*() hooks
 1.17 15-Mar-1997  is New ARP system, supports IPv4 over any hardware link.

Some of the stuff (e.g., rarpd, bootpd, dhcpd etc., libsa) still will
only support Ethernet. Tcpdump itself should be ok, but libpcap needs
lot of work.

For the detailed change history, look at the commit log entries for
the is-newarp branch.
 1.16 17-Oct-1996  thorpej branches: 1.16.4;
Appease the compiler: get rid of some unused variables, add some
prototypes, and suppress a bogus "might be used uninitialized" warning.
It's clear from reading the logic of the function that produces the
warning that the variable will not be used uninitialized, but the
compiler just isn't smart enough, I guess. Marked XXX for future reference.
 1.15 13-Oct-1996  christos backout kprintf changes
 1.14 10-Oct-1996  christos printf -> kprintf, sprintf -> ksprintf
 1.13 12-May-1996  mycroft Use intr.h.
 1.12 07-May-1996  thorpej Changed struct ifnet to have a pointer to the softc of the underlying
device and a printable "external name" (name + unit number), thus eliminating
if_name and if_unit. Updated interface to (*if_watchdog)() and (*if_reset)()
to take a struct ifnet *, rather than a unit number.
 1.11 11-Apr-1996  cgd update for addition of a machine-dependent cookie as the first argument
to isa_intr_{,dis}establish().
 1.10 08-Apr-1996  mycroft If we dequeue a packet due to excessive collisions, make sure we check
to see if the queue length has dropped to 0.
 1.9 17-Mar-1996  thorpej New device attachment scheme:

- split softc size and match/attach out from cfdriver into
a new struct cfattach.

- new "attach" directive for files.*. May specify the name of
the cfattach structure, so that devices may be easily attached
to parents with different autoconfiguration semantics.
 1.8 24-Dec-1995  mycroft The IST_* and IPL_* constants are not bus-specific; don't treat them as such.
Change splimp -> splnet in Ethernet, ARCnet, and FDDI drivers.
 1.7 07-Aug-1995  mycroft Fix another comment.
 1.6 07-Aug-1995  mycroft Make this interface simplex. It's more efficient, and sidesteps the
problem of receiving our own multicasts in promiscuous mode. Also, fix
some outdated comments.
 1.5 23-Jul-1995  mycroft Init functions are always called at splimp().
 1.4 23-Jul-1995  mycroft Always use m_pkthdr.len on output. Panic if M_PKTHDR is not set.
 1.3 28-Jun-1995  cgd note that most of dev/ic's contents have changed names
 1.2 12-Jun-1995  mycroft Remove check for if_addrlist == 0; if_attach() always puts one address on
the list, so this is a noop.
 1.1 01-May-1995  mycroft Add Masahiro SEKIGUCHI's MB8696[05] driver, ported, with some additional
changes by me:
* Make autoconfiguration work correctly for more models of AT1700.
* Make the debugging code more robust and complete.
* Tweak the output routine for better performance, and to eliminate an ugly
kluge.
Various other style cleanup. Needs more work.
 1.16.4.3 10-Mar-1997  is netinet/if_ether.h => netinet/if_inarp.h
 1.16.4.2 27-Feb-1997  is Removed #include <route.h> and #include <netisr.h>. They're not needed, and
the latter will go away soon.
 1.16.4.1 25-Feb-1997  is Convert to the new world order.
 1.29.2.1 11-Dec-1998  kenh The beginnings of interface detach support. Still some bugs, but mostly
works for me.

This work was originally by Bill Studenmund, and cleaned up by me.
 1.32.4.2 01-Jul-1999  thorpej Sync w/ -current.
 1.32.4.1 21-Jun-1999  thorpej Sync w/ -current.
 1.35.2.4 11-Feb-2001  bouyer Sync with HEAD.
 1.35.2.3 05-Jan-2001  bouyer Sync with HEAD
 1.35.2.2 22-Nov-2000  bouyer Sync with HEAD.
 1.35.2.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.39.2.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.45.2.7 29-Dec-2002  thorpej Sync with HEAD.
 1.45.2.6 11-Dec-2002  thorpej Sync with HEAD.
 1.45.2.5 18-Oct-2002  nathanw Catch up to -current.
 1.45.2.4 14-Nov-2001  nathanw Catch up to -current.
 1.45.2.3 21-Sep-2001  nathanw Catch up to -current.
 1.45.2.2 24-Aug-2001  nathanw Catch up with -current.
 1.45.2.1 21-Jun-2001  nathanw Catch up to -current.
 1.48.4.1 01-Oct-2001  fvdl Catch up with -current.
 1.48.2.2 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.48.2.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.56.2.6 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.56.2.5 17-Jan-2005  skrll Sync with HEAD.
 1.56.2.4 02-Nov-2004  skrll Sync with HEAD.
 1.56.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.56.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.56.2.1 03-Aug-2004  skrll Sync with HEAD
 1.57.4.1 24-Jan-2005  he Pull up revision 1.58 (requested by thorpej in ticket #939):
When adding or deleting multicast addresses, only change
the address filter if the interface is marked RUNNING.
Fixes PR#27678.
 1.59.4.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.59.2.1 29-Apr-2005  kent sync with -current
 1.60.4.4 27-Oct-2007  yamt sync with head.
 1.60.4.3 03-Sep-2007  yamt sync with head.
 1.60.4.2 30-Dec-2006  yamt sync with head.
 1.60.4.1 21-Jun-2006  yamt sync with head.
 1.62.6.1 22-Apr-2006  simonb Sync with head.
 1.62.4.1 09-Sep-2006  rpaulo sync with head
 1.62.2.1 01-Mar-2006  yamt sync with head.
 1.63.6.1 31-Mar-2006  tron Merge 2006-03-31 NetBSD-current into the "peter-altq" branch.
 1.63.4.1 19-Apr-2006  elad sync with head.
 1.63.2.2 14-Sep-2006  yamt sync with head.
 1.63.2.1 01-Apr-2006  yamt sync with head.
 1.65.8.1 12-Mar-2007  rmind Sync with HEAD.
 1.66.16.1 06-Nov-2007  matt sync with HEAD
 1.66.14.2 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.66.14.1 03-Sep-2007  jmcneill Sync with HEAD.
 1.66.10.1 03-Sep-2007  skrll Sync with HEAD.
 1.66.2.2 23-Oct-2007  ad Sync with head.
 1.66.2.1 09-Oct-2007  ad Sync with head.
 1.67.4.1 25-Oct-2007  bouyer Sync with HEAD.
 1.68.16.2 17-Jan-2009  mjf Sync with HEAD.
 1.68.16.1 02-Jun-2008  mjf Sync with HEAD.
 1.70.12.1 19-Jan-2009  skrll Sync with HEAD.
 1.70.10.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.70.4.5 11-Aug-2010  yamt sync with head.
 1.70.4.4 11-Mar-2010  yamt sync with head
 1.70.4.3 16-Sep-2009  yamt sync with head
 1.70.4.2 16-May-2009  yamt sync with head
 1.70.4.1 04-May-2009  yamt sync with head.
 1.72.2.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.76.4.1 30-May-2010  rmind sync with head
 1.76.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.77.12.1 18-Feb-2012  mrg merge to -current.
 1.77.8.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.77.8.1 17-Apr-2012  yamt sync with head
 1.78.6.3 03-Dec-2017  jdolecek update from HEAD
 1.78.6.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.78.6.1 23-Jun-2013  tls resync from head
 1.79.6.1 07-Apr-2014  tls Be a little more clear and consistent about harvesting entropy from devices:

1) deprecate RND_FLAG_NO_ESTIMATE

2) define RND_FLAG_COLLECT_TIME, RND_FLAG_COLLECT_VALUE

3) define RND_FLAG_ESTIMATE_TIME, RND_FLAG_ESTIMATE_VALUE

4) define RND_FLAG_DEFAULT: RND_FLAG_COLLECT_TIME|
RND_FLAG_COLLECT_VALUE|RND_FLAG_ESTIMATE_TIME

5) Make entropy harvesting from environmental sensors a little more generic
and remove it from individual sensor drivers.

6) Remove individual open-coded delta-estimators for values from a few
places in the tree (uvm, environmental drivers).

7) 0 -> RND_FLAG_DEFAULT, actually gather entropy from various drivers
that had stubbed out code, other minor cleanups.
 1.80.4.5 28-Aug-2017  skrll Sync with HEAD
 1.80.4.4 05-Feb-2017  skrll Sync with HEAD
 1.80.4.3 09-Jul-2016  skrll Sync with HEAD
 1.80.4.2 19-Mar-2016  skrll Sync with HEAD
 1.80.4.1 06-Jun-2015  skrll Sync with HEAD
 1.83.2.1 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.85.8.3 06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.85.8.2 28-Jul-2018  pgoyette Sync with HEAD
 1.85.8.1 25-Jun-2018  pgoyette Sync with HEAD
 1.85.2.1 26-Jul-2018  snj Pull up following revision(s) (requested by msaitoh in ticket #938):
sys/arch/acorn32/podulebus/if_ie.c: revision 1.41
sys/arch/amiga/dev/if_es.c: revision 1.58
sys/arch/amiga/dev/if_qn.c: revision 1.45
sys/arch/arm/at91/at91emac.c: revision 1.20
sys/arch/arm/ep93xx/epe.c: revision 1.37
sys/arch/emips/ebus/if_le_ebus.c: revision 1.14
sys/arch/emips/ebus/if_le_ebus.c: revision 1.15
sys/arch/mac68k/dev/if_mc.c: revision 1.46
sys/arch/macppc/dev/am79c950.c: revision 1.39
sys/arch/newsmips/apbus/if_sn.c: revision 1.40
sys/arch/next68k/dev/mb8795.c: revision 1.59
sys/arch/playstation2/dev/if_smap.c: revision 1.25
sys/arch/playstation2/dev/if_smap.c: revision 1.26
sys/arch/sun2/dev/if_ec.c: revision 1.28
sys/arch/sun3/dev/if_ie.c: revision 1.63
sys/arch/x68k/dev/if_ne_intio.c: revision 1.19
sys/arch/xen/xen/if_xennet_xenbus.c: revision 1.75
sys/arch/xen/xen/xennetback_xenbus.c: revision 1.63
sys/dev/bi/if_ni.c: revision 1.45
sys/dev/cadence/if_cemac.c: revision 1.12
sys/dev/ic/am7990.c: revision 1.78
sys/dev/ic/am79900.c: revision 1.27
sys/dev/ic/an.c: revision 1.67
sys/dev/ic/cs89x0.c: revision 1.40
sys/dev/ic/dm9000.c: revision 1.13
sys/dev/ic/dm9000.c: revision 1.14
sys/dev/ic/dp8390.c: revision 1.88
sys/dev/ic/elink3.c: revision 1.141
sys/dev/ic/elinkxl.c: revision 1.122
sys/dev/ic/hme.c: revision 1.98
sys/dev/ic/i82586.c: revision 1.77
sys/dev/ic/lance.c: revision 1.53
sys/dev/ic/mb86950.c: revision 1.27
sys/dev/ic/mb86960.c: revision 1.86
sys/dev/ic/mtd803.c: revision 1.34
sys/dev/ic/pdq_ifsubr.c: revision 1.59
sys/dev/ic/rrunner.c: revision 1.86
sys/dev/ic/seeq8005.c: revision 1.58
sys/dev/ic/sgec.c: revision 1.47
sys/dev/ic/smc90cx6.c: revision 1.72
sys/dev/ic/smc91cxx.c: revision 1.96
sys/dev/ic/tropic.c: revision 1.49
sys/dev/ic/wi.c: revision 1.245
sys/dev/isa/if_eg.c: revision 1.93
sys/dev/isa/if_el.c: revision 1.95
sys/dev/isa/if_iy.c: revision 1.101
sys/dev/ofw/ofnet.c: revision 1.58
sys/dev/pci/if_alc.c: revision 1.27
sys/dev/pci/if_de.c: revision 1.152
sys/dev/pci/if_fpa.c: revision 1.61
sys/dev/pci/if_jme.c: revision 1.34
sys/dev/pci/if_tl.c: revision 1.108
sys/dev/pci/if_vte.c: revision 1.19
sys/dev/pci/ixgbe/ixgbe.h: revision 1.50
sys/dev/pcmcia/if_cnw.c: revision 1.62
sys/dev/pcmcia/if_malo_pcmcia.c: revision 1.17
sys/dev/pcmcia/if_ray.c: revision 1.89
sys/dev/pcmcia/if_xi.c: revision 1.81
sys/dev/pcmcia/mhzc.c: revision 1.51
sys/dev/pcmcia/xirc.c: revision 1.34
sys/dev/qbus/if_de.c: revision 1.33
sys/dev/qbus/if_qe.c: revision 1.78
sys/dev/qbus/if_qt.c: revision 1.22
sys/dev/sbus/be.c: revision 1.87
sys/dev/sbus/qe.c: revision 1.68
sys/dev/scsipi/if_se.c: revision 1.96
sys/dev/usb/if_atu.c: revision 1.59
sys/net/if_l2tp.c: revision 1.28 via patch
sys/net/if_ppp.c: revision 1.160
It's not required to include net/bpfdesc.h. Remove it.
--
Simplify like other drivers. NULL check of ifp->if_bpf is done in
bpf_mtap(), so it's not required to do it here.
--
Remove duplicated inclusion of net/bpf.h.
--
Remove duplicated inclusion of net/bpf.h.
--
Simplify bpf_mtap() call. No functional change.
 1.87.2.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.87.2.1 10-Jun-2019  christos Sync with HEAD
 1.93.4.1 29-Feb-2020  ad Sync with head.
 1.95.10.1 01-Aug-2021  thorpej Sync with HEAD.
 1.2 28-Jun-1995  cgd move to more appropriate (...reg.h) names.
 1.1 01-May-1995  mycroft Add Masahiro SEKIGUCHI's MB8696[05] driver, ported, with some additional
changes by me:
* Make autoconfiguration work correctly for more models of AT1700.
* Make the debugging code more robust and complete.
* Tweak the output routine for better performance, and to eliminate an ugly
kluge.
Various other style cleanup. Needs more work.
 1.10 11-Dec-2005  christos merge ktrace-lwp.
 1.9 02-Nov-2003  wiz Fix some typos. From Tom Cosgrove via jmc@openbsd.
 1.8 30-Nov-2002  tsutsui branches: 1.8.6;
More cleanup of MI mb86960 driver:
- Add support for byte system bus mode. Based on patch in kern/17193 by
Christian Groessler, with some improvements by me.
- Rename sc_flags in mb86960_softc to sc_stat, rename "type" to sc_flags
to specify controller quirks and remove enum mb86960_type.
- Pass controller type via new sc_flags in mb86960_softc rather than
via an mb86960_attach() arg.
- Handle unaligned mbufs properly in mb86960_write_mbufs(). (from ne2000.c)
- Fix a signed/unsigned comparision warning.
- Add definitions of status bits in the RX packed header.
- Change types of some members in mb86960_softc.
 1.7 04-Oct-2002  tsutsui - Merge dev/ic/ate_subr.c into dev/ic/mb86960.c since it only has EEPROM
read function which can also be used for other MB86965 based boards.
- Rewrite EEPROM read function as per 93C06 EEPROM datasheet.
- Misc cleanup.
 1.6 29-Sep-2002  tsutsui Fix chip identification bit definitions in DLC7 register,
from Christian Groessler on port-dreamcast.
 1.5 28-Sep-2002  tsutsui Remove unused FE_MB86960_H_VERSION.
 1.4 23-Dec-2001  ichiro add FUJITSU MBH10302 specific Registers
 1.3 23-Mar-1998  msaitoh branches: 1.3.26; 1.3.28;
fix typo
 1.2 05-Jan-1998  perry RCSID Police.
 1.1 01-May-1995  mycroft Add Masahiro SEKIGUCHI's MB8696[05] driver, ported, with some additional
changes by me:
* Make autoconfiguration work correctly for more models of AT1700.
* Make the debugging code more robust and complete.
* Tweak the output routine for better performance, and to eliminate an ugly
kluge.
Various other style cleanup. Needs more work.
 1.3.28.2 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.3.28.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.3.26.3 11-Dec-2002  thorpej Sync with HEAD.
 1.3.26.2 18-Oct-2002  nathanw Catch up to -current.
 1.3.26.1 08-Jan-2002  nathanw Catch up to -current.
 1.8.6.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.8.6.2 18-Sep-2004  skrll Sync with HEAD.
 1.8.6.1 03-Aug-2004  skrll Sync with HEAD
 1.41 31-Jul-2021  andvar fix more typos in style found one in file - check/fix them all.
 1.40 13-Apr-2015  riastradh branches: 1.40.36;
Convert sys/dev to use <sys/rndsource.h>.
 1.39 02-Feb-2012  tls branches: 1.39.6; 1.39.24;
Entropy-pool implementation move and cleanup.

1) Move core entropy-pool code and source/sink/sample management code
to sys/kern from sys/dev.

2) Remove use of NRND as test for presence of entropy-pool code throughout
source tree.

3) Remove use of RND_ENABLED in device drivers as microoptimization to
avoid expensive operations on disabled entropy sources; make the
rnd_add calls do this directly so all callers benefit.

4) Fix bug in recent rnd_add_data()/rnd_add_uint32() changes that might
have lead to slight entropy overestimation for some sources.

5) Add new source types for environmental sensors, power sensors, VM
system events, and skew between clocks, with a sample implementation
for each.

ok releng to go in before the branch due to the difficulty of later
pullup (widespread #ifdef removal and moved files). Tested with release
builds on amd64 and evbarm and live testing on amd64.
 1.38 19-Nov-2011  tls branches: 1.38.2;
First step of random number subsystem rework described in
<20111022023242.BA26F14A158@mail.netbsd.org>. This change includes
the following:

An initial cleanup and minor reorganization of the entropy pool
code in sys/dev/rnd.c and sys/dev/rndpool.c. Several bugs are
fixed. Some effort is made to accumulate entropy more quickly at
boot time.

A generic interface, "rndsink", is added, for stream generators to
request that they be re-keyed with good quality entropy from the pool
as soon as it is available.

The arc4random()/arc4randbytes() implementation in libkern is
adjusted to use the rndsink interface for rekeying, which helps
address the problem of low-quality keys at boot time.

An implementation of the FIPS 140-2 statistical tests for random
number generator quality is provided (libkern/rngtest.c). This
is based on Greg Rose's implementation from Qualcomm.

A new random stream generator, nist_ctr_drbg, is provided. It is
based on an implementation of the NIST SP800-90 CTR_DRBG by
Henric Jungheim. This generator users AES in a modified counter
mode to generate a backtracking-resistant random stream.

An abstraction layer, "cprng", is provided for in-kernel consumers
of randomness. The arc4random/arc4randbytes API is deprecated for
in-kernel use. It is replaced by "cprng_strong". The current
cprng_fast implementation wraps the existing arc4random
implementation. The current cprng_strong implementation wraps the
new CTR_DRBG implementation. Both interfaces are rekeyed from
the entropy pool automatically at intervals justifiable from best
current cryptographic practice.

In some quick tests, cprng_fast() is about the same speed as
the old arc4randbytes(), and cprng_strong() is about 20% faster
than rnd_extract_data(). Performance is expected to improve.

The AES code in src/crypto/rijndael is no longer an optional
kernel component, as it is required by cprng_strong, which is
not an optional kernel component.

The entropy pool output is subjected to the rngtest tests at
startup time; if it fails, the system will reboot. There is
approximately a 3/10000 chance of a false positive from these
tests. Entropy pool _input_ from hardware random numbers is
subjected to the rngtest tests at attach time, as well as the
FIPS continuous-output test, to detect bad or stuck hardware
RNGs; if any are detected, they are detached, but the system
continues to run.

A problem with rndctl(8) is fixed -- datastructures with
pointers in arrays are no longer passed to userspace (this
was not a security problem, but rather a major issue for
compat32). A new kernel will require a new rndctl.

The sysctl kern.arandom() and kern.urandom() nodes are hooked
up to the new generators, but the /dev/*random pseudodevices
are not, yet.

Manual pages for the new kernel interfaces are forthcoming.
 1.37 12-May-2009  cegger branches: 1.37.12;
struct device * -> device_t, no functional changes intended.
 1.36 12-Apr-2008  tsutsui branches: 1.36.4; 1.36.18;
Split device_t/softc for MI mb86960, with misc cosmetics.
 1.35 11-Dec-2005  christos branches: 1.35.70;
merge ktrace-lwp.
 1.34 02-Jan-2005  tsutsui - use ANSI function decls
- remove __P()
- u_intNN_t -> uintNN_t
 1.33 05-Feb-2003  tsutsui branches: 1.33.2;
It seems the LAN Adapter on dreamcast actually uses slow 150ns SRAM,
so handle it properly by an additional quirk flag in sc_flags.

The problem was reported by Pat Wendorf on port-dreamcast, and
the fix was suggested and confirmed by Christian Groessler.
 1.32 30-Nov-2002  tsutsui More cleanup of MI mb86960 driver:
- Add support for byte system bus mode. Based on patch in kern/17193 by
Christian Groessler, with some improvements by me.
- Rename sc_flags in mb86960_softc to sc_stat, rename "type" to sc_flags
to specify controller quirks and remove enum mb86960_type.
- Pass controller type via new sc_flags in mb86960_softc rather than
via an mb86960_attach() arg.
- Handle unaligned mbufs properly in mb86960_write_mbufs(). (from ne2000.c)
- Fix a signed/unsigned comparision warning.
- Add definitions of status bits in the RX packed header.
- Change types of some members in mb86960_softc.
 1.31 05-Oct-2002  tsutsui Overhaul of fmv(4) driver:
- Split if_fmv.c into MI/MD part and add ISA-PnP attachment for FMV-183.
(XXX FMV-184 is not tested. It would require extra media-select functions..)
- Fix probe functions of fmv_isa so that FMV-181A/182A will also match.
Fixes port-i386/9476.
 1.30 04-Oct-2002  tsutsui Allied-Telesyn AT-1700xT and Allied-Telesis RE200x are actually identical,
so show both names in attachment. (From FreeBSD's if_fe_isa.c)
 1.29 04-Oct-2002  tsutsui - Merge dev/ic/ate_subr.c into dev/ic/mb86960.c since it only has EEPROM
read function which can also be used for other MB86965 based boards.
- Rewrite EEPROM read function as per 93C06 EEPROM datasheet.
- Misc cleanup.
 1.28 28-Sep-2002  tsutsui Remove unused FE_VERSION.
 1.27 01-May-2001  lukem branches: 1.27.2;
delint
 1.26 29-May-2000  jhawk branches: 1.26.4;
For all network drivers that call ether_ifattach(), and also
have _detach() functions:
Ensure that softc keeps state about whether the attach succeeded,
and make the detach function return immediately if the attach did
not complete.
 1.25 02-Feb-2000  enami branches: 1.25.2;
Add detach support.
 1.24 25-Mar-1999  thorpej branches: 1.24.8;
Use ETHER_*_LEN constants from <net/if_ether.h> instead of defining them
ourselves. Subtract ETHER_CRC_LEN as necessary to get the same values
for these constants as were previously defined locally.
 1.23 18-Nov-1998  thorpej Now that the *_activate() functions don't do things which are attachment
specific, move them into the chipset drivers.
 1.22 17-Nov-1998  thorpej Expose the "enable" and "disable" functions so that the front-ends can
access them.
 1.21 22-Mar-1998  enami Split Fujitsu MB9696x based ethernet card driver into bus
dependent/independent code and bus.h'fied.
 1.20 12-Jan-1998  thorpej Update for config changes.
 1.19 05-Jan-1998  perry RCSID Police.
 1.18 15-Oct-1997  explorer Add and/or update rnd_*() hooks
 1.17 15-Mar-1997  is New ARP system, supports IPv4 over any hardware link.

Some of the stuff (e.g., rarpd, bootpd, dhcpd etc., libsa) still will
only support Ethernet. Tcpdump itself should be ok, but libpcap needs
lot of work.

For the detailed change history, look at the commit log entries for
the is-newarp branch.
 1.16 17-Oct-1996  thorpej branches: 1.16.4;
Appease the compiler: get rid of some unused variables, add some
prototypes, and suppress a bogus "might be used uninitialized" warning.
It's clear from reading the logic of the function that produces the
warning that the variable will not be used uninitialized, but the
compiler just isn't smart enough, I guess. Marked XXX for future reference.
 1.15 13-Oct-1996  christos backout kprintf changes
 1.14 10-Oct-1996  christos printf -> kprintf, sprintf -> ksprintf
 1.13 12-May-1996  mycroft Use intr.h.
 1.12 07-May-1996  thorpej Changed struct ifnet to have a pointer to the softc of the underlying
device and a printable "external name" (name + unit number), thus eliminating
if_name and if_unit. Updated interface to (*if_watchdog)() and (*if_reset)()
to take a struct ifnet *, rather than a unit number.
 1.11 11-Apr-1996  cgd update for addition of a machine-dependent cookie as the first argument
to isa_intr_{,dis}establish().
 1.10 08-Apr-1996  mycroft If we dequeue a packet due to excessive collisions, make sure we check
to see if the queue length has dropped to 0.
 1.9 17-Mar-1996  thorpej New device attachment scheme:

- split softc size and match/attach out from cfdriver into
a new struct cfattach.

- new "attach" directive for files.*. May specify the name of
the cfattach structure, so that devices may be easily attached
to parents with different autoconfiguration semantics.
 1.8 24-Dec-1995  mycroft The IST_* and IPL_* constants are not bus-specific; don't treat them as such.
Change splimp -> splnet in Ethernet, ARCnet, and FDDI drivers.
 1.7 07-Aug-1995  mycroft Fix another comment.
 1.6 07-Aug-1995  mycroft Make this interface simplex. It's more efficient, and sidesteps the
problem of receiving our own multicasts in promiscuous mode. Also, fix
some outdated comments.
 1.5 23-Jul-1995  mycroft Init functions are always called at splimp().
 1.4 23-Jul-1995  mycroft Always use m_pkthdr.len on output. Panic if M_PKTHDR is not set.
 1.3 28-Jun-1995  cgd note that most of dev/ic's contents have changed names
 1.2 12-Jun-1995  mycroft Remove check for if_addrlist == 0; if_attach() always puts one address on
the list, so this is a noop.
 1.1 01-May-1995  mycroft Add Masahiro SEKIGUCHI's MB8696[05] driver, ported, with some additional
changes by me:
* Make autoconfiguration work correctly for more models of AT1700.
* Make the debugging code more robust and complete.
* Tweak the output routine for better performance, and to eliminate an ugly
kluge.
Various other style cleanup. Needs more work.
 1.16.4.3 10-Mar-1997  is netinet/if_ether.h => netinet/if_inarp.h
 1.16.4.2 27-Feb-1997  is Removed #include <route.h> and #include <netisr.h>. They're not needed, and
the latter will go away soon.
 1.16.4.1 25-Feb-1997  is Convert to the new world order.
 1.24.8.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.25.2.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.26.4.3 11-Dec-2002  thorpej Sync with HEAD.
 1.26.4.2 18-Oct-2002  nathanw Catch up to -current.
 1.26.4.1 21-Jun-2001  nathanw Catch up to -current.
 1.27.2.1 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.33.2.1 17-Jan-2005  skrll Sync with HEAD.
 1.35.70.1 02-Jun-2008  mjf Sync with HEAD.
 1.36.18.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.36.4.1 16-May-2009  yamt sync with head
 1.37.12.1 17-Apr-2012  yamt sync with head
 1.38.2.1 18-Feb-2012  mrg merge to -current.
 1.39.24.1 06-Jun-2015  skrll Sync with HEAD
 1.39.6.1 03-Dec-2017  jdolecek update from HEAD
 1.40.36.1 01-Aug-2021  thorpej Sync with HEAD.
 1.63 10-May-2023  riastradh spc(4): Use config_detach_children.
 1.62 28-Mar-2023  andvar s/interrput/interrupt/ and s/accesss/access/ in comments.
 1.61 01-Jan-2022  andvar fix typos in comments, mainly basicly -> basically.
 1.60 07-Aug-2021  thorpej Merge thorpej-cfargs2.
 1.59 24-Apr-2021  thorpej branches: 1.59.8;
Merge thorpej-cfargs branch:

Simplify and make extensible the config_search() / config_found() /
config_attach() interfaces: rather than having different variants for
which arguments you want pass along, just have a single call that
takes a variadic list of tag-value arguments.

Adjust all call sites:
- Simplify wherever possible; don't pass along arguments that aren't
actually needed.
- Don't be explicit about what interface attribute is attaching if
the device only has one. (More simplification.)
- Add a config_probe() function to be used in indirect configuiration
situations, making is visibly easier to see when indirect config is
in play, and allowing for future change in semantics. (As of now,
this is just a wrapper around config_match(), but that is an
implementation detail.)

Remove unnecessary or redundant interface attributes where they're not
needed.

There are currently 5 "cfargs" defined:
- CFARG_SUBMATCH (submatch function for direct config)
- CFARG_SEARCH (search function for indirect config)
- CFARG_IATTR (interface attribte)
- CFARG_LOCATORS (locators array)
- CFARG_DEVHANDLE (devhandle_t - wraps OFW, ACPI, etc. handles)

...and a sentinel value CFARG_EOL.

Add some extra sanity checking to ensure that interface attributes
aren't ambiguous.

Use CFARG_DEVHANDLE in MI FDT, OFW, and ACPI code, and macppc and shark
ports to associate those device handles with device_t instance. This
will trickle trough to more places over time (need back-end for pre-OFW
Sun OBP; any others?).
 1.58 06-Mar-2021  tsutsui branches: 1.58.2;
Fix a possible race condition in spc_msgin() in NO_MANUAL_XFER case.

To avoid the race, check SSTS and INTS after XFR command as
spc_pio_datain() does.

Reported from isaki@, observed on nono emulator.
 1.57 03-Sep-2018  riastradh branches: 1.57.4; 1.57.12;
Rename min/max -> uimin/uimax for better honesty.

These functions are defined on unsigned int. The generic name
min/max should not silently truncate to 32 bits on 64-bit systems.
This is purely a name change -- no functional change intended.

HOWEVER! Some subsystems have

#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))

even though our standard name for that is MIN/MAX. Although these
may invite multiple evaluation bugs, these do _not_ cause integer
truncation.

To avoid `fixing' these cases, I first changed the name in libkern,
and then compile-tested every file where min/max occurred in order to
confirm that it failed -- and thus confirm that nothing shadowed
min/max -- before changing it.

I have left a handful of bootloaders that are too annoying to
compile-test, and some dead code:

cobalt ews4800mips hp300 hppa ia64 luna68k vax
acorn32/if_ie.c (not included in any kernels)
macppc/if_gm.c (superseded by gem(4))

It should be easy to fix the fallout once identified -- this way of
doing things fails safe, and the goal here, after all, is to _avoid_
silent integer truncations, not introduce them.

Maybe one day we can reintroduce min/max as type-generic things that
never silently truncate. But we should avoid doing that for a while,
so that existing code has a chance to be detected by the compiler for
conversion to uimin/uimax without changing the semantics until we can
properly audit it all. (Who knows, maybe in some cases integer
truncation is actually intended!)
 1.56 28-Oct-2017  riastradh branches: 1.56.2; 1.56.4;
Kill some more extern struct cfdriver declarations.

Down with externs in .c!
 1.55 11-Jan-2017  skrll adatper -> adapter
 1.54 04-Nov-2013  christos branches: 1.54.6; 1.54.10;
mark variables __diagused
 1.53 02-Dec-2011  tsutsui branches: 1.53.8; 1.53.12;
Define NO_MANUAL_XFER on luna68k as temporary workaround for hangup problem
during probing old drives like DK312C in OMRON LUNA machines.

I'll check this MSGIN xfer problem later.
(NO_MANUAL_XFER also caused hang on heavy load on hp300 with multiple drives)
 1.52 27-Jul-2010  jakllsch branches: 1.52.8;
printf() size_t with 'z' format modifier in debug code.
 1.51 23-Nov-2009  rmind branches: 1.51.2; 1.51.4;
Remove some unecessary includes sys/user.h header.
 1.50 12-Nov-2009  dyoung Remove superfluous activation hook.

Add a child-detachment hook.
 1.49 12-Jun-2008  cegger use device_lookup_private to get softc
 1.48 04-May-2008  martin branches: 1.48.2; 1.48.4;
Move to standard TNF 2 clause license
 1.47 31-Mar-2008  tsutsui branches: 1.47.2; 1.47.4;
Split softc/device_t for spc(4) and misc related cleanup.
 1.46 19-Oct-2007  ad branches: 1.46.16;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.45 16-Nov-2006  christos branches: 1.45.8; 1.45.22; 1.45.24; 1.45.28;
__unused removal on arguments; approved by core.
 1.44 12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.43 04-Oct-2006  christos fix empty if
 1.42 02-Sep-2006  xtraeme branches: 1.42.2; 1.42.4;
Remove unused variable to make this build again.
 1.41 02-Sep-2006  christos comment out impossible code
 1.40 24-Dec-2005  perry branches: 1.40.4; 1.40.8;
Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.39 11-Dec-2005  christos merge ktrace-lwp.
 1.38 02-Jan-2005  tsutsui branches: 1.38.10;
u_intNN_t -> uintNN_t
 1.37 25-Sep-2004  tsutsui Use ANSI function decls.
 1.36 25-Sep-2004  tsutsui Sprinkle DELAY(1)'s in several busy loops to avoid excessive bus access.
Inspired by OpenBSD.
 1.35 25-Sep-2004  tsutsui On manual xfer via TEMP register, set PCTL_BFINT_ENAB and check
bus free by INTS register. spc_intr() also checks the INTS_DISCON bit.
 1.34 25-Sep-2004  tsutsui In spc_intr(), return 0 if the interrupt is not for spc(4).
 1.33 25-Sep-2004  tsutsui Use manual xfer via TEMP register in status phase even on x68k.
Some devices do not transfer data with proper way on status phase
and it causes bus error in spc_datain_pio() which uses auto xfer
via DREG register on weird x68k hardware.
 1.32 12-Aug-2004  mycroft Close a race condition in the datain loop. If we receive another byte between
reading the FIFO status and reading the interrupt status, we could end up
leaving it in the FIFO. Force another round through the loop after reading the
interrupt status until the FIFO reads empty again.

Also, there is no point in having the extra loop to wait for the transfer
command to the controller to be acknowledged, because the transfer loop handles
that just fine -- and getting rid of it fixes another race condition.
 1.31 11-Aug-2004  mycroft Correct the overrun loop while I'm at it.
 1.30 11-Aug-2004  mycroft Recode the datain_pio loop. This improves performance substantially (almost
2x) with my spc@pcmcia.
 1.29 09-Aug-2004  mycroft Add detach support for spc@pcmcia, modeled after aic@pcmcia.
 1.28 07-Aug-2004  mycroft Fix a printf() format for Alpha.
 1.27 07-Aug-2004  tsutsui On manual transfer via TEMP register, data should be read
before asserting ACK.
 1.26 06-Jan-2004  tsutsui branches: 1.26.2;
Fix bus error trap on X68030/25MHz on-board SPC, which may have some quirk.
Problem reported by Yasushi Oshima.
 1.25 02-Nov-2003  wiz Fix some typos. From Tom Cosgrove via jmc@openbsd.
 1.24 07-Sep-2003  isaki Delete strange ifdef x68k.
Requested by tsutsui@
 1.23 29-Aug-2003  isaki Delete unnecessary #ifndef for x68k.
approved by tsutsui@
 1.22 01-Aug-2003  tsutsui - Add hooks for MD DMA transfers.
- Prepare ADAPTER_REQ_SET_XFER_MODE function.
(currently sync xfer is not supported)
 1.21 27-Jul-2003  tsutsui There is a report that x68k SCSI no longer works after the previous changes.
It seems x68k SPC SCSI has several hardware quirks, so add some (a bit ugly)
#ifdefs for workaround. (XXX - needs revisiting)
 1.20 05-Jul-2003  tsutsui More misc fixes for forthcoming hp300 MI SCSI support:
- Don't use SCMD_XFR command in message-in phase and status phase.
It causes unexpected hangs on heavy load. Instead transfer data
manually via TEMP register by SCMD_SET_ACK and SCMD_RST_ACK.
- Don't set SCMD_ICPT_XFR in spc_dataout_pio() and spc_msgout().
- Rewrite spc_datain_pio() to handle FIFO more properly.
 1.19 05-Jul-2003  tsutsui Misc cleanup:
- disable debug code by default
- use MI minphys()
- add proper delay in spc_find()
- initialize TMOD register in spc_reset()
- wrap a sanity check with #ifdef DIAGNOSTIC (sync with aic6360.c)
- no need to set LUN bits in SCSI command which should be done in mid-layer
- set proper resid even in error case
- fix/remove some bogus comments
 1.18 05-Jul-2003  tsutsui Use bus_space_{read,write}_multi_1() for PIO data transfers.
 1.17 05-Jul-2003  tsutsui Rename some MI mb89352 functions for consistency:
spcintr() -> spc_intr()
spcattach() -> spc_attach()
 1.16 05-Jul-2003  tsutsui Some cosmetics:
- Remove useless macro.
- Remove ^L characters.
- KNF a comment.
 1.15 19-May-2003  tsutsui branches: 1.15.2;
Misc cosmetics:
- some KNF and wrap long lines
- use TAILQ macro
- replace some magic numbers with macro
- use #if 0/#endif pair to disable code
 1.14 21-Feb-2003  tsutsui hz -> Hz
 1.13 30-May-2002  thorpej Statements must follow labels.
 1.12 05-Apr-2002  bouyer branches: 1.12.2;
Implement mstohz() as discussed on tech-kern, and use it in SCSI drivers
to convert xs->timeout to callout() parameter.
 1.11 15-Nov-2001  lukem don't need <sys/types.h> when including <sys/param.h>
 1.10 13-Nov-2001  lukem add/cleanup RCSID
 1.9 04-Nov-2001  tsutsui Use common macro to check message length.
 1.8 07-Jul-2001  thorpej branches: 1.8.2; 1.8.6;
bzero -> memset
 1.7 07-Jul-2001  thorpej bcopy -> memcpy
 1.6 25-Apr-2001  bouyer Pull up the thorpej_scsipi branch to main branch.
This is a completely rewritten scsipi_xfer execution engine, and the
associated changes to HBA drivers. Overview of changes & features:
- All xfers are queued in the mid-layer, rather than doing so in an
ad-hoc fashion in individual adapter drivers.
- Adapter/channel resource management in the mid-layer, avoids even trying
to start running an xfer if the adapter/channel doesn't have the resources.
- Better communication between the mid-layer and the adapters.
- Asynchronous event notification mechanism from adapter to mid-layer and
peripherals.
- Better peripheral queue management: freeze/thaw, sorted requeueing during
recovery, etc.
- Clean separation of peripherals, adapters, and adapter channels (no more
scsipi_link).
- Kernel thread for each scsipi_channel makes error recovery much easier
(no more dealing with interrupt context when recovering from an error).
- Mid-layer support for tagged queueing: commands can have the tag type
set explicitly, tag IDs are allocated in the mid-layer (thus eliminating
the need to use buggy tag ID allocation schemes in many adapter drivers).
- support for QUEUE FULL and CHECK CONDITION status in mid-layer; the command
will be requeued, or a REQUEST SENSE will be sent as appropriate.

Just before the merge syssrc has been tagged with thorpej_scsipi_beforemerge
 1.5 23-Mar-2000  thorpej branches: 1.5.6;
New callout mechanism with two major improvements over the old
timeout()/untimeout() API:
- Clients supply callout handle storage, thus eliminating problems of
resource allocation.
- Insertion and removal of callouts is constant time, important as
this facility is used quite a lot in the kernel.

The old timeout()/untimeout() API has been removed from the kernel.
 1.4 30-Sep-1999  thorpej branches: 1.4.2;
Update for SCSPI changes.
 1.3 14-Mar-1999  minoura Some x68k conditionals (I don't know why these are needed...).
 1.2 19-Feb-1999  minoura Translated Japanese comments.
 1.1 13-Feb-1999  minoura MI version of the Fujitsu MB89352 SCSI Protocol Controler (SPC) driver.
Based on experimental NetBSD/pc98 ISA/PISA version, which was derived
from the MD /sys/arch/x68k/dev/spc.c.
 1.4.2.3 27-Mar-2001  bouyer Convert these drivers to thorpej_scsipi (untested).
 1.4.2.2 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.4.2.1 19-Oct-1999  thorpej Don't sleep waiting for a CCB; if we get to the CCB allocation phase, we're
guaranteed to have one.
 1.5.6.6 20-Jun-2002  nathanw Catch up to -current.
 1.5.6.5 17-Apr-2002  nathanw Catch up to -current.
 1.5.6.4 08-Jan-2002  nathanw Catch up to -current.
 1.5.6.3 14-Nov-2001  nathanw Catch up to -current.
 1.5.6.2 24-Aug-2001  nathanw Catch up with -current.
 1.5.6.1 21-Jun-2001  nathanw Catch up to -current.
 1.8.6.1 12-Nov-2001  thorpej Sync the thorpej-mips-cache branch with -current.
 1.8.2.2 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.8.2.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.12.2.1 20-Jun-2002  gehenna catch up with -current.
 1.15.2.6 17-Jan-2005  skrll Sync with HEAD.
 1.15.2.5 19-Oct-2004  skrll Sync with HEAD
 1.15.2.4 21-Sep-2004  skrll Fix the sync with head I botched.
 1.15.2.3 18-Sep-2004  skrll Sync with HEAD.
 1.15.2.2 12-Aug-2004  skrll Sync with HEAD.
 1.15.2.1 03-Aug-2004  skrll Sync with HEAD
 1.26.2.1 12-Aug-2004  jmc Pullup rev 1.27 (requested by tsutsui in ticket #747)

On manual transfer via TEMP register, data should be read before asserting ACK.
 1.38.10.3 27-Oct-2007  yamt sync with head.
 1.38.10.2 30-Dec-2006  yamt sync with head.
 1.38.10.1 21-Jun-2006  yamt sync with head.
 1.40.8.1 03-Sep-2006  yamt sync with head.
 1.40.4.1 09-Sep-2006  rpaulo sync with head
 1.42.4.2 10-Dec-2006  yamt sync with head.
 1.42.4.1 22-Oct-2006  yamt sync with head
 1.42.2.1 18-Nov-2006  ad Sync with head.
 1.45.28.1 25-Oct-2007  bouyer Sync with HEAD.
 1.45.24.1 06-Nov-2007  matt sync with HEAD
 1.45.22.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.45.8.1 23-Oct-2007  ad Sync with head.
 1.46.16.3 29-Jun-2008  mjf Sync with HEAD.
 1.46.16.2 02-Jun-2008  mjf Sync with HEAD.
 1.46.16.1 03-Apr-2008  mjf Sync with HEAD.
 1.47.4.4 11-Aug-2010  yamt sync with head.
 1.47.4.3 11-Mar-2010  yamt sync with head
 1.47.4.2 04-May-2009  yamt sync with head.
 1.47.4.1 16-May-2008  yamt sync with head.
 1.47.2.2 17-Jun-2008  yamt sync with head.
 1.47.2.1 18-May-2008  yamt sync with head.
 1.48.4.1 18-Jun-2008  simonb Sync with head.
 1.48.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.51.4.1 05-Mar-2011  rmind sync with head
 1.51.2.1 17-Aug-2010  uebayasi Sync with HEAD.
 1.52.8.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.52.8.1 17-Apr-2012  yamt sync with head
 1.53.12.1 18-May-2014  rmind sync with head
 1.53.8.2 03-Dec-2017  jdolecek update from HEAD
 1.53.8.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.54.10.1 20-Mar-2017  pgoyette Sync with HEAD
 1.54.6.1 05-Feb-2017  skrll Sync with HEAD
 1.56.4.1 10-Jun-2019  christos Sync with HEAD
 1.56.2.1 06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.57.12.1 03-Apr-2021  thorpej Sync with HEAD.
 1.57.4.1 09-Mar-2021  martin Pull up following revision(s) (requested by tsutsui in ticket #1228):

sys/dev/ic/mb89352.c: revision 1.58

Fix a possible race condition in spc_msgin() in NO_MANUAL_XFER case.

To avoid the race, check SSTS and INTS after XFR command as
spc_pio_datain() does.

Reported from isaki@, observed on nono emulator.
 1.58.2.1 21-Mar-2021  thorpej Give config_found() the same variadic arguments treatment as
config_search(). This commit only adds the CFARG_EOL sentinel
to the existing config_found() calls. Conversion of config_found_sm_loc()
and config_found_ia() call sites will be in subsequent commits.
 1.59.8.1 04-Aug-2021  thorpej Adapt to CFARGS().
 1.1 20-Nov-2000  bouyer branches: 1.1.2;
file mb89352.c.orig was initially added on branch thorpej_scsipi.
 1.1.2.2 20-Nov-2000  bouyer Ops, these shouldn't be there !
 1.1.2.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.7 09-Feb-2024  andvar fix spelling mistakes, mainly in comments and log messages.
 1.6 11-Dec-2005  christos merge ktrace-lwp.
 1.5 24-Mar-2004  wiz Move
(c) TNF
line from 4-clause UCB to 3-clause UCB license; in other words,
remove UCB's ad clause from the license TNF grants.
There is no point in TNF demanding that UCB's ad clause be followed
when even UCB doesn't demand it any longer.

Ok'd by board@ and agc@.
 1.4 04-Jan-2004  wiz Spell controller with two ls. Inspired by miod@openbsd.
 1.3 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22364, verified by myself.
 1.2 02-Aug-2003  tsutsui TAB/space cosmetics
 1.1 13-Feb-1999  minoura branches: 1.1.42;
MI version of the Fujitsu MB89352 SCSI Protocol Controler (SPC) driver.
Based on experimental NetBSD/pc98 ISA/PISA version, which was derived
from the MD /sys/arch/x68k/dev/spc.c.
 1.1.42.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.1.42.2 18-Sep-2004  skrll Sync with HEAD.
 1.1.42.1 03-Aug-2004  skrll Sync with HEAD
 1.16 01-Jan-2022  andvar fix typos in comments, mainly basicly -> basically.
 1.15 12-Nov-2009  dyoung Remove definition of spc_activate(), it has gone away.
 1.14 12-Nov-2009  dyoung Remove superfluous activation hook.

Add a child-detachment hook.
 1.13 12-May-2009  cegger struct device * -> device_t, no functional changes intended.
 1.12 04-May-2008  martin branches: 1.12.14;
Move to standard TNF 2 clause license
 1.11 31-Mar-2008  tsutsui branches: 1.11.2; 1.11.4;
Split softc/device_t for spc(4) and misc related cleanup.
 1.10 11-Dec-2005  christos branches: 1.10.70;
merge ktrace-lwp.
 1.9 07-Dec-2004  thorpej Use "struct scsipi_command" in internal command structures so that
we have enough space for 16-byte CDBs.
 1.8 25-Sep-2004  tsutsui Use ANSI function decls.
 1.7 09-Aug-2004  mycroft Add detach support for spc@pcmcia, modeled after aic@pcmcia.
 1.6 02-Aug-2003  tsutsui TAB/space cosmetics
 1.5 01-Aug-2003  tsutsui - Add hooks for MD DMA transfers.
- Prepare ADAPTER_REQ_SET_XFER_MODE function.
(currently sync xfer is not supported)
 1.4 05-Jul-2003  tsutsui Rename some MI mb89352 functions for consistency:
spcintr() -> spc_intr()
spcattach() -> spc_attach()
 1.3 25-Apr-2001  bouyer branches: 1.3.22;
Pull up the thorpej_scsipi branch to main branch.
This is a completely rewritten scsipi_xfer execution engine, and the
associated changes to HBA drivers. Overview of changes & features:
- All xfers are queued in the mid-layer, rather than doing so in an
ad-hoc fashion in individual adapter drivers.
- Adapter/channel resource management in the mid-layer, avoids even trying
to start running an xfer if the adapter/channel doesn't have the resources.
- Better communication between the mid-layer and the adapters.
- Asynchronous event notification mechanism from adapter to mid-layer and
peripherals.
- Better peripheral queue management: freeze/thaw, sorted requeueing during
recovery, etc.
- Clean separation of peripherals, adapters, and adapter channels (no more
scsipi_link).
- Kernel thread for each scsipi_channel makes error recovery much easier
(no more dealing with interrupt context when recovering from an error).
- Mid-layer support for tagged queueing: commands can have the tag type
set explicitly, tag IDs are allocated in the mid-layer (thus eliminating
the need to use buggy tag ID allocation schemes in many adapter drivers).
- support for QUEUE FULL and CHECK CONDITION status in mid-layer; the command
will be requeued, or a REQUEST SENSE will be sent as appropriate.

Just before the merge syssrc has been tagged with thorpej_scsipi_beforemerge
 1.2 07-Jan-2000  nisimura branches: 1.2.6;
Remove tinfo_t symbols which result in never used global common variables.
 1.1 13-Feb-1999  minoura branches: 1.1.8;
MI version of the Fujitsu MB89352 SCSI Protocol Controler (SPC) driver.
Based on experimental NetBSD/pc98 ISA/PISA version, which was derived
from the MD /sys/arch/x68k/dev/spc.c.
 1.1.8.2 27-Mar-2001  bouyer Convert these drivers to thorpej_scsipi (untested).
 1.1.8.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.2.6.1 21-Jun-2001  nathanw Catch up to -current.
 1.3.22.6 18-Dec-2004  skrll Sync with HEAD.
 1.3.22.5 19-Oct-2004  skrll Sync with HEAD
 1.3.22.4 21-Sep-2004  skrll Fix the sync with head I botched.
 1.3.22.3 18-Sep-2004  skrll Sync with HEAD.
 1.3.22.2 12-Aug-2004  skrll Sync with HEAD.
 1.3.22.1 03-Aug-2004  skrll Sync with HEAD
 1.10.70.2 02-Jun-2008  mjf Sync with HEAD.
 1.10.70.1 03-Apr-2008  mjf Sync with HEAD.
 1.11.4.3 11-Mar-2010  yamt sync with head
 1.11.4.2 16-May-2009  yamt sync with head
 1.11.4.1 16-May-2008  yamt sync with head.
 1.11.2.1 18-May-2008  yamt sync with head.
 1.12.14.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.22 07-Sep-2025  thorpej Change todr_chip_handle::cookie -> todr_chip_handle::todr_dev, and
make it a device_t. Upcoming functional changes will require the
device_t associated with a TODR device.

Change todr_chip_handle::bus_cookie -> todr_chip_handle::todr_devaux.
Nothing was using the old field, but I decided to keep it around just
in cause something needs it in the future.

And with these largely mechanical yet semantically meaningful changes,
thus spake the Oracle: "Welcome to NetBSD 11.99.2."
 1.21 06-Mar-2024  thorpej Expose mc146818_{get,set}time_ymdhms() and allow a front-end to override
these function pointers in the TODR handle, allowing the front-end to
wrap mc146818_{get,set}time_ymdhms() with special handling, if needed.
 1.20 01-Jan-2020  thorpej Fix some issues around todr_wenable():
- As previously defined, it was not possible to return an error from the
back-end RTC driver. Make it a real function so that it can do so.
- Only the mc146818 and mk48txx drivers used it (for historical reasons).
Centralize the logic for how it's used in kern_todr.c (and make it private
to that file) for consistency.
 1.19 20-Nov-2014  christos branches: 1.19.20;
use the inline bcdtobin and bintobcd directly instead through a macro.
 1.18 13-Dec-2008  tsutsui branches: 1.18.24;
Revert part of previous that reverted part of rev 1.14
which didn't affect the bug. (use __func__ to print function names)
 1.17 11-Dec-2008  kenh The wrong sense of the UIP register is used to test for a pending clock
update; this test is now correct.

mc146818_settime_ymdhms has been refactored to simply stop clock updates
while the time is being set. Based on FreeBSD code and macros in
mc146868reg.h.
 1.16 14-May-2008  tsutsui branches: 1.16.4; 1.16.6; 1.16.8;
Normalize my licenses.
 1.15 10-Jan-2008  tsutsui branches: 1.15.6; 1.15.8; 1.15.10; 1.15.12;
Move todr_attach(9) calls from each MD attachment to MI mc146818_attach().
 1.14 10-Jan-2008  tsutsui - use aprint_normal(9)
- use __func__ to print function names
 1.13 19-Oct-2007  ad branches: 1.13.2; 1.13.8;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.12 10-Sep-2006  tsutsui branches: 1.12.4; 1.12.10; 1.12.24; 1.12.26; 1.12.30;
Fix a typo (settime -> gettime) so that we can get time.
 1.11 07-Sep-2006  simonb branches: 1.11.2;
Revert rev 1.9. As pointed out by Izumi Tsutsui, the \n is printed
by MD code.
 1.10 07-Sep-2006  gdamore Switch to friendlier todr ymdhms entry points. Moved a consistency check
to common kern_todr.c while here.
 1.9 06-Sep-2006  simonb Add \n to end of autoconf message.
 1.8 04-Sep-2006  gdamore Remove unused todr_setcal/todr_getcal and all the assorted stub
implementations.
 1.7 11-Dec-2005  christos branches: 1.7.4; 1.7.8;
merge ktrace-lwp.
 1.6 04-Jun-2005  he branches: 1.6.2;
Fix the various todr_gettime() and todr_settime() fallouts from
-Wcast-qual differently, by instead changing the signatore of those
"functions" to take a "volatile struct timeval*" instead of a
"struct timeval*". Many places, these functions are called with
&time, and time is declared as volatile in <sys/kernel.h>. This
way we can get rid of all the ugly casts which now also triggered
warnings, and caused more code to be added to work around the
problem.

Reviewed by thorpej.
 1.5 25-Sep-2004  tsutsui Use ANSI function decls.
 1.4 24-Nov-2003  tsutsui branches: 1.4.4;
Handle BCD mode properly.
 1.3 01-Nov-2003  tsutsui Rename flag NO_CENTURY_ADJUST -> MC146818_NO_CENT_ADJUST to avoid conflicts.
 1.2 29-Oct-2003  tsutsui Fix think-o about century handling in settime function.
 1.1 29-Oct-2003  tsutsui Add MI driver for mc146818 based time-of-day clock with todr(9) support.
 1.4.4.6 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.4.4.5 19-Oct-2004  skrll Sync with HEAD
 1.4.4.4 21-Sep-2004  skrll Fix the sync with head I botched.
 1.4.4.3 18-Sep-2004  skrll Sync with HEAD.
 1.4.4.2 03-Aug-2004  skrll Sync with HEAD
 1.4.4.1 24-Nov-2003  skrll file mc146818.c was added on branch ktrace-lwp on 2004-08-03 10:46:17 +0000
 1.6.2.3 21-Jan-2008  yamt sync with head
 1.6.2.2 27-Oct-2007  yamt sync with head.
 1.6.2.1 30-Dec-2006  yamt sync with head.
 1.7.8.1 14-Sep-2006  yamt sync with head.
 1.7.4.1 09-Sep-2006  rpaulo sync with head
 1.11.2.1 18-Nov-2006  ad Sync with head.
 1.12.30.1 25-Oct-2007  bouyer Sync with HEAD.
 1.12.26.2 23-Mar-2008  matt sync with HEAD
 1.12.26.1 06-Nov-2007  matt sync with HEAD
 1.12.24.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.12.10.1 23-Oct-2007  ad Sync with head.
 1.12.4.1 13-Dec-2008  bouyer Pull up following revision(s) (requested by tsutsui in ticket #1248):
sys/dev/ic/mc146818.c: revision 1.17 via patch
The wrong sense of the UIP register is used to test for a pending clock
update; this test is now correct.
mc146818_settime_ymdhms has been refactored to simply stop clock updates
while the time is being set. Based on FreeBSD code and macros in
mc146868reg.h.
 1.13.8.1 10-Jan-2008  bouyer Sync with HEAD
 1.13.2.1 18-Feb-2008  mjf Sync with HEAD.
 1.15.12.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.15.10.2 04-May-2009  yamt sync with head.
 1.15.10.1 16-May-2008  yamt sync with head.
 1.15.8.1 18-May-2008  yamt sync with head.
 1.15.6.2 17-Jan-2009  mjf Sync with HEAD.
 1.15.6.1 02-Jun-2008  mjf Sync with HEAD.
 1.16.8.1 13-Dec-2008  bouyer Pull up following revision(s) (requested by tsutsui in ticket #184):
sys/dev/ic/mc146818.c: revision 1.17
sys/dev/ic/mc146818.c: revision 1.18
The wrong sense of the UIP register is used to test for a pending clock
update; this test is now correct.
mc146818_settime_ymdhms has been refactored to simply stop clock updates
while the time is being set. Based on FreeBSD code and macros in
mc146868reg.h.
Revert part of previous that reverted part of rev 1.14
which didn't affect the bug. (use __func__ to print function names)
 1.16.6.1 19-Jan-2009  skrll Sync with HEAD.
 1.16.4.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.18.24.1 03-Dec-2017  jdolecek update from HEAD
 1.19.20.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.2 28-Jun-1995  cgd move to more appropriate (...reg.h) names.
 1.1 04-May-1995  cgd machine-independent definitions for the Motorola MC146818A Real Time Clock
and compatible chips, including the Dallas Semicontuctor DS1287A.
This chip is used in PC's, DECstations, and Alphas, at least...
 1.9 08-Mar-2006  lukem Use the SI capitalization for "Hz", "kHz", and "MHz" in comments and strings.
Add a space between numbers and Hz unit.
 1.8 11-Dec-2005  christos branches: 1.8.4; 1.8.6; 1.8.8; 1.8.10;
merge ktrace-lwp.
 1.7 27-Feb-2005  perry branches: 1.7.4;
nuke trailing whitespace
 1.6 04-Feb-2005  perry de-__P
 1.5 02-Nov-2003  wiz branches: 1.5.8; 1.5.10;
Fix some typos. From Tom Cosgrove via jmc@openbsd.
 1.4 29-Oct-2003  tsutsui Switch arc to use MI mc146818 tod driver.
 1.3 08-Jul-2003  itojun function prototype must not have variable name
 1.2 12-Mar-1997  cgd branches: 1.2.56;
properly #define MC_REGB_SQWE. From Matt Jacob
 1.1 04-May-1995  cgd machine-independent definitions for the Motorola MC146818A Real Time Clock
and compatible chips, including the Dallas Semicontuctor DS1287A.
This chip is used in PC's, DECstations, and Alphas, at least...
 1.2.56.5 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.2.56.4 04-Feb-2005  skrll Sync with HEAD.
 1.2.56.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.2.56.2 18-Sep-2004  skrll Sync with HEAD.
 1.2.56.1 03-Aug-2004  skrll Sync with HEAD
 1.5.10.2 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.5.10.1 12-Feb-2005  yamt sync with head.
 1.5.8.1 29-Apr-2005  kent sync with -current
 1.7.4.1 21-Jun-2006  yamt sync with head.
 1.8.10.1 19-Apr-2006  elad sync with head.
 1.8.8.1 13-Mar-2006  yamt sync with head.
 1.8.6.1 22-Apr-2006  simonb Sync with head.
 1.8.4.1 09-Sep-2006  rpaulo sync with head
 1.8 06-Mar-2024  thorpej Expose mc146818_{get,set}time_ymdhms() and allow a front-end to override
these function pointers in the TODR handle, allowing the front-end to
wrap mc146818_{get,set}time_ymdhms() with special handling, if needed.
 1.7 14-May-2008  tsutsui Normalize my licenses.
 1.6 29-Mar-2008  tsutsui branches: 1.6.2; 1.6.4; 1.6.6;
Fix wrong type.
 1.5 28-Mar-2008  tsutsui Split device_t and softc for MI mc146818 clock,
and other related misc cosmetics.
 1.4 11-Dec-2005  christos branches: 1.4.70;
merge ktrace-lwp.
 1.3 24-Nov-2003  tsutsui branches: 1.3.4;
Handle BCD mode properly.
 1.2 01-Nov-2003  tsutsui Rename flag NO_CENTURY_ADJUST -> MC146818_NO_CENT_ADJUST to avoid conflicts.
 1.1 29-Oct-2003  tsutsui Add MI driver for mc146818 based time-of-day clock with todr(9) support.
 1.3.4.4 21-Sep-2004  skrll Fix the sync with head I botched.
 1.3.4.3 18-Sep-2004  skrll Sync with HEAD.
 1.3.4.2 03-Aug-2004  skrll Sync with HEAD
 1.3.4.1 24-Nov-2003  skrll file mc146818var.h was added on branch ktrace-lwp on 2004-08-03 10:46:17 +0000
 1.4.70.2 02-Jun-2008  mjf Sync with HEAD.
 1.4.70.1 03-Apr-2008  mjf Sync with HEAD.
 1.6.6.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.6.4.1 16-May-2008  yamt sync with head.
 1.6.2.1 18-May-2008  yamt sync with head.
 1.6 05-Oct-2024  andvar s/channes/channel/ in comment.
 1.5 28-Apr-2008  martin branches: 1.5.126;
Remove clause 3 and 4 from TNF licenses
 1.4 11-Dec-2005  christos branches: 1.4.70; 1.4.72; 1.4.74;
merge ktrace-lwp.
 1.3 27-Feb-2005  perry nuke trailing whitespace
 1.2 10-Feb-1999  minoura branches: 1.2.42; 1.2.50; 1.2.52;
void* -> u_int32_t
 1.1 30-Jan-1999  minoura MC68450 DMAC regs.
 1.2.52.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.2.50.1 29-Apr-2005  kent sync with -current
 1.2.42.1 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.4.74.1 16-May-2008  yamt sync with head.
 1.4.72.1 18-May-2008  yamt sync with head.
 1.4.70.1 02-Jun-2008  mjf Sync with HEAD.
 1.5.126.1 02-Aug-2025  perseant Sync with HEAD
 1.4 11-Dec-2005  christos merge ktrace-lwp.
 1.3 24-Mar-2004  drochner remove license clauses 3 and 4 from my cpoyright notices
 1.2 27-Jan-2003  tsutsui branches: 1.2.2;
- Use u_int8_t instead of char for register structure.
- Define MC6845_NREGS like vgareg.h.
 1.1 28-May-1998  drochner Put definitions and subroutines needed for all PC display adapters
(MGA/GCA and compatibles) into global headers / source files.
Let the VGA driver use them.
 1.2.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.2.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.2.2.1 03-Aug-2004  skrll Sync with HEAD
 1.2 11-Apr-2019  kamil Fix a typo in a comment
 1.1 10-Sep-2001  bjh21 branches: 1.1.2; 1.1.4; 1.1.6; 1.1.212;
Driver for the standard Archimedes Econet interface, based around the
Motorola 6854 ADLC.
 1.1.212.1 10-Jun-2019  christos Sync with HEAD
 1.1.6.2 01-Oct-2001  fvdl Catch up with -current.
 1.1.6.1 10-Sep-2001  fvdl file mc6854reg.h was added on branch thorpej-devvp on 2001-10-01 12:45:39 +0000
 1.1.4.2 21-Sep-2001  nathanw Catch up to -current.
 1.1.4.1 10-Sep-2001  nathanw file mc6854reg.h was added on branch nathanw_sa on 2001-09-21 22:35:43 +0000
 1.1.2.2 13-Sep-2001  thorpej Update the kqueue branch to HEAD.
 1.1.2.1 10-Sep-2001  thorpej file mc6854reg.h was added on branch kqueue on 2001-09-13 01:15:41 +0000
 1.3 09-Jul-2025  andvar fix few typos in comments.
 1.2 17-Jan-2022  thorpej branches: 1.2.10;
Pass the controller devhandle along to the GPIO layer.
 1.1 17-Jan-2022  thorpej Re-factor and overhaul the "mcp23s17gpio" driver as "mcpgpio", and
add support for 8-bit and I2C variants of the chip:
- MCP23008 / MCP23S08: 8-bit (I2C / SPI)
- MCP23017 / MCP23S17: 16-bit (I2C / SPI)
- MCP23018 / MCP23S18: 16-bit (I2C / SPI), open-drain outputs

The MCP23x17 and MCP23x18 are essentially identical, software-wise; we
merely report different GPIO pin capabilities (no push-pull output for
MCP23x18). Also, remove the tri-state capability that was previously
advertised by the old version of this driver; these chips have no way
to put the pin into a HI-Z mode.

All 3 I2C versions are supported, but the SPI front-end still only
supports the MCP23S17 for now (SPI autoconfiguration needs an overhaul).

mcp23s17gpio(4) remains present as a link to the new mcpgpio(4) man page.

XXX Still to-do: FDT integration, interrupt suppoort.
 1.2.10.1 02-Aug-2025  perseant Sync with HEAD
 1.1 17-Jan-2022  thorpej Re-factor and overhaul the "mcp23s17gpio" driver as "mcpgpio", and
add support for 8-bit and I2C variants of the chip:
- MCP23008 / MCP23S08: 8-bit (I2C / SPI)
- MCP23017 / MCP23S17: 16-bit (I2C / SPI)
- MCP23018 / MCP23S18: 16-bit (I2C / SPI), open-drain outputs

The MCP23x17 and MCP23x18 are essentially identical, software-wise; we
merely report different GPIO pin capabilities (no push-pull output for
MCP23x18). Also, remove the tri-state capability that was previously
advertised by the old version of this driver; these chips have no way
to put the pin into a HI-Z mode.

All 3 I2C versions are supported, but the SPI front-end still only
supports the MCP23S17 for now (SPI autoconfiguration needs an overhaul).

mcp23s17gpio(4) remains present as a link to the new mcpgpio(4) man page.

XXX Still to-do: FDT integration, interrupt suppoort.
 1.2 17-Jan-2022  thorpej G/C mcpgpio_softc::sc_phandle; nothing is using it.
 1.1 17-Jan-2022  thorpej Re-factor and overhaul the "mcp23s17gpio" driver as "mcpgpio", and
add support for 8-bit and I2C variants of the chip:
- MCP23008 / MCP23S08: 8-bit (I2C / SPI)
- MCP23017 / MCP23S17: 16-bit (I2C / SPI)
- MCP23018 / MCP23S18: 16-bit (I2C / SPI), open-drain outputs

The MCP23x17 and MCP23x18 are essentially identical, software-wise; we
merely report different GPIO pin capabilities (no push-pull output for
MCP23x18). Also, remove the tri-state capability that was previously
advertised by the old version of this driver; these chips have no way
to put the pin into a HI-Z mode.

All 3 I2C versions are supported, but the SPI front-end still only
supports the MCP23S17 for now (SPI autoconfiguration needs an overhaul).

mcp23s17gpio(4) remains present as a link to the new mcpgpio(4) man page.

XXX Still to-do: FDT integration, interrupt suppoort.
 1.80 02-Feb-2024  andvar s/mangement/management/ in comments.
 1.79 24-May-2022  andvar fix various typos in comment, documentation and log messages.
 1.78 22-May-2022  hannken Use PRIxBUSADDR for bus_addr_t in debug printf.

Kernel i386/ALL compiles again.
 1.77 13-May-2022  msaitoh Improve DNPRINTF. No functional change.
 1.76 12-May-2022  msaitoh Don't use MFI_PD_LIST_SIZE. Same as OpenBSD. No functional change.
 1.75 10-May-2022  msaitoh mfi(4): Set stripe size correctly for BIOCVOL.

Before:
Volume Status Size Device/Label Level Stripe
 1.74 09-May-2022  msaitoh Use union mbox instead of unit8_t[] to avoid unaligned access.

- Same as other OSes.
- mfii.c already use this.
- Found by kUBSan.
 1.73 09-May-2022  msaitoh KNF. Whitespace. No functional change.
 1.72 07-May-2022  msaitoh Clear mailbox to not to pass garbage data.
 1.71 07-May-2022  msaitoh Use mlp_bgi for MFI_LD_PROG_BGI. Same as OpenBSD.
 1.70 07-May-2022  msaitoh s/contrller/controller/ in comment.
 1.69 05-May-2022  msaitoh Add some code for the SKINNY variant to make Dell PERC H310 work.
 1.68 16-Apr-2022  andvar fix various typos in comments and log messages.
 1.67 05-Dec-2021  msaitoh s/decriptor/descriptor/ in comment.
 1.66 06-Nov-2021  msaitoh s/allign/align/
 1.65 07-Aug-2021  thorpej Merge thorpej-cfargs2.
 1.64 24-Apr-2021  thorpej branches: 1.64.8;
Merge thorpej-cfargs branch:

Simplify and make extensible the config_search() / config_found() /
config_attach() interfaces: rather than having different variants for
which arguments you want pass along, just have a single call that
takes a variadic list of tag-value arguments.

Adjust all call sites:
- Simplify wherever possible; don't pass along arguments that aren't
actually needed.
- Don't be explicit about what interface attribute is attaching if
the device only has one. (More simplification.)
- Add a config_probe() function to be used in indirect configuiration
situations, making is visibly easier to see when indirect config is
in play, and allowing for future change in semantics. (As of now,
this is just a wrapper around config_match(), but that is an
implementation detail.)

Remove unnecessary or redundant interface attributes where they're not
needed.

There are currently 5 "cfargs" defined:
- CFARG_SUBMATCH (submatch function for direct config)
- CFARG_SEARCH (search function for indirect config)
- CFARG_IATTR (interface attribte)
- CFARG_LOCATORS (locators array)
- CFARG_DEVHANDLE (devhandle_t - wraps OFW, ACPI, etc. handles)

...and a sentinel value CFARG_EOL.

Add some extra sanity checking to ensure that interface attributes
aren't ambiguous.

Use CFARG_DEVHANDLE in MI FDT, OFW, and ACPI code, and macppc and shark
ports to associate those device handles with device_t instance. This
will trickle trough to more places over time (need back-end for pre-OFW
Sun OBP; any others?).
 1.63 07-Jan-2020  maxv branches: 1.63.10;
Set 'ld_sync' to NULL as part of 'again', to prevent use-after-free.
 1.62 10-Nov-2019  chs in many device attach paths, allocate memory with M_WAITOK instead of M_NOWAIT
and remove code to handle failures that can no longer happen.
 1.61 29-Jul-2019  gdt branches: 1.61.2;
sys/dev/ic/mfi.c: Add missing break in switch

(The entire switch is guarded by MFI_DEBUG and is known not to build.)
Reported by Oskar.
 1.60 24-Nov-2018  bouyer Add some definitions from OpenBSD, needed by the upcoming mfii driver.
No functionnal change.
 1.59 03-Sep-2018  riastradh Rename min/max -> uimin/uimax for better honesty.

These functions are defined on unsigned int. The generic name
min/max should not silently truncate to 32 bits on 64-bit systems.
This is purely a name change -- no functional change intended.

HOWEVER! Some subsystems have

#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))

even though our standard name for that is MIN/MAX. Although these
may invite multiple evaluation bugs, these do _not_ cause integer
truncation.

To avoid `fixing' these cases, I first changed the name in libkern,
and then compile-tested every file where min/max occurred in order to
confirm that it failed -- and thus confirm that nothing shadowed
min/max -- before changing it.

I have left a handful of bootloaders that are too annoying to
compile-test, and some dead code:

cobalt ews4800mips hp300 hppa ia64 luna68k vax
acorn32/if_ie.c (not included in any kernels)
macppc/if_gm.c (superseded by gem(4))

It should be easy to fix the fallout once identified -- this way of
doing things fails safe, and the goal here, after all, is to _avoid_
silent integer truncations, not introduce them.

Maybe one day we can reintroduce min/max as type-generic things that
never silently truncate. But we should avoid doing that for a while,
so that existing code has a chance to be detected by the compiler for
conversion to uimin/uimax without changing the semantics until we can
properly audit it all. (Who knows, maybe in some cases integer
truncation is actually intended!)
 1.58 28-Oct-2017  riastradh branches: 1.58.2; 1.58.4;
Kill some more extern struct cfdriver declarations.

Down with externs in .c!
 1.57 04-Apr-2015  christos branches: 1.57.10;
fix double free, found by Brainy.
 1.56 12-Mar-2015  christos Dedup the conversion of bioc_disk and bioc_vol to envsys_data_t
 1.55 21-Aug-2014  christos branches: 1.55.2;
over-initialize for the benefit of gcc
 1.54 21-Aug-2014  christos revert previous; code checking tool is incorrect. Variables are not being
used in the non tbolt case.
 1.53 25-Jul-2014  dholland branches: 1.53.2;
Add d_discard to all struct cdevsw instances I could find.

All have been set to "nodiscard"; some should get a real implementation.
 1.52 16-Mar-2014  dholland branches: 1.52.2;
Change (mostly mechanically) every cdevsw/bdevsw I can find to use
designated initializers.

I have not built every extant kernel so I have probably broken at
least one build; however I've also found and fixed some wrong
cdevsw/bdevsw entries so even if so I think we come out ahead.
 1.51 25-Jan-2014  skrll More alignment spellos
 1.50 17-Oct-2013  christos - remove unused variables
- move variables inside ifdef sections
- ifdef notdef unused code
- use __USE for debugging variables
 1.49 28-Jun-2013  christos branches: 1.49.2;
Fix the non-thunderbolt case. XXX: Is that right even?
http://m00nbsd.net/ae123a9bae03f7dde5c6d654412daf5a.html
 1.48 09-Nov-2012  bouyer MFI_STATE_BOOT_MESSAGE_PENDING also needs to be handed for non-TBOLT
controllers, from FreeBSD. tested by Hugo Silva against a GEN2 controller.
 1.47 19-Sep-2012  bouyer Add a pass-through ioctl for mfi(4), allowing userland to send raw commands
to the controller. This is compatible with the linux and FreeBSD
implementations.
Add the needed conversion for mfi ioctls in COMPAT_LINUX
Allocate a character major number, and create /dev/mfi0 by default
on amd64 and i386.
This allows (along with a hand-created /emul/linux/proc/devices file)
to run the MegaCLI linux binary provided by LSI.
 1.46 26-Aug-2012  bouyer branches: 1.46.2;
Make MFI_DEBUG build on i386.
Report BBU state changes with aprint_normal(), it seems that sysmon_envsys()
doens't report changes for ENVSYS_INDICATOR as it does for ENVSYS_DRIVE.
 1.45 26-Aug-2012  bouyer After discussion on tech-kern@, fix performance issue related to
cache flush commands from WAPBL, by skipping the cache flush if the
BBU is present and considered good. Users which still want the write back
cache with a non-working BBU can set vfs.wapbl.flush_disk_cache to 0.
- add commands to monitor the BBU state. Add a boolean BBU sensor
to monitor the BBU state via sysmon_envsys(9).
- if the BBU is considered good, turn SCSI_SYNCHRONIZE_CACHE_10 and
SCSI_SYNCHRONIZE_CACHE_16 commands from upper layer into NOOPs.
While there, handle SCSI_SYNCHRONIZE_CACHE_16 in addition to
SCSI_SYNCHRONIZE_CACHE_10.
- Add a shutdown pmf(9) handler, which flushes the cache and shutdown the
firmware
- on detach, also flush cache and shutdown firmware.
- on attach, print the firmware-provided name, and the BBU state
Tested on a LSI MegaRAID SAS 9265-8i and a PERC 5/i Integrated
 1.44 23-Aug-2012  bouyer Avoid "unused variable" warning for non-DIAGNOSTIC kernels.
Pointed out by Havard Eidnes
 1.43 23-Aug-2012  bouyer Add support newer LSI RAID controllers based on the SAS2208 chip,
codenamed "ThunderBolt". Add tagged queuing support for all adapters
supported by mfi(4).
Tested with a MegaRAID SAS 9265-8i adapter, and an older Dell PERC 5/i.
 1.42 05-Aug-2012  bouyer Really init sc_ioptype in mfi_attach()
 1.41 05-Aug-2012  bouyer sg64.len is 32bits, so use htole32()
 1.40 05-Aug-2012  bouyer MFI_IOP_SKINNY is an enum not a single bit value, so it can't be used as
a bit flag. As sc_flags is really used to hold an enum mfi_iop value,
change it to enum mfi_iop and rename to sc_ioptype. While there init it
in mfi_attach() instead of mfi_pci_attach().
 1.39 05-Aug-2012  bouyer Add some support for 64bit DMA but stick to 32bit DMA for now.
From OpenBSD mfi.c rev 1.119.
 1.38 21-Mar-2012  sborrill Add support for skinny variants (e.g. IBM ServeRAID M1015). Based on OpenBSD
changes with some improvements. Tested on IBM x3550M3 with RAID0 and RAID1
volumes including bioctl(8) operation.
 1.37 21-Mar-2012  sborrill From OpenBSD. Fixes a deadlock during autoconf.

scrub more fields in the ccb when returning them to the free list after
theyve been used, in particular the mfi header flags which has a bit
that specifies if a command should be completed via the interrupt path.

if we use a ccb during boot we set that bit, but it isnt necessarily
cleared by things that use it later on. this means a ccb we expected to
complete via an interrupt never actually generates an interrupt or appears
in the reply queue. this obviously stalls the io.
 1.36 20-Jun-2011  pgoyette branches: 1.36.2; 1.36.6; 1.36.8;
Initialize current value for ENVSYS_DRIVE sensors
 1.35 20-Jun-2011  pgoyette Initializes sensors states before registering.
 1.34 14-Mar-2010  pgoyette branches: 1.34.8;
Remove setting of edata->monitor since that member no longer exists.
 1.33 09-Feb-2010  msaitoh Add newer cars supports. Tested on MegaRAID SAS 9260-8i.
- Add MFI gen2 support from OpenBSD.
- Add entry for MegaRAID SAS 9260-8i
 1.32 08-Feb-2010  msaitoh Fix a bug that the system which has no logical volume panics in shutdown
hook. Without any logical volume, sysmon_envsys_register() fails. On such
case, sc->sc_sme must be NULL for the detach. Reviewed by dyoung and bouyer.
 1.31 19-Jan-2010  bouyer branches: 1.31.2;
bio(4) is MP-safe but mfi(4) is not. So get the kernel_lock at
mfi_ioctl() entry and release it on exit.
 1.30 13-Sep-2009  dyoung Delete whitespace at ends of lines. No functional change intended.
 1.29 27-Aug-2009  bouyer Oups, remove extra }
 1.28 26-Aug-2009  bouyer mfi.c still uses the spl() synchronisation scheme and so needs the kernel lock.
The sysmon subsystem is marked MPSAFE and so runs without the kernel lock.
So get the kernel lock in mfi_sensor_refresh() before calling
mfi_ioctl_vol().
This fixes command list corruption seen on heavy I/O load on the mfi
driver(4).
 1.27 16-Jul-2009  dyoung Let us detach & re-attach children of mfi0. Detach mfi0 at shutdown.

Detachment may fail after freeing some but not all resources, so
take care not to re-release any resource during detachment.

Tested on a Dell PowerEdge 1950.
 1.26 16-Jul-2009  dyoung device_t/softc split. Tested and shown to work on a Dell PowerEdge
1950.
 1.25 16-Jul-2009  dyoung Try to detach ancestors (sd0 at scsibus0, scsibus0 at mfi0), first,
to avoid dangling references to envsys(4) sensors and such if
detaching the ancestors should fail.
 1.24 16-Jul-2009  dyoung Add a rudimentary detachment hook for mfi(4).
 1.23 12-May-2009  cegger struct device * -> device_t, no functional changes intended.
 1.22 18-Mar-2009  cegger bzero -> memset
 1.21 16-Feb-2009  mlelstv Don't release CCB twice. Found by code inspection.
 1.20 03-Jan-2009  yamt branches: 1.20.2;
remove extra semicolons.
 1.19 23-Oct-2008  bouyer branches: 1.19.2; 1.19.4; 1.19.8; 1.19.10;
Change mfi_mgmt() to take a mfi_ccb and scsipi_xfer as argument, as
mfi_scsi_io does. Do not tsleep in mfi_mgmt waiting for completion;
let the caller handle it. If mfi_mgmt() is called with a non-NULL scsipi_xfer
have mfi_mgmt_done() wake it up, else wake up the mfi_ccb.
mfi_poll()/mfi_post() is up to the caller.

mfi_scsipi_request(): handle SCSI_SYNCHRONIZE_CACHE_10 as we do for other
commmands: have mfi_mgmt() fill in the ccb, queue of poll the ccb and
return.

Introduce mfi_mgmt_internal() which behaves like mfi_mgmt() did (tsleep
waiting for completion). Use it for internal and ioctl management
requests.

Fix kern/39297 from Greg Oster (mfi calls tsleep() from mfi_intr()),
tested by Mark Davies.
 1.18 24-Jun-2008  gmcgarry branches: 1.18.2;
status is unsigned.
 1.17 22-Apr-2008  cegger branches: 1.17.2; 1.17.4; 1.17.6;
revert rev. 1.16 and redo the fix as proposed by oster per private mail
 1.16 22-Apr-2008  cegger Fix error path:
Don't try to free non-allocated memory. Only free allocated memory.
This fixes a crash reported by Brian A. Seklecki on port-xen:
http://mail-index.netbsd.org/port-xen/2008/04/10/msg003555.html

Fix tested by Brian A. Seklecki:
http://mail-index.netbsd.org/port-xen/2008/04/21/msg003604.html
 1.15 08-Apr-2008  cegger branches: 1.15.2;
use aprint_*_dev and device_xname
 1.14 27-Mar-2008  xtraeme Add back the bus_dmamap_sync() calls that were in the old
mfi_despatch_cmd() func after merging changes in rev 1.12.

Merge rev 1.69 and 1.64 from openbsd, fixing two bugs:

Fix subtle x ? y : z bug when calling mfi_create_sgl. This worked because
during runtime the bug condition does not happen.

When determining the size of the volumes and disks we want how many
bytes each of them has, not the number of kilobytes. this solves the
"why am i dividing by 2" question. the answer is "you dont, you multiply
by 512".

The first item fixes a panic with Dell Perc 5/i reported by oster@.
Changes tested on Dell Perc 5/i by oster@.
 1.13 25-Feb-2008  xtraeme Apply some KNF to this driver and do some random changes as well:

- Change malloc + memset(blah, 0, ...) to malloc with M_ZERO.
- The adapt_ioctl assigned was returning ENOTTY, so there's no point
on having it.
- Static'ify.

I believe there are some paths on this driver where the splbio()s
are not needed, but can't test to verify...
 1.12 25-Feb-2008  xtraeme Added support for the mfi(4) controllers with powerpc IOPs such as
LSI SAS1078 or Dell PERC 6, from OpenBSD.

Tested by Akira Kato on current-users@.
 1.11 16-Nov-2007  xtraeme branches: 1.11.10; 1.11.14;
Extend the envsys2 API (one more time, sorry) as defined in:

http://mail-index.netbsd.org/tech-kern/2007/11/09/0001.html

sysmon_envsys_create() and sysmon_envsys_destroy() were added to
create/destroy sysmon_envsys objects (and its TAILQ/LIST for sensors/events).

sysmon_envsys_sensor_attach() and sysmon_envsys_sensor_detach() were
added to attach/detach sensors to a specified sysmon_envsys device.

The events framework is now per device and configurable via the
ENVSYS_SETDICTIONARY ioctl or /etc/envsys.conf and envstat(8).

Update all users and documentation to reflect these changes.
 1.10 19-Oct-2007  ad branches: 1.10.2;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.9 04-Sep-2007  xtraeme branches: 1.9.4;
s/ENVSYS_FMONDRVSTATE/ENVSYS_FMONSTCHANGED/. Noticed by Manuel Bouyer@.
 1.8 04-Jul-2007  xtraeme branches: 1.8.2; 1.8.6; 1.8.8;
mfi_sensor_gtredata:

- There's no need to set edata->units again, it was set already before.
- Remove the last ENVSYS_SVALID assignment that overrides previous
assignments (found by mhitch@).
 1.7 01-Jul-2007  xtraeme There's no need to set ENVSYS_FMONNOTSUPP in sensor's flags anymore,
userland limits for this type of sensor is disabled by sysmon_envsys(9).
 1.6 01-Jul-2007  xtraeme Imported envsys 2, a brief description of the new features:
(Part 2: drivers)

* Support for detachable sensors.
* Cleaned up the API for simplicity and efficiency.
* Ability to send capacity/critical/warning events to powerd(8).
* Adapted all the code to the new locking order.
* Compatibility with the old envsys API: the ENVSYS_GTREINFO
and ENVSYS_GTREDATA ioctl(2)s are supported.
* Added support for a 'dictionary based communication channel' between
sysmon_power(9) and powerd(8), that means there is no 32 bytes event
size restriction anymore.
* Binary compatibility with old envstat(8) and powerd(8) via COMPAT_40.
* All drivers with the n^2 gtredata bug were fixed, PR kern/36226.

Tested by:

blymn: smsc(4).
bouyer: ipmi(4), mfi(4).
kefren: ug(4).
njoly: viaenv(4), adt7463.c.
riz: owtemp(4).
xtraeme: acpiacad(4), acpibat(4), acpitz(4), aiboost(4), it(4), lm(4).
 1.5 01-May-2007  dogcow tred->sensor is a u_int.
 1.4 01-May-2007  bouyer Add bio(4) and associated bioctl(8) from OpenBSD, a driver control block
device controllers, and more specifically raid controllers.
Add a new sensor type, ENVSYS_DRIVE, to report drive status. From OpenBSD.
Add bio and sysmon support to mfi(4). This allow userland to query
status for drives and logical volumes attached to a mfi(4) controller. While
there fix some debug printfs in mfi so they compile.
Add bio(4) to amd64 and i386 GENERIC.
 1.3 04-Mar-2007  christos branches: 1.3.2; 1.3.4;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.2 20-Dec-2006  bouyer branches: 1.2.2; 1.2.4; 1.2.6; 1.2.8; 1.2.10;
Add missing $NetBSD: $
 1.1 17-Dec-2006  bouyer branches: 1.1.2;
Add mfi(4), a driver for LSI Logic & Dell MegaRAID SAS RAID controller.
Ported from OpenBSD, tested on i386 and amd64.
 1.1.2.3 21-Dec-2006  yamt sync with head.
 1.1.2.2 18-Dec-2006  yamt sync with head.
 1.1.2.1 17-Dec-2006  yamt file mfi.c was added on branch yamt-splraiseipl on 2006-12-18 11:42:13 +0000
 1.2.10.2 07-May-2007  yamt sync with head.
 1.2.10.1 12-Mar-2007  rmind Sync with HEAD.
 1.2.8.2 12-Jan-2007  ad Sync with head.
 1.2.8.1 20-Dec-2006  ad file mfi.c was added on branch newlock2 on 2007-01-12 00:57:36 +0000
 1.2.6.6 27-Feb-2008  yamt sync with head.
 1.2.6.5 07-Dec-2007  yamt sync with head
 1.2.6.4 27-Oct-2007  yamt sync with head.
 1.2.6.3 03-Sep-2007  yamt sync with head.
 1.2.6.2 30-Dec-2006  yamt sync with head.
 1.2.6.1 20-Dec-2006  yamt file mfi.c was added on branch yamt-lazymbuf on 2006-12-30 20:48:03 +0000
 1.2.4.3 15-Oct-2007  riz Pull up following revisions via patch (requested by bouyer in ticket #1838):
distrib/sets/lists/man/mi: revision 1.997
sbin/bioctl/strtonum.c: revision 1.1
sys/dev/Makefile: revision 1.25
sys/arch/amd64/conf/GENERIC: revision 1.139
sbin/bioctl/strtonum.h: revision 1.1
sys/dev/bio.c: revision 1.1
sbin/bioctl/bioctl.c: revision 1.1
share/man/man4/bio.4: revision 1.1
sbin/bioctl/bioctl.8: revision 1.1
sys/sys/envsys.h: revision 1.11
sbin/bioctl/bioctl.8: revision 1.3
sbin/bioctl/bioctl.8: revision 1.4
sys/arch/i386/conf/XEN2_DOM0: revision 1.25
distrib/sets/lists/base/mi: revision 1.704
sys/conf/majors: revision 1.34
share/man/man4/Makefile: revision 1.426
etc/MAKEDEV.tmpl: revision 1.86
sys/arch/i386/conf/GENERIC: revision 1.825
distrib/sets/lists/comp/mi: revision 1.1022
sys/conf/files: revision 1.839
usr.sbin/envstat/envstat.c: revision 1.24
sbin/Makefile: revision 1.105
sys/dev/ic/mfi.c: revision 1.4
sys/dev/biovar.h: revision 1.1
sys/dev/ic/mfivar.h: revision 1.4
sbin/bioctl/Makefile: revision 1.1
Fix typo.
Add bio(4) and associated bioctl(8) from OpenBSD, a driver control block
device controllers, and more specifically raid controllers.
Add a new sensor type, ENVSYS_DRIVE, to report drive status. From OpenBSD.
Add bio and sysmon support to mfi(4). This allow userland to query
status for drives and logical volumes attached to a mfi(4) controller. While
there fix some debug printfs in mfi so they compile.
Add bio(4) to amd64 and i386 GENERIC.
Add bio(4) and associated bioctl(8) from OpenBSD, a driver control block
device controllers, and more specifically raid controllers.
Add a new sensor type, ENVSYS_DRIVE, to report drive status. From OpenBSD.
Add bio and sysmon support to mfi(4). This allow userland to query
status for drives and logical volumes attached to a mfi(4) controller. While
there fix some debug printfs in mfi so they compile.
Add bio(4) to amd64 and i386 GENERIC.
Fix Dd argument (use full month names).
Use more markup.
Comment out references to safte(4) and softraid(4), which don't exist in
NetBSD.
Remove trailing whitespace.
Use macros instead of characters for HTML output (replace ">", "<"
with \*[Gt], \*[Lt]).
Sort sections.
Create /dev/bio
 1.2.4.2 23-Dec-2006  ghen Pull up following revision(s) (requested by bouyer in ticket #1609):
sys/arch/i386/conf/INSTALL: revision 1.298
sys/arch/i386/conf/GENERIC: revision 1.802
sys/dev/pci/files.pci: revision 1.274
sys/arch/amd64/conf/GENERIC: revision 1.122
sys/dev/pci/mfi_pci.c: revision 1.1 via patch
distrib/sets/lists/man/mi: revision 1.958
sys/arch/amd64/conf/INSTALL: revision 1.61
sys/dev/ic/mfireg.h: revision 1.1
share/man/man4/Makefile: revision 1.416 via patch
sys/dev/ic/mfi.c: revision 1.1
sys/arch/i386/conf/XEN2_DOM0: revision 1.19
sys/dev/ic/mfivar.h: revision 1.1
sys/conf/files: revision 1.821
share/man/man4/mfi.4: revision 1.1
share/man/man4/mfi.4: revision 1.2
sys/dev/pci/pcidevs via patch
Add mfi(4), a driver for LSI Logic & Dell MegaRAID SAS RAID controller.
Ported from OpenBSD, tested on i386 and amd64.
Punctuation issues.
 1.2.4.1 20-Dec-2006  ghen file mfi.c was added on branch netbsd-3 on 2006-12-23 16:43:19 +0000
 1.2.2.4 08-May-2007  pavel Pull up following revision(s) (requested by bouyer in ticket #603):
distrib/sets/lists/base/mi: revision 1.704
distrib/sets/lists/comp/mi: revision 1.1022
distrib/sets/lists/man/mi: revision 1.997
doc/CHANGES: revision 1.839
sbin/Makefile: patch
sbin/bioctl/Makefile: revision 1.1
sbin/bioctl/bioctl.8: revision 1.1
sbin/bioctl/bioctl.c: revision 1.1
sbin/bioctl/strtonum.c: revision 1.1
sbin/bioctl/strtonum.h: revision 1.1
share/man/man4/Makefile: revision 1.426
share/man/man4/bio.4: revision 1.1
sys/arch/amd64/conf/GENERIC: revision 1.139
sys/arch/i386/conf/GENERIC: revision 1.825
sys/arch/i386/conf/XEN2_DOM0: revision 1.25
sys/conf/files: revision 1.839
sys/conf/majors: patch
sys/dev/Makefile: revision 1.25
sys/dev/bio.c: patch
sys/dev/biovar.h: patch
sys/dev/ic/mfi.c: revision 1.4-1.5
sys/dev/ic/mfivar.h: revision 1.4
sys/sys/envsys.h: revision 1.11
usr.sbin/envstat/envstat.c: revision 1.24
Add bio(4) and associated bioctl(8) from OpenBSD, a driver control block
device controllers, and more specifically raid controllers.
Add a new sensor type, ENVSYS_DRIVE, to report drive status. From OpenBSD.
Add bio and sysmon support to mfi(4). This allow userland to query
status for drives and logical volumes attached to a mfi(4) controller. While
there fix some debug printfs in mfi so they compile.
Add bio(4) to amd64 and i386 GENERIC.

note bio(4), envsys(4) DRIVE, and mfi(4) support for both.

tred->sensor is a u_int.
 1.2.2.3 21-Dec-2006  tron Pull up following revision(s) (requested by bouyer in ticket #286):
sys/dev/pci/mfi_pci.c: revision 1.2
sys/dev/ic/mfireg.h: revision 1.2
sys/dev/ic/mfi.c: revision 1.2
sys/dev/ic/mfivar.h: revision 1.2
Add missing $NetBSD: $
 1.2.2.2 21-Dec-2006  tron Pull up following revision(s) (requested by bouyer in ticket #286):
sys/arch/i386/conf/INSTALL: revision 1.298
sys/arch/i386/conf/GENERIC: revision 1.802
sys/dev/pci/files.pci: revision 1.274
sys/arch/amd64/conf/GENERIC: revision 1.122
sys/dev/pci/mfi_pci.c: revision 1.1
distrib/sets/lists/man/mi: revision 1.958
sys/arch/amd64/conf/INSTALL: revision 1.61
sys/arch/i386/conf/ALL: revision 1.75
sys/dev/ic/mfireg.h: revision 1.1
share/man/man4/Makefile: revision 1.416
sys/dev/ic/mfi.c: revision 1.1
sys/arch/i386/conf/XEN2_DOM0: revision 1.19
sys/dev/ic/mfivar.h: revision 1.1
sys/conf/files: revision 1.821
share/man/man4/mfi.4: revision 1.1
Add mfi(4), a driver for LSI Logic & Dell MegaRAID SAS RAID controller.
Ported from OpenBSD, tested on i386 and amd64.
 1.2.2.1 20-Dec-2006  tron file mfi.c was added on branch netbsd-4 on 2006-12-21 12:46:21 +0000
 1.3.4.1 11-Jul-2007  mjf Sync with head.
 1.3.2.4 23-Oct-2007  ad Sync with head.
 1.3.2.3 09-Oct-2007  ad Sync with head.
 1.3.2.2 15-Jul-2007  ad Sync with head.
 1.3.2.1 27-May-2007  ad Sync with head.
 1.8.8.3 23-Mar-2008  matt sync with HEAD
 1.8.8.2 09-Jan-2008  matt sync with HEAD
 1.8.8.1 06-Nov-2007  matt sync with HEAD
 1.8.6.3 21-Nov-2007  joerg Sync with HEAD.
 1.8.6.2 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.8.6.1 02-Oct-2007  joerg Sync with HEAD.
 1.8.2.1 10-Sep-2007  skrll Sync with HEAD.
 1.9.4.2 18-Nov-2007  bouyer Sync with HEAD
 1.9.4.1 25-Oct-2007  bouyer Sync with HEAD.
 1.10.2.1 19-Nov-2007  mjf Sync with HEAD.
 1.11.14.4 17-Jan-2009  mjf Sync with HEAD.
 1.11.14.3 29-Jun-2008  mjf Sync with HEAD.
 1.11.14.2 02-Jun-2008  mjf Sync with HEAD.
 1.11.14.1 03-Apr-2008  mjf Sync with HEAD.
 1.11.10.1 24-Mar-2008  keiichi sync with head.
 1.15.2.1 18-May-2008  yamt sync with head.
 1.17.6.1 27-Jun-2008  simonb Sync with head.
 1.17.4.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.17.2.6 11-Aug-2010  yamt sync with head.
 1.17.2.5 11-Mar-2010  yamt sync with head
 1.17.2.4 16-Sep-2009  yamt sync with head
 1.17.2.3 18-Jul-2009  yamt sync with head.
 1.17.2.2 16-May-2009  yamt sync with head
 1.17.2.1 04-May-2009  yamt sync with head.
 1.18.2.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.19.10.1 21-Apr-2010  matt sync to netbsd-5
 1.19.8.2 27-Jan-2010  sborrill Pull up the following revisions(s) (requested by bouyer in ticket #1257):
sys/dev/ic/mfi.c: revision 1.31

bio(4) is MP-safe but mfi(4) is not. So get the kernel_lock at
mfi_ioctl() entry and release it on exit.
 1.19.8.1 10-Sep-2009  snj Pull up following revision(s) (requested by bouyer in ticket #931):
sys/dev/ic/mfi.c: revision 1.28 via patch
mfi.c still uses the spl() synchronisation scheme and so needs the kernel lock.
The sysmon subsystem is marked MPSAFE and so runs without the kernel lock.
So get the kernel lock in mfi_sensor_refresh() before calling mfi_ioctl_vol().
This fixes command list corruption seen on heavy I/O load on the mfi driver(4).
 1.19.4.4 28-Mar-2010  snj Apply patch (requested by msaitoh in ticket #1326):
Add support for MFI gen2 devices. Mention newer devices, RAID 6 and
RAID60 in mfi.4.
 1.19.4.3 27-Jan-2010  sborrill Pull up the following revisions(s) (requested by bouyer in ticket #1257):
sys/dev/ic/mfi.c: revision 1.31

bio(4) is MP-safe but mfi(4) is not. So get the kernel_lock at
mfi_ioctl() entry and release it on exit.
 1.19.4.2 27-Jan-2010  sborrill Pull up the following revisions(s) (requested by bouyer in ticket #1256):
sys/dev/ic/mfi.c: revision 1.21

Don't release CCB twice. Found by code inspection.
 1.19.4.1 10-Sep-2009  snj Pull up following revision(s) (requested by bouyer in ticket #931):
sys/dev/ic/mfi.c: revision 1.28 via patch
mfi.c still uses the spl() synchronisation scheme and so needs the kernel lock.
The sysmon subsystem is marked MPSAFE and so runs without the kernel lock.
So get the kernel lock in mfi_sensor_refresh() before calling mfi_ioctl_vol().
This fixes command list corruption seen on heavy I/O load on the mfi driver(4).
 1.19.2.3 28-Apr-2009  skrll Sync with HEAD.
 1.19.2.2 03-Mar-2009  skrll Sync with HEAD.
 1.19.2.1 19-Jan-2009  skrll Sync with HEAD.
 1.20.2.2 23-Jul-2009  jym Sync with HEAD.
 1.20.2.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.31.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.34.8.1 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.36.8.5 18-Nov-2012  msaitoh Pull up following revision(s) (requested by bouyer in ticket #674):
sys/dev/ic/mfi.c: revision 1.48
MFI_STATE_BOOT_MESSAGE_PENDING also needs to be handed for non-TBOLT
controllers, from FreeBSD. tested by Hugo Silva against a GEN2 controller.
 1.36.8.4 24-Oct-2012  riz Pull up following revision(s) (requested by bouyer in ticket #629):
sys/compat/linux/common/linux_ioctl.c: revision 1.57
sys/dev/ic/mfi.c: revision 1.47
sys/conf/majors: revision 1.62
etc/etc.i386/MAKEDEV.conf: revision 1.24
sys/dev/ic/mfivar.h: revision 1.20
etc/MAKEDEV.tmpl: revision 1.159
sys/dev/ic/mfiio.h: revision 1.1
etc/etc.amd64/MAKEDEV.conf: revision 1.19
sys/dev/ic/mfireg.h: revision 1.8
Add a pass-through ioctl for mfi(4), allowing userland to send raw commands
to the controller. This is compatible with the linux and FreeBSD
implementations.
Add the needed conversion for mfi ioctls in COMPAT_LINUX
Allocate a character major number, and create /dev/mfi0 by default
on amd64 and i386.
This allows (along with a hand-created /emul/linux/proc/devices file)
to run the MegaCLI linux binary provided by LSI.
 1.36.8.3 24-Oct-2012  riz Pull up following revision(s) (requested by bouyer in ticket #628):
sys/dev/ic/mfi.c: revision 1.40
sys/dev/ic/mfi.c: revision 1.41
sys/dev/ic/mfi.c: revision 1.42
sys/dev/ic/mfi.c: revision 1.43
sys/dev/ic/mfi.c: revision 1.44
sys/dev/ic/mfi.c: revision 1.45
sys/dev/ic/mfi.c: revision 1.46
sys/dev/pci/pcidevs: revision 1.1128
sys/dev/pci/mfi_pci.c: revision 1.15
sys/dev/pci/mfi_pci.c: revision 1.16
sys/dev/ic/mfi.c: revision 1.39
sys/dev/ic/mfivar.h: revision 1.16
sys/dev/ic/mfireg.h: revision 1.6
sys/dev/ic/mfivar.h: revision 1.17
sys/dev/ic/mfireg.h: revision 1.7
sys/dev/ic/mfivar.h: revision 1.18
sys/dev/ic/mfivar.h: revision 1.19
Add some support for 64bit DMA but stick to 32bit DMA for now.
From OpenBSD mfi.c rev 1.119.
Add LSI MegaRAID SAS2208
MFI_IOP_SKINNY is an enum not a single bit value, so it can't be used as
a bit flag. As sc_flags is really used to hold an enum mfi_iop value,
change it to enum mfi_iop and rename to sc_ioptype. While there init it
in mfi_attach() instead of mfi_pci_attach().
sg64.len is 32bits, so use htole32()
Really init sc_ioptype in mfi_attach()
Add support newer LSI RAID controllers based on the SAS2208 chip,
codenamed "ThunderBolt". Add tagged queuing support for all adapters
supported by mfi(4).
Tested with a MegaRAID SAS 9265-8i adapter, and an older Dell PERC 5/i.
Avoid "unused variable" warning for non-DIAGNOSTIC kernels.
Pointed out by Havard Eidnes
After discussion on tech-kern@, fix performance issue related to
cache flush commands from WAPBL, by skipping the cache flush if the
BBU is present and considered good. Users which still want the write back
cache with a non-working BBU can set vfs.wapbl.flush_disk_cache to 0.
- add commands to monitor the BBU state. Add a boolean BBU sensor
to monitor the BBU state via sysmon_envsys(9).
- if the BBU is considered good, turn SCSI_SYNCHRONIZE_CACHE_10 and
SCSI_SYNCHRONIZE_CACHE_16 commands from upper layer into NOOPs.
While there, handle SCSI_SYNCHRONIZE_CACHE_16 in addition to
SCSI_SYNCHRONIZE_CACHE_10.
- Add a shutdown pmf(9) handler, which flushes the cache and shutdown the
firmware
- on detach, also flush cache and shutdown firmware.
- on attach, print the firmware-provided name, and the BBU state
Tested on a LSI MegaRAID SAS 9265-8i and a PERC 5/i Integrated
Make MFI_DEBUG build on i386.
Report BBU state changes with aprint_normal(), it seems that sysmon_envsys()
doens't report changes for ENVSYS_INDICATOR as it does for ENVSYS_DRIVE.
 1.36.8.2 22-Mar-2012  riz Pull up following revision(s) (requested by sborrill in ticket #138):
sys/dev/pci/mfi_pci.c: revision 1.13
sys/dev/ic/mfi.c: revision 1.38
sys/dev/ic/mfivar.h: revision 1.15
sys/dev/ic/mfireg.h: revision 1.5
Add support for skinny variants (e.g. IBM ServeRAID M1015). Based on OpenBSD
changes with some improvements. Tested on IBM x3550M3 with RAID0 and RAID1
volumes including bioctl(8) operation.
 1.36.8.1 22-Mar-2012  riz Pull up following revision(s) (requested by sborrill in ticket #136):
sys/dev/ic/mfi.c: revision 1.37
From OpenBSD. Fixes a deadlock during autoconf.
scrub more fields in the ccb when returning them to the free list after
theyve been used, in particular the mfi header flags which has a bit
that specifies if a command should be completed via the interrupt path.
if we use a ccb during boot we set that bit, but it isnt necessarily
cleared by things that use it later on. this means a ccb we expected to
complete via an interrupt never actually generates an interrupt or appears
in the reply queue. this obviously stalls the io.
 1.36.6.1 05-Apr-2012  mrg sync to latest -current.
 1.36.2.4 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.36.2.3 16-Jan-2013  yamt sync with (a bit old) head
 1.36.2.2 30-Oct-2012  yamt sync with head
 1.36.2.1 17-Apr-2012  yamt sync with head
 1.46.2.3 03-Dec-2017  jdolecek update from HEAD
 1.46.2.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.46.2.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.49.2.1 18-May-2014  rmind sync with head
 1.52.2.1 10-Aug-2014  tls Rebase.
 1.53.2.2 16-May-2015  snj Pull up following revision(s) (requested by maxv in ticket #761):
sys/arch/sgimips/dev/scn.c: revision 1.8
sys/arch/sgimips/mace/macekbc.c: revision 1.8
sys/dev/hpc/hpcfb.c: revision 1.59
sys/dev/i2c/i2c.c: revision 1.47
sys/dev/ic/mfi.c: revision 1.57
sys/dev/if_ndis/if_ndis_pci.c: revision 1.21
sys/dev/sysmon/sysmon_power.c: revisions 1.50-1.52
sys/dev/usb/umass_isdata.c: revision 1.31
fix double free, found by Brainy.
--
Free cmd on error if we allocated it.
Found by Brainy, reported by maxv@.
--
don't leak rl (but there are other leaks), found by Brainy.
--
Free ped if we can't hand it to the power daemon.
Found by Brainy, reported by maxv@.
--
don't forget to free the dictionary.
--
another missing free dict.
--
fix leak, found by Brainy.
--
don't malloc a tiny, fixed size buffer to scribble into, then not use it
and never free it either
found by Brainy
--
malloc() -> kmem_alloc() for private data, also kmem_free() them if we
don't finish attaching for whatever reason
found by Brainy
 1.53.2.1 22-Aug-2014  martin Pull up following revision(s) (requested by msaitoh in ticket #48):
sys/dev/ic/mfi.c: revision 1.54-1.55
Fix mfi(4) panic on boot on some mfi(4) chips.
 1.55.2.1 06-Apr-2015  skrll Sync with HEAD
 1.57.10.2 17-May-2022  bouyer Pull up following revision(s) via patch (requested by msaitoh in ticket #1454):
sys/dev/ic/mfi.c: revisions 1.63, 1.66-77
sys/dev/ic/mfireg.h: revisions 1.11-1.20 via patch
sys/dev/pci/mfi_pci.c: revision 1.21
sys/dev/pci/mfii.c: revisions 1.6-1.7, 1.10-1.15
share/man/man4/mfi.4: revision 1.13

Improve mfi(4) and mfii(4):
- Set 'ld_sync' to NULL as part of 'again', to prevent use-after-free.
- Add some code for the SKINNY variant to make Dell PERC H310 work.
- Print the percentage correctly when the background initialization is
running.
- Clear mailbox to not to pass garbage data.
- Use union mbox instead of unit8_t xxx[] to avoid unaligned access.
- Set stripe size for BIOCVOL to show the size correctly in bioctl.
- Add support for iBBU-09 to show BBU voltage, current and temperature
correctly.
- Fix typos in comments.
- Sprinkle static.
- Improve debug printf()s.
- KNF. Remove extra semicolon. Whitespace fixes.
 1.57.10.1 07-Dec-2018  martin Pull up following revision(s) (requested by bouyer in ticket #1129):

sys/arch/amd64/conf/XEN3_DOM0: revision 1.159
sys/arch/amd64/conf/GENERIC: revision 1.508
sys/arch/i386/conf/ALL: revision 1.458
sys/dev/ic/mfi.c: revision 1.60
sys/dev/pci/mpiireg.h: revision 1.1
distrib/sets/lists/man/mi: revision 1.1628
sys/dev/pci/mfii.c: revision 1.1,1.2 (adapted)
sys/arch/i386/conf/GENERIC: revision 1.1194
sys/dev/pci/mpii.c: revision 1.13
sys/dev/ic/mfireg.h: revision 1.9
share/man/man4/mfii.4: revision 1.1
share/man/man4/Makefile: revision 1.673 (patch)
sys/dev/pci/files.pci: revision 1.410
share/man/man4/mfii.4: revision 1.2
sys/arch/amd64/conf/ALL: revision 1.108
sys/arch/i386/conf/XEN3PAE_DOM0: revision 1.8 (patch, in XEN3_DOM0)

Add some definitions from OpenBSD, needed by the upcoming mfii driver.
No functionnal change.

-

Move registers definitions to a separate file, needed for the upcomning mpii
driver. No functionnal change.

-

Add mpii(4), a driver for LSI Megaraid Fusion controllers.
Ported from OpenBSD. This driver is MP-safe.

Note that the earlier fusion controllers (Megaraid 2208, codenamed Thunderbold)
are also supported by mfi(4). mpii will take precedence if both drivers
are enabled.

Tested on a
mfii0 at pci6 dev 0 function 0: "PERC H740P Adapter ", firmware 50.3.0-1512, 819
2MB cache
mfii0: interrupting at ioapic2 pin 2
scsibus0 at mfii0: 64 targets, 8 luns per target
scsibus0: waiting 2 seconds for devices to settle...
sd0 at scsibus0 target 0 lun 0: <DELL, PERC H740P Adp, 5.03> disk fixed
sd0: fabricating a geometry
sd0: 99 GB, 102399 cyl, 64 head, 32 sec, 512 bytes/sect x 209714688 sectors
sd0: tagged queueing
sd1 at scsibus0 target 1 lun 0: <DELL, PERC H740P Adp, 5.03> disk fixed
sd1: fabricating a geometry
sd1: 22254 GB, 22788608 cyl, 64 head, 32 sec, 512 bytes/sect x 46671069696 sectors
sd1: fabricating a geometry

It supports bioctl(8) ioctls, as well as sensors for the BBU and logical
drives.

Sponsored by LIP6.

-

Add my name in copyright list

-

add a man page for the new mpii, mostly from OpenBSD.

-

Sort SEE ALSO. Fix date. Whitespace fixes.
 1.58.4.3 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.58.4.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.58.4.1 10-Jun-2019  christos Sync with HEAD
 1.58.2.2 26-Nov-2018  pgoyette Sync with HEAD, resolve a couple of conflicts
 1.58.2.1 06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.61.2.1 17-May-2022  bouyer Pull up following revision(s) via patch (requested by msaitoh in ticket #1454):
sys/dev/ic/mfi.c: revisions 1.63, 1.66-77
sys/dev/ic/mfireg.h: revisions 1.11-1.20 via patch
sys/dev/pci/mfi_pci.c: revision 1.21
sys/dev/pci/mfii.c: revisions 1.6-1.7, 1.10-1.15
share/man/man4/mfi.4: revision 1.13

Improve mfi(4) and mfii(4):
- Set 'ld_sync' to NULL as part of 'again', to prevent use-after-free.
- Add some code for the SKINNY variant to make Dell PERC H310 work.
- Print the percentage correctly when the background initialization is
running.
- Clear mailbox to not to pass garbage data.
- Use union mbox instead of unit8_t xxx[] to avoid unaligned access.
- Set stripe size for BIOCVOL to show the size correctly in bioctl.
- Add support for iBBU-09 to show BBU voltage, current and temperature
correctly.
- Fix typos in comments.
- Sprinkle static.
- Improve debug printf()s.
- KNF. Remove extra semicolon. Whitespace fixes.
 1.63.10.3 28-Mar-2021  thorpej No need to pass interface or locators to config_found() in mfi_rescan().
 1.63.10.2 22-Mar-2021  thorpej Audit CFARG_IATTR in config_found() calls, and remove it in situations
where the interface attribute is not ambiguous.
 1.63.10.1 22-Mar-2021  thorpej Mechanical conversion of config_found_sm_loc() -> config_found().
CFARG_IATTR usage needs to be audited.
 1.64.8.1 04-Aug-2021  thorpej Adapt to CFARGS().
 1.1 19-Sep-2012  bouyer branches: 1.1.2; 1.1.4; 1.1.6;
Add a pass-through ioctl for mfi(4), allowing userland to send raw commands
to the controller. This is compatible with the linux and FreeBSD
implementations.
Add the needed conversion for mfi ioctls in COMPAT_LINUX
Allocate a character major number, and create /dev/mfi0 by default
on amd64 and i386.
This allows (along with a hand-created /emul/linux/proc/devices file)
to run the MegaCLI linux binary provided by LSI.
 1.1.6.2 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.1.6.1 19-Sep-2012  tls file mfiio.h was added on branch tls-maxphys on 2012-11-20 03:02:06 +0000
 1.1.4.2 30-Oct-2012  yamt sync with head
 1.1.4.1 19-Sep-2012  yamt file mfiio.h was added on branch yamt-pagecache on 2012-10-30 17:21:05 +0000
 1.1.2.2 24-Oct-2012  riz Pull up following revision(s) (requested by bouyer in ticket #629):
sys/compat/linux/common/linux_ioctl.c: revision 1.57
sys/dev/ic/mfi.c: revision 1.47
sys/conf/majors: revision 1.62
etc/etc.i386/MAKEDEV.conf: revision 1.24
sys/dev/ic/mfivar.h: revision 1.20
etc/MAKEDEV.tmpl: revision 1.159
sys/dev/ic/mfiio.h: revision 1.1
etc/etc.amd64/MAKEDEV.conf: revision 1.19
sys/dev/ic/mfireg.h: revision 1.8
Add a pass-through ioctl for mfi(4), allowing userland to send raw commands
to the controller. This is compatible with the linux and FreeBSD
implementations.
Add the needed conversion for mfi ioctls in COMPAT_LINUX
Allocate a character major number, and create /dev/mfi0 by default
on amd64 and i386.
This allows (along with a hand-created /emul/linux/proc/devices file)
to run the MegaCLI linux binary provided by LSI.
 1.1.2.1 19-Sep-2012  riz file mfiio.h was added on branch netbsd-6 on 2012-10-24 03:23:44 +0000
 1.25 13-Feb-2024  msaitoh mfii(4): Apply two changes from OpenBSD to fix an unknown firmware state.

My own MegaRAID 946N-8i 2G", firmware 50.5.0-2594 failed to attach.

mfii0: unknown firmware state 1879048192

1879048192 equals to 0x70000000(== MFI_STATE_FW_INIT_2).
Apply following two OpenBSD commits to resolve this problem.
 1.24 16-Jul-2022  msaitoh Add max 256 VD support.
 1.23 09-Jul-2022  msaitoh Add preliminary support for Aero.

- Aero supports 32bit descriptor.
- Even if the Aero card supports 32bit descriptor, 64bit descriptor
access is required for MFI_CMD_INIT.
- Add quirk for Aero to retry register read.
- The PCI ID table for Aero is disabled. Even if it's enabled, any logical
volumes are not found. Perhaps the reason is that our mfii driver is
currently not supports more than 64 logical volumes and MR_DCMD_LD_GET_LIST
returns incorrect value. Tested by Mark Daies' H750.
 1.22 29-Jun-2022  msaitoh Add CVPM02 BBU support.
 1.21 12-May-2022  msaitoh I think MFI_BBU_STATE_LEARN_CYC_REQ is not an error.
 1.20 12-May-2022  msaitoh No functional change.

- Reduce diff against OpenBSD
- Whitespace fix.
- Sort some defines and structures.
- Add comment.
- KNF.
 1.19 12-May-2022  msaitoh Don't use MFI_PD_LIST_SIZE. Same as OpenBSD. No functional change.
 1.18 11-May-2022  msaitoh Add support for iBBU-09 to show BBU voltage, current and temp correctly.
 1.17 11-May-2022  msaitoh KNF. s/u_quad_t/uint64_t/. No functional change.
 1.16 07-May-2022  msaitoh Fix typos.
 1.15 05-May-2022  msaitoh Add some code for the SKINNY variant to make Dell PERC H310 work.
 1.14 23-Mar-2022  andvar fix few typos in comments, mainly s/paramenters/parameters/.
 1.13 22-Mar-2022  andvar fix typos in comments.
 1.12 06-Nov-2021  msaitoh s/allign/align/
 1.11 24-Jul-2021  andvar Fix all remaining typos, mainly in comments but also in few definitions and log messages, reported by me in PR kern/54889.
Also fixed some additional typos in comments, found on review of same files or typos.
 1.10 05-Oct-2019  mrg branches: 1.10.12;
remove __packed attribute from struct ieee80211_radiotap_header
and all the structures that include it.

this should not change anything while avoiding packed vs alignment
warnings from GCC 8, and potentially pessimised code generation
due to the packed marker (there are no misaligned members, just
that the per-device parts may end unaligned.)

all consumers of these members are done from the properly aligned
packet members directly, or, as a union with a 64 byte member,
also properly aligned. codegen didn't appear to change, except
for the definition of sizeof(struct driver_[rt]x_radiotap_header)
in debug info, which is not directly used anywhere.
 1.9 24-Nov-2018  bouyer branches: 1.9.4;
Add some definitions from OpenBSD, needed by the upcoming mfii driver.
No functionnal change.
 1.8 19-Sep-2012  bouyer branches: 1.8.30; 1.8.36; 1.8.38;
Add a pass-through ioctl for mfi(4), allowing userland to send raw commands
to the controller. This is compatible with the linux and FreeBSD
implementations.
Add the needed conversion for mfi ioctls in COMPAT_LINUX
Allocate a character major number, and create /dev/mfi0 by default
on amd64 and i386.
This allows (along with a hand-created /emul/linux/proc/devices file)
to run the MegaCLI linux binary provided by LSI.
 1.7 26-Aug-2012  bouyer branches: 1.7.2;
After discussion on tech-kern@, fix performance issue related to
cache flush commands from WAPBL, by skipping the cache flush if the
BBU is present and considered good. Users which still want the write back
cache with a non-working BBU can set vfs.wapbl.flush_disk_cache to 0.
- add commands to monitor the BBU state. Add a boolean BBU sensor
to monitor the BBU state via sysmon_envsys(9).
- if the BBU is considered good, turn SCSI_SYNCHRONIZE_CACHE_10 and
SCSI_SYNCHRONIZE_CACHE_16 commands from upper layer into NOOPs.
While there, handle SCSI_SYNCHRONIZE_CACHE_16 in addition to
SCSI_SYNCHRONIZE_CACHE_10.
- Add a shutdown pmf(9) handler, which flushes the cache and shutdown the
firmware
- on detach, also flush cache and shutdown firmware.
- on attach, print the firmware-provided name, and the BBU state
Tested on a LSI MegaRAID SAS 9265-8i and a PERC 5/i Integrated
 1.6 23-Aug-2012  bouyer Add support newer LSI RAID controllers based on the SAS2208 chip,
codenamed "ThunderBolt". Add tagged queuing support for all adapters
supported by mfi(4).
Tested with a MegaRAID SAS 9265-8i adapter, and an older Dell PERC 5/i.
 1.5 21-Mar-2012  sborrill Add support for skinny variants (e.g. IBM ServeRAID M1015). Based on OpenBSD
changes with some improvements. Tested on IBM x3550M3 with RAID0 and RAID1
volumes including bioctl(8) operation.
 1.4 09-Feb-2010  msaitoh branches: 1.4.10; 1.4.14; 1.4.16;
Add newer cars supports. Tested on MegaRAID SAS 9260-8i.
- Add MFI gen2 support from OpenBSD.
- Add entry for MegaRAID SAS 9260-8i
 1.3 25-Feb-2008  xtraeme branches: 1.3.4; 1.3.14; 1.3.22; 1.3.24;
Added support for the mfi(4) controllers with powerpc IOPs such as
LSI SAS1078 or Dell PERC 6, from OpenBSD.

Tested by Akira Kato on current-users@.
 1.2 20-Dec-2006  bouyer branches: 1.2.2; 1.2.4; 1.2.6; 1.2.8; 1.2.28; 1.2.44; 1.2.48;
Add missing $NetBSD: $
 1.1 17-Dec-2006  bouyer branches: 1.1.2;
Add mfi(4), a driver for LSI Logic & Dell MegaRAID SAS RAID controller.
Ported from OpenBSD, tested on i386 and amd64.
 1.1.2.3 21-Dec-2006  yamt sync with head.
 1.1.2.2 18-Dec-2006  yamt sync with head.
 1.1.2.1 17-Dec-2006  yamt file mfireg.h was added on branch yamt-splraiseipl on 2006-12-18 11:42:13 +0000
 1.2.48.1 03-Apr-2008  mjf Sync with HEAD.
 1.2.44.1 24-Mar-2008  keiichi sync with head.
 1.2.28.1 23-Mar-2008  matt sync with HEAD
 1.2.8.2 12-Jan-2007  ad Sync with head.
 1.2.8.1 20-Dec-2006  ad file mfireg.h was added on branch newlock2 on 2007-01-12 00:57:36 +0000
 1.2.6.3 27-Feb-2008  yamt sync with head.
 1.2.6.2 30-Dec-2006  yamt sync with head.
 1.2.6.1 20-Dec-2006  yamt file mfireg.h was added on branch yamt-lazymbuf on 2006-12-30 20:48:03 +0000
 1.2.4.2 23-Dec-2006  ghen Pull up following revision(s) (requested by bouyer in ticket #1609):
sys/arch/i386/conf/INSTALL: revision 1.298
sys/arch/i386/conf/GENERIC: revision 1.802
sys/dev/pci/files.pci: revision 1.274
sys/arch/amd64/conf/GENERIC: revision 1.122
sys/dev/pci/mfi_pci.c: revision 1.1 via patch
distrib/sets/lists/man/mi: revision 1.958
sys/arch/amd64/conf/INSTALL: revision 1.61
sys/dev/ic/mfireg.h: revision 1.1
share/man/man4/Makefile: revision 1.416 via patch
sys/dev/ic/mfi.c: revision 1.1
sys/arch/i386/conf/XEN2_DOM0: revision 1.19
sys/dev/ic/mfivar.h: revision 1.1
sys/conf/files: revision 1.821
share/man/man4/mfi.4: revision 1.1
share/man/man4/mfi.4: revision 1.2
sys/dev/pci/pcidevs via patch
Add mfi(4), a driver for LSI Logic & Dell MegaRAID SAS RAID controller.
Ported from OpenBSD, tested on i386 and amd64.
Punctuation issues.
 1.2.4.1 20-Dec-2006  ghen file mfireg.h was added on branch netbsd-3 on 2006-12-23 16:43:19 +0000
 1.2.2.3 21-Dec-2006  tron Pull up following revision(s) (requested by bouyer in ticket #286):
sys/dev/pci/mfi_pci.c: revision 1.2
sys/dev/ic/mfireg.h: revision 1.2
sys/dev/ic/mfi.c: revision 1.2
sys/dev/ic/mfivar.h: revision 1.2
Add missing $NetBSD: $
 1.2.2.2 21-Dec-2006  tron Pull up following revision(s) (requested by bouyer in ticket #286):
sys/arch/i386/conf/INSTALL: revision 1.298
sys/arch/i386/conf/GENERIC: revision 1.802
sys/dev/pci/files.pci: revision 1.274
sys/arch/amd64/conf/GENERIC: revision 1.122
sys/dev/pci/mfi_pci.c: revision 1.1
distrib/sets/lists/man/mi: revision 1.958
sys/arch/amd64/conf/INSTALL: revision 1.61
sys/arch/i386/conf/ALL: revision 1.75
sys/dev/ic/mfireg.h: revision 1.1
share/man/man4/Makefile: revision 1.416
sys/dev/ic/mfi.c: revision 1.1
sys/arch/i386/conf/XEN2_DOM0: revision 1.19
sys/dev/ic/mfivar.h: revision 1.1
sys/conf/files: revision 1.821
share/man/man4/mfi.4: revision 1.1
Add mfi(4), a driver for LSI Logic & Dell MegaRAID SAS RAID controller.
Ported from OpenBSD, tested on i386 and amd64.
 1.2.2.1 20-Dec-2006  tron file mfireg.h was added on branch netbsd-4 on 2006-12-21 12:46:21 +0000
 1.3.24.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.3.22.1 21-Apr-2010  matt sync to netbsd-5
 1.3.14.1 28-Mar-2010  snj Apply patch (requested by msaitoh in ticket #1326):
Add support for MFI gen2 devices. Mention newer devices, RAID 6 and
RAID60 in mfi.4.
 1.3.4.1 11-Mar-2010  yamt sync with head
 1.4.16.3 24-Oct-2012  riz Pull up following revision(s) (requested by bouyer in ticket #629):
sys/compat/linux/common/linux_ioctl.c: revision 1.57
sys/dev/ic/mfi.c: revision 1.47
sys/conf/majors: revision 1.62
etc/etc.i386/MAKEDEV.conf: revision 1.24
sys/dev/ic/mfivar.h: revision 1.20
etc/MAKEDEV.tmpl: revision 1.159
sys/dev/ic/mfiio.h: revision 1.1
etc/etc.amd64/MAKEDEV.conf: revision 1.19
sys/dev/ic/mfireg.h: revision 1.8
Add a pass-through ioctl for mfi(4), allowing userland to send raw commands
to the controller. This is compatible with the linux and FreeBSD
implementations.
Add the needed conversion for mfi ioctls in COMPAT_LINUX
Allocate a character major number, and create /dev/mfi0 by default
on amd64 and i386.
This allows (along with a hand-created /emul/linux/proc/devices file)
to run the MegaCLI linux binary provided by LSI.
 1.4.16.2 24-Oct-2012  riz Pull up following revision(s) (requested by bouyer in ticket #628):
sys/dev/ic/mfi.c: revision 1.40
sys/dev/ic/mfi.c: revision 1.41
sys/dev/ic/mfi.c: revision 1.42
sys/dev/ic/mfi.c: revision 1.43
sys/dev/ic/mfi.c: revision 1.44
sys/dev/ic/mfi.c: revision 1.45
sys/dev/ic/mfi.c: revision 1.46
sys/dev/pci/pcidevs: revision 1.1128
sys/dev/pci/mfi_pci.c: revision 1.15
sys/dev/pci/mfi_pci.c: revision 1.16
sys/dev/ic/mfi.c: revision 1.39
sys/dev/ic/mfivar.h: revision 1.16
sys/dev/ic/mfireg.h: revision 1.6
sys/dev/ic/mfivar.h: revision 1.17
sys/dev/ic/mfireg.h: revision 1.7
sys/dev/ic/mfivar.h: revision 1.18
sys/dev/ic/mfivar.h: revision 1.19
Add some support for 64bit DMA but stick to 32bit DMA for now.
From OpenBSD mfi.c rev 1.119.
Add LSI MegaRAID SAS2208
MFI_IOP_SKINNY is an enum not a single bit value, so it can't be used as
a bit flag. As sc_flags is really used to hold an enum mfi_iop value,
change it to enum mfi_iop and rename to sc_ioptype. While there init it
in mfi_attach() instead of mfi_pci_attach().
sg64.len is 32bits, so use htole32()
Really init sc_ioptype in mfi_attach()
Add support newer LSI RAID controllers based on the SAS2208 chip,
codenamed "ThunderBolt". Add tagged queuing support for all adapters
supported by mfi(4).
Tested with a MegaRAID SAS 9265-8i adapter, and an older Dell PERC 5/i.
Avoid "unused variable" warning for non-DIAGNOSTIC kernels.
Pointed out by Havard Eidnes
After discussion on tech-kern@, fix performance issue related to
cache flush commands from WAPBL, by skipping the cache flush if the
BBU is present and considered good. Users which still want the write back
cache with a non-working BBU can set vfs.wapbl.flush_disk_cache to 0.
- add commands to monitor the BBU state. Add a boolean BBU sensor
to monitor the BBU state via sysmon_envsys(9).
- if the BBU is considered good, turn SCSI_SYNCHRONIZE_CACHE_10 and
SCSI_SYNCHRONIZE_CACHE_16 commands from upper layer into NOOPs.
While there, handle SCSI_SYNCHRONIZE_CACHE_16 in addition to
SCSI_SYNCHRONIZE_CACHE_10.
- Add a shutdown pmf(9) handler, which flushes the cache and shutdown the
firmware
- on detach, also flush cache and shutdown firmware.
- on attach, print the firmware-provided name, and the BBU state
Tested on a LSI MegaRAID SAS 9265-8i and a PERC 5/i Integrated
Make MFI_DEBUG build on i386.
Report BBU state changes with aprint_normal(), it seems that sysmon_envsys()
doens't report changes for ENVSYS_INDICATOR as it does for ENVSYS_DRIVE.
 1.4.16.1 22-Mar-2012  riz Pull up following revision(s) (requested by sborrill in ticket #138):
sys/dev/pci/mfi_pci.c: revision 1.13
sys/dev/ic/mfi.c: revision 1.38
sys/dev/ic/mfivar.h: revision 1.15
sys/dev/ic/mfireg.h: revision 1.5
Add support for skinny variants (e.g. IBM ServeRAID M1015). Based on OpenBSD
changes with some improvements. Tested on IBM x3550M3 with RAID0 and RAID1
volumes including bioctl(8) operation.
 1.4.14.1 05-Apr-2012  mrg sync to latest -current.
 1.4.10.2 30-Oct-2012  yamt sync with head
 1.4.10.1 17-Apr-2012  yamt sync with head
 1.7.2.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.8.38.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.8.38.1 10-Jun-2019  christos Sync with HEAD
 1.8.36.1 26-Nov-2018  pgoyette Sync with HEAD, resolve a couple of conflicts
 1.8.30.3 16-Sep-2022  martin Pull up the following, requested by msaitoh in ticket #1764:

sys/dev/ic/mfireg.h 1.22
sys/dev/pci/mfii.c 1.16-1.22,1.27 via patch
share/man/man4/mfii.4 1.3 via patch

- Fix wrong access in mfii_start().
- Add SAS3216,SAS3224,SAS3316 and SAS3324 support.
- Add CVPM02 BBU support.
- Use bus_space_write_8() if available.
- Don't panic on detach if no any sensor device.
- Add comment. Sort entries. KNF.
 1.8.30.2 17-May-2022  bouyer Pull up following revision(s) via patch (requested by msaitoh in ticket #1454):
sys/dev/ic/mfi.c: revisions 1.63, 1.66-77
sys/dev/ic/mfireg.h: revisions 1.11-1.20 via patch
sys/dev/pci/mfi_pci.c: revision 1.21
sys/dev/pci/mfii.c: revisions 1.6-1.7, 1.10-1.15
share/man/man4/mfi.4: revision 1.13

Improve mfi(4) and mfii(4):
- Set 'ld_sync' to NULL as part of 'again', to prevent use-after-free.
- Add some code for the SKINNY variant to make Dell PERC H310 work.
- Print the percentage correctly when the background initialization is
running.
- Clear mailbox to not to pass garbage data.
- Use union mbox instead of unit8_t xxx[] to avoid unaligned access.
- Set stripe size for BIOCVOL to show the size correctly in bioctl.
- Add support for iBBU-09 to show BBU voltage, current and temperature
correctly.
- Fix typos in comments.
- Sprinkle static.
- Improve debug printf()s.
- KNF. Remove extra semicolon. Whitespace fixes.
 1.8.30.1 07-Dec-2018  martin Pull up following revision(s) (requested by bouyer in ticket #1129):

sys/arch/amd64/conf/XEN3_DOM0: revision 1.159
sys/arch/amd64/conf/GENERIC: revision 1.508
sys/arch/i386/conf/ALL: revision 1.458
sys/dev/ic/mfi.c: revision 1.60
sys/dev/pci/mpiireg.h: revision 1.1
distrib/sets/lists/man/mi: revision 1.1628
sys/dev/pci/mfii.c: revision 1.1,1.2 (adapted)
sys/arch/i386/conf/GENERIC: revision 1.1194
sys/dev/pci/mpii.c: revision 1.13
sys/dev/ic/mfireg.h: revision 1.9
share/man/man4/mfii.4: revision 1.1
share/man/man4/Makefile: revision 1.673 (patch)
sys/dev/pci/files.pci: revision 1.410
share/man/man4/mfii.4: revision 1.2
sys/arch/amd64/conf/ALL: revision 1.108
sys/arch/i386/conf/XEN3PAE_DOM0: revision 1.8 (patch, in XEN3_DOM0)

Add some definitions from OpenBSD, needed by the upcoming mfii driver.
No functionnal change.

-

Move registers definitions to a separate file, needed for the upcomning mpii
driver. No functionnal change.

-

Add mpii(4), a driver for LSI Megaraid Fusion controllers.
Ported from OpenBSD. This driver is MP-safe.

Note that the earlier fusion controllers (Megaraid 2208, codenamed Thunderbold)
are also supported by mfi(4). mpii will take precedence if both drivers
are enabled.

Tested on a
mfii0 at pci6 dev 0 function 0: "PERC H740P Adapter ", firmware 50.3.0-1512, 819
2MB cache
mfii0: interrupting at ioapic2 pin 2
scsibus0 at mfii0: 64 targets, 8 luns per target
scsibus0: waiting 2 seconds for devices to settle...
sd0 at scsibus0 target 0 lun 0: <DELL, PERC H740P Adp, 5.03> disk fixed
sd0: fabricating a geometry
sd0: 99 GB, 102399 cyl, 64 head, 32 sec, 512 bytes/sect x 209714688 sectors
sd0: tagged queueing
sd1 at scsibus0 target 1 lun 0: <DELL, PERC H740P Adp, 5.03> disk fixed
sd1: fabricating a geometry
sd1: 22254 GB, 22788608 cyl, 64 head, 32 sec, 512 bytes/sect x 46671069696 sectors
sd1: fabricating a geometry

It supports bioctl(8) ioctls, as well as sensors for the BBU and logical
drives.

Sponsored by LIP6.

-

Add my name in copyright list

-

add a man page for the new mpii, mostly from OpenBSD.

-

Sort SEE ALSO. Fix date. Whitespace fixes.
 1.9.4.2 16-Sep-2022  martin Pull up the following, requested by msaitoh in ticket #1524:

sys/dev/ic/mfireg.h 1.22
sys/dev/pci/mfii.c 1.16-1.22,1.27 via patch
share/man/man4/mfii.4 1.3 via patch

- Fix wrong access in mfii_start().
- Add SAS3216,SAS3224,SAS3316 and SAS3324 support.
- Add CVPM02 BBU support.
- Use bus_space_write_8() if available.
- Don't panic on detach if no any sensor device.
- Add comment. Sort entries. KNF.
 1.9.4.1 17-May-2022  bouyer Pull up following revision(s) via patch (requested by msaitoh in ticket #1454):
sys/dev/ic/mfi.c: revisions 1.63, 1.66-77
sys/dev/ic/mfireg.h: revisions 1.11-1.20 via patch
sys/dev/pci/mfi_pci.c: revision 1.21
sys/dev/pci/mfii.c: revisions 1.6-1.7, 1.10-1.15
share/man/man4/mfi.4: revision 1.13

Improve mfi(4) and mfii(4):
- Set 'ld_sync' to NULL as part of 'again', to prevent use-after-free.
- Add some code for the SKINNY variant to make Dell PERC H310 work.
- Print the percentage correctly when the background initialization is
running.
- Clear mailbox to not to pass garbage data.
- Use union mbox instead of unit8_t xxx[] to avoid unaligned access.
- Set stripe size for BIOCVOL to show the size correctly in bioctl.
- Add support for iBBU-09 to show BBU voltage, current and temperature
correctly.
- Fix typos in comments.
- Sprinkle static.
- Improve debug printf()s.
- KNF. Remove extra semicolon. Whitespace fixes.
 1.10.12.1 01-Aug-2021  thorpej Sync with HEAD.
 1.20 19-Sep-2012  bouyer Add a pass-through ioctl for mfi(4), allowing userland to send raw commands
to the controller. This is compatible with the linux and FreeBSD
implementations.
Add the needed conversion for mfi ioctls in COMPAT_LINUX
Allocate a character major number, and create /dev/mfi0 by default
on amd64 and i386.
This allows (along with a hand-created /emul/linux/proc/devices file)
to run the MegaCLI linux binary provided by LSI.
 1.19 26-Aug-2012  bouyer branches: 1.19.2;
After discussion on tech-kern@, fix performance issue related to
cache flush commands from WAPBL, by skipping the cache flush if the
BBU is present and considered good. Users which still want the write back
cache with a non-working BBU can set vfs.wapbl.flush_disk_cache to 0.
- add commands to monitor the BBU state. Add a boolean BBU sensor
to monitor the BBU state via sysmon_envsys(9).
- if the BBU is considered good, turn SCSI_SYNCHRONIZE_CACHE_10 and
SCSI_SYNCHRONIZE_CACHE_16 commands from upper layer into NOOPs.
While there, handle SCSI_SYNCHRONIZE_CACHE_16 in addition to
SCSI_SYNCHRONIZE_CACHE_10.
- Add a shutdown pmf(9) handler, which flushes the cache and shutdown the
firmware
- on detach, also flush cache and shutdown firmware.
- on attach, print the firmware-provided name, and the BBU state
Tested on a LSI MegaRAID SAS 9265-8i and a PERC 5/i Integrated
 1.18 23-Aug-2012  bouyer Add support newer LSI RAID controllers based on the SAS2208 chip,
codenamed "ThunderBolt". Add tagged queuing support for all adapters
supported by mfi(4).
Tested with a MegaRAID SAS 9265-8i adapter, and an older Dell PERC 5/i.
 1.17 05-Aug-2012  bouyer MFI_IOP_SKINNY is an enum not a single bit value, so it can't be used as
a bit flag. As sc_flags is really used to hold an enum mfi_iop value,
change it to enum mfi_iop and rename to sc_ioptype. While there init it
in mfi_attach() instead of mfi_pci_attach().
 1.16 05-Aug-2012  bouyer Add some support for 64bit DMA but stick to 32bit DMA for now.
From OpenBSD mfi.c rev 1.119.
 1.15 21-Mar-2012  sborrill Add support for skinny variants (e.g. IBM ServeRAID M1015). Based on OpenBSD
changes with some improvements. Tested on IBM x3550M3 with RAID0 and RAID1
volumes including bioctl(8) operation.
 1.14 09-Feb-2010  msaitoh branches: 1.14.10; 1.14.14; 1.14.16;
Add newer cars supports. Tested on MegaRAID SAS 9260-8i.
- Add MFI gen2 support from OpenBSD.
- Add entry for MegaRAID SAS 9260-8i
 1.13 16-Jul-2009  dyoung branches: 1.13.2;
Let us detach & re-attach children of mfi0. Detach mfi0 at shutdown.

Detachment may fail after freeing some but not all resources, so
take care not to re-release any resource during detachment.

Tested on a Dell PowerEdge 1950.
 1.12 16-Jul-2009  dyoung device_t/softc split. Tested and shown to work on a Dell PowerEdge
1950.
 1.11 16-Jul-2009  dyoung Add a rudimentary detachment hook for mfi(4).
 1.10 24-Jun-2008  gmcgarry branches: 1.10.6; 1.10.10; 1.10.14;
Change gcc variadic macros to c99 variadic macros.
 1.9 08-Apr-2008  cegger branches: 1.9.4; 1.9.6; 1.9.8;
use aprint_*_dev and device_xname
 1.8 25-Feb-2008  xtraeme Apply some KNF to this driver and do some random changes as well:

- Change malloc + memset(blah, 0, ...) to malloc with M_ZERO.
- The adapt_ioctl assigned was returning ENOTTY, so there's no point
on having it.
- Static'ify.

I believe there are some paths on this driver where the splbio()s
are not needed, but can't test to verify...
 1.7 25-Feb-2008  xtraeme Added support for the mfi(4) controllers with powerpc IOPs such as
LSI SAS1078 or Dell PERC 6, from OpenBSD.

Tested by Akira Kato on current-users@.
 1.6 16-Nov-2007  xtraeme branches: 1.6.10; 1.6.14;
Extend the envsys2 API (one more time, sorry) as defined in:

http://mail-index.netbsd.org/tech-kern/2007/11/09/0001.html

sysmon_envsys_create() and sysmon_envsys_destroy() were added to
create/destroy sysmon_envsys objects (and its TAILQ/LIST for sensors/events).

sysmon_envsys_sensor_attach() and sysmon_envsys_sensor_detach() were
added to attach/detach sensors to a specified sysmon_envsys device.

The events framework is now per device and configurable via the
ENVSYS_SETDICTIONARY ioctl or /etc/envsys.conf and envstat(8).

Update all users and documentation to reflect these changes.
 1.5 01-Jul-2007  xtraeme branches: 1.5.6; 1.5.8; 1.5.12; 1.5.14;
Imported envsys 2, a brief description of the new features:
(Part 2: drivers)

* Support for detachable sensors.
* Cleaned up the API for simplicity and efficiency.
* Ability to send capacity/critical/warning events to powerd(8).
* Adapted all the code to the new locking order.
* Compatibility with the old envsys API: the ENVSYS_GTREINFO
and ENVSYS_GTREDATA ioctl(2)s are supported.
* Added support for a 'dictionary based communication channel' between
sysmon_power(9) and powerd(8), that means there is no 32 bytes event
size restriction anymore.
* Binary compatibility with old envstat(8) and powerd(8) via COMPAT_40.
* All drivers with the n^2 gtredata bug were fixed, PR kern/36226.

Tested by:

blymn: smsc(4).
bouyer: ipmi(4), mfi(4).
kefren: ug(4).
njoly: viaenv(4), adt7463.c.
riz: owtemp(4).
xtraeme: acpiacad(4), acpibat(4), acpitz(4), aiboost(4), it(4), lm(4).
 1.4 01-May-2007  bouyer Add bio(4) and associated bioctl(8) from OpenBSD, a driver control block
device controllers, and more specifically raid controllers.
Add a new sensor type, ENVSYS_DRIVE, to report drive status. From OpenBSD.
Add bio and sysmon support to mfi(4). This allow userland to query
status for drives and logical volumes attached to a mfi(4) controller. While
there fix some debug printfs in mfi so they compile.
Add bio(4) to amd64 and i386 GENERIC.
 1.3 04-Mar-2007  christos branches: 1.3.2; 1.3.4;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.2 20-Dec-2006  bouyer branches: 1.2.2; 1.2.4; 1.2.6; 1.2.8; 1.2.10;
Add missing $NetBSD: $
 1.1 17-Dec-2006  bouyer branches: 1.1.2;
Add mfi(4), a driver for LSI Logic & Dell MegaRAID SAS RAID controller.
Ported from OpenBSD, tested on i386 and amd64.
 1.1.2.3 21-Dec-2006  yamt sync with head.
 1.1.2.2 18-Dec-2006  yamt sync with head.
 1.1.2.1 17-Dec-2006  yamt file mfivar.h was added on branch yamt-splraiseipl on 2006-12-18 11:42:13 +0000
 1.2.10.2 07-May-2007  yamt sync with head.
 1.2.10.1 12-Mar-2007  rmind Sync with HEAD.
 1.2.8.2 12-Jan-2007  ad Sync with head.
 1.2.8.1 20-Dec-2006  ad file mfivar.h was added on branch newlock2 on 2007-01-12 00:57:36 +0000
 1.2.6.5 27-Feb-2008  yamt sync with head.
 1.2.6.4 07-Dec-2007  yamt sync with head
 1.2.6.3 03-Sep-2007  yamt sync with head.
 1.2.6.2 30-Dec-2006  yamt sync with head.
 1.2.6.1 20-Dec-2006  yamt file mfivar.h was added on branch yamt-lazymbuf on 2006-12-30 20:48:03 +0000
 1.2.4.3 15-Oct-2007  riz Pull up following revisions via patch (requested by bouyer in ticket #1838):
distrib/sets/lists/man/mi: revision 1.997
sbin/bioctl/strtonum.c: revision 1.1
sys/dev/Makefile: revision 1.25
sys/arch/amd64/conf/GENERIC: revision 1.139
sbin/bioctl/strtonum.h: revision 1.1
sys/dev/bio.c: revision 1.1
sbin/bioctl/bioctl.c: revision 1.1
share/man/man4/bio.4: revision 1.1
sbin/bioctl/bioctl.8: revision 1.1
sys/sys/envsys.h: revision 1.11
sbin/bioctl/bioctl.8: revision 1.3
sbin/bioctl/bioctl.8: revision 1.4
sys/arch/i386/conf/XEN2_DOM0: revision 1.25
distrib/sets/lists/base/mi: revision 1.704
sys/conf/majors: revision 1.34
share/man/man4/Makefile: revision 1.426
etc/MAKEDEV.tmpl: revision 1.86
sys/arch/i386/conf/GENERIC: revision 1.825
distrib/sets/lists/comp/mi: revision 1.1022
sys/conf/files: revision 1.839
usr.sbin/envstat/envstat.c: revision 1.24
sbin/Makefile: revision 1.105
sys/dev/ic/mfi.c: revision 1.4
sys/dev/biovar.h: revision 1.1
sys/dev/ic/mfivar.h: revision 1.4
sbin/bioctl/Makefile: revision 1.1
Fix typo.
Add bio(4) and associated bioctl(8) from OpenBSD, a driver control block
device controllers, and more specifically raid controllers.
Add a new sensor type, ENVSYS_DRIVE, to report drive status. From OpenBSD.
Add bio and sysmon support to mfi(4). This allow userland to query
status for drives and logical volumes attached to a mfi(4) controller. While
there fix some debug printfs in mfi so they compile.
Add bio(4) to amd64 and i386 GENERIC.
Add bio(4) and associated bioctl(8) from OpenBSD, a driver control block
device controllers, and more specifically raid controllers.
Add a new sensor type, ENVSYS_DRIVE, to report drive status. From OpenBSD.
Add bio and sysmon support to mfi(4). This allow userland to query
status for drives and logical volumes attached to a mfi(4) controller. While
there fix some debug printfs in mfi so they compile.
Add bio(4) to amd64 and i386 GENERIC.
Fix Dd argument (use full month names).
Use more markup.
Comment out references to safte(4) and softraid(4), which don't exist in
NetBSD.
Remove trailing whitespace.
Use macros instead of characters for HTML output (replace ">", "<"
with \*[Gt], \*[Lt]).
Sort sections.
Create /dev/bio
 1.2.4.2 23-Dec-2006  ghen Pull up following revision(s) (requested by bouyer in ticket #1609):
sys/arch/i386/conf/INSTALL: revision 1.298
sys/arch/i386/conf/GENERIC: revision 1.802
sys/dev/pci/files.pci: revision 1.274
sys/arch/amd64/conf/GENERIC: revision 1.122
sys/dev/pci/mfi_pci.c: revision 1.1 via patch
distrib/sets/lists/man/mi: revision 1.958
sys/arch/amd64/conf/INSTALL: revision 1.61
sys/dev/ic/mfireg.h: revision 1.1
share/man/man4/Makefile: revision 1.416 via patch
sys/dev/ic/mfi.c: revision 1.1
sys/arch/i386/conf/XEN2_DOM0: revision 1.19
sys/dev/ic/mfivar.h: revision 1.1
sys/conf/files: revision 1.821
share/man/man4/mfi.4: revision 1.1
share/man/man4/mfi.4: revision 1.2
sys/dev/pci/pcidevs via patch
Add mfi(4), a driver for LSI Logic & Dell MegaRAID SAS RAID controller.
Ported from OpenBSD, tested on i386 and amd64.
Punctuation issues.
 1.2.4.1 20-Dec-2006  ghen file mfivar.h was added on branch netbsd-3 on 2006-12-23 16:43:19 +0000
 1.2.2.4 08-May-2007  pavel Pull up following revision(s) (requested by bouyer in ticket #603):
distrib/sets/lists/base/mi: revision 1.704
distrib/sets/lists/comp/mi: revision 1.1022
distrib/sets/lists/man/mi: revision 1.997
doc/CHANGES: revision 1.839
sbin/Makefile: patch
sbin/bioctl/Makefile: revision 1.1
sbin/bioctl/bioctl.8: revision 1.1
sbin/bioctl/bioctl.c: revision 1.1
sbin/bioctl/strtonum.c: revision 1.1
sbin/bioctl/strtonum.h: revision 1.1
share/man/man4/Makefile: revision 1.426
share/man/man4/bio.4: revision 1.1
sys/arch/amd64/conf/GENERIC: revision 1.139
sys/arch/i386/conf/GENERIC: revision 1.825
sys/arch/i386/conf/XEN2_DOM0: revision 1.25
sys/conf/files: revision 1.839
sys/conf/majors: patch
sys/dev/Makefile: revision 1.25
sys/dev/bio.c: patch
sys/dev/biovar.h: patch
sys/dev/ic/mfi.c: revision 1.4-1.5
sys/dev/ic/mfivar.h: revision 1.4
sys/sys/envsys.h: revision 1.11
usr.sbin/envstat/envstat.c: revision 1.24
Add bio(4) and associated bioctl(8) from OpenBSD, a driver control block
device controllers, and more specifically raid controllers.
Add a new sensor type, ENVSYS_DRIVE, to report drive status. From OpenBSD.
Add bio and sysmon support to mfi(4). This allow userland to query
status for drives and logical volumes attached to a mfi(4) controller. While
there fix some debug printfs in mfi so they compile.
Add bio(4) to amd64 and i386 GENERIC.

note bio(4), envsys(4) DRIVE, and mfi(4) support for both.

tred->sensor is a u_int.
 1.2.2.3 21-Dec-2006  tron Pull up following revision(s) (requested by bouyer in ticket #286):
sys/dev/pci/mfi_pci.c: revision 1.2
sys/dev/ic/mfireg.h: revision 1.2
sys/dev/ic/mfi.c: revision 1.2
sys/dev/ic/mfivar.h: revision 1.2
Add missing $NetBSD: $
 1.2.2.2 21-Dec-2006  tron Pull up following revision(s) (requested by bouyer in ticket #286):
sys/arch/i386/conf/INSTALL: revision 1.298
sys/arch/i386/conf/GENERIC: revision 1.802
sys/dev/pci/files.pci: revision 1.274
sys/arch/amd64/conf/GENERIC: revision 1.122
sys/dev/pci/mfi_pci.c: revision 1.1
distrib/sets/lists/man/mi: revision 1.958
sys/arch/amd64/conf/INSTALL: revision 1.61
sys/arch/i386/conf/ALL: revision 1.75
sys/dev/ic/mfireg.h: revision 1.1
share/man/man4/Makefile: revision 1.416
sys/dev/ic/mfi.c: revision 1.1
sys/arch/i386/conf/XEN2_DOM0: revision 1.19
sys/dev/ic/mfivar.h: revision 1.1
sys/conf/files: revision 1.821
share/man/man4/mfi.4: revision 1.1
Add mfi(4), a driver for LSI Logic & Dell MegaRAID SAS RAID controller.
Ported from OpenBSD, tested on i386 and amd64.
 1.2.2.1 20-Dec-2006  tron file mfivar.h was added on branch netbsd-4 on 2006-12-21 12:46:21 +0000
 1.3.4.1 11-Jul-2007  mjf Sync with head.
 1.3.2.2 15-Jul-2007  ad Sync with head.
 1.3.2.1 27-May-2007  ad Sync with head.
 1.5.14.1 19-Nov-2007  mjf Sync with HEAD.
 1.5.12.1 18-Nov-2007  bouyer Sync with HEAD
 1.5.8.2 23-Mar-2008  matt sync with HEAD
 1.5.8.1 09-Jan-2008  matt sync with HEAD
 1.5.6.1 21-Nov-2007  joerg Sync with HEAD.
 1.6.14.3 29-Jun-2008  mjf Sync with HEAD.
 1.6.14.2 02-Jun-2008  mjf Sync with HEAD.
 1.6.14.1 03-Apr-2008  mjf Sync with HEAD.
 1.6.10.1 24-Mar-2008  keiichi sync with head.
 1.9.8.1 27-Jun-2008  simonb Sync with head.
 1.9.6.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.9.4.3 11-Mar-2010  yamt sync with head
 1.9.4.2 18-Jul-2009  yamt sync with head.
 1.9.4.1 04-May-2009  yamt sync with head.
 1.10.14.1 21-Apr-2010  matt sync to netbsd-5
 1.10.10.1 23-Jul-2009  jym Sync with HEAD.
 1.10.6.1 28-Mar-2010  snj Apply patch (requested by msaitoh in ticket #1326):
Add support for MFI gen2 devices. Mention newer devices, RAID 6 and
RAID60 in mfi.4.
 1.13.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.14.16.3 24-Oct-2012  riz Pull up following revision(s) (requested by bouyer in ticket #629):
sys/compat/linux/common/linux_ioctl.c: revision 1.57
sys/dev/ic/mfi.c: revision 1.47
sys/conf/majors: revision 1.62
etc/etc.i386/MAKEDEV.conf: revision 1.24
sys/dev/ic/mfivar.h: revision 1.20
etc/MAKEDEV.tmpl: revision 1.159
sys/dev/ic/mfiio.h: revision 1.1
etc/etc.amd64/MAKEDEV.conf: revision 1.19
sys/dev/ic/mfireg.h: revision 1.8
Add a pass-through ioctl for mfi(4), allowing userland to send raw commands
to the controller. This is compatible with the linux and FreeBSD
implementations.
Add the needed conversion for mfi ioctls in COMPAT_LINUX
Allocate a character major number, and create /dev/mfi0 by default
on amd64 and i386.
This allows (along with a hand-created /emul/linux/proc/devices file)
to run the MegaCLI linux binary provided by LSI.
 1.14.16.2 24-Oct-2012  riz Pull up following revision(s) (requested by bouyer in ticket #628):
sys/dev/ic/mfi.c: revision 1.40
sys/dev/ic/mfi.c: revision 1.41
sys/dev/ic/mfi.c: revision 1.42
sys/dev/ic/mfi.c: revision 1.43
sys/dev/ic/mfi.c: revision 1.44
sys/dev/ic/mfi.c: revision 1.45
sys/dev/ic/mfi.c: revision 1.46
sys/dev/pci/pcidevs: revision 1.1128
sys/dev/pci/mfi_pci.c: revision 1.15
sys/dev/pci/mfi_pci.c: revision 1.16
sys/dev/ic/mfi.c: revision 1.39
sys/dev/ic/mfivar.h: revision 1.16
sys/dev/ic/mfireg.h: revision 1.6
sys/dev/ic/mfivar.h: revision 1.17
sys/dev/ic/mfireg.h: revision 1.7
sys/dev/ic/mfivar.h: revision 1.18
sys/dev/ic/mfivar.h: revision 1.19
Add some support for 64bit DMA but stick to 32bit DMA for now.
From OpenBSD mfi.c rev 1.119.
Add LSI MegaRAID SAS2208
MFI_IOP_SKINNY is an enum not a single bit value, so it can't be used as
a bit flag. As sc_flags is really used to hold an enum mfi_iop value,
change it to enum mfi_iop and rename to sc_ioptype. While there init it
in mfi_attach() instead of mfi_pci_attach().
sg64.len is 32bits, so use htole32()
Really init sc_ioptype in mfi_attach()
Add support newer LSI RAID controllers based on the SAS2208 chip,
codenamed "ThunderBolt". Add tagged queuing support for all adapters
supported by mfi(4).
Tested with a MegaRAID SAS 9265-8i adapter, and an older Dell PERC 5/i.
Avoid "unused variable" warning for non-DIAGNOSTIC kernels.
Pointed out by Havard Eidnes
After discussion on tech-kern@, fix performance issue related to
cache flush commands from WAPBL, by skipping the cache flush if the
BBU is present and considered good. Users which still want the write back
cache with a non-working BBU can set vfs.wapbl.flush_disk_cache to 0.
- add commands to monitor the BBU state. Add a boolean BBU sensor
to monitor the BBU state via sysmon_envsys(9).
- if the BBU is considered good, turn SCSI_SYNCHRONIZE_CACHE_10 and
SCSI_SYNCHRONIZE_CACHE_16 commands from upper layer into NOOPs.
While there, handle SCSI_SYNCHRONIZE_CACHE_16 in addition to
SCSI_SYNCHRONIZE_CACHE_10.
- Add a shutdown pmf(9) handler, which flushes the cache and shutdown the
firmware
- on detach, also flush cache and shutdown firmware.
- on attach, print the firmware-provided name, and the BBU state
Tested on a LSI MegaRAID SAS 9265-8i and a PERC 5/i Integrated
Make MFI_DEBUG build on i386.
Report BBU state changes with aprint_normal(), it seems that sysmon_envsys()
doens't report changes for ENVSYS_INDICATOR as it does for ENVSYS_DRIVE.
 1.14.16.1 22-Mar-2012  riz Pull up following revision(s) (requested by sborrill in ticket #138):
sys/dev/pci/mfi_pci.c: revision 1.13
sys/dev/ic/mfi.c: revision 1.38
sys/dev/ic/mfivar.h: revision 1.15
sys/dev/ic/mfireg.h: revision 1.5
Add support for skinny variants (e.g. IBM ServeRAID M1015). Based on OpenBSD
changes with some improvements. Tested on IBM x3550M3 with RAID0 and RAID1
volumes including bioctl(8) operation.
 1.14.14.1 05-Apr-2012  mrg sync to latest -current.
 1.14.10.2 30-Oct-2012  yamt sync with head
 1.14.10.1 17-Apr-2012  yamt sync with head
 1.19.2.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.104 06-Sep-2018  maxv Retire the 'midway' driver. Discussed on tech-net@ recently and also three
years ago, part of removing the network ATM code.
 1.103 03-Sep-2018  riastradh Rename min/max -> uimin/uimax for better honesty.

These functions are defined on unsigned int. The generic name
min/max should not silently truncate to 32 bits on 64-bit systems.
This is purely a name change -- no functional change intended.

HOWEVER! Some subsystems have

#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))

even though our standard name for that is MIN/MAX. Although these
may invite multiple evaluation bugs, these do _not_ cause integer
truncation.

To avoid `fixing' these cases, I first changed the name in libkern,
and then compile-tested every file where min/max occurred in order to
confirm that it failed -- and thus confirm that nothing shadowed
min/max -- before changing it.

I have left a handful of bootloaders that are too annoying to
compile-test, and some dead code:

cobalt ews4800mips hp300 hppa ia64 luna68k vax
acorn32/if_ie.c (not included in any kernels)
macppc/if_gm.c (superseded by gem(4))

It should be easy to fix the fallout once identified -- this way of
doing things fails safe, and the goal here, after all, is to _avoid_
silent integer truncations, not introduce them.

Maybe one day we can reintroduce min/max as type-generic things that
never silently truncate. But we should avoid doing that for a while,
so that existing code has a chance to be detected by the compiler for
conversion to uimin/uimax without changing the semantics until we can
properly audit it all. (Who knows, maybe in some cases integer
truncation is actually intended!)
 1.102 26-Jun-2018  msaitoh branches: 1.102.2;
Implement the BPF direction filter (BIOC[GS]DIRECTION). It provides backward
compatibility with BIOC[GS]SEESENT ioctl. The userland interface is the same
as FreeBSD.

This change also fixes a bug that the direction is misunderstand on some
environment by passing the direction to bpf_mtap*() instead of checking
m->m_pkthdr.rcvif.
 1.101 28-Oct-2017  riastradh branches: 1.101.2;
Kill some more extern struct cfdriver declarations.

Down with externs in .c!
 1.100 31-Mar-2017  msaitoh Remove extra 0x. This bug was added when replacing bitmask_snprintf(9) with
snprintb(3) (in between NetBSD 5 and 6). Old bitmask_snprint(9) didn't add
0x" automatically for hexadecimal value, so old code used it with "0x%s".
 1.99 24-Jan-2017  ozaki-r Defer bpf_mtap in Rx interrupt context to softint

bpf_mtap of some drivers is still called in hardware interrupt context.
We want to run them in softint as well as bpf_mtap of most drivers
(see if_percpuq_softint and if_input).

To this end, bpf_mtap_softint mechanism is implemented; it defers
bpf_mtap processing to a dedicated softint for a target driver.
By using the machanism, we can move bpf_mtap processing to softint
without changing target drivers much while it adds some overhead
on CPU and memory. Once target drivers are changed to softint-based,
we should return to normal bpf_mtap.

Proposed on tech-kern and tech-net
 1.98 15-Dec-2016  ozaki-r branches: 1.98.2;
Annotate bpf_mtap still running in Rx hardware interrupt with "XXX not in softint"
 1.97 10-Jun-2016  ozaki-r branches: 1.97.2;
Introduce m_set_rcvif and m_reset_rcvif

The API is used to set (or reset) a received interface of a mbuf.
They are counterpart of m_get_rcvif, which will come in another
commit, hide internal of rcvif operation, and reduce the diff of
the upcoming change.

No functional change.
 1.96 22-Jan-2016  ozaki-r Revert previous

atm_input is not compatible with ifp->if_input and other *_input routines...
 1.95 22-Jan-2016  ozaki-r Don't call atm_input directly

This should be the last one that was survived ifp->if_input replacements.

No functional change.
 1.94 13-Mar-2012  elad branches: 1.94.2; 1.94.16;
Replace the remaining KAUTH_GENERIC_ISSUSER authorization calls with
something meaningful. All relevant documentation has been updated or
written.

Most of these changes were brought up in the following messages:

http://mail-index.netbsd.org/tech-kern/2012/01/18/msg012490.html
http://mail-index.netbsd.org/tech-kern/2012/01/19/msg012502.html
http://mail-index.netbsd.org/tech-kern/2012/02/17/msg012728.html

Thanks to christos, manu, njoly, and jmmv for input.

Huge thanks to pgoyette for spinning these changes through some build
cycles and ATF.
 1.93 18-Jul-2011  mrg branches: 1.93.2; 1.93.6;
convert the remaining dev/sbus drivers to CFATTACH_DECL_NEW, cfdata_t
and device_t, including the pci frontend and backend for en(4).
 1.92 01-Feb-2011  chuck udpate license clauses on my code to match the new-style BSD licenses.
remove no-longer-valid wustl email address for me.
based on diff that rmind@ sent me.

no functional change with this commit.
 1.91 05-Apr-2010  joerg branches: 1.91.2; 1.91.4;
Push the bpf_ops usage back into bpf.h. Push the common ifp->if_bpf
check into the inline functions as well the fourth argument for
bpf_attach.
 1.90 19-Jan-2010  pooka branches: 1.90.2; 1.90.4;
Redefine bpf linkage through an always present op vector, i.e.
#if NBPFILTER is no longer required in the client. This change
doesn't yet add support for loading bpf as a module, since drivers
can register before bpf is attached. However, callers of bpf can
now be modularized.

Dynamically loadable bpf could probably be done fairly easily with
coordination from the stub driver and the real driver by registering
attachments in the stub before the real driver is loaded and doing
a handoff. ... and I'm not going to ponder the depths of unload
here.

Tested with i386/MONOLITHIC, modified MONOLITHIC without bpf and rump.
 1.89 18-Jan-2010  pooka Nuke "ummmm" quality macro. It's outside __NetBSD__, so not
functional change, but some C parsers that don't know which cpp
macros are defined fall and hurt themselves quite badly with it.
 1.88 15-Apr-2009  elad Remove a few KAUTH_GENERIC_ISSUSER in favor of more descriptive
alternatives.

Discussed on tech-kern:

http://mail-index.netbsd.org/tech-kern/2009/04/11/msg004798.html

Input from ad@, christos@, dyoung@, tsutsui@.

Okay ad@.
 1.87 15-Mar-2009  cegger ansify function definitions
 1.86 14-Mar-2009  dsl Change about 4500 of the K&R function definitions to ANSI ones.
There are still about 1600 left, but they have ',' or /* ... */
in the actual variable definitions - which my awk script doesn't handle.
There are also many that need () -> (void).
(The script does handle misordered arguments.)
 1.85 17-Dec-2008  cegger branches: 1.85.2;
kill MALLOC and FREE macros.
 1.84 16-Dec-2008  christos replace bitmask_snprintf(9) with snprintb(3)
 1.83 07-Nov-2008  dyoung *** Summary ***

When a link-layer address changes (e.g., ifconfig ex0 link
02:de:ad:be:ef:02 active), send a gratuitous ARP and/or a Neighbor
Advertisement to update the network-/link-layer address bindings
on our LAN peers.

Refuse a change of ethernet address to the address 00:00:00:00:00:00
or to any multicast/broadcast address. (Thanks matt@.)

Reorder ifnet ioctl operations so that driver ioctls may inherit
the functions of their "class"---ether_ioctl(), fddi_ioctl(), et
cetera---and the class ioctls may inherit from the generic ioctl,
ifioctl_common(), but both driver- and class-ioctls may override
the generic behavior. Make network drivers share more code.

Distinguish a "factory" link-layer address from others for the
purposes of both protecting that address from deletion and computing
EUI64.

Return consistent, appropriate error codes from network drivers.

Improve readability. KNF.

*** Details ***

In if_attach(), always initialize the interface ioctl routine,
ifnet->if_ioctl, if the driver has not already initialized it.
Delete if_ioctl == NULL tests everywhere else, because it cannot
happen.

In the ioctl routines of network interfaces, inherit common ioctl
behaviors by calling either ifioctl_common() or whichever ioctl
routine is appropriate for the class of interface---e.g., ether_ioctl()
for ethernets.

Stop (ab)using SIOCSIFADDR and start to use SIOCINITIFADDR. In
the user->kernel interface, SIOCSIFADDR's argument was an ifreq,
but on the protocol->ifnet interface, SIOCSIFADDR's argument was
an ifaddr. That was confusing, and it would work against me as I
make it possible for a network interface to overload most ioctls.
On the protocol->ifnet interface, replace SIOCSIFADDR with
SIOCINITIFADDR. In ifioctl(), return EPERM if userland tries to
invoke SIOCINITIFADDR.

In ifioctl(), give the interface the first shot at handling most
interface ioctls, and give the protocol the second shot, instead
of the other way around. Finally, let compatibility code (COMPAT_OSOCK)
take a shot.

Pull device initialization out of switch statements under
SIOCINITIFADDR. For example, pull ..._init() out of any switch
statement that looks like this:

switch (...->sa_family) {
case ...:
..._init();
...
break;
...
default:
..._init();
...
break;
}

Rewrite many if-else clauses that handle all permutations of IFF_UP
and IFF_RUNNING to use a switch statement,

switch (x & (IFF_UP|IFF_RUNNING)) {
case 0:
...
break;
case IFF_RUNNING:
...
break;
case IFF_UP:
...
break;
case IFF_UP|IFF_RUNNING:
...
break;
}

unifdef lots of code containing #ifdef FreeBSD, #ifdef NetBSD, and
#ifdef SIOCSIFMTU, especially in fwip(4) and in ndis(4).

In ipw(4), remove an if_set_sadl() call that is out of place.

In nfe(4), reuse the jumbo MTU logic in ether_ioctl().

Let ethernets register a callback for setting h/w state such as
promiscuous mode and the multicast filter in accord with a change
in the if_flags: ether_set_ifflags_cb() registers a callback that
returns ENETRESET if the caller should reset the ethernet by calling
if_init(), 0 on success, != 0 on failure. Pull common code from
ex(4), gem(4), nfe(4), sip(4), tlp(4), vge(4) into ether_ioctl(),
and register if_flags callbacks for those drivers.

Return ENOTTY instead of EINVAL for inappropriate ioctls. In
zyd(4), use ENXIO instead of ENOTTY to indicate that the device is
not any longer attached.

Add to if_set_sadl() a boolean 'factory' argument that indicates
whether a link-layer address was assigned by the factory or some
other source. In a comment, recommend using the factory address
for generating an EUI64, and update in6_get_hw_ifid() to prefer a
factory address to any other link-layer address.

Add a routing message, RTM_LLINFO_UPD, that tells protocols to
update the binding of network-layer addresses to link-layer addresses.
Implement this message in IPv4 and IPv6 by sending a gratuitous
ARP or a neighbor advertisement, respectively. Generate RTM_LLINFO_UPD
messages on a change of an interface's link-layer address.

In ether_ioctl(), do not let SIOCALIFADDR set a link-layer address
that is broadcast/multicast or equal to 00:00:00:00:00:00.

Make ether_ioctl() call ifioctl_common() to handle ioctls that it
does not understand.

In gif(4), initialize if_softc and use it, instead of assuming that
the gif_softc and ifp overlap.

Let ifioctl_common() handle SIOCGIFADDR.

Sprinkle rtcache_invariants(), which checks on DIAGNOSTIC kernels
that certain invariants on a struct route are satisfied.

In agr(4), rewrite agr_ioctl_filter() to be a bit more explicit
about the ioctls that we do not allow on an agr(4) member interface.

bzero -> memset. Delete unnecessary casts to void *. Use
sockaddr_in_init() and sockaddr_in6_init(). Compare pointers with
NULL instead of "testing truth". Replace some instances of (type
*)0 with NULL. Change some K&R prototypes to ANSI C, and join
lines.
 1.82 08-Sep-2008  gmcgarry branches: 1.82.2;
Replace most gcc-specific __attribute__ uses with BSD-style sys/cdef.h
preprocessor macros.
 1.81 12-Jun-2008  cegger branches: 1.81.2;
use device_lookup_private to get softc
 1.80 08-Jun-2008  tsutsui branches: 1.80.2;
Replace device_lookup() with device_lookup_private() on getting softc
for future device_t/softc spilt.
 1.79 08-Apr-2008  cegger branches: 1.79.2; 1.79.4; 1.79.6;
use aprint_*_dev and device_xname
 1.78 07-Feb-2008  dyoung branches: 1.78.6;
Start patching up the kernel so that a network driver always has
the opportunity to handle an ioctl before generic ifioctl handling
occurs. This will ease extending the kernel and sharing of code
between drivers.

First steps: Make the signature of ifioctl_common() match struct
ifinet->if_ioctl. Convert SIOCSIFCAP and SIOCSIFMTU to the new
ifioctl() regime, throughout the kernel.
 1.77 19-Oct-2007  ad branches: 1.77.2;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.76 01-Sep-2007  dyoung branches: 1.76.4;
Use ifreq_setaddr(), ifreq_getaddr(), sockaddr_in_init(), and
sockaddr_copy(). Constify. Compare pointers with NULL, not 0.
Don't "test truth" of pointers, but compare with NULL.
 1.75 04-Mar-2007  christos branches: 1.75.2; 1.75.10; 1.75.14; 1.75.16;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.74 04-Jan-2007  elad branches: 1.74.2;
Consistent usage of KAUTH_GENERIC_ISSUSER.
 1.73 21-Jul-2006  ad branches: 1.73.4;
- Use the LWP cached credentials where sane.
- Minor cosmetic changes.
 1.72 14-May-2006  elad integrate kauth.
 1.71 10-May-2006  mrg quell GCC 4.1 uninitialised variable warnings.

XXX: we should audit the tree for which old ones are no longer needed
after getting the older compilers out of the tree..
 1.70 14-Apr-2006  christos Coverity CID 1542: Off by one in test.
 1.69 16-Mar-2006  christos branches: 1.69.2;
include if_ether.h if you want to use ether_sprintf()
 1.68 11-Dec-2005  christos branches: 1.68.4; 1.68.6; 1.68.8; 1.68.10;
merge ktrace-lwp.
 1.67 30-May-2005  christos branches: 1.67.2;
- add missing const
- fix variable shadowing
- remove unneeded casts
 1.66 27-Feb-2005  perry nuke trailing whitespace
 1.65 04-Feb-2005  perry de-__P
 1.64 22-Apr-2004  itojun branches: 1.64.4; 1.64.6;
sprintf -> snprintf
 1.63 02-Nov-2003  wiz Fix some typos. From Tom Cosgrove via jmc@openbsd.
 1.62 30-Oct-2003  simonb Remove some assigned-to but otherwise unused variables.
 1.61 23-Jun-2003  martin branches: 1.61.2;
Make sure to include opt_foo.h if a defflag option FOO is used.
 1.60 03-May-2003  wiz DMA, not dma nor Dma.
 1.59 31-Jan-2003  thorpej Use aprint_*().
 1.58 05-Mar-2002  itojun bring in latest ALTQ from kjc. ALTQify some of the drivers.
 1.57 11-Feb-2002  wiz "doesn't" should have an 's'.
 1.56 15-Nov-2001  lukem don't need <sys/types.h> when including <sys/param.h>
 1.55 13-Nov-2001  lukem add/cleanup RCSID
 1.54 28-Sep-2001  chs don't depend on other headers to include sys/proc.h for us.
 1.53 07-Jul-2001  thorpej branches: 1.53.2; 1.53.4;
bzero -> memset
 1.52 07-Jul-2001  thorpej bcopy -> memcpy, strcpy, memmove
 1.51 07-Jul-2001  thorpej bcmp -> memcmp
 1.50 05-Jul-2001  toshii Fix typo. s/extention/extension/
 1.49 12-Apr-2001  thorpej splimp -> splnet
 1.48 18-Dec-2000  thorpej branches: 1.48.2;
Adapt to ALTQ-related API changes (driver is not fully ALTQ'ified yet).
 1.47 12-Dec-2000  thorpej Adapt to bpfattach() changes, and further centralize the bpfattach()
and bpfdetach() calls into link-type subroutines where possible.
 1.46 10-Oct-2000  itojun make it work right on non-32bit arch. from kjc@csl.sony.co.jp
 1.45 06-Sep-2000  thorpej Cast the arg to vtophys() to vaddr_t.
 1.44 09-Aug-2000  tv %b -> bitmask_snprintf()
 1.43 20-Jul-2000  deberg don't define LIST_FOREACH, it's in sys/queue.h now.
 1.42 06-Jul-2000  thorpej Use device_lookup().
 1.41 28-Jun-2000  mrg remove include of <vm/vm.h>. <vm/vm.h> -> <uvm/uvm_extern.h>
 1.40 12-Apr-2000  itojun branches: 1.40.4;
revisit in6_ifattach().
- be persistent on initializing interfaces, even if there's manually-
assigned linklocal, multicast/whatever initialization is necessary.
- do not cache mac addr in the kernel. grab mac addr from existing cards
(this is important when you swap ethernet cards back and forth)
now ppp6 works just fine!

call in6_ifattach() on ATM PVC interface to assign link-local, using
hardware MAC address as seed.

(the change is in sync with kame tree).
 1.39 01-Jul-1999  itojun branches: 1.39.2;
IPv6 kernel code, based on KAME/NetBSD 1.4, SNAP kit 19990628.
(Sorry for a big commit, I can't separate this into several pieces...)
Pls check sys/netinet6/TODO and sys/netinet6/IMPLEMENTATION for details.

- sys/kern: do not assume single mbuf, accept chained mbuf on passing
data from userland to kernel (or other way round).
- "midway" ATM card: ATM PVC pseudo device support, like those done in ALTQ
package (ftp://ftp.csl.sony.co.jp/pub/kjc/).
- sys/netinet/tcp*: IPv4/v6 dual stack tcp support.
- sys/netinet/{ip6,icmp6}.h, sys/net/pfkeyv2.h: IETF document assumes those
file to be there so we patch it up.
- sys/netinet: IPsec additions are here and there.
- sys/netinet6/*: most of IPv6 code sits here.
- sys/netkey: IPsec key management code
- dev/pci/pcidevs: regen

In my understanding no code here is subject to export control so it
should be safe.
 1.38 12-Feb-1999  thorpej branches: 1.38.4; 1.38.6;
Fix printf format problems on Alpha.
 1.37 20-Oct-1998  chuck branches: 1.37.4;
when transmitting we cannot totally fill the circular buffer (i.e.
we can't use up all of the remaining sc->txslot[chan].bfree free
bytes) because that would cause the circular buffer read pointer
to become equal to the write pointer, thus signaling 'empty buffer'
to the hardware and stopping the transmitter. spotted and fixed
by Kenjiro Cho <kjc@csl.sony.co.jp>
 1.36 20-Aug-1998  pk Cast bus_size_t to u_long in printf() args.
 1.35 13-Aug-1998  eeh Merge paddr_t changes into the main branch.
 1.34 08-Aug-1998  mycroft Use splnet, not splimp.
 1.33 05-Jul-1998  jonathan branches: 1.33.2;
defopt INET, NETATALK.
 1.32 04-Jul-1998  jonathan defopt DDB.
 1.31 12-Jan-1998  thorpej Adjust for config changes.
 1.30 29-Sep-1997  chuck midway update:
[1] add EN_ENIDMAFIX - the byte-aligner on the ENI version of the card
appears to lose under heavy load so avoid using it. see comment
in midway.c for full details.

note that the Adaptec version of the card works properly under
load.

detected by Kenjiro Cho <kjc@csl.sony.co.jp> [confirmed by chuck]
fix by chuck & kjc

[2] update some freebsd specific code [from kjc]

[3] for circular buffers: ensure there is always one free slot so
that we can easily tell the difference between a full and
empty list. re-structure a few loops to reflect this.
fixes a problem with mbufs being free'd while still in DMA,
and makes drive a bit more robust.

detected and fixed by kjc
 1.29 07-Jul-1997  cgd branches: 1.29.2;
fix static inline functions' prototypes so they're correctly marked
'inline' as well as static. mark prototypes for static inline functions
as possibly unused (with __attribute__ ((unused))), to avoid generating
warnings when compiling without optimization but with most ports'
default warning flags. Clean up prototype list spacing, and make it more
consistent.
 1.28 28-Apr-1997  mycroft Oops; forgot to GC the last mbuf allocated when out of clusters.
 1.27 24-Apr-1997  mycroft Do not force the initial part of a packet into a separate mbuf.
 1.26 24-Apr-1997  mycroft If we fail to allocate a cluster to hold a large packet, simply
drop it rather than using a chain of tiny mbufs.
 1.25 20-Mar-1997  chuck MAJOR CHANGES: [contributed by Chuck Cranor <chuck@ccrc.wustl.edu> and
Anne Hutton <hutton@isi.edu>]:
- add support for Adaptec 155 PCI ATM cards (e.g. ANA-5940)
- add sc->is_adaptec to handle differences between cards.
- break out MID_MK_TXQ/MID_MK_RXQ seperate macros to handle
the new Adaptec format TXQ/RXQ.
- adjust en_dqneed to return 1 on ADP (since the Adaptec can
DMA anything in one DRQ/DTQ!)
- add hook for a bus specific reset function (adaptec has
a seperate reset register that needs to be hit when
resettting the midway).
- adjust DMA test to not worry about burst sizes on the
adaptec (since it handles it all for us!) and to handle
the new DTQ/DRQ format.
- add Adaptec DMA support to en_txlaunch() and en_service()


BUG FIXES:
- fixed receiver panic under heavy load ("lost mbuf in slot 0!").
when the reassembly buffer overflows, the T-bit is set in
the RDB and the data field is empty. en_service() sets up
a 4-byte (RDB size) dummy DMA without IF_ENQUEUE. but the
recv intr handling in en_intr() always does IF_DEQUEUE.
as a result, a successive recv intr loses its mbuf and
leads to a panic. the solution is to only IF_DEQUEUE if
the interrupt has non-zero length (indicating that there
is an mbuf to get). in order for this to work, EN_DQ_MK
must always be non-zero. we do this by or'ing in an unused
bit (0x80000).
reported by: Kenjiro Cho <kjc@csl.sony.co.jp>

- fix setting of transmit channel when txspeed[] is non-zero
(e.g. traffic shaping). the old scheme didn't work
properly (it allowed the same VCI to use multiple tx channels
thus defeating the txspeed[] parameter). the new scheme
statically assigns a VC to a channel when txspeed[] is set.
[note that the code to set txspeed[] isn't in the driver right
now since a MI interface to do this hasn't been made yet]
we add sc->txvc2slot[] and sc->txslot[n].nref for this.
reported by: Kenjiro Cho <kjc@csl.sony.co.jp>,
Milind M Buddihikot <milind@ccrc.wustl.edu>,
Dong Lin <dong@eecs.harvard.edu>

- when doing SRAM copies, be sure to round up the length to the next
largest word (otherwise the driver will try to do a byte clean
up DMA and then get an ID error interrupt).


MINOR CLEANUPS:
- clean up loops in DMA test
contributed by: Kenjiro Cho <kjc@csl.sony.co.jp>

- restructure and cleanup of en_read/en_write macros/inlines

- clean up some byte ordering stuff so that we are consistant throughout
the driver
 1.24 11-Mar-1997  chuck minor fixes to freebsd code sections from Kenjiro Cho <kjc@csl.sony.co.jp>

get ready to add support for adaptec version of midway card (which
has a different DMA interface).
 1.23 24-Jan-1997  chuck bug fix:
- if aal5 frame has a CRC error then the length field in the aal5 trailer
may not be valid, so we can not use it [and we must dump the frame]
[Yuhang Sun <sunyh@dworkin.wustl.edu> & chuck@ccrc.wustl.edu]
 1.22 21-Nov-1996  chuck midway fixes:
1. fix possible hang in en_txlaunch(). when attempting to extend
the length of an mbuf to avoid a flush we should extend it
by cnt [which is ((need - len) % 4)] rather than 4 - cnt.
also, add an EN_DEBUG printf() when we pad/FLUSH a buffer
to help with debugging/understanding what the driver is up to.
2. use interface packet counters
3. when turning off a recv VCI we recompute the new mode. make sure
we don't include the "in service" bit in the new mode, otherwise
a VCI may appear "hung" if you turn it off while a service
interrupt is pending.
4. when shutting down a VCI that is still receiving data, don't bother
going into "drain mode" if only the hardware in service bit is
set (otherwise the VCI may get "hung" in drain mode).
as a result of this we may get "unexpected rx interrupt" messages
which are not really an error, so put this printf in EN_DEBUG.
5. be sure to zero txspeed[lcv] when enabling a VCI (start at full
speed). (hooks for setting txspeed[] are currently not in
the driver, but we are playing with it locally).
credits:
#1: Detected by: Zdenek Salvet <salvet@horn.ics.muni.cz>, fix by me.
#2: Contributed by: Zdenek Salvet <salvet@horn.ics.muni.cz>
#3,#4,#5: Detected by: Milind M. Buddhikot <milind@dworkin.wustl.edu>,
fixed by me.
 1.21 09-Nov-1996  chuck netbsd pr#2919 (jukka.partanen@research.nokia.com):
- fix compiler warnings
 1.20 25-Oct-1996  cgd update alpha_XXX_dmamap() invocations to match prototype.
 1.19 23-Oct-1996  cgd update drivers to use the new NetBSD/alpha DMA mapping hack, since
the old one is not workable with the new bus.h.
 1.18 21-Oct-1996  thorpej New bus.h implementation/interface:
- No more distinction between i/o-mapped and memory-mapped
devices. It's all "bus space" now, and space tags
differentiate the space with finer grain than the
bus chipset tag.
- Add memory barrier methods.
- Implement space alloc/free methods.
- Implement region read/write methods (like memcpy to/from
bus space).
This interface provides a better abstraction for dealing with
machine-independent chipset drivers.
 1.17 13-Oct-1996  christos backout kprintf changes
 1.16 10-Oct-1996  christos - printf -> kprintf, sprintf -> ksprintf
 1.15 02-Aug-1996  chuck fix:
- fix memory sizing bug for 2MB cards. driver now works for both 512KB
and 2MB ATM cards (we just got 10 2MB cards).
 1.14 17-Jul-1996  chuck fixes/update:
- adjust txhiwat and mindma params a bit

- fixed a couple of incorrectly labeled panic calls

- the "location" was being calculated incorrectly in some cases (forgot
to subtract off MID_RAMBASE). this only caused problem when trying
to change the size of the tx/rx buffers (e.g. to 64KB).

- fixed possible non-aligned DMA burst in the starting byte burst case.
(e.g. if we could DMA 3 bytes, but only have 2 it is not legal
for us to use MIDDMA_BYTE2 mode).

- opt: on tx: try and avoid flushing the internal buffer by padding out the
length of the last mbuf a bit (if possible)
 1.13 16-Jul-1996  chuck midway fixes + new stuff:
- merged multiple DRQ/DTQ ADD macros into a single DRQ and a single DTQ
macro with a uniform interface to make the code simpler and easier to read.

- en_start: only update atm_flags if EN_MBUF_OPT is enabled (which it
should be)

- for alburst: make sure we don't DMA more bytes than we need (on both
tx and rx). if the alburst is larger than we need, drop to
MIDDMA_WORD mode.

- major change: enable the use of byte and 2 byte DMA on the trasmit side.
this allows us to DMA from non-word sized/aligned mbufs directly.
[the old code would always call en_mfix which would copy (or move) the
data in order to ensure proper alignment... it turns out TCP gives
us non-word sized/aligned mbufs when it is retransmitting, so we needed
to handle this case more efficiently.] the following functions
were changed to make this work:
- en_dqneed: add an arg to let us know if we are transmitting or not.
if we are TX, then we must take into account byte DMAs when
estimating the number of DTQs we will need for a buffer
- en_start: only mfix mbufs if DMA is disabled
- en_txdma: only set launch.nodma if we have en_mfix'd the mbuf chain
also, we may need a DTQ to flush the chip's internal byte buffer
- en_txlaunch: only attempt a copy if we have the proper alignment.
add byte dma code for the front and end of the buffer.
make sure the internal dma buffer is flushed out.
- stats: keep track of how many times we have to use byte sized DMA

midwayreg:
- add byte/2byte DMA defines

midwayvar:
- add new stat counter to monitor less-than-word lengthed DMA
 1.12 15-Jul-1996  cgd before #defining the vtophys() hack for the alpha, #undef vtophys since
it may be a macro.
 1.11 14-Jul-1996  cgd insert the normal NetBSD/Alpha vtophys() hack, so that this will compile
and link nicely on the Alpha. It may even run, if well written.
 1.10 14-Jul-1996  cgd fix bogus casts from pointer to unsigned int. Use unsigned long for this.
 1.9 11-Jul-1996  chuck fix:
- en_mfix shouldn't touch M_EXT mbufs. change to avoid this [at
the expense of allocating a new cluster mbuf to copy to].

XXX: en_mfix is getting called more often than I hoped it would
(seems to happen when TCP retransmits... we get all sorts of odd
sized, odd lengthed data mbufs, yuck). i may revise the xmit
DMA code to use non-word sized dma.
 1.8 11-Jul-1996  chuck fixes:

- don't try and add a PDU trailer (or TBD for that matter) to an M_EXT
mbuf. when M_EXT is set, the data area of the mbuf can be shared
with other mbufs (see m_copym()), and writing to one M_EXT mbuf may
invalidate another M_EXT mbuf (saw this with PDU trailers).

- be sure to validate the length value from the PDU trailer so that it
doesn't throw us out of sync with the chip (fixes yet another source
of the dread "en_service: id mismatch" panic).

- on recv, don't bother allocating an mbuf if mlen is zero since we are
only going to toss the data anyway.
 1.7 03-Jul-1996  chuck ported to FreeBSD 2.2-960612-SNAP. [thanks to Matt Thomas' driver work]
 1.6 29-Jun-1996  chuck new: add a raw_threshold for raw mode. this basically tells the driver
to ignore inbound data sizes less than the threshold. otherwise,
when connected to a video aal0 input the driver gives us a massive
stream of 56 byte mbufs each with one aal0 cell in it and the
system just can't keep up with it, especially if the socket buffer
size is large [it hangs until you turn off the video source].

fixes: when turning off a vc, try and check the freshest copy of the mode
when seeing if we need to enter the "drain" state. also, don't
panic if we get unexpected rx interrupt on a VCI (instead make sure
the VC is off, print a warning, and move on!).
 1.5 29-Jun-1996  chuck change:
- change rxso into a void handle ... no need to know details at this low
level.
fix:
- forgot to init "vci" during ENOTHER_DRAIN case of RX DMA interrupt
[could cause a vm_fault on native mode connection close depending
on needing to drain out the VC and also the random value of vci]
 1.4 28-Jun-1996  chuck new: add all needed hooks to engage raw mode.
 1.3 27-Jun-1996  chuck fixes/improvements:
- more stat counters (rxmbufout -- mbufs, ttrash -- trashed RBD)
- add swsl_size to keep track of size of software slist
- revise when we call en_service
- fix handling of circular lists (was getting full vs empty confused in
extreem cases...)
- native mode atm: remove sbappend code: can't do it here since
socket buffer is protected only by splsoftnet and that doesn't
mask enintr off. forces us to switch to a two level interrupt
scheme. revise call to atm_input to reflect that.
 1.2 26-Jun-1996  chuck fixes:
[1] rxslot "cur" pointer wasn't updated if we copied all data and
didn't have any fill. this could cause a service id mismatch
panic under load.
[2] recv of aal0 forgot to include the cell header in the data length
calc [add cell header length to midwayreg.h]
[3] fix control info "chop" for raw mode and aal0
[4] handle rxsb better for native atm connections
(XXX: still working on this ... not complete and needs revision)
 1.1 22-Jun-1996  chuck add support for efficient networks midway atm chip.
 1.29.2.1 14-Oct-1997  thorpej Update marc-pcmcia branch from trunk.
 1.33.2.1 30-Jul-1998  eeh Split vm_offset_t and vm_size_t into paddr_t, psize_t, vaddr_t, and vsize_t.
 1.37.4.1 11-Dec-1998  kenh The beginnings of interface detach support. Still some bugs, but mostly
works for me.

This work was originally by Bill Studenmund, and cleaned up by me.
 1.38.6.2 30-Nov-1999  itojun bring in latest KAME (as of 19991130, KAME/NetBSD141) into kame branch
just for reference purposes.
This commit includes 1.4 -> 1.4.1 sync for kame branch.

The branch does not compile at all (due to the lack of ALTQ and some other
source code). Please do not try to modify the branch, this is just for
referenre purposes.

synchronization to latest KAME will take place on HEAD branch soon.
 1.38.6.1 28-Jun-1999  itojun KAME/NetBSD 1.4 SNAP kit, dated 19990628.

NOTE: this branch (kame) is used just for refernce. this may not compile
due to multiple reasons.
 1.38.4.1 01-Jul-1999  thorpej Sync w/ -current.
 1.39.2.4 21-Apr-2001  bouyer Sync with HEAD
 1.39.2.3 05-Jan-2001  bouyer Sync with HEAD
 1.39.2.2 13-Dec-2000  bouyer Sync with HEAD (for UBC fixes).
 1.39.2.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.40.4.3 15-Mar-2003  he Pull up revision 1.44 (via ptch, requested by gmcgarry in ticket #8):
Convert from %b to bitmask_snprintf(). Allows this to compile
cleanly with later toolchains.
 1.40.4.2 06-May-2001  he Pull up revision 1.43 (requested by he):
Adapt to:
Add new powerhook argument values, PWR_SOFTSUSPEND, PWR_SOFTSTANDBY and
PWR_SOFTRESUME. Apm calls powerhook with the values in normal interrupt
priority level while others are protected with splhigh().
...by omitting local queue macro.
 1.40.4.1 17-Oct-2000  tv Pullup 1.46 [itojun]:
make it work right on non-32bit arch. from kjc@csl.sony.co.jp
 1.48.2.10 10-Jul-2002  nathanw Whitespace.
 1.48.2.9 24-Jun-2002  nathanw Curproc->curlwp renaming.

Change uses of "curproc->l_proc" back to "curproc", which is more like the
original use. Bare uses of "curproc" are now "curlwp".

"curproc" is now #defined in proc.h as ((curlwp) ? (curlwp)->l_proc) : NULL)
so that it is always safe to reference curproc (*de*referencing curproc
is another story, but that's always been true).
 1.48.2.8 01-Apr-2002  nathanw Catch up to -current.
(CVS: It's not just a program. It's an adventure!)
 1.48.2.7 28-Feb-2002  nathanw Catch up to -current.
 1.48.2.6 08-Jan-2002  nathanw Catch up to -current.
 1.48.2.5 14-Nov-2001  nathanw Catch up to -current.
 1.48.2.4 08-Oct-2001  nathanw Catch up to -current.
 1.48.2.3 24-Aug-2001  nathanw Catch up with -current.
 1.48.2.2 21-Jun-2001  nathanw Catch up to -current.
 1.48.2.1 05-Mar-2001  nathanw Initial commit of scheduler activations and lightweight process support.
 1.53.4.1 01-Oct-2001  fvdl Catch up with -current.
 1.53.2.2 16-Mar-2002  jdolecek Catch up with -current.
 1.53.2.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.61.2.6 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.61.2.5 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.61.2.4 04-Feb-2005  skrll Sync with HEAD.
 1.61.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.61.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.61.2.1 03-Aug-2004  skrll Sync with HEAD
 1.64.6.2 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.64.6.1 12-Feb-2005  yamt sync with head.
 1.64.4.1 29-Apr-2005  kent sync with -current
 1.67.2.6 11-Feb-2008  yamt sync with head.
 1.67.2.5 27-Oct-2007  yamt sync with head.
 1.67.2.4 03-Sep-2007  yamt sync with head.
 1.67.2.3 26-Feb-2007  yamt sync with head.
 1.67.2.2 30-Dec-2006  yamt sync with head.
 1.67.2.1 21-Jun-2006  yamt sync with head.
 1.68.10.4 11-May-2006  elad sync with head
 1.68.10.3 19-Apr-2006  elad sync with head.
 1.68.10.2 10-Mar-2006  elad generic_authorize() -> kauth_authorize_generic().
 1.68.10.1 08-Mar-2006  elad Adapt to kernel authorization KPI.
 1.68.8.3 11-Aug-2006  yamt sync with head
 1.68.8.2 24-May-2006  yamt sync with head.
 1.68.8.1 01-Apr-2006  yamt sync with head.
 1.68.6.2 01-Jun-2006  kardel Sync with head.
 1.68.6.1 22-Apr-2006  simonb Sync with head.
 1.68.4.1 09-Sep-2006  rpaulo sync with head
 1.69.2.1 24-May-2006  tron Merge 2006-05-24 NetBSD-current into the "peter-altq" branch.
 1.73.4.1 12-Jan-2007  ad Sync with head.
 1.74.2.1 12-Mar-2007  rmind Sync with HEAD.
 1.75.16.2 23-Mar-2008  matt sync with HEAD
 1.75.16.1 06-Nov-2007  matt sync with HEAD
 1.75.14.2 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.75.14.1 03-Sep-2007  jmcneill Sync with HEAD.
 1.75.10.1 03-Sep-2007  skrll Sync with HEAD.
 1.75.2.2 23-Oct-2007  ad Sync with head.
 1.75.2.1 09-Oct-2007  ad Sync with head.
 1.76.4.1 25-Oct-2007  bouyer Sync with HEAD.
 1.77.2.1 18-Feb-2008  mjf Sync with HEAD.
 1.78.6.4 17-Jan-2009  mjf Sync with HEAD.
 1.78.6.3 28-Sep-2008  mjf Sync with HEAD.
 1.78.6.2 29-Jun-2008  mjf Sync with HEAD.
 1.78.6.1 02-Jun-2008  mjf Sync with HEAD.
 1.79.6.2 24-Sep-2008  wrstuden Merge in changes between wrstuden-revivesa-base-2 and
wrstuden-revivesa-base-3.
 1.79.6.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.79.4.3 11-Aug-2010  yamt sync with head.
 1.79.4.2 11-Mar-2010  yamt sync with head
 1.79.4.1 04-May-2009  yamt sync with head.
 1.79.2.1 17-Jun-2008  yamt sync with head.
 1.80.2.1 18-Jun-2008  simonb Sync with head.
 1.81.2.2 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.81.2.1 19-Oct-2008  haad Sync with HEAD.
 1.82.2.2 28-Apr-2009  skrll Sync with HEAD.
 1.82.2.1 19-Jan-2009  skrll Sync with HEAD.
 1.85.2.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.90.4.2 05-Mar-2011  rmind sync with head
 1.90.4.1 30-May-2010  rmind sync with head
 1.90.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.91.4.1 08-Feb-2011  bouyer Sync with HEAD
 1.91.2.1 06-Jun-2011  jruoho Sync with HEAD.
 1.93.6.1 05-Apr-2012  mrg sync to latest -current.
 1.93.2.1 17-Apr-2012  yamt sync with head
 1.94.16.4 28-Aug-2017  skrll Sync with HEAD
 1.94.16.3 05-Feb-2017  skrll Sync with HEAD
 1.94.16.2 09-Jul-2016  skrll Sync with HEAD
 1.94.16.1 19-Mar-2016  skrll Sync with HEAD
 1.94.2.1 03-Dec-2017  jdolecek update from HEAD
 1.97.2.3 26-Apr-2017  pgoyette Sync with HEAD
 1.97.2.2 20-Mar-2017  pgoyette Sync with HEAD
 1.97.2.1 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.98.2.1 21-Apr-2017  bouyer Sync with HEAD
 1.101.2.3 30-Sep-2018  pgoyette Ssync with HEAD
 1.101.2.2 06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.101.2.1 28-Jul-2018  pgoyette Sync with HEAD
 1.102.2.1 10-Jun-2019  christos Sync with HEAD
 1.15 06-Sep-2018  maxv Retire the 'midway' driver. Discussed on tech-net@ recently and also three
years ago, part of removing the network ATM code.
 1.14 04-Mar-2007  christos branches: 1.14.128; 1.14.130;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.13 11-Dec-2005  christos branches: 1.13.26;
merge ktrace-lwp.
 1.12 27-Feb-2005  perry branches: 1.12.4;
nuke trailing whitespace
 1.11 02-Nov-2003  wiz branches: 1.11.8; 1.11.10;
Fix some typos. From Tom Cosgrove via jmc@openbsd.
 1.10 03-May-2003  wiz branches: 1.10.2;
DMA, not dma nor Dma.
 1.9 01-Jul-1999  itojun IPv6 kernel code, based on KAME/NetBSD 1.4, SNAP kit 19990628.
(Sorry for a big commit, I can't separate this into several pieces...)
Pls check sys/netinet6/TODO and sys/netinet6/IMPLEMENTATION for details.

- sys/kern: do not assume single mbuf, accept chained mbuf on passing
data from userland to kernel (or other way round).
- "midway" ATM card: ATM PVC pseudo device support, like those done in ALTQ
package (ftp://ftp.csl.sony.co.jp/pub/kjc/).
- sys/netinet/tcp*: IPv4/v6 dual stack tcp support.
- sys/netinet/{ip6,icmp6}.h, sys/net/pfkeyv2.h: IETF document assumes those
file to be there so we patch it up.
- sys/netinet: IPsec additions are here and there.
- sys/netinet6/*: most of IPv6 code sits here.
- sys/netkey: IPsec key management code
- dev/pci/pcidevs: regen

In my understanding no code here is subject to export control so it
should be safe.
 1.8 03-Mar-1999  pk branches: 1.8.4; 1.8.6;
sparc => __sparc__
 1.7 20-Aug-1998  pk remove sparc hack: there's a bus.h now.
 1.6 20-Mar-1997  chuck MAJOR CHANGES: [contributed by Chuck Cranor <chuck@ccrc.wustl.edu> and
Anne Hutton <hutton@isi.edu>]:
- add support for Adaptec 155 PCI ATM cards (e.g. ANA-5940)
- add sc->is_adaptec to handle differences between cards.
- break out MID_MK_TXQ/MID_MK_RXQ seperate macros to handle
the new Adaptec format TXQ/RXQ.
- adjust en_dqneed to return 1 on ADP (since the Adaptec can
DMA anything in one DRQ/DTQ!)
- add hook for a bus specific reset function (adaptec has
a seperate reset register that needs to be hit when
resettting the midway).
- adjust DMA test to not worry about burst sizes on the
adaptec (since it handles it all for us!) and to handle
the new DTQ/DRQ format.
- add Adaptec DMA support to en_txlaunch() and en_service()


BUG FIXES:
- fixed receiver panic under heavy load ("lost mbuf in slot 0!").
when the reassembly buffer overflows, the T-bit is set in
the RDB and the data field is empty. en_service() sets up
a 4-byte (RDB size) dummy DMA without IF_ENQUEUE. but the
recv intr handling in en_intr() always does IF_DEQUEUE.
as a result, a successive recv intr loses its mbuf and
leads to a panic. the solution is to only IF_DEQUEUE if
the interrupt has non-zero length (indicating that there
is an mbuf to get). in order for this to work, EN_DQ_MK
must always be non-zero. we do this by or'ing in an unused
bit (0x80000).
reported by: Kenjiro Cho <kjc@csl.sony.co.jp>

- fix setting of transmit channel when txspeed[] is non-zero
(e.g. traffic shaping). the old scheme didn't work
properly (it allowed the same VCI to use multiple tx channels
thus defeating the txspeed[] parameter). the new scheme
statically assigns a VC to a channel when txspeed[] is set.
[note that the code to set txspeed[] isn't in the driver right
now since a MI interface to do this hasn't been made yet]
we add sc->txvc2slot[] and sc->txslot[n].nref for this.
reported by: Kenjiro Cho <kjc@csl.sony.co.jp>,
Milind M Buddihikot <milind@ccrc.wustl.edu>,
Dong Lin <dong@eecs.harvard.edu>

- when doing SRAM copies, be sure to round up the length to the next
largest word (otherwise the driver will try to do a byte clean
up DMA and then get an ID error interrupt).


MINOR CLEANUPS:
- clean up loops in DMA test
contributed by: Kenjiro Cho <kjc@csl.sony.co.jp>

- restructure and cleanup of en_read/en_write macros/inlines

- clean up some byte ordering stuff so that we are consistant throughout
the driver
 1.5 21-Oct-1996  thorpej New bus.h implementation/interface:
- No more distinction between i/o-mapped and memory-mapped
devices. It's all "bus space" now, and space tags
differentiate the space with finer grain than the
bus chipset tag.
- Add memory barrier methods.
- Implement space alloc/free methods.
- Implement region read/write methods (like memcpy to/from
bus space).
This interface provides a better abstraction for dealing with
machine-independent chipset drivers.
 1.4 16-Jul-1996  chuck midway fixes + new stuff:
- merged multiple DRQ/DTQ ADD macros into a single DRQ and a single DTQ
macro with a uniform interface to make the code simpler and easier to read.

- en_start: only update atm_flags if EN_MBUF_OPT is enabled (which it
should be)

- for alburst: make sure we don't DMA more bytes than we need (on both
tx and rx). if the alburst is larger than we need, drop to
MIDDMA_WORD mode.

- major change: enable the use of byte and 2 byte DMA on the trasmit side.
this allows us to DMA from non-word sized/aligned mbufs directly.
[the old code would always call en_mfix which would copy (or move) the
data in order to ensure proper alignment... it turns out TCP gives
us non-word sized/aligned mbufs when it is retransmitting, so we needed
to handle this case more efficiently.] the following functions
were changed to make this work:
- en_dqneed: add an arg to let us know if we are transmitting or not.
if we are TX, then we must take into account byte DMAs when
estimating the number of DTQs we will need for a buffer
- en_start: only mfix mbufs if DMA is disabled
- en_txdma: only set launch.nodma if we have en_mfix'd the mbuf chain
also, we may need a DTQ to flush the chip's internal byte buffer
- en_txlaunch: only attempt a copy if we have the proper alignment.
add byte dma code for the front and end of the buffer.
make sure the internal dma buffer is flushed out.
- stats: keep track of how many times we have to use byte sized DMA

midwayreg:
- add byte/2byte DMA defines

midwayvar:
- add new stat counter to monitor less-than-word lengthed DMA
 1.3 03-Jul-1996  chuck ported to FreeBSD 2.2-960612-SNAP. [thanks to Matt Thomas' driver work]
 1.2 26-Jun-1996  chuck fixes:
[1] rxslot "cur" pointer wasn't updated if we copied all data and
didn't have any fill. this could cause a service id mismatch
panic under load.
[2] recv of aal0 forgot to include the cell header in the data length
calc [add cell header length to midwayreg.h]
[3] fix control info "chop" for raw mode and aal0
[4] handle rxsb better for native atm connections
(XXX: still working on this ... not complete and needs revision)
 1.1 22-Jun-1996  chuck add support for efficient networks midway atm chip.
 1.8.6.2 30-Nov-1999  itojun bring in latest KAME (as of 19991130, KAME/NetBSD141) into kame branch
just for reference purposes.
This commit includes 1.4 -> 1.4.1 sync for kame branch.

The branch does not compile at all (due to the lack of ALTQ and some other
source code). Please do not try to modify the branch, this is just for
referenre purposes.

synchronization to latest KAME will take place on HEAD branch soon.
 1.8.6.1 28-Jun-1999  itojun KAME/NetBSD 1.4 SNAP kit, dated 19990628.

NOTE: this branch (kame) is used just for refernce. this may not compile
due to multiple reasons.
 1.8.4.1 01-Jul-1999  thorpej Sync w/ -current.
 1.10.2.4 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.10.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.10.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.10.2.1 03-Aug-2004  skrll Sync with HEAD
 1.11.10.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.11.8.1 29-Apr-2005  kent sync with -current
 1.12.4.1 03-Sep-2007  yamt sync with head.
 1.13.26.1 12-Mar-2007  rmind Sync with HEAD.
 1.14.130.1 10-Jun-2019  christos Sync with HEAD
 1.14.128.1 30-Sep-2018  pgoyette Ssync with HEAD
 1.20 06-Sep-2018  maxv Retire the 'midway' driver. Discussed on tech-net@ recently and also three
years ago, part of removing the network ATM code.
 1.19 27-Oct-2012  chs branches: 1.19.36; 1.19.38;
split device_t/softc for all remaining drivers.
replace "struct device *" with "device_t".
use device_xname(), device_unit(), etc.
 1.18 18-Jul-2011  mrg branches: 1.18.2; 1.18.12;
convert the remaining dev/sbus drivers to CFATTACH_DECL_NEW, cfdata_t
and device_t, including the pci frontend and backend for en(4).
 1.17 01-Feb-2011  chuck udpate license clauses on my code to match the new-style BSD licenses.
remove no-longer-valid wustl email address for me.
based on diff that rmind@ sent me.

no functional change with this commit.
 1.16 11-Dec-2005  christos branches: 1.16.98; 1.16.104; 1.16.106;
merge ktrace-lwp.
 1.15 27-Feb-2005  perry nuke trailing whitespace
 1.14 04-Feb-2005  perry de-__P
 1.13 02-Nov-2003  wiz branches: 1.13.8; 1.13.10;
Fix some typos. From Tom Cosgrove via jmc@openbsd.
 1.12 03-May-2003  wiz branches: 1.12.2;
DMA, not dma nor Dma.
 1.11 01-Jul-1999  itojun IPv6 kernel code, based on KAME/NetBSD 1.4, SNAP kit 19990628.
(Sorry for a big commit, I can't separate this into several pieces...)
Pls check sys/netinet6/TODO and sys/netinet6/IMPLEMENTATION for details.

- sys/kern: do not assume single mbuf, accept chained mbuf on passing
data from userland to kernel (or other way round).
- "midway" ATM card: ATM PVC pseudo device support, like those done in ALTQ
package (ftp://ftp.csl.sony.co.jp/pub/kjc/).
- sys/netinet/tcp*: IPv4/v6 dual stack tcp support.
- sys/netinet/{ip6,icmp6}.h, sys/net/pfkeyv2.h: IETF document assumes those
file to be there so we patch it up.
- sys/netinet: IPsec additions are here and there.
- sys/netinet6/*: most of IPv6 code sits here.
- sys/netkey: IPsec key management code
- dev/pci/pcidevs: regen

In my understanding no code here is subject to export control so it
should be safe.
 1.10 20-Mar-1997  chuck branches: 1.10.14; 1.10.18; 1.10.20;
MAJOR CHANGES: [contributed by Chuck Cranor <chuck@ccrc.wustl.edu> and
Anne Hutton <hutton@isi.edu>]:
- add support for Adaptec 155 PCI ATM cards (e.g. ANA-5940)
- add sc->is_adaptec to handle differences between cards.
- break out MID_MK_TXQ/MID_MK_RXQ seperate macros to handle
the new Adaptec format TXQ/RXQ.
- adjust en_dqneed to return 1 on ADP (since the Adaptec can
DMA anything in one DRQ/DTQ!)
- add hook for a bus specific reset function (adaptec has
a seperate reset register that needs to be hit when
resettting the midway).
- adjust DMA test to not worry about burst sizes on the
adaptec (since it handles it all for us!) and to handle
the new DTQ/DRQ format.
- add Adaptec DMA support to en_txlaunch() and en_service()


BUG FIXES:
- fixed receiver panic under heavy load ("lost mbuf in slot 0!").
when the reassembly buffer overflows, the T-bit is set in
the RDB and the data field is empty. en_service() sets up
a 4-byte (RDB size) dummy DMA without IF_ENQUEUE. but the
recv intr handling in en_intr() always does IF_DEQUEUE.
as a result, a successive recv intr loses its mbuf and
leads to a panic. the solution is to only IF_DEQUEUE if
the interrupt has non-zero length (indicating that there
is an mbuf to get). in order for this to work, EN_DQ_MK
must always be non-zero. we do this by or'ing in an unused
bit (0x80000).
reported by: Kenjiro Cho <kjc@csl.sony.co.jp>

- fix setting of transmit channel when txspeed[] is non-zero
(e.g. traffic shaping). the old scheme didn't work
properly (it allowed the same VCI to use multiple tx channels
thus defeating the txspeed[] parameter). the new scheme
statically assigns a VC to a channel when txspeed[] is set.
[note that the code to set txspeed[] isn't in the driver right
now since a MI interface to do this hasn't been made yet]
we add sc->txvc2slot[] and sc->txslot[n].nref for this.
reported by: Kenjiro Cho <kjc@csl.sony.co.jp>,
Milind M Buddihikot <milind@ccrc.wustl.edu>,
Dong Lin <dong@eecs.harvard.edu>

- when doing SRAM copies, be sure to round up the length to the next
largest word (otherwise the driver will try to do a byte clean
up DMA and then get an ID error interrupt).


MINOR CLEANUPS:
- clean up loops in DMA test
contributed by: Kenjiro Cho <kjc@csl.sony.co.jp>

- restructure and cleanup of en_read/en_write macros/inlines

- clean up some byte ordering stuff so that we are consistant throughout
the driver
 1.9 11-Mar-1997  chuck minor fixes to freebsd code sections from Kenjiro Cho <kjc@csl.sony.co.jp>

get ready to add support for adaptec version of midway card (which
has a different DMA interface).
 1.8 21-Oct-1996  thorpej New bus.h implementation/interface:
- No more distinction between i/o-mapped and memory-mapped
devices. It's all "bus space" now, and space tags
differentiate the space with finer grain than the
bus chipset tag.
- Add memory barrier methods.
- Implement space alloc/free methods.
- Implement region read/write methods (like memcpy to/from
bus space).
This interface provides a better abstraction for dealing with
machine-independent chipset drivers.
 1.7 16-Jul-1996  chuck midway fixes + new stuff:
- merged multiple DRQ/DTQ ADD macros into a single DRQ and a single DTQ
macro with a uniform interface to make the code simpler and easier to read.

- en_start: only update atm_flags if EN_MBUF_OPT is enabled (which it
should be)

- for alburst: make sure we don't DMA more bytes than we need (on both
tx and rx). if the alburst is larger than we need, drop to
MIDDMA_WORD mode.

- major change: enable the use of byte and 2 byte DMA on the trasmit side.
this allows us to DMA from non-word sized/aligned mbufs directly.
[the old code would always call en_mfix which would copy (or move) the
data in order to ensure proper alignment... it turns out TCP gives
us non-word sized/aligned mbufs when it is retransmitting, so we needed
to handle this case more efficiently.] the following functions
were changed to make this work:
- en_dqneed: add an arg to let us know if we are transmitting or not.
if we are TX, then we must take into account byte DMAs when
estimating the number of DTQs we will need for a buffer
- en_start: only mfix mbufs if DMA is disabled
- en_txdma: only set launch.nodma if we have en_mfix'd the mbuf chain
also, we may need a DTQ to flush the chip's internal byte buffer
- en_txlaunch: only attempt a copy if we have the proper alignment.
add byte dma code for the front and end of the buffer.
make sure the internal dma buffer is flushed out.
- stats: keep track of how many times we have to use byte sized DMA

midwayreg:
- add byte/2byte DMA defines

midwayvar:
- add new stat counter to monitor less-than-word lengthed DMA
 1.6 11-Jul-1996  chuck fix:
- en_mfix shouldn't touch M_EXT mbufs. change to avoid this [at
the expense of allocating a new cluster mbuf to copy to].

XXX: en_mfix is getting called more often than I hoped it would
(seems to happen when TCP retransmits... we get all sorts of odd
sized, odd lengthed data mbufs, yuck). i may revise the xmit
DMA code to use non-word sized dma.
 1.5 03-Jul-1996  chuck ported to FreeBSD 2.2-960612-SNAP. [thanks to Matt Thomas' driver work]
 1.4 29-Jun-1996  chuck new: add a raw_threshold for raw mode. this basically tells the driver
to ignore inbound data sizes less than the threshold. otherwise,
when connected to a video aal0 input the driver gives us a massive
stream of 56 byte mbufs each with one aal0 cell in it and the
system just can't keep up with it, especially if the socket buffer
size is large [it hangs until you turn off the video source].

fixes: when turning off a vc, try and check the freshest copy of the mode
when seeing if we need to enter the "drain" state. also, don't
panic if we get unexpected rx interrupt on a VCI (instead make sure
the VC is off, print a warning, and move on!).
 1.3 29-Jun-1996  chuck change:
- change rxso into a void handle ... no need to know details at this low
level.
fix:
- forgot to init "vci" during ENOTHER_DRAIN case of RX DMA interrupt
[could cause a vm_fault on native mode connection close depending
on needing to drain out the VC and also the random value of vci]
 1.2 27-Jun-1996  chuck fixes/improvements:
- more stat counters (rxmbufout -- mbufs, ttrash -- trashed RBD)
- add swsl_size to keep track of size of software slist
- revise when we call en_service
- fix handling of circular lists (was getting full vs empty confused in
extreem cases...)
- native mode atm: remove sbappend code: can't do it here since
socket buffer is protected only by splsoftnet and that doesn't
mask enintr off. forces us to switch to a two level interrupt
scheme. revise call to atm_input to reflect that.
 1.1 22-Jun-1996  chuck add support for efficient networks midway atm chip.
 1.10.20.2 30-Nov-1999  itojun bring in latest KAME (as of 19991130, KAME/NetBSD141) into kame branch
just for reference purposes.
This commit includes 1.4 -> 1.4.1 sync for kame branch.

The branch does not compile at all (due to the lack of ALTQ and some other
source code). Please do not try to modify the branch, this is just for
referenre purposes.

synchronization to latest KAME will take place on HEAD branch soon.
 1.10.20.1 28-Jun-1999  itojun KAME/NetBSD 1.4 SNAP kit, dated 19990628.

NOTE: this branch (kame) is used just for refernce. this may not compile
due to multiple reasons.
 1.10.18.1 01-Jul-1999  thorpej Sync w/ -current.
 1.10.14.1 11-Dec-1998  kenh The beginnings of interface detach support. Still some bugs, but mostly
works for me.

This work was originally by Bill Studenmund, and cleaned up by me.
 1.12.2.5 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.12.2.4 04-Feb-2005  skrll Sync with HEAD.
 1.12.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.12.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.12.2.1 03-Aug-2004  skrll Sync with HEAD
 1.13.10.2 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.13.10.1 12-Feb-2005  yamt sync with head.
 1.13.8.1 29-Apr-2005  kent sync with -current
 1.16.106.1 08-Feb-2011  bouyer Sync with HEAD
 1.16.104.1 06-Jun-2011  jruoho Sync with HEAD.
 1.16.98.1 05-Mar-2011  rmind sync with head
 1.18.12.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.18.2.1 30-Oct-2012  yamt sync with head
 1.19.38.1 10-Jun-2019  christos Sync with HEAD
 1.19.36.1 30-Sep-2018  pgoyette Ssync with HEAD
 1.29 07-Sep-2025  thorpej Change todr_chip_handle::cookie -> todr_chip_handle::todr_dev, and
make it a device_t. Upcoming functional changes will require the
device_t associated with a TODR device.

Change todr_chip_handle::bus_cookie -> todr_chip_handle::todr_devaux.
Nothing was using the old field, but I decided to keep it around just
in cause something needs it in the future.

And with these largely mechanical yet semantically meaningful changes,
thus spake the Oracle: "Welcome to NetBSD 11.99.2."
 1.28 01-Jan-2020  thorpej Fix some issues around todr_wenable():
- As previously defined, it was not possible to return an error from the
back-end RTC driver. Make it a real function so that it can do so.
- Only the mc146818 and mk48txx drivers used it (for historical reasons).
Centralize the logic for how it's used in kern_todr.c (and make it private
to that file) for consistency.
 1.27 20-Nov-2014  christos branches: 1.27.20;
use the inline bcdtobin and bintobcd directly instead through a macro.
 1.26 04-Jan-2011  matt branches: 1.26.18;
Make this support the DS1553 as well. Add support for the centry reg which
newer RTCs seem to have.
 1.25 28-Apr-2008  martin branches: 1.25.22; 1.25.26;
Remove clause 3 and 4 from TNF licenses
 1.24 10-Jan-2008  tsutsui branches: 1.24.6; 1.24.8; 1.24.10;
- move todr_attach(9) calls from each MD attachment to MI mk48txx_attach()
- don't clear todr_setwen in mk48txx_attach() since it might be set by
MD attachments
 1.23 10-Jan-2008  tsutsui - use aprint_normal(9)
- use __arraycount()
- use __func__ to print a function name
 1.22 19-Oct-2007  ad branches: 1.22.2; 1.22.8;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.21 01-Oct-2006  tsutsui branches: 1.21.8; 1.21.22; 1.21.24; 1.21.28;
u_int8_t -> uint8_t
 1.20 07-Sep-2006  gdamore branches: 1.20.2; 1.20.4;
Updated to new clock_ymdhms support in kern_todr.
While here, ansify a few routines.
 1.19 04-Sep-2006  gdamore Remove unused todr_setcal/todr_getcal and all the assorted stub
implementations.
 1.18 11-Dec-2005  christos branches: 1.18.4; 1.18.8;
merge ktrace-lwp.
 1.17 04-Jun-2005  he branches: 1.17.2;
Fix the various todr_gettime() and todr_settime() fallouts from
-Wcast-qual differently, by instead changing the signatore of those
"functions" to take a "volatile struct timeval*" instead of a
"struct timeval*". Many places, these functions are called with
&time, and time is declared as volatile in <sys/kernel.h>. This
way we can get rid of all the ugly casts which now also triggered
warnings, and caused more code to be added to work around the
problem.

Reviewed by thorpej.
 1.16 29-Dec-2004  bjh21 If clock_ymdhms_to_secs() fails, return ERANGE. This gets my ELC with
a broken NVRAM to boot cleanly.
 1.15 05-Jul-2004  pk settime: round, instead of truncate, to the nearest second.
 1.14 01-Mar-2004  kleink Back out previous.
 1.13 01-Mar-2004  kleink Cosmetics; add missing newline to autoconf output.
 1.12 01-Nov-2003  tsutsui Cleanup MI mk48txx(4) todclock driver:
- Prepare mk48txxvar.h and leave only register definitions in mk48txxreg.h.
- Define struct mk48txx_softc as usual devices and allocate necessary
members like struct todr_chip_handle in it.
- Change mk48txx_attach(), mk48txx_nvwr() and mk48txx_nvrd() to take
struct mk48txx_softc.
 1.11 30-Oct-2003  matt Fix uninitialized warning.
 1.10 23-Feb-2002  scw branches: 1.10.16;
Allow MD code to provide functions for reading/writing NVRAM/RTC
locations. If passed NULL, the old behaviour using bus_space_{read,write}_1()
is used. Otherwise, all access to the chip goes via the MD functions.

This is necessary for mvmeppc boards where the mk48txx NVRAM/RTC is not
directly addressable.
 1.9 06-Dec-2001  kleink Recognize the MK48T18 as well (differs from the MK48T08 only in packaging
options and voltages).
 1.8 13-Nov-2001  lukem add/cleanup RCSID
 1.7 08-Apr-2001  tsutsui branches: 1.7.2;
Correct values for sanity checks.
 1.6 11-Nov-2000  pk branches: 1.6.2; 1.6.4;
Change `nvram size' data type to `bus_size_t'.
 1.5 11-Nov-2000  pk Add a function to retrieve the size of the on-chip NVRAM area.
 1.4 04-Oct-2000  tsutsui Enable sanity checks in mk48txx_gettime().
(Many news68k have dead NVRAM.)
 1.3 03-Oct-2000  tsutsui 1970 -> POSIX_BASE_YEAR
 1.2 01-Sep-2000  eeh Add support for write protecting clock registers.
 1.1 25-Jul-2000  pk New time-of-day clock chip drivers. These implement the todr(9) interface.
 1.6.4.4 28-Feb-2002  nathanw Catch up to -current.
 1.6.4.3 08-Jan-2002  nathanw Catch up to -current.
 1.6.4.2 14-Nov-2001  nathanw Catch up to -current.
 1.6.4.1 09-Apr-2001  nathanw Catch up with -current.
 1.6.2.4 21-Apr-2001  bouyer Sync with HEAD
 1.6.2.3 22-Nov-2000  bouyer Sync with HEAD.
 1.6.2.2 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.6.2.1 11-Nov-2000  bouyer file mk48txx.c was added on branch thorpej_scsipi on 2000-11-20 11:40:45 +0000
 1.7.2.2 16-Mar-2002  jdolecek Catch up with -current.
 1.7.2.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.10.16.5 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.10.16.4 17-Jan-2005  skrll Sync with HEAD.
 1.10.16.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.10.16.2 18-Sep-2004  skrll Sync with HEAD.
 1.10.16.1 03-Aug-2004  skrll Sync with HEAD
 1.17.2.3 21-Jan-2008  yamt sync with head
 1.17.2.2 27-Oct-2007  yamt sync with head.
 1.17.2.1 30-Dec-2006  yamt sync with head.
 1.18.8.1 14-Sep-2006  yamt sync with head.
 1.18.4.1 09-Sep-2006  rpaulo sync with head
 1.20.4.1 22-Oct-2006  yamt sync with head
 1.20.2.1 18-Nov-2006  ad Sync with head.
 1.21.28.1 25-Oct-2007  bouyer Sync with HEAD.
 1.21.24.2 23-Mar-2008  matt sync with HEAD
 1.21.24.1 06-Nov-2007  matt sync with HEAD
 1.21.22.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.21.8.1 23-Oct-2007  ad Sync with head.
 1.22.8.1 10-Jan-2008  bouyer Sync with HEAD
 1.22.2.1 18-Feb-2008  mjf Sync with HEAD.
 1.24.10.1 16-May-2008  yamt sync with head.
 1.24.8.1 18-May-2008  yamt sync with head.
 1.24.6.1 02-Jun-2008  mjf Sync with HEAD.
 1.25.26.1 07-Jan-2011  matt Add DS1553 support
 1.25.22.1 05-Mar-2011  rmind sync with head
 1.26.18.1 03-Dec-2017  jdolecek update from HEAD
 1.27.20.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.11 04-Jan-2011  matt Make this support the DS1553 as well. Add support for the centry reg which
newer RTCs seem to have.
 1.10 28-Apr-2008  martin branches: 1.10.22; 1.10.26;
Remove clause 3 and 4 from TNF licenses
 1.9 11-Dec-2005  christos branches: 1.9.70; 1.9.72; 1.9.74;
merge ktrace-lwp.
 1.8 30-Dec-2004  bjh21 Since I've got the datasheets in front of me, add #defines for the missing
registers in the supported MK48Txx chips.
 1.7 01-Nov-2003  tsutsui Cleanup MI mk48txx(4) todclock driver:
- Prepare mk48txxvar.h and leave only register definitions in mk48txxreg.h.
- Define struct mk48txx_softc as usual devices and allocate necessary
members like struct todr_chip_handle in it.
- Change mk48txx_attach(), mk48txx_nvwr() and mk48txx_nvrd() to take
struct mk48txx_softc.
 1.6 23-Feb-2002  scw branches: 1.6.16;
Allow MD code to provide functions for reading/writing NVRAM/RTC
locations. If passed NULL, the old behaviour using bus_space_{read,write}_1()
is used. Otherwise, all access to the chip goes via the MD functions.

This is necessary for mvmeppc boards where the mk48txx NVRAM/RTC is not
directly addressable.
 1.5 06-Dec-2001  kleink Recognize the MK48T18 as well (differs from the MK48T08 only in packaging
options and voltages).
 1.4 11-Nov-2000  pk branches: 1.4.2; 1.4.4; 1.4.6;
Change `nvram size' data type to `bus_size_t'.
 1.3 11-Nov-2000  pk Add a function to retrieve the size of the on-chip NVRAM area.
 1.2 03-Oct-2000  tsutsui Typo in comment.
 1.1 25-Jul-2000  pk New time-of-day clock chip drivers. These implement the todr(9) interface.
 1.4.6.2 16-Mar-2002  jdolecek Catch up with -current.
 1.4.6.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.4.4.2 28-Feb-2002  nathanw Catch up to -current.
 1.4.4.1 08-Jan-2002  nathanw Catch up to -current.
 1.4.2.3 22-Nov-2000  bouyer Sync with HEAD.
 1.4.2.2 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.4.2.1 11-Nov-2000  bouyer file mk48txxreg.h was added on branch thorpej_scsipi on 2000-11-20 11:40:45 +0000
 1.6.16.4 17-Jan-2005  skrll Sync with HEAD.
 1.6.16.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.6.16.2 18-Sep-2004  skrll Sync with HEAD.
 1.6.16.1 03-Aug-2004  skrll Sync with HEAD
 1.9.74.1 16-May-2008  yamt sync with head.
 1.9.72.1 18-May-2008  yamt sync with head.
 1.9.70.1 02-Jun-2008  mjf Sync with HEAD.
 1.10.26.1 07-Jan-2011  matt Add DS1553 support
 1.10.22.1 05-Mar-2011  rmind sync with head
 1.7 04-Jan-2011  matt Make this support the DS1553 as well. Add support for the centry reg which
newer RTCs seem to have.
 1.6 28-Apr-2008  martin branches: 1.6.22; 1.6.26;
Remove clause 3 and 4 from TNF licenses
 1.5 29-Mar-2008  tsutsui branches: 1.5.2; 1.5.4;
Fix wrong type.
 1.4 28-Mar-2008  tsutsui Split device_t and softc for MI mk48txx(4) and intersil7170(4) clocks,
and other related misc cosmetics.
 1.3 01-Oct-2006  tsutsui branches: 1.3.48;
u_int8_t -> uint8_t
 1.2 11-Dec-2005  christos branches: 1.2.20; 1.2.22;
merge ktrace-lwp.
 1.1 01-Nov-2003  tsutsui branches: 1.1.4; 1.1.18;
Cleanup MI mk48txx(4) todclock driver:
- Prepare mk48txxvar.h and leave only register definitions in mk48txxreg.h.
- Define struct mk48txx_softc as usual devices and allocate necessary
members like struct todr_chip_handle in it.
- Change mk48txx_attach(), mk48txx_nvwr() and mk48txx_nvrd() to take
struct mk48txx_softc.
 1.1.18.1 30-Dec-2006  yamt sync with head.
 1.1.4.4 21-Sep-2004  skrll Fix the sync with head I botched.
 1.1.4.3 18-Sep-2004  skrll Sync with HEAD.
 1.1.4.2 03-Aug-2004  skrll Sync with HEAD
 1.1.4.1 01-Nov-2003  skrll file mk48txxvar.h was added on branch ktrace-lwp on 2004-08-03 10:46:17 +0000
 1.2.22.1 22-Oct-2006  yamt sync with head
 1.2.20.1 18-Nov-2006  ad Sync with head.
 1.3.48.2 02-Jun-2008  mjf Sync with HEAD.
 1.3.48.1 03-Apr-2008  mjf Sync with HEAD.
 1.5.4.1 16-May-2008  yamt sync with head.
 1.5.2.1 18-May-2008  yamt sync with head.
 1.6.26.1 07-Jan-2011  matt Add DS1553 support
 1.6.22.1 05-Mar-2011  rmind sync with head
 1.70 07-Aug-2021  thorpej Merge thorpej-cfargs2.
 1.69 24-Apr-2021  thorpej branches: 1.69.8;
Merge thorpej-cfargs branch:

Simplify and make extensible the config_search() / config_found() /
config_attach() interfaces: rather than having different variants for
which arguments you want pass along, just have a single call that
takes a variadic list of tag-value arguments.

Adjust all call sites:
- Simplify wherever possible; don't pass along arguments that aren't
actually needed.
- Don't be explicit about what interface attribute is attaching if
the device only has one. (More simplification.)
- Add a config_probe() function to be used in indirect configuiration
situations, making is visibly easier to see when indirect config is
in play, and allowing for future change in semantics. (As of now,
this is just a wrapper around config_match(), but that is an
implementation detail.)

Remove unnecessary or redundant interface attributes where they're not
needed.

There are currently 5 "cfargs" defined:
- CFARG_SUBMATCH (submatch function for direct config)
- CFARG_SEARCH (search function for indirect config)
- CFARG_IATTR (interface attribte)
- CFARG_LOCATORS (locators array)
- CFARG_DEVHANDLE (devhandle_t - wraps OFW, ACPI, etc. handles)

...and a sentinel value CFARG_EOL.

Add some extra sanity checking to ensure that interface attributes
aren't ambiguous.

Use CFARG_DEVHANDLE in MI FDT, OFW, and ACPI code, and macppc and shark
ports to associate those device handles with device_t instance. This
will trickle trough to more places over time (need back-end for pre-OFW
Sun OBP; any others?).
 1.68 10-Nov-2019  chs branches: 1.68.10;
in many device attach paths, allocate memory with M_WAITOK instead of M_NOWAIT
and remove code to handle failures that can no longer happen.
 1.67 03-Sep-2018  riastradh Rename min/max -> uimin/uimax for better honesty.

These functions are defined on unsigned int. The generic name
min/max should not silently truncate to 32 bits on 64-bit systems.
This is purely a name change -- no functional change intended.

HOWEVER! Some subsystems have

#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))

even though our standard name for that is MIN/MAX. Although these
may invite multiple evaluation bugs, these do _not_ cause integer
truncation.

To avoid `fixing' these cases, I first changed the name in libkern,
and then compile-tested every file where min/max occurred in order to
confirm that it failed -- and thus confirm that nothing shadowed
min/max -- before changing it.

I have left a handful of bootloaders that are too annoying to
compile-test, and some dead code:

cobalt ews4800mips hp300 hppa ia64 luna68k vax
acorn32/if_ie.c (not included in any kernels)
macppc/if_gm.c (superseded by gem(4))

It should be easy to fix the fallout once identified -- this way of
doing things fails safe, and the goal here, after all, is to _avoid_
silent integer truncations, not introduce them.

Maybe one day we can reintroduce min/max as type-generic things that
never silently truncate. But we should avoid doing that for a while,
so that existing code has a chance to be detected by the compiler for
conversion to uimin/uimax without changing the semantics until we can
properly audit it all. (Who knows, maybe in some cases integer
truncation is actually intended!)
 1.66 28-Oct-2017  riastradh branches: 1.66.2; 1.66.4;
Kill some more extern struct cfdriver declarations.

Down with externs in .c!
 1.65 27-Sep-2016  pgoyette branches: 1.65.6;
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).
 1.64 14-Jul-2016  msaitoh branches: 1.64.2;
- Use aprint*() more in xxx_attach().
- Add missing aprint_naive("\n").
- Remove extra spaces and tabs.
- KNF.
 1.63 07-Jul-2016  msaitoh KNF. Remove extra spaces. No functional change.
 1.62 25-Jul-2014  dholland branches: 1.62.4;
Add d_discard to all struct cdevsw instances I could find.

All have been set to "nodiscard"; some should get a real implementation.
 1.61 16-Mar-2014  dholland branches: 1.61.2;
Change (mostly mechanically) every cdevsw/bdevsw I can find to use
designated initializers.

I have not built every extant kernel so I have probably broken at
least one build; however I've also found and fixed some wrong
cdevsw/bdevsw entries so even if so I think we come out ahead.
 1.60 27-Oct-2012  chs branches: 1.60.2;
split device_t/softc for all remaining drivers.
replace "struct device *" with "device_t".
use device_xname(), device_unit(), etc.
 1.59 13-Nov-2010  uebayasi branches: 1.59.8; 1.59.18;
Don't pull in the whole uvm(9) API to access only PAGE_SIZE and
some other constants. These are provided by sys/param.h now.
 1.58 16-Jan-2009  mhitch branches: 1.58.6;
When checking drive status, bump the pointer to the previous status
rather than using just drive 0 status. Another drive with a different
status would cause the previous status state to flip-flop and repeatedly
output state change messages.
 1.57 09-Sep-2008  tron branches: 1.57.2;
Complete device_t/softc split for the ld(4) attachments. This should
prevent crashes while attaching a drive.

Patch supplied by Juan RP in PR kern/39468.
 1.56 08-Jun-2008  tsutsui branches: 1.56.4;
Replace device_lookup() with device_lookup_private() on getting softc
for future device_t/softc spilt.
 1.55 28-Apr-2008  martin branches: 1.55.2;
Remove clause 3 and 4 from TNF licenses
 1.54 08-Apr-2008  cegger branches: 1.54.2; 1.54.4;
use aprint_*_dev and device_xname
 1.53 19-Oct-2007  ad branches: 1.53.16;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.52 09-Jul-2007  ad branches: 1.52.6; 1.52.8; 1.52.12;
Merge some of the less invasive changes from the vmlocking branch:

- kthread, callout, devsw API changes
- select()/poll() improvements
- miscellaneous MT safety improvements
 1.51 04-Mar-2007  christos branches: 1.51.2; 1.51.4;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.50 18-Feb-2007  tsutsui No need to specify BUS_DMA_ALLOCNOW for sglist map
since it will never be unloaded anyway.
 1.49 02-Dec-2006  elad branches: 1.49.2;
Change kauth(9) KPI for kauth_authorize_device_passthru() to add another
argument, u_long, serving as a bit-mask of generic requests for the
passthru request.

Discussed on tech-security@ and tech-kern@. Okay tls@.
 1.48 16-Nov-2006  christos branches: 1.48.2;
__unused removal on arguments; approved by core.
 1.47 08-Nov-2006  elad Replace securelevel checks with kauth(9) calls.
 1.46 12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.45 02-Sep-2006  christos branches: 1.45.2; 1.45.4;
- fix incomplete initializer
- static goes first
 1.44 23-Aug-2006  christos Acting as Elad's keyboard:

Place the securelevel checks in their logical locations.
This will be clearer in the future when code changes to use kauth(9) calls.

input and okay ad@
 1.43 07-Jun-2006  kardel merge FreeBSD timecounters from branch simonb-timecounters
- struct timeval time is gone
time.tv_sec -> time_second
- struct timeval mono_time is gone
mono_time.tv_sec -> time_uptime
- access to time via
{get,}{micro,nano,bin}time()
get* versions are fast but less precise
- support NTP nanokernel implementation (NTP API 4)
- further reading:
Timecounter Paper: http://phk.freebsd.dk/pubs/timecounter.pdf
NTP Nanokernel: http://www.eecis.udel.edu/~mills/ntp/html/kern.html
 1.42 14-Apr-2006  christos branches: 1.42.2;
Coverity CID 720: Remove dead code.
 1.41 14-Apr-2006  christos Coverity CID 1091: Avoid NULL deref by moving offending code inside if
statement.
 1.40 14-Apr-2006  christos Coverity CID 1092: Get the status earlier to avoid NULL deref.
 1.39 25-Mar-2006  thorpej Use device_parent().
 1.38 24-Dec-2005  perry branches: 1.38.4; 1.38.6; 1.38.8; 1.38.10; 1.38.12;
__inline__ -> inline
 1.37 11-Dec-2005  christos merge ktrace-lwp.
 1.36 25-Aug-2005  drochner kill a number of autoconf submatch functions which follow the
standard scheme:
if (<configured> != <wildcard> && <configured> != <real>)
then fail
else
ask device match function

This is handled by config_stdsubmatch() now.
 1.35 25-Aug-2005  drochner replace the "locdesc_t" structure carrying the number of locators
explicitely by a plain integer array
the length in now known to all relevant parties, so this avoids
duplication of information, and we can allocate that thing in
drivers without hacks
 1.34 30-Jul-2005  mhitch The handler for the periodic ENQUIRY command was not unmapping the ccb
data buffer, which left stale flags which caused Alpha ES40 crashes. Add
the mlx_ccb_unmap() call and the ES40 now runs with > 1GB memory.
 1.33 30-May-2005  christos branches: 1.33.2;
- add missing const
- fix variable shadowing
- remove unneeded casts
 1.32 27-Feb-2005  perry branches: 1.32.2;
nuke trailing whitespace
 1.31 28-Oct-2004  yamt branches: 1.31.4; 1.31.6;
move buffer queue related stuffs from buf.h to their own header, bufq.h.
 1.30 13-Sep-2004  drochner a round of autoconf cleanup:
-convert submatch() style functions (passed to config_search() or
config_found_sm()) to the locator passing variants
-pass interface attributes in some cases
-make submatch() functions look uniformly as far as possible
-avoid macros which just hide cfdata members, and reduce dependencies
on "locators.h"
 1.29 22-Apr-2004  itojun sprintf -> snprintf
 1.28 29-Jun-2003  fvdl branches: 1.28.2;
Back out the lwp/ktrace changes. They contained a lot of colateral damage,
and need to be examined and discussed more.
 1.27 28-Jun-2003  darrenr Pass lwp pointers throughtout the kernel, as required, so that the lwpid can
be inserted into ktrace records. The general change has been to replace
"struct proc *" with "struct lwp *" in various function prototypes, pass
the lwp through and use l_proc to get the process pointer when needed.

Bump the kernel rev up to 1.6V
 1.26 01-Jan-2003  thorpej Use aprint_normal() in cfprint routines.
 1.25 23-Oct-2002  jdolecek merge kqueue branch into -current

kqueue provides a stateful and efficient event notification framework
currently supported events include socket, file, directory, fifo,
pipe, tty and device changes, and monitoring of processes and signals

kqueue is supported by all writable filesystems in NetBSD tree
(with exception of Coda) and all device drivers supporting poll(2)

based on work done by Jonathan Lemon for FreeBSD
initial NetBSD port done by Luke Mewburn and Jason Thorpe
 1.24 08-Oct-2002  ad Fix pasto.
 1.23 06-Oct-2002  kristerw Do not free uninitialize pointers.
Do not try to print with uninitialized format-string pointers.
 1.22 27-Sep-2002  thorpej Introduce a new routine, config_match(), which invokes the
cfattach->ca_match function in behalf of the caller. Use it
rather than invoking cfattach->ca_match directly.
 1.21 22-Sep-2002  ad - Fix a command accounting bug.
- Don't use ID 0, since 1.x firmware may not like it.
 1.20 06-Sep-2002  gehenna Merge the gehenna-devsw branch into the trunk.

This merge changes the device switch tables from static array to
dynamically generated by config(8).

- All device switches is defined as a constant structure in device drivers.

- The new grammer ``device-major'' is introduced to ``files''.

device-major <prefix> char <num> [block <num>] [<rules>]

- All device major numbers must be listed up in port dependent majors.<arch>
by using this grammer.

- Added the new naming convention.
The name of the device switch must be <prefix>_[bc]devsw for auto-generation
of device switch tables.

- The backward compatibility of loading block/character device
switch by LKM framework is broken. This is necessary to convert
from block/character device major to device name in runtime and vice versa.

- The restriction to assign device major by LKM is completely removed.
We don't need to reserve LKM entries for dynamic loading of device switch.

- In compile time, device major numbers list is packed into the kernel and
the LKM framework will refer it to assign device major number dynamically.
 1.19 26-Aug-2002  ad Add an ioctl to retrieve basic controller information.
 1.18 26-Aug-2002  ad Handle aincent firmware as found on EISA/MCA boards. Untested.
 1.17 01-Jun-2002  lukem SIMPLEQ rototill:
- implement SIMPLEQ_REMOVE(head, elm, type, field). whilst it's O(n),
this mirrors the functionality of SLIST_REMOVE() (the other
singly-linked list type) and FreeBSD's STAILQ_REMOVE()
- remove the unnecessary elm arg from SIMPLEQ_REMOVE_HEAD().
this mirrors the functionality of SLIST_REMOVE_HEAD() (the other
singly-linked list type) and FreeBSD's STAILQ_REMOVE_HEAD()
- remove notes about SIMPLEQ not supporting arbitrary element removal
- use SIMPLEQ_FOREACH() instead of home-grown for loops
- use SIMPLEQ_EMPTY() appropriately
- use SIMPLEQ_*() instead of accessing sqh_first,sqh_last,sqe_next directly
- reorder manual page; be consistent about how the types are listed
- other minor cleanups
 1.16 23-Apr-2002  ad branches: 1.16.2; 1.16.4;
MLX_GET_SYSDRIVE expects the unit number returned in *arg. Should fix PR
14116.
 1.15 13-Nov-2001  lukem add/cleanup RCSID
 1.14 18-Sep-2001  wiz branches: 1.14.4;
Give initiali[sz]e all the "i"s it deserves.
 1.13 05-Aug-2001  jdolecek branches: 1.13.2;
Allow max. MAXPHYS sized mu_datasize for user command.
Reviewed by Andrew Doran <ad@NetBSD.org>.
 1.12 26-Jul-2001  ad - Stop the system drive status check when re-configuring in order to
avoid a issuing a possibly spurious warning.
- Squash some nits.
 1.11 19-Jul-2001  thorpej Use BUS_DMA_READ and BUS_DMA_WRITE in some obvious places.
 1.10 10-Jun-2001  ad branches: 1.10.2;
Don't make assumptions about the contents of the system drive table.
 1.9 15-May-2001  ad Correct arguments to bus_dmamap_create(), and add a reset routine for the v3
interface.
 1.8 06-May-2001  ad Make provision for resetting the board at start-up.
 1.7 30-Apr-2001  lukem remove trigraph
 1.6 09-Apr-2001  ad - Some firmware fills the system drive table with junk, so get the number
of system drives from an ENQUIRY.
- Complain if there's more than 1 segment when issuing some kind of enquiry
(this needs to be fixed properly).
- Fix the ID hack for 2.xx firmware.
- Fix an argument to bus_dmamap_sync().
 1.5 07-Mar-2001  thorpej Add BUS_DMA_STREAMING to data transfer maps.
 1.4 12-Feb-2001  ad branches: 1.4.2;
Don't put the request onto the `worklist' in ccb_submit(), since it may
still be on the pending queue.
 1.3 06-Feb-2001  ad branches: 1.3.2;
Squash some nits.
 1.2 05-Feb-2001  enami Include uvm/uvm_extern.h to pull in the definition of PAGE_SIZE.
 1.1 04-Feb-2001  ad Add a driver for the Mylex DAC960 family (including DEC SWXCR).
 1.3.2.4 21-Apr-2001  bouyer Sync with HEAD
 1.3.2.3 12-Mar-2001  bouyer Sync with HEAD.
 1.3.2.2 11-Feb-2001  bouyer Sync with HEAD.
 1.3.2.1 06-Feb-2001  bouyer file mlx.c was added on branch thorpej_scsipi on 2001-02-11 19:15:33 +0000
 1.4.2.11 03-Jan-2003  thorpej Sync with HEAD.
 1.4.2.10 11-Nov-2002  nathanw Catch up to -current
 1.4.2.9 18-Oct-2002  nathanw Catch up to -current.
 1.4.2.8 17-Sep-2002  nathanw Catch up to -current.
 1.4.2.7 27-Aug-2002  nathanw Catch up to -current.
 1.4.2.6 20-Jun-2002  nathanw Catch up to -current.
 1.4.2.5 14-Nov-2001  nathanw Catch up to -current.
 1.4.2.4 21-Sep-2001  nathanw Catch up to -current.
 1.4.2.3 24-Aug-2001  nathanw Catch up with -current.
 1.4.2.2 21-Jun-2001  nathanw Catch up to -current.
 1.4.2.1 09-Apr-2001  nathanw Catch up with -current.
 1.10.2.6 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.10.2.5 06-Sep-2002  jdolecek sync kqueue branch with HEAD
 1.10.2.4 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.10.2.3 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.10.2.2 25-Aug-2001  thorpej Merge Aug 24 -current into the kqueue branch.
 1.10.2.1 03-Aug-2001  lukem update to -current
 1.13.2.3 01-Oct-2001  fvdl Catch up with -current.
 1.13.2.2 26-Sep-2001  fvdl * add a VCLONED vnode flag that indicates a vnode representing a cloned
device.
* rename REVOKEALL to REVOKEALIAS, and add a REVOKECLONE flag, to pass
to VOP_REVOKE
* the revoke system call will revoke all aliases, as before, but not the
clones
* vdevgone is called when detaching a device, so make it use REVOKECLONE
to get rid of all clones as well
* clean up all uses of VOP_OPEN wrt. locking.
* add a few VOPS to spec_vnops that need to do something when it's a
clone vnode (access and getattr)
* add a copy of the vnode vattr structure of the original 'master' vnode
to the specinfo of a cloned vnode. could possibly redirect getattr to
the 'master' vnode, but this has issues with revoke
* add a vdev_reassignvp function that disassociates a vnode from its
original device, and reassociates it with the specified dev_t. to be
used by cloning devices only, in case a new minor is allocated.
* change all direct references in drivers to v_devcookie and v_rdev
to vdev_privdata(vp) and vdev_rdev(vp). for diagnostic purposes
when debugging race conditions that still exist wrt. locking and
revoking vnodes.
* make the locking state of a vnode consistent when passed to
d_open and d_close (unlocked). locked would be better, but has
some deadlock issues
 1.13.2.1 07-Sep-2001  thorpej Commit my "devvp" changes to the thorpej-devvp branch. This
replaces the use of dev_t in most places with a struct vnode *.

This will form the basic infrastructure for real cloning device
support (besides being architecurally cleaner -- it'll be good
to get away from using numbers to represent objects).
 1.14.4.2 25-Oct-2001  he Pull up revisions 1.1-1.13 (new, via patch, requested by ad):
Add Mylex DACC960, CAC-EISA, and I2O block/SCSI drivers.
 1.14.4.1 18-Sep-2001  he file mlx.c was added on branch netbsd-1-5 on 2001-10-25 18:03:39 +0000
 1.16.4.1 28-Jul-2003  he Pull up revisions 1.18-1.19,1.21 (requested by ad in ticket #1128):
Improve stability of the mlx driver.
o Better handling of old firmware
o Use correct mailbox length, fixes PR#14266
 1.16.2.3 29-Aug-2002  gehenna catch up with -current.
 1.16.2.2 20-Jun-2002  gehenna catch up with -current.
 1.16.2.1 16-May-2002  gehenna Add the character device switch.
 1.28.2.7 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.28.2.6 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.28.2.5 02-Nov-2004  skrll Sync with HEAD.
 1.28.2.4 21-Sep-2004  skrll Fix the sync with head I botched.
 1.28.2.3 18-Sep-2004  skrll Sync with HEAD.
 1.28.2.2 03-Aug-2004  skrll Sync with HEAD
 1.28.2.1 02-Jul-2003  darrenr Apply the aborted ktrace-lwp changes to a specific branch. This is just for
others to review, I'm concerned that patch fuziness may have resulted in some
errant code being generated but I'll look at that later by comparing the diff
from the base to the branch with the file I attempt to apply to it. This will,
at the very least, put the changes in a better context for others to review
them and attempt to tinker with removing passing of 'struct lwp' through
the kernel.
 1.31.6.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.31.4.1 29-Apr-2005  kent sync with -current
 1.32.2.1 04-Aug-2005  tron Pull up revision 1.34 (requested by thorpej in ticket #636):
The handler for the periodic ENQUIRY command was not unmapping the ccb
data buffer, which left stale flags which caused Alpha ES40 crashes. Add
the mlx_ccb_unmap() call and the ES40 now runs with > 1GB memory.
 1.33.2.5 27-Oct-2007  yamt sync with head.
 1.33.2.4 03-Sep-2007  yamt sync with head.
 1.33.2.3 26-Feb-2007  yamt sync with head.
 1.33.2.2 30-Dec-2006  yamt sync with head.
 1.33.2.1 21-Jun-2006  yamt sync with head.
 1.38.12.2 24-May-2006  tron Merge 2006-05-24 NetBSD-current into the "peter-altq" branch.
 1.38.12.1 28-Mar-2006  tron Merge 2006-03-28 NetBSD-current into the "peter-altq" branch.
 1.38.10.1 19-Apr-2006  elad sync with head.
 1.38.8.4 03-Sep-2006  yamt sync with head.
 1.38.8.3 26-Jun-2006  yamt sync with head.
 1.38.8.2 24-May-2006  yamt sync with head.
 1.38.8.1 01-Apr-2006  yamt sync with head.
 1.38.6.2 22-Apr-2006  simonb Sync with head.
 1.38.6.1 04-Feb-2006  simonb Adapt for timecounters: mostly use get*time() and use "time_second"
instead of "time.tv_sec".
 1.38.4.1 09-Sep-2006  rpaulo sync with head
 1.42.2.1 19-Jun-2006  chap Sync with head.
 1.45.4.2 10-Dec-2006  yamt sync with head.
 1.45.4.1 22-Oct-2006  yamt sync with head
 1.45.2.2 12-Jan-2007  ad Sync with head.
 1.45.2.1 18-Nov-2006  ad Sync with head.
 1.48.2.1 04-Dec-2006  tron Pull up following revision(s) (requested by elad in ticket #247):
sys/dev/ic/dpt.c: revision 1.55
sys/dev/pci/amr.c: revision 1.43
sys/secmodel/bsd44/secmodel_bsd44_securelevel.c: revision 1.19
sys/dev/pci/mly.c: revision 1.33
share/man/man9/kauth.9: revision 1.37
sys/dev/ic/mlx.c: revision 1.49
sys/dev/ic/icp_ioctl.c: revision 1.14
sys/dev/i2o/iop.c: revision 1.62
sys/dev/pci/twe.c: revision 1.82
sys/sys/kauth.h: revision 1.25
sys/dev/i2o/dpti.c: revision 1.31
sys/kern/kern_auth.c: revision 1.33
sys/dev/tc/stic.c: revision 1.37
Change kauth(9) KPI for kauth_authorize_device_passthru() to add another
argument, u_long, serving as a bit-mask of generic requests for the
passthru request.
Discussed on tech-security@ and tech-kern@. Okay tls@.
 1.49.2.2 12-Mar-2007  rmind Sync with HEAD.
 1.49.2.1 27-Feb-2007  yamt - sync with head.
- move sched_changepri back to kern_synch.c as it doesn't know PPQ anymore.
 1.51.4.1 11-Jul-2007  mjf Sync with head.
 1.51.2.4 23-Oct-2007  ad Sync with head.
 1.51.2.3 13-May-2007  ad - Pass the error number and residual count to biodone(), and let it handle
setting error indicators. Prepare to eliminate B_ERROR.
- Add a flag argument to brelse() to be set into the buf's flags, instead
of doing it directly. Typically used to set B_INVAL.
- Add a "struct cpu_info *" argument to kthread_create(), to be used to
create bound threads. Change "bool mpsafe" to "int flags".
- Allow exit of LWPs in the IDL state when (l != curlwp).
- More locking fixes & conversion to the new API.
 1.51.2.2 10-Apr-2007  ad Nuke the deferred kthread creation stuff, as it's no longer needed.
Pointed out by thorpej@.
 1.51.2.1 09-Apr-2007  ad - Add two new arguments to kthread_create1: pri_t pri, bool mpsafe.
- Fork kthreads off proc0 as new LWPs, not new processes.
 1.52.12.1 25-Oct-2007  bouyer Sync with HEAD.
 1.52.8.1 06-Nov-2007  matt sync with HEAD
 1.52.6.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.53.16.4 17-Jan-2009  mjf Sync with HEAD.
 1.53.16.3 28-Sep-2008  mjf Sync with HEAD.
 1.53.16.2 29-Jun-2008  mjf Sync with HEAD.
 1.53.16.1 02-Jun-2008  mjf Sync with HEAD.
 1.54.4.2 04-May-2009  yamt sync with head.
 1.54.4.1 16-May-2008  yamt sync with head.
 1.54.2.2 17-Jun-2008  yamt sync with head.
 1.54.2.1 18-May-2008  yamt sync with head.
 1.55.2.2 24-Sep-2008  wrstuden Merge in changes between wrstuden-revivesa-base-2 and
wrstuden-revivesa-base-3.
 1.55.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.56.4.1 19-Oct-2008  haad Sync with HEAD.
 1.57.2.1 19-Jan-2009  skrll Sync with HEAD.
 1.58.6.1 05-Mar-2011  rmind sync with head
 1.59.18.3 03-Dec-2017  jdolecek update from HEAD
 1.59.18.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.59.18.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.59.8.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.59.8.1 30-Oct-2012  yamt sync with head
 1.60.2.1 18-May-2014  rmind sync with head
 1.61.2.1 10-Aug-2014  tls Rebase.
 1.62.4.2 05-Oct-2016  skrll Sync with HEAD
 1.62.4.1 09-Jul-2016  skrll Sync with HEAD
 1.64.2.1 04-Nov-2016  pgoyette Sync with HEAD
 1.65.6.1 30-Apr-2017  pgoyette And a few more DEVSW_MODULE_INIT for modular drivers
 1.66.4.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.66.4.1 10-Jun-2019  christos Sync with HEAD
 1.66.2.1 06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.68.10.2 22-Mar-2021  thorpej Audit CFARG_IATTR in config_found() calls, and remove it in situations
where the interface attribute is not ambiguous.
 1.68.10.1 22-Mar-2021  thorpej Mechanical conversion of config_found_sm_loc() -> config_found().
CFARG_IATTR usage needs to be audited.
 1.69.8.1 04-Aug-2021  thorpej Adapt to CFARGS().
 1.4 28-Oct-2017  riastradh Add some #includes to make a few more header files compile.
 1.3 26-Aug-2002  ad branches: 1.3.154;
Add an ioctl to retrieve basic controller information.
 1.2 26-Aug-2002  ad Handle aincent firmware as found on EISA/MCA boards. Untested.
 1.1 04-Feb-2001  ad branches: 1.1.2; 1.1.4; 1.1.6; 1.1.12; 1.1.20; 1.1.22;
Add a driver for the Mylex DAC960 family (including DEC SWXCR).
 1.1.22.1 28-Jul-2003  he Pull up revisions 1.2-1.3 (requested by ad in ticket #1128):
Improve stability of the mlx driver.
o Better handling of old firmware
o Use correct mailbox length, fixes PR#14266
 1.1.20.1 29-Aug-2002  gehenna catch up with -current.
 1.1.12.2 25-Oct-2001  he Pull up revision 1.1 (requested by ad):
Add Mylex DACC960, CAC-EISA, and I2O block/SCSI drivers.
 1.1.12.1 04-Feb-2001  he file mlxio.h was added on branch netbsd-1-5 on 2001-10-25 17:53:59 +0000
 1.1.6.1 06-Sep-2002  jdolecek sync kqueue branch with HEAD
 1.1.4.1 27-Aug-2002  nathanw Catch up to -current.
 1.1.2.2 11-Feb-2001  bouyer Sync with HEAD.
 1.1.2.1 04-Feb-2001  bouyer file mlxio.h was added on branch thorpej_scsipi on 2001-02-11 19:15:34 +0000
 1.3.154.1 03-Dec-2017  jdolecek update from HEAD
 1.8 08-Sep-2008  gmcgarry Replace most gcc-specific __attribute__ uses with BSD-style sys/cdef.h
preprocessor macros.
 1.7 28-Apr-2008  martin branches: 1.7.2; 1.7.6;
Remove clause 3 and 4 from TNF licenses
 1.6 11-Dec-2005  christos branches: 1.6.70; 1.6.72; 1.6.74;
merge ktrace-lwp.
 1.5 27-Feb-2005  perry nuke trailing whitespace
 1.4 31-Aug-2002  ad branches: 1.4.6; 1.4.14; 1.4.16;
Nuke incorrect mailbox length defines and just use 13 everywhere. May help
with PR/14266.
 1.3 26-Jul-2001  ad branches: 1.3.6; 1.3.14; 1.3.16;
- Stop the system drive status check when re-configuring in order to
avoid a issuing a possibly spurious warning.
- Squash some nits.
 1.2 06-May-2001  ad branches: 1.2.2;
Make provision for resetting the board at start-up.
 1.1 04-Feb-2001  ad branches: 1.1.2; 1.1.4;
Add a driver for the Mylex DAC960 family (including DEC SWXCR).
 1.1.4.3 17-Sep-2002  nathanw Catch up to -current.
 1.1.4.2 24-Aug-2001  nathanw Catch up with -current.
 1.1.4.1 21-Jun-2001  nathanw Catch up to -current.
 1.1.2.2 11-Feb-2001  bouyer Sync with HEAD.
 1.1.2.1 04-Feb-2001  bouyer file mlxreg.h was added on branch thorpej_scsipi on 2001-02-11 19:15:34 +0000
 1.2.2.2 06-Sep-2002  jdolecek sync kqueue branch with HEAD
 1.2.2.1 03-Aug-2001  lukem update to -current
 1.3.16.1 28-Jul-2003  he Pull up revision 1.4 (requested by ad in ticket #1128):
Improve stability of the mlx driver.
o Better handling of old firmware
o Use correct mailbox length, fixes PR#14266
 1.3.14.1 31-Aug-2002  gehenna catch up with -current.
 1.3.6.2 25-Oct-2001  he Pull up revisions 1.1-1.3 (requested by ad):
Add Mylex DACC960, CAC-EISA, and I2O block/SCSI drivers.
 1.3.6.1 26-Jul-2001  he file mlxreg.h was added on branch netbsd-1-5 on 2001-10-25 17:54:04 +0000
 1.4.16.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.4.14.1 29-Apr-2005  kent sync with -current
 1.4.6.1 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.6.74.2 04-May-2009  yamt sync with head.
 1.6.74.1 16-May-2008  yamt sync with head.
 1.6.72.1 18-May-2008  yamt sync with head.
 1.6.70.2 28-Sep-2008  mjf Sync with HEAD.
 1.6.70.1 02-Jun-2008  mjf Sync with HEAD.
 1.7.6.1 19-Oct-2008  haad Sync with HEAD.
 1.7.2.1 24-Sep-2008  wrstuden Merge in changes between wrstuden-revivesa-base-2 and
wrstuden-revivesa-base-3.
 1.16 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).
 1.15 27-Oct-2012  chs branches: 1.15.14; 1.15.18;
split device_t/softc for all remaining drivers.
replace "struct device *" with "device_t".
use device_xname(), device_unit(), etc.
 1.14 28-Apr-2008  martin branches: 1.14.34; 1.14.44;
Remove clause 3 and 4 from TNF licenses
 1.13 04-Mar-2007  christos branches: 1.13.36; 1.13.38; 1.13.40;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.12 16-Feb-2006  perry branches: 1.12.20;
Change "inline" back to "__inline" in .h files -- C99 is still too
new, and some apps compile things in C89 mode. C89 keywords stay.

As per core@.
 1.11 24-Dec-2005  perry branches: 1.11.2; 1.11.4; 1.11.6;
__inline__ -> inline
 1.10 11-Dec-2005  christos merge ktrace-lwp.
 1.9 27-Feb-2005  perry branches: 1.9.4;
nuke trailing whitespace
 1.8 13-Sep-2004  drochner branches: 1.8.4; 1.8.6;
a round of autoconf cleanup:
-convert submatch() style functions (passed to config_search() or
config_found_sm()) to the locator passing variants
-pass interface attributes in some cases
-make submatch() functions look uniformly as far as possible
-avoid macros which just hide cfdata members, and reduce dependencies
on "locators.h"
 1.7 22-Sep-2002  ad branches: 1.7.6;
- Fix a command accounting bug.
- Don't use ID 0, since 1.x firmware may not like it.
 1.6 26-Aug-2002  ad Handle aincent firmware as found on EISA/MCA boards. Untested.
 1.5 18-Sep-2001  wiz branches: 1.5.4; 1.5.12; 1.5.14;
Give initiali[sz]e all the "i"s it deserves.
 1.4 26-Jul-2001  ad branches: 1.4.2;
- Stop the system drive status check when re-configuring in order to
avoid a issuing a possibly spurious warning.
- Squash some nits.
 1.3 10-Jun-2001  ad branches: 1.3.2;
Don't make assumptions about the contents of the system drive table.
 1.2 06-May-2001  ad Make provision for resetting the board at start-up.
 1.1 04-Feb-2001  ad branches: 1.1.2; 1.1.4;
Add a driver for the Mylex DAC960 family (including DEC SWXCR).
 1.1.4.5 18-Oct-2002  nathanw Catch up to -current.
 1.1.4.4 27-Aug-2002  nathanw Catch up to -current.
 1.1.4.3 21-Sep-2001  nathanw Catch up to -current.
 1.1.4.2 24-Aug-2001  nathanw Catch up with -current.
 1.1.4.1 21-Jun-2001  nathanw Catch up to -current.
 1.1.2.2 11-Feb-2001  bouyer Sync with HEAD.
 1.1.2.1 04-Feb-2001  bouyer file mlxvar.h was added on branch thorpej_scsipi on 2001-02-11 19:15:34 +0000
 1.3.2.4 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.3.2.3 06-Sep-2002  jdolecek sync kqueue branch with HEAD
 1.3.2.2 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.3.2.1 03-Aug-2001  lukem update to -current
 1.4.2.1 01-Oct-2001  fvdl Catch up with -current.
 1.5.14.1 28-Jul-2003  he Pull up revisions 1.6-1.7 (requested by ad in ticket #1128):
Improve stability of the mlx driver.
o Better handling of old firmware
o Use correct mailbox length, fixes PR#14266
 1.5.12.1 29-Aug-2002  gehenna catch up with -current.
 1.5.4.2 25-Oct-2001  he Pull up revisions 1.1-1.4 (requested by ad):
Add Mylex DACC960, CAC-EISA, and I2O block/SCSI drivers.
 1.5.4.1 18-Sep-2001  he file mlxvar.h was added on branch netbsd-1-5 on 2001-10-25 17:53:51 +0000
 1.7.6.3 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.7.6.2 21-Sep-2004  skrll Fix the sync with head I botched.
 1.7.6.1 18-Sep-2004  skrll Sync with HEAD.
 1.8.6.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.8.4.1 29-Apr-2005  kent sync with -current
 1.9.4.2 03-Sep-2007  yamt sync with head.
 1.9.4.1 21-Jun-2006  yamt sync with head.
 1.11.6.1 22-Apr-2006  simonb Sync with head.
 1.11.4.1 09-Sep-2006  rpaulo sync with head
 1.11.2.1 18-Feb-2006  yamt sync with head.
 1.12.20.1 12-Mar-2007  rmind Sync with HEAD.
 1.13.40.1 16-May-2008  yamt sync with head.
 1.13.38.1 18-May-2008  yamt sync with head.
 1.13.36.1 02-Jun-2008  mjf Sync with HEAD.
 1.14.44.2 03-Dec-2017  jdolecek update from HEAD
 1.14.44.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.14.34.1 30-Oct-2012  yamt sync with head
 1.15.18.1 04-Nov-2016  pgoyette Sync with HEAD
 1.15.14.1 05-Oct-2016  skrll Sync with HEAD
 1.19 07-Sep-2025  thorpej Change todr_chip_handle::cookie -> todr_chip_handle::todr_dev, and
make it a device_t. Upcoming functional changes will require the
device_t associated with a TODR device.

Change todr_chip_handle::bus_cookie -> todr_chip_handle::todr_devaux.
Nothing was using the old field, but I decided to keep it around just
in cause something needs it in the future.

And with these largely mechanical yet semantically meaningful changes,
thus spake the Oracle: "Welcome to NetBSD 11.99.2."
 1.18 07-Sep-2025  thorpej todr_chip_handle::base_time -> todr_chip_handle::todr_base_time

NFCI
 1.17 25-Sep-2022  thorpej Remove unnecessary include of <sys/malloc.h>.
 1.16 20-Nov-2014  christos use the inline bcdtobin and bintobcd directly instead through a macro.
 1.15 25-Jul-2013  msaitoh Clear memory as intended. Fixes PR#46372.
 1.14 12-Dec-2009  tsutsui branches: 1.14.12; 1.14.22; 1.14.26;
Switch to using todr_[gs]ettime_ymdhms() format
which don't require struct timeval details.
Also fix a botch calling MI todr_settime(9) without rtc_offset adjustment.
 1.13 12-Dec-2009  tsutsui Remove `volatile' qualifier from argument types of
struct timeval passed to todr_gettime(9) and todr_settime(9).
We no longer have an ancient and volatile struct timeval `time'
global since we have switched to MI timercounter(9) on all port.

XXX1: some of these RTC drivers still assume 32bit time_t
XXX2: some of these should be rewritten to use todr_[gs]ettime_ymdhms()
XXX3: todr(9) man page doesn't mention todr_[gs]ettime_ymdhms()
 1.12 11-Dec-2009  tsutsui Don't refer garbage in stack.
- An argument of struct timeval *tv passed by todr_gettime(9) is used
for a return value and it doesn't contain valid data. Don't read it.
- Instead, use getmicrotime(9) to get a "reasonable" (i.e. current) time
to see expected year value (which is not kept by this device).
- If current time is not valid, assume this is the first todr_gettime(9)
call from inittodr(9) and use file system time for the "reasonable" year.

Fixes silent hangup after mountroot() on sun2.

XXX: MI todr(9) functions seem to get mangled around year ~22000.
 1.11 06-Jul-2008  tsutsui Split device_t/softc with misc cosmetic changes.
 1.10 28-Apr-2008  martin branches: 1.10.2; 1.10.4;
Remove clause 3 and 4 from TNF licenses
 1.9 19-Oct-2007  ad branches: 1.9.16; 1.9.18; 1.9.20;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.8 04-Sep-2006  gdamore branches: 1.8.12; 1.8.26; 1.8.28; 1.8.32;
Remove unused todr_setcal/todr_getcal and all the assorted stub
implementations.
 1.7 11-Dec-2005  christos branches: 1.7.4; 1.7.8;
merge ktrace-lwp.
 1.6 04-Jun-2005  he branches: 1.6.2;
Fix the various todr_gettime() and todr_settime() fallouts from
-Wcast-qual differently, by instead changing the signatore of those
"functions" to take a "volatile struct timeval*" instead of a
"struct timeval*". Many places, these functions are called with
&time, and time is declared as volatile in <sys/kernel.h>. This
way we can get rid of all the ugly casts which now also triggered
warnings, and caused more code to be added to work around the
problem.

Reviewed by thorpej.
 1.5 27-Feb-2005  perry nuke trailing whitespace
 1.4 04-Feb-2005  perry de-__P
 1.3 13-Nov-2001  lukem branches: 1.3.16; 1.3.24; 1.3.26;
add/cleanup RCSID
 1.2 07-Jul-2001  thorpej branches: 1.2.2;
bzero -> memset
 1.1 10-Apr-2001  fredette branches: 1.1.2; 1.1.4;
Added.
 1.1.4.4 14-Nov-2001  nathanw Catch up to -current.
 1.1.4.3 24-Aug-2001  nathanw Catch up with -current.
 1.1.4.2 21-Jun-2001  nathanw Catch up to -current.
 1.1.4.1 10-Apr-2001  nathanw file mm58167.c was added on branch nathanw_sa on 2001-06-21 20:02:56 +0000
 1.1.2.2 21-Apr-2001  bouyer Sync with HEAD
 1.1.2.1 10-Apr-2001  bouyer file mm58167.c was added on branch thorpej_scsipi on 2001-04-21 17:48:38 +0000
 1.2.2.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.3.26.2 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.3.26.1 12-Feb-2005  yamt sync with head.
 1.3.24.1 29-Apr-2005  kent sync with -current
 1.3.16.3 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.3.16.2 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.3.16.1 04-Feb-2005  skrll Sync with HEAD.
 1.6.2.2 27-Oct-2007  yamt sync with head.
 1.6.2.1 30-Dec-2006  yamt sync with head.
 1.7.8.1 14-Sep-2006  yamt sync with head.
 1.7.4.1 09-Sep-2006  rpaulo sync with head
 1.8.32.1 25-Oct-2007  bouyer Sync with HEAD.
 1.8.28.1 06-Nov-2007  matt sync with HEAD
 1.8.26.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.8.12.1 23-Oct-2007  ad Sync with head.
 1.9.20.3 11-Mar-2010  yamt sync with head
 1.9.20.2 04-May-2009  yamt sync with head.
 1.9.20.1 16-May-2008  yamt sync with head.
 1.9.18.1 18-May-2008  yamt sync with head.
 1.9.16.2 28-Sep-2008  mjf Sync with HEAD.
 1.9.16.1 02-Jun-2008  mjf Sync with HEAD.
 1.10.4.1 18-Jul-2008  simonb Sync with head.
 1.10.2.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.14.26.1 28-Aug-2013  rmind sync with head
 1.14.22.2 03-Dec-2017  jdolecek update from HEAD
 1.14.22.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.14.12.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.6 06-Jul-2008  tsutsui Split device_t/softc with misc cosmetic changes.
 1.5 28-Apr-2008  martin branches: 1.5.2; 1.5.4;
Remove clause 3 and 4 from TNF licenses
 1.4 11-Dec-2005  christos branches: 1.4.70; 1.4.72; 1.4.74;
merge ktrace-lwp.
 1.3 27-Feb-2005  perry nuke trailing whitespace
 1.2 04-Feb-2005  perry de-__P
 1.1 10-Apr-2001  fredette branches: 1.1.2; 1.1.4; 1.1.26; 1.1.34; 1.1.36;
Added.
 1.1.36.2 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.1.36.1 12-Feb-2005  yamt sync with head.
 1.1.34.1 29-Apr-2005  kent sync with -current
 1.1.26.2 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.1.26.1 04-Feb-2005  skrll Sync with HEAD.
 1.1.4.2 21-Jun-2001  nathanw Catch up to -current.
 1.1.4.1 10-Apr-2001  nathanw file mm58167var.h was added on branch nathanw_sa on 2001-06-21 20:02:57 +0000
 1.1.2.2 21-Apr-2001  bouyer Sync with HEAD
 1.1.2.1 10-Apr-2001  bouyer file mm58167var.h was added on branch thorpej_scsipi on 2001-04-21 17:48:38 +0000
 1.4.74.2 04-May-2009  yamt sync with head.
 1.4.74.1 16-May-2008  yamt sync with head.
 1.4.72.1 18-May-2008  yamt sync with head.
 1.4.70.2 28-Sep-2008  mjf Sync with HEAD.
 1.4.70.1 02-Jun-2008  mjf Sync with HEAD.
 1.5.4.1 18-Jul-2008  simonb Sync with head.
 1.5.2.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.2 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.1 04-Mar-2000  elric branches: 1.1.6; 1.1.128; 1.1.130; 1.1.132;
Definition of struct monitor, which contains syncs, and dot clocks.
 1.1.132.1 16-May-2008  yamt sync with head.
 1.1.130.1 18-May-2008  yamt sync with head.
 1.1.128.1 02-Jun-2008  mjf Sync with HEAD.
 1.1.6.2 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.1.6.1 04-Mar-2000  bouyer file monitors.h was added on branch thorpej_scsipi on 2000-11-20 11:40:45 +0000
 1.3 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.2 11-Feb-2002  kleink branches: 1.2.114; 1.2.116; 1.2.118;
Forgot to mention two reserved bits.
 1.1 10-Dec-2001  kleink branches: 1.1.2; 1.1.4;
Add (some) register definitions for the Motorola MPC105 PCI Bridge/Memory
Controller (PCIB/MC).
 1.1.4.3 16-Mar-2002  jdolecek Catch up with -current.
 1.1.4.2 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.1.4.1 10-Dec-2001  thorpej file mpc105reg.h was added on branch kqueue on 2002-01-10 19:54:52 +0000
 1.1.2.3 28-Feb-2002  nathanw Catch up to -current.
 1.1.2.2 08-Jan-2002  nathanw Catch up to -current.
 1.1.2.1 10-Dec-2001  nathanw file mpc105reg.h was added on branch nathanw_sa on 2002-01-08 00:29:59 +0000
 1.2.118.1 16-May-2008  yamt sync with head.
 1.2.116.1 18-May-2008  yamt sync with head.
 1.2.114.1 02-Jun-2008  mjf Sync with HEAD.
 1.5 29-Feb-2024  andvar Fix couple typos in comments.
 1.4 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.3 03-May-2007  nisimura branches: 1.3.2; 1.3.4; 1.3.6; 1.3.16; 1.3.36; 1.3.38; 1.3.40;
fix errors in MCCR1 register
- ROMNAL bit field definition
- ROMFAL comment typo
 1.2 01-May-2007  garbled Convert to using BITS macros, and add some additional defines for
determining ECC/ram types
 1.1 01-May-2007  garbled Add a set of register defines for the MPC106 PCI bridge. Adapted from
the MPC105, and fleshed out with the user manual.
 1.3.40.1 16-May-2008  yamt sync with head.
 1.3.38.1 18-May-2008  yamt sync with head.
 1.3.36.1 02-Jun-2008  mjf Sync with HEAD.
 1.3.16.2 03-Sep-2007  yamt sync with head.
 1.3.16.1 03-May-2007  yamt file mpc106reg.h was added on branch yamt-lazymbuf on 2007-09-03 14:34:57 +0000
 1.3.6.2 11-Jul-2007  mjf Sync with head.
 1.3.6.1 03-May-2007  mjf file mpc106reg.h was added on branch mjf-ufs-trans on 2007-07-11 20:06:02 +0000
 1.3.4.2 09-Jun-2007  ad Sync with head.
 1.3.4.1 03-May-2007  ad file mpc106reg.h was added on branch vmlocking on 2007-06-09 21:37:16 +0000
 1.3.2.2 07-May-2007  yamt sync with head.
 1.3.2.1 03-May-2007  yamt file mpc106reg.h was added on branch yamt-idlelwp on 2007-05-07 10:55:26 +0000
 1.21 23-Sep-2019  skrll Use PRIxBUSADDR
 1.20 21-Sep-2019  kre bus_addt_t is different widths on different archs, so there is no
one simple %?x format that will always work to print it. Cast to
intmax_t and use %jx which should work everywhere.
 1.19 21-Sep-2019  maxv Add __printflike, and fix two incorrect fmts. Reported by the lgtm bot.
 1.18 30-Jan-2018  jakllsch branches: 1.18.4;
more-fully initialize mpt_disc_enable
 1.17 27-Sep-2014  jmcneill add bio(4) support
 1.16 18-Mar-2012  martin branches: 1.16.2; 1.16.14;
Split device_t
 1.15 24-May-2011  mrg branches: 1.15.4; 1.15.8; 1.15.10;
for SPI devices, allow platform code to set "scsi-initiator-id" device
property, and if set, use it instead of pfp.PortSCSIID.

on sparc64 systems on "scsi" or "scsi-2" devices, look from our node
up the tree for a "scsi-initiator-id" property, and if present, copy
it into the device properties.

this fixes mpt(4) issues on PRIMEPOWER250 (and probably other) systems.
idea from freebsd r207243/r207287, but reworked to use our device
properties instead of platform #ifdefs.


look in "device_type" as well as "name" for "ethernet" or "network",
and also look to see if a "local-mac-address" is set when choosing if
this may be a network device. fixes bge(4) nul ethernet address on
the same PRIMEPOWER250.
 1.14 28-Apr-2010  chs branches: 1.14.2;
add byte-swapping so that this works on BE platforms.
the logic is based on the current freebsd driver.
fixes PR 42870.
 1.13 18-Apr-2009  tsutsui branches: 1.13.2; 1.13.4;
Remove extra whitespace added by a stupid tool.
XXX: more in src/sys/arch
 1.12 18-Mar-2009  cegger bcopy -> memcpy
 1.11 18-Mar-2009  cegger bzero -> memset
 1.10 27-Jul-2007  tron branches: 1.10.30; 1.10.38; 1.10.40; 1.10.42; 1.10.46;
Use the appropriate number of maximum devices for Fibre Channel.
Problem Jarle Greipsland on "current-users" mailing list.
 1.9 27-Jul-2007  tron Add support for newer SAS and similar devices to mpt(4). Tested with
the LSI SAS1064 in a Sun x4200 server.

These enhancements were developed by Garrett D'Amore and contributed
to NetBSD by the TELES AG.
 1.8 04-Mar-2007  christos branches: 1.8.2; 1.8.10;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.7 24-Dec-2005  perry branches: 1.7.24; 1.7.26; 1.7.30;
Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.6 11-Dec-2005  christos merge ktrace-lwp.
 1.5 27-Feb-2005  perry branches: 1.5.2; 1.5.4; 1.5.12; 1.5.14;
nuke trailing whitespace
 1.4 02-Nov-2003  wiz branches: 1.4.8; 1.4.10;
Fix some typos. From Tom Cosgrove via jmc@openbsd.
 1.3 14-Jul-2003  lukem add missing __KERNEL_RCSID()
 1.2 16-Apr-2003  thorpej branches: 1.2.2;
Correctly sync the MPT request buffers, and remove BUS_DMA_COHERENT
from the mapping of those buffers.
 1.1 16-Apr-2003  thorpej Device driver for the LSI Logic Fusion-MPT based SCSI and Fibre Channel
adapters. Currently supports:

* LSI 53c1030 Ultra320 SCSI
* LSI FC909, FC909A, FC919, and FC929 Fibre Channel

Ported from the FreeBSD "mpt" driver, written by Greg Ansley. Thanks
to Frank van der Linden for testing and some bug finding.

This work was sponsored by Wasabi Systems, Inc.
 1.2.2.4 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.2.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.2.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.2.2.1 03-Aug-2004  skrll Sync with HEAD
 1.4.10.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.4.8.1 29-Apr-2005  kent sync with -current
 1.5.14.1 04-Oct-2007  bouyer Pull up following revision(s) (requested by tron in ticket #1822):
sys/dev/ic/mpt_netbsd.c: revision 1.12 via patch
sys/dev/ic/mpt_netbsd.h: revision 1.6 via patch
sys/dev/ic/mpt_mpilib.h: revision 1.3 via patch
sys/dev/ic/mpt.h: revision 1.6 via patch
sys/dev/ic/mpt.c: revisions 1.9, 1.10 via patch
sys/dev/ic/mpt_debug.c: patch
sys/dev/pci/mpt_pci.c: revision 1.11 via patch
sys/dev/pci/pcidevs: patch
sys/dev/pci/pcidevs.h: patch
sys/dev/pci/pcidevs_data.h: patch
Add support for newer SAS and similar devices to mpt(4). Tested with
the LSI SAS1064 in a Sun x4200 server.
These enhancements were developed by Garrett D'Amore and contributed
to NetBSD by the TELES AG.
 1.5.12.1 04-Oct-2007  bouyer Pull up following revision(s) (requested by tron in ticket #1822):
sys/dev/ic/mpt_netbsd.c: revision 1.12 via patch
sys/dev/ic/mpt_netbsd.h: revision 1.6 via patch
sys/dev/ic/mpt_mpilib.h: revision 1.3 via patch
sys/dev/ic/mpt.h: revision 1.6 via patch
sys/dev/ic/mpt.c: revisions 1.9, 1.10 via patch
sys/dev/ic/mpt_debug.c: patch
sys/dev/pci/mpt_pci.c: revision 1.11 via patch
sys/dev/pci/pcidevs: patch
sys/dev/pci/pcidevs.h: patch
sys/dev/pci/pcidevs_data.h: patch
Add support for newer SAS and similar devices to mpt(4). Tested with
the LSI SAS1064 in a Sun x4200 server.
These enhancements were developed by Garrett D'Amore and contributed
to NetBSD by the TELES AG.
 1.5.4.2 03-Sep-2007  yamt sync with head.
 1.5.4.1 21-Jun-2006  yamt sync with head.
 1.5.2.1 13-Sep-2007  bouyer Pull up following revision(s) (requested by tron in ticket #1822):
sys/dev/ic/mpt_netbsd.c: revision 1.12 via patch
sys/dev/ic/mpt_netbsd.h: revision 1.6 via patch
sys/dev/ic/mpt_mpilib.h: revision 1.3 via patch
sys/dev/ic/mpt.h: revision 1.6 via patch
sys/dev/ic/mpt.c: revisions 1.9, 1.10 via patch
sys/dev/ic/mpt_debug.c: patch
sys/dev/pci/mpt_pci.c: revision 1.11 via patch
sys/dev/pci/pcidevs: patch
sys/dev/pci/pcidevs.h: patch
sys/dev/pci/pcidevs_data.h: patch
Add support for newer SAS and similar devices to mpt(4). Tested with
the LSI SAS1064 in a Sun x4200 server.
These enhancements were developed by Garrett D'Amore and contributed
to NetBSD by the TELES AG.
 1.7.30.1 03-Sep-2007  wrstuden Sync w/ NetBSD-4-RC_1
 1.7.26.1 12-Mar-2007  rmind Sync with HEAD.
 1.7.24.2 30-Jul-2007  liamjfoy Pull up following revision(s) (requested by tron in ticket #797):
sys/dev/ic/mpt.c: revision 1.10
Use the appropriate number of maximum devices for Fibre Channel.
Problem Jarle Greipsland on "current-users" mailing list.
 1.7.24.1 30-Jul-2007  liamjfoy Pull up following revision(s) (requested by tron in ticket #797):
sys/dev/ic/mpt_netbsd.c: revision 1.12
sys/dev/ic/mpt_mpilib.h: revision 1.3
sys/dev/ic/mpt.h: revision 1.6
sys/dev/ic/mpt.c: revision 1.9
sys/dev/ic/mpt_netbsd.h: revision 1.6
sys/dev/pci/mpt_pci.c: revision 1.11
doc/CHANGES: revision 1.893
Add support for newer SAS and similar devices to mpt(4). Tested with
the LSI SAS1064 in a Sun x4200 server.
These enhancements were developed by Garrett D'Amore and contributed
to NetBSD by the TELES AG.
Mention support for new hardware in mpt(4).
 1.8.10.1 15-Aug-2007  skrll Sync with HEAD.
 1.8.2.1 20-Aug-2007  ad Sync with HEAD.
 1.10.46.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.10.42.1 02-Dec-2010  snj Pull up following revision(s) (requested by riz in ticket #1487):
sys/dev/ic/mpt.c: revision 1.14
sys/dev/ic/mpt.h: revision 1.7
sys/dev/ic/mpt_debug.c: revision 1.7
sys/dev/ic/mpt_netbsd.c: revision 1.15
add byte-swapping so that this works on BE platforms.
the logic is based on the current freebsd driver.
fixes PR 42870.
 1.10.40.1 28-Apr-2009  skrll Sync with HEAD.
 1.10.38.2 27-Jul-2007  tron Use the appropriate number of maximum devices for Fibre Channel.
Problem Jarle Greipsland on "current-users" mailing list.
 1.10.38.1 27-Jul-2007  tron file mpt.c was added on branch matt-mips64 on 2007-07-27 18:38:14 +0000
 1.10.30.2 11-Aug-2010  yamt sync with head.
 1.10.30.1 04-May-2009  yamt sync with head.
 1.13.4.2 31-May-2011  rmind sync with head
 1.13.4.1 30-May-2010  rmind sync with head
 1.13.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.14.2.1 06-Jun-2011  jruoho Sync with HEAD.
 1.15.10.1 03-Nov-2014  msaitoh Pull up following revision(s) (requested by jmcneill in ticket #1160):
sys/dev/ic/mpt_netbsd.c: revision 1.26-1.31
sys/dev/ic/mpt.c: revision 1.17
share/man/man4/bio.4: revision 1.12
share/man/man4/mpt.4: revision 1.6
sys/dev/ic/mpt.h: revision 1.8
- Add bio(4) support.
- xref mpt(4) in bio(4).
- xref bio(4) in mpt(4).
- show "sd0" instead of "mpt0" for volume device name
- include vendor/product/rev info for volumes and their disks.
- for BIOCDISK_NOVOL, set bd_disknovol=true for any disk not associated with a
volume for BIOCDISK_NOVOL, when setting bd_disknovol=false, also set
bv_volid
 1.15.8.1 05-Apr-2012  mrg sync to latest -current.
 1.15.4.1 17-Apr-2012  yamt sync with head
 1.16.14.1 29-Sep-2014  msaitoh Pull up following revision(s) (requested by jmcneill in ticket #120):
sys/dev/ic/mpt_netbsd.c: revision 1.28
sys/dev/ic/mpt_netbsd.c: revision 1.29
sys/dev/ic/mpt.c: revision 1.17
sys/dev/ic/mpt_netbsd.c: revision 1.30
sys/dev/ic/mpt_netbsd.c: revision 1.31
share/man/man4/bio.4: revision 1.12
share/man/man4/mpt.4: revision 1.6
sys/dev/ic/mpt.h: revision 1.8
sys/dev/ic/mpt_netbsd.c: revision 1.26
sys/dev/ic/mpt_netbsd.c: revision 1.27
- Add bio(4) support.
- xref mpt(4) in bio(4).
- xref bio(4) in mpt(4).
- show "sd0" instead of "mpt0" for volume device name
- include vendor/product/rev info for volumes and their disks.
- implement BIOCDISK_NOVOL
- for BIOCDISK_NOVOL, set bd_disknovol=true for any disk not associated with a
volume for BIOCDISK_NOVOL, when setting bd_disknovol=false, also set
bv_volid
 1.16.2.1 03-Dec-2017  jdolecek update from HEAD
 1.18.4.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.9 10-Nov-2021  msaitoh s/endianess/endianness/
 1.8 27-Sep-2014  jmcneill add bio(4) support
 1.7 28-Apr-2010  chs branches: 1.7.14; 1.7.18; 1.7.34;
add byte-swapping so that this works on BE platforms.
the logic is based on the current freebsd driver.
fixes PR 42870.
 1.6 27-Jul-2007  tron branches: 1.6.30; 1.6.38; 1.6.42; 1.6.52; 1.6.54;
Add support for newer SAS and similar devices to mpt(4). Tested with
the LSI SAS1064 in a Sun x4200 server.

These enhancements were developed by Garrett D'Amore and contributed
to NetBSD by the TELES AG.
 1.5 11-Dec-2005  christos branches: 1.5.24; 1.5.30; 1.5.38; 1.5.40;
merge ktrace-lwp.
 1.4 30-May-2005  christos branches: 1.4.2;
- add missing const
- fix variable shadowing
- remove unneeded casts
 1.3 27-Feb-2005  perry branches: 1.3.2; 1.3.4; 1.3.6;
nuke trailing whitespace
 1.2 08-Jul-2003  itojun branches: 1.2.8; 1.2.10;
function prototype must not have variable name
 1.1 16-Apr-2003  thorpej branches: 1.1.2;
Device driver for the LSI Logic Fusion-MPT based SCSI and Fibre Channel
adapters. Currently supports:

* LSI 53c1030 Ultra320 SCSI
* LSI FC909, FC909A, FC919, and FC929 Fibre Channel

Ported from the FreeBSD "mpt" driver, written by Greg Ansley. Thanks
to Frank van der Linden for testing and some bug finding.

This work was sponsored by Wasabi Systems, Inc.
 1.1.2.5 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.1.2.4 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.1.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.1.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.1.2.1 03-Aug-2004  skrll Sync with HEAD
 1.2.10.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.2.8.1 29-Apr-2005  kent sync with -current
 1.3.6.1 04-Oct-2007  bouyer Pull up following revision(s) (requested by tron in ticket #1822):
sys/dev/ic/mpt_netbsd.c: revision 1.12 via patch
sys/dev/ic/mpt_netbsd.h: revision 1.6 via patch
sys/dev/ic/mpt_mpilib.h: revision 1.3 via patch
sys/dev/ic/mpt.h: revision 1.6 via patch
sys/dev/ic/mpt.c: revisions 1.9, 1.10 via patch
sys/dev/ic/mpt_debug.c: patch
sys/dev/pci/mpt_pci.c: revision 1.11 via patch
sys/dev/pci/pcidevs: patch
sys/dev/pci/pcidevs.h: patch
sys/dev/pci/pcidevs_data.h: patch
Add support for newer SAS and similar devices to mpt(4). Tested with
the LSI SAS1064 in a Sun x4200 server.
These enhancements were developed by Garrett D'Amore and contributed
to NetBSD by the TELES AG.
 1.3.4.1 04-Oct-2007  bouyer Pull up following revision(s) (requested by tron in ticket #1822):
sys/dev/ic/mpt_netbsd.c: revision 1.12 via patch
sys/dev/ic/mpt_netbsd.h: revision 1.6 via patch
sys/dev/ic/mpt_mpilib.h: revision 1.3 via patch
sys/dev/ic/mpt.h: revision 1.6 via patch
sys/dev/ic/mpt.c: revisions 1.9, 1.10 via patch
sys/dev/ic/mpt_debug.c: patch
sys/dev/pci/mpt_pci.c: revision 1.11 via patch
sys/dev/pci/pcidevs: patch
sys/dev/pci/pcidevs.h: patch
sys/dev/pci/pcidevs_data.h: patch
Add support for newer SAS and similar devices to mpt(4). Tested with
the LSI SAS1064 in a Sun x4200 server.
These enhancements were developed by Garrett D'Amore and contributed
to NetBSD by the TELES AG.
 1.3.2.1 13-Sep-2007  bouyer Pull up following revision(s) (requested by tron in ticket #1822):
sys/dev/ic/mpt_netbsd.c: revision 1.12 via patch
sys/dev/ic/mpt_netbsd.h: revision 1.6 via patch
sys/dev/ic/mpt_mpilib.h: revision 1.3 via patch
sys/dev/ic/mpt.h: revision 1.6 via patch
sys/dev/ic/mpt.c: revisions 1.9, 1.10 via patch
sys/dev/ic/mpt_debug.c: patch
sys/dev/pci/mpt_pci.c: revision 1.11 via patch
sys/dev/pci/pcidevs: patch
sys/dev/pci/pcidevs.h: patch
sys/dev/pci/pcidevs_data.h: patch
Add support for newer SAS and similar devices to mpt(4). Tested with
the LSI SAS1064 in a Sun x4200 server.
These enhancements were developed by Garrett D'Amore and contributed
to NetBSD by the TELES AG.
 1.4.2.1 03-Sep-2007  yamt sync with head.
 1.5.40.1 15-Aug-2007  skrll Sync with HEAD.
 1.5.38.1 03-Sep-2007  wrstuden Sync w/ NetBSD-4-RC_1
 1.5.30.1 20-Aug-2007  ad Sync with HEAD.
 1.5.24.1 30-Jul-2007  liamjfoy Pull up following revision(s) (requested by tron in ticket #797):
sys/dev/ic/mpt_netbsd.c: revision 1.12
sys/dev/ic/mpt_mpilib.h: revision 1.3
sys/dev/ic/mpt.h: revision 1.6
sys/dev/ic/mpt.c: revision 1.9
sys/dev/ic/mpt_netbsd.h: revision 1.6
sys/dev/pci/mpt_pci.c: revision 1.11
doc/CHANGES: revision 1.893
Add support for newer SAS and similar devices to mpt(4). Tested with
the LSI SAS1064 in a Sun x4200 server.
These enhancements were developed by Garrett D'Amore and contributed
to NetBSD by the TELES AG.
Mention support for new hardware in mpt(4).
 1.6.54.1 30-May-2010  rmind sync with head
 1.6.52.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.6.42.1 02-Dec-2010  snj Pull up following revision(s) (requested by riz in ticket #1487):
sys/dev/ic/mpt.c: revision 1.14
sys/dev/ic/mpt.h: revision 1.7
sys/dev/ic/mpt_debug.c: revision 1.7
sys/dev/ic/mpt_netbsd.c: revision 1.15
add byte-swapping so that this works on BE platforms.
the logic is based on the current freebsd driver.
fixes PR 42870.
 1.6.38.2 27-Jul-2007  tron Add support for newer SAS and similar devices to mpt(4). Tested with
the LSI SAS1064 in a Sun x4200 server.

These enhancements were developed by Garrett D'Amore and contributed
to NetBSD by the TELES AG.
 1.6.38.1 27-Jul-2007  tron file mpt.h was added on branch matt-mips64 on 2007-07-27 13:06:52 +0000
 1.6.30.1 11-Aug-2010  yamt sync with head.
 1.7.34.1 29-Sep-2014  msaitoh Pull up following revision(s) (requested by jmcneill in ticket #120):
sys/dev/ic/mpt_netbsd.c: revision 1.28
sys/dev/ic/mpt_netbsd.c: revision 1.29
sys/dev/ic/mpt.c: revision 1.17
sys/dev/ic/mpt_netbsd.c: revision 1.30
sys/dev/ic/mpt_netbsd.c: revision 1.31
share/man/man4/bio.4: revision 1.12
share/man/man4/mpt.4: revision 1.6
sys/dev/ic/mpt.h: revision 1.8
sys/dev/ic/mpt_netbsd.c: revision 1.26
sys/dev/ic/mpt_netbsd.c: revision 1.27
- Add bio(4) support.
- xref mpt(4) in bio(4).
- xref bio(4) in mpt(4).
- show "sd0" instead of "mpt0" for volume device name
- include vendor/product/rev info for volumes and their disks.
- implement BIOCDISK_NOVOL
- for BIOCDISK_NOVOL, set bd_disknovol=true for any disk not associated with a
volume for BIOCDISK_NOVOL, when setting bd_disknovol=false, also set
bv_volid
 1.7.18.1 03-Dec-2017  jdolecek update from HEAD
 1.7.14.1 03-Nov-2014  msaitoh Pull up following revision(s) (requested by jmcneill in ticket #1160):
sys/dev/ic/mpt_netbsd.c: revision 1.26-1.31
sys/dev/ic/mpt.c: revision 1.17
share/man/man4/bio.4: revision 1.12
share/man/man4/mpt.4: revision 1.6
sys/dev/ic/mpt.h: revision 1.8
- Add bio(4) support.
- xref mpt(4) in bio(4).
- xref bio(4) in mpt(4).
- show "sd0" instead of "mpt0" for volume device name
- include vendor/product/rev info for volumes and their disks.
- for BIOCDISK_NOVOL, set bd_disknovol=true for any disk not associated with a
volume for BIOCDISK_NOVOL, when setting bd_disknovol=false, also set
bv_volid
 1.13 09-Feb-2024  andvar fix spelling mistakes, mainly in comments and log messages.
 1.12 31-May-2022  andvar fix various typos in comments, documentation and messages.
 1.11 05-Nov-2015  palle mpt: add missing debug strings to the Error_Map IOC_Event array
 1.10 17-Apr-2014  christos branches: 1.10.4;
CID/1203194, CID/1203195: Out of bounds read
 1.9 27-Mar-2014  christos branches: 1.9.2;
cleanup debugging printfs to avoid overflow
 1.8 17-Oct-2011  mbalmer branches: 1.8.2; 1.8.12; 1.8.16;
Receive, not recieve.
 1.7 28-Apr-2010  chs add byte-swapping so that this works on BE platforms.
the logic is based on the current freebsd driver.
fixes PR 42870.
 1.6 18-Apr-2009  tsutsui branches: 1.6.2; 1.6.4;
Remove extra whitespace added by a stupid tool.
XXX: more in src/sys/arch
 1.5 18-Mar-2009  cegger bcopy -> memcpy
 1.4 11-Dec-2005  christos branches: 1.4.74; 1.4.84; 1.4.86; 1.4.90;
merge ktrace-lwp.
 1.3 30-May-2005  christos - add missing const
- fix variable shadowing
- remove unneeded casts
 1.2 14-Jul-2003  lukem branches: 1.2.14; 1.2.18; 1.2.20;
add missing __KERNEL_RCSID()
 1.1 16-Apr-2003  thorpej branches: 1.1.2;
Device driver for the LSI Logic Fusion-MPT based SCSI and Fibre Channel
adapters. Currently supports:

* LSI 53c1030 Ultra320 SCSI
* LSI FC909, FC909A, FC919, and FC929 Fibre Channel

Ported from the FreeBSD "mpt" driver, written by Greg Ansley. Thanks
to Frank van der Linden for testing and some bug finding.

This work was sponsored by Wasabi Systems, Inc.
 1.1.2.4 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.1.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.1.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.1.2.1 03-Aug-2004  skrll Sync with HEAD
 1.2.20.1 04-Oct-2007  bouyer Pull up following revision(s) (requested by tron in ticket #1822):
sys/dev/ic/mpt_netbsd.c: revision 1.12 via patch
sys/dev/ic/mpt_netbsd.h: revision 1.6 via patch
sys/dev/ic/mpt_mpilib.h: revision 1.3 via patch
sys/dev/ic/mpt.h: revision 1.6 via patch
sys/dev/ic/mpt.c: revisions 1.9, 1.10 via patch
sys/dev/ic/mpt_debug.c: patch
sys/dev/pci/mpt_pci.c: revision 1.11 via patch
sys/dev/pci/pcidevs: patch
sys/dev/pci/pcidevs.h: patch
sys/dev/pci/pcidevs_data.h: patch
Add support for newer SAS and similar devices to mpt(4). Tested with
the LSI SAS1064 in a Sun x4200 server.
These enhancements were developed by Garrett D'Amore and contributed
to NetBSD by the TELES AG.
 1.2.18.1 04-Oct-2007  bouyer Pull up following revision(s) (requested by tron in ticket #1822):
sys/dev/ic/mpt_netbsd.c: revision 1.12 via patch
sys/dev/ic/mpt_netbsd.h: revision 1.6 via patch
sys/dev/ic/mpt_mpilib.h: revision 1.3 via patch
sys/dev/ic/mpt.h: revision 1.6 via patch
sys/dev/ic/mpt.c: revisions 1.9, 1.10 via patch
sys/dev/ic/mpt_debug.c: patch
sys/dev/pci/mpt_pci.c: revision 1.11 via patch
sys/dev/pci/pcidevs: patch
sys/dev/pci/pcidevs.h: patch
sys/dev/pci/pcidevs_data.h: patch
Add support for newer SAS and similar devices to mpt(4). Tested with
the LSI SAS1064 in a Sun x4200 server.
These enhancements were developed by Garrett D'Amore and contributed
to NetBSD by the TELES AG.
 1.2.14.1 15-Sep-2007  bouyer Pull up following revision(s) (requested by tron in ticket #1822):
sys/dev/ic/mpt_netbsd.c: revision 1.12 via patch
sys/dev/ic/mpt_netbsd.h: revision 1.6 via patch
sys/dev/ic/mpt_mpilib.h: revision 1.3 via patch
sys/dev/ic/mpt.h: revision 1.6 via patch
sys/dev/ic/mpt.c: revisions 1.9, 1.10 via patch
sys/dev/ic/mpt_debug.c: patch
sys/dev/pci/mpt_pci.c: revision 1.11 via patch
sys/dev/pci/pcidevs: patch
sys/dev/pci/pcidevs.h: patch
sys/dev/pci/pcidevs_data.h: patch
Add support for newer SAS and similar devices to mpt(4). Tested with
the LSI SAS1064 in a Sun x4200 server.
These enhancements were developed by Garrett D'Amore and contributed
to NetBSD by the TELES AG.
 1.4.90.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.4.86.1 02-Dec-2010  snj Pull up following revision(s) (requested by riz in ticket #1487):
sys/dev/ic/mpt.c: revision 1.14
sys/dev/ic/mpt.h: revision 1.7
sys/dev/ic/mpt_debug.c: revision 1.7
sys/dev/ic/mpt_netbsd.c: revision 1.15
add byte-swapping so that this works on BE platforms.
the logic is based on the current freebsd driver.
fixes PR 42870.
 1.4.84.1 28-Apr-2009  skrll Sync with HEAD.
 1.4.74.2 11-Aug-2010  yamt sync with head.
 1.4.74.1 04-May-2009  yamt sync with head.
 1.6.4.1 30-May-2010  rmind sync with head
 1.6.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.8.16.1 18-May-2014  rmind sync with head
 1.8.12.2 03-Dec-2017  jdolecek update from HEAD
 1.8.12.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.8.2.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.9.2.1 10-Aug-2014  tls Rebase.
 1.10.4.1 27-Dec-2015  skrll Sync with HEAD (as of 26th Dec)
 1.6 10-Feb-2024  andvar Fix various typos in comments, log messages and documentation.
 1.5 04-Apr-2022  andvar fix various typos, mainly in comments.
 1.4 24-Jul-2021  andvar Fix all remaining typos, mainly in comments but also in few definitions and log messages, reported by me in PR kern/54889.
Also fixed some additional typos in comments, found on review of same files or typos.
 1.3 27-Jul-2007  tron branches: 1.3.38; 1.3.138;
Add support for newer SAS and similar devices to mpt(4). Tested with
the LSI SAS1064 in a Sun x4200 server.

These enhancements were developed by Garrett D'Amore and contributed
to NetBSD by the TELES AG.
 1.2 16-Apr-2003  thorpej branches: 1.2.16; 1.2.18; 1.2.28; 1.2.52; 1.2.54; 1.2.60; 1.2.68; 1.2.70;
Use the standard fixed-sized types on NetBSD.
 1.1 16-Apr-2003  thorpej Device driver for the LSI Logic Fusion-MPT based SCSI and Fibre Channel
adapters. Currently supports:

* LSI 53c1030 Ultra320 SCSI
* LSI FC909, FC909A, FC919, and FC929 Fibre Channel

Ported from the FreeBSD "mpt" driver, written by Greg Ansley. Thanks
to Frank van der Linden for testing and some bug finding.

This work was sponsored by Wasabi Systems, Inc.
 1.2.70.1 15-Aug-2007  skrll Sync with HEAD.
 1.2.68.1 03-Sep-2007  wrstuden Sync w/ NetBSD-4-RC_1
 1.2.60.1 20-Aug-2007  ad Sync with HEAD.
 1.2.54.1 30-Jul-2007  liamjfoy Pull up following revision(s) (requested by tron in ticket #797):
sys/dev/ic/mpt_netbsd.c: revision 1.12
sys/dev/ic/mpt_mpilib.h: revision 1.3
sys/dev/ic/mpt.h: revision 1.6
sys/dev/ic/mpt.c: revision 1.9
sys/dev/ic/mpt_netbsd.h: revision 1.6
sys/dev/pci/mpt_pci.c: revision 1.11
doc/CHANGES: revision 1.893
Add support for newer SAS and similar devices to mpt(4). Tested with
the LSI SAS1064 in a Sun x4200 server.
These enhancements were developed by Garrett D'Amore and contributed
to NetBSD by the TELES AG.
Mention support for new hardware in mpt(4).
 1.2.52.1 04-Oct-2007  bouyer Pull up following revision(s) (requested by tron in ticket #1822):
sys/dev/ic/mpt_netbsd.c: revision 1.12 via patch
sys/dev/ic/mpt_netbsd.h: revision 1.6 via patch
sys/dev/ic/mpt_mpilib.h: revision 1.3 via patch
sys/dev/ic/mpt.h: revision 1.6 via patch
sys/dev/ic/mpt.c: revisions 1.9, 1.10 via patch
sys/dev/ic/mpt_debug.c: patch
sys/dev/pci/mpt_pci.c: revision 1.11 via patch
sys/dev/pci/pcidevs: patch
sys/dev/pci/pcidevs.h: patch
sys/dev/pci/pcidevs_data.h: patch
Add support for newer SAS and similar devices to mpt(4). Tested with
the LSI SAS1064 in a Sun x4200 server.
These enhancements were developed by Garrett D'Amore and contributed
to NetBSD by the TELES AG.
 1.2.28.1 04-Oct-2007  bouyer Pull up following revision(s) (requested by tron in ticket #1822):
sys/dev/ic/mpt_netbsd.c: revision 1.12 via patch
sys/dev/ic/mpt_netbsd.h: revision 1.6 via patch
sys/dev/ic/mpt_mpilib.h: revision 1.3 via patch
sys/dev/ic/mpt.h: revision 1.6 via patch
sys/dev/ic/mpt.c: revisions 1.9, 1.10 via patch
sys/dev/ic/mpt_debug.c: patch
sys/dev/pci/mpt_pci.c: revision 1.11 via patch
sys/dev/pci/pcidevs: patch
sys/dev/pci/pcidevs.h: patch
sys/dev/pci/pcidevs_data.h: patch
Add support for newer SAS and similar devices to mpt(4). Tested with
the LSI SAS1064 in a Sun x4200 server.
These enhancements were developed by Garrett D'Amore and contributed
to NetBSD by the TELES AG.
 1.2.18.1 03-Sep-2007  yamt sync with head.
 1.2.16.1 13-Sep-2007  bouyer Pull up following revision(s) (requested by tron in ticket #1822):
sys/dev/ic/mpt_netbsd.c: revision 1.12 via patch
sys/dev/ic/mpt_netbsd.h: revision 1.6 via patch
sys/dev/ic/mpt_mpilib.h: revision 1.3 via patch
sys/dev/ic/mpt.h: revision 1.6 via patch
sys/dev/ic/mpt.c: revisions 1.9, 1.10 via patch
sys/dev/ic/mpt_debug.c: patch
sys/dev/pci/mpt_pci.c: revision 1.11 via patch
sys/dev/pci/pcidevs: patch
sys/dev/pci/pcidevs.h: patch
sys/dev/pci/pcidevs_data.h: patch
Add support for newer SAS and similar devices to mpt(4). Tested with
the LSI SAS1064 in a Sun x4200 server.
These enhancements were developed by Garrett D'Amore and contributed
to NetBSD by the TELES AG.
 1.3.138.1 01-Aug-2021  thorpej Sync with HEAD.
 1.3.38.2 27-Jul-2007  tron Add support for newer SAS and similar devices to mpt(4). Tested with
the LSI SAS1064 in a Sun x4200 server.

These enhancements were developed by Garrett D'Amore and contributed
to NetBSD by the TELES AG.
 1.3.38.1 27-Jul-2007  tron file mpt_mpilib.h was added on branch matt-mips64 on 2007-07-27 13:06:52 +0000
 1.40 09-Feb-2024  andvar fix spelling mistakes, mainly in comments and log messages.
 1.39 07-Aug-2021  thorpej Merge thorpej-cfargs2.
 1.38 24-Apr-2021  thorpej branches: 1.38.8;
Merge thorpej-cfargs branch:

Simplify and make extensible the config_search() / config_found() /
config_attach() interfaces: rather than having different variants for
which arguments you want pass along, just have a single call that
takes a variadic list of tag-value arguments.

Adjust all call sites:
- Simplify wherever possible; don't pass along arguments that aren't
actually needed.
- Don't be explicit about what interface attribute is attaching if
the device only has one. (More simplification.)
- Add a config_probe() function to be used in indirect configuiration
situations, making is visibly easier to see when indirect config is
in play, and allowing for future change in semantics. (As of now,
this is just a wrapper around config_match(), but that is an
implementation detail.)

Remove unnecessary or redundant interface attributes where they're not
needed.

There are currently 5 "cfargs" defined:
- CFARG_SUBMATCH (submatch function for direct config)
- CFARG_SEARCH (search function for indirect config)
- CFARG_IATTR (interface attribte)
- CFARG_LOCATORS (locators array)
- CFARG_DEVHANDLE (devhandle_t - wraps OFW, ACPI, etc. handles)

...and a sentinel value CFARG_EOL.

Add some extra sanity checking to ensure that interface attributes
aren't ambiguous.

Use CFARG_DEVHANDLE in MI FDT, OFW, and ACPI code, and macppc and shark
ports to associate those device handles with device_t instance. This
will trickle trough to more places over time (need back-end for pre-OFW
Sun OBP; any others?).
 1.37 15-Sep-2020  mlelstv branches: 1.37.4;
max_devices is a 8bit value and zero is interpreted as 256. This value
can be reported by an mpt device emulated by VMware ESXi.
 1.36 08-May-2019  cnst branches: 1.36.2;
mpt(4): remove ENOTTY / noop implementation of bio(4) setstate

* All other bio(4) drivers either do or don't implement each command.

* This changes the returned error code, but it does not seem to matter,
as some bio(4) drivers always return ENOTTY in the default case, whilst
others always return EINVAL (e.g., both cac(4) and ciss(4) for setstate).
 1.35 05-Feb-2018  mrg branches: 1.35.4;
fixes for GCC 6.4:

- fix an indentation issue in radioioctl().
- fix an indentation issue in mpt_run_xfer().
- grep's printline() has some {} placement issues.
 1.34 30-Jan-2018  jakllsch Move mpt_disc_enable setting into is_scsi block.

The field is only 16 bits, and is only refered to in the is_scsi case.
 1.33 02-May-2016  christos branches: 1.33.10;
move scsipi_strvis -> libkern:strnvisx()
change the prototype to match userland
fix sizes of strings passed to it
 1.32 22-Jul-2015  hannken Adapter leaks requests when mpt_event_notify_reply() has to acknowledge
an event leading to "adapter resource shortage" messages when the scsipi
subsystem tries to use all adapt_openings.

Change mpt_ctlop() to free the request on event MPI_FUNCTION_EVENT_ACK.

Tested on a SunFire X4275 with Symbios Logic SAS1068E (1000:0058, rev. 4).
 1.31 28-Sep-2014  jmcneill branches: 1.31.2;
for BIOCDISK_NOVOL, when setting bd_disknovol=false, also set bv_volid
 1.30 28-Sep-2014  jmcneill for BIOCDISK_NOVOL, set bd_disknovol=true for any disk not associated with a volume
 1.29 27-Sep-2014  jmcneill implement BIOCDISK_NOVOL
 1.28 27-Sep-2014  jmcneill include vendor/product/rev info for volumes and their disks
 1.27 27-Sep-2014  jmcneill show "sd0" instead of "mpt0" for volume device name
 1.26 27-Sep-2014  jmcneill add bio(4) support
 1.25 08-Jul-2014  chs branches: 1.25.2;
fix a device/softc error.
remove some related glue that is no longer needed.
 1.24 17-Apr-2014  christos CID/1203197: NULL deref
 1.23 17-Apr-2014  christos CID 1203189: Null deref.
 1.22 15-Apr-2014  buhrow Checking in cosmetic changes -- no functional change.
(Suggestions made by Taylor Campbell)
 1.21 11-Apr-2014  buhrow Fix up some KNF errors.
 1.20 01-Apr-2014  buhrow branches: 1.20.2;


Checking in changes to improve error handling. Specifically:

- if commands timeout, clear the queues to the the card and perform a soft
reset on the LSI hardware since when these timeouts occur, the LSI firmware
is not graceful about recovering at all.

- Recover gracefully from more kinds of errors using the same recovery
mechanism listed above.

Also, implement mpt_ioctl() to handle bus reset requests from scsictl(8).
 1.19 23-Sep-2012  chs branches: 1.19.2;
set chan_bustype correctly.
 1.18 18-Mar-2012  martin branches: 1.18.2;
Split device_t
 1.17 30-Jan-2012  mhitch branches: 1.17.2;
Allow adapters with SAS/SATA or FC devices to use tagged queuing by the scsipi
layer. Can improve write performance on SAS adapters under certain conditions
when the logical drive does not have write caching enabled. Also need to
reserver a couple of slots for commands for the driver to use - stops the
adapter shortage messages. Multiple commands can now cause QUEUE_FULL events,
so add that to the events handled, currently just ignoring it. Changes
based on the thread http://mail-index.netbsd.org/tech-kern/2011/02/08/msg009946.html.
cvs: ----------------------------------------------------------------------
 1.16 17-Jul-2011  joerg branches: 1.16.2; 1.16.6;
Retire varargs.h support. Move machine/stdarg.h logic into MI
sys/stdarg.h and expect compiler to provide proper builtins, defaulting
to the GCC interface. lint still has a special fallback.
Reduce abuse of _BSD_VA_LIST_ by defining __va_list by default and
derive va_list as required by standards.
 1.15 28-Apr-2010  chs add byte-swapping so that this works on BE platforms.
the logic is based on the current freebsd driver.
fixes PR 42870.
 1.14 08-Apr-2008  cegger branches: 1.14.4; 1.14.14; 1.14.24; 1.14.26;
use aprint_*_dev and device_xname
 1.13 04-Aug-2007  tron branches: 1.13.22; 1.13.24;
Fix some KNF glitches pointed out by Garrett D'Amore.
 1.12 27-Jul-2007  tron branches: 1.12.4;
Add support for newer SAS and similar devices to mpt(4). Tested with
the LSI SAS1064 in a Sun x4200 server.

These enhancements were developed by Garrett D'Amore and contributed
to NetBSD by the TELES AG.
 1.11 04-Mar-2007  christos branches: 1.11.2; 1.11.10;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.10 11-Dec-2005  christos branches: 1.10.24; 1.10.26; 1.10.30;
merge ktrace-lwp.
 1.9 27-Feb-2005  perry branches: 1.9.2; 1.9.4; 1.9.12; 1.9.14;
nuke trailing whitespace
 1.8 10-Apr-2004  briggs branches: 1.8.4; 1.8.6;
Set the DMA SGL length correctly if the DMA request must be chained because
it is too large to fit in one SGL.
Fix from HITOSHI Osada <QFH02545 (at) nifty.com> in response to PR kern/24967.
 1.7 14-Jul-2003  lukem branches: 1.7.2;
add missing __KERNEL_RCSID()
 1.6 01-May-2003  thorpej branches: 1.6.2;
Free the mpt request structure before calling scsipi_done(), as
scsipi_done() may start another command which needs the request
structure being freed.

Patch from Stephan Uphoff, modified slightly by me.
 1.5 23-Apr-2003  tls Correct use of MAXBSIZE where MAXPHYS was intended. This is a necessary
first step towards per-device MAXPHYS, and has the beneficial side effect
of allowing clustering to MAXPHYS even on systems that need to run with
a reduced MAXBSIZE to get more metadata buffers.
 1.4 16-Apr-2003  thorpej In the polling case, don't call mpt_timeout() twice.
 1.3 16-Apr-2003  thorpej mpt_dma_mem_alloc(): If we fail, only destroy request DMA maps that
were actually created.
 1.2 16-Apr-2003  thorpej Correctly sync the MPT request buffers, and remove BUS_DMA_COHERENT
from the mapping of those buffers.
 1.1 16-Apr-2003  thorpej Device driver for the LSI Logic Fusion-MPT based SCSI and Fibre Channel
adapters. Currently supports:

* LSI 53c1030 Ultra320 SCSI
* LSI FC909, FC909A, FC919, and FC929 Fibre Channel

Ported from the FreeBSD "mpt" driver, written by Greg Ansley. Thanks
to Frank van der Linden for testing and some bug finding.

This work was sponsored by Wasabi Systems, Inc.
 1.6.2.4 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.6.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.6.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.6.2.1 03-Aug-2004  skrll Sync with HEAD
 1.7.2.1 11-Apr-2004  jmc Pullup rev 1.8 (requested by briggs in ticket #113)

Set the DMA SGL length correctly if the DMA request must be chained because
it is too large to fit in one SGL. PR#24967
 1.8.6.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.8.4.1 29-Apr-2005  kent sync with -current
 1.9.14.1 04-Oct-2007  bouyer Pull up following revision(s) (requested by tron in ticket #1822):
sys/dev/ic/mpt_netbsd.c: revision 1.12 via patch
sys/dev/ic/mpt_netbsd.h: revision 1.6 via patch
sys/dev/ic/mpt_mpilib.h: revision 1.3 via patch
sys/dev/ic/mpt.h: revision 1.6 via patch
sys/dev/ic/mpt.c: revisions 1.9, 1.10 via patch
sys/dev/ic/mpt_debug.c: patch
sys/dev/pci/mpt_pci.c: revision 1.11 via patch
sys/dev/pci/pcidevs: patch
sys/dev/pci/pcidevs.h: patch
sys/dev/pci/pcidevs_data.h: patch
Add support for newer SAS and similar devices to mpt(4). Tested with
the LSI SAS1064 in a Sun x4200 server.
These enhancements were developed by Garrett D'Amore and contributed
to NetBSD by the TELES AG.
 1.9.12.1 04-Oct-2007  bouyer Pull up following revision(s) (requested by tron in ticket #1822):
sys/dev/ic/mpt_netbsd.c: revision 1.12 via patch
sys/dev/ic/mpt_netbsd.h: revision 1.6 via patch
sys/dev/ic/mpt_mpilib.h: revision 1.3 via patch
sys/dev/ic/mpt.h: revision 1.6 via patch
sys/dev/ic/mpt.c: revisions 1.9, 1.10 via patch
sys/dev/ic/mpt_debug.c: patch
sys/dev/pci/mpt_pci.c: revision 1.11 via patch
sys/dev/pci/pcidevs: patch
sys/dev/pci/pcidevs.h: patch
sys/dev/pci/pcidevs_data.h: patch
Add support for newer SAS and similar devices to mpt(4). Tested with
the LSI SAS1064 in a Sun x4200 server.
These enhancements were developed by Garrett D'Amore and contributed
to NetBSD by the TELES AG.
 1.9.4.1 03-Sep-2007  yamt sync with head.
 1.9.2.1 13-Sep-2007  bouyer Pull up following revision(s) (requested by tron in ticket #1822):
sys/dev/ic/mpt_netbsd.c: revision 1.12 via patch
sys/dev/ic/mpt_netbsd.h: revision 1.6 via patch
sys/dev/ic/mpt_mpilib.h: revision 1.3 via patch
sys/dev/ic/mpt.h: revision 1.6 via patch
sys/dev/ic/mpt.c: revisions 1.9, 1.10 via patch
sys/dev/ic/mpt_debug.c: patch
sys/dev/pci/mpt_pci.c: revision 1.11 via patch
sys/dev/pci/pcidevs: patch
sys/dev/pci/pcidevs.h: patch
sys/dev/pci/pcidevs_data.h: patch
Add support for newer SAS and similar devices to mpt(4). Tested with
the LSI SAS1064 in a Sun x4200 server.
These enhancements were developed by Garrett D'Amore and contributed
to NetBSD by the TELES AG.
 1.10.30.1 03-Sep-2007  wrstuden Sync w/ NetBSD-4-RC_1
 1.10.26.1 12-Mar-2007  rmind Sync with HEAD.
 1.10.24.1 30-Jul-2007  liamjfoy Pull up following revision(s) (requested by tron in ticket #797):
sys/dev/ic/mpt_netbsd.c: revision 1.12
sys/dev/ic/mpt_mpilib.h: revision 1.3
sys/dev/ic/mpt.h: revision 1.6
sys/dev/ic/mpt.c: revision 1.9
sys/dev/ic/mpt_netbsd.h: revision 1.6
sys/dev/pci/mpt_pci.c: revision 1.11
doc/CHANGES: revision 1.893
Add support for newer SAS and similar devices to mpt(4). Tested with
the LSI SAS1064 in a Sun x4200 server.
These enhancements were developed by Garrett D'Amore and contributed
to NetBSD by the TELES AG.
Mention support for new hardware in mpt(4).
 1.11.10.1 15-Aug-2007  skrll Sync with HEAD.
 1.11.2.1 20-Aug-2007  ad Sync with HEAD.
 1.12.4.1 09-Aug-2007  jmcneill Sync with HEAD.
 1.13.24.2 04-Aug-2007  tron Fix some KNF glitches pointed out by Garrett D'Amore.
 1.13.24.1 04-Aug-2007  tron file mpt_netbsd.c was added on branch matt-mips64 on 2007-08-04 22:01:07 +0000
 1.13.22.1 02-Jun-2008  mjf Sync with HEAD.
 1.14.26.1 30-May-2010  rmind sync with head
 1.14.24.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.14.14.2 04-Feb-2012  bouyer Pull up following revision(s) (requested by mhitch in ticket #1720):
sys/dev/ic/mpt_netbsd.c: revision 1.17
Allow adapters with SAS/SATA or FC devices to use tagged queuing by the scsipi
layer. Can improve write performance on SAS adapters under certain conditions
when the logical drive does not have write caching enabled. Also need to
reserver a couple of slots for commands for the driver to use - stops the
adapter shortage messages. Multiple commands can now cause QUEUE_FULL events,
so add that to the events handled, currently just ignoring it. Changes
based on the thread http://mail-index.netbsd.org/tech-kern/2011/02/08/msg009946.html.
cvs: ----------------------------------------------------------------------
 1.14.14.1 02-Dec-2010  snj Pull up following revision(s) (requested by riz in ticket #1487):
sys/dev/ic/mpt.c: revision 1.14
sys/dev/ic/mpt.h: revision 1.7
sys/dev/ic/mpt_debug.c: revision 1.7
sys/dev/ic/mpt_netbsd.c: revision 1.15
add byte-swapping so that this works on BE platforms.
the logic is based on the current freebsd driver.
fixes PR 42870.
 1.14.4.1 11-Aug-2010  yamt sync with head.
 1.16.6.2 05-Apr-2012  mrg sync to latest -current.
 1.16.6.1 18-Feb-2012  mrg merge to -current.
 1.16.2.3 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.16.2.2 30-Oct-2012  yamt sync with head
 1.16.2.1 17-Apr-2012  yamt sync with head
 1.17.2.3 15-Nov-2015  bouyer Pull up following revision(s) (requested by hannken in ticket #1316):
sys/dev/ic/mpt_netbsd.c: revision 1.32
Adapter leaks requests when mpt_event_notify_reply() has to acknowledge
an event leading to "adapter resource shortage" messages when the scsipi
subsystem tries to use all adapt_openings.
Change mpt_ctlop() to free the request on event MPI_FUNCTION_EVENT_ACK.
Tested on a SunFire X4275 with Symbios Logic SAS1068E (1000:0058, rev. 4).
 1.17.2.2 03-Nov-2014  msaitoh Pull up following revision(s) (requested by jmcneill in ticket #1160):
sys/dev/ic/mpt_netbsd.c: revision 1.26-1.31
sys/dev/ic/mpt.c: revision 1.17
share/man/man4/bio.4: revision 1.12
share/man/man4/mpt.4: revision 1.6
sys/dev/ic/mpt.h: revision 1.8
- Add bio(4) support.
- xref mpt(4) in bio(4).
- xref bio(4) in mpt(4).
- show "sd0" instead of "mpt0" for volume device name
- include vendor/product/rev info for volumes and their disks.
- for BIOCDISK_NOVOL, set bd_disknovol=true for any disk not associated with a
volume for BIOCDISK_NOVOL, when setting bd_disknovol=false, also set
bv_volid
 1.17.2.1 22-Nov-2012  riz Pull up following revision(s) (requested by chs in ticket #686):
sys/dev/ic/mpt_netbsd.c: revision 1.19
set chan_bustype correctly.
 1.18.2.4 03-Dec-2017  jdolecek update from HEAD
 1.18.2.3 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.18.2.2 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.18.2.1 12-Sep-2012  tls Initial snapshot of work to eliminate 64K MAXPHYS. Basically works for
physio (I/O to raw devices); needs more doing to get it going with the
filesystems, but it shouldn't damage data.

All work's been done on amd64 so far. Not hard to add support to other
ports. If others want to pitch in, one very helpful thing would be to
sort out when and how IDE disks can do 128K or larger transfers, and
adjust the various PCI IDE (or at least ahcisata) drivers and wd.c
accordingly -- it would make testing much easier. Another very helpful
thing would be to implement a smart minphys() for RAIDframe along the
lines detailed in the MAXPHYS-NOTES file.
 1.19.2.1 18-May-2014  rmind sync with head
 1.20.2.1 10-Aug-2014  tls Rebase.
 1.25.2.2 30-Jul-2015  snj Pull up following revision(s) (requested by hannken in ticket #910):
sys/dev/ic/mpt_netbsd.c: revision 1.32
Adapter leaks requests when mpt_event_notify_reply() has to acknowledge
an event leading to "adapter resource shortage" messages when the scsipi
subsystem tries to use all adapt_openings.
Change mpt_ctlop() to free the request on event MPI_FUNCTION_EVENT_ACK.
Tested on a SunFire X4275 with Symbios Logic SAS1068E (1000:0058, rev. 4).
 1.25.2.1 29-Sep-2014  msaitoh Pull up following revision(s) (requested by jmcneill in ticket #120):
sys/dev/ic/mpt_netbsd.c: revision 1.28
sys/dev/ic/mpt_netbsd.c: revision 1.29
sys/dev/ic/mpt.c: revision 1.17
sys/dev/ic/mpt_netbsd.c: revision 1.30
sys/dev/ic/mpt_netbsd.c: revision 1.31
share/man/man4/bio.4: revision 1.12
share/man/man4/mpt.4: revision 1.6
sys/dev/ic/mpt.h: revision 1.8
sys/dev/ic/mpt_netbsd.c: revision 1.26
sys/dev/ic/mpt_netbsd.c: revision 1.27
- Add bio(4) support.
- xref mpt(4) in bio(4).
- xref bio(4) in mpt(4).
- show "sd0" instead of "mpt0" for volume device name
- include vendor/product/rev info for volumes and their disks.
- implement BIOCDISK_NOVOL
- for BIOCDISK_NOVOL, set bd_disknovol=true for any disk not associated with a
volume for BIOCDISK_NOVOL, when setting bd_disknovol=false, also set
bv_volid
 1.31.2.2 29-May-2016  skrll Sync with HEAD
 1.31.2.1 22-Sep-2015  skrll Sync with HEAD
 1.33.10.1 16-Sep-2020  martin Pull up following revision(s) (requested by mlelstv in ticket #1605):

sys/dev/ic/mpt_netbsd.c: revision 1.37

max_devices is a 8bit value and zero is interpreted as 256. This value
can be reported by an mpt device emulated by VMware ESXi.
 1.35.4.1 10-Jun-2019  christos Sync with HEAD
 1.36.2.1 16-Sep-2020  martin Pull up following revision(s) (requested by mlelstv in ticket #1085):

sys/dev/ic/mpt_netbsd.c: revision 1.37

max_devices is a 8bit value and zero is interpreted as 256. This value
can be reported by an mpt device emulated by VMware ESXi.
 1.37.4.1 21-Mar-2021  thorpej Give config_found() the same variadic arguments treatment as
config_search(). This commit only adds the CFARG_EOL sentinel
to the existing config_found() calls. Conversion of config_found_sm_loc()
and config_found_ia() call sites will be in subsequent commits.
 1.38.8.1 04-Aug-2021  thorpej Adapt to CFARGS().
 1.13 21-Sep-2019  maxv Add __printflike, and fix two incorrect fmts. Reported by the lgtm bot.
 1.12 30-Jan-2018  jakllsch branches: 1.12.4;
remove unused softc variables
 1.11 01-Apr-2014  buhrow Checking in changes to improve error handling. Specifically:

- if commands timeout, clear the queues to the the card and perform a soft
reset on the LSI hardware since when these timeouts occur, the LSI firmware
is not graceful about recovering at all.

- Recover gracefully from more kinds of errors using the same recovery
mechanism listed above.

Also, implement mpt_ioctl() to handle bus reset requests from scsictl(8).
 1.10 18-Mar-2012  martin branches: 1.10.2; 1.10.4;
Split device_t
 1.9 13-Nov-2010  uebayasi branches: 1.9.8; 1.9.12;
Don't pull in the whole uvm(9) API to access only PAGE_SIZE and
some other constants. These are provided by sys/param.h now.
 1.8 20-Nov-2007  ad branches: 1.8.40;
Don't rely on others being kind enough to pull in sys/device.h
 1.7 19-Oct-2007  ad branches: 1.7.2;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.6 27-Jul-2007  tron branches: 1.6.4; 1.6.6; 1.6.10; 1.6.12;
Add support for newer SAS and similar devices to mpt(4). Tested with
the LSI SAS1064 in a Sun x4200 server.

These enhancements were developed by Garrett D'Amore and contributed
to NetBSD by the TELES AG.
 1.5 25-Dec-2006  wiz branches: 1.5.6; 1.5.14;
Spell "separate" correctly. From Zafer Aydogan.
 1.4 11-Dec-2005  christos branches: 1.4.20; 1.4.24; 1.4.26;
merge ktrace-lwp.
 1.3 27-Feb-2005  perry branches: 1.3.2; 1.3.4; 1.3.12; 1.3.14;
nuke trailing whitespace
 1.2 16-Apr-2003  thorpej branches: 1.2.2; 1.2.10; 1.2.12;
Correctly sync the MPT request buffers, and remove BUS_DMA_COHERENT
from the mapping of those buffers.
 1.1 16-Apr-2003  thorpej Device driver for the LSI Logic Fusion-MPT based SCSI and Fibre Channel
adapters. Currently supports:

* LSI 53c1030 Ultra320 SCSI
* LSI FC909, FC909A, FC919, and FC929 Fibre Channel

Ported from the FreeBSD "mpt" driver, written by Greg Ansley. Thanks
to Frank van der Linden for testing and some bug finding.

This work was sponsored by Wasabi Systems, Inc.
 1.2.12.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.2.10.1 29-Apr-2005  kent sync with -current
 1.2.2.1 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.3.14.1 04-Oct-2007  bouyer Pull up following revision(s) (requested by tron in ticket #1822):
sys/dev/ic/mpt_netbsd.c: revision 1.12 via patch
sys/dev/ic/mpt_netbsd.h: revision 1.6 via patch
sys/dev/ic/mpt_mpilib.h: revision 1.3 via patch
sys/dev/ic/mpt.h: revision 1.6 via patch
sys/dev/ic/mpt.c: revisions 1.9, 1.10 via patch
sys/dev/ic/mpt_debug.c: patch
sys/dev/pci/mpt_pci.c: revision 1.11 via patch
sys/dev/pci/pcidevs: patch
sys/dev/pci/pcidevs.h: patch
sys/dev/pci/pcidevs_data.h: patch
Add support for newer SAS and similar devices to mpt(4). Tested with
the LSI SAS1064 in a Sun x4200 server.
These enhancements were developed by Garrett D'Amore and contributed
to NetBSD by the TELES AG.
 1.3.12.1 04-Oct-2007  bouyer Pull up following revision(s) (requested by tron in ticket #1822):
sys/dev/ic/mpt_netbsd.c: revision 1.12 via patch
sys/dev/ic/mpt_netbsd.h: revision 1.6 via patch
sys/dev/ic/mpt_mpilib.h: revision 1.3 via patch
sys/dev/ic/mpt.h: revision 1.6 via patch
sys/dev/ic/mpt.c: revisions 1.9, 1.10 via patch
sys/dev/ic/mpt_debug.c: patch
sys/dev/pci/mpt_pci.c: revision 1.11 via patch
sys/dev/pci/pcidevs: patch
sys/dev/pci/pcidevs.h: patch
sys/dev/pci/pcidevs_data.h: patch
Add support for newer SAS and similar devices to mpt(4). Tested with
the LSI SAS1064 in a Sun x4200 server.
These enhancements were developed by Garrett D'Amore and contributed
to NetBSD by the TELES AG.
 1.3.4.4 07-Dec-2007  yamt sync with head
 1.3.4.3 27-Oct-2007  yamt sync with head.
 1.3.4.2 03-Sep-2007  yamt sync with head.
 1.3.4.1 30-Dec-2006  yamt sync with head.
 1.3.2.1 13-Sep-2007  bouyer Pull up following revision(s) (requested by tron in ticket #1822):
sys/dev/ic/mpt_netbsd.c: revision 1.12 via patch
sys/dev/ic/mpt_netbsd.h: revision 1.6 via patch
sys/dev/ic/mpt_mpilib.h: revision 1.3 via patch
sys/dev/ic/mpt.h: revision 1.6 via patch
sys/dev/ic/mpt.c: revisions 1.9, 1.10 via patch
sys/dev/ic/mpt_debug.c: patch
sys/dev/pci/mpt_pci.c: revision 1.11 via patch
sys/dev/pci/pcidevs: patch
sys/dev/pci/pcidevs.h: patch
sys/dev/pci/pcidevs_data.h: patch
Add support for newer SAS and similar devices to mpt(4). Tested with
the LSI SAS1064 in a Sun x4200 server.
These enhancements were developed by Garrett D'Amore and contributed
to NetBSD by the TELES AG.
 1.4.26.1 03-Sep-2007  wrstuden Sync w/ NetBSD-4-RC_1
 1.4.24.1 30-Jul-2007  liamjfoy Pull up following revision(s) (requested by tron in ticket #797):
sys/dev/ic/mpt_netbsd.c: revision 1.12
sys/dev/ic/mpt_mpilib.h: revision 1.3
sys/dev/ic/mpt.h: revision 1.6
sys/dev/ic/mpt.c: revision 1.9
sys/dev/ic/mpt_netbsd.h: revision 1.6
sys/dev/pci/mpt_pci.c: revision 1.11
doc/CHANGES: revision 1.893
Add support for newer SAS and similar devices to mpt(4). Tested with
the LSI SAS1064 in a Sun x4200 server.
These enhancements were developed by Garrett D'Amore and contributed
to NetBSD by the TELES AG.
Mention support for new hardware in mpt(4).
 1.4.20.1 12-Jan-2007  ad Sync with head.
 1.5.14.1 15-Aug-2007  skrll Sync with HEAD.
 1.5.6.2 23-Oct-2007  ad Sync with head.
 1.5.6.1 20-Aug-2007  ad Sync with HEAD.
 1.6.12.2 27-Jul-2007  tron Add support for newer SAS and similar devices to mpt(4). Tested with
the LSI SAS1064 in a Sun x4200 server.

These enhancements were developed by Garrett D'Amore and contributed
to NetBSD by the TELES AG.
 1.6.12.1 27-Jul-2007  tron file mpt_netbsd.h was added on branch matt-mips64 on 2007-07-27 13:06:52 +0000
 1.6.10.2 21-Nov-2007  bouyer Sync with HEAD
 1.6.10.1 25-Oct-2007  bouyer Sync with HEAD.
 1.6.6.2 09-Jan-2008  matt sync with HEAD
 1.6.6.1 06-Nov-2007  matt sync with HEAD
 1.6.4.2 21-Nov-2007  joerg Sync with HEAD.
 1.6.4.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.7.2.1 08-Dec-2007  mjf Sync with HEAD.
 1.8.40.1 05-Mar-2011  rmind sync with head
 1.9.12.1 05-Apr-2012  mrg sync to latest -current.
 1.9.8.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.9.8.1 17-Apr-2012  yamt sync with head
 1.10.4.1 18-May-2014  rmind sync with head
 1.10.2.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.10.2.1 12-Sep-2012  tls Initial snapshot of work to eliminate 64K MAXPHYS. Basically works for
physio (I/O to raw devices); needs more doing to get it going with the
filesystems, but it shouldn't damage data.

All work's been done on amd64 so far. Not hard to add support to other
ports. If others want to pitch in, one very helpful thing would be to
sort out when and how IDE disks can do 128K or larger transfers, and
adjust the various PCI IDE (or at least ahcisata) drivers and wd.c
accordingly -- it would make testing much easier. Another very helpful
thing would be to implement a smart minphys() for RAIDframe along the
lines detailed in the MAXPHYS-NOTES file.
 1.12.4.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.19 21-Jan-2012  chs src/sys/dev/ic/mpu.c
fix assertions after audiomp.
 1.18 23-Nov-2011  jmcneill branches: 1.18.2;
Merge jmcneill-audiomp3 branch, which is derived from ad-audiomp2. From
the original ad-audiomp branch notes:

Add MP locking to the audio drivers.

Making the audio drivers MP safe is necessary before efforts
can be made to make the VM system MP safe.

The are two locks per device instance, an ISR lock and
a character device lock. The ISR lock replaces calls to
splaudio()/splx(), and will be held across calls to device
methods which were called at splaudio() before (e.g.
trigger_output). The character device lock is held across
calls to nearly all of the methods, excluding some only
used for initialization, e.g. get_locks.

Welcome to 5.99.57.
 1.17 28-Apr-2008  martin branches: 1.17.12; 1.17.34; 1.17.36;
Remove clause 3 and 4 from TNF licenses
 1.16 27-Mar-2008  xtraeme branches: 1.16.2; 1.16.4;
Split device_t/softc for mpu(4) and its attachments, plus other
related cosmetic changes.

Reviewed by cube@.
 1.15 19-Oct-2007  ad branches: 1.15.16;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.14 16-Nov-2006  christos branches: 1.14.6; 1.14.8; 1.14.22; 1.14.24; 1.14.28;
__unused removal on arguments; approved by core.
 1.13 12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.12 24-Dec-2005  perry branches: 1.12.20; 1.12.22;
Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.11 11-Dec-2005  christos merge ktrace-lwp.
 1.10 27-Feb-2005  perry branches: 1.10.4;
nuke trailing whitespace
 1.9 04-Feb-2005  perry de-__P
 1.8 02-Dec-2004  xtraeme branches: 1.8.4; 1.8.6;
Add ACPI mpu(4) attachment, based on lpt_acpi.c by jmcneill@,
reviewed by christos@, cube@ and martin@.

While here, remove a printf() in mpu_attach() (ic/mpu.c) to remove
an empty line in some frontends (mpu_isa.c, etc).
 1.7 29-Oct-2004  yamt constify audio_hw_if, midi_hw_if, and radio_hw_if.
 1.6 04-Dec-2003  keihan netbsd.org -> NetBSD.org

This was the last commit of this kind to src/sys, which is now totally
"NetBSD.org clean". Thanks for the patiance, and sorry for all the commits.
 1.5 13-Nov-2001  lukem branches: 1.5.16;
add/cleanup RCSID
 1.4 28-Jun-2000  mrg branches: 1.4.2; 1.4.4;
remove include of <vm/vm.h>. <vm/vm.h> -> <uvm/uvm_extern.h>
 1.3 05-Oct-1999  itohy branches: 1.3.2;
Add power control hooks.
 1.2 02-Aug-1999  augustss branches: 1.2.2;
Move the mpu device declaration to conf/files.
Let the mpu device attach at the sb device, and then midi at the mpu.
Update the mpu at eso attachment.
 1.1 01-Aug-1999  augustss Move the MPU driver isa/ to ic/.
(I didn't move it in the repository because the revision history
is very short and uninteresting. :)
 1.2.2.2 02-Aug-1999  thorpej Update from trunk.
 1.2.2.1 02-Aug-1999  thorpej file mpu.c was added on branch chs-ubc2 on 1999-08-02 21:59:05 +0000
 1.3.2.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.4.4.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.4.2.1 14-Nov-2001  nathanw Catch up to -current.
 1.5.16.7 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.5.16.6 04-Feb-2005  skrll Sync with HEAD.
 1.5.16.5 18-Dec-2004  skrll Sync with HEAD.
 1.5.16.4 02-Nov-2004  skrll Sync with HEAD.
 1.5.16.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.5.16.2 18-Sep-2004  skrll Sync with HEAD.
 1.5.16.1 03-Aug-2004  skrll Sync with HEAD
 1.8.6.2 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.8.6.1 12-Feb-2005  yamt sync with head.
 1.8.4.1 29-Apr-2005  kent sync with -current
 1.10.4.3 27-Oct-2007  yamt sync with head.
 1.10.4.2 30-Dec-2006  yamt sync with head.
 1.10.4.1 21-Jun-2006  yamt sync with head.
 1.12.22.2 10-Dec-2006  yamt sync with head.
 1.12.22.1 22-Oct-2006  yamt sync with head
 1.12.20.1 18-Nov-2006  ad Sync with head.
 1.14.28.1 25-Oct-2007  bouyer Sync with HEAD.
 1.14.24.1 06-Nov-2007  matt sync with HEAD
 1.14.22.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.14.8.1 23-Oct-2007  ad Sync with head.
 1.14.6.1 27-Feb-2007  ad Add MP locking for audio drivers.
 1.15.16.2 02-Jun-2008  mjf Sync with HEAD.
 1.15.16.1 03-Apr-2008  mjf Sync with HEAD.
 1.16.4.1 16-May-2008  yamt sync with head.
 1.16.2.1 18-May-2008  yamt sync with head.
 1.17.36.1 19-Nov-2011  jmcneill port ad-audiomp2 branch changes to 5.99.56
todo:
- port ad-audiomp2 pcppi changes
- these drivers need to be fixed:
- emuxki
- gcscaudio
- hdafg
- uaudio
- umidi
- MD audio drivers
 1.17.34.1 17-Apr-2012  yamt sync with head
 1.17.12.1 09-Dec-2008  ad Checkpoint work on MIDI.
 1.18.2.1 18-Feb-2012  mrg merge to -current.
 1.11 23-Nov-2011  jmcneill Merge jmcneill-audiomp3 branch, which is derived from ad-audiomp2. From
the original ad-audiomp branch notes:

Add MP locking to the audio drivers.

Making the audio drivers MP safe is necessary before efforts
can be made to make the VM system MP safe.

The are two locks per device instance, an ISR lock and
a character device lock. The ISR lock replaces calls to
splaudio()/splx(), and will be held across calls to device
methods which were called at splaudio() before (e.g.
trigger_output). The character device lock is held across
calls to nearly all of the methods, excluding some only
used for initialization, e.g. get_locks.

Welcome to 5.99.57.
 1.10 28-Apr-2008  martin branches: 1.10.12; 1.10.34; 1.10.36;
Remove clause 3 and 4 from TNF licenses
 1.9 27-Mar-2008  xtraeme branches: 1.9.2; 1.9.4;
Split device_t/softc for mpu(4) and its attachments, plus other
related cosmetic changes.

Reviewed by cube@.
 1.8 11-Dec-2005  christos branches: 1.8.70;
merge ktrace-lwp.
 1.7 29-May-2005  christos - sprinkle const.
- avoid variable shadowing.
 1.6 04-Feb-2005  perry de-__P
 1.5 29-Oct-2004  yamt branches: 1.5.4; 1.5.6;
constify audio_hw_if, midi_hw_if, and radio_hw_if.
 1.4 04-Dec-2003  keihan netbsd.org -> NetBSD.org

This was the last commit of this kind to src/sys, which is now totally
"NetBSD.org clean". Thanks for the patiance, and sorry for all the commits.
 1.3 05-Oct-1999  itohy branches: 1.3.36;
Add power control hooks.
 1.2 02-Aug-1999  augustss branches: 1.2.2;
Move the mpu device declaration to conf/files.
Let the mpu device attach at the sb device, and then midi at the mpu.
Update the mpu at eso attachment.
 1.1 01-Aug-1999  augustss Move the MPU driver isa/ to ic/.
(I didn't move it in the repository because the revision history
is very short and uninteresting. :)
 1.2.2.2 02-Aug-1999  thorpej Update from trunk.
 1.2.2.1 02-Aug-1999  thorpej file mpuvar.h was added on branch chs-ubc2 on 1999-08-02 21:59:05 +0000
 1.3.36.6 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.3.36.5 04-Feb-2005  skrll Sync with HEAD.
 1.3.36.4 02-Nov-2004  skrll Sync with HEAD.
 1.3.36.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.3.36.2 18-Sep-2004  skrll Sync with HEAD.
 1.3.36.1 03-Aug-2004  skrll Sync with HEAD
 1.5.6.1 12-Feb-2005  yamt sync with head.
 1.5.4.1 29-Apr-2005  kent sync with -current
 1.8.70.2 02-Jun-2008  mjf Sync with HEAD.
 1.8.70.1 03-Apr-2008  mjf Sync with HEAD.
 1.9.4.1 16-May-2008  yamt sync with head.
 1.9.2.1 18-May-2008  yamt sync with head.
 1.10.36.1 19-Nov-2011  jmcneill port ad-audiomp2 branch changes to 5.99.56
todo:
- port ad-audiomp2 pcppi changes
- these drivers need to be fixed:
- emuxki
- gcscaudio
- hdafg
- uaudio
- umidi
- MD audio drivers
 1.10.34.1 17-Apr-2012  yamt sync with head
 1.10.12.1 09-Dec-2008  ad Checkpoint work on MIDI.
 1.7 07-Sep-2025  thorpej Change todr_chip_handle::cookie -> todr_chip_handle::todr_dev, and
make it a device_t. Upcoming functional changes will require the
device_t associated with a TODR device.

Change todr_chip_handle::bus_cookie -> todr_chip_handle::todr_devaux.
Nothing was using the old field, but I decided to keep it around just
in cause something needs it in the future.

And with these largely mechanical yet semantically meaningful changes,
thus spake the Oracle: "Welcome to NetBSD 11.99.2."
 1.6 07-Sep-2025  thorpej Remove unnecessary NULL-initialization of TODR handle fields.
 1.5 01-Sep-2024  andvar s/specifc/specific/ in comments.
 1.4 06-Feb-2018  rin branches: 1.4.42;
Remove misplaced semicolon, found by GCC 6.
 1.3 04-Dec-2013  rkujawa branches: 1.3.22;
Fix RTC going backwards a year when saving time, because dt_mon != dt_year.

Patch by Roc Valles.
 1.2 14-Nov-2012  rkujawa branches: 1.2.2; 1.2.4; 1.2.6;
Add kernel RCS ID, clean up.
 1.1 14-Nov-2012  rkujawa Add MI OKI MSM6242B RTC driver.
 1.2.6.1 18-May-2014  rmind sync with head
 1.2.4.3 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.2.4.2 16-Jan-2013  yamt sync with (a bit old) head
 1.2.4.1 14-Nov-2012  yamt file msm6242b.c was added on branch yamt-pagecache on 2013-01-16 05:33:15 +0000
 1.2.2.3 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.2.2.2 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.2.2.1 14-Nov-2012  tls file msm6242b.c was added on branch tls-maxphys on 2012-11-20 03:02:07 +0000
 1.3.22.1 07-Apr-2019  martin Pull up following revision(s) (requested by rin in ticket #1227):

sys/dev/ic/msm6242b.c: revision 1.4

Remove misplaced semicolon, found by GCC 6.
 1.4.42.1 02-Aug-2025  perseant Sync with HEAD
 1.2 04-Feb-2013  phx 24h-mode is indicated by bit 2 of control register F.
 1.1 14-Nov-2012  rkujawa branches: 1.1.2; 1.1.4;
Add MI OKI MSM6242B RTC driver.
 1.1.4.3 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.1.4.2 16-Jan-2013  yamt sync with (a bit old) head
 1.1.4.1 14-Nov-2012  yamt file msm6242breg.h was added on branch yamt-pagecache on 2013-01-16 05:33:15 +0000
 1.1.2.3 25-Feb-2013  tls resync with head
 1.1.2.2 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.1.2.1 14-Nov-2012  tls file msm6242breg.h was added on branch tls-maxphys on 2012-11-20 03:02:07 +0000
 1.1 14-Nov-2012  rkujawa branches: 1.1.2; 1.1.4;
Add MI OKI MSM6242B RTC driver.
 1.1.4.2 16-Jan-2013  yamt sync with (a bit old) head
 1.1.4.1 14-Nov-2012  yamt file msm6242bvar.h was added on branch yamt-pagecache on 2013-01-16 05:33:15 +0000
 1.1.2.2 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.1.2.1 14-Nov-2012  tls file msm6242bvar.h was added on branch tls-maxphys on 2012-11-20 03:02:07 +0000
 1.26 08-May-2019  isaki Merge isaki-audio2 branch, the overhaul of audio subsystem.
- Interrupt-oriented system rather than thread-oriented.
- Improve stability, quality and performance.
- Split playback and record cleanly. Improve halfduplex support.
- Many bugs are fixed including deadlocks, resource leaks, abuses, etc.
- Simplify audio filter mechanism. The encoding/channels/frequency
conversions are completely handled in the upper layer. So the hard-
ware driver only converts its hardware encoding (if necessary).
- audio_hw_if changes:
- Obsoletes query_encoding and add query_format instead.
- Obsoletes set_params and add set_format instead.
- Remove drain, setfd, mappage.
- The call sequences are changed.
- ioctl AUDIO_GETFD/SETFD, AUDIO_GETCHAN/SETCHAN are obsoleted.
- ioctl AUDIO_{QUERY,GET,SET}FORMAT are introduced.
- cleanup config attributes: au*conv and mulaw.
- All hardware drivers should follow it (I've done as much as possible).

Some file paths are changed:
- dev/audio.c -> dev/audio/audio.c (rewritten)
- dev/audiovar.h -> dev/audio/audiovar.h
- dev/audio_dai.h -> dev/audio/audio_dai.h
- dev/audio_if.h -> dev/audio/audio_if.h
- dev/audiobell.c -> dev/audio/audiobell.c
- dev/audiobellvar.h -> dev/audio/audiobellvar.h
- dev/mulaw.[ch] -> dev/audio/mulaw.[ch] + dev/audio/alaw.c
 1.25 03-Sep-2018  riastradh branches: 1.25.2;
Rename min/max -> uimin/uimax for better honesty.

These functions are defined on unsigned int. The generic name
min/max should not silently truncate to 32 bits on 64-bit systems.
This is purely a name change -- no functional change intended.

HOWEVER! Some subsystems have

#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))

even though our standard name for that is MIN/MAX. Although these
may invite multiple evaluation bugs, these do _not_ cause integer
truncation.

To avoid `fixing' these cases, I first changed the name in libkern,
and then compile-tested every file where min/max occurred in order to
confirm that it failed -- and thus confirm that nothing shadowed
min/max -- before changing it.

I have left a handful of bootloaders that are too annoying to
compile-test, and some dead code:

cobalt ews4800mips hp300 hppa ia64 luna68k vax
acorn32/if_ie.c (not included in any kernels)
macppc/if_gm.c (superseded by gem(4))

It should be easy to fix the fallout once identified -- this way of
doing things fails safe, and the goal here, after all, is to _avoid_
silent integer truncations, not introduce them.

Maybe one day we can reintroduce min/max as type-generic things that
never silently truncate. But we should avoid doing that for a while,
so that existing code has a chance to be detected by the compiler for
conversion to uimin/uimax without changing the semantics until we can
properly audit it all. (Who knows, maybe in some cases integer
truncation is actually intended!)
 1.24 02-Sep-2017  isaki branches: 1.24.2; 1.24.4;
Revert previous local conversion for vs(4).
 1.23 05-Aug-2017  isaki vs(4) became to able to play audio again.
At the moment the encoding conversion using set_params() does
not seem to work for me. So vs(4) uses local conversion to/from
ADPCM instead of it. But this should be a temporary work.
XXX The playback quality is very poor compared to before...
XXX Recording is not tested.
 1.22 05-Aug-2017  isaki Fix typo. 266 -> 256.
 1.21 02-Aug-2017  isaki Use endian conversion macros (and some rearrange for readability).
No functional changes.
 1.20 30-Jul-2017  isaki Improve diagnostic code.
If the specified encoding is wrong, it outputs a sound like a buzzer :)
rather than panic.
 1.19 27-Jul-2017  isaki Also allow SLINEAR_BE on msm6258_linear8_to_adpcm.
Before merging in-kernel mixing, it was called with SLINEAR_LE even if
big endian arch. But now it seems to be called with SLINEAR_<HostEndian>.
 1.18 15-Jul-2017  isaki branches: 1.18.2;
Add DIAGNOSTIC code.
 1.17 23-Nov-2011  jmcneill branches: 1.17.8; 1.17.26;
Merge jmcneill-audiomp3 branch, which is derived from ad-audiomp2. From
the original ad-audiomp branch notes:

Add MP locking to the audio drivers.

Making the audio drivers MP safe is necessary before efforts
can be made to make the VM system MP safe.

The are two locks per device instance, an ISR lock and
a character device lock. The ISR lock replaces calls to
splaudio()/splx(), and will be held across calls to device
methods which were called at splaudio() before (e.g.
trigger_output). The character device lock is held across
calls to nearly all of the methods, excluding some only
used for initialization, e.g. get_locks.

Welcome to 5.99.57.
 1.16 16-Oct-2011  isaki branches: 1.16.2; 1.16.4;
Switch to 2-clause license.
 1.15 24-Dec-2005  perry Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.14 11-Dec-2005  christos merge ktrace-lwp.
 1.13 08-Jun-2005  he branches: 1.13.2;
Adapt to compiling with -Wcast-qual by adding const to some pointer casts.
 1.12 10-Jan-2005  kent merge kent-audio1 branch, which introduces audio filter pipeline to the MI
audio framework


Summary of changes:

* struct audio_params
- remove sw_code, factor, factor_denom, hw_sample_rate,
hw_encoding ,hw_precision, and hw_channels. Conversion information
is conveyed by stream_filter_list_t.
- change the type of sample_rate: u_long -> u_int
- add `validbits,' which represents the valid data size in
precision bits. It is required in order to distinguish 24/32bit
from 24/24bit or 32/32bit.

* audio_hw_if
- add two parameters to set_params()
stream_filter_list_t *pfil, stream_filter_list *rfil
A HW driver should set filter recipes for requested formats
- constify audio_params parameters of trigger_output() and
trigger_input(). They represent audio formats for the hardware.
- make open() and close() optional
- add int (AUMODE_PLAY or AUMODE_RECORD) and audio_params_t parameters
to round_blocksize()

* sw_code is replaced with stream_filter_t.
stream_filer_t converts audio data in an input buffer and writes
into another output buffer unlike sw_code, which converts data in
single buffer.
converters in dev/auconv.c, dev/mulaw.c, dev/aurateconv.c,
dev/tc/bba.c, dev/ic/msm6258.c, and arch/arm/iomd/vidcaudio.c are
reimplemented as stream_filter_t

* MI audio
- audiosetinfo() builds filter pipelines from stream_filter_list_t
filled by audio_hw_if::set_params()
- audiosetinfo() returns with EINVAL if mmapped and set_params()
requests filters
- audio_write(), audio_pint(), and audio_rint() invoke a filter
pipeline.
- ioctl() for FIONREAD, AUDIO_WSEEK, AUDIO_GETIOFFS,
AUDIO_GETOOFFS, and audio_prinfo::{seek,samples} for
AUDIO_GETINFO handle values for a buffer nearest to userland.

* add `struct device *' parameter to ac97_attach()

* all of audio HW drivers follow audio_hw_if and ac97 changes
 1.11 07-Sep-2003  isaki branches: 1.11.4;
Remove an advertising clause.
 1.10 13-Apr-2002  isaki branches: 1.10.10;
Fix minor typo in adpcm_estim[].
 1.9 07-Apr-2002  isaki Rewrite encode/decode algorithm completely.
It improves playing/recording quality greatly
and it was almost done by Yosuke Sugahara <penta@fuchu.or.jp>.
Thanks a lot!

Add support of slinear8, slinear16_le, slinear16_be.
 1.8 02-Apr-2002  isaki initialize codec variables every open().
 1.7 02-Apr-2002  isaki Correct ADPCM -> linear8 conversion routine.
Now, we can record on vs0 (but it's very noisy)
 1.6 16-Mar-2002  isaki Fix mis-increment bug in converter msm6258_ulinear8_to_adpcm().
This fix needs factor_denom.
 1.5 13-Nov-2001  lukem add/cleanup RCSID
 1.4 16-Oct-2001  minoura #include mulaw.h for converter functions prototypes.
 1.3 03-May-2001  minoura branches: 1.3.2; 1.3.4;
Correct playing mu-law and linear.
 1.2 02-May-2001  minoura Oops, it contained some debug code.
 1.1 02-May-2001  minoura Software codec for Oki MSM6258 voice synthesizer.
Recording untested.
 1.3.4.2 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.3.4.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.3.2.6 17-Apr-2002  nathanw Catch up to -current.
 1.3.2.5 01-Apr-2002  nathanw Catch up to -current.
(CVS: It's not just a program. It's an adventure!)
 1.3.2.4 14-Nov-2001  nathanw Catch up to -current.
 1.3.2.3 22-Oct-2001  nathanw Catch up to -current.
 1.3.2.2 21-Jun-2001  nathanw Catch up to -current.
 1.3.2.1 03-May-2001  nathanw file msm6258.c was added on branch nathanw_sa on 2001-06-21 20:02:57 +0000
 1.10.10.5 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.10.10.4 17-Jan-2005  skrll Sync with HEAD.
 1.10.10.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.10.10.2 18-Sep-2004  skrll Sync with HEAD.
 1.10.10.1 03-Aug-2004  skrll Sync with HEAD
 1.11.4.2 05-Jan-2005  kent introduce FILTER_LOOP_PROLOGUE() and FILTER_LOOP_EPILOGUE() macros, and
simplify filter implementations by the macros.
 1.11.4.1 03-Jan-2005  kent adopt the filter pipeline framework
 1.13.2.1 21-Jun-2006  yamt sync with head.
 1.16.4.1 20-Nov-2011  jmcneill adapt to audiomp api changes
 1.16.2.1 17-Apr-2012  yamt sync with head
 1.17.26.1 28-Aug-2017  skrll Sync with HEAD
 1.17.8.1 03-Dec-2017  jdolecek update from HEAD
 1.18.2.2 15-Jul-2017  isaki 2873897
 1.18.2.1 15-Jul-2017  isaki file msm6258.c was added on branch perseant-stdc-iso10646 on 2017-07-15 10:17:10 +0000
 1.24.4.1 10-Jun-2019  christos Sync with HEAD
 1.24.2.1 06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.25.2.3 04-May-2019  isaki Move dev/audio_if.h -> dev/audio/audio_if.h
 1.25.2.2 03-May-2019  isaki Remove unnecessary header file.
 1.25.2.1 21-Apr-2019  isaki Adapt to audio2.
 1.11 08-May-2019  isaki Merge isaki-audio2 branch, the overhaul of audio subsystem.
- Interrupt-oriented system rather than thread-oriented.
- Improve stability, quality and performance.
- Split playback and record cleanly. Improve halfduplex support.
- Many bugs are fixed including deadlocks, resource leaks, abuses, etc.
- Simplify audio filter mechanism. The encoding/channels/frequency
conversions are completely handled in the upper layer. So the hard-
ware driver only converts its hardware encoding (if necessary).
- audio_hw_if changes:
- Obsoletes query_encoding and add query_format instead.
- Obsoletes set_params and add set_format instead.
- Remove drain, setfd, mappage.
- The call sequences are changed.
- ioctl AUDIO_GETFD/SETFD, AUDIO_GETCHAN/SETCHAN are obsoleted.
- ioctl AUDIO_{QUERY,GET,SET}FORMAT are introduced.
- cleanup config attributes: au*conv and mulaw.
- All hardware drivers should follow it (I've done as much as possible).

Some file paths are changed:
- dev/audio.c -> dev/audio/audio.c (rewritten)
- dev/audiovar.h -> dev/audio/audiovar.h
- dev/audio_dai.h -> dev/audio/audio_dai.h
- dev/audio_if.h -> dev/audio/audio_if.h
- dev/audiobell.c -> dev/audio/audiobell.c
- dev/audiobellvar.h -> dev/audio/audiobellvar.h
- dev/mulaw.[ch] -> dev/audio/mulaw.[ch] + dev/audio/alaw.c
 1.10 02-Sep-2017  isaki branches: 1.10.4; 1.10.8;
Revert previous local conversion for vs(4).
 1.9 05-Aug-2017  isaki vs(4) became to able to play audio again.
At the moment the encoding conversion using set_params() does
not seem to work for me. So vs(4) uses local conversion to/from
ADPCM instead of it. But this should be a temporary work.
XXX The playback quality is very poor compared to before...
XXX Recording is not tested.
 1.8 16-Oct-2011  isaki branches: 1.8.30;
Switch to 2-clause license.
 1.7 11-Dec-2005  christos merge ktrace-lwp.
 1.6 10-Jan-2005  kent merge kent-audio1 branch, which introduces audio filter pipeline to the MI
audio framework


Summary of changes:

* struct audio_params
- remove sw_code, factor, factor_denom, hw_sample_rate,
hw_encoding ,hw_precision, and hw_channels. Conversion information
is conveyed by stream_filter_list_t.
- change the type of sample_rate: u_long -> u_int
- add `validbits,' which represents the valid data size in
precision bits. It is required in order to distinguish 24/32bit
from 24/24bit or 32/32bit.

* audio_hw_if
- add two parameters to set_params()
stream_filter_list_t *pfil, stream_filter_list *rfil
A HW driver should set filter recipes for requested formats
- constify audio_params parameters of trigger_output() and
trigger_input(). They represent audio formats for the hardware.
- make open() and close() optional
- add int (AUMODE_PLAY or AUMODE_RECORD) and audio_params_t parameters
to round_blocksize()

* sw_code is replaced with stream_filter_t.
stream_filer_t converts audio data in an input buffer and writes
into another output buffer unlike sw_code, which converts data in
single buffer.
converters in dev/auconv.c, dev/mulaw.c, dev/aurateconv.c,
dev/tc/bba.c, dev/ic/msm6258.c, and arch/arm/iomd/vidcaudio.c are
reimplemented as stream_filter_t

* MI audio
- audiosetinfo() builds filter pipelines from stream_filter_list_t
filled by audio_hw_if::set_params()
- audiosetinfo() returns with EINVAL if mmapped and set_params()
requests filters
- audio_write(), audio_pint(), and audio_rint() invoke a filter
pipeline.
- ioctl() for FIONREAD, AUDIO_WSEEK, AUDIO_GETIOFFS,
AUDIO_GETOOFFS, and audio_prinfo::{seek,samples} for
AUDIO_GETINFO handle values for a buffer nearest to userland.

* add `struct device *' parameter to ac97_attach()

* all of audio HW drivers follow audio_hw_if and ac97 changes
 1.5 07-Sep-2003  isaki branches: 1.5.4;
Remove an advertising clause.
 1.4 07-Apr-2002  isaki branches: 1.4.10;
Rewrite encode/decode algorithm completely.
It improves playing/recording quality greatly
and it was almost done by Yosuke Sugahara <penta@fuchu.or.jp>.
Thanks a lot!

Add support of slinear8, slinear16_le, slinear16_be.
 1.3 02-Apr-2002  isaki initialize codec variables every open().
 1.2 16-Mar-2002  isaki Fix mis-increment bug in converter msm6258_ulinear8_to_adpcm().
This fix needs factor_denom.
 1.1 02-May-2001  minoura branches: 1.1.2; 1.1.4;
Software codec for Oki MSM6258 voice synthesizer.
Recording untested.
 1.1.4.1 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.1.2.4 17-Apr-2002  nathanw Catch up to -current.
 1.1.2.3 01-Apr-2002  nathanw Catch up to -current.
(CVS: It's not just a program. It's an adventure!)
 1.1.2.2 21-Jun-2001  nathanw Catch up to -current.
 1.1.2.1 02-May-2001  nathanw file msm6258var.h was added on branch nathanw_sa on 2001-06-21 20:02:58 +0000
 1.4.10.4 17-Jan-2005  skrll Sync with HEAD.
 1.4.10.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.4.10.2 18-Sep-2004  skrll Sync with HEAD.
 1.4.10.1 03-Aug-2004  skrll Sync with HEAD
 1.5.4.1 03-Jan-2005  kent adopt the filter pipeline framework
 1.8.30.1 28-Aug-2017  skrll Sync with HEAD
 1.10.8.1 21-Apr-2019  isaki Adapt to audio2.
 1.10.4.1 10-Jun-2019  christos Sync with HEAD
 1.41 29-Jan-2020  thorpej Adopt <net/if_stats.h>.
 1.40 30-May-2019  msaitoh branches: 1.40.4;
Simplify MII structure initialization and reference. No functional change.
 1.39 28-May-2019  msaitoh Use ETHER_LOCK()/ETHER_UNLOCK() for all ethernet drivers to protect ec_multi*.
 1.38 23-May-2019  msaitoh -No functional change:
- Simplify struct ethercom's pointer near ETHER_FIRST_MULTI().
- Simplify MII structure initialization.
- u_int*_t -> uint*_t.
- KNF
 1.37 22-Jan-2019  msaitoh Change MII PHY read/write API from:

int (*mii_readreg_t)(device_t, int, int);
void (*mii_writereg_t)(device_t, int, int, int);
to:

int (*mii_readreg_t)(device_t, int, int, uint16_t *);
int (*mii_writereg_t)(device_t, int, int, uint16_t);

Now we can test if a read/write operation failed or not by the return value.

In 802.3 spec says that the PHY shall not respond to read/write transaction
to the unimplemented register(22.2.4.3). Detecting timeout can be used to
check whether a register is implemented or not (if the register conforms to
the spec). ukphy(4) can be used this for MII_MMDACR and MII_MMDAADR.

Note that I noticed that the following code do infinite loop in the
read/wirte function. If it accesses unimplemented PHY register, it will hang.
It should be fixed:

arm/at91/at91emac.c
arm/ep93xx/epe.c
arm/omap/omapl1x_emac.c
mips/ralink/ralink_eth.c
arch/powerpc/booke/dev/pq3etsec.c(read)
dev/cadence/if_cemac.c <- hkenken
dev/ic/lan9118.c


Tested with the following device:

axe+ukphy
axe+rgephy
axen+rgephy (tested by Andrius V)
wm+atphy
wm+ukphy
wm+igphy
wm+ihphy
wm+makphy
sk+makphy
sk+brgphy
sk+gentbi
msk+makphy
sip+icsphy
sip+ukphy
re+rgephy
bge+brgphy
bnx+brgphy
gsip+gphyter
rtk+rlphy
fxp+inphy (tested by Andrius V)
tlp+acphy
ex+exphy
epic+qsphy
vge+ciphy (tested by Andrius V)
vr+ukphy (tested by Andrius V)
vte+ukphy (tested by Andrius V)

Not tested (MAC):
arm:at91emac
arm:cemac
arm:epe
arm:geminigmac
arm:enet
arm:cpsw
arm:emac(omac)
arm:emac(sunxi)
arm:npe
evbppc:temac
macppc:bm
macppc:gm
mips:aumac
mips:ae
mips:cnmac
mips:reth
mips:sbmac
playstation2:smap
powerpc:tsec
powerpc:emac(ibm4xx)
sgimips:mec
sparc:be
sf
ne(ax88190, dl10019)
awge
ep
gem
hme
smsh
mtd
sm
age
alc
ale
bce
cas
et
jme
lii
nfe
pcn
ste
stge
tl
xi
aue
mue
smsc
udav
url

Not tested (PHY):
amhphy
bmtphy
dmphy
etphy
glxtphy
ikphy
iophy
lxtphy
nsphyter
pnaphy
rdcphy
sqphy
tlphy
tqphy
urlphy
 1.36 03-Sep-2018  riastradh Rename min/max -> uimin/uimax for better honesty.

These functions are defined on unsigned int. The generic name
min/max should not silently truncate to 32 bits on 64-bit systems.
This is purely a name change -- no functional change intended.

HOWEVER! Some subsystems have

#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))

even though our standard name for that is MIN/MAX. Although these
may invite multiple evaluation bugs, these do _not_ cause integer
truncation.

To avoid `fixing' these cases, I first changed the name in libkern,
and then compile-tested every file where min/max occurred in order to
confirm that it failed -- and thus confirm that nothing shadowed
min/max -- before changing it.

I have left a handful of bootloaders that are too annoying to
compile-test, and some dead code:

cobalt ews4800mips hp300 hppa ia64 luna68k vax
acorn32/if_ie.c (not included in any kernels)
macppc/if_gm.c (superseded by gem(4))

It should be easy to fix the fallout once identified -- this way of
doing things fails safe, and the goal here, after all, is to _avoid_
silent integer truncations, not introduce them.

Maybe one day we can reintroduce min/max as type-generic things that
never silently truncate. But we should avoid doing that for a while,
so that existing code has a chance to be detected by the compiler for
conversion to uimin/uimax without changing the semantics until we can
properly audit it all. (Who knows, maybe in some cases integer
truncation is actually intended!)
 1.35 26-Jun-2018  msaitoh branches: 1.35.2;
Implement the BPF direction filter (BIOC[GS]DIRECTION). It provides backward
compatibility with BIOC[GS]SEESENT ioctl. The userland interface is the same
as FreeBSD.

This change also fixes a bug that the direction is misunderstand on some
environment by passing the direction to bpf_mtap*() instead of checking
m->m_pkthdr.rcvif.
 1.34 22-Jun-2018  msaitoh It's not required to include net/bpfdesc.h. Remove it.
 1.33 15-Dec-2016  ozaki-r branches: 1.33.8; 1.33.14;
Move bpf_mtap and if_ipackets++ on Rx of each driver to percpuq if_input

The benefits of the change are:
- We can reduce codes
- We can provide the same behavior between drivers
- Where/When if_ipackets is counted up
- Note that some drivers still update packet statistics in their own
way (periodical update)
- Moved bpf_mtap run in softint
- This makes it easy to MP-ify bpf

Proposed on tech-kern and tech-net
 1.32 02-Oct-2016  christos MFREE -> m_free
 1.31 10-Jun-2016  ozaki-r branches: 1.31.2;
Introduce m_set_rcvif and m_reset_rcvif

The API is used to set (or reset) a received interface of a mbuf.
They are counterpart of m_get_rcvif, which will come in another
commit, hide internal of rcvif operation, and reduce the diff of
the upcoming change.

No functional change.
 1.30 09-Feb-2016  ozaki-r Introduce softint-based if_input

This change intends to run the whole network stack in softint context
(or normal LWP), not hardware interrupt context. Note that the work is
still incomplete by this change; to that end, we also have to softint-ify
if_link_state_change (and bpf) which can still run in hardware interrupt.

This change softint-ifies at ifp->if_input that is called from
each device driver (and ieee80211_input) to ensure Layer 2 runs
in softint (e.g., ether_input and bridge_input). To this end,
we provide a framework (called percpuq) that utlizes softint(9)
and percpu ifqueues. With this patch, rxintr of most drivers just
queues received packets and schedules a softint, and the softint
dequeues packets and does rest packet processing.

To minimize changes to each driver, percpuq is allocated in struct
ifnet for now and that is initialized by default (in if_attach).
We probably have to move percpuq to softc of each driver, but it's
future work. At this point, only wm(4) has percpuq in its softc
as a reference implementation.

Additional information including performance numbers can be found
in the thread at tech-kern@ and tech-net@:
http://mail-index.netbsd.org/tech-kern/2016/01/14/msg019997.html

Acknowledgment: riastradh@ greatly helped this work.
Thank you very much!
 1.29 10-Aug-2014  tls branches: 1.29.4;
Merge tls-earlyentropy branch into HEAD.
 1.28 17-Oct-2013  christos branches: 1.28.2;
- remove unused variables
- move variables inside ifdef sections
- ifdef notdef unused code
- use __USE for debugging variables
 1.27 27-Oct-2012  chs branches: 1.27.2;
split device_t/softc for all remaining drivers.
replace "struct device *" with "device_t".
use device_xname(), device_unit(), etc.
 1.26 22-Jul-2012  matt branches: 1.26.2;
Fix mii_statchg to take a 'struct ifnet *' instead of device_t. This fixes
problem with a common MDIO bus used for multiple interfaces.
Some drivers converted to CFATTACL_DECL_NEW.
 1.25 02-Feb-2012  tls Entropy-pool implementation move and cleanup.

1) Move core entropy-pool code and source/sink/sample management code
to sys/kern from sys/dev.

2) Remove use of NRND as test for presence of entropy-pool code throughout
source tree.

3) Remove use of RND_ENABLED in device drivers as microoptimization to
avoid expensive operations on disabled entropy sources; make the
rnd_add calls do this directly so all callers benefit.

4) Fix bug in recent rnd_add_data()/rnd_add_uint32() changes that might
have lead to slight entropy overestimation for some sources.

5) Add new source types for environmental sensors, power sensors, VM
system events, and skew between clocks, with a sample implementation
for each.

ok releng to go in before the branch due to the difficulty of later
pullup (widespread #ifdef removal and moved files). Tested with release
builds on amd64 and evbarm and live testing on amd64.
 1.24 05-Apr-2010  joerg branches: 1.24.8; 1.24.12;
Push the bpf_ops usage back into bpf.h. Push the common ifp->if_bpf
check into the inline functions as well the fourth argument for
bpf_attach.
 1.23 19-Jan-2010  pooka branches: 1.23.2; 1.23.4;
Redefine bpf linkage through an always present op vector, i.e.
#if NBPFILTER is no longer required in the client. This change
doesn't yet add support for loading bpf as a module, since drivers
can register before bpf is attached. However, callers of bpf can
now be modularized.

Dynamically loadable bpf could probably be done fairly easily with
coordination from the stub driver and the real driver by registering
attachments in the stub before the real driver is loaded and doing
a handoff. ... and I'm not going to ponder the depths of unload
here.

Tested with i386/MONOLITHIC, modified MONOLITHIC without bpf and rump.
 1.22 12-May-2009  cegger struct device * -> device_t, no functional changes intended.
 1.21 14-Mar-2009  dsl ANSIfy another 1261 function definitions.
The only ones left in sys are beyond by sed script!
(or in sys/dist or sys/external)
Mostly they have function pointer parameters.
 1.20 28-Apr-2008  martin branches: 1.20.8; 1.20.14;
Remove clause 3 and 4 from TNF licenses
 1.19 08-Apr-2008  cegger branches: 1.19.2; 1.19.4;
use aprint_*_dev and device_xname
 1.18 12-Mar-2008  dyoung Cosmetic: use device_t and accessors. Change to ANSI-style
prototypes. Delete some dead code.
 1.17 19-Jan-2008  dyoung branches: 1.17.2; 1.17.6;
Make many ethernet drivers share the common code for MII media
handling, ether_mediastatus() and ether_mediachange(). Check for
a non-ENXIO error return from mii_mediachg(). (ENXIO indicates
that a PHY is suspended.)

This patch shrinks the source code size by 979 lines. There was
a 5100-byte savings on the NetBSD/i386 kernel configuration, ALL.

I have made a few miscellaneous changes, too:

gem(4): use LIST_EMPTY(), LIST_FOREACH().
mtd(4): handle media ioctls, for a change!
axe(4): do not track link status in sc->axe_link any longer
nfe(4), aue(4), axe(4), udav(4), url(4): do not reset all PHYs
on a change of media

Except for the change to mtd(4), no functional changes are intended.

XXX This patch affects more architectures than I can feasibly
XXX compile and run. I have compiled macppc, sparc64, i386. I
XXX have run the patches on i386 boxen with bnx(4) and sip(4).
XXX Compiling and running on evbmips (MERAKI, ADM5120) is in
XXX progress.
 1.16 05-Dec-2007  ad branches: 1.16.4;
lockmgr -> mutex
 1.15 19-Oct-2007  ad branches: 1.15.2; 1.15.4;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.14 01-Sep-2007  dyoung branches: 1.14.4;
Change a bazillion occurrences of code resembling this,

error = (cmd == SIOCADDMULTI) ?
ether_addmulti(ifr, &sc->sc_ec) :
ether_delmulti(ifr, &sc->sc_ec);

if (error == ENETRESET) {

to this,

if ((error = ether_ioctl(ifp, cmd, data)) == ENETRESET) {

which does the same thing.

(A bazillion is a very large number. This seems to make the i386
ALL kernel smaller by 3kB to 4kB.)

Use ifreq_getaddr() twice in es(4).

Whitespace nits.
 1.13 04-Mar-2007  christos branches: 1.13.2; 1.13.10; 1.13.14; 1.13.16;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.12 16-Nov-2006  christos branches: 1.12.4;
__unused removal on arguments; approved by core.
 1.11 12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.10 20-Feb-2006  thorpej branches: 1.10.14; 1.10.16;
Use device_is_active() rather than testing dv_flags for DVF_ACTIVE
directly.
 1.9 11-Dec-2005  christos branches: 1.9.2; 1.9.4; 1.9.6;
merge ktrace-lwp.
 1.8 27-Feb-2005  perry branches: 1.8.4;
nuke trailing whitespace
 1.7 04-Feb-2005  perry de-__P
 1.6 30-Oct-2004  thorpej branches: 1.6.4; 1.6.6;
When adding/deleting multicast addresses, only whack the address
filter if the interface is marked RUNNING.

Fixes kern/27678.
 1.5 02-Nov-2003  wiz Fix some typos. From Tom Cosgrove via jmc@openbsd.
 1.4 23-Sep-2003  martin Fix rx buffer size bitmask, do not explicitly set burst length and use 1536
bytes buffers, so this driver can finally cope with full size ethernet
packets. From Peter Bex.
 1.3 14-Jul-2003  lukem add missing __KERNEL_RCSID()
 1.2 06-Jan-2003  wiz branches: 1.2.2;
descriptor with a c.
 1.1 07-Nov-2002  martin branches: 1.1.2;
Add a driver for the Myson Technology MTD803 3-in-1 Fast Ethernet Controller,
provided by Peter Bex in PR 18675.
 1.1.2.3 07-Jan-2003  thorpej Sync with HEAD.
 1.1.2.2 11-Nov-2002  nathanw Catch up to -current
 1.1.2.1 07-Nov-2002  nathanw file mtd803.c was added on branch nathanw_sa on 2002-11-11 22:09:52 +0000
 1.2.2.6 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.2.2.5 04-Feb-2005  skrll Sync with HEAD.
 1.2.2.4 02-Nov-2004  skrll Sync with HEAD.
 1.2.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.2.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.2.2.1 03-Aug-2004  skrll Sync with HEAD
 1.6.6.2 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.6.6.1 12-Feb-2005  yamt sync with head.
 1.6.4.1 29-Apr-2005  kent sync with -current
 1.8.4.7 17-Mar-2008  yamt sync with head.
 1.8.4.6 21-Jan-2008  yamt sync with head
 1.8.4.5 07-Dec-2007  yamt sync with head
 1.8.4.4 27-Oct-2007  yamt sync with head.
 1.8.4.3 03-Sep-2007  yamt sync with head.
 1.8.4.2 30-Dec-2006  yamt sync with head.
 1.8.4.1 21-Jun-2006  yamt sync with head.
 1.9.6.1 22-Apr-2006  simonb Sync with head.
 1.9.4.1 09-Sep-2006  rpaulo sync with head
 1.9.2.1 01-Mar-2006  yamt sync with head.
 1.10.16.2 10-Dec-2006  yamt sync with head.
 1.10.16.1 22-Oct-2006  yamt sync with head
 1.10.14.1 18-Nov-2006  ad Sync with head.
 1.12.4.1 12-Mar-2007  rmind Sync with HEAD.
 1.13.16.3 23-Mar-2008  matt sync with HEAD
 1.13.16.2 09-Jan-2008  matt sync with HEAD
 1.13.16.1 06-Nov-2007  matt sync with HEAD
 1.13.14.3 09-Dec-2007  jmcneill Sync with HEAD.
 1.13.14.2 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.13.14.1 03-Sep-2007  jmcneill Sync with HEAD.
 1.13.10.1 03-Sep-2007  skrll Sync with HEAD.
 1.13.2.2 23-Oct-2007  ad Sync with head.
 1.13.2.1 09-Oct-2007  ad Sync with head.
 1.14.4.1 25-Oct-2007  bouyer Sync with HEAD.
 1.15.4.1 08-Dec-2007  ad Sync with head.
 1.15.2.2 18-Feb-2008  mjf Sync with HEAD.
 1.15.2.1 08-Dec-2007  mjf Sync with HEAD.
 1.16.4.1 20-Jan-2008  bouyer Sync with HEAD
 1.17.6.2 02-Jun-2008  mjf Sync with HEAD.
 1.17.6.1 03-Apr-2008  mjf Sync with HEAD.
 1.17.2.1 24-Mar-2008  keiichi sync with head.
 1.19.4.5 11-Aug-2010  yamt sync with head.
 1.19.4.4 11-Mar-2010  yamt sync with head
 1.19.4.3 16-May-2009  yamt sync with head
 1.19.4.2 04-May-2009  yamt sync with head.
 1.19.4.1 16-May-2008  yamt sync with head.
 1.19.2.1 18-May-2008  yamt sync with head.
 1.20.14.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.20.8.1 28-Apr-2009  skrll Sync with HEAD.
 1.23.4.1 30-May-2010  rmind sync with head
 1.23.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.24.12.1 18-Feb-2012  mrg merge to -current.
 1.24.8.3 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.24.8.2 30-Oct-2012  yamt sync with head
 1.24.8.1 17-Apr-2012  yamt sync with head
 1.26.2.3 03-Dec-2017  jdolecek update from HEAD
 1.26.2.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.26.2.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.27.2.1 18-May-2014  rmind sync with head
 1.28.2.1 07-Apr-2014  tls Be a little more clear and consistent about harvesting entropy from devices:

1) deprecate RND_FLAG_NO_ESTIMATE

2) define RND_FLAG_COLLECT_TIME, RND_FLAG_COLLECT_VALUE

3) define RND_FLAG_ESTIMATE_TIME, RND_FLAG_ESTIMATE_VALUE

4) define RND_FLAG_DEFAULT: RND_FLAG_COLLECT_TIME|
RND_FLAG_COLLECT_VALUE|RND_FLAG_ESTIMATE_TIME

5) Make entropy harvesting from environmental sensors a little more generic
and remove it from individual sensor drivers.

6) Remove individual open-coded delta-estimators for values from a few
places in the tree (uvm, environmental drivers).

7) 0 -> RND_FLAG_DEFAULT, actually gather entropy from various drivers
that had stubbed out code, other minor cleanups.
 1.29.4.4 05-Feb-2017  skrll Sync with HEAD
 1.29.4.3 05-Oct-2016  skrll Sync with HEAD
 1.29.4.2 09-Jul-2016  skrll Sync with HEAD
 1.29.4.1 19-Mar-2016  skrll Sync with HEAD
 1.31.2.2 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.31.2.1 04-Nov-2016  pgoyette Sync with HEAD
 1.33.14.4 26-Jan-2019  pgoyette Sync with HEAD
 1.33.14.3 06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.33.14.2 28-Jul-2018  pgoyette Sync with HEAD
 1.33.14.1 25-Jun-2018  pgoyette Sync with HEAD
 1.33.8.1 26-Jul-2018  snj Pull up following revision(s) (requested by msaitoh in ticket #938):
sys/arch/acorn32/podulebus/if_ie.c: revision 1.41
sys/arch/amiga/dev/if_es.c: revision 1.58
sys/arch/amiga/dev/if_qn.c: revision 1.45
sys/arch/arm/at91/at91emac.c: revision 1.20
sys/arch/arm/ep93xx/epe.c: revision 1.37
sys/arch/emips/ebus/if_le_ebus.c: revision 1.14
sys/arch/emips/ebus/if_le_ebus.c: revision 1.15
sys/arch/mac68k/dev/if_mc.c: revision 1.46
sys/arch/macppc/dev/am79c950.c: revision 1.39
sys/arch/newsmips/apbus/if_sn.c: revision 1.40
sys/arch/next68k/dev/mb8795.c: revision 1.59
sys/arch/playstation2/dev/if_smap.c: revision 1.25
sys/arch/playstation2/dev/if_smap.c: revision 1.26
sys/arch/sun2/dev/if_ec.c: revision 1.28
sys/arch/sun3/dev/if_ie.c: revision 1.63
sys/arch/x68k/dev/if_ne_intio.c: revision 1.19
sys/arch/xen/xen/if_xennet_xenbus.c: revision 1.75
sys/arch/xen/xen/xennetback_xenbus.c: revision 1.63
sys/dev/bi/if_ni.c: revision 1.45
sys/dev/cadence/if_cemac.c: revision 1.12
sys/dev/ic/am7990.c: revision 1.78
sys/dev/ic/am79900.c: revision 1.27
sys/dev/ic/an.c: revision 1.67
sys/dev/ic/cs89x0.c: revision 1.40
sys/dev/ic/dm9000.c: revision 1.13
sys/dev/ic/dm9000.c: revision 1.14
sys/dev/ic/dp8390.c: revision 1.88
sys/dev/ic/elink3.c: revision 1.141
sys/dev/ic/elinkxl.c: revision 1.122
sys/dev/ic/hme.c: revision 1.98
sys/dev/ic/i82586.c: revision 1.77
sys/dev/ic/lance.c: revision 1.53
sys/dev/ic/mb86950.c: revision 1.27
sys/dev/ic/mb86960.c: revision 1.86
sys/dev/ic/mtd803.c: revision 1.34
sys/dev/ic/pdq_ifsubr.c: revision 1.59
sys/dev/ic/rrunner.c: revision 1.86
sys/dev/ic/seeq8005.c: revision 1.58
sys/dev/ic/sgec.c: revision 1.47
sys/dev/ic/smc90cx6.c: revision 1.72
sys/dev/ic/smc91cxx.c: revision 1.96
sys/dev/ic/tropic.c: revision 1.49
sys/dev/ic/wi.c: revision 1.245
sys/dev/isa/if_eg.c: revision 1.93
sys/dev/isa/if_el.c: revision 1.95
sys/dev/isa/if_iy.c: revision 1.101
sys/dev/ofw/ofnet.c: revision 1.58
sys/dev/pci/if_alc.c: revision 1.27
sys/dev/pci/if_de.c: revision 1.152
sys/dev/pci/if_fpa.c: revision 1.61
sys/dev/pci/if_jme.c: revision 1.34
sys/dev/pci/if_tl.c: revision 1.108
sys/dev/pci/if_vte.c: revision 1.19
sys/dev/pci/ixgbe/ixgbe.h: revision 1.50
sys/dev/pcmcia/if_cnw.c: revision 1.62
sys/dev/pcmcia/if_malo_pcmcia.c: revision 1.17
sys/dev/pcmcia/if_ray.c: revision 1.89
sys/dev/pcmcia/if_xi.c: revision 1.81
sys/dev/pcmcia/mhzc.c: revision 1.51
sys/dev/pcmcia/xirc.c: revision 1.34
sys/dev/qbus/if_de.c: revision 1.33
sys/dev/qbus/if_qe.c: revision 1.78
sys/dev/qbus/if_qt.c: revision 1.22
sys/dev/sbus/be.c: revision 1.87
sys/dev/sbus/qe.c: revision 1.68
sys/dev/scsipi/if_se.c: revision 1.96
sys/dev/usb/if_atu.c: revision 1.59
sys/net/if_l2tp.c: revision 1.28 via patch
sys/net/if_ppp.c: revision 1.160
It's not required to include net/bpfdesc.h. Remove it.
--
Simplify like other drivers. NULL check of ifp->if_bpf is done in
bpf_mtap(), so it's not required to do it here.
--
Remove duplicated inclusion of net/bpf.h.
--
Remove duplicated inclusion of net/bpf.h.
--
Simplify bpf_mtap() call. No functional change.
 1.35.2.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.35.2.1 10-Jun-2019  christos Sync with HEAD
 1.40.4.1 29-Feb-2020  ad Sync with head.
 1.3 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.2 07-Mar-2006  wiz branches: 1.2.60; 1.2.62; 1.2.64;
'advertisment' -> 'advertisement', from leonardo chiquitto filho
via jmc@openbsd.
 1.1 07-Nov-2002  martin branches: 1.1.2; 1.1.24; 1.1.38; 1.1.40; 1.1.42; 1.1.44;
Add a driver for the Myson Technology MTD803 3-in-1 Fast Ethernet Controller,
provided by Peter Bex in PR 18675.
 1.1.44.1 19-Apr-2006  elad sync with head.
 1.1.42.1 13-Mar-2006  yamt sync with head.
 1.1.40.1 22-Apr-2006  simonb Sync with head.
 1.1.38.1 09-Sep-2006  rpaulo sync with head
 1.1.24.1 21-Jun-2006  yamt sync with head.
 1.1.2.2 11-Nov-2002  nathanw Catch up to -current
 1.1.2.1 07-Nov-2002  nathanw file mtd803reg.h was added on branch nathanw_sa on 2002-11-11 22:09:53 +0000
 1.2.64.1 16-May-2008  yamt sync with head.
 1.2.62.1 18-May-2008  yamt sync with head.
 1.2.60.1 02-Jun-2008  mjf Sync with HEAD.
 1.10 13-Apr-2015  riastradh Convert sys/dev to use <sys/rndsource.h>.
 1.9 27-Oct-2012  chs branches: 1.9.14;
split device_t/softc for all remaining drivers.
replace "struct device *" with "device_t".
use device_xname(), device_unit(), etc.
 1.8 02-Feb-2012  tls branches: 1.8.6;
Entropy-pool implementation move and cleanup.

1) Move core entropy-pool code and source/sink/sample management code
to sys/kern from sys/dev.

2) Remove use of NRND as test for presence of entropy-pool code throughout
source tree.

3) Remove use of RND_ENABLED in device drivers as microoptimization to
avoid expensive operations on disabled entropy sources; make the
rnd_add calls do this directly so all callers benefit.

4) Fix bug in recent rnd_add_data()/rnd_add_uint32() changes that might
have lead to slight entropy overestimation for some sources.

5) Add new source types for environmental sensors, power sensors, VM
system events, and skew between clocks, with a sample implementation
for each.

ok releng to go in before the branch due to the difficulty of later
pullup (widespread #ifdef removal and moved files). Tested with release
builds on amd64 and evbarm and live testing on amd64.
 1.7 19-Nov-2011  tls branches: 1.7.2;
First step of random number subsystem rework described in
<20111022023242.BA26F14A158@mail.netbsd.org>. This change includes
the following:

An initial cleanup and minor reorganization of the entropy pool
code in sys/dev/rnd.c and sys/dev/rndpool.c. Several bugs are
fixed. Some effort is made to accumulate entropy more quickly at
boot time.

A generic interface, "rndsink", is added, for stream generators to
request that they be re-keyed with good quality entropy from the pool
as soon as it is available.

The arc4random()/arc4randbytes() implementation in libkern is
adjusted to use the rndsink interface for rekeying, which helps
address the problem of low-quality keys at boot time.

An implementation of the FIPS 140-2 statistical tests for random
number generator quality is provided (libkern/rngtest.c). This
is based on Greg Rose's implementation from Qualcomm.

A new random stream generator, nist_ctr_drbg, is provided. It is
based on an implementation of the NIST SP800-90 CTR_DRBG by
Henric Jungheim. This generator users AES in a modified counter
mode to generate a backtracking-resistant random stream.

An abstraction layer, "cprng", is provided for in-kernel consumers
of randomness. The arc4random/arc4randbytes API is deprecated for
in-kernel use. It is replaced by "cprng_strong". The current
cprng_fast implementation wraps the existing arc4random
implementation. The current cprng_strong implementation wraps the
new CTR_DRBG implementation. Both interfaces are rekeyed from
the entropy pool automatically at intervals justifiable from best
current cryptographic practice.

In some quick tests, cprng_fast() is about the same speed as
the old arc4randbytes(), and cprng_strong() is about 20% faster
than rnd_extract_data(). Performance is expected to improve.

The AES code in src/crypto/rijndael is no longer an optional
kernel component, as it is required by cprng_strong, which is
not an optional kernel component.

The entropy pool output is subjected to the rngtest tests at
startup time; if it fails, the system will reboot. There is
approximately a 3/10000 chance of a false positive from these
tests. Entropy pool _input_ from hardware random numbers is
subjected to the rngtest tests at attach time, as well as the
FIPS continuous-output test, to detect bad or stuck hardware
RNGs; if any are detected, they are detached, but the system
continues to run.

A problem with rndctl(8) is fixed -- datastructures with
pointers in arrays are no longer passed to userspace (this
was not a security problem, but rather a major issue for
compat32). A new kernel will require a new rndctl.

The sysctl kern.arandom() and kern.urandom() nodes are hooked
up to the new generators, but the /dev/*random pseudodevices
are not, yet.

Manual pages for the new kernel interfaces are forthcoming.
 1.6 28-Apr-2008  martin branches: 1.6.34;
Remove clause 3 and 4 from TNF licenses
 1.5 04-Mar-2007  christos branches: 1.5.36; 1.5.38; 1.5.40;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.4 11-Dec-2005  christos branches: 1.4.26;
merge ktrace-lwp.
 1.3 04-Feb-2005  perry branches: 1.3.6;
de-__P
 1.2 23-Sep-2003  martin branches: 1.2.8; 1.2.10;
Fix rx buffer size bitmask, do not explicitly set burst length and use 1536
bytes buffers, so this driver can finally cope with full size ethernet
packets. From Peter Bex.
 1.1 07-Nov-2002  martin branches: 1.1.2; 1.1.8;
Add a driver for the Myson Technology MTD803 3-in-1 Fast Ethernet Controller,
provided by Peter Bex in PR 18675.
 1.1.8.4 04-Feb-2005  skrll Sync with HEAD.
 1.1.8.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.1.8.2 18-Sep-2004  skrll Sync with HEAD.
 1.1.8.1 03-Aug-2004  skrll Sync with HEAD
 1.1.2.2 11-Nov-2002  nathanw Catch up to -current
 1.1.2.1 07-Nov-2002  nathanw file mtd803var.h was added on branch nathanw_sa on 2002-11-11 22:09:54 +0000
 1.2.10.1 12-Feb-2005  yamt sync with head.
 1.2.8.1 29-Apr-2005  kent sync with -current
 1.3.6.1 03-Sep-2007  yamt sync with head.
 1.4.26.1 12-Mar-2007  rmind Sync with HEAD.
 1.5.40.1 16-May-2008  yamt sync with head.
 1.5.38.1 18-May-2008  yamt sync with head.
 1.5.36.1 02-Jun-2008  mjf Sync with HEAD.
 1.6.34.2 30-Oct-2012  yamt sync with head
 1.6.34.1 17-Apr-2012  yamt sync with head
 1.7.2.1 18-Feb-2012  mrg merge to -current.
 1.8.6.2 03-Dec-2017  jdolecek update from HEAD
 1.8.6.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.9.14.1 06-Jun-2015  skrll Sync with HEAD
 1.62 05-Dec-2021  msaitoh s/coresponding/corresponding/ in comment.
 1.61 05-Oct-2021  rin PR kern/56403

Fix kernel freeze for wdc(4) variants with ATAC_CAP_NOIRQ:

(1) Change ata_xfer_ops:c_poll from void to int function. When it returns
ATAPOLL_AGAIN, let ata_xfer_start() iterate itself again.

(2) Let wdc_ata_bio_poll() return ATAPOLL_AGAIN until ATA_ITSDONE is
achieved.

A similar change has been made for mvsata(4) (see mvsata_bio_poll()),
and no functional changes for other devices.

This is how the drivers worked before jdolecek-ncq branch was merged.

Note that this changes are less likely to cause infinite recursion:

(1) wdc_ata_bio_intr() called from wdc_ata_bio_poll() asserts ATA_ITSDONE
in its error handling paths via wdc_ata_bio_done().

(2) Return value from c_start (= wdc_ata_bio_start()) is checked in
ata_xfer_start().

Therefore, errors encountered in ata_xfer_ops:c_poll and c_start routines
terminate the recursion for wdc(4). The situation is similar for mvsata(4).

Still, there is a possibility where ata_xfer_start() takes long time to
finish a normal operation. This can result in a delayed response for lower
priority interrupts. But, I've never observed such a situation, even when
heavy thrashing takes place for swap partition in wd(4).

"Go ahead" by jdolecek@.
 1.60 07-Aug-2021  thorpej Merge thorpej-cfargs2.
 1.59 24-Apr-2021  thorpej branches: 1.59.8;
Merge thorpej-cfargs branch:

Simplify and make extensible the config_search() / config_found() /
config_attach() interfaces: rather than having different variants for
which arguments you want pass along, just have a single call that
takes a variadic list of tag-value arguments.

Adjust all call sites:
- Simplify wherever possible; don't pass along arguments that aren't
actually needed.
- Don't be explicit about what interface attribute is attaching if
the device only has one. (More simplification.)
- Add a config_probe() function to be used in indirect configuiration
situations, making is visibly easier to see when indirect config is
in play, and allowing for future change in semantics. (As of now,
this is just a wrapper around config_match(), but that is an
implementation detail.)

Remove unnecessary or redundant interface attributes where they're not
needed.

There are currently 5 "cfargs" defined:
- CFARG_SUBMATCH (submatch function for direct config)
- CFARG_SEARCH (search function for indirect config)
- CFARG_IATTR (interface attribte)
- CFARG_LOCATORS (locators array)
- CFARG_DEVHANDLE (devhandle_t - wraps OFW, ACPI, etc. handles)

...and a sentinel value CFARG_EOL.

Add some extra sanity checking to ensure that interface attributes
aren't ambiguous.

Use CFARG_DEVHANDLE in MI FDT, OFW, and ACPI code, and macppc and shark
ports to associate those device handles with device_t instance. This
will trickle trough to more places over time (need back-end for pre-OFW
Sun OBP; any others?).
 1.58 25-Dec-2020  skrll branches: 1.58.2;
Use designated initializers for struct ata_bustype
 1.57 19-May-2020  jdolecek branches: 1.57.2;
only start the timeout machinery once the I/O is completely setup
and successful, particularly after PIO write is finished

fixes crashes in case the setup is so slow that timeout is triggered
e.g. while still waiting in wdc_wait_for_unbusy() or shortly after, without
drive actually having chance to complete the I/O, as seen in some
configuration under QEMU by Paul Ripke
 1.56 13-Apr-2020  jdolecek fix use-after-free for ata xfer on bio submission found by KASAN

driver ata_bio hooks read parts of the xfer after ata_exec_xfer()
call in order to determine return value, change so that the hook
doesn't return any value - callers do not care already,
as all I/O requests are asynchronous

this problem was uncovered by recent change for wd(4) to not hold
wd mutex during ata_bio call, the interrupt for the xfer might
thus actually fire immediately

adjust also ata_exec_command driver hooks similarily - remove all
completion and waiting logic from drivers, upper layer ata code
using AT_WAIT/AT_POLL changed to call ata_wait_cmd() itself

PR kern/55169 by Nick Hudson
 1.55 04-Apr-2020  jdolecek branches: 1.55.2;
fix deadlock in wdcwait() when xfer timeout happens while the atabus
thread sleeps in wdcwait() - check current lwp rather than relying
on global ATACH_TH_RUN channel flag

should fix the hang part of the problem reported in
http://mail-index.netbsd.org/netbsd-users/2020/03/12/msg024249.html

thanks to Paul Ripke for providing extensive debugging info
 1.54 22-Mar-2020  macallan do not assume that a bus_space_handle_t is simply an offset
now this has a fighting chance of working on sparc64
 1.53 19-Feb-2020  riastradh C99 initializers for scsipi_bustype. No functional change intended.
 1.52 27-Dec-2019  msaitoh branches: 1.52.2;
s/transfered/transferred/
 1.51 22-Dec-2019  jdolecek don't treat the EDMA self disable as autoconfig error, it's perfectly
normal at least during boot when device connection is reported by controller
 1.50 22-Dec-2019  jdolecek remove check for idle status when disabling EDMA, and always toggle
the disable regardless of current state - this particularly seems
to fail during error recovery, and on my system this also fails
during regular boot

this matches both FreeBSD and Linux drivers - neither of those checks
the idle status

should help with PR kern/52419 and maybe also the lock spinout part
of PR kern/52126
 1.49 10-Nov-2019  chs in many device attach paths, allocate memory with M_WAITOK instead of M_NOWAIT
and remove code to handle failures that can no longer happen.
 1.48 23-Jun-2019  tsutsui branches: 1.48.2;
Add a missing newline in an error message. Noticed in PR/54205
 1.47 23-Jun-2019  tsutsui Fix "mvsata:0:0:1: buffer load failed: error=27" failure. PR/54205

Ok'ed by jdolecek@.
Should be pulled up to netbsd-8.
 1.46 12-Nov-2018  jdolecek pass correct status + error to *_atapi_phase_complete(), so that
the function is actually able to recognize when there was an error;
tested via reading a cd0 device in QEMU with ejected cdrom

bug was introduced with jdolecek-ncq branch

fixes PR kern/53724 by Andreas Gustafsson
 1.45 12-Nov-2018  jdolecek hold channel lock during whole ata_dmaerr()/ata_downgrade_mode() -
according to code inspection this is safe, none of the set_modes
hooks execute anything which would be taking the lock

adresses PR kern/53714 by Andreas Gustafsson
 1.44 22-Oct-2018  jdolecek move mvsata(4) related items from ata/TODO.ncq to dev/ic/mvsata.c, it's
unlikely this will ever be done, but still good to note somewhere
 1.43 22-Oct-2018  jdolecek Merge jdolecek-ncqfixes branch

- ata_xfer's are dynamicall allocated as needed using a pool, no longer
limited to number of possible openings supported by controller; dump
and recovery paths use dedicated pre-allocated storage
- moved callouts and condvars from ata_xfer to queue or channel, so that
ata_xfer does not need special initialization
- slot allocation now done when xfer is being activated, uncoupled
from memory allocation; active slots are no longer tracked by controller
code
- channel and drive reset is done always via the atabus thread, and
now executes with channel locked the whole time
- NCQ recovery moved to shared function, and run via the thread also
- added some workarounds for buggy error recovery AHCI emulation in QEMU
and Parallels

designed to primarily fix kern/52614, but might also help with kern/47041
and kern/53183
 1.42 03-Sep-2018  riastradh Rename min/max -> uimin/uimax for better honesty.

These functions are defined on unsigned int. The generic name
min/max should not silently truncate to 32 bits on 64-bit systems.
This is purely a name change -- no functional change intended.

HOWEVER! Some subsystems have

#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))

even though our standard name for that is MIN/MAX. Although these
may invite multiple evaluation bugs, these do _not_ cause integer
truncation.

To avoid `fixing' these cases, I first changed the name in libkern,
and then compile-tested every file where min/max occurred in order to
confirm that it failed -- and thus confirm that nothing shadowed
min/max -- before changing it.

I have left a handful of bootloaders that are too annoying to
compile-test, and some dead code:

cobalt ews4800mips hp300 hppa ia64 luna68k vax
acorn32/if_ie.c (not included in any kernels)
macppc/if_gm.c (superseded by gem(4))

It should be easy to fix the fallout once identified -- this way of
doing things fails safe, and the goal here, after all, is to _avoid_
silent integer truncations, not introduce them.

Maybe one day we can reintroduce min/max as type-generic things that
never silently truncate. But we should avoid doing that for a while,
so that existing code has a chance to be detected by the compiler for
conversion to uimin/uimax without changing the semantics until we can
properly audit it all. (Who knows, maybe in some cases integer
truncation is actually intended!)
 1.41 31-Aug-2018  jdolecek branches: 1.41.2;
constify mvsata_pci_products[]
 1.40 08-Apr-2018  mlelstv branches: 1.40.2;
Avoid rounding errors for timeout values.
 1.39 17-Oct-2017  jdolecek branches: 1.39.2;
no need to clear DMA WAIT flag in mvsata_edma_handle(), it's not needed
by atabus layer
 1.38 10-Oct-2017  jdolecek make compile with ATAPI_DEBUG_PROBE (by copying over the code from
atapi_wdc.c), which is on e.g. for i386/amd64 ALL kernels
problem found by hannken@, thanks
 1.37 08-Oct-2017  joerg Initialize tfd even when not waiting for DSC.
 1.36 07-Oct-2017  jdolecek Merge support for SATA NCQ (Native Command Queueing) from jdolecek-ncq branch

ATA subsystem was changed to support several outstanding commands, and use
NCQ xfers if supported by both the controller and the disk, including NCQ
error recovery. Set NCQ high priority for BPRIO_TIMECRITICAL xfers
if supported. Added FUA support.

Done some work towards MP-safe, all ATA code tsleep()/wakeup() replaced
by condvars, and switched most code from spl* to mutexes (separate
wd(4) and ata channel lock).

Introduced new option WD_CHAOS_MONKEY to facilitate testing of error
handling, fixed several uncovered issues. Also fixed several problems
with kernel dump to wd(4) disk.

Tested with ahcisata(4), mvsata(4), siisata(4), piixide(4) on amd64,
with and without port multiplier, both disk and ATAPI devices; other
drivers and archs mechanically adjusted and compile-tested. NCQ is
supported for ahcisata(4) and siisata(4) for any controller, for
mvsata(4) only Gen IIe ones for now. Also enabled ATAPI support in
mvsata(4).

Thanks to Matt Thomas for initial ATA infrastructure patch, and
Jonathan A.Kollasch for siisata(4) NCQ changes and general testing.

Also fixes PR kern/43169 (wd(4)); and PR kern/11811, PR kern/47041,
PR kern/51979 (kernel dump)
 1.35 02-May-2016  christos branches: 1.35.6; 1.35.10;
move scsipi_strvis -> libkern:strnvisx()
change the prototype to match userland
fix sizes of strings passed to it
 1.34 02-Jan-2015  christos We have three sets of DTYPE_ constants in the kernel:
altq Drop Type
disklabel Disk Type
file Descriptor Type
(not to mention constants that contain the string DTYPE).
Let's make them two, by changing the disklabel one to be DisK TYPE since the
other disklabel constants seem to do that. Not many userland programs use
these constants (and the ones that they do are mostly in ifdefs). They will
be fixed shortly.
 1.33 17-Feb-2014  kiyohara branches: 1.33.6;
More delay() for some drives.
 1.32 01-Sep-2013  kiyohara Declare mvsata_probe_drive() when defined MVSATA_WITHOUTDMA.
And more delay() for some machines.
 1.31 06-May-2013  jakllsch branches: 1.31.4;
Put back AT_POLL hack in mvsata_bio_ready(). Without it 1.5Gbps
SATA WD800JD drives cause the kernel to stall during autoconf on
Orion.
 1.30 03-Apr-2013  bouyer Fix kernel dump on ahci controller, by making sure we won't sleep
while dumping:
- introduce ata_delay() which either use delay() or kpause()
depending on flags. use it in sata_reset_interface() and
some ahci functions
- kill ATA_NOSLEEP, it was tested but never set. use ATA_POLL instead.
- reduce delay while polling in ahci, to speed up the dump

Should fix PR kern/41095
 1.29 10-Feb-2013  jakllsch This change adds SATA port multiplier support to mvsata(4).
 1.28 10-Feb-2013  jakllsch Timeouts have priority over panicing.
 1.27 10-Feb-2013  jakllsch The device queue tag and the host queue tag are not the same thing.
We don't support device queueing yet, so write that tag as zero.
 1.26 10-Feb-2013  jakllsch We can't (well, actually we can, but we still can't) assume that all
ata_bios are LBA.
 1.25 03-Feb-2013  jakllsch Add argument to wdccommandext() to allow the entire contents of the
device/head register to be specified. Needed for upcoming port multipler
support in mvsata(4).
 1.24 31-Jul-2012  bouyer branches: 1.24.2;
Apply back changes that were reverted on Jul 24 and Jul 26 (general ata/wdc
cleanup and SATA PMP support), now that I'm back to fix the fallouts.
 1.23 26-Jul-2012  jakllsch Revert, with intention of restoring in a less invasive way, the SATA Port
Multiplier code.

ok christos@
 1.22 24-Jul-2012  jakllsch Revert dsl@'s changes of Sun, 15 Jul 2012 10:55:35 +0000 and
Sun, 15 Jul 2012 10:56:50 +0000, excepting the kernel version bump.
First step in reverting regressions to ata(4) subsystem during the addition of
port multiplier support.
 1.21 19-Jul-2012  jakllsch Fix MVSATA_WDC_* macros to actually access the Shadow Register Block.
 1.20 15-Jul-2012  dsl Some namespace protection (and add greppablity).
Prefix the DRIVE_ and DRIVET_ constants from atavar.h with ATA_.
Don't use an enum for drive_type - you don't know how big it will be.
Move driver_type to avoid implicit structure padding (esp on arm).
This change is purely lexical and mechanical.

Update to 6.99.9 - this wasn't done when the SATA PMP changes
were made - I'm sure they warranted a bump.
 1.19 15-Jul-2012  jakllsch Fix obvious copy/paste-induced error (my fault) that would clobber
the bottom 24-bits of r_lba during a LBA48 command with AT_READREG.
 1.18 12-Jul-2012  reinoud Fix surplus ( that was forgotten to remove in the DRIVE_ to DRIVET_ rototol.
 1.17 02-Jul-2012  bouyer Add sata Port MultiPlier (PMP) support to the ata bus layer,
as described in
http://mail-index.netbsd.org/tech-kern/2012/06/23/msg013442.html
PMP support in integrated to the atabus layer.
struct ata_channel's ch_drive[] is not dynamically allocated, and ch_ndrive
(renamed to ch_ndrives) closely reflects the size of the ch_drive[] array.
Add helper functions atabus_alloc_drives() and atabus_free_drives()
to manage ch_drive[]/ch_ndrives.
Add wdc_maxdrives to struct wdc_softc so that bus front-end can specify
how much drive they really support (master/slave or single).
ata_reset_drive() callback gains a uint32_t *sigp argument which,
when not NULL, will contain the signature of the device being reset.
While there, some cosmetic changes:
- added a drive_type enum to ata_drive_datas, and stop encoding the
probed drive type in drive_flags (we were out of drive flags anyway).
- rename DRIVE_ATAPIST to DRIVE_ATAPIDSCW to better reflect what this
really is
- remove ata_channel->ata_drives, it's redundant with the pointer in
ata_drive_datas
- factor out the interpretation of SATA signatures in sata_interpet_sig()

propagate these changes to the ATA HBA drivers, and add support for PMP
to ahcisata(4) and siisata(4).

Thanks to:
- Protocase (http://www.protocase.com/) which provided a system
with lots of controllers, SATA PMP and drive slots
- Conservation Genomics Laboratory, Department of Biology, New Mexico State
University for hosting the above system
- Brook Milligan, who set up remote access and has been very responsive
when SATA cable move was needed
 1.16 20-Apr-2012  bouyer Add a bustype_async_event_xfer_mode() callback to scsipi_bustype (which can
be NULL), so that transport-specific details of transfer mode setting/printing
can be handled more easily.
Move scsipi_async_event_xfer_mode() and scsipi_print_xfer_mode() to
scsi_base.c and split in parallel scsi and FC/SAS parts.
size of struct scsipi_bustype has changed, welcome to 6.99.5
 1.15 24-Jan-2012  jakllsch Rework struct ata_command to support LBA28 and LBA48-protocol commands.
Implement 28- and 48-bit command issuance and parameter read-back in the
various ATA host drivers. Add LBA28-protocol support to ATAIOCCOMMAND ioctl.
 1.14 22-Jan-2012  jakllsch Trailing whitespace.
 1.13 21-Jan-2012  jakllsch Correct some typos in comments, as was done in wdc.c 1.266.
 1.12 09-Jan-2012  jakllsch Instead of assume that 'features' is 0 in wdccommandext(),
pass it as an argument, as is done for wdccommand().
 1.11 01-Sep-2011  jakllsch branches: 1.11.2; 1.11.6;
It seems mvsata_bio_ready() is actually needed, and it seems
to work better if we always poll for completion for the
duration of this function.
 1.10 15-Aug-2011  jakllsch Even if the hardware can handle concurrent transfers, ata(4) can't.
Also, completely rework mvsata_bio_ready().

Seems to make mvsata(4) usable on 5182.
 1.9 14-Aug-2011  jakllsch Spell enqueue correctly.
 1.8 10-Mar-2011  jakllsch Shorten infinite loop. Tames atactl(8) atabus reset on mvsata(4).
 1.7 20-Feb-2011  riz Use PRId64 instead of lld, and PRIx64 instead of llx when compiling
with MVSATA_DEBUG.
 1.6 13-Jul-2010  kiyohara branches: 1.6.2; 1.6.4;
Fix wrong ifdef.
 1.5 13-Jul-2010  kiyohara Move to pci/mvsata_pci.c (marvell/mvsata_mv.c) splitting mvsata_products[].
mvsata(4) uses these to match.
 1.4 28-Mar-2010  snj Spell "enough" properly.
 1.3 05-Jan-2010  mbalmer branches: 1.3.2; 1.3.4;
Remove extra semicolons.
 1.2 03-Aug-2009  snj branches: 1.2.2;
Fix a typo inside a comment.
 1.1 27-Jul-2009  kiyohara Support Marvell Hercules-I/II SATA Controllers.
 1.2.2.4 11-Aug-2010  yamt sync with head.
 1.2.2.3 11-Mar-2010  yamt sync with head
 1.2.2.2 19-Aug-2009  yamt sync with head.
 1.2.2.1 03-Aug-2009  yamt file mvsata.c was added on branch yamt-nfs-mp on 2009-08-19 18:47:07 +0000
 1.3.4.3 21-Apr-2011  rmind sync with head
 1.3.4.2 05-Mar-2011  rmind sync with head
 1.3.4.1 30-May-2010  rmind sync with head
 1.3.2.2 17-Aug-2010  uebayasi Sync with HEAD.
 1.3.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.6.4.1 05-Mar-2011  bouyer Sync with HEAD
 1.6.2.1 06-Jun-2011  jruoho Sync with HEAD.
 1.11.6.2 29-Apr-2012  mrg sync to latest -current.
 1.11.6.1 18-Feb-2012  mrg merge to -current.
 1.11.2.4 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.11.2.3 30-Oct-2012  yamt sync with head
 1.11.2.2 23-May-2012  yamt sync with head.
 1.11.2.1 17-Apr-2012  yamt sync with head
 1.24.2.4 03-Dec-2017  jdolecek update from HEAD
 1.24.2.3 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.24.2.2 23-Jun-2013  tls resync from head
 1.24.2.1 25-Feb-2013  tls resync with head
 1.31.4.1 18-May-2014  rmind sync with head
 1.33.6.2 29-May-2016  skrll Sync with HEAD
 1.33.6.1 06-Apr-2015  skrll Sync with HEAD
 1.35.10.1 30-Jun-2019  martin Pull up following revision(s) (requested by tsutsui in ticket #1283):

sys/dev/ic/mvsata.c: revision 1.47
sys/dev/ic/mvsata.c: revision 1.48

Fix "mvsata:0:0:1: buffer load failed: error=27" failure. PR/54205
Ok'ed by jdolecek@.
Should be pulled up to netbsd-8.

Add a missing newline in an error message. Noticed in PR/54205
 1.35.6.32 30-Sep-2017  jdolecek must drop channel lock before calling ata_dmaerr() to avoid 'locking against
myself' in case of consecutive errors from ata_reset_channel() called via
ata_downgrade_mode()
 1.35.6.31 27-Sep-2017  jdolecek change wdc_init_shadow_regs() to accept only struct wdc_regs, it doesn't
touch anything else

factor out the probe-only struct ata_channel initialization to wdcprobe(), to
reduce duplication of logic in individual drivers, and to actually work now
that more init is needed beyond the memset()
 1.35.6.30 26-Sep-2017  jdolecek make compile without MVSATA_DEBUG
 1.35.6.29 25-Sep-2017  jdolecek move mvsata_quetag_get() to the start routines, so that it always matches
the active list of ata queue; important during error recovery, fixes
panics when calling

in mvsata_edma_handle() ignore events for non-active xfers

fix some missing ata_channel_unlock() on error path in mvsata_bio_intr()
and mvsata_atapi_intr(), fixes 'locking against myself' with LOCKDEBUG

with this, mvsata(4) finally survives full fio run with wdcdebug_wd_cnt == 200
 1.35.6.28 22-Sep-2017  jdolecek fix inverted logic for calling atastart()
 1.35.6.27 20-Sep-2017  jdolecek make compile again with MVSATA_WITHOUTDMA
 1.35.6.26 19-Sep-2017  jdolecek replace all remaining tsleep()/wakeup() calls with condition variables, or
calls to ata_delay(), as appropriate; change ata_delay() to require the
channel lock on entry, and pass the lock to kpause() for unlocking while
sleeping
 1.35.6.25 10-Sep-2017  jdolecek refactor code so that xfer c_start() hook is called with channel mutex held,
and hence the controller submit code no longer relies on spl

tested all the affected drivers - wdc (via piixide), ahci, mvsata, siisata,
both disk and atapi I/O
 1.35.6.24 10-Sep-2017  jdolecek move mvsata_bio(), mvsata_exec_command() and mvsata_atapi_scsipi_request()
just before their respective hook functions
 1.35.6.23 13-Aug-2017  jdolecek put the non-NCQ KASSERT() before edma disable for bio PIO, we are not supposed
to get there with NCQ command even on retries any more
 1.35.6.22 12-Aug-2017  jdolecek add NCQ error recovery for mvsata(4)

fix wait flags for mvsata_bio_start(), AT_* constants are only valid for cmd

change the debug logging to similar form as ahcisata/siisata, so it's
easier to selectively show
 1.35.6.21 12-Aug-2017  jdolecek convert the atabus thread to use the channel lock and a condvar, adjust
code which sets the relevant channel flags to take the lock while doing so
 1.35.6.20 12-Aug-2017  jdolecek remove all logic around ATACH_IRQ_WAIT and channel-global ch_error/ch_status,
so that there is less hidden state shared by commands; primary intent is
to make the NCQ and non-NCQ paths more similar, and remove possibility
of incorrect handling for the NCQ commands

tested both disk and ATAPI - piixide(4) on QEMU, and siisata(4),
ahcisata(4), mvsata(4) on real hw
 1.35.6.19 12-Aug-2017  jdolecek fix condition for switching to kernel thread for ATAPI and bio reset recovery
to match atapi_wdc.c, __wdcwait() postpones to the thread whenever neither
AT_POLL nor AT_WAIT flags are present

fixes spurious 'timeout' for the command on mvsata, followed by 'unexpected'
interrupt
 1.35.6.18 28-Jun-2017  jdolecek enable ATAPI on mvsata(4); it seems to work fine for my cdrom
 1.35.6.17 27-Jun-2017  jdolecek attend error paths, more strict asserts and code consistency

- atastart() and ata_kill_pending() now KASSERT() that all xfers on queue
have same channel
- inactive xfers are killed via new reason KILL_GONE_INACTIVE, controller
code must not call any resource deactivation in that case
- c_intr() must call ata_waitdrain_xfer_check() as first thing, and must not
further touch any xfer structures on exit path; any resource cleanup
is supposed to be done in c_kill_xfer()
- c_kill_xfer() should never call atastart()
- ata_waitdrain_check() removed, replaced by ata_waitdrain_xfer_check()
- ATA_DRIVE_WAITDRAIN handling converted to use condvar
- removed unused ata_c callback
 1.35.6.16 24-Jun-2017  jdolecek fix confusion around AT_WAIT vs AT_POLL for mvsata_edma_disable(), and switch
all the tsleep()/delay() ifs to just use ata_delay()
 1.35.6.15 24-Jun-2017  jdolecek fix dump on mvsata - there was misplaced mvsata_bio_intr() call causing
diagnostic panic, and we also need to switch controller to appropriate
DMA mode (NCQ vs. non-NCQ DMA)

while here, also reduce delay for the polled command wait to 100 us, same
as siisata(4) and ahcisata(4)
 1.35.6.14 21-Jun-2017  jdolecek change ata_queue_hwslot_to_xfer() and ata_queue_get_active_xfer() to take
ata_channel instead of ata_queue as parameter, and lock the channel while
traversing the queue
 1.35.6.13 20-Jun-2017  jdolecek remove ata queue downsizing - every device, attached to the same channel,
uses slots according to it's own limits

wdc code changed to expect maximum one active xfer, and not check number
of openings in the channel; this is to facilitate using wdc functions
for e.g. handling of atapi commands for drivers which support both ATAPI
and NCQ
 1.35.6.12 19-Jun-2017  jdolecek add ata_channel lock, use it to protect queue manipulation (only that for now);
add ata_channel_detach() to destroy the locks

change ata_get_xfer() so that it can wait for xfer, convert all on-stack
xfer code to use the blocking variant

fix siisata_reset_drive() to use polled reset and not try ata_activate_xfer(),
convert drive probe code also over from slot0 XXX to ata_get_xfer()

drive reset and PMP now works on siisata(4) too; changes tested also
on piixide(4), ahci(4), mvsata(4)
 1.35.6.11 16-Jun-2017  jdolecek adjust reset channel and dump paths
- channel reset now always kills active transfer, even on dump path, but
now doesn't touch the queued waiting transfers; also kill_xfer hook is
always called, so that HBA can free any private xfer resources and thus
the dump request has chance to work
- kill_xfer routines now always call ata_deactivate_xfer(); added KASSERT()s
to ata_free_xfer() to expect deactivated xfer
- when called during channel reset before dump, ata_kill_active() drops
any queued waiting transfers without processing
- do not (re)queue any transfers in wddone() when dumping
- kill AT_RST_NOCMD flag

This should also hopefully fix the 'polled command has been queued' panic
as reported in:
PR kern/11811 by John Hawkinson
PR kern/47041 by Taylor R Campbell
PR kern/51979 by Martin Husemann

dump tested working with piixide(4) and ahci(4). mvsata(4) dump times out,
but otherwise tested working, will be fixed separately. siisata(4) mechanically
changed and not tested.
 1.35.6.10 13-Jun-2017  jdolecek use MVSATA_EDMAQ_LEN instead of magic number for number of queue slots
 1.35.6.9 12-Jun-2017  jdolecek add support for NCQ on Gen IIe hardware

mvsata_quetag_get()/put() pairs adjusted to work also for non-DMA code paths,
i.e. during probe; replaced wdcintr() call with local routine which uses
currently active command tag, rather than assuming always tag 0 on that
code path

~55MB/s -> ~80MB/s sequential read using fio(1) on a test HDD, quite nice
 1.35.6.8 10-Jun-2017  jdolecek use satafis routine to build the command block for Gen IIe to reduce code
duplication
 1.35.6.7 09-Jun-2017  jdolecek fix the driver to work again - switch to using tag from xfer, adjust
to framework changes (queue dynamically allocated), and do not store
pointer to xfer inside internal structures

unhide the ATAPI code and fix to compile, keep it disabled however

no indended functional changes, logic kept as close as possible to what was
there before; tested with Adaptec 1430SA (88SX7042)
 1.35.6.6 19-Apr-2017  jdolecek adjust ata code to support more than one active command, including the
timeout handling, add support for NCQ commands

move probe for NCQ and number of tags to middle layer, negotiate mutual
support between drive and controller

implement NCQ support in ahci(4)
 1.35.6.5 15-Apr-2017  jdolecek pass also ata_command via ata_xfer, callers of ata_exec_command() is now
responsible for allocation/disposal of the structure

change code to allocate ata_xfer for commands on stack same way as previously
the ata_command were, using c_slot 0; adjust asserts so that it would allow
several xfers with same c_slot, as long as only one such transfer is active
at a time
 1.35.6.4 15-Apr-2017  jdolecek make ata_xfer's allocated as part of ata_queue and make it include ata_bio;
they are pre-allocated on attach and ata_get_xfer() now never sleep, drop the
pool

modify wd(4) to file the bio requests using the xfers and hence
make it possible to have more than one active I/O request in flight;
ata_bio callback doesn't need to allocate any memory any more,
require it to never return ATACMD_TRY_AGAIN

move lp, badsect, multi from ata_bio to ata_drive_datas, as they are per-drive,
not per transfer

drop unused drv atac_claim_hw/atac_free_hw hooks, and also drop again ata_bio
c_hwslot
 1.35.6.3 11-Apr-2017  jdolecek remove left-over curly brace
 1.35.6.2 11-Apr-2017  jdolecek fix to not access active_xfer directly
 1.35.6.1 10-Apr-2017  jdolecek ATA infrastructure improvements to eventually support more outstanding
commands

patch by Matt Thomas
 1.39.2.3 26-Nov-2018  pgoyette Sync with HEAD, resolve a couple of conflicts
 1.39.2.2 06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.39.2.1 16-Apr-2018  pgoyette Sync with HEAD, resolve some conflicts
 1.40.2.4 21-Apr-2020  martin Sync with HEAD
 1.40.2.3 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.40.2.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.40.2.1 10-Jun-2019  christos Sync with HEAD
 1.41.2.11 15-Oct-2018  jdolecek change the SATA/NCQ recovery to run in the atabus thread
 1.41.2.10 14-Oct-2018  jdolecek adjust mvsata_bio_intr() so it recognizes the 'tfd' parameter as passed
by recovery and hence works; use it also for passing state from
mvsata_edma_handle()
 1.41.2.9 13-Oct-2018  jdolecek make compile again with MVSATA_WITHOUTDMA
 1.41.2.8 13-Oct-2018  jdolecek add C_TIMEOUT KASSERT() on fail path of mvsata_bio_poll() for clarity
 1.41.2.7 11-Oct-2018  jdolecek refactor shared parts of the SATA error recovery into new function
ata_recovery_resume() and use for ahcisata/siisata/mvsata, also replace
per-controller hold/unhold with generic version

move the shared recovery code into separate file ata_recovery.c
 1.41.2.6 04-Oct-2018  jdolecek further channel locking pass for reset
 1.41.2.5 03-Oct-2018  jdolecek change channel reset and drive reset for all ATA controllers to always
run via thread, and with channel lock held the whole time; the queue is
frozen while reset is pending

for this repurpose ata_reset_channel() into new ata_thread_run()

also adjust some device printfs to not leak xfer pointer, and avoid
aprint_* for non-autoconf messages
 1.41.2.4 22-Sep-2018  jdolecek separate ata_xfer slot allocation and the memory allocation, so that
there can be more queued xfers than number of supported slots by controller,
and use a pool instead of custom pre-allocation

primarily to help PR kern/52614

remove no longer needed custom wd(4) logic for flush cache

switch also wd(4) trim/suspend/setcache/wdioctlstrategy to sleep waiting
for the memory, they are all called from process context and this
avoids spurious failures
 1.41.2.3 17-Sep-2018  jdolecek move ATAPI-only members of ata_xfer to an union struct to further save space
 1.41.2.2 17-Sep-2018  jdolecek move low-level protocol handlers hooks from ata_xfer to separate struct,
initialized statically

primarily to reduce ata_xfer struct size, but also improves readibility,
and enforces consistency
 1.41.2.1 31-Aug-2018  jdolecek refactor ata_xfer to be just dumb structure; move all callouts/condvars out

retry callout to wd(4); reset callout and the active/cmd finish condvars
to channel queue; change code using the condvars so it works if there
are multiple waiters

simplify the async wait code for cmds, replace ata_wait_xfer()/ata_wake_xfer()
with ata_wait_cmd()

fix the callout_invoking/ack race handling code for timeouts to
actually have chance to work; change mvsata(4) to use generic timeout func

towards resolution of kern/52614
 1.48.2.1 30-Dec-2022  martin Pull up following revision(s) (requested by tsutsui in ticket #1557):

sys/dev/ic/ahcisata_core.c: revision 1.83
sys/dev/ic/ahcisata_core.c: revision 1.102
sys/dev/ata/ata.c: revision 1.164
sys/dev/ata/ata_wdc.c: revision 1.115
sys/dev/ata/ata_recovery.c: revision 1.4
sys/dev/ic/siisata.c: revision 1.42
sys/dev/ic/wdc.c: revision 1.308
sys/dev/ic/mvsata.c: revision 1.56
sys/dev/scsipi/atapi_wdc.c: revision 1.138
sys/dev/ic/siisata.c: revision 1.49
sys/dev/ata/atavar.h: revision 1.105
sys/dev/ata/wd.c: revision 1.460
sys/dev/ata/ata.c: revision 1.155
sys/dev/ata/wd.c: revision 1.462
sys/dev/ata/atavar.h: revision 1.109
sys/dev/ata/satapmp_subr.c: revision 1.16
sys/dev/ic/wdc.c: revision 1.299
sys/dev/ic/ahcisata_core.c: revision 1.93
sys/dev/ata/ata_wdc.c: revision 1.120
sys/dev/ic/wdcvar.h: revision 1.100
sys/dev/scsipi/atapi_wdc.c: revision 1.141
sys/dev/ic/mvsata.c: revision 1.61
sys/dev/usb/umass_isdata.c (apply patch)

drop wd lock in wdstart1() before calling the ata_bio hook; when called
from ata thread context, that can still need to sleep for wdc attachments
in wdcwait()

fix use-after-free for ata xfer on bio submission found by KASAN
driver ata_bio hooks read parts of the xfer after ata_exec_xfer()
call in order to determine return value, change so that the hook
doesn't return any value - callers do not care already,
as all I/O requests are asynchronous

this problem was uncovered by recent change for wd(4) to not hold
wd mutex during ata_bio call, the interrupt for the xfer might
thus actually fire immediately

adjust also ata_exec_command driver hooks similarily - remove all
completion and waiting logic from drivers, upper layer ata code
using AT_WAIT/AT_POLL changed to call ata_wait_cmd() itself
PR kern/55169 by Nick Hudson

Function declaration formating whitespace consistency. NFCI.

PR kern/56403
Fix kernel freeze for wdc(4) variants with ATAC_CAP_NOIRQ:

(1) Change ata_xfer_ops:c_poll from void to int function. When it returns
ATAPOLL_AGAIN, let ata_xfer_start() iterate itself again.
(2) Let wdc_ata_bio_poll() return ATAPOLL_AGAIN until ATA_ITSDONE is
achieved.

A similar change has been made for mvsata(4) (see mvsata_bio_poll()),
and no functional changes for other devices.

This is how the drivers worked before jdolecek-ncq branch was merged.
Note that this changes are less likely to cause infinite recursion:

(1) wdc_ata_bio_intr() called from wdc_ata_bio_poll() asserts ATA_ITSDONE
in its error handling paths via wdc_ata_bio_done().
(2) Return value from c_start (= wdc_ata_bio_start()) is checked in
ata_xfer_start().

Therefore, errors encountered in ata_xfer_ops:c_poll and c_start routines
terminate the recursion for wdc(4). The situation is similar for mvsata(4).

Still, there is a possibility where ata_xfer_start() takes long time to
finish a normal operation. This can result in a delayed response for lower
priority interrupts. But, I've never observed such a situation, even when
heavy thrashing takes place for swap partition in wd(4).
"Go ahead" by jdolecek@.
 1.52.2.1 29-Feb-2020  ad Sync with head.
 1.55.2.1 20-Apr-2020  bouyer Sync with HEAD
 1.57.2.1 03-Jan-2021  thorpej Sync w/ HEAD.
 1.58.2.1 02-Apr-2021  thorpej config_found_ia() -> config_found() w/ CFARG_IATTR.
 1.59.8.1 04-Aug-2021  thorpej Adapt to CFARGS().
 1.5 16-Feb-2022  andvar fix various typos, mainly in comments.
 1.4 07-Oct-2017  jdolecek Merge support for SATA NCQ (Native Command Queueing) from jdolecek-ncq branch

ATA subsystem was changed to support several outstanding commands, and use
NCQ xfers if supported by both the controller and the disk, including NCQ
error recovery. Set NCQ high priority for BPRIO_TIMECRITICAL xfers
if supported. Added FUA support.

Done some work towards MP-safe, all ATA code tsleep()/wakeup() replaced
by condvars, and switched most code from spl* to mutexes (separate
wd(4) and ata channel lock).

Introduced new option WD_CHAOS_MONKEY to facilitate testing of error
handling, fixed several uncovered issues. Also fixed several problems
with kernel dump to wd(4) disk.

Tested with ahcisata(4), mvsata(4), siisata(4), piixide(4) on amd64,
with and without port multiplier, both disk and ATAPI devices; other
drivers and archs mechanically adjusted and compile-tested. NCQ is
supported for ahcisata(4) and siisata(4) for any controller, for
mvsata(4) only Gen IIe ones for now. Also enabled ATAPI support in
mvsata(4).

Thanks to Matt Thomas for initial ATA infrastructure patch, and
Jonathan A.Kollasch for siisata(4) NCQ changes and general testing.

Also fixes PR kern/43169 (wd(4)); and PR kern/11811, PR kern/47041,
PR kern/51979 (kernel dump)
 1.3 29-Aug-2012  jakllsch branches: 1.3.2; 1.3.28;
mvsata(4) DMA data structures are already __packed, but as the hardware
requires them to be 8-byte aligned, add __aligned(8) too, so that accesses
on strict alignment platforms are more efficent.
 1.2 23-Jul-2012  jakllsch Use "<<" instead of "<" for shift-to-left.
 1.1 27-Jul-2009  kiyohara branches: 1.1.2; 1.1.14;
Support Marvell Hercules-I/II SATA Controllers.
 1.1.14.1 30-Oct-2012  yamt sync with head
 1.1.2.2 19-Aug-2009  yamt sync with head.
 1.1.2.1 27-Jul-2009  yamt file mvsatareg.h was added on branch yamt-nfs-mp on 2009-08-19 18:47:07 +0000
 1.3.28.1 10-Jun-2017  jdolecek use satafis routine to build the command block for Gen IIe to reduce code
duplication
 1.3.2.1 03-Dec-2017  jdolecek update from HEAD
 1.5 22-Oct-2018  jdolecek Merge jdolecek-ncqfixes branch

- ata_xfer's are dynamicall allocated as needed using a pool, no longer
limited to number of possible openings supported by controller; dump
and recovery paths use dedicated pre-allocated storage
- moved callouts and condvars from ata_xfer to queue or channel, so that
ata_xfer does not need special initialization
- slot allocation now done when xfer is being activated, uncoupled
from memory allocation; active slots are no longer tracked by controller
code
- channel and drive reset is done always via the atabus thread, and
now executes with channel locked the whole time
- NCQ recovery moved to shared function, and run via the thread also
- added some workarounds for buggy error recovery AHCI emulation in QEMU
and Parallels

designed to primarily fix kern/52614, but might also help with kern/47041
and kern/53183
 1.4 31-Aug-2018  jdolecek branches: 1.4.2;
constify mvsata_pci_products[]
 1.3 07-Oct-2017  jdolecek branches: 1.3.2; 1.3.4;
Merge support for SATA NCQ (Native Command Queueing) from jdolecek-ncq branch

ATA subsystem was changed to support several outstanding commands, and use
NCQ xfers if supported by both the controller and the disk, including NCQ
error recovery. Set NCQ high priority for BPRIO_TIMECRITICAL xfers
if supported. Added FUA support.

Done some work towards MP-safe, all ATA code tsleep()/wakeup() replaced
by condvars, and switched most code from spl* to mutexes (separate
wd(4) and ata channel lock).

Introduced new option WD_CHAOS_MONKEY to facilitate testing of error
handling, fixed several uncovered issues. Also fixed several problems
with kernel dump to wd(4) disk.

Tested with ahcisata(4), mvsata(4), siisata(4), piixide(4) on amd64,
with and without port multiplier, both disk and ATAPI devices; other
drivers and archs mechanically adjusted and compile-tested. NCQ is
supported for ahcisata(4) and siisata(4) for any controller, for
mvsata(4) only Gen IIe ones for now. Also enabled ATAPI support in
mvsata(4).

Thanks to Matt Thomas for initial ATA infrastructure patch, and
Jonathan A.Kollasch for siisata(4) NCQ changes and general testing.

Also fixes PR kern/43169 (wd(4)); and PR kern/11811, PR kern/47041,
PR kern/51979 (kernel dump)
 1.2 13-Jul-2010  kiyohara branches: 1.2.18; 1.2.48;
Move to pci/mvsata_pci.c (marvell/mvsata_mv.c) splitting mvsata_products[].
mvsata(4) uses these to match.
 1.1 27-Jul-2009  kiyohara branches: 1.1.2; 1.1.4; 1.1.6;
Support Marvell Hercules-I/II SATA Controllers.
 1.1.6.1 05-Mar-2011  rmind sync with head
 1.1.4.1 17-Aug-2010  uebayasi Sync with HEAD.
 1.1.2.3 11-Aug-2010  yamt sync with head.
 1.1.2.2 19-Aug-2009  yamt sync with head.
 1.1.2.1 27-Jul-2009  yamt file mvsatavar.h was added on branch yamt-nfs-mp on 2009-08-19 18:47:07 +0000
 1.2.48.4 12-Aug-2017  jdolecek add NCQ error recovery for mvsata(4)

fix wait flags for mvsata_bio_start(), AT_* constants are only valid for cmd

change the debug logging to similar form as ahcisata/siisata, so it's
easier to selectively show
 1.2.48.3 01-Aug-2017  jdolecek fix logic bug in processing of finished commands - mask of active
commands can change during the loop as c_intr() callback can queue
new commands, so the interrupt routine should only mark as finished
those which were actually active before the loop started; otherwise
the code marked as finished commands which were just started, and
being executed by HBA, leading to all sorts of data corruption

while here mark the active mask volatile, as it is modified from
interrupt context

this fixes for good the random crashes, short reads, and fatal command
errors which I've been tracing down for past couple weeks

thanks to Jonathan (jakllsch@) for testing, and a script to easily
triggered the condition, and led to this bug being finally found and squashed
 1.2.48.2 24-Jun-2017  jdolecek fix dump on mvsata - there was misplaced mvsata_bio_intr() call causing
diagnostic panic, and we also need to switch controller to appropriate
DMA mode (NCQ vs. non-NCQ DMA)

while here, also reduce delay for the polled command wait to 100 us, same
as siisata(4) and ahcisata(4)
 1.2.48.1 09-Jun-2017  jdolecek fix the driver to work again - switch to using tag from xfer, adjust
to framework changes (queue dynamically allocated), and do not store
pointer to xfer inside internal structures

unhide the ATAPI code and fix to compile, keep it disabled however

no indended functional changes, logic kept as close as possible to what was
there before; tested with Adaptec 1430SA (88SX7042)
 1.2.18.1 03-Dec-2017  jdolecek update from HEAD
 1.3.4.1 10-Jun-2019  christos Sync with HEAD
 1.3.2.2 26-Nov-2018  pgoyette Sync with HEAD, resolve a couple of conflicts
 1.3.2.1 06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.4.2.1 11-Oct-2018  jdolecek refactor shared parts of the SATA error recovery into new function
ata_recovery_resume() and use for ahcisata/siisata/mvsata, also replace
per-controller hold/unhold with generic version

move the shared recovery code into separate file ata_recovery.c
 1.18 21-May-2024  andvar s/amout/amount/ in comments.
 1.17 01-Aug-2023  andvar s/diabling/disabling/ in comment.
 1.16 03-Sep-2018  riastradh Rename min/max -> uimin/uimax for better honesty.

These functions are defined on unsigned int. The generic name
min/max should not silently truncate to 32 bits on 64-bit systems.
This is purely a name change -- no functional change intended.

HOWEVER! Some subsystems have

#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))

even though our standard name for that is MIN/MAX. Although these
may invite multiple evaluation bugs, these do _not_ cause integer
truncation.

To avoid `fixing' these cases, I first changed the name in libkern,
and then compile-tested every file where min/max occurred in order to
confirm that it failed -- and thus confirm that nothing shadowed
min/max -- before changing it.

I have left a handful of bootloaders that are too annoying to
compile-test, and some dead code:

cobalt ews4800mips hp300 hppa ia64 luna68k vax
acorn32/if_ie.c (not included in any kernels)
macppc/if_gm.c (superseded by gem(4))

It should be easy to fix the fallout once identified -- this way of
doing things fails safe, and the goal here, after all, is to _avoid_
silent integer truncations, not introduce them.

Maybe one day we can reintroduce min/max as type-generic things that
never silently truncate. But we should avoid doing that for a while,
so that existing code has a chance to be detected by the compiler for
conversion to uimin/uimax without changing the semantics until we can
properly audit it all. (Who knows, maybe in some cases integer
truncation is actually intended!)
 1.15 14-Mar-2009  dsl branches: 1.15.62; 1.15.64;
ANSIfy another 1261 function definitions.
The only ones left in sys are beyond by sed script!
(or in sys/dist or sys/external)
Mostly they have function pointer parameters.
 1.14 14-Mar-2009  dsl Change about 4500 of the K&R function definitions to ANSI ones.
There are still about 1600 left, but they have ',' or /* ... */
in the actual variable definitions - which my awk script doesn't handle.
There are also many that need () -> (void).
(The script does handle misordered arguments.)
 1.13 28-Apr-2008  martin branches: 1.13.8; 1.13.14;
Remove clause 3 and 4 from TNF licenses
 1.12 12-Mar-2008  cube branches: 1.12.2; 1.12.4;
Split device_t and softc for the NE2000 Ethernet chip and all its variants
and attachments. Use device_t accessors, correct types, and ANSIfy when
appropriate.
 1.11 08-Jan-2008  matt branches: 1.11.2; 1.11.6;
Don't do arithmetic on void pointers.
 1.10 19-Oct-2007  ad branches: 1.10.2; 1.10.8;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.9 04-Mar-2007  christos branches: 1.9.2; 1.9.14; 1.9.16; 1.9.20;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.8 24-Dec-2005  perry branches: 1.8.26;
Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.7 11-Dec-2005  christos merge ktrace-lwp.
 1.6 18-Mar-2004  he branches: 1.6.16;
Adapt to the removal of NE2000_USE_WORD() macro, now replaced
by a field in ne2000_softc.
 1.5 04-Dec-2003  keihan netbsd.org -> NetBSD.org

This was the last commit of this kind to src/sys, which is now totally
"NetBSD.org clean". Thanks for the patiance, and sorry for all the commits.
 1.4 03-May-2003  wiz branches: 1.4.2;
DMA, not dma nor Dma.
 1.3 15-Jan-2003  bouyer Zero out the NIC memory when padding packet to ETHER_MIN_LEN-ETHER_CRC_LEN
sc->write_mbuf now return len of buffer, including padding.
Tested with a PCI ne2000.
 1.2 17-Feb-2002  bjh21 branches: 1.2.10;
Add prototypes for static functions.
 1.1 15-Dec-2001  bjh21 branches: 1.1.2; 1.1.4;
Add code to support the bugged Macronix MX98905 chip, as used in several
podulebus Ethernet cards. This replaces the NE2000 memory-access routines
with ones that don't try to transfer more than 255 bytes at a time.

This code should perhaps be merged into ne2000.c, but presumably most NE2000
clones won't need it.
 1.1.4.3 16-Mar-2002  jdolecek Catch up with -current.
 1.1.4.2 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.1.4.1 15-Dec-2001  thorpej file mx98905.c was added on branch kqueue on 2002-01-10 19:54:53 +0000
 1.1.2.4 17-Jan-2003  thorpej Sync with HEAD.
 1.1.2.3 28-Feb-2002  nathanw Catch up to -current.
 1.1.2.2 08-Jan-2002  nathanw Catch up to -current.
 1.1.2.1 15-Dec-2001  nathanw file mx98905.c was added on branch nathanw_sa on 2002-01-08 00:29:59 +0000
 1.2.10.1 27-Jan-2003  jmc Pullup revisions 1.2-1.3 (requested by bouyer in ticket #1096)
Zero out the NIC memory when padding packet to
ETHER_MIN_LEN-ETHER_CRC_LEN sc->write_mbuf now return len of
buffer, including padding.
 1.4.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.4.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.4.2.1 03-Aug-2004  skrll Sync with HEAD
 1.6.16.5 17-Mar-2008  yamt sync with head.
 1.6.16.4 21-Jan-2008  yamt sync with head
 1.6.16.3 27-Oct-2007  yamt sync with head.
 1.6.16.2 03-Sep-2007  yamt sync with head.
 1.6.16.1 21-Jun-2006  yamt sync with head.
 1.8.26.1 12-Mar-2007  rmind Sync with HEAD.
 1.9.20.1 25-Oct-2007  bouyer Sync with HEAD.
 1.9.16.3 23-Mar-2008  matt sync with HEAD
 1.9.16.2 09-Jan-2008  matt sync with HEAD
 1.9.16.1 06-Nov-2007  matt sync with HEAD
 1.9.14.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.9.2.1 23-Oct-2007  ad Sync with head.
 1.10.8.1 08-Jan-2008  bouyer Sync with HEAD
 1.10.2.1 18-Feb-2008  mjf Sync with HEAD.
 1.11.6.2 02-Jun-2008  mjf Sync with HEAD.
 1.11.6.1 03-Apr-2008  mjf Sync with HEAD.
 1.11.2.1 24-Mar-2008  keiichi sync with head.
 1.12.4.2 04-May-2009  yamt sync with head.
 1.12.4.1 16-May-2008  yamt sync with head.
 1.12.2.1 18-May-2008  yamt sync with head.
 1.13.14.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.13.8.1 28-Apr-2009  skrll Sync with HEAD.
 1.15.64.1 10-Jun-2019  christos Sync with HEAD
 1.15.62.1 06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.3 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.2 04-Mar-2007  christos branches: 1.2.36; 1.2.38; 1.2.40;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.1 15-Dec-2001  bjh21 branches: 1.1.2; 1.1.4; 1.1.36; 1.1.74;
Add code to support the bugged Macronix MX98905 chip, as used in several
podulebus Ethernet cards. This replaces the NE2000 memory-access routines
with ones that don't try to transfer more than 255 bytes at a time.

This code should perhaps be merged into ne2000.c, but presumably most NE2000
clones won't need it.
 1.1.74.1 12-Mar-2007  rmind Sync with HEAD.
 1.1.36.1 03-Sep-2007  yamt sync with head.
 1.1.4.2 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.1.4.1 15-Dec-2001  thorpej file mx98905var.h was added on branch kqueue on 2002-01-10 19:54:53 +0000
 1.1.2.2 08-Jan-2002  nathanw Catch up to -current.
 1.1.2.1 15-Dec-2001  nathanw file mx98905var.h was added on branch nathanw_sa on 2002-01-08 00:30:00 +0000
 1.2.40.1 16-May-2008  yamt sync with head.
 1.2.38.1 18-May-2008  yamt sync with head.
 1.2.36.1 02-Jun-2008  mjf Sync with HEAD.
 1.4 01-Jan-1996  thorpej Switch to David Jones' new machine-independent NCR5380 driver. It's been
in use by the sun3 port for some time, and is now used by the sparc port.
 1.3 26-Sep-1995  pk Remove a sun3-ism.
 1.2 03-Sep-1995  pk Patches from Jason Thorpe to deal with 4/110 scsi (PR#1422).
Also repairs a problem noted by David Jones: detect scsi phase correctly.
 1.1 08-Jul-1995  pk ncr5380 chip definitions and MI part of driver.
 1.5 11-Dec-2005  christos merge ktrace-lwp.
 1.4 27-Feb-2005  perry nuke trailing whitespace
 1.3 20-Aug-2001  wiz branches: 1.3.20; 1.3.28; 1.3.30;
"wierd" is weird.
 1.2 05-Jan-1998  perry branches: 1.2.26; 1.2.28;
RCSID Police.
 1.1 01-Jan-1996  thorpej Switch to David Jones' new machine-independent NCR5380 driver. It's been
in use by the sun3 port for some time, and is now used by the sparc port.
 1.2.28.1 25-Aug-2001  thorpej Merge Aug 24 -current into the kqueue branch.
 1.2.26.1 24-Aug-2001  nathanw Catch up with -current.
 1.3.30.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.3.28.1 29-Apr-2005  kent sync with -current
 1.3.20.1 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.7 11-Dec-2005  christos merge ktrace-lwp.
 1.6 27-Feb-2005  perry nuke trailing whitespace
 1.5 03-May-2003  wiz branches: 1.5.2; 1.5.10; 1.5.12;
DMA, not dma nor Dma.
 1.4 12-Apr-1999  pk Quote "AS IS" as in the majority of Carnegy Mellon notices.
 1.3 06-Apr-1999  pk Fix a pasto in copyright text which has been procreating like rabbits..
 1.2 01-Jan-1996  thorpej branches: 1.2.24;
Switch to David Jones' new machine-independent NCR5380 driver. It's been
in use by the sun3 port for some time, and is now used by the sparc port.
 1.1 08-Jul-1995  pk ncr5380 chip definitions and MI part of driver.
 1.2.24.2 12-Apr-1999  pk branches: 1.2.24.2.2;
Pullup copyright text corrections.
 1.2.24.1 07-Apr-1999  pk Pull up from trunk: copyright text warts.
 1.2.24.2.2.1 21-Jun-1999  thorpej Sync w/ -current.
 1.5.12.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.5.10.1 29-Apr-2005  kent sync with -current
 1.5.2.1 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.74 29-Oct-2024  nat A simpler fix for handling aborted requests.

From riastradh@.
 1.73 29-Oct-2024  nat Revert to previous - scsipi_done_once is not necessary.

A follow up commit will contain a simpler change (from riastradh@) to
ncr5380sbc.
 1.72 28-Oct-2024  nat Introduce scsipi_done_once.

This allows for transfers to be sucessfully aborted on the ncr5380sbc(4).

This may be usefull in future for other scsi controllers.

Callers of scsipi_done are not affected by this change.

Part of kern/58452.

As posted to tech-kern:
https://mail-index.netbsd.org/tech-kern/2024/08/02/msg029652.html

Ok thorpej@.
 1.71 28-Oct-2024  nat Avoid spamming console with abort messages.

This is common when using a device such as dse(4) and is a harmless message.

Part of kern/58452.

As posted to tech-kern:
https://mail-index.netbsd.org/tech-kern/2024/08/02/msg029652.html

Ok thorpej@.
 1.70 28-Oct-2024  nat Abort current request upon reset.

Part of kern/58452.

As posted to tech-kern:
https://mail-index.netbsd.org/tech-kern/2024/08/02/msg029652.html

Ok thorpej@.
 1.69 07-Aug-2021  thorpej branches: 1.69.12;
Merge thorpej-cfargs2.
 1.68 24-Apr-2021  thorpej branches: 1.68.8;
Merge thorpej-cfargs branch:

Simplify and make extensible the config_search() / config_found() /
config_attach() interfaces: rather than having different variants for
which arguments you want pass along, just have a single call that
takes a variadic list of tag-value arguments.

Adjust all call sites:
- Simplify wherever possible; don't pass along arguments that aren't
actually needed.
- Don't be explicit about what interface attribute is attaching if
the device only has one. (More simplification.)
- Add a config_probe() function to be used in indirect configuiration
situations, making is visibly easier to see when indirect config is
in play, and allowing for future change in semantics. (As of now,
this is just a wrapper around config_match(), but that is an
implementation detail.)

Remove unnecessary or redundant interface attributes where they're not
needed.

There are currently 5 "cfargs" defined:
- CFARG_SUBMATCH (submatch function for direct config)
- CFARG_SEARCH (search function for indirect config)
- CFARG_IATTR (interface attribte)
- CFARG_LOCATORS (locators array)
- CFARG_DEVHANDLE (devhandle_t - wraps OFW, ACPI, etc. handles)

...and a sentinel value CFARG_EOL.

Add some extra sanity checking to ensure that interface attributes
aren't ambiguous.

Use CFARG_DEVHANDLE in MI FDT, OFW, and ACPI code, and macppc and shark
ports to associate those device handles with device_t instance. This
will trickle trough to more places over time (need back-end for pre-OFW
Sun OBP; any others?).
 1.67 11-Jan-2017  skrll branches: 1.67.32;
adatper -> adapter
 1.66 28-Jul-2012  matt branches: 1.66.2; 1.66.16; 1.66.20;
Fix -fno-common found by building i386/conf/ALL
 1.65 27-Jul-2010  jakllsch branches: 1.65.8;
Make debugging code compile on LP64.
 1.64 23-Nov-2009  rmind branches: 1.64.2; 1.64.4;
Remove some unecessary includes sys/user.h header.
 1.63 04-Apr-2008  tsutsui branches: 1.63.4;
Split devict_t/softc for ncr5380sbc SCSI, and misc cosmetic changes.
 1.62 24-Nov-2006  christos branches: 1.62.48;
fix spelling of accommodate; from Zapher.
 1.61 16-Nov-2006  christos __unused removal on arguments; approved by core.
 1.60 12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.59 17-Aug-2006  christos branches: 1.59.2; 1.59.4;
Fix all the -D*DEBUG* code that it was rotting away and did not even compile.
Mostly from Arnaud Lacombe, many thanks!
 1.58 24-Dec-2005  perry branches: 1.58.4; 1.58.8;
Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.57 11-Dec-2005  christos merge ktrace-lwp.
 1.56 02-Jun-2005  tsutsui branches: 1.56.2;
Add a const. Fixes part of PR kern/30403.
 1.55 27-Feb-2005  perry nuke trailing whitespace
 1.54 04-Feb-2005  perry de-__P
 1.53 12-Sep-2004  he branches: 1.53.4; 1.53.6;
Enclose initialization of NCR_VARIANT_NCR53C400 in an ifdef on
NCR5380_USE_BUS_SPACE, to make this build again on acorn32, mac68k,
pc532, and sun3. This is done under the assumption that it's
somewhat doubtful that any of those machines will encounter that
chip variant.

The acorn32 and mac68k parent drivers (csa and sbc) are listed in
ncr5380var.h as "easy to convert", but it's evident that noone have
stepped up to that challenge yet. Sun3 and pc532 needs bus.h first,
which they apparently don't have at the moment.
 1.52 10-Aug-2004  mycroft For the c400, set 5380 compatibility mode on every pass through the reset
routine. The PCMCIA attachment, at least, needs this.
 1.51 05-Nov-2003  simonb Fix gcc332 uninitialised bogon.
 1.50 02-Nov-2003  wiz Fix some typos. From Tom Cosgrove via jmc@openbsd.
 1.49 03-May-2003  wiz branches: 1.49.2;
DMA, not dma nor Dma.
 1.48 05-Apr-2002  bouyer Implement mstohz() as discussed on tech-kern, and use it in SCSI drivers
to convert xs->timeout to callout() parameter.
 1.47 26-Nov-2001  fredette Use bus_space on sun2.
Update the comment to match list of bus_space-using ports.
Removed some old unused asm() labels.
 1.46 15-Nov-2001  lukem don't need <sys/types.h> when including <sys/param.h>
 1.45 13-Nov-2001  lukem add/cleanup RCSID
 1.44 04-Nov-2001  tsutsui Use common macro to check message length.
 1.43 08-Jul-2001  wiz branches: 1.43.2; 1.43.6;
Correct various misspellings of 'transfer' and inflected forms.
 1.42 07-Jul-2001  thorpej bzero -> memset
 1.41 13-Jun-2001  bjh21 Use the new generic mechanism for forcing polling on a SCSI interface, rather
than doing it ourselves.
 1.40 25-Apr-2001  bouyer Pull up the thorpej_scsipi branch to main branch.
This is a completely rewritten scsipi_xfer execution engine, and the
associated changes to HBA drivers. Overview of changes & features:
- All xfers are queued in the mid-layer, rather than doing so in an
ad-hoc fashion in individual adapter drivers.
- Adapter/channel resource management in the mid-layer, avoids even trying
to start running an xfer if the adapter/channel doesn't have the resources.
- Better communication between the mid-layer and the adapters.
- Asynchronous event notification mechanism from adapter to mid-layer and
peripherals.
- Better peripheral queue management: freeze/thaw, sorted requeueing during
recovery, etc.
- Clean separation of peripherals, adapters, and adapter channels (no more
scsipi_link).
- Kernel thread for each scsipi_channel makes error recovery much easier
(no more dealing with interrupt context when recovering from an error).
- Mid-layer support for tagged queueing: commands can have the tag type
set explicitly, tag IDs are allocated in the mid-layer (thus eliminating
the need to use buggy tag ID allocation schemes in many adapter drivers).
- support for QUEUE FULL and CHECK CONDITION status in mid-layer; the command
will be requeued, or a REQUEST SENSE will be sent as appropriate.

Just before the merge syssrc has been tagged with thorpej_scsipi_beforemerge
 1.39 13-Apr-2001  thorpej Remove the use of splimp() from the NetBSD kernel. splnet()
and only splnet() is allowed for the protection of data structures
used by network devices.
 1.38 06-Jun-2000  tsutsui branches: 1.38.4;
sun3 always defines Debugger(), so don't redefine it.
 1.37 26-May-2000  ragge branches: 1.37.2;
Fix for a driver bug provided by Jon W Grubbs (jgrubbs@megsinet.net).

This bug is only visible on some disks, and I have verified that it works
correctly on VAX. However, du to the author, it is a problem on other
machines/disks as well. Here's the author's comments:

> The MI code for the NCR5380 has a small bug in it The RZ56 wants to
> negotiate for Synchronous Data Transfers and when it does, the current code
> looks like it will send a REJECT message as the spec calls for when we cant
> handle the request. However, a couple of lines of code in the
> ncr5380_msg_in routine are missing wrt the PARITY message and anything that
> wants to send a REJECT message. The ATN setup that is done in
> ncr_sched_msgout is immediately negated by the final byte ACK sequence in
> this routine. This causes bad things to happen to an RZ56.
 1.36 29-Mar-2000  tsutsui Remove "register" declaration.
 1.35 25-Mar-2000  tsutsui Add a "sc_rev" member to ncr5380_softc and handle CXD1180 quirk
in MI ncr5380sbc.
 1.34 23-Mar-2000  thorpej New callout mechanism with two major improvements over the old
timeout()/untimeout() API:
- Clients supply callout handle storage, thus eliminating problems of
resource allocation.
- Insertion and removal of callouts is constant time, important as
this facility is used quite a lot in the kernel.

The old timeout()/untimeout() API has been removed from the kernel.
 1.33 18-Mar-2000  mycroft Change footprint of ncr5380_intr() to match normal interrupt handler usage.
 1.32 18-Mar-2000  mycroft Add a ncr5380_attach() routine which does part of the initialization, attaches
the scsibus, and does the addref/delref dance.
 1.31 30-Sep-1999  thorpej branches: 1.31.2;
Update for SCSPI changes.
 1.30 05-Dec-1998  mjacob Update HBAs to incorporate the new max_lun property.
 1.29 26-Oct-1998  scottr Update for changes to NCR5380_READ() and NCR5380_WRITE().
 1.28 25-Oct-1998  christos PR/6274: John Ruschmeyer: Add support for the ncr53c80 driver on the i386.
 1.27 16-Sep-1998  scottr Revert the last change: returning COMPLETE is clearly the wrong thing to do
if we weren't polling to begin with.
 1.26 14-Sep-1998  scottr Correct a serious problem that affects at least front ends that can only
use PIO (or equivalent) code to do asynchronous transfers: In
ncr5380_scsi_cmd(), test to see if the request has been completed after
the call to ncr5380_sched(), and return COMPLETE if so. This avoids
going into an infinite loop in scsipi_execute_xs() while waiting for an
interrupt to trigger completion of the transfer... which, of course,
never happens, since it's already done.
 1.25 04-Jul-1998  jonathan defopt DDB.
 1.24 12-Dec-1997  scottr Fix typo in a trace message expression.
 1.23 05-Sep-1997  scottr Fix a couple of field references missed during the scsipi merge.
 1.22 27-Aug-1997  bouyer Merge scsipi branch in the mainline. This add support for ATAPI devices
(currently only CD-ROM drives on i386). The sys/dev/scsipi system provides 2
busses to which devices can attach (scsibus and atapibus). This needed to
change some include files and structure names in the low level scsi drivers.
 1.21 07-Apr-1997  scottr branches: 1.21.2; 1.21.4;
Fix a debugging printf() format.
 1.20 27-Mar-1997  scottr Work around an ambiguity in the SCSI spec. Some implementations,
particularly older ones, don't do a SAVE DATA POINTER before disconnecting.
When the driver reconnects, it does an implicit RESTORE POINTERS, and
restores the data pointer from *before* the last transfer. If the driver
calculates the residual using the data pointer and doesn't account for
this, the residual will be wrong.

What we do is test for the SDEV_AUTOSAVE quirk when we see a disconnect
message, falling through to do a SAVE DATA POINTER if the quirk applies
to this target.

The workaround was suggested by Mycroft, who also provided the explanation
of the problem. Actual code was (mostly) ripped off from the 53C9x driver.
 1.19 27-Mar-1997  gwr No longer need the hack that forced SCSI_POLL when cold.
 1.18 04-Mar-1997  mycroft Fix a couple of splhigh()s that should be splbio().
 1.17 26-Feb-1997  gwr Use sc_no_disconnect (per-target) instead of NCR5380_PERMIT_RESELECT.
 1.16 26-Feb-1997  gwr Integrate fix for rude targets that transfer more data than requested.
(From Matthias Pfaller).
 1.15 15-Dec-1996  scottr branches: 1.15.4;
Make this compile #ifdef DDB:

- Prototype debugging functions
- Replace %x and %lx with %p as appropriate
 1.14 10-Dec-1996  thorpej Fill in sc_link.max_target
 1.13 13-Oct-1996  christos backout kprintf changes
 1.12 10-Oct-1996  christos - printf -> kprintf, sprintf -> ksprintf
 1.11 13-May-1996  christos Fix printf() statement argument order
 1.10 10-May-1996  gwr Add a new member to the softc (sc_parity_disable) with per-target
bits that tell the driver not to expect parity from those targets.
XXX: For now, it is up to MD code to set this mask. Eventually,
XXX: we should identify targets first (without demanding parity)
XXX: and then use a new "SCSI quirk" to set the right bit.
 1.9 18-Mar-1996  gwr Deal with devices that are slow to get off the bus.
 1.8 07-Mar-1996  christos prototypes for ccd audio and ncr5380
 1.7 01-Mar-1996  gwr Replace DEBUG with NCR5380_DEBUG and do not define it by default.
 1.6 28-Feb-1996  gwr Kill two mis-matched and unnecessary declarations.
 1.5 22-Feb-1996  gwr fix a trace message
 1.4 22-Feb-1996  gwr Do not mark target/LUN busy until we commit to working with it,
after the check for reselections. (From Matthias Pfaller, PR 2105)
Also improve the selection code WRT concurrent reselection.
 1.3 10-Feb-1996  christos vnd.c: Typo (disk_deta{t,}ch) It was detach in the header file and
detatch everywhere else. Reverted to the english spelling.
Also fixed the rest of the prototype warnings while I was at it.
ic/ncr5380sbc.c: Don't declare Debugger()... I have to clean this
everywhere :-(
 1.2 23-Jan-1996  gwr Use the function pointers sc_pio_in, sc_pio_out to call the PIO functions
for transfers in data phase so those functions may be MD implementations
that do "pseudo-DMA" if desired. Also correct some comments.
 1.1 01-Jan-1996  thorpej Switch to David Jones' new machine-independent NCR5380 driver. It's been
in use by the sun3 port for some time, and is now used by the sparc port.
 1.15.4.1 12-Mar-1997  is Merge in changes from Trunk
 1.21.4.2 06-Sep-1997  thorpej Update marc-pcmcia branch from trunk.
 1.21.4.1 27-Aug-1997  thorpej Update marc-pcmcia branch from trunk.
 1.21.2.1 01-Jul-1997  bouyer Updates for new scsipi subsystem. Actally known to work on i386 and sparc.
 1.31.2.8 21-Apr-2001  bouyer Sync with HEAD
 1.31.2.7 29-Mar-2001  bouyer Leave handling of SCSI_CHECK to middle-layer.
 1.31.2.6 22-Jan-2001  bouyer make it compile
 1.31.2.5 15-Jan-2001  bouyer req_sense_length is dead.
 1.31.2.4 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.31.2.3 01-Nov-1999  thorpej Fixup the SC_DEBUG() stuff for the new world order.
 1.31.2.2 26-Oct-1999  thorpej Update for:

Deal a little more gracefully with the fact that xfer mode parameters
are for the I_T Nexus, and make all xfer mode updates `async events'.
 1.31.2.1 19-Oct-1999  thorpej Adapt to scsipi API changes.
 1.37.2.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.38.4.5 17-Apr-2002  nathanw Catch up to -current.
 1.38.4.4 08-Jan-2002  nathanw Catch up to -current.
 1.38.4.3 14-Nov-2001  nathanw Catch up to -current.
 1.38.4.2 24-Aug-2001  nathanw Catch up with -current.
 1.38.4.1 21-Jun-2001  nathanw Catch up to -current.
 1.43.6.1 12-Nov-2001  thorpej Sync the thorpej-mips-cache branch with -current.
 1.43.2.2 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.43.2.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.49.2.7 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.49.2.6 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.49.2.5 04-Feb-2005  skrll Sync with HEAD.
 1.49.2.4 21-Sep-2004  skrll Fix the sync with head I botched.
 1.49.2.3 18-Sep-2004  skrll Sync with HEAD.
 1.49.2.2 12-Aug-2004  skrll Sync with HEAD.
 1.49.2.1 03-Aug-2004  skrll Sync with HEAD
 1.53.6.2 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.53.6.1 12-Feb-2005  yamt sync with head.
 1.53.4.1 29-Apr-2005  kent sync with -current
 1.56.2.2 30-Dec-2006  yamt sync with head.
 1.56.2.1 21-Jun-2006  yamt sync with head.
 1.58.8.1 03-Sep-2006  yamt sync with head.
 1.58.4.1 09-Sep-2006  rpaulo sync with head
 1.59.4.2 10-Dec-2006  yamt sync with head.
 1.59.4.1 22-Oct-2006  yamt sync with head
 1.59.2.2 12-Jan-2007  ad Sync with head.
 1.59.2.1 18-Nov-2006  ad Sync with head.
 1.62.48.1 02-Jun-2008  mjf Sync with HEAD.
 1.63.4.2 11-Aug-2010  yamt sync with head.
 1.63.4.1 11-Mar-2010  yamt sync with head
 1.64.4.1 05-Mar-2011  rmind sync with head
 1.64.2.1 17-Aug-2010  uebayasi Sync with HEAD.
 1.65.8.1 30-Oct-2012  yamt sync with head
 1.66.20.1 20-Mar-2017  pgoyette Sync with HEAD
 1.66.16.1 05-Feb-2017  skrll Sync with HEAD
 1.66.2.1 03-Dec-2017  jdolecek update from HEAD
 1.67.32.1 21-Mar-2021  thorpej Give config_found() the same variadic arguments treatment as
config_search(). This commit only adds the CFARG_EOL sentinel
to the existing config_found() calls. Conversion of config_found_sm_loc()
and config_found_ia() call sites will be in subsequent commits.
 1.68.8.1 04-Aug-2021  thorpej Adapt to CFARGS().
 1.69.12.1 02-Aug-2025  perseant Sync with HEAD
 1.1 20-Nov-2000  bouyer branches: 1.1.2;
file ncr5380sbc.c.orig was initially added on branch thorpej_scsipi.
 1.1.2.2 20-Nov-2000  bouyer Ops, these shouldn't be there !
 1.1.2.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.35 14-Sep-2025  andvar Fix various typos in comments and log message.
 1.34 24-Jan-2018  skrll Remove port-acorn26

OK core@
 1.33 28-Jul-2012  matt Fix -fno-common found by building i386/conf/ALL
 1.32 04-Apr-2008  tsutsui branches: 1.32.38;
Split devict_t/softc for ncr5380sbc SCSI, and misc cosmetic changes.
 1.31 19-Oct-2007  ad branches: 1.31.16;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.30 17-Aug-2006  christos branches: 1.30.12; 1.30.26; 1.30.28; 1.30.32;
Fix all the -D*DEBUG* code that it was rotting away and did not even compile.
Mostly from Arnaud Lacombe, many thanks!
 1.29 11-Dec-2005  christos branches: 1.29.4; 1.29.8;
merge ktrace-lwp.
 1.28 04-Feb-2005  perry branches: 1.28.6;
de-__P
 1.27 13-Aug-2004  tsutsui branches: 1.27.4; 1.27.6;
Use bus_space(9) on news68k.
Update/sort the comment/ifdefs about bus_space-using ports.

XXX which should we use defined(__${MACHINE_CPU}__) or defined(${MACHINE})?
 1.26 13-Aug-2004  mycroft amd64 also has bus_space...
 1.25 07-Aug-2004  mycroft Add Alpha to the list of platforms that use bus_space (for nca@pcmcia).
 1.24 02-Nov-2003  wiz Fix some typos. From Tom Cosgrove via jmc@openbsd.
 1.23 24-Mar-2002  bjh21 branches: 1.23.10;
__arm26__ -> acorn26. This has the advantage of actually being defined.
 1.22 26-Nov-2001  fredette Use bus_space on sun2.
Update the comment to match list of bus_space-using ports.
Removed some old unused asm() labels.
 1.21 26-May-2001  bjh21 branches: 1.21.2;
Use bus_space on arm26.
Update the comment to match list of bus_space-using ports.
Delete oak from list of drivers that need converting.
 1.20 25-Apr-2001  bouyer Pull up the thorpej_scsipi branch to main branch.
This is a completely rewritten scsipi_xfer execution engine, and the
associated changes to HBA drivers. Overview of changes & features:
- All xfers are queued in the mid-layer, rather than doing so in an
ad-hoc fashion in individual adapter drivers.
- Adapter/channel resource management in the mid-layer, avoids even trying
to start running an xfer if the adapter/channel doesn't have the resources.
- Better communication between the mid-layer and the adapters.
- Asynchronous event notification mechanism from adapter to mid-layer and
peripherals.
- Better peripheral queue management: freeze/thaw, sorted requeueing during
recovery, etc.
- Clean separation of peripherals, adapters, and adapter channels (no more
scsipi_link).
- Kernel thread for each scsipi_channel makes error recovery much easier
(no more dealing with interrupt context when recovering from an error).
- Mid-layer support for tagged queueing: commands can have the tag type
set explicitly, tag IDs are allocated in the mid-layer (thus eliminating
the need to use buggy tag ID allocation schemes in many adapter drivers).
- support for QUEUE FULL and CHECK CONDITION status in mid-layer; the command
will be requeued, or a REQUEST SENSE will be sent as appropriate.

Just before the merge syssrc has been tagged with thorpej_scsipi_beforemerge
 1.19 18-Jun-2000  pk branches: 1.19.4;
The sparc clients of this driver (si & sw) now use bus_space_*().
 1.18 25-Mar-2000  tsutsui branches: 1.18.2;
Add a "sc_rev" member to ncr5380_softc and handle CXD1180 quirk
in MI ncr5380sbc.
 1.17 18-Mar-2000  mycroft Change footprint of ncr5380_intr() to match normal interrupt handler usage.
 1.16 18-Mar-2000  mycroft Use bus_space on MIPS.
 1.15 18-Mar-2000  mycroft Add a ncr5380_attach() routine which does part of the initialization, attaches
the scsibus, and does the addref/delref dance.
 1.14 21-Sep-1999  ragge branches: 1.14.2;
Fix minphys() on vax. While here, convert to bus.h.
 1.13 19-Nov-1998  thorpej Adapt to the new scsipi_adapter interface.
 1.12 26-Oct-1998  scottr In order for the SCI_CLR_INTR() and SCI_BUSY() macros to work, we
must actually use the softc pointer provided. Adjust NCR5380_READ()
and NCR5380_WRITE() appropriately.
 1.11 25-Oct-1998  scottr Replace architecture-dependent tag/handle field names with
architecture-independent versions.
 1.10 25-Oct-1998  christos Fix typo
 1.9 25-Oct-1998  christos PR/6274: John Ruschmeyer: Add support for the ncr53c80 driver on the i386.
 1.8 27-Aug-1997  bouyer Merge scsipi branch in the mainline. This add support for ATAPI devices
(currently only CD-ROM drives on i386). The sys/dev/scsipi system provides 2
busses to which devices can attach (scsibus and atapibus). This needed to
change some include files and structure names in the low level scsi drivers.
 1.7 26-Feb-1997  gwr branches: 1.7.2; 1.7.4;
Add the new member "sc_no_disconnect" to ncr5380_softc, and
remove NCR5380_PERMIT_RESELECT.
 1.6 10-May-1996  gwr branches: 1.6.6;
Add a new member to the softc (sc_parity_disable) with per-target
bits that tell the driver not to expect parity from those targets.
XXX: For now, it is up to MD code to set this mask. Eventually,
XXX: we should identify targets first (without demanding parity)
XXX: and then use a new "SCSI quirk" to set the right bit.
 1.5 01-Mar-1996  gwr Replace DEBUG with NCR5380_DEBUG and do not define it by default.
 1.4 01-Jan-1996  thorpej Switch to David Jones' new machine-independent NCR5380 driver. It's been
in use by the sun3 port for some time, and is now used by the sparc port.
 1.3 26-Sep-1995  thorpej Don't declare Debugger(). It's handled in <sys/systm.h>
 1.2 03-Sep-1995  pk Patches from Jason Thorpe to deal with 4/110 scsi (PR#1422).
Also repairs a problem noted by David Jones: detect scsi phase correctly.
 1.1 08-Jul-1995  pk ncr5380 chip definitions and MI part of driver.
 1.6.6.1 12-Mar-1997  is Merge in changes from Trunk
 1.7.4.1 27-Aug-1997  thorpej Update marc-pcmcia branch from trunk.
 1.7.2.1 01-Jul-1997  bouyer Updates for new scsipi subsystem. Actally known to work on i386 and sparc.
 1.14.2.2 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.14.2.1 19-Oct-1999  thorpej Adapt to scsipi API changes.
 1.18.2.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.19.4.3 01-Apr-2002  nathanw Catch up to -current.
(CVS: It's not just a program. It's an adventure!)
 1.19.4.2 08-Jan-2002  nathanw Catch up to -current.
 1.19.4.1 21-Jun-2001  nathanw Catch up to -current.
 1.21.2.2 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.21.2.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.23.10.6 04-Feb-2005  skrll Sync with HEAD.
 1.23.10.5 21-Sep-2004  skrll Fix the sync with head I botched.
 1.23.10.4 18-Sep-2004  skrll Sync with HEAD.
 1.23.10.3 25-Aug-2004  skrll Sync with HEAD.
 1.23.10.2 12-Aug-2004  skrll Sync with HEAD.
 1.23.10.1 03-Aug-2004  skrll Sync with HEAD
 1.27.6.1 12-Feb-2005  yamt sync with head.
 1.27.4.1 29-Apr-2005  kent sync with -current
 1.28.6.2 27-Oct-2007  yamt sync with head.
 1.28.6.1 30-Dec-2006  yamt sync with head.
 1.29.8.1 03-Sep-2006  yamt sync with head.
 1.29.4.1 09-Sep-2006  rpaulo sync with head
 1.30.32.1 25-Oct-2007  bouyer Sync with HEAD.
 1.30.28.1 06-Nov-2007  matt sync with HEAD
 1.30.26.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.30.12.1 23-Oct-2007  ad Sync with head.
 1.31.16.1 02-Jun-2008  mjf Sync with HEAD.
 1.32.38.1 30-Oct-2012  yamt sync with head
 1.1 20-Nov-2000  bouyer branches: 1.1.2;
file ncr5380var.h.orig was initially added on branch thorpej_scsipi.
 1.1.2.2 20-Nov-2000  bouyer Ops, these shouldn't be there !
 1.1.2.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.2 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.1 18-Mar-2000  mycroft branches: 1.1.6; 1.1.128; 1.1.130; 1.1.132;
Move some code around in preparation for nca_pcmcia.
 1.1.132.1 16-May-2008  yamt sync with head.
 1.1.130.1 18-May-2008  yamt sync with head.
 1.1.128.1 02-Jun-2008  mjf Sync with HEAD.
 1.1.6.2 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.1.6.1 18-Mar-2000  bouyer file ncr53c400reg.h was added on branch thorpej_scsipi on 2000-11-20 11:40:46 +0000
 1.156 05-Dec-2021  msaitoh s/timout/timeout/
 1.155 07-Aug-2021  thorpej Merge thorpej-cfargs2.
 1.154 24-Apr-2021  thorpej branches: 1.154.8;
Merge thorpej-cfargs branch:

Simplify and make extensible the config_search() / config_found() /
config_attach() interfaces: rather than having different variants for
which arguments you want pass along, just have a single call that
takes a variadic list of tag-value arguments.

Adjust all call sites:
- Simplify wherever possible; don't pass along arguments that aren't
actually needed.
- Don't be explicit about what interface attribute is attaching if
the device only has one. (More simplification.)
- Add a config_probe() function to be used in indirect configuiration
situations, making is visibly easier to see when indirect config is
in play, and allowing for future change in semantics. (As of now,
this is just a wrapper around config_match(), but that is an
implementation detail.)

Remove unnecessary or redundant interface attributes where they're not
needed.

There are currently 5 "cfargs" defined:
- CFARG_SUBMATCH (submatch function for direct config)
- CFARG_SEARCH (search function for indirect config)
- CFARG_IATTR (interface attribte)
- CFARG_LOCATORS (locators array)
- CFARG_DEVHANDLE (devhandle_t - wraps OFW, ACPI, etc. handles)

...and a sentinel value CFARG_EOL.

Add some extra sanity checking to ensure that interface attributes
aren't ambiguous.

Use CFARG_DEVHANDLE in MI FDT, OFW, and ACPI code, and macppc and shark
ports to associate those device handles with device_t instance. This
will trickle trough to more places over time (need back-end for pre-OFW
Sun OBP; any others?).
 1.153 13-Apr-2020  chs branches: 1.153.4;
slightly change and fix the semantics of pool_set*wat(), pool_sethardlimit()
and pool_prime() (and their pool_cache_* counterparts):

- the pool_set*wat() APIs are supposed to specify thresholds for the count of
free items in the pool before pool pages are automatically allocated or freed
during pool_get() / pool_put(), whereas pool_sethardlimit() and pool_prime()
are supposed to specify minimum and maximum numbers of total items
in the pool (both free and allocated). these were somewhat conflated
in the existing code, so separate them as they were intended.

- change pool_prime() to take an absolute number of items to preallocate
rather than an increment over whatever was done before, and wait for
any memory allocations to succeed. since pool_prime() can no longer fail
after this, change its return value to void and adjust all callers.

- pool_setlowat() is documented as not immediately attempting to allocate
any memory, but it was changed some time ago to immediately try to allocate
up to the lowat level, so just fix the manpage to describe the current
behaviour.

- add a pool_cache_prime() to complete the API set.
 1.152 10-Nov-2019  chs branches: 1.152.6;
in many device attach paths, allocate memory with M_WAITOK instead of M_NOWAIT
and remove code to handle failures that can no longer happen.
 1.151 10-Feb-2019  christos Introduce PR_ZERO to avoid open-coding memset()s everywhere. OK riastradh@.
 1.150 03-Feb-2019  mrg - add or adjust /* FALLTHROUGH */ where appropriate
- add __unreachable() after functions that can return but won't in
this case, and thus can't be marked __dead easily
 1.149 03-Sep-2018  riastradh Rename min/max -> uimin/uimax for better honesty.

These functions are defined on unsigned int. The generic name
min/max should not silently truncate to 32 bits on 64-bit systems.
This is purely a name change -- no functional change intended.

HOWEVER! Some subsystems have

#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))

even though our standard name for that is MIN/MAX. Although these
may invite multiple evaluation bugs, these do _not_ cause integer
truncation.

To avoid `fixing' these cases, I first changed the name in libkern,
and then compile-tested every file where min/max occurred in order to
confirm that it failed -- and thus confirm that nothing shadowed
min/max -- before changing it.

I have left a handful of bootloaders that are too annoying to
compile-test, and some dead code:

cobalt ews4800mips hp300 hppa ia64 luna68k vax
acorn32/if_ie.c (not included in any kernels)
macppc/if_gm.c (superseded by gem(4))

It should be easy to fix the fallout once identified -- this way of
doing things fails safe, and the goal here, after all, is to _avoid_
silent integer truncations, not introduce them.

Maybe one day we can reintroduce min/max as type-generic things that
never silently truncate. But we should avoid doing that for a while,
so that existing code has a chance to be detected by the compiler for
conversion to uimin/uimax without changing the semantics until we can
properly audit it all. (Who knows, maybe in some cases integer
truncation is actually intended!)
 1.148 01-Jul-2017  macallan branches: 1.148.4; 1.148.6;
do what other SCSI drivers do - ack MSG_IGN_WIDE_RESIDUE messages and move on
instead of erroring out and resetting the drive
while there, when rejecting a message print which one it is
now my U2 boots without resetting its disk 3 times
 1.147 11-Jan-2017  skrll adatper -> adapter
 1.146 24-Dec-2016  macallan avoid accessing condition variables which belong to a scsibus before actually
attaching the scsibus
now my SS20 boots again
 1.145 18-Jun-2012  martin branches: 1.145.2; 1.145.16; 1.145.20;
When issuing a non-dma command, make sure to set the "remaining length of
command to be transfered via dma" (sc_cmdlen) to zero upfront, otherwise we
might get confused on command completition interrupt (no dma active but still
data left to transfer).
 1.144 10-Mar-2012  mrg take the kernel lock in functions called from attach*().
 1.143 31-Jul-2011  jakllsch branches: 1.143.2; 1.143.6; 1.143.8;
simple_lock to mutex conversion.
 1.142 04-Jul-2011  joerg Fix memset usage.
 1.141 07-Sep-2009  tsutsui Whitespace nits.
 1.140 02-Sep-2009  tsutsui Some backends may use ncr53c9x_abort(), so remove static declaration from
the function and explicitly declare it in ncr53c9xvar.h. Noticed by he@.
 1.139 29-Aug-2009  tsutsui Uncomment /*static*/ function declarations,
and #ifdef'ed out an unused function.
 1.138 01-May-2009  martin Add missing braces - patch from Kurt Lidl in PR port-vax/41314.
 1.137 13-May-2008  christos branches: 1.137.8; 1.137.12; 1.137.14;
don't play with timevals directly, use the macros. From OpenBSD
 1.136 28-Apr-2008  martin branches: 1.136.2;
Remove clause 3 and 4 from TNF licenses
 1.135 13-Apr-2008  tsutsui branches: 1.135.2; 1.135.4;
Fix another typo.
 1.134 13-Apr-2008  mlelstv fix format strings for DIAGNOSTIC output
 1.133 13-Apr-2008  tsutsui Split device_t/softc for MI ncr53c9x and some related devices,
with various cleanup.
 1.132 08-Apr-2008  cegger use aprint_*_dev and device_xname
 1.131 01-Oct-2007  martin branches: 1.131.18;
Back out accidently commited part of previous
 1.130 01-Oct-2007  martin Do not stop callouts for polled commands.
 1.129 20-Aug-2007  tsutsui branches: 1.129.2; 1.129.4;
KNF, ANSIfy, TAB/space cosmetics.
 1.128 09-Jul-2007  ad branches: 1.128.2; 1.128.6;
Merge some of the less invasive changes from the vmlocking branch:

- kthread, callout, devsw API changes
- select()/poll() improvements
- miscellaneous MT safety improvements
 1.127 12-Mar-2007  ad branches: 1.127.2;
Pass an ipl argument to pool_init/POOL_INIT to be used when initializing
the pool's lock.
 1.126 04-Mar-2007  christos branches: 1.126.2;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.125 09-Jan-2007  itohy branches: 1.125.2;
Cancel commands and free allocated resources on detach.
 1.124 28-Dec-2006  itohy Stop callout on detach.
 1.123 16-Nov-2006  christos __unused removal on arguments; approved by core.
 1.122 12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.121 04-Oct-2006  christos fix empty if
 1.120 07-Jun-2006  kardel branches: 1.120.6; 1.120.8;
merge FreeBSD timecounters from branch simonb-timecounters
- struct timeval time is gone
time.tv_sec -> time_second
- struct timeval mono_time is gone
mono_time.tv_sec -> time_uptime
- access to time via
{get,}{micro,nano,bin}time()
get* versions are fast but less precise
- support NTP nanokernel implementation (NTP API 4)
- further reading:
Timecounter Paper: http://phk.freebsd.dk/pubs/timecounter.pdf
NTP Nanokernel: http://www.eecis.udel.edu/~mills/ntp/html/kern.html
 1.119 29-Mar-2006  thorpej branches: 1.119.2;
Use device_cfdata().
 1.118 24-Dec-2005  perry branches: 1.118.4; 1.118.6; 1.118.8; 1.118.10; 1.118.12;
__inline__ -> inline
 1.117 11-Dec-2005  christos merge ktrace-lwp.
 1.116 06-Nov-2005  tsutsui NCRDMA_SETUP() should be called before NCR_SET_COUNT() and NCRCMD_DMA command
in ncr53c9x_select(). Tested with esp on SS1+ and sun3/80, and pcscp at pci.
 1.115 30-May-2005  christos branches: 1.115.2;
- add missing const
- fix variable shadowing
- remove unneeded casts
 1.114 27-Feb-2005  perry nuke trailing whitespace
 1.113 21-Feb-2005  thorpej Part 1 of a cleanup pass over the SCSI subsystem. The aim is to name
everything "scsi_*", since we really are talking about the SCSI command
set, ATAPI transport not withstanding. Improve the names of many structures,
and prepend "SCSI_" onto all SCSI command opcodes. Place items described
by the SCSI Primary Commands document into scsi_spc.h.
 1.112 10-Sep-2004  bouyer branches: 1.112.4; 1.112.6;
pool_prime() the ncr53c9x_ecb pool with one element (this will cause one page
to be allocated anyway). scsipi can deal with resources shortage, but if this
pool goes down to 0 pages we can deadlock with the scsipi_xfer, vnode or
inode pools.
Also update a comment, despite resources accounting we can return
ATAPTER_RESOURCES_SHORTAGE here.
 1.111 03-May-2004  pk On reset, clear state flags and the msgout queue and notify the upper layer.
 1.110 02-Nov-2003  wiz branches: 1.110.2;
Fix some typos. From Tom Cosgrove via jmc@openbsd.
 1.109 01-Nov-2003  jdolecek avoid strong words; use 'screw' instead
 1.108 19-Oct-2003  simonb Remove unreachable break after return and goto statements.
 1.107 25-Jul-2003  pk Print more diagnostic info on the occassions `unexpected disconnect' and
`invalid state'.
 1.106 16-Apr-2003  petrov branches: 1.106.2;
Comment out debug printf.
 1.105 04-Feb-2003  pk Make this driver MP-safe by using a single spin lock to guard all its entrances.
 1.104 30-Jan-2003  pk The introduction of FAS366 support annihilated the `reselect-while-selecting'
workaround for the ESP100 variant.
 1.103 06-Oct-2002  petrov Reset the driver on scsibus reset.
 1.102 27-Sep-2002  provos remove trailing \n in panic(). approved perry.
 1.101 25-Sep-2002  mycroft Update copyright.
 1.100 25-Sep-2002  mycroft Additional fixes to make 16 targets work on FAS366.
 1.99 24-Sep-2002  mycroft Oof, this driver needs a lot more work to support 16 targets.
 1.98 22-Sep-2002  mycroft Tell the scsibus layer we have 16 targets on the FAS366.
 1.97 16-Sep-2002  petrov Use driver reset in case 'internal state mismatch'.
 1.96 26-Aug-2002  petrov Accept WDTR from device(based on John Heasley patch for SCSI3 drive).
Do not define NCR53C9X_DEBUG.
 1.95 26-Aug-2002  petrov Start SYNC/WIDE renegotiating in controller reset, rearrange debug output.
 1.94 21-Jun-2002  lukem implement SCBUSIORESET by calling ncr53c9x_scsi_reset()
 1.93 05-Apr-2002  bouyer branches: 1.93.2; 1.93.4;
Implement mstohz() as discussed on tech-kern, and use it in SCSI drivers
to convert xs->timeout to callout() parameter.
 1.92 02-Apr-2002  petrov Return from interrupt handler after chip init(reset).
 1.91 24-Mar-2002  jdolecek ncr53c9x_attach(): if sc_rev is NCR53C90_86C01, set it to ESP100 once
the variant name is printed.
This fixes a problem that the card would be treated as ESP100 in
ncr53c9x_reset(), but not on couple other places (pointed out by
Andy Doran in private e-mail).

g/c now redundant case entry in ncr53c9x_reset()
 1.90 08-Mar-2002  thorpej Pool deals fairly well with physical memory shortage, but it doesn't
deal with shortages of the VM maps where the backing pages are mapped
(usually kmem_map). Try to deal with this:

* Group all information about the backend allocator for a pool in a
separate structure. The pool references this structure, rather than
the individual fields.
* Change the pool_init() API accordingly, and adjust all callers.
* Link all pools using the same backend allocator on a list.
* The backend allocator is responsible for waiting for physical memory
to become available, but will still fail if it cannot callocate KVA
space for the pages. If this happens, carefully drain all pools using
the same backend allocator, so that some KVA space can be freed.
* Change pool_reclaim() to indicate if it actually succeeded in freeing
some pages, and use that information to make draining easier and more
efficient.
* Get rid of PR_URGENT. There was only one use of it, and it could be
dealt with by the caller.

From art@openbsd.org.
 1.89 12-Jan-2002  tsutsui Call malloc(9) with M_ZERO flag instead of memset() after malloc().
 1.88 03-Dec-2001  jdolecek add NCR_VARIANT_NCR53C90_86C01 "NCR53C90 (86C01)"
treat exactly like NCR_VARIANT_ESP100
 1.87 15-Nov-2001  lukem don't need <sys/types.h> when including <sys/param.h>
 1.86 13-Nov-2001  lukem add/cleanup RCSID
 1.85 04-Nov-2001  tsutsui Use common macro to check message length.
 1.84 26-Jul-2001  tsutsui branches: 1.84.4;
Fix timeout overflow caused by "scsictl format" on machines HZ==100.
 1.83 10-Jul-2001  chs branches: 1.83.2;
add a missing newline in a printf.
 1.82 07-Jul-2001  thorpej bzero -> memset
 1.81 07-Jul-2001  thorpej bcopy -> memcpy
 1.80 23-May-2001  petrov adjust fas register fields names
 1.79 18-May-2001  bouyer Enable tagged queuing again; should work now with scsipi_base rev 1.42
 1.78 30-Apr-2001  bouyer Ops, don't forget to increment li->used for each tagged command.
 1.77 28-Apr-2001  bouyer - don't wait when called from interrupt context (basically this means we
can't sleep in HBA drivers)
- pool_get can fail, so return XS_RESOURCE_SHORTAGE instead of panic()
- don't try to bzero() a NULL pointer
 1.76 26-Apr-2001  bouyer Disable tagged queuing for now, it causes commands timeouts.
Note that it's not worse since thorpej_scsipi integration: tagged queuing
was not used before, because of a tag message rejected at probe time.
 1.75 25-Apr-2001  bouyer Pull up the thorpej_scsipi branch to main branch.
This is a completely rewritten scsipi_xfer execution engine, and the
associated changes to HBA drivers. Overview of changes & features:
- All xfers are queued in the mid-layer, rather than doing so in an
ad-hoc fashion in individual adapter drivers.
- Adapter/channel resource management in the mid-layer, avoids even trying
to start running an xfer if the adapter/channel doesn't have the resources.
- Better communication between the mid-layer and the adapters.
- Asynchronous event notification mechanism from adapter to mid-layer and
peripherals.
- Better peripheral queue management: freeze/thaw, sorted requeueing during
recovery, etc.
- Clean separation of peripherals, adapters, and adapter channels (no more
scsipi_link).
- Kernel thread for each scsipi_channel makes error recovery much easier
(no more dealing with interrupt context when recovering from an error).
- Mid-layer support for tagged queueing: commands can have the tag type
set explicitly, tag IDs are allocated in the mid-layer (thus eliminating
the need to use buggy tag ID allocation schemes in many adapter drivers).
- support for QUEUE FULL and CHECK CONDITION status in mid-layer; the command
will be requeued, or a REQUEST SENSE will be sent as appropriate.

Just before the merge syssrc has been tagged with thorpej_scsipi_beforemerge
 1.74 21-Apr-2001  tsutsui Make sure to check SC_ACCEL_TAGS in ncr53c9x_ioctl()
even if sync transfer is disabled or not supported.
 1.73 21-Apr-2001  tsutsui Clean up ncr53c9x_select():
- Define NCR_F_SELATN3 for sc_features and use it to check if the chip
supports SELATN3 command
- Make conditions of sending messages a bit simpler.
 1.72 20-Apr-2001  tsutsui Cosmetics. (tab/space etc.)
 1.71 29-Mar-2001  petrov fas support added
 1.70 19-Jan-2001  eeh branches: 1.70.2;
Use the SCSIACCEL ioctl() to turn on TAG QUEUEs.
 1.69 20-Dec-2000  briggs Make _sure_ that we do not use selatn3 when it is not present. Fixes a
problem on pmax reported by Izumi Tsutsui. Tested also on alpha and mac68k.
 1.68 20-Dec-2000  eeh Make the driver negotiate sync again and remove some (hopefully) superfluous
DELAY()s.
 1.67 19-Dec-2000  pk Fix reversed logic when setting setting sync-negotiation ability flag
 1.66 18-Dec-2000  briggs If the target rejects a tag message, turn off tagged transfers for that target.
Also, adjust message/command construction in ncr53c9x_select() to work no
matter how the structure alignment works out (needed at least for m68k).
Tested by me on mac68k & alpha, and sanity-checked by eeh.
 1.65 17-Dec-2000  briggs Back out previous change. It appears to be in error. There is something
else that is causing the esp driver on the mac68k to fail miserably.
 1.64 17-Dec-2000  briggs At least the 53c96 does not work with the selatn3 command. Disable it
for both the 53c94 and 53c96. This also addresses PR port-mac68k/11716.
 1.63 10-Dec-2000  eeh Fix for chips that don't grok NCRCMD_SELATN3.
 1.62 04-Dec-2000  fvdl 'error' was not initialized in the _ioctl function, potentially returning
!= 0 values in the non-error case.
 1.61 03-Dec-2000  eeh Fix bug in non-dma select code i added.
 1.60 01-Dec-2000  augustss Make this compile again (on i386).
 1.59 30-Nov-2000  pk We don't need <sys/proc.h>, <sys/user.h> and <machine/cpu.h>.
 1.58 30-Nov-2000  pk De-__P().
 1.57 30-Nov-2000  pk KNF patrol.
 1.56 30-Nov-2000  thorpej Fix some printf formats, and remove SPARC-specific debugging stuff.
 1.55 30-Nov-2000  pk Fix two cases of reversed arguments to printf();
 1.54 30-Nov-2000  eeh Add TAG QUEUE support to the ncr53c9x driver.
 1.53 13-Nov-2000  pk Define ncr53c9x_ioctl() and use it to start sync negotiation.
 1.52 04-Jul-2000  nisimura Fix negative timeout symptoms caused by integer multiply overflow,
which is revealed with larger HZ systems like NetBSD/pmax (256Hz)
and NetBSD/alpha (1024Hz) as reported by PR#8645. Polled tape
drive access is done with maximum 6 hour timeout which ended up
with negative time and then confused SCSI bus severely.
 1.51 05-Jun-2000  tsutsui branches: 1.51.2;
Oops, struct scsipi_adapter was changed recently.
 1.50 05-Jun-2000  nisimura Have MI ncr53c9x_attach() the 2nd and 3rd arguments for scsipi_adater
and scsipi_device respectively, with size reduction of ncr53c9x_softc.
Specifying NULL instructs the driver to use default adapter and default
device codes. Every target port has ncr53c9x_attach(sc, NULL, NULL) anyway.
 1.49 29-Mar-2000  tsutsui branches: 1.49.2;
Nuke register declarations.
 1.48 23-Mar-2000  thorpej New callout mechanism with two major improvements over the old
timeout()/untimeout() API:
- Clients supply callout handle storage, thus eliminating problems of
resource allocation.
- Insertion and removal of callouts is constant time, important as
this facility is used quite a lot in the kernel.

The old timeout()/untimeout() API has been removed from the kernel.
 1.47 22-Mar-2000  mycroft There's no need to frob cfg4/cfg5 in _attach(), since _reset() does it.
 1.46 20-Mar-2000  tsutsui Use sc_cfg4 for the Am53c974.
 1.45 20-Mar-2000  mycroft Reset CFG4 and CFG5 correctly in the reset routine.
 1.44 19-Mar-2000  mycroft For the ESP406/FAS408, add sc_cfg4 and sc_cfg5.
Add a detach routine, and do the addref/delref.
 1.43 18-Mar-2000  mycroft Expose ncr53c9x_init().
 1.42 18-Mar-2000  mycroft Adjust ncr53c9x_intr() prototype.
 1.41 09-Mar-2000  matt change Mb/s to MB/s (Megabit to megabyte).
 1.40 25-Jan-2000  pk Prevent possible wayward loop.
 1.39 10-Nov-1999  mycroft branches: 1.39.2;
Modification to the previous:
We still have to preload the command, when selecting without ATN. (We could
probably avoid this by being more careful in the interrupt handler...)
 1.38 10-Nov-1999  mycroft When sending a REQUEST SENSE, do *not* attempt to create an I_T_L nexus. This
is technically wrong, and some targets (like my 4x NEC CD-ROM drive) misbehave
when we do.
 1.37 10-Nov-1999  mycroft A residual after select with DMA step 2 is legitimate (in fact, *not* having a
residual would probably be cause for concern), so don't spew about it.
 1.36 30-Sep-1999  thorpej branches: 1.36.2; 1.36.4; 1.36.6;
Update for SCSPI changes.
 1.35 22-Sep-1999  mhitch Define config register 3 values for NCR53C9x/FAS216.

Add sc_cfg3_fscsi to the softc and use it to set the chip into Fast SCSI
mode for the chips that use it.
 1.34 12-Feb-1999  thorpej branches: 1.34.2;
Fix printf format problems on Alpha.
 1.33 06-Jan-1999  thorpej Changes to NCR53c9x driver necessary to add support for the AMD Am53c974
PCscsi-PCI SCSI controller. From Izumi Tsutsui, PR #6654.
 1.32 05-Dec-1998  mjacob Update HBAs to incorporate the new max_lun property.
 1.31 30-Nov-1998  pk Update previous: we don't have the required information all the time.
 1.30 30-Nov-1998  pk Some more misc. cleanup in the same style as previous.
 1.29 30-Nov-1998  pk Announce negotiation of async mode consistently (Soren Jorvang; PR#6512)
 1.28 19-Nov-1998  thorpej Adapt to the new scsipi_adapter interface.
 1.27 15-Aug-1998  mycroft Assign my copyrights to TNF.
 1.26 26-May-1998  thorpej If we have an NCR53CF9x (indicated by the front-end by setting a flag
in the softc's new "features" word), set FSCSI bit in CFG3 if the sync
period is <= 200ns, or clear it otherwise.
 1.25 04-May-1998  pk Eliminate the degenerate loop in `ncr53c9x_intr()'. Retain the delay heuristic
it implemented under the label `shortcut:' and only use it in these
cases: (1) after successful re-relection, (2) after receiving command-complete
status, and (3) during message-in handshake.
 1.24 04-May-1998  pk Allocate SCSI message buffers in ncr53c9x_attach(), with a provision
for front-ends to override the allocation to avoid alignment
handling in their DMA engines. Note that that ncr53c9x_msgout()
can request a 1 byte DMA transfer that would be difficult to break up.
 1.23 31-Jan-1998  pk * Make sure the `ECB_NEXUS' flag accurately reflects the existence of
an initiator/target nexus and thus mark the correct queue (if any) a
command is on.

* If a disconnected command times out, just leave it on the nexus queue
and do nothing (for now). I need yet to decide on the strategy to
follow in this case. Note: we used to move the command to the `ready'
queue and then do nothing, which is worse.
 1.22 24-Jan-1998  pk * Do not remove ATN from the scsi bus if we have no messages queued but
the target still is in MSG OUT phase. We still send a message (a NO_OP)
in this case and the chip will remove ATN at the appropriate time.
Using the RSTATN command here induces a "illegal command" in some
chip revisions.

This situation only occurs if the target rejects a previous (multi-byte)
message early (by switching to MESSAGE IN and sending a MESSAGE REJECT)
before the chip has completed the entire MSG OUT transfer. ATN will
remain asserted, and the target returns to MESSAGE OUT phase.

* Account for the events above when reporting "DMA not completed"
diagnostic messages.

* Stream-line the selection code a bit, and make the DMA setup code
more like the MSG OUT & DATA XFER setup.
 1.21 26-Oct-1997  pk Apply patch from Michael L. Hitch (PR#4318):

"A sequence step of 0 after a select with ATN can be a selection
timeout, or it can also indicate the target did not respond with
a message out phase. The latter will occur on very old SCSI
devices which do not respond to the ATN signal and go directly to
the command phase".
 1.20 04-Oct-1997  mhitch branches: 1.20.2;
Add yet another chip variant: FAS216, used by the amiga Phase5 SCSI boards.
 1.19 31-Aug-1997  pk Finish work-around for the re-select bug on ESP100s by dealing with
"illegal command" interrupt apparently caused by writing to the chip
while a re-selection is in progress.
 1.18 27-Aug-1997  bouyer Merge scsipi branch in the mainline. This add support for ATAPI devices
(currently only CD-ROM drives on i386). The sys/dev/scsipi system provides 2
busses to which devices can attach (scsibus and atapibus). This needed to
change some include files and structure names in the low level scsi drivers.
 1.17 04-Aug-1997  fair trivial change for PR#3815
 1.16 30-Jul-1997  pk Arrange to turn off future sync-mode negotiation after experiencing a
timeout while in a data phase.

Replace XS_STUFFUP with XS_TIMEOUT, so we get a second chance after
recovering.
 1.15 29-Jul-1997  pk branches: 1.15.2;
If state is NCR_CLEANING, do not schedule commands until reset is complete.
 1.14 22-Jul-1997  pk Relax `DMA terminal count' check to exclude any selection state to avoid
triggering the message when merely probing targets.
 1.13 20-Jul-1997  pk While processing DISCONNECTs, take note of the transfer count reaching
zero. We use this later when the COMPLETE message comes in to set the
final residual count to zero. The flag is reset if the target resumes
a data phase. This obsoletes the `AUTOSAVE' quirk (for this driver).
Also, avoid overwriting the residual count if a SENSE was appended to
the current transaction.
 1.12 19-Jul-1997  pk Propagate SCSI status byte back to higher levels.
 1.11 26-Jun-1997  thorpej branches: 1.11.2;
Do not print "esp0: !TC [intr ...]" messages if:
(a) The interrupt is a RESEL interrupt, and
(b) our state is SELECTING.
This condition can occur in perfectly normal operation if we are using
DMA to select the target and we are interrupted by another target
reselecting us. Per discussion with Paul Krannenburg.
 1.10 01-May-1997  pk Preliminary support for ESP406 and FAS408 variants (from Eric Hvodza; PR#3559)
 1.9 28-Apr-1997  mjacob On alpha size_t is not an int, ergo last argument to dma setup glue
function can't be a pointer to an int.
 1.8 27-Apr-1997  pk Implement target selection using DMA.
To allow a period of testing the variable `ncr53c9x_dmaselect' is used to
enable this feature (default is 0, i.e. the old behaviour).
 1.7 01-Apr-1997  gwr Always schedule a timeout before the first occasion where
we return from the driver expecting to come back due to an
interrupt, because the interrupt might not happen...
Do the untimeout in ncr53c9x_done instead of just before
almost every call to ncr53c9x_done as was done previously.
Make ncr53c9x_sense schedule its own timeout for the new
command it is starting (request sense), separate from the
timeout for the command that just completed.
 1.6 27-Mar-1997  gwr No longer need the hack that forced SCSI_POLL when cold.
 1.5 27-Mar-1997  pk Add workaround for the "extraneous bytes after re-select" problem that
ESP100 chips may exhibit.
 1.4 24-Mar-1997  gwr When cold!=0 force SCSI_POLL (otherwise swapconf will hang)
 1.3 15-Mar-1997  is New ARP system, supports IPv4 over any hardware link.

Some of the stuff (e.g., rarpd, bootpd, dhcpd etc., libsa) still will
only support Ethernet. Tcpdump itself should be ok, but libpcap needs
lot of work.

For the detailed change history, look at the commit log entries for
the is-newarp branch.
 1.2 27-Feb-1997  briggs branches: 1.2.2;
Add the 53c96 variant.
 1.1 27-Feb-1997  thorpej Machine-independent NCR 53c9x SCSI driver, derived from the SPARC/Alpha
versions. Thanks to Chris Demetrious and Paul Krannenburg for the
initial work towards merging the two.
 1.2.2.2 12-Mar-1997  is Merge in changes from Trunk
 1.2.2.1 27-Feb-1997  is file ncr53c9x.c was added on branch is-newarp on 1997-03-12 21:22:45 +0000
 1.11.2.4 14-Aug-1997  bouyer Sync with trunk.
 1.11.2.3 30-Jul-1997  bouyer Sync with trunk.
 1.11.2.2 22-Jul-1997  bouyer Sync with trunk.
 1.11.2.1 01-Jul-1997  bouyer Updates for new scsipi subsystem. Actally known to work on i386 and sparc.
 1.15.2.4 14-Oct-1997  thorpej Update marc-pcmcia branch from trunk.
 1.15.2.3 01-Sep-1997  thorpej Update marc-pcmcia branch from trunk.
 1.15.2.2 27-Aug-1997  thorpej Update marc-pcmcia branch from trunk.
 1.15.2.1 23-Aug-1997  thorpej Update marc-pcmcia branch from trunk.
 1.20.2.4 18-Jan-1999  cgd pull up rev 1.24 from trunk (PR#5180). (pk)
 1.20.2.3 07-Feb-1998  mellon Pull up 1.23 (pk)
 1.20.2.2 07-Feb-1998  mellon Pull up 1.22 (pk)
 1.20.2.1 27-Oct-1997  mellon Pull rev 1.21 up from trunk (pk)
 1.34.2.1 04-Dec-1999  he Pull up revision 1.35 (requested by mhitch):
Fix the problems in detecting the clock speed on the TCDS Dual
SCSI Option cards, and correctly configure the Fast SCSI interfaces.
This allows installation on the 3000/500 -> 3000/900 Alphas which
have the Fast SCSI interface on the on-board SCSI adapters.
 1.36.6.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.36.4.1 15-Nov-1999  fvdl Sync with -current
 1.36.2.19 25-Apr-2001  bouyer add back a missing
ecb->flags |= ECB_READY;
I can run with tagged queuing enabled on my ultra/1 now, which is an
improvement over -current :)
 1.36.2.18 25-Apr-2001  bouyer Add back a ncr53c9x_dequeue() which has been removed by mistake, I think.
 1.36.2.17 24-Apr-2001  bouyer reset ti->width to 0 when wide negotiation didn't succeed. Use this to
report wide status; T_WIDE is only used to tell if wide nego should be
started.
While I'm there fix a bogon in tagged queueing reporting.
 1.36.2.16 23-Apr-2001  bouyer Sync with HEAD.
 1.36.2.15 21-Apr-2001  bouyer Sync with HEAD
 1.36.2.14 23-Mar-2001  bouyer Remove debugging code.
 1.36.2.13 11-Feb-2001  bouyer Sync with HEAD.
 1.36.2.12 15-Jan-2001  bouyer Make it compile again.
 1.36.2.11 05-Jan-2001  bouyer Sync with HEAD
 1.36.2.10 19-Dec-2000  bouyer Add more ncr53c9x_update_xfer_mode() where appropriate.
 1.36.2.9 16-Dec-2000  bouyer Remove debug printf.
 1.36.2.8 16-Dec-2000  bouyer Gives a single-bit flag for T_TAGOFF.
Report tagged-queuing support to upper layer, so that tagged queuing is
really used. Report QUEUE FULL events to upper layer. Bup per-target
openings to 256 as the driver supports it. Fix handling of T_SYNCOFF.
 1.36.2.7 13-Dec-2000  bouyer Sync with HEAD (for UBC fixes).
 1.36.2.6 08-Dec-2000  bouyer Sync with HEAD.
 1.36.2.5 22-Nov-2000  bouyer Sync with HEAD.
 1.36.2.4 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.36.2.3 26-Oct-1999  thorpej Update for:

Deal a little more gracefully with the fact that xfer mode parameters
are for the I_T Nexus, and make all xfer mode updates `async events'.
 1.36.2.2 19-Oct-1999  thorpej Don't sleep waiting for a CCB; if we get to the CCB allocation phase, we're
guaranteed to have one.
 1.36.2.1 19-Oct-1999  thorpej Adapt to scsipi API changes.
 1.39.2.2 10-Nov-1999  mycroft Modification to the previous:
We still have to preload the command, when selecting without ATN. (We could
probably avoid this by being more careful in the interrupt handler...)
 1.39.2.1 10-Nov-1999  mycroft file ncr53c9x.c was added on branch comdex-fall-1999 on 1999-11-10 05:02:54 +0000
 1.49.2.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.51.2.1 04-Jul-2000  thorpej Pull up rev. 1.52:
Fix negative timeout symptoms caused by integer multiply overflow,
which is revealed with larger HZ systems like NetBSD/pmax (256Hz)
and NetBSD/alpha (1024Hz) as reported by PR#8645. Polled tape
drive access is done with maximum 6 hour timeout which ended up
with negative time and then confused SCSI bus severely.
 1.70.2.11 18-Oct-2002  nathanw Catch up to -current.
 1.70.2.10 27-Aug-2002  nathanw Catch up to -current.
 1.70.2.9 01-Aug-2002  nathanw Catch up to -current.
 1.70.2.8 17-Apr-2002  nathanw Catch up to -current.
 1.70.2.7 01-Apr-2002  nathanw Catch up to -current.
(CVS: It's not just a program. It's an adventure!)
 1.70.2.6 28-Feb-2002  nathanw Catch up to -current.
 1.70.2.5 08-Jan-2002  nathanw Catch up to -current.
 1.70.2.4 14-Nov-2001  nathanw Catch up to -current.
 1.70.2.3 24-Aug-2001  nathanw Catch up with -current.
 1.70.2.2 21-Jun-2001  nathanw Catch up to -current.
 1.70.2.1 09-Apr-2001  nathanw Catch up with -current.
 1.83.2.8 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.83.2.7 06-Sep-2002  jdolecek sync kqueue branch with HEAD
 1.83.2.6 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.83.2.5 16-Mar-2002  jdolecek Catch up with -current.
 1.83.2.4 11-Feb-2002  jdolecek Sync w/ -current.
 1.83.2.3 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.83.2.2 03-Aug-2001  lukem update to -current
 1.83.2.1 10-Jul-2001  lukem file ncr53c9x.c was added on branch kqueue on 2001-08-03 04:13:02 +0000
 1.84.4.1 12-Nov-2001  thorpej Sync the thorpej-mips-cache branch with -current.
 1.93.4.2 03-Feb-2003  jmc Pullup revisions 1.103->1.104 (requested by pk in ticket #1138)
The introduction of FAS366 support annihilated the
`reselect-while-selecting\' workaround for the ESP100 variant.
 1.93.4.1 22-Nov-2002  tron Pull up revision 1.94-1.103 (requested by martin in ticket #948):
Additional fixes to make 16 targets work on FAS366.
 1.93.2.2 29-Aug-2002  gehenna catch up with -current.
 1.93.2.1 15-Jul-2002  gehenna catch up with -current.
 1.106.2.5 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.106.2.4 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.106.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.106.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.106.2.1 03-Aug-2004  skrll Sync with HEAD
 1.110.2.2 11-Sep-2004  he Pull up revision 1.112 (requested by bouyer in ticket #838):
Reserve one element for the ncr53c9x_ecb pool to ensure that
we will not deadlock against other pool users.
 1.110.2.1 06-May-2004  jmc Pullup rev 1.111 (requested by pk in ticket #255)

On reset, clear state flags and the msgout queue and notify the upper layer.
 1.112.6.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.112.4.1 29-Apr-2005  kent sync with -current
 1.115.2.5 27-Oct-2007  yamt sync with head.
 1.115.2.4 03-Sep-2007  yamt sync with head.
 1.115.2.3 26-Feb-2007  yamt sync with head.
 1.115.2.2 30-Dec-2006  yamt sync with head.
 1.115.2.1 21-Jun-2006  yamt sync with head.
 1.118.12.1 31-Mar-2006  tron Merge 2006-03-31 NetBSD-current into the "peter-altq" branch.
 1.118.10.1 19-Apr-2006  elad sync with head.
 1.118.8.2 26-Jun-2006  yamt sync with head.
 1.118.8.1 01-Apr-2006  yamt sync with head.
 1.118.6.2 22-Apr-2006  simonb Sync with head.
 1.118.6.1 04-Feb-2006  simonb Adapt for timecounters: mostly use get*time() and use "time_second"
instead of "time.tv_sec".
 1.118.4.1 09-Sep-2006  rpaulo sync with head
 1.119.2.1 19-Jun-2006  chap Sync with head.
 1.120.8.2 10-Dec-2006  yamt sync with head.
 1.120.8.1 22-Oct-2006  yamt sync with head
 1.120.6.2 12-Jan-2007  ad Sync with head.
 1.120.6.1 18-Nov-2006  ad Sync with head.
 1.125.2.2 24-Mar-2007  yamt sync with head.
 1.125.2.1 12-Mar-2007  rmind Sync with HEAD.
 1.126.2.3 09-Oct-2007  ad Sync with head.
 1.126.2.2 01-Jul-2007  ad Adapt to callout API change.
 1.126.2.1 13-Mar-2007  ad Sync with head.
 1.127.2.1 11-Jul-2007  mjf Sync with head.
 1.128.6.2 02-Oct-2007  joerg Sync with HEAD.
 1.128.6.1 03-Sep-2007  jmcneill Sync with HEAD.
 1.128.2.1 03-Sep-2007  skrll Sync with HEAD.
 1.129.4.1 06-Oct-2007  yamt sync with head.
 1.129.2.1 06-Nov-2007  matt sync with HEAD
 1.131.18.1 02-Jun-2008  mjf Sync with HEAD.
 1.135.4.3 16-Sep-2009  yamt sync with head
 1.135.4.2 04-May-2009  yamt sync with head.
 1.135.4.1 16-May-2008  yamt sync with head.
 1.135.2.1 18-May-2008  yamt sync with head.
 1.136.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.137.14.1 03-May-2009  bouyer branches: 1.137.14.1.2;
Pull up following revision(s) (requested by martin in ticket #734):
sys/dev/ic/ncr53c9x.c: revision 1.138
Add missing braces - patch from Kurt Lidl in PR port-vax/41314.
 1.137.14.1.2.1 21-Apr-2010  matt sync to netbsd-5
 1.137.12.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.137.8.1 03-May-2009  bouyer Pull up following revision(s) (requested by martin in ticket #734):
sys/dev/ic/ncr53c9x.c: revision 1.138
Add missing braces - patch from Kurt Lidl in PR port-vax/41314.
 1.143.8.2 25-Jul-2012  jdc Pull up revision 1.145 (requested by ryoon in ticket #439).

When issuing a non-dma command, make sure to set the "remaining length of
command to be transfered via dma" (sc_cmdlen) to zero upfront, otherwise we
might get confused on command completition interrupt (no dma active but still
data left to transfer).
 1.143.8.1 19-Mar-2012  riz Pull up following revision(s) (requested by mrg in ticket #125):
sys/dev/scsipi/scsiconf.c: revision 1.263
sys/dev/scsipi/scsiconf.c: revision 1.264
sys/dev/ic/ncr53c9x.c: revision 1.144
sys/dev/ic/ninjascsi32.c: revision 1.22
sys/dev/usb/uhub.c: revision 1.117
take the kernel lock in functions called from attach*().
scsidevdetached ioctl path enters scsipi code without kernel lock
and this upsets the newer kasserts. take kernel lock here.
take the kernel lock a few more places when doing detach, to avoid
triggering KERNEL_LOCK_P() asserts in both scsi and usb code.
with this and other recent fixes i can now "drvctl -d ehci0".
 1.143.6.1 11-Mar-2012  mrg sync to latest -current
 1.143.2.2 30-Oct-2012  yamt sync with head
 1.143.2.1 17-Apr-2012  yamt sync with head
 1.145.20.2 20-Mar-2017  pgoyette Sync with HEAD
 1.145.20.1 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.145.16.2 28-Aug-2017  skrll Sync with HEAD
 1.145.16.1 05-Feb-2017  skrll Sync with HEAD
 1.145.2.1 03-Dec-2017  jdolecek update from HEAD
 1.148.6.3 21-Apr-2020  martin Sync with HEAD
 1.148.6.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.148.6.1 10-Jun-2019  christos Sync with HEAD
 1.148.4.1 06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.152.6.1 20-Apr-2020  bouyer Sync with HEAD
 1.153.4.1 21-Mar-2021  thorpej Give config_found() the same variadic arguments treatment as
config_search(). This commit only adds the CFARG_EOL sentinel
to the existing config_found() calls. Conversion of config_found_sm_loc()
and config_found_ia() call sites will be in subsequent commits.
 1.154.8.1 04-Aug-2021  thorpej Adapt to CFARGS().
 1.1 20-Nov-2000  bouyer branches: 1.1.2;
file ncr53c9x.c.orig was initially added on branch thorpej_scsipi.
 1.1.2.2 20-Nov-2000  bouyer Ops, these shouldn't be there !
 1.1.2.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.1 20-Nov-2000  bouyer branches: 1.1.2;
file ncr53c9x.c.rej was initially added on branch thorpej_scsipi.
 1.1.2.2 20-Nov-2000  bouyer Remove files that should not have been added
 1.1.2.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.16 07-Sep-2009  tsutsui Whitespace nits.
 1.15 11-Dec-2005  christos branches: 1.15.74;
merge ktrace-lwp.
 1.14 27-Feb-2005  perry nuke trailing whitespace
 1.13 02-Nov-2003  wiz branches: 1.13.8; 1.13.10;
Fix some typos. From Tom Cosgrove via jmc@openbsd.
 1.12 03-May-2003  wiz branches: 1.12.2;
DMA, not dma nor Dma.
 1.11 21-Feb-2003  tsutsui hz -> Hz
 1.10 21-Nov-2001  wiz "than" instead of "then".
 1.9 23-May-2001  petrov branches: 1.9.2;
adjust fas register fields names
 1.8 29-Mar-2001  petrov fas support added
 1.7 20-Mar-2000  mycroft branches: 1.7.6;
NCR_SCSIREGS() and NCR_PIOREGS() are bogus. GC them.
 1.6 22-Sep-1999  mhitch branches: 1.6.2;
Define config register 3 values for NCR53C9x/FAS216.

Add sc_cfg3_fscsi to the softc and use it to set the chip into Fast SCSI
mode for the chips that use it.
 1.5 06-Jan-1999  thorpej branches: 1.5.2;
Changes to NCR53c9x driver necessary to add support for the AMD Am53c974
PCscsi-PCI SCSI controller. From Izumi Tsutsui, PR #6654.
 1.4 17-May-1997  pk Mods for ESP406/FAS408 SCSI driver (from Eric S. Hvozda; PR#3581)
 1.3 01-May-1997  pk Preliminary support for ESP406 and FAS408 variants (from Eric Hvodza; PR#3559)
 1.2 15-Mar-1997  is New ARP system, supports IPv4 over any hardware link.

Some of the stuff (e.g., rarpd, bootpd, dhcpd etc., libsa) still will
only support Ethernet. Tcpdump itself should be ok, but libpcap needs
lot of work.

For the detailed change history, look at the commit log entries for
the is-newarp branch.
 1.1 27-Feb-1997  thorpej branches: 1.1.2;
Machine-independent NCR 53c9x SCSI driver, derived from the SPARC/Alpha
versions. Thanks to Chris Demetrious and Paul Krannenburg for the
initial work towards merging the two.
 1.1.2.2 12-Mar-1997  is Merge in changes from Trunk
 1.1.2.1 27-Feb-1997  is file ncr53c9xreg.h was added on branch is-newarp on 1997-03-12 21:22:50 +0000
 1.5.2.1 04-Dec-1999  he Pull up revision 1.6 (requested by mhitch):
Fix the problems in detecting the clock speed on the TCDS Dual
SCSI Option cards, and correctly configure the Fast SCSI interfaces.
This allows installation on the 3000/500 -> 3000/900 Alphas which
have the Fast SCSI interface on the on-board SCSI adapters.
 1.6.2.3 21-Apr-2001  bouyer Sync with HEAD
 1.6.2.2 16-Dec-2000  bouyer Gives a single-bit flag for T_TAGOFF.
Report tagged-queuing support to upper layer, so that tagged queuing is
really used. Report QUEUE FULL events to upper layer. Bup per-target
openings to 256 as the driver supports it. Fix handling of T_SYNCOFF.
 1.6.2.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.7.6.3 08-Jan-2002  nathanw Catch up to -current.
 1.7.6.2 21-Jun-2001  nathanw Catch up to -current.
 1.7.6.1 09-Apr-2001  nathanw Catch up with -current.
 1.9.2.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.12.2.4 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.12.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.12.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.12.2.1 03-Aug-2004  skrll Sync with HEAD
 1.13.10.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.13.8.1 29-Apr-2005  kent sync with -current
 1.15.74.1 16-Sep-2009  yamt sync with head
 1.58 06-Dec-2024  andvar s/suggesion/suggestion/ in comment.
 1.57 01-Jan-2022  andvar branches: 1.57.10;
fix typos in comments, mainly basicly -> basically.
 1.56 25-Mar-2014  christos kill sprintf
 1.55 31-Jul-2011  jakllsch branches: 1.55.2; 1.55.12; 1.55.16;
simple_lock to mutex conversion.
 1.54 07-Sep-2009  tsutsui Whitespace nits.
 1.53 02-Sep-2009  tsutsui Some backends may use ncr53c9x_abort(), so remove static declaration from
the function and explicitly declare it in ncr53c9xvar.h. Noticed by he@.
 1.52 12-May-2009  cegger struct device * -> device_t, no functional changes intended.
 1.51 28-Apr-2008  martin branches: 1.51.14;
Remove clause 3 and 4 from TNF licenses
 1.50 13-Apr-2008  tsutsui branches: 1.50.2; 1.50.4;
Split device_t/softc for MI ncr53c9x and some related devices,
with various cleanup.
 1.49 04-Jan-2008  ad branches: 1.49.6;
Start detangling lock.h from intr.h. This is likely to cause short term
breakage, but the mess of dependencies has been regularly breaking the
build recently anyhow.
 1.48 04-Mar-2007  christos branches: 1.48.16; 1.48.22; 1.48.28;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.47 11-Dec-2005  christos branches: 1.47.26;
merge ktrace-lwp.
 1.46 04-Feb-2005  perry branches: 1.46.6;
de-__P
 1.45 07-Dec-2004  thorpej branches: 1.45.2; 1.45.4;
Use "struct scsipi_command" in internal command structures so that
we have enough space for 16-byte CDBs.
 1.44 10-Aug-2004  mycroft Constify.
 1.43 02-Nov-2003  wiz Fix some typos. From Tom Cosgrove via jmc@openbsd.
 1.42 24-Mar-2003  pk branches: 1.42.2;
#include <sys/lock.h>
 1.41 04-Feb-2003  pk Make this driver MP-safe by using a single spin lock to guard all its entrances.
 1.40 06-Jan-2003  matt Add multiple inclusion protection.
 1.39 22-Oct-2002  petrov Correct typo in comment(pointed by john heasley <heas@shrubbery.net>).
 1.38 25-Sep-2002  mycroft Additional fixes to make 16 targets work on FAS366.
 1.37 26-Aug-2002  petrov Accept WDTR from device(based on John Heasley patch for SCSI3 drive).
Do not define NCR53C9X_DEBUG.
 1.36 26-Aug-2002  petrov Dispose unused tinfo flags.
 1.35 03-Dec-2001  jdolecek branches: 1.35.8; 1.35.10;
add NCR_VARIANT_NCR53C90_86C01 "NCR53C90 (86C01)"
treat exactly like NCR_VARIANT_ESP100
 1.34 10-Nov-2001  perry trivially rename some macro parameters to avoid lint warnings.
 1.33 25-Apr-2001  bouyer branches: 1.33.2; 1.33.6;
Pull up the thorpej_scsipi branch to main branch.
This is a completely rewritten scsipi_xfer execution engine, and the
associated changes to HBA drivers. Overview of changes & features:
- All xfers are queued in the mid-layer, rather than doing so in an
ad-hoc fashion in individual adapter drivers.
- Adapter/channel resource management in the mid-layer, avoids even trying
to start running an xfer if the adapter/channel doesn't have the resources.
- Better communication between the mid-layer and the adapters.
- Asynchronous event notification mechanism from adapter to mid-layer and
peripherals.
- Better peripheral queue management: freeze/thaw, sorted requeueing during
recovery, etc.
- Clean separation of peripherals, adapters, and adapter channels (no more
scsipi_link).
- Kernel thread for each scsipi_channel makes error recovery much easier
(no more dealing with interrupt context when recovering from an error).
- Mid-layer support for tagged queueing: commands can have the tag type
set explicitly, tag IDs are allocated in the mid-layer (thus eliminating
the need to use buggy tag ID allocation schemes in many adapter drivers).
- support for QUEUE FULL and CHECK CONDITION status in mid-layer; the command
will be requeued, or a REQUEST SENSE will be sent as appropriate.

Just before the merge syssrc has been tagged with thorpej_scsipi_beforemerge
 1.32 21-Apr-2001  tsutsui Clean up ncr53c9x_select():
- Define NCR_F_SELATN3 for sc_features and use it to check if the chip
supports SELATN3 command
- Make conditions of sending messages a bit simpler.
 1.31 29-Mar-2001  petrov fas support added
 1.30 19-Jan-2001  eeh branches: 1.30.2;
Use the SCSIACCEL ioctl() to turn on TAG QUEUEs.
 1.29 20-Dec-2000  eeh Make the driver negotiate sync again and remove some (hopefully) superfluous
DELAY()s.
 1.28 17-Dec-2000  eeh Make sure bits in the flags are disjoint.
 1.27 30-Nov-2000  pk KNF patrol && De-__P().
 1.26 30-Nov-2000  eeh Add TAG QUEUE support to the ncr53c9x driver.
 1.25 13-Nov-2000  pk Define ncr53c9x_ioctl() and use it to start sync negotiation.
 1.24 05-Jun-2000  nisimura Have MI ncr53c9x_attach() the 2nd and 3rd arguments for scsipi_adater
and scsipi_device respectively, with size reduction of ncr53c9x_softc.
Specifying NULL instructs the driver to use default adapter and default
device codes. Every target port has ncr53c9x_attach(sc, NULL, NULL) anyway.
 1.23 29-Mar-2000  simonb branches: 1.23.2;
Remove duplicate ncr53c9x_dmaselect declaration.
 1.22 19-Mar-2000  mycroft For the ESP406/FAS408, add sc_cfg4 and sc_cfg5.
Add a detach routine, and do the addref/delref.
 1.21 18-Mar-2000  mycroft Expose ncr53c9x_init().
 1.20 18-Mar-2000  mycroft Adjust ncr53c9x_intr() prototype.
 1.19 07-Jan-2000  nisimura Remove tinfo_t symbols which result in never used global common variables.
 1.18 22-Sep-1999  mhitch branches: 1.18.2;
Define config register 3 values for NCR53C9x/FAS216.

Add sc_cfg3_fscsi to the softc and use it to set the chip into Fast SCSI
mode for the chips that use it.
 1.17 06-Jan-1999  thorpej branches: 1.17.2;
Changes to NCR53c9x driver necessary to add support for the AMD Am53c974
PCscsi-PCI SCSI controller. From Izumi Tsutsui, PR #6654.
 1.16 19-Nov-1998  thorpej Adapt to the new scsipi_adapter interface.
 1.15 01-Sep-1998  pk Adjust some comments.
 1.14 01-Sep-1998  jeremy Changed inaccurate comment on the sc_freq member of the driver's softc
structure. The frequency is represented in MHz rather than Hz. [PR/6805]
 1.13 26-May-1998  thorpej If we have an NCR53CF9x (indicated by the front-end by setting a flag
in the softc's new "features" word), set FSCSI bit in CFG3 if the sync
period is <= 200ns, or clear it otherwise.
 1.12 04-May-1998  pk Allocate SCSI message buffers in ncr53c9x_attach(), with a provision
for front-ends to override the allocation to avoid alignment
handling in their DMA engines. Note that that ncr53c9x_msgout()
can request a 1 byte DMA transfer that would be difficult to break up.
 1.11 05-Oct-1997  thorpej branches: 1.11.2;
Copyright assigned to The NetBSD Foundation.
 1.10 04-Oct-1997  mhitch Add yet another chip variant: FAS216, used by the amiga Phase5 SCSI boards.
 1.9 27-Aug-1997  bouyer Merge scsipi branch in the mainline. This add support for ATAPI devices
(currently only CD-ROM drives on i386). The sys/dev/scsipi system provides 2
busses to which devices can attach (scsibus and atapibus). This needed to
change some include files and structure names in the low level scsi drivers.
 1.8 30-Jul-1997  pk Maintain a copy of the configuration flags in our `softc'.
 1.7 20-Jul-1997  pk branches: 1.7.2;
Declare `ncr53c9x_dmaselect'.
 1.6 01-May-1997  pk branches: 1.6.2;
Preliminary support for ESP406 and FAS408 variants (from Eric Hvodza; PR#3559)
 1.5 27-Apr-1997  pk Implement target selection using DMA.
To allow a period of testing the variable `ncr53c9x_dmaselect' is used to
enable this feature (default is 0, i.e. the old behaviour).
 1.4 01-Apr-1997  gwr Allow separate control over the "per-target trace" feature
via the NCR53C9X_DEBUG value. Add some padding for m68k.
 1.3 15-Mar-1997  is New ARP system, supports IPv4 over any hardware link.

Some of the stuff (e.g., rarpd, bootpd, dhcpd etc., libsa) still will
only support Ethernet. Tcpdump itself should be ok, but libpcap needs
lot of work.

For the detailed change history, look at the commit log entries for
the is-newarp branch.
 1.2 27-Feb-1997  briggs branches: 1.2.2;
Add the 53c96 variant.
 1.1 27-Feb-1997  thorpej Machine-independent NCR 53c9x SCSI driver, derived from the SPARC/Alpha
versions. Thanks to Chris Demetrious and Paul Krannenburg for the
initial work towards merging the two.
 1.2.2.2 12-Mar-1997  is Merge in changes from Trunk
 1.2.2.1 27-Feb-1997  is file ncr53c9xvar.h was added on branch is-newarp on 1997-03-12 21:22:54 +0000
 1.6.2.5 27-Aug-1997  bouyer Get this compile on sparc.
 1.6.2.4 14-Aug-1997  bouyer Sync with trunk.
 1.6.2.3 30-Jul-1997  bouyer Sync with trunk.
 1.6.2.2 22-Jul-1997  bouyer Sync with trunk.
 1.6.2.1 01-Jul-1997  bouyer Updates for new scsipi subsystem. Actally known to work on i386 and sparc.
 1.7.2.3 14-Oct-1997  thorpej Update marc-pcmcia branch from trunk.
 1.7.2.2 27-Aug-1997  thorpej Update marc-pcmcia branch from trunk.
 1.7.2.1 23-Aug-1997  thorpej Update marc-pcmcia branch from trunk.
 1.11.2.1 18-Jan-1999  cgd pull up rev 1.12 from trunk (PR#5180). (pk)
 1.17.2.1 04-Dec-1999  he Pull up revision 1.18 (requested by mhitch):
Fix the problems in detecting the clock speed on the TCDS Dual
SCSI Option cards, and correctly configure the Fast SCSI interfaces.
This allows installation on the 3000/500 -> 3000/900 Alphas which
have the Fast SCSI interface on the on-board SCSI adapters.
 1.18.2.9 23-Apr-2001  bouyer Sync with HEAD.
 1.18.2.8 21-Apr-2001  bouyer Sync with HEAD
 1.18.2.7 11-Feb-2001  bouyer Sync with HEAD.
 1.18.2.6 05-Jan-2001  bouyer Sync with HEAD
 1.18.2.5 16-Dec-2000  bouyer Gives a single-bit flag for T_TAGOFF.
Report tagged-queuing support to upper layer, so that tagged queuing is
really used. Report QUEUE FULL events to upper layer. Bup per-target
openings to 256 as the driver supports it. Fix handling of T_SYNCOFF.
 1.18.2.4 08-Dec-2000  bouyer Sync with HEAD.
 1.18.2.3 22-Nov-2000  bouyer Sync with HEAD.
 1.18.2.2 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.18.2.1 19-Oct-1999  thorpej Adapt to scsipi API changes.
 1.23.2.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.30.2.8 07-Jan-2003  thorpej Sync with HEAD.
 1.30.2.7 11-Nov-2002  nathanw Catch up to -current
 1.30.2.6 18-Oct-2002  nathanw Catch up to -current.
 1.30.2.5 27-Aug-2002  nathanw Catch up to -current.
 1.30.2.4 08-Jan-2002  nathanw Catch up to -current.
 1.30.2.3 14-Nov-2001  nathanw Catch up to -current.
 1.30.2.2 21-Jun-2001  nathanw Catch up to -current.
 1.30.2.1 09-Apr-2001  nathanw Catch up with -current.
 1.33.6.1 12-Nov-2001  thorpej Sync the thorpej-mips-cache branch with -current.
 1.33.2.3 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.33.2.2 06-Sep-2002  jdolecek sync kqueue branch with HEAD
 1.33.2.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.35.10.1 22-Nov-2002  tron Pull up revision 1.36-1.39 (requested by martin in ticket #948):
Additional fixes to make 16 targets work on FAS366.
 1.35.8.1 29-Aug-2002  gehenna catch up with -current.
 1.42.2.6 04-Feb-2005  skrll Sync with HEAD.
 1.42.2.5 18-Dec-2004  skrll Sync with HEAD.
 1.42.2.4 21-Sep-2004  skrll Fix the sync with head I botched.
 1.42.2.3 18-Sep-2004  skrll Sync with HEAD.
 1.42.2.2 12-Aug-2004  skrll Sync with HEAD.
 1.42.2.1 03-Aug-2004  skrll Sync with HEAD
 1.45.4.1 12-Feb-2005  yamt sync with head.
 1.45.2.1 29-Apr-2005  kent sync with -current
 1.46.6.2 21-Jan-2008  yamt sync with head
 1.46.6.1 03-Sep-2007  yamt sync with head.
 1.47.26.1 12-Mar-2007  rmind Sync with HEAD.
 1.48.28.1 08-Jan-2008  bouyer Sync with HEAD
 1.48.22.1 18-Feb-2008  mjf Sync with HEAD.
 1.48.16.1 09-Jan-2008  matt sync with HEAD
 1.49.6.1 02-Jun-2008  mjf Sync with HEAD.
 1.50.4.3 16-Sep-2009  yamt sync with head
 1.50.4.2 16-May-2009  yamt sync with head
 1.50.4.1 16-May-2008  yamt sync with head.
 1.50.2.1 18-May-2008  yamt sync with head.
 1.51.14.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.55.16.1 18-May-2014  rmind sync with head
 1.55.12.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.55.2.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.57.10.1 02-Aug-2025  perseant Sync with HEAD
 1.1 20-Nov-2000  bouyer branches: 1.1.2;
file ncr53c9xvar.h.orig was initially added on branch thorpej_scsipi.
 1.1.2.2 20-Nov-2000  bouyer Ops, these shouldn't be there !
 1.1.2.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.1 20-Nov-2000  bouyer branches: 1.1.2;
file ncr53c9xvar.h.rej was initially added on branch thorpej_scsipi.
 1.1.2.2 20-Nov-2000  bouyer Remove files that should not have been added
 1.1.2.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.2 06-Dec-2019  nonaka Added NDIS ver.6.20 definition.
 1.1 15-Feb-2019  nonaka branches: 1.1.2; 1.1.6;
Added Microsoft Hyper-V support. It ported from OpenBSD and FreeBSD.

graphical console is not work on Gen.2 VM yet. To use the serial console,
enter "consdev com,0x3f8,115200" on efiboot.
 1.1.6.3 08-Apr-2020  martin Merge changes from current as of 20200406
 1.1.6.2 10-Jun-2019  christos Sync with HEAD
 1.1.6.1 15-Feb-2019  christos file ndisreg.h was added on branch phil-wifi on 2019-06-10 22:07:11 +0000
 1.1.2.2 09-Mar-2019  martin Pull up following revision(s) via patch (requested by nonaka in ticket #1210):

sys/dev/hyperv/vmbusvar.h: revision 1.1
sys/dev/hyperv/hvs.c: revision 1.1
sys/dev/hyperv/if_hvn.c: revision 1.1
sys/dev/hyperv/vmbusic.c: revision 1.1
sys/arch/x86/x86/lapic.c: revision 1.69
sys/arch/x86/isa/clock.c: revision 1.34
sys/arch/x86/include/intrdefs.h: revision 1.22
sys/arch/i386/conf/GENERIC: revision 1.1201
sys/arch/x86/x86/hyperv.c: revision 1.1
sys/arch/x86/include/cpu.h: revision 1.105
sys/arch/x86/x86/x86_machdep.c: revision 1.124
sys/arch/i386/conf/GENERIC: revision 1.1203
sys/arch/amd64/amd64/genassym.cf: revision 1.74
sys/arch/i386/conf/GENERIC: revision 1.1204
sys/arch/amd64/conf/GENERIC: revision 1.520
sys/arch/x86/x86/hypervreg.h: revision 1.1
sys/arch/amd64/amd64/vector.S: revision 1.69
sys/dev/hyperv/hvshutdown.c: revision 1.1
sys/dev/hyperv/hvshutdown.c: revision 1.2
sys/dev/usb/if_urndisreg.h: file removal
sys/arch/x86/x86/cpu.c: revision 1.167
sys/arch/x86/conf/files.x86: revision 1.107
sys/dev/usb/if_urndis.c: revision 1.20
sys/dev/hyperv/vmbusicreg.h: revision 1.1
sys/dev/hyperv/hvheartbeat.c: revision 1.1
sys/dev/hyperv/vmbusicreg.h: revision 1.2
sys/dev/hyperv/hvheartbeat.c: revision 1.2
sys/dev/hyperv/files.hyperv: revision 1.1
sys/dev/ic/rndisreg.h: revision 1.1
sys/arch/i386/i386/genassym.cf: revision 1.111
sys/dev/ic/rndisreg.h: revision 1.2
sys/dev/hyperv/hyperv_common.c: revision 1.1
sys/dev/hyperv/hvtimesync.c: revision 1.1
sys/dev/hyperv/hypervreg.h: revision 1.1
sys/dev/hyperv/hvtimesync.c: revision 1.2
sys/dev/hyperv/vmbusicvar.h: revision 1.1
sys/dev/hyperv/if_hvnreg.h: revision 1.1
sys/arch/x86/x86/lapic.c: revision 1.70
sys/arch/amd64/amd64/vector.S: revision 1.70
sys/dev/ic/ndisreg.h: revision 1.1
sys/arch/amd64/conf/GENERIC: revision 1.516
sys/dev/hyperv/hypervvar.h: revision 1.1
sys/arch/amd64/conf/GENERIC: revision 1.518
sys/arch/amd64/conf/GENERIC: revision 1.519
sys/arch/i386/conf/files.i386: revision 1.400
sys/dev/acpi/vmbus_acpi.c: revision 1.1
sys/dev/hyperv/vmbus.c: revision 1.1
sys/dev/hyperv/vmbus.c: revision 1.2
sys/arch/x86/x86/intr.c: revision 1.144
sys/arch/i386/i386/vector.S: revision 1.83
sys/arch/amd64/conf/files.amd64: revision 1.112

separate RNDIS definitions from urndis(4) for use with Hyper-V NetVSC.

-

Added Microsoft Hyper-V support. It ported from OpenBSD and FreeBSD.
graphical console is not work on Gen.2 VM yet. To use the serial console,
enter "consdev com,0x3f8,115200" on efiboot.

-

Add __diagused.

-

PR/53984: Partial revert of modify lapic_calibrate_timer() in lapic.c r1.69.

-

Update Hyper-V related drivers description.

-

Remove unused definition.

-

Rename the MODULE_*_HOOK() macros to MODULE_HOOK_*() as briefly
discussed on irc.
NFCI intended.

-

commented out hvkvp entry.

-

fix typo. pointed out by pgoyette@n.o.

-

Use IDTVEC instead of NENTRY for handle_hyperv_hypercall.

-

Rename the MODULE_*_HOOK() macros to MODULE_HOOK_*() as briefly
discussed on irc.
 1.1.2.1 15-Feb-2019  martin file ndisreg.h was added on branch netbsd-8 on 2019-03-09 17:10:20 +0000
 1.79 21-May-2024  andvar nix extra whitespace.
 1.78 21-May-2024  andvar s/amout/amount/ in comments.
 1.77 20-Aug-2021  andvar fix various typos in comments and log messages.
 1.76 27-Jan-2019  pgoyette Merge the [pgoyette-compat] branch
 1.75 15-Jul-2018  maxv Retire ipkdb entirely. The option was removed from the config files
yesterday.

ok kamil christos
 1.74 11-Aug-2013  rkujawa branches: 1.74.28; 1.74.30;
Add support for AX88796(B) variant.
 1.73 27-Oct-2012  chs branches: 1.73.2;
split device_t/softc for all remaining drivers.
replace "struct device *" with "device_t".
use device_xname(), device_unit(), etc.
 1.72 29-Mar-2010  tsutsui branches: 1.72.8; 1.72.18;
Don't warn about DMA timeout during probe.
 1.71 19-Mar-2010  tsutsui No need to override mem_ring value in ne2000_ipkdb_attach()
since a wrong calculation in dp8390_ipkdb_attach() was fixed.
 1.70 13-Mar-2010  tsutsui branches: 1.70.2;
- make local functions static
- const'ify
 1.69 13-Mar-2010  tsutsui Misc KNF.
 1.68 03-Mar-2010  tsutsui Put several fixes to ne(4) driver for better 8 bit mode support,
especially on RTL8019AS which is also used for non-ISA local bus of
embedded controllers and some m68k machines like atari and x68k.

* move RTL8019 probe and attach code from each bus attachment
to MI ne2000_detect() and ne2000_attach()
* change a method for backend and attachment to specify 8 bit mode
to use a new sc->sc_quirk member, instead of sc->sc_dmawidth
* handle more NE2000 8 bit mode specific settings, including
bus_space(9) access width and available size of buffer memory
* add a function to detect NE2000 8 bit mode
(disabled by default, but enalbed by options NE2000_DETECT_8BIT
to avoid possible regression on various ISA clones)
* fix ipkdb attachment accordingly (untested)

Tested on two NE2000 ISA variants (RTL8019AS and another clone named UL0001)
in both 8 bit and 16 bit mode on i386. "Looks good" from nonaka@.

See my post on tech-kern for details:
http://mail-index.NetBSD.org/tech-kern/2010/02/26/msg007423.html
 1.67 24-Feb-2010  dyoung A pointer typedef entails trading too much flexibility to declare const
and non-const types, and the kernel uses both const and non-const
PMF qualifiers and device suspensors, so change the pmf_qual_t and
device_suspensor_t typedefs from "pointers to const" to non-pointer,
non-const types.
 1.66 24-Feb-2010  tsutsui Use roundup2() in <sys/param.h> rather than a conditional.
 1.65 24-Feb-2010  tsutsui Now dp8390_config() calculates mem_ring correctly so
no longer need to override it in ne2000_attach().
 1.64 08-Jan-2010  dyoung branches: 1.64.2;
Expand PMF_FN_* macros.
 1.63 02-Jan-2010  christos nothing uses ne2000_power anymore.
 1.62 05-May-2009  nonaka Added NE2000 with 8bit bus width support.
reviewd by tsutsui@ at tech-kern ML.
 1.61 05-Apr-2009  uwe Provide pmf(9) hooks that do what dopowerhooks(9) hook does.

XXX: Do NOT call pmf_class_network_register() yet, b/c db8320.c
doesn't provide if_stop method!
 1.60 14-Mar-2009  dsl Change about 4500 of the K&R function definitions to ANSI ones.
There are still about 1600 left, but they have ',' or /* ... */
in the actual variable definitions - which my awk script doesn't handle.
There are also many that need () -> (void).
(The script does handle misordered arguments.)
 1.59 28-Apr-2008  martin branches: 1.59.8; 1.59.10; 1.59.14;
Remove clause 3 and 4 from TNF licenses
 1.58 08-Apr-2008  cegger branches: 1.58.2; 1.58.4;
use aprint_*_dev and device_xname
 1.57 12-Mar-2008  cube Split device_t and softc for the NE2000 Ethernet chip and all its variants
and attachments. Use device_t accessors, correct types, and ANSIfy when
appropriate.
 1.56 09-Mar-2008  dholland Use NE2000_TYPE_UNKNOWN instead of just 0 in a couple places.
 1.55 19-Oct-2007  ad branches: 1.55.12; 1.55.16;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.54 04-Mar-2007  christos branches: 1.54.2; 1.54.14; 1.54.16; 1.54.20;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.53 13-Jan-2007  cube branches: 1.53.2;
Make the IPKDB code compile.
 1.52 16-Nov-2006  christos __unused removal on arguments; approved by core.
 1.51 12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.50 11-Jul-2006  peter branches: 1.50.4; 1.50.6;
Add power hooks for "ne* at pcmcia?".

ok christos@
 1.49 21-May-2006  christos branches: 1.49.2;
void casts to functions whose return values are ignored.
 1.48 29-Jan-2006  dsl branches: 1.48.2; 1.48.4; 1.48.6; 1.48.10; 1.48.12;
Make almost everything #include <sys/bswap.h> instead of <machine/bswap.h>
The bswap.h and endian.h files are all rather incestuous, but I want to
get the constant folding stuff into one place - sys/bswap.h
 1.47 11-Dec-2005  christos branches: 1.47.2;
merge ktrace-lwp.
 1.46 26-Feb-2005  bsh branches: 1.46.4;
ASIX AX88796 is an NE2000 compatible ethernet chip, but doesn't seem to
have "remote DMA complete bit" is ISR. So, don't wait for ISR.RDC bit
after writing a packet.
 1.45 04-Feb-2005  perry de-__P
 1.44 09-Aug-2004  mycroft branches: 1.44.4; 1.44.6;
Do barriers on the ASIC space without touching the NIC space.
 1.43 04-Jul-2004  mycroft Fix a bug in the packet "padding" code. If we're padding a packet with an odd
size, we were writing out too much data, possibly causing the chip to lock up.
 1.42 17-Mar-2004  mycroft branches: 1.42.2;
A random patch that's been in my source tree...
Figure out whether the shared memory region is word-accessible in the same
place we figure out its size, and store this in the softc, rather than using a
series of comparisons later.
 1.41 02-Nov-2003  wiz Fix some typos. From Tom Cosgrove via jmc@openbsd.
 1.40 25-Oct-2003  christos Fix uninitialized variable warnings
 1.39 22-Oct-2003  christos support for NE2000_TYPE_AX88790 from
Yong-Jhen Hong yongjhen at alqualonde dot org
 1.38 15-Jan-2003  bouyer branches: 1.38.2;
Zero out the NIC memory when padding packet to ETHER_MIN_LEN-ETHER_CRC_LEN
sc->write_mbuf now return len of buffer, including padding.
Tested with a PCI ne2000.
 1.37 13-Nov-2001  lukem branches: 1.37.10;
add/cleanup RCSID
 1.36 04-Aug-2001  enami MII access routines for ASIX AX88190.
 1.35 07-Jul-2001  thorpej branches: 1.35.2;
bcopy -> memcpy
 1.34 07-Jul-2001  thorpej bcmp -> memcmp
 1.33 05-Jun-2001  thorpej Handle the DL10022 case.
 1.32 12-Feb-2001  thorpej branches: 1.32.2;
Adjust the way that media is initialized on DP8390-compatible
chips. The dp8390_softc now has media_init and media_fini
function pointers that do the work.
 1.31 11-Dec-2000  ws Fix the previous differently:
The intent was to protect the full range of ports on the board by the
barriers. But the start address was wrong. Fix it.

While here, change two other barriers to also protect the full range
(not only the nic ports), and add yet another similar barrier.
 1.30 03-Dec-2000  jlam Set range of memory protected by read/write bus space barriers to the
correct size, instead of extending past the mapped region.
 1.29 22-Mar-2000  ws Make IPKDB working again.
Add support for i386 debugging and pci-based ne2000 boards.
 1.28 22-Mar-2000  ws Add bus_space_barrier.
Add DELAY in some busy loops to allow the dma engine to actually do something
(neccessary on fast processors).
 1.27 09-Feb-2000  enami ASIX AX88190 support (Planex FNW-3700-T and Melco LPC3-TX) from FreeBSD/PAO3.
 1.26 09-Feb-2000  enami - Since all resources are mandatory, no need to manage individually.
- KNF some code.
- Factor out some code into function.
- Disestablish an interrupt handler when failed to enable card power.
 1.25 02-Feb-2000  itojun use a bit more standard (sys/device.h) prototype for {dp8390,ne2000}_detach().
 1.24 02-Feb-2000  itojun implement if_detach code for ne/pcmcia.
XXX still incomplete, ne_pcmcia_detach() commented out for safery - please test
 1.23 27-Sep-1999  enami branches: 1.23.2;
Support Planex Communications Inc, FNW-3600-T.
 1.22 27-Sep-1999  enami Change NE2000_USE_WORD to take pointer to softc rather than type.
 1.21 27-Sep-1999  enami Minor cleanup; use the cached result instead of evaluating the
macro NE2000_USE_WORD twice.
 1.20 27-Sep-1999  enami Define new macro NE2000_USE_WORD() and use it where appropriate.
 1.19 27-Sep-1999  enami Allow caller to specify the type of NE2000.
 1.18 23-Mar-1999  drochner Use BUS_SPACE_ALIGNED_POINTER() instead of ALIGNED_POINTER() where the pointer
in not just used to access memory but is bassed to bus_space_xxx_n()
methods. For debugging purposes, bus_space can have additional constraints
which will be properly met by BUS_SPACE_ALIGNED_POINTER().
 1.17 18-Jan-1999  mjacob If you're BIG_ENDIAN and use bswapXX, pull in the header file that prototypes
these functions.
 1.16 18-Jan-1999  pk Need <machine/bswap.h>
 1.15 18-Dec-1998  thorpej Quiet some diagnostic messages when we might expect them to happen.
PR #6460, Rafal Boni.
 1.14 28-Oct-1998  thorpej branches: 1.14.4;
Add media list, media list count, and default media arguments to
ne2000_attach().
 1.13 13-Oct-1998  msaitoh make it compile with GWETHER again.
 1.12 10-Jun-1998  thorpej Do the unaligned buffer fixup without copying data, more-or-less lifted
from the Shark CS8900 driver.
 1.11 04-Feb-1998  sakamoto Change "__BUS_SPACE_NEED_STREAM_METHODS" to "__BUS_SPACE_HAS_STREAM_METHODS".
 1.10 03-Feb-1998  sakamoto Change the data access busification functions to
the "stream" busification functions.
In the architecture as the BeBox(CPU is big endian, have ISA bus),
These methods would be used where "raw" data needs to {read,write,set}
unchanged.

Add #ifndef __BUS_SPACE_NEED_STREAM_METHODS (define that on NetBSD/bebox),
if not define __BUS_SPACE_NEED_STREAM_METHODS,
define "stream" busification functions to normal busification functions.
 1.9 29-Jan-1998  thorpej In the NE2000 case, if we encounter an unaligned mbuf, copy it to an
aligned buffer so that we can do 16-bit PIO to the device without causing
an unaligned access fault.
 1.8 26-Jan-1998  thorpej Update copyright.
 1.7 26-Jan-1998  thorpej If we're using these devices on a big-endian CPU, byte swap the "count"
field in the dp8390's packet header (because the dp8390 runs in little-endian
mode in these cases). Inspired by an e-mail from Kazuki Sakamoto.
 1.6 12-Jan-1998  thorpej Adjust for config changes.
 1.5 02-Nov-1997  thorpej Adjust for ifmedia-related changes to dp8390 driver.
 1.4 29-Oct-1997  thorpej When probing for a dp8390 in ne2000_detect(), check for RST being set
in the ISR (from the ISA "ed" driver's generic 8390 probe routine).
Also, add a big comment describing exactly what we're checking when
probing for the dp8390 (also lifted from the ISA "ed" driver).

The RST check should help weed-out non-matches before they get to the
fairly invasive memory check.
 1.3 15-Oct-1997  enami branches: 1.3.2;
Pull following change from marc-pcmcia branch:

> revision 1.1.2.4
> date: 1997/10/15 01:01:57; author: enami; state: Exp; lines: +10 -8
> Use bus_space_write_1() directly instead of NIC_PUT(), since
> - same io port is accessed by bus_space_read_1() in the same function, and
> - can bypass sc_reg_map[].
 1.2 14-Oct-1997  thorpej Pull down from marc-pcmcia branch: Common code used by NE2000 and compatible
ethernet cards.
 1.1 14-Oct-1997  thorpej branches: 1.1.2;
file ne2000.c was initially added on branch marc-pcmcia.
 1.1.2.4 15-Oct-1997  enami Use bus_space_write_1() directly instead of NIC_PUT(), since
- same io port is accessed by bus_space_read_1() in the same function, and
- can bypass sc_reg_map[].
 1.1.2.3 14-Oct-1997  enami Delete unnecessary indentation.
 1.1.2.2 14-Oct-1997  thorpej Garbage-collect some debugging code that I forgot to remove.
 1.1.2.1 14-Oct-1997  thorpej Split off NE2000 support from the ISA "ed" driver, and create a new "ne"
driver that deals with NE2000s and compatibles on ISA, PCI, and PCMCIA
busses.

This driver uses the generic DP8390 core chipset back-end.
 1.3.2.3 29-Jan-1998  mellon Pull up 1.7-1.9 (thorpej)
 1.3.2.2 05-Nov-1997  thorpej Pullup from trunk: update for dp8390 ifmedia changes.
 1.3.2.1 29-Oct-1997  thorpej Pull up from trunk: make the check for a dp8390 in ne2000_detect()
slightly more robust, and comment it.
 1.14.4.1 11-Dec-1998  kenh The beginnings of interface detach support. Still some bugs, but mostly
works for me.

This work was originally by Bill Studenmund, and cleaned up by me.
 1.23.2.4 12-Mar-2001  bouyer Sync with HEAD.
 1.23.2.3 13-Dec-2000  bouyer Sync with HEAD (for UBC fixes).
 1.23.2.2 08-Dec-2000  bouyer Sync with HEAD.
 1.23.2.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.32.2.4 17-Jan-2003  thorpej Sync with HEAD.
 1.32.2.3 14-Nov-2001  nathanw Catch up to -current.
 1.32.2.2 24-Aug-2001  nathanw Catch up with -current.
 1.32.2.1 21-Jun-2001  nathanw Catch up to -current.
 1.35.2.2 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.35.2.1 25-Aug-2001  thorpej Merge Aug 24 -current into the kqueue branch.
 1.37.10.1 27-Jan-2003  jmc Pullup revisions 1.37-1.38 (requested by bouyer in ticket #1096)
Zero out the NIC memory when padding packet to
ETHER_MIN_LEN-ETHER_CRC_LEN sc->write_mbuf now return len of
buffer, including padding.
 1.38.2.6 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.38.2.5 04-Feb-2005  skrll Sync with HEAD.
 1.38.2.4 21-Sep-2004  skrll Fix the sync with head I botched.
 1.38.2.3 18-Sep-2004  skrll Sync with HEAD.
 1.38.2.2 12-Aug-2004  skrll Sync with HEAD.
 1.38.2.1 03-Aug-2004  skrll Sync with HEAD
 1.42.2.1 05-Jul-2004  he Pull up revision 1.43 (requested by mycroft in ticket #602):
Fix a bug in the packet ``padding'' code. If we are padding
a packet with an odd length, we are writing out too much
data, possibly causing the chip to lock up.
 1.44.6.2 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.44.6.1 12-Feb-2005  yamt sync with head.
 1.44.4.1 29-Apr-2005  kent sync with -current
 1.46.4.6 17-Mar-2008  yamt sync with head.
 1.46.4.5 27-Oct-2007  yamt sync with head.
 1.46.4.4 03-Sep-2007  yamt sync with head.
 1.46.4.3 26-Feb-2007  yamt sync with head.
 1.46.4.2 30-Dec-2006  yamt sync with head.
 1.46.4.1 21-Jun-2006  yamt sync with head.
 1.47.2.1 01-Feb-2006  yamt sync with head.
 1.48.12.1 19-Jun-2006  chap Sync with head.
 1.48.10.1 24-May-2006  tron Merge 2006-05-24 NetBSD-current into the "peter-altq" branch.
 1.48.6.2 11-Aug-2006  yamt sync with head
 1.48.6.1 24-May-2006  yamt sync with head.
 1.48.4.1 01-Jun-2006  kardel Sync with head.
 1.48.2.1 09-Sep-2006  rpaulo sync with head
 1.49.2.1 13-Jul-2006  gdamore Merge from HEAD.
 1.50.6.2 10-Dec-2006  yamt sync with head.
 1.50.6.1 22-Oct-2006  yamt sync with head
 1.50.4.2 01-Feb-2007  ad Sync with head.
 1.50.4.1 18-Nov-2006  ad Sync with head.
 1.53.2.1 12-Mar-2007  rmind Sync with HEAD.
 1.54.20.1 25-Oct-2007  bouyer Sync with HEAD.
 1.54.16.2 23-Mar-2008  matt sync with HEAD
 1.54.16.1 06-Nov-2007  matt sync with HEAD
 1.54.14.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.54.2.1 23-Oct-2007  ad Sync with head.
 1.55.16.2 02-Jun-2008  mjf Sync with HEAD.
 1.55.16.1 03-Apr-2008  mjf Sync with HEAD.
 1.55.12.1 24-Mar-2008  keiichi sync with head.
 1.58.4.5 11-Aug-2010  yamt sync with head.
 1.58.4.4 11-Mar-2010  yamt sync with head
 1.58.4.3 16-May-2009  yamt sync with head
 1.58.4.2 04-May-2009  yamt sync with head.
 1.58.4.1 16-May-2008  yamt sync with head.
 1.58.2.1 18-May-2008  yamt sync with head.
 1.59.14.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.59.10.1 20-Nov-2010  riz Pull up following revision(s) (requested by tsutsui in ticket #1367):
sys/dev/ic/ne2000var.h: revision 1.25
sys/arch/atari/conf/MILAN.in: revision 1.24
sys/arch/atari/conf/MILAN.in: revision 1.25
sys/dev/ic/ne2000.c: revision 1.71
sys/dev/ic/ne2000.c: revision 1.72
sys/arch/atari/dev/if_ne_mb.c: revision 1.1
sys/arch/atari/dev/if_ne_mb.c: revision 1.2
sys/arch/atari/conf/MILAN-PCIIDE: revision 1.69
sys/arch/atari/conf/HADES.in: revision 1.10
sys/arch/atari/conf/HADES.in: revision 1.11
sys/arch/x68k/dev/if_ne_neptune.c: revision 1.20
sys/dev/isa/if_ne_isa.c: revision 1.27
sys/arch/atari/atari/autoconf.c: revision 1.57
sys/dev/ic/ne2000.c: revision 1.62
sys/dev/isapnp/if_ne_isapnp.c: revision 1.27
sys/arch/atari/conf/files.atari: revision 1.117
sys/arch/atari/conf/HADES: revision 1.88
sys/arch/atari/conf/GENERIC.in: revision 1.85
sys/dev/ic/ne2000.c: revision 1.65
sys/dev/ic/ne2000.c: revision 1.66
sys/dev/ic/ne2000.c: revision 1.68
sys/arch/atari/conf/MILAN-ISAIDE: revision 1.65
distrib/notes/atari/hardware: revision 1.24
sys/conf/files: revision 1.980
sys/dev/ic/ne2000var.h: revision 1.21
sys/arch/x68k/dev/if_ne_intio.c: revision 1.16
sys/dev/ic/dp8390.c: revision 1.74
sys/dev/ic/dp8390.c: revision 1.75
Added NE2000 with 8bit bus width support.
reviewd by tsutsui@ at tech-kern ML.
Fix a wrong calculation bug around RX ring buffer memory address
slipped in about sixteen years ago. Fortunately, it had been working
for ages because some devices used address zero and other devices
ignored wrong higher bits.
Tested on we(4) (SMC Elite Ultra) and ne(4) (NE2000 compatible
named UL0001) on ISA.
Note FreeBSD also uses the same correct value in their ed(4) driver.
Now dp8390_config() calculates mem_ring correctly so
no longer need to override it in ne2000_attach().
Use roundup2() in <sys/param.h> rather than a conditional.
Also fix a wrong mem_ring calculation in dp8390_ipkdb_attach().
Put several fixes to ne(4) driver for better 8 bit mode support,
especially on RTL8019AS which is also used for non-ISA local bus of
embedded controllers and some m68k machines like atari and x68k.
* move RTL8019 probe and attach code from each bus attachment
to MI ne2000_detect() and ne2000_attach()
* change a method for backend and attachment to specify 8 bit mode
to use a new sc->sc_quirk member, instead of sc->sc_dmawidth
* handle more NE2000 8 bit mode specific settings, including
bus_space(9) access width and available size of buffer memory
* add a function to detect NE2000 8 bit mode
(disabled by default, but enalbed by options NE2000_DETECT_8BIT
to avoid possible regression on various ISA clones)
* fix ipkdb attachment accordingly (untested)
Tested on two NE2000 ISA variants (RTL8019AS and another clone named UL0001)
in both 8 bit and 16 bit mode on i386. "Looks good" from nonaka@.
See my post on tech-kern for details:
http://mail-index.NetBSD.org/tech-kern/2010/02/26/msg007423.html
No need to override mem_ring value in ne2000_ipkdb_attach()
since a wrong calculation in dp8390_ipkdb_attach() was fixed.
Don't warn about DMA timeout during probe.
Add support for the EtherNEC.
The EtherNEC is yet another user designed device for Atari machines,
an NE2000 based ISA board connected to Atari's ROM cartridge slot with
simple but ingenious interface and cartridge port adapter, and
it's the most available network solution for the old Atari machines.
See following pages for more details about EtherNEC:
http://hardware.atari.org/ether/
http://home.arcor.de/thomas.redelberger/prj/atari/etherne/
http://www.freemint.org/ethernec/ethernec.html
Also note EtherNEC.
Use callout_schedule(9) rather than callout_reset(9) on polling
as callout(9) man says.
Remove EtherNEC from HADES and MILAN.
They have ISA so no one will bother to connect ISA NE2000 via EtherNEC.
Regen from HADES.in rev 1.11 and MILAN.in rev 1.25:
Remove EtherNEC from HADES and MILAN.
They have ISA so no one will bother to connect ISA NE2000 via EtherNEC.
 1.59.8.1 28-Apr-2009  skrll Sync with HEAD.
 1.64.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.70.2.1 30-May-2010  rmind sync with head
 1.72.18.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.72.18.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.72.8.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.72.8.1 30-Oct-2012  yamt sync with head
 1.73.2.1 28-Aug-2013  rmind sync with head
 1.74.30.1 10-Jun-2019  christos Sync with HEAD
 1.74.28.1 28-Jul-2018  pgoyette Sync with HEAD
 1.4 04-Aug-2001  enami MII access routines for ASIX AX88190.
 1.3 09-Feb-2000  enami branches: 1.3.6; 1.3.8;
ASIX AX88190 support (Planex FNW-3700-T and Melco LPC3-TX) from FreeBSD/PAO3.
 1.2 14-Oct-1997  thorpej branches: 1.2.16;
Pull down from marc-pcmcia branch: Common code used by NE2000 and compatible
ethernet cards.
 1.1 14-Oct-1997  thorpej branches: 1.1.2;
file ne2000reg.h was initially added on branch marc-pcmcia.
 1.1.2.1 14-Oct-1997  thorpej Split off NE2000 support from the ISA "ed" driver, and create a new "ne"
driver that deals with NE2000s and compatibles on ISA, PCI, and PCMCIA
busses.

This driver uses the generic DP8390 core chipset back-end.
 1.2.16.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.3.8.1 25-Aug-2001  thorpej Merge Aug 24 -current into the kqueue branch.
 1.3.6.1 24-Aug-2001  nathanw Catch up with -current.
 1.28 15-Jul-2018  maxv Retire ipkdb entirely. The option was removed from the config files
yesterday.

ok kamil christos
 1.27 11-Aug-2013  rkujawa branches: 1.27.28; 1.27.30;
Add support for AX88796(B) variant.
 1.26 13-Mar-2010  tsutsui branches: 1.26.10; 1.26.20; 1.26.24;
u_int8_t -> uint8_t
 1.25 03-Mar-2010  tsutsui Put several fixes to ne(4) driver for better 8 bit mode support,
especially on RTL8019AS which is also used for non-ISA local bus of
embedded controllers and some m68k machines like atari and x68k.

* move RTL8019 probe and attach code from each bus attachment
to MI ne2000_detect() and ne2000_attach()
* change a method for backend and attachment to specify 8 bit mode
to use a new sc->sc_quirk member, instead of sc->sc_dmawidth
* handle more NE2000 8 bit mode specific settings, including
bus_space(9) access width and available size of buffer memory
* add a function to detect NE2000 8 bit mode
(disabled by default, but enalbed by options NE2000_DETECT_8BIT
to avoid possible regression on various ISA clones)
* fix ipkdb attachment accordingly (untested)

Tested on two NE2000 ISA variants (RTL8019AS and another clone named UL0001)
in both 8 bit and 16 bit mode on i386. "Looks good" from nonaka@.

See my post on tech-kern for details:
http://mail-index.NetBSD.org/tech-kern/2010/02/26/msg007423.html
 1.24 24-Feb-2010  dyoung A pointer typedef entails trading too much flexibility to declare const
and non-const types, and the kernel uses both const and non-const
PMF qualifiers and device suspensors, so change the pmf_qual_t and
device_suspensor_t typedefs from "pointers to const" to non-pointer,
non-const types.
 1.23 08-Jan-2010  dyoung branches: 1.23.2;
Expand PMF_FN_* macros.
 1.22 02-Jan-2010  christos nothing uses ne2000_power anymore.
 1.21 05-May-2009  nonaka Added NE2000 with 8bit bus width support.
reviewd by tsutsui@ at tech-kern ML.
 1.20 05-Apr-2009  uwe Provide pmf(9) hooks that do what dopowerhooks(9) hook does.

XXX: Do NOT call pmf_class_network_register() yet, b/c db8320.c
doesn't provide if_stop method!
 1.19 28-Apr-2008  martin branches: 1.19.8; 1.19.10; 1.19.14;
Remove clause 3 and 4 from TNF licenses
 1.18 11-Jul-2006  peter branches: 1.18.54; 1.18.56; 1.18.58;
Add power hooks for "ne* at pcmcia?".

ok christos@
 1.17 11-Dec-2005  christos branches: 1.17.4; 1.17.8; 1.17.16;
merge ktrace-lwp.
 1.16 04-Feb-2005  perry branches: 1.16.6;
de-__P
 1.15 17-Mar-2004  mycroft branches: 1.15.8; 1.15.10;
A random patch that's been in my source tree...
Figure out whether the shared memory region is word-accessible in the same
place we figure out its size, and store this in the softc, rather than using a
series of comparisons later.
 1.14 22-Oct-2003  christos support for NE2000_TYPE_AX88790 from
Yong-Jhen Hong yongjhen at alqualonde dot org
 1.13 12-Feb-2001  thorpej branches: 1.13.24;
Adjust the way that media is initialized on DP8390-compatible
chips. The dp8390_softc now has media_init and media_fini
function pointers that do the work.
 1.12 10-Feb-2001  thorpej Add a type for the DL10022.
 1.11 22-Mar-2000  ws Make IPKDB working again.
Add support for i386 debugging and pci-based ne2000 boards.
 1.10 09-Feb-2000  enami ASIX AX88190 support (Planex FNW-3700-T and Melco LPC3-TX) from FreeBSD/PAO3.
 1.9 09-Feb-2000  enami - Since all resources are mandatory, no need to manage individually.
- KNF some code.
- Factor out some code into function.
- Disestablish an interrupt handler when failed to enable card power.
 1.8 02-Feb-2000  itojun use a bit more standard (sys/device.h) prototype for {dp8390,ne2000}_detach().
 1.7 02-Feb-2000  itojun implement if_detach code for ne/pcmcia.
XXX still incomplete, ne_pcmcia_detach() commented out for safery - please test
 1.6 27-Sep-1999  enami branches: 1.6.2;
Support Planex Communications Inc, FNW-3600-T.
 1.5 27-Sep-1999  enami Change NE2000_USE_WORD to take pointer to softc rather than type.
 1.4 27-Sep-1999  enami Define new macro NE2000_USE_WORD() and use it where appropriate.
 1.3 28-Oct-1998  thorpej Add media list, media list count, and default media arguments to
ne2000_attach().
 1.2 14-Oct-1997  thorpej Pull down from marc-pcmcia branch: Common code used by NE2000 and compatible
ethernet cards.
 1.1 14-Oct-1997  thorpej branches: 1.1.2;
file ne2000var.h was initially added on branch marc-pcmcia.
 1.1.2.1 14-Oct-1997  thorpej Split off NE2000 support from the ISA "ed" driver, and create a new "ne"
driver that deals with NE2000s and compatibles on ISA, PCI, and PCMCIA
busses.

This driver uses the generic DP8390 core chipset back-end.
 1.6.2.3 12-Mar-2001  bouyer Sync with HEAD.
 1.6.2.2 11-Feb-2001  bouyer Sync with HEAD.
 1.6.2.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.13.24.4 04-Feb-2005  skrll Sync with HEAD.
 1.13.24.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.13.24.2 18-Sep-2004  skrll Sync with HEAD.
 1.13.24.1 03-Aug-2004  skrll Sync with HEAD
 1.15.10.1 12-Feb-2005  yamt sync with head.
 1.15.8.1 29-Apr-2005  kent sync with -current
 1.16.6.1 30-Dec-2006  yamt sync with head.
 1.17.16.1 13-Jul-2006  gdamore Merge from HEAD.
 1.17.8.1 11-Aug-2006  yamt sync with head
 1.17.4.1 09-Sep-2006  rpaulo sync with head
 1.18.58.5 11-Aug-2010  yamt sync with head.
 1.18.58.4 11-Mar-2010  yamt sync with head
 1.18.58.3 16-May-2009  yamt sync with head
 1.18.58.2 04-May-2009  yamt sync with head.
 1.18.58.1 16-May-2008  yamt sync with head.
 1.18.56.1 18-May-2008  yamt sync with head.
 1.18.54.1 02-Jun-2008  mjf Sync with HEAD.
 1.19.14.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.19.10.1 20-Nov-2010  riz Pull up following revision(s) (requested by tsutsui in ticket #1367):
sys/dev/ic/ne2000var.h: revision 1.25
sys/arch/atari/conf/MILAN.in: revision 1.24
sys/arch/atari/conf/MILAN.in: revision 1.25
sys/dev/ic/ne2000.c: revision 1.71
sys/dev/ic/ne2000.c: revision 1.72
sys/arch/atari/dev/if_ne_mb.c: revision 1.1
sys/arch/atari/dev/if_ne_mb.c: revision 1.2
sys/arch/atari/conf/MILAN-PCIIDE: revision 1.69
sys/arch/atari/conf/HADES.in: revision 1.10
sys/arch/atari/conf/HADES.in: revision 1.11
sys/arch/x68k/dev/if_ne_neptune.c: revision 1.20
sys/dev/isa/if_ne_isa.c: revision 1.27
sys/arch/atari/atari/autoconf.c: revision 1.57
sys/dev/ic/ne2000.c: revision 1.62
sys/dev/isapnp/if_ne_isapnp.c: revision 1.27
sys/arch/atari/conf/files.atari: revision 1.117
sys/arch/atari/conf/HADES: revision 1.88
sys/arch/atari/conf/GENERIC.in: revision 1.85
sys/dev/ic/ne2000.c: revision 1.65
sys/dev/ic/ne2000.c: revision 1.66
sys/dev/ic/ne2000.c: revision 1.68
sys/arch/atari/conf/MILAN-ISAIDE: revision 1.65
distrib/notes/atari/hardware: revision 1.24
sys/conf/files: revision 1.980
sys/dev/ic/ne2000var.h: revision 1.21
sys/arch/x68k/dev/if_ne_intio.c: revision 1.16
sys/dev/ic/dp8390.c: revision 1.74
sys/dev/ic/dp8390.c: revision 1.75
Added NE2000 with 8bit bus width support.
reviewd by tsutsui@ at tech-kern ML.
Fix a wrong calculation bug around RX ring buffer memory address
slipped in about sixteen years ago. Fortunately, it had been working
for ages because some devices used address zero and other devices
ignored wrong higher bits.
Tested on we(4) (SMC Elite Ultra) and ne(4) (NE2000 compatible
named UL0001) on ISA.
Note FreeBSD also uses the same correct value in their ed(4) driver.
Now dp8390_config() calculates mem_ring correctly so
no longer need to override it in ne2000_attach().
Use roundup2() in <sys/param.h> rather than a conditional.
Also fix a wrong mem_ring calculation in dp8390_ipkdb_attach().
Put several fixes to ne(4) driver for better 8 bit mode support,
especially on RTL8019AS which is also used for non-ISA local bus of
embedded controllers and some m68k machines like atari and x68k.
* move RTL8019 probe and attach code from each bus attachment
to MI ne2000_detect() and ne2000_attach()
* change a method for backend and attachment to specify 8 bit mode
to use a new sc->sc_quirk member, instead of sc->sc_dmawidth
* handle more NE2000 8 bit mode specific settings, including
bus_space(9) access width and available size of buffer memory
* add a function to detect NE2000 8 bit mode
(disabled by default, but enalbed by options NE2000_DETECT_8BIT
to avoid possible regression on various ISA clones)
* fix ipkdb attachment accordingly (untested)
Tested on two NE2000 ISA variants (RTL8019AS and another clone named UL0001)
in both 8 bit and 16 bit mode on i386. "Looks good" from nonaka@.
See my post on tech-kern for details:
http://mail-index.NetBSD.org/tech-kern/2010/02/26/msg007423.html
No need to override mem_ring value in ne2000_ipkdb_attach()
since a wrong calculation in dp8390_ipkdb_attach() was fixed.
Don't warn about DMA timeout during probe.
Add support for the EtherNEC.
The EtherNEC is yet another user designed device for Atari machines,
an NE2000 based ISA board connected to Atari's ROM cartridge slot with
simple but ingenious interface and cartridge port adapter, and
it's the most available network solution for the old Atari machines.
See following pages for more details about EtherNEC:
http://hardware.atari.org/ether/
http://home.arcor.de/thomas.redelberger/prj/atari/etherne/
http://www.freemint.org/ethernec/ethernec.html
Also note EtherNEC.
Use callout_schedule(9) rather than callout_reset(9) on polling
as callout(9) man says.
Remove EtherNEC from HADES and MILAN.
They have ISA so no one will bother to connect ISA NE2000 via EtherNEC.
Regen from HADES.in rev 1.11 and MILAN.in rev 1.25:
Remove EtherNEC from HADES and MILAN.
They have ISA so no one will bother to connect ISA NE2000 via EtherNEC.
 1.19.8.1 28-Apr-2009  skrll Sync with HEAD.
 1.23.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.26.24.1 28-Aug-2013  rmind sync with head
 1.26.20.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.26.10.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.27.30.1 10-Jun-2019  christos Sync with HEAD
 1.27.28.1 28-Jul-2018  pgoyette Sync with HEAD
 1.1 01-Oct-2006  bjh21 branches: 1.1.2; 1.1.4; 1.1.8;
New driver, sec(4), for the Acorn SCSI Expansion Card. Unlike asc(4), this
driver uses the board's DMA system, uses the machine-independent WD33C93
driver, works on NetBSD/acorn26, and doesn't share a name with six other
machine-dependent SCSI drivers. Not tested on acorn32, but it seems to
work tolerably well on my A540.
 1.1.8.2 30-Dec-2006  yamt sync with head.
 1.1.8.1 01-Oct-2006  yamt file nec71071reg.h was added on branch yamt-lazymbuf on 2006-12-30 20:48:03 +0000
 1.1.4.2 18-Nov-2006  ad Sync with head.
 1.1.4.1 01-Oct-2006  ad file nec71071reg.h was added on branch newlock2 on 2006-11-18 21:34:13 +0000
 1.1.2.2 22-Oct-2006  yamt sync with head
 1.1.2.1 01-Oct-2006  yamt file nec71071reg.h was added on branch yamt-splraiseipl on 2006-10-22 06:05:45 +0000
 1.5 20-May-2022  andvar s/auxillary/auxiliary/ in comments.
 1.4 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.3 11-Dec-2005  christos branches: 1.3.70; 1.3.72; 1.3.74;
merge ktrace-lwp.
 1.2 27-Feb-2005  perry nuke trailing whitespace
 1.1 02-Jun-2003  gmcgarry branches: 1.1.2; 1.1.10; 1.1.12;
Register definitions for NEC uPD7210 GPIB controller.
 1.1.12.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.1.10.1 29-Apr-2005  kent sync with -current
 1.1.2.1 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.3.74.1 16-May-2008  yamt sync with head.
 1.3.72.1 18-May-2008  yamt sync with head.
 1.3.70.1 02-Jun-2008  mjf Sync with HEAD.
 1.4 28-Jun-1995  cgd move to more appropriate (...reg.h) names.
 1.3 27-Oct-1994  cgd new RCS ID format.
 1.2 22-May-1993  cgd branches: 1.2.4;
add rcsids to everything and clean up headers
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.2.4.2 27-Oct-1993  mycroft Revert value of SENSED. IBM data sheet was wrong.
 1.2.4.1 16-Oct-1993  mycroft Correct NE7CMD_SENSED, and rearrange a little.
 1.7 11-Dec-2005  christos merge ktrace-lwp.
 1.6 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22364, verified by myself.
 1.5 03-May-2003  wiz branches: 1.5.2;
DMA, not dma nor Dma.
 1.4 20-Oct-1995  pk Correct NE7CMD_FORMAT command (from John Kohl; PR#1637).
 1.3 27-Oct-1994  cgd new RCS ID format.
 1.2 22-May-1993  cgd branches: 1.2.4;
add rcsids to everything and clean up headers
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.2.4.2 27-Oct-1993  mycroft Revert value of SENSED. IBM data sheet was wrong.
 1.2.4.1 16-Oct-1993  mycroft Correct NE7CMD_SENSED, and rearrange a little.
 1.5.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.5.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.5.2.1 03-Aug-2004  skrll Sync with HEAD
 1.20 20-Oct-2017  jdolecek move ata_queue_alloc(1) and ata_queue_free() calls to ata_channel_init()
and ata_channel_destroy() respectively, to make attachment code simpler,
and to make it easier to spot special queue manipulation like cmdide(4)

on topic of PR kern/52606
 1.19 07-Oct-2017  jdolecek Merge support for SATA NCQ (Native Command Queueing) from jdolecek-ncq branch

ATA subsystem was changed to support several outstanding commands, and use
NCQ xfers if supported by both the controller and the disk, including NCQ
error recovery. Set NCQ high priority for BPRIO_TIMECRITICAL xfers
if supported. Added FUA support.

Done some work towards MP-safe, all ATA code tsleep()/wakeup() replaced
by condvars, and switched most code from spl* to mutexes (separate
wd(4) and ata channel lock).

Introduced new option WD_CHAOS_MONKEY to facilitate testing of error
handling, fixed several uncovered issues. Also fixed several problems
with kernel dump to wd(4) disk.

Tested with ahcisata(4), mvsata(4), siisata(4), piixide(4) on amd64,
with and without port multiplier, both disk and ATAPI devices; other
drivers and archs mechanically adjusted and compile-tested. NCQ is
supported for ahcisata(4) and siisata(4) for any controller, for
mvsata(4) only Gen IIe ones for now. Also enabled ATAPI support in
mvsata(4).

Thanks to Matt Thomas for initial ATA infrastructure patch, and
Jonathan A.Kollasch for siisata(4) NCQ changes and general testing.

Also fixes PR kern/43169 (wd(4)); and PR kern/11811, PR kern/47041,
PR kern/51979 (kernel dump)
 1.18 31-Jul-2012  bouyer branches: 1.18.2; 1.18.28;
Apply back changes that were reverted on Jul 24 and Jul 26 (general ata/wdc
cleanup and SATA PMP support), now that I'm back to fix the fallouts.
 1.17 26-Jul-2012  jakllsch Revert, with intention of restoring in a less invasive way, the SATA Port
Multiplier code.

ok christos@
 1.16 24-Jul-2012  jakllsch Revert dsl@'s changes of Sun, 15 Jul 2012 10:55:35 +0000 and
Sun, 15 Jul 2012 10:56:50 +0000, excepting the kernel version bump.
First step in reverting regressions to ata(4) subsystem during the addition of
port multiplier support.
 1.15 15-Jul-2012  dsl Some namespace protection (and add greppablity).
Prefix the DRIVE_ and DRIVET_ constants from atavar.h with ATA_.
Don't use an enum for drive_type - you don't know how big it will be.
Move driver_type to avoid implicit structure padding (esp on arm).
This change is purely lexical and mechanical.

Update to 6.99.9 - this wasn't done when the SATA PMP changes
were made - I'm sure they warranted a bump.
 1.14 02-Jul-2012  bouyer Add sata Port MultiPlier (PMP) support to the ata bus layer,
as described in
http://mail-index.netbsd.org/tech-kern/2012/06/23/msg013442.html
PMP support in integrated to the atabus layer.
struct ata_channel's ch_drive[] is not dynamically allocated, and ch_ndrive
(renamed to ch_ndrives) closely reflects the size of the ch_drive[] array.
Add helper functions atabus_alloc_drives() and atabus_free_drives()
to manage ch_drive[]/ch_ndrives.
Add wdc_maxdrives to struct wdc_softc so that bus front-end can specify
how much drive they really support (master/slave or single).
ata_reset_drive() callback gains a uint32_t *sigp argument which,
when not NULL, will contain the signature of the device being reset.
While there, some cosmetic changes:
- added a drive_type enum to ata_drive_datas, and stop encoding the
probed drive type in drive_flags (we were out of drive flags anyway).
- rename DRIVE_ATAPIST to DRIVE_ATAPIDSCW to better reflect what this
really is
- remove ata_channel->ata_drives, it's redundant with the pointer in
ata_drive_datas
- factor out the interpretation of SATA signatures in sata_interpet_sig()

propagate these changes to the ATA HBA drivers, and add support for PMP
to ahcisata(4) and siisata(4).

Thanks to:
- Protocase (http://www.protocase.com/) which provided a system
with lots of controllers, SATA PMP and drive slots
- Conservation Genomics Laboratory, Department of Biology, New Mexico State
University for hosting the above system
- Brook Milligan, who set up remote access and has been very responsive
when SATA cable move was needed
 1.13 21-Feb-2011  itohy branches: 1.13.4;
Cleanup my copyright notice.
 1.12 13-Nov-2010  uebayasi branches: 1.12.2; 1.12.4;
Don't pull in the whole uvm(9) API to access only PAGE_SIZE and
some other constants. These are provided by sys/param.h now.
 1.11 14-Mar-2009  dsl branches: 1.11.4;
Change about 4500 of the K&R function definitions to ANSI ones.
There are still about 1600 left, but they have ',' or /* ... */
in the actual variable definitions - which my awk script doesn't handle.
There are also many that need () -> (void).
(The script does handle misordered arguments.)
 1.10 18-Mar-2008  cube branches: 1.10.4; 1.10.12; 1.10.18;
Split device_t and softc for ATA devices, as well as wd(4). Other
cosmetic changes where appropriate.
 1.9 19-Oct-2007  ad branches: 1.9.12; 1.9.16;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.8 09-Jul-2007  ad branches: 1.8.6; 1.8.8; 1.8.12;
Merge some of the less invasive changes from the vmlocking branch:

- kthread, callout, devsw API changes
- select()/poll() improvements
- miscellaneous MT safety improvements
 1.7 04-Mar-2007  christos branches: 1.7.2; 1.7.4;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.6 19-Dec-2006  itohy branches: 1.6.2; 1.6.4;
Fix bus_dmamap_sync() usage.
This should not be a problem since BUS_DMASYNC_POSTWRITE is probably a no-op.
 1.5 16-Nov-2006  christos branches: 1.5.2;
__unused removal on arguments; approved by core.
 1.4 12-Oct-2006  dogcow more __unused; also, ew, K&R decls.
 1.3 01-Oct-2006  itohy Change Id to NetBSD
 1.2 01-Oct-2006  itohy Use ATA timing, instead of busmaster wait, for adding waits.
Use default wait value 0x01.
 1.1 07-Sep-2006  itohy branches: 1.1.2; 1.1.4; 1.1.6; 1.1.8;
Workbit NinjaATA-32 busmastering PIO IDE controller driver (njata)

This driver supports NinjaATA-32Bi and NPATA-32 chips,
which are used for CardBus ATA interface cards and
CardBus CompactFlash adapters.
 1.1.8.3 21-Dec-2006  yamt sync with head.
 1.1.8.2 10-Dec-2006  yamt sync with head.
 1.1.8.1 22-Oct-2006  yamt sync with head
 1.1.6.2 14-Sep-2006  yamt sync with head.
 1.1.6.1 07-Sep-2006  yamt file ninjaata32.c was added on branch yamt-pdpolicy on 2006-09-14 12:31:30 +0000
 1.1.4.2 09-Sep-2006  rpaulo sync with head
 1.1.4.1 07-Sep-2006  rpaulo file ninjaata32.c was added on branch rpaulo-netinet-merge-pcb on 2006-09-09 02:50:02 +0000
 1.1.2.2 12-Jan-2007  ad Sync with head.
 1.1.2.1 18-Nov-2006  ad Sync with head.
 1.5.2.1 08-Mar-2007  bouyer Pull up following revision(s) (requested by itohy in ticket #493):
sys/dev/ic/ninjaata32.c: revision 1.6
sys/dev/ic/ninjaata32reg.h: revision 1.3
share/man/man4/njata.4: revision 1.5
Fix bus_dmamap_sync() usage.
Fix a typo in comment.
Fix release in man page.
 1.6.4.1 12-Mar-2007  rmind Sync with HEAD.
 1.6.2.5 24-Mar-2008  yamt sync with head.
 1.6.2.4 27-Oct-2007  yamt sync with head.
 1.6.2.3 03-Sep-2007  yamt sync with head.
 1.6.2.2 30-Dec-2006  yamt sync with head.
 1.6.2.1 19-Dec-2006  yamt file ninjaata32.c was added on branch yamt-lazymbuf on 2006-12-30 20:48:03 +0000
 1.7.4.1 11-Jul-2007  mjf Sync with head.
 1.7.2.2 23-Oct-2007  ad Sync with head.
 1.7.2.1 05-Apr-2007  ad Compile fixes.
 1.8.12.1 25-Oct-2007  bouyer Sync with HEAD.
 1.8.8.2 23-Mar-2008  matt sync with HEAD
 1.8.8.1 06-Nov-2007  matt sync with HEAD
 1.8.6.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.9.16.1 03-Apr-2008  mjf Sync with HEAD.
 1.9.12.1 24-Mar-2008  keiichi sync with head.
 1.10.18.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.10.12.1 28-Apr-2009  skrll Sync with HEAD.
 1.10.4.1 04-May-2009  yamt sync with head.
 1.11.4.1 05-Mar-2011  rmind sync with head
 1.12.4.1 05-Mar-2011  bouyer Sync with HEAD
 1.12.2.1 06-Jun-2011  jruoho Sync with HEAD.
 1.13.4.1 30-Oct-2012  yamt sync with head
 1.18.28.2 27-Sep-2017  jdolecek change wdc_init_shadow_regs() to accept only struct wdc_regs, it doesn't
touch anything else

factor out the probe-only struct ata_channel initialization to wdcprobe(), to
reduce duplication of logic in individual drivers, and to actually work now
that more init is needed beyond the memset()
 1.18.28.1 24-Apr-2017  jdolecek adjust to interface changes - ata_queue is now dynamically allocated
 1.18.2.1 03-Dec-2017  jdolecek update from HEAD
 1.4 21-Feb-2011  itohy Cleanup my copyright notice.
 1.3 10-Jan-2007  itohy branches: 1.3.68; 1.3.74; 1.3.76;
Fix a typo in comment.
 1.2 01-Oct-2006  itohy branches: 1.2.2; 1.2.4;
Change Id to NetBSD
 1.1 07-Sep-2006  itohy branches: 1.1.2; 1.1.4; 1.1.6; 1.1.8;
Workbit NinjaATA-32 busmastering PIO IDE controller driver (njata)

This driver supports NinjaATA-32Bi and NPATA-32 chips,
which are used for CardBus ATA interface cards and
CardBus CompactFlash adapters.
 1.1.8.1 22-Oct-2006  yamt sync with head
 1.1.6.2 14-Sep-2006  yamt sync with head.
 1.1.6.1 07-Sep-2006  yamt file ninjaata32reg.h was added on branch yamt-pdpolicy on 2006-09-14 12:31:30 +0000
 1.1.4.2 09-Sep-2006  rpaulo sync with head
 1.1.4.1 07-Sep-2006  rpaulo file ninjaata32reg.h was added on branch rpaulo-netinet-merge-pcb on 2006-09-09 02:50:02 +0000
 1.1.2.2 12-Jan-2007  ad Sync with head.
 1.1.2.1 18-Nov-2006  ad Sync with head.
 1.2.4.3 26-Feb-2007  yamt sync with head.
 1.2.4.2 30-Dec-2006  yamt sync with head.
 1.2.4.1 01-Oct-2006  yamt file ninjaata32reg.h was added on branch yamt-lazymbuf on 2006-12-30 20:48:03 +0000
 1.2.2.1 08-Mar-2007  bouyer Pull up following revision(s) (requested by itohy in ticket #493):
sys/dev/ic/ninjaata32.c: revision 1.6
sys/dev/ic/ninjaata32reg.h: revision 1.3
share/man/man4/njata.4: revision 1.5
Fix bus_dmamap_sync() usage.
Fix a typo in comment.
Fix release in man page.
 1.3.76.1 05-Mar-2011  bouyer Sync with HEAD
 1.3.74.1 06-Jun-2011  jruoho Sync with HEAD.
 1.3.68.1 05-Mar-2011  rmind sync with head
 1.6 07-Oct-2017  jdolecek Merge support for SATA NCQ (Native Command Queueing) from jdolecek-ncq branch

ATA subsystem was changed to support several outstanding commands, and use
NCQ xfers if supported by both the controller and the disk, including NCQ
error recovery. Set NCQ high priority for BPRIO_TIMECRITICAL xfers
if supported. Added FUA support.

Done some work towards MP-safe, all ATA code tsleep()/wakeup() replaced
by condvars, and switched most code from spl* to mutexes (separate
wd(4) and ata channel lock).

Introduced new option WD_CHAOS_MONKEY to facilitate testing of error
handling, fixed several uncovered issues. Also fixed several problems
with kernel dump to wd(4) disk.

Tested with ahcisata(4), mvsata(4), siisata(4), piixide(4) on amd64,
with and without port multiplier, both disk and ATAPI devices; other
drivers and archs mechanically adjusted and compile-tested. NCQ is
supported for ahcisata(4) and siisata(4) for any controller, for
mvsata(4) only Gen IIe ones for now. Also enabled ATAPI support in
mvsata(4).

Thanks to Matt Thomas for initial ATA infrastructure patch, and
Jonathan A.Kollasch for siisata(4) NCQ changes and general testing.

Also fixes PR kern/43169 (wd(4)); and PR kern/11811, PR kern/47041,
PR kern/51979 (kernel dump)
 1.5 21-Feb-2011  itohy branches: 1.5.14; 1.5.44;
Cleanup my copyright notice.
 1.4 18-Mar-2008  cube branches: 1.4.26; 1.4.32; 1.4.34;
Split device_t and softc for ATA devices, as well as wd(4). Other
cosmetic changes where appropriate.
 1.3 01-Oct-2006  itohy branches: 1.3.4; 1.3.26; 1.3.46; 1.3.50;
Change Id to NetBSD
 1.2 01-Oct-2006  itohy Use ATA timing, instead of busmaster wait, for adding waits.
Use default wait value 0x01.
 1.1 07-Sep-2006  itohy branches: 1.1.2; 1.1.4; 1.1.6; 1.1.8;
Workbit NinjaATA-32 busmastering PIO IDE controller driver (njata)

This driver supports NinjaATA-32Bi and NPATA-32 chips,
which are used for CardBus ATA interface cards and
CardBus CompactFlash adapters.
 1.1.8.1 22-Oct-2006  yamt sync with head
 1.1.6.2 14-Sep-2006  yamt sync with head.
 1.1.6.1 07-Sep-2006  yamt file ninjaata32var.h was added on branch yamt-pdpolicy on 2006-09-14 12:31:30 +0000
 1.1.4.2 09-Sep-2006  rpaulo sync with head
 1.1.4.1 07-Sep-2006  rpaulo file ninjaata32var.h was added on branch rpaulo-netinet-merge-pcb on 2006-09-09 02:50:02 +0000
 1.1.2.1 18-Nov-2006  ad Sync with head.
 1.3.50.1 03-Apr-2008  mjf Sync with HEAD.
 1.3.46.1 24-Mar-2008  keiichi sync with head.
 1.3.26.1 23-Mar-2008  matt sync with HEAD
 1.3.4.3 24-Mar-2008  yamt sync with head.
 1.3.4.2 30-Dec-2006  yamt sync with head.
 1.3.4.1 01-Oct-2006  yamt file ninjaata32var.h was added on branch yamt-lazymbuf on 2006-12-30 20:48:03 +0000
 1.4.34.1 05-Mar-2011  bouyer Sync with HEAD
 1.4.32.1 06-Jun-2011  jruoho Sync with HEAD.
 1.4.26.1 05-Mar-2011  rmind sync with head
 1.5.44.1 24-Apr-2017  jdolecek adjust to interface changes - ata_queue is now dynamically allocated
 1.5.14.1 03-Dec-2017  jdolecek update from HEAD
 1.28 07-Aug-2021  thorpej Merge thorpej-cfargs2.
 1.27 24-Apr-2021  thorpej branches: 1.27.8;
Merge thorpej-cfargs branch:

Simplify and make extensible the config_search() / config_found() /
config_attach() interfaces: rather than having different variants for
which arguments you want pass along, just have a single call that
takes a variadic list of tag-value arguments.

Adjust all call sites:
- Simplify wherever possible; don't pass along arguments that aren't
actually needed.
- Don't be explicit about what interface attribute is attaching if
the device only has one. (More simplification.)
- Add a config_probe() function to be used in indirect configuiration
situations, making is visibly easier to see when indirect config is
in play, and allowing for future change in semantics. (As of now,
this is just a wrapper around config_match(), but that is an
implementation detail.)

Remove unnecessary or redundant interface attributes where they're not
needed.

There are currently 5 "cfargs" defined:
- CFARG_SUBMATCH (submatch function for direct config)
- CFARG_SEARCH (search function for indirect config)
- CFARG_IATTR (interface attribte)
- CFARG_LOCATORS (locators array)
- CFARG_DEVHANDLE (devhandle_t - wraps OFW, ACPI, etc. handles)

...and a sentinel value CFARG_EOL.

Add some extra sanity checking to ensure that interface attributes
aren't ambiguous.

Use CFARG_DEVHANDLE in MI FDT, OFW, and ACPI code, and macppc and shark
ports to associate those device handles with device_t instance. This
will trickle trough to more places over time (need back-end for pre-OFW
Sun OBP; any others?).
 1.26 22-Mar-2018  rin branches: 1.26.18;
Redo previous; reset async events only if scsibus has already been attached.
 1.25 22-Mar-2018  rin Do not call scsipi routines via njsc32_init before scsibus is attached.
 1.24 14-Sep-2013  martin branches: 1.24.28;
Fix detach return value
 1.23 14-Sep-2013  joerg GC unused functions and variables.
 1.22 10-Mar-2012  mrg branches: 1.22.2; 1.22.4;
take the kernel lock in functions called from attach*().
 1.21 13-Nov-2010  uebayasi branches: 1.21.8; 1.21.12; 1.21.14;
Don't pull in the whole uvm(9) API to access only PAGE_SIZE and
some other constants. These are provided by sys/param.h now.
 1.20 16-May-2009  tsutsui branches: 1.20.4;
- fix one more device_t/softc split botch in debug code
- use sc->sc_dev to get device_t
- fix inconsistent aprint_error_dev(9) usage
- some KNF and wrap long lines
 1.19 16-May-2009  tsutsui Fix botch on device_t/softc split.

XXX: still doesn't work (command timeout on data xfer).
 1.18 09-Jul-2008  joerg branches: 1.18.8;
- device/softc split
 1.17 28-Apr-2008  martin branches: 1.17.2; 1.17.4; 1.17.6;
Remove clause 3 and 4 from TNF licenses
 1.16 08-Apr-2008  cegger branches: 1.16.2; 1.16.4;
use aprint_*_dev and device_xname
 1.15 06-Nov-2007  dogcow branches: 1.15.14;
callout_init has two args.
 1.14 06-Nov-2007  itohy - Reset the bus if a Bus Reset condition is detected to make sure
all devices on the bus are really reset.

- Block interrupts on Bus Reset, and check it periodically until the
reset is released. On some 32UDE devices (probably the earlier ones)
the RST line looks unstable without the termination power and may
suffer ~continuous Bus Reset interrupts.

- Change number of scatter/gather segments from 16 to 17, to allow
non-page-aligned 64KB transfer on 4KB/page platforms.
 1.13 29-Oct-2007  itohy branches: 1.13.2;
Fix problem where targets with ID 0, 1, or 2 couldn't be reconnected.
It seems I have always tested with targets those ID >= 3,
and that I am the only user of this driver.
 1.12 19-Oct-2007  ad machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.11 09-Jul-2007  ad branches: 1.11.6; 1.11.8; 1.11.12;
Merge some of the less invasive changes from the vmlocking branch:

- kthread, callout, devsw API changes
- select()/poll() improvements
- miscellaneous MT safety improvements
 1.10 04-Mar-2007  christos branches: 1.10.2; 1.10.4;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.9 21-Feb-2007  thorpej Replace the Mach-derived boolean_t type with the C99 bool type. A
future commit will replace use of TRUE and FALSE with true and false.
 1.8 16-Nov-2006  christos branches: 1.8.2; 1.8.4; 1.8.6;
__unused removal on arguments; approved by core.
 1.7 12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.6 14-Jan-2006  itohy branches: 1.6.18; 1.6.20;
- Fix panic when the DMA buffer is not 4byte aligned.
In this case, the transfer count becomes larger than the reality,
and this fix works around it.

- Add missing bus_dmamap_unload() in attach failure path.
 1.5 24-Dec-2005  perry branches: 1.5.2;
Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.4 11-Dec-2005  christos merge ktrace-lwp.
 1.3 30-May-2005  christos branches: 1.3.2;
- add missing const
- fix variable shadowing
- remove unneeded casts
 1.2 26-Aug-2004  thorpej branches: 1.2.2; 1.2.4; 1.2.6; 1.2.16;
Use ANSI function decls, more static.
 1.1 26-Aug-2004  itohy Workbit NinjaSCSI-32 PCI/CardBus SCSI driver (njs)
 1.2.16.2 19-Nov-2007  bouyer Pull up following revision(s) (requested by itohy in ticket #1875):
sys/dev/ic/ninjascsi32.c: revision 1.13, 1.14
sys/dev/ic/ninjascsi32var.h: revision 1.4
Fix problem where targets with ID 0, 1, or 2 couldn't be reconnected.
It seems I have always tested with targets those ID >= 3,
and that I am the only user of this driver.
- Reset the bus if a Bus Reset condition is detected to make sure
all devices on the bus are really reset.
- Block interrupts on Bus Reset, and check it periodically until the
reset is released. On some 32UDE devices (probably the earlier ones)
the RST line looks unstable without the termination power and may
suffer ~continuous Bus Reset interrupts.
- Change number of scatter/gather segments from 16 to 17, to allow
non-page-aligned 64KB transfer on 4KB/page platforms.
 1.2.16.1 20-Jan-2006  tron Pull up following revision(s) (requested by itohy in ticket #1117):
sys/dev/ic/ninjascsi32.c: revision 1.6
- Fix panic when the DMA buffer is not 4byte aligned.
In this case, the transfer count becomes larger than the reality,
and this fix works around it.
- Add missing bus_dmamap_unload() in attach failure path.
 1.2.6.3 20-Jan-2006  tron Pull up following revision(s) (requested by itohy in ticket #5991):
sys/dev/ic/ninjascsi32.c: revision 1.6
- Fix panic when the DMA buffer is not 4byte aligned.
In this case, the transfer count becomes larger than the reality,
and this fix works around it.
- Add missing bus_dmamap_unload() in attach failure path.
 1.2.6.2 11-Nov-2004  he Pull up revisions 1.1-1.2 (new, via patch, requested by itohy in ticket #1741):
Add support for the Workbit NinjaSCSI-32 PCI/Cardbus
SCSI driver, njs(4).
 1.2.6.1 26-Aug-2004  he file ninjascsi32.c was added on branch netbsd-1-6 on 2004-11-11 23:13:53 +0000
 1.2.4.5 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.2.4.4 21-Sep-2004  skrll Fix the sync with head I botched.
 1.2.4.3 18-Sep-2004  skrll Sync with HEAD.
 1.2.4.2 03-Sep-2004  skrll Sync with HEAD
 1.2.4.1 26-Aug-2004  skrll file ninjascsi32.c was added on branch ktrace-lwp on 2004-09-03 12:45:18 +0000
 1.2.2.3 30-Aug-2004  tron branches: 1.2.2.3.2;
Pull up revision 1.2 (requested by itohy in ticket #800):
Use ANSI function decls, more static.
 1.2.2.2 30-Aug-2004  tron Pull up revision 1.1 (requested by itohy in ticket #800):
Workbit NinjaSCSI-32 PCI/CardBus SCSI driver (njs)
 1.2.2.1 26-Aug-2004  tron file ninjascsi32.c was added on branch netbsd-2-0 on 2004-08-30 09:24:58 +0000
 1.2.2.3.2.2 19-Nov-2007  bouyer Pull up following revision(s) (requested by itohy in ticket #11391):
sys/dev/ic/ninjascsi32.c: revisions 1.13, 1.14
sys/dev/ic/ninjascsi32var.h: revision 1.4
Fix problem where targets with ID 0, 1, or 2 couldn't be reconnected.
It seems I have always tested with targets those ID >= 3,
and that I am the only user of this driver.
- Reset the bus if a Bus Reset condition is detected to make sure
all devices on the bus are really reset.
- Block interrupts on Bus Reset, and check it periodically until the
reset is released. On some 32UDE devices (probably the earlier ones)
the RST line looks unstable without the termination power and may
suffer ~continuous Bus Reset interrupts.
- Change number of scatter/gather segments from 16 to 17, to allow
non-page-aligned 64KB transfer on 4KB/page platforms.
 1.2.2.3.2.1 20-Jan-2006  tron Pull up following revision(s) (requested by itohy in ticket #10222):
sys/dev/ic/ninjascsi32.c: revision 1.6
- Fix panic when the DMA buffer is not 4byte aligned.
In this case, the transfer count becomes larger than the reality,
and this fix works around it.
- Add missing bus_dmamap_unload() in attach failure path.
 1.3.2.6 15-Nov-2007  yamt sync with head.
 1.3.2.5 27-Oct-2007  yamt sync with head.
 1.3.2.4 03-Sep-2007  yamt sync with head.
 1.3.2.3 26-Feb-2007  yamt sync with head.
 1.3.2.2 30-Dec-2006  yamt sync with head.
 1.3.2.1 21-Jun-2006  yamt sync with head.
 1.5.2.1 15-Jan-2006  yamt sync with head.
 1.6.20.2 10-Dec-2006  yamt sync with head.
 1.6.20.1 22-Oct-2006  yamt sync with head
 1.6.18.1 18-Nov-2006  ad Sync with head.
 1.8.6.1 06-Jan-2008  wrstuden Catch up to netbsd-4.0 release.
 1.8.4.2 12-Mar-2007  rmind Sync with HEAD.
 1.8.4.1 27-Feb-2007  yamt - sync with head.
- move sched_changepri back to kern_synch.c as it doesn't know PPQ anymore.
 1.8.2.1 25-Nov-2007  xtraeme Pull up following revision(s) (requested by itohy in ticket #980):
sys/dev/ic/ninjascsi32.c: revision 1.13
sys/dev/ic/ninjascsi32.c: revision 1.14
sys/dev/ic/ninjascsi32var.h: revision 1.4
Fix problem where targets with ID 0, 1, or 2 couldn't be reconnected.

It seems I have always tested with targets those ID >= 3,
and that I am the only user of this driver.
- Reset the bus if a Bus Reset condition is detected to make sure
all devices on the bus are really reset.
- Block interrupts on Bus Reset, and check it periodically until the
reset is released. On some 32UDE devices (probably the earlier ones)
the RST line looks unstable without the termination power and may
suffer ~continuous Bus Reset interrupts.
- Change number of scatter/gather segments from 16 to 17, to allow
non-page-aligned 64KB transfer on 4KB/page platforms.
 1.10.4.1 11-Jul-2007  mjf Sync with head.
 1.10.2.2 23-Oct-2007  ad Sync with head.
 1.10.2.1 05-Apr-2007  ad Compile fixes.
 1.11.12.2 13-Nov-2007  bouyer Sync with HEAD
 1.11.12.1 25-Oct-2007  bouyer Sync with HEAD.
 1.11.8.2 08-Nov-2007  matt sync with -HEAD
 1.11.8.1 06-Nov-2007  matt sync with HEAD
 1.11.6.3 06-Nov-2007  joerg Sync with HEAD.
 1.11.6.2 31-Oct-2007  joerg Sync with HEAD.
 1.11.6.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.13.2.1 19-Nov-2007  mjf Sync with HEAD.
 1.15.14.2 28-Sep-2008  mjf Sync with HEAD.
 1.15.14.1 02-Jun-2008  mjf Sync with HEAD.
 1.16.4.3 16-May-2009  yamt sync with head
 1.16.4.2 04-May-2009  yamt sync with head.
 1.16.4.1 16-May-2008  yamt sync with head.
 1.16.2.1 18-May-2008  yamt sync with head.
 1.17.6.1 19-Oct-2008  haad Sync with HEAD.
 1.17.4.1 18-Jul-2008  simonb Sync with head.
 1.17.2.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.18.8.1 23-Jul-2009  jym Sync with HEAD.
 1.20.4.1 05-Mar-2011  rmind sync with head
 1.21.14.1 19-Mar-2012  riz Pull up following revision(s) (requested by mrg in ticket #125):
sys/dev/scsipi/scsiconf.c: revision 1.263
sys/dev/scsipi/scsiconf.c: revision 1.264
sys/dev/ic/ncr53c9x.c: revision 1.144
sys/dev/ic/ninjascsi32.c: revision 1.22
sys/dev/usb/uhub.c: revision 1.117
take the kernel lock in functions called from attach*().
scsidevdetached ioctl path enters scsipi code without kernel lock
and this upsets the newer kasserts. take kernel lock here.
take the kernel lock a few more places when doing detach, to avoid
triggering KERNEL_LOCK_P() asserts in both scsi and usb code.
with this and other recent fixes i can now "drvctl -d ehci0".
 1.21.12.1 11-Mar-2012  mrg sync to latest -current
 1.21.8.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.21.8.1 17-Apr-2012  yamt sync with head
 1.22.4.1 18-May-2014  rmind sync with head
 1.22.2.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.24.28.1 30-Mar-2018  pgoyette Resolve conflicts between branch and HEAD
 1.26.18.1 21-Mar-2021  thorpej Give config_found() the same variadic arguments treatment as
config_search(). This commit only adds the CFARG_EOL sentinel
to the existing config_found() calls. Conversion of config_found_sm_loc()
and config_found_ia() call sites will be in subsequent commits.
 1.27.8.1 04-Aug-2021  thorpej Adapt to CFARGS().
 1.3 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.2 11-Dec-2005  christos branches: 1.2.70; 1.2.72; 1.2.74;
merge ktrace-lwp.
 1.1 26-Aug-2004  itohy branches: 1.1.2; 1.1.4; 1.1.6;
Workbit NinjaSCSI-32 PCI/CardBus SCSI driver (njs)
 1.1.6.2 11-Nov-2004  he Pull up revision 1.1 (new, requested by itohy in ticket #1741):
Add support for the Workbit NinjaSCSI-32 PCI/Cardbus
SCSI driver, njs(4).
 1.1.6.1 26-Aug-2004  he file ninjascsi32reg.h was added on branch netbsd-1-6 on 2004-11-11 23:14:39 +0000
 1.1.4.4 21-Sep-2004  skrll Fix the sync with head I botched.
 1.1.4.3 18-Sep-2004  skrll Sync with HEAD.
 1.1.4.2 03-Sep-2004  skrll Sync with HEAD
 1.1.4.1 26-Aug-2004  skrll file ninjascsi32reg.h was added on branch ktrace-lwp on 2004-09-03 12:45:18 +0000
 1.1.2.2 30-Aug-2004  tron Pull up revision 1.1 (requested by itohy in ticket #800):
Workbit NinjaSCSI-32 PCI/CardBus SCSI driver (njs)
 1.1.2.1 26-Aug-2004  tron file ninjascsi32reg.h was added on branch netbsd-2-0 on 2004-08-30 09:24:58 +0000
 1.2.74.1 16-May-2008  yamt sync with head.
 1.2.72.1 18-May-2008  yamt sync with head.
 1.2.70.1 02-Jun-2008  mjf Sync with HEAD.
 1.8 06-Oct-2021  andvar s/acccess/access/
 1.7 27-Oct-2012  chs split device_t/softc for all remaining drivers.
replace "struct device *" with "device_t".
use device_xname(), device_unit(), etc.
 1.6 09-Jul-2008  joerg branches: 1.6.28; 1.6.38;
- device/softc split
 1.5 28-Apr-2008  martin branches: 1.5.2; 1.5.4; 1.5.6;
Remove clause 3 and 4 from TNF licenses
 1.4 06-Nov-2007  itohy branches: 1.4.14; 1.4.16; 1.4.18;
- Reset the bus if a Bus Reset condition is detected to make sure
all devices on the bus are really reset.

- Block interrupts on Bus Reset, and check it periodically until the
reset is released. On some 32UDE devices (probably the earlier ones)
the RST line looks unstable without the termination power and may
suffer ~continuous Bus Reset interrupts.

- Change number of scatter/gather segments from 16 to 17, to allow
non-page-aligned 64KB transfer on 4KB/page platforms.
 1.3 11-Dec-2005  christos branches: 1.3.24; 1.3.38; 1.3.44; 1.3.46; 1.3.50; 1.3.52;
merge ktrace-lwp.
 1.2 26-Aug-2004  thorpej branches: 1.2.2; 1.2.4; 1.2.6; 1.2.16; 1.2.18;
Use ANSI function decls, more static.
 1.1 26-Aug-2004  itohy Workbit NinjaSCSI-32 PCI/CardBus SCSI driver (njs)
 1.2.18.1 15-Nov-2007  yamt sync with head.
 1.2.16.1 19-Nov-2007  bouyer Pull up following revision(s) (requested by itohy in ticket #1875):
sys/dev/ic/ninjascsi32.c: revision 1.13, 1.14
sys/dev/ic/ninjascsi32var.h: revision 1.4
Fix problem where targets with ID 0, 1, or 2 couldn't be reconnected.
It seems I have always tested with targets those ID >= 3,
and that I am the only user of this driver.
- Reset the bus if a Bus Reset condition is detected to make sure
all devices on the bus are really reset.
- Block interrupts on Bus Reset, and check it periodically until the
reset is released. On some 32UDE devices (probably the earlier ones)
the RST line looks unstable without the termination power and may
suffer ~continuous Bus Reset interrupts.
- Change number of scatter/gather segments from 16 to 17, to allow
non-page-aligned 64KB transfer on 4KB/page platforms.
 1.2.6.2 11-Nov-2004  he Pull up revision 1.1-1.2 (new, requested by itohy in ticket #1741):
Add support for the Workbit NinjaSCSI-32 PCI/Cardbus
SCSI driver, njs(4).
 1.2.6.1 26-Aug-2004  he file ninjascsi32var.h was added on branch netbsd-1-6 on 2004-11-11 23:16:19 +0000
 1.2.4.4 21-Sep-2004  skrll Fix the sync with head I botched.
 1.2.4.3 18-Sep-2004  skrll Sync with HEAD.
 1.2.4.2 03-Sep-2004  skrll Sync with HEAD
 1.2.4.1 26-Aug-2004  skrll file ninjascsi32var.h was added on branch ktrace-lwp on 2004-09-03 12:45:18 +0000
 1.2.2.3 30-Aug-2004  tron branches: 1.2.2.3.2;
Pull up revision 1.2 (requested by itohy in ticket #800):
Use ANSI function decls, more static.
 1.2.2.2 30-Aug-2004  tron Pull up revision 1.1 (requested by itohy in ticket #800):
Workbit NinjaSCSI-32 PCI/CardBus SCSI driver (njs)
 1.2.2.1 26-Aug-2004  tron file ninjascsi32var.h was added on branch netbsd-2-0 on 2004-08-30 09:24:58 +0000
 1.2.2.3.2.1 19-Nov-2007  bouyer Pull up following revision(s) (requested by itohy in ticket #11391):
sys/dev/ic/ninjascsi32.c: revisions 1.13, 1.14
sys/dev/ic/ninjascsi32var.h: revision 1.4
Fix problem where targets with ID 0, 1, or 2 couldn't be reconnected.
It seems I have always tested with targets those ID >= 3,
and that I am the only user of this driver.
- Reset the bus if a Bus Reset condition is detected to make sure
all devices on the bus are really reset.
- Block interrupts on Bus Reset, and check it periodically until the
reset is released. On some 32UDE devices (probably the earlier ones)
the RST line looks unstable without the termination power and may
suffer ~continuous Bus Reset interrupts.
- Change number of scatter/gather segments from 16 to 17, to allow
non-page-aligned 64KB transfer on 4KB/page platforms.
 1.3.52.1 19-Nov-2007  mjf Sync with HEAD.
 1.3.50.1 13-Nov-2007  bouyer Sync with HEAD
 1.3.46.1 08-Nov-2007  matt sync with -HEAD
 1.3.44.1 06-Nov-2007  joerg Sync with HEAD.
 1.3.38.1 06-Jan-2008  wrstuden Catch up to netbsd-4.0 release.
 1.3.24.1 25-Nov-2007  xtraeme Pull up following revision(s) (requested by itohy in ticket #980):
sys/dev/ic/ninjascsi32.c: revision 1.13
sys/dev/ic/ninjascsi32.c: revision 1.14
sys/dev/ic/ninjascsi32var.h: revision 1.4
Fix problem where targets with ID 0, 1, or 2 couldn't be reconnected.

It seems I have always tested with targets those ID >= 3,
and that I am the only user of this driver.
- Reset the bus if a Bus Reset condition is detected to make sure
all devices on the bus are really reset.
- Block interrupts on Bus Reset, and check it periodically until the
reset is released. On some 32UDE devices (probably the earlier ones)
the RST line looks unstable without the termination power and may
suffer ~continuous Bus Reset interrupts.
- Change number of scatter/gather segments from 16 to 17, to allow
non-page-aligned 64KB transfer on 4KB/page platforms.
 1.4.18.2 04-May-2009  yamt sync with head.
 1.4.18.1 16-May-2008  yamt sync with head.
 1.4.16.1 18-May-2008  yamt sync with head.
 1.4.14.2 28-Sep-2008  mjf Sync with HEAD.
 1.4.14.1 02-Jun-2008  mjf Sync with HEAD.
 1.5.6.1 19-Oct-2008  haad Sync with HEAD.
 1.5.4.1 18-Jul-2008  simonb Sync with head.
 1.5.2.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.6.38.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.6.28.1 30-Oct-2012  yamt sync with head
 1.2 22-Sep-2000  soren Rename to match Ben's naming scheme.
 1.1 01-May-2000  soren Add Seeq 8003 register definitions.
 1.4 28-Jun-1995  cgd move to more appropriate (...reg.h) names.
 1.3 27-Oct-1994  cgd new RCS ID format.
 1.2 22-May-1993  cgd add rcsids to everything and clean up headers
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.6 11-Dec-2005  christos merge ktrace-lwp.
 1.5 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22364, verified by myself.
 1.4 03-Oct-1997  enami branches: 1.4.50;
Cosmetic change; delete one space character.
 1.3 27-Oct-1994  cgd branches: 1.3.14;
new RCS ID format.
 1.2 22-May-1993  cgd add rcsids to everything and clean up headers
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.3.14.1 14-Oct-1997  thorpej Update marc-pcmcia branch from trunk.
 1.4.50.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.4.50.2 18-Sep-2004  skrll Sync with HEAD.
 1.4.50.1 03-Aug-2004  skrll Sync with HEAD
 1.5 28-Jun-1995  cgd move to more appropriate (...reg.h) names.
 1.4 27-Oct-1994  cgd new RCS ID format.
 1.3 30-Jun-1993  andrew Added com_scratch entry.
 1.2 22-May-1993  cgd add rcsids to everything and clean up headers
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.14 06-Oct-2022  riastradh com(4): Add include guards.
 1.13 11-Jan-2019  thorpej Simplify regmap initialization, and fix an regmap issue that
affected TI OMAP (LCR register would get clobbered due to
using the wrong offset for the MDR1 register) reported by Lwazi Dube
(who also found the root cause).
 1.12 29-Oct-2017  jmcneill branches: 1.12.2; 1.12.4;
Make all of the COM_xxx type options runtime selectable. Kernel configs
with the existing options (COM_16650, COM_16750, COM_AWIN, COM_HAYESP, and
COM_PXA2X0) will select the correct type in com_attach_subr. New code
should specify the com type by passing COM_TYPE_xxx to comcnattach and/or
setting sc_type.
 1.11 27-May-2016  bouyer The UART in the allwiner SoCs is not full-compatible with the 16550, and
it's not a 16750 either. Like the 16750 it has the IIR_BUSY interrupt,
which is triggered when writing to LCR while the chip
can't accept it. But unlike the 16750, it has a specific register,
HALT, to allow writing to the LCR and divisor registers, and then
commit the changes.
Tested on an A20 SoC, changing the baud rate while keeping the
tty device open and incoming data.
 1.10 03-Oct-2013  kiyohara branches: 1.10.4; 1.10.6;
Revirt 'Move the Marvell extension to com_mv.c' at Sun Sep 1 04:51:24 UTC 2013.
build test only.
 1.9 01-Sep-2013  kiyohara Move the Marvell extension to com_mv.c.
 1.8 20-Apr-2013  rkujawa Add support for 16750 style UARTs. Activated by defining COM_16750.

Obtained from Marvell, Semihalf.
 1.7 11-Dec-2005  christos branches: 1.7.110; 1.7.120;
merge ktrace-lwp.
 1.6 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22364, verified by myself.
 1.5 16-May-2000  thorpej branches: 1.5.28;
Whitespace glitch.
 1.4 27-Oct-1994  cgd branches: 1.4.32;
new RCS ID format.
 1.3 30-Jun-1993  andrew Added com_scratch entry.
 1.2 22-May-1993  cgd add rcsids to everything and clean up headers
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.4.32.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.5.28.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.5.28.2 18-Sep-2004  skrll Sync with HEAD.
 1.5.28.1 03-Aug-2004  skrll Sync with HEAD
 1.7.120.2 03-Dec-2017  jdolecek update from HEAD
 1.7.120.1 23-Jun-2013  tls resync from head
 1.7.110.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.10.6.1 29-May-2016  skrll Sync with HEAD
 1.10.4.1 22-Jun-2016  snj Pull up following revision(s) (requested by bouyer in ticket #1178):
sys/arch/arm/allwinner/files.awin: revision 1.36
sys/conf/files: revision 1.1159
sys/dev/ic/com.c: revision 1.339
sys/dev/ic/comreg.h: revision 1.25
sys/dev/ic/comvar.h: revision 1.82
sys/dev/ic/ns16550reg.h: revision 1.11
The UART in the allwiner SoCs is not full-compatible with the 16550, and
it's not a 16750 either. Like the 16750 it has the IIR_BUSY interrupt,
which is triggered when writing to LCR while the chip
can't accept it. But unlike the 16750, it has a specific register,
HALT, to allow writing to the LCR and divisor registers, and then
commit the changes.
Tested on an A20 SoC, changing the baud rate while keeping the
tty device open and incoming data.
 1.12.4.1 10-Jun-2019  christos Sync with HEAD
 1.12.2.1 18-Jan-2019  pgoyette Synch with HEAD
 1.3 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.2 05-Sep-1998  christos branches: 1.2.144; 1.2.146; 1.2.148;
Assign copyright to TNF.
 1.1 21-Jun-1998  christos Add register definitions for the ns8477 floppy controller. This is a superset
of the nec765.
 1.2.148.1 16-May-2008  yamt sync with head.
 1.2.146.1 18-May-2008  yamt sync with head.
 1.2.144.1 02-Jun-2008  mjf Sync with HEAD.
 1.79 16-Dec-2022  msaitoh lm(4): Add Nuvoton NCT6797D support.
 1.78 01-Oct-2022  msaitoh Add Nuvoton NCT6799D support.
 1.77 01-Aug-2022  mlelstv Prevent multiple unregistrations.
 1.76 01-Aug-2022  mlelstv revert accidental commit.
 1.75 01-Aug-2022  mlelstv Also fix shift values for SCT constants.
 1.74 07-Sep-2020  mrg don't call printf %s with a NULL.
 1.73 10-Jul-2019  msaitoh branches: 1.73.2;
Identify Nuvoton NCT6798D correctly. It seems that the bit width of NCT6796D
and newer devices' device ID is 13bit. The previous series was 12bits.
 1.72 30-Nov-2018  msaitoh Use pmf_device_{register,deregister}().
 1.71 07-Mar-2018  msaitoh branches: 1.71.2;
Add NCT6796D. Some functions of NCT6796D is extended from NCT6795D,
but this commit doesn't support them yet.
 1.70 18-Aug-2017  msaitoh branches: 1.70.2;
- WBSIO_ID_W83627DHG and newer devices have 12bit device ID. So, change sioid
from 8bit to 16bit and check with it strictly.
- s/lm_match/nslm_match/
- split {wb,lm,def}_match() to XXX_match and XXX_attach().
- Rename lm_probe with lm_match and call {wb,nslm,def}_match() at the end of
the function to check strictly.
- NCT610[246]D is different from otehrs, so add new nct6102d_sensors[] table.
- Register offsets of vendor ID and chip id of NCT610[246]D are different
from others. When it failed reading vendor ID or chip ID, fallback to
NCT610[246]D's register offsets.
- Add debug messages.
 1.69 17-Aug-2017  msaitoh Use uint8_t instead of int. No functional change.
 1.68 09-Aug-2017  msaitoh - Sprinkle static and const. No functional change.
- Print chip ID in hexadecimal instead of octal in def_match().
 1.67 20-Jul-2017  msaitoh Fix typo.
 1.66 20-Jul-2017  msaitoh Fix a bug that fan RPM wasn't printed correctly. 0xbX is not RPM but counter.
Use 0xcX.
 1.65 11-Jul-2017  msaitoh lm(4): Add suport for NCT5174D, NCT6775F, NCT6779D and NCT679[1235]D.
wbsio(4): Add support for NCT6795D.
 1.64 01-Jun-2016  pgoyette branches: 1.64.10;
Ooopppsss, missed the function declaration!
 1.63 01-Jun-2016  pgoyette Add support for Nuvoton NCT6776F from OpenBSD

From PR kern/49747
 1.62 23-Apr-2015  pgoyette Update module dependencies for all the existing modules that depend on sysmon components.
 1.61 16-Nov-2014  ozaki-r branches: 1.61.2;
Replace callout_stop with callout_halt

In order to call callout_destroy for a callout safely, we have to ensure
the function of the callout is not running and pending. To do so, we should
use callout_halt, not callout_stop.

Discussed with martin@ and riastradh@.
 1.60 20-Oct-2013  christos branches: 1.60.4;
fix unused variable warnings
 1.59 21-Jan-2012  jakllsch branches: 1.59.2; 1.59.6; 1.59.10;
Add module glue. (Better late than never.)
 1.58 20-Jun-2011  pgoyette branches: 1.58.2; 1.58.6;
Initializes sensors states before registering.
 1.57 05-Mar-2011  jakllsch branches: 1.57.2;
Set the ENVSYS_FCHANGERFACT flag soon enough for it to make a difference.
 1.56 06-Oct-2010  jakllsch branches: 1.56.2;
Fix vcore readings in some cases on W83627THF by being mindful of the VRM9 mode.
 1.55 23-Mar-2010  njoly Add some missing aprint_naive calls.
 1.54 13-Feb-2010  jakllsch branches: 1.54.2;
Explicitly mark voltage readings as valid in Winbond voltage refresh functions.
This fixes forever-N/A VCore and -12V readings on my W83627THF chips.
.
 1.53 09-Feb-2010  njoly Kill extra semi-column.
 1.52 09-Feb-2010  pgoyette Correct setting of bits in the "generic thermistor" mode. Cut&paste
error pointed out by njoly@
 1.51 08-Feb-2010  pgoyette After reviewing the datasheets, most of the supported Winbond chips can
handles the new flags for selecting sensor type. Update code and man
page accordingly.
 1.50 08-Feb-2010  pgoyette Add temp-sensor type selection (via autoconfig flags). Currently only
enabled for W83627HF but easily extended to others if appropriate.

Fixes PR kern-42758
 1.49 13-Oct-2008  pgoyette branches: 1.49.14;
Fix up the bus-independant probe code. Patch from njoly@
 1.48 12-Oct-2008  pgoyette Add an i2c attachment for the LM78 family of temp sensor/fan control

Tested by Martin Husemann
 1.47 28-Apr-2008  martin branches: 1.47.6;
Remove clause 3 and 4 from TNF licenses
 1.46 05-Mar-2008  xtraeme branches: 1.46.2; 1.46.4;
Split device_t/softc in the lm(4) driver and its attachments, and
other related cosmetic changes.
 1.45 07-Feb-2008  xtraeme branches: 1.45.2; 1.45.6;
lm_refresh_volt: don't overwrite the state of the sensor. Patch by
Fukumoto Atsushi - PR kern/37977.
 1.44 16-Nov-2007  xtraeme Extend the envsys2 API (one more time, sorry) as defined in:

http://mail-index.netbsd.org/tech-kern/2007/11/09/0001.html

sysmon_envsys_create() and sysmon_envsys_destroy() were added to
create/destroy sysmon_envsys objects (and its TAILQ/LIST for sensors/events).

sysmon_envsys_sensor_attach() and sysmon_envsys_sensor_detach() were
added to attach/detach sensors to a specified sysmon_envsys device.

The events framework is now per device and configurable via the
ENVSYS_SETDICTIONARY ioctl or /etc/envsys.conf and envstat(8).

Update all users and documentation to reflect these changes.
 1.43 19-Oct-2007  ad branches: 1.43.2;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.42 08-Sep-2007  xtraeme branches: 1.42.4;
Update a comment.
 1.41 08-Sep-2007  xtraeme Use a 2 seconds period to refresh sensor data, previous value wasn't
accepted and triggered an assertion.
 1.40 08-Sep-2007  xtraeme - Use a callout(9) to refresh sensor data each 1.5 seconds, respecting
the limit in some LM chips.
- Add the lm_detach() function that stops/destroys the callout and
unregisters the driver from the sysmon_envsys(9) framework.
 1.39 08-Aug-2007  xtraeme branches: 1.39.2;
w83627ehf_sensors: don't add sensors with duplicate descriptions.
These are voltage sensors and the VINX name is appropiate.

Found by Heron Gallegos.
 1.38 02-Jul-2007  xtraeme branches: 1.38.2; 1.38.6;
Winbond W83627EHF-A support, from OpenBSD.
 1.37 01-Jul-2007  xtraeme Imported envsys 2, a brief description of the new features:
(Part 2: drivers)

* Support for detachable sensors.
* Cleaned up the API for simplicity and efficiency.
* Ability to send capacity/critical/warning events to powerd(8).
* Adapted all the code to the new locking order.
* Compatibility with the old envsys API: the ENVSYS_GTREINFO
and ENVSYS_GTREDATA ioctl(2)s are supported.
* Added support for a 'dictionary based communication channel' between
sysmon_power(9) and powerd(8), that means there is no 32 bytes event
size restriction anymore.
* Binary compatibility with old envstat(8) and powerd(8) via COMPAT_40.
* All drivers with the n^2 gtredata bug were fixed, PR kern/36226.

Tested by:

blymn: smsc(4).
bouyer: ipmi(4), mfi(4).
kefren: ug(4).
njoly: viaenv(4), adt7463.c.
riz: owtemp(4).
xtraeme: acpiacad(4), acpibat(4), acpitz(4), aiboost(4), it(4), lm(4).
 1.36 26-May-2007  tsutsui Fix a typo in RFACT of the second 3.3Vcc of W83627EHF. From OpenBSD.
 1.35 19-Apr-2007  xtraeme Fix a debug printf.
 1.34 19-Apr-2007  xtraeme Add more debugging printfs, to see the raw data returned by
the registers.
 1.33 13-Mar-2007  xtraeme Use C99 struct initializers.
 1.32 11-Mar-2007  christos branches: 1.32.2;
fix missing initializers.
 1.31 11-Mar-2007  xtraeme Explicitly initialize lm_sensor->rfact for every sensor's chip.
 1.30 11-Mar-2007  xtraeme Update for the nslm7x driver:

* For each supported chip, there's a struct lm_sensor array
that specifies the sensor data, like reg, bank, descr, rfact.

* Rather than having 3 functions to setup the voltage, temp and fan
sensors, just have one that will do all the three steps looking at
its struct lm_sensor members, simplifying a lot the code.

and more things that I can remember, our code now is synced with
OpenBSD, IMHO much better to understand and maintain in the future.

Supported chips added with the new code include:

* Winbond: W83627EHF, W83627DHG, W83637HF, W83783S, W83791D, W83791SD,
W83792D.
* Asus AS9912F.

My new mobo with the Winbond W83627DHG chip correctly reports
the values now:

lm0 at isa0 port 0x290-0x297: Winbond W83627DHG Hardware monitor

[juan@nocturno][~]> envstat -r
VCore: 1.232 V
+12V: 12.091 V
+3.3V: 3.264 V
+5V: 4.945 V
VBAT: 3.728 V
System Temp: 36.000 degC
CPU Temp: 29.500 degC
Aux Temp: 22.000 degC
CPU Fan: 1591 RPM
[juan@nocturno][~]>
 1.29 29-Jan-2007  hubertf branches: 1.29.2; 1.29.6;
Remove more duplicate headers.
Patch by Slava Semushin <slava.semushin@gmail.com>

Again, this was tested by comparing obj files from a pristine and a patched
source tree against an i386/ALL kernel, and also for src/sbin/fsck_ffs,
src/sbin/fsdb and src/usr.sbin/makefs. Only changes in assert() line numbers
were detected in 'objdump -d' output.
 1.28 07-Jan-2007  tsutsui Typo.
 1.27 08-Jun-2006  hannken branches: 1.27.6; 1.27.10;
Add missing brace to make it compile again.
 1.26 07-Jun-2006  kardel merge FreeBSD timecounters from branch simonb-timecounters
- struct timeval time is gone
time.tv_sec -> time_second
- struct timeval mono_time is gone
mono_time.tv_sec -> time_uptime
- access to time via
{get,}{micro,nano,bin}time()
get* versions are fast but less precise
- support NTP nanokernel implementation (NTP API 4)
- further reading:
Timecounter Paper: http://phk.freebsd.dk/pubs/timecounter.pdf
NTP Nanokernel: http://www.eecis.udel.edu/~mills/ntp/html/kern.html
 1.25 13-May-2006  xtraeme branches: 1.25.2;
Remove code for the IT87xxF chipsets, it was included on its own
driver (it(4)).
 1.24 11-Dec-2005  christos branches: 1.24.4; 1.24.6; 1.24.8; 1.24.12;
merge ktrace-lwp.
 1.23 15-Oct-2005  xtraeme Added support for Winbond 83627THF, from OpenBSD.
 1.22 29-Apr-2005  xtraeme branches: 1.22.2;
Identify correctly ITE Super I/O chipsets by checking the core ID
register (only available in the model 8712F), if that fails we check
the vendor ID register as before.
 1.21 27-Feb-2005  perry branches: 1.21.2;
nuke trailing whitespace
 1.20 04-Feb-2005  perry de-__P
 1.19 24-Jul-2004  christos branches: 1.19.4; 1.19.6;
PR/26420: Thilo Manske: lm(4): Add support vor environment controller
built into iTE 8705f
Also: change some memcpy's to strlcpy's and some (0)'s to 0's
 1.18 22-Apr-2004  itojun sprintf -> snprintf
 1.17 15-Nov-2002  ad branches: 1.17.6;
Changes for SMBus/I2C:

- Move lm_readreg/lm_writereg into the front-ends. Add/use function pointers
in the softc.
- Add a bank select function pointer to the softc and provide a generic
version. WinBond chips accessed over serial bus present three addresses,
two of which are used to access bank 1/2 registers.
- Mark TSENS2/3 sensor data as invalid if the the corresponding bank select
fails.
 1.16 07-Nov-2002  thorpej Fix signed/unsigned comparison warnings.
 1.15 05-Apr-2002  bouyer Properly identify LM81. From Sergey Svishchev in PR kern/13420.
 1.14 30-Mar-2002  tron Apply changes provided by Thilo Manske in PR kern/16118:
1. Fix setting of nominal fan speeds with ENVSYS_STREINFO.
2. Treat Winbond 83781D specially because it has a programmable divisor for
FAN3 unlike generic devices.
3. Set nominal RPMs.
4. Fix a typo in the code for setting FAN3's divisor for W83782 type
hardware monitors.
 1.13 13-Nov-2001  lukem add/cleanup RCSID
 1.12 16-Sep-2001  wiz Spell 'occurred' with two 'r's.
 1.11 04-Nov-2000  veego branches: 1.11.2; 1.11.4; 1.11.6; 1.11.8;
Print the vendor and chip id in the DPRINTF with 0x%x and not just %d.
 1.10 03-Aug-2000  bouyer Some W83781 have ID 0x11 instead of 0x10; handle these too.
Restore printing sdata for each sensors if DEBUG.
 1.9 02-Aug-2000  bouyer W83781D: Explicitely reselect bank0 before using "value RAM" registers.
Hopefully this will make the W83781D works.
Also use common functions to set up fan & temp info[] & sensors[] for
the W83781D.
 1.8 02-Aug-2000  bouyer Add support for the W83697HF - basically a W83627HF with only 2 temp sensors.
 1.7 30-Jul-2000  bouyer Add support for the W83781D and W83782D hardware monitors.
 1.6 30-Jul-2000  bouyer swap lm_match() and wb_match(), as wb_match() is more restrictive.
Otherwise a winbond can be mis-probed as a lm if it has the rigth device ID.
Problem reported by Bernd Ernesti.
 1.5 27-Jul-2000  bouyer Add support for the W83627HF: lm7x like, but with more sensors, and more
registers.
 1.4 24-Jun-2000  thorpej Add a clearing-house pseudo-device for system monitoring devices
such as the LM78 and VT82C686A (and eventually ACPI). Multiple
sensor devices can be hooked registered with `sysmon', and eventually
sysmon will also handle hardware (and software) watchdog timers.

Convert the `lm' and `viaenv' drivers to the new interface.
 1.3 09-Mar-2000  groo branches: 1.3.4;
support rfact. use manufac. suggested resistor values by default
clean up some comments
 1.2 07-Mar-2000  groo split probe into generic and bus specific
 1.1 25-Feb-2000  groo Initial import of National Semiconductor LM7[89] Hardware Monitor with isa and
pnpbios attach.

examples:

lm0 at pnpbios0 index?
lm0 at isa? port 0x290


TODO: spinlocks, i2c interface.
 1.3.4.3 04-Aug-2000  bouyer Pull up (approved by jhawk):
share/man/man4/lm.4 1.6->1.8
sys/dev/ic/nslm7x.c 1.7 -> 1.10
sys/dev/ic/nslm7xvar.h 1.5->1.7

Factor out a few things in common functions.
Add support for W83781D, W83782D and W83697HF hardware monitors.
Print sdata for each sensors if DEBUG.
Update doc (W83781D & W83782D tested, W83697HF untested but "should work"
because very close to the W83627HF).
 1.3.4.2 02-Aug-2000  bouyer Pull up (approved by thorpej):
sys/dev/ic/nslm7x.c 1.4->1.7
sys/dev/ic/nslm7xvar.h 1.3->1.5
share/man/man4/lm.4 1.5->1.6

Add support for a few winbond hardware monitors.
 1.3.4.1 30-Jul-2000  bouyer Pull up (requested by thorpej):
lm_pnpbios.c 1.2->1.3
files 1.374->1.375
nslm7x.c 1.3->1.4
nslm7xvar.h 1.2->1.3
lm_isa.c 1.2->1.3
files.pci 1.96->1.97
viaenv.c 1.2->1.3
sysmon.c 1.1
sysmonvar.h 1.1

Add a clearing-house pseudo-device for system monitoring devices
such as the LM78 and VT82C686A (and eventually ACPI). Multiple
sensor devices can be hooked registered with `sysmon', and eventually
sysmon will also handle hardware (and software) watchdog timers.

Convert the `lm' and `viaenv' drivers to the new interface.
 1.11.8.1 01-Oct-2001  fvdl Catch up with -current.
 1.11.6.2 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.11.6.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.11.4.5 11-Dec-2002  thorpej Sync with HEAD.
 1.11.4.4 11-Nov-2002  nathanw Catch up to -current
 1.11.4.3 17-Apr-2002  nathanw Catch up to -current.
 1.11.4.2 14-Nov-2001  nathanw Catch up to -current.
 1.11.4.1 21-Sep-2001  nathanw Catch up to -current.
 1.11.2.3 22-Nov-2000  bouyer Sync with HEAD.
 1.11.2.2 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.11.2.1 04-Nov-2000  bouyer file nslm7x.c was added on branch thorpej_scsipi on 2000-11-20 11:40:50 +0000
 1.17.6.4 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.17.6.3 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.17.6.2 04-Feb-2005  skrll Sync with HEAD.
 1.17.6.1 03-Aug-2004  skrll Sync with HEAD
 1.19.6.2 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.19.6.1 12-Feb-2005  yamt sync with head.
 1.19.4.1 29-Apr-2005  kent sync with -current
 1.21.2.2 15-Oct-2005  riz Pull up following revision(s) (requested by xtraeme in ticket #893):
sys/dev/ic/nslm7x.c: revision 1.23
sys/dev/ic/nslm7xvar.h: revision 1.16
Added support for Winbond 83627THF, from OpenBSD.
 1.21.2.1 01-May-2005  tron Pull up revision 1.22 (requested by xtraeme in ticket #213):
Identify correctly ITE Super I/O chipsets by checking the core ID
register (only available in the model 8712F), if that fails we check
the vendor ID register as before.
 1.22.2.7 17-Mar-2008  yamt sync with head.
 1.22.2.6 11-Feb-2008  yamt sync with head.
 1.22.2.5 07-Dec-2007  yamt sync with head
 1.22.2.4 27-Oct-2007  yamt sync with head.
 1.22.2.3 03-Sep-2007  yamt sync with head.
 1.22.2.2 26-Feb-2007  yamt sync with head.
 1.22.2.1 21-Jun-2006  yamt sync with head.
 1.24.12.1 24-May-2006  tron Merge 2006-05-24 NetBSD-current into the "peter-altq" branch.
 1.24.8.2 26-Jun-2006  yamt sync with head.
 1.24.8.1 24-May-2006  yamt sync with head.
 1.24.6.2 01-Jun-2006  kardel Sync with head.
 1.24.6.1 04-Feb-2006  simonb Adapt for timecounters: mostly use get*time() and use "time_second"
instead of "time.tv_sec".
 1.24.4.1 09-Sep-2006  rpaulo sync with head
 1.25.2.1 19-Jun-2006  chap Sync with head.
 1.27.10.2 18-Jun-2007  liamjfoy Pull up following revision(s) (requested by tsutsui in ticket #730):
sys/dev/ic/nslm7x.c: revision 1.36
Fix a typo in RFACT of the second 3.3Vcc of W83627EHF. From OpenBSD.
 1.27.10.1 20-Apr-2007  bouyer branches: 1.27.10.1.2;
Pull up following revision(s) (requested by xtraeme in ticket #584):
share/man/man4/lm.4: revisions 1.19 - 1.20
sys/dev/isa/lm_isa.c: revision 1.16 via patch
sys/dev/ic/nslm7xvar.h: revision 1.19
sys/dev/ic/nslm7x.c: revision 1.30 - 1.33 via patch
sync lm(4) with OpenBSD.
Supported chips added with the new code include:
* Winbond: W83627EHF, W83627DHG, W83637HF, W83783S, W83791D, W83791SD,
W83792D.
* Asus AS9912F.
 1.27.10.1.2.1 03-Sep-2007  wrstuden Sync w/ NetBSD-4-RC_1
 1.27.6.2 01-Feb-2007  ad Sync with head.
 1.27.6.1 12-Jan-2007  ad Sync with head.
 1.29.6.7 23-Oct-2007  ad Sync with head.
 1.29.6.6 09-Oct-2007  ad Sync with head.
 1.29.6.5 20-Aug-2007  ad Sync with HEAD.
 1.29.6.4 15-Jul-2007  ad Sync with head.
 1.29.6.3 27-May-2007  ad Sync with head.
 1.29.6.2 10-Apr-2007  ad Sync with head.
 1.29.6.1 13-Mar-2007  ad Sync with head.
 1.29.2.3 07-May-2007  yamt sync with head.
 1.29.2.2 24-Mar-2007  yamt sync with head.
 1.29.2.1 12-Mar-2007  rmind Sync with HEAD.
 1.32.2.1 11-Jul-2007  mjf Sync with head.
 1.38.6.4 21-Nov-2007  joerg Sync with HEAD.
 1.38.6.3 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.38.6.2 02-Oct-2007  joerg Sync with HEAD.
 1.38.6.1 09-Aug-2007  jmcneill Sync with HEAD.
 1.38.2.2 10-Sep-2007  skrll Sync with HEAD.
 1.38.2.1 15-Aug-2007  skrll Sync with HEAD.
 1.39.2.3 23-Mar-2008  matt sync with HEAD
 1.39.2.2 09-Jan-2008  matt sync with HEAD
 1.39.2.1 06-Nov-2007  matt sync with HEAD
 1.42.4.2 18-Nov-2007  bouyer Sync with HEAD
 1.42.4.1 25-Oct-2007  bouyer Sync with HEAD.
 1.43.2.2 18-Feb-2008  mjf Sync with HEAD.
 1.43.2.1 19-Nov-2007  mjf Sync with HEAD.
 1.45.6.3 17-Jan-2009  mjf Sync with HEAD.
 1.45.6.2 02-Jun-2008  mjf Sync with HEAD.
 1.45.6.1 03-Apr-2008  mjf Sync with HEAD.
 1.45.2.1 24-Mar-2008  keiichi sync with head.
 1.46.4.5 09-Oct-2010  yamt sync with head
 1.46.4.4 11-Aug-2010  yamt sync with head.
 1.46.4.3 11-Mar-2010  yamt sync with head
 1.46.4.2 04-May-2009  yamt sync with head.
 1.46.4.1 16-May-2008  yamt sync with head.
 1.46.2.1 18-May-2008  yamt sync with head.
 1.47.6.1 19-Oct-2008  haad Sync with HEAD.
 1.49.14.2 22-Oct-2010  uebayasi Sync with HEAD (-D20101022).
 1.49.14.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.54.2.3 06-Mar-2011  rmind sync with head (and fix few botches with this)
 1.54.2.2 05-Mar-2011  rmind sync with head
 1.54.2.1 30-May-2010  rmind sync with head
 1.56.2.1 06-Jun-2011  jruoho Sync with HEAD.
 1.57.2.1 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.58.6.1 18-Feb-2012  mrg merge to -current.
 1.58.2.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.58.2.1 17-Apr-2012  yamt sync with head
 1.59.10.1 18-May-2014  rmind sync with head
 1.59.6.2 03-Dec-2017  jdolecek update from HEAD
 1.59.6.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.59.2.1 07-Dec-2014  martin Pull up following revision(s) (requested by ozaki-r in ticket #1201):
sys/kern/kern_ktrace.c: revision 1.166
sys/dev/isa/aps.c: revision 1.16
sys/dev/sysmon/sysmonvar.h: revision 1.45
sys/dev/ir/irframe_tty.c: revision 1.60
sys/dev/sysmon/sysmon_envsys_events.c: revision 1.111-1.112 (patch)
sys/dev/pci/pccbb.c: revision 1.207
sys/dev/wscons/wskbd.c: revision 1.135
sys/dev/usb/ohci.c: revision 1.254
sys/net/if_ecosubr.c: revision 1.41
sys/dev/pcmcia/btbc.c: revision 1.17
sys/arch/x86/x86/via_padlock.c: revision 1.23
sys/dev/sdmmc/sdmmc.c: revision 1.23 (patch)
sys/dev/bluetooth/btkbd.c: revision 1.17
sys/dev/bluetooth/bcsp.c: revision 1.25
sys/arch/x86/pci/fwhrng.c: revision 1.8
sys/dev/ic/nslm7x.c: revision 1.61
share/man/man9/callout.9: revision 1.28 (patch)

Replace callout_stop with callout_halt and ensure the callout
is not running before destroying it.
 1.60.4.1 01-Dec-2014  martin Pull up following revision(s) (requested by ozaki-r in ticket #279):
sys/kern/kern_ktrace.c: revision 1.166
sys/dev/isa/aps.c: revision 1.16
sys/dev/sysmon/sysmonvar.h: revision 1.45
sys/dev/ir/irframe_tty.c: revision 1.60
sys/dev/sysmon/sysmon_envsys_events.c: revision 1.111
sys/dev/sysmon/sysmon_envsys_events.c: revision 1.112
sys/dev/pci/pccbb.c: revision 1.207
sys/dev/wscons/wskbd.c: revision 1.135
sys/dev/usb/ohci.c: revision 1.254
sys/net/if_ecosubr.c: revision 1.41
sys/dev/pcmcia/btbc.c: revision 1.17
sys/arch/x86/x86/via_padlock.c: revision 1.23
sys/dev/sdmmc/sdmmc.c: revision 1.23
sys/dev/bluetooth/btkbd.c: revision 1.17
sys/dev/bluetooth/bcsp.c: revision 1.25
sys/arch/x86/pci/fwhrng.c: revision 1.8
sys/dev/ic/nslm7x.c: revision 1.61
share/man/man9/callout.9: revision 1.28
Replace callout_stop with callout_halt
In order to call callout_destroy for a callout safely, we have to ensure
the function of the callout is not running and pending. To do so, we should
use callout_halt, not callout_stop.
Discussed with martin@ and riastradh@.
Make it clear that we should use not callout_stop but callout_halt
before callout_destroy
Replace callout_stop with callout_halt
In order to call callout_destroy for a callout safely, we have to ensure
the function of the callout is not running and pending. To do so, we should
use callout_halt, not callout_stop.
In this case, we need to pass an interlock to callout_halt to wait for
the callout complete.
Reviewed by riastradh@.
Kill sme_callout_mtx and use sme_mtx instead
We can use sme_mtx for the callout as well. Actually we should do so
because sme_events_list and some other data that are touched in the
callout should be protected by sme_mtx, not sme_callout_mtx.
Discussed with riastradh@ in
http://mail-index.netbsd.org/tech-kern/2014/11/11/msg017956.html
Replace callout_stop with callout_halt
In order to call callout_destroy for a callout safely, we have to ensure
the function of the callout is not running and pending. To do so, we should
use callout_halt, not callout_stop.
In this case, we need to pass an interlock to callout_halt to wait for
the callout complete. And also we make sure that SME_CALLOUT_INITIALIZED
is unset before calling callout_halt to prevent the callout from calling
callout_schedule. This is the same as what we did in sys/netinet6/mld6.c@1.61.
Reviewed by riastradh@.
 1.61.2.3 28-Aug-2017  skrll Sync with HEAD
 1.61.2.2 09-Jul-2016  skrll Sync with HEAD
 1.61.2.1 06-Jun-2015  skrll Sync with HEAD
 1.64.10.5 19-Jan-2023  martin Pull up following revision(s) (requested by msaitoh in ticket #1784):

share/man/man4/lm.4: revision 1.38
sys/dev/ic/nslm7x.c: revision 1.79
sys/dev/isa/wbsio.c: revision 1.30
sys/dev/isa/wbsioreg.h: revision 1.11

lm(4): Add Nuvoton NCT6797D support.
 1.64.10.4 15-Oct-2022  martin Pull up following revision(s) (requested by msaitoh in ticket #1774):

share/man/man4/lm.4: revision 1.37
sys/dev/isa/wbsio.c: revision 1.28
sys/dev/ic/nslm7x.c: revision 1.78
sys/dev/isa/wbsioreg.h: revision 1.10

Add Nuvoton NCT6799D support.
 1.64.10.3 17-Jul-2019  martin Pull up following revision(s) (requested by msaitoh in ticket #1294):

sys/dev/isa/wbsio.c: revision 1.25
sys/dev/ic/nslm7x.c: revision 1.72
sys/dev/ic/nslm7x.c: revision 1.73
sys/dev/isa/wbsioreg.h: revision 1.9

Use pmf_device_{register,deregister}().

-

Identify Nuvoton NCT6798D correctly. It seems that the bit width of NCT6796D
and newer devices' device ID is 13bit. The previous series was 12bits.
 1.64.10.2 26-Jul-2018  snj Pull up following revision(s) (requested by msaitoh in ticket #927):
share/man/man4/lm.4: 1.35, 1.36
sys/dev/ic/nslm7x.c: 1.71
sys/dev/isa/wbsio.c: 1.23
sys/dev/isa/wbsioreg.h: 1.8
Add NCT6796D. Some functions of NCT6796D is extended from NCT6795D,
but this commit doesn't support them yet.
--
Add NCT6796D.
--
Remove Tn. Add serial comma.
 1.64.10.1 22-Nov-2017  martin Pull up following revision(s) (requested by msaitoh in ticket #374):
share/man/man4/lm.4: revision 1.33
share/man/man4/lm.4: revision 1.34
sys/dev/ic/nslm7x.c: revision 1.70
sys/dev/isa/lm_isa_common.c: revision 1.5
sys/dev/isa/lm_isa_common.c: revision 1.6
sys/dev/isa/wbsio.c: revision 1.11
sys/dev/i2c/lm_i2c.c: revision 1.3
sys/dev/isa/wbsio.c: revision 1.12
sys/dev/i2c/lm_i2c.c: revision 1.4
sys/dev/isa/wbsioreg.h: revision 1.1
sys/dev/isa/wbsio.c: revision 1.13
sys/dev/isa/wbsioreg.h: revision 1.2
sys/dev/isa/wbsio.c: revision 1.14
sys/dev/isa/wbsioreg.h: revision 1.3
sys/dev/isa/wbsio.c: revision 1.15
sys/dev/isa/wbsioreg.h: revision 1.4
sys/dev/isa/wbsioreg.h: revision 1.5
share/man/man4/wbsio.4: revision 1.4
share/man/man4/wbsio.4: revision 1.5
sys/dev/ic/nslm7xvar.h: revision 1.30
sys/dev/ic/nslm7x.c: revision 1.65
share/man/man4/wbsio.4: revision 1.6
sys/dev/ic/nslm7xvar.h: revision 1.31
sys/dev/ic/nslm7x.c: revision 1.66
sys/dev/ic/nslm7xvar.h: revision 1.32
sys/dev/ic/nslm7x.c: revision 1.67
sys/dev/ic/nslm7xvar.h: revision 1.33
sys/dev/ic/nslm7x.c: revision 1.68
sys/dev/ic/nslm7x.c: revision 1.69
Add Winbond W83627DHG-P, W83627SF, W83627UHG, W83667HGB, W83687THF, W83697UG,
Nuvoton NCT5104D, NCT610[246]D, NCT6775, NCT6779, NCT6791, NCT6792 and NCT6793.
lm(4): Add support for NCT5104D, NCT610[246]D, NCT6775F, NCT6779D and NCT679[1235]D.
wbsio(4): Add support for NCT6795D.
Add note about Nuvoton.
- Add new Nuvoton devices.
- Add CAVEATS section from OpenBSD.
Add space before left-paren
Remove superfluous Pp.
Whitespace.
Fix a bug that fan RPM wasn't printed correctly. 0xbX is not RPM but counter.
Use 0xcX.
Fix typo.
- Sprinkle static and const. No functional change.
- Print chip ID in hexadecimal instead of octal in def_match().
Use uint8_t instead of int. No functional change.
Print chip name correctly.
- WBSIO_ID_W83627DHG and newer devices have 12bit device ID. So, change sioid
from 8bit to 16bit and check with it strictly.
- s/lm_match/nslm_match/
- split {wb,lm,def}_match() to XXX_match and XXX_attach().
- Rename lm_probe with lm_match and call {wb,nslm,def}_match() at the end of
the function to check strictly.
- NCT610[246]D is different from others, so add new nct6102d_sensors[] table.
- Register offsets of vendor ID and chip id of NCT610[246]D are different
from others. When it failed reading vendor ID or chip ID, fallback to
NCT610[246]D's register offsets.
- Add debug messages.
Restore NetBSD RCS Id which was accidentally removed in rev. 1.2.
s/Id/NetBSD/. Pointed out by wiz!
 1.70.2.2 26-Dec-2018  pgoyette Sync with HEAD, resolve a few conflicts
 1.70.2.1 15-Mar-2018  pgoyette Synch with HEAD
 1.71.2.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.71.2.1 10-Jun-2019  christos Sync with HEAD
 1.73.2.2 19-Jan-2023  martin Pull up following revision(s) (requested by msaitoh in ticket #1568):

share/man/man4/lm.4: revision 1.38
sys/dev/ic/nslm7x.c: revision 1.79
sys/dev/isa/wbsio.c: revision 1.30
sys/dev/isa/wbsioreg.h: revision 1.11

lm(4): Add Nuvoton NCT6797D support.
 1.73.2.1 15-Oct-2022  martin Pull up following revision(s) (requested by msaitoh in ticket #1541):

share/man/man4/lm.4: revision 1.37
sys/dev/isa/wbsio.c: revision 1.28
sys/dev/ic/nslm7x.c: revision 1.78
sys/dev/isa/wbsioreg.h: revision 1.10

Add Nuvoton NCT6799D support.

Add NCT679[89] to the supported list.
 1.34 08-Feb-2018  dholland Typos.
 1.33 18-Aug-2017  msaitoh - WBSIO_ID_W83627DHG and newer devices have 12bit device ID. So, change sioid
from 8bit to 16bit and check with it strictly.
- s/lm_match/nslm_match/
- split {wb,lm,def}_match() to XXX_match and XXX_attach().
- Rename lm_probe with lm_match and call {wb,nslm,def}_match() at the end of
the function to check strictly.
- NCT610[246]D is different from otehrs, so add new nct6102d_sensors[] table.
- Register offsets of vendor ID and chip id of NCT610[246]D are different
from others. When it failed reading vendor ID or chip ID, fallback to
NCT610[246]D's register offsets.
- Add debug messages.
 1.32 17-Aug-2017  msaitoh Use uint8_t instead of int. No functional change.
 1.31 09-Aug-2017  msaitoh - Sprinkle static and const. No functional change.
- Print chip ID in hexadecimal instead of octal in def_match().
 1.30 11-Jul-2017  msaitoh lm(4): Add suport for NCT5174D, NCT6775F, NCT6779D and NCT679[1235]D.
wbsio(4): Add support for NCT6795D.
 1.29 01-Jun-2016  pgoyette branches: 1.29.10;
Add support for Nuvoton NCT6776F from OpenBSD

From PR kern/49747
 1.28 17-Jan-2012  jakllsch branches: 1.28.6; 1.28.24;
Include sysmonvar.h for envsys types.
 1.27 08-Feb-2010  pgoyette branches: 1.27.10; 1.27.14;
Add temp-sensor type selection (via autoconfig flags). Currently only
enabled for W83627HF but easily extended to others if appropriate.

Fixes PR kern-42758
 1.26 12-Oct-2008  pgoyette branches: 1.26.14;
Add an i2c attachment for the LM78 family of temp sensor/fan control

Tested by Martin Husemann
 1.25 28-Apr-2008  martin branches: 1.25.6;
Remove clause 3 and 4 from TNF licenses
 1.24 05-Mar-2008  xtraeme branches: 1.24.2; 1.24.4;
Split device_t/softc in the lm(4) driver and its attachments, and
other related cosmetic changes.
 1.23 16-Nov-2007  xtraeme branches: 1.23.10; 1.23.14;
Extend the envsys2 API (one more time, sorry) as defined in:

http://mail-index.netbsd.org/tech-kern/2007/11/09/0001.html

sysmon_envsys_create() and sysmon_envsys_destroy() were added to
create/destroy sysmon_envsys objects (and its TAILQ/LIST for sensors/events).

sysmon_envsys_sensor_attach() and sysmon_envsys_sensor_detach() were
added to attach/detach sensors to a specified sysmon_envsys device.

The events framework is now per device and configurable via the
ENVSYS_SETDICTIONARY ioctl or /etc/envsys.conf and envstat(8).

Update all users and documentation to reflect these changes.
 1.22 08-Sep-2007  xtraeme branches: 1.22.4; 1.22.6;
- Use a callout(9) to refresh sensor data each 1.5 seconds, respecting
the limit in some LM chips.
- Add the lm_detach() function that stops/destroys the callout and
unregisters the driver from the sysmon_envsys(9) framework.
 1.21 02-Jul-2007  xtraeme branches: 1.21.2; 1.21.6; 1.21.8;
Winbond W83627EHF-A support, from OpenBSD.
 1.20 01-Jul-2007  xtraeme Imported envsys 2, a brief description of the new features:
(Part 2: drivers)

* Support for detachable sensors.
* Cleaned up the API for simplicity and efficiency.
* Ability to send capacity/critical/warning events to powerd(8).
* Adapted all the code to the new locking order.
* Compatibility with the old envsys API: the ENVSYS_GTREINFO
and ENVSYS_GTREDATA ioctl(2)s are supported.
* Added support for a 'dictionary based communication channel' between
sysmon_power(9) and powerd(8), that means there is no 32 bytes event
size restriction anymore.
* Binary compatibility with old envstat(8) and powerd(8) via COMPAT_40.
* All drivers with the n^2 gtredata bug were fixed, PR kern/36226.

Tested by:

blymn: smsc(4).
bouyer: ipmi(4), mfi(4).
kefren: ug(4).
njoly: viaenv(4), adt7463.c.
riz: owtemp(4).
xtraeme: acpiacad(4), acpibat(4), acpitz(4), aiboost(4), it(4), lm(4).
 1.19 11-Mar-2007  xtraeme branches: 1.19.2;
Update for the nslm7x driver:

* For each supported chip, there's a struct lm_sensor array
that specifies the sensor data, like reg, bank, descr, rfact.

* Rather than having 3 functions to setup the voltage, temp and fan
sensors, just have one that will do all the three steps looking at
its struct lm_sensor members, simplifying a lot the code.

and more things that I can remember, our code now is synced with
OpenBSD, IMHO much better to understand and maintain in the future.

Supported chips added with the new code include:

* Winbond: W83627EHF, W83627DHG, W83637HF, W83783S, W83791D, W83791SD,
W83792D.
* Asus AS9912F.

My new mobo with the Winbond W83627DHG chip correctly reports
the values now:

lm0 at isa0 port 0x290-0x297: Winbond W83627DHG Hardware monitor

[juan@nocturno][~]> envstat -r
VCore: 1.232 V
+12V: 12.091 V
+3.3V: 3.264 V
+5V: 4.945 V
VBAT: 3.728 V
System Temp: 36.000 degC
CPU Temp: 29.500 degC
Aux Temp: 22.000 degC
CPU Fan: 1591 RPM
[juan@nocturno][~]>
 1.18 13-May-2006  xtraeme branches: 1.18.12; 1.18.14; 1.18.18;
Remove code for the IT87xxF chipsets, it was included on its own
driver (it(4)).
 1.17 11-Dec-2005  christos branches: 1.17.4; 1.17.6; 1.17.8; 1.17.12;
merge ktrace-lwp.
 1.16 15-Oct-2005  xtraeme Added support for Winbond 83627THF, from OpenBSD.
 1.15 29-Apr-2005  xtraeme branches: 1.15.2;
Identify correctly ITE Super I/O chipsets by checking the core ID
register (only available in the model 8712F), if that fails we check
the vendor ID register as before.
 1.14 27-Feb-2005  perry branches: 1.14.2;
nuke trailing whitespace
 1.13 04-Feb-2005  perry de-__P
 1.12 24-Jul-2004  christos branches: 1.12.4; 1.12.6;
PR/26420: Thilo Manske: lm(4): Add support vor environment controller
built into iTE 8705f
Also: change some memcpy's to strlcpy's and some (0)'s to 0's
 1.11 02-Nov-2003  wiz Fix some typos. From Tom Cosgrove via jmc@openbsd.
 1.10 15-Nov-2002  ad branches: 1.10.6;
Changes for SMBus/I2C:

- Move lm_readreg/lm_writereg into the front-ends. Add/use function pointers
in the softc.
- Add a bank select function pointer to the softc and provide a generic
version. WinBond chips accessed over serial bus present three addresses,
two of which are used to access bank 1/2 registers.
- Mark TSENS2/3 sensor data as invalid if the the corresponding bank select
fails.
 1.9 07-Nov-2002  thorpej Fix signed/unsigned comparison warnings.
 1.8 05-Apr-2002  bouyer Properly identify LM81. From Sergey Svishchev in PR kern/13420.
 1.7 03-Aug-2000  bouyer branches: 1.7.2; 1.7.4; 1.7.6;
Some W83781 have ID 0x11 instead of 0x10; handle these too.
Restore printing sdata for each sensors if DEBUG.
 1.6 02-Aug-2000  bouyer Add support for the W83697HF - basically a W83627HF with only 2 temp sensors.
 1.5 30-Jul-2000  bouyer Add support for the W83781D and W83782D hardware monitors.
 1.4 27-Jul-2000  bouyer Add support for the W83627HF: lm7x like, but with more sensors, and more
registers.
 1.3 24-Jun-2000  thorpej Add a clearing-house pseudo-device for system monitoring devices
such as the LM78 and VT82C686A (and eventually ACPI). Multiple
sensor devices can be hooked registered with `sysmon', and eventually
sysmon will also handle hardware (and software) watchdog timers.

Convert the `lm' and `viaenv' drivers to the new interface.
 1.2 07-Mar-2000  groo branches: 1.2.4;
split probe into generic and bus specific
 1.1 25-Feb-2000  groo Initial import of National Semiconductor LM7[89] Hardware Monitor with isa and
pnpbios attach.

examples:

lm0 at pnpbios0 index?
lm0 at isa? port 0x290


TODO: spinlocks, i2c interface.
 1.2.4.3 04-Aug-2000  bouyer Pull up (approved by jhawk):
share/man/man4/lm.4 1.6->1.8
sys/dev/ic/nslm7x.c 1.7 -> 1.10
sys/dev/ic/nslm7xvar.h 1.5->1.7

Factor out a few things in common functions.
Add support for W83781D, W83782D and W83697HF hardware monitors.
Print sdata for each sensors if DEBUG.
Update doc (W83781D & W83782D tested, W83697HF untested but "should work"
because very close to the W83627HF).
 1.2.4.2 02-Aug-2000  bouyer Pull up (approved by thorpej):
sys/dev/ic/nslm7x.c 1.4->1.7
sys/dev/ic/nslm7xvar.h 1.3->1.5
share/man/man4/lm.4 1.5->1.6

Add support for a few winbond hardware monitors.
 1.2.4.1 30-Jul-2000  bouyer Pull up (requested by thorpej):
lm_pnpbios.c 1.2->1.3
files 1.374->1.375
nslm7x.c 1.3->1.4
nslm7xvar.h 1.2->1.3
lm_isa.c 1.2->1.3
files.pci 1.96->1.97
viaenv.c 1.2->1.3
sysmon.c 1.1
sysmonvar.h 1.1

Add a clearing-house pseudo-device for system monitoring devices
such as the LM78 and VT82C686A (and eventually ACPI). Multiple
sensor devices can be hooked registered with `sysmon', and eventually
sysmon will also handle hardware (and software) watchdog timers.

Convert the `lm' and `viaenv' drivers to the new interface.
 1.7.6.1 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.7.4.3 11-Dec-2002  thorpej Sync with HEAD.
 1.7.4.2 11-Nov-2002  nathanw Catch up to -current
 1.7.4.1 17-Apr-2002  nathanw Catch up to -current.
 1.7.2.2 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.7.2.1 03-Aug-2000  bouyer file nslm7xvar.h was added on branch thorpej_scsipi on 2000-11-20 11:40:50 +0000
 1.10.6.4 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.10.6.3 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.10.6.2 04-Feb-2005  skrll Sync with HEAD.
 1.10.6.1 03-Aug-2004  skrll Sync with HEAD
 1.12.6.2 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.12.6.1 12-Feb-2005  yamt sync with head.
 1.12.4.1 29-Apr-2005  kent sync with -current
 1.14.2.2 15-Oct-2005  riz Pull up following revision(s) (requested by xtraeme in ticket #893):
sys/dev/ic/nslm7x.c: revision 1.23
sys/dev/ic/nslm7xvar.h: revision 1.16
Added support for Winbond 83627THF, from OpenBSD.
 1.14.2.1 01-May-2005  tron Pull up revision 1.15 (requested by xtraeme in ticket #213):
Identify correctly ITE Super I/O chipsets by checking the core ID
register (only available in the model 8712F), if that fails we check
the vendor ID register as before.
 1.15.2.5 17-Mar-2008  yamt sync with head.
 1.15.2.4 07-Dec-2007  yamt sync with head
 1.15.2.3 27-Oct-2007  yamt sync with head.
 1.15.2.2 03-Sep-2007  yamt sync with head.
 1.15.2.1 21-Jun-2006  yamt sync with head.
 1.17.12.1 24-May-2006  tron Merge 2006-05-24 NetBSD-current into the "peter-altq" branch.
 1.17.8.1 24-May-2006  yamt sync with head.
 1.17.6.1 01-Jun-2006  kardel Sync with head.
 1.17.4.1 09-Sep-2006  rpaulo sync with head
 1.18.18.3 09-Oct-2007  ad Sync with head.
 1.18.18.2 15-Jul-2007  ad Sync with head.
 1.18.18.1 13-Mar-2007  ad Sync with head.
 1.18.14.1 12-Mar-2007  rmind Sync with HEAD.
 1.18.12.1 20-Apr-2007  bouyer Pull up following revision(s) (requested by xtraeme in ticket #584):
share/man/man4/lm.4: revisions 1.19 - 1.20
sys/dev/isa/lm_isa.c: revision 1.16 via patch
sys/dev/ic/nslm7xvar.h: revision 1.19
sys/dev/ic/nslm7x.c: revision 1.30 - 1.33 via patch
sync lm(4) with OpenBSD.
Supported chips added with the new code include:
* Winbond: W83627EHF, W83627DHG, W83637HF, W83783S, W83791D, W83791SD,
W83792D.
* Asus AS9912F.
 1.19.2.1 11-Jul-2007  mjf Sync with head.
 1.21.8.3 23-Mar-2008  matt sync with HEAD
 1.21.8.2 09-Jan-2008  matt sync with HEAD
 1.21.8.1 06-Nov-2007  matt sync with HEAD
 1.21.6.2 21-Nov-2007  joerg Sync with HEAD.
 1.21.6.1 02-Oct-2007  joerg Sync with HEAD.
 1.21.2.1 10-Sep-2007  skrll Sync with HEAD.
 1.22.6.1 19-Nov-2007  mjf Sync with HEAD.
 1.22.4.1 18-Nov-2007  bouyer Sync with HEAD
 1.23.14.3 17-Jan-2009  mjf Sync with HEAD.
 1.23.14.2 02-Jun-2008  mjf Sync with HEAD.
 1.23.14.1 03-Apr-2008  mjf Sync with HEAD.
 1.23.10.1 24-Mar-2008  keiichi sync with head.
 1.24.4.3 11-Mar-2010  yamt sync with head
 1.24.4.2 04-May-2009  yamt sync with head.
 1.24.4.1 16-May-2008  yamt sync with head.
 1.24.2.1 18-May-2008  yamt sync with head.
 1.25.6.1 19-Oct-2008  haad Sync with HEAD.
 1.26.14.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.27.14.1 18-Feb-2012  mrg merge to -current.
 1.27.10.1 17-Apr-2012  yamt sync with head
 1.28.24.2 28-Aug-2017  skrll Sync with HEAD
 1.28.24.1 09-Jul-2016  skrll Sync with HEAD
 1.28.6.1 03-Dec-2017  jdolecek update from HEAD
 1.29.10.1 22-Nov-2017  martin Pull up following revision(s) (requested by msaitoh in ticket #374):
share/man/man4/lm.4: revision 1.33
share/man/man4/lm.4: revision 1.34
sys/dev/ic/nslm7x.c: revision 1.70
sys/dev/isa/lm_isa_common.c: revision 1.5
sys/dev/isa/lm_isa_common.c: revision 1.6
sys/dev/isa/wbsio.c: revision 1.11
sys/dev/i2c/lm_i2c.c: revision 1.3
sys/dev/isa/wbsio.c: revision 1.12
sys/dev/i2c/lm_i2c.c: revision 1.4
sys/dev/isa/wbsioreg.h: revision 1.1
sys/dev/isa/wbsio.c: revision 1.13
sys/dev/isa/wbsioreg.h: revision 1.2
sys/dev/isa/wbsio.c: revision 1.14
sys/dev/isa/wbsioreg.h: revision 1.3
sys/dev/isa/wbsio.c: revision 1.15
sys/dev/isa/wbsioreg.h: revision 1.4
sys/dev/isa/wbsioreg.h: revision 1.5
share/man/man4/wbsio.4: revision 1.4
share/man/man4/wbsio.4: revision 1.5
sys/dev/ic/nslm7xvar.h: revision 1.30
sys/dev/ic/nslm7x.c: revision 1.65
share/man/man4/wbsio.4: revision 1.6
sys/dev/ic/nslm7xvar.h: revision 1.31
sys/dev/ic/nslm7x.c: revision 1.66
sys/dev/ic/nslm7xvar.h: revision 1.32
sys/dev/ic/nslm7x.c: revision 1.67
sys/dev/ic/nslm7xvar.h: revision 1.33
sys/dev/ic/nslm7x.c: revision 1.68
sys/dev/ic/nslm7x.c: revision 1.69
Add Winbond W83627DHG-P, W83627SF, W83627UHG, W83667HGB, W83687THF, W83697UG,
Nuvoton NCT5104D, NCT610[246]D, NCT6775, NCT6779, NCT6791, NCT6792 and NCT6793.
lm(4): Add support for NCT5104D, NCT610[246]D, NCT6775F, NCT6779D and NCT679[1235]D.
wbsio(4): Add support for NCT6795D.
Add note about Nuvoton.
- Add new Nuvoton devices.
- Add CAVEATS section from OpenBSD.
Add space before left-paren
Remove superfluous Pp.
Whitespace.
Fix a bug that fan RPM wasn't printed correctly. 0xbX is not RPM but counter.
Use 0xcX.
Fix typo.
- Sprinkle static and const. No functional change.
- Print chip ID in hexadecimal instead of octal in def_match().
Use uint8_t instead of int. No functional change.
Print chip name correctly.
- WBSIO_ID_W83627DHG and newer devices have 12bit device ID. So, change sioid
from 8bit to 16bit and check with it strictly.
- s/lm_match/nslm_match/
- split {wb,lm,def}_match() to XXX_match and XXX_attach().
- Rename lm_probe with lm_match and call {wb,nslm,def}_match() at the end of
the function to check strictly.
- NCT610[246]D is different from others, so add new nct6102d_sensors[] table.
- Register offsets of vendor ID and chip id of NCT610[246]D are different
from others. When it failed reading vendor ID or chip ID, fallback to
NCT610[246]D's register offsets.
- Add debug messages.
Restore NetBSD RCS Id which was accidentally removed in rev. 1.2.
s/Id/NetBSD/. Pointed out by wiz!
 1.69 11-Mar-2024  riastradh nvme(4): Disestablish admin q interrupt while suspended.

And re-establish on resume. Fixes nvmectl(8) after a suspend/resume
cycle on some systems.

Adapted from a patch by mrg@.

PR kern/58025
 1.68 10-Mar-2024  mrg nvme(4): don't write to INTMC register if in intx mode

this matches the handling of INTMS, both of which have the same
restrictions on access in MSI-X mode.

ideally, this register should be written to with a full set of
values for MSI (upto 32 bits), but trying to force MSI mode for
my test machine makes the system unstable.

tested with samsung SM981 256GB, samsung 980 PRO 1TB, and intel
760p 250G.
 1.67 13-Sep-2022  riastradh branches: 1.67.4;
nvme(4): Don't leak memory for queues on every resume.
 1.66 30-Aug-2022  riastradh nvme(4): Actually check if bp is null as commented previously.

I had tested this change, but forgot to amend the commit before
exporting to CVS.
 1.65 30-Aug-2022  riastradh nvme(4): If bp is null or bp->b_ci is not assigned, use curcpu().

curcpu() might be stale by the time we're done, but it's still safe
to pass it to cpu_index, and this is just used as a best-effort
mechanism to keep I/O on queues handled by the same CPU.

bp is not always provided, and bp->b_ci is not always assigned,
e.g. when dumping. (If bp->b_ci is supposed to be always assigned,
then we need to audit all the paths into it to assign it in those
where it's not.)

Fixes dump on nvme.
 1.64 20-Aug-2022  riastradh nvme(4): Read cqe flags and cid in that order.
 1.63 15-Aug-2022  riastradh nvme(4): KASSERT(A && B) -> KASSERT(A); KASSERT(B)
 1.62 14-Aug-2022  jmcneill nvme: Make sure that q_ccb_list is always accessed with the q lock held.
 1.61 31-Jul-2022  mlelstv The namespace id is a 32bit value, in particular the "all namespaces" value
for global commands is 0xffffffff. While the driver only supports 16bit
numbers (device minor & 0xffff), we need to use the full value for pass
through commands.

This fixes e.g. logpage requests on the controller level.
 1.60 07-May-2022  skrll Add support for Apple silicon NVME. Ported from OpenBSD.
 1.59 16-Nov-2021  skrll Trailing whitespace
 1.58 07-Aug-2021  thorpej Merge thorpej-cfargs2.
 1.57 29-May-2021  riastradh branches: 1.57.4;
nvme(4): Move disestablishment of admin q interrupt to nvme_detach.

Nothing re-established this after suspend/resume, so attempting
suspend/resume/suspend would crash, and presumably we would miss
interrupts after resume. This keeps the establish/disestablish more
symmetric in attach/detach.
 1.56 29-May-2021  riastradh nvme(4): Add suspend/resume, derived from OpenBSD.
 1.55 24-Apr-2021  thorpej branches: 1.55.2; 1.55.4;
Merge thorpej-cfargs branch:

Simplify and make extensible the config_search() / config_found() /
config_attach() interfaces: rather than having different variants for
which arguments you want pass along, just have a single call that
takes a variadic list of tag-value arguments.

Adjust all call sites:
- Simplify wherever possible; don't pass along arguments that aren't
actually needed.
- Don't be explicit about what interface attribute is attaching if
the device only has one. (More simplification.)
- Add a config_probe() function to be used in indirect configuiration
situations, making is visibly easier to see when indirect config is
in play, and allowing for future change in semantics. (As of now,
this is just a wrapper around config_match(), but that is an
implementation detail.)

Remove unnecessary or redundant interface attributes where they're not
needed.

There are currently 5 "cfargs" defined:
- CFARG_SUBMATCH (submatch function for direct config)
- CFARG_SEARCH (search function for indirect config)
- CFARG_IATTR (interface attribte)
- CFARG_LOCATORS (locators array)
- CFARG_DEVHANDLE (devhandle_t - wraps OFW, ACPI, etc. handles)

...and a sentinel value CFARG_EOL.

Add some extra sanity checking to ensure that interface attributes
aren't ambiguous.

Use CFARG_DEVHANDLE in MI FDT, OFW, and ACPI code, and macppc and shark
ports to associate those device handles with device_t instance. This
will trickle trough to more places over time (need back-end for pre-OFW
Sun OBP; any others?).
 1.54 27-Dec-2020  jmcneill branches: 1.54.2;
Zero DMA memory after load, and add PREREAD sync op after to ensure it is visible
 1.53 04-Dec-2020  kardel PR kern/55839:
handle multiple nvme_rescan()s correctly by doing the
name-space identify only once per nsid.

fixes issue where modloading triggers multiple
rescans.
 1.52 10-Nov-2020  rin One more fix for big-endian machines.

Now, ld(4) at nvme(4) works perfectly for aarch64eb!

Tested on ROCKPro64 and qemu-system-aarch64.
 1.51 24-Sep-2020  ryo branches: 1.51.2;
no need to swap pt.cmd.cdwXX at nvme_set_number_of_queues(). cmd.cdwXX will be swapped in nvme_pt_fill().
 1.50 22-Sep-2020  kardel PR kern/55674:
move name space availability check from ld_nvme.c:ld_nvme_attach()
to nvme.c:nvme_rescan().
this avoids allocation of ld(4) instances for every possible
name space, even if it is not usable. it also reduces the device
node flood generated from that strategy.
 1.49 28-Jul-2020  jdolecek say what is not configured in nvme_print()
 1.48 07-Apr-2020  ryo avoid "panic: LOCKDEBUG: Mutex error: rw_vector_enter,309: spin lock held"

ok nonaka@. thanks
 1.47 11-Nov-2019  nonaka nvme(4): Use the SET_FEATURES command to get the number of allocated queues.
 1.46 26-Sep-2019  nonaka nvme(4): Don't attach the device, if namespace not found.
 1.45 20-Sep-2019  nonaka Don't set Phase Tag bit of Completion Queue entry at nvme_poll_done().

A new completion queue entry check incorrectly determined that there was
a Completion Queue entry for a command that was not submitted.

Fix PR kern/54275, PR kern/54503, PR kern/54532.
 1.44 28-Jun-2019  jmcneill branches: 1.44.2;
Fix a performance issue where one busy queue can starve all other queues.

In normal operations with multiple queues, the nvme driver will attempt
to schedule I/O requests on the submitting CPU. This breaks down when any
one of the queues becomes full; the driver returns EAGAIN to the disk
layer, which causes the disk layer to stop submitting more requests until
the blocked request is consumed. When space becomes available in the full
queue, it pulls the next buffer from the bufq and fills the queue again,
until finally hitting EAGAIN and preventing other queues from processing
requests.

Two changes here to fix the problem:

- When processing requests from the bufq, attempt to assign them to the
queue associated with the CPU that originated the request.
- If that queue is busy, try to find another queue with available space
before returning EAGAIN. This way, only when all queues are full will
the disk layer stop submitting more requests.

Now for some real numbers. On a Rockchip RK3399 board (6 CPUs), with 6
concurrent readers:

Old code:
4294967296 bytes transferred in 52.420 secs (81933752 bytes/sec)
4294967296 bytes transferred in 53.969 secs (79582117 bytes/sec)
4294967296 bytes transferred in 55.391 secs (77539082 bytes/sec)
4294967296 bytes transferred in 55.649 secs (77179595 bytes/sec)
4294967296 bytes transferred in 56.102 secs (76556402 bytes/sec)
4294967296 bytes transferred in 72.901 secs (58915066 bytes/sec)

New code:
4294967296 bytes transferred in 37.171 secs (115546186 bytes/sec)
4294967296 bytes transferred in 37.611 secs (114194445 bytes/sec)
4294967296 bytes transferred in 37.655 secs (114061009 bytes/sec)
4294967296 bytes transferred in 38.247 secs (112295534 bytes/sec)
4294967296 bytes transferred in 38.496 secs (111569183 bytes/sec)
4294967296 bytes transferred in 38.595 secs (111282997 bytes/sec)
 1.43 14-Jun-2019  mrg in nvme_attach() when creating the admin queue to probe the device info,
and also in nvme_dmamem_alloc(), allow as many DMA segment as would be
maximally needed for the size, rather than hard coding '2' for the form
and '1' for the latter.

now ld@nvme on i386 doesn't crash and i see at least 1.3GB/sec.
 1.42 24-Apr-2019  mlelstv Expose device type. You can query it with e.g. drvctl -p ld0 disk-info/type.
 1.41 01-Dec-2018  jdolecek support DIOCSCACHE + DKCACHE_WRITE if volatile write cache is present

fix the Get Features call for DIOCGCACHE to actually retrieve the current
value properly
 1.40 01-Dec-2018  jdolecek disestablish the interrupt on failure in nvme_q_create()
 1.39 18-Apr-2018  nonaka branches: 1.39.2;
nvmectl(8): Add big-endian support.

from FreeBSD nvmecontolr(8) r329824.
 1.38 18-Apr-2018  nonaka nvme(4): Added some delay before check RDY bit quirk when disabling device.

Pick from FreeBSD nvme(4) r326937.
 1.37 17-Mar-2018  jdolecek also remove now duplicate nvme_ccb_put() call from nvme_get_number_of_queues()
 1.36 17-Mar-2018  jdolecek fix passthrough command usage also in nvme_get_number_of_queues(), fixes
memory corruption and possible panic on boot

PR kern/53059
 1.35 17-Mar-2018  jdolecek switch handling of passthrough commands to use queue, instead of polling

should fix PR kern/53059 by Frank Kardel
 1.34 16-Mar-2018  jdolecek refactor the locking code around DIOCGCACHE handling to be reusable
for other infrequent commands

it uses single condvar for simplicity, and uses it both when waiting
for ccb or command completion - this is fine, since usually there
will be just one such command qeueued anyway

use this to finally properly implement DIOCCACHESYNC - return only after
the command is confirmed as completed by the controller
 1.33 16-Mar-2018  jdolecek stop using q_nccbs_avail for deciding whether there are available ccbs;
no need to maintain a counter _and_ q_ccb_list

this fixes deadlock when all ccbs happen to be taken before completion
interrupt - nvme_q_complete() increased q_nccbs_avail only after
processing all the completed commands, by then there was nothing
left to actually kick the disk queue again into action

this also fixes ccb leak on command errors e.g. with bus_dmamem_alloc()
or bus_dmamel_load() - q_nccbs_avail was never decreased on the error path

fixes PR kern/52769 by Martin Husemann, thanks to Paul Goyette
for testing
 1.32 27-Feb-2018  christos branches: 1.32.2;
- don't leak ccb on alloc failure.
- KASSERT to prevent memory leak.
 1.31 28-Oct-2017  riastradh branches: 1.31.2;
Kill some more extern struct cfdriver declarations.

Down with externs in .c!
 1.30 01-Jun-2017  chs branches: 1.30.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.
 1.29 29-May-2017  nonaka nvme(4): Don't set prp1 for DEL_IOCQ

> NVM_ADMIN_DEL_IOCQ does not need prp1 (just as NVM_ADMIN_DEL_IOSQ).
> Remove what is likely a cut'n'paste error from the *_ADD_* code.

from OpenBSD nvme.c r1.56.
 1.28 29-May-2017  nonaka nvme(4): Do not use bus_space_{read,write}_8() even on LP64 archs.

> some (broken) controllers require ordered split transfers.
> From linux a310acd7a7ea53533886c11bb7edd11ffd61a036

from OpenBSD nvme.c r1.53.
 1.27 29-May-2017  nonaka nvme(4): Mask non relevant bits when pritting version number.

from OpenBSD nvme.c r1.52.
 1.26 05-Apr-2017  jdolecek branches: 1.26.4;
expose disk device FUA/DPO support via DIOCGCACHE, and allow the flags
to be set for I/O; implement support in sd(4) and nvme(4)

discussed on tech-kern
 1.25 28-Feb-2017  jdolecek implement DIOCGCACHE
 1.24 13-Feb-2017  nonaka NVMe 1.2.1
 1.23 13-Feb-2017  nonaka nvme(4): Limit the number of queues to the number allocated in HW.
 1.22 01-Nov-2016  jdolecek branches: 1.22.2;
reduce admin queue size to save memory; it's only ever used during
attach/detach and for nvmectl(8), so there is actually no point having it big
 1.21 01-Nov-2016  jdolecek pass maxphys from device rather then assuming MAXPHYS; it's clipped in ld(4)
if bigger then MAXPHYS

multiply the queue size by number of queues for ld(4) sc_maxqueuecnt, so
that ld_diskstart() would try to use full capacity, instead of throttling
to one queue worth of commands
 1.20 01-Nov-2016  jdolecek tighter queue control - according to spec actual cap on number of commands
in flight is actually one less then queue size, head == tail means empty
queue
 1.19 20-Oct-2016  jdolecek revert change from rev. 1.12:
"""
slightly optimize memory access - change struct nvme_queue so that the
struct dmamem members are allocated as part of it, instead of separate
kmem_alloc()s
"""

that change quite curiously caused completion queue corruption on MP systems,
regardless of MPSAFE setting for the pci/softintr interrupt
 1.18 19-Oct-2016  jdolecek add debug code to check for completion queue corruption
 1.17 19-Oct-2016  jdolecek follow advice of spec and block interrupts via INTMS/INTMC for intx handler;
this also makes it possible to offload the actual interrupt processing to softintr
handler, similar as for MSI/MSI-X
 1.16 18-Oct-2016  nonaka fix a sync range size when number of bus_dma segment is greater than 2.
 1.15 05-Oct-2016  nonaka The maximum number of IO queue entries is hardware supported value.
 1.14 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).
 1.13 20-Sep-2016  jdolecek cache flush call must wait for completion; cap wait to 60 seconds just in case
controller won't respond
 1.12 19-Sep-2016  jdolecek slightly optimize memory access - change struct nvme_queue so that the
struct dmamem members are allocated as part of it, instead of separate
kmem_alloc()s
 1.11 19-Sep-2016  jdolecek on further thought, just remove the separately allocated nvme_ns_context
altogether and fold into nvme_ccb; allocating this separately just isn't useful
 1.10 19-Sep-2016  jdolecek comment tyop and KNF; pointed out by Nick
 1.9 18-Sep-2016  jdolecek fix several bugs, make nvme(4) MPSAFE by default and also bump default
number of ioq from 128 to 1024; tested with VirtualBox and QEMU

* remove NVME_INTMC/NVME_INTMS writes in hw intr handler as this is not MPSAFE,
fortunately they don't seem to be necessary; shaves two register writes
* need to use full mutex_enter() in nvme_q_complete(), to avoid small
race between one handler exiting the loop and another entering
* for MSI, handover the command result processing to softintr; unfortunately
can't easily do that for INTx interrupts as they require doorbell write
to deassert
* unlock/relock q->q_cq_mtx before calling ccb_done to avoid potential deadlocks
* make sure to destroy queue mutexes when destroying the queue (LOCKDEBUG)
* make ns ctx pool per-device, so that it's deallocated properly on module
unload
* handle ctx allocation failure in ld_nvme_dobio()
* remove splbio() calls in ld_nvme_dobio() and sync, the paths are exercised
only for dump/shutdown, and that already disables interrupts
* free the ns ctx in ld_nvme_biodone() before calling lddone() to avoid
memory starvation, as lddone() can trigger another i/o request
* be more careful with using PR_WAITOK, the paths are called from interrupt
context and there we can't wait
 1.8 17-Sep-2016  jdolecek make nvme_dumpregs() compile on LP64 hosts

sprinkle some delays() and extra checks into attach code, so that it follows
more closely what FreeBSD driver does, and is easier to cross-check
 1.7 16-Sep-2016  jdolecek introduce optional timeout for the polled commands; currently 5 seconds for
queue creation/deletion, 10 seconds for controller/namespace identify,
and unlimited for cache sync and passthrough commands

this makes device attach error out instead of hanging the kernel when
the device fails to respond properly, such as under QEMU currently
 1.6 16-Sep-2016  jdolecek make nvme_dumpregs() compile when NVME_DEBUG is defined
 1.5 08-Sep-2016  nonaka Fix to cannnot be opened a nvme(4) namespace device file.
 1.4 08-Sep-2016  nonaka fix off-by-one error in namespace id range check.
 1.3 04-Jun-2016  nonaka branches: 1.3.2;
Add NVMe command passthrough support.
 1.2 02-May-2016  christos branches: 1.2.2;
move scsipi_strvis -> libkern:strnvisx()
change the prototype to match userland
fix sizes of strings passed to it
 1.1 01-May-2016  nonaka Added nvme(4) for Non-Volatile Memory Host Controller Interface devices.
Ported from OpenBSD.
 1.2.2.6 28-Aug-2017  skrll Sync with HEAD
 1.2.2.5 05-Dec-2016  skrll Sync with HEAD
 1.2.2.4 05-Oct-2016  skrll Sync with HEAD
 1.2.2.3 09-Jul-2016  skrll Sync with HEAD
 1.2.2.2 29-May-2016  skrll Sync with HEAD
 1.2.2.1 02-May-2016  skrll file nvme.c was added on branch nick-nhusb on 2016-05-29 08:44:21 +0000
 1.3.2.3 26-Apr-2017  pgoyette Sync with HEAD
 1.3.2.2 20-Mar-2017  pgoyette Sync with HEAD
 1.3.2.1 04-Nov-2016  pgoyette Sync with HEAD
 1.22.2.1 21-Apr-2017  bouyer Sync with HEAD
 1.26.4.1 30-Apr-2017  pgoyette And a few more DEVSW_MODULE_INIT for modular drivers
 1.30.2.9 07-Dec-2020  martin Pull up following revision(s) (requested by kardel in ticket #1633):

sys/dev/ic/nvme.c: revision 1.53

PR kern/55839:

handle multiple nvme_rescan()s correctly by doing the
name-space identify only once per nsid.
fixes issue where modloading triggers multiple
rescans.
 1.30.2.8 27-Sep-2020  martin Pull up following revision(s) (requested by kardel in ticket #1610):

sys/dev/ic/ld_nvme.c: revision 1.24 (patch)
sys/dev/ic/nvme.c: revision 1.50 (patch)

PR kern/55674:
move name space availability check from ld_nvme.c:ld_nvme_attach()
to nvme.c:nvme_rescan().
this avoids allocation of ld(4) instances for every possible
name space, even if it is not usable. it also reduces the device
node flood generated from that strategy.
 1.30.2.7 11-Nov-2019  martin Pull up following revision(s) (requested by nonaka in ticket #1432):

sys/dev/ic/nvme.c: revision 1.47

nvme(4): Use the SET_FEATURES command to get the number of allocated queues.
 1.30.2.6 26-Sep-2019  martin Pull up following revision(s) (requested by nonaka in ticket #1390):

sys/dev/ic/nvme.c: revision 1.46

nvme(4): Don't attach the device, if namespace not found.
 1.30.2.5 25-Sep-2019  martin Pull up following revision(s) (requested by nonaka in ticket #1386):

sys/dev/ic/nvme.c: revision 1.45

Don't set Phase Tag bit of Completion Queue entry at nvme_poll_done().

A new completion queue entry check incorrectly determined that there was
a Completion Queue entry for a command that was not submitted.

Fix PR kern/54275, PR kern/54503, PR kern/54532.
 1.30.2.4 19-Apr-2018  martin Pull up following revision(s) (requested by nonaka in ticket #781):

sbin/nvmectl/Makefile 1.4
sbin/nvmectl/bignum.c 1.2
sbin/nvmectl/devlist.c 1.3-1.5
sbin/nvmectl/firmware.c 1.3,1.4
sbin/nvmectl/identify.c 1.3-1.5
sbin/nvmectl/logpage.c 1.5-1.7
sbin/nvmectl/nvme.h 1.3
sbin/nvmectl/nvmectl.8 1.5
sbin/nvmectl/nvmectl.c 1.5-1.7
sbin/nvmectl/nvmectl.h 1.5-1.8
sbin/nvmectl/perftest.c 1.3-1.5
sbin/nvmectl/power.c 1.3,1.4
sbin/nvmectl/reset.c 1.2,1.3
sbin/nvmectl/util.c 1.1,1.2
sbin/nvmectl/wdc.c 1.2-1.4
sys/dev/ic/ld_nvme.c 1.20
sys/dev/ic/nvme.c 1.38,1.39
sys/dev/ic/nvmeio.h 1.2
sys/dev/ic/nvmereg.h 1.10,1.11
sys/dev/ic/nvmevar.h 1.16
sys/dev/pci/nvme_pci.c 1.20

nvmectl(8): Sync with FreeBSD nvmecontrol(8) r328763.

nvmectl(8): fix wdc command usage.

nvme(4): Added some delay before check RDY bit quirk when disabling device.
Pick from FreeBSD nvme(4) r326937.

Add some new structure fileds, opcodes and statuses from NVMe 1.3a.

nvmectl(8): Add big-endian support.
from FreeBSD nvmecontolr(8) r329824.

nvmectl(8): fix subcommand usage.

nvmectl(8): Remove some wdc subcommands from man page.
- wdc drive-log
- wdc get-crash-dump
- wdc purge
- wdc purge-monitor

Typos.

use setprogname()/getprogname(), do not hardcode the prognam name in fixed
strings
 1.30.2.3 09-Apr-2018  bouyer Pull up following revision(s) (requested by msaitoh in ticket #718):
sys/dev/ic/nvme.c: revision 1.32
- don't leak ccb on alloc failure.
- KASSERT to prevent memory leak.
 1.30.2.2 18-Mar-2018  martin Pull up following revision(s) (requested by jdolecek in ticket #641):
sys/dev/ic/nvme.c: revision 1.34
sys/dev/ic/nvme.c: revision 1.35
sys/dev/ic/nvme.c: revision 1.36
sys/dev/ic/nvme.c: revision 1.37
sys/dev/ic/ld_nvme.c: revision 1.19
sys/dev/ic/nvmevar.h: revision 1.15

refactor the locking code around DIOCGCACHE handling to be reusable
for other infrequent commands,it uses single condvar for simplicity,
and uses it both when waiting for ccb or command completion - this
is fine, since usually there will be just one such command qeueued anyway
use this to finally properly implement DIOCCACHESYNC - return only after
the command is confirmed as completed by the controller.

switch handling of passthrough commands to use queue, instead of polling
should fix PR kern/53059 by Frank Kardel

fix passthrough command usage also in nvme_get_number_of_queues(), fixes
memory corruption and possible panic on boot

also remove now duplicate nvme_ccb_put() call from
nvme_get_number_of_queues()
 1.30.2.1 17-Mar-2018  martin Pull up following revision(s) (requested by jdolecek in ticket #636):
sys/dev/ic/nvme.c: revision 1.33
sys/dev/ic/nvmevar.h: revision 1.14
stop using q_nccbs_avail for deciding whether there are available ccbs;
no need to maintain a counter _and_ q_ccb_list
this fixes deadlock when all ccbs happen to be taken before completion
interrupt - nvme_q_complete() increased q_nccbs_avail only after
processing all the completed commands, by then there was nothing
left to actually kick the disk queue again into action
this also fixes ccb leak on command errors e.g. with bus_dmamem_alloc()
or bus_dmamel_load() - q_nccbs_avail was never decreased on the error path
fixes PR kern/52769 by Martin Husemann, thanks to Paul Goyette
for testing
 1.31.2.2 03-Dec-2017  jdolecek update from HEAD
 1.31.2.1 28-Oct-2017  jdolecek file nvme.c was added on branch tls-maxphys on 2017-12-03 11:37:03 +0000
 1.32.2.3 26-Dec-2018  pgoyette Sync with HEAD, resolve a few conflicts
 1.32.2.2 22-Apr-2018  pgoyette Sync with HEAD
 1.32.2.1 22-Mar-2018  pgoyette Synch with HEAD, resolve conflicts
 1.39.2.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.39.2.1 10-Jun-2019  christos Sync with HEAD
 1.44.2.7 12-Mar-2024  martin Pull up following revision(s) (requested by riastradh in ticket #1817):

sys/dev/ic/nvme.c: revision 1.69

nvme(4): Disestablish admin q interrupt while suspended.

And re-establish on resume. Fixes nvmectl(8) after a suspend/resume
cycle on some systems.

Adapted from a patch by mrg@.

PR kern/58025
 1.44.2.6 21-Jun-2021  martin Pull up following revision(s) (requested by riastradh in ticket #1305):

sys/dev/ic/nvmevar.h: revision 1.22
sys/dev/ic/nvme.c: revision 1.56
sys/dev/ic/nvme.c: revision 1.57
sys/dev/pci/nvme_pci.c: revision 1.30

nvme(4): Add suspend/resume, derived from OpenBSD.

nvme(4): Move disestablishment of admin q interrupt to nvme_detach.

Nothing re-established this after suspend/resume, so attempting
suspend/resume/suspend would crash, and presumably we would miss
interrupts after resume. This keeps the establish/disestablish more
symmetric in attach/detach.
 1.44.2.5 07-Dec-2020  martin Pull up following revision(s) (requested by kardel in ticket #1144):

sys/dev/ic/nvme.c: revision 1.53

PR kern/55839:

handle multiple nvme_rescan()s correctly by doing the
name-space identify only once per nsid.
fixes issue where modloading triggers multiple
rescans.
 1.44.2.4 27-Sep-2020  martin Pull up following revision(s) (requested by kardel in ticket #1094):

sys/dev/ic/ld_nvme.c: revision 1.24
sys/dev/ic/nvme.c: revision 1.50

PR kern/55674:
move name space availability check from ld_nvme.c:ld_nvme_attach()
to nvme.c:nvme_rescan().
this avoids allocation of ld(4) instances for every possible
name space, even if it is not usable. it also reduces the device
node flood generated from that strategy.
 1.44.2.3 11-Nov-2019  martin Pull up following revision(s) (requested by nonaka in ticket #415):

sys/dev/ic/nvme.c: revision 1.47

nvme(4): Use the SET_FEATURES command to get the number of allocated queues.
 1.44.2.2 26-Sep-2019  martin Pull up following revision(s) (requested by nonaka in ticket #248):

sys/dev/ic/nvme.c: revision 1.46

nvme(4): Don't attach the device, if namespace not found.
 1.44.2.1 22-Sep-2019  martin Pull up following revision(s) (requested by nonaka in ticket #218):

sys/dev/ic/nvme.c: revision 1.45

Don't set Phase Tag bit of Completion Queue entry at nvme_poll_done().

A new completion queue entry check incorrectly determined that there was
a Completion Queue entry for a command that was not submitted.

Fix PR kern/54275, PR kern/54503, PR kern/54532.
 1.51.2.2 03-Jan-2021  thorpej Sync w/ HEAD.
 1.51.2.1 14-Dec-2020  thorpej Sync w/ HEAD.
 1.54.2.2 28-Mar-2021  thorpej - In nvme_rescan(), pass the locators used for matching to config_found()
and use config_stdsubmatch().
- No need to be explicit about interface attribute, because we carry
only one.
 1.54.2.1 21-Mar-2021  thorpej Give config_found() the same variadic arguments treatment as
config_search(). This commit only adds the CFARG_EOL sentinel
to the existing config_found() calls. Conversion of config_found_sm_loc()
and config_found_ia() call sites will be in subsequent commits.
 1.55.4.1 31-May-2021  cjep sync with head
 1.55.2.1 17-Jun-2021  thorpej Sync w/ HEAD.
 1.57.4.1 04-Aug-2021  thorpej Adapt to CFARGS().
 1.67.4.1 12-Mar-2024  martin Pull up following revision(s) (requested by riastradh in ticket #633):

sys/dev/ic/nvme.c: revision 1.69

nvme(4): Disestablish admin q interrupt while suspended.

And re-establish on resume. Fixes nvmectl(8) after a suspend/resume
cycle on some systems.

Adapted from a patch by mrg@.

PR kern/58025
 1.4 10-Nov-2021  msaitoh s/endianess/endianness/
 1.3 19-Apr-2018  christos s/static inline/static __inline/g for consistency.
 1.2 18-Apr-2018  nonaka nvmectl(8): Add big-endian support.

from FreeBSD nvmecontolr(8) r329824.
 1.1 04-Jun-2016  nonaka branches: 1.1.2; 1.1.12; 1.1.18; 1.1.20;
Add NVMe command passthrough support.
 1.1.20.1 22-Apr-2018  pgoyette Sync with HEAD
 1.1.18.2 03-Dec-2017  jdolecek update from HEAD
 1.1.18.1 04-Jun-2016  jdolecek file nvmeio.h was added on branch tls-maxphys on 2017-12-03 11:37:03 +0000
 1.1.12.1 19-Apr-2018  martin Pull up following revision(s) (requested by nonaka in ticket #781):

sbin/nvmectl/Makefile 1.4
sbin/nvmectl/bignum.c 1.2
sbin/nvmectl/devlist.c 1.3-1.5
sbin/nvmectl/firmware.c 1.3,1.4
sbin/nvmectl/identify.c 1.3-1.5
sbin/nvmectl/logpage.c 1.5-1.7
sbin/nvmectl/nvme.h 1.3
sbin/nvmectl/nvmectl.8 1.5
sbin/nvmectl/nvmectl.c 1.5-1.7
sbin/nvmectl/nvmectl.h 1.5-1.8
sbin/nvmectl/perftest.c 1.3-1.5
sbin/nvmectl/power.c 1.3,1.4
sbin/nvmectl/reset.c 1.2,1.3
sbin/nvmectl/util.c 1.1,1.2
sbin/nvmectl/wdc.c 1.2-1.4
sys/dev/ic/ld_nvme.c 1.20
sys/dev/ic/nvme.c 1.38,1.39
sys/dev/ic/nvmeio.h 1.2
sys/dev/ic/nvmereg.h 1.10,1.11
sys/dev/ic/nvmevar.h 1.16
sys/dev/pci/nvme_pci.c 1.20

nvmectl(8): Sync with FreeBSD nvmecontrol(8) r328763.

nvmectl(8): fix wdc command usage.

nvme(4): Added some delay before check RDY bit quirk when disabling device.
Pick from FreeBSD nvme(4) r326937.

Add some new structure fileds, opcodes and statuses from NVMe 1.3a.

nvmectl(8): Add big-endian support.
from FreeBSD nvmecontolr(8) r329824.

nvmectl(8): fix subcommand usage.

nvmectl(8): Remove some wdc subcommands from man page.
- wdc drive-log
- wdc get-crash-dump
- wdc purge
- wdc purge-monitor

Typos.

use setprogname()/getprogname(), do not hardcode the prognam name in fixed
strings
 1.1.2.2 09-Jul-2016  skrll Sync with HEAD
 1.1.2.1 04-Jun-2016  skrll file nvmeio.h was added on branch nick-nhusb on 2016-07-09 20:25:02 +0000
 1.19 12-Oct-2022  andvar fix few typos in comments.
 1.18 01-Aug-2022  mlelstv Also fix shift values for SCT constants.
 1.17 31-Jul-2022  mlelstv The status is an 8 bit field. Fix masks and move the status type field
to the correct bit position.
 1.16 14-Nov-2021  skrll Use BITS(3) some more. Same nvme.o before and after.
 1.15 27-Sep-2020  jdolecek add definition of the bit indicating support for APSTA
 1.14 05-Oct-2019  mrg remove __packed attribute from struct ieee80211_radiotap_header
and all the structures that include it.

this should not change anything while avoiding packed vs alignment
warnings from GCC 8, and potentially pessimised code generation
due to the packed marker (there are no misaligned members, just
that the per-device parts may end unaligned.)

all consumers of these members are done from the properly aligned
packet members directly, or, as a union with a 64 byte member,
also properly aligned. codegen didn't appear to change, except
for the definition of sizeof(struct driver_[rt]x_radiotap_header)
in debug info, which is not directly used anywhere.
 1.13 01-Dec-2018  jdolecek rename NVME_ID_CTRLR_ONCS_SAVE back to NVME_ID_CTRLR_ONCS_SET_FEATURES;
it's actually used in nvmectl sources too, and while 'Save' is more
correct it's not complete either, so better to leseen churn -
according to spec it's support for 'Save' for Set Features, and
support for 'Select' for Get Features
 1.12 01-Dec-2018  jdolecek support DIOCSCACHE + DKCACHE_WRITE if volatile write cache is present

fix the Get Features call for DIOCGCACHE to actually retrieve the current
value properly
 1.11 18-Apr-2018  nonaka branches: 1.11.2;
Add some new structure fileds, opcodes and statuses from NVMe 1.3a.
 1.10 17-Apr-2018  nonaka nvmectl(8): Sync with FreeBSD nvmecontrol(8) r328763.
 1.9 29-May-2017  nonaka branches: 1.9.2; 1.9.8; 1.9.10;
nvme(4): Mask non relevant bits when pritting version number.

from OpenBSD nvme.c r1.52.
 1.8 28-Feb-2017  jdolecek implement DIOCGCACHE
 1.7 13-Feb-2017  nonaka NVMe 1.2.1
 1.6 08-Oct-2016  jdolecek branches: 1.6.2;
add defines for dataset management (from NVMe spec rev 1.2)
 1.5 17-Sep-2016  jdolecek add macros to read AQA subvalues, is used by nvme_dumpregs()
 1.4 16-Sep-2016  jdolecek add IO flags for FUA and also LR while here
 1.3 04-Jun-2016  nonaka branches: 1.3.2;
nvmectl(8): Added NVM Express control utility.

Ported from FreeBSD nvmecontrol(8).
 1.2 04-Jun-2016  nonaka Add NVMe command passthrough support.
 1.1 01-May-2016  nonaka branches: 1.1.2;
Added nvme(4) for Non-Volatile Memory Host Controller Interface devices.
Ported from OpenBSD.
 1.1.2.6 28-Aug-2017  skrll Sync with HEAD
 1.1.2.5 05-Dec-2016  skrll Sync with HEAD
 1.1.2.4 05-Oct-2016  skrll Sync with HEAD
 1.1.2.3 09-Jul-2016  skrll Sync with HEAD
 1.1.2.2 29-May-2016  skrll Sync with HEAD
 1.1.2.1 01-May-2016  skrll file nvmereg.h was added on branch nick-nhusb on 2016-05-29 08:44:21 +0000
 1.3.2.2 20-Mar-2017  pgoyette Sync with HEAD
 1.3.2.1 04-Nov-2016  pgoyette Sync with HEAD
 1.6.2.1 21-Apr-2017  bouyer Sync with HEAD
 1.9.10.2 26-Dec-2018  pgoyette Sync with HEAD, resolve a few conflicts
 1.9.10.1 22-Apr-2018  pgoyette Sync with HEAD
 1.9.8.2 03-Dec-2017  jdolecek update from HEAD
 1.9.8.1 29-May-2017  jdolecek file nvmereg.h was added on branch tls-maxphys on 2017-12-03 11:37:03 +0000
 1.9.2.1 19-Apr-2018  martin Pull up following revision(s) (requested by nonaka in ticket #781):

sbin/nvmectl/Makefile 1.4
sbin/nvmectl/bignum.c 1.2
sbin/nvmectl/devlist.c 1.3-1.5
sbin/nvmectl/firmware.c 1.3,1.4
sbin/nvmectl/identify.c 1.3-1.5
sbin/nvmectl/logpage.c 1.5-1.7
sbin/nvmectl/nvme.h 1.3
sbin/nvmectl/nvmectl.8 1.5
sbin/nvmectl/nvmectl.c 1.5-1.7
sbin/nvmectl/nvmectl.h 1.5-1.8
sbin/nvmectl/perftest.c 1.3-1.5
sbin/nvmectl/power.c 1.3,1.4
sbin/nvmectl/reset.c 1.2,1.3
sbin/nvmectl/util.c 1.1,1.2
sbin/nvmectl/wdc.c 1.2-1.4
sys/dev/ic/ld_nvme.c 1.20
sys/dev/ic/nvme.c 1.38,1.39
sys/dev/ic/nvmeio.h 1.2
sys/dev/ic/nvmereg.h 1.10,1.11
sys/dev/ic/nvmevar.h 1.16
sys/dev/pci/nvme_pci.c 1.20

nvmectl(8): Sync with FreeBSD nvmecontrol(8) r328763.

nvmectl(8): fix wdc command usage.

nvme(4): Added some delay before check RDY bit quirk when disabling device.
Pick from FreeBSD nvme(4) r326937.

Add some new structure fileds, opcodes and statuses from NVMe 1.3a.

nvmectl(8): Add big-endian support.
from FreeBSD nvmecontolr(8) r329824.

nvmectl(8): fix subcommand usage.

nvmectl(8): Remove some wdc subcommands from man page.
- wdc drive-log
- wdc get-crash-dump
- wdc purge
- wdc purge-monitor

Typos.

use setprogname()/getprogname(), do not hardcode the prognam name in fixed
strings
 1.11.2.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.11.2.1 10-Jun-2019  christos Sync with HEAD
 1.28 14-Aug-2022  jmcneill nvme: Make sure that q_ccb_list is always accessed with the q lock held.
 1.27 01-Aug-2022  mlelstv Now really restore 1.24.
 1.26 01-Aug-2022  mlelstv Revert last accidental commits.
 1.25 01-Aug-2022  mlelstv Also fix shift values for SCT constants.
 1.24 07-May-2022  skrll Add support for Apple silicon NVME. Ported from OpenBSD.
 1.23 16-Nov-2021  skrll Trailing whitespace
 1.22 29-May-2021  riastradh nvme(4): Add suspend/resume, derived from OpenBSD.
 1.21 28-Jul-2020  jdolecek branches: 1.21.6; 1.21.8;
add a quirk to disable MSI, and enable it for Intel SSD DC P4500

this device seems to cause serious system responsiveness issues when configured
to use MSI, while it works fine when configured for either INTx or MSI-X

this is important so this works well under Xen Dom0, which doesn't
support MSI-X yet

fixes another issue reported as feedback for PR port-xen/55285 by Frank Kardel
 1.20 28-Jun-2019  jmcneill branches: 1.20.2;
Fix a performance issue where one busy queue can starve all other queues.

In normal operations with multiple queues, the nvme driver will attempt
to schedule I/O requests on the submitting CPU. This breaks down when any
one of the queues becomes full; the driver returns EAGAIN to the disk
layer, which causes the disk layer to stop submitting more requests until
the blocked request is consumed. When space becomes available in the full
queue, it pulls the next buffer from the bufq and fills the queue again,
until finally hitting EAGAIN and preventing other queues from processing
requests.

Two changes here to fix the problem:

- When processing requests from the bufq, attempt to assign them to the
queue associated with the CPU that originated the request.
- If that queue is busy, try to find another queue with available space
before returning EAGAIN. This way, only when all queues are full will
the disk layer stop submitting more requests.

Now for some real numbers. On a Rockchip RK3399 board (6 CPUs), with 6
concurrent readers:

Old code:
4294967296 bytes transferred in 52.420 secs (81933752 bytes/sec)
4294967296 bytes transferred in 53.969 secs (79582117 bytes/sec)
4294967296 bytes transferred in 55.391 secs (77539082 bytes/sec)
4294967296 bytes transferred in 55.649 secs (77179595 bytes/sec)
4294967296 bytes transferred in 56.102 secs (76556402 bytes/sec)
4294967296 bytes transferred in 72.901 secs (58915066 bytes/sec)

New code:
4294967296 bytes transferred in 37.171 secs (115546186 bytes/sec)
4294967296 bytes transferred in 37.611 secs (114194445 bytes/sec)
4294967296 bytes transferred in 37.655 secs (114061009 bytes/sec)
4294967296 bytes transferred in 38.247 secs (112295534 bytes/sec)
4294967296 bytes transferred in 38.496 secs (111569183 bytes/sec)
4294967296 bytes transferred in 38.595 secs (111282997 bytes/sec)
 1.19 24-Apr-2019  mlelstv Expose device type. You can query it with e.g. drvctl -p ld0 disk-info/type.
 1.18 01-Dec-2018  jdolecek support DIOCSCACHE + DKCACHE_WRITE if volatile write cache is present

fix the Get Features call for DIOCGCACHE to actually retrieve the current
value properly
 1.17 19-Apr-2018  christos branches: 1.17.2;
s/static inline/static __inline/g for consistency.
 1.16 18-Apr-2018  nonaka nvme(4): Added some delay before check RDY bit quirk when disabling device.

Pick from FreeBSD nvme(4) r326937.
 1.15 16-Mar-2018  jdolecek refactor the locking code around DIOCGCACHE handling to be reusable
for other infrequent commands

it uses single condvar for simplicity, and uses it both when waiting
for ccb or command completion - this is fine, since usually there
will be just one such command qeueued anyway

use this to finally properly implement DIOCCACHESYNC - return only after
the command is confirmed as completed by the controller
 1.14 16-Mar-2018  jdolecek stop using q_nccbs_avail for deciding whether there are available ccbs;
no need to maintain a counter _and_ q_ccb_list

this fixes deadlock when all ccbs happen to be taken before completion
interrupt - nvme_q_complete() increased q_nccbs_avail only after
processing all the completed commands, by then there was nothing
left to actually kick the disk queue again into action

this also fixes ccb leak on command errors e.g. with bus_dmamem_alloc()
or bus_dmamel_load() - q_nccbs_avail was never decreased on the error path

fixes PR kern/52769 by Martin Husemann, thanks to Paul Goyette
for testing
 1.13 05-Apr-2017  jdolecek branches: 1.13.6; 1.13.12; 1.13.14;
expose disk device FUA/DPO support via DIOCGCACHE, and allow the flags
to be set for I/O; implement support in sd(4) and nvme(4)

discussed on tech-kern
 1.12 28-Feb-2017  jdolecek implement DIOCGCACHE
 1.11 01-Nov-2016  jdolecek branches: 1.11.2;
pass maxphys from device rather then assuming MAXPHYS; it's clipped in ld(4)
if bigger then MAXPHYS

multiply the queue size by number of queues for ld(4) sc_maxqueuecnt, so
that ld_diskstart() would try to use full capacity, instead of throttling
to one queue worth of commands
 1.10 01-Nov-2016  jdolecek tighter queue control - according to spec actual cap on number of commands
in flight is actually one less then queue size, head == tail means empty
queue
 1.9 20-Oct-2016  jdolecek revert change from rev. 1.12:
"""
slightly optimize memory access - change struct nvme_queue so that the
struct dmamem members are allocated as part of it, instead of separate
kmem_alloc()s
"""

that change quite curiously caused completion queue corruption on MP systems,
regardless of MPSAFE setting for the pci/softintr interrupt
 1.8 19-Oct-2016  jdolecek add debug code to check for completion queue corruption
 1.7 19-Oct-2016  jdolecek follow advice of spec and block interrupts via INTMS/INTMC for intx handler;
this also makes it possible to offload the actual interrupt processing to softintr
handler, similar as for MSI/MSI-X
 1.6 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).
 1.5 19-Sep-2016  jdolecek slightly optimize memory access - change struct nvme_queue so that the
struct dmamem members are allocated as part of it, instead of separate
kmem_alloc()s
 1.4 19-Sep-2016  jdolecek on further thought, just remove the separately allocated nvme_ns_context
altogether and fold into nvme_ccb; allocating this separately just isn't useful
 1.3 18-Sep-2016  jdolecek fix several bugs, make nvme(4) MPSAFE by default and also bump default
number of ioq from 128 to 1024; tested with VirtualBox and QEMU

* remove NVME_INTMC/NVME_INTMS writes in hw intr handler as this is not MPSAFE,
fortunately they don't seem to be necessary; shaves two register writes
* need to use full mutex_enter() in nvme_q_complete(), to avoid small
race between one handler exiting the loop and another entering
* for MSI, handover the command result processing to softintr; unfortunately
can't easily do that for INTx interrupts as they require doorbell write
to deassert
* unlock/relock q->q_cq_mtx before calling ccb_done to avoid potential deadlocks
* make sure to destroy queue mutexes when destroying the queue (LOCKDEBUG)
* make ns ctx pool per-device, so that it's deallocated properly on module
unload
* handle ctx allocation failure in ld_nvme_dobio()
* remove splbio() calls in ld_nvme_dobio() and sync, the paths are exercised
only for dump/shutdown, and that already disables interrupts
* free the ns ctx in ld_nvme_biodone() before calling lddone() to avoid
memory starvation, as lddone() can trigger another i/o request
* be more careful with using PR_WAITOK, the paths are called from interrupt
context and there we can't wait
 1.2 04-Jun-2016  nonaka branches: 1.2.2;
Add NVMe command passthrough support.
 1.1 01-May-2016  nonaka branches: 1.1.2;
Added nvme(4) for Non-Volatile Memory Host Controller Interface devices.
Ported from OpenBSD.
 1.1.2.6 28-Aug-2017  skrll Sync with HEAD
 1.1.2.5 05-Dec-2016  skrll Sync with HEAD
 1.1.2.4 05-Oct-2016  skrll Sync with HEAD
 1.1.2.3 09-Jul-2016  skrll Sync with HEAD
 1.1.2.2 29-May-2016  skrll Sync with HEAD
 1.1.2.1 01-May-2016  skrll file nvmevar.h was added on branch nick-nhusb on 2016-05-29 08:44:21 +0000
 1.2.2.3 26-Apr-2017  pgoyette Sync with HEAD
 1.2.2.2 20-Mar-2017  pgoyette Sync with HEAD
 1.2.2.1 04-Nov-2016  pgoyette Sync with HEAD
 1.11.2.1 21-Apr-2017  bouyer Sync with HEAD
 1.13.14.3 26-Dec-2018  pgoyette Sync with HEAD, resolve a few conflicts
 1.13.14.2 22-Apr-2018  pgoyette Sync with HEAD
 1.13.14.1 22-Mar-2018  pgoyette Synch with HEAD, resolve conflicts
 1.13.12.2 03-Dec-2017  jdolecek update from HEAD
 1.13.12.1 05-Apr-2017  jdolecek file nvmevar.h was added on branch tls-maxphys on 2017-12-03 11:37:03 +0000
 1.13.6.3 19-Apr-2018  martin Pull up following revision(s) (requested by nonaka in ticket #781):

sbin/nvmectl/Makefile 1.4
sbin/nvmectl/bignum.c 1.2
sbin/nvmectl/devlist.c 1.3-1.5
sbin/nvmectl/firmware.c 1.3,1.4
sbin/nvmectl/identify.c 1.3-1.5
sbin/nvmectl/logpage.c 1.5-1.7
sbin/nvmectl/nvme.h 1.3
sbin/nvmectl/nvmectl.8 1.5
sbin/nvmectl/nvmectl.c 1.5-1.7
sbin/nvmectl/nvmectl.h 1.5-1.8
sbin/nvmectl/perftest.c 1.3-1.5
sbin/nvmectl/power.c 1.3,1.4
sbin/nvmectl/reset.c 1.2,1.3
sbin/nvmectl/util.c 1.1,1.2
sbin/nvmectl/wdc.c 1.2-1.4
sys/dev/ic/ld_nvme.c 1.20
sys/dev/ic/nvme.c 1.38,1.39
sys/dev/ic/nvmeio.h 1.2
sys/dev/ic/nvmereg.h 1.10,1.11
sys/dev/ic/nvmevar.h 1.16
sys/dev/pci/nvme_pci.c 1.20

nvmectl(8): Sync with FreeBSD nvmecontrol(8) r328763.

nvmectl(8): fix wdc command usage.

nvme(4): Added some delay before check RDY bit quirk when disabling device.
Pick from FreeBSD nvme(4) r326937.

Add some new structure fileds, opcodes and statuses from NVMe 1.3a.

nvmectl(8): Add big-endian support.
from FreeBSD nvmecontolr(8) r329824.

nvmectl(8): fix subcommand usage.

nvmectl(8): Remove some wdc subcommands from man page.
- wdc drive-log
- wdc get-crash-dump
- wdc purge
- wdc purge-monitor

Typos.

use setprogname()/getprogname(), do not hardcode the prognam name in fixed
strings
 1.13.6.2 18-Mar-2018  martin Pull up following revision(s) (requested by jdolecek in ticket #641):
sys/dev/ic/nvme.c: revision 1.34
sys/dev/ic/nvme.c: revision 1.35
sys/dev/ic/nvme.c: revision 1.36
sys/dev/ic/nvme.c: revision 1.37
sys/dev/ic/ld_nvme.c: revision 1.19
sys/dev/ic/nvmevar.h: revision 1.15

refactor the locking code around DIOCGCACHE handling to be reusable
for other infrequent commands,it uses single condvar for simplicity,
and uses it both when waiting for ccb or command completion - this
is fine, since usually there will be just one such command qeueued anyway
use this to finally properly implement DIOCCACHESYNC - return only after
the command is confirmed as completed by the controller.

switch handling of passthrough commands to use queue, instead of polling
should fix PR kern/53059 by Frank Kardel

fix passthrough command usage also in nvme_get_number_of_queues(), fixes
memory corruption and possible panic on boot

also remove now duplicate nvme_ccb_put() call from
nvme_get_number_of_queues()
 1.13.6.1 17-Mar-2018  martin Pull up following revision(s) (requested by jdolecek in ticket #636):
sys/dev/ic/nvme.c: revision 1.33
sys/dev/ic/nvmevar.h: revision 1.14
stop using q_nccbs_avail for deciding whether there are available ccbs;
no need to maintain a counter _and_ q_ccb_list
this fixes deadlock when all ccbs happen to be taken before completion
interrupt - nvme_q_complete() increased q_nccbs_avail only after
processing all the completed commands, by then there was nothing
left to actually kick the disk queue again into action
this also fixes ccb leak on command errors e.g. with bus_dmamem_alloc()
or bus_dmamel_load() - q_nccbs_avail was never decreased on the error path
fixes PR kern/52769 by Martin Husemann, thanks to Paul Goyette
for testing
 1.17.2.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.17.2.1 10-Jun-2019  christos Sync with HEAD
 1.20.2.1 21-Jun-2021  martin Pull up following revision(s) (requested by riastradh in ticket #1305):

sys/dev/ic/nvmevar.h: revision 1.22
sys/dev/ic/nvme.c: revision 1.56
sys/dev/ic/nvme.c: revision 1.57
sys/dev/pci/nvme_pci.c: revision 1.30

nvme(4): Add suspend/resume, derived from OpenBSD.

nvme(4): Move disestablishment of admin q interrupt to nvme_detach.

Nothing re-established this after suspend/resume, so attempting
suspend/resume/suspend would crash, and presumably we would miss
interrupts after resume. This keeps the establish/disestablish more
symmetric in attach/detach.
 1.21.8.1 31-May-2021  cjep sync with head
 1.21.6.1 17-Jun-2021  thorpej Sync w/ HEAD.
 1.19 09-Feb-2024  andvar fix spelling mistakes, mainly in comments and log messages.
 1.18 07-Aug-2021  thorpej Merge thorpej-cfargs2.
 1.17 24-Apr-2021  thorpej branches: 1.17.8;
Merge thorpej-cfargs branch:

Simplify and make extensible the config_search() / config_found() /
config_attach() interfaces: rather than having different variants for
which arguments you want pass along, just have a single call that
takes a variadic list of tag-value arguments.

Adjust all call sites:
- Simplify wherever possible; don't pass along arguments that aren't
actually needed.
- Don't be explicit about what interface attribute is attaching if
the device only has one. (More simplification.)
- Add a config_probe() function to be used in indirect configuiration
situations, making is visibly easier to see when indirect config is
in play, and allowing for future change in semantics. (As of now,
this is just a wrapper around config_match(), but that is an
implementation detail.)

Remove unnecessary or redundant interface attributes where they're not
needed.

There are currently 5 "cfargs" defined:
- CFARG_SUBMATCH (submatch function for direct config)
- CFARG_SEARCH (search function for indirect config)
- CFARG_IATTR (interface attribte)
- CFARG_LOCATORS (locators array)
- CFARG_DEVHANDLE (devhandle_t - wraps OFW, ACPI, etc. handles)

...and a sentinel value CFARG_EOL.

Add some extra sanity checking to ensure that interface attributes
aren't ambiguous.

Use CFARG_DEVHANDLE in MI FDT, OFW, and ACPI code, and macppc and shark
ports to associate those device handles with device_t instance. This
will trickle trough to more places over time (need back-end for pre-OFW
Sun OBP; any others?).
 1.16 10-Nov-2019  chs branches: 1.16.10;
in many device attach paths, allocate memory with M_WAITOK instead of M_NOWAIT
and remove code to handle failures that can no longer happen.
 1.15 15-Dec-2014  skrll branches: 1.15.18;
Load the right xfer address into cb[i].xferdma. Fixes disk detection on
my hp715/50.

Hi Taylor.
 1.14 18-Aug-2014  riastradh branches: 1.14.2;
Fix leaks in oosiop_alloc_cb error branches, noted by maxv@.

While here, avoid a sketchy pointer cast that probably falls afoul of
strict aliasing rules.

Compile-tested only, with hppa.
 1.13 13-Nov-2010  uebayasi branches: 1.13.14; 1.13.18; 1.13.20; 1.13.28; 1.13.34;
Don't pull in the whole uvm(9) API to access only PAGE_SIZE and
some other constants. These are provided by sys/param.h now.
 1.12 29-Mar-2008  tsutsui branches: 1.12.26;
Split softc/device_t for oosiop(4) and osiop(4), with misc cosmetic changes.
 1.11 19-Oct-2007  ad branches: 1.11.16;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.10 04-Mar-2007  christos branches: 1.10.2; 1.10.14; 1.10.16; 1.10.20;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.9 24-Dec-2005  perry branches: 1.9.26;
Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.8 11-Dec-2005  christos merge ktrace-lwp.
 1.7 27-Feb-2005  perry branches: 1.7.4;
nuke trailing whitespace
 1.6 02-Jan-2005  tsutsui branches: 1.6.2; 1.6.4;
u_intNN_t -> uintNN_t
 1.5 14-Mar-2004  wiz It's extension, not extention. From Miod Vallat (miod at online fr).
 1.4 29-Oct-2003  tsutsui Eliminate an uninitialized variable warning.
 1.3 26-Sep-2003  simonb Cast through (void *) to appease gcc3.
 1.2 14-Jul-2003  lukem add missing __KERNEL_RCSID()
 1.1 06-Apr-2003  tsutsui branches: 1.1.2;
Add MI NCR/Symbios 53c700 SCSI driver.
This "oosiop" driver was originally written by Shuichiro URATA
for arc port, and then it was modified by me to make it work
also on hp700.

This driver has been tested on my NEC Express5800/240 with 53c700-66
for several months, and also tested on HP9000 735/125 with 53c700
(though current hp700 port has been broken since SA merge).
Both sync transfer and disconnect/reselect work fine,
but tagged queuing is not implemented yet.
 1.1.2.5 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.1.2.4 17-Jan-2005  skrll Sync with HEAD.
 1.1.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.1.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.1.2.1 03-Aug-2004  skrll Sync with HEAD
 1.6.4.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.6.2.1 29-Apr-2005  kent sync with -current
 1.7.4.3 27-Oct-2007  yamt sync with head.
 1.7.4.2 03-Sep-2007  yamt sync with head.
 1.7.4.1 21-Jun-2006  yamt sync with head.
 1.9.26.1 12-Mar-2007  rmind Sync with HEAD.
 1.10.20.1 25-Oct-2007  bouyer Sync with HEAD.
 1.10.16.1 06-Nov-2007  matt sync with HEAD
 1.10.14.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.10.2.1 23-Oct-2007  ad Sync with head.
 1.11.16.1 03-Apr-2008  mjf Sync with HEAD.
 1.12.26.1 05-Mar-2011  rmind sync with head
 1.13.34.2 15-Dec-2014  martin Pull up following revision(s) (requested by skrll in ticket #327):
sys/dev/ic/oosiop.c: revision 1.15
Load the right xfer address into cb[i].xferdma. Fixes disk detection on
my hp715/50.
Hi Taylor.
 1.13.34.1 22-Aug-2014  martin Pull up following revision(s) (requested by riastradh in ticket #44):
sys/altq/altq_jobs.c 1.7
Fix error branches to avoid leaks, noted by maxv@.
sys/dev/ic/oosiop.c 1.14
Fix leaks in oosiop_alloc_cb error branches, noted by maxv@.
While here, avoid a sketchy pointer cast that probably falls afoul
of strict aliasing rules.
sys/dev/qbus/if_qe.c 1.73
Avoid leak in error branch, noted by maxv@, compile-tested for vax.
sys/dev/rasops/rasops.c 1.72
Don't leak f on failure. Noted by maxv@.
sys/dev/vme/if_ie_vme.c 1.31
Sizeof struct ievme, not sizeof size_t.
Noted by maxv@, compile-tested for sparc.
sys/net/if_gre.c 1.160
Don't leak in gre_clone_create error branch.
Noted by maxv@, compile-tested for amd64.
 1.13.28.1 03-Nov-2014  msaitoh Pull up following revision(s) (requested by riastradh in ticket #1117):
sys/dev/rasops/rasops.c: revision 1.72
sys/dev/vme/if_ie_vme.c: revision 1.31
sys/dev/qbus/if_qe.c: revision 1.73
sys/altq/altq_jobs.c: revision 1.7
sys/net/if_gre.c: revision 1.160
sys/dev/ic/oosiop.c: revision 1.14
- Fix error branches in altq_jobs.c to avoid leaks, noted by maxv@.
- Fix leaks in oosiop_alloc_cb error branches, noted by maxv@.
While here, avoid a sketchy pointer cast that probably falls afoul of
strict aliasing rules. Compile-tested only, with hppa.
- Don't leak f on failurein rasops.c. Noted by maxv@.
Compile-tested only, with zaurus.
- Avoid leak in error branch in if_qe.c, noted by maxv@, compile-tested for
vax.
- Sizeof struct ievme, not sizeof size_t in if_ie_vme.c.
Noted by maxv@, compile-tested for sparc.
- Don't leak in gre_clone_create error branch.
Noted by maxv@, compile-tested for amd64.
 1.13.20.1 03-Nov-2014  msaitoh Pull up following revision(s) (requested by riastradh in ticket #1117):
sys/dev/rasops/rasops.c: revision 1.72
sys/dev/vme/if_ie_vme.c: revision 1.31
sys/dev/qbus/if_qe.c: revision 1.73
sys/altq/altq_jobs.c: revision 1.7
sys/net/if_gre.c: revision 1.160
sys/dev/ic/oosiop.c: revision 1.14
- Fix error branches in altq_jobs.c to avoid leaks, noted by maxv@.
- Fix leaks in oosiop_alloc_cb error branches, noted by maxv@.
While here, avoid a sketchy pointer cast that probably falls afoul of
strict aliasing rules. Compile-tested only, with hppa.
- Don't leak f on failurein rasops.c. Noted by maxv@.
Compile-tested only, with zaurus.
- Avoid leak in error branch in if_qe.c, noted by maxv@, compile-tested for
vax.
- Sizeof struct ievme, not sizeof size_t in if_ie_vme.c.
Noted by maxv@, compile-tested for sparc.
- Don't leak in gre_clone_create error branch.
Noted by maxv@, compile-tested for amd64.
 1.13.18.1 03-Dec-2017  jdolecek update from HEAD
 1.13.14.1 03-Nov-2014  msaitoh Pull up following revision(s) (requested by riastradh in ticket #1117):
sys/dev/rasops/rasops.c: revision 1.72
sys/dev/vme/if_ie_vme.c: revision 1.31
sys/dev/qbus/if_qe.c: revision 1.73
sys/altq/altq_jobs.c: revision 1.7
sys/net/if_gre.c: revision 1.160
sys/dev/ic/oosiop.c: revision 1.14
- Fix error branches in altq_jobs.c to avoid leaks, noted by maxv@.
- Fix leaks in oosiop_alloc_cb error branches, noted by maxv@.
While here, avoid a sketchy pointer cast that probably falls afoul of
strict aliasing rules. Compile-tested only, with hppa.
- Don't leak f on failurein rasops.c. Noted by maxv@.
Compile-tested only, with zaurus.
- Avoid leak in error branch in if_qe.c, noted by maxv@, compile-tested for
vax.
- Sizeof struct ievme, not sizeof size_t in if_ie_vme.c.
Noted by maxv@, compile-tested for sparc.
- Don't leak in gre_clone_create error branch.
Noted by maxv@, compile-tested for amd64.
 1.14.2.1 06-Apr-2015  skrll Sync with HEAD
 1.15.18.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.16.10.1 21-Mar-2021  thorpej Give config_found() the same variadic arguments treatment as
config_search(). This commit only adds the CFARG_EOL sentinel
to the existing config_found() calls. Conversion of config_found_sm_loc()
and config_found_ia() call sites will be in subsequent commits.
 1.17.8.1 04-Aug-2021  thorpej Adapt to CFARGS().
 1.4 11-Dec-2005  christos merge ktrace-lwp.
 1.3 02-Nov-2003  wiz Fix some typos. From Tom Cosgrove via jmc@openbsd.
 1.2 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22364, verified by myself.
 1.1 06-Apr-2003  tsutsui branches: 1.1.2;
Add MI NCR/Symbios 53c700 SCSI driver.
This "oosiop" driver was originally written by Shuichiro URATA
for arc port, and then it was modified by me to make it work
also on hp700.

This driver has been tested on my NEC Express5800/240 with 53c700-66
for several months, and also tested on HP9000 735/125 with 53c700
(though current hp700 port has been broken since SA merge).
Both sync transfer and disconnect/reselect work fine,
but tagged queuing is not implemented yet.
 1.1.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.1.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.1.2.1 03-Aug-2004  skrll Sync with HEAD
 1.6 29-Mar-2008  tsutsui Split softc/device_t for oosiop(4) and osiop(4), with misc cosmetic changes.
 1.5 25-Dec-2007  perry branches: 1.5.6;
Convert many of the uses of __attribute__ to equivalent
__packed, __unused and __dead macros from cdefs.h
 1.4 11-Dec-2005  christos branches: 1.4.46; 1.4.52; 1.4.56; 1.4.60;
merge ktrace-lwp.
 1.3 02-Jan-2005  tsutsui branches: 1.3.10;
u_intNN_t -> uintNN_t
 1.2 03-May-2003  wiz branches: 1.2.2;
DMA, not dma nor Dma.
 1.1 06-Apr-2003  tsutsui Add MI NCR/Symbios 53c700 SCSI driver.
This "oosiop" driver was originally written by Shuichiro URATA
for arc port, and then it was modified by me to make it work
also on hp700.

This driver has been tested on my NEC Express5800/240 with 53c700-66
for several months, and also tested on HP9000 735/125 with 53c700
(though current hp700 port has been broken since SA merge).
Both sync transfer and disconnect/reselect work fine,
but tagged queuing is not implemented yet.
 1.2.2.1 17-Jan-2005  skrll Sync with HEAD.
 1.3.10.1 21-Jan-2008  yamt sync with head
 1.4.60.1 02-Jan-2008  bouyer Sync with HEAD
 1.4.56.1 26-Dec-2007  ad Sync with head.
 1.4.52.1 18-Feb-2008  mjf Sync with HEAD.
 1.4.46.1 09-Jan-2008  matt sync with HEAD
 1.5.6.1 03-Apr-2008  mjf Sync with HEAD.
 1.44 10-May-2023  riastradh opl(4): Use config_detach_children.
 1.43 08-May-2019  isaki Merge isaki-audio2 branch, the overhaul of audio subsystem.
- Interrupt-oriented system rather than thread-oriented.
- Improve stability, quality and performance.
- Split playback and record cleanly. Improve halfduplex support.
- Many bugs are fixed including deadlocks, resource leaks, abuses, etc.
- Simplify audio filter mechanism. The encoding/channels/frequency
conversions are completely handled in the upper layer. So the hard-
ware driver only converts its hardware encoding (if necessary).
- audio_hw_if changes:
- Obsoletes query_encoding and add query_format instead.
- Obsoletes set_params and add set_format instead.
- Remove drain, setfd, mappage.
- The call sequences are changed.
- ioctl AUDIO_GETFD/SETFD, AUDIO_GETCHAN/SETCHAN are obsoleted.
- ioctl AUDIO_{QUERY,GET,SET}FORMAT are introduced.
- cleanup config attributes: au*conv and mulaw.
- All hardware drivers should follow it (I've done as much as possible).

Some file paths are changed:
- dev/audio.c -> dev/audio/audio.c (rewritten)
- dev/audiovar.h -> dev/audio/audiovar.h
- dev/audio_dai.h -> dev/audio/audio_dai.h
- dev/audio_if.h -> dev/audio/audio_if.h
- dev/audiobell.c -> dev/audio/audiobell.c
- dev/audiobellvar.h -> dev/audio/audiobellvar.h
- dev/mulaw.[ch] -> dev/audio/mulaw.[ch] + dev/audio/alaw.c
 1.42 14-Jul-2016  msaitoh branches: 1.42.18; 1.42.22;
- Use aprint*() more in xxx_attach().
- Add missing aprint_naive("\n").
- Remove extra spaces and tabs.
- KNF.
 1.41 07-Jul-2016  msaitoh KNF. Remove extra spaces. No functional change.
 1.40 28-Jun-2013  christos branches: 1.40.10;
avoid undefined behavior
http://m00nbsd.net/ae123a9bae03f7dde5c6d654412daf5a.html
 1.39 09-Apr-2012  plunky branches: 1.39.2;
Tidy up a little, the way that midi attachment code works

- change midi_attach() to omit the 'parent' arg (there are
only two callers of this and it is not used)

- change midisyn_attach() to midisyn_init(), so not needing a midi_softc,
and fix the midi_pcppi driver to set hw_if and hw_hdl directly in
its midi_softc before calling midi_attach()

- add a device_t to opl_softc structure, change opl drivers to store
the device 'self' in opl_softc and fix opl_attach() to use this
opl_softc->dev field directly rather than a field in an otherwise
unused midi_softc

- remove unnecessary midi_softc from opl and cms drivers (child device
provides that)

reviewed by mrg
 1.38 23-Nov-2011  jmcneill branches: 1.38.2;
Merge jmcneill-audiomp3 branch, which is derived from ad-audiomp2. From
the original ad-audiomp branch notes:

Add MP locking to the audio drivers.

Making the audio drivers MP safe is necessary before efforts
can be made to make the VM system MP safe.

The are two locks per device instance, an ISR lock and
a character device lock. The ISR lock replaces calls to
splaudio()/splx(), and will be held across calls to device
methods which were called at splaudio() before (e.g.
trigger_output). The character device lock is held across
calls to nearly all of the methods, excluding some only
used for initialization, e.g. get_locks.

Welcome to 5.99.57.
 1.37 01-Sep-2009  jmcneill branches: 1.37.12; 1.37.14;
aprint-ify
 1.36 14-Mar-2009  dsl ANSIfy another 1261 function definitions.
The only ones left in sys are beyond by sed script!
(or in sys/dist or sys/external)
Mostly they have function pointer parameters.
 1.35 14-Mar-2009  dsl Change about 4500 of the K&R function definitions to ANSI ones.
There are still about 1600 left, but they have ',' or /* ... */
in the actual variable definitions - which my awk script doesn't handle.
There are also many that need () -> (void).
(The script does handle misordered arguments.)
 1.34 28-Apr-2008  martin branches: 1.34.8; 1.34.12; 1.34.14;
Remove clause 3 and 4 from TNF licenses
 1.33 04-Mar-2008  cube branches: 1.33.2; 1.33.4;
Split device_t/softc for midi(4), and other related cosmetic changes.
 1.32 19-Oct-2007  ad branches: 1.32.12; 1.32.16;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.31 16-Nov-2006  christos branches: 1.31.8; 1.31.22; 1.31.24; 1.31.28;
__unused removal on arguments; approved by core.
 1.30 12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.29 03-Sep-2006  christos branches: 1.29.2; 1.29.4;
add missing initializers
 1.28 17-Aug-2006  christos Fix all the -D*DEBUG* code that it was rotting away and did not even compile.
Mostly from Arnaud Lacombe, many thanks!
 1.27 12-Aug-2006  nakayama Avoid gcc4 warnings; voice is unsigned so no need to check "voice < 0".
 1.26 30-Jun-2006  chap branches: 1.26.2;
Ankh-Morpork, we have a MIDI driver....

Merge from chap-midi branch, after
~month for review
Comments by thorpej@ drochner@ and Alexandre Ratchov

Incorporated: points by thorpej@ drochner@; preliminary support for
a stats-collecting ioctl suggested by martin@ from comments by A.R.

PR kern/32441 kern/32442 kern/32567 kern/32588 kern/32694 kern/33590
kern/33614 and one instance of kern/32651

ok martin@
 1.25 09-Jun-2006  christos branches: 1.25.2;
stack police: Introduce an opl_match function that uses malloc instead of
allocating ~2K of softc on the stack.
 1.24 29-Mar-2006  thorpej branches: 1.24.2;
Use device_cfdata().
 1.23 11-Dec-2005  christos branches: 1.23.4; 1.23.6; 1.23.8; 1.23.10; 1.23.12;
merge ktrace-lwp.
 1.22 04-Feb-2005  perry branches: 1.22.6;
de-__P
 1.21 22-Apr-2004  itojun branches: 1.21.4; 1.21.6;
sprintf -> snprintf
 1.20 04-Dec-2003  keihan netbsd.org -> NetBSD.org

This was the last commit of this kind to src/sys, which is now totally
"NetBSD.org clean". Thanks for the patiance, and sorry for all the commits.
 1.19 02-Nov-2003  wiz Fix some typos. From Tom Cosgrove via jmc@openbsd.
 1.18 09-Feb-2003  itohy branches: 1.18.2;
- init panpot at reset
- whitespace police
 1.17 13-Nov-2001  lukem add/cleanup RCSID
 1.16 04-Nov-2001  itohy Introduce "flags 1", which causes left and right channels swapped.
 1.15 23-Oct-2001  augustss branches: 1.15.2;
Make it compile with debug on.
 1.14 23-Oct-2001  itohy Support panpot on OPL3. Now this device is a stereo instrument.
 1.13 29-Sep-2001  augustss Add a detach function (from Jared D. McNeill).
 1.12 18-Jan-2001  jdolecek branches: 1.12.2; 1.12.4; 1.12.6;
constify
 1.11 12-Aug-2000  augustss Fix spelling in comment.
 1.10 05-Oct-1999  itohy branches: 1.10.2;
Add power control hooks.
 1.9 04-Oct-1999  augustss Implement program change. From Martin Cernohorsky <cerno@ics.muni.cz>.
 1.8 23-May-1999  augustss Update doc URL.
 1.7 08-Dec-1998  augustss branches: 1.7.6;
Make the OPL information string more informative.
 1.6 25-Nov-1998  augustss Make the copyright header conform to the NetBSD template.
 1.5 13-Sep-1998  mycroft Make sure all voices are deallocated on close.
 1.4 26-Aug-1998  augustss Do some renaming of registers and make sure we get sound in both
channels on OPL3.
 1.3 26-Aug-1998  augustss Make the OPL driver turn on the sound on sound cards that require it.
That makes it much more likely that we get any sound. DUH!
 1.2 22-Aug-1998  augustss Change debug output.
 1.1 17-Aug-1998  augustss * Redo the way the way the MIDI driver attaches to audio devices.
* Improve the midisyn layer a little.
* Add a driver for the Yamaha OPL[23] FM synths.
The opl driver is not finished yet; it sounds pretty awful.

For some strange reason I cannot get any FM sound from my SB64 cards,
but a regular SB16 works fine.
 1.7.6.1 21-Jun-1999  thorpej Sync w/ -current.
 1.10.2.2 11-Feb-2001  bouyer Sync with HEAD.
 1.10.2.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.12.6.1 01-Oct-2001  fvdl Catch up with -current.
 1.12.4.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.12.2.2 14-Nov-2001  nathanw Catch up to -current.
 1.12.2.1 08-Oct-2001  nathanw Catch up to -current.
 1.15.2.1 12-Nov-2001  thorpej Sync the thorpej-mips-cache branch with -current.
 1.18.2.4 04-Feb-2005  skrll Sync with HEAD.
 1.18.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.18.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.18.2.1 03-Aug-2004  skrll Sync with HEAD
 1.21.6.1 12-Feb-2005  yamt sync with head.
 1.21.4.1 29-Apr-2005  kent sync with -current
 1.22.6.4 17-Mar-2008  yamt sync with head.
 1.22.6.3 27-Oct-2007  yamt sync with head.
 1.22.6.2 30-Dec-2006  yamt sync with head.
 1.22.6.1 21-Jun-2006  yamt sync with head.
 1.23.12.1 31-Mar-2006  tron Merge 2006-03-31 NetBSD-current into the "peter-altq" branch.
 1.23.10.1 19-Apr-2006  elad sync with head.
 1.23.8.5 14-Sep-2006  yamt sync with head.
 1.23.8.4 03-Sep-2006  yamt sync with head.
 1.23.8.3 11-Aug-2006  yamt sync with head
 1.23.8.2 26-Jun-2006  yamt sync with head.
 1.23.8.1 01-Apr-2006  yamt sync with head.
 1.23.6.1 22-Apr-2006  simonb Sync with head.
 1.23.4.1 09-Sep-2006  rpaulo sync with head
 1.24.2.7 19-Jun-2006  chap Sync with head.
 1.24.2.6 11-Jun-2006  chap Add relevelv and repitchv methods to opl: it now responds to channel volume
and expression controls, and changes to them are applied in real time to
voices already sounding, so dynamics sound right. This by itself makes a
remarkable difference in listenability. Pitch bend and tuning changes are
not applied to voices already sounding--even though I tried; for now they
apply only to subsequently played notes. I don't know if there is a way
to make this chip change frequency without stopping and rearticulating the
voice; the documentation has no detail on that point, and my attempt at
just writing the freq registers while it is sounding has no effect. So, I
do not know this chip well enough to finish making pitch controls work on
sounding notes, but if there is a way to do it then somebody who knows how
should have a very easy time adding that detail.

The opl device I tested on does play sharp, offering an easy test for the
new channel tuning support. :) Setting RPN 1 to 45:0 gets it right on the
money. Of course it's reset on close, which doesn't make it easy to send
a tuning adjustment and then run a favorite player program. It might be
that a sysctl (per midisyn instance) to set an initial tuning default
would be useful for that case.
 1.24.2.5 09-Jun-2006  chap Bit of housecleaning.

"miditune" wasn't a good name for the pitch representation (even if it
did come from the MIDI Tuning Specification) because for too many people
a 'tune' is a little ditty, not a single pitch. Changed the name to
midipitch and added a typedef midipitch_t; renamed the associated macros
consistently.

The type and operations on it are now in <sys/midiio.h> because they could
show up in userland for manipulation of the MIDI Tuning messages that
RP-012 defines. The macro MIDIPITCH_TO_HZ18 expands in userland to
ordinary libm calls, and in-kernel to the no-floating-point version in
midisyn. A few more operations are defined in userland where libm is
available.

At the same time, made midipitch_t signed. It has the bits to spare,
and such manipulations as adding several corrections and clamping the
result will be simpler with it signed.
 1.24.2.4 09-Jun-2006  chap Missed a couple details for opl on the first try.

The opl device I tested plays slightly but noticeably sharp. I double-
checked the coefficients in the manual and also compared to a kernel
from before my changes: also sharp. So I don't think I did it. I don't
know what the usual tolerances are for inexpensive soundcards. There
will at any rate be a general workaround as soon as midisyn groks
master-tuning.

This leaves only cms untested with the midisyn changes; I don't have
access to a cms device, but confidence is high.
 1.24.2.3 08-Jun-2006  chap Rototill of midisyn <-> synth driver i/f.

The DOALLOC and FREQXLATE flags are on the way out. Whether a driver wants
allocation service is deducible from whether it provides an allocv method, and
anyway none does. As for freq, they all get a miditune and can convert it
whichever way they want.

Controller handling with midictl is hooked in but few controllers watched yet.

Some macros for manipulating the miditune type are currently in midisynvar.h
but should perhaps be exported in midiio.h.

opl no longer has its own master volume state (there was no setter for it
anyway, it never changed); soon that will be handled centrally in midisyn.

Builds a kernel. Not all functionality tested yet.
 1.24.2.2 07-Jun-2006  chap Done pruning unused and ill-defined methods. Several bits of code that
actually did nothing have been replaced with comments explaining what
ought to be done there someday. This is actually progress. Everything
should still work, save PAN for opl, the only preexisting functionality
that's actually gone at this point, but it will be back soon.
 1.24.2.1 07-Jun-2006  chap The midisyn clients now use designated initializers so the method
structure can evolve. Only opl currently provides any methods beyond
open/close/note-on/note-off. Only cms takes a note number; the others
want a frequency. This is good because it is much easier that way to
put a common handler for tuning/pitchbend/portamento in midisyn itself.

Next up, axe most methods nobody implements. Split note-on into two
methods, one with a frequency, one with a note number, of which a driver
provides one or the other. So far all of the clients delegate voice
allocation to midisyn, so clarify that the method is getting an actual
voice number for the device and not a MIDI channel. If a device that can
do its own allocation is later to be supported, let appropriate different
methods be added then.
 1.25.2.1 13-Jul-2006  gdamore Merge from HEAD.
 1.26.2.1 14-Aug-2006  tron Pull up following revision(s) (requested by nakayama in ticket #16):
sys/dev/ic/opl.c: revision 1.27
Avoid gcc4 warnings; voice is unsigned so no need to check "voice < 0".
 1.29.4.2 10-Dec-2006  yamt sync with head.
 1.29.4.1 22-Oct-2006  yamt sync with head
 1.29.2.1 18-Nov-2006  ad Sync with head.
 1.31.28.1 25-Oct-2007  bouyer Sync with HEAD.
 1.31.24.2 23-Mar-2008  matt sync with HEAD
 1.31.24.1 06-Nov-2007  matt sync with HEAD
 1.31.22.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.31.8.1 23-Oct-2007  ad Sync with head.
 1.32.16.2 02-Jun-2008  mjf Sync with HEAD.
 1.32.16.1 03-Apr-2008  mjf Sync with HEAD.
 1.32.12.1 24-Mar-2008  keiichi sync with head.
 1.33.4.3 16-Sep-2009  yamt sync with head
 1.33.4.2 04-May-2009  yamt sync with head.
 1.33.4.1 16-May-2008  yamt sync with head.
 1.33.2.1 18-May-2008  yamt sync with head.
 1.34.14.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.34.12.1 09-Dec-2008  ad Checkpoint work on MIDI.
 1.34.8.1 28-Apr-2009  skrll Sync with HEAD.
 1.37.14.2 20-Nov-2011  mrg XXX: don't KASSERT() if sc->lock is NULL, this is going to happen
XXX: during autoconfig match() where we've faked up a sc anyway.
 1.37.14.1 19-Nov-2011  jmcneill port ad-audiomp2 branch changes to 5.99.56
todo:
- port ad-audiomp2 pcppi changes
- these drivers need to be fixed:
- emuxki
- gcscaudio
- hdafg
- uaudio
- umidi
- MD audio drivers
 1.37.12.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.37.12.1 17-Apr-2012  yamt sync with head
 1.38.2.1 29-Apr-2012  mrg sync to latest -current.
 1.39.2.2 03-Dec-2017  jdolecek update from HEAD
 1.39.2.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.40.10.2 05-Oct-2016  skrll Sync with HEAD
 1.40.10.1 09-Jul-2016  skrll Sync with HEAD
 1.42.22.1 04-May-2019  isaki Move dev/audio_if.h -> dev/audio/audio_if.h
 1.42.18.1 10-Jun-2019  christos Sync with HEAD
 1.2 05-Oct-1999  itohy This file is obsoleted by opl3sa3reg.h . R.I.P.
Sorry for spamming this list so much. :)
 1.1 20-May-1998  augustss Add a Yamaha OPL3-SA3 driver and clean up all AD1848 drivers.
Submitted by Constantine Sapuntzakis <csapuntz@reeducation-labor.lcs.mit.edu>
and originally written for OpenBSD.
 1.5 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.4 11-Dec-2005  christos branches: 1.4.70; 1.4.72; 1.4.74;
merge ktrace-lwp.
 1.3 27-Feb-2005  perry nuke trailing whitespace
 1.2 10-Mar-2002  itohy branches: 1.2.12; 1.2.20; 1.2.22;
Add explicit support of OPL3-SA2 (YMF711).
Not well tested....
 1.1 05-Oct-1999  itohy branches: 1.1.12; 1.1.14; 1.1.16;
YAMAHA YMF175x (OPL3-SA3) control register description.
 1.1.16.1 16-Mar-2002  jdolecek Catch up with -current.
 1.1.14.1 01-Apr-2002  nathanw Catch up to -current.
(CVS: It's not just a program. It's an adventure!)
 1.1.12.1 27-Mar-2002  he Pull up revision 1.2 (requested by itohy):
Several changes to wss-compatible audio devices:
o Fix ADPCM playback/recording
o Add explicit support for OPL3-SA2 (YMF711), fixes PR#14819
o Add AD1845 support
o other minor bugfixes and cleanups
 1.2.22.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.2.20.1 29-Apr-2005  kent sync with -current
 1.2.12.1 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.4.74.1 16-May-2008  yamt sync with head.
 1.4.72.1 18-May-2008  yamt sync with head.
 1.4.70.1 02-Jun-2008  mjf Sync with HEAD.
 1.7 19-Oct-2007  ad machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.6 11-Dec-2005  christos branches: 1.6.30; 1.6.44; 1.6.46; 1.6.50;
merge ktrace-lwp.
 1.5 27-Feb-2005  perry branches: 1.5.4;
nuke trailing whitespace
 1.4 13-Nov-2001  lukem branches: 1.4.16; 1.4.24; 1.4.26;
add/cleanup RCSID
 1.3 18-Jan-2001  jdolecek branches: 1.3.2; 1.3.4;
constify
 1.2 15-Feb-1999  hubertf branches: 1.2.8;
RCS ID police
 1.1 17-Aug-1998  augustss * Redo the way the way the MIDI driver attaches to audio devices.
* Improve the midisyn layer a little.
* Add a driver for the Yamaha OPL[23] FM synths.
The opl driver is not finished yet; it sounds pretty awful.

For some strange reason I cannot get any FM sound from my SB64 cards,
but a regular SB16 works fine.
 1.2.8.1 11-Feb-2001  bouyer Sync with HEAD.
 1.3.4.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.3.2.1 14-Nov-2001  nathanw Catch up to -current.
 1.4.26.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.4.24.1 29-Apr-2005  kent sync with -current
 1.4.16.1 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.5.4.1 27-Oct-2007  yamt sync with head.
 1.6.50.1 25-Oct-2007  bouyer Sync with HEAD.
 1.6.46.1 06-Nov-2007  matt sync with HEAD
 1.6.44.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.6.30.1 23-Oct-2007  ad Sync with head.
 1.6 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.5 11-Dec-2005  christos branches: 1.5.70; 1.5.72; 1.5.74;
merge ktrace-lwp.
 1.4 04-Dec-2003  keihan netbsd.org -> NetBSD.org

This was the last commit of this kind to src/sys, which is now totally
"NetBSD.org clean". Thanks for the patiance, and sorry for all the commits.
 1.3 25-Nov-1998  augustss branches: 1.3.44;
Make the copyright header conform to the NetBSD template.
 1.2 26-Aug-1998  augustss Do some renaming of registers and make sure we get sound in both
channels on OPL3.
 1.1 17-Aug-1998  augustss * Redo the way the way the MIDI driver attaches to audio devices.
* Improve the midisyn layer a little.
* Add a driver for the Yamaha OPL[23] FM synths.
The opl driver is not finished yet; it sounds pretty awful.

For some strange reason I cannot get any FM sound from my SB64 cards,
but a regular SB16 works fine.
 1.3.44.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.3.44.2 18-Sep-2004  skrll Sync with HEAD.
 1.3.44.1 03-Aug-2004  skrll Sync with HEAD
 1.5.74.1 16-May-2008  yamt sync with head.
 1.5.72.1 18-May-2008  yamt sync with head.
 1.5.70.1 02-Jun-2008  mjf Sync with HEAD.
 1.17 09-Apr-2012  plunky Tidy up a little, the way that midi attachment code works

- change midi_attach() to omit the 'parent' arg (there are
only two callers of this and it is not used)

- change midisyn_attach() to midisyn_init(), so not needing a midi_softc,
and fix the midi_pcppi driver to set hw_if and hw_hdl directly in
its midi_softc before calling midi_attach()

- add a device_t to opl_softc structure, change opl drivers to store
the device 'self' in opl_softc and fix opl_attach() to use this
opl_softc->dev field directly rather than a field in an otherwise
unused midi_softc

- remove unnecessary midi_softc from opl and cms drivers (child device
provides that)

reviewed by mrg
 1.16 23-Nov-2011  jmcneill branches: 1.16.2;
Merge jmcneill-audiomp3 branch, which is derived from ad-audiomp2. From
the original ad-audiomp branch notes:

Add MP locking to the audio drivers.

Making the audio drivers MP safe is necessary before efforts
can be made to make the VM system MP safe.

The are two locks per device instance, an ISR lock and
a character device lock. The ISR lock replaces calls to
splaudio()/splx(), and will be held across calls to device
methods which were called at splaudio() before (e.g.
trigger_output). The character device lock is held across
calls to nearly all of the methods, excluding some only
used for initialization, e.g. get_locks.

Welcome to 5.99.57.
 1.15 28-Apr-2008  martin branches: 1.15.12; 1.15.34; 1.15.36;
Remove clause 3 and 4 from TNF licenses
 1.14 15-Mar-2008  cube branches: 1.14.2; 1.14.4;
Split device_t and softc for opl(4). That should have been done along with
midi(4), because opl_softc embed a midi_softc.
Fixes PR#38242 by Onno van der Linden.
 1.13 30-Jun-2006  chap branches: 1.13.30; 1.13.50; 1.13.54;
Ankh-Morpork, we have a MIDI driver....

Merge from chap-midi branch, after
~month for review
Comments by thorpej@ drochner@ and Alexandre Ratchov

Incorporated: points by thorpej@ drochner@; preliminary support for
a stats-collecting ioctl suggested by martin@ from comments by A.R.

PR kern/32441 kern/32442 kern/32567 kern/32588 kern/32694 kern/33590
kern/33614 and one instance of kern/32651

ok martin@
 1.12 09-Jun-2006  christos branches: 1.12.2;
stack police: Introduce an opl_match function that uses malloc instead of
allocating ~2K of softc on the stack.
 1.11 11-Dec-2005  christos branches: 1.11.4; 1.11.8; 1.11.14;
merge ktrace-lwp.
 1.10 04-Feb-2005  perry branches: 1.10.6;
de-__P
 1.9 04-Dec-2003  keihan branches: 1.9.8; 1.9.10;
netbsd.org -> NetBSD.org

This was the last commit of this kind to src/sys, which is now totally
"NetBSD.org clean". Thanks for the patiance, and sorry for all the commits.
 1.8 04-Nov-2001  itohy branches: 1.8.16;
Introduce "flags 1", which causes left and right channels swapped.
 1.7 23-Oct-2001  itohy branches: 1.7.2;
Support panpot on OPL3. Now this device is a stereo instrument.
 1.6 29-Sep-2001  augustss Add a detach function (from Jared D. McNeill).
 1.5 18-Jan-2001  jdolecek branches: 1.5.2; 1.5.4; 1.5.6;
constify
 1.4 05-Oct-1999  itohy branches: 1.4.2;
Add power control hooks.
 1.3 25-Nov-1998  augustss Make the copyright header conform to the NetBSD template.
 1.2 26-Aug-1998  augustss Make the OPL driver turn on the sound on sound cards that require it.
That makes it much more likely that we get any sound. DUH!
 1.1 17-Aug-1998  augustss * Redo the way the way the MIDI driver attaches to audio devices.
* Improve the midisyn layer a little.
* Add a driver for the Yamaha OPL[23] FM synths.
The opl driver is not finished yet; it sounds pretty awful.

For some strange reason I cannot get any FM sound from my SB64 cards,
but a regular SB16 works fine.
 1.4.2.1 11-Feb-2001  bouyer Sync with HEAD.
 1.5.6.1 01-Oct-2001  fvdl Catch up with -current.
 1.5.4.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.5.2.2 14-Nov-2001  nathanw Catch up to -current.
 1.5.2.1 08-Oct-2001  nathanw Catch up to -current.
 1.7.2.1 12-Nov-2001  thorpej Sync the thorpej-mips-cache branch with -current.
 1.8.16.4 04-Feb-2005  skrll Sync with HEAD.
 1.8.16.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.8.16.2 18-Sep-2004  skrll Sync with HEAD.
 1.8.16.1 03-Aug-2004  skrll Sync with HEAD
 1.9.10.1 12-Feb-2005  yamt sync with head.
 1.9.8.1 29-Apr-2005  kent sync with -current
 1.10.6.3 17-Mar-2008  yamt sync with head.
 1.10.6.2 30-Dec-2006  yamt sync with head.
 1.10.6.1 21-Jun-2006  yamt sync with head.
 1.11.14.2 19-Jun-2006  chap Sync with head.
 1.11.14.1 08-Jun-2006  chap Rototill of midisyn <-> synth driver i/f.

The DOALLOC and FREQXLATE flags are on the way out. Whether a driver wants
allocation service is deducible from whether it provides an allocv method, and
anyway none does. As for freq, they all get a miditune and can convert it
whichever way they want.

Controller handling with midictl is hooked in but few controllers watched yet.

Some macros for manipulating the miditune type are currently in midisynvar.h
but should perhaps be exported in midiio.h.

opl no longer has its own master volume state (there was no setter for it
anyway, it never changed); soon that will be handled centrally in midisyn.

Builds a kernel. Not all functionality tested yet.
 1.11.8.2 11-Aug-2006  yamt sync with head
 1.11.8.1 26-Jun-2006  yamt sync with head.
 1.11.4.1 09-Sep-2006  rpaulo sync with head
 1.12.2.1 13-Jul-2006  gdamore Merge from HEAD.
 1.13.54.2 02-Jun-2008  mjf Sync with HEAD.
 1.13.54.1 03-Apr-2008  mjf Sync with HEAD.
 1.13.50.1 24-Mar-2008  keiichi sync with head.
 1.13.30.1 23-Mar-2008  matt sync with HEAD
 1.14.4.1 16-May-2008  yamt sync with head.
 1.14.2.1 18-May-2008  yamt sync with head.
 1.15.36.1 19-Nov-2011  jmcneill port ad-audiomp2 branch changes to 5.99.56
todo:
- port ad-audiomp2 pcppi changes
- these drivers need to be fixed:
- emuxki
- gcscaudio
- hdafg
- uaudio
- umidi
- MD audio drivers
 1.15.34.1 17-Apr-2012  yamt sync with head
 1.15.12.1 09-Dec-2008  ad Checkpoint work on MIDI.
 1.16.2.1 29-Apr-2012  mrg sync to latest -current.
 1.43 07-Aug-2021  thorpej Merge thorpej-cfargs2.
 1.42 24-Apr-2021  thorpej branches: 1.42.8;
Merge thorpej-cfargs branch:

Simplify and make extensible the config_search() / config_found() /
config_attach() interfaces: rather than having different variants for
which arguments you want pass along, just have a single call that
takes a variadic list of tag-value arguments.

Adjust all call sites:
- Simplify wherever possible; don't pass along arguments that aren't
actually needed.
- Don't be explicit about what interface attribute is attaching if
the device only has one. (More simplification.)
- Add a config_probe() function to be used in indirect configuiration
situations, making is visibly easier to see when indirect config is
in play, and allowing for future change in semantics. (As of now,
this is just a wrapper around config_match(), but that is an
implementation detail.)

Remove unnecessary or redundant interface attributes where they're not
needed.

There are currently 5 "cfargs" defined:
- CFARG_SUBMATCH (submatch function for direct config)
- CFARG_SEARCH (search function for indirect config)
- CFARG_IATTR (interface attribte)
- CFARG_LOCATORS (locators array)
- CFARG_DEVHANDLE (devhandle_t - wraps OFW, ACPI, etc. handles)

...and a sentinel value CFARG_EOL.

Add some extra sanity checking to ensure that interface attributes
aren't ambiguous.

Use CFARG_DEVHANDLE in MI FDT, OFW, and ACPI code, and macppc and shark
ports to associate those device handles with device_t instance. This
will trickle trough to more places over time (need back-end for pre-OFW
Sun OBP; any others?).
 1.41 10-Nov-2019  chs branches: 1.41.10;
in many device attach paths, allocate memory with M_WAITOK instead of M_NOWAIT
and remove code to handle failures that can no longer happen.
 1.40 16-Dec-2013  mrg branches: 1.40.30;
avoid unused variables outside of diag code.
 1.39 13-Nov-2010  uebayasi branches: 1.39.8; 1.39.18; 1.39.22;
Don't pull in the whole uvm(9) API to access only PAGE_SIZE and
some other constants. These are provided by sys/param.h now.
 1.38 04-May-2010  tsutsui Make local functions static.
 1.37 09-Dec-2008  tsutsui branches: 1.37.4; 1.37.6;
Sync with src/sys/arch/amiga/dev/siop.c rev 1.59:
> Deal with unrecognized SCSI message byte - restart script to clear the
> ACK. No longer hangs the driver when an unhandled message byte is seen.
 1.36 14-May-2008  tsutsui branches: 1.36.4; 1.36.6; 1.36.8;
Normalize my licenses.
 1.35 03-May-2008  tsutsui branches: 1.35.2;
- remove dead URL of datasheet
- change my mail address to NetBSD.org one
 1.34 29-Mar-2008  tsutsui branches: 1.34.2; 1.34.4;
Split softc/device_t for oosiop(4) and osiop(4), with misc cosmetic changes.
 1.33 19-Oct-2007  ad branches: 1.33.16;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.32 30-Jun-2007  tsutsui branches: 1.32.6; 1.32.8; 1.32.12;
- avoid possible NULL pointer dereference in error path
- call Debugger() only #ifdef OSIOP_DEBUG
Partially from OpenBSD.
 1.31 30-Jun-2007  tsutsui Use more TAILQ macro. From OpenBSD.
 1.30 30-Jun-2007  tsutsui Backout previous; defer bus_dmamap_sync(9) op against data buffer instead.

XXX ews4800mips (which has 128byte L2 cacheline) still has
XXX some problem in sd_read_capacity() on some unclear condition.
 1.29 30-Jun-2007  tsutsui Copy SCSI command before bus_dmamap_sync(9) PREREAD ops against
data xfer buffer because command and data buffers might be in
the same cacheline.
 1.28 30-Jun-2007  tsutsui Rather than preparing DMA map for SCSI command (which is
less than 16 bytes) of each SCSI command block (acb), just
prepare DMA safe buffer in struct osiop_ds and copy commands
into the buffer on each transfer to save resources and
reduce small and unaligned cache flush ops.

As a side effect, sizeof struct osiop_ds (DMA safe data buffer)
is now 256 bytes (including padding) so it could be more
cacheline friendly on bus_dmamap_sync(9) ops.

Tested on Express5800/230 (arc) and EWS4800/360AD (ews4800mips),
and no visible performance difference on bonnie.
(hppa and mvme68k are untested)
 1.27 04-Mar-2007  christos branches: 1.27.2; 1.27.4;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.26 29-Mar-2006  thorpej branches: 1.26.14;
Use device_cfdata().
 1.25 11-Dec-2005  christos branches: 1.25.4; 1.25.6; 1.25.8; 1.25.10; 1.25.12;
merge ktrace-lwp.
 1.24 30-Apr-2005  tsutsui branches: 1.24.2;
Avoid NULL pointer dereference on unexpected error cases. (from OpenBSD)
 1.23 27-Feb-2005  perry nuke trailing whitespace
 1.22 18-Feb-2005  tsutsui Print newline in some error messages.
 1.21 17-Feb-2005  tsutsui Allow MD attachments to override CTEST4 register value.
 1.20 02-Jan-2005  tsutsui branches: 1.20.2; 1.20.4;
u_intNN_t -> uintNN_t
 1.19 25-Sep-2004  tsutsui Use ANSI function decls.
 1.18 28-Mar-2004  mhitch Remove clauses 3 and 4.
 1.17 02-Nov-2003  wiz Fix some typos. From Tom Cosgrove via jmc@openbsd.
 1.16 29-Oct-2003  tsutsui Add a bogus initializer to appease gcc's uninitialized warning.

XXX osiop_checkintr() should be rewritten.
 1.15 29-Sep-2003  wiz available, not avaliable. From miod@openbsd.
 1.14 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22364, verified by myself.
 1.13 12-Apr-2003  tsutsui branches: 1.13.2;
Add some delays between 8bit reads of DSTAT and SSTAT0 registers
as per the 53c710 manual. Pointed out by fredette in osiop_gsc.c long ago.
 1.12 12-Apr-2003  tsutsui Fixes from OpenBSD:
- Fix index bounds checking in save data pointers logic.
- Fix an indent problem and an extra blank space.
 1.11 18-Feb-2003  tsutsui Also remove (probably) incorrect comment.
 1.10 18-Feb-2003  tsutsui Remove unusable debug code.
 1.9 05-Apr-2002  bouyer Implement mstohz() as discussed on tech-kern, and use it in SCSI drivers
to convert xs->timeout to callout() parameter.
 1.8 16-Dec-2001  tsutsui malloc() + memset() -> malloc() with M_ZERO flag
 1.7 18-Nov-2001  tsutsui - Use MI ADAPTER_REQ_SET_XFER_MODE callback
- Move values in sc_sync[] member to sc_tinfo[]
- Change some u_int8_t values to int
- Remove unused wide negotiation states
- Misc cleanup
 1.6 13-Nov-2001  lukem add/cleanup RCSID
 1.5 19-Jul-2001  thorpej Use BUS_DMA_READ and BUS_DMA_WRITE in some obvious places.
 1.4 09-Jun-2001  tsutsui branches: 1.4.2; 1.4.4;
Fix an uninitialized variable in #ifdef DIAGNOSTIC.
Pointed out by soda.
 1.3 17-May-2001  scw In osiop_scsidone(), call scsipi_done() even for polled operations.

This fixes a `hang' on shutdown when the `Synchronise Cache' command
is sent to a disk. (It uses polled mode because it is called from inside
a shutdown hook).
 1.2 09-May-2001  tsutsui Print a clock frequency of the chip.
 1.1 30-Apr-2001  tsutsui Add a MI driver for the Symbios/NCR 53c710 SCSI controller.
This is based on amiga's siop driver, but converted to use
bus_space(9) functions and modified to fit bus_dma(9) framework.

Currently tested on NetBSD/arc with jazzio 53c710 SCSI,
which really requires bus_dma(9) functions :-)
Sync transfers and disconnect/reconnect are also working.

TODO:
- Test under more heavy load
- Clean up osiop_checkintr() hander
- Reorganize command queue and sync negotiation handling more suitable
for thorpej-scsipi mid-layer
- Re-think defered interrupt handling for amiga
 1.4.4.3 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.4.4.2 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.4.4.1 03-Aug-2001  lukem update to -current
 1.4.2.6 17-Apr-2002  nathanw Catch up to -current.
 1.4.2.5 08-Jan-2002  nathanw Catch up to -current.
 1.4.2.4 14-Nov-2001  nathanw Catch up to -current.
 1.4.2.3 24-Aug-2001  nathanw Catch up with -current.
 1.4.2.2 21-Jun-2001  nathanw Catch up to -current.
 1.4.2.1 09-Jun-2001  nathanw file osiop.c was added on branch nathanw_sa on 2001-06-21 20:03:04 +0000
 1.13.2.7 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.13.2.6 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.13.2.5 17-Jan-2005  skrll Sync with HEAD.
 1.13.2.4 19-Oct-2004  skrll Sync with HEAD
 1.13.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.13.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.13.2.1 03-Aug-2004  skrll Sync with HEAD
 1.20.4.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.20.2.1 29-Apr-2005  kent sync with -current
 1.24.2.3 27-Oct-2007  yamt sync with head.
 1.24.2.2 03-Sep-2007  yamt sync with head.
 1.24.2.1 21-Jun-2006  yamt sync with head.
 1.25.12.1 31-Mar-2006  tron Merge 2006-03-31 NetBSD-current into the "peter-altq" branch.
 1.25.10.1 19-Apr-2006  elad sync with head.
 1.25.8.1 01-Apr-2006  yamt sync with head.
 1.25.6.1 22-Apr-2006  simonb Sync with head.
 1.25.4.1 09-Sep-2006  rpaulo sync with head
 1.26.14.1 12-Mar-2007  rmind Sync with HEAD.
 1.27.4.1 11-Jul-2007  mjf Sync with head.
 1.27.2.2 23-Oct-2007  ad Sync with head.
 1.27.2.1 15-Jul-2007  ad Sync with head.
 1.32.12.1 25-Oct-2007  bouyer Sync with HEAD.
 1.32.8.1 06-Nov-2007  matt sync with HEAD
 1.32.6.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.33.16.3 17-Jan-2009  mjf Sync with HEAD.
 1.33.16.2 02-Jun-2008  mjf Sync with HEAD.
 1.33.16.1 03-Apr-2008  mjf Sync with HEAD.
 1.34.4.3 11-Aug-2010  yamt sync with head.
 1.34.4.2 04-May-2009  yamt sync with head.
 1.34.4.1 16-May-2008  yamt sync with head.
 1.34.2.1 18-May-2008  yamt sync with head.
 1.35.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.36.8.1 13-Dec-2008  bouyer Pull up following revision(s) (requested by tsutsui in ticket #183):
sys/dev/ic/osiop.c: revision 1.37
Sync with src/sys/arch/amiga/dev/siop.c rev 1.59:
Deal with unrecognized SCSI message byte - restart script to clear the
ACK. No longer hangs the driver when an unhandled message byte is seen.
 1.36.6.1 19-Jan-2009  skrll Sync with HEAD.
 1.36.4.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.37.6.2 05-Mar-2011  rmind sync with head
 1.37.6.1 30-May-2010  rmind sync with head
 1.37.4.1 17-Aug-2010  uebayasi Sync with HEAD.
 1.39.22.1 18-May-2014  rmind sync with head
 1.39.18.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.39.8.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.40.30.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.41.10.1 21-Mar-2021  thorpej Give config_found() the same variadic arguments treatment as
config_search(). This commit only adds the CFARG_EOL sentinel
to the existing config_found() calls. Conversion of config_found_sm_loc()
and config_found_ia() call sites will be in subsequent commits.
 1.42.8.1 04-Aug-2021  thorpej Adapt to CFARGS().
 1.6 24-Aug-2012  msaitoh Fix typos
 1.5 11-Dec-2005  christos branches: 1.5.110;
merge ktrace-lwp.
 1.4 02-Nov-2003  wiz Fix some typos. From Tom Cosgrove via jmc@openbsd.
 1.3 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22364, verified by myself.
 1.2 18-Feb-2003  tsutsui branches: 1.2.2;
hz -> Hz (from OpenBSD)
 1.1 30-Apr-2001  tsutsui branches: 1.1.2;
Add a MI driver for the Symbios/NCR 53c710 SCSI controller.
This is based on amiga's siop driver, but converted to use
bus_space(9) functions and modified to fit bus_dma(9) framework.

Currently tested on NetBSD/arc with jazzio 53c710 SCSI,
which really requires bus_dma(9) functions :-)
Sync transfers and disconnect/reconnect are also working.

TODO:
- Test under more heavy load
- Clean up osiop_checkintr() hander
- Reorganize command queue and sync negotiation handling more suitable
for thorpej-scsipi mid-layer
- Re-think defered interrupt handling for amiga
 1.1.2.2 21-Jun-2001  nathanw Catch up to -current.
 1.1.2.1 30-Apr-2001  nathanw file osiopreg.h was added on branch nathanw_sa on 2001-06-21 20:03:05 +0000
 1.2.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.2.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.2.2.1 03-Aug-2004  skrll Sync with HEAD
 1.5.110.1 30-Oct-2012  yamt sync with head
 1.14 01-Jan-2022  andvar fix typos in comments, mainly basicly -> basically.
 1.13 14-May-2008  tsutsui Normalize my licenses.
 1.12 29-Mar-2008  tsutsui branches: 1.12.2; 1.12.4; 1.12.6;
Split softc/device_t for oosiop(4) and osiop(4), with misc cosmetic changes.
 1.11 25-Dec-2007  perry branches: 1.11.6;
Convert many of the uses of __attribute__ to equivalent
__packed, __unused and __dead macros from cdefs.h
 1.10 30-Jun-2007  tsutsui branches: 1.10.8; 1.10.14; 1.10.16; 1.10.20;
Rather than preparing DMA map for SCSI command (which is
less than 16 bytes) of each SCSI command block (acb), just
prepare DMA safe buffer in struct osiop_ds and copy commands
into the buffer on each transfer to save resources and
reduce small and unaligned cache flush ops.

As a side effect, sizeof struct osiop_ds (DMA safe data buffer)
is now 256 bytes (including padding) so it could be more
cacheline friendly on bus_dmamap_sync(9) ops.

Tested on Express5800/230 (arc) and EWS4800/360AD (ews4800mips),
and no visible performance difference on bonnie.
(hppa and mvme68k are untested)
 1.9 11-Dec-2005  christos branches: 1.9.30; 1.9.32;
merge ktrace-lwp.
 1.8 27-Feb-2005  perry branches: 1.8.4;
nuke trailing whitespace
 1.7 17-Feb-2005  tsutsui Allow MD attachments to override CTEST4 register value.
 1.6 02-Jan-2005  tsutsui branches: 1.6.2; 1.6.4;
u_intNN_t -> uintNN_t
 1.5 02-Nov-2003  wiz Fix some typos. From Tom Cosgrove via jmc@openbsd.
 1.4 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22364, verified by myself.
 1.3 14-May-2002  matt branches: 1.3.10;
Eliminate more commons or redundant declarations.
 1.2 18-Nov-2001  tsutsui - Use MI ADAPTER_REQ_SET_XFER_MODE callback
- Move values in sc_sync[] member to sc_tinfo[]
- Change some u_int8_t values to int
- Remove unused wide negotiation states
- Misc cleanup
 1.1 30-Apr-2001  tsutsui branches: 1.1.2; 1.1.4;
Add a MI driver for the Symbios/NCR 53c710 SCSI controller.
This is based on amiga's siop driver, but converted to use
bus_space(9) functions and modified to fit bus_dma(9) framework.

Currently tested on NetBSD/arc with jazzio 53c710 SCSI,
which really requires bus_dma(9) functions :-)
Sync transfers and disconnect/reconnect are also working.

TODO:
- Test under more heavy load
- Clean up osiop_checkintr() hander
- Reorganize command queue and sync negotiation handling more suitable
for thorpej-scsipi mid-layer
- Re-think defered interrupt handling for amiga
 1.1.4.2 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.1.4.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.1.2.4 20-Jun-2002  nathanw Catch up to -current.
 1.1.2.3 08-Jan-2002  nathanw Catch up to -current.
 1.1.2.2 21-Jun-2001  nathanw Catch up to -current.
 1.1.2.1 30-Apr-2001  nathanw file osiopvar.h was added on branch nathanw_sa on 2001-06-21 20:03:06 +0000
 1.3.10.5 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.3.10.4 17-Jan-2005  skrll Sync with HEAD.
 1.3.10.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.3.10.2 18-Sep-2004  skrll Sync with HEAD.
 1.3.10.1 03-Aug-2004  skrll Sync with HEAD
 1.6.4.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.6.2.1 29-Apr-2005  kent sync with -current
 1.8.4.2 21-Jan-2008  yamt sync with head
 1.8.4.1 03-Sep-2007  yamt sync with head.
 1.9.32.1 11-Jul-2007  mjf Sync with head.
 1.9.30.1 15-Jul-2007  ad Sync with head.
 1.10.20.1 02-Jan-2008  bouyer Sync with HEAD
 1.10.16.1 26-Dec-2007  ad Sync with head.
 1.10.14.1 18-Feb-2008  mjf Sync with HEAD.
 1.10.8.1 09-Jan-2008  matt sync with HEAD
 1.11.6.2 02-Jun-2008  mjf Sync with HEAD.
 1.11.6.1 03-Apr-2008  mjf Sync with HEAD.
 1.12.6.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.12.4.1 16-May-2008  yamt sync with head.
 1.12.2.1 18-May-2008  yamt sync with head.
 1.6 15-Sep-2025  thorpej Encapsulate what's needed to attach an I2C bus into a iicbus_attach()
inline.
 1.5 07-Aug-2021  thorpej Merge thorpej-cfargs2.
 1.4 24-Apr-2021  thorpej branches: 1.4.8;
Merge thorpej-cfargs branch:

Simplify and make extensible the config_search() / config_found() /
config_attach() interfaces: rather than having different variants for
which arguments you want pass along, just have a single call that
takes a variadic list of tag-value arguments.

Adjust all call sites:
- Simplify wherever possible; don't pass along arguments that aren't
actually needed.
- Don't be explicit about what interface attribute is attaching if
the device only has one. (More simplification.)
- Add a config_probe() function to be used in indirect configuiration
situations, making is visibly easier to see when indirect config is
in play, and allowing for future change in semantics. (As of now,
this is just a wrapper around config_match(), but that is an
implementation detail.)

Remove unnecessary or redundant interface attributes where they're not
needed.

There are currently 5 "cfargs" defined:
- CFARG_SUBMATCH (submatch function for direct config)
- CFARG_SEARCH (search function for indirect config)
- CFARG_IATTR (interface attribte)
- CFARG_LOCATORS (locators array)
- CFARG_DEVHANDLE (devhandle_t - wraps OFW, ACPI, etc. handles)

...and a sentinel value CFARG_EOL.

Add some extra sanity checking to ensure that interface attributes
aren't ambiguous.

Use CFARG_DEVHANDLE in MI FDT, OFW, and ACPI code, and macppc and shark
ports to associate those device handles with device_t instance. This
will trickle trough to more places over time (need back-end for pre-OFW
Sun OBP; any others?).
 1.3 22-Dec-2019  thorpej branches: 1.3.10;
Cleanup i2c bus acquire / release, centralizing all of the logic into
iic_acquire_bus() / iic_release_bus(). "acquire" and "release" hooks
no longer need to be provided by back-end controller drivers (only if
they need special handling, e.g. powering on the i2c controller).
This results in the removal of a bunch of rendundant code from each
back-end controller driver.

Assert that we are not in hard interrupt context in iic_acquire_bus(),
iic_exec(), and iic_release_bus().
 1.2 14-Feb-2016  chs branches: 1.2.18;
zero the i2c_attach_args structure before filling it in.
fixes occasional crashes in iic_attach().
 1.1 09-Apr-2010  nonaka branches: 1.1.2; 1.1.4; 1.1.6; 1.1.24; 1.1.42;
Added PCA9564 I2C Controller driver.
 1.1.42.1 19-Mar-2016  skrll Sync with HEAD
 1.1.24.1 03-Dec-2017  jdolecek update from HEAD
 1.1.6.2 11-Aug-2010  yamt sync with head.
 1.1.6.1 09-Apr-2010  yamt file pca9564.c was added on branch yamt-nfs-mp on 2010-08-11 22:53:29 +0000
 1.1.4.2 30-May-2010  rmind sync with head
 1.1.4.1 09-Apr-2010  rmind file pca9564.c was added on branch rmind-uvmplock on 2010-05-30 05:17:24 +0000
 1.1.2.2 30-Apr-2010  uebayasi Sync with HEAD.
 1.1.2.1 09-Apr-2010  uebayasi file pca9564.c was added on branch uebayasi-xip on 2010-04-30 14:43:20 +0000
 1.2.18.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.3.10.1 23-Mar-2021  thorpej Convert config_found_ia() call sites where the device only carries
a single interface attribute to bare config_found() calls.
 1.4.8.1 04-Aug-2021  thorpej Adapt to CFARGS().
 1.1 09-Apr-2010  nonaka branches: 1.1.2; 1.1.4; 1.1.6;
Added PCA9564 I2C Controller driver.
 1.1.6.2 11-Aug-2010  yamt sync with head.
 1.1.6.1 09-Apr-2010  yamt file pca9564reg.h was added on branch yamt-nfs-mp on 2010-08-11 22:53:29 +0000
 1.1.4.2 30-May-2010  rmind sync with head
 1.1.4.1 09-Apr-2010  rmind file pca9564reg.h was added on branch rmind-uvmplock on 2010-05-30 05:17:24 +0000
 1.1.2.2 30-Apr-2010  uebayasi Sync with HEAD.
 1.1.2.1 09-Apr-2010  uebayasi file pca9564reg.h was added on branch uebayasi-xip on 2010-04-30 14:43:20 +0000
 1.2 22-Dec-2019  thorpej Cleanup i2c bus acquire / release, centralizing all of the logic into
iic_acquire_bus() / iic_release_bus(). "acquire" and "release" hooks
no longer need to be provided by back-end controller drivers (only if
they need special handling, e.g. powering on the i2c controller).
This results in the removal of a bunch of rendundant code from each
back-end controller driver.

Assert that we are not in hard interrupt context in iic_acquire_bus(),
iic_exec(), and iic_release_bus().
 1.1 09-Apr-2010  nonaka branches: 1.1.2; 1.1.4; 1.1.6; 1.1.66;
Added PCA9564 I2C Controller driver.
 1.1.66.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.1.6.2 11-Aug-2010  yamt sync with head.
 1.1.6.1 09-Apr-2010  yamt file pca9564var.h was added on branch yamt-nfs-mp on 2010-08-11 22:53:29 +0000
 1.1.4.2 30-May-2010  rmind sync with head
 1.1.4.1 09-Apr-2010  rmind file pca9564var.h was added on branch rmind-uvmplock on 2010-05-30 05:17:24 +0000
 1.1.2.2 30-Apr-2010  uebayasi Sync with HEAD.
 1.1.2.1 09-Apr-2010  uebayasi file pca9564var.h was added on branch uebayasi-xip on 2010-04-30 14:43:20 +0000
 1.1 14-May-1998  drochner needed for VGA text attributes
 1.16 25-Feb-2010  drochner retire our private definitions for the scan1/3/5/7/9 DEC graphics
symbols, use the unicode definitions instead (which apparently didn't
exist when I wrote that)
 1.15 24-Feb-2010  drochner map some more punctuation to more or less good replacements in the IBM
character set
 1.14 10-Feb-2010  drochner add some more mappings from punctuation and accented characters to
more or less adequate replacements in the builtin IBM character set
 1.13 19-Oct-2007  ad branches: 1.13.20; 1.13.40;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.12 16-Nov-2006  christos branches: 1.12.8; 1.12.22; 1.12.24; 1.12.28;
__unused removal on arguments; approved by core.
 1.11 12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.10 11-Dec-2005  christos branches: 1.10.20; 1.10.22;
merge ktrace-lwp.
 1.9 24-Mar-2004  drochner branches: 1.9.16;
remove license clauses 3 and 4 from my cpoyright notices
 1.8 25-Aug-2002  thorpej branches: 1.8.6;
Fix some signed/unsigned comparison warnings from GCC 3.3.
 1.7 13-Nov-2001  lukem branches: 1.7.8;
add/cleanup RCSID
 1.6 18-Jan-2001  jdolecek branches: 1.6.2; 1.6.4;
constify
 1.5 08-Jun-2000  cgd don't include ISA headers. these have been properly abstracted so that
the ISA headers are unnecessary, and they're used by PCI VGA. There may
not be any ISA at all.
 1.4 20-Feb-1999  drochner branches: 1.4.8; 1.4.16;
complete mapping tables a bit so that ASCII (ie vt100) art looks better
even without extra fonts loaded
 1.3 12-Feb-1999  drochner oops - forgot to convert the trivial case (ASCII) to "match levels"
 1.2 12-Feb-1999  drochner Display the danish o-slash as phi/Theta as proposed by
Soren S. Jorvang <soren@t.dk>, with a lower match level.
Display the other accented characters which are not present in the IBM
character set by their non-accented equivalents, with an even lower
match level.
 1.1 26-Jun-1998  drochner mapping tables for IBM character set
 1.4.16.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.4.8.2 11-Feb-2001  bouyer Sync with HEAD.
 1.4.8.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.6.4.2 06-Sep-2002  jdolecek sync kqueue branch with HEAD
 1.6.4.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.6.2.2 27-Aug-2002  nathanw Catch up to -current.
 1.6.2.1 14-Nov-2001  nathanw Catch up to -current.
 1.7.8.1 29-Aug-2002  gehenna catch up with -current.
 1.8.6.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.8.6.2 18-Sep-2004  skrll Sync with HEAD.
 1.8.6.1 03-Aug-2004  skrll Sync with HEAD
 1.9.16.2 27-Oct-2007  yamt sync with head.
 1.9.16.1 30-Dec-2006  yamt sync with head.
 1.10.22.2 10-Dec-2006  yamt sync with head.
 1.10.22.1 22-Oct-2006  yamt sync with head
 1.10.20.1 18-Nov-2006  ad Sync with head.
 1.12.28.1 25-Oct-2007  bouyer Sync with HEAD.
 1.12.24.1 06-Nov-2007  matt sync with HEAD
 1.12.22.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.12.8.1 23-Oct-2007  ad Sync with head.
 1.13.40.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.13.20.1 11-Mar-2010  yamt sync with head
 1.36 25-Mar-2022  uwe pcdisplay_getwschar: on error return error code, not -1.

This value ends up being returned from vga_ioctl to sys_ioctl which
expects an errno and spams kernel log otherwise.

Ditto for pcdisplay_putwschar.
 1.35 19-Oct-2010  jmcneill When disabling the hardware cursor, use the 'cursor disable' bit in the
cursor start register. I think this only accidentally worked for the past
11 years because the start and end scanlines were both set to 0x10.

See also http://www.osdever.net/FreeVGA/vga/crtcreg.htm#0A
 1.34 19-Oct-2007  ad branches: 1.34.40; 1.34.42;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.33 28-Jul-2007  mjf branches: 1.33.4; 1.33.6; 1.33.10; 1.33.12;
Implement bounds checking in some places in display driver code to avoid
the possibility of a local user panic.
 1.32 15-Apr-2006  jmmv branches: 1.32.12; 1.32.18; 1.32.26; 1.32.28;
Remove the getwschar and putwschar accessops from wsdisplay drivers as
requested by uwe@. These were wrong because they were receiving an
emulcookie yet they were accessops (thus having to receive an accesscookie).
Instead, just handle the WSDISPLAYIO_{GET,PUT}WSCHAR ioctls from the
driver's ioctl accessop.

As this reduces the amount of code needed to handle these operations to
two small functions in each driver, remove the WSDISPLAY_CHARFUNCS kernel
option.

Reviewed by, at least, uwe@ and macallan@. No objections in tech-kern@.
 1.31 12-Apr-2006  jmmv Get rid of the memt and memh local variables in the pcdisplay_{get,put}wschar
functions.
 1.30 12-Apr-2006  jmmv Convert to ANSI prototypes.
 1.29 11-Dec-2005  christos branches: 1.29.4; 1.29.6; 1.29.8; 1.29.10; 1.29.12;
merge ktrace-lwp.
 1.28 27-Feb-2005  perry branches: 1.28.2; 1.28.4; 1.28.12; 1.28.14;
nuke trailing whitespace
 1.27 28-Jul-2004  jmmv branches: 1.27.4; 1.27.6;
Implement support to dynamically change wscons console and kernel colors.

Two new ioctls are added to the wsdisplay device, named WSDISPLAY_GMSGATTRS
and WSDISPLAY_SMSGATTRS, used to retrieve the actual values and set them,
respectively (the name, if you are wondering, comes from "message attributes").

A new emulop is added to the underlying display driver (only vga, for now)
which sets the new attribute for the whole screen, without having to clear
it. This is optional, which means that this also works with other drivers
that don't have this new operation.

Five new kernel options have been added, although only documented in
i386 kernels (for now):
- WSDISPLAY_CUSTOM_OUTPUT, which enables the ioctls described above to
change the colors dynamically from userland. This is enabled by default
in the GENERIC kernel (as well as others) but disabled on all INSTALL*
kernels (as this feature is useless there).
- WS_DEFAULT_COLATTR, WS_DEFAULT_MONOATTR, WS_DEFAULT_BG and WS_DEFAULT_FG,
which specify the default colors for the console at boot time. These have
the same meaning as the (already existing) WS_KERNEL_* variables.

wsconsctl is modified to add msg.default.{attrs,bg,fg} and
msg.kernel.{attrs,bg,fg} to the display part, so that colors can be changed
after boot.

Tested on NetBSD/i386 with vga (and vga in mono mode), and on NetBSD/mac68k.
No objections in tech-kern@.
 1.26 28-May-2004  christos PR/19925: David Ferlier: Add scrolling support to wscons.
 1.25 25-Aug-2002  thorpej branches: 1.25.6; 1.25.8;
Fix some signed/unsigned comparison warnings from GCC 3.3.
 1.24 07-Jul-2002  tron Fix a typo in last commit which caused build failures if
"PCDISPLAY_SOFTCURSOR" is not defined.
 1.23 07-Jul-2002  junyoung Rename vc_ccol and vc_crow in struct pcdisplayscreen to cursorcol
and cursorrow, respectively, to be consistent with other members
in the structure.
 1.22 01-Jul-2002  christos more cleanups from Julio Merino.
 1.21 26-Jun-2002  christos PR/17402: Add wsmoused support by providing get/set char and events.
 1.20 13-Nov-2001  lukem branches: 1.20.8;
add/cleanup RCSID
 1.19 04-Sep-2001  drochner -update a comment wrt the "active screen" flag
-apply the patch from PR kern/13117 (Onno van der Linden) to make the
hardware cursor disappear more thoroughly
-deal with PR kern/13573: hardware cursor too big, but differently:
we have to obey the font size actually used. At this point, fix the
problem that the cursor got messed up by the initialization of
unrelated screens.
 1.18 07-Jul-2001  thorpej branches: 1.18.2;
bcopy -> memcpy
 1.17 05-Jul-2001  thorpej If using the hardware cursor, make sure the cursor shape is initialized,
otherwise we won't be able to see anything if the system firmware has
either not initialized it, or initialized it to "invlisible".
 1.16 08-Jun-2000  cgd branches: 1.16.4;
don't include ISA headers. these have been properly abstracted so that
the ISA headers are unnecessary, and they're used by PCI VGA. There may
not be any ISA at all.
 1.15 26-Jan-2000  ad branches: 1.15.2;
Argh - add initialization that got lost during editing of previous addition.
 1.14 25-Jan-2000  ad Finish with fixing the SOFTCURSOR stuff.
 1.13 12-Jan-2000  ad Make PCDISPLAY_SOFTCURSOR work as it should.
 1.12 05-Jan-2000  ad Add and use pcdisplay_cursor_init(). Still a couple of nits with this, I
will resolve when I can test properly.
 1.11 05-Jan-2000  ad Back out previous. A proper fix will follow.
 1.10 06-Dec-1999  ad If the vga driver isn't present in the kernel and PCDISPLAY_SOFTCURSOR
is set, then pcdisplay_cursor() should disable the hardware cursor first
time it is called.
 1.9 29-Sep-1999  ad branches: 1.9.2; 1.9.8;
PCDISPLAY_SOFTCURSOR: invert foreground too.
 1.8 19-Sep-1999  ad When moving the software cursor on an inactive screen, save character and
attribute from backing store, not display adapter.
 1.7 19-Sep-1999  ad - mc6845's cursor is disabled by punching bit 6 of cursor start register.
- Add new option (PCDISPLAY_SOFTCURSOR) that provides a large, non-blinking
cursor in software.
 1.6 24-Jul-1998  drochner allow the displayed area to start anywhere in display memory,
add a "dispoffset" variable to control this
 1.5 26-Jun-1998  drochner do the charcter mapping in a separate function
 1.4 20-Jun-1998  drochner adapt to wscons changes, treat incoming characters always as ISO
(ie, convert to IBM)
 1.3 17-Jun-1998  drochner do the former at one more place
 1.2 17-Jun-1998  drochner avoid sign extension if a character >=128 is passed
 1.1 28-May-1998  drochner Put definitions and subroutines needed for all PC display adapters
(MGA/GCA and compatibles) into global headers / source files.
Let the VGA driver use them.
 1.9.8.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.9.2.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.15.2.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.16.4.5 27-Aug-2002  nathanw Catch up to -current.
 1.16.4.4 01-Aug-2002  nathanw Catch up to -current.
 1.16.4.3 14-Nov-2001  nathanw Catch up to -current.
 1.16.4.2 21-Sep-2001  nathanw Catch up to -current.
 1.16.4.1 24-Aug-2001  nathanw Catch up with -current.
 1.18.2.3 06-Sep-2002  jdolecek sync kqueue branch with HEAD
 1.18.2.2 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.18.2.1 13-Sep-2001  thorpej Update the kqueue branch to HEAD.
 1.20.8.2 29-Aug-2002  gehenna catch up with -current.
 1.20.8.1 15-Jul-2002  gehenna catch up with -current.
 1.25.8.2 12-Aug-2007  bouyer Pull up following revision(s) (requested by mjf in ticket #11348):
Pull up following revision(s) (requested by mjf in ticket #11348):
sys/dev/ic/pcdisplay_subr.c: revision 1.33 via patch
sys/dev/ic/vga_raster.c: revision 1.29 via patch
sys/dev/ic/vga.c: revision 1.95 via patch
sys/dev/rasops/rasops.c: revision 1.56 via patch
sys/dev/isa/ega.c: revision 1.23 via patch
Implement bounds checking in some places in display driver code to avoid
the possibility of a local user panic.
Set the 'ri' pointer before use.
 1.25.8.1 07-Jun-2004  tron branches: 1.25.8.1.2; 1.25.8.1.4;
Pull up revision 1.26 (requested by recht in ticket #451):
PR/19925: David Ferlier: Add scrolling support to wscons.
 1.25.8.1.4.1 12-Aug-2007  bouyer Pull up following revision(s) (requested by mjf in ticket #11348):
Pull up following revision(s) (requested by mjf in ticket #11348):
sys/dev/ic/pcdisplay_subr.c: revision 1.33 via patch
sys/dev/ic/vga_raster.c: revision 1.29 via patch
sys/dev/ic/vga.c: revision 1.95 via patch
sys/dev/rasops/rasops.c: revision 1.56 via patch
sys/dev/isa/ega.c: revision 1.23 via patch
Implement bounds checking in some places in display driver code to avoid
the possibility of a local user panic.
Set the 'ri' pointer before use.
 1.25.8.1.2.1 11-Aug-2007  bouyer Pull up following revision(s) (requested by mjf in ticket #11348):
sys/dev/ic/pcdisplay_subr.c: revision 1.33 via patch
sys/dev/ic/vga_raster.c: revision 1.29 via patch
sys/dev/ic/vga.c: revision 1.95 via patch
sys/dev/rasops/rasops.c: revision 1.56 via patch
sys/dev/isa/ega.c: revision 1.23 via patch
Implement bounds checking in some places in display driver code to avoid
the possibility of a local user panic.
Set the 'ri' pointer before use.
 1.25.6.4 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.25.6.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.25.6.2 18-Sep-2004  skrll Sync with HEAD.
 1.25.6.1 03-Aug-2004  skrll Sync with HEAD
 1.27.6.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.27.4.1 29-Apr-2005  kent sync with -current
 1.28.14.1 06-Aug-2007  ghen Pull up following revision(s) (requested by mjf in ticket #1815):
sys/dev/ic/pcdisplay_subr.c: revision 1.33 via patch
sys/dev/ic/vga_raster.c: revision 1.29 via patch
sys/dev/ic/vga.c: revision 1.95 via patch
sys/dev/rasops/rasops.c: revision 1.56 via patch
sys/dev/isa/ega.c: revision 1.23 via patch
Implement bounds checking in some places in display driver code to avoid
the possibility of a local user panic.
Set the 'ri' pointer before use.
 1.28.12.1 06-Aug-2007  ghen Pull up following revision(s) (requested by mjf in ticket #1815):
sys/dev/ic/pcdisplay_subr.c: revision 1.33 via patch
sys/dev/ic/vga_raster.c: revision 1.29 via patch
sys/dev/ic/vga.c: revision 1.95 via patch
sys/dev/rasops/rasops.c: revision 1.56 via patch
sys/dev/isa/ega.c: revision 1.23 via patch
Implement bounds checking in some places in display driver code to avoid
the possibility of a local user panic.
Set the 'ri' pointer before use.
 1.28.4.3 27-Oct-2007  yamt sync with head.
 1.28.4.2 03-Sep-2007  yamt sync with head.
 1.28.4.1 21-Jun-2006  yamt sync with head.
 1.28.2.1 06-Aug-2007  ghen Pull up following revision(s) (requested by mjf in ticket #1815):
sys/dev/ic/pcdisplay_subr.c: revision 1.33 via patch
sys/dev/ic/vga_raster.c: revision 1.29 via patch
sys/dev/ic/vga.c: revision 1.95 via patch
sys/dev/rasops/rasops.c: revision 1.56 via patch
sys/dev/isa/ega.c: revision 1.23 via patch
Implement bounds checking in some places in display driver code to avoid
the possibility of a local user panic.
Set the 'ri' pointer before use.
 1.29.12.1 24-May-2006  tron Merge 2006-05-24 NetBSD-current into the "peter-altq" branch.
 1.29.10.1 19-Apr-2006  elad sync with head.
 1.29.8.1 24-May-2006  yamt sync with head.
 1.29.6.1 22-Apr-2006  simonb Sync with head.
 1.29.4.1 09-Sep-2006  rpaulo sync with head
 1.32.28.1 15-Aug-2007  skrll Sync with HEAD.
 1.32.26.1 03-Sep-2007  wrstuden Sync w/ NetBSD-4-RC_1
 1.32.18.2 23-Oct-2007  ad Sync with head.
 1.32.18.1 20-Aug-2007  ad Sync with HEAD.
 1.32.12.1 30-Jul-2007  liamjfoy Pull up following revision(s) (requested by mjf in ticket #799):
sys/dev/ic/pcdisplay_subr.c: revision 1.33
sys/dev/wscons/wsdisplay_vcons.c: revision 1.12
sys/dev/wscons/wsdisplay_vcons.c: revision 1.13
sys/dev/ic/vga_raster.c: revision 1.29
sys/dev/pci/chipsfb.c: revision 1.10
sys/dev/ic/vga.c: revision 1.95
sys/dev/rasops/rasops.c: revision 1.56
sys/dev/isa/ega.c: revision 1.23
Implement bounds checking in some places in display driver code to avoid
the possibility of a local user panic.
Set the 'ri' pointer before use.
 1.33.12.2 28-Jul-2007  mjf Implement bounds checking in some places in display driver code to avoid
the possibility of a local user panic.
 1.33.12.1 28-Jul-2007  mjf file pcdisplay_subr.c was added on branch matt-mips64 on 2007-07-28 20:28:57 +0000
 1.33.10.1 25-Oct-2007  bouyer Sync with HEAD.
 1.33.6.1 06-Nov-2007  matt sync with HEAD
 1.33.4.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.34.42.1 05-Mar-2011  rmind sync with head
 1.34.40.1 22-Oct-2010  uebayasi Sync with HEAD (-D20101022).
 1.20 12-Nov-2014  christos more _KERNEL_OPT
 1.19 15-Mar-2009  cegger branches: 1.19.22; 1.19.38;
ansify function definitions
 1.18 14-May-2006  elad branches: 1.18.62; 1.18.72; 1.18.78;
integrate kauth.
 1.17 15-Apr-2006  jmmv Remove the getwschar and putwschar accessops from wsdisplay drivers as
requested by uwe@. These were wrong because they were receiving an
emulcookie yet they were accessops (thus having to receive an accesscookie).
Instead, just handle the WSDISPLAYIO_{GET,PUT}WSCHAR ioctls from the
driver's ioctl accessop.

As this reduces the amount of code needed to handle these operations to
two small functions in each driver, remove the WSDISPLAY_CHARFUNCS kernel
option.

Reviewed by, at least, uwe@ and macallan@. No objections in tech-kern@.
 1.16 16-Feb-2006  perry branches: 1.16.2; 1.16.4; 1.16.6;
Change "inline" back to "__inline" in .h files -- C99 is still too
new, and some apps compile things in C89 mode. C89 keywords stay.

As per core@.
 1.15 11-Dec-2005  christos branches: 1.15.2; 1.15.4; 1.15.6;
merge ktrace-lwp.
 1.14 28-Jul-2004  jmmv branches: 1.14.12;
Implement support to dynamically change wscons console and kernel colors.

Two new ioctls are added to the wsdisplay device, named WSDISPLAY_GMSGATTRS
and WSDISPLAY_SMSGATTRS, used to retrieve the actual values and set them,
respectively (the name, if you are wondering, comes from "message attributes").

A new emulop is added to the underlying display driver (only vga, for now)
which sets the new attribute for the whole screen, without having to clear
it. This is optional, which means that this also works with other drivers
that don't have this new operation.

Five new kernel options have been added, although only documented in
i386 kernels (for now):
- WSDISPLAY_CUSTOM_OUTPUT, which enables the ioctls described above to
change the colors dynamically from userland. This is enabled by default
in the GENERIC kernel (as well as others) but disabled on all INSTALL*
kernels (as this feature is useless there).
- WS_DEFAULT_COLATTR, WS_DEFAULT_MONOATTR, WS_DEFAULT_BG and WS_DEFAULT_FG,
which specify the default colors for the console at boot time. These have
the same meaning as the (already existing) WS_KERNEL_* variables.

wsconsctl is modified to add msg.default.{attrs,bg,fg} and
msg.kernel.{attrs,bg,fg} to the display part, so that colors can be changed
after boot.

Tested on NetBSD/i386 with vga (and vga in mono mode), and on NetBSD/mac68k.
No objections in tech-kern@.
 1.13 28-May-2004  christos PR/19925: David Ferlier: Add scrolling support to wscons.
 1.12 24-Mar-2004  drochner branches: 1.12.2;
remove license clauses 3 and 4 from my cpoyright notices
 1.11 07-Jul-2002  junyoung branches: 1.11.6;
- ANSI & KNF, notably remove __P.
- Some cosmetic changes.
 1.10 07-Jul-2002  junyoung Rename vc_ccol and vc_crow in struct pcdisplayscreen to cursorcol
and cursorrow, respectively, to be consistent with other members
in the structure.
 1.9 26-Jun-2002  christos PR/17402: Add wsmoused support by providing get/set char and events.
 1.8 25-Jan-2000  ad branches: 1.8.6; 1.8.8; 1.8.20;
Finish with fixing the SOFTCURSOR stuff.
 1.7 05-Jan-2000  ad Add and use pcdisplay_cursor_init(). Still a couple of nits with this, I
will resolve when I can test properly.
 1.6 19-Sep-1999  ad branches: 1.6.2;
- mc6845's cursor is disabled by punching bit 6 of cursor start register.
- Add new option (PCDISPLAY_SOFTCURSOR) that provides a large, non-blinking
cursor in software.
 1.5 12-Feb-1999  drochner change the "mapchar" interface to return a "quality" or "match level"
arguments which allows to find approximations for characters which are
not present in a font
 1.4 24-Jul-1998  drochner allow the displayed area to start anywhere in display memory,
add a "dispoffset" variable to control this
 1.3 26-Jun-1998  drochner do the charcter mapping in a separate function
 1.2 20-Jun-1998  drochner adapt to wscons changes, treat incoming characters always as ISO
(ie, convert to IBM)
 1.1 28-May-1998  drochner Put definitions and subroutines needed for all PC display adapters
(MGA/GCA and compatibles) into global headers / source files.
Let the VGA driver use them.
 1.6.2.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.8.20.1 15-Jul-2002  gehenna catch up with -current.
 1.8.8.1 06-Sep-2002  jdolecek sync kqueue branch with HEAD
 1.8.6.1 01-Aug-2002  nathanw Catch up to -current.
 1.11.6.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.11.6.2 18-Sep-2004  skrll Sync with HEAD.
 1.11.6.1 03-Aug-2004  skrll Sync with HEAD
 1.12.2.1 07-Jun-2004  tron Pull up revision 1.13 (requested by recht in ticket #451):
PR/19925: David Ferlier: Add scrolling support to wscons.
 1.14.12.1 21-Jun-2006  yamt sync with head.
 1.15.6.1 22-Apr-2006  simonb Sync with head.
 1.15.4.1 09-Sep-2006  rpaulo sync with head
 1.15.2.1 18-Feb-2006  yamt sync with head.
 1.16.6.1 24-May-2006  tron Merge 2006-05-24 NetBSD-current into the "peter-altq" branch.
 1.16.4.1 19-Apr-2006  elad sync with head.
 1.16.2.1 24-May-2006  yamt sync with head.
 1.18.78.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.18.72.1 28-Apr-2009  skrll Sync with HEAD.
 1.18.62.1 04-May-2009  yamt sync with head.
 1.19.38.1 11-Jan-2015  snj Pull up following revision(s) (requested by chs in ticket #401):
distrib/sets/lists/modules/md.amd64: revisions 1.46, 1.47 via patch
distrib/sets/lists/modules/md.i386: revisions 1.49, 1.50
sys/dev/ic/pcdisplayvar.h: revision 1.20
sys/dev/ic/vgavar.h: revision 1.32
sys/external/bsd/drm/dist/bsd-core/drm_drv.c: revision 1.26
sys/external/bsd/drm2/dist/drm/drm_agpsupport.c: revisions 1.5, 1.6
sys/external/bsd/drm2/dist/drm/drm_pci.c: revisions 1.4, 1.5
sys/external/bsd/drm2/dist/drm/drm_stub.c: revisions 1.6-1.8
sys/external/bsd/drm2/dist/drm/i915/i915_drv.h: revision 1.11
sys/external/bsd/drm2/dist/drm/radeon/cik.c: revision 1.3
sys/external/bsd/drm2/dist/drm/radeon/ni.c: revision 1.3
sys/external/bsd/drm2/dist/drm/radeon/si.c: revision 1.3
sys/external/bsd/drm2/dist/include/drm/drmP.h: revisions 1.8, 1.9
sys/external/bsd/drm2/dist/include/drm/drm_agpsupport.h: revisions 1.3, 1.4
sys/external/bsd/drm2/drm/drm_drv.c: revision 1.11
sys/external/bsd/drm2/drm/drm_module.c: revision 1.9
sys/external/bsd/drm2/drm/drm_sysctl.c: revisions 1.1-1.4
sys/external/bsd/drm2/drm/drm_vm.c: revision 1.7
sys/external/bsd/drm2/drm/files.drmkms: revisions 1.8, 1.9
sys/external/bsd/drm2/i915drm/files.i915drmkms: revision 1.9
sys/external/bsd/drm2/i915drm/i915_module.c: revisions 1.4, 1.5
sys/external/bsd/drm2/include/drm/drm_sysctl.h: revisions 1.1, 1.2
sys/external/bsd/drm2/include/linux/hdmi.h: revisions 1.3-1.5
sys/external/bsd/drm2/include/linux/module.h: revision 1.5
sys/external/bsd/drm2/include/linux/moduleparam.h: revisions 1.3, 1.4
sys/external/bsd/drm2/include/linux/pci.h: revision 1.11
sys/external/bsd/drm2/linux/linux_module.c: revision 1.5
sys/external/bsd/drm2/nouveau/files.nouveau: revision 1.4
sys/external/bsd/drm2/nouveau/nouveau_module.c: revision 1.3
sys/external/bsd/drm2/pci/drm_pci.c: revision 1.8
sys/external/bsd/drm2/pci/drm_pci_module.c: revision 1.3
sys/external/bsd/drm2/radeon/radeon_module.c: revision 1.3
sys/external/bsd/drm2/ttm/files.ttm: revision 1.1
sys/modules/drm2pci/Makefile: file removal
sys/modules/drmkms/Makefile: revisions 1.4-1.7
sys/modules/drmkms_linux/Makefile: revision 1.5
sys/modules/drmkms_pci/Makefile: revisions 1.3, 1.4
sys/modules/i915drmkms/Makefile: revisions 1.5-1.7
Split drm ttm config into a separate file.
--
Fix module build of drmkms_linux.
--
Remove vestigial drm2pci module, replaced by drmkms_pci.
--
fix the module class.
--
add the drmkms modules
--
make a drm_agp_destroy() function to resolve the circular dependency between
drmkms and drmkms_pci
--
finalize the idr code.
--
add drm_agp_destroy
--
fix drmkms module path for xen.
--
fix build failure.
/tmp/bracket/build/2014.11.10.22.43.46-i386/src/sys/external/bsd/drm2/include/linux/pci.h:36:20: fatal error: acpica.h: No such file or directory
--
make this work: add agpsupport and sysctl code
--
move agpsupport to drmkms to avoid circular dependencies.
--
turn on dynamic ldscript creation to handle link set symbol definitions
used in the automatic sysctl creation.
--
Add __link_set based code to automatically convert the linux module parameters
into sysctls.
--
this module needs MKLDSCRIPT too now
--
more _KERNEL_OPT
--
prettify and add to all the modules that have it.
--
fix description setting.
--
Adjust flags to allow building with clang.
--
Fix build with clang.
--
Drop casts in favour of expressions that actually give the right
pointer.
--
Move all PCI/AGP code back to drmkms_pci module where it belongs.
--
Use correct length for hdmi_infoframe_header_pack in <linux/hdmi.h>.
Fixes PR kern/49411.
--
Back out previous, fix PR kern/49411 correctly.
frame->header.length is not initialized in the vendor packet case.
Instead, make hdmi_infoframe_header_pack take the packet length and
subtract the size of the header when packing the header.
(Could make it take the payload length instead, but for callers it is
more convenient to have a name for the whole packet length.)
--
Fix bounds checking in hdmi_infoframe_header_pack (PR kern/49411).
--
Trivial build fix for no options SYSCTL_INCLUDE_DESCR case, to
avoid -Werror.
OK christos@ and riastradh@
--
fix debugging compilation (ALL kernel)
--
nouveau_nv50_fence.c needs -Wno-shadow.
--
fix a confusion between dev_t and devmajor_t, and include the primary
minor when calling makedev().
 1.19.22.1 03-Dec-2017  jdolecek update from HEAD
 1.22 15-Sep-2025  thorpej Encapsulate what's needed to attach an I2C bus into a iicbus_attach()
inline.
 1.21 31-Aug-2025  thorpej Don't rely on pcfiic_attach() to print the newline.
 1.20 25-Sep-2022  thorpej Remove unnecessary include of <sys/malloc.h>.
 1.19 07-Aug-2021  thorpej branches: 1.19.2;
Merge thorpej-cfargs2.
 1.18 24-Apr-2021  thorpej branches: 1.18.2; 1.18.8;
Merge thorpej-cfargs branch:

Simplify and make extensible the config_search() / config_found() /
config_attach() interfaces: rather than having different variants for
which arguments you want pass along, just have a single call that
takes a variadic list of tag-value arguments.

Adjust all call sites:
- Simplify wherever possible; don't pass along arguments that aren't
actually needed.
- Don't be explicit about what interface attribute is attaching if
the device only has one. (More simplification.)
- Add a config_probe() function to be used in indirect configuiration
situations, making is visibly easier to see when indirect config is
in play, and allowing for future change in semantics. (As of now,
this is just a wrapper around config_match(), but that is an
implementation detail.)

Remove unnecessary or redundant interface attributes where they're not
needed.

There are currently 5 "cfargs" defined:
- CFARG_SUBMATCH (submatch function for direct config)
- CFARG_SEARCH (search function for indirect config)
- CFARG_IATTR (interface attribte)
- CFARG_LOCATORS (locators array)
- CFARG_DEVHANDLE (devhandle_t - wraps OFW, ACPI, etc. handles)

...and a sentinel value CFARG_EOL.

Add some extra sanity checking to ensure that interface attributes
aren't ambiguous.

Use CFARG_DEVHANDLE in MI FDT, OFW, and ACPI code, and macppc and shark
ports to associate those device handles with device_t instance. This
will trickle trough to more places over time (need back-end for pre-OFW
Sun OBP; any others?).
 1.17 23-Dec-2019  thorpej branches: 1.17.10;
pcfiic_i2c_exec(): No need to check 'cold' to force I2C_F_POLL; the i2c
upper layer does it for us.
 1.16 22-Dec-2019  thorpej Cleanup i2c bus acquire / release, centralizing all of the logic into
iic_acquire_bus() / iic_release_bus(). "acquire" and "release" hooks
no longer need to be provided by back-end controller drivers (only if
they need special handling, e.g. powering on the i2c controller).
This results in the removal of a bunch of rendundant code from each
back-end controller driver.

Assert that we are not in hard interrupt context in iic_acquire_bus(),
iic_exec(), and iic_release_bus().
 1.15 11-Jan-2016  jdc branches: 1.15.18;
Always take the bus lock (avoids collisions when drivers set I2C_F_POLL).
 1.14 04-Jan-2016  jdc Redo r1.12 - process cmd and value buffers in pcfiic_xmit().
Avoids allocating a temporary buffer for writes using both buffers.
 1.13 03-Jan-2016  jdc Remove duplicate register definitions and merge them all into pcf8584reg.h.
No functional change.
 1.12 16-Dec-2015  jdc Allow pcfiic to handle i2c writes using cmdbuf for the register, and buf for
the value to be written. Prior to this, we would send an empty write command
to the correct i2c address, plus an empty write command to the device at the
i2c address of the first byte of buf.
 1.11 20-Jan-2014  jdc branches: 1.11.6;
Remove the check for (cmdlen > 0) when writing. When i2cscan sends a
quick_write, the command length is 0, so we were previously returning
success for every address in this case.
 1.10 15-Sep-2013  martin Remove unused variable
 1.9 16-Apr-2010  dyoung branches: 1.9.8; 1.9.18; 1.9.22;
#include <sys/bus.h> instead of <machine/bus.h>. No functional change
intended.
 1.8 31-Mar-2010  macallan remove a now useless bus_space_barrier()
 1.7 31-Mar-2010  macallan Do as OpenSolaris does and read the status register after each write.
Now this driver works on my Blade 2500.
 1.6 28-Feb-2010  martin branches: 1.6.2;
Update pcf8584 driver from OpenBSD
 1.5 28-Apr-2008  martin branches: 1.5.20;
Remove clause 3 and 4 from TNF licenses
 1.4 08-Apr-2008  cegger branches: 1.4.2; 1.4.4;
use aprint_*_dev and device_xname
 1.3 26-Mar-2008  tnn convert pcf8584 to device_t.
 1.2 19-Oct-2007  ad branches: 1.2.16;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.1 14-Apr-2007  tnn branches: 1.1.2; 1.1.4; 1.1.6; 1.1.12; 1.1.14; 1.1.16; 1.1.20;
Add envctrl(4): Sun Ultra Enterprise 450 environmental monitoring driver.
Also add accompanying i2c controller driver, pcf8584.
Both written by me. Some cosmetic improvements from Iain Hibbert.
ok <martin>
 1.1.20.1 25-Oct-2007  bouyer Sync with HEAD.
 1.1.16.3 27-Oct-2007  yamt sync with head.
 1.1.16.2 03-Sep-2007  yamt sync with head.
 1.1.16.1 14-Apr-2007  yamt file pcf8584.c was added on branch yamt-lazymbuf on 2007-09-03 14:35:04 +0000
 1.1.14.1 06-Nov-2007  matt sync with HEAD
 1.1.12.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.1.6.2 11-Jul-2007  mjf Sync with head.
 1.1.6.1 14-Apr-2007  mjf file pcf8584.c was added on branch mjf-ufs-trans on 2007-07-11 20:06:05 +0000
 1.1.4.3 23-Oct-2007  ad Sync with head.
 1.1.4.2 09-Jun-2007  ad Sync with head.
 1.1.4.1 14-Apr-2007  ad file pcf8584.c was added on branch vmlocking on 2007-06-09 21:37:16 +0000
 1.1.2.2 15-Apr-2007  yamt sync with head.
 1.1.2.1 14-Apr-2007  yamt file pcf8584.c was added on branch yamt-idlelwp on 2007-04-15 16:03:22 +0000
 1.2.16.2 02-Jun-2008  mjf Sync with HEAD.
 1.2.16.1 03-Apr-2008  mjf Sync with HEAD.
 1.4.4.3 11-Aug-2010  yamt sync with head.
 1.4.4.2 11-Mar-2010  yamt sync with head
 1.4.4.1 16-May-2008  yamt sync with head.
 1.4.2.1 18-May-2008  yamt sync with head.
 1.5.20.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.6.2.1 30-May-2010  rmind sync with head
 1.9.22.1 18-May-2014  rmind sync with head
 1.9.18.2 03-Dec-2017  jdolecek update from HEAD
 1.9.18.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.9.8.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.11.6.2 19-Mar-2016  skrll Sync with HEAD
 1.11.6.1 27-Dec-2015  skrll Sync with HEAD (as of 26th Dec)
 1.15.18.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.17.10.1 21-Mar-2021  thorpej Give config_found() the same variadic arguments treatment as
config_search(). This commit only adds the CFARG_EOL sentinel
to the existing config_found() calls. Conversion of config_found_sm_loc()
and config_found_ia() call sites will be in subsequent commits.
 1.18.8.1 04-Aug-2021  thorpej Adapt to CFARGS().
 1.18.2.1 14-May-2021  thorpej Update the pcfiic driver for the new i2c device enumeration scheme.
Push the multiple-channels complexity up into the ebus front-end,
as that specific to a particular Sun model of controller. Now
the BBC-type controllers get multiple I2C bus instances attached to
them.
 1.19.2.2 12-Sep-2021  thorpej - Improve some comments.
- Update pcfiic_i2c_exec() for the channel split (might fix an issue
spotted by tnn@ in testing).
 1.19.2.1 09-Aug-2021  thorpej Port over the changes from thorpej-i2c-spi-conf to thorpej-i2c-spi-conf2,
which is based on a newer HEAD revision.
 1.3 05-Jan-2025  andvar fix various typos in comments.
 1.2 03-Jan-2016  jdc branches: 1.2.56;
Remove duplicate register definitions and merge them all into pcf8584reg.h.
No functional change.
 1.1 14-Apr-2007  tnn branches: 1.1.2; 1.1.4; 1.1.6; 1.1.16; 1.1.86; 1.1.106;
Add envctrl(4): Sun Ultra Enterprise 450 environmental monitoring driver.
Also add accompanying i2c controller driver, pcf8584.
Both written by me. Some cosmetic improvements from Iain Hibbert.
ok <martin>
 1.1.106.1 19-Mar-2016  skrll Sync with HEAD
 1.1.86.1 03-Dec-2017  jdolecek update from HEAD
 1.1.16.2 03-Sep-2007  yamt sync with head.
 1.1.16.1 14-Apr-2007  yamt file pcf8584reg.h was added on branch yamt-lazymbuf on 2007-09-03 14:35:04 +0000
 1.1.6.2 11-Jul-2007  mjf Sync with head.
 1.1.6.1 14-Apr-2007  mjf file pcf8584reg.h was added on branch mjf-ufs-trans on 2007-07-11 20:06:06 +0000
 1.1.4.2 09-Jun-2007  ad Sync with head.
 1.1.4.1 14-Apr-2007  ad file pcf8584reg.h was added on branch vmlocking on 2007-06-09 21:37:17 +0000
 1.1.2.2 15-Apr-2007  yamt sync with head.
 1.1.2.1 14-Apr-2007  yamt file pcf8584reg.h was added on branch yamt-idlelwp on 2007-04-15 16:03:22 +0000
 1.2.56.1 02-Aug-2025  perseant Sync with HEAD
 1.6 22-Dec-2019  thorpej branches: 1.6.12; 1.6.22;
Cleanup i2c bus acquire / release, centralizing all of the logic into
iic_acquire_bus() / iic_release_bus(). "acquire" and "release" hooks
no longer need to be provided by back-end controller drivers (only if
they need special handling, e.g. powering on the i2c controller).
This results in the removal of a bunch of rendundant code from each
back-end controller driver.

Assert that we are not in hard interrupt context in iic_acquire_bus(),
iic_exec(), and iic_release_bus().
 1.5 03-Jan-2016  jdc branches: 1.5.18;
Remove duplicate register definitions and merge them all into pcf8584reg.h.
No functional change.
 1.4 28-Feb-2010  martin branches: 1.4.20; 1.4.38;
Update pcf8584 driver from OpenBSD
 1.3 28-Apr-2008  martin branches: 1.3.20;
Remove clause 3 and 4 from TNF licenses
 1.2 26-Mar-2008  tnn branches: 1.2.2; 1.2.4;
convert pcf8584 to device_t.
 1.1 14-Apr-2007  tnn branches: 1.1.2; 1.1.4; 1.1.6; 1.1.16; 1.1.36;
Add envctrl(4): Sun Ultra Enterprise 450 environmental monitoring driver.
Also add accompanying i2c controller driver, pcf8584.
Both written by me. Some cosmetic improvements from Iain Hibbert.
ok <martin>
 1.1.36.2 02-Jun-2008  mjf Sync with HEAD.
 1.1.36.1 03-Apr-2008  mjf Sync with HEAD.
 1.1.16.2 03-Sep-2007  yamt sync with head.
 1.1.16.1 14-Apr-2007  yamt file pcf8584var.h was added on branch yamt-lazymbuf on 2007-09-03 14:35:05 +0000
 1.1.6.2 11-Jul-2007  mjf Sync with head.
 1.1.6.1 14-Apr-2007  mjf file pcf8584var.h was added on branch mjf-ufs-trans on 2007-07-11 20:06:07 +0000
 1.1.4.2 09-Jun-2007  ad Sync with head.
 1.1.4.1 14-Apr-2007  ad file pcf8584var.h was added on branch vmlocking on 2007-06-09 21:37:17 +0000
 1.1.2.2 15-Apr-2007  yamt sync with head.
 1.1.2.1 14-Apr-2007  yamt file pcf8584var.h was added on branch yamt-idlelwp on 2007-04-15 16:03:22 +0000
 1.2.4.2 11-Mar-2010  yamt sync with head
 1.2.4.1 16-May-2008  yamt sync with head.
 1.2.2.1 18-May-2008  yamt sync with head.
 1.3.20.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.4.38.1 19-Mar-2016  skrll Sync with HEAD
 1.4.20.1 03-Dec-2017  jdolecek update from HEAD
 1.5.18.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.6.22.1 09-Aug-2021  thorpej Port over the changes from thorpej-i2c-spi-conf to thorpej-i2c-spi-conf2,
which is based on a newer HEAD revision.
 1.6.12.1 14-May-2021  thorpej Update the pcfiic driver for the new i2c device enumeration scheme.
Push the multiple-channels complexity up into the ebus front-end,
as that specific to a particular Sun model of controller. Now
the BBC-type controllers get multiple I2C bus instances attached to
them.
 1.65 17-Nov-2022  riastradh pckbc(4): Stop waiting 8us before reading each data byte.

This appears to have copied from pccons(4), where it was introduced
by mycroft@ in 1994 in sys/arch/i386/isa/pccons.c rev. 1.63 with the
commit message `Rename two files.'. No justification was given.

This delay was in a hard interrupt handler, and an MP-unsafe one to
boot, so it could hold up system responsiveness by delaying interrupt
handling and blocking other users of the legacy kernel lock.

The delay remains in the pckbc_wait_output loop to set a command
byte, which is not used in the interrupt path (and I suspect is used
only on boot during attach anyway).
 1.64 28-Oct-2022  riastradh pckbc(4): Simplify the (disabled) logic to check keyboard port.

No functional change intended -- just reduces code duplication (and
fixes wrong-number-of-arguments in #if 0 logic).
 1.63 28-Oct-2022  riastradh pckbport(4): C99 initializers

No functional change intended.
 1.62 01-May-2020  riastradh Zero rndsource before using it.

XXX pullup
 1.61 10-Nov-2019  chs in many device attach paths, allocate memory with M_WAITOK instead of M_NOWAIT
and remove code to handle failures that can no longer happen.
 1.60 01-May-2019  mlelstv slotdata might not be attached, don't use it then.
 1.59 14-Jul-2016  msaitoh branches: 1.59.18;
- Use aprint*() more in xxx_attach().
- Add missing aprint_naive("\n").
- Remove extra spaces and tabs.
- KNF.
 1.58 13-Apr-2015  riastradh Convert sys/dev to use <sys/rndsource.h>.
 1.57 10-Aug-2014  tls branches: 1.57.4;
Merge tls-earlyentropy branch into HEAD.
 1.56 11-Jan-2014  jakllsch branches: 1.56.2;
Do not take data from the controller in interrupt handler if we are polling.
 1.55 15-Sep-2013  martin Remove unused variable
 1.54 13-Oct-2012  jdc branches: 1.54.2;
Add two flags to keyboard/mouse attachment:
PCKBC_CANT_TRANSLATE for keyboards that cannot translate to XT scancodes
PCKBC_NEED_AUXWRITE for mice that don't probe first time
These flags can be set by the port-specific attachments.

Add the translation table and function to handle set 2 to set 1 keyboard
translation in software.

Based on OpenBSD sys/dev/ic/pckbc.c revisions 1.10, 1.16, 1.17, and
sys/dev/pckbc/pckbd.c revision 1.15, and 8042 scan code information at:

http://www.computer-engineering.org/ps2keyboard/

Note, that this changes the signature of pckbc_cnattach(), so ride the
kernel version bump for namei.
 1.53 02-Feb-2012  tls branches: 1.53.2; 1.53.6;
Entropy-pool implementation move and cleanup.

1) Move core entropy-pool code and source/sink/sample management code
to sys/kern from sys/dev.

2) Remove use of NRND as test for presence of entropy-pool code throughout
source tree.

3) Remove use of RND_ENABLED in device drivers as microoptimization to
avoid expensive operations on disabled entropy sources; make the
rnd_add calls do this directly so all callers benefit.

4) Fix bug in recent rnd_add_data()/rnd_add_uint32() changes that might
have lead to slight entropy overestimation for some sources.

5) Add new source types for environmental sensors, power sensors, VM
system events, and skew between clocks, with a sample implementation
for each.

ok releng to go in before the branch due to the difficulty of later
pullup (widespread #ifdef removal and moved files). Tested with release
builds on amd64 and evbarm and live testing on amd64.
 1.52 19-Nov-2011  tls branches: 1.52.2;
First step of random number subsystem rework described in
<20111022023242.BA26F14A158@mail.netbsd.org>. This change includes
the following:

An initial cleanup and minor reorganization of the entropy pool
code in sys/dev/rnd.c and sys/dev/rndpool.c. Several bugs are
fixed. Some effort is made to accumulate entropy more quickly at
boot time.

A generic interface, "rndsink", is added, for stream generators to
request that they be re-keyed with good quality entropy from the pool
as soon as it is available.

The arc4random()/arc4randbytes() implementation in libkern is
adjusted to use the rndsink interface for rekeying, which helps
address the problem of low-quality keys at boot time.

An implementation of the FIPS 140-2 statistical tests for random
number generator quality is provided (libkern/rngtest.c). This
is based on Greg Rose's implementation from Qualcomm.

A new random stream generator, nist_ctr_drbg, is provided. It is
based on an implementation of the NIST SP800-90 CTR_DRBG by
Henric Jungheim. This generator users AES in a modified counter
mode to generate a backtracking-resistant random stream.

An abstraction layer, "cprng", is provided for in-kernel consumers
of randomness. The arc4random/arc4randbytes API is deprecated for
in-kernel use. It is replaced by "cprng_strong". The current
cprng_fast implementation wraps the existing arc4random
implementation. The current cprng_strong implementation wraps the
new CTR_DRBG implementation. Both interfaces are rekeyed from
the entropy pool automatically at intervals justifiable from best
current cryptographic practice.

In some quick tests, cprng_fast() is about the same speed as
the old arc4randbytes(), and cprng_strong() is about 20% faster
than rnd_extract_data(). Performance is expected to improve.

The AES code in src/crypto/rijndael is no longer an optional
kernel component, as it is required by cprng_strong, which is
not an optional kernel component.

The entropy pool output is subjected to the rngtest tests at
startup time; if it fails, the system will reboot. There is
approximately a 3/10000 chance of a false positive from these
tests. Entropy pool _input_ from hardware random numbers is
subjected to the rngtest tests at attach time, as well as the
FIPS continuous-output test, to detect bad or stuck hardware
RNGs; if any are detected, they are detached, but the system
continues to run.

A problem with rndctl(8) is fixed -- datastructures with
pointers in arrays are no longer passed to userspace (this
was not a security problem, but rather a major issue for
compat32). A new kernel will require a new rndctl.

The sysctl kern.arandom() and kern.urandom() nodes are hooked
up to the new generators, but the /dev/*random pseudodevices
are not, yet.

Manual pages for the new kernel interfaces are forthcoming.
 1.51 08-Aug-2010  isaki branches: 1.51.8;
white space -> tab.
 1.50 19-Apr-2010  dyoung Add default implementations for bus_space_is_equal(9),
bus_space_tag_create(9), and bus_space_tag_destroy(9). Use
bus_space_is_equal(9) throughout the kernel to compare
bus_space_tag_t's. Tested on i386 and on sparc64.
 1.49 22-Mar-2010  dyoung pckbc.c, vga.c: It doesn't appear to be helpful to compare two
bus_space_tag_t's in pckbc_is_console() and vga_is_console(), and MI
code should never do such a thing, so don't do it.

tcic2.c: #if 0 some diagnostic code that compares two bus_space_tag_t's.
 1.48 24-Feb-2010  dyoung branches: 1.48.2;
A pointer typedef entails trading too much flexibility to declare const
and non-const types, and the kernel uses both const and non-const
PMF qualifiers and device suspensors, so change the pmf_qual_t and
device_suspensor_t typedefs from "pointers to const" to non-pointer,
non-const types.
 1.47 08-Jan-2010  dyoung branches: 1.47.2;
Expand PMF_FN_* macros.
 1.46 12-May-2009  cegger struct device * -> device_t, no functional changes intended.
 1.45 04-Jun-2008  drochner branches: 1.45.12;
Reduce polling of the keyboard controller status by a factor of 1000.
While on real hardware hardware a poll cycle takes time in the
microsecond order of magnitude, a "legacy-free" system which emulates
the KBC in BIOS code takes milliseconds -- I'm seeing a multi-minute
delay in booting where the KBC is probed. So poll less and use delay()
to compensate so that the total wait time stays about the same.
 1.44 26-Apr-2008  cegger branches: 1.44.2; 1.44.4;
ansify
 1.43 08-Apr-2008  cegger branches: 1.43.2;
use aprint_*_dev and device_xname
 1.42 15-Mar-2008  cube Split device_t and softc for pckbc(4) and its attachments.
 1.41 29-Feb-2008  dyoung Use PMF_FN_ARGS, PMF_FN_PROTO.
 1.40 04-Jan-2008  ad branches: 1.40.2; 1.40.6;
Start detangling lock.h from intr.h. This is likely to cause short term
breakage, but the mess of dependencies has been regularly breaking the
build recently anyhow.
 1.39 09-Dec-2007  jmcneill branches: 1.39.2;
Merge jmcneill-pm branch.
 1.38 19-Oct-2007  ad branches: 1.38.2; 1.38.4; 1.38.6;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.37 09-Jul-2007  ad branches: 1.37.6; 1.37.8; 1.37.12;
Merge some of the less invasive changes from the vmlocking branch:

- kthread, callout, devsw API changes
- select()/poll() improvements
- miscellaneous MT safety improvements
 1.36 24-Jun-2007  christos PR/36538: Greg A. Woods: fix printfs to match driver name.
 1.35 11-Dec-2005  christos branches: 1.35.30; 1.35.32;
merge ktrace-lwp.
 1.34 27-Feb-2005  perry branches: 1.34.4;
nuke trailing whitespace
 1.33 04-Feb-2005  perry de-__P
 1.32 24-Mar-2004  drochner branches: 1.32.8; 1.32.10;
remove license clauses 3 and 4 from my cpoyright notices
 1.31 13-Mar-2004  bjh21 Abstract the interface between pckbc(4), and the pckbd(4) and pms(4)
drivers that attach to it. This allows for other host interface chips
that use the same keyboards and mice, such as the ones in the ARM
IOMD20, ARM7500, and SA-1111. The PC-compatible driver is still
called pckbc(4), and the new abstraction layer is "pckbport", so the
child devices have moved from sys/dev/pckbc to sys/dev/pckbport, which
also contains some code shared between all host controllers. To avoid
incompatibility, pckbdreg.h is still installed in
/usr/include/dev/pckbc.

In theory, this shouldn't cause any behavioural changes in the drivers
concerned. Thy just use rather more function pointers than before. Tested
on i386 and (with a new host driver) acorn32. Compiled on several other
affected architectures.
 1.30 14-Feb-2004  bjh21 Add a new MI attribute, pckbc_machdep_cnattach, and change pckbc_cnattach()
to only call pckbc_machdep_cnattach() if this is present. This allows
pckbc_machdep_cnattach() to be omitted entirely on most ports, where it only
returns ENXIO anyway.

The devices with this attribute at the moment are pc(4) on i386 and bebox, and
pckbc on sparc, where pckbc_machdep_cnattach() mysteriously returns 0 rather
than ENXIO.
 1.29 12-Dec-2003  martin Fix compilation for ports w/o __GENERIC_SOFT_INTERRUPTS_ALL_LEVELS.
 1.28 12-Dec-2003  martin In parallel to the interrupt handler pckbcintr provide two functions
pckbcintr_hard and pckbcintr_soft, which, together, do the same as
pckbcintr. The first is called from the interrupt handler, the second
from a softinterrupt at arbitrary protection level (lower or equal to
IPL_TTY). They pass data via a small ringbuffer.

The new functions are intended for platforms that, due to
hardware/firmware restrictions are not able to make pckbcintr called at
IPL_TTY, like Krups javastations. Using the monolithic pckbcintr on
these plattforms leads to the input handlers for the slot data to be
run at elevated priority, causing various race conditions.
 1.27 02-Nov-2003  wiz Fix some typos. From Tom Cosgrove via jmc@openbsd.
 1.26 12-Jun-2003  uwe branches: 1.26.2;
Request KBC_SELFTEST in pckbc_cnattach(), hidden under #ifdef
PCKBC_CNATTACH_SELFTEST. On machines where we boot on cold iron
(e.g. netwinder) we need this to init the pckbc.
 1.25 10-Jun-2003  grant wrap a debug message in #ifdef PCKBCDEBUG.

ok'd by simonb. fixes my PR kern/18441.
 1.24 01-Jan-2003  thorpej Use aprint_normal() in cfprint routines.
 1.23 01-Nov-2002  jdolecek pckbc_poll_data1(): make sure the loop variable is always initialized
this potential problem found by Krister Walfridsson
 1.22 27-Sep-2002  thorpej Introduce a new routine, config_match(), which invokes the
cfattach->ca_match function in behalf of the caller. Use it
rather than invoking cfattach->ca_match directly.
 1.21 18-Dec-2001  soren Previous was committed by mistake; revert.
 1.20 15-Dec-2001  soren To make dev/pcmcia work on platforms with 64-bit bus_addr_t and
32-bit bus_size_t (sparc), change the pcmcia_mem_map(9) offsetp
argument to bus_size_t as it is used as a bus_space offset.
 1.19 06-Dec-2001  augustss Small change to Christos' fix: allow malloc() to return NULL, but complain
if it does.
 1.18 06-Dec-2001  christos change the malloc arg from NOWAIT to WAITOK; pointed out by lennard.
 1.17 06-Dec-2001  christos PR/14852: Martin Husemann: Allocate the slotdata the the probed slot before
we call the configuration function. Thanks lennard for pointing it out.
XXX: Someone should look this over and make sure that the current strategy
makes sense.
 1.16 13-Nov-2001  lukem add/cleanup RCSID
 1.15 31-Jul-2001  jdolecek Make console polling (cnpollc/cngetc) work on IBM PS/2 keyboard controller
using level triggered interrupts, which livelocks calling intr routine
if the data register is not read in the interrupt routine, as it's case
when polling after interrupts are enabled during boot.

Block all interrupts when polling for keypress, and modify intr routine
to read and store value from data register. The latter one is to avoid
losing a keypress when one would manage to press a key when kernel is
not in spl-guarded code section.

Tested with classic pccons, 'pcconskbd at pckbc' and 'pckbd at pckbc'
configurations, on i386.
 1.14 23-Jul-2001  jdolecek Since ~all pckbc_poll_data1() callers had the appropriate pckbc
tag handy and we are going to need more of it in pckbc_poll_data1() soon,
change pckbc_poll_data1() to accept it as first arg. iot, ioh_d, ioh_c are
no longer passed separately. Use fabricated pckbc tag for calls from
arch/arc/jazz/pckbc_jazzio.c and dev/isa/pckbc_isa.c.
 1.13 07-Jul-2001  thorpej branches: 1.13.2;
bzero -> memset
 1.12 07-Jul-2001  thorpej bcopy -> memcpy
 1.11 17-Jun-2001  jdolecek make pckbc_slot_names[], pckbc_portcmd const
 1.10 02-Jun-2001  jdolecek Back the last revision off, upon Bill Sommerfeld's request
 1.9 02-Jun-2001  jdolecek When polling, raise priority level to tty, to block keyboard interrupts
when the system is "warm", i.e. interrupts are not blocked anymore.
This seems to be necessary on my PS/2 Model 70 keyboard - without this,
system ends up in endless loop calling the keyboard intr routine if a key
is pressed when polling. This _may_ be just specific to level-triggered
interrupts PS/2 MCA uses, though it's more likely it's just the way the
particular keyboard controller works.

Discussed on tech-kern@.
 1.8 17-May-2001  drochner Revert previous change; this breaks for the old controllers which 1.6
should help for. Instead, weaken the "echo" test: don't insist in
getting the same value back which was written.
 1.7 15-May-2001  christos Try the kbc_auxtest if the random write/read to the aux port fails (it returns
0xfe on my gateway 2000 circa 1993). That should not affect broken controllers
that choke on the kbc_auxtest, because for those the write/read test succeeds.
 1.6 09-Apr-2001  drochner Change the way the aux port is probed for. Some older chipsets w/o
mouse port seem to interpret the "test aux port" (0xa9) command differently,
leading to a non-working keyboard.
Now we try to echo a byte through the aux port by means of the "echo aux"
(0xd3) command, which is what Linux does.
Thanks to Christoph Badura for detailed reports and testing.
 1.5 09-Jun-2000  soda branches: 1.5.2; 1.5.4; 1.5.6;
increase number of parameters of pckbc_cnattach(), since offset of command port
is not 4 (KBCMDP), but 1 on jazz based platforms of arc port.
 1.4 06-Jun-2000  sommerfeld Fix previous change: guard against missing subdevices of pckbc.
 1.3 05-Jun-2000  sommerfeld If rnd is configured into the kernel, do rnd(4) entropy collection
from devices connected to pckbc:
- Do actual sample collection in pckbc.
- Add rndsource_element_t to the slot data.
- Change pckbc_set_inputhandler() to take an additional argument,
the name of the device, which is (eventually) passed into
rnd_attach_source() to identify the source.
- Change callers of pckbc_set_inputhander() appropriately.
 1.2 23-Mar-2000  thorpej branches: 1.2.2;
New callout mechanism with two major improvements over the old
timeout()/untimeout() API:
- Clients supply callout handle storage, thus eliminating problems of
resource allocation.
- Insertion and removal of callouts is constant time, important as
this facility is used quite a lot in the kernel.

The old timeout()/untimeout() API has been removed from the kernel.
 1.1 03-Dec-1999  thorpej branches: 1.1.2;
Split the PC-like keyboard controller driver into chip back-end and
bus front-end.
 1.1.2.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.2.2.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.5.6.7 03-Jan-2003  thorpej Sync with HEAD.
 1.5.6.6 11-Nov-2002  nathanw Catch up to -current
 1.5.6.5 18-Oct-2002  nathanw Catch up to -current.
 1.5.6.4 08-Jan-2002  nathanw Catch up to -current.
 1.5.6.3 14-Nov-2001  nathanw Catch up to -current.
 1.5.6.2 24-Aug-2001  nathanw Catch up with -current.
 1.5.6.1 21-Jun-2001  nathanw Catch up to -current.
 1.5.4.3 21-Apr-2001  bouyer Sync with HEAD
 1.5.4.2 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.5.4.1 09-Jun-2000  bouyer file pckbc.c was added on branch thorpej_scsipi on 2000-11-20 11:40:51 +0000
 1.5.2.1 16-Aug-2001  tv Pullup [drochner]:

sys/dev/ic/pckbc.c 1.6-1.8

Change the way the aux port is probed for. Some older chipsets w/o
mouse port seem to interpret the "test aux port" (0xa9) command differently,
leading to a non-working keyboard.
 1.13.2.3 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.13.2.2 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.13.2.1 03-Aug-2001  lukem update to -current
 1.26.2.5 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.26.2.4 04-Feb-2005  skrll Sync with HEAD.
 1.26.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.26.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.26.2.1 03-Aug-2004  skrll Sync with HEAD
 1.32.10.2 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.32.10.1 12-Feb-2005  yamt sync with head.
 1.32.8.1 29-Apr-2005  kent sync with -current
 1.34.4.4 17-Mar-2008  yamt sync with head.
 1.34.4.3 21-Jan-2008  yamt sync with head
 1.34.4.2 27-Oct-2007  yamt sync with head.
 1.34.4.1 03-Sep-2007  yamt sync with head.
 1.35.32.1 11-Jul-2007  mjf Sync with head.
 1.35.30.3 23-Oct-2007  ad Sync with head.
 1.35.30.2 15-Jul-2007  ad Sync with head.
 1.35.30.1 01-Jul-2007  ad Adapt to callout API change.
 1.37.12.1 25-Oct-2007  bouyer Sync with HEAD.
 1.37.8.3 23-Mar-2008  matt sync with HEAD
 1.37.8.2 09-Jan-2008  matt sync with HEAD
 1.37.8.1 06-Nov-2007  matt sync with HEAD
 1.37.6.3 06-Nov-2007  joerg Refactor PNP API:
- Make suspend/resume directly a device functionality. It consists of
three layers (class logic, device logic, bus logic), all of them being
optional. This replaces D0/D3 transitions.
- device_is_active returns true if the device was not disabled and was
not suspended (even partially), device_is_enabled returns true if the
device was enabled.
- Change pnp_global_transition into pnp_system_suspend and
pnp_system_resume. Before running any suspend/resume handlers, check
that all currently attached devices support power management and bail
out otherwise. The latter is not done for the shutdown/panic case.
- Make the former bus-specific generic network handlers a class handler.
- Make PNP message like volume up/down/toogle PNP events. Each device
can register what events they are interested in and whether the handler
should be global or not.
- Introduce device_active API for devices to mark themselve in use from
either the system or the device. Use this to implement the idle handling
for audio and input devices. This is intended to replace most ad-hoc
watchdogs as well.
- Fix somes situations in which audio resume would lose mixer settings.
- Make USB host controllers better deal with suspend in the light of
shared interrupts.
- Flush filesystem cache on suspend.
- Flush disk caches on suspend. Put ATA disks into standby on suspend as
well.
- Adopt drivers to use the new PNP API.
- Fix a critical bug in the generic cardbus layer that made D0->D3
break.
- Fix ral(4) to set if_stop.
- Convert cbb(4) to the new PNP API.
- Apply the PCI Express SCI fix on resume again.
 1.37.6.2 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.37.6.1 03-Aug-2007  jmcneill Pull in power management changes from private branch.
 1.38.6.1 11-Dec-2007  yamt sync with head.
 1.38.4.1 26-Dec-2007  ad Sync with head.
 1.38.2.1 18-Feb-2008  mjf Sync with HEAD.
 1.39.2.1 08-Jan-2008  bouyer Sync with HEAD
 1.40.6.3 05-Jun-2008  mjf Sync with HEAD.

Also fix build.
 1.40.6.2 02-Jun-2008  mjf Sync with HEAD.
 1.40.6.1 03-Apr-2008  mjf Sync with HEAD.
 1.40.2.1 24-Mar-2008  keiichi sync with head.
 1.43.2.2 17-Jun-2008  yamt sync with head.
 1.43.2.1 18-May-2008  yamt sync with head.
 1.44.4.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.44.2.4 11-Aug-2010  yamt sync with head.
 1.44.2.3 11-Mar-2010  yamt sync with head
 1.44.2.2 16-May-2009  yamt sync with head
 1.44.2.1 04-May-2009  yamt sync with head.
 1.45.12.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.47.2.2 17-Aug-2010  uebayasi Sync with HEAD.
 1.47.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.48.2.2 05-Mar-2011  rmind sync with head
 1.48.2.1 30-May-2010  rmind sync with head
 1.51.8.3 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.51.8.2 30-Oct-2012  yamt sync with head
 1.51.8.1 17-Apr-2012  yamt sync with head
 1.52.2.1 18-Feb-2012  mrg merge to -current.
 1.53.6.3 03-Dec-2017  jdolecek update from HEAD
 1.53.6.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.53.6.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.53.2.1 07-Feb-2014  sborrill Pull up the following revisions(s) (requested by skrll in ticket #1014):
sys/dev/ic/pckbc.c: revision 1.56

Do not take data from the keyboard controller in interrupt handler if
we are polling. Fixes PR/47406
 1.54.2.1 18-May-2014  rmind sync with head
 1.56.2.1 07-Apr-2014  tls Be a little more clear and consistent about harvesting entropy from devices:

1) deprecate RND_FLAG_NO_ESTIMATE

2) define RND_FLAG_COLLECT_TIME, RND_FLAG_COLLECT_VALUE

3) define RND_FLAG_ESTIMATE_TIME, RND_FLAG_ESTIMATE_VALUE

4) define RND_FLAG_DEFAULT: RND_FLAG_COLLECT_TIME|
RND_FLAG_COLLECT_VALUE|RND_FLAG_ESTIMATE_TIME

5) Make entropy harvesting from environmental sensors a little more generic
and remove it from individual sensor drivers.

6) Remove individual open-coded delta-estimators for values from a few
places in the tree (uvm, environmental drivers).

7) 0 -> RND_FLAG_DEFAULT, actually gather entropy from various drivers
that had stubbed out code, other minor cleanups.
 1.57.4.2 05-Oct-2016  skrll Sync with HEAD
 1.57.4.1 06-Jun-2015  skrll Sync with HEAD
 1.59.18.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.59.18.1 10-Jun-2019  christos Sync with HEAD
 1.22 07-Dec-2021  skrll G/C pckbc_attach_args
 1.21 13-Apr-2015  riastradh Convert sys/dev to use <sys/rndsource.h>.
 1.20 13-Oct-2012  jdc branches: 1.20.14;
Add two flags to keyboard/mouse attachment:
PCKBC_CANT_TRANSLATE for keyboards that cannot translate to XT scancodes
PCKBC_NEED_AUXWRITE for mice that don't probe first time
These flags can be set by the port-specific attachments.
 1.19 02-Feb-2012  tls branches: 1.19.6;
Entropy-pool implementation move and cleanup.

1) Move core entropy-pool code and source/sink/sample management code
to sys/kern from sys/dev.

2) Remove use of NRND as test for presence of entropy-pool code throughout
source tree.

3) Remove use of RND_ENABLED in device drivers as microoptimization to
avoid expensive operations on disabled entropy sources; make the
rnd_add calls do this directly so all callers benefit.

4) Fix bug in recent rnd_add_data()/rnd_add_uint32() changes that might
have lead to slight entropy overestimation for some sources.

5) Add new source types for environmental sensors, power sensors, VM
system events, and skew between clocks, with a sample implementation
for each.

ok releng to go in before the branch due to the difficulty of later
pullup (widespread #ifdef removal and moved files). Tested with release
builds on amd64 and evbarm and live testing on amd64.
 1.18 14-Nov-2010  uebayasi branches: 1.18.8; 1.18.12;
Directly include sys/pmf.h because this uses it.
 1.17 24-Feb-2010  dyoung branches: 1.17.2;
A pointer typedef entails trading too much flexibility to declare const
and non-const types, and the kernel uses both const and non-const
PMF qualifiers and device suspensors, so change the pmf_qual_t and
device_suspensor_t typedefs from "pointers to const" to non-pointer,
non-const types.
 1.16 08-Jan-2010  dyoung branches: 1.16.2;
Expand PMF_FN_* macros.
 1.15 15-Mar-2008  cube branches: 1.15.4;
Split device_t and softc for pckbc(4) and its attachments.
 1.14 29-Feb-2008  dyoung Use PMF_FN_ARGS, PMF_FN_PROTO.
 1.13 09-Dec-2007  jmcneill branches: 1.13.6; 1.13.10;
Merge jmcneill-pm branch.
 1.12 11-Dec-2005  christos branches: 1.12.44; 1.12.46; 1.12.56; 1.12.58;
merge ktrace-lwp.
 1.11 27-Feb-2005  perry branches: 1.11.4;
nuke trailing whitespace
 1.10 04-Feb-2005  perry de-__P
 1.9 24-Mar-2004  drochner branches: 1.9.8; 1.9.10;
remove license clauses 3 and 4 from my cpoyright notices
 1.8 13-Mar-2004  bjh21 Convert to use pckbport infrastructure -- another file I missed on the first
pass.
 1.7 12-Dec-2003  martin In parallel to the interrupt handler pckbcintr provide two functions
pckbcintr_hard and pckbcintr_soft, which, together, do the same as
pckbcintr. The first is called from the interrupt handler, the second
from a softinterrupt at arbitrary protection level (lower or equal to
IPL_TTY). They pass data via a small ringbuffer.

The new functions are intended for platforms that, due to
hardware/firmware restrictions are not able to make pckbcintr called at
IPL_TTY, like Krups javastations. Using the monolithic pckbcintr on
these plattforms leads to the input handlers for the slot data to be
run at elevated priority, causing various race conditions.
 1.6 23-Jul-2001  jdolecek branches: 1.6.20;
Since ~all pckbc_poll_data1() callers had the appropriate pckbc
tag handy and we are going to need more of it in pckbc_poll_data1() soon,
change pckbc_poll_data1() to accept it as first arg. iot, ioh_d, ioh_c are
no longer passed separately. Use fabricated pckbc tag for calls from
arch/arc/jazz/pckbc_jazzio.c and dev/isa/pckbc_isa.c.
 1.5 17-Jun-2001  jdolecek branches: 1.5.2;
make pckbc_slot_names[], pckbc_portcmd const
 1.4 09-Jun-2000  soda branches: 1.4.4; 1.4.6;
increase number of parameters of pckbc_cnattach(), since offset of command port
is not 4 (KBCMDP), but 1 on jazz based platforms of arc port.
 1.3 05-Jun-2000  sommerfeld If rnd is configured into the kernel, do rnd(4) entropy collection
from devices connected to pckbc:
- Do actual sample collection in pckbc.
- Add rndsource_element_t to the slot data.
- Change pckbc_set_inputhandler() to take an additional argument,
the name of the device, which is (eventually) passed into
rnd_attach_source() to identify the source.
- Change callers of pckbc_set_inputhander() appropriately.
 1.2 23-Mar-2000  thorpej branches: 1.2.2;
New callout mechanism with two major improvements over the old
timeout()/untimeout() API:
- Clients supply callout handle storage, thus eliminating problems of
resource allocation.
- Insertion and removal of callouts is constant time, important as
this facility is used quite a lot in the kernel.

The old timeout()/untimeout() API has been removed from the kernel.
 1.1 03-Dec-1999  thorpej branches: 1.1.2;
Split the PC-like keyboard controller driver into chip back-end and
bus front-end.
 1.1.2.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.2.2.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.4.6.2 24-Aug-2001  nathanw Catch up with -current.
 1.4.6.1 21-Jun-2001  nathanw Catch up to -current.
 1.4.4.2 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.4.4.1 09-Jun-2000  bouyer file pckbcvar.h was added on branch thorpej_scsipi on 2000-11-20 11:40:51 +0000
 1.5.2.1 03-Aug-2001  lukem update to -current
 1.6.20.5 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.6.20.4 04-Feb-2005  skrll Sync with HEAD.
 1.6.20.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.6.20.2 18-Sep-2004  skrll Sync with HEAD.
 1.6.20.1 03-Aug-2004  skrll Sync with HEAD
 1.9.10.2 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.9.10.1 12-Feb-2005  yamt sync with head.
 1.9.8.1 29-Apr-2005  kent sync with -current
 1.11.4.2 17-Mar-2008  yamt sync with head.
 1.11.4.1 21-Jan-2008  yamt sync with head
 1.12.58.1 11-Dec-2007  yamt sync with head.
 1.12.56.1 26-Dec-2007  ad Sync with head.
 1.12.46.2 23-Mar-2008  matt sync with HEAD
 1.12.46.1 09-Jan-2008  matt sync with HEAD
 1.12.44.2 06-Nov-2007  joerg Refactor PNP API:
- Make suspend/resume directly a device functionality. It consists of
three layers (class logic, device logic, bus logic), all of them being
optional. This replaces D0/D3 transitions.
- device_is_active returns true if the device was not disabled and was
not suspended (even partially), device_is_enabled returns true if the
device was enabled.
- Change pnp_global_transition into pnp_system_suspend and
pnp_system_resume. Before running any suspend/resume handlers, check
that all currently attached devices support power management and bail
out otherwise. The latter is not done for the shutdown/panic case.
- Make the former bus-specific generic network handlers a class handler.
- Make PNP message like volume up/down/toogle PNP events. Each device
can register what events they are interested in and whether the handler
should be global or not.
- Introduce device_active API for devices to mark themselve in use from
either the system or the device. Use this to implement the idle handling
for audio and input devices. This is intended to replace most ad-hoc
watchdogs as well.
- Fix somes situations in which audio resume would lose mixer settings.
- Make USB host controllers better deal with suspend in the light of
shared interrupts.
- Flush filesystem cache on suspend.
- Flush disk caches on suspend. Put ATA disks into standby on suspend as
well.
- Adopt drivers to use the new PNP API.
- Fix a critical bug in the generic cardbus layer that made D0->D3
break.
- Fix ral(4) to set if_stop.
- Convert cbb(4) to the new PNP API.
- Apply the PCI Express SCI fix on resume again.
 1.12.44.1 03-Aug-2007  jmcneill Pull in power management changes from private branch.
 1.13.10.1 03-Apr-2008  mjf Sync with HEAD.
 1.13.6.1 24-Mar-2008  keiichi sync with head.
 1.15.4.1 11-Mar-2010  yamt sync with head
 1.16.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.17.2.1 05-Mar-2011  rmind sync with head
 1.18.12.1 18-Feb-2012  mrg merge to -current.
 1.18.8.2 30-Oct-2012  yamt sync with head
 1.18.8.1 17-Apr-2012  yamt sync with head
 1.19.6.2 03-Dec-2017  jdolecek update from HEAD
 1.19.6.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.20.14.1 06-Jun-2015  skrll Sync with HEAD
 1.42 20-Jan-2020  thorpej Remove FDDI support.
 1.41 10-Nov-2019  chs branches: 1.41.2;
in many device attach paths, allocate memory with M_WAITOK instead of M_NOWAIT
and remove code to handle failures that can no longer happen.
 1.40 15-Sep-2013  martin branches: 1.40.30;
Mark a variable as potentially unused
 1.39 11-Dec-2005  christos branches: 1.39.110; 1.39.120; 1.39.126;
merge ktrace-lwp.
 1.38 17-May-2005  christos Yes, it was a cool trick >20 years ago to use "0123456789abcdef"[a] to
implement, xtoa(), but I think defining the samestring 50 times is a bit
too much. Defined HEXDIGITS and hexdigits in subr_prf.c and use it...
 1.37 27-Feb-2005  perry nuke trailing whitespace
 1.36 17-Jan-2003  matt branches: 1.36.2; 1.36.10; 1.36.12;
Make the DEFPA/DEFEA/DEFTA driver work on big-endian machines such as
powerpc or sparc64.
 1.35 25-Nov-2002  fvdl #if 0 out unused static arrays to pacify gcc 3.3
 1.34 08-Jun-2002  yamt make auto const variables static.
 1.33 13-Nov-2001  lukem branches: 1.33.8;
add/cleanup RCSID
 1.32 11-Nov-2001  mhitch After modifying transmit descriptors, write-back cache needs to be flushed.
Fixes DEFTA on R4x00 DECstations.
 1.31 13-Jun-2001  wiz branches: 1.31.2; 1.31.6;
withough -> without
 1.30 12-Jun-2001  wiz receive, not recieve
 1.29 28-May-2000  matt branches: 1.29.4;
reclaim transmitted packets on receive interrupts.
 1.28 27-Dec-1999  matt branches: 1.28.2;
Off by one error in station events.
 1.27 23-Dec-1999  matt Add some defensive code to the unsolicited event printing
 1.26 19-Sep-1999  matt branches: 1.26.2;
One more change for bigendian machines.
 1.25 19-Sep-1999  matt Make the DEFPA run under the macppc port (tested on a B&W G3). Add it to
the GENERIC config file.
 1.24 28-Sep-1998  matt Fix the receive length so it includes the extra bytes in the fddi_header.
 1.23 28-Sep-1998  matt Insert the FDDI control bytes in pdq_ifstart before we load the dmamap
and dmasync the data. Fix pdq_os_receive_pdu to use PDQ_OS_HDR_OFFSET
instead of PDQ_RX_FC_OFFSET.
 1.22 28-Sep-1998  matt Fix transmit handling (this also should speed up transmits
slightly).
 1.21 20-Sep-1998  matt Changes so that BPF readers will get the data in fddi packet aligned along
normal boundaries. This makes tcpdump much happier.
 1.20 24-Aug-1998  tv egcs brace warning
 1.19 28-May-1998  matt Another bug fix (clear transmit done before trying to queue more transmits).
 1.18 27-May-1998  matt Only enable transmit done interrupts when output ring is full.
 1.17 26-May-1998  matt Success! With these changes, the DEFTA now under NetBSD/pmax!!
 1.16 25-May-1998  matt Verify the driver work if PDQ_NO_BUS_DMA is defined.
 1.15 24-May-1998  matt More pmax coherency stuff. Getting close..
 1.14 24-May-1998  matt Fix dmamap leakages. fix transmit bug. fix receive bugs. fix mips
coherency problems.
 1.13 21-May-1998  matt Add bus_dma(9) support for the DEFxA FDDI driver
 1.12 07-Apr-1998  matt Fix problem with promicuously received packets. (ie. give them to bpf
but not fddi_input).
 1.11 08-Jun-1997  thorpej Merge pdq-970604 update.
 1.10 24-Mar-1997  thorpej Resolve conflicts from merge.
 1.9 13-Oct-1996  christos backout kprintf changes
 1.8 10-Oct-1996  christos - printf -> kprintf, sprintf -> ksprintf
- Fix an | -> ||
 1.7 10-Jul-1996  cgd add a couple of "default" entries in switch statements, to quiet -Wall.
 1.6 07-Jun-1996  cgd clean up import of new revision (June 7, 1996) from Matt Thomas.
 1.5 20-May-1996  thorpej branches: 1.5.4;
Fix conflicts during import.
 1.4 07-May-1996  christos Fixed gcc -Wall warnings.
 1.3 11-Mar-1996  thorpej Resolve conflicts from merge.
 1.2 19-Aug-1995  cgd local adaptations, and fix a could of compilation errors
 1.1 19-Aug-1995  cgd branches: 1.1.1;
Initial revision
 1.1.1.6 08-Jun-1997  thorpej Update of DEC PDQ FDDI driver, from Matt Thomas <matt@3am-software.com>.
 1.1.1.5 24-Mar-1997  thorpej Update from Matt Thomas <matt@3am-software.com>. Notable highlight:
the DEFTA (TurboChannel) card now works on the Alpha!
 1.1.1.4 07-Jun-1996  cgd New rev. from Matt Thomas (June 7, 1996), which:
(1) adds another parameter to PDQ_OS_VA_TO_PA() so that (via a
hack) the driver works on more Alpha models, and
(2) adds the definition PDQ_OS_PTR_FMT, which specifies what printf
format to use when printing pointers. (%p under NetBSD.)
 1.1.1.3 20-May-1996  thorpej Update to the Digital Equipment PDQ-based FDDI controllers, from
Matt Thomas. Now includes support for EISA (DEFEA) and first-cut of
support for TurboChannel (DEFTA) cards.
 1.1.1.2 11-Mar-1996  thorpej New snapshot of DEC PDQ-based FDDI driver, from Matt Thomas.
 1.1.1.1 19-Aug-1995  cgd Generic FDDI support by Matt Thomas. Support for DEC "PDQ" FDDI chipset
and for the PCI attachment of said chipset ("if_fpa"), also from Matt Thomas.
Arguably, pdq* doesn't belong in sys/dev/ic, but it's going to be shared by
various bus attachment devices at some point in the future, and there's no
other place that seems to fit as well.
 1.5.4.1 08-Jun-1996  cgd pull up from trunk:
>New rev. from Matt Thomas (June 7, 1996), which:
> (1) adds another parameter to PDQ_OS_VA_TO_PA() so that (via a
> hack) the driver works on more Alpha models, and
> (2) adds the definition PDQ_OS_PTR_FMT, which specifies what
> printf format to use when printing pointers. (%p under NetBSD.)
 1.26.2.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.28.2.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.29.4.5 17-Jan-2003  thorpej Sync with HEAD.
 1.29.4.4 11-Dec-2002  thorpej Sync with HEAD.
 1.29.4.3 20-Jun-2002  nathanw Catch up to -current.
 1.29.4.2 14-Nov-2001  nathanw Catch up to -current.
 1.29.4.1 21-Jun-2001  nathanw Catch up to -current.
 1.31.6.1 12-Nov-2001  thorpej Sync the thorpej-mips-cache branch with -current.
 1.31.2.2 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.31.2.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.33.8.1 20-Jun-2002  gehenna catch up with -current.
 1.36.12.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.36.10.1 29-Apr-2005  kent sync with -current
 1.36.2.2 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.36.2.1 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.39.126.1 18-May-2014  rmind sync with head
 1.39.120.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.39.110.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.40.30.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.41.2.1 25-Jan-2020  ad Sync with head.
 1.68 20-Jan-2020  thorpej Remove FDDI support.
 1.67 29-May-2019  msaitoh branches: 1.67.4;
Even if we don't use MII(4), use the common path of SIOC[GS]IFMEDIA in
sys/net/if_ethersubr.c if we can.
- Add ec_ifmedia into struct ethercom.
- ec_mii in struct ethercom is kept and used as it is. It might be used in
future. Note that some Ethernet drivers which _DOESN'T_ use mii(4) use
ec_mii for keeping the if_media. Those should be changed in future.
 1.66 28-May-2019  msaitoh Use ETHER_LOCK()/ETHER_UNLOCK() for all ethernet drivers to protect ec_multi*.
 1.65 23-May-2019  msaitoh Whitespace fix (mainly tabify).
 1.64 23-May-2019  msaitoh -No functional change:
- KNF
- u_int*_t -> uint*_t.
 1.63 24-Apr-2019  msaitoh KNF. No functional change.
 1.62 05-Feb-2019  msaitoh Remove very old IFF_NOTRAILERS flag.
 1.61 03-Feb-2019  mrg - add or adjust /* FALLTHROUGH */ where appropriate
- add __unreachable() after functions that can return but won't in
this case, and thus can't be marked __dead easily
 1.60 26-Jun-2018  msaitoh branches: 1.60.2;
Implement the BPF direction filter (BIOC[GS]DIRECTION). It provides backward
compatibility with BIOC[GS]SEESENT ioctl. The userland interface is the same
as FreeBSD.

This change also fixes a bug that the direction is misunderstand on some
environment by passing the direction to bpf_mtap*() instead of checking
m->m_pkthdr.rcvif.
 1.59 22-Jun-2018  msaitoh It's not required to include net/bpfdesc.h. Remove it.
 1.58 15-Dec-2016  ozaki-r branches: 1.58.8; 1.58.14;
Move bpf_mtap and if_ipackets++ on Rx of each driver to percpuq if_input

The benefits of the change are:
- We can reduce codes
- We can provide the same behavior between drivers
- Where/When if_ipackets is counted up
- Note that some drivers still update packet statistics in their own
way (periodical update)
- Moved bpf_mtap run in softint
- This makes it easy to MP-ify bpf

Proposed on tech-kern and tech-net
 1.57 10-Jun-2016  ozaki-r branches: 1.57.2;
Introduce m_set_rcvif and m_reset_rcvif

The API is used to set (or reset) a received interface of a mbuf.
They are counterpart of m_get_rcvif, which will come in another
commit, hide internal of rcvif operation, and reduce the diff of
the upcoming change.

No functional change.
 1.56 09-Feb-2016  ozaki-r Introduce softint-based if_input

This change intends to run the whole network stack in softint context
(or normal LWP), not hardware interrupt context. Note that the work is
still incomplete by this change; to that end, we also have to softint-ify
if_link_state_change (and bpf) which can still run in hardware interrupt.

This change softint-ifies at ifp->if_input that is called from
each device driver (and ieee80211_input) to ensure Layer 2 runs
in softint (e.g., ether_input and bridge_input). To this end,
we provide a framework (called percpuq) that utlizes softint(9)
and percpu ifqueues. With this patch, rxintr of most drivers just
queues received packets and schedules a softint, and the softint
dequeues packets and does rest packet processing.

To minimize changes to each driver, percpuq is allocated in struct
ifnet for now and that is initialized by default (in if_attach).
We probably have to move percpuq to softc of each driver, but it's
future work. At this point, only wm(4) has percpuq in its softc
as a reference implementation.

Additional information including performance numbers can be found
in the thread at tech-kern@ and tech-net@:
http://mail-index.netbsd.org/tech-kern/2016/01/14/msg019997.html

Acknowledgment: riastradh@ greatly helped this work.
Thank you very much!
 1.55 27-Oct-2012  chs branches: 1.55.14;
split device_t/softc for all remaining drivers.
replace "struct device *" with "device_t".
use device_xname(), device_unit(), etc.
 1.54 19-Jan-2010  pooka branches: 1.54.12; 1.54.22;
Redefine bpf linkage through an always present op vector, i.e.
#if NBPFILTER is no longer required in the client. This change
doesn't yet add support for loading bpf as a module, since drivers
can register before bpf is attached. However, callers of bpf can
now be modularized.

Dynamically loadable bpf could probably be done fairly easily with
coordination from the stub driver and the real driver by registering
attachments in the stub before the real driver is loaded and doing
a handoff. ... and I'm not going to ponder the depths of unload
here.

Tested with i386/MONOLITHIC, modified MONOLITHIC without bpf and rump.
 1.53 07-Nov-2008  dyoung *** Summary ***

When a link-layer address changes (e.g., ifconfig ex0 link
02:de:ad:be:ef:02 active), send a gratuitous ARP and/or a Neighbor
Advertisement to update the network-/link-layer address bindings
on our LAN peers.

Refuse a change of ethernet address to the address 00:00:00:00:00:00
or to any multicast/broadcast address. (Thanks matt@.)

Reorder ifnet ioctl operations so that driver ioctls may inherit
the functions of their "class"---ether_ioctl(), fddi_ioctl(), et
cetera---and the class ioctls may inherit from the generic ioctl,
ifioctl_common(), but both driver- and class-ioctls may override
the generic behavior. Make network drivers share more code.

Distinguish a "factory" link-layer address from others for the
purposes of both protecting that address from deletion and computing
EUI64.

Return consistent, appropriate error codes from network drivers.

Improve readability. KNF.

*** Details ***

In if_attach(), always initialize the interface ioctl routine,
ifnet->if_ioctl, if the driver has not already initialized it.
Delete if_ioctl == NULL tests everywhere else, because it cannot
happen.

In the ioctl routines of network interfaces, inherit common ioctl
behaviors by calling either ifioctl_common() or whichever ioctl
routine is appropriate for the class of interface---e.g., ether_ioctl()
for ethernets.

Stop (ab)using SIOCSIFADDR and start to use SIOCINITIFADDR. In
the user->kernel interface, SIOCSIFADDR's argument was an ifreq,
but on the protocol->ifnet interface, SIOCSIFADDR's argument was
an ifaddr. That was confusing, and it would work against me as I
make it possible for a network interface to overload most ioctls.
On the protocol->ifnet interface, replace SIOCSIFADDR with
SIOCINITIFADDR. In ifioctl(), return EPERM if userland tries to
invoke SIOCINITIFADDR.

In ifioctl(), give the interface the first shot at handling most
interface ioctls, and give the protocol the second shot, instead
of the other way around. Finally, let compatibility code (COMPAT_OSOCK)
take a shot.

Pull device initialization out of switch statements under
SIOCINITIFADDR. For example, pull ..._init() out of any switch
statement that looks like this:

switch (...->sa_family) {
case ...:
..._init();
...
break;
...
default:
..._init();
...
break;
}

Rewrite many if-else clauses that handle all permutations of IFF_UP
and IFF_RUNNING to use a switch statement,

switch (x & (IFF_UP|IFF_RUNNING)) {
case 0:
...
break;
case IFF_RUNNING:
...
break;
case IFF_UP:
...
break;
case IFF_UP|IFF_RUNNING:
...
break;
}

unifdef lots of code containing #ifdef FreeBSD, #ifdef NetBSD, and
#ifdef SIOCSIFMTU, especially in fwip(4) and in ndis(4).

In ipw(4), remove an if_set_sadl() call that is out of place.

In nfe(4), reuse the jumbo MTU logic in ether_ioctl().

Let ethernets register a callback for setting h/w state such as
promiscuous mode and the multicast filter in accord with a change
in the if_flags: ether_set_ifflags_cb() registers a callback that
returns ENETRESET if the caller should reset the ethernet by calling
if_init(), 0 on success, != 0 on failure. Pull common code from
ex(4), gem(4), nfe(4), sip(4), tlp(4), vge(4) into ether_ioctl(),
and register if_flags callbacks for those drivers.

Return ENOTTY instead of EINVAL for inappropriate ioctls. In
zyd(4), use ENXIO instead of ENOTTY to indicate that the device is
not any longer attached.

Add to if_set_sadl() a boolean 'factory' argument that indicates
whether a link-layer address was assigned by the factory or some
other source. In a comment, recommend using the factory address
for generating an EUI64, and update in6_get_hw_ifid() to prefer a
factory address to any other link-layer address.

Add a routing message, RTM_LLINFO_UPD, that tells protocols to
update the binding of network-layer addresses to link-layer addresses.
Implement this message in IPv4 and IPv6 by sending a gratuitous
ARP or a neighbor advertisement, respectively. Generate RTM_LLINFO_UPD
messages on a change of an interface's link-layer address.

In ether_ioctl(), do not let SIOCALIFADDR set a link-layer address
that is broadcast/multicast or equal to 00:00:00:00:00:00.

Make ether_ioctl() call ifioctl_common() to handle ioctls that it
does not understand.

In gif(4), initialize if_softc and use it, instead of assuming that
the gif_softc and ifp overlap.

Let ifioctl_common() handle SIOCGIFADDR.

Sprinkle rtcache_invariants(), which checks on DIAGNOSTIC kernels
that certain invariants on a struct route are satisfied.

In agr(4), rewrite agr_ioctl_filter() to be a bit more explicit
about the ioctls that we do not allow on an agr(4) member interface.

bzero -> memset. Delete unnecessary casts to void *. Use
sockaddr_in_init() and sockaddr_in6_init(). Compare pointers with
NULL instead of "testing truth". Replace some instances of (type
*)0 with NULL. Change some K&R prototypes to ANSI C, and join
lines.
 1.52 08-Apr-2008  cegger branches: 1.52.4; 1.52.10; 1.52.12;
use aprint_*_dev and device_xname
 1.51 07-Feb-2008  dyoung branches: 1.51.6;
Start patching up the kernel so that a network driver always has
the opportunity to handle an ioctl before generic ifioctl handling
occurs. This will ease extending the kernel and sharing of code
between drivers.

First steps: Make the signature of ifioctl_common() match struct
ifinet->if_ioctl. Convert SIOCSIFCAP and SIOCSIFMTU to the new
ifioctl() regime, throughout the kernel.
 1.50 20-Dec-2007  dyoung Constify struct ifnet->if_sadl and every use throughout the tree.
Add if_set_sadl() that both sets the link-layer address length and
replaces the current link-layer address with a new one, and use it
throughout the tree.
 1.49 01-Sep-2007  dyoung branches: 1.49.6; 1.49.8; 1.49.12;
Change a bazillion occurrences of code resembling this,

error = (cmd == SIOCADDMULTI) ?
ether_addmulti(ifr, &sc->sc_ec) :
ether_delmulti(ifr, &sc->sc_ec);

if (error == ENETRESET) {

to this,

if ((error = ether_ioctl(ifp, cmd, data)) == ENETRESET) {

which does the same thing.

(A bazillion is a very large number. This seems to make the i386
ALL kernel smaller by 3kB to 4kB.)

Use ifreq_getaddr() twice in es(4).

Whitespace nits.
 1.48 04-Mar-2007  christos branches: 1.48.2; 1.48.10; 1.48.14; 1.48.16;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.47 16-Nov-2006  christos branches: 1.47.4;
__unused removal on arguments; approved by core.
 1.46 12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.45 09-Oct-2006  jkunz Bringing up a fpa(4) interface on sparc(64) causes a hard kernel crash
(infinite loop) due to the way fpa(4) interacts with bus_dma(9).
This fixes the problem and makes fpa(4) usable on sparc(64).
 1.44 07-Sep-2006  dogcow branches: 1.44.2; 1.44.4;
remove more vestiges of CCITT, LLC, HDLC, NS, and NSIP.
 1.43 11-Dec-2005  christos branches: 1.43.4; 1.43.8;
merge ktrace-lwp.
 1.42 30-May-2005  christos branches: 1.42.2;
- add missing const
- fix variable shadowing
- remove unneeded casts
 1.41 27-Feb-2005  perry nuke trailing whitespace
 1.40 26-Feb-2003  matt branches: 1.40.2; 1.40.10; 1.40.12;
Add MBUFTRACE kernel option.
Do a little mbuf rework while here. Change all uses of MGET*(*, M_WAIT, *)
to m_get*(M_WAIT, *). These are not performance critical and making them
call m_get saves considerable space. Add m_clget analogue of MCLGET and
make corresponding change for M_WAIT uses.
Modify netinet, gem, fxp, tulip, nfs to support MBUFTRACE.
Begin to change netstat to use sysctl.
 1.39 05-Mar-2002  itojun bring in latest ALTQ from kjc. ALTQify some of the drivers.
 1.38 21-Dec-2001  matt When mapping the consumer assignment, assign db_seg[0] to cb_seg[0] so any
private fields are copied as well. Then adjust cb_seq[0] public fields.
This make the DEFPA come up on sparc64.
 1.37 13-Nov-2001  lukem add/cleanup RCSID
 1.36 19-Jul-2001  thorpej Use BUS_DMA_READ and BUS_DMA_WRITE in some obvious places.
 1.35 07-Jul-2001  thorpej branches: 1.35.2;
bcopy -> memcpy
 1.34 07-Jul-2001  thorpej bcmp -> memcmp
 1.33 25-Jun-2001  enami Invert the logic in last commit so that it actually works.
 1.32 25-Jun-2001  matt Add a flag to the softc to prevent recursion in ifstart
 1.31 13-Jun-2001  wiz withough -> without
 1.30 14-Dec-2000  thorpej branches: 1.30.2;
ALTQ'ify.
 1.29 12-Dec-2000  thorpej Adapt to bpfattach() changes, and further centralize the bpfattach()
and bpfdetach() calls into link-type subroutines where possible.
 1.28 28-Jun-2000  mrg remove include of <vm/vm.h>. <vm/vm.h> -> <uvm/uvm_extern.h>
 1.27 26-Jun-2000  mrg remove/move more mach vm header files:

<vm/pglist.h> -> <uvm/uvm_pglist.h>
<vm/vm_inherit.h> -> <uvm/uvm_inherit.h>
<vm/vm_kern.h> -> into <uvm/uvm_extern.h>
<vm/vm_object.h> -> nothing
<vm/vm_pager.h> -> into <uvm/uvm_pager.h>

also includes a bunch of <vm/vm_page.h> include removals (due to redudancy
with <vm/vm.h>), and a scattering of other similar headers.
 1.26 07-Mar-2000  mycroft Fix obvious typo.
 1.25 18-May-1999  thorpej branches: 1.25.2;
Rework layer 2 protocol input routines. Instead of calling e.g. ether_input()
directly, call the function pointer (*if_input)(ifp, m). The input routine
expects the packet header to be at the head of the packet, and will adjust
as necessary. Privatize the layer 2 input and output routines, allowing
*_ifattach() to set them up as appropriate.
 1.24 28-Sep-1998  matt branches: 1.24.4; 1.24.8;
Insert the FDDI control bytes in pdq_ifstart before we load the dmamap
and dmasync the data. Fix pdq_os_receive_pdu to use PDQ_OS_HDR_OFFSET
instead of PDQ_RX_FC_OFFSET.
 1.23 28-Sep-1998  matt Fix transmit handling (this also should speed up transmits
slightly).
 1.22 20-Sep-1998  matt Changes so that BPF readers will get the data in fddi packet aligned along
normal boundaries. This makes tcpdump much happier.
 1.21 19-Sep-1998  matt Make sure data in FDDI packets are aligned nicely (for alpha, etc.)
 1.20 16-Aug-1998  matt splnet() is not appropriate for everyone. Raise and lower SPL via
macros defined in pdqvar.h
 1.19 08-Aug-1998  mycroft Use splnet, not splimp.
 1.18 05-Jul-1998  jonathan defopt NS, NSIP.
 1.17 05-Jul-1998  jonathan defopt INET, NETATALK.
 1.16 27-May-1998  matt Fix syncing of consumer block.
 1.15 24-May-1998  matt More pmax coherency stuff. Getting close..
 1.14 24-May-1998  matt Fix dmamap leakages. fix transmit bug. fix receive bugs. fix mips
coherency problems.
 1.13 21-May-1998  matt Add bus_dma(9) support for the DEFxA FDDI driver
 1.12 07-Apr-1998  matt Fix problem with promicuously received packets. (ie. give them to bpf
but not fddi_input).
 1.11 08-Jun-1997  thorpej Merge pdq-970604 update.
 1.10 26-Mar-1997  thorpej Resolve conflicts from merge.
 1.9 24-Mar-1997  thorpej Resolve conflicts from merge.
 1.8 15-Mar-1997  is New ARP system, supports IPv4 over any hardware link.

Some of the stuff (e.g., rarpd, bootpd, dhcpd etc., libsa) still will
only support Ethernet. Tcpdump itself should be ok, but libpcap needs
lot of work.

For the detailed change history, look at the commit log entries for
the is-newarp branch.
 1.7 20-Feb-1997  is Make this compile again on NetBSD-current/i386.
 1.6 20-Feb-1997  mikel make sure that packets are ours before passing them up if interface is
in promiscuous mode; from Juergen Weiss in PR kern/3121.
 1.5 20-May-1996  thorpej branches: 1.5.6;
Fix conflicts during import.
 1.4 14-May-1996  thorpej Update for the arpwhohas() change.
 1.3 07-May-1996  thorpej Changed struct ifnet to have a pointer to the softc of the underlying
device and a printable "external name" (name + unit number), thus eliminating
if_name and if_unit. Updated interface to (*if_watchdog)() and (*if_start)()
to take a struct ifnet *, rather than a unit number.
 1.2 11-Mar-1996  thorpej Resolve conflicts from merge.
 1.1 09-Mar-1996  thorpej branches: 1.1.1;
Fill in the missing pieces and make the NetBSD version of Matt Thomas's
DEFPA FDDI driver actually compile and link.
 1.1.1.5 08-Jun-1997  thorpej Update of DEC PDQ FDDI driver, from Matt Thomas <matt@3am-software.com>.
 1.1.1.4 26-Mar-1997  thorpej Update from Matt Thomas <matt@3am-software.com>. Multicast-related
bug fixes.
 1.1.1.3 24-Mar-1997  thorpej Update from Matt Thomas <matt@3am-software.com>. Notable highlight:
the DEFTA (TurboChannel) card now works on the Alpha!
 1.1.1.2 20-May-1996  thorpej Update to the Digital Equipment PDQ-based FDDI controllers, from
Matt Thomas. Now includes support for EISA (DEFEA) and first-cut of
support for TurboChannel (DEFTA) cards.
 1.1.1.1 11-Mar-1996  thorpej New snapshot of DEC PDQ-based FDDI driver, from Matt Thomas.
 1.5.6.5 09-Mar-1997  is netinet/if_ether.h => netinet/if_inarp.h
 1.5.6.4 27-Feb-1997  is Removed #include <route.h> and #include <netisr.h>. They're not needed, and
the latter will go away soon.
 1.5.6.3 20-Feb-1997  is Merge in a bugfix from the Trunk.
 1.5.6.2 20-Feb-1997  is Give fddi_ifattach() a 2nd parameter, like ether_ifattach(): a pointer to the
link level address. xxx_ifattach() copy it to the sockaddr_dl structure
associated with the interface.

Change pdq to pass that parameter.
Change frontend to not copy the l.l.a. itself.
 1.5.6.1 07-Feb-1997  is Snapshot of new ARP code.

Our old ARP code was hardwired for 6-byte length medium
addresses, while the protocol is designed for any size.

This snapshot contains a first hack at getting rid of
Ethernet specific data structures. The ep driver is updated
(and tested on the PCI bus), the iy and fpa drivers have been
updated, but not real life tested yet.

If you want to test this with other drivers, you have to update
them first yourself, and probably tag the relevant directories.
Better contact me if you want to do this.
 1.24.8.1 21-Jun-1999  thorpej Sync w/ -current.
 1.24.4.1 11-Dec-1998  kenh The beginnings of interface detach support. Still some bugs, but mostly
works for me.

This work was originally by Bill Studenmund, and cleaned up by me.
 1.25.2.3 05-Jan-2001  bouyer Sync with HEAD
 1.25.2.2 13-Dec-2000  bouyer Sync with HEAD (for UBC fixes).
 1.25.2.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.30.2.5 01-Apr-2002  nathanw Catch up to -current.
(CVS: It's not just a program. It's an adventure!)
 1.30.2.4 08-Jan-2002  nathanw Catch up to -current.
 1.30.2.3 14-Nov-2001  nathanw Catch up to -current.
 1.30.2.2 24-Aug-2001  nathanw Catch up with -current.
 1.30.2.1 21-Jun-2001  nathanw Catch up to -current.
 1.35.2.3 16-Mar-2002  jdolecek Catch up with -current.
 1.35.2.2 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.35.2.1 03-Aug-2001  lukem update to -current
 1.40.12.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.40.10.1 29-Apr-2005  kent sync with -current
 1.40.2.2 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.40.2.1 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.42.2.4 11-Feb-2008  yamt sync with head.
 1.42.2.3 21-Jan-2008  yamt sync with head
 1.42.2.2 03-Sep-2007  yamt sync with head.
 1.42.2.1 30-Dec-2006  yamt sync with head.
 1.43.8.1 14-Sep-2006  yamt sync with head.
 1.43.4.1 09-Sep-2006  rpaulo sync with head
 1.44.4.2 10-Dec-2006  yamt sync with head.
 1.44.4.1 22-Oct-2006  yamt sync with head
 1.44.2.1 18-Nov-2006  ad Sync with head.
 1.47.4.1 12-Mar-2007  rmind Sync with HEAD.
 1.48.16.3 23-Mar-2008  matt sync with HEAD
 1.48.16.2 09-Jan-2008  matt sync with HEAD
 1.48.16.1 06-Nov-2007  matt sync with HEAD
 1.48.14.1 03-Sep-2007  jmcneill Sync with HEAD.
 1.48.10.1 03-Sep-2007  skrll Sync with HEAD.
 1.48.2.1 09-Oct-2007  ad Sync with head.
 1.49.12.1 02-Jan-2008  bouyer Sync with HEAD
 1.49.8.1 26-Dec-2007  ad Sync with head.
 1.49.6.1 18-Feb-2008  mjf Sync with HEAD.
 1.51.6.2 17-Jan-2009  mjf Sync with HEAD.
 1.51.6.1 02-Jun-2008  mjf Sync with HEAD.
 1.52.12.1 19-Jan-2009  skrll Sync with HEAD.
 1.52.10.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.52.4.2 11-Mar-2010  yamt sync with head
 1.52.4.1 04-May-2009  yamt sync with head.
 1.54.22.2 03-Dec-2017  jdolecek update from HEAD
 1.54.22.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.54.12.1 30-Oct-2012  yamt sync with head
 1.55.14.3 05-Feb-2017  skrll Sync with HEAD
 1.55.14.2 09-Jul-2016  skrll Sync with HEAD
 1.55.14.1 19-Mar-2016  skrll Sync with HEAD
 1.57.2.1 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.58.14.2 28-Jul-2018  pgoyette Sync with HEAD
 1.58.14.1 25-Jun-2018  pgoyette Sync with HEAD
 1.58.8.1 26-Jul-2018  snj Pull up following revision(s) (requested by msaitoh in ticket #938):
sys/arch/acorn32/podulebus/if_ie.c: revision 1.41
sys/arch/amiga/dev/if_es.c: revision 1.58
sys/arch/amiga/dev/if_qn.c: revision 1.45
sys/arch/arm/at91/at91emac.c: revision 1.20
sys/arch/arm/ep93xx/epe.c: revision 1.37
sys/arch/emips/ebus/if_le_ebus.c: revision 1.14
sys/arch/emips/ebus/if_le_ebus.c: revision 1.15
sys/arch/mac68k/dev/if_mc.c: revision 1.46
sys/arch/macppc/dev/am79c950.c: revision 1.39
sys/arch/newsmips/apbus/if_sn.c: revision 1.40
sys/arch/next68k/dev/mb8795.c: revision 1.59
sys/arch/playstation2/dev/if_smap.c: revision 1.25
sys/arch/playstation2/dev/if_smap.c: revision 1.26
sys/arch/sun2/dev/if_ec.c: revision 1.28
sys/arch/sun3/dev/if_ie.c: revision 1.63
sys/arch/x68k/dev/if_ne_intio.c: revision 1.19
sys/arch/xen/xen/if_xennet_xenbus.c: revision 1.75
sys/arch/xen/xen/xennetback_xenbus.c: revision 1.63
sys/dev/bi/if_ni.c: revision 1.45
sys/dev/cadence/if_cemac.c: revision 1.12
sys/dev/ic/am7990.c: revision 1.78
sys/dev/ic/am79900.c: revision 1.27
sys/dev/ic/an.c: revision 1.67
sys/dev/ic/cs89x0.c: revision 1.40
sys/dev/ic/dm9000.c: revision 1.13
sys/dev/ic/dm9000.c: revision 1.14
sys/dev/ic/dp8390.c: revision 1.88
sys/dev/ic/elink3.c: revision 1.141
sys/dev/ic/elinkxl.c: revision 1.122
sys/dev/ic/hme.c: revision 1.98
sys/dev/ic/i82586.c: revision 1.77
sys/dev/ic/lance.c: revision 1.53
sys/dev/ic/mb86950.c: revision 1.27
sys/dev/ic/mb86960.c: revision 1.86
sys/dev/ic/mtd803.c: revision 1.34
sys/dev/ic/pdq_ifsubr.c: revision 1.59
sys/dev/ic/rrunner.c: revision 1.86
sys/dev/ic/seeq8005.c: revision 1.58
sys/dev/ic/sgec.c: revision 1.47
sys/dev/ic/smc90cx6.c: revision 1.72
sys/dev/ic/smc91cxx.c: revision 1.96
sys/dev/ic/tropic.c: revision 1.49
sys/dev/ic/wi.c: revision 1.245
sys/dev/isa/if_eg.c: revision 1.93
sys/dev/isa/if_el.c: revision 1.95
sys/dev/isa/if_iy.c: revision 1.101
sys/dev/ofw/ofnet.c: revision 1.58
sys/dev/pci/if_alc.c: revision 1.27
sys/dev/pci/if_de.c: revision 1.152
sys/dev/pci/if_fpa.c: revision 1.61
sys/dev/pci/if_jme.c: revision 1.34
sys/dev/pci/if_tl.c: revision 1.108
sys/dev/pci/if_vte.c: revision 1.19
sys/dev/pci/ixgbe/ixgbe.h: revision 1.50
sys/dev/pcmcia/if_cnw.c: revision 1.62
sys/dev/pcmcia/if_malo_pcmcia.c: revision 1.17
sys/dev/pcmcia/if_ray.c: revision 1.89
sys/dev/pcmcia/if_xi.c: revision 1.81
sys/dev/pcmcia/mhzc.c: revision 1.51
sys/dev/pcmcia/xirc.c: revision 1.34
sys/dev/qbus/if_de.c: revision 1.33
sys/dev/qbus/if_qe.c: revision 1.78
sys/dev/qbus/if_qt.c: revision 1.22
sys/dev/sbus/be.c: revision 1.87
sys/dev/sbus/qe.c: revision 1.68
sys/dev/scsipi/if_se.c: revision 1.96
sys/dev/usb/if_atu.c: revision 1.59
sys/net/if_l2tp.c: revision 1.28 via patch
sys/net/if_ppp.c: revision 1.160
It's not required to include net/bpfdesc.h. Remove it.
--
Simplify like other drivers. NULL check of ifp->if_bpf is done in
bpf_mtap(), so it's not required to do it here.
--
Remove duplicated inclusion of net/bpf.h.
--
Remove duplicated inclusion of net/bpf.h.
--
Simplify bpf_mtap() call. No functional change.
 1.60.2.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.60.2.1 10-Jun-2019  christos Sync with HEAD
 1.67.4.1 25-Jan-2020  ad Sync with head.
 1.20 20-Jan-2020  thorpej Remove FDDI support.
 1.19 24-Jun-2008  gmcgarry branches: 1.19.84; 1.19.92;
Rearrange pdq_boolean_t, pdq_type_t and pdq_state_t so that enums are defined
before their typedefs and prototypes. Fixes compilation with pcc.
 1.18 11-Dec-2005  christos branches: 1.18.70; 1.18.74; 1.18.76; 1.18.78;
merge ktrace-lwp.
 1.17 30-May-2005  christos remove volatile that was being cast-away in all its references.
 1.16 27-Feb-2005  perry nuke trailing whitespace
 1.15 17-Jan-2003  matt branches: 1.15.2; 1.15.10; 1.15.12;
Make the DEFPA/DEFEA/DEFTA driver work on big-endian machines such as
powerpc or sparc64.
 1.14 13-Jun-2001  wiz withough -> without
 1.13 23-Dec-1999  matt branches: 1.13.6;
Add some defensive code to the unsolicited event printing
 1.12 27-May-1998  matt branches: 1.12.14;
Only enable transmit done interrupts when output ring is full.
 1.11 26-May-1998  matt Success! With these changes, the DEFTA now under NetBSD/pmax!!
 1.10 25-May-1998  matt Verify the driver work if PDQ_NO_BUS_DMA is defined.
 1.9 21-May-1998  matt Add bus_dma(9) support for the DEFxA FDDI driver
 1.8 07-Apr-1998  matt Fix problem with promicuously received packets. (ie. give them to bpf
but not fddi_input).
 1.7 24-Mar-1997  thorpej Resolve conflicts from merge.
 1.6 28-Aug-1996  cgd define PDQ_ASSERT directly in terms of __assert, because cpp doesn't seem
to do:
#define foo(x) ...
#define bar foo
like we'd like it to.
 1.5 27-Aug-1996  cgd Including user-land headers in kernel code is not allowed in NetBSD.
Therefore:
(1) define offsetof here, and
(2) implement assertion checking in terms of the libkern
assertion-checking macros.
 1.4 20-May-1996  thorpej Fix conflicts during import.
 1.3 11-Mar-1996  thorpej Resolve conflicts from merge.
 1.2 19-Aug-1995  cgd local adaptations, and fix a could of compilation errors
 1.1 19-Aug-1995  cgd branches: 1.1.1;
Initial revision
 1.1.1.4 24-Mar-1997  thorpej Update from Matt Thomas <matt@3am-software.com>. Notable highlight:
the DEFTA (TurboChannel) card now works on the Alpha!
 1.1.1.3 20-May-1996  thorpej Update to the Digital Equipment PDQ-based FDDI controllers, from
Matt Thomas. Now includes support for EISA (DEFEA) and first-cut of
support for TurboChannel (DEFTA) cards.
 1.1.1.2 11-Mar-1996  thorpej New snapshot of DEC PDQ-based FDDI driver, from Matt Thomas.
 1.1.1.1 19-Aug-1995  cgd Generic FDDI support by Matt Thomas. Support for DEC "PDQ" FDDI chipset
and for the PCI attachment of said chipset ("if_fpa"), also from Matt Thomas.
Arguably, pdq* doesn't belong in sys/dev/ic, but it's going to be shared by
various bus attachment devices at some point in the future, and there's no
other place that seems to fit as well.
 1.12.14.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.13.6.2 17-Jan-2003  thorpej Sync with HEAD.
 1.13.6.1 21-Jun-2001  nathanw Catch up to -current.
 1.15.12.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.15.10.1 29-Apr-2005  kent sync with -current
 1.15.2.2 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.15.2.1 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.18.78.1 27-Jun-2008  simonb Sync with head.
 1.18.76.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.18.74.1 04-May-2009  yamt sync with head.
 1.18.70.1 29-Jun-2008  mjf Sync with HEAD.
 1.19.92.1 25-Jan-2020  ad Sync with head.
 1.19.84.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.51 20-Jan-2020  thorpej Remove FDDI support.
 1.50 10-Nov-2019  chs branches: 1.50.2;
in many device attach paths, allocate memory with M_WAITOK instead of M_NOWAIT
and remove code to handle failures that can no longer happen.
 1.49 26-Jun-2018  msaitoh branches: 1.49.2;
Implement the BPF direction filter (BIOC[GS]DIRECTION). It provides backward
compatibility with BIOC[GS]SEESENT ioctl. The userland interface is the same
as FreeBSD.

This change also fixes a bug that the direction is misunderstand on some
environment by passing the direction to bpf_mtap*() instead of checking
m->m_pkthdr.rcvif.
 1.48 22-Jun-2017  flxd branches: 1.48.4;
spelling (DEC called it "TURBOchannel")
 1.47 27-Oct-2012  chs branches: 1.47.14;
split device_t/softc for all remaining drivers.
replace "struct device *" with "device_t".
use device_xname(), device_unit(), etc.
 1.46 13-Nov-2010  uebayasi branches: 1.46.8; 1.46.18;
Don't pull in the whole uvm(9) API to access only PAGE_SIZE and
some other constants. These are provided by sys/param.h now.
 1.45 05-Apr-2010  joerg Push the bpf_ops usage back into bpf.h. Push the common ifp->if_bpf
check into the inline functions as well the fourth argument for
bpf_attach.
 1.44 22-Mar-2010  dyoung sc_csr_memmapped is true iff the device registers are memory-mapped.
 1.43 19-Jan-2010  pooka branches: 1.43.2; 1.43.4;
Redefine bpf linkage through an always present op vector, i.e.
#if NBPFILTER is no longer required in the client. This change
doesn't yet add support for loading bpf as a module, since drivers
can register before bpf is attached. However, callers of bpf can
now be modularized.

Dynamically loadable bpf could probably be done fairly easily with
coordination from the stub driver and the real driver by registering
attachments in the stub before the real driver is loaded and doing
a handoff. ... and I'm not going to ponder the depths of unload
here.

Tested with i386/MONOLITHIC, modified MONOLITHIC without bpf and rump.
 1.42 17-Jan-2010  pooka Forward declare struct bpf_if and use that as the type for bpf_if
instead of "void *". Buys us oo times the type-safety for 0 times
the price.
(no functional change)
 1.41 18-Mar-2009  cegger bzero -> memset
 1.40 24-Jun-2008  gmcgarry branches: 1.40.4; 1.40.10;
Rearrange pdq_boolean_t, pdq_type_t and pdq_state_t so that enums are defined
before their typedefs and prototypes. Fixes compilation with pcc.
 1.39 20-Dec-2007  dyoung branches: 1.39.6; 1.39.10; 1.39.12; 1.39.14;
Constify struct ifnet->if_sadl and every use throughout the tree.
Add if_set_sadl() that both sets the link-layer address length and
replaces the current link-layer address with a new one, and use it
throughout the tree.
 1.38 19-Oct-2007  ad branches: 1.38.4; 1.38.8;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.37 04-Mar-2007  christos branches: 1.37.2; 1.37.14; 1.37.16; 1.37.20;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.36 11-Dec-2005  christos branches: 1.36.26;
merge ktrace-lwp.
 1.35 30-May-2005  christos branches: 1.35.2;
- add missing const
- fix variable shadowing
- remove unneeded casts
 1.34 08-Jul-2003  itojun function prototype must not have variable name
 1.33 07-Jul-2001  thorpej branches: 1.33.22;
bzero -> memset
 1.32 25-Jun-2001  matt Add a flag to the softc to prevent recursion in ifstart
 1.31 13-Jun-2001  wiz withough -> without
 1.30 14-Nov-2000  thorpej branches: 1.30.2;
NBPG -> PAGE_SIZE
 1.29 28-Jun-2000  mrg remove include of <vm/vm.h>. <vm/vm.h> -> <uvm/uvm_extern.h>
 1.28 26-Jun-2000  mrg remove/move more mach vm header files:

<vm/pglist.h> -> <uvm/uvm_pglist.h>
<vm/vm_inherit.h> -> <uvm/uvm_inherit.h>
<vm/vm_kern.h> -> into <uvm/uvm_extern.h>
<vm/vm_object.h> -> nothing
<vm/vm_pager.h> -> into <uvm/uvm_pager.h>

also includes a bunch of <vm/vm_page.h> include removals (due to redudancy
with <vm/vm.h>), and a scattering of other similar headers.
 1.27 03-May-2000  thorpej `typedef void ifnet_ret_t;' isn't valid C -- use #define, instead.
 1.26 24-Mar-1999  mrg branches: 1.26.8;
completely remove Mach VM support. all that is left is the all the
header files as UVM still uses (most of) these.
 1.25 02-Oct-1998  matt branches: 1.25.4;
Fix typo (pointed by Matthias Drochner).
 1.24 20-Sep-1998  matt Changes so that BPF readers will get the data in fddi packet aligned along
normal boundaries. This makes tcpdump much happier.
 1.23 16-Aug-1998  matt splnet() is not appropriate for everyone. Raise and lower SPL via
macros defined in pdqvar.h
 1.22 13-Aug-1998  eeh Merge paddr_t changes into the main branch.
 1.21 27-May-1998  matt branches: 1.21.2;
Fix syncing of consumer block.
 1.20 25-May-1998  matt Verify the driver work if PDQ_NO_BUS_DMA is defined.
 1.19 24-May-1998  matt More pmax coherency stuff. Getting close..
 1.18 24-May-1998  matt Fix dmamap leakages. fix transmit bug. fix receive bugs. fix mips
coherency problems.
 1.17 21-May-1998  matt Add bus_dma(9) support for the DEFxA FDDI driver
 1.16 07-Apr-1998  matt Fix problem with promicuously received packets. (ie. give them to bpf
but not fddi_input).
 1.15 10-Feb-1998  mrg - add defopt's for UVM, UVMHIST and PMAP_NEW.
- remove unnecessary UVMHIST_DECL's.
 1.14 05-Feb-1998  mrg initial import of the new virtual memory system, UVM, into -current.

UVM was written by chuck cranor <chuck@maria.wustl.edu>, with some
minor portions derived from the old Mach code. i provided some help
getting swap and paging working, and other bug fixes/ideas. chuck
silvers <chuq@chuq.com> also provided some other fixes.

this is the rest of the MI portion changes.

this will be KNF'd shortly. :-)
 1.13 24-Mar-1997  thorpej Resolve conflicts from merge.
 1.12 15-Mar-1997  is New ARP system, supports IPv4 over any hardware link.

Some of the stuff (e.g., rarpd, bootpd, dhcpd etc., libsa) still will
only support Ethernet. Tcpdump itself should be ok, but libpcap needs
lot of work.

For the detailed change history, look at the commit log entries for
the is-newarp branch.
 1.11 25-Oct-1996  cgd branches: 1.11.4;
update alpha_XXX_dmamap() invocations to match prototype.
 1.10 23-Oct-1996  cgd update drivers to use the new NetBSD/alpha DMA mapping hack, since
the old one is not workable with the new bus.h.
 1.9 21-Oct-1996  thorpej New bus.h implementation/interface:
- No more distinction between i/o-mapped and memory-mapped
devices. It's all "bus space" now, and space tags
differentiate the space with finer grain than the
bus chipset tag.
- Add memory barrier methods.
- Implement space alloc/free methods.
- Implement region read/write methods (like memcpy to/from
bus space).
This interface provides a better abstraction for dealing with
machine-independent chipset drivers.
 1.8 10-Jul-1996  cgd cast argument to alpha vtophys() to vm_offset_t, to catch up with
recent prototyping.
 1.7 07-Jun-1996  cgd clean up import of new revision (June 7, 1996) from Matt Thomas.
 1.6 20-May-1996  thorpej branches: 1.6.4;
Fix conflicts during import.
 1.5 07-May-1996  thorpej Changed struct ifnet to have a pointer to the softc of the underlying
device and a printable "external name" (name + unit number), thus eliminating
if_name and if_unit. Updated interface to (*if_watchdog)() and (*if_start)()
to take a struct ifnet *, rather than a unit number.
 1.4 11-Mar-1996  thorpej Resolve conflicts from merge.
 1.3 09-Mar-1996  thorpej Fill in the missing pieces and make the NetBSD version of Matt Thomas's
DEFPA FDDI driver actually compile and link.
 1.2 19-Aug-1995  cgd local adaptations, and fix a could of compilation errors
 1.1 19-Aug-1995  cgd branches: 1.1.1;
Initial revision
 1.1.1.5 24-Mar-1997  thorpej Update from Matt Thomas <matt@3am-software.com>. Notable highlight:
the DEFTA (TurboChannel) card now works on the Alpha!
 1.1.1.4 07-Jun-1996  cgd New rev. from Matt Thomas (June 7, 1996), which:
(1) adds another parameter to PDQ_OS_VA_TO_PA() so that (via a
hack) the driver works on more Alpha models, and
(2) adds the definition PDQ_OS_PTR_FMT, which specifies what printf
format to use when printing pointers. (%p under NetBSD.)
 1.1.1.3 20-May-1996  thorpej Update to the Digital Equipment PDQ-based FDDI controllers, from
Matt Thomas. Now includes support for EISA (DEFEA) and first-cut of
support for TurboChannel (DEFTA) cards.
 1.1.1.2 11-Mar-1996  thorpej New snapshot of DEC PDQ-based FDDI driver, from Matt Thomas.
 1.1.1.1 19-Aug-1995  cgd Generic FDDI support by Matt Thomas. Support for DEC "PDQ" FDDI chipset
and for the PCI attachment of said chipset ("if_fpa"), also from Matt Thomas.
Arguably, pdq* doesn't belong in sys/dev/ic, but it's going to be shared by
various bus attachment devices at some point in the future, and there's no
other place that seems to fit as well.
 1.6.4.1 08-Jun-1996  cgd pull up from trunk:
>New rev. from Matt Thomas (June 7, 1996), which:
> (1) adds another parameter to PDQ_OS_VA_TO_PA() so that (via a
> hack) the driver works on more Alpha models, and
> (2) adds the definition PDQ_OS_PTR_FMT, which specifies what
> printf format to use when printing pointers. (%p under NetBSD.)
 1.11.4.1 07-Feb-1997  is Snapshot of new ARP code.

Our old ARP code was hardwired for 6-byte length medium
addresses, while the protocol is designed for any size.

This snapshot contains a first hack at getting rid of
Ethernet specific data structures. The ep driver is updated
(and tested on the PCI bus), the iy and fpa drivers have been
updated, but not real life tested yet.

If you want to test this with other drivers, you have to update
them first yourself, and probably tag the relevant directories.
Better contact me if you want to do this.
 1.21.2.1 30-Jul-1998  eeh Split vm_offset_t and vm_size_t into paddr_t, psize_t, vaddr_t, and vsize_t.
 1.25.4.1 11-Dec-1998  kenh The beginnings of interface detach support. Still some bugs, but mostly
works for me.

This work was originally by Bill Studenmund, and cleaned up by me.
 1.26.8.2 22-Nov-2000  bouyer Sync with HEAD.
 1.26.8.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.30.2.2 24-Aug-2001  nathanw Catch up with -current.
 1.30.2.1 21-Jun-2001  nathanw Catch up to -current.
 1.33.22.4 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.33.22.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.33.22.2 18-Sep-2004  skrll Sync with HEAD.
 1.33.22.1 03-Aug-2004  skrll Sync with HEAD
 1.35.2.3 21-Jan-2008  yamt sync with head
 1.35.2.2 27-Oct-2007  yamt sync with head.
 1.35.2.1 03-Sep-2007  yamt sync with head.
 1.36.26.1 12-Mar-2007  rmind Sync with HEAD.
 1.37.20.1 25-Oct-2007  bouyer Sync with HEAD.
 1.37.16.2 09-Jan-2008  matt sync with HEAD
 1.37.16.1 06-Nov-2007  matt sync with HEAD
 1.37.14.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.37.2.1 23-Oct-2007  ad Sync with head.
 1.38.8.1 02-Jan-2008  bouyer Sync with HEAD
 1.38.4.1 26-Dec-2007  ad Sync with head.
 1.39.14.1 27-Jun-2008  simonb Sync with head.
 1.39.12.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.39.10.3 11-Aug-2010  yamt sync with head.
 1.39.10.2 11-Mar-2010  yamt sync with head
 1.39.10.1 04-May-2009  yamt sync with head.
 1.39.6.1 29-Jun-2008  mjf Sync with HEAD.
 1.40.10.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.40.4.1 28-Apr-2009  skrll Sync with HEAD.
 1.43.4.2 05-Mar-2011  rmind sync with head
 1.43.4.1 30-May-2010  rmind sync with head
 1.43.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.46.18.2 03-Dec-2017  jdolecek update from HEAD
 1.46.18.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.46.8.1 30-Oct-2012  yamt sync with head
 1.47.14.1 28-Aug-2017  skrll Sync with HEAD
 1.48.4.1 28-Jul-2018  pgoyette Sync with HEAD
 1.49.2.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.50.2.1 25-Jan-2020  ad Sync with head.
 1.3 08-Sep-2025  thorpej Garbage-collect fdtbus_todr_attach(); todr_attach() does all the
necessary work now.

kern/59630
 1.2 07-Sep-2025  thorpej Change todr_chip_handle::cookie -> todr_chip_handle::todr_dev, and
make it a device_t. Upcoming functional changes will require the
device_t associated with a TODR device.

Change todr_chip_handle::bus_cookie -> todr_chip_handle::todr_devaux.
Nothing was using the old field, but I decided to keep it around just
in cause something needs it in the future.

And with these largely mechanical yet semantically meaningful changes,
thus spake the Oracle: "Welcome to NetBSD 11.99.2."
 1.1 08-Jun-2017  jmcneill branches: 1.1.2; 1.1.6; 1.1.8;
Add driver for ARM PrimeCell PL031 (RTC) Real Time Clock.
 1.1.8.2 03-Dec-2017  jdolecek update from HEAD
 1.1.8.1 08-Jun-2017  jdolecek file pl031.c was added on branch tls-maxphys on 2017-12-03 11:37:03 +0000
 1.1.6.2 28-Aug-2017  skrll Sync with HEAD
 1.1.6.1 08-Jun-2017  skrll file pl031.c was added on branch nick-nhusb on 2017-08-28 17:52:03 +0000
 1.1.2.2 10-Jun-2017  snj Pull up following revision(s) (requested by jmcneill in ticket #19):
sys/arch/arm/fdt/files.fdt: revision 1.11
sys/arch/arm/fdt/plrtc_fdt.c: revision 1.1
sys/arch/evbarm/conf/VEXPRESS_A15: revision 1.16
sys/conf/files: revision 1.1175
sys/dev/ic/pl031.c: revision 1.1
sys/dev/ic/pl031var.h: revision 1.1
Add driver for ARM PrimeCell PL031 (RTC) Real Time Clock.
--
Add fdt glue for plrtc
--
Add plrtc driver
 1.1.2.1 08-Jun-2017  snj file pl031.c was added on branch netbsd-8 on 2017-06-10 05:57:08 +0000
 1.1 08-Jun-2017  jmcneill branches: 1.1.2; 1.1.6; 1.1.8;
Add driver for ARM PrimeCell PL031 (RTC) Real Time Clock.
 1.1.8.2 03-Dec-2017  jdolecek update from HEAD
 1.1.8.1 08-Jun-2017  jdolecek file pl031var.h was added on branch tls-maxphys on 2017-12-03 11:37:03 +0000
 1.1.6.2 28-Aug-2017  skrll Sync with HEAD
 1.1.6.1 08-Jun-2017  skrll file pl031var.h was added on branch nick-nhusb on 2017-08-28 17:52:03 +0000
 1.1.2.2 10-Jun-2017  snj Pull up following revision(s) (requested by jmcneill in ticket #19):
sys/arch/arm/fdt/files.fdt: revision 1.11
sys/arch/arm/fdt/plrtc_fdt.c: revision 1.1
sys/arch/evbarm/conf/VEXPRESS_A15: revision 1.16
sys/conf/files: revision 1.1175
sys/dev/ic/pl031.c: revision 1.1
sys/dev/ic/pl031var.h: revision 1.1
Add driver for ARM PrimeCell PL031 (RTC) Real Time Clock.
--
Add fdt glue for plrtc
--
Add plrtc driver
 1.1.2.1 08-Jun-2017  snj file pl031var.h was added on branch netbsd-8 on 2017-06-10 05:57:08 +0000
 1.8 29-Feb-2020  isaki Remove rounding by 4 bytes on round_blocksize().
For drivers which supports only 16bit * 2channels sampling,
rounding by 4 bytes no longer meaningful.
 1.7 23-Feb-2020  isaki Make start_input/halt_input optional if the driver has no recording,
make start_output/halt_output optional if the driver has no playback.
And remove such never called functions.
 1.6 08-May-2019  isaki branches: 1.6.4;
Merge isaki-audio2 branch, the overhaul of audio subsystem.
- Interrupt-oriented system rather than thread-oriented.
- Improve stability, quality and performance.
- Split playback and record cleanly. Improve halfduplex support.
- Many bugs are fixed including deadlocks, resource leaks, abuses, etc.
- Simplify audio filter mechanism. The encoding/channels/frequency
conversions are completely handled in the upper layer. So the hard-
ware driver only converts its hardware encoding (if necessary).
- audio_hw_if changes:
- Obsoletes query_encoding and add query_format instead.
- Obsoletes set_params and add set_format instead.
- Remove drain, setfd, mappage.
- The call sequences are changed.
- ioctl AUDIO_GETFD/SETFD, AUDIO_GETCHAN/SETCHAN are obsoleted.
- ioctl AUDIO_{QUERY,GET,SET}FORMAT are introduced.
- cleanup config attributes: au*conv and mulaw.
- All hardware drivers should follow it (I've done as much as possible).

Some file paths are changed:
- dev/audio.c -> dev/audio/audio.c (rewritten)
- dev/audiovar.h -> dev/audio/audiovar.h
- dev/audio_dai.h -> dev/audio/audio_dai.h
- dev/audio_if.h -> dev/audio/audio_if.h
- dev/audiobell.c -> dev/audio/audiobell.c
- dev/audiobellvar.h -> dev/audio/audiobellvar.h
- dev/mulaw.[ch] -> dev/audio/mulaw.[ch] + dev/audio/alaw.c
 1.5 03-Sep-2018  riastradh branches: 1.5.2;
Rename min/max -> uimin/uimax for better honesty.

These functions are defined on unsigned int. The generic name
min/max should not silently truncate to 32 bits on 64-bit systems.
This is purely a name change -- no functional change intended.

HOWEVER! Some subsystems have

#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))

even though our standard name for that is MIN/MAX. Although these
may invite multiple evaluation bugs, these do _not_ cause integer
truncation.

To avoid `fixing' these cases, I first changed the name in libkern,
and then compile-tested every file where min/max occurred in order to
confirm that it failed -- and thus confirm that nothing shadowed
min/max -- before changing it.

I have left a handful of bootloaders that are too annoying to
compile-test, and some dead code:

cobalt ews4800mips hp300 hppa ia64 luna68k vax
acorn32/if_ie.c (not included in any kernels)
macppc/if_gm.c (superseded by gem(4))

It should be easy to fix the fallout once identified -- this way of
doing things fails safe, and the goal here, after all, is to _avoid_
silent integer truncations, not introduce them.

Maybe one day we can reintroduce min/max as type-generic things that
never silently truncate. But we should avoid doing that for a while,
so that existing code has a chance to be detected by the compiler for
conversion to uimin/uimax without changing the semantics until we can
properly audit it all. (Who knows, maybe in some cases integer
truncation is actually intended!)
 1.4 09-Apr-2018  jmcneill branches: 1.4.2;
Use AC97_SLOT_* definitions instead of magic numbers. NFC.
 1.3 08-Jun-2017  jmcneill branches: 1.3.2; 1.3.6; 1.3.8; 1.3.10;
bus_space_write_multi_4 takes a count, not number of bytes. With this,
audio works in qemu.
 1.2 08-Jun-2017  jmcneill Fix two bugs:
- Inverted test for fifo status in aaci_write_data
- Return success from trigger_output (thanks nat)
 1.1 08-Jun-2017  jmcneill Add driver for ARM PrimeCell Advanced Audio CODEC interface (PL041).

Don't expect this driver to work on real hardware, but QEMU emulates it.
 1.3.10.2 06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.3.10.1 16-Apr-2018  pgoyette Sync with HEAD, resolve some conflicts
 1.3.8.2 03-Dec-2017  jdolecek update from HEAD
 1.3.8.1 08-Jun-2017  jdolecek file pl041.c was added on branch tls-maxphys on 2017-12-03 11:37:03 +0000
 1.3.6.2 28-Aug-2017  skrll Sync with HEAD
 1.3.6.1 08-Jun-2017  skrll file pl041.c was added on branch nick-nhusb on 2017-08-28 17:52:03 +0000
 1.3.2.2 09-Jun-2017  snj Pull up following revision(s) (requested by jmcneill in ticket #17):
sys/arch/arm/fdt/aaci_fdt.c: revision 1.1
sys/arch/arm/fdt/files.fdt: revision 1.10
sys/arch/evbarm/conf/VEXPRESS_A15: revisions 1.14, 1.15
sys/conf/files: revision 1.1174
sys/dev/ic/pl041.c: revisions 1.1-1.3
sys/dev/ic/pl041var.h: revision 1.1
Add driver for ARM PrimeCell Advanced Audio CODEC interface (PL041).
Don't expect this driver to work on real hardware, but QEMU emulates it.
--
Add fdt glue for ARM PrimeCell Advanced Audio CODEC interface (PL041).
--
Add aaci at fdt, commented out for now. Driver should work (tm) but QEMU
and my old Thinkpad can't seem to keep up.
--
Fix two bugs:
- Inverted test for fifo status in aaci_write_data
- Return success from trigger_output (thanks nat)
--
Enable aaci
--
bus_space_write_multi_4 takes a count, not number of bytes. With this,
audio works in qemu.
 1.3.2.1 08-Jun-2017  snj file pl041.c was added on branch netbsd-8 on 2017-06-09 16:59:20 +0000
 1.4.2.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.4.2.1 10-Jun-2019  christos Sync with HEAD
 1.5.2.2 04-May-2019  isaki Move dev/audio_if.h -> dev/audio/audio_if.h
 1.5.2.1 27-Apr-2019  isaki Adapt to audio2.
 1.6.4.1 29-Feb-2020  ad Sync with head.
 1.2 08-May-2019  isaki Merge isaki-audio2 branch, the overhaul of audio subsystem.
- Interrupt-oriented system rather than thread-oriented.
- Improve stability, quality and performance.
- Split playback and record cleanly. Improve halfduplex support.
- Many bugs are fixed including deadlocks, resource leaks, abuses, etc.
- Simplify audio filter mechanism. The encoding/channels/frequency
conversions are completely handled in the upper layer. So the hard-
ware driver only converts its hardware encoding (if necessary).
- audio_hw_if changes:
- Obsoletes query_encoding and add query_format instead.
- Obsoletes set_params and add set_format instead.
- Remove drain, setfd, mappage.
- The call sequences are changed.
- ioctl AUDIO_GETFD/SETFD, AUDIO_GETCHAN/SETCHAN are obsoleted.
- ioctl AUDIO_{QUERY,GET,SET}FORMAT are introduced.
- cleanup config attributes: au*conv and mulaw.
- All hardware drivers should follow it (I've done as much as possible).

Some file paths are changed:
- dev/audio.c -> dev/audio/audio.c (rewritten)
- dev/audiovar.h -> dev/audio/audiovar.h
- dev/audio_dai.h -> dev/audio/audio_dai.h
- dev/audio_if.h -> dev/audio/audio_if.h
- dev/audiobell.c -> dev/audio/audiobell.c
- dev/audiobellvar.h -> dev/audio/audiobellvar.h
- dev/mulaw.[ch] -> dev/audio/mulaw.[ch] + dev/audio/alaw.c
 1.1 08-Jun-2017  jmcneill branches: 1.1.2; 1.1.6; 1.1.8; 1.1.12; 1.1.16;
Add driver for ARM PrimeCell Advanced Audio CODEC interface (PL041).

Don't expect this driver to work on real hardware, but QEMU emulates it.
 1.1.16.2 03-May-2019  isaki Remove unnecessary header file.
 1.1.16.1 27-Apr-2019  isaki Adapt to audio2.
 1.1.12.1 10-Jun-2019  christos Sync with HEAD
 1.1.8.2 03-Dec-2017  jdolecek update from HEAD
 1.1.8.1 08-Jun-2017  jdolecek file pl041var.h was added on branch tls-maxphys on 2017-12-03 11:37:04 +0000
 1.1.6.2 28-Aug-2017  skrll Sync with HEAD
 1.1.6.1 08-Jun-2017  skrll file pl041var.h was added on branch nick-nhusb on 2017-08-28 17:52:03 +0000
 1.1.2.2 09-Jun-2017  snj Pull up following revision(s) (requested by jmcneill in ticket #17):
sys/arch/arm/fdt/aaci_fdt.c: revision 1.1
sys/arch/arm/fdt/files.fdt: revision 1.10
sys/arch/evbarm/conf/VEXPRESS_A15: revisions 1.14, 1.15
sys/conf/files: revision 1.1174
sys/dev/ic/pl041.c: revisions 1.1-1.3
sys/dev/ic/pl041var.h: revision 1.1
Add driver for ARM PrimeCell Advanced Audio CODEC interface (PL041).
Don't expect this driver to work on real hardware, but QEMU emulates it.
--
Add fdt glue for ARM PrimeCell Advanced Audio CODEC interface (PL041).
--
Add aaci at fdt, commented out for now. Driver should work (tm) but QEMU
and my old Thinkpad can't seem to keep up.
--
Fix two bugs:
- Inverted test for fifo status in aaci_write_data
- Return success from trigger_output (thanks nat)
--
Enable aaci
--
bus_space_write_multi_4 takes a count, not number of bytes. With this,
audio works in qemu.
 1.1.2.1 08-Jun-2017  snj file pl041var.h was added on branch netbsd-8 on 2017-06-09 16:59:20 +0000
 1.2 06-Jun-2017  jmcneill branches: 1.2.4; 1.2.6;
Attach kbd slot to console
 1.1 03-Jun-2017  jmcneill branches: 1.1.2;
Add driver for ARM PrimeCell PL050 (KMI) PS2 keyboard/mouse interface
 1.1.2.1 06-Jun-2017  snj Pull up following revision(s) (requested by jmcneill in ticket #13):
sys/arch/arm/fdt/plfb_fdt.c: revision 1.2
sys/arch/arm/vexpress/vexpress_platform.c: revision 1.3
sys/arch/evbarm/conf/VEXPRESS_A15: revision 1.13
sys/arch/evbarm/fdt/fdt_machdep.c: revisions 1.5, 1.6
sys/dev/ic/pl050.c: revision 1.2
Fix spelling of WS_DEFAULT_FG and WS_KERNEL_FG options.
--
Attach kbd slot to console
--
Allow plfb to be the console device
--
Add support for stdout-path= kernel cmdline option to override the
console device specified in the FDT.
--
Initialize boot_args before bootstrap for the benefit of platform code.
--
Allow 'console=fb' to act as a shortcut on vexpress for
'stdout-path=/smb@08000000/motherboard/iofpga@3,00000000/clcd@1f0000'
 1.2.6.2 03-Dec-2017  jdolecek update from HEAD
 1.2.6.1 06-Jun-2017  jdolecek file pl050.c was added on branch tls-maxphys on 2017-12-03 11:37:04 +0000
 1.2.4.2 28-Aug-2017  skrll Sync with HEAD
 1.2.4.1 06-Jun-2017  skrll file pl050.c was added on branch nick-nhusb on 2017-08-28 17:52:03 +0000
 1.1 03-Jun-2017  jmcneill branches: 1.1.6; 1.1.10;
Add driver for ARM PrimeCell PL050 (KMI) PS2 keyboard/mouse interface
 1.1.10.2 03-Dec-2017  jdolecek update from HEAD
 1.1.10.1 03-Jun-2017  jdolecek file pl050var.h was added on branch tls-maxphys on 2017-12-03 11:37:04 +0000
 1.1.6.2 28-Aug-2017  skrll Sync with HEAD
 1.1.6.1 03-Jun-2017  skrll file pl050var.h was added on branch nick-nhusb on 2017-08-28 17:52:03 +0000
 1.4 07-Aug-2021  thorpej Merge thorpej-cfargs2.
 1.3 24-Apr-2021  thorpej branches: 1.3.8;
Merge thorpej-cfargs branch:

Simplify and make extensible the config_search() / config_found() /
config_attach() interfaces: rather than having different variants for
which arguments you want pass along, just have a single call that
takes a variadic list of tag-value arguments.

Adjust all call sites:
- Simplify wherever possible; don't pass along arguments that aren't
actually needed.
- Don't be explicit about what interface attribute is attaching if
the device only has one. (More simplification.)
- Add a config_probe() function to be used in indirect configuiration
situations, making is visibly easier to see when indirect config is
in play, and allowing for future change in semantics. (As of now,
this is just a wrapper around config_match(), but that is an
implementation detail.)

Remove unnecessary or redundant interface attributes where they're not
needed.

There are currently 5 "cfargs" defined:
- CFARG_SUBMATCH (submatch function for direct config)
- CFARG_SEARCH (search function for indirect config)
- CFARG_IATTR (interface attribte)
- CFARG_LOCATORS (locators array)
- CFARG_DEVHANDLE (devhandle_t - wraps OFW, ACPI, etc. handles)

...and a sentinel value CFARG_EOL.

Add some extra sanity checking to ensure that interface attributes
aren't ambiguous.

Use CFARG_DEVHANDLE in MI FDT, OFW, and ACPI code, and macppc and shark
ports to associate those device handles with device_t instance. This
will trickle trough to more places over time (need back-end for pre-OFW
Sun OBP; any others?).
 1.2 21-Oct-2018  jmcneill branches: 1.2.4; 1.2.16;
Allow bus glue to reserve pins for private use
 1.1 15-Oct-2018  jmcneill branches: 1.1.2;
Rename pl061gpio to plgpio and split the device logic from the FDT glue.
 1.1.2.3 26-Nov-2018  pgoyette Sync with HEAD, resolve a couple of conflicts
 1.1.2.2 20-Oct-2018  pgoyette Sync with head
 1.1.2.1 15-Oct-2018  pgoyette file pl061.c was added on branch pgoyette-compat on 2018-10-20 06:58:31 +0000
 1.2.16.1 23-Mar-2021  thorpej Convert config_found_ia() call sites where the device only carries
a single interface attribute to bare config_found() calls.
 1.2.4.2 10-Jun-2019  christos Sync with HEAD
 1.2.4.1 21-Oct-2018  christos file pl061.c was added on branch phil-wifi on 2019-06-10 22:07:11 +0000
 1.3.8.1 04-Aug-2021  thorpej Adapt to CFARGS().
 1.1 15-Jun-2018  jakllsch branches: 1.1.2;
Add basic ARM PL061 GPIO driver with FDT attachment.

Mostly for Qemu 'virt' platform; really needs interrupt support
in gpiokeys(4) and this driver to work efficently and reliably.
 1.1.2.2 25-Jun-2018  pgoyette Sync with HEAD
 1.1.2.1 15-Jun-2018  pgoyette file pl061reg.h was added on branch pgoyette-compat on 2018-06-25 07:25:50 +0000
 1.2 21-Oct-2018  jmcneill branches: 1.2.4;
Allow bus glue to reserve pins for private use
 1.1 15-Oct-2018  jmcneill branches: 1.1.2;
Rename pl061gpio to plgpio and split the device logic from the FDT glue.
 1.1.2.3 26-Nov-2018  pgoyette Sync with HEAD, resolve a couple of conflicts
 1.1.2.2 20-Oct-2018  pgoyette Sync with head
 1.1.2.1 15-Oct-2018  pgoyette file pl061var.h was added on branch pgoyette-compat on 2018-10-20 06:58:31 +0000
 1.2.4.2 10-Jun-2019  christos Sync with HEAD
 1.2.4.1 21-Oct-2018  christos file pl061var.h was added on branch phil-wifi on 2019-06-10 22:07:11 +0000
 1.9 07-Aug-2021  thorpej Merge thorpej-cfargs2.
 1.8 24-Apr-2021  thorpej branches: 1.8.8;
Merge thorpej-cfargs branch:

Simplify and make extensible the config_search() / config_found() /
config_attach() interfaces: rather than having different variants for
which arguments you want pass along, just have a single call that
takes a variadic list of tag-value arguments.

Adjust all call sites:
- Simplify wherever possible; don't pass along arguments that aren't
actually needed.
- Don't be explicit about what interface attribute is attaching if
the device only has one. (More simplification.)
- Add a config_probe() function to be used in indirect configuiration
situations, making is visibly easier to see when indirect config is
in play, and allowing for future change in semantics. (As of now,
this is just a wrapper around config_match(), but that is an
implementation detail.)

Remove unnecessary or redundant interface attributes where they're not
needed.

There are currently 5 "cfargs" defined:
- CFARG_SUBMATCH (submatch function for direct config)
- CFARG_SEARCH (search function for indirect config)
- CFARG_IATTR (interface attribte)
- CFARG_LOCATORS (locators array)
- CFARG_DEVHANDLE (devhandle_t - wraps OFW, ACPI, etc. handles)

...and a sentinel value CFARG_EOL.

Add some extra sanity checking to ensure that interface attributes
aren't ambiguous.

Use CFARG_DEVHANDLE in MI FDT, OFW, and ACPI code, and macppc and shark
ports to associate those device handles with device_t instance. This
will trickle trough to more places over time (need back-end for pre-OFW
Sun OBP; any others?).
 1.7 12-Jun-2019  skrll branches: 1.7.12;
Trailing whitespace
 1.6 03-Sep-2018  riastradh Rename min/max -> uimin/uimax for better honesty.

These functions are defined on unsigned int. The generic name
min/max should not silently truncate to 32 bits on 64-bit systems.
This is purely a name change -- no functional change intended.

HOWEVER! Some subsystems have

#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))

even though our standard name for that is MIN/MAX. Although these
may invite multiple evaluation bugs, these do _not_ cause integer
truncation.

To avoid `fixing' these cases, I first changed the name in libkern,
and then compile-tested every file where min/max occurred in order to
confirm that it failed -- and thus confirm that nothing shadowed
min/max -- before changing it.

I have left a handful of bootloaders that are too annoying to
compile-test, and some dead code:

cobalt ews4800mips hp300 hppa ia64 luna68k vax
acorn32/if_ie.c (not included in any kernels)
macppc/if_gm.c (superseded by gem(4))

It should be easy to fix the fallout once identified -- this way of
doing things fails safe, and the goal here, after all, is to _avoid_
silent integer truncations, not introduce them.

Maybe one day we can reintroduce min/max as type-generic things that
never silently truncate. But we should avoid doing that for a while,
so that existing code has a chance to be detected by the compiler for
conversion to uimin/uimax without changing the semantics until we can
properly audit it all. (Who knows, maybe in some cases integer
truncation is actually intended!)
 1.5 19-Feb-2018  jmcneill branches: 1.5.2; 1.5.4;
Rewrite data transfer path to take advantage of the PL181's 64-byte FIFO.

Before: 134217728 bytes transferred in 43.683 secs (3072539 bytes/sec)
After: 134217728 bytes transferred in 23.789 secs (5642007 bytes/sec)
 1.4 04-Jun-2017  jmcneill branches: 1.4.4;
Re-introduce support for multi-block transfers and split transfers to fit
within the 65535-byte limit.
 1.3 02-Jun-2017  jmcneill branches: 1.3.2;
Separate clock frequency from maximum supported bus frequency.
 1.2 01-Jun-2017  jmcneill The sdmmc layer will send single requests up to MAXPHYS (65536) in size.
The length field on PL180/PL181 is 16-bit, and can only support up to
65535 byte transfers.

Workaround this for now by setting the SMC_CAPS_SINGLE_ONLY flag to only
do single block (512-byte) transfers. While here set SMC_CAPS_4BIT_MODE
as well.
 1.1 27-Jan-2015  jmcneill branches: 1.1.2;
Add driver for ARM PrimeCell MultiMedia Card Interface (PL181). Not tested
with real hardware, only qemu "integratorcp" configuration.
 1.1.2.3 28-Aug-2017  skrll Sync with HEAD
 1.1.2.2 06-Apr-2015  skrll Sync with HEAD
 1.1.2.1 27-Jan-2015  skrll file pl181.c was added on branch nick-nhusb on 2015-04-06 15:18:09 +0000
 1.3.2.1 04-Jun-2017  bouyer Pull up following revision(s) (requested by jmcneill in ticket #3):
sys/dev/sdmmc/sdmmcvar.h: revision 1.24
sys/dev/sdmmc/sdmmc_mem.c: revision 1.57
sys/dev/ic/pl181.c: revision 1.4
Give a hint to controllers in the command flags if we are performing a
transfer with an SDHC capable card. If the controller needs to adjust
command args, it can use this hint to understand how it is encoded.
Re-introduce support for multi-block transfers and split transfers to fit
within the 65535-byte limit.
 1.4.4.2 03-Dec-2017  jdolecek update from HEAD
 1.4.4.1 04-Jun-2017  jdolecek file pl181.c was added on branch tls-maxphys on 2017-12-03 11:37:04 +0000
 1.5.4.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.5.4.1 10-Jun-2019  christos Sync with HEAD
 1.5.2.1 06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.7.12.1 21-Mar-2021  thorpej Give config_found() the same variadic arguments treatment as
config_search(). This commit only adds the CFARG_EOL sentinel
to the existing config_found() calls. Conversion of config_found_sm_loc()
and config_found_ia() call sites will be in subsequent commits.
 1.8.8.1 04-Aug-2021  thorpej Adapt to CFARGS().
 1.1 27-Jan-2015  jmcneill branches: 1.1.2; 1.1.18;
Add driver for ARM PrimeCell MultiMedia Card Interface (PL181). Not tested
with real hardware, only qemu "integratorcp" configuration.
 1.1.18.2 03-Dec-2017  jdolecek update from HEAD
 1.1.18.1 27-Jan-2015  jdolecek file pl181reg.h was added on branch tls-maxphys on 2017-12-03 11:37:04 +0000
 1.1.2.2 06-Apr-2015  skrll Sync with HEAD
 1.1.2.1 27-Jan-2015  skrll file pl181reg.h was added on branch nick-nhusb on 2015-04-06 15:18:09 +0000
 1.3 19-Feb-2018  jmcneill Rewrite data transfer path to take advantage of the PL181's 64-byte FIFO.

Before: 134217728 bytes transferred in 43.683 secs (3072539 bytes/sec)
After: 134217728 bytes transferred in 23.789 secs (5642007 bytes/sec)
 1.2 02-Jun-2017  jmcneill branches: 1.2.8;
Separate clock frequency from maximum supported bus frequency.
 1.1 27-Jan-2015  jmcneill branches: 1.1.2;
Add driver for ARM PrimeCell MultiMedia Card Interface (PL181). Not tested
with real hardware, only qemu "integratorcp" configuration.
 1.1.2.3 28-Aug-2017  skrll Sync with HEAD
 1.1.2.2 06-Apr-2015  skrll Sync with HEAD
 1.1.2.1 27-Jan-2015  skrll file pl181var.h was added on branch nick-nhusb on 2015-04-06 15:18:09 +0000
 1.2.8.2 03-Dec-2017  jdolecek update from HEAD
 1.2.8.1 02-Jun-2017  jdolecek file pl181var.h was added on branch tls-maxphys on 2017-12-03 11:37:04 +0000
 1.3 06-Apr-2024  skrll Add RISC-V support
 1.2 03-Sep-2018  riastradh Rename min/max -> uimin/uimax for better honesty.

These functions are defined on unsigned int. The generic name
min/max should not silently truncate to 32 bits on 64-bit systems.
This is purely a name change -- no functional change intended.

HOWEVER! Some subsystems have

#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))

even though our standard name for that is MIN/MAX. Although these
may invite multiple evaluation bugs, these do _not_ cause integer
truncation.

To avoid `fixing' these cases, I first changed the name in libkern,
and then compile-tested every file where min/max occurred in order to
confirm that it failed -- and thus confirm that nothing shadowed
min/max -- before changing it.

I have left a handful of bootloaders that are too annoying to
compile-test, and some dead code:

cobalt ews4800mips hp300 hppa ia64 luna68k vax
acorn32/if_ie.c (not included in any kernels)
macppc/if_gm.c (superseded by gem(4))

It should be easy to fix the fallout once identified -- this way of
doing things fails safe, and the goal here, after all, is to _avoid_
silent integer truncations, not introduce them.

Maybe one day we can reintroduce min/max as type-generic things that
never silently truncate. But we should avoid doing that for a while,
so that existing code has a chance to be detected by the compiler for
conversion to uimin/uimax without changing the semantics until we can
properly audit it all. (Who knows, maybe in some cases integer
truncation is actually intended!)
 1.1 25-Nov-2017  jmcneill branches: 1.1.2; 1.1.4; 1.1.6;
Add driver for QEMU Firmware Configuration device.

This interface allows the host to pass various data items and files to
the guest OS.
 1.1.6.1 10-Jun-2019  christos Sync with HEAD
 1.1.4.1 06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.1.2.2 03-Dec-2017  jdolecek update from HEAD
 1.1.2.1 25-Nov-2017  jdolecek file qemufwcfg.c was added on branch tls-maxphys on 2017-12-03 11:37:04 +0000
 1.1 25-Nov-2017  jmcneill branches: 1.1.2;
Add driver for QEMU Firmware Configuration device.

This interface allows the host to pass various data items and files to
the guest OS.
 1.1.2.2 03-Dec-2017  jdolecek update from HEAD
 1.1.2.1 25-Nov-2017  jdolecek file qemufwcfgio.h was added on branch tls-maxphys on 2017-12-03 11:37:04 +0000
 1.1 25-Nov-2017  jmcneill branches: 1.1.2;
Add driver for QEMU Firmware Configuration device.

This interface allows the host to pass various data items and files to
the guest OS.
 1.1.2.2 03-Dec-2017  jdolecek update from HEAD
 1.1.2.1 25-Nov-2017  jdolecek file qemufwcfgvar.h was added on branch tls-maxphys on 2017-12-03 11:37:04 +0000
 1.8 06-Jun-2006  rpaulo Attachment framework for the rt2561.c and rt2661.c drivers.

From OpenBSD.
 1.7 03-Jun-2006  rpaulo Sean Boudreau: The eeprom bits are shifted out in host order.
Also present in the upcoming rt2560.c driver.
 1.6 18-Nov-2005  skrll branches: 1.6.4; 1.6.6; 1.6.8; 1.6.14;
Adapt drivers to the new net80211(9).

Most of this is from dyoung@. Thanks!
 1.5 16-Aug-2005  christos branches: 1.5.6; 1.5.8;
PR/31000: FUKAUMI Naoki: 2 bugs in ral driver:
- remove driver-private key allocators; use the default one instead
so wpa keys are handled properly (if_ral.c, if_ural.c rev 1.9)

- remove local mods that snuck into rev 1.6 (if_ral.c rev 1.10)
 1.4 12-Jul-2005  drochner fixes from FUKAUMI Naoki. Changes are
> Enable WEP (software engine).
> Add support for WPA[12].
> Print modes and rates.
> Add new devices.
> And some small changes and bug fixes.
 1.3 06-Jul-2005  dyoung Avoid an unnecessary API difference between NetBSD and FreeBSD:
back out my change to ieee80211_crypto_encap that made it free its
mbuf argument on error. I had thought it was a bug. It was not.
It's the drivers that are broken. Make an(4), atw(4), ipw(4),
iwi(4), ral(4), rtw(4), ural(4), and wi(4) free the mbuf when
ieee80211_crypto_encap returns NULL. Also, return ath(4) to the
way it was---i.e., free the mbuf.

Thanks to Sam Leffler to pointing out my mistake.
 1.2 04-Jul-2005  drochner branches: 1.2.2;
update PCI/Cardbus ral wlan driver, and adapt to new FreeBSD/NetBSD
80211 framework, from FUKAUMI Naoki per mail to tech-net
 1.1 01-Jul-2005  drochner add drivers for Ralink RT2500-based wireless adapters, written by
Damien Bergamini, ported and submitted by FUKAUMI Naoki per PR kern/30449
I've modified the USB "ural" driver for recent changes to the NetBSD
ieee80211 framework, possibly not completely, but with an ASUS wireless
adapter I'm getting some signs of life.
Didn't care about pci/cardbus for now, hopefully someone with hardware
will do it.
 1.2.2.1 21-Jun-2006  yamt sync with head.
 1.5.8.1 22-Nov-2005  yamt sync with head.
 1.5.6.3 11-Dec-2005  christos Sync with head.
 1.5.6.2 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.5.6.1 16-Aug-2005  skrll file ral.c was added on branch ktrace-lwp on 2005-11-10 14:04:15 +0000
 1.6.14.1 19-Jun-2006  chap Sync with head.
 1.6.8.1 26-Jun-2006  yamt sync with head.
 1.6.6.2 07-Jun-2006  kardel Sync with head.
 1.6.6.1 03-Jun-2006  kardel Sync with head.
 1.6.4.1 09-Sep-2006  rpaulo sync with head
 1.3 06-Jun-2006  rpaulo Attachment framework for the rt2561.c and rt2661.c drivers.

From OpenBSD.
 1.2 11-Dec-2005  christos branches: 1.2.4; 1.2.6; 1.2.8; 1.2.14;
merge ktrace-lwp.
 1.1 01-Jul-2005  drochner branches: 1.1.2; 1.1.8;
add drivers for Ralink RT2500-based wireless adapters, written by
Damien Bergamini, ported and submitted by FUKAUMI Naoki per PR kern/30449
I've modified the USB "ural" driver for recent changes to the NetBSD
ieee80211 framework, possibly not completely, but with an ASUS wireless
adapter I'm getting some signs of life.
Didn't care about pci/cardbus for now, hopefully someone with hardware
will do it.
 1.1.8.2 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.1.8.1 01-Jul-2005  skrll file ralreg.h was added on branch ktrace-lwp on 2005-11-10 14:04:15 +0000
 1.1.2.1 21-Jun-2006  yamt sync with head.
 1.2.14.1 19-Jun-2006  chap Sync with head.
 1.2.8.1 26-Jun-2006  yamt sync with head.
 1.2.6.1 07-Jun-2006  kardel Sync with head.
 1.2.4.1 09-Sep-2006  rpaulo sync with head
 1.5 06-Jun-2006  rpaulo Attachment framework for the rt2561.c and rt2661.c drivers.

From OpenBSD.
 1.4 05-May-2006  drochner branches: 1.4.2;
make sure "radiotap" capture data are aligned,
thanks to Pierrick Brossin for verifying the effect on "tcpdump" output
 1.3 11-Dec-2005  christos branches: 1.3.4; 1.3.6; 1.3.8; 1.3.10; 1.3.12;
merge ktrace-lwp.
 1.2 04-Jul-2005  drochner branches: 1.2.2; 1.2.8;
update PCI/Cardbus ral wlan driver, and adapt to new FreeBSD/NetBSD
80211 framework, from FUKAUMI Naoki per mail to tech-net
 1.1 01-Jul-2005  drochner add drivers for Ralink RT2500-based wireless adapters, written by
Damien Bergamini, ported and submitted by FUKAUMI Naoki per PR kern/30449
I've modified the USB "ural" driver for recent changes to the NetBSD
ieee80211 framework, possibly not completely, but with an ASUS wireless
adapter I'm getting some signs of life.
Didn't care about pci/cardbus for now, hopefully someone with hardware
will do it.
 1.2.8.2 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.2.8.1 04-Jul-2005  skrll file ralvar.h was added on branch ktrace-lwp on 2005-11-10 14:04:15 +0000
 1.2.2.1 21-Jun-2006  yamt sync with head.
 1.3.12.1 24-May-2006  tron Merge 2006-05-24 NetBSD-current into the "peter-altq" branch.
 1.3.10.1 11-May-2006  elad sync with head
 1.3.8.2 26-Jun-2006  yamt sync with head.
 1.3.8.1 24-May-2006  yamt sync with head.
 1.3.6.2 07-Jun-2006  kardel Sync with head.
 1.3.6.1 01-Jun-2006  kardel Sync with head.
 1.3.4.1 09-Sep-2006  rpaulo sync with head
 1.4.2.1 19-Jun-2006  chap Sync with head.
 1.8 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.7 11-Dec-2005  christos branches: 1.7.70; 1.7.72; 1.7.74;
merge ktrace-lwp.
 1.6 01-Jun-2005  drochner add "const" where needed
 1.5 27-Feb-2005  perry nuke trailing whitespace
 1.4 04-Feb-2005  perry de-__P
 1.3 12-Dec-2001  elric branches: 1.3.16; 1.3.24; 1.3.26;
Update the ramdac interface to be allow the setting of dotclocks. This is
required to support the driver in ibm561.c.
 1.2 02-Apr-2000  nathanw branches: 1.2.6; 1.2.8; 1.2.10;
Add ramdac_register() to interface structure.
 1.1 04-Mar-2000  elric Header for a generic RAMDAC that can be reused between different
graphics cards.
 1.2.10.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.2.8.1 08-Jan-2002  nathanw Catch up to -current.
 1.2.6.2 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.2.6.1 02-Apr-2000  bouyer file ramdac.h was added on branch thorpej_scsipi on 2000-11-20 11:40:52 +0000
 1.3.26.2 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.3.26.1 12-Feb-2005  yamt sync with head.
 1.3.24.1 29-Apr-2005  kent sync with -current
 1.3.16.3 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.3.16.2 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.3.16.1 04-Feb-2005  skrll Sync with HEAD.
 1.7.74.1 16-May-2008  yamt sync with head.
 1.7.72.1 18-May-2008  yamt sync with head.
 1.7.70.1 02-Jun-2008  mjf Sync with HEAD.
 1.6 19-Oct-2009  rmind Drop 3rd and 4th clauses from David Young's license.
Reviewed and approved by dyoung@ (copyright holder).
 1.5 08-Mar-2006  dyoung branches: 1.5.64;
Change macro names to avoid collisions:

BIT -> __BIT
BITS -> __BITS
 1.4 11-Dec-2005  christos branches: 1.4.4; 1.4.6; 1.4.8; 1.4.10;
merge ktrace-lwp.
 1.3 21-Jul-2004  dyoung branches: 1.3.2; 1.3.14;
Flesh out the register definitions.

Fix the botched RCS Id, $NetBSD -> $NetBSD$.
 1.2 15-Jul-2004  dyoung Here is the serial bus format for the RF3000.
 1.1 17-Feb-2004  dyoung Move the RF Microdevices RF3000 & Silicon Laboratories SI4126/SI4136
register sets into their own header files for re-use by future
drivers.
 1.3.14.1 21-Jun-2006  yamt sync with head.
 1.3.2.4 21-Sep-2004  skrll Fix the sync with head I botched.
 1.3.2.3 18-Sep-2004  skrll Sync with HEAD.
 1.3.2.2 03-Aug-2004  skrll Sync with HEAD
 1.3.2.1 21-Jul-2004  skrll file rf3000reg.h was added on branch ktrace-lwp on 2004-08-03 10:46:18 +0000
 1.4.10.1 19-Apr-2006  elad sync with head.
 1.4.8.1 13-Mar-2006  yamt sync with head.
 1.4.6.1 22-Apr-2006  simonb Sync with head.
 1.4.4.1 09-Sep-2006  rpaulo sync with head
 1.5.64.1 11-Mar-2010  yamt sync with head
 1.6 17-Aug-2021  andvar fix multiplei repetitive typos in comments, messages and documentation. mainly because copy paste code big amount of files are affected.
 1.5 08-Jan-2020  nonaka Added some RNDIS status definitions from FreeBSD.
 1.4 06-Dec-2019  nonaka Added RNDIS RSS and TCP offload related definitions.
 1.3 08-Aug-2019  maya Teach urndis to handle some REMOTE_NDIS_INDICATE_STATUS_MSG. If the status
is reasonable, don't tell userland we got an error. Stops spurious EIO.
From openbsd.
 1.2 15-Feb-2019  nonaka branches: 1.2.2; 1.2.6; 1.2.8;
Added Microsoft Hyper-V support. It ported from OpenBSD and FreeBSD.

graphical console is not work on Gen.2 VM yet. To use the serial console,
enter "consdev com,0x3f8,115200" on efiboot.
 1.1 14-Feb-2019  nonaka separate RNDIS definitions from urndis(4) for use with Hyper-V NetVSC.
 1.2.8.1 01-Sep-2019  martin Pull up following revision(s) (requested by mrg in ticket #135):

distrib/sets/lists/comp/mi 1.2279
distrib/sets/lists/modules/mi 1.123
share/man/man9/Makefile 1.438
share/man/man9/usbnet.9 1.1-1.9
sys/dev/ic/rndisreg.h 1.3
sys/dev/usb/TODO 1.47-1.52
sys/dev/usb/TODO.usbmp 1.15,1.16
sys/dev/usb/files.usb 1.157-1.167
sys/dev/usb/if_aue.c 1.155-1.161
sys/dev/usb/if_auereg.h 1.30-1.32
sys/dev/usb/if_axe.c 1.103-1.119
sys/dev/usb/if_axen.c 1.51-1.53,1.55-1.67
sys/dev/usb/if_axenreg.h 1.15
sys/dev/usb/if_cdce.c 1.54-1.67
sys/dev/usb/if_cue.c 1.85,1.86
sys/dev/usb/if_cuereg.h 1.23
sys/dev/usb/if_kue.c 1.97-1.100
sys/dev/usb/if_kuereg.h 1.23,1.24
sys/dev/usb/if_mue.c 1.51-1.55
sys/dev/usb/if_muereg.h 1.6
sys/dev/usb/if_muevar.h 1.9
sys/dev/usb/if_smsc.c 1.46-1.61
sys/dev/usb/if_smscreg.h 1.6
sys/dev/usb/if_smscvar.h delete
sys/dev/usb/if_udav.c 1.60-1.71
sys/dev/usb/if_udavreg.h 1.14,1.15
sys/dev/usb/if_upl.c 1.65,1.66
sys/dev/usb/if_ure.c 1.15-1.31
sys/dev/usb/if_urevar.h 1.4,1.5
sys/dev/usb/if_url.c 1.67-1.70
sys/dev/usb/if_urlreg.h 1.14
sys/dev/usb/if_urndis.c 1.22-1.33
sys/dev/usb/if_urtwn.c 1.72
sys/dev/usb/ohci.c 1.290
sys/dev/usb/uhub.c 1.143
sys/dev/usb/usb.c 1.180
sys/dev/usb/usb.h 1.118
sys/dev/usb/usb_mem.c 1.71
sys/dev/usb/usb_subr.c 1.238,1.239
sys/dev/usb/usbdevs 1.772
sys/dev/usb/usbdi.c 1.183,1.186
sys/dev/usb/usbdi.h 1.97
sys/dev/usb/usbdi_util.c 1.75
sys/dev/usb/usbhist.h 1.5,1.6
sys/dev/usb/usbnet.c 1.1-1.24
sys/dev/usb/usbnet.h 1.1-1.14
sys/dev/usb/usbroothub.c 1.9
sys/dev/usb/xhci.c 1.109,1.110
sys/modules/Makefile 1.223
sys/modules/usbnet/Makefile 1.1

usbnet(9): Add common framework for USB network devices.
This bring various safety fixes to all updated drivers,
and includes locking clean up, detach safety when being
used or not, separate rx/tx locks to improve performance,
porting to NET_MPSAFE, many edge/error case bugs in
drivers fixed, as well as resovling PRs 54303 and 54308.
These drivers are converted: axe(4), axen(4), aue(4),
cdce(4), cue(4), kue(4), mue(4), smsc(4), udav(4),
upl(4), ure(4), url(4), and urndis(4).
 1.2.6.4 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.2.6.3 08-Apr-2020  martin Merge changes from current as of 20200406
 1.2.6.2 10-Jun-2019  christos Sync with HEAD
 1.2.6.1 15-Feb-2019  christos file rndisreg.h was added on branch phil-wifi on 2019-06-10 22:07:11 +0000
 1.2.2.2 09-Mar-2019  martin Pull up following revision(s) via patch (requested by nonaka in ticket #1210):

sys/dev/hyperv/vmbusvar.h: revision 1.1
sys/dev/hyperv/hvs.c: revision 1.1
sys/dev/hyperv/if_hvn.c: revision 1.1
sys/dev/hyperv/vmbusic.c: revision 1.1
sys/arch/x86/x86/lapic.c: revision 1.69
sys/arch/x86/isa/clock.c: revision 1.34
sys/arch/x86/include/intrdefs.h: revision 1.22
sys/arch/i386/conf/GENERIC: revision 1.1201
sys/arch/x86/x86/hyperv.c: revision 1.1
sys/arch/x86/include/cpu.h: revision 1.105
sys/arch/x86/x86/x86_machdep.c: revision 1.124
sys/arch/i386/conf/GENERIC: revision 1.1203
sys/arch/amd64/amd64/genassym.cf: revision 1.74
sys/arch/i386/conf/GENERIC: revision 1.1204
sys/arch/amd64/conf/GENERIC: revision 1.520
sys/arch/x86/x86/hypervreg.h: revision 1.1
sys/arch/amd64/amd64/vector.S: revision 1.69
sys/dev/hyperv/hvshutdown.c: revision 1.1
sys/dev/hyperv/hvshutdown.c: revision 1.2
sys/dev/usb/if_urndisreg.h: file removal
sys/arch/x86/x86/cpu.c: revision 1.167
sys/arch/x86/conf/files.x86: revision 1.107
sys/dev/usb/if_urndis.c: revision 1.20
sys/dev/hyperv/vmbusicreg.h: revision 1.1
sys/dev/hyperv/hvheartbeat.c: revision 1.1
sys/dev/hyperv/vmbusicreg.h: revision 1.2
sys/dev/hyperv/hvheartbeat.c: revision 1.2
sys/dev/hyperv/files.hyperv: revision 1.1
sys/dev/ic/rndisreg.h: revision 1.1
sys/arch/i386/i386/genassym.cf: revision 1.111
sys/dev/ic/rndisreg.h: revision 1.2
sys/dev/hyperv/hyperv_common.c: revision 1.1
sys/dev/hyperv/hvtimesync.c: revision 1.1
sys/dev/hyperv/hypervreg.h: revision 1.1
sys/dev/hyperv/hvtimesync.c: revision 1.2
sys/dev/hyperv/vmbusicvar.h: revision 1.1
sys/dev/hyperv/if_hvnreg.h: revision 1.1
sys/arch/x86/x86/lapic.c: revision 1.70
sys/arch/amd64/amd64/vector.S: revision 1.70
sys/dev/ic/ndisreg.h: revision 1.1
sys/arch/amd64/conf/GENERIC: revision 1.516
sys/dev/hyperv/hypervvar.h: revision 1.1
sys/arch/amd64/conf/GENERIC: revision 1.518
sys/arch/amd64/conf/GENERIC: revision 1.519
sys/arch/i386/conf/files.i386: revision 1.400
sys/dev/acpi/vmbus_acpi.c: revision 1.1
sys/dev/hyperv/vmbus.c: revision 1.1
sys/dev/hyperv/vmbus.c: revision 1.2
sys/arch/x86/x86/intr.c: revision 1.144
sys/arch/i386/i386/vector.S: revision 1.83
sys/arch/amd64/conf/files.amd64: revision 1.112

separate RNDIS definitions from urndis(4) for use with Hyper-V NetVSC.

-

Added Microsoft Hyper-V support. It ported from OpenBSD and FreeBSD.
graphical console is not work on Gen.2 VM yet. To use the serial console,
enter "consdev com,0x3f8,115200" on efiboot.

-

Add __diagused.

-

PR/53984: Partial revert of modify lapic_calibrate_timer() in lapic.c r1.69.

-

Update Hyper-V related drivers description.

-

Remove unused definition.

-

Rename the MODULE_*_HOOK() macros to MODULE_HOOK_*() as briefly
discussed on irc.
NFCI intended.

-

commented out hvkvp entry.

-

fix typo. pointed out by pgoyette@n.o.

-

Use IDTVEC instead of NENTRY for handle_hyperv_hypercall.

-

Rename the MODULE_*_HOOK() macros to MODULE_HOOK_*() as briefly
discussed on irc.
 1.2.2.1 15-Feb-2019  martin file rndisreg.h was added on branch netbsd-8 on 2019-03-09 17:10:20 +0000
 1.4 19-Mar-2022  riastradh rnd(9): Omit needless locks in various HWRNG drivers.

Now that the rnd(9) API guarantees serial callbacks, we can simplify
everything a bit more.

(Some drivers like hifn(4) and sun8icrypto(4) still use locks to
coordinate with other parts of the driver to submit requests to and
process responses from the device.)
 1.3 19-Mar-2022  riastradh rnd(9): Adjust IPL of locks used by rndsource callbacks.

These no longer ever run from hard interrupt context or with a spin
lock held, so there is no longer any need to have them at IPL_VM to
block hard interrupts. Instead, lower them to IPL_SOFTSERIAL.
 1.2 30-Apr-2020  riastradh rnd_attach_source calls the callback itself now.

No need for every driver to explicitly call it to prime the pool.

Eliminate now-unused <sys/rndpool.h>.
 1.1 01-Sep-2019  mlelstv branches: 1.1.8;
Driver for Broadcom RNG200 hardware random generator
 1.1.8.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.1.8.1 01-Sep-2019  martin file rng200.c was added on branch phil-wifi on 2020-04-13 08:04:22 +0000
 1.1 01-Sep-2019  mlelstv branches: 1.1.8;
Driver for Broadcom RNG200 hardware random generator
 1.1.8.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.1.8.1 01-Sep-2019  martin file rng200reg.h was added on branch phil-wifi on 2020-04-13 08:04:22 +0000
 1.2 19-Mar-2022  riastradh rnd(9): Omit needless locks in various HWRNG drivers.

Now that the rnd(9) API guarantees serial callbacks, we can simplify
everything a bit more.

(Some drivers like hifn(4) and sun8icrypto(4) still use locks to
coordinate with other parts of the driver to submit requests to and
process responses from the device.)
 1.1 01-Sep-2019  mlelstv branches: 1.1.8;
Driver for Broadcom RNG200 hardware random generator
 1.1.8.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.1.8.1 01-Sep-2019  martin file rng200var.h was added on branch phil-wifi on 2020-04-13 08:04:22 +0000
 1.90 19-Jan-2020  thorpej Remove HIPPI support and the esh(4) driver that uses it. There have not
been any users of HIPPI for some time, and it is unlikely to be resurrected.
 1.89 05-Feb-2019  msaitoh branches: 1.89.6;
Remove very old IFF_NOTRAILERS flag.
 1.88 03-Sep-2018  riastradh Rename min/max -> uimin/uimax for better honesty.

These functions are defined on unsigned int. The generic name
min/max should not silently truncate to 32 bits on 64-bit systems.
This is purely a name change -- no functional change intended.

HOWEVER! Some subsystems have

#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))

even though our standard name for that is MIN/MAX. Although these
may invite multiple evaluation bugs, these do _not_ cause integer
truncation.

To avoid `fixing' these cases, I first changed the name in libkern,
and then compile-tested every file where min/max occurred in order to
confirm that it failed -- and thus confirm that nothing shadowed
min/max -- before changing it.

I have left a handful of bootloaders that are too annoying to
compile-test, and some dead code:

cobalt ews4800mips hp300 hppa ia64 luna68k vax
acorn32/if_ie.c (not included in any kernels)
macppc/if_gm.c (superseded by gem(4))

It should be easy to fix the fallout once identified -- this way of
doing things fails safe, and the goal here, after all, is to _avoid_
silent integer truncations, not introduce them.

Maybe one day we can reintroduce min/max as type-generic things that
never silently truncate. But we should avoid doing that for a while,
so that existing code has a chance to be detected by the compiler for
conversion to uimin/uimax without changing the semantics until we can
properly audit it all. (Who knows, maybe in some cases integer
truncation is actually intended!)
 1.87 26-Jun-2018  msaitoh branches: 1.87.2;
Implement the BPF direction filter (BIOC[GS]DIRECTION). It provides backward
compatibility with BIOC[GS]SEESENT ioctl. The userland interface is the same
as FreeBSD.

This change also fixes a bug that the direction is misunderstand on some
environment by passing the direction to bpf_mtap*() instead of checking
m->m_pkthdr.rcvif.
 1.86 22-Jun-2018  msaitoh It's not required to include net/bpfdesc.h. Remove it.
 1.85 28-Oct-2017  riastradh branches: 1.85.2;
Kill some more extern struct cfdriver declarations.

Down with externs in .c!
 1.84 20-Aug-2017  maxv M_WAITOK cannot fail, so remove the test, otherwise it looks like an
spl leak; found by mootja
 1.83 15-Dec-2016  ozaki-r branches: 1.83.8;
Move bpf_mtap and if_ipackets++ on Rx of each driver to percpuq if_input

The benefits of the change are:
- We can reduce codes
- We can provide the same behavior between drivers
- Where/When if_ipackets is counted up
- Note that some drivers still update packet statistics in their own
way (periodical update)
- Moved bpf_mtap run in softint
- This makes it easy to MP-ify bpf

Proposed on tech-kern and tech-net
 1.82 02-Oct-2016  christos MFREE -> m_free
 1.81 10-Jun-2016  ozaki-r branches: 1.81.2;
Introduce m_set_rcvif and m_reset_rcvif

The API is used to set (or reset) a received interface of a mbuf.
They are counterpart of m_get_rcvif, which will come in another
commit, hide internal of rcvif operation, and reduce the diff of
the upcoming change.

No functional change.
 1.80 09-Feb-2016  ozaki-r Introduce softint-based if_input

This change intends to run the whole network stack in softint context
(or normal LWP), not hardware interrupt context. Note that the work is
still incomplete by this change; to that end, we also have to softint-ify
if_link_state_change (and bpf) which can still run in hardware interrupt.

This change softint-ifies at ifp->if_input that is called from
each device driver (and ieee80211_input) to ensure Layer 2 runs
in softint (e.g., ether_input and bridge_input). To this end,
we provide a framework (called percpuq) that utlizes softint(9)
and percpu ifqueues. With this patch, rxintr of most drivers just
queues received packets and schedules a softint, and the softint
dequeues packets and does rest packet processing.

To minimize changes to each driver, percpuq is allocated in struct
ifnet for now and that is initialized by default (in if_attach).
We probably have to move percpuq to softc of each driver, but it's
future work. At this point, only wm(4) has percpuq in its softc
as a reference implementation.

Additional information including performance numbers can be found
in the thread at tech-kern@ and tech-net@:
http://mail-index.netbsd.org/tech-kern/2016/01/14/msg019997.html

Acknowledgment: riastradh@ greatly helped this work.
Thank you very much!
 1.79 30-Aug-2015  dholland Restore interrupts on error path.

Also, on another path, avoid splx()'ing twice. While calling splx() a
second time with the same value has no further effect, it looks to me
like the first one of these calls is too early and some of the
subsequent operations are potential races. Not actually tested, I'm
afraid.

From maxv's brainy list.
 1.78 25-Jul-2014  dholland branches: 1.78.4;
Add d_discard to all struct cdevsw instances I could find.

All have been set to "nodiscard"; some should get a real implementation.
 1.77 16-Mar-2014  dholland branches: 1.77.2;
Change (mostly mechanically) every cdevsw/bdevsw I can find to use
designated initializers.

I have not built every extant kernel so I have probably broken at
least one build; however I've also found and fixed some wrong
cdevsw/bdevsw entries so even if so I think we come out ahead.
 1.76 15-Sep-2013  martin Remove unused variables
 1.75 27-Oct-2012  chs branches: 1.75.2;
split device_t/softc for all remaining drivers.
replace "struct device *" with "device_t".
use device_xname(), device_unit(), etc.
 1.74 05-Apr-2010  joerg branches: 1.74.8; 1.74.18;
Push the bpf_ops usage back into bpf.h. Push the common ifp->if_bpf
check into the inline functions as well the fourth argument for
bpf_attach.
 1.73 19-Jan-2010  pooka branches: 1.73.2; 1.73.4;
Redefine bpf linkage through an always present op vector, i.e.
#if NBPFILTER is no longer required in the client. This change
doesn't yet add support for loading bpf as a module, since drivers
can register before bpf is attached. However, callers of bpf can
now be modularized.

Dynamically loadable bpf could probably be done fairly easily with
coordination from the stub driver and the real driver by registering
attachments in the stub before the real driver is loaded and doing
a handoff. ... and I'm not going to ponder the depths of unload
here.

Tested with i386/MONOLITHIC, modified MONOLITHIC without bpf and rump.
 1.72 21-Oct-2009  rmind Remove uarea swap-out functionality:

- Addresses the issue described in PR/38828.
- Some simplification in threading and sleepq subsystems.
- Eliminates pmap_collect() and, as a side note, allows pmap optimisations.
- Eliminates XS_CTL_DATA_ONSTACK in scsipi code.
- Avoids few scans on LWP list and thus potentially long holds of proc_lock.
- Cuts ~1.5k lines of code. Reduces amd64 kernel size by ~4k.
- Removes __SWAP_BROKEN cases.

Tested on x86, mips, acorn32 (thanks <mpumford>) and partly tested on
acorn26 (thanks to <bjh21>).

Discussed on <tech-kern>, reviewed by <ad>.
 1.71 15-Apr-2009  elad Remove a few KAUTH_GENERIC_ISSUSER in favor of more descriptive
alternatives.

Discussed on tech-kern:

http://mail-index.netbsd.org/tech-kern/2009/04/11/msg004798.html

Input from ad@, christos@, dyoung@, tsutsui@.

Okay ad@.
 1.70 14-Mar-2009  dsl Change about 4500 of the K&R function definitions to ANSI ones.
There are still about 1600 left, but they have ',' or /* ... */
in the actual variable definitions - which my awk script doesn't handle.
There are also many that need () -> (void).
(The script does handle misordered arguments.)
 1.69 13-Jan-2009  yamt branches: 1.69.2;
g/c BUFQ_FOO() macros and use bufq_foo() directly.
 1.68 07-Nov-2008  dyoung *** Summary ***

When a link-layer address changes (e.g., ifconfig ex0 link
02:de:ad:be:ef:02 active), send a gratuitous ARP and/or a Neighbor
Advertisement to update the network-/link-layer address bindings
on our LAN peers.

Refuse a change of ethernet address to the address 00:00:00:00:00:00
or to any multicast/broadcast address. (Thanks matt@.)

Reorder ifnet ioctl operations so that driver ioctls may inherit
the functions of their "class"---ether_ioctl(), fddi_ioctl(), et
cetera---and the class ioctls may inherit from the generic ioctl,
ifioctl_common(), but both driver- and class-ioctls may override
the generic behavior. Make network drivers share more code.

Distinguish a "factory" link-layer address from others for the
purposes of both protecting that address from deletion and computing
EUI64.

Return consistent, appropriate error codes from network drivers.

Improve readability. KNF.

*** Details ***

In if_attach(), always initialize the interface ioctl routine,
ifnet->if_ioctl, if the driver has not already initialized it.
Delete if_ioctl == NULL tests everywhere else, because it cannot
happen.

In the ioctl routines of network interfaces, inherit common ioctl
behaviors by calling either ifioctl_common() or whichever ioctl
routine is appropriate for the class of interface---e.g., ether_ioctl()
for ethernets.

Stop (ab)using SIOCSIFADDR and start to use SIOCINITIFADDR. In
the user->kernel interface, SIOCSIFADDR's argument was an ifreq,
but on the protocol->ifnet interface, SIOCSIFADDR's argument was
an ifaddr. That was confusing, and it would work against me as I
make it possible for a network interface to overload most ioctls.
On the protocol->ifnet interface, replace SIOCSIFADDR with
SIOCINITIFADDR. In ifioctl(), return EPERM if userland tries to
invoke SIOCINITIFADDR.

In ifioctl(), give the interface the first shot at handling most
interface ioctls, and give the protocol the second shot, instead
of the other way around. Finally, let compatibility code (COMPAT_OSOCK)
take a shot.

Pull device initialization out of switch statements under
SIOCINITIFADDR. For example, pull ..._init() out of any switch
statement that looks like this:

switch (...->sa_family) {
case ...:
..._init();
...
break;
...
default:
..._init();
...
break;
}

Rewrite many if-else clauses that handle all permutations of IFF_UP
and IFF_RUNNING to use a switch statement,

switch (x & (IFF_UP|IFF_RUNNING)) {
case 0:
...
break;
case IFF_RUNNING:
...
break;
case IFF_UP:
...
break;
case IFF_UP|IFF_RUNNING:
...
break;
}

unifdef lots of code containing #ifdef FreeBSD, #ifdef NetBSD, and
#ifdef SIOCSIFMTU, especially in fwip(4) and in ndis(4).

In ipw(4), remove an if_set_sadl() call that is out of place.

In nfe(4), reuse the jumbo MTU logic in ether_ioctl().

Let ethernets register a callback for setting h/w state such as
promiscuous mode and the multicast filter in accord with a change
in the if_flags: ether_set_ifflags_cb() registers a callback that
returns ENETRESET if the caller should reset the ethernet by calling
if_init(), 0 on success, != 0 on failure. Pull common code from
ex(4), gem(4), nfe(4), sip(4), tlp(4), vge(4) into ether_ioctl(),
and register if_flags callbacks for those drivers.

Return ENOTTY instead of EINVAL for inappropriate ioctls. In
zyd(4), use ENXIO instead of ENOTTY to indicate that the device is
not any longer attached.

Add to if_set_sadl() a boolean 'factory' argument that indicates
whether a link-layer address was assigned by the factory or some
other source. In a comment, recommend using the factory address
for generating an EUI64, and update in6_get_hw_ifid() to prefer a
factory address to any other link-layer address.

Add a routing message, RTM_LLINFO_UPD, that tells protocols to
update the binding of network-layer addresses to link-layer addresses.
Implement this message in IPv4 and IPv6 by sending a gratuitous
ARP or a neighbor advertisement, respectively. Generate RTM_LLINFO_UPD
messages on a change of an interface's link-layer address.

In ether_ioctl(), do not let SIOCALIFADDR set a link-layer address
that is broadcast/multicast or equal to 00:00:00:00:00:00.

Make ether_ioctl() call ifioctl_common() to handle ioctls that it
does not understand.

In gif(4), initialize if_softc and use it, instead of assuming that
the gif_softc and ifp overlap.

Let ifioctl_common() handle SIOCGIFADDR.

Sprinkle rtcache_invariants(), which checks on DIAGNOSTIC kernels
that certain invariants on a struct route are satisfied.

In agr(4), rewrite agr_ioctl_filter() to be a bit more explicit
about the ioctls that we do not allow on an agr(4) member interface.

bzero -> memset. Delete unnecessary casts to void *. Use
sockaddr_in_init() and sockaddr_in6_init(). Compare pointers with
NULL instead of "testing truth". Replace some instances of (type
*)0 with NULL. Change some K&R prototypes to ANSI C, and join
lines.
 1.67 08-Jun-2008  tsutsui branches: 1.67.4; 1.67.6;
Replace device_lookup() with device_lookup_private() on getting softc
for future device_t/softc spilt.
 1.66 28-Apr-2008  martin branches: 1.66.2;
Remove clause 3 and 4 from TNF licenses
 1.65 08-Apr-2008  cegger branches: 1.65.2; 1.65.4;
use aprint_*_dev and device_xname
 1.64 19-Oct-2007  ad branches: 1.64.16;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.63 29-Jul-2007  ad branches: 1.63.4; 1.63.6; 1.63.10; 1.63.12;
It's not a good idea for device drivers to modify b_flags, as they don't
need to understand the locking around that field. Instead of setting
B_ERROR, set b_error instead. b_error is 'owned' by whoever completes
the I/O request.
 1.62 09-Jul-2007  ad branches: 1.62.2;
Merge some of the less invasive changes from the vmlocking branch:

- kthread, callout, devsw API changes
- select()/poll() improvements
- miscellaneous MT safety improvements
 1.61 04-Mar-2007  christos branches: 1.61.2; 1.61.4;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.60 04-Jan-2007  elad branches: 1.60.2;
Consistent usage of KAUTH_GENERIC_ISSUSER.
 1.59 16-Nov-2006  christos __unused removal on arguments; approved by core.
 1.58 12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.57 05-Oct-2006  chs add support for O_DIRECT (I/O directly to application memory,
bypassing any kernel caching for file data).
 1.56 07-Sep-2006  dogcow branches: 1.56.2; 1.56.4;
remove more vestiges of CCITT, LLC, HDLC, NS, and NSIP.
 1.55 03-Sep-2006  christos - add missing initializer
- correct function decl.
 1.54 21-Jul-2006  ad - Use the LWP cached credentials where sane.
- Minor cosmetic changes.
 1.53 14-May-2006  elad integrate kauth.
 1.52 28-Mar-2006  thorpej Use device_unit().
 1.51 11-Dec-2005  christos branches: 1.51.4; 1.51.6; 1.51.8; 1.51.10; 1.51.12;
merge ktrace-lwp.
 1.50 15-Oct-2005  yamt - change the way to specify a bufq strategy. (by string rather than by number)
- rather than embedding bufq_state in driver softc,
have a pointer to the former.
- move bufq related functions from kern/subr_disk.c to kern/subr_bufq.c.
- rename method to strategy for consistency.
- move some definitions which don't need to be exposed to the rest of kernel
from sys/bufq.h to sys/bufq_impl.h.
(is it better to move it to kern/ or somewhere?)
- fix some obvious breakage in dev/qbus/ts.c. (not tested)
 1.49 30-May-2005  christos branches: 1.49.2;
- add missing const
- fix variable shadowing
- remove unneeded casts
 1.48 27-Feb-2005  perry nuke trailing whitespace
 1.47 04-Feb-2005  perry de-__P
 1.46 28-Oct-2004  yamt branches: 1.46.4; 1.46.6;
move buffer queue related stuffs from buf.h to their own header, bufq.h.
 1.45 22-Apr-2004  itojun sprintf -> snprintf
 1.44 03-Nov-2003  ichiro Fix uninitialized variable warnings
 1.43 02-Nov-2003  wiz boundary, not boundry. Inspired by Tom Cosgrove.
 1.42 30-Oct-2003  simonb Remove some assigned-to but otherwise unused variables.
 1.41 19-Oct-2003  simonb Remove some unreachable code with the comment "To shut up compiler"
that neither gcc 2.95.3 or 3.3.1 complains about if that bit of code
is missing...
 1.40 26-Sep-2003  wiz Definition, not defintion. From miod@openbsd.
 1.39 29-Jun-2003  fvdl branches: 1.39.2;
Back out the lwp/ktrace changes. They contained a lot of colateral damage,
and need to be examined and discussed more.
 1.38 28-Jun-2003  darrenr Pass lwp pointers throughtout the kernel, as required, so that the lwpid can
be inserted into ktrace records. The general change has been to replace
"struct proc *" with "struct lwp *" in various function prototypes, pass
the lwp through and use l_proc to get the process pointer when needed.

Bump the kernel rev up to 1.6V
 1.37 31-Jan-2003  thorpej Use aprint_*().
 1.36 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.35 06-Jan-2003  wiz writable, not writeable.
 1.34 23-Oct-2002  jdolecek merge kqueue branch into -current

kqueue provides a stateful and efficient event notification framework
currently supported events include socket, file, directory, fifo,
pipe, tty and device changes, and monitoring of processes and signals

kqueue is supported by all writable filesystems in NetBSD tree
(with exception of Coda) and all device drivers supporting poll(2)

based on work done by Jonathan Lemon for FreeBSD
initial NetBSD port done by Luke Mewburn and Jason Thorpe
 1.33 23-Sep-2002  itojun missing include - sys/conf.h
 1.32 06-Sep-2002  gehenna Merge the gehenna-devsw branch into the trunk.

This merge changes the device switch tables from static array to
dynamically generated by config(8).

- All device switches is defined as a constant structure in device drivers.

- The new grammer ``device-major'' is introduced to ``files''.

device-major <prefix> char <num> [block <num>] [<rules>]

- All device major numbers must be listed up in port dependent majors.<arch>
by using this grammer.

- Added the new naming convention.
The name of the device switch must be <prefix>_[bc]devsw for auto-generation
of device switch tables.

- The backward compatibility of loading block/character device
switch by LKM framework is broken. This is necessary to convert
from block/character device major to device name in runtime and vice versa.

- The restriction to assign device major by LKM is completely removed.
We don't need to reserve LKM entries for dynamic loading of device switch.

- In compile time, device major numbers list is packed into the kernel and
the LKM framework will refer it to assign device major number dynamically.
 1.31 24-Jul-2002  hannken Convert to new device buffer queue interface.
 1.30 14-Feb-2002  chs branches: 1.30.8;
allow writing to write-only mappings. fixes PR 3493.
 1.29 12-Jan-2002  tsutsui Call malloc(9) with M_ZERO flag instead of memset() after malloc().
 1.28 13-Nov-2001  lukem add/cleanup RCSID
 1.27 19-Jul-2001  thorpej branches: 1.27.2;
Use BUS_DMA_READ and BUS_DMA_WRITE in some obvious places.
 1.26 07-Jul-2001  thorpej branches: 1.26.2;
bzero -> memset
 1.25 07-Jul-2001  thorpej bcopy -> memcpy, strcpy
 1.24 19-Jun-2001  wiz `response', not `responce'
 1.23 19-Jun-2001  wiz `accessible' only has one `a'.
 1.22 15-Mar-2001  chs eliminate the KERN_* error codes in favor of the traditional E* codes.
the mapping is:

KERN_SUCCESS 0
KERN_INVALID_ADDRESS EFAULT
KERN_PROTECTION_FAILURE EACCES
KERN_NO_SPACE ENOMEM
KERN_INVALID_ARGUMENT EINVAL
KERN_FAILURE various, mostly turn into KASSERTs
KERN_RESOURCE_SHORTAGE ENOMEM
KERN_NOT_RECEIVER <unused>
KERN_NO_ACCESS <unused>
KERN_PAGES_LOCKED <unused>
 1.21 14-Dec-2000  thorpej branches: 1.21.2;
ALTQ'ify.
 1.20 12-Dec-2000  thorpej Adapt to bpfattach() changes, and further centralize the bpfattach()
and bpfdetach() calls into link-type subroutines where possible.
 1.19 06-Jul-2000  thorpej Use device_lookup().
 1.18 28-Jun-2000  mrg remove include of <vm/vm.h>. <vm/vm.h> -> <uvm/uvm_extern.h>
 1.17 26-Jun-2000  simonb Change the kernel mmap interface so that the offset to map is an
"off_t" and the return value is a "paddr_t" to allow mappings
at offsets past 2^31 bytes. Somewhat inspired by FreeBSD, which
only changed the offset to a "vm_offset_t".

Includes updates for the i386, pc532 and sh3 mmmmap from Jason Thorpe.
 1.16 08-Jun-2000  cgd branches: 1.16.2;
nuke bogus use of s = spl0() / splx(s). reviewed by Jason Thorpe.
 1.15 30-Mar-2000  augustss branches: 1.15.2;
Remove register declarations.
 1.14 21-Jan-2000  thorpej Update for sys/buf.h/disksort_*() changes.
 1.13 20-Jun-1999  thorpej branches: 1.13.2; 1.13.8;
Fix tyop.
 1.12 17-Jun-1999  thorpej Make uvm_vslock() return the error code from uvm_fault_wire(). All places
which use uvm_vslock() should now test the return value. If it's not
KERN_SUCCESS, wiring the pages failed, so the operation which is using
uvm_vslock() should error out.

XXX We currently just EFAULT a failed uvm_vslock(). We may want to do
more about translating error codes in the future.
 1.11 26-May-1999  thorpej Pass the appropriate access type for uvm_vslock() based on the FP operation:
fpread == VM_PROT_READ|VM_PROT_WRITE, fpwrite == VM_PROT_READ.
 1.10 18-May-1999  thorpej Rework layer 2 protocol input routines. Instead of calling e.g. ether_input()
directly, call the function pointer (*if_input)(ifp, m). The input routine
expects the packet header to be at the head of the packet, and will adjust
as necessary. Privatize the layer 2 input and output routines, allowing
*_ifattach() to set them up as appropriate.
 1.9 24-Mar-1999  mrg branches: 1.9.4;
completely remove Mach VM support. all that is left is the all the
header files as UVM still uses (most of) these.
 1.8 08-Jan-1999  augustss Fix more `void *' arithmetic.
 1.7 20-Nov-1998  kml Changes to support a HIPPI Framing Protocol device, which allows raw
HIPPI packets to be written without having to go through the network
stack.
 1.6 07-Jul-1998  thorpej Never, ever, ever, ever include "assym.h" in C source file.
 1.5 05-Jul-1998  jonathan defopt NS, NSIP.
 1.4 05-Jul-1998  jonathan defopt INET, NETATALK.
 1.3 08-Jun-1998  thorpej Make this build w/ EGCS.
 1.2 17-May-1998  kml Correct copyright date.
 1.1 14-May-1998  kml Driver for Essential Communications' RoadRunner HIPPI (800 Mb/sec network)
card. With some modification, this could probably also work for their
Gigabit Ethernet card based on the same chipset...
 1.9.4.2 21-Jun-1999  thorpej Sync w/ -current (again) to get a typo fix.
 1.9.4.1 21-Jun-1999  thorpej Sync w/ -current.
 1.13.8.1 21-Dec-1999  wrstuden Initial commit of recent changes to make DEV_BSIZE go away.

Runs on i386, needs work on other arch's. Main kernel routines should be
fine, but a number of the stand programs need help.

cd, fd, ccd, wd, and sd have been updated. sd has been tested with non-512
byte block devices. vnd, raidframe, and lfs need work.

Non 2**n block support is automatic for LKM's and conditional for kernels
on "options NON_PO2_BLOCKS".
 1.13.2.4 27-Mar-2001  bouyer Sync with HEAD.
 1.13.2.3 05-Jan-2001  bouyer Sync with HEAD
 1.13.2.2 13-Dec-2000  bouyer Sync with HEAD (for UBC fixes).
 1.13.2.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.15.2.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.16.2.1 30-Jun-2000  simonb Pull up mmap paddr_t/off_t changes from trunk.
 1.21.2.13 07-Jan-2003  thorpej Sync with HEAD.
 1.21.2.12 11-Nov-2002  nathanw Catch up to -current
 1.21.2.11 18-Oct-2002  nathanw Catch up to -current.
 1.21.2.10 17-Sep-2002  nathanw Catch up to -current.
 1.21.2.9 01-Aug-2002  nathanw Catch up to -current.
 1.21.2.8 12-Jul-2002  nathanw No longer need to pull in lwp.h; proc.h pulls it in for us.
 1.21.2.7 24-Jun-2002  nathanw Curproc->curlwp renaming.

Change uses of "curproc->l_proc" back to "curproc", which is more like the
original use. Bare uses of "curproc" are now "curlwp".

"curproc" is now #defined in proc.h as ((curlwp) ? (curlwp)->l_proc) : NULL)
so that it is always safe to reference curproc (*de*referencing curproc
is another story, but that's always been true).
 1.21.2.6 28-Feb-2002  nathanw Catch up to -current.
 1.21.2.5 14-Nov-2001  nathanw Catch up to -current.
 1.21.2.4 24-Aug-2001  nathanw Catch up with -current.
 1.21.2.3 21-Jun-2001  nathanw Catch up to -current.
 1.21.2.2 09-Apr-2001  nathanw Catch up with -current.
 1.21.2.1 05-Mar-2001  nathanw Initial commit of scheduler activations and lightweight process support.
 1.26.2.7 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.26.2.6 06-Sep-2002  jdolecek sync kqueue branch with HEAD
 1.26.2.5 16-Mar-2002  jdolecek Catch up with -current.
 1.26.2.4 11-Feb-2002  jdolecek Sync w/ -current.
 1.26.2.3 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.26.2.2 08-Sep-2001  thorpej Add kqueue support (does nothing just like the poll entry point).
 1.26.2.1 03-Aug-2001  lukem update to -current
 1.27.2.2 26-Sep-2001  fvdl * add a VCLONED vnode flag that indicates a vnode representing a cloned
device.
* rename REVOKEALL to REVOKEALIAS, and add a REVOKECLONE flag, to pass
to VOP_REVOKE
* the revoke system call will revoke all aliases, as before, but not the
clones
* vdevgone is called when detaching a device, so make it use REVOKECLONE
to get rid of all clones as well
* clean up all uses of VOP_OPEN wrt. locking.
* add a few VOPS to spec_vnops that need to do something when it's a
clone vnode (access and getattr)
* add a copy of the vnode vattr structure of the original 'master' vnode
to the specinfo of a cloned vnode. could possibly redirect getattr to
the 'master' vnode, but this has issues with revoke
* add a vdev_reassignvp function that disassociates a vnode from its
original device, and reassociates it with the specified dev_t. to be
used by cloning devices only, in case a new minor is allocated.
* change all direct references in drivers to v_devcookie and v_rdev
to vdev_privdata(vp) and vdev_rdev(vp). for diagnostic purposes
when debugging race conditions that still exist wrt. locking and
revoking vnodes.
* make the locking state of a vnode consistent when passed to
d_open and d_close (unlocked). locked would be better, but has
some deadlock issues
 1.27.2.1 07-Sep-2001  thorpej Commit my "devvp" changes to the thorpej-devvp branch. This
replaces the use of dev_t in most places with a struct vnode *.

This will form the basic infrastructure for real cloning device
support (besides being architecurally cleaner -- it'll be good
to get away from using numbers to represent objects).
 1.30.8.2 29-Aug-2002  gehenna catch up with -current.
 1.30.8.1 16-May-2002  gehenna Add the character device switch.
Fix prototype.
 1.39.2.8 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.39.2.7 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.39.2.6 04-Feb-2005  skrll Sync with HEAD.
 1.39.2.5 02-Nov-2004  skrll Sync with HEAD.
 1.39.2.4 21-Sep-2004  skrll Fix the sync with head I botched.
 1.39.2.3 18-Sep-2004  skrll Sync with HEAD.
 1.39.2.2 03-Aug-2004  skrll Sync with HEAD
 1.39.2.1 02-Jul-2003  darrenr Apply the aborted ktrace-lwp changes to a specific branch. This is just for
others to review, I'm concerned that patch fuziness may have resulted in some
errant code being generated but I'll look at that later by comparing the diff
from the base to the branch with the file I attempt to apply to it. This will,
at the very least, put the changes in a better context for others to review
them and attempt to tinker with removing passing of 'struct lwp' through
the kernel.
 1.46.6.2 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.46.6.1 12-Feb-2005  yamt sync with head.
 1.46.4.1 29-Apr-2005  kent sync with -current
 1.49.2.5 27-Oct-2007  yamt sync with head.
 1.49.2.4 03-Sep-2007  yamt sync with head.
 1.49.2.3 26-Feb-2007  yamt sync with head.
 1.49.2.2 30-Dec-2006  yamt sync with head.
 1.49.2.1 21-Jun-2006  yamt sync with head.
 1.51.12.2 24-May-2006  tron Merge 2006-05-24 NetBSD-current into the "peter-altq" branch.
 1.51.12.1 31-Mar-2006  tron Merge 2006-03-31 NetBSD-current into the "peter-altq" branch.
 1.51.10.3 19-Apr-2006  elad sync with head.
 1.51.10.2 10-Mar-2006  elad generic_authorize() -> kauth_authorize_generic().
 1.51.10.1 08-Mar-2006  elad Adapt to kernel authorization KPI.
 1.51.8.5 14-Sep-2006  yamt sync with head.
 1.51.8.4 03-Sep-2006  yamt sync with head.
 1.51.8.3 11-Aug-2006  yamt sync with head
 1.51.8.2 24-May-2006  yamt sync with head.
 1.51.8.1 01-Apr-2006  yamt sync with head.
 1.51.6.2 01-Jun-2006  kardel Sync with head.
 1.51.6.1 22-Apr-2006  simonb Sync with head.
 1.51.4.1 09-Sep-2006  rpaulo sync with head
 1.56.4.2 10-Dec-2006  yamt sync with head.
 1.56.4.1 22-Oct-2006  yamt sync with head
 1.56.2.2 12-Jan-2007  ad Sync with head.
 1.56.2.1 18-Nov-2006  ad Sync with head.
 1.60.2.1 12-Mar-2007  rmind Sync with HEAD.
 1.61.4.1 11-Jul-2007  mjf Sync with head.
 1.61.2.4 23-Oct-2007  ad Sync with head.
 1.61.2.3 19-Aug-2007  ad - Back out the biodone() changes.
- Eliminate B_ERROR (from HEAD).
 1.61.2.2 09-Jun-2007  ad Sync with head.
 1.61.2.1 05-Apr-2007  ad Compile fixes.
 1.62.2.1 15-Aug-2007  skrll Sync with HEAD.
 1.63.12.2 29-Jul-2007  ad It's not a good idea for device drivers to modify b_flags, as they don't
need to understand the locking around that field. Instead of setting
B_ERROR, set b_error instead. b_error is 'owned' by whoever completes
the I/O request.
 1.63.12.1 29-Jul-2007  ad file rrunner.c was added on branch matt-mips64 on 2007-07-29 12:50:21 +0000
 1.63.10.1 25-Oct-2007  bouyer Sync with HEAD.
 1.63.6.1 06-Nov-2007  matt sync with HEAD
 1.63.4.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.64.16.3 17-Jan-2009  mjf Sync with HEAD.
 1.64.16.2 29-Jun-2008  mjf Sync with HEAD.
 1.64.16.1 02-Jun-2008  mjf Sync with HEAD.
 1.65.4.4 11-Aug-2010  yamt sync with head.
 1.65.4.3 11-Mar-2010  yamt sync with head
 1.65.4.2 04-May-2009  yamt sync with head.
 1.65.4.1 16-May-2008  yamt sync with head.
 1.65.2.2 17-Jun-2008  yamt sync with head.
 1.65.2.1 18-May-2008  yamt sync with head.
 1.66.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.67.6.2 28-Apr-2009  skrll Sync with HEAD.
 1.67.6.1 19-Jan-2009  skrll Sync with HEAD.
 1.67.4.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.69.2.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.73.4.1 30-May-2010  rmind sync with head
 1.73.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.74.18.3 03-Dec-2017  jdolecek update from HEAD
 1.74.18.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.74.18.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.74.8.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.74.8.1 30-Oct-2012  yamt sync with head
 1.75.2.1 18-May-2014  rmind sync with head
 1.77.2.1 10-Aug-2014  tls Rebase.
 1.78.4.6 28-Aug-2017  skrll Sync with HEAD
 1.78.4.5 05-Feb-2017  skrll Sync with HEAD
 1.78.4.4 05-Oct-2016  skrll Sync with HEAD
 1.78.4.3 09-Jul-2016  skrll Sync with HEAD
 1.78.4.2 19-Mar-2016  skrll Sync with HEAD
 1.78.4.1 22-Sep-2015  skrll Sync with HEAD
 1.81.2.2 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.81.2.1 04-Nov-2016  pgoyette Sync with HEAD
 1.83.8.1 26-Jul-2018  snj Pull up following revision(s) (requested by msaitoh in ticket #938):
sys/arch/acorn32/podulebus/if_ie.c: revision 1.41
sys/arch/amiga/dev/if_es.c: revision 1.58
sys/arch/amiga/dev/if_qn.c: revision 1.45
sys/arch/arm/at91/at91emac.c: revision 1.20
sys/arch/arm/ep93xx/epe.c: revision 1.37
sys/arch/emips/ebus/if_le_ebus.c: revision 1.14
sys/arch/emips/ebus/if_le_ebus.c: revision 1.15
sys/arch/mac68k/dev/if_mc.c: revision 1.46
sys/arch/macppc/dev/am79c950.c: revision 1.39
sys/arch/newsmips/apbus/if_sn.c: revision 1.40
sys/arch/next68k/dev/mb8795.c: revision 1.59
sys/arch/playstation2/dev/if_smap.c: revision 1.25
sys/arch/playstation2/dev/if_smap.c: revision 1.26
sys/arch/sun2/dev/if_ec.c: revision 1.28
sys/arch/sun3/dev/if_ie.c: revision 1.63
sys/arch/x68k/dev/if_ne_intio.c: revision 1.19
sys/arch/xen/xen/if_xennet_xenbus.c: revision 1.75
sys/arch/xen/xen/xennetback_xenbus.c: revision 1.63
sys/dev/bi/if_ni.c: revision 1.45
sys/dev/cadence/if_cemac.c: revision 1.12
sys/dev/ic/am7990.c: revision 1.78
sys/dev/ic/am79900.c: revision 1.27
sys/dev/ic/an.c: revision 1.67
sys/dev/ic/cs89x0.c: revision 1.40
sys/dev/ic/dm9000.c: revision 1.13
sys/dev/ic/dm9000.c: revision 1.14
sys/dev/ic/dp8390.c: revision 1.88
sys/dev/ic/elink3.c: revision 1.141
sys/dev/ic/elinkxl.c: revision 1.122
sys/dev/ic/hme.c: revision 1.98
sys/dev/ic/i82586.c: revision 1.77
sys/dev/ic/lance.c: revision 1.53
sys/dev/ic/mb86950.c: revision 1.27
sys/dev/ic/mb86960.c: revision 1.86
sys/dev/ic/mtd803.c: revision 1.34
sys/dev/ic/pdq_ifsubr.c: revision 1.59
sys/dev/ic/rrunner.c: revision 1.86
sys/dev/ic/seeq8005.c: revision 1.58
sys/dev/ic/sgec.c: revision 1.47
sys/dev/ic/smc90cx6.c: revision 1.72
sys/dev/ic/smc91cxx.c: revision 1.96
sys/dev/ic/tropic.c: revision 1.49
sys/dev/ic/wi.c: revision 1.245
sys/dev/isa/if_eg.c: revision 1.93
sys/dev/isa/if_el.c: revision 1.95
sys/dev/isa/if_iy.c: revision 1.101
sys/dev/ofw/ofnet.c: revision 1.58
sys/dev/pci/if_alc.c: revision 1.27
sys/dev/pci/if_de.c: revision 1.152
sys/dev/pci/if_fpa.c: revision 1.61
sys/dev/pci/if_jme.c: revision 1.34
sys/dev/pci/if_tl.c: revision 1.108
sys/dev/pci/if_vte.c: revision 1.19
sys/dev/pci/ixgbe/ixgbe.h: revision 1.50
sys/dev/pcmcia/if_cnw.c: revision 1.62
sys/dev/pcmcia/if_malo_pcmcia.c: revision 1.17
sys/dev/pcmcia/if_ray.c: revision 1.89
sys/dev/pcmcia/if_xi.c: revision 1.81
sys/dev/pcmcia/mhzc.c: revision 1.51
sys/dev/pcmcia/xirc.c: revision 1.34
sys/dev/qbus/if_de.c: revision 1.33
sys/dev/qbus/if_qe.c: revision 1.78
sys/dev/qbus/if_qt.c: revision 1.22
sys/dev/sbus/be.c: revision 1.87
sys/dev/sbus/qe.c: revision 1.68
sys/dev/scsipi/if_se.c: revision 1.96
sys/dev/usb/if_atu.c: revision 1.59
sys/net/if_l2tp.c: revision 1.28 via patch
sys/net/if_ppp.c: revision 1.160
It's not required to include net/bpfdesc.h. Remove it.
--
Simplify like other drivers. NULL check of ifp->if_bpf is done in
bpf_mtap(), so it's not required to do it here.
--
Remove duplicated inclusion of net/bpf.h.
--
Remove duplicated inclusion of net/bpf.h.
--
Simplify bpf_mtap() call. No functional change.
 1.85.2.3 06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.85.2.2 28-Jul-2018  pgoyette Sync with HEAD
 1.85.2.1 25-Jun-2018  pgoyette Sync with HEAD
 1.87.2.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.87.2.1 10-Jun-2019  christos Sync with HEAD
 1.89.6.1 25-Jan-2020  ad Sync with head.
 1.11 19-Jan-2020  thorpej Remove HIPPI support and the esh(4) driver that uses it. There have not
been any users of HIPPI for some time, and it is unlikely to be resurrected.
 1.10 03-Sep-2018  riastradh branches: 1.10.6;
Rename min/max -> uimin/uimax for better honesty.

These functions are defined on unsigned int. The generic name
min/max should not silently truncate to 32 bits on 64-bit systems.
This is purely a name change -- no functional change intended.

HOWEVER! Some subsystems have

#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))

even though our standard name for that is MIN/MAX. Although these
may invite multiple evaluation bugs, these do _not_ cause integer
truncation.

To avoid `fixing' these cases, I first changed the name in libkern,
and then compile-tested every file where min/max occurred in order to
confirm that it failed -- and thus confirm that nothing shadowed
min/max -- before changing it.

I have left a handful of bootloaders that are too annoying to
compile-test, and some dead code:

cobalt ews4800mips hp300 hppa ia64 luna68k vax
acorn32/if_ie.c (not included in any kernels)
macppc/if_gm.c (superseded by gem(4))

It should be easy to fix the fallout once identified -- this way of
doing things fails safe, and the goal here, after all, is to _avoid_
silent integer truncations, not introduce them.

Maybe one day we can reintroduce min/max as type-generic things that
never silently truncate. But we should avoid doing that for a while,
so that existing code has a chance to be detected by the compiler for
conversion to uimin/uimax without changing the semantics until we can
properly audit it all. (Who knows, maybe in some cases integer
truncation is actually intended!)
 1.9 28-Apr-2008  martin branches: 1.9.86; 1.9.88;
Remove clause 3 and 4 from TNF licenses
 1.8 25-Feb-2006  wiz branches: 1.8.64; 1.8.66; 1.8.68;
Fix some typos.
 1.7 11-Dec-2005  christos branches: 1.7.2; 1.7.4; 1.7.6;
merge ktrace-lwp.
 1.6 27-Feb-2005  perry branches: 1.6.4;
nuke trailing whitespace
 1.5 02-Nov-2003  wiz branches: 1.5.8; 1.5.10;
Fix some typos. From Tom Cosgrove via jmc@openbsd.
 1.4 02-Nov-2003  wiz boundary, not boundry. Inspired by Tom Cosgrove.
 1.3 20-Nov-1998  kml branches: 1.3.44;
Changes to support a HIPPI Framing Protocol device, which allows raw
HIPPI packets to be written without having to go through the network
stack.
 1.2 17-May-1998  kml Correct copyright date.
 1.1 14-May-1998  kml Driver for Essential Communications' RoadRunner HIPPI (800 Mb/sec network)
card. With some modification, this could probably also work for their
Gigabit Ethernet card based on the same chipset...
 1.3.44.4 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.3.44.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.3.44.2 18-Sep-2004  skrll Sync with HEAD.
 1.3.44.1 03-Aug-2004  skrll Sync with HEAD
 1.5.10.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.5.8.1 29-Apr-2005  kent sync with -current
 1.6.4.1 21-Jun-2006  yamt sync with head.
 1.7.6.1 22-Apr-2006  simonb Sync with head.
 1.7.4.1 09-Sep-2006  rpaulo sync with head
 1.7.2.1 01-Mar-2006  yamt sync with head.
 1.8.68.1 16-May-2008  yamt sync with head.
 1.8.66.1 18-May-2008  yamt sync with head.
 1.8.64.1 02-Jun-2008  mjf Sync with HEAD.
 1.9.88.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.9.88.1 10-Jun-2019  christos Sync with HEAD
 1.9.86.1 06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.10.6.1 25-Jan-2020  ad Sync with head.
 1.15 19-Jan-2020  thorpej Remove HIPPI support and the esh(4) driver that uses it. There have not
been any users of HIPPI for some time, and it is unlikely to be resurrected.
 1.14 27-Oct-2012  chs branches: 1.14.38; 1.14.46;
split device_t/softc for all remaining drivers.
replace "struct device *" with "device_t".
use device_xname(), device_unit(), etc.
 1.13 28-Apr-2008  martin branches: 1.13.34; 1.13.44;
Remove clause 3 and 4 from TNF licenses
 1.12 04-Mar-2007  christos branches: 1.12.36; 1.12.38; 1.12.40;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.11 11-Dec-2005  christos branches: 1.11.26;
merge ktrace-lwp.
 1.10 15-Oct-2005  yamt - change the way to specify a bufq strategy. (by string rather than by number)
- rather than embedding bufq_state in driver softc,
have a pointer to the former.
- move bufq related functions from kern/subr_disk.c to kern/subr_bufq.c.
- rename method to strategy for consistency.
- move some definitions which don't need to be exposed to the rest of kernel
from sys/bufq.h to sys/bufq_impl.h.
(is it better to move it to kern/ or somewhere?)
- fix some obvious breakage in dev/qbus/ts.c. (not tested)
 1.9 27-Feb-2005  perry branches: 1.9.4;
nuke trailing whitespace
 1.8 04-Feb-2005  perry de-__P
 1.7 24-Jul-2002  hannken branches: 1.7.6; 1.7.14; 1.7.16;
Convert to new device buffer queue interface.
 1.6 21-Jan-2000  thorpej branches: 1.6.6; 1.6.8; 1.6.20;
Update for sys/buf.h/disksort_*() changes.
 1.5 20-Nov-1998  kml branches: 1.5.10;
Changes to support a HIPPI Framing Protocol device, which allows raw
HIPPI packets to be written without having to go through the network
stack.
 1.4 08-Jun-1998  thorpej Make this build w/ EGCS.
 1.3 08-Jun-1998  thorpej No need for an explicitly-sized type for sc_flags.
 1.2 17-May-1998  kml Correct copyright date.
 1.1 14-May-1998  kml Driver for Essential Communications' RoadRunner HIPPI (800 Mb/sec network)
card. With some modification, this could probably also work for their
Gigabit Ethernet card based on the same chipset...
 1.5.10.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.6.20.1 29-Aug-2002  gehenna catch up with -current.
 1.6.8.1 06-Sep-2002  jdolecek sync kqueue branch with HEAD
 1.6.6.1 01-Aug-2002  nathanw Catch up to -current.
 1.7.16.2 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.7.16.1 12-Feb-2005  yamt sync with head.
 1.7.14.1 29-Apr-2005  kent sync with -current
 1.7.6.3 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.7.6.2 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.7.6.1 04-Feb-2005  skrll Sync with HEAD.
 1.9.4.2 03-Sep-2007  yamt sync with head.
 1.9.4.1 21-Jun-2006  yamt sync with head.
 1.11.26.1 12-Mar-2007  rmind Sync with HEAD.
 1.12.40.1 16-May-2008  yamt sync with head.
 1.12.38.1 18-May-2008  yamt sync with head.
 1.12.36.1 02-Jun-2008  mjf Sync with HEAD.
 1.13.44.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.13.34.1 30-Oct-2012  yamt sync with head
 1.14.46.1 25-Jan-2020  ad Sync with head.
 1.14.38.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.11 07-Sep-2025  thorpej Change todr_chip_handle::cookie -> todr_chip_handle::todr_dev, and
make it a device_t. Upcoming functional changes will require the
device_t associated with a TODR device.

Change todr_chip_handle::bus_cookie -> todr_chip_handle::todr_devaux.
Nothing was using the old field, but I decided to keep it around just
in cause something needs it in the future.

And with these largely mechanical yet semantically meaningful changes,
thus spake the Oracle: "Welcome to NetBSD 11.99.2."
 1.10 20-Nov-2014  christos use the inline bcdtobin and bintobcd directly instead through a macro.
 1.9 06-Apr-2010  nonaka branches: 1.9.18;
Added support RICOH 5C316.
 1.8 04-May-2008  martin branches: 1.8.20; 1.8.22;
Move TNF licenses to 2 clause form
 1.7 27-Mar-2008  uwe branches: 1.7.2; 1.7.4;
Split device_t and softc.
 1.6 09-Jan-2008  uwe branches: 1.6.6;
Don't bury &sc->sc_dev idiom inside arglist of aprint_error_dev(), use
explicit device_t self variable instead to make future conversion easier.
 1.5 09-Jan-2008  uwe Autoconf allocates softc with M_ZERO, so there's no need to explicitly
init missing todr methods to NULL.
 1.4 09-Jan-2008  uwe Use todr_{get,set}time_ymdhms methods and let MI code in kern_todr.c
do conversion and checks.
 1.3 09-Jan-2008  uwe rtc_offset is handled by kern_todr.c, so nuke it here.
Pointed out by joerg@
 1.2 06-Nov-2007  uwe branches: 1.2.6;
Use aprint_*
 1.1 07-Sep-2006  uwe branches: 1.1.4; 1.1.6; 1.1.12; 1.1.32; 1.1.34; 1.1.38; 1.1.40;
MI part of the Ricoh RS5C313 real time clock todr(9) driver.
Based on the code from landisk port. With help from gdamore@
 1.1.40.2 18-Feb-2008  mjf Sync with HEAD.
 1.1.40.1 19-Nov-2007  mjf Sync with HEAD.
 1.1.38.1 13-Nov-2007  bouyer Sync with HEAD
 1.1.34.2 23-Mar-2008  matt sync with HEAD
 1.1.34.1 06-Nov-2007  matt sync with HEAD
 1.1.32.1 06-Nov-2007  joerg Sync with HEAD.
 1.1.12.4 21-Jan-2008  yamt sync with head
 1.1.12.3 15-Nov-2007  yamt sync with head.
 1.1.12.2 30-Dec-2006  yamt sync with head.
 1.1.12.1 07-Sep-2006  yamt file rs5c313.c was added on branch yamt-lazymbuf on 2006-12-30 20:48:03 +0000
 1.1.6.2 14-Sep-2006  yamt sync with head.
 1.1.6.1 07-Sep-2006  yamt file rs5c313.c was added on branch yamt-pdpolicy on 2006-09-14 12:31:30 +0000
 1.1.4.2 09-Sep-2006  rpaulo sync with head
 1.1.4.1 07-Sep-2006  rpaulo file rs5c313.c was added on branch rpaulo-netinet-merge-pcb on 2006-09-09 02:50:03 +0000
 1.2.6.1 10-Jan-2008  bouyer Sync with HEAD
 1.6.6.2 02-Jun-2008  mjf Sync with HEAD.
 1.6.6.1 03-Apr-2008  mjf Sync with HEAD.
 1.7.4.2 11-Aug-2010  yamt sync with head.
 1.7.4.1 16-May-2008  yamt sync with head.
 1.7.2.1 18-May-2008  yamt sync with head.
 1.8.22.1 30-May-2010  rmind sync with head
 1.8.20.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.9.18.1 03-Dec-2017  jdolecek update from HEAD
 1.3 06-Apr-2010  nonaka Added support RICOH 5C316.
 1.2 04-May-2008  martin branches: 1.2.20; 1.2.22;
Move TNF licenses to 2 clause form
 1.1 07-Sep-2006  uwe branches: 1.1.4; 1.1.6; 1.1.12; 1.1.58; 1.1.60; 1.1.62;
MI part of the Ricoh RS5C313 real time clock todr(9) driver.
Based on the code from landisk port. With help from gdamore@
 1.1.62.2 11-Aug-2010  yamt sync with head.
 1.1.62.1 16-May-2008  yamt sync with head.
 1.1.60.1 18-May-2008  yamt sync with head.
 1.1.58.1 02-Jun-2008  mjf Sync with HEAD.
 1.1.12.2 30-Dec-2006  yamt sync with head.
 1.1.12.1 07-Sep-2006  yamt file rs5c313reg.h was added on branch yamt-lazymbuf on 2006-12-30 20:48:03 +0000
 1.1.6.2 14-Sep-2006  yamt sync with head.
 1.1.6.1 07-Sep-2006  yamt file rs5c313reg.h was added on branch yamt-pdpolicy on 2006-09-14 12:31:30 +0000
 1.1.4.2 09-Sep-2006  rpaulo sync with head
 1.1.4.1 07-Sep-2006  rpaulo file rs5c313reg.h was added on branch rpaulo-netinet-merge-pcb on 2006-09-09 02:50:03 +0000
 1.2.22.1 30-May-2010  rmind sync with head
 1.2.20.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.3 06-Apr-2010  nonaka Added support RICOH 5C316.
 1.2 27-Mar-2008  uwe branches: 1.2.4; 1.2.24; 1.2.26;
Split device_t and softc.
 1.1 07-Sep-2006  uwe branches: 1.1.4; 1.1.6; 1.1.12; 1.1.58;
MI part of the Ricoh RS5C313 real time clock todr(9) driver.
Based on the code from landisk port. With help from gdamore@
 1.1.58.1 03-Apr-2008  mjf Sync with HEAD.
 1.1.12.2 30-Dec-2006  yamt sync with head.
 1.1.12.1 07-Sep-2006  yamt file rs5c313var.h was added on branch yamt-lazymbuf on 2006-12-30 20:48:03 +0000
 1.1.6.2 14-Sep-2006  yamt sync with head.
 1.1.6.1 07-Sep-2006  yamt file rs5c313var.h was added on branch yamt-pdpolicy on 2006-09-14 12:31:30 +0000
 1.1.4.2 09-Sep-2006  rpaulo sync with head
 1.1.4.1 07-Sep-2006  rpaulo file rs5c313var.h was added on branch rpaulo-netinet-merge-pcb on 2006-09-09 02:50:03 +0000
 1.2.26.1 30-May-2010  rmind sync with head
 1.2.24.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.2.4.1 11-Aug-2010  yamt sync with head.
 1.41 15-Jul-2025  andvar Fix various typos in comments.
 1.40 05-Dec-2021  msaitoh branches: 1.40.10;
s/decriptor/descriptor/ in comment.
 1.39 16-Jun-2021  riastradh if_attach and if_initialize cannot fail, don't test return value

These were originally made failable back in 2017 when if_initialize
allocated a softint in every interface for link state changes, so
that it could fail gracefully instead of panicking:

https://mail-index.NetBSD.org/source-changes/2017/10/23/msg089053.html

However, this spawned many seldom- or never-tested error branches,
which are risky to have around. And that softint in every interface
has since been replaced by a single global workqueue, because link
state changes require thread context but not low latency or high
throughput:

https://mail-index.NetBSD.org/source-changes/2020/02/06/msg113759.html

So there is no longer any reason for if_initialize to fail. (The
subroutine if_stats_init can't fail because percpu_alloc can't fail
either.)

There is a snag: the softint_establish in if_percpuq_create could
fail, potentially leading to bad consequences later on trying to use
the softint. This change doesn't introduce any new bugs because of
the snag -- if_percpuq_attach was already broken. However, the snag
can be better addressed without spawning error branches, either by
using a single softint or making softints less scarce.

(Separate commit will change the signatures of if_attach and
if_initialize to return void, scheduled to ride whatever is the next
convenient kernel bump.)

Patch and testing on amd64 and evbmips64-eb by maya@; commit message
soliloquy, and compile-testing on evbppc/i386/earmv7hf, by me.
 1.38 29-Jan-2020  thorpej branches: 1.38.10;
Adopt <net/if_stats.h>.
 1.37 10-Nov-2019  chs branches: 1.37.2;
in many device attach paths, allocate memory with M_WAITOK instead of M_NOWAIT
and remove code to handle failures that can no longer happen.
 1.36 22-Dec-2018  maxv Replace: M_COPY_PKTHDR -> m_copy_pkthdr. No functional change, since the
former is a macro to the latter.
 1.35 03-Sep-2018  riastradh Rename min/max -> uimin/uimax for better honesty.

These functions are defined on unsigned int. The generic name
min/max should not silently truncate to 32 bits on 64-bit systems.
This is purely a name change -- no functional change intended.

HOWEVER! Some subsystems have

#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))

even though our standard name for that is MIN/MAX. Although these
may invite multiple evaluation bugs, these do _not_ cause integer
truncation.

To avoid `fixing' these cases, I first changed the name in libkern,
and then compile-tested every file where min/max occurred in order to
confirm that it failed -- and thus confirm that nothing shadowed
min/max -- before changing it.

I have left a handful of bootloaders that are too annoying to
compile-test, and some dead code:

cobalt ews4800mips hp300 hppa ia64 luna68k vax
acorn32/if_ie.c (not included in any kernels)
macppc/if_gm.c (superseded by gem(4))

It should be easy to fix the fallout once identified -- this way of
doing things fails safe, and the goal here, after all, is to _avoid_
silent integer truncations, not introduce them.

Maybe one day we can reintroduce min/max as type-generic things that
never silently truncate. But we should avoid doing that for a while,
so that existing code has a chance to be detected by the compiler for
conversion to uimin/uimax without changing the semantics until we can
properly audit it all. (Who knows, maybe in some cases integer
truncation is actually intended!)
 1.34 26-Jun-2018  msaitoh branches: 1.34.2;
Implement the BPF direction filter (BIOC[GS]DIRECTION). It provides backward
compatibility with BIOC[GS]SEESENT ioctl. The userland interface is the same
as FreeBSD.

This change also fixes a bug that the direction is misunderstand on some
environment by passing the direction to bpf_mtap*() instead of checking
m->m_pkthdr.rcvif.
 1.33 01-May-2018  maya GC private 802.11 rateset declarations, use the standard ones.

Build tested only.
 1.32 08-Feb-2018  dholland branches: 1.32.2;
Typos.
 1.31 23-Oct-2017  msaitoh If if_initialize() failed in the attach function, free resources and return.
 1.30 23-May-2017  ozaki-r branches: 1.30.2;
Apply deferred if_start to more drivers

And annotate some XXX_start as it runs in softint to clarify that
it doesn't need deferred if_start.
 1.29 02-Feb-2017  nonaka wlan interfaces make interrupt routine running on softint context.

see http://mail-index.netbsd.org/tech-kern/2016/12/06/msg021281.html

tested device:
* ath at pci: AR5212, AR5424
* athn at pci: AR9287
* ipw at pci: 2100BG
* iwi at pci: 2915ABG
* iwm at pci: 3165, 7260, 8260
* iwn at pci: 4945, 6235
* ral at pci: RT2560
* rtwn at pci: RTL8192CE
 1.28 10-Jun-2016  ozaki-r branches: 1.28.2; 1.28.4;
Introduce m_set_rcvif and m_reset_rcvif

The API is used to set (or reset) a received interface of a mbuf.
They are counterpart of m_get_rcvif, which will come in another
commit, hide internal of rcvif operation, and reduce the diff of
the upcoming change.

No functional change.
 1.27 26-May-2016  ozaki-r Introduce M_CLEARCTX and use it instead of open-coding rcvif

No functional change.
 1.26 26-May-2016  ozaki-r Use M_GETCTX

No functional change.
 1.25 18-Feb-2012  drochner branches: 1.25.2; 1.25.16;
split device_t/softc
 1.24 13-Jun-2010  tsutsui branches: 1.24.8; 1.24.12;
No need to include PCI header files in bus independent code.
 1.23 05-Apr-2010  joerg Push the bpf_ops usage back into bpf.h. Push the common ifp->if_bpf
check into the inline functions as well the fourth argument for
bpf_attach.
 1.22 19-Jan-2010  pooka branches: 1.22.2; 1.22.4;
Redefine bpf linkage through an always present op vector, i.e.
#if NBPFILTER is no longer required in the client. This change
doesn't yet add support for loading bpf as a module, since drivers
can register before bpf is attached. However, callers of bpf can
now be modularized.

Dynamically loadable bpf could probably be done fairly easily with
coordination from the stub driver and the real driver by registering
attachments in the stub before the real driver is loaded and doing
a handoff. ... and I'm not going to ponder the depths of unload
here.

Tested with i386/MONOLITHIC, modified MONOLITHIC without bpf and rump.
 1.21 05-Sep-2009  tsutsui Invert logic around nested pmf(9) registrations for readability.
 1.20 07-Nov-2008  dyoung *** Summary ***

When a link-layer address changes (e.g., ifconfig ex0 link
02:de:ad:be:ef:02 active), send a gratuitous ARP and/or a Neighbor
Advertisement to update the network-/link-layer address bindings
on our LAN peers.

Refuse a change of ethernet address to the address 00:00:00:00:00:00
or to any multicast/broadcast address. (Thanks matt@.)

Reorder ifnet ioctl operations so that driver ioctls may inherit
the functions of their "class"---ether_ioctl(), fddi_ioctl(), et
cetera---and the class ioctls may inherit from the generic ioctl,
ifioctl_common(), but both driver- and class-ioctls may override
the generic behavior. Make network drivers share more code.

Distinguish a "factory" link-layer address from others for the
purposes of both protecting that address from deletion and computing
EUI64.

Return consistent, appropriate error codes from network drivers.

Improve readability. KNF.

*** Details ***

In if_attach(), always initialize the interface ioctl routine,
ifnet->if_ioctl, if the driver has not already initialized it.
Delete if_ioctl == NULL tests everywhere else, because it cannot
happen.

In the ioctl routines of network interfaces, inherit common ioctl
behaviors by calling either ifioctl_common() or whichever ioctl
routine is appropriate for the class of interface---e.g., ether_ioctl()
for ethernets.

Stop (ab)using SIOCSIFADDR and start to use SIOCINITIFADDR. In
the user->kernel interface, SIOCSIFADDR's argument was an ifreq,
but on the protocol->ifnet interface, SIOCSIFADDR's argument was
an ifaddr. That was confusing, and it would work against me as I
make it possible for a network interface to overload most ioctls.
On the protocol->ifnet interface, replace SIOCSIFADDR with
SIOCINITIFADDR. In ifioctl(), return EPERM if userland tries to
invoke SIOCINITIFADDR.

In ifioctl(), give the interface the first shot at handling most
interface ioctls, and give the protocol the second shot, instead
of the other way around. Finally, let compatibility code (COMPAT_OSOCK)
take a shot.

Pull device initialization out of switch statements under
SIOCINITIFADDR. For example, pull ..._init() out of any switch
statement that looks like this:

switch (...->sa_family) {
case ...:
..._init();
...
break;
...
default:
..._init();
...
break;
}

Rewrite many if-else clauses that handle all permutations of IFF_UP
and IFF_RUNNING to use a switch statement,

switch (x & (IFF_UP|IFF_RUNNING)) {
case 0:
...
break;
case IFF_RUNNING:
...
break;
case IFF_UP:
...
break;
case IFF_UP|IFF_RUNNING:
...
break;
}

unifdef lots of code containing #ifdef FreeBSD, #ifdef NetBSD, and
#ifdef SIOCSIFMTU, especially in fwip(4) and in ndis(4).

In ipw(4), remove an if_set_sadl() call that is out of place.

In nfe(4), reuse the jumbo MTU logic in ether_ioctl().

Let ethernets register a callback for setting h/w state such as
promiscuous mode and the multicast filter in accord with a change
in the if_flags: ether_set_ifflags_cb() registers a callback that
returns ENETRESET if the caller should reset the ethernet by calling
if_init(), 0 on success, != 0 on failure. Pull common code from
ex(4), gem(4), nfe(4), sip(4), tlp(4), vge(4) into ether_ioctl(),
and register if_flags callbacks for those drivers.

Return ENOTTY instead of EINVAL for inappropriate ioctls. In
zyd(4), use ENXIO instead of ENOTTY to indicate that the device is
not any longer attached.

Add to if_set_sadl() a boolean 'factory' argument that indicates
whether a link-layer address was assigned by the factory or some
other source. In a comment, recommend using the factory address
for generating an EUI64, and update in6_get_hw_ifid() to prefer a
factory address to any other link-layer address.

Add a routing message, RTM_LLINFO_UPD, that tells protocols to
update the binding of network-layer addresses to link-layer addresses.
Implement this message in IPv4 and IPv6 by sending a gratuitous
ARP or a neighbor advertisement, respectively. Generate RTM_LLINFO_UPD
messages on a change of an interface's link-layer address.

In ether_ioctl(), do not let SIOCALIFADDR set a link-layer address
that is broadcast/multicast or equal to 00:00:00:00:00:00.

Make ether_ioctl() call ifioctl_common() to handle ioctls that it
does not understand.

In gif(4), initialize if_softc and use it, instead of assuming that
the gif_softc and ifp overlap.

Let ifioctl_common() handle SIOCGIFADDR.

Sprinkle rtcache_invariants(), which checks on DIAGNOSTIC kernels
that certain invariants on a struct route are satisfied.

In agr(4), rewrite agr_ioctl_filter() to be a bit more explicit
about the ioctls that we do not allow on an agr(4) member interface.

bzero -> memset. Delete unnecessary casts to void *. Use
sockaddr_in_init() and sockaddr_in6_init(). Compare pointers with
NULL instead of "testing truth". Replace some instances of (type
*)0 with NULL. Change some K&R prototypes to ANSI C, and join
lines.
 1.19 08-Apr-2008  cegger branches: 1.19.4; 1.19.10; 1.19.12;
use aprint_*_dev and device_xname
 1.18 17-Mar-2008  xtraeme Merge some changes from OpenBSD:

RT2560+RT2661: update the physical address in the RX descriptor after
bus_dmamap_load() in the case where the same mbuf is reloaded.

modify interrupt handlers to exit early and return 0 on shared interrupts.

RT2661:
flags for register TXRX_CSR4 were shifted one bit too much on the left.
this has probably affected short preamble support as well as hardware
multi-rate retries settings.

fix handling of the SIOCS80211CHANNEL ioctl in monitor mode:
don't call xxx_set_chan() if the interface is not up&running.

Tested with the following hw:

ral0 at pci5 dev 0 function 0: Ralink Technologies RT2561 802.11b/g (rev. 0x00)
ral0: interrupting at ioapic0 pin 20 (irq 10)
ral0: 802.11 address 00:80:5a:4f:ab:e2
ral0: MAC/BBP RT2561C, RF RT2527
 1.17 09-Jan-2008  degroote branches: 1.17.2; 1.17.6;
Make sure BBP is ready before writing to it

From DragonflyBSD
 1.16 23-Dec-2007  joerg Remove dead power handling code.
 1.15 09-Dec-2007  jmcneill branches: 1.15.2;
Merge jmcneill-pm branch.
 1.14 21-Oct-2007  degroote branches: 1.14.2; 1.14.4; 1.14.6;
Fix a number of driver which doesn't check wep flag in *_tx_mgt.
It is incorrect because we need to encrypt some management frame in case of
shared authentification.
 1.13 19-Oct-2007  ad machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.12 01-Sep-2007  dyoung branches: 1.12.4;
Use bpf_mtap2().
 1.11 01-Sep-2007  dyoung Change a bazillion occurrences of code resembling this,

error = (cmd == SIOCADDMULTI) ?
ether_addmulti(ifr, &sc->sc_ec) :
ether_delmulti(ifr, &sc->sc_ec);

if (error == ENETRESET) {

to this,

if ((error = ether_ioctl(ifp, cmd, data)) == ENETRESET) {

which does the same thing.

(A bazillion is a very large number. This seems to make the i386
ALL kernel smaller by 3kB to 4kB.)

Use ifreq_getaddr() twice in es(4).

Whitespace nits.
 1.10 26-Aug-2007  dyoung branches: 1.10.2;
Constify: LLADDR -> CLLADDR. I'm aiming here to make it easier to
identify sockaddr_dl abuse that remains in the kernel, especially
the potential for overwriting memory past the end of a sockaddr_dl
with, e.g., memcpy(LLADDR(), ...).
 1.9 09-Jul-2007  ad branches: 1.9.2; 1.9.6;
Merge some of the less invasive changes from the vmlocking branch:

- kthread, callout, devsw API changes
- select()/poll() improvements
- miscellaneous MT safety improvements
 1.8 04-Mar-2007  christos branches: 1.8.2; 1.8.4;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.7 16-Nov-2006  christos branches: 1.7.2; 1.7.4;
__unused removal on arguments; approved by core.
 1.6 12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.5 25-Sep-2006  jmcneill Add powerhook for RT2560-based cardbus wireless adapters.
 1.4 17-Sep-2006  jmcneill branches: 1.4.2;
Call rt2560_stop() from rt2560_detach(). Fixes a panic on detach of cardbus
device on my Vaio. Fix from dyoung@.
 1.3 18-Jun-2006  rpaulo branches: 1.3.2; 1.3.4; 1.3.6; 1.3.8; 1.3.10; 1.3.12;
Remove IF_PREPEND() to comply with altq. I think the logic is safe to just
remove the macro call.
 1.2 18-Jun-2006  rpaulo When calling IF_DEQUEUE() check if the dequeued mbuf is NULL to comply
with altq.
 1.1 04-Jun-2006  rpaulo branches: 1.1.2; 1.1.4;
Driver for Ralink chipsets RT2460A, RT2560, RT2561S, RT2561 and RT2661
from FreeBSD/OpenBSD that supersedes ral*.[ch].

Not yet enabled because I don't have a CardBus controller to test and it
will most likely crash during detach.

I tried to include our modifications, but if something is missing please
tell me or add it.

Special thanks to minipci.biz for the donation of one PCI RT2661 and
one CardBus RT2661.
 1.1.4.1 13-Jul-2006  gdamore Merge from HEAD.
 1.1.2.2 07-Jun-2006  kardel Sync with head.
 1.1.2.1 04-Jun-2006  kardel file rt2560.c was added on branch simonb-timecounters on 2006-06-07 15:51:09 +0000
 1.3.12.2 09-Sep-2006  rpaulo sync with head
 1.3.12.1 18-Jun-2006  rpaulo file rt2560.c was added on branch rpaulo-netinet-merge-pcb on 2006-09-09 02:50:03 +0000
 1.3.10.1 18-Nov-2006  ad Sync with head.
 1.3.8.1 23-Sep-2006  snj Pull up following revision(s) (requested by jmcneill in ticket #174):
sys/dev/ic/rt2560.c: revision 1.4
Call rt2560_stop() from rt2560_detach(). Fixes a panic on detach of
cardbus
device on my Vaio. Fix from dyoung@.
 1.3.6.2 26-Jun-2006  yamt sync with head.
 1.3.6.1 18-Jun-2006  yamt file rt2560.c was added on branch yamt-pdpolicy on 2006-06-26 12:51:02 +0000
 1.3.4.7 24-Mar-2008  yamt sync with head.
 1.3.4.6 21-Jan-2008  yamt sync with head
 1.3.4.5 27-Oct-2007  yamt sync with head.
 1.3.4.4 03-Sep-2007  yamt sync with head.
 1.3.4.3 30-Dec-2006  yamt sync with head.
 1.3.4.2 21-Jun-2006  yamt sync with head.
 1.3.4.1 18-Jun-2006  yamt file rt2560.c was added on branch yamt-lazymbuf on 2006-06-21 15:02:56 +0000
 1.3.2.2 19-Jun-2006  chap Sync with head.
 1.3.2.1 18-Jun-2006  chap file rt2560.c was added on branch chap-midi on 2006-06-19 03:58:14 +0000
 1.4.2.2 10-Dec-2006  yamt sync with head.
 1.4.2.1 22-Oct-2006  yamt sync with head
 1.7.4.1 12-Mar-2007  rmind Sync with HEAD.
 1.7.2.1 31-Mar-2009  bouyer Pull up following revision(s) (requested by msaitoh in ticket #1298):
sys/dev/usb/if_ural.c: revision 1.26 via patch
sys/dev/usb/if_rum.c: revision 1.17 via patch
sys/dev/ic/rt2661.c: revision 1.20 via patch
sys/dev/ic/rt2560.c: revision 1.14 via patch
Fix a number of driver which doesn't check wep flag in *_tx_mgt.
It is incorrect because we need to encrypt some management frame in case of
shared authentification.
 1.8.4.1 11-Jul-2007  mjf Sync with head.
 1.8.2.3 23-Oct-2007  ad Sync with head.
 1.8.2.2 09-Oct-2007  ad Sync with head.
 1.8.2.1 01-Jul-2007  ad Adapt to callout API change.
 1.9.6.4 08-Dec-2007  jmcneill Rename pnp(9) -> pmf(9), as requested by many.
 1.9.6.3 06-Nov-2007  joerg Refactor PNP API:
- Make suspend/resume directly a device functionality. It consists of
three layers (class logic, device logic, bus logic), all of them being
optional. This replaces D0/D3 transitions.
- device_is_active returns true if the device was not disabled and was
not suspended (even partially), device_is_enabled returns true if the
device was enabled.
- Change pnp_global_transition into pnp_system_suspend and
pnp_system_resume. Before running any suspend/resume handlers, check
that all currently attached devices support power management and bail
out otherwise. The latter is not done for the shutdown/panic case.
- Make the former bus-specific generic network handlers a class handler.
- Make PNP message like volume up/down/toogle PNP events. Each device
can register what events they are interested in and whether the handler
should be global or not.
- Introduce device_active API for devices to mark themselve in use from
either the system or the device. Use this to implement the idle handling
for audio and input devices. This is intended to replace most ad-hoc
watchdogs as well.
- Fix somes situations in which audio resume would lose mixer settings.
- Make USB host controllers better deal with suspend in the light of
shared interrupts.
- Flush filesystem cache on suspend.
- Flush disk caches on suspend. Put ATA disks into standby on suspend as
well.
- Adopt drivers to use the new PNP API.
- Fix a critical bug in the generic cardbus layer that made D0->D3
break.
- Fix ral(4) to set if_stop.
- Convert cbb(4) to the new PNP API.
- Apply the PCI Express SCI fix on resume again.
 1.9.6.2 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.9.6.1 03-Sep-2007  jmcneill Sync with HEAD.
 1.9.2.1 03-Sep-2007  skrll Sync with HEAD.
 1.10.2.3 23-Mar-2008  matt sync with HEAD
 1.10.2.2 09-Jan-2008  matt sync with HEAD
 1.10.2.1 06-Nov-2007  matt sync with HEAD
 1.12.4.1 25-Oct-2007  bouyer Sync with HEAD.
 1.14.6.1 11-Dec-2007  yamt sync with head.
 1.14.4.1 26-Dec-2007  ad Sync with head.
 1.14.2.1 18-Feb-2008  mjf Sync with HEAD.
 1.15.2.2 10-Jan-2008  bouyer Sync with HEAD
 1.15.2.1 02-Jan-2008  bouyer Sync with HEAD
 1.17.6.3 17-Jan-2009  mjf Sync with HEAD.
 1.17.6.2 02-Jun-2008  mjf Sync with HEAD.
 1.17.6.1 03-Apr-2008  mjf Sync with HEAD.
 1.17.2.1 24-Mar-2008  keiichi sync with head.
 1.19.12.1 19-Jan-2009  skrll Sync with HEAD.
 1.19.10.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.19.4.4 11-Aug-2010  yamt sync with head.
 1.19.4.3 11-Mar-2010  yamt sync with head
 1.19.4.2 16-Sep-2009  yamt sync with head
 1.19.4.1 04-May-2009  yamt sync with head.
 1.22.4.2 03-Jul-2010  rmind sync with head
 1.22.4.1 30-May-2010  rmind sync with head
 1.22.2.2 17-Aug-2010  uebayasi Sync with HEAD.
 1.22.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.24.12.1 24-Feb-2012  mrg sync to -current.
 1.24.8.1 17-Apr-2012  yamt sync with head
 1.25.16.4 28-Aug-2017  skrll Sync with HEAD
 1.25.16.3 05-Feb-2017  skrll Sync with HEAD
 1.25.16.2 09-Jul-2016  skrll Sync with HEAD
 1.25.16.1 29-May-2016  skrll Sync with HEAD
 1.25.2.1 03-Dec-2017  jdolecek update from HEAD
 1.28.4.1 21-Apr-2017  bouyer Sync with HEAD
 1.28.2.1 20-Mar-2017  pgoyette Sync with HEAD
 1.30.2.1 10-Dec-2017  snj Pull up following revision(s) (requested by msaitoh in ticket #427):
sys/arch/amiga/dev/if_bah_zbus.c: 1.17
sys/arch/arm/broadcom/bcm53xx_eth.c: 1.30
sys/arch/powerpc/booke/dev/pq3etsec.c: 1.32
sys/arch/usermode/dev/if_veth.c: 1.9
sys/dev/ic/an.c: 1.66
sys/dev/ic/athn.c: 1.17
sys/dev/ic/atw.c: 1.162
sys/dev/ic/bwi.c: 1.33
sys/dev/ic/dwc_gmac.c: 1.41-1.42
sys/dev/ic/malo.c: 1.10
sys/dev/ic/rt2560.c: 1.31
sys/dev/ic/rt2661.c: 1.36
sys/dev/ic/rt2860.c: 1.29
sys/dev/ic/rtw.c: 1.127
sys/dev/ic/rtwvar.h: 1.46
sys/dev/ic/smc90cx6.c: 1.71
sys/dev/ic/smc90cx6var.h: 1.12
sys/dev/ic/wi.c: 1.244
sys/dev/pci/if_ipw.c: 1.66
sys/dev/pci/if_iwi.c: 1.104
sys/dev/pci/if_iwm.c: 1.76
sys/dev/pci/if_iwn.c: 1.86
sys/dev/pci/if_rtwn.c: 1.13
sys/dev/pci/if_wm.c: 1.541
sys/dev/pci/if_wpi.c: 1.79
sys/dev/pci/ixgbe/ixgbe.c: 1.106
sys/dev/pci/ixgbe/ixv.c: 1.73 via patch
sys/dev/pcmcia/if_malo_pcmcia.c: 1.15
sys/dev/scsipi/if_se.c: 1.95
sys/dev/usb/if_upl.c: 1.60
sys/net/if.c: 1.396
sys/net/if.h: 1.241
sys/net/if_arc.h: 1.23
sys/net/if_arcsubr.c: 1.78
sys/net/if_bridge.c: 1.136-1.137
sys/net/if_etherip.c: 1.39
sys/net/if_faith.c: 1.56
sys/net/if_gif.c: 1.131
sys/net/if_loop.c: 1.96
sys/net/if_mpls.c: 1.30
sys/net/if_pppoe.c: 1.129
sys/net/if_srt.c: 1.27
sys/net/if_stf.c: 1.102
sys/net/if_tap.c: 1.100
sys/net/if_vlan.c: 1.105
sys/netinet/ip_carp.c: 1.91
sys/rump/net/lib/libshmif/if_shmem.c: 1.73-1.74
sys/rump/net/lib/libvirtif/if_virt.c: 1.55-1.56
if_initalize() and if_attach() failed when resource allocation failed
(e.g. allocating softint). Without this change, it panics. It's bad because
resource shortage really occured when a lot of pseudo interface is created.
To avoid this problem, don't panic and change return value of if_initialize()
and if_attach() to int. Caller fanction will be recover from error cleanly by
checking the return value.
Return if bah_attach_subr() failed.
If if_attach() failed in the attach function, return.
- If if_initialize() failed in the attach function, free resources and return.
- Add some missing frees in bridge_clone_destroy().
- KNF
If error occured in bcmeth_ccb_attach(), free resources and return.
If error occured in pq3etsec_attach(), free resources and return.
If error occured in the attach function, free resources and return.
- If if_initialize() failed in athn_attach(), free resources and return.
- Add missing pmf_event_deregister() in athn_detach().
- Free resources correctly on some errors in atw_attach().
- Use apint*() insread of printf() in the attach function.
If if_initialize() failed in the attach function, return.
- If if_initialize() failed in the attach function, free resources and return.
- Add missing dwc_gmac_free_dma_rings() and mutex_destroy() when attach
failed.
- If if_initialize() failed in the attach function, free resources and return.
- ifp is always not NULL in iwi_detach(). Check correctly with ifp->if_softc.
- If if_initialize() failed in the attach function, free resources and return.
- Fix error path in the attach function correctly.
If if_initialize() failed in the attach function, free resources and return.
If if_attach() failed in the attach function, free resources and return.
- If if_initialize() failed in the attach function, free resources and return.
- KNF
- If if_attach() failed in the attach function, free resources and return.
- KNF
Fix compile error.
Fix compile error.
We don't need '&mii', but just 'mii' for mii_detach().
Don't free sc_rthash twice
 1.32.2.4 26-Dec-2018  pgoyette Sync with HEAD, resolve a few conflicts
 1.32.2.3 06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.32.2.2 28-Jul-2018  pgoyette Sync with HEAD
 1.32.2.1 02-May-2018  pgoyette Synch with HEAD
 1.34.2.3 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.34.2.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.34.2.1 10-Jun-2019  christos Sync with HEAD
 1.37.2.1 29-Feb-2020  ad Sync with head.
 1.38.10.1 17-Jun-2021  thorpej Sync w/ HEAD.
 1.40.10.1 02-Aug-2025  perseant Sync with HEAD
 1.1 04-Jun-2006  rpaulo branches: 1.1.2; 1.1.6; 1.1.8; 1.1.10; 1.1.16;
Driver for Ralink chipsets RT2460A, RT2560, RT2561S, RT2561 and RT2661
from FreeBSD/OpenBSD that supersedes ral*.[ch].

Not yet enabled because I don't have a CardBus controller to test and it
will most likely crash during detach.

I tried to include our modifications, but if something is missing please
tell me or add it.

Special thanks to minipci.biz for the donation of one PCI RT2661 and
one CardBus RT2661.
 1.1.16.2 09-Sep-2006  rpaulo sync with head
 1.1.16.1 04-Jun-2006  rpaulo file rt2560reg.h was added on branch rpaulo-netinet-merge-pcb on 2006-09-09 02:50:03 +0000
 1.1.10.2 26-Jun-2006  yamt sync with head.
 1.1.10.1 04-Jun-2006  yamt file rt2560reg.h was added on branch yamt-pdpolicy on 2006-06-26 12:51:02 +0000
 1.1.8.2 21-Jun-2006  yamt sync with head.
 1.1.8.1 04-Jun-2006  yamt file rt2560reg.h was added on branch yamt-lazymbuf on 2006-06-21 15:02:56 +0000
 1.1.6.2 19-Jun-2006  chap Sync with head.
 1.1.6.1 04-Jun-2006  chap file rt2560reg.h was added on branch chap-midi on 2006-06-19 03:58:14 +0000
 1.1.2.2 07-Jun-2006  kardel Sync with head.
 1.1.2.1 04-Jun-2006  kardel file rt2560reg.h was added on branch simonb-timecounters on 2006-06-07 15:51:09 +0000
 1.11 05-Oct-2019  mrg remove __packed attribute from struct ieee80211_radiotap_header
and all the structures that include it.

this should not change anything while avoiding packed vs alignment
warnings from GCC 8, and potentially pessimised code generation
due to the packed marker (there are no misaligned members, just
that the per-device parts may end unaligned.)

all consumers of these members are done from the properly aligned
packet members directly, or, as a union with a 64 byte member,
also properly aligned. codegen didn't appear to change, except
for the definition of sizeof(struct driver_[rt]x_radiotap_header)
in debug info, which is not directly used anywhere.
 1.10 02-Feb-2017  nonaka branches: 1.10.14;
wlan interfaces make interrupt routine running on softint context.

see http://mail-index.netbsd.org/tech-kern/2016/12/06/msg021281.html

tested device:
* ath at pci: AR5212, AR5424
* athn at pci: AR9287
* ipw at pci: 2100BG
* iwi at pci: 2915ABG
* iwm at pci: 3165, 7260, 8260
* iwn at pci: 4945, 6235
* ral at pci: RT2560
* rtwn at pci: RTL8192CE
 1.9 18-Feb-2012  drochner branches: 1.9.2; 1.9.16; 1.9.20; 1.9.24;
split device_t/softc
 1.8 19-Jan-2010  pooka branches: 1.8.12; 1.8.16;
Redefine bpf linkage through an always present op vector, i.e.
#if NBPFILTER is no longer required in the client. This change
doesn't yet add support for loading bpf as a module, since drivers
can register before bpf is attached. However, callers of bpf can
now be modularized.

Dynamically loadable bpf could probably be done fairly easily with
coordination from the stub driver and the real driver by registering
attachments in the stub before the real driver is loaded and doing
a handoff. ... and I'm not going to ponder the depths of unload
here.

Tested with i386/MONOLITHIC, modified MONOLITHIC without bpf and rump.
 1.7 17-Jan-2010  pooka Forward declare struct bpf_if and use that as the type for bpf_if
instead of "void *". Buys us oo times the type-safety for 0 times
the price.
(no functional change)
 1.6 09-Dec-2007  jmcneill branches: 1.6.14;
Merge jmcneill-pm branch.
 1.5 04-Mar-2007  christos branches: 1.5.14; 1.5.16; 1.5.24; 1.5.26;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.4 25-Sep-2006  jmcneill branches: 1.4.4;
Add powerhook for RT2560-based cardbus wireless adapters.
 1.3 09-Jun-2006  drochner branches: 1.3.4; 1.3.6; 1.3.8; 1.3.12; 1.3.14; 1.3.16;
fix obvious botch in radiotap header alignment (untested)
 1.2 06-Jun-2006  rpaulo branches: 1.2.2;
struct ifnet must be inside sc_ec. Fixes panics on detachment.
 1.1 04-Jun-2006  rpaulo Driver for Ralink chipsets RT2460A, RT2560, RT2561S, RT2561 and RT2661
from FreeBSD/OpenBSD that supersedes ral*.[ch].

Not yet enabled because I don't have a CardBus controller to test and it
will most likely crash during detach.

I tried to include our modifications, but if something is missing please
tell me or add it.

Special thanks to minipci.biz for the donation of one PCI RT2661 and
one CardBus RT2661.
 1.2.2.2 07-Jun-2006  kardel Sync with head.
 1.2.2.1 06-Jun-2006  kardel file rt2560var.h was added on branch simonb-timecounters on 2006-06-07 15:51:09 +0000
 1.3.16.1 22-Oct-2006  yamt sync with head
 1.3.14.2 09-Sep-2006  rpaulo sync with head
 1.3.14.1 09-Jun-2006  rpaulo file rt2560var.h was added on branch rpaulo-netinet-merge-pcb on 2006-09-09 02:50:03 +0000
 1.3.12.1 18-Nov-2006  ad Sync with head.
 1.3.8.2 26-Jun-2006  yamt sync with head.
 1.3.8.1 09-Jun-2006  yamt file rt2560var.h was added on branch yamt-pdpolicy on 2006-06-26 12:51:02 +0000
 1.3.6.5 21-Jan-2008  yamt sync with head
 1.3.6.4 03-Sep-2007  yamt sync with head.
 1.3.6.3 30-Dec-2006  yamt sync with head.
 1.3.6.2 21-Jun-2006  yamt sync with head.
 1.3.6.1 09-Jun-2006  yamt file rt2560var.h was added on branch yamt-lazymbuf on 2006-06-21 15:02:56 +0000
 1.3.4.2 19-Jun-2006  chap Sync with head.
 1.3.4.1 09-Jun-2006  chap file rt2560var.h was added on branch chap-midi on 2006-06-19 03:58:14 +0000
 1.4.4.1 12-Mar-2007  rmind Sync with HEAD.
 1.5.26.1 11-Dec-2007  yamt sync with head.
 1.5.24.1 26-Dec-2007  ad Sync with head.
 1.5.16.1 09-Jan-2008  matt sync with HEAD
 1.5.14.1 06-Nov-2007  joerg Refactor PNP API:
- Make suspend/resume directly a device functionality. It consists of
three layers (class logic, device logic, bus logic), all of them being
optional. This replaces D0/D3 transitions.
- device_is_active returns true if the device was not disabled and was
not suspended (even partially), device_is_enabled returns true if the
device was enabled.
- Change pnp_global_transition into pnp_system_suspend and
pnp_system_resume. Before running any suspend/resume handlers, check
that all currently attached devices support power management and bail
out otherwise. The latter is not done for the shutdown/panic case.
- Make the former bus-specific generic network handlers a class handler.
- Make PNP message like volume up/down/toogle PNP events. Each device
can register what events they are interested in and whether the handler
should be global or not.
- Introduce device_active API for devices to mark themselve in use from
either the system or the device. Use this to implement the idle handling
for audio and input devices. This is intended to replace most ad-hoc
watchdogs as well.
- Fix somes situations in which audio resume would lose mixer settings.
- Make USB host controllers better deal with suspend in the light of
shared interrupts.
- Flush filesystem cache on suspend.
- Flush disk caches on suspend. Put ATA disks into standby on suspend as
well.
- Adopt drivers to use the new PNP API.
- Fix a critical bug in the generic cardbus layer that made D0->D3
break.
- Fix ral(4) to set if_stop.
- Convert cbb(4) to the new PNP API.
- Apply the PCI Express SCI fix on resume again.
 1.6.14.1 11-Mar-2010  yamt sync with head
 1.8.16.1 24-Feb-2012  mrg sync to -current.
 1.8.12.1 17-Apr-2012  yamt sync with head
 1.9.24.1 21-Apr-2017  bouyer Sync with HEAD
 1.9.20.1 20-Mar-2017  pgoyette Sync with HEAD
 1.9.16.1 05-Feb-2017  skrll Sync with HEAD
 1.9.2.1 03-Dec-2017  jdolecek update from HEAD
 1.10.14.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.44 16-Jun-2021  riastradh if_attach and if_initialize cannot fail, don't test return value

These were originally made failable back in 2017 when if_initialize
allocated a softint in every interface for link state changes, so
that it could fail gracefully instead of panicking:

https://mail-index.NetBSD.org/source-changes/2017/10/23/msg089053.html

However, this spawned many seldom- or never-tested error branches,
which are risky to have around. And that softint in every interface
has since been replaced by a single global workqueue, because link
state changes require thread context but not low latency or high
throughput:

https://mail-index.NetBSD.org/source-changes/2020/02/06/msg113759.html

So there is no longer any reason for if_initialize to fail. (The
subroutine if_stats_init can't fail because percpu_alloc can't fail
either.)

There is a snag: the softint_establish in if_percpuq_create could
fail, potentially leading to bad consequences later on trying to use
the softint. This change doesn't introduce any new bugs because of
the snag -- if_percpuq_attach was already broken. However, the snag
can be better addressed without spawning error branches, either by
using a single softint or making softints less scarce.

(Separate commit will change the signatures of if_attach and
if_initialize to return void, scheduled to ride whatever is the next
convenient kernel bump.)

Patch and testing on amd64 and evbmips64-eb by maya@; commit message
soliloquy, and compile-testing on evbppc/i386/earmv7hf, by me.
 1.43 29-Jan-2020  thorpej branches: 1.43.10;
Adopt <net/if_stats.h>.
 1.42 10-Nov-2019  chs branches: 1.42.2;
in many device attach paths, allocate memory with M_WAITOK instead of M_NOWAIT
and remove code to handle failures that can no longer happen.
 1.41 22-Dec-2018  maxv Replace: M_COPY_PKTHDR -> m_copy_pkthdr. No functional change, since the
former is a macro to the latter.
 1.40 03-Sep-2018  riastradh Rename min/max -> uimin/uimax for better honesty.

These functions are defined on unsigned int. The generic name
min/max should not silently truncate to 32 bits on 64-bit systems.
This is purely a name change -- no functional change intended.

HOWEVER! Some subsystems have

#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))

even though our standard name for that is MIN/MAX. Although these
may invite multiple evaluation bugs, these do _not_ cause integer
truncation.

To avoid `fixing' these cases, I first changed the name in libkern,
and then compile-tested every file where min/max occurred in order to
confirm that it failed -- and thus confirm that nothing shadowed
min/max -- before changing it.

I have left a handful of bootloaders that are too annoying to
compile-test, and some dead code:

cobalt ews4800mips hp300 hppa ia64 luna68k vax
acorn32/if_ie.c (not included in any kernels)
macppc/if_gm.c (superseded by gem(4))

It should be easy to fix the fallout once identified -- this way of
doing things fails safe, and the goal here, after all, is to _avoid_
silent integer truncations, not introduce them.

Maybe one day we can reintroduce min/max as type-generic things that
never silently truncate. But we should avoid doing that for a while,
so that existing code has a chance to be detected by the compiler for
conversion to uimin/uimax without changing the semantics until we can
properly audit it all. (Who knows, maybe in some cases integer
truncation is actually intended!)
 1.39 26-Jun-2018  msaitoh branches: 1.39.2;
Implement the BPF direction filter (BIOC[GS]DIRECTION). It provides backward
compatibility with BIOC[GS]SEESENT ioctl. The userland interface is the same
as FreeBSD.

This change also fixes a bug that the direction is misunderstand on some
environment by passing the direction to bpf_mtap*() instead of checking
m->m_pkthdr.rcvif.
 1.38 26-Jun-2018  msaitoh bpf_mtap*() before ieee80211_encap() should be bpf_mtap() rather than
bpf_mtap3(). bpf_mtap3() is for raw bpf and be used after ieee80211_encap().
 1.37 01-May-2018  maya GC private 802.11 rateset declarations, use the standard ones.

Build tested only.
 1.36 23-Oct-2017  msaitoh branches: 1.36.2;
If if_initialize() failed in the attach function, free resources and return.
 1.35 23-May-2017  ozaki-r branches: 1.35.2;
Apply deferred if_start to more drivers

And annotate some XXX_start as it runs in softint to clarify that
it doesn't need deferred if_start.
 1.34 02-Feb-2017  nonaka wlan interfaces make interrupt routine running on softint context.

see http://mail-index.netbsd.org/tech-kern/2016/12/06/msg021281.html

tested device:
* ath at pci: AR5212, AR5424
* athn at pci: AR9287
* ipw at pci: 2100BG
* iwi at pci: 2915ABG
* iwm at pci: 3165, 7260, 8260
* iwn at pci: 4945, 6235
* ral at pci: RT2560
* rtwn at pci: RTL8192CE
 1.33 10-Jun-2016  ozaki-r branches: 1.33.2; 1.33.4;
Introduce m_set_rcvif and m_reset_rcvif

The API is used to set (or reset) a received interface of a mbuf.
They are counterpart of m_get_rcvif, which will come in another
commit, hide internal of rcvif operation, and reduce the diff of
the upcoming change.

No functional change.
 1.32 26-May-2016  ozaki-r Introduce M_CLEARCTX and use it instead of open-coding rcvif

No functional change.
 1.31 26-May-2016  ozaki-r Use M_GETCTX

No functional change.
 1.30 07-Jan-2015  ozaki-r Pass a correct firmware size (instead of 0) to firmware_free

firmware_free now uses kmem_free(9) instead of free(9),
so we need to pass a correct size to it.
 1.29 18-Feb-2012  drochner branches: 1.29.2; 1.29.16;
split device_t/softc
 1.28 05-Apr-2010  joerg branches: 1.28.8; 1.28.12;
Push the bpf_ops usage back into bpf.h. Push the common ifp->if_bpf
check into the inline functions as well the fourth argument for
bpf_attach.
 1.27 19-Jan-2010  pooka branches: 1.27.2; 1.27.4;
Redefine bpf linkage through an always present op vector, i.e.
#if NBPFILTER is no longer required in the client. This change
doesn't yet add support for loading bpf as a module, since drivers
can register before bpf is attached. However, callers of bpf can
now be modularized.

Dynamically loadable bpf could probably be done fairly easily with
coordination from the stub driver and the real driver by registering
attachments in the stub before the real driver is loaded and doing
a handoff. ... and I'm not going to ponder the depths of unload
here.

Tested with i386/MONOLITHIC, modified MONOLITHIC without bpf and rump.
 1.26 05-Sep-2009  tsutsui Invert logic around nested pmf(9) registrations for readability.
 1.25 07-Nov-2008  dyoung *** Summary ***

When a link-layer address changes (e.g., ifconfig ex0 link
02:de:ad:be:ef:02 active), send a gratuitous ARP and/or a Neighbor
Advertisement to update the network-/link-layer address bindings
on our LAN peers.

Refuse a change of ethernet address to the address 00:00:00:00:00:00
or to any multicast/broadcast address. (Thanks matt@.)

Reorder ifnet ioctl operations so that driver ioctls may inherit
the functions of their "class"---ether_ioctl(), fddi_ioctl(), et
cetera---and the class ioctls may inherit from the generic ioctl,
ifioctl_common(), but both driver- and class-ioctls may override
the generic behavior. Make network drivers share more code.

Distinguish a "factory" link-layer address from others for the
purposes of both protecting that address from deletion and computing
EUI64.

Return consistent, appropriate error codes from network drivers.

Improve readability. KNF.

*** Details ***

In if_attach(), always initialize the interface ioctl routine,
ifnet->if_ioctl, if the driver has not already initialized it.
Delete if_ioctl == NULL tests everywhere else, because it cannot
happen.

In the ioctl routines of network interfaces, inherit common ioctl
behaviors by calling either ifioctl_common() or whichever ioctl
routine is appropriate for the class of interface---e.g., ether_ioctl()
for ethernets.

Stop (ab)using SIOCSIFADDR and start to use SIOCINITIFADDR. In
the user->kernel interface, SIOCSIFADDR's argument was an ifreq,
but on the protocol->ifnet interface, SIOCSIFADDR's argument was
an ifaddr. That was confusing, and it would work against me as I
make it possible for a network interface to overload most ioctls.
On the protocol->ifnet interface, replace SIOCSIFADDR with
SIOCINITIFADDR. In ifioctl(), return EPERM if userland tries to
invoke SIOCINITIFADDR.

In ifioctl(), give the interface the first shot at handling most
interface ioctls, and give the protocol the second shot, instead
of the other way around. Finally, let compatibility code (COMPAT_OSOCK)
take a shot.

Pull device initialization out of switch statements under
SIOCINITIFADDR. For example, pull ..._init() out of any switch
statement that looks like this:

switch (...->sa_family) {
case ...:
..._init();
...
break;
...
default:
..._init();
...
break;
}

Rewrite many if-else clauses that handle all permutations of IFF_UP
and IFF_RUNNING to use a switch statement,

switch (x & (IFF_UP|IFF_RUNNING)) {
case 0:
...
break;
case IFF_RUNNING:
...
break;
case IFF_UP:
...
break;
case IFF_UP|IFF_RUNNING:
...
break;
}

unifdef lots of code containing #ifdef FreeBSD, #ifdef NetBSD, and
#ifdef SIOCSIFMTU, especially in fwip(4) and in ndis(4).

In ipw(4), remove an if_set_sadl() call that is out of place.

In nfe(4), reuse the jumbo MTU logic in ether_ioctl().

Let ethernets register a callback for setting h/w state such as
promiscuous mode and the multicast filter in accord with a change
in the if_flags: ether_set_ifflags_cb() registers a callback that
returns ENETRESET if the caller should reset the ethernet by calling
if_init(), 0 on success, != 0 on failure. Pull common code from
ex(4), gem(4), nfe(4), sip(4), tlp(4), vge(4) into ether_ioctl(),
and register if_flags callbacks for those drivers.

Return ENOTTY instead of EINVAL for inappropriate ioctls. In
zyd(4), use ENXIO instead of ENOTTY to indicate that the device is
not any longer attached.

Add to if_set_sadl() a boolean 'factory' argument that indicates
whether a link-layer address was assigned by the factory or some
other source. In a comment, recommend using the factory address
for generating an EUI64, and update in6_get_hw_ifid() to prefer a
factory address to any other link-layer address.

Add a routing message, RTM_LLINFO_UPD, that tells protocols to
update the binding of network-layer addresses to link-layer addresses.
Implement this message in IPv4 and IPv6 by sending a gratuitous
ARP or a neighbor advertisement, respectively. Generate RTM_LLINFO_UPD
messages on a change of an interface's link-layer address.

In ether_ioctl(), do not let SIOCALIFADDR set a link-layer address
that is broadcast/multicast or equal to 00:00:00:00:00:00.

Make ether_ioctl() call ifioctl_common() to handle ioctls that it
does not understand.

In gif(4), initialize if_softc and use it, instead of assuming that
the gif_softc and ifp overlap.

Let ifioctl_common() handle SIOCGIFADDR.

Sprinkle rtcache_invariants(), which checks on DIAGNOSTIC kernels
that certain invariants on a struct route are satisfied.

In agr(4), rewrite agr_ioctl_filter() to be a bit more explicit
about the ioctls that we do not allow on an agr(4) member interface.

bzero -> memset. Delete unnecessary casts to void *. Use
sockaddr_in_init() and sockaddr_in6_init(). Compare pointers with
NULL instead of "testing truth". Replace some instances of (type
*)0 with NULL. Change some K&R prototypes to ANSI C, and join
lines.
 1.24 29-Apr-2008  scw branches: 1.24.6; 1.24.8;
Pull in some more changes from OpenBSD:

- replace rssadapt(9) with amrr for automatic rate control.
- don't blindly IFQ_DEQUEUE() then drop a Tx packet if there are no
available Tx resources.
- move default MAC/BBP/RF settings from rt2661.c to rt2661reg.h.
- enable packet bursting when operating as a STA.
- implement new ic_updateslot() callback.
- in hostap mode, we defer update of the slot time until all associated
STAs are notified with updated beacons.
- 802.11a uses a 16 microseconds short interframe space.
- Fix rt2661_set_macaddr() so that we don't override the "unicast to me"
flag in RT2661_MAC_CSR3 when setting the MAC address.
- fix index of ERP information element in beacons.

Add a couple of tweaks of my own:

- The RX/TX BUSY flag should be the last thing written to a descriptor.
- Check and service any additional h/w interrupts before returning
from the isr.

Tested in STA, AP, and Monitor modes. Tested with WEP, WPA, and WPA2 crypto.

Additional testing by xtraeme@
 1.23 08-Apr-2008  cegger branches: 1.23.2; 1.23.4;
use aprint_*_dev and device_xname
 1.22 17-Mar-2008  xtraeme Merge some changes from OpenBSD:

RT2560+RT2661: update the physical address in the RX descriptor after
bus_dmamap_load() in the case where the same mbuf is reloaded.

modify interrupt handlers to exit early and return 0 on shared interrupts.

RT2661:
flags for register TXRX_CSR4 were shifted one bit too much on the left.
this has probably affected short preamble support as well as hardware
multi-rate retries settings.

fix handling of the SIOCS80211CHANNEL ioctl in monitor mode:
don't call xxx_set_chan() if the interface is not up&running.

Tested with the following hw:

ral0 at pci5 dev 0 function 0: Ralink Technologies RT2561 802.11b/g (rev. 0x00)
ral0: interrupting at ioapic0 pin 20 (irq 10)
ral0: 802.11 address 00:80:5a:4f:ab:e2
ral0: MAC/BBP RT2561C, RF RT2527
 1.21 09-Dec-2007  jmcneill branches: 1.21.6; 1.21.10;
Merge jmcneill-pm branch.
 1.20 21-Oct-2007  degroote branches: 1.20.4; 1.20.6;
Fix a number of driver which doesn't check wep flag in *_tx_mgt.
It is incorrect because we need to encrypt some management frame in case of
shared authentification.
 1.19 19-Oct-2007  ad machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.18 29-Sep-2007  scw branches: 1.18.2;
- Fix bpf radiotap: s/NPBFILTER/NBPFILTER/
- In rt2661_set_chan(), handle the case where there is no previous channel.
(Can happen if we go directly to monitor mode before UP'ing the i/f)
 1.17 01-Sep-2007  dyoung branches: 1.17.2;
Change a bazillion occurrences of code resembling this,

error = (cmd == SIOCADDMULTI) ?
ether_addmulti(ifr, &sc->sc_ec) :
ether_delmulti(ifr, &sc->sc_ec);

if (error == ENETRESET) {

to this,

if ((error = ether_ioctl(ifp, cmd, data)) == ENETRESET) {

which does the same thing.

(A bazillion is a very large number. This seems to make the i386
ALL kernel smaller by 3kB to 4kB.)

Use ifreq_getaddr() twice in es(4).

Whitespace nits.
 1.16 26-Aug-2007  dyoung branches: 1.16.2;
Constify: LLADDR -> CLLADDR. I'm aiming here to make it easier to
identify sockaddr_dl abuse that remains in the kernel, especially
the potential for overwriting memory past the end of a sockaddr_dl
with, e.g., memcpy(LLADDR(), ...).
 1.15 09-Jul-2007  ad branches: 1.15.2; 1.15.6;
Merge some of the less invasive changes from the vmlocking branch:

- kthread, callout, devsw API changes
- select()/poll() improvements
- miscellaneous MT safety improvements
 1.14 04-Mar-2007  christos branches: 1.14.2; 1.14.4;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.13 16-Nov-2006  christos branches: 1.13.2; 1.13.4;
__unused removal on arguments; approved by core.
 1.12 12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.11 04-Jul-2006  rpaulo branches: 1.11.4; 1.11.6; 1.11.8;
Add missing semicolon.
 1.10 04-Jul-2006  rpaulo Coverity CID 3805: Close the firmware_handle on error and avoid leaks.
 1.9 18-Jun-2006  rpaulo branches: 1.9.2; 1.9.4; 1.9.6;
Remove IF_PREPEND() to comply with altq. I think the logic is safe to just
remove the macro call.
 1.8 18-Jun-2006  rpaulo When calling IF_DEQUEUE() check if the dequeued mbuf is NULL to comply
with altq.
 1.7 09-Jun-2006  rpaulo branches: 1.7.2;
Revert previous. Wrong way of doing things...
 1.6 08-Jun-2006  rpaulo Bring the following change from OpenBSD:

Keep track of the average RSSI using an Exponential Moving Average (EMA).
Use it to dynamically tune radio receive sensitivity.

The idea is simple:
- increase sensitivity when the RSSI is bad to optimize throughput on
long distance to the AP, and
- decrease sensitivity when the RSSI is good to reduce noise level and
optimize throughput on short distance to the AP

The EMA allows to smooth RSSI variations so we don't end up changing the
sensitivity too frequently. We check if it would be worth updating the
sensitivity every one second.
RSSI thresholds were taken from the Ralink Tech. Linux driver.
 1.5 08-Jun-2006  rpaulo Rename sta variable. Pointed out by Havard Eidnes and Juergen Hannken-Illjes.
 1.4 06-Jun-2006  rpaulo branches: 1.4.2;
Oops, missing arg to firmware_free.
 1.3 05-Jun-2006  rpaulo Don't leak memory on error.
 1.2 05-Jun-2006  rpaulo Add missing firmware_close().
 1.1 04-Jun-2006  rpaulo Driver for Ralink chipsets RT2460A, RT2560, RT2561S, RT2561 and RT2661
from FreeBSD/OpenBSD that supersedes ral*.[ch].

Not yet enabled because I don't have a CardBus controller to test and it
will most likely crash during detach.

I tried to include our modifications, but if something is missing please
tell me or add it.

Special thanks to minipci.biz for the donation of one PCI RT2661 and
one CardBus RT2661.
 1.4.2.2 07-Jun-2006  kardel Sync with head.
 1.4.2.1 06-Jun-2006  kardel file rt2661.c was added on branch simonb-timecounters on 2006-06-07 15:51:09 +0000
 1.7.2.1 13-Jul-2006  gdamore Merge from HEAD.
 1.9.6.3 11-Aug-2006  yamt sync with head
 1.9.6.2 26-Jun-2006  yamt sync with head.
 1.9.6.1 18-Jun-2006  yamt file rt2661.c was added on branch yamt-pdpolicy on 2006-06-26 12:51:02 +0000
 1.9.4.7 24-Mar-2008  yamt sync with head.
 1.9.4.6 21-Jan-2008  yamt sync with head
 1.9.4.5 27-Oct-2007  yamt sync with head.
 1.9.4.4 03-Sep-2007  yamt sync with head.
 1.9.4.3 30-Dec-2006  yamt sync with head.
 1.9.4.2 21-Jun-2006  yamt sync with head.
 1.9.4.1 18-Jun-2006  yamt file rt2661.c was added on branch yamt-lazymbuf on 2006-06-21 15:02:56 +0000
 1.9.2.2 19-Jun-2006  chap Sync with head.
 1.9.2.1 18-Jun-2006  chap file rt2661.c was added on branch chap-midi on 2006-06-19 03:58:14 +0000
 1.11.8.2 10-Dec-2006  yamt sync with head.
 1.11.8.1 22-Oct-2006  yamt sync with head
 1.11.6.2 09-Sep-2006  rpaulo sync with head
 1.11.6.1 04-Jul-2006  rpaulo file rt2661.c was added on branch rpaulo-netinet-merge-pcb on 2006-09-09 02:50:03 +0000
 1.11.4.1 18-Nov-2006  ad Sync with head.
 1.13.4.1 12-Mar-2007  rmind Sync with HEAD.
 1.13.2.1 31-Mar-2009  bouyer Pull up following revision(s) (requested by msaitoh in ticket #1298):
sys/dev/usb/if_ural.c: revision 1.26 via patch
sys/dev/usb/if_rum.c: revision 1.17 via patch
sys/dev/ic/rt2661.c: revision 1.20 via patch
sys/dev/ic/rt2560.c: revision 1.14 via patch
Fix a number of driver which doesn't check wep flag in *_tx_mgt.
It is incorrect because we need to encrypt some management frame in case of
shared authentification.
 1.14.4.1 11-Jul-2007  mjf Sync with head.
 1.14.2.3 23-Oct-2007  ad Sync with head.
 1.14.2.2 09-Oct-2007  ad Sync with head.
 1.14.2.1 01-Jul-2007  ad Adapt to callout API change.
 1.15.6.5 08-Dec-2007  jmcneill Rename pnp(9) -> pmf(9), as requested by many.
 1.15.6.4 06-Nov-2007  joerg Refactor PNP API:
- Make suspend/resume directly a device functionality. It consists of
three layers (class logic, device logic, bus logic), all of them being
optional. This replaces D0/D3 transitions.
- device_is_active returns true if the device was not disabled and was
not suspended (even partially), device_is_enabled returns true if the
device was enabled.
- Change pnp_global_transition into pnp_system_suspend and
pnp_system_resume. Before running any suspend/resume handlers, check
that all currently attached devices support power management and bail
out otherwise. The latter is not done for the shutdown/panic case.
- Make the former bus-specific generic network handlers a class handler.
- Make PNP message like volume up/down/toogle PNP events. Each device
can register what events they are interested in and whether the handler
should be global or not.
- Introduce device_active API for devices to mark themselve in use from
either the system or the device. Use this to implement the idle handling
for audio and input devices. This is intended to replace most ad-hoc
watchdogs as well.
- Fix somes situations in which audio resume would lose mixer settings.
- Make USB host controllers better deal with suspend in the light of
shared interrupts.
- Flush filesystem cache on suspend.
- Flush disk caches on suspend. Put ATA disks into standby on suspend as
well.
- Adopt drivers to use the new PNP API.
- Fix a critical bug in the generic cardbus layer that made D0->D3
break.
- Fix ral(4) to set if_stop.
- Convert cbb(4) to the new PNP API.
- Apply the PCI Express SCI fix on resume again.
 1.15.6.3 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.15.6.2 02-Oct-2007  joerg Sync with HEAD.
 1.15.6.1 03-Sep-2007  jmcneill Sync with HEAD.
 1.15.2.1 03-Sep-2007  skrll Sync with HEAD.
 1.16.2.3 23-Mar-2008  matt sync with HEAD
 1.16.2.2 09-Jan-2008  matt sync with HEAD
 1.16.2.1 06-Nov-2007  matt sync with HEAD
 1.17.2.1 06-Oct-2007  yamt sync with head.
 1.18.2.1 25-Oct-2007  bouyer Sync with HEAD.
 1.20.6.1 11-Dec-2007  yamt sync with head.
 1.20.4.1 26-Dec-2007  ad Sync with head.
 1.21.10.3 17-Jan-2009  mjf Sync with HEAD.
 1.21.10.2 02-Jun-2008  mjf Sync with HEAD.
 1.21.10.1 03-Apr-2008  mjf Sync with HEAD.
 1.21.6.1 24-Mar-2008  keiichi sync with head.
 1.23.4.5 11-Aug-2010  yamt sync with head.
 1.23.4.4 11-Mar-2010  yamt sync with head
 1.23.4.3 16-Sep-2009  yamt sync with head
 1.23.4.2 04-May-2009  yamt sync with head.
 1.23.4.1 16-May-2008  yamt sync with head.
 1.23.2.1 18-May-2008  yamt sync with head.
 1.24.8.1 19-Jan-2009  skrll Sync with HEAD.
 1.24.6.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.27.4.1 30-May-2010  rmind sync with head
 1.27.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.28.12.1 24-Feb-2012  mrg sync to -current.
 1.28.8.1 17-Apr-2012  yamt sync with head
 1.29.16.5 28-Aug-2017  skrll Sync with HEAD
 1.29.16.4 05-Feb-2017  skrll Sync with HEAD
 1.29.16.3 09-Jul-2016  skrll Sync with HEAD
 1.29.16.2 29-May-2016  skrll Sync with HEAD
 1.29.16.1 06-Apr-2015  skrll Sync with HEAD
 1.29.2.1 03-Dec-2017  jdolecek update from HEAD
 1.33.4.1 21-Apr-2017  bouyer Sync with HEAD
 1.33.2.1 20-Mar-2017  pgoyette Sync with HEAD
 1.35.2.2 31-Jul-2018  martin Pull up following revision(s) (requested by msaitoh in ticket #951):

sys/dev/ic/rt2661.c: revision 1.38

bpf_mtap*() before ieee80211_encap() should be bpf_mtap() rather than
bpf_mtap3(). bpf_mtap3() is for raw bpf and be used after ieee80211_encap().
 1.35.2.1 10-Dec-2017  snj Pull up following revision(s) (requested by msaitoh in ticket #427):
sys/arch/amiga/dev/if_bah_zbus.c: 1.17
sys/arch/arm/broadcom/bcm53xx_eth.c: 1.30
sys/arch/powerpc/booke/dev/pq3etsec.c: 1.32
sys/arch/usermode/dev/if_veth.c: 1.9
sys/dev/ic/an.c: 1.66
sys/dev/ic/athn.c: 1.17
sys/dev/ic/atw.c: 1.162
sys/dev/ic/bwi.c: 1.33
sys/dev/ic/dwc_gmac.c: 1.41-1.42
sys/dev/ic/malo.c: 1.10
sys/dev/ic/rt2560.c: 1.31
sys/dev/ic/rt2661.c: 1.36
sys/dev/ic/rt2860.c: 1.29
sys/dev/ic/rtw.c: 1.127
sys/dev/ic/rtwvar.h: 1.46
sys/dev/ic/smc90cx6.c: 1.71
sys/dev/ic/smc90cx6var.h: 1.12
sys/dev/ic/wi.c: 1.244
sys/dev/pci/if_ipw.c: 1.66
sys/dev/pci/if_iwi.c: 1.104
sys/dev/pci/if_iwm.c: 1.76
sys/dev/pci/if_iwn.c: 1.86
sys/dev/pci/if_rtwn.c: 1.13
sys/dev/pci/if_wm.c: 1.541
sys/dev/pci/if_wpi.c: 1.79
sys/dev/pci/ixgbe/ixgbe.c: 1.106
sys/dev/pci/ixgbe/ixv.c: 1.73 via patch
sys/dev/pcmcia/if_malo_pcmcia.c: 1.15
sys/dev/scsipi/if_se.c: 1.95
sys/dev/usb/if_upl.c: 1.60
sys/net/if.c: 1.396
sys/net/if.h: 1.241
sys/net/if_arc.h: 1.23
sys/net/if_arcsubr.c: 1.78
sys/net/if_bridge.c: 1.136-1.137
sys/net/if_etherip.c: 1.39
sys/net/if_faith.c: 1.56
sys/net/if_gif.c: 1.131
sys/net/if_loop.c: 1.96
sys/net/if_mpls.c: 1.30
sys/net/if_pppoe.c: 1.129
sys/net/if_srt.c: 1.27
sys/net/if_stf.c: 1.102
sys/net/if_tap.c: 1.100
sys/net/if_vlan.c: 1.105
sys/netinet/ip_carp.c: 1.91
sys/rump/net/lib/libshmif/if_shmem.c: 1.73-1.74
sys/rump/net/lib/libvirtif/if_virt.c: 1.55-1.56
if_initalize() and if_attach() failed when resource allocation failed
(e.g. allocating softint). Without this change, it panics. It's bad because
resource shortage really occured when a lot of pseudo interface is created.
To avoid this problem, don't panic and change return value of if_initialize()
and if_attach() to int. Caller fanction will be recover from error cleanly by
checking the return value.
Return if bah_attach_subr() failed.
If if_attach() failed in the attach function, return.
- If if_initialize() failed in the attach function, free resources and return.
- Add some missing frees in bridge_clone_destroy().
- KNF
If error occured in bcmeth_ccb_attach(), free resources and return.
If error occured in pq3etsec_attach(), free resources and return.
If error occured in the attach function, free resources and return.
- If if_initialize() failed in athn_attach(), free resources and return.
- Add missing pmf_event_deregister() in athn_detach().
- Free resources correctly on some errors in atw_attach().
- Use apint*() insread of printf() in the attach function.
If if_initialize() failed in the attach function, return.
- If if_initialize() failed in the attach function, free resources and return.
- Add missing dwc_gmac_free_dma_rings() and mutex_destroy() when attach
failed.
- If if_initialize() failed in the attach function, free resources and return.
- ifp is always not NULL in iwi_detach(). Check correctly with ifp->if_softc.
- If if_initialize() failed in the attach function, free resources and return.
- Fix error path in the attach function correctly.
If if_initialize() failed in the attach function, free resources and return.
If if_attach() failed in the attach function, free resources and return.
- If if_initialize() failed in the attach function, free resources and return.
- KNF
- If if_attach() failed in the attach function, free resources and return.
- KNF
Fix compile error.
Fix compile error.
We don't need '&mii', but just 'mii' for mii_detach().
Don't free sc_rthash twice
 1.36.2.4 26-Dec-2018  pgoyette Sync with HEAD, resolve a few conflicts
 1.36.2.3 06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.36.2.2 28-Jul-2018  pgoyette Sync with HEAD
 1.36.2.1 02-May-2018  pgoyette Synch with HEAD
 1.39.2.3 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.39.2.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.39.2.1 10-Jun-2019  christos Sync with HEAD
 1.42.2.1 29-Feb-2020  ad Sync with head.
 1.43.10.1 17-Jun-2021  thorpej Sync w/ HEAD.
 1.3 29-Apr-2008  scw Pull in some more changes from OpenBSD:

- replace rssadapt(9) with amrr for automatic rate control.
- don't blindly IFQ_DEQUEUE() then drop a Tx packet if there are no
available Tx resources.
- move default MAC/BBP/RF settings from rt2661.c to rt2661reg.h.
- enable packet bursting when operating as a STA.
- implement new ic_updateslot() callback.
- in hostap mode, we defer update of the slot time until all associated
STAs are notified with updated beacons.
- 802.11a uses a 16 microseconds short interframe space.
- Fix rt2661_set_macaddr() so that we don't override the "unicast to me"
flag in RT2661_MAC_CSR3 when setting the MAC address.
- fix index of ERP information element in beacons.

Add a couple of tweaks of my own:

- The RX/TX BUSY flag should be the last thing written to a descriptor.
- Check and service any additional h/w interrupts before returning
from the isr.

Tested in STA, AP, and Monitor modes. Tested with WEP, WPA, and WPA2 crypto.

Additional testing by xtraeme@
 1.2 17-Mar-2008  xtraeme branches: 1.2.2; 1.2.4;
Merge some changes from OpenBSD:

RT2560+RT2661: update the physical address in the RX descriptor after
bus_dmamap_load() in the case where the same mbuf is reloaded.

modify interrupt handlers to exit early and return 0 on shared interrupts.

RT2661:
flags for register TXRX_CSR4 were shifted one bit too much on the left.
this has probably affected short preamble support as well as hardware
multi-rate retries settings.

fix handling of the SIOCS80211CHANNEL ioctl in monitor mode:
don't call xxx_set_chan() if the interface is not up&running.

Tested with the following hw:

ral0 at pci5 dev 0 function 0: Ralink Technologies RT2561 802.11b/g (rev. 0x00)
ral0: interrupting at ioapic0 pin 20 (irq 10)
ral0: 802.11 address 00:80:5a:4f:ab:e2
ral0: MAC/BBP RT2561C, RF RT2527
 1.1 04-Jun-2006  rpaulo branches: 1.1.2; 1.1.6; 1.1.8; 1.1.10; 1.1.16; 1.1.42; 1.1.62; 1.1.66;
Driver for Ralink chipsets RT2460A, RT2560, RT2561S, RT2561 and RT2661
from FreeBSD/OpenBSD that supersedes ral*.[ch].

Not yet enabled because I don't have a CardBus controller to test and it
will most likely crash during detach.

I tried to include our modifications, but if something is missing please
tell me or add it.

Special thanks to minipci.biz for the donation of one PCI RT2661 and
one CardBus RT2661.
 1.1.66.2 02-Jun-2008  mjf Sync with HEAD.
 1.1.66.1 03-Apr-2008  mjf Sync with HEAD.
 1.1.62.1 24-Mar-2008  keiichi sync with head.
 1.1.42.1 23-Mar-2008  matt sync with HEAD
 1.1.16.2 09-Sep-2006  rpaulo sync with head
 1.1.16.1 04-Jun-2006  rpaulo file rt2661reg.h was added on branch rpaulo-netinet-merge-pcb on 2006-09-09 02:50:03 +0000
 1.1.10.2 26-Jun-2006  yamt sync with head.
 1.1.10.1 04-Jun-2006  yamt file rt2661reg.h was added on branch yamt-pdpolicy on 2006-06-26 12:51:02 +0000
 1.1.8.3 24-Mar-2008  yamt sync with head.
 1.1.8.2 21-Jun-2006  yamt sync with head.
 1.1.8.1 04-Jun-2006  yamt file rt2661reg.h was added on branch yamt-lazymbuf on 2006-06-21 15:02:56 +0000
 1.1.6.2 19-Jun-2006  chap Sync with head.
 1.1.6.1 04-Jun-2006  chap file rt2661reg.h was added on branch chap-midi on 2006-06-19 03:58:14 +0000
 1.1.2.2 07-Jun-2006  kardel Sync with head.
 1.1.2.1 04-Jun-2006  kardel file rt2661reg.h was added on branch simonb-timecounters on 2006-06-07 15:51:09 +0000
 1.2.4.1 16-May-2008  yamt sync with head.
 1.2.2.1 18-May-2008  yamt sync with head.
 1.13 05-Oct-2019  mrg remove __packed attribute from struct ieee80211_radiotap_header
and all the structures that include it.

this should not change anything while avoiding packed vs alignment
warnings from GCC 8, and potentially pessimised code generation
due to the packed marker (there are no misaligned members, just
that the per-device parts may end unaligned.)

all consumers of these members are done from the properly aligned
packet members directly, or, as a union with a 64 byte member,
also properly aligned. codegen didn't appear to change, except
for the definition of sizeof(struct driver_[rt]x_radiotap_header)
in debug info, which is not directly used anywhere.
 1.12 02-Feb-2017  nonaka branches: 1.12.14;
wlan interfaces make interrupt routine running on softint context.

see http://mail-index.netbsd.org/tech-kern/2016/12/06/msg021281.html

tested device:
* ath at pci: AR5212, AR5424
* athn at pci: AR9287
* ipw at pci: 2100BG
* iwi at pci: 2915ABG
* iwm at pci: 3165, 7260, 8260
* iwn at pci: 4945, 6235
* ral at pci: RT2560
* rtwn at pci: RTL8192CE
 1.11 18-Feb-2012  drochner branches: 1.11.2; 1.11.16; 1.11.20; 1.11.24;
split device_t/softc
 1.10 19-Jan-2010  pooka branches: 1.10.12; 1.10.16;
Redefine bpf linkage through an always present op vector, i.e.
#if NBPFILTER is no longer required in the client. This change
doesn't yet add support for loading bpf as a module, since drivers
can register before bpf is attached. However, callers of bpf can
now be modularized.

Dynamically loadable bpf could probably be done fairly easily with
coordination from the stub driver and the real driver by registering
attachments in the stub before the real driver is loaded and doing
a handoff. ... and I'm not going to ponder the depths of unload
here.

Tested with i386/MONOLITHIC, modified MONOLITHIC without bpf and rump.
 1.9 17-Jan-2010  pooka Forward declare struct bpf_if and use that as the type for bpf_if
instead of "void *". Buys us oo times the type-safety for 0 times
the price.
(no functional change)
 1.8 29-Apr-2008  scw Pull in some more changes from OpenBSD:

- replace rssadapt(9) with amrr for automatic rate control.
- don't blindly IFQ_DEQUEUE() then drop a Tx packet if there are no
available Tx resources.
- move default MAC/BBP/RF settings from rt2661.c to rt2661reg.h.
- enable packet bursting when operating as a STA.
- implement new ic_updateslot() callback.
- in hostap mode, we defer update of the slot time until all associated
STAs are notified with updated beacons.
- 802.11a uses a 16 microseconds short interframe space.
- Fix rt2661_set_macaddr() so that we don't override the "unicast to me"
flag in RT2661_MAC_CSR3 when setting the MAC address.
- fix index of ERP information element in beacons.

Add a couple of tweaks of my own:

- The RX/TX BUSY flag should be the last thing written to a descriptor.
- Check and service any additional h/w interrupts before returning
from the isr.

Tested in STA, AP, and Monitor modes. Tested with WEP, WPA, and WPA2 crypto.

Additional testing by xtraeme@
 1.7 09-Dec-2007  jmcneill branches: 1.7.10; 1.7.12; 1.7.14;
Merge jmcneill-pm branch.
 1.6 04-Mar-2007  christos branches: 1.6.14; 1.6.16; 1.6.24; 1.6.26;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.5 09-Jun-2006  drochner branches: 1.5.4; 1.5.6; 1.5.8; 1.5.14; 1.5.20;
fix obvious botch in radiotap header alignment (untested)
 1.4 09-Jun-2006  rpaulo Revert previous. Wrong way of doing things...
 1.3 08-Jun-2006  rpaulo Bring the following change from OpenBSD:

Keep track of the average RSSI using an Exponential Moving Average (EMA).
Use it to dynamically tune radio receive sensitivity.

The idea is simple:
- increase sensitivity when the RSSI is bad to optimize throughput on
long distance to the AP, and
- decrease sensitivity when the RSSI is good to reduce noise level and
optimize throughput on short distance to the AP

The EMA allows to smooth RSSI variations so we don't end up changing the
sensitivity too frequently. We check if it would be worth updating the
sensitivity every one second.
RSSI thresholds were taken from the Ralink Tech. Linux driver.
 1.2 06-Jun-2006  rpaulo branches: 1.2.2;
struct ifnet must be inside sc_ec. Fixes panics on detachment.
 1.1 04-Jun-2006  rpaulo Driver for Ralink chipsets RT2460A, RT2560, RT2561S, RT2561 and RT2661
from FreeBSD/OpenBSD that supersedes ral*.[ch].

Not yet enabled because I don't have a CardBus controller to test and it
will most likely crash during detach.

I tried to include our modifications, but if something is missing please
tell me or add it.

Special thanks to minipci.biz for the donation of one PCI RT2661 and
one CardBus RT2661.
 1.2.2.2 07-Jun-2006  kardel Sync with head.
 1.2.2.1 06-Jun-2006  kardel file rt2661var.h was added on branch simonb-timecounters on 2006-06-07 15:51:09 +0000
 1.5.20.1 12-Mar-2007  rmind Sync with HEAD.
 1.5.14.2 09-Sep-2006  rpaulo sync with head
 1.5.14.1 09-Jun-2006  rpaulo file rt2661var.h was added on branch rpaulo-netinet-merge-pcb on 2006-09-09 02:50:03 +0000
 1.5.8.2 26-Jun-2006  yamt sync with head.
 1.5.8.1 09-Jun-2006  yamt file rt2661var.h was added on branch yamt-pdpolicy on 2006-06-26 12:51:02 +0000
 1.5.6.4 21-Jan-2008  yamt sync with head
 1.5.6.3 03-Sep-2007  yamt sync with head.
 1.5.6.2 21-Jun-2006  yamt sync with head.
 1.5.6.1 09-Jun-2006  yamt file rt2661var.h was added on branch yamt-lazymbuf on 2006-06-21 15:02:56 +0000
 1.5.4.2 19-Jun-2006  chap Sync with head.
 1.5.4.1 09-Jun-2006  chap file rt2661var.h was added on branch chap-midi on 2006-06-19 03:58:14 +0000
 1.6.26.1 11-Dec-2007  yamt sync with head.
 1.6.24.1 26-Dec-2007  ad Sync with head.
 1.6.16.1 09-Jan-2008  matt sync with HEAD
 1.6.14.1 06-Nov-2007  joerg Refactor PNP API:
- Make suspend/resume directly a device functionality. It consists of
three layers (class logic, device logic, bus logic), all of them being
optional. This replaces D0/D3 transitions.
- device_is_active returns true if the device was not disabled and was
not suspended (even partially), device_is_enabled returns true if the
device was enabled.
- Change pnp_global_transition into pnp_system_suspend and
pnp_system_resume. Before running any suspend/resume handlers, check
that all currently attached devices support power management and bail
out otherwise. The latter is not done for the shutdown/panic case.
- Make the former bus-specific generic network handlers a class handler.
- Make PNP message like volume up/down/toogle PNP events. Each device
can register what events they are interested in and whether the handler
should be global or not.
- Introduce device_active API for devices to mark themselve in use from
either the system or the device. Use this to implement the idle handling
for audio and input devices. This is intended to replace most ad-hoc
watchdogs as well.
- Fix somes situations in which audio resume would lose mixer settings.
- Make USB host controllers better deal with suspend in the light of
shared interrupts.
- Flush filesystem cache on suspend.
- Flush disk caches on suspend. Put ATA disks into standby on suspend as
well.
- Adopt drivers to use the new PNP API.
- Fix a critical bug in the generic cardbus layer that made D0->D3
break.
- Fix ral(4) to set if_stop.
- Convert cbb(4) to the new PNP API.
- Apply the PCI Express SCI fix on resume again.
 1.7.14.2 11-Mar-2010  yamt sync with head
 1.7.14.1 16-May-2008  yamt sync with head.
 1.7.12.1 18-May-2008  yamt sync with head.
 1.7.10.1 02-Jun-2008  mjf Sync with HEAD.
 1.10.16.1 24-Feb-2012  mrg sync to -current.
 1.10.12.1 17-Apr-2012  yamt sync with head
 1.11.24.1 21-Apr-2017  bouyer Sync with HEAD
 1.11.20.1 20-Mar-2017  pgoyette Sync with HEAD
 1.11.16.1 05-Feb-2017  skrll Sync with HEAD
 1.11.2.1 03-Dec-2017  jdolecek update from HEAD
 1.12.14.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.36 16-Jun-2021  riastradh if_attach and if_initialize cannot fail, don't test return value

These were originally made failable back in 2017 when if_initialize
allocated a softint in every interface for link state changes, so
that it could fail gracefully instead of panicking:

https://mail-index.NetBSD.org/source-changes/2017/10/23/msg089053.html

However, this spawned many seldom- or never-tested error branches,
which are risky to have around. And that softint in every interface
has since been replaced by a single global workqueue, because link
state changes require thread context but not low latency or high
throughput:

https://mail-index.NetBSD.org/source-changes/2020/02/06/msg113759.html

So there is no longer any reason for if_initialize to fail. (The
subroutine if_stats_init can't fail because percpu_alloc can't fail
either.)

There is a snag: the softint_establish in if_percpuq_create could
fail, potentially leading to bad consequences later on trying to use
the softint. This change doesn't introduce any new bugs because of
the snag -- if_percpuq_attach was already broken. However, the snag
can be better addressed without spawning error branches, either by
using a single softint or making softints less scarce.

(Separate commit will change the signatures of if_attach and
if_initialize to return void, scheduled to ride whatever is the next
convenient kernel bump.)

Patch and testing on amd64 and evbmips64-eb by maya@; commit message
soliloquy, and compile-testing on evbppc/i386/earmv7hf, by me.
 1.35 29-Jan-2020  thorpej branches: 1.35.10;
Adopt <net/if_stats.h>.
 1.34 03-Sep-2019  msaitoh branches: 1.34.2;
Use unsigned to avoid undefined behavior. Found by kUBSan.
 1.33 03-Sep-2018  riastradh branches: 1.33.4;
Rename min/max -> uimin/uimax for better honesty.

These functions are defined on unsigned int. The generic name
min/max should not silently truncate to 32 bits on 64-bit systems.
This is purely a name change -- no functional change intended.

HOWEVER! Some subsystems have

#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))

even though our standard name for that is MIN/MAX. Although these
may invite multiple evaluation bugs, these do _not_ cause integer
truncation.

To avoid `fixing' these cases, I first changed the name in libkern,
and then compile-tested every file where min/max occurred in order to
confirm that it failed -- and thus confirm that nothing shadowed
min/max -- before changing it.

I have left a handful of bootloaders that are too annoying to
compile-test, and some dead code:

cobalt ews4800mips hp300 hppa ia64 luna68k vax
acorn32/if_ie.c (not included in any kernels)
macppc/if_gm.c (superseded by gem(4))

It should be easy to fix the fallout once identified -- this way of
doing things fails safe, and the goal here, after all, is to _avoid_
silent integer truncations, not introduce them.

Maybe one day we can reintroduce min/max as type-generic things that
never silently truncate. But we should avoid doing that for a while,
so that existing code has a chance to be detected by the compiler for
conversion to uimin/uimax without changing the semantics until we can
properly audit it all. (Who knows, maybe in some cases integer
truncation is actually intended!)
 1.32 26-Jun-2018  msaitoh branches: 1.32.2;
Implement the BPF direction filter (BIOC[GS]DIRECTION). It provides backward
compatibility with BIOC[GS]SEESENT ioctl. The userland interface is the same
as FreeBSD.

This change also fixes a bug that the direction is misunderstand on some
environment by passing the direction to bpf_mtap*() instead of checking
m->m_pkthdr.rcvif.
 1.31 23-Jun-2018  maxv constify
 1.30 14-Jan-2018  maxv branches: 1.30.2;
Fix awful use of m_defrag, this code just can't work. And don't forget to
return the updated pointer, because otherwise use-after-free.

I couldn't test this change because I don't have the hardware.
 1.29 23-Oct-2017  msaitoh branches: 1.29.2;
If if_initialize() failed in the attach function, free resources and return.
 1.28 25-Jul-2017  maya enable rt2860 power management code

adjust to fit netbsd:
make suspend,resume functions match desired pmf* prototypes
remove wakeup/activate wrapper functions

avoid jumping to NULL on resume by initializing if_stop

the problem machine has other issues on resume, so there might be further
issues, but it's an improvement over a jump to NULL.

tested by Riccardo Mottola
 1.27 20-Jul-2017  maya Use kmem_free for kmem_alloc'd memory

Fixes diagnostic crash on detach, tested by Riccardo Mottola
 1.26 23-May-2017  ozaki-r branches: 1.26.2;
Apply deferred if_start to more drivers

And annotate some XXX_start as it runs in softint to clarify that
it doesn't need deferred if_start.
 1.25 02-Feb-2017  nonaka wlan interfaces make interrupt routine running on softint context.

see http://mail-index.netbsd.org/tech-kern/2016/12/06/msg021281.html

tested device:
* ath at pci: AR5212, AR5424
* athn at pci: AR9287
* ipw at pci: 2100BG
* iwi at pci: 2915ABG
* iwm at pci: 3165, 7260, 8260
* iwn at pci: 4945, 6235
* ral at pci: RT2560
* rtwn at pci: RTL8192CE
 1.24 08-Oct-2016  christos branches: 1.24.2;
sync antenna vals with OpenBSD, some changes from FreeBSD.
 1.23 27-Sep-2016  christos remove stray debugging, fix debugging message.
 1.22 27-Sep-2016  christos works, tested without privacy, wep and wpa. Soft crypto only for now.
 1.21 13-Jul-2016  christos branches: 1.21.2;
Use the proper channel for some things.
Remove debugging now that it all works.
 1.20 08-Jul-2016  christos more fixes.
 1.19 07-Jul-2016  christos kill RAL_DEBUG
 1.18 07-Jul-2016  christos add 539x support from FreeBSD (not working)
 1.17 24-Jun-2016  christos diff reduction with openbsd; turn debugging on.
 1.16 17-Jun-2016  christos ifdef out unused code.
 1.15 17-Jun-2016  christos disable hardware crypto for now.
 1.14 16-Jun-2016  riastradh Use m_set_rcvif, not M_SETCTX.

M_SETCTX is only for driver-private use of rcvif, whereas here we
really mean to set the receiving interface with m_set_rcvif.
 1.13 16-Jun-2016  nonaka use M_SETCTX() macro.
 1.12 16-Jun-2016  christos more conservating handling of memory.
 1.11 16-Jun-2016  christos fix mbuf handling; we don't crash anymore.
 1.10 26-May-2016  ozaki-r branches: 1.10.2;
Introduce M_CLEARCTX and use it instead of open-coding rcvif

No functional change.
 1.9 26-May-2016  ozaki-r Use M_GETCTX

No functional change.
 1.8 06-May-2016  christos misc cleanups.
 1.7 03-May-2016  christos minor nits
 1.6 02-May-2016  christos Make it look more like rt2560.c
 1.5 01-May-2016  nonaka Remove RAL_DEBUG define. Fix amd64 ALL kernel build failure.
 1.4 29-Apr-2016  christos remove in %s\n", __func__ debugging
 1.3 28-Apr-2016  christos Pass the proper device_t to the attach hook.
 1.2 27-Apr-2016  christos Make RT 2860 for the if_ral_pci.c driver compile.
This work was done by Jeff Rizzo
 1.1 26-Apr-2016  christos Unmodified OpenBSD sources (except Ids)
 1.10.2.7 28-Aug-2017  skrll Sync with HEAD
 1.10.2.6 05-Feb-2017  skrll Sync with HEAD
 1.10.2.5 05-Dec-2016  skrll Sync with HEAD
 1.10.2.4 05-Oct-2016  skrll Sync with HEAD
 1.10.2.3 09-Jul-2016  skrll Sync with HEAD
 1.10.2.2 29-May-2016  skrll Sync with HEAD
 1.10.2.1 26-May-2016  skrll file rt2860.c was added on branch nick-nhusb on 2016-05-29 08:44:21 +0000
 1.21.2.2 20-Mar-2017  pgoyette Sync with HEAD
 1.21.2.1 04-Nov-2016  pgoyette Sync with HEAD
 1.24.2.1 21-Apr-2017  bouyer Sync with HEAD
 1.26.2.3 10-Dec-2017  snj Pull up following revision(s) (requested by msaitoh in ticket #427):
sys/arch/amiga/dev/if_bah_zbus.c: 1.17
sys/arch/arm/broadcom/bcm53xx_eth.c: 1.30
sys/arch/powerpc/booke/dev/pq3etsec.c: 1.32
sys/arch/usermode/dev/if_veth.c: 1.9
sys/dev/ic/an.c: 1.66
sys/dev/ic/athn.c: 1.17
sys/dev/ic/atw.c: 1.162
sys/dev/ic/bwi.c: 1.33
sys/dev/ic/dwc_gmac.c: 1.41-1.42
sys/dev/ic/malo.c: 1.10
sys/dev/ic/rt2560.c: 1.31
sys/dev/ic/rt2661.c: 1.36
sys/dev/ic/rt2860.c: 1.29
sys/dev/ic/rtw.c: 1.127
sys/dev/ic/rtwvar.h: 1.46
sys/dev/ic/smc90cx6.c: 1.71
sys/dev/ic/smc90cx6var.h: 1.12
sys/dev/ic/wi.c: 1.244
sys/dev/pci/if_ipw.c: 1.66
sys/dev/pci/if_iwi.c: 1.104
sys/dev/pci/if_iwm.c: 1.76
sys/dev/pci/if_iwn.c: 1.86
sys/dev/pci/if_rtwn.c: 1.13
sys/dev/pci/if_wm.c: 1.541
sys/dev/pci/if_wpi.c: 1.79
sys/dev/pci/ixgbe/ixgbe.c: 1.106
sys/dev/pci/ixgbe/ixv.c: 1.73 via patch
sys/dev/pcmcia/if_malo_pcmcia.c: 1.15
sys/dev/scsipi/if_se.c: 1.95
sys/dev/usb/if_upl.c: 1.60
sys/net/if.c: 1.396
sys/net/if.h: 1.241
sys/net/if_arc.h: 1.23
sys/net/if_arcsubr.c: 1.78
sys/net/if_bridge.c: 1.136-1.137
sys/net/if_etherip.c: 1.39
sys/net/if_faith.c: 1.56
sys/net/if_gif.c: 1.131
sys/net/if_loop.c: 1.96
sys/net/if_mpls.c: 1.30
sys/net/if_pppoe.c: 1.129
sys/net/if_srt.c: 1.27
sys/net/if_stf.c: 1.102
sys/net/if_tap.c: 1.100
sys/net/if_vlan.c: 1.105
sys/netinet/ip_carp.c: 1.91
sys/rump/net/lib/libshmif/if_shmem.c: 1.73-1.74
sys/rump/net/lib/libvirtif/if_virt.c: 1.55-1.56
if_initalize() and if_attach() failed when resource allocation failed
(e.g. allocating softint). Without this change, it panics. It's bad because
resource shortage really occured when a lot of pseudo interface is created.
To avoid this problem, don't panic and change return value of if_initialize()
and if_attach() to int. Caller fanction will be recover from error cleanly by
checking the return value.
Return if bah_attach_subr() failed.
If if_attach() failed in the attach function, return.
- If if_initialize() failed in the attach function, free resources and return.
- Add some missing frees in bridge_clone_destroy().
- KNF
If error occured in bcmeth_ccb_attach(), free resources and return.
If error occured in pq3etsec_attach(), free resources and return.
If error occured in the attach function, free resources and return.
- If if_initialize() failed in athn_attach(), free resources and return.
- Add missing pmf_event_deregister() in athn_detach().
- Free resources correctly on some errors in atw_attach().
- Use apint*() insread of printf() in the attach function.
If if_initialize() failed in the attach function, return.
- If if_initialize() failed in the attach function, free resources and return.
- Add missing dwc_gmac_free_dma_rings() and mutex_destroy() when attach
failed.
- If if_initialize() failed in the attach function, free resources and return.
- ifp is always not NULL in iwi_detach(). Check correctly with ifp->if_softc.
- If if_initialize() failed in the attach function, free resources and return.
- Fix error path in the attach function correctly.
If if_initialize() failed in the attach function, free resources and return.
If if_attach() failed in the attach function, free resources and return.
- If if_initialize() failed in the attach function, free resources and return.
- KNF
- If if_attach() failed in the attach function, free resources and return.
- KNF
Fix compile error.
Fix compile error.
We don't need '&mii', but just 'mii' for mii_detach().
Don't free sc_rthash twice
 1.26.2.2 01-Aug-2017  snj Pull up following revision(s) (requested by maya in ticket #162):
sys/dev/pci/if_ral_pci.c: revision 1.24
sys/dev/ic/rt2860.c: revision 1.28
sys/dev/ic/rt2860var.h: revision 1.5
enable rt2860 power management code
adjust to fit netbsd:
make suspend,resume functions match desired pmf* prototypes
remove wakeup/activate wrapper functions
avoid jumping to NULL on resume by initializing if_stop
the problem machine has other issues on resume, so there might be further
issues, but it's an improvement over a jump to NULL.
tested by Riccardo Mottola
 1.26.2.1 25-Jul-2017  snj Pull up following revision(s) (requested by maya in ticket #150):
sys/dev/ic/rt2860.c: revision 1.27
Use kmem_free for kmem_alloc'd memory
Fixes diagnostic crash on detach, tested by Riccardo Mottola
 1.29.2.2 03-Dec-2017  jdolecek update from HEAD
 1.29.2.1 23-Oct-2017  jdolecek file rt2860.c was added on branch tls-maxphys on 2017-12-03 11:37:04 +0000
 1.30.2.3 06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.30.2.2 28-Jul-2018  pgoyette Sync with HEAD
 1.30.2.1 25-Jun-2018  pgoyette Sync with HEAD
 1.32.2.3 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.32.2.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.32.2.1 10-Jun-2019  christos Sync with HEAD
 1.33.4.1 31-Jan-2020  martin Pull up following revision(s) (requested by msaitoh in ticket #671):

sys/dev/pci/if_bce.c: revision 1.53
sys/dev/pci/pccbbreg.h: revision 1.16
sys/dev/ic/rt2860.c: revision 1.34
sys/dev/pci/if_alc.c: revision 1.45
sys/dev/pci/if_mcx.c: revision 1.5
sys/dev/pci/if_pcn.c: revision 1.72
sys/dev/pci/if_ale.c: revision 1.37
sys/dev/pci/if_age.c: revision 1.65
sys/dev/ieee1394/fwohcireg.h: revision 1.20
sys/dev/ieee1394/fwohci.c: revision 1.143
sys/dev/ieee1394/firewire.c: revision 1.49
sys/dev/ic/am79900reg.h: revision 1.10

Use unsigned to avoid undefined behavior. Found by kUBSan.
 1.34.2.1 29-Feb-2020  ad Sync with head.
 1.35.10.1 17-Jun-2021  thorpej Sync w/ HEAD.
 1.7 08-Oct-2016  christos sync antenna vals with OpenBSD, some changes from FreeBSD.
 1.6 16-Sep-2016  mlelstv Merge enough FreeBSD code to make RT5592 work.
 1.5 08-Jul-2016  christos branches: 1.5.2;
more fixes.
 1.4 07-Jul-2016  christos add 539x support from FreeBSD (not working)
 1.3 27-Apr-2016  christos Make RT 2860 for the if_ral_pci.c driver compile.
This work was done by Jeff Rizzo
 1.2 26-Apr-2016  christos Unmodified OpenBSD sources (except Ids)
 1.1 30-May-2012  nonaka branches: 1.1.2; 1.1.4; 1.1.6; 1.1.20;
Add a driver for Ralink Technology RT2700U/RT2800U/RT3000U USB IEEE
802.11a/b/g/n wireless network devices, ported from OpenBSD by FUKAUMI Naoki,
arranged by me.
 1.1.20.4 05-Dec-2016  skrll Sync with HEAD
 1.1.20.3 05-Oct-2016  skrll Sync with HEAD
 1.1.20.2 09-Jul-2016  skrll Sync with HEAD
 1.1.20.1 29-May-2016  skrll Sync with HEAD
 1.1.6.2 30-Oct-2012  yamt sync with head
 1.1.6.1 30-May-2012  yamt file rt2860reg.h was added on branch yamt-pagecache on 2012-10-30 17:21:08 +0000
 1.1.4.1 03-Dec-2017  jdolecek update from HEAD
 1.1.2.2 02-Jun-2012  mrg sync to latest -current.
 1.1.2.1 30-May-2012  mrg file rt2860reg.h was added on branch jmcneill-usbmp on 2012-06-02 11:09:17 +0000
 1.5.2.1 04-Nov-2016  pgoyette Sync with HEAD
 1.6 05-Oct-2019  mrg remove __packed attribute from struct ieee80211_radiotap_header
and all the structures that include it.

this should not change anything while avoiding packed vs alignment
warnings from GCC 8, and potentially pessimised code generation
due to the packed marker (there are no misaligned members, just
that the per-device parts may end unaligned.)

all consumers of these members are done from the properly aligned
packet members directly, or, as a union with a 64 byte member,
also properly aligned. codegen didn't appear to change, except
for the definition of sizeof(struct driver_[rt]x_radiotap_header)
in debug info, which is not directly used anywhere.
 1.5 25-Jul-2017  maya branches: 1.5.2; 1.5.6;
enable rt2860 power management code

adjust to fit netbsd:
make suspend,resume functions match desired pmf* prototypes
remove wakeup/activate wrapper functions

avoid jumping to NULL on resume by initializing if_stop

the problem machine has other issues on resume, so there might be further
issues, but it's an improvement over a jump to NULL.

tested by Riccardo Mottola
 1.4 02-Feb-2017  nonaka branches: 1.4.6;
wlan interfaces make interrupt routine running on softint context.

see http://mail-index.netbsd.org/tech-kern/2016/12/06/msg021281.html

tested device:
* ath at pci: AR5212, AR5424
* athn at pci: AR9287
* ipw at pci: 2100BG
* iwi at pci: 2915ABG
* iwm at pci: 3165, 7260, 8260
* iwn at pci: 4945, 6235
* ral at pci: RT2560
* rtwn at pci: RTL8192CE
 1.3 08-Jul-2016  christos branches: 1.3.2; 1.3.4;
more fixes.
 1.2 27-Apr-2016  christos branches: 1.2.2;
Make RT 2860 for the if_ral_pci.c driver compile.
This work was done by Jeff Rizzo
 1.1 26-Apr-2016  christos Unmodified OpenBSD sources (except Ids)
 1.2.2.5 28-Aug-2017  skrll Sync with HEAD
 1.2.2.4 05-Feb-2017  skrll Sync with HEAD
 1.2.2.3 09-Jul-2016  skrll Sync with HEAD
 1.2.2.2 29-May-2016  skrll Sync with HEAD
 1.2.2.1 27-Apr-2016  skrll file rt2860var.h was added on branch nick-nhusb on 2016-05-29 08:44:21 +0000
 1.3.4.1 21-Apr-2017  bouyer Sync with HEAD
 1.3.2.1 20-Mar-2017  pgoyette Sync with HEAD
 1.4.6.1 01-Aug-2017  snj Pull up following revision(s) (requested by maya in ticket #162):
sys/dev/pci/if_ral_pci.c: revision 1.24
sys/dev/ic/rt2860.c: revision 1.28
sys/dev/ic/rt2860var.h: revision 1.5
enable rt2860 power management code
adjust to fit netbsd:
make suspend,resume functions match desired pmf* prototypes
remove wakeup/activate wrapper functions
avoid jumping to NULL on resume by initializing if_stop
the problem machine has other issues on resume, so there might be further
issues, but it's an improvement over a jump to NULL.
tested by Riccardo Mottola
 1.5.6.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.5.2.2 03-Dec-2017  jdolecek update from HEAD
 1.5.2.1 25-Jul-2017  jdolecek file rt2860var.h was added on branch tls-maxphys on 2017-12-03 11:37:04 +0000
 1.19 31-Dec-2023  isaki ne(4): Write CR0 properly.
Writing 0b000 to RD2-0 in CR0 appears harmless, but it is "not allowed"
by the RTL8019AS (and several NE2000 derived) datasheets.
 1.18 25-Apr-2019  msaitoh KNF. No functional change.
 1.17 25-Apr-2019  msaitoh No functional change:
- Use __arraycount().
- u_int_{8,16,32}_t -> uint_{8,16,32}_t
- KNF.
- Tabify.
- Remove extra space.
 1.16 16-Jun-2014  msaitoh branches: 1.16.28;
IFM_FDX and IFM_HDX use different bit, so set IFM_HDX bit if it's not full
duplex. For many drivers, it recognize half duplex if IFM_FDX isn't set,
but not for others. Same as {Free|Open}BSD.
 1.15 14-Mar-2009  dsl branches: 1.15.18; 1.15.22; 1.15.36;
Change about 4500 of the K&R function definitions to ANSI ones.
There are still about 1600 left, but they have ',' or /* ... */
in the actual variable definitions - which my awk script doesn't handle.
There are also many that need () -> (void).
(The script does handle misordered arguments.)
 1.14 28-Apr-2008  martin branches: 1.14.8; 1.14.14;
Remove clause 3 and 4 from TNF licenses
 1.13 12-Mar-2008  cube branches: 1.13.2; 1.13.4;
Split device_t and softc for the NE2000 Ethernet chip and all its variants
and attachments. Use device_t accessors, correct types, and ANSIfy when
appropriate.
 1.12 19-Oct-2007  ad branches: 1.12.12; 1.12.16;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.11 11-Dec-2005  christos branches: 1.11.30; 1.11.44; 1.11.46; 1.11.50;
merge ktrace-lwp.
 1.10 28-Oct-2003  mycroft branches: 1.10.16;
Kill another bogus initializer.
 1.9 25-Oct-2003  christos Fix uninitialized variable warnings
 1.8 13-Nov-2001  lukem branches: 1.8.16;
add/cleanup RCSID
 1.7 08-Jul-2001  thorpej branches: 1.7.2;
Remove unnecessary include files, from Onno van der Linden.
 1.6 12-Jun-2001  thorpej Don't need INET or NS includes here.
 1.5 12-Feb-2001  thorpej branches: 1.5.2;
Adjust the way that media is initialized on DP8390-compatible
chips. The dp8390_softc now has media_init and media_fini
function pointers that do the work.
 1.4 28-Apr-2000  is change 10base-t media _setting_ to set autodetect instead.
Contrary to what the rtl8019 docs say, this seems to be necessary.
Observed by myself when implementing non-auto earlier, and independently
complained about by Antti Kante in PR 9962.
 1.3 03-Mar-2000  is - we didn't write enable toe config1-3 registers before trying to set the
media.
- read out original settings to find out what the defaults (EEPROM) for this
board were, instad of hardwiring to auto.
XXX the first might need further refinement. At least on my boards, 10baseT
doesn't work for 10baseT, only AUTO.
 1.2 08-Nov-1998  veego branches: 1.2.4; 1.2.12;
We don't need the pci headers here.
 1.1 31-Oct-1998  thorpej Code common to RealTek 8019 and 8029 NE2000-compatible Ethernet chips.
Includes media selection support and support for Full-duplex.
 1.2.12.2 12-Mar-2001  bouyer Sync with HEAD.
 1.2.12.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.2.4.1 11-Dec-1998  kenh The beginnings of interface detach support. Still some bugs, but mostly
works for me.

This work was originally by Bill Studenmund, and cleaned up by me.
 1.5.2.3 14-Nov-2001  nathanw Catch up to -current.
 1.5.2.2 24-Aug-2001  nathanw Catch up with -current.
 1.5.2.1 21-Jun-2001  nathanw Catch up to -current.
 1.7.2.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.8.16.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.8.16.2 18-Sep-2004  skrll Sync with HEAD.
 1.8.16.1 03-Aug-2004  skrll Sync with HEAD
 1.10.16.2 17-Mar-2008  yamt sync with head.
 1.10.16.1 27-Oct-2007  yamt sync with head.
 1.11.50.1 25-Oct-2007  bouyer Sync with HEAD.
 1.11.46.2 23-Mar-2008  matt sync with HEAD
 1.11.46.1 06-Nov-2007  matt sync with HEAD
 1.11.44.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.11.30.1 23-Oct-2007  ad Sync with head.
 1.12.16.2 02-Jun-2008  mjf Sync with HEAD.
 1.12.16.1 03-Apr-2008  mjf Sync with HEAD.
 1.12.12.1 24-Mar-2008  keiichi sync with head.
 1.13.4.2 04-May-2009  yamt sync with head.
 1.13.4.1 16-May-2008  yamt sync with head.
 1.13.2.1 18-May-2008  yamt sync with head.
 1.14.14.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.14.8.1 28-Apr-2009  skrll Sync with HEAD.
 1.15.36.1 10-Aug-2014  tls Rebase.
 1.15.22.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.15.18.1 09-Nov-2014  martin Pull up following revision(s) (requested by msaitoh in ticket #1189):
sys/dev/pci/if_wm.c: revision 1.270
sys/dev/mii/inphy.c: revision 1.53
sys/dev/mii/glxtphy.c: revision 1.24
sys/dev/mii/tlphy.c: revision 1.62
sys/dev/mii/iophy.c: revision 1.37
sys/dev/mii/brgphy.c: revision 1.70
sys/dev/mii/ihphy.c: revision 1.8
sys/dev/mii/bmtphy.c: revision 1.31
sys/dev/mii/urlphy.c: revision 1.30
sys/dev/mii/makphy.c: revision 1.40
sys/dev/mii/qsphy.c: revision 1.48
sys/dev/mii/igphy.c: revision 1.23
sys/dev/mii/nsphy.c: revision 1.58
sys/dev/mii/mvphy.c: revision 1.10
sys/dev/pci/if_txp.c: revision 1.41
sys/dev/mii/nsphy.c: revision 1.59
sys/dev/mii/rlphy.c: revision 1.28
sys/dev/mii/icsphy.c: revision 1.49
sys/dev/mii/rlphy.c: revision 1.29
sys/dev/mii/lxtphy.c: revision 1.49
sys/dev/mii/ciphyreg.h: revision 1.5
sys/dev/mii/nsphyter.c: revision 1.38
sys/dev/mii/sqphy.c: revision 1.50
sys/dev/mii/gentbi.c: revision 1.26
sys/dev/mii/gentbi.c: revision 1.27
sys/dev/mii/tqphy.c: revision 1.39
sys/dev/mii/ikphy.c: revision 1.10
sys/dev/mii/dmphy.c: revision 1.35
sys/dev/mii/amhphy.c: revision 1.20
sys/dev/mii/acphy.c: revision 1.24
sys/dev/mii/ciphy.c: revision 1.25
sys/dev/mii/brgphyreg.h: revision 1.8
sys/dev/mii/ukphy_subr.c: revision 1.12
sys/dev/ic/rtl80x9.c: revision 1.16
sys/arch/mips/adm5120/dev/if_admsw.c: revision 1.12
sys/dev/pci/if_kse.c: revision 1.28
sys/dev/mii/ukphy_subr.c: revision 1.13
sys/dev/mii/mii.h: revision 1.18
sys/dev/mii/gphyter.c: revision 1.29
No functional change:
- Fix typo.
- Remove trailing white spaces.
- Capitalize comments.
- Tabify.
- KNF.
IFM_FDX and IFM_HDX use different bit, so set IFM_HDX bit if it's not full
duplex. For many drivers, it recognize half duplex if IFM_FDX isn't set,
but not for others. Same as {Free|Open}BSD.
 1.16.28.1 10-Jun-2019  christos Sync with HEAD
 1.7 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.6 11-Dec-2005  christos branches: 1.6.70; 1.6.72; 1.6.74;
merge ktrace-lwp.
 1.5 27-Feb-2005  perry nuke trailing whitespace
 1.4 13-Feb-2004  wiz branches: 1.4.8; 1.4.10;
RealTek -> Realtek.
 1.3 02-Nov-2003  wiz Fix some typos. From Tom Cosgrove via jmc@openbsd.
 1.2 31-Oct-1998  thorpej branches: 1.2.46;
Multiple inclusion protection.
 1.1 31-Oct-1998  thorpej Move the RTL8029 register definitions to <dev/ic/rtl80x9reg.h>, and add
the registers/bits present in the RTL8019 (ISA version).
 1.2.46.4 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.2.46.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.2.46.2 18-Sep-2004  skrll Sync with HEAD.
 1.2.46.1 03-Aug-2004  skrll Sync with HEAD
 1.4.10.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.4.8.1 29-Apr-2005  kent sync with -current
 1.6.74.1 16-May-2008  yamt sync with head.
 1.6.72.1 18-May-2008  yamt sync with head.
 1.6.70.1 02-Jun-2008  mjf Sync with HEAD.
 1.6 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.5 11-Dec-2005  christos branches: 1.5.70; 1.5.72; 1.5.74;
merge ktrace-lwp.
 1.4 04-Feb-2005  perry de-__P
 1.3 13-Feb-2004  wiz branches: 1.3.8; 1.3.10;
RealTek -> Realtek.
 1.2 12-Feb-2001  thorpej branches: 1.2.24;
Adjust the way that media is initialized on DP8390-compatible
chips. The dp8390_softc now has media_init and media_fini
function pointers that do the work.
 1.1 31-Oct-1998  thorpej branches: 1.1.12;
Code common to RealTek 8019 and 8029 NE2000-compatible Ethernet chips.
Includes media selection support and support for Full-duplex.
 1.1.12.1 12-Mar-2001  bouyer Sync with HEAD.
 1.2.24.4 04-Feb-2005  skrll Sync with HEAD.
 1.2.24.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.2.24.2 18-Sep-2004  skrll Sync with HEAD.
 1.2.24.1 03-Aug-2004  skrll Sync with HEAD
 1.3.10.1 12-Feb-2005  yamt sync with head.
 1.3.8.1 29-Apr-2005  kent sync with -current
 1.5.74.1 16-May-2008  yamt sync with head.
 1.5.72.1 18-May-2008  yamt sync with head.
 1.5.70.1 02-Jun-2008  mjf Sync with HEAD.
 1.179 12-Aug-2024  christos fix whitespace
 1.178 12-Aug-2024  christos PR/58588: Christos Zoulas: Avoid crashes when exiting promiscuous mode (^C
tcpdump) by disabling RX in re_stop. Also add some earlyoff stuff while here.
From FreeBSD.
 1.177 05-Jul-2024  rin sys: Drop redundant NULL check before m_freem(9)

m_freem(9) safely has accepted NULL argument at least since 4.2BSD:
https://www.tuhs.org/cgi-bin/utree.pl?file=4.2BSD/usr/src/sys/sys/uipc_mbuf.c

Compile-tested on amd64/ALL.

Suggested by knakahara@
 1.176 29-Jun-2024  riastradh branches: 1.176.2;
if_stats(9): Add ifp argument to if_stat..._ref.

This will enable us to pass the ifp through to a dtrace probe inside.

No functional change intended in this change, but this is an API
change visible to modules so it shouldn't be pulled up.

PR kern/58377
 1.175 25-Sep-2022  thorpej Remove unnecessary include of <sys/malloc.h>.
 1.174 01-Aug-2022  mlelstv Revert last accidental commits.
 1.173 01-Aug-2022  mlelstv Also fix shift values for SCT constants.
 1.172 25-Jun-2022  tsutsui Pass proper status values to rnd_add_uint32(9) as rnd(9) man page claims.
 1.171 24-May-2022  andvar fix various typos in comment, documentation and log messages.
 1.170 27-Jan-2022  jakllsch drop poorly phrased and redundant message about unsupported chip revisions
 1.169 31-Dec-2021  riastradh sys: Use if_init wrapper function.

Exception: Not in kern_pmf.c, for the kind of silly reason that it
avoids having kern_pmf.c refer to symbols defined only in net; this
avoids a pain in the rump.
 1.168 04-Sep-2021  jakllsch re(4): misc chip revision support changes
* remove impossible-to-match chip revision cases
* bring support for modern chips in line with FreeBSD and OpenBSD
* adds support for RTL8168GU

Addresses PR kern/56312.
 1.167 21-Sep-2020  msaitoh - Print chip revision. From OpenBSD.
- Rename RTK_HWREV_8168_SPIN[123] to RTK_HWREV_8168'B'_SPIN[123].
Same as other *BSDs.
- Rename RTK_HWREV_8168G_SPIN4 to RTK_HWREV_8411B. Same as other *BSDs.
- Add definition of RTK_HWREV_8169_8110SCE.
 1.166 13-Mar-2020  thorpej Use BUS_ADDR_{LO,HI}32().
 1.165 12-Mar-2020  thorpej Add support for MBUFTRACE.
 1.164 07-Feb-2020  thorpej Use callout_setfunc() / callout_schedule().
 1.163 04-Feb-2020  thorpej Use ifmedia_fini().
 1.162 29-Jan-2020  thorpej Adopt <net/if_stats.h>.
 1.161 17-Dec-2019  msaitoh branches: 1.161.2;
Improve some chip revisions support:

- Add 8168FP, 8411, 8168G, 8401E, 8105E, 8105E_SPIN1, 8106E and 8402 from
{Free,Open}BSD.
- Renumber RTK_HWREV_8103E from 0x24C00000 to 0x34c00000. 0x24C00000 is newly
used as RTK_HWREV_8102EL_SPIN1. Same as {Free,Open}BSD.
 1.160 22-Sep-2019  ryo 8168H model didn't link up well. some models seems to require to enable TX/RX after configuration.
RTKQ_TXRXEN_LATER quirk flag added. it may be able to unify with RTKQ_RXDV_GATED flag?
 1.159 30-May-2019  msaitoh branches: 1.159.2;
Simplify MII structure initialization and reference. No functional change.
 1.158 05-Apr-2019  uwe RTK_CFG2_BUSFREQ is only 1 byte. Fixes panic on landisk.
 1.157 22-Jan-2019  msaitoh Change MII PHY read/write API from:

int (*mii_readreg_t)(device_t, int, int);
void (*mii_writereg_t)(device_t, int, int, int);
to:

int (*mii_readreg_t)(device_t, int, int, uint16_t *);
int (*mii_writereg_t)(device_t, int, int, uint16_t);

Now we can test if a read/write operation failed or not by the return value.

In 802.3 spec says that the PHY shall not respond to read/write transaction
to the unimplemented register(22.2.4.3). Detecting timeout can be used to
check whether a register is implemented or not (if the register conforms to
the spec). ukphy(4) can be used this for MII_MMDACR and MII_MMDAADR.

Note that I noticed that the following code do infinite loop in the
read/wirte function. If it accesses unimplemented PHY register, it will hang.
It should be fixed:

arm/at91/at91emac.c
arm/ep93xx/epe.c
arm/omap/omapl1x_emac.c
mips/ralink/ralink_eth.c
arch/powerpc/booke/dev/pq3etsec.c(read)
dev/cadence/if_cemac.c <- hkenken
dev/ic/lan9118.c


Tested with the following device:

axe+ukphy
axe+rgephy
axen+rgephy (tested by Andrius V)
wm+atphy
wm+ukphy
wm+igphy
wm+ihphy
wm+makphy
sk+makphy
sk+brgphy
sk+gentbi
msk+makphy
sip+icsphy
sip+ukphy
re+rgephy
bge+brgphy
bnx+brgphy
gsip+gphyter
rtk+rlphy
fxp+inphy (tested by Andrius V)
tlp+acphy
ex+exphy
epic+qsphy
vge+ciphy (tested by Andrius V)
vr+ukphy (tested by Andrius V)
vte+ukphy (tested by Andrius V)

Not tested (MAC):
arm:at91emac
arm:cemac
arm:epe
arm:geminigmac
arm:enet
arm:cpsw
arm:emac(omac)
arm:emac(sunxi)
arm:npe
evbppc:temac
macppc:bm
macppc:gm
mips:aumac
mips:ae
mips:cnmac
mips:reth
mips:sbmac
playstation2:smap
powerpc:tsec
powerpc:emac(ibm4xx)
sgimips:mec
sparc:be
sf
ne(ax88190, dl10019)
awge
ep
gem
hme
smsh
mtd
sm
age
alc
ale
bce
cas
et
jme
lii
nfe
pcn
ste
stge
tl
xi
aue
mue
smsc
udav
url

Not tested (PHY):
amhphy
bmtphy
dmphy
etphy
glxtphy
ikphy
iophy
lxtphy
nsphyter
pnaphy
rdcphy
sqphy
tlphy
tqphy
urlphy
 1.156 10-Jan-2019  mlelstv Fix handling of RTKQ_IM_HW quirk, the check was inverted.

Found by tho@useless-ficus.net, thanks.
Fixes PR/53858.
 1.155 13-Nov-2018  mlelstv compute interrupt timer depending on bus clock.
 1.154 26-Jun-2018  msaitoh branches: 1.154.2;
Implement the BPF direction filter (BIOC[GS]DIRECTION). It provides backward
compatibility with BIOC[GS]SEESENT ioctl. The userland interface is the same
as FreeBSD.

This change also fixes a bug that the direction is misunderstand on some
environment by passing the direction to bpf_mtap*() instead of checking
m->m_pkthdr.rcvif.
 1.153 01-Jun-2018  maxv Use m_remove_pkthdr() instead of "&= ~M_PKTHDR", to ensure the tags get
freed. Several other drivers have this problem it seems...
 1.152 26-Sep-2017  knakahara branches: 1.152.2;
VLAN ID uses pkthdr instead of mtag now. Contributed by s-yamaguchi@IIJ.

I just commit by proxy. Reviewed by joerg@n.o and christos@n.o, thanks.
See http://mail-index.netbsd.org/tech-net/2017/09/26/msg006459.html

XXX need pullup to -8 branch
 1.151 16-May-2017  snj branches: 1.151.2;
fix inverted logic.

spotted by "sc dying" on current-users.
 1.150 19-Apr-2017  jmcneill branches: 1.150.2;
Performance improvements for PCIe and 8168 based devices:
- When using the countdown timer for interrupt moderation on PCIe devices,
use a timer rate value based on a 125MHz PCIe reference clock instead of
33 MHz.
- For 8168 based devices, ditch the countdown timer and instead use the
(undocumented) hardware interrupt moderation feature.
- Support TSOv4 on 8168D and later devices.
 1.149 20-Feb-2017  ozaki-r Fix assertion failure in bpf_mtap by applying deferred if_start to re(4)

Reported by maya@
 1.148 15-Dec-2016  ozaki-r branches: 1.148.2;
Move bpf_mtap and if_ipackets++ on Rx of each driver to percpuq if_input

The benefits of the change are:
- We can reduce codes
- We can provide the same behavior between drivers
- Where/When if_ipackets is counted up
- Note that some drivers still update packet statistics in their own
way (periodical update)
- Moved bpf_mtap run in softint
- This makes it easy to MP-ify bpf

Proposed on tech-kern and tech-net
 1.147 10-Jun-2016  ozaki-r branches: 1.147.2;
Introduce m_set_rcvif and m_reset_rcvif

The API is used to set (or reset) a received interface of a mbuf.
They are counterpart of m_get_rcvif, which will come in another
commit, hide internal of rcvif operation, and reduce the diff of
the upcoming change.

No functional change.
 1.146 09-Feb-2016  ozaki-r Introduce softint-based if_input

This change intends to run the whole network stack in softint context
(or normal LWP), not hardware interrupt context. Note that the work is
still incomplete by this change; to that end, we also have to softint-ify
if_link_state_change (and bpf) which can still run in hardware interrupt.

This change softint-ifies at ifp->if_input that is called from
each device driver (and ieee80211_input) to ensure Layer 2 runs
in softint (e.g., ether_input and bridge_input). To this end,
we provide a framework (called percpuq) that utlizes softint(9)
and percpu ifqueues. With this patch, rxintr of most drivers just
queues received packets and schedules a softint, and the softint
dequeues packets and does rest packet processing.

To minimize changes to each driver, percpuq is allocated in struct
ifnet for now and that is initialized by default (in if_attach).
We probably have to move percpuq to softc of each driver, but it's
future work. At this point, only wm(4) has percpuq in its softc
as a reference implementation.

Additional information including performance numbers can be found
in the thread at tech-kern@ and tech-net@:
http://mail-index.netbsd.org/tech-kern/2016/01/14/msg019997.html

Acknowledgment: riastradh@ greatly helped this work.
Thank you very much!
 1.145 28-Aug-2015  nonaka Add support for Realtek RTL8168H/8111H variant.
 1.144 13-Apr-2015  riastradh Convert sys/dev to use <sys/rndsource.h>.
 1.143 22-Nov-2014  joerg branches: 1.143.2;
Drop unnecessary-but-harmful casts.
 1.142 14-Oct-2014  uwe RealTek 8139C+ incorrectly identifies UDP checksum 0xffff as bad.
Force software recalculation of UDP checksum if bad checksum is
reported by the hardware.
 1.141 10-Oct-2014  christos PR/49259: J. Lorec: Add support for Realtek 8111G chipset into re(4)
 1.140 10-Aug-2014  tls branches: 1.140.2;
Merge tls-earlyentropy branch into HEAD.
 1.139 10-May-2013  tsutsui branches: 1.139.6;
Add RNG entropy collection support of rnd(9) to re(4).
Taken from rtk(4), and briefly checked by rndctl(8).
 1.138 10-May-2013  tsutsui Make re(4) driver always use IDR register values for its MAC address.

Some sandpoint NAS firmwares set MAC address per their
firmware settings and don't use re(4)'s EEPROM values.
Per rtl8169 manuals re(4) chip reads EEPROM automatically after
hardware reset and Linux driver also uses IDR registers,
so this change should not affect existing other boards
which actually have vaild EEPROM.

Per discussion in old tech-kern@ thread:
http://mail-index.netbsd.org/tech-kern/2012/12/01/msg014573.html
Note rtl81x9.c is still shared among rtk(4) only for a multicast function
(to avoid boring refactoring work).
 1.137 06-Apr-2013  khorben Added support for the Realtek 8168F variant in re(4).

From FreeBSD; not tested on real hardware unfortunately. The manual page was adjusted as well.

No objection from current-users@, "commit it" gdt@
 1.136 22-Jul-2012  matt branches: 1.136.2;
Fix mii_statchg to take a 'struct ifnet *' instead of device_t. This fixes
problem with a common MDIO bus used for multiple interfaces.
Some drivers converted to CFATTACL_DECL_NEW.
 1.135 02-Mar-2012  nonaka Added RTL8168E/8111E-VL support.
 1.134 22-Nov-2011  garbled branches: 1.134.2; 1.134.4;
Add support to recognize the 8168E model of this chip. Taken from FreeBSD
 1.133 28-Jul-2010  msaitoh branches: 1.133.8;
The ETHERCAP_VLAN_HWTAGGING flag is not a member of if_cap but ec_cap,
so fix it.
 1.132 27-Jul-2010  jakllsch Make the Realtek PCI network interfaces detachable.
Use __arraycount to avoid null table entries.
Miscellaneous other touch-ups in bus front-ends.
 1.131 09-Apr-2010  nonaka Added 8110SBL support.
 1.130 05-Apr-2010  joerg Push the bpf_ops usage back into bpf.h. Push the common ifp->if_bpf
check into the inline functions as well the fourth argument for
bpf_attach.
 1.129 19-Jan-2010  pooka branches: 1.129.2; 1.129.4;
Redefine bpf linkage through an always present op vector, i.e.
#if NBPFILTER is no longer required in the client. This change
doesn't yet add support for loading bpf as a module, since drivers
can register before bpf is attached. However, callers of bpf can
now be modularized.

Dynamically loadable bpf could probably be done fairly easily with
coordination from the stub driver and the real driver by registering
attachments in the stub before the real driver is loaded and doing
a handoff. ... and I'm not going to ponder the depths of unload
here.

Tested with i386/MONOLITHIC, modified MONOLITHIC without bpf and rump.
 1.128 15-Sep-2009  dyoung Simplify activation routines: do not call mii_activate(), it is a
no-op. Do not block interrupts, if_deactivate() will take care of
that for us.
 1.127 05-Sep-2009  tsutsui Remove one more extra whitespace.
 1.126 05-Sep-2009  tsutsui Remove unnecessary whitespace.
 1.125 02-Sep-2009  tsutsui Move pmf(9) calls to MI re_attach() and re_detach() from each backend.
 1.124 31-Aug-2009  tsutsui Treat 8168DP as well as 8168C/CP/D. From FreeBSD.
 1.123 29-Aug-2009  tsutsui - no need to include "vlan.h" since no NVLAN reference
- whitespace in comment
 1.122 27-Aug-2009  tsutsui Remove an unnecessary assignment. No binary change.
 1.121 31-May-2009  tsutsui Two fixes for RX hwcsum on DESCV2 chips:
* On checking TCPv4/UDPv4 RX checksum on DESCV2 chips, also check
RE_RDESC_VLANCTL_IPV4 bit because those DESCV2 chips may also recognize
IPv6 packets and set RE_PROTOID_TCPIP or RE_PROTOID_UDPIP bits for
TCPv6/UDPv6 packets. This may fix PR kern/40605.
* According to Realtek's Linux driver, DESCV2 chips don't set RE_PROTOID_IP
for non-TCP/UDP IP packets (set only RE_RDESC_VLANCTL_IPV[46]) so
remove PROTOID check for IPv4 RX cheksum on DESCV2 chips.
 1.120 12-May-2009  cegger struct device * -> device_t, no functional changes intended.
 1.119 11-May-2009  tsutsui - rename RTK_HWREV_8102EL_SPIN2 -> RTK_HWREV_8103E
- add a HWREV value for 8168DP
Per Realtek's Linux drivers.
 1.118 03-May-2009  tsutsui Remove unused sc_rev settings (all quirks are handled by sc_quirk)
and merge HWREV cases which have the same quirks.
 1.117 29-Apr-2009  tsutsui Pull some changes for newer chips from FreeBSD:
- pull MACSTAT and CMDSTOP quirks for 8168/8111 chips
- always set CPLUSCMD_PCI_MRW on reset
- set VLANSTRIP and RXCSUM_ENB bits on CPLUS register per if_capenable

Tested on 8111C and 8111D by several users, and
no bad side effect on my old 8169S.
 1.116 13-Apr-2009  tsutsui Assume an unknown HWREV chip has the same features with the latest one.
 1.115 13-Apr-2009  tsutsui Add HWREV of RTL8102EL variant. From FUKAUMI Naoki.
 1.114 13-Apr-2009  tsutsui Add HWREV values of RTL8168CP and RTL8168D. From FreeBSD.

XXX: needs more quirk handling after wakeup for newer chips.
 1.113 28-Mar-2009  tsutsui Fix another botch in hwcsum changes for PR kern/40955:
8168/8111/8168B/8111B doesn't have DESCV2.

Problem reported by Arto Huusko on current-users@.
 1.112 27-Mar-2009  tsutsui Check a correct bit for ip4csum-rx. Reported privately on PR kern/40955.
 1.111 21-Mar-2009  tsutsui Add another quirk flag which shows availability of EEPROM command register.

Now we can remove sc_rev which was intended to represent "MAC revision"
used in the Realtek driver.
 1.110 21-Mar-2009  tsutsui Add and use a new quirk flag to disable JUMBO MTU,
rather than checking sc_rev values.
 1.109 21-Mar-2009  tsutsui Add hardware checksum support for newer PCIe 8168/8111/8102 chips,
per device info taken from FreeBSD driver. Tested by snj@ on 8111C.

Should closes PR kern/40955.

Note on old 8169 chips IP hw csum must be enabled to use TCP/UDP hw csums,
but I'm not sure if these newer chips still have the same restriction.
 1.108 20-Mar-2009  tsutsui Access LDPS register in re_reset() only on 8169S single chip variants.
From OpenBSD and FreeBSD drivers via PR kern/41009, and
Realtek-supplied FreeBSD driver.
 1.107 03-Jan-2009  yamt branches: 1.107.2;
remove extra semicolons.
 1.106 08-Dec-2008  alc Add support for a 8168C/8111C revision

- also disable jumbo frame on this adapter following the FreeBSD driver
- merge redundant call to aprint_error_dev
 1.105 23-Aug-2008  tnn branches: 1.105.2; 1.105.4;
Add support for the Realtek 8102E/8102EL PCIe 10/100 Ethernet devices.
From FreeBSD.
 1.104 06-May-2008  tsutsui branches: 1.104.2; 1.104.6;
- use RTK_IDR[0-5] registers to get MAC address on RTL8168C
- change sc_rev numbers to match quirk numbers used in Realtek's driver
- tweak some register definitions
Taken from Realtek's FreeBSD driver.

Untested yet on 8168C, but no bad sideeffect on older chips.
 1.103 29-Apr-2008  tsutsui Fix a leakage on device_t/softc split. PR kern/38541 from HITOSHI OSADA.
 1.102 25-Apr-2008  tsutsui branches: 1.102.2;
Split device_t/softc for re(4) and rtk(4).
 1.101 18-Apr-2008  tsutsui - use aprint_*() variants only in functions called during autoconf(9)
- wrap long lines
 1.100 18-Apr-2008  joerg NetBSD has no such thing as DEVICE_POLLING, so remove it.
 1.99 08-Apr-2008  cegger branches: 1.99.2;
use aprint_*_dev and device_xname
 1.98 18-Mar-2008  tsutsui It looks vlan tag info must appear not only in the first descriptor
but in all descriptors of a multi-descriptor transmission attempt on re(4).

Problem was reported and fix was confirmed by Chris Brookes on tech-net.
Should also close PR kern/37959.
 1.97 14-Mar-2008  tsutsui Don't fetch DMA descriptor after BUS_DMASYNC_PREREAD op.
 1.96 07-Feb-2008  dyoung branches: 1.96.2; 1.96.6;
Start patching up the kernel so that a network driver always has
the opportunity to handle an ioctl before generic ifioctl handling
occurs. This will ease extending the kernel and sharing of code
between drivers.

First steps: Make the signature of ifioctl_common() match struct
ifinet->if_ioctl. Convert SIOCSIFCAP and SIOCSIFMTU to the new
ifioctl() regime, throughout the kernel.
 1.95 04-Feb-2008  tsutsui FreeBSD says "16 bits" comment about RTK_GTXSTART was incorrect.
Use CSR_WRITE_1() for it. (though the previous code also worked)
 1.94 03-Feb-2008  tsutsui No need to preserve RE_NTXDESC_RSVD on re_start().
 1.93 19-Jan-2008  dyoung Make many ethernet drivers share the common code for MII media
handling, ether_mediastatus() and ether_mediachange(). Check for
a non-ENXIO error return from mii_mediachg(). (ENXIO indicates
that a PHY is suspended.)

This patch shrinks the source code size by 979 lines. There was
a 5100-byte savings on the NetBSD/i386 kernel configuration, ALL.

I have made a few miscellaneous changes, too:

gem(4): use LIST_EMPTY(), LIST_FOREACH().
mtd(4): handle media ioctls, for a change!
axe(4): do not track link status in sc->axe_link any longer
nfe(4), aue(4), axe(4), udav(4), url(4): do not reset all PHYs
on a change of media

Except for the change to mtd(4), no functional changes are intended.

XXX This patch affects more architectures than I can feasibly
XXX compile and run. I have compiled macppc, sparc64, i386. I
XXX have run the patches on i386 boxen with bnx(4) and sip(4).
XXX Compiling and running on evbmips (MERAKI, ADM5120) is in
XXX progress.
 1.92 08-Jan-2008  joerg Short-cut interrupt processing if device has been suspended.
uvm_fault reported by xtraeme.
 1.91 11-Dec-2007  lukem use __KERNEL_RCSID()
 1.90 09-Dec-2007  jmcneill branches: 1.90.2;
Merge jmcneill-pm branch.
 1.89 19-Oct-2007  ad branches: 1.89.2; 1.89.4; 1.89.6;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.88 27-Aug-2007  dyoung branches: 1.88.2; 1.88.6;
Constify: use CLLADDR() instead of LLADDR() wherever possible.
 1.87 19-Aug-2007  tsutsui FALSE -> false, TRUE -> true
 1.86 09-Jul-2007  ad branches: 1.86.2; 1.86.6;
Merge some of the less invasive changes from the vmlocking branch:

- kthread, callout, devsw API changes
- select()/poll() improvements
- miscellaneous MT safety improvements
 1.85 10-May-2007  tsutsui Pull a fix for PCIe variants from FreeBSD's if_re.c rev 1.71:

> - With the PCIe devices, it looks issuing a TX command while there's
> already a transmission in progress doesn't have any effect. In other
> words, if you send two packets in rapid succession, the second one may
> end up sitting in the TX DMA ring until another transmit command is
> issued later in the future. Basically, if re_txeof() sees that there
> are still descriptors outstanding, it needs to manually resume the
> TX DMA channel by issuing another TX command to make sure all
> transmissions are flushed out. (The PCI devices seem to keep the
> TX channel moving until all descriptors have been consumed. I'm not
> sure why the PCIe devices behave differently.)
 1.84 21-Mar-2007  tsutsui Cleanup handling of quikrs on each RealTek chip:
- replace rtk_type member in rtk_softc which has chip types
with new rtk_quirk that represents quirks on each chip:
- RTKQ_8129 doesn't have internal MII (used in rtk(4))
- RTKQ_8139CPLUS has different register layout (for re(4))
- RTKQ_8169NONS (original 8169) requires some settings on init
- RTKQ_PCIE requires different settings in setmulti
so that we don't have to check each hwrev values or types everywhere
and newer variants will also work without changes if they don't
have other quirks
(sc_rev is unchenged for now for reference to the Realtek's driver)
- don't check hwrev register in re_pci_match() but check
only PCI_VENDER(), PCI_PRODUCT() and PCI_REVISION()
so that we no longer have to map pci space there
- add a new HWREV value for another 8168 variant
- try to map PCI mem space more properly
- remove (probably unneeded) ifp->if_baudrate initialization

Tested on a newer 8168 variant by Dennis den Brok on tech-kern,
and also tested on 8139 and 8169C on macppc, and 8139C+ on landisk
by me.
 1.83 04-Mar-2007  christos branches: 1.83.2; 1.83.4; 1.83.6;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.82 21-Feb-2007  thorpej Replace the Mach-derived boolean_t type with the C99 bool type. A
future commit will replace use of TRUE and FALSE with true and false.
 1.81 15-Feb-2007  tsutsui branches: 1.81.2;
Don't set RTK_CFG1_FULLDUPLEX bit in RTK_CFG1 register
since it's available only on RTL8129. From FreeBSD.

As defined in rtl81x9reg.h, bits of 0x80 and 0x40 in RTK_CFG1
seem to indicate LEDS0 and LEDS1 configuration initialized by
EEPROM settings, and they seem read only on my quick tests with
two 8169S based cards.
 1.80 15-Feb-2007  tsutsui Use new RTK_HWREV_8100E_SPIN2 macro. (missed in the previous)
 1.79 10-Feb-2007  tsutsui Clear IFF_OACTIVE in re_txeof() only if there are more than RE_TXDESC_RSVD
free TXDESCs. From FreeBSD, but I'm still wondering why we have to reserve
some free TXDESCs even on re_start().
 1.78 04-Feb-2007  tsutsui - check more hwrev and use HWREV_* macro. From Realtek driver
via Darrin B.Jewell.
XXX: maybe we should check this sc_rev on more place
- use RTK_TXCFG_HWREV (0x7cc00000) rather than 0x7c800000
to mask the hwrev value since bit 0x00400000 is used only by 8139D
which is not supported by this driver
- fix a tyop
 1.77 29-Jan-2007  tsutsui Fix EEPROM functions for RTL8169SC chips:

rtl81x9.c:
Increase delay on EEPROM access since EEPROM on RTL8169 based board
seems to require slower clock. Also use common EE_DELAY() macro.

rtl8169.c:
Use common rtk_read_eeprom() function to get Ethernet address on
8169 chips because EEMODE_AUTOLOAD command was a workaround on
original FreeBSD's driver and it doesn't work on 8169SC.

Problem reported and fix tested by Frank Lorenzen on current-users,
and also tested on 8139C with rtk(4) driver by me.
 1.76 26-Dec-2006  tsutsui Wrap a sanity check in re_newbuf() with #ifdef DIAGNOSTIC and
make it fatal on failure.
 1.75 26-Dec-2006  tsutsui Use __predict_false() in several conditionals.
 1.74 16-Dec-2006  tsutsui Fix and reenable HW VLAN tagging on re(4):
- clear re_vlanctl in DMA descriptors before starting TX and RX
to avoid stale tags
- use bswap16() rather than be16toh() or htons() on VLAN tag access
since we already use htole32()

Closes PR kern/32643 and also fixes HW VLAN tagging on big endian machines.
 1.73 06-Dec-2006  tsutsui No need to include PCI header files.
 1.72 29-Nov-2006  tsutsui branches: 1.72.2;
Remove mii_mediachg() call from re_init().
It causes a few second TRX stalls on each ioctls
(on ifconfig(8) or tcpdump(8) etc.) and PHY seems
initialized properly without it at least on RTL8169S
with internal rgephy(4) PHY. Closes PR kern/34517.

XXX: maybe we should also test this on the original RTL8169
with external makphy(4).
 1.71 25-Nov-2006  tsutsui - add RE_RX_DMAMEM_SZ macro to hide a bit confusing hack
(allocating TX padding buffer in RX DMA mem to save resouces)
and use it where appropriate
- add a comment about the hack in re_attach() too
- pass a correct size on bus_dmamem_unmap() for RX DMA mem
 1.70 24-Nov-2006  tsutsui Change RXFIFO, RXDMA and TXDMA configrations to values taken from
the Reaktek's driver, which are also used in FreeBSD.
Fixes RX FIFO overrun errors on my Duron 1300MHz PC.
(Note the configuration values for rtk(4) are not changed)

Also add some debug printf's in RX error case (disabled by default).
 1.69 22-Nov-2006  tsutsui Umm, fix typo.
 1.68 18-Nov-2006  tsutsui No need to check ifp->if_capenable on RX checksumming.
 1.67 18-Nov-2006  tsutsui Fix some comments.
 1.66 18-Nov-2006  tsutsui Replace magic numbers with macro.
 1.65 18-Nov-2006  tsutsui Use bitmask ops rather than modulo in RE_NEXT_*() macro since
we can assume each number of descriptors and TX queue is a power of two.
 1.64 17-Nov-2006  tsutsui Prepare and use an inline function which sets 64 bit DMA address into
struct re_desc to avoid unnecessary 64 bit arithmetic on ILP32 ports.
 1.63 17-Nov-2006  tsutsui Add a workaround for hardware ip4csum-tx bug on re(4) chips.

See discussion on tech-kern and tech-net for details:
http://mail-index.netbsd.org/tech-net/2006/10/21/0000.html
http://mail-index.netbsd.org/tech-net/2006/11/04/0003.html
http://mail-index.netbsd.org/tech-net/2006/11/07/0002.html
http://mail-index.netbsd.org/tech-net/2006/11/12/0000.html
etc.
 1.62 16-Nov-2006  christos __unused removal on arguments; approved by core.
 1.61 12-Nov-2006  tsutsui Replace RTK_ETHER_ALIGN with RE_ETHER_ALIGN, which I missed.
Pointed out by dieter roelants in PR kern/35041.
 1.60 12-Nov-2006  tsutsui Remove an extra semicolon.
 1.59 12-Nov-2006  tsutsui - merge re_encap() into re_start() so that we can handle each error case
more flexible
- account a number of free txq and use it to see if packets are queued or sent
- assume free TX descriptors are not owned by the chip in re_start() and
panic if there is any inconsistency on them #ifdef DIAGNOSTIC case.
- replace a magic number (reserved TX descs?) with macro
 1.58 11-Nov-2006  tsutsui Minor style tweaks in re_txeof().
 1.57 11-Nov-2006  tsutsui Some minor tweaks in re_intr():
- check status bits at once (I'm not sure how gcc optimized them though)
- no need to check (ifp->if_flags & IFF_UP) twice
(re_init() must be called at splnet() anyway)
- call re_start() only if the interrupt is actually handled here
- call re_start() directly rather than via (*ifp->if_start)()
 1.56 11-Nov-2006  tsutsui Clear a TX timeout only if all queued packets are handled.
 1.55 11-Nov-2006  tsutsui Remove a leftover comment.
(note bus_dmamap_sync(9) is still needed even if no changes are made to
DMA descriptors but once they are fetched into the CPU cache)
 1.54 11-Nov-2006  tsutsui - set descriptor DMA addresses before enabling TX and RX
- set RTK_EARLY_TX_THRESH before starting TX and RX
 1.53 10-Nov-2006  tsutsui Call re_reset() after re_stop() in re_init().
Without this, re(4) on my macppc sometimes falls into mangled state
and generates many errors after ifconfig(8) or tcpdump(8) etc.
 1.52 05-Nov-2006  tsutsui Rename prefixes of re(4) specific macro and structure members
from RTK_ or rtk_ to RE_ or re_ for maintainability of these sources.
Eventually we should split these files (and struct rtk_softc) into
three elements, rtk(4) specific one, re(4) specific one, and a common
(register definitions, eeprom and multicast functions etc) part.

While here, add a couple of comments around weird definitions.
 1.51 03-Nov-2006  tsutsui Pull a 8139C+ fix from FreeBSD if_re.c rev 1.73:
Ignore BMCR_LOOP and BMCR_ISO bits which have different meanings on 8139C+.

Tested by Brian A. Seklecki.
 1.50 28-Oct-2006  tsutsui Put common data for each RX DMA descriptor into a new rxsoft structure
for micro optimization.
 1.49 27-Oct-2006  tsutsui Remove redundant byteswap ops.
 1.48 24-Oct-2006  tsutsui Set RTK_RDESC_CMD_OWN in rtk_cmdstat of RX DMA descriptor after
all other descriptor data is written to avoid possible race condition.
 1.47 22-Oct-2006  tsutsui Rename RTK_[TR]X_DESC_INC() macro to RTK_NEXT_[TR]X_DESC() and
change them to return rvalues to avoid possible side effects.
Also define RTK_NEXT_TXQ() for rtk_txq index and use it as well.
 1.46 22-Oct-2006  tsutsui Rename a variable to clarify meaning of index.
 1.45 21-Oct-2006  tsutsui Tweak TX descriptor setup code in re_encap() to make it more readable a bit.
 1.44 21-Oct-2006  tsutsui Use aprint_error(9) to print error messages.
 1.43 21-Oct-2006  tsutsui Use CSR_WRITE_1() to write RTK_TXSTART register because it is localted
at an odd address (0xd9) and noted "8 bit" in rtl81x9reg.h.

XXX: FreeBSD and OpenBSD also use CSR_WRITE_1() to write RTK_GTXSTART
XXX: for 8169 even though there is a "16 bits" comment at GTXSTART macro.
XXX: Which is correct?
 1.42 20-Oct-2006  tsutsui In re_newbuf():
- adjust m_data and m_len directly rather than calling m_adj(9)
- more cosmetics
 1.41 20-Oct-2006  tsutsui KNF, remove register decls, TAB/space cosmetics etc.
 1.40 20-Oct-2006  tsutsui u_intNN_t -> uintNN_t
 1.39 20-Oct-2006  tsutsui Use BUS_DMA_COHERENT on mapping DMA memory for TX/RX descriptors.
I can't think of a good way to avoid race condition between writeback and
DMA write against descriptors if cachelinesize > sizeof(struct rtk_desc)...

Anyway, now re(4) is functional on O2 (and probably other mips ports).
 1.38 20-Oct-2006  tsutsui Try to avoid race condition between cache writeback from CPU and DMA write
from re(4) chip as much as possible.
 1.37 20-Oct-2006  tsutsui while (1) -> for (;;)
 1.36 20-Oct-2006  tsutsui - bcopy -> memcpy
- bcmp -> memcmp
 1.35 20-Oct-2006  tsutsui There is no particular reason to use BUS_DMA_ALLOCNOW on bus_dmamap_create(9).
 1.34 20-Oct-2006  tsutsui Tweak a for() loop a bit in re_rxeof().
 1.33 20-Oct-2006  tsutsui Sync RX mbufs before setting up RX DMA descriptor.
 1.32 20-Oct-2006  tsutsui - call bus_dmamap_sync(9) against DMA descriptors more properly
- make DMA descripter members volatile
Now re(4) works on sgimips O2.

XXX: Still re(4) sometimes stalls on NFS load on sgimips,
XXX: but I'm not sure it's sgimips specific or not.
 1.31 17-Oct-2006  tsutsui DMA memory for the TX ring should be aligned at RTK_RING_ALIGN,
not RTK_ETHER_ALIGN.
 1.30 17-Oct-2006  yamt re_diag: constify.
 1.29 13-Oct-2006  yamt re_start: fix tx stall.
 1.28 13-Oct-2006  yamt re_txeof: fix watchdog timeout.
 1.27 12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.26 24-Sep-2006  jmcneill Add "name" parameter to powerhook_establish, to aid debugging. No objections
on tech-kern@
 1.25 18-Jun-2006  rpaulo branches: 1.25.4; 1.25.6;
Use IFQ_IS_EMPTY().
 1.24 26-May-2006  blymn branches: 1.24.2;
Clean up bogus whitespace
 1.23 16-May-2006  pavel branches: 1.23.2;
Disable hw VLAN tagging, in a similar way that it was done in OpenBSD
(src/sys/dev/ic/re.c rev. 1.15). The disabled VLAN stripping is mine.
(The OpenBSD driver forgot to do this.)

The reason is that untagged packets get sometimes tagged incorrectly.
PR 32643.

Approved by martin@.
 1.22 11-Dec-2005  christos branches: 1.22.4; 1.22.6; 1.22.8; 1.22.12;
merge ktrace-lwp.
 1.21 11-Jul-2005  yamt specify dma direction hints for bus_dmamap_load_mbuf.
 1.20 19-May-2005  briggs branches: 1.20.2;
BUS_DMASYNC_* routines are from the point of view of the memory controller,
so BUS_DMASYNC_POSTREAD should follow a device->memory transfer (like for
the rx packet data.
Also, it would be good to do a BUS_DMASYNC_PREWRITE to ensure that packet
data is flushed to memory before the chip tries to transmit data.
Tested on a PowerPC system.
 1.19 15-May-2005  yamt disable IFCAP_CSUM_IPv4_Tx and comment why.
 1.18 02-May-2005  yamt split IFCAP_CSUM_xxx to IFCAP_CSUM_xxx_Rx and IFCAP_CSUM_xxx_Tx.
 1.17 30-Mar-2005  yamt - use IFQ_POLL/DEQUEUE rather than IF_DEQUEUE/PREPEND.
- handle tx queue full correctly.
 1.16 29-Mar-2005  yamt re_encap: set RTK_TDESC_CMD_IPCSUM if any of checksum offloading is requested.
otherwise, RTK_TDESC_CMD_TCPCSUM/UDPCSUM don't seem to make any effect.
 1.15 23-Mar-2005  yamt - restructure tx descriptor handling code to decouple
number of tx descriptors, number of rx descriptors, and number of mbufs.
- bump number of tx descriptors for rtl8169. 64 doesn't seem to be sufficient
when doing TSO.
 1.14 14-Mar-2005  yamt branches: 1.14.2;
move the code to drop packets in the previous version
from re_encap to re_start so that other rtk_tx_free checks are
also covered.
 1.13 12-Mar-2005  yamt re(4) driver:
- TSO support.
- fix some error handling.
- remove mysterious RTK_NTXSEGS and use more appropriate values
for bus_dmamap_create.
- if we need more than all of our tx descriptors in order to transmit a packet,
just drop it rather than retrying infinitely.
 1.12 27-Feb-2005  perry nuke trailing whitespace
 1.11 23-Feb-2005  yamt re_init: correct usage of bus_dma(9).
now re@pci works on my alpha, in the case of !RE_USEIOSPACE.
 1.10 23-Feb-2005  yamt remove unused macros.
 1.9 20-Feb-2005  jdolecek use VLAN_* macros for VLAN tag extraction/addition
 1.8 13-Feb-2005  jdolecek don't call re_rxeof a second time when we've already done the work
pull common code out from if and else clauses

from FreeBSD if_re.c rev. 1.33
 1.7 13-Feb-2005  jdolecek g/c debug printf
 1.6 13-Jan-2005  kanaoka branches: 1.6.2; 1.6.4; 1.6.6;
- Move re_diag() from bus independend code to PCI attachment code.

XXX: I tested cardbus device,but not PCI device.
 1.5 09-Jan-2005  kanaoka sys/dev/ic/rtl8169.c:
- re_attach(): Use bus_dma* directly instead of calling re_alloc().
- re_attach(): Free bus_dma* resources if attach fails.
- re_detach(): Free bus_dma* resources.
- re_newbuf(): Remove unnecessary error check.

sys/dev/ic/rtl81x9reg.h:
- Define RTK_NTXSEGS.

sys/dev/ic/rtl81x9var.h:
- Add new members to struct rtk_list_data for bus_dma*.
 1.4 09-Jan-2005  kanaoka - Use aprint_*.
- Remove unnecesarry code.
- Changes some cosmetic.
 1.3 26-Dec-2004  kanaoka - Use ether_ioctl().
- Remove unnecessary re_init() in re_attach().
- Remove notyet compile option.
 1.2 26-Dec-2004  kanaoka - Sync if_re.c(rev=1.6).

When adding/deleting multicast addresses, only whack the address
filter if the interface is marked RUNNING.

Fixes kern/27678.
 1.1 23-Dec-2004  jonathan Snapshot of incomplete-but-working split of re(4) driver into a
bus-independent backend, with PCI and CardBus attachment code.
The committed code has two serious bugs:

1. The driver makes no attempt to recover resources when a (Cardbus)
instance is removed; bus resources are leaked.

2. In testing with a NetGear GA-511, the Cardbus card never responded
to a reset/wakeup if the card is powered down after attachment.
So for now, leave cardbus instances powered up at attachment
(insertion, or at boot if a card is already present).

That aside, it acutally works on my GA-511. Committed as-is despite
the bugs, after repeated requests to make the code available for
further testing. Also requires sys/dev/mii/miidevs rev 1.54 -> 1.55,
and consequent regen of miidevs{,_data}.h.
 1.6.6.2 26-Mar-2005  yamt sync with head.
 1.6.6.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.6.4.6 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.6.4.5 01-Apr-2005  skrll Sync with HEAD.
 1.6.4.4 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.6.4.3 15-Feb-2005  skrll Sync with HEAD.
 1.6.4.2 17-Jan-2005  skrll Sync with HEAD.
 1.6.4.1 13-Jan-2005  skrll file rtl8169.c was added on branch ktrace-lwp on 2005-01-17 19:30:40 +0000
 1.6.2.1 29-Apr-2005  kent sync with -current
 1.14.2.7 04-Oct-2007  bouyer Pull up following revision(s) (requested by tsutsui in ticket #1852):
sys/dev/ic/rtl81x9var.h: revision 1.39
sys/dev/cardbus/if_re_cardbus.c: revision 1.13
sys/dev/pci/if_re_pci.c: revision 1.27 via patch
sys/dev/pci/if_rtk_pci.c: revision 1.32
sys/dev/cardbus/if_rtk_cardbus.c: revision 1.32
sys/dev/ic/rtl8169.c: revision 1.84, 1.85
sys/dev/ic/rtl81x9reg.h: revision 1.27
sys/dev/ic/rtl81x9.c: revision 1.72
Cleanup handling of quikrs on each RealTek chip:
Pull a fix for PCIe variants from FreeBSD
 1.14.2.6 03-Mar-2007  bouyer Pull up following revision(s) (requested by tsutsui in ticket #1673):
distrib/sets/lists/man/mi 1.844, 1.871
share/man/man4/Makefile 1.372, 1.379 via patch
share/man/man4/re.4 1.8, 1.9, 1.11, 1.12
share/man/man4/rgephy.4 1.1
share/man/man4/rlphy.4 1.1, 1.2
sys/arch/amd64/conf/GENERIC 1.79, 1.89
sys/arch/amd64/conf/INSTALL 1.45, 1.49
sys/arch/i386/conf/GENERIC 1.717, 1.747
sys/arch/i386/conf/GENERIC_LAPTOP 1.164
sys/arch/i386/conf/INSTALL 1.277, 1.283
sys/arch/i386/conf/INSTALL_LAPTOP 1.96, 1.98
sys/arch/i386/conf/XEN2_DOM0 1.22 via patch
sys/arch/macppc/conf/GENERIC 1.220, 1.246
sys/arch/macppc/conf/INSTALL 1.96, 1.100
sys/dev/cardbus/if_re_cardbus.c 1.10
sys/dev/cardbus/if_rtk_cardbus.c 1.29-1.31
sys/dev/ic/rtl8169.c 1.14, 1.20, 1.24, 1.25, 1.28-1.61, 1.63, 1.64-1.81 via patch
sys/dev/ic/rtl81x9.c 1.52, 1.54-1.63, 1.65, 1.67-1.70
sys/dev/ic/rtl81x9reg.h 1.15-1.26
sys/dev/ic/rtl81x9var.h 1.19, 1.21-1.37
sys/dev/mii/files.mii 1.38
sys/dev/mii/miidevs 1.62, 1.64
sys/dev/mii/rgephy.c 1.10, 1.13-1.16
sys/dev/mii/rlphy.c 1.1, 1.6, 1.7, 1.11 via patch
sys/dev/pci/if_re_pci.c 1.13, 1.15-1.17, 1.19-1.23
sys/dev/pci/if_rtk_pci.c 1.25, 1.28, 1.29, 1.31
sys/dev/pci/pcidevs 1.851, 1.852

on re(4):
- improve stability (I believe ;-)
- add a workaround for hardware ip4csum-tx bug
- support newer chips (8169SB/SC, PCIe based 8168 etc.)
- fix 8139C+ support
- enable hardware VLAN
- misc bus_dma(9) fix (which makes re(4) work on mips ports)

on rtk(4):
- fix kern/31348
- fix possible panic on dreamcast
 1.14.2.5 31-May-2006  tron Pull up following revision(s) (requested by pavel in ticket #1340):
sys/dev/ic/rtl8169.c: revision 1.23
Disable hw VLAN tagging, in a similar way that it was done in OpenBSD
(src/sys/dev/ic/re.c rev. 1.15). The disabled VLAN stripping is mine.
(The OpenBSD driver forgot to do this.)
The reason is that untagged packets get sometimes tagged incorrectly.
PR 32643.
Approved by martin@.
 1.14.2.4 18-Aug-2005  tron Pull up revision 1.21 (requested by yamt in ticket #674):
specify dma direction hints for bus_dmamap_load_mbuf.
 1.14.2.3 04-Apr-2005  tron Pull up revision 1.17 (requested by yamt in ticket #94):
- use IFQ_POLL/DEQUEUE rather than IF_DEQUEUE/PREPEND.
- handle tx queue full correctly.
 1.14.2.2 04-Apr-2005  tron Pull up revision 1.16 (requested by yamt in ticket #92):
re_encap: set RTK_TDESC_CMD_IPCSUM if any of checksum offloading is requested.
otherwise, RTK_TDESC_CMD_TCPCSUM/UDPCSUM don't seem to make any effect.
 1.14.2.1 04-Apr-2005  tron Pull up revision 1.15 (requested by yamt in ticket #91):
- restructure tx descriptor handling code to decouple
number of tx descriptors, number of rx descriptors, and number of mbufs.
- bump number of tx descriptors for rtl8169. 64 doesn't seem to be sufficient
when doing TSO.
 1.20.2.10 24-Mar-2008  yamt sync with head.
 1.20.2.9 17-Mar-2008  yamt sync with head.
 1.20.2.8 11-Feb-2008  yamt sync with head.
 1.20.2.7 04-Feb-2008  yamt sync with head.
 1.20.2.6 21-Jan-2008  yamt sync with head
 1.20.2.5 27-Oct-2007  yamt sync with head.
 1.20.2.4 03-Sep-2007  yamt sync with head.
 1.20.2.3 26-Feb-2007  yamt sync with head.
 1.20.2.2 30-Dec-2006  yamt sync with head.
 1.20.2.1 21-Jun-2006  yamt sync with head.
 1.22.12.1 24-May-2006  tron Merge 2006-05-24 NetBSD-current into the "peter-altq" branch.
 1.22.8.2 26-Jun-2006  yamt sync with head.
 1.22.8.1 24-May-2006  yamt sync with head.
 1.22.6.1 01-Jun-2006  kardel Sync with head.
 1.22.4.1 09-Sep-2006  rpaulo sync with head
 1.23.2.1 19-Jun-2006  chap Sync with head.
 1.24.2.1 13-Jul-2006  gdamore Merge from HEAD.
 1.25.6.3 18-Dec-2006  yamt sync with head.
 1.25.6.2 10-Dec-2006  yamt sync with head.
 1.25.6.1 22-Oct-2006  yamt sync with head
 1.25.4.4 09-Feb-2007  ad Sync with HEAD.
 1.25.4.3 01-Feb-2007  ad Sync with head.
 1.25.4.2 12-Jan-2007  ad Sync with head.
 1.25.4.1 18-Nov-2006  ad Sync with head.
 1.72.2.11 18-Aug-2009  bouyer Pull up following revision(s) (requested by tsutsui in ticket #1339):
sys/dev/ic/rtl8169.c: revisions 1.107, 1.114, 1.115, 1.116,
1.117 (via patch), 1.118 (via patch),
1.119, 1.121
sys/dev/ic/rtl81x9reg.h: revisions 1.36, 1.37, 1.38, 1.39
sys/dev/ic/rtl81x9var.h: revision 1.47
sys/dev/mii/rgephy.c: revisions 1.16, 1.18, 1.19, 1.27 (via patch)
sys/dev/mii/rgephyreg.h: revision 1.3
sys/dev/pci/if_re_pci.c: revision 1.36
- add support for RTL8211B(L) to rgephy(4)
- add a wakeup instruction for rgephy(4) on newer re(4) chips
- detect RTL8169CP, RTL8168D/8111D, and RTL8103E variants
- fix rgephy(4) problem on RTL8111D reported on current-users:
http://mail-index.NetBSD.org/current-users/2009/04/12/msg008977.html
http://mail-index.NetBSD.org/current-users/2009/04/19/msg009096.html
- pull more quirk handling from FreeBSD
- fix RX hwcksum for DESCV2 chips for PR kern/40605
- remove "B" suffix from RTL8168 device names in attach message
 1.72.2.10 31-Mar-2009  bouyer Pull up following revision(s) (requested by tsutsui in ticket #1297):
src/sys/dev/ic/rtl8169.c 1.104 (via patch), 1.105 (via patch),
1.106 (via patch), 1.108, 1.109 (via patch),
1.110, 1.111, 1.112, 1.113
sys/dev/ic/rtl81x9reg.h: revision 1.30 - 1.35
sys/dev/ic/rtl81x9var.h: revision 1.42 - 1.45
sys/dev/pci/if_re_pci.c: revision 1.35
Add support for 8168C/8111C/8102E chips.
Fix MAC reset issue (PR kern/41009)
Add/fix HW checksum support (PR kern/40955)
 1.72.2.9 24-Mar-2008  bouyer Pull up following revision(s) (requested by tsutsui in ticket #1105):
sys/dev/ic/rtl8169.c: revisions 1.94, 1.95, 1.97, 1.98
sys/dev/ic/rtl81x9reg.h: revision 1.28
No need to preserve RE_NTXDESC_RSVD on re_start().
FreeBSD says "16 bits" comment about RTK_GTXSTART was incorrect.
Use CSR_WRITE_1() for it. (though the previous code also worked)
Don't fetch DMA descriptor after BUS_DMASYNC_PREREAD op.
It looks vlan tag info must appear not only in the first descriptor
but in all descriptors of a multi-descriptor transmission attempt on re(4).
Problem was reported and fix was confirmed by Chris Brookes on tech-net.
Should also close PR kern/37959.
 1.72.2.8 16-May-2007  jdc Pull up revisions 1.84-1.85 (requested by tsutsui in ticket #640).

Cleanup handling of quikrs on each RealTek chip:
- replace rtk_type member in rtk_softc which has chip types
with new rtk_quirk that represents quirks on each chip:
- RTKQ_8129 doesn't have internal MII (used in rtk(4))
- RTKQ_8139CPLUS has different register layout (for re(4))
- RTKQ_8169NONS (original 8169) requires some settings on init
- RTKQ_PCIE requires different settings in setmulti
so that we don't have to check each hwrev values or types everywhere
and newer variants will also work without changes if they don't
have other quirks
(sc_rev is unchenged for now for reference to the Realtek's driver)
- don't check hwrev register in re_pci_match() but check
only PCI_VENDER(), PCI_PRODUCT() and PCI_REVISION()
so that we no longer have to map pci space there
- add a new HWREV value for another 8168 variant
- try to map PCI mem space more properly
- remove (probably unneeded) ifp->if_baudrate initialization

Tested on a newer 8168 variant by Dennis den Brok on tech-kern,
and also tested on 8139 and 8169C on macppc, and 8139C+ on landisk
by me.

Pull a fix for PCIe variants from FreeBSD's if_re.c rev 1.71:

> - With the PCIe devices, it looks issuing a TX command while there's
> already a transmission in progress doesn't have any effect. In other
> words, if you send two packets in rapid succession, the second one may
> end up sitting in the TX DMA ring until another transmit command is
> issued later in the future. Basically, if re_txeof() sees that there
> are still descriptors outstanding, it needs to manually resume the
> TX DMA channel by issuing another TX command to make sure all
> transmissions are flushed out. (The PCI devices seem to keep the
> TX channel moving until all descriptors have been consumed. I'm not
> sure why the PCIe devices behave differently.)
 1.72.2.7 24-Feb-2007  bouyer branches: 1.72.2.7.2;
Pull up following revision(s) (requested by tsutsui in ticket #462):
sys/dev/ic/rtl8169.c: revision 1.80 - 1.81
sys/dev/ic/rtl81x9.c: revision 1.70
Use new RTK_HWREV_8100E_SPIN2 macro. (missed in the previous)
Don't set RTK_CFG1_FULLDUPLEX bit in RTK_CFG1 register
since it's available only on RTL8129. From FreeBSD.
As defined in rtl81x9reg.h, bits of 0x80 and 0x40 in RTK_CFG1
seem to indicate LEDS0 and LEDS1 configuration initialized by
EEPROM settings, and they seem read only on my quick tests with
two 8169S based cards.
RTK_HWREV_8100E_SPIN2 is a PCIe device so also check it
in rtk_setmulti() to handle quirk. Noticed by OpenBSD.
 1.72.2.6 10-Feb-2007  tron Pull up following revision(s) (requested by tsutsui in ticket #437):
sys/dev/ic/rtl8169.c: revision 1.79
Clear IFF_OACTIVE in re_txeof() only if there are more than RE_TXDESC_RSVD
free TXDESCs. From FreeBSD, but I'm still wondering why we have to reserve
some free TXDESCs even on re_start().
 1.72.2.5 10-Feb-2007  tron Pull up following revision(s) (requested by tsutsui in ticket #437):
sys/dev/ic/rtl8169.c: revision 1.78
- check more hwrev and use HWREV_* macro. From Realtek driver
via Darrin B.Jewell.
XXX: maybe we should check this sc_rev on more place
- use RTK_TXCFG_HWREV (0x7cc00000) rather than 0x7c800000
to mask the hwrev value since bit 0x00400000 is used only by 8139D
which is not supported by this driver
- fix a tyop
 1.72.2.4 10-Feb-2007  tron Pull up following revision(s) (requested by tsutsui in ticket #437):
sys/dev/ic/rtl81x9.c: revision 1.67
sys/dev/ic/rtl8169.c: revision 1.77
Fix EEPROM functions for RTL8169SC chips:
rtl81x9.c:
Increase delay on EEPROM access since EEPROM on RTL8169 based board
seems to require slower clock. Also use common EE_DELAY() macro.
rtl8169.c:
Use common rtk_read_eeprom() function to get Ethernet address on
8169 chips because EEMODE_AUTOLOAD command was a workaround on
original FreeBSD's driver and it doesn't work on 8169SC.
Problem reported and fix tested by Frank Lorenzen on current-users,
and also tested on 8139C with rtk(4) driver by me.
 1.72.2.3 10-Feb-2007  tron Pull up following revision(s) (requested by tsutsui in ticket #437):
sys/dev/ic/rtl8169.c: revision 1.76
Wrap a sanity check in re_newbuf() with #ifdef DIAGNOSTIC and
make it fatal on failure.
 1.72.2.2 10-Feb-2007  tron Pull up following revision(s) (requested by tsutsui in ticket #437):
sys/dev/ic/rtl8169.c: revision 1.75
Use __predict_false() in several conditionals.
 1.72.2.1 20-Dec-2006  bouyer Pull up following revision(s) (requested by tsutsui in ticket #283):
share/man/man4/re.4: revision 1.11
sys/dev/ic/rtl8169.c: revision 1.74
Fix and reenable HW VLAN tagging on re(4).
Closes PR kern/32643 and also fixes HW VLAN tagging on big endian machines.
 1.72.2.7.2.2 03-Jun-2008  skrll Sync with netbsd-4.
 1.72.2.7.2.1 03-Jun-2007  wrstuden Catch up with now-somewhat-dated netbsd-4. These changes took longer
than expected for me to actually get around to merging.
 1.81.2.4 17-May-2007  yamt sync with head.
 1.81.2.3 24-Mar-2007  yamt sync with head.
 1.81.2.2 12-Mar-2007  rmind Sync with HEAD.
 1.81.2.1 27-Feb-2007  yamt - sync with head.
- move sched_changepri back to kern_synch.c as it doesn't know PPQ anymore.
 1.83.6.1 29-Mar-2007  reinoud Pullup to -current
 1.83.4.1 11-Jul-2007  mjf Sync with head.
 1.83.2.6 23-Oct-2007  ad Sync with head.
 1.83.2.5 09-Oct-2007  ad Sync with head.
 1.83.2.4 20-Aug-2007  ad Sync with HEAD.
 1.83.2.3 01-Jul-2007  ad Adapt to callout API change.
 1.83.2.2 27-May-2007  ad Sync with head.
 1.83.2.1 10-Apr-2007  ad Sync with head.
 1.86.6.3 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.86.6.2 05-Oct-2007  joerg Remove the power management nonsense in the PCI versions of
rtk(4) and re(4). It is not really likely to work anyway.
Use PNP power management for the cardbus attachment as well and
remove the power management handlers from the chipset code.
 1.86.6.1 03-Sep-2007  jmcneill Sync with HEAD.
 1.86.2.1 03-Sep-2007  skrll Sync with HEAD.
 1.88.6.1 25-Oct-2007  bouyer Sync with HEAD.
 1.88.2.3 23-Mar-2008  matt sync with HEAD
 1.88.2.2 09-Jan-2008  matt sync with HEAD
 1.88.2.1 06-Nov-2007  matt sync with HEAD
 1.89.6.1 11-Dec-2007  yamt sync with head.
 1.89.4.1 26-Dec-2007  ad Sync with head.
 1.89.2.1 18-Feb-2008  mjf Sync with HEAD.
 1.90.2.3 20-Jan-2008  bouyer Sync with HEAD
 1.90.2.2 08-Jan-2008  bouyer Sync with HEAD
 1.90.2.1 13-Dec-2007  bouyer Sync with HEAD
 1.96.6.4 17-Jan-2009  mjf Sync with HEAD.
 1.96.6.3 28-Sep-2008  mjf Sync with HEAD.
 1.96.6.2 02-Jun-2008  mjf Sync with HEAD.
 1.96.6.1 03-Apr-2008  mjf Sync with HEAD.
 1.96.2.1 24-Mar-2008  keiichi sync with head.
 1.99.2.1 18-May-2008  yamt sync with head.
 1.102.2.7 11-Aug-2010  yamt sync with head.
 1.102.2.6 11-Mar-2010  yamt sync with head
 1.102.2.5 16-Sep-2009  yamt sync with head
 1.102.2.4 20-Jun-2009  yamt sync with head
 1.102.2.3 16-May-2009  yamt sync with head
 1.102.2.2 04-May-2009  yamt sync with head.
 1.102.2.1 16-May-2008  yamt sync with head.
 1.104.6.2 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.104.6.1 19-Oct-2008  haad Sync with HEAD.
 1.104.2.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.105.4.10 21-Dec-2014  msaitoh Pull up following revision(s) (requested by uwe in ticket #1936):
sys/dev/ic/rtl8169.c: revision 1.142
RealTek 8139C+ incorrectly identifies UDP checksum 0xffff as bad.
Force software recalculation of UDP checksum if bad checksum is
reported by the hardware.
 1.105.4.9 25-Jan-2012  riz Pull up following revision(s) (requested by garbled in ticket #1698):
sys/dev/ic/rtl81x9var.h: revision 1.52
sys/dev/ic/rtl8169.c: revision 1.134
sys/dev/ic/rtl81x9reg.h: revision 1.42
Add support to recognize the 8168E model of this chip. Taken from FreeBSD
 1.105.4.8 19-Jun-2009  snj Pull up following revision(s) (requested by tsutsui in ticket #821):
sys/dev/ic/rtl8169.c: revisions 1.107, 1.114-1.119, 1.121
sys/dev/ic/rtl81x9reg.h: revisions 1.36-1.39
sys/dev/ic/rtl81x9var.h: revision 1.47
sys/dev/mii/rgephy.c: revision 1.27 via patch
sys/dev/pci/if_re_pci.c: revision 1.36
remove extra semicolons.
--
Add HWREV values of RTL8168CP and RTL8168D. From FreeBSD.

XXX: needs more quirk handling after wakeup for newer chips.
--
Add HWREV of RTL8102EL variant. From FUKAUMI Naoki.
--
Assume an unknown HWREV chip has the same features with the latest one.
--
Remove suffix "B" from rtk_name of PCI_PRODUCT_REALTEK_RT8168 devices.
All 8168/8111 variants (8168/8168B/8168C/8168CP/8168D/8111B/8111C/8111CP)
have the same PCI device ID.
--
Remove magic reset sequence except wakeup for rev 2 chips which breaks 8111D.
Problem reported and fix confirmed by Thomas Bieg on current-users.

Also tested on 8111C (no bad side effect) by several users privately.
--
Pull some changes for newer chips from FreeBSD:
- pull MACSTAT and CMDSTOP quirks for 8168/8111 chips
- always set CPLUSCMD_PCI_MRW on reset
- set VLANSTRIP and RXCSUM_ENB bits on CPLUS register per if_capenable

Tested on 8111C and 8111D by several users, and
no bad side effect on my old 8169S.
--
Remove unused sc_rev settings (all quirks are handled by sc_quirk)
and merge HWREV cases which have the same quirks.
--
- rename RTK_HWREV_8102EL_SPIN2 -> RTK_HWREV_8103E
- add a HWREV value for 8168DP
Per Realtek's Linux drivers.
--
Two fixes for RX hwcsum on DESCV2 chips:
* On checking TCPv4/UDPv4 RX checksum on DESCV2 chips, also check
RE_RDESC_VLANCTL_IPV4 bit because those DESCV2 chips may also recognize
IPv6 packets and set RE_PROTOID_TCPIP or RE_PROTOID_UDPIP bits for
TCPv6/UDPv6 packets. This may fix PR kern/40605.
* According to Realtek's Linux driver, DESCV2 chips don't set RE_PROTOID_IP
for non-TCP/UDP IP packets (set only RE_RDESC_VLANCTL_IPV[46]) so
remove PROTOID check for IPv4 RX cheksum on DESCV2 chips.
 1.105.4.7 01-May-2009  snj Pull up following revision(s) (requested by tsutsui in ticket #597):
sys/dev/ic/rtl8169.c: revision 1.113
Fix another botch in hwcsum changes for PR kern/40955:
8168/8111/8168B/8111B doesn't have DESCV2.
Problem reported by Arto Huusko on current-users@.
 1.105.4.6 01-May-2009  snj Pull up following revision(s) (requested by tsutsui in ticket #597):
sys/dev/ic/rtl8169.c: revision 1.112
sys/dev/ic/rtl81x9reg.h: revision 1.35
Check a correct bit for ip4csum-rx. Reported privately on PR kern/40955.
 1.105.4.5 01-May-2009  snj Pull up following revision(s) (requested by tsutsui in ticket #597):
sys/dev/ic/rtl8169.c: revision 1.111
sys/dev/ic/rtl81x9var.h: revision 1.45
Add another quirk flag which shows availability of EEPROM command register.
Now we can remove sc_rev which was intended to represent "MAC revision"
used in the Realtek driver.
 1.105.4.4 01-May-2009  snj Pull up following revision(s) (requested by tsutsui in ticket #597):
sys/dev/ic/rtl8169.c: revision 1.110
sys/dev/ic/rtl81x9var.h: revision 1.44
Add and use a new quirk flag to disable JUMBO MTU,
rather than checking sc_rev values.
 1.105.4.3 01-May-2009  snj Pull up following revision(s) (requested by tsutsui in ticket #597):
sys/dev/ic/rtl8169.c: revision 1.109
sys/dev/ic/rtl81x9reg.h: revision 1.34
sys/dev/ic/rtl81x9var.h: revision 1.43
Add hardware checksum support for newer PCIe 8168/8111/8102 chips,
per device info taken from FreeBSD driver. Tested by snj@ on 8111C.
Should closes PR kern/40955.
Note on old 8169 chips IP hw csum must be enabled to use TCP/UDP hw csums,
but I'm not sure if these newer chips still have the same restriction.
 1.105.4.2 26-Mar-2009  snj branches: 1.105.4.2.4;
Pull up following revision(s) (requested by tsutsui in ticket #597):
sys/dev/ic/rtl8169.c: revision 1.106
sys/dev/ic/rtl81x9reg.h: revision 1.33
Add support for a 8168C/8111C revision
- also disable jumbo frame on this adapter following the FreeBSD driver
- merge redundant call to aprint_error_dev
 1.105.4.1 24-Mar-2009  snj Pull up following revision(s) (requested by tsutsui in ticket #596):
sys/dev/ic/rtl8169.c: revision 1.108
sys/dev/ic/rtl81x9var.h: revision 1.42
Access LDPS register in re_reset() only on 8169S single chip variants.
From OpenBSD and FreeBSD drivers via PR kern/41009, and
Realtek-supplied FreeBSD driver.
 1.105.4.2.4.1 21-Apr-2010  matt sync to netbsd-5
 1.105.2.2 28-Apr-2009  skrll Sync with HEAD.
 1.105.2.1 19-Jan-2009  skrll Sync with HEAD.
 1.107.2.2 23-Jul-2009  jym Sync with HEAD.
 1.107.2.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.129.4.2 05-Mar-2011  rmind sync with head
 1.129.4.1 30-May-2010  rmind sync with head
 1.129.2.2 17-Aug-2010  uebayasi Sync with HEAD.
 1.129.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.133.8.3 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.133.8.2 30-Oct-2012  yamt sync with head
 1.133.8.1 17-Apr-2012  yamt sync with head
 1.134.4.4 14-Dec-2014  martin Pull up following revision(s) (requested by uwe in ticket #1212):
sys/dev/ic/rtl8169.c: revision 1.142
RealTek 8139C+ incorrectly identifies UDP checksum 0xffff as bad.
Force software recalculation of UDP checksum if bad checksum is
reported by the hardware.
 1.134.4.3 18-Sep-2013  bouyer Pull up following revision(s) (requested by phx in ticket #946):
sys/arch/sandpoint/stand/altboot/rge.c: revision 1.7
sys/arch/sandpoint/stand/altboot/brdsetup.c: revision 1.32
sys/dev/ic/rtl8169.c: revision 1.138
QNAP V200 boards have no EEPROM for the MAC address, so all devices default
to the same address (00:e0:4c:69:20:01).
Now we read the real MAC address from the flash ROM. It is stored at the
beginning of a 512-byte block in ASCII format. Some QNAP's have a broken
ext2 file system, so we cannot look for the file ETH0.MAC_ADDR therein,
but have to search the whole flash in 512-byte steps for candidates...
Make re(4) driver always use IDR register values for its MAC address.
Some sandpoint NAS firmwares set MAC address per their
firmware settings and don't use re(4)'s EEPROM values.
Per rtl8169 manuals re(4) chip reads EEPROM automatically after
hardware reset and Linux driver also uses IDR registers,
so this change should not affect existing other boards
which actually have vaild EEPROM.
Per discussion in old tech-kern@ thread:
http://mail-index.netbsd.org/tech-kern/2012/12/01/msg014573.html
Note rtl81x9.c is still shared among rtk(4) only for a multicast function
(to avoid boring refactoring work).
 1.134.4.2 29-Jul-2013  msaitoh Pull up following revision(s) (requested by khorben in ticket #913):
sys/dev/ic/rtl8169.c: revision 1.137
sys/dev/ic/rtl81x9reg.h: revision 1.44
share/man/man4/re.4: revision 1.14
Added support for the Realtek 8168F variant in re(4).
From FreeBSD; not tested on real hardware unfortunately. The manual page
was adjusted as well.
No objection from current-users@, "commit it" gdt@
 1.134.4.1 05-Mar-2012  sborrill Pull up the following revisions(s) (requested by nonaka in ticket #83):
sys/dev/ic/rtl8169.c: revision 1.135
sys/dev/ic/rtl81x9reg.h: revision 1.43

Add RTL8168E/8111E-VL support.
 1.134.2.3 06-Mar-2012  mrg sync to -current
 1.134.2.2 06-Mar-2012  mrg sync to -current
 1.134.2.1 04-Mar-2012  mrg sync to latest -current.
 1.136.2.3 03-Dec-2017  jdolecek update from HEAD
 1.136.2.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.136.2.1 23-Jun-2013  tls resync from head
 1.139.6.1 07-Apr-2014  tls Be a little more clear and consistent about harvesting entropy from devices:

1) deprecate RND_FLAG_NO_ESTIMATE

2) define RND_FLAG_COLLECT_TIME, RND_FLAG_COLLECT_VALUE

3) define RND_FLAG_ESTIMATE_TIME, RND_FLAG_ESTIMATE_VALUE

4) define RND_FLAG_DEFAULT: RND_FLAG_COLLECT_TIME|
RND_FLAG_COLLECT_VALUE|RND_FLAG_ESTIMATE_TIME

5) Make entropy harvesting from environmental sensors a little more generic
and remove it from individual sensor drivers.

6) Remove individual open-coded delta-estimators for values from a few
places in the tree (uvm, environmental drivers).

7) 0 -> RND_FLAG_DEFAULT, actually gather entropy from various drivers
that had stubbed out code, other minor cleanups.
 1.140.2.2 15-May-2015  snj Pull up following revision(s) (requested by joerg in ticket #772):
sys/arch/arm/amlogic/amlogic_genfb.c: revision 1.4
sys/arch/arm/arm/disassem.c: revision 1.25
sys/arch/arm/omap/am335x_cm_padconf.c: revision 1.3
sys/arch/arm/omap/sitara_cm.h: revision 1.2
sys/dev/ic/i82557var.h: revision 1.51
sys/dev/ic/rtl8169.c: revision 1.143
sys/dev/ieee1394/fwcrom.c: revision 1.17
sys/external/bsd/dwc2/dwc2.c: revision 1.32
dwc2_hubd appears to be unused so #if 0 it in order to appease clang
--
Preserve const.
--
No reason not to make the string const.
--
Drop unnecessary-but-harmful casts.
--
Replace void * cast with proper __UNVOLATILE.
--
Preserve const.
--
amlogic_genfb_hdmi_write_4 is currently unused, mark it as such.
 1.140.2.1 14-Dec-2014  martin Pull up following revision(s) (requested by uwe in ticket #324):
sys/dev/ic/rtl8169.c: revision 1.142
RealTek 8139C+ incorrectly identifies UDP checksum 0xffff as bad.
Force software recalculation of UDP checksum if bad checksum is
reported by the hardware.
 1.143.2.6 28-Aug-2017  skrll Sync with HEAD
 1.143.2.5 05-Feb-2017  skrll Sync with HEAD
 1.143.2.4 09-Jul-2016  skrll Sync with HEAD
 1.143.2.3 19-Mar-2016  skrll Sync with HEAD
 1.143.2.2 22-Sep-2015  skrll Sync with HEAD
 1.143.2.1 06-Jun-2015  skrll Sync with HEAD
 1.147.2.3 26-Apr-2017  pgoyette Sync with HEAD
 1.147.2.2 20-Mar-2017  pgoyette Sync with HEAD
 1.147.2.1 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.148.2.1 21-Apr-2017  bouyer Sync with HEAD
 1.150.2.1 19-May-2017  pgoyette Resolve conflicts from previous merge (all resulting from $NetBSD
keywork expansion)
 1.151.2.1 24-Oct-2017  snj Pull up following revision(s) (requested by knakahara in ticket #302):
sys/arch/powerpc/booke/dev/pq3etsec.c: 1.30-1.31
sys/arch/x86/pci/if_vmx.c: 1.20
sys/dev/ic/i82557.c: 1.148
sys/dev/ic/rtl8169.c: 1.152
sys/dev/pci/cxgb/cxgb_sge.c: 1.5
sys/dev/pci/if_age.c: 1.51
sys/dev/pci/if_alc.c: 1.25
sys/dev/pci/if_ale.c: 1.23
sys/dev/pci/if_bge.c: 1.311
sys/dev/pci/if_bge.c: 1.312
sys/dev/pci/if_bnx.c: 1.62
sys/dev/pci/if_jme.c: 1.32
sys/dev/pci/if_nfe.c: 1.64
sys/dev/pci/if_sip.c: 1.167
sys/dev/pci/if_stge.c: 1.63-1.64
sys/dev/pci/if_ti.c: 1.102
sys/dev/pci/if_txp.c: 1.48
sys/dev/pci/if_vge.c: 1.61
sys/dev/pci/if_wm.c: 1.538
sys/dev/pci/ixgbe/ix_txrx.c: 1.29 via patch
sys/net/agr/if_agrether_hash.c: 1.4
sys/net/if_ether.h: 1.67-1.68
sys/net/if_ethersubr.c: 1.244
sys/net/if_vlan.c: 1.100
sys/net80211/ieee80211_input.c: 1.89
sys/net80211/ieee80211_output.c: 1.59
sys/sys/mbuf.h: 1.171
VLAN ID uses pkthdr instead of mtag now. Contributed by s-yamaguchi@IIJ.
I just commit by proxy. Reviewed by joerg@n.o and christos@n.o, thanks.
See http://mail-index.netbsd.org/tech-net/2017/09/26/msg006459.html
--
only get vtag when we have vtag like the other drivers.
--
- only get the vtag if we have it like the other drivers
- mask the hardware vlan tag
--
- add a constant for the vlan mask.
- enforce that we have a tag before we get it.
only get vtag when we have vtag like the other drivers.
like if_bge.c:1.312 and if_stge.c:1.64.
fixed by s-yamaguchi@IIJ, thanks.
 1.152.2.5 26-Jan-2019  pgoyette Sync with HEAD
 1.152.2.4 18-Jan-2019  pgoyette Synch with HEAD
 1.152.2.3 26-Nov-2018  pgoyette Sync with HEAD, resolve a couple of conflicts
 1.152.2.2 28-Jul-2018  pgoyette Sync with HEAD
 1.152.2.1 25-Jun-2018  pgoyette Sync with HEAD
 1.154.2.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.154.2.1 10-Jun-2019  christos Sync with HEAD
 1.159.2.2 04-Aug-2023  martin Pull up following revision(s) (requested by jakllsch in ticket #1705):

sys/dev/ic/rtl81x9var.h: revision 1.58
sys/dev/ic/rtl81x9reg.h: revision 1.54
sys/dev/ic/rtl8169.c: revision 1.167
sys/dev/ic/rtl8169.c: revision 1.168

re(4): misc chip revision support changes
* remove impossible-to-match chip revision cases
* bring support for modern chips in line with FreeBSD and OpenBSD
* adds support for RTL8168GU

Addresses PR kern/56312.

- Print chip revision. From OpenBSD.
- Rename RTK_HWREV_8168_SPIN[123] to RTK_HWREV_8168'B'_SPIN[123].
Same as other *BSDs.
- Rename RTK_HWREV_8168G_SPIN4 to RTK_HWREV_8411B. Same as other *BSDs.
- Add definition of RTK_HWREV_8169_8110SCE.
 1.159.2.1 28-Jan-2020  martin Pull up following revision(s) (requested by msaitoh in ticket #667):

sys/dev/ic/rtl81x9var.h: revision 1.57
sys/dev/ic/rtl81x9.c: revision 1.107
sys/dev/ic/rtl81x9reg.h: revision 1.51
sys/dev/ic/rtl8169.c: revision 1.160
sys/dev/ic/rtl81x9reg.h: revision 1.52
sys/dev/ic/rtl8169.c: revision 1.161

Use unsigned in rtk_setmulti() to avoid undefined behavior. Found bk kUBSan.
8168H model didn't link up well. some models seems to require to enable TX/RX after configuration.
RTKQ_TXRXEN_LATER quirk flag added. it may be able to unify with RTKQ_RXDV_GATED flag?
Sort RTK_HWREV_* by value.

Improve some chip revisions support:
- Add 8168FP, 8411, 8168G, 8401E, 8105E, 8105E_SPIN1, 8106E and 8402 from
{Free,Open}BSD.
- Renumber RTK_HWREV_8103E from 0x24C00000 to 0x34c00000. 0x24C00000 is newly
used as RTK_HWREV_8102EL_SPIN1. Same as {Free,Open}BSD.
 1.161.2.1 29-Feb-2020  ad Sync with head.
 1.176.2.1 02-Aug-2025  perseant Sync with HEAD
 1.4 12-May-2009  cegger struct device * -> device_t, no functional changes intended.
 1.3 11-Dec-2005  christos branches: 1.3.74; 1.3.90;
merge ktrace-lwp.
 1.2 13-Jan-2005  kanaoka branches: 1.2.4;
- Move re_diag() from bus independend code to PCI attachment code.

XXX: I tested cardbus device,but not PCI device.
 1.1 23-Dec-2004  jonathan Snapshot of incomplete-but-working split of re(4) driver into a
bus-independent backend, with PCI and CardBus attachment code.
The committed code has two serious bugs:

1. The driver makes no attempt to recover resources when a (Cardbus)
instance is removed; bus resources are leaked.

2. In testing with a NetGear GA-511, the Cardbus card never responded
to a reset/wakeup if the card is powered down after attachment.
So for now, leave cardbus instances powered up at attachment
(insertion, or at boot if a card is already present).

That aside, it acutally works on my GA-511. Committed as-is despite
the bugs, after repeated requests to make the code available for
further testing. Also requires sys/dev/mii/miidevs rev 1.54 -> 1.55,
and consequent regen of miidevs{,_data}.h.
 1.2.4.2 17-Jan-2005  skrll Sync with HEAD.
 1.2.4.1 13-Jan-2005  skrll file rtl8169var.h was added on branch ktrace-lwp on 2005-01-17 19:30:40 +0000
 1.3.90.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.3.74.1 16-May-2009  yamt sync with head
 1.115 29-Jun-2024  riastradh if_stats(9): Add ifp argument to if_stat..._ref.

This will enable us to pass the ifp through to a dtrace probe inside.

No functional change intended in this change, but this is an API
change visible to modules so it shouldn't be pulled up.

PR kern/58377
 1.114 21-May-2023  andvar s/thar/that/ in comments.
 1.113 25-Sep-2022  thorpej Remove unnecessary include of <sys/malloc.h>.
 1.112 25-Jun-2022  tsutsui Pass proper status values to rnd_add_uint32(9) as rnd(9) man page claims.
 1.111 12-Mar-2020  thorpej Add support for MBUFTRACE.
 1.110 07-Feb-2020  thorpej Use callout_setfunc() / callout_schedule().
 1.109 04-Feb-2020  thorpej Use ifmedia_fini().
 1.108 29-Jan-2020  thorpej Adopt <net/if_stats.h>.
 1.107 01-Aug-2019  msaitoh branches: 1.107.2;
Use unsigned in rtk_setmulti() to avoid undefined behavoir. Found bk kUBSan.
 1.106 28-May-2019  msaitoh branches: 1.106.2;
Use ETHER_LOCK()/ETHER_UNLOCK() for all ethernet drivers to protect ec_multi*.
 1.105 23-May-2019  msaitoh No functional change:
- Simplify MII structure initialization and reference.
- u_int*_t -> uint*_t.
- KNF
 1.104 22-Jan-2019  msaitoh Change MII PHY read/write API from:

int (*mii_readreg_t)(device_t, int, int);
void (*mii_writereg_t)(device_t, int, int, int);
to:

int (*mii_readreg_t)(device_t, int, int, uint16_t *);
int (*mii_writereg_t)(device_t, int, int, uint16_t);

Now we can test if a read/write operation failed or not by the return value.

In 802.3 spec says that the PHY shall not respond to read/write transaction
to the unimplemented register(22.2.4.3). Detecting timeout can be used to
check whether a register is implemented or not (if the register conforms to
the spec). ukphy(4) can be used this for MII_MMDACR and MII_MMDAADR.

Note that I noticed that the following code do infinite loop in the
read/wirte function. If it accesses unimplemented PHY register, it will hang.
It should be fixed:

arm/at91/at91emac.c
arm/ep93xx/epe.c
arm/omap/omapl1x_emac.c
mips/ralink/ralink_eth.c
arch/powerpc/booke/dev/pq3etsec.c(read)
dev/cadence/if_cemac.c <- hkenken
dev/ic/lan9118.c


Tested with the following device:

axe+ukphy
axe+rgephy
axen+rgephy (tested by Andrius V)
wm+atphy
wm+ukphy
wm+igphy
wm+ihphy
wm+makphy
sk+makphy
sk+brgphy
sk+gentbi
msk+makphy
sip+icsphy
sip+ukphy
re+rgephy
bge+brgphy
bnx+brgphy
gsip+gphyter
rtk+rlphy
fxp+inphy (tested by Andrius V)
tlp+acphy
ex+exphy
epic+qsphy
vge+ciphy (tested by Andrius V)
vr+ukphy (tested by Andrius V)
vte+ukphy (tested by Andrius V)

Not tested (MAC):
arm:at91emac
arm:cemac
arm:epe
arm:geminigmac
arm:enet
arm:cpsw
arm:emac(omac)
arm:emac(sunxi)
arm:npe
evbppc:temac
macppc:bm
macppc:gm
mips:aumac
mips:ae
mips:cnmac
mips:reth
mips:sbmac
playstation2:smap
powerpc:tsec
powerpc:emac(ibm4xx)
sgimips:mec
sparc:be
sf
ne(ax88190, dl10019)
awge
ep
gem
hme
smsh
mtd
sm
age
alc
ale
bce
cas
et
jme
lii
nfe
pcn
ste
stge
tl
xi
aue
mue
smsc
udav
url

Not tested (PHY):
amhphy
bmtphy
dmphy
etphy
glxtphy
ikphy
iophy
lxtphy
nsphyter
pnaphy
rdcphy
sqphy
tlphy
tqphy
urlphy
 1.103 26-Jun-2018  msaitoh branches: 1.103.2;
Implement the BPF direction filter (BIOC[GS]DIRECTION). It provides backward
compatibility with BIOC[GS]SEESENT ioctl. The userland interface is the same
as FreeBSD.

This change also fixes a bug that the direction is misunderstand on some
environment by passing the direction to bpf_mtap*() instead of checking
m->m_pkthdr.rcvif.
 1.102 20-Feb-2017  ozaki-r branches: 1.102.12;
Apply deferred if_start to more drivers
 1.101 15-Dec-2016  ozaki-r branches: 1.101.2;
Move bpf_mtap and if_ipackets++ on Rx of each driver to percpuq if_input

The benefits of the change are:
- We can reduce codes
- We can provide the same behavior between drivers
- Where/When if_ipackets is counted up
- Note that some drivers still update packet statistics in their own
way (periodical update)
- Moved bpf_mtap run in softint
- This makes it easy to MP-ify bpf

Proposed on tech-kern and tech-net
 1.100 10-Jun-2016  ozaki-r branches: 1.100.2;
Introduce m_set_rcvif and m_reset_rcvif

The API is used to set (or reset) a received interface of a mbuf.
They are counterpart of m_get_rcvif, which will come in another
commit, hide internal of rcvif operation, and reduce the diff of
the upcoming change.

No functional change.
 1.99 08-Jun-2016  pgoyette Revert previous (rev. 1.98). It breaks at least one user's card.

PR kern/44433
 1.98 01-Jun-2016  pgoyette Enable writing to the EPROM before trying to change our MAC address.

From PR kern/44433
 1.97 09-Feb-2016  ozaki-r Introduce softint-based if_input

This change intends to run the whole network stack in softint context
(or normal LWP), not hardware interrupt context. Note that the work is
still incomplete by this change; to that end, we also have to softint-ify
if_link_state_change (and bpf) which can still run in hardware interrupt.

This change softint-ifies at ifp->if_input that is called from
each device driver (and ieee80211_input) to ensure Layer 2 runs
in softint (e.g., ether_input and bridge_input). To this end,
we provide a framework (called percpuq) that utlizes softint(9)
and percpu ifqueues. With this patch, rxintr of most drivers just
queues received packets and schedules a softint, and the softint
dequeues packets and does rest packet processing.

To minimize changes to each driver, percpuq is allocated in struct
ifnet for now and that is initialized by default (in if_attach).
We probably have to move percpuq to softc of each driver, but it's
future work. At this point, only wm(4) has percpuq in its softc
as a reference implementation.

Additional information including performance numbers can be found
in the thread at tech-kern@ and tech-net@:
http://mail-index.netbsd.org/tech-kern/2016/01/14/msg019997.html

Acknowledgment: riastradh@ greatly helped this work.
Thank you very much!
 1.96 13-Apr-2015  riastradh Convert sys/dev to use <sys/rndsource.h>.
 1.95 10-Aug-2014  tls branches: 1.95.4;
Merge tls-earlyentropy branch into HEAD.
 1.94 22-Jul-2012  matt branches: 1.94.2; 1.94.12;
Fix mii_statchg to take a 'struct ifnet *' instead of device_t. This fixes
problem with a common MDIO bus used for multiple interfaces.
Some drivers converted to CFATTACL_DECL_NEW.
 1.93 02-Feb-2012  tls Entropy-pool implementation move and cleanup.

1) Move core entropy-pool code and source/sink/sample management code
to sys/kern from sys/dev.

2) Remove use of NRND as test for presence of entropy-pool code throughout
source tree.

3) Remove use of RND_ENABLED in device drivers as microoptimization to
avoid expensive operations on disabled entropy sources; make the
rnd_add calls do this directly so all callers benefit.

4) Fix bug in recent rnd_add_data()/rnd_add_uint32() changes that might
have lead to slight entropy overestimation for some sources.

5) Add new source types for environmental sensors, power sensors, VM
system events, and skew between clocks, with a sample implementation
for each.

ok releng to go in before the branch due to the difficulty of later
pullup (widespread #ifdef removal and moved files). Tested with release
builds on amd64 and evbarm and live testing on amd64.
 1.92 13-Nov-2010  uebayasi branches: 1.92.8; 1.92.12;
Don't pull in the whole uvm(9) API to access only PAGE_SIZE and
some other constants. These are provided by sys/param.h now.
 1.91 27-Jul-2010  jakllsch Make the Realtek PCI network interfaces detachable.
Use __arraycount to avoid null table entries.
Miscellaneous other touch-ups in bus front-ends.
 1.90 05-Apr-2010  joerg Push the bpf_ops usage back into bpf.h. Push the common ifp->if_bpf
check into the inline functions as well the fourth argument for
bpf_attach.
 1.89 28-Mar-2010  snj Spell "enough" properly.
 1.88 19-Jan-2010  pooka branches: 1.88.2; 1.88.4;
Redefine bpf linkage through an always present op vector, i.e.
#if NBPFILTER is no longer required in the client. This change
doesn't yet add support for loading bpf as a module, since drivers
can register before bpf is attached. However, callers of bpf can
now be modularized.

Dynamically loadable bpf could probably be done fairly easily with
coordination from the stub driver and the real driver by registering
attachments in the stub before the real driver is loaded and doing
a handoff. ... and I'm not going to ponder the depths of unload
here.

Tested with i386/MONOLITHIC, modified MONOLITHIC without bpf and rump.
 1.87 15-Sep-2009  dyoung Simplify activation routines: do not call mii_activate(), it is a
no-op. Do not block interrupts, if_deactivate() will take care of
that for us.
 1.86 27-Apr-2009  tsutsui Wrap one more printf() with #ifdef DEBUG, which was missed on rev 1.52.
 1.85 26-Apr-2009  tsutsui Always make local functions static. Local symbols are still preserved
on link by ld(1) with -X option on most ports for debug.
 1.84 26-Apr-2009  tsutsui - use (uint8_t *) for RX buffer
- remove unnecessary pointer casts
 1.83 25-Apr-2009  tsutsui Use roundup2() macro.
 1.82 25-Apr-2008  tsutsui branches: 1.82.2; 1.82.10; 1.82.16;
Split device_t/softc for re(4) and rtk(4).
 1.81 19-Jan-2008  dyoung branches: 1.81.6; 1.81.8;
Make many ethernet drivers share the common code for MII media
handling, ether_mediastatus() and ether_mediachange(). Check for
a non-ENXIO error return from mii_mediachg(). (ENXIO indicates
that a PHY is suspended.)

This patch shrinks the source code size by 979 lines. There was
a 5100-byte savings on the NetBSD/i386 kernel configuration, ALL.

I have made a few miscellaneous changes, too:

gem(4): use LIST_EMPTY(), LIST_FOREACH().
mtd(4): handle media ioctls, for a change!
axe(4): do not track link status in sc->axe_link any longer
nfe(4), aue(4), axe(4), udav(4), url(4): do not reset all PHYs
on a change of media

Except for the change to mtd(4), no functional changes are intended.

XXX This patch affects more architectures than I can feasibly
XXX compile and run. I have compiled macppc, sparc64, i386. I
XXX have run the patches on i386 boxen with bnx(4) and sip(4).
XXX Compiling and running on evbmips (MERAKI, ADM5120) is in
XXX progress.
 1.80 08-Jan-2008  joerg Short-cut interrupt processing if device has been suspended.
uvm_fault reported by xtraeme.
 1.79 09-Dec-2007  jmcneill branches: 1.79.2;
Merge jmcneill-pm branch.
 1.78 06-Nov-2007  uwe branches: 1.78.2; 1.78.4;
Use device_t and device_private(). Convert attach to use aprint_*.
 1.77 19-Oct-2007  ad branches: 1.77.2;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.76 26-Aug-2007  dyoung branches: 1.76.2; 1.76.6;
Constify: LLADDR -> CLLADDR. I'm aiming here to make it easier to
identify sockaddr_dl abuse that remains in the kernel, especially
the potential for overwriting memory past the end of a sockaddr_dl
with, e.g., memcpy(LLADDR(), ...).
 1.75 09-Jul-2007  ad branches: 1.75.2; 1.75.6;
Merge some of the less invasive changes from the vmlocking branch:

- kthread, callout, devsw API changes
- select()/poll() improvements
- miscellaneous MT safety improvements
 1.74 18-May-2007  joerg If the interrupt status register reads as 0xffff in rtk_intr, assume
that the card is gone and abort the loop. This fixes hot-plugging of
cardbus cards.

From FreeBSD's rl(4).
 1.73 18-May-2007  joerg Make rtk_list_tx_init return void. The return value was constant and
never used.
 1.72 21-Mar-2007  tsutsui Cleanup handling of quikrs on each RealTek chip:
- replace rtk_type member in rtk_softc which has chip types
with new rtk_quirk that represents quirks on each chip:
- RTKQ_8129 doesn't have internal MII (used in rtk(4))
- RTKQ_8139CPLUS has different register layout (for re(4))
- RTKQ_8169NONS (original 8169) requires some settings on init
- RTKQ_PCIE requires different settings in setmulti
so that we don't have to check each hwrev values or types everywhere
and newer variants will also work without changes if they don't
have other quirks
(sc_rev is unchenged for now for reference to the Realtek's driver)
- don't check hwrev register in re_pci_match() but check
only PCI_VENDER(), PCI_PRODUCT() and PCI_REVISION()
so that we no longer have to map pci space there
- add a new HWREV value for another 8168 variant
- try to map PCI mem space more properly
- remove (probably unneeded) ifp->if_baudrate initialization

Tested on a newer 8168 variant by Dennis den Brok on tech-kern,
and also tested on 8139 and 8169C on macppc, and 8139C+ on landisk
by me.
 1.71 04-Mar-2007  christos branches: 1.71.2; 1.71.4; 1.71.6;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.70 16-Feb-2007  tsutsui branches: 1.70.2;
RTK_HWREV_8100E_SPIN2 is a PCIe device so also check it
in rtk_setmulti() to handle quirk. Noticed by OpenBSD.
 1.69 10-Feb-2007  tsutsui Pull a multicast fix from FreeBSD's if_re.c rev 1.81:
Fix rtk_setmulti() so that it works correctly for PCIe chips where
the multicast hash table are in reverse order compared to older
devices.

Closes PR kern/35579 from Nino Dehne.
 1.68 04-Feb-2007  tsutsui Accept RX packets which are larger than ETHER_MAX_LEN but can be stored
into RX mbufs. Inspired by OpenBSD.
 1.67 29-Jan-2007  tsutsui Fix EEPROM functions for RTL8169SC chips:

rtl81x9.c:
Increase delay on EEPROM access since EEPROM on RTL8169 based board
seems to require slower clock. Also use common EE_DELAY() macro.

rtl8169.c:
Use common rtk_read_eeprom() function to get Ethernet address on
8169 chips because EEMODE_AUTOLOAD command was a workaround on
original FreeBSD's driver and it doesn't work on 8169SC.

Problem reported and fix tested by Frank Lorenzen on current-users,
and also tested on 8139C with rtk(4) driver by me.
 1.66 16-Nov-2006  christos branches: 1.66.2;
__unused removal on arguments; approved by core.
 1.65 05-Nov-2006  tsutsui - make TX threshold macro more generic
- no need to bother to initialize sc_txthresh in rtk_attach()
since it's done in rtk_init()
 1.64 12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.63 29-Sep-2006  tsutsui - KNF
- u_intNN_t -> uintNN_t
- misc cosmetics
 1.62 29-Sep-2006  tsutsui ANSIfy.
 1.61 29-Sep-2006  tsutsui TAB/space cleanup.
 1.60 29-Sep-2006  tsutsui Set a timeout only if any TX packet is actually queued.
 1.59 29-Sep-2006  tsutsui rtk_intr() should return 1 only if any interrupts are actually handled.
 1.58 29-Sep-2006  tsutsui Use `SIMPLEQ_EMPTY()' rather than `SIMPLEQ_FIRST() == NULL'.
 1.57 29-Sep-2006  tsutsui Handle more wraparound case on RX ring-buffer calculation.
(it might cause problem only if RTK_RXBUFLEN < 64KB)
 1.56 29-Sep-2006  tsutsui Pull mii_readreg fix from FreeBSD if_rl.c rev 1.81:

> When reading PHY regs over the i2c bus, the turnaround ACK bit
> is read one clock edge too late. This bit is driven low by
> slave (as any other input data bits from slave) when the clock
> is LOW. The current code did read the bit after the clock was
> driven high again.
 1.55 29-Sep-2006  tsutsui In rtk_txeof(), clear the timeout timer only if there is no pending packet.
 1.54 29-Sep-2006  tsutsui In rtk_rxeof():
- discard too short packets as well as too large ones
- trim CRC off rather than setting M_HASFCS

Closes PR kern/31348.
 1.53 24-Sep-2006  jmcneill Add "name" parameter to powerhook_establish, to aid debugging. No objections
on tech-kern@
 1.52 08-Dec-2005  xtraeme branches: 1.52.20; 1.52.22;
Not everyone want to see debugging printf()s unless "options DEBUG"
is compiled in.
 1.51 27-Feb-2005  perry branches: 1.51.2; 1.51.4;
nuke trailing whitespace
 1.50 13-Feb-2005  jdolecek KNF
 1.49 04-Feb-2005  perry de-__P
 1.48 23-Jan-2005  dan branches: 1.48.2;
attach rtk(4) as an event source to rnd(4)
patches from Sean Davis in PR/28547
(also added a detach hook)
 1.47 30-Oct-2004  thorpej branches: 1.47.4;
When adding/deleting multicast addresses, only whack the address
filter if the interface is marked RUNNING.

Fixes kern/27678.
 1.46 28-May-2004  toshii A couple of changes for adding re(4) (Realtek gigabit ethernet):
- add necessary members in rtk_softc
- make functions used by re(4) non-static
 1.45 21-Feb-2003  tsutsui branches: 1.45.2; 1.45.4;
hz -> Hz
 1.44 15-Jan-2003  bouyer Use a properly zero'd buffer to pad the packet to ETHER_MIN_LEN-ETHER_CRC_LEN
 1.43 07-Nov-2002  thorpej Fix signed/unsigned comparison warnings.
 1.42 22-Oct-2002  fair Change the "dontcare bits" argument to ifmedia_init() to IFM_IMASK
so that it is possible select PHY instances other than the first
one (instance zero), if there is more than one PHY attached.
 1.41 01-Jun-2002  lukem SIMPLEQ rototill:
- implement SIMPLEQ_REMOVE(head, elm, type, field). whilst it's O(n),
this mirrors the functionality of SLIST_REMOVE() (the other
singly-linked list type) and FreeBSD's STAILQ_REMOVE()
- remove the unnecessary elm arg from SIMPLEQ_REMOVE_HEAD().
this mirrors the functionality of SLIST_REMOVE_HEAD() (the other
singly-linked list type) and FreeBSD's STAILQ_REMOVE_HEAD()
- remove notes about SIMPLEQ not supporting arbitrary element removal
- use SIMPLEQ_FOREACH() instead of home-grown for loops
- use SIMPLEQ_EMPTY() appropriately
- use SIMPLEQ_*() instead of accessing sqh_first,sqh_last,sqe_next directly
- reorder manual page; be consistent about how the types are listed
- other minor cleanups
 1.40 13-Nov-2001  lukem branches: 1.40.8; 1.40.10;
add/cleanup RCSID
 1.39 20-Aug-2001  wiz precede, not preceed, and a whitespace fix.
 1.38 14-Aug-2001  mrg mtod() with uintptr_t, not bus_addr_t.
 1.37 07-Aug-2001  kanaoka Fix typo in a message.
 1.36 25-Jul-2001  kanaoka - Increase Early TX threshold if underrun occurred.
 1.35 19-Jul-2001  thorpej Use BUS_DMA_READ and BUS_DMA_WRITE in some obvious places.
 1.34 07-Jul-2001  thorpej branches: 1.34.2;
bzero -> memset
 1.33 07-Jul-2001  thorpej bcopy -> strcpy
 1.32 12-Jun-2001  thorpej Don't need INET or NS includes here.
 1.31 02-Feb-2001  thorpej branches: 1.31.2;
Rework the transmit logic. Use a "free" and "dirty" list of
transmit jobs. The previous logic occasionally, under heavy
load, would attempt to sync and unload DMA maps that weren't
currently in use, and also occasionally leaked mbufs under
heavy load.

Yay, NFS now works pretty well on my Dreamcast.
 1.30 02-Feb-2001  thorpej Put the rx buf pointer into the softc directly.
 1.29 01-Feb-2001  thorpej Fix a bug in ring-buffer wrap calculation. On the Dreamcast,
it causes assertions to fail in the PCI bounce buffer code. On
other platforms, it causes the address of the next packet to
be mis-calculated, leading to packet loss.
 1.28 29-Jan-2001  enami Handle allmulti case correctly as a NetBSD network driver;
if we are requested range of multicast address or too many multicast address,
program multicast filter to receive all multicast address. And set/clear
IFF_ALLMULTI flag properly.
 1.27 11-Jan-2001  tsutsui Don't copy Rx packet to mbuf if it has invalid length; just discard it.
Fixes kern/11877.
 1.26 19-Dec-2000  thorpej Fix a problem with the ALTQ changes that can cause bogus memory
refernces. Problem reported by Luke Mewburn.
 1.25 14-Dec-2000  thorpej ALTQ'ify.
 1.24 09-Dec-2000  tsutsui Add (missed) bus_dmemem_free() in rtk_detach().
 1.23 05-Dec-2000  tsutsui - Since rtk_rxeof() was rewritten, we don't have to reserve a few bytes
before the Rx buffer.
- Reduce delay on EEPROM access.
- Some more cosmetics.
 1.22 03-Dec-2000  tsutsui Clean up receive interrupt routine:
- Use MGETHDR + MCLGET + memcpy rathar than m_devget + m_adj + m_copyback.
- Call bus_dmamap_sync(9) correctly for Rx buffer.

Mostly from thorpej's if_rtp.c.
 1.21 30-Nov-2000  tsutsui Clarify RX status header length and some cosmetics.
 1.20 30-Nov-2000  tsutsui After rev 1.16 rtk driver uses the CRC from the chip,
so no need to adjust Rx address for it. Fixes kern/11301.
 1.19 26-Nov-2000  takemura Add new powerhook argument values, PWR_SOFTSUSPEND, PWR_SOFTSTANDBY and
PWR_SOFTRESUME. Apm calls powerhook with the values in normal interrupt
priority level while others are protected with splhigh().
 1.18 15-Nov-2000  thorpej branches: 1.18.2;
Move bpfattach()/bpfdetach() calls into ether_ifattach()/ether_ifdetach().
 1.17 14-Nov-2000  thorpej NBPG -> PAGE_SIZE
 1.16 15-Oct-2000  thorpej Don't trim off the FCS, pass it up.
 1.15 11-Oct-2000  thorpej Use ether_ioctl().
 1.14 01-Oct-2000  thorpej Move the check for "promisc + unicast + not for us" into ether_input(),
and change Ethernet drivers to always pass all received frames to
ether_input() (with a few exceptions, which are documented in the
code).
 1.13 25-Sep-2000  enami Fix merge lossage in disabled code.
 1.12 01-Sep-2000  drochner -fix multicast filter programming
-support access to MII_ANER too for completeness
-remove some hacks which disappeared in FreeBSD if_rl.c
rev. 1.25 (Aug 31 14:45:49 1999)
(the driver could need more updating, but this is what I've tested
for months)
 1.11 21-May-2000  tsutsui branches: 1.11.4;
Call bus_dmamap_unload() if any Tx mbuf remains in rtk_stop().
 1.10 19-May-2000  tsutsui - Change RL_* -> RTK_*
- Free bus_dma resources if attach fails
- Add detach and power management code

Patch from Masanori Kanaoka <kanaoka@ann.hi-ho.ne.jp> in kern/10156.
 1.9 15-May-2000  thorpej splimp() -> splnet()
 1.8 15-May-2000  thorpej Symbol namespace cleanup: rl_ -> rtk_
 1.7 12-May-2000  thorpej Use ether_crc32_be().
 1.6 01-May-2000  tsutsui - Move some initialization into MI rl_attach() from each bus attachment.
- Use proper CARDBUS_* macro in if_rl_cardbus.c
- Use product ID read from PCI configuration space rather than from EEPROM
in if_rl_pci.c.

Patch sent from Masanori Kanaoka <kanaoka@ann.hi-ho.ne.jp> and
some cosmetic changes by me.
 1.5 30-Apr-2000  tsutsui Modify EEPROM read functions and handle also 9356 EEPROM.
Fixes kern/9861.
 1.4 26-Apr-2000  tsutsui - Allocate mbuf dynamically on Tx and use bus_dmamap_load_mbuf(9).
- Call bus_dmamap_sync(9) as appropriate.
- Leave only register declarations in rtl81x9reg.h and
split other stuff into rtl81x9var.h.

bus_dma(9) code mostly taken from thorpej's if_rtp.c.
 1.3 25-Apr-2000  tsutsui Fix two endian problems. rtk now works on macppc.

- Use le32toh() on reading rxstat from the Rx DMA buffer.
- rl_read_eeprom() should return EEPROM values in little endian
when caller requires byte-stream data.

bus_dma(9) fixes are still on-going.

XXX rtk on macppc seems to make tons of CRC errors...
XXX Does it work fine on i386 or others?
 1.2 24-Apr-2000  tsutsui Merge changes of sys/pci/if_rl.c rev. 1.8->1.10. (from kern/9870)
Also remove unused pbase, vbase and PCI_CAP_PWRMGMT declarations.
 1.1 10-Apr-2000  haya Incorporate the changes of RL81x9 driver provided by M. Kanaoka
<kanaoka@ann.hi-ho.ne.jp>. He separated the driver into IC specific
portion and bus attachment portion and added cardbus attachent.
 1.11.4.6 27-Oct-2001  he Pull up revisions 1.29-1.31,1.33-1.34,1.36 (via patch, requested by jdolecek):
Apply assorted stability fixes:
o increase early TX threshold if underrun occurred
o reworked transmit logic
o fix bug in ring-buffer wrap calculation
Should fix problems with hung network interfaces of this type.
Tested by jdolecek on 1.5.1.
 1.11.4.5 06-May-2001  he Pull up revision 1.19 (via patch, requested by he):
Add new powerhook argument values, PWR_SOFTSUSPEND, PWR_SOFTSTANDBY and
PWR_SOFTRESUME. Apm calls powerhook with the values in normal interrupt
priority level while others are protected with splhigh().
 1.11.4.4 13-Mar-2001  he Pull up revision 1.28 (requested by tsutsui):
Handle allmulti case correctly as a NetBSD network driver;
if we are requested range of multicast address or too many
multicast address, program multicast filter to receive all
multicast address. And set/clear IFF_ALLMULTI flag properly.
 1.11.4.3 26-Feb-2001  he Pull up revision 1.27 (requested by tsutsui):
Don't copy Rx packet to mbuf if it has invalid length; just
discard. Fixes PR#11877.
 1.11.4.2 25-Jan-2001  jhawk Pull up revisions 1.12, 1.21-1.24 via patch (requested by tsutsui):
Clean up receive interrupt routine and fix DMA buffer handing
for receive buffering.
Add missed bus_dmamem_free() in rtk_detach().
Some cosmetic fixes.
 1.11.4.1 11-Sep-2000  drochner pull up rev. 1.12 (approved by thorpej):
-fix multicast filter programming
-support access to MII_ANER too for completeness
-remove some hacks which disappeared in FreeBSD if_rl.c
rev. 1.25 (Aug 31 14:45:49 1999)
(the driver could need more updating, but this is what I've tested
for months)
 1.18.2.8 11-Feb-2001  bouyer Sync with HEAD.
 1.18.2.7 18-Jan-2001  bouyer Sync with head (for UBC+NFS fixes, mostly).
 1.18.2.6 05-Jan-2001  bouyer Sync with HEAD
 1.18.2.5 13-Dec-2000  bouyer Sync with HEAD (for UBC fixes).
 1.18.2.4 08-Dec-2000  bouyer Sync with HEAD.
 1.18.2.3 22-Nov-2000  bouyer Sync with HEAD.
 1.18.2.2 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.18.2.1 15-Nov-2000  bouyer file rtl81x9.c was added on branch thorpej_scsipi on 2000-11-20 11:40:53 +0000
 1.31.2.6 17-Jan-2003  thorpej Sync with HEAD.
 1.31.2.5 11-Nov-2002  nathanw Catch up to -current
 1.31.2.4 20-Jun-2002  nathanw Catch up to -current.
 1.31.2.3 14-Nov-2001  nathanw Catch up to -current.
 1.31.2.2 24-Aug-2001  nathanw Catch up with -current.
 1.31.2.1 21-Jun-2001  nathanw Catch up to -current.
 1.34.2.4 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.34.2.3 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.34.2.2 25-Aug-2001  thorpej Merge Aug 24 -current into the kqueue branch.
 1.34.2.1 03-Aug-2001  lukem update to -current
 1.40.10.1 26-Jan-2003  he Pull up revision 1.44 (via patch, requested by bouyer in ticket #1086):
Use a properly zeroed buffer to pad small packets to make
sure the chip doesn't send random data.
 1.40.8.1 20-Jun-2002  gehenna catch up with -current.
 1.45.4.1 21-Jun-2004  tron branches: 1.45.4.1.2;
Pull up revision 1.46 (requested by toshii in ticket #517):
A couple of changes for adding re(4) (Realtek gigabit ethernet):
- add necessary members in rtk_softc
- make functions used by re(4) non-static
 1.45.4.1.2.2 16-Apr-2005  tron Pull up revision 1.48 (requested by dan in ticket #1116):
attach rtk(4) as an event source to rnd(4)
patches from Sean Davis in PR/28547
(also added a detach hook)
 1.45.4.1.2.1 24-Jan-2005  he Pull up revision 1.47 (requested by thorpej in ticket #939):
When adding or deleting multicast addresses, only change
the address filter if the interface is marked RUNNING.
Fixes PR#27678.
 1.45.2.9 11-Dec-2005  christos Sync with head.
 1.45.2.8 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.45.2.7 15-Feb-2005  skrll Sync with HEAD.
 1.45.2.6 04-Feb-2005  skrll Sync with HEAD.
 1.45.2.5 24-Jan-2005  skrll Sync with HEAD.
 1.45.2.4 02-Nov-2004  skrll Sync with HEAD.
 1.45.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.45.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.45.2.1 03-Aug-2004  skrll Sync with HEAD
 1.47.4.1 29-Apr-2005  kent sync with -current
 1.48.2.2 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.48.2.1 12-Feb-2005  yamt sync with head.
 1.51.4.7 21-Jan-2008  yamt sync with head
 1.51.4.6 15-Nov-2007  yamt sync with head.
 1.51.4.5 27-Oct-2007  yamt sync with head.
 1.51.4.4 03-Sep-2007  yamt sync with head.
 1.51.4.3 26-Feb-2007  yamt sync with head.
 1.51.4.2 30-Dec-2006  yamt sync with head.
 1.51.4.1 21-Jun-2006  yamt sync with head.
 1.51.2.2 04-Oct-2007  bouyer Pull up following revision(s) (requested by tsutsui in ticket #1852):
sys/dev/ic/rtl81x9var.h: revision 1.39
sys/dev/cardbus/if_re_cardbus.c: revision 1.13
sys/dev/pci/if_re_pci.c: revision 1.27 via patch
sys/dev/pci/if_rtk_pci.c: revision 1.32
sys/dev/cardbus/if_rtk_cardbus.c: revision 1.32
sys/dev/ic/rtl8169.c: revision 1.84, 1.85
sys/dev/ic/rtl81x9reg.h: revision 1.27
sys/dev/ic/rtl81x9.c: revision 1.72
Cleanup handling of quikrs on each RealTek chip:
Pull a fix for PCIe variants from FreeBSD
 1.51.2.1 03-Mar-2007  bouyer Pull up following revision(s) (requested by tsutsui in ticket #1673):
distrib/sets/lists/man/mi 1.844, 1.871
share/man/man4/Makefile 1.372, 1.379 via patch
share/man/man4/re.4 1.8, 1.9, 1.11, 1.12
share/man/man4/rgephy.4 1.1
share/man/man4/rlphy.4 1.1, 1.2
sys/arch/amd64/conf/GENERIC 1.79, 1.89
sys/arch/amd64/conf/INSTALL 1.45, 1.49
sys/arch/i386/conf/GENERIC 1.717, 1.747
sys/arch/i386/conf/GENERIC_LAPTOP 1.164
sys/arch/i386/conf/INSTALL 1.277, 1.283
sys/arch/i386/conf/INSTALL_LAPTOP 1.96, 1.98
sys/arch/i386/conf/XEN2_DOM0 1.22 via patch
sys/arch/macppc/conf/GENERIC 1.220, 1.246
sys/arch/macppc/conf/INSTALL 1.96, 1.100
sys/dev/cardbus/if_re_cardbus.c 1.10
sys/dev/cardbus/if_rtk_cardbus.c 1.29-1.31
sys/dev/ic/rtl8169.c 1.14, 1.20, 1.24, 1.25, 1.28-1.61, 1.63, 1.64-1.81 via patch
sys/dev/ic/rtl81x9.c 1.52, 1.54-1.63, 1.65, 1.67-1.70
sys/dev/ic/rtl81x9reg.h 1.15-1.26
sys/dev/ic/rtl81x9var.h 1.19, 1.21-1.37
sys/dev/mii/files.mii 1.38
sys/dev/mii/miidevs 1.62, 1.64
sys/dev/mii/rgephy.c 1.10, 1.13-1.16
sys/dev/mii/rlphy.c 1.1, 1.6, 1.7, 1.11 via patch
sys/dev/pci/if_re_pci.c 1.13, 1.15-1.17, 1.19-1.23
sys/dev/pci/if_rtk_pci.c 1.25, 1.28, 1.29, 1.31
sys/dev/pci/pcidevs 1.851, 1.852

on re(4):
- improve stability (I believe ;-)
- add a workaround for hardware ip4csum-tx bug
- support newer chips (8169SB/SC, PCIe based 8168 etc.)
- fix 8139C+ support
- enable hardware VLAN
- misc bus_dma(9) fix (which makes re(4) work on mips ports)

on rtk(4):
- fix kern/31348
- fix possible panic on dreamcast
 1.52.22.2 10-Dec-2006  yamt sync with head.
 1.52.22.1 22-Oct-2006  yamt sync with head
 1.52.20.3 09-Feb-2007  ad Sync with HEAD.
 1.52.20.2 01-Feb-2007  ad Sync with head.
 1.52.20.1 18-Nov-2006  ad Sync with head.
 1.66.2.6 24-May-2007  riz Pull up following revision(s) (requested by joerg in ticket #663):
sys/dev/ic/rtl81x9.c: revision 1.74
If the interrupt status register reads as 0xffff in rtk_intr, assume
that the card is gone and abort the loop. This fixes hot-plugging of
cardbus cards.
From FreeBSD's rl(4).
 1.66.2.5 16-May-2007  jdc Pull up revision 1.72 (requested by tsutsui in ticket #640).

Cleanup handling of quikrs on each RealTek chip:
- replace rtk_type member in rtk_softc which has chip types
with new rtk_quirk that represents quirks on each chip:
- RTKQ_8129 doesn't have internal MII (used in rtk(4))
- RTKQ_8139CPLUS has different register layout (for re(4))
- RTKQ_8169NONS (original 8169) requires some settings on init
- RTKQ_PCIE requires different settings in setmulti
so that we don't have to check each hwrev values or types everywhere
and newer variants will also work without changes if they don't
have other quirks
(sc_rev is unchenged for now for reference to the Realtek's driver)
- don't check hwrev register in re_pci_match() but check
only PCI_VENDER(), PCI_PRODUCT() and PCI_REVISION()
so that we no longer have to map pci space there
- add a new HWREV value for another 8168 variant
- try to map PCI mem space more properly
- remove (probably unneeded) ifp->if_baudrate initialization

Tested on a newer 8168 variant by Dennis den Brok on tech-kern,
and also tested on 8139 and 8169C on macppc, and 8139C+ on landisk
by me.
 1.66.2.4 24-Feb-2007  bouyer branches: 1.66.2.4.2;
Pull up following revision(s) (requested by tsutsui in ticket #462):
sys/dev/ic/rtl8169.c: revision 1.80 - 1.81
sys/dev/ic/rtl81x9.c: revision 1.70
Use new RTK_HWREV_8100E_SPIN2 macro. (missed in the previous)
Don't set RTK_CFG1_FULLDUPLEX bit in RTK_CFG1 register
since it's available only on RTL8129. From FreeBSD.
As defined in rtl81x9reg.h, bits of 0x80 and 0x40 in RTK_CFG1
seem to indicate LEDS0 and LEDS1 configuration initialized by
EEPROM settings, and they seem read only on my quick tests with
two 8169S based cards.
RTK_HWREV_8100E_SPIN2 is a PCIe device so also check it
in rtk_setmulti() to handle quirk. Noticed by OpenBSD.
 1.66.2.3 10-Feb-2007  tron Pull up following revision(s) (requested by tsutsui in ticket #437):
sys/dev/ic/rtl81x9.c: revision 1.69
Pull a multicast fix from FreeBSD's if_re.c rev 1.81:
Fix rtk_setmulti() so that it works correctly for PCIe chips where
the multicast hash table are in reverse order compared to older
devices.
Closes PR kern/35579 from Nino Dehne.
 1.66.2.2 10-Feb-2007  tron Pull up following revision(s) (requested by tsutsui in ticket #437):
sys/dev/ic/rtl81x9.c: revision 1.68
Accept RX packets which are larger than ETHER_MAX_LEN but can be stored
into RX mbufs. Inspired by OpenBSD.
 1.66.2.1 10-Feb-2007  tron Pull up following revision(s) (requested by tsutsui in ticket #437):
sys/dev/ic/rtl81x9.c: revision 1.67
sys/dev/ic/rtl8169.c: revision 1.77
Fix EEPROM functions for RTL8169SC chips:
rtl81x9.c:
Increase delay on EEPROM access since EEPROM on RTL8169 based board
seems to require slower clock. Also use common EE_DELAY() macro.
rtl8169.c:
Use common rtk_read_eeprom() function to get Ethernet address on
8169 chips because EEMODE_AUTOLOAD command was a workaround on
original FreeBSD's driver and it doesn't work on 8169SC.
Problem reported and fix tested by Frank Lorenzen on current-users,
and also tested on 8139C with rtk(4) driver by me.
 1.66.2.4.2.2 04-Jun-2007  wrstuden Update to today's netbsd-4.
 1.66.2.4.2.1 03-Jun-2007  wrstuden Catch up with now-somewhat-dated netbsd-4. These changes took longer
than expected for me to actually get around to merging.
 1.70.2.2 24-Mar-2007  yamt sync with head.
 1.70.2.1 12-Mar-2007  rmind Sync with HEAD.
 1.71.6.1 29-Mar-2007  reinoud Pullup to -current
 1.71.4.1 11-Jul-2007  mjf Sync with head.
 1.71.2.5 23-Oct-2007  ad Sync with head.
 1.71.2.4 09-Oct-2007  ad Sync with head.
 1.71.2.3 01-Jul-2007  ad Adapt to callout API change.
 1.71.2.2 27-May-2007  ad Sync with head.
 1.71.2.1 10-Apr-2007  ad Sync with head.
 1.75.6.4 06-Nov-2007  joerg Sync with HEAD.
 1.75.6.3 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.75.6.2 05-Oct-2007  joerg Remove the power management nonsense in the PCI versions of
rtk(4) and re(4). It is not really likely to work anyway.
Use PNP power management for the cardbus attachment as well and
remove the power management handlers from the chipset code.
 1.75.6.1 03-Sep-2007  jmcneill Sync with HEAD.
 1.75.2.1 03-Sep-2007  skrll Sync with HEAD.
 1.76.6.2 13-Nov-2007  bouyer Sync with HEAD
 1.76.6.1 25-Oct-2007  bouyer Sync with HEAD.
 1.76.2.3 23-Mar-2008  matt sync with HEAD
 1.76.2.2 09-Jan-2008  matt sync with HEAD
 1.76.2.1 06-Nov-2007  matt sync with HEAD
 1.77.2.3 18-Feb-2008  mjf Sync with HEAD.
 1.77.2.2 27-Dec-2007  mjf Sync with HEAD.
 1.77.2.1 19-Nov-2007  mjf Sync with HEAD.
 1.78.4.1 11-Dec-2007  yamt sync with head.
 1.78.2.1 26-Dec-2007  ad Sync with head.
 1.79.2.2 20-Jan-2008  bouyer Sync with HEAD
 1.79.2.1 08-Jan-2008  bouyer Sync with HEAD
 1.81.8.1 18-May-2008  yamt sync with head.
 1.81.6.1 02-Jun-2008  mjf Sync with HEAD.
 1.82.16.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.82.10.1 28-Apr-2009  skrll Sync with HEAD.
 1.82.2.4 11-Aug-2010  yamt sync with head.
 1.82.2.3 11-Mar-2010  yamt sync with head
 1.82.2.2 16-Sep-2009  yamt sync with head
 1.82.2.1 04-May-2009  yamt sync with head.
 1.88.4.2 05-Mar-2011  rmind sync with head
 1.88.4.1 30-May-2010  rmind sync with head
 1.88.2.2 17-Aug-2010  uebayasi Sync with HEAD.
 1.88.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.92.12.1 18-Feb-2012  mrg merge to -current.
 1.92.8.2 30-Oct-2012  yamt sync with head
 1.92.8.1 17-Apr-2012  yamt sync with head
 1.94.12.1 07-Apr-2014  tls Be a little more clear and consistent about harvesting entropy from devices:

1) deprecate RND_FLAG_NO_ESTIMATE

2) define RND_FLAG_COLLECT_TIME, RND_FLAG_COLLECT_VALUE

3) define RND_FLAG_ESTIMATE_TIME, RND_FLAG_ESTIMATE_VALUE

4) define RND_FLAG_DEFAULT: RND_FLAG_COLLECT_TIME|
RND_FLAG_COLLECT_VALUE|RND_FLAG_ESTIMATE_TIME

5) Make entropy harvesting from environmental sensors a little more generic
and remove it from individual sensor drivers.

6) Remove individual open-coded delta-estimators for values from a few
places in the tree (uvm, environmental drivers).

7) 0 -> RND_FLAG_DEFAULT, actually gather entropy from various drivers
that had stubbed out code, other minor cleanups.
 1.94.2.2 03-Dec-2017  jdolecek update from HEAD
 1.94.2.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.95.4.5 28-Aug-2017  skrll Sync with HEAD
 1.95.4.4 05-Feb-2017  skrll Sync with HEAD
 1.95.4.3 09-Jul-2016  skrll Sync with HEAD
 1.95.4.2 19-Mar-2016  skrll Sync with HEAD
 1.95.4.1 06-Jun-2015  skrll Sync with HEAD
 1.100.2.2 20-Mar-2017  pgoyette Sync with HEAD
 1.100.2.1 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.101.2.1 21-Apr-2017  bouyer Sync with HEAD
 1.102.12.2 26-Jan-2019  pgoyette Sync with HEAD
 1.102.12.1 28-Jul-2018  pgoyette Sync with HEAD
 1.103.2.3 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.103.2.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.103.2.1 10-Jun-2019  christos Sync with HEAD
 1.106.2.1 28-Jan-2020  martin Pull up following revision(s) (requested by msaitoh in ticket #667):

sys/dev/ic/rtl81x9var.h: revision 1.57
sys/dev/ic/rtl81x9.c: revision 1.107
sys/dev/ic/rtl81x9reg.h: revision 1.51
sys/dev/ic/rtl8169.c: revision 1.160
sys/dev/ic/rtl81x9reg.h: revision 1.52
sys/dev/ic/rtl8169.c: revision 1.161

Use unsigned in rtk_setmulti() to avoid undefined behavior. Found bk kUBSan.
8168H model didn't link up well. some models seems to require to enable TX/RX after configuration.
RTKQ_TXRXEN_LATER quirk flag added. it may be able to unify with RTKQ_RXDV_GATED flag?
Sort RTK_HWREV_* by value.

Improve some chip revisions support:
- Add 8168FP, 8411, 8168G, 8401E, 8105E, 8105E_SPIN1, 8106E and 8402 from
{Free,Open}BSD.
- Renumber RTK_HWREV_8103E from 0x24C00000 to 0x34c00000. 0x24C00000 is newly
used as RTK_HWREV_8102EL_SPIN1. Same as {Free,Open}BSD.
 1.107.2.1 29-Feb-2020  ad Sync with head.
 1.55 12-Aug-2024  christos PR/58588: Christos Zoulas: Avoid crashes when exiting promiscuous mode (^C
tcpdump) by disabling RX in re_stop. Also add some earlyoff stuff while here.
From FreeBSD.
 1.54 21-Sep-2020  msaitoh branches: 1.54.26;
- Print chip revision. From OpenBSD.
- Rename RTK_HWREV_8168_SPIN[123] to RTK_HWREV_8168'B'_SPIN[123].
Same as other *BSDs.
- Rename RTK_HWREV_8168G_SPIN4 to RTK_HWREV_8411B. Same as other *BSDs.
- Add definition of RTK_HWREV_8169_8110SCE.
 1.53 13-Mar-2020  thorpej Use BUS_ADDR_{LO,HI}32().
 1.52 17-Dec-2019  msaitoh Improve some chip revisions support:

- Add 8168FP, 8411, 8168G, 8401E, 8105E, 8105E_SPIN1, 8106E and 8402 from
{Free,Open}BSD.
- Renumber RTK_HWREV_8103E from 0x24C00000 to 0x34c00000. 0x24C00000 is newly
used as RTK_HWREV_8102EL_SPIN1. Same as {Free,Open}BSD.
 1.51 15-Nov-2019  msaitoh Sort RTK_HWREV_* by value.
 1.50 05-Apr-2019  uwe branches: 1.50.4;
Fix indentation for RTK_CFG2_BUSFREQ to line up with the rest.
 1.49 19-Apr-2017  jmcneill branches: 1.49.12;
Fix value for RE_TDESC_CMD_LGSEND_V6 (currently unused)
 1.48 19-Apr-2017  jmcneill Performance improvements for PCIe and 8168 based devices:
- When using the countdown timer for interrupt moderation on PCIe devices,
use a timer rate value based on a 125MHz PCIe reference clock instead of
33 MHz.
- For 8168 based devices, ditch the countdown timer and instead use the
(undocumented) hardware interrupt moderation feature.
- Support TSOv4 on 8168D and later devices.
 1.47 28-Aug-2015  nonaka branches: 1.47.2; 1.47.4;
Add support for Realtek RTL8168H/8111H variant.
 1.46 10-Oct-2014  christos branches: 1.46.2;
PR/49259: J. Lorec: Add support for Realtek 8111G chipset into re(4)
 1.45 13-Dec-2013  jakllsch Put previous (RTK_HWREV_8168F) in numeric sort order like its neighbors.
 1.44 06-Apr-2013  khorben branches: 1.44.4;
Added support for the Realtek 8168F variant in re(4).

From FreeBSD; not tested on real hardware unfortunately. The manual page was adjusted as well.

No objection from current-users@, "commit it" gdt@
 1.43 02-Mar-2012  nonaka branches: 1.43.2;
Added RTL8168E/8111E-VL support.
 1.42 22-Nov-2011  garbled branches: 1.42.2; 1.42.4;
Add support to recognize the 8168E model of this chip. Taken from FreeBSD
 1.41 09-Apr-2010  nonaka branches: 1.41.8;
Added 8110SBL support.
 1.40 05-Sep-2009  tsutsui branches: 1.40.2; 1.40.4;
Remove unnecessary whitespace.
 1.39 11-May-2009  tsutsui - rename RTK_HWREV_8102EL_SPIN2 -> RTK_HWREV_8103E
- add a HWREV value for 8168DP
Per Realtek's Linux drivers.
 1.38 29-Apr-2009  tsutsui Pull some changes for newer chips from FreeBSD:
- pull MACSTAT and CMDSTOP quirks for 8168/8111 chips
- always set CPLUSCMD_PCI_MRW on reset
- set VLANSTRIP and RXCSUM_ENB bits on CPLUS register per if_capenable

Tested on 8111C and 8111D by several users, and
no bad side effect on my old 8169S.
 1.37 13-Apr-2009  tsutsui Add HWREV of RTL8102EL variant. From FUKAUMI Naoki.
 1.36 13-Apr-2009  tsutsui Add HWREV values of RTL8168CP and RTL8168D. From FreeBSD.

XXX: needs more quirk handling after wakeup for newer chips.
 1.35 27-Mar-2009  tsutsui Check a correct bit for ip4csum-rx. Reported privately on PR kern/40955.
 1.34 21-Mar-2009  tsutsui Add hardware checksum support for newer PCIe 8168/8111/8102 chips,
per device info taken from FreeBSD driver. Tested by snj@ on 8111C.

Should closes PR kern/40955.

Note on old 8169 chips IP hw csum must be enabled to use TCP/UDP hw csums,
but I'm not sure if these newer chips still have the same restriction.
 1.33 08-Dec-2008  alc branches: 1.33.2;
Add support for a 8168C/8111C revision

- also disable jumbo frame on this adapter following the FreeBSD driver
- merge redundant call to aprint_error_dev
 1.32 23-Aug-2008  tnn branches: 1.32.2; 1.32.4;
Add support for the Realtek 8102E/8102EL PCIe 10/100 Ethernet devices.
From FreeBSD.
 1.31 06-May-2008  tsutsui branches: 1.31.2; 1.31.6;
- use RTK_IDR[0-5] registers to get MAC address on RTL8168C
- change sc_rev numbers to match quirk numbers used in Realtek's driver
- tweak some register definitions
Taken from Realtek's FreeBSD driver.

Untested yet on 8168C, but no bad sideeffect on older chips.
 1.30 05-Apr-2008  tsutsui branches: 1.30.2; 1.30.4;
Add some register definitions for RTL8168C.
 1.29 06-Feb-2008  dyoung branches: 1.29.6;
Make some RE_* constants aliases for their generic ethernet
counterparts, whose values are the same.
 1.28 04-Feb-2008  tsutsui FreeBSD says "16 bits" comment about RTK_GTXSTART was incorrect.
Use CSR_WRITE_1() for it. (though the previous code also worked)
 1.27 21-Mar-2007  tsutsui branches: 1.27.10; 1.27.16;
Cleanup handling of quikrs on each RealTek chip:
- replace rtk_type member in rtk_softc which has chip types
with new rtk_quirk that represents quirks on each chip:
- RTKQ_8129 doesn't have internal MII (used in rtk(4))
- RTKQ_8139CPLUS has different register layout (for re(4))
- RTKQ_8169NONS (original 8169) requires some settings on init
- RTKQ_PCIE requires different settings in setmulti
so that we don't have to check each hwrev values or types everywhere
and newer variants will also work without changes if they don't
have other quirks
(sc_rev is unchenged for now for reference to the Realtek's driver)
- don't check hwrev register in re_pci_match() but check
only PCI_VENDER(), PCI_PRODUCT() and PCI_REVISION()
so that we no longer have to map pci space there
- add a new HWREV value for another 8168 variant
- try to map PCI mem space more properly
- remove (probably unneeded) ifp->if_baudrate initialization

Tested on a newer 8168 variant by Dennis den Brok on tech-kern,
and also tested on 8139 and 8169C on macppc, and 8139C+ on landisk
by me.
 1.26 04-Feb-2007  tsutsui branches: 1.26.2; 1.26.6; 1.26.8; 1.26.10;
Add another 8100E HWREV number. From Realtek driver and Plan9 driver.
 1.25 24-Nov-2006  tsutsui branches: 1.25.2;
Change RXFIFO, RXDMA and TXDMA configrations to values taken from
the Reaktek's driver, which are also used in FreeBSD.
Fixes RX FIFO overrun errors on my Duron 1300MHz PC.
(Note the configuration values for rtk(4) are not changed)

Also add some debug printf's in RX error case (disabled by default).
 1.24 18-Nov-2006  tsutsui - sync HWREV definitions with FreeBSD
- recognize 8169SC/8100E/8101E (untested, but won't hurt working devices)
XXX: 8100E/8101E don't support 1000M; need some flag to set if_baudrate
 1.23 17-Nov-2006  tsutsui - add some more register definitions from Realtek driver
- sort
 1.22 05-Nov-2006  tsutsui Rename prefixes of re(4) specific macro and structure members
from RTK_ or rtk_ to RE_ or re_ for maintainability of these sources.
Eventually we should split these files (and struct rtk_softc) into
three elements, rtk(4) specific one, re(4) specific one, and a common
(register definitions, eeprom and multicast functions etc) part.

While here, add a couple of comments around weird definitions.
 1.21 05-Nov-2006  tsutsui - make TX threshold macro more generic
- no need to bother to initialize sc_txthresh in rtk_attach()
since it's done in rtk_init()
 1.20 03-Nov-2006  tsutsui Minor cleanups:
- move some driver specific definitions from rtl81x9reg.h to rtl81x9var.h
- move several macro where related structures are declared
- remove unused macro
- fix some comments
- unwrap some lines
 1.19 03-Nov-2006  tsutsui Use #define<space>, which seems consistent in these files.
 1.18 28-Oct-2006  christos PR/34933: Sami Kantoluoto: RealTek 8168B found from Asus P5B motherboard
is not recognized
 1.17 20-Oct-2006  tsutsui u_intNN_t -> uintNN_t
 1.16 20-Oct-2006  tsutsui - call bus_dmamap_sync(9) against DMA descriptors more properly
- make DMA descripter members volatile
Now re(4) works on sgimips O2.

XXX: Still re(4) sometimes stalls on NFS load on sgimips,
XXX: but I'm not sure it's sgimips specific or not.
 1.15 18-Jun-2006  christos branches: 1.15.4; 1.15.6;
PR/33761: dieter roelants: NetBSD doesn't recognize a RealTek 8168B nic
 1.14 25-Dec-2005  rpaulo branches: 1.14.4; 1.14.8; 1.14.14; 1.14.16;
PR/32386: Dawid Szymanski (arhea). Add support for the 8169SB chipset.
 1.13 11-Dec-2005  christos merge ktrace-lwp.
 1.12 23-Mar-2005  yamt branches: 1.12.2;
- restructure tx descriptor handling code to decouple
number of tx descriptors, number of rx descriptors, and number of mbufs.
- bump number of tx descriptors for rtl8169. 64 doesn't seem to be sufficient
when doing TSO.
 1.11 12-Mar-2005  yamt branches: 1.11.2;
re(4) driver:
- TSO support.
- fix some error handling.
- remove mysterious RTK_NTXSEGS and use more appropriate values
for bus_dmamap_create.
- if we need more than all of our tx descriptors in order to transmit a packet,
just drop it rather than retrying infinitely.
 1.10 27-Feb-2005  perry nuke trailing whitespace
 1.9 09-Jan-2005  kanaoka branches: 1.9.2; 1.9.4;
sys/dev/ic/rtl8169.c:
- re_attach(): Use bus_dma* directly instead of calling re_alloc().
- re_attach(): Free bus_dma* resources if attach fails.
- re_detach(): Free bus_dma* resources.
- re_newbuf(): Remove unnecessary error check.

sys/dev/ic/rtl81x9reg.h:
- Define RTK_NTXSEGS.

sys/dev/ic/rtl81x9var.h:
- Add new members to struct rtk_list_data for bus_dma*.
 1.8 02-Nov-2003  wiz Fix some typos. From Tom Cosgrove via jmc@openbsd.
 1.7 25-Oct-2003  fvdl Add definitions for 8139C+ and 8169 chips. Not used yet. From FreeBSD.
 1.6 31-Jan-2001  thorpej branches: 1.6.24;
Use a 16K receive buffer on the SEGA Dreamcast (XXX should be
done differently than it is).
 1.5 19-May-2000  tsutsui branches: 1.5.6;
- Change RL_* -> RTK_*
- Free bus_dma resources if attach fails
- Add detach and power management code

Patch from Masanori Kanaoka <kanaoka@ann.hi-ho.ne.jp> in kern/10156.
 1.4 30-Apr-2000  tsutsui Modify EEPROM read functions and handle also 9356 EEPROM.
Fixes kern/9861.
 1.3 26-Apr-2000  tsutsui - Allocate mbuf dynamically on Tx and use bus_dmamap_load_mbuf(9).
- Call bus_dmamap_sync(9) as appropriate.
- Leave only register declarations in rtl81x9reg.h and
split other stuff into rtl81x9var.h.

bus_dma(9) code mostly taken from thorpej's if_rtp.c.
 1.2 24-Apr-2000  tsutsui Merge changes of sys/pci/if_rl.c rev. 1.8->1.10. (from kern/9870)
Also remove unused pbase, vbase and PCI_CAP_PWRMGMT declarations.
 1.1 10-Apr-2000  haya Incorporate the changes of RL81x9 driver provided by M. Kanaoka
<kanaoka@ann.hi-ho.ne.jp>. He separated the driver into IC specific
portion and bus attachment portion and added cardbus attachent.
 1.5.6.3 11-Feb-2001  bouyer Sync with HEAD.
 1.5.6.2 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.5.6.1 19-May-2000  bouyer file rtl81x9reg.h was added on branch thorpej_scsipi on 2000-11-20 11:40:53 +0000
 1.6.24.6 01-Apr-2005  skrll Sync with HEAD.
 1.6.24.5 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.6.24.4 17-Jan-2005  skrll Sync with HEAD.
 1.6.24.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.6.24.2 18-Sep-2004  skrll Sync with HEAD.
 1.6.24.1 03-Aug-2004  skrll Sync with HEAD
 1.9.4.2 26-Mar-2005  yamt sync with head.
 1.9.4.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.9.2.1 29-Apr-2005  kent sync with -current
 1.11.2.4 04-Oct-2007  bouyer Pull up following revision(s) (requested by tsutsui in ticket #1852):
sys/dev/ic/rtl81x9var.h: revision 1.39
sys/dev/cardbus/if_re_cardbus.c: revision 1.13
sys/dev/pci/if_re_pci.c: revision 1.27 via patch
sys/dev/pci/if_rtk_pci.c: revision 1.32
sys/dev/cardbus/if_rtk_cardbus.c: revision 1.32
sys/dev/ic/rtl8169.c: revision 1.84, 1.85
sys/dev/ic/rtl81x9reg.h: revision 1.27
sys/dev/ic/rtl81x9.c: revision 1.72
Cleanup handling of quikrs on each RealTek chip:
Pull a fix for PCIe variants from FreeBSD
 1.11.2.3 03-Mar-2007  bouyer Pull up following revision(s) (requested by tsutsui in ticket #1673):
distrib/sets/lists/man/mi 1.844, 1.871
share/man/man4/Makefile 1.372, 1.379 via patch
share/man/man4/re.4 1.8, 1.9, 1.11, 1.12
share/man/man4/rgephy.4 1.1
share/man/man4/rlphy.4 1.1, 1.2
sys/arch/amd64/conf/GENERIC 1.79, 1.89
sys/arch/amd64/conf/INSTALL 1.45, 1.49
sys/arch/i386/conf/GENERIC 1.717, 1.747
sys/arch/i386/conf/GENERIC_LAPTOP 1.164
sys/arch/i386/conf/INSTALL 1.277, 1.283
sys/arch/i386/conf/INSTALL_LAPTOP 1.96, 1.98
sys/arch/i386/conf/XEN2_DOM0 1.22 via patch
sys/arch/macppc/conf/GENERIC 1.220, 1.246
sys/arch/macppc/conf/INSTALL 1.96, 1.100
sys/dev/cardbus/if_re_cardbus.c 1.10
sys/dev/cardbus/if_rtk_cardbus.c 1.29-1.31
sys/dev/ic/rtl8169.c 1.14, 1.20, 1.24, 1.25, 1.28-1.61, 1.63, 1.64-1.81 via patch
sys/dev/ic/rtl81x9.c 1.52, 1.54-1.63, 1.65, 1.67-1.70
sys/dev/ic/rtl81x9reg.h 1.15-1.26
sys/dev/ic/rtl81x9var.h 1.19, 1.21-1.37
sys/dev/mii/files.mii 1.38
sys/dev/mii/miidevs 1.62, 1.64
sys/dev/mii/rgephy.c 1.10, 1.13-1.16
sys/dev/mii/rlphy.c 1.1, 1.6, 1.7, 1.11 via patch
sys/dev/pci/if_re_pci.c 1.13, 1.15-1.17, 1.19-1.23
sys/dev/pci/if_rtk_pci.c 1.25, 1.28, 1.29, 1.31
sys/dev/pci/pcidevs 1.851, 1.852

on re(4):
- improve stability (I believe ;-)
- add a workaround for hardware ip4csum-tx bug
- support newer chips (8169SB/SC, PCIe based 8168 etc.)
- fix 8139C+ support
- enable hardware VLAN
- misc bus_dma(9) fix (which makes re(4) work on mips ports)

on rtk(4):
- fix kern/31348
- fix possible panic on dreamcast
 1.11.2.2 29-Dec-2005  riz Pull up following revision(s) (requested by rpaulo in ticket #1070):
sys/dev/pci/if_re_pci.c: revision 1.12
sys/dev/ic/rtl81x9reg.h: revision 1.14
PR/32386: Dawid Szymanski (arhea). Add support for the 8169SB chipset.
From FreeBSD.
 1.11.2.1 04-Apr-2005  tron Pull up revision 1.12 (requested by yamt in ticket #91):
- restructure tx descriptor handling code to decouple
number of tx descriptors, number of rx descriptors, and number of mbufs.
- bump number of tx descriptors for rtl8169. 64 doesn't seem to be sufficient
when doing TSO.
 1.12.2.5 11-Feb-2008  yamt sync with head.
 1.12.2.4 03-Sep-2007  yamt sync with head.
 1.12.2.3 26-Feb-2007  yamt sync with head.
 1.12.2.2 30-Dec-2006  yamt sync with head.
 1.12.2.1 21-Jun-2006  yamt sync with head.
 1.14.16.1 13-Jul-2006  gdamore Merge from HEAD.
 1.14.14.1 22-Jun-2006  chap Complete a sync sys/ with head.
 1.14.8.1 26-Jun-2006  yamt sync with head.
 1.14.4.1 09-Sep-2006  rpaulo sync with head
 1.15.6.2 10-Dec-2006  yamt sync with head.
 1.15.6.1 22-Oct-2006  yamt sync with head
 1.15.4.3 09-Feb-2007  ad Sync with HEAD.
 1.15.4.2 12-Jan-2007  ad Sync with head.
 1.15.4.1 18-Nov-2006  ad Sync with head.
 1.25.2.6 18-Aug-2009  bouyer Pull up following revision(s) (requested by tsutsui in ticket #1339):
sys/dev/ic/rtl8169.c: revisions 1.107, 1.114, 1.115, 1.116,
1.117 (via patch), 1.118 (via patch),
1.119, 1.121
sys/dev/ic/rtl81x9reg.h: revisions 1.36, 1.37, 1.38, 1.39
sys/dev/ic/rtl81x9var.h: revision 1.47
sys/dev/mii/rgephy.c: revisions 1.16, 1.18, 1.19, 1.27 (via patch)
sys/dev/mii/rgephyreg.h: revision 1.3
sys/dev/pci/if_re_pci.c: revision 1.36
- add support for RTL8211B(L) to rgephy(4)
- add a wakeup instruction for rgephy(4) on newer re(4) chips
- detect RTL8169CP, RTL8168D/8111D, and RTL8103E variants
- fix rgephy(4) problem on RTL8111D reported on current-users:
http://mail-index.NetBSD.org/current-users/2009/04/12/msg008977.html
http://mail-index.NetBSD.org/current-users/2009/04/19/msg009096.html
- pull more quirk handling from FreeBSD
- fix RX hwcksum for DESCV2 chips for PR kern/40605
- remove "B" suffix from RTL8168 device names in attach message
 1.25.2.5 01-Apr-2009  bouyer Fix processing or ticket pullup-4 #1297; previous didn't include revisions
1.34 and 1.35 as requested and announced in commit messages and
CHANGES-4.1 entry
 1.25.2.4 31-Mar-2009  bouyer Pull up following revision(s) (requested by tsutsui in ticket #1297):
src/sys/dev/ic/rtl8169.c 1.104 (via patch), 1.105 (via patch),
1.106 (via patch), 1.108, 1.109 (via patch),
1.110, 1.111, 1.112, 1.113
sys/dev/ic/rtl81x9reg.h: revision 1.30 - 1.35
sys/dev/ic/rtl81x9var.h: revision 1.42 - 1.45
sys/dev/pci/if_re_pci.c: revision 1.35
Add support for 8168C/8111C/8102E chips.
Fix MAC reset issue (PR kern/41009)
Add/fix HW checksum support (PR kern/40955)
 1.25.2.3 24-Mar-2008  bouyer Pull up following revision(s) (requested by tsutsui in ticket #1105):
sys/dev/ic/rtl8169.c: revisions 1.94, 1.95, 1.97, 1.98
sys/dev/ic/rtl81x9reg.h: revision 1.28
No need to preserve RE_NTXDESC_RSVD on re_start().
FreeBSD says "16 bits" comment about RTK_GTXSTART was incorrect.
Use CSR_WRITE_1() for it. (though the previous code also worked)
Don't fetch DMA descriptor after BUS_DMASYNC_PREREAD op.
It looks vlan tag info must appear not only in the first descriptor
but in all descriptors of a multi-descriptor transmission attempt on re(4).
Problem was reported and fix was confirmed by Chris Brookes on tech-net.
Should also close PR kern/37959.
 1.25.2.2 16-May-2007  jdc Pull up revision 1.27 (requested by tsutsui in ticket #640).

Cleanup handling of quikrs on each RealTek chip:
- replace rtk_type member in rtk_softc which has chip types
with new rtk_quirk that represents quirks on each chip:
- RTKQ_8129 doesn't have internal MII (used in rtk(4))
- RTKQ_8139CPLUS has different register layout (for re(4))
- RTKQ_8169NONS (original 8169) requires some settings on init
- RTKQ_PCIE requires different settings in setmulti
so that we don't have to check each hwrev values or types everywhere
and newer variants will also work without changes if they don't
have other quirks
(sc_rev is unchenged for now for reference to the Realtek's driver)
- don't check hwrev register in re_pci_match() but check
only PCI_VENDER(), PCI_PRODUCT() and PCI_REVISION()
so that we no longer have to map pci space there
- add a new HWREV value for another 8168 variant
- try to map PCI mem space more properly
- remove (probably unneeded) ifp->if_baudrate initialization

Tested on a newer 8168 variant by Dennis den Brok on tech-kern,
and also tested on 8139 and 8169C on macppc, and 8139C+ on landisk
by me.
 1.25.2.1 10-Feb-2007  tron branches: 1.25.2.1.2;
Pull up following revision(s) (requested by tsutsui in ticket #437):
sys/dev/ic/rtl81x9reg.h: revision 1.26
Add another 8100E HWREV number. From Realtek driver and Plan9 driver.
 1.25.2.1.2.2 03-Jun-2008  skrll Sync with netbsd-4.
 1.25.2.1.2.1 03-Jun-2007  wrstuden Catch up with now-somewhat-dated netbsd-4. These changes took longer
than expected for me to actually get around to merging.
 1.26.10.1 29-Mar-2007  reinoud Pullup to -current
 1.26.8.1 11-Jul-2007  mjf Sync with head.
 1.26.6.1 10-Apr-2007  ad Sync with head.
 1.26.2.1 24-Mar-2007  yamt sync with head.
 1.27.16.1 18-Feb-2008  mjf Sync with HEAD.
 1.27.10.1 23-Mar-2008  matt sync with HEAD
 1.29.6.3 17-Jan-2009  mjf Sync with HEAD.
 1.29.6.2 28-Sep-2008  mjf Sync with HEAD.
 1.29.6.1 02-Jun-2008  mjf Sync with HEAD.
 1.30.4.5 11-Aug-2010  yamt sync with head.
 1.30.4.4 16-Sep-2009  yamt sync with head
 1.30.4.3 16-May-2009  yamt sync with head
 1.30.4.2 04-May-2009  yamt sync with head.
 1.30.4.1 16-May-2008  yamt sync with head.
 1.30.2.1 18-May-2008  yamt sync with head.
 1.31.6.2 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.31.6.1 19-Oct-2008  haad Sync with HEAD.
 1.31.2.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.32.4.5 25-Jan-2012  riz Pull up following revision(s) (requested by garbled in ticket #1698):
sys/dev/ic/rtl81x9var.h: revision 1.52
sys/dev/ic/rtl8169.c: revision 1.134
sys/dev/ic/rtl81x9reg.h: revision 1.42
Add support to recognize the 8168E model of this chip. Taken from FreeBSD
 1.32.4.4 19-Jun-2009  snj Pull up following revision(s) (requested by tsutsui in ticket #821):
sys/dev/ic/rtl8169.c: revisions 1.107, 1.114-1.119, 1.121
sys/dev/ic/rtl81x9reg.h: revisions 1.36-1.39
sys/dev/ic/rtl81x9var.h: revision 1.47
sys/dev/mii/rgephy.c: revision 1.27 via patch
sys/dev/pci/if_re_pci.c: revision 1.36
remove extra semicolons.
--
Add HWREV values of RTL8168CP and RTL8168D. From FreeBSD.

XXX: needs more quirk handling after wakeup for newer chips.
--
Add HWREV of RTL8102EL variant. From FUKAUMI Naoki.
--
Assume an unknown HWREV chip has the same features with the latest one.
--
Remove suffix "B" from rtk_name of PCI_PRODUCT_REALTEK_RT8168 devices.
All 8168/8111 variants (8168/8168B/8168C/8168CP/8168D/8111B/8111C/8111CP)
have the same PCI device ID.
--
Remove magic reset sequence except wakeup for rev 2 chips which breaks 8111D.
Problem reported and fix confirmed by Thomas Bieg on current-users.

Also tested on 8111C (no bad side effect) by several users privately.
--
Pull some changes for newer chips from FreeBSD:
- pull MACSTAT and CMDSTOP quirks for 8168/8111 chips
- always set CPLUSCMD_PCI_MRW on reset
- set VLANSTRIP and RXCSUM_ENB bits on CPLUS register per if_capenable

Tested on 8111C and 8111D by several users, and
no bad side effect on my old 8169S.
--
Remove unused sc_rev settings (all quirks are handled by sc_quirk)
and merge HWREV cases which have the same quirks.
--
- rename RTK_HWREV_8102EL_SPIN2 -> RTK_HWREV_8103E
- add a HWREV value for 8168DP
Per Realtek's Linux drivers.
--
Two fixes for RX hwcsum on DESCV2 chips:
* On checking TCPv4/UDPv4 RX checksum on DESCV2 chips, also check
RE_RDESC_VLANCTL_IPV4 bit because those DESCV2 chips may also recognize
IPv6 packets and set RE_PROTOID_TCPIP or RE_PROTOID_UDPIP bits for
TCPv6/UDPv6 packets. This may fix PR kern/40605.
* According to Realtek's Linux driver, DESCV2 chips don't set RE_PROTOID_IP
for non-TCP/UDP IP packets (set only RE_RDESC_VLANCTL_IPV[46]) so
remove PROTOID check for IPv4 RX cheksum on DESCV2 chips.
 1.32.4.3 01-May-2009  snj Pull up following revision(s) (requested by tsutsui in ticket #597):
sys/dev/ic/rtl8169.c: revision 1.112
sys/dev/ic/rtl81x9reg.h: revision 1.35
Check a correct bit for ip4csum-rx. Reported privately on PR kern/40955.
 1.32.4.2 01-May-2009  snj Pull up following revision(s) (requested by tsutsui in ticket #597):
sys/dev/ic/rtl8169.c: revision 1.109
sys/dev/ic/rtl81x9reg.h: revision 1.34
sys/dev/ic/rtl81x9var.h: revision 1.43
Add hardware checksum support for newer PCIe 8168/8111/8102 chips,
per device info taken from FreeBSD driver. Tested by snj@ on 8111C.
Should closes PR kern/40955.
Note on old 8169 chips IP hw csum must be enabled to use TCP/UDP hw csums,
but I'm not sure if these newer chips still have the same restriction.
 1.32.4.1 26-Mar-2009  snj branches: 1.32.4.1.4;
Pull up following revision(s) (requested by tsutsui in ticket #597):
sys/dev/ic/rtl8169.c: revision 1.106
sys/dev/ic/rtl81x9reg.h: revision 1.33
Add support for a 8168C/8111C revision
- also disable jumbo frame on this adapter following the FreeBSD driver
- merge redundant call to aprint_error_dev
 1.32.4.1.4.1 21-Apr-2010  matt sync to netbsd-5
 1.32.2.2 28-Apr-2009  skrll Sync with HEAD.
 1.32.2.1 19-Jan-2009  skrll Sync with HEAD.
 1.33.2.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.40.4.1 30-May-2010  rmind sync with head
 1.40.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.41.8.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.41.8.1 17-Apr-2012  yamt sync with head
 1.42.4.2 29-Jul-2013  msaitoh Pull up following revision(s) (requested by khorben in ticket #913):
sys/dev/ic/rtl8169.c: revision 1.137
sys/dev/ic/rtl81x9reg.h: revision 1.44
share/man/man4/re.4: revision 1.14
Added support for the Realtek 8168F variant in re(4).
From FreeBSD; not tested on real hardware unfortunately. The manual page
was adjusted as well.
No objection from current-users@, "commit it" gdt@
 1.42.4.1 05-Mar-2012  sborrill Pull up the following revisions(s) (requested by nonaka in ticket #83):
sys/dev/ic/rtl8169.c: revision 1.135
sys/dev/ic/rtl81x9reg.h: revision 1.43

Add RTL8168E/8111E-VL support.
 1.42.2.3 06-Mar-2012  mrg sync to -current
 1.42.2.2 06-Mar-2012  mrg sync to -current
 1.42.2.1 04-Mar-2012  mrg sync to latest -current.
 1.43.2.3 03-Dec-2017  jdolecek update from HEAD
 1.43.2.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.43.2.1 23-Jun-2013  tls resync from head
 1.44.4.1 18-May-2014  rmind sync with head
 1.46.2.2 28-Aug-2017  skrll Sync with HEAD
 1.46.2.1 22-Sep-2015  skrll Sync with HEAD
 1.47.4.1 21-Apr-2017  bouyer Sync with HEAD
 1.47.2.1 26-Apr-2017  pgoyette Sync with HEAD
 1.49.12.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.49.12.1 10-Jun-2019  christos Sync with HEAD
 1.50.4.2 04-Aug-2023  martin Pull up following revision(s) (requested by jakllsch in ticket #1705):

sys/dev/ic/rtl81x9var.h: revision 1.58
sys/dev/ic/rtl81x9reg.h: revision 1.54
sys/dev/ic/rtl8169.c: revision 1.167
sys/dev/ic/rtl8169.c: revision 1.168

re(4): misc chip revision support changes
* remove impossible-to-match chip revision cases
* bring support for modern chips in line with FreeBSD and OpenBSD
* adds support for RTL8168GU

Addresses PR kern/56312.

- Print chip revision. From OpenBSD.
- Rename RTK_HWREV_8168_SPIN[123] to RTK_HWREV_8168'B'_SPIN[123].
Same as other *BSDs.
- Rename RTK_HWREV_8168G_SPIN4 to RTK_HWREV_8411B. Same as other *BSDs.
- Add definition of RTK_HWREV_8169_8110SCE.
 1.50.4.1 28-Jan-2020  martin Pull up following revision(s) (requested by msaitoh in ticket #667):

sys/dev/ic/rtl81x9var.h: revision 1.57
sys/dev/ic/rtl81x9.c: revision 1.107
sys/dev/ic/rtl81x9reg.h: revision 1.51
sys/dev/ic/rtl8169.c: revision 1.160
sys/dev/ic/rtl81x9reg.h: revision 1.52
sys/dev/ic/rtl8169.c: revision 1.161

Use unsigned in rtk_setmulti() to avoid undefined behavior. Found bk kUBSan.
8168H model didn't link up well. some models seems to require to enable TX/RX after configuration.
RTKQ_TXRXEN_LATER quirk flag added. it may be able to unify with RTKQ_RXDV_GATED flag?
Sort RTK_HWREV_* by value.

Improve some chip revisions support:
- Add 8168FP, 8411, 8168G, 8401E, 8105E, 8105E_SPIN1, 8106E and 8402 from
{Free,Open}BSD.
- Renumber RTK_HWREV_8103E from 0x24C00000 to 0x34c00000. 0x24C00000 is newly
used as RTK_HWREV_8102EL_SPIN1. Same as {Free,Open}BSD.
 1.54.26.1 02-Aug-2025  perseant Sync with HEAD
 1.59 12-Aug-2024  christos PR/58588: Christos Zoulas: Avoid crashes when exiting promiscuous mode (^C
tcpdump) by disabling RX in re_stop. Also add some earlyoff stuff while here.
From FreeBSD.
 1.58 21-Sep-2020  msaitoh branches: 1.58.26;
- Print chip revision. From OpenBSD.
- Rename RTK_HWREV_8168_SPIN[123] to RTK_HWREV_8168'B'_SPIN[123].
Same as other *BSDs.
- Rename RTK_HWREV_8168G_SPIN4 to RTK_HWREV_8411B. Same as other *BSDs.
- Add definition of RTK_HWREV_8169_8110SCE.
 1.57 22-Sep-2019  ryo 8168H model didn't link up well. some models seems to require to enable TX/RX after configuration.
RTKQ_TXRXEN_LATER quirk flag added. it may be able to unify with RTKQ_RXDV_GATED flag?
 1.56 19-Apr-2017  jmcneill branches: 1.56.12; 1.56.18;
Performance improvements for PCIe and 8168 based devices:
- When using the countdown timer for interrupt moderation on PCIe devices,
use a timer rate value based on a 125MHz PCIe reference clock instead of
33 MHz.
- For 8168 based devices, ditch the countdown timer and instead use the
(undocumented) hardware interrupt moderation feature.
- Support TSOv4 on 8168D and later devices.
 1.55 13-Apr-2015  riastradh branches: 1.55.2; 1.55.4;
Convert sys/dev to use <sys/rndsource.h>.
 1.54 10-Oct-2014  christos branches: 1.54.2;
PR/49259: J. Lorec: Add support for Realtek 8111G chipset into re(4)
 1.53 02-Feb-2012  tls branches: 1.53.6;
Entropy-pool implementation move and cleanup.

1) Move core entropy-pool code and source/sink/sample management code
to sys/kern from sys/dev.

2) Remove use of NRND as test for presence of entropy-pool code throughout
source tree.

3) Remove use of RND_ENABLED in device drivers as microoptimization to
avoid expensive operations on disabled entropy sources; make the
rnd_add calls do this directly so all callers benefit.

4) Fix bug in recent rnd_add_data()/rnd_add_uint32() changes that might
have lead to slight entropy overestimation for some sources.

5) Add new source types for environmental sensors, power sensors, VM
system events, and skew between clocks, with a sample implementation
for each.

ok releng to go in before the branch due to the difficulty of later
pullup (widespread #ifdef removal and moved files). Tested with release
builds on amd64 and evbarm and live testing on amd64.
 1.52 22-Nov-2011  garbled branches: 1.52.2;
Add support to recognize the 8168E model of this chip. Taken from FreeBSD
 1.51 19-Nov-2011  tls First step of random number subsystem rework described in
<20111022023242.BA26F14A158@mail.netbsd.org>. This change includes
the following:

An initial cleanup and minor reorganization of the entropy pool
code in sys/dev/rnd.c and sys/dev/rndpool.c. Several bugs are
fixed. Some effort is made to accumulate entropy more quickly at
boot time.

A generic interface, "rndsink", is added, for stream generators to
request that they be re-keyed with good quality entropy from the pool
as soon as it is available.

The arc4random()/arc4randbytes() implementation in libkern is
adjusted to use the rndsink interface for rekeying, which helps
address the problem of low-quality keys at boot time.

An implementation of the FIPS 140-2 statistical tests for random
number generator quality is provided (libkern/rngtest.c). This
is based on Greg Rose's implementation from Qualcomm.

A new random stream generator, nist_ctr_drbg, is provided. It is
based on an implementation of the NIST SP800-90 CTR_DRBG by
Henric Jungheim. This generator users AES in a modified counter
mode to generate a backtracking-resistant random stream.

An abstraction layer, "cprng", is provided for in-kernel consumers
of randomness. The arc4random/arc4randbytes API is deprecated for
in-kernel use. It is replaced by "cprng_strong". The current
cprng_fast implementation wraps the existing arc4random
implementation. The current cprng_strong implementation wraps the
new CTR_DRBG implementation. Both interfaces are rekeyed from
the entropy pool automatically at intervals justifiable from best
current cryptographic practice.

In some quick tests, cprng_fast() is about the same speed as
the old arc4randbytes(), and cprng_strong() is about 20% faster
than rnd_extract_data(). Performance is expected to improve.

The AES code in src/crypto/rijndael is no longer an optional
kernel component, as it is required by cprng_strong, which is
not an optional kernel component.

The entropy pool output is subjected to the rngtest tests at
startup time; if it fails, the system will reboot. There is
approximately a 3/10000 chance of a false positive from these
tests. Entropy pool _input_ from hardware random numbers is
subjected to the rngtest tests at attach time, as well as the
FIPS continuous-output test, to detect bad or stuck hardware
RNGs; if any are detected, they are detached, but the system
continues to run.

A problem with rndctl(8) is fixed -- datastructures with
pointers in arrays are no longer passed to userspace (this
was not a security problem, but rather a major issue for
compat32). A new kernel will require a new rndctl.

The sysctl kern.arandom() and kern.urandom() nodes are hooked
up to the new generators, but the /dev/*random pseudodevices
are not, yet.

Manual pages for the new kernel interfaces are forthcoming.
 1.50 27-Jul-2010  jakllsch branches: 1.50.8;
Make the Realtek PCI network interfaces detachable.
Use __arraycount to avoid null table entries.
Miscellaneous other touch-ups in bus front-ends.
 1.49 05-Sep-2009  tsutsui branches: 1.49.2; 1.49.4;
Remove unnecessary whitespace.
 1.48 12-May-2009  cegger struct device * -> device_t, no functional changes intended.
 1.47 29-Apr-2009  tsutsui Pull some changes for newer chips from FreeBSD:
- pull MACSTAT and CMDSTOP quirks for 8168/8111 chips
- always set CPLUSCMD_PCI_MRW on reset
- set VLANSTRIP and RXCSUM_ENB bits on CPLUS register per if_capenable

Tested on 8111C and 8111D by several users, and
no bad side effect on my old 8169S.
 1.46 26-Apr-2009  tsutsui - use (uint8_t *) for RX buffer
- remove unnecessary pointer casts
 1.45 21-Mar-2009  tsutsui Add another quirk flag which shows availability of EEPROM command register.

Now we can remove sc_rev which was intended to represent "MAC revision"
used in the Realtek driver.
 1.44 21-Mar-2009  tsutsui Add and use a new quirk flag to disable JUMBO MTU,
rather than checking sc_rev values.
 1.43 21-Mar-2009  tsutsui Add hardware checksum support for newer PCIe 8168/8111/8102 chips,
per device info taken from FreeBSD driver. Tested by snj@ on 8111C.

Should closes PR kern/40955.

Note on old 8169 chips IP hw csum must be enabled to use TCP/UDP hw csums,
but I'm not sure if these newer chips still have the same restriction.
 1.42 20-Mar-2009  tsutsui Access LDPS register in re_reset() only on 8169S single chip variants.
From OpenBSD and FreeBSD drivers via PR kern/41009, and
Realtek-supplied FreeBSD driver.
 1.41 25-Apr-2008  tsutsui branches: 1.41.2; 1.41.10; 1.41.12; 1.41.16;
Split device_t/softc for re(4) and rtk(4).
 1.40 09-Dec-2007  jmcneill branches: 1.40.10; 1.40.12;
Merge jmcneill-pm branch.
 1.39 21-Mar-2007  tsutsui branches: 1.39.8; 1.39.10; 1.39.18; 1.39.20;
Cleanup handling of quikrs on each RealTek chip:
- replace rtk_type member in rtk_softc which has chip types
with new rtk_quirk that represents quirks on each chip:
- RTKQ_8129 doesn't have internal MII (used in rtk(4))
- RTKQ_8139CPLUS has different register layout (for re(4))
- RTKQ_8169NONS (original 8169) requires some settings on init
- RTKQ_PCIE requires different settings in setmulti
so that we don't have to check each hwrev values or types everywhere
and newer variants will also work without changes if they don't
have other quirks
(sc_rev is unchenged for now for reference to the Realtek's driver)
- don't check hwrev register in re_pci_match() but check
only PCI_VENDER(), PCI_PRODUCT() and PCI_REVISION()
so that we no longer have to map pci space there
- add a new HWREV value for another 8168 variant
- try to map PCI mem space more properly
- remove (probably unneeded) ifp->if_baudrate initialization

Tested on a newer 8168 variant by Dennis den Brok on tech-kern,
and also tested on 8139 and 8169C on macppc, and 8139C+ on landisk
by me.
 1.38 04-Mar-2007  christos branches: 1.38.2; 1.38.4; 1.38.6;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.37 25-Nov-2006  tsutsui branches: 1.37.2; 1.37.4; 1.37.8;
- add RE_RX_DMAMEM_SZ macro to hide a bit confusing hack
(allocating TX padding buffer in RX DMA mem to save resouces)
and use it where appropriate
- add a comment about the hack in re_attach() too
- pass a correct size on bus_dmamem_unmap() for RX DMA mem
 1.36 18-Nov-2006  tsutsui Use bitmask ops rather than modulo in RE_NEXT_*() macro since
we can assume each number of descriptors and TX queue is a power of two.
 1.35 17-Nov-2006  tsutsui Add a workaround for hardware ip4csum-tx bug on re(4) chips.

See discussion on tech-kern and tech-net for details:
http://mail-index.netbsd.org/tech-net/2006/10/21/0000.html
http://mail-index.netbsd.org/tech-net/2006/11/04/0003.html
http://mail-index.netbsd.org/tech-net/2006/11/07/0002.html
http://mail-index.netbsd.org/tech-net/2006/11/12/0000.html
etc.
 1.34 12-Nov-2006  tsutsui - merge re_encap() into re_start() so that we can handle each error case
more flexible
- account a number of free txq and use it to see if packets are queued or sent
- assume free TX descriptors are not owned by the chip in re_start() and
panic if there is any inconsistency on them #ifdef DIAGNOSTIC case.
- replace a magic number (reserved TX descs?) with macro
 1.33 11-Nov-2006  tsutsui - declare struct re_txq separately
- reorder bus_dma_segment_t members since they are used only on attach/detach
 1.32 05-Nov-2006  tsutsui Rename prefixes of re(4) specific macro and structure members
from RTK_ or rtk_ to RE_ or re_ for maintainability of these sources.
Eventually we should split these files (and struct rtk_softc) into
three elements, rtk(4) specific one, re(4) specific one, and a common
(register definitions, eeprom and multicast functions etc) part.

While here, add a couple of comments around weird definitions.
 1.31 05-Nov-2006  tsutsui - make TX threshold macro more generic
- no need to bother to initialize sc_txthresh in rtk_attach()
since it's done in rtk_init()
 1.30 03-Nov-2006  tsutsui Minor cleanups:
- move some driver specific definitions from rtl81x9reg.h to rtl81x9var.h
- move several macro where related structures are declared
- remove unused macro
- fix some comments
- unwrap some lines
 1.29 03-Nov-2006  tsutsui Use #define<space>, which seems consistent in these files.
 1.28 28-Oct-2006  tsutsui Put common data for each RX DMA descriptor into a new rxsoft structure
for micro optimization.
 1.27 27-Oct-2006  tsutsui Remove redundant byteswap ops.
 1.26 27-Oct-2006  tsutsui Use common macro rather than local one.
 1.25 22-Oct-2006  tsutsui Rename RTK_[TR]X_DESC_INC() macro to RTK_NEXT_[TR]X_DESC() and
change them to return rvalues to avoid possible side effects.
Also define RTK_NEXT_TXQ() for rtk_txq index and use it as well.
 1.24 20-Oct-2006  tsutsui u_intNN_t -> uintNN_t
 1.23 20-Oct-2006  tsutsui - call bus_dmamap_sync(9) against DMA descriptors more properly
- make DMA descripter members volatile
Now re(4) works on sgimips O2.

XXX: Still re(4) sometimes stalls on NFS load on sgimips,
XXX: but I'm not sure it's sgimips specific or not.
 1.22 17-Oct-2006  tsutsui Use "#ifdef __NO_STRICT_ALIGNMENT" rather than
"#if defined(__i386__) || defined(__x86_64__)".

XXX: What will happen if RTL8168B is used on !__NO_STRICT_ALIGNMENT hosts?
XXX: If 8168B can't handle RX DMA into 32bit-unaligned memory, should we
XXX: implement some code to copy RX buffers like vge(4)?
XXX: Or is 8168B available only for on-board NIC for PCs?
 1.21 18-Jun-2006  christos branches: 1.21.4; 1.21.6;
PR/33763: dieter roelants: Realtek 8168B doesn't function. Don't align
for i386/x86_64. From FreeBSD.
 1.20 11-Dec-2005  christos branches: 1.20.4; 1.20.8; 1.20.14; 1.20.16;
merge ktrace-lwp.
 1.19 30-May-2005  christos branches: 1.19.2;
- add missing const
- fix variable shadowing
- remove unneeded casts
 1.18 23-Mar-2005  yamt - restructure tx descriptor handling code to decouple
number of tx descriptors, number of rx descriptors, and number of mbufs.
- bump number of tx descriptors for rtl8169. 64 doesn't seem to be sufficient
when doing TSO.
 1.17 04-Feb-2005  perry branches: 1.17.4;
de-__P
 1.16 23-Jan-2005  dan branches: 1.16.2;
attach rtk(4) as an event source to rnd(4)
patches from Sean Davis in PR/28547
(also added a detach hook)
 1.15 09-Jan-2005  kanaoka branches: 1.15.2;
sys/dev/ic/rtl8169.c:
- re_attach(): Use bus_dma* directly instead of calling re_alloc().
- re_attach(): Free bus_dma* resources if attach fails.
- re_detach(): Free bus_dma* resources.
- re_newbuf(): Remove unnecessary error check.

sys/dev/ic/rtl81x9reg.h:
- Define RTK_NTXSEGS.

sys/dev/ic/rtl81x9var.h:
- Add new members to struct rtk_list_data for bus_dma*.
 1.14 25-Dec-2004  jonathan Add a forgotten change to rtl81x9var.hfor split re(4) driver
(sys/dev/ic/rtl8169.c): add `sc_rev' to generic 81x9 struct rtk_softc.
 1.13 30-May-2004  toshii Minor clean ups. No functional change.
- use RTK_RX_DESC_CNT where appropriate
- remove unused members
 1.12 28-May-2004  toshii A couple of changes for adding re(4) (Realtek gigabit ethernet):
- add necessary members in rtk_softc
- make functions used by re(4) non-static
 1.11 25-Oct-2003  fvdl branches: 1.11.2;
Add definitions for 8139C+ and 8169 chips. Not used yet. From FreeBSD.
 1.10 25-Jul-2001  kanaoka branches: 1.10.20;
- Increase Early TX threshold if underrun occurred.
 1.9 02-Feb-2001  thorpej branches: 1.9.2; 1.9.4;
Rework the transmit logic. Use a "free" and "dirty" list of
transmit jobs. The previous logic occasionally, under heavy
load, would attempt to sync and unload DMA maps that weren't
currently in use, and also occasionally leaked mbufs under
heavy load.

Yay, NFS now works pretty well on my Dreamcast.
 1.8 02-Feb-2001  thorpej Put the rx buf pointer into the softc directly.
 1.7 05-Dec-2000  tsutsui - Since rtk_rxeof() was rewritten, we don't have to reserve a few bytes
before the Rx buffer.
- Reduce delay on EEPROM access.
- Some more cosmetics.
 1.6 30-Nov-2000  tsutsui Clarify RX status header length and some cosmetics.
 1.5 19-May-2000  tsutsui branches: 1.5.4; 1.5.6;
- Change RL_* -> RTK_*
- Free bus_dma resources if attach fails
- Add detach and power management code

Patch from Masanori Kanaoka <kanaoka@ann.hi-ho.ne.jp> in kern/10156.
 1.4 15-May-2000  thorpej Symbol namespace cleanup: rl_ -> rtk_
 1.3 01-May-2000  tsutsui - Move some initialization into MI rl_attach() from each bus attachment.
- Use proper CARDBUS_* macro in if_rl_cardbus.c
- Use product ID read from PCI configuration space rather than from EEPROM
in if_rl_pci.c.

Patch sent from Masanori Kanaoka <kanaoka@ann.hi-ho.ne.jp> and
some cosmetic changes by me.
 1.2 30-Apr-2000  tsutsui Modify EEPROM read functions and handle also 9356 EEPROM.
Fixes kern/9861.
 1.1 26-Apr-2000  tsutsui - Allocate mbuf dynamically on Tx and use bus_dmamap_load_mbuf(9).
- Call bus_dmamap_sync(9) as appropriate.
- Leave only register declarations in rtl81x9reg.h and
split other stuff into rtl81x9var.h.

bus_dma(9) code mostly taken from thorpej's if_rtp.c.
 1.5.6.4 11-Feb-2001  bouyer Sync with HEAD.
 1.5.6.3 08-Dec-2000  bouyer Sync with HEAD.
 1.5.6.2 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.5.6.1 19-May-2000  bouyer file rtl81x9var.h was added on branch thorpej_scsipi on 2000-11-20 11:40:53 +0000
 1.5.4.2 27-Oct-2001  he Pull up revisions 1.8-1.10 (via patch, requested by jdolecek):
Apply assorted stability fixes:
o increase early TX threshold if underrun occurred
o reworked transmit logic
o fix bug in ring-buffer wrap calculation
Should fix problems with hung network interfaces of this type.
 1.5.4.1 25-Jan-2001  jhawk Pull up revisions 1.6-1.7 (requested by tsutsui):
Clean up receive interrupt routine and fix DMA buffer handing
for receive buffering.
Add missed bus_dmamem_free() in rtk_detach().
Some cosmetic fixes.
 1.9.4.1 03-Aug-2001  lukem update to -current
 1.9.2.1 24-Aug-2001  nathanw Catch up with -current.
 1.10.20.8 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.10.20.7 01-Apr-2005  skrll Sync with HEAD.
 1.10.20.6 04-Feb-2005  skrll Sync with HEAD.
 1.10.20.5 24-Jan-2005  skrll Sync with HEAD.
 1.10.20.4 17-Jan-2005  skrll Sync with HEAD.
 1.10.20.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.10.20.2 18-Sep-2004  skrll Sync with HEAD.
 1.10.20.1 03-Aug-2004  skrll Sync with HEAD
 1.11.2.2 21-Jun-2004  tron branches: 1.11.2.2.2;
Pull up revision 1.13 (requested by toshii in ticket #517):
Minor clean ups. No functional change.
- use RTK_RX_DESC_CNT where appropriate
- remove unused members
 1.11.2.1 21-Jun-2004  tron Pull up revision 1.12 (requested by toshii in ticket #517):
A couple of changes for adding re(4) (Realtek gigabit ethernet):
- add necessary members in rtk_softc
- make functions used by re(4) non-static
 1.11.2.2.2.1 16-Apr-2005  tron Pull up revision 1.16 (requested by dan in ticket #1116):
attach rtk(4) as an event source to rnd(4)
patches from Sean Davis in PR/28547
(also added a detach hook)
 1.15.2.1 29-Apr-2005  kent sync with -current
 1.16.2.2 26-Mar-2005  yamt sync with head.
 1.16.2.1 12-Feb-2005  yamt sync with head.
 1.17.4.3 04-Oct-2007  bouyer Pull up following revision(s) (requested by tsutsui in ticket #1852):
sys/dev/ic/rtl81x9var.h: revision 1.39
sys/dev/cardbus/if_re_cardbus.c: revision 1.13
sys/dev/pci/if_re_pci.c: revision 1.27 via patch
sys/dev/pci/if_rtk_pci.c: revision 1.32
sys/dev/cardbus/if_rtk_cardbus.c: revision 1.32
sys/dev/ic/rtl8169.c: revision 1.84, 1.85
sys/dev/ic/rtl81x9reg.h: revision 1.27
sys/dev/ic/rtl81x9.c: revision 1.72
Cleanup handling of quikrs on each RealTek chip:
Pull a fix for PCIe variants from FreeBSD
 1.17.4.2 03-Mar-2007  bouyer Pull up following revision(s) (requested by tsutsui in ticket #1673):
distrib/sets/lists/man/mi 1.844, 1.871
share/man/man4/Makefile 1.372, 1.379 via patch
share/man/man4/re.4 1.8, 1.9, 1.11, 1.12
share/man/man4/rgephy.4 1.1
share/man/man4/rlphy.4 1.1, 1.2
sys/arch/amd64/conf/GENERIC 1.79, 1.89
sys/arch/amd64/conf/INSTALL 1.45, 1.49
sys/arch/i386/conf/GENERIC 1.717, 1.747
sys/arch/i386/conf/GENERIC_LAPTOP 1.164
sys/arch/i386/conf/INSTALL 1.277, 1.283
sys/arch/i386/conf/INSTALL_LAPTOP 1.96, 1.98
sys/arch/i386/conf/XEN2_DOM0 1.22 via patch
sys/arch/macppc/conf/GENERIC 1.220, 1.246
sys/arch/macppc/conf/INSTALL 1.96, 1.100
sys/dev/cardbus/if_re_cardbus.c 1.10
sys/dev/cardbus/if_rtk_cardbus.c 1.29-1.31
sys/dev/ic/rtl8169.c 1.14, 1.20, 1.24, 1.25, 1.28-1.61, 1.63, 1.64-1.81 via patch
sys/dev/ic/rtl81x9.c 1.52, 1.54-1.63, 1.65, 1.67-1.70
sys/dev/ic/rtl81x9reg.h 1.15-1.26
sys/dev/ic/rtl81x9var.h 1.19, 1.21-1.37
sys/dev/mii/files.mii 1.38
sys/dev/mii/miidevs 1.62, 1.64
sys/dev/mii/rgephy.c 1.10, 1.13-1.16
sys/dev/mii/rlphy.c 1.1, 1.6, 1.7, 1.11 via patch
sys/dev/pci/if_re_pci.c 1.13, 1.15-1.17, 1.19-1.23
sys/dev/pci/if_rtk_pci.c 1.25, 1.28, 1.29, 1.31
sys/dev/pci/pcidevs 1.851, 1.852

on re(4):
- improve stability (I believe ;-)
- add a workaround for hardware ip4csum-tx bug
- support newer chips (8169SB/SC, PCIe based 8168 etc.)
- fix 8139C+ support
- enable hardware VLAN
- misc bus_dma(9) fix (which makes re(4) work on mips ports)

on rtk(4):
- fix kern/31348
- fix possible panic on dreamcast
 1.17.4.1 04-Apr-2005  tron Pull up revision 1.18 (requested by yamt in ticket #91):
- restructure tx descriptor handling code to decouple
number of tx descriptors, number of rx descriptors, and number of mbufs.
- bump number of tx descriptors for rtl8169. 64 doesn't seem to be sufficient
when doing TSO.
 1.19.2.4 21-Jan-2008  yamt sync with head
 1.19.2.3 03-Sep-2007  yamt sync with head.
 1.19.2.2 30-Dec-2006  yamt sync with head.
 1.19.2.1 21-Jun-2006  yamt sync with head.
 1.20.16.1 13-Jul-2006  gdamore Merge from HEAD.
 1.20.14.1 22-Jun-2006  chap Complete a sync sys/ with head.
 1.20.8.1 26-Jun-2006  yamt sync with head.
 1.20.4.1 09-Sep-2006  rpaulo sync with head
 1.21.6.2 10-Dec-2006  yamt sync with head.
 1.21.6.1 22-Oct-2006  yamt sync with head
 1.21.4.2 12-Jan-2007  ad Sync with head.
 1.21.4.1 18-Nov-2006  ad Sync with head.
 1.37.8.1 03-Jun-2007  wrstuden Catch up with now-somewhat-dated netbsd-4. These changes took longer
than expected for me to actually get around to merging.
 1.37.4.2 24-Mar-2007  yamt sync with head.
 1.37.4.1 12-Mar-2007  rmind Sync with HEAD.
 1.37.2.3 18-Aug-2009  bouyer Pull up following revision(s) (requested by tsutsui in ticket #1339):
sys/dev/ic/rtl8169.c: revisions 1.107, 1.114, 1.115, 1.116,
1.117 (via patch), 1.118 (via patch),
1.119, 1.121
sys/dev/ic/rtl81x9reg.h: revisions 1.36, 1.37, 1.38, 1.39
sys/dev/ic/rtl81x9var.h: revision 1.47
sys/dev/mii/rgephy.c: revisions 1.16, 1.18, 1.19, 1.27 (via patch)
sys/dev/mii/rgephyreg.h: revision 1.3
sys/dev/pci/if_re_pci.c: revision 1.36
- add support for RTL8211B(L) to rgephy(4)
- add a wakeup instruction for rgephy(4) on newer re(4) chips
- detect RTL8169CP, RTL8168D/8111D, and RTL8103E variants
- fix rgephy(4) problem on RTL8111D reported on current-users:
http://mail-index.NetBSD.org/current-users/2009/04/12/msg008977.html
http://mail-index.NetBSD.org/current-users/2009/04/19/msg009096.html
- pull more quirk handling from FreeBSD
- fix RX hwcksum for DESCV2 chips for PR kern/40605
- remove "B" suffix from RTL8168 device names in attach message
 1.37.2.2 31-Mar-2009  bouyer Pull up following revision(s) (requested by tsutsui in ticket #1297):
src/sys/dev/ic/rtl8169.c 1.104 (via patch), 1.105 (via patch),
1.106 (via patch), 1.108, 1.109 (via patch),
1.110, 1.111, 1.112, 1.113
sys/dev/ic/rtl81x9reg.h: revision 1.30 - 1.35
sys/dev/ic/rtl81x9var.h: revision 1.42 - 1.45
sys/dev/pci/if_re_pci.c: revision 1.35
Add support for 8168C/8111C/8102E chips.
Fix MAC reset issue (PR kern/41009)
Add/fix HW checksum support (PR kern/40955)
 1.37.2.1 16-May-2007  jdc Pull up revision 1.39 (requested by tsutsui in ticket #640).

Cleanup handling of quikrs on each RealTek chip:
- replace rtk_type member in rtk_softc which has chip types
with new rtk_quirk that represents quirks on each chip:
- RTKQ_8129 doesn't have internal MII (used in rtk(4))
- RTKQ_8139CPLUS has different register layout (for re(4))
- RTKQ_8169NONS (original 8169) requires some settings on init
- RTKQ_PCIE requires different settings in setmulti
so that we don't have to check each hwrev values or types everywhere
and newer variants will also work without changes if they don't
have other quirks
(sc_rev is unchenged for now for reference to the Realtek's driver)
- don't check hwrev register in re_pci_match() but check
only PCI_VENDER(), PCI_PRODUCT() and PCI_REVISION()
so that we no longer have to map pci space there
- add a new HWREV value for another 8168 variant
- try to map PCI mem space more properly
- remove (probably unneeded) ifp->if_baudrate initialization

Tested on a newer 8168 variant by Dennis den Brok on tech-kern,
and also tested on 8139 and 8169C on macppc, and 8139C+ on landisk
by me.
 1.38.6.1 29-Mar-2007  reinoud Pullup to -current
 1.38.4.1 11-Jul-2007  mjf Sync with head.
 1.38.2.1 10-Apr-2007  ad Sync with head.
 1.39.20.1 11-Dec-2007  yamt sync with head.
 1.39.18.1 26-Dec-2007  ad Sync with head.
 1.39.10.1 09-Jan-2008  matt sync with HEAD
 1.39.8.1 05-Oct-2007  joerg Remove the power management nonsense in the PCI versions of
rtk(4) and re(4). It is not really likely to work anyway.
Use PNP power management for the cardbus attachment as well and
remove the power management handlers from the chipset code.
 1.40.12.1 18-May-2008  yamt sync with head.
 1.40.10.1 02-Jun-2008  mjf Sync with HEAD.
 1.41.16.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.41.12.6 25-Jan-2012  riz Pull up following revision(s) (requested by garbled in ticket #1698):
sys/dev/ic/rtl81x9var.h: revision 1.52
sys/dev/ic/rtl8169.c: revision 1.134
sys/dev/ic/rtl81x9reg.h: revision 1.42
Add support to recognize the 8168E model of this chip. Taken from FreeBSD
 1.41.12.5 19-Jun-2009  snj Pull up following revision(s) (requested by tsutsui in ticket #821):
sys/dev/ic/rtl8169.c: revisions 1.107, 1.114-1.119, 1.121
sys/dev/ic/rtl81x9reg.h: revisions 1.36-1.39
sys/dev/ic/rtl81x9var.h: revision 1.47
sys/dev/mii/rgephy.c: revision 1.27 via patch
sys/dev/pci/if_re_pci.c: revision 1.36
remove extra semicolons.
--
Add HWREV values of RTL8168CP and RTL8168D. From FreeBSD.

XXX: needs more quirk handling after wakeup for newer chips.
--
Add HWREV of RTL8102EL variant. From FUKAUMI Naoki.
--
Assume an unknown HWREV chip has the same features with the latest one.
--
Remove suffix "B" from rtk_name of PCI_PRODUCT_REALTEK_RT8168 devices.
All 8168/8111 variants (8168/8168B/8168C/8168CP/8168D/8111B/8111C/8111CP)
have the same PCI device ID.
--
Remove magic reset sequence except wakeup for rev 2 chips which breaks 8111D.
Problem reported and fix confirmed by Thomas Bieg on current-users.

Also tested on 8111C (no bad side effect) by several users privately.
--
Pull some changes for newer chips from FreeBSD:
- pull MACSTAT and CMDSTOP quirks for 8168/8111 chips
- always set CPLUSCMD_PCI_MRW on reset
- set VLANSTRIP and RXCSUM_ENB bits on CPLUS register per if_capenable

Tested on 8111C and 8111D by several users, and
no bad side effect on my old 8169S.
--
Remove unused sc_rev settings (all quirks are handled by sc_quirk)
and merge HWREV cases which have the same quirks.
--
- rename RTK_HWREV_8102EL_SPIN2 -> RTK_HWREV_8103E
- add a HWREV value for 8168DP
Per Realtek's Linux drivers.
--
Two fixes for RX hwcsum on DESCV2 chips:
* On checking TCPv4/UDPv4 RX checksum on DESCV2 chips, also check
RE_RDESC_VLANCTL_IPV4 bit because those DESCV2 chips may also recognize
IPv6 packets and set RE_PROTOID_TCPIP or RE_PROTOID_UDPIP bits for
TCPv6/UDPv6 packets. This may fix PR kern/40605.
* According to Realtek's Linux driver, DESCV2 chips don't set RE_PROTOID_IP
for non-TCP/UDP IP packets (set only RE_RDESC_VLANCTL_IPV[46]) so
remove PROTOID check for IPv4 RX cheksum on DESCV2 chips.
 1.41.12.4 01-May-2009  snj Pull up following revision(s) (requested by tsutsui in ticket #597):
sys/dev/ic/rtl8169.c: revision 1.111
sys/dev/ic/rtl81x9var.h: revision 1.45
Add another quirk flag which shows availability of EEPROM command register.
Now we can remove sc_rev which was intended to represent "MAC revision"
used in the Realtek driver.
 1.41.12.3 01-May-2009  snj Pull up following revision(s) (requested by tsutsui in ticket #597):
sys/dev/ic/rtl8169.c: revision 1.110
sys/dev/ic/rtl81x9var.h: revision 1.44
Add and use a new quirk flag to disable JUMBO MTU,
rather than checking sc_rev values.
 1.41.12.2 01-May-2009  snj Pull up following revision(s) (requested by tsutsui in ticket #597):
sys/dev/ic/rtl8169.c: revision 1.109
sys/dev/ic/rtl81x9reg.h: revision 1.34
sys/dev/ic/rtl81x9var.h: revision 1.43
Add hardware checksum support for newer PCIe 8168/8111/8102 chips,
per device info taken from FreeBSD driver. Tested by snj@ on 8111C.
Should closes PR kern/40955.
Note on old 8169 chips IP hw csum must be enabled to use TCP/UDP hw csums,
but I'm not sure if these newer chips still have the same restriction.
 1.41.12.1 24-Mar-2009  snj branches: 1.41.12.1.4;
Pull up following revision(s) (requested by tsutsui in ticket #596):
sys/dev/ic/rtl8169.c: revision 1.108
sys/dev/ic/rtl81x9var.h: revision 1.42
Access LDPS register in re_reset() only on 8169S single chip variants.
From OpenBSD and FreeBSD drivers via PR kern/41009, and
Realtek-supplied FreeBSD driver.
 1.41.12.1.4.1 21-Apr-2010  matt sync to netbsd-5
 1.41.10.1 28-Apr-2009  skrll Sync with HEAD.
 1.41.2.4 11-Aug-2010  yamt sync with head.
 1.41.2.3 16-Sep-2009  yamt sync with head
 1.41.2.2 16-May-2009  yamt sync with head
 1.41.2.1 04-May-2009  yamt sync with head.
 1.49.4.1 05-Mar-2011  rmind sync with head
 1.49.2.1 17-Aug-2010  uebayasi Sync with HEAD.
 1.50.8.1 17-Apr-2012  yamt sync with head
 1.52.2.1 18-Feb-2012  mrg merge to -current.
 1.53.6.1 03-Dec-2017  jdolecek update from HEAD
 1.54.2.2 28-Aug-2017  skrll Sync with HEAD
 1.54.2.1 06-Jun-2015  skrll Sync with HEAD
 1.55.4.1 21-Apr-2017  bouyer Sync with HEAD
 1.55.2.1 26-Apr-2017  pgoyette Sync with HEAD
 1.56.18.2 04-Aug-2023  martin Pull up following revision(s) (requested by jakllsch in ticket #1705):

sys/dev/ic/rtl81x9var.h: revision 1.58
sys/dev/ic/rtl81x9reg.h: revision 1.54
sys/dev/ic/rtl8169.c: revision 1.167
sys/dev/ic/rtl8169.c: revision 1.168

re(4): misc chip revision support changes
* remove impossible-to-match chip revision cases
* bring support for modern chips in line with FreeBSD and OpenBSD
* adds support for RTL8168GU

Addresses PR kern/56312.

- Print chip revision. From OpenBSD.
- Rename RTK_HWREV_8168_SPIN[123] to RTK_HWREV_8168'B'_SPIN[123].
Same as other *BSDs.
- Rename RTK_HWREV_8168G_SPIN4 to RTK_HWREV_8411B. Same as other *BSDs.
- Add definition of RTK_HWREV_8169_8110SCE.
 1.56.18.1 28-Jan-2020  martin Pull up following revision(s) (requested by msaitoh in ticket #667):

sys/dev/ic/rtl81x9var.h: revision 1.57
sys/dev/ic/rtl81x9.c: revision 1.107
sys/dev/ic/rtl81x9reg.h: revision 1.51
sys/dev/ic/rtl8169.c: revision 1.160
sys/dev/ic/rtl81x9reg.h: revision 1.52
sys/dev/ic/rtl8169.c: revision 1.161

Use unsigned in rtk_setmulti() to avoid undefined behavior. Found bk kUBSan.
8168H model didn't link up well. some models seems to require to enable TX/RX after configuration.
RTKQ_TXRXEN_LATER quirk flag added. it may be able to unify with RTKQ_RXDV_GATED flag?
Sort RTK_HWREV_* by value.

Improve some chip revisions support:
- Add 8168FP, 8411, 8168G, 8401E, 8105E, 8105E_SPIN1, 8106E and 8402 from
{Free,Open}BSD.
- Renumber RTK_HWREV_8103E from 0x24C00000 to 0x34c00000. 0x24C00000 is newly
used as RTK_HWREV_8102EL_SPIN1. Same as {Free,Open}BSD.
 1.56.12.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.58.26.1 02-Aug-2025  perseant Sync with HEAD
 1.7 11-Aug-2023  mrg avoid uninitialised variable warnings (likely incorrect ones.)

cry wolved by GCC 12.
 1.6 07-Aug-2021  thorpej Merge thorpej-cfargs2.
 1.5 24-Apr-2021  thorpej branches: 1.5.8;
Merge thorpej-cfargs branch:

Simplify and make extensible the config_search() / config_found() /
config_attach() interfaces: rather than having different variants for
which arguments you want pass along, just have a single call that
takes a variadic list of tag-value arguments.

Adjust all call sites:
- Simplify wherever possible; don't pass along arguments that aren't
actually needed.
- Don't be explicit about what interface attribute is attaching if
the device only has one. (More simplification.)
- Add a config_probe() function to be used in indirect configuiration
situations, making is visibly easier to see when indirect config is
in play, and allowing for future change in semantics. (As of now,
this is just a wrapper around config_match(), but that is an
implementation detail.)

Remove unnecessary or redundant interface attributes where they're not
needed.

There are currently 5 "cfargs" defined:
- CFARG_SUBMATCH (submatch function for direct config)
- CFARG_SEARCH (search function for indirect config)
- CFARG_IATTR (interface attribte)
- CFARG_LOCATORS (locators array)
- CFARG_DEVHANDLE (devhandle_t - wraps OFW, ACPI, etc. handles)

...and a sentinel value CFARG_EOL.

Add some extra sanity checking to ensure that interface attributes
aren't ambiguous.

Use CFARG_DEVHANDLE in MI FDT, OFW, and ACPI code, and macppc and shark
ports to associate those device handles with device_t instance. This
will trickle trough to more places over time (need back-end for pre-OFW
Sun OBP; any others?).
 1.4 19-Dec-2019  kamil branches: 1.4.10;
Avoid changing signedness bit with << in rtsx_read_cfg()

Reported by <prlw1>
 1.3 24-Apr-2018  maya branches: 1.3.2;
rtsx(4): Add support for RT525A, from openbsd.

ok rkujawa
 1.2 29-Oct-2014  nonaka branches: 1.2.12; 1.2.18;
Added RTS5227/RTL8402/RTL8411/RTL8411B support.
 1.1 19-Mar-2014  nonaka branches: 1.1.4; 1.1.6; 1.1.8; 1.1.10;
Add a driver for Realtek RTS5209/RTS5229 Card Reader.
Ported from OpenBSD.
 1.1.10.3 03-Dec-2017  jdolecek update from HEAD
 1.1.10.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.1.10.1 19-Mar-2014  tls file rtsx.c was added on branch tls-maxphys on 2014-08-20 00:03:38 +0000
 1.1.8.1 17-Jan-2015  martin Pull up following revision(s) (requested by nonaka in ticket #432):
sys/dev/ic/rtsxreg.h: revision 1.2
sys/dev/ic/rtsxvar.h: revision 1.2
sys/dev/pci/rtsx_pci.c: revision 1.3
sys/dev/ic/rtsx.c: revision 1.2
share/man/man4/rtsx.4: revision 1.3-1.4
Added RTS5227/RTL8402/RTL8411/RTL8411B support.
 1.1.6.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.1.6.1 19-Mar-2014  yamt file rtsx.c was added on branch yamt-pagecache on 2014-05-22 11:40:22 +0000
 1.1.4.2 18-May-2014  rmind sync with head
 1.1.4.1 19-Mar-2014  rmind file rtsx.c was added on branch rmind-smpnet on 2014-05-18 17:45:37 +0000
 1.2.18.1 02-May-2018  pgoyette Synch with HEAD
 1.2.12.1 14-Jun-2018  martin Pull up following revision(s) (requested by maya in ticket #878):

share/man/man4/rtsx.4: revision 1.5
sys/dev/pci/pcidevs: revision 1.1331
sys/dev/ic/rtsxreg.h: revision 1.3
sys/dev/ic/rtsxvar.h: revision 1.3
sys/dev/pci/rtsx_pci.c: revision 1.7
sys/dev/ic/rtsx.c: revision 1.3

add realtek RT525A PCI-E card reader
found in my Dell XPS 15 9550.

rtsx(4): Add support for RT525A, from openbsd.
ok rkujawa

Denote RTS525A, bump date
 1.3.2.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.4.10.1 21-Mar-2021  thorpej Give config_found() the same variadic arguments treatment as
config_search(). This commit only adds the CFARG_EOL sentinel
to the existing config_found() calls. Conversion of config_found_sm_loc()
and config_found_ia() call sites will be in subsequent commits.
 1.5.8.1 04-Aug-2021  thorpej Adapt to CFARGS().
 1.3 24-Apr-2018  maya rtsx(4): Add support for RT525A, from openbsd.

ok rkujawa
 1.2 29-Oct-2014  nonaka branches: 1.2.12; 1.2.18;
Added RTS5227/RTL8402/RTL8411/RTL8411B support.
 1.1 19-Mar-2014  nonaka branches: 1.1.4; 1.1.6; 1.1.8; 1.1.10;
Add a driver for Realtek RTS5209/RTS5229 Card Reader.
Ported from OpenBSD.
 1.1.10.3 03-Dec-2017  jdolecek update from HEAD
 1.1.10.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.1.10.1 19-Mar-2014  tls file rtsxreg.h was added on branch tls-maxphys on 2014-08-20 00:03:38 +0000
 1.1.8.1 17-Jan-2015  martin Pull up following revision(s) (requested by nonaka in ticket #432):
sys/dev/ic/rtsxreg.h: revision 1.2
sys/dev/ic/rtsxvar.h: revision 1.2
sys/dev/pci/rtsx_pci.c: revision 1.3
sys/dev/ic/rtsx.c: revision 1.2
share/man/man4/rtsx.4: revision 1.3-1.4
Added RTS5227/RTL8402/RTL8411/RTL8411B support.
 1.1.6.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.1.6.1 19-Mar-2014  yamt file rtsxreg.h was added on branch yamt-pagecache on 2014-05-22 11:40:22 +0000
 1.1.4.2 18-May-2014  rmind sync with head
 1.1.4.1 19-Mar-2014  rmind file rtsxreg.h was added on branch rmind-smpnet on 2014-05-18 17:45:37 +0000
 1.2.18.1 02-May-2018  pgoyette Synch with HEAD
 1.2.12.1 14-Jun-2018  martin Pull up following revision(s) (requested by maya in ticket #878):

share/man/man4/rtsx.4: revision 1.5
sys/dev/pci/pcidevs: revision 1.1331
sys/dev/ic/rtsxreg.h: revision 1.3
sys/dev/ic/rtsxvar.h: revision 1.3
sys/dev/pci/rtsx_pci.c: revision 1.7
sys/dev/ic/rtsx.c: revision 1.3

add realtek RT525A PCI-E card reader
found in my Dell XPS 15 9550.

rtsx(4): Add support for RT525A, from openbsd.
ok rkujawa

Denote RTS525A, bump date
 1.3 24-Apr-2018  maya rtsx(4): Add support for RT525A, from openbsd.

ok rkujawa
 1.2 29-Oct-2014  nonaka branches: 1.2.12; 1.2.18;
Added RTS5227/RTL8402/RTL8411/RTL8411B support.
 1.1 19-Mar-2014  nonaka branches: 1.1.4; 1.1.6; 1.1.8; 1.1.10;
Add a driver for Realtek RTS5209/RTS5229 Card Reader.
Ported from OpenBSD.
 1.1.10.3 03-Dec-2017  jdolecek update from HEAD
 1.1.10.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.1.10.1 19-Mar-2014  tls file rtsxvar.h was added on branch tls-maxphys on 2014-08-20 00:03:38 +0000
 1.1.8.1 17-Jan-2015  martin Pull up following revision(s) (requested by nonaka in ticket #432):
sys/dev/ic/rtsxreg.h: revision 1.2
sys/dev/ic/rtsxvar.h: revision 1.2
sys/dev/pci/rtsx_pci.c: revision 1.3
sys/dev/ic/rtsx.c: revision 1.2
share/man/man4/rtsx.4: revision 1.3-1.4
Added RTS5227/RTL8402/RTL8411/RTL8411B support.
 1.1.6.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.1.6.1 19-Mar-2014  yamt file rtsxvar.h was added on branch yamt-pagecache on 2014-05-22 11:40:22 +0000
 1.1.4.2 18-May-2014  rmind sync with head
 1.1.4.1 19-Mar-2014  rmind file rtsxvar.h was added on branch rmind-smpnet on 2014-05-18 17:45:37 +0000
 1.2.18.1 02-May-2018  pgoyette Synch with HEAD
 1.2.12.1 14-Jun-2018  martin Pull up following revision(s) (requested by maya in ticket #878):

share/man/man4/rtsx.4: revision 1.5
sys/dev/pci/pcidevs: revision 1.1331
sys/dev/ic/rtsxreg.h: revision 1.3
sys/dev/ic/rtsxvar.h: revision 1.3
sys/dev/pci/rtsx_pci.c: revision 1.7
sys/dev/ic/rtsx.c: revision 1.3

add realtek RT525A PCI-E card reader
found in my Dell XPS 15 9550.

rtsx(4): Add support for RT525A, from openbsd.
ok rkujawa

Denote RTS525A, bump date
 1.137 10-Nov-2021  msaitoh s/desciptor/descriptor/ in comment.
 1.136 16-Jun-2021  riastradh if_attach and if_initialize cannot fail, don't test return value

These were originally made failable back in 2017 when if_initialize
allocated a softint in every interface for link state changes, so
that it could fail gracefully instead of panicking:

https://mail-index.NetBSD.org/source-changes/2017/10/23/msg089053.html

However, this spawned many seldom- or never-tested error branches,
which are risky to have around. And that softint in every interface
has since been replaced by a single global workqueue, because link
state changes require thread context but not low latency or high
throughput:

https://mail-index.NetBSD.org/source-changes/2020/02/06/msg113759.html

So there is no longer any reason for if_initialize to fail. (The
subroutine if_stats_init can't fail because percpu_alloc can't fail
either.)

There is a snag: the softint_establish in if_percpuq_create could
fail, potentially leading to bad consequences later on trying to use
the softint. This change doesn't introduce any new bugs because of
the snag -- if_percpuq_attach was already broken. However, the snag
can be better addressed without spawning error branches, either by
using a single softint or making softints less scarce.

(Separate commit will change the signatures of if_attach and
if_initialize to return void, scheduled to ride whatever is the next
convenient kernel bump.)

Patch and testing on amd64 and evbmips64-eb by maya@; commit message
soliloquy, and compile-testing on evbppc/i386/earmv7hf, by me.
 1.135 29-Jan-2020  thorpej branches: 1.135.10;
Adopt <net/if_stats.h>.
 1.134 10-Nov-2019  chs branches: 1.134.2;
in many device attach paths, allocate memory with M_WAITOK instead of M_NOWAIT
and remove code to handle failures that can no longer happen.
 1.133 28-May-2019  msaitoh Use ETHER_LOCK()/ETHER_UNLOCK() for all ethernet drivers to protect ec_multi*.
 1.132 23-May-2019  msaitoh Whitespace fix (mainly tabify).
 1.131 23-May-2019  msaitoh -No functional change:
- KNF
- u_int*_t -> uint*_t.
 1.130 05-Feb-2019  msaitoh Remove very old IFF_NOTRAILERS flag.
 1.129 03-Feb-2019  mrg - add or adjust /* FALLTHROUGH */ where appropriate
- add __unreachable() after functions that can return but won't in
this case, and thus can't be marked __dead easily
 1.128 26-Jun-2018  msaitoh branches: 1.128.2;
Implement the BPF direction filter (BIOC[GS]DIRECTION). It provides backward
compatibility with BIOC[GS]SEESENT ioctl. The userland interface is the same
as FreeBSD.

This change also fixes a bug that the direction is misunderstand on some
environment by passing the direction to bpf_mtap*() instead of checking
m->m_pkthdr.rcvif.
 1.127 23-Oct-2017  msaitoh branches: 1.127.2;
If if_initialize() failed in the attach function, free resources and return.
 1.126 23-May-2017  ozaki-r branches: 1.126.2;
Apply deferred if_start to more drivers

And annotate some XXX_start as it runs in softint to clarify that
it doesn't need deferred if_start.
 1.125 02-Feb-2017  nonaka wlan interfaces make interrupt routine running on softint context.

see http://mail-index.netbsd.org/tech-kern/2016/12/06/msg021281.html

tested device:
* ath at pci: AR5212, AR5424
* athn at pci: AR9287
* ipw at pci: 2100BG
* iwi at pci: 2915ABG
* iwm at pci: 3165, 7260, 8260
* iwn at pci: 4945, 6235
* ral at pci: RT2560
* rtwn at pci: RTL8192CE
 1.124 15-Sep-2016  jdolecek branches: 1.124.2;
remove last isolated islands using BUS_SPACE_BARRIER_SYNC and
BUS_SPACE_BARRIER_X_BEFORE_X - these were only ever defined for mips and ia64,
and never actually implemented even there
 1.123 10-Jun-2016  ozaki-r branches: 1.123.2;
Introduce m_set_rcvif and m_reset_rcvif

The API is used to set (or reset) a received interface of a mbuf.
They are counterpart of m_get_rcvif, which will come in another
commit, hide internal of rcvif operation, and reduce the diff of
the upcoming change.

No functional change.
 1.122 16-May-2016  ozaki-r Use M_GETCTX and M_SETCTX instead of open-coding rcvif

No functional change.
 1.121 25-Feb-2014  pooka branches: 1.121.6;
Ensure that the top level sysctl nodes (kern, vfs, net, ...) exist before
the sysctl link sets are processed, and remove redundancy.

Shaves >13kB off of an amd64 GENERIC, not to mention >1k duplicate
lines of code.
 1.120 17-Oct-2013  christos - remove unused variables
- move variables inside ifdef sections
- ifdef notdef unused code
- use __USE for debugging variables
 1.119 04-Jul-2011  joerg branches: 1.119.2; 1.119.12; 1.119.16;
Fix memset usage.
 1.118 15-Nov-2010  uebayasi Socket ioctl definitions need sys/sockio.h.
 1.117 13-Nov-2010  uebayasi Don't pull in the whole uvm(9) API to access only PAGE_SIZE and
some other constants. These are provided by sys/param.h now.
 1.116 05-Apr-2010  joerg Push the bpf_ops usage back into bpf.h. Push the common ifp->if_bpf
check into the inline functions as well the fourth argument for
bpf_attach.
 1.115 15-Mar-2010  dyoung Make this compile on sparc64:

1 s/next_tick/next_tint/ because next_tick shadows a global on sparc64.

2 Fix the bus-barrier helper routines, which had the tag & handle
swapped (!!). Move the helpers from rtwreg.h to rtwvar.h, and
change RTW_BARRIER() into an inline subroutine called rtw_barrier().
 1.114 24-Feb-2010  dyoung branches: 1.114.2;
A pointer typedef entails trading too much flexibility to declare const
and non-const types, and the kernel uses both const and non-const
PMF qualifiers and device suspensors, so change the pmf_qual_t and
device_suspensor_t typedefs from "pointers to const" to non-pointer,
non-const types.
 1.113 31-Jan-2010  dyoung branches: 1.113.2;
Add the missing newline to a verbose autoconf message.
 1.112 19-Jan-2010  pooka Redefine bpf linkage through an always present op vector, i.e.
#if NBPFILTER is no longer required in the client. This change
doesn't yet add support for loading bpf as a module, since drivers
can register before bpf is attached. However, callers of bpf can
now be modularized.

Dynamically loadable bpf could probably be done fairly easily with
coordination from the stub driver and the real driver by registering
attachments in the stub before the real driver is loaded and doing
a handoff. ... and I'm not going to ponder the depths of unload
here.

Tested with i386/MONOLITHIC, modified MONOLITHIC without bpf and rump.
 1.111 08-Jan-2010  dyoung Expand PMF_FN_* macros.
 1.110 19-Oct-2009  rmind Drop 3rd and 4th clauses from David Young's license.
Reviewed and approved by dyoung@ (copyright holder).
 1.109 16-Sep-2009  dyoung In pmf(9), improve the implementation of device self-suspension
and make suspension by self, by drvctl(8), and by ACPI system sleep
play nice together. Start solidifying some temporary API changes.

1. Extract a new header file, <sys/device_if.h>, from <sys/device.h> and
#include it from <sys/pmf.h> instead of <sys/device.h> to break the
circular dependency between <sys/device.h> and <sys/pmf.h>.

2. Introduce pmf_qual_t, an aggregate of qualifications on a PMF
suspend/resume call. Start to replace instances of PMF_FN_PROTO,
PMF_FN_ARGS, et cetera, with a pmf_qual_t.

3. Introduce the notion of a "suspensor," an entity that holds a
device in suspension. More than one suspensor may hold a device
at once. A device stays suspended as long as at least one
suspensor holds it. A device resumes when the last suspensor
releases it.

Currently, the kernel defines three suspensors,

3a the system-suspensor: for system suspension, initiated
by 'sysctl -w machdep.sleep_state=3', by lid closure, by
power-button press, et cetera,

3b the drvctl-suspensor: for device suspension by /dev/drvctl
ioctl, e.g., drvctl -S sip0.

3c the system self-suspensor: for device drivers that suspend
themselves and their children. Several drivers for network
interfaces put the network device to sleep while it is not
administratively up, that is, after the kernel calls if_stop(,
1). The self-suspensor should not be used directly. See
the description of suspensor delegates, below.

A suspensor can have one or more "delegates". A suspensor can
release devices that its delegates hold suspended. Right now,
only the system self-suspensor has delegates. For each device
that a self-suspending driver attaches, it creates the device's
self-suspensor, a delegate of the system self-suspensor.

Suspensors stop a system-wide suspend/resume cycle from waking
devices that the operator put to sleep with drvctl before the cycle.
They also help self-suspension to work more simply, safely, and in
accord with expectations.

4. Add the notion of device activation level, devact_level_t,
and a routine for checking the current activation level,
device_activation(). Current activation levels are DEVACT_LEVEL_BUS,
DEVACT_LEVEL_DRIVER, and DEVACT_LEVEL_CLASS, which respectively
indicate that the device's bus is active, that the bus and device are
active, and that the bus, device, and the functions of the device's
class (network, audio) are active.

Suspend/resume calls can be qualified with a devact_level_t.
The power-management framework treats a devact_level_t that
qualifies a device suspension as the device's current activation
level; it only runs hooks to reduce the activation level from
the presumed current level to the fully suspended state. The
framework treats a devact_level_t qualifying device resumption
as the target activation level; it only runs hooks to raise the
activation level to the target.

5. Use pmf_qual_t, devact_level_t, and self-suspensors in several
drivers.

6. Temporarily add an unused power-management workqueue that I will
remove or replace, soon.
 1.108 07-Apr-2009  dyoung Cosmetic: remove some dead code.
 1.107 02-Apr-2009  dyoung Add the WEP capability to our net80211 capability flags, since we do
sort of support hardware WEP. Only change the WEP key index in a Tx
descriptor from 0 if the type of our transmit key is _WEP, not _TKIP:
i.e., only if we're really doing WEP crypto in the hardware.

Ignore a watchdog timeout on any Tx ring if we can collect some packets
from that ring. Restart both the receiver and the transmitter when a
watchdog timeout occurs instead of restarting only the transmitter.
 1.106 12-Nov-2008  ad branches: 1.106.4;
Remove LKMs and switch to the module framework, pass 1.

Proposed on tech-kern@.
 1.105 07-Nov-2008  dyoung *** Summary ***

When a link-layer address changes (e.g., ifconfig ex0 link
02:de:ad:be:ef:02 active), send a gratuitous ARP and/or a Neighbor
Advertisement to update the network-/link-layer address bindings
on our LAN peers.

Refuse a change of ethernet address to the address 00:00:00:00:00:00
or to any multicast/broadcast address. (Thanks matt@.)

Reorder ifnet ioctl operations so that driver ioctls may inherit
the functions of their "class"---ether_ioctl(), fddi_ioctl(), et
cetera---and the class ioctls may inherit from the generic ioctl,
ifioctl_common(), but both driver- and class-ioctls may override
the generic behavior. Make network drivers share more code.

Distinguish a "factory" link-layer address from others for the
purposes of both protecting that address from deletion and computing
EUI64.

Return consistent, appropriate error codes from network drivers.

Improve readability. KNF.

*** Details ***

In if_attach(), always initialize the interface ioctl routine,
ifnet->if_ioctl, if the driver has not already initialized it.
Delete if_ioctl == NULL tests everywhere else, because it cannot
happen.

In the ioctl routines of network interfaces, inherit common ioctl
behaviors by calling either ifioctl_common() or whichever ioctl
routine is appropriate for the class of interface---e.g., ether_ioctl()
for ethernets.

Stop (ab)using SIOCSIFADDR and start to use SIOCINITIFADDR. In
the user->kernel interface, SIOCSIFADDR's argument was an ifreq,
but on the protocol->ifnet interface, SIOCSIFADDR's argument was
an ifaddr. That was confusing, and it would work against me as I
make it possible for a network interface to overload most ioctls.
On the protocol->ifnet interface, replace SIOCSIFADDR with
SIOCINITIFADDR. In ifioctl(), return EPERM if userland tries to
invoke SIOCINITIFADDR.

In ifioctl(), give the interface the first shot at handling most
interface ioctls, and give the protocol the second shot, instead
of the other way around. Finally, let compatibility code (COMPAT_OSOCK)
take a shot.

Pull device initialization out of switch statements under
SIOCINITIFADDR. For example, pull ..._init() out of any switch
statement that looks like this:

switch (...->sa_family) {
case ...:
..._init();
...
break;
...
default:
..._init();
...
break;
}

Rewrite many if-else clauses that handle all permutations of IFF_UP
and IFF_RUNNING to use a switch statement,

switch (x & (IFF_UP|IFF_RUNNING)) {
case 0:
...
break;
case IFF_RUNNING:
...
break;
case IFF_UP:
...
break;
case IFF_UP|IFF_RUNNING:
...
break;
}

unifdef lots of code containing #ifdef FreeBSD, #ifdef NetBSD, and
#ifdef SIOCSIFMTU, especially in fwip(4) and in ndis(4).

In ipw(4), remove an if_set_sadl() call that is out of place.

In nfe(4), reuse the jumbo MTU logic in ether_ioctl().

Let ethernets register a callback for setting h/w state such as
promiscuous mode and the multicast filter in accord with a change
in the if_flags: ether_set_ifflags_cb() registers a callback that
returns ENETRESET if the caller should reset the ethernet by calling
if_init(), 0 on success, != 0 on failure. Pull common code from
ex(4), gem(4), nfe(4), sip(4), tlp(4), vge(4) into ether_ioctl(),
and register if_flags callbacks for those drivers.

Return ENOTTY instead of EINVAL for inappropriate ioctls. In
zyd(4), use ENXIO instead of ENOTTY to indicate that the device is
not any longer attached.

Add to if_set_sadl() a boolean 'factory' argument that indicates
whether a link-layer address was assigned by the factory or some
other source. In a comment, recommend using the factory address
for generating an EUI64, and update in6_get_hw_ifid() to prefer a
factory address to any other link-layer address.

Add a routing message, RTM_LLINFO_UPD, that tells protocols to
update the binding of network-layer addresses to link-layer addresses.
Implement this message in IPv4 and IPv6 by sending a gratuitous
ARP or a neighbor advertisement, respectively. Generate RTM_LLINFO_UPD
messages on a change of an interface's link-layer address.

In ether_ioctl(), do not let SIOCALIFADDR set a link-layer address
that is broadcast/multicast or equal to 00:00:00:00:00:00.

Make ether_ioctl() call ifioctl_common() to handle ioctls that it
does not understand.

In gif(4), initialize if_softc and use it, instead of assuming that
the gif_softc and ifp overlap.

Let ifioctl_common() handle SIOCGIFADDR.

Sprinkle rtcache_invariants(), which checks on DIAGNOSTIC kernels
that certain invariants on a struct route are satisfied.

In agr(4), rewrite agr_ioctl_filter() to be a bit more explicit
about the ioctls that we do not allow on an agr(4) member interface.

bzero -> memset. Delete unnecessary casts to void *. Use
sockaddr_in_init() and sockaddr_in6_init(). Compare pointers with
NULL instead of "testing truth". Replace some instances of (type
*)0 with NULL. Change some K&R prototypes to ANSI C, and join
lines.
 1.104 15-Mar-2008  dyoung branches: 1.104.4; 1.104.10; 1.104.12;
Cosmetic: make rtw_hw_keysupp() return a bool instead of int. In
rtw_wep_setkeys(), add a debug printf, and move the initialization
of keylen from the for-loop to the declaration.
 1.103 14-Mar-2008  dyoung Extract subroutine rtw_tx_kick() from rtw_start(), and reuse it in
rtw_io_enable() to restart the transmitter after resetting it.
 1.102 14-Mar-2008  dyoung Change tests for "impossible" keys to KASSERT()s. Get rid of a
temporary variable. In rtw_key_delete(), do not invalidate the
hardware keys unless a WEP key is deleted.
 1.101 12-Mar-2008  dyoung Use device_t and its accessors throughout. Use aprint_*_dev().

Improve PMF-ability.

Add a 'flags' argument to suspend/resume handlers and
callers such as pmf_system_suspend().

Define a flag, PMF_F_SELF, which indicates to PMF that a
device is suspending/resuming itself. Add helper routines,
pmf_device_suspend_self(dev) and pmf_device_resume_self(dev),
that call pmf_device_suspend(dev, PMF_F_SELF) and
pmf_device_resume(dev, PMF_F_SELF), respectively. Use
PMF_F_SELF to suspend/resume self in ath(4), audio(4),
rtw(4), and sip(4).

In ath(4) and in rtw(4), replace the icky sc_enable/sc_disable
callbacks, provided by the bus front-end, with
self-suspension/resumption. Also, clean up the bus
front-ends. Make sure that the interrupt handler is
disestablished during suspension. Get rid of driver-private
flags (e.g., RTW_F_ENABLED, ath_softc->sc_invalid); use
device_is_active()/device_has_power() calls, instead.

In the network-class suspend handler, call if_stop(, 0)
instead of if_stop(, 1), because the latter is superfluous
(bus- and driver-suspension hooks will 'disable' the NIC),
and it may cause recursion.

In the network-class resume handler, prevent infinite
recursion through if_init() by getting out early if we are
self-suspending (PMF_F_SELF).

rtw(4) improvements:

Destroy rtw(4) callouts when we detach it. Make rtw at
pci detachable. Print some more information with the "rx
frame too long" warning.

Remove activate() methods:

Get rid of rtw_activate() and ath_activate(). The device
activate() methods are not good for much these days.

Make ath at cardbus resume with crypto functions intact:

Introduce a boolean device property, "pmf-powerdown". If
pmf-powerdown is present and false, it indicates that a
bus back-end should not remove power from a device.

Honor this property in cardbus_child_suspend().

Set this property to 'false' in ath_attach(), since removing
power from an ath at cardbus seems to lobotomize the WPA
crypto engine. XXX Should the pmf-powerdown property
propagate toward the root of the device tree?

Miscellaneous ath(4) changes:

Warn if ath(4) tries to write crypto keys to suspended
hardware.

Reduce differences between FreeBSD and NetBSD in ath(4)
multicast filter setup.

Make ath_printrxbuf() print an rx descriptor's status &
key index, to help debug crypto errors.

Shorten a staircase in ath_ioctl(). Don't check for
ieee80211_ioctl() return code ERESTART, it never happens.
 1.100 12-Mar-2008  dyoung Print the TPPoll register when the Tx DMA engine doesn't shut down
in the time we allow.
 1.99 03-Mar-2008  tsutsui Explicitly include <sys/device.h> for device_t.
 1.98 21-Dec-2007  dyoung branches: 1.98.2; 1.98.6;
Do not embed a struct device in rtw_softc any longer. Register
both pci and cardbus attachments with CFATTACH_DECL_NEW(). Access
the softc through the device_t using device_private().

While I'm here, change a couple of KASSERT()s about the Rx buffer
length to a warning.
 1.97 20-Dec-2007  dyoung Remove shutdown hooks. Use KASSERT().
 1.96 16-Dec-2007  dyoung Fix a bug I introduced to rtw_chan2txpower() the other night.

Fix a bug in device detachment: change a break statement to a
/*FALLTHROUGH*/ in rtw_detach().
 1.95 16-Dec-2007  dyoung Synchronize device detachment with network interrupts. Use the
pmf network class instead of powerhooks.
 1.94 18-Nov-2007  jnemeth branches: 1.94.2; 1.94.6;
fix 'm' used unitialized
 1.93 16-Nov-2007  dyoung Accommodate the variety of RF front-ends when radiotapping frames:
tap only RSSI when there is a Philips RF front-end. Tap both Barker
lock quality and RSSI when there is any other RF front-end.

Provide radiotap listeners a more complete picture of channel
activity:

in promiscuous mode, tap frames who do not pass the CRC32 check.
Flag packets that were received with a short preamble. Ask
the NIC to pass us 802.11 Control frames. Pass frames to
radiotap listeners before stripping the FCS. Re-order operations
in rtw_intr_rx() in order to accomplish all of this, taking
care not to pass a broken packet to net80211!

Do not provide a flags field when tapping xmitted frames.

Assert sane Rx packet lengths. Really should check and drop instead
of KASSERTing. I will revisit this, soon.

Update copyright.
 1.92 15-Nov-2007  dyoung Fix order of operations:

rtw_rxdesc_init: before initializing a Rx descriptor's
control word, synchronize the Rx buffer

rtw_start, be paranoid: set the "NIC owns" bit on a Tx
descriptor dead last. Always reinitialize the "next
Tx descriptor" pointer, just in case it got clobbered
somehow.

Let the compiler decide whether to inline rtw_collect_txring or
not.
 1.91 19-Oct-2007  ad branches: 1.91.2;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.90 29-Sep-2007  scw branches: 1.90.2;
s/NPBFILTER/NBPFILTER/ in some #endif comments. No functional change.
 1.89 09-Jul-2007  ad branches: 1.89.6; 1.89.8; 1.89.10;
Merge some of the less invasive changes from the vmlocking branch:

- kthread, callout, devsw API changes
- select()/poll() improvements
- miscellaneous MT safety improvements
 1.88 29-May-2007  dyoung Fix rtw(4) on NetBSD/macppc: use bus_space_write_region_stream_4()
instead of bus_space_write_region_4() to write WEP Rx keys to the
NIC. Thanks macallan@ for detecting the bug and testing the fix.
 1.87 29-May-2007  dyoung Cosmetic: simplify a memset() statement, use __arraycount(), and
remove a gratuitous return statement at the end of a void subroutine.
 1.86 29-May-2007  dyoung Simplify multicast filter programming, and take care to avoid
gratuitous device resets when the kernel adds/deletes a multicast
address.
 1.85 04-Mar-2007  christos branches: 1.85.2; 1.85.4;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.84 29-Jan-2007  dyoung branches: 1.84.2;
In rtw_dequeue(), initialize *mp to NULL before anything else, so
that it is either NULL or a valid mbuf. Previously, it was possible
for rtw_dequeue() to exit with 0 before initializing *mp. rtw_start()
would have used whatever trash was in *mp, which would lead to
problems later on.
 1.83 06-Jan-2007  dyoung I have made a small change that suppresses "recovery" from (spurious?)
tx timeouts on the beacon queue. The driver's recovery process
badly disrupts the MAC's receiver. This needs a closer look, later.

Every other fix is by Charles M. Hannum. Charles writes:

"With these, the device is quite stable under load, does not experience
xmit timeouts, no longer mysteriously freezes, and does not spew
a lot of garbage. It does, however, continue to get some "tx fifo
underflow"s.

global, SYSCTL_SETUP():
a) Removed unused sysctl variables.

rtw_io_enable():
b) Change rtw_io_enable to take a softc, and make it call
rtw_txring_fixup().
c) Enable the PCI multiple read/write bit.
d) Always reset rdb_next to 0 when starting the receive engine.

rtw_intr_rx():
e) When processing receive packets, store the next pointer in rdb_next
and read it back on the next round, to fix a race condition vs.
rtw_tune() during AP discovery and association.
f) Remove the special "skip to 0th descriptor" code, because it is no
longer needed.

rtw_collect_txring():
g) In the "force" case, stop when we catch up to the hardware xmit
pointer.

rtw_intr_beacon():
h) Resetting tdb_next here looked fishy to me, in light of changes in
rtw_collect_txring(). XXX However, this is the one part I haven't
tested.

rtw_txring_fixup():
i) Add function and line arguments, so we can print out information
about the caller.
j) In addition to reading the hardware pointer, skip over any
additional packets with OWN set -- we may have queued more.

rtw_rxring_fixup():
k) Remove this, because it's completely wrong.

rtw_intr_ioerror():
l) Don't handle receive overruns here; handle them in the normal receive
path. Also changed RTW_INTR_RX and RTW_INTR_IOERROR accordingly.
m) Do not fiddle with CR; the transmit engine is still running just
fine.
n) Do not fiddle with IMR; it was unnecessary.
o) Don't touch the receive engine at all; not necessary now that we're
leaving CR alone.
p) Remove the rtw_do_chip_reset case; it was dangerous and not actually
used.

rtw_intr():
q) Don't mask off ISR bits when we pass down the ISR value; it's not
necessary, and sometimes the other bits useful in debugging output.

rtw_seg_too_short():
r) Don't spew here; the caller will do it if necessary. (Stops spewage
in an expected case.)

rtw_rxdesc_blk:
s) Minor change to make the elements have the same order as txdesc_blk.

general:
t) Added a bunch of debugging output, #ifdef RTW_DIAG, that was useful
while investigating the ring management problems. Also moved
rtw_txring_fixup() into RTW_DIAG, as I believe the transmit pointer
is always kept in sync now, and the function has potential race
conditions.
 1.82 06-Jan-2007  dyoung After we examine a rx/tx descriptor and find that it's still owned
by the NIC, re-sync the descriptor so that a cacheline will not
"cover" the NIC's modifications to the descriptor when we next
examine it.

This compiles, but I have not tested it, yet.
 1.81 16-Nov-2006  christos __unused removal on arguments; approved by core.
 1.80 13-Nov-2006  dyoung Stop using typeof() in the bit-twiddling macros, per yamt@'s
suggestion. This change requires that I use the __PRIuBITS format
string in atw and rtw, so do that.
 1.79 12-Oct-2006  xtraeme Use __unused in function arguments where appropiate.
 1.78 12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.77 24-Sep-2006  jmcneill Add "name" parameter to powerhook_establish, to aid debugging. No objections
on tech-kern@
 1.76 03-Sep-2006  christos branches: 1.76.2; 1.76.4;
- comment out impossible comparisons
- remove superfluous if statement
 1.75 31-Aug-2006  dyoung Per discussion on tech-kern and tech-userlevel, move the bit-twiddling
macros, __BIT, __BITS, SHIFTIN, SHIFTOUT, and __arraycount() from
lib/libkern/libkern.h to sys/cdefs.h. Add a __-prefix to SHIFTIN
and SHIFTOUT, and add a manual page for the bit-twiddling macros,
bits(3).

Make the __BIT and __BITS macros "widthless," as best I can, by
changing their type to uintmax_t from uint32_t. XXX The manual
page lags this change by a bit.

Define __PRIxBIT and __PRIxBITS printf(3) format strings.
 1.74 26-May-2006  blymn Clean up bogus whitespace
 1.73 14-May-2006  christos branches: 1.73.2;
XXX: GCC uninitialized
 1.72 28-Mar-2006  dyoung Revamp ieee80211_get_rate. Now it does not use the rateset in the
ic->ic_bss, but it uses the rateset in its new ieee80211_node
argument, instead. If the rate is fixed by ic->ic_fixed_rate, but
the fixed rate is not in the node's rateset, choose a reasonable
default: prefer the lowest basic rate or, if there is no basic
rate, prefer the lowest rate, period.

Change a printf complaint to a debug message.

Adapt drivers to suit new ieee80211_get_rate calling convention.

XXX I really need to replace ieee80211_get_rate with a bitrate
XXX adaptation algorithm. Soon, soon....
 1.71 27-Mar-2006  dyoung Set the channel frequency and flags in the radiotap headers in
rtw_tune instead of in rtw_start, rtw_intr_rx.
 1.70 27-Mar-2006  dyoung Remove unused argument ifflagsp from rtw_dmamap_load_txbuf.
 1.69 08-Mar-2006  dyoung branches: 1.69.2;
Change macro names to avoid collisions:

BIT -> __BIT
BITS -> __BITS
 1.68 08-Mar-2006  dyoung Move my bit-twiddling macros to libkern.h from my drivers, where
I had duplicated them. Improve the macros' names. Simplify their
implementation.

A brief description of each macro is below.

BIT(n): Return a bitmask with bit m set, where the least
significant bit is bit 0.

BITS(m, n): Return a bitmask with bits m through n, inclusive,
set. It does not matter whether m>n or m<=n.
The least significant bit is bit 0.

A "bitfield" is a span of consecutive bits defined by a
bitmask, where 1s select the bits in the bitfield. SHIFTIN,
SHIFTOUT, and SHIFTOUT_MASK help read and write bitfields
from device registers.

SHIFTIN(v, mask): Left-shift bits `v' into the bitfield
defined by `mask', and return them. No
side-effects.

SHIFTOUT(v, mask): Extract and return the bitfield selected
by `mask' from `v', right-shifting the
bits so that the rightmost selected bit
is at bit 0. No side-effects.

SHIFTOUT_MASK(mask): Right-shift the bits in `mask' so that
the rightmost non-zero bit is at bit
0. This is useful for finding the
greatest unsigned value that a bitfield
can hold. No side-effects. Note that
SHIFTOUT_MASK(m) = SHIFTOUT(m, m).

Examples:

/*
* Register definitions taken from the RFMD RF3000 manual.
*/
#define RF3000_GAINCTL 0x11 /* TX variable gain control */
#define RF3000_GAINCTL_TXVGC_MASK BITS(7, 2)
#define RF3000_GAINCTL_SCRAMBLER BIT(1)

/*
* Shift the transmit power into the transmit-power field of the
* gain-control register and write it to the baseband processor.
*/
atw_rf3000_write(sc, RF3000_GAINCTL,
SHIFTIN(txpower, RF3000_GAINCTL_TXVGC_MASK));


/*
* Register definitions taken from the ADMtek ADM8211 manual.
*
*/
#define ATW_RXSTAT_OWN BIT(31) /* 1: NIC may fill descriptor */
/* ... */
#define ATW_RXSTAT_DA1 BIT(17) /* DA bit 1, admin'd address */
#define ATW_RXSTAT_DA0 BIT(16) /* DA bit 0, group address */
#define ATW_RXSTAT_RXDR_MASK BITS(15,12) /* RX data rate */
#define ATW_RXSTAT_FL_MASK BITS(11,0) /* RX frame length, last
* descriptor only
*/

/* Extract the frame length from the Rx descriptor's
* status field.
*/
len = SHIFTOUT(rxstat, ATW_RXSTAT_FL_MASK);
 1.67 20-Feb-2006  thorpej branches: 1.67.2; 1.67.4;
Use device_is_active() rather than testing dv_flags for DVF_ACTIVE
directly.
 1.66 19-Feb-2006  dyoung When rtw_enable is called, power may have been removed and re-applied,
so invalidate the WEP key registers to force us to write the keys
back to the hardware.

Revamp key handling: use the hardware WEP engine for 40-bit and
104-bit keys, only; use software WEP for all other key lengths.
Set the hardware key length to the length of the default Tx key,
or if there is no default Tx key, use the length of the longest
WEP key.
 1.65 04-Feb-2006  dyoung In rtw_{rx,tx}ring_fixup, do not set the tx/rx ring index to
something out of bounds if we read an invalid pointer form the
hardware. Prevents a panic when an rtw@cardbus is ejected.
 1.64 29-Dec-2005  dyoung branches: 1.64.2; 1.64.4; 1.64.6;
Add support for the GCT Semiconductor GRF5101 transceiver/synthesizer.
From OpenBSD.

GCT will not provide any documentation, so there are many magic
numbers in this code.
 1.63 29-Dec-2005  dyoung Update rtw(4) for the new IBSS merge idiom, where ieee80211_ibss_merge()
does not return ENETRESET if the driver should change its BSSID,
but it makes a RUN->RUN transition, instead.
 1.62 29-Dec-2005  dyoung In atw(4), use ieee80211_compute_duration() to compute IEEE 802.11
Duration and PLCP Length fields, and delete the abominable
atw_frame_setdurs() subroutine.

Make rtw(4) use the new ieee80211_compute_duration() calling
convention.

Add an ieee80211_key argument to ieee80211_compute_duration() and
lightly constify arguments. Get the crypto header length from the
key argument instead of blithely assuming a WEP header. Add some
inline documentation. Account for data padding (IEEE80211_F_DATAPAD).
 1.61 24-Dec-2005  perry Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.60 13-Dec-2005  dyoung Fix comments and debug printfs: Tx FIFOs underflow, they don't
overflow.
 1.59 13-Dec-2005  dyoung On a transmit FIFO overflow (err, actually an underflow...) reset
both the transmit & receive sections of the MAC.
 1.58 23-Nov-2005  dyoung Miscellaneous Realtek RTL8180L driver improvements:

1 Added new sysctl controls for debugging.

2 Improve detection & support for hardware WEP.

3 Revamp handling of transmit descriptor rings.

4 Reliably IFF_OACTIVE when transmit descriptors are available, to
stop the transmit section of the driver from freezing up.

5 Fix beacon transmission in adhoc and hostap modes. XXX There is
a wart in hostap mode, where beacons are transmitted at 1/2 the
correct rate. Load beacon descriptors when the RTW_INTR_BINT
interrupt arrives; schedule RTW_INTR_BINT 1ms ahead of the target
beacon time.

6 Recover more gracefully from tx/rx errors: avoid
transmitter/receiver/chip resets. Try to re-synchronize software
state with hardware state---e.g., load next descriptor pointer
from hardware.

7 Activate the transmit watchdog timer for beacons as well as other
packets.

8 Introduce rtw_idle() that waits for transmit DMA to finish; call
it before resetting the transmitter.
 1.57 18-Nov-2005  skrll Adapt drivers to the new net80211(9).

Most of this is from dyoung@. Thanks!
 1.56 22-Sep-2005  gdt branches: 1.56.6;
Make arg of IFQ_SET_READY be &ifp->if_snd, to match all other drivers
and be compilable with altq enabled. Reviewed by dyoung@
 1.55 07-Sep-2005  dogcow With the assistance of dyoung, fix the following problems:
* some 8180L cards need a longer time for the srom to initialize; patch
suggested via OpenBSD.
* some cards give '0' for USA, some give '3'; for the meantime, accept both
as being USA locale cards.
* this is RTW, not ATW. :)
 1.54 06-Sep-2005  dogcow make rtw.c compile again after the 22-jun-05 net80211 import
 1.53 11-Jul-2005  dyoung Add undefined variable 'ic' to rtw_attach.
 1.52 06-Jul-2005  dyoung Historically, an(4), ath(4), atw(4), rtw(4), and wi(4) have printed
out their modes and rates at boot. Revert to the historical
behavior.
 1.51 06-Jul-2005  dyoung Avoid an unnecessary API difference between NetBSD and FreeBSD:
back out my change to ieee80211_crypto_encap that made it free its
mbuf argument on error. I had thought it was a bug. It was not.
It's the drivers that are broken. Make an(4), atw(4), ipw(4),
iwi(4), ral(4), rtw(4), ural(4), and wi(4) free the mbuf when
ieee80211_crypto_encap returns NULL. Also, return ath(4) to the
way it was---i.e., free the mbuf.

Thanks to Sam Leffler to pointing out my mistake.
 1.50 28-Jun-2005  dyoung branches: 1.50.2;
Here is a grotty hack that lets the RTL8180L handle WEP in the
receive direction, while software handles WEP in the transmit
direction. When net80211 calls rtw's rtw_key_set with a WEP key,
I point the key's wk_cipher at our "fake" cipher, rtw_cipher_wep,
which is alike to ieee80211_cipher_wep except it provides a different
crypto-decapsulation routine, rtw_wep_decap. rtw_wep_decap copies
the key passed to it by net80211, clears the key's SWCRYPT flag,
and then calls wep_decap. Now wep_decap will decapsulate, but it
will *not* re-decrypt.

XXX I need to check whether the hardware supports 40-bit WEP,
XXX 104-bit WEP, or both, and act accordingly.
 1.49 27-Jun-2005  dyoung rtw: Try to get hardware WEP to work. It seems to work in
the RX direction, but not in the TX direction. The
net80211 crypto framework doesn't seem to cope very well
with the assymetry (I'm probably missing something), so
I will use software WEP for now.

net80211: In ieee80211_compute_duration, figure out whether to add
the WEP header to the packet overhead by checking the
WEP bit in the Frame Control field of the 802.11 header,
instead of checking the IEEE80211_F_PRIVACY flag.

Also, if the WEP bit is present, assume that the frame
described by (wh, len) has already already been WEP
encapsulated, and adjust the payload length accordingly.
XXX that's a grotty hack that I will have to revisit,
later.
 1.48 22-Jun-2005  dyoung Resolve conflicts in importation of 18-May-2005 ath(4) / net80211(9)
from FreeBSD. Introduce compatibility shims (sys/dev/ic/ath_netbsd.[ch],
sys/net80211/ieee80211_netbsd.[ch]). Update drivers (an, atu, atw,
awi, ipw, iwi, rtw, wi) for the new net80211(9) API.
 1.47 20-Jun-2005  atatat Change the rest of the sysctl subsystem to use const consistently.
The __UNCONST macro is now used only where necessary and the RW macros
are gone. Most of the changes here are consumers of the
sysctl_createv(9) interface that now takes a pair of const pointers
which used not to be.
 1.46 10-Jun-2005  dyoung Sprinkle __UNCONST() and rename variables to quiet uiet -Wcast-qual,
-Wshadow complaints.
 1.45 02-Mar-2005  dyoung Misc. changes to improve ad hoc mode and to enable hostap mode:

Fix the work-around for the NIC bug where it skips to rx
descriptor 0. The driver used to skip to rx descriptor 1.
Hopefully this stops the out-of-order packet reception that
Charles Hannum saw.
When debugging is enabled, print rx-descriptor status flags
before printing the rx bit rate.

Add a debug message for when a beacon tx buffer reclamation.

Reset IFF_OACTIVE when we reset the transmitter.

Pass the consolidated LED state, a struct rtw_led_state,
to rtw_led_attach.

Choose the bit-rate for management frames (1Mb/s) at the
same place we choose for all other frames.

Do not use the NIC's short preamble or RTS options for
management frames. Label beacons for the NIC.

Following a Linux driver, take care not to zero arbitrary
bits in the TPPOLL register.

Use the new idiom for IBSS merges: disable transmitter,
kick the state machine.
Add a second descriptor to the beacon ring. The NIC seems
to like this much better.
 1.44 27-Feb-2005  perry nuke trailing whitespace
 1.43 31-Jan-2005  thorpej Eliminate use of M_HASFCS.
 1.42 16-Jan-2005  dyoung branches: 1.42.2; 1.42.4;
Move the register access mode into struct rtw_regs. Change
rtw_set_access, rtw_set_access1 to match.

Add a subroutine for setting WEP keys. WEP isn't quite finished,
because I have to add the WEP header to Tx packets. Implement the
SIOCS80211NWKEY ioctl for setting WEP keys.

Program the LEDs based on operating state and packet activity.

* On a Revision F RTL8180, blink LED1 at 1Hz to indicate
scan/authenticate/associate states. In the run state, turn LED1
on. In every state, blink LED1 at 5Hz to indicate non-beacon
tx/rx activity. I would like to use two LEDs, but in all my
Rev. F instances, LED0 is not wired to an LED; instead, the
first LED is wired to indicate that the card's power is on.

* On a Revision D RTL8180, program the LEDs so that LED0 indicates
Tx, and LED1 indicates Rx. The Rx LED will blink annoyingly if
there are beacons in the air, but at least the Tx LED is useful.

* Store the hardware revision in the softc to support my futile
attempt at programming LEDs for both Rev. D and Rev. F parts;
I never did get Rev. D LEDs to work right.

* Add a debug flag RTW_DEBUG_LED for the LED transitions.

Add RTW_TPPOLL_ALL, RTW_TPPOLL_SALL to start and stop, respectively,
all of the transmit rings.

In ad hoc mode, allocate a beacon and load it into the beacon ring.
Start the ring. In one trial, the card re-transmitted the beacon
ring's contents several times before stopping. More programming
and testing for ad hoc mode is necessary. I'm not setting the
beacon flag in the transmit descriptor.

Revamp the transmit section to make better use of all the transmit
rings: beacon queue, high-, low-, and medium-priority rings. Put
beacon frames on the beacon ring. All other management frames,
and data frames, go on the medium-priority ring. Power-save data
frames go on the high-priority ring. (Note that powersaving is
not implemented!) This is a work in progress.

Send all 802.11 Management frames at 1Mbps.

After we put a packet on a transmit ring, tickle the right bit in
the TPPOLL to tell RTL8180. Stop all rings on error and in rtw_stop.

Use the RF chip type, not the RTL8180 revision, to choose between
host- and MAC-controlled RF serial I/O. Now the Netgear MA521
works.

Remove bogus definition of bit RTW_TPPOLL_FSWINT.
 1.41 04-Jan-2005  dyoung Set initial conditions to guarantee that when read_seeprom toggles
Chip Select, it turns *on* rather than *off*.
 1.40 04-Jan-2005  dyoung Add the logic for IBSS merges.
 1.39 03-Jan-2005  dyoung sys/dev/ic/rtw.c:

Cosmetic: remove two short ladders from rtw_init. Fit the
NIC registers print-out onto one line using the RTW_PRINT_REGS
macro.

sys/dev/ic/rtwvar.h:

Add RTW_PRINT_REGS wrapper macro for rtw_print_regs. It
is a null op unless defined(RTW_DEBUG).
 1.38 03-Jan-2005  dyoung In sys/dev/ic/rtw.c:

Use clue from rtk(4) and re(4) to fix the rtw(4) packet
filter. Previously, I was using the wrong CRC32 function
to hash multicast addresses; to compensate, I set the
multicast filter to all 1s. Now that I hash the addresses
correctly, I do not any longer set the filter to all 1s.

In rtw_ioctl, avoid gratuitous re-initialization when the
interface flags change. If a !IFF_UP -> IFF_UP transition,
call rtw_init(); otherwise, only reload the packet filter.

In sys/dev/ic/rtwreg.h:

Put useful combinations of Receiver Control Register flags
in RTW_RCR_PKTFILT_MASK, RTW_RCR_MONITOR, and
RTW_RCR_PKTFILT_DEFAULT. (XXX RTW_RCR_MONITOR should be
called RTW_RCR_PKTFILT_MONITOR.)
 1.37 02-Jan-2005  dyoung Cosmetic: change u_int{8,16,32,64}_t to C99-style uint{8,16,32,64}_t,
which is preferred.
 1.36 29-Dec-2004  dyoung In rtw_detach, flag the rtw as "invalid" (RTW_F_INVALID). Do not
try to power-down the RF section of an invalid rtw.

The radiotap signal quality field is 16, not 8, bits wide. Convert
the byte order.
 1.35 29-Dec-2004  dyoung Remove some dead code.
 1.34 29-Dec-2004  dyoung I like the tlp/atw-style names for software descriptors, txsoft,
better than txctl. Change from rtw_txctl/rtw_rxctl to
rtw_txsoft/rtw_rxsoft. Change the descriptor blocks' names to
match: rtw_txctl_blk becomes rtw_txsoft_blk. Change the member-name
prefixes for both software and hardware descriptors.
 1.33 29-Dec-2004  dyoung Consolidate variables related to the rx ring in sc_rxdesc_blk,
which is a struct rtw_rxdesc_blk.

Put a copy of the DMA tag and the DMA map into the rx- and tx-ring
blocks so that I don't have to pass them to subroutines all of the
time.
 1.32 28-Dec-2004  dyoung Add bpf(4) packet taps to rtw(4). Now you can tap DLT_EN10MB
(Ethernet II), DLT_IEEE802_11 (802.11), and DLT_IEEE802_11_RADIO
(radiotap + 802.11).
 1.31 28-Dec-2004  dyoung If defined(RTW_DEBUG), provide a sysctl (hw.rtw.rxbufs_limit) for
limiting the number of rx buffers an rtw may allocate. Use this
sysctl to test the code that copes with buffer exhaustion.

Allocate at most RTW_RXQLEN rx buffers, stopping at the sysctl
limit. Record in sc_nrxdesc how many were allocated, and put the
end-of-ring indication on sc_rxdesc[sc_nrxdesc - 1]. In rtw_init,
if no rx buffers could be allocated, log a complaint, clear
IFF_RUNNING, and exit with an error.

Many changes to accomodate a short rx ring, mainly of the "add a
rx-ring length argument" variety. XXX I really should consolidate
all of the rx ring variables in one struct and pass that to the
rx-ring subroutines.

Bug fix: after calling MCLGET, use the (m->m_flags & M_EXT) idiom
to check for success, instead of m != NULL.

Bug fix: at the top of rtw_start, if IFF_RUNNING is not set, or
IFF_OACTIVE is, get out.
 1.30 27-Dec-2004  dyoung Use a table to convert the hardware's bit rates (0, 1, 2, 3) to
net80211 bit rates (2, 4, 11, 22).

Count input errors (if_ierrors++) for "DMA error/FIFO overflow"
and unknown bit rate.
 1.29 27-Dec-2004  dyoung Simplify the reset we do on a transmit timeout. Really, this could
be as simple as rtw_stop(, 0), rtw_init().
 1.28 27-Dec-2004  mycroft Use the last descriptor to count collisions and failed transmissions, too.
 1.27 27-Dec-2004  mycroft When checking if a split packet is completed, check the *last* segment, not
the first. Otherwise we can overwrite parts of the TX ring that we shouldn't.

Kluge the basic rate setting for now.

Minor simplification to the dequeueing logic.
 1.26 27-Dec-2004  dyoung Remove useless debug sysctls.

For AP scanning, change the channel dwell time from 1 second to
1/5 second.
 1.25 27-Dec-2004  mycroft Replace d_plcp_svc with d_residue. The latter is the number of whole
empty/unused octets to fill out the data time slot. The value is constrained
by math to 0 for <= 5.5Mb, 0-1 for 11Mb, and 0-2 for 22Mb. It is used to
signal to the MAC that there is residue.
 1.24 26-Dec-2004  dyoung Make rtw(4) build w/o RTW_DEBUG. Thanks to Charles Hannum for
pointing out my oversight.
 1.23 25-Dec-2004  dyoung The rx descriptor ring bug happens quite often, so printf'ing
occurrences is annoying. Only printf about it when rtw_debug
contains RTW_DEBUG_BUG.
 1.22 25-Dec-2004  dyoung IMPORTANT: set m->m_pkthdr.rcvif on rx'd packets. Illegal memory
references abound without this fix.

In rtw_intr_rx, skip to the next rx packet earlier if the rx packet
length is too short.

Also in rtw_intr_rx, if a packet is rx'd with unknown rate, printf
a warning, drop the packet, recycle the rx buffer, skip to next rx
packet.
 1.21 25-Dec-2004  dyoung Change rtw_debug from a debug level to a debug mask. Add a lot of
debug flags.

From Linux: handle an RTL8180 bug. Sometimes the NIC skips from
the middle of the ring to the 0th rx descriptor. Now the driver
resynchronizes.

Handle a receive descriptor underrun or Rx FIFO overflow condition
in the way that the Linux driver does. This kind of seems like
overkill, but whatever.

Protect rtw_ioctl with splnet().

Do not load a tx descriptor with a buffer shorter than 4 bytes.

Handle a transmit timeout less disruptively.
 1.20 23-Dec-2004  dyoung Oops, straggler from last commit: set the 802.11 Duration field
with the result from ieee80211_compute_duration.
 1.19 23-Dec-2004  dyoung Fix a bug in ieee80211_compute_duration: the 802.11 Duration field
in an 802.11 unicast data packet is equal to the duration of the
SIFS and Acknowledgement. That is, the amount of time reserved
*after* the packet has finished transmitting.

Change the arguments to ieee80211_compute_duration: pass the entire
packet length, not just the payload length. Add a 'debug' argument
to ieee80211_compute_duration and its helper subroutine,
ieee80211_compute_duration1.

If debug != 0, ieee80211_compute_duration printfs its arguments
and several local variables.

In rtw(4), load the 802.11 Duration field with the result from
ieee80211_compute_duration.
 1.18 23-Dec-2004  dyoung Bug fix: in rtw_rxbuf_alloc, unload the previous mbuf chain before
loading the new chain.
 1.17 23-Dec-2004  dyoung DMA-synchronize the Rx buffers before re-initializing them.
XXX not necessary?
 1.16 23-Dec-2004  dyoung Add more comprehensive debug messages as we setup transmit descriptors.
Also, dump packets if IFF_DEBUG|IFF_LINK2. Factor out a subroutine
for printing transmit-descriptor debug messages.
 1.15 23-Dec-2004  dyoung Disable interrupts and stop transmit DMA before disabling the
transmitter and receiver.
 1.14 23-Dec-2004  dyoung Shorten variables, s/txctl/ctl/. This is rtw_start, after all:
transmission is implied.
 1.13 23-Dec-2004  dyoung Do not indicate to the NIC that the host has appended the CRC32 to
Tx frames.
 1.12 23-Dec-2004  dyoung When we set up the supported rates table, mark 1Mb/s, 2Mb/s as
basic rates.
 1.11 23-Dec-2004  dyoung Extract the transmission status from a tx descriptor, and convert
to host byte-order, once.
 1.10 20-Dec-2004  dyoung Realtek sample sources are not consistent about the "Digital PHY"
bit in the SROM. It seems as if it is set to 1 when the PHY is
*analog*, not *digital*. Fix my sources.

In rtw_intr_rx, use units of 500kb/s instead of 100kb/s for rate,
to be consistent with net80211's expectations. Polish up some
debugging ugly messages. Dump raw 802.11 packets if IFF_DEBUG|IFF_LINK2
and RTW_DEBUG is defined.

Polish power-state (on/sleep/off) handling. Especially improve
support for RFMD (totally untested) and Maxim. For Philips, take
the Digital PHY property into account.

Call the net80211 watchdog function from rtw_watchdog, so that we
scan again if auth/assoc fails.

Be a little more cautious about writing register[RTW_TPPOLL], since
other drivers are.... Don't frob the high/low-priority queues
right now, since I don't use them.

Add rtw_join_bss which programs the card with the BSSID and other
properties of a BSS. Use it on state transitions. Factor out
rtw_set_nettype.

Make rtw_recv_beacon call ieee80211_recv_mgmt instead of dropping
beacons on the floor! TBD IBSS merges.

Change some rtw_debug=2 printfs to rtw_debug=3 (RTW_DPRINTF3)
printfs so the console doesn't get spammed so badly at rtw_debug=2.
Change some debugging printfs to RTW_DPRINTFs. E.g., print the
"RF programming method" only if debugging is enabled.
 1.9 20-Dec-2004  dyoung Fix bug in last commit: use &sc->sc_regs, regs is not defined.
 1.8 20-Dec-2004  dyoung Add some bus barriers. Remark where they are needed, e.g.,
read_eeprom.

Change some printfs to RTW_DPRINTF2s to quiet rtw(4) when debugging
is disabled.
 1.7 20-Dec-2004  dyoung Get rid of the silly char (*dvname)[IFNAMSIZ] pattern. Replace it
with const char *dvname. I'm not sure what I was thinking.
 1.6 20-Dec-2004  dyoung Assert that I'm DMA-syncing a non-negative number of transmit
descriptors.

As I free dirty transmit buffers, move them to the free list, not
back to the dirty list!

Add a 5-second transmit timeout.
 1.5 19-Dec-2004  dyoung Add the transmit section of rtw(4): build up and tear down transmit
descriptor rings, move packets from the transmit queues to the
transmit rings, handle transmission-completed interrupts. My
Linksys WPC11 ver. 4 with Maxim RF, generates interrupts like it
is successfully transmitting packets. Clearly there are bugs: my
G4 Powerbook locks up hard. I will debug tomorrow.
 1.4 13-Dec-2004  dyoung At last, I have rtw w/ Philips RF receiving packets.

I added some sysctls to aid debugging:

* hw.rtw.debug -- enable debugging

* hw.rtw.flush_rfio -- Linux voodoo: possibly makes the MAC
"flush" bits down the serial bus to the RF

* hw.rtw.host_rfio: force the host to bang bits to the RF, instead
of the MAC banging bits

* hw.rtw.rfio_delay: after telling the MAC to bang bits to the
RF front-end, delay rfio_delay microseconds.

* hw.rtw.rfprog_fallback: there is this notion of the "RF
programming method." I believe the choice influences the
polarity/timing of the serial bus used to program the RF
front-end. I know the correct choice for Intersil/RFMD/Philips
front-ends, only. For all other front-ends, I "fallback" to
rfprog_fallback.

Make rtw_txdac_enable take an rtw_softc argument. I will probably
revert this change.

Add some Linux voodoo to rtw_continuous_tx_enable. I will probably
revert this change.

Important: add rtw_set_rfprog, which sets the correct RF programming
method. This change and the following change are probably responsible
for making the Philips RF work.

Important: RTW_CONFIG1 is an 8-bit register, treat it that way!

Important: RTW_BRSR is 16-bit, RTW_CRCOUNT, RTW_PHYDELAY, and
RTW_MSR are 8-bit: treat them that way!

Vastly simplify rtw_resume_ticks.

Note to self: set the LED state to match the power state.

Hedge against the possibility that RTW_MSR is protected as
RTW_CONFIG[0123] are, meanwhile reworking that section of rtw_init
a little.

Add sc_anaparm, which isn't used, yet....
 1.3 12-Dec-2004  dyoung Miscellaneous changes. Details below. Important changes flagged
with []. Using the driver with my Linksys WPC11 ver. 4, it seems
to be receiving packets for a change. The WPC11 ver. 4 has a Maxim
RF section. My no-name rtw with Philips RF section still does not
receive any packets.

Keep access-level (analog params > config[0123] registers > none)
in sc_access. Add rtw_set_access for changing the access level.

Make rtw_continuous_tx_enable and other subroutines use rtw_set_access
instead of rtw_config0123_enable and rtw_anaparm_enable.

Factor part of the chip-reset code into rtw_chip_reset1.

Change the 'struct foo (*bar)[N]'-style arguments to
'struct foo *bar'-style arguments.

Consolidate software/hardware Tx/Rx ring setup in rtw_hwring_setup,
rtw_swring_setup.

Add a new constant, SA2400_OPMODE_DEFAULTS, for the bits that we
*always* set in the SA2400 OPMODE register.

Factor some code out into rtw_sa2400_calibrate. (Inspired by the
Linux driver.)

[] When the receiver goes into underrun/overflow state, call a new
subroutine, rtw_kick() that stops the Rx/Tx processes, resets
the chip, reinitializes the Tx/Rx rings, and restarts Rx/Tx
processes. (Inspired by the Linux driver.)

[] In rtw_intr_rx, check for too-short packets before calling
ieee80211_find_rxnode. I believe this will prevent a repeat of
the MCHK exception I saw once on macppc.

[] Use seconds-elapased as well as microseconds-elapsed to set the
next "due date" for the timeout interrupt. This keeps the driver
from programming the timeout to expire too early.

[] In rtw_intr, read RTW_ISR at most 10 times, then get out. If
the interface is not enabled (RTW_F_ENABLED), then get out.

[] In rtw_stop, get out if the interface is not enabled (RTW_F_ENABLED).
Block IPL_NET interrupts. Don't read/write any registers if
the interface is invalid (RTW_F_INVALID).

[] Call rtw_stop in rtw_detach.
 1.2 30-Oct-2004  thorpej When adding/deleting multicast addresses, only whack the address
filter if the interface is marked RUNNING.

Fixes kern/27678.
 1.1 26-Sep-2004  dyoung branches: 1.1.2;
Add work-in-progress driver rtw(4) for Realtek RTL8180 MAC/baseband.

Add register definitions for Maxim MAX2820 and Philips SA2400 radio
front-ends.
 1.1.2.9 11-Dec-2005  christos Sync with head.
 1.1.2.8 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.1.2.7 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.1.2.6 04-Feb-2005  skrll Sync with HEAD.
 1.1.2.5 17-Jan-2005  skrll Sync with HEAD.
 1.1.2.4 18-Dec-2004  skrll Sync with HEAD.
 1.1.2.3 02-Nov-2004  skrll Sync with HEAD.
 1.1.2.2 19-Oct-2004  skrll Sync with HEAD
 1.1.2.1 26-Sep-2004  skrll file rtw.c was added on branch ktrace-lwp on 2004-10-19 15:56:56 +0000
 1.42.4.2 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.42.4.1 12-Feb-2005  yamt sync with head.
 1.42.2.2 29-Apr-2005  kent sync with -current
 1.42.2.1 16-Jan-2005  kent file rtw.c was added on branch kent-audio2 on 2005-04-29 11:28:52 +0000
 1.50.2.8 17-Mar-2008  yamt sync with head.
 1.50.2.7 21-Jan-2008  yamt sync with head
 1.50.2.6 07-Dec-2007  yamt sync with head
 1.50.2.5 27-Oct-2007  yamt sync with head.
 1.50.2.4 03-Sep-2007  yamt sync with head.
 1.50.2.3 26-Feb-2007  yamt sync with head.
 1.50.2.2 30-Dec-2006  yamt sync with head.
 1.50.2.1 21-Jun-2006  yamt sync with head.
 1.56.6.2 29-Nov-2005  yamt sync with head.
 1.56.6.1 22-Nov-2005  yamt sync with head.
 1.64.6.2 01-Jun-2006  kardel Sync with head.
 1.64.6.1 22-Apr-2006  simonb Sync with head.
 1.64.4.1 09-Sep-2006  rpaulo sync with head
 1.64.2.2 01-Mar-2006  yamt sync with head.
 1.64.2.1 18-Feb-2006  yamt sync with head.
 1.67.4.1 19-Apr-2006  elad sync with head.
 1.67.2.5 03-Sep-2006  yamt sync with head.
 1.67.2.4 26-Jun-2006  yamt sync with head.
 1.67.2.3 24-May-2006  yamt sync with head.
 1.67.2.2 01-Apr-2006  yamt sync with head.
 1.67.2.1 13-Mar-2006  yamt sync with head.
 1.69.2.2 24-May-2006  tron Merge 2006-05-24 NetBSD-current into the "peter-altq" branch.
 1.69.2.1 28-Mar-2006  tron Merge 2006-03-28 NetBSD-current into the "peter-altq" branch.
 1.73.2.1 19-Jun-2006  chap Sync with head.
 1.76.4.2 10-Dec-2006  yamt sync with head.
 1.76.4.1 22-Oct-2006  yamt sync with head
 1.76.2.3 01-Feb-2007  ad Sync with head.
 1.76.2.2 12-Jan-2007  ad Sync with head.
 1.76.2.1 18-Nov-2006  ad Sync with head.
 1.84.2.1 12-Mar-2007  rmind Sync with HEAD.
 1.85.4.1 11-Jul-2007  mjf Sync with head.
 1.85.2.4 23-Oct-2007  ad Sync with head.
 1.85.2.3 09-Oct-2007  ad Sync with head.
 1.85.2.2 01-Jul-2007  ad Adapt to callout API change.
 1.85.2.1 09-Jun-2007  ad Sync with head.
 1.89.10.1 06-Oct-2007  yamt sync with head.
 1.89.8.3 23-Mar-2008  matt sync with HEAD
 1.89.8.2 09-Jan-2008  matt sync with HEAD
 1.89.8.1 06-Nov-2007  matt sync with HEAD
 1.89.6.3 21-Nov-2007  joerg Sync with HEAD.
 1.89.6.2 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.89.6.1 02-Oct-2007  joerg Sync with HEAD.
 1.90.2.2 18-Nov-2007  bouyer Sync with HEAD
 1.90.2.1 25-Oct-2007  bouyer Sync with HEAD.
 1.91.2.2 27-Dec-2007  mjf Sync with HEAD.
 1.91.2.1 19-Nov-2007  mjf Sync with HEAD.
 1.94.6.1 02-Jan-2008  bouyer Sync with HEAD
 1.94.2.1 26-Dec-2007  ad Sync with head.
 1.98.6.2 17-Jan-2009  mjf Sync with HEAD.
 1.98.6.1 03-Apr-2008  mjf Sync with HEAD.
 1.98.2.1 24-Mar-2008  keiichi sync with head.
 1.104.12.2 28-Apr-2009  skrll Sync with HEAD.
 1.104.12.1 19-Jan-2009  skrll Sync with HEAD.
 1.104.10.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.104.4.3 11-Aug-2010  yamt sync with head.
 1.104.4.2 11-Mar-2010  yamt sync with head
 1.104.4.1 04-May-2009  yamt sync with head.
 1.106.4.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.113.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.114.2.2 05-Mar-2011  rmind sync with head
 1.114.2.1 30-May-2010  rmind sync with head
 1.119.16.1 18-May-2014  rmind sync with head
 1.119.12.2 03-Dec-2017  jdolecek update from HEAD
 1.119.12.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.119.2.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.121.6.5 28-Aug-2017  skrll Sync with HEAD
 1.121.6.4 05-Feb-2017  skrll Sync with HEAD
 1.121.6.3 05-Oct-2016  skrll Sync with HEAD
 1.121.6.2 09-Jul-2016  skrll Sync with HEAD
 1.121.6.1 29-May-2016  skrll Sync with HEAD
 1.123.2.2 20-Mar-2017  pgoyette Sync with HEAD
 1.123.2.1 04-Nov-2016  pgoyette Sync with HEAD
 1.124.2.1 21-Apr-2017  bouyer Sync with HEAD
 1.126.2.1 10-Dec-2017  snj Pull up following revision(s) (requested by msaitoh in ticket #427):
sys/arch/amiga/dev/if_bah_zbus.c: 1.17
sys/arch/arm/broadcom/bcm53xx_eth.c: 1.30
sys/arch/powerpc/booke/dev/pq3etsec.c: 1.32
sys/arch/usermode/dev/if_veth.c: 1.9
sys/dev/ic/an.c: 1.66
sys/dev/ic/athn.c: 1.17
sys/dev/ic/atw.c: 1.162
sys/dev/ic/bwi.c: 1.33
sys/dev/ic/dwc_gmac.c: 1.41-1.42
sys/dev/ic/malo.c: 1.10
sys/dev/ic/rt2560.c: 1.31
sys/dev/ic/rt2661.c: 1.36
sys/dev/ic/rt2860.c: 1.29
sys/dev/ic/rtw.c: 1.127
sys/dev/ic/rtwvar.h: 1.46
sys/dev/ic/smc90cx6.c: 1.71
sys/dev/ic/smc90cx6var.h: 1.12
sys/dev/ic/wi.c: 1.244
sys/dev/pci/if_ipw.c: 1.66
sys/dev/pci/if_iwi.c: 1.104
sys/dev/pci/if_iwm.c: 1.76
sys/dev/pci/if_iwn.c: 1.86
sys/dev/pci/if_rtwn.c: 1.13
sys/dev/pci/if_wm.c: 1.541
sys/dev/pci/if_wpi.c: 1.79
sys/dev/pci/ixgbe/ixgbe.c: 1.106
sys/dev/pci/ixgbe/ixv.c: 1.73 via patch
sys/dev/pcmcia/if_malo_pcmcia.c: 1.15
sys/dev/scsipi/if_se.c: 1.95
sys/dev/usb/if_upl.c: 1.60
sys/net/if.c: 1.396
sys/net/if.h: 1.241
sys/net/if_arc.h: 1.23
sys/net/if_arcsubr.c: 1.78
sys/net/if_bridge.c: 1.136-1.137
sys/net/if_etherip.c: 1.39
sys/net/if_faith.c: 1.56
sys/net/if_gif.c: 1.131
sys/net/if_loop.c: 1.96
sys/net/if_mpls.c: 1.30
sys/net/if_pppoe.c: 1.129
sys/net/if_srt.c: 1.27
sys/net/if_stf.c: 1.102
sys/net/if_tap.c: 1.100
sys/net/if_vlan.c: 1.105
sys/netinet/ip_carp.c: 1.91
sys/rump/net/lib/libshmif/if_shmem.c: 1.73-1.74
sys/rump/net/lib/libvirtif/if_virt.c: 1.55-1.56
if_initalize() and if_attach() failed when resource allocation failed
(e.g. allocating softint). Without this change, it panics. It's bad because
resource shortage really occured when a lot of pseudo interface is created.
To avoid this problem, don't panic and change return value of if_initialize()
and if_attach() to int. Caller fanction will be recover from error cleanly by
checking the return value.
Return if bah_attach_subr() failed.
If if_attach() failed in the attach function, return.
- If if_initialize() failed in the attach function, free resources and return.
- Add some missing frees in bridge_clone_destroy().
- KNF
If error occured in bcmeth_ccb_attach(), free resources and return.
If error occured in pq3etsec_attach(), free resources and return.
If error occured in the attach function, free resources and return.
- If if_initialize() failed in athn_attach(), free resources and return.
- Add missing pmf_event_deregister() in athn_detach().
- Free resources correctly on some errors in atw_attach().
- Use apint*() insread of printf() in the attach function.
If if_initialize() failed in the attach function, return.
- If if_initialize() failed in the attach function, free resources and return.
- Add missing dwc_gmac_free_dma_rings() and mutex_destroy() when attach
failed.
- If if_initialize() failed in the attach function, free resources and return.
- ifp is always not NULL in iwi_detach(). Check correctly with ifp->if_softc.
- If if_initialize() failed in the attach function, free resources and return.
- Fix error path in the attach function correctly.
If if_initialize() failed in the attach function, free resources and return.
If if_attach() failed in the attach function, free resources and return.
- If if_initialize() failed in the attach function, free resources and return.
- KNF
- If if_attach() failed in the attach function, free resources and return.
- KNF
Fix compile error.
Fix compile error.
We don't need '&mii', but just 'mii' for mii_detach().
Don't free sc_rthash twice
 1.127.2.1 28-Jul-2018  pgoyette Sync with HEAD
 1.128.2.3 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.128.2.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.128.2.1 10-Jun-2019  christos Sync with HEAD
 1.134.2.1 29-Feb-2020  ad Sync with head.
 1.135.10.1 17-Jun-2021  thorpej Sync w/ HEAD.
 1.2 26-Sep-2022  martin Extent rtl8188eu_txagc[] (in a quite cryptic way duplicating all
zeroes?!) to avoid out of array accesses - there are RTL8192EU
variants with 2 TX chains.
 1.1 29-Jun-2018  thorpej branches: 1.1.2; 1.1.8;
- Unify the "rtwn" and "urtwn" register definitions and initialization
tables into common header files shared by both drivers.
- Fix some register and bit definitions, from OpenBSD and verified against
the vendor driver.
- Add some additional register / descriptor defnitions, from OpenBSD.
 1.1.8.2 10-Jun-2019  christos Sync with HEAD
 1.1.8.1 29-Jun-2018  christos file rtwn_data.h was added on branch phil-wifi on 2019-06-10 22:07:11 +0000
 1.1.2.2 28-Jul-2018  pgoyette Sync with HEAD
 1.1.2.1 29-Jun-2018  pgoyette file rtwn_data.h was added on branch pgoyette-compat on 2018-07-28 04:37:45 +0000
 1.3 16-Apr-2020  nat Correct rx packet count for 8192EU. Tested OK.
 1.2 25-Jul-2019  msaitoh branches: 1.2.8;
Avoid undefined behavior. Found by KUBSan.
 1.1 29-Jun-2018  thorpej branches: 1.1.2; 1.1.8;
- Unify the "rtwn" and "urtwn" register definitions and initialization
tables into common header files shared by both drivers.
- Fix some register and bit definitions, from OpenBSD and verified against
the vendor driver.
- Add some additional register / descriptor defnitions, from OpenBSD.
 1.1.8.4 16-Apr-2020  nat Update with 92EU changes from -current.
 1.1.8.3 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.1.8.2 10-Jun-2019  christos Sync with HEAD
 1.1.8.1 29-Jun-2018  christos file rtwnreg.h was added on branch phil-wifi on 2019-06-10 22:07:11 +0000
 1.1.2.2 28-Jul-2018  pgoyette Sync with HEAD
 1.1.2.1 29-Jun-2018  pgoyette file rtwnreg.h was added on branch pgoyette-compat on 2018-07-28 04:37:45 +0000
 1.2.8.1 20-Apr-2020  bouyer Sync with HEAD
 1.17 10-Nov-2019  chs in many device attach paths, allocate memory with M_WAITOK instead of M_NOWAIT
and remove code to handle failures that can no longer happen.
 1.16 15-Nov-2013  nisimura branches: 1.16.30;

fix unused variable warning
 1.15 19-Oct-2009  rmind branches: 1.15.12; 1.15.22; 1.15.26;
Drop 3rd and 4th clauses from David Young's license.
Reviewed and approved by dyoung@ (copyright holder).
 1.14 03-Mar-2008  tsutsui branches: 1.14.4;
Explicitly include <sys/device.h> for device_t.
 1.13 19-Oct-2007  ad branches: 1.13.12; 1.13.16;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.12 16-Nov-2006  christos branches: 1.12.8; 1.12.22; 1.12.24; 1.12.28;
__unused removal on arguments; approved by core.
 1.11 12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.10 31-Aug-2006  dyoung branches: 1.10.2; 1.10.4;
Per discussion on tech-kern and tech-userlevel, move the bit-twiddling
macros, __BIT, __BITS, SHIFTIN, SHIFTOUT, and __arraycount() from
lib/libkern/libkern.h to sys/cdefs.h. Add a __-prefix to SHIFTIN
and SHIFTOUT, and add a manual page for the bit-twiddling macros,
bits(3).

Make the __BIT and __BITS macros "widthless," as best I can, by
changing their type to uintmax_t from uint32_t. XXX The manual
page lags this change by a bit.

Define __PRIxBIT and __PRIxBITS printf(3) format strings.
 1.9 08-Mar-2006  dyoung Move my bit-twiddling macros to libkern.h from my drivers, where
I had duplicated them. Improve the macros' names. Simplify their
implementation.

A brief description of each macro is below.

BIT(n): Return a bitmask with bit m set, where the least
significant bit is bit 0.

BITS(m, n): Return a bitmask with bits m through n, inclusive,
set. It does not matter whether m>n or m<=n.
The least significant bit is bit 0.

A "bitfield" is a span of consecutive bits defined by a
bitmask, where 1s select the bits in the bitfield. SHIFTIN,
SHIFTOUT, and SHIFTOUT_MASK help read and write bitfields
from device registers.

SHIFTIN(v, mask): Left-shift bits `v' into the bitfield
defined by `mask', and return them. No
side-effects.

SHIFTOUT(v, mask): Extract and return the bitfield selected
by `mask' from `v', right-shifting the
bits so that the rightmost selected bit
is at bit 0. No side-effects.

SHIFTOUT_MASK(mask): Right-shift the bits in `mask' so that
the rightmost non-zero bit is at bit
0. This is useful for finding the
greatest unsigned value that a bitfield
can hold. No side-effects. Note that
SHIFTOUT_MASK(m) = SHIFTOUT(m, m).

Examples:

/*
* Register definitions taken from the RFMD RF3000 manual.
*/
#define RF3000_GAINCTL 0x11 /* TX variable gain control */
#define RF3000_GAINCTL_TXVGC_MASK BITS(7, 2)
#define RF3000_GAINCTL_SCRAMBLER BIT(1)

/*
* Shift the transmit power into the transmit-power field of the
* gain-control register and write it to the baseband processor.
*/
atw_rf3000_write(sc, RF3000_GAINCTL,
SHIFTIN(txpower, RF3000_GAINCTL_TXVGC_MASK));


/*
* Register definitions taken from the ADMtek ADM8211 manual.
*
*/
#define ATW_RXSTAT_OWN BIT(31) /* 1: NIC may fill descriptor */
/* ... */
#define ATW_RXSTAT_DA1 BIT(17) /* DA bit 1, admin'd address */
#define ATW_RXSTAT_DA0 BIT(16) /* DA bit 0, group address */
#define ATW_RXSTAT_RXDR_MASK BITS(15,12) /* RX data rate */
#define ATW_RXSTAT_FL_MASK BITS(11,0) /* RX frame length, last
* descriptor only
*/

/* Extract the frame length from the Rx descriptor's
* status field.
*/
len = SHIFTOUT(rxstat, ATW_RXSTAT_FL_MASK);
 1.8 29-Dec-2005  dyoung branches: 1.8.4; 1.8.6; 1.8.8; 1.8.10;
Add support for the GCT Semiconductor GRF5101 transceiver/synthesizer.
From OpenBSD.

GCT will not provide any documentation, so there are many magic
numbers in this code.
 1.7 11-Dec-2005  christos merge ktrace-lwp.
 1.6 22-Jun-2005  dyoung branches: 1.6.2;
Resolve conflicts in importation of 18-May-2005 ath(4) / net80211(9)
from FreeBSD. Introduce compatibility shims (sys/dev/ic/ath_netbsd.[ch],
sys/net80211/ieee80211_netbsd.[ch]). Update drivers (an, atu, atw,
awi, ipw, iwi, rtw, wi) for the new net80211(9) API.
 1.5 27-Feb-2005  perry nuke trailing whitespace
 1.4 02-Jan-2005  dyoung branches: 1.4.2; 1.4.4;
Cosmetic: change u_int{8,16,32,64}_t to C99-style uint{8,16,32,64}_t,
which is preferred.
 1.3 25-Dec-2004  dyoung Change rtw_debug from a debug level to a debug mask. Add a lot of
debug flags.

From Linux: handle an RTL8180 bug. Sometimes the NIC skips from
the middle of the ring to the 0th rx descriptor. Now the driver
resynchronizes.

Handle a receive descriptor underrun or Rx FIFO overflow condition
in the way that the Linux driver does. This kind of seems like
overkill, but whatever.

Protect rtw_ioctl with splnet().

Do not load a tx descriptor with a buffer shorter than 4 bytes.

Handle a transmit timeout less disruptively.
 1.2 12-Dec-2004  dyoung Miscellaneous changes. Details below. Important changes flagged
with []. Using the driver with my Linksys WPC11 ver. 4, it seems
to be receiving packets for a change. The WPC11 ver. 4 has a Maxim
RF section. My no-name rtw with Philips RF section still does not
receive any packets.

Keep access-level (analog params > config[0123] registers > none)
in sc_access. Add rtw_set_access for changing the access level.

Make rtw_continuous_tx_enable and other subroutines use rtw_set_access
instead of rtw_config0123_enable and rtw_anaparm_enable.

Factor part of the chip-reset code into rtw_chip_reset1.

Change the 'struct foo (*bar)[N]'-style arguments to
'struct foo *bar'-style arguments.

Consolidate software/hardware Tx/Rx ring setup in rtw_hwring_setup,
rtw_swring_setup.

Add a new constant, SA2400_OPMODE_DEFAULTS, for the bits that we
*always* set in the SA2400 OPMODE register.

Factor some code out into rtw_sa2400_calibrate. (Inspired by the
Linux driver.)

[] When the receiver goes into underrun/overflow state, call a new
subroutine, rtw_kick() that stops the Rx/Tx processes, resets
the chip, reinitializes the Tx/Rx rings, and restarts Rx/Tx
processes. (Inspired by the Linux driver.)

[] In rtw_intr_rx, check for too-short packets before calling
ieee80211_find_rxnode. I believe this will prevent a repeat of
the MCHK exception I saw once on macppc.

[] Use seconds-elapased as well as microseconds-elapsed to set the
next "due date" for the timeout interrupt. This keeps the driver
from programming the timeout to expire too early.

[] In rtw_intr, read RTW_ISR at most 10 times, then get out. If
the interface is not enabled (RTW_F_ENABLED), then get out.

[] In rtw_stop, get out if the interface is not enabled (RTW_F_ENABLED).
Block IPL_NET interrupts. Don't read/write any registers if
the interface is invalid (RTW_F_INVALID).

[] Call rtw_stop in rtw_detach.
 1.1 26-Sep-2004  dyoung branches: 1.1.2;
Add work-in-progress driver rtw(4) for Realtek RTL8180 MAC/baseband.

Add register definitions for Maxim MAX2820 and Philips SA2400 radio
front-ends.
 1.1.2.6 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.1.2.5 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.1.2.4 17-Jan-2005  skrll Sync with HEAD.
 1.1.2.3 18-Dec-2004  skrll Sync with HEAD.
 1.1.2.2 19-Oct-2004  skrll Sync with HEAD
 1.1.2.1 26-Sep-2004  skrll file rtwphy.c was added on branch ktrace-lwp on 2004-10-19 15:56:56 +0000
 1.4.4.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.4.2.1 29-Apr-2005  kent sync with -current
 1.6.2.4 17-Mar-2008  yamt sync with head.
 1.6.2.3 27-Oct-2007  yamt sync with head.
 1.6.2.2 30-Dec-2006  yamt sync with head.
 1.6.2.1 21-Jun-2006  yamt sync with head.
 1.8.10.1 19-Apr-2006  elad sync with head.
 1.8.8.2 03-Sep-2006  yamt sync with head.
 1.8.8.1 13-Mar-2006  yamt sync with head.
 1.8.6.1 22-Apr-2006  simonb Sync with head.
 1.8.4.1 09-Sep-2006  rpaulo sync with head
 1.10.4.2 10-Dec-2006  yamt sync with head.
 1.10.4.1 22-Oct-2006  yamt sync with head
 1.10.2.1 18-Nov-2006  ad Sync with head.
 1.12.28.1 25-Oct-2007  bouyer Sync with HEAD.
 1.12.24.2 23-Mar-2008  matt sync with HEAD
 1.12.24.1 06-Nov-2007  matt sync with HEAD
 1.12.22.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.12.8.1 23-Oct-2007  ad Sync with head.
 1.13.16.1 03-Apr-2008  mjf Sync with HEAD.
 1.13.12.1 24-Mar-2008  keiichi sync with head.
 1.14.4.1 11-Mar-2010  yamt sync with head
 1.15.26.1 18-May-2014  rmind sync with head
 1.15.22.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.15.12.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.16.30.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.6 19-Oct-2009  rmind Drop 3rd and 4th clauses from David Young's license.
Reviewed and approved by dyoung@ (copyright holder).
 1.5 29-Dec-2005  dyoung branches: 1.5.74;
Add support for the GCT Semiconductor GRF5101 transceiver/synthesizer.
From OpenBSD.

GCT will not provide any documentation, so there are many magic
numbers in this code.
 1.4 11-Dec-2005  christos merge ktrace-lwp.
 1.3 02-Jan-2005  dyoung branches: 1.3.10;
Cosmetic: change u_int{8,16,32,64}_t to C99-style uint{8,16,32,64}_t,
which is preferred.
 1.2 29-Dec-2004  dyoung Add my copyright.
 1.1 26-Sep-2004  dyoung branches: 1.1.2;
Add work-in-progress driver rtw(4) for Realtek RTL8180 MAC/baseband.

Add register definitions for Maxim MAX2820 and Philips SA2400 radio
front-ends.
 1.1.2.3 17-Jan-2005  skrll Sync with HEAD.
 1.1.2.2 19-Oct-2004  skrll Sync with HEAD
 1.1.2.1 26-Sep-2004  skrll file rtwphy.h was added on branch ktrace-lwp on 2004-10-19 15:56:56 +0000
 1.3.10.1 21-Jun-2006  yamt sync with head.
 1.5.74.1 11-Mar-2010  yamt sync with head
 1.19 09-Oct-2016  christos PR/51540: Henning Petersen: replace , with ;
 1.18 14-Sep-2013  joerg branches: 1.18.6; 1.18.10;
Put helper functions for debugging under the corresponding debug
options.
 1.17 19-Oct-2009  rmind branches: 1.17.12; 1.17.22; 1.17.26;
Drop 3rd and 4th clauses from David Young's license.
Reviewed and approved by dyoung@ (copyright holder).
 1.16 03-Mar-2008  tsutsui branches: 1.16.4;
Explicitly include <sys/device.h> for device_t.
 1.15 19-Oct-2007  ad branches: 1.15.12; 1.15.16;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.14 16-Nov-2006  christos branches: 1.14.8; 1.14.22; 1.14.24; 1.14.28;
__unused removal on arguments; approved by core.
 1.13 12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.12 31-Aug-2006  dyoung branches: 1.12.2; 1.12.4;
Per discussion on tech-kern and tech-userlevel, move the bit-twiddling
macros, __BIT, __BITS, SHIFTIN, SHIFTOUT, and __arraycount() from
lib/libkern/libkern.h to sys/cdefs.h. Add a __-prefix to SHIFTIN
and SHIFTOUT, and add a manual page for the bit-twiddling macros,
bits(3).

Make the __BIT and __BITS macros "widthless," as best I can, by
changing their type to uintmax_t from uint32_t. XXX The manual
page lags this change by a bit.

Define __PRIxBIT and __PRIxBITS printf(3) format strings.
 1.11 08-Mar-2006  dyoung Move my bit-twiddling macros to libkern.h from my drivers, where
I had duplicated them. Improve the macros' names. Simplify their
implementation.

A brief description of each macro is below.

BIT(n): Return a bitmask with bit m set, where the least
significant bit is bit 0.

BITS(m, n): Return a bitmask with bits m through n, inclusive,
set. It does not matter whether m>n or m<=n.
The least significant bit is bit 0.

A "bitfield" is a span of consecutive bits defined by a
bitmask, where 1s select the bits in the bitfield. SHIFTIN,
SHIFTOUT, and SHIFTOUT_MASK help read and write bitfields
from device registers.

SHIFTIN(v, mask): Left-shift bits `v' into the bitfield
defined by `mask', and return them. No
side-effects.

SHIFTOUT(v, mask): Extract and return the bitfield selected
by `mask' from `v', right-shifting the
bits so that the rightmost selected bit
is at bit 0. No side-effects.

SHIFTOUT_MASK(mask): Right-shift the bits in `mask' so that
the rightmost non-zero bit is at bit
0. This is useful for finding the
greatest unsigned value that a bitfield
can hold. No side-effects. Note that
SHIFTOUT_MASK(m) = SHIFTOUT(m, m).

Examples:

/*
* Register definitions taken from the RFMD RF3000 manual.
*/
#define RF3000_GAINCTL 0x11 /* TX variable gain control */
#define RF3000_GAINCTL_TXVGC_MASK BITS(7, 2)
#define RF3000_GAINCTL_SCRAMBLER BIT(1)

/*
* Shift the transmit power into the transmit-power field of the
* gain-control register and write it to the baseband processor.
*/
atw_rf3000_write(sc, RF3000_GAINCTL,
SHIFTIN(txpower, RF3000_GAINCTL_TXVGC_MASK));


/*
* Register definitions taken from the ADMtek ADM8211 manual.
*
*/
#define ATW_RXSTAT_OWN BIT(31) /* 1: NIC may fill descriptor */
/* ... */
#define ATW_RXSTAT_DA1 BIT(17) /* DA bit 1, admin'd address */
#define ATW_RXSTAT_DA0 BIT(16) /* DA bit 0, group address */
#define ATW_RXSTAT_RXDR_MASK BITS(15,12) /* RX data rate */
#define ATW_RXSTAT_FL_MASK BITS(11,0) /* RX frame length, last
* descriptor only
*/

/* Extract the frame length from the Rx descriptor's
* status field.
*/
len = SHIFTOUT(rxstat, ATW_RXSTAT_FL_MASK);
 1.10 29-Dec-2005  dyoung branches: 1.10.4; 1.10.6; 1.10.8; 1.10.10;
Add support for the GCT Semiconductor GRF5101 transceiver/synthesizer.
From OpenBSD.

GCT will not provide any documentation, so there are many magic
numbers in this code.
 1.9 24-Dec-2005  perry Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.8 11-Dec-2005  christos merge ktrace-lwp.
 1.7 22-Jun-2005  dyoung branches: 1.7.2;
Resolve conflicts in importation of 18-May-2005 ath(4) / net80211(9)
from FreeBSD. Introduce compatibility shims (sys/dev/ic/ath_netbsd.[ch],
sys/net80211/ieee80211_netbsd.[ch]). Update drivers (an, atu, atw,
awi, ipw, iwi, rtw, wi) for the new net80211(9) API.
 1.6 02-Jan-2005  dyoung Cosmetic: change u_int{8,16,32,64}_t to C99-style uint{8,16,32,64}_t,
which is preferred.
 1.5 27-Dec-2004  dyoung Remove useless debug sysctls.

For AP scanning, change the channel dwell time from 1 second to
1/5 second.
 1.4 25-Dec-2004  dyoung Change rtw_debug from a debug level to a debug mask. Add a lot of
debug flags.

From Linux: handle an RTL8180 bug. Sometimes the NIC skips from
the middle of the ring to the 0th rx descriptor. Now the driver
resynchronizes.

Handle a receive descriptor underrun or Rx FIFO overflow condition
in the way that the Linux driver does. This kind of seems like
overkill, but whatever.

Protect rtw_ioctl with splnet().

Do not load a tx descriptor with a buffer shorter than 4 bytes.

Handle a transmit timeout less disruptively.
 1.3 20-Dec-2004  dyoung Realtek sample sources are not consistent about the "Digital PHY"
bit in the SROM. It seems as if it is set to 1 when the PHY is
*analog*, not *digital*. Fix my sources.

In rtw_intr_rx, use units of 500kb/s instead of 100kb/s for rate,
to be consistent with net80211's expectations. Polish up some
debugging ugly messages. Dump raw 802.11 packets if IFF_DEBUG|IFF_LINK2
and RTW_DEBUG is defined.

Polish power-state (on/sleep/off) handling. Especially improve
support for RFMD (totally untested) and Maxim. For Philips, take
the Digital PHY property into account.

Call the net80211 watchdog function from rtw_watchdog, so that we
scan again if auth/assoc fails.

Be a little more cautious about writing register[RTW_TPPOLL], since
other drivers are.... Don't frob the high/low-priority queues
right now, since I don't use them.

Add rtw_join_bss which programs the card with the BSSID and other
properties of a BSS. Use it on state transitions. Factor out
rtw_set_nettype.

Make rtw_recv_beacon call ieee80211_recv_mgmt instead of dropping
beacons on the floor! TBD IBSS merges.

Change some rtw_debug=2 printfs to rtw_debug=3 (RTW_DPRINTF3)
printfs so the console doesn't get spammed so badly at rtw_debug=2.
Change some debugging printfs to RTW_DPRINTFs. E.g., print the
"RF programming method" only if debugging is enabled.
 1.2 13-Dec-2004  dyoung At last, I have rtw w/ Philips RF receiving packets.

I added some sysctls to aid debugging:

* hw.rtw.debug -- enable debugging

* hw.rtw.flush_rfio -- Linux voodoo: possibly makes the MAC
"flush" bits down the serial bus to the RF

* hw.rtw.host_rfio: force the host to bang bits to the RF, instead
of the MAC banging bits

* hw.rtw.rfio_delay: after telling the MAC to bang bits to the
RF front-end, delay rfio_delay microseconds.

* hw.rtw.rfprog_fallback: there is this notion of the "RF
programming method." I believe the choice influences the
polarity/timing of the serial bus used to program the RF
front-end. I know the correct choice for Intersil/RFMD/Philips
front-ends, only. For all other front-ends, I "fallback" to
rfprog_fallback.

Make rtw_txdac_enable take an rtw_softc argument. I will probably
revert this change.

Add some Linux voodoo to rtw_continuous_tx_enable. I will probably
revert this change.

Important: add rtw_set_rfprog, which sets the correct RF programming
method. This change and the following change are probably responsible
for making the Philips RF work.

Important: RTW_CONFIG1 is an 8-bit register, treat it that way!

Important: RTW_BRSR is 16-bit, RTW_CRCOUNT, RTW_PHYDELAY, and
RTW_MSR are 8-bit: treat them that way!

Vastly simplify rtw_resume_ticks.

Note to self: set the LED state to match the power state.

Hedge against the possibility that RTW_MSR is protected as
RTW_CONFIG[0123] are, meanwhile reworking that section of rtw_init
a little.

Add sc_anaparm, which isn't used, yet....
 1.1 26-Sep-2004  dyoung branches: 1.1.2;
Add work-in-progress driver rtw(4) for Realtek RTL8180 MAC/baseband.

Add register definitions for Maxim MAX2820 and Philips SA2400 radio
front-ends.
 1.1.2.5 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.1.2.4 17-Jan-2005  skrll Sync with HEAD.
 1.1.2.3 18-Dec-2004  skrll Sync with HEAD.
 1.1.2.2 19-Oct-2004  skrll Sync with HEAD
 1.1.2.1 26-Sep-2004  skrll file rtwphyio.c was added on branch ktrace-lwp on 2004-10-19 15:56:56 +0000
 1.7.2.4 17-Mar-2008  yamt sync with head.
 1.7.2.3 27-Oct-2007  yamt sync with head.
 1.7.2.2 30-Dec-2006  yamt sync with head.
 1.7.2.1 21-Jun-2006  yamt sync with head.
 1.10.10.1 19-Apr-2006  elad sync with head.
 1.10.8.2 03-Sep-2006  yamt sync with head.
 1.10.8.1 13-Mar-2006  yamt sync with head.
 1.10.6.1 22-Apr-2006  simonb Sync with head.
 1.10.4.1 09-Sep-2006  rpaulo sync with head
 1.12.4.2 10-Dec-2006  yamt sync with head.
 1.12.4.1 22-Oct-2006  yamt sync with head
 1.12.2.1 18-Nov-2006  ad Sync with head.
 1.14.28.1 25-Oct-2007  bouyer Sync with HEAD.
 1.14.24.2 23-Mar-2008  matt sync with HEAD
 1.14.24.1 06-Nov-2007  matt sync with HEAD
 1.14.22.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.14.8.1 23-Oct-2007  ad Sync with head.
 1.15.16.1 03-Apr-2008  mjf Sync with HEAD.
 1.15.12.1 24-Mar-2008  keiichi sync with head.
 1.16.4.1 11-Mar-2010  yamt sync with head
 1.17.26.1 18-May-2014  rmind sync with head
 1.17.22.2 03-Dec-2017  jdolecek update from HEAD
 1.17.22.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.17.12.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.18.10.1 04-Nov-2016  pgoyette Sync with HEAD
 1.18.6.1 05-Dec-2016  skrll Sync with HEAD
 1.4 19-Oct-2009  rmind Drop 3rd and 4th clauses from David Young's license.
Reviewed and approved by dyoung@ (copyright holder).
 1.3 11-Dec-2005  christos branches: 1.3.74;
merge ktrace-lwp.
 1.2 02-Jan-2005  dyoung Cosmetic: change u_int{8,16,32,64}_t to C99-style uint{8,16,32,64}_t,
which is preferred.
 1.1 26-Sep-2004  dyoung branches: 1.1.2;
Add work-in-progress driver rtw(4) for Realtek RTL8180 MAC/baseband.

Add register definitions for Maxim MAX2820 and Philips SA2400 radio
front-ends.
 1.1.2.3 17-Jan-2005  skrll Sync with HEAD.
 1.1.2.2 19-Oct-2004  skrll Sync with HEAD
 1.1.2.1 26-Sep-2004  skrll file rtwphyio.h was added on branch ktrace-lwp on 2004-10-19 15:56:56 +0000
 1.3.74.1 11-Mar-2010  yamt sync with head
 1.29 15-Sep-2016  jdolecek remove last isolated islands using BUS_SPACE_BARRIER_SYNC and
BUS_SPACE_BARRIER_X_BEFORE_X - these were only ever defined for mips and ia64,
and never actually implemented even there
 1.28 15-Mar-2010  dyoung branches: 1.28.18; 1.28.36; 1.28.40;
Make this compile on sparc64:

1 s/next_tick/next_tint/ because next_tick shadows a global on sparc64.

2 Fix the bus-barrier helper routines, which had the tag & handle
swapped (!!). Move the helpers from rtwreg.h to rtwvar.h, and
change RTW_BARRIER() into an inline subroutine called rtw_barrier().
 1.27 19-Oct-2009  rmind branches: 1.27.2; 1.27.4;
Drop 3rd and 4th clauses from David Young's license.
Reviewed and approved by dyoung@ (copyright holder).
 1.26 08-Sep-2008  gmcgarry Replace most gcc-specific __attribute__ uses with BSD-style sys/cdef.h
preprocessor macros.
 1.25 06-Jun-2008  dyoung branches: 1.25.4;
Fix typo in comment.
 1.24 16-Nov-2007  dyoung branches: 1.24.14; 1.24.16; 1.24.18; 1.24.20;
Accommodate the variety of RF front-ends when radiotapping frames:
tap only RSSI when there is a Philips RF front-end. Tap both Barker
lock quality and RSSI when there is any other RF front-end.

Provide radiotap listeners a more complete picture of channel
activity:

in promiscuous mode, tap frames who do not pass the CRC32 check.
Flag packets that were received with a short preamble. Ask
the NIC to pass us 802.11 Control frames. Pass frames to
radiotap listeners before stripping the FCS. Re-order operations
in rtw_intr_rx() in order to accomplish all of this, taking
care not to pass a broken packet to net80211!

Do not provide a flags field when tapping xmitted frames.

Assert sane Rx packet lengths. Really should check and drop instead
of KASSERTing. I will revisit this, soon.

Update copyright.
 1.23 06-Jan-2007  dyoung branches: 1.23.18; 1.23.20; 1.23.24; 1.23.26;
I have made a small change that suppresses "recovery" from (spurious?)
tx timeouts on the beacon queue. The driver's recovery process
badly disrupts the MAC's receiver. This needs a closer look, later.

Every other fix is by Charles M. Hannum. Charles writes:

"With these, the device is quite stable under load, does not experience
xmit timeouts, no longer mysteriously freezes, and does not spew
a lot of garbage. It does, however, continue to get some "tx fifo
underflow"s.

global, SYSCTL_SETUP():
a) Removed unused sysctl variables.

rtw_io_enable():
b) Change rtw_io_enable to take a softc, and make it call
rtw_txring_fixup().
c) Enable the PCI multiple read/write bit.
d) Always reset rdb_next to 0 when starting the receive engine.

rtw_intr_rx():
e) When processing receive packets, store the next pointer in rdb_next
and read it back on the next round, to fix a race condition vs.
rtw_tune() during AP discovery and association.
f) Remove the special "skip to 0th descriptor" code, because it is no
longer needed.

rtw_collect_txring():
g) In the "force" case, stop when we catch up to the hardware xmit
pointer.

rtw_intr_beacon():
h) Resetting tdb_next here looked fishy to me, in light of changes in
rtw_collect_txring(). XXX However, this is the one part I haven't
tested.

rtw_txring_fixup():
i) Add function and line arguments, so we can print out information
about the caller.
j) In addition to reading the hardware pointer, skip over any
additional packets with OWN set -- we may have queued more.

rtw_rxring_fixup():
k) Remove this, because it's completely wrong.

rtw_intr_ioerror():
l) Don't handle receive overruns here; handle them in the normal receive
path. Also changed RTW_INTR_RX and RTW_INTR_IOERROR accordingly.
m) Do not fiddle with CR; the transmit engine is still running just
fine.
n) Do not fiddle with IMR; it was unnecessary.
o) Don't touch the receive engine at all; not necessary now that we're
leaving CR alone.
p) Remove the rtw_do_chip_reset case; it was dangerous and not actually
used.

rtw_intr():
q) Don't mask off ISR bits when we pass down the ISR value; it's not
necessary, and sometimes the other bits useful in debugging output.

rtw_seg_too_short():
r) Don't spew here; the caller will do it if necessary. (Stops spewage
in an expected case.)

rtw_rxdesc_blk:
s) Minor change to make the elements have the same order as txdesc_blk.

general:
t) Added a bunch of debugging output, #ifdef RTW_DIAG, that was useful
while investigating the ring management problems. Also moved
rtw_txring_fixup() into RTW_DIAG, as I believe the transmit pointer
is always kept in sync now, and the function has potential race
conditions.
 1.22 06-Jan-2007  dyoung Add a hint to the compiler that rx/tx descriptors deserve 4-byte
alignment. Helps GCC produce better code on ARM.
 1.21 26-Nov-2006  dyoung Add 'volatile' to rx/tx descriptor fields.
 1.20 31-Aug-2006  dyoung branches: 1.20.2; 1.20.4;
Per discussion on tech-kern and tech-userlevel, move the bit-twiddling
macros, __BIT, __BITS, SHIFTIN, SHIFTOUT, and __arraycount() from
lib/libkern/libkern.h to sys/cdefs.h. Add a __-prefix to SHIFTIN
and SHIFTOUT, and add a manual page for the bit-twiddling macros,
bits(3).

Make the __BIT and __BITS macros "widthless," as best I can, by
changing their type to uintmax_t from uint32_t. XXX The manual
page lags this change by a bit.

Define __PRIxBIT and __PRIxBITS printf(3) format strings.
 1.19 10-Mar-2006  dyoung Fix typo: change an impossible bitfield (ends at bit 32) to a
possible one (ends at bit 31).
 1.18 08-Mar-2006  dyoung Change macro names to avoid collisions:

BIT -> __BIT
BITS -> __BITS
 1.17 08-Mar-2006  dyoung Move my bit-twiddling macros to libkern.h from my drivers, where
I had duplicated them. Improve the macros' names. Simplify their
implementation.

A brief description of each macro is below.

BIT(n): Return a bitmask with bit m set, where the least
significant bit is bit 0.

BITS(m, n): Return a bitmask with bits m through n, inclusive,
set. It does not matter whether m>n or m<=n.
The least significant bit is bit 0.

A "bitfield" is a span of consecutive bits defined by a
bitmask, where 1s select the bits in the bitfield. SHIFTIN,
SHIFTOUT, and SHIFTOUT_MASK help read and write bitfields
from device registers.

SHIFTIN(v, mask): Left-shift bits `v' into the bitfield
defined by `mask', and return them. No
side-effects.

SHIFTOUT(v, mask): Extract and return the bitfield selected
by `mask' from `v', right-shifting the
bits so that the rightmost selected bit
is at bit 0. No side-effects.

SHIFTOUT_MASK(mask): Right-shift the bits in `mask' so that
the rightmost non-zero bit is at bit
0. This is useful for finding the
greatest unsigned value that a bitfield
can hold. No side-effects. Note that
SHIFTOUT_MASK(m) = SHIFTOUT(m, m).

Examples:

/*
* Register definitions taken from the RFMD RF3000 manual.
*/
#define RF3000_GAINCTL 0x11 /* TX variable gain control */
#define RF3000_GAINCTL_TXVGC_MASK BITS(7, 2)
#define RF3000_GAINCTL_SCRAMBLER BIT(1)

/*
* Shift the transmit power into the transmit-power field of the
* gain-control register and write it to the baseband processor.
*/
atw_rf3000_write(sc, RF3000_GAINCTL,
SHIFTIN(txpower, RF3000_GAINCTL_TXVGC_MASK));


/*
* Register definitions taken from the ADMtek ADM8211 manual.
*
*/
#define ATW_RXSTAT_OWN BIT(31) /* 1: NIC may fill descriptor */
/* ... */
#define ATW_RXSTAT_DA1 BIT(17) /* DA bit 1, admin'd address */
#define ATW_RXSTAT_DA0 BIT(16) /* DA bit 0, group address */
#define ATW_RXSTAT_RXDR_MASK BITS(15,12) /* RX data rate */
#define ATW_RXSTAT_FL_MASK BITS(11,0) /* RX frame length, last
* descriptor only
*/

/* Extract the frame length from the Rx descriptor's
* status field.
*/
len = SHIFTOUT(rxstat, ATW_RXSTAT_FL_MASK);
 1.16 29-Dec-2005  dyoung branches: 1.16.4; 1.16.6; 1.16.8; 1.16.10;
Add support for the GCT Semiconductor GRF5101 transceiver/synthesizer.
From OpenBSD.

GCT will not provide any documentation, so there are many magic
numbers in this code.
 1.15 13-Dec-2005  dyoung Fix comments and debug printfs: Tx FIFOs underflow, they don't
overflow.
 1.14 23-Nov-2005  dyoung Miscellaneous Realtek RTL8180L driver improvements:

1 Added new sysctl controls for debugging.

2 Improve detection & support for hardware WEP.

3 Revamp handling of transmit descriptor rings.

4 Reliably IFF_OACTIVE when transmit descriptors are available, to
stop the transmit section of the driver from freezing up.

5 Fix beacon transmission in adhoc and hostap modes. XXX There is
a wart in hostap mode, where beacons are transmitted at 1/2 the
correct rate. Load beacon descriptors when the RTW_INTR_BINT
interrupt arrives; schedule RTW_INTR_BINT 1ms ahead of the target
beacon time.

6 Recover more gracefully from tx/rx errors: avoid
transmitter/receiver/chip resets. Try to re-synchronize software
state with hardware state---e.g., load next descriptor pointer
from hardware.

7 Activate the transmit watchdog timer for beacons as well as other
packets.

8 Introduce rtw_idle() that waits for transmit DMA to finish; call
it before resetting the transmitter.
 1.13 27-Feb-2005  perry branches: 1.13.4; 1.13.10;
nuke trailing whitespace
 1.12 16-Jan-2005  dyoung branches: 1.12.2; 1.12.4;
Move the register access mode into struct rtw_regs. Change
rtw_set_access, rtw_set_access1 to match.

Add a subroutine for setting WEP keys. WEP isn't quite finished,
because I have to add the WEP header to Tx packets. Implement the
SIOCS80211NWKEY ioctl for setting WEP keys.

Program the LEDs based on operating state and packet activity.

* On a Revision F RTL8180, blink LED1 at 1Hz to indicate
scan/authenticate/associate states. In the run state, turn LED1
on. In every state, blink LED1 at 5Hz to indicate non-beacon
tx/rx activity. I would like to use two LEDs, but in all my
Rev. F instances, LED0 is not wired to an LED; instead, the
first LED is wired to indicate that the card's power is on.

* On a Revision D RTL8180, program the LEDs so that LED0 indicates
Tx, and LED1 indicates Rx. The Rx LED will blink annoyingly if
there are beacons in the air, but at least the Tx LED is useful.

* Store the hardware revision in the softc to support my futile
attempt at programming LEDs for both Rev. D and Rev. F parts;
I never did get Rev. D LEDs to work right.

* Add a debug flag RTW_DEBUG_LED for the LED transitions.

Add RTW_TPPOLL_ALL, RTW_TPPOLL_SALL to start and stop, respectively,
all of the transmit rings.

In ad hoc mode, allocate a beacon and load it into the beacon ring.
Start the ring. In one trial, the card re-transmitted the beacon
ring's contents several times before stopping. More programming
and testing for ad hoc mode is necessary. I'm not setting the
beacon flag in the transmit descriptor.

Revamp the transmit section to make better use of all the transmit
rings: beacon queue, high-, low-, and medium-priority rings. Put
beacon frames on the beacon ring. All other management frames,
and data frames, go on the medium-priority ring. Power-save data
frames go on the high-priority ring. (Note that powersaving is
not implemented!) This is a work in progress.

Send all 802.11 Management frames at 1Mbps.

After we put a packet on a transmit ring, tickle the right bit in
the TPPOLL to tell RTL8180. Stop all rings on error and in rtw_stop.

Use the RF chip type, not the RTL8180 revision, to choose between
host- and MAC-controlled RF serial I/O. Now the Netgear MA521
works.

Remove bogus definition of bit RTW_TPPOLL_FSWINT.
 1.11 14-Jan-2005  dyoung Fix typos in TPPOLL register definition: stop the normal- &
low-priority queues with bit1 and bit0, not bit2 and bit2.
 1.10 03-Jan-2005  dyoung In sys/dev/ic/rtw.c:

Use clue from rtk(4) and re(4) to fix the rtw(4) packet
filter. Previously, I was using the wrong CRC32 function
to hash multicast addresses; to compensate, I set the
multicast filter to all 1s. Now that I hash the addresses
correctly, I do not any longer set the filter to all 1s.

In rtw_ioctl, avoid gratuitous re-initialization when the
interface flags change. If a !IFF_UP -> IFF_UP transition,
call rtw_init(); otherwise, only reload the packet filter.

In sys/dev/ic/rtwreg.h:

Put useful combinations of Receiver Control Register flags
in RTW_RCR_PKTFILT_MASK, RTW_RCR_MONITOR, and
RTW_RCR_PKTFILT_DEFAULT. (XXX RTW_RCR_MONITOR should be
called RTW_RCR_PKTFILT_MONITOR.)
 1.9 02-Jan-2005  dyoung Guess the meanings of most registers on the baseband processor.
Available documentation is incomplete, so the true meanings will
have to be found out by painstaking experimentation.
 1.8 02-Jan-2005  dyoung Cosmetic: change u_int{8,16,32,64}_t to C99-style uint{8,16,32,64}_t,
which is preferred.
 1.7 29-Dec-2004  dyoung Remove the cut & pasted copyright and apply my copyright.
 1.6 29-Dec-2004  dyoung I like the tlp/atw-style names for software descriptors, txsoft,
better than txctl. Change from rtw_txctl/rtw_rxctl to
rtw_txsoft/rtw_rxsoft. Change the descriptor blocks' names to
match: rtw_txctl_blk becomes rtw_txsoft_blk. Change the member-name
prefixes for both software and hardware descriptors.
 1.5 27-Dec-2004  mycroft Fix the BRSR macros.
 1.4 21-Dec-2004  dyoung The CRC bit in the Transmit Configuration Register seems to have
the meaning opposite to what I thought I read in the datasheet.
 1.3 20-Dec-2004  dyoung Realtek sample sources are not consistent about the "Digital PHY"
bit in the SROM. It seems as if it is set to 1 when the PHY is
*analog*, not *digital*. Fix my sources.

In rtw_intr_rx, use units of 500kb/s instead of 100kb/s for rate,
to be consistent with net80211's expectations. Polish up some
debugging ugly messages. Dump raw 802.11 packets if IFF_DEBUG|IFF_LINK2
and RTW_DEBUG is defined.

Polish power-state (on/sleep/off) handling. Especially improve
support for RFMD (totally untested) and Maxim. For Philips, take
the Digital PHY property into account.

Call the net80211 watchdog function from rtw_watchdog, so that we
scan again if auth/assoc fails.

Be a little more cautious about writing register[RTW_TPPOLL], since
other drivers are.... Don't frob the high/low-priority queues
right now, since I don't use them.

Add rtw_join_bss which programs the card with the BSSID and other
properties of a BSS. Use it on state transitions. Factor out
rtw_set_nettype.

Make rtw_recv_beacon call ieee80211_recv_mgmt instead of dropping
beacons on the floor! TBD IBSS merges.

Change some rtw_debug=2 printfs to rtw_debug=3 (RTW_DPRINTF3)
printfs so the console doesn't get spammed so badly at rtw_debug=2.
Change some debugging printfs to RTW_DPRINTFs. E.g., print the
"RF programming method" only if debugging is enabled.
 1.2 19-Dec-2004  dyoung Add the transmit section of rtw(4): build up and tear down transmit
descriptor rings, move packets from the transmit queues to the
transmit rings, handle transmission-completed interrupts. My
Linksys WPC11 ver. 4 with Maxim RF, generates interrupts like it
is successfully transmitting packets. Clearly there are bugs: my
G4 Powerbook locks up hard. I will debug tomorrow.
 1.1 26-Sep-2004  dyoung branches: 1.1.2;
Add work-in-progress driver rtw(4) for Realtek RTL8180 MAC/baseband.

Add register definitions for Maxim MAX2820 and Philips SA2400 radio
front-ends.
 1.1.2.5 11-Dec-2005  christos Sync with head.
 1.1.2.4 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.1.2.3 17-Jan-2005  skrll Sync with HEAD.
 1.1.2.2 19-Oct-2004  skrll Sync with HEAD
 1.1.2.1 26-Sep-2004  skrll file rtwreg.h was added on branch ktrace-lwp on 2004-10-19 15:56:56 +0000
 1.12.4.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.12.2.2 29-Apr-2005  kent sync with -current
 1.12.2.1 16-Jan-2005  kent file rtwreg.h was added on branch kent-audio2 on 2005-04-29 11:28:52 +0000
 1.13.10.1 29-Nov-2005  yamt sync with head.
 1.13.4.4 07-Dec-2007  yamt sync with head
 1.13.4.3 26-Feb-2007  yamt sync with head.
 1.13.4.2 30-Dec-2006  yamt sync with head.
 1.13.4.1 21-Jun-2006  yamt sync with head.
 1.16.10.1 19-Apr-2006  elad sync with head.
 1.16.8.2 03-Sep-2006  yamt sync with head.
 1.16.8.1 13-Mar-2006  yamt sync with head.
 1.16.6.1 22-Apr-2006  simonb Sync with head.
 1.16.4.1 09-Sep-2006  rpaulo sync with head
 1.20.4.1 10-Dec-2006  yamt sync with head.
 1.20.2.1 12-Jan-2007  ad Sync with head.
 1.23.26.1 19-Nov-2007  mjf Sync with HEAD.
 1.23.24.1 18-Nov-2007  bouyer Sync with HEAD
 1.23.20.1 09-Jan-2008  matt sync with HEAD
 1.23.18.1 21-Nov-2007  joerg Sync with HEAD.
 1.24.20.2 24-Sep-2008  wrstuden Merge in changes between wrstuden-revivesa-base-2 and
wrstuden-revivesa-base-3.
 1.24.20.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.24.18.3 11-Aug-2010  yamt sync with head.
 1.24.18.2 11-Mar-2010  yamt sync with head
 1.24.18.1 04-May-2009  yamt sync with head.
 1.24.16.1 17-Jun-2008  yamt sync with head.
 1.24.14.2 28-Sep-2008  mjf Sync with HEAD.
 1.24.14.1 29-Jun-2008  mjf Sync with HEAD.
 1.25.4.1 19-Oct-2008  haad Sync with HEAD.
 1.27.4.1 30-May-2010  rmind sync with head
 1.27.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.28.40.1 04-Nov-2016  pgoyette Sync with HEAD
 1.28.36.1 05-Oct-2016  skrll Sync with HEAD
 1.28.18.1 03-Dec-2017  jdolecek update from HEAD
 1.48 05-Oct-2019  mrg remove __packed attribute from struct ieee80211_radiotap_header
and all the structures that include it.

this should not change anything while avoiding packed vs alignment
warnings from GCC 8, and potentially pessimised code generation
due to the packed marker (there are no misaligned members, just
that the per-device parts may end unaligned.)

all consumers of these members are done from the properly aligned
packet members directly, or, as a union with a 64 byte member,
also properly aligned. codegen didn't appear to change, except
for the definition of sizeof(struct driver_[rt]x_radiotap_header)
in debug info, which is not directly used anywhere.
 1.47 19-Apr-2018  christos branches: 1.47.2;
s/static inline/static __inline/g for consistency.
 1.46 23-Oct-2017  msaitoh branches: 1.46.2;
If if_initialize() failed in the attach function, free resources and return.
 1.45 02-Feb-2017  nonaka branches: 1.45.6;
wlan interfaces make interrupt routine running on softint context.

see http://mail-index.netbsd.org/tech-kern/2016/12/06/msg021281.html

tested device:
* ath at pci: AR5212, AR5424
* athn at pci: AR9287
* ipw at pci: 2100BG
* iwi at pci: 2915ABG
* iwm at pci: 3165, 7260, 8260
* iwn at pci: 4945, 6235
* ral at pci: RT2560
* rtwn at pci: RTL8192CE
 1.44 15-Sep-2016  jdolecek branches: 1.44.2;
remove last isolated islands using BUS_SPACE_BARRIER_SYNC and
BUS_SPACE_BARRIER_X_BEFORE_X - these were only ever defined for mips and ia64,
and never actually implemented even there
 1.43 15-Mar-2010  dyoung branches: 1.43.18; 1.43.36; 1.43.40;
Make this compile on sparc64:

1 s/next_tick/next_tint/ because next_tick shadows a global on sparc64.

2 Fix the bus-barrier helper routines, which had the tag & handle
swapped (!!). Move the helpers from rtwreg.h to rtwvar.h, and
change RTW_BARRIER() into an inline subroutine called rtw_barrier().
 1.42 24-Feb-2010  dyoung branches: 1.42.2;
A pointer typedef entails trading too much flexibility to declare const
and non-const types, and the kernel uses both const and non-const
PMF qualifiers and device suspensors, so change the pmf_qual_t and
device_suspensor_t typedefs from "pointers to const" to non-pointer,
non-const types.
 1.41 17-Jan-2010  pooka branches: 1.41.2;
Forward declare struct bpf_if and use that as the type for bpf_if
instead of "void *". Buys us oo times the type-safety for 0 times
the price.
(no functional change)
 1.40 08-Jan-2010  dyoung Expand PMF_FN_* macros.
 1.39 19-Oct-2009  rmind Drop 3rd and 4th clauses from David Young's license.
Reviewed and approved by dyoung@ (copyright holder).
 1.38 16-Sep-2009  dyoung In pmf(9), improve the implementation of device self-suspension
and make suspension by self, by drvctl(8), and by ACPI system sleep
play nice together. Start solidifying some temporary API changes.

1. Extract a new header file, <sys/device_if.h>, from <sys/device.h> and
#include it from <sys/pmf.h> instead of <sys/device.h> to break the
circular dependency between <sys/device.h> and <sys/pmf.h>.

2. Introduce pmf_qual_t, an aggregate of qualifications on a PMF
suspend/resume call. Start to replace instances of PMF_FN_PROTO,
PMF_FN_ARGS, et cetera, with a pmf_qual_t.

3. Introduce the notion of a "suspensor," an entity that holds a
device in suspension. More than one suspensor may hold a device
at once. A device stays suspended as long as at least one
suspensor holds it. A device resumes when the last suspensor
releases it.

Currently, the kernel defines three suspensors,

3a the system-suspensor: for system suspension, initiated
by 'sysctl -w machdep.sleep_state=3', by lid closure, by
power-button press, et cetera,

3b the drvctl-suspensor: for device suspension by /dev/drvctl
ioctl, e.g., drvctl -S sip0.

3c the system self-suspensor: for device drivers that suspend
themselves and their children. Several drivers for network
interfaces put the network device to sleep while it is not
administratively up, that is, after the kernel calls if_stop(,
1). The self-suspensor should not be used directly. See
the description of suspensor delegates, below.

A suspensor can have one or more "delegates". A suspensor can
release devices that its delegates hold suspended. Right now,
only the system self-suspensor has delegates. For each device
that a self-suspending driver attaches, it creates the device's
self-suspensor, a delegate of the system self-suspensor.

Suspensors stop a system-wide suspend/resume cycle from waking
devices that the operator put to sleep with drvctl before the cycle.
They also help self-suspension to work more simply, safely, and in
accord with expectations.

4. Add the notion of device activation level, devact_level_t,
and a routine for checking the current activation level,
device_activation(). Current activation levels are DEVACT_LEVEL_BUS,
DEVACT_LEVEL_DRIVER, and DEVACT_LEVEL_CLASS, which respectively
indicate that the device's bus is active, that the bus and device are
active, and that the bus, device, and the functions of the device's
class (network, audio) are active.

Suspend/resume calls can be qualified with a devact_level_t.
The power-management framework treats a devact_level_t that
qualifies a device suspension as the device's current activation
level; it only runs hooks to reduce the activation level from
the presumed current level to the fully suspended state. The
framework treats a devact_level_t qualifying device resumption
as the target activation level; it only runs hooks to raise the
activation level to the target.

5. Use pmf_qual_t, devact_level_t, and self-suspensors in several
drivers.

6. Temporarily add an unused power-management workqueue that I will
remove or replace, soon.
 1.37 12-Mar-2008  dyoung branches: 1.37.4;
Use device_t and its accessors throughout. Use aprint_*_dev().

Improve PMF-ability.

Add a 'flags' argument to suspend/resume handlers and
callers such as pmf_system_suspend().

Define a flag, PMF_F_SELF, which indicates to PMF that a
device is suspending/resuming itself. Add helper routines,
pmf_device_suspend_self(dev) and pmf_device_resume_self(dev),
that call pmf_device_suspend(dev, PMF_F_SELF) and
pmf_device_resume(dev, PMF_F_SELF), respectively. Use
PMF_F_SELF to suspend/resume self in ath(4), audio(4),
rtw(4), and sip(4).

In ath(4) and in rtw(4), replace the icky sc_enable/sc_disable
callbacks, provided by the bus front-end, with
self-suspension/resumption. Also, clean up the bus
front-ends. Make sure that the interrupt handler is
disestablished during suspension. Get rid of driver-private
flags (e.g., RTW_F_ENABLED, ath_softc->sc_invalid); use
device_is_active()/device_has_power() calls, instead.

In the network-class suspend handler, call if_stop(, 0)
instead of if_stop(, 1), because the latter is superfluous
(bus- and driver-suspension hooks will 'disable' the NIC),
and it may cause recursion.

In the network-class resume handler, prevent infinite
recursion through if_init() by getting out early if we are
self-suspending (PMF_F_SELF).

rtw(4) improvements:

Destroy rtw(4) callouts when we detach it. Make rtw at
pci detachable. Print some more information with the "rx
frame too long" warning.

Remove activate() methods:

Get rid of rtw_activate() and ath_activate(). The device
activate() methods are not good for much these days.

Make ath at cardbus resume with crypto functions intact:

Introduce a boolean device property, "pmf-powerdown". If
pmf-powerdown is present and false, it indicates that a
bus back-end should not remove power from a device.

Honor this property in cardbus_child_suspend().

Set this property to 'false' in ath_attach(), since removing
power from an ath at cardbus seems to lobotomize the WPA
crypto engine. XXX Should the pmf-powerdown property
propagate toward the root of the device tree?

Miscellaneous ath(4) changes:

Warn if ath(4) tries to write crypto keys to suspended
hardware.

Reduce differences between FreeBSD and NetBSD in ath(4)
multicast filter setup.

Make ath_printrxbuf() print an rx descriptor's status &
key index, to help debug crypto errors.

Shorten a staircase in ath_ioctl(). Don't check for
ieee80211_ioctl() return code ERESTART, it never happens.
 1.36 25-Dec-2007  perry branches: 1.36.2; 1.36.6;
Convert many of the uses of __attribute__ to equivalent
__packed, __unused and __dead macros from cdefs.h
 1.35 21-Dec-2007  dyoung Do not embed a struct device in rtw_softc any longer. Register
both pci and cardbus attachments with CFATTACH_DECL_NEW(). Access
the softc through the device_t using device_private().

While I'm here, change a couple of KASSERT()s about the Rx buffer
length to a warning.
 1.34 20-Dec-2007  dyoung Remove shutdown hooks. Use KASSERT().
 1.33 16-Dec-2007  dyoung Synchronize device detachment with network interrupts. Use the
pmf network class instead of powerhooks.
 1.32 16-Nov-2007  dyoung branches: 1.32.2; 1.32.6;
Accommodate the variety of RF front-ends when radiotapping frames:
tap only RSSI when there is a Philips RF front-end. Tap both Barker
lock quality and RSSI when there is any other RF front-end.

Provide radiotap listeners a more complete picture of channel
activity:

in promiscuous mode, tap frames who do not pass the CRC32 check.
Flag packets that were received with a short preamble. Ask
the NIC to pass us 802.11 Control frames. Pass frames to
radiotap listeners before stripping the FCS. Re-order operations
in rtw_intr_rx() in order to accomplish all of this, taking
care not to pass a broken packet to net80211!

Do not provide a flags field when tapping xmitted frames.

Assert sane Rx packet lengths. Really should check and drop instead
of KASSERTing. I will revisit this, soon.

Update copyright.
 1.31 04-Mar-2007  christos branches: 1.31.14; 1.31.16; 1.31.20; 1.31.22;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.30 06-Jan-2007  dyoung branches: 1.30.2;
I have made a small change that suppresses "recovery" from (spurious?)
tx timeouts on the beacon queue. The driver's recovery process
badly disrupts the MAC's receiver. This needs a closer look, later.

Every other fix is by Charles M. Hannum. Charles writes:

"With these, the device is quite stable under load, does not experience
xmit timeouts, no longer mysteriously freezes, and does not spew
a lot of garbage. It does, however, continue to get some "tx fifo
underflow"s.

global, SYSCTL_SETUP():
a) Removed unused sysctl variables.

rtw_io_enable():
b) Change rtw_io_enable to take a softc, and make it call
rtw_txring_fixup().
c) Enable the PCI multiple read/write bit.
d) Always reset rdb_next to 0 when starting the receive engine.

rtw_intr_rx():
e) When processing receive packets, store the next pointer in rdb_next
and read it back on the next round, to fix a race condition vs.
rtw_tune() during AP discovery and association.
f) Remove the special "skip to 0th descriptor" code, because it is no
longer needed.

rtw_collect_txring():
g) In the "force" case, stop when we catch up to the hardware xmit
pointer.

rtw_intr_beacon():
h) Resetting tdb_next here looked fishy to me, in light of changes in
rtw_collect_txring(). XXX However, this is the one part I haven't
tested.

rtw_txring_fixup():
i) Add function and line arguments, so we can print out information
about the caller.
j) In addition to reading the hardware pointer, skip over any
additional packets with OWN set -- we may have queued more.

rtw_rxring_fixup():
k) Remove this, because it's completely wrong.

rtw_intr_ioerror():
l) Don't handle receive overruns here; handle them in the normal receive
path. Also changed RTW_INTR_RX and RTW_INTR_IOERROR accordingly.
m) Do not fiddle with CR; the transmit engine is still running just
fine.
n) Do not fiddle with IMR; it was unnecessary.
o) Don't touch the receive engine at all; not necessary now that we're
leaving CR alone.
p) Remove the rtw_do_chip_reset case; it was dangerous and not actually
used.

rtw_intr():
q) Don't mask off ISR bits when we pass down the ISR value; it's not
necessary, and sometimes the other bits useful in debugging output.

rtw_seg_too_short():
r) Don't spew here; the caller will do it if necessary. (Stops spewage
in an expected case.)

rtw_rxdesc_blk:
s) Minor change to make the elements have the same order as txdesc_blk.

general:
t) Added a bunch of debugging output, #ifdef RTW_DIAG, that was useful
while investigating the ring management problems. Also moved
rtw_txring_fixup() into RTW_DIAG, as I believe the transmit pointer
is always kept in sync now, and the function has potential race
conditions.
 1.29 14-May-2006  dyoung branches: 1.29.8;
Make rtwvar.h, rtw.c agree whether rtw_host_rfio and rtw_debug are
static or extern. Problem noted by Tom Spindler.
 1.28 16-Feb-2006  perry branches: 1.28.2; 1.28.6;
Change "inline" back to "__inline" in .h files -- C99 is still too
new, and some apps compile things in C89 mode. C89 keywords stay.

As per core@.
 1.27 29-Dec-2005  dyoung branches: 1.27.2; 1.27.4; 1.27.6;
Add support for the GCT Semiconductor GRF5101 transceiver/synthesizer.
From OpenBSD.

GCT will not provide any documentation, so there are many magic
numbers in this code.
 1.26 24-Dec-2005  perry Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.25 23-Nov-2005  dyoung Miscellaneous Realtek RTL8180L driver improvements:

1 Added new sysctl controls for debugging.

2 Improve detection & support for hardware WEP.

3 Revamp handling of transmit descriptor rings.

4 Reliably IFF_OACTIVE when transmit descriptors are available, to
stop the transmit section of the driver from freezing up.

5 Fix beacon transmission in adhoc and hostap modes. XXX There is
a wart in hostap mode, where beacons are transmitted at 1/2 the
correct rate. Load beacon descriptors when the RTW_INTR_BINT
interrupt arrives; schedule RTW_INTR_BINT 1ms ahead of the target
beacon time.

6 Recover more gracefully from tx/rx errors: avoid
transmitter/receiver/chip resets. Try to re-synchronize software
state with hardware state---e.g., load next descriptor pointer
from hardware.

7 Activate the transmit watchdog timer for beacons as well as other
packets.

8 Introduce rtw_idle() that waits for transmit DMA to finish; call
it before resetting the transmitter.
 1.24 27-Jun-2005  dyoung branches: 1.24.2; 1.24.8;
rtw: Try to get hardware WEP to work. It seems to work in
the RX direction, but not in the TX direction. The
net80211 crypto framework doesn't seem to cope very well
with the assymetry (I'm probably missing something), so
I will use software WEP for now.

net80211: In ieee80211_compute_duration, figure out whether to add
the WEP header to the packet overhead by checking the
WEP bit in the Frame Control field of the 802.11 header,
instead of checking the IEEE80211_F_PRIVACY flag.

Also, if the WEP bit is present, assume that the frame
described by (wh, len) has already already been WEP
encapsulated, and adjust the payload length accordingly.
XXX that's a grotty hack that I will have to revisit,
later.
 1.23 22-Jun-2005  dyoung Resolve conflicts in importation of 18-May-2005 ath(4) / net80211(9)
from FreeBSD. Introduce compatibility shims (sys/dev/ic/ath_netbsd.[ch],
sys/net80211/ieee80211_netbsd.[ch]). Update drivers (an, atu, atw,
awi, ipw, iwi, rtw, wi) for the new net80211(9) API.
 1.22 02-Mar-2005  dyoung Misc. changes to improve ad hoc mode and to enable hostap mode:

Fix the work-around for the NIC bug where it skips to rx
descriptor 0. The driver used to skip to rx descriptor 1.
Hopefully this stops the out-of-order packet reception that
Charles Hannum saw.
When debugging is enabled, print rx-descriptor status flags
before printing the rx bit rate.

Add a debug message for when a beacon tx buffer reclamation.

Reset IFF_OACTIVE when we reset the transmitter.

Pass the consolidated LED state, a struct rtw_led_state,
to rtw_led_attach.

Choose the bit-rate for management frames (1Mb/s) at the
same place we choose for all other frames.

Do not use the NIC's short preamble or RTS options for
management frames. Label beacons for the NIC.

Following a Linux driver, take care not to zero arbitrary
bits in the TPPOLL register.

Use the new idiom for IBSS merges: disable transmitter,
kick the state machine.
Add a second descriptor to the beacon ring. The NIC seems
to like this much better.
 1.21 27-Feb-2005  perry nuke trailing whitespace
 1.20 04-Feb-2005  perry de-__P
 1.19 16-Jan-2005  dyoung branches: 1.19.2; 1.19.4;
Move the register access mode into struct rtw_regs. Change
rtw_set_access, rtw_set_access1 to match.

Add a subroutine for setting WEP keys. WEP isn't quite finished,
because I have to add the WEP header to Tx packets. Implement the
SIOCS80211NWKEY ioctl for setting WEP keys.

Program the LEDs based on operating state and packet activity.

* On a Revision F RTL8180, blink LED1 at 1Hz to indicate
scan/authenticate/associate states. In the run state, turn LED1
on. In every state, blink LED1 at 5Hz to indicate non-beacon
tx/rx activity. I would like to use two LEDs, but in all my
Rev. F instances, LED0 is not wired to an LED; instead, the
first LED is wired to indicate that the card's power is on.

* On a Revision D RTL8180, program the LEDs so that LED0 indicates
Tx, and LED1 indicates Rx. The Rx LED will blink annoyingly if
there are beacons in the air, but at least the Tx LED is useful.

* Store the hardware revision in the softc to support my futile
attempt at programming LEDs for both Rev. D and Rev. F parts;
I never did get Rev. D LEDs to work right.

* Add a debug flag RTW_DEBUG_LED for the LED transitions.

Add RTW_TPPOLL_ALL, RTW_TPPOLL_SALL to start and stop, respectively,
all of the transmit rings.

In ad hoc mode, allocate a beacon and load it into the beacon ring.
Start the ring. In one trial, the card re-transmitted the beacon
ring's contents several times before stopping. More programming
and testing for ad hoc mode is necessary. I'm not setting the
beacon flag in the transmit descriptor.

Revamp the transmit section to make better use of all the transmit
rings: beacon queue, high-, low-, and medium-priority rings. Put
beacon frames on the beacon ring. All other management frames,
and data frames, go on the medium-priority ring. Power-save data
frames go on the high-priority ring. (Note that powersaving is
not implemented!) This is a work in progress.

Send all 802.11 Management frames at 1Mbps.

After we put a packet on a transmit ring, tickle the right bit in
the TPPOLL to tell RTL8180. Stop all rings on error and in rtw_stop.

Use the RF chip type, not the RTL8180 revision, to choose between
host- and MAC-controlled RF serial I/O. Now the Netgear MA521
works.

Remove bogus definition of bit RTW_TPPOLL_FSWINT.
 1.18 03-Jan-2005  dyoung sys/dev/ic/rtw.c:

Cosmetic: remove two short ladders from rtw_init. Fit the
NIC registers print-out onto one line using the RTW_PRINT_REGS
macro.

sys/dev/ic/rtwvar.h:

Add RTW_PRINT_REGS wrapper macro for rtw_print_regs. It
is a null op unless defined(RTW_DEBUG).
 1.17 02-Jan-2005  dyoung Cosmetic: change u_int{8,16,32,64}_t to C99-style uint{8,16,32,64}_t,
which is preferred.
 1.16 29-Dec-2004  dyoung Remove unused rtw_softc variables and some other dead code.
 1.15 29-Dec-2004  dyoung I like the tlp/atw-style names for software descriptors, txsoft,
better than txctl. Change from rtw_txctl/rtw_rxctl to
rtw_txsoft/rtw_rxsoft. Change the descriptor blocks' names to
match: rtw_txctl_blk becomes rtw_txsoft_blk. Change the member-name
prefixes for both software and hardware descriptors.
 1.14 29-Dec-2004  dyoung Consolidate variables related to the rx ring in sc_rxdesc_blk,
which is a struct rtw_rxdesc_blk.

Put a copy of the DMA tag and the DMA map into the rx- and tx-ring
blocks so that I don't have to pass them to subroutines all of the
time.
 1.13 28-Dec-2004  dyoung Add bpf(4) packet taps to rtw(4). Now you can tap DLT_EN10MB
(Ethernet II), DLT_IEEE802_11 (802.11), and DLT_IEEE802_11_RADIO
(radiotap + 802.11).
 1.12 28-Dec-2004  dyoung Group receiver-related variables together: move sc_rxctl nearer to
sc_rxnext.

Add sc_nrxdesc, the number of receive descriptors that we are
actually able to use. sc_nrxdesc will ordinarily equal RTW_RXQLEN.
If buffers are exhausted, sc_nrxdesc < RTW_RXQLEN. My next commit
will change dev/ic/rtw.c to deal with buffer exhaustion.
 1.11 27-Dec-2004  dyoung Remove useless debug sysctls.

For AP scanning, change the channel dwell time from 1 second to
1/5 second.
 1.10 26-Dec-2004  mycroft Fix a compile error if no RTW_DEBUG.
 1.9 25-Dec-2004  dyoung The rx descriptor ring bug happens quite often, so printf'ing
occurrences is annoying. Only printf about it when rtw_debug
contains RTW_DEBUG_BUG.
 1.8 25-Dec-2004  dyoung Change rtw_debug from a debug level to a debug mask. Add a lot of
debug flags.

From Linux: handle an RTL8180 bug. Sometimes the NIC skips from
the middle of the ring to the 0th rx descriptor. Now the driver
resynchronizes.

Handle a receive descriptor underrun or Rx FIFO overflow condition
in the way that the Linux driver does. This kind of seems like
overkill, but whatever.

Protect rtw_ioctl with splnet().

Do not load a tx descriptor with a buffer shorter than 4 bytes.

Handle a transmit timeout less disruptively.
 1.7 23-Dec-2004  dyoung Round up the number of h/w Rx descriptors to the number of h/w,
not s/w, descriptors in 256 bytes (the descriptor ring alignment).
 1.6 20-Dec-2004  dyoung Realtek sample sources are not consistent about the "Digital PHY"
bit in the SROM. It seems as if it is set to 1 when the PHY is
*analog*, not *digital*. Fix my sources.

In rtw_intr_rx, use units of 500kb/s instead of 100kb/s for rate,
to be consistent with net80211's expectations. Polish up some
debugging ugly messages. Dump raw 802.11 packets if IFF_DEBUG|IFF_LINK2
and RTW_DEBUG is defined.

Polish power-state (on/sleep/off) handling. Especially improve
support for RFMD (totally untested) and Maxim. For Philips, take
the Digital PHY property into account.

Call the net80211 watchdog function from rtw_watchdog, so that we
scan again if auth/assoc fails.

Be a little more cautious about writing register[RTW_TPPOLL], since
other drivers are.... Don't frob the high/low-priority queues
right now, since I don't use them.

Add rtw_join_bss which programs the card with the BSSID and other
properties of a BSS. Use it on state transitions. Factor out
rtw_set_nettype.

Make rtw_recv_beacon call ieee80211_recv_mgmt instead of dropping
beacons on the floor! TBD IBSS merges.

Change some rtw_debug=2 printfs to rtw_debug=3 (RTW_DPRINTF3)
printfs so the console doesn't get spammed so badly at rtw_debug=2.
Change some debugging printfs to RTW_DPRINTFs. E.g., print the
"RF programming method" only if debugging is enabled.
 1.5 19-Dec-2004  dyoung Add the transmit section of rtw(4): build up and tear down transmit
descriptor rings, move packets from the transmit queues to the
transmit rings, handle transmission-completed interrupts. My
Linksys WPC11 ver. 4 with Maxim RF, generates interrupts like it
is successfully transmitting packets. Clearly there are bugs: my
G4 Powerbook locks up hard. I will debug tomorrow.
 1.4 13-Dec-2004  dyoung Fix a typo, s/high/low/.
 1.3 13-Dec-2004  dyoung At last, I have rtw w/ Philips RF receiving packets.

I added some sysctls to aid debugging:

* hw.rtw.debug -- enable debugging

* hw.rtw.flush_rfio -- Linux voodoo: possibly makes the MAC
"flush" bits down the serial bus to the RF

* hw.rtw.host_rfio: force the host to bang bits to the RF, instead
of the MAC banging bits

* hw.rtw.rfio_delay: after telling the MAC to bang bits to the
RF front-end, delay rfio_delay microseconds.

* hw.rtw.rfprog_fallback: there is this notion of the "RF
programming method." I believe the choice influences the
polarity/timing of the serial bus used to program the RF
front-end. I know the correct choice for Intersil/RFMD/Philips
front-ends, only. For all other front-ends, I "fallback" to
rfprog_fallback.

Make rtw_txdac_enable take an rtw_softc argument. I will probably
revert this change.

Add some Linux voodoo to rtw_continuous_tx_enable. I will probably
revert this change.

Important: add rtw_set_rfprog, which sets the correct RF programming
method. This change and the following change are probably responsible
for making the Philips RF work.

Important: RTW_CONFIG1 is an 8-bit register, treat it that way!

Important: RTW_BRSR is 16-bit, RTW_CRCOUNT, RTW_PHYDELAY, and
RTW_MSR are 8-bit: treat them that way!

Vastly simplify rtw_resume_ticks.

Note to self: set the LED state to match the power state.

Hedge against the possibility that RTW_MSR is protected as
RTW_CONFIG[0123] are, meanwhile reworking that section of rtw_init
a little.

Add sc_anaparm, which isn't used, yet....
 1.2 12-Dec-2004  dyoung Miscellaneous changes. Details below. Important changes flagged
with []. Using the driver with my Linksys WPC11 ver. 4, it seems
to be receiving packets for a change. The WPC11 ver. 4 has a Maxim
RF section. My no-name rtw with Philips RF section still does not
receive any packets.

Keep access-level (analog params > config[0123] registers > none)
in sc_access. Add rtw_set_access for changing the access level.

Make rtw_continuous_tx_enable and other subroutines use rtw_set_access
instead of rtw_config0123_enable and rtw_anaparm_enable.

Factor part of the chip-reset code into rtw_chip_reset1.

Change the 'struct foo (*bar)[N]'-style arguments to
'struct foo *bar'-style arguments.

Consolidate software/hardware Tx/Rx ring setup in rtw_hwring_setup,
rtw_swring_setup.

Add a new constant, SA2400_OPMODE_DEFAULTS, for the bits that we
*always* set in the SA2400 OPMODE register.

Factor some code out into rtw_sa2400_calibrate. (Inspired by the
Linux driver.)

[] When the receiver goes into underrun/overflow state, call a new
subroutine, rtw_kick() that stops the Rx/Tx processes, resets
the chip, reinitializes the Tx/Rx rings, and restarts Rx/Tx
processes. (Inspired by the Linux driver.)

[] In rtw_intr_rx, check for too-short packets before calling
ieee80211_find_rxnode. I believe this will prevent a repeat of
the MCHK exception I saw once on macppc.

[] Use seconds-elapased as well as microseconds-elapsed to set the
next "due date" for the timeout interrupt. This keeps the driver
from programming the timeout to expire too early.

[] In rtw_intr, read RTW_ISR at most 10 times, then get out. If
the interface is not enabled (RTW_F_ENABLED), then get out.

[] In rtw_stop, get out if the interface is not enabled (RTW_F_ENABLED).
Block IPL_NET interrupts. Don't read/write any registers if
the interface is invalid (RTW_F_INVALID).

[] Call rtw_stop in rtw_detach.
 1.1 26-Sep-2004  dyoung branches: 1.1.2;
Add work-in-progress driver rtw(4) for Realtek RTL8180 MAC/baseband.

Add register definitions for Maxim MAX2820 and Philips SA2400 radio
front-ends.
 1.1.2.8 11-Dec-2005  christos Sync with head.
 1.1.2.7 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.1.2.6 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.1.2.5 04-Feb-2005  skrll Sync with HEAD.
 1.1.2.4 17-Jan-2005  skrll Sync with HEAD.
 1.1.2.3 18-Dec-2004  skrll Sync with HEAD.
 1.1.2.2 19-Oct-2004  skrll Sync with HEAD
 1.1.2.1 26-Sep-2004  skrll file rtwvar.h was added on branch ktrace-lwp on 2004-10-19 15:56:56 +0000
 1.19.4.2 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.19.4.1 12-Feb-2005  yamt sync with head.
 1.19.2.2 29-Apr-2005  kent sync with -current
 1.19.2.1 16-Jan-2005  kent file rtwvar.h was added on branch kent-audio2 on 2005-04-29 11:28:52 +0000
 1.24.8.1 29-Nov-2005  yamt sync with head.
 1.24.2.6 17-Mar-2008  yamt sync with head.
 1.24.2.5 21-Jan-2008  yamt sync with head
 1.24.2.4 07-Dec-2007  yamt sync with head
 1.24.2.3 03-Sep-2007  yamt sync with head.
 1.24.2.2 26-Feb-2007  yamt sync with head.
 1.24.2.1 21-Jun-2006  yamt sync with head.
 1.27.6.2 01-Jun-2006  kardel Sync with head.
 1.27.6.1 22-Apr-2006  simonb Sync with head.
 1.27.4.1 09-Sep-2006  rpaulo sync with head
 1.27.2.1 18-Feb-2006  yamt sync with head.
 1.28.6.1 24-May-2006  tron Merge 2006-05-24 NetBSD-current into the "peter-altq" branch.
 1.28.2.1 24-May-2006  yamt sync with head.
 1.29.8.1 12-Jan-2007  ad Sync with head.
 1.30.2.1 12-Mar-2007  rmind Sync with HEAD.
 1.31.22.3 18-Feb-2008  mjf Sync with HEAD.
 1.31.22.2 27-Dec-2007  mjf Sync with HEAD.
 1.31.22.1 19-Nov-2007  mjf Sync with HEAD.
 1.31.20.1 18-Nov-2007  bouyer Sync with HEAD
 1.31.16.2 23-Mar-2008  matt sync with HEAD
 1.31.16.1 09-Jan-2008  matt sync with HEAD
 1.31.14.1 21-Nov-2007  joerg Sync with HEAD.
 1.32.6.1 02-Jan-2008  bouyer Sync with HEAD
 1.32.2.1 26-Dec-2007  ad Sync with head.
 1.36.6.1 03-Apr-2008  mjf Sync with HEAD.
 1.36.2.1 24-Mar-2008  keiichi sync with head.
 1.37.4.2 11-Aug-2010  yamt sync with head.
 1.37.4.1 11-Mar-2010  yamt sync with head
 1.41.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.42.2.1 30-May-2010  rmind sync with head
 1.43.40.2 20-Mar-2017  pgoyette Sync with HEAD
 1.43.40.1 04-Nov-2016  pgoyette Sync with HEAD
 1.43.36.2 05-Feb-2017  skrll Sync with HEAD
 1.43.36.1 05-Oct-2016  skrll Sync with HEAD
 1.43.18.1 03-Dec-2017  jdolecek update from HEAD
 1.44.2.1 21-Apr-2017  bouyer Sync with HEAD
 1.45.6.1 10-Dec-2017  snj Pull up following revision(s) (requested by msaitoh in ticket #427):
sys/arch/amiga/dev/if_bah_zbus.c: 1.17
sys/arch/arm/broadcom/bcm53xx_eth.c: 1.30
sys/arch/powerpc/booke/dev/pq3etsec.c: 1.32
sys/arch/usermode/dev/if_veth.c: 1.9
sys/dev/ic/an.c: 1.66
sys/dev/ic/athn.c: 1.17
sys/dev/ic/atw.c: 1.162
sys/dev/ic/bwi.c: 1.33
sys/dev/ic/dwc_gmac.c: 1.41-1.42
sys/dev/ic/malo.c: 1.10
sys/dev/ic/rt2560.c: 1.31
sys/dev/ic/rt2661.c: 1.36
sys/dev/ic/rt2860.c: 1.29
sys/dev/ic/rtw.c: 1.127
sys/dev/ic/rtwvar.h: 1.46
sys/dev/ic/smc90cx6.c: 1.71
sys/dev/ic/smc90cx6var.h: 1.12
sys/dev/ic/wi.c: 1.244
sys/dev/pci/if_ipw.c: 1.66
sys/dev/pci/if_iwi.c: 1.104
sys/dev/pci/if_iwm.c: 1.76
sys/dev/pci/if_iwn.c: 1.86
sys/dev/pci/if_rtwn.c: 1.13
sys/dev/pci/if_wm.c: 1.541
sys/dev/pci/if_wpi.c: 1.79
sys/dev/pci/ixgbe/ixgbe.c: 1.106
sys/dev/pci/ixgbe/ixv.c: 1.73 via patch
sys/dev/pcmcia/if_malo_pcmcia.c: 1.15
sys/dev/scsipi/if_se.c: 1.95
sys/dev/usb/if_upl.c: 1.60
sys/net/if.c: 1.396
sys/net/if.h: 1.241
sys/net/if_arc.h: 1.23
sys/net/if_arcsubr.c: 1.78
sys/net/if_bridge.c: 1.136-1.137
sys/net/if_etherip.c: 1.39
sys/net/if_faith.c: 1.56
sys/net/if_gif.c: 1.131
sys/net/if_loop.c: 1.96
sys/net/if_mpls.c: 1.30
sys/net/if_pppoe.c: 1.129
sys/net/if_srt.c: 1.27
sys/net/if_stf.c: 1.102
sys/net/if_tap.c: 1.100
sys/net/if_vlan.c: 1.105
sys/netinet/ip_carp.c: 1.91
sys/rump/net/lib/libshmif/if_shmem.c: 1.73-1.74
sys/rump/net/lib/libvirtif/if_virt.c: 1.55-1.56
if_initalize() and if_attach() failed when resource allocation failed
(e.g. allocating softint). Without this change, it panics. It's bad because
resource shortage really occured when a lot of pseudo interface is created.
To avoid this problem, don't panic and change return value of if_initialize()
and if_attach() to int. Caller fanction will be recover from error cleanly by
checking the return value.
Return if bah_attach_subr() failed.
If if_attach() failed in the attach function, return.
- If if_initialize() failed in the attach function, free resources and return.
- Add some missing frees in bridge_clone_destroy().
- KNF
If error occured in bcmeth_ccb_attach(), free resources and return.
If error occured in pq3etsec_attach(), free resources and return.
If error occured in the attach function, free resources and return.
- If if_initialize() failed in athn_attach(), free resources and return.
- Add missing pmf_event_deregister() in athn_detach().
- Free resources correctly on some errors in atw_attach().
- Use apint*() insread of printf() in the attach function.
If if_initialize() failed in the attach function, return.
- If if_initialize() failed in the attach function, free resources and return.
- Add missing dwc_gmac_free_dma_rings() and mutex_destroy() when attach
failed.
- If if_initialize() failed in the attach function, free resources and return.
- ifp is always not NULL in iwi_detach(). Check correctly with ifp->if_softc.
- If if_initialize() failed in the attach function, free resources and return.
- Fix error path in the attach function correctly.
If if_initialize() failed in the attach function, free resources and return.
If if_attach() failed in the attach function, free resources and return.
- If if_initialize() failed in the attach function, free resources and return.
- KNF
- If if_attach() failed in the attach function, free resources and return.
- KNF
Fix compile error.
Fix compile error.
We don't need '&mii', but just 'mii' for mii_detach().
Don't free sc_rthash twice
 1.46.2.1 22-Apr-2018  pgoyette Sync with HEAD
 1.47.2.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.8 19-Oct-2009  rmind Drop 3rd and 4th clauses from David Young's license.
Reviewed and approved by dyoung@ (copyright holder).
 1.7 31-Aug-2006  dyoung branches: 1.7.56;
Per discussion on tech-kern and tech-userlevel, move the bit-twiddling
macros, __BIT, __BITS, SHIFTIN, SHIFTOUT, and __arraycount() from
lib/libkern/libkern.h to sys/cdefs.h. Add a __-prefix to SHIFTIN
and SHIFTOUT, and add a manual page for the bit-twiddling macros,
bits(3).

Make the __BIT and __BITS macros "widthless," as best I can, by
changing their type to uintmax_t from uint32_t. XXX The manual
page lags this change by a bit.

Define __PRIxBIT and __PRIxBITS printf(3) format strings.
 1.6 08-Mar-2006  dyoung Change macro names to avoid collisions:

BIT -> __BIT
BITS -> __BITS
 1.5 08-Mar-2006  dyoung Move my bit-twiddling macros to libkern.h from my drivers, where
I had duplicated them. Improve the macros' names. Simplify their
implementation.

A brief description of each macro is below.

BIT(n): Return a bitmask with bit m set, where the least
significant bit is bit 0.

BITS(m, n): Return a bitmask with bits m through n, inclusive,
set. It does not matter whether m>n or m<=n.
The least significant bit is bit 0.

A "bitfield" is a span of consecutive bits defined by a
bitmask, where 1s select the bits in the bitfield. SHIFTIN,
SHIFTOUT, and SHIFTOUT_MASK help read and write bitfields
from device registers.

SHIFTIN(v, mask): Left-shift bits `v' into the bitfield
defined by `mask', and return them. No
side-effects.

SHIFTOUT(v, mask): Extract and return the bitfield selected
by `mask' from `v', right-shifting the
bits so that the rightmost selected bit
is at bit 0. No side-effects.

SHIFTOUT_MASK(mask): Right-shift the bits in `mask' so that
the rightmost non-zero bit is at bit
0. This is useful for finding the
greatest unsigned value that a bitfield
can hold. No side-effects. Note that
SHIFTOUT_MASK(m) = SHIFTOUT(m, m).

Examples:

/*
* Register definitions taken from the RFMD RF3000 manual.
*/
#define RF3000_GAINCTL 0x11 /* TX variable gain control */
#define RF3000_GAINCTL_TXVGC_MASK BITS(7, 2)
#define RF3000_GAINCTL_SCRAMBLER BIT(1)

/*
* Shift the transmit power into the transmit-power field of the
* gain-control register and write it to the baseband processor.
*/
atw_rf3000_write(sc, RF3000_GAINCTL,
SHIFTIN(txpower, RF3000_GAINCTL_TXVGC_MASK));


/*
* Register definitions taken from the ADMtek ADM8211 manual.
*
*/
#define ATW_RXSTAT_OWN BIT(31) /* 1: NIC may fill descriptor */
/* ... */
#define ATW_RXSTAT_DA1 BIT(17) /* DA bit 1, admin'd address */
#define ATW_RXSTAT_DA0 BIT(16) /* DA bit 0, group address */
#define ATW_RXSTAT_RXDR_MASK BITS(15,12) /* RX data rate */
#define ATW_RXSTAT_FL_MASK BITS(11,0) /* RX frame length, last
* descriptor only
*/

/* Extract the frame length from the Rx descriptor's
* status field.
*/
len = SHIFTOUT(rxstat, ATW_RXSTAT_FL_MASK);
 1.4 11-Dec-2005  christos branches: 1.4.4; 1.4.6; 1.4.8; 1.4.10;
merge ktrace-lwp.
 1.3 27-Feb-2005  perry branches: 1.3.4;
nuke trailing whitespace
 1.2 12-Dec-2004  dyoung branches: 1.2.2; 1.2.4;
Miscellaneous changes. Details below. Important changes flagged
with []. Using the driver with my Linksys WPC11 ver. 4, it seems
to be receiving packets for a change. The WPC11 ver. 4 has a Maxim
RF section. My no-name rtw with Philips RF section still does not
receive any packets.

Keep access-level (analog params > config[0123] registers > none)
in sc_access. Add rtw_set_access for changing the access level.

Make rtw_continuous_tx_enable and other subroutines use rtw_set_access
instead of rtw_config0123_enable and rtw_anaparm_enable.

Factor part of the chip-reset code into rtw_chip_reset1.

Change the 'struct foo (*bar)[N]'-style arguments to
'struct foo *bar'-style arguments.

Consolidate software/hardware Tx/Rx ring setup in rtw_hwring_setup,
rtw_swring_setup.

Add a new constant, SA2400_OPMODE_DEFAULTS, for the bits that we
*always* set in the SA2400 OPMODE register.

Factor some code out into rtw_sa2400_calibrate. (Inspired by the
Linux driver.)

[] When the receiver goes into underrun/overflow state, call a new
subroutine, rtw_kick() that stops the Rx/Tx processes, resets
the chip, reinitializes the Tx/Rx rings, and restarts Rx/Tx
processes. (Inspired by the Linux driver.)

[] In rtw_intr_rx, check for too-short packets before calling
ieee80211_find_rxnode. I believe this will prevent a repeat of
the MCHK exception I saw once on macppc.

[] Use seconds-elapased as well as microseconds-elapsed to set the
next "due date" for the timeout interrupt. This keeps the driver
from programming the timeout to expire too early.

[] In rtw_intr, read RTW_ISR at most 10 times, then get out. If
the interface is not enabled (RTW_F_ENABLED), then get out.

[] In rtw_stop, get out if the interface is not enabled (RTW_F_ENABLED).
Block IPL_NET interrupts. Don't read/write any registers if
the interface is invalid (RTW_F_INVALID).

[] Call rtw_stop in rtw_detach.
 1.1 26-Sep-2004  dyoung branches: 1.1.2;
Add work-in-progress driver rtw(4) for Realtek RTL8180 MAC/baseband.

Add register definitions for Maxim MAX2820 and Philips SA2400 radio
front-ends.
 1.1.2.4 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.1.2.3 18-Dec-2004  skrll Sync with HEAD.
 1.1.2.2 19-Oct-2004  skrll Sync with HEAD
 1.1.2.1 26-Sep-2004  skrll file sa2400reg.h was added on branch ktrace-lwp on 2004-10-19 15:56:56 +0000
 1.2.4.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.2.2.1 29-Apr-2005  kent sync with -current
 1.3.4.2 30-Dec-2006  yamt sync with head.
 1.3.4.1 21-Jun-2006  yamt sync with head.
 1.4.10.1 19-Apr-2006  elad sync with head.
 1.4.8.2 03-Sep-2006  yamt sync with head.
 1.4.8.1 13-Mar-2006  yamt sync with head.
 1.4.6.1 22-Apr-2006  simonb Sync with head.
 1.4.4.1 09-Sep-2006  rpaulo sync with head
 1.7.56.1 11-Mar-2010  yamt sync with head
 1.1 24-Oct-2025  brad A driver for the NXP SC16IS7xx family of UART chips. This family is
mostly a 16C450 with features from the 16C550, 16C650 and 16C750 and
makes use of src/sys/dev/ic/com.c for much of the heavy lifting.

A BIG difference is that the chip family is attached via a I2C or SPI
bus and is in no way, shape or form, attached to the computer via a
computer bus.

Since spin locks are not allowed to be held while calling to the I2C
or SPI framework com.c grew a new hw feature flag where it could be
run at something other than a hard IP level and doesn't hold spin lock
(for very long). In particular, IPL_SOFTSERIAL. This method is
enabled via a hw feature flag and should not effect any other use of
com.c. Other changes with this new method of use include the use of
workqueues and such.

A further feature added to com.c was the abilty to take advantage of
the MCR prescaler that is present in the SC16IS7xx family and likely
present in the 16C650. This prescaler is tried if the baud rate
requested can not be met with the frequency oscillator that the chip is
built with.

The chip family does not use any particular frequency oscillator for
the baud rate generator. In order to deal with this the frequency can
be set via sysctl, a kernel option or with a FDT overlay if that is
supported.

Most of the features of the chip family are supported including the
gpio pins via gpiobus(4) that are present with some of the family
members.

The chip can attach via I2C or SPI and can make sure of FDT if that is
present in the system.

This chip family has been around for quite some time and there are a
number of breakout boards on Amazon. It is also reasonably priced and
you can roll your own board if you can perform simple SMD soldering as
very few additional components are required.
 1.1 24-Oct-2025  brad A driver for the NXP SC16IS7xx family of UART chips. This family is
mostly a 16C450 with features from the 16C550, 16C650 and 16C750 and
makes use of src/sys/dev/ic/com.c for much of the heavy lifting.

A BIG difference is that the chip family is attached via a I2C or SPI
bus and is in no way, shape or form, attached to the computer via a
computer bus.

Since spin locks are not allowed to be held while calling to the I2C
or SPI framework com.c grew a new hw feature flag where it could be
run at something other than a hard IP level and doesn't hold spin lock
(for very long). In particular, IPL_SOFTSERIAL. This method is
enabled via a hw feature flag and should not effect any other use of
com.c. Other changes with this new method of use include the use of
workqueues and such.

A further feature added to com.c was the abilty to take advantage of
the MCR prescaler that is present in the SC16IS7xx family and likely
present in the 16C650. This prescaler is tried if the baud rate
requested can not be met with the frequency oscillator that the chip is
built with.

The chip family does not use any particular frequency oscillator for
the baud rate generator. In order to deal with this the frequency can
be set via sysctl, a kernel option or with a FDT overlay if that is
supported.

Most of the features of the chip family are supported including the
gpio pins via gpiobus(4) that are present with some of the family
members.

The chip can attach via I2C or SPI and can make sure of FDT if that is
present in the system.

This chip family has been around for quite some time and there are a
number of breakout boards on Amazon. It is also reasonably priced and
you can roll your own board if you can perform simple SMD soldering as
very few additional components are required.
 1.1 24-Oct-2025  brad A driver for the NXP SC16IS7xx family of UART chips. This family is
mostly a 16C450 with features from the 16C550, 16C650 and 16C750 and
makes use of src/sys/dev/ic/com.c for much of the heavy lifting.

A BIG difference is that the chip family is attached via a I2C or SPI
bus and is in no way, shape or form, attached to the computer via a
computer bus.

Since spin locks are not allowed to be held while calling to the I2C
or SPI framework com.c grew a new hw feature flag where it could be
run at something other than a hard IP level and doesn't hold spin lock
(for very long). In particular, IPL_SOFTSERIAL. This method is
enabled via a hw feature flag and should not effect any other use of
com.c. Other changes with this new method of use include the use of
workqueues and such.

A further feature added to com.c was the abilty to take advantage of
the MCR prescaler that is present in the SC16IS7xx family and likely
present in the 16C650. This prescaler is tried if the baud rate
requested can not be met with the frequency oscillator that the chip is
built with.

The chip family does not use any particular frequency oscillator for
the baud rate generator. In order to deal with this the frequency can
be set via sysctl, a kernel option or with a FDT overlay if that is
supported.

Most of the features of the chip family are supported including the
gpio pins via gpiobus(4) that are present with some of the family
members.

The chip can attach via I2C or SPI and can make sure of FDT if that is
present in the system.

This chip family has been around for quite some time and there are a
number of breakout boards on Amazon. It is also reasonably priced and
you can roll your own board if you can perform simple SMD soldering as
very few additional components are required.
 1.1 24-Oct-2025  brad A driver for the NXP SC16IS7xx family of UART chips. This family is
mostly a 16C450 with features from the 16C550, 16C650 and 16C750 and
makes use of src/sys/dev/ic/com.c for much of the heavy lifting.

A BIG difference is that the chip family is attached via a I2C or SPI
bus and is in no way, shape or form, attached to the computer via a
computer bus.

Since spin locks are not allowed to be held while calling to the I2C
or SPI framework com.c grew a new hw feature flag where it could be
run at something other than a hard IP level and doesn't hold spin lock
(for very long). In particular, IPL_SOFTSERIAL. This method is
enabled via a hw feature flag and should not effect any other use of
com.c. Other changes with this new method of use include the use of
workqueues and such.

A further feature added to com.c was the abilty to take advantage of
the MCR prescaler that is present in the SC16IS7xx family and likely
present in the 16C650. This prescaler is tried if the baud rate
requested can not be met with the frequency oscillator that the chip is
built with.

The chip family does not use any particular frequency oscillator for
the baud rate generator. In order to deal with this the frequency can
be set via sysctl, a kernel option or with a FDT overlay if that is
supported.

Most of the features of the chip family are supported including the
gpio pins via gpiobus(4) that are present with some of the family
members.

The chip can attach via I2C or SPI and can make sure of FDT if that is
present in the system.

This chip family has been around for quite some time and there are a
number of breakout boards on Amazon. It is also reasonably priced and
you can roll your own board if you can perform simple SMD soldering as
very few additional components are required.
 1.1 24-Oct-2025  brad A driver for the NXP SC16IS7xx family of UART chips. This family is
mostly a 16C450 with features from the 16C550, 16C650 and 16C750 and
makes use of src/sys/dev/ic/com.c for much of the heavy lifting.

A BIG difference is that the chip family is attached via a I2C or SPI
bus and is in no way, shape or form, attached to the computer via a
computer bus.

Since spin locks are not allowed to be held while calling to the I2C
or SPI framework com.c grew a new hw feature flag where it could be
run at something other than a hard IP level and doesn't hold spin lock
(for very long). In particular, IPL_SOFTSERIAL. This method is
enabled via a hw feature flag and should not effect any other use of
com.c. Other changes with this new method of use include the use of
workqueues and such.

A further feature added to com.c was the abilty to take advantage of
the MCR prescaler that is present in the SC16IS7xx family and likely
present in the 16C650. This prescaler is tried if the baud rate
requested can not be met with the frequency oscillator that the chip is
built with.

The chip family does not use any particular frequency oscillator for
the baud rate generator. In order to deal with this the frequency can
be set via sysctl, a kernel option or with a FDT overlay if that is
supported.

Most of the features of the chip family are supported including the
gpio pins via gpiobus(4) that are present with some of the family
members.

The chip can attach via I2C or SPI and can make sure of FDT if that is
present in the system.

This chip family has been around for quite some time and there are a
number of breakout boards on Amazon. It is also reasonably priced and
you can roll your own board if you can perform simple SMD soldering as
very few additional components are required.
 1.3 06-Oct-2022  andvar fix few typos in comments and node description.
 1.2 31-Mar-2022  pgoyette For device modules that provide both auto-config and /dev/xxx
interfaces, make sure that initialization and destruction
follow the proper sequence. This is triggered by the recent
changes to the devsw stuff; per riastradh@ the required call
sequence is:

devsw_attach()
config_init_component() or config_cf*_attach()
...
config_fini_component() or config_cf*_detach()
devsw_detach()

While here, add a few missing calls to some of the detach
routines.

Testing of these changes has been limited to:
1. compile without build break
2. no related test failures from atf
3. modload/modunload work as well as
before.

No functional device testing done, since I don't have any
of these devices. Let me know of any damage I might cause
here!

XXX Some of the modules affected by this commit are already
XXX broken; see kern/56772. This commit does not break
any additional modules (as far as I know).
 1.1 07-Dec-2021  brad A driver and user land utility for the Sparkfun Serial Controlled Motor
Driver module as illustrated here:

https://www.sparkfun.com/products/13911

A SCMD module is a ARM SOC simular to a Arduino in front of a motor
driver chip. The single SCMD module can control two motors and up to
16 additional modules can be chained together using an internal I2C
bus. One can interface with the SCMD using tty uart commands, SPI or
I2C. The driver in this commit adds a kernel driver for the I2C and
SPI interfaces. The command line utility provides a set of
convenience commands that support most of the functions of the SCMD
and is able to use the tty uart mode, SPI user land or the included
kernel driver in a uniform manor.

The use of the SCMD module is mostly for small robots and the like,
but it can control anything that is controllable by voltage.
 1.3 05-Apr-2023  andvar remove some double ee typos in comments.
 1.2 21-May-2022  andvar s/artifical/artificial/ in comments.
 1.1 07-Dec-2021  brad A driver and user land utility for the Sparkfun Serial Controlled Motor
Driver module as illustrated here:

https://www.sparkfun.com/products/13911

A SCMD module is a ARM SOC simular to a Arduino in front of a motor
driver chip. The single SCMD module can control two motors and up to
16 additional modules can be chained together using an internal I2C
bus. One can interface with the SCMD using tty uart commands, SPI or
I2C. The driver in this commit adds a kernel driver for the I2C and
SPI interfaces. The command line utility provides a set of
convenience commands that support most of the functions of the SCMD
and is able to use the tty uart mode, SPI user land or the included
kernel driver in a uniform manor.

The use of the SCMD module is mostly for small robots and the like,
but it can control anything that is controllable by voltage.
 1.1 07-Dec-2021  brad A driver and user land utility for the Sparkfun Serial Controlled Motor
Driver module as illustrated here:

https://www.sparkfun.com/products/13911

A SCMD module is a ARM SOC simular to a Arduino in front of a motor
driver chip. The single SCMD module can control two motors and up to
16 additional modules can be chained together using an internal I2C
bus. One can interface with the SCMD using tty uart commands, SPI or
I2C. The driver in this commit adds a kernel driver for the I2C and
SPI interfaces. The command line utility provides a set of
convenience commands that support most of the functions of the SCMD
and is able to use the tty uart mode, SPI user land or the included
kernel driver in a uniform manor.

The use of the SCMD module is mostly for small robots and the like,
but it can control anything that is controllable by voltage.
 1.1 08-Jan-2025  jmcneill branches: 1.1.4;
scmi: Add Arm SCMI performance protocol support.

From OpenBSD, adapted for the NetBSD cpufreq sysctl interface.
 1.1.4.2 02-Aug-2025  perseant Sync with HEAD
 1.1.4.1 08-Jan-2025  perseant file scmi.c was added on branch perseant-exfatfs on 2025-08-02 05:56:42 +0000
 1.1 08-Jan-2025  jmcneill branches: 1.1.4;
scmi: Add Arm SCMI performance protocol support.

From OpenBSD, adapted for the NetBSD cpufreq sysctl interface.
 1.1.4.2 02-Aug-2025  perseant Sync with HEAD
 1.1.4.1 08-Jan-2025  perseant file scmi.h was added on branch perseant-exfatfs on 2025-08-02 05:56:42 +0000
 1.4 30-Dec-2022  andvar s/succes/success/ in comments.
 1.3 07-Jun-2001  thorpej Correct the receive mode mask in the RXCMD register.
 1.2 06-Jun-2001  soren Update URL to documentation PDF.
 1.1 22-Sep-2000  soren branches: 1.1.2; 1.1.4;
Rename to match Ben's naming scheme.
 1.1.4.1 21-Jun-2001  nathanw Catch up to -current.
 1.1.2.2 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.1.2.1 22-Sep-2000  bouyer file seeq8003reg.h was added on branch thorpej_scsipi on 2000-11-20 11:40:53 +0000
 1.66 30-Jan-2020  thorpej Adopt <net/if_stats.h>.
 1.65 10-Nov-2019  chs branches: 1.65.2;
in many device attach paths, allocate memory with M_WAITOK instead of M_NOWAIT
and remove code to handle failures that can no longer happen.
 1.64 28-May-2019  msaitoh Use ETHER_LOCK()/ETHER_UNLOCK() for all ethernet drivers to protect ec_multi*.
 1.63 23-May-2019  msaitoh Whitespace fix (mainly tabify).
 1.62 23-May-2019  msaitoh -No functional change:
- Simplify struct ethercom's pointer near ETHER_FIRST_MULTI().
- Simplify MII structure initialization.
- u_int*_t -> uint*_t.
- KNF
 1.61 05-Feb-2019  msaitoh Remove very old IFF_NOTRAILERS flag.
 1.60 03-Sep-2018  riastradh Rename min/max -> uimin/uimax for better honesty.

These functions are defined on unsigned int. The generic name
min/max should not silently truncate to 32 bits on 64-bit systems.
This is purely a name change -- no functional change intended.

HOWEVER! Some subsystems have

#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))

even though our standard name for that is MIN/MAX. Although these
may invite multiple evaluation bugs, these do _not_ cause integer
truncation.

To avoid `fixing' these cases, I first changed the name in libkern,
and then compile-tested every file where min/max occurred in order to
confirm that it failed -- and thus confirm that nothing shadowed
min/max -- before changing it.

I have left a handful of bootloaders that are too annoying to
compile-test, and some dead code:

cobalt ews4800mips hp300 hppa ia64 luna68k vax
acorn32/if_ie.c (not included in any kernels)
macppc/if_gm.c (superseded by gem(4))

It should be easy to fix the fallout once identified -- this way of
doing things fails safe, and the goal here, after all, is to _avoid_
silent integer truncations, not introduce them.

Maybe one day we can reintroduce min/max as type-generic things that
never silently truncate. But we should avoid doing that for a while,
so that existing code has a chance to be detected by the compiler for
conversion to uimin/uimax without changing the semantics until we can
properly audit it all. (Who knows, maybe in some cases integer
truncation is actually intended!)
 1.59 26-Jun-2018  msaitoh branches: 1.59.2;
Implement the BPF direction filter (BIOC[GS]DIRECTION). It provides backward
compatibility with BIOC[GS]SEESENT ioctl. The userland interface is the same
as FreeBSD.

This change also fixes a bug that the direction is misunderstand on some
environment by passing the direction to bpf_mtap*() instead of checking
m->m_pkthdr.rcvif.
 1.58 22-Jun-2018  msaitoh It's not required to include net/bpfdesc.h. Remove it.
 1.57 15-Dec-2016  ozaki-r branches: 1.57.8; 1.57.14;
Move bpf_mtap and if_ipackets++ on Rx of each driver to percpuq if_input

The benefits of the change are:
- We can reduce codes
- We can provide the same behavior between drivers
- Where/When if_ipackets is counted up
- Note that some drivers still update packet statistics in their own
way (periodical update)
- Moved bpf_mtap run in softint
- This makes it easy to MP-ify bpf

Proposed on tech-kern and tech-net
 1.56 10-Jun-2016  ozaki-r branches: 1.56.2;
Introduce m_set_rcvif and m_reset_rcvif

The API is used to set (or reset) a received interface of a mbuf.
They are counterpart of m_get_rcvif, which will come in another
commit, hide internal of rcvif operation, and reduce the diff of
the upcoming change.

No functional change.
 1.55 09-Feb-2016  ozaki-r Introduce softint-based if_input

This change intends to run the whole network stack in softint context
(or normal LWP), not hardware interrupt context. Note that the work is
still incomplete by this change; to that end, we also have to softint-ify
if_link_state_change (and bpf) which can still run in hardware interrupt.

This change softint-ifies at ifp->if_input that is called from
each device driver (and ieee80211_input) to ensure Layer 2 runs
in softint (e.g., ether_input and bridge_input). To this end,
we provide a framework (called percpuq) that utlizes softint(9)
and percpu ifqueues. With this patch, rxintr of most drivers just
queues received packets and schedules a softint, and the softint
dequeues packets and does rest packet processing.

To minimize changes to each driver, percpuq is allocated in struct
ifnet for now and that is initialized by default (in if_attach).
We probably have to move percpuq to softc of each driver, but it's
future work. At this point, only wm(4) has percpuq in its softc
as a reference implementation.

Additional information including performance numbers can be found
in the thread at tech-kern@ and tech-net@:
http://mail-index.netbsd.org/tech-kern/2016/01/14/msg019997.html

Acknowledgment: riastradh@ greatly helped this work.
Thank you very much!
 1.54 12-Sep-2015  christos Add missing splx() found by brainy.
 1.53 13-Apr-2015  riastradh Convert sys/dev to use <sys/rndsource.h>.
 1.52 10-Aug-2014  tls branches: 1.52.4;
Merge tls-earlyentropy branch into HEAD.
 1.51 10-Oct-2012  skrll branches: 1.51.10;
Second part of PR/46998. The following is taken from the PR with a slight
edit from me.

The TX buffer size is not a function of the SEEQ chip, it is an arbitrary
driver threshold, so I've renamed the define accordingly and added a new
one to specify how many buffers are used (in my port I allow multiple
packets to be in flight at once, so have used #ifndef, such that the
makefile can override).

Comment corrected, and make use of the above defines.

Missing delay(1) added, otherwise the 20,000 timeout loop is dependent
on the speed of your processor. Matches ea_stoptx logic now.

The FIFO empty check does nothing if the previous mode was 'read', but is
required before changing the BUFCODE (per 80C04 datasheet page 19,
note [2]). Then the mode is set to write, so a second FIFO empty check is
needed incase the previous mode was read.

Treat m0 as a pointer not an integer.

Remove double write of the NULL packet header. Either do
memset/ea_writebuf or two writes to SEEQ_BUFWIN, but not both.

The calculation of nextpacket (for hdr[]) assumes bufstart = 0, and puts
the packet header pointing in the wrong place when it isn't.

The setting of CFG2_OUTPUT is done in ea_init(), so doing it in ea_rxinit
is duplicated code.
 1.50 10-Oct-2012  skrll Split softc/device_t
Use device_xname

From chuq
 1.49 10-Oct-2012  skrll Rename eatxpacket to ea_txpacket for consistency.

First part of PR/46998
 1.48 10-Jun-2012  christos branches: 1.48.2;
PR/46576: Robert Sprowson: Shutdown doesn't disable TX/RX interrupts in
SEEQ8005 driver, plus misc white-space and 0->NULL fixes.
 1.47 09-May-2012  martin PR port-acorn32/46435: type mismatch, padbuf should be unsigned char.
 1.46 02-Feb-2012  tls branches: 1.46.2;
Entropy-pool implementation move and cleanup.

1) Move core entropy-pool code and source/sink/sample management code
to sys/kern from sys/dev.

2) Remove use of NRND as test for presence of entropy-pool code throughout
source tree.

3) Remove use of RND_ENABLED in device drivers as microoptimization to
avoid expensive operations on disabled entropy sources; make the
rnd_add calls do this directly so all callers benefit.

4) Fix bug in recent rnd_add_data()/rnd_add_uint32() changes that might
have lead to slight entropy overestimation for some sources.

5) Add new source types for environmental sensors, power sensors, VM
system events, and skew between clocks, with a sample implementation
for each.

ok releng to go in before the branch due to the difficulty of later
pullup (widespread #ifdef removal and moved files). Tested with release
builds on amd64 and evbarm and live testing on amd64.
 1.45 05-Apr-2010  joerg branches: 1.45.8; 1.45.12;
Push the bpf_ops usage back into bpf.h. Push the common ifp->if_bpf
check into the inline functions as well the fourth argument for
bpf_attach.
 1.44 19-Jan-2010  pooka branches: 1.44.2; 1.44.4;
Redefine bpf linkage through an always present op vector, i.e.
#if NBPFILTER is no longer required in the client. This change
doesn't yet add support for loading bpf as a module, since drivers
can register before bpf is attached. However, callers of bpf can
now be modularized.

Dynamically loadable bpf could probably be done fairly easily with
coordination from the stub driver and the real driver by registering
attachments in the stub before the real driver is loaded and doing
a handoff. ... and I'm not going to ponder the depths of unload
here.

Tested with i386/MONOLITHIC, modified MONOLITHIC without bpf and rump.
 1.43 08-Apr-2008  cegger branches: 1.43.4;
use aprint_*_dev and device_xname
 1.42 19-Oct-2007  ad branches: 1.42.16;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.41 26-Aug-2007  dyoung branches: 1.41.2; 1.41.6;
Constify: LLADDR -> CLLADDR. I'm aiming here to make it easier to
identify sockaddr_dl abuse that remains in the kernel, especially
the potential for overwriting memory past the end of a sockaddr_dl
with, e.g., memcpy(LLADDR(), ...).
 1.40 05-Mar-2007  he branches: 1.40.2; 1.40.10; 1.40.14;
Use a char* variable for doing pointer arithmetic with.
 1.39 04-Mar-2007  christos Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.38 11-Dec-2005  christos branches: 1.38.26;
merge ktrace-lwp.
 1.37 27-Feb-2005  perry branches: 1.37.4;
nuke trailing whitespace
 1.36 30-Oct-2004  thorpej branches: 1.36.4; 1.36.6;
When adding/deleting multicast addresses, only whack the address
filter if the interface is marked RUNNING.

Fixes kern/27678.
 1.35 15-Jan-2003  bouyer branches: 1.35.2; 1.35.6;
Use a properly zero'd buffer to pad the packet to ETHER_MIN_LEN
XXX should it be ETHER_MIN_LEN-ETHER_CRC_LEN ?
 1.34 03-Nov-2002  bjh21 Quieten lint a little.
 1.33 07-Jun-2002  bjh21 When copying a block with an odd size to or from the card, be very careful
not to overrun the end of it on the host side, since that might just slip over
a page boundary and cause an embarrassing kernel panic.
 1.32 15-Nov-2001  lukem branches: 1.32.8; 1.32.10;
don't need <sys/types.h> when including <sys/param.h>
 1.31 13-Nov-2001  lukem add/cleanup RCSID
 1.30 07-Nov-2001  bjh21 Add support for feeding entropy to rnd(4).
 1.29 07-Jul-2001  thorpej branches: 1.29.2; 1.29.6;
bcopy -> strcpy
 1.28 07-Jul-2001  thorpej bcmp -> memcmp
 1.27 26-Jun-2001  bjh21 Add support for handling full-size 802.1Q packets.
 1.26 23-Jun-2001  bjh21 ea_mc_reset_8004(): Rather than doing the CRC32 ourselves, call
ether_crc32_be() to do it for us.
 1.25 23-Jun-2001  bjh21 Fix bogons in previous commit:
* Remove harmful debugging code from seeq8005_attach().
* Re-insert variable declarations in ea_mc_reset_8004(), since they aren't
dead yet.
 1.24 22-Jun-2001  bjh21 Attampt support for 8-bit mode. I believe this should work, but I need a more
flexible bus_space on arm26 before I can test it.
 1.23 12-Jun-2001  bjh21 No need to pull in INET or NS headers -- that's all done by ether_ioctl() now.
 1.22 06-Apr-2001  bjh21 In ea_writembuf(), reset the DMA pointer for each mbuf we copy, since
odd-sized mbufs will confuse things. This makes transmission of odd-sized
packets work.
 1.21 05-Apr-2001  bjh21 Add a bit of voodoo code from the old "eb" driver that seems to prevent the
80C04 returning garbage when we read from it. This driver can now handle flood
pings without dropping packets.
 1.20 02-Apr-2001  bjh21 Tweak product ID printing in light of the 80C04A data sheet.

Split out Rx and Tx interrupt handlers into their own functions for clarity.
 1.19 29-Mar-2001  bjh21 On an 80C04, try not to start reads at addresses of the form xx,ea, xx,ee, or
xx,f0. This appears to heavily alleviate, but not to eliminate entirely,
the problems I've been seeing with garbage being read from the rx buffer.
I suspect the real solution lies elsewhere.
 1.18 29-Mar-2001  bjh21 Print a warning message when the DMA FIFO fails to fill or empty before we
time out.
 1.17 27-Mar-2001  bjh21 Print the address within the Rx buffer whenever anything goes wrong: it seems
to be significant.
 1.16 27-Mar-2001  bjh21 Clean up debugging printfs a little.
 1.15 27-Mar-2001  bjh21 Add some extra diagnostics:
* Use the timer to timoe out transmit operations.
* Spot when the "next packet" pointer falls outside the recieve buffer and
reset the interface.
* Don't reset the interface when we get a bad packet (unless there's
something else wrong as well).
 1.14 27-Mar-2001  bjh21 Comment and #ifdef cleanup.
 1.13 25-Mar-2001  bjh21 Tweak handling of multicast on 80C04. I think we need to set the match mode
to "multicast" for it to work, but I could be wrong.

Also make ALLMULTI work on 80C04, but this is untested.
 1.12 24-Mar-2001  bjh21 Re-arrange board memory to suit the current (crude) transmit code.

Add ea_writembuf() from mark's code, and re-work eatxpacket() to use it.
 1.11 24-Mar-2001  bjh21 Enormous pile of changes from mark's (uncommitted) work on this driver.
About the only bit of his code not here is the transmit routines, which I'll
merge in separately.

Also a few bug-fixes, so (for instance) multicast on an 8005 doesn't
immediately fall back to IFF_ALLMULTI.
 1.10 24-Mar-2001  bjh21 Change all the register definitions to match the names using in mark's
improved version of the driver.
 1.9 24-Mar-2001  bjh21 Handle IFF_ALLMULTI correctly. We can now cope with multicast, but for
some reason DAD fails when starting IPv6.
 1.8 23-Dec-2000  bjh21 branches: 1.8.2;
Print the newline after the memory test. This makes it clear that the delay's
related to this driver rather than the next device to be attached.
 1.7 14-Dec-2000  thorpej ALTQ'ify.
 1.6 15-Nov-2000  thorpej branches: 1.6.2;
Move bpfattach()/bpfdetach() calls into ether_ifattach()/ether_ifdetach().
 1.5 03-Nov-2000  bjh21 First attempt at multicast stuff. I suspect it doesn't work.
Use ether_ioctl -- saves 300 bytes of text.
 1.4 01-Oct-2000  thorpej Move the check for "promisc + unicast + not for us" into ether_input(),
and change Ethernet drivers to always pass all received frames to
ether_input() (with a few exceptions, which are documented in the
code).
 1.3 23-Sep-2000  bjh21 Substantial overhaul, factoring out of common code, removal of redundancy
and general cleanup. Still not a beautiful driver, but one I'd be willing to
introduce to my parents now.
 1.2 21-Sep-2000  bjh21 Add rudimentary 80C04 support (basically saying "Oh look, an 80C04!").
Move printing the initial ":" into the board driver, like i82586.c does.
Don't bother printing the amount of RAM, as it's always 64 KB.
 1.1 18-Sep-2000  bjh21 Split the arm26 Ether3 (ea) driver into an MI driver for the SEEQ 8005 chip,
and a front-end driver for the Ether3. Only semantic change is to remove
ea_claimirq() and ea_releaseirq() on the grounds that the seem too spurious
to warrant a callback to the front-end.
 1.6.2.6 21-Apr-2001  bouyer Sync with HEAD
 1.6.2.5 27-Mar-2001  bouyer Sync with HEAD.
 1.6.2.4 05-Jan-2001  bouyer Sync with HEAD
 1.6.2.3 22-Nov-2000  bouyer Sync with HEAD.
 1.6.2.2 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.6.2.1 15-Nov-2000  bouyer file seeq8005.c was added on branch thorpej_scsipi on 2000-11-20 11:40:53 +0000
 1.8.2.8 17-Jan-2003  thorpej Sync with HEAD.
 1.8.2.7 11-Nov-2002  nathanw Catch up to -current
 1.8.2.6 20-Jun-2002  nathanw Catch up to -current.
 1.8.2.5 08-Jan-2002  nathanw Catch up to -current.
 1.8.2.4 14-Nov-2001  nathanw Catch up to -current.
 1.8.2.3 24-Aug-2001  nathanw Catch up with -current.
 1.8.2.2 21-Jun-2001  nathanw Catch up to -current.
 1.8.2.1 09-Apr-2001  nathanw Catch up with -current.
 1.29.6.1 12-Nov-2001  thorpej Sync the thorpej-mips-cache branch with -current.
 1.29.2.2 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.29.2.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.32.10.2 27-Jan-2003  jmc Pullup revisions 1.34-1.35 (requested by bouyer in ticket #1087)

Use a properly zero'd buffer to pad the packet to ETHER_MIN_LEN
XXX should it be ETHER_MIN_LEN-ETHER_CRC_LEN ?
 1.32.10.1 07-Jun-2002  thorpej pullup-1-6 ticket #201:

syssrc/sys/dev/ic/seeq8005.c 1.33

When copying a block with an odd size to or from the card, be very careful
not to overrun the end of it on the host side, since that might just slip over
a page boundary and cause an embarrassing kernel panic.
 1.32.8.1 20-Jun-2002  gehenna catch up with -current.
 1.35.6.1 24-Jan-2005  he Pull up revision 1.36 (requested by thorpej in ticket #939):
When adding or deleting multicast addresses, only change
the address filter if the interface is marked RUNNING.
Fixes PR#27678.
 1.35.2.2 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.35.2.1 02-Nov-2004  skrll Sync with HEAD.
 1.36.6.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.36.4.1 29-Apr-2005  kent sync with -current
 1.37.4.2 27-Oct-2007  yamt sync with head.
 1.37.4.1 03-Sep-2007  yamt sync with head.
 1.38.26.1 12-Mar-2007  rmind Sync with HEAD.
 1.40.14.2 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.40.14.1 03-Sep-2007  jmcneill Sync with HEAD.
 1.40.10.1 03-Sep-2007  skrll Sync with HEAD.
 1.40.2.2 23-Oct-2007  ad Sync with head.
 1.40.2.1 09-Oct-2007  ad Sync with head.
 1.41.6.1 25-Oct-2007  bouyer Sync with HEAD.
 1.41.2.1 06-Nov-2007  matt sync with HEAD
 1.42.16.1 02-Jun-2008  mjf Sync with HEAD.
 1.43.4.2 11-Aug-2010  yamt sync with head.
 1.43.4.1 11-Mar-2010  yamt sync with head
 1.44.4.1 30-May-2010  rmind sync with head
 1.44.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.45.12.2 02-Jun-2012  mrg sync to latest -current.
 1.45.12.1 18-Feb-2012  mrg merge to -current.
 1.45.8.3 30-Oct-2012  yamt sync with head
 1.45.8.2 23-May-2012  yamt sync with head.
 1.45.8.1 17-Apr-2012  yamt sync with head
 1.46.2.1 12-Jun-2012  riz Pull up following revision(s) (requested by christos in ticket #325):
sys/dev/ic/seeq8005.c: revision 1.48
PR/46576: Robert Sprowson: Shutdown doesn't disable TX/RX interrupts in
SEEQ8005 driver, plus misc white-space and 0->NULL fixes.
 1.48.2.3 03-Dec-2017  jdolecek update from HEAD
 1.48.2.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.48.2.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.51.10.1 07-Apr-2014  tls Be a little more clear and consistent about harvesting entropy from devices:

1) deprecate RND_FLAG_NO_ESTIMATE

2) define RND_FLAG_COLLECT_TIME, RND_FLAG_COLLECT_VALUE

3) define RND_FLAG_ESTIMATE_TIME, RND_FLAG_ESTIMATE_VALUE

4) define RND_FLAG_DEFAULT: RND_FLAG_COLLECT_TIME|
RND_FLAG_COLLECT_VALUE|RND_FLAG_ESTIMATE_TIME

5) Make entropy harvesting from environmental sensors a little more generic
and remove it from individual sensor drivers.

6) Remove individual open-coded delta-estimators for values from a few
places in the tree (uvm, environmental drivers).

7) 0 -> RND_FLAG_DEFAULT, actually gather entropy from various drivers
that had stubbed out code, other minor cleanups.
 1.52.4.5 05-Feb-2017  skrll Sync with HEAD
 1.52.4.4 09-Jul-2016  skrll Sync with HEAD
 1.52.4.3 19-Mar-2016  skrll Sync with HEAD
 1.52.4.2 22-Sep-2015  skrll Sync with HEAD
 1.52.4.1 06-Jun-2015  skrll Sync with HEAD
 1.56.2.1 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.57.14.3 06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.57.14.2 28-Jul-2018  pgoyette Sync with HEAD
 1.57.14.1 25-Jun-2018  pgoyette Sync with HEAD
 1.57.8.1 26-Jul-2018  snj Pull up following revision(s) (requested by msaitoh in ticket #938):
sys/arch/acorn32/podulebus/if_ie.c: revision 1.41
sys/arch/amiga/dev/if_es.c: revision 1.58
sys/arch/amiga/dev/if_qn.c: revision 1.45
sys/arch/arm/at91/at91emac.c: revision 1.20
sys/arch/arm/ep93xx/epe.c: revision 1.37
sys/arch/emips/ebus/if_le_ebus.c: revision 1.14
sys/arch/emips/ebus/if_le_ebus.c: revision 1.15
sys/arch/mac68k/dev/if_mc.c: revision 1.46
sys/arch/macppc/dev/am79c950.c: revision 1.39
sys/arch/newsmips/apbus/if_sn.c: revision 1.40
sys/arch/next68k/dev/mb8795.c: revision 1.59
sys/arch/playstation2/dev/if_smap.c: revision 1.25
sys/arch/playstation2/dev/if_smap.c: revision 1.26
sys/arch/sun2/dev/if_ec.c: revision 1.28
sys/arch/sun3/dev/if_ie.c: revision 1.63
sys/arch/x68k/dev/if_ne_intio.c: revision 1.19
sys/arch/xen/xen/if_xennet_xenbus.c: revision 1.75
sys/arch/xen/xen/xennetback_xenbus.c: revision 1.63
sys/dev/bi/if_ni.c: revision 1.45
sys/dev/cadence/if_cemac.c: revision 1.12
sys/dev/ic/am7990.c: revision 1.78
sys/dev/ic/am79900.c: revision 1.27
sys/dev/ic/an.c: revision 1.67
sys/dev/ic/cs89x0.c: revision 1.40
sys/dev/ic/dm9000.c: revision 1.13
sys/dev/ic/dm9000.c: revision 1.14
sys/dev/ic/dp8390.c: revision 1.88
sys/dev/ic/elink3.c: revision 1.141
sys/dev/ic/elinkxl.c: revision 1.122
sys/dev/ic/hme.c: revision 1.98
sys/dev/ic/i82586.c: revision 1.77
sys/dev/ic/lance.c: revision 1.53
sys/dev/ic/mb86950.c: revision 1.27
sys/dev/ic/mb86960.c: revision 1.86
sys/dev/ic/mtd803.c: revision 1.34
sys/dev/ic/pdq_ifsubr.c: revision 1.59
sys/dev/ic/rrunner.c: revision 1.86
sys/dev/ic/seeq8005.c: revision 1.58
sys/dev/ic/sgec.c: revision 1.47
sys/dev/ic/smc90cx6.c: revision 1.72
sys/dev/ic/smc91cxx.c: revision 1.96
sys/dev/ic/tropic.c: revision 1.49
sys/dev/ic/wi.c: revision 1.245
sys/dev/isa/if_eg.c: revision 1.93
sys/dev/isa/if_el.c: revision 1.95
sys/dev/isa/if_iy.c: revision 1.101
sys/dev/ofw/ofnet.c: revision 1.58
sys/dev/pci/if_alc.c: revision 1.27
sys/dev/pci/if_de.c: revision 1.152
sys/dev/pci/if_fpa.c: revision 1.61
sys/dev/pci/if_jme.c: revision 1.34
sys/dev/pci/if_tl.c: revision 1.108
sys/dev/pci/if_vte.c: revision 1.19
sys/dev/pci/ixgbe/ixgbe.h: revision 1.50
sys/dev/pcmcia/if_cnw.c: revision 1.62
sys/dev/pcmcia/if_malo_pcmcia.c: revision 1.17
sys/dev/pcmcia/if_ray.c: revision 1.89
sys/dev/pcmcia/if_xi.c: revision 1.81
sys/dev/pcmcia/mhzc.c: revision 1.51
sys/dev/pcmcia/xirc.c: revision 1.34
sys/dev/qbus/if_de.c: revision 1.33
sys/dev/qbus/if_qe.c: revision 1.78
sys/dev/qbus/if_qt.c: revision 1.22
sys/dev/sbus/be.c: revision 1.87
sys/dev/sbus/qe.c: revision 1.68
sys/dev/scsipi/if_se.c: revision 1.96
sys/dev/usb/if_atu.c: revision 1.59
sys/net/if_l2tp.c: revision 1.28 via patch
sys/net/if_ppp.c: revision 1.160
It's not required to include net/bpfdesc.h. Remove it.
--
Simplify like other drivers. NULL check of ifp->if_bpf is done in
bpf_mtap(), so it's not required to do it here.
--
Remove duplicated inclusion of net/bpf.h.
--
Remove duplicated inclusion of net/bpf.h.
--
Simplify bpf_mtap() call. No functional change.
 1.59.2.3 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.59.2.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.59.2.1 10-Jun-2019  christos Sync with HEAD
 1.65.2.1 29-Feb-2020  ad Sync with head.
 1.4 01-Apr-2001  bjh21 Add some definitions for the 80C04A, thanks to Reinoud, who found me a data
sheet for it.
 1.3 24-Mar-2001  bjh21 Change all the register definitions to match the names using in mark's
improved version of the driver.
 1.2 21-Sep-2000  bjh21 branches: 1.2.2; 1.2.4;
Add rudimentary 80C04 support (basically saying "Oh look, an 80C04!").
Move printing the initial ":" into the board driver, like i82586.c does.
Don't bother printing the amount of RAM, as it's always 64 KB.
 1.1 18-Sep-2000  bjh21 Split the arm26 Ether3 (ea) driver into an MI driver for the SEEQ 8005 chip,
and a front-end driver for the Ether3. Only semantic change is to remove
ea_claimirq() and ea_releaseirq() on the grounds that the seem too spurious
to warrant a callback to the front-end.
 1.2.4.1 09-Apr-2001  nathanw Catch up with -current.
 1.2.2.4 21-Apr-2001  bouyer Sync with HEAD
 1.2.2.3 27-Mar-2001  bouyer Sync with HEAD.
 1.2.2.2 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.2.2.1 21-Sep-2000  bouyer file seeq8005reg.h was added on branch thorpej_scsipi on 2000-11-20 11:40:54 +0000
 1.9 13-Apr-2015  riastradh Convert sys/dev to use <sys/rndsource.h>.
 1.8 10-Oct-2012  skrll branches: 1.8.14;
Split softc/device_t
Use device_xname

From chuq
 1.7 02-Feb-2012  tls branches: 1.7.6;
Entropy-pool implementation move and cleanup.

1) Move core entropy-pool code and source/sink/sample management code
to sys/kern from sys/dev.

2) Remove use of NRND as test for presence of entropy-pool code throughout
source tree.

3) Remove use of RND_ENABLED in device drivers as microoptimization to
avoid expensive operations on disabled entropy sources; make the
rnd_add calls do this directly so all callers benefit.

4) Fix bug in recent rnd_add_data()/rnd_add_uint32() changes that might
have lead to slight entropy overestimation for some sources.

5) Add new source types for environmental sensors, power sensors, VM
system events, and skew between clocks, with a sample implementation
for each.

ok releng to go in before the branch due to the difficulty of later
pullup (widespread #ifdef removal and moved files). Tested with release
builds on amd64 and evbarm and live testing on amd64.
 1.6 19-Nov-2011  tls branches: 1.6.2;
First step of random number subsystem rework described in
<20111022023242.BA26F14A158@mail.netbsd.org>. This change includes
the following:

An initial cleanup and minor reorganization of the entropy pool
code in sys/dev/rnd.c and sys/dev/rndpool.c. Several bugs are
fixed. Some effort is made to accumulate entropy more quickly at
boot time.

A generic interface, "rndsink", is added, for stream generators to
request that they be re-keyed with good quality entropy from the pool
as soon as it is available.

The arc4random()/arc4randbytes() implementation in libkern is
adjusted to use the rndsink interface for rekeying, which helps
address the problem of low-quality keys at boot time.

An implementation of the FIPS 140-2 statistical tests for random
number generator quality is provided (libkern/rngtest.c). This
is based on Greg Rose's implementation from Qualcomm.

A new random stream generator, nist_ctr_drbg, is provided. It is
based on an implementation of the NIST SP800-90 CTR_DRBG by
Henric Jungheim. This generator users AES in a modified counter
mode to generate a backtracking-resistant random stream.

An abstraction layer, "cprng", is provided for in-kernel consumers
of randomness. The arc4random/arc4randbytes API is deprecated for
in-kernel use. It is replaced by "cprng_strong". The current
cprng_fast implementation wraps the existing arc4random
implementation. The current cprng_strong implementation wraps the
new CTR_DRBG implementation. Both interfaces are rekeyed from
the entropy pool automatically at intervals justifiable from best
current cryptographic practice.

In some quick tests, cprng_fast() is about the same speed as
the old arc4randbytes(), and cprng_strong() is about 20% faster
than rnd_extract_data(). Performance is expected to improve.

The AES code in src/crypto/rijndael is no longer an optional
kernel component, as it is required by cprng_strong, which is
not an optional kernel component.

The entropy pool output is subjected to the rngtest tests at
startup time; if it fails, the system will reboot. There is
approximately a 3/10000 chance of a false positive from these
tests. Entropy pool _input_ from hardware random numbers is
subjected to the rngtest tests at attach time, as well as the
FIPS continuous-output test, to detect bad or stuck hardware
RNGs; if any are detected, they are detached, but the system
continues to run.

A problem with rndctl(8) is fixed -- datastructures with
pointers in arrays are no longer passed to userspace (this
was not a security problem, but rather a major issue for
compat32). A new kernel will require a new rndctl.

The sysctl kern.arandom() and kern.urandom() nodes are hooked
up to the new generators, but the /dev/*random pseudodevices
are not, yet.

Manual pages for the new kernel interfaces are forthcoming.
 1.5 07-Nov-2001  bjh21 branches: 1.5.154;
Add support for feeding entropy to rnd(4).
 1.4 25-Jun-2001  bjh21 branches: 1.4.2; 1.4.6;
Add sc_flags to seeq8005_softc, and put a flag in it.
 1.3 24-Mar-2001  bjh21 Enormous pile of changes from mark's (uncommitted) work on this driver.
About the only bit of his code not here is the transmit routines, which I'll
merge in separately.

Also a few bug-fixes, so (for instance) multicast on an 8005 doesn't
immediately fall back to IFF_ALLMULTI.
 1.2 21-Sep-2000  bjh21 branches: 1.2.2; 1.2.4;
Add rudimentary 80C04 support (basically saying "Oh look, an 80C04!").
Move printing the initial ":" into the board driver, like i82586.c does.
Don't bother printing the amount of RAM, as it's always 64 KB.
 1.1 18-Sep-2000  bjh21 Split the arm26 Ether3 (ea) driver into an MI driver for the SEEQ 8005 chip,
and a front-end driver for the Ether3. Only semantic change is to remove
ea_claimirq() and ea_releaseirq() on the grounds that the seem too spurious
to warrant a callback to the front-end.
 1.2.4.3 14-Nov-2001  nathanw Catch up to -current.
 1.2.4.2 24-Aug-2001  nathanw Catch up with -current.
 1.2.4.1 09-Apr-2001  nathanw Catch up with -current.
 1.2.2.3 27-Mar-2001  bouyer Sync with HEAD.
 1.2.2.2 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.2.2.1 21-Sep-2000  bouyer file seeq8005var.h was added on branch thorpej_scsipi on 2000-11-20 11:40:54 +0000
 1.4.6.1 12-Nov-2001  thorpej Sync the thorpej-mips-cache branch with -current.
 1.4.2.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.5.154.2 30-Oct-2012  yamt sync with head
 1.5.154.1 17-Apr-2012  yamt sync with head
 1.6.2.1 18-Feb-2012  mrg merge to -current.
 1.7.6.2 03-Dec-2017  jdolecek update from HEAD
 1.7.6.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.8.14.1 06-Jun-2015  skrll Sync with HEAD
 1.53 15-Mar-2020  thorpej Don't bother with IFF_OACTIVE.
 1.52 30-Jan-2020  thorpej Adopt <net/if_stats.h>.
 1.51 28-May-2019  msaitoh branches: 1.51.4;
Use ETHER_LOCK()/ETHER_UNLOCK() for all ethernet drivers to protect ec_multi*.
 1.50 23-May-2019  msaitoh Whitespace fix (mainly tabify).
 1.49 23-May-2019  msaitoh -No functional change:
- KNF
- u_int*_t -> uint*_t.
 1.48 26-Jun-2018  msaitoh branches: 1.48.2;
Implement the BPF direction filter (BIOC[GS]DIRECTION). It provides backward
compatibility with BIOC[GS]SEESENT ioctl. The userland interface is the same
as FreeBSD.

This change also fixes a bug that the direction is misunderstand on some
environment by passing the direction to bpf_mtap*() instead of checking
m->m_pkthdr.rcvif.
 1.47 22-Jun-2018  msaitoh It's not required to include net/bpfdesc.h. Remove it.
 1.46 22-May-2017  ragge branches: 1.46.2; 1.46.8;
Update copyright notice for Ludd (remove clause 3 & 4).
 1.45 15-Dec-2016  ozaki-r Move bpf_mtap in Tx hardware intrrupt to if_start

The intention of the change is to prevent bpf_mtap from running in
hardware interrupt context. if_start is a usual place to do bpf_mtap
on Tx.

Proposed on tech-kern and tech-net
 1.44 15-Dec-2016  ozaki-r Move bpf_mtap and if_ipackets++ on Rx of each driver to percpuq if_input

The benefits of the change are:
- We can reduce codes
- We can provide the same behavior between drivers
- Where/When if_ipackets is counted up
- Note that some drivers still update packet statistics in their own
way (periodical update)
- Moved bpf_mtap run in softint
- This makes it easy to MP-ify bpf

Proposed on tech-kern and tech-net
 1.43 10-Jun-2016  ozaki-r branches: 1.43.2;
Introduce m_set_rcvif and m_reset_rcvif

The API is used to set (or reset) a received interface of a mbuf.
They are counterpart of m_get_rcvif, which will come in another
commit, hide internal of rcvif operation, and reduce the diff of
the upcoming change.

No functional change.
 1.42 09-Feb-2016  ozaki-r Introduce softint-based if_input

This change intends to run the whole network stack in softint context
(or normal LWP), not hardware interrupt context. Note that the work is
still incomplete by this change; to that end, we also have to softint-ify
if_link_state_change (and bpf) which can still run in hardware interrupt.

This change softint-ifies at ifp->if_input that is called from
each device driver (and ieee80211_input) to ensure Layer 2 runs
in softint (e.g., ether_input and bridge_input). To this end,
we provide a framework (called percpuq) that utlizes softint(9)
and percpu ifqueues. With this patch, rxintr of most drivers just
queues received packets and schedules a softint, and the softint
dequeues packets and does rest packet processing.

To minimize changes to each driver, percpuq is allocated in struct
ifnet for now and that is initialized by default (in if_attach).
We probably have to move percpuq to softc of each driver, but it's
future work. At this point, only wm(4) has percpuq in its softc
as a reference implementation.

Additional information including performance numbers can be found
in the thread at tech-kern@ and tech-net@:
http://mail-index.netbsd.org/tech-kern/2016/01/14/msg019997.html

Acknowledgment: riastradh@ greatly helped this work.
Thank you very much!
 1.41 30-Aug-2015  dholland Initialize uninitialized variable; from maxv's brainy list. Fixes slipup
in -r1.30 back in 2007.
 1.40 24-Oct-2013  martin branches: 1.40.6;
Fix a few copy&pastos in an error path
 1.39 13-Nov-2010  uebayasi branches: 1.39.8; 1.39.18; 1.39.22;
Don't pull in the whole uvm(9) API to access only PAGE_SIZE and
some other constants. These are provided by sys/param.h now.
 1.38 05-Apr-2010  joerg Push the bpf_ops usage back into bpf.h. Push the common ifp->if_bpf
check into the inline functions as well the fourth argument for
bpf_attach.
 1.37 19-Jan-2010  pooka branches: 1.37.2; 1.37.4;
Redefine bpf linkage through an always present op vector, i.e.
#if NBPFILTER is no longer required in the client. This change
doesn't yet add support for loading bpf as a module, since drivers
can register before bpf is attached. However, callers of bpf can
now be modularized.

Dynamically loadable bpf could probably be done fairly easily with
coordination from the stub driver and the real driver by registering
attachments in the stub before the real driver is loaded and doing
a handoff. ... and I'm not going to ponder the depths of unload
here.

Tested with i386/MONOLITHIC, modified MONOLITHIC without bpf and rump.
 1.36 07-Nov-2008  dyoung *** Summary ***

When a link-layer address changes (e.g., ifconfig ex0 link
02:de:ad:be:ef:02 active), send a gratuitous ARP and/or a Neighbor
Advertisement to update the network-/link-layer address bindings
on our LAN peers.

Refuse a change of ethernet address to the address 00:00:00:00:00:00
or to any multicast/broadcast address. (Thanks matt@.)

Reorder ifnet ioctl operations so that driver ioctls may inherit
the functions of their "class"---ether_ioctl(), fddi_ioctl(), et
cetera---and the class ioctls may inherit from the generic ioctl,
ifioctl_common(), but both driver- and class-ioctls may override
the generic behavior. Make network drivers share more code.

Distinguish a "factory" link-layer address from others for the
purposes of both protecting that address from deletion and computing
EUI64.

Return consistent, appropriate error codes from network drivers.

Improve readability. KNF.

*** Details ***

In if_attach(), always initialize the interface ioctl routine,
ifnet->if_ioctl, if the driver has not already initialized it.
Delete if_ioctl == NULL tests everywhere else, because it cannot
happen.

In the ioctl routines of network interfaces, inherit common ioctl
behaviors by calling either ifioctl_common() or whichever ioctl
routine is appropriate for the class of interface---e.g., ether_ioctl()
for ethernets.

Stop (ab)using SIOCSIFADDR and start to use SIOCINITIFADDR. In
the user->kernel interface, SIOCSIFADDR's argument was an ifreq,
but on the protocol->ifnet interface, SIOCSIFADDR's argument was
an ifaddr. That was confusing, and it would work against me as I
make it possible for a network interface to overload most ioctls.
On the protocol->ifnet interface, replace SIOCSIFADDR with
SIOCINITIFADDR. In ifioctl(), return EPERM if userland tries to
invoke SIOCINITIFADDR.

In ifioctl(), give the interface the first shot at handling most
interface ioctls, and give the protocol the second shot, instead
of the other way around. Finally, let compatibility code (COMPAT_OSOCK)
take a shot.

Pull device initialization out of switch statements under
SIOCINITIFADDR. For example, pull ..._init() out of any switch
statement that looks like this:

switch (...->sa_family) {
case ...:
..._init();
...
break;
...
default:
..._init();
...
break;
}

Rewrite many if-else clauses that handle all permutations of IFF_UP
and IFF_RUNNING to use a switch statement,

switch (x & (IFF_UP|IFF_RUNNING)) {
case 0:
...
break;
case IFF_RUNNING:
...
break;
case IFF_UP:
...
break;
case IFF_UP|IFF_RUNNING:
...
break;
}

unifdef lots of code containing #ifdef FreeBSD, #ifdef NetBSD, and
#ifdef SIOCSIFMTU, especially in fwip(4) and in ndis(4).

In ipw(4), remove an if_set_sadl() call that is out of place.

In nfe(4), reuse the jumbo MTU logic in ether_ioctl().

Let ethernets register a callback for setting h/w state such as
promiscuous mode and the multicast filter in accord with a change
in the if_flags: ether_set_ifflags_cb() registers a callback that
returns ENETRESET if the caller should reset the ethernet by calling
if_init(), 0 on success, != 0 on failure. Pull common code from
ex(4), gem(4), nfe(4), sip(4), tlp(4), vge(4) into ether_ioctl(),
and register if_flags callbacks for those drivers.

Return ENOTTY instead of EINVAL for inappropriate ioctls. In
zyd(4), use ENXIO instead of ENOTTY to indicate that the device is
not any longer attached.

Add to if_set_sadl() a boolean 'factory' argument that indicates
whether a link-layer address was assigned by the factory or some
other source. In a comment, recommend using the factory address
for generating an EUI64, and update in6_get_hw_ifid() to prefer a
factory address to any other link-layer address.

Add a routing message, RTM_LLINFO_UPD, that tells protocols to
update the binding of network-layer addresses to link-layer addresses.
Implement this message in IPv4 and IPv6 by sending a gratuitous
ARP or a neighbor advertisement, respectively. Generate RTM_LLINFO_UPD
messages on a change of an interface's link-layer address.

In ether_ioctl(), do not let SIOCALIFADDR set a link-layer address
that is broadcast/multicast or equal to 00:00:00:00:00:00.

Make ether_ioctl() call ifioctl_common() to handle ioctls that it
does not understand.

In gif(4), initialize if_softc and use it, instead of assuming that
the gif_softc and ifp overlap.

Let ifioctl_common() handle SIOCGIFADDR.

Sprinkle rtcache_invariants(), which checks on DIAGNOSTIC kernels
that certain invariants on a struct route are satisfied.

In agr(4), rewrite agr_ioctl_filter() to be a bit more explicit
about the ioctls that we do not allow on an agr(4) member interface.

bzero -> memset. Delete unnecessary casts to void *. Use
sockaddr_in_init() and sockaddr_in6_init(). Compare pointers with
NULL instead of "testing truth". Replace some instances of (type
*)0 with NULL. Change some K&R prototypes to ANSI C, and join
lines.
 1.35 11-Mar-2008  matt branches: 1.35.4; 1.35.10; 1.35.12;
Rototill the vax code. Switch to devicet/PRIV_ALLOC. Cleanup vax autoconf
code. Move to prototype definitions. staticfy, constify, avoid casting.
Use device_* accessors.
 1.34 19-Oct-2007  ad branches: 1.34.12; 1.34.16;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.33 06-Sep-2007  he branches: 1.33.4;
Remove a now-unused local variable.
 1.32 01-Sep-2007  dyoung Change a bazillion occurrences of code resembling this,

error = (cmd == SIOCADDMULTI) ?
ether_addmulti(ifr, &sc->sc_ec) :
ether_delmulti(ifr, &sc->sc_ec);

if (error == ENETRESET) {

to this,

if ((error = ether_ioctl(ifp, cmd, data)) == ENETRESET) {

which does the same thing.

(A bazillion is a very large number. This seems to make the i386
ALL kernel smaller by 3kB to 4kB.)

Use ifreq_getaddr() twice in es(4).

Whitespace nits.
 1.31 27-Aug-2007  dyoung branches: 1.31.2;
Constify: use CLLADDR() instead of LLADDR() wherever possible.
 1.30 26-Apr-2007  matt branches: 1.30.2; 1.30.6;
Count tx/rx intrs.
Don't set OW in the first transmit descriptor until all descriptors have
been set up. Always try to drain the transmit ring.
 1.29 13-Apr-2007  matt Improve the transmit logic. Use bus_dma_load_mbuf on the entire mbuf and
load each segment. in transmit interrupt service, take advatnage on know
how many segments/descriptors are in each packet.
 1.28 04-Mar-2007  christos branches: 1.28.2; 1.28.4;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.27 11-Dec-2005  christos branches: 1.27.24; 1.27.26;
merge ktrace-lwp.
 1.26 27-Feb-2005  perry branches: 1.26.4;
nuke trailing whitespace
 1.25 04-Feb-2005  perry de-__P
 1.24 31-Jan-2005  thorpej Eliminate the use of M_HASFCS.
 1.23 30-Oct-2004  thorpej branches: 1.23.4; 1.23.6;
When adding/deleting multicast addresses, only whack the address
filter if the interface is marked RUNNING.

Fixes kern/27678.
 1.22 26-Feb-2003  matt branches: 1.22.2; 1.22.6;
Add MBUFTRACE kernel option.
Do a little mbuf rework while here. Change all uses of MGET*(*, M_WAIT, *)
to m_get*(M_WAIT, *). These are not performance critical and making them
call m_get saves considerable space. Add m_clget analogue of MCLGET and
make corresponding change for M_WAIT uses.
Modify netinet, gem, fxp, tulip, nfs to support MBUFTRACE.
Begin to change netstat to use sysctl.
 1.21 15-Jan-2003  bouyer Hum, ragge said this chip should autopad, so just remove the check.
 1.20 15-Jan-2003  bouyer zero out the remaining of last mbuf when padding the packet to ETHER_MIN_LEN
XXX should it be ETHER_MIN_LEN-ETHER_CRC_LEN ?
XXX2 we assume there is enouth room in the last mbuf. The code already assumes
this in other places.
 1.19 27-Sep-2002  provos remove trailing \n in panic(). approved perry.
 1.18 13-Nov-2001  lukem branches: 1.18.10;
add/cleanup RCSID
 1.17 19-Jul-2001  thorpej Use BUS_DMA_READ and BUS_DMA_WRITE in some obvious places.
 1.16 07-Jul-2001  thorpej branches: 1.16.2;
bzero -> memset
 1.15 07-Jul-2001  thorpej bcopy -> memcpy
 1.14 07-Jul-2001  thorpej bcmp -> memcmp
 1.13 15-Apr-2001  ragge Remove some unused variables.
 1.12 12-Apr-2001  thorpej Nuke some unneeded splimp.
 1.11 14-Dec-2000  thorpej branches: 1.11.2;
ALTQ'ify.
 1.10 15-Nov-2000  thorpej Move bpfattach()/bpfdetach() calls into ether_ifattach()/ether_ifdetach().
 1.9 14-Nov-2000  thorpej NBPG -> PAGE_SIZE
 1.8 14-Oct-2000  matt The input packet has the FCS attached to set M_HASFCS before passing up.
Revove eh = ... since it's no longer used.
 1.7 01-Oct-2000  thorpej Move the check for "promisc + unicast + not for us" into ether_input(),
and change Ethernet drivers to always pass all received frames to
ether_input() (with a few exceptions, which are documented in the
code).
 1.6 05-Jun-2000  matt branches: 1.6.2;
Update to new evcnt stuff
 1.5 04-Jun-2000  matt Start couting interrupts.
 1.4 27-May-2000  matt branches: 1.4.2;
Fix counting of output packets. Only count descriptors with TDES_LS set.
Also make transmit timeout logic more correct.
 1.3 20-May-2000  matt count input and output packets.
 1.2 30-Mar-2000  augustss Remove register declarations.
 1.1 08-Aug-1999  ragge branches: 1.1.2;
Driver for the DEC SGEC, Second Generation Ethernet Controller.
 1.1.2.4 21-Apr-2001  bouyer Sync with HEAD
 1.1.2.3 05-Jan-2001  bouyer Sync with HEAD
 1.1.2.2 22-Nov-2000  bouyer Sync with HEAD.
 1.1.2.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.4.2.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.6.2.1 21-Apr-2001  he Apply patch (requested by matt):
Set M_HASFCS on mbuf to indicate that CRC is at the end of the
mbuf.
 1.11.2.5 17-Jan-2003  thorpej Sync with HEAD.
 1.11.2.4 18-Oct-2002  nathanw Catch up to -current.
 1.11.2.3 14-Nov-2001  nathanw Catch up to -current.
 1.11.2.2 24-Aug-2001  nathanw Catch up with -current.
 1.11.2.1 21-Jun-2001  nathanw Catch up to -current.
 1.16.2.3 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.16.2.2 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.16.2.1 03-Aug-2001  lukem update to -current
 1.18.10.1 27-Jan-2003  jmc Pullup revisions 1.19-1.21 (requested by bouyer in ticket #1088)
zero out the remaining of last mbuf when padding the packet to
ETHER_MIN_LEN
XXX should it be ETHER_MIN_LEN-ETHER_CRC_LEN ?
XXX2 we assume there is enouth room in the last mbuf. The code already
assumes this in other places.
Hum, ragge said this chip should autopad, so just remove the check.
 1.22.6.1 24-Jan-2005  he Pull up revision 1.23 (requested by thorpej in ticket #939):
When adding or deleting multicast addresses, only change
the address filter if the interface is marked RUNNING.
Fixes PR#27678.
 1.22.2.3 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.22.2.2 04-Feb-2005  skrll Sync with HEAD.
 1.22.2.1 02-Nov-2004  skrll Sync with HEAD.
 1.23.6.2 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.23.6.1 12-Feb-2005  yamt sync with head.
 1.23.4.1 29-Apr-2005  kent sync with -current
 1.26.4.3 17-Mar-2008  yamt sync with head.
 1.26.4.2 27-Oct-2007  yamt sync with head.
 1.26.4.1 03-Sep-2007  yamt sync with head.
 1.27.26.3 07-May-2007  yamt sync with head.
 1.27.26.2 15-Apr-2007  yamt sync with head.
 1.27.26.1 12-Mar-2007  rmind Sync with HEAD.
 1.27.24.2 07-May-2007  snj Pull up following revision(s) (requested by mhitch in ticket #609):
sys/dev/ic/sgecvar.h: revision 1.7
sys/dev/ic/sgec.c: revision 1.30
Count tx/rx intrs.
Don't set OW in the first transmit descriptor until all descriptors have
been set up. Always try to drain the transmit ring.
 1.27.24.1 07-May-2007  snj Pull up following revision(s) (requested by mhitch in ticket #608):
sys/dev/ic/sgec.c: revision 1.29
Improve the transmit logic. Use bus_dma_load_mbuf on the entire mbuf and
load each segment. in transmit interrupt service, take advatnage on know
how many segments/descriptors are in each packet.
 1.28.4.1 11-Jul-2007  mjf Sync with head.
 1.28.2.3 23-Oct-2007  ad Sync with head.
 1.28.2.2 09-Oct-2007  ad Sync with head.
 1.28.2.1 27-May-2007  ad Sync with head.
 1.30.6.3 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.30.6.2 02-Oct-2007  joerg Sync with HEAD.
 1.30.6.1 03-Sep-2007  jmcneill Sync with HEAD.
 1.30.2.2 10-Sep-2007  skrll Sync with HEAD.
 1.30.2.1 03-Sep-2007  skrll Sync with HEAD.
 1.31.2.2 23-Mar-2008  matt sync with HEAD
 1.31.2.1 06-Nov-2007  matt sync with HEAD
 1.33.4.1 25-Oct-2007  bouyer Sync with HEAD.
 1.34.16.2 17-Jan-2009  mjf Sync with HEAD.
 1.34.16.1 03-Apr-2008  mjf Sync with HEAD.
 1.34.12.1 24-Mar-2008  keiichi sync with head.
 1.35.12.1 19-Jan-2009  skrll Sync with HEAD.
 1.35.10.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.35.4.3 11-Aug-2010  yamt sync with head.
 1.35.4.2 11-Mar-2010  yamt sync with head
 1.35.4.1 04-May-2009  yamt sync with head.
 1.37.4.2 05-Mar-2011  rmind sync with head
 1.37.4.1 30-May-2010  rmind sync with head
 1.37.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.39.22.1 18-May-2014  rmind sync with head
 1.39.18.2 03-Dec-2017  jdolecek update from HEAD
 1.39.18.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.39.8.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.40.6.5 28-Aug-2017  skrll Sync with HEAD
 1.40.6.4 05-Feb-2017  skrll Sync with HEAD
 1.40.6.3 09-Jul-2016  skrll Sync with HEAD
 1.40.6.2 19-Mar-2016  skrll Sync with HEAD
 1.40.6.1 22-Sep-2015  skrll Sync with HEAD
 1.43.2.1 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.46.8.2 28-Jul-2018  pgoyette Sync with HEAD
 1.46.8.1 25-Jun-2018  pgoyette Sync with HEAD
 1.46.2.1 26-Jul-2018  snj Pull up following revision(s) (requested by msaitoh in ticket #938):
sys/arch/acorn32/podulebus/if_ie.c: revision 1.41
sys/arch/amiga/dev/if_es.c: revision 1.58
sys/arch/amiga/dev/if_qn.c: revision 1.45
sys/arch/arm/at91/at91emac.c: revision 1.20
sys/arch/arm/ep93xx/epe.c: revision 1.37
sys/arch/emips/ebus/if_le_ebus.c: revision 1.14
sys/arch/emips/ebus/if_le_ebus.c: revision 1.15
sys/arch/mac68k/dev/if_mc.c: revision 1.46
sys/arch/macppc/dev/am79c950.c: revision 1.39
sys/arch/newsmips/apbus/if_sn.c: revision 1.40
sys/arch/next68k/dev/mb8795.c: revision 1.59
sys/arch/playstation2/dev/if_smap.c: revision 1.25
sys/arch/playstation2/dev/if_smap.c: revision 1.26
sys/arch/sun2/dev/if_ec.c: revision 1.28
sys/arch/sun3/dev/if_ie.c: revision 1.63
sys/arch/x68k/dev/if_ne_intio.c: revision 1.19
sys/arch/xen/xen/if_xennet_xenbus.c: revision 1.75
sys/arch/xen/xen/xennetback_xenbus.c: revision 1.63
sys/dev/bi/if_ni.c: revision 1.45
sys/dev/cadence/if_cemac.c: revision 1.12
sys/dev/ic/am7990.c: revision 1.78
sys/dev/ic/am79900.c: revision 1.27
sys/dev/ic/an.c: revision 1.67
sys/dev/ic/cs89x0.c: revision 1.40
sys/dev/ic/dm9000.c: revision 1.13
sys/dev/ic/dm9000.c: revision 1.14
sys/dev/ic/dp8390.c: revision 1.88
sys/dev/ic/elink3.c: revision 1.141
sys/dev/ic/elinkxl.c: revision 1.122
sys/dev/ic/hme.c: revision 1.98
sys/dev/ic/i82586.c: revision 1.77
sys/dev/ic/lance.c: revision 1.53
sys/dev/ic/mb86950.c: revision 1.27
sys/dev/ic/mb86960.c: revision 1.86
sys/dev/ic/mtd803.c: revision 1.34
sys/dev/ic/pdq_ifsubr.c: revision 1.59
sys/dev/ic/rrunner.c: revision 1.86
sys/dev/ic/seeq8005.c: revision 1.58
sys/dev/ic/sgec.c: revision 1.47
sys/dev/ic/smc90cx6.c: revision 1.72
sys/dev/ic/smc91cxx.c: revision 1.96
sys/dev/ic/tropic.c: revision 1.49
sys/dev/ic/wi.c: revision 1.245
sys/dev/isa/if_eg.c: revision 1.93
sys/dev/isa/if_el.c: revision 1.95
sys/dev/isa/if_iy.c: revision 1.101
sys/dev/ofw/ofnet.c: revision 1.58
sys/dev/pci/if_alc.c: revision 1.27
sys/dev/pci/if_de.c: revision 1.152
sys/dev/pci/if_fpa.c: revision 1.61
sys/dev/pci/if_jme.c: revision 1.34
sys/dev/pci/if_tl.c: revision 1.108
sys/dev/pci/if_vte.c: revision 1.19
sys/dev/pci/ixgbe/ixgbe.h: revision 1.50
sys/dev/pcmcia/if_cnw.c: revision 1.62
sys/dev/pcmcia/if_malo_pcmcia.c: revision 1.17
sys/dev/pcmcia/if_ray.c: revision 1.89
sys/dev/pcmcia/if_xi.c: revision 1.81
sys/dev/pcmcia/mhzc.c: revision 1.51
sys/dev/pcmcia/xirc.c: revision 1.34
sys/dev/qbus/if_de.c: revision 1.33
sys/dev/qbus/if_qe.c: revision 1.78
sys/dev/qbus/if_qt.c: revision 1.22
sys/dev/sbus/be.c: revision 1.87
sys/dev/sbus/qe.c: revision 1.68
sys/dev/scsipi/if_se.c: revision 1.96
sys/dev/usb/if_atu.c: revision 1.59
sys/net/if_l2tp.c: revision 1.28 via patch
sys/net/if_ppp.c: revision 1.160
It's not required to include net/bpfdesc.h. Remove it.
--
Simplify like other drivers. NULL check of ifp->if_bpf is done in
bpf_mtap(), so it's not required to do it here.
--
Remove duplicated inclusion of net/bpf.h.
--
Remove duplicated inclusion of net/bpf.h.
--
Simplify bpf_mtap() call. No functional change.
 1.48.2.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.48.2.1 10-Jun-2019  christos Sync with HEAD
 1.51.4.1 29-Feb-2020  ad Sync with head.
 1.4 11-Dec-2005  christos merge ktrace-lwp.
 1.3 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22364, verified by myself.
 1.2 06-Jan-2003  matt branches: 1.2.2;
Add multiple inclusion protection.
 1.1 08-Aug-1999  ragge branches: 1.1.14;
Driver for the DEC SGEC, Second Generation Ethernet Controller.
 1.1.14.1 07-Jan-2003  thorpej Sync with HEAD.
 1.2.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.2.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.2.2.1 03-Aug-2004  skrll Sync with HEAD
 1.9 22-May-2017  ragge Update copyright notice for Ludd (remove clause 3 & 4).
 1.8 11-Mar-2008  matt branches: 1.8.48; 1.8.68;
Rototill the vax code. Switch to devicet/PRIV_ALLOC. Cleanup vax autoconf
code. Move to prototype definitions. staticfy, constify, avoid casting.
Use device_* accessors.
 1.7 26-Apr-2007  matt branches: 1.7.8; 1.7.24; 1.7.28;
Count tx/rx intrs.
Don't set OW in the first transmit descriptor until all descriptors have
been set up. Always try to drain the transmit ring.
 1.6 11-Dec-2005  christos branches: 1.6.24; 1.6.26; 1.6.30; 1.6.32;
merge ktrace-lwp.
 1.5 27-Feb-2005  perry branches: 1.5.4;
nuke trailing whitespace
 1.4 04-Feb-2005  perry de-__P
 1.3 06-Jan-2003  matt branches: 1.3.2; 1.3.10; 1.3.12;
Add multiple inclusion protection.
 1.2 04-Jun-2000  matt branches: 1.2.4;
Start couting interrupts.
 1.1 08-Aug-1999  ragge branches: 1.1.2; 1.1.10;
Driver for the DEC SGEC, Second Generation Ethernet Controller.
 1.1.10.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.1.2.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.2.4.1 07-Jan-2003  thorpej Sync with HEAD.
 1.3.12.2 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.3.12.1 12-Feb-2005  yamt sync with head.
 1.3.10.1 29-Apr-2005  kent sync with -current
 1.3.2.2 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.3.2.1 04-Feb-2005  skrll Sync with HEAD.
 1.5.4.2 17-Mar-2008  yamt sync with head.
 1.5.4.1 03-Sep-2007  yamt sync with head.
 1.6.32.1 11-Jul-2007  mjf Sync with head.
 1.6.30.1 27-May-2007  ad Sync with head.
 1.6.26.1 07-May-2007  yamt sync with head.
 1.6.24.1 07-May-2007  snj Pull up following revision(s) (requested by mhitch in ticket #609):
sys/dev/ic/sgecvar.h: revision 1.7
sys/dev/ic/sgec.c: revision 1.30
Count tx/rx intrs.
Don't set OW in the first transmit descriptor until all descriptors have
been set up. Always try to drain the transmit ring.
 1.7.28.1 03-Apr-2008  mjf Sync with HEAD.
 1.7.24.1 24-Mar-2008  keiichi sync with head.
 1.7.8.1 23-Mar-2008  matt sync with HEAD
 1.8.68.1 28-Aug-2017  skrll Sync with HEAD
 1.8.48.1 03-Dec-2017  jdolecek update from HEAD
 1.6 19-Oct-2009  rmind Drop 3rd and 4th clauses from David Young's license.
Reviewed and approved by dyoung@ (copyright holder).
 1.5 31-Aug-2006  dyoung branches: 1.5.56;
Per discussion on tech-kern and tech-userlevel, move the bit-twiddling
macros, __BIT, __BITS, SHIFTIN, SHIFTOUT, and __arraycount() from
lib/libkern/libkern.h to sys/cdefs.h. Add a __-prefix to SHIFTIN
and SHIFTOUT, and add a manual page for the bit-twiddling macros,
bits(3).

Make the __BIT and __BITS macros "widthless," as best I can, by
changing their type to uintmax_t from uint32_t. XXX The manual
page lags this change by a bit.

Define __PRIxBIT and __PRIxBITS printf(3) format strings.
 1.4 08-Mar-2006  dyoung Change macro names to avoid collisions:

BIT -> __BIT
BITS -> __BITS
 1.3 08-Mar-2006  dyoung Move my bit-twiddling macros to libkern.h from my drivers, where
I had duplicated them. Improve the macros' names. Simplify their
implementation.

A brief description of each macro is below.

BIT(n): Return a bitmask with bit m set, where the least
significant bit is bit 0.

BITS(m, n): Return a bitmask with bits m through n, inclusive,
set. It does not matter whether m>n or m<=n.
The least significant bit is bit 0.

A "bitfield" is a span of consecutive bits defined by a
bitmask, where 1s select the bits in the bitfield. SHIFTIN,
SHIFTOUT, and SHIFTOUT_MASK help read and write bitfields
from device registers.

SHIFTIN(v, mask): Left-shift bits `v' into the bitfield
defined by `mask', and return them. No
side-effects.

SHIFTOUT(v, mask): Extract and return the bitfield selected
by `mask' from `v', right-shifting the
bits so that the rightmost selected bit
is at bit 0. No side-effects.

SHIFTOUT_MASK(mask): Right-shift the bits in `mask' so that
the rightmost non-zero bit is at bit
0. This is useful for finding the
greatest unsigned value that a bitfield
can hold. No side-effects. Note that
SHIFTOUT_MASK(m) = SHIFTOUT(m, m).

Examples:

/*
* Register definitions taken from the RFMD RF3000 manual.
*/
#define RF3000_GAINCTL 0x11 /* TX variable gain control */
#define RF3000_GAINCTL_TXVGC_MASK BITS(7, 2)
#define RF3000_GAINCTL_SCRAMBLER BIT(1)

/*
* Shift the transmit power into the transmit-power field of the
* gain-control register and write it to the baseband processor.
*/
atw_rf3000_write(sc, RF3000_GAINCTL,
SHIFTIN(txpower, RF3000_GAINCTL_TXVGC_MASK));


/*
* Register definitions taken from the ADMtek ADM8211 manual.
*
*/
#define ATW_RXSTAT_OWN BIT(31) /* 1: NIC may fill descriptor */
/* ... */
#define ATW_RXSTAT_DA1 BIT(17) /* DA bit 1, admin'd address */
#define ATW_RXSTAT_DA0 BIT(16) /* DA bit 0, group address */
#define ATW_RXSTAT_RXDR_MASK BITS(15,12) /* RX data rate */
#define ATW_RXSTAT_FL_MASK BITS(11,0) /* RX frame length, last
* descriptor only
*/

/* Extract the frame length from the Rx descriptor's
* status field.
*/
len = SHIFTOUT(rxstat, ATW_RXSTAT_FL_MASK);
 1.2 11-Dec-2005  christos branches: 1.2.4; 1.2.6; 1.2.8; 1.2.10;
merge ktrace-lwp.
 1.1 17-Feb-2004  dyoung branches: 1.1.4; 1.1.18;
Move the RF Microdevices RF3000 & Silicon Laboratories SI4126/SI4136
register sets into their own header files for re-use by future
drivers.
 1.1.18.2 30-Dec-2006  yamt sync with head.
 1.1.18.1 21-Jun-2006  yamt sync with head.
 1.1.4.4 21-Sep-2004  skrll Fix the sync with head I botched.
 1.1.4.3 18-Sep-2004  skrll Sync with HEAD.
 1.1.4.2 03-Aug-2004  skrll Sync with HEAD
 1.1.4.1 17-Feb-2004  skrll file si4136reg.h was added on branch ktrace-lwp on 2004-08-03 10:46:18 +0000
 1.2.10.1 19-Apr-2006  elad sync with head.
 1.2.8.2 03-Sep-2006  yamt sync with head.
 1.2.8.1 13-Mar-2006  yamt sync with head.
 1.2.6.1 22-Apr-2006  simonb Sync with head.
 1.2.4.1 09-Sep-2006  rpaulo sync with head
 1.5.56.1 11-Mar-2010  yamt sync with head
 1.1 13-Jan-2013  jakllsch branches: 1.1.2; 1.1.6;
Add slurm(4), a radio(4) driver for USB FM radio modules based on the
Silicon Labs reference design.
 1.1.6.2 25-Feb-2013  tls resync with head
 1.1.6.1 13-Jan-2013  tls file si470x_reg.h was added on branch tls-maxphys on 2013-02-25 00:29:15 +0000
 1.1.2.2 23-Jan-2013  yamt sync with head
 1.1.2.1 13-Jan-2013  yamt file si470x_reg.h was added on branch yamt-pagecache on 2013-01-23 00:06:06 +0000
 1.51 02-Feb-2024  andvar fix various typos in comments.
 1.50 10-Nov-2021  msaitoh s/endianess/endianness/
 1.49 05-Oct-2021  rin PR kern/56403

Fix kernel freeze for wdc(4) variants with ATAC_CAP_NOIRQ:

(1) Change ata_xfer_ops:c_poll from void to int function. When it returns
ATAPOLL_AGAIN, let ata_xfer_start() iterate itself again.

(2) Let wdc_ata_bio_poll() return ATAPOLL_AGAIN until ATA_ITSDONE is
achieved.

A similar change has been made for mvsata(4) (see mvsata_bio_poll()),
and no functional changes for other devices.

This is how the drivers worked before jdolecek-ncq branch was merged.

Note that this changes are less likely to cause infinite recursion:

(1) wdc_ata_bio_intr() called from wdc_ata_bio_poll() asserts ATA_ITSDONE
in its error handling paths via wdc_ata_bio_done().

(2) Return value from c_start (= wdc_ata_bio_start()) is checked in
ata_xfer_start().

Therefore, errors encountered in ata_xfer_ops:c_poll and c_start routines
terminate the recursion for wdc(4). The situation is similar for mvsata(4).

Still, there is a possibility where ata_xfer_start() takes long time to
finish a normal operation. This can result in a delayed response for lower
priority interrupts. But, I've never observed such a situation, even when
heavy thrashing takes place for swap partition in wd(4).

"Go ahead" by jdolecek@.
 1.48 07-Aug-2021  thorpej Merge thorpej-cfargs2.
 1.47 24-Apr-2021  thorpej branches: 1.47.8;
Merge thorpej-cfargs branch:

Simplify and make extensible the config_search() / config_found() /
config_attach() interfaces: rather than having different variants for
which arguments you want pass along, just have a single call that
takes a variadic list of tag-value arguments.

Adjust all call sites:
- Simplify wherever possible; don't pass along arguments that aren't
actually needed.
- Don't be explicit about what interface attribute is attaching if
the device only has one. (More simplification.)
- Add a config_probe() function to be used in indirect configuiration
situations, making is visibly easier to see when indirect config is
in play, and allowing for future change in semantics. (As of now,
this is just a wrapper around config_match(), but that is an
implementation detail.)

Remove unnecessary or redundant interface attributes where they're not
needed.

There are currently 5 "cfargs" defined:
- CFARG_SUBMATCH (submatch function for direct config)
- CFARG_SEARCH (search function for indirect config)
- CFARG_IATTR (interface attribte)
- CFARG_LOCATORS (locators array)
- CFARG_DEVHANDLE (devhandle_t - wraps OFW, ACPI, etc. handles)

...and a sentinel value CFARG_EOL.

Add some extra sanity checking to ensure that interface attributes
aren't ambiguous.

Use CFARG_DEVHANDLE in MI FDT, OFW, and ACPI code, and macppc and shark
ports to associate those device handles with device_t instance. This
will trickle trough to more places over time (need back-end for pre-OFW
Sun OBP; any others?).
 1.46 11-Jan-2021  skrll branches: 1.46.2;
KNF
 1.45 11-Jan-2021  skrll Trailing whitespace
 1.44 25-Dec-2020  skrll Use designated initializers for struct ata_bustype
 1.43 10-Oct-2020  thorpej branches: 1.43.2;
In siisata_intr_port(), skip reading the error condition if
ata_queue_get_active_xfer() returns NULL.

PR kern/55682. Fix suggested by mlelstv@.
 1.42 13-Apr-2020  jdolecek fix use-after-free for ata xfer on bio submission found by KASAN

driver ata_bio hooks read parts of the xfer after ata_exec_xfer()
call in order to determine return value, change so that the hook
doesn't return any value - callers do not care already,
as all I/O requests are asynchronous

this problem was uncovered by recent change for wd(4) to not hold
wd mutex during ata_bio call, the interrupt for the xfer might
thus actually fire immediately

adjust also ata_exec_command driver hooks similarily - remove all
completion and waiting logic from drivers, upper layer ata code
using AT_WAIT/AT_POLL changed to call ata_wait_cmd() itself

PR kern/55169 by Nick Hudson
 1.41 19-Feb-2020  riastradh branches: 1.41.4;
C99 initializers for scsipi_bustype. No functional change intended.
 1.40 10-Nov-2019  chs branches: 1.40.2;
in many device attach paths, allocate memory with M_WAITOK instead of M_NOWAIT
and remove code to handle failures that can no longer happen.
 1.39 19-Nov-2018  jdolecek branches: 1.39.4;
consistently use the SATA correct 'port %d' instead of 'channel', some
whitespace fixes
 1.38 24-Oct-2018  jdolecek need now channel lock around siisata_device_reset() executed for fatal error
 1.37 24-Oct-2018  jdolecek detach the controller itself on shutdown; adjust to not detach already
detached atabus/channel
 1.36 22-Oct-2018  jdolecek Merge jdolecek-ncqfixes branch

- ata_xfer's are dynamicall allocated as needed using a pool, no longer
limited to number of possible openings supported by controller; dump
and recovery paths use dedicated pre-allocated storage
- moved callouts and condvars from ata_xfer to queue or channel, so that
ata_xfer does not need special initialization
- slot allocation now done when xfer is being activated, uncoupled
from memory allocation; active slots are no longer tracked by controller
code
- channel and drive reset is done always via the atabus thread, and
now executes with channel locked the whole time
- NCQ recovery moved to shared function, and run via the thread also
- added some workarounds for buggy error recovery AHCI emulation in QEMU
and Parallels

designed to primarily fix kern/52614, but might also help with kern/47041
and kern/53183
 1.35 20-Oct-2017  jdolecek branches: 1.35.2; 1.35.4; 1.35.6;
move ata_queue_alloc(1) and ata_queue_free() calls to ata_channel_init()
and ata_channel_destroy() respectively, to make attachment code simpler,
and to make it easier to spot special queue manipulation like cmdide(4)

on topic of PR kern/52606
 1.34 07-Oct-2017  jdolecek Merge support for SATA NCQ (Native Command Queueing) from jdolecek-ncq branch

ATA subsystem was changed to support several outstanding commands, and use
NCQ xfers if supported by both the controller and the disk, including NCQ
error recovery. Set NCQ high priority for BPRIO_TIMECRITICAL xfers
if supported. Added FUA support.

Done some work towards MP-safe, all ATA code tsleep()/wakeup() replaced
by condvars, and switched most code from spl* to mutexes (separate
wd(4) and ata channel lock).

Introduced new option WD_CHAOS_MONKEY to facilitate testing of error
handling, fixed several uncovered issues. Also fixed several problems
with kernel dump to wd(4) disk.

Tested with ahcisata(4), mvsata(4), siisata(4), piixide(4) on amd64,
with and without port multiplier, both disk and ATAPI devices; other
drivers and archs mechanically adjusted and compile-tested. NCQ is
supported for ahcisata(4) and siisata(4) for any controller, for
mvsata(4) only Gen IIe ones for now. Also enabled ATAPI support in
mvsata(4).

Thanks to Matt Thomas for initial ATA infrastructure patch, and
Jonathan A.Kollasch for siisata(4) NCQ changes and general testing.

Also fixes PR kern/43169 (wd(4)); and PR kern/11811, PR kern/47041,
PR kern/51979 (kernel dump)
 1.33 24-Apr-2017  jakllsch Fix PRB blanking, so as not to stomp on the feet of neighboring slots.
Also, don't blank some PRB fields twice.

[:U+1F633:]
 1.32 24-Apr-2017  jakllsch Fix typo in comment.
 1.31 24-Apr-2017  jakllsch Drop unused prototype. Whitespace fixes. Wrap/re-wrap long lines.
 1.30 03-Jan-2017  jakllsch branches: 1.30.4;
The SiI3124 was implemented at a time when the ATA/ACS2
DATA SET MANAGEMENT/TRIM command did not exist. As such, the (presumably
immutable) lookup table in the chip does not know that this command
indicates a data write to follow. Use the PRB Protocol Override
functionality to tell the chip the protocol we need for this command.

For PR kern/51756.
 1.29 19-Sep-2016  jakllsch Don't permanantly disable port if drive probe times out,
reinitialize port instead.
 1.28 02-May-2016  christos branches: 1.28.2;
move scsipi_strvis -> libkern:strnvisx()
change the prototype to match userland
fix sizes of strings passed to it
 1.27 08-Aug-2013  bouyer branches: 1.27.6;
Fix reverted condition. Fix panic reported by Patrick Welche on
current-users with an ATAPI device connected to siisata.
 1.26 22-Jun-2013  matt branches: 1.26.2;
Make sure dynamically allocated channel_queue struct are zero-filled.
 1.25 09-Jun-2013  njoly Add missing parenthesis.
 1.24 03-Apr-2013  bouyer Fix kernel dump on ahci controller, by making sure we won't sleep
while dumping:
- introduce ata_delay() which either use delay() or kpause()
depending on flags. use it in sata_reset_interface() and
some ahci functions
- kill ATA_NOSLEEP, it was tested but never set. use ATA_POLL instead.
- reduce delay while polling in ahci, to speed up the dump

Should fix PR kern/41095
 1.23 22-Oct-2012  jakllsch Work around missing __BUS_SPACE_HAS_STREAM_METHODS on some ports.
 1.22 31-Jul-2012  bouyer branches: 1.22.2;
Apply back changes that were reverted on Jul 24 and Jul 26 (general ata/wdc
cleanup and SATA PMP support), now that I'm back to fix the fallouts.
 1.21 26-Jul-2012  jakllsch Revert, with intention of restoring in a less invasive way, the SATA Port
Multiplier code.

ok christos@
 1.20 24-Jul-2012  jakllsch Revert dsl@'s changes of Sun, 15 Jul 2012 10:55:35 +0000 and
Sun, 15 Jul 2012 10:56:50 +0000, excepting the kernel version bump.
First step in reverting regressions to ata(4) subsystem during the addition of
port multiplier support.
 1.19 15-Jul-2012  dsl Some namespace protection (and add greppablity).
Prefix the DRIVE_ and DRIVET_ constants from atavar.h with ATA_.
Don't use an enum for drive_type - you don't know how big it will be.
Move driver_type to avoid implicit structure padding (esp on arm).
This change is purely lexical and mechanical.

Update to 6.99.9 - this wasn't done when the SATA PMP changes
were made - I'm sure they warranted a bump.
 1.18 02-Jul-2012  bouyer Add sata Port MultiPlier (PMP) support to the ata bus layer,
as described in
http://mail-index.netbsd.org/tech-kern/2012/06/23/msg013442.html
PMP support in integrated to the atabus layer.
struct ata_channel's ch_drive[] is not dynamically allocated, and ch_ndrive
(renamed to ch_ndrives) closely reflects the size of the ch_drive[] array.
Add helper functions atabus_alloc_drives() and atabus_free_drives()
to manage ch_drive[]/ch_ndrives.
Add wdc_maxdrives to struct wdc_softc so that bus front-end can specify
how much drive they really support (master/slave or single).
ata_reset_drive() callback gains a uint32_t *sigp argument which,
when not NULL, will contain the signature of the device being reset.
While there, some cosmetic changes:
- added a drive_type enum to ata_drive_datas, and stop encoding the
probed drive type in drive_flags (we were out of drive flags anyway).
- rename DRIVE_ATAPIST to DRIVE_ATAPIDSCW to better reflect what this
really is
- remove ata_channel->ata_drives, it's redundant with the pointer in
ata_drive_datas
- factor out the interpretation of SATA signatures in sata_interpet_sig()

propagate these changes to the ATA HBA drivers, and add support for PMP
to ahcisata(4) and siisata(4).

Thanks to:
- Protocase (http://www.protocase.com/) which provided a system
with lots of controllers, SATA PMP and drive slots
- Conservation Genomics Laboratory, Department of Biology, New Mexico State
University for hosting the above system
- Brook Milligan, who set up remote access and has been very responsive
when SATA cable move was needed
 1.17 15-May-2012  bouyer Gather disable/enable interruptst at the Port Interrupt Enable level in
2 functions, and use them to disable interrupts for polled commands.
In siisata_probe_drive(), disable interrupt while resetting the PHY and
sending the SOFT_RESET FIS. Also dectect timeout/errors at this level and
disable the port if needed.
Make siisata_intr_port() more resistent to interrupts without xfer (especially
error interrupts which can be asynchrounous, but can also happen for
timed out xfer).

With this, the kernel doesn't pannic when a siisata controller is connected
to a SATA port multiplier. More work is needed to support port multiplier
though.
 1.16 20-Apr-2012  bouyer Add a bustype_async_event_xfer_mode() callback to scsipi_bustype (which can
be NULL), so that transport-specific details of transfer mode setting/printing
can be handled more easily.
Move scsipi_async_event_xfer_mode() and scsipi_print_xfer_mode() to
scsi_base.c and split in parallel scsi and FC/SAS parts.
size of struct scsipi_bustype has changed, welcome to 6.99.5
 1.15 27-Sep-2011  jym branches: 1.15.2; 1.15.6;
Modify *ASSERTMSG() so they are now used as variadic macros. The main goal
is to provide routines that do as KASSERT(9) says: append a message
to the panic format string when the assertion triggers, with optional
arguments.

Fix call sites to reflect the new definition.

Discussed on tech-kern@. See
http://mail-index.netbsd.org/tech-kern/2011/09/07/msg011427.html
 1.14 13-Feb-2011  jakllsch Treat unexpected command completions a little more like regular completions.
Slight chance this might prevent some occasional log spew trouble at shutdown
time.
 1.13 13-Nov-2010  uebayasi branches: 1.13.2; 1.13.4;
Include sys/proc.h for tsleep, wakeup.
 1.12 26-Jul-2010  jakllsch Store information for bus_dmamem_unmap() and bus_dmamem_free()
somewhere outside the bus_dmamap_t. The bus_dmamap_t has already
been destroyed by this time.

Fixes DMA memory leak at siisata_detach() time.
 1.11 25-Apr-2010  rmind Fix KASSERTMSG() to be consistent with KASSERT() logic, not inverted.
Hi matt@!
 1.10 07-Apr-2010  jakllsch satafis:
- Add function to parse RDH FIS for use in implementing AT_READREG.
- Correct and clean up some structure definitions.
- Sprinkle a bit of const.
- Remove dependency on <dev/ic/wdcreg.h>, WDCTL_4BIT doesn't seem
to be specified by any recent ATA standard, and it seems to make
no difference in practice.
- Stop using WDSD_IBM, these bits have been obsolete since before SATA.

siisata:
- Implement AT_READREG.
- Reap now-unneeded <dev/ic/wdcreg.h>.
- Whitespace and slight debug code cleanup.
- Some possibly-uncessary code reordering.

ahcisata:
- Implement AT_READREG.
- Reap now-unneeded <dev/ic/wdcreg.h>.
 1.9 30-Jan-2010  jakllsch branches: 1.9.2; 1.9.4;
Sprinkle __KERNEL_RCSID() into siisata(4).
Slightly adjust some comment styling.
 1.8 19-Oct-2009  bouyer Remove closes 3 & 4 from my licence. Lots of thanks to Soren Jacobsen
for the booring work !
 1.7 04-Jul-2009  jakllsch Further corrections for siisata.

Reset ch_status and ch_error at the beginning of any operation.

The chip only writes the RDH FIS to the SRAM when the error bit is
set in a RDH FIS (per the datasheet). Thus, satafis_sdb_parse() is
replaced with satafis_rhd_parse(). A valid FIS type field seems to
not be written to the SRAM, so don't bother checking it for the
correct magic.

Additionally, append 2009 to copyright year set, and remove
obsolete CVS Id lines from when this was in my repository.
 1.6 27-Jun-2009  jakllsch Correct various siisata bugs, some old, some new.

- Move clearing of interrupts to before atastart() is called in the
xfer interrupt handler. Should fix kern/41579.
- Using cv_timedwait(9) is not possible in code that can be called from
interrupt context, fall back to DELAY(9).
- Correctly poll Port Slot Status register for soft reset PRBs.
- Only use the Recive Transfer Count register on reads, when it is valid.
- Activate PRBs in a way that takes the whole physical address into account,
even when the PRB is beyond 4GiB.
- consistently use DELAY(9)
- Use DELAY() constants in completion polling loops that are consistent with
the loop count limit. (i.e. timeout in 10 rather than 100 seconds)
 1.5 21-Jun-2009  jakllsch Use PRO_PS and PRO_PCS correctly.
From Wolfgang Stukenbrock as part of kern/41579.

While here, remove a line of whitespace, and add an else case to
the ATAPI command length toggle.
 1.4 17-Jun-2009  cegger make this build w/o SIISATA_DEBUG
 1.3 17-Jun-2009  jakllsch A few changes for siisata(4):

- Support detachment. From KIYOHARA Takashi.
- Add PCI detachment functionality (albeit not very interesting when
the bus can not yet be rescanned).
- Rework interrupt handlers to reduce near-duplicate code.
Borrowed from ahcisata(4).
- Attempt to make polled I/O work. Untested.
- Fix formatting of some messages.
- For always-polled commands, disable interrupt
at slot level rather than port level.
- Instead of busy-waiting indefinitely for completion of some commands
move on after 31 seconds. Use cv_timedwait(9) instead of DELAY(9).
- Use abstracted SATA FIS code.
- Enable use of disks that don't respond with the standard signature.
 1.2 14-Sep-2008  jakllsch branches: 1.2.4; 1.2.8; 1.2.12; 1.2.14;
A few cleanups for siisata(4)

No functional changes intended (except maybe un-reseting the chip a bit later
in attach).

- pass fewer arguments to local functions where arguments can be derived from
an existing argument
- some coding style fixes
- more abstraction for PRB activation and deactivation
- bus_dma(9) properification in error cases
- undefine SIISATA_DEBUG, and cleanup variables used only for DEBUG_PRINT()s
 1.1 23-May-2008  jnemeth branches: 1.1.2; 1.1.4; 1.1.8; 1.1.10;
Import siisata(4) by Jonathan A. Kollasch.

The siisata driver supports the Silicon Image SteelVine family of SATA-II
controllers, interfacing the hardware with the ata(4) and atapi(4) sub-
systems.

The following controllers are supported by the siisata driver:

Silicon Image SiI3124 4-port PCI/PCI-X
Silicon Image SiI3132 2-port PCI-Express x1
Silicon Image SiI3531 1-port PCI-Express x1

SATA Native Command Queueing is not yet supported.
Device hot swapping is not yet supported.
Silicon Image's Software RAID is not yet supported by the
ataraid(4) driver.

Approved by: core (christos), releng (bouyer)
 1.1.10.1 19-Oct-2008  haad Sync with HEAD.
 1.1.8.3 24-Sep-2008  wrstuden Merge in changes between wrstuden-revivesa-base-2 and
wrstuden-revivesa-base-3.
 1.1.8.2 23-Jun-2008  wrstuden Add files to branch that were added on -current.

After this, all that's left of update is to merge some changes
that had conflicts.
 1.1.8.1 23-May-2008  wrstuden file siisata.c was added on branch wrstuden-revivesa on 2008-06-23 05:02:13 +0000
 1.1.4.2 04-Jun-2008  yamt sync with head
 1.1.4.1 23-May-2008  yamt file siisata.c was added on branch yamt-pf42 on 2008-06-04 02:05:10 +0000
 1.1.2.3 28-Sep-2008  mjf Sync with HEAD.
 1.1.2.2 02-Jun-2008  mjf Sync with HEAD.
 1.1.2.1 23-May-2008  mjf file siisata.c was added on branch mjf-devfs2 on 2008-06-02 13:23:27 +0000
 1.2.14.3 14-Feb-2014  matt Change KASSERTMSG/KDASSERTMSG to use varadic arguments like HEAD.
panic -> vpanic, add panic wrapper to vpanic.
 1.2.14.2 29-Apr-2011  matt Fix sense of KASSERTMSGs
 1.2.14.1 21-Apr-2010  matt sync to netbsd-5
 1.2.12.6 11-Aug-2010  yamt sync with head.
 1.2.12.5 11-Mar-2010  yamt sync with head
 1.2.12.4 18-Jul-2009  yamt sync with head.
 1.2.12.3 20-Jun-2009  yamt sync with head
 1.2.12.2 04-May-2009  yamt sync with head.
 1.2.12.1 14-Sep-2008  yamt file siisata.c was added on branch yamt-nfs-mp on 2009-05-04 08:12:44 +0000
 1.2.8.1 23-Jul-2009  jym Sync with HEAD.
 1.2.4.5 28-Sep-2009  snj Pull up following revision(s) (requested by jakllsch in ticket #1023):
sys/dev/ata/satafis_subr.c: revision 1.3
sys/dev/ata/satafisvar.h: revision 1.2
sys/dev/ic/siisata.c: revision 1.7
sys/dev/ic/siisatareg.h: revision 1.4
Further corrections for siisata.
Reset ch_status and ch_error at the beginning of any operation.
The chip only writes the RDH FIS to the SRAM when the error bit is
set in a RDH FIS (per the datasheet). Thus, satafis_sdb_parse() is
replaced with satafis_rhd_parse(). A valid FIS type field seems to
not be written to the SRAM, so don't bother checking it for the
correct magic.
Additionally, append 2009 to copyright year set, and remove
obsolete CVS Id lines from when this was in my repository.
 1.2.4.4 28-Sep-2009  snj Pull up following revision(s) (requested by jakllsch in ticket #1023):
sys/dev/ic/siisata.c: revision 1.6
Correct various siisata bugs, some old, some new.
- Move clearing of interrupts to before atastart() is called in the
xfer interrupt handler. Should fix kern/41579.
- Using cv_timedwait(9) is not possible in code that can be called from
interrupt context, fall back to DELAY(9).
- Correctly poll Port Slot Status register for soft reset PRBs.
- Only use the Recive Transfer Count register on reads, when it is valid.
- Activate PRBs in a way that takes the whole physical address into account,
even when the PRB is beyond 4GiB.
- consistently use DELAY(9)
- Use DELAY() constants in completion polling loops that are consistent with
the loop count limit. (i.e. timeout in 10 rather than 100 seconds)
 1.2.4.3 28-Sep-2009  snj Pull up following revision(s) (requested by jakllsch in ticket #1023):
sys/dev/ic/siisata.c: revision 1.5
Use PRO_PS and PRO_PCS correctly.
From Wolfgang Stukenbrock as part of kern/41579.
While here, remove a line of whitespace, and add an else case to
the ATAPI command length toggle.
 1.2.4.2 28-Sep-2009  snj Pull up following revision(s) (requested by jakllsch in ticket #1023):
sys/dev/ic/siisata.c: revision 1.4
make this build w/o SIISATA_DEBUG
 1.2.4.1 28-Sep-2009  snj Pull up following revision(s) (requested by jakllsch in ticket #1023):
sys/dev/ic/siisata.c: revision 1.3
sys/dev/ic/siisatareg.h: revision 1.3
sys/dev/ic/siisatavar.h: revision 1.3
sys/dev/pci/files.pci: revision 1.315
sys/dev/pci/siisata_pci.c: revision 1.3
A few changes for siisata(4):
- Support detachment. From KIYOHARA Takashi.
- Add PCI detachment functionality (albeit not very interesting when
the bus can not yet be rescanned).
- Rework interrupt handlers to reduce near-duplicate code.
Borrowed from ahcisata(4).
- Attempt to make polled I/O work. Untested.
- Fix formatting of some messages.
- For always-polled commands, disable interrupt
at slot level rather than port level.
- Instead of busy-waiting indefinitely for completion of some commands
move on after 31 seconds. Use cv_timedwait(9) instead of DELAY(9).
- Use abstracted SATA FIS code.
- Enable use of disks that don't respond with the standard signature.
 1.9.4.2 05-Mar-2011  rmind sync with head
 1.9.4.1 30-May-2010  rmind sync with head
 1.9.2.2 17-Aug-2010  uebayasi Sync with HEAD.
 1.9.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.13.4.1 17-Feb-2011  bouyer Sync with HEAD
 1.13.2.1 06-Jun-2011  jruoho Sync with HEAD.
 1.15.6.2 02-Jun-2012  mrg sync to latest -current.
 1.15.6.1 29-Apr-2012  mrg sync to latest -current.
 1.15.2.3 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.15.2.2 30-Oct-2012  yamt sync with head
 1.15.2.1 23-May-2012  yamt sync with head.
 1.22.2.4 03-Dec-2017  jdolecek update from HEAD
 1.22.2.3 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.22.2.2 23-Jun-2013  tls resync from head
 1.22.2.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.26.2.1 28-Aug-2013  rmind sync with head
 1.27.6.4 28-Aug-2017  skrll Sync with HEAD
 1.27.6.3 05-Feb-2017  skrll Sync with HEAD
 1.27.6.2 05-Oct-2016  skrll Sync with HEAD
 1.27.6.1 29-May-2016  skrll Sync with HEAD
 1.28.2.3 26-Apr-2017  pgoyette Sync with HEAD
 1.28.2.2 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.28.2.1 04-Nov-2016  pgoyette Sync with HEAD
 1.30.4.38 19-Sep-2017  jdolecek replace all remaining tsleep()/wakeup() calls with condition variables, or
calls to ata_delay(), as appropriate; change ata_delay() to require the
channel lock on entry, and pass the lock to kpause() for unlocking while
sleeping
 1.30.4.37 10-Sep-2017  jdolecek refactor code so that xfer c_start() hook is called with channel mutex held,
and hence the controller submit code no longer relies on spl

tested all the affected drivers - wdc (via piixide), ahci, mvsata, siisata,
both disk and atapi I/O
 1.30.4.36 15-Aug-2017  jakllsch Use ata_queue_free() instead of free() to deallocate chp->ch_queue during detach.
 1.30.4.35 12-Aug-2017  jdolecek do not reset drive after successful NCQ error recovery
 1.30.4.34 11-Aug-2017  jdolecek replace magic 3100 with locall defined WDC_RESET_WAIT
 1.30.4.33 04-Aug-2017  jdolecek prb_control need to add (or) PRB_CF_INTERRUPT_MASK for polled commands,
rather that set - the field may be nonzero for ATAPI or for protocol override
 1.30.4.32 04-Aug-2017  jdolecek restore part of what was removed in 1.30.4.30 - the success of command
needs to be driven by PSS so that it works also for polled commands, apparently
PR_PIS_CMDCMPL is not set in that case; now do error handling again only when
PSS_ATTENTION is set

this fixes timeout for polled commands like standby on shutdown,
and (ehm ehm), READ LOG EXT on NCQ error recovery
 1.30.4.31 01-Aug-2017  jdolecek fix logic bug in processing of finished commands - mask of active
commands can change during the loop as c_intr() callback can queue
new commands, so the interrupt routine should only mark as finished
those which were actually active before the loop started; otherwise
the code marked as finished commands which were just started, and
being executed by HBA, leading to all sorts of data corruption

while here mark the active mask volatile, as it is modified from
interrupt context

this fixes for good the random crashes, short reads, and fatal command
errors which I've been tracing down for past couple weeks

thanks to Jonathan (jakllsch@) for testing, and a script to easily
triggered the condition, and led to this bug being finally found and squashed
 1.30.4.30 01-Aug-2017  jdolecek adjust code to be closer to HEAD to it's easier to compare and find
regressions, undoing some changes which were actually not necessary
 1.30.4.29 30-Jul-2017  jdolecek undo debug code
 1.30.4.28 30-Jul-2017  jdolecek adjust error recovery to similar shape as ahcisata; also switch to using
siisata_reset_channel(), as that seems more reliably get the HBA to running
state again after some errors

besides this, change several places checking PORT_READY to use
siisata_reinit_port() and properly timeout - seen several cases
where it would just loop there indefinitely on some errors with no
way to get into ddb and no error message, due to the tight DELAY() loop
 1.30.4.27 19-Jul-2017  jdolecek forced commit to get into history - previous commit removed also
the siisata-specific downgrade of SATA channel speed on CRC, as it
doesn't really fit with error/state not being available after
c_intr(); as noted this handling should be in generic code, and
it's overly harsh to do this after single error anyway, particularly
since there is no way to get back
 1.30.4.26 19-Jul-2017  jdolecek convert over to new error handling world order:
- switch to ata_timeout()
- stop using ch_status/ch_error for passing state/error, stop setting
ATACH_IRQ_WAIT in ch_flags; pass the state via the last parameter
to c_intr() routine
- add NCQ recovery and KILL_REQUEUE
- only call atastart() in c_intr() if there was no error

several siisata specific tweaks:
- improve reset to better handle PM - need to reset couple more registers
- add timeouts for unbusy wait - ATA_DELAY (10s)
- siisata_bio_complete() do not use PRSO_RTC for byte count for NCQ transfers,
they never return partial reads; and that register might contain some random
junk, at least that's the case with ahcisata cmdh_prdbc
 1.30.4.25 27-Jun-2017  jdolecek need to explicitely call siisata_timeout() also for polled bio command when
it times out to clean up; this should avoid the 'polled command has been
queued' panic from wddump()
 1.30.4.24 27-Jun-2017  jdolecek attend error paths, more strict asserts and code consistency

- atastart() and ata_kill_pending() now KASSERT() that all xfers on queue
have same channel
- inactive xfers are killed via new reason KILL_GONE_INACTIVE, controller
code must not call any resource deactivation in that case
- c_intr() must call ata_waitdrain_xfer_check() as first thing, and must not
further touch any xfer structures on exit path; any resource cleanup
is supposed to be done in c_kill_xfer()
- c_kill_xfer() should never call atastart()
- ata_waitdrain_check() removed, replaced by ata_waitdrain_xfer_check()
- ATA_DRIVE_WAITDRAIN handling converted to use condvar
- removed unused ata_c callback
 1.30.4.23 26-Jun-2017  jdolecek when reducing DELAY(), it's necessary to appropriately increase number
of iteration, or command can timeout too soon

adjust also siisata_atapi_start() to use DELAY(100) for the polled command,
mostly for consistency, ATAPI devices are quite slow so likely won't have
real effect
 1.30.4.22 24-Jun-2017  jdolecek reduce the polling interval also for siisata_cmd_start()
 1.30.4.21 23-Jun-2017  jdolecek fix dump for siisata(4) to work - need to call drv_done() callback in order to
not leak xfers

while here, reduce the DELAY() for polled bio to make it go much faster,
same value as used in ahcisata(4)

needs also rev. 1.252 src/sys/arch/x86/x86/pmap.c to not trigger the
assertion, the pmap.c fix committed only on HEAD
 1.30.4.20 23-Jun-2017  jdolecek ata/TODO.ncq
 1.30.4.19 21-Jun-2017  jdolecek change ata_queue_hwslot_to_xfer() and ata_queue_get_active_xfer() to take
ata_channel instead of ata_queue as parameter, and lock the channel while
traversing the queue
 1.30.4.18 20-Jun-2017  jdolecek remove ata queue downsizing - every device, attached to the same channel,
uses slots according to it's own limits

wdc code changed to expect maximum one active xfer, and not check number
of openings in the channel; this is to facilitate using wdc functions
for e.g. handling of atapi commands for drivers which support both ATAPI
and NCQ

siisata(4) part, including fix to hang on drive probe (missing ata_free_xfer())
 1.30.4.17 19-Jun-2017  jdolecek add ata_channel lock, use it to protect queue manipulation (only that for now);
add ata_channel_detach() to destroy the locks

change ata_get_xfer() so that it can wait for xfer, convert all on-stack
xfer code to use the blocking variant

fix siisata_reset_drive() to use polled reset and not try ata_activate_xfer(),
convert drive probe code also over from slot0 XXX to ata_get_xfer()

drive reset and PMP now works on siisata(4) too; changes tested also
on piixide(4), ahci(4), mvsata(4)
 1.30.4.16 16-Jun-2017  jdolecek adjust reset channel and dump paths
- channel reset now always kills active transfer, even on dump path, but
now doesn't touch the queued waiting transfers; also kill_xfer hook is
always called, so that HBA can free any private xfer resources and thus
the dump request has chance to work
- kill_xfer routines now always call ata_deactivate_xfer(); added KASSERT()s
to ata_free_xfer() to expect deactivated xfer
- when called during channel reset before dump, ata_kill_active() drops
any queued waiting transfers without processing
- do not (re)queue any transfers in wddone() when dumping
- kill AT_RST_NOCMD flag

This should also hopefully fix the 'polled command has been queued' panic
as reported in:
PR kern/11811 by John Hawkinson
PR kern/47041 by Taylor R Campbell
PR kern/51979 by Martin Husemann

dump tested working with piixide(4) and ahci(4). mvsata(4) dump times out,
but otherwise tested working, will be fixed separately. siisata(4) mechanically
changed and not tested.
 1.30.4.15 13-Jun-2017  jakllsch Add NCQ support to siisata(4).

There are still issues that need to be address before I consider this
mergable.
 1.30.4.14 24-Apr-2017  jakllsch Merge HEAD.
 1.30.4.13 24-Apr-2017  jakllsch Merge HEAD.
 1.30.4.12 24-Apr-2017  jakllsch Merge HEAD.
 1.30.4.11 23-Apr-2017  jakllsch Allocate a full compliment of queue slots for each channel.
 1.30.4.10 23-Apr-2017  jakllsch Use ata_kill_active() in siisata_reset_channel() so as to ensure all
in-flight xfers are taken care of.
 1.30.4.9 23-Apr-2017  jakllsch Fix inverted ata_waitdrain_xfer_check() logic in siisata_atapi_complete().
 1.30.4.8 22-Apr-2017  jakllsch Another one missed in previous.
 1.30.4.7 22-Apr-2017  jakllsch 3rd xfer interrupt argument fix change missed in previous.
 1.30.4.6 22-Apr-2017  jakllsch Don't use the third argument of the xfer interrupt functions to pass the slot number in siisata(4).

This (abuse) is redundant because we are now storing the slot in the xfer structure.
 1.30.4.5 19-Apr-2017  jdolecek adjust ata code to support more than one active command, including the
timeout handling, add support for NCQ commands

move probe for NCQ and number of tags to middle layer, negotiate mutual
support between drive and controller

implement NCQ support in ahci(4)
 1.30.4.4 15-Apr-2017  jdolecek pass also ata_command via ata_xfer, callers of ata_exec_command() is now
responsible for allocation/disposal of the structure

change code to allocate ata_xfer for commands on stack same way as previously
the ata_command were, using c_slot 0; adjust asserts so that it would allow
several xfers with same c_slot, as long as only one such transfer is active
at a time
 1.30.4.3 15-Apr-2017  jdolecek make ata_xfer's allocated as part of ata_queue and make it include ata_bio;
they are pre-allocated on attach and ata_get_xfer() now never sleep, drop the
pool

modify wd(4) to file the bio requests using the xfers and hence
make it possible to have more than one active I/O request in flight;
ata_bio callback doesn't need to allocate any memory any more,
require it to never return ATACMD_TRY_AGAIN

move lp, badsect, multi from ata_bio to ata_drive_datas, as they are per-drive,
not per transfer

drop unused drv atac_claim_hw/atac_free_hw hooks, and also drop again ata_bio
c_hwslot
 1.30.4.2 11-Apr-2017  jdolecek fix to not access active_xfer directly
 1.30.4.1 10-Apr-2017  jdolecek ATA infrastructure improvements to eventually support more outstanding
commands

patch by Matt Thomas
 1.35.6.11 21-Oct-2018  jdolecek decouple siisata_reset_channel() from siisata_reinit_port(); the former
now needs channel lock, but we don't have it in siisata_init_port()
during attach

instead call siisata_reset_channel() when siisata_reinit_port() fails,
and ignore the error during attach
 1.35.6.10 15-Oct-2018  jdolecek change the SATA/NCQ recovery to run in the atabus thread
 1.35.6.9 11-Oct-2018  jdolecek refactor shared parts of the SATA error recovery into new function
ata_recovery_resume() and use for ahcisata/siisata/mvsata, also replace
per-controller hold/unhold with generic version

move the shared recovery code into separate file ata_recovery.c
 1.35.6.8 07-Oct-2018  jdolecek call atastart() when ATA command completes without timeout or error, similar
to AHCI
 1.35.6.7 04-Oct-2018  jdolecek further channel locking pass for reset
 1.35.6.6 03-Oct-2018  jdolecek change channel reset and drive reset for all ATA controllers to always
run via thread, and with channel lock held the whole time; the queue is
frozen while reset is pending

for this repurpose ata_reset_channel() into new ata_thread_run()

also adjust some device printfs to not leak xfer pointer, and avoid
aprint_* for non-autoconf messages
 1.35.6.5 22-Sep-2018  jdolecek separate ata_xfer slot allocation and the memory allocation, so that
there can be more queued xfers than number of supported slots by controller,
and use a pool instead of custom pre-allocation

primarily to help PR kern/52614

remove no longer needed custom wd(4) logic for flush cache

switch also wd(4) trim/suspend/setcache/wdioctlstrategy to sleep waiting
for the memory, they are all called from process context and this
avoids spurious failures
 1.35.6.4 17-Sep-2018  jdolecek move ATAPI-only members of ata_xfer to an union struct to further save space
 1.35.6.3 17-Sep-2018  jdolecek move low-level protocol handlers hooks from ata_xfer to separate struct,
initialized statically

primarily to reduce ata_xfer struct size, but also improves readibility,
and enforces consistency
 1.35.6.2 01-Sep-2018  jdolecek only call ata_deactivate_xfer() once completely done with the active
xfer in controller code (i.e. after bus_dmamap_sync() et.al.), so that
the command slot is safe to be reused immediatelly after deactivate
 1.35.6.1 31-Aug-2018  jdolecek refactor ata_xfer to be just dumb structure; move all callouts/condvars out

retry callout to wd(4); reset callout and the active/cmd finish condvars
to channel queue; change code using the condvars so it works if there
are multiple waiters

simplify the async wait code for cmds, replace ata_wait_xfer()/ata_wake_xfer()
with ata_wait_cmd()

fix the callout_invoking/ack race handling code for timeouts to
actually have chance to work; change mvsata(4) to use generic timeout func

towards resolution of kern/52614
 1.35.4.4 21-Apr-2020  martin Sync with HEAD
 1.35.4.3 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.35.4.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.35.4.1 10-Jun-2019  christos Sync with HEAD
 1.35.2.1 26-Nov-2018  pgoyette Sync with HEAD, resolve a couple of conflicts
 1.39.4.1 30-Dec-2022  martin Pull up following revision(s) (requested by tsutsui in ticket #1557):

sys/dev/ic/ahcisata_core.c: revision 1.83
sys/dev/ic/ahcisata_core.c: revision 1.102
sys/dev/ata/ata.c: revision 1.164
sys/dev/ata/ata_wdc.c: revision 1.115
sys/dev/ata/ata_recovery.c: revision 1.4
sys/dev/ic/siisata.c: revision 1.42
sys/dev/ic/wdc.c: revision 1.308
sys/dev/ic/mvsata.c: revision 1.56
sys/dev/scsipi/atapi_wdc.c: revision 1.138
sys/dev/ic/siisata.c: revision 1.49
sys/dev/ata/atavar.h: revision 1.105
sys/dev/ata/wd.c: revision 1.460
sys/dev/ata/ata.c: revision 1.155
sys/dev/ata/wd.c: revision 1.462
sys/dev/ata/atavar.h: revision 1.109
sys/dev/ata/satapmp_subr.c: revision 1.16
sys/dev/ic/wdc.c: revision 1.299
sys/dev/ic/ahcisata_core.c: revision 1.93
sys/dev/ata/ata_wdc.c: revision 1.120
sys/dev/ic/wdcvar.h: revision 1.100
sys/dev/scsipi/atapi_wdc.c: revision 1.141
sys/dev/ic/mvsata.c: revision 1.61
sys/dev/usb/umass_isdata.c (apply patch)

drop wd lock in wdstart1() before calling the ata_bio hook; when called
from ata thread context, that can still need to sleep for wdc attachments
in wdcwait()

fix use-after-free for ata xfer on bio submission found by KASAN
driver ata_bio hooks read parts of the xfer after ata_exec_xfer()
call in order to determine return value, change so that the hook
doesn't return any value - callers do not care already,
as all I/O requests are asynchronous

this problem was uncovered by recent change for wd(4) to not hold
wd mutex during ata_bio call, the interrupt for the xfer might
thus actually fire immediately

adjust also ata_exec_command driver hooks similarily - remove all
completion and waiting logic from drivers, upper layer ata code
using AT_WAIT/AT_POLL changed to call ata_wait_cmd() itself
PR kern/55169 by Nick Hudson

Function declaration formating whitespace consistency. NFCI.

PR kern/56403
Fix kernel freeze for wdc(4) variants with ATAC_CAP_NOIRQ:

(1) Change ata_xfer_ops:c_poll from void to int function. When it returns
ATAPOLL_AGAIN, let ata_xfer_start() iterate itself again.
(2) Let wdc_ata_bio_poll() return ATAPOLL_AGAIN until ATA_ITSDONE is
achieved.

A similar change has been made for mvsata(4) (see mvsata_bio_poll()),
and no functional changes for other devices.

This is how the drivers worked before jdolecek-ncq branch was merged.
Note that this changes are less likely to cause infinite recursion:

(1) wdc_ata_bio_intr() called from wdc_ata_bio_poll() asserts ATA_ITSDONE
in its error handling paths via wdc_ata_bio_done().
(2) Return value from c_start (= wdc_ata_bio_start()) is checked in
ata_xfer_start().

Therefore, errors encountered in ata_xfer_ops:c_poll and c_start routines
terminate the recursion for wdc(4). The situation is similar for mvsata(4).

Still, there is a possibility where ata_xfer_start() takes long time to
finish a normal operation. This can result in a delayed response for lower
priority interrupts. But, I've never observed such a situation, even when
heavy thrashing takes place for swap partition in wd(4).
"Go ahead" by jdolecek@.
 1.40.2.1 29-Feb-2020  ad Sync with head.
 1.41.4.1 20-Apr-2020  bouyer Sync with HEAD
 1.43.2.2 03-Apr-2021  thorpej Sync with HEAD.
 1.43.2.1 03-Jan-2021  thorpej Sync w/ HEAD.
 1.46.2.1 02-Apr-2021  thorpej config_found_ia() -> config_found() w/ CFARG_IATTR.
 1.47.8.1 04-Aug-2021  thorpej Adapt to CFARGS().
 1.12 31-Jul-2021  andvar s/threshhold/threshold
 1.11 08-Feb-2018  dholland branches: 1.11.22;
Typos.
 1.10 07-Oct-2017  jdolecek Merge support for SATA NCQ (Native Command Queueing) from jdolecek-ncq branch

ATA subsystem was changed to support several outstanding commands, and use
NCQ xfers if supported by both the controller and the disk, including NCQ
error recovery. Set NCQ high priority for BPRIO_TIMECRITICAL xfers
if supported. Added FUA support.

Done some work towards MP-safe, all ATA code tsleep()/wakeup() replaced
by condvars, and switched most code from spl* to mutexes (separate
wd(4) and ata channel lock).

Introduced new option WD_CHAOS_MONKEY to facilitate testing of error
handling, fixed several uncovered issues. Also fixed several problems
with kernel dump to wd(4) disk.

Tested with ahcisata(4), mvsata(4), siisata(4), piixide(4) on amd64,
with and without port multiplier, both disk and ATAPI devices; other
drivers and archs mechanically adjusted and compile-tested. NCQ is
supported for ahcisata(4) and siisata(4) for any controller, for
mvsata(4) only Gen IIe ones for now. Also enabled ATAPI support in
mvsata(4).

Thanks to Matt Thomas for initial ATA infrastructure patch, and
Jonathan A.Kollasch for siisata(4) NCQ changes and general testing.

Also fixes PR kern/43169 (wd(4)); and PR kern/11811, PR kern/47041,
PR kern/51979 (kernel dump)
 1.9 24-Apr-2017  jakllsch Add PR_PS_ACTIVE_SLOT bits.
 1.8 24-Apr-2017  jakllsch Whitespace fixes.
 1.7 02-Nov-2011  jakllsch branches: 1.7.12; 1.7.30; 1.7.34; 1.7.42;
Use appropriate __aligned(value) on already __packed hardware data structures.
 1.6 07-Apr-2010  jakllsch satafis:
- Add function to parse RDH FIS for use in implementing AT_READREG.
- Correct and clean up some structure definitions.
- Sprinkle a bit of const.
- Remove dependency on <dev/ic/wdcreg.h>, WDCTL_4BIT doesn't seem
to be specified by any recent ATA standard, and it seems to make
no difference in practice.
- Stop using WDSD_IBM, these bits have been obsolete since before SATA.

siisata:
- Implement AT_READREG.
- Reap now-unneeded <dev/ic/wdcreg.h>.
- Whitespace and slight debug code cleanup.
- Some possibly-uncessary code reordering.

ahcisata:
- Implement AT_READREG.
- Reap now-unneeded <dev/ic/wdcreg.h>.
 1.5 19-Jul-2009  kiyohara branches: 1.5.2; 1.5.4;
Support siisata@cardbus.
It tested on amd64 and i386 only.
 1.4 04-Jul-2009  jakllsch Further corrections for siisata.

Reset ch_status and ch_error at the beginning of any operation.

The chip only writes the RDH FIS to the SRAM when the error bit is
set in a RDH FIS (per the datasheet). Thus, satafis_sdb_parse() is
replaced with satafis_rhd_parse(). A valid FIS type field seems to
not be written to the SRAM, so don't bother checking it for the
correct magic.

Additionally, append 2009 to copyright year set, and remove
obsolete CVS Id lines from when this was in my repository.
 1.3 17-Jun-2009  jakllsch A few changes for siisata(4):

- Support detachment. From KIYOHARA Takashi.
- Add PCI detachment functionality (albeit not very interesting when
the bus can not yet be rescanned).
- Rework interrupt handlers to reduce near-duplicate code.
Borrowed from ahcisata(4).
- Attempt to make polled I/O work. Untested.
- Fix formatting of some messages.
- For always-polled commands, disable interrupt
at slot level rather than port level.
- Instead of busy-waiting indefinitely for completion of some commands
move on after 31 seconds. Use cv_timedwait(9) instead of DELAY(9).
- Use abstracted SATA FIS code.
- Enable use of disks that don't respond with the standard signature.
 1.2 08-Sep-2008  gmcgarry branches: 1.2.4; 1.2.8; 1.2.12; 1.2.14;
Replace most gcc-specific __attribute__ uses with BSD-style sys/cdef.h
preprocessor macros.
 1.1 23-May-2008  jnemeth branches: 1.1.2; 1.1.4; 1.1.8; 1.1.10;
Import siisata(4) by Jonathan A. Kollasch.

The siisata driver supports the Silicon Image SteelVine family of SATA-II
controllers, interfacing the hardware with the ata(4) and atapi(4) sub-
systems.

The following controllers are supported by the siisata driver:

Silicon Image SiI3124 4-port PCI/PCI-X
Silicon Image SiI3132 2-port PCI-Express x1
Silicon Image SiI3531 1-port PCI-Express x1

SATA Native Command Queueing is not yet supported.
Device hot swapping is not yet supported.
Silicon Image's Software RAID is not yet supported by the
ataraid(4) driver.

Approved by: core (christos), releng (bouyer)
 1.1.10.1 19-Oct-2008  haad Sync with HEAD.
 1.1.8.3 24-Sep-2008  wrstuden Merge in changes between wrstuden-revivesa-base-2 and
wrstuden-revivesa-base-3.
 1.1.8.2 23-Jun-2008  wrstuden Add files to branch that were added on -current.

After this, all that's left of update is to merge some changes
that had conflicts.
 1.1.8.1 23-May-2008  wrstuden file siisatareg.h was added on branch wrstuden-revivesa on 2008-06-23 05:02:13 +0000
 1.1.4.2 04-Jun-2008  yamt sync with head
 1.1.4.1 23-May-2008  yamt file siisatareg.h was added on branch yamt-pf42 on 2008-06-04 02:05:10 +0000
 1.1.2.3 28-Sep-2008  mjf Sync with HEAD.
 1.1.2.2 02-Jun-2008  mjf Sync with HEAD.
 1.1.2.1 23-May-2008  mjf file siisatareg.h was added on branch mjf-devfs2 on 2008-06-02 13:23:27 +0000
 1.2.14.1 21-Apr-2010  matt sync to netbsd-5
 1.2.12.6 11-Aug-2010  yamt sync with head.
 1.2.12.5 19-Aug-2009  yamt sync with head.
 1.2.12.4 18-Jul-2009  yamt sync with head.
 1.2.12.3 20-Jun-2009  yamt sync with head
 1.2.12.2 04-May-2009  yamt sync with head.
 1.2.12.1 08-Sep-2008  yamt file siisatareg.h was added on branch yamt-nfs-mp on 2009-05-04 08:12:44 +0000
 1.2.8.1 23-Jul-2009  jym Sync with HEAD.
 1.2.4.2 28-Sep-2009  snj Pull up following revision(s) (requested by jakllsch in ticket #1023):
sys/dev/ata/satafis_subr.c: revision 1.3
sys/dev/ata/satafisvar.h: revision 1.2
sys/dev/ic/siisata.c: revision 1.7
sys/dev/ic/siisatareg.h: revision 1.4
Further corrections for siisata.
Reset ch_status and ch_error at the beginning of any operation.
The chip only writes the RDH FIS to the SRAM when the error bit is
set in a RDH FIS (per the datasheet). Thus, satafis_sdb_parse() is
replaced with satafis_rhd_parse(). A valid FIS type field seems to
not be written to the SRAM, so don't bother checking it for the
correct magic.
Additionally, append 2009 to copyright year set, and remove
obsolete CVS Id lines from when this was in my repository.
 1.2.4.1 28-Sep-2009  snj Pull up following revision(s) (requested by jakllsch in ticket #1023):
sys/dev/ic/siisata.c: revision 1.3
sys/dev/ic/siisatareg.h: revision 1.3
sys/dev/ic/siisatavar.h: revision 1.3
sys/dev/pci/files.pci: revision 1.315
sys/dev/pci/siisata_pci.c: revision 1.3
A few changes for siisata(4):
- Support detachment. From KIYOHARA Takashi.
- Add PCI detachment functionality (albeit not very interesting when
the bus can not yet be rescanned).
- Rework interrupt handlers to reduce near-duplicate code.
Borrowed from ahcisata(4).
- Attempt to make polled I/O work. Untested.
- Fix formatting of some messages.
- For always-polled commands, disable interrupt
at slot level rather than port level.
- Instead of busy-waiting indefinitely for completion of some commands
move on after 31 seconds. Use cv_timedwait(9) instead of DELAY(9).
- Use abstracted SATA FIS code.
- Enable use of disks that don't respond with the standard signature.
 1.5.4.1 30-May-2010  rmind sync with head
 1.5.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.7.42.4 29-Jul-2017  jdolecek add macro for getting the slot from context register, just for reference for now
 1.7.42.3 19-Jul-2017  jdolecek header changes for siisata switch to new error handling world order
 1.7.42.2 12-Jun-2017  jakllsch Macro argument parentheses paranoia.
Annotate another register initialism.
 1.7.42.1 24-Apr-2017  jakllsch Merge HEAD.
 1.7.34.1 26-Apr-2017  pgoyette Sync with HEAD
 1.7.30.1 28-Aug-2017  skrll Sync with HEAD
 1.7.12.1 03-Dec-2017  jdolecek update from HEAD
 1.11.22.1 01-Aug-2021  thorpej Sync with HEAD.
 1.9 24-Oct-2018  jdolecek detach the controller itself on shutdown; adjust to not detach already
detached atabus/channel
 1.8 22-Oct-2018  jdolecek Merge jdolecek-ncqfixes branch

- ata_xfer's are dynamicall allocated as needed using a pool, no longer
limited to number of possible openings supported by controller; dump
and recovery paths use dedicated pre-allocated storage
- moved callouts and condvars from ata_xfer to queue or channel, so that
ata_xfer does not need special initialization
- slot allocation now done when xfer is being activated, uncoupled
from memory allocation; active slots are no longer tracked by controller
code
- channel and drive reset is done always via the atabus thread, and
now executes with channel locked the whole time
- NCQ recovery moved to shared function, and run via the thread also
- added some workarounds for buggy error recovery AHCI emulation in QEMU
and Parallels

designed to primarily fix kern/52614, but might also help with kern/47041
and kern/53183
 1.7 07-Oct-2017  jdolecek branches: 1.7.2; 1.7.4; 1.7.6;
Merge support for SATA NCQ (Native Command Queueing) from jdolecek-ncq branch

ATA subsystem was changed to support several outstanding commands, and use
NCQ xfers if supported by both the controller and the disk, including NCQ
error recovery. Set NCQ high priority for BPRIO_TIMECRITICAL xfers
if supported. Added FUA support.

Done some work towards MP-safe, all ATA code tsleep()/wakeup() replaced
by condvars, and switched most code from spl* to mutexes (separate
wd(4) and ata channel lock).

Introduced new option WD_CHAOS_MONKEY to facilitate testing of error
handling, fixed several uncovered issues. Also fixed several problems
with kernel dump to wd(4) disk.

Tested with ahcisata(4), mvsata(4), siisata(4), piixide(4) on amd64,
with and without port multiplier, both disk and ATAPI devices; other
drivers and archs mechanically adjusted and compile-tested. NCQ is
supported for ahcisata(4) and siisata(4) for any controller, for
mvsata(4) only Gen IIe ones for now. Also enabled ATAPI support in
mvsata(4).

Thanks to Matt Thomas for initial ATA infrastructure patch, and
Jonathan A.Kollasch for siisata(4) NCQ changes and general testing.

Also fixes PR kern/43169 (wd(4)); and PR kern/11811, PR kern/47041,
PR kern/51979 (kernel dump)
 1.6 26-Jul-2010  jakllsch branches: 1.6.18; 1.6.48;
Store information for bus_dmamem_unmap() and bus_dmamem_free()
somewhere outside the bus_dmamap_t. The bus_dmamap_t has already
been destroyed by this time.

Fixes DMA memory leak at siisata_detach() time.
 1.5 19-Oct-2009  bouyer branches: 1.5.2; 1.5.4;
Remove closes 3 & 4 from my licence. Lots of thanks to Soren Jacobsen
for the booring work !
 1.4 04-Jul-2009  jakllsch Remove unused elements from siisata_softc.

Clean up siisata pci attachment.
noteable changes:
- Use aprint_*_dev where appropriate.
- Condense board match table and use C99 initializers.
- Use aprint_verbose for extra info.

Also, add 2009 to my copyright, as well as remove my local CVS tags.
 1.3 17-Jun-2009  jakllsch A few changes for siisata(4):

- Support detachment. From KIYOHARA Takashi.
- Add PCI detachment functionality (albeit not very interesting when
the bus can not yet be rescanned).
- Rework interrupt handlers to reduce near-duplicate code.
Borrowed from ahcisata(4).
- Attempt to make polled I/O work. Untested.
- Fix formatting of some messages.
- For always-polled commands, disable interrupt
at slot level rather than port level.
- Instead of busy-waiting indefinitely for completion of some commands
move on after 31 seconds. Use cv_timedwait(9) instead of DELAY(9).
- Use abstracted SATA FIS code.
- Enable use of disks that don't respond with the standard signature.
 1.2 14-Sep-2008  jakllsch branches: 1.2.4; 1.2.8; 1.2.12; 1.2.14;
A few cleanups for siisata(4)

No functional changes intended (except maybe un-reseting the chip a bit later
in attach).

- pass fewer arguments to local functions where arguments can be derived from
an existing argument
- some coding style fixes
- more abstraction for PRB activation and deactivation
- bus_dma(9) properification in error cases
- undefine SIISATA_DEBUG, and cleanup variables used only for DEBUG_PRINT()s
 1.1 23-May-2008  jnemeth branches: 1.1.2; 1.1.4; 1.1.8; 1.1.10;
Import siisata(4) by Jonathan A. Kollasch.

The siisata driver supports the Silicon Image SteelVine family of SATA-II
controllers, interfacing the hardware with the ata(4) and atapi(4) sub-
systems.

The following controllers are supported by the siisata driver:

Silicon Image SiI3124 4-port PCI/PCI-X
Silicon Image SiI3132 2-port PCI-Express x1
Silicon Image SiI3531 1-port PCI-Express x1

SATA Native Command Queueing is not yet supported.
Device hot swapping is not yet supported.
Silicon Image's Software RAID is not yet supported by the
ataraid(4) driver.

Approved by: core (christos), releng (bouyer)
 1.1.10.1 19-Oct-2008  haad Sync with HEAD.
 1.1.8.3 24-Sep-2008  wrstuden Merge in changes between wrstuden-revivesa-base-2 and
wrstuden-revivesa-base-3.
 1.1.8.2 23-Jun-2008  wrstuden Add files to branch that were added on -current.

After this, all that's left of update is to merge some changes
that had conflicts.
 1.1.8.1 23-May-2008  wrstuden file siisatavar.h was added on branch wrstuden-revivesa on 2008-06-23 05:02:13 +0000
 1.1.4.2 04-Jun-2008  yamt sync with head
 1.1.4.1 23-May-2008  yamt file siisatavar.h was added on branch yamt-pf42 on 2008-06-04 02:05:10 +0000
 1.1.2.3 28-Sep-2008  mjf Sync with HEAD.
 1.1.2.2 02-Jun-2008  mjf Sync with HEAD.
 1.1.2.1 23-May-2008  mjf file siisatavar.h was added on branch mjf-devfs2 on 2008-06-02 13:23:27 +0000
 1.2.14.1 21-Apr-2010  matt sync to netbsd-5
 1.2.12.6 11-Aug-2010  yamt sync with head.
 1.2.12.5 11-Mar-2010  yamt sync with head
 1.2.12.4 18-Jul-2009  yamt sync with head.
 1.2.12.3 20-Jun-2009  yamt sync with head
 1.2.12.2 04-May-2009  yamt sync with head.
 1.2.12.1 14-Sep-2008  yamt file siisatavar.h was added on branch yamt-nfs-mp on 2009-05-04 08:12:44 +0000
 1.2.8.1 23-Jul-2009  jym Sync with HEAD.
 1.2.4.2 28-Sep-2009  snj Pull up following revision(s) (requested by jakllsch in ticket #1023):
sys/dev/ic/siisatavar.h: revision 1.4
sys/dev/pci/siisata_pci.c: revision 1.4
Remove unused elements from siisata_softc.
Clean up siisata pci attachment.
noteable changes:
- Use aprint_*_dev where appropriate.
- Condense board match table and use C99 initializers.
- Use aprint_verbose for extra info.
Also, add 2009 to my copyright, as well as remove my local CVS tags.
 1.2.4.1 28-Sep-2009  snj Pull up following revision(s) (requested by jakllsch in ticket #1023):
sys/dev/ic/siisata.c: revision 1.3
sys/dev/ic/siisatareg.h: revision 1.3
sys/dev/ic/siisatavar.h: revision 1.3
sys/dev/pci/files.pci: revision 1.315
sys/dev/pci/siisata_pci.c: revision 1.3
A few changes for siisata(4):
- Support detachment. From KIYOHARA Takashi.
- Add PCI detachment functionality (albeit not very interesting when
the bus can not yet be rescanned).
- Rework interrupt handlers to reduce near-duplicate code.
Borrowed from ahcisata(4).
- Attempt to make polled I/O work. Untested.
- Fix formatting of some messages.
- For always-polled commands, disable interrupt
at slot level rather than port level.
- Instead of busy-waiting indefinitely for completion of some commands
move on after 31 seconds. Use cv_timedwait(9) instead of DELAY(9).
- Use abstracted SATA FIS code.
- Enable use of disks that don't respond with the standard signature.
 1.5.4.1 05-Mar-2011  rmind sync with head
 1.5.2.1 17-Aug-2010  uebayasi Sync with HEAD.
 1.6.48.3 01-Aug-2017  jdolecek fix logic bug in processing of finished commands - mask of active
commands can change during the loop as c_intr() callback can queue
new commands, so the interrupt routine should only mark as finished
those which were actually active before the loop started; otherwise
the code marked as finished commands which were just started, and
being executed by HBA, leading to all sorts of data corruption

while here mark the active mask volatile, as it is modified from
interrupt context

this fixes for good the random crashes, short reads, and fatal command
errors which I've been tracing down for past couple weeks

thanks to Jonathan (jakllsch@) for testing, and a script to easily
triggered the condition, and led to this bug being finally found and squashed
 1.6.48.2 19-Jul-2017  jdolecek header changes for siisata switch to new error handling world order
 1.6.48.1 13-Jun-2017  jakllsch Add NCQ support to siisata(4).

There are still issues that need to be address before I consider this
mergable.
 1.6.18.1 03-Dec-2017  jdolecek update from HEAD
 1.7.6.1 11-Oct-2018  jdolecek refactor shared parts of the SATA error recovery into new function
ata_recovery_resume() and use for ahcisata/siisata/mvsata, also replace
per-controller hold/unhold with generic version

move the shared recovery code into separate file ata_recovery.c
 1.7.4.1 10-Jun-2019  christos Sync with HEAD
 1.7.2.1 26-Nov-2018  pgoyette Sync with HEAD, resolve a couple of conflicts
 1.105 08-Feb-2024  andvar s/should't/shouldn't/ and s/mistmatch/mismatch/ in comments.
 1.104 02-Nov-2022  andvar s/ourselve/ourselves/ in comments.
 1.103 23-Feb-2022  andvar fix various typos in comments, mainly immediatly/immediately/,
as well shared and recently fixed typos in OpenBSD code by Jonathan Grey.
 1.102 07-Aug-2021  thorpej Merge thorpej-cfargs2.
 1.101 24-Apr-2021  thorpej branches: 1.101.8;
Merge thorpej-cfargs branch:

Simplify and make extensible the config_search() / config_found() /
config_attach() interfaces: rather than having different variants for
which arguments you want pass along, just have a single call that
takes a variadic list of tag-value arguments.

Adjust all call sites:
- Simplify wherever possible; don't pass along arguments that aren't
actually needed.
- Don't be explicit about what interface attribute is attaching if
the device only has one. (More simplification.)
- Add a config_probe() function to be used in indirect configuiration
situations, making is visibly easier to see when indirect config is
in play, and allowing for future change in semantics. (As of now,
this is just a wrapper around config_match(), but that is an
implementation detail.)

Remove unnecessary or redundant interface attributes where they're not
needed.

There are currently 5 "cfargs" defined:
- CFARG_SUBMATCH (submatch function for direct config)
- CFARG_SEARCH (search function for indirect config)
- CFARG_IATTR (interface attribte)
- CFARG_LOCATORS (locators array)
- CFARG_DEVHANDLE (devhandle_t - wraps OFW, ACPI, etc. handles)

...and a sentinel value CFARG_EOL.

Add some extra sanity checking to ensure that interface attributes
aren't ambiguous.

Use CFARG_DEVHANDLE in MI FDT, OFW, and ACPI code, and macppc and shark
ports to associate those device handles with device_t instance. This
will trickle trough to more places over time (need back-end for pre-OFW
Sun OBP; any others?).
 1.100 02-Nov-2013  gson branches: 1.100.46;
Turn the "esiop_intr: I shouldn't be there !" panic into a printf
followed by a return from the interrupt handler. The condition is
triggered on some KVM virtual hosts, apparently harmlessly, and not
panicing makes it possible to boot a NetBSD GENERIC kernel on those
hosts. Also make the same change to siop to minimize divergence
between siop and esiop. Fixes PR kern/48277.
 1.99 30-Oct-2013  gson Fix incorrect function names in panic message strings.
 1.98 13-Nov-2010  uebayasi branches: 1.98.8; 1.98.18; 1.98.22;
Don't pull in the whole uvm(9) API to access only PAGE_SIZE and
some other constants. These are provided by sys/param.h now.
 1.97 09-Sep-2010  jakllsch Allow e?siop_dump_script() to work with on-chip RAM. Prefix
DUMP_SCRIPT with SIOP_. Additionally, avoid undefining DEBUG,
condition on SIOP_DEBUG instead.
 1.96 02-May-2010  jakllsch Add (missing) newlines to error messages.
 1.95 09-Apr-2010  jakllsch Improve error paths in (e)siop_scsipi_request():

- When terminating the adapter request after the cmd has been removed
from the free list, put that cmd back on the free list before returing.
- Correctly indicate which bus_dma_load() failed.

Analysis and fix from Michael L. Hitch in PR/42844.
 1.94 19-Oct-2009  bouyer branches: 1.94.2; 1.94.4;
Remove closes 3 & 4 from my licence. Lots of thanks to Soren Jacobsen
for the booring work !
 1.93 04-Sep-2009  tsutsui Remove unnecessary whitespace.
 1.92 16-May-2009  tsutsui Misc cleanup:
- some KNF
- u_intNN_t -> uintNN_t
- wrap long lines and fix indent
- remove return statements at the end of void functions
- use __arraycount()

XXX: many inconsistent aprint_error_dev(9) vs printf(9)
 1.91 15-May-2009  tsutsui Split device_t/softc.

No crash on:
esiop0 at pci0 dev 11 function 0: Symbios Logic 53c875 (ultra-wide scsi)
siop0 at pci0 dev 9 function 0: Symbios Logic 53c810a (fast scsi)
siop0 at gsc0 hpa 0xf0830000 path 2/0/7 irq 3 ipl 6: NCR53C720 rev 2
 1.90 15-Mar-2009  cegger ansify function definitions
 1.89 14-Mar-2009  dsl ANSIfy another 1261 function definitions.
The only ones left in sys are beyond by sed script!
(or in sys/dist or sys/external)
Mostly they have function pointer parameters.
 1.88 14-Mar-2009  dsl Change about 4500 of the K&R function definitions to ANSI ones.
There are still about 1600 left, but they have ',' or /* ... */
in the actual variable definitions - which my awk script doesn't handle.
There are also many that need () -> (void).
(The script does handle misordered arguments.)
 1.87 08-Apr-2008  cegger branches: 1.87.4; 1.87.12; 1.87.14; 1.87.18;
use aprint_*_dev and device_xname
 1.86 27-Mar-2008  skrll Add support for the (non-pci) NCR 53c720/770 in big-endian mode.

From OpenBSD (Mark Kettenis)
 1.85 19-Oct-2007  ad branches: 1.85.16;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.84 30-Sep-2007  martin branches: 1.84.2;
Do not stop callouts on polled commands. Problem noticed by Chris Ross
when trying to do a kernel dump on sparc64.
Approved by Manuel Bouyer.
 1.83 04-Mar-2007  christos branches: 1.83.2; 1.83.14; 1.83.16; 1.83.18;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.82 02-Nov-2006  garbled branches: 1.82.4;
Comment out the debug options to siop, and change the undef to define.
This way they will be compiled by the i386 DEBUG kernel and tested.
 1.81 02-Nov-2006  garbled Make these compile when SIOP_DEBUG is enabled, by nuking the reference to
t_offset, which no longer seems to exist.
 1.80 24-Dec-2005  perry branches: 1.80.20; 1.80.22;
__inline__ -> inline
 1.79 18-Nov-2005  bouyer Some drives disconnect after the last data phase without a save data pointer
message. In such case we would not update resid with the proper value
(eventually resid would not be updated at all if there was only one data
phase). To fix this, have the script save the offset in the data tables at
disconnect time if there was a transfer, and use this to compute the resid
if the current offset is 0.
Problem reported and patch tested by edwin, Roy Bixler and YAMAMOTO Takashi.
Fix kern/31990 by YAMAMOTO Takashi.
 1.78 27-Feb-2005  perry branches: 1.78.2; 1.78.4; 1.78.10;
nuke trailing whitespace
 1.77 04-Feb-2005  perry de-__P
 1.76 03-Oct-2004  bouyer branches: 1.76.4; 1.76.6;
Add missing return, fix handling of Ignore Wide Residue messages.
 1.75 17-May-2004  bouyer Add support for the Ignore Wide Residue SCSI message.
 1.74 17-May-2004  bouyer when an unexpected disconnect occurs only compute the resid; do the
real save data pointers when we get the message (or rather, at disconnect
time following the message).
Factor out code to do this, and to deal with xs->resid, in siop_common.c.
 1.73 17-May-2004  bouyer Properly compute xs->resid, instead of assuming it'll always be 0 when
a command is done.
 1.72 16-Mar-2004  bouyer branches: 1.72.4;
cbd -> cdb
Command Block Descriptor -> Command Descriptor Block
Pointed out by Allen Briggs.
 1.71 15-Mar-2004  bouyer Extract the code printing the CBD from scsipi_print_sense(), so that it's
usable in other context.
Use the new scsipi_print_cbd() to dump the command in case of timeout
in siop/esiop.
 1.70 02-Nov-2003  wiz Fix some typos. From Tom Cosgrove via jmc@openbsd.
 1.69 28-Oct-2003  matt fix bogus GCC uninitialized variable warning. Use TAILQ_FOREACH.
 1.68 25-Oct-2003  christos Fix uninitialized variable warnings
 1.67 21-Oct-2003  simonb Remove return after panic().
 1.66 03-May-2003  wiz branches: 1.66.2;
DMA, not dma nor Dma.
 1.65 08-Nov-2002  bouyer in siop_reset(), reset sc_ntargets to 0. The number of targets will be
computed again in siop_add_reselsw()
in siop_reset(), reset the tag reseloff to 0, in addition to the lun reseloff.
If siop_add_dev() fails this time we would use the old reseloff, clobbering
memory now used for something else.
 1.64 26-Jul-2002  wiz enouth -> enough.
 1.63 18-Jul-2002  wiz Spell 'should' correctly.
 1.62 18-May-2002  bouyer branches: 1.62.2;
Be more verbose when returning XS_DRIVER_STUFFUP
 1.61 16-May-2002  thorpej Don't access a scsipi channel's periph table directly; use
scsipi_lookup_periph().
 1.60 25-Apr-2002  bouyer branches: 1.60.2;
It's not safe to access the SCNTL1 register while the SCRIPT is running.
On the 1010 this can wedge the chip. So abort the script instead.
the abort interrupt will trigger a bus reset.
 1.59 23-Apr-2002  bouyer More copyright fixes, pointed out by Thomas. Thanks !
 1.58 23-Apr-2002  bouyer - factor out parts of (e)siop_attach() to siop_common_attach()
- Add support for DT transfers (aka Ultra/160) in esiop

Note that DT transfers are not enabled for 53c1010-33 rev 0 yet; if I trust
FreeBSD it has a bug which prevent them to do DT properly.
From the same source there may be issues with some revs of 53c1010-66.
 1.57 23-Apr-2002  bouyer Bump the space for SCSI messages from 8 to 16 octets, as 8 may not be
enouth for IDENTIFY + TAG + PPR.
Get rid of constants in C code by use of a offsetof macro.
 1.56 23-Apr-2002  bouyer Enable software LED control based on LED0 feature, not #define.
For now, set the LED0 feature if SIOP_SYMLED is defined in siop_pci_common.c.
From Jason R Thorpe.
 1.55 22-Apr-2002  bouyer Fix last change: assign siop_cmd->tag in callers instead of siop_setuptables(),
and use siop_cmd->tag instead of xs->xs_tag_id. This way siop can use
xs->xs_tag_id + 1 without interferences with esiop.
 1.54 22-Apr-2002  bouyer In siop_setuptables(), use the proposed tag_id, not tag_id +1.
In siop.c bump siop_cmd->tag by one as tag id 0 is reserved for untagged cmds.
 1.53 20-Apr-2002  bouyer Move a few things around, so that ic/siop_common.c and pci/siop_pci_common.c
can be compiled without including siopvar.h.
 1.52 18-Apr-2002  bouyer If SIOP_SYMLED is defined, drive the activity LED though GPIO pin 1.
 1.51 05-Apr-2002  bouyer Implement mstohz() as discussed on tech-kern, and use it in SCSI drivers
to convert xs->timeout to callout() parameter.
 1.50 01-Mar-2002  bouyer As siop_morecbd() is called from the kernel thread, protect access to the
queues with splbio.
 1.49 12-Jan-2002  tsutsui Call malloc(9) with M_ZERO flag instead of memset() after malloc().
 1.48 13-Nov-2001  lukem add/cleanup RCSID
 1.47 14-Oct-2001  bouyer Call siop_morecbd() only when scsipi ask us ADAPTER_REQ_GROW_RESOURCES.
This prevent using bus_dmamem_map() from interrupt context.
Should fix kern/13827.
 1.46 19-Jul-2001  thorpej Use BUS_DMA_READ and BUS_DMA_WRITE in some obvious places.
 1.45 21-Jun-2001  bouyer branches: 1.45.2;
Also print DSA addr in a DIAGNOSTING printf.
 1.44 23-May-2001  bouyer Call scsipi_channel_thaw() after scsipi_done() so that command ordering
is preserved.
 1.43 30-Apr-2001  lukem delint newline in string
 1.42 25-Apr-2001  bouyer Pull up the thorpej_scsipi branch to main branch.
This is a completely rewritten scsipi_xfer execution engine, and the
associated changes to HBA drivers. Overview of changes & features:
- All xfers are queued in the mid-layer, rather than doing so in an
ad-hoc fashion in individual adapter drivers.
- Adapter/channel resource management in the mid-layer, avoids even trying
to start running an xfer if the adapter/channel doesn't have the resources.
- Better communication between the mid-layer and the adapters.
- Asynchronous event notification mechanism from adapter to mid-layer and
peripherals.
- Better peripheral queue management: freeze/thaw, sorted requeueing during
recovery, etc.
- Clean separation of peripherals, adapters, and adapter channels (no more
scsipi_link).
- Kernel thread for each scsipi_channel makes error recovery much easier
(no more dealing with interrupt context when recovering from an error).
- Mid-layer support for tagged queueing: commands can have the tag type
set explicitly, tag IDs are allocated in the mid-layer (thus eliminating
the need to use buggy tag ID allocation schemes in many adapter drivers).
- support for QUEUE FULL and CHECK CONDITION status in mid-layer; the command
will be requeued, or a REQUEST SENSE will be sent as appropriate.

Just before the merge syssrc has been tagged with thorpej_scsipi_beforemerge
 1.41 07-Mar-2001  thorpej Add BUS_DMA_STREAMING to data transfer maps.
 1.40 01-Mar-2001  thorpej branches: 1.40.2;
Differentiate a couple of similar error message, and add newlines
on the end of them.
 1.39 11-Feb-2001  bouyer Avoid sending new commands to the device if it has sense pending:
- run request sense command without disconnect
- don't restart the script before siop_scsicmd_end has been called if the
cmd didn't complete with good status.
- reserve slot 0 for request sense, to make sure it'll be sent first.
 1.38 26-Jan-2001  bouyer Add a few siop_table_sync() calls.
 1.37 14-Nov-2000  thorpej branches: 1.37.2;
NBPG -> PAGE_SIZE
 1.36 23-Oct-2000  bouyer Fixes related to QUEUE FULL status:
- move status handling in siop_scsicmd_end(), it's better than in siop_intr()
- define 2 internal SIOP status, for "no status reported by device" and
reset condition
- add a list of "urgent" command, to be executed before the list of command
queued the normal way; this is used for command which got aborted
by a QUEUE FULL and have to be requeued in order.
- Don't accept to send a Q_TAG message not immediatly folowing a IDENTIFY
 1.35 23-Oct-2000  bouyer Rearrange for script changes (scheduler core in main script, command part
of the scheduler in command table).
Add tagged command queuing support.
 1.34 21-Oct-2000  bouyer Ops, sync the script DMA map when the script RAM *don't* exists.
 1.33 19-Oct-2000  bouyer Adapt for script change: don't assume Ent_lun_switch_entry == 0
 1.32 18-Oct-2000  bouyer Ops, add proper bus_dmamap_sync() calls for reselect switch operations.
 1.31 18-Oct-2000  bouyer Adapt for new lun switch script.
Implement SCBUSACCEL ioctl.
Snapshot of work in progress on tagged queuing: we can send/receive
queue tag messages. Infrastructure to manage multiple commands per
devices not here yet.
 1.30 06-Oct-2000  bouyer Ops, disable debugging messages.
 1.29 06-Oct-2000  bouyer Fix recurent typo: shed->sched
 1.28 06-Oct-2000  bouyer Adapt for reselect handling from the script. While here, fix typo
(SIOP_SCXFER -> SIOP_SXFER).
 1.27 27-Jul-2000  bouyer Force 64bit arithmetic for timeout computation; a 32bit int opverflows for
large timeouts. Should fix PR kern/10575.
 1.26 24-Jul-2000  bouyer create a funcion, siop_busreset(), to reset the scsibus.
Reset the scsi bus at attach time, to be sure all devices start in narrow/async
mode.
Defer sync/wide negotiation until after whe have a valid
xs->sc_link->device_softc, so that we can honnor the NOSYNC/NOWIDE quirks.
 1.25 19-Jul-2000  pk Fixx off-by-one error in handlereset().
 1.24 28-Jun-2000  mrg remove include of <vm/vm.h>. <vm/vm.h> -> <uvm/uvm_extern.h>
 1.23 26-Jun-2000  mrg remove/move more mach vm header files:

<vm/pglist.h> -> <uvm/uvm_pglist.h>
<vm/vm_inherit.h> -> <uvm/uvm_inherit.h>
<vm/vm_kern.h> -> into <uvm/uvm_extern.h>
<vm/vm_object.h> -> nothing
<vm/vm_pager.h> -> into <uvm/uvm_pager.h>

also includes a bunch of <vm/vm_page.h> include removals (due to redudancy
with <vm/vm.h>), and a scattering of other similar headers.
 1.22 20-Jun-2000  bouyer Patch from Eduardo Horvath: don't bus_dmamap_sync the script dma map if
it lives in the on-chip RAM !
 1.21 13-Jun-2000  bouyer branches: 1.21.2;
sheduler->scheduler, as pointed out by Klaus Klein
 1.20 12-Jun-2000  bouyer Handle "scsi bus mode change" interrupts on 895 and higther.
Thanks to Hal Murray for reporting the problem and testing the fix.
 1.19 07-Jun-2000  tsutsui Adapt struct scsipi_adapter changes.
 1.18 05-Jun-2000  bouyer use the correct variable in a debug printf().
 1.17 25-May-2000  bouyer branches: 1.17.2;
Separate the sheduler from the main script, allocate another DMA-safe
memory page for the sheduler. Put the main script in the on-chip RAM when
available.
Avoid a null-pointer dereference when DSA is invalid.
 1.16 23-May-2000  bouyer Allocate dynamically the command block descriptors.
 1.15 15-May-2000  bouyer Don't enable debug message by default.
 1.14 15-May-2000  bouyer - split siop.c in script-dependant vs script-independant part, for
comming esiop
- add a reset callback for bus-dependant registers settings
 1.13 11-May-2000  bouyer Use correct divider value for scxfer
 1.12 06-May-2000  soren Typos.
 1.11 05-May-2000  bouyer Ops, restore sync/wide parameters after a reselect.
Also, better handling of parity errors.
 1.10 05-May-2000  bouyer Rework the command queue, to avoid having commands blocked at the end
of the queue. Load is now properly balanced across all disks of the same bus.
 1.9 04-May-2000  bouyer When a WDTR message is rejected, initiate sync negotiation anyway.
When a SDTR message is rejected indicate that target is async
Add a missing bus_dma_sync call.
 1.8 04-May-2000  bouyer - LP64 issues in debug printfs.
- on a phase mismatch, do byte recovery only if we were in data phase.
Otherwise just clear the fifo.
- Properly handle reject of a sync or wide negotiation.
 1.7 02-May-2000  bouyer - do sync/wide negotiation
- use a circular queue for the start slots, so that order has better chances
to be preserved.
 1.6 27-Apr-2000  bouyer More big-endian fixes from Izumi Tsutsui.
 1.5 27-Apr-2000  bouyer Fix copyrigth notice.
 1.4 26-Apr-2000  bouyer Big-endian fixes from Izumi Tsutsui.
 1.3 25-Apr-2000  bouyer Ops, need to restore correct DSA value after a phase mismatch, we may have
been interrupted during a S/G operation.
 1.2 25-Apr-2000  bouyer - Change the script to start new commands in an asyncronous way, using
'command slots' in which the host can put command and wait for the script
to start them
- Change siop.c to do full disconnect/reslelect, allowing as much as one
command per target/lun to run in parallel.
- Fix bug in registers init where a board without BIOS would end at
ID 0 (now the driver works on alpha too).
- better handling of messages, sending back a MSG_EXT_SDTR in response to an
incoming MSG_EXT_SDTR, and MSG_MESSAGE_REJECT for unhandled messages.
- fix use of bus_dmamap_sync() and htole32().
- supports shared interrups
- change some int8 and int16 to int, for alpha and mips benefits ( suggested by
Toru Nishimura)
 1.1 21-Apr-2000  bouyer Snapshot of work in progress: new driver for the NCR 53c8xx SCSI controller
(the name 'siop' is still being discussed, may change).
Only basic disconnect/reselect for now, no sync/wide negotiation.
Tested with 810A, 875 and 895 on i386 only.
The bus-independant part should also be able to handle the 53c720 and 53c770.
A new driver with enhanced script should appear for the 825/875/895 'soon'.
 1.17.2.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.21.2.8 05-Jan-2002  he Pull up revision 1.47 (via patch, requested by bouyer):
Don't call siop_morecbd() in interrupt context, but pre-allocate
CBD at probe time instead. Fixes PR#13827, PR#14866 and PR#15048.
 1.21.2.7 26-Feb-2001  he Pull up revision 1.39 (requested by bouyer):
Don't queue new commands to a device which has sense pending.
 1.21.2.6 04-Feb-2001  he Pull up revision 1.38 (requested by bouyer):
Add missing bus_dmamap_sync() calls.
 1.21.2.5 15-Dec-2000  he Pull up revisions 1.23-1.24,1.28-1.36 (requested by bouyer):
Speed improvements to the siop driver, and add tagged queueing
support. As a side effect, better handling of some not so common
phase or message sequences.
 1.21.2.4 03-Oct-2000  bouyer Pull up 1.24->1.25 (approved by thorpej):
fix off by one error.
 1.21.2.3 30-Jul-2000  bouyer pull up 1.26->1.27, approved by jhawk:
Fixes 32bit interger overflow with large timeout. Fixes kern/10575.
 1.21.2.2 24-Jul-2000  bouyer Pull up (approved by thorpej):
sys/dev/ic/siop.c 1.25->1.26
sys/dev/ic/siop_common.c 1.5->1.6
sys/dev/ic/siopvar_common.h 1.3->1.4

create a funcion, siop_busreset(), to reset the scsibus.
Reset the scsi bus at attach time, to be sure all devices start in narrow/async
mode.
Defer sync/wide negotiation until after whe have a valid
xs->sc_link->device_softc, so that we can honnor the NOSYNC/NOWIDE quirks.
 1.21.2.1 26-Jun-2000  bouyer Pull up 1.22, approved by thorpej:
don't bus_dmamap_sync the script dma map if it lives in the on-chip RAM.
 1.37.2.12 03-Apr-2001  bouyer Ops, unfreeze the queue after a reset too.
 1.37.2.11 03-Apr-2001  bouyer Remove local command queue; if we run out of start slots, just freeze the
channel; and unfreeze it at the first command complete.
 1.37.2.10 14-Mar-2001  bouyer Add BUS_DMA_STREAMING for the data map, it really helps for sparc64.
 1.37.2.9 12-Mar-2001  bouyer Sync with HEAD.
 1.37.2.8 11-Feb-2001  bouyer Sync with HEAD.
 1.37.2.7 22-Jan-2001  bouyer Put URGENT requests in the urgent queue
When we get CHECK CONDITION, remove and requeue all xfer for this T/L that have
not yet been queued in the device (still in a scheduler slot or in the queues),
otherwise if one of them is accepted before the request sense, sense will be
lost.
Don't allow disconnect for REQUEST SENSE commands, as others drivers do.
 1.37.2.6 15-Jan-2001  bouyer Pass CHECK CONDITION status and reset events to the mid-layer.
 1.37.2.5 15-Dec-2000  bouyer Tell the upper layer we can do tagged queuing, so that it sends us more
than one concurent command. Leave the handling of QUEUE FULL events to the
upper layer.
 1.37.2.4 14-Dec-2000  bouyer Convert to thorpej_scsipi interface. Still some work to do to get all benefits
of the new middle layer, but it works.
 1.37.2.3 22-Nov-2000  bouyer Sync with HEAD.
 1.37.2.2 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.37.2.1 14-Nov-2000  bouyer file siop.c was added on branch thorpej_scsipi on 2000-11-20 11:40:54 +0000
 1.40.2.11 11-Nov-2002  nathanw Catch up to -current
 1.40.2.10 01-Aug-2002  nathanw Catch up to -current.
 1.40.2.9 20-Jun-2002  nathanw Catch up to -current.
 1.40.2.8 17-Apr-2002  nathanw Catch up to -current.
 1.40.2.7 01-Apr-2002  nathanw Catch up to -current.
(CVS: It's not just a program. It's an adventure!)
 1.40.2.6 28-Feb-2002  nathanw Catch up to -current.
 1.40.2.5 14-Nov-2001  nathanw Catch up to -current.
 1.40.2.4 22-Oct-2001  nathanw Catch up to -current.
 1.40.2.3 24-Aug-2001  nathanw Catch up with -current.
 1.40.2.2 21-Jun-2001  nathanw Catch up to -current.
 1.40.2.1 09-Apr-2001  nathanw Catch up with -current.
 1.45.2.6 06-Sep-2002  jdolecek sync kqueue branch with HEAD
 1.45.2.5 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.45.2.4 16-Mar-2002  jdolecek Catch up with -current.
 1.45.2.3 11-Feb-2002  jdolecek Sync w/ -current.
 1.45.2.2 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.45.2.1 03-Aug-2001  lukem update to -current
 1.60.2.3 29-Aug-2002  gehenna catch up with -current.
 1.60.2.2 20-Jul-2002  gehenna catch up with -current.
 1.60.2.1 30-May-2002  gehenna Catch up with -current.
 1.62.2.6 14-Dec-2005  jmc Pullup via patch (requested in ticket #5957 by bouyer)
Some drives disconnect after the last data phase without a save data pointer
message. In such case we would not update resid with the proper value
(eventually resid would not be updated at all if there was only one data
phase). To fix this, have the script save the offset in the data tables at
disconnect time if there was a transfer, and use this to compute the resid
if the current offset is 0. PR#31990
 1.62.2.5 19-Mar-2005  tron Pull up revision 1.76 (requested by bouyer in ticket #1753):
Add missing return, fix handling of Ignore Wide Residue messages.
 1.62.2.4 19-Mar-2005  tron Pull up revision 1.75 (requested by bouyer in ticket #1751):
Add support for the Ignore Wide Residue SCSI message.
 1.62.2.3 17-Mar-2005  tron Pull up revision 1.74 (requested by bouyer in ticket #1750):
when an unexpected disconnect occurs only compute the resid; do the
real save data pointers when we get the message (or rather, at disconnect
time following the message).
Factor out code to do this, and to deal with xs->resid, in siop_common.c.
 1.62.2.2 17-Mar-2005  tron Pull up revision 1.73 (requested by bouyer in ticket #1749):
Properly compute xs->resid, instead of assuming it'll always be 0 when
a command is done.
 1.62.2.1 11-Dec-2002  he Pull up revision 1.65 (requested by bouyer in ticket #975):
In siop_reset(), reset sc_ntargets to 0; it will be
computed again in siop_add_reselsw().
In siop_reset(), reset the tag reseloff to 0, in addition
to the lun reseloff. If siop_add_dev() fails this time,
we would use the old reseloff, clobbering memory new used
for something else.
 1.66.2.7 11-Dec-2005  christos Sync with head.
 1.66.2.6 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.66.2.5 04-Feb-2005  skrll Sync with HEAD.
 1.66.2.4 19-Oct-2004  skrll Sync with HEAD
 1.66.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.66.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.66.2.1 03-Aug-2004  skrll Sync with HEAD
 1.72.4.5 01-Dec-2005  riz Pull up following revision(s) (requested by bouyer in ticket #10168):
sys/dev/ic/siop.c: revision 1.79 via patch
sys/dev/ic/siopvar_common.h: revision 1.33 via patch
sys/dev/ic/esiopvar.h: revision 1.13 via patch
sys/dev/ic/esiop.c: revision 1.34 via patch
sys/dev/microcode/siop/esiop.ss: revision 1.20 via patch
sys/dev/ic/siopvar.h: revision 1.22 via patch
sys/dev/microcode/siop/siop.ss: revision 1.20 via patch
Some drives disconnect after the last data phase without a save data pointer
message. In such case we would not update resid with the proper value
(eventually resid would not be updated at all if there was only one data
phase). To fix this, have the script save the offset in the data tables at
disconnect time if there was a transfer, and use this to compute the resid
if the current offset is 0.
Problem reported and patch tested by edwin, Roy Bixler and YAMAMOTO Takashi.
Fix kern/31990 by YAMAMOTO Takashi.
 1.72.4.4 11-May-2005  snj branches: 1.72.4.4.2;
Pull up revision 1.76 (requested by bouyer in ticket #1367):
Add missing return, fix handling of Ignore Wide Residue messages.
 1.72.4.3 11-May-2005  snj Pull up revision 1.75 (requested by bouyer in ticket #1366):
Add support for the Ignore Wide Residue SCSI message.
 1.72.4.2 11-May-2005  snj Pull up revision 1.74 (requested by bouyer in ticket #1365):
when an unexpected disconnect occurs only compute the resid; do the
real save data pointers when we get the message (or rather, at disconnect
time following the message).
Factor out code to do this, and to deal with xs->resid, in siop_common.c.
 1.72.4.1 11-May-2005  snj Pull up revision 1.73 (requested by bouyer in ticket #1364):
Properly compute xs->resid, instead of assuming it'll always be 0 when
a command is done.
 1.72.4.4.2.1 01-Dec-2005  riz Pull up following revision(s) (requested by bouyer in ticket #10168):
sys/dev/ic/siop.c: revision 1.79 via patch
sys/dev/ic/siopvar_common.h: revision 1.33 via patch
sys/dev/ic/esiopvar.h: revision 1.13 via patch
sys/dev/ic/esiop.c: revision 1.34 via patch
sys/dev/microcode/siop/esiop.ss: revision 1.20 via patch
sys/dev/ic/siopvar.h: revision 1.22 via patch
sys/dev/microcode/siop/siop.ss: revision 1.20 via patch
Some drives disconnect after the last data phase without a save data pointer
message. In such case we would not update resid with the proper value
(eventually resid would not be updated at all if there was only one data
phase). To fix this, have the script save the offset in the data tables at
disconnect time if there was a transfer, and use this to compute the resid
if the current offset is 0.
Problem reported and patch tested by edwin, Roy Bixler and YAMAMOTO Takashi.
Fix kern/31990 by YAMAMOTO Takashi.
 1.76.6.2 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.76.6.1 12-Feb-2005  yamt sync with head.
 1.76.4.1 29-Apr-2005  kent sync with -current
 1.78.10.1 22-Nov-2005  yamt sync with head.
 1.78.4.4 27-Oct-2007  yamt sync with head.
 1.78.4.3 03-Sep-2007  yamt sync with head.
 1.78.4.2 30-Dec-2006  yamt sync with head.
 1.78.4.1 21-Jun-2006  yamt sync with head.
 1.78.2.1 21-Nov-2005  tron Pull up following revision(s) (requested by bouyer in ticket #973):
sys/dev/ic/siop.c: revision 1.79
sys/dev/ic/siopvar_common.h: revision 1.33
sys/dev/ic/esiopvar.h: revision 1.13
sys/dev/ic/esiop.c: revision 1.34
sys/dev/microcode/siop/esiop.ss: revision 1.20
sys/dev/ic/siopvar.h: revision 1.22
sys/dev/microcode/siop/siop.ss: revision 1.20
Some drives disconnect after the last data phase without a save data pointer
message. In such case we would not update resid with the proper value
(eventually resid would not be updated at all if there was only one data
phase). To fix this, have the script save the offset in the data tables at
disconnect time if there was a transfer, and use this to compute the resid
if the current offset is 0.
Problem reported and patch tested by edwin, Roy Bixler and YAMAMOTO Takashi.
Fix kern/31990 by YAMAMOTO Takashi.
 1.80.22.1 10-Dec-2006  yamt sync with head.
 1.80.20.1 18-Nov-2006  ad Sync with head.
 1.82.4.1 12-Mar-2007  rmind Sync with HEAD.
 1.83.18.1 06-Oct-2007  yamt sync with head.
 1.83.16.1 06-Nov-2007  matt sync with HEAD
 1.83.14.2 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.83.14.1 02-Oct-2007  joerg Sync with HEAD.
 1.83.2.2 23-Oct-2007  ad Sync with head.
 1.83.2.1 09-Oct-2007  ad Sync with head.
 1.84.2.1 25-Oct-2007  bouyer Sync with HEAD.
 1.85.16.2 02-Jun-2008  mjf Sync with HEAD.
 1.85.16.1 03-Apr-2008  mjf Sync with HEAD.
 1.87.18.2 23-Jul-2009  jym Sync with HEAD.
 1.87.18.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.87.14.2 20-Nov-2010  riz Fix patch from ticket 1390; bad merge from -current to netbsd-5.
 1.87.14.1 20-Nov-2010  riz Pull up following revision(s) (requested by mhitch in ticket #1390):
sys/dev/ic/siop.c: revision 1.95
sys/dev/ic/esiop.c: revision 1.52
Improve error paths in (e)siop_scsipi_request():
- When terminating the adapter request after the cmd has been removed
from the free list, put that cmd back on the free list before returing.
- Correctly indicate which bus_dma_load() failed.
Analysis and fix from Michael L. Hitch in PR/42844.
 1.87.12.1 28-Apr-2009  skrll Sync with HEAD.
 1.87.4.6 09-Oct-2010  yamt sync with head
 1.87.4.5 11-Aug-2010  yamt sync with head.
 1.87.4.4 11-Mar-2010  yamt sync with head
 1.87.4.3 16-Sep-2009  yamt sync with head
 1.87.4.2 16-May-2009  yamt sync with head
 1.87.4.1 04-May-2009  yamt sync with head.
 1.94.4.2 05-Mar-2011  rmind sync with head
 1.94.4.1 30-May-2010  rmind sync with head
 1.94.2.3 22-Oct-2010  uebayasi Sync with HEAD (-D20101022).
 1.94.2.2 17-Aug-2010  uebayasi Sync with HEAD.
 1.94.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.98.22.1 18-May-2014  rmind sync with head
 1.98.18.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.98.8.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.100.46.1 21-Mar-2021  thorpej Give config_found() the same variadic arguments treatment as
config_search(). This commit only adds the CFARG_EOL sentinel
to the existing config_found() calls. Conversion of config_found_sm_loc()
and config_found_ia() call sites will be in subsequent commits.
 1.101.8.1 04-Aug-2021  thorpej Adapt to CFARGS().
 1.60 08-Feb-2024  andvar s/should't/shouldn't/ and s/mistmatch/mismatch/ in comments.
 1.59 25-Sep-2022  thorpej Remove unnecessary include of <sys/malloc.h>.
 1.58 03-Jun-2022  andvar fix folloing->following typos in more files.
also s/begginning/beginning/.
 1.57 23-May-2022  andvar s/beggining/beginning/ in comments.
 1.56 22-May-2022  andvar fix various small typos, mainly in comments.
 1.55 27-Dec-2019  msaitoh s/transfered/transferred/
 1.54 15-Sep-2013  martin branches: 1.54.30;
Remove unused variable/ifdef like use
 1.53 13-Nov-2010  uebayasi branches: 1.53.8; 1.53.18; 1.53.22;
Don't pull in the whole uvm(9) API to access only PAGE_SIZE and
some other constants. These are provided by sys/param.h now.
 1.52 19-Oct-2009  bouyer branches: 1.52.4;
Remove closes 3 & 4 from my licence. Lots of thanks to Soren Jacobsen
for the booring work !
 1.51 04-Sep-2009  tsutsui Remove unnecessary whitespace.
 1.50 16-May-2009  tsutsui Misc cleanup:
- some KNF
- u_intNN_t -> uintNN_t
- wrap long lines and fix indent
- remove return statements at the end of void functions
- use __arraycount()

XXX: many inconsistent aprint_error_dev(9) vs printf(9)
 1.49 15-May-2009  tsutsui Split device_t/softc.

No crash on:
esiop0 at pci0 dev 11 function 0: Symbios Logic 53c875 (ultra-wide scsi)
siop0 at pci0 dev 9 function 0: Symbios Logic 53c810a (fast scsi)
siop0 at gsc0 hpa 0xf0830000 path 2/0/7 irq 3 ipl 6: NCR53C720 rev 2
 1.48 14-Mar-2009  dsl ANSIfy another 1261 function definitions.
The only ones left in sys are beyond by sed script!
(or in sys/dist or sys/external)
Mostly they have function pointer parameters.
 1.47 14-Mar-2009  dsl Change about 4500 of the K&R function definitions to ANSI ones.
There are still about 1600 left, but they have ',' or /* ... */
in the actual variable definitions - which my awk script doesn't handle.
There are also many that need () -> (void).
(The script does handle misordered arguments.)
 1.46 11-Jun-2008  kiyohara branches: 1.46.4; 1.46.10;
Support use PCI Clock(SF_CHIP_USEPCIC). We can set the value "use_pciclock"
by prop_dictionary_set_bool().
 1.45 08-Apr-2008  cegger branches: 1.45.2; 1.45.4; 1.45.6; 1.45.8;
use aprint_*_dev and device_xname
 1.44 27-Mar-2008  skrll Add support for the (non-pci) NCR 53c720/770 in big-endian mode.

From OpenBSD (Mark Kettenis)
 1.43 19-Oct-2007  ad branches: 1.43.16;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.42 04-Mar-2007  christos branches: 1.42.2; 1.42.14; 1.42.16; 1.42.20;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.41 16-Nov-2006  christos branches: 1.41.4;
__unused removal on arguments; approved by core.
 1.40 12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.39 03-Sep-2006  christos branches: 1.39.2; 1.39.4;
add missing decl.
 1.38 26-Nov-2005  tsutsui branches: 1.38.4; 1.38.8;
FALLTHROUH -> FALLTHROUGH (from OpenBSD)
 1.37 27-Feb-2005  perry branches: 1.37.4; 1.37.10;
nuke trailing whitespace
 1.36 17-May-2004  bouyer branches: 1.36.4; 1.36.6;
Add support for the Ignore Wide Residue SCSI message.
 1.35 17-May-2004  bouyer when an unexpected disconnect occurs only compute the resid; do the
real save data pointers when we get the message (or rather, at disconnect
time following the message).
Factor out code to do this, and to deal with xs->resid, in siop_common.c.
 1.34 17-May-2004  bouyer Properly compute xs->resid, instead of assuming it'll always be 0 when
a command is done.
 1.33 10-Mar-2004  bouyer branches: 1.33.4;
The 1010-66 always generate AIP values on the bus, regardless of the SCNTL4
settings. Disable AIP completely, as this confuse pre-Ultra160 drives.
From FreeBSD.
 1.32 31-Jan-2003  thorpej branches: 1.32.2;
Use aprint_*().
 1.31 27-Sep-2002  provos remove trailing \n in panic(). approved perry.
 1.30 29-Aug-2002  bouyer The 1010 will generate a scsi gross error if a RAM entry is read before being
written (i.e. is used uninitialised). The esiop SCRIPT may do this in some
circonstances (and it is safe) so bus_space_set_region_4() the RAM in
reset routine.
Problem reported and fix tested by Allen Briggs.
 1.29 18-Jul-2002  wiz Spell 'should' correctly.
 1.28 05-May-2002  bouyer branches: 1.28.2; 1.28.4;
Don't disable TARF_TAG when the 1010 workaround is active, otherwise
the target won't do tagged queuing again after e.g. a bus reset.
Just report to scsipi that we can't do tagged queuing.
 1.27 04-May-2002  bouyer Keep track of the current SCSI mode (SE/HVD/LVD) and don't start PPR
negotiation if it's not a LVD bus.
Remove write to SIOP_STEST0, it's bogus and I don't know why it's there at
the first place.
 1.26 04-May-2002  bouyer It seems that the 1010-33 has a bug: it sometimes generate spurious SCSI gross
errors for narrow transfers after a reselect. FreeBSD sym driver has a comment
about this, but their workaround (disable SCSI gross error reports) doesn't
work for me. Instead dissallow disconnect if the target is not wide
(FreeBSD doens't allow disconnect until the target has been fully probed, which
is why they may not have noticed my problem).
 1.25 29-Apr-2002  bouyer Factor out initialisation of t_msgout.count
clear scntl4 in sdtr/wdtr negotiation
 1.24 25-Apr-2002  bouyer It's not safe to access the SCNTL1 register while the SCRIPT is running.
On the 1010 this can wedge the chip. So abort the script instead.
the abort interrupt will trigger a bus reset.
 1.23 23-Apr-2002  bouyer More copyright fixes, pointed out by Thomas. Thanks !
 1.22 23-Apr-2002  bouyer - factor out parts of (e)siop_attach() to siop_common_attach()
- Add support for DT transfers (aka Ultra/160) in esiop

Note that DT transfers are not enabled for 53c1010-33 rev 0 yet; if I trust
FreeBSD it has a bug which prevent them to do DT properly.
From the same source there may be issues with some revs of 53c1010-66.
 1.21 23-Apr-2002  bouyer Enable software LED control based on LED0 feature, not #define.
For now, set the LED0 feature if SIOP_SYMLED is defined in siop_pci_common.c.
From Jason R Thorpe.
 1.20 22-Apr-2002  bouyer Really, don't set siop_cmd->tag in setup_table()
 1.19 22-Apr-2002  bouyer Fix last change: assign siop_cmd->tag in callers instead of siop_setuptables(),
and use siop_cmd->tag instead of xs->xs_tag_id. This way siop can use
xs->xs_tag_id + 1 without interferences with esiop.
 1.18 22-Apr-2002  bouyer In siop_setuptables(), use the proposed tag_id, not tag_id +1.
In siop.c bump siop_cmd->tag by one as tag id 0 is reserved for untagged cmds.
 1.17 20-Apr-2002  bouyer Move a few things around, so that ic/siop_common.c and pci/siop_pci_common.c
can be compiled without including siopvar.h.
 1.16 18-Apr-2002  bouyer If SIOP_SYMLED is defined, drive the activity LED though GPIO pin 1.
 1.15 13-Nov-2001  lukem add/cleanup RCSID
 1.14 25-Apr-2001  bouyer branches: 1.14.2;
Pull up the thorpej_scsipi branch to main branch.
This is a completely rewritten scsipi_xfer execution engine, and the
associated changes to HBA drivers. Overview of changes & features:
- All xfers are queued in the mid-layer, rather than doing so in an
ad-hoc fashion in individual adapter drivers.
- Adapter/channel resource management in the mid-layer, avoids even trying
to start running an xfer if the adapter/channel doesn't have the resources.
- Better communication between the mid-layer and the adapters.
- Asynchronous event notification mechanism from adapter to mid-layer and
peripherals.
- Better peripheral queue management: freeze/thaw, sorted requeueing during
recovery, etc.
- Clean separation of peripherals, adapters, and adapter channels (no more
scsipi_link).
- Kernel thread for each scsipi_channel makes error recovery much easier
(no more dealing with interrupt context when recovering from an error).
- Mid-layer support for tagged queueing: commands can have the tag type
set explicitly, tag IDs are allocated in the mid-layer (thus eliminating
the need to use buggy tag ID allocation schemes in many adapter drivers).
- support for QUEUE FULL and CHECK CONDITION status in mid-layer; the command
will be requeued, or a REQUEST SENSE will be sent as appropriate.

Just before the merge syssrc has been tagged with thorpej_scsipi_beforemerge
 1.13 12-Mar-2001  bouyer Preliminary support for SYM53C1010-33 (at 80MB/s only for now), based on
patches sent by Matthias Drochner <M.Drochner@fz-juelich.de> and
Kenneth R Westerback <kwesterback@home.com>
 1.12 11-Feb-2001  bouyer branches: 1.12.2;
Avoid sending new commands to the device if it has sense pending:
- run request sense command without disconnect
- don't restart the script before siop_scsicmd_end has been called if the
cmd didn't complete with good status.
- reserve slot 0 for request sense, to make sure it'll be sent first.
 1.11 23-Oct-2000  bouyer branches: 1.11.2;
Fixes related to QUEUE FULL status:
- move status handling in siop_scsicmd_end(), it's better than in siop_intr()
- define 2 internal SIOP status, for "no status reported by device" and
reset condition
- add a list of "urgent" command, to be executed before the list of command
queued the normal way; this is used for command which got aborted
by a QUEUE FULL and have to be requeued in order.
- Don't accept to send a Q_TAG message not immediatly folowing a IDENTIFY
 1.10 23-Oct-2000  bouyer Rearrange for script changes (scheduler core in main script, command part
of the scheduler in command table).
Add tagged command queuing support.
 1.9 18-Oct-2000  bouyer Adapt for new lun switch script.
Implement SCBUSACCEL ioctl.
Snapshot of work in progress on tagged queuing: we can send/receive
queue tag messages. Infrastructure to manage multiple commands per
devices not here yet.
 1.8 06-Oct-2000  bouyer Fix recurent typo: shed->sched
 1.7 06-Oct-2000  bouyer Adapt for reselect handling from the script. While here, fix typo
(SIOP_SCXFER -> SIOP_SXFER).
 1.6 24-Jul-2000  bouyer create a funcion, siop_busreset(), to reset the scsibus.
Reset the scsi bus at attach time, to be sure all devices start in narrow/async
mode.
Defer sync/wide negotiation until after whe have a valid
xs->sc_link->device_softc, so that we can honnor the NOSYNC/NOWIDE quirks.
 1.5 28-Jun-2000  mrg remove include of <vm/vm.h>. <vm/vm.h> -> <uvm/uvm_extern.h>
 1.4 26-Jun-2000  mrg remove/move more mach vm header files:

<vm/pglist.h> -> <uvm/uvm_pglist.h>
<vm/vm_inherit.h> -> <uvm/uvm_inherit.h>
<vm/vm_kern.h> -> into <uvm/uvm_extern.h>
<vm/vm_object.h> -> nothing
<vm/vm_pager.h> -> into <uvm/uvm_pager.h>

also includes a bunch of <vm/vm_page.h> include removals (due to redudancy
with <vm/vm.h>), and a scattering of other similar headers.
 1.3 12-Jun-2000  bouyer branches: 1.3.2;
Handle "scsi bus mode change" interrupts on 895 and higther.
Thanks to Hal Murray for reporting the problem and testing the fix.
 1.2 15-May-2000  bouyer branches: 1.2.2;
Don't enable debug message by default.
 1.1 15-May-2000  bouyer - split siop.c in script-dependant vs script-independant part, for
comming esiop
- add a reset callback for bus-dependant registers settings
 1.2.2.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.3.2.4 29-Jan-2002  he Pull up revision 1.13 (requested by bouyer):
Add support for the 53c1010-33, and bring documentation up to
date.
 1.3.2.3 26-Feb-2001  he Pull up revision 1.12 (requested by bouyer):
Don't queue new commands to a device which has sense pending.
 1.3.2.2 16-Dec-2000  he Pull up revisions 1.7-1.11 (requested by bouyer):
Speed improvements to the siop driver, and add tagged queueing
support. As a side effect, better handling of some not so common
phase or message sequences.
 1.3.2.1 24-Jul-2000  bouyer Pull up (approved by thorpej):
sys/dev/ic/siop.c 1.25->1.26
sys/dev/ic/siop_common.c 1.5->1.6
sys/dev/ic/siopvar_common.h 1.3->1.4

create a funcion, siop_busreset(), to reset the scsibus.
Reset the scsi bus at attach time, to be sure all devices start in narrow/async
mode.
Defer sync/wide negotiation until after whe have a valid
xs->sc_link->device_softc, so that we can honnor the NOSYNC/NOWIDE quirks.
 1.11.2.8 03-Apr-2001  bouyer Remove local command queue; if we run out of start slots, just freeze the
channel; and unfreeze it at the first command complete.
 1.11.2.7 12-Mar-2001  bouyer Sync with HEAD.
 1.11.2.6 22-Jan-2001  bouyer Put URGENT requests in the urgent queue
When we get CHECK CONDITION, remove and requeue all xfer for this T/L that have
not yet been queued in the device (still in a scheduler slot or in the queues),
otherwise if one of them is accepted before the request sense, sense will be
lost.
Don't allow disconnect for REQUEST SENSE commands, as others drivers do.
 1.11.2.5 15-Jan-2001  bouyer Pass CHECK CONDITION status and reset events to the mid-layer.
 1.11.2.4 15-Dec-2000  bouyer Tell the upper layer we can do tagged queuing, so that it sends us more
than one concurent command. Leave the handling of QUEUE FULL events to the
upper layer.
 1.11.2.3 14-Dec-2000  bouyer Convert to thorpej_scsipi interface. Still some work to do to get all benefits
of the new middle layer, but it works.
 1.11.2.2 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.11.2.1 23-Oct-2000  bouyer file siop_common.c was added on branch thorpej_scsipi on 2000-11-20 11:40:55 +0000
 1.12.2.7 18-Oct-2002  nathanw Catch up to -current.
 1.12.2.6 29-Aug-2002  briggs Sync with head
 1.12.2.5 01-Aug-2002  nathanw Catch up to -current.
 1.12.2.4 20-Jun-2002  nathanw Catch up to -current.
 1.12.2.3 14-Nov-2001  nathanw Catch up to -current.
 1.12.2.2 21-Jun-2001  nathanw Catch up to -current.
 1.12.2.1 09-Apr-2001  nathanw Catch up with -current.
 1.14.2.4 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.14.2.3 06-Sep-2002  jdolecek sync kqueue branch with HEAD
 1.14.2.2 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.14.2.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.28.4.5 19-Mar-2005  tron Pull up revision 1.36 (requested by bouyer in ticket #1751):
Add support for the Ignore Wide Residue SCSI message.
 1.28.4.4 17-Mar-2005  tron Pull up revision 1.35 (requested by bouyer in ticket #1750):
when an unexpected disconnect occurs only compute the resid; do the
real save data pointers when we get the message (or rather, at disconnect
time following the message).
Factor out code to do this, and to deal with xs->resid, in siop_common.c.
 1.28.4.3 17-Mar-2005  tron Pull up revision 1.34 (requested by bouyer in ticket #1749):
Properly compute xs->resid, instead of assuming it'll always be 0 when
a command is done.
 1.28.4.2 17-Mar-2005  tron Pull up revision 1.33 (requested by bouyer in ticket #1748):
The 1010-66 always generate AIP values on the bus, regardless of the SCNTL4
settings. Disable AIP completely, as this confuse pre-Ultra160 drives.
From FreeBSD.
 1.28.4.1 24-Nov-2002  tron Pull up revision 1.30 (requested by bouyer in ticket #747):
The 1010 will generate a scsi gross error if a RAM entry is read before being
written (i.e. is used uninitialised). The esiop SCRIPT may do this in some
circonstances (and it is safe) so bus_space_set_region_4() the RAM in
reset routine.
Problem reported and fix tested by Allen Briggs.
 1.28.2.2 31-Aug-2002  gehenna catch up with -current.
 1.28.2.1 20-Jul-2002  gehenna catch up with -current.
 1.32.2.5 11-Dec-2005  christos Sync with head.
 1.32.2.4 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.32.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.32.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.32.2.1 03-Aug-2004  skrll Sync with HEAD
 1.33.4.3 11-May-2005  snj Pull up revision 1.36 (requested by bouyer in ticket #1366):
Add support for the Ignore Wide Residue SCSI message.
 1.33.4.2 11-May-2005  snj Pull up revision 1.35 (requested by bouyer in ticket #1365):
when an unexpected disconnect occurs only compute the resid; do the
real save data pointers when we get the message (or rather, at disconnect
time following the message).
Factor out code to do this, and to deal with xs->resid, in siop_common.c.
 1.33.4.1 11-May-2005  snj Pull up revision 1.34 (requested by bouyer in ticket #1364):
Properly compute xs->resid, instead of assuming it'll always be 0 when
a command is done.
 1.36.6.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.36.4.1 29-Apr-2005  kent sync with -current
 1.37.10.1 29-Nov-2005  yamt sync with head.
 1.37.4.4 27-Oct-2007  yamt sync with head.
 1.37.4.3 03-Sep-2007  yamt sync with head.
 1.37.4.2 30-Dec-2006  yamt sync with head.
 1.37.4.1 21-Jun-2006  yamt sync with head.
 1.38.8.1 03-Sep-2006  yamt sync with head.
 1.38.4.1 09-Sep-2006  rpaulo sync with head
 1.39.4.2 10-Dec-2006  yamt sync with head.
 1.39.4.1 22-Oct-2006  yamt sync with head
 1.39.2.1 18-Nov-2006  ad Sync with head.
 1.41.4.1 12-Mar-2007  rmind Sync with HEAD.
 1.42.20.1 25-Oct-2007  bouyer Sync with HEAD.
 1.42.16.1 06-Nov-2007  matt sync with HEAD
 1.42.14.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.42.2.1 23-Oct-2007  ad Sync with head.
 1.43.16.3 29-Jun-2008  mjf Sync with HEAD.
 1.43.16.2 02-Jun-2008  mjf Sync with HEAD.
 1.43.16.1 03-Apr-2008  mjf Sync with HEAD.
 1.45.8.1 18-Jun-2008  simonb Sync with head.
 1.45.6.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.45.4.4 11-Mar-2010  yamt sync with head
 1.45.4.3 16-Sep-2009  yamt sync with head
 1.45.4.2 16-May-2009  yamt sync with head
 1.45.4.1 04-May-2009  yamt sync with head.
 1.45.2.1 17-Jun-2008  yamt sync with head.
 1.46.10.2 23-Jul-2009  jym Sync with HEAD.
 1.46.10.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.46.4.1 28-Apr-2009  skrll Sync with HEAD.
 1.52.4.1 05-Mar-2011  rmind sync with head
 1.53.22.1 18-May-2014  rmind sync with head
 1.53.18.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.53.8.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.54.30.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.22 19-Oct-2009  bouyer Remove closes 3 & 4 from my licence. Lots of thanks to Soren Jacobsen
for the booring work !
 1.21 04-Sep-2009  tsutsui u_intNN_t -> uintNN_t
 1.20 11-Jun-2008  kiyohara Support use PCI Clock(SF_CHIP_USEPCIC). We can set the value "use_pciclock"
by prop_dictionary_set_bool().
 1.19 27-Mar-2008  skrll branches: 1.19.2; 1.19.4; 1.19.6; 1.19.8;
Add support for the (non-pci) NCR 53c720/770 in big-endian mode.

From OpenBSD (Mark Kettenis)
 1.18 25-Dec-2007  perry branches: 1.18.6;
Convert many of the uses of __attribute__ to equivalent
__packed, __unused and __dead macros from cdefs.h
 1.17 11-Dec-2005  christos branches: 1.17.46; 1.17.52; 1.17.56; 1.17.60;
merge ktrace-lwp.
 1.16 27-Feb-2005  perry branches: 1.16.4;
nuke trailing whitespace
 1.15 02-Nov-2003  wiz branches: 1.15.8; 1.15.10;
Fix some typos. From Tom Cosgrove via jmc@openbsd.
 1.14 21-Feb-2003  tsutsui branches: 1.14.2;
hz -> Hz
 1.13 29-Aug-2002  bouyer Add definitions for the AIP control registers (1010 only).
 1.12 04-May-2002  bouyer branches: 1.12.2; 1.12.4;
Add 1010 only SCSI gross error disable bits.
 1.11 23-Apr-2002  bouyer More copyright fixes, pointed out by Thomas. Thanks !
 1.10 23-Apr-2002  bouyer - factor out parts of (e)siop_attach() to siop_common_attach()
- Add support for DT transfers (aka Ultra/160) in esiop

Note that DT transfers are not enabled for 53c1010-33 rev 0 yet; if I trust
FreeBSD it has a bug which prevent them to do DT properly.
From the same source there may be issues with some revs of 53c1010-66.
 1.9 18-Apr-2002  thorpej Define the Symbios Logic and Tekram NVRAM contents.
 1.8 12-Mar-2001  bouyer branches: 1.8.2;
Preliminary support for SYM53C1010-33 (at 80MB/s only for now), based on
patches sent by Matthias Drochner <M.Drochner@fz-juelich.de> and
Kenneth R Westerback <kwesterback@home.com>
 1.7 06-Oct-2000  bouyer branches: 1.7.2; 1.7.4;
Adapt for reselect handling from the script. While here, fix typo
(SIOP_SCXFER -> SIOP_SXFER).
 1.6 12-Jun-2000  bouyer branches: 1.6.2;
Handle "scsi bus mode change" interrupts on 895 and higther.
Thanks to Hal Murray for reporting the problem and testing the fix.
 1.5 15-May-2000  bouyer branches: 1.5.2;
- split siop.c in script-dependant vs script-independant part, for
comming esiop
- add a reset callback for bus-dependant registers settings
 1.4 02-May-2000  bouyer - do sync/wide negotiation
- use a circular queue for the start slots, so that order has better chances
to be preserved.
 1.3 27-Apr-2000  bouyer Fix copyrigth notice.
 1.2 25-Apr-2000  bouyer - Change the script to start new commands in an asyncronous way, using
'command slots' in which the host can put command and wait for the script
to start them
- Change siop.c to do full disconnect/reslelect, allowing as much as one
command per target/lun to run in parallel.
- Fix bug in registers init where a board without BIOS would end at
ID 0 (now the driver works on alpha too).
- better handling of messages, sending back a MSG_EXT_SDTR in response to an
incoming MSG_EXT_SDTR, and MSG_MESSAGE_REJECT for unhandled messages.
- fix use of bus_dmamap_sync() and htole32().
- supports shared interrups
- change some int8 and int16 to int, for alpha and mips benefits ( suggested by
Toru Nishimura)
 1.1 21-Apr-2000  bouyer Snapshot of work in progress: new driver for the NCR 53c8xx SCSI controller
(the name 'siop' is still being discussed, may change).
Only basic disconnect/reselect for now, no sync/wide negotiation.
Tested with 810A, 875 and 895 on i386 only.
The bus-independant part should also be able to handle the 53c720 and 53c770.
A new driver with enhanced script should appear for the 825/875/895 'soon'.
 1.5.2.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.6.2.2 29-Jan-2002  he Pull up revision 1.8 (requested by bouyer):
Add support for the 53c1010-33, and bring documentation up to
date.
 1.6.2.1 15-Dec-2000  he Pull up revision 1.7 (requested by bouyer):
Speed improvements to the siop driver, and add tagged queueing
support. As a side effect, better handling of some not so common
phase or message sequences.
 1.7.4.3 17-Sep-2002  nathanw Catch up to -current.
 1.7.4.2 20-Jun-2002  nathanw Catch up to -current.
 1.7.4.1 09-Apr-2001  nathanw Catch up with -current.
 1.7.2.3 12-Mar-2001  bouyer Sync with HEAD.
 1.7.2.2 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.7.2.1 06-Oct-2000  bouyer file siopreg.h was added on branch thorpej_scsipi on 2000-11-20 11:40:55 +0000
 1.8.2.2 06-Sep-2002  jdolecek sync kqueue branch with HEAD
 1.8.2.1 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.12.4.1 24-Nov-2002  tron Pull up revision 1.13 (requested by bouyer in ticket #747):
Add definitions for the AIP control registers (1010 only).
 1.12.2.1 31-Aug-2002  gehenna catch up with -current.
 1.14.2.4 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.14.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.14.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.14.2.1 03-Aug-2004  skrll Sync with HEAD
 1.15.10.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.15.8.1 29-Apr-2005  kent sync with -current
 1.16.4.1 21-Jan-2008  yamt sync with head
 1.17.60.1 02-Jan-2008  bouyer Sync with HEAD
 1.17.56.1 26-Dec-2007  ad Sync with head.
 1.17.52.1 18-Feb-2008  mjf Sync with HEAD.
 1.17.46.1 09-Jan-2008  matt sync with HEAD
 1.18.6.2 29-Jun-2008  mjf Sync with HEAD.
 1.18.6.1 03-Apr-2008  mjf Sync with HEAD.
 1.19.8.1 18-Jun-2008  simonb Sync with head.
 1.19.6.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.19.4.3 11-Mar-2010  yamt sync with head
 1.19.4.2 16-Sep-2009  yamt sync with head
 1.19.4.1 04-May-2009  yamt sync with head.
 1.19.2.1 17-Jun-2008  yamt sync with head.
 1.29 24-Aug-2012  msaitoh Fix typos
 1.28 19-Oct-2009  bouyer branches: 1.28.12;
Remove closes 3 & 4 from my licence. Lots of thanks to Soren Jacobsen
for the booring work !
 1.27 04-Sep-2009  tsutsui u_intNN_t -> uintNN_t
 1.26 15-Mar-2009  cegger ansify function definitions
 1.25 25-Dec-2007  perry branches: 1.25.10; 1.25.18; 1.25.24;
Convert many of the uses of __attribute__ to equivalent
__packed, __unused and __dead macros from cdefs.h
 1.24 16-Feb-2006  perry branches: 1.24.40; 1.24.46; 1.24.50; 1.24.54;
Change "inline" back to "__inline" in .h files -- C99 is still too
new, and some apps compile things in C89 mode. C89 keywords stay.

As per core@.
 1.23 24-Dec-2005  perry branches: 1.23.2; 1.23.4; 1.23.6;
__inline__ -> inline
 1.22 18-Nov-2005  bouyer Some drives disconnect after the last data phase without a save data pointer
message. In such case we would not update resid with the proper value
(eventually resid would not be updated at all if there was only one data
phase). To fix this, have the script save the offset in the data tables at
disconnect time if there was a transfer, and use this to compute the resid
if the current offset is 0.
Problem reported and patch tested by edwin, Roy Bixler and YAMAMOTO Takashi.
Fix kern/31990 by YAMAMOTO Takashi.
 1.21 27-Feb-2005  perry branches: 1.21.2; 1.21.4; 1.21.10;
nuke trailing whitespace
 1.20 04-Feb-2005  perry de-__P
 1.19 02-Nov-2003  wiz branches: 1.19.6; 1.19.8; 1.19.10; 1.19.12;
Fix some typos. From Tom Cosgrove via jmc@openbsd.
 1.18 23-Apr-2002  bouyer branches: 1.18.4; 1.18.10;
More copyright fixes, pointed out by Thomas. Thanks !
 1.17 20-Apr-2002  bouyer Move a few things around, so that ic/siop_common.c and pci/siop_pci_common.c
can be compiled without including siopvar.h.
 1.16 25-Apr-2001  bouyer branches: 1.16.2;
Pull up the thorpej_scsipi branch to main branch.
This is a completely rewritten scsipi_xfer execution engine, and the
associated changes to HBA drivers. Overview of changes & features:
- All xfers are queued in the mid-layer, rather than doing so in an
ad-hoc fashion in individual adapter drivers.
- Adapter/channel resource management in the mid-layer, avoids even trying
to start running an xfer if the adapter/channel doesn't have the resources.
- Better communication between the mid-layer and the adapters.
- Asynchronous event notification mechanism from adapter to mid-layer and
peripherals.
- Better peripheral queue management: freeze/thaw, sorted requeueing during
recovery, etc.
- Clean separation of peripherals, adapters, and adapter channels (no more
scsipi_link).
- Kernel thread for each scsipi_channel makes error recovery much easier
(no more dealing with interrupt context when recovering from an error).
- Mid-layer support for tagged queueing: commands can have the tag type
set explicitly, tag IDs are allocated in the mid-layer (thus eliminating
the need to use buggy tag ID allocation schemes in many adapter drivers).
- support for QUEUE FULL and CHECK CONDITION status in mid-layer; the command
will be requeued, or a REQUEST SENSE will be sent as appropriate.

Just before the merge syssrc has been tagged with thorpej_scsipi_beforemerge
 1.15 15-Mar-2001  bouyer Note that SF_CHIP_QUAD is for clock quadrupler with busy wait for PPL.
SF_CHIP_DBLR is for clock doubler or quadrupler.
 1.14 12-Mar-2001  bouyer Preliminary support for SYM53C1010-33 (at 80MB/s only for now), based on
patches sent by Matthias Drochner <M.Drochner@fz-juelich.de> and
Kenneth R Westerback <kwesterback@home.com>
 1.13 23-Oct-2000  bouyer branches: 1.13.2; 1.13.4;
Fixes related to QUEUE FULL status:
- move status handling in siop_scsicmd_end(), it's better than in siop_intr()
- define 2 internal SIOP status, for "no status reported by device" and
reset condition
- add a list of "urgent" command, to be executed before the list of command
queued the normal way; this is used for command which got aborted
by a QUEUE FULL and have to be requeued in order.
- Don't accept to send a Q_TAG message not immediatly folowing a IDENTIFY
 1.12 23-Oct-2000  bouyer Rearrange for script changes (scheduler core in main script, command part
of the scheduler in command table).
Add tagged command queuing support.
 1.11 18-Oct-2000  bouyer Adapt for new lun switch script.
Implement SCBUSACCEL ioctl.
Snapshot of work in progress on tagged queuing: we can send/receive
queue tag messages. Infrastructure to manage multiple commands per
devices not here yet.
 1.10 06-Oct-2000  bouyer Fix recurent typo: shed->sched
 1.9 06-Oct-2000  bouyer Adapt for reselect handling from the script. While here, fix typo
(SIOP_SCXFER -> SIOP_SXFER).
 1.8 13-Jun-2000  bouyer branches: 1.8.2;
sheduler->scheduler, as pointed out by Klaus Klein
 1.7 25-May-2000  bouyer branches: 1.7.2;
Separate the sheduler from the main script, allocate another DMA-safe
memory page for the sheduler. Put the main script in the on-chip RAM when
available.
Avoid a null-pointer dereference when DSA is invalid.
 1.6 23-May-2000  bouyer Allocate dynamically the command block descriptors.
 1.5 15-May-2000  bouyer - split siop.c in script-dependant vs script-independant part, for
comming esiop
- add a reset callback for bus-dependant registers settings
 1.4 02-May-2000  bouyer - do sync/wide negotiation
- use a circular queue for the start slots, so that order has better chances
to be preserved.
 1.3 27-Apr-2000  bouyer Fix copyrigth notice.
 1.2 25-Apr-2000  bouyer - Change the script to start new commands in an asyncronous way, using
'command slots' in which the host can put command and wait for the script
to start them
- Change siop.c to do full disconnect/reslelect, allowing as much as one
command per target/lun to run in parallel.
- Fix bug in registers init where a board without BIOS would end at
ID 0 (now the driver works on alpha too).
- better handling of messages, sending back a MSG_EXT_SDTR in response to an
incoming MSG_EXT_SDTR, and MSG_MESSAGE_REJECT for unhandled messages.
- fix use of bus_dmamap_sync() and htole32().
- supports shared interrups
- change some int8 and int16 to int, for alpha and mips benefits ( suggested by
Toru Nishimura)
 1.1 21-Apr-2000  bouyer Snapshot of work in progress: new driver for the NCR 53c8xx SCSI controller
(the name 'siop' is still being discussed, may change).
Only basic disconnect/reselect for now, no sync/wide negotiation.
Tested with 810A, 875 and 895 on i386 only.
The bus-independant part should also be able to handle the 53c720 and 53c770.
A new driver with enhanced script should appear for the 825/875/895 'soon'.
 1.7.2.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.8.2.3 29-Jan-2002  he Pull up revisions 1.14-1.15 (requested by bouyer):
Add support for the 53c1010-33, and bring documentation up to
date.
 1.8.2.2 05-Jan-2002  he Apply patch (requested by bouyer):
Don't call siop_morecbd() in interrupt context, but pre-allocate
CBD at probe time instead. Fixes PR#13827, PR#14866 and PR#15048.
 1.8.2.1 15-Dec-2000  he Pull up revisions 1.9-1.13 (requested by bouyer):
Speed improvements to the siop driver, and add tagged queueing
support. As a side effect, better handling of some not so common
phase or message sequences.
 1.13.4.3 20-Jun-2002  nathanw Catch up to -current.
 1.13.4.2 21-Jun-2001  nathanw Catch up to -current.
 1.13.4.1 09-Apr-2001  nathanw Catch up with -current.
 1.13.2.6 03-Apr-2001  bouyer Remove local command queue; if we run out of start slots, just freeze the
channel; and unfreeze it at the first command complete.
 1.13.2.5 27-Mar-2001  bouyer Sync with HEAD.
 1.13.2.4 12-Mar-2001  bouyer Sync with HEAD.
 1.13.2.3 14-Dec-2000  bouyer Convert to thorpej_scsipi interface. Still some work to do to get all benefits
of the new middle layer, but it works.
 1.13.2.2 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.13.2.1 23-Oct-2000  bouyer file siopvar.h was added on branch thorpej_scsipi on 2000-11-20 11:40:55 +0000
 1.16.2.1 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.18.10.6 11-Dec-2005  christos Sync with head.
 1.18.10.5 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.18.10.4 04-Feb-2005  skrll Sync with HEAD.
 1.18.10.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.18.10.2 18-Sep-2004  skrll Sync with HEAD.
 1.18.10.1 03-Aug-2004  skrll Sync with HEAD
 1.18.4.1 14-Dec-2005  jmc Pullup via patch (requested in ticket #5957 by bouyer)
Some drives disconnect after the last data phase without a save data pointer
message. In such case we would not update resid with the proper value
(eventually resid would not be updated at all if there was only one data
phase). To fix this, have the script save the offset in the data tables at
disconnect time if there was a transfer, and use this to compute the resid
if the current offset is 0. PR#31990
 1.19.12.1 01-Dec-2005  riz Pull up following revision(s) (requested by bouyer in ticket #10168):
sys/dev/ic/siop.c: revision 1.79 via patch
sys/dev/ic/siopvar_common.h: revision 1.33 via patch
sys/dev/ic/esiopvar.h: revision 1.13 via patch
sys/dev/ic/esiop.c: revision 1.34 via patch
sys/dev/microcode/siop/esiop.ss: revision 1.20 via patch
sys/dev/ic/siopvar.h: revision 1.22 via patch
sys/dev/microcode/siop/siop.ss: revision 1.20 via patch
Some drives disconnect after the last data phase without a save data pointer
message. In such case we would not update resid with the proper value
(eventually resid would not be updated at all if there was only one data
phase). To fix this, have the script save the offset in the data tables at
disconnect time if there was a transfer, and use this to compute the resid
if the current offset is 0.
Problem reported and patch tested by edwin, Roy Bixler and YAMAMOTO Takashi.
Fix kern/31990 by YAMAMOTO Takashi.
 1.19.10.2 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.19.10.1 12-Feb-2005  yamt sync with head.
 1.19.8.1 29-Apr-2005  kent sync with -current
 1.19.6.1 01-Dec-2005  riz Pull up following revision(s) (requested by bouyer in ticket #10168):
sys/dev/ic/siop.c: revision 1.79 via patch
sys/dev/ic/siopvar_common.h: revision 1.33 via patch
sys/dev/ic/esiopvar.h: revision 1.13 via patch
sys/dev/ic/esiop.c: revision 1.34 via patch
sys/dev/microcode/siop/esiop.ss: revision 1.20 via patch
sys/dev/ic/siopvar.h: revision 1.22 via patch
sys/dev/microcode/siop/siop.ss: revision 1.20 via patch
Some drives disconnect after the last data phase without a save data pointer
message. In such case we would not update resid with the proper value
(eventually resid would not be updated at all if there was only one data
phase). To fix this, have the script save the offset in the data tables at
disconnect time if there was a transfer, and use this to compute the resid
if the current offset is 0.
Problem reported and patch tested by edwin, Roy Bixler and YAMAMOTO Takashi.
Fix kern/31990 by YAMAMOTO Takashi.
 1.21.10.1 22-Nov-2005  yamt sync with head.
 1.21.4.2 21-Jan-2008  yamt sync with head
 1.21.4.1 21-Jun-2006  yamt sync with head.
 1.21.2.1 21-Nov-2005  tron Pull up following revision(s) (requested by bouyer in ticket #973):
sys/dev/ic/siop.c: revision 1.79
sys/dev/ic/siopvar_common.h: revision 1.33
sys/dev/ic/esiopvar.h: revision 1.13
sys/dev/ic/esiop.c: revision 1.34
sys/dev/microcode/siop/esiop.ss: revision 1.20
sys/dev/ic/siopvar.h: revision 1.22
sys/dev/microcode/siop/siop.ss: revision 1.20
Some drives disconnect after the last data phase without a save data pointer
message. In such case we would not update resid with the proper value
(eventually resid would not be updated at all if there was only one data
phase). To fix this, have the script save the offset in the data tables at
disconnect time if there was a transfer, and use this to compute the resid
if the current offset is 0.
Problem reported and patch tested by edwin, Roy Bixler and YAMAMOTO Takashi.
Fix kern/31990 by YAMAMOTO Takashi.
 1.23.6.1 22-Apr-2006  simonb Sync with head.
 1.23.4.1 09-Sep-2006  rpaulo sync with head
 1.23.2.1 18-Feb-2006  yamt sync with head.
 1.24.54.1 02-Jan-2008  bouyer Sync with HEAD
 1.24.50.1 26-Dec-2007  ad Sync with head.
 1.24.46.1 18-Feb-2008  mjf Sync with HEAD.
 1.24.40.1 09-Jan-2008  matt sync with HEAD
 1.25.24.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.25.18.1 28-Apr-2009  skrll Sync with HEAD.
 1.25.10.3 11-Mar-2010  yamt sync with head
 1.25.10.2 16-Sep-2009  yamt sync with head
 1.25.10.1 04-May-2009  yamt sync with head.
 1.28.12.1 30-Oct-2012  yamt sync with head
 1.40 19-Oct-2009  bouyer Remove closes 3 & 4 from my licence. Lots of thanks to Soren Jacobsen
for the booring work !
 1.39 04-Sep-2009  tsutsui u_intNN_t -> uintNN_t
 1.38 04-Sep-2009  tsutsui Remove unnecessary whitespace.
 1.37 15-May-2009  tsutsui Split device_t/softc.

No crash on:
esiop0 at pci0 dev 11 function 0: Symbios Logic 53c875 (ultra-wide scsi)
siop0 at pci0 dev 9 function 0: Symbios Logic 53c810a (fast scsi)
siop0 at gsc0 hpa 0xf0830000 path 2/0/7 irq 3 ipl 6: NCR53C720 rev 2
 1.36 11-Jun-2008  kiyohara branches: 1.36.10;
Support use PCI Clock(SF_CHIP_USEPCIC). We can set the value "use_pciclock"
by prop_dictionary_set_bool().
 1.35 27-Mar-2008  skrll branches: 1.35.2; 1.35.4; 1.35.6; 1.35.8;
Add support for the (non-pci) NCR 53c720/770 in big-endian mode.

From OpenBSD (Mark Kettenis)
 1.34 04-Mar-2007  christos branches: 1.34.36;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.33 18-Nov-2005  bouyer branches: 1.33.26;
Some drives disconnect after the last data phase without a save data pointer
message. In such case we would not update resid with the proper value
(eventually resid would not be updated at all if there was only one data
phase). To fix this, have the script save the offset in the data tables at
disconnect time if there was a transfer, and use this to compute the resid
if the current offset is 0.
Problem reported and patch tested by edwin, Roy Bixler and YAMAMOTO Takashi.
Fix kern/31990 by YAMAMOTO Takashi.
 1.32 27-Feb-2005  perry branches: 1.32.2; 1.32.4; 1.32.10;
nuke trailing whitespace
 1.31 04-Feb-2005  perry de-__P
 1.30 01-Jul-2004  drochner branches: 1.30.4; 1.30.6;
put the __packed__ attribute close to the struct definition
(to appease gcc-3.4), and use the compiler-independant __packed
form for consistency
 1.29 17-May-2004  bouyer Add support for the Ignore Wide Residue SCSI message.
 1.28 17-May-2004  bouyer when an unexpected disconnect occurs only compute the resid; do the
real save data pointers when we get the message (or rather, at disconnect
time following the message).
Factor out code to do this, and to deal with xs->resid, in siop_common.c.
 1.27 10-Mar-2004  bouyer branches: 1.27.4;
The 1010-66 always generate AIP values on the bus, regardless of the SCNTL4
settings. Disable AIP completely, as this confuse pre-Ultra160 drives.
From FreeBSD.
 1.26 10-Nov-2003  wiz Spell address with two d's. Inspired by similar changes in OpenBSD,
originating from Jonathon Gray and forwarded by jmc@openbsd.
 1.25 02-Nov-2003  wiz Fix some typos. From Tom Cosgrove via jmc@openbsd.
 1.24 09-Apr-2003  thorpej branches: 1.24.2;
Use PAGE_SIZE rather than NBPG.
 1.23 21-Feb-2003  tsutsui hz -> Hz
 1.22 23-Oct-2002  christos remove duplicate cpp defs.
 1.21 04-May-2002  bouyer branches: 1.21.4;
Keep track of the current SCSI mode (SE/HVD/LVD) and don't start PPR
negotiation if it's not a LVD bus.
Remove write to SIOP_STEST0, it's bogus and I don't know why it's there at
the first place.
 1.20 04-May-2002  bouyer It seems that the 1010-33 has a bug: it sometimes generate spurious SCSI gross
errors for narrow transfers after a reselect. FreeBSD sym driver has a comment
about this, but their workaround (disable SCSI gross error reports) doesn't
work for me. Instead dissallow disconnect if the target is not wide
(FreeBSD doens't allow disconnect until the target has been fully probed, which
is why they may not have noticed my problem).
 1.19 23-Apr-2002  bouyer More copyright fixes, pointed out by Thomas. Thanks !
 1.18 23-Apr-2002  bouyer - factor out parts of (e)siop_attach() to siop_common_attach()
- Add support for DT transfers (aka Ultra/160) in esiop

Note that DT transfers are not enabled for 53c1010-33 rev 0 yet; if I trust
FreeBSD it has a bug which prevent them to do DT properly.
From the same source there may be issues with some revs of 53c1010-66.
 1.17 23-Apr-2002  bouyer Bump the space for SCSI messages from 8 to 16 octets, as 8 may not be
enouth for IDENTIFY + TAG + PPR.
Get rid of constants in C code by use of a offsetof macro.
 1.16 23-Apr-2002  bouyer Enable software LED control based on LED0 feature, not #define.
For now, set the LED0 feature if SIOP_SYMLED is defined in siop_pci_common.c.
From Jason R Thorpe.
 1.15 23-Apr-2002  bouyer Add some new features:
- SF_BUS_ULTRA3, for Ultra/3 (80Mhz) busses
- SF_CHIP_LEDC, led on GPIO0 with hardware control
- SF_CHIP_DT, support DT clocking.
 1.14 20-Apr-2002  bouyer Note that if siop_common_xfer is changed, the scripts need to be changed too.
 1.13 20-Apr-2002  bouyer Move a few things around, so that ic/siop_common.c and pci/siop_pci_common.c
can be compiled without including siopvar.h.
 1.12 22-Oct-2001  bouyer Forgot to add __attribute__((__packed__)) to one hardware structure.
 1.11 25-Apr-2001  bouyer branches: 1.11.2;
Pull up the thorpej_scsipi branch to main branch.
This is a completely rewritten scsipi_xfer execution engine, and the
associated changes to HBA drivers. Overview of changes & features:
- All xfers are queued in the mid-layer, rather than doing so in an
ad-hoc fashion in individual adapter drivers.
- Adapter/channel resource management in the mid-layer, avoids even trying
to start running an xfer if the adapter/channel doesn't have the resources.
- Better communication between the mid-layer and the adapters.
- Asynchronous event notification mechanism from adapter to mid-layer and
peripherals.
- Better peripheral queue management: freeze/thaw, sorted requeueing during
recovery, etc.
- Clean separation of peripherals, adapters, and adapter channels (no more
scsipi_link).
- Kernel thread for each scsipi_channel makes error recovery much easier
(no more dealing with interrupt context when recovering from an error).
- Mid-layer support for tagged queueing: commands can have the tag type
set explicitly, tag IDs are allocated in the mid-layer (thus eliminating
the need to use buggy tag ID allocation schemes in many adapter drivers).
- support for QUEUE FULL and CHECK CONDITION status in mid-layer; the command
will be requeued, or a REQUEST SENSE will be sent as appropriate.

Just before the merge syssrc has been tagged with thorpej_scsipi_beforemerge
 1.10 26-Jan-2001  bouyer branches: 1.10.2;
Fix a 4 byte ovferflow in an array:
resel[sizeof(load_dsa) / sizeof(load_dsa[0])] is 25, not 24.
 1.9 14-Nov-2000  thorpej branches: 1.9.2;
NBPG -> PAGE_SIZE
 1.8 23-Oct-2000  bouyer Fixes related to QUEUE FULL status:
- move status handling in siop_scsicmd_end(), it's better than in siop_intr()
- define 2 internal SIOP status, for "no status reported by device" and
reset condition
- add a list of "urgent" command, to be executed before the list of command
queued the normal way; this is used for command which got aborted
by a QUEUE FULL and have to be requeued in order.
- Don't accept to send a Q_TAG message not immediatly folowing a IDENTIFY
 1.7 23-Oct-2000  bouyer Rearrange for script changes (scheduler core in main script, command part
of the scheduler in command table).
Add tagged command queuing support.
 1.6 18-Oct-2000  bouyer Adapt for new lun switch script.
Implement SCBUSACCEL ioctl.
Snapshot of work in progress on tagged queuing: we can send/receive
queue tag messages. Infrastructure to manage multiple commands per
devices not here yet.
 1.5 06-Oct-2000  bouyer Adapt for reselect handling from the script. While here, fix typo
(SIOP_SCXFER -> SIOP_SXFER).
 1.4 24-Jul-2000  bouyer create a funcion, siop_busreset(), to reset the scsibus.
Reset the scsi bus at attach time, to be sure all devices start in narrow/async
mode.
Defer sync/wide negotiation until after whe have a valid
xs->sc_link->device_softc, so that we can honnor the NOSYNC/NOWIDE quirks.
 1.3 12-Jun-2000  bouyer branches: 1.3.2;
Handle "scsi bus mode change" interrupts on 895 and higther.
Thanks to Hal Murray for reporting the problem and testing the fix.
 1.2 23-May-2000  bouyer branches: 1.2.2;
Allocate dynamically the command block descriptors.
 1.1 15-May-2000  bouyer - split siop.c in script-dependant vs script-independant part, for
comming esiop
- add a reset callback for bus-dependant registers settings
 1.2.2.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.3.2.3 04-Feb-2001  he Pull up revision 1.10 (requested by bouyer):
Fix a 4 byte ovferflow in an array.
 1.3.2.2 15-Dec-2000  he Pull up revisions 1.5-1.8 (requested by bouyer):
Speed improvements to the siop driver, and add tagged queueing
support. As a side effect, better handling of some not so common
phase or message sequences.
 1.3.2.1 24-Jul-2000  bouyer Pull up (approved by thorpej):
sys/dev/ic/siop.c 1.25->1.26
sys/dev/ic/siop_common.c 1.5->1.6
sys/dev/ic/siopvar_common.h 1.3->1.4

create a funcion, siop_busreset(), to reset the scsibus.
Reset the scsi bus at attach time, to be sure all devices start in narrow/async
mode.
Defer sync/wide negotiation until after whe have a valid
xs->sc_link->device_softc, so that we can honnor the NOSYNC/NOWIDE quirks.
 1.9.2.7 11-Feb-2001  bouyer Sync with HEAD.
 1.9.2.6 15-Jan-2001  bouyer Pass CHECK CONDITION status and reset events to the mid-layer.
 1.9.2.5 15-Dec-2000  bouyer Tell the upper layer we can do tagged queuing, so that it sends us more
than one concurent command. Leave the handling of QUEUE FULL events to the
upper layer.
 1.9.2.4 14-Dec-2000  bouyer Convert to thorpej_scsipi interface. Still some work to do to get all benefits
of the new middle layer, but it works.
 1.9.2.3 22-Nov-2000  bouyer Sync with HEAD.
 1.9.2.2 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.9.2.1 14-Nov-2000  bouyer file siopvar_common.h was added on branch thorpej_scsipi on 2000-11-20 11:40:55 +0000
 1.10.2.4 11-Nov-2002  nathanw Catch up to -current
 1.10.2.3 20-Jun-2002  nathanw Catch up to -current.
 1.10.2.2 22-Oct-2001  nathanw Catch up to -current.
 1.10.2.1 21-Jun-2001  nathanw Catch up to -current.
 1.11.2.2 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.11.2.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.21.4.4 14-Dec-2005  jmc Pullup via patch (requested in ticket #5957 by bouyer)
Some drives disconnect after the last data phase without a save data pointer
message. In such case we would not update resid with the proper value
(eventually resid would not be updated at all if there was only one data
phase). To fix this, have the script save the offset in the data tables at
disconnect time if there was a transfer, and use this to compute the resid
if the current offset is 0. PR#31990
 1.21.4.3 19-Mar-2005  tron Pull up revision 1.29 (requested by bouyer in ticket #1751):
Add support for the Ignore Wide Residue SCSI message.
 1.21.4.2 17-Mar-2005  tron Pull up revision 1.28 (requested by bouyer in ticket #1750):
when an unexpected disconnect occurs only compute the resid; do the
real save data pointers when we get the message (or rather, at disconnect
time following the message).
Factor out code to do this, and to deal with xs->resid, in siop_common.c.
 1.21.4.1 17-Mar-2005  tron Pull up revision 1.27 (requested by bouyer in ticket #1748):
The 1010-66 always generate AIP values on the bus, regardless of the SCNTL4
settings. Disable AIP completely, as this confuse pre-Ultra160 drives.
From FreeBSD.
 1.24.2.6 11-Dec-2005  christos Sync with head.
 1.24.2.5 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.24.2.4 04-Feb-2005  skrll Sync with HEAD.
 1.24.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.24.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.24.2.1 03-Aug-2004  skrll Sync with HEAD
 1.27.4.3 01-Dec-2005  riz Pull up following revision(s) (requested by bouyer in ticket #10168):
sys/dev/ic/siop.c: revision 1.79 via patch
sys/dev/ic/siopvar_common.h: revision 1.33 via patch
sys/dev/ic/esiopvar.h: revision 1.13 via patch
sys/dev/ic/esiop.c: revision 1.34 via patch
sys/dev/microcode/siop/esiop.ss: revision 1.20 via patch
sys/dev/ic/siopvar.h: revision 1.22 via patch
sys/dev/microcode/siop/siop.ss: revision 1.20 via patch
Some drives disconnect after the last data phase without a save data pointer
message. In such case we would not update resid with the proper value
(eventually resid would not be updated at all if there was only one data
phase). To fix this, have the script save the offset in the data tables at
disconnect time if there was a transfer, and use this to compute the resid
if the current offset is 0.
Problem reported and patch tested by edwin, Roy Bixler and YAMAMOTO Takashi.
Fix kern/31990 by YAMAMOTO Takashi.
 1.27.4.2 11-May-2005  snj branches: 1.27.4.2.2;
Pull up revision 1.29 (requested by bouyer in ticket #1366):
Add support for the Ignore Wide Residue SCSI message.
 1.27.4.1 11-May-2005  snj Pull up revision 1.28 (requested by bouyer in ticket #1365):
when an unexpected disconnect occurs only compute the resid; do the
real save data pointers when we get the message (or rather, at disconnect
time following the message).
Factor out code to do this, and to deal with xs->resid, in siop_common.c.
 1.27.4.2.2.1 01-Dec-2005  riz Pull up following revision(s) (requested by bouyer in ticket #10168):
sys/dev/ic/siop.c: revision 1.79 via patch
sys/dev/ic/siopvar_common.h: revision 1.33 via patch
sys/dev/ic/esiopvar.h: revision 1.13 via patch
sys/dev/ic/esiop.c: revision 1.34 via patch
sys/dev/microcode/siop/esiop.ss: revision 1.20 via patch
sys/dev/ic/siopvar.h: revision 1.22 via patch
sys/dev/microcode/siop/siop.ss: revision 1.20 via patch
Some drives disconnect after the last data phase without a save data pointer
message. In such case we would not update resid with the proper value
(eventually resid would not be updated at all if there was only one data
phase). To fix this, have the script save the offset in the data tables at
disconnect time if there was a transfer, and use this to compute the resid
if the current offset is 0.
Problem reported and patch tested by edwin, Roy Bixler and YAMAMOTO Takashi.
Fix kern/31990 by YAMAMOTO Takashi.
 1.30.6.2 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.30.6.1 12-Feb-2005  yamt sync with head.
 1.30.4.1 29-Apr-2005  kent sync with -current
 1.32.10.1 22-Nov-2005  yamt sync with head.
 1.32.4.2 03-Sep-2007  yamt sync with head.
 1.32.4.1 21-Jun-2006  yamt sync with head.
 1.32.2.1 21-Nov-2005  tron Pull up following revision(s) (requested by bouyer in ticket #973):
sys/dev/ic/siop.c: revision 1.79
sys/dev/ic/siopvar_common.h: revision 1.33
sys/dev/ic/esiopvar.h: revision 1.13
sys/dev/ic/esiop.c: revision 1.34
sys/dev/microcode/siop/esiop.ss: revision 1.20
sys/dev/ic/siopvar.h: revision 1.22
sys/dev/microcode/siop/siop.ss: revision 1.20
Some drives disconnect after the last data phase without a save data pointer
message. In such case we would not update resid with the proper value
(eventually resid would not be updated at all if there was only one data
phase). To fix this, have the script save the offset in the data tables at
disconnect time if there was a transfer, and use this to compute the resid
if the current offset is 0.
Problem reported and patch tested by edwin, Roy Bixler and YAMAMOTO Takashi.
Fix kern/31990 by YAMAMOTO Takashi.
 1.33.26.1 12-Mar-2007  rmind Sync with HEAD.
 1.34.36.2 29-Jun-2008  mjf Sync with HEAD.
 1.34.36.1 03-Apr-2008  mjf Sync with HEAD.
 1.35.8.1 18-Jun-2008  simonb Sync with head.
 1.35.6.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.35.4.4 11-Mar-2010  yamt sync with head
 1.35.4.3 16-Sep-2009  yamt sync with head
 1.35.4.2 16-May-2009  yamt sync with head
 1.35.4.1 04-May-2009  yamt sync with head.
 1.35.2.1 17-Jun-2008  yamt sync with head.
 1.36.10.1 23-Jul-2009  jym Sync with HEAD.
 1.112 03-May-2022  andvar fix various typos, mainly s/trasfering/transferring/ and s/theese/these/.
 1.111 09-Mar-2022  riastradh usb: Provisionally release bus lock around ubm_rhctrl.

This isn't quite correct, but it avoids a deadlock:

- *_roothub_ctrl holds bus lock, waits in usb_delay_ms for kpause
- softint waits for bus lock, holds up kpause wakeup

The deadlock is new since recent changes to hold the bus lock over
upm_start/upm_transfer. Making this change regresses to other
problems:

- *_suspend/resume and *_roothub_ctrl often touch the same portsc
registers

- roothub_ctrl_abort needs to wait for ubm_rhctrl to complete.

When the bus lock was held across both, a noop served here, but we
can't hold the bus lock across both, so that doesn't work.

However, these problems -- which we've had for a long time -- seem to
be less bad than the deadlock. So let's avoid the deadlock for now
and then work out another way to serialize suspend/resume/rhctrl and
aborts.

Candidate fix for PR kern/56739.
 1.110 03-Mar-2022  riastradh usb: Hold pipe lock across upm_transfer and upm_start.

This simplifies the code and fixes races with abort. Access to the
pipe's queue is now done exclusively while the pipe is locked.
 1.109 03-Mar-2022  riastradh usb: Factor usb_insert_transfer out of upm_transfer and make private.

Almost every upm_transfer function starts with:

mutex_enter(&sc->sc_lock);
err = usb_insert_transfer(xfer);
mutex_exit(&sc->sc_lock);
if (err)
return err;

Some of them have debug messages sprinkled in here too, or assert
that err == USBD_NORMAL_COMPLETION (alternative is USBD_IN_PROGRESS,
only for pipes with up_running or up_serialise, presumably not
applicable for these types of pipes). Some of them also assert
xfer->ux_status == USBD_NOT_STARTED, which is guaranteed on entry and
preserved by usb_insert_transer.

Exceptions:

- arch/mips/adm5120/dev/ahci.c ahci_device_isoc_transfer just returns
USBD_NORMAL_COMPLETION, but I'm pretty sure this is and always has
been broken anyway, so won't make anything worse (if anything, might
make it better...)

- external/bsd/dwc2/dwc2.c dwc2_device_bulk_transfer and
dwc2_device_isoc_transfer _also_ issue dwc2_device_start(xfer)
under the lock. This is probably a better way to do it, but let's
do it uniformly across all HCIs at once.

- rump/dev/lib/libugenhc/ugenhc.c rumpusb_device_bulk_transfer
sometimes returns USBD_IN_PROGRESS _without_ queueing the transfer,
in the !rump_threads case. Not really sure how this is supposed to
work... If it actually breaks anything, we can figure it out.
 1.108 10-Dec-2021  andvar s/occured/occurred/ in comments, log messages and man pages.
 1.107 09-Aug-2021  andvar fix various typos in compatibility, mainly in comments.
 1.106 07-Aug-2021  thorpej Merge thorpej-cfargs2.
 1.105 24-Apr-2021  thorpej branches: 1.105.8;
Merge thorpej-cfargs branch:

Simplify and make extensible the config_search() / config_found() /
config_attach() interfaces: rather than having different variants for
which arguments you want pass along, just have a single call that
takes a variadic list of tag-value arguments.

Adjust all call sites:
- Simplify wherever possible; don't pass along arguments that aren't
actually needed.
- Don't be explicit about what interface attribute is attaching if
the device only has one. (More simplification.)
- Add a config_probe() function to be used in indirect configuiration
situations, making is visibly easier to see when indirect config is
in play, and allowing for future change in semantics. (As of now,
this is just a wrapper around config_match(), but that is an
implementation detail.)

Remove unnecessary or redundant interface attributes where they're not
needed.

There are currently 5 "cfargs" defined:
- CFARG_SUBMATCH (submatch function for direct config)
- CFARG_SEARCH (search function for indirect config)
- CFARG_IATTR (interface attribte)
- CFARG_LOCATORS (locators array)
- CFARG_DEVHANDLE (devhandle_t - wraps OFW, ACPI, etc. handles)

...and a sentinel value CFARG_EOL.

Add some extra sanity checking to ensure that interface attributes
aren't ambiguous.

Use CFARG_DEVHANDLE in MI FDT, OFW, and ACPI code, and macppc and shark
ports to associate those device handles with device_t instance. This
will trickle trough to more places over time (need back-end for pre-OFW
Sun OBP; any others?).
 1.104 30-Sep-2020  simonb branches: 1.104.4;
Add some KNF whitespace.
 1.103 15-Feb-2020  riastradh Fix mistakes in previous sloppy change with root intr xfers.

- Make sure ux_status is set to USBD_IN_PROGRESS when started.
Otherwise, if it is still in flight when we abort the pipe,
usbd_ar_pipe will skip calling upm_abort.

- Initialize ux_status under the lock; in principle a completion
interrupt (or a delay) could race with the initialization.

- KASSERT that the xfer is in progress when we're about to complete
it.

Candidate fix for PR kern/54963 for other HCI drivers than uhci.

ok nick
ok phone

(This is the change that nick evidently MEANT to ok when he ok'd the
previous one!)
 1.102 27-Dec-2019  msaitoh branches: 1.102.2;
s/transfered/transferred/
 1.101 17-Feb-2019  rin branches: 1.101.4;
Fix assertion failures triggered by usbdi.c,v 1.182, when devices
are detached.

This is because xfers of USBD_NOT_STARTED can be removed from queue
in an invisible way to host controller drivers.

Discussed on tech-kern.
 1.100 03-Sep-2018  riastradh Rename min/max -> uimin/uimax for better honesty.

These functions are defined on unsigned int. The generic name
min/max should not silently truncate to 32 bits on 64-bit systems.
This is purely a name change -- no functional change intended.

HOWEVER! Some subsystems have

#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))

even though our standard name for that is MIN/MAX. Although these
may invite multiple evaluation bugs, these do _not_ cause integer
truncation.

To avoid `fixing' these cases, I first changed the name in libkern,
and then compile-tested every file where min/max occurred in order to
confirm that it failed -- and thus confirm that nothing shadowed
min/max -- before changing it.

I have left a handful of bootloaders that are too annoying to
compile-test, and some dead code:

cobalt ews4800mips hp300 hppa ia64 luna68k vax
acorn32/if_ie.c (not included in any kernels)
macppc/if_gm.c (superseded by gem(4))

It should be easy to fix the fallout once identified -- this way of
doing things fails safe, and the goal here, after all, is to _avoid_
silent integer truncations, not introduce them.

Maybe one day we can reintroduce min/max as type-generic things that
never silently truncate. But we should avoid doing that for a while,
so that existing code has a chance to be detected by the compiler for
conversion to uimin/uimax without changing the semantics until we can
properly audit it all. (Who knows, maybe in some cases integer
truncation is actually intended!)
 1.99 09-Apr-2018  jakllsch branches: 1.99.2;
Stop potential misuse of vendor names and USB vendor IDs in root hub
device and string descriptors.

Firstly: Few vendors have identical PCI-SIG vendor IDs and USB-IF vendor
IDs. As such, using the PCI vendor ID as a USB vendor ID may trample
on whomever is allocated that USB vendor ID.

Secondly: The vendor of the host controller hardware implementation has
little to nothing to do with our usbroothub implementation. Thus we
should not potentially associate any problems therewith to such third
party.

This change will result in root hubs being identified by USB Vendor ID
0x0000. Root hub vendor string will now be "NetBSD" (or, specifically:
ostype). Product ID (0x0000) and product strings remain unchanged.
 1.98 28-Oct-2017  pgoyette branches: 1.98.2;
Update the kernhist(9) kernel history code to address issues identified
in PR kern/52639, as well as some general cleaning-up...

(As proposed on tech-kern@ with additional changes and enhancements.)

Details of changes:

* All history arguments are now stored as uintmax_t values[1], both in
the kernel and in the structures used for exporting the history data
to userland via sysctl(9). This avoids problems on some architectures
where passing a 64-bit (or larger) value to printf(3) can cause it to
process the value as multiple arguments. (This can be particularly
problematic when printf()'s format string is not a literal, since in
that case the compiler cannot know how large each argument should be.)

* Update the data structures used for exporting kernel history data to
include a version number as well as the length of history arguments.

* All [2] existing users of kernhist(9) have had their format strings
updated. Each format specifier now includes an explicit length
modifier 'j' to refer to numeric values of the size of uintmax_t.

* All [2] existing users of kernhist(9) have had their format strings
updated to replace uses of "%p" with "%#jx", and the pointer
arguments are now cast to (uintptr_t) before being subsequently cast
to (uintmax_t). This is needed to avoid compiler warnings about
casting "pointer to integer of a different size."

* All [2] existing users of kernhist(9) have had instances of "%s" or
"%c" format strings replaced with numeric formats; several instances
of mis-match between format string and argument list have been fixed.

* vmstat(1) has been modified to handle the new size of arguments in the
history data as exported by sysctl(9).

* vmstat(1) now provides a warning message if the history requested with
the -u option does not exist (previously, this condition was silently
ignored, with only a single blank line being printed).

* vmstat(1) now checks the version and argument length included in the
data exported via sysctl(9) and exits if they do not match the values
with which vmstat was built.

* The kernhist(9) man-page has been updated to note the additional
requirements imposed on the format strings, along with several other
minor changes and enhancements.

[1] It would have been possible to use an explicit length (for example,
uint64_t) for the history arguments. But that would require another
"rototill" of all the users in the future when we add support for an
architecture that supports a larger size. Also, the printf(3) format
specifiers for explicitly-sized values, such as "%"PRIu64, are much
more verbose (and less aesthetically appealing, IMHO) than simply
using "%ju".

[2] I've tried very hard to find "all [the] existing users of kernhist(9)"
but it is possible that I've missed some of them. I would be glad to
update any stragglers that anyone identifies.
 1.97 01-Oct-2016  christos branches: 1.97.8;
remove unused variable.
 1.96 24-Sep-2016  skrll Truncate the transfer length if an overflow is seen rather than halting.

Don't consider an EP11_STAT_SETUP as an error as it's not valid for
host operation.

Should fix kern/51500: axe(4) at slhci(4) does not attach, but there are
more problems with axe(4)
 1.95 15-Sep-2016  jdolecek remove last isolated islands using BUS_SPACE_BARRIER_SYNC and
BUS_SPACE_BARRIER_X_BEFORE_X - these were only ever defined for mips and ia64,
and never actually implemented even there
 1.94 25-Aug-2016  skrll Fix scheduling of interrupt transfers. I can now use a hub with my flxd
ISA USB adapter
 1.93 01-Jul-2016  skrll branches: 1.93.2;
Loop in the interrupt handler while there are interrupts to process.

umass(4) reads now work much better.
 1.92 01-Jul-2016  skrll Fixup the error handling and specifically NAK hold off. If the device
NAKs then delay the transfer by at least a frame.

I can now write files to a umass attached to slhci(4).
 1.91 01-Jul-2016  skrll Debug tweak
 1.90 01-Jul-2016  skrll Format conditional
 1.89 01-Jul-2016  skrll Format conditionals
 1.88 01-Jul-2016  skrll Reformat a conditional
 1.87 30-Jun-2016  skrll Remove dead code
 1.86 28-Jun-2016  skrll Add slhci_memtest which is run when SLHCI_DEBUG is defined.

From Felix Deichmann.
 1.85 20-Jun-2016  skrll Fix a comment
 1.84 20-Jun-2016  skrll More debug.
 1.83 20-Jun-2016  skrll Set ssc as early as possible
 1.82 19-Jun-2016  skrll More debug
 1.81 19-Jun-2016  skrll More debug and fix a debug
 1.80 18-Jun-2016  skrll Fix non-debug build.
 1.79 18-Jun-2016  skrll Debug updates to work with vmstat(1) -u
 1.78 17-Jun-2016  skrll More(/less) debug
 1.77 17-Jun-2016  skrll _KERNEL_OPT protection
 1.76 17-May-2016  martin Mark a diagnostic only variable
 1.75 16-May-2016  skrll Simplify and fixup roothub interrupt transfers to work as well as before
nick-nhusb.
 1.74 16-May-2016  skrll Update comment
 1.73 16-May-2016  skrll Really fix comment
 1.72 15-May-2016  skrll Fix comment
 1.71 15-May-2016  skrll Typo in comment
 1.70 14-May-2016  skrll #if 0 an assert around rootintr that's no longer correct. root hub
interrupt transfers could do with reworking.
 1.69 14-May-2016  skrll Another locking fix in slhci_roothub_ctrl
 1.68 12-May-2016  skrll Fix locking in slhci_roothub_ctrl
 1.67 12-May-2016  skrll More typos in previous
 1.66 11-May-2016  skrll Typo in previous
 1.65 11-May-2016  skrll More debug
 1.64 11-May-2016  skrll Remove incorrect comment
 1.63 11-May-2016  skrll More debug
 1.62 11-May-2016  skrll The HCD should no longer restart a repeating transfer (i.e. an interrupt
transfer) as this is now handled in the usb core code.
 1.61 11-May-2016  skrll fix build
 1.60 10-May-2016  skrll Remove comment about splusb and replace with KASSERT(mutex_owned())
 1.59 10-May-2016  skrll More debug
 1.58 08-May-2016  skrll More debug
 1.57 08-May-2016  skrll Create sc_intr_lock at IPL_USB
 1.56 26-Apr-2016  skrll First pass at adapting SLHCI_DEBUG to USBHIST
 1.55 26-Apr-2016  skrll Fix SLHCI_XFER_TYPE
 1.54 26-Apr-2016  skrll Remove unnecessary whitespace from attach message.

From Felix Deichmann
 1.53 26-Apr-2016  skrll KNF the #includes
 1.52 26-Apr-2016  skrll One sys/cdefs.h is enough
 1.51 26-Apr-2016  skrll s/slhci_debug/slhcidebug/ for consistency with other HCD debug variables
 1.50 26-Apr-2016  skrll Remove unused variable
 1.49 25-Apr-2016  joerg GC slhci_hubd
 1.48 23-Apr-2016  skrll Merge nick-nhusb

- API / infrastructure changes to support memory management changes.
- Memory management improvements and bug fixes.
- HCDs should now be MP safe
- conversion to KERNHIST based debug
- FS/LS isoc support on ehci(4).
- conversion to kmem(9)
- Some USB 3 support - mostly from Takahiro HAYASHI (t-hash).
- interrupt transfers now get proper DMA operations
- general bug fixes
- kern/48308
- uhub status notification improvements
- umass(4) probe fix (applied to HEAD already)
- ohci(4) short transfer fix
 1.47 17-Oct-2013  christos branches: 1.47.4; 1.47.6; 1.47.10;
- remove unused variables
- move variables inside ifdef sections
- ifdef notdef unused code
- use __USE for debugging variables
 1.46 04-Oct-2013  joerg Move an assert to the point where the referenced variable is initialized.
 1.45 03-Oct-2013  skrll Remove incorrect KASSERT.
 1.44 02-Oct-2013  skrll LOCKDEBUG doesn't imply DIAGNOSTIC. duh.
 1.43 02-Oct-2013  skrll Fix a KASSERT - how did that sneak in?
 1.42 02-Oct-2013  skrll Remove harmless paste error.
 1.41 02-Oct-2013  skrll Modernise slhci. Many thanks to rkujawa@ for testing.
 1.40 23-Sep-2013  skrll KNF a comment.
 1.39 23-Sep-2013  skrll Typo
 1.38 22-Sep-2013  adam Removed duplicated lines introduced in version 1.36.
 1.37 22-Sep-2013  skrll Remove all trailing whitespace
 1.36 22-Sep-2013  skrll Remove trailing whitespace.
 1.35 02-Sep-2013  skrll Use C99 designated initializers.
 1.34 02-Sep-2013  skrll KNF multi-line comments.
 1.33 10-Jun-2012  mrg branches: 1.33.2; 1.33.4;
merge the jmcneill-usbmp branch. many thanks to jared for the
initial work, and every one else who has tested things for me.
this is largely my fault at this point :-)

the main changes are something like:

- usbd_bus_methods{} gains a get_lock() to enable the
host controller to provide a lock for the USB code.
if the lock isn't provided, old-style protection is
(partially) applied.

- ehci/ohci/uhci have been converted to the new
interfaces, including mutex/cv/etc conversion.

- usbdivar.h contains a discussion about locking and
what locks are held for which method calls. more
to come for usbdi(9) here.

- audio drivers (uaudio, umidi, auvitek) have been
properly SMPified now that USB is ready.

- scsi drivers have been modified to take the kernel
lock explicitly before calling into scsi code.

- usb pipes are associated with a lock, that is the
same as the controller lock. (this could be split
up further in the future.)

- several usbfoo_locked() or usbfoo_unlocked()
functions have been added to the usbdi(9) to
enable functionality with or without the USB
lock (per controller) already being held.

the TODO.usbmp file has specific details on what is left to
do, including what device-specific changes should be done now
that the whole framework is ready.
 1.32 11-Mar-2012  mrg pull down from usbmp branch:
- remove usbd_bus{} intr_context member, and replace the checks against
it with cpu_intr_p() and cpu_softintr_p().
 1.31 27-Nov-2011  rmind branches: 1.31.2;
G/C unnecessary IPL_HARDUSB
 1.30 17-Oct-2011  isaki branches: 1.30.2;
Fix typo in comment. Pointed out by Y.Sugahara.
 1.29 21-Jun-2011  kiyohara More stride for PSIONTEKLOGIX NETBOOK PRO.
 1.28 17-May-2011  mrg move and rename the uvm history code out of uvm_stat to "kernhist".

rename "UVMHIST" option to enable the uvm histories.

TODO:
- make UVMHIST properly depend upon KERNHIST
- enable dynamic registration of histories. this is mostly just
allocating something in a bitmap, and is only for viewing multiple
histories in a merged form.


tested on amd64 and sparc64.
 1.27 13-Mar-2011  kiyohara Fix reset status. Clear some flags for active pipes after completing hard reset.
 1.26 08-May-2010  isaki branches: 1.26.2;
Move "opt_slhci.h" from .h to .c
to avoid link error (multiple definition of _KERNEL_OPT_foo).
 1.25 25-Nov-2009  rmind branches: 1.25.2; 1.25.4;
Remove IPL_LPT and IPL_IPI aliases, use the actual IPLs.
Fix some broken comments.
 1.24 12-Nov-2009  dyoung Simplify activation hook.
 1.23 12-May-2009  cegger struct device * -> device_t, no functional changes intended.
 1.22 18-Mar-2009  cegger Ansify function definitions w/o arguments. Generated with sed.
 1.21 28-Mar-2008  drochner branches: 1.21.4; 1.21.12; 1.21.18;
split device/softc for USB host controllers and the usb (control)
device,
this is hairy stuff, and I've only tested with uhci/ehci at pci,
please test the rest and report problems
 1.20 24-Feb-2008  isaki slhci also shares usbroothub_subr.
 1.19 07-Jan-2008  ad branches: 1.19.2; 1.19.6;
Really, remove last vestiges of simplelock debugging.
 1.18 07-Jan-2008  ad Remove vestiges of simplelock debugging.
 1.17 04-Jan-2008  ad Start detangling lock.h from intr.h. This is likely to cause short term
breakage, but the mess of dependencies has been regularly breaking the
build recently anyhow.
 1.16 06-Nov-2007  ad branches: 1.16.6;
Use the softint_* API.
 1.15 19-Oct-2007  ad branches: 1.15.2;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.14 24-Aug-2007  kiyohara branches: 1.14.2; 1.14.6;
The variable slhci_usbdebug is defined in '#ifdef SLHCI_DEBUG' and
'#ifdef USB_DEBUG'.
Reported by Bernd Ernesti <netbsd@lists.veego.de>
 1.13 19-Aug-2007  kiyohara slhci(4) is MP safe and can use the CALLOUT_MPSAFE flag.
patch from Matthew Orgass <darkstar@city-net.com>
 1.12 15-Aug-2007  kiyohara Replace to Matthew Orgass's slhci(4).
http://mail-index.netbsd.org/tech-kern/2007/06/26/0001.html
 1.11 16-Nov-2006  christos branches: 1.11.8; 1.11.18; 1.11.20; 1.11.24;
__unused removal on arguments; approved by core.
 1.10 12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.9 17-Aug-2006  christos branches: 1.9.2; 1.9.4;
Fix all the -D*DEBUG* code that it was rotting away and did not even compile.
Mostly from Arnaud Lacombe, many thanks!
 1.8 17-Jul-2006  christos remove lhs cast for gcc4
 1.7 11-Dec-2005  christos branches: 1.7.4; 1.7.8;
merge ktrace-lwp.
 1.6 01-Jun-2005  drochner branches: 1.6.2;
const fall-out, from Patrick Welche
 1.5 27-Feb-2005  perry nuke trailing whitespace
 1.4 22-Apr-2004  itojun branches: 1.4.4; 1.4.6;
sprintf -> snprintf
 1.3 13-Mar-2003  bsh branches: 1.3.2;
make this compile with SLHCI_DEBUG
 1.2 08-Sep-2002  isaki Correct xfer->busy_free status in DIAGNOSTIC.
 1.1 11-Aug-2002  isaki branches: 1.1.2; 1.1.4; 1.1.6;
Add driver for ScanLogic SL811HS/T USB Host Controller.
XXX It's experimental code yet.

For x68k: USB part of Nereid USB/Ethernet/memory board
For ISA: ISA USB Host board from Morphy planning
 1.1.6.3 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.1.6.2 06-Sep-2002  jdolecek sync kqueue branch with HEAD
 1.1.6.1 11-Aug-2002  jdolecek file sl811hs.c was added on branch kqueue on 2002-09-06 08:44:35 +0000
 1.1.4.2 29-Aug-2002  gehenna catch up with -current.
 1.1.4.1 11-Aug-2002  gehenna file sl811hs.c was added on branch gehenna-devsw on 2002-08-29 05:22:33 +0000
 1.1.2.3 17-Sep-2002  nathanw Catch up to -current.
 1.1.2.2 13-Aug-2002  nathanw Catch up to -current.
 1.1.2.1 11-Aug-2002  nathanw file sl811hs.c was added on branch nathanw_sa on 2002-08-13 02:19:29 +0000
 1.3.2.5 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.3.2.4 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.3.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.3.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.3.2.1 03-Aug-2004  skrll Sync with HEAD
 1.4.6.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.4.4.1 29-Apr-2005  kent sync with -current
 1.6.2.6 27-Feb-2008  yamt sync with head.
 1.6.2.5 21-Jan-2008  yamt sync with head
 1.6.2.4 15-Nov-2007  yamt sync with head.
 1.6.2.3 27-Oct-2007  yamt sync with head.
 1.6.2.2 03-Sep-2007  yamt sync with head.
 1.6.2.1 30-Dec-2006  yamt sync with head.
 1.7.8.2 03-Sep-2006  yamt sync with head.
 1.7.8.1 11-Aug-2006  yamt sync with head
 1.7.4.1 09-Sep-2006  rpaulo sync with head
 1.9.4.2 10-Dec-2006  yamt sync with head.
 1.9.4.1 22-Oct-2006  yamt sync with head
 1.9.2.1 18-Nov-2006  ad Sync with head.
 1.11.24.4 11-Nov-2007  joerg Sync with HEAD.
 1.11.24.3 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.11.24.2 03-Sep-2007  jmcneill Sync with HEAD.
 1.11.24.1 16-Aug-2007  jmcneill Sync with HEAD.
 1.11.20.2 03-Sep-2007  skrll Sync with HEAD.
 1.11.20.1 15-Aug-2007  skrll Sync with HEAD.
 1.11.18.4 21-May-2008  itohy Change buffer memory interface.
 1.11.18.3 17-Jun-2007  itohy caddr_t -> u_int8_t * / const u_int8_t *
 1.11.18.2 31-May-2007  itohy usbdi(9): Change usbd_map_buffer_mbuf to return the result, since
mbuf(9) chain may be fragmented and mapping failure will happen.
-void usbd_map_buffer_mbuf(usbd_xfer_handle xfer, struct mbuf *chain)
+usbd_status usbd_map_buffer_mbuf(usbd_xfer_handle xfer, struct mbuf *chain)

usbdi(9): Add more diagnostic assertions.
uhci(4): fix aux dma for mbuf mapping.
slhci(4): fix repeated interrupt transfer (not tested).
ehci/slhci/ohci/uhci: Add checks where mbuf(4) transfer is not supported.

usb_port.h: Add some compat macros for FreeBSD.
usb_mem_nodma.c: Fix typos.
 1.11.18.1 22-May-2007  itohy Overhaul of USB stack, mostly DMA related

This applies to NetBSD 4.99.13 (March 1, 2007)

usbdi(9) interface is based on FreeBSD version, excluding
- removal of portability code

Patch most NetBSD changes, excluding
- DMA memory "reserve", since we don't need contiguous buffers any longer
- volatiles in DMA structure, since it should not be needed
with proper bus_dmamap_sync(9)s

DMA/non-DMA memory management overhaul
- Move all DMA related code to usb_mem.[ch]
(add usb_alloc_buffer_dma(), usb_free_buffer_dma(), etc.).
XXX Should usb_mem.[ch] be renamed as usb_mem_dma.[ch] ?
- Add corresponding non-DMA code to usb_mem_nodma.[ch] .
Currently just use malloc(9).
- Above files are conditionally used by config framework (added
attributes to conf/files and dev/usb/files.usb).
- Add diagnostic panics when resource allocation is requested
on interrupt context.
- Change memory allocations (that require context) from NOWAIT to WAITOK.

Allocate DMA/non-DMA buffer per host interface, not globally.
advantage: Buffers can be freed on detaching host interface.
Activity of a host interface does not affect others.
disadvantages: It possibly consumes more memory.

API changes
- usbd_alloc_xfer() is changed:
old: usbd_xfer_handle usbd_alloc_xfer(usbd_device_handle dev);
new: usbd_xfer_handle usbd_alloc_xfer(usbd_device_handle dev,
usbd_pipe_handle pipe);
- pipe argument of usbd_setup_*xfer() are now unused
XXX the pipe argument should be removed?
- add mapping APIs
- async request will be processed as a task (kernel thread context),
and delayed to some extent
- usbdivar.h: struct usbd_xfer: renamed a member "allocbuf" to "hcbuffer"
(mapped/allocated/refered buffer for HCI driver)
- usb_port.h: change usb_proc_ptr from struct ptoc * to struct lwp *
- usb_port.h: add usb_sigproc_ptr for psignal(9) (struct proc *)
- usb.h: add UE_MAXPKTSZ(ep) and UE_MAXPKTSZ_MASK macros for USB 2.0

changes to USB device drivers
- atu, aue, axe, cdce, cue, kue, rum, udav, upl, ural, url,
uaudio, ubt, ucom, ugen, uhidev, uirda, ulpt, umidi, urio,
uscanner, ustir, utoppy:
* catch up API change of usbd_alloc_xfer()
- umass, usscanner:
* catch up API change of usbd_alloc_xfer()
* eliminate memory copy for large transfer

ohci
- free resources on detach
- add lots of bus_dmamap_sync() operations
- simplify the code of loading std chain
- rewrite code of looking up TD/ITD from DMA addr by using allocation chunk
- add workaround for CMD Tech 670 and 673 chipsets
- make sure resources are not allocated in interrupt context
- add support for mapping buffer and mbuf

slhci
- allocate xfer and slhci_xfer at once, and simplify relevant code
- add slhci_detach()
- remove second arg of slhci_attach() since it is the same as the first arg.
- add support for "mapping" (no, it doesn't map since it doesn't do DMA)
buffer and mbuf
- add pcmcia frontend
- NOT TESTED, missing hardware

ehci
- add lots of bus_dmamap_sync() operations, possibly too many
- make sure resources are not allocated in interrupt context
- add support for mapping buffer and mbuf
- done only simple test

uhci
- add lots of bus_dmamap_sync() operations, possibly too many
- make sure resources are not allocated in interrupt context
- add support for mapping buffer and mbuf

To do
- review, test, debug
- rewrite network drivers to utilize usbd_map_buffer_mbuf()
- rewrite uaudio(4) to eliminate memcpy
- "pipe" argument of usbd_setup_*xfer() should eventually be removed
 1.11.8.4 23-Oct-2007  ad Sync with head.
 1.11.8.3 12-Oct-2007  ad Fix merge errors.
 1.11.8.2 09-Oct-2007  ad Sync with head.
 1.11.8.1 20-Aug-2007  ad Sync with HEAD.
 1.14.6.2 13-Nov-2007  bouyer Sync with HEAD
 1.14.6.1 25-Oct-2007  bouyer Sync with HEAD.
 1.14.2.4 23-Mar-2008  matt sync with HEAD
 1.14.2.3 09-Jan-2008  matt sync with HEAD
 1.14.2.2 08-Nov-2007  matt sync with -HEAD
 1.14.2.1 06-Nov-2007  matt sync with HEAD
 1.15.2.2 18-Feb-2008  mjf Sync with HEAD.
 1.15.2.1 19-Nov-2007  mjf Sync with HEAD.
 1.16.6.1 08-Jan-2008  bouyer Sync with HEAD
 1.19.6.1 03-Apr-2008  mjf Sync with HEAD.
 1.19.2.1 24-Mar-2008  keiichi sync with head.
 1.21.18.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.21.12.1 28-Apr-2009  skrll Sync with HEAD.
 1.21.4.4 11-Aug-2010  yamt sync with head.
 1.21.4.3 11-Mar-2010  yamt sync with head
 1.21.4.2 16-May-2009  yamt sync with head
 1.21.4.1 04-May-2009  yamt sync with head.
 1.25.4.3 31-May-2011  rmind sync with head
 1.25.4.2 21-Apr-2011  rmind sync with head
 1.25.4.1 30-May-2010  rmind sync with head
 1.25.2.1 17-Aug-2010  uebayasi Sync with HEAD.
 1.26.2.1 06-Jun-2011  jruoho Sync with HEAD.
 1.30.2.3 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.30.2.2 30-Oct-2012  yamt sync with head
 1.30.2.1 17-Apr-2012  yamt sync with head
 1.31.2.4 12-Mar-2012  mrg fix a comment
 1.31.2.3 11-Mar-2012  mrg sync to latest -current
 1.31.2.2 25-Feb-2012  mrg catch up with bus->intr_context going away.
 1.31.2.1 04-Dec-2011  jmcneill Make ehci mpsafe.
 1.33.4.1 18-May-2014  rmind sync with head
 1.33.2.2 03-Dec-2017  jdolecek update from HEAD
 1.33.2.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.47.10.2 26-Jan-2017  skrll Sync with HEAD/nhusb
 1.47.10.1 06-Sep-2016  skrll First pass at netbsd-7 updated with USB code from HEAD
 1.47.6.19 05-Oct-2016  skrll Sync with HEAD
 1.47.6.18 09-Jul-2016  skrll Sync with HEAD
 1.47.6.17 29-May-2016  skrll Sync with HEAD
 1.47.6.16 25-Mar-2016  skrll Wrap long lines
 1.47.6.15 22-Oct-2015  skrll Simplify *_XFER2SC using ux_bus
 1.47.6.14 20-Oct-2015  skrll Consistently providei/use *_{XFER,PIPE,BUS}2SC, etc macros
 1.47.6.13 11-Oct-2015  skrll Update ubm_allocx with the isoc frame count parameter and use it in
dwctwo(4)
 1.47.6.12 11-Oct-2015  skrll Typo
 1.47.6.11 05-Dec-2014  skrll KNF. Remove ( ) from return statements.
 1.47.6.10 04-Dec-2014  skrll Rework roothub control transfers so that much of the code is shared
across HCDs.

I have retained the vendor/product reporting for each HCD for now,
but it maybe get removed later.

ahci(4) now reports a language table and uses the usb_makestrdesc
function instead of rolling its own version.
 1.47.6.9 03-Dec-2014  skrll Rename usbroothub_subr.[ch] to usbroothub.[ch]
 1.47.6.8 03-Dec-2014  skrll Provide a USETWD macro for use with USB words designated
initialisers.
 1.47.6.7 03-Dec-2014  skrll Replace malloc(9) with kmem(9)
 1.47.6.6 03-Dec-2014  skrll Use designated initializers for more descriptors.
 1.47.6.5 03-Dec-2014  skrll Use designated initialisers for usb_device_descriptor_t structs.
 1.47.6.4 03-Dec-2014  skrll The grand renaming of structure members.

No functional change.
 1.47.6.3 02-Dec-2014  skrll Step #1 of memory allocation re-organisation.

Centralised the buffer allocation routine which now supports DMA
and non-DMA capable host controllers. Remove the
ubm_{alloc,free}m methods from usbd_bus_methods.

The buffer allocation is only allowed in thread context and,
therefore, negates the usefulness of the reserve dma code which
is removed in this change.

USBD_NO_COPY is also no longer required as usbd_transfer and
usbd_transfer_complete now track buffer usage and handle any
copying.
 1.47.6.2 01-Dec-2014  skrll Add prefixes to method structures member names. No functional change.
 1.47.6.1 30-Nov-2014  skrll Use C99 types. u_int{8,16,32,64}_t to uint{8,16,32,64}_t.

No functional change.
 1.47.4.1 05-Apr-2017  snj Pull up following revision(s) (requested by skrll in ticket #1395):
share/man/man4/axe.4: netbsd-7-nhusb
share/man/man4/axen.4: netbsd-7-nhusb
share/man/man4/cdce.4: netbsd-7-nhusb
share/man/man4/uaudio.4: netbsd-7-nhusb
share/man/man4/ucom.4: netbsd-7-nhusb
share/man/man4/uep.4: netbsd-7-nhusb
share/man/man4/urtw.4: netbsd-7-nhusb
share/man/man4/usb.4: netbsd-7-nhusb
share/man/man4/uyap.4: netbsd-7-nhusb
share/man/man4/xhci.4: netbsd-7-nhusb
share/man/man9/usbdi.9: netbsd-7-nhusb
sys/arch/amd64/conf/ALL: netbsd-7-nhusb
sys/arch/amd64/conf/GENERIC: netbsd-7-nhusb
sys/arch/amiga/dev/slhci_zbus.c: netbsd-7-nhusb
sys/arch/arm/allwinner/awin_otg.c: netbsd-7-nhusb
sys/arch/arm/allwinner/awin_usb.c: netbsd-7-nhusb
sys/arch/arm/amlogic/amlogic_dwctwo.c: netbsd-7-nhusb
sys/arch/arm/at91/at91ohci.c: netbsd-7-nhusb
sys/arch/arm/broadcom/bcm2835_dwctwo.c: netbsd-7-nhusb
sys/arch/arm/broadcom/bcm53xx_usb.c: netbsd-7-nhusb
sys/arch/arm/ep93xx/epohci.c: netbsd-7-nhusb
sys/arch/arm/gemini/obio_ehci.c: netbsd-7-nhusb
sys/arch/arm/imx/files.imx23: netbsd-7-nhusb
sys/arch/arm/imx/imxusb.c: netbsd-7-nhusb
sys/arch/arm/imx/imxusbreg.h: netbsd-7-nhusb
sys/arch/arm/omap/obio_ohci.c: netbsd-7-nhusb
sys/arch/arm/omap/omap3_ehci.c: netbsd-7-nhusb
sys/arch/arm/omap/omapl1x_ohci.c: netbsd-7-nhusb
sys/arch/arm/omap/tiotg.c: netbsd-7-nhusb
sys/arch/arm/s3c2xx0/ohci_s3c24x0.c: netbsd-7-nhusb
sys/arch/arm/samsung/exynos_usb.c: netbsd-7-nhusb
sys/arch/arm/xscale/pxa2x0_ohci.c: netbsd-7-nhusb
sys/arch/arm/zynq/zynq_usb.c: netbsd-7-nhusb
sys/arch/hpcarm/dev/nbp_slhci.c: netbsd-7-nhusb
sys/arch/hpcmips/dev/plumohci.c: netbsd-7-nhusb
sys/arch/i386/conf/ALL: netbsd-7-nhusb
sys/arch/i386/conf/GENERIC: netbsd-7-nhusb
sys/arch/i386/pci/gcscehci.c: netbsd-7-nhusb
sys/arch/luna68k/conf/GENERIC: netbsd-7-nhusb
sys/arch/mips/adm5120/dev/ahci.c: netbsd-7-nhusb
sys/arch/mips/adm5120/dev/ahcivar.h: netbsd-7-nhusb
sys/arch/mips/alchemy/dev/ohci_aubus.c: netbsd-7-nhusb
sys/arch/mips/atheros/dev/ehci_arbus.c: netbsd-7-nhusb
sys/arch/mips/atheros/dev/ohci_arbus.c: netbsd-7-nhusb
sys/arch/mips/conf/files.adm5120: netbsd-7-nhusb
sys/arch/mips/ralink/ralink_ehci.c: netbsd-7-nhusb
sys/arch/mips/ralink/ralink_ohci.c: netbsd-7-nhusb
sys/arch/mips/rmi/rmixl_ehci.c: netbsd-7-nhusb
sys/arch/mips/rmi/rmixl_ohci.c: netbsd-7-nhusb
sys/arch/playstation2/dev/ohci_sbus.c: netbsd-7-nhusb
sys/arch/powerpc/booke/dev/pq3ehci.c: netbsd-7-nhusb
sys/arch/powerpc/ibm4xx/dev/dwctwo_plb.c: netbsd-7-nhusb
sys/arch/x68k/dev/slhci_intio.c: netbsd-7-nhusb
sys/conf/files: netbsd-7-nhusb
sys/dev/cardbus/ehci_cardbus.c: netbsd-7-nhusb
sys/dev/cardbus/ohci_cardbus.c: netbsd-7-nhusb
sys/dev/cardbus/uhci_cardbus.c: netbsd-7-nhusb
sys/dev/ic/sl811hs.c: netbsd-7-nhusb
sys/dev/ic/sl811hsvar.h: netbsd-7-nhusb
sys/dev/isa/slhci_isa.c: netbsd-7-nhusb
sys/dev/marvell/ehci_mv.c: netbsd-7-nhusb
sys/dev/pci/ehci_pci.c: netbsd-7-nhusb
sys/dev/pci/ohci_pci.c: netbsd-7-nhusb
sys/dev/pci/uhci_pci.c: netbsd-7-nhusb
sys/dev/pci/xhci_pci.c: netbsd-7-nhusb
sys/dev/pcmcia/slhci_pcmcia.c: netbsd-7-nhusb
sys/dev/usb/Makefile.usbdevs: netbsd-7-nhusb
sys/dev/usb/TODO: netbsd-7-nhusb
sys/dev/usb/TODO.usbmp: netbsd-7-nhusb
sys/dev/usb/aubtfwl.c: netbsd-7-nhusb
sys/dev/usb/auvitek.c: netbsd-7-nhusb
sys/dev/usb/auvitek_audio.c: netbsd-7-nhusb
sys/dev/usb/auvitek_dtv.c: netbsd-7-nhusb
sys/dev/usb/auvitek_i2c.c: netbsd-7-nhusb
sys/dev/usb/auvitek_video.c: netbsd-7-nhusb
sys/dev/usb/auvitekvar.h: netbsd-7-nhusb
sys/dev/usb/ehci.c: netbsd-7-nhusb
sys/dev/usb/ehcireg.h: netbsd-7-nhusb
sys/dev/usb/ehcivar.h: netbsd-7-nhusb
sys/dev/usb/emdtv.c: netbsd-7-nhusb
sys/dev/usb/emdtv_dtv.c: netbsd-7-nhusb
sys/dev/usb/emdtv_ir.c: netbsd-7-nhusb
sys/dev/usb/emdtvvar.h: netbsd-7-nhusb
sys/dev/usb/ezload.c: netbsd-7-nhusb
sys/dev/usb/ezload.h: netbsd-7-nhusb
sys/dev/usb/files.usb: netbsd-7-nhusb
sys/dev/usb/hid.c: netbsd-7-nhusb
sys/dev/usb/hid.h: netbsd-7-nhusb
sys/dev/usb/if_athn_usb.c: netbsd-7-nhusb
sys/dev/usb/if_athn_usb.h: netbsd-7-nhusb
sys/dev/usb/if_atu.c: netbsd-7-nhusb
sys/dev/usb/if_atureg.h: netbsd-7-nhusb
sys/dev/usb/if_aue.c: netbsd-7-nhusb
sys/dev/usb/if_auereg.h: netbsd-7-nhusb
sys/dev/usb/if_axe.c: netbsd-7-nhusb
sys/dev/usb/if_axen.c: netbsd-7-nhusb
sys/dev/usb/if_axenreg.h: netbsd-7-nhusb
sys/dev/usb/if_axereg.h: netbsd-7-nhusb
sys/dev/usb/if_cdce.c: netbsd-7-nhusb
sys/dev/usb/if_cdcereg.h: netbsd-7-nhusb
sys/dev/usb/if_cue.c: netbsd-7-nhusb
sys/dev/usb/if_cuereg.h: netbsd-7-nhusb
sys/dev/usb/if_kue.c: netbsd-7-nhusb
sys/dev/usb/if_kuereg.h: netbsd-7-nhusb
sys/dev/usb/if_otus.c: netbsd-7-nhusb
sys/dev/usb/if_otusvar.h: netbsd-7-nhusb
sys/dev/usb/if_rum.c: netbsd-7-nhusb
sys/dev/usb/if_rumreg.h: netbsd-7-nhusb
sys/dev/usb/if_rumvar.h: netbsd-7-nhusb
sys/dev/usb/if_run.c: netbsd-7-nhusb
sys/dev/usb/if_runvar.h: netbsd-7-nhusb
sys/dev/usb/if_smsc.c: netbsd-7-nhusb
sys/dev/usb/if_smscreg.h: netbsd-7-nhusb
sys/dev/usb/if_smscvar.h: netbsd-7-nhusb
sys/dev/usb/if_udav.c: netbsd-7-nhusb
sys/dev/usb/if_udavreg.h: netbsd-7-nhusb
sys/dev/usb/if_upgt.c: netbsd-7-nhusb
sys/dev/usb/if_upgtvar.h: netbsd-7-nhusb
sys/dev/usb/if_upl.c: netbsd-7-nhusb
sys/dev/usb/if_ural.c: netbsd-7-nhusb
sys/dev/usb/if_uralreg.h: netbsd-7-nhusb
sys/dev/usb/if_uralvar.h: netbsd-7-nhusb
sys/dev/usb/if_url.c: netbsd-7-nhusb
sys/dev/usb/if_urlreg.h: netbsd-7-nhusb
sys/dev/usb/if_urndis.c: netbsd-7-nhusb
sys/dev/usb/if_urndisreg.h: netbsd-7-nhusb
sys/dev/usb/if_urtw.c: netbsd-7-nhusb
sys/dev/usb/if_urtwn.c: netbsd-7-nhusb
sys/dev/usb/if_urtwn_data.h: netbsd-7-nhusb
sys/dev/usb/if_urtwnreg.h: netbsd-7-nhusb
sys/dev/usb/if_urtwnvar.h: netbsd-7-nhusb
sys/dev/usb/if_urtwreg.h: netbsd-7-nhusb
sys/dev/usb/if_zyd.c: netbsd-7-nhusb
sys/dev/usb/if_zydreg.h: netbsd-7-nhusb
sys/dev/usb/irmce.c: netbsd-7-nhusb
sys/dev/usb/moscom.c: netbsd-7-nhusb
sys/dev/usb/motg.c: netbsd-7-nhusb
sys/dev/usb/motgvar.h: netbsd-7-nhusb
sys/dev/usb/ohci.c: netbsd-7-nhusb
sys/dev/usb/ohcireg.h: netbsd-7-nhusb
sys/dev/usb/ohcivar.h: netbsd-7-nhusb
sys/dev/usb/pseye.c: netbsd-7-nhusb
sys/dev/usb/slurm.c: netbsd-7-nhusb
sys/dev/usb/stuirda.c: netbsd-7-nhusb
sys/dev/usb/u3g.c: netbsd-7-nhusb
sys/dev/usb/uark.c: netbsd-7-nhusb
sys/dev/usb/uatp.c: netbsd-7-nhusb
sys/dev/usb/uaudio.c: netbsd-7-nhusb
sys/dev/usb/uberry.c: netbsd-7-nhusb
sys/dev/usb/ubsa.c: netbsd-7-nhusb
sys/dev/usb/ubsa_common.c: netbsd-7-nhusb
sys/dev/usb/ubsavar.h: netbsd-7-nhusb
sys/dev/usb/ubt.c: netbsd-7-nhusb
sys/dev/usb/uchcom.c: netbsd-7-nhusb
sys/dev/usb/ucom.c: netbsd-7-nhusb
sys/dev/usb/ucomvar.h: netbsd-7-nhusb
sys/dev/usb/ucycom.c: netbsd-7-nhusb
sys/dev/usb/udl.c: netbsd-7-nhusb
sys/dev/usb/udl.h: netbsd-7-nhusb
sys/dev/usb/udsbr.c: netbsd-7-nhusb
sys/dev/usb/udsir.c: netbsd-7-nhusb
sys/dev/usb/uep.c: netbsd-7-nhusb
sys/dev/usb/uftdi.c: netbsd-7-nhusb
sys/dev/usb/uftdireg.h: netbsd-7-nhusb
sys/dev/usb/ugen.c: netbsd-7-nhusb
sys/dev/usb/ugensa.c: netbsd-7-nhusb
sys/dev/usb/uhci.c: netbsd-7-nhusb
sys/dev/usb/uhcireg.h: netbsd-7-nhusb
sys/dev/usb/uhcivar.h: netbsd-7-nhusb
sys/dev/usb/uhid.c: netbsd-7-nhusb
sys/dev/usb/uhidev.c: netbsd-7-nhusb
sys/dev/usb/uhidev.h: netbsd-7-nhusb
sys/dev/usb/uhmodem.c: netbsd-7-nhusb
sys/dev/usb/uhso.c: netbsd-7-nhusb
sys/dev/usb/uhub.c: netbsd-7-nhusb
sys/dev/usb/uipad.c: netbsd-7-nhusb
sys/dev/usb/uipaq.c: netbsd-7-nhusb
sys/dev/usb/uirda.c: netbsd-7-nhusb
sys/dev/usb/uirdavar.h: netbsd-7-nhusb
sys/dev/usb/ukbd.c: netbsd-7-nhusb
sys/dev/usb/ukbdmap.c: netbsd-7-nhusb
sys/dev/usb/ukyopon.c: netbsd-7-nhusb
sys/dev/usb/ukyopon.h: netbsd-7-nhusb
sys/dev/usb/ulpt.c: netbsd-7-nhusb
sys/dev/usb/umass.c: netbsd-7-nhusb
sys/dev/usb/umass_isdata.c: netbsd-7-nhusb
sys/dev/usb/umass_isdata.h: netbsd-7-nhusb
sys/dev/usb/umass_quirks.c: netbsd-7-nhusb
sys/dev/usb/umass_quirks.h: netbsd-7-nhusb
sys/dev/usb/umass_scsipi.c: netbsd-7-nhusb
sys/dev/usb/umass_scsipi.h: netbsd-7-nhusb
sys/dev/usb/umassvar.h: netbsd-7-nhusb
sys/dev/usb/umcs.c: netbsd-7-nhusb
sys/dev/usb/umct.c: netbsd-7-nhusb
sys/dev/usb/umidi.c: netbsd-7-nhusb
sys/dev/usb/umidi_quirks.c: netbsd-7-nhusb
sys/dev/usb/umidi_quirks.h: netbsd-7-nhusb
sys/dev/usb/umodem.c: netbsd-7-nhusb
sys/dev/usb/umodem_common.c: netbsd-7-nhusb
sys/dev/usb/umodemvar.h: netbsd-7-nhusb
sys/dev/usb/ums.c: netbsd-7-nhusb
sys/dev/usb/uplcom.c: netbsd-7-nhusb
sys/dev/usb/urio.c: netbsd-7-nhusb
sys/dev/usb/urio.h: netbsd-7-nhusb
sys/dev/usb/usb.c: netbsd-7-nhusb
sys/dev/usb/usb.h: netbsd-7-nhusb
sys/dev/usb/usb_mem.c: netbsd-7-nhusb
sys/dev/usb/usb_mem.h: netbsd-7-nhusb
sys/dev/usb/usb_quirks.c: netbsd-7-nhusb
sys/dev/usb/usb_quirks.h: netbsd-7-nhusb
sys/dev/usb/usb_subr.c: netbsd-7-nhusb
sys/dev/usb/usbdevices.config: netbsd-7-nhusb
sys/dev/usb/usbdevs: netbsd-7-nhusb
sys/dev/usb/usbdevs.h: netbsd-7-nhusb
sys/dev/usb/usbdevs_data.h: netbsd-7-nhusb
sys/dev/usb/usbdi.c: netbsd-7-nhusb
sys/dev/usb/usbdi.h: netbsd-7-nhusb
sys/dev/usb/usbdi_util.c: netbsd-7-nhusb
sys/dev/usb/usbdi_util.h: netbsd-7-nhusb
sys/dev/usb/usbdivar.h: netbsd-7-nhusb
sys/dev/usb/usbhid.h: netbsd-7-nhusb
sys/dev/usb/usbhist.h: netbsd-7-nhusb
sys/dev/usb/usbroothub.c: netbsd-7-nhusb
sys/dev/usb/usbroothub.h: netbsd-7-nhusb
sys/dev/usb/usbroothub_subr.c: delete
sys/dev/usb/usbroothub_subr.h: delete
sys/dev/usb/uscanner.c: netbsd-7-nhusb
sys/dev/usb/uslsa.c: netbsd-7-nhusb
sys/dev/usb/usscanner.c: netbsd-7-nhusb
sys/dev/usb/ustir.c: netbsd-7-nhusb
sys/dev/usb/uthum.c: netbsd-7-nhusb
sys/dev/usb/utoppy.c: netbsd-7-nhusb
sys/dev/usb/uts.c: netbsd-7-nhusb
sys/dev/usb/uvideo.c: netbsd-7-nhusb
sys/dev/usb/uvisor.c: netbsd-7-nhusb
sys/dev/usb/uvscom.c: netbsd-7-nhusb
sys/dev/usb/uyap.c: netbsd-7-nhusb
sys/dev/usb/uyap_firmware.h: netbsd-7-nhusb
sys/dev/usb/uyurex.c: netbsd-7-nhusb
sys/dev/usb/x1input_rdesc.h: netbsd-7-nhusb
sys/dev/usb/xhci.c: netbsd-7-nhusb
sys/dev/usb/xhcireg.h: netbsd-7-nhusb
sys/dev/usb/xhcivar.h: netbsd-7-nhusb
sys/dev/usb/xinput_rdesc.h: netbsd-7-nhusb
sys/external/bsd/common/conf/files.linux: netbsd-7-nhusb
sys/external/bsd/common/include/linux/err.h: netbsd-7-nhusb
sys/external/bsd/common/include/linux/kernel.h: netbsd-7-nhusb
sys/external/bsd/common/include/linux/workqueue.h: netbsd-7-nhusb
sys/external/bsd/common/linux/linux_work.c: netbsd-7-nhusb
sys/external/bsd/drm2/dist/drm/radeon/atombios_encoders.c: netbsd-7-nhusb
sys/external/bsd/drm2/dist/drm/radeon/radeon_legacy_encoders.c: netbsd-7-nhusb
sys/external/bsd/drm2/drm/files.drmkms: netbsd-7-nhusb
sys/external/bsd/drm2/i915drm/files.i915drmkms: netbsd-7-nhusb
sys/external/bsd/drm2/include/linux/err.h: delete
sys/external/bsd/drm2/include/linux/workqueue.h: delete
sys/external/bsd/drm2/linux/files.drmkms_linux: netbsd-7-nhusb
sys/external/bsd/drm2/linux/linux_work.c: delete
sys/external/bsd/dwc2/dwc2.c: netbsd-7-nhusb
sys/external/bsd/dwc2/dwc2.h: netbsd-7-nhusb
sys/external/bsd/dwc2/dwc2var.h: netbsd-7-nhusb
sys/external/bsd/dwc2/dwctwo2netbsd: netbsd-7-nhusb
sys/external/bsd/dwc2/conf/files.dwc2: netbsd-7-nhusb
sys/external/bsd/dwc2/dist/dwc2_core.c: netbsd-7-nhusb
sys/external/bsd/dwc2/dist/dwc2_core.h: netbsd-7-nhusb
sys/external/bsd/dwc2/dist/dwc2_coreintr.c: netbsd-7-nhusb
sys/external/bsd/dwc2/dist/dwc2_hcd.c: netbsd-7-nhusb
sys/external/bsd/dwc2/dist/dwc2_hcd.h: netbsd-7-nhusb
sys/external/bsd/dwc2/dist/dwc2_hcdddma.c: netbsd-7-nhusb
sys/external/bsd/dwc2/dist/dwc2_hcdintr.c: netbsd-7-nhusb
sys/external/bsd/dwc2/dist/dwc2_hcdqueue.c: netbsd-7-nhusb
sys/external/bsd/dwc2/dist/dwc2_hw.h: netbsd-7-nhusb
sys/modules/drmkms_linux/Makefile: netbsd-7-nhusb
sys/modules/i915drmkms/Makefile: netbsd-7-nhusb
sys/rump/dev/lib/libugenhc/ugenhc.c: netbsd-7-nhusb
sys/rump/dev/lib/libusb/Makefile: netbsd-7-nhusb
sys/rump/dev/lib/libusb/USB.ioconf: netbsd-7-nhusb
sys/rump/dev/lib/libusb/usb_at_ugenhc.c: delete
sys/rump/dev/lib/libusb/opt/opt_usb.h: delete
sys/rump/dev/lib/libusb/opt/opt_usbverbose.h: delete
sys/sys/mbuf.h: netbsd-7-nhusb
usr.sbin/usbdevs/usbdevs.8: netbsd-7-nhusb
usr.sbin/usbdevs/usbdevs.c: netbsd-7-nhusb
Merge netbsd-7-nhusb:
- API / infrastructure changes to support memory management changes.
- Memory management improvements and bug fixes.
- HCDs should now be MP safe
- conversion to KERNHIST based debug
- FS/LS isoc support on ehci(4).
- conversion to kmem(9)
- Some USB 3 support - mostly from Takahiro HAYASHI (t-hash).
- interrupt transfers now get proper DMA operations
- general bug fixes
- kern/48308
- uhub status notification improvements
- umass(4) probe fix (applied to HEAD already)
- ohci(4) short transfer fix
- Change the SOFTINT level from NET to SERIAL for the USB softint handler.
This gives the callback a chance of running when another softint handler
at SOFTINT_NET has blocked holding a lock, e.g. softnet_lock and most of
the network stack.
- kern/49065 - ifconfig tun0 ... sequence locks up system / lockup:
softnet_lock held across usb xfr
- kern/50491 - unkillable wait in usbd_transfer while using usmsc0
on raspberry pi 2
- kern/51395 - USB Ethernet makes xhci hang
- Various improvements to slhci(4)
- Various improvements to dwc2(4)
 1.93.2.1 04-Nov-2016  pgoyette Sync with HEAD
 1.97.8.1 02-Nov-2017  snj Pull up following revision(s) (requested by pgoyette in ticket #335):
share/man/man9/kernhist.9: 1.5-1.8
sys/arch/acorn26/acorn26/pmap.c: 1.39
sys/arch/arm/arm32/fault.c: 1.105 via patch
sys/arch/arm/arm32/pmap.c: 1.350, 1.359
sys/arch/arm/broadcom/bcm2835_bsc.c: 1.7
sys/arch/arm/omap/if_cpsw.c: 1.20
sys/arch/arm/omap/tiotg.c: 1.7
sys/arch/evbarm/conf/RPI2_INSTALL: 1.3
sys/dev/ic/sl811hs.c: 1.98
sys/dev/usb/ehci.c: 1.256
sys/dev/usb/if_axe.c: 1.83
sys/dev/usb/motg.c: 1.18
sys/dev/usb/ohci.c: 1.274
sys/dev/usb/ucom.c: 1.119
sys/dev/usb/uhci.c: 1.277
sys/dev/usb/uhub.c: 1.137
sys/dev/usb/umass.c: 1.160-1.162
sys/dev/usb/umass_quirks.c: 1.100
sys/dev/usb/umass_scsipi.c: 1.55
sys/dev/usb/usb.c: 1.168
sys/dev/usb/usb_mem.c: 1.70
sys/dev/usb/usb_subr.c: 1.221
sys/dev/usb/usbdi.c: 1.175
sys/dev/usb/usbdi_util.c: 1.67-1.70
sys/dev/usb/usbroothub.c: 1.3
sys/dev/usb/xhci.c: 1.75
sys/external/bsd/drm2/dist/drm/i915/i915_gem.c: 1.34
sys/kern/kern_history.c: 1.15
sys/kern/kern_xxx.c: 1.74
sys/kern/vfs_bio.c: 1.275-1.276
sys/miscfs/genfs/genfs_io.c: 1.71
sys/sys/kernhist.h: 1.21
sys/ufs/ffs/ffs_balloc.c: 1.63
sys/ufs/lfs/lfs_vfsops.c: 1.361
sys/ufs/lfs/ulfs_inode.c: 1.21
sys/ufs/lfs/ulfs_vnops.c: 1.52
sys/ufs/ufs/ufs_inode.c: 1.102
sys/ufs/ufs/ufs_vnops.c: 1.239
sys/uvm/pmap/pmap.c: 1.37-1.39
sys/uvm/pmap/pmap_tlb.c: 1.22
sys/uvm/uvm_amap.c: 1.108
sys/uvm/uvm_anon.c: 1.64
sys/uvm/uvm_aobj.c: 1.126
sys/uvm/uvm_bio.c: 1.91
sys/uvm/uvm_device.c: 1.66
sys/uvm/uvm_fault.c: 1.201
sys/uvm/uvm_km.c: 1.144
sys/uvm/uvm_loan.c: 1.85
sys/uvm/uvm_map.c: 1.353
sys/uvm/uvm_page.c: 1.194
sys/uvm/uvm_pager.c: 1.111
sys/uvm/uvm_pdaemon.c: 1.109
sys/uvm/uvm_swap.c: 1.175
sys/uvm/uvm_vnode.c: 1.103
usr.bin/vmstat/vmstat.c: 1.219
Reorder to test for null before null deref in debug code
--
Reorder to test for null before null deref in debug code
--
KNF
--
No need for '\n' in UVMHIST_LOG
--
normalise a BIOHIST log message
--
Update the kernhist(9) kernel history code to address issues identified
in PR kern/52639, as well as some general cleaning-up...
(As proposed on tech-kern@ with additional changes and enhancements.)
Details of changes:
* All history arguments are now stored as uintmax_t values[1], both in
the kernel and in the structures used for exporting the history data
to userland via sysctl(9). This avoids problems on some architectures
where passing a 64-bit (or larger) value to printf(3) can cause it to
process the value as multiple arguments. (This can be particularly
problematic when printf()'s format string is not a literal, since in
that case the compiler cannot know how large each argument should be.)
* Update the data structures used for exporting kernel history data to
include a version number as well as the length of history arguments.
* All [2] existing users of kernhist(9) have had their format strings
updated. Each format specifier now includes an explicit length
modifier 'j' to refer to numeric values of the size of uintmax_t.
* All [2] existing users of kernhist(9) have had their format strings
updated to replace uses of "%p" with "%#jx", and the pointer
arguments are now cast to (uintptr_t) before being subsequently cast
to (uintmax_t). This is needed to avoid compiler warnings about
casting "pointer to integer of a different size."
* All [2] existing users of kernhist(9) have had instances of "%s" or
"%c" format strings replaced with numeric formats; several instances
of mis-match between format string and argument list have been fixed.
* vmstat(1) has been modified to handle the new size of arguments in the
history data as exported by sysctl(9).
* vmstat(1) now provides a warning message if the history requested with
the -u option does not exist (previously, this condition was silently
ignored, with only a single blank line being printed).
* vmstat(1) now checks the version and argument length included in the
data exported via sysctl(9) and exits if they do not match the values
with which vmstat was built.
* The kernhist(9) man-page has been updated to note the additional
requirements imposed on the format strings, along with several other
minor changes and enhancements.
[1] It would have been possible to use an explicit length (for example,
uint64_t) for the history arguments. But that would require another
"rototill" of all the users in the future when we add support for an
architecture that supports a larger size. Also, the printf(3)
format
specifiers for explicitly-sized values, such as "%"PRIu64, are much
more verbose (and less aesthetically appealing, IMHO) than simply
using "%ju".
[2] I've tried very hard to find "all [the] existing users of
kernhist(9)"
but it is possible that I've missed some of them. I would be glad
to
update any stragglers that anyone identifies.
--
For some reason this single kernel seems to have outgrown its declared
size as a result of the kernhist(9) changes. Bump the size.
XXX The amount of increase may be excessive - anyone with more detailed
XXX knowledge please feel free to further adjust the value
appropriately.
--
Misssed one cast of pointer --> uintptr_t in previous kernhist(9) commit
--
And yet another one. :(
--
Use correct mark-up for NetBSD version.
--
More improvements in grammar and readability.
--
Remove a stray '"' (obvious typo) and add a couple of casts that are
probably needed.
--
And replace an instance of "%p" conversion with "%#jx"
--
Whitespace fix. Give Bl tag table a width. Fix Xr.
 1.98.2.2 06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.98.2.1 16-Apr-2018  pgoyette Sync with HEAD, resolve some conflicts
 1.99.2.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.99.2.1 10-Jun-2019  christos Sync with HEAD
 1.101.4.1 01-Mar-2020  martin Pull up following revision(s) (requested by riastradh in ticket #744):

sys/dev/usb/uhci.c: revision 1.292
sys/dev/usb/uhci.c: revision 1.293
sys/dev/usb/usbdi.h: revision 1.99
sys/dev/usb/motg.c: revision 1.26
sys/dev/usb/motg.c: revision 1.27
sys/dev/usb/motg.c: revision 1.28
sys/dev/usb/motg.c: revision 1.29
sys/external/bsd/dwc2/dwc2.c: revision 1.70
sys/external/bsd/dwc2/dwc2.c: revision 1.71
sys/dev/usb/usb.c: revision 1.181
sys/arch/mips/adm5120/dev/ahci.c: revision 1.20
sys/dev/usb/usb.c: revision 1.182
sys/dev/usb/xhci.c: revision 1.116
sys/dev/usb/xhci.c: revision 1.117
sys/dev/usb/xhci.c: revision 1.118
sys/dev/usb/uhci.c: revision 1.289
sys/dev/usb/usbdivar.h: revision 1.121
sys/dev/usb/usbdi.c: revision 1.190
sys/dev/usb/usbdivar.h: revision 1.122
sys/dev/usb/usbdi.c: revision 1.191
sys/dev/usb/usbdi.c: revision 1.192
sys/external/bsd/dwc2/dwc2var.h: revision 1.7
sys/dev/usb/motg.c: revision 1.30
sys/dev/usb/motg.c: revision 1.31
sys/dev/usb/motg.c: revision 1.32
sys/dev/usb/motg.c: revision 1.33
sys/external/bsd/dwc2/dwc2.c: revision 1.67
sys/external/bsd/dwc2/dwc2.c: revision 1.68
sys/dev/usb/ehci.c: revision 1.270
sys/external/bsd/dwc2/dwc2.c: revision 1.69
sys/dev/usb/usbdi.h: revision 1.100
sys/dev/usb/ehci.c: revision 1.271
sys/arch/mips/adm5120/dev/ahci.c: revision 1.18
sys/dev/usb/usbdi.h: revision 1.101
sys/dev/usb/ehci.c: revision 1.272
sys/dev/ic/sl811hs.c: revision 1.103
sys/arch/mips/adm5120/dev/ahci.c: revision 1.19
sys/dev/usb/ehci.c: revision 1.273
sys/dev/usb/ohci.c: revision 1.293
sys/dev/usb/uhci.c: revision 1.290
sys/dev/usb/ohci.c: revision 1.294
sys/dev/usb/uhci.c: revision 1.291
sys/dev/usb/ohci.c: revision 1.295

Teach usb_rem_task to return whether removed from queue or not.

New function usb_task_pending for diagnostic assertions.
Usable only for negative diagnostic assertions:

KASSERT(!usb_task_pending(dev, task))

If you can think of a better name for this than !usb_task_pending,
I'm all ears.

-

Nothing guarantees xfer's timeout has completed.

Wait for it when we free the xfer.

-


New xfer state variables ux_timeout_set and ux_timeout_reset.

These are needed because:
- The host controller interrupt cannot wait for the callout or task
to finish running.
- Nothing in the USBD API as is waits for the callout or task to
finish running.
- Callers expect to be able to resubmit USB xfers from xfer callbacks
without waiting for anything to finish running.

The variable ux_timeout_set can be used by a host controller to
decide on submission whether to schedule the callout or to ask an
already-scheduled callout or already-queued task to reschedule the
callout, by setting the variable ux_timeout_reset to true.

When the callout or task runs and sees that ux_timeout_reset is true,
rather than queue the task or abort the xfer, it can instead just
schedule the callout anew.

-

Fix steady state of timeouts in ehci.

This is complicated because:
1. There are three ways that an xfer can be completed:
(a) hardware interrupt completes xfer
(b) software decision aborts xfer with USBD_CANCELLED
(c) timeout aborts xfer with USBD_TIMEOUT
2. The timeout abort can't be done in callout because ehci_sync_hc,
called unconditionally by ehci_abort_xfer to wait until the device
has finished using any references to the xfer, may sleep. So we
have to schedule a callout that, when run, will schedule a usb_task.
3. The hardware completion interrupt can't sleep waiting for a callout
or task to finish -- can't use callout_halt or usb_rem_task_wait.
So the callout and usb_task must be able to run _after_ the hardware
completion interrupt, and recognize that they're late to the party.
(Note, though, that usbd_free_xfer does wait for the callout and
task to complete, so there's no danger they may use themselves after
free.)
4. The xfer may resubmitted -- and the timeout may be rescheduled --
immediately after the hardware completion interrupt, _while_ the
callout and/or usb_task may still be scheduled. Specifically, we
may have the following sequence of events:
(a) hardware completion interrupt
(b) callout or usb_task fires
(c) driver resubmits xfer
(d) callout or usb_task acquires lock and looks around dazed and
bewildered at the firehose of events like reading the news in 2019

The mechanism for sorting this out is that we have two bits of state:
- xfer->ux_timeout_set informs the driver, when submitting an xfer and
setting up its timeout, whether either the callout or usb_task is
already scheduled or not.
- xfer->ux_timeout_reset informs the callout or usb_task whether it
should reschedule the callout, because the xfer got resubmitted, or
not.

-

Factor out HCI-independent xfer completion logic.

New API for HCI drivers to synchronize hardware completion
interrupts, synchronous aborts, and asynchronous timeouts:
- When submitting an xfer to hardware, call
usbd_xfer_schedule_timeout(xfer).
- On HCI completion interrupt for xfer completion:
if (!usbd_xfer_trycomplete(xfer))
return; /* timed out or aborted, ignore it */
- In upm_abort methods, call usbd_xfer_abort(xfer).

For HCI drivers that use this API (not needed in drivers that don't,
or for xfers like root intr xfers that don't use it):
- New ubm_abortx method serves role of former *hci_abort_xfer, but
without any logic for wrangling timeouts/callouts/tasks -- caller
in usbd_xfer_abort has already handled them.
- New ubm_dying method, returns true if the device is in the process
of detaching, used by the timeout logic.

Converted and tested:
- ehci
- ohci

Converted and compile-tested:
- ahci (XXX did this ever work?)
- dwc2
- motg (XXX missing usbd_xfer_schedule_timeout in motg_*_start?)
- uhci
- xhci

Not changed:
- slhci (sys/dev/ic/sl811hs.c) -- doesn't use a separate per-xfer
callout for timeouts (XXX but maybe should?)
- ugenhc (sys/rump/dev/lib/libugenhc/ugenhc.c) -- doesn't manage its
own transfer timeouts

-

Fix steady state of root intr xfers.

Why?
- Avoid completing a root intr xfer multiple times in races.
- Avoid potential use-after-free in poll_hub callouts (uhci, ahci).

How?
- Use sc->sc_intr_xfer or equivalent to store only a pending xfer
that has not yet completed -- whether successfully, by timeout, or
by synchronous abort. When any of those happens, set it to null
under the lock, so the xfer is completed only once.
- For hci drivers that use a callout to poll the root hub (uhci, ahci):
. Pass the softc pointer, not the xfer, to the callout, so the
callout is not even tempted to use xfer after free -- if the
callout fires, but the xfer is synchronously aborted before the
callout can do anything, the xfer might be freed by the time the
callout starts to examine it.
. Teach the callout to do nothing if it is callout_pending after it
has fired. This way:
1. completion or synchronous abort can just callout_stop
2. start can just callout_schedule
If the callout had already fired before (1), and doesn't acquire
the bus lock until after (2), it may be tempted to abort the new
root intr xfer just after submission, which would be wrong -- so
instead we just have the callout do nothing if it notices it has
been rescheduled, since it will fire again after the appropriate
time has elapsed.

-

Initialize xfer->ux_status in uhci_root_intr_start.

Otherwise, it will be USBD_NOT_STARTED, so usbd_ar_pipe will skip
calling upm_abort.
Candidate fix for PR kern/54963, same problem as reported at:
href="https://mail-index.NetBSD.org/current-users/2020/02/13/msg037740.html

-

Set ux_isdone in uhci_poll_hub for DIAGNOSTIC.

-

Fix mistakes in previous sloppy change with root intr xfers.
- Make sure ux_status is set to USBD_IN_PROGRESS when started.
Otherwise, if it is still in flight when we abort the pipe,
usbd_ar_pipe will skip calling upm_abort.
- Initialize ux_status under the lock; in principle a completion
interrupt (or a delay) could race with the initialization.
- KASSERT that the xfer is in progress when we're about to complete
it.

Candidate fix for PR kern/54963 for other HCI drivers than uhci.
ok nick
ok phone
(This is the change that nick evidently MEANT to ok when he ok'd the
previous one!)

-

Fix build

-

Fix non-DIAGNOSTIC builds.

-

Fix wrong KASSERT in motg abort.
This has been wrong since last summer when we did the transition to
xfer->ux_status = USBD_CANCELLED earlier.
XXX pullup-9

-

Fix mistakes in timeout/abort/completion changes in motg(4).
- Call usbd_xfer_schedule_timeout so we actually do time out.
- Don't call usbd_xfer_trycomplete until all the data have been
transferred -- it commits to completion, not timeout.
- Use xfer->ux_status != USBD_IN_PROGRESS to test whether, after a
partial write, an xfer has been interrupted or timed out and need
not be continued.
- Remove wrong assertion.

-

Fix mistake in use of usbd_xfer_schedule_timeout in motg.

This code path is used both for xfers that are new, and xfers that
are being done piece by piece and are partway done. For the latter
case, skip usbd_xfer_schedule_timeout so we schedule it only once per
xfer.

-

Simplify some branches and kassert some redundant assignments.
 1.102.2.1 29-Feb-2020  ad Sync with head.
 1.104.4.1 21-Mar-2021  thorpej Give config_found() the same variadic arguments treatment as
config_search(). This commit only adds the CFARG_EOL sentinel
to the existing config_found() calls. Conversion of config_found_sm_loc()
and config_found_ia() call sites will be in subsequent commits.
 1.105.8.1 04-Aug-2021  thorpej Adapt to CFARGS().
 1.6 24-Sep-2016  skrll Truncate the transfer length if an overflow is seen rather than halting.

Don't consider an EP11_STAT_SETUP as an error as it's not valid for
host operation.

Should fix kern/51500: axe(4) at slhci(4) does not attach, but there are
more problems with axe(4)
 1.5 24-Sep-2016  skrll Use bit defines to create bit groups for SL11_EPSTAT
 1.4 22-Sep-2013  skrll branches: 1.4.6; 1.4.10;
Remove all trailing whitespace
 1.3 02-Sep-2013  skrll KNF multi-line comments.
 1.2 15-Aug-2007  kiyohara branches: 1.2.60; 1.2.70; 1.2.76;
Replace to Matthew Orgass's slhci(4).
http://mail-index.netbsd.org/tech-kern/2007/06/26/0001.html
 1.1 11-Aug-2002  isaki branches: 1.1.2; 1.1.4; 1.1.6; 1.1.28; 1.1.70; 1.1.80; 1.1.84;
Add driver for ScanLogic SL811HS/T USB Host Controller.
XXX It's experimental code yet.

For x68k: USB part of Nereid USB/Ethernet/memory board
For ISA: ISA USB Host board from Morphy planning
 1.1.84.1 16-Aug-2007  jmcneill Sync with HEAD.
 1.1.80.1 15-Aug-2007  skrll Sync with HEAD.
 1.1.70.1 20-Aug-2007  ad Sync with HEAD.
 1.1.28.1 03-Sep-2007  yamt sync with head.
 1.1.6.2 06-Sep-2002  jdolecek sync kqueue branch with HEAD
 1.1.6.1 11-Aug-2002  jdolecek file sl811hsreg.h was added on branch kqueue on 2002-09-06 08:44:36 +0000
 1.1.4.2 29-Aug-2002  gehenna catch up with -current.
 1.1.4.1 11-Aug-2002  gehenna file sl811hsreg.h was added on branch gehenna-devsw on 2002-08-29 05:22:33 +0000
 1.1.2.2 13-Aug-2002  nathanw Catch up to -current.
 1.1.2.1 11-Aug-2002  nathanw file sl811hsreg.h was added on branch nathanw_sa on 2002-08-13 02:19:29 +0000
 1.2.76.1 18-May-2014  rmind sync with head
 1.2.70.2 03-Dec-2017  jdolecek update from HEAD
 1.2.70.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.2.60.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.4.10.1 04-Nov-2016  pgoyette Sync with HEAD
 1.4.6.1 05-Oct-2016  skrll Sync with HEAD
 1.12 23-Apr-2016  skrll Merge nick-nhusb

- API / infrastructure changes to support memory management changes.
- Memory management improvements and bug fixes.
- HCDs should now be MP safe
- conversion to KERNHIST based debug
- FS/LS isoc support on ehci(4).
- conversion to kmem(9)
- Some USB 3 support - mostly from Takahiro HAYASHI (t-hash).
- interrupt transfers now get proper DMA operations
- general bug fixes
- kern/48308
- uhub status notification improvements
- umass(4) probe fix (applied to HEAD already)
- ohci(4) short transfer fix
 1.11 02-Oct-2013  skrll branches: 1.11.4; 1.11.6; 1.11.10;
Modernise slhci. Many thanks to rkujawa@ for testing.
 1.10 22-Sep-2013  skrll Remove all trailing whitespace
 1.9 27-Oct-2012  chs branches: 1.9.2;
split device_t/softc for all remaining drivers.
replace "struct device *" with "device_t".
use device_xname(), device_unit(), etc.
 1.8 21-Jun-2011  kiyohara branches: 1.8.2; 1.8.12;
More stride for PSIONTEKLOGIX NETBOOK PRO.
 1.7 08-May-2010  isaki Move "opt_slhci.h" from .h to .c
to avoid link error (multiple definition of _KERNEL_OPT_foo).
 1.6 12-May-2009  cegger branches: 1.6.2; 1.6.4;
struct device * -> device_t, no functional changes intended.
 1.5 08-Apr-2008  cegger branches: 1.5.4; 1.5.18;
use aprint_*_dev and device_xname
 1.4 28-Mar-2008  drochner split device/softc for USB host controllers and the usb (control)
device,
this is hairy stuff, and I've only tested with uhci/ehci at pci,
please test the rest and report problems
 1.3 04-Jan-2008  ad branches: 1.3.6;
Start detangling lock.h from intr.h. This is likely to cause short term
breakage, but the mess of dependencies has been regularly breaking the
build recently anyhow.
 1.2 15-Aug-2007  kiyohara branches: 1.2.2; 1.2.8; 1.2.14;
Replace to Matthew Orgass's slhci(4).
http://mail-index.netbsd.org/tech-kern/2007/06/26/0001.html
 1.1 11-Aug-2002  isaki branches: 1.1.2; 1.1.4; 1.1.6; 1.1.28; 1.1.70; 1.1.80; 1.1.82; 1.1.86;
Add driver for ScanLogic SL811HS/T USB Host Controller.
XXX It's experimental code yet.

For x68k: USB part of Nereid USB/Ethernet/memory board
For ISA: ISA USB Host board from Morphy planning
 1.1.86.1 16-Aug-2007  jmcneill Sync with HEAD.
 1.1.82.1 15-Aug-2007  skrll Sync with HEAD.
 1.1.80.1 22-May-2007  itohy Overhaul of USB stack, mostly DMA related

This applies to NetBSD 4.99.13 (March 1, 2007)

usbdi(9) interface is based on FreeBSD version, excluding
- removal of portability code

Patch most NetBSD changes, excluding
- DMA memory "reserve", since we don't need contiguous buffers any longer
- volatiles in DMA structure, since it should not be needed
with proper bus_dmamap_sync(9)s

DMA/non-DMA memory management overhaul
- Move all DMA related code to usb_mem.[ch]
(add usb_alloc_buffer_dma(), usb_free_buffer_dma(), etc.).
XXX Should usb_mem.[ch] be renamed as usb_mem_dma.[ch] ?
- Add corresponding non-DMA code to usb_mem_nodma.[ch] .
Currently just use malloc(9).
- Above files are conditionally used by config framework (added
attributes to conf/files and dev/usb/files.usb).
- Add diagnostic panics when resource allocation is requested
on interrupt context.
- Change memory allocations (that require context) from NOWAIT to WAITOK.

Allocate DMA/non-DMA buffer per host interface, not globally.
advantage: Buffers can be freed on detaching host interface.
Activity of a host interface does not affect others.
disadvantages: It possibly consumes more memory.

API changes
- usbd_alloc_xfer() is changed:
old: usbd_xfer_handle usbd_alloc_xfer(usbd_device_handle dev);
new: usbd_xfer_handle usbd_alloc_xfer(usbd_device_handle dev,
usbd_pipe_handle pipe);
- pipe argument of usbd_setup_*xfer() are now unused
XXX the pipe argument should be removed?
- add mapping APIs
- async request will be processed as a task (kernel thread context),
and delayed to some extent
- usbdivar.h: struct usbd_xfer: renamed a member "allocbuf" to "hcbuffer"
(mapped/allocated/refered buffer for HCI driver)
- usb_port.h: change usb_proc_ptr from struct ptoc * to struct lwp *
- usb_port.h: add usb_sigproc_ptr for psignal(9) (struct proc *)
- usb.h: add UE_MAXPKTSZ(ep) and UE_MAXPKTSZ_MASK macros for USB 2.0

changes to USB device drivers
- atu, aue, axe, cdce, cue, kue, rum, udav, upl, ural, url,
uaudio, ubt, ucom, ugen, uhidev, uirda, ulpt, umidi, urio,
uscanner, ustir, utoppy:
* catch up API change of usbd_alloc_xfer()
- umass, usscanner:
* catch up API change of usbd_alloc_xfer()
* eliminate memory copy for large transfer

ohci
- free resources on detach
- add lots of bus_dmamap_sync() operations
- simplify the code of loading std chain
- rewrite code of looking up TD/ITD from DMA addr by using allocation chunk
- add workaround for CMD Tech 670 and 673 chipsets
- make sure resources are not allocated in interrupt context
- add support for mapping buffer and mbuf

slhci
- allocate xfer and slhci_xfer at once, and simplify relevant code
- add slhci_detach()
- remove second arg of slhci_attach() since it is the same as the first arg.
- add support for "mapping" (no, it doesn't map since it doesn't do DMA)
buffer and mbuf
- add pcmcia frontend
- NOT TESTED, missing hardware

ehci
- add lots of bus_dmamap_sync() operations, possibly too many
- make sure resources are not allocated in interrupt context
- add support for mapping buffer and mbuf
- done only simple test

uhci
- add lots of bus_dmamap_sync() operations, possibly too many
- make sure resources are not allocated in interrupt context
- add support for mapping buffer and mbuf

To do
- review, test, debug
- rewrite network drivers to utilize usbd_map_buffer_mbuf()
- rewrite uaudio(4) to eliminate memcpy
- "pipe" argument of usbd_setup_*xfer() should eventually be removed
 1.1.70.1 20-Aug-2007  ad Sync with HEAD.
 1.1.28.2 21-Jan-2008  yamt sync with head
 1.1.28.1 03-Sep-2007  yamt sync with head.
 1.1.6.2 06-Sep-2002  jdolecek sync kqueue branch with HEAD
 1.1.6.1 11-Aug-2002  jdolecek file sl811hsvar.h was added on branch kqueue on 2002-09-06 08:44:36 +0000
 1.1.4.2 29-Aug-2002  gehenna catch up with -current.
 1.1.4.1 11-Aug-2002  gehenna file sl811hsvar.h was added on branch gehenna-devsw on 2002-08-29 05:22:33 +0000
 1.1.2.2 13-Aug-2002  nathanw Catch up to -current.
 1.1.2.1 11-Aug-2002  nathanw file sl811hsvar.h was added on branch nathanw_sa on 2002-08-13 02:19:29 +0000
 1.2.14.1 08-Jan-2008  bouyer Sync with HEAD
 1.2.8.1 18-Feb-2008  mjf Sync with HEAD.
 1.2.2.1 09-Jan-2008  matt sync with HEAD
 1.3.6.2 02-Jun-2008  mjf Sync with HEAD.
 1.3.6.1 03-Apr-2008  mjf Sync with HEAD.
 1.5.18.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.5.4.2 11-Aug-2010  yamt sync with head.
 1.5.4.1 16-May-2009  yamt sync with head
 1.6.4.1 30-May-2010  rmind sync with head
 1.6.2.1 17-Aug-2010  uebayasi Sync with HEAD.
 1.8.12.3 03-Dec-2017  jdolecek update from HEAD
 1.8.12.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.8.12.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.8.2.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.8.2.1 30-Oct-2012  yamt sync with head
 1.9.2.1 18-May-2014  rmind sync with head
 1.11.10.1 06-Sep-2016  skrll First pass at netbsd-7 updated with USB code from HEAD
 1.11.6.1 04-Dec-2014  skrll Rework roothub control transfers so that much of the code is shared
across HCDs.

I have retained the vendor/product reporting for each HCD for now,
but it maybe get removed later.

ahci(4) now reports a language table and uses the usb_makestrdesc
function instead of rolling its own version.
 1.11.4.1 05-Apr-2017  snj Pull up following revision(s) (requested by skrll in ticket #1395):
share/man/man4/axe.4: netbsd-7-nhusb
share/man/man4/axen.4: netbsd-7-nhusb
share/man/man4/cdce.4: netbsd-7-nhusb
share/man/man4/uaudio.4: netbsd-7-nhusb
share/man/man4/ucom.4: netbsd-7-nhusb
share/man/man4/uep.4: netbsd-7-nhusb
share/man/man4/urtw.4: netbsd-7-nhusb
share/man/man4/usb.4: netbsd-7-nhusb
share/man/man4/uyap.4: netbsd-7-nhusb
share/man/man4/xhci.4: netbsd-7-nhusb
share/man/man9/usbdi.9: netbsd-7-nhusb
sys/arch/amd64/conf/ALL: netbsd-7-nhusb
sys/arch/amd64/conf/GENERIC: netbsd-7-nhusb
sys/arch/amiga/dev/slhci_zbus.c: netbsd-7-nhusb
sys/arch/arm/allwinner/awin_otg.c: netbsd-7-nhusb
sys/arch/arm/allwinner/awin_usb.c: netbsd-7-nhusb
sys/arch/arm/amlogic/amlogic_dwctwo.c: netbsd-7-nhusb
sys/arch/arm/at91/at91ohci.c: netbsd-7-nhusb
sys/arch/arm/broadcom/bcm2835_dwctwo.c: netbsd-7-nhusb
sys/arch/arm/broadcom/bcm53xx_usb.c: netbsd-7-nhusb
sys/arch/arm/ep93xx/epohci.c: netbsd-7-nhusb
sys/arch/arm/gemini/obio_ehci.c: netbsd-7-nhusb
sys/arch/arm/imx/files.imx23: netbsd-7-nhusb
sys/arch/arm/imx/imxusb.c: netbsd-7-nhusb
sys/arch/arm/imx/imxusbreg.h: netbsd-7-nhusb
sys/arch/arm/omap/obio_ohci.c: netbsd-7-nhusb
sys/arch/arm/omap/omap3_ehci.c: netbsd-7-nhusb
sys/arch/arm/omap/omapl1x_ohci.c: netbsd-7-nhusb
sys/arch/arm/omap/tiotg.c: netbsd-7-nhusb
sys/arch/arm/s3c2xx0/ohci_s3c24x0.c: netbsd-7-nhusb
sys/arch/arm/samsung/exynos_usb.c: netbsd-7-nhusb
sys/arch/arm/xscale/pxa2x0_ohci.c: netbsd-7-nhusb
sys/arch/arm/zynq/zynq_usb.c: netbsd-7-nhusb
sys/arch/hpcarm/dev/nbp_slhci.c: netbsd-7-nhusb
sys/arch/hpcmips/dev/plumohci.c: netbsd-7-nhusb
sys/arch/i386/conf/ALL: netbsd-7-nhusb
sys/arch/i386/conf/GENERIC: netbsd-7-nhusb
sys/arch/i386/pci/gcscehci.c: netbsd-7-nhusb
sys/arch/luna68k/conf/GENERIC: netbsd-7-nhusb
sys/arch/mips/adm5120/dev/ahci.c: netbsd-7-nhusb
sys/arch/mips/adm5120/dev/ahcivar.h: netbsd-7-nhusb
sys/arch/mips/alchemy/dev/ohci_aubus.c: netbsd-7-nhusb
sys/arch/mips/atheros/dev/ehci_arbus.c: netbsd-7-nhusb
sys/arch/mips/atheros/dev/ohci_arbus.c: netbsd-7-nhusb
sys/arch/mips/conf/files.adm5120: netbsd-7-nhusb
sys/arch/mips/ralink/ralink_ehci.c: netbsd-7-nhusb
sys/arch/mips/ralink/ralink_ohci.c: netbsd-7-nhusb
sys/arch/mips/rmi/rmixl_ehci.c: netbsd-7-nhusb
sys/arch/mips/rmi/rmixl_ohci.c: netbsd-7-nhusb
sys/arch/playstation2/dev/ohci_sbus.c: netbsd-7-nhusb
sys/arch/powerpc/booke/dev/pq3ehci.c: netbsd-7-nhusb
sys/arch/powerpc/ibm4xx/dev/dwctwo_plb.c: netbsd-7-nhusb
sys/arch/x68k/dev/slhci_intio.c: netbsd-7-nhusb
sys/conf/files: netbsd-7-nhusb
sys/dev/cardbus/ehci_cardbus.c: netbsd-7-nhusb
sys/dev/cardbus/ohci_cardbus.c: netbsd-7-nhusb
sys/dev/cardbus/uhci_cardbus.c: netbsd-7-nhusb
sys/dev/ic/sl811hs.c: netbsd-7-nhusb
sys/dev/ic/sl811hsvar.h: netbsd-7-nhusb
sys/dev/isa/slhci_isa.c: netbsd-7-nhusb
sys/dev/marvell/ehci_mv.c: netbsd-7-nhusb
sys/dev/pci/ehci_pci.c: netbsd-7-nhusb
sys/dev/pci/ohci_pci.c: netbsd-7-nhusb
sys/dev/pci/uhci_pci.c: netbsd-7-nhusb
sys/dev/pci/xhci_pci.c: netbsd-7-nhusb
sys/dev/pcmcia/slhci_pcmcia.c: netbsd-7-nhusb
sys/dev/usb/Makefile.usbdevs: netbsd-7-nhusb
sys/dev/usb/TODO: netbsd-7-nhusb
sys/dev/usb/TODO.usbmp: netbsd-7-nhusb
sys/dev/usb/aubtfwl.c: netbsd-7-nhusb
sys/dev/usb/auvitek.c: netbsd-7-nhusb
sys/dev/usb/auvitek_audio.c: netbsd-7-nhusb
sys/dev/usb/auvitek_dtv.c: netbsd-7-nhusb
sys/dev/usb/auvitek_i2c.c: netbsd-7-nhusb
sys/dev/usb/auvitek_video.c: netbsd-7-nhusb
sys/dev/usb/auvitekvar.h: netbsd-7-nhusb
sys/dev/usb/ehci.c: netbsd-7-nhusb
sys/dev/usb/ehcireg.h: netbsd-7-nhusb
sys/dev/usb/ehcivar.h: netbsd-7-nhusb
sys/dev/usb/emdtv.c: netbsd-7-nhusb
sys/dev/usb/emdtv_dtv.c: netbsd-7-nhusb
sys/dev/usb/emdtv_ir.c: netbsd-7-nhusb
sys/dev/usb/emdtvvar.h: netbsd-7-nhusb
sys/dev/usb/ezload.c: netbsd-7-nhusb
sys/dev/usb/ezload.h: netbsd-7-nhusb
sys/dev/usb/files.usb: netbsd-7-nhusb
sys/dev/usb/hid.c: netbsd-7-nhusb
sys/dev/usb/hid.h: netbsd-7-nhusb
sys/dev/usb/if_athn_usb.c: netbsd-7-nhusb
sys/dev/usb/if_athn_usb.h: netbsd-7-nhusb
sys/dev/usb/if_atu.c: netbsd-7-nhusb
sys/dev/usb/if_atureg.h: netbsd-7-nhusb
sys/dev/usb/if_aue.c: netbsd-7-nhusb
sys/dev/usb/if_auereg.h: netbsd-7-nhusb
sys/dev/usb/if_axe.c: netbsd-7-nhusb
sys/dev/usb/if_axen.c: netbsd-7-nhusb
sys/dev/usb/if_axenreg.h: netbsd-7-nhusb
sys/dev/usb/if_axereg.h: netbsd-7-nhusb
sys/dev/usb/if_cdce.c: netbsd-7-nhusb
sys/dev/usb/if_cdcereg.h: netbsd-7-nhusb
sys/dev/usb/if_cue.c: netbsd-7-nhusb
sys/dev/usb/if_cuereg.h: netbsd-7-nhusb
sys/dev/usb/if_kue.c: netbsd-7-nhusb
sys/dev/usb/if_kuereg.h: netbsd-7-nhusb
sys/dev/usb/if_otus.c: netbsd-7-nhusb
sys/dev/usb/if_otusvar.h: netbsd-7-nhusb
sys/dev/usb/if_rum.c: netbsd-7-nhusb
sys/dev/usb/if_rumreg.h: netbsd-7-nhusb
sys/dev/usb/if_rumvar.h: netbsd-7-nhusb
sys/dev/usb/if_run.c: netbsd-7-nhusb
sys/dev/usb/if_runvar.h: netbsd-7-nhusb
sys/dev/usb/if_smsc.c: netbsd-7-nhusb
sys/dev/usb/if_smscreg.h: netbsd-7-nhusb
sys/dev/usb/if_smscvar.h: netbsd-7-nhusb
sys/dev/usb/if_udav.c: netbsd-7-nhusb
sys/dev/usb/if_udavreg.h: netbsd-7-nhusb
sys/dev/usb/if_upgt.c: netbsd-7-nhusb
sys/dev/usb/if_upgtvar.h: netbsd-7-nhusb
sys/dev/usb/if_upl.c: netbsd-7-nhusb
sys/dev/usb/if_ural.c: netbsd-7-nhusb
sys/dev/usb/if_uralreg.h: netbsd-7-nhusb
sys/dev/usb/if_uralvar.h: netbsd-7-nhusb
sys/dev/usb/if_url.c: netbsd-7-nhusb
sys/dev/usb/if_urlreg.h: netbsd-7-nhusb
sys/dev/usb/if_urndis.c: netbsd-7-nhusb
sys/dev/usb/if_urndisreg.h: netbsd-7-nhusb
sys/dev/usb/if_urtw.c: netbsd-7-nhusb
sys/dev/usb/if_urtwn.c: netbsd-7-nhusb
sys/dev/usb/if_urtwn_data.h: netbsd-7-nhusb
sys/dev/usb/if_urtwnreg.h: netbsd-7-nhusb
sys/dev/usb/if_urtwnvar.h: netbsd-7-nhusb
sys/dev/usb/if_urtwreg.h: netbsd-7-nhusb
sys/dev/usb/if_zyd.c: netbsd-7-nhusb
sys/dev/usb/if_zydreg.h: netbsd-7-nhusb
sys/dev/usb/irmce.c: netbsd-7-nhusb
sys/dev/usb/moscom.c: netbsd-7-nhusb
sys/dev/usb/motg.c: netbsd-7-nhusb
sys/dev/usb/motgvar.h: netbsd-7-nhusb
sys/dev/usb/ohci.c: netbsd-7-nhusb
sys/dev/usb/ohcireg.h: netbsd-7-nhusb
sys/dev/usb/ohcivar.h: netbsd-7-nhusb
sys/dev/usb/pseye.c: netbsd-7-nhusb
sys/dev/usb/slurm.c: netbsd-7-nhusb
sys/dev/usb/stuirda.c: netbsd-7-nhusb
sys/dev/usb/u3g.c: netbsd-7-nhusb
sys/dev/usb/uark.c: netbsd-7-nhusb
sys/dev/usb/uatp.c: netbsd-7-nhusb
sys/dev/usb/uaudio.c: netbsd-7-nhusb
sys/dev/usb/uberry.c: netbsd-7-nhusb
sys/dev/usb/ubsa.c: netbsd-7-nhusb
sys/dev/usb/ubsa_common.c: netbsd-7-nhusb
sys/dev/usb/ubsavar.h: netbsd-7-nhusb
sys/dev/usb/ubt.c: netbsd-7-nhusb
sys/dev/usb/uchcom.c: netbsd-7-nhusb
sys/dev/usb/ucom.c: netbsd-7-nhusb
sys/dev/usb/ucomvar.h: netbsd-7-nhusb
sys/dev/usb/ucycom.c: netbsd-7-nhusb
sys/dev/usb/udl.c: netbsd-7-nhusb
sys/dev/usb/udl.h: netbsd-7-nhusb
sys/dev/usb/udsbr.c: netbsd-7-nhusb
sys/dev/usb/udsir.c: netbsd-7-nhusb
sys/dev/usb/uep.c: netbsd-7-nhusb
sys/dev/usb/uftdi.c: netbsd-7-nhusb
sys/dev/usb/uftdireg.h: netbsd-7-nhusb
sys/dev/usb/ugen.c: netbsd-7-nhusb
sys/dev/usb/ugensa.c: netbsd-7-nhusb
sys/dev/usb/uhci.c: netbsd-7-nhusb
sys/dev/usb/uhcireg.h: netbsd-7-nhusb
sys/dev/usb/uhcivar.h: netbsd-7-nhusb
sys/dev/usb/uhid.c: netbsd-7-nhusb
sys/dev/usb/uhidev.c: netbsd-7-nhusb
sys/dev/usb/uhidev.h: netbsd-7-nhusb
sys/dev/usb/uhmodem.c: netbsd-7-nhusb
sys/dev/usb/uhso.c: netbsd-7-nhusb
sys/dev/usb/uhub.c: netbsd-7-nhusb
sys/dev/usb/uipad.c: netbsd-7-nhusb
sys/dev/usb/uipaq.c: netbsd-7-nhusb
sys/dev/usb/uirda.c: netbsd-7-nhusb
sys/dev/usb/uirdavar.h: netbsd-7-nhusb
sys/dev/usb/ukbd.c: netbsd-7-nhusb
sys/dev/usb/ukbdmap.c: netbsd-7-nhusb
sys/dev/usb/ukyopon.c: netbsd-7-nhusb
sys/dev/usb/ukyopon.h: netbsd-7-nhusb
sys/dev/usb/ulpt.c: netbsd-7-nhusb
sys/dev/usb/umass.c: netbsd-7-nhusb
sys/dev/usb/umass_isdata.c: netbsd-7-nhusb
sys/dev/usb/umass_isdata.h: netbsd-7-nhusb
sys/dev/usb/umass_quirks.c: netbsd-7-nhusb
sys/dev/usb/umass_quirks.h: netbsd-7-nhusb
sys/dev/usb/umass_scsipi.c: netbsd-7-nhusb
sys/dev/usb/umass_scsipi.h: netbsd-7-nhusb
sys/dev/usb/umassvar.h: netbsd-7-nhusb
sys/dev/usb/umcs.c: netbsd-7-nhusb
sys/dev/usb/umct.c: netbsd-7-nhusb
sys/dev/usb/umidi.c: netbsd-7-nhusb
sys/dev/usb/umidi_quirks.c: netbsd-7-nhusb
sys/dev/usb/umidi_quirks.h: netbsd-7-nhusb
sys/dev/usb/umodem.c: netbsd-7-nhusb
sys/dev/usb/umodem_common.c: netbsd-7-nhusb
sys/dev/usb/umodemvar.h: netbsd-7-nhusb
sys/dev/usb/ums.c: netbsd-7-nhusb
sys/dev/usb/uplcom.c: netbsd-7-nhusb
sys/dev/usb/urio.c: netbsd-7-nhusb
sys/dev/usb/urio.h: netbsd-7-nhusb
sys/dev/usb/usb.c: netbsd-7-nhusb
sys/dev/usb/usb.h: netbsd-7-nhusb
sys/dev/usb/usb_mem.c: netbsd-7-nhusb
sys/dev/usb/usb_mem.h: netbsd-7-nhusb
sys/dev/usb/usb_quirks.c: netbsd-7-nhusb
sys/dev/usb/usb_quirks.h: netbsd-7-nhusb
sys/dev/usb/usb_subr.c: netbsd-7-nhusb
sys/dev/usb/usbdevices.config: netbsd-7-nhusb
sys/dev/usb/usbdevs: netbsd-7-nhusb
sys/dev/usb/usbdevs.h: netbsd-7-nhusb
sys/dev/usb/usbdevs_data.h: netbsd-7-nhusb
sys/dev/usb/usbdi.c: netbsd-7-nhusb
sys/dev/usb/usbdi.h: netbsd-7-nhusb
sys/dev/usb/usbdi_util.c: netbsd-7-nhusb
sys/dev/usb/usbdi_util.h: netbsd-7-nhusb
sys/dev/usb/usbdivar.h: netbsd-7-nhusb
sys/dev/usb/usbhid.h: netbsd-7-nhusb
sys/dev/usb/usbhist.h: netbsd-7-nhusb
sys/dev/usb/usbroothub.c: netbsd-7-nhusb
sys/dev/usb/usbroothub.h: netbsd-7-nhusb
sys/dev/usb/usbroothub_subr.c: delete
sys/dev/usb/usbroothub_subr.h: delete
sys/dev/usb/uscanner.c: netbsd-7-nhusb
sys/dev/usb/uslsa.c: netbsd-7-nhusb
sys/dev/usb/usscanner.c: netbsd-7-nhusb
sys/dev/usb/ustir.c: netbsd-7-nhusb
sys/dev/usb/uthum.c: netbsd-7-nhusb
sys/dev/usb/utoppy.c: netbsd-7-nhusb
sys/dev/usb/uts.c: netbsd-7-nhusb
sys/dev/usb/uvideo.c: netbsd-7-nhusb
sys/dev/usb/uvisor.c: netbsd-7-nhusb
sys/dev/usb/uvscom.c: netbsd-7-nhusb
sys/dev/usb/uyap.c: netbsd-7-nhusb
sys/dev/usb/uyap_firmware.h: netbsd-7-nhusb
sys/dev/usb/uyurex.c: netbsd-7-nhusb
sys/dev/usb/x1input_rdesc.h: netbsd-7-nhusb
sys/dev/usb/xhci.c: netbsd-7-nhusb
sys/dev/usb/xhcireg.h: netbsd-7-nhusb
sys/dev/usb/xhcivar.h: netbsd-7-nhusb
sys/dev/usb/xinput_rdesc.h: netbsd-7-nhusb
sys/external/bsd/common/conf/files.linux: netbsd-7-nhusb
sys/external/bsd/common/include/linux/err.h: netbsd-7-nhusb
sys/external/bsd/common/include/linux/kernel.h: netbsd-7-nhusb
sys/external/bsd/common/include/linux/workqueue.h: netbsd-7-nhusb
sys/external/bsd/common/linux/linux_work.c: netbsd-7-nhusb
sys/external/bsd/drm2/dist/drm/radeon/atombios_encoders.c: netbsd-7-nhusb
sys/external/bsd/drm2/dist/drm/radeon/radeon_legacy_encoders.c: netbsd-7-nhusb
sys/external/bsd/drm2/drm/files.drmkms: netbsd-7-nhusb
sys/external/bsd/drm2/i915drm/files.i915drmkms: netbsd-7-nhusb
sys/external/bsd/drm2/include/linux/err.h: delete
sys/external/bsd/drm2/include/linux/workqueue.h: delete
sys/external/bsd/drm2/linux/files.drmkms_linux: netbsd-7-nhusb
sys/external/bsd/drm2/linux/linux_work.c: delete
sys/external/bsd/dwc2/dwc2.c: netbsd-7-nhusb
sys/external/bsd/dwc2/dwc2.h: netbsd-7-nhusb
sys/external/bsd/dwc2/dwc2var.h: netbsd-7-nhusb
sys/external/bsd/dwc2/dwctwo2netbsd: netbsd-7-nhusb
sys/external/bsd/dwc2/conf/files.dwc2: netbsd-7-nhusb
sys/external/bsd/dwc2/dist/dwc2_core.c: netbsd-7-nhusb
sys/external/bsd/dwc2/dist/dwc2_core.h: netbsd-7-nhusb
sys/external/bsd/dwc2/dist/dwc2_coreintr.c: netbsd-7-nhusb
sys/external/bsd/dwc2/dist/dwc2_hcd.c: netbsd-7-nhusb
sys/external/bsd/dwc2/dist/dwc2_hcd.h: netbsd-7-nhusb
sys/external/bsd/dwc2/dist/dwc2_hcdddma.c: netbsd-7-nhusb
sys/external/bsd/dwc2/dist/dwc2_hcdintr.c: netbsd-7-nhusb
sys/external/bsd/dwc2/dist/dwc2_hcdqueue.c: netbsd-7-nhusb
sys/external/bsd/dwc2/dist/dwc2_hw.h: netbsd-7-nhusb
sys/modules/drmkms_linux/Makefile: netbsd-7-nhusb
sys/modules/i915drmkms/Makefile: netbsd-7-nhusb
sys/rump/dev/lib/libugenhc/ugenhc.c: netbsd-7-nhusb
sys/rump/dev/lib/libusb/Makefile: netbsd-7-nhusb
sys/rump/dev/lib/libusb/USB.ioconf: netbsd-7-nhusb
sys/rump/dev/lib/libusb/usb_at_ugenhc.c: delete
sys/rump/dev/lib/libusb/opt/opt_usb.h: delete
sys/rump/dev/lib/libusb/opt/opt_usbverbose.h: delete
sys/sys/mbuf.h: netbsd-7-nhusb
usr.sbin/usbdevs/usbdevs.8: netbsd-7-nhusb
usr.sbin/usbdevs/usbdevs.c: netbsd-7-nhusb
Merge netbsd-7-nhusb:
- API / infrastructure changes to support memory management changes.
- Memory management improvements and bug fixes.
- HCDs should now be MP safe
- conversion to KERNHIST based debug
- FS/LS isoc support on ehci(4).
- conversion to kmem(9)
- Some USB 3 support - mostly from Takahiro HAYASHI (t-hash).
- interrupt transfers now get proper DMA operations
- general bug fixes
- kern/48308
- uhub status notification improvements
- umass(4) probe fix (applied to HEAD already)
- ohci(4) short transfer fix
- Change the SOFTINT level from NET to SERIAL for the USB softint handler.
This gives the callback a chance of running when another softint handler
at SOFTINT_NET has blocked holding a lock, e.g. softnet_lock and most of
the network stack.
- kern/49065 - ifconfig tun0 ... sequence locks up system / lockup:
softnet_lock held across usb xfr
- kern/50491 - unkillable wait in usbd_transfer while using usmsc0
on raspberry pi 2
- kern/51395 - USB Ethernet makes xhci hang
- Various improvements to slhci(4)
- Various improvements to dwc2(4)
 1.7 13-Mar-2013  macallan fix typo
 1.6 13-Mar-2013  macallan add some register bits
 1.5 07-Dec-2011  macallan branches: 1.5.6;
add a bunch of register definitions
 1.4 08-Nov-2011  macallan branches: 1.4.4;
fix a typo
 1.3 28-Sep-2011  macallan branches: 1.3.2;
add a couple more registers
 1.2 31-Aug-2011  macallan add a couple more register definitions
 1.1 12-Aug-2009  macallan branches: 1.1.2;
add voyagerfb, a driver for the Gdium Liberty 1000's onboard graphics chip
 1.1.2.2 19-Aug-2009  yamt sync with head.
 1.1.2.1 12-Aug-2009  yamt file sm502reg.h was added on branch yamt-nfs-mp on 2009-08-19 18:47:08 +0000
 1.3.2.3 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.3.2.2 17-Apr-2012  yamt sync with head
 1.3.2.1 10-Nov-2011  yamt sync with head
 1.4.4.1 18-Feb-2012  mrg merge to -current.
 1.5.6.1 23-Jun-2013  tls resync from head
 1.99 07-Sep-2024  andvar spelling and grammar fixes, mainly in comments.
 1.98 29-Jun-2024  riastradh branches: 1.98.2;
if_stats(9): Add ifp argument to if_stat..._ref.

This will enable us to pass the ifp through to a dtrace probe inside.

No functional change intended in this change, but this is an API
change visible to modules so it shouldn't be pulled up.

PR kern/58377
 1.97 10-Feb-2024  andvar s/alloted/allotted/ in comments.
 1.96 25-Sep-2022  thorpej Remove unnecessary include of <sys/malloc.h>.
 1.95 15-Mar-2020  thorpej Don't bother with IFF_OACTIVE.
 1.94 12-Mar-2020  thorpej Add support for MBUFTRACE.
 1.93 07-Feb-2020  thorpej Use callout_setfunc() / callout_schedule().
 1.92 30-Jan-2020  thorpej Adopt <net/if_stats.h>.
 1.91 22-Jan-2020  thorpej Static'ify.
 1.90 28-May-2019  msaitoh branches: 1.90.4;
Use ETHER_LOCK()/ETHER_UNLOCK() for all ethernet drivers to protect ec_multi*.
 1.89 23-May-2019  msaitoh Whitespace fix (mainly tabify).
 1.88 23-May-2019  msaitoh No functional change:
- Simplify MII structure initialization and reference.
- u_int*_t -> uint*_t.
- KNF
 1.87 22-Jan-2019  msaitoh Change MII PHY read/write API from:

int (*mii_readreg_t)(device_t, int, int);
void (*mii_writereg_t)(device_t, int, int, int);
to:

int (*mii_readreg_t)(device_t, int, int, uint16_t *);
int (*mii_writereg_t)(device_t, int, int, uint16_t);

Now we can test if a read/write operation failed or not by the return value.

In 802.3 spec says that the PHY shall not respond to read/write transaction
to the unimplemented register(22.2.4.3). Detecting timeout can be used to
check whether a register is implemented or not (if the register conforms to
the spec). ukphy(4) can be used this for MII_MMDACR and MII_MMDAADR.

Note that I noticed that the following code do infinite loop in the
read/wirte function. If it accesses unimplemented PHY register, it will hang.
It should be fixed:

arm/at91/at91emac.c
arm/ep93xx/epe.c
arm/omap/omapl1x_emac.c
mips/ralink/ralink_eth.c
arch/powerpc/booke/dev/pq3etsec.c(read)
dev/cadence/if_cemac.c <- hkenken
dev/ic/lan9118.c


Tested with the following device:

axe+ukphy
axe+rgephy
axen+rgephy (tested by Andrius V)
wm+atphy
wm+ukphy
wm+igphy
wm+ihphy
wm+makphy
sk+makphy
sk+brgphy
sk+gentbi
msk+makphy
sip+icsphy
sip+ukphy
re+rgephy
bge+brgphy
bnx+brgphy
gsip+gphyter
rtk+rlphy
fxp+inphy (tested by Andrius V)
tlp+acphy
ex+exphy
epic+qsphy
vge+ciphy (tested by Andrius V)
vr+ukphy (tested by Andrius V)
vte+ukphy (tested by Andrius V)

Not tested (MAC):
arm:at91emac
arm:cemac
arm:epe
arm:geminigmac
arm:enet
arm:cpsw
arm:emac(omac)
arm:emac(sunxi)
arm:npe
evbppc:temac
macppc:bm
macppc:gm
mips:aumac
mips:ae
mips:cnmac
mips:reth
mips:sbmac
playstation2:smap
powerpc:tsec
powerpc:emac(ibm4xx)
sgimips:mec
sparc:be
sf
ne(ax88190, dl10019)
awge
ep
gem
hme
smsh
mtd
sm
age
alc
ale
bce
cas
et
jme
lii
nfe
pcn
ste
stge
tl
xi
aue
mue
smsc
udav
url

Not tested (PHY):
amhphy
bmtphy
dmphy
etphy
glxtphy
ikphy
iophy
lxtphy
nsphyter
pnaphy
rdcphy
sqphy
tlphy
tqphy
urlphy
 1.86 26-Jun-2018  msaitoh branches: 1.86.2;
Implement the BPF direction filter (BIOC[GS]DIRECTION). It provides backward
compatibility with BIOC[GS]SEESENT ioctl. The userland interface is the same
as FreeBSD.

This change also fixes a bug that the direction is misunderstand on some
environment by passing the direction to bpf_mtap*() instead of checking
m->m_pkthdr.rcvif.
 1.85 20-Feb-2017  ozaki-r branches: 1.85.12;
Apply deferred if_start to more drivers
 1.84 15-Dec-2016  ozaki-r branches: 1.84.2;
Move bpf_mtap and if_ipackets++ on Rx of each driver to percpuq if_input

The benefits of the change are:
- We can reduce codes
- We can provide the same behavior between drivers
- Where/When if_ipackets is counted up
- Note that some drivers still update packet statistics in their own
way (periodical update)
- Moved bpf_mtap run in softint
- This makes it easy to MP-ify bpf

Proposed on tech-kern and tech-net
 1.83 10-Jun-2016  ozaki-r branches: 1.83.2;
Introduce m_set_rcvif and m_reset_rcvif

The API is used to set (or reset) a received interface of a mbuf.
They are counterpart of m_get_rcvif, which will come in another
commit, hide internal of rcvif operation, and reduce the diff of
the upcoming change.

No functional change.
 1.82 09-Feb-2016  ozaki-r Introduce softint-based if_input

This change intends to run the whole network stack in softint context
(or normal LWP), not hardware interrupt context. Note that the work is
still incomplete by this change; to that end, we also have to softint-ify
if_link_state_change (and bpf) which can still run in hardware interrupt.

This change softint-ifies at ifp->if_input that is called from
each device driver (and ieee80211_input) to ensure Layer 2 runs
in softint (e.g., ether_input and bridge_input). To this end,
we provide a framework (called percpuq) that utlizes softint(9)
and percpu ifqueues. With this patch, rxintr of most drivers just
queues received packets and schedules a softint, and the softint
dequeues packets and does rest packet processing.

To minimize changes to each driver, percpuq is allocated in struct
ifnet for now and that is initialized by default (in if_attach).
We probably have to move percpuq to softc of each driver, but it's
future work. At this point, only wm(4) has percpuq in its softc
as a reference implementation.

Additional information including performance numbers can be found
in the thread at tech-kern@ and tech-net@:
http://mail-index.netbsd.org/tech-kern/2016/01/14/msg019997.html

Acknowledgment: riastradh@ greatly helped this work.
Thank you very much!
 1.81 22-Jul-2012  matt branches: 1.81.2; 1.81.16;
Fix mii_statchg to take a 'struct ifnet *' instead of device_t. This fixes
problem with a common MDIO bus used for multiple interfaces.
Some drivers converted to CFATTACL_DECL_NEW.
 1.80 13-Nov-2010  uebayasi branches: 1.80.8;
Don't pull in the whole uvm(9) API to access only PAGE_SIZE and
some other constants. These are provided by sys/param.h now.
 1.79 05-Apr-2010  joerg Push the bpf_ops usage back into bpf.h. Push the common ifp->if_bpf
check into the inline functions as well the fourth argument for
bpf_attach.
 1.78 19-Jan-2010  pooka branches: 1.78.2; 1.78.4;
Redefine bpf linkage through an always present op vector, i.e.
#if NBPFILTER is no longer required in the client. This change
doesn't yet add support for loading bpf as a module, since drivers
can register before bpf is attached. However, callers of bpf can
now be modularized.

Dynamically loadable bpf could probably be done fairly easily with
coordination from the stub driver and the real driver by registering
attachments in the stub before the real driver is loaded and doing
a handoff. ... and I'm not going to ponder the depths of unload
here.

Tested with i386/MONOLITHIC, modified MONOLITHIC without bpf and rump.
 1.77 03-Sep-2009  tsutsui Replace shutdownhook_establish(9) with pmf_device_register1().
Tested EtherPower II 10/100 (SMC9432TX) on macppc.
 1.76 06-Jul-2008  tsutsui Split device_t/softc with misc cosmetic changes.
 1.75 04-May-2008  xtraeme branches: 1.75.2; 1.75.4;
mii_dev is a device_t now.
 1.74 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.73 08-Apr-2008  cegger branches: 1.73.2; 1.73.4;
use aprint_*_dev and device_xname
 1.72 12-Mar-2008  dyoung epic_stop: clear IFF_RUNNING before disabling.
 1.71 19-Jan-2008  dyoung branches: 1.71.2; 1.71.6;
Make many ethernet drivers share the common code for MII media
handling, ether_mediastatus() and ether_mediachange(). Check for
a non-ENXIO error return from mii_mediachg(). (ENXIO indicates
that a PHY is suspended.)

This patch shrinks the source code size by 979 lines. There was
a 5100-byte savings on the NetBSD/i386 kernel configuration, ALL.

I have made a few miscellaneous changes, too:

gem(4): use LIST_EMPTY(), LIST_FOREACH().
mtd(4): handle media ioctls, for a change!
axe(4): do not track link status in sc->axe_link any longer
nfe(4), aue(4), axe(4), udav(4), url(4): do not reset all PHYs
on a change of media

Except for the change to mtd(4), no functional changes are intended.

XXX This patch affects more architectures than I can feasibly
XXX compile and run. I have compiled macppc, sparc64, i386. I
XXX have run the patches on i386 boxen with bnx(4) and sip(4).
XXX Compiling and running on evbmips (MERAKI, ADM5120) is in
XXX progress.
 1.70 30-Dec-2007  dyoung Cosmetic: remark that EPIC may deserve one or two custom PHY drivers.
Change a !(bittest) to (bittest) == 0.
 1.69 29-Dec-2007  dyoung Use LIST_EMPTY(), LIST_FOREACH().
 1.68 29-Dec-2007  tsutsui Fix typo in comments.
 1.67 19-Oct-2007  ad branches: 1.67.2; 1.67.8;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.66 27-Aug-2007  dyoung branches: 1.66.2; 1.66.6;
Constify: use CLLADDR() instead of LLADDR() wherever possible.
 1.65 09-Jul-2007  ad branches: 1.65.2; 1.65.6;
Merge some of the less invasive changes from the vmlocking branch:

- kthread, callout, devsw API changes
- select()/poll() improvements
- miscellaneous MT safety improvements
 1.64 04-Mar-2007  christos branches: 1.64.2; 1.64.4;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.63 16-Apr-2006  tsutsui branches: 1.63.14;
u_intNN_t -> uintNN_t
 1.62 16-Apr-2006  tsutsui Use __arraycount().
 1.61 16-Apr-2006  tsutsui i >= 0 can never be false if i is u_int. Noticed by OpenBSD.
 1.60 11-Dec-2005  christos branches: 1.60.4; 1.60.6; 1.60.8; 1.60.10; 1.60.12;
merge ktrace-lwp.
 1.59 27-Feb-2005  perry branches: 1.59.4;
nuke trailing whitespace
 1.58 04-Feb-2005  perry de-__P
 1.57 30-Jan-2005  thorpej Eliminate use of M_HASFCS.
 1.56 30-Oct-2004  thorpej branches: 1.56.4; 1.56.6;
When adding/deleting multicast addresses, only whack the address
filter if the interface is marked RUNNING.

Fixes kern/27678.
 1.55 08-Nov-2003  tsutsui branches: 1.55.4;
Define all members in TX/RX DMA descriptors as u_int32_t and use proper shift
and mask ops since smc83c170 chips access them in 32bit width with proper
byteswap mechanism, so that all #if BYTE_ORDER in descriptors can be removed.
While here, do some slight optimizations in epic_start() and epic_intr().
 1.54 02-Nov-2003  wiz Fix some typos. From Tom Cosgrove via jmc@openbsd.
 1.53 31-Jan-2003  thorpej branches: 1.53.2;
Use aprint_*().
 1.52 13-Jan-2003  bouyer For short (< ETHER_MIN_LEN) packets, supply a zero'd buffer for the extra
bytes to make sure the chip won't send random data.
 1.51 07-Nov-2002  thorpej Fix signed/unsigned comparison warnings.
 1.50 22-Oct-2002  fair Change the "dontcare bits" argument to ifmedia_init() to IFM_IMASK
so that it is possible select PHY instances other than the first
one (instance zero), if there is more than one PHY attached.
 1.49 13-Nov-2001  lukem branches: 1.49.10;
add/cleanup RCSID
 1.48 23-Jul-2001  thorpej Make sure to initialize the all Rx descriptors properly in *_init()
even if mbufs for them are already allocated.
 1.47 19-Jul-2001  thorpej Use BUS_DMA_READ and BUS_DMA_WRITE in some obvious places.
 1.46 07-Jul-2001  thorpej branches: 1.46.2;
bcmp -> memcmp
 1.45 12-Jun-2001  thorpej Don't need INET or NS includes here.
 1.44 17-May-2001  drochner increase the delay after PHY reset - it seems that mii register accesses
can fail if attempted too soon after reset
 1.43 17-May-2001  drochner support BNC interfaces (serial mode) as on the SMC9432BTX and 100FX
on the SMC9432FTX
 1.42 15-Mar-2001  tsutsui Fix tyop in comments.
 1.41 19-Dec-2000  thorpej branches: 1.41.2;
Fix a problem with the ALTQ changes that can cause bogus memory
refernces. Problem reported by Luke Mewburn.
 1.40 14-Dec-2000  thorpej ALTQ'ify.
 1.39 15-Nov-2000  thorpej Move bpfattach()/bpfdetach() calls into ether_ifattach()/ether_ifdetach().
 1.38 14-Nov-2000  thorpej NBPG -> PAGE_SIZE
 1.37 08-Nov-2000  thorpej One more fix to multicast hash computation. Submitter confirms that
with this fix, multicast does indeed work properly on the EPIC.

From Zdenek Salvet <salvet@ics.muni.cz>.
 1.36 18-Oct-2000  bouyer Looks like frame size isn't checked; just say we can do VLAN MTU.
Tested with a SMC9432TX.
 1.35 15-Oct-2000  thorpej Don't trim off the FCS, pass it up.
 1.34 11-Oct-2000  thorpej Use ether_ioctl().
 1.33 01-Oct-2000  thorpej Move the check for "promisc + unicast + not for us" into ether_input(),
and change Ethernet drivers to always pass all received frames to
ether_input() (with a few exceptions, which are documented in the
code).
 1.32 26-May-2000  tsutsui branches: 1.32.4;
Don't use bcopy() to copy u_int16_t data to u_int8_t array.
 1.31 12-May-2000  thorpej Oops! We actually want the *lower* 6 bits of the crc32 of the multicast
address to generate the multicast filter bit index, not the upper 6.

Should address kern/8268.
 1.30 12-May-2000  thorpej Use ether_crc32_le().
 1.29 23-Mar-2000  thorpej New callout mechanism with two major improvements over the old
timeout()/untimeout() API:
- Clients supply callout handle storage, thus eliminating problems of
resource allocation.
- Insertion and removal of callouts is constant time, important as
this facility is used quite a lot in the kernel.

The old timeout()/untimeout() API has been removed from the kernel.
 1.28 06-Mar-2000  thorpej No longer necessary to futz with ifp->if_baudrate here.
 1.27 06-Mar-2000  enami Remove redundant assignment.
 1.26 08-Feb-2000  thorpej Don't rely on the receive descriptor's BCAST/MCAST status bits. Test the
Ethernet destination address to see if it's multicast.
 1.25 02-Feb-2000  thorpej Don't dry to diving MIIF_NOISOLATE in the PHY drivers. Instead, pass
flags down from the parent to child vi mii_attach().
 1.24 02-Feb-2000  thorpej Bring some order to the chaos which was the MII code function naming
"conventions".
 1.23 12-Nov-1999  thorpej Call mii_down() as appropriate.
 1.22 04-Nov-1999  thorpej Adapt to mii_phy_probe() change.
 1.21 27-Aug-1999  thorpej branches: 1.21.2; 1.21.4; 1.21.8;
- Include the RXE (receive error) interrupt in the interrupt enable mask,
and consider it to be like an RCC (receive copy complete). The RCC
code path has always checked for bad received packets.
- Trim the CRC length off the recived packet length; the EPIC/100 always
includes the CRC in the packet.
- Improve fatal error reporting.
 1.20 25-Aug-1999  thorpej When padding short packets on transmit, don't include the CRC length
in the computation. kern/8194.
 1.19 03-Aug-1999  thorpej Be a little nicer about memory usage:
* Don't allocate receive buffers until the interface is actually brought
up, and release all of them if the interface is taken down.
* Add a knob (defaults to off) which will copy an incoming packet to
a single header mbuf if it is small enough to fit in one, rather than
burning an entire cluster on it. Note that this change will be mostly
moot if/when sbcompress() it changed to handle compressing clusters.
 1.18 27-Jul-1999  thorpej Make this "should work" on big endian systems.
 1.17 18-Jun-1999  thorpej Fix that ANNOYING transmit timeout bug, caused by an unfortunate interaction
between a bug in the receive path (buffer length used instead of actual
received frame length) and the ARP code not correctly setting the length
of the reused mbuf, which all told caused the transmit logic in the chip
to wedge.

Also, make sure to count received packets.

Found and fixed by Zdenek Salvet <salvet@ics.muni.cz>, PR #7809.
 1.16 18-May-1999  thorpej Rework layer 2 protocol input routines. Instead of calling e.g. ether_input()
directly, call the function pointer (*if_input)(ifp, m). The input routine
expects the packet header to be at the head of the packet, and will adjust
as necessary. Privatize the layer 2 input and output routines, allowing
*_ifattach() to set them up as appropriate.
 1.15 25-Mar-1999  thorpej branches: 1.15.2; 1.15.4; 1.15.6;
Use ETHER_*_LEN constants from <net/if_ether.h> instead of defining them
ourselves. Fix a bug where packets wouldn't be padded to the correct
minimum length.
 1.14 18-Feb-1999  thorpej Fix the code in epic_attach() that frees resources when the attach fails.
 1.13 18-Feb-1999  thorpej Only do the multicast filter bug work-around if in 10Mbps mode. Also,
don't reset the interface if the multicast list changes. Just reprogram
the multicast hash table.
 1.12 17-Feb-1999  thorpej Change a straggling splimp -> splnet.
 1.11 13-Feb-1999  thorpej Make sure full-duplex is reflected in TXCON, and don't reset the interface
when the media changes.
 1.10 12-Feb-1999  thorpej Cleanup of the EPIC/100 driver I did while hacking on the Rhine driver:
* Macroize hardware and software descriptor access (much easier to read).
* Simplify and optimize the transmit loop a bit, and use IFF_OACTIVE as
appropriate.
* Fix a potential race condition in the transmit loop. This change has
made the driver significantly more stable (almost completely eliminated
the "device timeout" errors that have plagued this driver).
* Implement transmit interrupt pacing.
* Add missing bus_dmamap_sync() calls (on transmit and receive descriptors
and fraglists). (Draining the write buffer when accessing these structures
may have also contributed to the increased stability of this driver on
the Alpha.)
 1.9 05-Oct-1998  thorpej branches: 1.9.4;
In epic_init(), attempt to start output on the interface once the interface
is initialized.
 1.8 11-Aug-1998  thorpej Adapt to new MII code.
 1.7 08-Aug-1998  mycroft Use splnet, not splimp.
 1.6 23-Jul-1998  thorpej Slight variation on last; be a bit more zealous about fixing up the
clock source. Now, when my EtherPower II locks up, it eventually recovers!

(Geez, I'd like to know why it does this, and only apparently in 10mb/s mode).
 1.5 20-Jul-1998  thorpej Write the CLOCK TEST bit *at least 16 consecutive times* during initialization,
as the clock source will be set incorrectly otherwise! From SMC Application
Note 7-15. Thanks to Christoph Badura for the pointer!
 1.4 20-Jul-1998  thorpej The mystery bit in the TEST register is actually the CLOCK TEST bit.
 1.3 05-Jul-1998  jonathan defopt NS, NSIP.
 1.2 05-Jul-1998  jonathan defopt INET, NETATALK.
 1.1 02-Jun-1998  thorpej Device driver for the SMC 83c170 Ethernet PCI Integrated Controller (EPIC/100)
used in the SMC EtherPower II.

Media control isn't yet supported, due to some MII infrastructure
problems which I hope to address soon. This isn't a huge deal, since
the PHY defaults to auto-negotiate mode.

Also, the device just programs the multicast hash table to accept all
multicast, to avoid a hardware bug that causes the multicast address
filter to lose in 10Mb/s mode. This bug will be fixed in a more sane
way once the media control issues are dealt with.
 1.9.4.1 11-Dec-1998  kenh The beginnings of interface detach support. Still some bugs, but mostly
works for me.

This work was originally by Bill Studenmund, and cleaned up by me.
 1.15.6.1 30-Nov-1999  itojun bring in latest KAME (as of 19991130, KAME/NetBSD141) into kame branch
just for reference purposes.
This commit includes 1.4 -> 1.4.1 sync for kame branch.

The branch does not compile at all (due to the lack of ALTQ and some other
source code). Please do not try to modify the branch, this is just for
referenre purposes.

synchronization to latest KAME will take place on HEAD branch soon.
 1.15.4.2 02-Aug-1999  thorpej Update from trunk.
 1.15.4.1 21-Jun-1999  thorpej Sync w/ -current.
 1.15.2.3 22-May-2000  he Pull up revision 1.31 (via patch, requested by thorpej):
Use the lower bits of the crc32 for the multicast address filter,
not the upper bits. Fixes PR#8268.
 1.15.2.2 08-Feb-2000  he Pull up revision 1.26 (via patch, requested by thorpej):
Don't rely on the receive descriptor's BCAST/MCAST status bits.
Instead, test the Ethernet destination address to see if it's
multicast.
 1.15.2.1 18-Jun-1999  perry apply patch from thorpej, fixes transmit timeout bug
 1.21.8.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.21.4.1 15-Nov-1999  fvdl Sync with -current
 1.21.2.4 27-Mar-2001  bouyer Sync with HEAD.
 1.21.2.3 05-Jan-2001  bouyer Sync with HEAD
 1.21.2.2 22-Nov-2000  bouyer Sync with HEAD.
 1.21.2.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.32.4.2 31-Dec-2000  jhawk Pull up revision 1.36 (requested by bouyer):
Add support for 802.1Q virtual LANs.
 1.32.4.1 09-Nov-2000  tv Pullup 1.37 [thorpej]:
One more fix to multicast hash computation. Submitter confirms that
with this fix, multicast does indeed work properly on the EPIC.

From Zdenek Salvet <salvet@ics.muni.cz>.
 1.41.2.6 15-Jan-2003  thorpej Sync with HEAD.
 1.41.2.5 11-Nov-2002  nathanw Catch up to -current
 1.41.2.4 14-Nov-2001  nathanw Catch up to -current.
 1.41.2.3 24-Aug-2001  nathanw Catch up with -current.
 1.41.2.2 21-Jun-2001  nathanw Catch up to -current.
 1.41.2.1 09-Apr-2001  nathanw Catch up with -current.
 1.46.2.2 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.46.2.1 03-Aug-2001  lukem update to -current
 1.49.10.1 26-Jan-2003  he Pull up revision 1.52 (requested by bouyer in ticket #1083):
For short (< ETHER_MIN_LEN) packets, supply a zeroed buffer
for the extra bytes to make sure the chip doesn't send
random data.
 1.53.2.6 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.53.2.5 04-Feb-2005  skrll Sync with HEAD.
 1.53.2.4 02-Nov-2004  skrll Sync with HEAD.
 1.53.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.53.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.53.2.1 03-Aug-2004  skrll Sync with HEAD
 1.55.4.1 24-Jan-2005  he Pull up revision 1.56 (requested by thorpej in ticket #939):
When adding or deleting multicast addresses, only change
the address filter if the interface is marked RUNNING.
Fixes PR#27678.
 1.56.6.2 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.56.6.1 12-Feb-2005  yamt sync with head.
 1.56.4.1 29-Apr-2005  kent sync with -current
 1.59.4.5 17-Mar-2008  yamt sync with head.
 1.59.4.4 21-Jan-2008  yamt sync with head
 1.59.4.3 27-Oct-2007  yamt sync with head.
 1.59.4.2 03-Sep-2007  yamt sync with head.
 1.59.4.1 21-Jun-2006  yamt sync with head.
 1.60.12.1 24-May-2006  tron Merge 2006-05-24 NetBSD-current into the "peter-altq" branch.
 1.60.10.1 19-Apr-2006  elad sync with head.
 1.60.8.1 24-May-2006  yamt sync with head.
 1.60.6.1 22-Apr-2006  simonb Sync with head.
 1.60.4.1 09-Sep-2006  rpaulo sync with head
 1.63.14.1 12-Mar-2007  rmind Sync with HEAD.
 1.64.4.1 11-Jul-2007  mjf Sync with head.
 1.64.2.3 23-Oct-2007  ad Sync with head.
 1.64.2.2 09-Oct-2007  ad Sync with head.
 1.64.2.1 01-Jul-2007  ad Adapt to callout API change.
 1.65.6.2 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.65.6.1 03-Sep-2007  jmcneill Sync with HEAD.
 1.65.2.1 03-Sep-2007  skrll Sync with HEAD.
 1.66.6.1 25-Oct-2007  bouyer Sync with HEAD.
 1.66.2.3 23-Mar-2008  matt sync with HEAD
 1.66.2.2 09-Jan-2008  matt sync with HEAD
 1.66.2.1 06-Nov-2007  matt sync with HEAD
 1.67.8.2 20-Jan-2008  bouyer Sync with HEAD
 1.67.8.1 02-Jan-2008  bouyer Sync with HEAD
 1.67.2.1 18-Feb-2008  mjf Sync with HEAD.
 1.71.6.3 28-Sep-2008  mjf Sync with HEAD.
 1.71.6.2 02-Jun-2008  mjf Sync with HEAD.
 1.71.6.1 03-Apr-2008  mjf Sync with HEAD.
 1.71.2.1 24-Mar-2008  keiichi sync with head.
 1.73.4.5 11-Aug-2010  yamt sync with head.
 1.73.4.4 11-Mar-2010  yamt sync with head
 1.73.4.3 16-Sep-2009  yamt sync with head
 1.73.4.2 04-May-2009  yamt sync with head.
 1.73.4.1 16-May-2008  yamt sync with head.
 1.73.2.1 18-May-2008  yamt sync with head.
 1.75.4.1 18-Jul-2008  simonb Sync with head.
 1.75.2.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.78.4.2 05-Mar-2011  rmind sync with head
 1.78.4.1 30-May-2010  rmind sync with head
 1.78.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.80.8.1 30-Oct-2012  yamt sync with head
 1.81.16.4 28-Aug-2017  skrll Sync with HEAD
 1.81.16.3 05-Feb-2017  skrll Sync with HEAD
 1.81.16.2 09-Jul-2016  skrll Sync with HEAD
 1.81.16.1 19-Mar-2016  skrll Sync with HEAD
 1.81.2.1 03-Dec-2017  jdolecek update from HEAD
 1.83.2.2 20-Mar-2017  pgoyette Sync with HEAD
 1.83.2.1 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.84.2.1 21-Apr-2017  bouyer Sync with HEAD
 1.85.12.2 26-Jan-2019  pgoyette Sync with HEAD
 1.85.12.1 28-Jul-2018  pgoyette Sync with HEAD
 1.86.2.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.86.2.1 10-Jun-2019  christos Sync with HEAD
 1.90.4.2 29-Feb-2020  ad Sync with head.
 1.90.4.1 25-Jan-2020  ad Sync with head.
 1.98.2.1 02-Aug-2025  perseant Sync with HEAD
 1.14 09-Feb-2024  andvar fix spelling mistakes, mainly in comments and log messages.
 1.13 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.12 16-Feb-2007  tsutsui branches: 1.12.40; 1.12.42; 1.12.44;
Make DMA descriptors volatile to avoid unintended reordering which might
cause some race condition.
 1.11 16-Apr-2006  tsutsui branches: 1.11.12;
u_intNN_t -> uintNN_t
 1.10 11-Dec-2005  christos branches: 1.10.4; 1.10.6; 1.10.8; 1.10.10; 1.10.12;
merge ktrace-lwp.
 1.9 08-Nov-2003  tsutsui branches: 1.9.16;
Define all members in TX/RX DMA descriptors as u_int32_t and use proper shift
and mask ops since smc83c170 chips access them in 32bit width with proper
byteswap mechanism, so that all #if BYTE_ORDER in descriptors can be removed.
While here, do some slight optimizations in epic_start() and epic_intr().
 1.8 02-Nov-2003  wiz Fix some typos. From Tom Cosgrove via jmc@openbsd.
 1.7 16-Sep-2001  wiz branches: 1.7.18;
Spell 'occurred' with two 'r's.
 1.6 26-May-2000  tsutsui branches: 1.6.6; 1.6.8; 1.6.10;
Swap the order of u_int16_t member in Tx/Rx descriptors
on big endian machines.

"Big endian mode" of smc83c170 actually works!
(i.e. no htole??()/le??toh() functions are needed.)
 1.5 27-Aug-1999  thorpej branches: 1.5.2;
Reduce the number of transmit fragments to 16.
 1.4 27-Jul-1999  thorpej Make this "should work" on big endian systems.
 1.3 11-Aug-1998  thorpej branches: 1.3.8;
Adapt to new MII code.
 1.2 20-Jul-1998  thorpej The mystery bit in the TEST register is actually the CLOCK TEST bit.
 1.1 02-Jun-1998  thorpej Device driver for the SMC 83c170 Ethernet PCI Integrated Controller (EPIC/100)
used in the SMC EtherPower II.

Media control isn't yet supported, due to some MII infrastructure
problems which I hope to address soon. This isn't a huge deal, since
the PHY defaults to auto-negotiate mode.

Also, the device just programs the multicast hash table to accept all
multicast, to avoid a hardware bug that causes the multicast address
filter to lose in 10Mb/s mode. This bug will be fixed in a more sane
way once the media control issues are dealt with.
 1.3.8.1 02-Aug-1999  thorpej Update from trunk.
 1.5.2.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.6.10.1 01-Oct-2001  fvdl Catch up with -current.
 1.6.8.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.6.6.1 21-Sep-2001  nathanw Catch up to -current.
 1.7.18.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.7.18.2 18-Sep-2004  skrll Sync with HEAD.
 1.7.18.1 03-Aug-2004  skrll Sync with HEAD
 1.9.16.2 26-Feb-2007  yamt sync with head.
 1.9.16.1 21-Jun-2006  yamt sync with head.
 1.10.12.1 24-May-2006  tron Merge 2006-05-24 NetBSD-current into the "peter-altq" branch.
 1.10.10.1 19-Apr-2006  elad sync with head.
 1.10.8.1 24-May-2006  yamt sync with head.
 1.10.6.1 22-Apr-2006  simonb Sync with head.
 1.10.4.1 09-Sep-2006  rpaulo sync with head
 1.11.12.1 24-Feb-2007  bouyer Pull up following revision(s) (requested by tsutsui in ticket #463):
sys/dev/ic/smc83c170reg.h: revision 1.12
sys/dev/ic/smc83c170var.h: revision 1.11
Make DMA descriptors volatile to avoid unintended reordering which might
cause some race condition.
Set ER_RXSTAT_OWNER after all descriptor members are ready.
 1.12.44.1 16-May-2008  yamt sync with head.
 1.12.42.1 18-May-2008  yamt sync with head.
 1.12.40.1 02-Jun-2008  mjf Sync with HEAD.
 1.15 10-Nov-2021  msaitoh s/desciptor/descriptor/ in comment.
 1.14 03-Sep-2009  tsutsui Replace shutdownhook_establish(9) with pmf_device_register1().
Tested EtherPower II 10/100 (SMC9432TX) on macppc.
 1.13 06-Jul-2008  tsutsui Split device_t/softc with misc cosmetic changes.
 1.12 28-Apr-2008  martin branches: 1.12.2; 1.12.4;
Remove clause 3 and 4 from TNF licenses
 1.11 16-Feb-2007  tsutsui branches: 1.11.40; 1.11.42; 1.11.44;
Set ER_RXSTAT_OWNER after all descriptor members are ready.
 1.10 11-Dec-2005  christos branches: 1.10.24;
merge ktrace-lwp.
 1.9 04-Feb-2005  perry branches: 1.9.6;
de-__P
 1.8 08-Nov-2003  tsutsui branches: 1.8.8; 1.8.10;
Define all members in TX/RX DMA descriptors as u_int32_t and use proper shift
and mask ops since smc83c170 chips access them in 32bit width with proper
byteswap mechanism, so that all #if BYTE_ORDER in descriptors can be removed.
While here, do some slight optimizations in epic_start() and epic_intr().
 1.7 13-Jan-2003  bouyer branches: 1.7.2;
For short (< ETHER_MIN_LEN) packets, supply a zero'd buffer for the extra
bytes to make sure the chip won't send random data.
 1.6 07-Nov-2002  thorpej Fix signed/unsigned comparison warnings.
 1.5 17-May-2001  drochner branches: 1.5.16;
support BNC interfaces (serial mode) as on the SMC9432BTX and 100FX
on the SMC9432FTX
 1.4 23-Mar-2000  thorpej branches: 1.4.6;
New callout mechanism with two major improvements over the old
timeout()/untimeout() API:
- Clients supply callout handle storage, thus eliminating problems of
resource allocation.
- Insertion and removal of callouts is constant time, important as
this facility is used quite a lot in the kernel.

The old timeout()/untimeout() API has been removed from the kernel.
 1.3 12-Feb-1999  thorpej branches: 1.3.8;
Cleanup of the EPIC/100 driver I did while hacking on the Rhine driver:
* Macroize hardware and software descriptor access (much easier to read).
* Simplify and optimize the transmit loop a bit, and use IFF_OACTIVE as
appropriate.
* Fix a potential race condition in the transmit loop. This change has
made the driver significantly more stable (almost completely eliminated
the "device timeout" errors that have plagued this driver).
* Implement transmit interrupt pacing.
* Add missing bus_dmamap_sync() calls (on transmit and receive descriptors
and fraglists). (Draining the write buffer when accessing these structures
may have also contributed to the increased stability of this driver on
the Alpha.)
 1.2 11-Aug-1998  thorpej Adapt to new MII code.
 1.1 02-Jun-1998  thorpej Device driver for the SMC 83c170 Ethernet PCI Integrated Controller (EPIC/100)
used in the SMC EtherPower II.

Media control isn't yet supported, due to some MII infrastructure
problems which I hope to address soon. This isn't a huge deal, since
the PHY defaults to auto-negotiate mode.

Also, the device just programs the multicast hash table to accept all
multicast, to avoid a hardware bug that causes the multicast address
filter to lose in 10Mb/s mode. This bug will be fixed in a more sane
way once the media control issues are dealt with.
 1.3.8.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.4.6.3 15-Jan-2003  thorpej Sync with HEAD.
 1.4.6.2 11-Nov-2002  nathanw Catch up to -current
 1.4.6.1 21-Jun-2001  nathanw Catch up to -current.
 1.5.16.1 26-Jan-2003  he Pull up revision 1.7 (requested by bouyer in ticket #1083):
For short (< ETHER_MIN_LEN) packets, supply a zeroed buffer
for the extra bytes to make sure the chip doesn't send
random data.
 1.7.2.4 04-Feb-2005  skrll Sync with HEAD.
 1.7.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.7.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.7.2.1 03-Aug-2004  skrll Sync with HEAD
 1.8.10.1 12-Feb-2005  yamt sync with head.
 1.8.8.1 29-Apr-2005  kent sync with -current
 1.9.6.1 26-Feb-2007  yamt sync with head.
 1.10.24.1 24-Feb-2007  bouyer Pull up following revision(s) (requested by tsutsui in ticket #463):
sys/dev/ic/smc83c170reg.h: revision 1.12
sys/dev/ic/smc83c170var.h: revision 1.11
Make DMA descriptors volatile to avoid unintended reordering which might
cause some race condition.
Set ER_RXSTAT_OWNER after all descriptor members are ready.
 1.11.44.3 16-Sep-2009  yamt sync with head
 1.11.44.2 04-May-2009  yamt sync with head.
 1.11.44.1 16-May-2008  yamt sync with head.
 1.11.42.1 18-May-2008  yamt sync with head.
 1.11.40.2 28-Sep-2008  mjf Sync with HEAD.
 1.11.40.1 02-Jun-2008  mjf Sync with HEAD.
 1.12.4.1 18-Jul-2008  simonb Sync with head.
 1.12.2.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.77 08-Sep-2024  rillig fix a/an grammar in obvious cases
 1.76 05-Jul-2024  rin sys: Drop redundant NULL check before m_freem(9)

m_freem(9) safely has accepted NULL argument at least since 4.2BSD:
https://www.tuhs.org/cgi-bin/utree.pl?file=4.2BSD/usr/src/sys/sys/uipc_mbuf.c

Compile-tested on amd64/ALL.

Suggested by knakahara@
 1.75 30-Jan-2020  thorpej branches: 1.75.30;
Adopt <net/if_stats.h>.
 1.74 05-Feb-2019  msaitoh branches: 1.74.6;
Remove very old IFF_NOTRAILERS flag.
 1.73 26-Jun-2018  msaitoh branches: 1.73.2;
Implement the BPF direction filter (BIOC[GS]DIRECTION). It provides backward
compatibility with BIOC[GS]SEESENT ioctl. The userland interface is the same
as FreeBSD.

This change also fixes a bug that the direction is misunderstand on some
environment by passing the direction to bpf_mtap*() instead of checking
m->m_pkthdr.rcvif.
 1.72 22-Jun-2018  msaitoh It's not required to include net/bpfdesc.h. Remove it.
 1.71 23-Oct-2017  msaitoh branches: 1.71.2;
If if_attach() failed in the attach function, return.
 1.70 23-May-2017  ozaki-r branches: 1.70.2;
Remove an out-of-date comment

Pointed out by knakahara@
 1.69 23-May-2017  ozaki-r Apply deferred if_start to more drivers

And annotate some XXX_start as it runs in softint to clarify that
it doesn't need deferred if_start.
 1.68 15-Dec-2016  ozaki-r Move bpf_mtap and if_ipackets++ on Rx of each driver to percpuq if_input

The benefits of the change are:
- We can reduce codes
- We can provide the same behavior between drivers
- Where/When if_ipackets is counted up
- Note that some drivers still update packet statistics in their own
way (periodical update)
- Moved bpf_mtap run in softint
- This makes it easy to MP-ify bpf

Proposed on tech-kern and tech-net
 1.67 10-Jun-2016  ozaki-r branches: 1.67.2;
Introduce m_set_rcvif and m_reset_rcvif

The API is used to set (or reset) a received interface of a mbuf.
They are counterpart of m_get_rcvif, which will come in another
commit, hide internal of rcvif operation, and reduce the diff of
the upcoming change.

No functional change.
 1.66 09-Feb-2016  ozaki-r Introduce softint-based if_input

This change intends to run the whole network stack in softint context
(or normal LWP), not hardware interrupt context. Note that the work is
still incomplete by this change; to that end, we also have to softint-ify
if_link_state_change (and bpf) which can still run in hardware interrupt.

This change softint-ifies at ifp->if_input that is called from
each device driver (and ieee80211_input) to ensure Layer 2 runs
in softint (e.g., ether_input and bridge_input). To this end,
we provide a framework (called percpuq) that utlizes softint(9)
and percpu ifqueues. With this patch, rxintr of most drivers just
queues received packets and schedules a softint, and the softint
dequeues packets and does rest packet processing.

To minimize changes to each driver, percpuq is allocated in struct
ifnet for now and that is initialized by default (in if_attach).
We probably have to move percpuq to softc of each driver, but it's
future work. At this point, only wm(4) has percpuq in its softc
as a reference implementation.

Additional information including performance numbers can be found
in the thread at tech-kern@ and tech-net@:
http://mail-index.netbsd.org/tech-kern/2016/01/14/msg019997.html

Acknowledgment: riastradh@ greatly helped this work.
Thank you very much!
 1.65 30-Oct-2015  phx Fixed format string types to make it compile with BAH_DEBUG again.
 1.64 27-Oct-2012  chs branches: 1.64.14;
split device_t/softc for all remaining drivers.
replace "struct device *" with "device_t".
use device_xname(), device_unit(), etc.
 1.63 05-Apr-2010  joerg branches: 1.63.8; 1.63.18;
Push the bpf_ops usage back into bpf.h. Push the common ifp->if_bpf
check into the inline functions as well the fourth argument for
bpf_attach.
 1.62 19-Jan-2010  pooka branches: 1.62.2; 1.62.4;
Redefine bpf linkage through an always present op vector, i.e.
#if NBPFILTER is no longer required in the client. This change
doesn't yet add support for loading bpf as a module, since drivers
can register before bpf is attached. However, callers of bpf can
now be modularized.

Dynamically loadable bpf could probably be done fairly easily with
coordination from the stub driver and the real driver by registering
attachments in the stub before the real driver is loaded and doing
a handoff. ... and I'm not going to ponder the depths of unload
here.

Tested with i386/MONOLITHIC, modified MONOLITHIC without bpf and rump.
 1.61 10-Jan-2010  snj Add a missing closing parenthesis in a few places. From Henning Petersen
in PR kern/42527.
 1.60 31-May-2009  he Don't include <machine/mtpr.h> anymore since it has been removed
(at least from the amiga port) and appears to no longer be required.
 1.59 14-Mar-2009  dsl Change about 4500 of the K&R function definitions to ANSI ones.
There are still about 1600 left, but they have ',' or /* ... */
in the actual variable definitions - which my awk script doesn't handle.
There are also many that need () -> (void).
(The script does handle misordered arguments.)
 1.58 12-Nov-2008  phx branches: 1.58.4;
Added missing #include <net/if_ether.h> for ether_ioctl().
 1.57 07-Nov-2008  dyoung *** Summary ***

When a link-layer address changes (e.g., ifconfig ex0 link
02:de:ad:be:ef:02 active), send a gratuitous ARP and/or a Neighbor
Advertisement to update the network-/link-layer address bindings
on our LAN peers.

Refuse a change of ethernet address to the address 00:00:00:00:00:00
or to any multicast/broadcast address. (Thanks matt@.)

Reorder ifnet ioctl operations so that driver ioctls may inherit
the functions of their "class"---ether_ioctl(), fddi_ioctl(), et
cetera---and the class ioctls may inherit from the generic ioctl,
ifioctl_common(), but both driver- and class-ioctls may override
the generic behavior. Make network drivers share more code.

Distinguish a "factory" link-layer address from others for the
purposes of both protecting that address from deletion and computing
EUI64.

Return consistent, appropriate error codes from network drivers.

Improve readability. KNF.

*** Details ***

In if_attach(), always initialize the interface ioctl routine,
ifnet->if_ioctl, if the driver has not already initialized it.
Delete if_ioctl == NULL tests everywhere else, because it cannot
happen.

In the ioctl routines of network interfaces, inherit common ioctl
behaviors by calling either ifioctl_common() or whichever ioctl
routine is appropriate for the class of interface---e.g., ether_ioctl()
for ethernets.

Stop (ab)using SIOCSIFADDR and start to use SIOCINITIFADDR. In
the user->kernel interface, SIOCSIFADDR's argument was an ifreq,
but on the protocol->ifnet interface, SIOCSIFADDR's argument was
an ifaddr. That was confusing, and it would work against me as I
make it possible for a network interface to overload most ioctls.
On the protocol->ifnet interface, replace SIOCSIFADDR with
SIOCINITIFADDR. In ifioctl(), return EPERM if userland tries to
invoke SIOCINITIFADDR.

In ifioctl(), give the interface the first shot at handling most
interface ioctls, and give the protocol the second shot, instead
of the other way around. Finally, let compatibility code (COMPAT_OSOCK)
take a shot.

Pull device initialization out of switch statements under
SIOCINITIFADDR. For example, pull ..._init() out of any switch
statement that looks like this:

switch (...->sa_family) {
case ...:
..._init();
...
break;
...
default:
..._init();
...
break;
}

Rewrite many if-else clauses that handle all permutations of IFF_UP
and IFF_RUNNING to use a switch statement,

switch (x & (IFF_UP|IFF_RUNNING)) {
case 0:
...
break;
case IFF_RUNNING:
...
break;
case IFF_UP:
...
break;
case IFF_UP|IFF_RUNNING:
...
break;
}

unifdef lots of code containing #ifdef FreeBSD, #ifdef NetBSD, and
#ifdef SIOCSIFMTU, especially in fwip(4) and in ndis(4).

In ipw(4), remove an if_set_sadl() call that is out of place.

In nfe(4), reuse the jumbo MTU logic in ether_ioctl().

Let ethernets register a callback for setting h/w state such as
promiscuous mode and the multicast filter in accord with a change
in the if_flags: ether_set_ifflags_cb() registers a callback that
returns ENETRESET if the caller should reset the ethernet by calling
if_init(), 0 on success, != 0 on failure. Pull common code from
ex(4), gem(4), nfe(4), sip(4), tlp(4), vge(4) into ether_ioctl(),
and register if_flags callbacks for those drivers.

Return ENOTTY instead of EINVAL for inappropriate ioctls. In
zyd(4), use ENXIO instead of ENOTTY to indicate that the device is
not any longer attached.

Add to if_set_sadl() a boolean 'factory' argument that indicates
whether a link-layer address was assigned by the factory or some
other source. In a comment, recommend using the factory address
for generating an EUI64, and update in6_get_hw_ifid() to prefer a
factory address to any other link-layer address.

Add a routing message, RTM_LLINFO_UPD, that tells protocols to
update the binding of network-layer addresses to link-layer addresses.
Implement this message in IPv4 and IPv6 by sending a gratuitous
ARP or a neighbor advertisement, respectively. Generate RTM_LLINFO_UPD
messages on a change of an interface's link-layer address.

In ether_ioctl(), do not let SIOCALIFADDR set a link-layer address
that is broadcast/multicast or equal to 00:00:00:00:00:00.

Make ether_ioctl() call ifioctl_common() to handle ioctls that it
does not understand.

In gif(4), initialize if_softc and use it, instead of assuming that
the gif_softc and ifp overlap.

Let ifioctl_common() handle SIOCGIFADDR.

Sprinkle rtcache_invariants(), which checks on DIAGNOSTIC kernels
that certain invariants on a struct route are satisfied.

In agr(4), rewrite agr_ioctl_filter() to be a bit more explicit
about the ioctls that we do not allow on an agr(4) member interface.

bzero -> memset. Delete unnecessary casts to void *. Use
sockaddr_in_init() and sockaddr_in6_init(). Compare pointers with
NULL instead of "testing truth". Replace some instances of (type
*)0 with NULL. Change some K&R prototypes to ANSI C, and join
lines.
 1.56 28-Apr-2008  martin branches: 1.56.6; 1.56.8;
Remove clause 3 and 4 from TNF licenses
 1.55 08-Apr-2008  cegger branches: 1.55.2; 1.55.4;
use aprint_*_dev and device_xname
 1.54 28-Dec-2007  joerg branches: 1.54.6;
Be friendly to timecounter enabled architectures.
 1.53 25-Dec-2007  he Convert to using if_set_sadl() instead of arc_storelladdr(), catching
an overlooked setting of ifnet->if_sadl. This follows up the recent
change to net/if.h.
 1.52 19-Oct-2007  ad branches: 1.52.2; 1.52.4; 1.52.8;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.51 08-Oct-2007  ad branches: 1.51.2;
Use the softint API.
 1.50 03-Sep-2007  he branches: 1.50.2;
Rename function argument from command to cmd, to make the code
actually build after the previous change.
 1.49 01-Sep-2007  dyoung Use ifreq_setaddr(), ifreq_getaddr(), sockaddr_in_init(), and
sockaddr_copy(). Constify. Compare pointers with NULL, not 0.
Don't "test truth" of pointers, but compare with NULL.
 1.48 11-Jul-2007  he branches: 1.48.2; 1.48.6; 1.48.8;
Adapt to the new signature for callout_init().
 1.47 04-Mar-2007  christos branches: 1.47.2;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.46 25-Dec-2006  wiz branches: 1.46.2;
Spell "threshold" correctly. From Zafer Aydogan.
 1.45 24-Dec-2005  perry branches: 1.45.20;
Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.44 11-Dec-2005  christos merge ktrace-lwp.
 1.43 27-Feb-2005  perry branches: 1.43.4;
nuke trailing whitespace
 1.42 04-Feb-2005  perry de-__P
 1.41 02-Nov-2003  wiz branches: 1.41.8; 1.41.10;
Fix some typos. From Tom Cosgrove via jmc@openbsd.
 1.40 06-Jan-2003  wiz branches: 1.40.2;
interrupt with two rs.
 1.39 13-Nov-2001  lukem add/cleanup RCSID
 1.38 07-Jul-2001  thorpej branches: 1.38.2;
bcopy -> strcpy
 1.37 14-Dec-2000  thorpej branches: 1.37.2;
ALTQ'ify.
 1.36 12-Dec-2000  thorpej Adapt to bpfattach() changes, and further centralize the bpfattach()
and bpfdetach() calls into link-type subroutines where possible.
 1.35 30-Mar-2000  augustss Remove register declarations.
 1.34 23-Mar-2000  thorpej New callout mechanism with two major improvements over the old
timeout()/untimeout() API:
- Clients supply callout handle storage, thus eliminating problems of
resource allocation.
- Insertion and removal of callouts is constant time, important as
this facility is used quite a lot in the kernel.

The old timeout()/untimeout() API has been removed from the kernel.
 1.33 25-Sep-1999  is branches: 1.33.2;
Avoid calling m_pullup in a few places, where not necessary.
 1.32 27-Aug-1999  is Factor out arc_storelladdr(), and use that instead of arc_ifattach() in
the bah_reset() function.
This makes the last change work without deconnecting all the other interfaces
from the interface list.
 1.31 26-Aug-1999  is Only use ifp->if_addrlen after initializing it.\
Problem detected by Andreas Johansson.
 1.30 18-May-1999  thorpej Rework layer 2 protocol input routines. Instead of calling e.g. ether_input()
directly, call the function pointer (*if_input)(ifp, m). The input routine
expects the packet header to be at the head of the packet, and will adjust
as necessary. Privatize the layer 2 input and output routines, allowing
*_ifattach() to set them up as appropriate.
 1.29 16-Feb-1999  is branches: 1.29.4;
Fix Copyright dates
 1.28 16-Feb-1999  is Assign my files to The NetBSD Foundation, Inc.
 1.27 20-Oct-1998  is branches: 1.27.4;
fully implement soft callback usage
 1.26 19-Oct-1998  is Stopgap fix for stupid pasto. Fix for the BAHSOFTCOPY case will be provided
after more sleep.
 1.25 02-Sep-1998  is Split SMC chipset ARCnet driver into
- machine independent chip driver, in dev/ic/smc90cx6.c/...reg.h,...var.h,
using bus_space methods
- ZBUS frontend in arch/amiga/dev/if_bah_zbus.c
- added IPL_SOFTNET to arch/amiga/include/intr.h, for this
Implementing the ISA bus frontend is left as an exercise to the reader.
 1.24 05-Jul-1998  jonathan defopt INET, NETATALK.
 1.23 12-Jan-1998  thorpej Adjust for config changes.
 1.22 28-Apr-1997  mycroft branches: 1.22.8;
Oops; forgot to GC the last mbuf allocated when out of clusters.
 1.21 24-Apr-1997  mycroft Fix typo in previous.
 1.20 24-Apr-1997  mycroft If we fail to allocate a cluster to hold a large packet, simply
drop it rather than using a chain of tiny mbufs.
 1.19 13-Oct-1996  christos backout kprintf changes
 1.18 10-Oct-1996  christos - printf -> kprintf, sprintf -> ksprintf
 1.17 07-May-1996  thorpej branches: 1.17.4;
Changed struct ifnet to have a pointer to the softc of the underlying
device and a printable "external name" (name + unit number), thus eliminating
if_name and if_unit. Updated interface to (*if_watchdog)() and (*if_start)()
to take a struct ifnet *, rather than a unit number.
 1.16 20-Mar-1996  is - Zeroth version of M68060 support (dont want to cause emulation traps for
the "Fast Assembler Version of the copy loop)
- Yet another sanity check included: initialize unused receive buffers to
zero sender id; and test for sender hardware id of zero in the receiver.
Gives us better error messages in case flaky hardware causes spurious
receive interupts.
 1.15 17-Mar-1996  thorpej New device attachment scheme:

- split softc size and match/attach out from cfdriver into
a new struct cfattach.

- new "attach" directive for files.*. May specify the name of
the cfattach structure, so that devices may be easily attached
to parents with different autoconfiguration semantics.
 1.14 27-Dec-1995  chopps make changed from pr#1824 from Ignatios Souvatzis
 1.13 24-Dec-1995  mycroft The IST_* and IPL_* constants are not bus-specific; don't treat them as such.
Change splimp -> splnet in Ethernet, ARCnet, and FDDI drivers.
 1.12 09-Oct-1995  chopps add prototypes for isr stuff fixes pr# 1284 and 1569
 1.11 09-Oct-1995  chopps fix hang bug from Ignatios Souvatzis <ignatios@theory.cs.uni-bonn.de>
 1.10 02-Jul-1995  mycroft Remove references to if_addrlist.
 1.9 27-Jun-1995  chopps udpate to match ifnets new use of sys/queue.h
 1.8 07-Jun-1995  cgd update from Ignatios Souvatzis
 1.7 15-Apr-1995  cgd cleanup; mostly KNF.
 1.6 14-Apr-1995  chopps couple small changes plus a new watchdog timer from Ignatios Souvatzis <is@beverly.rhein.de>
 1.5 11-Apr-1995  chopps fix up some changes
 1.4 11-Apr-1995  mycroft Sync with the rest of the world. Various additional cleanup.
 1.3 02-Mar-1995  chopps some cleanup..
 1.2 01-Mar-1995  chopps Fixup (c)'s and ids.
 1.1 28-Feb-1995  chopps new arcnet (2060) device from is@Beverly.Rhein.DE (Ignatios Souvatzis)
 1.17.4.2 31-Aug-1996  thorpej Remove these from the NetBSD 1.2 release branch; they were tagged in error.
 1.17.4.1 14-Jun-1996  is Not needed yet for the netbsd-1-2 release.
 1.22.8.1 09-Nov-1997  mellon Not needed on branch (is)
 1.27.4.1 11-Dec-1998  kenh The beginnings of interface detach support. Still some bugs, but mostly
works for me.

This work was originally by Bill Studenmund, and cleaned up by me.
 1.29.4.1 21-Jun-1999  thorpej Sync w/ -current.
 1.33.2.3 05-Jan-2001  bouyer Sync with HEAD
 1.33.2.2 13-Dec-2000  bouyer Sync with HEAD (for UBC fixes).
 1.33.2.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.37.2.3 07-Jan-2003  thorpej Sync with HEAD.
 1.37.2.2 14-Nov-2001  nathanw Catch up to -current.
 1.37.2.1 24-Aug-2001  nathanw Catch up with -current.
 1.38.2.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.40.2.5 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.40.2.4 04-Feb-2005  skrll Sync with HEAD.
 1.40.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.40.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.40.2.1 03-Aug-2004  skrll Sync with HEAD
 1.41.10.2 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.41.10.1 12-Feb-2005  yamt sync with head.
 1.41.8.1 29-Apr-2005  kent sync with -current
 1.43.4.5 21-Jan-2008  yamt sync with head
 1.43.4.4 27-Oct-2007  yamt sync with head.
 1.43.4.3 03-Sep-2007  yamt sync with head.
 1.43.4.2 30-Dec-2006  yamt sync with head.
 1.43.4.1 21-Jun-2006  yamt sync with head.
 1.45.20.1 12-Jan-2007  ad Sync with head.
 1.46.2.1 12-Mar-2007  rmind Sync with HEAD.
 1.47.2.4 23-Oct-2007  ad Sync with head.
 1.47.2.3 09-Oct-2007  ad Sync with head.
 1.47.2.2 15-Jul-2007  ad Sync with head.
 1.47.2.1 17-Jun-2007  ad - Increase the number of thread priorities from 128 to 256. How the space
is set up is to be revisited.
- Implement soft interrupts as kernel threads. A generic implementation
is provided, with hooks for fast-path MD code that can run the interrupt
threads over the top of other threads executing in the kernel.
- Split vnode::v_flag into three fields, depending on how the flag is
locked (by the interlock, by the vnode lock, by the file system).
- Miscellaneous locking fixes and improvements.
 1.48.8.2 09-Jan-2008  matt sync with HEAD
 1.48.8.1 06-Nov-2007  matt sync with HEAD
 1.48.6.2 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.48.6.1 03-Sep-2007  jmcneill Sync with HEAD.
 1.48.2.2 10-Sep-2007  skrll Sync with HEAD.
 1.48.2.1 03-Sep-2007  skrll Sync with HEAD.
 1.50.2.1 14-Oct-2007  yamt sync with head.
 1.51.2.1 25-Oct-2007  bouyer Sync with HEAD.
 1.52.8.1 02-Jan-2008  bouyer Sync with HEAD
 1.52.4.1 26-Dec-2007  ad Sync with head.
 1.52.2.1 18-Feb-2008  mjf Sync with HEAD.
 1.54.6.2 17-Jan-2009  mjf Sync with HEAD.
 1.54.6.1 02-Jun-2008  mjf Sync with HEAD.
 1.55.4.5 11-Aug-2010  yamt sync with head.
 1.55.4.4 11-Mar-2010  yamt sync with head
 1.55.4.3 20-Jun-2009  yamt sync with head
 1.55.4.2 04-May-2009  yamt sync with head.
 1.55.4.1 16-May-2008  yamt sync with head.
 1.55.2.1 18-May-2008  yamt sync with head.
 1.56.8.2 28-Apr-2009  skrll Sync with HEAD.
 1.56.8.1 19-Jan-2009  skrll Sync with HEAD.
 1.56.6.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.58.4.2 23-Jul-2009  jym Sync with HEAD.
 1.58.4.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.62.4.1 30-May-2010  rmind sync with head
 1.62.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.63.18.2 03-Dec-2017  jdolecek update from HEAD
 1.63.18.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.63.8.1 30-Oct-2012  yamt sync with head
 1.64.14.5 28-Aug-2017  skrll Sync with HEAD
 1.64.14.4 05-Feb-2017  skrll Sync with HEAD
 1.64.14.3 09-Jul-2016  skrll Sync with HEAD
 1.64.14.2 19-Mar-2016  skrll Sync with HEAD
 1.64.14.1 27-Dec-2015  skrll Sync with HEAD (as of 26th Dec)
 1.67.2.1 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.70.2.2 26-Jul-2018  snj Pull up following revision(s) (requested by msaitoh in ticket #938):
sys/arch/acorn32/podulebus/if_ie.c: revision 1.41
sys/arch/amiga/dev/if_es.c: revision 1.58
sys/arch/amiga/dev/if_qn.c: revision 1.45
sys/arch/arm/at91/at91emac.c: revision 1.20
sys/arch/arm/ep93xx/epe.c: revision 1.37
sys/arch/emips/ebus/if_le_ebus.c: revision 1.14
sys/arch/emips/ebus/if_le_ebus.c: revision 1.15
sys/arch/mac68k/dev/if_mc.c: revision 1.46
sys/arch/macppc/dev/am79c950.c: revision 1.39
sys/arch/newsmips/apbus/if_sn.c: revision 1.40
sys/arch/next68k/dev/mb8795.c: revision 1.59
sys/arch/playstation2/dev/if_smap.c: revision 1.25
sys/arch/playstation2/dev/if_smap.c: revision 1.26
sys/arch/sun2/dev/if_ec.c: revision 1.28
sys/arch/sun3/dev/if_ie.c: revision 1.63
sys/arch/x68k/dev/if_ne_intio.c: revision 1.19
sys/arch/xen/xen/if_xennet_xenbus.c: revision 1.75
sys/arch/xen/xen/xennetback_xenbus.c: revision 1.63
sys/dev/bi/if_ni.c: revision 1.45
sys/dev/cadence/if_cemac.c: revision 1.12
sys/dev/ic/am7990.c: revision 1.78
sys/dev/ic/am79900.c: revision 1.27
sys/dev/ic/an.c: revision 1.67
sys/dev/ic/cs89x0.c: revision 1.40
sys/dev/ic/dm9000.c: revision 1.13
sys/dev/ic/dm9000.c: revision 1.14
sys/dev/ic/dp8390.c: revision 1.88
sys/dev/ic/elink3.c: revision 1.141
sys/dev/ic/elinkxl.c: revision 1.122
sys/dev/ic/hme.c: revision 1.98
sys/dev/ic/i82586.c: revision 1.77
sys/dev/ic/lance.c: revision 1.53
sys/dev/ic/mb86950.c: revision 1.27
sys/dev/ic/mb86960.c: revision 1.86
sys/dev/ic/mtd803.c: revision 1.34
sys/dev/ic/pdq_ifsubr.c: revision 1.59
sys/dev/ic/rrunner.c: revision 1.86
sys/dev/ic/seeq8005.c: revision 1.58
sys/dev/ic/sgec.c: revision 1.47
sys/dev/ic/smc90cx6.c: revision 1.72
sys/dev/ic/smc91cxx.c: revision 1.96
sys/dev/ic/tropic.c: revision 1.49
sys/dev/ic/wi.c: revision 1.245
sys/dev/isa/if_eg.c: revision 1.93
sys/dev/isa/if_el.c: revision 1.95
sys/dev/isa/if_iy.c: revision 1.101
sys/dev/ofw/ofnet.c: revision 1.58
sys/dev/pci/if_alc.c: revision 1.27
sys/dev/pci/if_de.c: revision 1.152
sys/dev/pci/if_fpa.c: revision 1.61
sys/dev/pci/if_jme.c: revision 1.34
sys/dev/pci/if_tl.c: revision 1.108
sys/dev/pci/if_vte.c: revision 1.19
sys/dev/pci/ixgbe/ixgbe.h: revision 1.50
sys/dev/pcmcia/if_cnw.c: revision 1.62
sys/dev/pcmcia/if_malo_pcmcia.c: revision 1.17
sys/dev/pcmcia/if_ray.c: revision 1.89
sys/dev/pcmcia/if_xi.c: revision 1.81
sys/dev/pcmcia/mhzc.c: revision 1.51
sys/dev/pcmcia/xirc.c: revision 1.34
sys/dev/qbus/if_de.c: revision 1.33
sys/dev/qbus/if_qe.c: revision 1.78
sys/dev/qbus/if_qt.c: revision 1.22
sys/dev/sbus/be.c: revision 1.87
sys/dev/sbus/qe.c: revision 1.68
sys/dev/scsipi/if_se.c: revision 1.96
sys/dev/usb/if_atu.c: revision 1.59
sys/net/if_l2tp.c: revision 1.28 via patch
sys/net/if_ppp.c: revision 1.160
It's not required to include net/bpfdesc.h. Remove it.
--
Simplify like other drivers. NULL check of ifp->if_bpf is done in
bpf_mtap(), so it's not required to do it here.
--
Remove duplicated inclusion of net/bpf.h.
--
Remove duplicated inclusion of net/bpf.h.
--
Simplify bpf_mtap() call. No functional change.
 1.70.2.1 10-Dec-2017  snj Pull up following revision(s) (requested by msaitoh in ticket #427):
sys/arch/amiga/dev/if_bah_zbus.c: 1.17
sys/arch/arm/broadcom/bcm53xx_eth.c: 1.30
sys/arch/powerpc/booke/dev/pq3etsec.c: 1.32
sys/arch/usermode/dev/if_veth.c: 1.9
sys/dev/ic/an.c: 1.66
sys/dev/ic/athn.c: 1.17
sys/dev/ic/atw.c: 1.162
sys/dev/ic/bwi.c: 1.33
sys/dev/ic/dwc_gmac.c: 1.41-1.42
sys/dev/ic/malo.c: 1.10
sys/dev/ic/rt2560.c: 1.31
sys/dev/ic/rt2661.c: 1.36
sys/dev/ic/rt2860.c: 1.29
sys/dev/ic/rtw.c: 1.127
sys/dev/ic/rtwvar.h: 1.46
sys/dev/ic/smc90cx6.c: 1.71
sys/dev/ic/smc90cx6var.h: 1.12
sys/dev/ic/wi.c: 1.244
sys/dev/pci/if_ipw.c: 1.66
sys/dev/pci/if_iwi.c: 1.104
sys/dev/pci/if_iwm.c: 1.76
sys/dev/pci/if_iwn.c: 1.86
sys/dev/pci/if_rtwn.c: 1.13
sys/dev/pci/if_wm.c: 1.541
sys/dev/pci/if_wpi.c: 1.79
sys/dev/pci/ixgbe/ixgbe.c: 1.106
sys/dev/pci/ixgbe/ixv.c: 1.73 via patch
sys/dev/pcmcia/if_malo_pcmcia.c: 1.15
sys/dev/scsipi/if_se.c: 1.95
sys/dev/usb/if_upl.c: 1.60
sys/net/if.c: 1.396
sys/net/if.h: 1.241
sys/net/if_arc.h: 1.23
sys/net/if_arcsubr.c: 1.78
sys/net/if_bridge.c: 1.136-1.137
sys/net/if_etherip.c: 1.39
sys/net/if_faith.c: 1.56
sys/net/if_gif.c: 1.131
sys/net/if_loop.c: 1.96
sys/net/if_mpls.c: 1.30
sys/net/if_pppoe.c: 1.129
sys/net/if_srt.c: 1.27
sys/net/if_stf.c: 1.102
sys/net/if_tap.c: 1.100
sys/net/if_vlan.c: 1.105
sys/netinet/ip_carp.c: 1.91
sys/rump/net/lib/libshmif/if_shmem.c: 1.73-1.74
sys/rump/net/lib/libvirtif/if_virt.c: 1.55-1.56
if_initalize() and if_attach() failed when resource allocation failed
(e.g. allocating softint). Without this change, it panics. It's bad because
resource shortage really occured when a lot of pseudo interface is created.
To avoid this problem, don't panic and change return value of if_initialize()
and if_attach() to int. Caller fanction will be recover from error cleanly by
checking the return value.
Return if bah_attach_subr() failed.
If if_attach() failed in the attach function, return.
- If if_initialize() failed in the attach function, free resources and return.
- Add some missing frees in bridge_clone_destroy().
- KNF
If error occured in bcmeth_ccb_attach(), free resources and return.
If error occured in pq3etsec_attach(), free resources and return.
If error occured in the attach function, free resources and return.
- If if_initialize() failed in athn_attach(), free resources and return.
- Add missing pmf_event_deregister() in athn_detach().
- Free resources correctly on some errors in atw_attach().
- Use apint*() insread of printf() in the attach function.
If if_initialize() failed in the attach function, return.
- If if_initialize() failed in the attach function, free resources and return.
- Add missing dwc_gmac_free_dma_rings() and mutex_destroy() when attach
failed.
- If if_initialize() failed in the attach function, free resources and return.
- ifp is always not NULL in iwi_detach(). Check correctly with ifp->if_softc.
- If if_initialize() failed in the attach function, free resources and return.
- Fix error path in the attach function correctly.
If if_initialize() failed in the attach function, free resources and return.
If if_attach() failed in the attach function, free resources and return.
- If if_initialize() failed in the attach function, free resources and return.
- KNF
- If if_attach() failed in the attach function, free resources and return.
- KNF
Fix compile error.
Fix compile error.
We don't need '&mii', but just 'mii' for mii_detach().
Don't free sc_rthash twice
 1.71.2.2 28-Jul-2018  pgoyette Sync with HEAD
 1.71.2.1 25-Jun-2018  pgoyette Sync with HEAD
 1.73.2.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.73.2.1 10-Jun-2019  christos Sync with HEAD
 1.74.6.1 29-Feb-2020  ad Sync with head.
 1.75.30.1 02-Aug-2025  perseant Sync with HEAD
 1.10 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.9 11-Dec-2005  christos branches: 1.9.70; 1.9.72; 1.9.74;
merge ktrace-lwp.
 1.8 27-Feb-2005  perry nuke trailing whitespace
 1.7 16-Feb-1999  is branches: 1.7.42; 1.7.50; 1.7.52;
Fix Copyright dates
 1.6 16-Feb-1999  is Assign my files to The NetBSD Foundation, Inc.
 1.5 02-Sep-1998  is Split SMC chipset ARCnet driver into
- machine independent chip driver, in dev/ic/smc90cx6.c/...reg.h,...var.h,
using bus_space methods
- ZBUS frontend in arch/amiga/dev/if_bah_zbus.c
- added IPL_SOFTNET to arch/amiga/include/intr.h, for this
Implementing the ISA bus frontend is left as an exercise to the reader.
 1.4 07-Jun-1995  cgd branches: 1.4.4; 1.4.16;
update from Ignatios Souvatzis
 1.3 02-Mar-1995  chopps some cleanup..
 1.2 01-Mar-1995  chopps Fixup (c)'s and ids.
 1.1 28-Feb-1995  chopps new arcnet (2060) device from is@Beverly.Rhein.DE (Ignatios Souvatzis)
 1.4.16.1 09-Nov-1997  mellon Not needed on branch (is)
 1.4.4.2 31-Aug-1996  thorpej Remove these from the NetBSD 1.2 release branch; they were tagged in error.
 1.4.4.1 14-Jun-1996  is Not needed yet for the netbsd-1-2 release.
 1.7.52.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.7.50.1 29-Apr-2005  kent sync with -current
 1.7.42.1 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.9.74.1 16-May-2008  yamt sync with head.
 1.9.72.1 18-May-2008  yamt sync with head.
 1.9.70.1 02-Jun-2008  mjf Sync with HEAD.
 1.12 23-Oct-2017  msaitoh If if_attach() failed in the attach function, return.
 1.11 27-Oct-2012  chs branches: 1.11.30;
split device_t/softc for all remaining drivers.
replace "struct device *" with "device_t".
use device_xname(), device_unit(), etc.
 1.10 01-Aug-2011  mbalmer branches: 1.10.2; 1.10.12;
According to the Oxford Dictionary of Etymology, a wether is a male sheep
or ram.
 1.9 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.8 11-Dec-2005  christos branches: 1.8.70; 1.8.72; 1.8.74;
merge ktrace-lwp.
 1.7 27-Feb-2005  perry nuke trailing whitespace
 1.6 04-Feb-2005  perry de-__P
 1.5 23-Mar-2000  thorpej branches: 1.5.28; 1.5.36; 1.5.38;
New callout mechanism with two major improvements over the old
timeout()/untimeout() API:
- Clients supply callout handle storage, thus eliminating problems of
resource allocation.
- Insertion and removal of callouts is constant time, important as
this facility is used quite a lot in the kernel.

The old timeout()/untimeout() API has been removed from the kernel.
 1.4 16-Feb-1999  is branches: 1.4.8;
Fix Copyright dates
 1.3 16-Feb-1999  is Assign my files to The NetBSD Foundation, Inc.
 1.2 20-Oct-1998  is fully implement soft callback usage
 1.1 02-Sep-1998  is Split SMC chipset ARCnet driver into
- machine independent chip driver, in dev/ic/smc90cx6.c/...reg.h,...var.h,
using bus_space methods
- ZBUS frontend in arch/amiga/dev/if_bah_zbus.c
- added IPL_SOFTNET to arch/amiga/include/intr.h, for this
Implementing the ISA bus frontend is left as an exercise to the reader.
 1.4.8.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.5.38.2 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.5.38.1 12-Feb-2005  yamt sync with head.
 1.5.36.1 29-Apr-2005  kent sync with -current
 1.5.28.2 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.5.28.1 04-Feb-2005  skrll Sync with HEAD.
 1.8.74.1 16-May-2008  yamt sync with head.
 1.8.72.1 18-May-2008  yamt sync with head.
 1.8.70.1 02-Jun-2008  mjf Sync with HEAD.
 1.10.12.2 03-Dec-2017  jdolecek update from HEAD
 1.10.12.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.10.2.1 30-Oct-2012  yamt sync with head
 1.11.30.1 10-Dec-2017  snj Pull up following revision(s) (requested by msaitoh in ticket #427):
sys/arch/amiga/dev/if_bah_zbus.c: 1.17
sys/arch/arm/broadcom/bcm53xx_eth.c: 1.30
sys/arch/powerpc/booke/dev/pq3etsec.c: 1.32
sys/arch/usermode/dev/if_veth.c: 1.9
sys/dev/ic/an.c: 1.66
sys/dev/ic/athn.c: 1.17
sys/dev/ic/atw.c: 1.162
sys/dev/ic/bwi.c: 1.33
sys/dev/ic/dwc_gmac.c: 1.41-1.42
sys/dev/ic/malo.c: 1.10
sys/dev/ic/rt2560.c: 1.31
sys/dev/ic/rt2661.c: 1.36
sys/dev/ic/rt2860.c: 1.29
sys/dev/ic/rtw.c: 1.127
sys/dev/ic/rtwvar.h: 1.46
sys/dev/ic/smc90cx6.c: 1.71
sys/dev/ic/smc90cx6var.h: 1.12
sys/dev/ic/wi.c: 1.244
sys/dev/pci/if_ipw.c: 1.66
sys/dev/pci/if_iwi.c: 1.104
sys/dev/pci/if_iwm.c: 1.76
sys/dev/pci/if_iwn.c: 1.86
sys/dev/pci/if_rtwn.c: 1.13
sys/dev/pci/if_wm.c: 1.541
sys/dev/pci/if_wpi.c: 1.79
sys/dev/pci/ixgbe/ixgbe.c: 1.106
sys/dev/pci/ixgbe/ixv.c: 1.73 via patch
sys/dev/pcmcia/if_malo_pcmcia.c: 1.15
sys/dev/scsipi/if_se.c: 1.95
sys/dev/usb/if_upl.c: 1.60
sys/net/if.c: 1.396
sys/net/if.h: 1.241
sys/net/if_arc.h: 1.23
sys/net/if_arcsubr.c: 1.78
sys/net/if_bridge.c: 1.136-1.137
sys/net/if_etherip.c: 1.39
sys/net/if_faith.c: 1.56
sys/net/if_gif.c: 1.131
sys/net/if_loop.c: 1.96
sys/net/if_mpls.c: 1.30
sys/net/if_pppoe.c: 1.129
sys/net/if_srt.c: 1.27
sys/net/if_stf.c: 1.102
sys/net/if_tap.c: 1.100
sys/net/if_vlan.c: 1.105
sys/netinet/ip_carp.c: 1.91
sys/rump/net/lib/libshmif/if_shmem.c: 1.73-1.74
sys/rump/net/lib/libvirtif/if_virt.c: 1.55-1.56
if_initalize() and if_attach() failed when resource allocation failed
(e.g. allocating softint). Without this change, it panics. It's bad because
resource shortage really occured when a lot of pseudo interface is created.
To avoid this problem, don't panic and change return value of if_initialize()
and if_attach() to int. Caller fanction will be recover from error cleanly by
checking the return value.
Return if bah_attach_subr() failed.
If if_attach() failed in the attach function, return.
- If if_initialize() failed in the attach function, free resources and return.
- Add some missing frees in bridge_clone_destroy().
- KNF
If error occured in bcmeth_ccb_attach(), free resources and return.
If error occured in pq3etsec_attach(), free resources and return.
If error occured in the attach function, free resources and return.
- If if_initialize() failed in athn_attach(), free resources and return.
- Add missing pmf_event_deregister() in athn_detach().
- Free resources correctly on some errors in atw_attach().
- Use apint*() insread of printf() in the attach function.
If if_initialize() failed in the attach function, return.
- If if_initialize() failed in the attach function, free resources and return.
- Add missing dwc_gmac_free_dma_rings() and mutex_destroy() when attach
failed.
- If if_initialize() failed in the attach function, free resources and return.
- ifp is always not NULL in iwi_detach(). Check correctly with ifp->if_softc.
- If if_initialize() failed in the attach function, free resources and return.
- Fix error path in the attach function correctly.
If if_initialize() failed in the attach function, free resources and return.
If if_attach() failed in the attach function, free resources and return.
- If if_initialize() failed in the attach function, free resources and return.
- KNF
- If if_attach() failed in the attach function, free resources and return.
- KNF
Fix compile error.
Fix compile error.
We don't need '&mii', but just 'mii' for mii_detach().
Don't free sc_rthash twice
 1.108 25-Sep-2022  thorpej Remove unnecessary include of <sys/malloc.h>.
 1.107 24-May-2022  andvar fix various typos in comment, documentation and log messages.
 1.106 07-Feb-2020  thorpej Use callout_setfunc() / callout_schedule().
 1.105 04-Feb-2020  thorpej Use ifmedia_fini().
 1.104 30-Jan-2020  thorpej Adopt <net/if_stats.h>.
 1.103 06-Dec-2019  maxv branches: 1.103.2;
localify
 1.102 30-May-2019  msaitoh Simplify MII structure initialization and reference. No functional change.
 1.101 25-Apr-2019  msaitoh No functional change:
- Use __arraycount().
- u_int_{8,16,32}_t -> uint_{8,16,32}_t
- KNF.
- Tabify.
- Remove extra space.
 1.100 22-Apr-2019  msaitoh This driver uses MII(4) and have hook SIOC[GS]IFMEDIA which just pass to
ifmedia_ioctl(), the hook is not required because ether_ioctl has it
(if_ethersubr.c rev. 1.160). These drivers don't return ENETRESET in
ifmedia_ioctl(), so no functional change.
 1.99 05-Feb-2019  msaitoh Remove very old IFF_NOTRAILERS flag.
 1.98 22-Jan-2019  msaitoh Change MII PHY read/write API from:

int (*mii_readreg_t)(device_t, int, int);
void (*mii_writereg_t)(device_t, int, int, int);
to:

int (*mii_readreg_t)(device_t, int, int, uint16_t *);
int (*mii_writereg_t)(device_t, int, int, uint16_t);

Now we can test if a read/write operation failed or not by the return value.

In 802.3 spec says that the PHY shall not respond to read/write transaction
to the unimplemented register(22.2.4.3). Detecting timeout can be used to
check whether a register is implemented or not (if the register conforms to
the spec). ukphy(4) can be used this for MII_MMDACR and MII_MMDAADR.

Note that I noticed that the following code do infinite loop in the
read/wirte function. If it accesses unimplemented PHY register, it will hang.
It should be fixed:

arm/at91/at91emac.c
arm/ep93xx/epe.c
arm/omap/omapl1x_emac.c
mips/ralink/ralink_eth.c
arch/powerpc/booke/dev/pq3etsec.c(read)
dev/cadence/if_cemac.c <- hkenken
dev/ic/lan9118.c


Tested with the following device:

axe+ukphy
axe+rgephy
axen+rgephy (tested by Andrius V)
wm+atphy
wm+ukphy
wm+igphy
wm+ihphy
wm+makphy
sk+makphy
sk+brgphy
sk+gentbi
msk+makphy
sip+icsphy
sip+ukphy
re+rgephy
bge+brgphy
bnx+brgphy
gsip+gphyter
rtk+rlphy
fxp+inphy (tested by Andrius V)
tlp+acphy
ex+exphy
epic+qsphy
vge+ciphy (tested by Andrius V)
vr+ukphy (tested by Andrius V)
vte+ukphy (tested by Andrius V)

Not tested (MAC):
arm:at91emac
arm:cemac
arm:epe
arm:geminigmac
arm:enet
arm:cpsw
arm:emac(omac)
arm:emac(sunxi)
arm:npe
evbppc:temac
macppc:bm
macppc:gm
mips:aumac
mips:ae
mips:cnmac
mips:reth
mips:sbmac
playstation2:smap
powerpc:tsec
powerpc:emac(ibm4xx)
sgimips:mec
sparc:be
sf
ne(ax88190, dl10019)
awge
ep
gem
hme
smsh
mtd
sm
age
alc
ale
bce
cas
et
jme
lii
nfe
pcn
ste
stge
tl
xi
aue
mue
smsc
udav
url

Not tested (PHY):
amhphy
bmtphy
dmphy
etphy
glxtphy
ikphy
iophy
lxtphy
nsphyter
pnaphy
rdcphy
sqphy
tlphy
tqphy
urlphy
 1.97 26-Jun-2018  msaitoh branches: 1.97.2;
Implement the BPF direction filter (BIOC[GS]DIRECTION). It provides backward
compatibility with BIOC[GS]SEESENT ioctl. The userland interface is the same
as FreeBSD.

This change also fixes a bug that the direction is misunderstand on some
environment by passing the direction to bpf_mtap*() instead of checking
m->m_pkthdr.rcvif.
 1.96 22-Jun-2018  msaitoh It's not required to include net/bpfdesc.h. Remove it.
 1.95 23-May-2017  ozaki-r branches: 1.95.2; 1.95.8;
Apply deferred if_start to more drivers

And annotate some XXX_start as it runs in softint to clarify that
it doesn't need deferred if_start.
 1.94 15-Dec-2016  ozaki-r Move bpf_mtap and if_ipackets++ on Rx of each driver to percpuq if_input

The benefits of the change are:
- We can reduce codes
- We can provide the same behavior between drivers
- Where/When if_ipackets is counted up
- Note that some drivers still update packet statistics in their own
way (periodical update)
- Moved bpf_mtap run in softint
- This makes it easy to MP-ify bpf

Proposed on tech-kern and tech-net
 1.93 07-Jul-2016  msaitoh branches: 1.93.2;
KNF. Remove extra spaces. No functional change.
 1.92 10-Jun-2016  ozaki-r Introduce m_set_rcvif and m_reset_rcvif

The API is used to set (or reset) a received interface of a mbuf.
They are counterpart of m_get_rcvif, which will come in another
commit, hide internal of rcvif operation, and reduce the diff of
the upcoming change.

No functional change.
 1.91 09-Feb-2016  ozaki-r Introduce softint-based if_input

This change intends to run the whole network stack in softint context
(or normal LWP), not hardware interrupt context. Note that the work is
still incomplete by this change; to that end, we also have to softint-ify
if_link_state_change (and bpf) which can still run in hardware interrupt.

This change softint-ifies at ifp->if_input that is called from
each device driver (and ieee80211_input) to ensure Layer 2 runs
in softint (e.g., ether_input and bridge_input). To this end,
we provide a framework (called percpuq) that utlizes softint(9)
and percpu ifqueues. With this patch, rxintr of most drivers just
queues received packets and schedules a softint, and the softint
dequeues packets and does rest packet processing.

To minimize changes to each driver, percpuq is allocated in struct
ifnet for now and that is initialized by default (in if_attach).
We probably have to move percpuq to softc of each driver, but it's
future work. At this point, only wm(4) has percpuq in its softc
as a reference implementation.

Additional information including performance numbers can be found
in the thread at tech-kern@ and tech-net@:
http://mail-index.netbsd.org/tech-kern/2016/01/14/msg019997.html

Acknowledgment: riastradh@ greatly helped this work.
Thank you very much!
 1.90 30-Aug-2015  dholland Even if the "card went away", don't return from smc91cxx_init without
restoring interrupts. From maxv's brainy list.
 1.89 13-Apr-2015  riastradh Convert sys/dev to use <sys/rndsource.h>.
 1.88 10-Aug-2014  tls branches: 1.88.4;
Merge tls-earlyentropy branch into HEAD.
 1.87 10-Jul-2014  christos add missing fallthrough
 1.86 08-Sep-2013  chs branches: 1.86.2;
revert making smc91cxx_idstrs static, it's referenced from
sys/dev/isa/if_sm_isa.c
 1.85 07-Sep-2013  chs apply changes from Robert Sprowson in PR 47765 and PR 47788:
- make sure we wait long enough after resetting the chip.
- add the necessary delay after changing the FIFO pointer.
- add a missing interrupt ACK.
- fix padding of short and odd-length packets.

and a few more changes from me:
- do 2-byte writes in most places even if SMC91CXX_NO_BYTE_WRITE
is not defined. the only ones still conditionalized are
writing to the interrupt ack/mask registers.
- the only big-endian front-end of this driver (on mac68k) uses
a bus_space that does all the byte-swapping in that layer,
so remove the explicit byte-swapping in the MI part.

tested on mac68k.
 1.84 11-Jun-2013  msaitoh branches: 1.84.2;
In interrupt function, use mii_pollstat() instead of mii_tick() to update
PHY status.
 1.83 27-Oct-2012  chs split device_t/softc for all remaining drivers.
replace "struct device *" with "device_t".
use device_xname(), device_unit(), etc.
 1.82 22-Jul-2012  matt branches: 1.82.2;
Fix mii_statchg to take a 'struct ifnet *' instead of device_t. This fixes
problem with a common MDIO bus used for multiple interfaces.
Some drivers converted to CFATTACL_DECL_NEW.
 1.81 12-Feb-2012  matt Change old-style function defintions to C89 prototypes.

Approved by releng.
 1.80 02-Feb-2012  tls Entropy-pool implementation move and cleanup.

1) Move core entropy-pool code and source/sink/sample management code
to sys/kern from sys/dev.

2) Remove use of NRND as test for presence of entropy-pool code throughout
source tree.

3) Remove use of RND_ENABLED in device drivers as microoptimization to
avoid expensive operations on disabled entropy sources; make the
rnd_add calls do this directly so all callers benefit.

4) Fix bug in recent rnd_add_data()/rnd_add_uint32() changes that might
have lead to slight entropy overestimation for some sources.

5) Add new source types for environmental sensors, power sensors, VM
system events, and skew between clocks, with a sample implementation
for each.

ok releng to go in before the branch due to the difficulty of later
pullup (widespread #ifdef removal and moved files). Tested with release
builds on amd64 and evbarm and live testing on amd64.
 1.79 13-Nov-2010  uebayasi branches: 1.79.8; 1.79.12;
Don't pull in the whole uvm(9) API to access only PAGE_SIZE and
some other constants. These are provided by sys/param.h now.
 1.78 05-Apr-2010  joerg Push the bpf_ops usage back into bpf.h. Push the common ifp->if_bpf
check into the inline functions as well the fourth argument for
bpf_attach.
 1.77 19-Jan-2010  pooka branches: 1.77.2; 1.77.4;
Redefine bpf linkage through an always present op vector, i.e.
#if NBPFILTER is no longer required in the client. This change
doesn't yet add support for loading bpf as a module, since drivers
can register before bpf is attached. However, callers of bpf can
now be modularized.

Dynamically loadable bpf could probably be done fairly easily with
coordination from the stub driver and the real driver by registering
attachments in the stub before the real driver is loaded and doing
a handoff. ... and I'm not going to ponder the depths of unload
here.

Tested with i386/MONOLITHIC, modified MONOLITHIC without bpf and rump.
 1.76 06-Dec-2009  dyoung Simplify device-activation hooks.
 1.75 12-May-2009  cegger struct device * -> device_t, no functional changes intended.
 1.74 11-May-2009  cegger use device_xname()
 1.73 14-Mar-2009  dsl ANSIfy another 1261 function definitions.
The only ones left in sys are beyond by sed script!
(or in sys/dist or sys/external)
Mostly they have function pointer parameters.
 1.72 14-Mar-2009  dsl Change about 4500 of the K&R function definitions to ANSI ones.
There are still about 1600 left, but they have ',' or /* ... */
in the actual variable definitions - which my awk script doesn't handle.
There are also many that need () -> (void).
(The script does handle misordered arguments.)
 1.71 07-Nov-2008  dyoung branches: 1.71.4;
*** Summary ***

When a link-layer address changes (e.g., ifconfig ex0 link
02:de:ad:be:ef:02 active), send a gratuitous ARP and/or a Neighbor
Advertisement to update the network-/link-layer address bindings
on our LAN peers.

Refuse a change of ethernet address to the address 00:00:00:00:00:00
or to any multicast/broadcast address. (Thanks matt@.)

Reorder ifnet ioctl operations so that driver ioctls may inherit
the functions of their "class"---ether_ioctl(), fddi_ioctl(), et
cetera---and the class ioctls may inherit from the generic ioctl,
ifioctl_common(), but both driver- and class-ioctls may override
the generic behavior. Make network drivers share more code.

Distinguish a "factory" link-layer address from others for the
purposes of both protecting that address from deletion and computing
EUI64.

Return consistent, appropriate error codes from network drivers.

Improve readability. KNF.

*** Details ***

In if_attach(), always initialize the interface ioctl routine,
ifnet->if_ioctl, if the driver has not already initialized it.
Delete if_ioctl == NULL tests everywhere else, because it cannot
happen.

In the ioctl routines of network interfaces, inherit common ioctl
behaviors by calling either ifioctl_common() or whichever ioctl
routine is appropriate for the class of interface---e.g., ether_ioctl()
for ethernets.

Stop (ab)using SIOCSIFADDR and start to use SIOCINITIFADDR. In
the user->kernel interface, SIOCSIFADDR's argument was an ifreq,
but on the protocol->ifnet interface, SIOCSIFADDR's argument was
an ifaddr. That was confusing, and it would work against me as I
make it possible for a network interface to overload most ioctls.
On the protocol->ifnet interface, replace SIOCSIFADDR with
SIOCINITIFADDR. In ifioctl(), return EPERM if userland tries to
invoke SIOCINITIFADDR.

In ifioctl(), give the interface the first shot at handling most
interface ioctls, and give the protocol the second shot, instead
of the other way around. Finally, let compatibility code (COMPAT_OSOCK)
take a shot.

Pull device initialization out of switch statements under
SIOCINITIFADDR. For example, pull ..._init() out of any switch
statement that looks like this:

switch (...->sa_family) {
case ...:
..._init();
...
break;
...
default:
..._init();
...
break;
}

Rewrite many if-else clauses that handle all permutations of IFF_UP
and IFF_RUNNING to use a switch statement,

switch (x & (IFF_UP|IFF_RUNNING)) {
case 0:
...
break;
case IFF_RUNNING:
...
break;
case IFF_UP:
...
break;
case IFF_UP|IFF_RUNNING:
...
break;
}

unifdef lots of code containing #ifdef FreeBSD, #ifdef NetBSD, and
#ifdef SIOCSIFMTU, especially in fwip(4) and in ndis(4).

In ipw(4), remove an if_set_sadl() call that is out of place.

In nfe(4), reuse the jumbo MTU logic in ether_ioctl().

Let ethernets register a callback for setting h/w state such as
promiscuous mode and the multicast filter in accord with a change
in the if_flags: ether_set_ifflags_cb() registers a callback that
returns ENETRESET if the caller should reset the ethernet by calling
if_init(), 0 on success, != 0 on failure. Pull common code from
ex(4), gem(4), nfe(4), sip(4), tlp(4), vge(4) into ether_ioctl(),
and register if_flags callbacks for those drivers.

Return ENOTTY instead of EINVAL for inappropriate ioctls. In
zyd(4), use ENXIO instead of ENOTTY to indicate that the device is
not any longer attached.

Add to if_set_sadl() a boolean 'factory' argument that indicates
whether a link-layer address was assigned by the factory or some
other source. In a comment, recommend using the factory address
for generating an EUI64, and update in6_get_hw_ifid() to prefer a
factory address to any other link-layer address.

Add a routing message, RTM_LLINFO_UPD, that tells protocols to
update the binding of network-layer addresses to link-layer addresses.
Implement this message in IPv4 and IPv6 by sending a gratuitous
ARP or a neighbor advertisement, respectively. Generate RTM_LLINFO_UPD
messages on a change of an interface's link-layer address.

In ether_ioctl(), do not let SIOCALIFADDR set a link-layer address
that is broadcast/multicast or equal to 00:00:00:00:00:00.

Make ether_ioctl() call ifioctl_common() to handle ioctls that it
does not understand.

In gif(4), initialize if_softc and use it, instead of assuming that
the gif_softc and ifp overlap.

Let ifioctl_common() handle SIOCGIFADDR.

Sprinkle rtcache_invariants(), which checks on DIAGNOSTIC kernels
that certain invariants on a struct route are satisfied.

In agr(4), rewrite agr_ioctl_filter() to be a bit more explicit
about the ioctls that we do not allow on an agr(4) member interface.

bzero -> memset. Delete unnecessary casts to void *. Use
sockaddr_in_init() and sockaddr_in6_init(). Compare pointers with
NULL instead of "testing truth". Replace some instances of (type
*)0 with NULL. Change some K&R prototypes to ANSI C, and join
lines.
 1.70 03-Sep-2008  rjs branches: 1.70.2;
Make it work again for platforms that can do single byte operations.

Fix to PR kern/38757.
 1.69 25-May-2008  chs branches: 1.69.4;
include uvm/uvm_extern.h for trunc_page() on sparc
(where the page size isn't a compile-time constant).
 1.68 29-Apr-2008  nakayama branches: 1.68.2;
Make it compile again on big endian, and restore CVS keyword.
 1.67 28-Apr-2008  matt More forgotten changes from matt-armv6.
 1.66 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.65 08-Apr-2008  cegger branches: 1.65.2; 1.65.4;
use aprint_*_dev and device_xname
 1.64 19-Jan-2008  dyoung branches: 1.64.6;
Make many ethernet drivers share the common code for MII media
handling, ether_mediastatus() and ether_mediachange(). Check for
a non-ENXIO error return from mii_mediachg(). (ENXIO indicates
that a PHY is suspended.)

This patch shrinks the source code size by 979 lines. There was
a 5100-byte savings on the NetBSD/i386 kernel configuration, ALL.

I have made a few miscellaneous changes, too:

gem(4): use LIST_EMPTY(), LIST_FOREACH().
mtd(4): handle media ioctls, for a change!
axe(4): do not track link status in sc->axe_link any longer
nfe(4), aue(4), axe(4), udav(4), url(4): do not reset all PHYs
on a change of media

Except for the change to mtd(4), no functional changes are intended.

XXX This patch affects more architectures than I can feasibly
XXX compile and run. I have compiled macppc, sparc64, i386. I
XXX have run the patches on i386 boxen with bnx(4) and sip(4).
XXX Compiling and running on evbmips (MERAKI, ADM5120) is in
XXX progress.
 1.63 19-Oct-2007  ad branches: 1.63.2; 1.63.8;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.62 01-Sep-2007  dyoung branches: 1.62.4;
Change a bazillion occurrences of code resembling this,

error = (cmd == SIOCADDMULTI) ?
ether_addmulti(ifr, &sc->sc_ec) :
ether_delmulti(ifr, &sc->sc_ec);

if (error == ENETRESET) {

to this,

if ((error = ether_ioctl(ifp, cmd, data)) == ENETRESET) {

which does the same thing.

(A bazillion is a very large number. This seems to make the i386
ALL kernel smaller by 3kB to 4kB.)

Use ifreq_getaddr() twice in es(4).

Whitespace nits.
 1.61 27-Aug-2007  dyoung branches: 1.61.2;
Constify: use CLLADDR() instead of LLADDR() wherever possible.
 1.60 14-Aug-2007  kiyohara Must call callout_init().
 1.59 04-Mar-2007  christos branches: 1.59.2; 1.59.10; 1.59.14;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.58 16-Nov-2006  christos branches: 1.58.4; 1.58.10;
__unused removal on arguments; approved by core.
 1.57 12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.56 07-Sep-2006  dogcow branches: 1.56.2; 1.56.4;
remove more vestiges of CCITT, LLC, HDLC, NS, and NSIP.
 1.55 20-Feb-2006  thorpej branches: 1.55.2;
Use device_is_active() rather than testing dv_flags for DVF_ACTIVE
directly.
 1.54 24-Dec-2005  perry branches: 1.54.2; 1.54.4; 1.54.6;
Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.53 11-Dec-2005  christos merge ktrace-lwp.
 1.52 06-Jun-2005  pooka branches: 1.52.2;
Instead of writing the packet length in two 8bit pieces, use one
16bit write. At least in certain environments this has the effect
of the latter 8bit write of the length to be not interpreted as
the first 16 bits of the packet contents and hence the interface
working.
 1.51 27-Feb-2005  perry nuke trailing whitespace
 1.50 04-Feb-2005  perry de-__P
 1.49 30-Oct-2004  thorpej branches: 1.49.4; 1.49.6;
When adding/deleting multicast addresses, only whack the address
filter if the interface is marked RUNNING.

Fixes kern/27678.
 1.48 09-Aug-2004  mycroft Don't loop forever if a card went away.
 1.47 08-Aug-2004  mycroft Look in the correct register for the BSR detection value.
Also, do this early, before writing any registers.
 1.46 02-Nov-2003  wiz branches: 1.46.4;
Fix some typos. From Tom Cosgrove via jmc@openbsd.
 1.45 29-Apr-2003  scw branches: 1.45.2;
Add support for the SMC91C111 chip, with its internal PHY.
 1.44 22-Oct-2002  fair Change the "dontcare bits" argument to ifmedia_init() to IFM_IMASK
so that it is possible select PHY instances other than the first
one (instance zero), if there is more than one PHY attached.
 1.43 28-Sep-2002  scw Add smc91cxx_copy_tx_frame(), based on the version in cs89x0.c, to deal
with misaligned mbufs.
 1.42 24-Sep-2002  bsh make this compile again on ports that don't have bus space stream methods.
 1.41 04-Sep-2002  scw Add a flag, SMC_FLAGS_32BIT_READ, which is settable by the bus-specific
back-end to indicate that the device always sees reads as 32-bit
transactions, even if the host does 8 or 16-bit reads.

This is necessary for the SH-5 "Cayman" on-board ethernet. The SMsC part
is behind an FPGA which maps all cpu reads to 32-bits transactions.
 1.40 03-May-2002  thorpej Handle platforms that don't provide stream methods.
From Hiroyuki Bessho, PR 16617.
 1.39 27-Mar-2002  chs 91C96 has the same chip ID as 91C94, list both in attach output. PR 11413.
 1.38 20-Mar-2002  thorpej When getting the packet off the interface, make sure the payload is
aligned after the Ethernet header.

kern/15982, Hiroyuki Bessho <bsh@grotto.jp>
 1.37 13-Nov-2001  lukem add/cleanup RCSID
 1.36 02-Oct-2001  pooka fix system freeze in situation where you pop a pcmcia card out of the
slot while it is in operation

ok'd by thorpej
 1.35 20-Aug-2001  thorpej branches: 1.35.2;
Oops, the "auto" capability was getting masked off by mistake.
Fixes a panic reported by Chuck Silvers.
 1.34 07-Jul-2001  thorpej branches: 1.34.2;
bcopy -> memcpy, strcpy
 1.33 14-Jun-2001  itojun change the meaning of ifnet.if_lastchange to meet RFC1573 ifLastChange.
follows BSD/OS practice and ucd-snmp code (FreeBSD does it for specific
interfaces only).

was: if_lastchange get updated on every packet transmission/receipt.
now: if_lastchange get updated when IFF_UP is changed.
 1.32 14-Dec-2000  thorpej branches: 1.32.2;
ALTQ'ify.
 1.31 15-Nov-2000  thorpej Move bpfattach()/bpfdetach() calls into ether_ifattach()/ether_ifdetach().
 1.30 01-Oct-2000  thorpej Move the check for "promisc + unicast + not for us" into ether_input(),
and change Ethernet drivers to always pass all received frames to
ether_input() (with a few exceptions, which are documented in the
code).
 1.29 06-Aug-2000  briggs Label the buffer size as such on probe. 128 KB makes sense, but 4608 does not.
 1.28 31-Jul-2000  briggs Use bus_space_read/write_multi_stream_2 for FIFO instead of bsr/w_multi_2.
 1.27 31-Jul-2000  briggs Make sure that we do not call bus_space_*_multi_* with zero count.
 1.26 30-Jul-2000  briggs Add MII support to smc91cxx driver. This is supported for the 91c100
and 91c100FD (FEAST) controllers. Existing controllers should continue
to work as they have. Added the card's memory to the probe message.
 1.25 29-May-2000  jhawk branches: 1.25.2;
For all network drivers that call ether_ifattach(), and also
have _detach() functions:
Ensure that softc keeps state about whether the attach succeeded,
and make the detach function return immediately if the attach did
not complete.
 1.24 04-Feb-2000  enami branches: 1.24.2;
- Call if_deactivate instead of smc91cxx_disable when deactivating.
- Fix typo in comment.
 1.23 03-Feb-2000  itojun fix promisc mode for smc91cxx again.
 1.22 02-Feb-2000  itojun if_detach for sm/pcmcia.
with addition of resource allocation flags in softc (to DTRT on detach).
 1.21 17-Jan-2000  itojun in promisc mode, don't inject outgoing packet to bpf twice.
this is because the card gets the outgoing packet from itself in promisc mode
(not really IFF_SIMPLEX).
 1.20 28-Sep-1999  thorpej branches: 1.20.2;
Make sure the Revision register contains the correct magic number.

From Chuck Cranor.
 1.19 12-Sep-1999  itojun drop wrongly looped back multicast packet before we put it into BPF.
 1.18 10-Sep-1999  itojun Make sure to behave as IFF_SIMPLEX in all cases.
Drop multicast/broadcast packet looped back from myself.

This is to cope with SMC91C92 (Megahertz XJ10BT), which
loops back multicast packet to itself on promiscuous mode.
(should be ensured by chipset configuration)

Reviewed by: thorpej
 1.17 18-May-1999  thorpej Rework layer 2 protocol input routines. Instead of calling e.g. ether_input()
directly, call the function pointer (*if_input)(ifp, m). The input routine
expects the packet header to be at the head of the packet, and will adjust
as necessary. Privatize the layer 2 input and output routines, allowing
*_ifattach() to set them up as appropriate.
 1.16 25-Mar-1999  thorpej branches: 1.16.2; 1.16.4; 1.16.6;
Use ETHER_*_LEN constants from <net/if_ether.h> instead of defining them
ourselves.
 1.15 28-Feb-1999  explorer Update to slightly altered rnd_attach_source() api
 1.14 17-Feb-1999  thorpej Avoid initializing the interface in the SIOCSIFFLAGS if ! UP and ! RUNNING.
 1.13 18-Nov-1998  thorpej branches: 1.13.2;
Now that the *_activate() functions don't do things which are attachment
specific, move them into the chipset drivers.
 1.12 17-Nov-1998  thorpej Expose the "enable" and "disable" functions so that the front-ends can
access them.
 1.11 08-Aug-1998  mycroft Use splnet, not splimp.
 1.10 05-Jul-1998  jonathan defopt NS, NSIP.
 1.9 05-Jul-1998  jonathan defopt LLC
 1.8 05-Jul-1998  jonathan defopt CCITT.
 1.7 05-Jul-1998  jonathan defopt INET, NETATALK.
 1.6 12-Jan-1998  thorpej Adjust for config changes.
 1.5 15-Oct-1997  explorer Add and/or update rnd_*() hooks
 1.4 14-Oct-1997  thorpej Pull down from marc-pcmcia branch:

Add support for power management.
 1.3 09-Oct-1997  jtc Fix tipo inherited from old version of TNF copyright template.
 1.2 02-Sep-1997  thorpej Pull the SMC91Cxx single-chip Ethernet driver core down from the marc-pcmcia
branch. It is also needed by and ISA front-end.
 1.1 11-Aug-1997  thorpej branches: 1.1.2;
file smc91cxx.c was initially added on branch marc-pcmcia.
 1.1.2.10 14-Oct-1997  thorpej Update marc-pcmcia branch from trunk.
 1.1.2.9 14-Oct-1997  thorpej Rearrange the disable functions slightly so that an interface that
interfaces that don't have a disable hook will never be marked "disabled".

Now, once an interface has been marked "enabled" by the enable function,
it will remain marked as such for the duration of the kernel's lifetime.
 1.1.2.8 06-Oct-1997  thorpej Fix a brain-o in my last power management changes. Specifically, allow
the media callbacks to be used while the interface is powered off. If
the interface is powered off, return "none" in response to a "get media",
and in the case of "set media", just return success, since the init routine
will properly program the hardware when power is enabled. If we return
an error in the powered off case, ifconfig(8) will lose because it performs
the "set address" (which will enable power on a disabled interface) after
parsing the entire command line.
 1.1.2.7 29-Sep-1997  thorpej Add power management hooks.
 1.1.2.6 24-Aug-1997  thorpej If we change the MAC address, make sure the receiver is disabled first.
 1.1.2.5 24-Aug-1997  thorpej Fix a few more problems, making this much more stable under heavy
transmit load (ping -f -s 4096 ...):
- Correct a logical flaw in the memory allocation portion of smc91cxx_start().
Previous code could get into an infinite loop in some cases.
- Only clear the watchdog timer on TX complete/underrun and memory allocation
interrupts.
- Always attempt to transmit any pending packets whenever we recieve an
interrupt.

Also, use log(), not printf(), to log device timeouts.

Still needs a bit more work, but we're getting there. The Megahertz
X-JACK Ethernet is now very usable for every "normal" task I can throw
at it.
 1.1.2.4 24-Aug-1997  thorpej Fix a few annoying bugs:
- Make sure the default media is set up correctly in smc91cxx_init().
- Fix a memory leak in the "resume from memory allocation interrupt" logic.
Acually, completely toss the logic that was in the original driver, and
replace it with a much simpler scheme from Michael Hitch's NetBSD/amiga
"es" driver: Rather than "resuming" the transmission that causes us
to use the memory allocation interrupt, simply free the just-allocated
memory back to the chip's MMU, and use the standard "start" logic, which
will reallocate it from the MMU in a straightforward way.
- Only set IFF_OACTIVE if we can't transmit any more packets (i.e. we
were forced to use the memory allocation interrupt).
 1.1.2.3 13-Aug-1997  jtk fix typo in X25 code
 1.1.2.2 12-Aug-1997  thorpej Fix a couple of constants that slipped through. (Wow, and this worked
when I tested it?)
 1.1.2.1 11-Aug-1997  thorpej Driver for the SMC91Cxx ethernet chip, found in some ISA and PCMCIA ethernet
interfaces. Some PCI network interfaces also use a variant of this chip
Derived from the FreeBSD "sn" driver, written by Gardener Buchanan.
 1.13.2.1 11-Dec-1998  kenh The beginnings of interface detach support. Still some bugs, but mostly
works for me.

This work was originally by Bill Studenmund, and cleaned up by me.
 1.16.6.1 30-Nov-1999  itojun bring in latest KAME (as of 19991130, KAME/NetBSD141) into kame branch
just for reference purposes.
This commit includes 1.4 -> 1.4.1 sync for kame branch.

The branch does not compile at all (due to the lack of ALTQ and some other
source code). Please do not try to modify the branch, this is just for
referenre purposes.

synchronization to latest KAME will take place on HEAD branch soon.
 1.16.4.1 21-Jun-1999  thorpej Sync w/ -current.
 1.16.2.1 16-Sep-1999  itojun pullup changes 1.17->1.19.

Avoid multicast packet loopback from itself during promiscuous mode.
This makes the driver behave as IFF_SIMPLEX interface in all cases.
 1.20.2.3 05-Jan-2001  bouyer Sync with HEAD
 1.20.2.2 22-Nov-2000  bouyer Sync with HEAD.
 1.20.2.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.24.2.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.25.2.1 06-Aug-2000  briggs Pullups approved by thorpej --
Add MII support to smc91cxx driver. This is supported for the 91c100
and 91c100FD (FEAST) controllers. Existing controllers should continue
to work as they have. Added the card's memory to the probe message.

Make sure that we do not call bus_space_*_multi_* with zero count.
Use bus_space_read/write_multi_stream_2 for FIFO instead of bsr/w_multi_2.
 1.32.2.9 11-Nov-2002  nathanw Catch up to -current
 1.32.2.8 18-Oct-2002  nathanw Catch up to -current.
 1.32.2.7 17-Sep-2002  nathanw Catch up to -current.
 1.32.2.6 20-Jun-2002  nathanw Catch up to -current.
 1.32.2.5 01-Apr-2002  nathanw Catch up to -current.
(CVS: It's not just a program. It's an adventure!)
 1.32.2.4 14-Nov-2001  nathanw Catch up to -current.
 1.32.2.3 08-Oct-2001  nathanw Catch up to -current.
 1.32.2.2 24-Aug-2001  nathanw Catch up with -current.
 1.32.2.1 21-Jun-2001  nathanw Catch up to -current.
 1.34.2.4 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.34.2.3 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.34.2.2 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.34.2.1 25-Aug-2001  thorpej Merge Aug 24 -current into the kqueue branch.
 1.35.2.1 11-Oct-2001  fvdl Catch up with -current. Fix some bogons in the sparc64 kbd/ms
attach code. cd18xx conversion provided by mrg.
 1.45.2.8 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.45.2.7 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.45.2.6 04-Feb-2005  skrll Sync with HEAD.
 1.45.2.5 02-Nov-2004  skrll Sync with HEAD.
 1.45.2.4 21-Sep-2004  skrll Fix the sync with head I botched.
 1.45.2.3 18-Sep-2004  skrll Sync with HEAD.
 1.45.2.2 12-Aug-2004  skrll Sync with HEAD.
 1.45.2.1 03-Aug-2004  skrll Sync with HEAD
 1.46.4.1 24-Jan-2005  he Pull up revision 1.49 (requested by thorpej in ticket #939):
When adding or deleting multicast addresses, only change
the address filter if the interface is marked RUNNING.
Fixes PR#27678.
 1.49.6.2 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.49.6.1 12-Feb-2005  yamt sync with head.
 1.49.4.1 29-Apr-2005  kent sync with -current
 1.52.2.5 21-Jan-2008  yamt sync with head
 1.52.2.4 27-Oct-2007  yamt sync with head.
 1.52.2.3 03-Sep-2007  yamt sync with head.
 1.52.2.2 30-Dec-2006  yamt sync with head.
 1.52.2.1 21-Jun-2006  yamt sync with head.
 1.54.6.1 22-Apr-2006  simonb Sync with head.
 1.54.4.1 09-Sep-2006  rpaulo sync with head
 1.54.2.1 01-Mar-2006  yamt sync with head.
 1.55.2.1 14-Sep-2006  yamt sync with head.
 1.56.4.2 10-Dec-2006  yamt sync with head.
 1.56.4.1 22-Oct-2006  yamt sync with head
 1.56.2.1 18-Nov-2006  ad Sync with head.
 1.58.10.1 10-Nov-2007  matt Add AT91 support from Sami Kantoluoto
Add TI OMAP2430 support from Marty Fouts @ Danger Inc
 1.58.4.1 12-Mar-2007  rmind Sync with HEAD.
 1.59.14.3 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.59.14.2 03-Sep-2007  jmcneill Sync with HEAD.
 1.59.14.1 16-Aug-2007  jmcneill Sync with HEAD.
 1.59.10.2 03-Sep-2007  skrll Sync with HEAD.
 1.59.10.1 15-Aug-2007  skrll Sync with HEAD.
 1.59.2.3 23-Oct-2007  ad Sync with head.
 1.59.2.2 09-Oct-2007  ad Sync with head.
 1.59.2.1 20-Aug-2007  ad Sync with HEAD.
 1.61.2.3 23-Mar-2008  matt sync with HEAD
 1.61.2.2 06-Nov-2007  matt sync with HEAD
 1.61.2.1 29-Oct-2007  matt Update to use only word accesses. Fix incorrect padding of odd length
packets. Cache intmask.
 1.62.4.1 25-Oct-2007  bouyer Sync with HEAD.
 1.63.8.1 20-Jan-2008  bouyer Sync with HEAD
 1.63.2.1 18-Feb-2008  mjf Sync with HEAD.
 1.64.6.3 17-Jan-2009  mjf Sync with HEAD.
 1.64.6.2 28-Sep-2008  mjf Sync with HEAD.
 1.64.6.1 02-Jun-2008  mjf Sync with HEAD.
 1.65.4.5 11-Aug-2010  yamt sync with head.
 1.65.4.4 11-Mar-2010  yamt sync with head
 1.65.4.3 16-May-2009  yamt sync with head
 1.65.4.2 04-May-2009  yamt sync with head.
 1.65.4.1 16-May-2008  yamt sync with head.
 1.65.2.2 04-Jun-2008  yamt sync with head
 1.65.2.1 18-May-2008  yamt sync with head.
 1.68.2.2 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.68.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.69.4.2 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.69.4.1 19-Oct-2008  haad Sync with HEAD.
 1.70.2.2 28-Apr-2009  skrll Sync with HEAD.
 1.70.2.1 19-Jan-2009  skrll Sync with HEAD.
 1.71.4.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.77.4.2 05-Mar-2011  rmind sync with head
 1.77.4.1 30-May-2010  rmind sync with head
 1.77.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.79.12.1 18-Feb-2012  mrg merge to -current.
 1.79.8.3 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.79.8.2 30-Oct-2012  yamt sync with head
 1.79.8.1 17-Apr-2012  yamt sync with head
 1.82.2.4 03-Dec-2017  jdolecek update from HEAD
 1.82.2.3 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.82.2.2 23-Jun-2013  tls resync from head
 1.82.2.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.84.2.1 18-May-2014  rmind sync with head
 1.86.2.2 10-Aug-2014  tls Rebase.
 1.86.2.1 07-Apr-2014  tls Be a little more clear and consistent about harvesting entropy from devices:

1) deprecate RND_FLAG_NO_ESTIMATE

2) define RND_FLAG_COLLECT_TIME, RND_FLAG_COLLECT_VALUE

3) define RND_FLAG_ESTIMATE_TIME, RND_FLAG_ESTIMATE_VALUE

4) define RND_FLAG_DEFAULT: RND_FLAG_COLLECT_TIME|
RND_FLAG_COLLECT_VALUE|RND_FLAG_ESTIMATE_TIME

5) Make entropy harvesting from environmental sensors a little more generic
and remove it from individual sensor drivers.

6) Remove individual open-coded delta-estimators for values from a few
places in the tree (uvm, environmental drivers).

7) 0 -> RND_FLAG_DEFAULT, actually gather entropy from various drivers
that had stubbed out code, other minor cleanups.
 1.88.4.6 28-Aug-2017  skrll Sync with HEAD
 1.88.4.5 05-Feb-2017  skrll Sync with HEAD
 1.88.4.4 09-Jul-2016  skrll Sync with HEAD
 1.88.4.3 19-Mar-2016  skrll Sync with HEAD
 1.88.4.2 22-Sep-2015  skrll Sync with HEAD
 1.88.4.1 06-Jun-2015  skrll Sync with HEAD
 1.93.2.1 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.95.8.3 26-Jan-2019  pgoyette Sync with HEAD
 1.95.8.2 28-Jul-2018  pgoyette Sync with HEAD
 1.95.8.1 25-Jun-2018  pgoyette Sync with HEAD
 1.95.2.1 26-Jul-2018  snj Pull up following revision(s) (requested by msaitoh in ticket #938):
sys/arch/acorn32/podulebus/if_ie.c: revision 1.41
sys/arch/amiga/dev/if_es.c: revision 1.58
sys/arch/amiga/dev/if_qn.c: revision 1.45
sys/arch/arm/at91/at91emac.c: revision 1.20
sys/arch/arm/ep93xx/epe.c: revision 1.37
sys/arch/emips/ebus/if_le_ebus.c: revision 1.14
sys/arch/emips/ebus/if_le_ebus.c: revision 1.15
sys/arch/mac68k/dev/if_mc.c: revision 1.46
sys/arch/macppc/dev/am79c950.c: revision 1.39
sys/arch/newsmips/apbus/if_sn.c: revision 1.40
sys/arch/next68k/dev/mb8795.c: revision 1.59
sys/arch/playstation2/dev/if_smap.c: revision 1.25
sys/arch/playstation2/dev/if_smap.c: revision 1.26
sys/arch/sun2/dev/if_ec.c: revision 1.28
sys/arch/sun3/dev/if_ie.c: revision 1.63
sys/arch/x68k/dev/if_ne_intio.c: revision 1.19
sys/arch/xen/xen/if_xennet_xenbus.c: revision 1.75
sys/arch/xen/xen/xennetback_xenbus.c: revision 1.63
sys/dev/bi/if_ni.c: revision 1.45
sys/dev/cadence/if_cemac.c: revision 1.12
sys/dev/ic/am7990.c: revision 1.78
sys/dev/ic/am79900.c: revision 1.27
sys/dev/ic/an.c: revision 1.67
sys/dev/ic/cs89x0.c: revision 1.40
sys/dev/ic/dm9000.c: revision 1.13
sys/dev/ic/dm9000.c: revision 1.14
sys/dev/ic/dp8390.c: revision 1.88
sys/dev/ic/elink3.c: revision 1.141
sys/dev/ic/elinkxl.c: revision 1.122
sys/dev/ic/hme.c: revision 1.98
sys/dev/ic/i82586.c: revision 1.77
sys/dev/ic/lance.c: revision 1.53
sys/dev/ic/mb86950.c: revision 1.27
sys/dev/ic/mb86960.c: revision 1.86
sys/dev/ic/mtd803.c: revision 1.34
sys/dev/ic/pdq_ifsubr.c: revision 1.59
sys/dev/ic/rrunner.c: revision 1.86
sys/dev/ic/seeq8005.c: revision 1.58
sys/dev/ic/sgec.c: revision 1.47
sys/dev/ic/smc90cx6.c: revision 1.72
sys/dev/ic/smc91cxx.c: revision 1.96
sys/dev/ic/tropic.c: revision 1.49
sys/dev/ic/wi.c: revision 1.245
sys/dev/isa/if_eg.c: revision 1.93
sys/dev/isa/if_el.c: revision 1.95
sys/dev/isa/if_iy.c: revision 1.101
sys/dev/ofw/ofnet.c: revision 1.58
sys/dev/pci/if_alc.c: revision 1.27
sys/dev/pci/if_de.c: revision 1.152
sys/dev/pci/if_fpa.c: revision 1.61
sys/dev/pci/if_jme.c: revision 1.34
sys/dev/pci/if_tl.c: revision 1.108
sys/dev/pci/if_vte.c: revision 1.19
sys/dev/pci/ixgbe/ixgbe.h: revision 1.50
sys/dev/pcmcia/if_cnw.c: revision 1.62
sys/dev/pcmcia/if_malo_pcmcia.c: revision 1.17
sys/dev/pcmcia/if_ray.c: revision 1.89
sys/dev/pcmcia/if_xi.c: revision 1.81
sys/dev/pcmcia/mhzc.c: revision 1.51
sys/dev/pcmcia/xirc.c: revision 1.34
sys/dev/qbus/if_de.c: revision 1.33
sys/dev/qbus/if_qe.c: revision 1.78
sys/dev/qbus/if_qt.c: revision 1.22
sys/dev/sbus/be.c: revision 1.87
sys/dev/sbus/qe.c: revision 1.68
sys/dev/scsipi/if_se.c: revision 1.96
sys/dev/usb/if_atu.c: revision 1.59
sys/net/if_l2tp.c: revision 1.28 via patch
sys/net/if_ppp.c: revision 1.160
It's not required to include net/bpfdesc.h. Remove it.
--
Simplify like other drivers. NULL check of ifp->if_bpf is done in
bpf_mtap(), so it's not required to do it here.
--
Remove duplicated inclusion of net/bpf.h.
--
Remove duplicated inclusion of net/bpf.h.
--
Simplify bpf_mtap() call. No functional change.
 1.97.2.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.97.2.1 10-Jun-2019  christos Sync with HEAD
 1.103.2.1 29-Feb-2020  ad Sync with head.
 1.6 08-Dec-2021  andvar fix various typos in comments and log messages.
 1.5 29-Apr-2003  scw Add support for the SMC91C111 chip, with its internal PHY.
 1.4 12-Jun-2001  wiz receive, not recieve
 1.3 30-Jul-2000  briggs branches: 1.3.2;
Add MII support to smc91cxx driver. This is supported for the 91c100
and 91c100FD (FEAST) controllers. Existing controllers should continue
to work as they have. Added the card's memory to the probe message.
 1.2 02-Sep-1997  thorpej branches: 1.2.18; 1.2.28;
Pull the SMC91Cxx single-chip Ethernet driver core down from the marc-pcmcia
branch. It is also needed by and ISA front-end.
 1.1 11-Aug-1997  thorpej branches: 1.1.2;
file smc91cxxreg.h was initially added on branch marc-pcmcia.
 1.1.2.1 11-Aug-1997  thorpej Driver for the SMC91Cxx ethernet chip, found in some ISA and PCMCIA ethernet
interfaces. Some PCI network interfaces also use a variant of this chip
Derived from the FreeBSD "sn" driver, written by Gardener Buchanan.
 1.2.28.1 06-Aug-2000  briggs Pullups approved by thorpej --
Add MII support to smc91cxx driver. This is supported for the 91c100
and 91c100FD (FEAST) controllers. Existing controllers should continue
to work as they have. Added the card's memory to the probe message.

Make sure that we do not call bus_space_*_multi_* with zero count.
Use bus_space_read/write_multi_stream_2 for FIFO instead of bsr/w_multi_2.
 1.2.18.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.3.2.1 21-Jun-2001  nathanw Catch up to -current.
 1.21 06-Dec-2019  maxv localify
 1.20 13-Apr-2015  riastradh branches: 1.20.18;
Convert sys/dev to use <sys/rndsource.h>.
 1.19 27-Oct-2012  chs branches: 1.19.14;
split device_t/softc for all remaining drivers.
replace "struct device *" with "device_t".
use device_xname(), device_unit(), etc.
 1.18 02-Feb-2012  tls branches: 1.18.6;
Entropy-pool implementation move and cleanup.

1) Move core entropy-pool code and source/sink/sample management code
to sys/kern from sys/dev.

2) Remove use of NRND as test for presence of entropy-pool code throughout
source tree.

3) Remove use of RND_ENABLED in device drivers as microoptimization to
avoid expensive operations on disabled entropy sources; make the
rnd_add calls do this directly so all callers benefit.

4) Fix bug in recent rnd_add_data()/rnd_add_uint32() changes that might
have lead to slight entropy overestimation for some sources.

5) Add new source types for environmental sensors, power sensors, VM
system events, and skew between clocks, with a sample implementation
for each.

ok releng to go in before the branch due to the difficulty of later
pullup (widespread #ifdef removal and moved files). Tested with release
builds on amd64 and evbarm and live testing on amd64.
 1.17 19-Nov-2011  tls branches: 1.17.2;
First step of random number subsystem rework described in
<20111022023242.BA26F14A158@mail.netbsd.org>. This change includes
the following:

An initial cleanup and minor reorganization of the entropy pool
code in sys/dev/rnd.c and sys/dev/rndpool.c. Several bugs are
fixed. Some effort is made to accumulate entropy more quickly at
boot time.

A generic interface, "rndsink", is added, for stream generators to
request that they be re-keyed with good quality entropy from the pool
as soon as it is available.

The arc4random()/arc4randbytes() implementation in libkern is
adjusted to use the rndsink interface for rekeying, which helps
address the problem of low-quality keys at boot time.

An implementation of the FIPS 140-2 statistical tests for random
number generator quality is provided (libkern/rngtest.c). This
is based on Greg Rose's implementation from Qualcomm.

A new random stream generator, nist_ctr_drbg, is provided. It is
based on an implementation of the NIST SP800-90 CTR_DRBG by
Henric Jungheim. This generator users AES in a modified counter
mode to generate a backtracking-resistant random stream.

An abstraction layer, "cprng", is provided for in-kernel consumers
of randomness. The arc4random/arc4randbytes API is deprecated for
in-kernel use. It is replaced by "cprng_strong". The current
cprng_fast implementation wraps the existing arc4random
implementation. The current cprng_strong implementation wraps the
new CTR_DRBG implementation. Both interfaces are rekeyed from
the entropy pool automatically at intervals justifiable from best
current cryptographic practice.

In some quick tests, cprng_fast() is about the same speed as
the old arc4randbytes(), and cprng_strong() is about 20% faster
than rnd_extract_data(). Performance is expected to improve.

The AES code in src/crypto/rijndael is no longer an optional
kernel component, as it is required by cprng_strong, which is
not an optional kernel component.

The entropy pool output is subjected to the rngtest tests at
startup time; if it fails, the system will reboot. There is
approximately a 3/10000 chance of a false positive from these
tests. Entropy pool _input_ from hardware random numbers is
subjected to the rngtest tests at attach time, as well as the
FIPS continuous-output test, to detect bad or stuck hardware
RNGs; if any are detected, they are detached, but the system
continues to run.

A problem with rndctl(8) is fixed -- datastructures with
pointers in arrays are no longer passed to userspace (this
was not a security problem, but rather a major issue for
compat32). A new kernel will require a new rndctl.

The sysctl kern.arandom() and kern.urandom() nodes are hooked
up to the new generators, but the /dev/*random pseudodevices
are not, yet.

Manual pages for the new kernel interfaces are forthcoming.
 1.16 12-May-2009  cegger branches: 1.16.12;
struct device * -> device_t, no functional changes intended.
 1.15 28-Apr-2008  matt branches: 1.15.14;
More forgotten changes from matt-armv6.
 1.14 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.13 11-Dec-2005  christos branches: 1.13.46; 1.13.54; 1.13.70; 1.13.72; 1.13.74;
merge ktrace-lwp.
 1.12 04-Feb-2005  perry de-__P
 1.11 29-Apr-2003  scw branches: 1.11.2; 1.11.10; 1.11.12;
Add support for the SMC91C111 chip, with its internal PHY.
 1.10 04-Sep-2002  scw Add a flag, SMC_FLAGS_32BIT_READ, which is settable by the bus-specific
back-end to indicate that the device always sees reads as 32-bit
transactions, even if the host does 8 or 16-bit reads.

This is necessary for the SH-5 "Cayman" on-board ethernet. The SMsC part
is behind an FPGA which maps all cpu reads to 32-bits transactions.
 1.9 30-Jul-2000  briggs branches: 1.9.2; 1.9.4;
Add MII support to smc91cxx driver. This is supported for the 91c100
and 91c100FD (FEAST) controllers. Existing controllers should continue
to work as they have. Added the card's memory to the probe message.
 1.8 29-May-2000  jhawk branches: 1.8.2;
For all network drivers that call ether_ifattach(), and also
have _detach() functions:
Ensure that softc keeps state about whether the attach succeeded,
and make the detach function return immediately if the attach did
not complete.
 1.7 02-Feb-2000  itojun branches: 1.7.2;
if_detach for sm/pcmcia.
with addition of resource allocation flags in softc (to DTRT on detach).
 1.6 18-Nov-1998  thorpej branches: 1.6.10;
Now that the *_activate() functions don't do things which are attachment
specific, move them into the chipset drivers.
 1.5 17-Nov-1998  thorpej Expose the "enable" and "disable" functions so that the front-ends can
access them.
 1.4 15-Oct-1997  explorer Add and/or update rnd_*() hooks
 1.3 14-Oct-1997  thorpej Pull down from marc-pcmcia branch:

Add support for power management.
 1.2 02-Sep-1997  thorpej Pull the SMC91Cxx single-chip Ethernet driver core down from the marc-pcmcia
branch. It is also needed by and ISA front-end.
 1.1 11-Aug-1997  thorpej branches: 1.1.2;
file smc91cxxvar.h was initially added on branch marc-pcmcia.
 1.1.2.3 29-Sep-1997  thorpej Add power management hooks.
 1.1.2.2 24-Aug-1997  thorpej Fix a few annoying bugs:
- Make sure the default media is set up correctly in smc91cxx_init().
- Fix a memory leak in the "resume from memory allocation interrupt" logic.
Acually, completely toss the logic that was in the original driver, and
replace it with a much simpler scheme from Michael Hitch's NetBSD/amiga
"es" driver: Rather than "resuming" the transmission that causes us
to use the memory allocation interrupt, simply free the just-allocated
memory back to the chip's MMU, and use the standard "start" logic, which
will reallocate it from the MMU in a straightforward way.
- Only set IFF_OACTIVE if we can't transmit any more packets (i.e. we
were forced to use the memory allocation interrupt).
 1.1.2.1 11-Aug-1997  thorpej Driver for the SMC91Cxx ethernet chip, found in some ISA and PCMCIA ethernet
interfaces. Some PCI network interfaces also use a variant of this chip
Derived from the FreeBSD "sn" driver, written by Gardener Buchanan.
 1.6.10.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.7.2.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.8.2.1 06-Aug-2000  briggs Pullups approved by thorpej --
Add MII support to smc91cxx driver. This is supported for the 91c100
and 91c100FD (FEAST) controllers. Existing controllers should continue
to work as they have. Added the card's memory to the probe message.

Make sure that we do not call bus_space_*_multi_* with zero count.
Use bus_space_read/write_multi_stream_2 for FIFO instead of bsr/w_multi_2.
 1.9.4.1 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.9.2.1 17-Sep-2002  nathanw Catch up to -current.
 1.11.12.1 12-Feb-2005  yamt sync with head.
 1.11.10.1 29-Apr-2005  kent sync with -current
 1.11.2.1 04-Feb-2005  skrll Sync with HEAD.
 1.13.74.2 16-May-2009  yamt sync with head
 1.13.74.1 16-May-2008  yamt sync with head.
 1.13.72.1 18-May-2008  yamt sync with head.
 1.13.70.1 02-Jun-2008  mjf Sync with HEAD.
 1.13.54.1 10-Nov-2007  matt Add AT91 support from Sami Kantoluoto
Add TI OMAP2430 support from Marty Fouts @ Danger Inc
 1.13.46.1 29-Oct-2007  matt Update to use only word accesses. Fix incorrect padding of odd length
packets. Cache intmask.
 1.15.14.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.16.12.2 30-Oct-2012  yamt sync with head
 1.16.12.1 17-Apr-2012  yamt sync with head
 1.17.2.1 18-Feb-2012  mrg merge to -current.
 1.18.6.2 03-Dec-2017  jdolecek update from HEAD
 1.18.6.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.19.14.1 06-Jun-2015  skrll Sync with HEAD
 1.20.18.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.15 14-Mar-2009  dsl Change about 4500 of the K&R function definitions to ANSI ones.
There are still about 1600 left, but they have ',' or /* ... */
in the actual variable definitions - which my awk script doesn't handle.
There are also many that need () -> (void).
(The script does handle misordered arguments.)
 1.14 19-Oct-2007  ad branches: 1.14.20; 1.14.28; 1.14.34;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.13 29-Jan-2007  hubertf branches: 1.13.6; 1.13.18; 1.13.20; 1.13.24;
Remove more duplicate headers.
Patch by Slava Semushin <slava.semushin@gmail.com>

Again, this was tested by comparing obj files from a pristine and a patched
source tree against an i386/ALL kernel, and also for src/sbin/fsck_ffs,
src/sbin/fsdb and src/usr.sbin/makefs. Only changes in assert() line numbers
were detected in 'objdump -d' output.
 1.12 11-Dec-2005  christos branches: 1.12.20;
merge ktrace-lwp.
 1.11 22-Jun-2005  dyoung branches: 1.11.2;
Resolve conflicts in importation of 18-May-2005 ath(4) / net80211(9)
from FreeBSD. Introduce compatibility shims (sys/dev/ic/ath_netbsd.[ch],
sys/net80211/ieee80211_netbsd.[ch]). Update drivers (an, atu, atw,
awi, ipw, iwi, rtw, wi) for the new net80211(9) API.
 1.10 02-May-2003  dyoung branches: 1.10.2;
Adapt SMC 93cx6 library so that it will work with both 8- and 32-bit
registers. This is so that I can read an SMC 93cx6 through the
32-bit registers of the ADMtek ADM8211 802.11 wireless MAC.

Adapt aic to choose 8-bit registers.
 1.9 13-Nov-2001  lukem add/cleanup RCSID
 1.8 20-Aug-2001  wiz precede, not preceed.
 1.7 30-Apr-2001  lukem branches: 1.7.2;
delint
 1.6 15-Mar-2000  fvdl branches: 1.6.6;
New ahc driver, a port of Justin Gibbs' FreeBSD driver. This adds
support for the U2W chips, and U160 controllers.
 1.5 21-Oct-1996  thorpej branches: 1.5.28;
New bus.h implementation/interface:
- No more distinction between i/o-mapped and memory-mapped
devices. It's all "bus space" now, and space tags
differentiate the space with finer grain than the
bus chipset tag.
- Add memory barrier methods.
- Implement space alloc/free methods.
- Implement region read/write methods (like memcpy to/from
bus space).
This interface provides a better abstraction for dealing with
machine-independent chipset drivers.
 1.4 13-Oct-1996  christos backout kprintf changes
 1.3 10-Oct-1996  christos - printf -> kprintf, sprintf -> ksprintf
 1.2 10-Jul-1996  explorer Updates to aic7xxx driver ; from pr port-i386/2600
 1.1 16-May-1996  mycroft branches: 1.1.4;
New version, with changes from Justin Gibbs and Noriyuki Soda.
 1.1.4.1 18-Jul-1996  jtc Pulled up from rev 1.2, ahc fixes
 1.5.28.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.6.6.3 14-Nov-2001  nathanw Catch up to -current.
 1.6.6.2 24-Aug-2001  nathanw Catch up with -current.
 1.6.6.1 21-Jun-2001  nathanw Catch up to -current.
 1.7.2.2 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.7.2.1 25-Aug-2001  thorpej Merge Aug 24 -current into the kqueue branch.
 1.10.2.1 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.11.2.2 27-Oct-2007  yamt sync with head.
 1.11.2.1 26-Feb-2007  yamt sync with head.
 1.12.20.1 01-Feb-2007  ad Sync with head.
 1.13.24.1 25-Oct-2007  bouyer Sync with HEAD.
 1.13.20.1 06-Nov-2007  matt sync with HEAD
 1.13.18.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.13.6.1 23-Oct-2007  ad Sync with head.
 1.14.34.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.14.28.1 28-Apr-2009  skrll Sync with HEAD.
 1.14.20.1 04-May-2009  yamt sync with head.
 1.9 11-Dec-2005  christos merge ktrace-lwp.
 1.8 22-Jun-2005  dyoung Resolve conflicts in importation of 18-May-2005 ath(4) / net80211(9)
from FreeBSD. Introduce compatibility shims (sys/dev/ic/ath_netbsd.[ch],
sys/net80211/ieee80211_netbsd.[ch]). Update drivers (an, atu, atw,
awi, ipw, iwi, rtw, wi) for the new net80211(9) API.
 1.7 30-May-2005  christos - add missing const
- fix variable shadowing
- remove unneeded casts
 1.6 02-May-2003  dyoung branches: 1.6.2;
Adapt SMC 93cx6 library so that it will work with both 8- and 32-bit
registers. This is so that I can read an SMC 93cx6 through the
32-bit registers of the ADMtek ADM8211 802.11 wireless MAC.

Adapt aic to choose 8-bit registers.
 1.5 15-Mar-2000  fvdl New ahc driver, a port of Justin Gibbs' FreeBSD driver. This adds
support for the U2W chips, and U160 controllers.
 1.4 10-Apr-1997  cgd branches: 1.4.22;
clean these up (mostly rename bus_space_{tag,handle}_t variables) so that
this code makes equal sense for memory and I/O space, prefer to map
the PCI front end via memory space (conditionalized on a patchable kernel
variable), and do a bit of other random NetBSD-specific cleanup. (These
changes were sent to Justin Gibbs on March 28.)
 1.3 21-Oct-1996  thorpej New bus.h implementation/interface:
- No more distinction between i/o-mapped and memory-mapped
devices. It's all "bus space" now, and space tags
differentiate the space with finer grain than the
bus chipset tag.
- Add memory barrier methods.
- Implement space alloc/free methods.
- Implement region read/write methods (like memcpy to/from
bus space).
This interface provides a better abstraction for dealing with
machine-independent chipset drivers.
 1.2 10-Jul-1996  explorer Updates to aic7xxx driver ; from pr port-i386/2600
 1.1 16-May-1996  mycroft branches: 1.1.4;
New version, with changes from Justin Gibbs and Noriyuki Soda.
 1.1.4.1 18-Jul-1996  jtc Pulled up from rev 1.2, ahc fixes
 1.4.22.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.6.2.1 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.38 02-Feb-2022  nakayama Fix misplaced comma.
 1.37 29-Jan-2022  msaitoh Add code for DDR5 a little. I have no datasheet.
 1.36 29-Jan-2022  msaitoh Add LPDDR4X and DDR5. Not decoded yet.
 1.35 24-Mar-2020  msaitoh Calculate DDR3's tRAS correctly.
 1.34 24-Mar-2020  msaitoh - Define some new parameters of DDR3 SPD ROM.
- Use fine timebase parameters for time calculation on DDR3. This change
makes PC3-XXXX vaule more correctly on newer DDR3.
 1.33 24-Mar-2020  msaitoh KNF. No functional change.
 1.32 20-Mar-2020  msaitoh Print DDR3's row and column correctly.
 1.31 07-Apr-2019  pgoyette branches: 1.31.4;
Fix spelling of symeti^Hric
 1.30 27-Dec-2018  msaitoh Print rank on DDR4.
 1.29 26-Dec-2018  msaitoh - Fix DDR4's rows and columns value.
- Print "banks/group" instead of "banks" because it's not the total bank
number.
 1.28 24-Oct-2017  msaitoh branches: 1.28.2; 1.28.4;
Print "ECC" or "no ECC" for DDR4.
 1.27 16-Oct-2017  christos simplify previous.
 1.26 16-Oct-2017  christos dedup
 1.25 16-Oct-2017  msaitoh A part number field of DDR3 and DDR4 is not NUL terminated. All unused chars
are filled by 0x20. Print it correctly.

Before:
spdmem0 at iic0 addr 0x50: 8KTF51264AZ-1G6E1 E1M^@,DPAFEQZ021
spdmem1 at iic0 addr 0x51: ACR256X64D3U1333C9BA^AM^X
spdmem2 at iic0 addr 0x52: KP223C-ELD BA^BM-~

After:
spdmem0 at iic0 addr 0x50: 8KTF51264AZ-1G6E1
spdmem1 at iic0 addr 0x51: ACR256X64D3U1333C9
spdmem2 at iic0 addr 0x52: KP223C-ELD
 1.24 18-Jan-2017  msaitoh branches: 1.24.6;
- Move __DDR4_VALUE()'s comment to the correct position.
- s/ftp/ftb/. No functional change.
 1.23 11-Jan-2017  maya branches: 1.23.2;
fix off by one.

ok riastradh
 1.22 09-Sep-2016  msaitoh Add code to select page "0" for DDR4 and newer SPD ROM. If the value read
is not suitable as SPD ROM, try to select page 0 and try again. The passed
arguments of iic_exec(SPDCTL_SPA) might not be correct and/or our API of
iic_exec() should be improved. See the comment for the detail.

Use this change until we find a better (or correct?) way.
 1.21 05-Jan-2016  msaitoh branches: 1.21.2;
Check whether iic_exec is failed or not.
- This change fixes a bug that a device that the checksum is really 0 fails
attaching.
- Reduce the number of access to one if a device doesn't exist. Without this
change and iic(4) does polling, it'll wait long time.
 1.20 24-Dec-2015  msaitoh - Add DDR4E, LPDDR3 and LPDDR4.
- Check NVDIMM hybrid.
- add DDR4's tWR and tWTR.
- Print cycle time with aprint_verbose on DDR4 as DDR[23].
 1.19 08-Dec-2015  pgoyette Update calculations for DDR4 devices. This gets 1066MHz modules to
report as PC4-17000.

XXX Due to insufficient precision in the SPD ROM data, we still report
XXX these modules with a DDR speed of 2132MHz, not 2133. :( (The
XXX cycle time is really 937.5ps, but is stored in the ROM as 938.0ps)
 1.18 07-Dec-2015  msaitoh Bugfixes
- Calculate cycle_time correctly. _ftb is from +127 to -128.
- Print latency in correct order.
- Don't print the size twice.
- KNF
 1.17 06-Dec-2015  msaitoh KNF.
 1.16 05-Dec-2015  pgoyette Use the DDR4 rows and columns fields when printing DDR4 data
 1.15 05-Dec-2015  msaitoh Calculated CRC is for bytes from 0 to 125 on DDR4. Now we can attach spdmem
driver for DDR4.
 1.14 15-May-2015  msaitoh Print operable voltage with aprint_verbose(). OK'ed by pgoyette@.
 1.13 20-Apr-2015  pgoyette Initial pass at supporting decode for DDR4.

XXX I fully expect that reporting of PC4-xxxxx values is incorrect.
XXX Please report this, or any other errors that you may see.
 1.12 01-Apr-2015  matt Add missing ,
constify the arrays of string pointers.
 1.11 27-Mar-2015  msaitoh Add DDR4 support a bit.
 1.10 14-Apr-2014  pooka branches: 1.10.4;
Remove extraneous sysctl setup calls now done as part of regular attach.
 1.9 25-Feb-2014  pooka branches: 1.9.2;
Ensure that the top level sysctl nodes (kern, vfs, net, ...) exist before
the sysctl link sets are processed, and remove redundancy.

Shaves >13kB off of an amd64 GENERIC, not to mention >1k duplicate
lines of code.
 1.8 19-Jul-2013  soren Print the part number for DDR3 modules.

Also closes PR kern/44665.
 1.7 27-Oct-2012  chs branches: 1.7.2; 1.7.8;
split device_t/softc for all remaining drivers.
replace "struct device *" with "device_t".
use device_xname(), device_unit(), etc.
 1.6 31-May-2012  pgoyette branches: 1.6.2;
Update handling of sysctl stuff when built as modules
 1.5 19-Aug-2011  wiz branches: 1.5.2; 1.5.6;
Remove semicolon at end of #define line to fix build.
 1.4 19-Aug-2011  christos fix non-literal format strings (Paul Goyette)
 1.3 01-Aug-2011  pgoyette Modularize the spdmem(4) driver
 1.2 29-Jun-2010  pgoyette branches: 1.2.2;
Fix logic error in detecting length of DDR3 SPD covered by CRC check.

Reported by Jonathan Gray in private email - thanks!
 1.1 24-Mar-2010  pgoyette branches: 1.1.2; 1.1.4;
Split spdmem driver into a bus attachment and a common back-end
probe and ROM decode, to follow similar changes made in OpenBSD:

http://article.gmane.org/gmane.os.openbsd.cvs/94948
http://article.gmane.org/gmane.os.openbsd.cvs/94956

There exists at least one alternative attachment (for SGI IP35
systems; see http://article.gmane.org/gmane.os.openbsd.cvs/94947),
and there could be more in the future.

Thanks to Christoph Egger for pointing out the OpenBSD activity.
 1.1.4.3 03-Jul-2010  rmind sync with head
 1.1.4.2 30-May-2010  rmind sync with head
 1.1.4.1 24-Mar-2010  rmind file spdmem.c was added on branch rmind-uvmplock on 2010-05-30 05:17:26 +0000
 1.1.2.3 17-Aug-2010  uebayasi Sync with HEAD.
 1.1.2.2 30-Apr-2010  uebayasi Sync with HEAD.
 1.1.2.1 24-Mar-2010  uebayasi file spdmem.c was added on branch uebayasi-xip on 2010-04-30 14:43:23 +0000
 1.2.2.2 11-Aug-2010  yamt sync with head.
 1.2.2.1 29-Jun-2010  yamt file spdmem.c was added on branch yamt-nfs-mp on 2010-08-11 22:53:32 +0000
 1.5.6.1 02-Jun-2012  mrg sync to latest -current.
 1.5.2.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.5.2.1 30-Oct-2012  yamt sync with head
 1.6.2.3 03-Dec-2017  jdolecek update from HEAD
 1.6.2.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.6.2.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.7.8.1 23-Jul-2013  riastradh sync with HEAD
 1.7.2.2 18-May-2014  rmind sync with head
 1.7.2.1 28-Aug-2013  rmind sync with head
 1.9.2.1 10-Aug-2014  tls Rebase.
 1.10.4.6 05-Feb-2017  skrll Sync with HEAD
 1.10.4.5 05-Oct-2016  skrll Sync with HEAD
 1.10.4.4 19-Mar-2016  skrll Sync with HEAD
 1.10.4.3 27-Dec-2015  skrll Sync with HEAD (as of 26th Dec)
 1.10.4.2 06-Jun-2015  skrll Sync with HEAD
 1.10.4.1 06-Apr-2015  skrll Sync with HEAD
 1.21.2.1 20-Mar-2017  pgoyette Sync with HEAD
 1.23.2.1 21-Apr-2017  bouyer Sync with HEAD
 1.24.6.3 14-Apr-2020  martin Pull up following revision(s) (requested by msaitoh in ticket #1528):

sys/dev/ic/spdmemvar.h: revision 1.15
sys/dev/ic/spdmemvar.h: revision 1.16
sys/dev/ic/spdmem.c: revision 1.31
sys/dev/ic/spdmem.c: revision 1.32
sys/dev/ic/spdmem.c: revision 1.33
sys/dev/ic/spdmem.c: revision 1.34
sys/dev/ic/spdmem.c: revision 1.35

Fix spelling of symeti^Hric

Print DDR3's row and column correctly.

KNF. No functional change.

- Define some new parameters of DDR3 SPD ROM.
- Use fine timebase parameters for time calculation on DDR3. This change
makes PC3-XXXX value more correctly on newer DDR3.

Calculate DDR3's tRAS correctly.

Fix unused area size found by pgoyette@.
 1.24.6.2 03-Jan-2019  martin Pull up following revision(s) (requested by msaitoh in ticket #1153):

sys/dev/ic/spdmemvar.h: revision 1.14
sys/dev/ic/spdmem.c: revision 1.30
sys/dev/ic/spdmem.c: revision 1.29

- Fix DDR4's rows and columns value.
- Print "banks/group" instead of "banks" because it's not the total bank
number.

-

Print rank on DDR4.
 1.24.6.1 22-Nov-2017  martin Pull up following revision(s) (requested by msaitoh in ticket #369):
sys/dev/ic/spdmem.c: revision 1.25
sys/dev/ic/spdmem.c: revision 1.26
sys/dev/ic/spdmem.c: revision 1.27
sys/dev/ic/spdmem.c: revision 1.28
A part number field of DDR3 and DDR4 is not NUL terminated. All unused chars
are filled by 0x20. Print it correctly.
Before:
spdmem0 at iic0 addr 0x50: 8KTF51264AZ-1G6E1 E1M^@,DPAFEQZ021
spdmem1 at iic0 addr 0x51: ACR256X64D3U1333C9BA^AM^X
spdmem2 at iic0 addr 0x52: KP223C-ELD BA^BM-~
After:
spdmem0 at iic0 addr 0x50: 8KTF51264AZ-1G6E1
spdmem1 at iic0 addr 0x51: ACR256X64D3U1333C9
spdmem2 at iic0 addr 0x52: KP223C-ELD
dedup
simplify previous.
Print "ECC" or "no ECC" for DDR4.
 1.28.4.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.28.4.1 10-Jun-2019  christos Sync with HEAD
 1.28.2.1 18-Jan-2019  pgoyette Synch with HEAD
 1.31.4.1 14-Apr-2020  martin Pull up following revision(s) (requested by msaitoh in ticket #832):

sys/dev/ic/spdmemvar.h: revision 1.15
sys/dev/ic/spdmemvar.h: revision 1.16
sys/dev/ic/spdmem.c: revision 1.32
sys/dev/ic/spdmem.c: revision 1.33
sys/dev/ic/spdmem.c: revision 1.34
sys/dev/ic/spdmem.c: revision 1.35

Print DDR3's row and column correctly.

KNF. No functional change.

- Define some new parameters of DDR3 SPD ROM.
- Use fine timebase parameters for time calculation on DDR3. This change
makes PC3-XXXX value more correctly on newer DDR3.

Calculate DDR3's tRAS correctly.

Fix unused area size found by pgoyette@.
 1.5 29-Jan-2022  msaitoh Add LPDDR4X and DDR5. Not decoded yet.
 1.4 24-Dec-2015  msaitoh - Add DDR4E, LPDDR3 and LPDDR4.
- Check NVDIMM hybrid.
- add DDR4's tWR and tWTR.
- Print cycle time with aprint_verbose on DDR4 as DDR[23].
 1.3 20-Apr-2015  pgoyette Initial pass at supporting decode for DDR4.

XXX I fully expect that reporting of PC4-xxxxx values is incorrect.
XXX Please report this, or any other errors that you may see.
 1.2 27-Mar-2015  msaitoh Add DDR4 support a bit.
 1.1 24-Mar-2010  pgoyette branches: 1.1.2; 1.1.4; 1.1.6; 1.1.24; 1.1.42;
Split spdmem driver into a bus attachment and a common back-end
probe and ROM decode, to follow similar changes made in OpenBSD:

http://article.gmane.org/gmane.os.openbsd.cvs/94948
http://article.gmane.org/gmane.os.openbsd.cvs/94956

There exists at least one alternative attachment (for SGI IP35
systems; see http://article.gmane.org/gmane.os.openbsd.cvs/94947),
and there could be more in the future.

Thanks to Christoph Egger for pointing out the OpenBSD activity.
 1.1.42.3 27-Dec-2015  skrll Sync with HEAD (as of 26th Dec)
 1.1.42.2 06-Jun-2015  skrll Sync with HEAD
 1.1.42.1 06-Apr-2015  skrll Sync with HEAD
 1.1.24.1 03-Dec-2017  jdolecek update from HEAD
 1.1.6.2 11-Aug-2010  yamt sync with head.
 1.1.6.1 24-Mar-2010  yamt file spdmemreg.h was added on branch yamt-nfs-mp on 2010-08-11 22:53:32 +0000
 1.1.4.2 30-May-2010  rmind sync with head
 1.1.4.1 24-Mar-2010  rmind file spdmemreg.h was added on branch rmind-uvmplock on 2010-05-30 05:17:26 +0000
 1.1.2.2 30-Apr-2010  uebayasi Sync with HEAD.
 1.1.2.1 24-Mar-2010  uebayasi file spdmemreg.h was added on branch uebayasi-xip on 2010-04-30 14:43:23 +0000
 1.16 24-Mar-2020  msaitoh Fix unused area size found by pgoyette@.
 1.15 24-Mar-2020  msaitoh - Define some new parameters of DDR3 SPD ROM.
- Use fine timebase parameters for time calculation on DDR3. This change
makes PC3-XXXX vaule more correctly on newer DDR3.
 1.14 27-Dec-2018  msaitoh branches: 1.14.4;
Print rank on DDR4.
 1.13 18-Jan-2017  msaitoh branches: 1.13.6; 1.13.12; 1.13.14;
- Move __DDR4_VALUE()'s comment to the correct position.
- s/ftp/ftb/. No functional change.
 1.12 05-Sep-2016  msaitoh branches: 1.12.2;
Fix the first two bytes' definitions of the DDR3 SPD ROM. This was not a real
bug because the definitions haven't used. From JEDEC Standard No. 21-C Annex K:
Serial Presense Detect (SPD) for DDR3 SDRAM Modules Document Release 6.
 1.11 05-Jan-2016  msaitoh branches: 1.11.2;
Check whether iic_exec is failed or not.
- This change fixes a bug that a device that the checksum is really 0 fails
attaching.
- Reduce the number of access to one if a device doesn't exist. Without this
change and iic(4) does polling, it'll wait long time.
 1.10 24-Dec-2015  msaitoh - Add DDR4E, LPDDR3 and LPDDR4.
- Check NVDIMM hybrid.
- add DDR4's tWR and tWTR.
- Print cycle time with aprint_verbose on DDR4 as DDR[23].
 1.9 07-Dec-2015  mlelstv Handle reading of 4kbit EEPROMs in SPD devices. This is needed for DDR4 DIMMs.
 1.8 06-Dec-2015  msaitoh Fix the definition of DDR4's tFAW (offset 0x24).
 1.7 15-May-2015  msaitoh Print operable voltage with aprint_verbose(). OK'ed by pgoyette@.
 1.6 20-Apr-2015  ozaki-r Unbreak the build of spdmem

- Get rid of a tab after backslace
- Add a missing semicolon

From Henning Petersen
 1.5 20-Apr-2015  pgoyette Initial pass at supporting decode for DDR4.

XXX I fully expect that reporting of PC4-xxxxx values is incorrect.
XXX Please report this, or any other errors that you may see.
 1.4 18-Mar-2014  riastradh branches: 1.4.6;
Merge riastradh-drm2 to HEAD.
 1.3 19-Jul-2013  soren Print the part number for DDR3 modules.

Also closes PR kern/44665.
 1.2 01-Aug-2011  pgoyette branches: 1.2.2; 1.2.12; 1.2.16; 1.2.24;
Modularize the spdmem(4) driver
 1.1 24-Mar-2010  pgoyette branches: 1.1.2; 1.1.4; 1.1.6;
Split spdmem driver into a bus attachment and a common back-end
probe and ROM decode, to follow similar changes made in OpenBSD:

http://article.gmane.org/gmane.os.openbsd.cvs/94948
http://article.gmane.org/gmane.os.openbsd.cvs/94956

There exists at least one alternative attachment (for SGI IP35
systems; see http://article.gmane.org/gmane.os.openbsd.cvs/94947),
and there could be more in the future.

Thanks to Christoph Egger for pointing out the OpenBSD activity.
 1.1.6.2 11-Aug-2010  yamt sync with head.
 1.1.6.1 24-Mar-2010  yamt file spdmemvar.h was added on branch yamt-nfs-mp on 2010-08-11 22:53:32 +0000
 1.1.4.2 30-May-2010  rmind sync with head
 1.1.4.1 24-Mar-2010  rmind file spdmemvar.h was added on branch rmind-uvmplock on 2010-05-30 05:17:26 +0000
 1.1.2.2 30-Apr-2010  uebayasi Sync with HEAD.
 1.1.2.1 24-Mar-2010  uebayasi file spdmemvar.h was added on branch uebayasi-xip on 2010-04-30 14:43:23 +0000
 1.2.24.1 23-Jul-2013  riastradh sync with HEAD
 1.2.16.1 28-Aug-2013  rmind sync with head
 1.2.12.2 03-Dec-2017  jdolecek update from HEAD
 1.2.12.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.2.2.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.4.6.5 05-Feb-2017  skrll Sync with HEAD
 1.4.6.4 05-Oct-2016  skrll Sync with HEAD
 1.4.6.3 19-Mar-2016  skrll Sync with HEAD
 1.4.6.2 27-Dec-2015  skrll Sync with HEAD (as of 26th Dec)
 1.4.6.1 06-Jun-2015  skrll Sync with HEAD
 1.11.2.1 20-Mar-2017  pgoyette Sync with HEAD
 1.12.2.1 21-Apr-2017  bouyer Sync with HEAD
 1.13.14.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.13.14.1 10-Jun-2019  christos Sync with HEAD
 1.13.12.1 18-Jan-2019  pgoyette Synch with HEAD
 1.13.6.2 14-Apr-2020  martin Pull up following revision(s) (requested by msaitoh in ticket #1528):

sys/dev/ic/spdmemvar.h: revision 1.15
sys/dev/ic/spdmemvar.h: revision 1.16
sys/dev/ic/spdmem.c: revision 1.31
sys/dev/ic/spdmem.c: revision 1.32
sys/dev/ic/spdmem.c: revision 1.33
sys/dev/ic/spdmem.c: revision 1.34
sys/dev/ic/spdmem.c: revision 1.35

Fix spelling of symeti^Hric

Print DDR3's row and column correctly.

KNF. No functional change.

- Define some new parameters of DDR3 SPD ROM.
- Use fine timebase parameters for time calculation on DDR3. This change
makes PC3-XXXX value more correctly on newer DDR3.

Calculate DDR3's tRAS correctly.

Fix unused area size found by pgoyette@.
 1.13.6.1 03-Jan-2019  martin Pull up following revision(s) (requested by msaitoh in ticket #1153):

sys/dev/ic/spdmemvar.h: revision 1.14
sys/dev/ic/spdmem.c: revision 1.30
sys/dev/ic/spdmem.c: revision 1.29

- Fix DDR4's rows and columns value.
- Print "banks/group" instead of "banks" because it's not the total bank
number.

-

Print rank on DDR4.
 1.14.4.1 14-Apr-2020  martin Pull up following revision(s) (requested by msaitoh in ticket #832):

sys/dev/ic/spdmemvar.h: revision 1.15
sys/dev/ic/spdmemvar.h: revision 1.16
sys/dev/ic/spdmem.c: revision 1.32
sys/dev/ic/spdmem.c: revision 1.33
sys/dev/ic/spdmem.c: revision 1.34
sys/dev/ic/spdmem.c: revision 1.35

Print DDR3's row and column correctly.

KNF. No functional change.

- Define some new parameters of DDR3 SPD ROM.
- Use fine timebase parameters for time calculation on DDR3. This change
makes PC3-XXXX value more correctly on newer DDR3.

Calculate DDR3's tRAS correctly.

Fix unused area size found by pgoyette@.
 1.22 10-Apr-2022  andvar fix various typos in comments and output/log messages.
 1.21 07-Aug-2021  thorpej Merge thorpej-cfargs2.
 1.20 24-Apr-2021  thorpej branches: 1.20.8;
Merge thorpej-cfargs branch:

Simplify and make extensible the config_search() / config_found() /
config_attach() interfaces: rather than having different variants for
which arguments you want pass along, just have a single call that
takes a variadic list of tag-value arguments.

Adjust all call sites:
- Simplify wherever possible; don't pass along arguments that aren't
actually needed.
- Don't be explicit about what interface attribute is attaching if
the device only has one. (More simplification.)
- Add a config_probe() function to be used in indirect configuiration
situations, making is visibly easier to see when indirect config is
in play, and allowing for future change in semantics. (As of now,
this is just a wrapper around config_match(), but that is an
implementation detail.)

Remove unnecessary or redundant interface attributes where they're not
needed.

There are currently 5 "cfargs" defined:
- CFARG_SUBMATCH (submatch function for direct config)
- CFARG_SEARCH (search function for indirect config)
- CFARG_IATTR (interface attribte)
- CFARG_LOCATORS (locators array)
- CFARG_DEVHANDLE (devhandle_t - wraps OFW, ACPI, etc. handles)

...and a sentinel value CFARG_EOL.

Add some extra sanity checking to ensure that interface attributes
aren't ambiguous.

Use CFARG_DEVHANDLE in MI FDT, OFW, and ACPI code, and macppc and shark
ports to associate those device handles with device_t instance. This
will trickle trough to more places over time (need back-end for pre-OFW
Sun OBP; any others?).
 1.19 17-Oct-2013  christos branches: 1.19.46;
- remove unused variables
- move variables inside ifdef sections
- ifdef notdef unused code
- use __USE for debugging variables
 1.18 21-Apr-2010  dyoung branches: 1.18.8; 1.18.18; 1.18.22;
Don't printf bus_space_tag_t's in a MI driver.
 1.17 24-Feb-2010  dyoung branches: 1.17.2;
A pointer typedef entails trading too much flexibility to declare const
and non-const types, and the kernel uses both const and non-const
PMF qualifiers and device suspensors, so change the pmf_qual_t and
device_suspensor_t typedefs from "pointers to const" to non-pointer,
non-const types.
 1.16 08-Jan-2010  dyoung branches: 1.16.2;
Expand PMF_FN_* macros.
 1.15 04-May-2008  xtraeme device_t/softc split for spic(4) and other related cosmetic changes.
 1.14 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.13 08-Apr-2008  cegger branches: 1.13.2; 1.13.4;
use aprint_*_dev and device_xname
 1.12 29-Feb-2008  dyoung Use PMF_FN_ARGS, PMF_FN_PROTO.
 1.11 17-Dec-2007  christos branches: 1.11.2; 1.11.6;
from jmcneill: suspend and resume handlers for spic.
 1.10 09-Dec-2007  jmcneill branches: 1.10.2;
Merge jmcneill-pm branch.
 1.9 19-Oct-2007  ad branches: 1.9.4; 1.9.6;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.8 09-Jul-2007  ad branches: 1.8.6; 1.8.8; 1.8.12;
Merge some of the less invasive changes from the vmlocking branch:

- kthread, callout, devsw API changes
- select()/poll() improvements
- miscellaneous MT safety improvements
 1.7 04-Mar-2007  christos branches: 1.7.2; 1.7.4;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.6 16-Nov-2006  christos branches: 1.6.4;
__unused removal on arguments; approved by core.
 1.5 12-Nov-2006  plunky Tidy away wsmouse_input() abstractions and update
documentation to include the W direction.
 1.4 12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.3 20-Jun-2006  jmcneill branches: 1.3.4; 1.3.6;
Hook the lid switch, sleep button, and hibernate button into sysmon. This
enables special Fn keys on Sony Vaio laptops.
 1.2 12-Dec-2005  christos branches: 1.2.4; 1.2.8; 1.2.16;
more proc -> lwp
 1.1 22-Apr-2002  augustss branches: 1.1.6; 1.1.8; 1.1.30;
Add a driver for the Sony SPIC that handles jog dials etc.
This driver works on my SRX77, but probably little else.
It makes the jog dial appear as a wsmouse.
 1.1.30.6 17-Mar-2008  yamt sync with head.
 1.1.30.5 21-Jan-2008  yamt sync with head
 1.1.30.4 27-Oct-2007  yamt sync with head.
 1.1.30.3 03-Sep-2007  yamt sync with head.
 1.1.30.2 30-Dec-2006  yamt sync with head.
 1.1.30.1 21-Jun-2006  yamt sync with head.
 1.1.8.2 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.1.8.1 22-Apr-2002  jdolecek file spic.c was added on branch kqueue on 2002-06-23 17:46:51 +0000
 1.1.6.2 20-Jun-2002  nathanw Catch up to -current.
 1.1.6.1 22-Apr-2002  nathanw file spic.c was added on branch nathanw_sa on 2002-06-20 03:45:03 +0000
 1.2.16.1 13-Jul-2006  gdamore Merge from HEAD.
 1.2.8.1 26-Jun-2006  yamt sync with head.
 1.2.4.1 09-Sep-2006  rpaulo sync with head
 1.3.6.2 10-Dec-2006  yamt sync with head.
 1.3.6.1 22-Oct-2006  yamt sync with head
 1.3.4.1 18-Nov-2006  ad Sync with head.
 1.6.4.1 12-Mar-2007  rmind Sync with HEAD.
 1.7.4.1 11-Jul-2007  mjf Sync with head.
 1.7.2.2 23-Oct-2007  ad Sync with head.
 1.7.2.1 01-Jul-2007  ad Adapt to callout API change.
 1.8.12.1 25-Oct-2007  bouyer Sync with HEAD.
 1.8.8.3 23-Mar-2008  matt sync with HEAD
 1.8.8.2 09-Jan-2008  matt sync with HEAD
 1.8.8.1 06-Nov-2007  matt sync with HEAD
 1.8.6.4 08-Dec-2007  jmcneill Rename pnp(9) -> pmf(9), as requested by many.
 1.8.6.3 06-Nov-2007  joerg Refactor PNP API:
- Make suspend/resume directly a device functionality. It consists of
three layers (class logic, device logic, bus logic), all of them being
optional. This replaces D0/D3 transitions.
- device_is_active returns true if the device was not disabled and was
not suspended (even partially), device_is_enabled returns true if the
device was enabled.
- Change pnp_global_transition into pnp_system_suspend and
pnp_system_resume. Before running any suspend/resume handlers, check
that all currently attached devices support power management and bail
out otherwise. The latter is not done for the shutdown/panic case.
- Make the former bus-specific generic network handlers a class handler.
- Make PNP message like volume up/down/toogle PNP events. Each device
can register what events they are interested in and whether the handler
should be global or not.
- Introduce device_active API for devices to mark themselve in use from
either the system or the device. Use this to implement the idle handling
for audio and input devices. This is intended to replace most ad-hoc
watchdogs as well.
- Fix somes situations in which audio resume would lose mixer settings.
- Make USB host controllers better deal with suspend in the light of
shared interrupts.
- Flush filesystem cache on suspend.
- Flush disk caches on suspend. Put ATA disks into standby on suspend as
well.
- Adopt drivers to use the new PNP API.
- Fix a critical bug in the generic cardbus layer that made D0->D3
break.
- Fix ral(4) to set if_stop.
- Convert cbb(4) to the new PNP API.
- Apply the PCI Express SCI fix on resume again.
 1.8.6.2 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.8.6.1 09-Sep-2007  christos Patch from jmcneill to make the brightness buttons work on my sony vgn-t250p.
 1.9.6.1 11-Dec-2007  yamt sync with head.
 1.9.4.1 26-Dec-2007  ad Sync with head.
 1.10.2.1 02-Jan-2008  bouyer Sync with HEAD
 1.11.6.2 02-Jun-2008  mjf Sync with HEAD.
 1.11.6.1 03-Apr-2008  mjf Sync with HEAD.
 1.11.2.1 24-Mar-2008  keiichi sync with head.
 1.13.4.3 11-Aug-2010  yamt sync with head.
 1.13.4.2 11-Mar-2010  yamt sync with head
 1.13.4.1 16-May-2008  yamt sync with head.
 1.13.2.1 18-May-2008  yamt sync with head.
 1.16.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.17.2.1 30-May-2010  rmind sync with head
 1.18.22.1 18-May-2014  rmind sync with head
 1.18.18.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.18.8.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.19.46.1 21-Mar-2021  thorpej Give config_found() the same variadic arguments treatment as
config_search(). This commit only adds the CFARG_EOL sentinel
to the existing config_found() calls. Conversion of config_found_sm_loc()
and config_found_ia() call sites will be in subsequent commits.
 1.20.8.1 04-Aug-2021  thorpej Adapt to CFARGS().
 1.9 10-Apr-2022  andvar fix various typos in comments and output/log messages.
 1.8 27-Jun-2016  pgoyette Add license, copied from the companion file dev/ic/spic.c

Addresses PR kern/25173 (the $NetBSD$ had previously been added in
rev 1.7 by dyoung)
 1.7 24-Feb-2010  dyoung branches: 1.7.20; 1.7.38;
A pointer typedef entails trading too much flexibility to declare const
and non-const types, and the kernel uses both const and non-const
PMF qualifiers and device suspensors, so change the pmf_qual_t and
device_suspensor_t typedefs from "pointers to const" to non-pointer,
non-const types.
 1.6 08-Jan-2010  dyoung branches: 1.6.2;
Expand PMF_FN_* macros.
 1.5 04-May-2008  xtraeme device_t/softc split for spic(4) and other related cosmetic changes.
 1.4 29-Feb-2008  dyoung branches: 1.4.2; 1.4.4;
Use PMF_FN_ARGS, PMF_FN_PROTO.
 1.3 17-Dec-2007  christos branches: 1.3.2; 1.3.6;
from jmcneill: suspend and resume handlers for spic.
 1.2 20-Jun-2006  jmcneill branches: 1.2.30; 1.2.40; 1.2.44;
Hook the lid switch, sleep button, and hibernate button into sysmon. This
enables special Fn keys on Sony Vaio laptops.
 1.1 22-Apr-2002  augustss branches: 1.1.6; 1.1.8; 1.1.30; 1.1.44; 1.1.48; 1.1.56;
Add a driver for the Sony SPIC that handles jog dials etc.
This driver works on my SRX77, but probably little else.
It makes the jog dial appear as a wsmouse.
 1.1.56.1 13-Jul-2006  gdamore Merge from HEAD.
 1.1.48.1 26-Jun-2006  yamt sync with head.
 1.1.44.1 09-Sep-2006  rpaulo sync with head
 1.1.30.3 17-Mar-2008  yamt sync with head.
 1.1.30.2 21-Jan-2008  yamt sync with head
 1.1.30.1 21-Jun-2006  yamt sync with head.
 1.1.8.2 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.1.8.1 22-Apr-2002  jdolecek file spicvar.h was added on branch kqueue on 2002-06-23 17:46:52 +0000
 1.1.6.2 20-Jun-2002  nathanw Catch up to -current.
 1.1.6.1 22-Apr-2002  nathanw file spicvar.h was added on branch nathanw_sa on 2002-06-20 03:45:03 +0000
 1.2.44.1 02-Jan-2008  bouyer Sync with HEAD
 1.2.40.1 26-Dec-2007  ad Sync with head.
 1.2.30.2 23-Mar-2008  matt sync with HEAD
 1.2.30.1 09-Jan-2008  matt sync with HEAD
 1.3.6.2 02-Jun-2008  mjf Sync with HEAD.
 1.3.6.1 03-Apr-2008  mjf Sync with HEAD.
 1.3.2.1 24-Mar-2008  keiichi sync with head.
 1.4.4.2 11-Mar-2010  yamt sync with head
 1.4.4.1 16-May-2008  yamt sync with head.
 1.4.2.1 18-May-2008  yamt sync with head.
 1.6.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.7.38.1 09-Jul-2016  skrll Sync with HEAD
 1.7.20.1 03-Dec-2017  jdolecek update from HEAD
 1.22 21-Aug-2021  tnn ssdfb: add missing break in switch. Unbreaks contrast setting for SSD1353

spotted by hannken@
 1.21 07-Aug-2021  thorpej Merge thorpej-cfargs2.
 1.20 06-Aug-2021  tnn conditionally put back the include of <uvm/uvm_page.h>

This is a kludge to fix the build on some ports. According to pmap(9),
including <uvm/uvm_extern.h> should be sufficient to use
"bool pmap_is_modified(struct vm_page *pg)". However, on several ports,
the function is implemented as a macro and depends on implementation
details of "struct vm_page *", which is normally an incomplete forward
declaration only. XXX revert when all ports are fixed.
 1.19 05-Aug-2021  tnn ssdfb: revert rev 1.14

Can't run the worker thread MPSAFE with spi(4) yet because most controller
drivers still lack MP safety. Cause issues when using multiple displays.
 1.18 05-Aug-2021  tnn ssdfb: support the SSD1353 controller and the DEP 160128A(1)-RGB display

DEP 160128A is a 160x128 18-bit RGB OLED display module advertised as
having an 8-bit parallel I/O interface. The controller can however attach
serially via spi(4) by moving jumper resistors J1 and J2 to GND position.
 1.17 05-Aug-2021  tnn ssdfb: prepare for supporting rgb color displays
 1.16 05-Aug-2021  tnn ssdfb: make it work on big-endian
 1.15 02-Aug-2021  tnn ssdfb: define SSD1353 command set

also adjust some SSD1322 command names
 1.14 30-Jul-2021  tnn branches: 1.14.2;
ssdfb(4): remove code for dealing with non-MPSAFE attachment

spi(4) was marked MPSAFE some time ago, so we're always on an
MPSAFE parent device.
 1.13 24-Apr-2021  thorpej branches: 1.13.2;
Merge thorpej-cfargs branch:

Simplify and make extensible the config_search() / config_found() /
config_attach() interfaces: rather than having different variants for
which arguments you want pass along, just have a single call that
takes a variadic list of tag-value arguments.

Adjust all call sites:
- Simplify wherever possible; don't pass along arguments that aren't
actually needed.
- Don't be explicit about what interface attribute is attaching if
the device only has one. (More simplification.)
- Add a config_probe() function to be used in indirect configuiration
situations, making is visibly easier to see when indirect config is
in play, and allowing for future change in semantics. (As of now,
this is just a wrapper around config_match(), but that is an
implementation detail.)

Remove unnecessary or redundant interface attributes where they're not
needed.

There are currently 5 "cfargs" defined:
- CFARG_SUBMATCH (submatch function for direct config)
- CFARG_SEARCH (search function for indirect config)
- CFARG_IATTR (interface attribte)
- CFARG_LOCATORS (locators array)
- CFARG_DEVHANDLE (devhandle_t - wraps OFW, ACPI, etc. handles)

...and a sentinel value CFARG_EOL.

Add some extra sanity checking to ensure that interface attributes
aren't ambiguous.

Use CFARG_DEVHANDLE in MI FDT, OFW, and ACPI code, and macppc and shark
ports to associate those device handles with device_t instance. This
will trickle trough to more places over time (need back-end for pre-OFW
Sun OBP; any others?).
 1.12 05-Sep-2020  riastradh branches: 1.12.4;
Round of uvm.h cleanup.

The poorly named uvm.h is generally supposed to be for uvm-internal
users only.

- Narrow it to files that actually need it -- mostly files that need
to query whether curlwp is the pagedaemon, which should maybe be
exposed by an external header.

- Use uvm_extern.h where feasible and uvm_*.h for things not exposed
by it. We should split up uvm_extern.h but this will serve for now
to reduce the uvm.h dependencies.

- Use uvm_stat.h and #ifdef UVMHIST uvm.h for files that use
UVMHIST(ubchist), since ubchist is declared in uvm.h but the
reference evaporates if UVMHIST is not defined, so we reduce header
file dependencies.

- Make uvm_device.h and uvm_swap.h independently includable while
here.

ok chs@
 1.11 23-Feb-2020  ad UVM locking changes, proposed on tech-kern:

- Change the lock on uvm_object, vm_amap and vm_anon to be a RW lock.
- Break v_interlock and vmobjlock apart. v_interlock remains a mutex.
- Do partial PV list locking in the x86 pmap. Others to follow later.
 1.10 02-Nov-2019  tnn branches: 1.10.2;
fix hang when SSDFB_ATTACH_FLAG_CONSOLE used with spi
 1.9 02-Nov-2019  tnn ssdfb: add support for SSD1322
 1.8 22-Oct-2019  tnn allow to have a per-product init function
 1.7 22-Oct-2019  tnn use __SHIFTIN
 1.6 05-Jun-2019  tnn branches: 1.6.2;
add missing kthread_exit
 1.5 04-Jun-2019  tnn revert previous as suggested by mrg IPL_SCHED is correct here
 1.4 30-May-2019  tnn - include uvm.h before uvm_device.h
- don't need IPL_SCHED here
 1.3 17-Mar-2019  tnn ensure the device's UVM pager object is present before using uvm_pageratop
 1.2 17-Mar-2019  tnn formatting
 1.1 17-Mar-2019  tnn add ssdfb

The ssdfb driver provides wsdisplay(4) support for OLED/PLED framebuffer
modules based on one of the following controller chips:

- Solomon Systech Ltd SSD1306
- Sino Wealth Electronic Ltd SH1106

It supports xf86-video-wsfb and can optionally attach as the console.

Some products that should work with this driver include:
- Adafruit 0.96" 128x64 OLED graphic display
- Adafruit 1.3" 128x64 OLED graphic display
- Adafruit 128x32 OLED graphic display
- Adafruit PiOLED 128x32 Monochome OLED for Raspberry Pi
- "GM009605" commonly distributed with Arduino starter kits
- display modules made by Chengdu Heltec Automation technology co. LTD

Note: I used the name ssdfb(4) because that's what OpenBSD calls their
driver but the implementation is entirely unique to NetBSD.
 1.6.2.4 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.6.2.3 08-Apr-2020  martin Merge changes from current as of 20200406
 1.6.2.2 10-Jun-2019  christos Sync with HEAD
 1.6.2.1 05-Jun-2019  christos file ssdfb.c was added on branch phil-wifi on 2019-06-10 22:07:11 +0000
 1.10.2.1 29-Feb-2020  ad Sync with head.
 1.12.4.1 21-Mar-2021  thorpej Give config_found() the same variadic arguments treatment as
config_search(). This commit only adds the CFARG_EOL sentinel
to the existing config_found() calls. Conversion of config_found_sm_loc()
and config_found_ia() call sites will be in subsequent commits.
 1.13.2.1 01-Aug-2021  thorpej Sync with HEAD.
 1.14.2.1 04-Aug-2021  thorpej Adapt to CFARGS().
 1.10 05-Aug-2021  tnn ssdfb: revert rev 1.14

Can't run the worker thread MPSAFE with spi(4) yet because most controller
drivers still lack MP safety. Cause issues when using multiple displays.
 1.9 05-Aug-2021  tnn ssdfb: support the SSD1353 controller and the DEP 160128A(1)-RGB display

DEP 160128A is a 160x128 18-bit RGB OLED display module advertised as
having an 8-bit parallel I/O interface. The controller can however attach
serially via spi(4) by moving jumper resistors J1 and J2 to GND position.
 1.8 05-Aug-2021  tnn ssdfb: prepare for supporting rgb color displays
 1.7 02-Aug-2021  tnn ssdfb: define SSD1353 command set

also adjust some SSD1322 command names
 1.6 30-Jul-2021  tnn ssdfb(4): remove code for dealing with non-MPSAFE attachment

spi(4) was marked MPSAFE some time ago, so we're always on an
MPSAFE parent device.
 1.5 02-Nov-2019  tnn branches: 1.5.12;
ssdfb: add support for SSD1322
 1.4 22-Oct-2019  tnn allow to have a per-product init function
 1.3 22-Oct-2019  tnn define SSD1322 command set
 1.2 17-Mar-2019  tnn branches: 1.2.4;
ensure the device's UVM pager object is present before using uvm_pageratop
 1.1 17-Mar-2019  tnn add ssdfb

The ssdfb driver provides wsdisplay(4) support for OLED/PLED framebuffer
modules based on one of the following controller chips:

- Solomon Systech Ltd SSD1306
- Sino Wealth Electronic Ltd SH1106

It supports xf86-video-wsfb and can optionally attach as the console.

Some products that should work with this driver include:
- Adafruit 0.96" 128x64 OLED graphic display
- Adafruit 1.3" 128x64 OLED graphic display
- Adafruit 128x32 OLED graphic display
- Adafruit PiOLED 128x32 Monochome OLED for Raspberry Pi
- "GM009605" commonly distributed with Arduino starter kits
- display modules made by Chengdu Heltec Automation technology co. LTD

Note: I used the name ssdfb(4) because that's what OpenBSD calls their
driver but the implementation is entirely unique to NetBSD.
 1.2.4.3 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.2.4.2 10-Jun-2019  christos Sync with HEAD
 1.2.4.1 17-Mar-2019  christos file ssdfbvar.h was added on branch phil-wifi on 2019-06-10 22:07:11 +0000
 1.5.12.1 01-Aug-2021  thorpej Sync with HEAD.
 1.4 06-Oct-2022  riastradh com(4): Add include guards.
 1.3 11-Dec-2005  christos merge ktrace-lwp.
 1.2 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22364, verified by myself.
 1.1 19-Oct-1997  fvdl branches: 1.1.50;
Add 16650 hardware flowcontrol support. Basically PR 3844 from
Dave Huang <khym@bga.com>, with added check for broken early versions
of the 16650, taken from the Linux driver.

This should be extended to use, for example, higher trigger levels for
the bigger 16650 FIFO, and its capability for using a smaller divisor
and thus higher speeds. But this patch is very useful for 16650 users
already.
 1.1.50.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.1.50.2 18-Sep-2004  skrll Sync with HEAD.
 1.1.50.1 03-Aug-2004  skrll Sync with HEAD
 1.47 30-May-2025  tsutsui Fix indent.
 1.46 30-May-2025  tsutsui Use fixed STI_PGSHIFT to calculate region info stored in the sti(4) ROM.

The length and offset values in the ROM assume 4KB/page.
Now sti(4) works with 8KB/page (PGSHIFT == 13) settings on hp300.
 1.45 29-May-2025  tsutsui Fix silent panic when STIDEBUG is defined and sti(4) is console.
 1.44 25-May-2025  tsutsui No need to setup board specific routines for hp300 specific EVRX variants.

They are handled in MD sys/arch/hp300/dev/sti_machdep.c later.
 1.43 10-Dec-2024  macallan un-static the unicode-to-HP Roman8 table so we can use it wlsewhere - whatever
uses it will depend on STI anyway, so no need for multiple copies
 1.42 06-Dec-2024  macallan add *very* experimental FB support for Visualize FX 5/10
needs testing
 1.41 06-Dec-2024  macallan more Visualize FX stuff:
- magic number reduction
- set VRAM read mode so X now works without shadowfb
 1.40 20-Nov-2024  macallan add fb / cmap support for Summit family, aka FX2/4/6
 1.39 19-Aug-2024  skrll Whitespace fixes
 1.38 19-Aug-2024  macallan add an ioctl() to read a device's graphics ID, mimic HP/UX's GCID
that way an xorg driver can identify which WSDISPLAY_TYPE_STI it's talking to
without having to setup its own STI
 1.37 03-Jul-2024  macallan fix HXRC colour map handling
With this we can run X in 8bit with correct colours.
 1.36 25-Jun-2024  macallan branches: 1.36.2;
first step to HCRX support
this gets us an 8bit framebuffer with wrong colours, as opposed to X just
erroring out
 1.35 13-Feb-2024  macallan in sti_screen_setup() don't bother looking for fonts if STI_FBMODE is requested
 1.34 01-Feb-2024  skrll Trailing whitespace
 1.33 01-Feb-2024  gutteridge sti.c: fix a typo in a comment
 1.32 31-Jan-2024  macallan Make this work properly on PCI Visualize EG:
- use bus_space_*_stream() for all register accesses in order to avoid
byte order conversion on PCI devices
- when switching to framebuffer mode, request as many text planes as STI allows
- request access to both text and non-text planes in fb mode
With this and the bus_space commit a few days ago I have usable X on my C360
and a PCI Visualize EG.
This needs testing on quite literally everything else.
 1.31 07-Aug-2021  thorpej branches: 1.31.6;
Merge thorpej-cfargs2.
 1.30 24-Apr-2021  thorpej branches: 1.30.8;
Merge thorpej-cfargs branch:

Simplify and make extensible the config_search() / config_found() /
config_attach() interfaces: rather than having different variants for
which arguments you want pass along, just have a single call that
takes a variadic list of tag-value arguments.

Adjust all call sites:
- Simplify wherever possible; don't pass along arguments that aren't
actually needed.
- Don't be explicit about what interface attribute is attaching if
the device only has one. (More simplification.)
- Add a config_probe() function to be used in indirect configuiration
situations, making is visibly easier to see when indirect config is
in play, and allowing for future change in semantics. (As of now,
this is just a wrapper around config_match(), but that is an
implementation detail.)

Remove unnecessary or redundant interface attributes where they're not
needed.

There are currently 5 "cfargs" defined:
- CFARG_SUBMATCH (submatch function for direct config)
- CFARG_SEARCH (search function for indirect config)
- CFARG_IATTR (interface attribte)
- CFARG_LOCATORS (locators array)
- CFARG_DEVHANDLE (devhandle_t - wraps OFW, ACPI, etc. handles)

...and a sentinel value CFARG_EOL.

Add some extra sanity checking to ensure that interface attributes
aren't ambiguous.

Use CFARG_DEVHANDLE in MI FDT, OFW, and ACPI code, and macppc and shark
ports to associate those device handles with device_t instance. This
will trickle trough to more places over time (need back-end for pre-OFW
Sun OBP; any others?).
 1.29 14-Mar-2021  skrll branches: 1.29.2;
No need to have an MD #ifdef in an MI file, so remove it.
 1.28 07-Mar-2021  skrll Remove an '#ifndef hp300' and make STI_{EN,DIS}ABLE_ROM simply check the
sc_{en,disable}_rom methdos provide by the bus attachment glue.
 1.27 07-Mar-2021  skrll Use bus_space_mmap in sti_mmap. This makes X on sti for my B160L nearly
work (the colour map is somewhat wrong), but at least the machine doesn't
wedge.
 1.26 04-Mar-2021  skrll Trailing whitespace
 1.25 26-Dec-2020  tsutsui Ignore WSDISPLAYIO_PUTCMAP in WSDISPLAYIO_MODE_EMUL, i.e. text mode.

The hardware palette settings are handled by the STI ROM in STI_TEXTMODE
and changing cmap could cause mangled text colors at least on CRX on 425t.
Updating CMAP in EMUL mode isn't expected anyway.

Fixes "red or invisible text" after exiting mlterm-wscons on A1659 CRX.
 1.24 25-Dec-2020  tsutsui Handle WSSCREEN_REVERSE properly. Based on OpenBSD's sti(4).

Also remove WSSCREEN_UNDERLINE from capabilities that is not handled
by sti(4) ROM routines.

Tested on HP9000/425t with CRX.
 1.23 23-Dec-2020  tsutsui Pull the latest OpenBSD sti(4) changes for bitmap framebuffer support.

- bitmap and colormap ops based on old HP ngle X11 driver:
http://cvsweb.openbsd.org/cgi-bin/cvsweb/src/sys/dev/ic/sti.c#rev1.76
> Work-in-progress support for non-accelerated X11 on *some* sti(4)
> frame buffers; based upon the old HP ngle X11 driver.
> Currently limited to CRX (720/735/750), Timber (710, old 715),
> Artist (712, 715) and EG (B-series), however the
> colormap isn't set up correctly on Timber and EG yet.
>
> Joint work with Artem Falcon, now in good enough shape to be worked further
> in the tree.
- misc other cosmetic changes to reduce diffs

No particular comments on port-hp300@ and port-hppa@:
https://mail-index.netbsd.org/port-hp300/2020/12/19/msg000184.html
https://mail-index.netbsd.org/port-hp300/2020/12/20/msg000185.html

The MD hp300 attachment for SGC CRX (A1659-66001) will be committed
separately.
 1.22 05-Sep-2020  riastradh branches: 1.22.2;
Round of uvm.h cleanup.

The poorly named uvm.h is generally supposed to be for uvm-internal
users only.

- Narrow it to files that actually need it -- mostly files that need
to query whether curlwp is the pagedaemon, which should maybe be
exposed by an external header.

- Use uvm_extern.h where feasible and uvm_*.h for things not exposed
by it. We should split up uvm_extern.h but this will serve for now
to reduce the uvm.h dependencies.

- Use uvm_stat.h and #ifdef UVMHIST uvm.h for files that use
UVMHIST(ubchist), since ubchist is declared in uvm.h but the
reference evaporates if UVMHIST is not defined, so we reduce header
file dependencies.

- Make uvm_device.h and uvm_swap.h independently includable while
here.

ok chs@
 1.21 04-May-2020  tsutsui Add bitmap access ops support for EVRX framebuffer on HP9000/425e.

8bpp Xorg wsfb server and mlterm-wscons (formerly mlterm-fb) work.
No particular comment on port-hp300@ and port-hppa@:
https://mail-index.netbsd.org/port-hp300/2020/05/02/msg000170.html

Special thanks to Miod Vallat, for his advice about HP-UX implementation
and binutils patches to disassemble old HP-UX a.out-hp300hpux binaries
(and also contributing his 425e back in 2014).
 1.20 10-Nov-2019  chs in many device attach paths, allocate memory with M_WAITOK instead of M_NOWAIT
and remove code to handle failures that can no longer happen.
 1.19 13-Jun-2017  spz branches: 1.19.6; 1.19.12;
correct size checks so they cannot be circumvented by integer overflows

reported by CTurt, thanks for the notification
 1.18 29-Jun-2014  tsutsui branches: 1.18.2; 1.18.4; 1.18.6; 1.18.14; 1.18.20;
Export accessops functions to allow overriding them in MD attachment.
 1.17 20-Apr-2014  tsutsui Add proper consinit(9) support for sti(4) at sgc framebuffer on hp300.

The cnattach functions for sti(4) and service switch check method
for 425e in com_frodo.c are taken from OpenBSD.
The strategy how to choose the console device in hp300_cninit() is
quite diverged from 4.4BSD and OpenBSD so it's tweaked by me.

Also put several changes in sti_sgc.c to reduce diffs from OpenBSD/hp300.

Tested on 425e and 362 (which still uses gendiofb(4), not sti(4)).

XXX: sti(4) requires uvm_km_alloc(9) and uvm_map_protect(9)
to copy and call ROM functions on the executable memory region, so
it can be called before UVM and related initializations are complete.
Probably it's time to consider about MI "deferred consinit()" API
in init_main.c (or elsewhere) for modern complicated VM system...
 1.16 11-Jul-2011  matt branches: 1.16.2; 1.16.8; 1.16.12; 1.16.14; 1.16.16; 1.16.22; 1.16.26;
Fix
error: new qualifiers in middle of multi-level non-const cast are unsafe
by defining the type correctly thereby avoid the cast.
 1.15 21-May-2011  tsutsui Add a kludge to make this build on hp300.
(anyway bus independent driver should not include bus dependent sti_pci.h)
 1.14 24-Nov-2010  skrll branches: 1.14.2;
Improve debug output.
 1.13 09-Nov-2010  skrll Update sti(4) from OpenBSD bringing across support for sti @ pci.

Thanks to Adam Hoka for testing.
 1.12 01-Nov-2010  skrll u_intNN_t -> uintNN_t

Same code before and after.
 1.11 31-Oct-2010  skrll RCSId police.
 1.10 07-May-2009  skrll branches: 1.10.2; 1.10.4;
device_t/softc split
struct device * -> device_t
struct cfdata * -> cfdata_t
Use aprint*

There are a couple of MI drivers with MD attachments left.
 1.9 08-Apr-2008  cegger branches: 1.9.4; 1.9.18;
use aprint_*_dev and device_xname
 1.8 19-Oct-2007  ad branches: 1.8.16;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.7 04-Mar-2007  christos branches: 1.7.2; 1.7.14; 1.7.16; 1.7.20;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.6 12-Apr-2006  jmmv branches: 1.6.14;
Add an extra cookie to the ioctl and mmap wsdisplay accessops that points
to the screen on which they are being called. The driver cannot guess
this by itself but it is needed to implement, at least, the getwschar and
putwschar functions in the correct place. There are no functional changes
yet.

Tested on i386 (vga, vga_raster, machfb, vesafb), macppc and sparc64.
Suggested and reviewed by macallan@.
 1.5 11-Dec-2005  christos branches: 1.5.4; 1.5.6; 1.5.8; 1.5.10; 1.5.12;
merge ktrace-lwp.
 1.4 01-Apr-2005  yamt branches: 1.4.2;
merge yamt-km branch.
- don't use managed mappings/backing objects for wired memory allocations.
save some resources like pv_entry. also fix (most of) PR/27030.
- simplify kernel memory management API.
- simplify pmap bootstrap of some ports.
- some related cleanups.
 1.3 27-Feb-2005  perry nuke trailing whitespace
 1.2 19-Sep-2004  chs branches: 1.2.4; 1.2.6;
fix optimized compilation.
 1.1 26-Aug-2004  jkunz branches: 1.1.2;
Import STI wscons(4) driver from OpenBSD and add new driver for PS/2
keyboard / mouse pots of LASI.
 1.1.2.8 01-Apr-2005  skrll Sync with HEAD.
 1.1.2.7 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.1.2.6 09-Feb-2005  skrll Adapt to branch.
 1.1.2.5 24-Sep-2004  skrll Sync with HEAD.
 1.1.2.4 21-Sep-2004  skrll Fix the sync with head I botched.
 1.1.2.3 18-Sep-2004  skrll Sync with HEAD.
 1.1.2.2 03-Sep-2004  skrll Sync with HEAD
 1.1.2.1 26-Aug-2004  skrll file sti.c was added on branch ktrace-lwp on 2004-09-03 12:45:18 +0000
 1.2.6.2 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.2.6.1 25-Jan-2005  yamt convert to new apis.
 1.2.4.1 29-Apr-2005  kent sync with -current
 1.4.2.3 27-Oct-2007  yamt sync with head.
 1.4.2.2 03-Sep-2007  yamt sync with head.
 1.4.2.1 21-Jun-2006  yamt sync with head.
 1.5.12.1 24-May-2006  tron Merge 2006-05-24 NetBSD-current into the "peter-altq" branch.
 1.5.10.1 19-Apr-2006  elad sync with head.
 1.5.8.1 24-May-2006  yamt sync with head.
 1.5.6.1 22-Apr-2006  simonb Sync with head.
 1.5.4.1 09-Sep-2006  rpaulo sync with head
 1.6.14.1 12-Mar-2007  rmind Sync with HEAD.
 1.7.20.1 25-Oct-2007  bouyer Sync with HEAD.
 1.7.16.1 06-Nov-2007  matt sync with HEAD
 1.7.14.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.7.2.1 23-Oct-2007  ad Sync with head.
 1.8.16.1 02-Jun-2008  mjf Sync with HEAD.
 1.9.18.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.9.4.1 16-May-2009  yamt sync with head
 1.10.4.2 31-May-2011  rmind sync with head
 1.10.4.1 05-Mar-2011  rmind sync with head
 1.10.2.1 06-Nov-2010  uebayasi Sync with HEAD.
 1.14.2.1 06-Jun-2011  jruoho Sync with HEAD.
 1.16.26.1 10-Aug-2014  tls Rebase.
 1.16.22.1 15-Jun-2017  snj Pull up following revision(s) (requested by spz in ticket #1456):
sys/arch/ews4800mips/sbd/fb_sbdio.c: revision 1.16
sys/arch/pmax/ibus/pm.c: revision 1.13
sys/dev/hpc/bivideo.c: revision 1.34
sys/dev/ic/sti.c: revision 1.19
correct size checks so they cannot be circumvented by integer overflows
reported by CTurt, thanks for the notification
 1.16.16.1 18-May-2014  rmind sync with head
 1.16.14.1 15-Jun-2017  snj Pull up following revision(s) (requested by spz in ticket #1456):
sys/arch/ews4800mips/sbd/fb_sbdio.c: revision 1.16
sys/arch/pmax/ibus/pm.c: revision 1.13
sys/dev/hpc/bivideo.c: revision 1.34
sys/dev/ic/sti.c: revision 1.19
correct size checks so they cannot be circumvented by integer overflows
reported by CTurt, thanks for the notification
 1.16.12.2 03-Dec-2017  jdolecek update from HEAD
 1.16.12.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.16.8.2 15-Jun-2017  snj Pull up following revision(s) (requested by spz in ticket #1456):
sys/arch/ews4800mips/sbd/fb_sbdio.c: revision 1.16
sys/arch/pmax/ibus/pm.c: revision 1.13
sys/dev/hpc/bivideo.c: revision 1.34
sys/dev/ic/sti.c: revision 1.19
correct size checks so they cannot be circumvented by integer overflows
reported by CTurt, thanks for the notification
 1.16.8.1 21-May-2014  bouyer Pull up following revision(s) (requested by tsutsui in ticket #1058):
sys/arch/hp300/conf/files.hp300: revision 1.88
sys/arch/hp300/include/autoconf.h: revision 1.13
sys/dev/ic/sti.c: revision 1.17
sys/arch/hp300/dev/frodo.c: revision 1.31
sys/arch/hp300/conf/GENERIC: revision 1.173
sys/arch/hp300/hp300/machdep.c: revision 1.229
sys/arch/hp300/dev/frodo.c: revision 1.32
sys/arch/hp300/hp300/autoconf.c: revision 1.102
sys/arch/hp300/dev/frodoreg.h: revision 1.5
sys/arch/hp300/stand/common/ite_sti.c: revision 1.1
sys/arch/hp300/stand/common/itevar.h: revision 1.16
sys/arch/hp300/hp300/autoconf.c: revision 1.105
sys/arch/hp300/dev/sti_sgcvar.h: revision 1.1
sys/arch/hp300/stand/common/apci.c: revision 1.12
sys/arch/hp300/stand/common/apci.c: revision 1.13
sys/arch/hp300/dev/dnkbd.c: revision 1.6
sys/arch/hp300/dev/dnkbd.c: revision 1.7
sys/arch/hp300/stand/inst/version: revision 1.12
sys/arch/hp300/dev/com_frodo.c: revision 1.9
sys/arch/hp300/stand/common/ite.c: revision 1.17
sys/arch/hp300/conf/GENERIC: revision 1.181
sys/arch/hp300/dev/sti_sgc.c: revision 1.1
sys/arch/hp300/stand/common/dnkbd.c: revision 1.13
sys/arch/hp300/dev/sti_sgc.c: revision 1.2
sys/dev/ic/stivar.h: revision 1.8
sys/arch/hp300/dev/rtc.c: revision 1.21
sys/arch/hp300/conf/INSTALL: revision 1.56
sys/arch/hp300/conf/INSTALL: revision 1.58
sys/arch/hp300/stand/uboot/version: revision 1.19
sys/arch/hp300/stand/common/samachdep.h: revision 1.17
sys/arch/hp300/stand/common/clock.c: revision 1.12
sys/arch/hp300/dev/mcclock_frodo.c: revision 1.1
sys/arch/hp300/stand/Makefile.buildboot: revision 1.34
sys/arch/hp300/conf/files.hp300: revision 1.87
Add sti at sgc framebuffer.
Ported from OpenBSD by kiyohara@.
Fix a botch on switching from apci (and dca) to MI com(4) 10 years ago.
I.e. fix apci device address per FRODO_BASE macro change
in frodoreg.h rev 1.2. Now bootloader works with serial console
on HP425e (which has only com at frodo).
Thanks to miod@openbsd for providing his 425e.
Add sti(4) at sgc screen console support. From (the late) OpenBSD/hp300.
Tested on HP9000/425e, which was sent from Miod Vallat and
demonstrated at Open Source unConference 2014 Kagawa.
Check the service switch on 425e to select apci serial console.
Taken from OpenBSD/hp300. See the following comment for details:
> * Check the service switch. On the 425e, this is a physical
> * switch, unlike other frodo-based machines, so we can use it
> * as a serial vs internal video selector, since the PROM can not
> * be configured for serial console.
Add proper RealTime Clock support for HP9000/425e.
As the OpenBSD/hp300 page says 425e doesn't have the traditional
RTC at intio (as it also lacks DCA 16550 serial at intio?),
but after a few hour investigation it turns out that
425e uses mc146818 compatible calendar clock in
the Apollo "frodo" utility chip and the frodo chip on
425e actually has the 32kHz OSC and is actually backed up
by the onboard lithium battery.
Tested on HP425e (with mcclock) and HP362 (with old rtc).
Add RTC support for HP9000/425e to bootloader too.
Also put several cleanup:
- make local functions and variables static
- use proper variable types
- some KNF
Note it turns out that extreme slowness of netboot on hp300 is
caused by the too slow access of the traditional RTC chip at intio
(i.e. netboot on 425e is so much faster than others). Oh well.
Add proper consinit(9) support for sti(4) at sgc framebuffer on hp300.
The cnattach functions for sti(4) and service switch check method
for 425e in com_frodo.c are taken from OpenBSD.
The strategy how to choose the console device in hp300_cninit() is
quite diverged from 4.4BSD and OpenBSD so it's tweaked by me.
Also put several changes in sti_sgc.c to reduce diffs from OpenBSD/hp300.
Tested on 425e and 362 (which still uses gendiofb(4), not sti(4)).
XXX: sti(4) requires uvm_km_alloc(9) and uvm_map_protect(9)
to copy and call ROM functions on the executable memory region, so
it can be called before UVM and related initializations are complete.
Probably it's time to consider about MI "deferred consinit()" API
in init_main.c (or elsewhere) for modern complicated VM system...
Also fix the apci device address in dnkbd.c as apci.c rev 1.12:
http://mail-index.netbsd.org/source-changes/2014/04/10/msg053940.html
Finally dnkbd(4) is confirmed working at least on bootloader.
Thanks again to Miod Vallat.
Make the Apollo Domain keyboard actually work.
Tested on HP9000/425e and the keyboard model A1630-82001 R2 (RX-60857-HW)
provided by Miod Vallat. Mouse support needs more work.
Pull random notes on the Apollo Domain keyboard from ancient PR/3528.
Bump versions to denote recent 425e related changes.
Probe mcclock only on 425e to avoid an extra "not configured" message.
Add and enable sti(4) at sgc in install kernels for 425e.
Tested on both serial console and framebuffer console.
(switched by the service switch on the back panel)
 1.16.2.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.18.20.1 15-Jun-2017  snj Pull up following revision(s) (requested by spz in ticket #39):
sys/arch/ews4800mips/sbd/fb_sbdio.c: revision 1.16
sys/arch/pmax/ibus/pm.c: revision 1.13
sys/dev/hpc/bivideo.c: revision 1.34
sys/dev/ic/sti.c: revision 1.19
correct size checks so they cannot be circumvented by integer overflows
reported by CTurt, thanks for the notification
 1.18.14.1 15-Jun-2017  snj Pull up following revision(s) (requested by spz in ticket #1432):
sys/arch/ews4800mips/sbd/fb_sbdio.c: revision 1.16
sys/arch/pmax/ibus/pm.c: revision 1.13
sys/dev/hpc/bivideo.c: revision 1.34
sys/dev/ic/sti.c: revision 1.19
correct size checks so they cannot be circumvented by integer overflows
reported by CTurt, thanks for the notification
 1.18.6.1 15-Jun-2017  snj Pull up following revision(s) (requested by spz in ticket #1432):
sys/arch/ews4800mips/sbd/fb_sbdio.c: revision 1.16
sys/arch/pmax/ibus/pm.c: revision 1.13
sys/dev/hpc/bivideo.c: revision 1.34
sys/dev/ic/sti.c: revision 1.19
correct size checks so they cannot be circumvented by integer overflows
reported by CTurt, thanks for the notification
 1.18.4.1 28-Aug-2017  skrll Sync with HEAD
 1.18.2.1 15-Jun-2017  snj Pull up following revision(s) (requested by spz in ticket #1432):
sys/arch/ews4800mips/sbd/fb_sbdio.c: revision 1.16
sys/arch/pmax/ibus/pm.c: revision 1.13
sys/dev/hpc/bivideo.c: revision 1.34
sys/dev/ic/sti.c: revision 1.19
correct size checks so they cannot be circumvented by integer overflows
reported by CTurt, thanks for the notification
 1.19.12.2 28-Dec-2020  martin Pull up following revision(s) (requested by tsutsui in ticket #1162):

sys/dev/ic/stivar.h: revision 1.11
sys/dev/ic/sti.c: revision 1.23
sys/dev/ic/sti.c: revision 1.24
sys/dev/ic/sti.c: revision 1.25
sys/arch/hp300/dev/sti_sgc.c: revision 1.4

Pull the latest OpenBSD sti(4) changes for bitmap framebuffer support.
- bitmap and colormap ops based on old HP ngle X11 driver:
http://cvsweb.openbsd.org/cgi-bin/cvsweb/src/sys/dev/ic/sti.c#rev1.76
> Work-in-progress support for non-accelerated X11 on *some* sti(4)
> frame buffers; based upon the old HP ngle X11 driver.
> Currently limited to CRX (720/735/750), Timber (710, old 715),
> Artist (712, 715) and EG (B-series), however the
> colormap isn't set up correctly on Timber and EG yet.
>
> Joint work with Artem Falcon, now in good enough shape to be worked further
> in the tree.
- misc other cosmetic changes to reduce diffs
No particular comments on port-hp300@ and port-hppa@:
https://mail-index.netbsd.org/port-hp300/2020/12/19/msg000184.html
https://mail-index.netbsd.org/port-hp300/2020/12/20/msg000185.html

The MD hp300 attachment for SGC CRX (A1659-66001) will be committed
separately.

Add bitmap access ops support for SGC CRX (A1659-66001) framebuffer.
Also modify existing 425e EVRX attachment to use updated MI sti(4) ops
more efficiently.

The Xorg server and mlterm-wscons (that support wsdisplay bitmap) work
fine on SGC hp425t.

No particular comments on port-hp300@ and port-hppa@:
https://mail-index.netbsd.org/port-hp300/2020/12/19/msg000184.html
https://mail-index.netbsd.org/port-hp300/2020/12/20/msg000185.html

Special thanks to Miod Vallat again, for contributing the SGC CRX
framebuffer with the SGC connector and flexible cable for HP9000/425t.

He also contributed DIO-II "Hyperion" monochrome framebuffer and
1 plane grayscale SGC GRX (A1924-66001), and I've confirmed hyper(4)
just works even with Xorg server. I will try GRX as the next project.

Handle WSSCREEN_REVERSE properly. Based on OpenBSD's sti(4).

Also remove WSSCREEN_UNDERLINE from capabilities that is not handled
by sti(4) ROM routines.

Tested on HP9000/425t with CRX.

Ignore WSDISPLAYIO_PUTCMAP in WSDISPLAYIO_MODE_EMUL, i.e. text mode.

The hardware palette settings are handled by the STI ROM in STI_TEXTMODE
and changing cmap could cause mangled text colors at least on CRX on 425t.

Updating CMAP in EMUL mode isn't expected anyway.

Fixes "red or invisible text" after exiting mlterm-wscons on A1659 CRX.
 1.19.12.1 18-May-2020  martin Pull up following revision(s) (requested by tsutsui in ticket #908):

sys/dev/ic/stivar.h: revision 1.10
sys/dev/ic/sti.c: revision 1.21
sys/arch/hp300/dev/sti_sgc.c: revision 1.3

Add bitmap access ops support for EVRX framebuffer on HP9000/425e.

8bpp Xorg wsfb server and mlterm-wscons (formerly mlterm-fb) work.
No particular comment on port-hp300@ and port-hppa@:
https://mail-index.netbsd.org/port-hp300/2020/05/02/msg000170.html

Special thanks to Miod Vallat, for his advice about HP-UX implementation
and binutils patches to disassemble old HP-UX a.out-hp300hpux binaries
(and also contributing his 425e back in 2014).
 1.19.6.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.22.2.2 03-Apr-2021  thorpej Sync with HEAD.
 1.22.2.1 03-Jan-2021  thorpej Sync w/ HEAD.
 1.29.2.1 21-Mar-2021  thorpej Give config_found() the same variadic arguments treatment as
config_search(). This commit only adds the CFARG_EOL sentinel
to the existing config_found() calls. Conversion of config_found_sm_loc()
and config_found_ia() call sites will be in subsequent commits.
 1.30.8.1 04-Aug-2021  thorpej Adapt to CFARGS().
 1.31.6.1 17-Feb-2024  martin Pull up following revision(s) (requested by macallan in ticket #593):

sys/dev/ic/sti.c: revision 1.32

Make this work properly on PCI Visualize EG:
- use bus_space_*_stream() for all register accesses in order to avoid
byte order conversion on PCI devices
- when switching to framebuffer mode, request as many text planes as STI allows
- request access to both text and non-text planes in fb mode

With this and the bus_space commit a few days ago I have usable X on my C360
and a PCI Visualize EG.

This needs testing on quite literally everything else.
 1.36.2.1 02-Aug-2025  perseant Sync with HEAD
 1.18 30-May-2025  tsutsui Use fixed STI_PGSHIFT to calculate region info stored in the sti(4) ROM.

The length and offset values in the ROM assume 4KB/page.
Now sti(4) works with 8KB/page (PGSHIFT == 13) settings on hp300.
 1.17 01-May-2025  tsutsui Add a graphics id of HP9000/382 on-board mid-resolution framebuffer.
 1.16 27-Oct-2024  macallan moar bits
 1.15 25-Oct-2024  macallan rearrange and annotate bits for the bitmap access and buffer control registers
NFC
 1.14 04-Sep-2024  macallan more annotations:
- 'transfer data' is actually a pixel mask
- transparency
- bg colour register confirmed
all found by experiment
 1.13 19-Aug-2024  macallan add an ioctl() to read a device's graphics ID, mimic HP/UX's GCID
that way an xorg driver can identify which WSDISPLAY_TYPE_STI it's talking to
without having to setup its own STI
 1.12 06-Aug-2024  macallan moar bits & pieces
 1.11 05-Aug-2024  macallan describe more register functions
 1.10 31-Jul-2024  macallan moar ROPs
 1.9 17-Jul-2024  macallan moar bits
these should probably go into their own header since they don't actually
have anything to do with STI
 1.8 17-Jul-2024  macallan document a few more registers & bits
 1.7 15-Jul-2024  macallan annotate (some) registers if we know what they do
fix a tpyo while there
 1.6 09-Sep-2015  skrll branches: 1.6.56;
Sync with OpenBSD. No functional change.
 1.5 09-Nov-2010  skrll branches: 1.5.18; 1.5.36;
Update sti(4) from OpenBSD bringing across support for sti @ pci.

Thanks to Adam Hoka for testing.
 1.4 01-Nov-2010  skrll u_intNN_t -> uintNN_t

Same code before and after.
 1.3 31-Oct-2010  skrll RCSId police.
 1.2 11-Dec-2005  christos branches: 1.2.96; 1.2.98;
merge ktrace-lwp.
 1.1 26-Aug-2004  jkunz branches: 1.1.2;
Import STI wscons(4) driver from OpenBSD and add new driver for PS/2
keyboard / mouse pots of LASI.
 1.1.2.4 21-Sep-2004  skrll Fix the sync with head I botched.
 1.1.2.3 18-Sep-2004  skrll Sync with HEAD.
 1.1.2.2 03-Sep-2004  skrll Sync with HEAD
 1.1.2.1 26-Aug-2004  skrll file stireg.h was added on branch ktrace-lwp on 2004-09-03 12:45:18 +0000
 1.2.98.1 05-Mar-2011  rmind sync with head
 1.2.96.1 06-Nov-2010  uebayasi Sync with HEAD.
 1.5.36.1 22-Sep-2015  skrll Sync with HEAD
 1.5.18.1 03-Dec-2017  jdolecek update from HEAD
 1.6.56.1 02-Aug-2025  perseant Sync with HEAD
 1.12 16-Dec-2024  macallan properly declare sti_unitoroman[] and explain what it's for
 1.11 23-Dec-2020  tsutsui branches: 1.11.24;
Pull the latest OpenBSD sti(4) changes for bitmap framebuffer support.

- bitmap and colormap ops based on old HP ngle X11 driver:
http://cvsweb.openbsd.org/cgi-bin/cvsweb/src/sys/dev/ic/sti.c#rev1.76
> Work-in-progress support for non-accelerated X11 on *some* sti(4)
> frame buffers; based upon the old HP ngle X11 driver.
> Currently limited to CRX (720/735/750), Timber (710, old 715),
> Artist (712, 715) and EG (B-series), however the
> colormap isn't set up correctly on Timber and EG yet.
>
> Joint work with Artem Falcon, now in good enough shape to be worked further
> in the tree.
- misc other cosmetic changes to reduce diffs

No particular comments on port-hp300@ and port-hppa@:
https://mail-index.netbsd.org/port-hp300/2020/12/19/msg000184.html
https://mail-index.netbsd.org/port-hp300/2020/12/20/msg000185.html

The MD hp300 attachment for SGC CRX (A1659-66001) will be committed
separately.
 1.10 04-May-2020  tsutsui branches: 1.10.2;
Add bitmap access ops support for EVRX framebuffer on HP9000/425e.

8bpp Xorg wsfb server and mlterm-wscons (formerly mlterm-fb) work.
No particular comment on port-hp300@ and port-hppa@:
https://mail-index.netbsd.org/port-hp300/2020/05/02/msg000170.html

Special thanks to Miod Vallat, for his advice about HP-UX implementation
and binutils patches to disassemble old HP-UX a.out-hp300hpux binaries
(and also contributing his 425e back in 2014).
 1.9 29-Jun-2014  tsutsui branches: 1.9.34;
Export accessops functions to allow overriding them in MD attachment.
 1.8 20-Apr-2014  tsutsui Add proper consinit(9) support for sti(4) at sgc framebuffer on hp300.

The cnattach functions for sti(4) and service switch check method
for 425e in com_frodo.c are taken from OpenBSD.
The strategy how to choose the console device in hp300_cninit() is
quite diverged from 4.4BSD and OpenBSD so it's tweaked by me.

Also put several changes in sti_sgc.c to reduce diffs from OpenBSD/hp300.

Tested on 425e and 362 (which still uses gendiofb(4), not sti(4)).

XXX: sti(4) requires uvm_km_alloc(9) and uvm_map_protect(9)
to copy and call ROM functions on the executable memory region, so
it can be called before UVM and related initializations are complete.
Probably it's time to consider about MI "deferred consinit()" API
in init_main.c (or elsewhere) for modern complicated VM system...
 1.7 11-Jul-2011  matt branches: 1.7.2; 1.7.8; 1.7.12; 1.7.16; 1.7.26;
Fix
error: new qualifiers in middle of multi-level non-const cast are unsafe
by defining the type correctly thereby avoid the cast.
 1.6 09-Nov-2010  skrll Update sti(4) from OpenBSD bringing across support for sti @ pci.

Thanks to Adam Hoka for testing.
 1.5 01-Nov-2010  skrll u_intNN_t -> uintNN_t

Same code before and after.
 1.4 31-Oct-2010  skrll RCSId police.
 1.3 07-May-2009  skrll branches: 1.3.2; 1.3.4;
device_t/softc split
struct device * -> device_t
struct cfdata * -> cfdata_t
Use aprint*

There are a couple of MI drivers with MD attachments left.
 1.2 11-Dec-2005  christos branches: 1.2.74; 1.2.90;
merge ktrace-lwp.
 1.1 26-Aug-2004  jkunz branches: 1.1.2;
Import STI wscons(4) driver from OpenBSD and add new driver for PS/2
keyboard / mouse pots of LASI.
 1.1.2.4 21-Sep-2004  skrll Fix the sync with head I botched.
 1.1.2.3 18-Sep-2004  skrll Sync with HEAD.
 1.1.2.2 03-Sep-2004  skrll Sync with HEAD
 1.1.2.1 26-Aug-2004  skrll file stivar.h was added on branch ktrace-lwp on 2004-09-03 12:45:18 +0000
 1.2.90.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.2.74.1 16-May-2009  yamt sync with head
 1.3.4.1 05-Mar-2011  rmind sync with head
 1.3.2.1 06-Nov-2010  uebayasi Sync with HEAD.
 1.7.26.1 10-Aug-2014  tls Rebase.
 1.7.16.1 18-May-2014  rmind sync with head
 1.7.12.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.7.8.1 21-May-2014  bouyer Pull up following revision(s) (requested by tsutsui in ticket #1058):
sys/arch/hp300/conf/files.hp300: revision 1.88
sys/arch/hp300/include/autoconf.h: revision 1.13
sys/dev/ic/sti.c: revision 1.17
sys/arch/hp300/dev/frodo.c: revision 1.31
sys/arch/hp300/conf/GENERIC: revision 1.173
sys/arch/hp300/hp300/machdep.c: revision 1.229
sys/arch/hp300/dev/frodo.c: revision 1.32
sys/arch/hp300/hp300/autoconf.c: revision 1.102
sys/arch/hp300/dev/frodoreg.h: revision 1.5
sys/arch/hp300/stand/common/ite_sti.c: revision 1.1
sys/arch/hp300/stand/common/itevar.h: revision 1.16
sys/arch/hp300/hp300/autoconf.c: revision 1.105
sys/arch/hp300/dev/sti_sgcvar.h: revision 1.1
sys/arch/hp300/stand/common/apci.c: revision 1.12
sys/arch/hp300/stand/common/apci.c: revision 1.13
sys/arch/hp300/dev/dnkbd.c: revision 1.6
sys/arch/hp300/dev/dnkbd.c: revision 1.7
sys/arch/hp300/stand/inst/version: revision 1.12
sys/arch/hp300/dev/com_frodo.c: revision 1.9
sys/arch/hp300/stand/common/ite.c: revision 1.17
sys/arch/hp300/conf/GENERIC: revision 1.181
sys/arch/hp300/dev/sti_sgc.c: revision 1.1
sys/arch/hp300/stand/common/dnkbd.c: revision 1.13
sys/arch/hp300/dev/sti_sgc.c: revision 1.2
sys/dev/ic/stivar.h: revision 1.8
sys/arch/hp300/dev/rtc.c: revision 1.21
sys/arch/hp300/conf/INSTALL: revision 1.56
sys/arch/hp300/conf/INSTALL: revision 1.58
sys/arch/hp300/stand/uboot/version: revision 1.19
sys/arch/hp300/stand/common/samachdep.h: revision 1.17
sys/arch/hp300/stand/common/clock.c: revision 1.12
sys/arch/hp300/dev/mcclock_frodo.c: revision 1.1
sys/arch/hp300/stand/Makefile.buildboot: revision 1.34
sys/arch/hp300/conf/files.hp300: revision 1.87
Add sti at sgc framebuffer.
Ported from OpenBSD by kiyohara@.
Fix a botch on switching from apci (and dca) to MI com(4) 10 years ago.
I.e. fix apci device address per FRODO_BASE macro change
in frodoreg.h rev 1.2. Now bootloader works with serial console
on HP425e (which has only com at frodo).
Thanks to miod@openbsd for providing his 425e.
Add sti(4) at sgc screen console support. From (the late) OpenBSD/hp300.
Tested on HP9000/425e, which was sent from Miod Vallat and
demonstrated at Open Source unConference 2014 Kagawa.
Check the service switch on 425e to select apci serial console.
Taken from OpenBSD/hp300. See the following comment for details:
> * Check the service switch. On the 425e, this is a physical
> * switch, unlike other frodo-based machines, so we can use it
> * as a serial vs internal video selector, since the PROM can not
> * be configured for serial console.
Add proper RealTime Clock support for HP9000/425e.
As the OpenBSD/hp300 page says 425e doesn't have the traditional
RTC at intio (as it also lacks DCA 16550 serial at intio?),
but after a few hour investigation it turns out that
425e uses mc146818 compatible calendar clock in
the Apollo "frodo" utility chip and the frodo chip on
425e actually has the 32kHz OSC and is actually backed up
by the onboard lithium battery.
Tested on HP425e (with mcclock) and HP362 (with old rtc).
Add RTC support for HP9000/425e to bootloader too.
Also put several cleanup:
- make local functions and variables static
- use proper variable types
- some KNF
Note it turns out that extreme slowness of netboot on hp300 is
caused by the too slow access of the traditional RTC chip at intio
(i.e. netboot on 425e is so much faster than others). Oh well.
Add proper consinit(9) support for sti(4) at sgc framebuffer on hp300.
The cnattach functions for sti(4) and service switch check method
for 425e in com_frodo.c are taken from OpenBSD.
The strategy how to choose the console device in hp300_cninit() is
quite diverged from 4.4BSD and OpenBSD so it's tweaked by me.
Also put several changes in sti_sgc.c to reduce diffs from OpenBSD/hp300.
Tested on 425e and 362 (which still uses gendiofb(4), not sti(4)).
XXX: sti(4) requires uvm_km_alloc(9) and uvm_map_protect(9)
to copy and call ROM functions on the executable memory region, so
it can be called before UVM and related initializations are complete.
Probably it's time to consider about MI "deferred consinit()" API
in init_main.c (or elsewhere) for modern complicated VM system...
Also fix the apci device address in dnkbd.c as apci.c rev 1.12:
http://mail-index.netbsd.org/source-changes/2014/04/10/msg053940.html
Finally dnkbd(4) is confirmed working at least on bootloader.
Thanks again to Miod Vallat.
Make the Apollo Domain keyboard actually work.
Tested on HP9000/425e and the keyboard model A1630-82001 R2 (RX-60857-HW)
provided by Miod Vallat. Mouse support needs more work.
Pull random notes on the Apollo Domain keyboard from ancient PR/3528.
Bump versions to denote recent 425e related changes.
Probe mcclock only on 425e to avoid an extra "not configured" message.
Add and enable sti(4) at sgc in install kernels for 425e.
Tested on both serial console and framebuffer console.
(switched by the service switch on the back panel)
 1.7.2.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.9.34.2 28-Dec-2020  martin Pull up following revision(s) (requested by tsutsui in ticket #1162):

sys/dev/ic/stivar.h: revision 1.11
sys/dev/ic/sti.c: revision 1.23
sys/dev/ic/sti.c: revision 1.24
sys/dev/ic/sti.c: revision 1.25
sys/arch/hp300/dev/sti_sgc.c: revision 1.4

Pull the latest OpenBSD sti(4) changes for bitmap framebuffer support.
- bitmap and colormap ops based on old HP ngle X11 driver:
http://cvsweb.openbsd.org/cgi-bin/cvsweb/src/sys/dev/ic/sti.c#rev1.76
> Work-in-progress support for non-accelerated X11 on *some* sti(4)
> frame buffers; based upon the old HP ngle X11 driver.
> Currently limited to CRX (720/735/750), Timber (710, old 715),
> Artist (712, 715) and EG (B-series), however the
> colormap isn't set up correctly on Timber and EG yet.
>
> Joint work with Artem Falcon, now in good enough shape to be worked further
> in the tree.
- misc other cosmetic changes to reduce diffs
No particular comments on port-hp300@ and port-hppa@:
https://mail-index.netbsd.org/port-hp300/2020/12/19/msg000184.html
https://mail-index.netbsd.org/port-hp300/2020/12/20/msg000185.html

The MD hp300 attachment for SGC CRX (A1659-66001) will be committed
separately.

Add bitmap access ops support for SGC CRX (A1659-66001) framebuffer.
Also modify existing 425e EVRX attachment to use updated MI sti(4) ops
more efficiently.

The Xorg server and mlterm-wscons (that support wsdisplay bitmap) work
fine on SGC hp425t.

No particular comments on port-hp300@ and port-hppa@:
https://mail-index.netbsd.org/port-hp300/2020/12/19/msg000184.html
https://mail-index.netbsd.org/port-hp300/2020/12/20/msg000185.html

Special thanks to Miod Vallat again, for contributing the SGC CRX
framebuffer with the SGC connector and flexible cable for HP9000/425t.

He also contributed DIO-II "Hyperion" monochrome framebuffer and
1 plane grayscale SGC GRX (A1924-66001), and I've confirmed hyper(4)
just works even with Xorg server. I will try GRX as the next project.

Handle WSSCREEN_REVERSE properly. Based on OpenBSD's sti(4).

Also remove WSSCREEN_UNDERLINE from capabilities that is not handled
by sti(4) ROM routines.

Tested on HP9000/425t with CRX.

Ignore WSDISPLAYIO_PUTCMAP in WSDISPLAYIO_MODE_EMUL, i.e. text mode.

The hardware palette settings are handled by the STI ROM in STI_TEXTMODE
and changing cmap could cause mangled text colors at least on CRX on 425t.

Updating CMAP in EMUL mode isn't expected anyway.

Fixes "red or invisible text" after exiting mlterm-wscons on A1659 CRX.
 1.9.34.1 18-May-2020  martin Pull up following revision(s) (requested by tsutsui in ticket #908):

sys/dev/ic/stivar.h: revision 1.10
sys/dev/ic/sti.c: revision 1.21
sys/arch/hp300/dev/sti_sgc.c: revision 1.3

Add bitmap access ops support for EVRX framebuffer on HP9000/425e.

8bpp Xorg wsfb server and mlterm-wscons (formerly mlterm-fb) work.
No particular comment on port-hp300@ and port-hppa@:
https://mail-index.netbsd.org/port-hp300/2020/05/02/msg000170.html

Special thanks to Miod Vallat, for his advice about HP-UX implementation
and binutils patches to disassemble old HP-UX a.out-hp300hpux binaries
(and also contributing his 425e back in 2014).
 1.10.2.1 03-Jan-2021  thorpej Sync w/ HEAD.
 1.11.24.1 02-Aug-2025  perseant Sync with HEAD
 1.16 29-Jan-2025  macallan branches: 1.16.4;
comment on what I've found out about alpha blending on the FX4
NFC
 1.15 27-Jan-2025  macallan add what we know about the alpha blending register(s)
 1.14 26-Jan-2025  macallan document FIFO behaviour and cursor register access
NFC
 1.13 24-Jan-2025  macallan - add read prefetch hint register
- use unbuffered access for cursor registers
 1.12 26-Dec-2024  macallan add more registers - now we can do ROPs
 1.11 25-Dec-2024  macallan flip CFS_8I and _332, now this works correctly
 1.10 25-Dec-2024  macallan add more registers
 1.9 18-Dec-2024  macallan - use 0x800000 range for cursor and cmap access - we can read back values there
but not at 0x400000
- add cursor foreground colour register
 1.8 16-Dec-2024  macallan the cursor sprite and colour map registers live in the same address range,
0x80xxxx and 0x40xxxx are aliases, no idea what the diffrence is.
Rearrange register definitions and explain what's going on
 1.7 05-Dec-2024  macallan more bits
found STI's colour change mode, but no ROPs yet
 1.6 28-Nov-2024  macallan found another register
 1.5 27-Nov-2024  riastradh hppa/summitfb(4): Nix trailing whitespace.

Plus some other minor whitespace/comment cleanups.
 1.4 27-Nov-2024  macallan found clipping registers
 1.3 26-Nov-2024  macallan moar bits
 1.2 26-Nov-2024  macallan identified a few more registers
 1.1 20-Nov-2024  macallan register definitions for HP Visualize FX4 and friends, aka Summit
 1.16.4.2 02-Aug-2025  perseant Sync with HEAD
 1.16.4.1 29-Jan-2025  perseant file summitreg.h was added on branch perseant-exfatfs on 2025-08-02 05:56:42 +0000
 1.30 10-Oct-2025  christos Fix reversed arguments and bump buffer size (thanks rillig@)
 1.29 07-Aug-2021  thorpej Merge thorpej-cfargs2.
 1.28 24-Apr-2021  thorpej branches: 1.28.8;
Merge thorpej-cfargs branch:

Simplify and make extensible the config_search() / config_found() /
config_attach() interfaces: rather than having different variants for
which arguments you want pass along, just have a single call that
takes a variadic list of tag-value arguments.

Adjust all call sites:
- Simplify wherever possible; don't pass along arguments that aren't
actually needed.
- Don't be explicit about what interface attribute is attaching if
the device only has one. (More simplification.)
- Add a config_probe() function to be used in indirect configuiration
situations, making is visibly easier to see when indirect config is
in play, and allowing for future change in semantics. (As of now,
this is just a wrapper around config_match(), but that is an
implementation detail.)

Remove unnecessary or redundant interface attributes where they're not
needed.

There are currently 5 "cfargs" defined:
- CFARG_SUBMATCH (submatch function for direct config)
- CFARG_SEARCH (search function for indirect config)
- CFARG_IATTR (interface attribte)
- CFARG_LOCATORS (locators array)
- CFARG_DEVHANDLE (devhandle_t - wraps OFW, ACPI, etc. handles)

...and a sentinel value CFARG_EOL.

Add some extra sanity checking to ensure that interface attributes
aren't ambiguous.

Use CFARG_DEVHANDLE in MI FDT, OFW, and ACPI code, and macppc and shark
ports to associate those device handles with device_t instance. This
will trickle trough to more places over time (need back-end for pre-OFW
Sun OBP; any others?).
 1.27 11-Jan-2017  skrll branches: 1.27.32;
adatper -> adapter
 1.26 25-Mar-2014  christos branches: 1.26.6; 1.26.10;
kill sprintf
 1.25 23-Nov-2009  rmind branches: 1.25.12; 1.25.22; 1.25.26;
Remove some unecessary includes sys/user.h header.
 1.24 16-Dec-2008  christos replace bitmask_snprintf(9) with snprintb(3)
 1.23 06-Jul-2008  tsutsui branches: 1.23.4;
Split device_t/softc with misc cosmetic changes.
 1.22 08-Apr-2008  cegger branches: 1.22.4; 1.22.6; 1.22.8;
use aprint_*_dev and device_xname
 1.21 24-Nov-2006  christos branches: 1.21.48;
fix spelling of accommodate; from Zapher.
 1.20 24-Dec-2005  perry branches: 1.20.20; 1.20.22;
Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.19 11-Dec-2005  christos merge ktrace-lwp.
 1.18 03-Jun-2005  tsutsui branches: 1.18.2;
Constify.
 1.17 27-Feb-2005  perry nuke trailing whitespace
 1.16 04-Feb-2005  perry de-__P
 1.15 18-Sep-2004  mycroft branches: 1.15.4; 1.15.6;
If we need to poll, set SCSIPI_ADAPT_POLL_ONLY rather than a homegrown flag.
 1.14 03-May-2003  wiz branches: 1.14.2;
DMA, not dma nor Dma.
 1.13 27-Sep-2002  provos remove trailing \n in panic(). approved perry.
 1.12 05-Apr-2002  bouyer Implement mstohz() as discussed on tech-kern, and use it in SCSI drivers
to convert xs->timeout to callout() parameter.
 1.11 22-Mar-2002  fredette Fixed a possible overflow bug in the timeout calculation.
 1.10 15-Nov-2001  lukem don't need <sys/types.h> when including <sys/param.h>
 1.9 13-Nov-2001  lukem add/cleanup RCSID
 1.8 04-Nov-2001  tsutsui Use common macro to check message length.
 1.7 17-Aug-2001  fredette branches: 1.7.4;
When asked to set the transfer mode, just call back
immediately, because we don't support that.
 1.6 15-Jul-2001  fredette When reporting an ICR value, use bitmask_snprintf to
give a human-readable description of the value.
 1.5 08-Jul-2001  wiz branches: 1.5.2;
Correct various misspellings of 'transfer' and inflected forms.
 1.4 07-Jul-2001  thorpej bzero -> memset
 1.3 18-May-2001  fredette branches: 1.3.2;
Fixed some typos, removed unused asm() labels. Removed
the DMA map creation, now the bus glue does this.
 1.2 25-Apr-2001  bouyer Pull up the thorpej_scsipi branch to main branch.
This is a completely rewritten scsipi_xfer execution engine, and the
associated changes to HBA drivers. Overview of changes & features:
- All xfers are queued in the mid-layer, rather than doing so in an
ad-hoc fashion in individual adapter drivers.
- Adapter/channel resource management in the mid-layer, avoids even trying
to start running an xfer if the adapter/channel doesn't have the resources.
- Better communication between the mid-layer and the adapters.
- Asynchronous event notification mechanism from adapter to mid-layer and
peripherals.
- Better peripheral queue management: freeze/thaw, sorted requeueing during
recovery, etc.
- Clean separation of peripherals, adapters, and adapter channels (no more
scsipi_link).
- Kernel thread for each scsipi_channel makes error recovery much easier
(no more dealing with interrupt context when recovering from an error).
- Mid-layer support for tagged queueing: commands can have the tag type
set explicitly, tag IDs are allocated in the mid-layer (thus eliminating
the need to use buggy tag ID allocation schemes in many adapter drivers).
- support for QUEUE FULL and CHECK CONDITION status in mid-layer; the command
will be requeued, or a REQUEST SENSE will be sent as appropriate.

Just before the merge syssrc has been tagged with thorpej_scsipi_beforemerge
 1.1 20-Apr-2001  fredette branches: 1.1.2;
Added support for the chipset used on the Sun2 "sc" SCSI adapters.
A little rough around the edges, but definitely a starting point.
 1.1.2.3 23-Apr-2001  bouyer Port to thorpej_scsipi.
XXX SUNSCPAL_OPENINGS can certainly be lowered to 8, as we won't queue more
than one command per device.
 1.1.2.2 23-Apr-2001  bouyer Sync with HEAD.
 1.1.2.1 20-Apr-2001  bouyer file sunscpal.c was added on branch thorpej_scsipi on 2001-04-23 09:42:20 +0000
 1.3.2.8 18-Oct-2002  nathanw Catch up to -current.
 1.3.2.7 17-Apr-2002  nathanw Catch up to -current.
 1.3.2.6 01-Apr-2002  nathanw Catch up to -current.
(CVS: It's not just a program. It's an adventure!)
 1.3.2.5 08-Jan-2002  nathanw Catch up to -current.
 1.3.2.4 14-Nov-2001  nathanw Catch up to -current.
 1.3.2.3 24-Aug-2001  nathanw Catch up with -current.
 1.3.2.2 21-Jun-2001  nathanw Catch up to -current.
 1.3.2.1 18-May-2001  nathanw file sunscpal.c was added on branch nathanw_sa on 2001-06-21 20:03:22 +0000
 1.5.2.5 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.5.2.4 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.5.2.3 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.5.2.2 25-Aug-2001  thorpej Merge Aug 24 -current into the kqueue branch.
 1.5.2.1 03-Aug-2001  lukem update to -current
 1.7.4.1 12-Nov-2001  thorpej Sync the thorpej-mips-cache branch with -current.
 1.14.2.5 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.14.2.4 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.14.2.3 04-Feb-2005  skrll Sync with HEAD.
 1.14.2.2 21-Sep-2004  skrll Fix the sync with head I botched.
 1.14.2.1 18-Sep-2004  skrll Sync with HEAD.
 1.15.6.2 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.15.6.1 12-Feb-2005  yamt sync with head.
 1.15.4.1 29-Apr-2005  kent sync with -current
 1.18.2.2 30-Dec-2006  yamt sync with head.
 1.18.2.1 21-Jun-2006  yamt sync with head.
 1.20.22.1 10-Dec-2006  yamt sync with head.
 1.20.20.1 12-Jan-2007  ad Sync with head.
 1.21.48.3 17-Jan-2009  mjf Sync with HEAD.
 1.21.48.2 28-Sep-2008  mjf Sync with HEAD.
 1.21.48.1 02-Jun-2008  mjf Sync with HEAD.
 1.22.8.1 18-Jul-2008  simonb Sync with head.
 1.22.6.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.22.4.2 11-Mar-2010  yamt sync with head
 1.22.4.1 04-May-2009  yamt sync with head.
 1.23.4.1 19-Jan-2009  skrll Sync with HEAD.
 1.25.26.1 18-May-2014  rmind sync with head
 1.25.22.2 03-Dec-2017  jdolecek update from HEAD
 1.25.22.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.25.12.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.26.10.1 20-Mar-2017  pgoyette Sync with HEAD
 1.26.6.1 05-Feb-2017  skrll Sync with HEAD
 1.27.32.1 21-Mar-2021  thorpej Give config_found() the same variadic arguments treatment as
config_search(). This commit only adds the CFARG_EOL sentinel
to the existing config_found() calls. Conversion of config_found_sm_loc()
and config_found_ia() call sites will be in subsequent commits.
 1.28.8.1 04-Aug-2021  thorpej Adapt to CFARGS().
 1.3 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.2 15-Jul-2001  fredette branches: 1.2.118; 1.2.120; 1.2.122;
When reporting an ICR value, use bitmask_snprintf to
give a human-readable description of the value.
 1.1 20-Apr-2001  fredette branches: 1.1.2; 1.1.4; 1.1.6;
Added support for the chipset used on the Sun2 "sc" SCSI adapters.
A little rough around the edges, but definitely a starting point.
 1.1.6.1 03-Aug-2001  lukem update to -current
 1.1.4.3 24-Aug-2001  nathanw Catch up with -current.
 1.1.4.2 21-Jun-2001  nathanw Catch up to -current.
 1.1.4.1 20-Apr-2001  nathanw file sunscpalreg.h was added on branch nathanw_sa on 2001-06-21 20:03:23 +0000
 1.1.2.2 23-Apr-2001  bouyer Sync with HEAD.
 1.1.2.1 20-Apr-2001  bouyer file sunscpalreg.h was added on branch thorpej_scsipi on 2001-04-23 09:42:20 +0000
 1.2.122.1 16-May-2008  yamt sync with head.
 1.2.120.1 18-May-2008  yamt sync with head.
 1.2.118.1 02-Jun-2008  mjf Sync with HEAD.
 1.10 23-Jan-2023  andvar s/lager/larger/ in comments.
 1.9 06-Jul-2008  tsutsui Split device_t/softc with misc cosmetic changes.
 1.8 19-Oct-2007  ad branches: 1.8.16; 1.8.20; 1.8.22; 1.8.24;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.7 11-Dec-2005  christos branches: 1.7.30; 1.7.44; 1.7.46; 1.7.50;
merge ktrace-lwp.
 1.6 27-Feb-2005  perry branches: 1.6.4;
nuke trailing whitespace
 1.5 04-Feb-2005  perry de-__P
 1.4 18-Sep-2004  mycroft branches: 1.4.4; 1.4.6;
If we need to poll, set SCSIPI_ADAPT_POLL_ONLY rather than a homegrown flag.
 1.3 02-Nov-2003  wiz Fix some typos. From Tom Cosgrove via jmc@openbsd.
 1.2 25-Apr-2001  bouyer branches: 1.2.2; 1.2.24;
Pull up the thorpej_scsipi branch to main branch.
This is a completely rewritten scsipi_xfer execution engine, and the
associated changes to HBA drivers. Overview of changes & features:
- All xfers are queued in the mid-layer, rather than doing so in an
ad-hoc fashion in individual adapter drivers.
- Adapter/channel resource management in the mid-layer, avoids even trying
to start running an xfer if the adapter/channel doesn't have the resources.
- Better communication between the mid-layer and the adapters.
- Asynchronous event notification mechanism from adapter to mid-layer and
peripherals.
- Better peripheral queue management: freeze/thaw, sorted requeueing during
recovery, etc.
- Clean separation of peripherals, adapters, and adapter channels (no more
scsipi_link).
- Kernel thread for each scsipi_channel makes error recovery much easier
(no more dealing with interrupt context when recovering from an error).
- Mid-layer support for tagged queueing: commands can have the tag type
set explicitly, tag IDs are allocated in the mid-layer (thus eliminating
the need to use buggy tag ID allocation schemes in many adapter drivers).
- support for QUEUE FULL and CHECK CONDITION status in mid-layer; the command
will be requeued, or a REQUEST SENSE will be sent as appropriate.

Just before the merge syssrc has been tagged with thorpej_scsipi_beforemerge
 1.1 20-Apr-2001  fredette branches: 1.1.2;
Added support for the chipset used on the Sun2 "sc" SCSI adapters.
A little rough around the edges, but definitely a starting point.
 1.1.2.3 23-Apr-2001  bouyer Port to thorpej_scsipi.
XXX SUNSCPAL_OPENINGS can certainly be lowered to 8, as we won't queue more
than one command per device.
 1.1.2.2 23-Apr-2001  bouyer Sync with HEAD.
 1.1.2.1 20-Apr-2001  bouyer file sunscpalvar.h was added on branch thorpej_scsipi on 2001-04-23 09:42:21 +0000
 1.2.24.5 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.2.24.4 04-Feb-2005  skrll Sync with HEAD.
 1.2.24.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.2.24.2 18-Sep-2004  skrll Sync with HEAD.
 1.2.24.1 03-Aug-2004  skrll Sync with HEAD
 1.2.2.2 21-Jun-2001  nathanw Catch up to -current.
 1.2.2.1 25-Apr-2001  nathanw file sunscpalvar.h was added on branch nathanw_sa on 2001-06-21 20:03:23 +0000
 1.4.6.2 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.4.6.1 12-Feb-2005  yamt sync with head.
 1.4.4.1 29-Apr-2005  kent sync with -current
 1.6.4.1 27-Oct-2007  yamt sync with head.
 1.7.50.1 25-Oct-2007  bouyer Sync with HEAD.
 1.7.46.1 06-Nov-2007  matt sync with HEAD
 1.7.44.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.7.30.1 23-Oct-2007  ad Sync with head.
 1.8.24.1 18-Jul-2008  simonb Sync with head.
 1.8.22.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.8.20.1 04-May-2009  yamt sync with head.
 1.8.16.1 28-Sep-2008  mjf Sync with HEAD.
 1.42 13-Feb-2024  andvar s/enqueing/enqueuing/ in debug messages (took a bait from recent Nick's commit)
s/occaision/occasion/ in comment.
 1.41 07-Aug-2021  thorpej Merge thorpej-cfargs2.
 1.40 24-Apr-2021  thorpej branches: 1.40.8;
Merge thorpej-cfargs branch:

Simplify and make extensible the config_search() / config_found() /
config_attach() interfaces: rather than having different variants for
which arguments you want pass along, just have a single call that
takes a variadic list of tag-value arguments.

Adjust all call sites:
- Simplify wherever possible; don't pass along arguments that aren't
actually needed.
- Don't be explicit about what interface attribute is attaching if
the device only has one. (More simplification.)
- Add a config_probe() function to be used in indirect configuiration
situations, making is visibly easier to see when indirect config is
in play, and allowing for future change in semantics. (As of now,
this is just a wrapper around config_match(), but that is an
implementation detail.)

Remove unnecessary or redundant interface attributes where they're not
needed.

There are currently 5 "cfargs" defined:
- CFARG_SUBMATCH (submatch function for direct config)
- CFARG_SEARCH (search function for indirect config)
- CFARG_IATTR (interface attribte)
- CFARG_LOCATORS (locators array)
- CFARG_DEVHANDLE (devhandle_t - wraps OFW, ACPI, etc. handles)

...and a sentinel value CFARG_EOL.

Add some extra sanity checking to ensure that interface attributes
aren't ambiguous.

Use CFARG_DEVHANDLE in MI FDT, OFW, and ACPI code, and macppc and shark
ports to associate those device handles with device_t instance. This
will trickle trough to more places over time (need back-end for pre-OFW
Sun OBP; any others?).
 1.39 03-Sep-2018  riastradh branches: 1.39.14;
Rename min/max -> uimin/uimax for better honesty.

These functions are defined on unsigned int. The generic name
min/max should not silently truncate to 32 bits on 64-bit systems.
This is purely a name change -- no functional change intended.

HOWEVER! Some subsystems have

#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))

even though our standard name for that is MIN/MAX. Although these
may invite multiple evaluation bugs, these do _not_ cause integer
truncation.

To avoid `fixing' these cases, I first changed the name in libkern,
and then compile-tested every file where min/max occurred in order to
confirm that it failed -- and thus confirm that nothing shadowed
min/max -- before changing it.

I have left a handful of bootloaders that are too annoying to
compile-test, and some dead code:

cobalt ews4800mips hp300 hppa ia64 luna68k vax
acorn32/if_ie.c (not included in any kernels)
macppc/if_gm.c (superseded by gem(4))

It should be easy to fix the fallout once identified -- this way of
doing things fails safe, and the goal here, after all, is to _avoid_
silent integer truncations, not introduce them.

Maybe one day we can reintroduce min/max as type-generic things that
never silently truncate. But we should avoid doing that for a while,
so that existing code has a chance to be detected by the compiler for
conversion to uimin/uimax without changing the semantics until we can
properly audit it all. (Who knows, maybe in some cases integer
truncation is actually intended!)
 1.38 27-Oct-2012  chs branches: 1.38.36; 1.38.38;
split device_t/softc for all remaining drivers.
replace "struct device *" with "device_t".
use device_xname(), device_unit(), etc.
 1.37 24-Aug-2012  msaitoh branches: 1.37.2;
Fix typos
 1.36 26-Jul-2011  dyoung branches: 1.36.2;
Don't set the iobase and iosize members of pcmciabus_attach_args because
they're not used in any meaningful way.
 1.35 19-Apr-2010  dyoung Add default implementations for bus_space_is_equal(9),
bus_space_tag_create(9), and bus_space_tag_destroy(9). Use
bus_space_is_equal(9) throughout the kernel to compare
bus_space_tag_t's. Tested on i386 and on sparc64.
 1.34 22-Mar-2010  dyoung pckbc.c, vga.c: It doesn't appear to be helpful to compare two
bus_space_tag_t's in pckbc_is_console() and vga_is_console(), and MI
code should never do such a thing, so don't do it.

tcic2.c: #if 0 some diagnostic code that compares two bus_space_tag_t's.
 1.33 14-Mar-2009  dsl branches: 1.33.2; 1.33.4;
ANSIfy another 1261 function definitions.
The only ones left in sys are beyond by sed script!
(or in sys/dist or sys/external)
Mostly they have function pointer parameters.
 1.32 14-Mar-2009  dsl Change about 4500 of the K&R function definitions to ANSI ones.
There are still about 1600 left, but they have ',' or /* ... */
in the actual variable definitions - which my awk script doesn't handle.
There are also many that need () -> (void).
(The script does handle misordered arguments.)
 1.31 13-Feb-2009  bouyer More printf format fixes.
 1.30 08-Apr-2008  cegger branches: 1.30.4; 1.30.12; 1.30.14; 1.30.18; 1.30.20;
use aprint_*_dev and device_xname
 1.29 29-Mar-2008  ad Make TCICDEBUG / TCICISADEBUG compile.
 1.28 19-Oct-2007  ad branches: 1.28.16;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.27 09-Jul-2007  ad branches: 1.27.6; 1.27.8; 1.27.12;
Merge some of the less invasive changes from the vmlocking branch:

- kthread, callout, devsw API changes
- select()/poll() improvements
- miscellaneous MT safety improvements
 1.26 16-Nov-2006  christos branches: 1.26.8; 1.26.10;
__unused removal on arguments; approved by core.
 1.25 12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.24 14-Apr-2006  christos branches: 1.24.8; 1.24.10;
Coverity CID 2501: Make it painfully obvious that memh is initialized.
 1.23 11-Dec-2005  christos branches: 1.23.4; 1.23.6; 1.23.8; 1.23.10; 1.23.12;
merge ktrace-lwp.
 1.22 25-Aug-2005  drochner kill a number of autoconf submatch functions which follow the
standard scheme:
if (<configured> != <wildcard> && <configured> != <real>)
then fail
else
ask device match function

This is handled by config_stdsubmatch() now.
 1.21 25-Aug-2005  drochner replace the "locdesc_t" structure carrying the number of locators
explicitely by a plain integer array
the length in now known to all relevant parties, so this avoids
duplication of information, and we can allocate that thing in
drivers without hacks
 1.20 30-May-2005  christos branches: 1.20.2;
- add missing const
- fix variable shadowing
- remove unneeded casts
 1.19 27-Feb-2005  perry nuke trailing whitespace
 1.18 04-Feb-2005  perry de-__P
 1.17 13-Sep-2004  drochner branches: 1.17.4; 1.17.6;
use locator passing versions of xxxsubmatch() and simplify the code by
using arithmetics instead of case statements
 1.16 11-Aug-2004  mycroft Add a settype function.
Nuke address windows earlier in power up sequence.
 1.15 20-Jun-2004  thorpej Define and use pcmciabuscf_controller as an alias for
cf_loc[PCMCIABUSCF_CONTROLLER] and pcmciabuscf_socket
as an alias for cf_loc[PCMCIABUSCF_SOCKET].
 1.14 28-Dec-2003  christos make the printf statements on chip_io_map complete lines.
 1.13 02-Nov-2003  wiz Fix some typos. From Tom Cosgrove via jmc@openbsd.
 1.12 01-Jan-2003  thorpej branches: 1.12.2;
Use aprint_normal() in cfprint routines.
 1.11 27-Sep-2002  thorpej Introduce a new routine, config_match(), which invokes the
cfattach->ca_match function in behalf of the caller. Use it
rather than invoking cfattach->ca_match directly.
 1.10 01-Jun-2002  lukem SIMPLEQ rototill:
- implement SIMPLEQ_REMOVE(head, elm, type, field). whilst it's O(n),
this mirrors the functionality of SLIST_REMOVE() (the other
singly-linked list type) and FreeBSD's STAILQ_REMOVE()
- remove the unnecessary elm arg from SIMPLEQ_REMOVE_HEAD().
this mirrors the functionality of SLIST_REMOVE_HEAD() (the other
singly-linked list type) and FreeBSD's STAILQ_REMOVE_HEAD()
- remove notes about SIMPLEQ not supporting arbitrary element removal
- use SIMPLEQ_FOREACH() instead of home-grown for loops
- use SIMPLEQ_EMPTY() appropriately
- use SIMPLEQ_*() instead of accessing sqh_first,sqh_last,sqe_next directly
- reorder manual page; be consistent about how the types are listed
- other minor cleanups
 1.9 15-Dec-2001  soren branches: 1.9.8;
To make dev/pcmcia work on platforms with 64-bit bus_addr_t and
32-bit bus_size_t (sparc), change the pcmcia_mem_map(9) offsetp
argument to bus_size_t as it is used as a bus_space offset.
 1.8 15-Nov-2001  lukem don't need <sys/types.h> when including <sys/param.h>
 1.7 13-Nov-2001  lukem add/cleanup RCSID
 1.6 28-Jun-2000  mrg branches: 1.6.2; 1.6.4;
remove include of <vm/vm.h>. <vm/vm.h> -> <uvm/uvm_extern.h>
 1.5 16-Jun-2000  cgd beat back the undead: __BROKEN_INDIRECT_CONFIG had risen, and was
terrorizing innocent hackers...
 1.4 08-May-2000  explorer branches: 1.4.2;
set paa_busname to pcmcia, like the i82365.c driver does.
 1.3 13-Jan-2000  joda (tcic_chip_do_mem_map): handle 8-bit memory
 1.2 06-Jul-1999  thorpej branches: 1.2.2;
Make the kthread API a bit more friendly to loadable kernel modules.
 1.1 23-Mar-1999  bad branches: 1.1.4;
A backend for Databook's TCIC family of PCMCIA chips.

Thanks to Andreas Lohrum, O'Reilly Verlag, Terry Moore, and Holger Czukay
for hardware, documentation, and support.
 1.1.4.1 02-Aug-1999  thorpej Update from trunk.
 1.2.2.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.4.2.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.6.4.3 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.6.4.2 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.6.4.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.6.2.5 03-Jan-2003  thorpej Sync with HEAD.
 1.6.2.4 18-Oct-2002  nathanw Catch up to -current.
 1.6.2.3 20-Jun-2002  nathanw Catch up to -current.
 1.6.2.2 08-Jan-2002  nathanw Catch up to -current.
 1.6.2.1 14-Nov-2001  nathanw Catch up to -current.
 1.9.8.1 20-Jun-2002  gehenna catch up with -current.
 1.12.2.7 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.12.2.6 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.12.2.5 04-Feb-2005  skrll Sync with HEAD.
 1.12.2.4 21-Sep-2004  skrll Fix the sync with head I botched.
 1.12.2.3 18-Sep-2004  skrll Sync with HEAD.
 1.12.2.2 12-Aug-2004  skrll Sync with HEAD.
 1.12.2.1 03-Aug-2004  skrll Sync with HEAD
 1.17.6.2 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.17.6.1 12-Feb-2005  yamt sync with head.
 1.17.4.1 29-Apr-2005  kent sync with -current
 1.20.2.4 27-Oct-2007  yamt sync with head.
 1.20.2.3 03-Sep-2007  yamt sync with head.
 1.20.2.2 30-Dec-2006  yamt sync with head.
 1.20.2.1 21-Jun-2006  yamt sync with head.
 1.23.12.1 24-May-2006  tron Merge 2006-05-24 NetBSD-current into the "peter-altq" branch.
 1.23.10.1 19-Apr-2006  elad sync with head.
 1.23.8.1 24-May-2006  yamt sync with head.
 1.23.6.1 22-Apr-2006  simonb Sync with head.
 1.23.4.1 09-Sep-2006  rpaulo sync with head
 1.24.10.2 10-Dec-2006  yamt sync with head.
 1.24.10.1 22-Oct-2006  yamt sync with head
 1.24.8.1 18-Nov-2006  ad Sync with head.
 1.26.10.1 11-Jul-2007  mjf Sync with head.
 1.26.8.4 23-Oct-2007  ad Sync with head.
 1.26.8.3 13-May-2007  ad - Pass the error number and residual count to biodone(), and let it handle
setting error indicators. Prepare to eliminate B_ERROR.
- Add a flag argument to brelse() to be set into the buf's flags, instead
of doing it directly. Typically used to set B_INVAL.
- Add a "struct cpu_info *" argument to kthread_create(), to be used to
create bound threads. Change "bool mpsafe" to "int flags".
- Allow exit of LWPs in the IDL state when (l != curlwp).
- More locking fixes & conversion to the new API.
 1.26.8.2 10-Apr-2007  ad Nuke the deferred kthread creation stuff, as it's no longer needed.
Pointed out by thorpej@.
 1.26.8.1 09-Apr-2007  ad - Add two new arguments to kthread_create1: pri_t pri, bool mpsafe.
- Fork kthreads off proc0 as new LWPs, not new processes.
 1.27.12.1 25-Oct-2007  bouyer Sync with HEAD.
 1.27.8.1 06-Nov-2007  matt sync with HEAD
 1.27.6.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.28.16.2 02-Jun-2008  mjf Sync with HEAD.
 1.28.16.1 03-Apr-2008  mjf Sync with HEAD.
 1.30.20.1 26-Jul-2009  snj branches: 1.30.20.1.2;
Pull up following revision(s) (requested by dholland in ticket #874):
sys/dev/ic/ciss.c: revision 1.15
sys/dev/isa/isadma.c: revision 1.59
sys/dev/usb/ulpt.c: revision 1.82
sys/dev/ic/tcic2.c: revision 1.31
sys/dev/isa/if_ntwoc_isa.c: revision 1.18
sys/dev/pci/if_sk.c: revision 1.57
sys/dev/pcmcia/if_cnw.c: revision 1.46
More printf format fixes.
 1.30.20.1.2.1 21-Apr-2010  matt sync to netbsd-5
 1.30.18.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.30.14.1 26-Jul-2009  snj Pull up following revision(s) (requested by dholland in ticket #874):
sys/dev/ic/ciss.c: revision 1.15
sys/dev/isa/isadma.c: revision 1.59
sys/dev/usb/ulpt.c: revision 1.82
sys/dev/ic/tcic2.c: revision 1.31
sys/dev/isa/if_ntwoc_isa.c: revision 1.18
sys/dev/pci/if_sk.c: revision 1.57
sys/dev/pcmcia/if_cnw.c: revision 1.46
More printf format fixes.
 1.30.12.2 28-Apr-2009  skrll Sync with HEAD.
 1.30.12.1 03-Mar-2009  skrll Sync with HEAD.
 1.30.4.2 11-Aug-2010  yamt sync with head.
 1.30.4.1 04-May-2009  yamt sync with head.
 1.33.4.1 30-May-2010  rmind sync with head
 1.33.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.36.2.1 30-Oct-2012  yamt sync with head
 1.37.2.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.38.38.1 10-Jun-2019  christos Sync with HEAD
 1.38.36.1 06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.39.14.2 22-Mar-2021  thorpej Audit CFARG_IATTR in config_found() calls, and remove it in situations
where the interface attribute is not ambiguous.
 1.39.14.1 22-Mar-2021  thorpej Mechanical conversion of config_found_sm_loc() -> config_found().
CFARG_IATTR usage needs to be audited.
 1.40.8.1 04-Aug-2021  thorpej Adapt to CFARGS().
 1.6 09-Feb-2024  andvar fix spelling mistakes, mainly in comments and log messages.
 1.5 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.4 11-Dec-2005  christos branches: 1.4.70; 1.4.72; 1.4.74;
merge ktrace-lwp.
 1.3 27-Feb-2005  perry nuke trailing whitespace
 1.2 02-Nov-2003  wiz branches: 1.2.8; 1.2.10;
Fix some typos. From Tom Cosgrove via jmc@openbsd.
 1.1 23-Mar-1999  bad branches: 1.1.42;
A backend for Databook's TCIC family of PCMCIA chips.

Thanks to Andreas Lohrum, O'Reilly Verlag, Terry Moore, and Holger Czukay
for hardware, documentation, and support.
 1.1.42.4 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.1.42.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.1.42.2 18-Sep-2004  skrll Sync with HEAD.
 1.1.42.1 03-Aug-2004  skrll Sync with HEAD
 1.2.10.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.2.8.1 29-Apr-2005  kent sync with -current
 1.4.74.1 16-May-2008  yamt sync with head.
 1.4.72.1 18-May-2008  yamt sync with head.
 1.4.70.1 02-Jun-2008  mjf Sync with HEAD.
 1.15 05-Mar-2020  riastradh Revert "Include opt_diagnostic.h for DIAGNOSTIC."

This did not do what I thought it did. opt_diagnostic.h is only for
the unused _DIAGNOSTIC, which seems like an abortive attempt to
incrementally convert DIAGNOSTIC to an opt_*.h option rather than a
command-line option.
 1.14 05-Mar-2020  riastradh Include opt_diagnostic.h for DIAGNOSTIC.

...at least, in header files, which may not have already included
libkern.h.
 1.13 27-Oct-2012  chs split device_t/softc for all remaining drivers.
replace "struct device *" with "device_t".
use device_xname(), device_unit(), etc.
 1.12 12-May-2009  cegger branches: 1.12.12; 1.12.22;
struct device * -> device_t, no functional changes intended.
 1.11 16-Mar-2009  cegger ansify function definitions
 1.10 09-Jul-2007  ad branches: 1.10.32; 1.10.42; 1.10.48;
Merge some of the less invasive changes from the vmlocking branch:

- kthread, callout, devsw API changes
- select()/poll() improvements
- miscellaneous MT safety improvements
 1.9 03-Sep-2006  christos branches: 1.9.12; 1.9.14;
add missing decl
 1.8 16-Feb-2006  perry branches: 1.8.2;
Change "inline" back to "__inline" in .h files -- C99 is still too
new, and some apps compile things in C89 mode. C89 keywords stay.

As per core@.
 1.7 24-Dec-2005  perry branches: 1.7.2; 1.7.4; 1.7.6;
__inline__ -> inline
 1.6 11-Dec-2005  christos merge ktrace-lwp.
 1.5 30-May-2005  christos branches: 1.5.2;
- add missing const
- fix variable shadowing
- remove unneeded casts
 1.4 04-Feb-2005  perry de-__P
 1.3 11-Aug-2004  mycroft branches: 1.3.4; 1.3.6;
Add a settype function.
Nuke address windows earlier in power up sequence.
 1.2 15-Dec-2001  soren branches: 1.2.16;
To make dev/pcmcia work on platforms with 64-bit bus_addr_t and
32-bit bus_size_t (sparc), change the pcmcia_mem_map(9) offsetp
argument to bus_size_t as it is used as a bus_space offset.
 1.1 23-Mar-1999  bad branches: 1.1.20; 1.1.22;
A backend for Databook's TCIC family of PCMCIA chips.

Thanks to Andreas Lohrum, O'Reilly Verlag, Terry Moore, and Holger Czukay
for hardware, documentation, and support.
 1.1.22.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.1.20.1 08-Jan-2002  nathanw Catch up to -current.
 1.2.16.5 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.2.16.4 04-Feb-2005  skrll Sync with HEAD.
 1.2.16.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.2.16.2 18-Sep-2004  skrll Sync with HEAD.
 1.2.16.1 12-Aug-2004  skrll Sync with HEAD.
 1.3.6.1 12-Feb-2005  yamt sync with head.
 1.3.4.1 29-Apr-2005  kent sync with -current
 1.5.2.3 03-Sep-2007  yamt sync with head.
 1.5.2.2 30-Dec-2006  yamt sync with head.
 1.5.2.1 21-Jun-2006  yamt sync with head.
 1.7.6.1 22-Apr-2006  simonb Sync with head.
 1.7.4.1 09-Sep-2006  rpaulo sync with head
 1.7.2.1 18-Feb-2006  yamt sync with head.
 1.8.2.1 03-Sep-2006  yamt sync with head.
 1.9.14.1 11-Jul-2007  mjf Sync with head.
 1.9.12.1 09-Apr-2007  ad - Add two new arguments to kthread_create1: pri_t pri, bool mpsafe.
- Fork kthreads off proc0 as new LWPs, not new processes.
 1.10.48.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.10.42.1 28-Apr-2009  skrll Sync with HEAD.
 1.10.32.2 16-May-2009  yamt sync with head
 1.10.32.1 04-May-2009  yamt sync with head.
 1.12.22.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.12.12.1 30-Oct-2012  yamt sync with head
 1.5 11-Dec-2005  christos merge ktrace-lwp.
 1.4 02-Jun-2005  christos simplify weird tests.
 1.3 14-Jul-2003  lukem add missing __KERNEL_RCSID()
 1.2 03-Sep-2002  augustss branches: 1.2.6;
Use a different way to recognize tea5759 chips. From OpenBSD.
 1.1 01-Jan-2002  augustss branches: 1.1.2; 1.1.4;
Add support for radio cards. Written by Maxim Tsyplakov and Vladimir Popov
for OpenBSD, from where it was imported.
 1.1.4.3 06-Sep-2002  jdolecek sync kqueue branch with HEAD
 1.1.4.2 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.1.4.1 01-Jan-2002  thorpej file tea5757.c was added on branch kqueue on 2002-01-10 19:55:05 +0000
 1.1.2.3 17-Sep-2002  nathanw Catch up to -current.
 1.1.2.2 08-Jan-2002  nathanw Catch up to -current.
 1.1.2.1 01-Jan-2002  nathanw file tea5757.c was added on branch nathanw_sa on 2002-01-08 00:30:06 +0000
 1.2.6.4 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.2.6.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.2.6.2 18-Sep-2004  skrll Sync with HEAD.
 1.2.6.1 03-Aug-2004  skrll Sync with HEAD
 1.3 19-Oct-2007  ad machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.2 03-Sep-2002  augustss branches: 1.2.22; 1.2.64; 1.2.78; 1.2.80; 1.2.84;
Use a different way to recognize tea5759 chips. From OpenBSD.
 1.1 01-Jan-2002  augustss branches: 1.1.2; 1.1.4;
Add support for radio cards. Written by Maxim Tsyplakov and Vladimir Popov
for OpenBSD, from where it was imported.
 1.1.4.3 06-Sep-2002  jdolecek sync kqueue branch with HEAD
 1.1.4.2 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.1.4.1 01-Jan-2002  thorpej file tea5757.h was added on branch kqueue on 2002-01-10 19:55:06 +0000
 1.1.2.3 17-Sep-2002  nathanw Catch up to -current.
 1.1.2.2 08-Jan-2002  nathanw Catch up to -current.
 1.1.2.1 01-Jan-2002  nathanw file tea5757.h was added on branch nathanw_sa on 2002-01-08 00:30:07 +0000
 1.2.84.1 25-Oct-2007  bouyer Sync with HEAD.
 1.2.80.1 06-Nov-2007  matt sync with HEAD
 1.2.78.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.2.64.1 23-Oct-2007  ad Sync with head.
 1.2.22.1 27-Oct-2007  yamt sync with head.
 1.12 27-Oct-2012  chs split device_t/softc for all remaining drivers.
replace "struct device *" with "device_t".
use device_xname(), device_unit(), etc.
 1.11 12-May-2009  cegger branches: 1.11.12; 1.11.22;
struct device * -> device_t, no functional changes intended.
 1.10 12-May-2009  cegger struct cfdata * -> cfdata_t, no functional changes intended.
 1.9 28-Apr-2008  martin branches: 1.9.14;
Remove clause 3 and 4 from TNF licenses
 1.8 19-Oct-2007  ad branches: 1.8.16; 1.8.18; 1.8.20;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.7 11-Dec-2005  christos branches: 1.7.30; 1.7.44; 1.7.46; 1.7.50;
merge ktrace-lwp.
 1.6 14-Jul-2003  lukem branches: 1.6.16;
add missing __KERNEL_RCSID()
 1.5 02-Oct-2002  thorpej branches: 1.5.6;
Add trailing ; to CFATTACH_DECL.
 1.4 30-Sep-2002  thorpej Use CFATTACH_DECL().
 1.3 27-Sep-2002  thorpej Declare all cfattach structures const.
 1.2 13-Jun-2002  augustss branches: 1.2.2; 1.2.4;
Use consistent naming.
 1.1 21-May-2002  augustss branches: 1.1.4;
Add a driver for the IBM CPC700 chip. This chip is a host bridge for
PowerPC and provides a PCI-host bridge, interrupt controller, two com ports,
two IIC ports, a timer, and a DRAM controller.
The driver supports PCI, interrupts and com ports.
 1.1.4.3 20-Jun-2002  gehenna catch up with -current.
 1.1.4.2 30-May-2002  gehenna Catch up with -current.
 1.1.4.1 21-May-2002  gehenna file timer_cpcbus.c was added on branch gehenna-devsw on 2002-05-30 14:46:01 +0000
 1.2.4.3 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.2.4.2 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.2.4.1 13-Jun-2002  jdolecek file timer_cpcbus.c was added on branch kqueue on 2002-06-23 17:46:53 +0000
 1.2.2.3 18-Oct-2002  nathanw Catch up to -current.
 1.2.2.2 20-Jun-2002  nathanw Catch up to -current.
 1.2.2.1 13-Jun-2002  nathanw file timer_cpcbus.c was added on branch nathanw_sa on 2002-06-20 03:45:04 +0000
 1.5.6.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.5.6.2 18-Sep-2004  skrll Sync with HEAD.
 1.5.6.1 03-Aug-2004  skrll Sync with HEAD
 1.6.16.1 27-Oct-2007  yamt sync with head.
 1.7.50.1 25-Oct-2007  bouyer Sync with HEAD.
 1.7.46.1 06-Nov-2007  matt sync with HEAD
 1.7.44.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.7.30.1 23-Oct-2007  ad Sync with head.
 1.8.20.2 16-May-2009  yamt sync with head
 1.8.20.1 16-May-2008  yamt sync with head.
 1.8.18.1 18-May-2008  yamt sync with head.
 1.8.16.1 02-Jun-2008  mjf Sync with HEAD.
 1.9.14.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.11.22.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.11.12.1 30-Oct-2012  yamt sync with head
 1.27 08-Jun-2019  isaki Clean get_props().
- Make get_props() return AUDIO_PROP_{PLAYBACK,CAPTURE} properly.
This eliminates need for audio.c to take care of such (old)
drivers which don't return both of PLAYBACK and CAPTURE.
- All get_props() doesn't need to return AUDIO_PROP_MMAP.
It is handled in the audio layer now.
 1.26 08-May-2019  isaki Merge isaki-audio2 branch, the overhaul of audio subsystem.
- Interrupt-oriented system rather than thread-oriented.
- Improve stability, quality and performance.
- Split playback and record cleanly. Improve halfduplex support.
- Many bugs are fixed including deadlocks, resource leaks, abuses, etc.
- Simplify audio filter mechanism. The encoding/channels/frequency
conversions are completely handled in the upper layer. So the hard-
ware driver only converts its hardware encoding (if necessary).
- audio_hw_if changes:
- Obsoletes query_encoding and add query_format instead.
- Obsoletes set_params and add set_format instead.
- Remove drain, setfd, mappage.
- The call sequences are changed.
- ioctl AUDIO_GETFD/SETFD, AUDIO_GETCHAN/SETCHAN are obsoleted.
- ioctl AUDIO_{QUERY,GET,SET}FORMAT are introduced.
- cleanup config attributes: au*conv and mulaw.
- All hardware drivers should follow it (I've done as much as possible).

Some file paths are changed:
- dev/audio.c -> dev/audio/audio.c (rewritten)
- dev/audiovar.h -> dev/audio/audiovar.h
- dev/audio_dai.h -> dev/audio/audio_dai.h
- dev/audio_if.h -> dev/audio/audio_if.h
- dev/audiobell.c -> dev/audio/audiobell.c
- dev/audiobellvar.h -> dev/audio/audiobellvar.h
- dev/mulaw.[ch] -> dev/audio/mulaw.[ch] + dev/audio/alaw.c
 1.25 16-Mar-2019  isaki branches: 1.25.2;
Use C99 style struct initializer to audio_hw_if.
 1.24 16-Mar-2019  isaki Make it compilable (remove unused variables).
 1.23 27-Oct-2012  chs branches: 1.23.12; 1.23.30; 1.23.38;
split device_t/softc for all remaining drivers.
replace "struct device *" with "device_t".
use device_xname(), device_unit(), etc.
 1.22 23-Nov-2011  jmcneill branches: 1.22.8;
Merge jmcneill-audiomp3 branch, which is derived from ad-audiomp2. From
the original ad-audiomp branch notes:

Add MP locking to the audio drivers.

Making the audio drivers MP safe is necessary before efforts
can be made to make the VM system MP safe.

The are two locks per device instance, an ISR lock and
a character device lock. The ISR lock replaces calls to
splaudio()/splx(), and will be held across calls to device
methods which were called at splaudio() before (e.g.
trigger_output). The character device lock is held across
calls to nearly all of the methods, excluding some only
used for initialization, e.g. get_locks.

Welcome to 5.99.57.
 1.21 28-Apr-2008  martin branches: 1.21.34; 1.21.36;
Remove clause 3 and 4 from TNF licenses
 1.20 08-Apr-2008  cegger branches: 1.20.2; 1.20.4;
use aprint_*_dev and device_xname
 1.19 19-Oct-2007  ad branches: 1.19.16;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.18 11-Dec-2005  christos branches: 1.18.28; 1.18.30; 1.18.44; 1.18.46; 1.18.50;
merge ktrace-lwp.
 1.17 15-Jan-2005  kent branches: 1.17.10;
ansify and KNF
 1.16 10-Jan-2005  kent merge kent-audio1 branch, which introduces audio filter pipeline to the MI
audio framework


Summary of changes:

* struct audio_params
- remove sw_code, factor, factor_denom, hw_sample_rate,
hw_encoding ,hw_precision, and hw_channels. Conversion information
is conveyed by stream_filter_list_t.
- change the type of sample_rate: u_long -> u_int
- add `validbits,' which represents the valid data size in
precision bits. It is required in order to distinguish 24/32bit
from 24/24bit or 32/32bit.

* audio_hw_if
- add two parameters to set_params()
stream_filter_list_t *pfil, stream_filter_list *rfil
A HW driver should set filter recipes for requested formats
- constify audio_params parameters of trigger_output() and
trigger_input(). They represent audio formats for the hardware.
- make open() and close() optional
- add int (AUMODE_PLAY or AUMODE_RECORD) and audio_params_t parameters
to round_blocksize()

* sw_code is replaced with stream_filter_t.
stream_filer_t converts audio data in an input buffer and writes
into another output buffer unlike sw_code, which converts data in
single buffer.
converters in dev/auconv.c, dev/mulaw.c, dev/aurateconv.c,
dev/tc/bba.c, dev/ic/msm6258.c, and arch/arm/iomd/vidcaudio.c are
reimplemented as stream_filter_t

* MI audio
- audiosetinfo() builds filter pipelines from stream_filter_list_t
filled by audio_hw_if::set_params()
- audiosetinfo() returns with EINVAL if mmapped and set_params()
requests filters
- audio_write(), audio_pint(), and audio_rint() invoke a filter
pipeline.
- ioctl() for FIONREAD, AUDIO_WSEEK, AUDIO_GETIOFFS,
AUDIO_GETOOFFS, and audio_prinfo::{seek,samples} for
AUDIO_GETINFO handle values for a buffer nearest to userland.

* add `struct device *' parameter to ac97_attach()

* all of audio HW drivers follow audio_hw_if and ac97 changes
 1.15 29-Oct-2004  yamt branches: 1.15.2;
constify audio_hw_if, midi_hw_if, and radio_hw_if.
 1.14 09-Jul-2004  mycroft Remove junk code.
 1.13 22-Apr-2004  itojun sprintf -> snprintf
 1.12 06-Jan-2003  wiz branches: 1.12.2;
interrupt with two rs.
 1.11 15-Nov-2001  lukem don't need <sys/types.h> when including <sys/param.h>
 1.10 13-Nov-2001  lukem add/cleanup RCSID
 1.9 03-Oct-2001  augustss Add a new optional method, dev_ioctl, to the audio hardware driver interface.
It is called when an unrecognized ioctl() is performed on a device,
thus allowing ioctl()s that frob the hardware driver (like loading
microcode).
 1.8 16-Feb-1999  is branches: 1.8.20; 1.8.22; 1.8.24;
Fix Copyright dates
 1.7 16-Feb-1999  is Assign my files to The NetBSD Foundation, Inc.
 1.6 17-Aug-1998  augustss * Redo the way the way the MIDI driver attaches to audio devices.
* Improve the midisyn layer a little.
* Add a driver for the Yamaha OPL[23] FM synths.
The opl driver is not finished yet; it sounds pretty awful.

For some strange reason I cannot get any FM sound from my SB64 cards,
but a regular SB16 works fine.
 1.5 20-Oct-1997  is Dont waste time in delay()s... else we won't finish in time to get our first
lowwatermark interupt for AUDIO_BYPASS data.
 1.4 19-Oct-1997  is Fix pasto in symbolic name for string
 1.3 19-Oct-1997  is tav_write_word -> tav_write_short
 1.2 19-Oct-1997  augustss Make the audio API (almost) SunOS compatible.
The changes is to allow some limited mixer manipulation through
the audio device (instead of the mixer device).
This rendered 4 methods in audio_hw_if unused so garbage collect these.
 1.1 16-Oct-1997  is TMS320AV110 (mpeg layer 2 decoder chip) and ZBUS Melody board, which uses it.
No optionboards yet for Melody, only audio driver.
MPEG data types for audio.c
 1.8.24.1 11-Oct-2001  fvdl Catch up with -current. Fix some bogons in the sparc64 kbd/ms
attach code. cd18xx conversion provided by mrg.
 1.8.22.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.8.20.4 07-Jan-2003  thorpej Sync with HEAD.
 1.8.20.3 08-Jan-2002  nathanw Catch up to -current.
 1.8.20.2 14-Nov-2001  nathanw Catch up to -current.
 1.8.20.1 08-Oct-2001  nathanw Catch up to -current.
 1.12.2.5 17-Jan-2005  skrll Sync with HEAD.
 1.12.2.4 02-Nov-2004  skrll Sync with HEAD.
 1.12.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.12.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.12.2.1 03-Aug-2004  skrll Sync with HEAD
 1.15.2.2 09-Jan-2005  kent audio_hw_if change
* make open() and close() optional
* add int (AUMODE_PLAY or AUMODE_RECORD) and audio_params_t parameters
to round_blocksize()
 1.15.2.1 03-Jan-2005  kent adopt the filter pipeline framework
 1.17.10.1 27-Oct-2007  yamt sync with head.
 1.18.50.1 25-Oct-2007  bouyer Sync with HEAD.
 1.18.46.1 06-Nov-2007  matt sync with HEAD
 1.18.44.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.18.30.1 23-Oct-2007  ad Sync with head.
 1.18.28.1 27-Feb-2007  ad Add MP locking for audio drivers.
 1.19.16.1 02-Jun-2008  mjf Sync with HEAD.
 1.20.4.1 16-May-2008  yamt sync with head.
 1.20.2.1 18-May-2008  yamt sync with head.
 1.21.36.2 22-Nov-2011  jmcneill get rid of unused 'powerstate' callback in audio_hw_if
 1.21.36.1 20-Nov-2011  jmcneill adapt to audiomp api changes
 1.21.34.2 30-Oct-2012  yamt sync with head
 1.21.34.1 17-Apr-2012  yamt sync with head
 1.22.8.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.23.38.1 10-Jun-2019  christos Sync with HEAD
 1.23.30.1 08-Mar-2020  martin Pull up following revision(s) (requested by is in ticket #1516):

sys/dev/ic/tms320av110.c: revision 1.24

Make it compilable (remove unused variables).
 1.23.12.1 08-Mar-2020  martin Pull up following revision(s) (requested by is in ticket #1723):

sys/dev/ic/tms320av110.c: revision 1.24

Make it compilable (remove unused variables).
 1.25.2.3 04-May-2019  isaki Move dev/audio_if.h -> dev/audio/audio_if.h
 1.25.2.2 25-Apr-2019  isaki Add missing mutex_exit() in interrupt handler.
 1.25.2.1 25-Apr-2019  isaki Adapt to audio2.
- Starting playback in init_output() no longer works.
Introduce sc_active flag instead and do it in start_output().
 1.4 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.3 16-Feb-1999  is branches: 1.3.140; 1.3.142; 1.3.144;
Fix Copyright dates
 1.2 16-Feb-1999  is Assign my files to The NetBSD Foundation, Inc.
 1.1 16-Oct-1997  is TMS320AV110 (mpeg layer 2 decoder chip) and ZBUS Melody board, which uses it.
No optionboards yet for Melody, only audio driver.
MPEG data types for audio.c
 1.3.144.1 16-May-2008  yamt sync with head.
 1.3.142.1 18-May-2008  yamt sync with head.
 1.3.140.1 02-Jun-2008  mjf Sync with HEAD.
 1.13 08-May-2019  isaki Merge isaki-audio2 branch, the overhaul of audio subsystem.
- Interrupt-oriented system rather than thread-oriented.
- Improve stability, quality and performance.
- Split playback and record cleanly. Improve halfduplex support.
- Many bugs are fixed including deadlocks, resource leaks, abuses, etc.
- Simplify audio filter mechanism. The encoding/channels/frequency
conversions are completely handled in the upper layer. So the hard-
ware driver only converts its hardware encoding (if necessary).
- audio_hw_if changes:
- Obsoletes query_encoding and add query_format instead.
- Obsoletes set_params and add set_format instead.
- Remove drain, setfd, mappage.
- The call sequences are changed.
- ioctl AUDIO_GETFD/SETFD, AUDIO_GETCHAN/SETCHAN are obsoleted.
- ioctl AUDIO_{QUERY,GET,SET}FORMAT are introduced.
- cleanup config attributes: au*conv and mulaw.
- All hardware drivers should follow it (I've done as much as possible).

Some file paths are changed:
- dev/audio.c -> dev/audio/audio.c (rewritten)
- dev/audiovar.h -> dev/audio/audiovar.h
- dev/audio_dai.h -> dev/audio/audio_dai.h
- dev/audio_if.h -> dev/audio/audio_if.h
- dev/audiobell.c -> dev/audio/audiobell.c
- dev/audiobellvar.h -> dev/audio/audiobellvar.h
- dev/mulaw.[ch] -> dev/audio/mulaw.[ch] + dev/audio/alaw.c
 1.12 27-Oct-2012  chs branches: 1.12.38; 1.12.42;
split device_t/softc for all remaining drivers.
replace "struct device *" with "device_t".
use device_xname(), device_unit(), etc.
 1.11 23-Nov-2011  jmcneill branches: 1.11.8;
Merge jmcneill-audiomp3 branch, which is derived from ad-audiomp2. From
the original ad-audiomp branch notes:

Add MP locking to the audio drivers.

Making the audio drivers MP safe is necessary before efforts
can be made to make the VM system MP safe.

The are two locks per device instance, an ISR lock and
a character device lock. The ISR lock replaces calls to
splaudio()/splx(), and will be held across calls to device
methods which were called at splaudio() before (e.g.
trigger_output). The character device lock is held across
calls to nearly all of the methods, excluding some only
used for initialization, e.g. get_locks.

Welcome to 5.99.57.
 1.10 28-Apr-2008  martin branches: 1.10.34; 1.10.36;
Remove clause 3 and 4 from TNF licenses
 1.9 19-Oct-2007  ad branches: 1.9.16; 1.9.18; 1.9.20;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.8 16-Feb-2006  perry branches: 1.8.24; 1.8.38; 1.8.40; 1.8.44;
Change "inline" back to "__inline" in .h files -- C99 is still too
new, and some apps compile things in C89 mode. C89 keywords stay.

As per core@.
 1.7 24-Dec-2005  perry branches: 1.7.2; 1.7.4; 1.7.6;
Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.6 11-Dec-2005  christos merge ktrace-lwp.
 1.5 15-Jan-2005  kent branches: 1.5.10;
ansify and KNF
 1.4 06-Jan-2003  wiz branches: 1.4.2;
interrupt with two rs.
 1.3 16-Feb-1999  is branches: 1.3.20;
Fix Copyright dates
 1.2 16-Feb-1999  is Assign my files to The NetBSD Foundation, Inc.
 1.1 16-Oct-1997  is TMS320AV110 (mpeg layer 2 decoder chip) and ZBUS Melody board, which uses it.
No optionboards yet for Melody, only audio driver.
MPEG data types for audio.c
 1.3.20.1 07-Jan-2003  thorpej Sync with HEAD.
 1.4.2.1 17-Jan-2005  skrll Sync with HEAD.
 1.5.10.1 27-Oct-2007  yamt sync with head.
 1.7.6.1 22-Apr-2006  simonb Sync with head.
 1.7.4.1 09-Sep-2006  rpaulo sync with head
 1.7.2.1 18-Feb-2006  yamt sync with head.
 1.8.44.1 25-Oct-2007  bouyer Sync with HEAD.
 1.8.40.1 06-Nov-2007  matt sync with HEAD
 1.8.38.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.8.24.1 23-Oct-2007  ad Sync with head.
 1.9.20.1 16-May-2008  yamt sync with head.
 1.9.18.1 18-May-2008  yamt sync with head.
 1.9.16.1 02-Jun-2008  mjf Sync with HEAD.
 1.10.36.1 20-Nov-2011  jmcneill adapt to audiomp api changes
 1.10.34.2 30-Oct-2012  yamt sync with head
 1.10.34.1 17-Apr-2012  yamt sync with head
 1.11.8.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.12.42.1 25-Apr-2019  isaki Adapt to audio2.
- Starting playback in init_output() no longer works.
Introduce sc_active flag instead and do it in start_output().
 1.12.38.1 10-Jun-2019  christos Sync with HEAD
 1.2 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.1 02-Jun-2003  gmcgarry branches: 1.1.100; 1.1.102; 1.1.104;
Register definitions for TMS 9914 GPIB controller.
 1.1.104.1 16-May-2008  yamt sync with head.
 1.1.102.1 18-May-2008  yamt sync with head.
 1.1.100.1 02-Jun-2008  mjf Sync with HEAD.
 1.29 14-May-2024  riastradh tpm(4): device_printf needs \n.

Observed in PR 58255.
 1.28 04-Jul-2023  riastradh tpm(4): Switch tsleep to kpause.

Nothing is interrupt-driven here, so no need for condvars to allow
more prompt wakeups.
 1.27 25-Sep-2022  thorpej Remove unnecessary include of <sys/malloc.h>.
 1.26 07-Sep-2022  khorben tpm(4): add missing newline character in device_printf()

Observed with on a Sun Ultra 24, NetBSD/amd64:

tpm0 at acpi0 (TPM, IFX0102-1): io 0x4e-0x4f,0x4700-0x470b mem 0xfed40000-0xfed44fff
tpm0: device 0x000b15d1 rev 0x10
tpm0: read 8 bytes, expected 10tpm0: deactivating entropy source
 1.25 29-Jan-2022  riastradh tpm(4): Nix TPM_BE16/TPM_BE32. Just use sys/endian.h.
 1.24 16-Jan-2022  riastradh tpm(4): Fix suspend and rework I/O transaction lock.

Use sc->sc_lock over individual I/O transactions, not open/close of
the whole device. This way there is a bounded time before the tpm is
unbusied even if userland is getting at it, so userland can't hold up
suspend indefinitely. Of course, the tpm might be suspended and
resumed in the middle of the user's session this way -- tough.

This limits the response buffer to 1024 bytes -- which is already a
bit hefty to have on the stack (but it's probably not very deep on
the stack from userland so maybe not a big deal). If it turns out we
need more, we can use kmem to allocate a buffer on the heap, with the
caveat that it might fail. This is necessary so that suspend doesn't
block indefinitely on uiomove in tpmread.
 1.23 20-Dec-2021  riastradh tpm(4): Fix disabling of rnd source if tpm is deactivated.

Nothing prevents a second worker from being queued when the first one
is about to do rnd_detach_source. Instead, just set a flag so future
requests don't bother running a new thread; if there's a concurrent
one that's already been scheduled on another CPU, well, too bad, we
get a couple extra log messages but that's fine.

A better way to do this would probably be to detect whether the tpm
is deactivated at attach time, but that requires reading more of the
tpm spec than I care to do when there are alternative ways to
procrastinate like scrubbing the toilet.
 1.22 02-Jun-2021  riastradh tpm(4): Preserve error if any on ending commands.

This way we don't spuriously suppress an error, such as
TPM_DEACTIVATED, in a loop where we rely on it.
 1.21 29-May-2021  riastradh branches: 1.21.2;
tpm(4): Handle TPM 2.0 random source too, and loop on short reads.

Tested on ThinkPad T480.
 1.20 22-May-2021  thorpej Remove extra newline from boot messages (isa and acpi front-ends
already provide the newline).
 1.19 04-Jan-2021  riastradh branches: 1.19.4; 1.19.6;
dev/ic/tpm: Take advantage of entropy source if available.

If the tpm is deactivated, though, detach the entropy source so we
don't continue to try polling it -- it can't be activated without a
reboot anyway.
 1.18 04-Jan-2021  riastradh dev/ic/tpm: Add missing line break in attach output.
 1.17 04-Jan-2021  riastradh dev/ic/tpm: Tidy up headers.

- Add include guards.
- Add necessary includes.
- Sort includes.
- Use _BYTE_ORDER, not BYTE_ORDER, for public header.
 1.16 09-Oct-2019  maxv branches: 1.16.8;
Provide a better abstraction for the TPM interface. Report it in the ioctl.
 1.15 09-Oct-2019  maxv Add suspend support for TPM 2.0 chips. Check the TPM response also for 1.2
chips. Unfortunately I cannot really test this change since ACPI suspend
does not work on any of my laptops.
 1.14 08-Oct-2019  maxv Improvements in tpm(4):
- Remove interrupt support, do polling only, avoids unnecessary trouble.
- Simplify a few things.
- Fix the suspend function, the SaveState command is 0x98, not 0x9C.
- Make the driver MP-safe.
- Sync the man page with reality.
 1.13 22-Jun-2019  maxv branches: 1.13.2;
Revamp the TPM driver

* Fix several bugs, and clean up.
* Drop the "legacy" interface, it relied on an undocumented global
variable that was never initialized. It likely had never been tested
either, so good riddance.
* Add support for TPM 2.0 chips via ACPI. For these we use the TIS1.2
interface, same as TPM 1.2.
* Provide an ioctl to fetch TPM information from the driver.

Tested on a Lenovo desktop with ACPI-TPM2.0, an HP laptop ACPI-TPM2.0, a
Dell laptop with ISA-TPM1.2.
 1.12 28-Oct-2017  riastradh branches: 1.12.4;
Kill some more extern struct cfdriver declarations.

Down with externs in .c!
 1.11 25-Jul-2014  dholland Add d_discard to all struct cdevsw instances I could find.

All have been set to "nodiscard"; some should get a real implementation.
 1.10 16-Mar-2014  dholland branches: 1.10.2;
Change (mostly mechanically) every cdevsw/bdevsw I can find to use
designated initializers.

I have not built every extant kernel so I have probably broken at
least one build; however I've also found and fixed some wrong
cdevsw/bdevsw entries so even if so I think we come out ahead.
 1.9 17-Oct-2013  christos - remove unused variables
- move variables inside ifdef sections
- ifdef notdef unused code
- use __USE for debugging variables
 1.8 14-Sep-2013  joerg GC unused functions and variables.
 1.7 06-Feb-2012  christos branches: 1.7.4; 1.7.6; 1.7.10; 1.7.14;
PR/45932: Pierre Pronchery: Fix the return values of the suspend and resume
functions.
 1.6 03-Feb-2012  christos shutup debug.
 1.5 03-Feb-2012  christos don't try to write in a const buffer.
 1.4 23-Jan-2012  christos reduce the polling interval to 2 seconds, and try harder to get interrupts
working.
 1.3 22-Jan-2012  christos cosmetic fixes
 1.2 22-Jan-2012  christos as jared noted, this is not mpsafe.
 1.1 22-Jan-2012  christos add a tpm driver from bsssd.sourceforge.net
 1.7.14.1 18-May-2014  rmind sync with head
 1.7.10.2 03-Dec-2017  jdolecek update from HEAD
 1.7.10.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.7.6.3 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.7.6.2 17-Apr-2012  yamt sync with head
 1.7.6.1 06-Feb-2012  yamt file tpm.c was added on branch yamt-pagecache on 2012-04-17 00:07:37 +0000
 1.7.4.2 18-Feb-2012  mrg merge to -current.
 1.7.4.1 06-Feb-2012  mrg file tpm.c was added on branch jmcneill-usbmp on 2012-02-18 07:34:24 +0000
 1.10.2.1 10-Aug-2014  tls Rebase.
 1.12.4.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.13.2.3 29-Aug-2022  martin Pull up following revision(s) (requested by riastradh in ticket #1505):

sys/dev/isa/tpm_isa.c: revision 1.8
sys/dev/ic/tpm.c: revision 1.20

Add missing printing-of-newlines in the attach routine.

Remove extra newline from boot messages (isa and acpi front-ends
already provide the newline).
 1.13.2.2 03-Aug-2022  martin Pull up following revision(s) (requested by riastradh in ticket #1495):

share/man/man4/tpm.4: revision 1.7
sys/dev/ic/tpm.c: revision 1.17
sys/dev/ic/tpmvar.h: revision 1.10
sys/dev/ic/tpm.c: revision 1.18
sys/dev/ic/tpm.c: revision 1.19
sys/dev/acpi/tpm_acpi.c: revision 1.14
sys/dev/ic/tpmreg.h: revision 1.10
sys/dev/ic/tpmreg.h: revision 1.11
sys/dev/ic/tpm.c: revision 1.21
sys/dev/ic/tpm.c: revision 1.22
sys/dev/ic/tpm.c: revision 1.23
sys/dev/ic/tpm.c: revision 1.24
sys/dev/ic/tpm.c: revision 1.25
sys/dev/ic/tpmreg.h: revision 1.7
sys/dev/ic/tpmreg.h: revision 1.8
sys/dev/ic/tpmreg.h: revision 1.9
sys/dev/ic/tpmvar.h: revision 1.8
sys/dev/ic/tpmvar.h: revision 1.9

dev/ic/tpm: Tidy up headers.
- Add include guards.
- Add necessary includes.
- Sort includes.
- Use _BYTE_ORDER, not BYTE_ORDER, for public header.

dev/ic/tpm: Add missing line break in attach output.

dev/ic/tpm: Take advantage of entropy source if available.

If the tpm is deactivated, though, detach the entropy source so we
don't continue to try polling it -- it can't be activated without a
reboot anyway.

Add note about enabling TPM and rnd(4) source.

tpm(4): Handle TPM 2.0 random source too, and loop on short reads.
Tested on ThinkPad T480.

tpm(4): Preserve error if any on ending commands.
This way we don't spuriously suppress an error, such as
TPM_DEACTIVATED, in a loop where we rely on it.

tpm@acpi: Require only one locality's worth of register space.
We don't actually use the registers for the other localities, and
some older TPMs only have the first locality exposed via ACPI.


tpm(4): Fix disabling of rnd source if tpm is deactivated.

Nothing prevents a second worker from being queued when the first one
is about to do rnd_detach_source. Instead, just set a flag so future
requests don't bother running a new thread; if there's a concurrent
one that's already been scheduled on another CPU, well, too bad, we
get a couple extra log messages but that's fine.

A better way to do this would probably be to detect whether the tpm
is deactivated at attach time, but that requires reading more of the
tpm spec than I care to do when there are alternative ways to
procrastinate like scrubbing the toilet.


tpm(4): Fix suspend and rework I/O transaction lock.

Use sc->sc_lock over individual I/O transactions, not open/close of
the whole device. This way there is a bounded time before the tpm is
unbusied even if userland is getting at it, so userland can't hold up
suspend indefinitely. Of course, the tpm might be suspended and
resumed in the middle of the user's session this way -- tough.

This limits the response buffer to 1024 bytes -- which is already a
bit hefty to have on the stack (but it's probably not very deep on
the stack from userland so maybe not a big deal). If it turns out we
need more, we can use kmem to allocate a buffer on the heap, with the
caveat that it might fail. This is necessary so that suspend doesn't
block indefinitely on uiomove in tpmread.


tpm(4): Nix TPM_BE16/TPM_BE32. Just use sys/endian.h.
 1.13.2.1 16-Oct-2019  martin Pull up following revision(s) (requested by maxv in ticket #336):

sys/dev/isa/tpm_isa.c: revision 1.6
sys/dev/ic/tpm.c: revision 1.16
sys/dev/isa/tpm_isa.c: revision 1.7
sys/dev/acpi/tpm_acpi.c: revision 1.10
sys/dev/acpi/tpm_acpi.c: revision 1.11
sys/dev/ic/tpmreg.h: revision 1.5
sys/dev/ic/tpmreg.h: revision 1.6
sys/dev/acpi/tpm_acpi.c: revision 1.9
sys/dev/ic/tpmvar.h: revision 1.5
sys/dev/ic/tpmvar.h: revision 1.6
sys/dev/ic/tpmvar.h: revision 1.7
sys/dev/ic/tpm.c: revision 1.14
share/man/man4/tpm.4: revision 1.5
sys/dev/isa/tpm_isa.c: revision 1.5
sys/dev/ic/tpm.c: revision 1.15

Improvements in tpm(4):
- Remove interrupt support, do polling only, avoids unnecessary trouble.
- Simplify a few things.
- Fix the suspend function, the SaveState command is 0x98, not 0x9C.
- Make the driver MP-safe.
- Sync the man page with reality.

-

Add suspend support for TPM 2.0 chips. Check the TPM response also for 1.2
chips. Unfortunately I cannot really test this change since ACPI suspend
does not work on any of my laptops.

-

Provide a better abstraction for the TPM interface. Report it in the ioctl.
 1.16.8.1 03-Apr-2021  thorpej Sync with HEAD.
 1.19.6.1 31-May-2021  cjep sync with head
 1.19.4.1 17-Jun-2021  thorpej Sync w/ HEAD.
 1.21.2.1 06-Jun-2021  cjep sync with head
 1.11 29-Jan-2022  riastradh tpm(4): Nix TPM_BE16/TPM_BE32. Just use sys/endian.h.
 1.10 14-Nov-2021  riastradh tpm@acpi: Require only one locality's worth of register space.

We don't actually use the registers for the other localities, and
some older TPMs only have the first locality exposed via ACPI.
 1.9 29-May-2021  riastradh tpm(4): Handle TPM 2.0 random source too, and loop on short reads.

Tested on ThinkPad T480.
 1.8 04-Jan-2021  riastradh branches: 1.8.4; 1.8.6;
dev/ic/tpm: Take advantage of entropy source if available.

If the tpm is deactivated, though, detach the entropy source so we
don't continue to try polling it -- it can't be activated without a
reboot anyway.
 1.7 04-Jan-2021  riastradh dev/ic/tpm: Tidy up headers.

- Add include guards.
- Add necessary includes.
- Sort includes.
- Use _BYTE_ORDER, not BYTE_ORDER, for public header.
 1.6 09-Oct-2019  maxv branches: 1.6.8;
Add suspend support for TPM 2.0 chips. Check the TPM response also for 1.2
chips. Unfortunately I cannot really test this change since ACPI suspend
does not work on any of my laptops.
 1.5 08-Oct-2019  maxv Improvements in tpm(4):
- Remove interrupt support, do polling only, avoids unnecessary trouble.
- Simplify a few things.
- Fix the suspend function, the SaveState command is 0x98, not 0x9C.
- Make the driver MP-safe.
- Sync the man page with reality.
 1.4 22-Jun-2019  maxv branches: 1.4.2;
Revamp the TPM driver

* Fix several bugs, and clean up.
* Drop the "legacy" interface, it relied on an undocumented global
variable that was never initialized. It likely had never been tested
either, so good riddance.
* Add support for TPM 2.0 chips via ACPI. For these we use the TIS1.2
interface, same as TPM 1.2.
* Provide an ioctl to fetch TPM information from the driver.

Tested on a Lenovo desktop with ACPI-TPM2.0, an HP laptop ACPI-TPM2.0, a
Dell laptop with ISA-TPM1.2.
 1.3 23-Jan-2012  christos branches: 1.3.4; 1.3.6; 1.3.52;
reduce the polling interval to 2 seconds, and try harder to get interrupts
working.
 1.2 22-Jan-2012  christos cosmetic fixes
 1.1 22-Jan-2012  christos add a tpm driver from bsssd.sourceforge.net
 1.3.52.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.3.6.2 17-Apr-2012  yamt sync with head
 1.3.6.1 23-Jan-2012  yamt file tpmreg.h was added on branch yamt-pagecache on 2012-04-17 00:07:37 +0000
 1.3.4.2 18-Feb-2012  mrg merge to -current.
 1.3.4.1 23-Jan-2012  mrg file tpmreg.h was added on branch jmcneill-usbmp on 2012-02-18 07:34:24 +0000
 1.4.2.2 03-Aug-2022  martin Pull up following revision(s) (requested by riastradh in ticket #1495):

share/man/man4/tpm.4: revision 1.7
sys/dev/ic/tpm.c: revision 1.17
sys/dev/ic/tpmvar.h: revision 1.10
sys/dev/ic/tpm.c: revision 1.18
sys/dev/ic/tpm.c: revision 1.19
sys/dev/acpi/tpm_acpi.c: revision 1.14
sys/dev/ic/tpmreg.h: revision 1.10
sys/dev/ic/tpmreg.h: revision 1.11
sys/dev/ic/tpm.c: revision 1.21
sys/dev/ic/tpm.c: revision 1.22
sys/dev/ic/tpm.c: revision 1.23
sys/dev/ic/tpm.c: revision 1.24
sys/dev/ic/tpm.c: revision 1.25
sys/dev/ic/tpmreg.h: revision 1.7
sys/dev/ic/tpmreg.h: revision 1.8
sys/dev/ic/tpmreg.h: revision 1.9
sys/dev/ic/tpmvar.h: revision 1.8
sys/dev/ic/tpmvar.h: revision 1.9

dev/ic/tpm: Tidy up headers.
- Add include guards.
- Add necessary includes.
- Sort includes.
- Use _BYTE_ORDER, not BYTE_ORDER, for public header.

dev/ic/tpm: Add missing line break in attach output.

dev/ic/tpm: Take advantage of entropy source if available.

If the tpm is deactivated, though, detach the entropy source so we
don't continue to try polling it -- it can't be activated without a
reboot anyway.

Add note about enabling TPM and rnd(4) source.

tpm(4): Handle TPM 2.0 random source too, and loop on short reads.
Tested on ThinkPad T480.

tpm(4): Preserve error if any on ending commands.
This way we don't spuriously suppress an error, such as
TPM_DEACTIVATED, in a loop where we rely on it.

tpm@acpi: Require only one locality's worth of register space.
We don't actually use the registers for the other localities, and
some older TPMs only have the first locality exposed via ACPI.


tpm(4): Fix disabling of rnd source if tpm is deactivated.

Nothing prevents a second worker from being queued when the first one
is about to do rnd_detach_source. Instead, just set a flag so future
requests don't bother running a new thread; if there's a concurrent
one that's already been scheduled on another CPU, well, too bad, we
get a couple extra log messages but that's fine.

A better way to do this would probably be to detect whether the tpm
is deactivated at attach time, but that requires reading more of the
tpm spec than I care to do when there are alternative ways to
procrastinate like scrubbing the toilet.


tpm(4): Fix suspend and rework I/O transaction lock.

Use sc->sc_lock over individual I/O transactions, not open/close of
the whole device. This way there is a bounded time before the tpm is
unbusied even if userland is getting at it, so userland can't hold up
suspend indefinitely. Of course, the tpm might be suspended and
resumed in the middle of the user's session this way -- tough.

This limits the response buffer to 1024 bytes -- which is already a
bit hefty to have on the stack (but it's probably not very deep on
the stack from userland so maybe not a big deal). If it turns out we
need more, we can use kmem to allocate a buffer on the heap, with the
caveat that it might fail. This is necessary so that suspend doesn't
block indefinitely on uiomove in tpmread.


tpm(4): Nix TPM_BE16/TPM_BE32. Just use sys/endian.h.
 1.4.2.1 16-Oct-2019  martin Pull up following revision(s) (requested by maxv in ticket #336):

sys/dev/isa/tpm_isa.c: revision 1.6
sys/dev/ic/tpm.c: revision 1.16
sys/dev/isa/tpm_isa.c: revision 1.7
sys/dev/acpi/tpm_acpi.c: revision 1.10
sys/dev/acpi/tpm_acpi.c: revision 1.11
sys/dev/ic/tpmreg.h: revision 1.5
sys/dev/ic/tpmreg.h: revision 1.6
sys/dev/acpi/tpm_acpi.c: revision 1.9
sys/dev/ic/tpmvar.h: revision 1.5
sys/dev/ic/tpmvar.h: revision 1.6
sys/dev/ic/tpmvar.h: revision 1.7
sys/dev/ic/tpm.c: revision 1.14
share/man/man4/tpm.4: revision 1.5
sys/dev/isa/tpm_isa.c: revision 1.5
sys/dev/ic/tpm.c: revision 1.15

Improvements in tpm(4):
- Remove interrupt support, do polling only, avoids unnecessary trouble.
- Simplify a few things.
- Fix the suspend function, the SaveState command is 0x98, not 0x9C.
- Make the driver MP-safe.
- Sync the man page with reality.

-

Add suspend support for TPM 2.0 chips. Check the TPM response also for 1.2
chips. Unfortunately I cannot really test this change since ACPI suspend
does not work on any of my laptops.

-

Provide a better abstraction for the TPM interface. Report it in the ioctl.
 1.6.8.1 03-Apr-2021  thorpej Sync with HEAD.
 1.8.6.1 31-May-2021  cjep sync with head
 1.8.4.1 17-Jun-2021  thorpej Sync w/ HEAD.
 1.10 20-Dec-2021  riastradh tpm(4): Fix disabling of rnd source if tpm is deactivated.

Nothing prevents a second worker from being queued when the first one
is about to do rnd_detach_source. Instead, just set a flag so future
requests don't bother running a new thread; if there's a concurrent
one that's already been scheduled on another CPU, well, too bad, we
get a couple extra log messages but that's fine.

A better way to do this would probably be to detect whether the tpm
is deactivated at attach time, but that requires reading more of the
tpm spec than I care to do when there are alternative ways to
procrastinate like scrubbing the toilet.
 1.9 04-Jan-2021  riastradh dev/ic/tpm: Take advantage of entropy source if available.

If the tpm is deactivated, though, detach the entropy source so we
don't continue to try polling it -- it can't be activated without a
reboot anyway.
 1.8 04-Jan-2021  riastradh dev/ic/tpm: Tidy up headers.

- Add include guards.
- Add necessary includes.
- Sort includes.
- Use _BYTE_ORDER, not BYTE_ORDER, for public header.
 1.7 09-Oct-2019  maxv branches: 1.7.8;
Provide a better abstraction for the TPM interface. Report it in the ioctl.
 1.6 09-Oct-2019  maxv Add suspend support for TPM 2.0 chips. Check the TPM response also for 1.2
chips. Unfortunately I cannot really test this change since ACPI suspend
does not work on any of my laptops.
 1.5 08-Oct-2019  maxv Improvements in tpm(4):
- Remove interrupt support, do polling only, avoids unnecessary trouble.
- Simplify a few things.
- Fix the suspend function, the SaveState command is 0x98, not 0x9C.
- Make the driver MP-safe.
- Sync the man page with reality.
 1.4 22-Jun-2019  maxv branches: 1.4.2;
Revamp the TPM driver

* Fix several bugs, and clean up.
* Drop the "legacy" interface, it relied on an undocumented global
variable that was never initialized. It likely had never been tested
either, so good riddance.
* Add support for TPM 2.0 chips via ACPI. For these we use the TIS1.2
interface, same as TPM 1.2.
* Provide an ioctl to fetch TPM information from the driver.

Tested on a Lenovo desktop with ACPI-TPM2.0, an HP laptop ACPI-TPM2.0, a
Dell laptop with ISA-TPM1.2.
 1.3 27-Oct-2012  chs branches: 1.3.38;
split device_t/softc for all remaining drivers.
replace "struct device *" with "device_t".
use device_xname(), device_unit(), etc.
 1.2 22-Jan-2012  christos branches: 1.2.4; 1.2.6; 1.2.10;
cosmetic fixes
 1.1 22-Jan-2012  christos add a tpm driver from bsssd.sourceforge.net
 1.2.10.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.2.6.3 30-Oct-2012  yamt sync with head
 1.2.6.2 17-Apr-2012  yamt sync with head
 1.2.6.1 22-Jan-2012  yamt file tpmvar.h was added on branch yamt-pagecache on 2012-04-17 00:07:37 +0000
 1.2.4.2 18-Feb-2012  mrg merge to -current.
 1.2.4.1 22-Jan-2012  mrg file tpmvar.h was added on branch jmcneill-usbmp on 2012-02-18 07:34:24 +0000
 1.3.38.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.4.2.2 03-Aug-2022  martin Pull up following revision(s) (requested by riastradh in ticket #1495):

share/man/man4/tpm.4: revision 1.7
sys/dev/ic/tpm.c: revision 1.17
sys/dev/ic/tpmvar.h: revision 1.10
sys/dev/ic/tpm.c: revision 1.18
sys/dev/ic/tpm.c: revision 1.19
sys/dev/acpi/tpm_acpi.c: revision 1.14
sys/dev/ic/tpmreg.h: revision 1.10
sys/dev/ic/tpmreg.h: revision 1.11
sys/dev/ic/tpm.c: revision 1.21
sys/dev/ic/tpm.c: revision 1.22
sys/dev/ic/tpm.c: revision 1.23
sys/dev/ic/tpm.c: revision 1.24
sys/dev/ic/tpm.c: revision 1.25
sys/dev/ic/tpmreg.h: revision 1.7
sys/dev/ic/tpmreg.h: revision 1.8
sys/dev/ic/tpmreg.h: revision 1.9
sys/dev/ic/tpmvar.h: revision 1.8
sys/dev/ic/tpmvar.h: revision 1.9

dev/ic/tpm: Tidy up headers.
- Add include guards.
- Add necessary includes.
- Sort includes.
- Use _BYTE_ORDER, not BYTE_ORDER, for public header.

dev/ic/tpm: Add missing line break in attach output.

dev/ic/tpm: Take advantage of entropy source if available.

If the tpm is deactivated, though, detach the entropy source so we
don't continue to try polling it -- it can't be activated without a
reboot anyway.

Add note about enabling TPM and rnd(4) source.

tpm(4): Handle TPM 2.0 random source too, and loop on short reads.
Tested on ThinkPad T480.

tpm(4): Preserve error if any on ending commands.
This way we don't spuriously suppress an error, such as
TPM_DEACTIVATED, in a loop where we rely on it.

tpm@acpi: Require only one locality's worth of register space.
We don't actually use the registers for the other localities, and
some older TPMs only have the first locality exposed via ACPI.


tpm(4): Fix disabling of rnd source if tpm is deactivated.

Nothing prevents a second worker from being queued when the first one
is about to do rnd_detach_source. Instead, just set a flag so future
requests don't bother running a new thread; if there's a concurrent
one that's already been scheduled on another CPU, well, too bad, we
get a couple extra log messages but that's fine.

A better way to do this would probably be to detect whether the tpm
is deactivated at attach time, but that requires reading more of the
tpm spec than I care to do when there are alternative ways to
procrastinate like scrubbing the toilet.


tpm(4): Fix suspend and rework I/O transaction lock.

Use sc->sc_lock over individual I/O transactions, not open/close of
the whole device. This way there is a bounded time before the tpm is
unbusied even if userland is getting at it, so userland can't hold up
suspend indefinitely. Of course, the tpm might be suspended and
resumed in the middle of the user's session this way -- tough.

This limits the response buffer to 1024 bytes -- which is already a
bit hefty to have on the stack (but it's probably not very deep on
the stack from userland so maybe not a big deal). If it turns out we
need more, we can use kmem to allocate a buffer on the heap, with the
caveat that it might fail. This is necessary so that suspend doesn't
block indefinitely on uiomove in tpmread.


tpm(4): Nix TPM_BE16/TPM_BE32. Just use sys/endian.h.
 1.4.2.1 16-Oct-2019  martin Pull up following revision(s) (requested by maxv in ticket #336):

sys/dev/isa/tpm_isa.c: revision 1.6
sys/dev/ic/tpm.c: revision 1.16
sys/dev/isa/tpm_isa.c: revision 1.7
sys/dev/acpi/tpm_acpi.c: revision 1.10
sys/dev/acpi/tpm_acpi.c: revision 1.11
sys/dev/ic/tpmreg.h: revision 1.5
sys/dev/ic/tpmreg.h: revision 1.6
sys/dev/acpi/tpm_acpi.c: revision 1.9
sys/dev/ic/tpmvar.h: revision 1.5
sys/dev/ic/tpmvar.h: revision 1.6
sys/dev/ic/tpmvar.h: revision 1.7
sys/dev/ic/tpm.c: revision 1.14
share/man/man4/tpm.4: revision 1.5
sys/dev/isa/tpm_isa.c: revision 1.5
sys/dev/ic/tpm.c: revision 1.15

Improvements in tpm(4):
- Remove interrupt support, do polling only, avoids unnecessary trouble.
- Simplify a few things.
- Fix the suspend function, the SaveState command is 0x98, not 0x9C.
- Make the driver MP-safe.
- Sync the man page with reality.

-

Add suspend support for TPM 2.0 chips. Check the TPM response also for 1.2
chips. Unfortunately I cannot really test this change since ACPI suspend
does not work on any of my laptops.

-

Provide a better abstraction for the TPM interface. Report it in the ioctl.
 1.7.8.1 03-Apr-2021  thorpej Sync with HEAD.
 1.54 19-Jan-2020  thorpej Remove Token Ring support.
 1.53 29-May-2019  msaitoh branches: 1.53.4;
Even if we don't use MII(4), use the common path of SIOC[GS]IFMEDIA in
sys/net/if_ethersubr.c if we can.
- Add ec_ifmedia into struct ethercom.
- ec_mii in struct ethercom is kept and used as it is. It might be used in
future. Note that some Ethernet drivers which _DOESN'T_ use mii(4) use
ec_mii for keeping the if_media. Those should be changed in future.
 1.52 05-Feb-2019  msaitoh Remove very old IFF_NOTRAILERS flag.
 1.51 03-Sep-2018  riastradh Rename min/max -> uimin/uimax for better honesty.

These functions are defined on unsigned int. The generic name
min/max should not silently truncate to 32 bits on 64-bit systems.
This is purely a name change -- no functional change intended.

HOWEVER! Some subsystems have

#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))

even though our standard name for that is MIN/MAX. Although these
may invite multiple evaluation bugs, these do _not_ cause integer
truncation.

To avoid `fixing' these cases, I first changed the name in libkern,
and then compile-tested every file where min/max occurred in order to
confirm that it failed -- and thus confirm that nothing shadowed
min/max -- before changing it.

I have left a handful of bootloaders that are too annoying to
compile-test, and some dead code:

cobalt ews4800mips hp300 hppa ia64 luna68k vax
acorn32/if_ie.c (not included in any kernels)
macppc/if_gm.c (superseded by gem(4))

It should be easy to fix the fallout once identified -- this way of
doing things fails safe, and the goal here, after all, is to _avoid_
silent integer truncations, not introduce them.

Maybe one day we can reintroduce min/max as type-generic things that
never silently truncate. But we should avoid doing that for a while,
so that existing code has a chance to be detected by the compiler for
conversion to uimin/uimax without changing the semantics until we can
properly audit it all. (Who knows, maybe in some cases integer
truncation is actually intended!)
 1.50 26-Jun-2018  msaitoh branches: 1.50.2;
Implement the BPF direction filter (BIOC[GS]DIRECTION). It provides backward
compatibility with BIOC[GS]SEESENT ioctl. The userland interface is the same
as FreeBSD.

This change also fixes a bug that the direction is misunderstand on some
environment by passing the direction to bpf_mtap*() instead of checking
m->m_pkthdr.rcvif.
 1.49 22-Jun-2018  msaitoh It's not required to include net/bpfdesc.h. Remove it.
 1.48 15-Dec-2016  ozaki-r branches: 1.48.8; 1.48.14;
Move bpf_mtap and if_ipackets++ on Rx of each driver to percpuq if_input

The benefits of the change are:
- We can reduce codes
- We can provide the same behavior between drivers
- Where/When if_ipackets is counted up
- Note that some drivers still update packet statistics in their own
way (periodical update)
- Moved bpf_mtap run in softint
- This makes it easy to MP-ify bpf

Proposed on tech-kern and tech-net
 1.47 14-Jul-2016  msaitoh branches: 1.47.2;
- Use aprint*() instead of printf() in xxx_attach().
- Add missing aprint_naive("\n");
- KNF
 1.46 10-Jun-2016  ozaki-r Introduce m_set_rcvif and m_reset_rcvif

The API is used to set (or reset) a received interface of a mbuf.
They are counterpart of m_get_rcvif, which will come in another
commit, hide internal of rcvif operation, and reduce the diff of
the upcoming change.

No functional change.
 1.45 09-Feb-2016  ozaki-r Introduce softint-based if_input

This change intends to run the whole network stack in softint context
(or normal LWP), not hardware interrupt context. Note that the work is
still incomplete by this change; to that end, we also have to softint-ify
if_link_state_change (and bpf) which can still run in hardware interrupt.

This change softint-ifies at ifp->if_input that is called from
each device driver (and ieee80211_input) to ensure Layer 2 runs
in softint (e.g., ether_input and bridge_input). To this end,
we provide a framework (called percpuq) that utlizes softint(9)
and percpu ifqueues. With this patch, rxintr of most drivers just
queues received packets and schedules a softint, and the softint
dequeues packets and does rest packet processing.

To minimize changes to each driver, percpuq is allocated in struct
ifnet for now and that is initialized by default (in if_attach).
We probably have to move percpuq to softc of each driver, but it's
future work. At this point, only wm(4) has percpuq in its softc
as a reference implementation.

Additional information including performance numbers can be found
in the thread at tech-kern@ and tech-net@:
http://mail-index.netbsd.org/tech-kern/2016/01/14/msg019997.html

Acknowledgment: riastradh@ greatly helped this work.
Thank you very much!
 1.44 27-Oct-2012  chs branches: 1.44.14;
split device_t/softc for all remaining drivers.
replace "struct device *" with "device_t".
use device_xname(), device_unit(), etc.
 1.43 01-Aug-2011  mbalmer branches: 1.43.2; 1.43.12;
According to the Oxford Dictionary of Etymology, a wether is a male sheep
or ram.
 1.42 05-Apr-2010  joerg Push the bpf_ops usage back into bpf.h. Push the common ifp->if_bpf
check into the inline functions as well the fourth argument for
bpf_attach.
 1.41 19-Jan-2010  pooka branches: 1.41.2; 1.41.4;
Redefine bpf linkage through an always present op vector, i.e.
#if NBPFILTER is no longer required in the client. This change
doesn't yet add support for loading bpf as a module, since drivers
can register before bpf is attached. However, callers of bpf can
now be modularized.

Dynamically loadable bpf could probably be done fairly easily with
coordination from the stub driver and the real driver by registering
attachments in the stub before the real driver is loaded and doing
a handoff. ... and I'm not going to ponder the depths of unload
here.

Tested with i386/MONOLITHIC, modified MONOLITHIC without bpf and rump.
 1.40 06-Dec-2009  dyoung Simplify device-activation hook.
 1.39 12-May-2009  cegger struct device * -> device_t, no functional changes intended.
 1.38 18-Mar-2009  cegger Ansify function definitions w/o arguments. Generated with sed.
 1.37 14-Mar-2009  dsl ANSIfy another 1261 function definitions.
The only ones left in sys are beyond by sed script!
(or in sys/dist or sys/external)
Mostly they have function pointer parameters.
 1.36 14-Mar-2009  dsl Change about 4500 of the K&R function definitions to ANSI ones.
There are still about 1600 left, but they have ',' or /* ... */
in the actual variable definitions - which my awk script doesn't handle.
There are also many that need () -> (void).
(The script does handle misordered arguments.)
 1.35 07-Nov-2008  dyoung branches: 1.35.4;
*** Summary ***

When a link-layer address changes (e.g., ifconfig ex0 link
02:de:ad:be:ef:02 active), send a gratuitous ARP and/or a Neighbor
Advertisement to update the network-/link-layer address bindings
on our LAN peers.

Refuse a change of ethernet address to the address 00:00:00:00:00:00
or to any multicast/broadcast address. (Thanks matt@.)

Reorder ifnet ioctl operations so that driver ioctls may inherit
the functions of their "class"---ether_ioctl(), fddi_ioctl(), et
cetera---and the class ioctls may inherit from the generic ioctl,
ifioctl_common(), but both driver- and class-ioctls may override
the generic behavior. Make network drivers share more code.

Distinguish a "factory" link-layer address from others for the
purposes of both protecting that address from deletion and computing
EUI64.

Return consistent, appropriate error codes from network drivers.

Improve readability. KNF.

*** Details ***

In if_attach(), always initialize the interface ioctl routine,
ifnet->if_ioctl, if the driver has not already initialized it.
Delete if_ioctl == NULL tests everywhere else, because it cannot
happen.

In the ioctl routines of network interfaces, inherit common ioctl
behaviors by calling either ifioctl_common() or whichever ioctl
routine is appropriate for the class of interface---e.g., ether_ioctl()
for ethernets.

Stop (ab)using SIOCSIFADDR and start to use SIOCINITIFADDR. In
the user->kernel interface, SIOCSIFADDR's argument was an ifreq,
but on the protocol->ifnet interface, SIOCSIFADDR's argument was
an ifaddr. That was confusing, and it would work against me as I
make it possible for a network interface to overload most ioctls.
On the protocol->ifnet interface, replace SIOCSIFADDR with
SIOCINITIFADDR. In ifioctl(), return EPERM if userland tries to
invoke SIOCINITIFADDR.

In ifioctl(), give the interface the first shot at handling most
interface ioctls, and give the protocol the second shot, instead
of the other way around. Finally, let compatibility code (COMPAT_OSOCK)
take a shot.

Pull device initialization out of switch statements under
SIOCINITIFADDR. For example, pull ..._init() out of any switch
statement that looks like this:

switch (...->sa_family) {
case ...:
..._init();
...
break;
...
default:
..._init();
...
break;
}

Rewrite many if-else clauses that handle all permutations of IFF_UP
and IFF_RUNNING to use a switch statement,

switch (x & (IFF_UP|IFF_RUNNING)) {
case 0:
...
break;
case IFF_RUNNING:
...
break;
case IFF_UP:
...
break;
case IFF_UP|IFF_RUNNING:
...
break;
}

unifdef lots of code containing #ifdef FreeBSD, #ifdef NetBSD, and
#ifdef SIOCSIFMTU, especially in fwip(4) and in ndis(4).

In ipw(4), remove an if_set_sadl() call that is out of place.

In nfe(4), reuse the jumbo MTU logic in ether_ioctl().

Let ethernets register a callback for setting h/w state such as
promiscuous mode and the multicast filter in accord with a change
in the if_flags: ether_set_ifflags_cb() registers a callback that
returns ENETRESET if the caller should reset the ethernet by calling
if_init(), 0 on success, != 0 on failure. Pull common code from
ex(4), gem(4), nfe(4), sip(4), tlp(4), vge(4) into ether_ioctl(),
and register if_flags callbacks for those drivers.

Return ENOTTY instead of EINVAL for inappropriate ioctls. In
zyd(4), use ENXIO instead of ENOTTY to indicate that the device is
not any longer attached.

Add to if_set_sadl() a boolean 'factory' argument that indicates
whether a link-layer address was assigned by the factory or some
other source. In a comment, recommend using the factory address
for generating an EUI64, and update in6_get_hw_ifid() to prefer a
factory address to any other link-layer address.

Add a routing message, RTM_LLINFO_UPD, that tells protocols to
update the binding of network-layer addresses to link-layer addresses.
Implement this message in IPv4 and IPv6 by sending a gratuitous
ARP or a neighbor advertisement, respectively. Generate RTM_LLINFO_UPD
messages on a change of an interface's link-layer address.

In ether_ioctl(), do not let SIOCALIFADDR set a link-layer address
that is broadcast/multicast or equal to 00:00:00:00:00:00.

Make ether_ioctl() call ifioctl_common() to handle ioctls that it
does not understand.

In gif(4), initialize if_softc and use it, instead of assuming that
the gif_softc and ifp overlap.

Let ifioctl_common() handle SIOCGIFADDR.

Sprinkle rtcache_invariants(), which checks on DIAGNOSTIC kernels
that certain invariants on a struct route are satisfied.

In agr(4), rewrite agr_ioctl_filter() to be a bit more explicit
about the ioctls that we do not allow on an agr(4) member interface.

bzero -> memset. Delete unnecessary casts to void *. Use
sockaddr_in_init() and sockaddr_in6_init(). Compare pointers with
NULL instead of "testing truth". Replace some instances of (type
*)0 with NULL. Change some K&R prototypes to ANSI C, and join
lines.
 1.34 08-Apr-2008  cegger branches: 1.34.4; 1.34.10; 1.34.12;
use aprint_*_dev and device_xname
 1.33 07-Feb-2008  dyoung branches: 1.33.6;
Start patching up the kernel so that a network driver always has
the opportunity to handle an ioctl before generic ifioctl handling
occurs. This will ease extending the kernel and sharing of code
between drivers.

First steps: Make the signature of ifioctl_common() match struct
ifinet->if_ioctl. Convert SIOCSIFCAP and SIOCSIFMTU to the new
ifioctl() regime, throughout the kernel.
 1.32 19-Oct-2007  ad branches: 1.32.2;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.31 09-Jul-2007  ad branches: 1.31.6; 1.31.8; 1.31.12;
Merge some of the less invasive changes from the vmlocking branch:

- kthread, callout, devsw API changes
- select()/poll() improvements
- miscellaneous MT safety improvements
 1.30 04-Mar-2007  christos branches: 1.30.2; 1.30.4;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.29 16-Nov-2006  christos branches: 1.29.4;
__unused removal on arguments; approved by core.
 1.28 12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.27 07-Sep-2006  dogcow branches: 1.27.2; 1.27.4;
remove more vestiges of CCITT, LLC, HDLC, NS, and NSIP.
 1.26 11-Dec-2005  christos branches: 1.26.4; 1.26.8;
merge ktrace-lwp.
 1.25 30-May-2005  christos branches: 1.25.2;
- add missing const
- fix variable shadowing
- remove unneeded casts
 1.24 27-Feb-2005  perry nuke trailing whitespace
 1.23 04-Feb-2005  perry de-__P
 1.22 02-Nov-2003  wiz branches: 1.22.8; 1.22.10;
Fix some typos. From Tom Cosgrove via jmc@openbsd.
 1.21 30-Oct-2003  simonb Remove some assigned-to but otherwise unused variables.
 1.20 06-Jan-2003  wiz branches: 1.20.2;
interrupt with two rs.
 1.19 13-Nov-2001  lukem add/cleanup RCSID
 1.18 07-Jul-2001  thorpej branches: 1.18.2;
bcopy -> strcpy
 1.17 14-Dec-2000  thorpej branches: 1.17.2;
if_qflush() -> IFQ_PURGE()
 1.16 14-Dec-2000  thorpej ALTQ'ify.
 1.15 12-Dec-2000  thorpej Adapt to bpfattach() changes, and further centralize the bpfattach()
and bpfdetach() calls into link-type subroutines where possible.
 1.14 31-Oct-2000  mjl Fix hanging token ring when data size is multiple of 514, using
patch in PR/11316 by YAMAMOTO Takashi.
This fixes random hangs I experienced, and probably also
remedies PR/11300 and PR/9321.
 1.13 02-Oct-2000  itojun fix compilation without INET.
 1.12 15-Jun-2000  soren branches: 1.12.2;
Update from Onno:
- Add a tr_reopen() and use that instead of tr_init() for callouts.
- As tr_reinit() and tr_reopen() are used as callouts, protect them at splnet.
 1.11 13-Jun-2000  soren Call frontend enable/disable functions in the ioctl path.
Use _sc prefixes for some softc members.
A few minor cleanups.
 1.10 06-Jun-2000  soren Some minor diagnostics cleanups.
 1.9 06-Jun-2000  soren Add power management hooks.
 1.8 27-May-2000  thorpej branches: 1.8.2;
Don't use sleep() and a callout; just use tsleep().
 1.7 23-Mar-2000  thorpej New callout mechanism with two major improvements over the old
timeout()/untimeout() API:
- Clients supply callout handle storage, thus eliminating problems of
resource allocation.
- Insertion and removal of callouts is constant time, important as
this facility is used quite a lot in the kernel.

The old timeout()/untimeout() API has been removed from the kernel.
 1.6 17-Dec-1999  fvdl Deal with cable problems gracefully. From Onno van der Linden.
 1.5 29-May-1999  bad branches: 1.5.2; 1.5.8;
Now that the ARP code doesn't assume that m_pktdat[0] is the start of the
packet(!) we can enable the code that aligns the struct token_header at the
start of the mbuf.
 1.4 18-May-1999  thorpej Rework layer 2 protocol input routines. Instead of calling e.g. ether_input()
directly, call the function pointer (*if_input)(ifp, m). The input routine
expects the packet header to be at the head of the packet, and will adjust
as necessary. Privatize the layer 2 input and output routines, allowing
*_ifattach() to set them up as appropriate.
 1.3 29-Apr-1999  bad From Onno van der Linden:
Reorganise the driver some what.
Rename tr_reset() to the more appropriate tr_stop().
Create a common tropic reset routine and use it in the frontends.
Move the code in tr_config() which is only used in the card attachment
routines into a new tr_attach() function.
Take adapter off the ring through tr_shutdown() in a shutdown hook.
This simplifies the bus-specific frontend.
 1.2 22-Mar-1999  bad branches: 1.2.2;
Oops. RcsID police.
 1.1 22-Mar-1999  bad Chipset driver for TROPIC based Token-Ring cards.
Frontends for IBM and 3COM ISA cards.

By Onno van der Linden <onno@simplex.nl>.
 1.2.2.2 05-Jan-2000  he Pull up revision 1.6 (requested by fvdl):
Fix interface hang which could happen in case of cable problems
or if the cable was pulled and then reinserted.
 1.2.2.1 29-Apr-1999  perry branches: 1.2.2.1.2;
pullup 1.2->1.3 (bad)
 1.2.2.1.2.1 21-Jun-1999  thorpej Sync w/ -current.
 1.5.8.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.5.2.4 05-Jan-2001  bouyer Sync with HEAD
 1.5.2.3 13-Dec-2000  bouyer Sync with HEAD (for UBC fixes).
 1.5.2.2 22-Nov-2000  bouyer Sync with HEAD.
 1.5.2.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.8.2.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.12.2.1 01-Nov-2000  tv Pullup 1.14 [mjl]:
Fix hanging token ring when data size is multiple of 514, using
patch in PR/11316 by YAMAMOTO Takashi.
This fixes random hangs I experienced, and probably also
remedies PR/11300 and PR/9321.
 1.17.2.3 07-Jan-2003  thorpej Sync with HEAD.
 1.17.2.2 14-Nov-2001  nathanw Catch up to -current.
 1.17.2.1 24-Aug-2001  nathanw Catch up with -current.
 1.18.2.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.20.2.6 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.20.2.5 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.20.2.4 04-Feb-2005  skrll Sync with HEAD.
 1.20.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.20.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.20.2.1 03-Aug-2004  skrll Sync with HEAD
 1.22.10.2 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.22.10.1 12-Feb-2005  yamt sync with head.
 1.22.8.1 29-Apr-2005  kent sync with -current
 1.25.2.4 11-Feb-2008  yamt sync with head.
 1.25.2.3 27-Oct-2007  yamt sync with head.
 1.25.2.2 03-Sep-2007  yamt sync with head.
 1.25.2.1 30-Dec-2006  yamt sync with head.
 1.26.8.1 14-Sep-2006  yamt sync with head.
 1.26.4.1 09-Sep-2006  rpaulo sync with head
 1.27.4.2 10-Dec-2006  yamt sync with head.
 1.27.4.1 22-Oct-2006  yamt sync with head
 1.27.2.1 18-Nov-2006  ad Sync with head.
 1.29.4.1 12-Mar-2007  rmind Sync with HEAD.
 1.30.4.1 11-Jul-2007  mjf Sync with head.
 1.30.2.2 23-Oct-2007  ad Sync with head.
 1.30.2.1 01-Jul-2007  ad Adapt to callout API change.
 1.31.12.1 25-Oct-2007  bouyer Sync with HEAD.
 1.31.8.2 23-Mar-2008  matt sync with HEAD
 1.31.8.1 06-Nov-2007  matt sync with HEAD
 1.31.6.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.32.2.1 18-Feb-2008  mjf Sync with HEAD.
 1.33.6.2 17-Jan-2009  mjf Sync with HEAD.
 1.33.6.1 02-Jun-2008  mjf Sync with HEAD.
 1.34.12.2 28-Apr-2009  skrll Sync with HEAD.
 1.34.12.1 19-Jan-2009  skrll Sync with HEAD.
 1.34.10.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.34.4.4 11-Aug-2010  yamt sync with head.
 1.34.4.3 11-Mar-2010  yamt sync with head
 1.34.4.2 16-May-2009  yamt sync with head
 1.34.4.1 04-May-2009  yamt sync with head.
 1.35.4.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.41.4.1 30-May-2010  rmind sync with head
 1.41.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.43.12.2 03-Dec-2017  jdolecek update from HEAD
 1.43.12.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.43.2.1 30-Oct-2012  yamt sync with head
 1.44.14.4 05-Feb-2017  skrll Sync with HEAD
 1.44.14.3 05-Oct-2016  skrll Sync with HEAD
 1.44.14.2 09-Jul-2016  skrll Sync with HEAD
 1.44.14.1 19-Mar-2016  skrll Sync with HEAD
 1.47.2.1 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.48.14.3 06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.48.14.2 28-Jul-2018  pgoyette Sync with HEAD
 1.48.14.1 25-Jun-2018  pgoyette Sync with HEAD
 1.48.8.1 26-Jul-2018  snj Pull up following revision(s) (requested by msaitoh in ticket #938):
sys/arch/acorn32/podulebus/if_ie.c: revision 1.41
sys/arch/amiga/dev/if_es.c: revision 1.58
sys/arch/amiga/dev/if_qn.c: revision 1.45
sys/arch/arm/at91/at91emac.c: revision 1.20
sys/arch/arm/ep93xx/epe.c: revision 1.37
sys/arch/emips/ebus/if_le_ebus.c: revision 1.14
sys/arch/emips/ebus/if_le_ebus.c: revision 1.15
sys/arch/mac68k/dev/if_mc.c: revision 1.46
sys/arch/macppc/dev/am79c950.c: revision 1.39
sys/arch/newsmips/apbus/if_sn.c: revision 1.40
sys/arch/next68k/dev/mb8795.c: revision 1.59
sys/arch/playstation2/dev/if_smap.c: revision 1.25
sys/arch/playstation2/dev/if_smap.c: revision 1.26
sys/arch/sun2/dev/if_ec.c: revision 1.28
sys/arch/sun3/dev/if_ie.c: revision 1.63
sys/arch/x68k/dev/if_ne_intio.c: revision 1.19
sys/arch/xen/xen/if_xennet_xenbus.c: revision 1.75
sys/arch/xen/xen/xennetback_xenbus.c: revision 1.63
sys/dev/bi/if_ni.c: revision 1.45
sys/dev/cadence/if_cemac.c: revision 1.12
sys/dev/ic/am7990.c: revision 1.78
sys/dev/ic/am79900.c: revision 1.27
sys/dev/ic/an.c: revision 1.67
sys/dev/ic/cs89x0.c: revision 1.40
sys/dev/ic/dm9000.c: revision 1.13
sys/dev/ic/dm9000.c: revision 1.14
sys/dev/ic/dp8390.c: revision 1.88
sys/dev/ic/elink3.c: revision 1.141
sys/dev/ic/elinkxl.c: revision 1.122
sys/dev/ic/hme.c: revision 1.98
sys/dev/ic/i82586.c: revision 1.77
sys/dev/ic/lance.c: revision 1.53
sys/dev/ic/mb86950.c: revision 1.27
sys/dev/ic/mb86960.c: revision 1.86
sys/dev/ic/mtd803.c: revision 1.34
sys/dev/ic/pdq_ifsubr.c: revision 1.59
sys/dev/ic/rrunner.c: revision 1.86
sys/dev/ic/seeq8005.c: revision 1.58
sys/dev/ic/sgec.c: revision 1.47
sys/dev/ic/smc90cx6.c: revision 1.72
sys/dev/ic/smc91cxx.c: revision 1.96
sys/dev/ic/tropic.c: revision 1.49
sys/dev/ic/wi.c: revision 1.245
sys/dev/isa/if_eg.c: revision 1.93
sys/dev/isa/if_el.c: revision 1.95
sys/dev/isa/if_iy.c: revision 1.101
sys/dev/ofw/ofnet.c: revision 1.58
sys/dev/pci/if_alc.c: revision 1.27
sys/dev/pci/if_de.c: revision 1.152
sys/dev/pci/if_fpa.c: revision 1.61
sys/dev/pci/if_jme.c: revision 1.34
sys/dev/pci/if_tl.c: revision 1.108
sys/dev/pci/if_vte.c: revision 1.19
sys/dev/pci/ixgbe/ixgbe.h: revision 1.50
sys/dev/pcmcia/if_cnw.c: revision 1.62
sys/dev/pcmcia/if_malo_pcmcia.c: revision 1.17
sys/dev/pcmcia/if_ray.c: revision 1.89
sys/dev/pcmcia/if_xi.c: revision 1.81
sys/dev/pcmcia/mhzc.c: revision 1.51
sys/dev/pcmcia/xirc.c: revision 1.34
sys/dev/qbus/if_de.c: revision 1.33
sys/dev/qbus/if_qe.c: revision 1.78
sys/dev/qbus/if_qt.c: revision 1.22
sys/dev/sbus/be.c: revision 1.87
sys/dev/sbus/qe.c: revision 1.68
sys/dev/scsipi/if_se.c: revision 1.96
sys/dev/usb/if_atu.c: revision 1.59
sys/net/if_l2tp.c: revision 1.28 via patch
sys/net/if_ppp.c: revision 1.160
It's not required to include net/bpfdesc.h. Remove it.
--
Simplify like other drivers. NULL check of ifp->if_bpf is done in
bpf_mtap(), so it's not required to do it here.
--
Remove duplicated inclusion of net/bpf.h.
--
Remove duplicated inclusion of net/bpf.h.
--
Simplify bpf_mtap() call. No functional change.
 1.50.2.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.50.2.1 10-Jun-2019  christos Sync with HEAD
 1.53.4.1 25-Jan-2020  ad Sync with head.
 1.7 19-Jan-2020  thorpej Remove Token Ring support.
 1.6 11-Dec-2005  christos branches: 1.6.164; 1.6.172;
merge ktrace-lwp.
 1.5 27-Feb-2005  perry nuke trailing whitespace
 1.4 02-Nov-2003  wiz branches: 1.4.8; 1.4.10;
Fix some typos. From Tom Cosgrove via jmc@openbsd.
 1.3 17-Oct-1999  cgd branches: 1.3.34;
nuke RCS "Log" and "Header" tags. They cause problems for third parties
importing our sources, and for NetBSD release engineering folks.
(They've been against the NetBSD coding style forever, but they crept
in anyway.)
 1.2 22-Mar-1999  bad branches: 1.2.8;
Oops. RcsID police.
 1.1 22-Mar-1999  bad Chipset driver for TROPIC based Token-Ring cards.
Frontends for IBM and 3COM ISA cards.

By Onno van der Linden <onno@simplex.nl>.
 1.2.8.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.3.34.4 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.3.34.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.3.34.2 18-Sep-2004  skrll Sync with HEAD.
 1.3.34.1 03-Aug-2004  skrll Sync with HEAD
 1.4.10.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.4.8.1 29-Apr-2005  kent sync with -current
 1.6.172.1 25-Jan-2020  ad Sync with head.
 1.6.164.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.15 19-Jan-2020  thorpej Remove Token Ring support.
 1.14 27-Oct-2012  chs branches: 1.14.38; 1.14.46;
split device_t/softc for all remaining drivers.
replace "struct device *" with "device_t".
use device_xname(), device_unit(), etc.
 1.13 12-May-2009  cegger branches: 1.13.12; 1.13.22;
struct device * -> device_t, no functional changes intended.
 1.12 04-Mar-2007  christos branches: 1.12.40; 1.12.56;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.11 11-Dec-2005  christos branches: 1.11.26;
merge ktrace-lwp.
 1.10 27-Feb-2005  perry branches: 1.10.4;
nuke trailing whitespace
 1.9 04-Feb-2005  perry de-__P
 1.8 13-Jun-2000  soren branches: 1.8.26; 1.8.34; 1.8.36;
Call frontend enable/disable functions in the ioctl path.
Use _sc prefixes for some softc members.
A few minor cleanups.
 1.7 06-Jun-2000  soren Add power management hooks.
 1.6 27-May-2000  thorpej branches: 1.6.2;
Don't use sleep() and a callout; just use tsleep().
 1.5 23-Mar-2000  thorpej New callout mechanism with two major improvements over the old
timeout()/untimeout() API:
- Clients supply callout handle storage, thus eliminating problems of
resource allocation.
- Insertion and removal of callouts is constant time, important as
this facility is used quite a lot in the kernel.

The old timeout()/untimeout() API has been removed from the kernel.
 1.4 17-Oct-1999  cgd branches: 1.4.2;
nuke RCS "Log" and "Header" tags. They cause problems for third parties
importing our sources, and for NetBSD release engineering folks.
(They've been against the NetBSD coding style forever, but they crept
in anyway.)
 1.3 29-Apr-1999  bad branches: 1.3.2;
From Onno van der Linden:
Reorganise the driver some what.
Rename tr_reset() to the more appropriate tr_stop().
Create a common tropic reset routine and use it in the frontends.
Move the code in tr_config() which is only used in the card attachment
routines into a new tr_attach() function.
Take adapter off the ring through tr_shutdown() in a shutdown hook.
This simplifies the bus-specific frontend.
 1.2 22-Mar-1999  bad branches: 1.2.2;
Oops. RcsID police.
 1.1 22-Mar-1999  bad Chipset driver for TROPIC based Token-Ring cards.
Frontends for IBM and 3COM ISA cards.

By Onno van der Linden <onno@simplex.nl>.
 1.2.2.1 29-Apr-1999  perry branches: 1.2.2.1.2;
pullup 1.2->1.3 (bad)
 1.2.2.1.2.1 21-Jun-1999  thorpej Sync w/ -current.
 1.3.2.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.4.2.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.6.2.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.8.36.2 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.8.36.1 12-Feb-2005  yamt sync with head.
 1.8.34.1 29-Apr-2005  kent sync with -current
 1.8.26.2 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.8.26.1 04-Feb-2005  skrll Sync with HEAD.
 1.10.4.1 03-Sep-2007  yamt sync with head.
 1.11.26.1 12-Mar-2007  rmind Sync with HEAD.
 1.12.56.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.12.40.1 16-May-2009  yamt sync with head
 1.13.22.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.13.12.1 30-Oct-2012  yamt sync with head
 1.14.46.1 25-Jan-2020  ad Sync with head.
 1.14.38.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.213 05-Jul-2024  rin sys: Drop redundant NULL check before m_freem(9)

m_freem(9) safely has accepted NULL argument at least since 4.2BSD:
https://www.tuhs.org/cgi-bin/utree.pl?file=4.2BSD/usr/src/sys/sys/uipc_mbuf.c

Compile-tested on amd64/ALL.

Suggested by knakahara@
 1.212 29-Jun-2024  riastradh branches: 1.212.2;
if_stats(9): Add ifp argument to if_stat..._ref.

This will enable us to pass the ifp through to a dtrace probe inside.

No functional change intended in this change, but this is an API
change visible to modules so it shouldn't be pulled up.

PR kern/58377
 1.211 10-Feb-2024  andvar s/alloted/allotted/ in comments.
 1.210 20-Dec-2023  thorpej malloc(9) -> kmem(9), and plug a memory leak on detach while I'm here.
 1.209 04-Sep-2023  mrg mask a value with the array size mask to avoid a GCC 12 warning.

i'm fairly sure this can't actually happen, but it likely avoids
any potential bug without real issue.
 1.208 01-Aug-2022  kre Revert this to 1.205, undoing changes apparently mistakenly
committed in 1.206, and the total disaster that the attempt to
revert those in 1.207 created.
 1.207 01-Aug-2022  mlelstv Revert last accidental commits.
 1.206 01-Aug-2022  mlelstv Also fix shift values for SCT constants.
 1.205 25-Jun-2022  tsutsui Pass proper status values to rnd_add_uint32(9) as rnd(9) man page claims.
 1.204 15-Mar-2020  thorpej Don't bother with IFF_OACTIVE.
 1.203 11-Mar-2020  msaitoh Use unsigned to avoid undefined behavior. Found by kUBSan.
 1.202 04-Feb-2020  thorpej Use ifmedia_fini().
 1.201 29-Jan-2020  thorpej Adopt <net/if_stats.h>.
 1.200 10-Nov-2019  chs branches: 1.200.2;
in many device attach paths, allocate memory with M_WAITOK instead of M_NOWAIT
and remove code to handle failures that can no longer happen.
 1.199 13-Sep-2019  msaitoh if_flags is neither int nor short. It's unsigned short.
 1.198 30-Jul-2019  msaitoh Avoid undefined behavior when setting multicast address. found by kUBSan.
 1.197 28-May-2019  msaitoh branches: 1.197.2;
s/recieve/receive/
 1.196 28-May-2019  msaitoh Use ETHER_LOCK()/ETHER_UNLOCK() for all ethernet drivers to protect ec_multi*.
 1.195 23-May-2019  msaitoh Whitespace fix (mainly tabify).
 1.194 23-May-2019  msaitoh No functional change:
- Simplify MII structure initialization and reference.
- u_int*_t -> uint*_t.
- KNF
 1.193 22-Apr-2019  msaitoh On drivers which use MII(4) and have hook SIOC[GS]IFMEDIA which just pass to
ifmedia_ioctl(), the hook is not required because ether_ioctl has it
(if_ethersubr.c rev. 1.160). These drivers don't return ENETRESET in
ifmedia_ioctl(), so no functional change.
 1.192 22-Jan-2019  msaitoh Change MII PHY read/write API from:

int (*mii_readreg_t)(device_t, int, int);
void (*mii_writereg_t)(device_t, int, int, int);
to:

int (*mii_readreg_t)(device_t, int, int, uint16_t *);
int (*mii_writereg_t)(device_t, int, int, uint16_t);

Now we can test if a read/write operation failed or not by the return value.

In 802.3 spec says that the PHY shall not respond to read/write transaction
to the unimplemented register(22.2.4.3). Detecting timeout can be used to
check whether a register is implemented or not (if the register conforms to
the spec). ukphy(4) can be used this for MII_MMDACR and MII_MMDAADR.

Note that I noticed that the following code do infinite loop in the
read/wirte function. If it accesses unimplemented PHY register, it will hang.
It should be fixed:

arm/at91/at91emac.c
arm/ep93xx/epe.c
arm/omap/omapl1x_emac.c
mips/ralink/ralink_eth.c
arch/powerpc/booke/dev/pq3etsec.c(read)
dev/cadence/if_cemac.c <- hkenken
dev/ic/lan9118.c


Tested with the following device:

axe+ukphy
axe+rgephy
axen+rgephy (tested by Andrius V)
wm+atphy
wm+ukphy
wm+igphy
wm+ihphy
wm+makphy
sk+makphy
sk+brgphy
sk+gentbi
msk+makphy
sip+icsphy
sip+ukphy
re+rgephy
bge+brgphy
bnx+brgphy
gsip+gphyter
rtk+rlphy
fxp+inphy (tested by Andrius V)
tlp+acphy
ex+exphy
epic+qsphy
vge+ciphy (tested by Andrius V)
vr+ukphy (tested by Andrius V)
vte+ukphy (tested by Andrius V)

Not tested (MAC):
arm:at91emac
arm:cemac
arm:epe
arm:geminigmac
arm:enet
arm:cpsw
arm:emac(omac)
arm:emac(sunxi)
arm:npe
evbppc:temac
macppc:bm
macppc:gm
mips:aumac
mips:ae
mips:cnmac
mips:reth
mips:sbmac
playstation2:smap
powerpc:tsec
powerpc:emac(ibm4xx)
sgimips:mec
sparc:be
sf
ne(ax88190, dl10019)
awge
ep
gem
hme
smsh
mtd
sm
age
alc
ale
bce
cas
et
jme
lii
nfe
pcn
ste
stge
tl
xi
aue
mue
smsc
udav
url

Not tested (PHY):
amhphy
bmtphy
dmphy
etphy
glxtphy
ikphy
iophy
lxtphy
nsphyter
pnaphy
rdcphy
sqphy
tlphy
tqphy
urlphy
 1.191 26-Jun-2018  msaitoh branches: 1.191.2;
Implement the BPF direction filter (BIOC[GS]DIRECTION). It provides backward
compatibility with BIOC[GS]SEESENT ioctl. The userland interface is the same
as FreeBSD.

This change also fixes a bug that the direction is misunderstand on some
environment by passing the direction to bpf_mtap*() instead of checking
m->m_pkthdr.rcvif.
 1.190 23-May-2017  ozaki-r branches: 1.190.8;
Apply deferred if_start to more drivers

And annotate some XXX_start as it runs in softint to clarify that
it doesn't need deferred if_start.
 1.189 15-Dec-2016  ozaki-r Move bpf_mtap and if_ipackets++ on Rx of each driver to percpuq if_input

The benefits of the change are:
- We can reduce codes
- We can provide the same behavior between drivers
- Where/When if_ipackets is counted up
- Note that some drivers still update packet statistics in their own
way (periodical update)
- Moved bpf_mtap run in softint
- This makes it easy to MP-ify bpf

Proposed on tech-kern and tech-net
 1.188 11-Jul-2016  msaitoh branches: 1.188.2;
KNF. No functional change.
 1.187 10-Jun-2016  ozaki-r Introduce m_set_rcvif and m_reset_rcvif

The API is used to set (or reset) a received interface of a mbuf.
They are counterpart of m_get_rcvif, which will come in another
commit, hide internal of rcvif operation, and reduce the diff of
the upcoming change.

No functional change.
 1.186 09-Feb-2016  ozaki-r Introduce softint-based if_input

This change intends to run the whole network stack in softint context
(or normal LWP), not hardware interrupt context. Note that the work is
still incomplete by this change; to that end, we also have to softint-ify
if_link_state_change (and bpf) which can still run in hardware interrupt.

This change softint-ifies at ifp->if_input that is called from
each device driver (and ieee80211_input) to ensure Layer 2 runs
in softint (e.g., ether_input and bridge_input). To this end,
we provide a framework (called percpuq) that utlizes softint(9)
and percpu ifqueues. With this patch, rxintr of most drivers just
queues received packets and schedules a softint, and the softint
dequeues packets and does rest packet processing.

To minimize changes to each driver, percpuq is allocated in struct
ifnet for now and that is initialized by default (in if_attach).
We probably have to move percpuq to softc of each driver, but it's
future work. At this point, only wm(4) has percpuq in its softc
as a reference implementation.

Additional information including performance numbers can be found
in the thread at tech-kern@ and tech-net@:
http://mail-index.netbsd.org/tech-kern/2016/01/14/msg019997.html

Acknowledgment: riastradh@ greatly helped this work.
Thank you very much!
 1.185 26-Feb-2015  nakayama Stop the interface before detaching to avoid the race between
tlp_detach() and tlp_intr().

While there, add missing callout_destroy()s.
 1.184 10-Aug-2014  tls branches: 1.184.2; 1.184.4;
Merge tls-earlyentropy branch into HEAD.
 1.183 15-Sep-2013  martin branches: 1.183.2;
Comment out unused variable
 1.182 14-Sep-2013  joerg GC unused functions and variables.
 1.181 22-Jul-2012  matt branches: 1.181.2; 1.181.4;
Fix mii_statchg to take a 'struct ifnet *' instead of device_t. This fixes
problem with a common MDIO bus used for multiple interfaces.
Some drivers converted to CFATTACL_DECL_NEW.
 1.180 02-Feb-2012  tls branches: 1.180.2; 1.180.6; 1.180.8;
Entropy-pool implementation move and cleanup.

1) Move core entropy-pool code and source/sink/sample management code
to sys/kern from sys/dev.

2) Remove use of NRND as test for presence of entropy-pool code throughout
source tree.

3) Remove use of RND_ENABLED in device drivers as microoptimization to
avoid expensive operations on disabled entropy sources; make the
rnd_add calls do this directly so all callers benefit.

4) Fix bug in recent rnd_add_data()/rnd_add_uint32() changes that might
have lead to slight entropy overestimation for some sources.

5) Add new source types for environmental sensors, power sensors, VM
system events, and skew between clocks, with a sample implementation
for each.

ok releng to go in before the branch due to the difficulty of later
pullup (widespread #ifdef removal and moved files). Tested with release
builds on amd64 and evbarm and live testing on amd64.
 1.179 13-Aug-2011  jakllsch branches: 1.179.2; 1.179.6;
Fix TLP_DEBUG after previous
 1.178 13-Aug-2011  christos simplifying code, unconfuses gcc index calculation.
 1.177 09-Jul-2011  christos - add a routine to get the name of the card.
 1.176 13-Nov-2010  uebayasi Don't pull in the whole uvm(9) API to access only PAGE_SIZE and
some other constants. These are provided by sys/param.h now.
 1.175 05-Apr-2010  joerg Push the bpf_ops usage back into bpf.h. Push the common ifp->if_bpf
check into the inline functions as well the fourth argument for
bpf_attach.
 1.174 19-Jan-2010  pooka branches: 1.174.2; 1.174.4;
Redefine bpf linkage through an always present op vector, i.e.
#if NBPFILTER is no longer required in the client. This change
doesn't yet add support for loading bpf as a module, since drivers
can register before bpf is attached. However, callers of bpf can
now be modularized.

Dynamically loadable bpf could probably be done fairly easily with
coordination from the stub driver and the real driver by registering
attachments in the stub before the real driver is loaded and doing
a handoff. ... and I'm not going to ponder the depths of unload
here.

Tested with i386/MONOLITHIC, modified MONOLITHIC without bpf and rump.
 1.173 04-Dec-2009  dyoung Oops, there was one mii_activate() call left. Delete it.
 1.172 05-Sep-2009  tsutsui Invert logic around nested pmf(9) registrations for readability.
 1.171 01-Sep-2009  jmcneill aprint-ify
 1.170 27-Aug-2009  dyoung Use *_FOREACH() routines instead of open-coding them.
 1.169 17-Apr-2009  cegger change tlp_attach() to return an error code on failure.
 1.168 17-Apr-2009  cegger set dmamap to NULL when bus_dmamap_create() fails to prevent bus_dmamap_destroy to be called with an invalid dmamap in error path.
 1.167 17-Apr-2009  cegger device_t/softc split. Tested with tlp at pci
 1.166 17-Apr-2009  cegger use device_private
 1.165 17-Apr-2009  cegger struct device * -> device_t
u_intNN_t -> uintNN_t
 1.164 07-Nov-2008  dyoung branches: 1.164.4;
*** Summary ***

When a link-layer address changes (e.g., ifconfig ex0 link
02:de:ad:be:ef:02 active), send a gratuitous ARP and/or a Neighbor
Advertisement to update the network-/link-layer address bindings
on our LAN peers.

Refuse a change of ethernet address to the address 00:00:00:00:00:00
or to any multicast/broadcast address. (Thanks matt@.)

Reorder ifnet ioctl operations so that driver ioctls may inherit
the functions of their "class"---ether_ioctl(), fddi_ioctl(), et
cetera---and the class ioctls may inherit from the generic ioctl,
ifioctl_common(), but both driver- and class-ioctls may override
the generic behavior. Make network drivers share more code.

Distinguish a "factory" link-layer address from others for the
purposes of both protecting that address from deletion and computing
EUI64.

Return consistent, appropriate error codes from network drivers.

Improve readability. KNF.

*** Details ***

In if_attach(), always initialize the interface ioctl routine,
ifnet->if_ioctl, if the driver has not already initialized it.
Delete if_ioctl == NULL tests everywhere else, because it cannot
happen.

In the ioctl routines of network interfaces, inherit common ioctl
behaviors by calling either ifioctl_common() or whichever ioctl
routine is appropriate for the class of interface---e.g., ether_ioctl()
for ethernets.

Stop (ab)using SIOCSIFADDR and start to use SIOCINITIFADDR. In
the user->kernel interface, SIOCSIFADDR's argument was an ifreq,
but on the protocol->ifnet interface, SIOCSIFADDR's argument was
an ifaddr. That was confusing, and it would work against me as I
make it possible for a network interface to overload most ioctls.
On the protocol->ifnet interface, replace SIOCSIFADDR with
SIOCINITIFADDR. In ifioctl(), return EPERM if userland tries to
invoke SIOCINITIFADDR.

In ifioctl(), give the interface the first shot at handling most
interface ioctls, and give the protocol the second shot, instead
of the other way around. Finally, let compatibility code (COMPAT_OSOCK)
take a shot.

Pull device initialization out of switch statements under
SIOCINITIFADDR. For example, pull ..._init() out of any switch
statement that looks like this:

switch (...->sa_family) {
case ...:
..._init();
...
break;
...
default:
..._init();
...
break;
}

Rewrite many if-else clauses that handle all permutations of IFF_UP
and IFF_RUNNING to use a switch statement,

switch (x & (IFF_UP|IFF_RUNNING)) {
case 0:
...
break;
case IFF_RUNNING:
...
break;
case IFF_UP:
...
break;
case IFF_UP|IFF_RUNNING:
...
break;
}

unifdef lots of code containing #ifdef FreeBSD, #ifdef NetBSD, and
#ifdef SIOCSIFMTU, especially in fwip(4) and in ndis(4).

In ipw(4), remove an if_set_sadl() call that is out of place.

In nfe(4), reuse the jumbo MTU logic in ether_ioctl().

Let ethernets register a callback for setting h/w state such as
promiscuous mode and the multicast filter in accord with a change
in the if_flags: ether_set_ifflags_cb() registers a callback that
returns ENETRESET if the caller should reset the ethernet by calling
if_init(), 0 on success, != 0 on failure. Pull common code from
ex(4), gem(4), nfe(4), sip(4), tlp(4), vge(4) into ether_ioctl(),
and register if_flags callbacks for those drivers.

Return ENOTTY instead of EINVAL for inappropriate ioctls. In
zyd(4), use ENXIO instead of ENOTTY to indicate that the device is
not any longer attached.

Add to if_set_sadl() a boolean 'factory' argument that indicates
whether a link-layer address was assigned by the factory or some
other source. In a comment, recommend using the factory address
for generating an EUI64, and update in6_get_hw_ifid() to prefer a
factory address to any other link-layer address.

Add a routing message, RTM_LLINFO_UPD, that tells protocols to
update the binding of network-layer addresses to link-layer addresses.
Implement this message in IPv4 and IPv6 by sending a gratuitous
ARP or a neighbor advertisement, respectively. Generate RTM_LLINFO_UPD
messages on a change of an interface's link-layer address.

In ether_ioctl(), do not let SIOCALIFADDR set a link-layer address
that is broadcast/multicast or equal to 00:00:00:00:00:00.

Make ether_ioctl() call ifioctl_common() to handle ioctls that it
does not understand.

In gif(4), initialize if_softc and use it, instead of assuming that
the gif_softc and ifp overlap.

Let ifioctl_common() handle SIOCGIFADDR.

Sprinkle rtcache_invariants(), which checks on DIAGNOSTIC kernels
that certain invariants on a struct route are satisfied.

In agr(4), rewrite agr_ioctl_filter() to be a bit more explicit
about the ioctls that we do not allow on an agr(4) member interface.

bzero -> memset. Delete unnecessary casts to void *. Use
sockaddr_in_init() and sockaddr_in6_init(). Compare pointers with
NULL instead of "testing truth". Replace some instances of (type
*)0 with NULL. Change some K&R prototypes to ANSI C, and join
lines.
 1.163 28-Apr-2008  martin branches: 1.163.6; 1.163.8;
Remove clause 3 and 4 from TNF licenses
 1.162 08-Apr-2008  cegger branches: 1.162.2; 1.162.4;
use aprint_*_dev and device_xname
 1.161 23-Mar-2008  tsutsui On preparing a setup packet, use proper byteswap ops and byte shift ops
rather than #ifdef BYTE_ORDER and subtle pointer casts.
 1.160 23-Mar-2008  tsutsui Ignore the Report on MII error bit if chip doesn't have MII.
Fixes annoying "tlp0: MII error" messages on Qube 2700 with 21041.
 1.159 11-Mar-2008  dyoung Prepare for PMF self-suspension: in the if_stop() methods, clear
IFF_UP and IFF_RUNNING before running the 'disable' step, instead
of after. Soon I will handle the 'disable' step by calling into
PMF, which may call if_stop(, 0). Ordinarily, that is harmless.
This change lets the if_stop() routines exit early when they find
on entry that IFF_RUNNING is not set.
 1.158 09-Mar-2008  jmcneill Convert from shutdownhook/powerhook to PMF.
 1.157 19-Jan-2008  dyoung branches: 1.157.2; 1.157.6;
Make many ethernet drivers share the common code for MII media
handling, ether_mediastatus() and ether_mediachange(). Check for
a non-ENXIO error return from mii_mediachg(). (ENXIO indicates
that a PHY is suspended.)

This patch shrinks the source code size by 979 lines. There was
a 5100-byte savings on the NetBSD/i386 kernel configuration, ALL.

I have made a few miscellaneous changes, too:

gem(4): use LIST_EMPTY(), LIST_FOREACH().
mtd(4): handle media ioctls, for a change!
axe(4): do not track link status in sc->axe_link any longer
nfe(4), aue(4), axe(4), udav(4), url(4): do not reset all PHYs
on a change of media

Except for the change to mtd(4), no functional changes are intended.

XXX This patch affects more architectures than I can feasibly
XXX compile and run. I have compiled macppc, sparc64, i386. I
XXX have run the patches on i386 boxen with bnx(4) and sip(4).
XXX Compiling and running on evbmips (MERAKI, ADM5120) is in
XXX progress.
 1.156 18-Jan-2008  ad Noisy printf
 1.155 29-Dec-2007  tsutsui Fix typo in comments.
 1.154 19-Oct-2007  ad branches: 1.154.2; 1.154.8;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.153 29-Sep-2007  scw branches: 1.153.2;
s/NPBFILTER/NBPFILTER/ in some #endif comments. No functional change.
 1.152 27-Aug-2007  dyoung branches: 1.152.2; 1.152.4;
Constify.
 1.151 26-Aug-2007  dyoung Constify: LLADDR -> CLLADDR. I'm aiming here to make it easier to
identify sockaddr_dl abuse that remains in the kernel, especially
the potential for overwriting memory past the end of a sockaddr_dl
with, e.g., memcpy(LLADDR(), ...).
 1.150 09-Jul-2007  ad branches: 1.150.2; 1.150.6;
Merge some of the less invasive changes from the vmlocking branch:

- kthread, callout, devsw API changes
- select()/poll() improvements
- miscellaneous MT safety improvements
 1.149 04-Mar-2007  christos branches: 1.149.2; 1.149.4;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.148 19-Feb-2007  rumble Extract mac addresses on Phobos G100 boards.
 1.147 24-Sep-2006  jmcneill branches: 1.147.2; 1.147.4;
Add "name" parameter to powerhook_establish, to aid debugging. No objections
on tech-kern@
 1.146 30-Aug-2006  rumble branches: 1.146.2; 1.146.4;
Phobos boards (my G130 at least) have a non-standard srom layout. Try to
identify it and pull out the enaddr.
 1.145 26-May-2006  blymn branches: 1.145.4;
Clean up bogus whitespace
 1.144 14-May-2006  elad branches: 1.144.2;
integrate kauth.
 1.143 25-Mar-2006  rpaulo Add support for the Conexant RS7112. From Frank Wille <frank@phoenix.owl.de>.
 1.142 20-Feb-2006  thorpej branches: 1.142.2; 1.142.4; 1.142.6;
Use device_is_active() rather than testing dv_flags for DVF_ACTIVE
directly.
 1.141 24-Dec-2005  perry branches: 1.141.2; 1.141.4; 1.141.6;
Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.140 11-Dec-2005  christos merge ktrace-lwp.
 1.139 17-Jul-2005  he Make tlp_idle() not be static, so that the newsmips version of the
driver can access that function again.

Approved by thorpej
 1.138 08-Jul-2005  thorpej - Use ANSI function decls.
- Liberally apply static.
 1.137 23-Jun-2005  rpaulo branches: 1.137.2;
Add support for ASIX AX88140A/AX88141 chipsets using only
the 10/100 MII with inspiration from FreeBSD dc(4) driver.

Tested on i386 and macppc.

Reviewed by Jason Thorpe and ok'ed by Hubert Feyrer.
 1.136 23-Mar-2005  wiz Remove duplicate word in comment. From Rui Paulo in PR 29767.
 1.135 27-Feb-2005  perry branches: 1.135.2;
nuke trailing whitespace
 1.134 06-Feb-2005  skrll Initialize 'error' in all cases in ioctl handler, otherwise it doesn't
compile (and of course might return garbage). [hi kim!]
 1.133 06-Feb-2005  kim If the interface is up and running, only modify the receive filter
when setting promiscuous or debug mode. This avoids resetting the
chip unnecessarily.

Fixes PR kern/29126.
 1.132 04-Feb-2005  perry de-__P
 1.131 30-Jan-2005  thorpej Eliminate use of M_HASFCS.
 1.130 11-Dec-2004  sketch branches: 1.130.2; 1.130.4;
Silence the 'receive process failed to idle' message on the Davicom DM9102A.
 1.129 30-Oct-2004  thorpej When adding/deleting multicast addresses, only whack the address
filter if the interface is marked RUNNING.

Fixes kern/27678.
 1.128 05-Aug-2004  jkunz Attach phy anyway if srom has invalid contents.
Patch sugested by Charles M. Hannum on tech-kern.
 1.127 02-Jul-2004  mycroft Add debugging code to dump the filter setup descriptor, similar to the transmit
path.
 1.126 18-Dec-2003  thorpej branches: 1.126.2; 1.126.4;
If we're running on a Connectix Virtual PC, we might get a packet longer
than a max size Ethernet frame without getting a frame-too-long error. VPC
seems to be adding 4 zeros at the end of every frame. Detect this condition
and simply truncate the packet to a max size Ethernet frame.

I now have no problems with networking on NetBSD inside Virtual PC 6.
 1.125 25-Oct-2003  christos Fix uninitialized variable warning.
 1.124 25-Oct-2003  christos Fix uninitialized variable warnings
 1.123 07-Sep-2003  tsutsui Handle SROM quirk of tulip on Cobalt RAQ2. Fixes kern/20702.
 1.122 26-Feb-2003  matt branches: 1.122.2;
Add MBUFTRACE kernel option.
Do a little mbuf rework while here. Change all uses of MGET*(*, M_WAIT, *)
to m_get*(M_WAIT, *). These are not performance critical and making them
call m_get saves considerable space. Add m_clget analogue of MCLGET and
make corresponding change for M_WAIT uses.
Modify netinet, gem, fxp, tulip, nfs to support MBUFTRACE.
Begin to change netstat to use sysctl.
 1.121 08-Oct-2002  minoura Check existence of the default 10baseT media for 21140.
If one does not exist, fall back to the first.
 1.120 27-Sep-2002  provos remove trailing \n in panic(). approved perry.
 1.119 18-Sep-2002  thorpej For the 21142/21143 internal Nway, only advertise/resolve media for
which we have SROM blocks.
 1.118 14-Jul-2002  chs use the SROM info to set the media in 2114[23] autonegotiation
rather than just fiddling the opmode CSR, since we might
need to change the SIA CSRs as well (eg. for some ZNYX cards).
from PR 17510.
 1.117 09-Jul-2002  chuck only powerdown on a suspend. do not powerdown on a standby (PR#17537).
 1.116 08-Jul-2002  mycroft Add a missing DELAY() in the initial GPIO setup for the 21140.
 1.115 01-Jun-2002  lukem SIMPLEQ rototill:
- implement SIMPLEQ_REMOVE(head, elm, type, field). whilst it's O(n),
this mirrors the functionality of SLIST_REMOVE() (the other
singly-linked list type) and FreeBSD's STAILQ_REMOVE()
- remove the unnecessary elm arg from SIMPLEQ_REMOVE_HEAD().
this mirrors the functionality of SLIST_REMOVE_HEAD() (the other
singly-linked list type) and FreeBSD's STAILQ_REMOVE_HEAD()
- remove notes about SIMPLEQ not supporting arbitrary element removal
- use SIMPLEQ_FOREACH() instead of home-grown for loops
- use SIMPLEQ_EMPTY() appropriately
- use SIMPLEQ_*() instead of accessing sqh_first,sqh_last,sqe_next directly
- reorder manual page; be consistent about how the types are listed
- other minor cleanups
 1.114 31-May-2002  thorpej Remove duplicate TULIP_SET/TULIP_CLR.
 1.113 03-May-2002  mycroft branches: 1.113.2; 1.113.4;
Clean up some dead code.
Combine nway_reset() into nway_auto().
 1.112 03-May-2002  mycroft 5) Be more liberal in blasting SIATXRX and SIASTAT in nway_auto(); in
particular, make sure that all the SIASTAT_ANS bits are in the right state
so we don't do something inane.

Still doesn't actually bring the link up properly, but at least it negotiates
most of the time, and does it a little faster.
 1.111 03-May-2002  mycroft More internal Nway issues:
1) Do not call tlp_sia_update_link() in Nway mode, and do not look at SIASTAT
in any other place that nway_status(), where we first check that it's valid.
In other places, look at IFM_ACTIVE after having call nway_status().
2) Eliminate stupid MII_MEDIACHG calls, and arrange for nway_service() to
update status on every call.
3) Nuke the synchronous case of nway_auto() from orbit.
4) Do not call nway_statchg() when using manual configuration; tlp_sia_set()
does everything we need.
 1.110 03-May-2002  mycroft Fix multiple problems with 2114x internal Nway:
1) Set OPMODE_TTM in the default tsti_opmode, so that nway_status doesn't
blow up and report the wrong media type when statically configured. (This
code is a hack.)
2) Do not set IFM_ACTIVE (i.e. ignore SIASTAT_LS*) when in auto-negotiation
mode and negotiation has not completed (per 21143 manual).
3) Do not clear auto-negotiation mode; otherwise the chip will not
renegotiate on a link failure.

With these changes, 10/100 selection is more stable, and auto-negotiation
comes up with the right status and detects link, but the link does not work
unless it's hardwired. More work is needed.
 1.109 14-Apr-2002  mycroft tm_gpctl and tm_gpdata must be shifted right 16 bits. DOH.
This makes another CardBus tlp card work...
 1.108 09-Apr-2002  chs add support for built-in NWay autonegotiation on 2114[23], Macronix
98713A, 98715, 98715A, 98725, and Lite-On 82C115.
 1.107 05-Apr-2002  mycroft With certain 21140 and 21143 SROM formats, OPMODE_FD was never being set when
the interface was wired to full-duplex mode. Duh.
Also, add OPMODE_TTM to OPMODE_MEDIA_BITS, to insure that it is changed when
we switch between 10 and 100.
 1.106 26-Mar-2002  chs move some prototypes from tulip.c to tulipvar.h so they can
be used by bus-specific code.
 1.105 16-Mar-2002  chs in the TULIP_ROM_MB_21142_MII case of tlp_2114x_isv_tmsw_init(),
use "cp" instead of "ncp" as a temporary pointer into the SROM.
we still need the value of ncp here, it points to the next media block.
(update the copy of this code in tlp_21142_reset() just 'cause.)
this makes the BNC port on the Adaptec ANA-6911A work.
 1.104 14-Mar-2002  chs assume that 21143 SROM info blocks are in extended format (as the spec
requires), even if the bit to indicate this is not set.
this makes Phobos P430 4-port cards work.
 1.103 12-Jan-2002  tsutsui Call malloc(9) with M_ZERO flag instead of memset() after malloc().
 1.102 22-Nov-2001  yamt use little-endian crc on multicast hash for admtek chips.
 1.101 13-Nov-2001  lukem add/cleanup RCSID
 1.100 10-Nov-2001  perry trivially rename some macro parameters to avoid lint warnings.
 1.99 16-Sep-2001  wiz branches: 1.99.2;
Spell 'occurred' with two 'r's.
 1.98 20-Aug-2001  wiz branches: 1.98.2;
Succeed has two 'c's.
 1.97 14-Aug-2001  mrg mtod() with uintptr_t, not bus_addr_t.
 1.96 23-Jul-2001  thorpej Make sure to initialize the all Rx descriptors properly in *_init()
even if mbufs for them are already allocated.
 1.95 19-Jul-2001  thorpej Use BUS_DMA_READ and BUS_DMA_WRITE in some obvious places.
 1.94 07-Jul-2001  thorpej branches: 1.94.2;
bcmp -> memcmp
 1.93 12-Jun-2001  thorpej Don't need INET or NS includes here.
 1.92 12-Jun-2001  wiz receive, not recieve
 1.91 24-Feb-2001  cgd branches: 1.91.2;
C requires that labels be followed by statements.
 1.90 21-Feb-2001  jdolecek make some more constant arrays 'const'
 1.89 17-Jan-2001  thorpej Filter "receive process failed to idle" on noisy chips (like the
ADMtek AN985).
 1.88 16-Jan-2001  thorpej Fix register offset botch when setting the multicast filter on
the ADMtek AN985.
 1.87 08-Jan-2001  thorpej On ADMtek chips, don't just idle the chip when programming the
multicast filter. These chips don't like to go into "idle" state
very much, so we have to use the big hammer and reset the chip,
instead.
 1.86 08-Jan-2001  thorpej The ADMtek AN985 "ghosts" the single built-in PHY at every MII address.
Work around this by having a custom media init routine that limits the
search to MII address 1.
 1.85 07-Jan-2001  thorpej Also ignore receiver errors if VLAN_MTU is enabled; the 21040 appears
to require this.
 1.84 19-Dec-2000  thorpej Fix a problem with the ALTQ changes that can cause bogus memory
refernces. Problem reported by Luke Mewburn.
 1.83 14-Dec-2000  thorpej ALTQ'ify.
 1.82 26-Nov-2000  takemura Add new powerhook argument values, PWR_SOFTSUSPEND, PWR_SOFTSTANDBY and
PWR_SOFTRESUME. Apm calls powerhook with the values in normal interrupt
priority level while others are protected with splhigh().
 1.81 15-Nov-2000  thorpej Move bpfattach()/bpfdetach() calls into ether_ifattach()/ether_ifdetach().
 1.80 15-Oct-2000  thorpej Don't trim off the FCS, pass it up.
 1.79 11-Oct-2000  thorpej Use ether_ioctl().
 1.78 11-Oct-2000  onoe Add flags to indicate that tlp_init() should set some more BUSMODE bits.
TULIPF_BLE /* data is big endian */
TULIPF_DBO /* descriptor is big endian */
These setting is required for Big-endian bus front-end (such as APbus for
newsmips) to work with tulip. Also,
sc_maxburst
member is added to the tulip_softc to limit the maximum burst length.
This member defaults to zero which means no restriction for burst length.
 1.77 09-Oct-2000  enami Move inclusion of rnd.h and sys/rnd.h from tulip.c to tulipvar.h.
 1.76 09-Oct-2000  enami Make tulip a random source.
 1.75 05-Oct-2000  bouyer When 802.1Q MTU, we have to ignore the Frame Too Long errors, and there's no
need to disable RWT and JAB.
 1.74 03-Oct-2000  thorpej Support ETHERCAP_VLAN_MTU by igorning Receive Watchdog and Transmit Jabber
errors if VLANs are configured on the interface.
 1.73 03-Oct-2000  thorpej Add support for the ADMtek AN983 and AN985.
 1.72 01-Oct-2000  thorpej Move the check for "promisc + unicast + not for us" into ether_input(),
and change Ethernet drivers to always pass all received frames to
ether_input() (with a few exceptions, which are documented in the
code).
 1.71 03-Aug-2000  castor Support some differences in the Macronix 98715AEC-C and E chips from the other
98715* series.

The MX98715AEC-[C,E] use a different location in the serial eerom for
LED control, and programming it with the original location's values
caused unpredictable behavior.

Also, start integrating fixes where media changes on an adapter
under load may fail. There's more work to be done here, but I need
to sort out our internal changes a little more carefully.
 1.70 04-Jul-2000  thorpej Remove work-around for Lite-On PNIC in tlp_filter_setup() that is
apparently no longer necessary (probably due to other fixes that
have happened in the filter setup path) and is in fact harmful.

Based on a patch from Krister Walfridsson, who claims this makes
his newer NetGear FA-310TX work (although, my older NetGear FA-310TX
still does not, but fails in an entirely different way).
 1.69 28-Jun-2000  mrg remove include of <vm/vm.h>. <vm/vm.h> -> <uvm/uvm_extern.h>
 1.68 26-May-2000  thorpej branches: 1.68.4;
Add support for the Davicom DM9102 and DM9102A 10/100 Ethernet chips.

Partially based on diffs submitted by Matthew Orgass <darkstar@pgh.net>
and IWAMOTO Toshihiro <iwamoto@sat.t.u-tokyo.ac.jp>.
 1.67 25-May-2000  thorpej So, while the DEC chips and other clones want no FS|LS in the
setup descriptor, apparently the Xircom X3201-3 requires it.
 1.66 25-May-2000  thorpej Fix a couple of typos in debugging messages. From IWAMOTO Toshihiro,
kern/10194.
 1.65 25-May-2000  thorpej Don't set FS and LS in the setup packet descriptor. From
IWAMOTO Toshihiro <iwamoto@sat.t.u-tokyo.ac.jp>, kern/10194,
and confirmed with the 21040 manual.
 1.64 18-May-2000  thorpej Use big-endian CRC on ADMtek multicast hash.
 1.63 12-May-2000  thorpej If using ring-mode, don't update the receive descriptor list base address
when a receive overrun occurs. From Castor Fu <castor@geocast.com>.
 1.62 12-May-2000  thorpej Use ether_crc32_le().
 1.61 07-Apr-2000  thorpej Add a patchable variable `tlp_srom_debug' that enables dumping of
SROM output, etc.
 1.60 04-Apr-2000  thorpej - if_tlp_cardbus.c: Use the `pmreg' pointer passed by by
cardbus_get_capability() [mirror change already made to if_tlp_pci.c]
- if_tlp_cardbus.c: If we don't find an ISV SROM, try to grab the
Ethernet address from the CIS.
- if_tlp_cardbus.c: set CardBus cards to store-and-forward mode from
the get-go.
- Put the TxThresh tables in tulipvar.h, and use them in the CardBus
and PCI front-ends to go to store-and-forward mode.
- Document the Xircom X3201-3 clone a little more.
 1.59 02-Apr-2000  mycroft If the SROM size is to far out of range, issue a diagnostic and set the size
to 1Kb. Some boards (e.g. my SMC9332) have a broken MicroWire interface.
 1.58 02-Apr-2000  thorpej Slight correction to last: really only do it if it's a 21142 or 21143.
 1.57 02-Apr-2000  mycroft When using MII on 2114[23] chips, zero the SIA TXRX register to disable the
internal Nway engine. This fixed a major performance problem.
Thanks to Matt Thomas for pointing this out.
 1.56 23-Mar-2000  thorpej New callout mechanism with two major improvements over the old
timeout()/untimeout() API:
- Clients supply callout handle storage, thus eliminating problems of
resource allocation.
- Insertion and removal of callouts is constant time, important as
this facility is used quite a lot in the kernel.

The old timeout()/untimeout() API has been removed from the kernel.
 1.55 20-Mar-2000  thorpej Get rid of the powerhook when we detach.
 1.54 19-Mar-2000  thorpej Add suspend/resume hooks to ensure that the chip doesn't scramble memory
after an APM suspend and is unsnoozed after an APM resume.
 1.53 15-Mar-2000  thorpej Add power management support to the `tlp' driver. The battery on my
laptop lasts a whole lot longer now.
 1.52 10-Mar-2000  thorpej Slight change to the SROM size printf.
 1.51 07-Mar-2000  enami Add missing `cnt++'.
 1.50 07-Mar-2000  enami Also, fix indentation in previous commit.
 1.49 07-Mar-2000  soren Fix bug in previous.
 1.48 07-Mar-2000  soren Only print SROM size if TLP_DEBUG.
 1.47 07-Mar-2000  mycroft Determine the size of the SROM by probing the chip using the standard Microwire
protocol. Eliminates the need for srom_quirks and some other trash.
 1.46 06-Mar-2000  thorpej No longer necessary to futz with ifp->if_baudrate here.
 1.45 06-Mar-2000  enami Remove redundant assignment.
 1.44 02-Feb-2000  thorpej Don't dry to diving MIIF_NOISOLATE in the PHY drivers. Instead, pass
flags down from the parent to child vi mii_attach().
 1.43 02-Feb-2000  thorpej Bring some order to the chaos which was the MII code function naming
"conventions".
 1.42 01-Feb-2000  thorpej First cut at detach support; doens't fully work yet.
 1.41 28-Jan-2000  thorpej When possible, use ring mode for descriptors. Not only is this slightly
more efficient on genuine DEC chips, but some clones apparently Lose Badly
if you use chain mode. To further complicate things, some clones *only*
do chain mode, so make this whole mess conditional.
 1.40 28-Jan-2000  thorpej Just use a regular Tx descriptor for the setup packet; don't bother with
a separate one.
 1.39 25-Jan-2000  thorpej Some changes for the Xircom X3201-3 in 21143 emulation mode:
- The Xircom doesn't bring itself out of reset; we have to do it.
- The Xircom requires transmit buffers to be aligned to 4 bytes, too.

Partially from Rafal Boni (though the Tx buffer alignment issue is
handled much differently in this version).
 1.38 25-Jan-2000  thorpej Add a chip type for the Xircom X3201-3, and centralize the declaration
of the chip names array.
 1.37 25-Jan-2000  thorpej When checking for a non-standard address ROM format, allow the
Cobalt Networks address ROM through.

From Soren S. Jorvang <soren@wheel.dk>
 1.36 15-Dec-1999  tsutsui add one more htole32().
fixes "tlp0: filter setup timeout" on my macppc.
 1.35 11-Dec-1999  thorpej - Don't try to run the chip in big-endian mode. Not all chips support
this consistently, and it doesn't always work even when the chip
supports it.
- Make sure things DMA'd to the chip that the chip interprets are in
little-endian mode.
 1.34 07-Dec-1999  thorpej When checking the SROM checksum, if the standard location fails, try
the new standard location (according to the SROM format update document
for the 21143). From Masanori Kanaoka.
 1.33 19-Nov-1999  thorpej - Use the common MII bit-bang module.
- Add support other than 128-byte SROMs.
- Add support for the 21142/21143 MII.
 1.32 12-Nov-1999  thorpej Call mii_down() as appropriate.
 1.31 04-Nov-1999  thorpej Do rd/line and rd/mult on the MX98725 and LC82C115, too.
 1.30 04-Nov-1999  thorpej Use Memory Read Line and Memory Read Multiple on the 21140, 21140A,
21142, and 21143, if the PCI bus says its okay.
 1.29 04-Nov-1999  thorpej Adapt to mii_phy_probe() change.
 1.28 03-Nov-1999  thorpej Update for ifmedia changes.
 1.27 03-Nov-1999  thorpej More or less completely rewrite the way DECchip media is handled, and
add support for the DECchip 21142/21143 SIA/SYM media. Make the Macronix
98713 behave like a 21140A, and the 98713A and later behave like a 21143.
Nuke all of the Macronix-specific Nway code, as it will be identical to
the 21143 Nway code once it is written.
 1.26 30-Sep-1999  thorpej branches: 1.26.2; 1.26.4; 1.26.8;
Set the LED mode per the EEPROM on Macronix chips.
 1.25 30-Sep-1999  thorpej Changes to get the Lite-On/Macronix 82C115 working:
- 82C115 has a 128-bit multicast hash table, not 512-bit.
- Correct the way the MAC address is read from the SROM, after re-reading
the MX98715A Application Note.

Other semi-related changes:
- Differentiate between MX98715 and MX98715A.
- Improve the Macronix link-up/link-down detection.
 1.24 30-Sep-1999  thorpej Add link-up/link-down detection for the Macronix NWay block.
 1.23 29-Sep-1999  thorpej Add some optional stats gathering, and fix tx stats counting; use the last
descriptor in the packet, not the first.
 1.22 29-Sep-1999  thorpej Grumble, yet another chip-designers-and-manual-writers-disagree. Deal with
this by frobbing the 10TCTL register minimally, toggling only the bit we
care about (and hoping that link-capability advertisement happens correctly).

MX98715 can talk to the network now.
 1.21 29-Sep-1999  thorpej - Get a little closer on the Macronix chips. Still some more work to do.
- Add some basic support for the ADMtek AL981 clone (which, unfortunately,
I can't test until my sample boards arrive).
 1.20 28-Sep-1999  thorpej Oops, Macronix MX98713A doesn't have GPIO direction bits in the SROM
because it doesn't have a GPIO port (CSR12 is the `10baseT status'
register on this chip revision).
 1.19 27-Sep-1999  thorpej Initial support for 21140[A] GPR media.
 1.18 26-Sep-1999  thorpej Make tlp_read_srom() work on big-endian systems.

From a patch supplied by Luoqi Chen <luoqi@chekov.watermarkgroup.com>.
 1.17 25-Sep-1999  thorpej Add support for the DECchip 21140[A]. This currently only works with
boards which use MII for media attachment.

ISV SROM format information lifted from Matt Thomas's `de' driver.

Thanks to Dave Sainty for experimenting w/ his 21140A MII boards, and
for supplying a fix to the MII bit-bang code (PR #8382).
 1.16 21-Sep-1999  thorpej A couple more hacks for the Lite-On PNIC:
- Only use 16 longword bursts.
- Reset the interface for receive filter setups that don't come from
the reset path.

Hi, Jason is getting really tired of broken clone chips, and really wishes
real 21140 boards were still available, because the DEC chips seem to work
Just Dandy.
 1.15 20-Sep-1999  thorpej Remove the has-mii-doesn't-have-mii OPMODE block from tlp_init(), and
let the pre-init hook and media switch routines handle it all.
 1.14 20-Sep-1999  thorpej Remove special-case 2114x-set-OPMODE_MBO; it's done in the pre-init hook
now.
 1.13 20-Sep-1999  thorpej Add support for the DECchip 21041. This also adds some preliminary
support for the ISV SROM format used in the 2114{1,1A,2,3}. Note, like
the 21040, auto-sense is not yet supported for the 21041.

Add a "pre-init" hook, which will be used for the 2114x and PNIC (currently)
which allows chip-specific code to set up and write OPMODE before the
chip is reset. This is necessary in order for the chip's internal
pathways to get initialized properly for MII/SYM/PCS/SIA media attachments.

Thanks to Dave Sainty for the hint from the `de' driver that inspired the
pre-init hook.
 1.12 19-Sep-1999  thorpej Fix a buglet in tlp_reset(): don't touch the Tulip for at least 50
PCI cycles after starting the reset; it won't respond. This will
cause a machine check on some Alpha core logic chipsets (e.g. 21071 APECS).
 1.11 17-Sep-1999  thorpej If the interface is not marked as running, abort tlp_intr() early.
 1.10 14-Sep-1999  thorpej Apparently can't really look at excessive collitions and late collisions
in completed transmit descriptors. These seem to be set even on successful
packet transmissions on my AlphaStation 500's 21040.
 1.9 14-Sep-1999  thorpej First crack at shared ROM/shared interrupts on 21040 multi-port boards,
plus quirk identification for non-multiple-port boards.
 1.8 14-Sep-1999  thorpej Change the semantics of `sc_regshift'; it is now the shift required to
make a CSR index number into a CSR offset. Introduce a couple of macros
to handle CSR name -> offset conversion.
 1.7 14-Sep-1999  thorpej - More PNIC NWAY stuff. Still more work to do, here.
- Fix the SROM checksum routine.
- Add code to parse the old DEC Address ROM SROM format.
- Rearrange the statchg routines a bit, to make them consistent with one
another.
- Add support for the DECchip 21040. XXX No support for media autosense
yet, and no support for any of the multi-port boards yet.
 1.6 09-Sep-1999  thorpej Snapshot of work-in-progress to support the internal NWay block on
the Lite-On PNIC chips. Not finished yet; some other infrastructure
work left to do.
 1.5 02-Sep-1999  thorpej Deal with some more Winbond differences, after a more-thorough-than-before
reading of its manual.
 1.4 01-Sep-1999  thorpej Make Tulip-style filter setup interrupt-driven.
 1.3 01-Sep-1999  thorpej Don't attempt to do transmit threshold tuning on the Lite-On PNCI; just
put it in Store-and-Forward mode right from the get-go. This eliminates
the DMA underrun errors that prevented the receive filter setup from working
and caused smashed packets to go out onto the wire.

My NetGear FA310-TX board now works.

There are still "filter setup failed to complete" messages, however they
don't appear to indicate that the filter setup actually failed, since
unicast and multicast packet reception work fine. I will address this
problem shortly.

Reading the log for the FreeBSD `pn' driver suggests that these chips are,
in fact, pretty crappy, riddled with hardware bugs (for which more workarounds
are coming).
 1.2 01-Sep-1999  thorpej Some of the Tulip clone chips (like the Winbond and ASIX) want the
IC bit set in the *first* descriptor of the outgoing packet. Appease
them.
 1.1 01-Sep-1999  thorpej This is the long-awaited "new Tulip driver", a complete, from-scratch
rewrite of the driver for the DECchip 21x4x Ethernet chips, and a variety
of clones.

Currently, the driver supports the Winbond 89C840F (this works pretty
well), and the Lite-On PNIC (e.g. NetGear PCI boards), however Lite-On
support may be broken [I may simply have a busted test board].

Eventually, support for the Macronix and ASIX chips will filter into
this driver, and then, slowly, support for the genuine DEC chips,
and maybe even the DE-425 EISA model.
 1.26.8.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.26.4.1 15-Nov-1999  fvdl Sync with -current
 1.26.2.7 12-Mar-2001  bouyer Sync with HEAD.
 1.26.2.6 11-Feb-2001  bouyer Sync with HEAD.
 1.26.2.5 18-Jan-2001  bouyer Sync with head (for UBC+NFS fixes, mostly).
 1.26.2.4 05-Jan-2001  bouyer Sync with HEAD
 1.26.2.3 08-Dec-2000  bouyer Sync with HEAD.
 1.26.2.2 22-Nov-2000  bouyer Sync with HEAD.
 1.26.2.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.68.4.7 06-May-2001  he Pull up revision 1.82 (via patch, requested by he):
Add new powerhook argument values, PWR_SOFTSUSPEND, PWR_SOFTSTANDBY and
PWR_SOFTRESUME. Apm calls powerhook with the values in normal interrupt
priority level while others are protected with splhigh().
 1.68.4.6 23-Apr-2001  he Pull up revisions 1.73,1.87 (via patch, requested by hubertf):
Support Accton EN2242 and other AmdTek AN985 compatible cards
with the tlp(4) driver.
 1.68.4.5 26-Jan-2001  jhawk Pull up revision 1.85 (requested by thorpej):
Ignore recieve errors if VLAN_MTU is enabled.
 1.68.4.4 31-Dec-2000  jhawk Pull up revisions 1.74-1.75 (requested by bouyer):
Add support for 802.1Q virtual LANs.
 1.68.4.3 17-Oct-2000  tv Pullup 1.76 and 1.77 [enami]:
Make tulip a random source.
 1.68.4.2 09-Aug-2000  castor Pulling up
ic/tulipvar.h diffs between 1.36 and 1.37
ic/tulipreg.h diffs between 1.21 and 1.20
ic/ tulip.c diffs between 1.70 and 1.71
pci/if_tlp_pci.c diffs between 1.43 and 1.46

requested by tls and thorpej, approved by thorpej

> date: 2000/08/03 03:07:31; author: castor; state: Exp;
lines: +5 -1 Support some differences in the Macronix
98715AEC-C and E chips from the other 98715* series.

The MX98715AEC-[C,E] use a different location in the serial eerom for
LED control, and programming it with the original location's values
caused unpredictable behavior.

Also, start integrating fixes where media changes on an adapter
under load may fail. There's more work to be done here, but I need
to sort out our internal changes a little more carefully.
 1.68.4.1 04-Jul-2000  thorpej Pull up rev. 1.70:
Remove work-around for Lite-On PNIC in tlp_filter_setup() that is
apparently no longer necessary (probably due to other fixes that
have happened in the filter setup path) and is in fact harmful.

Based on a patch from Krister Walfridsson, who claims this makes
his newer NetGear FA-310TX work (although, my older NetGear FA-310TX
still does not, but fails in an entirely different way).
 1.91.2.11 18-Oct-2002  nathanw Catch up to -current.
 1.91.2.10 01-Aug-2002  nathanw Catch up to -current.
 1.91.2.9 20-Jun-2002  nathanw Catch up to -current.
 1.91.2.8 17-Apr-2002  nathanw Catch up to -current.
 1.91.2.7 01-Apr-2002  nathanw Catch up to -current.
(CVS: It's not just a program. It's an adventure!)
 1.91.2.6 28-Feb-2002  nathanw Catch up to -current.
 1.91.2.5 08-Jan-2002  nathanw Catch up to -current.
 1.91.2.4 14-Nov-2001  nathanw Catch up to -current.
 1.91.2.3 21-Sep-2001  nathanw Catch up to -current.
 1.91.2.2 24-Aug-2001  nathanw Catch up with -current.
 1.91.2.1 21-Jun-2001  nathanw Catch up to -current.
 1.94.2.7 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.94.2.6 06-Sep-2002  jdolecek sync kqueue branch with HEAD
 1.94.2.5 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.94.2.4 11-Feb-2002  jdolecek Sync w/ -current.
 1.94.2.3 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.94.2.2 25-Aug-2001  thorpej Merge Aug 24 -current into the kqueue branch.
 1.94.2.1 03-Aug-2001  lukem update to -current
 1.98.2.1 01-Oct-2001  fvdl Catch up with -current.
 1.99.2.1 12-Nov-2001  thorpej Sync the thorpej-mips-cache branch with -current.
 1.113.4.4 28-Jul-2003  he Pull up revisions 1.116,1.119 (requested by thorpej in ticket #845):
Add a missing DELAY() in the initial GPIO setup for the 21140.
For the 21142/21143 internal Nway, only advertise/resolve media for
which we have SROM blocks. Fixes panic on DEC PWS, which only has
built-in 10BaseT media.
 1.113.4.3 07-Dec-2002  he Pull up revision 1.121 (requested by minoura in ticket #943):
Check existence of the default 10baseT media for 21140.
If none exists, fall back to the first.
 1.113.4.2 15-Jul-2002  thorpej pullup-1-6 ticket #505 (chuq).

Original log message:
use the SROM info to set the media in 2114[23] autonegotiation
rather than just fiddling the opmode CSR, since we might
need to change the SIA CSRs as well (eg. for some ZNYX cards).
from PR 17510.
 1.113.4.1 10-Jul-2002  lukem Pull up revision 1.117 (requested by chuck in ticket #454):
only powerdown on a suspend. do not powerdown on a standby (PR#17537).
 1.113.2.2 15-Jul-2002  gehenna catch up with -current.
 1.113.2.1 20-Jun-2002  gehenna catch up with -current.
 1.122.2.12 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.122.2.11 01-Apr-2005  skrll Sync with HEAD.
 1.122.2.10 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.122.2.9 07-Feb-2005  skrll Sunc with HEAD.
 1.122.2.8 06-Feb-2005  skrll Sync with HEAD.
 1.122.2.7 04-Feb-2005  skrll Sync with HEAD.
 1.122.2.6 18-Dec-2004  skrll Sync with HEAD.
 1.122.2.5 02-Nov-2004  skrll Sync with HEAD.
 1.122.2.4 21-Sep-2004  skrll Fix the sync with head I botched.
 1.122.2.3 18-Sep-2004  skrll Sync with HEAD.
 1.122.2.2 12-Aug-2004  skrll Sync with HEAD.
 1.122.2.1 03-Aug-2004  skrll Sync with HEAD
 1.126.4.2 30-Jan-2005  he Pull up revision 1.129 (requested by thorpej in ticket #940):
When adding or deleting multicast addresses, only change
the address filter if the interface is marked RUNNING.
Fixes PR#37678.
 1.126.4.1 11-Jan-2005  jmc Pullup rev 1.130 (requested by sketch in ticket #1084)

Silence the 'receive process failed to idle' message on the Davicom DM9102A.
 1.126.2.1 11-Jan-2005  jmc Pullup rev 1.130 (requested by sketch in ticket #1084)

Silence the 'receive process failed to idle' message on the Davicom DM9102A.
 1.130.4.3 26-Mar-2005  yamt sync with head.
 1.130.4.2 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.130.4.1 12-Feb-2005  yamt sync with head.
 1.130.2.1 29-Apr-2005  kent sync with -current
 1.135.2.1 01-Jul-2005  tron Pull up revision 1.137 (requested by rpaulo in ticket #493):
Add support for ASIX AX88140A/AX88141 chipsets using only
the 10/100 MII with inspiration from FreeBSD dc(4) driver.
Tested on i386 and macppc.
Reviewed by Jason Thorpe and ok'ed by Hubert Feyrer.
 1.137.2.8 24-Mar-2008  yamt sync with head.
 1.137.2.7 17-Mar-2008  yamt sync with head.
 1.137.2.6 21-Jan-2008  yamt sync with head
 1.137.2.5 27-Oct-2007  yamt sync with head.
 1.137.2.4 03-Sep-2007  yamt sync with head.
 1.137.2.3 26-Feb-2007  yamt sync with head.
 1.137.2.2 30-Dec-2006  yamt sync with head.
 1.137.2.1 21-Jun-2006  yamt sync with head.
 1.141.6.2 01-Jun-2006  kardel Sync with head.
 1.141.6.1 22-Apr-2006  simonb Sync with head.
 1.141.4.1 09-Sep-2006  rpaulo sync with head
 1.141.2.1 01-Mar-2006  yamt sync with head.
 1.142.6.1 28-Mar-2006  tron Merge 2006-03-28 NetBSD-current into the "peter-altq" branch.
 1.142.4.1 19-Apr-2006  elad sync with head.
 1.142.2.3 03-Sep-2006  yamt sync with head.
 1.142.2.2 26-Jun-2006  yamt sync with head.
 1.142.2.1 01-Apr-2006  yamt sync with head.
 1.144.2.1 19-Jun-2006  chap Sync with head.
 1.145.4.1 10-Sep-2006  tron Pull up following revision(s) (requested by rumble in ticket #137):
sys/dev/ic/tulip.c: revision 1.146
Phobos boards (my G130 at least) have a non-standard srom layout. Try to
identify it and pull out the enaddr.
 1.146.4.1 22-Oct-2006  yamt sync with head
 1.146.2.1 18-Nov-2006  ad Sync with head.
 1.147.4.2 12-Mar-2007  rmind Sync with HEAD.
 1.147.4.1 27-Feb-2007  yamt - sync with head.
- move sched_changepri back to kern_synch.c as it doesn't know PPQ anymore.
 1.147.2.1 04-Mar-2007  bouyer Pull up following revision(s) (requested by rumble in ticket #478):
sys/dev/pci/if_tl.c: revision 1.78 - 1.80
sys/dev/ic/tulip.c: revision 1.148
Make the ThunderLAN part of the Set Engineering GIO board for sgimips (IP22)
work.
Extract mac addresses on Phobos G100 boards.
 1.149.4.1 11-Jul-2007  mjf Sync with head.
 1.149.2.3 23-Oct-2007  ad Sync with head.
 1.149.2.2 09-Oct-2007  ad Sync with head.
 1.149.2.1 01-Jul-2007  ad Adapt to callout API change.
 1.150.6.3 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.150.6.2 02-Oct-2007  joerg Sync with HEAD.
 1.150.6.1 03-Sep-2007  jmcneill Sync with HEAD.
 1.150.2.1 03-Sep-2007  skrll Sync with HEAD.
 1.152.4.1 06-Oct-2007  yamt sync with head.
 1.152.2.3 23-Mar-2008  matt sync with HEAD
 1.152.2.2 09-Jan-2008  matt sync with HEAD
 1.152.2.1 06-Nov-2007  matt sync with HEAD
 1.153.2.1 25-Oct-2007  bouyer Sync with HEAD.
 1.154.8.3 20-Jan-2008  bouyer Sync with HEAD
 1.154.8.2 19-Jan-2008  bouyer Sync with HEAD
 1.154.8.1 02-Jan-2008  bouyer Sync with HEAD
 1.154.2.1 18-Feb-2008  mjf Sync with HEAD.
 1.157.6.3 17-Jan-2009  mjf Sync with HEAD.
 1.157.6.2 02-Jun-2008  mjf Sync with HEAD.
 1.157.6.1 03-Apr-2008  mjf Sync with HEAD.
 1.157.2.1 24-Mar-2008  keiichi sync with head.
 1.162.4.5 11-Aug-2010  yamt sync with head.
 1.162.4.4 11-Mar-2010  yamt sync with head
 1.162.4.3 16-Sep-2009  yamt sync with head
 1.162.4.2 04-May-2009  yamt sync with head.
 1.162.4.1 16-May-2008  yamt sync with head.
 1.162.2.1 18-May-2008  yamt sync with head.
 1.163.8.2 28-Apr-2009  skrll Sync with HEAD.
 1.163.8.1 19-Jan-2009  skrll Sync with HEAD.
 1.163.6.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.164.4.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.174.4.2 05-Mar-2011  rmind sync with head
 1.174.4.1 30-May-2010  rmind sync with head
 1.174.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.179.6.1 18-Feb-2012  mrg merge to -current.
 1.179.2.3 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.179.2.2 30-Oct-2012  yamt sync with head
 1.179.2.1 17-Apr-2012  yamt sync with head
 1.180.8.1 05-Mar-2015  riz Pull up following revision(s) (requested by nakayama in ticket #1262):
sys/dev/ic/tulip.c: revision 1.185
Stop the interface before detaching to avoid the race between
tlp_detach() and tlp_intr().
While there, add missing callout_destroy()s.
 1.180.6.1 05-Mar-2015  riz Pull up following revision(s) (requested by nakayama in ticket #1262):
sys/dev/ic/tulip.c: revision 1.185
Stop the interface before detaching to avoid the race between
tlp_detach() and tlp_intr().
While there, add missing callout_destroy()s.
 1.180.2.1 05-Mar-2015  riz Pull up following revision(s) (requested by nakayama in ticket #1262):
sys/dev/ic/tulip.c: revision 1.185
Stop the interface before detaching to avoid the race between
tlp_detach() and tlp_intr().
While there, add missing callout_destroy()s.
 1.181.4.1 18-May-2014  rmind sync with head
 1.181.2.2 03-Dec-2017  jdolecek update from HEAD
 1.181.2.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.183.2.1 07-Apr-2014  tls Be a little more clear and consistent about harvesting entropy from devices:

1) deprecate RND_FLAG_NO_ESTIMATE

2) define RND_FLAG_COLLECT_TIME, RND_FLAG_COLLECT_VALUE

3) define RND_FLAG_ESTIMATE_TIME, RND_FLAG_ESTIMATE_VALUE

4) define RND_FLAG_DEFAULT: RND_FLAG_COLLECT_TIME|
RND_FLAG_COLLECT_VALUE|RND_FLAG_ESTIMATE_TIME

5) Make entropy harvesting from environmental sensors a little more generic
and remove it from individual sensor drivers.

6) Remove individual open-coded delta-estimators for values from a few
places in the tree (uvm, environmental drivers).

7) 0 -> RND_FLAG_DEFAULT, actually gather entropy from various drivers
that had stubbed out code, other minor cleanups.
 1.184.4.6 28-Aug-2017  skrll Sync with HEAD
 1.184.4.5 05-Feb-2017  skrll Sync with HEAD
 1.184.4.4 05-Oct-2016  skrll Sync with HEAD
 1.184.4.3 09-Jul-2016  skrll Sync with HEAD
 1.184.4.2 19-Mar-2016  skrll Sync with HEAD
 1.184.4.1 06-Apr-2015  skrll Sync with HEAD
 1.184.2.1 03-Mar-2015  snj Pull up following revision(s) (requested by nakayama in ticket #558):
sys/dev/ic/tulip.c: revision 1.185
Stop the interface before detaching to avoid the race between
tlp_detach() and tlp_intr().
While there, add missing callout_destroy()s.
 1.188.2.1 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.190.8.2 26-Jan-2019  pgoyette Sync with HEAD
 1.190.8.1 28-Jul-2018  pgoyette Sync with HEAD
 1.191.2.3 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.191.2.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.191.2.1 10-Jun-2019  christos Sync with HEAD
 1.197.2.1 31-Jan-2020  martin Pull up following revision(s) (requested by msaitoh in ticket #672):

sys/dev/ic/tulip.c: revision 1.198
sys/dev/pci/if_jme.c: revision 1.45
sys/dev/pci/agp.c: revision 1.86
sys/dev/pci/if_lii.c: revision 1.27
sys/dev/acpi/thinkpad_acpi.c: revision 1.47
sys/dev/scsipi/scsipi_base.c: revision 1.183
sys/dev/ic/aic6915reg.h: revision 1.6

Fix undefined behavior in thinkpad_mask_init(). Found by kUBSan.

Use unsigned when initialize the transmit completion ring to avoid undefined
behavior. Found by kUBSan.

Avoid undefined behavior when setting multicast address. found by kUBSan.

Use unsigned to avoid undefined behavior in agpattach(). Found by kUBSan.

Avoid undefined behavior in jme_mii_write(). Found by kUBSan.

Use unsigned to avoid undefined behavior in lii_setmulti().

Use unsigned to avoid undefined behavior in scsipi_{get,put}_tag().

Found by kUBSan.
 1.200.2.1 29-Feb-2020  ad Sync with head.
 1.212.2.1 02-Aug-2025  perseant Sync with HEAD
 1.44 05-Feb-2024  andvar triple "r" typos, mainly s/interrrupt/interrupt/ in comments and one definition.
 1.43 01-Aug-2022  mlelstv Revert last accidental commits.
 1.42 01-Aug-2022  mlelstv Also fix shift values for SCT constants.
 1.41 19-Aug-2021  andvar add plural for packets and move it to new line to keep 80 symbols per line.
 1.40 17-Aug-2021  andvar fix multiplei repetitive typos in comments, messages and documentation. mainly because copy paste code big amount of files are affected.
 1.39 28-May-2019  msaitoh s/recieve/receive/
 1.38 03-Apr-2019  thorpej After throwing away countless hours of my life on this driver, I am not
going to let an obvious typo go uncorrected.
 1.37 16-Jan-2012  jakllsch branches: 1.37.48;
Add DECchip EB140 reference design GPIO definitions.
From document EC-QD2SA-TE.
 1.36 28-Aug-2009  dyoung branches: 1.36.12; 1.36.16;
Use C99 types, s/u_int32_t/uint32_t/. No functional change intended.
 1.35 27-Aug-2009  dyoung Make descriptors packed w/ 4-byte alignment.
 1.34 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.33 24-Dec-2005  perry branches: 1.33.70; 1.33.72; 1.33.74;
Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.32 11-Dec-2005  christos merge ktrace-lwp.
 1.31 23-Jun-2005  rpaulo branches: 1.31.2;
Add support for ASIX AX88140A/AX88141 chipsets using only
the 10/100 MII with inspiration from FreeBSD dc(4) driver.

Tested on i386 and macppc.

Reviewed by Jason Thorpe and ok'ed by Hubert Feyrer.
 1.30 27-Feb-2005  perry branches: 1.30.2;
nuke trailing whitespace
 1.29 07-Nov-2002  thorpej branches: 1.29.6; 1.29.14; 1.29.16;
Fix signed/unsigned comparison warnings.
 1.28 05-Apr-2002  mycroft With certain 21140 and 21143 SROM formats, OPMODE_FD was never being set when
the interface was wired to full-duplex mode. Duh.
Also, add OPMODE_TTM to OPMODE_MEDIA_BITS, to insure that it is changed when
we switch between 10 and 100.
 1.27 04-Apr-2002  chs add support for Cogent EM100 (aka Adaptec ANA-6910) TX and FX.
 1.26 26-Mar-2002  chs add support for SMC 9332DST.
 1.25 12-Jun-2001  wiz branches: 1.25.2;
receive, not recieve
 1.24 11-Jun-2001  wiz transceiver, not transciever.
 1.23 03-Oct-2000  thorpej branches: 1.23.2;
Add support for the ADMtek AN983 and AN985.
 1.22 25-Aug-2000  jeffs Fix typo in SIATXRX_SPP comment.
 1.21 03-Aug-2000  castor Support some differences in the Macronix 98715AEC-C and E chips from the other
98715* series.

The MX98715AEC-[C,E] use a different location in the serial eerom for
LED control, and programming it with the original location's values
caused unpredictable behavior.

Also, start integrating fixes where media changes on an adapter
under load may fail. There's more work to be done here, but I need
to sort out our internal changes a little more carefully.
 1.20 25-May-2000  thorpej branches: 1.20.4;
Add Davicom DM9102 registers.
 1.19 25-May-2000  thorpej Comment the fact that the X3201-3 requires FS|LS in the setup
packet descriptor.
 1.18 04-Apr-2000  thorpej - if_tlp_cardbus.c: Use the `pmreg' pointer passed by by
cardbus_get_capability() [mirror change already made to if_tlp_pci.c]
- if_tlp_cardbus.c: If we don't find an ISV SROM, try to grab the
Ethernet address from the CIS.
- if_tlp_cardbus.c: set CardBus cards to store-and-forward mode from
the get-go.
- Put the TxThresh tables in tulipvar.h, and use them in the CardBus
and PCI front-ends to go to store-and-forward mode.
- Document the Xircom X3201-3 clone a little more.
 1.17 26-Mar-2000  soren For Cobalt Networks 21143's, always use store-and-forward and toggle
a GPIO line to fully reset the PHY.
 1.16 02-Feb-2000  thorpej Don't dry to diving MIIF_NOISOLATE in the PHY drivers. Instead, pass
flags down from the parent to child vi mii_attach().
 1.15 22-Jan-2000  thorpej Add OPMODE_FD (full-duplex) to the media-related OPMODE bitmask. This
will cause the Tulip to be reset when this bit is toggled. This is
apparently required for some chip revs.

From Matt Thomas.
 1.14 07-Dec-1999  thorpej When checking the SROM checksum, if the standard location fails, try
the new standard location (according to the SROM format update document
for the 21143). From Masanori Kanaoka.
 1.13 19-Nov-1999  thorpej - Use the common MII bit-bang module.
- Add support other than 128-byte SROMs.
- Add support for the 21142/21143 MII.
 1.12 03-Nov-1999  thorpej Define DECchip 21142/21143 register bits, and since the Macronix chips
are nearly perfect 21143 clones, delete a bunch of redundant info in that
section of the file.
 1.11 30-Sep-1999  thorpej branches: 1.11.2; 1.11.4; 1.11.8;
- Improve the comments that describe the various clone chips.
- Add some more Macronix register bits.
- Define the Lite-On/Macronix 82C115 ``PNIC II'' registers.
- Add the ADMtek AL981 PHY register bits.
 1.10 29-Sep-1999  thorpej - Add register definitions for the ADMtek AL981.
- Add a comment about the Macronix MX98713 -- it's almost exactly like
a 21140A, and doens't have the Nway registers that the other Macronix
chips have.
 1.9 28-Sep-1999  enami s/#define /#define<TAB>/.
 1.8 27-Sep-1999  thorpej - Define more "selected connection type" bits for the ISV SROM.
- Define ISV SROM bits for 21140[A] GPR media.
- Define a bitmask which includes media-related bits in the OPMODE
register.
 1.7 24-Sep-1999  thorpej Add Tulip ISV-format SROM media block types.
 1.6 20-Sep-1999  thorpej Add support for the DECchip 21041. This also adds some preliminary
support for the ISV SROM format used in the 2114{1,1A,2,3}. Note, like
the 21040, auto-sense is not yet supported for the 21041.

Add a "pre-init" hook, which will be used for the 2114x and PNIC (currently)
which allows chip-specific code to set up and write OPMODE before the
chip is reset. This is necessary in order for the chip's internal
pathways to get initialized properly for MII/SYM/PCS/SIA media attachments.

Thanks to Dave Sainty for the hint from the `de' driver that inspired the
pre-init hook.
 1.5 14-Sep-1999  thorpej Change the semantics of `sc_regshift'; it is now the shift required to
make a CSR index number into a CSR offset. Introduce a couple of macros
to handle CSR name -> offset conversion.
 1.4 14-Sep-1999  thorpej - More PNIC NWAY stuff. Still more work to do, here.
- Fix the SROM checksum routine.
- Add code to parse the old DEC Address ROM SROM format.
- Rearrange the statchg routines a bit, to make them consistent with one
another.
- Add support for the DECchip 21040. XXX No support for media autosense
yet, and no support for any of the multi-port boards yet.
 1.3 09-Sep-1999  thorpej Snapshot of work-in-progress to support the internal NWay block on
the Lite-On PNIC chips. Not finished yet; some other infrastructure
work left to do.
 1.2 02-Sep-1999  thorpej Deal with some more Winbond differences, after a more-thorough-than-before
reading of its manual.
 1.1 01-Sep-1999  thorpej This is the long-awaited "new Tulip driver", a complete, from-scratch
rewrite of the driver for the DECchip 21x4x Ethernet chips, and a variety
of clones.

Currently, the driver supports the Winbond 89C840F (this works pretty
well), and the Lite-On PNIC (e.g. NetGear PCI boards), however Lite-On
support may be broken [I may simply have a busted test board].

Eventually, support for the Macronix and ASIX chips will filter into
this driver, and then, slowly, support for the genuine DEC chips,
and maybe even the DE-425 EISA model.
 1.11.8.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.11.4.1 15-Nov-1999  fvdl Sync with -current
 1.11.2.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.20.4.1 09-Aug-2000  castor Pulling up
ic/tulipvar.h diffs between 1.36 and 1.37
ic/tulipreg.h diffs between 1.21 and 1.20
ic/ tulip.c diffs between 1.70 and 1.71
pci/if_tlp_pci.c diffs between 1.43 and 1.46

requested by tls and thorpej, approved by thorpej

> date: 2000/08/03 03:07:31; author: castor; state: Exp;
lines: +5 -1 Support some differences in the Macronix
98715AEC-C and E chips from the other 98715* series.

The MX98715AEC-[C,E] use a different location in the serial eerom for
LED control, and programming it with the original location's values
caused unpredictable behavior.

Also, start integrating fixes where media changes on an adapter
under load may fail. There's more work to be done here, but I need
to sort out our internal changes a little more carefully.
 1.23.2.4 11-Nov-2002  nathanw Catch up to -current
 1.23.2.3 17-Apr-2002  nathanw Catch up to -current.
 1.23.2.2 01-Apr-2002  nathanw Catch up to -current.
(CVS: It's not just a program. It's an adventure!)
 1.23.2.1 21-Jun-2001  nathanw Catch up to -current.
 1.25.2.1 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.29.16.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.29.14.1 29-Apr-2005  kent sync with -current
 1.29.6.2 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.29.6.1 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.30.2.1 01-Jul-2005  tron Pull up revision 1.31 (requested by rpaulo in ticket #493):
Add support for ASIX AX88140A/AX88141 chipsets using only
the 10/100 MII with inspiration from FreeBSD dc(4) driver.
Tested on i386 and macppc.
Reviewed by Jason Thorpe and ok'ed by Hubert Feyrer.
 1.31.2.1 21-Jun-2006  yamt sync with head.
 1.33.74.2 16-Sep-2009  yamt sync with head
 1.33.74.1 16-May-2008  yamt sync with head.
 1.33.72.1 18-May-2008  yamt sync with head.
 1.33.70.1 02-Jun-2008  mjf Sync with HEAD.
 1.36.16.1 18-Feb-2012  mrg merge to -current.
 1.36.12.1 17-Apr-2012  yamt sync with head
 1.37.48.1 10-Jun-2019  christos Sync with HEAD
 1.70 13-Sep-2019  msaitoh if_flags is neither int nor short. It's unsigned short.
 1.69 13-Apr-2015  riastradh branches: 1.69.18;
Convert sys/dev to use <sys/rndsource.h>.
 1.68 22-Jul-2012  matt branches: 1.68.2; 1.68.16;
Fix mii_statchg to take a 'struct ifnet *' instead of device_t. This fixes
problem with a common MDIO bus used for multiple interfaces.
Some drivers converted to CFATTACL_DECL_NEW.
 1.67 02-Feb-2012  tls Entropy-pool implementation move and cleanup.

1) Move core entropy-pool code and source/sink/sample management code
to sys/kern from sys/dev.

2) Remove use of NRND as test for presence of entropy-pool code throughout
source tree.

3) Remove use of RND_ENABLED in device drivers as microoptimization to
avoid expensive operations on disabled entropy sources; make the
rnd_add calls do this directly so all callers benefit.

4) Fix bug in recent rnd_add_data()/rnd_add_uint32() changes that might
have lead to slight entropy overestimation for some sources.

5) Add new source types for environmental sensors, power sensors, VM
system events, and skew between clocks, with a sample implementation
for each.

ok releng to go in before the branch due to the difficulty of later
pullup (widespread #ifdef removal and moved files). Tested with release
builds on amd64 and evbarm and live testing on amd64.
 1.66 19-Nov-2011  tls branches: 1.66.2;
First step of random number subsystem rework described in
<20111022023242.BA26F14A158@mail.netbsd.org>. This change includes
the following:

An initial cleanup and minor reorganization of the entropy pool
code in sys/dev/rnd.c and sys/dev/rndpool.c. Several bugs are
fixed. Some effort is made to accumulate entropy more quickly at
boot time.

A generic interface, "rndsink", is added, for stream generators to
request that they be re-keyed with good quality entropy from the pool
as soon as it is available.

The arc4random()/arc4randbytes() implementation in libkern is
adjusted to use the rndsink interface for rekeying, which helps
address the problem of low-quality keys at boot time.

An implementation of the FIPS 140-2 statistical tests for random
number generator quality is provided (libkern/rngtest.c). This
is based on Greg Rose's implementation from Qualcomm.

A new random stream generator, nist_ctr_drbg, is provided. It is
based on an implementation of the NIST SP800-90 CTR_DRBG by
Henric Jungheim. This generator users AES in a modified counter
mode to generate a backtracking-resistant random stream.

An abstraction layer, "cprng", is provided for in-kernel consumers
of randomness. The arc4random/arc4randbytes API is deprecated for
in-kernel use. It is replaced by "cprng_strong". The current
cprng_fast implementation wraps the existing arc4random
implementation. The current cprng_strong implementation wraps the
new CTR_DRBG implementation. Both interfaces are rekeyed from
the entropy pool automatically at intervals justifiable from best
current cryptographic practice.

In some quick tests, cprng_fast() is about the same speed as
the old arc4randbytes(), and cprng_strong() is about 20% faster
than rnd_extract_data(). Performance is expected to improve.

The AES code in src/crypto/rijndael is no longer an optional
kernel component, as it is required by cprng_strong, which is
not an optional kernel component.

The entropy pool output is subjected to the rngtest tests at
startup time; if it fails, the system will reboot. There is
approximately a 3/10000 chance of a false positive from these
tests. Entropy pool _input_ from hardware random numbers is
subjected to the rngtest tests at attach time, as well as the
FIPS continuous-output test, to detect bad or stuck hardware
RNGs; if any are detected, they are detached, but the system
continues to run.

A problem with rndctl(8) is fixed -- datastructures with
pointers in arrays are no longer passed to userspace (this
was not a security problem, but rather a major issue for
compat32). A new kernel will require a new rndctl.

The sysctl kern.arandom() and kern.urandom() nodes are hooked
up to the new generators, but the /dev/*random pseudodevices
are not, yet.

Manual pages for the new kernel interfaces are forthcoming.
 1.65 09-Jul-2011  christos branches: 1.65.2;
- add a routine to get the name of the card.
 1.64 17-Apr-2009  cegger change tlp_attach() to return an error code on failure.
 1.63 17-Apr-2009  cegger device_t/softc split. Tested with tlp at pci
 1.62 17-Apr-2009  cegger struct device * -> device_t
u_intNN_t -> uintNN_t
 1.61 28-Apr-2008  martin branches: 1.61.8; 1.61.14;
Remove clause 3 and 4 from TNF licenses
 1.60 23-Mar-2008  tsutsui branches: 1.60.2; 1.60.4;
On preparing a setup packet, use proper byteswap ops and byte shift ops
rather than #ifdef BYTE_ORDER and subtle pointer casts.
 1.59 09-Mar-2008  jmcneill Convert from shutdownhook/powerhook to PMF.
 1.58 25-Mar-2006  rpaulo branches: 1.58.34; 1.58.54; 1.58.58;
Add support for the Conexant RS7112. From Frank Wille <frank@phoenix.owl.de>.
 1.57 11-Dec-2005  christos branches: 1.57.4; 1.57.6; 1.57.8; 1.57.10; 1.57.12;
merge ktrace-lwp.
 1.56 17-Jul-2005  he Make tlp_idle() not be static, so that the newsmips version of the
driver can access that function again.

Approved by thorpej
 1.55 23-Jun-2005  rpaulo branches: 1.55.2;
Add support for ASIX AX88140A/AX88141 chipsets using only
the 10/100 MII with inspiration from FreeBSD dc(4) driver.

Tested on i386 and macppc.

Reviewed by Jason Thorpe and ok'ed by Hubert Feyrer.
 1.54 27-Feb-2005  perry branches: 1.54.2;
nuke trailing whitespace
 1.53 06-Feb-2005  kim If the interface is up and running, only modify the receive filter
when setting promiscuous or debug mode. This avoids resetting the
chip unnecessarily.

Fixes PR kern/29126.
 1.52 04-Feb-2005  perry de-__P
 1.51 24-Oct-2004  christos branches: 1.51.4; 1.51.6;
Change the sc_name buffer size from 16 to 32, since we already oveflow 16
in if_tlp_pci.c... The name code really needs to be fixed so that it does
not have a buffer overflow again:

1. the cardbus and eisa code don't initialize sc_name; it probably should?
2. tlp_attach() seems to print the name and the ethernet address, but
the pci front end seems to do the same.
3. some of the name determination code in the pci front-end does not guarantee
nul terminated strings.

Really, all this name code is just bloat and another place for bugs to hide.
 1.50 18-Dec-2003  thorpej If we're running on a Connectix Virtual PC, we might get a packet longer
than a max size Ethernet frame without getting a frame-too-long error. VPC
seems to be adding 4 zeros at the end of every frame. Detect this condition
and simply truncate the packet to a max size Ethernet frame.

I now have no problems with networking on NetBSD inside Virtual PC 6.
 1.49 02-Nov-2003  wiz Fix some typos. From Tom Cosgrove via jmc@openbsd.
 1.48 18-Sep-2002  thorpej branches: 1.48.6;
For the 21142/21143 internal Nway, only advertise/resolve media for
which we have SROM blocks.
 1.47 09-Apr-2002  chs branches: 1.47.4;
add support for built-in NWay autonegotiation on 2114[23], Macronix
98713A, 98715, 98715A, 98725, and Lite-On 82C115.
 1.46 26-Mar-2002  chs move some prototypes from tulip.c to tulipvar.h so they can
be used by bus-specific code.
 1.45 01-May-2001  lukem branches: 1.45.2;
delint
 1.44 21-Feb-2001  jdolecek branches: 1.44.2;
make some more constant arrays 'const'
 1.43 08-Jan-2001  thorpej The ADMtek AN985 "ghosts" the single built-in PHY at every MII address.
Work around this by having a custom media init routine that limits the
search to MII address 1.
 1.42 23-Oct-2000  onoe Fixed the value of TULIPF_DBO; which was accidentaly shared with the same
value of TULIPF_BLE. Pointed out by Enami-san.
 1.41 11-Oct-2000  onoe Add flags to indicate that tlp_init() should set some more BUSMODE bits.
TULIPF_BLE /* data is big endian */
TULIPF_DBO /* descriptor is big endian */
These setting is required for Big-endian bus front-end (such as APbus for
newsmips) to work with tulip. Also,
sc_maxburst
member is added to the tulip_softc to limit the maximum burst length.
This member defaults to zero which means no restriction for burst length.
 1.40 09-Oct-2000  enami Move inclusion of rnd.h and sys/rnd.h from tulip.c to tulipvar.h.
 1.39 09-Oct-2000  enami Make tulip a random source.
 1.38 03-Oct-2000  thorpej Add support for the ADMtek AN983 and AN985.
 1.37 03-Aug-2000  castor Support some differences in the Macronix 98715AEC-C and E chips from the other
98715* series.

The MX98715AEC-[C,E] use a different location in the serial eerom for
LED control, and programming it with the original location's values
caused unpredictable behavior.

Also, start integrating fixes where media changes on an adapter
under load may fail. There's more work to be done here, but I need
to sort out our internal changes a little more carefully.
 1.36 26-May-2000  thorpej branches: 1.36.4;
Add support for the Davicom DM9102 and DM9102A 10/100 Ethernet chips.

Partially based on diffs submitted by Matthew Orgass <darkstar@pgh.net>
and IWAMOTO Toshihiro <iwamoto@sat.t.u-tokyo.ac.jp>.
 1.35 25-May-2000  thorpej So, while the DEC chips and other clones want no FS|LS in the
setup descriptor, apparently the Xircom X3201-3 requires it.
 1.34 25-May-2000  thorpej Truncate receive buffers to 4-byte boundary. Slightly modified
from kern/10198, from Izumi Tsutsui <tsutsui@ceres.dti.ne.jp>.
 1.33 04-Apr-2000  thorpej - if_tlp_cardbus.c: Use the `pmreg' pointer passed by by
cardbus_get_capability() [mirror change already made to if_tlp_pci.c]
- if_tlp_cardbus.c: If we don't find an ISV SROM, try to grab the
Ethernet address from the CIS.
- if_tlp_cardbus.c: set CardBus cards to store-and-forward mode from
the get-go.
- Put the TxThresh tables in tulipvar.h, and use them in the CardBus
and PCI front-ends to go to store-and-forward mode.
- Document the Xircom X3201-3 clone a little more.
 1.32 23-Mar-2000  thorpej New callout mechanism with two major improvements over the old
timeout()/untimeout() API:
- Clients supply callout handle storage, thus eliminating problems of
resource allocation.
- Insertion and removal of callouts is constant time, important as
this facility is used quite a lot in the kernel.

The old timeout()/untimeout() API has been removed from the kernel.
 1.31 19-Mar-2000  thorpej Add suspend/resume hooks to ensure that the chip doesn't scramble memory
after an APM suspend and is unsnoozed after an APM resume.
 1.30 15-Mar-2000  thorpej Add power management support to the `tlp' driver. The battery on my
laptop lasts a whole lot longer now.
 1.29 07-Mar-2000  mycroft Determine the size of the SROM by probing the chip using the standard Microwire
protocol. Eliminates the need for srom_quirks and some other trash.
 1.28 01-Feb-2000  thorpej First cut at detach support; doens't fully work yet.
 1.27 28-Jan-2000  thorpej When possible, use ring mode for descriptors. Not only is this slightly
more efficient on genuine DEC chips, but some clones apparently Lose Badly
if you use chain mode. To further complicate things, some clones *only*
do chain mode, so make this whole mess conditional.
 1.26 28-Jan-2000  thorpej Just use a regular Tx descriptor for the setup packet; don't bother with
a separate one.
 1.25 25-Jan-2000  thorpej Some changes for the Xircom X3201-3 in 21143 emulation mode:
- The Xircom doesn't bring itself out of reset; we have to do it.
- The Xircom requires transmit buffers to be aligned to 4 bytes, too.

Partially from Rafal Boni (though the Tx buffer alignment issue is
handled much differently in this version).
 1.24 25-Jan-2000  thorpej Add a chip type for the Xircom X3201-3, and centralize the declaration
of the chip names array.
 1.23 12-Dec-1999  thorpej Oops, forgot to byte-swap the receive descriptors.
 1.22 11-Dec-1999  thorpej - Don't try to run the chip in big-endian mode. Not all chips support
this consistently, and it doesn't always work even when the chip
supports it.
- Make sure things DMA'd to the chip that the chip interprets are in
little-endian mode.
 1.21 19-Nov-1999  thorpej - Use the common MII bit-bang module.
- Add support other than 128-byte SROMs.
- Add support for the 21142/21143 MII.
 1.20 04-Nov-1999  thorpej Use Memory Read Line and Memory Read Multiple on the 21140, 21140A,
21142, and 21143, if the PCI bus says its okay.
 1.19 03-Nov-1999  thorpej More or less completely rewrite the way DECchip media is handled, and
add support for the DECchip 21142/21143 SIA/SYM media. Make the Macronix
98713 behave like a 21140A, and the 98713A and later behave like a 21143.
Nuke all of the Macronix-specific Nway code, as it will be identical to
the 21143 Nway code once it is written.
 1.18 30-Sep-1999  thorpej branches: 1.18.2; 1.18.4; 1.18.8;
Changes to get the Lite-On/Macronix 82C115 working:
- 82C115 has a 128-bit multicast hash table, not 512-bit.
- Correct the way the MAC address is read from the SROM, after re-reading
the MX98715A Application Note.

Other semi-related changes:
- Differentiate between MX98715 and MX98715A.
- Improve the Macronix link-up/link-down detection.
 1.17 29-Sep-1999  thorpej Add some optional stats gathering, and fix tx stats counting; use the last
descriptor in the packet, not the first.
 1.16 29-Sep-1999  thorpej - Get a little closer on the Macronix chips. Still some more work to do.
- Add some basic support for the ADMtek AL981 clone (which, unfortunately,
I can't test until my sample boards arrive).
 1.15 28-Sep-1999  enami s/#define /#define<TAB>/.
 1.14 27-Sep-1999  thorpej Add a media name pointer to the tulip_2114x_media structure, and define
a table for converting SROM media block type codes to ifmedia subtypes.
 1.13 26-Sep-1999  thorpej Make tlp_read_srom() work on big-endian systems.

From a patch supplied by Luoqi Chen <luoqi@chekov.watermarkgroup.com>.
 1.12 25-Sep-1999  thorpej Add support for the DECchip 21140[A]. This currently only works with
boards which use MII for media attachment.

ISV SROM format information lifted from Matt Thomas's `de' driver.

Thanks to Dave Sainty for experimenting w/ his 21140A MII boards, and
for supplying a fix to the MII bit-bang code (PR #8382).
 1.11 20-Sep-1999  thorpej Add support for the DECchip 21041. This also adds some preliminary
support for the ISV SROM format used in the 2114{1,1A,2,3}. Note, like
the 21040, auto-sense is not yet supported for the 21041.

Add a "pre-init" hook, which will be used for the 2114x and PNIC (currently)
which allows chip-specific code to set up and write OPMODE before the
chip is reset. This is necessary in order for the chip's internal
pathways to get initialized properly for MII/SYM/PCS/SIA media attachments.

Thanks to Dave Sainty for the hint from the `de' driver that inspired the
pre-init hook.
 1.10 14-Sep-1999  thorpej Move the PCI device number to the base Tulip softc; it will be needed to
decode the SROM on 21041 and 2114x multi-port boards.
 1.9 14-Sep-1999  thorpej First crack at shared ROM/shared interrupts on 21040 multi-port boards,
plus quirk identification for non-multiple-port boards.
 1.8 14-Sep-1999  thorpej Change the semantics of `sc_regshift'; it is now the shift required to
make a CSR index number into a CSR offset. Introduce a couple of macros
to handle CSR name -> offset conversion.
 1.7 14-Sep-1999  thorpej - More PNIC NWAY stuff. Still more work to do, here.
- Fix the SROM checksum routine.
- Add code to parse the old DEC Address ROM SROM format.
- Rearrange the statchg routines a bit, to make them consistent with one
another.
- Add support for the DECchip 21040. XXX No support for media autosense
yet, and no support for any of the multi-port boards yet.
 1.6 09-Sep-1999  thorpej Snapshot of work-in-progress to support the internal NWay block on
the Lite-On PNIC chips. Not finished yet; some other infrastructure
work left to do.
 1.5 08-Sep-1999  thorpej Add chip types for several more Tulip clones (ASIX, ADMtex, PNIC II, Davicom),
and match the Compex RL100-ATX; it uses the Winbond 89C840F (RL100-TX is
a Macronix 98713).
 1.4 02-Sep-1999  thorpej Deal with some more Winbond differences, after a more-thorough-than-before
reading of its manual.
 1.3 01-Sep-1999  thorpej Make Tulip-style filter setup interrupt-driven.
 1.2 01-Sep-1999  thorpej Some of the Tulip clone chips (like the Winbond and ASIX) want the
IC bit set in the *first* descriptor of the outgoing packet. Appease
them.
 1.1 01-Sep-1999  thorpej This is the long-awaited "new Tulip driver", a complete, from-scratch
rewrite of the driver for the DECchip 21x4x Ethernet chips, and a variety
of clones.

Currently, the driver supports the Winbond 89C840F (this works pretty
well), and the Lite-On PNIC (e.g. NetGear PCI boards), however Lite-On
support may be broken [I may simply have a busted test board].

Eventually, support for the Macronix and ASIX chips will filter into
this driver, and then, slowly, support for the genuine DEC chips,
and maybe even the DE-425 EISA model.
 1.18.8.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.18.4.1 15-Nov-1999  fvdl Sync with -current
 1.18.2.3 12-Mar-2001  bouyer Sync with HEAD.
 1.18.2.2 18-Jan-2001  bouyer Sync with head (for UBC+NFS fixes, mostly).
 1.18.2.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.36.4.3 23-Apr-2001  he Pull up revisions 1.38,1.43 (requested by hubertf):
Support Accton EN2242 and other AmdTek AN985 compatible cards
with the tlp(4) driver.
 1.36.4.2 17-Oct-2000  tv Pullup 1.39 and 1.40 [enami]:
Make tulip a random source.
 1.36.4.1 09-Aug-2000  castor Pulling up
ic/tulipvar.h diffs between 1.36 and 1.37
ic/tulipreg.h diffs between 1.21 and 1.20
ic/ tulip.c diffs between 1.70 and 1.71
pci/if_tlp_pci.c diffs between 1.43 and 1.46

requested by tls and thorpej, approved by thorpej

> date: 2000/08/03 03:07:31; author: castor; state: Exp;
lines: +5 -1 Support some differences in the Macronix
98715AEC-C and E chips from the other 98715* series.

The MX98715AEC-[C,E] use a different location in the serial eerom for
LED control, and programming it with the original location's values
caused unpredictable behavior.

Also, start integrating fixes where media changes on an adapter
under load may fail. There's more work to be done here, but I need
to sort out our internal changes a little more carefully.
 1.44.2.4 18-Oct-2002  nathanw Catch up to -current.
 1.44.2.3 17-Apr-2002  nathanw Catch up to -current.
 1.44.2.2 01-Apr-2002  nathanw Catch up to -current.
(CVS: It's not just a program. It's an adventure!)
 1.44.2.1 21-Jun-2001  nathanw Catch up to -current.
 1.45.2.2 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.45.2.1 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.47.4.1 28-Jul-2003  he Pull up revision 1.48 (requested by thorpej in ticket #845):
For the 21142/21143 internal Nway, only advertise/resolve media for
which we have SROM blocks. Fixes panic on DEC PWS, which only has
built-in 10BaseT media.
 1.48.6.8 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.48.6.7 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.48.6.6 06-Feb-2005  skrll Sync with HEAD.
 1.48.6.5 04-Feb-2005  skrll Sync with HEAD.
 1.48.6.4 02-Nov-2004  skrll Sync with HEAD.
 1.48.6.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.48.6.2 18-Sep-2004  skrll Sync with HEAD.
 1.48.6.1 03-Aug-2004  skrll Sync with HEAD
 1.51.6.2 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.51.6.1 12-Feb-2005  yamt sync with head.
 1.51.4.1 29-Apr-2005  kent sync with -current
 1.54.2.1 01-Jul-2005  tron Pull up revision 1.55 (requested by rpaulo in ticket #493):
Add support for ASIX AX88140A/AX88141 chipsets using only
the 10/100 MII with inspiration from FreeBSD dc(4) driver.
Tested on i386 and macppc.
Reviewed by Jason Thorpe and ok'ed by Hubert Feyrer.
 1.55.2.3 24-Mar-2008  yamt sync with head.
 1.55.2.2 17-Mar-2008  yamt sync with head.
 1.55.2.1 21-Jun-2006  yamt sync with head.
 1.57.12.1 28-Mar-2006  tron Merge 2006-03-28 NetBSD-current into the "peter-altq" branch.
 1.57.10.1 19-Apr-2006  elad sync with head.
 1.57.8.1 01-Apr-2006  yamt sync with head.
 1.57.6.1 22-Apr-2006  simonb Sync with head.
 1.57.4.1 09-Sep-2006  rpaulo sync with head
 1.58.58.2 02-Jun-2008  mjf Sync with HEAD.
 1.58.58.1 03-Apr-2008  mjf Sync with HEAD.
 1.58.54.1 24-Mar-2008  keiichi sync with head.
 1.58.34.1 23-Mar-2008  matt sync with HEAD
 1.60.4.2 04-May-2009  yamt sync with head.
 1.60.4.1 16-May-2008  yamt sync with head.
 1.60.2.1 18-May-2008  yamt sync with head.
 1.61.14.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.61.8.1 28-Apr-2009  skrll Sync with HEAD.
 1.65.2.2 30-Oct-2012  yamt sync with head
 1.65.2.1 17-Apr-2012  yamt sync with head
 1.66.2.1 18-Feb-2012  mrg merge to -current.
 1.68.16.1 06-Jun-2015  skrll Sync with HEAD
 1.68.2.1 03-Dec-2017  jdolecek update from HEAD
 1.69.18.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.2 08-May-2019  isaki Merge isaki-audio2 branch, the overhaul of audio subsystem.
- Interrupt-oriented system rather than thread-oriented.
- Improve stability, quality and performance.
- Split playback and record cleanly. Improve halfduplex support.
- Many bugs are fixed including deadlocks, resource leaks, abuses, etc.
- Simplify audio filter mechanism. The encoding/channels/frequency
conversions are completely handled in the upper layer. So the hard-
ware driver only converts its hardware encoding (if necessary).
- audio_hw_if changes:
- Obsoletes query_encoding and add query_format instead.
- Obsoletes set_params and add set_format instead.
- Remove drain, setfd, mappage.
- The call sequences are changed.
- ioctl AUDIO_GETFD/SETFD, AUDIO_GETCHAN/SETCHAN are obsoleted.
- ioctl AUDIO_{QUERY,GET,SET}FORMAT are introduced.
- cleanup config attributes: au*conv and mulaw.
- All hardware drivers should follow it (I've done as much as possible).

Some file paths are changed:
- dev/audio.c -> dev/audio/audio.c (rewritten)
- dev/audiovar.h -> dev/audio/audiovar.h
- dev/audio_dai.h -> dev/audio/audio_dai.h
- dev/audio_if.h -> dev/audio/audio_if.h
- dev/audiobell.c -> dev/audio/audiobell.c
- dev/audiobellvar.h -> dev/audio/audiobellvar.h
- dev/mulaw.[ch] -> dev/audio/mulaw.[ch] + dev/audio/alaw.c
 1.1 28-Jan-2012  nisimura branches: 1.1.4; 1.1.6; 1.1.52; 1.1.56;

Add UDA1341TS audio CODEC support. Code is written by
Paul Fleischer.
 1.1.56.3 04-May-2019  isaki Move dev/audio_if.h -> dev/audio/audio_if.h
 1.1.56.2 25-Apr-2019  isaki Adapt to audio2.
- The sample rate seems to be determined by peripherals so
move uda1341_formats[] structure from ic/uda1341.c to audio_mini2440.c.
- XXX Resetting the device in open() (and close()) might be harmful
but I don't know details about what does this reset do.
 1.1.56.1 21-Apr-2019  isaki Use C99 style struct initializer to audio_format.
 1.1.52.1 10-Jun-2019  christos Sync with HEAD
 1.1.6.2 17-Apr-2012  yamt sync with head
 1.1.6.1 28-Jan-2012  yamt file uda1341.c was added on branch yamt-pagecache on 2012-04-17 00:07:37 +0000
 1.1.4.2 18-Feb-2012  mrg merge to -current.
 1.1.4.1 28-Jan-2012  mrg file uda1341.c was added on branch jmcneill-usbmp on 2012-02-18 07:34:25 +0000
 1.1 28-Jan-2012  nisimura branches: 1.1.4; 1.1.6;

Add UDA1341TS audio CODEC support. Code is written by
Paul Fleischer.
 1.1.6.2 17-Apr-2012  yamt sync with head
 1.1.6.1 28-Jan-2012  yamt file uda1341reg.h was added on branch yamt-pagecache on 2012-04-17 00:07:37 +0000
 1.1.4.2 18-Feb-2012  mrg merge to -current.
 1.1.4.1 28-Jan-2012  mrg file uda1341reg.h was added on branch jmcneill-usbmp on 2012-02-18 07:34:25 +0000
 1.2 08-May-2019  isaki Merge isaki-audio2 branch, the overhaul of audio subsystem.
- Interrupt-oriented system rather than thread-oriented.
- Improve stability, quality and performance.
- Split playback and record cleanly. Improve halfduplex support.
- Many bugs are fixed including deadlocks, resource leaks, abuses, etc.
- Simplify audio filter mechanism. The encoding/channels/frequency
conversions are completely handled in the upper layer. So the hard-
ware driver only converts its hardware encoding (if necessary).
- audio_hw_if changes:
- Obsoletes query_encoding and add query_format instead.
- Obsoletes set_params and add set_format instead.
- Remove drain, setfd, mappage.
- The call sequences are changed.
- ioctl AUDIO_GETFD/SETFD, AUDIO_GETCHAN/SETCHAN are obsoleted.
- ioctl AUDIO_{QUERY,GET,SET}FORMAT are introduced.
- cleanup config attributes: au*conv and mulaw.
- All hardware drivers should follow it (I've done as much as possible).

Some file paths are changed:
- dev/audio.c -> dev/audio/audio.c (rewritten)
- dev/audiovar.h -> dev/audio/audiovar.h
- dev/audio_dai.h -> dev/audio/audio_dai.h
- dev/audio_if.h -> dev/audio/audio_if.h
- dev/audiobell.c -> dev/audio/audiobell.c
- dev/audiobellvar.h -> dev/audio/audiobellvar.h
- dev/mulaw.[ch] -> dev/audio/mulaw.[ch] + dev/audio/alaw.c
 1.1 28-Jan-2012  nisimura branches: 1.1.4; 1.1.6; 1.1.52; 1.1.56;

Add UDA1341TS audio CODEC support. Code is written by
Paul Fleischer.
 1.1.56.1 25-Apr-2019  isaki Adapt to audio2.
- The sample rate seems to be determined by peripherals so
move uda1341_formats[] structure from ic/uda1341.c to audio_mini2440.c.
- XXX Resetting the device in open() (and close()) might be harmful
but I don't know details about what does this reset do.
 1.1.52.1 10-Jun-2019  christos Sync with HEAD
 1.1.6.2 17-Apr-2012  yamt sync with head
 1.1.6.1 28-Jan-2012  yamt file uda1341var.h was added on branch yamt-pagecache on 2012-04-17 00:07:37 +0000
 1.1.4.2 18-Feb-2012  mrg merge to -current.
 1.1.4.1 28-Jan-2012  mrg file uda1341var.h was added on branch jmcneill-usbmp on 2012-02-18 07:34:25 +0000
 1.15 25-Sep-2022  thorpej Remove unnecessary include of <sys/malloc.h>.
 1.14 24-Jun-2020  jdolecek rearrange to avoid allocating softc on stack in ug_isa_match()
 1.13 03-Jun-2018  maxv Constify ug2_mb[], so that it lands in .rodata.
 1.12 20-Jun-2011  pgoyette branches: 1.12.52;
Initialize sensor states before registering
 1.11 26-Mar-2008  xtraeme branches: 1.11.36;
Split device_t/softc for ug(4) and other related cosmetic changes.
 1.10 17-Nov-2007  kefren branches: 1.10.14;
initialize via sysmon_envsys_create()
make sensors valid
 1.9 16-Nov-2007  xtraeme Extend the envsys2 API (one more time, sorry) as defined in:

http://mail-index.netbsd.org/tech-kern/2007/11/09/0001.html

sysmon_envsys_create() and sysmon_envsys_destroy() were added to
create/destroy sysmon_envsys objects (and its TAILQ/LIST for sensors/events).

sysmon_envsys_sensor_attach() and sysmon_envsys_sensor_detach() were
added to attach/detach sensors to a specified sysmon_envsys device.

The events framework is now per device and configurable via the
ENVSYS_SETDICTIONARY ioctl or /etc/envsys.conf and envstat(8).

Update all users and documentation to reflect these changes.
 1.8 19-Oct-2007  ad branches: 1.8.2;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.7 03-Jul-2007  xtraeme branches: 1.7.2; 1.7.8; 1.7.10; 1.7.12; 1.7.16;
ug_gtredata: add another break in the default case. Just for consistency
with other code.
 1.6 03-Jul-2007  xtraeme ug2_gtredata: add missing break in default case.
 1.5 01-Jul-2007  xtraeme ug*_gtredata: use the edata pointer rather than using the edata array
index.
 1.4 01-Jul-2007  xtraeme There's no need to use another envsys_data_t pointer that points to
the sensor specified in the softc, use edata passed in by the gtredata
function. Also remove a line of code that is not needed anymore with
envsys2.
 1.3 01-Jul-2007  xtraeme Imported envsys 2, a brief description of the new features:
(Part 2: drivers)

* Support for detachable sensors.
* Cleaned up the API for simplicity and efficiency.
* Ability to send capacity/critical/warning events to powerd(8).
* Adapted all the code to the new locking order.
* Compatibility with the old envsys API: the ENVSYS_GTREINFO
and ENVSYS_GTREDATA ioctl(2)s are supported.
* Added support for a 'dictionary based communication channel' between
sysmon_power(9) and powerd(8), that means there is no 32 bytes event
size restriction anymore.
* Binary compatibility with old envstat(8) and powerd(8) via COMPAT_40.
* All drivers with the n^2 gtredata bug were fixed, PR kern/36226.

Tested by:

blymn: smsc(4).
bouyer: ipmi(4), mfi(4).
kefren: ug(4).
njoly: viaenv(4), adt7463.c.
riz: owtemp(4).
xtraeme: acpiacad(4), acpibat(4), acpitz(4), aiboost(4), it(4), lm(4).
 1.2 08-May-2007  xtraeme branches: 1.2.2; 1.2.4; 1.2.6;
Missing __KERNEL_RCSID().
 1.1 08-May-2007  xtraeme Split the ug(4) driver in three components:

* dev/ic/ug.c (main code shared by the attachments)
* dev/isa/ug_isa.c (isa attachment)
* dev/acpi/ug_acpi.c (acpi attachment)

That means that ug(4) can now be attached via ACPI.

Thanks to Mihai Chelaru for the good work.
 1.2.6.4 23-Oct-2007  ad Sync with head.
 1.2.6.3 15-Jul-2007  ad Sync with head.
 1.2.6.2 09-Jun-2007  ad Sync with head.
 1.2.6.1 08-May-2007  ad file ug.c was added on branch vmlocking on 2007-06-09 21:37:18 +0000
 1.2.4.2 17-May-2007  yamt sync with head.
 1.2.4.1 08-May-2007  yamt file ug.c was added on branch yamt-idlelwp on 2007-05-17 13:41:26 +0000
 1.2.2.3 13-May-2007  pavel Fix new files from ticket #633.
 1.2.2.2 13-May-2007  pavel Pull up patch (requested by xtraeme in ticket #633):
sys/arch/amd64/conf/GENERIC: patch
sys/arch/i386/conf/ALL: patch
sys/arch/i386/conf/GENERIC: patch
sys/conf/files: patch
sys/dev/acpi/files.acpi: patch
sys/dev/acpi/ug_acpi.c: patch
sys/dev/ic/ug.c: patch
sys/dev/ic/ugreg.h: patch
sys/dev/ic/ugvar.h: patch
sys/dev/isa/files.isa: patch
sys/dev/isa/ug_isa.c: patch
share/man/man4/ug.4: patch
doc/CHANGES: patch
sys/dev/isa/ug.c: delete
sys/dev/isa/ugvar.h: delete

Add an acpi attachement for the ug hardware monitor driver.
 1.2.2.1 08-May-2007  pavel file ug.c was added on branch netbsd-4 on 2007-05-13 06:52:53 +0000
 1.7.16.2 18-Nov-2007  bouyer Sync with HEAD
 1.7.16.1 25-Oct-2007  bouyer Sync with HEAD.
 1.7.12.4 07-Dec-2007  yamt sync with head
 1.7.12.3 27-Oct-2007  yamt sync with head.
 1.7.12.2 03-Sep-2007  yamt sync with head.
 1.7.12.1 03-Jul-2007  yamt file ug.c was added on branch yamt-lazymbuf on 2007-09-03 14:35:18 +0000
 1.7.10.2 09-Jan-2008  matt sync with HEAD
 1.7.10.1 06-Nov-2007  matt sync with HEAD
 1.7.8.2 21-Nov-2007  joerg Sync with HEAD.
 1.7.8.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.7.2.2 11-Jul-2007  mjf Sync with head.
 1.7.2.1 03-Jul-2007  mjf file ug.c was added on branch mjf-ufs-trans on 2007-07-11 20:06:15 +0000
 1.8.2.1 19-Nov-2007  mjf Sync with HEAD.
 1.10.14.1 03-Apr-2008  mjf Sync with HEAD.
 1.11.36.1 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.12.52.1 25-Jun-2018  pgoyette Sync with HEAD
 1.2 07-Sep-2024  andvar spelling and grammar fixes, mainly in comments.
 1.1 08-May-2007  xtraeme branches: 1.1.2; 1.1.4; 1.1.6; 1.1.8; 1.1.18; 1.1.170;
Split the ug(4) driver in three components:

* dev/ic/ug.c (main code shared by the attachments)
* dev/isa/ug_isa.c (isa attachment)
* dev/acpi/ug_acpi.c (acpi attachment)

That means that ug(4) can now be attached via ACPI.

Thanks to Mihai Chelaru for the good work.
 1.1.170.1 02-Aug-2025  perseant Sync with HEAD
 1.1.18.2 03-Sep-2007  yamt sync with head.
 1.1.18.1 08-May-2007  yamt file ugreg.h was added on branch yamt-lazymbuf on 2007-09-03 14:35:19 +0000
 1.1.8.2 11-Jul-2007  mjf Sync with head.
 1.1.8.1 08-May-2007  mjf file ugreg.h was added on branch mjf-ufs-trans on 2007-07-11 20:06:16 +0000
 1.1.6.2 09-Jun-2007  ad Sync with head.
 1.1.6.1 08-May-2007  ad file ugreg.h was added on branch vmlocking on 2007-06-09 21:37:18 +0000
 1.1.4.2 17-May-2007  yamt sync with head.
 1.1.4.1 08-May-2007  yamt file ugreg.h was added on branch yamt-idlelwp on 2007-05-17 13:41:26 +0000
 1.1.2.3 13-May-2007  pavel Fix new files from ticket #633.
 1.1.2.2 13-May-2007  pavel Pull up patch (requested by xtraeme in ticket #633):
sys/arch/amd64/conf/GENERIC: patch
sys/arch/i386/conf/ALL: patch
sys/arch/i386/conf/GENERIC: patch
sys/conf/files: patch
sys/dev/acpi/files.acpi: patch
sys/dev/acpi/ug_acpi.c: patch
sys/dev/ic/ug.c: patch
sys/dev/ic/ugreg.h: patch
sys/dev/ic/ugvar.h: patch
sys/dev/isa/files.isa: patch
sys/dev/isa/ug_isa.c: patch
share/man/man4/ug.4: patch
doc/CHANGES: patch
sys/dev/isa/ug.c: delete
sys/dev/isa/ugvar.h: delete

Add an acpi attachement for the ug hardware monitor driver.
 1.1.2.1 08-May-2007  pavel file ugreg.h was added on branch netbsd-4 on 2007-05-13 06:52:53 +0000
 1.6 24-Jun-2020  jdolecek rearrange to avoid allocating softc on stack in ug_isa_match()
 1.5 03-Jun-2018  maxv Constify ug2_mb[], so that it lands in .rodata.
 1.4 26-Mar-2008  xtraeme branches: 1.4.90;
Split device_t/softc for ug(4) and other related cosmetic changes.
 1.3 16-Nov-2007  xtraeme branches: 1.3.14;
Extend the envsys2 API (one more time, sorry) as defined in:

http://mail-index.netbsd.org/tech-kern/2007/11/09/0001.html

sysmon_envsys_create() and sysmon_envsys_destroy() were added to
create/destroy sysmon_envsys objects (and its TAILQ/LIST for sensors/events).

sysmon_envsys_sensor_attach() and sysmon_envsys_sensor_detach() were
added to attach/detach sensors to a specified sysmon_envsys device.

The events framework is now per device and configurable via the
ENVSYS_SETDICTIONARY ioctl or /etc/envsys.conf and envstat(8).

Update all users and documentation to reflect these changes.
 1.2 01-Jul-2007  xtraeme branches: 1.2.2; 1.2.8; 1.2.10; 1.2.12; 1.2.16; 1.2.18;
Imported envsys 2, a brief description of the new features:
(Part 2: drivers)

* Support for detachable sensors.
* Cleaned up the API for simplicity and efficiency.
* Ability to send capacity/critical/warning events to powerd(8).
* Adapted all the code to the new locking order.
* Compatibility with the old envsys API: the ENVSYS_GTREINFO
and ENVSYS_GTREDATA ioctl(2)s are supported.
* Added support for a 'dictionary based communication channel' between
sysmon_power(9) and powerd(8), that means there is no 32 bytes event
size restriction anymore.
* Binary compatibility with old envstat(8) and powerd(8) via COMPAT_40.
* All drivers with the n^2 gtredata bug were fixed, PR kern/36226.

Tested by:

blymn: smsc(4).
bouyer: ipmi(4), mfi(4).
kefren: ug(4).
njoly: viaenv(4), adt7463.c.
riz: owtemp(4).
xtraeme: acpiacad(4), acpibat(4), acpitz(4), aiboost(4), it(4), lm(4).
 1.1 08-May-2007  xtraeme branches: 1.1.2; 1.1.4; 1.1.6;
Split the ug(4) driver in three components:

* dev/ic/ug.c (main code shared by the attachments)
* dev/isa/ug_isa.c (isa attachment)
* dev/acpi/ug_acpi.c (acpi attachment)

That means that ug(4) can now be attached via ACPI.

Thanks to Mihai Chelaru for the good work.
 1.1.6.3 15-Jul-2007  ad Sync with head.
 1.1.6.2 09-Jun-2007  ad Sync with head.
 1.1.6.1 08-May-2007  ad file ugvar.h was added on branch vmlocking on 2007-06-09 21:37:19 +0000
 1.1.4.2 17-May-2007  yamt sync with head.
 1.1.4.1 08-May-2007  yamt file ugvar.h was added on branch yamt-idlelwp on 2007-05-17 13:41:26 +0000
 1.1.2.3 13-May-2007  pavel Fix new files from ticket #633.
 1.1.2.2 13-May-2007  pavel Pull up patch (requested by xtraeme in ticket #633):
sys/arch/amd64/conf/GENERIC: patch
sys/arch/i386/conf/ALL: patch
sys/arch/i386/conf/GENERIC: patch
sys/conf/files: patch
sys/dev/acpi/files.acpi: patch
sys/dev/acpi/ug_acpi.c: patch
sys/dev/ic/ug.c: patch
sys/dev/ic/ugreg.h: patch
sys/dev/ic/ugvar.h: patch
sys/dev/isa/files.isa: patch
sys/dev/isa/ug_isa.c: patch
share/man/man4/ug.4: patch
doc/CHANGES: patch
sys/dev/isa/ug.c: delete
sys/dev/isa/ugvar.h: delete

Add an acpi attachement for the ug hardware monitor driver.
 1.1.2.1 08-May-2007  pavel file ugvar.h was added on branch netbsd-4 on 2007-05-13 06:52:54 +0000
 1.2.18.1 19-Nov-2007  mjf Sync with HEAD.
 1.2.16.1 18-Nov-2007  bouyer Sync with HEAD
 1.2.12.3 07-Dec-2007  yamt sync with head
 1.2.12.2 03-Sep-2007  yamt sync with head.
 1.2.12.1 01-Jul-2007  yamt file ugvar.h was added on branch yamt-lazymbuf on 2007-09-03 14:35:19 +0000
 1.2.10.1 09-Jan-2008  matt sync with HEAD
 1.2.8.1 21-Nov-2007  joerg Sync with HEAD.
 1.2.2.2 11-Jul-2007  mjf Sync with head.
 1.2.2.1 01-Jul-2007  mjf file ugvar.h was added on branch mjf-ufs-trans on 2007-07-11 20:06:16 +0000
 1.3.14.1 03-Apr-2008  mjf Sync with HEAD.
 1.4.90.1 25-Jun-2018  pgoyette Sync with HEAD
 1.50 25-Sep-2022  thorpej Remove unnecessary include of <sys/malloc.h>.
 1.49 07-Aug-2021  thorpej Merge thorpej-cfargs2.
 1.48 24-Apr-2021  thorpej branches: 1.48.8;
Merge thorpej-cfargs branch:

Simplify and make extensible the config_search() / config_found() /
config_attach() interfaces: rather than having different variants for
which arguments you want pass along, just have a single call that
takes a variadic list of tag-value arguments.

Adjust all call sites:
- Simplify wherever possible; don't pass along arguments that aren't
actually needed.
- Don't be explicit about what interface attribute is attaching if
the device only has one. (More simplification.)
- Add a config_probe() function to be used in indirect configuiration
situations, making is visibly easier to see when indirect config is
in play, and allowing for future change in semantics. (As of now,
this is just a wrapper around config_match(), but that is an
implementation detail.)

Remove unnecessary or redundant interface attributes where they're not
needed.

There are currently 5 "cfargs" defined:
- CFARG_SUBMATCH (submatch function for direct config)
- CFARG_SEARCH (search function for indirect config)
- CFARG_IATTR (interface attribte)
- CFARG_LOCATORS (locators array)
- CFARG_DEVHANDLE (devhandle_t - wraps OFW, ACPI, etc. handles)

...and a sentinel value CFARG_EOL.

Add some extra sanity checking to ensure that interface attributes
aren't ambiguous.

Use CFARG_DEVHANDLE in MI FDT, OFW, and ACPI code, and macppc and shark
ports to associate those device handles with device_t instance. This
will trickle trough to more places over time (need back-end for pre-OFW
Sun OBP; any others?).
 1.47 11-Jul-2016  msaitoh branches: 1.47.34;
KNF. No functional change.
 1.46 27-Oct-2012  chs branches: 1.46.14;
split device_t/softc for all remaining drivers.
replace "struct device *" with "device_t".
use device_xname(), device_unit(), etc.
 1.45 13-Nov-2010  uebayasi branches: 1.45.8; 1.45.18;
Don't pull in the whole uvm(9) API to access only PAGE_SIZE and
some other constants. These are provided by sys/param.h now.
 1.44 23-Nov-2009  rmind branches: 1.44.4;
Remove some unecessary includes sys/user.h header.
 1.43 14-Mar-2009  dsl Change about 4500 of the K&R function definitions to ANSI ones.
There are still about 1600 left, but they have ',' or /* ... */
in the actual variable definitions - which my awk script doesn't handle.
There are also many that need () -> (void).
(The script does handle misordered arguments.)
 1.42 28-Apr-2008  martin branches: 1.42.8; 1.42.14;
Remove clause 3 and 4 from TNF licenses
 1.41 08-Apr-2008  cegger branches: 1.41.2; 1.41.4;
use aprint_*_dev and device_xname
 1.40 19-Oct-2007  ad branches: 1.40.16;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.39 04-Mar-2007  christos branches: 1.39.2; 1.39.14; 1.39.16; 1.39.20;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.38 16-Nov-2006  christos branches: 1.38.4;
__unused removal on arguments; approved by core.
 1.37 12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.36 11-Dec-2005  christos branches: 1.36.20; 1.36.22;
merge ktrace-lwp.
 1.35 21-Feb-2005  thorpej branches: 1.35.4;
Part 1 of a cleanup pass over the SCSI subsystem. The aim is to name
everything "scsi_*", since we really are talking about the SCSI command
set, ATAPI transport not withstanding. Improve the names of many structures,
and prepend "SCSI_" onto all SCSI command opcodes. Place items described
by the SCSI Primary Commands document into scsi_spc.h.
 1.34 04-Feb-2005  perry de-__P
 1.33 07-Dec-2004  thorpej branches: 1.33.2; 1.33.4;
Don't use "struct scsi_generic" in a hardware-defined structure. Instead,
use an array of 12 bytes. Check the incoming CDB to see that it will fit,
and print and error and fail the command if it won't.
 1.32 30-Oct-2003  simonb branches: 1.32.6;
Remove some assigned-to but otherwise unused variables.
 1.31 15-Nov-2001  lukem branches: 1.31.16;
don't need <sys/types.h> when including <sys/param.h>
 1.30 13-Nov-2001  lukem add/cleanup RCSID
 1.29 19-Jul-2001  thorpej Use BUS_DMA_READ and BUS_DMA_WRITE in some obvious places.
 1.28 07-Jul-2001  thorpej branches: 1.28.2;
bzero -> memset
 1.27 07-Jul-2001  thorpej bcopy -> memcpy
 1.26 25-Apr-2001  bouyer Pull up the thorpej_scsipi branch to main branch.
This is a completely rewritten scsipi_xfer execution engine, and the
associated changes to HBA drivers. Overview of changes & features:
- All xfers are queued in the mid-layer, rather than doing so in an
ad-hoc fashion in individual adapter drivers.
- Adapter/channel resource management in the mid-layer, avoids even trying
to start running an xfer if the adapter/channel doesn't have the resources.
- Better communication between the mid-layer and the adapters.
- Asynchronous event notification mechanism from adapter to mid-layer and
peripherals.
- Better peripheral queue management: freeze/thaw, sorted requeueing during
recovery, etc.
- Clean separation of peripherals, adapters, and adapter channels (no more
scsipi_link).
- Kernel thread for each scsipi_channel makes error recovery much easier
(no more dealing with interrupt context when recovering from an error).
- Mid-layer support for tagged queueing: commands can have the tag type
set explicitly, tag IDs are allocated in the mid-layer (thus eliminating
the need to use buggy tag ID allocation schemes in many adapter drivers).
- support for QUEUE FULL and CHECK CONDITION status in mid-layer; the command
will be requeued, or a REQUEST SENSE will be sent as appropriate.

Just before the merge syssrc has been tagged with thorpej_scsipi_beforemerge
 1.25 07-Mar-2001  thorpej Add BUS_DMA_STREAMING to data transfer maps.
 1.24 14-Nov-2000  thorpej branches: 1.24.2;
NBPG -> PAGE_SIZE
 1.23 12-Feb-2000  thorpej If we got an xfer from our backlog queue, don't allow sleeping; we're in
interrupt context.

XXX This is fixed properly in the thorpej_scsipi branch, but that won't
be ready for 1.5, I don't think.
 1.22 30-Sep-1999  thorpej branches: 1.22.2;
Update for SCSPI changes.
 1.21 09-Dec-1998  thorpej Update for changed scsipi_xfer struct.
 1.20 05-Dec-1998  mjacob Update HBAs to incorporate the new max_lun property.
 1.19 19-Nov-1998  thorpej Adapt to the new scsipi_adapter interface.
 1.18 10-Oct-1998  thorpej Garbage-collect the open_target_lu and close_target_lu entry points from
struct scsipi_adapter; they were not used.

Add a scsipi_ioctl entry point to struct scsipi_adapter. This will be
used to issue ioctl commands to the host adapters.

Inspired by PR #6090, from Matt Jacob.
 1.17 17-Aug-1998  mycroft Assign my copyrights to TNF.
 1.16 17-Feb-1998  thorpej - Perform all necessary bus_dmamap_sync() operations.
- Greatly simplify allocation and DMA mapping of the mailbox and ccbs.
- Be more robust against resource shortage errors, and report errors better.
 1.15 04-Feb-1998  thorpej Add offset and length parameters to bus_dmamap_sync(), used for specifiying
partial syncs of a DMA mapping.
 1.14 04-Feb-1998  thorpej Add dm_mapsize to bus_dmamap_t and rename BUS_DMAMEM_NOSYNC to
BUS_DMA_COHERENT.
 1.13 28-Jan-1998  thorpej Use offsetof() from libkern.h
 1.12 12-Jan-1998  thorpej Adjust for config changes.
 1.11 04-Nov-1997  thorpej Implement a simple queueing mechanism that makes these drivers much
more robust in resource shortage situations, basically identical to
code I added to the "ahc" driver some time ago.

Thanks to Brad Spencer for the testing help.
 1.10 28-Oct-1997  thorpej When creating mscps, be a little more informative about why we couldn't
should creation/initialization of a mscp fail. Also, don't panic in
these situations. Instead, simply return an error condition and allow
the caller to deal with it. It may be the case that we were able to
create one mscp what we can grab, and continue to hobble along.

Also, fix the mscp freelist fencepost error, similar to aha.c and bha.c
 1.9 27-Aug-1997  bouyer branches: 1.9.4;
Merge scsipi branch in the mainline. This add support for ATAPI devices
(currently only CD-ROM drives on i386). The sys/dev/scsipi system provides 2
busses to which devices can attach (scsibus and atapibus). This needed to
change some include files and structure names in the low level scsi drivers.
 1.8 06-Jun-1997  thorpej branches: 1.8.2; 1.8.4;
Pull thorpej-bus-dma branch into mainline.
 1.7 29-Mar-1997  mycroft branches: 1.7.2;
Use a temporary data structure for holding probe information, rather than a
full softc.
 1.6 10-Dec-1996  thorpej Fill in sc_link.max_target
 1.5 15-Nov-1996  jonathan Fix front-ends of split uha driver to compile when DDB is not configured:
Propagate Debugger() macro from uha.c to uha_{eisa,isa}.c.
update file names accordingly.
 1.4 12-Nov-1996  mycroft Fix uha_{reset,init}_mscp() prototypes.
 1.3 13-Oct-1996  christos backout kprintf changes
 1.2 10-Oct-1996  christos - printf -> kprintf, sprintf -> ksprintf
- include <systm.h>
 1.1 31-Aug-1996  mycroft Split the UltraStor driver apart.
 1.7.2.2 17-May-1997  thorpej Update for bus_dmamem_alloc() changes.
 1.7.2.1 13-May-1997  thorpej Convert to use bus dma.
 1.8.4.1 27-Aug-1997  thorpej Update marc-pcmcia branch from trunk.
 1.8.2.1 01-Jul-1997  bouyer Updates for new scsipi subsystem. Actally known to work on i386 and sparc.
 1.9.4.2 04-Nov-1997  thorpej Pull up from trunk: add a queueing mechanism to make this much more
robust in resource shortage conditions.
 1.9.4.1 28-Oct-1997  thorpej Pull up from trunk: fix fencepost errors in mscp allocation and be
more verbose/robust when mscp allocation/initialization fails.
 1.22.2.8 12-Mar-2001  bouyer Sync with HEAD.
 1.22.2.7 22-Nov-2000  bouyer Sync with HEAD.
 1.22.2.6 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.22.2.5 01-Nov-1999  thorpej Fixup the SC_DEBUG() stuff for the new world order.
 1.22.2.4 26-Oct-1999  thorpej Update for:

Deal a little more gracefully with the fact that xfer mode parameters
are for the I_T Nexus, and make all xfer mode updates `async events'.
 1.22.2.3 20-Oct-1999  thorpej Eliminate sleeping from adapter routines.
 1.22.2.2 19-Oct-1999  thorpej Don't sleep waiting for a CCB; if we get to the CCB allocation phase, we're
guaranteed to have one.
 1.22.2.1 19-Oct-1999  thorpej Adapt to scsipi API changes.
 1.24.2.5 08-Jan-2002  nathanw Catch up to -current.
 1.24.2.4 14-Nov-2001  nathanw Catch up to -current.
 1.24.2.3 24-Aug-2001  nathanw Catch up with -current.
 1.24.2.2 21-Jun-2001  nathanw Catch up to -current.
 1.24.2.1 09-Apr-2001  nathanw Catch up with -current.
 1.28.2.2 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.28.2.1 03-Aug-2001  lukem update to -current
 1.31.16.6 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.31.16.5 04-Feb-2005  skrll Sync with HEAD.
 1.31.16.4 18-Dec-2004  skrll Sync with HEAD.
 1.31.16.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.31.16.2 18-Sep-2004  skrll Sync with HEAD.
 1.31.16.1 03-Aug-2004  skrll Sync with HEAD
 1.32.6.1 02-Apr-2005  he Pull up revision 1.33 (requested by thorpej in ticket #1022):
Don't use "struct scsi_generic" in a hardware-defined structure.
Instead, use an array of 12 bytes. Check the incoming CDB to see
that it will fit, and print and error and fail the command if it
won't.
 1.33.4.2 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.33.4.1 12-Feb-2005  yamt sync with head.
 1.33.2.1 29-Apr-2005  kent sync with -current
 1.35.4.3 27-Oct-2007  yamt sync with head.
 1.35.4.2 03-Sep-2007  yamt sync with head.
 1.35.4.1 30-Dec-2006  yamt sync with head.
 1.36.22.2 10-Dec-2006  yamt sync with head.
 1.36.22.1 22-Oct-2006  yamt sync with head
 1.36.20.1 18-Nov-2006  ad Sync with head.
 1.38.4.1 12-Mar-2007  rmind Sync with HEAD.
 1.39.20.1 25-Oct-2007  bouyer Sync with HEAD.
 1.39.16.1 06-Nov-2007  matt sync with HEAD
 1.39.14.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.39.2.1 23-Oct-2007  ad Sync with head.
 1.40.16.1 02-Jun-2008  mjf Sync with HEAD.
 1.41.4.3 11-Mar-2010  yamt sync with head
 1.41.4.2 04-May-2009  yamt sync with head.
 1.41.4.1 16-May-2008  yamt sync with head.
 1.41.2.1 18-May-2008  yamt sync with head.
 1.42.14.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.42.8.1 28-Apr-2009  skrll Sync with HEAD.
 1.44.4.1 05-Mar-2011  rmind sync with head
 1.45.18.2 03-Dec-2017  jdolecek update from HEAD
 1.45.18.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.45.8.1 30-Oct-2012  yamt sync with head
 1.46.14.1 05-Oct-2016  skrll Sync with HEAD
 1.47.34.1 21-Mar-2021  thorpej Give config_found() the same variadic arguments treatment as
config_search(). This commit only adds the CFARG_EOL sentinel
to the existing config_found() calls. Conversion of config_found_sm_loc()
and config_found_ia() call sites will be in subsequent commits.
 1.48.8.1 04-Aug-2021  thorpej Adapt to CFARGS().
 1.1 20-Nov-2000  bouyer branches: 1.1.2;
file uha.c.orig was initially added on branch thorpej_scsipi.
 1.1.2.2 20-Nov-2000  bouyer Ops, these shouldn't be there !
 1.1.2.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.1 20-Nov-2000  bouyer branches: 1.1.2;
file uha.c.rej was initially added on branch thorpej_scsipi.
 1.1.2.2 20-Nov-2000  bouyer Remove files that should not have been added
 1.1.2.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.13 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.12 11-Dec-2005  christos branches: 1.12.70; 1.12.72; 1.12.74;
merge ktrace-lwp.
 1.11 21-Feb-2005  thorpej Part 1 of a cleanup pass over the SCSI subsystem. The aim is to name
everything "scsi_*", since we really are talking about the SCSI command
set, ATAPI transport not withstanding. Improve the names of many structures,
and prepend "SCSI_" onto all SCSI command opcodes. Place items described
by the SCSI Primary Commands document into scsi_spc.h.
 1.10 07-Dec-2004  thorpej branches: 1.10.2; 1.10.4;
Don't use "struct scsi_generic" in a hardware-defined structure. Instead,
use an array of 12 bytes. Check the incoming CDB to see that it will fit,
and print and error and fail the command if it won't.
 1.9 03-May-2003  wiz branches: 1.9.2; 1.9.8;
DMA, not dma nor Dma.
 1.8 08-Jun-2000  cgd in allegedly-MI code, if we're gonna use '#pragma pack(N)', #pragma pack()
should be used to reset the packing. (#pragma pack(4) was used here
before. "wrong!")
 1.7 17-Aug-1998  mycroft branches: 1.7.12; 1.7.20;
Assign my copyrights to TNF.
 1.6 17-Feb-1998  thorpej - Perform all necessary bus_dmamap_sync() operations.
- Greatly simplify allocation and DMA mapping of the mailbox and ccbs.
- Be more robust against resource shortage errors, and report errors better.
 1.5 09-Sep-1997  mycroft Make `hashkey' unsigned.
 1.4 27-Aug-1997  bouyer Merge scsipi branch in the mainline. This add support for ATAPI devices
(currently only CD-ROM drives on i386). The sys/dev/scsipi system provides 2
busses to which devices can attach (scsibus and atapibus). This needed to
change some include files and structure names in the low level scsi drivers.
 1.3 06-Jun-1997  thorpej branches: 1.3.2; 1.3.4;
Pull thorpej-bus-dma branch into mainline.
 1.2 01-Sep-1996  mycroft branches: 1.2.8;
Minor changes.
 1.1 31-Aug-1996  mycroft Split the UltraStor driver apart.
 1.2.8.1 13-May-1997  thorpej Convert to use bus dma.
 1.3.4.2 16-Sep-1997  thorpej Update marc-pcmcia branch from trunk.
 1.3.4.1 27-Aug-1997  thorpej Update marc-pcmcia branch from trunk.
 1.3.2.1 01-Jul-1997  bouyer Updates for new scsipi subsystem. Actally known to work on i386 and sparc.
 1.7.20.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.7.12.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.9.8.1 02-Apr-2005  he Pull up revision 1.10 (requested by thorpej in ticket #1022):
Don't use "struct scsi_generic" in a hardware-defined structure.
Instead, use an array of 12 bytes. Check the incoming CDB to see
that it will fit, and print and error and fail the command if it
won't.
 1.9.2.2 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.9.2.1 18-Dec-2004  skrll Sync with HEAD.
 1.10.4.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.10.2.1 29-Apr-2005  kent sync with -current
 1.12.74.1 16-May-2008  yamt sync with head.
 1.12.72.1 18-May-2008  yamt sync with head.
 1.12.70.1 02-Jun-2008  mjf Sync with HEAD.
 1.16 27-Oct-2012  chs split device_t/softc for all remaining drivers.
replace "struct device *" with "device_t".
use device_xname(), device_unit(), etc.
 1.15 28-Apr-2008  martin branches: 1.15.34; 1.15.44;
Remove clause 3 and 4 from TNF licenses
 1.14 11-Dec-2005  christos branches: 1.14.70; 1.14.72; 1.14.74;
merge ktrace-lwp.
 1.13 04-Feb-2005  perry de-__P
 1.12 25-Apr-2001  bouyer branches: 1.12.22; 1.12.30; 1.12.32;
Pull up the thorpej_scsipi branch to main branch.
This is a completely rewritten scsipi_xfer execution engine, and the
associated changes to HBA drivers. Overview of changes & features:
- All xfers are queued in the mid-layer, rather than doing so in an
ad-hoc fashion in individual adapter drivers.
- Adapter/channel resource management in the mid-layer, avoids even trying
to start running an xfer if the adapter/channel doesn't have the resources.
- Better communication between the mid-layer and the adapters.
- Asynchronous event notification mechanism from adapter to mid-layer and
peripherals.
- Better peripheral queue management: freeze/thaw, sorted requeueing during
recovery, etc.
- Clean separation of peripherals, adapters, and adapter channels (no more
scsipi_link).
- Kernel thread for each scsipi_channel makes error recovery much easier
(no more dealing with interrupt context when recovering from an error).
- Mid-layer support for tagged queueing: commands can have the tag type
set explicitly, tag IDs are allocated in the mid-layer (thus eliminating
the need to use buggy tag ID allocation schemes in many adapter drivers).
- support for QUEUE FULL and CHECK CONDITION status in mid-layer; the command
will be requeued, or a REQUEST SENSE will be sent as appropriate.

Just before the merge syssrc has been tagged with thorpej_scsipi_beforemerge
 1.11 09-Dec-1998  thorpej branches: 1.11.10; 1.11.22;
Update for changed scsipi_xfer struct.
 1.10 19-Nov-1998  thorpej Adapt to the new scsipi_adapter interface.
 1.9 15-Aug-1998  mycroft Assign my copyrights to TNF.
 1.8 17-Feb-1998  thorpej - Perform all necessary bus_dmamap_sync() operations.
- Greatly simplify allocation and DMA mapping of the mailbox and ccbs.
- Be more robust against resource shortage errors, and report errors better.
 1.7 04-Nov-1997  thorpej Implement a simple queueing mechanism that makes these drivers much
more robust in resource shortage situations, basically identical to
code I added to the "ahc" driver some time ago.

Thanks to Brad Spencer for the testing help.
 1.6 27-Aug-1997  bouyer branches: 1.6.4;
Merge scsipi branch in the mainline. This add support for ATAPI devices
(currently only CD-ROM drives on i386). The sys/dev/scsipi system provides 2
busses to which devices can attach (scsibus and atapibus). This needed to
change some include files and structure names in the low level scsi drivers.
 1.5 06-Jun-1997  thorpej branches: 1.5.2; 1.5.4;
Pull thorpej-bus-dma branch into mainline.
 1.4 29-Mar-1997  mycroft branches: 1.4.2;
Use a temporary data structure for holding probe information, rather than a
full softc.
 1.3 21-Oct-1996  thorpej New bus.h implementation/interface:
- No more distinction between i/o-mapped and memory-mapped
devices. It's all "bus space" now, and space tags
differentiate the space with finer grain than the
bus chipset tag.
- Add memory barrier methods.
- Implement space alloc/free methods.
- Implement region read/write methods (like memcpy to/from
bus space).
This interface provides a better abstraction for dealing with
machine-independent chipset drivers.
 1.2 01-Sep-1996  mycroft Minor changes.
 1.1 31-Aug-1996  mycroft Split the UltraStor driver apart.
 1.4.2.1 13-May-1997  thorpej Convert to use bus dma.
 1.5.4.1 27-Aug-1997  thorpej Update marc-pcmcia branch from trunk.
 1.5.2.1 01-Jul-1997  bouyer Updates for new scsipi subsystem. Actally known to work on i386 and sparc.
 1.6.4.1 04-Nov-1997  thorpej Pull up from trunk: add a queueing mechanism to make this much more
robust in resource shortage conditions.
 1.11.22.1 21-Jun-2001  nathanw Catch up to -current.
 1.11.10.1 19-Oct-1999  thorpej Adapt to scsipi API changes.
 1.12.32.1 12-Feb-2005  yamt sync with head.
 1.12.30.1 29-Apr-2005  kent sync with -current
 1.12.22.1 04-Feb-2005  skrll Sync with HEAD.
 1.14.74.1 16-May-2008  yamt sync with head.
 1.14.72.1 18-May-2008  yamt sync with head.
 1.14.70.1 02-Jun-2008  mjf Sync with HEAD.
 1.15.44.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.15.34.1 30-Oct-2012  yamt sync with head
 1.1 20-Nov-2000  bouyer branches: 1.1.2;
file uhavar.h.orig was initially added on branch thorpej_scsipi.
 1.1.2.2 20-Nov-2000  bouyer Ops, these shouldn't be there !
 1.1.2.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.1 25-Feb-2000  drochner branches: 1.1.6;
add (minimal, PIO only) support for the popular "Tundra Universe"
PCI-VME interface chip and a frontend for the "Bit3 Mod. 2706"
PCI-VME adapter
 1.1.6.2 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.1.6.1 25-Feb-2000  bouyer file universereg.h was added on branch thorpej_scsipi on 2000-11-20 11:41:03 +0000
 1.16 11-Nov-2019  msaitoh Remove acorn26's upc(4) devices.
 1.15 27-Oct-2012  chs branches: 1.15.38;
split device_t/softc for all remaining drivers.
replace "struct device *" with "device_t".
use device_xname(), device_unit(), etc.
 1.14 08-Apr-2008  cegger branches: 1.14.38; 1.14.48;
use aprint_*_dev and device_xname
 1.13 19-Oct-2007  ad branches: 1.13.16;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.12 11-Dec-2005  christos branches: 1.12.30; 1.12.44; 1.12.46; 1.12.50;
merge ktrace-lwp.
 1.11 25-Aug-2005  drochner kill a number of autoconf submatch functions which follow the
standard scheme:
if (<configured> != <wildcard> && <configured> != <real>)
then fail
else
ask device match function

This is handled by config_stdsubmatch() now.
 1.10 25-Aug-2005  drochner replace the "locdesc_t" structure carrying the number of locators
explicitely by a plain integer array
the length in now known to all relevant parties, so this avoids
duplication of information, and we can allocate that thing in
drivers without hacks
 1.9 27-Feb-2005  perry branches: 1.9.4;
nuke trailing whitespace
 1.8 13-Sep-2004  drochner branches: 1.8.4; 1.8.6;
a round of autoconf cleanup:
-convert submatch() style functions (passed to config_search() or
config_found_sm()) to the locator passing variants
-pass interface attributes in some cases
-make submatch() functions look uniformly as far as possible
-avoid macros which just hide cfdata members, and reduce dependencies
on "locators.h"
 1.7 29-Nov-2003  bjh21 Include wdcreg.h for WDC_NREGS (used by wdcvar.h).
 1.6 02-Mar-2003  bjh21 branches: 1.6.2;
Add support for the 82C710, the original Universal Peripheral Controller.
It turns out (now that I've found the data sheet) to have a substantially
different configuration mechanism from its successors.
 1.5 01-Jan-2003  thorpej Use aprint_normal() in cfprint routines.
 1.4 27-Sep-2002  thorpej Introduce a new routine, config_match(), which invokes the
cfattach->ca_match function in behalf of the caller. Use it
rather than invoking cfattach->ca_match directly.
 1.3 27-Sep-2002  thorpej Rather than referencing the cfdriver directly in the cfdata entries,
instead use a string naming the driver. The cfdriver is then looked
up in a list which is built at run-time.
 1.2 13-Nov-2001  lukem add/cleanup RCSID
 1.1 16-Aug-2000  bjh21 branches: 1.1.2; 1.1.4; 1.1.6;
Basic driver for CHIPS 82C710 Universal Peripheral Controller and friends,
as used on later arm26 system (A5000, A4, A3010, A3020, A4000).

What we have got:
...
upc0 at iobus0 base 0x010000: config state bb 87 1c 00 00
fdc at upc0 offset 0x3f4 not configured
wdc0 at upc0 offset 0x1f0
lpt0 at upc0 offset 0x278
com0 at upc0 offset 0x3f8: ns8250 or ns16450, no fifo
...

What we haven't got:
- FDC support (found, but not configured).
- Clearing lpt interrupts on arm26 systems (needs help from IOEB).
- A upc(4) manual page.
- More than minimal testing (my A3020s don't have root devices).
- A proper probe routine (arm26 can't use one anyway).
 1.1.6.2 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.1.6.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.1.4.3 03-Jan-2003  thorpej Sync with HEAD.
 1.1.4.2 18-Oct-2002  nathanw Catch up to -current.
 1.1.4.1 14-Nov-2001  nathanw Catch up to -current.
 1.1.2.2 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.1.2.1 16-Aug-2000  bouyer file upc.c was added on branch thorpej_scsipi on 2000-11-20 11:41:04 +0000
 1.6.2.5 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.6.2.4 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.6.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.6.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.6.2.1 03-Aug-2004  skrll Sync with HEAD
 1.8.6.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.8.4.1 29-Apr-2005  kent sync with -current
 1.9.4.2 27-Oct-2007  yamt sync with head.
 1.9.4.1 21-Jun-2006  yamt sync with head.
 1.12.50.1 25-Oct-2007  bouyer Sync with HEAD.
 1.12.46.1 06-Nov-2007  matt sync with HEAD
 1.12.44.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.12.30.1 23-Oct-2007  ad Sync with head.
 1.13.16.1 02-Jun-2008  mjf Sync with HEAD.
 1.14.48.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.14.38.1 30-Oct-2012  yamt sync with head
 1.15.38.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.3 02-Mar-2003  bjh21 Add support for the 82C710, the original Universal Peripheral Controller.
It turns out (now that I've found the data sheet) to have a substantially
different configuration mechanism from its successors.
 1.2 16-Aug-2000  bjh21 branches: 1.2.2;
Basic driver for CHIPS 82C710 Universal Peripheral Controller and friends,
as used on later arm26 system (A5000, A4, A3010, A3020, A4000).

What we have got:
...
upc0 at iobus0 base 0x010000: config state bb 87 1c 00 00
fdc at upc0 offset 0x3f4 not configured
wdc0 at upc0 offset 0x1f0
lpt0 at upc0 offset 0x278
com0 at upc0 offset 0x3f8: ns8250 or ns16450, no fifo
...

What we haven't got:
- FDC support (found, but not configured).
- Clearing lpt interrupts on arm26 systems (needs help from IOEB).
- A upc(4) manual page.
- More than minimal testing (my A3020s don't have root devices).
- A proper probe routine (arm26 can't use one anyway).
 1.1 08-Aug-2000  bjh21 Register definitions for the C&T 82C710, 82C711 and 82C721, as used in
the Acorn A5000, A4, A4000, A3010 and A3020.
 1.2.2.2 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.2.2.1 16-Aug-2000  bouyer file upcreg.h was added on branch thorpej_scsipi on 2000-11-20 11:41:04 +0000
 1.6 27-Oct-2012  chs split device_t/softc for all remaining drivers.
replace "struct device *" with "device_t".
use device_xname(), device_unit(), etc.
 1.5 19-Oct-2007  ad branches: 1.5.54; 1.5.64;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.4 11-Dec-2005  christos branches: 1.4.30; 1.4.44; 1.4.46; 1.4.50;
merge ktrace-lwp.
 1.3 27-Feb-2005  perry branches: 1.3.4;
nuke trailing whitespace
 1.2 02-Mar-2003  bjh21 branches: 1.2.2; 1.2.10; 1.2.12;
Add support for the 82C710, the original Universal Peripheral Controller.
It turns out (now that I've found the data sheet) to have a substantially
different configuration mechanism from its successors.
 1.1 16-Aug-2000  bjh21 branches: 1.1.2;
Basic driver for CHIPS 82C710 Universal Peripheral Controller and friends,
as used on later arm26 system (A5000, A4, A3010, A3020, A4000).

What we have got:
...
upc0 at iobus0 base 0x010000: config state bb 87 1c 00 00
fdc at upc0 offset 0x3f4 not configured
wdc0 at upc0 offset 0x1f0
lpt0 at upc0 offset 0x278
com0 at upc0 offset 0x3f8: ns8250 or ns16450, no fifo
...

What we haven't got:
- FDC support (found, but not configured).
- Clearing lpt interrupts on arm26 systems (needs help from IOEB).
- A upc(4) manual page.
- More than minimal testing (my A3020s don't have root devices).
- A proper probe routine (arm26 can't use one anyway).
 1.1.2.2 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.1.2.1 16-Aug-2000  bouyer file upcvar.h was added on branch thorpej_scsipi on 2000-11-20 11:41:04 +0000
 1.2.12.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.2.10.1 29-Apr-2005  kent sync with -current
 1.2.2.1 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.3.4.1 27-Oct-2007  yamt sync with head.
 1.4.50.1 25-Oct-2007  bouyer Sync with HEAD.
 1.4.46.1 06-Nov-2007  matt sync with HEAD
 1.4.44.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.4.30.1 23-Oct-2007  ad Sync with head.
 1.5.64.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.5.54.1 30-Oct-2012  yamt sync with head
 1.120 07-Aug-2021  thorpej Merge thorpej-cfargs2.
 1.119 24-Apr-2021  thorpej branches: 1.119.8;
Merge thorpej-cfargs branch:

Simplify and make extensible the config_search() / config_found() /
config_attach() interfaces: rather than having different variants for
which arguments you want pass along, just have a single call that
takes a variadic list of tag-value arguments.

Adjust all call sites:
- Simplify wherever possible; don't pass along arguments that aren't
actually needed.
- Don't be explicit about what interface attribute is attaching if
the device only has one. (More simplification.)
- Add a config_probe() function to be used in indirect configuiration
situations, making is visibly easier to see when indirect config is
in play, and allowing for future change in semantics. (As of now,
this is just a wrapper around config_match(), but that is an
implementation detail.)

Remove unnecessary or redundant interface attributes where they're not
needed.

There are currently 5 "cfargs" defined:
- CFARG_SUBMATCH (submatch function for direct config)
- CFARG_SEARCH (search function for indirect config)
- CFARG_IATTR (interface attribte)
- CFARG_LOCATORS (locators array)
- CFARG_DEVHANDLE (devhandle_t - wraps OFW, ACPI, etc. handles)

...and a sentinel value CFARG_EOL.

Add some extra sanity checking to ensure that interface attributes
aren't ambiguous.

Use CFARG_DEVHANDLE in MI FDT, OFW, and ACPI code, and macppc and shark
ports to associate those device handles with device_t instance. This
will trickle trough to more places over time (need back-end for pre-OFW
Sun OBP; any others?).
 1.118 24-Apr-2020  ad branches: 1.118.4;
BUS_SPACE_MAP_PREFETCHABLE yields a write combining region on x86 and that's
not what I intended.. BUS_SPACE_MAP_CACHEABLE is enough.
 1.117 01-Dec-2019  ad branches: 1.117.6;
Map the video RAM cacheable/prefetchable, it's very slow and this helps a bit.
 1.116 10-Nov-2019  chs in many device attach paths, allocate memory with M_WAITOK instead of M_NOWAIT
and remove code to handle failures that can no longer happen.
 1.115 01-Mar-2015  mlelstv branches: 1.115.18;
Also unmap video memory when detaching console
 1.114 14-Jan-2015  chs remove BIOS-mapping code that was #if-0'd in the previous commit.
 1.113 21-Aug-2014  macallan branches: 1.113.2;
#if 0 code to map the VGA BIOS
I've been unable to find any code that actually uses the mapping and we may
want to read the ROM from drm2.
If no users show up within a week or so I'll delete it.
 1.112 12-Jul-2014  mlelstv branches: 1.112.2;
detach wscons when detaching console
 1.111 04-Nov-2013  christos branches: 1.111.2;
mark variables __diagused
 1.110 21-Jan-2013  mlelstv branches: 1.110.2;
Make internal functions static
 1.109 09-Aug-2012  uwe branches: 1.109.2;
Reset flip/flop using dedicated vga_reset_state() macro we already have.
Explicit vga_raw_read() used here before was incorrect since it reads
from *wrong* io handle!

Fixes weird problem under VirtualBox where first switch to a different
VT caused text mode color 0 (normally black) to become something else.
 1.108 11-Jan-2012  macallan branches: 1.108.2;
wsfont_matches() and wsfont_find() take an extra parameter now
 1.107 08-Jun-2011  drochner branches: 1.107.2; 1.107.6;
add support for the interesting parts of ISO-2 and KOI8-R fonts
to the vga(4) driver
 1.106 09-Dec-2010  christos branches: 1.106.6;
PR/41415: IdOp: Implement save and restore palette for vga.
 1.105 19-Oct-2010  jmcneill If PCDISPLAY_SOFTCURSOR is defined, disable the hardware cursor on resume.
 1.104 19-Apr-2010  dyoung Add default implementations for bus_space_is_equal(9),
bus_space_tag_create(9), and bus_space_tag_destroy(9). Use
bus_space_is_equal(9) throughout the kernel to compare
bus_space_tag_t's. Tested on i386 and on sparc64.
 1.103 22-Mar-2010  dyoung pckbc.c, vga.c: It doesn't appear to be helpful to compare two
bus_space_tag_t's in pckbc_is_console() and vga_is_console(), and MI
code should never do such a thing, so don't do it.

tcic2.c: #if 0 some diagnostic code that compares two bus_space_tag_t's.
 1.102 25-Feb-2010  drochner branches: 1.102.2;
retire our private definitions for the scan1/3/5/7/9 DEC graphics
symbols, use the unicode definitions instead (which apparently didn't
exist when I wrote that)
 1.101 19-Feb-2009  jmcneill branches: 1.101.2;
Remove vesafb-specific hacks.
 1.100 16-Mar-2008  dyoung branches: 1.100.4; 1.100.12; 1.100.18;
Always deviter_release().
 1.99 14-Mar-2008  dyoung In vga_is_console(), use deviter_first/_next() and device_t accessors.
Ok cube@.
 1.98 14-Mar-2008  cube Split device_t and softc for all attachments of vga(4).
 1.97 09-Dec-2007  jmcneill branches: 1.97.6; 1.97.10;
Merge jmcneill-pm branch.
 1.96 19-Oct-2007  ad branches: 1.96.4; 1.96.6;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.95 28-Jul-2007  mjf branches: 1.95.4; 1.95.6; 1.95.10; 1.95.12;
Implement bounds checking in some places in display driver code to avoid
the possibility of a local user panic.
 1.94 19-Jul-2007  dsl include sys/cdefs.h before opt_xxx.h
 1.93 09-Jul-2007  ad branches: 1.93.2;
Merge some of the less invasive changes from the vmlocking branch:

- kthread, callout, devsw API changes
- select()/poll() improvements
- miscellaneous MT safety improvements
 1.92 04-Mar-2007  christos branches: 1.92.2; 1.92.4;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.91 16-Nov-2006  christos branches: 1.91.2; 1.91.4; 1.91.8;
__unused removal on arguments; approved by core.
 1.90 12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.89 13-Sep-2006  christos branches: 1.89.2;
- use c99 initializers
- add missing initializer
 1.88 13-Aug-2006  jmcneill branches: 1.88.2;
Provide a method for other display drivers to ask vga to free resources
it had claimed while acting as the initial console device. This allows
(for example) vga to be the initial console, and an accelerated
framebuffer driver to take over later.
 1.87 15-Apr-2006  jmmv Remove the getwschar and putwschar accessops from wsdisplay drivers as
requested by uwe@. These were wrong because they were receiving an
emulcookie yet they were accessops (thus having to receive an accesscookie).
Instead, just handle the WSDISPLAYIO_{GET,PUT}WSCHAR ioctls from the
driver's ioctl accessop.

As this reduces the amount of code needed to handle these operations to
two small functions in each driver, remove the WSDISPLAY_CHARFUNCS kernel
option.

Reviewed by, at least, uwe@ and macallan@. No objections in tech-kern@.
 1.86 12-Apr-2006  jmmv Add an extra cookie to the ioctl and mmap wsdisplay accessops that points
to the screen on which they are being called. The driver cannot guess
this by itself but it is needed to implement, at least, the getwschar and
putwschar functions in the correct place. There are no functional changes
yet.

Tested on i386 (vga, vga_raster, machfb, vesafb), macppc and sparc64.
Suggested and reviewed by macallan@.
 1.85 05-Apr-2006  drochner Move the ga_getborder()/vga_setborder() calls from accessops to the
ioctl handler.
Also fix error reporting for the vga_getborder() call.
 1.84 19-Feb-2006  jmcneill branches: 1.84.2; 1.84.4; 1.84.6;
Prevent vga from attaching if vesafb is the console. Accessing VGA
registers after switching to a VESA linear framebuffer mode is not
guaranteed to work. This should fix the majority of the problems people
have been experiencing with vesafb.

XXX: Still doesn't fix the assertion in wscons with options DIAGNOSTIC.
 1.83 11-Dec-2005  christos branches: 1.83.2; 1.83.4; 1.83.6;
merge ktrace-lwp.
 1.82 21-Oct-2005  dbj decrement nscreens in vga_free_screen
this cleans up a crash on failed allocation, although
vga_free_screen may still be leaking resources
 1.81 27-Feb-2005  perry branches: 1.81.2; 1.81.4; 1.81.6; 1.81.8; 1.81.10;
nuke trailing whitespace
 1.80 13-Aug-2004  mycroft branches: 1.80.4; 1.80.6;
Fix two annoying display glitches with "fast scrolling" and
WSDISPLAY_SCROLLSUPPORT.
 1.79 08-Aug-2004  christos disable the quirk on the console so that it can scroll.
 1.78 30-Jul-2004  jmmv Fix initialitzation of border color at boot time through the
WSDISPLAY_BORDER_COLOR option, broken by a last-minute change.
Pointed out by xtraeme@.

Also back out the previous change by dogcow@, which was an attempt
to fix kernel builds that didn't define WSDISPLAY_CUSTOM_BORDER;
shouldn't be needed now. (Problem also introduced by the same
last-minute change; sorry).
 1.77 30-Jul-2004  dogcow let kernels that don't have WSDISPLAY_CUSTOM_BORDER compile again.
 1.76 29-Jul-2004  jmmv Implement border color customization in wscons(4), only available for vga(4)
at the moment.

This includes the addition of two new wsdisplay ioctls, WSDISPLAY_{G,S}BORDER,
one to get the actual color and one to set it, respectively. Possible colors
match those defined by ANSI (and listed in wsdisplayvar.h).

It also adds two accessops to the underlying graphics device, getborder and
setborder, which mach their ioctl counterparts.

Two kernel options are added: WSDISPLAY_CUSTOM_BORDER, which enables the
ioctls described above (to customize the border color from userland after
boot), and WSDISPLAY_BORDER_COLOR, which sets the color at boot time.
The former is enabled by default on the GENERIC kernel, but not on INSTALL
(among others). The later is always commented out, leaving the usual black
border as a default.

wsconsctl is modified to allow accessing this value easily. For example,
'wsconsctl -d -w border=blue'.
 1.75 28-Jul-2004  jmmv Implement support to dynamically change wscons console and kernel colors.

Two new ioctls are added to the wsdisplay device, named WSDISPLAY_GMSGATTRS
and WSDISPLAY_SMSGATTRS, used to retrieve the actual values and set them,
respectively (the name, if you are wondering, comes from "message attributes").

A new emulop is added to the underlying display driver (only vga, for now)
which sets the new attribute for the whole screen, without having to clear
it. This is optional, which means that this also works with other drivers
that don't have this new operation.

Five new kernel options have been added, although only documented in
i386 kernels (for now):
- WSDISPLAY_CUSTOM_OUTPUT, which enables the ioctls described above to
change the colors dynamically from userland. This is enabled by default
in the GENERIC kernel (as well as others) but disabled on all INSTALL*
kernels (as this feature is useless there).
- WS_DEFAULT_COLATTR, WS_DEFAULT_MONOATTR, WS_DEFAULT_BG and WS_DEFAULT_FG,
which specify the default colors for the console at boot time. These have
the same meaning as the (already existing) WS_KERNEL_* variables.

wsconsctl is modified to add msg.default.{attrs,bg,fg} and
msg.kernel.{attrs,bg,fg} to the display part, so that colors can be changed
after boot.

Tested on NetBSD/i386 with vga (and vga in mono mode), and on NetBSD/mac68k.
No objections in tech-kern@.
 1.74 29-May-2004  christos fix another scrolling use that leaked.
 1.73 28-May-2004  christos move scroll function definition last.
 1.72 28-May-2004  christos PR/19925: David Ferlier: Add scrolling support to wscons.
 1.71 29-Jun-2003  fvdl branches: 1.71.2; 1.71.4;
Back out the lwp/ktrace changes. They contained a lot of colateral damage,
and need to be examined and discussed more.
 1.70 28-Jun-2003  darrenr Pass lwp pointers throughtout the kernel, as required, so that the lwpid can
be inserted into ktrace records. The general change has been to replace
"struct proc *" with "struct lwp *" in various function prototypes, pass
the lwp through and use l_proc to get the process pointer when needed.

Bump the kernel rev up to 1.6V
 1.69 09-Feb-2003  jdolecek make 'name' and 'data' of struct wsdisplay_font const, mark data arrays
in font sources const
 1.68 31-Jan-2003  tsutsui Changes to allow machines which don't use text mode at the boot time
to use generic VGA driver(s):
- Allow VGA drivers to use wsfont instead of builtin font.
- Add vga_reset() function, which will be called from MD consinit(),
to put VGA into text mode. This function is enabled by options VGA_RESET.
 1.67 27-Jan-2003  tsutsui - Replace some magic numbers with proper macro.
- Use vga_6845_{read,write}() defined in pcdisplayvar.h and
remove vga_crtc_{read,write}() macros in vgareg.h.
 1.66 27-Jan-2003  tsutsui KNF and space/TAB cleanup.
 1.65 20-Jan-2003  simonb Remove unreachable break after return.
 1.64 15-Oct-2002  junyoung Move vga_common_probe() to vga_common.c. vga_common.c contains common
stuff between existing char-cell VGA driver and raster VGA driver to
come shortly.
 1.63 08-Jul-2002  drochner save quirks in softc, obey VGA_QUIRK_NOFASTSCROLL
 1.62 07-Jul-2002  junyoung No need to include opt_vga.h here, since it is included in vgavar.h.
 1.61 07-Jul-2002  junyoung There's no function like vga_common_setup.
 1.60 07-Jul-2002  junyoung Rename vc_ccol and vc_crow in struct pcdisplayscreen to cursorcol
and cursorrow, respectively, to be consistent with other members
in the structure.
 1.59 04-Jul-2002  junyoung alloc_attr -> allocattr

Approved by Matthias Drochner.
 1.58 01-Jul-2002  drochner simplify console initialization a bit, avoid wasting
memory in attach(), and add some commemts
 1.57 01-Jul-2002  christos more cleanups from Julio Merino.
 1.56 28-Jun-2002  drochner clean up font handling:
-treat the builtin font like any other font at runtime
-for that, copy it to malloc()'d memory during attach()
-in early console initialization, if we have to consider a broken card
(VGA_CONSOLE_ATI_BROKEN_FONTSEL), copy the builtin font to another
location in font ram; the attach() code will do the rest
put the "quirk" code into effect again
 1.55 28-Jun-2002  junyoung Do the necessaries when the builtin font gets saved in slot 1.
 1.54 27-Jun-2002  junyoung - Work around a hardware bug that loaded fonts don't work, which is
found on many (all?) of PCI-based ATI graphics cards. It is fully optional
and can be enabled by adding `options VGA_CONSOLE_ATI_BROKEN_FONTSEL'
to config file.
- Temporarily remove `quirk' mechanism. Similar code already exists
in pci_quirks.c.
 1.53 26-Jun-2002  christos PR/17402: Add wsmoused support by providing get/set char and events.
 1.52 26-Jun-2002  drochner 2 fixes:
-Don't assume fonts to start with character 0, load at the
right offset. Now we can use eg wsfont/bold8x16.h which
starts with chr(1).
-Don't touch the hardware if a font is set for a screen which is
not active.
 1.51 25-Jun-2002  drochner allow to overwrite the builtin VGA font if necessary,
make the number of available font slots variable,
set up a "quirk" mechanism to tell the generic vga code about crippled
VGA adapters which ignore the "fontsel" TS register,
initiate the quirk table with an ATI chip which happened to be on a board
I tested with.
Afaik quite a number of ATI chips suffers from the "loaded fonts don't
work" problem - these should be added.
Bad side effect of my change: The builtin font will be kicked out
always if a VGA_CONSOLE_SCREENTYPE is specified which needs a loaded
font. In early console initialization, we don't know much about the
graphics card, so we have to assume the worst (ie ATI:-).
 1.50 04-Apr-2002  hannken branches: 1.50.2;
Avoid dereferencing null pointer. `data->name == NULL' means default font.
 1.49 17-Mar-2002  atatat Convert ioctl code to use EPASSTHROUGH instead of -1 or ENOTTY for
indicating an unhandled "command". ERESTART is -1, which can lead to
confusion. ERESTART has been moved to -3 and EPASSTHROUGH has been
placed at -4. No ioctl code should now return -1 anywhere. The
ioctl() system call is now properly restartable.
 1.48 13-Mar-2002  ad Fix botch in previous.
 1.47 13-Mar-2002  ad Reorganise the wsfont stuff slightly so that multiple display adapters
with different bit/byte order requirements can co-exist happily.
 1.46 23-Jan-2002  lukem Add support for WSCONS screenblank ioctls. From Phil Budne in [kern/15213].
 1.45 13-Dec-2001  junyoung ANSIfication & cosmetic changes.
 1.44 02-Dec-2001  bjh21 Add comments naming our private-use characters (in lower case, to make them
distinct from real Unicode characters).
 1.43 13-Nov-2001  lukem add/cleanup RCSID
 1.42 14-Sep-2001  thorpej Allow bus front-end to provide both ioctl and mmap entry points,
and also the wsdisplay type.

Based on changes from Simon Burge <simonb@wasabisystems.com>.
 1.41 10-Sep-2001  drochner remove all traces when a font is removed
 1.40 07-Sep-2001  drochner concentrate screen initialization into vga_init_screen() where it belongs
 1.39 04-Sep-2001  drochner branches: 1.39.2;
simplify the way the "active screen" is kept track of a bit
 1.38 04-Sep-2001  drochner -fix a debug message
-unref font(s) if a screen is deleted, so they could be unloaded
if dev/wsfont supported it
-add missing pieces to support screen types with font sizes != 8x16
as system console - now
options VGA_CONSOLE_SCREENTYPE="\"80x50\""
options FONT_VT220L8x8
gives you what you'd expect
 1.37 03-Sep-2001  drochner manage fonts through the wsfont framework, which allows to use both
compiled-in or runtime loaded fonts,
keep font pointers in a LRU queue and load into the adapter on demand,
so we can have more fonts in use than physical font slots

CAUTION: font loading through the wsdisplay device directly into the
adapter doesn't work anymore!
 1.36 07-Jul-2001  thorpej branches: 1.36.2;
bcopy -> memcpy
 1.35 18-Jan-2001  jdolecek branches: 1.35.2;
constify
 1.34 15-Sep-2000  drochner -make the default screentype override less invasive, call it
VGA_CONSOLE_SCREENTYPE because the screen types are hardware specific
and make it affect the console only (no need to change runtime
behaviour), don't call vga_setscreentype() unless necessary (to avoid
trouble with strange hardware - PR kern/11025)
-some beginnings of ISO-7 (greek) font support
 1.33 10-Sep-2000  lukem * rename vga_stdscreen* -> vga_25lscreen*
* in vga_init(), set the screen type to WSCONS_DEFAULT_TYPE, which defaults
to "80x25".
XXX: the code currently makes no attempt to ensure that a font
with the appropriate width & height is available, effectively
limiting this default to either "80x25" or "80x24" at this
time.
* make wsdisplay_screentype_pick() non static, so that vga_init() can use it
 1.32 14-Aug-2000  thorpej Just add the mmap argument to vga_common_attach(), don't bother
with vga_extended_attach().
 1.31 08-Aug-2000  jeffs Update arc map routine prototype to compile again.
 1.30 15-Jul-2000  drochner define "80x24" screen types for better vt100 compatibility
 1.29 26-Jun-2000  simonb Change the kernel mmap interface so that the offset to map is an
"off_t" and the return value is a "paddr_t" to allow mappings
at offsets past 2^31 bytes. Somewhat inspired by FreeBSD, which
only changed the offset to a "vm_offset_t".

Includes updates for the i386, pc532 and sh3 mmmmap from Jason Thorpe.
 1.28 17-Jun-2000  soda branches: 1.28.2;
add vga_extended_attach function on arc port, to make mmap() available.
XXX - is it better to remove "#ifdef arc"?
 1.27 08-Jun-2000  cgd don't include ISA headers. these have been properly abstracted so that
the ISA headers are unnecessary, and they're used by PCI VGA. There may
not be any ISA at all.
 1.26 23-Mar-2000  thorpej branches: 1.26.2;
New callout mechanism with two major improvements over the old
timeout()/untimeout() API:
- Clients supply callout handle storage, thus eliminating problems of
resource allocation.
- Insertion and removal of callouts is constant time, important as
this facility is used quite a lot in the kernel.

The old timeout()/untimeout() API has been removed from the kernel.
 1.25 25-Jan-2000  ad Finish with fixing the SOFTCURSOR stuff.
 1.24 05-Jan-2000  ad Add and use pcdisplay_cursor_init(). Still a couple of nits with this, I
will resolve when I can test properly.
 1.23 13-Dec-1999  drochner fix off-by-one error in font table initialisation
(mostly harmless because it is zero initialized in most cases anyway)
 1.22 06-Dec-1999  drochner do the screen switch asynchronously (via timeout(0)) if possible,
this hopefully helps for the (very rare) display corruption reported
in PR kern/8628
 1.21 03-Nov-1999  mycroft Only update the cursor state if it's enabled.
 1.20 29-Sep-1999  ad branches: 1.20.2; 1.20.4; 1.20.6;
PCDISPLAY_SOFTCURSOR: remember state of cursor during full screen scroll.
 1.19 19-Sep-1999  ad Software cursor is not enabled at boot time. Hardware cursor is.
 1.18 19-Sep-1999  ad - mc6845's cursor is disabled by punching bit 6 of cursor start register.
- Add new option (PCDISPLAY_SOFTCURSOR) that provides a large, non-blinking
cursor in software.
 1.17 10-Apr-1999  drochner add support for 80x40 screens
 1.16 01-Apr-1999  drochner branches: 1.16.4;
use defopted WSCONS_SUPPORT_PCVTFONTS, refuse to load pcvt fonts if this
option is not given, suppress complaints in non-debug case
 1.15 22-Mar-1999  drochner set "fontset" variables to 0 if no appropriate font was found for a
freshly allocated screen, should fix panic if "vga_mapchar()" it
attempted later
 1.14 20-Feb-1999  drochner complete mapping table for pcvt fonts, make dual-font selection work
as intended
 1.13 12-Feb-1999  drochner change the "mapchar" interface to return a "quality" or "match level"
arguments which allows to find approximations for characters which are
not present in a font
 1.12 13-Jan-1999  drochner -implement new wscons font handling with separate download and selection
calls
-support use of 2 fonts simultanously; this costs the ability to
"highlight", ie to use the upper 8 colours
-define screen types "80x25bf" and "80x50bf" which use this ability
-add conditional code to deal with the weird mapping of pcvt's
supplemental fonts
 1.11 09-Jan-1999  drochner Allow to deallocate also the currently visible virtual screen (unless
it is the console).
This requires vva_show_screen() to catch the case where it has no screen
to switch from, ie no need to save the current state.
 1.10 30-Dec-1998  augustss Add a wscons display type `unknown' that the generic VGA driver can
return until someone fixes it for real.
 1.9 13-Aug-1998  eeh Merge paddr_t changes into the main branch.
 1.8 24-Jul-1998  drochner branches: 1.8.2;
Overload the generic "copyrows" function by a private one which implents
a "fast scroll" by setting the display start in memory.
(Only implemented for "scroll up" because this is more used. "scroll down"
is easy to add.)
This moves the semantics of "copyrows" to something like "moverows";
the contents of the new visible lines at the bottom is undefined.
The emulations can live without the original "copy" semantics.
 1.7 26-Jun-1998  drochner do the charcter mapping in a separate function
 1.6 20-Jun-1998  drochner adapt to wscons changes, treat incoming characters always as ISO
(ie, convert to IBM)
 1.5 12-Jun-1998  drochner reserve the VGA BIOS area (but don't worry if it fails)
 1.4 28-May-1998  drochner Put definitions and subroutines needed for all PC display adapters
(MGA/GCA and compatibles) into global headers / source files.
Let the VGA driver use them.
 1.3 14-May-1998  drochner Simple screen attribute handling for wscons.
The graphics device driver passes a "default attribute" for normal text
output to the wscons framework. If the emulation module needs more
attributes (for different "renditions") it can allocate them via a
callback.
For now, only the "sun" emulation makes use of it.
 1.2 07-Apr-1998  drochner Avoid namespace pollution.
 1.1 22-Mar-1998  drochner initial import of VGA driver backend for use with the new wscons code
 1.8.2.2 08-Aug-1998  eeh Revert cdevsw mmap routines to return int.
 1.8.2.1 07-Aug-1998  drochner make it compile in paddr_t world
 1.16.4.1 21-Jun-1999  thorpej Sync w/ -current.
 1.20.6.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.20.4.1 15-Nov-1999  fvdl Sync with -current
 1.20.2.2 11-Feb-2001  bouyer Sync with HEAD.
 1.20.2.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.26.2.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.28.2.3 31-Aug-2000  drochner pullup rev. 1.30:
define "80x24" screen types for better vt100 compatibility
(manpage was already pulled up)
 1.28.2.2 08-Aug-2000  jeffs Pull up revision 1.31 (approved by thorpej):
Fix compile problem with paddr_t.
 1.28.2.1 30-Jun-2000  simonb Pull up mmap paddr_t/off_t changes from trunk.
 1.35.2.9 18-Oct-2002  nathanw Catch up to -current.
 1.35.2.8 01-Aug-2002  nathanw Catch up to -current.
 1.35.2.7 17-Apr-2002  nathanw Catch up to -current.
 1.35.2.6 01-Apr-2002  nathanw Catch up to -current.
(CVS: It's not just a program. It's an adventure!)
 1.35.2.5 28-Feb-2002  nathanw Catch up to -current.
 1.35.2.4 08-Jan-2002  nathanw Catch up to -current.
 1.35.2.3 14-Nov-2001  nathanw Catch up to -current.
 1.35.2.2 21-Sep-2001  nathanw Catch up to -current.
 1.35.2.1 24-Aug-2001  nathanw Catch up with -current.
 1.36.2.6 06-Sep-2002  jdolecek sync kqueue branch with HEAD
 1.36.2.5 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.36.2.4 16-Mar-2002  jdolecek Catch up with -current.
 1.36.2.3 11-Feb-2002  jdolecek Sync w/ -current.
 1.36.2.2 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.36.2.1 13-Sep-2001  thorpej Update the kqueue branch to HEAD.
 1.39.2.1 01-Oct-2001  fvdl Catch up with -current.
 1.50.2.1 15-Jul-2002  gehenna catch up with -current.
 1.71.4.6 12-Aug-2007  bouyer Pull up following revision(s) (requested by mjf in ticket #11348):
Pull up following revision(s) (requested by mjf in ticket #11348):
sys/dev/ic/pcdisplay_subr.c: revision 1.33 via patch
sys/dev/ic/vga_raster.c: revision 1.29 via patch
sys/dev/ic/vga.c: revision 1.95 via patch
sys/dev/rasops/rasops.c: revision 1.56 via patch
sys/dev/isa/ega.c: revision 1.23 via patch
Implement bounds checking in some places in display driver code to avoid
the possibility of a local user panic.
Set the 'ri' pointer before use.
 1.71.4.5 22-Aug-2004  tron branches: 1.71.4.5.2; 1.71.4.5.4;
Pull up revision 1.80 (requested by recht in ticket #774):
Fix two annoying display glitches with "fast scrolling" and
WSDISPLAY_SCROLLSUPPORT.
 1.71.4.4 22-Aug-2004  tron Pull up revision 1.79 (requested by recht in ticket #774):
disable the quirk on the console so that it can scroll.
 1.71.4.3 07-Jun-2004  tron Pull up revision 1.74 (requested by recht in ticket #451):
fix another scrolling use that leaked.
 1.71.4.2 07-Jun-2004  tron Pull up revision 1.73 (requested by recht in ticket #451):
move scroll function definition last.
 1.71.4.1 07-Jun-2004  tron Pull up revision 1.72 (requested by recht in ticket #451):
PR/19925: David Ferlier: Add scrolling support to wscons.
 1.71.4.5.4.1 12-Aug-2007  bouyer Pull up following revision(s) (requested by mjf in ticket #11348):
Pull up following revision(s) (requested by mjf in ticket #11348):
sys/dev/ic/pcdisplay_subr.c: revision 1.33 via patch
sys/dev/ic/vga_raster.c: revision 1.29 via patch
sys/dev/ic/vga.c: revision 1.95 via patch
sys/dev/rasops/rasops.c: revision 1.56 via patch
sys/dev/isa/ega.c: revision 1.23 via patch
Implement bounds checking in some places in display driver code to avoid
the possibility of a local user panic.
Set the 'ri' pointer before use.
 1.71.4.5.2.1 11-Aug-2007  bouyer Pull up following revision(s) (requested by mjf in ticket #11348):
sys/dev/ic/pcdisplay_subr.c: revision 1.33 via patch
sys/dev/ic/vga_raster.c: revision 1.29 via patch
sys/dev/ic/vga.c: revision 1.95 via patch
sys/dev/rasops/rasops.c: revision 1.56 via patch
sys/dev/isa/ega.c: revision 1.23 via patch
Implement bounds checking in some places in display driver code to avoid
the possibility of a local user panic.
Set the 'ri' pointer before use.
 1.71.2.8 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.71.2.7 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.71.2.6 21-Sep-2004  skrll Fix the sync with head I botched.
 1.71.2.5 18-Sep-2004  skrll Sync with HEAD.
 1.71.2.4 25-Aug-2004  skrll Sync with HEAD.
 1.71.2.3 12-Aug-2004  skrll Sync with HEAD.
 1.71.2.2 03-Aug-2004  skrll Sync with HEAD
 1.71.2.1 02-Jul-2003  darrenr Apply the aborted ktrace-lwp changes to a specific branch. This is just for
others to review, I'm concerned that patch fuziness may have resulted in some
errant code being generated but I'll look at that later by comparing the diff
from the base to the branch with the file I attempt to apply to it. This will,
at the very least, put the changes in a better context for others to review
them and attempt to tinker with removing passing of 'struct lwp' through
the kernel.
 1.80.6.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.80.4.1 29-Apr-2005  kent sync with -current
 1.81.10.1 06-Aug-2007  ghen Pull up following revision(s) (requested by mjf in ticket #1815):
sys/dev/ic/pcdisplay_subr.c: revision 1.33 via patch
sys/dev/ic/vga_raster.c: revision 1.29 via patch
sys/dev/ic/vga.c: revision 1.95 via patch
sys/dev/rasops/rasops.c: revision 1.56 via patch
sys/dev/isa/ega.c: revision 1.23 via patch
Implement bounds checking in some places in display driver code to avoid
the possibility of a local user panic.
Set the 'ri' pointer before use.
 1.81.8.1 06-Aug-2007  ghen Pull up following revision(s) (requested by mjf in ticket #1815):
sys/dev/ic/pcdisplay_subr.c: revision 1.33 via patch
sys/dev/ic/vga_raster.c: revision 1.29 via patch
sys/dev/ic/vga.c: revision 1.95 via patch
sys/dev/rasops/rasops.c: revision 1.56 via patch
sys/dev/isa/ega.c: revision 1.23 via patch
Implement bounds checking in some places in display driver code to avoid
the possibility of a local user panic.
Set the 'ri' pointer before use.
 1.81.6.1 26-Oct-2005  yamt sync with head
 1.81.4.6 17-Mar-2008  yamt sync with head.
 1.81.4.5 21-Jan-2008  yamt sync with head
 1.81.4.4 27-Oct-2007  yamt sync with head.
 1.81.4.3 03-Sep-2007  yamt sync with head.
 1.81.4.2 30-Dec-2006  yamt sync with head.
 1.81.4.1 21-Jun-2006  yamt sync with head.
 1.81.2.1 06-Aug-2007  ghen Pull up following revision(s) (requested by mjf in ticket #1815):
sys/dev/ic/pcdisplay_subr.c: revision 1.33 via patch
sys/dev/ic/vga_raster.c: revision 1.29 via patch
sys/dev/ic/vga.c: revision 1.95 via patch
sys/dev/rasops/rasops.c: revision 1.56 via patch
sys/dev/isa/ega.c: revision 1.23 via patch
Implement bounds checking in some places in display driver code to avoid
the possibility of a local user panic.
Set the 'ri' pointer before use.
 1.83.6.1 22-Apr-2006  simonb Sync with head.
 1.83.4.1 09-Sep-2006  rpaulo sync with head
 1.83.2.1 01-Mar-2006  yamt sync with head.
 1.84.6.1 24-May-2006  tron Merge 2006-05-24 NetBSD-current into the "peter-altq" branch.
 1.84.4.1 19-Apr-2006  elad sync with head.
 1.84.2.4 14-Sep-2006  yamt sync with head.
 1.84.2.3 03-Sep-2006  yamt sync with head.
 1.84.2.2 24-May-2006  yamt sync with head.
 1.84.2.1 11-Apr-2006  yamt sync with head
 1.88.2.1 18-Nov-2006  ad Sync with head.
 1.89.2.2 10-Dec-2006  yamt sync with head.
 1.89.2.1 22-Oct-2006  yamt sync with head
 1.91.8.1 03-Sep-2007  wrstuden Sync w/ NetBSD-4-RC_1
 1.91.4.1 12-Mar-2007  rmind Sync with HEAD.
 1.91.2.1 30-Jul-2007  liamjfoy Pull up following revision(s) (requested by mjf in ticket #799):
sys/dev/ic/pcdisplay_subr.c: revision 1.33
sys/dev/wscons/wsdisplay_vcons.c: revision 1.12
sys/dev/wscons/wsdisplay_vcons.c: revision 1.13
sys/dev/ic/vga_raster.c: revision 1.29
sys/dev/pci/chipsfb.c: revision 1.10
sys/dev/ic/vga.c: revision 1.95
sys/dev/rasops/rasops.c: revision 1.56
sys/dev/isa/ega.c: revision 1.23
Implement bounds checking in some places in display driver code to avoid
the possibility of a local user panic.
Set the 'ri' pointer before use.
 1.92.4.1 11-Jul-2007  mjf Sync with head.
 1.92.2.4 23-Oct-2007  ad Sync with head.
 1.92.2.3 12-Oct-2007  ad Fix merge errors.
 1.92.2.2 20-Aug-2007  ad Sync with HEAD.
 1.92.2.1 01-Jul-2007  ad Adapt to callout API change.
 1.93.2.1 15-Aug-2007  skrll Sync with HEAD.
 1.95.12.2 28-Jul-2007  mjf Implement bounds checking in some places in display driver code to avoid
the possibility of a local user panic.
 1.95.12.1 28-Jul-2007  mjf file vga.c was added on branch matt-mips64 on 2007-07-28 20:28:57 +0000
 1.95.10.1 25-Oct-2007  bouyer Sync with HEAD.
 1.95.6.3 23-Mar-2008  matt sync with HEAD
 1.95.6.2 09-Jan-2008  matt sync with HEAD
 1.95.6.1 06-Nov-2007  matt sync with HEAD
 1.95.4.4 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.95.4.3 01-Oct-2007  joerg Extend device API by device_power_private and device_power_set_private.
The latter is a temporary mean until the pnp_register API itself is
overhault. This functions allow a generic power handler to store its
state independent of the driver.

Use this and revamp the PCI power handling. Pretty much all PCI devices
had power handlers that did the same thing, generalize this in
pci_generic_power_register/deregister and the handler. This interface
offers callbacks for the drivers to save and restore state on
transistions. After a long discussion with jmcneill@ it was considered
to be powerful enough until evidence is shown that devices can handle
D1/D2 with less code and higher speed than without the full
save/restore. The generic code is carefully written to handle device
without PCI-PM support and ensure that the correct registers are written
to when D3 loses all state.

Reimplement the generic PCI network device handling on
top of PCI generic power handling.

Introduce pci_disable_retry as used and implemented locally at least by
ath(4) and iwi(4). Use it in this drivers to restore behaviour from
before the introduction of generic PCI network handling.

Convert all PCI drivers that were using pnp_register to the new
framework. The only exception is vga(4) as it is commonly used as
console device. Add a note therein that this should be fixed later.
 1.95.4.2 04-Aug-2007  jmcneill Don't bother running vga_initregs on resume.
 1.95.4.1 03-Aug-2007  jmcneill Pull in power management changes from private branch.
 1.96.6.1 11-Dec-2007  yamt sync with head.
 1.96.4.1 26-Dec-2007  ad Sync with head.
 1.97.10.1 03-Apr-2008  mjf Sync with HEAD.
 1.97.6.1 24-Mar-2008  keiichi sync with head.
 1.100.18.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.100.12.1 03-Mar-2009  skrll Sync with HEAD.
 1.100.4.3 11-Aug-2010  yamt sync with head.
 1.100.4.2 11-Mar-2010  yamt sync with head
 1.100.4.1 04-May-2009  yamt sync with head.
 1.101.2.2 22-Oct-2010  uebayasi Sync with HEAD (-D20101022).
 1.101.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.102.2.3 12-Jun-2011  rmind sync with head
 1.102.2.2 05-Mar-2011  rmind sync with head
 1.102.2.1 30-May-2010  rmind sync with head
 1.106.6.1 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.107.6.1 18-Feb-2012  mrg merge to -current.
 1.107.2.4 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.107.2.3 23-Jan-2013  yamt sync with head
 1.107.2.2 30-Oct-2012  yamt sync with head
 1.107.2.1 17-Apr-2012  yamt sync with head
 1.108.2.1 12-Aug-2012  martin Pull up following revision(s) (requested by uwe in ticket #472):
sys/dev/ic/vga.c: revision 1.109
Reset flip/flop using dedicated vga_reset_state() macro we already have.
Explicit vga_raw_read() used here before was incorrect since it reads
from *wrong* io handle!
Fixes weird problem under VirtualBox where first switch to a different
VT caused text mode color 0 (normally black) to become something else.
 1.109.2.3 03-Dec-2017  jdolecek update from HEAD
 1.109.2.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.109.2.1 25-Feb-2013  tls resync with head
 1.110.2.1 18-May-2014  rmind sync with head
 1.111.2.1 10-Aug-2014  tls Rebase.
 1.112.2.1 14-Jan-2015  martin Pull up following revision(s) (requested by chs in ticket #418):
sys/dev/ic/vga.c: revision 1.113
sys/dev/ic/vga.c: revision 1.114
sys/dev/ic/vga_raster.c: revision 1.42
sys/dev/ic/vga_raster.c: revision 1.43
sys/dev/ic/vgavar.h: revision 1.31
sys/dev/ic/vgavar.h: revision 1.33
I've been unable to find any code that actually uses the mapping and we may
want to read the ROM from drm2.
If no users show up within a week or so I'll delete it.
remove BIOS-mapping code that was #if-0'd in the previous commit.
 1.113.2.1 06-Apr-2015  skrll Sync with HEAD
 1.115.18.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.115.18.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.117.6.1 25-Apr-2020  bouyer Sync with bouyer-xenpvh-base2 (HEAD)
 1.118.4.1 02-Apr-2021  thorpej config_found_ia() -> config_found() w/ CFARG_IATTR.
 1.119.8.1 04-Aug-2021  thorpej Adapt to CFARGS().
 1.11 19-Feb-2009  jmcneill Remove vesafb-specific hacks.
 1.10 08-Apr-2008  cegger branches: 1.10.4; 1.10.12; 1.10.18;
use aprint_*_dev and device_xname
 1.9 14-Mar-2008  cube Split device_t and softc for all attachments of vga(4).
 1.8 19-Oct-2007  ad branches: 1.8.12; 1.8.16;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.7 19-Feb-2006  jmcneill branches: 1.7.24; 1.7.38; 1.7.40; 1.7.44;
Prevent vga from attaching if vesafb is the console. Accessing VGA
registers after switching to a VESA linear framebuffer mode is not
guaranteed to work. This should fix the majority of the problems people
have been experiencing with vesafb.

XXX: Still doesn't fix the assertion in wscons with options DIAGNOSTIC.
 1.6 11-Dec-2005  christos branches: 1.6.2; 1.6.4; 1.6.6;
merge ktrace-lwp.
 1.5 27-Feb-2005  perry branches: 1.5.4;
nuke trailing whitespace
 1.4 14-Jul-2003  lukem branches: 1.4.8; 1.4.10;
add missing __KERNEL_RCSID()
 1.3 27-Jan-2003  tsutsui branches: 1.3.2;
- Replace some magic numbers with proper macro.
- Use vga_6845_{read,write}() defined in pcdisplayvar.h and
remove vga_crtc_{read,write}() macros in vgareg.h.
 1.2 27-Jan-2003  tsutsui KNF and space/TAB cleanup.
 1.1 15-Oct-2002  junyoung branches: 1.1.2;
Move vga_common_probe() to vga_common.c. vga_common.c contains common
stuff between existing char-cell VGA driver and raster VGA driver to
come shortly.
 1.1.2.2 18-Oct-2002  nathanw Catch up to -current.
 1.1.2.1 15-Oct-2002  nathanw file vga_common.c was added on branch nathanw_sa on 2002-10-18 02:42:01 +0000
 1.3.2.4 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.3.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.3.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.3.2.1 03-Aug-2004  skrll Sync with HEAD
 1.4.10.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.4.8.1 29-Apr-2005  kent sync with -current
 1.5.4.3 17-Mar-2008  yamt sync with head.
 1.5.4.2 27-Oct-2007  yamt sync with head.
 1.5.4.1 21-Jun-2006  yamt sync with head.
 1.6.6.1 22-Apr-2006  simonb Sync with head.
 1.6.4.1 09-Sep-2006  rpaulo sync with head
 1.6.2.1 01-Mar-2006  yamt sync with head.
 1.7.44.1 25-Oct-2007  bouyer Sync with HEAD.
 1.7.40.2 23-Mar-2008  matt sync with HEAD
 1.7.40.1 06-Nov-2007  matt sync with HEAD
 1.7.38.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.7.24.1 23-Oct-2007  ad Sync with head.
 1.8.16.2 02-Jun-2008  mjf Sync with HEAD.
 1.8.16.1 03-Apr-2008  mjf Sync with HEAD.
 1.8.12.1 24-Mar-2008  keiichi sync with head.
 1.10.18.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.10.12.1 03-Mar-2009  skrll Sync with HEAD.
 1.10.4.1 04-May-2009  yamt sync with head.
 1.50 07-Aug-2021  thorpej Merge thorpej-cfargs2.
 1.49 24-Apr-2021  thorpej branches: 1.49.8;
Merge thorpej-cfargs branch:

Simplify and make extensible the config_search() / config_found() /
config_attach() interfaces: rather than having different variants for
which arguments you want pass along, just have a single call that
takes a variadic list of tag-value arguments.

Adjust all call sites:
- Simplify wherever possible; don't pass along arguments that aren't
actually needed.
- Don't be explicit about what interface attribute is attaching if
the device only has one. (More simplification.)
- Add a config_probe() function to be used in indirect configuiration
situations, making is visibly easier to see when indirect config is
in play, and allowing for future change in semantics. (As of now,
this is just a wrapper around config_match(), but that is an
implementation detail.)

Remove unnecessary or redundant interface attributes where they're not
needed.

There are currently 5 "cfargs" defined:
- CFARG_SUBMATCH (submatch function for direct config)
- CFARG_SEARCH (search function for indirect config)
- CFARG_IATTR (interface attribte)
- CFARG_LOCATORS (locators array)
- CFARG_DEVHANDLE (devhandle_t - wraps OFW, ACPI, etc. handles)

...and a sentinel value CFARG_EOL.

Add some extra sanity checking to ensure that interface attributes
aren't ambiguous.

Use CFARG_DEVHANDLE in MI FDT, OFW, and ACPI code, and macppc and shark
ports to associate those device handles with device_t instance. This
will trickle trough to more places over time (need back-end for pre-OFW
Sun OBP; any others?).
 1.48 24-Apr-2020  ad branches: 1.48.4;
BUS_SPACE_MAP_PREFETCHABLE yields a write combining region on x86 and that's
not what I intended.. BUS_SPACE_MAP_CACHEABLE is enough.
 1.47 04-Apr-2020  riastradh branches: 1.47.2;
Mark res __diagused; #ifdef DIAGNOSTIC panic ---> KASSERT.
 1.46 01-Dec-2019  ad Map the video RAM cacheable/prefetchable, it's very slow and this helps a bit.
 1.45 10-Nov-2019  chs in many device attach paths, allocate memory with M_WAITOK instead of M_NOWAIT
and remove code to handle failures that can no longer happen.
 1.44 01-Mar-2015  mlelstv branches: 1.44.18;
Also unmap video memory when detaching console
 1.43 14-Jan-2015  chs remove BIOS-mapping code that was #if-0'd in the previous commit.
 1.42 21-Aug-2014  macallan branches: 1.42.2;
#if 0 code to map the VGA BIOS
I've been unable to find any code that actually uses the mapping and we may
want to read the ROM from drm2.
If no users show up within a week or so I'll delete it.
 1.41 12-Jul-2014  mlelstv branches: 1.41.2;
detach wscons when detaching console
 1.40 18-Apr-2014  mlelstv more unused variables.
 1.39 18-Apr-2014  mlelstv include VGA kernel options
 1.38 18-Apr-2014  mlelstv handle unused variables
 1.37 14-Apr-2013  christos branches: 1.37.4; 1.37.8;
return something reasonable for WSDISPLAYIO_GINFO
 1.36 21-Jan-2013  mlelstv Make internal functions static
 1.35 11-Jan-2012  macallan branches: 1.35.6;
wsfont_matches() and wsfont_find() take an extra parameter now
 1.34 24-Mar-2010  tnn branches: 1.34.8; 1.34.12;
sys/dev/ic/videomode.h is almost identical to sys/dev/videomode/videomode.h
Remove the former.
 1.33 19-Oct-2008  jmcneill branches: 1.33.14; 1.33.16;
Calculate maxdispoffset rather than hard-coding it. Fixes scrolling in
80x25 mode.

XXX This doesn't handle odd modes like 80x30 on 640x480, but the driver
didn't allow that selection previously so at least it's an improvement
over the previous behaviour.
 1.32 19-Oct-2008  jmcneill vga_cnattach: calling wsdisplay_screentype_pick with a NULL type will
select the first entry in the list, which overrides the selected screen
type. Only call it a second time if the original selection is invalid.
 1.31 15-Jun-2008  nonaka branches: 1.31.2;
fix compile failure.
 1.30 19-Oct-2007  ad branches: 1.30.16; 1.30.18; 1.30.20; 1.30.22; 1.30.24;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.29 28-Jul-2007  mjf branches: 1.29.4; 1.29.6; 1.29.10; 1.29.12;
Implement bounds checking in some places in display driver code to avoid
the possibility of a local user panic.
 1.28 09-Jul-2007  ad branches: 1.28.2;
Merge some of the less invasive changes from the vmlocking branch:

- kthread, callout, devsw API changes
- select()/poll() improvements
- miscellaneous MT safety improvements
 1.27 15-Mar-2007  dogcow Some delicious copypasta from sys/dev/ic/vga.c, so that unichromefb will
compile (and possibly work) when option VGA_RASTERCONSOLE is present.
 1.26 04-Mar-2007  christos branches: 1.26.2; 1.26.4; 1.26.6;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.25 16-Nov-2006  christos branches: 1.25.2; 1.25.4; 1.25.8;
__unused removal on arguments; approved by core.
 1.24 12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.23 03-Sep-2006  christos branches: 1.23.2; 1.23.4;
add missing initializers
 1.22 26-Apr-2006  rpaulo In vga_cnattach(), intialize typestr to NULL.
 1.21 12-Apr-2006  jmmv Add an extra cookie to the ioctl and mmap wsdisplay accessops that points
to the screen on which they are being called. The driver cannot guess
this by itself but it is needed to implement, at least, the getwschar and
putwschar functions in the correct place. There are no functional changes
yet.

Tested on i386 (vga, vga_raster, machfb, vesafb), macppc and sparc64.
Suggested and reviewed by macallan@.
 1.20 12-Dec-2005  christos branches: 1.20.4; 1.20.6; 1.20.8; 1.20.10; 1.20.12;
more proc->lwp changes.
 1.19 11-Dec-2005  christos merge ktrace-lwp.
 1.18 21-Oct-2005  dbj decrement nscreens in vga_free_screen
this cleans up a crash on failed allocation, although
vga_free_screen may still be leaking resources
 1.17 07-Jul-2005  christos branches: 1.17.2;
add a missing const.
 1.16 27-Feb-2005  perry branches: 1.16.2; 1.16.4; 1.16.6; 1.16.8;
nuke trailing whitespace
 1.15 13-Aug-2004  mycroft branches: 1.15.4; 1.15.6;
Remove a really gratuitous 1s delay.
 1.14 30-Jul-2004  jmmv Implement the replaceattr emulop.
 1.13 30-Jul-2004  jmmv Fix the eraserows operation, which was using an incorrect value to paint
the background. The problem was exposed when setting a non-black color
as the background, as the shift did not produce the expected fill value
(for black it worked because 0 is black).
 1.12 14-Jul-2003  lukem branches: 1.12.2; 1.12.4; 1.12.6;
add missing __KERNEL_RCSID()
 1.11 07-Apr-2003  junyoung branches: 1.11.2;
As beginning of merging uwscons to -current:
- Add a (temporary) printf to vga_raster_load_font() for tracking font
loading process. If you encountered "vga_raster_load_font: called"
kernel message, please let me know.
- While here, some KNF.
 1.10 31-Jan-2003  tsutsui Changes to allow machines which don't use text mode at the boot time
to use generic VGA driver(s):
- Allow VGA drivers to use wsfont instead of builtin font.
- Add vga_reset() function, which will be called from MD consinit(),
to put VGA into text mode. This function is enabled by options VGA_RESET.
 1.9 27-Jan-2003  tsutsui Set a value for MISCOUT register correctly in vga_setup_regs().
 1.8 27-Jan-2003  tsutsui const'ify.
 1.7 27-Jan-2003  tsutsui - Replace some magic numbers with proper macro.
- Use vga_6845_{read,write}() defined in pcdisplayvar.h and
remove vga_crtc_{read,write}() macros in vgareg.h.
 1.6 27-Jan-2003  tsutsui KNF and space/TAB cleanup.
 1.5 28-Nov-2002  junyoung Fix compile error.
 1.4 04-Nov-2002  junyoung Missing '.'
 1.3 31-Oct-2002  junyoung Now VGA_CONSOLE_SCREENTYPE can be specified with VGA_RASTERCONSOLE.
Currently only 80x25 and 80x30 modes are supported.
 1.2 31-Oct-2002  junyoung Simplify vga_raster_setscreentype() and clean up code.
 1.1 15-Oct-2002  junyoung branches: 1.1.2;
Add VGA raster graphics console driver. It is written as an extension
to char-cell based vga(4) driver, and fully compatible with existing
apps like XFree86. Currently it supports 80x25, 80x30, 80x40 and 80x50
text modes using emulation. You can enable it by specifying `options
VGA_RASTERCONSOLE' in your kernel config file.

Note that displaying multilingual text doesn't work yet. Necessary
code is already there, but userland stuff and some functionality isn't
ready for prime time yet. I'm working on them.
 1.1.2.4 11-Dec-2002  thorpej Sync with HEAD.
 1.1.2.3 11-Nov-2002  nathanw Catch up to -current
 1.1.2.2 18-Oct-2002  nathanw Catch up to -current.
 1.1.2.1 15-Oct-2002  nathanw file vga_raster.c was added on branch nathanw_sa on 2002-10-18 02:42:01 +0000
 1.11.2.6 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.11.2.5 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.11.2.4 21-Sep-2004  skrll Fix the sync with head I botched.
 1.11.2.3 18-Sep-2004  skrll Sync with HEAD.
 1.11.2.2 25-Aug-2004  skrll Sync with HEAD.
 1.11.2.1 03-Aug-2004  skrll Sync with HEAD
 1.12.6.1 12-Aug-2007  bouyer Pull up following revision(s) (requested by mjf in ticket #11348):
Pull up following revision(s) (requested by mjf in ticket #11348):
sys/dev/ic/pcdisplay_subr.c: revision 1.33 via patch
sys/dev/ic/vga_raster.c: revision 1.29 via patch
sys/dev/ic/vga.c: revision 1.95 via patch
sys/dev/rasops/rasops.c: revision 1.56 via patch
sys/dev/isa/ega.c: revision 1.23 via patch
Implement bounds checking in some places in display driver code to avoid
the possibility of a local user panic.
Set the 'ri' pointer before use.
 1.12.4.1 11-Aug-2007  bouyer Pull up following revision(s) (requested by mjf in ticket #11348):
sys/dev/ic/pcdisplay_subr.c: revision 1.33 via patch
sys/dev/ic/vga_raster.c: revision 1.29 via patch
sys/dev/ic/vga.c: revision 1.95 via patch
sys/dev/rasops/rasops.c: revision 1.56 via patch
sys/dev/isa/ega.c: revision 1.23 via patch
Implement bounds checking in some places in display driver code to avoid
the possibility of a local user panic.
Set the 'ri' pointer before use.
 1.12.2.1 12-Aug-2007  bouyer Pull up following revision(s) (requested by mjf in ticket #11348):
Pull up following revision(s) (requested by mjf in ticket #11348):
sys/dev/ic/pcdisplay_subr.c: revision 1.33 via patch
sys/dev/ic/vga_raster.c: revision 1.29 via patch
sys/dev/ic/vga.c: revision 1.95 via patch
sys/dev/rasops/rasops.c: revision 1.56 via patch
sys/dev/isa/ega.c: revision 1.23 via patch
Implement bounds checking in some places in display driver code to avoid
the possibility of a local user panic.
Set the 'ri' pointer before use.
 1.15.6.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.15.4.1 29-Apr-2005  kent sync with -current
 1.16.8.1 06-Aug-2007  ghen Pull up following revision(s) (requested by mjf in ticket #1815):
sys/dev/ic/pcdisplay_subr.c: revision 1.33 via patch
sys/dev/ic/vga_raster.c: revision 1.29 via patch
sys/dev/ic/vga.c: revision 1.95 via patch
sys/dev/rasops/rasops.c: revision 1.56 via patch
sys/dev/isa/ega.c: revision 1.23 via patch
Implement bounds checking in some places in display driver code to avoid
the possibility of a local user panic.
Set the 'ri' pointer before use.
 1.16.6.1 06-Aug-2007  ghen Pull up following revision(s) (requested by mjf in ticket #1815):
sys/dev/ic/pcdisplay_subr.c: revision 1.33 via patch
sys/dev/ic/vga_raster.c: revision 1.29 via patch
sys/dev/ic/vga.c: revision 1.95 via patch
sys/dev/rasops/rasops.c: revision 1.56 via patch
sys/dev/isa/ega.c: revision 1.23 via patch
Implement bounds checking in some places in display driver code to avoid
the possibility of a local user panic.
Set the 'ri' pointer before use.
 1.16.4.4 27-Oct-2007  yamt sync with head.
 1.16.4.3 03-Sep-2007  yamt sync with head.
 1.16.4.2 30-Dec-2006  yamt sync with head.
 1.16.4.1 21-Jun-2006  yamt sync with head.
 1.16.2.1 06-Aug-2007  ghen Pull up following revision(s) (requested by mjf in ticket #1815):
sys/dev/ic/pcdisplay_subr.c: revision 1.33 via patch
sys/dev/ic/vga_raster.c: revision 1.29 via patch
sys/dev/ic/vga.c: revision 1.95 via patch
sys/dev/rasops/rasops.c: revision 1.56 via patch
sys/dev/isa/ega.c: revision 1.23 via patch
Implement bounds checking in some places in display driver code to avoid
the possibility of a local user panic.
Set the 'ri' pointer before use.
 1.17.2.1 26-Oct-2005  yamt sync with head
 1.20.12.1 24-May-2006  tron Merge 2006-05-24 NetBSD-current into the "peter-altq" branch.
 1.20.10.2 11-May-2006  elad sync with head
 1.20.10.1 19-Apr-2006  elad sync with head.
 1.20.8.2 14-Sep-2006  yamt sync with head.
 1.20.8.1 24-May-2006  yamt sync with head.
 1.20.6.2 01-Jun-2006  kardel Sync with head.
 1.20.6.1 22-Apr-2006  simonb Sync with head.
 1.20.4.1 09-Sep-2006  rpaulo sync with head
 1.23.4.2 10-Dec-2006  yamt sync with head.
 1.23.4.1 22-Oct-2006  yamt sync with head
 1.23.2.1 18-Nov-2006  ad Sync with head.
 1.25.8.1 03-Sep-2007  wrstuden Sync w/ NetBSD-4-RC_1
 1.25.4.2 24-Mar-2007  yamt sync with head.
 1.25.4.1 12-Mar-2007  rmind Sync with HEAD.
 1.25.2.1 30-Jul-2007  liamjfoy Pull up following revision(s) (requested by mjf in ticket #799):
sys/dev/ic/pcdisplay_subr.c: revision 1.33
sys/dev/wscons/wsdisplay_vcons.c: revision 1.12
sys/dev/wscons/wsdisplay_vcons.c: revision 1.13
sys/dev/ic/vga_raster.c: revision 1.29
sys/dev/pci/chipsfb.c: revision 1.10
sys/dev/ic/vga.c: revision 1.95
sys/dev/rasops/rasops.c: revision 1.56
sys/dev/isa/ega.c: revision 1.23
Implement bounds checking in some places in display driver code to avoid
the possibility of a local user panic.
Set the 'ri' pointer before use.
 1.26.6.1 18-Mar-2007  reinoud First attempt to bring branch in sync with HEAD
 1.26.4.1 11-Jul-2007  mjf Sync with head.
 1.26.2.4 23-Oct-2007  ad Sync with head.
 1.26.2.3 20-Aug-2007  ad Sync with HEAD.
 1.26.2.2 01-Jul-2007  ad Adapt to callout API change.
 1.26.2.1 10-Apr-2007  ad Sync with head.
 1.28.2.1 15-Aug-2007  skrll Sync with HEAD.
 1.29.12.2 28-Jul-2007  mjf Implement bounds checking in some places in display driver code to avoid
the possibility of a local user panic.
 1.29.12.1 28-Jul-2007  mjf file vga_raster.c was added on branch matt-mips64 on 2007-07-28 20:28:58 +0000
 1.29.10.1 25-Oct-2007  bouyer Sync with HEAD.
 1.29.6.1 06-Nov-2007  matt sync with HEAD
 1.29.4.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.30.24.1 18-Jun-2008  simonb Sync with head.
 1.30.22.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.30.20.2 11-Aug-2010  yamt sync with head.
 1.30.20.1 04-May-2009  yamt sync with head.
 1.30.18.1 17-Jun-2008  yamt sync with head.
 1.30.16.2 17-Jan-2009  mjf Sync with HEAD.
 1.30.16.1 29-Jun-2008  mjf Sync with HEAD.
 1.31.2.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.33.16.1 30-May-2010  rmind sync with head
 1.33.14.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.34.12.1 18-Feb-2012  mrg merge to -current.
 1.34.8.3 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.34.8.2 23-Jan-2013  yamt sync with head
 1.34.8.1 17-Apr-2012  yamt sync with head
 1.35.6.4 03-Dec-2017  jdolecek update from HEAD
 1.35.6.3 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.35.6.2 23-Jun-2013  tls resync from head
 1.35.6.1 25-Feb-2013  tls resync with head
 1.37.8.1 10-Aug-2014  tls Rebase.
 1.37.4.1 18-May-2014  rmind sync with head
 1.41.2.1 14-Jan-2015  martin Pull up following revision(s) (requested by chs in ticket #418):
sys/dev/ic/vga.c: revision 1.113
sys/dev/ic/vga.c: revision 1.114
sys/dev/ic/vga_raster.c: revision 1.42
sys/dev/ic/vga_raster.c: revision 1.43
sys/dev/ic/vgavar.h: revision 1.31
sys/dev/ic/vgavar.h: revision 1.33
I've been unable to find any code that actually uses the mapping and we may
want to read the ROM from drm2.
If no users show up within a week or so I'll delete it.
remove BIOS-mapping code that was #if-0'd in the previous commit.
 1.42.2.1 06-Apr-2015  skrll Sync with HEAD
 1.44.18.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.44.18.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.47.2.1 25-Apr-2020  bouyer Sync with bouyer-xenpvh-base2 (HEAD)
 1.48.4.2 24-Apr-2021  thorpej Make sure to explcitly specify the "wsemuldisplaydev" interface attribute
when attaching the wscons display instance, because these devices can
also attach children using the "drm" interface attribute.
 1.48.4.1 21-Mar-2021  thorpej Give config_found() the same variadic arguments treatment as
config_search(). This commit only adds the CFARG_EOL sentinel
to the existing config_found() calls. Conversion of config_found_sm_loc()
and config_found_ia() call sites will be in subsequent commits.
 1.49.8.1 04-Aug-2021  thorpej Adapt to CFARGS().
 1.26 06-May-2023  andvar s/regster/register/ in comments and error messages.
 1.25 09-Aug-2012  uwe Use vga_raw_read/vga_raw_write instead of spelling bus space ops explicitly.
Same object code is produced.
 1.24 02-Feb-2009  tsutsui branches: 1.24.14;
- u_int8_t -> uint8_t
- use ANSI function decls
 1.23 09-Dec-2007  jmcneill branches: 1.23.14; 1.23.22;
Merge jmcneill-pm branch.
 1.22 19-Oct-2007  ad branches: 1.22.4; 1.22.6;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.21 19-Jul-2007  dsl branches: 1.21.4; 1.21.6; 1.21.10; 1.21.12;
include sys/cdefs.h before opt_xxx.h
 1.20 11-Dec-2005  christos branches: 1.20.30; 1.20.40;
merge ktrace-lwp.
 1.19 27-Dec-2004  tsutsui branches: 1.19.10;
Fix typo in comment.
 1.18 29-Jul-2004  jmmv Implement border color customization in wscons(4), only available for vga(4)
at the moment.

This includes the addition of two new wsdisplay ioctls, WSDISPLAY_{G,S}BORDER,
one to get the actual color and one to set it, respectively. Possible colors
match those defined by ANSI (and listed in wsdisplayvar.h).

It also adds two accessops to the underlying graphics device, getborder and
setborder, which mach their ioctl counterparts.

Two kernel options are added: WSDISPLAY_CUSTOM_BORDER, which enables the
ioctls described above (to customize the border color from userland after
boot), and WSDISPLAY_BORDER_COLOR, which sets the color at boot time.
The former is enabled by default on the GENERIC kernel, but not on INSTALL
(among others). The later is always commented out, leaving the usual black
border as a default.

wsconsctl is modified to allow accessing this value easily. For example,
'wsconsctl -d -w border=blue'.
 1.17 24-Mar-2004  drochner remove license clauses 3 and 4 from my cpoyright notices
 1.16 13-Feb-2004  wiz Uppercase CPU, plural is CPUs.
 1.15 09-Feb-2003  jdolecek branches: 1.15.2;
make 'name' and 'data' of struct wsdisplay_font const, mark data arrays
in font sources const
 1.14 31-Jan-2003  tsutsui Changes to allow machines which don't use text mode at the boot time
to use generic VGA driver(s):
- Allow VGA drivers to use wsfont instead of builtin font.
- Add vga_reset() function, which will be called from MD consinit(),
to put VGA into text mode. This function is enabled by options VGA_RESET.
 1.13 27-Jan-2003  tsutsui const'ify.
 1.12 27-Jan-2003  tsutsui KNF and space/TAB cleanup.
 1.11 15-Oct-2002  junyoung Add VGA raster graphics console driver. It is written as an extension
to char-cell based vga(4) driver, and fully compatible with existing
apps like XFree86. Currently it supports 80x25, 80x30, 80x40 and 80x50
text modes using emulation. You can enable it by specifying `options
VGA_RASTERCONSOLE' in your kernel config file.

Note that displaying multilingual text doesn't work yet. Necessary
code is already there, but userland stuff and some functionality isn't
ready for prime time yet. I'm working on them.
 1.10 28-Jun-2002  drochner clean up font handling:
-treat the builtin font like any other font at runtime
-for that, copy it to malloc()'d memory during attach()
-in early console initialization, if we have to consider a broken card
(VGA_CONSOLE_ATI_BROKEN_FONTSEL), copy the builtin font to another
location in font ram; the attach() code will do the rest
put the "quirk" code into effect again
 1.9 27-Jun-2002  junyoung - Work around a hardware bug that loaded fonts don't work, which is
found on many (all?) of PCI-based ATI graphics cards. It is fully optional
and can be enabled by adding `options VGA_CONSOLE_ATI_BROKEN_FONTSEL'
to config file.
- Temporarily remove `quirk' mechanism. Similar code already exists
in pci_quirks.c.
 1.8 13-Dec-2001  junyoung branches: 1.8.8;
ANSIfy.
 1.7 13-Nov-2001  lukem add/cleanup RCSID
 1.6 25-Jan-2000  ad branches: 1.6.6; 1.6.8;
Finish with fixing the SOFTCURSOR stuff.
 1.5 19-Sep-1999  ad branches: 1.5.2;
- mc6845's cursor is disabled by punching bit 6 of cursor start register.
- Add new option (PCDISPLAY_SOFTCURSOR) that provides a large, non-blinking
cursor in software.
 1.4 17-Aug-1999  drochner correct a comment
 1.3 13-Jan-1999  drochner -implement new wscons font handling with separate download and selection
calls
-support use of 2 fonts simultanously; this costs the ability to
"highlight", ie to use the upper 8 colours
-define screen types "80x25bf" and "80x50bf" which use this ability
-add conditional code to deal with the weird mapping of pcvt's
supplemental fonts
 1.2 28-May-1998  drochner Put definitions and subroutines needed for all PC display adapters
(MGA/GCA and compatibles) into global headers / source files.
Let the VGA driver use them.
 1.1 22-Mar-1998  drochner initial import of VGA driver backend for use with the new wscons code
 1.5.2.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.6.8.2 06-Sep-2002  jdolecek sync kqueue branch with HEAD
 1.6.8.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.6.6.4 18-Oct-2002  nathanw Catch up to -current.
 1.6.6.3 01-Aug-2002  nathanw Catch up to -current.
 1.6.6.2 08-Jan-2002  nathanw Catch up to -current.
 1.6.6.1 14-Nov-2001  nathanw Catch up to -current.
 1.8.8.1 15-Jul-2002  gehenna catch up with -current.
 1.15.2.4 17-Jan-2005  skrll Sync with HEAD.
 1.15.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.15.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.15.2.1 03-Aug-2004  skrll Sync with HEAD
 1.19.10.3 21-Jan-2008  yamt sync with head
 1.19.10.2 27-Oct-2007  yamt sync with head.
 1.19.10.1 03-Sep-2007  yamt sync with head.
 1.20.40.1 15-Aug-2007  skrll Sync with HEAD.
 1.20.30.2 23-Oct-2007  ad Sync with head.
 1.20.30.1 12-Oct-2007  ad Fix merge errors.
 1.21.12.2 19-Jul-2007  dsl include sys/cdefs.h before opt_xxx.h
 1.21.12.1 19-Jul-2007  dsl file vga_subr.c was added on branch matt-mips64 on 2007-07-19 22:24:08 +0000
 1.21.10.1 25-Oct-2007  bouyer Sync with HEAD.
 1.21.6.2 09-Jan-2008  matt sync with HEAD
 1.21.6.1 06-Nov-2007  matt sync with HEAD
 1.21.4.2 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.21.4.1 03-Aug-2007  jmcneill Pull in power management changes from private branch.
 1.22.6.1 11-Dec-2007  yamt sync with head.
 1.22.4.1 26-Dec-2007  ad Sync with head.
 1.23.22.1 03-Mar-2009  skrll Sync with HEAD.
 1.23.14.1 04-May-2009  yamt sync with head.
 1.24.14.1 30-Oct-2012  yamt sync with head
 1.9 11-Dec-2005  christos merge ktrace-lwp.
 1.8 29-Jul-2004  jmmv Implement border color customization in wscons(4), only available for vga(4)
at the moment.

This includes the addition of two new wsdisplay ioctls, WSDISPLAY_{G,S}BORDER,
one to get the actual color and one to set it, respectively. Possible colors
match those defined by ANSI (and listed in wsdisplayvar.h).

It also adds two accessops to the underlying graphics device, getborder and
setborder, which mach their ioctl counterparts.

Two kernel options are added: WSDISPLAY_CUSTOM_BORDER, which enables the
ioctls described above (to customize the border color from userland after
boot), and WSDISPLAY_BORDER_COLOR, which sets the color at boot time.
The former is enabled by default on the GENERIC kernel, but not on INSTALL
(among others). The later is always commented out, leaving the usual black
border as a default.

wsconsctl is modified to allow accessing this value easily. For example,
'wsconsctl -d -w border=blue'.
 1.7 24-Mar-2004  drochner remove license clauses 3 and 4 from my cpoyright notices
 1.6 31-Jan-2003  tsutsui branches: 1.6.2;
Changes to allow machines which don't use text mode at the boot time
to use generic VGA driver(s):
- Allow VGA drivers to use wsfont instead of builtin font.
- Add vga_reset() function, which will be called from MD consinit(),
to put VGA into text mode. This function is enabled by options VGA_RESET.
 1.5 27-Jan-2003  tsutsui - Replace some magic numbers with proper macro.
- Use vga_6845_{read,write}() defined in pcdisplayvar.h and
remove vga_crtc_{read,write}() macros in vgareg.h.
 1.4 30-Dec-2001  junyoung Registers are of u_int8_t type.
 1.3 29-Dec-2001  junyoung - Add a structure needed for access to CRTC registers.
- Add definitions for misc output register.
- Add defintions for the number of registers.
 1.2 28-May-1998  drochner branches: 1.2.26; 1.2.28;
Put definitions and subroutines needed for all PC display adapters
(MGA/GCA and compatibles) into global headers / source files.
Let the VGA driver use them.
 1.1 22-Mar-1998  drochner initial import of VGA driver backend for use with the new wscons code
 1.2.28.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.2.26.1 08-Jan-2002  nathanw Catch up to -current.
 1.6.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.6.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.6.2.1 03-Aug-2004  skrll Sync with HEAD
 1.33 14-Jan-2015  chs remove BIOS-mapping code that was #if-0'd in the previous commit.
 1.32 12-Nov-2014  christos branches: 1.32.2;
more _KERNEL_OPT
 1.31 21-Aug-2014  macallan #if 0 code to map the VGA BIOS
I've been unable to find any code that actually uses the mapping and we may
want to read the ROM from drm2.
If no users show up within a week or so I'll delete it.
 1.30 21-Jan-2013  mlelstv branches: 1.30.12;
Make internal functions static
 1.29 09-Dec-2010  christos branches: 1.29.8; 1.29.18;
PR/41415: IdOp: Implement save and restore palette for vga.
 1.28 14-Mar-2008  cube branches: 1.28.26;
Split device_t and softc for all attachments of vga(4).
 1.27 09-Dec-2007  jmcneill branches: 1.27.6; 1.27.10;
Merge jmcneill-pm branch.
 1.26 04-Mar-2007  christos branches: 1.26.14; 1.26.16; 1.26.24; 1.26.26;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.25 13-Aug-2006  jmcneill branches: 1.25.8;
Provide a method for other display drivers to ask vga to free resources
it had claimed while acting as the initial console device. This allows
(for example) vga to be the initial console, and an accelerated
framebuffer driver to take over later.
 1.24 16-Feb-2006  perry branches: 1.24.2;
Change "inline" back to "__inline" in .h files -- C99 is still too
new, and some apps compile things in C89 mode. C89 keywords stay.

As per core@.
 1.23 11-Dec-2005  christos branches: 1.23.2; 1.23.4; 1.23.6;
merge ktrace-lwp.
 1.22 27-Feb-2005  perry branches: 1.22.4;
nuke trailing whitespace
 1.21 29-Jun-2003  fvdl branches: 1.21.2; 1.21.10; 1.21.12;
Back out the lwp/ktrace changes. They contained a lot of colateral damage,
and need to be examined and discussed more.
 1.20 28-Jun-2003  darrenr Pass lwp pointers throughtout the kernel, as required, so that the lwpid can
be inserted into ktrace records. The general change has been to replace
"struct proc *" with "struct lwp *" in various function prototypes, pass
the lwp through and use l_proc to get the process pointer when needed.

Bump the kernel rev up to 1.6V
 1.19 09-Feb-2003  jdolecek make 'name' and 'data' of struct wsdisplay_font const, mark data arrays
in font sources const
 1.18 31-Jan-2003  tsutsui Changes to allow machines which don't use text mode at the boot time
to use generic VGA driver(s):
- Allow VGA drivers to use wsfont instead of builtin font.
- Add vga_reset() function, which will be called from MD consinit(),
to put VGA into text mode. This function is enabled by options VGA_RESET.
 1.17 27-Jan-2003  tsutsui - Replace some magic numbers with proper macro.
- Use vga_6845_{read,write}() defined in pcdisplayvar.h and
remove vga_crtc_{read,write}() macros in vgareg.h.
 1.16 27-Jan-2003  tsutsui KNF and space/TAB cleanup.
 1.15 15-Oct-2002  junyoung Add VGA raster graphics console driver. It is written as an extension
to char-cell based vga(4) driver, and fully compatible with existing
apps like XFree86. Currently it supports 80x25, 80x30, 80x40 and 80x50
text modes using emulation. You can enable it by specifying `options
VGA_RASTERCONSOLE' in your kernel config file.

Note that displaying multilingual text doesn't work yet. Necessary
code is already there, but userland stuff and some functionality isn't
ready for prime time yet. I'm working on them.
 1.14 08-Jul-2002  drochner save the "quirks" in the softc
 1.13 28-Jun-2002  drochner clean up font handling:
-treat the builtin font like any other font at runtime
-for that, copy it to malloc()'d memory during attach()
-in early console initialization, if we have to consider a broken card
(VGA_CONSOLE_ATI_BROKEN_FONTSEL), copy the builtin font to another
location in font ram; the attach() code will do the rest
put the "quirk" code into effect again
 1.12 27-Jun-2002  junyoung - Work around a hardware bug that loaded fonts don't work, which is
found on many (all?) of PCI-based ATI graphics cards. It is fully optional
and can be enabled by adding `options VGA_CONSOLE_ATI_BROKEN_FONTSEL'
to config file.
- Temporarily remove `quirk' mechanism. Similar code already exists
in pci_quirks.c.
 1.11 25-Jun-2002  drochner allow to overwrite the builtin VGA font if necessary,
make the number of available font slots variable,
set up a "quirk" mechanism to tell the generic vga code about crippled
VGA adapters which ignore the "fontsel" TS register,
initiate the quirk table with an ATI chip which happened to be on a board
I tested with.
Afaik quite a number of ATI chips suffers from the "loaded fonts don't
work" problem - these should be added.
Bad side effect of my change: The builtin font will be kicked out
always if a VGA_CONSOLE_SCREENTYPE is specified which needs a loaded
font. In early console initialization, we don't know much about the
graphics card, so we have to assume the worst (ie ATI:-).
 1.10 29-Dec-2001  junyoung branches: 1.10.8;
Add functions needed for access to CRTC registers.
 1.9 29-Dec-2001  junyoung KNF.
 1.8 13-Dec-2001  junyoung ANSIfication & cosmetic changes.
 1.7 14-Sep-2001  thorpej Allow bus front-end to provide both ioctl and mmap entry points,
and also the wsdisplay type.

Based on changes from Simon Burge <simonb@wasabisystems.com>.
 1.6 14-Aug-2000  thorpej branches: 1.6.2; 1.6.4; 1.6.6;
Just add the mmap argument to vga_common_attach(), don't bother
with vga_extended_attach().
 1.5 08-Aug-2000  jeffs Update arc map routine prototype to compile again.
 1.4 17-Jun-2000  soda branches: 1.4.2;
add vga_extended_attach function on arc port, to make mmap() available.
XXX - is it better to remove "#ifdef arc"?
 1.3 13-Jan-1999  drochner branches: 1.3.8; 1.3.16;
-implement new wscons font handling with separate download and selection
calls
-support use of 2 fonts simultanously; this costs the ability to
"highlight", ie to use the upper 8 colours
-define screen types "80x25bf" and "80x50bf" which use this ability
-add conditional code to deal with the weird mapping of pcvt's
supplemental fonts
 1.2 28-May-1998  drochner Put definitions and subroutines needed for all PC display adapters
(MGA/GCA and compatibles) into global headers / source files.
Let the VGA driver use them.
 1.1 22-Mar-1998  drochner initial import of VGA driver backend for use with the new wscons code
 1.3.16.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.3.8.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.4.2.1 08-Aug-2000  jeffs Pull up revision 1.5 (approved by thorpej):
Fix compile problems with paddr_t for arc.
 1.6.6.1 01-Oct-2001  fvdl Catch up with -current.
 1.6.4.2 06-Sep-2002  jdolecek sync kqueue branch with HEAD
 1.6.4.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.6.2.4 18-Oct-2002  nathanw Catch up to -current.
 1.6.2.3 01-Aug-2002  nathanw Catch up to -current.
 1.6.2.2 08-Jan-2002  nathanw Catch up to -current.
 1.6.2.1 21-Sep-2001  nathanw Catch up to -current.
 1.10.8.1 15-Jul-2002  gehenna catch up with -current.
 1.21.12.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.21.10.1 29-Apr-2005  kent sync with -current
 1.21.2.4 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.21.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.21.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.21.2.1 02-Jul-2003  darrenr Apply the aborted ktrace-lwp changes to a specific branch. This is just for
others to review, I'm concerned that patch fuziness may have resulted in some
errant code being generated but I'll look at that later by comparing the diff
from the base to the branch with the file I attempt to apply to it. This will,
at the very least, put the changes in a better context for others to review
them and attempt to tinker with removing passing of 'struct lwp' through
the kernel.
 1.22.4.5 17-Mar-2008  yamt sync with head.
 1.22.4.4 21-Jan-2008  yamt sync with head
 1.22.4.3 03-Sep-2007  yamt sync with head.
 1.22.4.2 30-Dec-2006  yamt sync with head.
 1.22.4.1 21-Jun-2006  yamt sync with head.
 1.23.6.1 22-Apr-2006  simonb Sync with head.
 1.23.4.1 09-Sep-2006  rpaulo sync with head
 1.23.2.1 18-Feb-2006  yamt sync with head.
 1.24.2.1 03-Sep-2006  yamt sync with head.
 1.25.8.1 12-Mar-2007  rmind Sync with HEAD.
 1.26.26.1 11-Dec-2007  yamt sync with head.
 1.26.24.1 26-Dec-2007  ad Sync with head.
 1.26.16.2 23-Mar-2008  matt sync with HEAD
 1.26.16.1 09-Jan-2008  matt sync with HEAD
 1.26.14.2 01-Oct-2007  joerg Extend device API by device_power_private and device_power_set_private.
The latter is a temporary mean until the pnp_register API itself is
overhault. This functions allow a generic power handler to store its
state independent of the driver.

Use this and revamp the PCI power handling. Pretty much all PCI devices
had power handlers that did the same thing, generalize this in
pci_generic_power_register/deregister and the handler. This interface
offers callbacks for the drivers to save and restore state on
transistions. After a long discussion with jmcneill@ it was considered
to be powerful enough until evidence is shown that devices can handle
D1/D2 with less code and higher speed than without the full
save/restore. The generic code is carefully written to handle device
without PCI-PM support and ensure that the correct registers are written
to when D3 loses all state.

Reimplement the generic PCI network device handling on
top of PCI generic power handling.

Introduce pci_disable_retry as used and implemented locally at least by
ath(4) and iwi(4). Use it in this drivers to restore behaviour from
before the introduction of generic PCI network handling.

Convert all PCI drivers that were using pnp_register to the new
framework. The only exception is vga(4) as it is commonly used as
console device. Add a note therein that this should be fixed later.
 1.26.14.1 03-Aug-2007  jmcneill Pull in power management changes from private branch.
 1.27.10.1 03-Apr-2008  mjf Sync with HEAD.
 1.27.6.1 24-Mar-2008  keiichi sync with head.
 1.28.26.1 05-Mar-2011  rmind sync with head
 1.29.18.2 03-Dec-2017  jdolecek update from HEAD
 1.29.18.1 25-Feb-2013  tls resync with head
 1.29.8.1 23-Jan-2013  yamt sync with head
 1.30.12.2 14-Jan-2015  martin Pull up following revision(s) (requested by chs in ticket #418):
sys/dev/ic/vga.c: revision 1.113
sys/dev/ic/vga.c: revision 1.114
sys/dev/ic/vga_raster.c: revision 1.42
sys/dev/ic/vga_raster.c: revision 1.43
sys/dev/ic/vgavar.h: revision 1.31
sys/dev/ic/vgavar.h: revision 1.33
I've been unable to find any code that actually uses the mapping and we may
want to read the ROM from drm2.
If no users show up within a week or so I'll delete it.
remove BIOS-mapping code that was #if-0'd in the previous commit.
 1.30.12.1 11-Jan-2015  snj Pull up following revision(s) (requested by chs in ticket #401):
distrib/sets/lists/modules/md.amd64: revisions 1.46, 1.47 via patch
distrib/sets/lists/modules/md.i386: revisions 1.49, 1.50
sys/dev/ic/pcdisplayvar.h: revision 1.20
sys/dev/ic/vgavar.h: revision 1.32
sys/external/bsd/drm/dist/bsd-core/drm_drv.c: revision 1.26
sys/external/bsd/drm2/dist/drm/drm_agpsupport.c: revisions 1.5, 1.6
sys/external/bsd/drm2/dist/drm/drm_pci.c: revisions 1.4, 1.5
sys/external/bsd/drm2/dist/drm/drm_stub.c: revisions 1.6-1.8
sys/external/bsd/drm2/dist/drm/i915/i915_drv.h: revision 1.11
sys/external/bsd/drm2/dist/drm/radeon/cik.c: revision 1.3
sys/external/bsd/drm2/dist/drm/radeon/ni.c: revision 1.3
sys/external/bsd/drm2/dist/drm/radeon/si.c: revision 1.3
sys/external/bsd/drm2/dist/include/drm/drmP.h: revisions 1.8, 1.9
sys/external/bsd/drm2/dist/include/drm/drm_agpsupport.h: revisions 1.3, 1.4
sys/external/bsd/drm2/drm/drm_drv.c: revision 1.11
sys/external/bsd/drm2/drm/drm_module.c: revision 1.9
sys/external/bsd/drm2/drm/drm_sysctl.c: revisions 1.1-1.4
sys/external/bsd/drm2/drm/drm_vm.c: revision 1.7
sys/external/bsd/drm2/drm/files.drmkms: revisions 1.8, 1.9
sys/external/bsd/drm2/i915drm/files.i915drmkms: revision 1.9
sys/external/bsd/drm2/i915drm/i915_module.c: revisions 1.4, 1.5
sys/external/bsd/drm2/include/drm/drm_sysctl.h: revisions 1.1, 1.2
sys/external/bsd/drm2/include/linux/hdmi.h: revisions 1.3-1.5
sys/external/bsd/drm2/include/linux/module.h: revision 1.5
sys/external/bsd/drm2/include/linux/moduleparam.h: revisions 1.3, 1.4
sys/external/bsd/drm2/include/linux/pci.h: revision 1.11
sys/external/bsd/drm2/linux/linux_module.c: revision 1.5
sys/external/bsd/drm2/nouveau/files.nouveau: revision 1.4
sys/external/bsd/drm2/nouveau/nouveau_module.c: revision 1.3
sys/external/bsd/drm2/pci/drm_pci.c: revision 1.8
sys/external/bsd/drm2/pci/drm_pci_module.c: revision 1.3
sys/external/bsd/drm2/radeon/radeon_module.c: revision 1.3
sys/external/bsd/drm2/ttm/files.ttm: revision 1.1
sys/modules/drm2pci/Makefile: file removal
sys/modules/drmkms/Makefile: revisions 1.4-1.7
sys/modules/drmkms_linux/Makefile: revision 1.5
sys/modules/drmkms_pci/Makefile: revisions 1.3, 1.4
sys/modules/i915drmkms/Makefile: revisions 1.5-1.7
Split drm ttm config into a separate file.
--
Fix module build of drmkms_linux.
--
Remove vestigial drm2pci module, replaced by drmkms_pci.
--
fix the module class.
--
add the drmkms modules
--
make a drm_agp_destroy() function to resolve the circular dependency between
drmkms and drmkms_pci
--
finalize the idr code.
--
add drm_agp_destroy
--
fix drmkms module path for xen.
--
fix build failure.
/tmp/bracket/build/2014.11.10.22.43.46-i386/src/sys/external/bsd/drm2/include/linux/pci.h:36:20: fatal error: acpica.h: No such file or directory
--
make this work: add agpsupport and sysctl code
--
move agpsupport to drmkms to avoid circular dependencies.
--
turn on dynamic ldscript creation to handle link set symbol definitions
used in the automatic sysctl creation.
--
Add __link_set based code to automatically convert the linux module parameters
into sysctls.
--
this module needs MKLDSCRIPT too now
--
more _KERNEL_OPT
--
prettify and add to all the modules that have it.
--
fix description setting.
--
Adjust flags to allow building with clang.
--
Fix build with clang.
--
Drop casts in favour of expressions that actually give the right
pointer.
--
Move all PCI/AGP code back to drmkms_pci module where it belongs.
--
Use correct length for hdmi_infoframe_header_pack in <linux/hdmi.h>.
Fixes PR kern/49411.
--
Back out previous, fix PR kern/49411 correctly.
frame->header.length is not initialized in the vendor packet case.
Instead, make hdmi_infoframe_header_pack take the packet length and
subtract the size of the header when packing the header.
(Could make it take the payload length instead, but for callers it is
more convenient to have a name for the whole packet length.)
--
Fix bounds checking in hdmi_infoframe_header_pack (PR kern/49411).
--
Trivial build fix for no options SYSCTL_INCLUDE_DESCR case, to
avoid -Werror.
OK christos@ and riastradh@
--
fix debugging compilation (ALL kernel)
--
nouveau_nv50_fence.c needs -Wno-shadow.
--
fix a confusion between dev_t and devmajor_t, and include the primary
minor when calling makedev().
 1.32.2.1 06-Apr-2015  skrll Sync with HEAD
 1.5 24-Mar-2010  tnn sys/dev/ic/videomode.h is almost identical to sys/dev/videomode/videomode.h
Remove the former.
 1.4 11-Dec-2005  christos branches: 1.4.74; 1.4.96; 1.4.98;
merge ktrace-lwp.
 1.3 27-Feb-2005  perry nuke trailing whitespace
 1.2 04-Nov-2002  junyoung branches: 1.2.6; 1.2.14; 1.2.16;
Missing '.'
 1.1 15-Oct-2002  junyoung branches: 1.1.2;
Add VGA raster graphics console driver. It is written as an extension
to char-cell based vga(4) driver, and fully compatible with existing
apps like XFree86. Currently it supports 80x25, 80x30, 80x40 and 80x50
text modes using emulation. You can enable it by specifying `options
VGA_RASTERCONSOLE' in your kernel config file.

Note that displaying multilingual text doesn't work yet. Necessary
code is already there, but userland stuff and some functionality isn't
ready for prime time yet. I'm working on them.
 1.1.2.3 11-Nov-2002  nathanw Catch up to -current
 1.1.2.2 18-Oct-2002  nathanw Catch up to -current.
 1.1.2.1 15-Oct-2002  nathanw file videomode.h was added on branch nathanw_sa on 2002-10-18 02:42:02 +0000
 1.2.16.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.2.14.1 29-Apr-2005  kent sync with -current
 1.2.6.1 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.4.98.1 30-May-2010  rmind sync with head
 1.4.96.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.4.74.1 11-Aug-2010  yamt sync with head.
 1.3 11-May-2020  jdc Make the driver endian-independent.
Add a quirk so that the bus front end can specify 1-bit only mode.
Remove unused isa includes.
Change the error returned for unsupported opcodes to ENOTSUP, so that
we can pass this back to sdmmc_mem, where it's handled since r1.72 of
src/sys/dev/sdmmc/sdmmc_mem.c
 1.2 19-Aug-2010  jmcneill add suspend/resume support
 1.1 30-Sep-2009  jmcneill branches: 1.1.2; 1.1.4; 1.1.6; 1.1.8; 1.1.10;
Initial import of an SD/MMC driver for the Winbond W83L518D (and probably
W83L519D) Integrated Media Reader with PNP bus attachment glue.
 1.1.10.2 21-Apr-2010  matt sync to netbsd-5
 1.1.10.1 30-Sep-2009  matt file w83l518d.c was added on branch matt-nb5-mips64 on 2010-04-21 00:27:37 +0000
 1.1.8.1 05-Mar-2011  rmind sync with head
 1.1.6.3 09-Oct-2010  yamt sync with head
 1.1.6.2 11-Mar-2010  yamt sync with head
 1.1.6.1 30-Sep-2009  yamt file w83l518d.c was added on branch yamt-nfs-mp on 2010-03-11 15:03:36 +0000
 1.1.4.1 22-Oct-2010  uebayasi Sync with HEAD (-D20101022).
 1.1.2.3 21-Nov-2010  riz Pull up following revision(s) (requested by jmcneill in ticket #1462):
sys/dev/acpi/wb_acpi.c: revision 1.3
sys/dev/ic/w83l518d_sdmmc.c: revision 1.2
sys/dev/ic/w83l518d_sdmmc.h: revision 1.2
sys/dev/ic/w83l518d.c: revision 1.2
sys/dev/ic/w83l518dvar.h: revision 1.2
add suspend/resume support
add pmf support
 1.1.2.2 08-Oct-2009  sborrill Pull up the following revisions(s) (requested by jmcneill in ticket #1045):
distrib/sets/lists/man/mi: revision 1.1160
share/man/man4/Makefile: revision 1.499
share/man/man4/wb.4: revision 1.1-1.2
share/man/man4/ld.4: revision 1.17
sys/arch/i386/conf/ALL: revision 1.215-1.216 + patch
sys/arch/i386/conf/GENERIC: revision 1.946-1.947 + patch
sys/arch/amd64/conf/GENERIC: revision 1.254-1.256 + patch
sys/conf/files: revision 1.958
sys/dev/acpi/files.acpi: revision 1.59
sys/dev/acpi/wb_acpi.c: revision 1.1
sys/dev/ic/w83l518d.c: revision 1.1
sys/dev/ic/w83l518d_sdmmc.c: revision 1.1
sys/dev/ic/w83l518d_sdmmc.h: revision 1.1
sys/dev/ic/w83l518dreg.h: revision 1.1
sys/dev/ic/w83l518dvar.h.c: revision 1.1

wb(4): Add a driver for Winbond W83L518D SD/MMC readers.
 1.1.2.1 30-Sep-2009  sborrill file w83l518d.c was added on branch netbsd-5 on 2009-10-08 09:47:09 +0000
 1.7 10-May-2023  riastradh wb(4): Use config_detach_children.
 1.6 07-Aug-2021  thorpej Merge thorpej-cfargs2.
 1.5 24-Apr-2021  thorpej branches: 1.5.8;
Merge thorpej-cfargs branch:

Simplify and make extensible the config_search() / config_found() /
config_attach() interfaces: rather than having different variants for
which arguments you want pass along, just have a single call that
takes a variadic list of tag-value arguments.

Adjust all call sites:
- Simplify wherever possible; don't pass along arguments that aren't
actually needed.
- Don't be explicit about what interface attribute is attaching if
the device only has one. (More simplification.)
- Add a config_probe() function to be used in indirect configuiration
situations, making is visibly easier to see when indirect config is
in play, and allowing for future change in semantics. (As of now,
this is just a wrapper around config_match(), but that is an
implementation detail.)

Remove unnecessary or redundant interface attributes where they're not
needed.

There are currently 5 "cfargs" defined:
- CFARG_SUBMATCH (submatch function for direct config)
- CFARG_SEARCH (search function for indirect config)
- CFARG_IATTR (interface attribte)
- CFARG_LOCATORS (locators array)
- CFARG_DEVHANDLE (devhandle_t - wraps OFW, ACPI, etc. handles)

...and a sentinel value CFARG_EOL.

Add some extra sanity checking to ensure that interface attributes
aren't ambiguous.

Use CFARG_DEVHANDLE in MI FDT, OFW, and ACPI code, and macppc and shark
ports to associate those device handles with device_t instance. This
will trickle trough to more places over time (need back-end for pre-OFW
Sun OBP; any others?).
 1.4 11-May-2020  jdc branches: 1.4.4;
Make the driver endian-independent.
Add a quirk so that the bus front end can specify 1-bit only mode.
Remove unused isa includes.
Change the error returned for unsupported opcodes to ENOTSUP, so that
we can pass this back to sdmmc_mem, where it's handled since r1.72 of
src/sys/dev/sdmmc/sdmmc_mem.c
 1.3 07-Oct-2010  kiyohara Support change Open-drain/Push-pull by bus_rod().
 1.2 19-Aug-2010  jmcneill add suspend/resume support
 1.1 30-Sep-2009  jmcneill branches: 1.1.2; 1.1.4; 1.1.6; 1.1.8; 1.1.10;
Initial import of an SD/MMC driver for the Winbond W83L518D (and probably
W83L519D) Integrated Media Reader with PNP bus attachment glue.
 1.1.10.2 21-Apr-2010  matt sync to netbsd-5
 1.1.10.1 30-Sep-2009  matt file w83l518d_sdmmc.c was added on branch matt-nb5-mips64 on 2010-04-21 00:27:37 +0000
 1.1.8.1 05-Mar-2011  rmind sync with head
 1.1.6.3 09-Oct-2010  yamt sync with head
 1.1.6.2 11-Mar-2010  yamt sync with head
 1.1.6.1 30-Sep-2009  yamt file w83l518d_sdmmc.c was added on branch yamt-nfs-mp on 2010-03-11 15:03:36 +0000
 1.1.4.1 22-Oct-2010  uebayasi Sync with HEAD (-D20101022).
 1.1.2.3 21-Nov-2010  riz Pull up following revision(s) (requested by jmcneill in ticket #1462):
sys/dev/acpi/wb_acpi.c: revision 1.3
sys/dev/ic/w83l518d_sdmmc.c: revision 1.2
sys/dev/ic/w83l518d_sdmmc.h: revision 1.2
sys/dev/ic/w83l518d.c: revision 1.2
sys/dev/ic/w83l518dvar.h: revision 1.2
add suspend/resume support
add pmf support
 1.1.2.2 08-Oct-2009  sborrill Pull up the following revisions(s) (requested by jmcneill in ticket #1045):
distrib/sets/lists/man/mi: revision 1.1160
share/man/man4/Makefile: revision 1.499
share/man/man4/wb.4: revision 1.1-1.2
share/man/man4/ld.4: revision 1.17
sys/arch/i386/conf/ALL: revision 1.215-1.216 + patch
sys/arch/i386/conf/GENERIC: revision 1.946-1.947 + patch
sys/arch/amd64/conf/GENERIC: revision 1.254-1.256 + patch
sys/conf/files: revision 1.958
sys/dev/acpi/files.acpi: revision 1.59
sys/dev/acpi/wb_acpi.c: revision 1.1
sys/dev/ic/w83l518d.c: revision 1.1
sys/dev/ic/w83l518d_sdmmc.c: revision 1.1
sys/dev/ic/w83l518d_sdmmc.h: revision 1.1
sys/dev/ic/w83l518dreg.h: revision 1.1
sys/dev/ic/w83l518dvar.h.c: revision 1.1

wb(4): Add a driver for Winbond W83L518D SD/MMC readers.
 1.1.2.1 30-Sep-2009  sborrill file w83l518d_sdmmc.c was added on branch netbsd-5 on 2009-10-08 09:47:09 +0000
 1.4.4.1 21-Mar-2021  thorpej Give config_found() the same variadic arguments treatment as
config_search(). This commit only adds the CFARG_EOL sentinel
to the existing config_found() calls. Conversion of config_found_sm_loc()
and config_found_ia() call sites will be in subsequent commits.
 1.5.8.1 04-Aug-2021  thorpej Adapt to CFARGS().
 1.2 19-Aug-2010  jmcneill add suspend/resume support
 1.1 30-Sep-2009  jmcneill branches: 1.1.2; 1.1.4; 1.1.6; 1.1.8; 1.1.10;
Initial import of an SD/MMC driver for the Winbond W83L518D (and probably
W83L519D) Integrated Media Reader with PNP bus attachment glue.
 1.1.10.2 21-Apr-2010  matt sync to netbsd-5
 1.1.10.1 30-Sep-2009  matt file w83l518d_sdmmc.h was added on branch matt-nb5-mips64 on 2010-04-21 00:27:37 +0000
 1.1.8.1 05-Mar-2011  rmind sync with head
 1.1.6.3 09-Oct-2010  yamt sync with head
 1.1.6.2 11-Mar-2010  yamt sync with head
 1.1.6.1 30-Sep-2009  yamt file w83l518d_sdmmc.h was added on branch yamt-nfs-mp on 2010-03-11 15:03:36 +0000
 1.1.4.1 22-Oct-2010  uebayasi Sync with HEAD (-D20101022).
 1.1.2.3 21-Nov-2010  riz Pull up following revision(s) (requested by jmcneill in ticket #1462):
sys/dev/acpi/wb_acpi.c: revision 1.3
sys/dev/ic/w83l518d_sdmmc.c: revision 1.2
sys/dev/ic/w83l518d_sdmmc.h: revision 1.2
sys/dev/ic/w83l518d.c: revision 1.2
sys/dev/ic/w83l518dvar.h: revision 1.2
add suspend/resume support
add pmf support
 1.1.2.2 08-Oct-2009  sborrill Pull up the following revisions(s) (requested by jmcneill in ticket #1045):
distrib/sets/lists/man/mi: revision 1.1160
share/man/man4/Makefile: revision 1.499
share/man/man4/wb.4: revision 1.1-1.2
share/man/man4/ld.4: revision 1.17
sys/arch/i386/conf/ALL: revision 1.215-1.216 + patch
sys/arch/i386/conf/GENERIC: revision 1.946-1.947 + patch
sys/arch/amd64/conf/GENERIC: revision 1.254-1.256 + patch
sys/conf/files: revision 1.958
sys/dev/acpi/files.acpi: revision 1.59
sys/dev/acpi/wb_acpi.c: revision 1.1
sys/dev/ic/w83l518d.c: revision 1.1
sys/dev/ic/w83l518d_sdmmc.c: revision 1.1
sys/dev/ic/w83l518d_sdmmc.h: revision 1.1
sys/dev/ic/w83l518dreg.h: revision 1.1
sys/dev/ic/w83l518dvar.h.c: revision 1.1

wb(4): Add a driver for Winbond W83L518D SD/MMC readers.
 1.1.2.1 30-Sep-2009  sborrill file w83l518d_sdmmc.h was added on branch netbsd-5 on 2009-10-08 09:47:09 +0000
 1.1 30-Sep-2009  jmcneill branches: 1.1.2; 1.1.6; 1.1.10;
Initial import of an SD/MMC driver for the Winbond W83L518D (and probably
W83L519D) Integrated Media Reader with PNP bus attachment glue.
 1.1.10.2 21-Apr-2010  matt sync to netbsd-5
 1.1.10.1 30-Sep-2009  matt file w83l518dreg.h was added on branch matt-nb5-mips64 on 2010-04-21 00:27:37 +0000
 1.1.6.2 11-Mar-2010  yamt sync with head
 1.1.6.1 30-Sep-2009  yamt file w83l518dreg.h was added on branch yamt-nfs-mp on 2010-03-11 15:03:36 +0000
 1.1.2.2 08-Oct-2009  sborrill Pull up the following revisions(s) (requested by jmcneill in ticket #1045):
distrib/sets/lists/man/mi: revision 1.1160
share/man/man4/Makefile: revision 1.499
share/man/man4/wb.4: revision 1.1-1.2
share/man/man4/ld.4: revision 1.17
sys/arch/i386/conf/ALL: revision 1.215-1.216 + patch
sys/arch/i386/conf/GENERIC: revision 1.946-1.947 + patch
sys/arch/amd64/conf/GENERIC: revision 1.254-1.256 + patch
sys/conf/files: revision 1.958
sys/dev/acpi/files.acpi: revision 1.59
sys/dev/acpi/wb_acpi.c: revision 1.1
sys/dev/ic/w83l518d.c: revision 1.1
sys/dev/ic/w83l518d_sdmmc.c: revision 1.1
sys/dev/ic/w83l518d_sdmmc.h: revision 1.1
sys/dev/ic/w83l518dreg.h: revision 1.1
sys/dev/ic/w83l518dvar.h.c: revision 1.1

wb(4): Add a driver for Winbond W83L518D SD/MMC readers.
 1.1.2.1 30-Sep-2009  sborrill file w83l518dreg.h was added on branch netbsd-5 on 2009-10-08 09:47:09 +0000
 1.3 11-May-2020  jdc Make the driver endian-independent.
Add a quirk so that the bus front end can specify 1-bit only mode.
Remove unused isa includes.
Change the error returned for unsupported opcodes to ENOTSUP, so that
we can pass this back to sdmmc_mem, where it's handled since r1.72 of
src/sys/dev/sdmmc/sdmmc_mem.c
 1.2 19-Aug-2010  jmcneill add suspend/resume support
 1.1 30-Sep-2009  jmcneill branches: 1.1.2; 1.1.4; 1.1.6; 1.1.8; 1.1.10;
Initial import of an SD/MMC driver for the Winbond W83L518D (and probably
W83L519D) Integrated Media Reader with PNP bus attachment glue.
 1.1.10.2 21-Apr-2010  matt sync to netbsd-5
 1.1.10.1 30-Sep-2009  matt file w83l518dvar.h was added on branch matt-nb5-mips64 on 2010-04-21 00:27:38 +0000
 1.1.8.1 05-Mar-2011  rmind sync with head
 1.1.6.3 09-Oct-2010  yamt sync with head
 1.1.6.2 11-Mar-2010  yamt sync with head
 1.1.6.1 30-Sep-2009  yamt file w83l518dvar.h was added on branch yamt-nfs-mp on 2010-03-11 15:03:36 +0000
 1.1.4.1 22-Oct-2010  uebayasi Sync with HEAD (-D20101022).
 1.1.2.3 21-Nov-2010  riz Pull up following revision(s) (requested by jmcneill in ticket #1462):
sys/dev/acpi/wb_acpi.c: revision 1.3
sys/dev/ic/w83l518d_sdmmc.c: revision 1.2
sys/dev/ic/w83l518d_sdmmc.h: revision 1.2
sys/dev/ic/w83l518d.c: revision 1.2
sys/dev/ic/w83l518dvar.h: revision 1.2
add suspend/resume support
add pmf support
 1.1.2.2 08-Oct-2009  sborrill Pull up the following revisions(s) (requested by jmcneill in ticket #1045):
distrib/sets/lists/man/mi: revision 1.1160
share/man/man4/Makefile: revision 1.499
share/man/man4/wb.4: revision 1.1-1.2
share/man/man4/ld.4: revision 1.17
sys/arch/i386/conf/ALL: revision 1.215-1.216 + patch
sys/arch/i386/conf/GENERIC: revision 1.946-1.947 + patch
sys/arch/amd64/conf/GENERIC: revision 1.254-1.256 + patch
sys/conf/files: revision 1.958
sys/dev/acpi/files.acpi: revision 1.59
sys/dev/acpi/wb_acpi.c: revision 1.1
sys/dev/ic/w83l518d.c: revision 1.1
sys/dev/ic/w83l518d_sdmmc.c: revision 1.1
sys/dev/ic/w83l518d_sdmmc.h: revision 1.1
sys/dev/ic/w83l518dreg.h: revision 1.1
sys/dev/ic/w83l518dvar.h.c: revision 1.1

wb(4): Add a driver for Winbond W83L518D SD/MMC readers.
 1.1.2.1 30-Sep-2009  sborrill file w83l518dvar.h was added on branch netbsd-5 on 2009-10-08 09:47:09 +0000
 1.33 09-Feb-2024  andvar fix spelling mistakes, mainly in comments and log messages.
 1.32 09-Feb-2022  andvar fix various typos in comments.
 1.31 21-Aug-2021  andvar fix some more typos in comments/log messages, improve wording as well.
 1.30 07-Aug-2021  thorpej Merge thorpej-cfargs2.
 1.29 24-Apr-2021  thorpej branches: 1.29.8;
Merge thorpej-cfargs branch:

Simplify and make extensible the config_search() / config_found() /
config_attach() interfaces: rather than having different variants for
which arguments you want pass along, just have a single call that
takes a variadic list of tag-value arguments.

Adjust all call sites:
- Simplify wherever possible; don't pass along arguments that aren't
actually needed.
- Don't be explicit about what interface attribute is attaching if
the device only has one. (More simplification.)
- Add a config_probe() function to be used in indirect configuiration
situations, making is visibly easier to see when indirect config is
in play, and allowing for future change in semantics. (As of now,
this is just a wrapper around config_match(), but that is an
implementation detail.)

Remove unnecessary or redundant interface attributes where they're not
needed.

There are currently 5 "cfargs" defined:
- CFARG_SUBMATCH (submatch function for direct config)
- CFARG_SEARCH (search function for indirect config)
- CFARG_IATTR (interface attribte)
- CFARG_LOCATORS (locators array)
- CFARG_DEVHANDLE (devhandle_t - wraps OFW, ACPI, etc. handles)

...and a sentinel value CFARG_EOL.

Add some extra sanity checking to ensure that interface attributes
aren't ambiguous.

Use CFARG_DEVHANDLE in MI FDT, OFW, and ACPI code, and macppc and shark
ports to associate those device handles with device_t instance. This
will trickle trough to more places over time (need back-end for pre-OFW
Sun OBP; any others?).
 1.28 10-Feb-2019  christos branches: 1.28.14;
Introduce PR_ZERO to avoid open-coding memset()s everywhere. OK riastradh@.
 1.27 08-Feb-2018  dholland branches: 1.27.4;
Typos.
 1.26 11-Jan-2017  skrll adatper -> adapter
 1.25 22-Jan-2014  christos branches: 1.25.6; 1.25.10;
fix unused variable warnings
 1.24 13-Nov-2010  uebayasi branches: 1.24.8; 1.24.18; 1.24.22;
Don't pull in the whole uvm(9) API to access only PAGE_SIZE and
some other constants. These are provided by sys/param.h now.
 1.23 12-Feb-2009  rumble branches: 1.23.4;
If sc_dmamode is set to SBIC_CTL_NO_DMA, then actually don't do DMA. Now
PIO mode actually works.
 1.22 27-Jan-2009  tsutsui branches: 1.22.2;
- use device_t and cfdata_t
- rename variables for readability after device_t/softc split
- use proper pointer types

No binary changes.
 1.21 25-Jan-2009  bjh21 Split device_t from wd33c93_softc. Reviewed by cube; tested on sgimips
by tsutsui.
 1.20 20-Jan-2009  bjh21 Convert more printfs to aprint_* and use the latter more consistently.
 1.19 08-Apr-2008  cegger branches: 1.19.4; 1.19.12;
use aprint_*_dev and device_xname
 1.18 19-Oct-2007  ad branches: 1.18.16;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.17 09-Jul-2007  ad branches: 1.17.6; 1.17.8; 1.17.12;
Merge some of the less invasive changes from the vmlocking branch:

- kthread, callout, devsw API changes
- select()/poll() improvements
- miscellaneous MT safety improvements
 1.16 21-May-2007  rumble Fix comments about the cf_flags layout and use macros to test whether
tags, sync, and disconnect/reconnect are to be disabled or not.
 1.15 21-May-2007  rumble Check in a workaround before I lose or forget about it:

My SGI issued IBM DORS-32160 will respond to every message with a sync
negotiation (even IDENTIFY) until it gets a response it likes (and it
definitely doesn't like async). Unfortunately, this locks us into an endless
loop after sending IDENTIFY, since the device responds with a SYNC
negotiation that we refuse to accept. This refusal results in a new
target-initiated sync negotiation, and so on...

To work around this, permit negotiating sync mode on an unexpected
target-initiated sync negotiation.
 1.14 08-May-2007  rumble Report whether we're using DMA and what type on attach, since I keep losing
track while testing.
 1.13 08-May-2007  rumble The maximum FIFO depth on old WD33C93 parts is only 5, not 12 as on 93A and
93B. However, there appear to be issues using the maximum of 5 on old
parts, so 4 is it.
 1.12 08-May-2007  rumble Enable Fast SCSI transfers for WD33C93B parts with appropriate input
clocks.

My Seagate ST32430N now sees about 50% greater throughput (about 97% as
fast as IRIX can push it). However, there appear to be other performance
issues with the driver as other disks perform significantly worse than they
should, with or without this change.

Reviewed by bjh21. Tested on my Indy and Challenge S.
 1.11 12-Mar-2007  ad branches: 1.11.2;
Pass an ipl argument to pool_init/POOL_INIT to be used when initializing
the pool's lock.
 1.10 05-Mar-2007  he branches: 1.10.2;
Cast to char* before doing pointer arithmetic.
 1.9 01-Oct-2006  bjh21 branches: 1.9.4; 1.9.6;
Allow wd33c93 attachments to choose what DMA mode it should use, and arrange
to use burst mode on sec(4), which makes it slightly but significantly faster.
 1.8 26-Sep-2006  bjh21 Merge my bjh21-wd33c93 branch. This improves message handling in general
and sync negotiation in particular. Tested on sgimips (thanks to
Manuel Bouyer) and acorn26 (with my still-unfinished driver for the Acorn
SCSI Expansion Card).
 1.7 05-Sep-2006  rumble branches: 1.7.2; 1.7.4; 1.7.6;
Make this work with timecounters.
 1.6 27-Aug-2006  bjh21 branches: 1.6.2; 1.6.4;
Revert revision 1.4: it seems to have caused serious problems on sgimips,
so I should probably leave it until I get my Indy going.
 1.5 27-Aug-2006  bjh21 Use symbolic names for CSR values after reset.
 1.4 26-Aug-2006  bjh21 When receiving a SCSI message, it's important not to deassert ACK on the last
byte until we've worked out what to do with the message, since if we plan
to reply to it we have to assert ATN before deasserting ACK. Implement this.
 1.3 26-Aug-2006  bjh21 Use standard MSG_IS1BYTE, MSG_IS2BYTE, and MSG_ISEXTENDED macros rather
than rolling our own.
 1.2 26-Aug-2006  bjh21 Use the 'z' size modifier when printfing size_t, so that GCC doesn't complain
on systems were size_t isn't unsigned int.
 1.1 26-Aug-2006  bjh21 Move the sgimips "sbic" driver from arch/sgimips/hpc/sbic.c to
dev/ic/wd33c93.c. This may not be the best WD33C93 driver we've
got, but it's the most recently worked on and probably the most
portable, so it seems like a good basis for further work (and in
particular an acorn26 driver for the Acorn SCSI card). There's
no functional change in this commit, and sgimips kernels still
compile.
 1.6.4.3 14-Sep-2006  yamt sync with head.
 1.6.4.2 03-Sep-2006  yamt sync with head.
 1.6.4.1 27-Aug-2006  yamt file wd33c93.c was added on branch yamt-pdpolicy on 2006-09-03 15:23:57 +0000
 1.6.2.10 24-Sep-2006  bjh21 Pull up timecounter fix from trunk.
 1.6.2.9 29-Aug-2006  bjh21 Remove a rogue printf that crept into the last commit.
 1.6.2.8 29-Aug-2006  bjh21 When reselecting a transfer that had DMA disabled, keep DMA disabled.
 1.6.2.7 29-Aug-2006  bjh21 Add support for negotiating async transfers if the scsipi layer asks for
that, or if the target requests sync transfers but the scsipi layer hasn't
turned them on yet. This is still some way from correctly implementing
the rules in SPI-5, but it's closer than it was.
 1.6.2.6 29-Aug-2006  bjh21 At the end of sync transfer negotiations, record the actual synchronous
transfer agreement that's been reached, rather than rounding it up to
the next transfer period we can support. This is particularly important
for target-initiated negotiations, since otherwise it might end up
transmitting at a lower than necessary rate.

Also, if we've agreed on sync transfer, don't silently try to use async
transfers just because the transfer period we've negotiated is a bit long.
It's possible we should renegotiate async transfers at that point, but for
now we'll just put up with it.
 1.6.2.5 29-Aug-2006  bjh21 Add a couple of debugging messages for tracing transfer mode discussions
with the scsipi layer.
 1.6.2.4 28-Aug-2006  bjh21 Print the attachment message in the attach routine rather than in the bus
reset routine. This should avoid getting odd messages when things go badly
wrong. While I'm there, re-arrange the attach message a bit (to look more
like the NCR53C9x one) and add the clock frequency to it.
 1.6.2.3 28-Aug-2006  bjh21 Ignoring WDTR IN is rude. Respond instead with MESSAGE REJECT OUT, like
any good initiator should.
 1.6.2.2 28-Aug-2006  bjh21 Rather than doing lots of sums every time we need to convert between
SCSI transfer period factors and WD33C93 TPx bits, build a little lookup
table of the available TPFs at startup and use that. This is rather
easier to understand than the old way.

Connectedly, remove code that tested for sc_minsync==0, since that couldn't
reasonably be true. Clients can use cf_flags to disable sync negotiation
if necessary.
 1.6.2.1 28-Aug-2006  bjh21 Reinstate my changes to the message-handling code, ensuring that we don't
release ACK until after we've decided whether we need to reply to a message,
since if we reply, we have to assert ATN before releasing ACK.
 1.7.6.1 22-Oct-2006  yamt sync with head
 1.7.4.2 09-Sep-2006  rpaulo sync with head
 1.7.4.1 05-Sep-2006  rpaulo file wd33c93.c was added on branch rpaulo-netinet-merge-pcb on 2006-09-09 02:50:03 +0000
 1.7.2.1 18-Nov-2006  ad Sync with head.
 1.9.6.3 17-May-2007  yamt sync with head.
 1.9.6.2 24-Mar-2007  yamt sync with head.
 1.9.6.1 12-Mar-2007  rmind Sync with HEAD.
 1.9.4.4 27-Oct-2007  yamt sync with head.
 1.9.4.3 03-Sep-2007  yamt sync with head.
 1.9.4.2 30-Dec-2006  yamt sync with head.
 1.9.4.1 01-Oct-2006  yamt file wd33c93.c was added on branch yamt-lazymbuf on 2006-12-30 20:48:04 +0000
 1.10.2.4 23-Oct-2007  ad Sync with head.
 1.10.2.3 01-Jul-2007  ad Adapt to callout API change.
 1.10.2.2 27-May-2007  ad Sync with head.
 1.10.2.1 13-Mar-2007  ad Sync with head.
 1.11.2.1 11-Jul-2007  mjf Sync with head.
 1.17.12.1 25-Oct-2007  bouyer Sync with HEAD.
 1.17.8.1 06-Nov-2007  matt sync with HEAD
 1.17.6.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.18.16.1 02-Jun-2008  mjf Sync with HEAD.
 1.19.12.1 03-Mar-2009  skrll Sync with HEAD.
 1.19.4.1 04-May-2009  yamt sync with head.
 1.22.2.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.23.4.1 05-Mar-2011  rmind sync with head
 1.24.22.1 18-May-2014  rmind sync with head
 1.24.18.2 03-Dec-2017  jdolecek update from HEAD
 1.24.18.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.24.8.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.25.10.1 20-Mar-2017  pgoyette Sync with HEAD
 1.25.6.1 05-Feb-2017  skrll Sync with HEAD
 1.27.4.1 10-Jun-2019  christos Sync with HEAD
 1.28.14.1 21-Mar-2021  thorpej Give config_found() the same variadic arguments treatment as
config_search(). This commit only adds the CFARG_EOL sentinel
to the existing config_found() calls. Conversion of config_found_sm_loc()
and config_found_ia() call sites will be in subsequent commits.
 1.29.8.1 04-Aug-2021  thorpej Adapt to CFARGS().
 1.4 12-Feb-2009  rumble WD33C93 has only two registers, which often times aren't mapped to adjacent
bus space locations. Map them individually, instead.
 1.3 08-May-2007  rumble branches: 1.3.32; 1.3.42; 1.3.48;
The maximum FIFO depth on old WD33C93 parts is only 5, not 12 as on 93A and
93B. However, there appear to be issues using the maximum of 5 on old
parts, so 4 is it.
 1.2 08-May-2007  rumble Enable Fast SCSI transfers for WD33C93B parts with appropriate input
clocks.

My Seagate ST32430N now sees about 50% greater throughput (about 97% as
fast as IRIX can push it). However, there appear to be other performance
issues with the driver as other disks perform significantly worse than they
should, with or without this change.

Reviewed by bjh21. Tested on my Indy and Challenge S.
 1.1 26-Aug-2006  bjh21 branches: 1.1.4; 1.1.8; 1.1.14; 1.1.16; 1.1.20; 1.1.22;
Move the sgimips "sbic" driver from arch/sgimips/hpc/sbic.c to
dev/ic/wd33c93.c. This may not be the best WD33C93 driver we've
got, but it's the most recently worked on and probably the most
portable, so it seems like a good basis for further work (and in
particular an acorn26 driver for the Acorn SCSI card). There's
no functional change in this commit, and sgimips kernels still
compile.
 1.1.22.1 11-Jul-2007  mjf Sync with head.
 1.1.20.1 27-May-2007  ad Sync with head.
 1.1.16.1 17-May-2007  yamt sync with head.
 1.1.14.3 03-Sep-2007  yamt sync with head.
 1.1.14.2 30-Dec-2006  yamt sync with head.
 1.1.14.1 26-Aug-2006  yamt file wd33c93reg.h was added on branch yamt-lazymbuf on 2006-12-30 20:48:04 +0000
 1.1.8.2 09-Sep-2006  rpaulo sync with head
 1.1.8.1 26-Aug-2006  rpaulo file wd33c93reg.h was added on branch rpaulo-netinet-merge-pcb on 2006-09-09 02:50:03 +0000
 1.1.4.2 03-Sep-2006  yamt sync with head.
 1.1.4.1 26-Aug-2006  yamt file wd33c93reg.h was added on branch yamt-pdpolicy on 2006-09-03 15:23:57 +0000
 1.3.48.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.3.42.1 03-Mar-2009  skrll Sync with HEAD.
 1.3.32.1 04-May-2009  yamt sync with head.
 1.13 09-Feb-2024  andvar fix spelling mistakes, mainly in comments and log messages.
 1.12 27-Dec-2019  msaitoh s/transfered/transferred/
 1.11 28-Jul-2012  matt branches: 1.11.40;
Remove tinfo_t which would have been a typedef had someone actually used
typedef but instead it become an unused common.
 1.10 12-May-2009  cegger branches: 1.10.12;
struct device * -> device_t, no functional changes intended.
 1.9 12-Feb-2009  rumble WD33C93 has only two registers, which often times aren't mapped to adjacent
bus space locations. Map them individually, instead.
 1.8 25-Jan-2009  bjh21 branches: 1.8.2;
Split device_t from wd33c93_softc. Reviewed by cube; tested on sgimips
by tsutsui.
 1.7 21-May-2007  rumble branches: 1.7.32; 1.7.42;
Fix comments about the cf_flags layout and use macros to test whether
tags, sync, and disconnect/reconnect are to be disabled or not.
 1.6 08-May-2007  rumble Enable Fast SCSI transfers for WD33C93B parts with appropriate input
clocks.

My Seagate ST32430N now sees about 50% greater throughput (about 97% as
fast as IRIX can push it). However, there appear to be other performance
issues with the driver as other disks perform significantly worse than they
should, with or without this change.

Reviewed by bjh21. Tested on my Indy and Challenge S.
 1.5 04-Mar-2007  christos branches: 1.5.2; 1.5.4;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.4 01-Oct-2006  bjh21 branches: 1.4.4; 1.4.6;
Allow wd33c93 attachments to choose what DMA mode it should use, and arrange
to use burst mode on sec(4), which makes it slightly but significantly faster.
 1.3 26-Sep-2006  bjh21 wd33c93_minphys() doesn't exist any more, so don't declare it.
 1.2 26-Sep-2006  bjh21 Merge my bjh21-wd33c93 branch. This improves message handling in general
and sync negotiation in particular. Tested on sgimips (thanks to
Manuel Bouyer) and acorn26 (with my still-unfinished driver for the Acorn
SCSI Expansion Card).
 1.1 26-Aug-2006  bjh21 branches: 1.1.2; 1.1.4; 1.1.6; 1.1.8; 1.1.10;
Move the sgimips "sbic" driver from arch/sgimips/hpc/sbic.c to
dev/ic/wd33c93.c. This may not be the best WD33C93 driver we've
got, but it's the most recently worked on and probably the most
portable, so it seems like a good basis for further work (and in
particular an acorn26 driver for the Acorn SCSI card). There's
no functional change in this commit, and sgimips kernels still
compile.
 1.1.10.1 22-Oct-2006  yamt sync with head
 1.1.8.2 09-Sep-2006  rpaulo sync with head
 1.1.8.1 26-Aug-2006  rpaulo file wd33c93var.h was added on branch rpaulo-netinet-merge-pcb on 2006-09-09 02:50:03 +0000
 1.1.6.1 18-Nov-2006  ad Sync with head.
 1.1.4.2 03-Sep-2006  yamt sync with head.
 1.1.4.1 26-Aug-2006  yamt file wd33c93var.h was added on branch yamt-pdpolicy on 2006-09-03 15:23:57 +0000
 1.1.2.3 26-Sep-2006  bjh21 Add a definition of T_WANTSYNC, which I somehow missed committing.
 1.1.2.2 28-Aug-2006  bjh21 Rather than doing lots of sums every time we need to convert between
SCSI transfer period factors and WD33C93 TPx bits, build a little lookup
table of the available TPFs at startup and use that. This is rather
easier to understand than the old way.

Connectedly, remove code that tested for sc_minsync==0, since that couldn't
reasonably be true. Clients can use cf_flags to disable sync negotiation
if necessary.
 1.1.2.1 28-Aug-2006  bjh21 Remove a couple of disused structure elements.
 1.4.6.2 17-May-2007  yamt sync with head.
 1.4.6.1 12-Mar-2007  rmind Sync with HEAD.
 1.4.4.3 03-Sep-2007  yamt sync with head.
 1.4.4.2 30-Dec-2006  yamt sync with head.
 1.4.4.1 01-Oct-2006  yamt file wd33c93var.h was added on branch yamt-lazymbuf on 2006-12-30 20:48:04 +0000
 1.5.4.1 11-Jul-2007  mjf Sync with head.
 1.5.2.1 27-May-2007  ad Sync with head.
 1.7.42.1 03-Mar-2009  skrll Sync with HEAD.
 1.7.32.2 16-May-2009  yamt sync with head
 1.7.32.1 04-May-2009  yamt sync with head.
 1.8.2.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.10.12.1 30-Oct-2012  yamt sync with head
 1.11.40.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.310 31-May-2022  andvar fix various typos in comments, documentation and messages.
 1.309 24-May-2022  andvar fix various typos in comment, documentation and log messages.
 1.308 05-Oct-2021  rin PR kern/56403

Fix kernel freeze for wdc(4) variants with ATAC_CAP_NOIRQ:

(1) Change ata_xfer_ops:c_poll from void to int function. When it returns
ATAPOLL_AGAIN, let ata_xfer_start() iterate itself again.

(2) Let wdc_ata_bio_poll() return ATAPOLL_AGAIN until ATA_ITSDONE is
achieved.

A similar change has been made for mvsata(4) (see mvsata_bio_poll()),
and no functional changes for other devices.

This is how the drivers worked before jdolecek-ncq branch was merged.

Note that this changes are less likely to cause infinite recursion:

(1) wdc_ata_bio_intr() called from wdc_ata_bio_poll() asserts ATA_ITSDONE
in its error handling paths via wdc_ata_bio_done().

(2) Return value from c_start (= wdc_ata_bio_start()) is checked in
ata_xfer_start().

Therefore, errors encountered in ata_xfer_ops:c_poll and c_start routines
terminate the recursion for wdc(4). The situation is similar for mvsata(4).

Still, there is a possibility where ata_xfer_start() takes long time to
finish a normal operation. This can result in a delayed response for lower
priority interrupts. But, I've never observed such a situation, even when
heavy thrashing takes place for swap partition in wd(4).

"Go ahead" by jdolecek@.
 1.307 17-Sep-2021  rin wdc_sataprobe: Fix lock leak when atabus_alloc_drives() fails.
 1.306 04-Jan-2021  skrll KNF
 1.305 04-Jan-2021  skrll Trailing whitespace
 1.304 04-Jan-2021  skrll Spell interrupts correctly
 1.303 03-Jun-2020  bouyer branches: 1.303.2;
Don't print an error message on spurious interrupt. Way too noisy for Xen.
 1.302 30-May-2020  jdolecek fix wdcprobe_with_reset() to avoid allocating big structures on stack
 1.301 21-May-2020  jdolecek in wdctimeout(), do not schedule another timeout handler, as that only
creates race with eventual xfer resubmission - the c_intr()
method does all the necessary handling, including re-scheduling of the
timeout handler if appropriate

also make sure to clear ATACH_IRQ_WAIT before calling c_intr(), same
as real interrupt does; this is important so that eventual spurious timeout
would not interfere with xfer handling in the atabus thread

fixes another race in the atabus thread found by KASAN, reported by Paul Ripke
 1.300 19-May-2020  jdolecek in wdctimeout() ignore timeout if not actually waiting for IRQ, to avoid
processing xfer which is not quite setup

in wdcintr() actually write the error message on invocation when
not waiting for IRQ even without ATADEBUG option, as usually that
is a driver bug; might revisit this if this ends up too noisy for
PCI-IDE which seems to ignore WDCTL_IDS and hence trigger irq even
for polled commands
 1.299 13-Apr-2020  jdolecek fix use-after-free for ata xfer on bio submission found by KASAN

driver ata_bio hooks read parts of the xfer after ata_exec_xfer()
call in order to determine return value, change so that the hook
doesn't return any value - callers do not care already,
as all I/O requests are asynchronous

this problem was uncovered by recent change for wd(4) to not hold
wd mutex during ata_bio call, the interrupt for the xfer might
thus actually fire immediately

adjust also ata_exec_command driver hooks similarily - remove all
completion and waiting logic from drivers, upper layer ata code
using AT_WAIT/AT_POLL changed to call ata_wait_cmd() itself

PR kern/55169 by Nick Hudson
 1.298 04-Apr-2020  jdolecek branches: 1.298.2;
fix deadlock in wdcwait() when xfer timeout happens while the atabus
thread sleeps in wdcwait() - check current lwp rather than relying
on global ATACH_TH_RUN channel flag

should fix the hang part of the problem reported in
http://mail-index.netbsd.org/netbsd-users/2020/03/12/msg024249.html

thanks to Paul Ripke for providing extensive debugging info
 1.297 10-Feb-2020  jdolecek use wdc_maxdrives for atabus_alloc_drives() also in wdc_sataprobe()
instead of magic 1; no functional change, all wdc_sataprobe() users
actually set wdc_maxdrives to 1
 1.296 27-Dec-2019  msaitoh branches: 1.296.2;
s/transfered/transferred/
 1.295 04-Nov-2019  prlw1 Fix locking bug seen when using WDCNDELAY_DEBUG in PR kern/52126
(Observed
piixide0:0:0: warning: busy-wait took 200us
with no panic)
 1.294 23-Oct-2019  christos Missing ata_channel_unlock(chp). Noted by mjg@freebsd.
 1.293 22-Oct-2019  martin Fix channel locking - patch from Christos.
 1.292 14-Sep-2019  tsutsui Restore interface to pass a MD reset function to MI wdcprobe().

Fixes silent hang on G1IDE on Dreamcast. PR kern/54538
Should be pulled up to netbsd-9 with the previous changes.
 1.291 27-Oct-2018  maya branches: 1.291.4;
Fix previous misnamed initializer elements

committed wrong version of patch, sorry!
 1.290 27-Oct-2018  maya Add missing ata_recovery struct element, NULL, same as wdc_ata_bustype
in the NWD > 0 case.

Build fix for the case where wd(4) is not built, reported by
John D. Baker on current-users.
 1.289 22-Oct-2018  jdolecek Merge jdolecek-ncqfixes branch

- ata_xfer's are dynamicall allocated as needed using a pool, no longer
limited to number of possible openings supported by controller; dump
and recovery paths use dedicated pre-allocated storage
- moved callouts and condvars from ata_xfer to queue or channel, so that
ata_xfer does not need special initialization
- slot allocation now done when xfer is being activated, uncoupled
from memory allocation; active slots are no longer tracked by controller
code
- channel and drive reset is done always via the atabus thread, and
now executes with channel locked the whole time
- NCQ recovery moved to shared function, and run via the thread also
- added some workarounds for buggy error recovery AHCI emulation in QEMU
and Parallels

designed to primarily fix kern/52614, but might also help with kern/47041
and kern/53183
 1.288 20-Oct-2017  jdolecek branches: 1.288.2; 1.288.4; 1.288.6;
move ata_queue_alloc(1) and ata_queue_free() calls to ata_channel_init()
and ata_channel_destroy() respectively, to make attachment code simpler,
and to make it easier to spot special queue manipulation like cmdide(4)

on topic of PR kern/52606
 1.287 17-Oct-2017  jdolecek reintroduce ATACH_IRQ_WAIT flag for attachments using wdcintr(), only
process the interrupt when the flag is set - this fixes spurious interrupt
during post-reset drive setup in wdc_ata_bio_start(), and wdc_atapi_start()

while those functions set WDCTL_IDS, this seems to be ignored by certain
(maybe all) PCI-IDE controllers; usually the implicit KERNEL_LOCK() would
prevent the interrupt anyway, but not when the start routine is started
from the atabus thread, which doesn't take it

fixes 'panic: wdc_ata_bio_intr: bad state' reported on current-users
by Chavdar Ivanov
 1.286 16-Oct-2017  jdolecek fix comment - it's WDCTL_IDS which is supposed to disable interrupts
 1.285 15-Oct-2017  jdolecek explicitely ignore polled xfers in wdcintr(), so it won't be processed
twice - seems setting WDSD_IBM actually has no effect at least
on some PCI-IDE, and the interrupt ends up being triggered when we release
the channel lock to call c_poll hook

fixes PR kern/52605, and should also fix the 'New panic in wdc_ata_bio_intr'
reported on current-users@
 1.284 07-Oct-2017  jdolecek Merge support for SATA NCQ (Native Command Queueing) from jdolecek-ncq branch

ATA subsystem was changed to support several outstanding commands, and use
NCQ xfers if supported by both the controller and the disk, including NCQ
error recovery. Set NCQ high priority for BPRIO_TIMECRITICAL xfers
if supported. Added FUA support.

Done some work towards MP-safe, all ATA code tsleep()/wakeup() replaced
by condvars, and switched most code from spl* to mutexes (separate
wd(4) and ata channel lock).

Introduced new option WD_CHAOS_MONKEY to facilitate testing of error
handling, fixed several uncovered issues. Also fixed several problems
with kernel dump to wd(4) disk.

Tested with ahcisata(4), mvsata(4), siisata(4), piixide(4) on amd64,
with and without port multiplier, both disk and ATAPI devices; other
drivers and archs mechanically adjusted and compile-tested. NCQ is
supported for ahcisata(4) and siisata(4) for any controller, for
mvsata(4) only Gen IIe ones for now. Also enabled ATAPI support in
mvsata(4).

Thanks to Matt Thomas for initial ATA infrastructure patch, and
Jonathan A.Kollasch for siisata(4) NCQ changes and general testing.

Also fixes PR kern/43169 (wd(4)); and PR kern/11811, PR kern/47041,
PR kern/51979 (kernel dump)
 1.283 29-Mar-2017  msaitoh branches: 1.283.2;
Fix 0x%d and 0x%u.
 1.282 17-Aug-2016  skrll branches: 1.282.2;
Spelling in comment
 1.281 06-May-2016  msaitoh branches: 1.281.2;
KNF. No functional change.
 1.280 18-Jan-2016  msaitoh Fix a bug that wdcprobe1() accesses NULL pointer when the DEBUG_PROBE bit
is set in atadebug_mask variable. The caller passes data which has
temporary-generated wdc_softc in it, but the device_t has not initialized
because it's not determined yet. So it can't use device_xname(). Use
__function__ instead.
 1.279 15-Sep-2013  martin branches: 1.279.6;
Mark potentially unused variables
 1.278 03-Apr-2013  bouyer branches: 1.278.4;
Fix kernel dump on ahci controller, by making sure we won't sleep
while dumping:
- introduce ata_delay() which either use delay() or kpause()
depending on flags. use it in sata_reset_interface() and
some ahci functions
- kill ATA_NOSLEEP, it was tested but never set. use ATA_POLL instead.
- reduce delay while polling in ahci, to speed up the dump

Should fix PR kern/41095
 1.277 03-Feb-2013  jakllsch Add argument to wdccommandext() to allow the entire contents of the
device/head register to be specified. Needed for upcoming port multipler
support in mvsata(4).
 1.276 19-Dec-2012  kiyohara Restore spl before continue.
 1.275 19-Nov-2012  rkujawa Introduce WDC_CAPABILITY_NO_AUXCTL flag. For lame controllers that don't
have aux control registers (driver coming soon).
 1.274 31-Jul-2012  bouyer branches: 1.274.2;
Apply back changes that were reverted on Jul 24 and Jul 26 (general ata/wdc
cleanup and SATA PMP support), now that I'm back to fix the fallouts.
 1.273 29-Jul-2012  christos PR/46599: Onno van der Linden: Don't call bus space commands with 0 len.
Causes the sil 3112 controller to lock up.
 1.272 26-Jul-2012  jakllsch Revert, with intention of restoring in a less invasive way, the SATA Port
Multiplier code.

ok christos@
 1.271 24-Jul-2012  jakllsch Revert dsl@'s changes of Sun, 15 Jul 2012 10:55:35 +0000 and
Sun, 15 Jul 2012 10:56:50 +0000, excepting the kernel version bump.
First step in reverting regressions to ata(4) subsystem during the addition of
port multiplier support.
 1.270 15-Jul-2012  dsl Some namespace protection (and add greppablity).
Prefix the DRIVE_ and DRIVET_ constants from atavar.h with ATA_.
Don't use an enum for drive_type - you don't know how big it will be.
Move driver_type to avoid implicit structure padding (esp on arm).
This change is purely lexical and mechanical.

Update to 6.99.9 - this wasn't done when the SATA PMP changes
were made - I'm sure they warranted a bump.
 1.269 02-Jul-2012  bouyer Add sata Port MultiPlier (PMP) support to the ata bus layer,
as described in
http://mail-index.netbsd.org/tech-kern/2012/06/23/msg013442.html
PMP support in integrated to the atabus layer.
struct ata_channel's ch_drive[] is not dynamically allocated, and ch_ndrive
(renamed to ch_ndrives) closely reflects the size of the ch_drive[] array.
Add helper functions atabus_alloc_drives() and atabus_free_drives()
to manage ch_drive[]/ch_ndrives.
Add wdc_maxdrives to struct wdc_softc so that bus front-end can specify
how much drive they really support (master/slave or single).
ata_reset_drive() callback gains a uint32_t *sigp argument which,
when not NULL, will contain the signature of the device being reset.
While there, some cosmetic changes:
- added a drive_type enum to ata_drive_datas, and stop encoding the
probed drive type in drive_flags (we were out of drive flags anyway).
- rename DRIVE_ATAPIST to DRIVE_ATAPIDSCW to better reflect what this
really is
- remove ata_channel->ata_drives, it's redundant with the pointer in
ata_drive_datas
- factor out the interpretation of SATA signatures in sata_interpet_sig()

propagate these changes to the ATA HBA drivers, and add support for PMP
to ahcisata(4) and siisata(4).

Thanks to:
- Protocase (http://www.protocase.com/) which provided a system
with lots of controllers, SATA PMP and drive slots
- Conservation Genomics Laboratory, Department of Biology, New Mexico State
University for hosting the above system
- Brook Milligan, who set up remote access and has been very responsive
when SATA cable move was needed
 1.268 24-Jan-2012  jakllsch Rework struct ata_command to support LBA28 and LBA48-protocol commands.
Implement 28- and 48-bit command issuance and parameter read-back in the
various ATA host drivers. Add LBA28-protocol support to ATAIOCCOMMAND ioctl.
 1.267 09-Jan-2012  jakllsch Instead of assume that 'features' is 0 in wdccommandext(),
pass it as an argument, as is done for wdccommand().
 1.266 04-Dec-2011  jakllsch correct some typos in comments, whitespace adjustments
 1.265 28-Aug-2011  bouyer branches: 1.265.2; 1.265.6;
Revert previous and fix properly by just removing the #error and a bogus
KASSERT() (these 2 are leftover from the experiments on the fuloong
and were not intended to be commited).
 1.264 28-Aug-2011  christos Make this compile again without WDC_NO_IDS.
 1.263 27-Aug-2011  bouyer The loongon2f+cs5526+jmicron PATA->SATA bridge cause an interresting issue:
1) because the CS5536 is not associated with a x86 CPU, interrupts are not
ack'ed as it expects so interrupts cannot configured as edge-triggered
(as is expected for a PCIIDE in compat mode)
2) the PATA->SATA bridge ignores the WDC_IDS (interrupt disable bit) so
the PATA IRQ line gets asserted when resetting or running some polled
commands. It also wrongly asserts IRQ when the (nonexistent) slave
device is selected
2) wouldn't be an issue with edge-triggered interrupt because we would
get a spurious interrupt and continue operation, a new interrupt only shows
up when the PATA IRQ line goes low and high again. But because of 1),
we get an unclearable interrupt instead, and the system loops on the
interrupt handler.

To workaround this, introduce a WDC_NO_IDS compile option which runs
all polled commands (including reset) at splbio() and without sleeps,
so that the controller's interrupt is effectively disabled and
won't be reenabled before the interrupt can be cleared.

The conditions triggering this problem are speficic enough to handle
this via a compile-time option; no need for a run-time (e.g. a
config(9), device property or callback to disable interrupts) solution.
 1.262 13-Aug-2011  jakllsch It's hard to get a backtrace after calling a NULL function pointer,
add KASSERT before calling.
 1.261 28-Mar-2010  snj Spell "enough" properly.
 1.260 12-Nov-2009  dyoung branches: 1.260.2; 1.260.4;
Remove superfluous activation hook.
 1.259 19-Oct-2009  bouyer Remove closes 3 & 4 from my licence. Lots of thanks to Soren Jacobsen
for the booring work !
 1.258 06-Oct-2009  sborrill Commit patch from PR#41926. Confirmed to work by PR submitter on two
controllers as well myself and another on viaide.

Stops errors such as the following when probing SATA drives through
controllers that offer the legacy pciide interface:
viaide1 channel 0: reset failed for drive 0

OK bouyer@
 1.257 08-Dec-2008  pooka Warn about large struct on stack in comment.
 1.256 16-Nov-2008  bouyer cpu_intr_p() doesn't account for software interrupts (e.g. callouts) so
we can't use it here. Rssurect ATACH_TH_RUN, backing out
src/sys/dev/ata/ata.c 1.101
src/sys/dev/ata/ata_wdc.c 1.90
src/sys/dev/ata/atavar.h 1.77
src/sys/dev/ic/wdc.c 1.255
src/sys/dev/scsipi/atapi_wdc.c 1.108
Should fix kern/39927 and kern/39725.
 1.255 02-Oct-2008  bouyer branches: 1.255.2; 1.255.4;
Kill ATACH_TH_RUN and use cpu_intr_p() instead.
 1.254 28-Apr-2008  martin branches: 1.254.2; 1.254.6;
Remove clause 3 and 4 from TNF licenses
 1.253 18-Mar-2008  cube branches: 1.253.2; 1.253.4;
Split device_t and softc for ATA devices, as well as wd(4). Other
cosmetic changes where appropriate.
 1.252 28-Jan-2008  dyoung branches: 1.252.2; 1.252.6;
If something still holds a reference to our scsipi_adapter, do not
warn and complete the detachment, but return EBUSY.
 1.251 19-Jan-2008  dyoung In wdcdetach(), if config_detach() fails, get out early.
 1.250 10-Jan-2008  dyoung Let us detach atabus* from wdc*, and wdc* from isa*.

Use device_t, device_private().
 1.249 19-Oct-2007  ad branches: 1.249.2; 1.249.8;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.248 16-Apr-2007  dyoung branches: 1.248.6; 1.248.8; 1.248.12;
Make this compile with or without 'options ATADEBUG'.
 1.247 17-Mar-2007  dyoung Let config(1) know that #define ATADEBUG goes in opt_ata.h. In
dev/ic/wdc.c and in dev/ata/ata.c, #include "opt_ata.h", and make
both the files compile with or *without* ATADEBUG. Do not compile
with ATADEBUG by default.
 1.246 26-Jan-2007  sborrill branches: 1.246.2; 1.246.6; 1.246.8; 1.246.10;
Add missing bus_space_(read,write)_stream macros.
Approved by martin@
 1.245 18-Jan-2007  bouyer For the unaligned case:
Be consistant with the spaces around * and +
Use data32io[th] for 32bit access
Use stream bus_space access unless we have DRIVE_NOSTREAM
all pointed out by enami tsugutomo, thanks !
 1.244 14-Jan-2007  martin If __NO_STRICT_ALIGNMENT is not defined, take special care to do PIO
transfers with proper alignement - this removes alignement restrictions
of the buffer pointer passed.
Thanks to bouyer, reinoud, jdc for helping with the code, and special
thanks to Dave Huang for testing.
 1.243 29-Nov-2006  bouyer branches: 1.243.2;
Use mstohz() for callout argument instead of local arithmetic.
 1.242 20-Nov-2006  bouyer Move part of wdc_sataprobe() to sys/dev/ata/sata_subr.c so that it can be
shared with non-wdc SATA controllers.
 1.241 14-Nov-2006  bouyer wdc_sataprobe():
- wait up to 1s for SStatus_DET_DEV after SControl_DET_INIT toggle (from
FreeBSD)
- reset the drive once we know it's there. It may be in some PM state and
not able to properly reply to IDENTIFY. Tested by Teemu Rinta-aho,
fixes PR kern/35049 and should also fix PR kern/35008.
 1.240 25-Oct-2006  bouyer Exclude wdc_sataprobe() when no SATA controllers are present. Fix
build of *_TINY kernels.
 1.239 25-Oct-2006  bouyer Add sata registers to struct wdc_regs. Add wdc_sataprobe(), a function
probing drives using the standard SATA registers; taken from various
PCI sata drivers. Export wdc_drvprobe() too.
 1.238 30-Sep-2006  itohy A little effort against kernel bloat....
Exclude ATA DMA support if no ATA DMA capable drivers are compiled in.
 1.237 17-Aug-2006  christos branches: 1.237.2; 1.237.4;
Fix all the -D*DEBUG* code that it was rotting away and did not even compile.
Mostly from Arnaud Lacombe, many thanks!
 1.236 18-Mar-2006  bouyer __wdcwait_reset(): if we hare there we have a wdc pointer, so no need to check
if wdc is not NULL here at all (we were doing it after wdc has been
dereferenced anyway).
Coverity ID 2441.
 1.235 20-Feb-2006  thorpej branches: 1.235.2; 1.235.4; 1.235.6;
Use device_is_active() rather than testing dv_flags for DVF_ACTIVE
directly.
 1.234 24-Jan-2006  bouyer branches: 1.234.2; 1.234.4;
Revert part of previous: checking the drive's status after a read seems to
cause interrupt timeouts on some hardware.
 1.233 22-Jan-2006  bouyer Make some debug printf more verbose.
In wdccommand_intr(), after a data read check that the drive is ready again.
 1.232 16-Jan-2006  bouyer properly use ata_channel->ch_ndrive:
- initialize it properly in the bus front-ends (all 2, exept in wdc_pcmcia.c
for the "Sandisk CompactFlash Card" where it's set to 1)
- remplace hardcoded '2' by ata_channel->ch_ndrive in MI IDE drivers.

From Christos Zoulas in kern/32501.
 1.231 16-Nov-2005  bouyer branches: 1.231.2;
After a reset don't wait for drives to come ready if there's no drives.
Fix a 30s hang after resume. Problem reported and fix tested by Brian de Alwis.
 1.230 29-Aug-2005  bouyer branches: 1.230.6;
In __wdccommand_start(), don't cann wdcwait() with ata_c->flags, as this gives
information about the context in which wdc_exec_command() was called, but
we may be in interrupt context here. Call wdcwait() with flags derived from
xfer->c_flags instead, as do other wdcwait() callers.
Should fix kern/31083 by Jukka Salmi.
 1.229 17-Aug-2005  tacha make CF on pcmcia works again.

Approved by bouyer.
closed kern/30998.
 1.228 10-Aug-2005  bouyer Add missing declaration/initialisation of wdc.
Pointed out by Rui Paulo.
 1.227 10-Aug-2005  bouyer Also initialize wdc->reset in wdcprobe() if the bus back-end didn't provide
one. Prevent NULL pointer dereference when wdcprobe() is called.
 1.226 09-Aug-2005  bouyer The ATA/ATAPI IDENTIFY data were designed to be converted on the fly to
host byte order (eventually the byte swapping could be wired in hardware, on
the 16 bit data bus). This was keept when wdc_exec_command() was created,
and as a result wdc_exec_command() is doing 16bit conversion to host byte
order. This is fine for IDENTIFY but doesn't work for other opaque data
structure, such as the ones for SMART.
So change wdc_exec_command() to do the conversion to host byte order only for
WDCC_IDENTIFY and ATAPI_IDENTIFY_DEVICE. This fixes atactl smart status
on big-endian hosts.

While here change __wdccommand_intr() to only use wdc_data{in,out}_pio, there
is no gain in doing the 32bit data port stuff locally.
 1.225 06-Aug-2005  bouyer Add an optionnal controller callback for channel reset. If the callback
is set to NULL, use the generic reset code.
Use this to work around a bug in some Acer IDE controllers (like the
one found in some sparc systems) where a controller disable/enable
is required after a reset to avoid data corruption when Ultra-DMA is
used. Workaround from opensolaris, thanks to Hiroki Sato for testing.
 1.224 19-Jun-2005  bouyer branches: 1.224.2;
In wdcprobe1(), wait 5s for the drive to deassert ready. In case of e.g.
pcmcia devices, the drive may still be doing its power-on reset.
XXX From the specs the delay could be up to 31s here, but we don't want to
wait for 31s if we have a channel with no drives and pull-up resitors on
the bus.
Based on patch submitted in kern/25659 by Steven M. Bellovin, part of fix for
kern/25659.
 1.223 16-Jun-2005  bouyer Remove a (wdc == NULL) test. We know wdc is not NULL at this point.
 1.222 29-May-2005  christos - sprinkle const.
- avoid variable shadowing.
 1.221 28-Mar-2005  fvdl Reverse the cyl_lo and cyl_hi reads for the AT_READREG case; previously,
the cyl_lo information would have been thrown away.
 1.220 02-Mar-2005  mycroft branches: 1.220.2;
Copyright maintenance.
 1.219 27-Feb-2005  perry nuke trailing whitespace
 1.218 11-Feb-2005  rearnsha Add support for Artisea chips operating in DPA mode, which has a
16-bit view of the ATA command registers for extended commands.

Approved by briggs.
 1.217 30-Oct-2004  bouyer branches: 1.217.4; 1.217.6;
Allow polled commands to be queued, if ata_exec_xfer() is called in thread
context. For this introduce 3 new xfer tags:
- C_WAIT, equivalent of AT_WAIT
- C_WAITACT, when there is a thread waiting on this xfer to become the active
one (that is, to be at the head of the queue)
- C_FREE, set by ata_free_xfer() when it can't free the xfer because it's
still in use. The holder should then free the xfer ASAP.

If ata_exec_xfer() is called with (C_POLL | C_WAIT), and there is already
xfers to be processed, assert C_WAITACT and sleep.
atastart() checks for C_WAITACT, and wakeup the thread waiting for this xfer
to become active if set. atastart() won't process this xfer, it's the
responsability of the thread waked up to handle it.

Fix (the right way) kern/27421 by Martin Husemann.
 1.216 30-Oct-2004  bouyer Revert 1.215, with a comment explaining why we can't use interrupts here.
 1.215 26-Oct-2004  bouyer wdc_drvprobe(): don't poll for the IDENTIFY, use interrupts. There's no
reasons to not use interrupts here, and polling cause problems when there is
a shared queue between 2 channels.
Fix kern/27421 by Martin Husemann.
 1.214 25-Oct-2004  enami Fill some entry in fake wdc_ata_bustype since those are called even
if no wd(4) device is configured in a kernel.
 1.213 21-Aug-2004  thorpej Make some functions referenced only in wdc.c private to that file.
 1.212 21-Aug-2004  thorpej atastart() (called only at splbio(), and from interrupts) can change
drive_flags, to make sure all drive_flags manipulations are done at
splbio().
 1.211 20-Aug-2004  thorpej - Add an (*ata_reset_channel)() member to ata_bustype.
- Add an ata_reset_channel() function that performs the common parts
of resetting an ATA channel, which uses the (*ata_reset_channel)()
callback to do the heavy lifting. Adjust callers to use ata_reset_channel()
instead of wdc_reset_channel().

This removes the last wdc-specific code from ata.c!
 1.210 20-Aug-2004  thorpej Move common parts of attaching an ata_channel to a new ata_channel_attach()
function.
 1.209 20-Aug-2004  thorpej Move atabusconfig() to ata.c.
 1.208 20-Aug-2004  thorpej - Add an atac_bustype_ata member to atac_softc to hold a pointer to
the ata_bustype for the controller. Fill it in and use it instead
of referencing wdc_ata_bustype directly.
- Add an atac_atapibus_attach member to atac_softc to hold a pointer
to the function that attaches the ATAPI bus for the controller. Fill
it in and use it instead of referencing wdc_atapibus_attach directly.
 1.207 20-Aug-2004  thorpej Move most of wdc_softc into a new atac_softc structure that contains
info common to all types of ATA controllers.
 1.206 19-Aug-2004  thorpej - Add and use a CHAN_TO_WDC() macro to get the wdc_softc from an
ata_channel.
- Add and use a CHAN_TO_WDC_REGS() macro to get the wdc_regs from an
ata_channel.
- Add and use a CHAN_TO_PCIIDE() macro to get the pciide_softc from an
ata_channel.
- Add and use a CHAN_TO_PCHAN() macro to get the pciide_channel from an
ata_channel. (This one just hides a cast, and is really just for
consistency with the others.)
 1.205 14-Aug-2004  thorpej - Split the register handles out of struct wdc_channel into a separate
wdc_regs structure, and array of which (indexed per channel) is pointed
to by struct wdc_softc.
- Move the resulting wdc_channel structure to atavar.h and rename it to
ata_channel. Rename the corresponding flags.
- Add a "ch_ndrive" member to struct ata_channel, which indicates the
maximum number of drives that can be present on the channel. For now,
this is always 2. Add an ATA_MAXDRIVES constant that places an upper
limit on this value, also currently 2.
 1.204 13-Aug-2004  thorpej WDCDEBUG -> ATADEBUG.
 1.203 13-Aug-2004  thorpej Don't bother with bits that tell of the presence of optional callbacks;
just check the function pointers for NULL.
 1.202 13-Aug-2004  thorpej Move wdcstart() to ata.c and rename it to atastart().
 1.201 13-Aug-2004  thorpej Move wdc_exec_xfer() to ata.c and rename it ata_exec_xfer().
 1.200 12-Aug-2004  thorpej Move wdc_addref() and wdc_delref() to ata.c and rename them to
ata_*.
 1.199 12-Aug-2004  thorpej Move wdc_kill_pending() to ata.c and rename it ata_kill_pending().
 1.198 12-Aug-2004  thorpej - Move wdc_xfer_pool, wdc_get_xfer(), wdc_free_xfer() to ata.c, and rename
to ata_*.
- Use a static initializer for the ata_xfer_pool.
 1.197 12-Aug-2004  thorpej Move wdc_probe_caps() to ata.c and rename it ata_probe_caps().
 1.196 12-Aug-2004  thorpej Move wdc_downgrade_mode() to ata.c and rename it to ata_downgrade_mode().
 1.195 12-Aug-2004  thorpej Move wdc_print_modes() into ata.c and rename it ata_print_modes().
 1.194 12-Aug-2004  mycroft Whoops. Swap the order of the delref() and the config_pending_decr().
 1.193 12-Aug-2004  thorpej Rename some constants:
WDC_COMPLETE -> ATACMD_COMPLETE
WDC_QUEUED -> ATACMD_QUEUED
WDC_TRY_AGAIN -> ATACMD_TRY_AGAIN
 1.192 12-Aug-2004  thorpej Rename "struct wdc_command" to "struct ata_command".
 1.191 11-Aug-2004  mycroft Make datain_pio and dataout_pio function pointers in wdc_softc, which can
be overridden by the backend if desired. Add experimental code to wdc_pcmcia
to use this in memory-mapped mode, disabled by default.
 1.190 11-Aug-2004  mycroft Add two helper functions -- wdc_datain_pio() and wdc_dataout_pio() -- which
encapsulate the logic for the various methods of transferring data. Use these
throughout.
 1.189 10-Aug-2004  mycroft Hold a reference between atabus_attach() and atabusconfig() to avoid an extra
enable/disable cycle. Now my CF card attaches a bit faster.

XXX This code is split strangely between files.
 1.188 10-Aug-2004  mycroft Be robust against the case of the child devices failing to decrement the
refcnt.
 1.187 04-Aug-2004  bouyer Change wdc_kill_pending() to take a struct ata_drive_datas * as argument,
and kill only pending requests for this drive.
Implement a DRIVE_WAITDRAIN flag, which will cause the active command to
be killed once complete.
Other minor fixes.
Now it's possible to detach a ATA or ATAPI device from ioctl even when
a dd on the raw char partition is running.
 1.186 04-Aug-2004  bouyer Add
struct ata_xfer *active_xfer
to ata_queue. Now the active xfer isn't the head of the queue any more,
this makes a few things easier (this will also help for tagged queuing
support).
Remove the WDCF_ACTIVE flag, test active_xfer != NULL instead.
clean up wdc_free_xfer() and kill_xfer().
Clean up wdc_reset_channel(), and make it issue a ATAPI_SOFT_RESET if the
active command is ATAPI.
In wdc_atapi_get_params(), use AT_WAIT | AT_POLL for ATAPI_SOFT_RESET,
so that we'll use tsleep() instead of delay().
In wdc_atapi_start(), call wdc_dmawait() at the right place.
 1.185 02-Aug-2004  bouyer Make it possible for (*dma_finish)() to abort quietly a DMA op. Use this
in wdc_reset_channel().
 1.184 02-Aug-2004  bouyer Clean up interraction between wdc_reset_channel and the kernel thread.
Move kill_xfer() after the reset, and stop the DMA engine if needed
(this will unload the DMA maps).
 1.183 01-Aug-2004  bouyer Implement an atabus control device, and define some ATA bus control
IOCTLS. Implement ATABUSIORESET, which will reset the given ATA bus.
 1.182 31-Jul-2004  bouyer Implement asynchronous channel reset.
Use this to reset the channel before doing a dump, instead of the hack in
wdc_exec_xfer() based on C_POLL. This hack was causing problems on
controllers with a shared queue, because we now can have C_POLL set during
concurent channels probes (problem found and analysed on sparc64 by
Martin Husemann).
This should even make core dumps marginally more reliable on ATA drives.
 1.181 23-Jun-2004  bouyer For now, remove the ATAPI_SOFT_RESET done at attach time. I added this to get a
IBM pcmcia external cdrom drive working, but it cause troubles for others
IDE/ATAPI devices. Need to find another way to get this IBM drive to probe.
 1.180 01-Jun-2004  mycroft Only downgrade modes due to an actual CRC error. Downgrading on other errors
is anti-social -- especially given that there's no way to upgrade again short
of rebooting.

Also, downgrade UDMA modes more slowly. It's entirely possible that they're
using an 80-wire cable, but it's just too long for the higher modes, or there
is minor crosstalk.
 1.179 27-May-2004  mycroft Write the registers in the proscribed order -- sector,cyllo,cylhi (LSB first
for LBA). This make no difference with real devices, but the funky IDE
analyzer can't search properly if the order is wrong.
 1.178 27-May-2004  thorpej Clean-up of use of "precomp". It is used as "features" everywhere, so
rename the fields in wdc_command as appropriate.
 1.177 27-May-2004  thorpej In wdcccommand(), load wd_features, not wd_precomp, with the features
provided by callers.

From Jordan Rhody @ Wasabi.
 1.176 25-May-2004  thorpej Add the notion of "shadow registers" to the wdc driver. These shadow
registers are registers that overlap with others on many controllers, but
which may actually be distinct on some controllers. Right now, the two
shadows are:

- wd_status (usually overlaps wd_command)
- wd_features (usually overlaps wd_error)

Add a new helper function, wdc_init_shadow_regs(), used to initialize
the shadow register handles on controllers where they do actually overlap.

Partially from Jordan Rhody @ Wasabi Systems, Inc.
 1.175 24-May-2004  bouyer Add a delay(5000) between the ATAPI_SOFT_RESET and the channel reset.
Some ATAPI device never get out of busy if touched too fast after a reset.
Delay value from atapi_wdc.c; fix problem reported by Nicolas Joly on
current-users.
 1.174 15-May-2004  bouyer In wdcprobe1(), protect the register writability test with splbio().
What we do here seems to trigger interrupts on some pcmcia adapters, which
cause the kernel to hang.
Add some WDCDEBUG_PRINT((), DEBUG_PROBE).
Avoid touching registers of nonexistent drives, once we know which drive is
or is not here.

This makes the "IBM PCMCIA Portable CD-ROM Drive" (external CD drive with
PCMCIA adapter) work.
 1.173 08-May-2004  bouyer Add a delay(10) after re-enabling interrupts in the control register.
Some controllers/drives (e.g. SataLink 3114 with WD Raptor) require
it. Should fix kern/23808 by Chris Gilbert, patch suplied by Chris Gilbert
on tech-kern, extended to all places enabling interrupts by me.
 1.172 25-Mar-2004  bouyer branches: 1.172.2;
Deassert RST before re-enabling interrupts. Some drives (or controller)
require it.
From Michael van Elst in kern/24904.
 1.171 07-Jan-2004  thorpej Add a comment about some code that should be cleaned up.
 1.170 03-Jan-2004  thorpej More structure member namespace cleanup: thread -> ch_thread
 1.169 03-Jan-2004  thorpej More wdc_channel structure member namespace cleanup:
- channel -> ch_channel
- wdc -> ch_wdc
 1.168 03-Jan-2004  thorpej Rename "struct channel_softc" to "struct wdc_channel".
 1.167 01-Jan-2004  thorpej Tidy this file up a little.
 1.166 01-Jan-2004  thorpej Prepend "wdc_" to wait_for_drq, wait_for_unbusy, and wait_for_ready.
 1.165 01-Jan-2004  thorpej Rename:
- wdc_xfer to ata_xfer
- channel_queue to ata_queue
and move them to <dev/ata/atavar.h> so they can be used by non-wdc ATA
controllers. Clean up the member names of these structures while at it.
 1.164 30-Dec-2003  thorpej Move the drive probing code out of atabusconfig() and into a new
wdc_drvprobe() function. wdc_drvprobe() is used if the controller
does not specify a custom one prior to calling wdcattach(). The
WDC_CAPABILITY_DRVPROBE bit is gone.
 1.163 30-Dec-2003  thorpej Use ANSI function decls.
 1.162 30-Dec-2003  thorpej Move most of the atabus layer into ata.c.
 1.161 15-Dec-2003  thorpej Add a (*drv_probe)() optional callback into the driver to probe for
drives on a channel. Drivers should provide this if they have some
sort of intelligent probing mechanism.
 1.160 14-Dec-2003  thorpej Rename __wdcprobe() to wdcprobe1().
 1.159 14-Dec-2003  thorpej No need to include wdvar.h anymore.
 1.158 29-Nov-2003  he Patterned after the rest of the code, add one more check that
chp->wdc is non-null before de-referencing it.
 1.157 27-Nov-2003  fvdl There are some cards that map the ATA control and IDE DMA registers
in a different fashion. Individually, they have the same functionality,
but their layout is different. An example of such a chipset is
the Promise 203xx.

To be able to deal with this, transform the cmd and dma bus_space handles
into an array of handles, each seperately created with bus_space_subregion.
The code generated by using the extra indirection shouldn't change much,
since the extra indirection is negated by having the offset calculation
already done in bus_space_subregion. E.g.

bus_space_write_4(tag, handle, offset, value)

becomes

bus_space_write_4(tag, handles[offset], 0, value)

Reviewed by Manuel Bouyer. Tested on wdc_isa, wdc_pcmcia, viaide, piixide (i386)
and on cmdide (sparc64).
 1.156 25-Nov-2003  bouyer Some combination of controller/drive sends a continous stream of
interrupt while SRST is asserted. Work around by blocking interrupts while
SRST is asserted, and clearing any pending interrupt before unblocking.
Fix kern/23529 from Michael Hertrick.
 1.155 17-Nov-2003  bouyer Clear DRIVE_ATA|DRIVE_ATAPI for both drives only when we're sure this is
an old drive. Should fix kern/23468.
When we know there's no drive here, abort the probe and try next drive.
 1.154 13-Nov-2003  bouyer If we detected an old drive on a channel, clear (ATA|ATAPI) for both
drives on the channel.
 1.153 07-Nov-2003  bouyer If we already have a channel reset pending, don't try to queue a new one.
Otherwise we would bump queue_freeze several times, but the kernel thread would
decrease it only one time.
Fix PR kern/23377 by Mattias Karlsson, and should also fix similar problem
reported by Mihai CHELARU and Bruce J.A. Nourish on current-users.
 1.152 02-Nov-2003  wiz Fix some typos. From Tom Cosgrove via jmc@openbsd.
 1.151 31-Oct-2003  briggs Use aprint_*(9) instead of printf() in attach routines.
 1.150 30-Oct-2003  simonb Remove some assigned-to but otherwise unused variables.
 1.149 29-Oct-2003  bouyer Remove check for the error register value at probe time. There have been report
on -current-users of some drives not returning the proper value here.
This shouldn't affect the probe time for the common cases.
 1.148 29-Oct-2003  bouyer freese->freeze, as pointed out by Frederick Bruck.
 1.147 29-Oct-2003  bouyer - test if we have some work to do before tsleep() in the kernel thread,
in case the previous loop scheduled some more work to do (e.g. reset)
- use queue_freese to block the queue when a reset is pending too
- Avoid using WDCF_TH_RUN in some place that can be called from callout.
If the kernel thread is tsleep()ing somewhere, we may come here with
WDCF_TH_RUN set while being in the callout context. Fix a panic() in
tsleep() reported by Chuck Silvers.
- Use AT_WAIT instead of WDCF_TH_RUN wdcwait(), as we may not be in the
channel's thread context but still be able to tsleep(). Fix queue_freese
panics for WDC_CAPABILITY_NOIRQ controllers (port-mac68k/23208 by
Frederick Bruck).
 1.146 25-Oct-2003  christos more uninitialized variables
 1.145 25-Oct-2003  christos fix uninitialized variables
 1.144 22-Oct-2003  briggs Avoid a race condition that could allow a removable controller (such as
a compact flash card) to lock the atabus thread if it gets detached during
the probe process.
 1.143 15-Oct-2003  bouyer Make sure chp->atabus is initialised, and wakeup the right address when
shutting down the kernel thread.
 1.142 15-Oct-2003  bouyer - don't ignore last bit when checking for floating bus value on slave
device; some ATAPI devices as master will report 0x7f in all registers
for slave before reset
- For the same reason, remove the er1 check.
Makes slave device with a "strange" ATAPI master probe again.
Problem reported and fix tested by Gary Duzan on current-users.
 1.141 15-Oct-2003  bouyer Clear chp->ch_drive[i].drive_flags if we didn't find a driver for the
drive.
 1.140 12-Oct-2003  bouyer Remove block that has been pasted twice. Pointed out by Alexander Yurchenko.
 1.139 09-Oct-2003  bouyer Remove the check for WAIT+POLL+READ case in __wdccommand_start(),
this case is already handled in __wdccommand_intr().
Pointed out by Charles M. Hannum.
 1.138 08-Oct-2003  bouyer Following Matt Thomas's request, rename ata attribute to ata_hl, and
wdc_base to ata. We can now have
atabus* at ata?
in kernel config files.
 1.137 08-Oct-2003  bouyer Make the ATA mid-layer appears as atabus, as proposed in
http://mail-index.netbsd.org/tech-kern/2003/09/25/0006.html
This adds a device (atabus) between IDE controllers and wd or atapibus, to
have each ATA channel show up in the device tree. Later there will be atabus
devices in /dev, so that we can do IOCTL on them.
Each atabus has its own kernel thread, to handle operations that needs polling,
e.g. reset and others.

Device probing on each bus it defered to the atabus thread creation.
This allows to do the reset and basic device probes in parallel, which reduce
boot time on systems with several pciide controllers.
 1.136 08-Oct-2003  mycroft We really don't need to do 2 resets in wdc_channel_attach() -- the one done
by wdcprobe() is enough.
 1.135 06-Oct-2003  bouyer Revert to polling for ata_get_params() in wdc_channel_attach().
When probing a nonexistent slave, we may timeout waiting for an interrupt.
In __wdccommand_start(), for polled data in commands, abort quickly if
status still read 0 after 400ns (for a nonexistant slave, the
command will either be aborted, or the status register will report 0; for
a real device we should have BSY, DRQ or ERR).
Thanks to Alexander Yurchenko for reporting the problem and testing the
fix.
 1.134 25-Sep-2003  mycroft Hide the use of config_interrupts() in one place.
 1.133 25-Sep-2003  bouyer Don't print modes we are using if we don't know which modes are really used.
 1.132 23-Sep-2003  bouyer Fix a typo that prevented pre-ata drives from working since 1999.
 1.131 23-Sep-2003  mycroft Fix more probe delay and/or failure problems:
1) Don't wait for DRQ on an IDENTIFY command -- if it's not set when we see
BSY clear, abort the command and ignore the drive. (Do this by testing
for DRQ in the read/write cases in __wdccommand_intr().)
2) Don't wait for DRQ to deassert when we finish an IDENTIFY (or any other
non-block command that reads data) -- we don't do this for block I/O, and
empirically it doesn't clear on my CF cards at all, causing a pointless 1s
delay.
3) Add comments to some of the delay()s, and add missing ones in wdcreset()
and the WDCC_RECAL in the so-called "pre-ATA" probe.
4) Slightly simplify the reset sequence -- we were doing an extra I/O.
5) Modify the register writability test to make sure that registers are not
overlapped -- this can happen in some weird cases with a missing device 1.
6) Check the error register value after the reset -- if it's not 01h or 81h,
as appropriate (see ATA spec), punt.
Tested with a number of ATA-only, ATAPI-only, mixed ATA-ATAPI, CF, and IDE
disk configurations.

Also remove the SINGLE_DRIVE nonsense again.
 1.130 21-Sep-2003  enami Correctly resurrect the style in previous. While I'm here, also removed
whitespace at the end of line in comment.
 1.129 21-Sep-2003  bouyer Since we can't detect ghost drives in the wdc back-end, resurect
WDC_CAPABILITY_SINGLE_DRIVE.
 1.128 20-Sep-2003  bouyer Remove the "Register ghost test". It won't work, because on ATA register
of both devices are written, and device 0 will respond for device 1 if
device 1 isn't present. Pointed out by Quentin Garnier.
So the only way to know if device 1 is there or not is to send a command, which
is done later.
Detecting the second device here isn't important and won't speed up the probe.
We just need to know if there is at last one device on the bus.

Fix PR kern/22869 from Julio M. Merino Vidal.
 1.127 20-Sep-2003  christos print the name of the driver that found the ghost
 1.126 20-Sep-2003  enami Now wdcattach() is called interrupts enabled, config_interrupts() tries to
call ata_raid_check_component() immediately, and panics since DMA setup
isn't done yet. So, defer the call until attach stage is almost done.
Tested with Promise TX2000.
 1.125 19-Sep-2003  mycroft 1) Use config_interrupts() to attach IDE and ATAPI drives. This eliminates
most polling.
2) Clean up some goofiness in pciide -- get rid of the whole "candisable" path
(it's gratuitous) and simplify the code by calling pciide_map_compat_intr(),
*_set_modes() and wdc_print_modes() from central locations.
3) Add a register writability and register ghost test to eliminate phantom
drives more quickly.
 1.124 17-Sep-2003  drochner typo in comment
 1.123 17-May-2003  thorpej branches: 1.123.2;
* Use aprint*().
* Add Ultra/133 to wdc_print_modes().
 1.122 27-Jan-2003  thorpej Experimental support for RAID volumes configured by ATA "RAID" controllers.
Such RAID controllers are actually just IDE controllers with a BIOS that
can create RAID volumes and write the configuration info to config blocks
on the disks. The BIOS can do I/O to these volumes, and the OS must
understand the config blocks and implement RAID in software in order to be
able to use these volumes.

Only SPAN (simple concatenation) and RAID0 are supported at this time,
and writing back config blocks is also not supported at this time. Currently,
only the Promise configuration scheme is supported, although supporting
the Highpoint scheme should not be too difficult.

In any case, this is sufficient to use the Promise RAID0 volume (thus
preserving the win2k AS installation) on this new Intel server I have.

Thanks to Soren Schmidt for doing the work in FreeBSD; it made this
task much easier. The config block parsing code is adapted from his
work.
 1.121 20-Jan-2003  simonb Remove variable that is only assigned too but not referenced.
 1.120 01-Jan-2003  thorpej Use aprint_normal() in cfprint routines.
 1.119 06-Dec-2002  drochner typo in comment
 1.118 27-Sep-2002  provos remove trailing \n in panic(). approved perry.
 1.117 25-Aug-2002  bouyer Add support for Ultra/133 (ultra-DMA6) in wdc_probe_caps().
 1.116 26-Jul-2002  wiz Two typos in comments.
 1.115 12-Jun-2002  bouyer Bump delay() between reset and IDENTIFY from 100 to 5000. Some ATAPI devices
wedge when talking to them too soon, and incorrectly react to WDC_RESET.
Close PR kern/17208 by Paul Goyette.
 1.114 09-Apr-2002  bouyer branches: 1.114.2; 1.114.4;
In wdc_exec_command(), for data commands, read the status register after
the data transfer. This is mandatory for data out commands (although none are
used for now), and not forbiddend for data in commands. Also record if we
did transfers any data.
May solve kern/16159 by making the probe more robust in face of fake identify.
 1.113 28-Mar-2002  bouyer In wdcintr(), it !WDCF_IRQ_WAIT, read the status register anyway to clear a
possible pending interrupt. This should avoid the interrupt loop described
in PR kern/15841.
It is safe to read status here, because if we're not waiting for an interrupt
we have no command pending, so the device should be idle.
 1.112 08-Mar-2002  thorpej Pool deals fairly well with physical memory shortage, but it doesn't
deal with shortages of the VM maps where the backing pages are mapped
(usually kmem_map). Try to deal with this:

* Group all information about the backend allocator for a pool in a
separate structure. The pool references this structure, rather than
the individual fields.
* Change the pool_init() API accordingly, and adjust all callers.
* Link all pools using the same backend allocator on a list.
* The backend allocator is responsible for waiting for physical memory
to become available, but will still fail if it cannot callocate KVA
space for the pages. If this happens, carefully drain all pools using
the same backend allocator, so that some KVA space can be freed.
* Change pool_reclaim() to indicate if it actually succeeded in freeing
some pages, and use that information to make draining easier and more
efficient.
* Get rid of PR_URGENT. There was only one use of it, and it could be
dealt with by the caller.

From art@openbsd.org.
 1.111 04-Mar-2002  simonb Don't "extern int cold;" - this is in <sys/kernel.h>.
 1.110 31-Jan-2002  simonb White-space niggle.
 1.109 14-Jan-2002  bouyer Don't use chp->wdc if it's NULL.
 1.108 13-Jan-2002  christos Add LBA48 support based on patches from Keisuke YOSHIDA. KNF a bit while
I am there.
 1.107 07-Jan-2002  dbj Changes to the wdc(4) mi driver that add the WDC_CAPABILITY_SELECT
flag and a callback function which gets called whenever a target is
selected on a channel.

The macppc wdc driver needs to reprogram its timing register
differently for each target on a channel each time that target is
selected. I also changed the ATA4_TIME_TO_TICK to use a divisor of
15, which brings our timing calculations consistent with darwin.

These patches fix problems on my dual usb ibook with combo dvd/cdrw
drive because the hard drive supports udma and the combo drive does
not. Without turning off the udma timings in the configuration
register, I cannot access the non-udma combo drive.
 1.106 05-Dec-2001  bouyer Compile with NWD == 0. Fixe kern/14844 by hamajima@nagoya.ydc.co.jp.
 1.105 03-Dec-2001  enami Use correct format letter for chp->channel.
 1.104 03-Dec-2001  bouyer Update my copyrigth.
 1.103 03-Dec-2001  bouyer Allow wd to attach to something else than wdc/pciide (like USB<->ATA bridges):
- move some functions from ata.c to ata_wdc.c or wdc.c.
- add callbacks to struct ata_bustype so that wd.c doesn't call directly
functions from the lower level driver.
 1.102 02-Dec-2001  bouyer Clean up attach of wd/atapibus:
kill ata_atapi_attach. Change atapibus to use a struct scsipi_channel instead
of ata_atapi_attach as attach arch. Create a ata_device, compatible with
scsipi_channel, to attach wd.
 1.101 14-Nov-2001  bouyer If the controller doesn't support UDMA, don't allow enabling UDMA via
config flags.
 1.100 13-Nov-2001  lukem add/cleanup RCSID
 1.99 18-Sep-2001  chs in wdc_get_xfer(), avoid crashing if pool_get() fails.
 1.98 13-Jun-2001  bjh21 branches: 1.98.2; 1.98.4;
Add explicit support for IDE and SCSI adaptors which don't support interrupts.
On such adaptors, all transfers are done in polling mode.

OK'ed by Manuel on tech-kern.
 1.97 11-Jun-2001  bjh21 Add a short-circuit return from wdcprobe for IDE controllers without pullup
resistors, which return the last value written to the bus on a read. This
makes detecting empty channels on my HCCS and D.T. Software IDE interfaces
rather faster.
 1.96 25-Apr-2001  bouyer Pull up the thorpej_scsipi branch to main branch.
This is a completely rewritten scsipi_xfer execution engine, and the
associated changes to HBA drivers. Overview of changes & features:
- All xfers are queued in the mid-layer, rather than doing so in an
ad-hoc fashion in individual adapter drivers.
- Adapter/channel resource management in the mid-layer, avoids even trying
to start running an xfer if the adapter/channel doesn't have the resources.
- Better communication between the mid-layer and the adapters.
- Asynchronous event notification mechanism from adapter to mid-layer and
peripherals.
- Better peripheral queue management: freeze/thaw, sorted requeueing during
recovery, etc.
- Clean separation of peripherals, adapters, and adapter channels (no more
scsipi_link).
- Kernel thread for each scsipi_channel makes error recovery much easier
(no more dealing with interrupt context when recovering from an error).
- Mid-layer support for tagged queueing: commands can have the tag type
set explicitly, tag IDs are allocated in the mid-layer (thus eliminating
the need to use buggy tag ID allocation schemes in many adapter drivers).
- support for QUEUE FULL and CHECK CONDITION status in mid-layer; the command
will be requeued, or a REQUEST SENSE will be sent as appropriate.

Just before the merge syssrc has been tagged with thorpej_scsipi_beforemerge
 1.95 21-Mar-2001  bouyer Add a small delay before reset at attach time, required by one old ATAPI
CD. Reported by Onno van der Linden.
 1.94 06-Jan-2001  takemura branches: 1.94.2;
Add WDC_CAPABILITY_SINGLE_DRIVE to ignore secound drive. Wdc on pcmcia will
be attached with this flag.
Some CF Card (for ex. IBM MicroDrive and SanDisk) doesn't seem to implement
drive select command. In this case, you can't eliminate ghost drive properly.
So you should use this flag to ignore the ghost by force.
 1.93 08-Nov-2000  wrstuden Move guts of pciide_print_modes() to wdc_print_modes() so that non-pciide
wdc drivers (like macppc's obio IDE interface) can use it. Also add
support to both wd attach line and to wdc_print_modes() to print
Ultra/{33,66,100} for respective UDMA modes (From Manuel Bouyer).
 1.92 28-Jun-2000  mrg remove include of <vm/vm.h>. <vm/vm.h> -> <uvm/uvm_extern.h>
 1.91 12-Jun-2000  bouyer branches: 1.91.2;
Add a callback (*irqack), for controllers that need special action to ack
the interrupt once it has been ack'd on the drive.
 1.90 11-Jun-2000  bouyer Relax condition on 'sn' for atapi probe, it can be different from 0x1 with
some controllers/devices. Fixes a problem reported by Markus Illenseer.
 1.89 12-May-2000  bouyer branches: 1.89.2;
Accept any 'sc' value when probing atapi drives: with some drives, or
controllers, or combination of both, the value can be different from the
expected one after a reset.
 1.88 05-Apr-2000  mrg avoid using uninitalised variables inside WDCDEBUG.
 1.87 04-Apr-2000  bouyer Add checks to detect busy-waits, conditionnal on new debug flag
DEBUG_DELAY (0x40). This will print how much time we did loop in wdcwait(),
if we had to read registers more than one time.
 1.86 04-Apr-2000  bouyer Better fix to previous: delay(100) before the IDENTIFY, and if it fails
delay(1000000) and retry. The 1s delay is needed for some special case only,
no need to hang the machine for that long everytime (especially for PCMCIA).
 1.85 01-Apr-2000  bouyer Bump delay() from 100 to 1000000 before attempting a IDENTIFY just after a
reset - solves a problem reported by cpg@aladdin.de.
 1.84 01-Apr-2000  bouyer - DMA code cleanup: pciide_dma_finish() doesn't stop/unload the current DMA op
if an IRQ was not detected, unless the force flag was given. Use this to
detect if the IRQ was for us (closer to shared IRQ for controllers which
don't have their own IRQ handler in pciide.c) and to poll for DMA xfer.
Also makes the timeout recovery code simpler.
- ATAPI cleanup: don't call controller-specific functions from atapiconf.c
(wdc_*), so that it's possible to attach an atapibus to something else
than a wdc/pciide (Hi Lennart :).
Overload struct scsi_adapter with struct atapi_adapter, defined
as struct scsi_adapter + atapi-specific callbacks. scsipi_link still points
to an scsi_adapter, atapi code casts it to atapi_adapter if needed.
Move atapi_softc to atapiconf.h so that it can be used by the underlying
controller code (e.g. atapi_wdc.c).
Add an atapi-specific callback *atapi_probedev(), which probe a drive
in a controller-specific way, allocate the sc_link and fills in the
ataparams if needed. It then calls atapi_probedev() (from atapiconf.c)
to do the generic initialisations and attach the device.
- While I'm there merge and centralise the state definitions in atavar.h.
It should now be possible to use a common ata/atapi routine to set the
drive's modes (will do later).
 1.83 29-Mar-2000  simonb Remove reduncdant decl of wdc_kill_pending - it's in <dev/ic/wdcvar.h>.
 1.82 23-Mar-2000  soren s/32-bits/32-bit/ (Hi Al!)
 1.81 23-Mar-2000  thorpej New callout mechanism with two major improvements over the old
timeout()/untimeout() API:
- Clients supply callout handle storage, thus eliminating problems of
resource allocation.
- Insertion and removal of callouts is constant time, important as
this facility is used quite a lot in the kernel.

The old timeout()/untimeout() API has been removed from the kernel.
 1.80 20-Mar-2000  enami - Test the generic device active flag instead of home grown one.
- Test also it in wdcintr.
 1.79 14-Feb-2000  bouyer - Be more strict in status check before sending a command (make sure
DRQ is not asserted). Closes kern/9346.
- Change the "fake identify before the real one" by a delay(). The real cause
of the problem is that the drive is unresponsive just after a reset.
The real problem (and the solution) showed up after the first change.
 1.78 17-Jan-2000  bouyer Improve the downgrade logic:
- If UDMA 2 is failing try UDMA 1 first, it helps in some cases
- downgrade if we get an error in the first 4000 xfers, or if we get
4 errors in 4000 xfers if the first 4000 went without troubles.

While I'm there commit a local change I have since some time to get my CD
probed: issue a "blanck" IDENTIFY before the one used to detect slave ghosts,
with my drive the first IDENTIFY following a controller reset fails with an
aborted command ...
 1.77 28-Nov-1999  bouyer Improve a few debug messages.
 1.76 21-Oct-1999  bouyer If IRQ was not for us, add back WDCF_IRQ_WAIT to the flags, so that
the next IRQ (real or timeout) will be handled.
Fixes the 'missing untimeout' problem reported by a few peoples, and
kern/8639.
 1.75 20-Oct-1999  enami Cancel active transfers on aic/wdc detach.
Also makes LS-120 drive works for me again.
 1.74 23-Sep-1999  enami branches: 1.74.2; 1.74.4; 1.74.6;
Allow to detach wdc, atapibus, wd and cd.
 1.73 30-Aug-1999  bouyer If we are using UDMA mode > 2 and get a DMA error, downgrade to UDMA mode 2
first: maybe we incorrectly guessed the cable type.
 1.72 25-Aug-1999  bouyer Guard pool_get()/pool_put() with splbio()/splx(). Fix kern/8245.
 1.71 09-Aug-1999  bouyer - use pool(9) for wdc_xfer, instead of managing a free list.
- fix printing of Ultra-DMA modes (shows up when the drive supports highther
modes than the controller).
- Don't use C_NEEDDONE anymore. We were setting this flag in a possibly
freed wdc_xfer (this didn't create problems, as it was free'd in the POLL
case only, while IRQs are blocked, but it's not good practice anyway
and pool(9) complains about it ;)
 1.70 06-Aug-1999  bouyer - Add some debug printf (WDCPROBE) in _wdcreset_wait(), I've needed these
2 times in the past
- Set up timeout per xfer instead of per interrupt. This helps with
PIO transfer (we would call timeout()/untimout() several times for a
transfer).
- If we missed an interrupt for a PIO transfer, reset and restart it
immedialy, don't try to recover and continue. If we missed an interrupt we
may have lost a read/write cycle on the IDE bus. If this happens 1) we
corrupt data and 2) we enter an interrupt loop at the end of the xfer, as
the drive has some more data to read/write, but the host thinks the xfer is
done.
This last change fix the (or at last some of the) 'lookup after lost interrupt'
some peoples have been experiencing.
 1.69 30-Jul-1999  bouyer Guard tsleep() with a while (!(wdc_c->flags & AT_DONE)) {}, as suggested by
Constantine Sapuntzakis confirmed by Bill Sommerfeld. Although nothing is
supposed to call wakeup on this without setting AT_DONE, it's good practice to
do it this way (the process may be waken up by a setrunnable() call).
 1.68 23-Jun-1999  bouyer Resurect the old register read/write test for non-ATA/ATAPI drives, to avoid
false matches on controllers which properly respond to a WDCC_RECAL command.
Should close PR port-i386/7702 (the author tested this patch, and said it
solves his problem).
 1.67 11-Apr-1999  bouyer Fix probe code for IDE devices:
- Don't rely on ATA signature: some ide controllers seems to not transmit it
properly (SIMIDE on arm32 machines). Instead, when we guess a drive is here
after reset, just mark it as ATA and OLD is it's not ATAPI.
- at attach time, use IDENTIFY to eliminate ghost from the probe. If the
drive had the old flag and IDENTIFY failed, issue a WDCC_RECAL command
to detect a pre-ATA disk. If IDENTIFY succeded, remove the OLD flag,
it's obviously not a pre-ATA disk.
- add a new controller flag, WDC_CAPABILITY_PREATA, used to shorcut parts
of the probe (not necessary, but makes the probe/attach faster). This is
only set by the ISA front-end, all other controllers supported can't have
pre-ATA drives attached.
The mechanism used are more or less the same as before, they have just been
reordered. Should solve port-arm32/7324 (waiting for feedback).
 1.66 01-Apr-1999  bouyer branches: 1.66.2;
- change the interrupt routines to take a 3rd arguments, set to 1 if we
are called from the interrupt or timeout handler, 0 otherwise.
- use this to know if we can busy-wait for wait_for_unbusy or wait_for_ready
This fixes a bug where CDs withot the DRQ_INTR capability would not busy-wait
for the CMDOUT phase.
While I'm there change 2 delay() to DELAY() for consistency, and
garbage-collect some old code from wdcintr() which has been ifdef'd out
for some time now.
 1.65 31-Mar-1999  bouyer Increase some DELAY(), this seems required on some hardware (I'm not sure if
the hardware is at fault, or if DELAY(1) waits for less than 1us).
Improve debuging messages for wdcreset_wait().
 1.64 29-Mar-1999  bouyer Remove the hack to attach devices responding with ATA signatures as atapi if
IDENTIFY said so: it doesn't help for the drive this was supposed helping,
and seems to break another device.
In interrupt routine, don't return 0 if we are polling: this should fix the
"panic: wdc_exec_command: polled command not done" some people reported
(kern/7269).
 1.63 25-Mar-1999  bouyer Avoid busy-waiting when possible if we are not polling (real IRQ or timeout
callback). Shared PCI IRQ should now work (but still untested).
 1.62 10-Mar-1999  bouyer Add a new disk flag: DRIVE_OLD for pre-ATA disks. probe routine will now set
DRIVE_OLD, DRIVE_ATA or DRIVE_ATAPI based on register signatures.
The attach routine will issue a IDENTIFY command for ATA/ATAPI disk,
to detect flase matches by the probe routine.
probe/attach should now be fully compliant with ata-4/ata-5. As a side
effect, ATAPI drives which improperly use ATA register signatures should now
be attached as ATAPI.
 1.61 07-Mar-1999  bouyer Keep track of CRC errors in Ultra-DMA mode. If we noticed a CRC error and we
need to downgrade, downgrade to PIO, as it has been shown if we got CRC errors
in Ultra-DMA mode, we will have silent data corruption in multiword DMA mode
(isn't IDE wonderfull ? :).
Set timeout to 1s for "normal" ata I/O, to minimise the effects of missed
interrupts.
 1.60 21-Feb-1999  abs wdcwait is called initially without any device on my thinkpad.
This breaks the first WDCDEBUG_PRINT. Handle this case.
 1.59 20-Feb-1999  hubertf Only #define WDCDEBUG if it isn't already defined (e.g. by some options
in the kernel config file).
 1.58 18-Feb-1999  bouyer Don't print an extra newline if the controller doesn't support 32 bits access.
Pointed out by Dave Huang.
 1.57 15-Feb-1999  bouyer Be less strict on ATAPI signature, at last one CD puts 0x00 in sc instead
of 0x01.
 1.56 08-Feb-1999  bouyer There's no ATA draft where it is required for the drive to set DRDY | DSC when
the disk is ready to transfer data, and in ATA-5 the DSC has been obsoleted.
So only wait for DRQ to transfer data. This can be made conditional on the
ATA version if it's proven to break with some drives (worked with all the
drives I have access to).
While I'm there correct a few typos.
 1.55 18-Jan-1999  bouyer move wd.c:print_wderror() to ata.c:ata_perror().
In wdc_probe_caps() add code to guess the ATA revision supported (if
ATA4 if Ultra-DMA, ATA2 if PIO mode > 2). We can't rely on param.atap_ata_major
here, at last one Ultra-DMA drive claims to support only ATA-3.
Use the ATA version in ata_perror(), and to try a flush cache command
in a shutdown hook for IDE drives.
 1.54 16-Dec-1998  bouyer Keep track of DMA errors, and downgrade the transert mode (UDMA ->DMA,
DMA->PIO) in case of 2 consecutive errors. Don't downgrade if the
PIO/DMA/UDMA modes were forced by a config flag.
 1.53 08-Dec-1998  bouyer Add a missing 'return' in an error path; noticed by Matthias Drochner.
 1.52 03-Dec-1998  bouyer Rename pio_mode, etc ... to PIO_cap, etc ... for consistency with the
ata_drive_datas struct. Suggested by Soren S. Jorvan.
 1.51 03-Dec-1998  bouyer UDMA->Ultra-DMA in a printf
 1.50 03-Dec-1998  bouyer add a udma_mode field to wdc_softc, and use it the same way dma_mode is used
(higthest ultra-dma mode supported). There may be a higther ultra-dma mode
defined ...
 1.49 02-Dec-1998  bouyer In struct wdc_xfer, change 'channel' to a pointer to a channel_softc, to avoid
a double-pointer dereference at run-time. Suggested by Matthias Drochner.
 1.48 02-Dec-1998  bouyer - change drive_flags from u_int8_t to u_int16_t
- keep the modes supported by the drive in struct ata_drive_datas (will be
later used for downgrading the DMA/PIO mode on error)
- use config flags to force/disable PIO/DMA/UDMA modes
- For the CMD PCI0643/6 setup DMA mode to DMA Read multiple.
 1.47 29-Nov-1998  bouyer wdcstart(): Re-add support of shared xfer queue across multiple channels
(was lost between 1.44 and 1.45).
 1.46 23-Nov-1998  kenh Implement the AT_READREG flag. This is needed for the CHECK POWER MODE
ATA command (among others).
 1.45 21-Nov-1998  drochner in wdc_softc: access the per-channel data via a pointer array instead of
an array of fixed-sized channel_softc elements. This way IDE controllers
which more than 1 channel (pciide) can extend the channel data easily
for private needs.
To avoid the double dereference at runtime, change the argument of
wdcstart() to the channel data pointer instead of the array index.
 1.44 20-Nov-1998  thorpej Implement reference counting for ATA adapters.
 1.43 19-Nov-1998  kenh Sigh, my bad. Check for chp->wdc being NULL before trying to deference it.
(I didn't realize the ISA wdc front-end doesn't fill in chp->wdc).
 1.42 19-Nov-1998  thorpej Back out revision 1.40. That change couldn't have POSSIBLY worked, since
when wdcprobe() is called, the wdc_softc pointer in the channel_softc
hasn't even been intialized!
 1.41 19-Nov-1998  kenh __wdccommand_done() needs to call wdcstart(), otherwise you can run
into deadlocks when using wdc_exec_command().
 1.40 18-Nov-1998  kenh Quirk out the first test in the beginning of wdcprobe(); the Vaio
CD-ROM drive doesn't like it for some reason.
 1.39 11-Nov-1998  bouyer - clearify the boot messages (features supported vs features used). Thanks to
Havard Eidnes for his complains about this :)
- fix some typo in comments
- hoppefully better detection of drives reporting bogus PIO modes.
 1.38 21-Oct-1998  bouyer If WDC_DIAGNOSTIC is defined, check in wdcstart() that we are called at
splbio.
 1.37 20-Oct-1998  bouyer Donc reset the disk state to 0 in wd.c, set a flag which will cause it
to be reset to 0 at wdcstart(). This fixes a race condition between
normal I/O and wdioclt().
 1.36 15-Oct-1998  bouyer Kill an extra printf("\n").
 1.35 13-Oct-1998  bouyer Add a new drive flag, DRIVE_MODE, set when the drive properly reported its
PIO/DMA modes. Don't try a SET_FEATURE if it didn't report its mode.
 1.34 13-Oct-1998  bouyer In debug message, always print controller:channel:drive
 1.33 13-Oct-1998  bouyer Properly separate DEBUF_XFERS and DEBUG_FUNCS: DEBUF_XFERS is for data
transfers (may be called often), where DEBUG_FUNCS is for setup functions
(not used for normal contitions).
 1.32 13-Oct-1998  bouyer pciide.c: don't define WDCDEBUG, so it compiles on alpha. Correct a bogon
in the printing of DMA mode (piix3/4 only)
others: set the debug_mask to 0, so that debug messages are turned off by
default but can be easily turned on.
Reset drive_flags to 0 for unconfigured devices, so that they are ignored
later. For configured devices, reset state to 0 after probe/attach.
 1.31 12-Oct-1998  bouyer Merge bouyer-ide
 1.30 10-Oct-1998  thorpej Garbage-collect the open_target_lu and close_target_lu entry points from
struct scsipi_adapter; they were not used.

Add a scsipi_ioctl entry point to struct scsipi_adapter. This will be
used to issue ioctl commands to the host adapters.

Inspired by PR #6090, from Matt Jacob.
 1.29 22-Sep-1998  mark Use the data32iot and data32ioh members of the wdc_attachment_data
structure for 32 bit transfers.
Test for 32 bit capability on data transfers currently restricted to 16 bit
only.
 1.28 10-Sep-1998  kenh Add support for passing device quirks from the attachment routine,
and add support for a NO_EXTRA_RESETS quirk (required by the TEAC
IDE Card/II, which the Vaio uses).
 1.27 15-Aug-1998  mycroft Assign my copyrights to TNF.
 1.26 14-Aug-1998  drochner explicitely select the master before trying to access its registers
 1.25 30-Jun-1998  hpeyerl Fix spalling misteak: indentify -> identify
 1.24 04-Jun-1998  enami branches: 1.24.2;
Make this compile with WDDEBUG
 1.23 28-Apr-1998  thorpej In wdcintr(), add a catch-all case so that this will compile if no
children are configured.
 1.22 26-Apr-1998  mycroft Update copyright.
 1.21 26-Apr-1998  mycroft In LBA mode, always use the `total capacity' count, rather than calculating
the capacity based on the c/h/s numbers. In fact, don't use the c/h/s
numbers for much of anything.
For ATA-4 drives or later, always use LBA mode, since it's now required.

Collectively, this allows >8GB disks (like the 12GB Bigfoot) to work.
 1.20 23-Apr-1998  bouyer From Robert V. Baron:
Compute the disk block addr at command queing time rather than exec time.
This fix a bug which could lead to data corruption on disk: when a command
was reexecuted after an error condition (from wdcunwedge), the partition
offset was re-added to the block addr, leading to a transfert at the wrong
disk block.
This should fix the problem reported by some laptop's users, where the
first disk read after a suspend/resume returned garbage.
 1.19 07-Apr-1998  leo Add hooks to make exclusive hardware locking possible. This is necessary
to make the driver suitable for the atari falcon.
 1.18 27-Mar-1998  cgd add a short delay (5ms) after ATAPI software reset is done, suggested by
Soren S. Jorvang <soren@t.dk>. Apparently some devices Really Want this.
 1.17 04-Feb-1998  sakamoto Change "__BUS_SPACE_NEED_STREAM_METHODS" to "__BUS_SPACE_HAS_STREAM_METHODS".
 1.16 03-Feb-1998  sakamoto Change the data access busification functions to
the "stream" busification functions.
In the architecture as the BeBox(CPU is big endian, have ISA bus),
These methods would be used where "raw" data needs to {read,write,set}
unchanged.

Add #ifndef __BUS_SPACE_NEED_STREAM_METHODS (define that on NetBSD/bebox),
if not define __BUS_SPACE_NEED_STREAM_METHODS,
define "stream" busification functions to normal busification functions.
 1.15 23-Jan-1998  mycroft Assume a newline has already been printed in wdcattach().
 1.14 15-Jan-1998  cgd #include a just-added scsipi header.
 1.13 15-Jan-1998  cgd kill a couple of unnecessary #ifs
 1.12 14-Jan-1998  cgd Various cleanups and bug fixes to the wdc/wd code:
* Fix bug in wdc that would overflow ATAPI transfer length.
* Improve wdc probe code so that 'wdc' is probed in if present
even if there are no drives attached, and so that it works
properly even if the only device is an ATAPI slave.
* bus_space-ify.
* split the ISA attachment from the wdc driver, and remove
ISA dependencies from non-ISA files.
* claim that wd and wdc are now machine-independent (probably not
completely true, but mostly so; they at least work on arm32 and
i386).
* Various other minor fixups and cleanups, some of which were pointed
out by Kazuki Sakamoto.
 1.11 12-Jan-1998  thorpej Update for config changes.
 1.10 07-Jan-1998  mikel fix some typos in error messages & comments
 1.9 24-Dec-1997  fvdl Add extra delay after wdcreset() call in wdcprobe. Needed by at least
one controller, where registers otherwise will still be inaccesible
(even though the busy bit has been reset), making the probe fail.
 1.8 05-Nov-1997  bouyer Various bug fixes for atapi part:
- clean up debug code
- Don't check ATAPI signature when probing ATA drives, ATAPI devices were
detected before
- Reset controller after disks probes. The probe, with some combinations of
ATA/ATAPI device keep it in a mostly working, but strange state (with busy
led on)
- The WDCF_IRQ_WAIT flag is now cleared by wdc_ata_intr and wdc_atapi_intr
when appropriate (helps recover from failure conditions)
- In wdcunwedge, send ATAPI_SOFT_RESET to non-ata drives
(helps recover from failure conditions)
- in wdctimeout be a bit more verbose when we missed an interrupt
- Always Increment xfer->c_skip where it should be
- Set the ITSDONE flag when a polled command completed.
 1.7 27-Oct-1997  bouyer Changes to the probe and attach routine:
- at end of attach, explicitely select an existing drive. This fixes hangs
some users reported (such as the one reported in port-i386/4247).
- Some atapi cdrom drives (e.g. Nec 24x) don't enables their registers before
a controller reset is issued. The controller probe routine is changed as
follow: issue a controller reset. If fail, test atapi signature on slave.
If fail, wait 5s and retry a reset. If the second reset fail, return(0).
If the first reset succeed, test presence of a master drive:
atapi signature, and if this fail RO/RW registers test. If no master, test
atapi signature on slave. If no slave, return 0.
 1.6 16-Oct-1997  matt branches: 1.6.2;
Fix a misspelling of slave in a comment.
 1.5 24-Sep-1997  bouyer Return the rigth value in the interrupt handler. This change the semantic
of wdc_atapi_intr, so we check for ITSDONE rather than the return value for
a pooled command.
 1.4 03-Sep-1997  bouyer Add a map to wdc_softc to track the already known devices to prevent them to
be probed several times. This fixes the "ATAPI CD probed as wd drive" problem.
Thanks to Geoff Wing <mason@primenet.com.au> for testing this on his hardware.
 1.3 28-Aug-1997  bouyer Change an ATAPI_DEBUG2->ATAPI_DEBUG. This debug message is needed when
looking what's the autoconfig do on strange harware, and ATAPI_DEBUG2 is
for debuging data transfers (and is really verbose once the machine has booted
from an IDE disk).
 1.2 27-Aug-1997  bouyer branches: 1.2.2;
Merge scsipi branch in the mainline. This add support for ATAPI devices
(currently only CD-ROM drives on i386). The sys/dev/scsipi system provides 2
busses to which devices can attach (scsibus and atapibus). This needed to
change some include files and structure names in the low level scsi drivers.
 1.1 01-Jul-1997  bouyer branches: 1.1.2;
file wdc.c was initially added on branch bouyer-scsipi.
 1.1.2.2 18-Jul-1997  bouyer Update from trunck:
fvdl: "Work around possible race condition with 2 drives on one controller
in wd_get_parms. PR 3773, from Onno van der Linden (onno@simplex.nl)"
 1.1.2.1 01-Jul-1997  bouyer Add the ide atapi driver from my original atapi driver, ported
to scsipi.
 1.2.2.4 29-Sep-1997  thorpej Update marc-pcmcia branch from trunk.
 1.2.2.3 04-Sep-1997  thorpej Update marc-pcmcia branch from trunk.
 1.2.2.2 01-Sep-1997  thorpej Update marc-pcmcia branch from trunk.
 1.2.2.1 27-Aug-1997  thorpej Update marc-pcmcia branch from trunk.
 1.6.2.3 24-Dec-1997  perry pull up emergency patch from trunk (fvdl)
 1.6.2.2 06-Nov-1997  mellon Pull rev 1.8 up from trunk (bouyer)
 1.6.2.1 27-Oct-1997  mellon Pull rev 1.7 up from trunk (bouyer)
 1.24.2.19 12-Oct-1998  bouyer Sync with HEAD.
 1.24.2.18 05-Oct-1998  bouyer Rename WDC_CAPABILITY_PIO to WDC_CAPABILITY_MODE, as it's used to tell wether
the controller's driver can tell which timing mode it uses. Check this
before setting DMA modes too.
This allow the generic DMA code to work again.
 1.24.2.17 04-Oct-1998  bouyer atavar.h: drv_softc is a struct device * instead of void*, as it's mostly
used for dv_xname
wd.c: convert for drv_softc type change, printf cleanup
wdc.c: always call ata_get_params() (params was used initialised with
non-32bit controllers, leaving to bogus PIO/DMA mode report).
Cleaup of the PIO/DMA mode message.
pciide_piix_reg.h: Fix definition of PIIX_IDETIM_CLEAR (unused before)
pciide.c: add a method do disable a channel on know device. If a channel
doesn't have any drive, we disable it and free its resources if disable
was successfull. This should help with laptops where the second channel
of the PIIX4 is unused but not disabled by BIOS. On such laptops,
irq15 can be used for PCMCIA but it was claimed by pciide.
Misc printf cleanup.
wdc_isa.c: printf cleanup.
 1.24.2.16 02-Oct-1998  bouyer Cleanup a few error message, remove some dead code. Re-add a reset at end of
attach, unless we have WDC_NO_EXTRA_RESETS.
Add support for data32iot/data32ioh from -current: each controller pass
WDC_CAPABILITY_DATA32 if they can do 32bit, and WDC_CAPABILITY_DATA16 if they
can do 16bit. For controller that support both, the usual autodetect
mechanism is still used.
 1.24.2.15 21-Sep-1998  bouyer Check ATAPI signature for all drives on a channel, before atempting the
register write test. The test on the first ATA drive will clobber the register
of the slave ATAPI.
 1.24.2.14 20-Sep-1998  bouyer Kill the 'old drive' flag. The probe for IDE controllers now looks
like this :
- if status = 0xff for both master and slave, no drive at all -> exit.
- issue a reset (timeout = 31s).
- test signatures: if ATAPI signature, flag a (possible) ATAPI devices here
else test register writability, then wait for the drive to become
ready, issue a diagnostic command and wait for the drive to become ready
if ok, flag a real ATA device.
This looks more like the old probe.
For ATA devices, if IDENTIFY fails, then it's an old drive and use
a fake disklabel/geometry.
 1.24.2.13 20-Sep-1998  bouyer - always call config_found() from wdcattach(), instead of printing our own
the "not configured" message ourselve. When no atapibus is configured,
use a fake ata_atapi_attach, else call wdc_atapibus_attach(). This way we
don't have to include the whole atapi support in an ata-only config.
- the dma_* function pointers take a 'int flags' as last argument, instead
of an 'int read'. The 2 valid flags are: WDC_DMA_READ (to select read/write)
and WDC_DMA_POLL, to signal interrupt-less mode (for core dumps).
- Reworked wdcprobe() so look more like the old one. A status of 0xff is
interpreted as "no drive" (freebsd does this); this this speed up
the probe for non-IDE machines (a reset timeout has been bumped to 31s,
to match the specs). The probe set ups the drive flags to either ATA or
ATAPI (depend on register signature) or OLD (if register signature don't
match, but a working drive appears to be there). Later the ATA code
will look at the OLD flag to decide wether there is no drive, or an old
(ST506) one if WDC_IDENTIFY fails.
- For known PCI chips, don't use the wdcprobe() heuristic to find wether
a channel is enabled/disabled; use the chip's specific registers for this.
- Clear the command queue when we have a polled command. This allows dumps to
work even if a command was being handled by the controller at panic time.
- Increase the number of available DMA segments by one, as user requests may
not be aligned on a page boundary.
 1.24.2.12 11-Sep-1998  bouyer Sync with HEAD.
 1.24.2.11 21-Aug-1998  bouyer Sync with -current
 1.24.2.10 13-Aug-1998  bouyer - sync with HEAD
- better error detection and report for wd drives
- better wddump() support
- wdcwait() now takes a timout argument, so that we can honnor the
timeout argument of scsipi cmds.
 1.24.2.9 19-Jun-1998  leo Fix hw-locking.
 1.24.2.8 10-Jun-1998  bouyer Fix probe/attach for ATAPI or ATA-only kernels.
(XXX still 'brocken' in one way, will be worked out soon).
 1.24.2.7 09-Jun-1998  bouyer Fix typos (from Soren S. Jorvan).
 1.24.2.6 09-Jun-1998  bouyer - sync with trunck
- add a missing '~' when resetting the 32BIT flag to 0.
- don't try to set the PIO or DMA mode if we don't know how to set them
on the controller. This seems to confuse some 'intelligent' isa controllers.
 1.24.2.5 05-Jun-1998  bouyer Add a missing LIST_INIT().
 1.24.2.4 05-Jun-1998  bouyer A few bux fixes (untested):
- If the PIO mode of the controller is unknown, put the drive in the
hightest mode it supports. A drive in a faster mode than the controller
should work.
- Create DMA maps even for unknown controllers in pciide.
 1.24.2.3 05-Jun-1998  bouyer Patches from Leo Weppelman for IDE on atari, with minor fixes by me
(needed the addition of a void wdcrestart __P((void*)) function).
Quoting his words:
These diffs are preliminary because it looks like the free_hw() function
does not get called. This is only a problem on the atari falcon. I have not
yet been able to track this down.
Also, KNF wdc.c.
 1.24.2.2 04-Jun-1998  bouyer Commit changes to the IDE system in a branch. This allows a better separation
between higth-level and low-level (i.e. registers read/write) and generalize
the queue for all commands. This also add supports for IDE DMA.
 1.24.2.1 04-Jun-1998  bouyer file wdc.c was added on branch bouyer-ide on 1998-06-04 16:52:47 +0000
 1.66.2.9 07-Jul-2000  he Apply patch (requested by bouyer):
Add support for the following PCIIDE controllers:
o AMD 756
o CMD PCI0648 and PCI0649
o Hightpoint HPT366
o OPTi 82c621 (and a few of its derivatives)
o Promise Ultra/33 and Ultra/66
o Intel 82801 (ICH/ICH0)
Also fix PR#10437 (detect more ATAPI devices).
 1.66.2.8 01-Feb-2000  he Pull up revision 1.71 (via patch, requested by bouyer):
Correct a minor bug in Ultra-DMA mode printing.
 1.66.2.7 23-Jan-2000  he Pull up revision 1.78 (2nd part, via patch, requested by bouyer):
Issue a blank IDENTIFY before the real one, for drives which
reject the first IDENTIFY after a reset.
 1.66.2.6 23-Jan-2000  he Pull up revision 1.78 (partially, via patch, requested by bouyer):
Improve the downgrade logic to work better in some cases (especially
for Acer Labs M5229 controllers with Ultra-DMA/66 disks).
 1.66.2.5 22-Oct-1999  he Pull up revision 1.76 (requested by bouyer):
The WDCF_IRQ_WAIT flag was erroneously cleared when an earlier
interrupt not for this IDE channel controller was received.
Fixes the "missing untimeout" problems reported in PR#8639.
 1.66.2.4 28-Aug-1999  he Pull up revision 1.69:
A mostly-stylistic change guarding tsleep() with a while() loop. (bouyer)
 1.66.2.3 25-Aug-1999  he Pull up 1.69->1.70:
Add some debug printfs, change timeout handling to be more efficient
and less error-prone, and fix the "lockup after lost interrupt"
problem some users have been reporting. (bouyer)
 1.66.2.2 24-Jun-1999  perry pullup 1.67->1.68 (bouyer)
 1.66.2.1 12-Apr-1999  bouyer branches: 1.66.2.1.2; 1.66.2.1.4;
Sync with ic/wdc.c 1.67, ic/wdcvar.h 1.17, isa/wdc_isa.c 1.14:
Revert to a more conservative probe: it controller responded and we don't find
ATAPI signature, assume it and ATA or OLD drive (OLD is only set if the
wdc front end passed WDC_CAPABILITIES_OLD, only used for ISA front-end).
At attach time, issue an IDENTIFY to detect drives and eliminates ghosts.
If IDENTIFY failed and OLD is set, issue a RECAL to check for the presence
of old drives.
Should fix the 'disk dissapeared' problems reported by some users, including
port-arm32/7324.
 1.66.2.1.4.1 30-Nov-1999  itojun bring in latest KAME (as of 19991130, KAME/NetBSD141) into kame branch
just for reference purposes.
This commit includes 1.4 -> 1.4.1 sync for kame branch.

The branch does not compile at all (due to the lack of ALTQ and some other
source code). Please do not try to modify the branch, this is just for
referenre purposes.

synchronization to latest KAME will take place on HEAD branch soon.
 1.66.2.1.2.3 02-Aug-1999  thorpej Update from trunk.
 1.66.2.1.2.2 01-Jul-1999  thorpej Sync w/ -current.
 1.66.2.1.2.1 21-Jun-1999  thorpej Sync w/ -current.
 1.74.6.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.74.4.1 15-Nov-1999  fvdl Sync with -current
 1.74.2.7 27-Mar-2001  bouyer Sync with HEAD.
 1.74.2.6 18-Feb-2001  bouyer Move atapiprint() to ic/wdc.c so that we can compile a kernel with IDE
controller but without atapibus.
 1.74.2.5 18-Jan-2001  bouyer Sync with head (for UBC+NFS fixes, mostly).
 1.74.2.4 22-Nov-2000  bouyer Sync with HEAD.
 1.74.2.3 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.74.2.2 20-Oct-1999  thorpej Sync w/ trunk.
 1.74.2.1 19-Oct-1999  thorpej Adapt to scsipi API changes.
 1.89.2.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.91.2.5 06-Oct-2003  itojun Fix a typo that prevented pre-ata drives from working since 1999.
[ticket #85, bouyer]
 1.91.2.4 23-Jan-2003  msaitoh Pull up revision 1.114 (requested by Manuel Bouyer):

read status after data commands in wdc_exec_command(). Mandatory for data out
commands (nonw are used for now), and doesn't hurt for data in. Also keep
track if we did transfer data. Makes the probe more robust and solves
kern/16159
 1.91.2.3 22-Jan-2002  he Pull up revision 1.109 (via patch, requested by bouyer):
Don't try to use chp->wdc if it's NULL. Fixes PR#15307.
 1.91.2.2 16-Jan-2002  he Pull up revision 1.107 (via patch, requested by dbj):
Add UDMA support and allow separate DMA timings to be programmed
for two different devices on the same wdc channel on the macppc.
The machine-independent driver is updated to optionally use the
WDC_CAPABILITY_SELECT callback whenever a target is selected on
a channel.
 1.91.2.1 05-Jan-2002  he Pull up revision 1.101 (requested by bouyer):
Do not allow forcing Ultra-DMA via config flags if the controller
does not support it.
 1.94.2.16 03-Jan-2003  thorpej Sync with HEAD.
 1.94.2.15 11-Dec-2002  thorpej Sync with HEAD.
 1.94.2.14 18-Oct-2002  nathanw Catch up to -current.
 1.94.2.13 27-Aug-2002  nathanw Catch up to -current.
 1.94.2.12 01-Aug-2002  nathanw Catch up to -current.
 1.94.2.11 20-Jun-2002  nathanw Catch up to -current.
 1.94.2.10 17-Apr-2002  nathanw Catch up to -current.
 1.94.2.9 01-Apr-2002  nathanw Catch up to -current.
(CVS: It's not just a program. It's an adventure!)
 1.94.2.8 28-Feb-2002  nathanw Catch up to -current.
 1.94.2.7 23-Feb-2002  gmcgarry Merge up from -current.
 1.94.2.6 11-Jan-2002  nathanw More catchup.
 1.94.2.5 08-Jan-2002  nathanw Catch up to -current.
 1.94.2.4 14-Nov-2001  nathanw Catch up to -current.
 1.94.2.3 21-Sep-2001  nathanw Catch up to -current.
 1.94.2.2 21-Jun-2001  nathanw Catch up to -current.
 1.94.2.1 09-Apr-2001  nathanw Catch up with -current.
 1.98.4.1 01-Oct-2001  fvdl Catch up with -current.
 1.98.2.6 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.98.2.5 06-Sep-2002  jdolecek sync kqueue branch with HEAD
 1.98.2.4 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.98.2.3 16-Mar-2002  jdolecek Catch up with -current.
 1.98.2.2 11-Feb-2002  jdolecek Sync w/ -current.
 1.98.2.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.114.4.4 28-Mar-2004  jmc Pullup patch (requested by bouyer in ticket #1637)

Wait a bit more after reset before re-enabling interrupts. PR#24904
 1.114.4.3 24-Sep-2003  tron Pull up revision 1.132 (requested by bouyer in ticket #1481):
Fix a typo that prevented pre-ata drives from working since 1999.
 1.114.4.2 01-Nov-2002  tron Pull up revision 1.117 (requested by bouyer in ticket #726):
Add support for Ultra/133 (ultra-DMA6) in wdc_probe_caps().
 1.114.4.1 13-Jun-2002  lukem Pull up revision 1.115 (requested by bouyer in ticket #256):
Bump delay() between reset and IDENTIFY from 100 to 5000. Some ATAPI devices
wedge when talking to them too soon, and incorrectly react to WDC_RESET.
Close PR kern/17208 by Paul Goyette.
 1.114.2.2 29-Aug-2002  gehenna catch up with -current.
 1.114.2.1 20-Jun-2002  gehenna catch up with -current.
 1.123.2.11 11-Dec-2005  christos Sync with head.
 1.123.2.10 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.123.2.9 01-Apr-2005  skrll Sync with HEAD.
 1.123.2.8 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.123.2.7 15-Feb-2005  skrll Sync with HEAD.
 1.123.2.6 02-Nov-2004  skrll Sync with HEAD.
 1.123.2.5 21-Sep-2004  skrll Fix the sync with head I botched.
 1.123.2.4 18-Sep-2004  skrll Sync with HEAD.
 1.123.2.3 25-Aug-2004  skrll Sync with HEAD.
 1.123.2.2 12-Aug-2004  skrll Sync with HEAD.
 1.123.2.1 03-Aug-2004  skrll Sync with HEAD
 1.172.2.7 17-Sep-2004  jmc branches: 1.172.2.7.2;
Pullup patch (requested by bouyer in ticket #854)

__wdc_reset_channel(): give the loop over commands a chance to terminate by
- updating xfer on each iteration (ops)
- making sure that xfers gets removed from the queue
 1.172.2.6 11-Sep-2004  he Apply patch (requested by bouyer in ticket #840):
If we are not going to handle a reset request because one is
already pending, decrease queue_freeze that we just increased.
Otherwise, the queue stays frozen after the reset.
Should fix PR#26873 and PR#26910.
 1.172.2.5 11-Aug-2004  jmc Pullup rev 1.182 (requested by bouyer in ticket #733)

Implement asynchronous channel reset.
Use this to reset the channel before doing a dump, instead of the hack in
wdc_exec_xfer() based on C_POLL. This hack was causing problems on
controllers with a shared queue, because we now can have C_POLL set during
concurent channels probes
 1.172.2.4 24-Jun-2004  he Pull up revision 1.181 (requested by bouyer in ticket #543):
For now, remove the ATAPI_SOFT_RESET done at attach time,
which was added to get an IBM pcmcia external cdrom drive
working. However, this appears to cause trouble for other
IDE/ATAPI devices.
 1.172.2.3 29-May-2004  tron Pull up revision 1.175 (requested by bouyer in ticket #397):
Add a delay(5000) between the ATAPI_SOFT_RESET and the channel reset.
Some ATAPI device never get out of busy if touched too fast after a reset.
Delay value from atapi_wdc.c; fix problem reported by Nicolas Joly on
current-users.
 1.172.2.2 29-May-2004  tron Pull up revision 1.174 (requested by bouyer in ticket #397):
In wdcprobe1(), protect the register writability test with splbio().
What we do here seems to trigger interrupts on some pcmcia adapters, which
cause the kernel to hang.
Add some WDCDEBUG_PRINT((), DEBUG_PROBE).
Avoid touching registers of nonexistent drives, once we know which drive is
or is not here.
This makes the "IBM PCMCIA Portable CD-ROM Drive" (external CD drive with
PCMCIA adapter) work.
 1.172.2.1 29-May-2004  tron Pull up revision 1.173 (requested by bouyer in ticket #396):
Add a delay(10) after re-enabling interrupts in the control register.
Some controllers/drives (e.g. SataLink 3114 with WD Raptor) require
it. Should fix kern/23808 by Chris Gilbert, patch suplied by Chris Gilbert
on tech-kern, extended to all places enabling interrupts by me.
 1.172.2.7.2.11 28-Oct-2005  jmc Pullup (via patch) requested by bouyer in ticket #5852
In __wdccommand_start(), don't cann wdcwait() with ata_c->flags, as this gives
information about the context in which wdc_exec_command() was called, but
we may be in interrupt context here. Call wdcwait() with flags derived from
xfer->c_flags instead, as do other wdcwait() callers. PR#31083
 1.172.2.7.2.10 23-Aug-2005  tron Apply patch (requested by bouyer in ticket #5605):
On NetBSD 2.x chp->ch_wdc can be NULL in some case, check for this.
This avoids panics in wdcprobe().
 1.172.2.7.2.9 23-Aug-2005  tron Apply patch (requested by bouyer in ticket #5604):
Fix error in patch from ticket #5603.
 1.172.2.7.2.8 22-Aug-2005  riz Pull up following revision(s) (requested by bouyer in ticket #5603):
sys/dev/ic/wdc.c: revision 1.226
The ATA/ATAPI IDENTIFY data were designed to be converted on the fly to
host byte order (eventually the byte swapping could be wired in hardware, on
the 16 bit data bus). This was keept when wdc_exec_command() was created,
and as a result wdc_exec_command() is doing 16bit conversion to host byte
order. This is fine for IDENTIFY but doesn't work for other opaque data
structure, such as the ones for SMART.
So change wdc_exec_command() to do the conversion to host byte order only for
WDCC_IDENTIFY and ATAPI_IDENTIFY_DEVICE. This fixes atactl smart status
on big-endian hosts.

sys/dev/ic/wdc.c: revision 1.229
make CF on pcmcia works again.
Approved by bouyer.
closed kern/30998.
 1.172.2.7.2.7 13-Aug-2005  riz Pull up patch (requested by bouyer in ticket #5561):

CHAN_TO_WDC() doesn't exist on netbsd-2; correct this pullup (as
requested by bouyer).
 1.172.2.7.2.6 13-Aug-2005  riz Pull up revision 1.228 (requested by bouyer in ticket #5561):
Add missing declaration/initialisation of wdc.
Pointed out by Rui Paulo.
 1.172.2.7.2.5 13-Aug-2005  riz Pull up revision 1.227 (requested by bouyer in ticket #5561):
Also initialize wdc->reset in wdcprobe() if the bus back-end didn't provide
one. Prevent NULL pointer dereference when wdcprobe() is called.
 1.172.2.7.2.4 07-Aug-2005  riz Pull up revision 1.225 via patch (requested by bouyer in ticket #5555):
Add an optionnal controller callback for channel reset. If the callback
is set to NULL, use the generic reset code.
Use this to work around a bug in some Acer IDE controllers (like the
one found in some sparc systems) where a controller disable/enable
is required after a reset to avoid data corruption when Ultra-DMA is
used. Workaround from opensolaris, thanks to Hiroki Sato for testing.
 1.172.2.7.2.3 05-Jul-2005  riz Pull up revision 1.224 via patch (requested by bouyer in ticket #2030):
In wdcprobe1(), wait 5s for the drive to deassert ready. In case of e.g.
pcmcia devices, the drive may still be doing its power-on reset.
XXX From the specs the delay could be up to 31s here, but we don't want to
wait for 31s if we have a channel with no drives and pull-up resitors on
the bus.
Based on patch submitted in kern/25659 by Steven M. Bellovin, part of fix for
kern/25659.
 1.172.2.7.2.2 16-Apr-2005  tron Pull up revision 1.217 via patch (requested by bouyer in ticket #1105):
Allow polled commands to be queued, if ata_exec_xfer() is called in thread
context. For this introduce 3 new xfer tags:
- C_WAIT, equivalent of AT_WAIT
- C_WAITACT, when there is a thread waiting on this xfer to become the active
one (that is, to be at the head of the queue)
- C_FREE, set by ata_free_xfer() when it can't free the xfer because it's
still in use. The holder should then free the xfer ASAP.
If ata_exec_xfer() is called with (C_POLL | C_WAIT), and there is already
xfers to be processed, assert C_WAITACT and sleep.
atastart() checks for C_WAITACT, and wakeup the thread waiting for this xfer
to become active if set. atastart() won't process this xfer, it's the
responsability of the thread waked up to handle it.
Fix (the right way) kern/27421 by Martin Husemann.
 1.172.2.7.2.1 16-Mar-2005  jmc Pullup rev 1.180 (requested by mycroft in ticket #1018)

Only downgrade modes due to an actual CRC error. Downgrading on other errors
is anti-social -- especially given that there's no way to upgrade again short
of rebooting.

Also, downgrade UDMA modes more slowly. It's entirely possible that they're
using an 80-wire cable, but it's just too long for the higher modes, or there
is minor crosstalk.
 1.217.6.2 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.217.6.1 12-Feb-2005  yamt sync with head.
 1.217.4.1 29-Apr-2005  kent sync with -current
 1.220.2.9 26-Jan-2006  jdc Pull up revision 1.231 (requested by bouyer in ticket #1125).

After a reset don't wait for drives to come ready if there's no drives.
Fix a 30s hang after resume. Problem reported and fix tested by Brian de Alwis.
 1.220.2.8 13-Sep-2005  tron branches: 1.220.2.8.2;
Pull up following revision(s) (requested by bouyer in ticket #780):
sys/dev/ic/wdc.c: revision 1.230
In __wdccommand_start(), don't call wdcwait() with ata_c->flags, as this gives
information about the context in which wdc_exec_command() was called, but
we may be in interrupt context here. Call wdcwait() with flags derived from
xfer->c_flags instead, as do other wdcwait() callers.
Should fix kern/31083 by Jukka Salmi.
 1.220.2.7 24-Aug-2005  tron Pull up revision 1.229 (requested by bouyer in ticket #693):
make CF on pcmcia works again.
Approved by bouyer.
closed kern/30998.
 1.220.2.6 24-Aug-2005  tron Pull up revision 1.226 (requested by bouyer in ticket #693):
The ATA/ATAPI IDENTIFY data were designed to be converted on the fly to
host byte order (eventually the byte swapping could be wired in hardware, on
the 16 bit data bus). This was keept when wdc_exec_command() was created,
and as a result wdc_exec_command() is doing 16bit conversion to host byte
order. This is fine for IDENTIFY but doesn't work for other opaque data
structure, such as the ones for SMART.
So change wdc_exec_command() to do the conversion to host byte order only for
WDCC_IDENTIFY and ATAPI_IDENTIFY_DEVICE. This fixes atactl smart status
on big-endian hosts.
While here change __wdccommand_intr() to only use wdc_data{in,out}_pio, there
is no gain in doing the 32bit data port stuff locally.
 1.220.2.5 18-Aug-2005  tron Pull up revision 1.228 (requested by bouyer in ticket #653):
Add missing declaration/initialisation of wdc.
Pointed out by Rui Paulo.
 1.220.2.4 18-Aug-2005  tron Pull up revision 1.227 (requested by bouyer in ticket #653):
Also initialize wdc->reset in wdcprobe() if the bus back-end didn't provide
one. Prevent NULL pointer dereference when wdcprobe() is called.
 1.220.2.3 18-Aug-2005  tron Pull up revision 1.225 (requested by bouyer in ticket #653):
Add an optionnal controller callback for channel reset. If the callback
is set to NULL, use the generic reset code.
Use this to work around a bug in some Acer IDE controllers (like the
one found in some sparc systems) where a controller disable/enable
is required after a reset to avoid data corruption when Ultra-DMA is
used. Workaround from opensolaris, thanks to Hiroki Sato for testing.
 1.220.2.2 02-Jul-2005  tron Pull up revision 1.224 (requested by bouyer in ticket #499):
In wdcprobe1(), wait 5s for the drive to deassert ready. In case of e.g.
pcmcia devices, the drive may still be doing its power-on reset.
XXX From the specs the delay could be up to 31s here, but we don't want to
wait for 31s if we have a channel with no drives and pull-up resitors on
the bus.
Based on patch submitted in kern/25659 by Steven M. Bellovin, part of fix for
kern/25659.
 1.220.2.1 22-Jun-2005  tron Pull up revision 1.223 (requested by bouyer in ticket #480):
Remove a (wdc == NULL) test. We know wdc is not NULL at this point.
 1.220.2.8.2.1 26-Jan-2006  jdc Pull up revision 1.231 (requested by bouyer in ticket #1125).

After a reset don't wait for drives to come ready if there's no drives.
Fix a 30s hang after resume. Problem reported and fix tested by Brian de Alwis.
 1.224.2.8 24-Mar-2008  yamt sync with head.
 1.224.2.7 04-Feb-2008  yamt sync with head.
 1.224.2.6 21-Jan-2008  yamt sync with head
 1.224.2.5 27-Oct-2007  yamt sync with head.
 1.224.2.4 03-Sep-2007  yamt sync with head.
 1.224.2.3 26-Feb-2007  yamt sync with head.
 1.224.2.2 30-Dec-2006  yamt sync with head.
 1.224.2.1 21-Jun-2006  yamt sync with head.
 1.230.6.1 22-Nov-2005  yamt sync with head.
 1.231.2.2 01-Mar-2006  yamt sync with head.
 1.231.2.1 01-Feb-2006  yamt sync with head.
 1.234.4.1 22-Apr-2006  simonb Sync with head.
 1.234.2.1 09-Sep-2006  rpaulo sync with head
 1.235.6.1 28-Mar-2006  tron Merge 2006-03-28 NetBSD-current into the "peter-altq" branch.
 1.235.4.1 19-Apr-2006  elad sync with head.
 1.235.2.2 03-Sep-2006  yamt sync with head.
 1.235.2.1 01-Apr-2006  yamt sync with head.
 1.237.4.2 10-Dec-2006  yamt sync with head.
 1.237.4.1 22-Oct-2006  yamt sync with head
 1.237.2.3 01-Feb-2007  ad Sync with head.
 1.237.2.2 12-Jan-2007  ad Sync with head.
 1.237.2.1 18-Nov-2006  ad Sync with head.
 1.243.2.3 29-Jan-2007  bouyer Pull up following revision(s) (requested by sborrill in ticket #389):
sys/dev/ic/wdc.c: revision 1.246
Add missing bus_space_(read,write)_stream macros.
Approved by martin@
 1.243.2.2 23-Jan-2007  tron Pull up following revision(s) (requested by bouyer in ticket #380):
sys/dev/ic/wdc.c: revision 1.245
For the unaligned case:
Be consistant with the spaces around * and +
Use data32io[th] for 32bit access
Use stream bus_space access unless we have DRIVE_NOSTREAM
all pointed out by enami tsugutomo, thanks !
 1.243.2.1 15-Jan-2007  pavel Pull up following revision(s) (requested by martin in ticket #371):
sys/dev/scsipi/cd.c: revision 1.261
sys/dev/ic/wdc.c: revision 1.244
If __NO_STRICT_ALIGNMENT is not defined, take special care to do PIO
transfers with proper alignement - this removes alignement restrictions
of the buffer pointer passed.
Thanks to bouyer, reinoud, jdc for helping with the code, and special
thanks to Dave Huang for testing.
The previous fix for PR 34202 was wrong (some sizeof used the union, not
the command block) - but instead of fixing this, we can now revert it
completley: the real fix has been applied to ../ic/wdc.c in rev. 1.244,
removing the alignement constraints.
 1.246.10.1 18-Mar-2007  reinoud First attempt to bring branch in sync with HEAD
 1.246.8.1 11-Jul-2007  mjf Sync with head.
 1.246.6.5 23-Oct-2007  ad Sync with head.
 1.246.6.4 16-Sep-2007  ad Remove debug code that crept in.
 1.246.6.3 19-Aug-2007  ad - Back out the biodone() changes.
- Eliminate B_ERROR (from HEAD).
 1.246.6.2 27-May-2007  ad Sync with head.
 1.246.6.1 10-Apr-2007  ad Sync with head.
 1.246.2.2 07-May-2007  yamt sync with head.
 1.246.2.1 24-Mar-2007  yamt sync with head.
 1.248.12.1 25-Oct-2007  bouyer Sync with HEAD.
 1.248.8.2 23-Mar-2008  matt sync with HEAD
 1.248.8.1 06-Nov-2007  matt sync with HEAD
 1.248.6.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.249.8.2 20-Jan-2008  bouyer Sync with HEAD
 1.249.8.1 10-Jan-2008  bouyer Sync with HEAD
 1.249.2.1 18-Feb-2008  mjf Sync with HEAD.
 1.252.6.4 17-Jan-2009  mjf Sync with HEAD.
 1.252.6.3 05-Oct-2008  mjf Sync with HEAD.
 1.252.6.2 02-Jun-2008  mjf Sync with HEAD.
 1.252.6.1 03-Apr-2008  mjf Sync with HEAD.
 1.252.2.1 24-Mar-2008  keiichi sync with head.
 1.253.4.4 11-Aug-2010  yamt sync with head.
 1.253.4.3 11-Mar-2010  yamt sync with head
 1.253.4.2 04-May-2009  yamt sync with head.
 1.253.4.1 16-May-2008  yamt sync with head.
 1.253.2.1 18-May-2008  yamt sync with head.
 1.254.6.2 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.254.6.1 19-Oct-2008  haad Sync with HEAD.
 1.254.2.1 10-Oct-2008  skrll Sync with HEAD.
 1.255.4.2 18-Oct-2009  bouyer Pull up following revision(s) (requested by sborrill in ticket #1074):
sys/dev/ic/wdc.c: revision 1.258
Commit patch from PR#41926. Confirmed to work by PR submitter on two
controllers as well myself and another on viaide.
Stops errors such as the following when probing SATA drives through
controllers that offer the legacy pciide interface:
viaide1 channel 0: reset failed for drive 0
OK bouyer@
 1.255.4.1 20-Nov-2008  snj branches: 1.255.4.1.4;
Pull up following revision(s) (requested by bouyer in ticket #67):
sys/dev/ic/wdc.c: revision 1.256
sys/dev/ata/ata.c: revision 1.102
sys/dev/scsipi/atapi_wdc.c: revision 1.109
sys/dev/ata/atavar.h: revision 1.78
sys/dev/ata/ata_wdc.c: revision 1.91
cpu_intr_p() doesn't account for software interrupts (e.g. callouts) so
we can't use it here. Rssurect ATACH_TH_RUN, backing out
src/sys/dev/ata/ata.c 1.101
src/sys/dev/ata/ata_wdc.c 1.90
src/sys/dev/ata/atavar.h 1.77
src/sys/dev/ic/wdc.c 1.255
src/sys/dev/scsipi/atapi_wdc.c 1.108
Should fix kern/39927 and kern/39725.
 1.255.4.1.4.1 21-Apr-2010  matt sync to netbsd-5
 1.255.2.1 19-Jan-2009  skrll Sync with HEAD.
 1.260.4.1 30-May-2010  rmind sync with head
 1.260.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.265.6.1 18-Feb-2012  mrg merge to -current.
 1.265.2.5 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.265.2.4 23-Jan-2013  yamt sync with head
 1.265.2.3 16-Jan-2013  yamt sync with (a bit old) head
 1.265.2.2 30-Oct-2012  yamt sync with head
 1.265.2.1 17-Apr-2012  yamt sync with head
 1.274.2.4 03-Dec-2017  jdolecek update from HEAD
 1.274.2.3 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.274.2.2 23-Jun-2013  tls resync from head
 1.274.2.1 25-Feb-2013  tls resync with head
 1.278.4.1 18-May-2014  rmind sync with head
 1.279.6.4 28-Aug-2017  skrll Sync with HEAD
 1.279.6.3 05-Oct-2016  skrll Sync with HEAD
 1.279.6.2 29-May-2016  skrll Sync with HEAD
 1.279.6.1 19-Mar-2016  skrll Sync with HEAD
 1.281.2.1 26-Apr-2017  pgoyette Sync with HEAD
 1.282.2.1 21-Apr-2017  bouyer Sync with HEAD
 1.283.2.17 27-Sep-2017  jdolecek change wdc_init_shadow_regs() to accept only struct wdc_regs, it doesn't
touch anything else

factor out the probe-only struct ata_channel initialization to wdcprobe(), to
reduce duplication of logic in individual drivers, and to actually work now
that more init is needed beyond the memset()
 1.283.2.16 19-Sep-2017  jdolecek replace all remaining tsleep()/wakeup() calls with condition variables, or
calls to ata_delay(), as appropriate; change ata_delay() to require the
channel lock on entry, and pass the lock to kpause() for unlocking while
sleeping
 1.283.2.15 11-Sep-2017  jdolecek fix condition for calling atastart() when command is done
 1.283.2.14 10-Sep-2017  jdolecek refactor code so that xfer c_start() hook is called with channel mutex held,
and hence the controller submit code no longer relies on spl

tested all the affected drivers - wdc (via piixide), ahci, mvsata, siisata,
both disk and atapi I/O
 1.283.2.13 12-Aug-2017  jdolecek convert the atabus thread to use the channel lock and a condvar, adjust
code which sets the relevant channel flags to take the lock while doing so
 1.283.2.12 12-Aug-2017  jdolecek remove debug printf
 1.283.2.11 12-Aug-2017  jdolecek remove all logic around ATACH_IRQ_WAIT and channel-global ch_error/ch_status,
so that there is less hidden state shared by commands; primary intent is
to make the NCQ and non-NCQ paths more similar, and remove possibility
of incorrect handling for the NCQ commands

tested both disk and ATAPI - piixide(4) on QEMU, and siisata(4),
ahcisata(4), mvsata(4) on real hw
 1.283.2.10 27-Jun-2017  jdolecek attend error paths, more strict asserts and code consistency

- atastart() and ata_kill_pending() now KASSERT() that all xfers on queue
have same channel
- inactive xfers are killed via new reason KILL_GONE_INACTIVE, controller
code must not call any resource deactivation in that case
- c_intr() must call ata_waitdrain_xfer_check() as first thing, and must not
further touch any xfer structures on exit path; any resource cleanup
is supposed to be done in c_kill_xfer()
- c_kill_xfer() should never call atastart()
- ata_waitdrain_check() removed, replaced by ata_waitdrain_xfer_check()
- ATA_DRIVE_WAITDRAIN handling converted to use condvar
- removed unused ata_c callback
 1.283.2.9 21-Jun-2017  jdolecek change ata_queue_hwslot_to_xfer() and ata_queue_get_active_xfer() to take
ata_channel instead of ata_queue as parameter, and lock the channel while
traversing the queue
 1.283.2.8 21-Jun-2017  jdolecek actually remove the KASSERT() for queue_active in wdc.c as it's superfluous,
and make struct ata_queue completly opaque to attachment code; fix two other
places which were not converted to ata_queue_alloc() which were surfaced
by this change
 1.283.2.7 20-Jun-2017  jdolecek remove ata queue downsizing - every device, attached to the same channel,
uses slots according to it's own limits

wdc code changed to expect maximum one active xfer, and not check number
of openings in the channel; this is to facilitate using wdc functions
for e.g. handling of atapi commands for drivers which support both ATAPI
and NCQ
 1.283.2.6 19-Jun-2017  jdolecek add ata_channel lock, use it to protect queue manipulation (only that for now);
add ata_channel_detach() to destroy the locks

change ata_get_xfer() so that it can wait for xfer, convert all on-stack
xfer code to use the blocking variant

fix siisata_reset_drive() to use polled reset and not try ata_activate_xfer(),
convert drive probe code also over from slot0 XXX to ata_get_xfer()

drive reset and PMP now works on siisata(4) too; changes tested also
on piixide(4), ahci(4), mvsata(4)
 1.283.2.5 16-Jun-2017  jdolecek adjust reset channel and dump paths
- channel reset now always kills active transfer, even on dump path, but
now doesn't touch the queued waiting transfers; also kill_xfer hook is
always called, so that HBA can free any private xfer resources and thus
the dump request has chance to work
- kill_xfer routines now always call ata_deactivate_xfer(); added KASSERT()s
to ata_free_xfer() to expect deactivated xfer
- when called during channel reset before dump, ata_kill_active() drops
any queued waiting transfers without processing
- do not (re)queue any transfers in wddone() when dumping
- kill AT_RST_NOCMD flag

This should also hopefully fix the 'polled command has been queued' panic
as reported in:
PR kern/11811 by John Hawkinson
PR kern/47041 by Taylor R Campbell
PR kern/51979 by Martin Husemann

dump tested working with piixide(4) and ahci(4). mvsata(4) dump times out,
but otherwise tested working, will be fixed separately. siisata(4) mechanically
changed and not tested.
 1.283.2.4 19-Apr-2017  jdolecek adjust ata code to support more than one active command, including the
timeout handling, add support for NCQ commands

move probe for NCQ and number of tags to middle layer, negotiate mutual
support between drive and controller

implement NCQ support in ahci(4)
 1.283.2.3 15-Apr-2017  jdolecek pass also ata_command via ata_xfer, callers of ata_exec_command() is now
responsible for allocation/disposal of the structure

change code to allocate ata_xfer for commands on stack same way as previously
the ata_command were, using c_slot 0; adjust asserts so that it would allow
several xfers with same c_slot, as long as only one such transfer is active
at a time
 1.283.2.2 15-Apr-2017  jdolecek make ata_xfer's allocated as part of ata_queue and make it include ata_bio;
they are pre-allocated on attach and ata_get_xfer() now never sleep, drop the
pool

modify wd(4) to file the bio requests using the xfers and hence
make it possible to have more than one active I/O request in flight;
ata_bio callback doesn't need to allocate any memory any more,
require it to never return ATACMD_TRY_AGAIN

move lp, badsect, multi from ata_bio to ata_drive_datas, as they are per-drive,
not per transfer

drop unused drv atac_claim_hw/atac_free_hw hooks, and also drop again ata_bio
c_hwslot
 1.283.2.1 10-Apr-2017  jdolecek ATA infrastructure improvements to eventually support more outstanding
commands

patch by Matt Thomas
 1.288.6.3 03-Oct-2018  jdolecek change channel reset and drive reset for all ATA controllers to always
run via thread, and with channel lock held the whole time; the queue is
frozen while reset is pending

for this repurpose ata_reset_channel() into new ata_thread_run()

also adjust some device printfs to not leak xfer pointer, and avoid
aprint_* for non-autoconf messages
 1.288.6.2 17-Sep-2018  jdolecek move low-level protocol handlers hooks from ata_xfer to separate struct,
initialized statically

primarily to reduce ata_xfer struct size, but also improves readibility,
and enforces consistency
 1.288.6.1 31-Aug-2018  jdolecek refactor ata_xfer to be just dumb structure; move all callouts/condvars out

retry callout to wd(4); reset callout and the active/cmd finish condvars
to channel queue; change code using the condvars so it works if there
are multiple waiters

simplify the async wait code for cmds, replace ata_wait_xfer()/ata_wake_xfer()
with ata_wait_cmd()

fix the callout_invoking/ack race handling code for timeouts to
actually have chance to work; change mvsata(4) to use generic timeout func

towards resolution of kern/52614
 1.288.4.4 21-Apr-2020  martin Sync with HEAD
 1.288.4.3 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.288.4.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.288.4.1 10-Jun-2019  christos Sync with HEAD
 1.288.2.1 26-Nov-2018  pgoyette Sync with HEAD, resolve a couple of conflicts
 1.291.4.2 30-Dec-2022  martin Pull up following revision(s) (requested by tsutsui in ticket #1557):

sys/dev/ic/ahcisata_core.c: revision 1.83
sys/dev/ic/ahcisata_core.c: revision 1.102
sys/dev/ata/ata.c: revision 1.164
sys/dev/ata/ata_wdc.c: revision 1.115
sys/dev/ata/ata_recovery.c: revision 1.4
sys/dev/ic/siisata.c: revision 1.42
sys/dev/ic/wdc.c: revision 1.308
sys/dev/ic/mvsata.c: revision 1.56
sys/dev/scsipi/atapi_wdc.c: revision 1.138
sys/dev/ic/siisata.c: revision 1.49
sys/dev/ata/atavar.h: revision 1.105
sys/dev/ata/wd.c: revision 1.460
sys/dev/ata/ata.c: revision 1.155
sys/dev/ata/wd.c: revision 1.462
sys/dev/ata/atavar.h: revision 1.109
sys/dev/ata/satapmp_subr.c: revision 1.16
sys/dev/ic/wdc.c: revision 1.299
sys/dev/ic/ahcisata_core.c: revision 1.93
sys/dev/ata/ata_wdc.c: revision 1.120
sys/dev/ic/wdcvar.h: revision 1.100
sys/dev/scsipi/atapi_wdc.c: revision 1.141
sys/dev/ic/mvsata.c: revision 1.61
sys/dev/usb/umass_isdata.c (apply patch)

drop wd lock in wdstart1() before calling the ata_bio hook; when called
from ata thread context, that can still need to sleep for wdc attachments
in wdcwait()

fix use-after-free for ata xfer on bio submission found by KASAN
driver ata_bio hooks read parts of the xfer after ata_exec_xfer()
call in order to determine return value, change so that the hook
doesn't return any value - callers do not care already,
as all I/O requests are asynchronous

this problem was uncovered by recent change for wd(4) to not hold
wd mutex during ata_bio call, the interrupt for the xfer might
thus actually fire immediately

adjust also ata_exec_command driver hooks similarily - remove all
completion and waiting logic from drivers, upper layer ata code
using AT_WAIT/AT_POLL changed to call ata_wait_cmd() itself
PR kern/55169 by Nick Hudson

Function declaration formating whitespace consistency. NFCI.

PR kern/56403
Fix kernel freeze for wdc(4) variants with ATAC_CAP_NOIRQ:

(1) Change ata_xfer_ops:c_poll from void to int function. When it returns
ATAPOLL_AGAIN, let ata_xfer_start() iterate itself again.
(2) Let wdc_ata_bio_poll() return ATAPOLL_AGAIN until ATA_ITSDONE is
achieved.

A similar change has been made for mvsata(4) (see mvsata_bio_poll()),
and no functional changes for other devices.

This is how the drivers worked before jdolecek-ncq branch was merged.
Note that this changes are less likely to cause infinite recursion:

(1) wdc_ata_bio_intr() called from wdc_ata_bio_poll() asserts ATA_ITSDONE
in its error handling paths via wdc_ata_bio_done().
(2) Return value from c_start (= wdc_ata_bio_start()) is checked in
ata_xfer_start().

Therefore, errors encountered in ata_xfer_ops:c_poll and c_start routines
terminate the recursion for wdc(4). The situation is similar for mvsata(4).

Still, there is a possibility where ata_xfer_start() takes long time to
finish a normal operation. This can result in a delayed response for lower
priority interrupts. But, I've never observed such a situation, even when
heavy thrashing takes place for swap partition in wd(4).
"Go ahead" by jdolecek@.
 1.291.4.1 23-Sep-2019  martin Pull up following revision(s) (requested by tsutsui in ticket #232):

sys/arch/evbppc/mpc85xx/wdc_obio.c: revision 1.7
sys/arch/dreamcast/dev/g1/wdc_g1.c: revision 1.4
sys/arch/dreamcast/dev/g1/wdc_g1.c: revision 1.5
sys/arch/mmeye/dev/wdc_mainbus.c: revision 1.7
sys/dev/ic/wdcvar.h: revision 1.99
sys/dev/ic/wdc.c: revision 1.292
sys/arch/mips/adm5120/dev/wdc_extio.c: revision 1.11

adjust several missed drivers for wdcprobe() changes of ATA NCQ branch
for dreamcast g1 just drop the custom reset function, it doesn't seem to do
anything useful over the generic variant

PR kern/54538 by Izumi Tsutsui

Restore interface to pass a MD reset function to MI wdcprobe().

Fixes silent hang on G1IDE on Dreamcast. PR kern/54538
Should be pulled up to netbsd-9 with the previous changes.
 1.296.2.1 29-Feb-2020  ad Sync with head.
 1.298.2.1 20-Apr-2020  bouyer Sync with HEAD
 1.303.2.1 03-Apr-2021  thorpej Sync with HEAD.
 1.32 11-Nov-2019  msaitoh Remove acorn26's upc(4) devices.
 1.31 20-Oct-2017  jdolecek branches: 1.31.4;
move ata_queue_alloc(1) and ata_queue_free() calls to ata_channel_init()
and ata_channel_destroy() respectively, to make attachment code simpler,
and to make it easier to spot special queue manipulation like cmdide(4)

on topic of PR kern/52606
 1.30 07-Oct-2017  jdolecek adapt several more wdc attachments for NCQ branch merge
 1.29 31-Jul-2012  bouyer branches: 1.29.2;
Apply back changes that were reverted on Jul 24 and Jul 26 (general ata/wdc
cleanup and SATA PMP support), now that I'm back to fix the fallouts.
 1.28 26-Jul-2012  jakllsch Revert, with intention of restoring in a less invasive way, the SATA Port
Multiplier code.

ok christos@
 1.27 02-Jul-2012  bouyer Add sata Port MultiPlier (PMP) support to the ata bus layer,
as described in
http://mail-index.netbsd.org/tech-kern/2012/06/23/msg013442.html
PMP support in integrated to the atabus layer.
struct ata_channel's ch_drive[] is not dynamically allocated, and ch_ndrive
(renamed to ch_ndrives) closely reflects the size of the ch_drive[] array.
Add helper functions atabus_alloc_drives() and atabus_free_drives()
to manage ch_drive[]/ch_ndrives.
Add wdc_maxdrives to struct wdc_softc so that bus front-end can specify
how much drive they really support (master/slave or single).
ata_reset_drive() callback gains a uint32_t *sigp argument which,
when not NULL, will contain the signature of the device being reset.
While there, some cosmetic changes:
- added a drive_type enum to ata_drive_datas, and stop encoding the
probed drive type in drive_flags (we were out of drive flags anyway).
- rename DRIVE_ATAPIST to DRIVE_ATAPIDSCW to better reflect what this
really is
- remove ata_channel->ata_drives, it's redundant with the pointer in
ata_drive_datas
- factor out the interpretation of SATA signatures in sata_interpet_sig()

propagate these changes to the ATA HBA drivers, and add support for PMP
to ahcisata(4) and siisata(4).

Thanks to:
- Protocase (http://www.protocase.com/) which provided a system
with lots of controllers, SATA PMP and drive slots
- Conservation Genomics Laboratory, Department of Biology, New Mexico State
University for hosting the above system
- Brook Milligan, who set up remote access and has been very responsive
when SATA cable move was needed
 1.26 25-Jan-2009  bjh21 branches: 1.26.14;
The introduction of config_stdsubmatch() lost an important feature of
upc_submatch() whereby it made sure that the correct driver attached.
Since this didn't really belong in the submatch function anyway,
reintroduce it in the match functions for upc's children.

This allows my A5000 to find at least one of its hard disks.
 1.25 18-Mar-2008  cube branches: 1.25.4; 1.25.12; 1.25.14;
Split device_t and softc for ATA devices, as well as wd(4). Other
cosmetic changes where appropriate.
 1.24 19-Oct-2007  ad branches: 1.24.12; 1.24.16;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.23 01-Oct-2006  bjh21 branches: 1.23.8; 1.23.22; 1.23.24; 1.23.28;
There's no need to explicitly deny DMA support, and that causes compile
problems when the kernel doesn't support IDE DMA.
 1.22 16-Jan-2006  bouyer branches: 1.22.18; 1.22.20;
properly use ata_channel->ch_ndrive:
- initialize it properly in the bus front-ends (all 2, exept in wdc_pcmcia.c
for the "Sandisk CompactFlash Card" where it's set to 1)
- remplace hardcoded '2' by ata_channel->ch_ndrive in MI IDE drivers.

From Christos Zoulas in kern/32501.
 1.21 11-Dec-2005  christos branches: 1.21.2;
merge ktrace-lwp.
 1.20 27-Feb-2005  perry branches: 1.20.4;
nuke trailing whitespace
 1.19 20-Aug-2004  thorpej branches: 1.19.4; 1.19.6;
Move most of wdc_softc into a new atac_softc structure that contains
info common to all types of ATA controllers.
 1.18 14-Aug-2004  thorpej - Split the register handles out of struct wdc_channel into a separate
wdc_regs structure, and array of which (indexed per channel) is pointed
to by struct wdc_softc.
- Move the resulting wdc_channel structure to atavar.h and rename it to
ata_channel. Rename the corresponding flags.
- Add a "ch_ndrive" member to struct ata_channel, which indicates the
maximum number of drives that can be present on the channel. For now,
this is always 2. Add an ATA_MAXDRIVES constant that places an upper
limit on this value, also currently 2.
 1.17 14-Aug-2004  thorpej - Split the register handles out of struct wdc_channel into a separate
wdc_regs structure, and array of which (indexed per channel) is pointed
to by struct wdc_softc.
- Move the resulting wdc_channel structure to atavar.h and rename it to
ata_channel. Rename the corresponding flags.
- Add a "ch_ndrive" member to struct ata_channel, which indicates the
maximum number of drives that can be present on the channel. For now,
this is always 2. Add an ATA_MAXDRIVES constant that places an upper
limit on this value, also currently 2.
 1.16 25-May-2004  thorpej Add the notion of "shadow registers" to the wdc driver. These shadow
registers are registers that overlap with others on many controllers, but
which may actually be distinct on some controllers. Right now, the two
shadows are:

- wd_status (usually overlaps wd_command)
- wd_features (usually overlaps wd_error)

Add a new helper function, wdc_init_shadow_regs(), used to initialize
the shadow register handles on controllers where they do actually overlap.

Partially from Jordan Rhody @ Wasabi Systems, Inc.
 1.15 03-Jan-2004  thorpej More wdc_channel structure member namespace cleanup:
- channel -> ch_channel
- wdc -> ch_wdc
 1.14 03-Jan-2004  thorpej Rename "struct channel_softc" to "struct wdc_channel".
 1.13 01-Jan-2004  thorpej Rename:
- wdc_xfer to ata_xfer
- channel_queue to ata_queue
and move them to <dev/ata/atavar.h> so they can be used by non-wdc ATA
controllers. Clean up the member names of these structures while at it.
 1.12 30-Dec-2003  thorpej Simplify setting up the channel queue a little.
 1.11 27-Nov-2003  fvdl There are some cards that map the ATA control and IDE DMA registers
in a different fashion. Individually, they have the same functionality,
but their layout is different. An example of such a chipset is
the Promise 203xx.

To be able to deal with this, transform the cmd and dma bus_space handles
into an array of handles, each seperately created with bus_space_subregion.
The code generated by using the extra indirection shouldn't change much,
since the extra indirection is negated by having the offset calculation
already done in bus_space_subregion. E.g.

bus_space_write_4(tag, handle, offset, value)

becomes

bus_space_write_4(tag, handles[offset], 0, value)

Reviewed by Manuel Bouyer. Tested on wdc_isa, wdc_pcmcia, viaide, piixide (i386)
and on cmdide (sparc64).
 1.10 31-Oct-2003  briggs Use aprint_*(9) instead of printf() in attach routines.
 1.9 08-Oct-2003  bouyer Make the ATA mid-layer appears as atabus, as proposed in
http://mail-index.netbsd.org/tech-kern/2003/09/25/0006.html
This adds a device (atabus) between IDE controllers and wd or atapibus, to
have each ATA channel show up in the device tree. Later there will be atabus
devices in /dev, so that we can do IOCTL on them.
Each atabus has its own kernel thread, to handle operations that needs polling,
e.g. reset and others.

Device probing on each bus it defered to the atabus thread creation.
This allows to do the reset and basic device probes in parallel, which reduce
boot time on systems with several pciide controllers.
 1.8 25-Sep-2003  mycroft Hide the use of config_interrupts() in one place.
 1.7 19-Sep-2003  mycroft 1) Use config_interrupts() to attach IDE and ATAPI drives. This eliminates
most polling.
2) Clean up some goofiness in pciide -- get rid of the whole "candisable" path
(it's gratuitous) and simplify the code by calling pciide_map_compat_intr(),
*_set_modes() and wdc_print_modes() from central locations.
3) Add a register writability and register ghost test to eliminate phantom
drives more quickly.
 1.6 02-Oct-2002  thorpej branches: 1.6.6;
Add trailing ; to CFATTACH_DECL.
 1.5 30-Sep-2002  thorpej Use CFATTACH_DECL().
 1.4 27-Sep-2002  thorpej Declare all cfattach structures const.
 1.3 13-Nov-2001  lukem add/cleanup RCSID
 1.2 14-Oct-2000  bjh21 branches: 1.2.2; 1.2.4; 1.2.6;
Shuffle printfs around so they look right when we've got a drive attached.
 1.1 16-Aug-2000  bjh21 Basic driver for CHIPS 82C710 Universal Peripheral Controller and friends,
as used on later arm26 system (A5000, A4, A3010, A3020, A4000).

What we have got:
...
upc0 at iobus0 base 0x010000: config state bb 87 1c 00 00
fdc at upc0 offset 0x3f4 not configured
wdc0 at upc0 offset 0x1f0
lpt0 at upc0 offset 0x278
com0 at upc0 offset 0x3f8: ns8250 or ns16450, no fifo
...

What we haven't got:
- FDC support (found, but not configured).
- Clearing lpt interrupts on arm26 systems (needs help from IOEB).
- A upc(4) manual page.
- More than minimal testing (my A3020s don't have root devices).
- A proper probe routine (arm26 can't use one anyway).
 1.2.6.2 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.2.6.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.2.4.2 18-Oct-2002  nathanw Catch up to -current.
 1.2.4.1 14-Nov-2001  nathanw Catch up to -current.
 1.2.2.2 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.2.2.1 14-Oct-2000  bouyer file wdc_upc.c was added on branch thorpej_scsipi on 2000-11-20 11:41:06 +0000
 1.6.6.5 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.6.6.4 21-Sep-2004  skrll Fix the sync with head I botched.
 1.6.6.3 18-Sep-2004  skrll Sync with HEAD.
 1.6.6.2 25-Aug-2004  skrll Sync with HEAD.
 1.6.6.1 03-Aug-2004  skrll Sync with HEAD
 1.19.6.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.19.4.1 29-Apr-2005  kent sync with -current
 1.20.4.4 24-Mar-2008  yamt sync with head.
 1.20.4.3 27-Oct-2007  yamt sync with head.
 1.20.4.2 30-Dec-2006  yamt sync with head.
 1.20.4.1 21-Jun-2006  yamt sync with head.
 1.21.2.1 01-Feb-2006  yamt sync with head.
 1.22.20.1 22-Oct-2006  yamt sync with head
 1.22.18.1 18-Nov-2006  ad Sync with head.
 1.23.28.1 25-Oct-2007  bouyer Sync with HEAD.
 1.23.24.2 23-Mar-2008  matt sync with HEAD
 1.23.24.1 06-Nov-2007  matt sync with HEAD
 1.23.22.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.23.8.1 23-Oct-2007  ad Sync with head.
 1.24.16.1 03-Apr-2008  mjf Sync with HEAD.
 1.24.12.1 24-Mar-2008  keiichi sync with head.
 1.25.14.1 02-Feb-2009  snj Pull up following revision(s) (requested by bjh21 in ticket #335):
sys/dev/ic/com_upc.c: revision 1.11
sys/dev/ic/lpt_upc.c: revision 1.10
sys/dev/ic/wdc_upc.c: revision 1.26
The introduction of config_stdsubmatch() lost an important feature of
upc_submatch() whereby it made sure that the correct driver attached.
Since this didn't really belong in the submatch function anyway,
reintroduce it in the match functions for upc's children.
This allows my A5000 to find at least one of its hard disks.
 1.25.12.1 03-Mar-2009  skrll Sync with HEAD.
 1.25.4.1 04-May-2009  yamt sync with head.
 1.26.14.1 30-Oct-2012  yamt sync with head
 1.29.2.1 03-Dec-2017  jdolecek update from HEAD
 1.31.4.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.35 15-Jan-2012  jakllsch Add WDCTL_HOB. Will be used for LBA48 support in AT_READREG.
 1.34 11-Dec-2005  christos branches: 1.34.110; 1.34.114;
merge ktrace-lwp.
 1.33 25-May-2004  thorpej Add the notion of "shadow registers" to the wdc driver. These shadow
registers are registers that overlap with others on many controllers, but
which may actually be distinct on some controllers. Right now, the two
shadows are:

- wd_status (usually overlaps wd_command)
- wd_features (usually overlaps wd_error)

Add a new helper function, wdc_init_shadow_regs(), used to initialize
the shadow register handles on controllers where they do actually overlap.

Partially from Jordan Rhody @ Wasabi Systems, Inc.
 1.32 30-Dec-2003  thorpej Move the register definitions for ATA Task File registers to atareg.h;
they are also used by controllers that do not map the registers into the
system address space, and are thus distinct from the "controller" registers.
 1.31 20-Dec-2003  lha add SMART Read Log constant
 1.30 03-Dec-2003  bouyer Move WDC_NREG from wdcreg.h to wdcvar.h. First part of fix for
port-macppc/23604.
 1.29 27-Nov-2003  fvdl There are some cards that map the ATA control and IDE DMA registers
in a different fashion. Individually, they have the same functionality,
but their layout is different. An example of such a chipset is
the Promise 203xx.

To be able to deal with this, transform the cmd and dma bus_space handles
into an array of handles, each seperately created with bus_space_subregion.
The code generated by using the extra indirection shouldn't change much,
since the extra indirection is negated by having the offset calculation
already done in bus_space_subregion. E.g.

bus_space_write_4(tag, handle, offset, value)

becomes

bus_space_write_4(tag, handles[offset], 0, value)

Reviewed by Manuel Bouyer. Tested on wdc_isa, wdc_pcmcia, viaide, piixide (i386)
and on cmdide (sparc64).
 1.28 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22364, verified by myself.
 1.27 26-Apr-2003  bouyer branches: 1.27.2;
Rename WDSF_EN_WR_CACHE to WDSF_WRITE_CACHE_EN for consistency with other
subcommands.
 1.26 05-Aug-2002  soren Add ATA SMART reporting support from Ben Collver in kern/12787.
 1.25 31-Mar-2002  bouyer branches: 1.25.2; 1.25.4;
Fix typo in a comment. Reported by Alexander Yurchenko in private e-mail.
 1.24 13-Jan-2002  christos Add LBA48 support based on patches from Keisuke YOSHIDA. KNF a bit while
I am there.
 1.23 21-Aug-2000  castor branches: 1.23.2; 1.23.4;
Add register definitions for S.M.A.R.T. -- an autonomous disk monitoring
standard.
 1.22 07-Mar-1999  bouyer branches: 1.22.8;
Keep track of CRC errors in Ultra-DMA mode. If we noticed a CRC error and we
need to downgrade, downgrade to PIO, as it has been shown if we got CRC errors
in Ultra-DMA mode, we will have silent data corruption in multiword DMA mode
(isn't IDE wonderfull ? :).
Set timeout to 1s for "normal" ata I/O, to minimise the effects of missed
interrupts.
 1.21 18-Jan-1999  bouyer move wd.c:print_wderror() to ata.c:ata_perror().
In wdc_probe_caps() add code to guess the ATA revision supported (if
ATA4 if Ultra-DMA, ATA2 if PIO mode > 2). We can't rely on param.atap_ata_major
here, at last one Ultra-DMA drive claims to support only ATA-3.
Use the ATA version in ata_perror(), and to try a flush cache command
in a shutdown hook for IDE drives.
 1.20 23-Nov-1998  kenh Implement the AT_READREG flag. This is needed for the CHECK POWER MODE
ATA command (among others).
 1.19 05-Nov-1998  kenh Add definitions for the ATA power management commands
 1.18 12-Oct-1998  bouyer Merge bouyer-ide
 1.17 26-Apr-1998  mycroft branches: 1.17.2;
In LBA mode, always use the `total capacity' count, rather than calculating
the capacity based on the c/h/s numbers. In fact, don't use the c/h/s
numbers for much of anything.
For ATA-4 drives or later, always use LBA mode, since it's now required.

Collectively, this allows >8GB disks (like the 12GB Bigfoot) to work.
 1.16 23-Apr-1998  bouyer Correct defifintion of the WDCE_MCR and WDCE_ABRT bits: they have been
inverted since the begining.
This doesn't change anything, as these bits are not used in the driver.
 1.15 14-Jan-1998  cgd Various cleanups and bug fixes to the wdc/wd code:
* Fix bug in wdc that would overflow ATAPI transfer length.
* Improve wdc probe code so that 'wdc' is probed in if present
even if there are no drives attached, and so that it works
properly even if the only device is an ATAPI slave.
* bus_space-ify.
* split the ISA attachment from the wdc driver, and remove
ISA dependencies from non-ISA files.
* claim that wd and wdc are now machine-independent (probably not
completely true, but mostly so; they at least work on arm32 and
i386).
* Various other minor fixups and cleanups, some of which were pointed
out by Kazuki Sakamoto.
 1.14 27-Aug-1997  bouyer Merge scsipi branch in the mainline. This add support for ATAPI devices
(currently only CD-ROM drives on i386). The sys/dev/scsipi system provides 2
busses to which devices can attach (scsibus and atapibus). This needed to
change some include files and structure names in the low level scsi drivers.
 1.13 29-Mar-1995  briggs branches: 1.13.12; 1.13.14;
KERNEL -> _KERNEL.
 1.12 26-Mar-1995  jtc KERNEL -> _KERNEL
 1.11 23-Nov-1994  mycroft Forgot to commit this as part of the LBA changes.
 1.10 22-Nov-1994  mycroft Implement EIDE multi-sector PIO and DMA modes, based on code from Onno van
der Linden. Also, various structural cleanup, and fix two bogons that crept
in, and remove all of the old clustering nonsense.
 1.9 22-Nov-1994  mycroft Change some constant names, etc., to better match the ATA spec.
 1.8 04-Nov-1994  mycroft Add a simplified version of wdcommand() that can be used in some cases.
Avoid needing a wd_softc inside wdprobe().
 1.7 27-Oct-1994  cgd new RCS ID format.
 1.6 22-Aug-1994  mycroft Fix typo in WDCS_BITS.
 1.5 10-Mar-1994  mycroft branches: 1.5.2;
Cleanup to fit standard coding conventions, and *many* bugs fixed.
 1.4 02-Mar-1994  mycroft Fix prototype of wdintr().
 1.3 11-Feb-1994  mycroft Add proc arg to wdioctl() proto.
 1.2 22-May-1993  cgd add rcsids to everything and clean up headers
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.5.2.1 22-Aug-1994  mycroft update from trunk
 1.13.14.1 27-Aug-1997  thorpej Update marc-pcmcia branch from trunk.
 1.13.12.1 01-Jul-1997  bouyer Add the ide atapi driver from my original atapi driver, ported
to scsipi.
 1.17.2.2 20-Sep-1998  bouyer - always call config_found() from wdcattach(), instead of printing our own
the "not configured" message ourselve. When no atapibus is configured,
use a fake ata_atapi_attach, else call wdc_atapibus_attach(). This way we
don't have to include the whole atapi support in an ata-only config.
- the dma_* function pointers take a 'int flags' as last argument, instead
of an 'int read'. The 2 valid flags are: WDC_DMA_READ (to select read/write)
and WDC_DMA_POLL, to signal interrupt-less mode (for core dumps).
- Reworked wdcprobe() so look more like the old one. A status of 0xff is
interpreted as "no drive" (freebsd does this); this this speed up
the probe for non-IDE machines (a reset timeout has been bumped to 31s,
to match the specs). The probe set ups the drive flags to either ATA or
ATAPI (depend on register signature) or OLD (if register signature don't
match, but a working drive appears to be there). Later the ATA code
will look at the OLD flag to decide wether there is no drive, or an old
(ST506) one if WDC_IDENTIFY fails.
- For known PCI chips, don't use the wdcprobe() heuristic to find wether
a channel is enabled/disabled; use the chip's specific registers for this.
- Clear the command queue when we have a polled command. This allows dumps to
work even if a command was being handled by the controller at panic time.
- Increase the number of available DMA segments by one, as user requests may
not be aligned on a page boundary.
 1.17.2.1 04-Jun-1998  bouyer Commit changes to the IDE system in a branch. This allows a better separation
between higth-level and low-level (i.e. registers read/write) and generalize
the queue for all commands. This also add supports for IDE DMA.
 1.22.8.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.23.4.3 06-Sep-2002  jdolecek sync kqueue branch with HEAD
 1.23.4.2 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.23.4.1 11-Feb-2002  jdolecek Sync w/ -current.
 1.23.2.4 13-Aug-2002  nathanw Catch up to -current.
 1.23.2.3 17-Apr-2002  nathanw Catch up to -current.
 1.23.2.2 28-Feb-2002  nathanw Catch up to -current.
 1.23.2.1 23-Feb-2002  gmcgarry Merge up from -current.
 1.25.4.2 14-May-2004  jdc Apply patch from revision 1.18 of sys/dev/ata/atareg.h
(requested by bouyer in ticket #1691)

When using LBA48, use Flush cache extended command if supported.
From Christos Zoulas in PR 25366, with minor adjustements from me.
 1.25.4.1 30-Jun-2003  grant Pull up revision 1.27 (requested by bouyer in ticket #1354):

Rename WDSF_EN_WR_CACHE to WDSF_WRITE_CACHE_EN for consistency with
other subcommands.
 1.25.2.1 29-Aug-2002  gehenna catch up with -current.
 1.27.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.27.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.27.2.1 03-Aug-2004  skrll Sync with HEAD
 1.34.114.1 18-Feb-2012  mrg merge to -current.
 1.34.110.1 17-Apr-2012  yamt sync with head
 1.100 13-Apr-2020  jdolecek fix use-after-free for ata xfer on bio submission found by KASAN

driver ata_bio hooks read parts of the xfer after ata_exec_xfer()
call in order to determine return value, change so that the hook
doesn't return any value - callers do not care already,
as all I/O requests are asynchronous

this problem was uncovered by recent change for wd(4) to not hold
wd mutex during ata_bio call, the interrupt for the xfer might
thus actually fire immediately

adjust also ata_exec_command driver hooks similarily - remove all
completion and waiting logic from drivers, upper layer ata code
using AT_WAIT/AT_POLL changed to call ata_wait_cmd() itself

PR kern/55169 by Nick Hudson
 1.99 14-Sep-2019  tsutsui branches: 1.99.6;
Restore interface to pass a MD reset function to MI wdcprobe().

Fixes silent hang on G1IDE on Dreamcast. PR kern/54538
Should be pulled up to netbsd-9 with the previous changes.
 1.98 07-Oct-2017  jdolecek branches: 1.98.4; 1.98.10;
Merge support for SATA NCQ (Native Command Queueing) from jdolecek-ncq branch

ATA subsystem was changed to support several outstanding commands, and use
NCQ xfers if supported by both the controller and the disk, including NCQ
error recovery. Set NCQ high priority for BPRIO_TIMECRITICAL xfers
if supported. Added FUA support.

Done some work towards MP-safe, all ATA code tsleep()/wakeup() replaced
by condvars, and switched most code from spl* to mutexes (separate
wd(4) and ata channel lock).

Introduced new option WD_CHAOS_MONKEY to facilitate testing of error
handling, fixed several uncovered issues. Also fixed several problems
with kernel dump to wd(4) disk.

Tested with ahcisata(4), mvsata(4), siisata(4), piixide(4) on amd64,
with and without port multiplier, both disk and ATAPI devices; other
drivers and archs mechanically adjusted and compile-tested. NCQ is
supported for ahcisata(4) and siisata(4) for any controller, for
mvsata(4) only Gen IIe ones for now. Also enabled ATAPI support in
mvsata(4).

Thanks to Matt Thomas for initial ATA infrastructure patch, and
Jonathan A.Kollasch for siisata(4) NCQ changes and general testing.

Also fixes PR kern/43169 (wd(4)); and PR kern/11811, PR kern/47041,
PR kern/51979 (kernel dump)
 1.97 03-Feb-2013  jakllsch branches: 1.97.26;
Add argument to wdccommandext() to allow the entire contents of the
device/head register to be specified. Needed for upcoming port multipler
support in mvsata(4).
 1.96 19-Nov-2012  rkujawa Introduce WDC_CAPABILITY_NO_AUXCTL flag. For lame controllers that don't
have aux control registers (driver coming soon).
 1.95 31-Jul-2012  bouyer branches: 1.95.2;
Apply back changes that were reverted on Jul 24 and Jul 26 (general ata/wdc
cleanup and SATA PMP support), now that I'm back to fix the fallouts.
 1.94 26-Jul-2012  jakllsch Revert, with intention of restoring in a less invasive way, the SATA Port
Multiplier code.

ok christos@
 1.93 02-Jul-2012  bouyer Add sata Port MultiPlier (PMP) support to the ata bus layer,
as described in
http://mail-index.netbsd.org/tech-kern/2012/06/23/msg013442.html
PMP support in integrated to the atabus layer.
struct ata_channel's ch_drive[] is not dynamically allocated, and ch_ndrive
(renamed to ch_ndrives) closely reflects the size of the ch_drive[] array.
Add helper functions atabus_alloc_drives() and atabus_free_drives()
to manage ch_drive[]/ch_ndrives.
Add wdc_maxdrives to struct wdc_softc so that bus front-end can specify
how much drive they really support (master/slave or single).
ata_reset_drive() callback gains a uint32_t *sigp argument which,
when not NULL, will contain the signature of the device being reset.
While there, some cosmetic changes:
- added a drive_type enum to ata_drive_datas, and stop encoding the
probed drive type in drive_flags (we were out of drive flags anyway).
- rename DRIVE_ATAPIST to DRIVE_ATAPIDSCW to better reflect what this
really is
- remove ata_channel->ata_drives, it's redundant with the pointer in
ata_drive_datas
- factor out the interpretation of SATA signatures in sata_interpet_sig()

propagate these changes to the ATA HBA drivers, and add support for PMP
to ahcisata(4) and siisata(4).

Thanks to:
- Protocase (http://www.protocase.com/) which provided a system
with lots of controllers, SATA PMP and drive slots
- Conservation Genomics Laboratory, Department of Biology, New Mexico State
University for hosting the above system
- Brook Milligan, who set up remote access and has been very responsive
when SATA cable move was needed
 1.92 09-Jan-2012  jakllsch Instead of assume that 'features' is 0 in wdccommandext(),
pass it as an argument, as is done for wdccommand().
 1.91 05-Nov-2010  jakllsch branches: 1.91.8; 1.91.12;
Pave the way for detachment of pciide(4)-family ATA controllers.
 1.90 01-Dec-2009  dyoung branches: 1.90.2; 1.90.4;
Delete wdcactivate() prototype, it's gone away for good.
 1.89 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.88 10-Jan-2008  dyoung branches: 1.88.6; 1.88.8; 1.88.10;
Let us detach atabus* from wdc*, and wdc* from isa*.

Use device_t, device_private().
 1.87 25-Oct-2006  bouyer branches: 1.87.24; 1.87.30; 1.87.38;
Add sata registers to struct wdc_regs. Add wdc_sataprobe(), a function
probing drives using the standard SATA registers; taken from various
PCI sata drivers. Export wdc_drvprobe() too.
 1.86 30-Sep-2006  itohy A little effort against kernel bloat....
Exclude ATA DMA support if no ATA DMA capable drivers are compiled in.
 1.85 07-Sep-2006  itohy branches: 1.85.2; 1.85.4;
Add PIOBM (busmastering transfer using ATA PIO mode) support.
The PIOBM is used by only one driver (will be added later,
stay tuned) and intruduce an attribute "ata_piobm" so that
it will be conditionally compiled in.
The "ata_dma" (busmastering transfer using ATA DMA mode) and
"ata_udma" (busmastering transfer using ATA Ultra DMA mode)
attributes are also added for consistency, but unused for now.
 1.84 11-Dec-2005  christos branches: 1.84.4; 1.84.8;
merge ktrace-lwp.
 1.83 06-Aug-2005  bouyer Add an optionnal controller callback for channel reset. If the callback
is set to NULL, use the generic reset code.
Use this to work around a bug in some Acer IDE controllers (like the
one found in some sparc systems) where a controller disable/enable
is required after a reset to avoid data corruption when Ultra-DMA is
used. Workaround from opensolaris, thanks to Hiroki Sato for testing.
 1.82 02-Mar-2005  mycroft branches: 1.82.2; 1.82.4;
Copyright maintenance.
 1.81 27-Feb-2005  perry nuke trailing whitespace
 1.80 11-Feb-2005  rearnsha Add support for Artisea chips operating in DPA mode, which has a
16-bit view of the ATA command registers for extended commands.

Approved by briggs.
 1.79 21-Aug-2004  thorpej branches: 1.79.4; 1.79.6;
Make some functions referenced only in wdc.c private to that file.
 1.78 20-Aug-2004  thorpej Move atabusconfig() to ata.c.
 1.77 20-Aug-2004  thorpej Move most of wdc_softc into a new atac_softc structure that contains
info common to all types of ATA controllers.
 1.76 19-Aug-2004  thorpej - Add and use a CHAN_TO_WDC() macro to get the wdc_softc from an
ata_channel.
- Add and use a CHAN_TO_WDC_REGS() macro to get the wdc_regs from an
ata_channel.
- Add and use a CHAN_TO_PCIIDE() macro to get the pciide_softc from an
ata_channel.
- Add and use a CHAN_TO_PCHAN() macro to get the pciide_channel from an
ata_channel. (This one just hides a cast, and is really just for
consistency with the others.)
 1.75 14-Aug-2004  thorpej - Split the register handles out of struct wdc_channel into a separate
wdc_regs structure, and array of which (indexed per channel) is pointed
to by struct wdc_softc.
- Move the resulting wdc_channel structure to atavar.h and rename it to
ata_channel. Rename the corresponding flags.
- Add a "ch_ndrive" member to struct ata_channel, which indicates the
maximum number of drives that can be present on the channel. For now,
this is always 2. Add an ATA_MAXDRIVES constant that places an upper
limit on this value, also currently 2.
 1.74 13-Aug-2004  thorpej Don't bother with bits that tell of the presence of optional callbacks;
just check the function pointers for NULL.
 1.73 13-Aug-2004  thorpej Move wdcstart() to ata.c and rename it to atastart().
 1.72 13-Aug-2004  thorpej Move wdc_exec_xfer() to ata.c and rename it ata_exec_xfer().
 1.71 12-Aug-2004  thorpej Move wdc_addref() and wdc_delref() to ata.c and rename them to
ata_*.
 1.70 12-Aug-2004  thorpej Move wdc_kill_pending() to ata.c and rename it ata_kill_pending().
 1.69 12-Aug-2004  thorpej - Move wdc_xfer_pool, wdc_get_xfer(), wdc_free_xfer() to ata.c, and rename
to ata_*.
- Use a static initializer for the ata_xfer_pool.
 1.68 12-Aug-2004  thorpej Move wdc_probe_caps() to ata.c and rename it ata_probe_caps().
 1.67 12-Aug-2004  thorpej Move wdc_print_modes() into ata.c and rename it ata_print_modes().
 1.66 12-Aug-2004  thorpej Rename some constants:
WDC_COMPLETE -> ATACMD_COMPLETE
WDC_QUEUED -> ATACMD_QUEUED
WDC_TRY_AGAIN -> ATACMD_TRY_AGAIN
 1.65 12-Aug-2004  thorpej Rename "struct wdc_command" to "struct ata_command".
 1.64 11-Aug-2004  mycroft Make datain_pio and dataout_pio function pointers in wdc_softc, which can
be overridden by the backend if desired. Add experimental code to wdc_pcmcia
to use this in memory-mapped mode, disabled by default.
 1.63 11-Aug-2004  mycroft Add two helper functions -- wdc_datain_pio() and wdc_dataout_pio() -- which
encapsulate the logic for the various methods of transferring data. Use these
throughout.
 1.62 04-Aug-2004  bouyer Change wdc_kill_pending() to take a struct ata_drive_datas * as argument,
and kill only pending requests for this drive.
Implement a DRIVE_WAITDRAIN flag, which will cause the active command to
be killed once complete.
Other minor fixes.
Now it's possible to detach a ATA or ATAPI device from ioctl even when
a dd on the raw char partition is running.
 1.61 04-Aug-2004  bouyer Add
struct ata_xfer *active_xfer
to ata_queue. Now the active xfer isn't the head of the queue any more,
this makes a few things easier (this will also help for tagged queuing
support).
Remove the WDCF_ACTIVE flag, test active_xfer != NULL instead.
clean up wdc_free_xfer() and kill_xfer().
Clean up wdc_reset_channel(), and make it issue a ATAPI_SOFT_RESET if the
active command is ATAPI.
In wdc_atapi_get_params(), use AT_WAIT | AT_POLL for ATAPI_SOFT_RESET,
so that we'll use tsleep() instead of delay().
In wdc_atapi_start(), call wdc_dmawait() at the right place.
 1.60 02-Aug-2004  bouyer Make it possible for (*dma_finish)() to abort quietly a DMA op. Use this
in wdc_reset_channel().
 1.59 02-Aug-2004  bouyer Clean up interraction between wdc_reset_channel and the kernel thread.
Move kill_xfer() after the reset, and stop the DMA engine if needed
(this will unload the DMA maps).
 1.58 01-Aug-2004  bouyer Implement an atabus control device, and define some ATA bus control
IOCTLS. Implement ATABUSIORESET, which will reset the given ATA bus.
 1.57 25-May-2004  thorpej Add the notion of "shadow registers" to the wdc driver. These shadow
registers are registers that overlap with others on many controllers, but
which may actually be distinct on some controllers. Right now, the two
shadows are:

- wd_status (usually overlaps wd_command)
- wd_features (usually overlaps wd_error)

Add a new helper function, wdc_init_shadow_regs(), used to initialize
the shadow register handles on controllers where they do actually overlap.

Partially from Jordan Rhody @ Wasabi Systems, Inc.
 1.56 13-Apr-2004  bouyer Make wdc_channel->ch_flags volatile, and cast it to (void *) when used
in tsleep()/wakeup() to appease gcc. Otherwise, the ch_flags value may
be cached in a register in atabus_thread(), and when it sets the WDCF_TH_RUN
bit after tsleep() it may loose loose the changes made by an interrupt handler
or another thread.
Problem analysed by Jukka Andberg on tech-kern.
 1.55 03-Jan-2004  thorpej branches: 1.55.2;
More structure member namespace cleanup: thread -> ch_thread
 1.54 03-Jan-2004  thorpej More wdc_channel structure member namespace cleanup:
- channel -> ch_channel
- wdc -> ch_wdc
 1.53 03-Jan-2004  thorpej More comment/whitespace tidy-up.
 1.52 03-Jan-2004  thorpej Rename "struct channel_softc" to "struct wdc_channel".
 1.51 01-Jan-2004  thorpej Prepend "wdc_" to wait_for_drq, wait_for_unbusy, and wait_for_ready.
 1.50 01-Jan-2004  thorpej Tidy up this file somewhat.
 1.49 01-Jan-2004  thorpej Rename:
- wdc_xfer to ata_xfer
- channel_queue to ata_queue
and move them to <dev/ata/atavar.h> so they can be used by non-wdc ATA
controllers. Clean up the member names of these structures while at it.
 1.48 30-Dec-2003  thorpej Move the drive probing code out of atabusconfig() and into a new
wdc_drvprobe() function. wdc_drvprobe() is used if the controller
does not specify a custom one prior to calling wdcattach(). The
WDC_CAPABILITY_DRVPROBE bit is gone.
 1.47 30-Dec-2003  thorpej Move most of the atabus layer into ata.c.
 1.46 15-Dec-2003  thorpej Add a (*drv_probe)() optional callback into the driver to probe for
drives on a channel. Drivers should provide this if they have some
sort of intelligent probing mechanism.
 1.45 03-Dec-2003  bouyer Move WDC_NREG from wdcreg.h to wdcvar.h. First part of fix for
port-macppc/23604.
 1.44 27-Nov-2003  fvdl There are some cards that map the ATA control and IDE DMA registers
in a different fashion. Individually, they have the same functionality,
but their layout is different. An example of such a chipset is
the Promise 203xx.

To be able to deal with this, transform the cmd and dma bus_space handles
into an array of handles, each seperately created with bus_space_subregion.
The code generated by using the extra indirection shouldn't change much,
since the extra indirection is negated by having the offset calculation
already done in bus_space_subregion. E.g.

bus_space_write_4(tag, handle, offset, value)

becomes

bus_space_write_4(tag, handles[offset], 0, value)

Reviewed by Manuel Bouyer. Tested on wdc_isa, wdc_pcmcia, viaide, piixide (i386)
and on cmdide (sparc64).
 1.43 02-Nov-2003  wiz Fix some typos. From Tom Cosgrove via jmc@openbsd.
 1.42 29-Oct-2003  bouyer freese->freeze, as pointed out by Frederick Bruck.
 1.41 08-Oct-2003  bouyer Make the ATA mid-layer appears as atabus, as proposed in
http://mail-index.netbsd.org/tech-kern/2003/09/25/0006.html
This adds a device (atabus) between IDE controllers and wd or atapibus, to
have each ATA channel show up in the device tree. Later there will be atabus
devices in /dev, so that we can do IOCTL on them.
Each atabus has its own kernel thread, to handle operations that needs polling,
e.g. reset and others.

Device probing on each bus it defered to the atabus thread creation.
This allows to do the reset and basic device probes in parallel, which reduce
boot time on systems with several pciide controllers.
 1.40 25-Sep-2003  mycroft Hide the use of config_interrupts() in one place.
 1.39 23-Sep-2003  mycroft Fix more probe delay and/or failure problems:
1) Don't wait for DRQ on an IDENTIFY command -- if it's not set when we see
BSY clear, abort the command and ignore the drive. (Do this by testing
for DRQ in the read/write cases in __wdccommand_intr().)
2) Don't wait for DRQ to deassert when we finish an IDENTIFY (or any other
non-block command that reads data) -- we don't do this for block I/O, and
empirically it doesn't clear on my CF cards at all, causing a pointless 1s
delay.
3) Add comments to some of the delay()s, and add missing ones in wdcreset()
and the WDCC_RECAL in the so-called "pre-ATA" probe.
4) Slightly simplify the reset sequence -- we were doing an extra I/O.
5) Modify the register writability test to make sure that registers are not
overlapped -- this can happen in some weird cases with a missing device 1.
6) Check the error register value after the reset -- if it's not 01h or 81h,
as appropriate (see ATA spec), punt.
Tested with a number of ATA-only, ATAPI-only, mixed ATA-ATAPI, CF, and IDE
disk configurations.

Also remove the SINGLE_DRIVE nonsense again.
 1.38 21-Sep-2003  bouyer Since we can't detect ghost drives in the wdc back-end, resurect
WDC_CAPABILITY_SINGLE_DRIVE.
 1.37 19-Sep-2003  mycroft 1) Use config_interrupts() to attach IDE and ATAPI drives. This eliminates
most polling.
2) Clean up some goofiness in pciide -- get rid of the whole "candisable" path
(it's gratuitous) and simplify the code by calling pciide_map_compat_intr(),
*_set_modes() and wdc_print_modes() from central locations.
3) Add a register writability and register ghost test to eliminate phantom
drives more quickly.
 1.36 28-Apr-2003  nakayama branches: 1.36.2;
Make DMA mode works on Promise Ultra66/100 with 48-bit LBA drives.
Ok'ed by bouyer in tech-kern@netbsd.org.
 1.35 27-Jan-2003  thorpej Experimental support for RAID volumes configured by ATA "RAID" controllers.
Such RAID controllers are actually just IDE controllers with a BIOS that
can create RAID volumes and write the configuration info to config blocks
on the disks. The BIOS can do I/O to these volumes, and the OS must
understand the config blocks and implement RAID in software in order to be
able to use these volumes.

Only SPAN (simple concatenation) and RAID0 are supported at this time,
and writing back config blocks is also not supported at this time. Currently,
only the Promise configuration scheme is supported, although supporting
the Highpoint scheme should not be too difficult.

In any case, this is sufficient to use the Promise RAID0 volume (thus
preserving the win2k AS installation) on this new Intel server I have.

Thanks to Soren Schmidt for doing the work in FreeBSD; it made this
task much easier. The config block parsing code is adapted from his
work.
 1.34 13-Jan-2002  christos branches: 1.34.10;
Add LBA48 support based on patches from Keisuke YOSHIDA. KNF a bit while
I am there.
 1.33 07-Jan-2002  dbj Changes to the wdc(4) mi driver that add the WDC_CAPABILITY_SELECT
flag and a callback function which gets called whenever a target is
selected on a channel.

The macppc wdc driver needs to reprogram its timing register
differently for each target on a channel each time that target is
selected. I also changed the ATA4_TIME_TO_TICK to use a divisor of
15, which brings our timing calculations consistent with darwin.

These patches fix problems on my dual usb ibook with combo dvd/cdrw
drive because the hard drive supports udma and the combo drive does
not. Without turning off the udma timings in the configuration
register, I cannot access the non-udma combo drive.
 1.32 03-Dec-2001  bouyer Allow wd to attach to something else than wdc/pciide (like USB<->ATA bridges):
- move some functions from ata.c to ata_wdc.c or wdc.c.
- add callbacks to struct ata_bustype so that wd.c doesn't call directly
functions from the lower level driver.
 1.31 01-Dec-2001  bouyer For ATAPI tape drives, poll for DSC (using a callout), to get the real
status of the command, and make sure the drive is ready for the next one.
 1.30 13-Jun-2001  bjh21 branches: 1.30.2;
Add explicit support for IDE and SCSI adaptors which don't support interrupts.
On such adaptors, all transfers are done in polling mode.

OK'ed by Manuel on tech-kern.
 1.29 25-Apr-2001  bouyer Pull up the thorpej_scsipi branch to main branch.
This is a completely rewritten scsipi_xfer execution engine, and the
associated changes to HBA drivers. Overview of changes & features:
- All xfers are queued in the mid-layer, rather than doing so in an
ad-hoc fashion in individual adapter drivers.
- Adapter/channel resource management in the mid-layer, avoids even trying
to start running an xfer if the adapter/channel doesn't have the resources.
- Better communication between the mid-layer and the adapters.
- Asynchronous event notification mechanism from adapter to mid-layer and
peripherals.
- Better peripheral queue management: freeze/thaw, sorted requeueing during
recovery, etc.
- Clean separation of peripherals, adapters, and adapter channels (no more
scsipi_link).
- Kernel thread for each scsipi_channel makes error recovery much easier
(no more dealing with interrupt context when recovering from an error).
- Mid-layer support for tagged queueing: commands can have the tag type
set explicitly, tag IDs are allocated in the mid-layer (thus eliminating
the need to use buggy tag ID allocation schemes in many adapter drivers).
- support for QUEUE FULL and CHECK CONDITION status in mid-layer; the command
will be requeued, or a REQUEST SENSE will be sent as appropriate.

Just before the merge syssrc has been tagged with thorpej_scsipi_beforemerge
 1.28 22-Jan-2001  mycroft branches: 1.28.2;
Force certain commands (i.e. DVD authentication) to PIO mode. They are
explicitly not supported in DMA mode, and generally return an `illegal field
in CDB' error.
This should have been done ages ago.
 1.27 06-Jan-2001  takemura Add WDC_CAPABILITY_SINGLE_DRIVE to ignore secound drive. Wdc on pcmcia will
be attached with this flag.
Some CF Card (for ex. IBM MicroDrive and SanDisk) doesn't seem to implement
drive select command. In this case, you can't eliminate ghost drive properly.
So you should use this flag to ignore the ghost by force.
 1.26 08-Nov-2000  wrstuden Move guts of pciide_print_modes() to wdc_print_modes() so that non-pciide
wdc drivers (like macppc's obio IDE interface) can use it. Also add
support to both wd attach line and to wdc_print_modes() to print
Ultra/{33,66,100} for respective UDMA modes (From Manuel Bouyer).
 1.25 12-Jun-2000  bouyer branches: 1.25.2;
Add a callback (*irqack), for controllers that need special action to ack
the interrupt once it has been ack'd on the drive.
 1.24 01-Apr-2000  bouyer branches: 1.24.2;
- DMA code cleanup: pciide_dma_finish() doesn't stop/unload the current DMA op
if an IRQ was not detected, unless the force flag was given. Use this to
detect if the IRQ was for us (closer to shared IRQ for controllers which
don't have their own IRQ handler in pciide.c) and to poll for DMA xfer.
Also makes the timeout recovery code simpler.
- ATAPI cleanup: don't call controller-specific functions from atapiconf.c
(wdc_*), so that it's possible to attach an atapibus to something else
than a wdc/pciide (Hi Lennart :).
Overload struct scsi_adapter with struct atapi_adapter, defined
as struct scsi_adapter + atapi-specific callbacks. scsipi_link still points
to an scsi_adapter, atapi code casts it to atapi_adapter if needed.
Move atapi_softc to atapiconf.h so that it can be used by the underlying
controller code (e.g. atapi_wdc.c).
Add an atapi-specific callback *atapi_probedev(), which probe a drive
in a controller-specific way, allocate the sc_link and fills in the
ataparams if needed. It then calls atapi_probedev() (from atapiconf.c)
to do the generic initialisations and attach the device.
- While I'm there merge and centralise the state definitions in atavar.h.
It should now be possible to use a common ata/atapi routine to set the
drive's modes (will do later).
 1.23 23-Mar-2000  enami Fix a typo in comment in previous commit.
 1.22 23-Mar-2000  thorpej New callout mechanism with two major improvements over the old
timeout()/untimeout() API:
- Clients supply callout handle storage, thus eliminating problems of
resource allocation.
- Insertion and removal of callouts is constant time, important as
this facility is used quite a lot in the kernel.

The old timeout()/untimeout() API has been removed from the kernel.
 1.21 20-Mar-2000  enami - Test the generic device active flag instead of home grown one.
- Test also it in wdcintr.
 1.20 20-Oct-1999  enami Cancel active transfers on aic/wdc detach.
Also makes LS-120 drive works for me again.
 1.19 23-Sep-1999  enami branches: 1.19.2; 1.19.4; 1.19.6;
Allow to detach wdc, atapibus, wd and cd.
 1.18 09-Aug-1999  bouyer Garbage-collect C_INUSE and C_NEEDDONE.
 1.17 11-Apr-1999  bouyer Fix probe code for IDE devices:
- Don't rely on ATA signature: some ide controllers seems to not transmit it
properly (SIMIDE on arm32 machines). Instead, when we guess a drive is here
after reset, just mark it as ATA and OLD is it's not ATAPI.
- at attach time, use IDENTIFY to eliminate ghost from the probe. If the
drive had the old flag and IDENTIFY failed, issue a WDCC_RECAL command
to detect a pre-ATA disk. If IDENTIFY succeded, remove the OLD flag,
it's obviously not a pre-ATA disk.
- add a new controller flag, WDC_CAPABILITY_PREATA, used to shorcut parts
of the probe (not necessary, but makes the probe/attach faster). This is
only set by the ISA front-end, all other controllers supported can't have
pre-ATA drives attached.
The mechanism used are more or less the same as before, they have just been
reordered. Should solve port-arm32/7324 (waiting for feedback).
 1.16 01-Apr-1999  bouyer branches: 1.16.2;
- change the interrupt routines to take a 3rd arguments, set to 1 if we
are called from the interrupt or timeout handler, 0 otherwise.
- use this to know if we can busy-wait for wait_for_unbusy or wait_for_ready
This fixes a bug where CDs withot the DRQ_INTR capability would not busy-wait
for the CMDOUT phase.
While I'm there change 2 delay() to DELAY() for consistency, and
garbage-collect some old code from wdcintr() which has been ifdef'd out
for some time now.
 1.15 08-Feb-1999  bouyer There's no ATA draft where it is required for the drive to set DRDY | DSC when
the disk is ready to transfer data, and in ATA-5 the DSC has been obsoleted.
So only wait for DRQ to transfer data. This can be made conditional on the
ATA version if it's proven to break with some drives (worked with all the
drives I have access to).
While I'm there correct a few typos.
 1.14 16-Dec-1998  bouyer Add a callback to re-compute the modes used on a channel.
 1.13 03-Dec-1998  bouyer Rename pio_mode, etc ... to PIO_cap, etc ... for consistency with the
ata_drive_datas struct. Suggested by Soren S. Jorvan.
 1.12 03-Dec-1998  bouyer add a udma_mode field to wdc_softc, and use it the same way dma_mode is used
(higthest ultra-dma mode supported). There may be a higther ultra-dma mode
defined ...
 1.11 02-Dec-1998  bouyer In struct wdc_xfer, change 'channel' to a pointer to a channel_softc, to avoid
a double-pointer dereference at run-time. Suggested by Matthias Drochner.
 1.10 21-Nov-1998  drochner in wdc_softc: access the per-channel data via a pointer array instead of
an array of fixed-sized channel_softc elements. This way IDE controllers
which more than 1 channel (pciide) can extend the channel data easily
for private needs.
To avoid the double dereference at runtime, change the argument of
wdcstart() to the channel data pointer instead of the array index.
 1.9 20-Nov-1998  thorpej Implement reference counting for ATA adapters.
 1.8 19-Nov-1998  thorpej Adapt to the new scsipi_adapter interface.
 1.7 17-Nov-1998  bouyer New IDE xfer flag: C_SENSE, set by the ATAPI back-end sense info needs to
be retrieved.
 1.6 12-Oct-1998  bouyer Merge bouyer-ide
 1.5 22-Sep-1998  mark Add data32iot and data32ioh members to the wdc_attachment_data structure.
This bus space tag and handle is used for 32 bit data transfers i.e.
when WDC_CAPABILITY_DATA32 is enabled as the 32 bit data register may
not be part of the standard drive registers.
 1.4 10-Sep-1998  kenh Add support for passing device quirks from the attachment routine,
and add support for a NO_EXTRA_RESETS quirk (required by the TEAC
IDE Card/II, which the Vaio uses).
 1.3 15-Aug-1998  mycroft Assign my copyrights to TNF.
 1.2 07-Apr-1998  leo branches: 1.2.2;
Add hooks to make exclusive hardware locking possible. This is necessary
to make the driver suitable for the atari falcon.
 1.1 14-Jan-1998  cgd Various cleanups and bug fixes to the wdc/wd code:
* Fix bug in wdc that would overflow ATAPI transfer length.
* Improve wdc probe code so that 'wdc' is probed in if present
even if there are no drives attached, and so that it works
properly even if the only device is an ATAPI slave.
* bus_space-ify.
* split the ISA attachment from the wdc driver, and remove
ISA dependencies from non-ISA files.
* claim that wd and wdc are now machine-independent (probably not
completely true, but mostly so; they at least work on arm32 and
i386).
* Various other minor fixups and cleanups, some of which were pointed
out by Kazuki Sakamoto.
 1.2.2.13 05-Oct-1998  bouyer Rename WDC_CAPABILITY_PIO to WDC_CAPABILITY_MODE, as it's used to tell wether
the controller's driver can tell which timing mode it uses. Check this
before setting DMA modes too.
This allow the generic DMA code to work again.
 1.2.2.12 04-Oct-1998  bouyer New flag for wdc_xfer: C_DMA, set when a cmd will use DMA. This reduce some
if() in ata_wdc.c and atapi_wdc.c from 3 tests to one.
 1.2.2.11 02-Oct-1998  bouyer Cleanup a few error message, remove some dead code. Re-add a reset at end of
attach, unless we have WDC_NO_EXTRA_RESETS.
Add support for data32iot/data32ioh from -current: each controller pass
WDC_CAPABILITY_DATA32 if they can do 32bit, and WDC_CAPABILITY_DATA16 if they
can do 16bit. For controller that support both, the usual autodetect
mechanism is still used.
 1.2.2.10 20-Sep-1998  bouyer Kill the 'old drive' flag. The probe for IDE controllers now looks
like this :
- if status = 0xff for both master and slave, no drive at all -> exit.
- issue a reset (timeout = 31s).
- test signatures: if ATAPI signature, flag a (possible) ATAPI devices here
else test register writability, then wait for the drive to become
ready, issue a diagnostic command and wait for the drive to become ready
if ok, flag a real ATA device.
This looks more like the old probe.
For ATA devices, if IDENTIFY fails, then it's an old drive and use
a fake disklabel/geometry.
 1.2.2.9 20-Sep-1998  bouyer - always call config_found() from wdcattach(), instead of printing our own
the "not configured" message ourselve. When no atapibus is configured,
use a fake ata_atapi_attach, else call wdc_atapibus_attach(). This way we
don't have to include the whole atapi support in an ata-only config.
- the dma_* function pointers take a 'int flags' as last argument, instead
of an 'int read'. The 2 valid flags are: WDC_DMA_READ (to select read/write)
and WDC_DMA_POLL, to signal interrupt-less mode (for core dumps).
- Reworked wdcprobe() so look more like the old one. A status of 0xff is
interpreted as "no drive" (freebsd does this); this this speed up
the probe for non-IDE machines (a reset timeout has been bumped to 31s,
to match the specs). The probe set ups the drive flags to either ATA or
ATAPI (depend on register signature) or OLD (if register signature don't
match, but a working drive appears to be there). Later the ATA code
will look at the OLD flag to decide wether there is no drive, or an old
(ST506) one if WDC_IDENTIFY fails.
- For known PCI chips, don't use the wdcprobe() heuristic to find wether
a channel is enabled/disabled; use the chip's specific registers for this.
- Clear the command queue when we have a polled command. This allows dumps to
work even if a command was being handled by the controller at panic time.
- Increase the number of available DMA segments by one, as user requests may
not be aligned on a page boundary.
 1.2.2.8 11-Sep-1998  bouyer Sync with HEAD.
 1.2.2.7 21-Aug-1998  bouyer Sync with -current
 1.2.2.6 13-Aug-1998  bouyer - sync with HEAD
- better error detection and report for wd drives
- better wddump() support
- wdcwait() now takes a timout argument, so that we can honnor the
timeout argument of scsipi cmds.
 1.2.2.5 23-Jun-1998  leo Add necessary cruft to handle swapped byte-lanes on the data-register. It
basically boils down to the fact that there are 2 new options:
WDC_CAPABILITY_{ATA,ATAPI}_NOSTREAM with which you are able to control
the usage bus_space_read_multi_X() vs. bus_space_read_multi_stream_X().
 1.2.2.4 19-Jun-1998  leo Kill typo
 1.2.2.3 05-Jun-1998  bouyer A few bux fixes (untested):
- If the PIO mode of the controller is unknown, put the drive in the
hightest mode it supports. A drive in a faster mode than the controller
should work.
- Create DMA maps even for unknown controllers in pciide.
 1.2.2.2 05-Jun-1998  bouyer Patches from Leo Weppelman for IDE on atari, with minor fixes by me
(needed the addition of a void wdcrestart __P((void*)) function).
Quoting his words:
These diffs are preliminary because it looks like the free_hw() function
does not get called. This is only a problem on the atari falcon. I have not
yet been able to track this down.
Also, KNF wdc.c.
 1.2.2.1 04-Jun-1998  bouyer Commit changes to the IDE system in a branch. This allows a better separation
between higth-level and low-level (i.e. registers read/write) and generalize
the queue for all commands. This also add supports for IDE DMA.
 1.16.2.2 07-Jul-2000  he Apply patch (requested by bouyer):
Add support for the following PCIIDE controllers:
o AMD 756
o CMD PCI0648 and PCI0649
o Hightpoint HPT366
o OPTi 82c621 (and a few of its derivatives)
o Promise Ultra/33 and Ultra/66
o Intel 82801 (ICH/ICH0)
Also fix PR#10437 (detect more ATAPI devices).
 1.16.2.1 12-Apr-1999  bouyer branches: 1.16.2.1.2;
Sync with ic/wdc.c 1.67, ic/wdcvar.h 1.17, isa/wdc_isa.c 1.14:
Revert to a more conservative probe: it controller responded and we don't find
ATAPI signature, assume it and ATA or OLD drive (OLD is only set if the
wdc front end passed WDC_CAPABILITIES_OLD, only used for ISA front-end).
At attach time, issue an IDENTIFY to detect drives and eliminates ghosts.
If IDENTIFY failed and OLD is set, issue a RECAL to check for the presence
of old drives.
Should fix the 'disk dissapeared' problems reported by some users, including
port-arm32/7324.
 1.16.2.1.2.1 21-Jun-1999  thorpej Sync w/ -current.
 1.19.6.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.19.4.1 15-Nov-1999  fvdl Sync with -current
 1.19.2.6 11-Feb-2001  bouyer Sync with HEAD.
 1.19.2.5 18-Jan-2001  bouyer Sync with head (for UBC+NFS fixes, mostly).
 1.19.2.4 22-Nov-2000  bouyer Sync with HEAD.
 1.19.2.3 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.19.2.2 20-Oct-1999  thorpej Sync w/ trunk.
 1.19.2.1 19-Oct-1999  thorpej Adapt to scsipi API changes.
 1.24.2.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.25.2.2 16-Jan-2002  he Pull up revision 1.33 (via patch, requested by dbj):
Add UDMA support and allow separate DMA timings to be programmed
for two different devices on the same wdc channel on the macppc.
The machine-independent driver is updated to optionally use the
WDC_CAPABILITY_SELECT callback whenever a target is selected on
a channel.
 1.25.2.1 27-Dec-2001  he Pull up revision 1.28 (requested by mycroft):
Make DVD commands work on drives configured for DMA.
 1.28.2.5 28-Feb-2002  nathanw Catch up to -current.
 1.28.2.4 23-Feb-2002  gmcgarry Merge up from -current.
 1.28.2.3 11-Jan-2002  nathanw More catchup.
 1.28.2.2 08-Jan-2002  nathanw Catch up to -current.
 1.28.2.1 21-Jun-2001  nathanw Catch up to -current.
 1.30.2.2 11-Feb-2002  jdolecek Sync w/ -current.
 1.30.2.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.34.10.1 28-Apr-2003  tron Pull up revision 1.36 (requested by nakayama in ticket #1275):
Make DMA mode works on Promise Ultra66/100 with 48-bit LBA drives.
Ok'ed by bouyer in tech-kern@netbsd.org.
 1.36.2.8 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.36.2.7 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.36.2.6 15-Feb-2005  skrll Sync with HEAD.
 1.36.2.5 21-Sep-2004  skrll Fix the sync with head I botched.
 1.36.2.4 18-Sep-2004  skrll Sync with HEAD.
 1.36.2.3 25-Aug-2004  skrll Sync with HEAD.
 1.36.2.2 12-Aug-2004  skrll Sync with HEAD.
 1.36.2.1 03-Aug-2004  skrll Sync with HEAD
 1.55.2.1 18-Apr-2004  jmc branches: 1.55.2.1.2;
Pullup rev 1.56 (requested by bouyer in ticket #149)

Make wdc_channel->ch_flags volatile, and cast it to (void *) when used
in tsleep()/wakeup() to appease gcc. Otherwise, the ch_flags value may
be cached in a register in atabus_thread(), and when it sets the WDCF_TH_RUN
bit after tsleep() it may loose loose the changes made by an interrupt handler
or another thread.
 1.55.2.1.2.1 07-Aug-2005  riz Pull up revision 1.83 via patch (requested by bouyer in ticket #5555):
Add an optionnal controller callback for channel reset. If the callback
is set to NULL, use the generic reset code.
Use this to work around a bug in some Acer IDE controllers (like the
one found in some sparc systems) where a controller disable/enable
is required after a reset to avoid data corruption when Ultra-DMA is
used. Workaround from opensolaris, thanks to Hiroki Sato for testing.
 1.79.6.2 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.79.6.1 12-Feb-2005  yamt sync with head.
 1.79.4.1 29-Apr-2005  kent sync with -current
 1.82.4.3 21-Jan-2008  yamt sync with head
 1.82.4.2 30-Dec-2006  yamt sync with head.
 1.82.4.1 21-Jun-2006  yamt sync with head.
 1.82.2.1 18-Aug-2005  tron Pull up revision 1.83 (requested by bouyer in ticket #653):
Add an optionnal controller callback for channel reset. If the callback
is set to NULL, use the generic reset code.
Use this to work around a bug in some Acer IDE controllers (like the
one found in some sparc systems) where a controller disable/enable
is required after a reset to avoid data corruption when Ultra-DMA is
used. Workaround from opensolaris, thanks to Hiroki Sato for testing.
 1.84.8.1 14-Sep-2006  yamt sync with head.
 1.84.4.1 09-Sep-2006  rpaulo sync with head
 1.85.4.2 10-Dec-2006  yamt sync with head.
 1.85.4.1 22-Oct-2006  yamt sync with head
 1.85.2.1 18-Nov-2006  ad Sync with head.
 1.87.38.1 10-Jan-2008  bouyer Sync with HEAD
 1.87.30.1 18-Feb-2008  mjf Sync with HEAD.
 1.87.24.1 23-Mar-2008  matt sync with HEAD
 1.88.10.2 11-Mar-2010  yamt sync with head
 1.88.10.1 16-May-2008  yamt sync with head.
 1.88.8.1 18-May-2008  yamt sync with head.
 1.88.6.1 02-Jun-2008  mjf Sync with HEAD.
 1.90.4.1 05-Mar-2011  rmind sync with head
 1.90.2.1 06-Nov-2010  uebayasi Sync with HEAD.
 1.91.12.1 18-Feb-2012  mrg merge to -current.
 1.91.8.4 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.91.8.3 16-Jan-2013  yamt sync with (a bit old) head
 1.91.8.2 30-Oct-2012  yamt sync with head
 1.91.8.1 17-Apr-2012  yamt sync with head
 1.95.2.2 03-Dec-2017  jdolecek update from HEAD
 1.95.2.1 25-Feb-2013  tls resync with head
 1.97.26.3 27-Sep-2017  jdolecek change wdc_init_shadow_regs() to accept only struct wdc_regs, it doesn't
touch anything else

factor out the probe-only struct ata_channel initialization to wdcprobe(), to
reduce duplication of logic in individual drivers, and to actually work now
that more init is needed beyond the memset()
 1.97.26.2 12-Aug-2017  jdolecek remove all logic around ATACH_IRQ_WAIT and channel-global ch_error/ch_status,
so that there is less hidden state shared by commands; primary intent is
to make the NCQ and non-NCQ paths more similar, and remove possibility
of incorrect handling for the NCQ commands

tested both disk and ATAPI - piixide(4) on QEMU, and siisata(4),
ahcisata(4), mvsata(4) on real hw
 1.97.26.1 15-Apr-2017  jdolecek pass also ata_command via ata_xfer, callers of ata_exec_command() is now
responsible for allocation/disposal of the structure

change code to allocate ata_xfer for commands on stack same way as previously
the ata_command were, using c_slot 0; adjust asserts so that it would allow
several xfers with same c_slot, as long as only one such transfer is active
at a time
 1.98.10.2 30-Dec-2022  martin Pull up following revision(s) (requested by tsutsui in ticket #1557):

sys/dev/ic/ahcisata_core.c: revision 1.83
sys/dev/ic/ahcisata_core.c: revision 1.102
sys/dev/ata/ata.c: revision 1.164
sys/dev/ata/ata_wdc.c: revision 1.115
sys/dev/ata/ata_recovery.c: revision 1.4
sys/dev/ic/siisata.c: revision 1.42
sys/dev/ic/wdc.c: revision 1.308
sys/dev/ic/mvsata.c: revision 1.56
sys/dev/scsipi/atapi_wdc.c: revision 1.138
sys/dev/ic/siisata.c: revision 1.49
sys/dev/ata/atavar.h: revision 1.105
sys/dev/ata/wd.c: revision 1.460
sys/dev/ata/ata.c: revision 1.155
sys/dev/ata/wd.c: revision 1.462
sys/dev/ata/atavar.h: revision 1.109
sys/dev/ata/satapmp_subr.c: revision 1.16
sys/dev/ic/wdc.c: revision 1.299
sys/dev/ic/ahcisata_core.c: revision 1.93
sys/dev/ata/ata_wdc.c: revision 1.120
sys/dev/ic/wdcvar.h: revision 1.100
sys/dev/scsipi/atapi_wdc.c: revision 1.141
sys/dev/ic/mvsata.c: revision 1.61
sys/dev/usb/umass_isdata.c (apply patch)

drop wd lock in wdstart1() before calling the ata_bio hook; when called
from ata thread context, that can still need to sleep for wdc attachments
in wdcwait()

fix use-after-free for ata xfer on bio submission found by KASAN
driver ata_bio hooks read parts of the xfer after ata_exec_xfer()
call in order to determine return value, change so that the hook
doesn't return any value - callers do not care already,
as all I/O requests are asynchronous

this problem was uncovered by recent change for wd(4) to not hold
wd mutex during ata_bio call, the interrupt for the xfer might
thus actually fire immediately

adjust also ata_exec_command driver hooks similarily - remove all
completion and waiting logic from drivers, upper layer ata code
using AT_WAIT/AT_POLL changed to call ata_wait_cmd() itself
PR kern/55169 by Nick Hudson

Function declaration formating whitespace consistency. NFCI.

PR kern/56403
Fix kernel freeze for wdc(4) variants with ATAC_CAP_NOIRQ:

(1) Change ata_xfer_ops:c_poll from void to int function. When it returns
ATAPOLL_AGAIN, let ata_xfer_start() iterate itself again.
(2) Let wdc_ata_bio_poll() return ATAPOLL_AGAIN until ATA_ITSDONE is
achieved.

A similar change has been made for mvsata(4) (see mvsata_bio_poll()),
and no functional changes for other devices.

This is how the drivers worked before jdolecek-ncq branch was merged.
Note that this changes are less likely to cause infinite recursion:

(1) wdc_ata_bio_intr() called from wdc_ata_bio_poll() asserts ATA_ITSDONE
in its error handling paths via wdc_ata_bio_done().
(2) Return value from c_start (= wdc_ata_bio_start()) is checked in
ata_xfer_start().

Therefore, errors encountered in ata_xfer_ops:c_poll and c_start routines
terminate the recursion for wdc(4). The situation is similar for mvsata(4).

Still, there is a possibility where ata_xfer_start() takes long time to
finish a normal operation. This can result in a delayed response for lower
priority interrupts. But, I've never observed such a situation, even when
heavy thrashing takes place for swap partition in wd(4).
"Go ahead" by jdolecek@.
 1.98.10.1 23-Sep-2019  martin Pull up following revision(s) (requested by tsutsui in ticket #232):

sys/arch/evbppc/mpc85xx/wdc_obio.c: revision 1.7
sys/arch/dreamcast/dev/g1/wdc_g1.c: revision 1.4
sys/arch/dreamcast/dev/g1/wdc_g1.c: revision 1.5
sys/arch/mmeye/dev/wdc_mainbus.c: revision 1.7
sys/dev/ic/wdcvar.h: revision 1.99
sys/dev/ic/wdc.c: revision 1.292
sys/arch/mips/adm5120/dev/wdc_extio.c: revision 1.11

adjust several missed drivers for wdcprobe() changes of ATA NCQ branch
for dreamcast g1 just drop the custom reset function, it doesn't seem to do
anything useful over the generic variant

PR kern/54538 by Izumi Tsutsui

Restore interface to pass a MD reset function to MI wdcprobe().

Fixes silent hang on G1IDE on Dreamcast. PR kern/54538
Should be pulled up to netbsd-9 with the previous changes.
 1.98.4.2 21-Apr-2020  martin Sync with HEAD
 1.98.4.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.99.6.1 20-Apr-2020  bouyer Sync with HEAD
 1.17 19-Mar-2010  tsutsui Replace some magic numbers with macro. Tested on SMC_TT on atari.
 1.16 19-Mar-2010  tsutsui Misc KNF.
 1.15 28-Apr-2008  martin branches: 1.15.20; 1.15.22;
Remove clause 3 and 4 from TNF licenses
 1.14 12-Mar-2008  cube branches: 1.14.2; 1.14.4;
Split device_t and softc for the NE2000 Ethernet chip and all its variants
and attachments. Use device_t accessors, correct types, and ANSIfy when
appropriate.
 1.13 19-Oct-2007  ad branches: 1.13.12; 1.13.16;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.12 04-Mar-2007  christos branches: 1.12.2; 1.12.14; 1.12.16; 1.12.20;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.11 29-Mar-2006  thorpej branches: 1.11.14;
Use device_cfdata().
 1.10 29-Jan-2006  dsl branches: 1.10.2; 1.10.4; 1.10.6; 1.10.8; 1.10.10;
Make almost everything #include <sys/bswap.h> instead of <machine/bswap.h>
The bswap.h and endian.h files are all rather incestuous, but I want to
get the constant folding stuff into one place - sys/bswap.h
 1.9 24-Dec-2005  perry branches: 1.9.2;
Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.8 11-Dec-2005  christos merge ktrace-lwp.
 1.7 03-Apr-2005  jdolecek branches: 1.7.2;
Make it possible for attachment to specify that the 16bit access shouldn't
be toggled in WE_MEM_{ENABLE|DISABLE} when receiving or transmitting packets.
Use this to switch the toggle off for MCA cards, since it causes NIC resets
there.

Fixes PR kern/26895 by Dave Barnes.
 1.6 04-Feb-2005  perry de-__P
 1.5 15-Jan-2003  bouyer branches: 1.5.2; 1.5.10; 1.5.12;
Zero out the NIC memory when padding packet to ETHER_MIN_LEN-ETHER_CRC_LEN
sc->write_mbuf now return len of buffer, including padding.
Tested with a PCI ne2000.
 1.4 13-Nov-2001  lukem branches: 1.4.10;
add/cleanup RCSID
 1.3 04-Jul-2001  jdolecek branches: 1.3.2;
g/c WE_FLAGS_*, use DP8390_FORCE_{8|16}BIT_MODE instead WE_FLAGS_*
counterpart. Fixes kern/7295 by Martin Husemann.
 1.2 29-Mar-2001  jdolecek branches: 1.2.2;
kill bunch of unneeded includes
 1.1 23-Mar-2001  jdolecek branches: 1.1.2;
Split we(4) driver to bus independant and ISA-specific parts, in preparation
for MCA attachment.
 1.1.2.3 21-Apr-2001  bouyer Sync with HEAD
 1.1.2.2 27-Mar-2001  bouyer Sync with HEAD.
 1.1.2.1 23-Mar-2001  bouyer file we.c was added on branch thorpej_scsipi on 2001-03-27 15:32:01 +0000
 1.2.2.5 17-Jan-2003  thorpej Sync with HEAD.
 1.2.2.4 14-Nov-2001  nathanw Catch up to -current.
 1.2.2.3 24-Aug-2001  nathanw Catch up with -current.
 1.2.2.2 09-Apr-2001  nathanw Catch up with -current.
 1.2.2.1 29-Mar-2001  nathanw file we.c was added on branch nathanw_sa on 2001-04-09 01:56:34 +0000
 1.3.2.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.4.10.1 27-Jan-2003  jmc Pullup revisions 1.4-1.5 (requested by bouyer in ticket #1096)
Zero out the NIC memory when padding packet to
ETHER_MIN_LEN-ETHER_CRC_LEN sc->write_mbuf now return len of
buffer, including padding.
 1.5.12.1 12-Feb-2005  yamt sync with head.
 1.5.10.1 29-Apr-2005  kent sync with -current
 1.5.2.2 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.5.2.1 04-Feb-2005  skrll Sync with HEAD.
 1.7.2.4 17-Mar-2008  yamt sync with head.
 1.7.2.3 27-Oct-2007  yamt sync with head.
 1.7.2.2 03-Sep-2007  yamt sync with head.
 1.7.2.1 21-Jun-2006  yamt sync with head.
 1.9.2.1 01-Feb-2006  yamt sync with head.
 1.10.10.1 31-Mar-2006  tron Merge 2006-03-31 NetBSD-current into the "peter-altq" branch.
 1.10.8.1 19-Apr-2006  elad sync with head.
 1.10.6.1 01-Apr-2006  yamt sync with head.
 1.10.4.1 22-Apr-2006  simonb Sync with head.
 1.10.2.1 09-Sep-2006  rpaulo sync with head
 1.11.14.1 12-Mar-2007  rmind Sync with HEAD.
 1.12.20.1 25-Oct-2007  bouyer Sync with HEAD.
 1.12.16.2 23-Mar-2008  matt sync with HEAD
 1.12.16.1 06-Nov-2007  matt sync with HEAD
 1.12.14.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.12.2.1 23-Oct-2007  ad Sync with head.
 1.13.16.2 02-Jun-2008  mjf Sync with HEAD.
 1.13.16.1 03-Apr-2008  mjf Sync with HEAD.
 1.13.12.1 24-Mar-2008  keiichi sync with head.
 1.14.4.2 11-Aug-2010  yamt sync with head.
 1.14.4.1 16-May-2008  yamt sync with head.
 1.14.2.1 18-May-2008  yamt sync with head.
 1.15.22.1 30-May-2010  rmind sync with head
 1.15.20.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.3 19-Mar-2010  tsutsui Replace some magic numbers with macro. Tested on SMC_TT on atari.
 1.2 04-Jul-2001  jdolecek branches: 1.2.124; 1.2.146; 1.2.148;
g/c WE_FLAGS_*, use DP8390_FORCE_{8|16}BIT_MODE instead WE_FLAGS_*
counterpart. Fixes kern/7295 by Martin Husemann.
 1.1 23-Mar-2001  jdolecek branches: 1.1.2; 1.1.4;
Split we(4) driver to bus independant and ISA-specific parts, in preparation
for MCA attachment.
 1.1.4.3 24-Aug-2001  nathanw Catch up with -current.
 1.1.4.2 09-Apr-2001  nathanw Catch up with -current.
 1.1.4.1 23-Mar-2001  nathanw file wereg.h was added on branch nathanw_sa on 2001-04-09 01:56:34 +0000
 1.1.2.2 27-Mar-2001  bouyer Sync with HEAD.
 1.1.2.1 23-Mar-2001  bouyer file wereg.h was added on branch thorpej_scsipi on 2001-03-27 15:32:02 +0000
 1.2.148.1 30-May-2010  rmind sync with head
 1.2.146.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.2.124.1 11-Aug-2010  yamt sync with head.
 1.5 12-May-2009  cegger struct device * -> device_t, no functional changes intended.
 1.4 11-Dec-2005  christos branches: 1.4.74; 1.4.90;
merge ktrace-lwp.
 1.3 03-Apr-2005  jdolecek Make it possible for attachment to specify that the 16bit access shouldn't
be toggled in WE_MEM_{ENABLE|DISABLE} when receiving or transmitting packets.
Use this to switch the toggle off for MCA cards, since it causes NIC resets
there.

Fixes PR kern/26895 by Dave Barnes.
 1.2 04-Feb-2005  perry de-__P
 1.1 23-Mar-2001  jdolecek branches: 1.1.2; 1.1.4; 1.1.26; 1.1.34; 1.1.36;
Split we(4) driver to bus independant and ISA-specific parts, in preparation
for MCA attachment.
 1.1.36.1 12-Feb-2005  yamt sync with head.
 1.1.34.1 29-Apr-2005  kent sync with -current
 1.1.26.2 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.1.26.1 04-Feb-2005  skrll Sync with HEAD.
 1.1.4.2 09-Apr-2001  nathanw Catch up with -current.
 1.1.4.1 23-Mar-2001  nathanw file wevar.h was added on branch nathanw_sa on 2001-04-09 01:56:35 +0000
 1.1.2.2 27-Mar-2001  bouyer Sync with HEAD.
 1.1.2.1 23-Mar-2001  bouyer file wevar.h was added on branch thorpej_scsipi on 2001-03-27 15:32:02 +0000
 1.4.90.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.4.74.1 16-May-2009  yamt sync with head
 1.258 01-Aug-2023  mrg fix simple mis-matched function prototype and definitions.

most of these are like, eg

void foo(int[2]);

with either of these

void foo(int*) { ... }
void foo(int[]) { ... }

in some cases (such as stat or utimes* calls found in our header files),
we now match standard definition from opengroup.

found by GCC 12.
 1.257 21-Sep-2021  christos don't opencode kauth_cred_get()
 1.256 16-Jun-2021  riastradh if_attach and if_initialize cannot fail, don't test return value

These were originally made failable back in 2017 when if_initialize
allocated a softint in every interface for link state changes, so
that it could fail gracefully instead of panicking:

https://mail-index.NetBSD.org/source-changes/2017/10/23/msg089053.html

However, this spawned many seldom- or never-tested error branches,
which are risky to have around. And that softint in every interface
has since been replaced by a single global workqueue, because link
state changes require thread context but not low latency or high
throughput:

https://mail-index.NetBSD.org/source-changes/2020/02/06/msg113759.html

So there is no longer any reason for if_initialize to fail. (The
subroutine if_stats_init can't fail because percpu_alloc can't fail
either.)

There is a snag: the softint_establish in if_percpuq_create could
fail, potentially leading to bad consequences later on trying to use
the softint. This change doesn't introduce any new bugs because of
the snag -- if_percpuq_attach was already broken. However, the snag
can be better addressed without spawning error branches, either by
using a single softint or making softints less scarce.

(Separate commit will change the signatures of if_attach and
if_initialize to return void, scheduled to ride whatever is the next
convenient kernel bump.)

Patch and testing on amd64 and evbmips64-eb by maya@; commit message
soliloquy, and compile-testing on evbppc/i386/earmv7hf, by me.
 1.255 30-Jan-2020  thorpej branches: 1.255.10;
Adopt <net/if_stats.h>.
 1.254 05-Dec-2019  msaitoh branches: 1.254.2;
Remove SIOC[GS]IFMEDIA because ieee80211_ioctl() does the same thing.
 1.253 28-May-2019  msaitoh Use ETHER_LOCK()/ETHER_UNLOCK() for all ethernet drivers to protect ec_multi*.
 1.252 23-May-2019  msaitoh Whitespace fix (mainly tabify).
 1.251 23-May-2019  msaitoh -No functional change:
- KNF
- u_int*_t -> uint*_t.
 1.250 05-Feb-2019  msaitoh Remove very old IFF_NOTRAILERS flag.
 1.249 15-Nov-2018  maxv Remove the 'copy' argument from m_devget(), unused. While here rename
off0->off.
 1.248 03-Sep-2018  riastradh Rename min/max -> uimin/uimax for better honesty.

These functions are defined on unsigned int. The generic name
min/max should not silently truncate to 32 bits on 64-bit systems.
This is purely a name change -- no functional change intended.

HOWEVER! Some subsystems have

#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))

even though our standard name for that is MIN/MAX. Although these
may invite multiple evaluation bugs, these do _not_ cause integer
truncation.

To avoid `fixing' these cases, I first changed the name in libkern,
and then compile-tested every file where min/max occurred in order to
confirm that it failed -- and thus confirm that nothing shadowed
min/max -- before changing it.

I have left a handful of bootloaders that are too annoying to
compile-test, and some dead code:

cobalt ews4800mips hp300 hppa ia64 luna68k vax
acorn32/if_ie.c (not included in any kernels)
macppc/if_gm.c (superseded by gem(4))

It should be easy to fix the fallout once identified -- this way of
doing things fails safe, and the goal here, after all, is to _avoid_
silent integer truncations, not introduce them.

Maybe one day we can reintroduce min/max as type-generic things that
never silently truncate. But we should avoid doing that for a while,
so that existing code has a chance to be detected by the compiler for
conversion to uimin/uimax without changing the semantics until we can
properly audit it all. (Who knows, maybe in some cases integer
truncation is actually intended!)
 1.247 26-Jun-2018  msaitoh branches: 1.247.2;
Implement the BPF direction filter (BIOC[GS]DIRECTION). It provides backward
compatibility with BIOC[GS]SEESENT ioctl. The userland interface is the same
as FreeBSD.

This change also fixes a bug that the direction is misunderstand on some
environment by passing the direction to bpf_mtap*() instead of checking
m->m_pkthdr.rcvif.
 1.246 23-Jun-2018  maxv constify
 1.245 22-Jun-2018  msaitoh It's not required to include net/bpfdesc.h. Remove it.
 1.244 23-Oct-2017  msaitoh branches: 1.244.2;
If if_initialize() failed in the attach function, free resources and return.
 1.243 29-Mar-2017  msaitoh branches: 1.243.6;
Fix 0x%d and 0x%u.
 1.242 02-Feb-2017  nonaka wlan interfaces make interrupt routine running on softint context.

see http://mail-index.netbsd.org/tech-kern/2016/12/06/msg021281.html

tested device:
* ath at pci: AR5212, AR5424
* athn at pci: AR9287
* ipw at pci: 2100BG
* iwi at pci: 2915ABG
* iwm at pci: 3165, 7260, 8260
* iwn at pci: 4945, 6235
* ral at pci: RT2560
* rtwn at pci: RTL8192CE
 1.241 01-Feb-2017  nonaka Added missing splx(s).
 1.240 10-Jun-2016  ozaki-r branches: 1.240.2; 1.240.4;
Introduce m_set_rcvif and m_reset_rcvif

The API is used to set (or reset) a received interface of a mbuf.
They are counterpart of m_get_rcvif, which will come in another
commit, hide internal of rcvif operation, and reduce the diff of
the upcoming change.

No functional change.
 1.239 26-May-2016  ozaki-r Introduce M_CLEARCTX and use it instead of open-coding rcvif

No functional change.
 1.238 26-May-2016  ozaki-r Use M_GETCTX

No functional change.
 1.237 25-Feb-2014  pooka branches: 1.237.6;
Ensure that the top level sysctl nodes (kern, vfs, net, ...) exist before
the sysctl link sets are processed, and remove redundancy.

Shaves >13kB off of an amd64 GENERIC, not to mention >1k duplicate
lines of code.
 1.236 15-Sep-2013  martin Mark a potentially unused variable
 1.235 15-Aug-2011  dyoung branches: 1.235.2; 1.235.12; 1.235.16;
Use a recursive lock to ensure that only on thread is in wi_ioctl() at
one time. It's a recursive lock because sometimes wi_ioctl() recurses
through the network stack (ick).
 1.234 23-Nov-2010  christos split if_wi
 1.233 05-Apr-2010  joerg Push the bpf_ops usage back into bpf.h. Push the common ifp->if_bpf
check into the inline functions as well the fourth argument for
bpf_attach.
 1.232 19-Jan-2010  pooka branches: 1.232.2; 1.232.4;
Redefine bpf linkage through an always present op vector, i.e.
#if NBPFILTER is no longer required in the client. This change
doesn't yet add support for loading bpf as a module, since drivers
can register before bpf is attached. However, callers of bpf can
now be modularized.

Dynamically loadable bpf could probably be done fairly easily with
coordination from the stub driver and the real driver by registering
attachments in the stub before the real driver is loaded and doing
a handoff. ... and I'm not going to ponder the depths of unload
here.

Tested with i386/MONOLITHIC, modified MONOLITHIC without bpf and rump.
 1.231 15-Sep-2009  dyoung Simplify activation routines. Don't block interrupts, if_deactivate()
does it. Compile-tested, only.
 1.230 12-May-2009  cegger struct device * -> device_t, no functional changes intended.
 1.229 15-Apr-2009  elad Remove a few KAUTH_GENERIC_ISSUSER in favor of more descriptive
alternatives.

Discussed on tech-kern:

http://mail-index.netbsd.org/tech-kern/2009/04/11/msg004798.html

Input from ad@, christos@, dyoung@, tsutsui@.

Okay ad@.
 1.228 12-Nov-2008  ad branches: 1.228.4;
Remove LKMs and switch to the module framework, pass 1.

Proposed on tech-kern@.
 1.227 07-Nov-2008  dyoung *** Summary ***

When a link-layer address changes (e.g., ifconfig ex0 link
02:de:ad:be:ef:02 active), send a gratuitous ARP and/or a Neighbor
Advertisement to update the network-/link-layer address bindings
on our LAN peers.

Refuse a change of ethernet address to the address 00:00:00:00:00:00
or to any multicast/broadcast address. (Thanks matt@.)

Reorder ifnet ioctl operations so that driver ioctls may inherit
the functions of their "class"---ether_ioctl(), fddi_ioctl(), et
cetera---and the class ioctls may inherit from the generic ioctl,
ifioctl_common(), but both driver- and class-ioctls may override
the generic behavior. Make network drivers share more code.

Distinguish a "factory" link-layer address from others for the
purposes of both protecting that address from deletion and computing
EUI64.

Return consistent, appropriate error codes from network drivers.

Improve readability. KNF.

*** Details ***

In if_attach(), always initialize the interface ioctl routine,
ifnet->if_ioctl, if the driver has not already initialized it.
Delete if_ioctl == NULL tests everywhere else, because it cannot
happen.

In the ioctl routines of network interfaces, inherit common ioctl
behaviors by calling either ifioctl_common() or whichever ioctl
routine is appropriate for the class of interface---e.g., ether_ioctl()
for ethernets.

Stop (ab)using SIOCSIFADDR and start to use SIOCINITIFADDR. In
the user->kernel interface, SIOCSIFADDR's argument was an ifreq,
but on the protocol->ifnet interface, SIOCSIFADDR's argument was
an ifaddr. That was confusing, and it would work against me as I
make it possible for a network interface to overload most ioctls.
On the protocol->ifnet interface, replace SIOCSIFADDR with
SIOCINITIFADDR. In ifioctl(), return EPERM if userland tries to
invoke SIOCINITIFADDR.

In ifioctl(), give the interface the first shot at handling most
interface ioctls, and give the protocol the second shot, instead
of the other way around. Finally, let compatibility code (COMPAT_OSOCK)
take a shot.

Pull device initialization out of switch statements under
SIOCINITIFADDR. For example, pull ..._init() out of any switch
statement that looks like this:

switch (...->sa_family) {
case ...:
..._init();
...
break;
...
default:
..._init();
...
break;
}

Rewrite many if-else clauses that handle all permutations of IFF_UP
and IFF_RUNNING to use a switch statement,

switch (x & (IFF_UP|IFF_RUNNING)) {
case 0:
...
break;
case IFF_RUNNING:
...
break;
case IFF_UP:
...
break;
case IFF_UP|IFF_RUNNING:
...
break;
}

unifdef lots of code containing #ifdef FreeBSD, #ifdef NetBSD, and
#ifdef SIOCSIFMTU, especially in fwip(4) and in ndis(4).

In ipw(4), remove an if_set_sadl() call that is out of place.

In nfe(4), reuse the jumbo MTU logic in ether_ioctl().

Let ethernets register a callback for setting h/w state such as
promiscuous mode and the multicast filter in accord with a change
in the if_flags: ether_set_ifflags_cb() registers a callback that
returns ENETRESET if the caller should reset the ethernet by calling
if_init(), 0 on success, != 0 on failure. Pull common code from
ex(4), gem(4), nfe(4), sip(4), tlp(4), vge(4) into ether_ioctl(),
and register if_flags callbacks for those drivers.

Return ENOTTY instead of EINVAL for inappropriate ioctls. In
zyd(4), use ENXIO instead of ENOTTY to indicate that the device is
not any longer attached.

Add to if_set_sadl() a boolean 'factory' argument that indicates
whether a link-layer address was assigned by the factory or some
other source. In a comment, recommend using the factory address
for generating an EUI64, and update in6_get_hw_ifid() to prefer a
factory address to any other link-layer address.

Add a routing message, RTM_LLINFO_UPD, that tells protocols to
update the binding of network-layer addresses to link-layer addresses.
Implement this message in IPv4 and IPv6 by sending a gratuitous
ARP or a neighbor advertisement, respectively. Generate RTM_LLINFO_UPD
messages on a change of an interface's link-layer address.

In ether_ioctl(), do not let SIOCALIFADDR set a link-layer address
that is broadcast/multicast or equal to 00:00:00:00:00:00.

Make ether_ioctl() call ifioctl_common() to handle ioctls that it
does not understand.

In gif(4), initialize if_softc and use it, instead of assuming that
the gif_softc and ifp overlap.

Let ifioctl_common() handle SIOCGIFADDR.

Sprinkle rtcache_invariants(), which checks on DIAGNOSTIC kernels
that certain invariants on a struct route are satisfied.

In agr(4), rewrite agr_ioctl_filter() to be a bit more explicit
about the ioctls that we do not allow on an agr(4) member interface.

bzero -> memset. Delete unnecessary casts to void *. Use
sockaddr_in_init() and sockaddr_in6_init(). Compare pointers with
NULL instead of "testing truth". Replace some instances of (type
*)0 with NULL. Change some K&R prototypes to ANSI C, and join
lines.
 1.226 28-Apr-2008  martin branches: 1.226.6; 1.226.8;
Remove clause 3 and 4 from TNF licenses
 1.225 08-Apr-2008  cegger branches: 1.225.2; 1.225.4;
use aprint_*_dev and device_xname
 1.224 20-Dec-2007  dyoung branches: 1.224.6;
Constify struct ifnet->if_sadl and every use throughout the tree.
Add if_set_sadl() that both sets the link-layer address length and
replaces the current link-layer address with a new one, and use it
throughout the tree.
 1.223 09-Dec-2007  jmcneill branches: 1.223.2;
Merge jmcneill-pm branch.
 1.222 19-Oct-2007  ad branches: 1.222.4; 1.222.6;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.221 01-Sep-2007  dyoung branches: 1.221.4;
Change a bazillion occurrences of code resembling this,

error = (cmd == SIOCADDMULTI) ?
ether_addmulti(ifr, &sc->sc_ec) :
ether_delmulti(ifr, &sc->sc_ec);

if (error == ENETRESET) {

to this,

if ((error = ether_ioctl(ifp, cmd, data)) == ENETRESET) {

which does the same thing.

(A bazillion is a very large number. This seems to make the i386
ALL kernel smaller by 3kB to 4kB.)

Use ifreq_getaddr() twice in es(4).

Whitespace nits.
 1.220 09-Jul-2007  ad branches: 1.220.2; 1.220.6; 1.220.8;
Merge some of the less invasive changes from the vmlocking branch:

- kthread, callout, devsw API changes
- select()/poll() improvements
- miscellaneous MT safety improvements
 1.219 04-Mar-2007  christos branches: 1.219.2; 1.219.4;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.218 04-Jan-2007  elad branches: 1.218.2;
Consistent usage of KAUTH_GENERIC_ISSUSER.
 1.217 16-Nov-2006  christos __unused removal on arguments; approved by core.
 1.216 12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.215 21-Jul-2006  ad branches: 1.215.4; 1.215.6;
- Use the LWP cached credentials where sane.
- Minor cosmetic changes.
 1.214 14-May-2006  elad integrate kauth.
 1.213 12-Mar-2006  dyoung branches: 1.213.2;
Note in radiotap header file and manual page that radiotap fields
are little-endian. Fix wi(4) and atw(4) to reflect this fact.
 1.212 20-Feb-2006  thorpej branches: 1.212.2; 1.212.4;
Use device_is_active() rather than testing dv_flags for DVF_ACTIVE
directly.
 1.211 24-Dec-2005  perry branches: 1.211.2; 1.211.4; 1.211.6;
Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.210 18-Nov-2005  skrll Adapt drivers to the new net80211(9).

Most of this is from dyoung@. Thanks!
 1.209 10-Aug-2005  christos branches: 1.209.6;
Allow setting the MAC address via wiconfig -m (Lord Isildur)
 1.208 23-Jul-2005  drochner disable SYSCTL_SETUP for _LKM until we have a plan how to deal with
it correctly
 1.207 16-Jul-2005  yamt #ifdef out an unused variable in the case of !WI_DEBUG.
 1.206 15-Jul-2005  dyoung Add a sysctl for turning wi(4) debugging on and off.

Do not print the number of tx commands outstanding on entrance to
wi_cmd_intr unless wi_debug > 1.
 1.205 14-Jul-2005  dyoung Clear IEEE80211_F_DROPUNENC in ic_flags in operating states where
the NIC decryptes & decapsulates WEP frames before passing them to
the host. "Remember" the state of IEEE80211_F_DROPUNENC in
sc_ic_flags, though, and try our best to honor it as we setup the
hardware state.

This is the second patch of this kind. The previous patch was
badly broken because wi_mend_flags was basing its decision to clear
IEEE80211_F_DROPUNENC based on the operating state we were
transitioning FROM instead of the state we were transitioning TO.

This fixes a bug that Simon Burge reported, where dhclient wi0
would not get a lease unless and until you ran 'ifconfig wi0'
concurrently (which would frob the IEEE80211_F_DROPUNENC bit in
the right way). This patch was tested by Simon with his Toshiba
Lucent-clone.
 1.204 06-Jul-2005  dyoung Historically, an(4), ath(4), atw(4), rtw(4), and wi(4) have printed
out their modes and rates at boot. Revert to the historical
behavior.
 1.203 06-Jul-2005  dyoung Avoid an unnecessary API difference between NetBSD and FreeBSD:
back out my change to ieee80211_crypto_encap that made it free its
mbuf argument on error. I had thought it was a bug. It was not.
It's the drivers that are broken. Make an(4), atw(4), ipw(4),
iwi(4), ral(4), rtw(4), ural(4), and wi(4) free the mbuf when
ieee80211_crypto_encap returns NULL. Also, return ath(4) to the
way it was---i.e., free the mbuf.

Thanks to Sam Leffler to pointing out my mistake.
 1.202 06-Jul-2005  dyoung branches: 1.202.2;
Don't write the WEP keys to the device if it is invalid (e.g.,
unplugged) or if it is not enabled. Fixes kern/30592.
 1.201 26-Jun-2005  erh Make sure there is a valid transmit key, before trying to use information
about it. Fixes a crash when configuring wi0.
 1.200 26-Jun-2005  dyoung Do not build AP support if 'options IEEE80211_NO_HOSTAP' is in the
kernel configuration.
 1.199 25-Jun-2005  dyoung Bug fix: fix WEP by managing keys & crypto in the style of the new
net80211. It was especially important to zero the IEEE80211_F_DROPUNENC
(discard unencrypted packets) flag in operating modes where the
firmware decrypts for us. Otherwise, the 802.11 layer discarded
all received frames. See wi_mend_flags. From FreeBSD, with
improvements by me.

For better compliance with the "net80211 way":
set sc_cnfauthmode from ic->ic_bss->ni_authmode. Enter
the RUN state through ieee80211_create_ibss instead of
ieee80211_new_state(IEEE80211_S_RUN). To sync BSSID in ad hoc
mode, use ieee80211_sta_join() instead of
ieee80211_new_state(IEEE80211_S_RUN). From FreeBSD.

Configure the firmware to obey IEEE80211_F_DROPUNENC.

As we change to state RUN in STA mode, generate a link-status
message on the routing socket with a call to ieee80211_notify_node_join()
instead of calling rt_ifmsg directly.

Run normal net80211 processing (ieee80211_newstate) on the ->RUN
transition.
 1.198 22-Jun-2005  dyoung Resolve conflicts in importation of 18-May-2005 ath(4) / net80211(9)
from FreeBSD. Introduce compatibility shims (sys/dev/ic/ath_netbsd.[ch],
sys/net80211/ieee80211_netbsd.[ch]). Update drivers (an, atu, atw,
awi, ipw, iwi, rtw, wi) for the new net80211(9) API.
 1.197 27-Mar-2005  dyoung correct logic so we recognize timeout on alloc

Noticed by: Coverity Prevent analysis tool

From FreeBSD. Thanks Sam Leffler for bringing this to my attention.
 1.196 27-Feb-2005  perry nuke trailing whitespace
 1.195 13-Feb-2005  dyoung Bug fix: use the MAC that the firmware tells us, resorting to the
CIS MAC only on error.

(NetBSD these days tries to read the MAC address from the PCMCIA
CIS. Prism cards made by Senao set the MAC in every PCMCIA CIS to
00:02:6f:00:02:15. In a network of Senao cards, this causes MAC
duplication.)
 1.194 17-Jan-2005  dyoung branches: 1.194.2;
Delete an out-of-date comment.
 1.193 14-Dec-2004  dyoung branches: 1.193.2;
In wi_stop, wait for transmit commands to complete. Extract
subroutine wi_txcmd_wait from wi_cmd and wi_stop.

This stops wi from griping, "wi0: command timed out, cmd=0x10b,
arg=0x0", when we down/up the interface. Thanks to Pavel Cahyna
for reporting this bug.
 1.192 13-Dec-2004  dyoung Bug fix: synchronize Transmit commands with all other commands.

Following Charles Hannum's wi(4) optimizations, there could be a
Transmit command outstanding after wi_tx_intr or wi_start returns.
The driver would blithely issue a second command [*] before the
first command was finished, taking the first command's WI_EV_CMD
indication to mean the second command had finished. The driver
would be dreadfully confused when the second command's results did
not meet its expectations (e.g., a RID mismatch error would occur).
The packet transmit section of the code would never read the
WI_EV_CMD it expected, so transmissions would cease.

This patch counts the outstanding transmit commands (there can be
only one) and, if a transmit command is outstanding at the top of
wi_cmd(), wi_cmd waits for the command to complete. If there was
a transmit command outstanding when wi_cmd begins, it calls
wi_cmd_intr() on its way out.

I have tested this on an Orinoco card. Previously, the card would
stop transmitting or the kernel would panic as desynchronization
occurred. Now it works beautifully.

[*] A second command could be issued by wi_ioctl or else by
wi_intr->wi_info_intr->wi_newstate->wi_read_xrid->wi_read_rid.
 1.191 13-Dec-2004  dyoung In wi_tx_intr, be a little more explicit about which fields we're
reading from the Tx-Complete FID.
 1.190 13-Dec-2004  dyoung Refactor. wi_read_rid calls,

wi_read_rid(sc, rid, &val, &buflen) == 0 && buflen == sizeof(val),

become wi_read_xrid calls

wi_read_xrid(sc, rid, &val, sizeof(val)) == 0.

If the actual RID length is different from the expected RID length,
wi_read_rid prints to the log.
 1.189 26-Nov-2004  mycroft Fix what appears to be a byte order error on big-endian systems with Symbol
cards.
 1.188 30-Oct-2004  thorpej When adding/deleting multicast addresses, only whack the address
filter if the interface is marked RUNNING.

Fixes kern/27678.
 1.187 28-Sep-2004  dyoung Simplify the BSSID synchronization code.
 1.186 10-Aug-2004  dyoung Make the node table into an LRU cache: least-recently used nodes
are at the end of the node queue. Change the reference-counting
discipline: ni->ni_refcnt indicates how many times net80211 has
granted ni to the driver. Every node in the table with ni_refcnt=0
is eligible to be garbage-collected. The mere presence of a node
in the table does not any longer indicate its auth/assoc state;
nodes have a ni_state variable, now. A sysctl,
net.link.ieee80211.maxnodecache, controls the maximum LRU cache
size.

While I am here, patch ieee80211_find_node_for_beacon to do a "best
match" by bssid/ssid/channel, not a "perfect match." This keeps
net80211 from caching duplicate nodes in the table.
 1.185 07-Aug-2004  mycroft Be much more robust with RID values during attach:
* If the device returns a length too short to even contain the RID number,
flag it as not supported and return EOPNOTSUPP, rather than returning a
length of -2 and trying to use the value anyway.
* Check the returned lengths to see if we actually got anything.
* If we get no rate list, fail the attach, so we don't just blow up later.
Allow the frontend to pass in a MAC address.
 1.184 06-Aug-2004  mycroft Use bpf_mtap2().
 1.183 05-Aug-2004  mycroft Put unadulterated dB values in the radiotap header, not the converted dBm
values.
 1.182 23-Jul-2004  mycroft IEEE80211_F_WEPON -> IEEE80211_F_PRIVACY
 1.181 22-Jul-2004  mycroft Add sc_txstart and sc_txstarted, to keep track of the current FID we want to
start and the number we've started that have not been alloced yet. Currently
sc_txstarted is constained to 0 or 1 because of the way we start the next
packet, but this will change.
 1.180 22-Jul-2004  mycroft Copyright maintenance.
 1.179 22-Jul-2004  mycroft Change some DELAY(2) to more sensible values.
 1.178 22-Jul-2004  mycroft Add some histogram code (controlled by an #ifdef) to track how long various
busy-wait loops take.
 1.177 22-Jul-2004  mycroft Keep a count of packets written to the chip but not yet initiated. This
simplifies some logic, and is needed for later changes.
 1.176 22-Jul-2004  mycroft Change some names.
sc_txnext -> sc_txalloc
sc_txcur -> sc_txqueue
 1.175 22-Jul-2004  mycroft Keep a count of FIDs allocated, rather than storing a packet length in the
ring.
 1.174 22-Jul-2004  mycroft Make the radiotap header reflect the actual transmit rate.
 1.173 22-Jul-2004  mycroft Ack events in only one place. Reduces register writes sometimes.
 1.172 22-Jul-2004  mycroft Only read the part of the frame header we use in wi_tx_intr().
 1.171 22-Jul-2004  mycroft Rework the rate-lowering hack:
* Update sc_txpending[] when a packet is written, even before we issue the TX
command, since it may be active when we issue the TX command for the
following packet.
* Do not lower the rate in ni_txrate or id_rateidx, because these are used to
keep track of sc_txpending[], and could cause us to get "stuck" at the lower
rate.
 1.170 22-Jul-2004  mycroft Make the logic in wi_write_txrate() less obscure.
 1.169 22-Jul-2004  mycroft For Intersil firmware, use the ROM rate list to determine the correct bitmask
for BASIC_RATE and SUPPORT_RATE. Always set these, because otherwise probe
frames will not get the correct list.
 1.168 22-Jul-2004  mycroft Missed one change in the previous. Now we really don't try to write it.
 1.167 22-Jul-2004  mycroft Symbol firmware doesn't support the power management register, so don't try to
do power management there.
 1.166 22-Jul-2004  mycroft Whoops, change one back to regular "static" for an inline function.
 1.165 22-Jul-2004  mycroft I hate "static". Add an #ifdef so I can turn it off easily.
 1.164 02-Jul-2004  dyoung Indicate link status changes on the routing socket.
 1.163 02-Jul-2004  dyoung Cosmetic: shift a break-statement into the right column.
 1.162 02-Jul-2004  dyoung wi_start compaction: check for software descriptor exhaustion in
one place. Check for the _RUN state in one place.
 1.161 06-Jun-2004  dyoung Finally, refactor wi_media_change and ieee80211_media_change.
ieee80211_media_change handles a lot more conditions than
wi_media_change did.

This helps with the second bug mentioned in kern/25604, which causes
"SIOCSIFMEDIA: Invalid argument."
 1.160 31-May-2004  dyoung Don't set a frame's WEP bits, the 802.11 layer already has.
 1.159 26-Mar-2004  dyoung branches: 1.159.2;
Actually, disabling RSS rate-adaptation does not make any discernible
difference in locking up STA f/w 8.42.1.
 1.158 26-Mar-2004  dyoung Firmware revisions are decimal.
 1.157 25-Mar-2004  dyoung Enable Tx and TxExc interrupts. Somehow this escaped my initial
commit. The rate adaptation code expects them. Usually wi gets
lucky, and an Rx/Alloc/Info event triggers the interrupt handler,
but I had not intended for wi to count on it.

Without Tx/TxExc interrupts enabled, wi will sometimes exhaust all
its rssdescs and cease transmitting. Usually it sets IFF_OACTIVE
in that situation.
 1.156 17-Mar-2004  dyoung Prevent a buffer overflow that's been seen in the wild. The firmware
will sometimes return 0; subtracting 1 from that yields a too-big
buffer length.
 1.155 17-Mar-2004  dyoung In wi(4), wi_choose_rate used to contain device-independent code.
I have pulled that code into the function ieee80211_rssadapt_choose
so that I can re-use it in ath(4), atw(4), and in other drivers.

In rssadapt(9), I have also created a struct ieee80211_rssadapt_expavgctl
that contains parameters for rate adaptation. When IEEE80211_RSSADAPT_DEBUG
is enabled, I will using sysctl to expose an ieee80211_rssadapt_expavgctl
for each wireless device.

Also in rssadapt(9), I have introduced an interpolate() macro which
makes the exponential-averaging code more compact.
 1.154 10-Feb-2004  dyoung If the firmware returns to us an RSS descriptor index that is out
of bounds, then complain and recover by freeing all of the descriptors.
That will usually provoke additional complaints---see the next
paragraph.

If the firmware returns to us an RSS descriptor that is in-bounds
but out of service (id_node == NULL), then gripe and get out of
the interrupt handler. ***This will still leak RSS descriptors.***
I'm working on a better solution. Possibly I will just free all of
the descriptors.
 1.153 10-Feb-2004  dyoung Disable rate-adaptation for Lucent firmware version 8.42.1, per a
bug report from Simon Burge: the firmware seems to lock up.

If rate-adaptation is disabled on a Lucent card, then do all the
rate-adaptation work *except* for writing the new transmit rate,
since I suspect that is what locks-up the firmware.
 1.152 10-Feb-2004  dyoung Shorten the retry count on Prism APs to improve the speed of
rate-adaptation.
 1.151 10-Feb-2004  dyoung Factor out the initialization/reset of RSS descriptors, making
wi_rssdescs_init, wi_rssdescs_reset, which I will use to receover
when the firmware botches up the RSS descriptor index.
 1.150 10-Feb-2004  dyoung The radiotap header is little-endian.
 1.149 31-Jan-2004  dyoung wi_stop tells which stations' rssadapt descriptors it cleans up
when IFF_DEBUG is set.
 1.148 07-Dec-2003  dyoung Enable RSSI-based rate-adaptation for wi(4). This enables wi(4)-based
APs to run at "full speed" where before they ran at just 1 or 2Mb/s.
The AP will adapt the data rate for each client based on packet
losses and the received signal strength.

I have also enabled rate adaptation for STA mode and for IBSS mode,
but the hardware gives us less control over the data rate in those
modes.
 1.147 04-Dec-2003  keihan netbsd.org -> NetBSD.org

This was the last commit of this kind to src/sys, which is now totally
"NetBSD.org clean". Thanks for the patiance, and sorry for all the commits.
 1.146 16-Nov-2003  dyoung From Steve Woodford (scw@): fix wi(4) and wiconfig(8) on big-endian
machines.
 1.145 16-Nov-2003  dyoung Fix spelling/grammar in a comment.
 1.144 16-Nov-2003  dyoung Add data-link type DLT_IEEE802_11_RADIO to wi and atw. DLT_IEEE802_11_RADIO
lets you monitor radio stats like received signal strength, which
diversity antenna was used, channel/frequency, modulation, and data
rate.
 1.143 02-Nov-2003  dyoung Use ieee80211_find_rxnode to attribute Rx packets to the write
ieee80211_node. This reduces code duplication. It will help us
support passive scanning and rate adaptation.
 1.142 02-Nov-2003  dyoung Mark the available channels using the ic_channels table instead of
setting bits in ic_chan_avail, which is the responsibility of
ieee80211_ifattach. I cannot believe the previous code worked.
 1.141 02-Nov-2003  dyoung Get the ieee80211_node for management packets from the rcvif field.
 1.140 02-Nov-2003  dyoung Fix bugs in power-saving:

Use a power-saving station's ieee80211_node, which is stored in
the rcvif field.

Do not free a node if it is put onto the power-saving queue.
 1.139 01-Nov-2003  dyoung Bug fix: in wi_cfg_txrate, do not divide the 802.11 rate by 2 and
take off the flags before giving it to wi_write_txrate.

Also add a useful debug message to wi_write_txrate.
 1.138 24-Oct-2003  mycroft In wi_newstate(), read the BSSID into a temporary buffer that has guaranteed
alignment. Fixes a really obscure failure mode on Alpha, and panics on other
machines.
 1.137 19-Oct-2003  dyoung Don't take the 802.11 header off of a frame until after we've given
it to the driver's BPF tap.
 1.136 17-Oct-2003  dyoung ieee80211_newstate() wants for ic->ic_state to equal the previous
state, so do not update ic->ic_state in wi_newstate() before calling
ieee80211_newstate(). Instead, update ic->ic_state when we do not
let ieee80211_newstate() run.
 1.135 16-Oct-2003  dyoung Prepare for wi rate adaptation. Add wi_write_txrate, which only
writes a hardware register when the data rate selection actually
changes. Add wi_cfg_txrate, which writes the data rate selection
regardless.

Name some fields in the wi Tx buffer which we will use for rate
adaptation.

Name the Prism "Alternate Retry Count" RID, WI_RID_ALT_RETRY_COUNT.
 1.134 16-Oct-2003  dyoung The upper & lower bounds on wi RSSI are completely bogus, AFAICT.
 1.133 13-Oct-2003  dyoung Switch wi(4) to the new 802.11 layer.
 1.132 06-Jul-2003  dyoung Still more consolidation of 802.11 media-handling, moving moving
common code from awi and wi into the 802.11 framework. Inspired by
Sam Leffler's patches to FreeBSD.
 1.131 06-Jul-2003  dyoung Improved RSSI->dBm conversion, especially for Lucent cards, for
which I borrowed some conversion constants from the Linux orinoco_cs
driver.
 1.130 19-Jun-2003  rh branches: 1.130.2;
Add and enable monitoring mode for Lucent cards.
 1.129 31-May-2003  dyoung Picky cosmetic change: remove leading space.
 1.128 22-May-2003  dyoung Update to wi interrupt handling:

No longer require a hi-low-hi transition of a status bit before
we believe it. It's a performance killer, and without it there
does not seem to be a race.

Sam Leffler reports that wi_intr needs to be bracketed by
disable/enable interrupts through WI_INT_EN, or else performance
is bad on Lucent. So now we do that.
 1.127 20-May-2003  dyoung Stop wi panics on card ejection in Powerbook in both the enabled
and disabled states. This should fix an x86 panic somebody reported
on icb.
 1.126 17-May-2003  christos Initialize and reset curtxeps to zero each time the error rate is exceeded.
This stops the continuous spewing of error messages, making it just sporadic.
 1.125 16-May-2003  dyoung IEEE80211_LOCK and WI_LOCK conceal enormous differences in locking
semantics on FreeBSD and NetBSD, so I am backing them out until
the macro set is enriched.
 1.124 13-May-2003  dyoung Revert to previous multicast logic, which enami@sm.sony.co.jp says
was correct.
 1.123 13-May-2003  dyoung Begin synchronization with FreeBSD:

1 Add channel mask, transmit rate-mask arguments to wi_scan_ap.
2 Adopt the macros WI_LOCK/WI_UNLOCK for synchronization. FreeBSD
uses a different synchronization mechanism.
3 In wi_cmd, adopt constants WI_DELAY/WI_TIMEOUT for timing.
4 Pull debug messages from into wi_read_nicid from FreeBSD.
5 Bug fix: if IFF_ALLMULTI, don't filter any multicasts.
6 Count and report TX exceptions, but don't generate any additional
interrupts.
 1.122 13-May-2003  dyoung For converge with FreeBSD:
 1.121 13-May-2003  dyoung Track TX exceptions. This will eventually enable round-robin retries
(for fairness) and RTM_LOSING or some such other message to indicate
a losing wireless destination.

From FreeBSD.
 1.120 13-May-2003  dyoung Complete prior patch: dump packets in wi_rx_intr, too.
 1.119 13-May-2003  dyoung Debug code from FreeBSD: handy packet dumps when IFF_DEBUG|IFF_LINK2
are set.
 1.118 13-May-2003  dyoung Misc changes to wi_stop. First, block interrupts in wi_stop. (From
FreeBSD.)

Fix a bug in wi_stop where ejecting from the Powerbook crashes the
system. Essentially, the patch makes sure we write *no* registers
when we are no longer attached.

Also, for consistency w/ FreeBSD, use sc_portnum throughout wi,
instead of hard-coding WI_PORT0 .
 1.117 13-May-2003  dyoung For uniformity between FreeBSD & NetBSD, adopt FreeBSD's more
concise wi_cmd.
 1.116 08-Apr-2003  kml Host AP power saving support. The Host AP notices that the power
saving bit is set in incoming frames from a station, and buffers the
outgoing frames for the station until they are polled for. This
requires support in the driver to set a bit in the TIM bitmap sent
during 802.11 beacons.

So far, support for power saving in Host AP mode is only available
for the PRISM2 chipset.
 1.115 27-Mar-2003  dyoung 802.11 MLME-JOIN.request is an abstract MAC function that is not
necessarily exposed to the host, so Lucent/Agere/whatever is correct
in not supporting it.
 1.114 27-Mar-2003  dyoung HostAP broke in version 1.4.2 of station firmware. Try 1.3.x, 1.4.9,
or later.
 1.113 27-Mar-2003  dyoung Introduced sc_reset to wi_softc. The bus-specific front-end gets
to fill this.
 1.112 25-Feb-2003  dyoung Add support for Prism monitor mode. From Kevin Lahey
<kml@patheticgeek.net>.

This patch does NOT add monitor mode support for the Lucent radios.

awi(4) was only modified for compatibility with the new mediaopt.
It does NOT support monitor mode.

Tested by Kevin, Daniel Carosone, and I.
 1.111 25-Feb-2003  dyoung Disable interrupts before ACKing them to avoid the obvious race.
 1.110 25-Feb-2003  dyoung Following implementation for other RIDs, read the driver's notion
of the fragmentation threshold instead of the hardware's notion.
 1.109 09-Jan-2003  dyoung Oops. This turns off debugging again.
 1.108 09-Jan-2003  dyoung wi_start: write an mbuf chain to the driver using wi_mwrite_bap,
which is safer than the loop there used to be here.

wi_mwrite_bap: if wi_write_bap fails, don't keep on going: this
way you avoid writing garbage to the radio. First time you see
an odd-length mbuf, copy the remainder of the chain to sc_txbuf
and from there to the MAC. This way, you do not read an mbuf past
the end of its data (occasionally you will cross a page doing
that!) and you avoid expensive, excess seeks in the radio's own
buffer chain.

wi_rx_intr: clamp the frame length told to us by the driver to the
most bytes we can fit in our mbuf cluster.

I am still getting e-mails from my testers telling me how much
better this makes things.
 1.107 01-Jan-2003  dyoung A Prism firmware participating in an IBSS network will not send a
LINK_STAT notification for every change of BSSID, so the firmware's
BSSID and the driver's BSSID will get out of sync. This has two
bad affects. First, because the 802.11 framework filters received
packets based on BSSID, many packets can be dropped before the
driver adopts the firmware's BSSID. Second, ifconfig's tells a
misleading BSSID to the operator.

This problem is most apparent in networks where every station does
not hear every other. I reproduce these conditions in an office by
removing/replacing the antennas on my 802.11 cards.

As a solution, in IBSS mode, the driver will ask the firmware for
the BSSID every five seconds. Also, whenever the driver receives
a frame carrying a different BSSID than the driver's BSSID, then
the driver asks the firmware for the BSSID before handing the frame
to ieee80211_input.
 1.106 27-Dec-2002  dyoung On Lucent cards, indicate that changing BSSID with SIOCS80211BSSID
is impossible. Never write to the Prism-only JOIN RID.
 1.105 27-Dec-2002  dyoung The RID for the RSSI->dBm adjustment is not supported by Prism
station firmware version <= 1.1.1.
 1.104 18-Nov-2002  dyoung Only Prism is known to support WI_RID_FRAG_THRESH.
 1.103 16-Nov-2002  dyoung In wi_get_cfg, factor the code for getting the tx rate with the
IEEE 802.11 subsystem.

In wi_write_txrate, document the clever code for computing
WI_RID_TX_RATE from a bit rate.
 1.102 16-Nov-2002  dyoung Support two new RIDs.

WI_RID_DBM_ADJUST: In preparation for capturing Prism packets
containing received signal strength indications (RSSI), read the
constant for conversion from RSSI to dBm (decibels relative to
a milliwatt).

WI_RID_FRAG_THRESH: Get/set the packet fragmentation threshold
on Lucent/Prism.
 1.101 25-Oct-2002  mycroft IBSS mode does in fact work on some earlier Symbol firmware versions, as
witnessed by my home network.
 1.100 15-Oct-2002  onoe Fix to use 104bit key for Intersil/Symbol firmware:
It seems that the firmware accept 104bit key only if
all the keys have 104bit length. We get the length of
the transmit key and use it for all other keys.
Perhaps we should use software WEP for such situation.
 1.99 07-Oct-2002  onoe Update BSSID at every CONNECTED LINK_STAT notification in IBSS mode,
since it can be updated by IBSS merge. Also the lucent firmware 8.10.1
changes random generated bssid every 10 seconds in IBSS creation enable.
PR 18520
 1.98 04-Oct-2002  onoe Handle of AP_IN_RANGE/AP_OUT_RANGE, to fix a problem once the station
is out of ragen, it never comes up again.
For HostAP, prohibit sending DATA frame to an unassociated but authenticated
station.
 1.97 03-Oct-2002  onoe Set IEEE80211_F_IBSSON before test in wi_init() to set CREATE_IBSS
correctly for Lucent firmware to work with IBSS mode.
PR 18520
 1.96 02-Oct-2002  onoe Fix NIC-memory leak for symbol firmware at reinitialization. After 4-5
times changing of 802.11 parameters, such as nwid, the error
"tx buffer allocation failed" occured unless ifconfig down up.

Pass signal streangth and timestamp to ieee80211_input, though it is not
useful for wi driver for now.
 1.95 01-Oct-2002  onoe Do not call wi_stop() with disabled flag set from wi_init(), since it
sometimes call within interrupt and deleting handler causes panic.
Fix to display current tx rate as media.
Clear trailer bytes in ssid fields.
 1.94 01-Oct-2002  onoe Linkstatus AP_IN_RANGE doesn't mean associatted, rather it just mean trying
to associate.
 1.93 01-Oct-2002  onoe Allow SIOCSIFADDR with AF_LINK and WI_RID_MAC_NODE (wiconfig -m)
to set MAC address.
 1.92 01-Oct-2002  onoe initialize sc_txcur and sc_txnext at wi_init to avoid reordering after
reinitialized.
 1.91 30-Sep-2002  onoe old lucent adhoc-demo mode (adhoc,flag0 or wiconfig -p 3) wasn't handled
correctly. To avoid massive extra code in each driver, now if_iee80211subr.c
also handles non-standard old lucent adhoc-demo mode.
This also fixes PR 14227.
 1.90 30-Sep-2002  onoe Jumbo commit for wi driver.
- Eliminate wi_hostap.c since most of the code are duplicated with
net/if_ieee80211subr.c
- Station for Infrastructure network and IBSS also use service functions
as much as possible to be consistent with other wireless drivers.
Now WEP works for station/ibss/hostap.
 1.89 30-Sep-2002  onoe Nuke unneeded member sc_ifp and use #define sc_if instead,
to prepare jumbo commit for wi.c
 1.88 27-Sep-2002  thorpej Increase the timeout in wi_cmd(). Fixes reports of "busy didn't
clear". From David Young <dyoung@ojctech.com>.
 1.87 26-Sep-2002  martin If we wi_stop the card in wi_shutdown, better do that before the frontend
removes power from the pcmcia slot (inside the sc_disable hook).
 1.86 26-Sep-2002  martin Set error = 0 (instead of EINVAL) when it is later tested against != 0.
This allows using wiconfig while the interface is not (yet) marked IFF_UP
again.
 1.85 26-Sep-2002  martin In wi_shutdown only call wi_stop if sc_enabled is set (don't try to send
commands to a card that is not powered up - it will always fail)
 1.84 23-Sep-2002  thorpej Jumbo patch, from David Young <dyoung@ojctech.com>, with small tweaks
by me:
* Speed up reading/writing buffers from the hardware by avoiding
slow forward seeks. In preparation to use the optimization, do
not read overlapping bytes. This is currently disabled, but can
be enabled with OPTIMIZE_RW_DATA.
* Hand 802.11 and Prism-specific frames to BPF. User can watch these
frames by specifying an alternate DLT to e.g. tcpdump(8).
* Add support for SIOC[SG]80211BSSID and SIOC[SG]80211CHANNEL.
* Issue join requests and track join/create state through link-status
notifications.
* Split wi_rxeof into separate routines for receiving Ethernet II,
802.11 data, and 802.11 management frames.
* Bug fix: Account for aligning m_data to a word boundary in the Rx
buffer size check.
* Bug fix: Check for LLC/SNAP even if the firmware tells us the frame
is Ethernet II, as the firmware sometimes gets this wrong.
* Process as many events as possible when we get an interrupt, using
a simple heuristic to avoid reprocessing an event (which can have
bad side-effects). Clamp the time spent in the interrupt handler
to 4ms.
* Redo the timeout loops to be consistent and less prone to error.
* Add delays to timeout loops which were missing them, so that a
fast CPU won't win the race.
* Borrow some timeout loop values from the linux-wlan-ng driver,
which seems to reflect a high level of clue (due to direct support
from Intersil).
* Get rid of silly wi_read_data(..., len + 2) idiom; simply round up
in wi_read_data() and wi_write_data(). Also, protect against a
length of 0.
* Name some frequently-used constants. Correct spelling. Other style nits.
* Bug fix: On Prism, set Create IBSS register to 0 *always*. The meaning
of Create IBSS == 1 is join an IBSS or *ESS*, and we do not want to
join an ESS, because that would put us in an inconsistent state. 0
is the right value for Prism.
* Bug fix: Clean up state at the top of wi_init(), in the event that
we don't reach the bottom.
* Simplify wi_start() by always providing an RFC1042-encoded 802.11
frame to the firmware.
* Larval powersave support for HostAP mode, enabled by WI_HOSTAP_POWERSAVE.
* Bug fix: Call wi_stop() from wi_shutdown().
* Bug fix: sync media options with HostAP mode in wi_sync_media().
* In wi_media_status(), inquire firmware for current media state if
media == auto. From FreeBSD.
* Clean up the way buffer lengths are computed by using pointer
arithmetic rather than magic constants.
* Swap the order of comparisons in addr_cmp() for speed.
* Bug fix: Send ReAssoc Response instead of Assoc Response to a
ReAssoc Request.
* Bug fix: Copy SSID using the correct size.
* Give more meaningful names to offsets in a wi_frame.
* Bug fix: Assign the right values to the named constants for
Rx frame encoding.
* Get rid of useless SNAP constants.
 1.83 21-Aug-2002  onoe Make the meaning of media options consistent with other wireless drivers.
mediaopt adhoc 802.11 adhoc (IBSS) mode. IBSS creation is enabled
for cards which can create IBSS.
mediaopt adhoc,flag0 old lucent adhoc demo mode.
Note that [adhoc] media options for wi driver was used for adhoc demo mode,
which is NOW CHANGED.
 1.82 12-Aug-2002  thorpej wi_keylen is kept in little-endian order, so le16toh() it before
using it in e.g. a memcpy() call.
 1.81 11-Aug-2002  thorpej Pass all 3 parameters to wi_cmd().
 1.80 11-Aug-2002  thorpej * Fix a Lucent <-> Prism2 WEP interop bug. We only want to set the
EXCLUDE_UNENCRYPTED bit in the WI_RID_P2_ENCRYPTION value if we are
in shared key mode. Symbol cards, just to be different, supposedly
always want the EXCLUDE_UNENCRYPTED bit set (confirmed with the
Linux orinoco and spectrum24 drivers).

* Flesh out the Host-AP WEP transmit side. Note this does not yet
work properly; the frame as seen by the receiver FCS's incorrectly.

Both changes from OpenBSD. Not confirmed whether or not Host-AP WEP
works with OpenBSD (mail sent to millert).
 1.79 11-Aug-2002  thorpej Snapshot of work-in-progress: Add AP support for Prism2-based boards.
WEP for APs is not yet implemented, but without WEP, this works well
enough for my laptop to associate with an AP running this code.

Adapted from OpenBSD.
 1.78 11-Aug-2002  thorpej Use WI_RID_DATA_RATES to fetch the supported rates. From OpenBSD.
 1.77 11-Aug-2002  thorpej * Add "wi_flags" to the softc to indicate capabilities of the card. Fill
in this info based on firmware type and version. Replace "wi_has_wep"
with a flag.
* For cards which support IBSS, add "ibss" has a media option.
* For cards which support CREATE_IBSS, add "ibss-master" as a media
option.
* Use the "ibss" and "ibss-master" media options to determine if
we should go into IBSS mode and/or create the IBSS.
* Internally convert between the generic WI_PORTTYPE_IBSS and the
value the firmware wants to use for IBSS.
* When setting the IBSS name, if a desired-SSID is set, and we're
an ibss-master, write the desired-SSID into the own-SSID slot.
This ensures that "ifconfig wi0 nwid FOO" will do the expected
thing.
* Only set the roaming mode if the card supports roaming.

From OpenBSD.
 1.76 11-Aug-2002  thorpej Only read supported rates on Prism2 boards.
 1.75 11-Aug-2002  thorpej Read supported rates from the card and report them. Only add
media types if that rate is supported.

Adapted from OpenBSD.
 1.74 10-Aug-2002  thorpej Fix some whitespace.
 1.73 31-May-2002  mycroft Mask off extraneous bits in the RX frame status when testing it. My cards set
bit 3 in ad hoc mode.
Also, some minor constant folding.
 1.72 18-Apr-2002  onoe branches: 1.72.2; 1.72.4;
(force commit: no changes in the code)
WI_RID_SCAN_APS in previous commit works for Intel Pro/Wirelss 2011
with firmware 2.51.1.
It seems that the firmware automatically updated after the card runs on
Windows 2000 with 2011_2011B_CD_3.0 in Intel web site.
 1.71 16-Apr-2002  onoe Support WI_RID_SCAN_APS (wiconfig -D) for Symbol CF Card.
It apparently requires newer firmware (3.10.4), and doesn't work on
Intel PRO/Wireless 2011 (2.0.11).
 1.70 14-Apr-2002  onoe Some fixes for Symbol card.
- The version string doesn't need to start with 'V'.
- Symbol firmware also support CREATE_IBSS.
- But it doesn't support ROAMING_MODE nor MICROWAVE_OVEN.
 1.69 11-Apr-2002  augustss Put device name at start of line.
 1.68 05-Apr-2002  ichiro Upps, fix typo
 1.67 05-Apr-2002  ichiro fix minor bugs for lucent cards. (point out from Warner Losh)
 1.66 04-Apr-2002  jdolecek move wi_pci_reset() from ic/wi.c to pci/if_wi_pci.c, where is belongs
 1.65 04-Apr-2002  jdolecek fix sligh confusion on whether or not to supply dv_xname to printf() in
error cases of attach
Noticed in kern/16197 by George E Sollish.
 1.64 04-Apr-2002  ichiro using table driven for Prism2 family IDs/Names.
 1.63 03-Apr-2002  ichiro s/WI_NIC_3842/WI_NIC_3842_EVA
 1.62 03-Apr-2002  ichiro add more IDs of PRISM family
 1.61 01-Apr-2002  ichiro add more IDs of PRISM family
 1.60 31-Mar-2002  jdolecek add some bound checking
patch submitted by IWAMOTO Toshihiro in kern/13112
 1.59 31-Mar-2002  ichiro Dont use magic number.
added parameter of WEP flags
 1.58 30-Mar-2002  ichiro added sc_pri_firmware_ver, and print Primary/Station firmware versions.
cosmetic change.
 1.57 30-Mar-2002  ichiro the kind of "firmware" was clarified.
firmware -> station firmware
 1.56 27-Mar-2002  onoe Fix to work Symbol firmware card, which cannot be initialized more than once.
Tested with 3Com 3CRWE737A and Intel Pro/Wireless 2011.
 1.55 25-Mar-2002  dbj changes from Warner Losh to read firmware version for non prism2 cards
 1.54 21-Mar-2002  itohy I have Prism2 with 0.8.2 firmware, and have no problem
using WEP without promisc on the device.
 1.53 17-Mar-2002  dbj don't set prism2 bit when WI_NIC_LUCENT is detected
 1.52 10-Mar-2002  ichiro fix 128bit WEP work with Prism2 Card.
from FreeBSD
 1.51 10-Mar-2002  augustss Add a nic I don't really know much about, but it's used on my D-Link card.
 1.50 06-Mar-2002  dbj return EINPROGRESS instead of EINVAL when trying to read
the results of an AP scan that is not finished
 1.49 04-Mar-2002  dbj Don't attempt to gather unrequested statistics.

Allow SIOCSWAVELAN with WI_RID_IFACE_STATS to request
an immediate statistics update.

We might in the future want to have SIOCGWAVELAN with
WI_RID_IFACE_STATS return an error if a statistics gathering is in
progress. Then the caller could request fresh statistics and gather
them when they are done. Instead, we currently just return whatever
statistics are available, which may be up to 60 seconds old.
 1.48 04-Mar-2002  dbj fix byte swapping when gathering statistics
this should complete the fix to pr 14385
AP scanning and statistic gathering should work on le hosts now
 1.47 04-Mar-2002  dbj correctly handle AP scanning result when there are no APs
 1.46 04-Mar-2002  dbj used %02x instead of %x when printing out BSS ids
 1.45 04-Mar-2002  dbj s/Faild/Failed/
 1.44 26-Feb-2002  dbj use #ifdef WI_DEBUG instead of #if WI_DEBUG
 1.43 26-Feb-2002  dbj avoid walking full length of unknown stats structure.
this partially addresses pr14385.
there is still a byte swapping bug retrieving the
stats structure. Since both the type and the length
are incorrectly swapped, we would timeout while reading
an extra long section (caused by the byteswapped length)
of garbage data.
turning on WI_DEBUG now just reports the unknown info type
which can be seen to be obviously incorrectly swapped
on macppc
 1.42 18-Feb-2002  yamt fix indent
 1.41 18-Feb-2002  yamt add a missing splx in the case of error.
 1.40 17-Feb-2002  martin Protect calls to wi_cmd() from callout handlers by proper splnet()/splx()
pairs. Without this, the interrupt handler will steal the "command completed"
status and wi_cmd will busy loop until it times out.

Add some error output to make failure modes like this more prominent.

This should fix PR 14559.
 1.39 13-Feb-2002  itojun make the driver even more silent; print state change messages only if IFF_DEBUG.
 1.38 01-Feb-2002  martin Don't display some (non-exceptional) events unless IFF_DEBUG is set.
I have a card that fires a continuos stream of "connected" events (one
every 30 seconds) while it hasn't found any peer.
 1.37 21-Jan-2002  ichiro if AP is nothing, FrameLen is 3 or less.
 1.36 21-Jan-2002  ichiro Print Association status changes to the console.
 1.35 21-Jan-2002  ichiro "Association Faild" was added to "Link Stat" messages.
;
Implement wi_scan into wi.c.
forces if_wi to initiate one round of access point scan.
This code was written by jrb@cs.pdx.edu, modified and bug-fixed by ichiro@netbsd.org
 1.34 20-Jan-2002  ichiro mistake bit number of tx_rate
case 4 -> case 5
 1.33 20-Jan-2002  ichiro When the length of the key of WEP was 5 or less octets, WEP was set to 40Bit.
5.5MBps were added to ifmedia.
 1.32 18-Jan-2002  ichiro to use 104bit WEP key
 1.31 09-Jan-2002  drochner print link status changes to the console
 1.30 05-Jan-2002  explorer revert changes I made a long time ago. This should undo the changes which are causing problems on some non-x86 platforms. I'll probsably redo some of these changes, but after the next release branch.
 1.29 13-Nov-2001  lukem add/cleanup RCSID
 1.28 11-Nov-2001  christos Get rid of duplicate RID definitions.
 1.27 14-Oct-2001  ichiro branches: 1.27.2;
The description about soft-reset of WI_PCI_COR was added
and WI_PCI_SOFT_RESET was used.
Cosmetic change.
 1.26 13-Oct-2001  ichiro Add Intersil Prism2.5 Mini-PCI wavelan.
 1.25 22-Sep-2001  explorer Implement two major items:

(1) Add an IOCTL to tell the Lucent based cards how often to
do an access point scan. These results are returned by
calling another IOCTL to get the most recent scan data.

This function works with prism2 cards as well, but the
data is returned in a different format, or perhaps it is
data only for the closest access point.

(2) For prism2 cards, add the ability to put it into LAN monitor
mode, where (via BPF) all packets can be received. This
mode works best with "wiconfig wi0 -p 3 -f ?" to put the
card into pseudo-IBSS mode (to keep it from channel-hopping
and scanning for access points) and to set the frequency of
the AP you wish to monitor.

The returned data has a partial wi_frame header (down to the
wi_dat_len field) followed by the raw data of the packet.
I have and will put up on http://www.flame.org/NetBSD/wireless/
some simple utilities which do some perhaps interesting things,
like scan for access points, capture packets, etc.
 1.24 16-Aug-2001  wiz branches: 1.24.2;
Fix indentation in switch statement, per kern/13725 by seebs.
 1.23 13-Aug-2001  wiz Space nit. kern/13712 by seebs.
 1.22 26-Jul-2001  jdolecek make local variable 'len' in wi_set_nwkey() size_t (hence unsigned)
this one is merely cosmetic, no functional change
 1.21 07-Jul-2001  thorpej branches: 1.21.2;
bzero -> memset
 1.20 07-Jul-2001  thorpej bcopy -> memcpy
 1.19 07-Jul-2001  thorpej bcmp -> memcmp
 1.18 27-Jun-2001  nathanw The back end driver doesn't need PCMCIA headers, but it does need
<machine/bus.h>.
 1.17 12-Jun-2001  thorpej branches: 1.17.2;
Don't need INET or NS includes here.
 1.16 04-Jun-2001  toshii Don't pass nonpositive repeat count to CSR_*_MULTI_2.
Should fix kern/13092.
 1.15 02-Jun-2001  toshii Use bus_space_{read,write}_multi_stream_2 where available.
 1.14 20-May-2001  ichiro add more comment about firmware of EVAL-CARD.
 1.13 20-May-2001  ichiro chenge chip and card identity,
print RF-chipset, Medium Access Controller(MAC) and CARD-identity
 1.12 16-May-2001  ichiro support BUFFALO AirStation WLI-PCM-S11
this card are PRISM2.5 card.
 1.11 16-May-2001  tsubai Big-endian support.
 1.10 16-May-2001  ichiro add prism chip identity, Prism2 with SST flush.
 1.9 16-May-2001  ichiro cosmetic change.
change version format: <major>.<minor> variant <num>
 1.8 15-May-2001  ichiro fixed mistake.
major version and minor version were made reverse.
 1.7 15-May-2001  ichiro Fix indentation in recent commit.
 1.6 15-May-2001  ichiro getting prism2 firm ver routine to wi_get_id().
if firm ver is more than 0.8c3, promiscuous mode is off.

typo WI_RID_STA_IDENEITY -> WI_RID_STA_IDENTITY
 1.5 15-May-2001  ichiro WEP cannot be used when Prism2 Firm version is lower than 0.8.3.
Although WEP is used in Windows also in an old firm,
because WEP is processed by the windows driver side.
If Prism2 Firm version is more than 0.8.3, WEP does work without 'Promiscuous ON'.
 1.4 15-May-2001  ichiro It enabled it to control roaming mode and authentication mode.
Roaming mode can change value into 'firm mode' and disable.
Authentication mode can change into 'Open System authentication'
and 'Shared Key Authentication' with Prism2 chip.

wi_get_id() was introduced in order that chip might judge automatically
whether it is Prism2 chip. Therefore, a pp_prism2 entry in
"struct wi_pcmcia_product" became unnecessary.
 1.3 08-May-2001  ichiro change promisc mode in case of SIOCSIFFLAGS of wi_ioctl.
Fix indentation.
 1.2 08-May-2001  ichiro delay(10) is too much enough for command waiting routine.
 1.1 06-May-2001  ichiro divided into PCMCIA attachment and common code of wi.
since if_wi_ieee.h does not depend for pcmcia,
sys/dev/pcmcia/if_wi_ieee.h was moved to sys/dev/ic/wi_ieee.h .
 1.17.2.24 15-Jan-2003  thorpej Sync with HEAD.
 1.17.2.23 03-Jan-2003  thorpej Sync with HEAD.
 1.17.2.22 29-Dec-2002  thorpej Sync with HEAD.
 1.17.2.21 11-Dec-2002  thorpej Sync with HEAD.
 1.17.2.20 11-Nov-2002  nathanw Catch up to -current
 1.17.2.19 18-Oct-2002  nathanw Catch up to -current.
 1.17.2.18 23-Sep-2002  thorpej Sync with HEAD.
 1.17.2.17 27-Aug-2002  nathanw Catch up to -current.
 1.17.2.16 13-Aug-2002  nathanw Catch up to -current.
 1.17.2.15 12-Jul-2002  nathanw No longer need to pull in lwp.h; proc.h pulls it in for us.
 1.17.2.14 24-Jun-2002  nathanw Curproc->curlwp renaming.

Change uses of "curproc->l_proc" back to "curproc", which is more like the
original use. Bare uses of "curproc" are now "curlwp".

"curproc" is now #defined in proc.h as ((curlwp) ? (curlwp)->l_proc) : NULL)
so that it is always safe to reference curproc (*de*referencing curproc
is another story, but that's always been true).
 1.17.2.13 20-Jun-2002  nathanw Catch up to -current.
 1.17.2.12 17-Apr-2002  nathanw Catch up to -current.
 1.17.2.11 01-Apr-2002  nathanw Catch up to -current.
(CVS: It's not just a program. It's an adventure!)
 1.17.2.10 28-Feb-2002  nathanw Catch up to -current.
 1.17.2.9 11-Jan-2002  nathanw More catchup.
 1.17.2.8 09-Jan-2002  nathanw Catch up to -current. No, really, for sure this time.
 1.17.2.7 08-Jan-2002  nathanw Catch up to -current.
 1.17.2.6 15-Nov-2001  thorpej Merge from -current; compilation fix (pcmcia front-end out of sync
with bus-independent part .. merge error, I guess).
 1.17.2.5 08-Oct-2001  nathanw Catch up to -current.
 1.17.2.4 26-Sep-2001  nathanw Catch up to -current.
Again.
 1.17.2.3 24-Aug-2001  nathanw Catch up with -current.
 1.17.2.2 21-Jun-2001  nathanw Catch up to -current.
 1.17.2.1 12-Jun-2001  nathanw file wi.c was added on branch nathanw_sa on 2001-06-21 20:03:30 +0000
 1.21.2.8 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.21.2.7 06-Sep-2002  jdolecek sync kqueue branch with HEAD
 1.21.2.6 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.21.2.5 16-Mar-2002  jdolecek Catch up with -current.
 1.21.2.4 11-Feb-2002  jdolecek Sync w/ -current.
 1.21.2.3 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.21.2.2 25-Aug-2001  thorpej Merge Aug 24 -current into the kqueue branch.
 1.21.2.1 03-Aug-2001  lukem update to -current
 1.24.2.1 01-Oct-2001  fvdl Catch up with -current.
 1.27.2.1 12-Nov-2001  thorpej Sync the thorpej-mips-cache branch with -current.
 1.72.4.1 01-Jun-2002  tv Pull up revision 1.73 (requested by mycroft in ticket #109):
Makes some cards with Symbol firmware work in ad-hoc mode.
 1.72.2.2 29-Aug-2002  gehenna catch up with -current.
 1.72.2.1 20-Jun-2002  gehenna catch up with -current.
 1.130.2.12 11-Dec-2005  christos Sync with head.
 1.130.2.11 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.130.2.10 01-Apr-2005  skrll Sync with HEAD.
 1.130.2.9 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.130.2.8 15-Feb-2005  skrll Sync with HEAD.
 1.130.2.7 17-Jan-2005  skrll Sync with HEAD.
 1.130.2.6 18-Dec-2004  skrll Sync with HEAD.
 1.130.2.5 29-Nov-2004  skrll Sync with HEAD.
 1.130.2.4 02-Nov-2004  skrll Sync with HEAD.
 1.130.2.3 19-Oct-2004  skrll Sync with HEAD
 1.130.2.2 12-Aug-2004  skrll Sync with HEAD.
 1.130.2.1 03-Aug-2004  skrll Sync with HEAD
 1.159.2.2 23-Jul-2004  he branches: 1.159.2.2.2;
Pull up revisions 1.162-1.181 (requested by mycroft in tickets #700,#701):
Many bug fixes and performance fixes for the wi(4) driver,
as well as changes paving the way for further performance
improvements.
 1.159.2.1 07-Jun-2004  jdc Pull up revision 1.161 (requested by dyoung in ticket #449).

Finally, refactor wi_media_change and ieee80211_media_change.
ieee80211_media_change handles a lot more conditions than
wi_media_change did.

This helps with the second bug mentioned in kern/25604, which causes
"SIOCSIFMEDIA: Invalid argument."
 1.159.2.2.2.1 24-Jan-2005  he Pull up revision 1.188 (requested by thorpej in ticket #939):
When adding or deleting multicast addresses, only change
the address filter if the interface is marked RUNNING.
Fixes PR#27678.
 1.193.2.1 29-Apr-2005  kent sync with -current
 1.194.2.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.202.2.6 21-Jan-2008  yamt sync with head
 1.202.2.5 27-Oct-2007  yamt sync with head.
 1.202.2.4 03-Sep-2007  yamt sync with head.
 1.202.2.3 26-Feb-2007  yamt sync with head.
 1.202.2.2 30-Dec-2006  yamt sync with head.
 1.202.2.1 21-Jun-2006  yamt sync with head.
 1.209.6.1 22-Nov-2005  yamt sync with head.
 1.211.6.2 01-Jun-2006  kardel Sync with head.
 1.211.6.1 22-Apr-2006  simonb Sync with head.
 1.211.4.1 09-Sep-2006  rpaulo sync with head
 1.211.2.1 01-Mar-2006  yamt sync with head.
 1.212.4.3 19-Apr-2006  elad sync with head.
 1.212.4.2 10-Mar-2006  elad generic_authorize() -> kauth_authorize_generic().
 1.212.4.1 08-Mar-2006  elad Adapt to kernel authorization KPI.
 1.212.2.3 11-Aug-2006  yamt sync with head
 1.212.2.2 24-May-2006  yamt sync with head.
 1.212.2.1 13-Mar-2006  yamt sync with head.
 1.213.2.1 24-May-2006  tron Merge 2006-05-24 NetBSD-current into the "peter-altq" branch.
 1.215.6.2 10-Dec-2006  yamt sync with head.
 1.215.6.1 22-Oct-2006  yamt sync with head
 1.215.4.2 12-Jan-2007  ad Sync with head.
 1.215.4.1 18-Nov-2006  ad Sync with head.
 1.218.2.1 12-Mar-2007  rmind Sync with HEAD.
 1.219.4.1 11-Jul-2007  mjf Sync with head.
 1.219.2.3 23-Oct-2007  ad Sync with head.
 1.219.2.2 09-Oct-2007  ad Sync with head.
 1.219.2.1 01-Jul-2007  ad Adapt to callout API change.
 1.220.8.2 09-Jan-2008  matt sync with HEAD
 1.220.8.1 06-Nov-2007  matt sync with HEAD
 1.220.6.3 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.220.6.2 04-Sep-2007  joerg Convert wi(4) to jmcneill-pm style power management.
 1.220.6.1 03-Sep-2007  jmcneill Sync with HEAD.
 1.220.2.1 03-Sep-2007  skrll Sync with HEAD.
 1.221.4.1 25-Oct-2007  bouyer Sync with HEAD.
 1.222.6.1 11-Dec-2007  yamt sync with head.
 1.222.4.1 26-Dec-2007  ad Sync with head.
 1.223.2.1 02-Jan-2008  bouyer Sync with HEAD
 1.224.6.2 17-Jan-2009  mjf Sync with HEAD.
 1.224.6.1 02-Jun-2008  mjf Sync with HEAD.
 1.225.4.6 11-Aug-2010  yamt sync with head.
 1.225.4.5 11-Mar-2010  yamt sync with head
 1.225.4.4 16-Sep-2009  yamt sync with head
 1.225.4.3 16-May-2009  yamt sync with head
 1.225.4.2 04-May-2009  yamt sync with head.
 1.225.4.1 16-May-2008  yamt sync with head.
 1.225.2.1 18-May-2008  yamt sync with head.
 1.226.8.2 28-Apr-2009  skrll Sync with HEAD.
 1.226.8.1 19-Jan-2009  skrll Sync with HEAD.
 1.226.6.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.228.4.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.232.4.2 05-Mar-2011  rmind sync with head
 1.232.4.1 30-May-2010  rmind sync with head
 1.232.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.235.16.1 18-May-2014  rmind sync with head
 1.235.12.2 03-Dec-2017  jdolecek update from HEAD
 1.235.12.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.235.2.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.237.6.4 28-Aug-2017  skrll Sync with HEAD
 1.237.6.3 05-Feb-2017  skrll Sync with HEAD
 1.237.6.2 09-Jul-2016  skrll Sync with HEAD
 1.237.6.1 29-May-2016  skrll Sync with HEAD
 1.240.4.1 21-Apr-2017  bouyer Sync with HEAD
 1.240.2.2 26-Apr-2017  pgoyette Sync with HEAD
 1.240.2.1 20-Mar-2017  pgoyette Sync with HEAD
 1.243.6.2 26-Jul-2018  snj Pull up following revision(s) (requested by msaitoh in ticket #938):
sys/arch/acorn32/podulebus/if_ie.c: revision 1.41
sys/arch/amiga/dev/if_es.c: revision 1.58
sys/arch/amiga/dev/if_qn.c: revision 1.45
sys/arch/arm/at91/at91emac.c: revision 1.20
sys/arch/arm/ep93xx/epe.c: revision 1.37
sys/arch/emips/ebus/if_le_ebus.c: revision 1.14
sys/arch/emips/ebus/if_le_ebus.c: revision 1.15
sys/arch/mac68k/dev/if_mc.c: revision 1.46
sys/arch/macppc/dev/am79c950.c: revision 1.39
sys/arch/newsmips/apbus/if_sn.c: revision 1.40
sys/arch/next68k/dev/mb8795.c: revision 1.59
sys/arch/playstation2/dev/if_smap.c: revision 1.25
sys/arch/playstation2/dev/if_smap.c: revision 1.26
sys/arch/sun2/dev/if_ec.c: revision 1.28
sys/arch/sun3/dev/if_ie.c: revision 1.63
sys/arch/x68k/dev/if_ne_intio.c: revision 1.19
sys/arch/xen/xen/if_xennet_xenbus.c: revision 1.75
sys/arch/xen/xen/xennetback_xenbus.c: revision 1.63
sys/dev/bi/if_ni.c: revision 1.45
sys/dev/cadence/if_cemac.c: revision 1.12
sys/dev/ic/am7990.c: revision 1.78
sys/dev/ic/am79900.c: revision 1.27
sys/dev/ic/an.c: revision 1.67
sys/dev/ic/cs89x0.c: revision 1.40
sys/dev/ic/dm9000.c: revision 1.13
sys/dev/ic/dm9000.c: revision 1.14
sys/dev/ic/dp8390.c: revision 1.88
sys/dev/ic/elink3.c: revision 1.141
sys/dev/ic/elinkxl.c: revision 1.122
sys/dev/ic/hme.c: revision 1.98
sys/dev/ic/i82586.c: revision 1.77
sys/dev/ic/lance.c: revision 1.53
sys/dev/ic/mb86950.c: revision 1.27
sys/dev/ic/mb86960.c: revision 1.86
sys/dev/ic/mtd803.c: revision 1.34
sys/dev/ic/pdq_ifsubr.c: revision 1.59
sys/dev/ic/rrunner.c: revision 1.86
sys/dev/ic/seeq8005.c: revision 1.58
sys/dev/ic/sgec.c: revision 1.47
sys/dev/ic/smc90cx6.c: revision 1.72
sys/dev/ic/smc91cxx.c: revision 1.96
sys/dev/ic/tropic.c: revision 1.49
sys/dev/ic/wi.c: revision 1.245
sys/dev/isa/if_eg.c: revision 1.93
sys/dev/isa/if_el.c: revision 1.95
sys/dev/isa/if_iy.c: revision 1.101
sys/dev/ofw/ofnet.c: revision 1.58
sys/dev/pci/if_alc.c: revision 1.27
sys/dev/pci/if_de.c: revision 1.152
sys/dev/pci/if_fpa.c: revision 1.61
sys/dev/pci/if_jme.c: revision 1.34
sys/dev/pci/if_tl.c: revision 1.108
sys/dev/pci/if_vte.c: revision 1.19
sys/dev/pci/ixgbe/ixgbe.h: revision 1.50
sys/dev/pcmcia/if_cnw.c: revision 1.62
sys/dev/pcmcia/if_malo_pcmcia.c: revision 1.17
sys/dev/pcmcia/if_ray.c: revision 1.89
sys/dev/pcmcia/if_xi.c: revision 1.81
sys/dev/pcmcia/mhzc.c: revision 1.51
sys/dev/pcmcia/xirc.c: revision 1.34
sys/dev/qbus/if_de.c: revision 1.33
sys/dev/qbus/if_qe.c: revision 1.78
sys/dev/qbus/if_qt.c: revision 1.22
sys/dev/sbus/be.c: revision 1.87
sys/dev/sbus/qe.c: revision 1.68
sys/dev/scsipi/if_se.c: revision 1.96
sys/dev/usb/if_atu.c: revision 1.59
sys/net/if_l2tp.c: revision 1.28 via patch
sys/net/if_ppp.c: revision 1.160
It's not required to include net/bpfdesc.h. Remove it.
--
Simplify like other drivers. NULL check of ifp->if_bpf is done in
bpf_mtap(), so it's not required to do it here.
--
Remove duplicated inclusion of net/bpf.h.
--
Remove duplicated inclusion of net/bpf.h.
--
Simplify bpf_mtap() call. No functional change.
 1.243.6.1 10-Dec-2017  snj Pull up following revision(s) (requested by msaitoh in ticket #427):
sys/arch/amiga/dev/if_bah_zbus.c: 1.17
sys/arch/arm/broadcom/bcm53xx_eth.c: 1.30
sys/arch/powerpc/booke/dev/pq3etsec.c: 1.32
sys/arch/usermode/dev/if_veth.c: 1.9
sys/dev/ic/an.c: 1.66
sys/dev/ic/athn.c: 1.17
sys/dev/ic/atw.c: 1.162
sys/dev/ic/bwi.c: 1.33
sys/dev/ic/dwc_gmac.c: 1.41-1.42
sys/dev/ic/malo.c: 1.10
sys/dev/ic/rt2560.c: 1.31
sys/dev/ic/rt2661.c: 1.36
sys/dev/ic/rt2860.c: 1.29
sys/dev/ic/rtw.c: 1.127
sys/dev/ic/rtwvar.h: 1.46
sys/dev/ic/smc90cx6.c: 1.71
sys/dev/ic/smc90cx6var.h: 1.12
sys/dev/ic/wi.c: 1.244
sys/dev/pci/if_ipw.c: 1.66
sys/dev/pci/if_iwi.c: 1.104
sys/dev/pci/if_iwm.c: 1.76
sys/dev/pci/if_iwn.c: 1.86
sys/dev/pci/if_rtwn.c: 1.13
sys/dev/pci/if_wm.c: 1.541
sys/dev/pci/if_wpi.c: 1.79
sys/dev/pci/ixgbe/ixgbe.c: 1.106
sys/dev/pci/ixgbe/ixv.c: 1.73 via patch
sys/dev/pcmcia/if_malo_pcmcia.c: 1.15
sys/dev/scsipi/if_se.c: 1.95
sys/dev/usb/if_upl.c: 1.60
sys/net/if.c: 1.396
sys/net/if.h: 1.241
sys/net/if_arc.h: 1.23
sys/net/if_arcsubr.c: 1.78
sys/net/if_bridge.c: 1.136-1.137
sys/net/if_etherip.c: 1.39
sys/net/if_faith.c: 1.56
sys/net/if_gif.c: 1.131
sys/net/if_loop.c: 1.96
sys/net/if_mpls.c: 1.30
sys/net/if_pppoe.c: 1.129
sys/net/if_srt.c: 1.27
sys/net/if_stf.c: 1.102
sys/net/if_tap.c: 1.100
sys/net/if_vlan.c: 1.105
sys/netinet/ip_carp.c: 1.91
sys/rump/net/lib/libshmif/if_shmem.c: 1.73-1.74
sys/rump/net/lib/libvirtif/if_virt.c: 1.55-1.56
if_initalize() and if_attach() failed when resource allocation failed
(e.g. allocating softint). Without this change, it panics. It's bad because
resource shortage really occured when a lot of pseudo interface is created.
To avoid this problem, don't panic and change return value of if_initialize()
and if_attach() to int. Caller fanction will be recover from error cleanly by
checking the return value.
Return if bah_attach_subr() failed.
If if_attach() failed in the attach function, return.
- If if_initialize() failed in the attach function, free resources and return.
- Add some missing frees in bridge_clone_destroy().
- KNF
If error occured in bcmeth_ccb_attach(), free resources and return.
If error occured in pq3etsec_attach(), free resources and return.
If error occured in the attach function, free resources and return.
- If if_initialize() failed in athn_attach(), free resources and return.
- Add missing pmf_event_deregister() in athn_detach().
- Free resources correctly on some errors in atw_attach().
- Use apint*() insread of printf() in the attach function.
If if_initialize() failed in the attach function, return.
- If if_initialize() failed in the attach function, free resources and return.
- Add missing dwc_gmac_free_dma_rings() and mutex_destroy() when attach
failed.
- If if_initialize() failed in the attach function, free resources and return.
- ifp is always not NULL in iwi_detach(). Check correctly with ifp->if_softc.
- If if_initialize() failed in the attach function, free resources and return.
- Fix error path in the attach function correctly.
If if_initialize() failed in the attach function, free resources and return.
If if_attach() failed in the attach function, free resources and return.
- If if_initialize() failed in the attach function, free resources and return.
- KNF
- If if_attach() failed in the attach function, free resources and return.
- KNF
Fix compile error.
Fix compile error.
We don't need '&mii', but just 'mii' for mii_detach().
Don't free sc_rthash twice
 1.244.2.4 26-Nov-2018  pgoyette Sync with HEAD, resolve a couple of conflicts
 1.244.2.3 06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.244.2.2 28-Jul-2018  pgoyette Sync with HEAD
 1.244.2.1 25-Jun-2018  pgoyette Sync with HEAD
 1.247.2.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.247.2.1 10-Jun-2019  christos Sync with HEAD
 1.254.2.1 29-Feb-2020  ad Sync with head.
 1.255.10.1 17-Jun-2021  thorpej Sync w/ HEAD.
 1.4 30-Sep-2002  onoe Jumbo commit for wi driver.
- Eliminate wi_hostap.c since most of the code are duplicated with
net/if_ieee80211subr.c
- Station for Infrastructure network and IBSS also use service functions
as much as possible to be consistent with other wireless drivers.
Now WEP works for station/ibss/hostap.
 1.3 30-Sep-2002  onoe Nuke unneeded member sc_ifp and use #define sc_if instead,
to prepare jumbo commit for wi.c
 1.2 23-Sep-2002  thorpej Jumbo patch, from David Young <dyoung@ojctech.com>, with small tweaks
by me:
* Speed up reading/writing buffers from the hardware by avoiding
slow forward seeks. In preparation to use the optimization, do
not read overlapping bytes. This is currently disabled, but can
be enabled with OPTIMIZE_RW_DATA.
* Hand 802.11 and Prism-specific frames to BPF. User can watch these
frames by specifying an alternate DLT to e.g. tcpdump(8).
* Add support for SIOC[SG]80211BSSID and SIOC[SG]80211CHANNEL.
* Issue join requests and track join/create state through link-status
notifications.
* Split wi_rxeof into separate routines for receiving Ethernet II,
802.11 data, and 802.11 management frames.
* Bug fix: Account for aligning m_data to a word boundary in the Rx
buffer size check.
* Bug fix: Check for LLC/SNAP even if the firmware tells us the frame
is Ethernet II, as the firmware sometimes gets this wrong.
* Process as many events as possible when we get an interrupt, using
a simple heuristic to avoid reprocessing an event (which can have
bad side-effects). Clamp the time spent in the interrupt handler
to 4ms.
* Redo the timeout loops to be consistent and less prone to error.
* Add delays to timeout loops which were missing them, so that a
fast CPU won't win the race.
* Borrow some timeout loop values from the linux-wlan-ng driver,
which seems to reflect a high level of clue (due to direct support
from Intersil).
* Get rid of silly wi_read_data(..., len + 2) idiom; simply round up
in wi_read_data() and wi_write_data(). Also, protect against a
length of 0.
* Name some frequently-used constants. Correct spelling. Other style nits.
* Bug fix: On Prism, set Create IBSS register to 0 *always*. The meaning
of Create IBSS == 1 is join an IBSS or *ESS*, and we do not want to
join an ESS, because that would put us in an inconsistent state. 0
is the right value for Prism.
* Bug fix: Clean up state at the top of wi_init(), in the event that
we don't reach the bottom.
* Simplify wi_start() by always providing an RFC1042-encoded 802.11
frame to the firmware.
* Larval powersave support for HostAP mode, enabled by WI_HOSTAP_POWERSAVE.
* Bug fix: Call wi_stop() from wi_shutdown().
* Bug fix: sync media options with HostAP mode in wi_sync_media().
* In wi_media_status(), inquire firmware for current media state if
media == auto. From FreeBSD.
* Clean up the way buffer lengths are computed by using pointer
arithmetic rather than magic constants.
* Swap the order of comparisons in addr_cmp() for speed.
* Bug fix: Send ReAssoc Response instead of Assoc Response to a
ReAssoc Request.
* Bug fix: Copy SSID using the correct size.
* Give more meaningful names to offsets in a wi_frame.
* Bug fix: Assign the right values to the named constants for
Rx frame encoding.
* Get rid of useless SNAP constants.
 1.1 11-Aug-2002  thorpej branches: 1.1.2; 1.1.4; 1.1.6;
Snapshot of work-in-progress: Add AP support for Prism2-based boards.
WEP for APs is not yet implemented, but without WEP, this works well
enough for my laptop to associate with an AP running this code.

Adapted from OpenBSD.
 1.1.6.3 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.1.6.2 06-Sep-2002  jdolecek sync kqueue branch with HEAD
 1.1.6.1 11-Aug-2002  jdolecek file wi_hostap.c was added on branch kqueue on 2002-09-06 08:44:43 +0000
 1.1.4.2 29-Aug-2002  gehenna catch up with -current.
 1.1.4.1 11-Aug-2002  gehenna file wi_hostap.c was added on branch gehenna-devsw on 2002-08-29 05:22:34 +0000
 1.1.2.4 18-Oct-2002  nathanw Catch up to -current.
 1.1.2.3 23-Sep-2002  thorpej Sync with HEAD.
 1.1.2.2 13-Aug-2002  nathanw Catch up to -current.
 1.1.2.1 11-Aug-2002  nathanw file wi_hostap.c was added on branch nathanw_sa on 2002-08-13 02:19:31 +0000
 1.3 30-Sep-2002  onoe Jumbo commit for wi driver.
- Eliminate wi_hostap.c since most of the code are duplicated with
net/if_ieee80211subr.c
- Station for Infrastructure network and IBSS also use service functions
as much as possible to be consistent with other wireless drivers.
Now WEP works for station/ibss/hostap.
 1.2 23-Sep-2002  thorpej Jumbo patch, from David Young <dyoung@ojctech.com>, with small tweaks
by me:
* Speed up reading/writing buffers from the hardware by avoiding
slow forward seeks. In preparation to use the optimization, do
not read overlapping bytes. This is currently disabled, but can
be enabled with OPTIMIZE_RW_DATA.
* Hand 802.11 and Prism-specific frames to BPF. User can watch these
frames by specifying an alternate DLT to e.g. tcpdump(8).
* Add support for SIOC[SG]80211BSSID and SIOC[SG]80211CHANNEL.
* Issue join requests and track join/create state through link-status
notifications.
* Split wi_rxeof into separate routines for receiving Ethernet II,
802.11 data, and 802.11 management frames.
* Bug fix: Account for aligning m_data to a word boundary in the Rx
buffer size check.
* Bug fix: Check for LLC/SNAP even if the firmware tells us the frame
is Ethernet II, as the firmware sometimes gets this wrong.
* Process as many events as possible when we get an interrupt, using
a simple heuristic to avoid reprocessing an event (which can have
bad side-effects). Clamp the time spent in the interrupt handler
to 4ms.
* Redo the timeout loops to be consistent and less prone to error.
* Add delays to timeout loops which were missing them, so that a
fast CPU won't win the race.
* Borrow some timeout loop values from the linux-wlan-ng driver,
which seems to reflect a high level of clue (due to direct support
from Intersil).
* Get rid of silly wi_read_data(..., len + 2) idiom; simply round up
in wi_read_data() and wi_write_data(). Also, protect against a
length of 0.
* Name some frequently-used constants. Correct spelling. Other style nits.
* Bug fix: On Prism, set Create IBSS register to 0 *always*. The meaning
of Create IBSS == 1 is join an IBSS or *ESS*, and we do not want to
join an ESS, because that would put us in an inconsistent state. 0
is the right value for Prism.
* Bug fix: Clean up state at the top of wi_init(), in the event that
we don't reach the bottom.
* Simplify wi_start() by always providing an RFC1042-encoded 802.11
frame to the firmware.
* Larval powersave support for HostAP mode, enabled by WI_HOSTAP_POWERSAVE.
* Bug fix: Call wi_stop() from wi_shutdown().
* Bug fix: sync media options with HostAP mode in wi_sync_media().
* In wi_media_status(), inquire firmware for current media state if
media == auto. From FreeBSD.
* Clean up the way buffer lengths are computed by using pointer
arithmetic rather than magic constants.
* Swap the order of comparisons in addr_cmp() for speed.
* Bug fix: Send ReAssoc Response instead of Assoc Response to a
ReAssoc Request.
* Bug fix: Copy SSID using the correct size.
* Give more meaningful names to offsets in a wi_frame.
* Bug fix: Assign the right values to the named constants for
Rx frame encoding.
* Get rid of useless SNAP constants.
 1.1 11-Aug-2002  thorpej branches: 1.1.2; 1.1.4; 1.1.6;
Snapshot of work-in-progress: Add AP support for Prism2-based boards.
WEP for APs is not yet implemented, but without WEP, this works well
enough for my laptop to associate with an AP running this code.

Adapted from OpenBSD.
 1.1.6.3 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.1.6.2 06-Sep-2002  jdolecek sync kqueue branch with HEAD
 1.1.6.1 11-Aug-2002  jdolecek file wi_hostap.h was added on branch kqueue on 2002-09-06 08:44:43 +0000
 1.1.4.2 29-Aug-2002  gehenna catch up with -current.
 1.1.4.1 11-Aug-2002  gehenna file wi_hostap.h was added on branch gehenna-devsw on 2002-08-29 05:22:34 +0000
 1.1.2.4 18-Oct-2002  nathanw Catch up to -current.
 1.1.2.3 23-Sep-2002  thorpej Sync with HEAD.
 1.1.2.2 13-Aug-2002  nathanw Catch up to -current.
 1.1.2.1 11-Aug-2002  nathanw file wi_hostap.h was added on branch nathanw_sa on 2002-08-13 02:19:31 +0000
 1.24 11-Dec-2005  christos merge ktrace-lwp.
 1.23 27-Feb-2005  perry nuke trailing whitespace
 1.22 02-Nov-2003  wiz branches: 1.22.8; 1.22.10;
Fix some typos. From Tom Cosgrove via jmc@openbsd.
 1.21 16-Oct-2003  dyoung Prepare for wi rate adaptation. Add wi_write_txrate, which only
writes a hardware register when the data rate selection actually
changes. Add wi_cfg_txrate, which writes the data rate selection
regardless.

Name some fields in the wi Tx buffer which we will use for rate
adaptation.

Name the Prism "Alternate Retry Count" RID, WI_RID_ALT_RETRY_COUNT.
 1.20 08-Apr-2003  kml branches: 1.20.2;
Host AP power saving support. The Host AP notices that the power
saving bit is set in incoming frames from a station, and buffers the
outgoing frames for the station until they are polled for. This
requires support in the driver to set a bit in the TIM bitmap sent
during 802.11 beacons.

So far, support for power saving in Host AP mode is only available
for the PRISM2 chipset.
 1.19 16-Nov-2002  dyoung Support two new RIDs.

WI_RID_DBM_ADJUST: In preparation for capturing Prism packets
containing received signal strength indications (RSSI), read the
constant for conversion from RSSI to dBm (decibels relative to
a milliwatt).

WI_RID_FRAG_THRESH: Get/set the packet fragmentation threshold
on Lucent/Prism.
 1.18 26-Sep-2002  onoe Oops. forgot to delete old line in previous commit:
| Changed the name for resource id 0xfd45 to match the reality.
| WI_RID_OWN_BEACON_INT -> WI_RID_CUR_BEACON_INT
 1.17 26-Sep-2002  onoe Changed the name for resource id 0xfd45 to match the reality.
WI_RID_OWN_BEACON_INT -> WI_RID_CUR_BEACON_INT
 1.16 11-Aug-2002  thorpej Snapshot of work-in-progress: Add AP support for Prism2-based boards.
WEP for APs is not yet implemented, but without WEP, this works well
enough for my laptop to associate with an AP running this code.

Adapted from OpenBSD.
 1.15 18-Apr-2002  onoe branches: 1.15.2;
(force commit: no changes in the code)
WI_RID_SCAN_APS in previous commit works for Intel Pro/Wirelss 2011
with firmware 2.51.1.
It seems that the firmware automatically updated after the card runs on
Windows 2000 with 2011_2011B_CD_3.0 in Intel web site.
 1.14 16-Apr-2002  onoe Support WI_RID_SCAN_APS (wiconfig -D) for Symbol CF Card.
It apparently requires newer firmware (3.10.4), and doesn't work on
Intel PRO/Wireless 2011 (2.0.11).
 1.13 31-Mar-2002  ichiro typo fixed
 1.12 31-Mar-2002  ichiro Dont use magic number.
added parameter of WEP flags
 1.11 30-Mar-2002  ichiro add WI_RID_PRI_IDENTITY rid , (0xFD02)
Reflects the primary funcs firmware Identification number
 1.10 27-Mar-2002  onoe Fix to work Symbol firmware card, which cannot be initialized more than once.
Tested with 3Com 3CRWE737A and Intel Pro/Wireless 2011.
 1.9 21-Jan-2002  ichiro "Association Faild" was added to "Link Stat" messages.
;
Implement wi_scan into wi.c.
forces if_wi to initiate one round of access point scan.
This code was written by jrb@cs.pdx.edu, modified and bug-fixed by ichiro@netbsd.org
 1.8 20-Jan-2002  ichiro add scan req/result RIDs
 1.7 05-Jan-2002  explorer revert changes I made a long time ago. This should undo the changes which are causing problems on some non-x86 platforms. I'll probsably redo some of these changes, but after the next release branch.
 1.6 11-Nov-2001  christos Oops, missed one.
 1.5 11-Nov-2001  christos Get rid of duplicate RID definitions.
 1.4 22-Sep-2001  explorer branches: 1.4.2;
Implement two major items:

(1) Add an IOCTL to tell the Lucent based cards how often to
do an access point scan. These results are returned by
calling another IOCTL to get the most recent scan data.

This function works with prism2 cards as well, but the
data is returned in a different format, or perhaps it is
data only for the closest access point.

(2) For prism2 cards, add the ability to put it into LAN monitor
mode, where (via BPF) all packets can be received. This
mode works best with "wiconfig wi0 -p 3 -f ?" to put the
card into pseudo-IBSS mode (to keep it from channel-hopping
and scanning for access points) and to set the frequency of
the AP you wish to monitor.

The returned data has a partial wi_frame header (down to the
wi_dat_len field) followed by the raw data of the packet.
I have and will put up on http://www.flame.org/NetBSD/wireless/
some simple utilities which do some perhaps interesting things,
like scan for access points, capture packets, etc.
 1.3 15-May-2001  ichiro branches: 1.3.2; 1.3.4; 1.3.6;
getting prism2 firm ver routine to wi_get_id().
if firm ver is more than 0.8c3, promiscuous mode is off.

typo WI_RID_STA_IDENEITY -> WI_RID_STA_IDENTITY
 1.2 15-May-2001  ichiro It enabled it to control roaming mode and authentication mode.
Roaming mode can change value into 'firm mode' and disable.
Authentication mode can change into 'Open System authentication'
and 'Shared Key Authentication' with Prism2 chip.

wi_get_id() was introduced in order that chip might judge automatically
whether it is Prism2 chip. Therefore, a pp_prism2 entry in
"struct wi_pcmcia_product" became unnecessary.
 1.1 06-May-2001  ichiro divided into PCMCIA attachment and common code of wi.
since if_wi_ieee.h does not depend for pcmcia,
sys/dev/pcmcia/if_wi_ieee.h was moved to sys/dev/ic/wi_ieee.h .
 1.3.6.1 01-Oct-2001  fvdl Catch up with -current.
 1.3.4.5 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.3.4.4 06-Sep-2002  jdolecek sync kqueue branch with HEAD
 1.3.4.3 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.3.4.2 11-Feb-2002  jdolecek Sync w/ -current.
 1.3.4.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.3.2.15 21-Nov-2002  martin Catch up to -current.
 1.3.2.14 18-Oct-2002  nathanw Catch up to -current.
 1.3.2.13 13-Aug-2002  nathanw Catch up to -current.
 1.3.2.12 20-Jun-2002  nathanw Catch up to -current.
 1.3.2.11 17-Apr-2002  nathanw Catch up to -current.
 1.3.2.10 01-Apr-2002  nathanw Catch up to -current.
(CVS: It's not just a program. It's an adventure!)
 1.3.2.9 28-Feb-2002  nathanw Catch up to -current.
 1.3.2.8 11-Jan-2002  nathanw More catchup.
 1.3.2.7 09-Jan-2002  nathanw Catch up to -current. No, really, for sure this time.
 1.3.2.6 08-Jan-2002  nathanw Catch up to -current.
 1.3.2.5 15-Nov-2001  thorpej Merge from -current; compilation fix (pcmcia front-end out of sync
with bus-independent part .. merge error, I guess).
 1.3.2.4 08-Oct-2001  nathanw Catch up to -current.
 1.3.2.3 26-Sep-2001  nathanw Catch up to -current.
Again.
 1.3.2.2 21-Jun-2001  nathanw Catch up to -current.
 1.3.2.1 15-May-2001  nathanw file wi_ieee.h was added on branch nathanw_sa on 2001-06-21 20:03:31 +0000
 1.4.2.1 12-Nov-2001  thorpej Sync the thorpej-mips-cache branch with -current.
 1.15.2.1 29-Aug-2002  gehenna catch up with -current.
 1.20.2.4 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.20.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.20.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.20.2.1 03-Aug-2004  skrll Sync with HEAD
 1.22.10.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.22.8.1 29-Apr-2005  kent sync with -current
 1.53 25-Dec-2007  perry Convert many of the uses of __attribute__ to equivalent
__packed, __unused and __dead macros from cdefs.h
 1.52 11-Dec-2005  christos branches: 1.52.46; 1.52.52; 1.52.56; 1.52.60;
merge ktrace-lwp.
 1.51 27-Feb-2005  perry branches: 1.51.4;
nuke trailing whitespace
 1.50 14-Dec-2003  dyoung branches: 1.50.8; 1.50.10;
PR 23428: support National Datacomm Corporation NCP130A2 board.
Thanks T. M. Pederson for sending the patches.
 1.49 02-Nov-2003  wiz Fix some typos. From Tom Cosgrove via jmc@openbsd.
 1.48 25-Oct-2003  simonb Make this compile with older gcc.
 1.47 24-Oct-2003  mycroft In wi_newstate(), read the BSSID into a temporary buffer that has guaranteed
alignment. Fixes a really obscure failure mode on Alpha, and panics on other
machines.
 1.46 16-Oct-2003  dyoung Prepare for wi rate adaptation. Add wi_write_txrate, which only
writes a hardware register when the data rate selection actually
changes. Add wi_cfg_txrate, which writes the data rate selection
regardless.

Name some fields in the wi Tx buffer which we will use for rate
adaptation.

Name the Prism "Alternate Retry Count" RID, WI_RID_ALT_RETRY_COUNT.
 1.45 13-May-2003  dyoung branches: 1.45.2;
Begin synchronization with FreeBSD:

1 Add channel mask, transmit rate-mask arguments to wi_scan_ap.
2 Adopt the macros WI_LOCK/WI_UNLOCK for synchronization. FreeBSD
uses a different synchronization mechanism.
3 In wi_cmd, adopt constants WI_DELAY/WI_TIMEOUT for timing.
4 Pull debug messages from into wi_read_nicid from FreeBSD.
5 Bug fix: if IFF_ALLMULTI, don't filter any multicasts.
6 Count and report TX exceptions, but don't generate any additional
interrupts.
 1.44 08-Apr-2003  kml Host AP power saving support. The Host AP notices that the power
saving bit is set in incoming frames from a station, and buffers the
outgoing frames for the station until they are polled for. This
requires support in the driver to set a bit in the TIM bitmap sent
during 802.11 beacons.

So far, support for power saving in Host AP mode is only available
for the PRISM2 chipset.
 1.43 25-Feb-2003  dyoung Step 0 of adding Prism monitor mode: name the firmware command for
setting up manufacturing test modes. Name the sub-command for
turning on monitor mode.
 1.42 21-Oct-2002  soren WI_PCI_CBMA belongs in dev/pci.
 1.41 02-Oct-2002  onoe Fix NIC-memory leak for symbol firmware at reinitialization. After 4-5
times changing of 802.11 parameters, such as nwid, the error
"tx buffer allocation failed" occured unless ifconfig down up.

Pass signal streangth and timestamp to ieee80211_input, though it is not
useful for wi driver for now.
 1.40 30-Sep-2002  onoe Jumbo commit for wi driver.
- Eliminate wi_hostap.c since most of the code are duplicated with
net/if_ieee80211subr.c
- Station for Infrastructure network and IBSS also use service functions
as much as possible to be consistent with other wireless drivers.
Now WEP works for station/ibss/hostap.
 1.39 23-Sep-2002  thorpej Jumbo patch, from David Young <dyoung@ojctech.com>, with small tweaks
by me:
* Speed up reading/writing buffers from the hardware by avoiding
slow forward seeks. In preparation to use the optimization, do
not read overlapping bytes. This is currently disabled, but can
be enabled with OPTIMIZE_RW_DATA.
* Hand 802.11 and Prism-specific frames to BPF. User can watch these
frames by specifying an alternate DLT to e.g. tcpdump(8).
* Add support for SIOC[SG]80211BSSID and SIOC[SG]80211CHANNEL.
* Issue join requests and track join/create state through link-status
notifications.
* Split wi_rxeof into separate routines for receiving Ethernet II,
802.11 data, and 802.11 management frames.
* Bug fix: Account for aligning m_data to a word boundary in the Rx
buffer size check.
* Bug fix: Check for LLC/SNAP even if the firmware tells us the frame
is Ethernet II, as the firmware sometimes gets this wrong.
* Process as many events as possible when we get an interrupt, using
a simple heuristic to avoid reprocessing an event (which can have
bad side-effects). Clamp the time spent in the interrupt handler
to 4ms.
* Redo the timeout loops to be consistent and less prone to error.
* Add delays to timeout loops which were missing them, so that a
fast CPU won't win the race.
* Borrow some timeout loop values from the linux-wlan-ng driver,
which seems to reflect a high level of clue (due to direct support
from Intersil).
* Get rid of silly wi_read_data(..., len + 2) idiom; simply round up
in wi_read_data() and wi_write_data(). Also, protect against a
length of 0.
* Name some frequently-used constants. Correct spelling. Other style nits.
* Bug fix: On Prism, set Create IBSS register to 0 *always*. The meaning
of Create IBSS == 1 is join an IBSS or *ESS*, and we do not want to
join an ESS, because that would put us in an inconsistent state. 0
is the right value for Prism.
* Bug fix: Clean up state at the top of wi_init(), in the event that
we don't reach the bottom.
* Simplify wi_start() by always providing an RFC1042-encoded 802.11
frame to the firmware.
* Larval powersave support for HostAP mode, enabled by WI_HOSTAP_POWERSAVE.
* Bug fix: Call wi_stop() from wi_shutdown().
* Bug fix: sync media options with HostAP mode in wi_sync_media().
* In wi_media_status(), inquire firmware for current media state if
media == auto. From FreeBSD.
* Clean up the way buffer lengths are computed by using pointer
arithmetic rather than magic constants.
* Swap the order of comparisons in addr_cmp() for speed.
* Bug fix: Send ReAssoc Response instead of Assoc Response to a
ReAssoc Request.
* Bug fix: Copy SSID using the correct size.
* Give more meaningful names to offsets in a wi_frame.
* Bug fix: Assign the right values to the named constants for
Rx frame encoding.
* Get rid of useless SNAP constants.
 1.38 11-Aug-2002  thorpej Remove a redundant defn.
 1.37 11-Aug-2002  thorpej Snapshot of work-in-progress: Add AP support for Prism2-based boards.
WEP for APs is not yet implemented, but without WEP, this works well
enough for my laptop to associate with an AP running this code.

Adapted from OpenBSD.
 1.36 11-Aug-2002  thorpej Read supported rates from the card and report them. Only add
media types if that rate is supported.

Adapted from OpenBSD.
 1.35 10-Aug-2002  thorpej Define PORTTYPE constants for IBSS and HOSTAP (already in the
comments!).
 1.34 18-Apr-2002  onoe branches: 1.34.2;
(force commit: no changes in the code)
WI_RID_SCAN_APS in previous commit works for Intel Pro/Wirelss 2011
with firmware 2.51.1.
It seems that the firmware automatically updated after the card runs on
Windows 2000 with 2011_2011B_CD_3.0 in Intel web site.
 1.33 16-Apr-2002  onoe Support WI_RID_SCAN_APS (wiconfig -D) for Symbol CF Card.
It apparently requires newer firmware (3.10.4), and doesn't work on
Intel PRO/Wireless 2011 (2.0.11).
 1.32 15-Apr-2002  onoe Add support to Symbol Wireless Networker CF card.
The card is Type 1 CF card and it doesn't have firmware in.
So we need to download the firmware image into the card before
touching it.
XXX downloading code should be written in generic (bus independent),
but I don't have enough information for now.
 1.31 10-Apr-2002  ichiro more description of Chips was added
 1.30 05-Apr-2002  ichiro fix minor bugs for lucent cards. (point out from Warner Losh)
 1.29 04-Apr-2002  ichiro space/TAB cosmetics
 1.28 04-Apr-2002  ichiro using table driven for Prism2 family IDs/Names.
 1.27 03-Apr-2002  ichiro add more IDs of PRISM family
 1.26 01-Apr-2002  ichiro add more IDs of PRISM family
 1.25 31-Mar-2002  ichiro add more description of "Connection control characteristics" in Prism2
 1.24 31-Mar-2002  ichiro delete incorrect register
 1.23 31-Mar-2002  ichiro add rx/tx status register
 1.22 31-Mar-2002  ichiro mistake
 1.21 31-Mar-2002  ichiro add more frame structure register
 1.20 15-Mar-2002  martin Psssst, don't tell anybody I commited this.

Add an ugly hack, #ifdef WI_AT_BIGENDIAN_BUS_HACK, to make the wi driver
access the underlying bus in big endian byte order.

This makes it possible to use this driver (probably one of the most
interesting ones) in the pcmcia slot of a stp4020 (nell) adapter at sbus. The
sparc ports bus_space_{read,write}_* macros do not provide a way to do this
cleanly now as they ignore the bus_space_tag_t parameter.

XXX - make bus_space_{read,write}_* on sparc do the right thing.
 1.19 10-Mar-2002  augustss Add a nic I don't really know much about, but it's used on my D-Link card.
 1.18 21-Jan-2002  ichiro Print Association status changes to the console.
 1.17 21-Jan-2002  ichiro "Association Faild" was added to "Link Stat" messages.
;
Implement wi_scan into wi.c.
forces if_wi to initiate one round of access point scan.
This code was written by jrb@cs.pdx.edu, modified and bug-fixed by ichiro@netbsd.org
 1.16 20-Jan-2002  ichiro Upps
Garbage was removed.
 1.15 20-Jan-2002  ichiro add few Information frame types
 1.14 05-Jan-2002  explorer revert changes I made a long time ago. This should undo the changes which are causing problems on some non-x86 platforms. I'll probsably redo some of these changes, but after the next release branch.
 1.13 11-Nov-2001  christos Get rid of duplicate RID definitions.
 1.12 14-Oct-2001  ichiro branches: 1.12.2;
The description about soft-reset of WI_PCI_COR was added
and WI_PCI_SOFT_RESET was used.
Cosmetic change.
 1.11 13-Oct-2001  ichiro Add Intersil Prism2.5 Mini-PCI wavelan.
 1.10 22-Sep-2001  explorer Implement two major items:

(1) Add an IOCTL to tell the Lucent based cards how often to
do an access point scan. These results are returned by
calling another IOCTL to get the most recent scan data.

This function works with prism2 cards as well, but the
data is returned in a different format, or perhaps it is
data only for the closest access point.

(2) For prism2 cards, add the ability to put it into LAN monitor
mode, where (via BPF) all packets can be received. This
mode works best with "wiconfig wi0 -p 3 -f ?" to put the
card into pseudo-IBSS mode (to keep it from channel-hopping
and scanning for access points) and to set the frequency of
the AP you wish to monitor.

The returned data has a partial wi_frame header (down to the
wi_dat_len field) followed by the raw data of the packet.
I have and will put up on http://www.flame.org/NetBSD/wireless/
some simple utilities which do some perhaps interesting things,
like scan for access points, capture packets, etc.
 1.9 07-Jul-2001  thorpej branches: 1.9.2; 1.9.4;
bzero -> memset
 1.8 07-Jul-2001  thorpej bcopy -> memcpy
 1.7 02-Jun-2001  toshii branches: 1.7.2;
Use bus_space_{read,write}_multi_stream_2 where available.
 1.6 16-May-2001  ichiro support BUFFALO AirStation WLI-PCM-S11
this card are PRISM2.5 card.
 1.5 16-May-2001  tsubai Big-endian support.
 1.4 16-May-2001  ichiro add prism chip identity, Prism2 with SST flush.
 1.3 15-May-2001  ichiro getting prism2 firm ver routine to wi_get_id().
if firm ver is more than 0.8c3, promiscuous mode is off.

typo WI_RID_STA_IDENEITY -> WI_RID_STA_IDENTITY
 1.2 15-May-2001  ichiro It enabled it to control roaming mode and authentication mode.
Roaming mode can change value into 'firm mode' and disable.
Authentication mode can change into 'Open System authentication'
and 'Shared Key Authentication' with Prism2 chip.

wi_get_id() was introduced in order that chip might judge automatically
whether it is Prism2 chip. Therefore, a pp_prism2 entry in
"struct wi_pcmcia_product" became unnecessary.
 1.1 06-May-2001  ichiro divided into PCMCIA attachment and common code of wi.
since if_wi_ieee.h does not depend for pcmcia,
sys/dev/pcmcia/if_wi_ieee.h was moved to sys/dev/ic/wi_ieee.h .
 1.7.2.17 11-Nov-2002  nathanw Catch up to -current
 1.7.2.16 18-Oct-2002  nathanw Catch up to -current.
 1.7.2.15 23-Sep-2002  thorpej Sync with HEAD.
 1.7.2.14 13-Aug-2002  nathanw Catch up to -current.
 1.7.2.13 20-Jun-2002  nathanw Catch up to -current.
 1.7.2.12 17-Apr-2002  nathanw Catch up to -current.
 1.7.2.11 01-Apr-2002  nathanw Catch up to -current.
(CVS: It's not just a program. It's an adventure!)
 1.7.2.10 28-Feb-2002  nathanw Catch up to -current.
 1.7.2.9 11-Jan-2002  nathanw More catchup.
 1.7.2.8 09-Jan-2002  nathanw Catch up to -current. No, really, for sure this time.
 1.7.2.7 08-Jan-2002  nathanw Catch up to -current.
 1.7.2.6 15-Nov-2001  thorpej Merge from -current; compilation fix (pcmcia front-end out of sync
with bus-independent part .. merge error, I guess).
 1.7.2.5 08-Oct-2001  nathanw Catch up to -current.
 1.7.2.4 26-Sep-2001  nathanw Catch up to -current.
Again.
 1.7.2.3 24-Aug-2001  nathanw Catch up with -current.
 1.7.2.2 21-Jun-2001  nathanw Catch up to -current.
 1.7.2.1 02-Jun-2001  nathanw file wireg.h was added on branch nathanw_sa on 2001-06-21 20:03:31 +0000
 1.9.4.1 01-Oct-2001  fvdl Catch up with -current.
 1.9.2.6 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.9.2.5 06-Sep-2002  jdolecek sync kqueue branch with HEAD
 1.9.2.4 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.9.2.3 16-Mar-2002  jdolecek Catch up with -current.
 1.9.2.2 11-Feb-2002  jdolecek Sync w/ -current.
 1.9.2.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.12.2.1 12-Nov-2001  thorpej Sync the thorpej-mips-cache branch with -current.
 1.34.2.1 29-Aug-2002  gehenna catch up with -current.
 1.45.2.4 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.45.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.45.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.45.2.1 03-Aug-2004  skrll Sync with HEAD
 1.50.10.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.50.8.1 29-Apr-2005  kent sync with -current
 1.51.4.1 21-Jan-2008  yamt sync with head
 1.52.60.1 02-Jan-2008  bouyer Sync with HEAD
 1.52.56.1 26-Dec-2007  ad Sync with head.
 1.52.52.1 18-Feb-2008  mjf Sync with HEAD.
 1.52.46.1 09-Jan-2008  matt sync with HEAD
 1.67 05-Oct-2019  mrg remove __packed attribute from struct ieee80211_radiotap_header
and all the structures that include it.

this should not change anything while avoiding packed vs alignment
warnings from GCC 8, and potentially pessimised code generation
due to the packed marker (there are no misaligned members, just
that the per-device parts may end unaligned.)

all consumers of these members are done from the properly aligned
packet members directly, or, as a union with a 64 byte member,
also properly aligned. codegen didn't appear to change, except
for the definition of sizeof(struct driver_[rt]x_radiotap_header)
in debug info, which is not directly used anywhere.
 1.66 02-Feb-2017  nonaka branches: 1.66.14;
wlan interfaces make interrupt routine running on softint context.

see http://mail-index.netbsd.org/tech-kern/2016/12/06/msg021281.html

tested device:
* ath at pci: AR5212, AR5424
* athn at pci: AR9287
* ipw at pci: 2100BG
* iwi at pci: 2915ABG
* iwm at pci: 3165, 7260, 8260
* iwn at pci: 4945, 6235
* ral at pci: RT2560
* rtwn at pci: RTL8192CE
 1.65 15-Aug-2011  dyoung branches: 1.65.12; 1.65.30; 1.65.34; 1.65.38;
Use a recursive lock to ensure that only on thread is in wi_ioctl() at
one time. It's a recursive lock because sometimes wi_ioctl() recurses
through the network stack (ick).
 1.64 23-Nov-2010  christos split if_wi
 1.63 17-Jan-2010  pooka branches: 1.63.4;
Forward declare struct bpf_if and use that as the type for bpf_if
instead of "void *". Buys us oo times the type-safety for 0 times
the price.
(no functional change)
 1.62 12-May-2009  cegger struct device * -> device_t, no functional changes intended.
 1.61 25-Dec-2007  perry branches: 1.61.10; 1.61.24;
Convert many of the uses of __attribute__ to equivalent
__packed, __unused and __dead macros from cdefs.h
 1.60 09-Dec-2007  jmcneill branches: 1.60.2;
Merge jmcneill-pm branch.
 1.59 04-Mar-2007  christos branches: 1.59.14; 1.59.16; 1.59.22; 1.59.24; 1.59.26;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.58 18-Nov-2005  skrll branches: 1.58.26;
Adapt drivers to the new net80211(9).

Most of this is from dyoung@. Thanks!
 1.57 25-Jun-2005  dyoung branches: 1.57.2; 1.57.8;
Bug fix: fix WEP by managing keys & crypto in the style of the new
net80211. It was especially important to zero the IEEE80211_F_DROPUNENC
(discard unencrypted packets) flag in operating modes where the
firmware decrypts for us. Otherwise, the 802.11 layer discarded
all received frames. See wi_mend_flags. From FreeBSD, with
improvements by me.

For better compliance with the "net80211 way":
set sc_cnfauthmode from ic->ic_bss->ni_authmode. Enter
the RUN state through ieee80211_create_ibss instead of
ieee80211_new_state(IEEE80211_S_RUN). To sync BSSID in ad hoc
mode, use ieee80211_sta_join() instead of
ieee80211_new_state(IEEE80211_S_RUN). From FreeBSD.

Configure the firmware to obey IEEE80211_F_DROPUNENC.

As we change to state RUN in STA mode, generate a link-status
message on the routing socket with a call to ieee80211_notify_node_join()
instead of calling rt_ifmsg directly.

Run normal net80211 processing (ieee80211_newstate) on the ->RUN
transition.
 1.56 22-Jun-2005  dyoung Resolve conflicts in importation of 18-May-2005 ath(4) / net80211(9)
from FreeBSD. Introduce compatibility shims (sys/dev/ic/ath_netbsd.[ch],
sys/net80211/ieee80211_netbsd.[ch]). Update drivers (an, atu, atw,
awi, ipw, iwi, rtw, wi) for the new net80211(9) API.
 1.55 30-May-2005  christos - add missing const
- fix variable shadowing
- remove unneeded casts
 1.54 27-Feb-2005  perry nuke trailing whitespace
 1.53 13-Dec-2004  dyoung branches: 1.53.2; 1.53.4;
Bug fix: synchronize Transmit commands with all other commands.

Following Charles Hannum's wi(4) optimizations, there could be a
Transmit command outstanding after wi_tx_intr or wi_start returns.
The driver would blithely issue a second command [*] before the
first command was finished, taking the first command's WI_EV_CMD
indication to mean the second command had finished. The driver
would be dreadfully confused when the second command's results did
not meet its expectations (e.g., a RID mismatch error would occur).
The packet transmit section of the code would never read the
WI_EV_CMD it expected, so transmissions would cease.

This patch counts the outstanding transmit commands (there can be
only one) and, if a transmit command is outstanding at the top of
wi_cmd(), wi_cmd waits for the command to complete. If there was
a transmit command outstanding when wi_cmd begins, it calls
wi_cmd_intr() on its way out.

I have tested this on an Orinoco card. Previously, the card would
stop transmitting or the kernel would panic as desynchronization
occurred. Now it works beautifully.

[*] A second command could be issued by wi_ioctl or else by
wi_intr->wi_info_intr->wi_newstate->wi_read_xrid->wi_read_rid.
 1.52 28-Sep-2004  dyoung Simplify the BSSID synchronization code.
 1.51 07-Aug-2004  mycroft Be much more robust with RID values during attach:
* If the device returns a length too short to even contain the RID number,
flag it as not supported and return EOPNOTSUPP, rather than returning a
length of -2 and trying to use the value anyway.
* Check the returned lengths to see if we actually got anything.
* If we get no rate list, fail the attach, so we don't just blow up later.
Allow the frontend to pass in a MAC address.
 1.50 05-Aug-2004  mycroft Put unadulterated dB values in the radiotap header, not the converted dBm
values.
 1.49 22-Jul-2004  mycroft Add sc_txstart and sc_txstarted, to keep track of the current FID we want to
start and the number we've started that have not been alloced yet. Currently
sc_txstarted is constained to 0 or 1 because of the way we start the next
packet, but this will change.
 1.48 22-Jul-2004  mycroft Non-functional changes: add comments, remove a structure name.
 1.47 22-Jul-2004  mycroft Keep a count of packets written to the chip but not yet initiated. This
simplifies some logic, and is needed for later changes.
 1.46 22-Jul-2004  mycroft Change some names.
sc_txnext -> sc_txalloc
sc_txcur -> sc_txqueue
 1.45 22-Jul-2004  mycroft Keep a count of FIDs allocated, rather than storing a packet length in the
ring.
 1.44 22-Jul-2004  mycroft Rework the rate-lowering hack:
* Update sc_txpending[] when a packet is written, even before we issue the TX
command, since it may be active when we issue the TX command for the
following packet.
* Do not lower the rate in ni_txrate or id_rateidx, because these are used to
keep track of sc_txpending[], and could cause us to get "stuck" at the lower
rate.
 1.43 10-Feb-2004  dyoung branches: 1.43.2;
Disable rate-adaptation for Lucent firmware version 8.42.1, per a
bug report from Simon Burge: the firmware seems to lock up.

If rate-adaptation is disabled on a Lucent card, then do all the
rate-adaptation work *except* for writing the new transmit rate,
since I suspect that is what locks-up the firmware.
 1.42 10-Feb-2004  dyoung Factor out the initialization/reset of RSS descriptors, making
wi_rssdescs_init, wi_rssdescs_reset, which I will use to receover
when the firmware botches up the RSS descriptor index.
 1.41 07-Dec-2003  dyoung Enable RSSI-based rate-adaptation for wi(4). This enables wi(4)-based
APs to run at "full speed" where before they ran at just 1 or 2Mb/s.
The AP will adapt the data rate for each client based on packet
losses and the received signal strength.

I have also enabled rate adaptation for STA mode and for IBSS mode,
but the hardware gives us less control over the data rate in those
modes.
 1.40 07-Dec-2003  dyoung Updates to 802.11 radiotap. The _DB_ flags were used everywhere to
denote a signed dBm Rx power, so rename them to _DBM_ and change
the signedness. Add new _DB_ flags for unsigned Rx power measured
from an arbitrary reference.

Try to synchronize net80211/ieee80211_radiotap.h with my tcpdump
sources (which public tcpdump has not seen, yet) and with FreeBSD.
 1.39 16-Nov-2003  dyoung Add data-link type DLT_IEEE802_11_RADIO to wi and atw. DLT_IEEE802_11_RADIO
lets you monitor radio stats like received signal strength, which
diversity antenna was used, channel/frequency, modulation, and data
rate.
 1.38 16-Oct-2003  dyoung The upper & lower bounds on wi RSSI are completely bogus, AFAICT.
 1.37 13-Oct-2003  dyoung Switch wi(4) to the new 802.11 layer.
 1.36 06-Jul-2003  dyoung Still more consolidation of 802.11 media-handling, moving moving
common code from awi and wi into the 802.11 framework. Inspired by
Sam Leffler's patches to FreeBSD.
 1.35 06-Jul-2003  dyoung Improved RSSI->dBm conversion, especially for Lucent cards, for
which I borrowed some conversion constants from the Linux orinoco_cs
driver.
 1.34 20-May-2003  dyoung branches: 1.34.2;
Stop wi panics on card ejection in Powerbook in both the enabled
and disabled states. This should fix an x86 panic somebody reported
on icb.
 1.33 16-May-2003  dyoung IEEE80211_LOCK and WI_LOCK conceal enormous differences in locking
semantics on FreeBSD and NetBSD, so I am backing them out until
the macro set is enriched.
 1.32 13-May-2003  dyoung Begin synchronization with FreeBSD:

1 Add channel mask, transmit rate-mask arguments to wi_scan_ap.
2 Adopt the macros WI_LOCK/WI_UNLOCK for synchronization. FreeBSD
uses a different synchronization mechanism.
3 In wi_cmd, adopt constants WI_DELAY/WI_TIMEOUT for timing.
4 Pull debug messages from into wi_read_nicid from FreeBSD.
5 Bug fix: if IFF_ALLMULTI, don't filter any multicasts.
6 Count and report TX exceptions, but don't generate any additional
interrupts.
 1.31 13-May-2003  dyoung Misc changes to wi_stop. First, block interrupts in wi_stop. (From
FreeBSD.)

Fix a bug in wi_stop where ejecting from the Powerbook crashes the
system. Essentially, the patch makes sure we write *no* registers
when we are no longer attached.

Also, for consistency w/ FreeBSD, use sc_portnum throughout wi,
instead of hard-coding WI_PORT0 .
 1.30 27-Mar-2003  dyoung Cosmetic: move sc_reset closer to its siblings sc_disable and sc_enable.
 1.29 27-Mar-2003  dyoung Introduced sc_reset to wi_softc. The bus-specific front-end gets
to fill this.
 1.28 09-Jan-2003  dyoung wi_start: write an mbuf chain to the driver using wi_mwrite_bap,
which is safer than the loop there used to be here.

wi_mwrite_bap: if wi_write_bap fails, don't keep on going: this
way you avoid writing garbage to the radio. First time you see
an odd-length mbuf, copy the remainder of the chain to sc_txbuf
and from there to the MAC. This way, you do not read an mbuf past
the end of its data (occasionally you will cross a page doing
that!) and you avoid expensive, excess seeks in the radio's own
buffer chain.

wi_rx_intr: clamp the frame length told to us by the driver to the
most bytes we can fit in our mbuf cluster.

I am still getting e-mails from my testers telling me how much
better this makes things.
 1.27 01-Jan-2003  dyoung A Prism firmware participating in an IBSS network will not send a
LINK_STAT notification for every change of BSSID, so the firmware's
BSSID and the driver's BSSID will get out of sync. This has two
bad affects. First, because the 802.11 framework filters received
packets based on BSSID, many packets can be dropped before the
driver adopts the firmware's BSSID. Second, ifconfig's tells a
misleading BSSID to the operator.

This problem is most apparent in networks where every station does
not hear every other. I reproduce these conditions in an office by
removing/replacing the antennas on my 802.11 cards.

As a solution, in IBSS mode, the driver will ask the firmware for
the BSSID every five seconds. Also, whenever the driver receives
a frame carrying a different BSSID than the driver's BSSID, then
the driver asks the firmware for the BSSID before handing the frame
to ieee80211_input.
 1.26 27-Dec-2002  dyoung The RID for the RSSI->dBm adjustment is not supported by Prism
station firmware version <= 1.1.1.
 1.25 18-Nov-2002  dyoung Only Prism is known to support WI_RID_FRAG_THRESH.
 1.24 16-Nov-2002  dyoung Support two new RIDs.

WI_RID_DBM_ADJUST: In preparation for capturing Prism packets
containing received signal strength indications (RSSI), read the
constant for conversion from RSSI to dBm (decibels relative to
a milliwatt).

WI_RID_FRAG_THRESH: Get/set the packet fragmentation threshold
on Lucent/Prism.
 1.23 04-Oct-2002  onoe Handle of AP_IN_RANGE/AP_OUT_RANGE, to fix a problem once the station
is out of ragen, it never comes up again.
For HostAP, prohibit sending DATA frame to an unassociated but authenticated
station.
 1.22 30-Sep-2002  onoe old lucent adhoc-demo mode (adhoc,flag0 or wiconfig -p 3) wasn't handled
correctly. To avoid massive extra code in each driver, now if_iee80211subr.c
also handles non-standard old lucent adhoc-demo mode.
This also fixes PR 14227.
 1.21 30-Sep-2002  onoe Jumbo commit for wi driver.
- Eliminate wi_hostap.c since most of the code are duplicated with
net/if_ieee80211subr.c
- Station for Infrastructure network and IBSS also use service functions
as much as possible to be consistent with other wireless drivers.
Now WEP works for station/ibss/hostap.
 1.20 30-Sep-2002  onoe Nuke unneeded member sc_ifp and use #define sc_if instead,
to prepare jumbo commit for wi.c
 1.19 23-Sep-2002  thorpej Jumbo patch, from David Young <dyoung@ojctech.com>, with small tweaks
by me:
* Speed up reading/writing buffers from the hardware by avoiding
slow forward seeks. In preparation to use the optimization, do
not read overlapping bytes. This is currently disabled, but can
be enabled with OPTIMIZE_RW_DATA.
* Hand 802.11 and Prism-specific frames to BPF. User can watch these
frames by specifying an alternate DLT to e.g. tcpdump(8).
* Add support for SIOC[SG]80211BSSID and SIOC[SG]80211CHANNEL.
* Issue join requests and track join/create state through link-status
notifications.
* Split wi_rxeof into separate routines for receiving Ethernet II,
802.11 data, and 802.11 management frames.
* Bug fix: Account for aligning m_data to a word boundary in the Rx
buffer size check.
* Bug fix: Check for LLC/SNAP even if the firmware tells us the frame
is Ethernet II, as the firmware sometimes gets this wrong.
* Process as many events as possible when we get an interrupt, using
a simple heuristic to avoid reprocessing an event (which can have
bad side-effects). Clamp the time spent in the interrupt handler
to 4ms.
* Redo the timeout loops to be consistent and less prone to error.
* Add delays to timeout loops which were missing them, so that a
fast CPU won't win the race.
* Borrow some timeout loop values from the linux-wlan-ng driver,
which seems to reflect a high level of clue (due to direct support
from Intersil).
* Get rid of silly wi_read_data(..., len + 2) idiom; simply round up
in wi_read_data() and wi_write_data(). Also, protect against a
length of 0.
* Name some frequently-used constants. Correct spelling. Other style nits.
* Bug fix: On Prism, set Create IBSS register to 0 *always*. The meaning
of Create IBSS == 1 is join an IBSS or *ESS*, and we do not want to
join an ESS, because that would put us in an inconsistent state. 0
is the right value for Prism.
* Bug fix: Clean up state at the top of wi_init(), in the event that
we don't reach the bottom.
* Simplify wi_start() by always providing an RFC1042-encoded 802.11
frame to the firmware.
* Larval powersave support for HostAP mode, enabled by WI_HOSTAP_POWERSAVE.
* Bug fix: Call wi_stop() from wi_shutdown().
* Bug fix: sync media options with HostAP mode in wi_sync_media().
* In wi_media_status(), inquire firmware for current media state if
media == auto. From FreeBSD.
* Clean up the way buffer lengths are computed by using pointer
arithmetic rather than magic constants.
* Swap the order of comparisons in addr_cmp() for speed.
* Bug fix: Send ReAssoc Response instead of Assoc Response to a
ReAssoc Request.
* Bug fix: Copy SSID using the correct size.
* Give more meaningful names to offsets in a wi_frame.
* Bug fix: Assign the right values to the named constants for
Rx frame encoding.
* Get rid of useless SNAP constants.
 1.18 11-Aug-2002  thorpej Remove an unused member from the softc.
 1.17 11-Aug-2002  thorpej Snapshot of work-in-progress: Add AP support for Prism2-based boards.
WEP for APs is not yet implemented, but without WEP, this works well
enough for my laptop to associate with an AP running this code.

Adapted from OpenBSD.
 1.16 11-Aug-2002  thorpej * Add "wi_flags" to the softc to indicate capabilities of the card. Fill
in this info based on firmware type and version. Replace "wi_has_wep"
with a flag.
* For cards which support IBSS, add "ibss" has a media option.
* For cards which support CREATE_IBSS, add "ibss-master" as a media
option.
* Use the "ibss" and "ibss-master" media options to determine if
we should go into IBSS mode and/or create the IBSS.
* Internally convert between the generic WI_PORTTYPE_IBSS and the
value the firmware wants to use for IBSS.
* When setting the IBSS name, if a desired-SSID is set, and we're
an ibss-master, write the desired-SSID into the own-SSID slot.
This ensures that "ifconfig wi0 nwid FOO" will do the expected
thing.
* Only set the roaming mode if the card supports roaming.

From OpenBSD.
 1.15 11-Aug-2002  thorpej Read supported rates from the card and report them. Only add
media types if that rate is supported.

Adapted from OpenBSD.
 1.14 05-Apr-2002  ichiro branches: 1.14.2;
fix minor bugs for lucent cards. (point out from Warner Losh)
 1.13 04-Apr-2002  jdolecek move wi_pci_reset() from ic/wi.c to pci/if_wi_pci.c, where is belongs
 1.12 04-Apr-2002  ichiro using table driven for Prism2 family IDs/Names.
 1.11 30-Mar-2002  ichiro added sc_pri_firmware_ver, and print Primary/Station firmware versions.
cosmetic change.
 1.10 27-Mar-2002  onoe Fix to work Symbol firmware card, which cannot be initialized more than once.
Tested with 3Com 3CRWE737A and Intel Pro/Wireless 2011.
 1.9 25-Mar-2002  dbj changes from Warner Losh to read firmware version for non prism2 cards
 1.8 21-Jan-2002  ichiro "Association Faild" was added to "Link Stat" messages.
;
Implement wi_scan into wi.c.
forces if_wi to initiate one round of access point scan.
This code was written by jrb@cs.pdx.edu, modified and bug-fixed by ichiro@netbsd.org
 1.7 05-Jan-2002  explorer revert changes I made a long time ago. This should undo the changes which are causing problems on some non-x86 platforms. I'll probsably redo some of these changes, but after the next release branch.
 1.6 13-Oct-2001  ichiro Add Intersil Prism2.5 Mini-PCI wavelan.
 1.5 22-Sep-2001  explorer Implement two major items:

(1) Add an IOCTL to tell the Lucent based cards how often to
do an access point scan. These results are returned by
calling another IOCTL to get the most recent scan data.

This function works with prism2 cards as well, but the
data is returned in a different format, or perhaps it is
data only for the closest access point.

(2) For prism2 cards, add the ability to put it into LAN monitor
mode, where (via BPF) all packets can be received. This
mode works best with "wiconfig wi0 -p 3 -f ?" to put the
card into pseudo-IBSS mode (to keep it from channel-hopping
and scanning for access points) and to set the frequency of
the AP you wish to monitor.

The returned data has a partial wi_frame header (down to the
wi_dat_len field) followed by the raw data of the packet.
I have and will put up on http://www.flame.org/NetBSD/wireless/
some simple utilities which do some perhaps interesting things,
like scan for access points, capture packets, etc.
 1.4 15-May-2001  ichiro branches: 1.4.2; 1.4.4; 1.4.6;
getting prism2 firm ver routine to wi_get_id().
if firm ver is more than 0.8c3, promiscuous mode is off.

typo WI_RID_STA_IDENEITY -> WI_RID_STA_IDENTITY
 1.3 15-May-2001  ichiro It enabled it to control roaming mode and authentication mode.
Roaming mode can change value into 'firm mode' and disable.
Authentication mode can change into 'Open System authentication'
and 'Shared Key Authentication' with Prism2 chip.

wi_get_id() was introduced in order that chip might judge automatically
whether it is Prism2 chip. Therefore, a pp_prism2 entry in
"struct wi_pcmcia_product" became unnecessary.
 1.2 08-May-2001  ichiro change promisc mode in case of SIOCSIFFLAGS of wi_ioctl.
Fix indentation.
 1.1 06-May-2001  ichiro divided into PCMCIA attachment and common code of wi.
since if_wi_ieee.h does not depend for pcmcia,
sys/dev/pcmcia/if_wi_ieee.h was moved to sys/dev/ic/wi_ieee.h .
 1.4.6.1 01-Oct-2001  fvdl Catch up with -current.
 1.4.4.5 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.4.4.4 06-Sep-2002  jdolecek sync kqueue branch with HEAD
 1.4.4.3 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.4.4.2 11-Feb-2002  jdolecek Sync w/ -current.
 1.4.4.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.4.2.18 15-Jan-2003  thorpej Sync with HEAD.
 1.4.2.17 03-Jan-2003  thorpej Sync with HEAD.
 1.4.2.16 29-Dec-2002  thorpej Sync with HEAD.
 1.4.2.15 11-Dec-2002  thorpej Sync with HEAD.
 1.4.2.14 18-Oct-2002  nathanw Catch up to -current.
 1.4.2.13 23-Sep-2002  thorpej Sync with HEAD.
 1.4.2.12 13-Aug-2002  nathanw Catch up to -current.
 1.4.2.11 17-Apr-2002  nathanw Catch up to -current.
 1.4.2.10 01-Apr-2002  nathanw Catch up to -current.
(CVS: It's not just a program. It's an adventure!)
 1.4.2.9 28-Feb-2002  nathanw Catch up to -current.
 1.4.2.8 11-Jan-2002  nathanw More catchup.
 1.4.2.7 09-Jan-2002  nathanw Catch up to -current. No, really, for sure this time.
 1.4.2.6 08-Jan-2002  nathanw Catch up to -current.
 1.4.2.5 15-Nov-2001  thorpej Merge from -current; compilation fix (pcmcia front-end out of sync
with bus-independent part .. merge error, I guess).
 1.4.2.4 08-Oct-2001  nathanw Catch up to -current.
 1.4.2.3 26-Sep-2001  nathanw Catch up to -current.
Again.
 1.4.2.2 21-Jun-2001  nathanw Catch up to -current.
 1.4.2.1 15-May-2001  nathanw file wivar.h was added on branch nathanw_sa on 2001-06-21 20:03:32 +0000
 1.14.2.1 29-Aug-2002  gehenna catch up with -current.
 1.34.2.7 11-Dec-2005  christos Sync with head.
 1.34.2.6 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.34.2.5 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.34.2.4 18-Dec-2004  skrll Sync with HEAD.
 1.34.2.3 19-Oct-2004  skrll Sync with HEAD
 1.34.2.2 12-Aug-2004  skrll Sync with HEAD.
 1.34.2.1 03-Aug-2004  skrll Sync with HEAD
 1.43.2.1 23-Jul-2004  he Pull up revisions 1.44-1.49 (requested by mycroft in ticket #700):
Many bug fixes and performance fixes for the wi(4) driver,
as well as changes paving the way for further performance
improvements.
 1.53.4.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.53.2.1 29-Apr-2005  kent sync with -current
 1.57.8.1 22-Nov-2005  yamt sync with head.
 1.57.2.3 21-Jan-2008  yamt sync with head
 1.57.2.2 03-Sep-2007  yamt sync with head.
 1.57.2.1 21-Jun-2006  yamt sync with head.
 1.58.26.1 12-Mar-2007  rmind Sync with HEAD.
 1.59.26.1 11-Dec-2007  yamt sync with head.
 1.59.24.1 26-Dec-2007  ad Sync with head.
 1.59.22.1 18-Feb-2008  mjf Sync with HEAD.
 1.59.16.1 09-Jan-2008  matt sync with HEAD
 1.59.14.1 04-Sep-2007  joerg Convert wi(4) to jmcneill-pm style power management.
 1.60.2.1 02-Jan-2008  bouyer Sync with HEAD
 1.61.24.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.61.10.2 11-Mar-2010  yamt sync with head
 1.61.10.1 16-May-2009  yamt sync with head
 1.63.4.1 05-Mar-2011  rmind sync with head
 1.65.38.1 21-Apr-2017  bouyer Sync with HEAD
 1.65.34.1 20-Mar-2017  pgoyette Sync with HEAD
 1.65.30.1 05-Feb-2017  skrll Sync with HEAD
 1.65.12.1 03-Dec-2017  jdolecek update from HEAD
 1.66.14.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.2 27-Dec-2002  mrg this file is way out of date...
 1.1 24-Jan-1996  gwr branches: 1.1.42;
Reorganized, machine-independent z8530 driver, based on the sparc/sun3 zs.
Uses autoconfig to attach keyboard, mouse, or tty. (See z8530.doc)
 1.1.42.1 29-Dec-2002  thorpej Sync with HEAD.
 1.4 28-Jun-1995  cgd move to more appropriate (...reg.h) names.
 1.3 19-Jun-1995  briggs David Leonard (leonard@dstc.edu.au) noticed an embedded comment
delimiter in a comment within a #define (ZSWR14_DTR_REQ). Inserted
spaces in case someone wants to use this define at some point.
 1.2 11-Apr-1995  mycroft Adjust for endianness, and move CHAN_[AB] out of here.
 1.1 11-Apr-1995  mycroft Move this into a generic location.
 1.13 24-May-2022  andvar fix various typos in comment, documentation and log messages.
 1.12 11-Dec-2005  christos merge ktrace-lwp.
 1.11 02-Nov-2003  wiz Fix some typos. From Tom Cosgrove via jmc@openbsd.
 1.10 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22364, verified by myself.
 1.9 31-Jul-1998  wrstuden branches: 1.9.46;
Merge in a register definition mentioned only in passing in one place in
the Zilog docs.
 1.8 13-Dec-1996  gwr branches: 1.8.16;
Add ZSWR1_IMASK (all intr. enable bits in WR1)
 1.7 23-Oct-1996  gwr Add masks for some combinations of bits that are set as a group.
 1.6 16-Oct-1996  gwr Add definitions for the Z85C30 and Z85230 enhanced serial controllers.
Thanks to Bill Studenmund <wrstuden@loki.stanford.edu>
 1.5 24-Jan-1996  gwr Move struct definitions to MD code.
 1.4 20-Aug-1995  leo Select the right register structure for the Atari. Although it's big-endian,
it uses the odd bytes. Also make the registers volatile.
 1.3 19-Jun-1995  briggs David Leonard (leonard@dstc.edu.au) noticed an embedded comment
delimiter in a comment within a #define (ZSWR14_DTR_REQ). Inserted
spaces in case someone wants to use this define at some point.
 1.2 11-Apr-1995  mycroft Adjust for endianness, and move CHAN_[AB] out of here.
 1.1 11-Apr-1995  mycroft Move this into a generic location.
 1.8.16.1 08-Aug-1998  eeh Revert cdevsw mmap routines to return int.
 1.9.46.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.9.46.2 18-Sep-2004  skrll Sync with HEAD.
 1.9.46.1 03-Aug-2004  skrll Sync with HEAD
 1.31 15-Sep-2013  martin Remove unused variable
 1.30 22-May-2009  mrg branches: 1.30.12; 1.30.22; 1.30.26;
add two new functions for z8530tty: zs_chan_lock() and zs_chan_unlock(),
and use them instead of various spl's in the zs.c's.

reviewed by ad and martin.
 1.29 20-Mar-2009  tsutsui Try to avoid zstty hangs on higher speed:

z8530sc.c:
Check pending interrupts in a loop until all requests are handled.
The old comments said it would cause horrible latency to sun3x floppy etc,
but serial ports should have higher priority than disks anyway.

z8530tty.c:
Don't enable and disable TX interrupts on each transmit start and completion
because it could cause possible race conditions.
Instead, set ZSWR0_RESET_TXINT on each TIE interrupt to clear the request
as other kbd drivers attached at zs(4).

Tested on cobalt, macppc, news68k, sparc, and sun3.
 1.28 29-Mar-2008  tsutsui branches: 1.28.4; 1.28.12; 1.28.14; 1.28.18;
Split softc and device_t for zsc(4) and its children.

XXX we should restructure MI APIs and make it really machine independent.
 1.27 12-Nov-2007  ad branches: 1.27.14;
Back out revision 1.26.
 1.26 09-Nov-2007  macallan turn the channel lock into a spin mutex at IPL_NONE so it resembles the
simplelock it used to be
With this my macppc boxes no longer deadlock when init sets up serial ports
 1.25 09-Nov-2007  ad Use zs_lock_init() to set up the chanstate's lock.
 1.24 07-Nov-2007  ad Merge tty changes from the vmlocking branch.
 1.23 04-Mar-2007  christos branches: 1.23.2; 1.23.14; 1.23.16; 1.23.20; 1.23.22;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.22 11-Dec-2005  christos branches: 1.22.26;
merge ktrace-lwp.
 1.21 27-Feb-2005  perry branches: 1.21.4;
nuke trailing whitespace
 1.20 04-Feb-2005  perry de-__P
 1.19 07-Aug-2003  agc branches: 1.19.8; 1.19.10;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22364, verified by myself.
 1.18 28-Jan-2003  pk branches: 1.18.2;
Provide locking required by the interrupt handlers running at IPL_SERIAL.
 1.17 24-Sep-2002  ad Deal with the strange SCC wiring on TC IOASIC machines. Thanks to Bill
Studenmund and Jonathan Stone for useful comments.
 1.16 13-Nov-2001  lukem add/cleanup RCSID
 1.15 07-Jul-2001  thorpej branches: 1.15.2; 1.15.4;
bcopy -> memcpy
 1.14 07-Jul-2001  thorpej bcmp -> memcmp
 1.13 25-Jun-2001  wdk Don't reprogram SCC registers unless the values have changed.

Some CMOS Z85C30 SCC's (as used in the SGI Indy and Mips Magnum 3000's)
reset the baud rate generator when a new prescaler is loaded - despite
what is documented in the datasheet.

Avoids "character glitch" problems when line discipline characteristics
are changed at the start of the login process, or during a ftp session
on the /dev/console device.

Tested on -sgimips, -mipsco and -alpha platforms
 1.12 30-Mar-2000  augustss branches: 1.12.6;
Remove register declarations.
 1.11 03-Feb-1999  mycroft branches: 1.11.8;
Catch up with a change to the stint interface.
 1.10 22-Mar-1998  mycroft Read up to 32 bytes. The ESCC *needs* 8, and it doesn't hurt to leave some
slop in case there are clone chips with a deeper FIFO.
 1.9 05-Mar-1998  wrstuden KNF last change
 1.8 05-Mar-1998  wrstuden Make zs_iflush not loop indefinitly. Some Mac PowerBooks lie about having
two SCC channels, and can get stuck in an infinite loop. This change
stops after flushing 4 bytes. Might need upping to 8 bytes if we support
85230 ESCC's.

Idea bounced off of scottr & gwr
 1.7 19-Feb-1998  mycroft Similar changes to com driver:
Arrange to call com_break() and com_modem() at splserial().
It's simpler this way. Really.
 1.6 04-Oct-1997  gwr branches: 1.6.2;
Remove the while loop from zsc_intr_hard(). It caused problems on
some machines, and those that really want to can just call this
function in a loop until it returns zero.
 1.5 17-Dec-1996  gwr branches: 1.5.10;
New version of the z8530 driver that should permit the mac68k port
to use this instead of its own. Also fix warnings, etc.
 1.4 17-May-1996  gwr Rename cs_pclk_div16 to cs_brg_clk to clarify the fact that the
Baud Rate Generator (BRG) clock is not necessarily PCLK/16.
 1.3 10-Apr-1996  gwr Make the ring size configurable in the tty driver.
Make the pseudo-interrupt functions return void.
Call the tty layer at spltty (to be safe).
 1.2 30-Jan-1996  gwr Eliminate remaining direct references to the z8530 chip
to allow the MD access functions to do delays, etc.
 1.1 24-Jan-1996  gwr Reorganized, machine-independent z8530 driver, based on the sparc/sun3 zs.
Uses autoconfig to attach keyboard, mouse, or tty. (See z8530.doc)
 1.5.10.1 14-Oct-1997  thorpej Update marc-pcmcia branch from trunk.
 1.6.2.1 05-May-1998  mycroft Pull up 1.7, per request of scottr.
 1.11.8.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.12.6.3 18-Oct-2002  nathanw Catch up to -current.
 1.12.6.2 14-Nov-2001  nathanw Catch up to -current.
 1.12.6.1 24-Aug-2001  nathanw Catch up with -current.
 1.15.4.2 13-Oct-2001  fvdl Revert the t_dev -> t_devvp change in struct tty. The way that tty
structs are currently used (especially by console ttys) aren't
ready for it, and this will require quite a few changes.
 1.15.4.1 11-Oct-2001  fvdl Work around some evil, like directly calling interrupt functions
from the attach path, which devvp didn't like because of incompletely
inited tty structs.

All the struct tty init stuff should really be deferred to the first
open for all drivers; the structures are idle before then and
shouldn't be referenced.
 1.15.2.2 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.15.2.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.18.2.5 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.18.2.4 04-Feb-2005  skrll Sync with HEAD.
 1.18.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.18.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.18.2.1 03-Aug-2004  skrll Sync with HEAD
 1.19.10.2 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.19.10.1 12-Feb-2005  yamt sync with head.
 1.19.8.1 29-Apr-2005  kent sync with -current
 1.21.4.2 15-Nov-2007  yamt sync with head.
 1.21.4.1 03-Sep-2007  yamt sync with head.
 1.22.26.1 12-Mar-2007  rmind Sync with HEAD.
 1.23.22.1 19-Nov-2007  mjf Sync with HEAD.
 1.23.20.1 13-Nov-2007  bouyer Sync with HEAD
 1.23.16.2 09-Jan-2008  matt sync with HEAD
 1.23.16.1 08-Nov-2007  matt sync with -HEAD
 1.23.14.2 14-Nov-2007  joerg Sync with HEAD.
 1.23.14.1 11-Nov-2007  joerg Sync with HEAD.
 1.23.2.1 15-Jul-2007  ad Get pmax working.
 1.27.14.1 03-Apr-2008  mjf Sync with HEAD.
 1.28.18.2 23-Jul-2009  jym Sync with HEAD.
 1.28.18.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.28.14.1 16-Jan-2011  bouyer Pull up following revision(s) (requested by mrg in ticket #1526):
sys/arch/sparc/dev/zs.c: revision 1.115
sys/dev/ic/z8530sc.h: revision 1.26
sys/dev/ic/z8530sc.c: revision 1.30
sys/dev/ic/z8530tty.c: revision 1.127
sys/arch/sparc64/dev/zs.c: revision 1.68
add two new functions for z8530tty: zs_chan_lock() and zs_chan_unlock(),
and use them instead of various spl's in the zs.c's.
reviewed by ad and martin.
 1.28.12.1 28-Apr-2009  skrll Sync with HEAD.
 1.28.4.2 20-Jun-2009  yamt sync with head
 1.28.4.1 04-May-2009  yamt sync with head.
 1.30.26.1 18-May-2014  rmind sync with head
 1.30.22.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.30.12.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.26 22-May-2009  mrg add two new functions for z8530tty: zs_chan_lock() and zs_chan_unlock(),
and use them instead of various spl's in the zs.c's.

reviewed by ad and martin.
 1.25 20-Apr-2008  tsutsui branches: 1.25.2; 1.25.12; 1.25.16;
- use uint8_t instead of u_char for unsigned byte values
- make cs_softreq volatile
 1.24 09-Nov-2007  ad branches: 1.24.14; 1.24.16;
Use zs_lock_init() to set up the chanstate's lock.
 1.23 07-Nov-2007  ad Merge tty changes from the vmlocking branch.
 1.22 11-Dec-2005  christos branches: 1.22.30; 1.22.44; 1.22.46; 1.22.50; 1.22.52;
merge ktrace-lwp.
 1.21 04-Feb-2005  perry branches: 1.21.6;
de-__P
 1.20 20-Jun-2004  thorpej branches: 1.20.4; 1.20.6;
Define and use zsccf_channel as an alias for cf_loc[ZSCCF_CHANNEL].
 1.19 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22364, verified by myself.
 1.18 28-Jan-2003  pk branches: 1.18.2;
Provide locking required by the interrupt handlers running at IPL_SERIAL.
 1.17 24-Sep-2002  ad Deal with the strange SCC wiring on TC IOASIC machines. Thanks to Bill
Studenmund and Jonathan Stone for useful comments.
 1.16 06-Sep-2002  gehenna Merge the gehenna-devsw branch into the trunk.

This merge changes the device switch tables from static array to
dynamically generated by config(8).

- All device switches is defined as a constant structure in device drivers.

- The new grammer ``device-major'' is introduced to ``files''.

device-major <prefix> char <num> [block <num>] [<rules>]

- All device major numbers must be listed up in port dependent majors.<arch>
by using this grammer.

- Added the new naming convention.
The name of the device switch must be <prefix>_[bc]devsw for auto-generation
of device switch tables.

- The backward compatibility of loading block/character device
switch by LKM framework is broken. This is necessary to convert
from block/character device major to device name in runtime and vice versa.

- The restriction to assign device major by LKM is completely removed.
We don't need to reserve LKM entries for dynamic loading of device switch.

- In compile time, device major numbers list is packed into the kernel and
the LKM framework will refer it to assign device major number dynamically.
 1.15 11-May-2001  thorpej branches: 1.15.2; 1.15.4; 1.15.14;
Add a flag to suppress SCC reset at attach time.

From Rafal K. Boni.
 1.14 19-Mar-2000  pk branches: 1.14.6;
Define separate flags for console input and output.
Allow console operations to be passed in attachment arguments.
 1.13 14-Mar-2000  jdc Add power management hooks.
 1.12 27-Mar-1999  wrstuden branches: 1.12.8;
PPS support. Copied off of com.c support, with changes as DCD interupts
are only enabled if needed and if ok'd by MD layer.
 1.11 03-Feb-1999  mycroft Catch up with a change to the stint interface.
 1.10 30-Mar-1998  mycroft Eliminate cs_heldchar. It is not necessary in my version of the driver.
 1.9 12-Nov-1997  pk Use a 1-character queue so polled console output can be deferred if
regular I/O has been scheduled.
 1.8 01-Nov-1997  mycroft More changes taken from com driver:
Stop output as fast as possible when DCD is deasserted.
Do *not* automatically drop DTR when DCD is deasserted.
Only check for rr0 bits that we care about (DTR and DCD).
 1.7 17-Oct-1997  gwr branches: 1.7.2;
Rename cs_pad to cs_spare1 (for future use by Bill Studenmund).
 1.6 24-Feb-1997  gwr Add declaration for zs_check_kgdb()
 1.5 17-Dec-1996  gwr branches: 1.5.4;
New version of the z8530 driver that should permit the mac68k port
to use this instead of its own. Also fix warnings, etc.
 1.4 16-Oct-1996  gwr Replace the field cs_rr0_new with cs_rr0_delta (keep changes instead).
 1.3 17-May-1996  gwr Rename cs_pclk_div16 to cs_brg_clk to clarify the fact that the
Baud Rate Generator (BRG) clock is not necessarily PCLK/16.
Also fix up spacing.
 1.2 10-Apr-1996  gwr Make the ring size configurable in the tty driver.
Make the pseudo-interrupt functions return void.
Call the tty layer at spltty (to be safe).
 1.1 24-Jan-1996  gwr Reorganized, machine-independent z8530 driver, based on the sparc/sun3 zs.
Uses autoconfig to attach keyboard, mouse, or tty. (See z8530.doc)
 1.5.4.1 12-Mar-1997  is Merge in changes from Trunk
 1.7.2.3 08-May-1998  mycroft Pull up 1.10, per request of mycroft.
 1.7.2.2 14-Nov-1997  mellon Pull rev 1.9 up from trunk (pk)
 1.7.2.1 06-Nov-1997  mrg pull up rest of zs changes from trunk (verison 1.8)
 1.12.8.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.14.6.3 18-Oct-2002  nathanw Catch up to -current.
 1.14.6.2 17-Sep-2002  nathanw Catch up to -current.
 1.14.6.1 21-Jun-2001  nathanw Catch up to -current.
 1.15.14.1 16-May-2002  gehenna Remove hard-coded major.
 1.15.4.2 13-Oct-2001  fvdl Revert the t_dev -> t_devvp change in struct tty. The way that tty
structs are currently used (especially by console ttys) aren't
ready for it, and this will require quite a few changes.
 1.15.4.1 11-Oct-2001  fvdl Work around some evil, like directly calling interrupt functions
from the attach path, which devvp didn't like because of incompletely
inited tty structs.

All the struct tty init stuff should really be deferred to the first
open for all drivers; the structures are idle before then and
shouldn't be referenced.
 1.15.2.1 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.18.2.4 04-Feb-2005  skrll Sync with HEAD.
 1.18.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.18.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.18.2.1 03-Aug-2004  skrll Sync with HEAD
 1.20.6.1 12-Feb-2005  yamt sync with head.
 1.20.4.1 29-Apr-2005  kent sync with -current
 1.21.6.1 15-Nov-2007  yamt sync with head.
 1.22.52.1 19-Nov-2007  mjf Sync with HEAD.
 1.22.50.1 13-Nov-2007  bouyer Sync with HEAD
 1.22.46.2 09-Jan-2008  matt sync with HEAD
 1.22.46.1 08-Nov-2007  matt sync with -HEAD
 1.22.44.1 11-Nov-2007  joerg Sync with HEAD.
 1.22.30.1 15-Jul-2007  ad Get pmax working.
 1.24.16.1 18-May-2008  yamt sync with head.
 1.24.14.1 02-Jun-2008  mjf Sync with HEAD.
 1.25.16.1 23-Jul-2009  jym Sync with HEAD.
 1.25.12.1 16-Jan-2011  bouyer Pull up following revision(s) (requested by mrg in ticket #1526):
sys/arch/sparc/dev/zs.c: revision 1.115
sys/dev/ic/z8530sc.h: revision 1.26
sys/dev/ic/z8530sc.c: revision 1.30
sys/dev/ic/z8530tty.c: revision 1.127
sys/arch/sparc64/dev/zs.c: revision 1.68
add two new functions for z8530tty: zs_chan_lock() and zs_chan_unlock(),
and use them instead of various spl's in the zs.c's.
reviewed by ad and martin.
 1.25.2.1 20-Jun-2009  yamt sync with head
 1.135 26-Oct-2022  riastradh zs(4): Convert to ttylock/ttyunlock.
 1.134 10-Nov-2019  chs in many device attach paths, allocate memory with M_WAITOK instead of M_NOWAIT
and remove code to handle failures that can no longer happen.
 1.133 21-Jul-2019  rin Fix panic due to inconsistent lock states of tty_lock in zsparam().
Tested on mac68k.
 1.132 31-Oct-2017  martin branches: 1.132.4;
As discussed on tech-kern: define a new tty internal state flag: TS_KERN_ONLY

Implement it in a few tty drivers. If this flag is set, the underlying
hardware is used by another driver and userland has no right to open
it. A few uses will appear soon in sys/dev/sun/sun{kbd,ms}.c.
 1.131 15-Nov-2014  christos branches: 1.131.12;
centralize the dialout/call unit macros.
 1.130 25-Jul-2014  dholland Add d_discard to all struct cdevsw instances I could find.

All have been set to "nodiscard"; some should get a real implementation.
 1.129 16-Mar-2014  dholland branches: 1.129.2;
Change (mostly mechanically) every cdevsw/bdevsw I can find to use
designated initializers.

I have not built every extant kernel so I have probably broken at
least one build; however I've also found and fixed some wrong
cdevsw/bdevsw entries so even if so I think we come out ahead.
 1.128 24-Apr-2011  rmind branches: 1.128.4; 1.128.14; 1.128.18;
Rename ttymalloc() to tty_alloc(), and ttyfree() to tty_free() for
consistency. Remove some unnecessary malloc.h inclusions as well.
 1.127 22-May-2009  mrg branches: 1.127.4; 1.127.6;
add two new functions for z8530tty: zs_chan_lock() and zs_chan_unlock(),
and use them instead of various spl's in the zs.c's.

reviewed by ad and martin.
 1.126 12-May-2009  cegger struct device * -> device_t, no functional changes intended.
 1.125 12-May-2009  cegger struct cfdata * -> cfdata_t, no functional changes intended.
 1.124 20-Mar-2009  tsutsui Try to avoid zstty hangs on higher speed:

z8530sc.c:
Check pending interrupts in a loop until all requests are handled.
The old comments said it would cause horrible latency to sun3x floppy etc,
but serial ports should have higher priority than disks anyway.

z8530tty.c:
Don't enable and disable TX interrupts on each transmit start and completion
because it could cause possible race conditions.
Instead, set ZSWR0_RESET_TXINT on each TIE interrupt to clear the request
as other kbd drivers attached at zs(4).

Tested on cobalt, macppc, news68k, sparc, and sun3.
 1.123 21-Apr-2008  ad branches: 1.123.2; 1.123.10; 1.123.12; 1.123.16;
Make ntp, pmc, reboot, sysarch, time syscalls MPSAFE.
 1.122 29-Mar-2008  tsutsui branches: 1.122.2;
Split softc and device_t for zsc(4) and its children.

XXX we should restructure MI APIs and make it really machine independent.
 1.121 14-Mar-2008  martin Remove a tty_lock for now - I know that this is wrong, but the whole
tty subsystem locking is not consistent and Andrew didn't have
time to come up (or guide to) the right fix.
This prevents machines with serial console on zs(4) from deadlocking on
first input.
 1.120 20-Jan-2008  joerg branches: 1.120.2; 1.120.6;
Now that __HAVE_TIMECOUNTER and __HAVE_GENERIC_TODR are invariants,
remove the conditionals and the code associated with the undef case.
 1.119 22-Dec-2007  ad t_linesw->l_modem would ideally be called with tty_lock held, but before
that can happen someone needs to beat all the drivers into shape.
 1.118 22-Dec-2007  ad Don't recursively acquire tty_lock when zstty_softint() is called directly.
 1.117 19-Nov-2007  ad branches: 1.117.2; 1.117.6;
- Factor out too many copies of the same bit of tty code.
- Fix another tty signalling/wakeup problem.
 1.116 10-Nov-2007  ad zsstart, zstty_txsoft: don't acquire tty_lock, it's already held.
 1.115 07-Nov-2007  ad Merge tty changes from the vmlocking branch.
 1.114 09-Jul-2007  ad branches: 1.114.6; 1.114.8; 1.114.12; 1.114.14;
Merge some of the less invasive changes from the vmlocking branch:

- kthread, callout, devsw API changes
- select()/poll() improvements
- miscellaneous MT safety improvements
 1.113 04-Mar-2007  christos branches: 1.113.2; 1.113.4;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.112 01-Oct-2006  elad branches: 1.112.4;
More from Matt Fleming:

Adapt to KAUTH_DEVICE_TTY_PRIVSET and KAUTH_DEVICE_TTY_OPEN.
 1.111 01-Oct-2006  elad Adapt MD code to KAUTH_DEVICE_TTY_OPEN, batch #2 from Matt Fleming, thanks!

Also, add forgotten splx() calls in some places.
 1.110 22-Jul-2006  martin branches: 1.110.4; 1.110.6;
Remove unused variable to make it compile again.
 1.109 21-Jul-2006  ad - Use the LWP cached credentials where sane.
- Minor cosmetic changes.
 1.108 07-Jun-2006  kardel merge FreeBSD timecounters from branch simonb-timecounters
- struct timeval time is gone
time.tv_sec -> time_second
- struct timeval mono_time is gone
mono_time.tv_sec -> time_uptime
- access to time via
{get,}{micro,nano,bin}time()
get* versions are fast but less precise
- support NTP nanokernel implementation (NTP API 4)
- further reading:
Timecounter Paper: http://phk.freebsd.dk/pubs/timecounter.pdf
NTP Nanokernel: http://www.eecis.udel.edu/~mills/ntp/html/kern.html
 1.107 14-May-2006  elad branches: 1.107.2;
integrate kauth.
 1.106 19-Apr-2006  tsutsui - use M_NOWAIT rather than M_WAITOK for malloc(9) to allocate RX buffer
in zstty_attach()
- check a return value of the malloc(9)

Taken from com.c, and somehow this seems to fix PR port-sun2/32420 on tme.
 1.105 29-Mar-2006  thorpej Use device_cfdata().
 1.104 28-Mar-2006  thorpej Use device_unit().
 1.103 05-Mar-2006  rjs branches: 1.103.2; 1.103.4;
Remove SET/CLR/ISSET macros.
 1.102 27-Dec-2005  chs branches: 1.102.4; 1.102.6; 1.102.8;
switch macppc to use the MI zstty driver.
add macppc's ZS_TXDMA hooks there.
 1.101 11-Dec-2005  christos merge ktrace-lwp.
 1.100 06-Sep-2005  kleink Change the driver open function's conditional for overriding exclusive tty
use from checking the proc's uid to suser(9), and account for the use of
privileges. Noted by David Holland in PR kern/31126.
 1.99 30-Jun-2005  macallan branches: 1.99.2;
Allow sparc64-style attachment of mouse and keyboard via zstty, needed for
wscons support.
Reviewed by uwe.
 1.98 31-May-2005  christos - add const
- avoid variable shadow
 1.97 27-Feb-2005  perry nuke trailing whitespace
 1.96 04-Feb-2005  perry de-__P
 1.95 20-Jun-2004  thorpej branches: 1.95.4; 1.95.6;
Define and use zsccf_channel as an alias for cf_loc[ZSCCF_CHANNEL].
 1.94 23-Jan-2004  simonb Fix NTP PPSAPI support (enabled with "options PPS_SYNC"):

From PR kern/13702 from Charles Carvalho. Tested on alpha and
i386 with a Laipac TF10 PPS-capable GPS. The com.c change was
copied wholesale from Charles' z8530tty.c patch.
 1.93 04-Dec-2003  keihan netbsd.org -> NetBSD.org

This was the last commit of this kind to src/sys, which is now totally
"NetBSD.org clean". Thanks for the patiance, and sorry for all the commits.
 1.92 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22364, verified by myself.
 1.91 29-Jun-2003  fvdl branches: 1.91.2;
Back out the lwp/ktrace changes. They contained a lot of colateral damage,
and need to be examined and discussed more.
 1.90 29-Jun-2003  darrenr More changes for providing lwpid for ktrace (sparc GENERIC built)
 1.89 28-Jan-2003  pk Provide locking required by the interrupt handlers running at IPL_SERIAL.
 1.88 24-Jan-2003  pk zs_shutdown: lower IPL before sleeping. Also note the fact that the
effectiveness of that very tsleep() call is dubious at best.
 1.87 06-Jan-2003  wiz interrupt with two rs.
 1.86 09-Nov-2002  thorpej Fix signed/unsigned comparison warnings.
 1.85 23-Oct-2002  jdolecek merge kqueue branch into -current

kqueue provides a stateful and efficient event notification framework
currently supported events include socket, file, directory, fifo,
pipe, tty and device changes, and monitoring of processes and signals

kqueue is supported by all writable filesystems in NetBSD tree
(with exception of Coda) and all device drivers supporting poll(2)

based on work done by Jonathan Lemon for FreeBSD
initial NetBSD port done by Luke Mewburn and Jason Thorpe
 1.84 02-Oct-2002  thorpej Add trailing ; to CFATTACH_DECL.
 1.83 30-Sep-2002  thorpej Use CFATTACH_DECL().
 1.82 27-Sep-2002  thorpej Declare all cfattach structures const.
 1.81 24-Sep-2002  ad Deal with the strange SCC wiring on TC IOASIC machines. Thanks to Bill
Studenmund and Jonathan Stone for useful comments.
 1.80 06-Sep-2002  gehenna Merge the gehenna-devsw branch into the trunk.

This merge changes the device switch tables from static array to
dynamically generated by config(8).

- All device switches is defined as a constant structure in device drivers.

- The new grammer ``device-major'' is introduced to ``files''.

device-major <prefix> char <num> [block <num>] [<rules>]

- All device major numbers must be listed up in port dependent majors.<arch>
by using this grammer.

- Added the new naming convention.
The name of the device switch must be <prefix>_[bc]devsw for auto-generation
of device switch tables.

- The backward compatibility of loading block/character device
switch by LKM framework is broken. This is necessary to convert
from block/character device major to device name in runtime and vice versa.

- The restriction to assign device major by LKM is completely removed.
We don't need to reserve LKM entries for dynamic loading of device switch.

- In compile time, device major numbers list is packed into the kernel and
the LKM framework will refer it to assign device major number dynamically.
 1.79 17-Mar-2002  atatat branches: 1.79.4;
Convert ioctl code to use EPASSTHROUGH instead of -1 or ENOTTY for
indicating an unhandled "command". ERESTART is -1, which can lead to
confusion. ERESTART has been moved to -3 and EPASSTHROUGH has been
placed at -4. No ioctl code should now return -1 anywhere. The
ioctl() system call is now properly restartable.
 1.78 13-Nov-2001  lukem add/cleanup RCSID
 1.77 30-May-2001  lukem branches: 1.77.2; 1.77.4;
add missing #include "opt_kgdb.h"
 1.76 11-May-2001  thorpej Add a flag to suppress SCC reset at attach time.

From Rafal K. Boni.
 1.75 02-May-2001  scw Add `l_poll' to `struct linesw' and provide an xxxpoll() entry point
in each tty driver to indirect through it.

This allows tty line-disciplines to handle poll(2) system calls.
 1.74 12-Mar-2001  tsutsui Add some delay in zstty_attach() to wait previous console output
to complete before hardware initialization.
 1.73 11-Mar-2001  wdk Add missing \n during probe if port is dedicated to kgdb
 1.72 08-Nov-2000  eeh branches: 1.72.2;
Use the MI console magic sequence framework.
 1.71 05-Nov-2000  chs remove what looks to be a bit of leftover debug code.
 1.70 01-Nov-2000  eeh Adapt to the new line discipline scheme.
 1.69 17-Sep-2000  toshii Change tiocm_to_{com,zs}'s second argument to u_long to match with
the type in their caller.
 1.68 06-Jul-2000  thorpej Use device_lookup().
 1.67 14-Apr-2000  pk branches: 1.67.4;
Remove spurious splx() call.
 1.66 24-Mar-2000  hannken Fix typos from last commit (callout).
 1.65 23-Mar-2000  thorpej New callout mechanism with two major improvements over the old
timeout()/untimeout() API:
- Clients supply callout handle storage, thus eliminating problems of
resource allocation.
- Insertion and removal of callouts is constant time, important as
this facility is used quite a lot in the kernel.

The old timeout()/untimeout() API has been removed from the kernel.
 1.64 19-Mar-2000  pk Check for console input and output separately.
XXX - split input/output for /dev/console is not yet supported.
 1.63 14-Mar-2000  jdc Add power management hooks.
 1.62 04-Nov-1999  jonathan Update user-level PPS-API to match -05 draft.
Change PPS_<xxx> ioctls to PPS_IOC_<xxx>.
 1.61 15-Oct-1999  jonathan branches: 1.61.2; 1.61.4;
Fix nanosecond/microsecond botch in PPSAPI:
remove bogus TIMESPEC_TO_TIMEVAL() after applying any {assert,clear} offset.
 1.60 22-Apr-1999  pk branches: 1.60.2;
Don't send any data upstream if we're not open yet.
 1.59 27-Mar-1999  wrstuden branches: 1.59.2;
PPS support. Copied off of com.c support, with changes as DCD interupts
are only enabled if needed and if ok'd by MD layer.
 1.58 03-Feb-1999  mycroft Minor changes to tiocm code.
 1.57 03-Feb-1999  mycroft Redo the N previous changes, plus a couple of other things:
* Move the printf() delay to just after the printf(), where it actually makes
sense.
* Use zstty_stint() and zstty_softint() from zsparam(), to force an immediate
update of the carrier and flow control status. Abuse this in the attach and
open functions to defer all of that work. This insures that we don't lose
any status updates.
* Don't screw with register 1 when closing the console.
* Fix bugs in TIOCM??? (stay semicolon, clearing DTR while transmitting).
* Add comments in a couple of places.
 1.56 31-Jan-1999  wrstuden Add the patch I floated on tech-kern. Andreas Eltrich <elchy@dahoam.de>
says it got pppd working for him.
 1.55 25-Jan-1999  wrstuden Fix thinko in part of rev 1.53.

Thanks to Scott for pointing this out to me (I got his mail and figured out
this change before seeing the discussion on tech-kern) and to Charles for
the initial explanation.
 1.54 13-Jan-1999  christos Put back modem control ioctl's
 1.53 23-Nov-1998  wrstuden Changes to deal with mac serial ports having clock sources on DCD or CTS.

- When doing a first open, don't enable receive & status interupts before
the MD layer has had a chance to set things up.
- Enable logic to only enable DCD/CTS interupts if we are looking for/
expecting interupts on those pins. Disable otherwise.
- in zs_param, only pass up the state of ZSRR0_DCD if we have enabled
interupts on that pin.

Henry Hotz (<hotz@jpl.nasa.gov>) and Greg walsh <gwalsh@artec.com> have
tried these changes to get certain printers from hanging at boot. They
work in a 1.3.2 kernel for Greg.
 1.52 01-Oct-1998  drochner minor changes to console handling in zstty_attach():
-wait 20ms between printf() and reconfiguring the hardware
-set cn_tab->cn_dev here because this is the place where the real minor
number is known
 1.51 31-Aug-1998  cgd kill the last remnants of __BROKEN_INDIRECT_CONFIG. (only the pica port
used it, and it's non-working and apparently slated for replacement.)
 1.50 09-Aug-1998  wrstuden Oops. We do still need to set t_dev in the first open part of zsopen,
so we get ttyXX vs cuaXX right. Leave the initialization in attach.
 1.49 09-Aug-1998  wrstuden Initialize the struct tty's t_dev field at attach rather than first open.
The attach routine calls zsparam if we're setting up the console, and
zsparam needs this field to tell which zstty to set up. Otherwise, we
set up zstty0 even if it's not the console!
 1.48 30-Mar-1998  mycroft Eliminate cs_heldchar. It is not necessary in my version of the driver.
 1.47 22-Mar-1998  mycroft Move the code to wait for carrier on a tty into a common function, since it
depends only on device-independent state bits.
Implement SunOS-style `dialout' devices.
 1.46 21-Mar-1998  mycroft Fix pasto.
 1.45 21-Mar-1998  mycroft Replace TS_WOPEN with t_wopen, per mail on tech-kern.
 1.44 22-Feb-1998  mycroft Fix bonehead error in previous change.
 1.43 19-Feb-1998  mycroft Similar changes to com driver:
Arrange to call com_break() and com_modem() at splserial().
It's simpler this way. Really.
 1.42 12-Jan-1998  thorpej Adjust for config changes.
 1.41 12-Nov-1997  pk Use a 1-character queue so polled console output can be deferred if
regular I/O has been scheduled.
 1.40 03-Nov-1997  mycroft Actually use TIOCFLAG_CDTRCTS.
 1.39 03-Nov-1997  mycroft Always leave DCD_IE and CTS_IE on for now. Needs more work in zsparam() to
make the optimization actually work right.
 1.38 03-Nov-1997  mycroft Leave the console running with or without DDB.
 1.37 03-Nov-1997  mycroft Slight optimization in soft input routine.
 1.36 03-Nov-1997  mycroft Set the ring size back to 2k.
 1.35 03-Nov-1997  mycroft Bug fixes:
* Carrier detect (TS_CARR_ON) is based on the actual DCD bit, even if it's
being ignored.
* Set TS_WOPEN early on in zsopen().
* Don't disable interrupts on the console during close if we have DDB.

Inert changes:
* Don't handle ZS_HWFLAG_NO_DCD here; the frontend does it.
* Deprecate `register'.
* Use SET(), CLR(), and ISSET().

More performance changes:
* Rototill receive handling; use a backpressure mechanism to prevent livelock.
* Output silo/ibuf overflow warnings at most once per minute, from a callout.
* When we exhaust the current transmit run, turn off transmit interrupts in
zstty_txint(), so we're fairly sure we don't get another one.
 1.34 03-Nov-1997  gwr Fix serial console support (did not turn on CLOCAL).
 1.33 02-Nov-1997  mycroft Rearrange *param() slightly to eliminate a spl.
Also fix another comment regarding DTR.
 1.32 02-Nov-1997  mycroft Add another splserial()/splzs().
 1.31 02-Nov-1997  mycroft Minimize some spl regions slightly.
 1.30 02-Nov-1997  mycroft If we lose HFC, assert RTS.
 1.29 02-Nov-1997  mycroft Set the state of DCD_IE and CTS_IE based on what's in rr0_mask.
 1.28 01-Nov-1997  mycroft Correct a comment regarding our behaviour with DTR.
 1.27 01-Nov-1997  mycroft Fix minor omission; write back reg 1 earlier in zsopen().
 1.26 01-Nov-1997  mycroft Need some additional splzs() in zsopen(), and nuke one that's no longer
needed.
 1.25 01-Nov-1997  mycroft Nuke the special case of heldchange for reg 5. We don't use it for flow
control any more, and the speed of changing DTR isn't really an issue. Also,
the old code created a bug where zsparam() might have failed to set some
registers.
 1.24 01-Nov-1997  mycroft Yet more changes imported from com driver:
Change the interface to zs_hwiflow(); just have it use zst_rx_blocked.
Make zs_modem() a tiny bit faster.
Do RTS updates immediately; do not allow them to be held.
 1.23 01-Nov-1997  mycroft Make zst_tba a u_char *.
 1.22 01-Nov-1997  mycroft More changes taken from com driver:
Stop output as fast as possible when DCD is deasserted.
Do *not* automatically drop DTR when DCD is deasserted.
Only check for rr0 bits that we care about (DTR and DCD).
 1.21 01-Nov-1997  mycroft GC some unused bits.
Also, part of the previous was copied from the com driver, so DTRT.
 1.20 01-Nov-1997  mycroft Rearrange open sequence to make sure we catch all line status changes.
Make sure we turn on DTR and/or RTS as appropriate during open.
Rearrange close sequence so the tty is flushed before turning off interrupts.
Deal with `softcar' and the console device by silently asserting CLOCAL and
|HUPCL, as in com driver.
Do *not* fiddle with DTR when changing the line speed.
Make sure we update the tty's carrier status when CLOCAL or MDMBUF is changed.
Only change rr1 when we actually need to turn on or off TIE.
 1.19 17-Oct-1997  gwr branches: 1.19.2;
Move the ttychars() call below the if-not-raw block.
(from Bill Studenmund)
 1.18 07-Aug-1997  scottr spltty() does not drop the SPL; use splx() instead.
 1.17 17-Jul-1997  jtk branches: 1.17.2;
use locator defines in "locators.h" to index cf_loc[]
 1.16 19-May-1997  mrg KNF.
 1.15 24-Feb-1997  gwr Tweak the KGDB glue slightly - do the printf here.
 1.14 17-Dec-1996  gwr branches: 1.14.4;
New version of the z8530 driver that should permit the mac68k port
to use this instead of its own. Also fix warnings, etc.
 1.13 16-Oct-1996  gwr Correct a problem with CRTSCTS flow control where output may fail to
restart if we get multiple status interrupts before the softintr()
routine gets a chance to run. The fix is to determine and accumulate
status line changes at the H/W interrupt level, and then check and zero
the accumulated changes when the softint() finally runs. Many thanks
to Bill Studenmund <wrstuden@loki.stanford.edu> for finding and fixing.
 1.12 13-Oct-1996  christos backout kprintf changes
 1.11 10-Oct-1996  christos - printf -> kprintf, sprintf -> ksprintf
 1.10 02-Sep-1996  mycroft tty stop functions really should return void, not int, and certainly not both.
 1.9 13-Jun-1996  gwr Add tty_attach(), and fix a type mismatch.
 1.8 17-May-1996  gwr branches: 1.8.4;
New version that handles hardware flow-control (CRTSCTS) at the input
to the ring (or silo). This eliminates ring overrun with crtscts.
Also handle deferred register changes earlier, and misc. cleanup.
Give credit to: Bill Studenmund and Ian Dall (Thanks!)
 1.7 17-May-1996  gwr Rename cs_pclk_div16 to cs_brg_clk to clarify the fact that the
Baud Rate Generator (BRG) clock is not necessarily PCLK/16.
 1.6 10-Apr-1996  gwr Make the ring size configurable in the tty driver.
Make the pseudo-interrupt functions return void.
Call the tty layer at spltty (to be safe).
 1.5 18-Mar-1996  gwr Fix two bugs pointed out by Leo Weppelman:
(1) Did not initialize cs->cs_rr0 anywhere
(2) Have to read rr1 before the data it applies to
 1.4 17-Mar-1996  thorpej New device attachment scheme:

- split softc size and match/attach out from cfdriver into
a new struct cfattach.

- new "attach" directive for files.*. May specify the name of
the cfattach structure, so that devices may be easily attached
to parents with different autoconfiguration semantics.
 1.3 19-Feb-1996  gwr Fix two bugs found by Bill Studenmund:
Driver can not use tp->t_sc for its own purposes
Attach should take the unit number from _dev.dv_unit
 1.2 30-Jan-1996  gwr Eliminate remaining direct references to the z8530 chip
to allow the MD access functions to do delays, etc.
 1.1 24-Jan-1996  gwr Reorganized, machine-independent z8530 driver, based on the sparc/sun3 zs.
Uses autoconfig to attach keyboard, mouse, or tty. (See z8530.doc)
 1.8.4.2 13-Jun-1996  gwr Pull up version 1.9 (fix a type mismatch).
 1.8.4.1 03-Jun-1996  gwr Add tty_attach(tp);
 1.14.4.1 12-Mar-1997  is Merge in changes from Trunk
 1.17.2.1 23-Aug-1997  thorpej Update marc-pcmcia branch from trunk.
 1.19.2.7 01-Feb-1999  cgd revert pullup of rev 1.53. (wrstuden)
 1.19.2.6 25-Nov-1998  cgd pull up rev 1.53 from trunk (wrstuden)
 1.19.2.5 28-Sep-1998  cgd pull up revs 1.49 and 1.50 from trunk (wrstuden).
 1.19.2.4 08-May-1998  mycroft Pull up 1.48, per request of mycroft.
 1.19.2.3 05-May-1998  mycroft Pull up 1.43-1.44, per request of scottr.
 1.19.2.2 14-Nov-1997  mellon Pull rev 1.41 up from trunk (pk)
 1.19.2.1 04-Nov-1997  mellon Pull rev 1.20 through 1.40 up from trunk (mycroft)
 1.59.2.2 20-Jan-2000  he Pull up revisions 1.61-1.62 (requested by jonathan):
Fix TIMEVAL/TIMESPEC botches and update to the -05 draft version
of the PPS-API specification.
 1.59.2.1 23-Apr-1999  perry branches: 1.59.2.1.2;
pullup 1.59->1.60 (pk)
 1.59.2.1.2.1 21-Jun-1999  thorpej Sync w/ -current.
 1.60.2.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.61.4.1 15-Nov-1999  fvdl Sync with -current
 1.61.2.4 27-Mar-2001  bouyer Sync with HEAD.
 1.61.2.3 12-Mar-2001  bouyer Sync with HEAD.
 1.61.2.2 22-Nov-2000  bouyer Sync with HEAD.
 1.61.2.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.67.4.1 16-Mar-2001  he Pull up revision 1.74 (requested by tsutsui):
Add some delay in zstty_attach() to wait for previous console
output to complete before hardware initialization. Should fix
missing ``\r'' after zstty attach on serial console.
 1.72.2.8 07-Jan-2003  thorpej Sync with HEAD.
 1.72.2.7 11-Nov-2002  nathanw Catch up to -current
 1.72.2.6 18-Oct-2002  nathanw Catch up to -current.
 1.72.2.5 17-Sep-2002  nathanw Catch up to -current.
 1.72.2.4 01-Apr-2002  nathanw Catch up to -current.
(CVS: It's not just a program. It's an adventure!)
 1.72.2.3 14-Nov-2001  nathanw Catch up to -current.
 1.72.2.2 21-Jun-2001  nathanw Catch up to -current.
 1.72.2.1 09-Apr-2001  nathanw Catch up with -current.
 1.77.4.6 13-Oct-2001  fvdl Revert the t_dev -> t_devvp change in struct tty. The way that tty
structs are currently used (especially by console ttys) aren't
ready for it, and this will require quite a few changes.
 1.77.4.5 11-Oct-2001  fvdl Work around some evil, like directly calling interrupt functions
from the attach path, which devvp didn't like because of incompletely
inited tty structs.

All the struct tty init stuff should really be deferred to the first
open for all drivers; the structures are idle before then and
shouldn't be referenced.
 1.77.4.4 11-Oct-2001  fvdl Catch up with -current. Fix some bogons in the sparc64 kbd/ms
attach code. cd18xx conversion provided by mrg.
 1.77.4.3 10-Oct-2001  fvdl Convert all remaining devices.
 1.77.4.2 26-Sep-2001  fvdl * add a VCLONED vnode flag that indicates a vnode representing a cloned
device.
* rename REVOKEALL to REVOKEALIAS, and add a REVOKECLONE flag, to pass
to VOP_REVOKE
* the revoke system call will revoke all aliases, as before, but not the
clones
* vdevgone is called when detaching a device, so make it use REVOKECLONE
to get rid of all clones as well
* clean up all uses of VOP_OPEN wrt. locking.
* add a few VOPS to spec_vnops that need to do something when it's a
clone vnode (access and getattr)
* add a copy of the vnode vattr structure of the original 'master' vnode
to the specinfo of a cloned vnode. could possibly redirect getattr to
the 'master' vnode, but this has issues with revoke
* add a vdev_reassignvp function that disassociates a vnode from its
original device, and reassociates it with the specified dev_t. to be
used by cloning devices only, in case a new minor is allocated.
* change all direct references in drivers to v_devcookie and v_rdev
to vdev_privdata(vp) and vdev_rdev(vp). for diagnostic purposes
when debugging race conditions that still exist wrt. locking and
revoking vnodes.
* make the locking state of a vnode consistent when passed to
d_open and d_close (unlocked). locked would be better, but has
some deadlock issues
 1.77.4.1 07-Sep-2001  thorpej Commit my "devvp" changes to the thorpej-devvp branch. This
replaces the use of dev_t in most places with a struct vnode *.

This will form the basic infrastructure for real cloning device
support (besides being architecurally cleaner -- it'll be good
to get away from using numbers to represent objects).
 1.77.2.3 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.77.2.2 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.77.2.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.79.4.1 16-May-2002  gehenna Add the character device switch.
Replace the access to devsw table with calling devsw API.
 1.91.2.7 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.91.2.6 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.91.2.5 04-Feb-2005  skrll Sync with HEAD.
 1.91.2.4 21-Sep-2004  skrll Fix the sync with head I botched.
 1.91.2.3 18-Sep-2004  skrll Sync with HEAD.
 1.91.2.2 26-Aug-2004  skrll Adapt to branch.

sparc64 GENERIC compiles.
 1.91.2.1 03-Aug-2004  skrll Sync with HEAD
 1.95.6.2 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.95.6.1 12-Feb-2005  yamt sync with head.
 1.95.4.1 29-Apr-2005  kent sync with -current
 1.99.2.7 17-Mar-2008  yamt sync with head.
 1.99.2.6 21-Jan-2008  yamt sync with head
 1.99.2.5 07-Dec-2007  yamt sync with head
 1.99.2.4 15-Nov-2007  yamt sync with head.
 1.99.2.3 03-Sep-2007  yamt sync with head.
 1.99.2.2 30-Dec-2006  yamt sync with head.
 1.99.2.1 21-Jun-2006  yamt sync with head.
 1.102.8.5 11-Aug-2006  yamt sync with head
 1.102.8.4 26-Jun-2006  yamt sync with head.
 1.102.8.3 24-May-2006  yamt sync with head.
 1.102.8.2 01-Apr-2006  yamt sync with head.
 1.102.8.1 13-Mar-2006  yamt sync with head.
 1.102.6.4 01-Jun-2006  kardel Sync with head.
 1.102.6.3 10-May-2006  kardel fix compilation for new PPS implementation
 1.102.6.2 22-Apr-2006  simonb Sync with head.
 1.102.6.1 04-Feb-2006  simonb Adapt for timecounters and newer PPS API.
 1.102.4.1 09-Sep-2006  rpaulo sync with head
 1.103.4.2 24-May-2006  tron Merge 2006-05-24 NetBSD-current into the "peter-altq" branch.
 1.103.4.1 31-Mar-2006  tron Merge 2006-03-31 NetBSD-current into the "peter-altq" branch.
 1.103.2.4 11-May-2006  elad sync with head
 1.103.2.3 19-Apr-2006  elad sync with head.
 1.103.2.2 10-Mar-2006  elad generic_authorize() -> kauth_authorize_generic().
 1.103.2.1 08-Mar-2006  elad Adapt to kernel authorization KPI.
 1.107.2.1 19-Jun-2006  chap Sync with head.
 1.110.6.1 22-Oct-2006  yamt sync with head
 1.110.4.1 18-Nov-2006  ad Sync with head.
 1.112.4.1 12-Mar-2007  rmind Sync with HEAD.
 1.113.4.1 11-Jul-2007  mjf Sync with head.
 1.113.2.3 19-Oct-2007  ad Replace the tty locks with a global tty_lock.
 1.113.2.2 15-Jul-2007  ad Get pmax working.
 1.113.2.1 15-Jul-2007  ad Sync with head.
 1.114.14.4 18-Feb-2008  mjf Sync with HEAD.
 1.114.14.3 27-Dec-2007  mjf Sync with HEAD.
 1.114.14.2 08-Dec-2007  mjf Sync with HEAD.
 1.114.14.1 19-Nov-2007  mjf Sync with HEAD.
 1.114.12.2 21-Nov-2007  bouyer Sync with HEAD
 1.114.12.1 13-Nov-2007  bouyer Sync with HEAD
 1.114.8.3 23-Mar-2008  matt sync with HEAD
 1.114.8.2 09-Jan-2008  matt sync with HEAD
 1.114.8.1 08-Nov-2007  matt sync with -HEAD
 1.114.6.2 21-Nov-2007  joerg Sync with HEAD.
 1.114.6.1 11-Nov-2007  joerg Sync with HEAD.
 1.117.6.2 23-Jan-2008  bouyer Sync with HEAD.
 1.117.6.1 02-Jan-2008  bouyer Sync with HEAD
 1.117.2.1 26-Dec-2007  ad Sync with head.
 1.120.6.2 02-Jun-2008  mjf Sync with HEAD.
 1.120.6.1 03-Apr-2008  mjf Sync with HEAD.
 1.120.2.1 24-Mar-2008  keiichi sync with head.
 1.122.2.1 18-May-2008  yamt sync with head.
 1.123.16.2 23-Jul-2009  jym Sync with HEAD.
 1.123.16.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.123.12.1 16-Jan-2011  bouyer Pull up following revision(s) (requested by mrg in ticket #1526):
sys/arch/sparc/dev/zs.c: revision 1.115
sys/dev/ic/z8530sc.h: revision 1.26
sys/dev/ic/z8530sc.c: revision 1.30
sys/dev/ic/z8530tty.c: revision 1.127
sys/arch/sparc64/dev/zs.c: revision 1.68
add two new functions for z8530tty: zs_chan_lock() and zs_chan_unlock(),
and use them instead of various spl's in the zs.c's.
reviewed by ad and martin.
 1.123.10.1 28-Apr-2009  skrll Sync with HEAD.
 1.123.2.3 20-Jun-2009  yamt sync with head
 1.123.2.2 16-May-2009  yamt sync with head
 1.123.2.1 04-May-2009  yamt sync with head.
 1.127.6.1 06-Jun-2011  jruoho Sync with HEAD.
 1.127.4.1 31-May-2011  rmind sync with head
 1.128.18.1 18-May-2014  rmind sync with head
 1.128.14.2 03-Dec-2017  jdolecek update from HEAD
 1.128.14.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.128.4.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.129.2.1 10-Aug-2014  tls Rebase.
 1.131.12.1 06-Nov-2017  snj Pull up following revision(s) (requested by martin in ticket #338):
sys/arch/sparc64/dev/sab.c: revision 1.55
sys/dev/ic/com.c: revision 1.345
sys/dev/ic/z8530tty.c: revision 1.132
sys/dev/sun/sunkbd.c: revision 1.30
sys/dev/sun/sunms.c: revision 1.33
sys/sys/tty.h: revision 1.94
As discussed on tech-kern: define a new tty internal state flag: TS_KERN_ONLY
Implement it in a few tty drivers. If this flag is set, the underlying
hardware is used by another driver and userland has no right to open
it. A few uses will appear soon in sys/dev/sun/sun{kbd,ms}.c.
--
PR port-sparc64/52622: mark the parent device as TS_KERN_ONLY,
so userland will not touch it (and change serial params w/o our
control).
 1.132.4.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.6 17-Dec-1996  gwr New version of the z8530 driver that should permit the mac68k port
to use this instead of its own. Also fix warnings, etc.
 1.5 23-Oct-1996  gwr Add prototypes, and a few more fields now used in z8530tty.c
 1.4 16-Oct-1996  gwr Replace the field cs_rr0_new with cs_rr0_delta (keep changes instead).
 1.3 17-May-1996  gwr Rename cs_pclk_div16 to cs_brg_clk to clarify the fact that the
Baud Rate Generator (BRG) clock is not necessarily PCLK/16.
Also fix up spacing.
 1.2 10-Apr-1996  gwr Make the ring size configurable in the tty driver.
Make the pseudo-interrupt functions return void.
Call the tty layer at spltty (to be safe).
 1.1 24-Jan-1996  gwr Reorganized, machine-independent z8530 driver, based on the sparc/sun3 zs.
Uses autoconfig to attach keyboard, mouse, or tty. (See z8530.doc)
 1.3 31-Jan-2012  hauke Employ the two free 16 bit timers of the Hurdler Centronics Parallel
Interface card's Z8536 CIO for Timecounter support.

Builds, should work, but not testable yet because of pmap breakage.
 1.2 23-May-2008  hauke branches: 1.2.2; 1.2.4; 1.2.8; 1.2.22; 1.2.40; 1.2.44;
Fix NetBSD version tag.
 1.1 22-May-2008  hauke Added driver for the Creative Systems Inc. Hurdler CPI parallel printer card.
Timecounter support for the Z8536 counters A + B is not complete, yet.

Reviewed by Martin Husemann.
 1.2.44.1 18-Feb-2012  mrg merge to -current.
 1.2.40.1 17-Apr-2012  yamt sync with head
 1.2.22.2 04-May-2009  yamt sync with head.
 1.2.22.1 23-May-2008  yamt file z8536reg.h was added on branch yamt-nfs-mp on 2009-05-04 08:12:45 +0000
 1.2.8.2 23-Jun-2008  wrstuden Add files to branch that were added on -current.

After this, all that's left of update is to merge some changes
that had conflicts.
 1.2.8.1 23-May-2008  wrstuden file z8536reg.h was added on branch wrstuden-revivesa on 2008-06-23 05:02:13 +0000
 1.2.4.2 04-Jun-2008  yamt sync with head
 1.2.4.1 23-May-2008  yamt file z8536reg.h was added on branch yamt-pf42 on 2008-06-04 02:05:11 +0000
 1.2.2.2 02-Jun-2008  mjf Sync with HEAD.
 1.2.2.1 23-May-2008  mjf file z8536reg.h was added on branch mjf-devfs2 on 2008-06-02 13:23:28 +0000

RSS XML Feed