History log of /openbsd-current/sys/dev/ic/rt2560.c
Revision (<<< Hide revision tags) (Show revision tags >>>) Date Author Comments
# 1.90 21-Apr-2022 stsp

Use memset() to initialize struct ieee80211_rxinfo properly.

Sven Wolf noticed that scans on ral(4) are buggy ever since I added a new
field to this struct. Turns out a lot of drivers were initializing fields
one-by-one, leaving any newly added fields uninitialized by default.

Affected drivers may report wrong channel numbers for received beacons.
The net80211 stack will discard such beacons, assuming they were received
on the wrong channel due to signal leakage. Scanning is broken as result.

ok miod@


Revision tags: OPENBSD_7_1_BASE
# 1.89 09-Jan-2022 jsg

branches: 1.89.2;
spelling
feedback and ok tb@ jmc@ ok ratchov@


Revision tags: OPENBSD_6_8_BASE OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.88 20-Jul-2020 stsp

The IEEE80211_F_HIDENWID flag is now part of ic_userflags, not ic_flags.
Fix code which was still looking for this flag at the old location.

The 'hidenwid' feature was slightly broken as a result: The SSID was leaked
in probe responses to wildcard probe requests. There are other trivial ways
of snooping a "hidden" SSID however so this is not a big deal.

Problem reported by Mogens Jensen.


# 1.87 10-Jul-2020 patrick

Change users of IFQ_DEQUEUE(), IFQ_ENQUEUE() and IFQ_LEN() to use the
"new" API.

ok dlg@ tobhe@


Revision tags: OPENBSD_6_7_BASE
# 1.86 19-Feb-2020 claudio

Similar to other wireless drivers use bpf_mtap_hdr() to prepend the
radiotap header instead of using a fack mbuf in the stack.
OK stsp@


Revision tags: OPENBSD_6_6_BASE
# 1.85 12-Sep-2019 stsp

Make wireless drivers call if_input() only once per interrupt.

This reduces drops caused by the ifq pressure drop mechanism and hence
increases throughput. Such drops are visible with e.g. 'netstat -dnI iwm0'.

Not all affected drivers have been tested yet but these changes are largely
mechanical and should be safe. As usual, please report any regressions.

With help from dlg@ and mpi@

Problem found by robert@
Tested by robert, jmc, Tracey Emer, Matthias Schmidt, florian, Bj��rn Ketelaars
ok mpi@


Revision tags: OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.84 26-Oct-2017 mpi

Move common code to add/remove multicast filters to ieee80211_ioctl(9).

ok jsg@, stsp@


Revision tags: OPENBSD_6_2_BASE
# 1.83 03-Jul-2017 kevlo

Replace slot time durations with macros.

ok stsp@


Revision tags: OPENBSD_6_1_BASE
# 1.82 22-Jan-2017 dlg

move counting if_opackets next to counting if_obytes in if_enqueue.

this means packets are consistently counted in one place, unlike the
many and various ways that drivers thought they should do it.

ok mpi@ deraadt@


# 1.81 06-Oct-2016 stsp

Disable RTS for long frames in ral(4) for rt2560 chips.
On these chips RTS causes bad performance in hostap mode for unknown reasons.

Convert some debug printfs to DPRINTF.
Add a comment which explains why 2 free slots are needed on the Tx queue.

ok phessler@ sthen@


Revision tags: OPENBSD_6_0_BASE
# 1.80 13-Apr-2016 mpi

G/C IFQ_SET_READY().


Revision tags: OPENBSD_5_9_BASE
# 1.79 05-Dec-2015 dlg

ifq_deq_rollback without a preceding ifq_deq_begin is fail.

caused by a badly managed merge.

found by and testing by sebastia@
ok mpi@


# 1.78 25-Nov-2015 dlg

replace IFF_OACTIVE manipulation with mpsafe operations.

there are two things shared between the network stack and drivers
in the send path: the send queue and the IFF_OACTIVE flag. the send
queue is now protected by a mutex. this diff makes the oactive
functionality mpsafe too.

IFF_OACTIVE is part of if_flags. there are two problems with that.
firstly, if_flags is a short and we dont have any MI atomic operations
to manipulate a short. secondly, while we could make the IFF_OACTIVE
operates mpsafe, all changes to other flags would have to be made
safe at the same time, otherwise a read-modify-write cycle on their
updates could clobber the oactive change.

instead, this moves the oactive mark into struct ifqueue and provides
an API for changing it. there's ifq_set_oactive, ifq_clr_oactive,
and ifq_is_oactive. these are modelled on ifsq_set_oactive,
ifsq_clr_oactive, and ifsq_is_oactive in dragonflybsd.

this diff includes changes to all the drivers manipulating IFF_OACTIVE
to now use the ifsq_{set,clr_is}_oactive API too.

ok kettenis@ mpi@ jmatthew@ deraadt@


# 1.77 24-Nov-2015 mpi

The only network driver needing <net/if_types.h> is upl(4) for IFT_OTHER.


# 1.76 20-Nov-2015 mpi

Check for space on the ring before dequeuing packets.

Allows us to get rid of mq_requeue(9) and IFQ_POLL(9) because wireless
drivers use a special queue for management frames.

Tested by stsp@, ok dlg@, stsp@


# 1.75 20-Nov-2015 dlg

shuffle struct ifqueue so in flight mbufs are protected by a mutex.

the code is refactored so the IFQ macros call newly implemented ifq
functions. the ifq code is split so each discipline (priq and hfsc
in our case) is an opaque set of operations that the common ifq
code can call. the common code does the locking, accounting (ifq_len
manipulation), and freeing of the mbuf if the disciplines enqueue
function rejects it. theyre kind of like bufqs in the block layer
with their fifo and nscan disciplines.

the new api also supports atomic switching of disciplines at runtime.
the hfsc setup in pf_ioctl.c has been tweaked to build a complete
hfsc_if structure which it attaches to the send queue in a single
operation, rather than attaching to the interface up front and
building up a list of queues.

the send queue is now mutexed, which raises the expectation that
packets can be enqueued or purged on one cpu while another cpu is
dequeueing them in a driver for transmission. a lot of drivers use
IFQ_POLL to peek at an mbuf and attempt to fit it on the ring before
committing to it with a later IFQ_DEQUEUE operation. if the mbuf
gets freed in between the POLL and DEQUEUE operations, fireworks
will ensue.

to avoid this, the ifq api introduces ifq_deq_begin, ifq_deq_rollback,
and ifq_deq_commit. ifq_deq_begin allows a driver to take the ifq
mutex and get a reference to the mbuf they wish to try and tx. if
there's space, they can ifq_deq_commit it to remove the mbuf and
release the mutex. if there's no space, ifq_deq_rollback simply
releases the mutex. this api was developed to make updating the
drivers using IFQ_POLL easy, instead of having to do significant
semantic changes to avoid POLL that we cannot test on all the
hardware.

the common code has been tested pretty hard, and all the driver
modifications are straightforward except for de(4). if that breaks
it can be dealt with later.

ok mpi@ jmatthew@


# 1.74 04-Nov-2015 dlg

replace the ifqueues in net80211 with mbuf_queues.

the specific queues are ic_mgtq, ic_pwrsaveq, and ni_savedq. rtw
had its own queue for beacons.

tested by mpi@ and jmc@
ok mpi@


# 1.73 25-Oct-2015 mpi

arp_ifinit() is no longer needed.


# 1.72 09-Sep-2015 deraadt

sizes for free(); ok semarie


Revision tags: OPENBSD_5_8_BASE
# 1.71 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.70 10-Feb-2015 mpi

Wireless drivers call if_input() via ieee80211_input() which set `rcvif'
on every received mbuf, so there's no need to initialize this pointer in
the drivers.

Tested by and ok phessler@


# 1.69 22-Dec-2014 tedu

unifdef INET


# 1.68 19-Dec-2014 guenther

Use <sys/endian.h> instead of <machine/endian.h>

ok dlg@ mpi@ bcook@ millert@ miod@


# 1.67 06-Sep-2014 jsg

reduce the amount of pci includes


Revision tags: OPENBSD_5_6_BASE
# 1.66 22-Jul-2014 mpi

Fewer <netinet/in_systm.h>


# 1.65 13-Jul-2014 deraadt

Some reallocarray() use; review Jean-Philippe Ouellet, patrick keshishian
ok tedu


# 1.64 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


# 1.63 19-Mar-2014 mpi

Stop abusing the rcvif pointer to pass wireless nodes down to the
driver start routines. Instead add & use a pointer in the pkthdr
since we don't want the overhead of using a mbuf_tags(9).

claudio@ pointed out that other subsystems might want to use this
pointer too, so here's a new cookie!

ok claudio@, mikeb@, deraadt@


Revision tags: OPENBSD_5_5_BASE
# 1.62 06-Dec-2013 deraadt

Add a DVACT_WAKEUP op to the *_activate() API. This is called after the
kernel resumes normal (non-cold, able to run processes, etc) operation.
Previously we were relying on specific DVACT_RESUME op's in drivers
creating callback/threads themselves, but that has become too common,
indicating the need for a built-in mechanism.
ok dlg kettenis, tested by a sufficient amount of people


# 1.61 07-Aug-2013 bluhm

Most network drivers include netinet/in_var.h, but apparently they
don't have to. Just remove these include lines.
Compiled on amd64 i386 sparc64; OK henning@ mikeb@


Revision tags: OPENBSD_5_2_BASE OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.60 13-Jul-2012 stsp

Keep separate OACTIVE flags to mark full management/data tx queues,
and set the interface's IFF_OACTIVE flag if either queue is full and
clear it only if both queues have free slots. Before this change both
queues were setting/clearing the same flag with no regard for the
other queue's state.

Also, don't reset the tx watchdog counter if either queue still has frames
queued when we exit the frame-processing loop in the per-queue interrupt
handlers.

Both changes originally from sephe@dragonfly.

Tested by myself and edd on a slow busy soekris which before this
change required occasional 'ifconfig ral0 down up' to recover.


# 1.59 13-Jul-2012 stsp

Init the baseband processor before selecting antennas since selecting antennas
involves tweaking of BBP registers. Wait for BBP to stop being busy before
reading from it.

Originally from sephe@dragonfly. ok kettenis sthen


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.58 22-Feb-2011 kettenis

Mark descriptors as invalid *before* unmapping the associated mbuf.
Might prevent the unrecoverable DMA error mentioned in PR 6557.

ok damien@


# 1.57 07-Sep-2010 deraadt

remove the powerhook code. All architectures now use the ca_activate tree
traversal code to suspend/resume
ok oga kettenis blambert


# 1.56 06-Sep-2010 deraadt

All PWR_{SUSPEND,RESUME} can now be replaced by DVACT_{SUSPEND,RESUME}


# 1.55 06-Sep-2010 kettenis

Make the interrupt handler bail out early if the device wen away. Fixes
freezes that occur when removing CardBus cards when the interface is up.

ok deraadt@


# 1.54 28-Aug-2010 deraadt

rename the *_power functions to *_powerhook to indicate that we've been
here already for the activate/powerhook cleanup


# 1.53 27-Aug-2010 jsg

remove the unused if_init callback in struct ifnet
ok deraadt@ henning@ claudio@


# 1.52 27-Aug-2010 kettenis

Stop calling xxx_power() from xxx_resume(); instead do it the other way around.
Get rid of the sc_power() callback, which isn't used anymore.

ok deraadt@


# 1.51 27-Aug-2010 deraadt

kill PWR_STANDBY (apm can use PWR_SUSPEND instead). While here, renumber
PWR_{SUSPEND,RESUME} so that they match the values of DAVCT_{SUSPEND,RESUME}
so that we can eventually (many more steps...) kill the powerhook garbage
and use the activate mechanism.
no objections


# 1.50 25-Aug-2010 kettenis

Make CardBus ral(4) suspend and resume properly on machines that keep the
CardBus bridge powered up during suspend. Step zero on the long road
towards fully suspending CardBus on all machines.

ok deraadt@, damien@


Revision tags: OPENBSD_4_8_BASE
# 1.49 04-Aug-2010 damien

add suspend/resume support for PCI ral(4) devices.

ok deraadt@, sthen@

tested by matthew@ (RT2560), dcoppa@ (RT2790), okan@ (RT2860), todd@ (RT2560)


# 1.48 19-May-2010 oga

BUS_DMA_ZERO instead of alloc, map, bzero.

ok krw@


# 1.47 20-Apr-2010 tedu

remove proc.h include from uvm_map.h. This has far reaching effects, as
sysctl.h was reliant on this particular include, and many drivers included
sysctl.h unnecessarily. remove sysctl.h or add proc.h as needed.
ok deraadt


Revision tags: OPENBSD_4_7_BASE
# 1.46 01-Nov-2009 damien

call powerhook_disestablish() and pci_intr_disestablish() earlier.

diff from deraadt@


# 1.45 10-Aug-2009 damien

three more shutdown hooks bite the dust.


# 1.44 29-Jul-2009 blambert

timeout_add -> timeout_add_msec

ok damien@


Revision tags: OPENBSD_4_6_BASE
# 1.43 29-Mar-2009 sthen

make various strings ("can't map mem space" and similar) more consistent
between instances, saving space in the kernel. feedback from many (some
incorporated, some left for future work).

ok deraadt, kettenis, "why not" miod.


Revision tags: OPENBSD_4_5_BASE
# 1.42 22-Dec-2008 damien

I swapped MGETHDR arguments in my m_defrag removal commit.


# 1.41 21-Dec-2008 damien

Undo m_defrag().

m_defrag() does not work. It seems to assume that if the length of
the mbuf passed as parameter is less than MHLEN, then it is an mbuf
header and not a cluster (or something like that.)
It thus fails miserably in the bcopy path.
I don't have the time to investigate further into this.

Thanks to Okan Demirmen for reporting the issue on a ral(4) RT2560.
The RT2560 chipset does not support TX scatter and thus m_defrag()
was called much more often than in other drivers using m_defrag()
where it was less noticeable.


# 1.40 25-Nov-2008 damien

use shiny new m_defrag() and nitems() instead of rolling our own.


# 1.39 27-Aug-2008 damien

introduce new IEEE80211_STA_ONLY kernel option that can be set to
remove IBSS and HostAP support from net80211 and 802.11 drivers.
it can be used to shrink RAMDISK kernels for instance (like what
was done for wi(4)).
it also has the benefit of highlighting what is specific to IBSS
and HostAP modes in the code.
the cost is that we now have two code paths to maintain.


# 1.38 14-Aug-2008 damien

in ieee80211_input(), call if_start() after enqueuing frames in if_snd
when acting as an access point instead of having each driver doing the
job.

tested by krw@ (ral AP) and me with several drivers.


Revision tags: OPENBSD_4_4_BASE
# 1.37 21-Jul-2008 damien

instead of passing rx tstamp and rssi to the ieee80211_input function,
pass a pointer to an ieee80211_rxinfo structure containing those two
fields plus an extra flags field that indicates whether the frame was
decrypted by hardware or not.
required for a future fix.


# 1.36 16-Apr-2008 damien

Kernel implementation of the 4-way handshake and group-key
handshake protocols (both supplicant and authenticator state
machines) as defined in the IEEE 802.11i standard.

Software implementation of the TKIP (Temporal Key Integrity
Protocol) and CCMP (CTR with CBC-MAC Protocol) protocols.

This diff doesn't implement any of the 802.1X authentication
protocols and thus only PSK authentication (using pre-shared
keys) is currently supported.

In concrete terms, this adds support for WPA-PSK and WPA2-PSK
protocols, both in station and hostap modes.

The following drivers are marked as WPA-capable and should
work: bwi(4), malo(4), ral(4), iwn(4), wpi(4), ural(4),
rum(4), upgt(4), and zyd(4)

The following options have been added to ifconfig(8):
wpa, wpapsk, wpaprotos, wpaakms, wpaciphers, wpagroupcipher

wpa-psk(8) can be used to generate keys from passphrases.

tested by many@
ok deraadt@


Revision tags: OPENBSD_4_3_BASE
# 1.35 17-Nov-2007 damien

RT2560+RT2661: update the physical address in the RX descriptor after
bus_dmamap_load() in the case where the same mbuf is reloaded.
RT2661: remove a 2x prototype, fix an error message.


# 1.34 15-Oct-2007 fgsch

more remove unneeded declarations that shadows existing vars; ok by many.


# 1.33 07-Sep-2007 damien

use new malloc M_ZERO flag to shrink kernel.
remove <malloc.h> from files where malloc is not used.


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.32 08-Mar-2007 deraadt

XXX commit a workaround (as found in a few other drivers) for the
divide by zero rate bug. Someone has to find the source of this
bug one day; from jsg


# 1.31 24-Jan-2007 damien

revert changes committed between r1.25 and 1.26.
this breaks some RT2560 adapters.

pointed out by krw@ and Pierre Riteau.


# 1.30 03-Jan-2007 claudio

M_DUP_PKTHDR() cleanup. On static buffers M_DUP_PKTHDR() will leak mbuf tags.
See similar rum(4) commit for more info. OK mglocker@


# 1.29 17-Dec-2006 damien

fix index of ERP information element in beacons.
still ugly, but correct.


# 1.28 03-Dec-2006 damien

fix handling of the SIOCS80211CHANNEL ioctl in monitor mode:
don't call xxx_set_chan() if the interface is not up&running.

patch from Steffen Schuetz (st dot sch at gmx dot net) with
minor modifications by me.

closes kernel/5313


# 1.27 26-Nov-2006 deraadt

do not have each net80211 driver define its own rates structures. if they use
the standard rates, use some defined by net80211 itself. kernel shrinks a bit
ok jsg mglocker


# 1.26 22-Nov-2006 damien

don't write to BBP before it is ready and fully initialized
-> move rt2560_set{tx,rx}antenna() after rt2560_bbp_init().

from <sephe at dragonflybsd dot org>


# 1.25 13-Nov-2006 damien

first round of commits for proper 11b/g protection support:
- use the newly introduced ieee80211_get_rts() and
ieee80211_get_cts_to_self() functions.
- use CTS-to-self instead of RTS/CTS to protect OFDM frames in
a mixed 11b/g BSS.
- make sure multicast frames are sent using CCK modulation.

remove support for 5GHz radios in ral(4) RT2560 and ural(4).
i'm not aware of any such adapters on the market and 11a code
is known to be broken.

some cleanup while i'm here.


# 1.24 22-Oct-2006 damien

replace rssadapt(9) with amrr for automatic rate control.
as a side-effect, this should fix all the "bogus xmit rate" panics
users have been complaining about for some time when operating in
HostAP mode.


# 1.23 18-Sep-2006 damien

don't use IF_PREPEND() on altq's.
use IFQ_POLL()/IFQ_DEQUEUE() logic instead as described in altq(4).


Revision tags: OPENBSD_4_0_BASE
# 1.22 18-Jul-2006 damien

modify interrupt handlers to exit early and return 0 on shared interrupts.

pointed out by deraadt@


# 1.21 18-Jun-2006 damien

- implement new ic_updateslot() callback.
- in hostap mode, we defer update of the slot time until all associated
STAs are notified with updated beacons.


# 1.20 18-Jun-2006 damien

enable packet bursting when operating as a STA.
limit bursts to 8 frames.


# 1.19 14-Jun-2006 damien

must use RTS/CTS protection when sending frames at OFDM rates in a BSS
with non-ERP STAs. some bits are missing in net80211 though, so this
code won't be triggered yet.


# 1.18 10-Jun-2006 damien

- fix checking of WEP flags
- encrypt mgmt frames when they need to (shared authmode)
- move default MAC/BBP/RF settings from rt2560.c to rt2560reg.h


# 1.17 02-Jun-2006 robert

add powerhooks for ral(4) cards with the RT2560 chipset;

ok damien@


# 1.16 01-Jun-2006 robert

Make the debug printfs work if RAL_DEBUG is defined.


# 1.15 20-Apr-2006 miod

Fix various printf() issues: too many arguments, not enough arguments, argument
order reversed, wrong modifiers. ok deraadt@ marco@ mickey@


# 1.14 27-Mar-2006 damien

fixes interrupts processing.

should fix a panic reported by Karel Gardas.


# 1.13 25-Mar-2006 djm

allow bpf(4) to ignore packets based on their direction (inbound or
outbound), using a new BIOCSDIRFILT ioctl;
guidance, feedback and ok canacar@


Revision tags: OPENBSD_3_9_BASE
# 1.12 25-Feb-2006 damien

branches: 1.12.2;
instead of panicing when tx rate is zero, fallback to 1Mbps.
this is a temporary workaround since we should really not see any node
with an empty rate set but it seems to happen in hostap mode.


# 1.11 18-Feb-2006 damien

don't try to release references to nodes that have been freed by net80211.
in HostAP mode, when switching to the INIT state, net80211 sends a DISASSOC
and a DEAUTH frame to all associated stations and immediately free all the
nodes while we may still hold references to them in our Tx queues.

hopefully, this should fix PRs 4469/kernel and 4953/kernel.


# 1.10 14-Jan-2006 damien

- give rate to rx radiotap
- read TSF high 32bit word before low 32bit word to avoid wraparounds


# 1.9 14-Jan-2006 jsg

Correct the length of the rx radiotap to be that of the rx not tx
struct.

ok damien@


# 1.8 13-Jan-2006 damien

fix short slot time + cosmetic


# 1.7 13-Jan-2006 damien

- simplify lookup of 802.11a channels (we know they exist)
- kill two stupid comments while i'm here


# 1.6 11-Jan-2006 damien

fix RTS protection mode.


# 1.5 10-Jan-2006 damien

- use rssadapt(9) as rate control algorithm
- add 802.11 radiotap support
- read 802.11a channels tx power from EEPROM
- read vendor-specific BBP settings from EEPROM
- fix setting of beacons (xflags)
- fix DMA sync in rt2661_rx_intr
- indicate whether RF supports MIMO in dmesg
- add short slot time support
- many cleanups while i'm here


# 1.4 10-Jan-2006 damien

fix reading of EEPROM content on big endian arches.


# 1.3 10-Jan-2006 damien

send management, control and beacon frames at the lowest possible rate
(1Mbps for 802.11b/g, 6Mbps for 802.11a)


# 1.2 10-Jan-2006 damien

cleanup rt2560_setup_tx_desc().
fix contention window.


# 1.1 09-Jan-2006 damien

- add preliminary support for Ralink Technology RT2561, RT2561S and RT2661
chipsets in ral(4).
- restructure the code a bit; split ic/ral.c into ic/rt2560.c and ic/rt2661.c
- import the 8051 microcode files required by these chipsets.
- more to come; there is currently no automatic rate control and some
features are untested (hostap and ibss modes for instance). most of
the pre-802.11n capabilities of the RT2661 chipset are not supported
(like frame aggregation, piggy-back). MIMO should work though the
performance/range gain has not been measured.


# 1.89 09-Jan-2022 jsg

spelling
feedback and ok tb@ jmc@ ok ratchov@


Revision tags: OPENBSD_6_8_BASE OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.88 20-Jul-2020 stsp

The IEEE80211_F_HIDENWID flag is now part of ic_userflags, not ic_flags.
Fix code which was still looking for this flag at the old location.

The 'hidenwid' feature was slightly broken as a result: The SSID was leaked
in probe responses to wildcard probe requests. There are other trivial ways
of snooping a "hidden" SSID however so this is not a big deal.

Problem reported by Mogens Jensen.


# 1.87 10-Jul-2020 patrick

Change users of IFQ_DEQUEUE(), IFQ_ENQUEUE() and IFQ_LEN() to use the
"new" API.

ok dlg@ tobhe@


Revision tags: OPENBSD_6_7_BASE
# 1.86 19-Feb-2020 claudio

Similar to other wireless drivers use bpf_mtap_hdr() to prepend the
radiotap header instead of using a fack mbuf in the stack.
OK stsp@


Revision tags: OPENBSD_6_6_BASE
# 1.85 12-Sep-2019 stsp

Make wireless drivers call if_input() only once per interrupt.

This reduces drops caused by the ifq pressure drop mechanism and hence
increases throughput. Such drops are visible with e.g. 'netstat -dnI iwm0'.

Not all affected drivers have been tested yet but these changes are largely
mechanical and should be safe. As usual, please report any regressions.

With help from dlg@ and mpi@

Problem found by robert@
Tested by robert, jmc, Tracey Emer, Matthias Schmidt, florian, Bj��rn Ketelaars
ok mpi@


Revision tags: OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.84 26-Oct-2017 mpi

Move common code to add/remove multicast filters to ieee80211_ioctl(9).

ok jsg@, stsp@


Revision tags: OPENBSD_6_2_BASE
# 1.83 03-Jul-2017 kevlo

Replace slot time durations with macros.

ok stsp@


Revision tags: OPENBSD_6_1_BASE
# 1.82 22-Jan-2017 dlg

move counting if_opackets next to counting if_obytes in if_enqueue.

this means packets are consistently counted in one place, unlike the
many and various ways that drivers thought they should do it.

ok mpi@ deraadt@


# 1.81 06-Oct-2016 stsp

Disable RTS for long frames in ral(4) for rt2560 chips.
On these chips RTS causes bad performance in hostap mode for unknown reasons.

Convert some debug printfs to DPRINTF.
Add a comment which explains why 2 free slots are needed on the Tx queue.

ok phessler@ sthen@


Revision tags: OPENBSD_6_0_BASE
# 1.80 13-Apr-2016 mpi

G/C IFQ_SET_READY().


Revision tags: OPENBSD_5_9_BASE
# 1.79 05-Dec-2015 dlg

ifq_deq_rollback without a preceding ifq_deq_begin is fail.

caused by a badly managed merge.

found by and testing by sebastia@
ok mpi@


# 1.78 25-Nov-2015 dlg

replace IFF_OACTIVE manipulation with mpsafe operations.

there are two things shared between the network stack and drivers
in the send path: the send queue and the IFF_OACTIVE flag. the send
queue is now protected by a mutex. this diff makes the oactive
functionality mpsafe too.

IFF_OACTIVE is part of if_flags. there are two problems with that.
firstly, if_flags is a short and we dont have any MI atomic operations
to manipulate a short. secondly, while we could make the IFF_OACTIVE
operates mpsafe, all changes to other flags would have to be made
safe at the same time, otherwise a read-modify-write cycle on their
updates could clobber the oactive change.

instead, this moves the oactive mark into struct ifqueue and provides
an API for changing it. there's ifq_set_oactive, ifq_clr_oactive,
and ifq_is_oactive. these are modelled on ifsq_set_oactive,
ifsq_clr_oactive, and ifsq_is_oactive in dragonflybsd.

this diff includes changes to all the drivers manipulating IFF_OACTIVE
to now use the ifsq_{set,clr_is}_oactive API too.

ok kettenis@ mpi@ jmatthew@ deraadt@


# 1.77 24-Nov-2015 mpi

The only network driver needing <net/if_types.h> is upl(4) for IFT_OTHER.


# 1.76 20-Nov-2015 mpi

Check for space on the ring before dequeuing packets.

Allows us to get rid of mq_requeue(9) and IFQ_POLL(9) because wireless
drivers use a special queue for management frames.

Tested by stsp@, ok dlg@, stsp@


# 1.75 20-Nov-2015 dlg

shuffle struct ifqueue so in flight mbufs are protected by a mutex.

the code is refactored so the IFQ macros call newly implemented ifq
functions. the ifq code is split so each discipline (priq and hfsc
in our case) is an opaque set of operations that the common ifq
code can call. the common code does the locking, accounting (ifq_len
manipulation), and freeing of the mbuf if the disciplines enqueue
function rejects it. theyre kind of like bufqs in the block layer
with their fifo and nscan disciplines.

the new api also supports atomic switching of disciplines at runtime.
the hfsc setup in pf_ioctl.c has been tweaked to build a complete
hfsc_if structure which it attaches to the send queue in a single
operation, rather than attaching to the interface up front and
building up a list of queues.

the send queue is now mutexed, which raises the expectation that
packets can be enqueued or purged on one cpu while another cpu is
dequeueing them in a driver for transmission. a lot of drivers use
IFQ_POLL to peek at an mbuf and attempt to fit it on the ring before
committing to it with a later IFQ_DEQUEUE operation. if the mbuf
gets freed in between the POLL and DEQUEUE operations, fireworks
will ensue.

to avoid this, the ifq api introduces ifq_deq_begin, ifq_deq_rollback,
and ifq_deq_commit. ifq_deq_begin allows a driver to take the ifq
mutex and get a reference to the mbuf they wish to try and tx. if
there's space, they can ifq_deq_commit it to remove the mbuf and
release the mutex. if there's no space, ifq_deq_rollback simply
releases the mutex. this api was developed to make updating the
drivers using IFQ_POLL easy, instead of having to do significant
semantic changes to avoid POLL that we cannot test on all the
hardware.

the common code has been tested pretty hard, and all the driver
modifications are straightforward except for de(4). if that breaks
it can be dealt with later.

ok mpi@ jmatthew@


# 1.74 04-Nov-2015 dlg

replace the ifqueues in net80211 with mbuf_queues.

the specific queues are ic_mgtq, ic_pwrsaveq, and ni_savedq. rtw
had its own queue for beacons.

tested by mpi@ and jmc@
ok mpi@


# 1.73 25-Oct-2015 mpi

arp_ifinit() is no longer needed.


# 1.72 09-Sep-2015 deraadt

sizes for free(); ok semarie


Revision tags: OPENBSD_5_8_BASE
# 1.71 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.70 10-Feb-2015 mpi

Wireless drivers call if_input() via ieee80211_input() which set `rcvif'
on every received mbuf, so there's no need to initialize this pointer in
the drivers.

Tested by and ok phessler@


# 1.69 22-Dec-2014 tedu

unifdef INET


# 1.68 19-Dec-2014 guenther

Use <sys/endian.h> instead of <machine/endian.h>

ok dlg@ mpi@ bcook@ millert@ miod@


# 1.67 06-Sep-2014 jsg

reduce the amount of pci includes


Revision tags: OPENBSD_5_6_BASE
# 1.66 22-Jul-2014 mpi

Fewer <netinet/in_systm.h>


# 1.65 13-Jul-2014 deraadt

Some reallocarray() use; review Jean-Philippe Ouellet, patrick keshishian
ok tedu


# 1.64 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


# 1.63 19-Mar-2014 mpi

Stop abusing the rcvif pointer to pass wireless nodes down to the
driver start routines. Instead add & use a pointer in the pkthdr
since we don't want the overhead of using a mbuf_tags(9).

claudio@ pointed out that other subsystems might want to use this
pointer too, so here's a new cookie!

ok claudio@, mikeb@, deraadt@


Revision tags: OPENBSD_5_5_BASE
# 1.62 06-Dec-2013 deraadt

Add a DVACT_WAKEUP op to the *_activate() API. This is called after the
kernel resumes normal (non-cold, able to run processes, etc) operation.
Previously we were relying on specific DVACT_RESUME op's in drivers
creating callback/threads themselves, but that has become too common,
indicating the need for a built-in mechanism.
ok dlg kettenis, tested by a sufficient amount of people


# 1.61 07-Aug-2013 bluhm

Most network drivers include netinet/in_var.h, but apparently they
don't have to. Just remove these include lines.
Compiled on amd64 i386 sparc64; OK henning@ mikeb@


Revision tags: OPENBSD_5_2_BASE OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.60 13-Jul-2012 stsp

Keep separate OACTIVE flags to mark full management/data tx queues,
and set the interface's IFF_OACTIVE flag if either queue is full and
clear it only if both queues have free slots. Before this change both
queues were setting/clearing the same flag with no regard for the
other queue's state.

Also, don't reset the tx watchdog counter if either queue still has frames
queued when we exit the frame-processing loop in the per-queue interrupt
handlers.

Both changes originally from sephe@dragonfly.

Tested by myself and edd on a slow busy soekris which before this
change required occasional 'ifconfig ral0 down up' to recover.


# 1.59 13-Jul-2012 stsp

Init the baseband processor before selecting antennas since selecting antennas
involves tweaking of BBP registers. Wait for BBP to stop being busy before
reading from it.

Originally from sephe@dragonfly. ok kettenis sthen


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.58 22-Feb-2011 kettenis

Mark descriptors as invalid *before* unmapping the associated mbuf.
Might prevent the unrecoverable DMA error mentioned in PR 6557.

ok damien@


# 1.57 07-Sep-2010 deraadt

remove the powerhook code. All architectures now use the ca_activate tree
traversal code to suspend/resume
ok oga kettenis blambert


# 1.56 06-Sep-2010 deraadt

All PWR_{SUSPEND,RESUME} can now be replaced by DVACT_{SUSPEND,RESUME}


# 1.55 06-Sep-2010 kettenis

Make the interrupt handler bail out early if the device wen away. Fixes
freezes that occur when removing CardBus cards when the interface is up.

ok deraadt@


# 1.54 28-Aug-2010 deraadt

rename the *_power functions to *_powerhook to indicate that we've been
here already for the activate/powerhook cleanup


# 1.53 27-Aug-2010 jsg

remove the unused if_init callback in struct ifnet
ok deraadt@ henning@ claudio@


# 1.52 27-Aug-2010 kettenis

Stop calling xxx_power() from xxx_resume(); instead do it the other way around.
Get rid of the sc_power() callback, which isn't used anymore.

ok deraadt@


# 1.51 27-Aug-2010 deraadt

kill PWR_STANDBY (apm can use PWR_SUSPEND instead). While here, renumber
PWR_{SUSPEND,RESUME} so that they match the values of DAVCT_{SUSPEND,RESUME}
so that we can eventually (many more steps...) kill the powerhook garbage
and use the activate mechanism.
no objections


# 1.50 25-Aug-2010 kettenis

Make CardBus ral(4) suspend and resume properly on machines that keep the
CardBus bridge powered up during suspend. Step zero on the long road
towards fully suspending CardBus on all machines.

ok deraadt@, damien@


Revision tags: OPENBSD_4_8_BASE
# 1.49 04-Aug-2010 damien

add suspend/resume support for PCI ral(4) devices.

ok deraadt@, sthen@

tested by matthew@ (RT2560), dcoppa@ (RT2790), okan@ (RT2860), todd@ (RT2560)


# 1.48 19-May-2010 oga

BUS_DMA_ZERO instead of alloc, map, bzero.

ok krw@


# 1.47 20-Apr-2010 tedu

remove proc.h include from uvm_map.h. This has far reaching effects, as
sysctl.h was reliant on this particular include, and many drivers included
sysctl.h unnecessarily. remove sysctl.h or add proc.h as needed.
ok deraadt


Revision tags: OPENBSD_4_7_BASE
# 1.46 01-Nov-2009 damien

call powerhook_disestablish() and pci_intr_disestablish() earlier.

diff from deraadt@


# 1.45 10-Aug-2009 damien

three more shutdown hooks bite the dust.


# 1.44 29-Jul-2009 blambert

timeout_add -> timeout_add_msec

ok damien@


Revision tags: OPENBSD_4_6_BASE
# 1.43 29-Mar-2009 sthen

make various strings ("can't map mem space" and similar) more consistent
between instances, saving space in the kernel. feedback from many (some
incorporated, some left for future work).

ok deraadt, kettenis, "why not" miod.


Revision tags: OPENBSD_4_5_BASE
# 1.42 22-Dec-2008 damien

I swapped MGETHDR arguments in my m_defrag removal commit.


# 1.41 21-Dec-2008 damien

Undo m_defrag().

m_defrag() does not work. It seems to assume that if the length of
the mbuf passed as parameter is less than MHLEN, then it is an mbuf
header and not a cluster (or something like that.)
It thus fails miserably in the bcopy path.
I don't have the time to investigate further into this.

Thanks to Okan Demirmen for reporting the issue on a ral(4) RT2560.
The RT2560 chipset does not support TX scatter and thus m_defrag()
was called much more often than in other drivers using m_defrag()
where it was less noticeable.


# 1.40 25-Nov-2008 damien

use shiny new m_defrag() and nitems() instead of rolling our own.


# 1.39 27-Aug-2008 damien

introduce new IEEE80211_STA_ONLY kernel option that can be set to
remove IBSS and HostAP support from net80211 and 802.11 drivers.
it can be used to shrink RAMDISK kernels for instance (like what
was done for wi(4)).
it also has the benefit of highlighting what is specific to IBSS
and HostAP modes in the code.
the cost is that we now have two code paths to maintain.


# 1.38 14-Aug-2008 damien

in ieee80211_input(), call if_start() after enqueuing frames in if_snd
when acting as an access point instead of having each driver doing the
job.

tested by krw@ (ral AP) and me with several drivers.


Revision tags: OPENBSD_4_4_BASE
# 1.37 21-Jul-2008 damien

instead of passing rx tstamp and rssi to the ieee80211_input function,
pass a pointer to an ieee80211_rxinfo structure containing those two
fields plus an extra flags field that indicates whether the frame was
decrypted by hardware or not.
required for a future fix.


# 1.36 16-Apr-2008 damien

Kernel implementation of the 4-way handshake and group-key
handshake protocols (both supplicant and authenticator state
machines) as defined in the IEEE 802.11i standard.

Software implementation of the TKIP (Temporal Key Integrity
Protocol) and CCMP (CTR with CBC-MAC Protocol) protocols.

This diff doesn't implement any of the 802.1X authentication
protocols and thus only PSK authentication (using pre-shared
keys) is currently supported.

In concrete terms, this adds support for WPA-PSK and WPA2-PSK
protocols, both in station and hostap modes.

The following drivers are marked as WPA-capable and should
work: bwi(4), malo(4), ral(4), iwn(4), wpi(4), ural(4),
rum(4), upgt(4), and zyd(4)

The following options have been added to ifconfig(8):
wpa, wpapsk, wpaprotos, wpaakms, wpaciphers, wpagroupcipher

wpa-psk(8) can be used to generate keys from passphrases.

tested by many@
ok deraadt@


Revision tags: OPENBSD_4_3_BASE
# 1.35 17-Nov-2007 damien

RT2560+RT2661: update the physical address in the RX descriptor after
bus_dmamap_load() in the case where the same mbuf is reloaded.
RT2661: remove a 2x prototype, fix an error message.


# 1.34 15-Oct-2007 fgsch

more remove unneeded declarations that shadows existing vars; ok by many.


# 1.33 07-Sep-2007 damien

use new malloc M_ZERO flag to shrink kernel.
remove <malloc.h> from files where malloc is not used.


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.32 08-Mar-2007 deraadt

XXX commit a workaround (as found in a few other drivers) for the
divide by zero rate bug. Someone has to find the source of this
bug one day; from jsg


# 1.31 24-Jan-2007 damien

revert changes committed between r1.25 and 1.26.
this breaks some RT2560 adapters.

pointed out by krw@ and Pierre Riteau.


# 1.30 03-Jan-2007 claudio

M_DUP_PKTHDR() cleanup. On static buffers M_DUP_PKTHDR() will leak mbuf tags.
See similar rum(4) commit for more info. OK mglocker@


# 1.29 17-Dec-2006 damien

fix index of ERP information element in beacons.
still ugly, but correct.


# 1.28 03-Dec-2006 damien

fix handling of the SIOCS80211CHANNEL ioctl in monitor mode:
don't call xxx_set_chan() if the interface is not up&running.

patch from Steffen Schuetz (st dot sch at gmx dot net) with
minor modifications by me.

closes kernel/5313


# 1.27 26-Nov-2006 deraadt

do not have each net80211 driver define its own rates structures. if they use
the standard rates, use some defined by net80211 itself. kernel shrinks a bit
ok jsg mglocker


# 1.26 22-Nov-2006 damien

don't write to BBP before it is ready and fully initialized
-> move rt2560_set{tx,rx}antenna() after rt2560_bbp_init().

from <sephe at dragonflybsd dot org>


# 1.25 13-Nov-2006 damien

first round of commits for proper 11b/g protection support:
- use the newly introduced ieee80211_get_rts() and
ieee80211_get_cts_to_self() functions.
- use CTS-to-self instead of RTS/CTS to protect OFDM frames in
a mixed 11b/g BSS.
- make sure multicast frames are sent using CCK modulation.

remove support for 5GHz radios in ral(4) RT2560 and ural(4).
i'm not aware of any such adapters on the market and 11a code
is known to be broken.

some cleanup while i'm here.


# 1.24 22-Oct-2006 damien

replace rssadapt(9) with amrr for automatic rate control.
as a side-effect, this should fix all the "bogus xmit rate" panics
users have been complaining about for some time when operating in
HostAP mode.


# 1.23 18-Sep-2006 damien

don't use IF_PREPEND() on altq's.
use IFQ_POLL()/IFQ_DEQUEUE() logic instead as described in altq(4).


Revision tags: OPENBSD_4_0_BASE
# 1.22 18-Jul-2006 damien

modify interrupt handlers to exit early and return 0 on shared interrupts.

pointed out by deraadt@


# 1.21 18-Jun-2006 damien

- implement new ic_updateslot() callback.
- in hostap mode, we defer update of the slot time until all associated
STAs are notified with updated beacons.


# 1.20 18-Jun-2006 damien

enable packet bursting when operating as a STA.
limit bursts to 8 frames.


# 1.19 14-Jun-2006 damien

must use RTS/CTS protection when sending frames at OFDM rates in a BSS
with non-ERP STAs. some bits are missing in net80211 though, so this
code won't be triggered yet.


# 1.18 10-Jun-2006 damien

- fix checking of WEP flags
- encrypt mgmt frames when they need to (shared authmode)
- move default MAC/BBP/RF settings from rt2560.c to rt2560reg.h


# 1.17 02-Jun-2006 robert

add powerhooks for ral(4) cards with the RT2560 chipset;

ok damien@


# 1.16 01-Jun-2006 robert

Make the debug printfs work if RAL_DEBUG is defined.


# 1.15 20-Apr-2006 miod

Fix various printf() issues: too many arguments, not enough arguments, argument
order reversed, wrong modifiers. ok deraadt@ marco@ mickey@


# 1.14 27-Mar-2006 damien

fixes interrupts processing.

should fix a panic reported by Karel Gardas.


# 1.13 25-Mar-2006 djm

allow bpf(4) to ignore packets based on their direction (inbound or
outbound), using a new BIOCSDIRFILT ioctl;
guidance, feedback and ok canacar@


Revision tags: OPENBSD_3_9_BASE
# 1.12 25-Feb-2006 damien

branches: 1.12.2;
instead of panicing when tx rate is zero, fallback to 1Mbps.
this is a temporary workaround since we should really not see any node
with an empty rate set but it seems to happen in hostap mode.


# 1.11 18-Feb-2006 damien

don't try to release references to nodes that have been freed by net80211.
in HostAP mode, when switching to the INIT state, net80211 sends a DISASSOC
and a DEAUTH frame to all associated stations and immediately free all the
nodes while we may still hold references to them in our Tx queues.

hopefully, this should fix PRs 4469/kernel and 4953/kernel.


# 1.10 14-Jan-2006 damien

- give rate to rx radiotap
- read TSF high 32bit word before low 32bit word to avoid wraparounds


# 1.9 14-Jan-2006 jsg

Correct the length of the rx radiotap to be that of the rx not tx
struct.

ok damien@


# 1.8 13-Jan-2006 damien

fix short slot time + cosmetic


# 1.7 13-Jan-2006 damien

- simplify lookup of 802.11a channels (we know they exist)
- kill two stupid comments while i'm here


# 1.6 11-Jan-2006 damien

fix RTS protection mode.


# 1.5 10-Jan-2006 damien

- use rssadapt(9) as rate control algorithm
- add 802.11 radiotap support
- read 802.11a channels tx power from EEPROM
- read vendor-specific BBP settings from EEPROM
- fix setting of beacons (xflags)
- fix DMA sync in rt2661_rx_intr
- indicate whether RF supports MIMO in dmesg
- add short slot time support
- many cleanups while i'm here


# 1.4 10-Jan-2006 damien

fix reading of EEPROM content on big endian arches.


# 1.3 10-Jan-2006 damien

send management, control and beacon frames at the lowest possible rate
(1Mbps for 802.11b/g, 6Mbps for 802.11a)


# 1.2 10-Jan-2006 damien

cleanup rt2560_setup_tx_desc().
fix contention window.


# 1.1 09-Jan-2006 damien

- add preliminary support for Ralink Technology RT2561, RT2561S and RT2661
chipsets in ral(4).
- restructure the code a bit; split ic/ral.c into ic/rt2560.c and ic/rt2661.c
- import the 8051 microcode files required by these chipsets.
- more to come; there is currently no automatic rate control and some
features are untested (hostap and ibss modes for instance). most of
the pre-802.11n capabilities of the RT2661 chipset are not supported
(like frame aggregation, piggy-back). MIMO should work though the
performance/range gain has not been measured.


# 1.88 20-Jul-2020 stsp

The IEEE80211_F_HIDENWID flag is now part of ic_userflags, not ic_flags.
Fix code which was still looking for this flag at the old location.

The 'hidenwid' feature was slightly broken as a result: The SSID was leaked
in probe responses to wildcard probe requests. There are other trivial ways
of snooping a "hidden" SSID however so this is not a big deal.

Problem reported by Mogens Jensen.


# 1.87 10-Jul-2020 patrick

Change users of IFQ_DEQUEUE(), IFQ_ENQUEUE() and IFQ_LEN() to use the
"new" API.

ok dlg@ tobhe@


Revision tags: OPENBSD_6_7_BASE
# 1.86 19-Feb-2020 claudio

Similar to other wireless drivers use bpf_mtap_hdr() to prepend the
radiotap header instead of using a fack mbuf in the stack.
OK stsp@


Revision tags: OPENBSD_6_6_BASE
# 1.85 12-Sep-2019 stsp

Make wireless drivers call if_input() only once per interrupt.

This reduces drops caused by the ifq pressure drop mechanism and hence
increases throughput. Such drops are visible with e.g. 'netstat -dnI iwm0'.

Not all affected drivers have been tested yet but these changes are largely
mechanical and should be safe. As usual, please report any regressions.

With help from dlg@ and mpi@

Problem found by robert@
Tested by robert, jmc, Tracey Emer, Matthias Schmidt, florian, Bj��rn Ketelaars
ok mpi@


Revision tags: OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.84 26-Oct-2017 mpi

Move common code to add/remove multicast filters to ieee80211_ioctl(9).

ok jsg@, stsp@


Revision tags: OPENBSD_6_2_BASE
# 1.83 03-Jul-2017 kevlo

Replace slot time durations with macros.

ok stsp@


Revision tags: OPENBSD_6_1_BASE
# 1.82 22-Jan-2017 dlg

move counting if_opackets next to counting if_obytes in if_enqueue.

this means packets are consistently counted in one place, unlike the
many and various ways that drivers thought they should do it.

ok mpi@ deraadt@


# 1.81 06-Oct-2016 stsp

Disable RTS for long frames in ral(4) for rt2560 chips.
On these chips RTS causes bad performance in hostap mode for unknown reasons.

Convert some debug printfs to DPRINTF.
Add a comment which explains why 2 free slots are needed on the Tx queue.

ok phessler@ sthen@


Revision tags: OPENBSD_6_0_BASE
# 1.80 13-Apr-2016 mpi

G/C IFQ_SET_READY().


Revision tags: OPENBSD_5_9_BASE
# 1.79 05-Dec-2015 dlg

ifq_deq_rollback without a preceding ifq_deq_begin is fail.

caused by a badly managed merge.

found by and testing by sebastia@
ok mpi@


# 1.78 25-Nov-2015 dlg

replace IFF_OACTIVE manipulation with mpsafe operations.

there are two things shared between the network stack and drivers
in the send path: the send queue and the IFF_OACTIVE flag. the send
queue is now protected by a mutex. this diff makes the oactive
functionality mpsafe too.

IFF_OACTIVE is part of if_flags. there are two problems with that.
firstly, if_flags is a short and we dont have any MI atomic operations
to manipulate a short. secondly, while we could make the IFF_OACTIVE
operates mpsafe, all changes to other flags would have to be made
safe at the same time, otherwise a read-modify-write cycle on their
updates could clobber the oactive change.

instead, this moves the oactive mark into struct ifqueue and provides
an API for changing it. there's ifq_set_oactive, ifq_clr_oactive,
and ifq_is_oactive. these are modelled on ifsq_set_oactive,
ifsq_clr_oactive, and ifsq_is_oactive in dragonflybsd.

this diff includes changes to all the drivers manipulating IFF_OACTIVE
to now use the ifsq_{set,clr_is}_oactive API too.

ok kettenis@ mpi@ jmatthew@ deraadt@


# 1.77 24-Nov-2015 mpi

The only network driver needing <net/if_types.h> is upl(4) for IFT_OTHER.


# 1.76 20-Nov-2015 mpi

Check for space on the ring before dequeuing packets.

Allows us to get rid of mq_requeue(9) and IFQ_POLL(9) because wireless
drivers use a special queue for management frames.

Tested by stsp@, ok dlg@, stsp@


# 1.75 20-Nov-2015 dlg

shuffle struct ifqueue so in flight mbufs are protected by a mutex.

the code is refactored so the IFQ macros call newly implemented ifq
functions. the ifq code is split so each discipline (priq and hfsc
in our case) is an opaque set of operations that the common ifq
code can call. the common code does the locking, accounting (ifq_len
manipulation), and freeing of the mbuf if the disciplines enqueue
function rejects it. theyre kind of like bufqs in the block layer
with their fifo and nscan disciplines.

the new api also supports atomic switching of disciplines at runtime.
the hfsc setup in pf_ioctl.c has been tweaked to build a complete
hfsc_if structure which it attaches to the send queue in a single
operation, rather than attaching to the interface up front and
building up a list of queues.

the send queue is now mutexed, which raises the expectation that
packets can be enqueued or purged on one cpu while another cpu is
dequeueing them in a driver for transmission. a lot of drivers use
IFQ_POLL to peek at an mbuf and attempt to fit it on the ring before
committing to it with a later IFQ_DEQUEUE operation. if the mbuf
gets freed in between the POLL and DEQUEUE operations, fireworks
will ensue.

to avoid this, the ifq api introduces ifq_deq_begin, ifq_deq_rollback,
and ifq_deq_commit. ifq_deq_begin allows a driver to take the ifq
mutex and get a reference to the mbuf they wish to try and tx. if
there's space, they can ifq_deq_commit it to remove the mbuf and
release the mutex. if there's no space, ifq_deq_rollback simply
releases the mutex. this api was developed to make updating the
drivers using IFQ_POLL easy, instead of having to do significant
semantic changes to avoid POLL that we cannot test on all the
hardware.

the common code has been tested pretty hard, and all the driver
modifications are straightforward except for de(4). if that breaks
it can be dealt with later.

ok mpi@ jmatthew@


# 1.74 04-Nov-2015 dlg

replace the ifqueues in net80211 with mbuf_queues.

the specific queues are ic_mgtq, ic_pwrsaveq, and ni_savedq. rtw
had its own queue for beacons.

tested by mpi@ and jmc@
ok mpi@


# 1.73 25-Oct-2015 mpi

arp_ifinit() is no longer needed.


# 1.72 09-Sep-2015 deraadt

sizes for free(); ok semarie


Revision tags: OPENBSD_5_8_BASE
# 1.71 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.70 10-Feb-2015 mpi

Wireless drivers call if_input() via ieee80211_input() which set `rcvif'
on every received mbuf, so there's no need to initialize this pointer in
the drivers.

Tested by and ok phessler@


# 1.69 22-Dec-2014 tedu

unifdef INET


# 1.68 19-Dec-2014 guenther

Use <sys/endian.h> instead of <machine/endian.h>

ok dlg@ mpi@ bcook@ millert@ miod@


# 1.67 06-Sep-2014 jsg

reduce the amount of pci includes


Revision tags: OPENBSD_5_6_BASE
# 1.66 22-Jul-2014 mpi

Fewer <netinet/in_systm.h>


# 1.65 13-Jul-2014 deraadt

Some reallocarray() use; review Jean-Philippe Ouellet, patrick keshishian
ok tedu


# 1.64 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


# 1.63 19-Mar-2014 mpi

Stop abusing the rcvif pointer to pass wireless nodes down to the
driver start routines. Instead add & use a pointer in the pkthdr
since we don't want the overhead of using a mbuf_tags(9).

claudio@ pointed out that other subsystems might want to use this
pointer too, so here's a new cookie!

ok claudio@, mikeb@, deraadt@


Revision tags: OPENBSD_5_5_BASE
# 1.62 06-Dec-2013 deraadt

Add a DVACT_WAKEUP op to the *_activate() API. This is called after the
kernel resumes normal (non-cold, able to run processes, etc) operation.
Previously we were relying on specific DVACT_RESUME op's in drivers
creating callback/threads themselves, but that has become too common,
indicating the need for a built-in mechanism.
ok dlg kettenis, tested by a sufficient amount of people


# 1.61 07-Aug-2013 bluhm

Most network drivers include netinet/in_var.h, but apparently they
don't have to. Just remove these include lines.
Compiled on amd64 i386 sparc64; OK henning@ mikeb@


Revision tags: OPENBSD_5_2_BASE OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.60 13-Jul-2012 stsp

Keep separate OACTIVE flags to mark full management/data tx queues,
and set the interface's IFF_OACTIVE flag if either queue is full and
clear it only if both queues have free slots. Before this change both
queues were setting/clearing the same flag with no regard for the
other queue's state.

Also, don't reset the tx watchdog counter if either queue still has frames
queued when we exit the frame-processing loop in the per-queue interrupt
handlers.

Both changes originally from sephe@dragonfly.

Tested by myself and edd on a slow busy soekris which before this
change required occasional 'ifconfig ral0 down up' to recover.


# 1.59 13-Jul-2012 stsp

Init the baseband processor before selecting antennas since selecting antennas
involves tweaking of BBP registers. Wait for BBP to stop being busy before
reading from it.

Originally from sephe@dragonfly. ok kettenis sthen


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.58 22-Feb-2011 kettenis

Mark descriptors as invalid *before* unmapping the associated mbuf.
Might prevent the unrecoverable DMA error mentioned in PR 6557.

ok damien@


# 1.57 07-Sep-2010 deraadt

remove the powerhook code. All architectures now use the ca_activate tree
traversal code to suspend/resume
ok oga kettenis blambert


# 1.56 06-Sep-2010 deraadt

All PWR_{SUSPEND,RESUME} can now be replaced by DVACT_{SUSPEND,RESUME}


# 1.55 06-Sep-2010 kettenis

Make the interrupt handler bail out early if the device wen away. Fixes
freezes that occur when removing CardBus cards when the interface is up.

ok deraadt@


# 1.54 28-Aug-2010 deraadt

rename the *_power functions to *_powerhook to indicate that we've been
here already for the activate/powerhook cleanup


# 1.53 27-Aug-2010 jsg

remove the unused if_init callback in struct ifnet
ok deraadt@ henning@ claudio@


# 1.52 27-Aug-2010 kettenis

Stop calling xxx_power() from xxx_resume(); instead do it the other way around.
Get rid of the sc_power() callback, which isn't used anymore.

ok deraadt@


# 1.51 27-Aug-2010 deraadt

kill PWR_STANDBY (apm can use PWR_SUSPEND instead). While here, renumber
PWR_{SUSPEND,RESUME} so that they match the values of DAVCT_{SUSPEND,RESUME}
so that we can eventually (many more steps...) kill the powerhook garbage
and use the activate mechanism.
no objections


# 1.50 25-Aug-2010 kettenis

Make CardBus ral(4) suspend and resume properly on machines that keep the
CardBus bridge powered up during suspend. Step zero on the long road
towards fully suspending CardBus on all machines.

ok deraadt@, damien@


Revision tags: OPENBSD_4_8_BASE
# 1.49 04-Aug-2010 damien

add suspend/resume support for PCI ral(4) devices.

ok deraadt@, sthen@

tested by matthew@ (RT2560), dcoppa@ (RT2790), okan@ (RT2860), todd@ (RT2560)


# 1.48 19-May-2010 oga

BUS_DMA_ZERO instead of alloc, map, bzero.

ok krw@


# 1.47 20-Apr-2010 tedu

remove proc.h include from uvm_map.h. This has far reaching effects, as
sysctl.h was reliant on this particular include, and many drivers included
sysctl.h unnecessarily. remove sysctl.h or add proc.h as needed.
ok deraadt


Revision tags: OPENBSD_4_7_BASE
# 1.46 01-Nov-2009 damien

call powerhook_disestablish() and pci_intr_disestablish() earlier.

diff from deraadt@


# 1.45 10-Aug-2009 damien

three more shutdown hooks bite the dust.


# 1.44 29-Jul-2009 blambert

timeout_add -> timeout_add_msec

ok damien@


Revision tags: OPENBSD_4_6_BASE
# 1.43 29-Mar-2009 sthen

make various strings ("can't map mem space" and similar) more consistent
between instances, saving space in the kernel. feedback from many (some
incorporated, some left for future work).

ok deraadt, kettenis, "why not" miod.


Revision tags: OPENBSD_4_5_BASE
# 1.42 22-Dec-2008 damien

I swapped MGETHDR arguments in my m_defrag removal commit.


# 1.41 21-Dec-2008 damien

Undo m_defrag().

m_defrag() does not work. It seems to assume that if the length of
the mbuf passed as parameter is less than MHLEN, then it is an mbuf
header and not a cluster (or something like that.)
It thus fails miserably in the bcopy path.
I don't have the time to investigate further into this.

Thanks to Okan Demirmen for reporting the issue on a ral(4) RT2560.
The RT2560 chipset does not support TX scatter and thus m_defrag()
was called much more often than in other drivers using m_defrag()
where it was less noticeable.


# 1.40 25-Nov-2008 damien

use shiny new m_defrag() and nitems() instead of rolling our own.


# 1.39 27-Aug-2008 damien

introduce new IEEE80211_STA_ONLY kernel option that can be set to
remove IBSS and HostAP support from net80211 and 802.11 drivers.
it can be used to shrink RAMDISK kernels for instance (like what
was done for wi(4)).
it also has the benefit of highlighting what is specific to IBSS
and HostAP modes in the code.
the cost is that we now have two code paths to maintain.


# 1.38 14-Aug-2008 damien

in ieee80211_input(), call if_start() after enqueuing frames in if_snd
when acting as an access point instead of having each driver doing the
job.

tested by krw@ (ral AP) and me with several drivers.


Revision tags: OPENBSD_4_4_BASE
# 1.37 21-Jul-2008 damien

instead of passing rx tstamp and rssi to the ieee80211_input function,
pass a pointer to an ieee80211_rxinfo structure containing those two
fields plus an extra flags field that indicates whether the frame was
decrypted by hardware or not.
required for a future fix.


# 1.36 16-Apr-2008 damien

Kernel implementation of the 4-way handshake and group-key
handshake protocols (both supplicant and authenticator state
machines) as defined in the IEEE 802.11i standard.

Software implementation of the TKIP (Temporal Key Integrity
Protocol) and CCMP (CTR with CBC-MAC Protocol) protocols.

This diff doesn't implement any of the 802.1X authentication
protocols and thus only PSK authentication (using pre-shared
keys) is currently supported.

In concrete terms, this adds support for WPA-PSK and WPA2-PSK
protocols, both in station and hostap modes.

The following drivers are marked as WPA-capable and should
work: bwi(4), malo(4), ral(4), iwn(4), wpi(4), ural(4),
rum(4), upgt(4), and zyd(4)

The following options have been added to ifconfig(8):
wpa, wpapsk, wpaprotos, wpaakms, wpaciphers, wpagroupcipher

wpa-psk(8) can be used to generate keys from passphrases.

tested by many@
ok deraadt@


Revision tags: OPENBSD_4_3_BASE
# 1.35 17-Nov-2007 damien

RT2560+RT2661: update the physical address in the RX descriptor after
bus_dmamap_load() in the case where the same mbuf is reloaded.
RT2661: remove a 2x prototype, fix an error message.


# 1.34 15-Oct-2007 fgsch

more remove unneeded declarations that shadows existing vars; ok by many.


# 1.33 07-Sep-2007 damien

use new malloc M_ZERO flag to shrink kernel.
remove <malloc.h> from files where malloc is not used.


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.32 08-Mar-2007 deraadt

XXX commit a workaround (as found in a few other drivers) for the
divide by zero rate bug. Someone has to find the source of this
bug one day; from jsg


# 1.31 24-Jan-2007 damien

revert changes committed between r1.25 and 1.26.
this breaks some RT2560 adapters.

pointed out by krw@ and Pierre Riteau.


# 1.30 03-Jan-2007 claudio

M_DUP_PKTHDR() cleanup. On static buffers M_DUP_PKTHDR() will leak mbuf tags.
See similar rum(4) commit for more info. OK mglocker@


# 1.29 17-Dec-2006 damien

fix index of ERP information element in beacons.
still ugly, but correct.


# 1.28 03-Dec-2006 damien

fix handling of the SIOCS80211CHANNEL ioctl in monitor mode:
don't call xxx_set_chan() if the interface is not up&running.

patch from Steffen Schuetz (st dot sch at gmx dot net) with
minor modifications by me.

closes kernel/5313


# 1.27 26-Nov-2006 deraadt

do not have each net80211 driver define its own rates structures. if they use
the standard rates, use some defined by net80211 itself. kernel shrinks a bit
ok jsg mglocker


# 1.26 22-Nov-2006 damien

don't write to BBP before it is ready and fully initialized
-> move rt2560_set{tx,rx}antenna() after rt2560_bbp_init().

from <sephe at dragonflybsd dot org>


# 1.25 13-Nov-2006 damien

first round of commits for proper 11b/g protection support:
- use the newly introduced ieee80211_get_rts() and
ieee80211_get_cts_to_self() functions.
- use CTS-to-self instead of RTS/CTS to protect OFDM frames in
a mixed 11b/g BSS.
- make sure multicast frames are sent using CCK modulation.

remove support for 5GHz radios in ral(4) RT2560 and ural(4).
i'm not aware of any such adapters on the market and 11a code
is known to be broken.

some cleanup while i'm here.


# 1.24 22-Oct-2006 damien

replace rssadapt(9) with amrr for automatic rate control.
as a side-effect, this should fix all the "bogus xmit rate" panics
users have been complaining about for some time when operating in
HostAP mode.


# 1.23 18-Sep-2006 damien

don't use IF_PREPEND() on altq's.
use IFQ_POLL()/IFQ_DEQUEUE() logic instead as described in altq(4).


Revision tags: OPENBSD_4_0_BASE
# 1.22 18-Jul-2006 damien

modify interrupt handlers to exit early and return 0 on shared interrupts.

pointed out by deraadt@


# 1.21 18-Jun-2006 damien

- implement new ic_updateslot() callback.
- in hostap mode, we defer update of the slot time until all associated
STAs are notified with updated beacons.


# 1.20 18-Jun-2006 damien

enable packet bursting when operating as a STA.
limit bursts to 8 frames.


# 1.19 14-Jun-2006 damien

must use RTS/CTS protection when sending frames at OFDM rates in a BSS
with non-ERP STAs. some bits are missing in net80211 though, so this
code won't be triggered yet.


# 1.18 10-Jun-2006 damien

- fix checking of WEP flags
- encrypt mgmt frames when they need to (shared authmode)
- move default MAC/BBP/RF settings from rt2560.c to rt2560reg.h


# 1.17 02-Jun-2006 robert

add powerhooks for ral(4) cards with the RT2560 chipset;

ok damien@


# 1.16 01-Jun-2006 robert

Make the debug printfs work if RAL_DEBUG is defined.


# 1.15 20-Apr-2006 miod

Fix various printf() issues: too many arguments, not enough arguments, argument
order reversed, wrong modifiers. ok deraadt@ marco@ mickey@


# 1.14 27-Mar-2006 damien

fixes interrupts processing.

should fix a panic reported by Karel Gardas.


# 1.13 25-Mar-2006 djm

allow bpf(4) to ignore packets based on their direction (inbound or
outbound), using a new BIOCSDIRFILT ioctl;
guidance, feedback and ok canacar@


Revision tags: OPENBSD_3_9_BASE
# 1.12 25-Feb-2006 damien

branches: 1.12.2;
instead of panicing when tx rate is zero, fallback to 1Mbps.
this is a temporary workaround since we should really not see any node
with an empty rate set but it seems to happen in hostap mode.


# 1.11 18-Feb-2006 damien

don't try to release references to nodes that have been freed by net80211.
in HostAP mode, when switching to the INIT state, net80211 sends a DISASSOC
and a DEAUTH frame to all associated stations and immediately free all the
nodes while we may still hold references to them in our Tx queues.

hopefully, this should fix PRs 4469/kernel and 4953/kernel.


# 1.10 14-Jan-2006 damien

- give rate to rx radiotap
- read TSF high 32bit word before low 32bit word to avoid wraparounds


# 1.9 14-Jan-2006 jsg

Correct the length of the rx radiotap to be that of the rx not tx
struct.

ok damien@


# 1.8 13-Jan-2006 damien

fix short slot time + cosmetic


# 1.7 13-Jan-2006 damien

- simplify lookup of 802.11a channels (we know they exist)
- kill two stupid comments while i'm here


# 1.6 11-Jan-2006 damien

fix RTS protection mode.


# 1.5 10-Jan-2006 damien

- use rssadapt(9) as rate control algorithm
- add 802.11 radiotap support
- read 802.11a channels tx power from EEPROM
- read vendor-specific BBP settings from EEPROM
- fix setting of beacons (xflags)
- fix DMA sync in rt2661_rx_intr
- indicate whether RF supports MIMO in dmesg
- add short slot time support
- many cleanups while i'm here


# 1.4 10-Jan-2006 damien

fix reading of EEPROM content on big endian arches.


# 1.3 10-Jan-2006 damien

send management, control and beacon frames at the lowest possible rate
(1Mbps for 802.11b/g, 6Mbps for 802.11a)


# 1.2 10-Jan-2006 damien

cleanup rt2560_setup_tx_desc().
fix contention window.


# 1.1 09-Jan-2006 damien

- add preliminary support for Ralink Technology RT2561, RT2561S and RT2661
chipsets in ral(4).
- restructure the code a bit; split ic/ral.c into ic/rt2560.c and ic/rt2661.c
- import the 8051 microcode files required by these chipsets.
- more to come; there is currently no automatic rate control and some
features are untested (hostap and ibss modes for instance). most of
the pre-802.11n capabilities of the RT2661 chipset are not supported
(like frame aggregation, piggy-back). MIMO should work though the
performance/range gain has not been measured.


# 1.87 10-Jul-2020 patrick

Change users of IFQ_DEQUEUE(), IFQ_ENQUEUE() and IFQ_LEN() to use the
"new" API.

ok dlg@ tobhe@


Revision tags: OPENBSD_6_7_BASE
# 1.86 19-Feb-2020 claudio

Similar to other wireless drivers use bpf_mtap_hdr() to prepend the
radiotap header instead of using a fack mbuf in the stack.
OK stsp@


Revision tags: OPENBSD_6_6_BASE
# 1.85 12-Sep-2019 stsp

Make wireless drivers call if_input() only once per interrupt.

This reduces drops caused by the ifq pressure drop mechanism and hence
increases throughput. Such drops are visible with e.g. 'netstat -dnI iwm0'.

Not all affected drivers have been tested yet but these changes are largely
mechanical and should be safe. As usual, please report any regressions.

With help from dlg@ and mpi@

Problem found by robert@
Tested by robert, jmc, Tracey Emer, Matthias Schmidt, florian, Bj��rn Ketelaars
ok mpi@


Revision tags: OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.84 26-Oct-2017 mpi

Move common code to add/remove multicast filters to ieee80211_ioctl(9).

ok jsg@, stsp@


Revision tags: OPENBSD_6_2_BASE
# 1.83 03-Jul-2017 kevlo

Replace slot time durations with macros.

ok stsp@


Revision tags: OPENBSD_6_1_BASE
# 1.82 22-Jan-2017 dlg

move counting if_opackets next to counting if_obytes in if_enqueue.

this means packets are consistently counted in one place, unlike the
many and various ways that drivers thought they should do it.

ok mpi@ deraadt@


# 1.81 06-Oct-2016 stsp

Disable RTS for long frames in ral(4) for rt2560 chips.
On these chips RTS causes bad performance in hostap mode for unknown reasons.

Convert some debug printfs to DPRINTF.
Add a comment which explains why 2 free slots are needed on the Tx queue.

ok phessler@ sthen@


Revision tags: OPENBSD_6_0_BASE
# 1.80 13-Apr-2016 mpi

G/C IFQ_SET_READY().


Revision tags: OPENBSD_5_9_BASE
# 1.79 05-Dec-2015 dlg

ifq_deq_rollback without a preceding ifq_deq_begin is fail.

caused by a badly managed merge.

found by and testing by sebastia@
ok mpi@


# 1.78 25-Nov-2015 dlg

replace IFF_OACTIVE manipulation with mpsafe operations.

there are two things shared between the network stack and drivers
in the send path: the send queue and the IFF_OACTIVE flag. the send
queue is now protected by a mutex. this diff makes the oactive
functionality mpsafe too.

IFF_OACTIVE is part of if_flags. there are two problems with that.
firstly, if_flags is a short and we dont have any MI atomic operations
to manipulate a short. secondly, while we could make the IFF_OACTIVE
operates mpsafe, all changes to other flags would have to be made
safe at the same time, otherwise a read-modify-write cycle on their
updates could clobber the oactive change.

instead, this moves the oactive mark into struct ifqueue and provides
an API for changing it. there's ifq_set_oactive, ifq_clr_oactive,
and ifq_is_oactive. these are modelled on ifsq_set_oactive,
ifsq_clr_oactive, and ifsq_is_oactive in dragonflybsd.

this diff includes changes to all the drivers manipulating IFF_OACTIVE
to now use the ifsq_{set,clr_is}_oactive API too.

ok kettenis@ mpi@ jmatthew@ deraadt@


# 1.77 24-Nov-2015 mpi

The only network driver needing <net/if_types.h> is upl(4) for IFT_OTHER.


# 1.76 20-Nov-2015 mpi

Check for space on the ring before dequeuing packets.

Allows us to get rid of mq_requeue(9) and IFQ_POLL(9) because wireless
drivers use a special queue for management frames.

Tested by stsp@, ok dlg@, stsp@


# 1.75 20-Nov-2015 dlg

shuffle struct ifqueue so in flight mbufs are protected by a mutex.

the code is refactored so the IFQ macros call newly implemented ifq
functions. the ifq code is split so each discipline (priq and hfsc
in our case) is an opaque set of operations that the common ifq
code can call. the common code does the locking, accounting (ifq_len
manipulation), and freeing of the mbuf if the disciplines enqueue
function rejects it. theyre kind of like bufqs in the block layer
with their fifo and nscan disciplines.

the new api also supports atomic switching of disciplines at runtime.
the hfsc setup in pf_ioctl.c has been tweaked to build a complete
hfsc_if structure which it attaches to the send queue in a single
operation, rather than attaching to the interface up front and
building up a list of queues.

the send queue is now mutexed, which raises the expectation that
packets can be enqueued or purged on one cpu while another cpu is
dequeueing them in a driver for transmission. a lot of drivers use
IFQ_POLL to peek at an mbuf and attempt to fit it on the ring before
committing to it with a later IFQ_DEQUEUE operation. if the mbuf
gets freed in between the POLL and DEQUEUE operations, fireworks
will ensue.

to avoid this, the ifq api introduces ifq_deq_begin, ifq_deq_rollback,
and ifq_deq_commit. ifq_deq_begin allows a driver to take the ifq
mutex and get a reference to the mbuf they wish to try and tx. if
there's space, they can ifq_deq_commit it to remove the mbuf and
release the mutex. if there's no space, ifq_deq_rollback simply
releases the mutex. this api was developed to make updating the
drivers using IFQ_POLL easy, instead of having to do significant
semantic changes to avoid POLL that we cannot test on all the
hardware.

the common code has been tested pretty hard, and all the driver
modifications are straightforward except for de(4). if that breaks
it can be dealt with later.

ok mpi@ jmatthew@


# 1.74 04-Nov-2015 dlg

replace the ifqueues in net80211 with mbuf_queues.

the specific queues are ic_mgtq, ic_pwrsaveq, and ni_savedq. rtw
had its own queue for beacons.

tested by mpi@ and jmc@
ok mpi@


# 1.73 25-Oct-2015 mpi

arp_ifinit() is no longer needed.


# 1.72 09-Sep-2015 deraadt

sizes for free(); ok semarie


Revision tags: OPENBSD_5_8_BASE
# 1.71 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.70 10-Feb-2015 mpi

Wireless drivers call if_input() via ieee80211_input() which set `rcvif'
on every received mbuf, so there's no need to initialize this pointer in
the drivers.

Tested by and ok phessler@


# 1.69 22-Dec-2014 tedu

unifdef INET


# 1.68 19-Dec-2014 guenther

Use <sys/endian.h> instead of <machine/endian.h>

ok dlg@ mpi@ bcook@ millert@ miod@


# 1.67 06-Sep-2014 jsg

reduce the amount of pci includes


Revision tags: OPENBSD_5_6_BASE
# 1.66 22-Jul-2014 mpi

Fewer <netinet/in_systm.h>


# 1.65 13-Jul-2014 deraadt

Some reallocarray() use; review Jean-Philippe Ouellet, patrick keshishian
ok tedu


# 1.64 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


# 1.63 19-Mar-2014 mpi

Stop abusing the rcvif pointer to pass wireless nodes down to the
driver start routines. Instead add & use a pointer in the pkthdr
since we don't want the overhead of using a mbuf_tags(9).

claudio@ pointed out that other subsystems might want to use this
pointer too, so here's a new cookie!

ok claudio@, mikeb@, deraadt@


Revision tags: OPENBSD_5_5_BASE
# 1.62 06-Dec-2013 deraadt

Add a DVACT_WAKEUP op to the *_activate() API. This is called after the
kernel resumes normal (non-cold, able to run processes, etc) operation.
Previously we were relying on specific DVACT_RESUME op's in drivers
creating callback/threads themselves, but that has become too common,
indicating the need for a built-in mechanism.
ok dlg kettenis, tested by a sufficient amount of people


# 1.61 07-Aug-2013 bluhm

Most network drivers include netinet/in_var.h, but apparently they
don't have to. Just remove these include lines.
Compiled on amd64 i386 sparc64; OK henning@ mikeb@


Revision tags: OPENBSD_5_2_BASE OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.60 13-Jul-2012 stsp

Keep separate OACTIVE flags to mark full management/data tx queues,
and set the interface's IFF_OACTIVE flag if either queue is full and
clear it only if both queues have free slots. Before this change both
queues were setting/clearing the same flag with no regard for the
other queue's state.

Also, don't reset the tx watchdog counter if either queue still has frames
queued when we exit the frame-processing loop in the per-queue interrupt
handlers.

Both changes originally from sephe@dragonfly.

Tested by myself and edd on a slow busy soekris which before this
change required occasional 'ifconfig ral0 down up' to recover.


# 1.59 13-Jul-2012 stsp

Init the baseband processor before selecting antennas since selecting antennas
involves tweaking of BBP registers. Wait for BBP to stop being busy before
reading from it.

Originally from sephe@dragonfly. ok kettenis sthen


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.58 22-Feb-2011 kettenis

Mark descriptors as invalid *before* unmapping the associated mbuf.
Might prevent the unrecoverable DMA error mentioned in PR 6557.

ok damien@


# 1.57 07-Sep-2010 deraadt

remove the powerhook code. All architectures now use the ca_activate tree
traversal code to suspend/resume
ok oga kettenis blambert


# 1.56 06-Sep-2010 deraadt

All PWR_{SUSPEND,RESUME} can now be replaced by DVACT_{SUSPEND,RESUME}


# 1.55 06-Sep-2010 kettenis

Make the interrupt handler bail out early if the device wen away. Fixes
freezes that occur when removing CardBus cards when the interface is up.

ok deraadt@


# 1.54 28-Aug-2010 deraadt

rename the *_power functions to *_powerhook to indicate that we've been
here already for the activate/powerhook cleanup


# 1.53 27-Aug-2010 jsg

remove the unused if_init callback in struct ifnet
ok deraadt@ henning@ claudio@


# 1.52 27-Aug-2010 kettenis

Stop calling xxx_power() from xxx_resume(); instead do it the other way around.
Get rid of the sc_power() callback, which isn't used anymore.

ok deraadt@


# 1.51 27-Aug-2010 deraadt

kill PWR_STANDBY (apm can use PWR_SUSPEND instead). While here, renumber
PWR_{SUSPEND,RESUME} so that they match the values of DAVCT_{SUSPEND,RESUME}
so that we can eventually (many more steps...) kill the powerhook garbage
and use the activate mechanism.
no objections


# 1.50 25-Aug-2010 kettenis

Make CardBus ral(4) suspend and resume properly on machines that keep the
CardBus bridge powered up during suspend. Step zero on the long road
towards fully suspending CardBus on all machines.

ok deraadt@, damien@


Revision tags: OPENBSD_4_8_BASE
# 1.49 04-Aug-2010 damien

add suspend/resume support for PCI ral(4) devices.

ok deraadt@, sthen@

tested by matthew@ (RT2560), dcoppa@ (RT2790), okan@ (RT2860), todd@ (RT2560)


# 1.48 19-May-2010 oga

BUS_DMA_ZERO instead of alloc, map, bzero.

ok krw@


# 1.47 20-Apr-2010 tedu

remove proc.h include from uvm_map.h. This has far reaching effects, as
sysctl.h was reliant on this particular include, and many drivers included
sysctl.h unnecessarily. remove sysctl.h or add proc.h as needed.
ok deraadt


Revision tags: OPENBSD_4_7_BASE
# 1.46 01-Nov-2009 damien

call powerhook_disestablish() and pci_intr_disestablish() earlier.

diff from deraadt@


# 1.45 10-Aug-2009 damien

three more shutdown hooks bite the dust.


# 1.44 29-Jul-2009 blambert

timeout_add -> timeout_add_msec

ok damien@


Revision tags: OPENBSD_4_6_BASE
# 1.43 29-Mar-2009 sthen

make various strings ("can't map mem space" and similar) more consistent
between instances, saving space in the kernel. feedback from many (some
incorporated, some left for future work).

ok deraadt, kettenis, "why not" miod.


Revision tags: OPENBSD_4_5_BASE
# 1.42 22-Dec-2008 damien

I swapped MGETHDR arguments in my m_defrag removal commit.


# 1.41 21-Dec-2008 damien

Undo m_defrag().

m_defrag() does not work. It seems to assume that if the length of
the mbuf passed as parameter is less than MHLEN, then it is an mbuf
header and not a cluster (or something like that.)
It thus fails miserably in the bcopy path.
I don't have the time to investigate further into this.

Thanks to Okan Demirmen for reporting the issue on a ral(4) RT2560.
The RT2560 chipset does not support TX scatter and thus m_defrag()
was called much more often than in other drivers using m_defrag()
where it was less noticeable.


# 1.40 25-Nov-2008 damien

use shiny new m_defrag() and nitems() instead of rolling our own.


# 1.39 27-Aug-2008 damien

introduce new IEEE80211_STA_ONLY kernel option that can be set to
remove IBSS and HostAP support from net80211 and 802.11 drivers.
it can be used to shrink RAMDISK kernels for instance (like what
was done for wi(4)).
it also has the benefit of highlighting what is specific to IBSS
and HostAP modes in the code.
the cost is that we now have two code paths to maintain.


# 1.38 14-Aug-2008 damien

in ieee80211_input(), call if_start() after enqueuing frames in if_snd
when acting as an access point instead of having each driver doing the
job.

tested by krw@ (ral AP) and me with several drivers.


Revision tags: OPENBSD_4_4_BASE
# 1.37 21-Jul-2008 damien

instead of passing rx tstamp and rssi to the ieee80211_input function,
pass a pointer to an ieee80211_rxinfo structure containing those two
fields plus an extra flags field that indicates whether the frame was
decrypted by hardware or not.
required for a future fix.


# 1.36 16-Apr-2008 damien

Kernel implementation of the 4-way handshake and group-key
handshake protocols (both supplicant and authenticator state
machines) as defined in the IEEE 802.11i standard.

Software implementation of the TKIP (Temporal Key Integrity
Protocol) and CCMP (CTR with CBC-MAC Protocol) protocols.

This diff doesn't implement any of the 802.1X authentication
protocols and thus only PSK authentication (using pre-shared
keys) is currently supported.

In concrete terms, this adds support for WPA-PSK and WPA2-PSK
protocols, both in station and hostap modes.

The following drivers are marked as WPA-capable and should
work: bwi(4), malo(4), ral(4), iwn(4), wpi(4), ural(4),
rum(4), upgt(4), and zyd(4)

The following options have been added to ifconfig(8):
wpa, wpapsk, wpaprotos, wpaakms, wpaciphers, wpagroupcipher

wpa-psk(8) can be used to generate keys from passphrases.

tested by many@
ok deraadt@


Revision tags: OPENBSD_4_3_BASE
# 1.35 17-Nov-2007 damien

RT2560+RT2661: update the physical address in the RX descriptor after
bus_dmamap_load() in the case where the same mbuf is reloaded.
RT2661: remove a 2x prototype, fix an error message.


# 1.34 15-Oct-2007 fgsch

more remove unneeded declarations that shadows existing vars; ok by many.


# 1.33 07-Sep-2007 damien

use new malloc M_ZERO flag to shrink kernel.
remove <malloc.h> from files where malloc is not used.


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.32 08-Mar-2007 deraadt

XXX commit a workaround (as found in a few other drivers) for the
divide by zero rate bug. Someone has to find the source of this
bug one day; from jsg


# 1.31 24-Jan-2007 damien

revert changes committed between r1.25 and 1.26.
this breaks some RT2560 adapters.

pointed out by krw@ and Pierre Riteau.


# 1.30 03-Jan-2007 claudio

M_DUP_PKTHDR() cleanup. On static buffers M_DUP_PKTHDR() will leak mbuf tags.
See similar rum(4) commit for more info. OK mglocker@


# 1.29 17-Dec-2006 damien

fix index of ERP information element in beacons.
still ugly, but correct.


# 1.28 03-Dec-2006 damien

fix handling of the SIOCS80211CHANNEL ioctl in monitor mode:
don't call xxx_set_chan() if the interface is not up&running.

patch from Steffen Schuetz (st dot sch at gmx dot net) with
minor modifications by me.

closes kernel/5313


# 1.27 26-Nov-2006 deraadt

do not have each net80211 driver define its own rates structures. if they use
the standard rates, use some defined by net80211 itself. kernel shrinks a bit
ok jsg mglocker


# 1.26 22-Nov-2006 damien

don't write to BBP before it is ready and fully initialized
-> move rt2560_set{tx,rx}antenna() after rt2560_bbp_init().

from <sephe at dragonflybsd dot org>


# 1.25 13-Nov-2006 damien

first round of commits for proper 11b/g protection support:
- use the newly introduced ieee80211_get_rts() and
ieee80211_get_cts_to_self() functions.
- use CTS-to-self instead of RTS/CTS to protect OFDM frames in
a mixed 11b/g BSS.
- make sure multicast frames are sent using CCK modulation.

remove support for 5GHz radios in ral(4) RT2560 and ural(4).
i'm not aware of any such adapters on the market and 11a code
is known to be broken.

some cleanup while i'm here.


# 1.24 22-Oct-2006 damien

replace rssadapt(9) with amrr for automatic rate control.
as a side-effect, this should fix all the "bogus xmit rate" panics
users have been complaining about for some time when operating in
HostAP mode.


# 1.23 18-Sep-2006 damien

don't use IF_PREPEND() on altq's.
use IFQ_POLL()/IFQ_DEQUEUE() logic instead as described in altq(4).


Revision tags: OPENBSD_4_0_BASE
# 1.22 18-Jul-2006 damien

modify interrupt handlers to exit early and return 0 on shared interrupts.

pointed out by deraadt@


# 1.21 18-Jun-2006 damien

- implement new ic_updateslot() callback.
- in hostap mode, we defer update of the slot time until all associated
STAs are notified with updated beacons.


# 1.20 18-Jun-2006 damien

enable packet bursting when operating as a STA.
limit bursts to 8 frames.


# 1.19 14-Jun-2006 damien

must use RTS/CTS protection when sending frames at OFDM rates in a BSS
with non-ERP STAs. some bits are missing in net80211 though, so this
code won't be triggered yet.


# 1.18 10-Jun-2006 damien

- fix checking of WEP flags
- encrypt mgmt frames when they need to (shared authmode)
- move default MAC/BBP/RF settings from rt2560.c to rt2560reg.h


# 1.17 02-Jun-2006 robert

add powerhooks for ral(4) cards with the RT2560 chipset;

ok damien@


# 1.16 01-Jun-2006 robert

Make the debug printfs work if RAL_DEBUG is defined.


# 1.15 20-Apr-2006 miod

Fix various printf() issues: too many arguments, not enough arguments, argument
order reversed, wrong modifiers. ok deraadt@ marco@ mickey@


# 1.14 27-Mar-2006 damien

fixes interrupts processing.

should fix a panic reported by Karel Gardas.


# 1.13 25-Mar-2006 djm

allow bpf(4) to ignore packets based on their direction (inbound or
outbound), using a new BIOCSDIRFILT ioctl;
guidance, feedback and ok canacar@


Revision tags: OPENBSD_3_9_BASE
# 1.12 25-Feb-2006 damien

branches: 1.12.2;
instead of panicing when tx rate is zero, fallback to 1Mbps.
this is a temporary workaround since we should really not see any node
with an empty rate set but it seems to happen in hostap mode.


# 1.11 18-Feb-2006 damien

don't try to release references to nodes that have been freed by net80211.
in HostAP mode, when switching to the INIT state, net80211 sends a DISASSOC
and a DEAUTH frame to all associated stations and immediately free all the
nodes while we may still hold references to them in our Tx queues.

hopefully, this should fix PRs 4469/kernel and 4953/kernel.


# 1.10 14-Jan-2006 damien

- give rate to rx radiotap
- read TSF high 32bit word before low 32bit word to avoid wraparounds


# 1.9 14-Jan-2006 jsg

Correct the length of the rx radiotap to be that of the rx not tx
struct.

ok damien@


# 1.8 13-Jan-2006 damien

fix short slot time + cosmetic


# 1.7 13-Jan-2006 damien

- simplify lookup of 802.11a channels (we know they exist)
- kill two stupid comments while i'm here


# 1.6 11-Jan-2006 damien

fix RTS protection mode.


# 1.5 10-Jan-2006 damien

- use rssadapt(9) as rate control algorithm
- add 802.11 radiotap support
- read 802.11a channels tx power from EEPROM
- read vendor-specific BBP settings from EEPROM
- fix setting of beacons (xflags)
- fix DMA sync in rt2661_rx_intr
- indicate whether RF supports MIMO in dmesg
- add short slot time support
- many cleanups while i'm here


# 1.4 10-Jan-2006 damien

fix reading of EEPROM content on big endian arches.


# 1.3 10-Jan-2006 damien

send management, control and beacon frames at the lowest possible rate
(1Mbps for 802.11b/g, 6Mbps for 802.11a)


# 1.2 10-Jan-2006 damien

cleanup rt2560_setup_tx_desc().
fix contention window.


# 1.1 09-Jan-2006 damien

- add preliminary support for Ralink Technology RT2561, RT2561S and RT2661
chipsets in ral(4).
- restructure the code a bit; split ic/ral.c into ic/rt2560.c and ic/rt2661.c
- import the 8051 microcode files required by these chipsets.
- more to come; there is currently no automatic rate control and some
features are untested (hostap and ibss modes for instance). most of
the pre-802.11n capabilities of the RT2661 chipset are not supported
(like frame aggregation, piggy-back). MIMO should work though the
performance/range gain has not been measured.


# 1.86 19-Feb-2020 claudio

Similar to other wireless drivers use bpf_mtap_hdr() to prepend the
radiotap header instead of using a fack mbuf in the stack.
OK stsp@


Revision tags: OPENBSD_6_6_BASE
# 1.85 12-Sep-2019 stsp

Make wireless drivers call if_input() only once per interrupt.

This reduces drops caused by the ifq pressure drop mechanism and hence
increases throughput. Such drops are visible with e.g. 'netstat -dnI iwm0'.

Not all affected drivers have been tested yet but these changes are largely
mechanical and should be safe. As usual, please report any regressions.

With help from dlg@ and mpi@

Problem found by robert@
Tested by robert, jmc, Tracey Emer, Matthias Schmidt, florian, Bj��rn Ketelaars
ok mpi@


Revision tags: OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.84 26-Oct-2017 mpi

Move common code to add/remove multicast filters to ieee80211_ioctl(9).

ok jsg@, stsp@


Revision tags: OPENBSD_6_2_BASE
# 1.83 03-Jul-2017 kevlo

Replace slot time durations with macros.

ok stsp@


Revision tags: OPENBSD_6_1_BASE
# 1.82 22-Jan-2017 dlg

move counting if_opackets next to counting if_obytes in if_enqueue.

this means packets are consistently counted in one place, unlike the
many and various ways that drivers thought they should do it.

ok mpi@ deraadt@


# 1.81 06-Oct-2016 stsp

Disable RTS for long frames in ral(4) for rt2560 chips.
On these chips RTS causes bad performance in hostap mode for unknown reasons.

Convert some debug printfs to DPRINTF.
Add a comment which explains why 2 free slots are needed on the Tx queue.

ok phessler@ sthen@


Revision tags: OPENBSD_6_0_BASE
# 1.80 13-Apr-2016 mpi

G/C IFQ_SET_READY().


Revision tags: OPENBSD_5_9_BASE
# 1.79 05-Dec-2015 dlg

ifq_deq_rollback without a preceding ifq_deq_begin is fail.

caused by a badly managed merge.

found by and testing by sebastia@
ok mpi@


# 1.78 25-Nov-2015 dlg

replace IFF_OACTIVE manipulation with mpsafe operations.

there are two things shared between the network stack and drivers
in the send path: the send queue and the IFF_OACTIVE flag. the send
queue is now protected by a mutex. this diff makes the oactive
functionality mpsafe too.

IFF_OACTIVE is part of if_flags. there are two problems with that.
firstly, if_flags is a short and we dont have any MI atomic operations
to manipulate a short. secondly, while we could make the IFF_OACTIVE
operates mpsafe, all changes to other flags would have to be made
safe at the same time, otherwise a read-modify-write cycle on their
updates could clobber the oactive change.

instead, this moves the oactive mark into struct ifqueue and provides
an API for changing it. there's ifq_set_oactive, ifq_clr_oactive,
and ifq_is_oactive. these are modelled on ifsq_set_oactive,
ifsq_clr_oactive, and ifsq_is_oactive in dragonflybsd.

this diff includes changes to all the drivers manipulating IFF_OACTIVE
to now use the ifsq_{set,clr_is}_oactive API too.

ok kettenis@ mpi@ jmatthew@ deraadt@


# 1.77 24-Nov-2015 mpi

The only network driver needing <net/if_types.h> is upl(4) for IFT_OTHER.


# 1.76 20-Nov-2015 mpi

Check for space on the ring before dequeuing packets.

Allows us to get rid of mq_requeue(9) and IFQ_POLL(9) because wireless
drivers use a special queue for management frames.

Tested by stsp@, ok dlg@, stsp@


# 1.75 20-Nov-2015 dlg

shuffle struct ifqueue so in flight mbufs are protected by a mutex.

the code is refactored so the IFQ macros call newly implemented ifq
functions. the ifq code is split so each discipline (priq and hfsc
in our case) is an opaque set of operations that the common ifq
code can call. the common code does the locking, accounting (ifq_len
manipulation), and freeing of the mbuf if the disciplines enqueue
function rejects it. theyre kind of like bufqs in the block layer
with their fifo and nscan disciplines.

the new api also supports atomic switching of disciplines at runtime.
the hfsc setup in pf_ioctl.c has been tweaked to build a complete
hfsc_if structure which it attaches to the send queue in a single
operation, rather than attaching to the interface up front and
building up a list of queues.

the send queue is now mutexed, which raises the expectation that
packets can be enqueued or purged on one cpu while another cpu is
dequeueing them in a driver for transmission. a lot of drivers use
IFQ_POLL to peek at an mbuf and attempt to fit it on the ring before
committing to it with a later IFQ_DEQUEUE operation. if the mbuf
gets freed in between the POLL and DEQUEUE operations, fireworks
will ensue.

to avoid this, the ifq api introduces ifq_deq_begin, ifq_deq_rollback,
and ifq_deq_commit. ifq_deq_begin allows a driver to take the ifq
mutex and get a reference to the mbuf they wish to try and tx. if
there's space, they can ifq_deq_commit it to remove the mbuf and
release the mutex. if there's no space, ifq_deq_rollback simply
releases the mutex. this api was developed to make updating the
drivers using IFQ_POLL easy, instead of having to do significant
semantic changes to avoid POLL that we cannot test on all the
hardware.

the common code has been tested pretty hard, and all the driver
modifications are straightforward except for de(4). if that breaks
it can be dealt with later.

ok mpi@ jmatthew@


# 1.74 04-Nov-2015 dlg

replace the ifqueues in net80211 with mbuf_queues.

the specific queues are ic_mgtq, ic_pwrsaveq, and ni_savedq. rtw
had its own queue for beacons.

tested by mpi@ and jmc@
ok mpi@


# 1.73 25-Oct-2015 mpi

arp_ifinit() is no longer needed.


# 1.72 09-Sep-2015 deraadt

sizes for free(); ok semarie


Revision tags: OPENBSD_5_8_BASE
# 1.71 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.70 10-Feb-2015 mpi

Wireless drivers call if_input() via ieee80211_input() which set `rcvif'
on every received mbuf, so there's no need to initialize this pointer in
the drivers.

Tested by and ok phessler@


# 1.69 22-Dec-2014 tedu

unifdef INET


# 1.68 19-Dec-2014 guenther

Use <sys/endian.h> instead of <machine/endian.h>

ok dlg@ mpi@ bcook@ millert@ miod@


# 1.67 06-Sep-2014 jsg

reduce the amount of pci includes


Revision tags: OPENBSD_5_6_BASE
# 1.66 22-Jul-2014 mpi

Fewer <netinet/in_systm.h>


# 1.65 13-Jul-2014 deraadt

Some reallocarray() use; review Jean-Philippe Ouellet, patrick keshishian
ok tedu


# 1.64 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


# 1.63 19-Mar-2014 mpi

Stop abusing the rcvif pointer to pass wireless nodes down to the
driver start routines. Instead add & use a pointer in the pkthdr
since we don't want the overhead of using a mbuf_tags(9).

claudio@ pointed out that other subsystems might want to use this
pointer too, so here's a new cookie!

ok claudio@, mikeb@, deraadt@


Revision tags: OPENBSD_5_5_BASE
# 1.62 06-Dec-2013 deraadt

Add a DVACT_WAKEUP op to the *_activate() API. This is called after the
kernel resumes normal (non-cold, able to run processes, etc) operation.
Previously we were relying on specific DVACT_RESUME op's in drivers
creating callback/threads themselves, but that has become too common,
indicating the need for a built-in mechanism.
ok dlg kettenis, tested by a sufficient amount of people


# 1.61 07-Aug-2013 bluhm

Most network drivers include netinet/in_var.h, but apparently they
don't have to. Just remove these include lines.
Compiled on amd64 i386 sparc64; OK henning@ mikeb@


Revision tags: OPENBSD_5_2_BASE OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.60 13-Jul-2012 stsp

Keep separate OACTIVE flags to mark full management/data tx queues,
and set the interface's IFF_OACTIVE flag if either queue is full and
clear it only if both queues have free slots. Before this change both
queues were setting/clearing the same flag with no regard for the
other queue's state.

Also, don't reset the tx watchdog counter if either queue still has frames
queued when we exit the frame-processing loop in the per-queue interrupt
handlers.

Both changes originally from sephe@dragonfly.

Tested by myself and edd on a slow busy soekris which before this
change required occasional 'ifconfig ral0 down up' to recover.


# 1.59 13-Jul-2012 stsp

Init the baseband processor before selecting antennas since selecting antennas
involves tweaking of BBP registers. Wait for BBP to stop being busy before
reading from it.

Originally from sephe@dragonfly. ok kettenis sthen


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.58 22-Feb-2011 kettenis

Mark descriptors as invalid *before* unmapping the associated mbuf.
Might prevent the unrecoverable DMA error mentioned in PR 6557.

ok damien@


# 1.57 07-Sep-2010 deraadt

remove the powerhook code. All architectures now use the ca_activate tree
traversal code to suspend/resume
ok oga kettenis blambert


# 1.56 06-Sep-2010 deraadt

All PWR_{SUSPEND,RESUME} can now be replaced by DVACT_{SUSPEND,RESUME}


# 1.55 06-Sep-2010 kettenis

Make the interrupt handler bail out early if the device wen away. Fixes
freezes that occur when removing CardBus cards when the interface is up.

ok deraadt@


# 1.54 28-Aug-2010 deraadt

rename the *_power functions to *_powerhook to indicate that we've been
here already for the activate/powerhook cleanup


# 1.53 27-Aug-2010 jsg

remove the unused if_init callback in struct ifnet
ok deraadt@ henning@ claudio@


# 1.52 27-Aug-2010 kettenis

Stop calling xxx_power() from xxx_resume(); instead do it the other way around.
Get rid of the sc_power() callback, which isn't used anymore.

ok deraadt@


# 1.51 27-Aug-2010 deraadt

kill PWR_STANDBY (apm can use PWR_SUSPEND instead). While here, renumber
PWR_{SUSPEND,RESUME} so that they match the values of DAVCT_{SUSPEND,RESUME}
so that we can eventually (many more steps...) kill the powerhook garbage
and use the activate mechanism.
no objections


# 1.50 25-Aug-2010 kettenis

Make CardBus ral(4) suspend and resume properly on machines that keep the
CardBus bridge powered up during suspend. Step zero on the long road
towards fully suspending CardBus on all machines.

ok deraadt@, damien@


Revision tags: OPENBSD_4_8_BASE
# 1.49 04-Aug-2010 damien

add suspend/resume support for PCI ral(4) devices.

ok deraadt@, sthen@

tested by matthew@ (RT2560), dcoppa@ (RT2790), okan@ (RT2860), todd@ (RT2560)


# 1.48 19-May-2010 oga

BUS_DMA_ZERO instead of alloc, map, bzero.

ok krw@


# 1.47 20-Apr-2010 tedu

remove proc.h include from uvm_map.h. This has far reaching effects, as
sysctl.h was reliant on this particular include, and many drivers included
sysctl.h unnecessarily. remove sysctl.h or add proc.h as needed.
ok deraadt


Revision tags: OPENBSD_4_7_BASE
# 1.46 01-Nov-2009 damien

call powerhook_disestablish() and pci_intr_disestablish() earlier.

diff from deraadt@


# 1.45 10-Aug-2009 damien

three more shutdown hooks bite the dust.


# 1.44 29-Jul-2009 blambert

timeout_add -> timeout_add_msec

ok damien@


Revision tags: OPENBSD_4_6_BASE
# 1.43 29-Mar-2009 sthen

make various strings ("can't map mem space" and similar) more consistent
between instances, saving space in the kernel. feedback from many (some
incorporated, some left for future work).

ok deraadt, kettenis, "why not" miod.


Revision tags: OPENBSD_4_5_BASE
# 1.42 22-Dec-2008 damien

I swapped MGETHDR arguments in my m_defrag removal commit.


# 1.41 21-Dec-2008 damien

Undo m_defrag().

m_defrag() does not work. It seems to assume that if the length of
the mbuf passed as parameter is less than MHLEN, then it is an mbuf
header and not a cluster (or something like that.)
It thus fails miserably in the bcopy path.
I don't have the time to investigate further into this.

Thanks to Okan Demirmen for reporting the issue on a ral(4) RT2560.
The RT2560 chipset does not support TX scatter and thus m_defrag()
was called much more often than in other drivers using m_defrag()
where it was less noticeable.


# 1.40 25-Nov-2008 damien

use shiny new m_defrag() and nitems() instead of rolling our own.


# 1.39 27-Aug-2008 damien

introduce new IEEE80211_STA_ONLY kernel option that can be set to
remove IBSS and HostAP support from net80211 and 802.11 drivers.
it can be used to shrink RAMDISK kernels for instance (like what
was done for wi(4)).
it also has the benefit of highlighting what is specific to IBSS
and HostAP modes in the code.
the cost is that we now have two code paths to maintain.


# 1.38 14-Aug-2008 damien

in ieee80211_input(), call if_start() after enqueuing frames in if_snd
when acting as an access point instead of having each driver doing the
job.

tested by krw@ (ral AP) and me with several drivers.


Revision tags: OPENBSD_4_4_BASE
# 1.37 21-Jul-2008 damien

instead of passing rx tstamp and rssi to the ieee80211_input function,
pass a pointer to an ieee80211_rxinfo structure containing those two
fields plus an extra flags field that indicates whether the frame was
decrypted by hardware or not.
required for a future fix.


# 1.36 16-Apr-2008 damien

Kernel implementation of the 4-way handshake and group-key
handshake protocols (both supplicant and authenticator state
machines) as defined in the IEEE 802.11i standard.

Software implementation of the TKIP (Temporal Key Integrity
Protocol) and CCMP (CTR with CBC-MAC Protocol) protocols.

This diff doesn't implement any of the 802.1X authentication
protocols and thus only PSK authentication (using pre-shared
keys) is currently supported.

In concrete terms, this adds support for WPA-PSK and WPA2-PSK
protocols, both in station and hostap modes.

The following drivers are marked as WPA-capable and should
work: bwi(4), malo(4), ral(4), iwn(4), wpi(4), ural(4),
rum(4), upgt(4), and zyd(4)

The following options have been added to ifconfig(8):
wpa, wpapsk, wpaprotos, wpaakms, wpaciphers, wpagroupcipher

wpa-psk(8) can be used to generate keys from passphrases.

tested by many@
ok deraadt@


Revision tags: OPENBSD_4_3_BASE
# 1.35 17-Nov-2007 damien

RT2560+RT2661: update the physical address in the RX descriptor after
bus_dmamap_load() in the case where the same mbuf is reloaded.
RT2661: remove a 2x prototype, fix an error message.


# 1.34 15-Oct-2007 fgsch

more remove unneeded declarations that shadows existing vars; ok by many.


# 1.33 07-Sep-2007 damien

use new malloc M_ZERO flag to shrink kernel.
remove <malloc.h> from files where malloc is not used.


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.32 08-Mar-2007 deraadt

XXX commit a workaround (as found in a few other drivers) for the
divide by zero rate bug. Someone has to find the source of this
bug one day; from jsg


# 1.31 24-Jan-2007 damien

revert changes committed between r1.25 and 1.26.
this breaks some RT2560 adapters.

pointed out by krw@ and Pierre Riteau.


# 1.30 03-Jan-2007 claudio

M_DUP_PKTHDR() cleanup. On static buffers M_DUP_PKTHDR() will leak mbuf tags.
See similar rum(4) commit for more info. OK mglocker@


# 1.29 17-Dec-2006 damien

fix index of ERP information element in beacons.
still ugly, but correct.


# 1.28 03-Dec-2006 damien

fix handling of the SIOCS80211CHANNEL ioctl in monitor mode:
don't call xxx_set_chan() if the interface is not up&running.

patch from Steffen Schuetz (st dot sch at gmx dot net) with
minor modifications by me.

closes kernel/5313


# 1.27 26-Nov-2006 deraadt

do not have each net80211 driver define its own rates structures. if they use
the standard rates, use some defined by net80211 itself. kernel shrinks a bit
ok jsg mglocker


# 1.26 22-Nov-2006 damien

don't write to BBP before it is ready and fully initialized
-> move rt2560_set{tx,rx}antenna() after rt2560_bbp_init().

from <sephe at dragonflybsd dot org>


# 1.25 13-Nov-2006 damien

first round of commits for proper 11b/g protection support:
- use the newly introduced ieee80211_get_rts() and
ieee80211_get_cts_to_self() functions.
- use CTS-to-self instead of RTS/CTS to protect OFDM frames in
a mixed 11b/g BSS.
- make sure multicast frames are sent using CCK modulation.

remove support for 5GHz radios in ral(4) RT2560 and ural(4).
i'm not aware of any such adapters on the market and 11a code
is known to be broken.

some cleanup while i'm here.


# 1.24 22-Oct-2006 damien

replace rssadapt(9) with amrr for automatic rate control.
as a side-effect, this should fix all the "bogus xmit rate" panics
users have been complaining about for some time when operating in
HostAP mode.


# 1.23 18-Sep-2006 damien

don't use IF_PREPEND() on altq's.
use IFQ_POLL()/IFQ_DEQUEUE() logic instead as described in altq(4).


Revision tags: OPENBSD_4_0_BASE
# 1.22 18-Jul-2006 damien

modify interrupt handlers to exit early and return 0 on shared interrupts.

pointed out by deraadt@


# 1.21 18-Jun-2006 damien

- implement new ic_updateslot() callback.
- in hostap mode, we defer update of the slot time until all associated
STAs are notified with updated beacons.


# 1.20 18-Jun-2006 damien

enable packet bursting when operating as a STA.
limit bursts to 8 frames.


# 1.19 14-Jun-2006 damien

must use RTS/CTS protection when sending frames at OFDM rates in a BSS
with non-ERP STAs. some bits are missing in net80211 though, so this
code won't be triggered yet.


# 1.18 10-Jun-2006 damien

- fix checking of WEP flags
- encrypt mgmt frames when they need to (shared authmode)
- move default MAC/BBP/RF settings from rt2560.c to rt2560reg.h


# 1.17 02-Jun-2006 robert

add powerhooks for ral(4) cards with the RT2560 chipset;

ok damien@


# 1.16 01-Jun-2006 robert

Make the debug printfs work if RAL_DEBUG is defined.


# 1.15 20-Apr-2006 miod

Fix various printf() issues: too many arguments, not enough arguments, argument
order reversed, wrong modifiers. ok deraadt@ marco@ mickey@


# 1.14 27-Mar-2006 damien

fixes interrupts processing.

should fix a panic reported by Karel Gardas.


# 1.13 25-Mar-2006 djm

allow bpf(4) to ignore packets based on their direction (inbound or
outbound), using a new BIOCSDIRFILT ioctl;
guidance, feedback and ok canacar@


Revision tags: OPENBSD_3_9_BASE
# 1.12 25-Feb-2006 damien

branches: 1.12.2;
instead of panicing when tx rate is zero, fallback to 1Mbps.
this is a temporary workaround since we should really not see any node
with an empty rate set but it seems to happen in hostap mode.


# 1.11 18-Feb-2006 damien

don't try to release references to nodes that have been freed by net80211.
in HostAP mode, when switching to the INIT state, net80211 sends a DISASSOC
and a DEAUTH frame to all associated stations and immediately free all the
nodes while we may still hold references to them in our Tx queues.

hopefully, this should fix PRs 4469/kernel and 4953/kernel.


# 1.10 14-Jan-2006 damien

- give rate to rx radiotap
- read TSF high 32bit word before low 32bit word to avoid wraparounds


# 1.9 14-Jan-2006 jsg

Correct the length of the rx radiotap to be that of the rx not tx
struct.

ok damien@


# 1.8 13-Jan-2006 damien

fix short slot time + cosmetic


# 1.7 13-Jan-2006 damien

- simplify lookup of 802.11a channels (we know they exist)
- kill two stupid comments while i'm here


# 1.6 11-Jan-2006 damien

fix RTS protection mode.


# 1.5 10-Jan-2006 damien

- use rssadapt(9) as rate control algorithm
- add 802.11 radiotap support
- read 802.11a channels tx power from EEPROM
- read vendor-specific BBP settings from EEPROM
- fix setting of beacons (xflags)
- fix DMA sync in rt2661_rx_intr
- indicate whether RF supports MIMO in dmesg
- add short slot time support
- many cleanups while i'm here


# 1.4 10-Jan-2006 damien

fix reading of EEPROM content on big endian arches.


# 1.3 10-Jan-2006 damien

send management, control and beacon frames at the lowest possible rate
(1Mbps for 802.11b/g, 6Mbps for 802.11a)


# 1.2 10-Jan-2006 damien

cleanup rt2560_setup_tx_desc().
fix contention window.


# 1.1 09-Jan-2006 damien

- add preliminary support for Ralink Technology RT2561, RT2561S and RT2661
chipsets in ral(4).
- restructure the code a bit; split ic/ral.c into ic/rt2560.c and ic/rt2661.c
- import the 8051 microcode files required by these chipsets.
- more to come; there is currently no automatic rate control and some
features are untested (hostap and ibss modes for instance). most of
the pre-802.11n capabilities of the RT2661 chipset are not supported
(like frame aggregation, piggy-back). MIMO should work though the
performance/range gain has not been measured.


# 1.85 12-Sep-2019 stsp

Make wireless drivers call if_input() only once per interrupt.

This reduces drops caused by the ifq pressure drop mechanism and hence
increases throughput. Such drops are visible with e.g. 'netstat -dnI iwm0'.

Not all affected drivers have been tested yet but these changes are largely
mechanical and should be safe. As usual, please report any regressions.

With help from dlg@ and mpi@

Problem found by robert@
Tested by robert, jmc, Tracey Emer, Matthias Schmidt, florian, Bj��rn Ketelaars
ok mpi@


Revision tags: OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.84 26-Oct-2017 mpi

Move common code to add/remove multicast filters to ieee80211_ioctl(9).

ok jsg@, stsp@


Revision tags: OPENBSD_6_2_BASE
# 1.83 03-Jul-2017 kevlo

Replace slot time durations with macros.

ok stsp@


Revision tags: OPENBSD_6_1_BASE
# 1.82 22-Jan-2017 dlg

move counting if_opackets next to counting if_obytes in if_enqueue.

this means packets are consistently counted in one place, unlike the
many and various ways that drivers thought they should do it.

ok mpi@ deraadt@


# 1.81 06-Oct-2016 stsp

Disable RTS for long frames in ral(4) for rt2560 chips.
On these chips RTS causes bad performance in hostap mode for unknown reasons.

Convert some debug printfs to DPRINTF.
Add a comment which explains why 2 free slots are needed on the Tx queue.

ok phessler@ sthen@


Revision tags: OPENBSD_6_0_BASE
# 1.80 13-Apr-2016 mpi

G/C IFQ_SET_READY().


Revision tags: OPENBSD_5_9_BASE
# 1.79 05-Dec-2015 dlg

ifq_deq_rollback without a preceding ifq_deq_begin is fail.

caused by a badly managed merge.

found by and testing by sebastia@
ok mpi@


# 1.78 25-Nov-2015 dlg

replace IFF_OACTIVE manipulation with mpsafe operations.

there are two things shared between the network stack and drivers
in the send path: the send queue and the IFF_OACTIVE flag. the send
queue is now protected by a mutex. this diff makes the oactive
functionality mpsafe too.

IFF_OACTIVE is part of if_flags. there are two problems with that.
firstly, if_flags is a short and we dont have any MI atomic operations
to manipulate a short. secondly, while we could make the IFF_OACTIVE
operates mpsafe, all changes to other flags would have to be made
safe at the same time, otherwise a read-modify-write cycle on their
updates could clobber the oactive change.

instead, this moves the oactive mark into struct ifqueue and provides
an API for changing it. there's ifq_set_oactive, ifq_clr_oactive,
and ifq_is_oactive. these are modelled on ifsq_set_oactive,
ifsq_clr_oactive, and ifsq_is_oactive in dragonflybsd.

this diff includes changes to all the drivers manipulating IFF_OACTIVE
to now use the ifsq_{set,clr_is}_oactive API too.

ok kettenis@ mpi@ jmatthew@ deraadt@


# 1.77 24-Nov-2015 mpi

The only network driver needing <net/if_types.h> is upl(4) for IFT_OTHER.


# 1.76 20-Nov-2015 mpi

Check for space on the ring before dequeuing packets.

Allows us to get rid of mq_requeue(9) and IFQ_POLL(9) because wireless
drivers use a special queue for management frames.

Tested by stsp@, ok dlg@, stsp@


# 1.75 20-Nov-2015 dlg

shuffle struct ifqueue so in flight mbufs are protected by a mutex.

the code is refactored so the IFQ macros call newly implemented ifq
functions. the ifq code is split so each discipline (priq and hfsc
in our case) is an opaque set of operations that the common ifq
code can call. the common code does the locking, accounting (ifq_len
manipulation), and freeing of the mbuf if the disciplines enqueue
function rejects it. theyre kind of like bufqs in the block layer
with their fifo and nscan disciplines.

the new api also supports atomic switching of disciplines at runtime.
the hfsc setup in pf_ioctl.c has been tweaked to build a complete
hfsc_if structure which it attaches to the send queue in a single
operation, rather than attaching to the interface up front and
building up a list of queues.

the send queue is now mutexed, which raises the expectation that
packets can be enqueued or purged on one cpu while another cpu is
dequeueing them in a driver for transmission. a lot of drivers use
IFQ_POLL to peek at an mbuf and attempt to fit it on the ring before
committing to it with a later IFQ_DEQUEUE operation. if the mbuf
gets freed in between the POLL and DEQUEUE operations, fireworks
will ensue.

to avoid this, the ifq api introduces ifq_deq_begin, ifq_deq_rollback,
and ifq_deq_commit. ifq_deq_begin allows a driver to take the ifq
mutex and get a reference to the mbuf they wish to try and tx. if
there's space, they can ifq_deq_commit it to remove the mbuf and
release the mutex. if there's no space, ifq_deq_rollback simply
releases the mutex. this api was developed to make updating the
drivers using IFQ_POLL easy, instead of having to do significant
semantic changes to avoid POLL that we cannot test on all the
hardware.

the common code has been tested pretty hard, and all the driver
modifications are straightforward except for de(4). if that breaks
it can be dealt with later.

ok mpi@ jmatthew@


# 1.74 04-Nov-2015 dlg

replace the ifqueues in net80211 with mbuf_queues.

the specific queues are ic_mgtq, ic_pwrsaveq, and ni_savedq. rtw
had its own queue for beacons.

tested by mpi@ and jmc@
ok mpi@


# 1.73 25-Oct-2015 mpi

arp_ifinit() is no longer needed.


# 1.72 09-Sep-2015 deraadt

sizes for free(); ok semarie


Revision tags: OPENBSD_5_8_BASE
# 1.71 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.70 10-Feb-2015 mpi

Wireless drivers call if_input() via ieee80211_input() which set `rcvif'
on every received mbuf, so there's no need to initialize this pointer in
the drivers.

Tested by and ok phessler@


# 1.69 22-Dec-2014 tedu

unifdef INET


# 1.68 19-Dec-2014 guenther

Use <sys/endian.h> instead of <machine/endian.h>

ok dlg@ mpi@ bcook@ millert@ miod@


# 1.67 06-Sep-2014 jsg

reduce the amount of pci includes


Revision tags: OPENBSD_5_6_BASE
# 1.66 22-Jul-2014 mpi

Fewer <netinet/in_systm.h>


# 1.65 13-Jul-2014 deraadt

Some reallocarray() use; review Jean-Philippe Ouellet, patrick keshishian
ok tedu


# 1.64 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


# 1.63 19-Mar-2014 mpi

Stop abusing the rcvif pointer to pass wireless nodes down to the
driver start routines. Instead add & use a pointer in the pkthdr
since we don't want the overhead of using a mbuf_tags(9).

claudio@ pointed out that other subsystems might want to use this
pointer too, so here's a new cookie!

ok claudio@, mikeb@, deraadt@


Revision tags: OPENBSD_5_5_BASE
# 1.62 06-Dec-2013 deraadt

Add a DVACT_WAKEUP op to the *_activate() API. This is called after the
kernel resumes normal (non-cold, able to run processes, etc) operation.
Previously we were relying on specific DVACT_RESUME op's in drivers
creating callback/threads themselves, but that has become too common,
indicating the need for a built-in mechanism.
ok dlg kettenis, tested by a sufficient amount of people


# 1.61 07-Aug-2013 bluhm

Most network drivers include netinet/in_var.h, but apparently they
don't have to. Just remove these include lines.
Compiled on amd64 i386 sparc64; OK henning@ mikeb@


Revision tags: OPENBSD_5_2_BASE OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.60 13-Jul-2012 stsp

Keep separate OACTIVE flags to mark full management/data tx queues,
and set the interface's IFF_OACTIVE flag if either queue is full and
clear it only if both queues have free slots. Before this change both
queues were setting/clearing the same flag with no regard for the
other queue's state.

Also, don't reset the tx watchdog counter if either queue still has frames
queued when we exit the frame-processing loop in the per-queue interrupt
handlers.

Both changes originally from sephe@dragonfly.

Tested by myself and edd on a slow busy soekris which before this
change required occasional 'ifconfig ral0 down up' to recover.


# 1.59 13-Jul-2012 stsp

Init the baseband processor before selecting antennas since selecting antennas
involves tweaking of BBP registers. Wait for BBP to stop being busy before
reading from it.

Originally from sephe@dragonfly. ok kettenis sthen


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.58 22-Feb-2011 kettenis

Mark descriptors as invalid *before* unmapping the associated mbuf.
Might prevent the unrecoverable DMA error mentioned in PR 6557.

ok damien@


# 1.57 07-Sep-2010 deraadt

remove the powerhook code. All architectures now use the ca_activate tree
traversal code to suspend/resume
ok oga kettenis blambert


# 1.56 06-Sep-2010 deraadt

All PWR_{SUSPEND,RESUME} can now be replaced by DVACT_{SUSPEND,RESUME}


# 1.55 06-Sep-2010 kettenis

Make the interrupt handler bail out early if the device wen away. Fixes
freezes that occur when removing CardBus cards when the interface is up.

ok deraadt@


# 1.54 28-Aug-2010 deraadt

rename the *_power functions to *_powerhook to indicate that we've been
here already for the activate/powerhook cleanup


# 1.53 27-Aug-2010 jsg

remove the unused if_init callback in struct ifnet
ok deraadt@ henning@ claudio@


# 1.52 27-Aug-2010 kettenis

Stop calling xxx_power() from xxx_resume(); instead do it the other way around.
Get rid of the sc_power() callback, which isn't used anymore.

ok deraadt@


# 1.51 27-Aug-2010 deraadt

kill PWR_STANDBY (apm can use PWR_SUSPEND instead). While here, renumber
PWR_{SUSPEND,RESUME} so that they match the values of DAVCT_{SUSPEND,RESUME}
so that we can eventually (many more steps...) kill the powerhook garbage
and use the activate mechanism.
no objections


# 1.50 25-Aug-2010 kettenis

Make CardBus ral(4) suspend and resume properly on machines that keep the
CardBus bridge powered up during suspend. Step zero on the long road
towards fully suspending CardBus on all machines.

ok deraadt@, damien@


Revision tags: OPENBSD_4_8_BASE
# 1.49 04-Aug-2010 damien

add suspend/resume support for PCI ral(4) devices.

ok deraadt@, sthen@

tested by matthew@ (RT2560), dcoppa@ (RT2790), okan@ (RT2860), todd@ (RT2560)


# 1.48 19-May-2010 oga

BUS_DMA_ZERO instead of alloc, map, bzero.

ok krw@


# 1.47 20-Apr-2010 tedu

remove proc.h include from uvm_map.h. This has far reaching effects, as
sysctl.h was reliant on this particular include, and many drivers included
sysctl.h unnecessarily. remove sysctl.h or add proc.h as needed.
ok deraadt


Revision tags: OPENBSD_4_7_BASE
# 1.46 01-Nov-2009 damien

call powerhook_disestablish() and pci_intr_disestablish() earlier.

diff from deraadt@


# 1.45 10-Aug-2009 damien

three more shutdown hooks bite the dust.


# 1.44 29-Jul-2009 blambert

timeout_add -> timeout_add_msec

ok damien@


Revision tags: OPENBSD_4_6_BASE
# 1.43 29-Mar-2009 sthen

make various strings ("can't map mem space" and similar) more consistent
between instances, saving space in the kernel. feedback from many (some
incorporated, some left for future work).

ok deraadt, kettenis, "why not" miod.


Revision tags: OPENBSD_4_5_BASE
# 1.42 22-Dec-2008 damien

I swapped MGETHDR arguments in my m_defrag removal commit.


# 1.41 21-Dec-2008 damien

Undo m_defrag().

m_defrag() does not work. It seems to assume that if the length of
the mbuf passed as parameter is less than MHLEN, then it is an mbuf
header and not a cluster (or something like that.)
It thus fails miserably in the bcopy path.
I don't have the time to investigate further into this.

Thanks to Okan Demirmen for reporting the issue on a ral(4) RT2560.
The RT2560 chipset does not support TX scatter and thus m_defrag()
was called much more often than in other drivers using m_defrag()
where it was less noticeable.


# 1.40 25-Nov-2008 damien

use shiny new m_defrag() and nitems() instead of rolling our own.


# 1.39 27-Aug-2008 damien

introduce new IEEE80211_STA_ONLY kernel option that can be set to
remove IBSS and HostAP support from net80211 and 802.11 drivers.
it can be used to shrink RAMDISK kernels for instance (like what
was done for wi(4)).
it also has the benefit of highlighting what is specific to IBSS
and HostAP modes in the code.
the cost is that we now have two code paths to maintain.


# 1.38 14-Aug-2008 damien

in ieee80211_input(), call if_start() after enqueuing frames in if_snd
when acting as an access point instead of having each driver doing the
job.

tested by krw@ (ral AP) and me with several drivers.


Revision tags: OPENBSD_4_4_BASE
# 1.37 21-Jul-2008 damien

instead of passing rx tstamp and rssi to the ieee80211_input function,
pass a pointer to an ieee80211_rxinfo structure containing those two
fields plus an extra flags field that indicates whether the frame was
decrypted by hardware or not.
required for a future fix.


# 1.36 16-Apr-2008 damien

Kernel implementation of the 4-way handshake and group-key
handshake protocols (both supplicant and authenticator state
machines) as defined in the IEEE 802.11i standard.

Software implementation of the TKIP (Temporal Key Integrity
Protocol) and CCMP (CTR with CBC-MAC Protocol) protocols.

This diff doesn't implement any of the 802.1X authentication
protocols and thus only PSK authentication (using pre-shared
keys) is currently supported.

In concrete terms, this adds support for WPA-PSK and WPA2-PSK
protocols, both in station and hostap modes.

The following drivers are marked as WPA-capable and should
work: bwi(4), malo(4), ral(4), iwn(4), wpi(4), ural(4),
rum(4), upgt(4), and zyd(4)

The following options have been added to ifconfig(8):
wpa, wpapsk, wpaprotos, wpaakms, wpaciphers, wpagroupcipher

wpa-psk(8) can be used to generate keys from passphrases.

tested by many@
ok deraadt@


Revision tags: OPENBSD_4_3_BASE
# 1.35 17-Nov-2007 damien

RT2560+RT2661: update the physical address in the RX descriptor after
bus_dmamap_load() in the case where the same mbuf is reloaded.
RT2661: remove a 2x prototype, fix an error message.


# 1.34 15-Oct-2007 fgsch

more remove unneeded declarations that shadows existing vars; ok by many.


# 1.33 07-Sep-2007 damien

use new malloc M_ZERO flag to shrink kernel.
remove <malloc.h> from files where malloc is not used.


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.32 08-Mar-2007 deraadt

XXX commit a workaround (as found in a few other drivers) for the
divide by zero rate bug. Someone has to find the source of this
bug one day; from jsg


# 1.31 24-Jan-2007 damien

revert changes committed between r1.25 and 1.26.
this breaks some RT2560 adapters.

pointed out by krw@ and Pierre Riteau.


# 1.30 03-Jan-2007 claudio

M_DUP_PKTHDR() cleanup. On static buffers M_DUP_PKTHDR() will leak mbuf tags.
See similar rum(4) commit for more info. OK mglocker@


# 1.29 17-Dec-2006 damien

fix index of ERP information element in beacons.
still ugly, but correct.


# 1.28 03-Dec-2006 damien

fix handling of the SIOCS80211CHANNEL ioctl in monitor mode:
don't call xxx_set_chan() if the interface is not up&running.

patch from Steffen Schuetz (st dot sch at gmx dot net) with
minor modifications by me.

closes kernel/5313


# 1.27 26-Nov-2006 deraadt

do not have each net80211 driver define its own rates structures. if they use
the standard rates, use some defined by net80211 itself. kernel shrinks a bit
ok jsg mglocker


# 1.26 22-Nov-2006 damien

don't write to BBP before it is ready and fully initialized
-> move rt2560_set{tx,rx}antenna() after rt2560_bbp_init().

from <sephe at dragonflybsd dot org>


# 1.25 13-Nov-2006 damien

first round of commits for proper 11b/g protection support:
- use the newly introduced ieee80211_get_rts() and
ieee80211_get_cts_to_self() functions.
- use CTS-to-self instead of RTS/CTS to protect OFDM frames in
a mixed 11b/g BSS.
- make sure multicast frames are sent using CCK modulation.

remove support for 5GHz radios in ral(4) RT2560 and ural(4).
i'm not aware of any such adapters on the market and 11a code
is known to be broken.

some cleanup while i'm here.


# 1.24 22-Oct-2006 damien

replace rssadapt(9) with amrr for automatic rate control.
as a side-effect, this should fix all the "bogus xmit rate" panics
users have been complaining about for some time when operating in
HostAP mode.


# 1.23 18-Sep-2006 damien

don't use IF_PREPEND() on altq's.
use IFQ_POLL()/IFQ_DEQUEUE() logic instead as described in altq(4).


Revision tags: OPENBSD_4_0_BASE
# 1.22 18-Jul-2006 damien

modify interrupt handlers to exit early and return 0 on shared interrupts.

pointed out by deraadt@


# 1.21 18-Jun-2006 damien

- implement new ic_updateslot() callback.
- in hostap mode, we defer update of the slot time until all associated
STAs are notified with updated beacons.


# 1.20 18-Jun-2006 damien

enable packet bursting when operating as a STA.
limit bursts to 8 frames.


# 1.19 14-Jun-2006 damien

must use RTS/CTS protection when sending frames at OFDM rates in a BSS
with non-ERP STAs. some bits are missing in net80211 though, so this
code won't be triggered yet.


# 1.18 10-Jun-2006 damien

- fix checking of WEP flags
- encrypt mgmt frames when they need to (shared authmode)
- move default MAC/BBP/RF settings from rt2560.c to rt2560reg.h


# 1.17 02-Jun-2006 robert

add powerhooks for ral(4) cards with the RT2560 chipset;

ok damien@


# 1.16 01-Jun-2006 robert

Make the debug printfs work if RAL_DEBUG is defined.


# 1.15 20-Apr-2006 miod

Fix various printf() issues: too many arguments, not enough arguments, argument
order reversed, wrong modifiers. ok deraadt@ marco@ mickey@


# 1.14 27-Mar-2006 damien

fixes interrupts processing.

should fix a panic reported by Karel Gardas.


# 1.13 25-Mar-2006 djm

allow bpf(4) to ignore packets based on their direction (inbound or
outbound), using a new BIOCSDIRFILT ioctl;
guidance, feedback and ok canacar@


Revision tags: OPENBSD_3_9_BASE
# 1.12 25-Feb-2006 damien

branches: 1.12.2;
instead of panicing when tx rate is zero, fallback to 1Mbps.
this is a temporary workaround since we should really not see any node
with an empty rate set but it seems to happen in hostap mode.


# 1.11 18-Feb-2006 damien

don't try to release references to nodes that have been freed by net80211.
in HostAP mode, when switching to the INIT state, net80211 sends a DISASSOC
and a DEAUTH frame to all associated stations and immediately free all the
nodes while we may still hold references to them in our Tx queues.

hopefully, this should fix PRs 4469/kernel and 4953/kernel.


# 1.10 14-Jan-2006 damien

- give rate to rx radiotap
- read TSF high 32bit word before low 32bit word to avoid wraparounds


# 1.9 14-Jan-2006 jsg

Correct the length of the rx radiotap to be that of the rx not tx
struct.

ok damien@


# 1.8 13-Jan-2006 damien

fix short slot time + cosmetic


# 1.7 13-Jan-2006 damien

- simplify lookup of 802.11a channels (we know they exist)
- kill two stupid comments while i'm here


# 1.6 11-Jan-2006 damien

fix RTS protection mode.


# 1.5 10-Jan-2006 damien

- use rssadapt(9) as rate control algorithm
- add 802.11 radiotap support
- read 802.11a channels tx power from EEPROM
- read vendor-specific BBP settings from EEPROM
- fix setting of beacons (xflags)
- fix DMA sync in rt2661_rx_intr
- indicate whether RF supports MIMO in dmesg
- add short slot time support
- many cleanups while i'm here


# 1.4 10-Jan-2006 damien

fix reading of EEPROM content on big endian arches.


# 1.3 10-Jan-2006 damien

send management, control and beacon frames at the lowest possible rate
(1Mbps for 802.11b/g, 6Mbps for 802.11a)


# 1.2 10-Jan-2006 damien

cleanup rt2560_setup_tx_desc().
fix contention window.


# 1.1 09-Jan-2006 damien

- add preliminary support for Ralink Technology RT2561, RT2561S and RT2661
chipsets in ral(4).
- restructure the code a bit; split ic/ral.c into ic/rt2560.c and ic/rt2661.c
- import the 8051 microcode files required by these chipsets.
- more to come; there is currently no automatic rate control and some
features are untested (hostap and ibss modes for instance). most of
the pre-802.11n capabilities of the RT2661 chipset are not supported
(like frame aggregation, piggy-back). MIMO should work though the
performance/range gain has not been measured.


# 1.84 26-Oct-2017 mpi

Move common code to add/remove multicast filters to ieee80211_ioctl(9).

ok jsg@, stsp@


Revision tags: OPENBSD_6_2_BASE
# 1.83 03-Jul-2017 kevlo

Replace slot time durations with macros.

ok stsp@


Revision tags: OPENBSD_6_1_BASE
# 1.82 22-Jan-2017 dlg

move counting if_opackets next to counting if_obytes in if_enqueue.

this means packets are consistently counted in one place, unlike the
many and various ways that drivers thought they should do it.

ok mpi@ deraadt@


# 1.81 06-Oct-2016 stsp

Disable RTS for long frames in ral(4) for rt2560 chips.
On these chips RTS causes bad performance in hostap mode for unknown reasons.

Convert some debug printfs to DPRINTF.
Add a comment which explains why 2 free slots are needed on the Tx queue.

ok phessler@ sthen@


Revision tags: OPENBSD_6_0_BASE
# 1.80 13-Apr-2016 mpi

G/C IFQ_SET_READY().


Revision tags: OPENBSD_5_9_BASE
# 1.79 05-Dec-2015 dlg

ifq_deq_rollback without a preceding ifq_deq_begin is fail.

caused by a badly managed merge.

found by and testing by sebastia@
ok mpi@


# 1.78 25-Nov-2015 dlg

replace IFF_OACTIVE manipulation with mpsafe operations.

there are two things shared between the network stack and drivers
in the send path: the send queue and the IFF_OACTIVE flag. the send
queue is now protected by a mutex. this diff makes the oactive
functionality mpsafe too.

IFF_OACTIVE is part of if_flags. there are two problems with that.
firstly, if_flags is a short and we dont have any MI atomic operations
to manipulate a short. secondly, while we could make the IFF_OACTIVE
operates mpsafe, all changes to other flags would have to be made
safe at the same time, otherwise a read-modify-write cycle on their
updates could clobber the oactive change.

instead, this moves the oactive mark into struct ifqueue and provides
an API for changing it. there's ifq_set_oactive, ifq_clr_oactive,
and ifq_is_oactive. these are modelled on ifsq_set_oactive,
ifsq_clr_oactive, and ifsq_is_oactive in dragonflybsd.

this diff includes changes to all the drivers manipulating IFF_OACTIVE
to now use the ifsq_{set,clr_is}_oactive API too.

ok kettenis@ mpi@ jmatthew@ deraadt@


# 1.77 24-Nov-2015 mpi

The only network driver needing <net/if_types.h> is upl(4) for IFT_OTHER.


# 1.76 20-Nov-2015 mpi

Check for space on the ring before dequeuing packets.

Allows us to get rid of mq_requeue(9) and IFQ_POLL(9) because wireless
drivers use a special queue for management frames.

Tested by stsp@, ok dlg@, stsp@


# 1.75 20-Nov-2015 dlg

shuffle struct ifqueue so in flight mbufs are protected by a mutex.

the code is refactored so the IFQ macros call newly implemented ifq
functions. the ifq code is split so each discipline (priq and hfsc
in our case) is an opaque set of operations that the common ifq
code can call. the common code does the locking, accounting (ifq_len
manipulation), and freeing of the mbuf if the disciplines enqueue
function rejects it. theyre kind of like bufqs in the block layer
with their fifo and nscan disciplines.

the new api also supports atomic switching of disciplines at runtime.
the hfsc setup in pf_ioctl.c has been tweaked to build a complete
hfsc_if structure which it attaches to the send queue in a single
operation, rather than attaching to the interface up front and
building up a list of queues.

the send queue is now mutexed, which raises the expectation that
packets can be enqueued or purged on one cpu while another cpu is
dequeueing them in a driver for transmission. a lot of drivers use
IFQ_POLL to peek at an mbuf and attempt to fit it on the ring before
committing to it with a later IFQ_DEQUEUE operation. if the mbuf
gets freed in between the POLL and DEQUEUE operations, fireworks
will ensue.

to avoid this, the ifq api introduces ifq_deq_begin, ifq_deq_rollback,
and ifq_deq_commit. ifq_deq_begin allows a driver to take the ifq
mutex and get a reference to the mbuf they wish to try and tx. if
there's space, they can ifq_deq_commit it to remove the mbuf and
release the mutex. if there's no space, ifq_deq_rollback simply
releases the mutex. this api was developed to make updating the
drivers using IFQ_POLL easy, instead of having to do significant
semantic changes to avoid POLL that we cannot test on all the
hardware.

the common code has been tested pretty hard, and all the driver
modifications are straightforward except for de(4). if that breaks
it can be dealt with later.

ok mpi@ jmatthew@


# 1.74 04-Nov-2015 dlg

replace the ifqueues in net80211 with mbuf_queues.

the specific queues are ic_mgtq, ic_pwrsaveq, and ni_savedq. rtw
had its own queue for beacons.

tested by mpi@ and jmc@
ok mpi@


# 1.73 25-Oct-2015 mpi

arp_ifinit() is no longer needed.


# 1.72 09-Sep-2015 deraadt

sizes for free(); ok semarie


Revision tags: OPENBSD_5_8_BASE
# 1.71 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.70 10-Feb-2015 mpi

Wireless drivers call if_input() via ieee80211_input() which set `rcvif'
on every received mbuf, so there's no need to initialize this pointer in
the drivers.

Tested by and ok phessler@


# 1.69 22-Dec-2014 tedu

unifdef INET


# 1.68 19-Dec-2014 guenther

Use <sys/endian.h> instead of <machine/endian.h>

ok dlg@ mpi@ bcook@ millert@ miod@


# 1.67 06-Sep-2014 jsg

reduce the amount of pci includes


Revision tags: OPENBSD_5_6_BASE
# 1.66 22-Jul-2014 mpi

Fewer <netinet/in_systm.h>


# 1.65 13-Jul-2014 deraadt

Some reallocarray() use; review Jean-Philippe Ouellet, patrick keshishian
ok tedu


# 1.64 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


# 1.63 19-Mar-2014 mpi

Stop abusing the rcvif pointer to pass wireless nodes down to the
driver start routines. Instead add & use a pointer in the pkthdr
since we don't want the overhead of using a mbuf_tags(9).

claudio@ pointed out that other subsystems might want to use this
pointer too, so here's a new cookie!

ok claudio@, mikeb@, deraadt@


Revision tags: OPENBSD_5_5_BASE
# 1.62 06-Dec-2013 deraadt

Add a DVACT_WAKEUP op to the *_activate() API. This is called after the
kernel resumes normal (non-cold, able to run processes, etc) operation.
Previously we were relying on specific DVACT_RESUME op's in drivers
creating callback/threads themselves, but that has become too common,
indicating the need for a built-in mechanism.
ok dlg kettenis, tested by a sufficient amount of people


# 1.61 07-Aug-2013 bluhm

Most network drivers include netinet/in_var.h, but apparently they
don't have to. Just remove these include lines.
Compiled on amd64 i386 sparc64; OK henning@ mikeb@


Revision tags: OPENBSD_5_2_BASE OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.60 13-Jul-2012 stsp

Keep separate OACTIVE flags to mark full management/data tx queues,
and set the interface's IFF_OACTIVE flag if either queue is full and
clear it only if both queues have free slots. Before this change both
queues were setting/clearing the same flag with no regard for the
other queue's state.

Also, don't reset the tx watchdog counter if either queue still has frames
queued when we exit the frame-processing loop in the per-queue interrupt
handlers.

Both changes originally from sephe@dragonfly.

Tested by myself and edd on a slow busy soekris which before this
change required occasional 'ifconfig ral0 down up' to recover.


# 1.59 13-Jul-2012 stsp

Init the baseband processor before selecting antennas since selecting antennas
involves tweaking of BBP registers. Wait for BBP to stop being busy before
reading from it.

Originally from sephe@dragonfly. ok kettenis sthen


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.58 22-Feb-2011 kettenis

Mark descriptors as invalid *before* unmapping the associated mbuf.
Might prevent the unrecoverable DMA error mentioned in PR 6557.

ok damien@


# 1.57 07-Sep-2010 deraadt

remove the powerhook code. All architectures now use the ca_activate tree
traversal code to suspend/resume
ok oga kettenis blambert


# 1.56 06-Sep-2010 deraadt

All PWR_{SUSPEND,RESUME} can now be replaced by DVACT_{SUSPEND,RESUME}


# 1.55 06-Sep-2010 kettenis

Make the interrupt handler bail out early if the device wen away. Fixes
freezes that occur when removing CardBus cards when the interface is up.

ok deraadt@


# 1.54 28-Aug-2010 deraadt

rename the *_power functions to *_powerhook to indicate that we've been
here already for the activate/powerhook cleanup


# 1.53 27-Aug-2010 jsg

remove the unused if_init callback in struct ifnet
ok deraadt@ henning@ claudio@


# 1.52 27-Aug-2010 kettenis

Stop calling xxx_power() from xxx_resume(); instead do it the other way around.
Get rid of the sc_power() callback, which isn't used anymore.

ok deraadt@


# 1.51 27-Aug-2010 deraadt

kill PWR_STANDBY (apm can use PWR_SUSPEND instead). While here, renumber
PWR_{SUSPEND,RESUME} so that they match the values of DAVCT_{SUSPEND,RESUME}
so that we can eventually (many more steps...) kill the powerhook garbage
and use the activate mechanism.
no objections


# 1.50 25-Aug-2010 kettenis

Make CardBus ral(4) suspend and resume properly on machines that keep the
CardBus bridge powered up during suspend. Step zero on the long road
towards fully suspending CardBus on all machines.

ok deraadt@, damien@


Revision tags: OPENBSD_4_8_BASE
# 1.49 04-Aug-2010 damien

add suspend/resume support for PCI ral(4) devices.

ok deraadt@, sthen@

tested by matthew@ (RT2560), dcoppa@ (RT2790), okan@ (RT2860), todd@ (RT2560)


# 1.48 19-May-2010 oga

BUS_DMA_ZERO instead of alloc, map, bzero.

ok krw@


# 1.47 20-Apr-2010 tedu

remove proc.h include from uvm_map.h. This has far reaching effects, as
sysctl.h was reliant on this particular include, and many drivers included
sysctl.h unnecessarily. remove sysctl.h or add proc.h as needed.
ok deraadt


Revision tags: OPENBSD_4_7_BASE
# 1.46 01-Nov-2009 damien

call powerhook_disestablish() and pci_intr_disestablish() earlier.

diff from deraadt@


# 1.45 10-Aug-2009 damien

three more shutdown hooks bite the dust.


# 1.44 29-Jul-2009 blambert

timeout_add -> timeout_add_msec

ok damien@


Revision tags: OPENBSD_4_6_BASE
# 1.43 29-Mar-2009 sthen

make various strings ("can't map mem space" and similar) more consistent
between instances, saving space in the kernel. feedback from many (some
incorporated, some left for future work).

ok deraadt, kettenis, "why not" miod.


Revision tags: OPENBSD_4_5_BASE
# 1.42 22-Dec-2008 damien

I swapped MGETHDR arguments in my m_defrag removal commit.


# 1.41 21-Dec-2008 damien

Undo m_defrag().

m_defrag() does not work. It seems to assume that if the length of
the mbuf passed as parameter is less than MHLEN, then it is an mbuf
header and not a cluster (or something like that.)
It thus fails miserably in the bcopy path.
I don't have the time to investigate further into this.

Thanks to Okan Demirmen for reporting the issue on a ral(4) RT2560.
The RT2560 chipset does not support TX scatter and thus m_defrag()
was called much more often than in other drivers using m_defrag()
where it was less noticeable.


# 1.40 25-Nov-2008 damien

use shiny new m_defrag() and nitems() instead of rolling our own.


# 1.39 27-Aug-2008 damien

introduce new IEEE80211_STA_ONLY kernel option that can be set to
remove IBSS and HostAP support from net80211 and 802.11 drivers.
it can be used to shrink RAMDISK kernels for instance (like what
was done for wi(4)).
it also has the benefit of highlighting what is specific to IBSS
and HostAP modes in the code.
the cost is that we now have two code paths to maintain.


# 1.38 14-Aug-2008 damien

in ieee80211_input(), call if_start() after enqueuing frames in if_snd
when acting as an access point instead of having each driver doing the
job.

tested by krw@ (ral AP) and me with several drivers.


Revision tags: OPENBSD_4_4_BASE
# 1.37 21-Jul-2008 damien

instead of passing rx tstamp and rssi to the ieee80211_input function,
pass a pointer to an ieee80211_rxinfo structure containing those two
fields plus an extra flags field that indicates whether the frame was
decrypted by hardware or not.
required for a future fix.


# 1.36 16-Apr-2008 damien

Kernel implementation of the 4-way handshake and group-key
handshake protocols (both supplicant and authenticator state
machines) as defined in the IEEE 802.11i standard.

Software implementation of the TKIP (Temporal Key Integrity
Protocol) and CCMP (CTR with CBC-MAC Protocol) protocols.

This diff doesn't implement any of the 802.1X authentication
protocols and thus only PSK authentication (using pre-shared
keys) is currently supported.

In concrete terms, this adds support for WPA-PSK and WPA2-PSK
protocols, both in station and hostap modes.

The following drivers are marked as WPA-capable and should
work: bwi(4), malo(4), ral(4), iwn(4), wpi(4), ural(4),
rum(4), upgt(4), and zyd(4)

The following options have been added to ifconfig(8):
wpa, wpapsk, wpaprotos, wpaakms, wpaciphers, wpagroupcipher

wpa-psk(8) can be used to generate keys from passphrases.

tested by many@
ok deraadt@


Revision tags: OPENBSD_4_3_BASE
# 1.35 17-Nov-2007 damien

RT2560+RT2661: update the physical address in the RX descriptor after
bus_dmamap_load() in the case where the same mbuf is reloaded.
RT2661: remove a 2x prototype, fix an error message.


# 1.34 15-Oct-2007 fgsch

more remove unneeded declarations that shadows existing vars; ok by many.


# 1.33 07-Sep-2007 damien

use new malloc M_ZERO flag to shrink kernel.
remove <malloc.h> from files where malloc is not used.


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.32 08-Mar-2007 deraadt

XXX commit a workaround (as found in a few other drivers) for the
divide by zero rate bug. Someone has to find the source of this
bug one day; from jsg


# 1.31 24-Jan-2007 damien

revert changes committed between r1.25 and 1.26.
this breaks some RT2560 adapters.

pointed out by krw@ and Pierre Riteau.


# 1.30 03-Jan-2007 claudio

M_DUP_PKTHDR() cleanup. On static buffers M_DUP_PKTHDR() will leak mbuf tags.
See similar rum(4) commit for more info. OK mglocker@


# 1.29 17-Dec-2006 damien

fix index of ERP information element in beacons.
still ugly, but correct.


# 1.28 03-Dec-2006 damien

fix handling of the SIOCS80211CHANNEL ioctl in monitor mode:
don't call xxx_set_chan() if the interface is not up&running.

patch from Steffen Schuetz (st dot sch at gmx dot net) with
minor modifications by me.

closes kernel/5313


# 1.27 26-Nov-2006 deraadt

do not have each net80211 driver define its own rates structures. if they use
the standard rates, use some defined by net80211 itself. kernel shrinks a bit
ok jsg mglocker


# 1.26 22-Nov-2006 damien

don't write to BBP before it is ready and fully initialized
-> move rt2560_set{tx,rx}antenna() after rt2560_bbp_init().

from <sephe at dragonflybsd dot org>


# 1.25 13-Nov-2006 damien

first round of commits for proper 11b/g protection support:
- use the newly introduced ieee80211_get_rts() and
ieee80211_get_cts_to_self() functions.
- use CTS-to-self instead of RTS/CTS to protect OFDM frames in
a mixed 11b/g BSS.
- make sure multicast frames are sent using CCK modulation.

remove support for 5GHz radios in ral(4) RT2560 and ural(4).
i'm not aware of any such adapters on the market and 11a code
is known to be broken.

some cleanup while i'm here.


# 1.24 22-Oct-2006 damien

replace rssadapt(9) with amrr for automatic rate control.
as a side-effect, this should fix all the "bogus xmit rate" panics
users have been complaining about for some time when operating in
HostAP mode.


# 1.23 18-Sep-2006 damien

don't use IF_PREPEND() on altq's.
use IFQ_POLL()/IFQ_DEQUEUE() logic instead as described in altq(4).


Revision tags: OPENBSD_4_0_BASE
# 1.22 18-Jul-2006 damien

modify interrupt handlers to exit early and return 0 on shared interrupts.

pointed out by deraadt@


# 1.21 18-Jun-2006 damien

- implement new ic_updateslot() callback.
- in hostap mode, we defer update of the slot time until all associated
STAs are notified with updated beacons.


# 1.20 18-Jun-2006 damien

enable packet bursting when operating as a STA.
limit bursts to 8 frames.


# 1.19 14-Jun-2006 damien

must use RTS/CTS protection when sending frames at OFDM rates in a BSS
with non-ERP STAs. some bits are missing in net80211 though, so this
code won't be triggered yet.


# 1.18 10-Jun-2006 damien

- fix checking of WEP flags
- encrypt mgmt frames when they need to (shared authmode)
- move default MAC/BBP/RF settings from rt2560.c to rt2560reg.h


# 1.17 02-Jun-2006 robert

add powerhooks for ral(4) cards with the RT2560 chipset;

ok damien@


# 1.16 01-Jun-2006 robert

Make the debug printfs work if RAL_DEBUG is defined.


# 1.15 20-Apr-2006 miod

Fix various printf() issues: too many arguments, not enough arguments, argument
order reversed, wrong modifiers. ok deraadt@ marco@ mickey@


# 1.14 27-Mar-2006 damien

fixes interrupts processing.

should fix a panic reported by Karel Gardas.


# 1.13 25-Mar-2006 djm

allow bpf(4) to ignore packets based on their direction (inbound or
outbound), using a new BIOCSDIRFILT ioctl;
guidance, feedback and ok canacar@


Revision tags: OPENBSD_3_9_BASE
# 1.12 25-Feb-2006 damien

branches: 1.12.2;
instead of panicing when tx rate is zero, fallback to 1Mbps.
this is a temporary workaround since we should really not see any node
with an empty rate set but it seems to happen in hostap mode.


# 1.11 18-Feb-2006 damien

don't try to release references to nodes that have been freed by net80211.
in HostAP mode, when switching to the INIT state, net80211 sends a DISASSOC
and a DEAUTH frame to all associated stations and immediately free all the
nodes while we may still hold references to them in our Tx queues.

hopefully, this should fix PRs 4469/kernel and 4953/kernel.


# 1.10 14-Jan-2006 damien

- give rate to rx radiotap
- read TSF high 32bit word before low 32bit word to avoid wraparounds


# 1.9 14-Jan-2006 jsg

Correct the length of the rx radiotap to be that of the rx not tx
struct.

ok damien@


# 1.8 13-Jan-2006 damien

fix short slot time + cosmetic


# 1.7 13-Jan-2006 damien

- simplify lookup of 802.11a channels (we know they exist)
- kill two stupid comments while i'm here


# 1.6 11-Jan-2006 damien

fix RTS protection mode.


# 1.5 10-Jan-2006 damien

- use rssadapt(9) as rate control algorithm
- add 802.11 radiotap support
- read 802.11a channels tx power from EEPROM
- read vendor-specific BBP settings from EEPROM
- fix setting of beacons (xflags)
- fix DMA sync in rt2661_rx_intr
- indicate whether RF supports MIMO in dmesg
- add short slot time support
- many cleanups while i'm here


# 1.4 10-Jan-2006 damien

fix reading of EEPROM content on big endian arches.


# 1.3 10-Jan-2006 damien

send management, control and beacon frames at the lowest possible rate
(1Mbps for 802.11b/g, 6Mbps for 802.11a)


# 1.2 10-Jan-2006 damien

cleanup rt2560_setup_tx_desc().
fix contention window.


# 1.1 09-Jan-2006 damien

- add preliminary support for Ralink Technology RT2561, RT2561S and RT2661
chipsets in ral(4).
- restructure the code a bit; split ic/ral.c into ic/rt2560.c and ic/rt2661.c
- import the 8051 microcode files required by these chipsets.
- more to come; there is currently no automatic rate control and some
features are untested (hostap and ibss modes for instance). most of
the pre-802.11n capabilities of the RT2661 chipset are not supported
(like frame aggregation, piggy-back). MIMO should work though the
performance/range gain has not been measured.