Home | History | Annotate | Download | only in pci
History log of /src/sys/dev/pci/if_wpi.c
RevisionDateAuthorComments
 1.92  05-Dec-2021  msaitoh s/persistant/persistent/ in comment.
 1.91  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.90  05-Feb-2021  christos branches: 1.90.4;
PR/55975: Riccardo Mottola: Don't try to lock a mutex from an interrupt context.
 1.89  20-Mar-2020  sevan branches: 1.89.4;
Apply the same change as for if_iwi.c r1.114 here.

This driver sleeps during wpi_media_change(), and thus requires an adaptive
mutex for the media lock.
 1.88  30-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  24-Jun-2019  jakllsch Put back correct recieve ring allocation size which was lost just over
five years ago mae culpa.

Found by msaitoh@

Should fix PR kern/54320 once pulled up.
 1.85  22-Dec-2018  maxv Replace: M_COPY_PKTHDR -> m_copy_pkthdr. No functional change, since the
former is a macro to the latter.
 1.84  09-Dec-2018  jdolecek use pci_intr_establish_xname() everywhere
 1.83  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.82  20-Aug-2018  riastradh Suspend the getrfkill thread while we're suspended.

Otherwise it tries to futz with device registers, which doesn't work,
and who knows, maybe is bad.
 1.81  20-Aug-2018  riastradh What we have created, we must destroy.
 1.80  26-Jun-2018  msaitoh branches: 1.80.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.79  23-Oct-2017  msaitoh branches: 1.79.2;
If if_initialize() failed in the attach function, free resources and return.
 1.78  23-May-2017  ozaki-r branches: 1.78.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.77  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.76  02-Feb-2017  jakllsch wpi(4): use MSI if available.
 1.75  08-Dec-2016  ozaki-r branches: 1.75.2;
Apply deferred if_start framework

if_schedule_deferred_start checks if the if_snd queue contains packets,
so drivers don't need to check it by themselves.
 1.74  10-Jun-2016  ozaki-r branches: 1.74.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.73  26-May-2016  ozaki-r Introduce M_CLEARCTX and use it instead of open-coding rcvif

No functional change.
 1.72  26-May-2016  ozaki-r Use M_GETCTX

No functional change.
 1.71  09-Jan-2015  bouyer Take sc_rsw_mtx before calling wpi_getrfkill() from wpi_init(),
Problem reported and patch tested by chris at chriswareham.net
 1.70  06-Jan-2015  bouyer As proposed on tech-net@, introduce a new switch type, PSWITCH_TYPE_RADIO,
to be used to report to userland hardware radio switch changes.
powerd(8) will call a "radio_button" script to handle the event.
This script can e.g. start or stop wpa_supplicant.
Update wpi(4) to report PSWITCH_TYPE_RADIO events to sysmon.
 1.69  19-Dec-2014  bouyer Consistently take the interface down when the radio swicth is off.
 1.68  08-Aug-2014  jmcneill branches: 1.68.2; 1.68.4;
wpi_fix_channel hack no longer needed with recent scanning changes
 1.67  07-Aug-2014  jmcneill Scan one channel at a time instead of trying to do them all at once and
trying to outsmart the ieee80211 state machine.
 1.66  07-Aug-2014  jmcneill scanning fixes
 1.65  07-Aug-2014  jmcneill simplify wpi_rx_intr rbuf handling and add some more bus_dmamap_sync; fixes stalls when downloading large files for me
 1.64  05-Aug-2014  jmcneill bus_dmamap_sync for rx descriptors too, derived from openbsd driver
 1.63  05-Aug-2014  jmcneill Sprinkle bus_dmamap_sync to make this work on my Thinkpad T61 (amd64)
with 4GB RAM.
 1.62  05-Jul-2014  jakllsch Use M_ZERO. From OpenBSD if_wpi.c 1.53.
 1.61  05-Jul-2014  jakllsch Reduce wpi(4) diff to OpenBSD circa September 2007; mostly by following KNF.
The only functional changes in this commit are some %d to %u debugging printf
format specifier adjustments so as to match the OpenBSD code.
 1.60  02-Jul-2014  jakllsch No need to duplicate the members of the wpi_cmd_data structure within
the wpi_scan_hdr structure when we can just put the wpi_cmd_data
structure within the wpi_scan_hdr structure.

This also brings our if_wpireg.h mostly in line with OpenBSD's 1.18.
 1.59  16-Jun-2014  jakllsch wpi(4): mostly cosmetic changes to source, also a little bit of diff
reduction relative to OpenBSD as of late 2007.
 1.58  29-Mar-2014  christos branches: 1.58.2;
make pci_intr_string and eisa_intr_string take a buffer and a length
instead of relying in local static storage.
 1.57  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.56  30-Mar-2013  christos branches: 1.56.4;
replace function with macro
 1.55  30-Mar-2013  christos remove trailing whitespace
 1.54  25-Nov-2012  riastradh Rework firmware reference counting and error messages in wpi(4).

. Clarify the shared firmware abstraction in wpi_cached_firmware
and its new sibling wpi_release_firmware.
. Fix typo in wpa_cache_firmware error branch leading to free NULL.
. Fix leak in wpi_load_firmware error branch.
. Sprinkle some kasserts to executably document invariants.
. A little KNF here and there.

Based on a patch from dh in PR kern/44144.
 1.53  04-Aug-2012  riastradh branches: 1.53.2;
Fix error branch in wpi(4) firmware loading.

Fixes panic if firmware is not available.
 1.52  02-Jun-2012  dsl 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.51  12-May-2012  khorben No longer wrongly advertise ad-hoc (IBSS) mode as being supported.

Fixes kern/46101

No objection from current-users@
 1.50  30-Jan-2012  drochner branches: 1.50.2;
Use pci_aprint_devinfo(9) instead of pci_devinfo+aprint_{normal,naive}
where it looks straightforward, and pci_aprint_devinfo_fancy in a few
others where drivers want to supply their own device names instead
of the pcidevs generated one. More complicated cases, where names
are composed at runtime, are left alone for now. It certainly makes
sense to simplify the drivers here rather than inventing a catch-all API.
This should serve as as example for new drivers, and also ensure
consistent output in the AB_QUIET ("boot -q") case. Also, it avoids
excessive stack usage where drivers attach child devices because the
buffer for the device name is not kept on the local stack anymore.
 1.49  02-Apr-2011  mbalmer branches: 1.49.4; 1.49.8;
Fix misplaced parenthesis. From henning.petersen@t-online.de, thanks.
 1.48  15-Nov-2010  uebayasi branches: 1.48.2;
tsleep needs sys/proc.h.
 1.47  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.46  24-Feb-2010  dyoung branches: 1.46.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.45  19-Jan-2010  pooka branches: 1.45.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.44  08-Jan-2010  dyoung Expand PMF_FN_* macros.
 1.43  05-Sep-2009  tsutsui Invert logic around nested pmf(9) registrations for readability.
 1.42  06-May-2009  cegger struct cfdata * -> cfdata_t, no functional changes intended.
 1.41  12-Nov-2008  joerg branches: 1.41.4;
Cache wpi firmware in memory, free it only on invalid content or when
the last user is detached. This stops wpi from accessing the disk on
resume.
 1.40  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.39  02-Jul-2008  cube branches: 1.39.2; 1.39.4; 1.39.6;
Protect private mbuf external data storage allocater with a mutex, as it
was done in nfe(4), sk(4) and msk(4). And maybe some others.
Confirmed to fix the usual issue of data corruption by Jared McNeill.
 1.38  28-Apr-2008  drochner branches: 1.38.2; 1.38.4;
fix error handling after m_pullup()
 1.37  11-Mar-2008  dyoung branches: 1.37.2; 1.37.4;
pci_disable_retry() is now a no-op, so don't call it any more.
 1.36  29-Feb-2008  dyoung Use PMF_FN_ARGS, PMF_FN_PROTO.
 1.35  19-Jan-2008  simonb branches: 1.35.2; 1.35.6;
Use M_80211_NODE as malloc type for a 80211 node as rest of net80211
code does, instead of M_DEVBUF. Fixes panics if KMEMSTATS are enabled.
Also use M_ZERO instead of memset on malloc()'s results.
 1.34  09-Jan-2008  degroote Add some sysctl to retrieve the radio state (and the debug level).

While here, fixe the return value in case where radio is off (suggested by
joerg@).
 1.33  09-Dec-2007  jmcneill branches: 1.33.2;
Merge jmcneill-pm branch.
 1.32  01-Dec-2007  jmcneill branches: 1.32.2; 1.32.4;
Prefix the regulatory domain and address output with the device name.
 1.31  28-Nov-2007  degroote In wpi_init, check for the status of radio switch and print a useful message
in this case.
 1.30  23-Nov-2007  plunky when using CFATTACH_DECL_NEW(), we must remember to record the
device_t if we wish to use it.

sc->sc_dev = self;
 1.29  23-Nov-2007  joerg If memory for the firmware image couldn't be allocated, print only
one error message.
 1.28  16-Nov-2007  degroote Use device_t instead of struct device* and use associated functions
Use callout_setfunc and callout_scheduler instead of callout_reset

No functionnal change expected
 1.27  07-Nov-2007  ad Merge from vmlocking:

- pool_cache changes.
- Debugger/procfs locking fixes.
- Other minor changes.
 1.26  21-Oct-2007  degroote branches: 1.26.2;
802.11 header may have different sizes. Deals correctly with this.
 1.25  19-Oct-2007  ad machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.24  02-Sep-2007  degroote branches: 1.24.4;
The service queue isn't used anymore so don't allocate it.
It saves a bit of memory and reduces diff with other BSD.
 1.23  02-Sep-2007  degroote Fix scanning code for wpi based on the iwi code.

Keep track of the status of the scan.
On a transition IEEE80211_S_SCAN -> IEEE80211_S_SCAN, don't stop the previous
scan, finish the current scan.
When we receive some frames in the IEEE80211_S_SCAN state, set current_channel
based on the value advertised in beacons or probre reponse.

Moreover, it fixes WPA issues for me.
 1.22  01-Sep-2007  dyoung Instead of IF_POLL()'ing and IF_DEQUEUE()'ing, just IF_DEQUEUE().
 1.21  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.20  26-Aug-2007  dyoung branches: 1.20.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.19  15-Aug-2007  degroote Fix possible "packet corruption" which appears on high load
 1.18  04-Aug-2007  degroote branches: 1.18.2;
Call wpi_stop at the beginning of wpi_init so we are sure that wpi is really
stopped (in particular interrupt are disabled).
 1.17  18-Jul-2007  degroote branches: 1.17.4;
change firmware loading code to adopt the new 2.14.4 firmware layout (from
OpenBSD).

While here, remove some dead code I added when I ported the code from OpenBSD.


IMPORTANT : You must download the 2.14.4 firmware or update your
sysutils/wpi-firmware2 to the last revision (2.14.4) or the driver will stop
working.
 1.16  11-Jul-2007  degroote branches: 1.16.2;
Fix more build issues on amd64 (exposed by WPI_DEBUG)
 1.15  11-Jul-2007  xtraeme Use %zu to print a size_t, fixes the build on amd64.
 1.14  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.13  09-Jul-2007  degroote Fix some conflicts in my previous commit.
Sorry for the bad commit

Thanks to dogcow@ for the report.
 1.12  09-Jul-2007  degroote Sync the driver with the OpenBSD one

1/ Update the driver to use the new firmware images from Intel (2.14.3.)
2/ Read the list of supported channels from the EEPROM instead of having
it hard-coded in the driver.
3/ Limit output power to what is specified in EEPROM.
4/ Decrease output power for highest OFDM rates to reduce distortion.
5/ Automatically adjust output power to temperature changes for increased
throughput and range.
6/ Attach the adapter's onboard thermal sensor to the sensor framework.
7/ Replace 'magic' fields in structures with their correct definitions.
8/ Rewrite the firmware load in order to reduce the diff with OpenBSD one

NOTE2: you must install sysutils/wpi-firmware2 in order to use the new
driver

NOTE2: if you are using a channel not allowed by the regulatory domain
of your adapter, you will no longer be able to associate.

Thanks a lot for his hard work to damien@OpenBSD.org
 1.11  04-Jul-2007  pooka wsize is size_t = unsigned and should be printed with %zu instead
of %zd. cosmetics for PR 36591 by khorben.
 1.10  18-Jun-2007  degroote Add a workaround in the case where we have low number of rbuf.
It seems to fix problem of frozen network with wpi.

ok by @joerg.
 1.9  04-Mar-2007  christos branches: 1.9.2; 1.9.4;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.8  25-Jan-2007  njoly branches: 1.8.2;
Fix compilation on platforms where sizeof int/size_t differs.
Successfully tested on amd64.

ok by tron@
 1.7  13-Jan-2007  degroote Sync the wpi driver with the openbsd one. Thanks to Jean-Baptiste
Campesato for his work.
Fix PR/34463


ok dyoung@ joerg@
 1.6  16-Nov-2006  christos branches: 1.6.2; 1.6.4; 1.6.6;
__unused removal on arguments; approved by core.
 1.5  31-Oct-2006  joerg Move AMRR code out of wpi(4) and ural(4) into net80211 itself.
From OpenBSD.
 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  24-Sep-2006  jmcneill Add "name" parameter to powerhook_establish, to aid debugging. No objections
on tech-kern@
 1.2  13-Aug-2006  oster branches: 1.2.2; 1.2.4; 1.2.6; 1.2.8;
Apply a change from damien in OpenBSD: fix a use-after-free (read)
of a mbuf in wpi_tx_intr().
 1.1  13-Aug-2006  simonb Add a port of the OpenBSD Intel 3945ABG wpi(4) wireless driver, by
Jean-Baptiste Campesato.

From PR kern/33778.
 1.2.8.2  10-Dec-2006  yamt sync with head.
 1.2.8.1  22-Oct-2006  yamt sync with head
 1.2.6.2  09-Sep-2006  rpaulo sync with head
 1.2.6.1  13-Aug-2006  rpaulo file if_wpi.c was added on branch rpaulo-netinet-merge-pcb on 2006-09-09 02:52:18 +0000
 1.2.4.2  01-Feb-2007  ad Sync with head.
 1.2.4.1  18-Nov-2006  ad Sync with head.
 1.2.2.2  03-Sep-2006  yamt sync with head.
 1.2.2.1  13-Aug-2006  yamt file if_wpi.c was added on branch yamt-pdpolicy on 2006-09-03 15:24:22 +0000
 1.6.6.2  30-Sep-2007  wrstuden Catch up on netbsd-4 as of a few days ago.
 1.6.6.1  03-Sep-2007  wrstuden Sync w/ NetBSD-4-RC_1
 1.6.4.9  17-Mar-2008  yamt sync with head.
 1.6.4.8  21-Jan-2008  yamt sync with head
 1.6.4.7  07-Dec-2007  yamt sync with head
 1.6.4.6  15-Nov-2007  yamt sync with head.
 1.6.4.5  27-Oct-2007  yamt sync with head.
 1.6.4.4  03-Sep-2007  yamt sync with head.
 1.6.4.3  26-Feb-2007  yamt sync with head.
 1.6.4.2  30-Dec-2006  yamt sync with head.
 1.6.4.1  16-Nov-2006  yamt file if_wpi.c was added on branch yamt-lazymbuf on 2006-12-30 20:48:46 +0000
 1.6.2.3  27-Sep-2007  xtraeme Pull up following revision(s) (requested by degroote in ticket #860):
sys/dev/pci/if_wpivar.h: revision 1.7 (via patch)
sys/dev/pci/if_wpi.c: revision 1.18 (via patch)
sys/dev/pci/if_wpi.c: revision 1.19 (via patch)
sys/dev/pci/if_wpi.c: revision 1.23 (via patch)

Call wpi_stop at the beginning of wpi_init so we are sure that wpi is really
stopped (in particular interrupt are disabled).
Fix possible "packet corruption" which appears on high load
Fix scanning code for wpi based on the iwi code.
Keep track of the status of the scan.
On a transition IEEE80211_S_SCAN -> IEEE80211_S_SCAN, don't stop the previous
scan, finish the current scan.
When we receive some frames in the IEEE80211_S_SCAN state, set current_channel
based on the value advertised in beacons or probre reponse.
Moreover, it fixes WPA issues for me.
 1.6.2.2  27-Jul-2007  liamjfoy Pullup requested by degroote in ticket 795:
Rewrite of the rbuf management
Sync with the last OpenBSD driver
Use the last firmware available from Intel (2.4.14).
Use legal limitations and Tx regulation embedded in the eeprom.
Rewrite the way we handle the firmware.

Pullup the following revisions of this files
sys/dev/pci/if_wpi.c rev 1.7 1.8 1.10 1.12 1.13 1.15 1.16 1.17 via patch
sys/dev/pci/if_wpireg.h rev 1.3 1.4 1.5 via patch
sys/dev/pci/if_wpivar.h rev 1.3 1.5 1.6 via patch
 1.6.2.1  06-Jul-2007  liamjfoy Pull up following revision(s) (requested by pooka in ticket #756)
sys/dev/pci/if_wpi.c: revision 1.11

wsize is size_t = unsigned and should be printed with %zu instead
of %zd. cosmetics for PR 36591 by khorben.
 1.8.2.1  12-Mar-2007  rmind Sync with HEAD.
 1.9.4.1  11-Jul-2007  mjf Sync with head.
 1.9.2.7  23-Oct-2007  ad Sync with head.
 1.9.2.6  09-Oct-2007  ad Sync with head.
 1.9.2.5  01-Sep-2007  ad Update for pool_cache API changes.
 1.9.2.4  20-Aug-2007  ad Sync with HEAD.
 1.9.2.3  15-Jul-2007  ad Sync with head.
 1.9.2.2  15-Jul-2007  ad Sync with head.
 1.9.2.1  01-Jul-2007  ad Adapt to callout API change.
 1.16.2.2  03-Sep-2007  skrll Sync with HEAD.
 1.16.2.1  15-Aug-2007  skrll Sync with HEAD.
 1.17.4.15  08-Dec-2007  jmcneill Rename pnp(9) -> pmf(9), as requested by many.
 1.17.4.14  03-Dec-2007  joerg Sync with HEAD.
 1.17.4.13  01-Dec-2007  jmcneill Sync with HEAD.
 1.17.4.12  27-Nov-2007  joerg Sync with HEAD. amd64 Xen support needs testing.
 1.17.4.11  21-Nov-2007  joerg Sync with HEAD.
 1.17.4.10  11-Nov-2007  joerg Sync with HEAD.
 1.17.4.9  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.17.4.8  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.4.7  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.17.4.6  04-Sep-2007  degroote Convert wpi_power to use pci_net_generic_power.
With this, I can use the card after resume.
 1.17.4.5  03-Sep-2007  jmcneill Sync with HEAD.
 1.17.4.4  02-Sep-2007  jmcneill Sync with HEAD.
 1.17.4.3  16-Aug-2007  jmcneill Sync with HEAD.
 1.17.4.2  09-Aug-2007  jmcneill Sync with HEAD.
 1.17.4.1  03-Aug-2007  jmcneill Pull in power management changes from private branch.
 1.18.2.2  04-Aug-2007  degroote Call wpi_stop at the beginning of wpi_init so we are sure that wpi is really
stopped (in particular interrupt are disabled).
 1.18.2.1  04-Aug-2007  degroote file if_wpi.c was added on branch matt-mips64 on 2007-08-04 18:24:25 +0000
 1.20.2.4  23-Mar-2008  matt sync with HEAD
 1.20.2.3  09-Jan-2008  matt sync with HEAD
 1.20.2.2  08-Nov-2007  matt sync with -HEAD
 1.20.2.1  06-Nov-2007  matt sync with HEAD
 1.24.4.3  18-Nov-2007  bouyer Sync with HEAD
 1.24.4.2  13-Nov-2007  bouyer Sync with HEAD
 1.24.4.1  25-Oct-2007  bouyer Sync with HEAD.
 1.26.2.4  18-Feb-2008  mjf Sync with HEAD.
 1.26.2.3  27-Dec-2007  mjf Sync with HEAD.
 1.26.2.2  08-Dec-2007  mjf Sync with HEAD.
 1.26.2.1  19-Nov-2007  mjf Sync with HEAD.
 1.32.4.1  11-Dec-2007  yamt sync with head.
 1.32.2.1  26-Dec-2007  ad Sync with head.
 1.33.2.2  19-Jan-2008  bouyer Sync with HEAD
 1.33.2.1  10-Jan-2008  bouyer Sync with HEAD
 1.35.6.4  17-Jan-2009  mjf Sync with HEAD.
 1.35.6.3  02-Jul-2008  mjf Sync with HEAD.
 1.35.6.2  02-Jun-2008  mjf Sync with HEAD.
 1.35.6.1  03-Apr-2008  mjf Sync with HEAD.
 1.35.2.1  24-Mar-2008  keiichi sync with head.
 1.37.4.6  11-Aug-2010  yamt sync with head.
 1.37.4.5  11-Mar-2010  yamt sync with head
 1.37.4.4  16-Sep-2009  yamt sync with head
 1.37.4.3  16-May-2009  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.1  18-May-2008  yamt sync with head.
 1.38.4.1  03-Jul-2008  simonb Sync with head.
 1.38.2.1  18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.39.6.1  16-Nov-2008  snj Pull up following revision(s) (requested by joerg in ticket #62):
sys/dev/pci/if_wpivar.h: revision 1.13
sys/dev/pci/if_wpi.c: revision 1.41
Cache wpi firmware in memory, free it only on invalid content or when
the last user is detached. This stops wpi from accessing the disk on
resume.
 1.39.4.1  19-Jan-2009  skrll Sync with HEAD.
 1.39.2.1  13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.41.4.1  13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.45.2.1  30-Apr-2010  uebayasi Sync with HEAD.
 1.46.2.3  21-Apr-2011  rmind sync with head
 1.46.2.2  05-Mar-2011  rmind sync with head
 1.46.2.1  30-May-2010  rmind sync with head
 1.48.2.1  06-Jun-2011  jruoho Sync with HEAD.
 1.49.8.2  02-Jun-2012  mrg sync to latest -current.
 1.49.8.1  18-Feb-2012  mrg merge to -current.
 1.49.4.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.49.4.4  16-Jan-2013  yamt sync with (a bit old) head
 1.49.4.3  30-Oct-2012  yamt sync with head
 1.49.4.2  23-May-2012  yamt sync with head.
 1.49.4.1  17-Apr-2012  yamt sync with head
 1.50.2.4  08-Feb-2013  riz Pull up following revision(s) (requested by riastradh in ticket #784):
sys/dev/pci/if_wpi.c: revision 1.54
Rework firmware reference counting and error messages in wpi(4).
. Clarify the shared firmware abstraction in wpi_cached_firmware
and its new sibling wpi_release_firmware.
. Fix typo in wpa_cache_firmware error branch leading to free NULL.
. Fix leak in wpi_load_firmware error branch.
. Sprinkle some kasserts to executably document invariants.
. A little KNF here and there.
Based on a patch from dh in PR kern/44144.
 1.50.2.3  12-Aug-2012  martin Pull up following revision(s) (requested by riastradh in ticket #478):
sys/dev/pci/if_wpi.c: revision 1.53
Fix error branch in wpi(4) firmware loading.
Fixes panic if firmware is not available.
 1.50.2.2  22-May-2012  riz Pull up following revision(s) (requested by khorben in ticket #266):
sys/dev/pci/if_wpi.c: patch

Fix harmless typo which was previously pulled up.
 1.50.2.1  19-May-2012  riz Pull up following revision(s) (requested by khorben in ticket #266):
sys/dev/pci/if_wpi.c: revision 1.51
No longer wrongly advertise ad-hoc (IBSS) mode as being supported.
Fixes kern/46101
No objection from current-users@
 1.53.2.4  03-Dec-2017  jdolecek update from HEAD
 1.53.2.3  20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.53.2.2  23-Jun-2013  tls resync from head
 1.53.2.1  25-Feb-2013  tls resync with head
 1.56.4.1  18-May-2014  rmind sync with head
 1.58.2.1  10-Aug-2014  tls Rebase.
 1.68.4.5  28-Aug-2017  skrll Sync with HEAD
 1.68.4.4  05-Feb-2017  skrll Sync with HEAD
 1.68.4.3  09-Jul-2016  skrll Sync with HEAD
 1.68.4.2  29-May-2016  skrll Sync with HEAD
 1.68.4.1  06-Apr-2015  skrll Sync with HEAD
 1.68.2.2  12-Jan-2015  snj Pull up following revision(s) (requested by bouyer in ticket #415):
share/man/man9/sysmon_pswitch.9: revision 1.6
sys/dev/pci/if_wpi.c: revision 1.70, 1.71
sys/dev/pci/if_wpivar.h: revision 1.19
sys/dev/sysmon/sysmon_power.c: revision 1.49
sys/sys/power.h: revision 1.20
As proposed on tech-net@, introduce a new switch type, PSWITCH_TYPE_RADIO,
to be used to report to userland hardware radio switch changes.
powerd(8) will call a "radio_button" script to handle the event.
This script can e.g. start or stop wpa_supplicant.
Update wpi(4) to report PSWITCH_TYPE_RADIO events to sysmon.
--
Take sc_rsw_mtx before calling wpi_getrfkill() from wpi_init(),
Problem reported and patch tested by chris at chriswareham.net
 1.68.2.1  21-Dec-2014  snj Pull up following revision(s) (requested by bouyer in ticket #338):
sys/dev/pci/if_wpi.c: revision 1.69
Consistently take the interface down when the radio swicth is off.
 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.78.2.2  27-Jul-2019  martin Pull up following revision(s) (requested by jakllsch in ticket #1308):

sys/dev/pci/if_wpi.c: revision 1.86

Put back correct recieve ring allocation size which was lost just over
five years ago mae culpa.

Found by msaitoh@

Should fix PR kern/54320 once pulled up.
 1.78.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.79.2.3  26-Dec-2018  pgoyette Sync with HEAD, resolve a few conflicts
 1.79.2.2  06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.79.2.1  28-Jul-2018  pgoyette Sync with HEAD
 1.80.2.3  13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.80.2.2  08-Apr-2020  martin Merge changes from current as of 20200406
 1.80.2.1  10-Jun-2019  christos Sync with HEAD
 1.87.2.1  29-Feb-2020  ad Sync with head.
 1.89.4.1  03-Apr-2021  thorpej Sync with HEAD.
 1.90.4.1  17-Jun-2021  thorpej Sync w/ HEAD.

RSS XML Feed