History log of /openbsd-current/sys/dev/ic/bwi.c
Revision (<<< Hide revision tags) (Show revision tags >>>) Date Author Comments
# 1.135 13-Apr-2024 jsg

correct indentation

no functional change, found by smatch warnings
ok miod@ bluhm@


Revision tags: OPENBSD_7_5_BASE
# 1.134 10-Nov-2023 bluhm

Make ifq and ifiq interface MP safe.

Rename ifq_set_maxlen() to ifq_init_maxlen(). This function neither
uses WRITE_ONCE() nor a mutex and is called before the ifq mutex
is initialized. The new name expresses that it should be used only
during interface attach when there is no concurrency.

Protect ifq_len(), ifq_empty(), ifiq_len(), and ifiq_empty() with
READ_ONCE(). They can be used without lock as they only read a
single integer.

OK dlg@


Revision tags: OPENBSD_7_2_BASE OPENBSD_7_3_BASE OPENBSD_7_4_BASE
# 1.133 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.132 09-Jan-2022 jsg

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


Revision tags: OPENBSD_7_0_BASE
# 1.131 16-May-2021 deraadt

panic does not require a \n at the end. When one is provided, it looks wrong.


Revision tags: OPENBSD_6_8_BASE OPENBSD_6_9_BASE
# 1.130 10-Jul-2020 patrick

Change users of IFQ_SET_MAXLEN() and IFQ_IS_EMPTY() to use the "new" API.

ok dlg@ tobhe@


# 1.129 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_6_BASE OPENBSD_6_7_BASE
# 1.128 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.127 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.126 08-Sep-2017 deraadt

If you use sys/param.h, you don't need sys/types.h


# 1.125 03-Jul-2017 kevlo

Replace slot time durations with macros.

ok stsp@


Revision tags: OPENBSD_6_1_BASE
# 1.124 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@


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

G/C IFQ_SET_READY().


Revision tags: OPENBSD_5_9_BASE
# 1.122 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.121 12-Nov-2015 dlg

two newlines in the middle of a func doenst look right.


# 1.120 11-Nov-2015 mpi

Kill useless IFQ_POLL().

ok dlg@


# 1.119 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.118 25-Oct-2015 mpi

arp_ifinit() is no longer needed.


# 1.117 29-Aug-2015 deraadt

firmware sizes are known; use them for free()


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.116 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.115 10-Jan-2015 stsp

Remove pointless empty 64bit support code stubs from bwi(4).
It seems no 64bit bus space support is forthcoming. Nothing
has happened in DragonflyBSD for several years and FreeBSD
has a different driver for 64bit chips called bwn(4).
ok mpi@ some time ago


# 1.114 10-Jan-2015 stsp

Merge two bwi(4) fixes from FreeBSD:


# 1.113 22-Dec-2014 tedu

unifdef INET


# 1.112 19-Dec-2014 guenther

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

ok dlg@ mpi@ bcook@ millert@ miod@


# 1.111 16-Dec-2014 miod

Protect memory allocation and disposal with splvm(); gets rid of splassert
complaints during boot on i386.
ok stsp@


# 1.110 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


# 1.109 06-Sep-2014 jsg

reduce the amount of pci includes


Revision tags: OPENBSD_5_6_BASE
# 1.108 03-Aug-2014 jsg

When stsp changed bwi_encap() for 30 bit addresses in rev 1.106 code
that used to always initialise the error variable is no longer run.

And at the end of bwi_encap() there is:

if (error)
m_freem(m);
return (error);

Fixing this prevents packet loss stsp was seeing.

ok stsp@ miod@ deraadt@


# 1.107 22-Jul-2014 mpi

Fewer <netinet/in_systm.h>


# 1.106 20-Jul-2014 stsp

Always allocate bwi(4) ring descriptors below the 1GB boundary to give 30bit
devices a chance to work. Use bounce buffers for mbufs on 30bit devices.

This fixes "intr fatal TX/RX" errors that render the internal wifi on many
macppc machines unusable. However, packet loss problems remain. In my testing
the device works fine sometimes, but experiences packet loss rates of up
to 80% at other times. Still, this is a step forward.

Helpful hints from claudio@ and dlg@
Tested on macppc by mpi@ and myself
"go ahead" kettenis@, ok mpi@


# 1.105 20-Jul-2014 stsp

In bwi(4), don't declare an interrupt as unhandled in case the PHY TX error
bit is set. This interrupt condition is handled by resetting the device.
ok mpi@ as part of a larger diff


# 1.104 20-Jul-2014 stsp

Make bwi_dma_mbuf_create() use the correct loop counter in error case.
Bug inherited from DragonFly BSD.
ok mpi@ as part of a larger diff.


# 1.103 20-Jul-2014 stsp

Load bwi(4) firmware once, not every time the interface is brought up.
Fixes a panic if the interrupt handler decides to reset the device.
Firmware cannot be loaded in interrupt context.
ok mpi@ as part of a larger diff


# 1.102 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.101 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.100 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.99 14-Nov-2013 dlg

replace workqs with tasks for handling resume

from kimberley manning


# 1.98 01-Oct-2013 sf

Use %z* for size_t

while there, fix a few %d into %u


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.97 31-Dec-2012 miod

Spell `calculation' correctly.


# 1.96 05-Dec-2012 deraadt

Remove excessive sys/cdefs.h inclusion
ok guenther millert kettenis


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.95 27-Aug-2010 jsg

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


Revision tags: OPENBSD_4_8_BASE
# 1.94 07-Aug-2010 krw

No "\n" needed at the end of panic() strings.

Bogus chunks pointed out by matthew@ and miod@. No cookies for
marco@ and jasper@.

ok deraadt@ miod@ matthew@ jasper@ macro@


# 1.93 06-Aug-2010 mglocker

ACPI suspend/resume for bwi(4). Initial diff from todd@, finished and
tested by me on X40 with a BCM4306.

OK deraadt@


# 1.92 19-May-2010 oga

BUS_DMA_ZERO instead of alloc, map, bzero.

ok krw@


Revision tags: OPENBSD_4_7_BASE
# 1.91 13-Sep-2009 krw

M_DUP_PKTHDR() define -> m_dup_pkthdr() function to properly deal
with m_tag_copy_chain() failures.

Use m_defrag() to eliminate hand rolled defragging of mbufs and
some uses of M_DUP_PKTHDR().

Original diff from thib@, claudio@'s feedback integrated by me.

Tests kevlo@ claudio@, "reads ok" blambert@

ok thib@ claudio@, "m_defrag() bits ok" kettenis@


# 1.90 02-Aug-2009 blambert

timeout_add -> timeout_add_msec

ok mglocker@ jsg@


# 1.89 25-Jul-2009 krw

Fix crash in bwi on armish by properly aligning a 32-bit value. Not
to say it works great yet. Might fix bwi on any other alignment
sensitive archs we have.

My original hack generalized and made sane by jsg@. Didn't affect
operation on my macppc. Problem first noted by ian@ a long time
ago.

ok jsg@ (whose tree is currently unavailable to commit from)


# 1.88 19-Jul-2009 jsg

Include 0x4402 in the bbp id mapping table used on older
devices.
http://bcm-specs.sipsolutions.net/BackPlane agrees.


Revision tags: OPENBSD_4_6_BASE
# 1.87 02-Jun-2009 deraadt

change a sizeof() to nitems() because the array subtype is a short.
change all the N() macros to our favorite new macro nitems()
found by Parfait
ok oga guenther


# 1.86 24-May-2009 jsg

declare a variable at the start of bwi_dma_free() instead
of several times throughout the function, in and outside
of a loop.


Revision tags: OPENBSD_4_5_BASE
# 1.85 21-Jan-2009 grange

Replace timeout_add(msecs * hz / 1000) with timeout_add_msec(msecs).
No functional changes.

ok krw@ miod@


# 1.84 07-Jan-2009 jsg

declare bwi_modtype enum before it is used in function prototypes.


# 1.83 26-Nov-2008 dlg

dont have bpf.h expose the kernel ticks variable wherever it is includeing.

it is very confusing like this.

ok deraadt@ canacar@


# 1.82 15-Oct-2008 blambert

Second pass of simple timeout_add -> timeout_add_sec conversions
This should take care of the simpler ones (i.e., timeout values of
integer multiples of hz).

ok krw@, art@


# 1.81 27-Aug-2008 damien

another IEEE80211_RADIOTAP_F_FCS candidate.


# 1.80 27-Aug-2008 damien

override net80211's ic_node_alloc function to allocate a full
bwi_node structure (containing the rate control state).
because bwi(4) does not support HostAP or IBSS modes there is
no need to maintain a per-node rate control state, so we could
as well store it in bwi_softc but that will allow for future
improvements.

pointed out by Taylor R Campbell (campbell AT mumble DOT net)
on tech@


# 1.79 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.78 22-Aug-2008 deraadt

a ; in a bad place; dragonfly; ok mglocker


Revision tags: OPENBSD_4_4_BASE
# 1.77 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.76 11-Jun-2008 jsg

Don't get the address of the txstats pointers when doing bzero,
just use the actual pointers.

Debugged into the early hours of the morning with todd, without
being able to use a keyboard with ddb. Fixes a panic seen on his
powerbook.


# 1.75 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.74 25-Feb-2008 mglocker

Make bwi compile in debug mode again.


# 1.73 25-Feb-2008 mglocker

Sync up with DragonFlyBSD driver. Please read their commit message
for details:

http://leaf.dragonflybsd.org/mailarchive/commits/2008-02/msg00165.html

Tested and OK brad@, kettenis@


# 1.72 16-Feb-2008 mglocker

Zap KKASSERT porting macro and use KASSERT instead.


# 1.71 16-Feb-2008 mglocker

Count output packets.


# 1.70 16-Feb-2008 mglocker

Replace bwi_rate2plcp() with ieee80211_rate2plcp().


# 1.69 16-Feb-2008 mglocker

Fix spacing / comments.


# 1.68 16-Feb-2008 mglocker

While importing the driver a lot of printf's have been converted to
DPRINTF's by mistake. Fix this so we can see fatal errors without beeing
in DEBUG mode.


# 1.67 16-Feb-2008 mglocker

Report rssi and rate in rx radio tap.

From the DragonFlyBSD driver.


# 1.66 16-Feb-2008 mglocker

Better support for 11b mode.

From the DragonFlyBSD driver.


# 1.65 16-Feb-2008 mglocker

Remove some double prototype definitions.


# 1.64 16-Feb-2008 mglocker

Always print device name in front of debug messages.


# 1.63 17-Nov-2007 mglocker

- Add more LED support, like activity blinking (though just supporting
some devices yet).
- Calculate RX rate which can be used later in bpf_mtap().

Diff ported from DragonFlyBSD, tested by some.


# 1.62 18-Oct-2007 mglocker

Add some first LEDs support. Tested on my cardbus Linksys WPC54G Ver 3.

Diff ported from DragonFlyBSD


# 1.61 04-Oct-2007 mglocker

Since we know the firmware load works, merge the single firmware files
together to one single, finally.

You need to bump the firmware package to version 1.3!

OK jsg@


# 1.60 01-Oct-2007 mglocker

Spacing.


# 1.59 01-Oct-2007 mglocker

Fix `bogus xmit rate setup' panic, which mostly happened while associating
to an 11b AP due to not correct initialized tx rates.


# 1.58 01-Oct-2007 jsg

remove rate_fb variable as it always gets set to the same value
as rate anyway.


# 1.57 01-Oct-2007 jsg

Print the MAC address.


# 1.56 01-Oct-2007 jsg

Disable default debug setting, make tx power map printing debug only.


# 1.55 01-Oct-2007 mglocker

Use uint_* consistent.

Agreed with jsg@


# 1.54 30-Sep-2007 mglocker

Spacing.


# 1.53 30-Sep-2007 mglocker

Don't count interrupts with state "not of interest".

From Oleg Safiullin. OK jsg@


# 1.52 30-Sep-2007 kettenis

BWI_BBP_ATTEN is a 16-bit register, so use CSR_WRITE_2 to access it.
Fixes unaligned access on strict-alignment architectures.

ok mglocker@


# 1.51 29-Sep-2007 mglocker

Fix two panic's on macppc. Allows me first network communication over
my PowerBook G4 internal BCM4306 device.


# 1.50 27-Sep-2007 mglocker

Spacing.


# 1.49 27-Sep-2007 mglocker

Add automatic rate control (AMRR).


# 1.48 27-Sep-2007 mglocker

Spacing.


# 1.47 27-Sep-2007 mglocker

Kill __BIT* macros.

Help and OK jsg@


# 1.46 24-Sep-2007 mglocker

Add radio tap support. We still need to calculate correct RX rate and
RX signal strength.


# 1.45 23-Sep-2007 mglocker

Fix page fault kernel crash when changing media and device is up.


# 1.44 23-Sep-2007 mglocker

Add missing device name printf arguments for firmware load error output.


# 1.43 23-Sep-2007 mglocker

More debug ouput cleanup.


# 1.42 23-Sep-2007 mglocker

Correctly clear PCI_STATUS_TARGET_TARGET_ABORT bit.


# 1.41 23-Sep-2007 jsg

Properly handle the physical address in bwi_encap() as well.
With this change I can now scan, associate and ssh via bwi(4)


# 1.40 23-Sep-2007 jsg

Make sure to set physical address in bwi_newbuf()


# 1.39 18-Sep-2007 mglocker

Drag back the original DragonFlyBSD firmware loading routines, so we can
load the same firmware revision as they do. Our previously used firmware
images seem to contain the wrong revision. You need to bump your firmware
package to version 1.2.

Other than expected, loading the right firmware revision still doesn't fix
a fatal chip error at initialization time.


# 1.38 17-Sep-2007 mglocker

If device is down, don't handle any interrupts. Even don't read the
interrupt status register instead return directly. This fixes the machine
freeze on amd64 and let me receive proper interrupts if device is up.
This bit was originaly in the DragonFly code, and must have sneaked out
while porting ...


# 1.37 17-Sep-2007 mglocker

Several DPRINTF arguments was missing, which can lead to ugly kernel
crashes. Fix them.


# 1.36 17-Sep-2007 mglocker

In case of IV load failure free ucode.


# 1.35 16-Sep-2007 mglocker

Remove more obsolete firmware specific bits.


# 1.34 16-Sep-2007 mglocker

Remove obsolete firmware specific bits.


# 1.33 16-Sep-2007 jsg

Better version of fake KKASSERT until they are changed properly.


# 1.32 16-Sep-2007 mglocker

Do sc_disable when device gets stopped.

OK jsg@


# 1.31 16-Sep-2007 jsg

Clear error before starting m_defrag() equivalent.


# 1.30 16-Sep-2007 jsg

Move some noisy debug printfs to higher levels.


# 1.29 16-Sep-2007 jsg

CardBus works much better when sc_enable is called.
Remove some safety returns while here.

ok mglocker@


# 1.28 16-Sep-2007 mglocker

Free ucode if an error happens while FW / IV load. Always return a proper
code in case of error.


# 1.27 16-Sep-2007 jsg

Convert most of the remaining non firmware handling code.


# 1.26 16-Sep-2007 jsg

Remove most of the __unused due to to code being enabled.


# 1.25 15-Sep-2007 mglocker

Adapt firmware images prefix to driver name. Needs bump to firmware
package version 1.1.


# 1.24 15-Sep-2007 mglocker

Get IV load working. Simplified IV loading routine (mainly a rewrite).
Adapted IV loading routines so we can use it with our one file firmware.


# 1.23 15-Sep-2007 jsg

Give hardware physical addresses and add some missing
bus_dmamap_create() calls.


# 1.22 15-Sep-2007 jsg

most of the remaining bus_dma conversion


# 1.21 15-Sep-2007 jsg

Convert bus_dmamap_sync() calls.


# 1.20 15-Sep-2007 jsg

Convert bus_dma_load_mbuf() calls and remove unrequired callback
code previously used.


# 1.19 15-Sep-2007 brad

suitible -> suitable

ok mglocker@ dlg@


# 1.18 15-Sep-2007 jsg

convert bus_dmamap_unload() calls
remove bus_dma_tag_destroy() calls as we don't use/require them.


# 1.17 15-Sep-2007 jsg

convert bus_dmamap_load() calls


# 1.16 15-Sep-2007 jsg

Properly fill in some of the pci information the driver uses internally.


# 1.15 15-Sep-2007 jsg

define BWI_DEBUG to make things easier


# 1.14 14-Sep-2007 mglocker

Get firmware load working. Adapt firmware routines that way so we can
use our one file firmware.


# 1.13 14-Sep-2007 mglocker

Use our standard ratesets from ieee80211 instead.


# 1.12 14-Sep-2007 mglocker

Sort prototypes.


# 1.11 14-Sep-2007 mglocker

Another cleanup run.


# 1.10 13-Sep-2007 mglocker

Move all debug lines to DPRINTF. KNF. Fix some tweaks while there.


# 1.9 13-Sep-2007 mglocker

Add if_detach(). Fixes kernel crash when detaching cardbus device.


# 1.8 13-Sep-2007 mglocker

Ops, remove temporary debug line.


# 1.7 13-Sep-2007 mglocker

Forgot to set psc->psc_pcitag. Replace all PCI/Cardbus config space
functions with our new one. Attachment seems to work now mainly.


# 1.6 13-Sep-2007 mglocker

Enable access to PCI and Cardbus config space from the driver. Lets us
power on the device.


# 1.5 12-Sep-2007 mglocker

Spacing run.


# 1.4 12-Sep-2007 mglocker

For now just return directly from the interrupt handler, or my amd64 will
crash badly.


# 1.3 12-Sep-2007 jsg

Tweak bwi_attach() a little.


# 1.2 12-Sep-2007 jsg

destatic/deinline


# 1.1 12-Sep-2007 jsg

Initial port of Sepherosa Ziehau's DragonFlyBSD driver
for Broadcom AirForce wireless devices.

Not yet functional, things like DMA and firmware handling
haven't been converted yet.

ok mglocker@


# 1.134 10-Nov-2023 bluhm

Make ifq and ifiq interface MP safe.

Rename ifq_set_maxlen() to ifq_init_maxlen(). This function neither
uses WRITE_ONCE() nor a mutex and is called before the ifq mutex
is initialized. The new name expresses that it should be used only
during interface attach when there is no concurrency.

Protect ifq_len(), ifq_empty(), ifiq_len(), and ifiq_empty() with
READ_ONCE(). They can be used without lock as they only read a
single integer.

OK dlg@


Revision tags: OPENBSD_7_2_BASE OPENBSD_7_3_BASE OPENBSD_7_4_BASE
# 1.133 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.132 09-Jan-2022 jsg

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


Revision tags: OPENBSD_7_0_BASE
# 1.131 16-May-2021 deraadt

panic does not require a \n at the end. When one is provided, it looks wrong.


Revision tags: OPENBSD_6_8_BASE OPENBSD_6_9_BASE
# 1.130 10-Jul-2020 patrick

Change users of IFQ_SET_MAXLEN() and IFQ_IS_EMPTY() to use the "new" API.

ok dlg@ tobhe@


# 1.129 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_6_BASE OPENBSD_6_7_BASE
# 1.128 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.127 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.126 08-Sep-2017 deraadt

If you use sys/param.h, you don't need sys/types.h


# 1.125 03-Jul-2017 kevlo

Replace slot time durations with macros.

ok stsp@


Revision tags: OPENBSD_6_1_BASE
# 1.124 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@


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

G/C IFQ_SET_READY().


Revision tags: OPENBSD_5_9_BASE
# 1.122 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.121 12-Nov-2015 dlg

two newlines in the middle of a func doenst look right.


# 1.120 11-Nov-2015 mpi

Kill useless IFQ_POLL().

ok dlg@


# 1.119 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.118 25-Oct-2015 mpi

arp_ifinit() is no longer needed.


# 1.117 29-Aug-2015 deraadt

firmware sizes are known; use them for free()


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.116 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.115 10-Jan-2015 stsp

Remove pointless empty 64bit support code stubs from bwi(4).
It seems no 64bit bus space support is forthcoming. Nothing
has happened in DragonflyBSD for several years and FreeBSD
has a different driver for 64bit chips called bwn(4).
ok mpi@ some time ago


# 1.114 10-Jan-2015 stsp

Merge two bwi(4) fixes from FreeBSD:


# 1.113 22-Dec-2014 tedu

unifdef INET


# 1.112 19-Dec-2014 guenther

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

ok dlg@ mpi@ bcook@ millert@ miod@


# 1.111 16-Dec-2014 miod

Protect memory allocation and disposal with splvm(); gets rid of splassert
complaints during boot on i386.
ok stsp@


# 1.110 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


# 1.109 06-Sep-2014 jsg

reduce the amount of pci includes


Revision tags: OPENBSD_5_6_BASE
# 1.108 03-Aug-2014 jsg

When stsp changed bwi_encap() for 30 bit addresses in rev 1.106 code
that used to always initialise the error variable is no longer run.

And at the end of bwi_encap() there is:

if (error)
m_freem(m);
return (error);

Fixing this prevents packet loss stsp was seeing.

ok stsp@ miod@ deraadt@


# 1.107 22-Jul-2014 mpi

Fewer <netinet/in_systm.h>


# 1.106 20-Jul-2014 stsp

Always allocate bwi(4) ring descriptors below the 1GB boundary to give 30bit
devices a chance to work. Use bounce buffers for mbufs on 30bit devices.

This fixes "intr fatal TX/RX" errors that render the internal wifi on many
macppc machines unusable. However, packet loss problems remain. In my testing
the device works fine sometimes, but experiences packet loss rates of up
to 80% at other times. Still, this is a step forward.

Helpful hints from claudio@ and dlg@
Tested on macppc by mpi@ and myself
"go ahead" kettenis@, ok mpi@


# 1.105 20-Jul-2014 stsp

In bwi(4), don't declare an interrupt as unhandled in case the PHY TX error
bit is set. This interrupt condition is handled by resetting the device.
ok mpi@ as part of a larger diff


# 1.104 20-Jul-2014 stsp

Make bwi_dma_mbuf_create() use the correct loop counter in error case.
Bug inherited from DragonFly BSD.
ok mpi@ as part of a larger diff.


# 1.103 20-Jul-2014 stsp

Load bwi(4) firmware once, not every time the interface is brought up.
Fixes a panic if the interrupt handler decides to reset the device.
Firmware cannot be loaded in interrupt context.
ok mpi@ as part of a larger diff


# 1.102 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.101 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.100 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.99 14-Nov-2013 dlg

replace workqs with tasks for handling resume

from kimberley manning


# 1.98 01-Oct-2013 sf

Use %z* for size_t

while there, fix a few %d into %u


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.97 31-Dec-2012 miod

Spell `calculation' correctly.


# 1.96 05-Dec-2012 deraadt

Remove excessive sys/cdefs.h inclusion
ok guenther millert kettenis


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.95 27-Aug-2010 jsg

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


Revision tags: OPENBSD_4_8_BASE
# 1.94 07-Aug-2010 krw

No "\n" needed at the end of panic() strings.

Bogus chunks pointed out by matthew@ and miod@. No cookies for
marco@ and jasper@.

ok deraadt@ miod@ matthew@ jasper@ macro@


# 1.93 06-Aug-2010 mglocker

ACPI suspend/resume for bwi(4). Initial diff from todd@, finished and
tested by me on X40 with a BCM4306.

OK deraadt@


# 1.92 19-May-2010 oga

BUS_DMA_ZERO instead of alloc, map, bzero.

ok krw@


Revision tags: OPENBSD_4_7_BASE
# 1.91 13-Sep-2009 krw

M_DUP_PKTHDR() define -> m_dup_pkthdr() function to properly deal
with m_tag_copy_chain() failures.

Use m_defrag() to eliminate hand rolled defragging of mbufs and
some uses of M_DUP_PKTHDR().

Original diff from thib@, claudio@'s feedback integrated by me.

Tests kevlo@ claudio@, "reads ok" blambert@

ok thib@ claudio@, "m_defrag() bits ok" kettenis@


# 1.90 02-Aug-2009 blambert

timeout_add -> timeout_add_msec

ok mglocker@ jsg@


# 1.89 25-Jul-2009 krw

Fix crash in bwi on armish by properly aligning a 32-bit value. Not
to say it works great yet. Might fix bwi on any other alignment
sensitive archs we have.

My original hack generalized and made sane by jsg@. Didn't affect
operation on my macppc. Problem first noted by ian@ a long time
ago.

ok jsg@ (whose tree is currently unavailable to commit from)


# 1.88 19-Jul-2009 jsg

Include 0x4402 in the bbp id mapping table used on older
devices.
http://bcm-specs.sipsolutions.net/BackPlane agrees.


Revision tags: OPENBSD_4_6_BASE
# 1.87 02-Jun-2009 deraadt

change a sizeof() to nitems() because the array subtype is a short.
change all the N() macros to our favorite new macro nitems()
found by Parfait
ok oga guenther


# 1.86 24-May-2009 jsg

declare a variable at the start of bwi_dma_free() instead
of several times throughout the function, in and outside
of a loop.


Revision tags: OPENBSD_4_5_BASE
# 1.85 21-Jan-2009 grange

Replace timeout_add(msecs * hz / 1000) with timeout_add_msec(msecs).
No functional changes.

ok krw@ miod@


# 1.84 07-Jan-2009 jsg

declare bwi_modtype enum before it is used in function prototypes.


# 1.83 26-Nov-2008 dlg

dont have bpf.h expose the kernel ticks variable wherever it is includeing.

it is very confusing like this.

ok deraadt@ canacar@


# 1.82 15-Oct-2008 blambert

Second pass of simple timeout_add -> timeout_add_sec conversions
This should take care of the simpler ones (i.e., timeout values of
integer multiples of hz).

ok krw@, art@


# 1.81 27-Aug-2008 damien

another IEEE80211_RADIOTAP_F_FCS candidate.


# 1.80 27-Aug-2008 damien

override net80211's ic_node_alloc function to allocate a full
bwi_node structure (containing the rate control state).
because bwi(4) does not support HostAP or IBSS modes there is
no need to maintain a per-node rate control state, so we could
as well store it in bwi_softc but that will allow for future
improvements.

pointed out by Taylor R Campbell (campbell AT mumble DOT net)
on tech@


# 1.79 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.78 22-Aug-2008 deraadt

a ; in a bad place; dragonfly; ok mglocker


Revision tags: OPENBSD_4_4_BASE
# 1.77 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.76 11-Jun-2008 jsg

Don't get the address of the txstats pointers when doing bzero,
just use the actual pointers.

Debugged into the early hours of the morning with todd, without
being able to use a keyboard with ddb. Fixes a panic seen on his
powerbook.


# 1.75 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.74 25-Feb-2008 mglocker

Make bwi compile in debug mode again.


# 1.73 25-Feb-2008 mglocker

Sync up with DragonFlyBSD driver. Please read their commit message
for details:

http://leaf.dragonflybsd.org/mailarchive/commits/2008-02/msg00165.html

Tested and OK brad@, kettenis@


# 1.72 16-Feb-2008 mglocker

Zap KKASSERT porting macro and use KASSERT instead.


# 1.71 16-Feb-2008 mglocker

Count output packets.


# 1.70 16-Feb-2008 mglocker

Replace bwi_rate2plcp() with ieee80211_rate2plcp().


# 1.69 16-Feb-2008 mglocker

Fix spacing / comments.


# 1.68 16-Feb-2008 mglocker

While importing the driver a lot of printf's have been converted to
DPRINTF's by mistake. Fix this so we can see fatal errors without beeing
in DEBUG mode.


# 1.67 16-Feb-2008 mglocker

Report rssi and rate in rx radio tap.

From the DragonFlyBSD driver.


# 1.66 16-Feb-2008 mglocker

Better support for 11b mode.

From the DragonFlyBSD driver.


# 1.65 16-Feb-2008 mglocker

Remove some double prototype definitions.


# 1.64 16-Feb-2008 mglocker

Always print device name in front of debug messages.


# 1.63 17-Nov-2007 mglocker

- Add more LED support, like activity blinking (though just supporting
some devices yet).
- Calculate RX rate which can be used later in bpf_mtap().

Diff ported from DragonFlyBSD, tested by some.


# 1.62 18-Oct-2007 mglocker

Add some first LEDs support. Tested on my cardbus Linksys WPC54G Ver 3.

Diff ported from DragonFlyBSD


# 1.61 04-Oct-2007 mglocker

Since we know the firmware load works, merge the single firmware files
together to one single, finally.

You need to bump the firmware package to version 1.3!

OK jsg@


# 1.60 01-Oct-2007 mglocker

Spacing.


# 1.59 01-Oct-2007 mglocker

Fix `bogus xmit rate setup' panic, which mostly happened while associating
to an 11b AP due to not correct initialized tx rates.


# 1.58 01-Oct-2007 jsg

remove rate_fb variable as it always gets set to the same value
as rate anyway.


# 1.57 01-Oct-2007 jsg

Print the MAC address.


# 1.56 01-Oct-2007 jsg

Disable default debug setting, make tx power map printing debug only.


# 1.55 01-Oct-2007 mglocker

Use uint_* consistent.

Agreed with jsg@


# 1.54 30-Sep-2007 mglocker

Spacing.


# 1.53 30-Sep-2007 mglocker

Don't count interrupts with state "not of interest".

From Oleg Safiullin. OK jsg@


# 1.52 30-Sep-2007 kettenis

BWI_BBP_ATTEN is a 16-bit register, so use CSR_WRITE_2 to access it.
Fixes unaligned access on strict-alignment architectures.

ok mglocker@


# 1.51 29-Sep-2007 mglocker

Fix two panic's on macppc. Allows me first network communication over
my PowerBook G4 internal BCM4306 device.


# 1.50 27-Sep-2007 mglocker

Spacing.


# 1.49 27-Sep-2007 mglocker

Add automatic rate control (AMRR).


# 1.48 27-Sep-2007 mglocker

Spacing.


# 1.47 27-Sep-2007 mglocker

Kill __BIT* macros.

Help and OK jsg@


# 1.46 24-Sep-2007 mglocker

Add radio tap support. We still need to calculate correct RX rate and
RX signal strength.


# 1.45 23-Sep-2007 mglocker

Fix page fault kernel crash when changing media and device is up.


# 1.44 23-Sep-2007 mglocker

Add missing device name printf arguments for firmware load error output.


# 1.43 23-Sep-2007 mglocker

More debug ouput cleanup.


# 1.42 23-Sep-2007 mglocker

Correctly clear PCI_STATUS_TARGET_TARGET_ABORT bit.


# 1.41 23-Sep-2007 jsg

Properly handle the physical address in bwi_encap() as well.
With this change I can now scan, associate and ssh via bwi(4)


# 1.40 23-Sep-2007 jsg

Make sure to set physical address in bwi_newbuf()


# 1.39 18-Sep-2007 mglocker

Drag back the original DragonFlyBSD firmware loading routines, so we can
load the same firmware revision as they do. Our previously used firmware
images seem to contain the wrong revision. You need to bump your firmware
package to version 1.2.

Other than expected, loading the right firmware revision still doesn't fix
a fatal chip error at initialization time.


# 1.38 17-Sep-2007 mglocker

If device is down, don't handle any interrupts. Even don't read the
interrupt status register instead return directly. This fixes the machine
freeze on amd64 and let me receive proper interrupts if device is up.
This bit was originaly in the DragonFly code, and must have sneaked out
while porting ...


# 1.37 17-Sep-2007 mglocker

Several DPRINTF arguments was missing, which can lead to ugly kernel
crashes. Fix them.


# 1.36 17-Sep-2007 mglocker

In case of IV load failure free ucode.


# 1.35 16-Sep-2007 mglocker

Remove more obsolete firmware specific bits.


# 1.34 16-Sep-2007 mglocker

Remove obsolete firmware specific bits.


# 1.33 16-Sep-2007 jsg

Better version of fake KKASSERT until they are changed properly.


# 1.32 16-Sep-2007 mglocker

Do sc_disable when device gets stopped.

OK jsg@


# 1.31 16-Sep-2007 jsg

Clear error before starting m_defrag() equivalent.


# 1.30 16-Sep-2007 jsg

Move some noisy debug printfs to higher levels.


# 1.29 16-Sep-2007 jsg

CardBus works much better when sc_enable is called.
Remove some safety returns while here.

ok mglocker@


# 1.28 16-Sep-2007 mglocker

Free ucode if an error happens while FW / IV load. Always return a proper
code in case of error.


# 1.27 16-Sep-2007 jsg

Convert most of the remaining non firmware handling code.


# 1.26 16-Sep-2007 jsg

Remove most of the __unused due to to code being enabled.


# 1.25 15-Sep-2007 mglocker

Adapt firmware images prefix to driver name. Needs bump to firmware
package version 1.1.


# 1.24 15-Sep-2007 mglocker

Get IV load working. Simplified IV loading routine (mainly a rewrite).
Adapted IV loading routines so we can use it with our one file firmware.


# 1.23 15-Sep-2007 jsg

Give hardware physical addresses and add some missing
bus_dmamap_create() calls.


# 1.22 15-Sep-2007 jsg

most of the remaining bus_dma conversion


# 1.21 15-Sep-2007 jsg

Convert bus_dmamap_sync() calls.


# 1.20 15-Sep-2007 jsg

Convert bus_dma_load_mbuf() calls and remove unrequired callback
code previously used.


# 1.19 15-Sep-2007 brad

suitible -> suitable

ok mglocker@ dlg@


# 1.18 15-Sep-2007 jsg

convert bus_dmamap_unload() calls
remove bus_dma_tag_destroy() calls as we don't use/require them.


# 1.17 15-Sep-2007 jsg

convert bus_dmamap_load() calls


# 1.16 15-Sep-2007 jsg

Properly fill in some of the pci information the driver uses internally.


# 1.15 15-Sep-2007 jsg

define BWI_DEBUG to make things easier


# 1.14 14-Sep-2007 mglocker

Get firmware load working. Adapt firmware routines that way so we can
use our one file firmware.


# 1.13 14-Sep-2007 mglocker

Use our standard ratesets from ieee80211 instead.


# 1.12 14-Sep-2007 mglocker

Sort prototypes.


# 1.11 14-Sep-2007 mglocker

Another cleanup run.


# 1.10 13-Sep-2007 mglocker

Move all debug lines to DPRINTF. KNF. Fix some tweaks while there.


# 1.9 13-Sep-2007 mglocker

Add if_detach(). Fixes kernel crash when detaching cardbus device.


# 1.8 13-Sep-2007 mglocker

Ops, remove temporary debug line.


# 1.7 13-Sep-2007 mglocker

Forgot to set psc->psc_pcitag. Replace all PCI/Cardbus config space
functions with our new one. Attachment seems to work now mainly.


# 1.6 13-Sep-2007 mglocker

Enable access to PCI and Cardbus config space from the driver. Lets us
power on the device.


# 1.5 12-Sep-2007 mglocker

Spacing run.


# 1.4 12-Sep-2007 mglocker

For now just return directly from the interrupt handler, or my amd64 will
crash badly.


# 1.3 12-Sep-2007 jsg

Tweak bwi_attach() a little.


# 1.2 12-Sep-2007 jsg

destatic/deinline


# 1.1 12-Sep-2007 jsg

Initial port of Sepherosa Ziehau's DragonFlyBSD driver
for Broadcom AirForce wireless devices.

Not yet functional, things like DMA and firmware handling
haven't been converted yet.

ok mglocker@


# 1.133 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.132 09-Jan-2022 jsg

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


Revision tags: OPENBSD_7_0_BASE
# 1.131 16-May-2021 deraadt

panic does not require a \n at the end. When one is provided, it looks wrong.


Revision tags: OPENBSD_6_8_BASE OPENBSD_6_9_BASE
# 1.130 10-Jul-2020 patrick

Change users of IFQ_SET_MAXLEN() and IFQ_IS_EMPTY() to use the "new" API.

ok dlg@ tobhe@


# 1.129 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_6_BASE OPENBSD_6_7_BASE
# 1.128 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.127 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.126 08-Sep-2017 deraadt

If you use sys/param.h, you don't need sys/types.h


# 1.125 03-Jul-2017 kevlo

Replace slot time durations with macros.

ok stsp@


Revision tags: OPENBSD_6_1_BASE
# 1.124 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@


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

G/C IFQ_SET_READY().


Revision tags: OPENBSD_5_9_BASE
# 1.122 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.121 12-Nov-2015 dlg

two newlines in the middle of a func doenst look right.


# 1.120 11-Nov-2015 mpi

Kill useless IFQ_POLL().

ok dlg@


# 1.119 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.118 25-Oct-2015 mpi

arp_ifinit() is no longer needed.


# 1.117 29-Aug-2015 deraadt

firmware sizes are known; use them for free()


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.116 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.115 10-Jan-2015 stsp

Remove pointless empty 64bit support code stubs from bwi(4).
It seems no 64bit bus space support is forthcoming. Nothing
has happened in DragonflyBSD for several years and FreeBSD
has a different driver for 64bit chips called bwn(4).
ok mpi@ some time ago


# 1.114 10-Jan-2015 stsp

Merge two bwi(4) fixes from FreeBSD:


# 1.113 22-Dec-2014 tedu

unifdef INET


# 1.112 19-Dec-2014 guenther

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

ok dlg@ mpi@ bcook@ millert@ miod@


# 1.111 16-Dec-2014 miod

Protect memory allocation and disposal with splvm(); gets rid of splassert
complaints during boot on i386.
ok stsp@


# 1.110 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


# 1.109 06-Sep-2014 jsg

reduce the amount of pci includes


Revision tags: OPENBSD_5_6_BASE
# 1.108 03-Aug-2014 jsg

When stsp changed bwi_encap() for 30 bit addresses in rev 1.106 code
that used to always initialise the error variable is no longer run.

And at the end of bwi_encap() there is:

if (error)
m_freem(m);
return (error);

Fixing this prevents packet loss stsp was seeing.

ok stsp@ miod@ deraadt@


# 1.107 22-Jul-2014 mpi

Fewer <netinet/in_systm.h>


# 1.106 20-Jul-2014 stsp

Always allocate bwi(4) ring descriptors below the 1GB boundary to give 30bit
devices a chance to work. Use bounce buffers for mbufs on 30bit devices.

This fixes "intr fatal TX/RX" errors that render the internal wifi on many
macppc machines unusable. However, packet loss problems remain. In my testing
the device works fine sometimes, but experiences packet loss rates of up
to 80% at other times. Still, this is a step forward.

Helpful hints from claudio@ and dlg@
Tested on macppc by mpi@ and myself
"go ahead" kettenis@, ok mpi@


# 1.105 20-Jul-2014 stsp

In bwi(4), don't declare an interrupt as unhandled in case the PHY TX error
bit is set. This interrupt condition is handled by resetting the device.
ok mpi@ as part of a larger diff


# 1.104 20-Jul-2014 stsp

Make bwi_dma_mbuf_create() use the correct loop counter in error case.
Bug inherited from DragonFly BSD.
ok mpi@ as part of a larger diff.


# 1.103 20-Jul-2014 stsp

Load bwi(4) firmware once, not every time the interface is brought up.
Fixes a panic if the interrupt handler decides to reset the device.
Firmware cannot be loaded in interrupt context.
ok mpi@ as part of a larger diff


# 1.102 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.101 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.100 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.99 14-Nov-2013 dlg

replace workqs with tasks for handling resume

from kimberley manning


# 1.98 01-Oct-2013 sf

Use %z* for size_t

while there, fix a few %d into %u


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.97 31-Dec-2012 miod

Spell `calculation' correctly.


# 1.96 05-Dec-2012 deraadt

Remove excessive sys/cdefs.h inclusion
ok guenther millert kettenis


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.95 27-Aug-2010 jsg

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


Revision tags: OPENBSD_4_8_BASE
# 1.94 07-Aug-2010 krw

No "\n" needed at the end of panic() strings.

Bogus chunks pointed out by matthew@ and miod@. No cookies for
marco@ and jasper@.

ok deraadt@ miod@ matthew@ jasper@ macro@


# 1.93 06-Aug-2010 mglocker

ACPI suspend/resume for bwi(4). Initial diff from todd@, finished and
tested by me on X40 with a BCM4306.

OK deraadt@


# 1.92 19-May-2010 oga

BUS_DMA_ZERO instead of alloc, map, bzero.

ok krw@


Revision tags: OPENBSD_4_7_BASE
# 1.91 13-Sep-2009 krw

M_DUP_PKTHDR() define -> m_dup_pkthdr() function to properly deal
with m_tag_copy_chain() failures.

Use m_defrag() to eliminate hand rolled defragging of mbufs and
some uses of M_DUP_PKTHDR().

Original diff from thib@, claudio@'s feedback integrated by me.

Tests kevlo@ claudio@, "reads ok" blambert@

ok thib@ claudio@, "m_defrag() bits ok" kettenis@


# 1.90 02-Aug-2009 blambert

timeout_add -> timeout_add_msec

ok mglocker@ jsg@


# 1.89 25-Jul-2009 krw

Fix crash in bwi on armish by properly aligning a 32-bit value. Not
to say it works great yet. Might fix bwi on any other alignment
sensitive archs we have.

My original hack generalized and made sane by jsg@. Didn't affect
operation on my macppc. Problem first noted by ian@ a long time
ago.

ok jsg@ (whose tree is currently unavailable to commit from)


# 1.88 19-Jul-2009 jsg

Include 0x4402 in the bbp id mapping table used on older
devices.
http://bcm-specs.sipsolutions.net/BackPlane agrees.


Revision tags: OPENBSD_4_6_BASE
# 1.87 02-Jun-2009 deraadt

change a sizeof() to nitems() because the array subtype is a short.
change all the N() macros to our favorite new macro nitems()
found by Parfait
ok oga guenther


# 1.86 24-May-2009 jsg

declare a variable at the start of bwi_dma_free() instead
of several times throughout the function, in and outside
of a loop.


Revision tags: OPENBSD_4_5_BASE
# 1.85 21-Jan-2009 grange

Replace timeout_add(msecs * hz / 1000) with timeout_add_msec(msecs).
No functional changes.

ok krw@ miod@


# 1.84 07-Jan-2009 jsg

declare bwi_modtype enum before it is used in function prototypes.


# 1.83 26-Nov-2008 dlg

dont have bpf.h expose the kernel ticks variable wherever it is includeing.

it is very confusing like this.

ok deraadt@ canacar@


# 1.82 15-Oct-2008 blambert

Second pass of simple timeout_add -> timeout_add_sec conversions
This should take care of the simpler ones (i.e., timeout values of
integer multiples of hz).

ok krw@, art@


# 1.81 27-Aug-2008 damien

another IEEE80211_RADIOTAP_F_FCS candidate.


# 1.80 27-Aug-2008 damien

override net80211's ic_node_alloc function to allocate a full
bwi_node structure (containing the rate control state).
because bwi(4) does not support HostAP or IBSS modes there is
no need to maintain a per-node rate control state, so we could
as well store it in bwi_softc but that will allow for future
improvements.

pointed out by Taylor R Campbell (campbell AT mumble DOT net)
on tech@


# 1.79 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.78 22-Aug-2008 deraadt

a ; in a bad place; dragonfly; ok mglocker


Revision tags: OPENBSD_4_4_BASE
# 1.77 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.76 11-Jun-2008 jsg

Don't get the address of the txstats pointers when doing bzero,
just use the actual pointers.

Debugged into the early hours of the morning with todd, without
being able to use a keyboard with ddb. Fixes a panic seen on his
powerbook.


# 1.75 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.74 25-Feb-2008 mglocker

Make bwi compile in debug mode again.


# 1.73 25-Feb-2008 mglocker

Sync up with DragonFlyBSD driver. Please read their commit message
for details:

http://leaf.dragonflybsd.org/mailarchive/commits/2008-02/msg00165.html

Tested and OK brad@, kettenis@


# 1.72 16-Feb-2008 mglocker

Zap KKASSERT porting macro and use KASSERT instead.


# 1.71 16-Feb-2008 mglocker

Count output packets.


# 1.70 16-Feb-2008 mglocker

Replace bwi_rate2plcp() with ieee80211_rate2plcp().


# 1.69 16-Feb-2008 mglocker

Fix spacing / comments.


# 1.68 16-Feb-2008 mglocker

While importing the driver a lot of printf's have been converted to
DPRINTF's by mistake. Fix this so we can see fatal errors without beeing
in DEBUG mode.


# 1.67 16-Feb-2008 mglocker

Report rssi and rate in rx radio tap.

From the DragonFlyBSD driver.


# 1.66 16-Feb-2008 mglocker

Better support for 11b mode.

From the DragonFlyBSD driver.


# 1.65 16-Feb-2008 mglocker

Remove some double prototype definitions.


# 1.64 16-Feb-2008 mglocker

Always print device name in front of debug messages.


# 1.63 17-Nov-2007 mglocker

- Add more LED support, like activity blinking (though just supporting
some devices yet).
- Calculate RX rate which can be used later in bpf_mtap().

Diff ported from DragonFlyBSD, tested by some.


# 1.62 18-Oct-2007 mglocker

Add some first LEDs support. Tested on my cardbus Linksys WPC54G Ver 3.

Diff ported from DragonFlyBSD


# 1.61 04-Oct-2007 mglocker

Since we know the firmware load works, merge the single firmware files
together to one single, finally.

You need to bump the firmware package to version 1.3!

OK jsg@


# 1.60 01-Oct-2007 mglocker

Spacing.


# 1.59 01-Oct-2007 mglocker

Fix `bogus xmit rate setup' panic, which mostly happened while associating
to an 11b AP due to not correct initialized tx rates.


# 1.58 01-Oct-2007 jsg

remove rate_fb variable as it always gets set to the same value
as rate anyway.


# 1.57 01-Oct-2007 jsg

Print the MAC address.


# 1.56 01-Oct-2007 jsg

Disable default debug setting, make tx power map printing debug only.


# 1.55 01-Oct-2007 mglocker

Use uint_* consistent.

Agreed with jsg@


# 1.54 30-Sep-2007 mglocker

Spacing.


# 1.53 30-Sep-2007 mglocker

Don't count interrupts with state "not of interest".

From Oleg Safiullin. OK jsg@


# 1.52 30-Sep-2007 kettenis

BWI_BBP_ATTEN is a 16-bit register, so use CSR_WRITE_2 to access it.
Fixes unaligned access on strict-alignment architectures.

ok mglocker@


# 1.51 29-Sep-2007 mglocker

Fix two panic's on macppc. Allows me first network communication over
my PowerBook G4 internal BCM4306 device.


# 1.50 27-Sep-2007 mglocker

Spacing.


# 1.49 27-Sep-2007 mglocker

Add automatic rate control (AMRR).


# 1.48 27-Sep-2007 mglocker

Spacing.


# 1.47 27-Sep-2007 mglocker

Kill __BIT* macros.

Help and OK jsg@


# 1.46 24-Sep-2007 mglocker

Add radio tap support. We still need to calculate correct RX rate and
RX signal strength.


# 1.45 23-Sep-2007 mglocker

Fix page fault kernel crash when changing media and device is up.


# 1.44 23-Sep-2007 mglocker

Add missing device name printf arguments for firmware load error output.


# 1.43 23-Sep-2007 mglocker

More debug ouput cleanup.


# 1.42 23-Sep-2007 mglocker

Correctly clear PCI_STATUS_TARGET_TARGET_ABORT bit.


# 1.41 23-Sep-2007 jsg

Properly handle the physical address in bwi_encap() as well.
With this change I can now scan, associate and ssh via bwi(4)


# 1.40 23-Sep-2007 jsg

Make sure to set physical address in bwi_newbuf()


# 1.39 18-Sep-2007 mglocker

Drag back the original DragonFlyBSD firmware loading routines, so we can
load the same firmware revision as they do. Our previously used firmware
images seem to contain the wrong revision. You need to bump your firmware
package to version 1.2.

Other than expected, loading the right firmware revision still doesn't fix
a fatal chip error at initialization time.


# 1.38 17-Sep-2007 mglocker

If device is down, don't handle any interrupts. Even don't read the
interrupt status register instead return directly. This fixes the machine
freeze on amd64 and let me receive proper interrupts if device is up.
This bit was originaly in the DragonFly code, and must have sneaked out
while porting ...


# 1.37 17-Sep-2007 mglocker

Several DPRINTF arguments was missing, which can lead to ugly kernel
crashes. Fix them.


# 1.36 17-Sep-2007 mglocker

In case of IV load failure free ucode.


# 1.35 16-Sep-2007 mglocker

Remove more obsolete firmware specific bits.


# 1.34 16-Sep-2007 mglocker

Remove obsolete firmware specific bits.


# 1.33 16-Sep-2007 jsg

Better version of fake KKASSERT until they are changed properly.


# 1.32 16-Sep-2007 mglocker

Do sc_disable when device gets stopped.

OK jsg@


# 1.31 16-Sep-2007 jsg

Clear error before starting m_defrag() equivalent.


# 1.30 16-Sep-2007 jsg

Move some noisy debug printfs to higher levels.


# 1.29 16-Sep-2007 jsg

CardBus works much better when sc_enable is called.
Remove some safety returns while here.

ok mglocker@


# 1.28 16-Sep-2007 mglocker

Free ucode if an error happens while FW / IV load. Always return a proper
code in case of error.


# 1.27 16-Sep-2007 jsg

Convert most of the remaining non firmware handling code.


# 1.26 16-Sep-2007 jsg

Remove most of the __unused due to to code being enabled.


# 1.25 15-Sep-2007 mglocker

Adapt firmware images prefix to driver name. Needs bump to firmware
package version 1.1.


# 1.24 15-Sep-2007 mglocker

Get IV load working. Simplified IV loading routine (mainly a rewrite).
Adapted IV loading routines so we can use it with our one file firmware.


# 1.23 15-Sep-2007 jsg

Give hardware physical addresses and add some missing
bus_dmamap_create() calls.


# 1.22 15-Sep-2007 jsg

most of the remaining bus_dma conversion


# 1.21 15-Sep-2007 jsg

Convert bus_dmamap_sync() calls.


# 1.20 15-Sep-2007 jsg

Convert bus_dma_load_mbuf() calls and remove unrequired callback
code previously used.


# 1.19 15-Sep-2007 brad

suitible -> suitable

ok mglocker@ dlg@


# 1.18 15-Sep-2007 jsg

convert bus_dmamap_unload() calls
remove bus_dma_tag_destroy() calls as we don't use/require them.


# 1.17 15-Sep-2007 jsg

convert bus_dmamap_load() calls


# 1.16 15-Sep-2007 jsg

Properly fill in some of the pci information the driver uses internally.


# 1.15 15-Sep-2007 jsg

define BWI_DEBUG to make things easier


# 1.14 14-Sep-2007 mglocker

Get firmware load working. Adapt firmware routines that way so we can
use our one file firmware.


# 1.13 14-Sep-2007 mglocker

Use our standard ratesets from ieee80211 instead.


# 1.12 14-Sep-2007 mglocker

Sort prototypes.


# 1.11 14-Sep-2007 mglocker

Another cleanup run.


# 1.10 13-Sep-2007 mglocker

Move all debug lines to DPRINTF. KNF. Fix some tweaks while there.


# 1.9 13-Sep-2007 mglocker

Add if_detach(). Fixes kernel crash when detaching cardbus device.


# 1.8 13-Sep-2007 mglocker

Ops, remove temporary debug line.


# 1.7 13-Sep-2007 mglocker

Forgot to set psc->psc_pcitag. Replace all PCI/Cardbus config space
functions with our new one. Attachment seems to work now mainly.


# 1.6 13-Sep-2007 mglocker

Enable access to PCI and Cardbus config space from the driver. Lets us
power on the device.


# 1.5 12-Sep-2007 mglocker

Spacing run.


# 1.4 12-Sep-2007 mglocker

For now just return directly from the interrupt handler, or my amd64 will
crash badly.


# 1.3 12-Sep-2007 jsg

Tweak bwi_attach() a little.


# 1.2 12-Sep-2007 jsg

destatic/deinline


# 1.1 12-Sep-2007 jsg

Initial port of Sepherosa Ziehau's DragonFlyBSD driver
for Broadcom AirForce wireless devices.

Not yet functional, things like DMA and firmware handling
haven't been converted yet.

ok mglocker@


# 1.132 09-Jan-2022 jsg

spelling
feedback and ok tb@ jmc@ ok ratchov@


Revision tags: OPENBSD_7_0_BASE
# 1.131 16-May-2021 deraadt

panic does not require a \n at the end. When one is provided, it looks wrong.


Revision tags: OPENBSD_6_8_BASE OPENBSD_6_9_BASE
# 1.130 10-Jul-2020 patrick

Change users of IFQ_SET_MAXLEN() and IFQ_IS_EMPTY() to use the "new" API.

ok dlg@ tobhe@


# 1.129 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_6_BASE OPENBSD_6_7_BASE
# 1.128 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.127 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.126 08-Sep-2017 deraadt

If you use sys/param.h, you don't need sys/types.h


# 1.125 03-Jul-2017 kevlo

Replace slot time durations with macros.

ok stsp@


Revision tags: OPENBSD_6_1_BASE
# 1.124 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@


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

G/C IFQ_SET_READY().


Revision tags: OPENBSD_5_9_BASE
# 1.122 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.121 12-Nov-2015 dlg

two newlines in the middle of a func doenst look right.


# 1.120 11-Nov-2015 mpi

Kill useless IFQ_POLL().

ok dlg@


# 1.119 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.118 25-Oct-2015 mpi

arp_ifinit() is no longer needed.


# 1.117 29-Aug-2015 deraadt

firmware sizes are known; use them for free()


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.116 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.115 10-Jan-2015 stsp

Remove pointless empty 64bit support code stubs from bwi(4).
It seems no 64bit bus space support is forthcoming. Nothing
has happened in DragonflyBSD for several years and FreeBSD
has a different driver for 64bit chips called bwn(4).
ok mpi@ some time ago


# 1.114 10-Jan-2015 stsp

Merge two bwi(4) fixes from FreeBSD:


# 1.113 22-Dec-2014 tedu

unifdef INET


# 1.112 19-Dec-2014 guenther

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

ok dlg@ mpi@ bcook@ millert@ miod@


# 1.111 16-Dec-2014 miod

Protect memory allocation and disposal with splvm(); gets rid of splassert
complaints during boot on i386.
ok stsp@


# 1.110 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


# 1.109 06-Sep-2014 jsg

reduce the amount of pci includes


Revision tags: OPENBSD_5_6_BASE
# 1.108 03-Aug-2014 jsg

When stsp changed bwi_encap() for 30 bit addresses in rev 1.106 code
that used to always initialise the error variable is no longer run.

And at the end of bwi_encap() there is:

if (error)
m_freem(m);
return (error);

Fixing this prevents packet loss stsp was seeing.

ok stsp@ miod@ deraadt@


# 1.107 22-Jul-2014 mpi

Fewer <netinet/in_systm.h>


# 1.106 20-Jul-2014 stsp

Always allocate bwi(4) ring descriptors below the 1GB boundary to give 30bit
devices a chance to work. Use bounce buffers for mbufs on 30bit devices.

This fixes "intr fatal TX/RX" errors that render the internal wifi on many
macppc machines unusable. However, packet loss problems remain. In my testing
the device works fine sometimes, but experiences packet loss rates of up
to 80% at other times. Still, this is a step forward.

Helpful hints from claudio@ and dlg@
Tested on macppc by mpi@ and myself
"go ahead" kettenis@, ok mpi@


# 1.105 20-Jul-2014 stsp

In bwi(4), don't declare an interrupt as unhandled in case the PHY TX error
bit is set. This interrupt condition is handled by resetting the device.
ok mpi@ as part of a larger diff


# 1.104 20-Jul-2014 stsp

Make bwi_dma_mbuf_create() use the correct loop counter in error case.
Bug inherited from DragonFly BSD.
ok mpi@ as part of a larger diff.


# 1.103 20-Jul-2014 stsp

Load bwi(4) firmware once, not every time the interface is brought up.
Fixes a panic if the interrupt handler decides to reset the device.
Firmware cannot be loaded in interrupt context.
ok mpi@ as part of a larger diff


# 1.102 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.101 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.100 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.99 14-Nov-2013 dlg

replace workqs with tasks for handling resume

from kimberley manning


# 1.98 01-Oct-2013 sf

Use %z* for size_t

while there, fix a few %d into %u


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.97 31-Dec-2012 miod

Spell `calculation' correctly.


# 1.96 05-Dec-2012 deraadt

Remove excessive sys/cdefs.h inclusion
ok guenther millert kettenis


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.95 27-Aug-2010 jsg

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


Revision tags: OPENBSD_4_8_BASE
# 1.94 07-Aug-2010 krw

No "\n" needed at the end of panic() strings.

Bogus chunks pointed out by matthew@ and miod@. No cookies for
marco@ and jasper@.

ok deraadt@ miod@ matthew@ jasper@ macro@


# 1.93 06-Aug-2010 mglocker

ACPI suspend/resume for bwi(4). Initial diff from todd@, finished and
tested by me on X40 with a BCM4306.

OK deraadt@


# 1.92 19-May-2010 oga

BUS_DMA_ZERO instead of alloc, map, bzero.

ok krw@


Revision tags: OPENBSD_4_7_BASE
# 1.91 13-Sep-2009 krw

M_DUP_PKTHDR() define -> m_dup_pkthdr() function to properly deal
with m_tag_copy_chain() failures.

Use m_defrag() to eliminate hand rolled defragging of mbufs and
some uses of M_DUP_PKTHDR().

Original diff from thib@, claudio@'s feedback integrated by me.

Tests kevlo@ claudio@, "reads ok" blambert@

ok thib@ claudio@, "m_defrag() bits ok" kettenis@


# 1.90 02-Aug-2009 blambert

timeout_add -> timeout_add_msec

ok mglocker@ jsg@


# 1.89 25-Jul-2009 krw

Fix crash in bwi on armish by properly aligning a 32-bit value. Not
to say it works great yet. Might fix bwi on any other alignment
sensitive archs we have.

My original hack generalized and made sane by jsg@. Didn't affect
operation on my macppc. Problem first noted by ian@ a long time
ago.

ok jsg@ (whose tree is currently unavailable to commit from)


# 1.88 19-Jul-2009 jsg

Include 0x4402 in the bbp id mapping table used on older
devices.
http://bcm-specs.sipsolutions.net/BackPlane agrees.


Revision tags: OPENBSD_4_6_BASE
# 1.87 02-Jun-2009 deraadt

change a sizeof() to nitems() because the array subtype is a short.
change all the N() macros to our favorite new macro nitems()
found by Parfait
ok oga guenther


# 1.86 24-May-2009 jsg

declare a variable at the start of bwi_dma_free() instead
of several times throughout the function, in and outside
of a loop.


Revision tags: OPENBSD_4_5_BASE
# 1.85 21-Jan-2009 grange

Replace timeout_add(msecs * hz / 1000) with timeout_add_msec(msecs).
No functional changes.

ok krw@ miod@


# 1.84 07-Jan-2009 jsg

declare bwi_modtype enum before it is used in function prototypes.


# 1.83 26-Nov-2008 dlg

dont have bpf.h expose the kernel ticks variable wherever it is includeing.

it is very confusing like this.

ok deraadt@ canacar@


# 1.82 15-Oct-2008 blambert

Second pass of simple timeout_add -> timeout_add_sec conversions
This should take care of the simpler ones (i.e., timeout values of
integer multiples of hz).

ok krw@, art@


# 1.81 27-Aug-2008 damien

another IEEE80211_RADIOTAP_F_FCS candidate.


# 1.80 27-Aug-2008 damien

override net80211's ic_node_alloc function to allocate a full
bwi_node structure (containing the rate control state).
because bwi(4) does not support HostAP or IBSS modes there is
no need to maintain a per-node rate control state, so we could
as well store it in bwi_softc but that will allow for future
improvements.

pointed out by Taylor R Campbell (campbell AT mumble DOT net)
on tech@


# 1.79 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.78 22-Aug-2008 deraadt

a ; in a bad place; dragonfly; ok mglocker


Revision tags: OPENBSD_4_4_BASE
# 1.77 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.76 11-Jun-2008 jsg

Don't get the address of the txstats pointers when doing bzero,
just use the actual pointers.

Debugged into the early hours of the morning with todd, without
being able to use a keyboard with ddb. Fixes a panic seen on his
powerbook.


# 1.75 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.74 25-Feb-2008 mglocker

Make bwi compile in debug mode again.


# 1.73 25-Feb-2008 mglocker

Sync up with DragonFlyBSD driver. Please read their commit message
for details:

http://leaf.dragonflybsd.org/mailarchive/commits/2008-02/msg00165.html

Tested and OK brad@, kettenis@


# 1.72 16-Feb-2008 mglocker

Zap KKASSERT porting macro and use KASSERT instead.


# 1.71 16-Feb-2008 mglocker

Count output packets.


# 1.70 16-Feb-2008 mglocker

Replace bwi_rate2plcp() with ieee80211_rate2plcp().


# 1.69 16-Feb-2008 mglocker

Fix spacing / comments.


# 1.68 16-Feb-2008 mglocker

While importing the driver a lot of printf's have been converted to
DPRINTF's by mistake. Fix this so we can see fatal errors without beeing
in DEBUG mode.


# 1.67 16-Feb-2008 mglocker

Report rssi and rate in rx radio tap.

From the DragonFlyBSD driver.


# 1.66 16-Feb-2008 mglocker

Better support for 11b mode.

From the DragonFlyBSD driver.


# 1.65 16-Feb-2008 mglocker

Remove some double prototype definitions.


# 1.64 16-Feb-2008 mglocker

Always print device name in front of debug messages.


# 1.63 17-Nov-2007 mglocker

- Add more LED support, like activity blinking (though just supporting
some devices yet).
- Calculate RX rate which can be used later in bpf_mtap().

Diff ported from DragonFlyBSD, tested by some.


# 1.62 18-Oct-2007 mglocker

Add some first LEDs support. Tested on my cardbus Linksys WPC54G Ver 3.

Diff ported from DragonFlyBSD


# 1.61 04-Oct-2007 mglocker

Since we know the firmware load works, merge the single firmware files
together to one single, finally.

You need to bump the firmware package to version 1.3!

OK jsg@


# 1.60 01-Oct-2007 mglocker

Spacing.


# 1.59 01-Oct-2007 mglocker

Fix `bogus xmit rate setup' panic, which mostly happened while associating
to an 11b AP due to not correct initialized tx rates.


# 1.58 01-Oct-2007 jsg

remove rate_fb variable as it always gets set to the same value
as rate anyway.


# 1.57 01-Oct-2007 jsg

Print the MAC address.


# 1.56 01-Oct-2007 jsg

Disable default debug setting, make tx power map printing debug only.


# 1.55 01-Oct-2007 mglocker

Use uint_* consistent.

Agreed with jsg@


# 1.54 30-Sep-2007 mglocker

Spacing.


# 1.53 30-Sep-2007 mglocker

Don't count interrupts with state "not of interest".

From Oleg Safiullin. OK jsg@


# 1.52 30-Sep-2007 kettenis

BWI_BBP_ATTEN is a 16-bit register, so use CSR_WRITE_2 to access it.
Fixes unaligned access on strict-alignment architectures.

ok mglocker@


# 1.51 29-Sep-2007 mglocker

Fix two panic's on macppc. Allows me first network communication over
my PowerBook G4 internal BCM4306 device.


# 1.50 27-Sep-2007 mglocker

Spacing.


# 1.49 27-Sep-2007 mglocker

Add automatic rate control (AMRR).


# 1.48 27-Sep-2007 mglocker

Spacing.


# 1.47 27-Sep-2007 mglocker

Kill __BIT* macros.

Help and OK jsg@


# 1.46 24-Sep-2007 mglocker

Add radio tap support. We still need to calculate correct RX rate and
RX signal strength.


# 1.45 23-Sep-2007 mglocker

Fix page fault kernel crash when changing media and device is up.


# 1.44 23-Sep-2007 mglocker

Add missing device name printf arguments for firmware load error output.


# 1.43 23-Sep-2007 mglocker

More debug ouput cleanup.


# 1.42 23-Sep-2007 mglocker

Correctly clear PCI_STATUS_TARGET_TARGET_ABORT bit.


# 1.41 23-Sep-2007 jsg

Properly handle the physical address in bwi_encap() as well.
With this change I can now scan, associate and ssh via bwi(4)


# 1.40 23-Sep-2007 jsg

Make sure to set physical address in bwi_newbuf()


# 1.39 18-Sep-2007 mglocker

Drag back the original DragonFlyBSD firmware loading routines, so we can
load the same firmware revision as they do. Our previously used firmware
images seem to contain the wrong revision. You need to bump your firmware
package to version 1.2.

Other than expected, loading the right firmware revision still doesn't fix
a fatal chip error at initialization time.


# 1.38 17-Sep-2007 mglocker

If device is down, don't handle any interrupts. Even don't read the
interrupt status register instead return directly. This fixes the machine
freeze on amd64 and let me receive proper interrupts if device is up.
This bit was originaly in the DragonFly code, and must have sneaked out
while porting ...


# 1.37 17-Sep-2007 mglocker

Several DPRINTF arguments was missing, which can lead to ugly kernel
crashes. Fix them.


# 1.36 17-Sep-2007 mglocker

In case of IV load failure free ucode.


# 1.35 16-Sep-2007 mglocker

Remove more obsolete firmware specific bits.


# 1.34 16-Sep-2007 mglocker

Remove obsolete firmware specific bits.


# 1.33 16-Sep-2007 jsg

Better version of fake KKASSERT until they are changed properly.


# 1.32 16-Sep-2007 mglocker

Do sc_disable when device gets stopped.

OK jsg@


# 1.31 16-Sep-2007 jsg

Clear error before starting m_defrag() equivalent.


# 1.30 16-Sep-2007 jsg

Move some noisy debug printfs to higher levels.


# 1.29 16-Sep-2007 jsg

CardBus works much better when sc_enable is called.
Remove some safety returns while here.

ok mglocker@


# 1.28 16-Sep-2007 mglocker

Free ucode if an error happens while FW / IV load. Always return a proper
code in case of error.


# 1.27 16-Sep-2007 jsg

Convert most of the remaining non firmware handling code.


# 1.26 16-Sep-2007 jsg

Remove most of the __unused due to to code being enabled.


# 1.25 15-Sep-2007 mglocker

Adapt firmware images prefix to driver name. Needs bump to firmware
package version 1.1.


# 1.24 15-Sep-2007 mglocker

Get IV load working. Simplified IV loading routine (mainly a rewrite).
Adapted IV loading routines so we can use it with our one file firmware.


# 1.23 15-Sep-2007 jsg

Give hardware physical addresses and add some missing
bus_dmamap_create() calls.


# 1.22 15-Sep-2007 jsg

most of the remaining bus_dma conversion


# 1.21 15-Sep-2007 jsg

Convert bus_dmamap_sync() calls.


# 1.20 15-Sep-2007 jsg

Convert bus_dma_load_mbuf() calls and remove unrequired callback
code previously used.


# 1.19 15-Sep-2007 brad

suitible -> suitable

ok mglocker@ dlg@


# 1.18 15-Sep-2007 jsg

convert bus_dmamap_unload() calls
remove bus_dma_tag_destroy() calls as we don't use/require them.


# 1.17 15-Sep-2007 jsg

convert bus_dmamap_load() calls


# 1.16 15-Sep-2007 jsg

Properly fill in some of the pci information the driver uses internally.


# 1.15 15-Sep-2007 jsg

define BWI_DEBUG to make things easier


# 1.14 14-Sep-2007 mglocker

Get firmware load working. Adapt firmware routines that way so we can
use our one file firmware.


# 1.13 14-Sep-2007 mglocker

Use our standard ratesets from ieee80211 instead.


# 1.12 14-Sep-2007 mglocker

Sort prototypes.


# 1.11 14-Sep-2007 mglocker

Another cleanup run.


# 1.10 13-Sep-2007 mglocker

Move all debug lines to DPRINTF. KNF. Fix some tweaks while there.


# 1.9 13-Sep-2007 mglocker

Add if_detach(). Fixes kernel crash when detaching cardbus device.


# 1.8 13-Sep-2007 mglocker

Ops, remove temporary debug line.


# 1.7 13-Sep-2007 mglocker

Forgot to set psc->psc_pcitag. Replace all PCI/Cardbus config space
functions with our new one. Attachment seems to work now mainly.


# 1.6 13-Sep-2007 mglocker

Enable access to PCI and Cardbus config space from the driver. Lets us
power on the device.


# 1.5 12-Sep-2007 mglocker

Spacing run.


# 1.4 12-Sep-2007 mglocker

For now just return directly from the interrupt handler, or my amd64 will
crash badly.


# 1.3 12-Sep-2007 jsg

Tweak bwi_attach() a little.


# 1.2 12-Sep-2007 jsg

destatic/deinline


# 1.1 12-Sep-2007 jsg

Initial port of Sepherosa Ziehau's DragonFlyBSD driver
for Broadcom AirForce wireless devices.

Not yet functional, things like DMA and firmware handling
haven't been converted yet.

ok mglocker@


# 1.131 16-May-2021 deraadt

panic does not require a \n at the end. When one is provided, it looks wrong.


Revision tags: OPENBSD_6_8_BASE OPENBSD_6_9_BASE
# 1.130 10-Jul-2020 patrick

Change users of IFQ_SET_MAXLEN() and IFQ_IS_EMPTY() to use the "new" API.

ok dlg@ tobhe@


# 1.129 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_6_BASE OPENBSD_6_7_BASE
# 1.128 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.127 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.126 08-Sep-2017 deraadt

If you use sys/param.h, you don't need sys/types.h


# 1.125 03-Jul-2017 kevlo

Replace slot time durations with macros.

ok stsp@


Revision tags: OPENBSD_6_1_BASE
# 1.124 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@


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

G/C IFQ_SET_READY().


Revision tags: OPENBSD_5_9_BASE
# 1.122 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.121 12-Nov-2015 dlg

two newlines in the middle of a func doenst look right.


# 1.120 11-Nov-2015 mpi

Kill useless IFQ_POLL().

ok dlg@


# 1.119 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.118 25-Oct-2015 mpi

arp_ifinit() is no longer needed.


# 1.117 29-Aug-2015 deraadt

firmware sizes are known; use them for free()


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.116 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.115 10-Jan-2015 stsp

Remove pointless empty 64bit support code stubs from bwi(4).
It seems no 64bit bus space support is forthcoming. Nothing
has happened in DragonflyBSD for several years and FreeBSD
has a different driver for 64bit chips called bwn(4).
ok mpi@ some time ago


# 1.114 10-Jan-2015 stsp

Merge two bwi(4) fixes from FreeBSD:


# 1.113 22-Dec-2014 tedu

unifdef INET


# 1.112 19-Dec-2014 guenther

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

ok dlg@ mpi@ bcook@ millert@ miod@


# 1.111 16-Dec-2014 miod

Protect memory allocation and disposal with splvm(); gets rid of splassert
complaints during boot on i386.
ok stsp@


# 1.110 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


# 1.109 06-Sep-2014 jsg

reduce the amount of pci includes


Revision tags: OPENBSD_5_6_BASE
# 1.108 03-Aug-2014 jsg

When stsp changed bwi_encap() for 30 bit addresses in rev 1.106 code
that used to always initialise the error variable is no longer run.

And at the end of bwi_encap() there is:

if (error)
m_freem(m);
return (error);

Fixing this prevents packet loss stsp was seeing.

ok stsp@ miod@ deraadt@


# 1.107 22-Jul-2014 mpi

Fewer <netinet/in_systm.h>


# 1.106 20-Jul-2014 stsp

Always allocate bwi(4) ring descriptors below the 1GB boundary to give 30bit
devices a chance to work. Use bounce buffers for mbufs on 30bit devices.

This fixes "intr fatal TX/RX" errors that render the internal wifi on many
macppc machines unusable. However, packet loss problems remain. In my testing
the device works fine sometimes, but experiences packet loss rates of up
to 80% at other times. Still, this is a step forward.

Helpful hints from claudio@ and dlg@
Tested on macppc by mpi@ and myself
"go ahead" kettenis@, ok mpi@


# 1.105 20-Jul-2014 stsp

In bwi(4), don't declare an interrupt as unhandled in case the PHY TX error
bit is set. This interrupt condition is handled by resetting the device.
ok mpi@ as part of a larger diff


# 1.104 20-Jul-2014 stsp

Make bwi_dma_mbuf_create() use the correct loop counter in error case.
Bug inherited from DragonFly BSD.
ok mpi@ as part of a larger diff.


# 1.103 20-Jul-2014 stsp

Load bwi(4) firmware once, not every time the interface is brought up.
Fixes a panic if the interrupt handler decides to reset the device.
Firmware cannot be loaded in interrupt context.
ok mpi@ as part of a larger diff


# 1.102 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.101 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.100 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.99 14-Nov-2013 dlg

replace workqs with tasks for handling resume

from kimberley manning


# 1.98 01-Oct-2013 sf

Use %z* for size_t

while there, fix a few %d into %u


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.97 31-Dec-2012 miod

Spell `calculation' correctly.


# 1.96 05-Dec-2012 deraadt

Remove excessive sys/cdefs.h inclusion
ok guenther millert kettenis


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.95 27-Aug-2010 jsg

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


Revision tags: OPENBSD_4_8_BASE
# 1.94 07-Aug-2010 krw

No "\n" needed at the end of panic() strings.

Bogus chunks pointed out by matthew@ and miod@. No cookies for
marco@ and jasper@.

ok deraadt@ miod@ matthew@ jasper@ macro@


# 1.93 06-Aug-2010 mglocker

ACPI suspend/resume for bwi(4). Initial diff from todd@, finished and
tested by me on X40 with a BCM4306.

OK deraadt@


# 1.92 19-May-2010 oga

BUS_DMA_ZERO instead of alloc, map, bzero.

ok krw@


Revision tags: OPENBSD_4_7_BASE
# 1.91 13-Sep-2009 krw

M_DUP_PKTHDR() define -> m_dup_pkthdr() function to properly deal
with m_tag_copy_chain() failures.

Use m_defrag() to eliminate hand rolled defragging of mbufs and
some uses of M_DUP_PKTHDR().

Original diff from thib@, claudio@'s feedback integrated by me.

Tests kevlo@ claudio@, "reads ok" blambert@

ok thib@ claudio@, "m_defrag() bits ok" kettenis@


# 1.90 02-Aug-2009 blambert

timeout_add -> timeout_add_msec

ok mglocker@ jsg@


# 1.89 25-Jul-2009 krw

Fix crash in bwi on armish by properly aligning a 32-bit value. Not
to say it works great yet. Might fix bwi on any other alignment
sensitive archs we have.

My original hack generalized and made sane by jsg@. Didn't affect
operation on my macppc. Problem first noted by ian@ a long time
ago.

ok jsg@ (whose tree is currently unavailable to commit from)


# 1.88 19-Jul-2009 jsg

Include 0x4402 in the bbp id mapping table used on older
devices.
http://bcm-specs.sipsolutions.net/BackPlane agrees.


Revision tags: OPENBSD_4_6_BASE
# 1.87 02-Jun-2009 deraadt

change a sizeof() to nitems() because the array subtype is a short.
change all the N() macros to our favorite new macro nitems()
found by Parfait
ok oga guenther


# 1.86 24-May-2009 jsg

declare a variable at the start of bwi_dma_free() instead
of several times throughout the function, in and outside
of a loop.


Revision tags: OPENBSD_4_5_BASE
# 1.85 21-Jan-2009 grange

Replace timeout_add(msecs * hz / 1000) with timeout_add_msec(msecs).
No functional changes.

ok krw@ miod@


# 1.84 07-Jan-2009 jsg

declare bwi_modtype enum before it is used in function prototypes.


# 1.83 26-Nov-2008 dlg

dont have bpf.h expose the kernel ticks variable wherever it is includeing.

it is very confusing like this.

ok deraadt@ canacar@


# 1.82 15-Oct-2008 blambert

Second pass of simple timeout_add -> timeout_add_sec conversions
This should take care of the simpler ones (i.e., timeout values of
integer multiples of hz).

ok krw@, art@


# 1.81 27-Aug-2008 damien

another IEEE80211_RADIOTAP_F_FCS candidate.


# 1.80 27-Aug-2008 damien

override net80211's ic_node_alloc function to allocate a full
bwi_node structure (containing the rate control state).
because bwi(4) does not support HostAP or IBSS modes there is
no need to maintain a per-node rate control state, so we could
as well store it in bwi_softc but that will allow for future
improvements.

pointed out by Taylor R Campbell (campbell AT mumble DOT net)
on tech@


# 1.79 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.78 22-Aug-2008 deraadt

a ; in a bad place; dragonfly; ok mglocker


Revision tags: OPENBSD_4_4_BASE
# 1.77 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.76 11-Jun-2008 jsg

Don't get the address of the txstats pointers when doing bzero,
just use the actual pointers.

Debugged into the early hours of the morning with todd, without
being able to use a keyboard with ddb. Fixes a panic seen on his
powerbook.


# 1.75 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.74 25-Feb-2008 mglocker

Make bwi compile in debug mode again.


# 1.73 25-Feb-2008 mglocker

Sync up with DragonFlyBSD driver. Please read their commit message
for details:

http://leaf.dragonflybsd.org/mailarchive/commits/2008-02/msg00165.html

Tested and OK brad@, kettenis@


# 1.72 16-Feb-2008 mglocker

Zap KKASSERT porting macro and use KASSERT instead.


# 1.71 16-Feb-2008 mglocker

Count output packets.


# 1.70 16-Feb-2008 mglocker

Replace bwi_rate2plcp() with ieee80211_rate2plcp().


# 1.69 16-Feb-2008 mglocker

Fix spacing / comments.


# 1.68 16-Feb-2008 mglocker

While importing the driver a lot of printf's have been converted to
DPRINTF's by mistake. Fix this so we can see fatal errors without beeing
in DEBUG mode.


# 1.67 16-Feb-2008 mglocker

Report rssi and rate in rx radio tap.

From the DragonFlyBSD driver.


# 1.66 16-Feb-2008 mglocker

Better support for 11b mode.

From the DragonFlyBSD driver.


# 1.65 16-Feb-2008 mglocker

Remove some double prototype definitions.


# 1.64 16-Feb-2008 mglocker

Always print device name in front of debug messages.


# 1.63 17-Nov-2007 mglocker

- Add more LED support, like activity blinking (though just supporting
some devices yet).
- Calculate RX rate which can be used later in bpf_mtap().

Diff ported from DragonFlyBSD, tested by some.


# 1.62 18-Oct-2007 mglocker

Add some first LEDs support. Tested on my cardbus Linksys WPC54G Ver 3.

Diff ported from DragonFlyBSD


# 1.61 04-Oct-2007 mglocker

Since we know the firmware load works, merge the single firmware files
together to one single, finally.

You need to bump the firmware package to version 1.3!

OK jsg@


# 1.60 01-Oct-2007 mglocker

Spacing.


# 1.59 01-Oct-2007 mglocker

Fix `bogus xmit rate setup' panic, which mostly happened while associating
to an 11b AP due to not correct initialized tx rates.


# 1.58 01-Oct-2007 jsg

remove rate_fb variable as it always gets set to the same value
as rate anyway.


# 1.57 01-Oct-2007 jsg

Print the MAC address.


# 1.56 01-Oct-2007 jsg

Disable default debug setting, make tx power map printing debug only.


# 1.55 01-Oct-2007 mglocker

Use uint_* consistent.

Agreed with jsg@


# 1.54 30-Sep-2007 mglocker

Spacing.


# 1.53 30-Sep-2007 mglocker

Don't count interrupts with state "not of interest".

From Oleg Safiullin. OK jsg@


# 1.52 30-Sep-2007 kettenis

BWI_BBP_ATTEN is a 16-bit register, so use CSR_WRITE_2 to access it.
Fixes unaligned access on strict-alignment architectures.

ok mglocker@


# 1.51 29-Sep-2007 mglocker

Fix two panic's on macppc. Allows me first network communication over
my PowerBook G4 internal BCM4306 device.


# 1.50 27-Sep-2007 mglocker

Spacing.


# 1.49 27-Sep-2007 mglocker

Add automatic rate control (AMRR).


# 1.48 27-Sep-2007 mglocker

Spacing.


# 1.47 27-Sep-2007 mglocker

Kill __BIT* macros.

Help and OK jsg@


# 1.46 24-Sep-2007 mglocker

Add radio tap support. We still need to calculate correct RX rate and
RX signal strength.


# 1.45 23-Sep-2007 mglocker

Fix page fault kernel crash when changing media and device is up.


# 1.44 23-Sep-2007 mglocker

Add missing device name printf arguments for firmware load error output.


# 1.43 23-Sep-2007 mglocker

More debug ouput cleanup.


# 1.42 23-Sep-2007 mglocker

Correctly clear PCI_STATUS_TARGET_TARGET_ABORT bit.


# 1.41 23-Sep-2007 jsg

Properly handle the physical address in bwi_encap() as well.
With this change I can now scan, associate and ssh via bwi(4)


# 1.40 23-Sep-2007 jsg

Make sure to set physical address in bwi_newbuf()


# 1.39 18-Sep-2007 mglocker

Drag back the original DragonFlyBSD firmware loading routines, so we can
load the same firmware revision as they do. Our previously used firmware
images seem to contain the wrong revision. You need to bump your firmware
package to version 1.2.

Other than expected, loading the right firmware revision still doesn't fix
a fatal chip error at initialization time.


# 1.38 17-Sep-2007 mglocker

If device is down, don't handle any interrupts. Even don't read the
interrupt status register instead return directly. This fixes the machine
freeze on amd64 and let me receive proper interrupts if device is up.
This bit was originaly in the DragonFly code, and must have sneaked out
while porting ...


# 1.37 17-Sep-2007 mglocker

Several DPRINTF arguments was missing, which can lead to ugly kernel
crashes. Fix them.


# 1.36 17-Sep-2007 mglocker

In case of IV load failure free ucode.


# 1.35 16-Sep-2007 mglocker

Remove more obsolete firmware specific bits.


# 1.34 16-Sep-2007 mglocker

Remove obsolete firmware specific bits.


# 1.33 16-Sep-2007 jsg

Better version of fake KKASSERT until they are changed properly.


# 1.32 16-Sep-2007 mglocker

Do sc_disable when device gets stopped.

OK jsg@


# 1.31 16-Sep-2007 jsg

Clear error before starting m_defrag() equivalent.


# 1.30 16-Sep-2007 jsg

Move some noisy debug printfs to higher levels.


# 1.29 16-Sep-2007 jsg

CardBus works much better when sc_enable is called.
Remove some safety returns while here.

ok mglocker@


# 1.28 16-Sep-2007 mglocker

Free ucode if an error happens while FW / IV load. Always return a proper
code in case of error.


# 1.27 16-Sep-2007 jsg

Convert most of the remaining non firmware handling code.


# 1.26 16-Sep-2007 jsg

Remove most of the __unused due to to code being enabled.


# 1.25 15-Sep-2007 mglocker

Adapt firmware images prefix to driver name. Needs bump to firmware
package version 1.1.


# 1.24 15-Sep-2007 mglocker

Get IV load working. Simplified IV loading routine (mainly a rewrite).
Adapted IV loading routines so we can use it with our one file firmware.


# 1.23 15-Sep-2007 jsg

Give hardware physical addresses and add some missing
bus_dmamap_create() calls.


# 1.22 15-Sep-2007 jsg

most of the remaining bus_dma conversion


# 1.21 15-Sep-2007 jsg

Convert bus_dmamap_sync() calls.


# 1.20 15-Sep-2007 jsg

Convert bus_dma_load_mbuf() calls and remove unrequired callback
code previously used.


# 1.19 15-Sep-2007 brad

suitible -> suitable

ok mglocker@ dlg@


# 1.18 15-Sep-2007 jsg

convert bus_dmamap_unload() calls
remove bus_dma_tag_destroy() calls as we don't use/require them.


# 1.17 15-Sep-2007 jsg

convert bus_dmamap_load() calls


# 1.16 15-Sep-2007 jsg

Properly fill in some of the pci information the driver uses internally.


# 1.15 15-Sep-2007 jsg

define BWI_DEBUG to make things easier


# 1.14 14-Sep-2007 mglocker

Get firmware load working. Adapt firmware routines that way so we can
use our one file firmware.


# 1.13 14-Sep-2007 mglocker

Use our standard ratesets from ieee80211 instead.


# 1.12 14-Sep-2007 mglocker

Sort prototypes.


# 1.11 14-Sep-2007 mglocker

Another cleanup run.


# 1.10 13-Sep-2007 mglocker

Move all debug lines to DPRINTF. KNF. Fix some tweaks while there.


# 1.9 13-Sep-2007 mglocker

Add if_detach(). Fixes kernel crash when detaching cardbus device.


# 1.8 13-Sep-2007 mglocker

Ops, remove temporary debug line.


# 1.7 13-Sep-2007 mglocker

Forgot to set psc->psc_pcitag. Replace all PCI/Cardbus config space
functions with our new one. Attachment seems to work now mainly.


# 1.6 13-Sep-2007 mglocker

Enable access to PCI and Cardbus config space from the driver. Lets us
power on the device.


# 1.5 12-Sep-2007 mglocker

Spacing run.


# 1.4 12-Sep-2007 mglocker

For now just return directly from the interrupt handler, or my amd64 will
crash badly.


# 1.3 12-Sep-2007 jsg

Tweak bwi_attach() a little.


# 1.2 12-Sep-2007 jsg

destatic/deinline


# 1.1 12-Sep-2007 jsg

Initial port of Sepherosa Ziehau's DragonFlyBSD driver
for Broadcom AirForce wireless devices.

Not yet functional, things like DMA and firmware handling
haven't been converted yet.

ok mglocker@


# 1.130 10-Jul-2020 patrick

Change users of IFQ_SET_MAXLEN() and IFQ_IS_EMPTY() to use the "new" API.

ok dlg@ tobhe@


# 1.129 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_6_BASE OPENBSD_6_7_BASE
# 1.128 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.127 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.126 08-Sep-2017 deraadt

If you use sys/param.h, you don't need sys/types.h


# 1.125 03-Jul-2017 kevlo

Replace slot time durations with macros.

ok stsp@


Revision tags: OPENBSD_6_1_BASE
# 1.124 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@


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

G/C IFQ_SET_READY().


Revision tags: OPENBSD_5_9_BASE
# 1.122 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.121 12-Nov-2015 dlg

two newlines in the middle of a func doenst look right.


# 1.120 11-Nov-2015 mpi

Kill useless IFQ_POLL().

ok dlg@


# 1.119 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.118 25-Oct-2015 mpi

arp_ifinit() is no longer needed.


# 1.117 29-Aug-2015 deraadt

firmware sizes are known; use them for free()


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.116 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.115 10-Jan-2015 stsp

Remove pointless empty 64bit support code stubs from bwi(4).
It seems no 64bit bus space support is forthcoming. Nothing
has happened in DragonflyBSD for several years and FreeBSD
has a different driver for 64bit chips called bwn(4).
ok mpi@ some time ago


# 1.114 10-Jan-2015 stsp

Merge two bwi(4) fixes from FreeBSD:


# 1.113 22-Dec-2014 tedu

unifdef INET


# 1.112 19-Dec-2014 guenther

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

ok dlg@ mpi@ bcook@ millert@ miod@


# 1.111 16-Dec-2014 miod

Protect memory allocation and disposal with splvm(); gets rid of splassert
complaints during boot on i386.
ok stsp@


# 1.110 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


# 1.109 06-Sep-2014 jsg

reduce the amount of pci includes


Revision tags: OPENBSD_5_6_BASE
# 1.108 03-Aug-2014 jsg

When stsp changed bwi_encap() for 30 bit addresses in rev 1.106 code
that used to always initialise the error variable is no longer run.

And at the end of bwi_encap() there is:

if (error)
m_freem(m);
return (error);

Fixing this prevents packet loss stsp was seeing.

ok stsp@ miod@ deraadt@


# 1.107 22-Jul-2014 mpi

Fewer <netinet/in_systm.h>


# 1.106 20-Jul-2014 stsp

Always allocate bwi(4) ring descriptors below the 1GB boundary to give 30bit
devices a chance to work. Use bounce buffers for mbufs on 30bit devices.

This fixes "intr fatal TX/RX" errors that render the internal wifi on many
macppc machines unusable. However, packet loss problems remain. In my testing
the device works fine sometimes, but experiences packet loss rates of up
to 80% at other times. Still, this is a step forward.

Helpful hints from claudio@ and dlg@
Tested on macppc by mpi@ and myself
"go ahead" kettenis@, ok mpi@


# 1.105 20-Jul-2014 stsp

In bwi(4), don't declare an interrupt as unhandled in case the PHY TX error
bit is set. This interrupt condition is handled by resetting the device.
ok mpi@ as part of a larger diff


# 1.104 20-Jul-2014 stsp

Make bwi_dma_mbuf_create() use the correct loop counter in error case.
Bug inherited from DragonFly BSD.
ok mpi@ as part of a larger diff.


# 1.103 20-Jul-2014 stsp

Load bwi(4) firmware once, not every time the interface is brought up.
Fixes a panic if the interrupt handler decides to reset the device.
Firmware cannot be loaded in interrupt context.
ok mpi@ as part of a larger diff


# 1.102 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.101 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.100 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.99 14-Nov-2013 dlg

replace workqs with tasks for handling resume

from kimberley manning


# 1.98 01-Oct-2013 sf

Use %z* for size_t

while there, fix a few %d into %u


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.97 31-Dec-2012 miod

Spell `calculation' correctly.


# 1.96 05-Dec-2012 deraadt

Remove excessive sys/cdefs.h inclusion
ok guenther millert kettenis


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.95 27-Aug-2010 jsg

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


Revision tags: OPENBSD_4_8_BASE
# 1.94 07-Aug-2010 krw

No "\n" needed at the end of panic() strings.

Bogus chunks pointed out by matthew@ and miod@. No cookies for
marco@ and jasper@.

ok deraadt@ miod@ matthew@ jasper@ macro@


# 1.93 06-Aug-2010 mglocker

ACPI suspend/resume for bwi(4). Initial diff from todd@, finished and
tested by me on X40 with a BCM4306.

OK deraadt@


# 1.92 19-May-2010 oga

BUS_DMA_ZERO instead of alloc, map, bzero.

ok krw@


Revision tags: OPENBSD_4_7_BASE
# 1.91 13-Sep-2009 krw

M_DUP_PKTHDR() define -> m_dup_pkthdr() function to properly deal
with m_tag_copy_chain() failures.

Use m_defrag() to eliminate hand rolled defragging of mbufs and
some uses of M_DUP_PKTHDR().

Original diff from thib@, claudio@'s feedback integrated by me.

Tests kevlo@ claudio@, "reads ok" blambert@

ok thib@ claudio@, "m_defrag() bits ok" kettenis@


# 1.90 02-Aug-2009 blambert

timeout_add -> timeout_add_msec

ok mglocker@ jsg@


# 1.89 25-Jul-2009 krw

Fix crash in bwi on armish by properly aligning a 32-bit value. Not
to say it works great yet. Might fix bwi on any other alignment
sensitive archs we have.

My original hack generalized and made sane by jsg@. Didn't affect
operation on my macppc. Problem first noted by ian@ a long time
ago.

ok jsg@ (whose tree is currently unavailable to commit from)


# 1.88 19-Jul-2009 jsg

Include 0x4402 in the bbp id mapping table used on older
devices.
http://bcm-specs.sipsolutions.net/BackPlane agrees.


Revision tags: OPENBSD_4_6_BASE
# 1.87 02-Jun-2009 deraadt

change a sizeof() to nitems() because the array subtype is a short.
change all the N() macros to our favorite new macro nitems()
found by Parfait
ok oga guenther


# 1.86 24-May-2009 jsg

declare a variable at the start of bwi_dma_free() instead
of several times throughout the function, in and outside
of a loop.


Revision tags: OPENBSD_4_5_BASE
# 1.85 21-Jan-2009 grange

Replace timeout_add(msecs * hz / 1000) with timeout_add_msec(msecs).
No functional changes.

ok krw@ miod@


# 1.84 07-Jan-2009 jsg

declare bwi_modtype enum before it is used in function prototypes.


# 1.83 26-Nov-2008 dlg

dont have bpf.h expose the kernel ticks variable wherever it is includeing.

it is very confusing like this.

ok deraadt@ canacar@


# 1.82 15-Oct-2008 blambert

Second pass of simple timeout_add -> timeout_add_sec conversions
This should take care of the simpler ones (i.e., timeout values of
integer multiples of hz).

ok krw@, art@


# 1.81 27-Aug-2008 damien

another IEEE80211_RADIOTAP_F_FCS candidate.


# 1.80 27-Aug-2008 damien

override net80211's ic_node_alloc function to allocate a full
bwi_node structure (containing the rate control state).
because bwi(4) does not support HostAP or IBSS modes there is
no need to maintain a per-node rate control state, so we could
as well store it in bwi_softc but that will allow for future
improvements.

pointed out by Taylor R Campbell (campbell AT mumble DOT net)
on tech@


# 1.79 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.78 22-Aug-2008 deraadt

a ; in a bad place; dragonfly; ok mglocker


Revision tags: OPENBSD_4_4_BASE
# 1.77 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.76 11-Jun-2008 jsg

Don't get the address of the txstats pointers when doing bzero,
just use the actual pointers.

Debugged into the early hours of the morning with todd, without
being able to use a keyboard with ddb. Fixes a panic seen on his
powerbook.


# 1.75 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.74 25-Feb-2008 mglocker

Make bwi compile in debug mode again.


# 1.73 25-Feb-2008 mglocker

Sync up with DragonFlyBSD driver. Please read their commit message
for details:

http://leaf.dragonflybsd.org/mailarchive/commits/2008-02/msg00165.html

Tested and OK brad@, kettenis@


# 1.72 16-Feb-2008 mglocker

Zap KKASSERT porting macro and use KASSERT instead.


# 1.71 16-Feb-2008 mglocker

Count output packets.


# 1.70 16-Feb-2008 mglocker

Replace bwi_rate2plcp() with ieee80211_rate2plcp().


# 1.69 16-Feb-2008 mglocker

Fix spacing / comments.


# 1.68 16-Feb-2008 mglocker

While importing the driver a lot of printf's have been converted to
DPRINTF's by mistake. Fix this so we can see fatal errors without beeing
in DEBUG mode.


# 1.67 16-Feb-2008 mglocker

Report rssi and rate in rx radio tap.

From the DragonFlyBSD driver.


# 1.66 16-Feb-2008 mglocker

Better support for 11b mode.

From the DragonFlyBSD driver.


# 1.65 16-Feb-2008 mglocker

Remove some double prototype definitions.


# 1.64 16-Feb-2008 mglocker

Always print device name in front of debug messages.


# 1.63 17-Nov-2007 mglocker

- Add more LED support, like activity blinking (though just supporting
some devices yet).
- Calculate RX rate which can be used later in bpf_mtap().

Diff ported from DragonFlyBSD, tested by some.


# 1.62 18-Oct-2007 mglocker

Add some first LEDs support. Tested on my cardbus Linksys WPC54G Ver 3.

Diff ported from DragonFlyBSD


# 1.61 04-Oct-2007 mglocker

Since we know the firmware load works, merge the single firmware files
together to one single, finally.

You need to bump the firmware package to version 1.3!

OK jsg@


# 1.60 01-Oct-2007 mglocker

Spacing.


# 1.59 01-Oct-2007 mglocker

Fix `bogus xmit rate setup' panic, which mostly happened while associating
to an 11b AP due to not correct initialized tx rates.


# 1.58 01-Oct-2007 jsg

remove rate_fb variable as it always gets set to the same value
as rate anyway.


# 1.57 01-Oct-2007 jsg

Print the MAC address.


# 1.56 01-Oct-2007 jsg

Disable default debug setting, make tx power map printing debug only.


# 1.55 01-Oct-2007 mglocker

Use uint_* consistent.

Agreed with jsg@


# 1.54 30-Sep-2007 mglocker

Spacing.


# 1.53 30-Sep-2007 mglocker

Don't count interrupts with state "not of interest".

From Oleg Safiullin. OK jsg@


# 1.52 30-Sep-2007 kettenis

BWI_BBP_ATTEN is a 16-bit register, so use CSR_WRITE_2 to access it.
Fixes unaligned access on strict-alignment architectures.

ok mglocker@


# 1.51 29-Sep-2007 mglocker

Fix two panic's on macppc. Allows me first network communication over
my PowerBook G4 internal BCM4306 device.


# 1.50 27-Sep-2007 mglocker

Spacing.


# 1.49 27-Sep-2007 mglocker

Add automatic rate control (AMRR).


# 1.48 27-Sep-2007 mglocker

Spacing.


# 1.47 27-Sep-2007 mglocker

Kill __BIT* macros.

Help and OK jsg@


# 1.46 24-Sep-2007 mglocker

Add radio tap support. We still need to calculate correct RX rate and
RX signal strength.


# 1.45 23-Sep-2007 mglocker

Fix page fault kernel crash when changing media and device is up.


# 1.44 23-Sep-2007 mglocker

Add missing device name printf arguments for firmware load error output.


# 1.43 23-Sep-2007 mglocker

More debug ouput cleanup.


# 1.42 23-Sep-2007 mglocker

Correctly clear PCI_STATUS_TARGET_TARGET_ABORT bit.


# 1.41 23-Sep-2007 jsg

Properly handle the physical address in bwi_encap() as well.
With this change I can now scan, associate and ssh via bwi(4)


# 1.40 23-Sep-2007 jsg

Make sure to set physical address in bwi_newbuf()


# 1.39 18-Sep-2007 mglocker

Drag back the original DragonFlyBSD firmware loading routines, so we can
load the same firmware revision as they do. Our previously used firmware
images seem to contain the wrong revision. You need to bump your firmware
package to version 1.2.

Other than expected, loading the right firmware revision still doesn't fix
a fatal chip error at initialization time.


# 1.38 17-Sep-2007 mglocker

If device is down, don't handle any interrupts. Even don't read the
interrupt status register instead return directly. This fixes the machine
freeze on amd64 and let me receive proper interrupts if device is up.
This bit was originaly in the DragonFly code, and must have sneaked out
while porting ...


# 1.37 17-Sep-2007 mglocker

Several DPRINTF arguments was missing, which can lead to ugly kernel
crashes. Fix them.


# 1.36 17-Sep-2007 mglocker

In case of IV load failure free ucode.


# 1.35 16-Sep-2007 mglocker

Remove more obsolete firmware specific bits.


# 1.34 16-Sep-2007 mglocker

Remove obsolete firmware specific bits.


# 1.33 16-Sep-2007 jsg

Better version of fake KKASSERT until they are changed properly.


# 1.32 16-Sep-2007 mglocker

Do sc_disable when device gets stopped.

OK jsg@


# 1.31 16-Sep-2007 jsg

Clear error before starting m_defrag() equivalent.


# 1.30 16-Sep-2007 jsg

Move some noisy debug printfs to higher levels.


# 1.29 16-Sep-2007 jsg

CardBus works much better when sc_enable is called.
Remove some safety returns while here.

ok mglocker@


# 1.28 16-Sep-2007 mglocker

Free ucode if an error happens while FW / IV load. Always return a proper
code in case of error.


# 1.27 16-Sep-2007 jsg

Convert most of the remaining non firmware handling code.


# 1.26 16-Sep-2007 jsg

Remove most of the __unused due to to code being enabled.


# 1.25 15-Sep-2007 mglocker

Adapt firmware images prefix to driver name. Needs bump to firmware
package version 1.1.


# 1.24 15-Sep-2007 mglocker

Get IV load working. Simplified IV loading routine (mainly a rewrite).
Adapted IV loading routines so we can use it with our one file firmware.


# 1.23 15-Sep-2007 jsg

Give hardware physical addresses and add some missing
bus_dmamap_create() calls.


# 1.22 15-Sep-2007 jsg

most of the remaining bus_dma conversion


# 1.21 15-Sep-2007 jsg

Convert bus_dmamap_sync() calls.


# 1.20 15-Sep-2007 jsg

Convert bus_dma_load_mbuf() calls and remove unrequired callback
code previously used.


# 1.19 15-Sep-2007 brad

suitible -> suitable

ok mglocker@ dlg@


# 1.18 15-Sep-2007 jsg

convert bus_dmamap_unload() calls
remove bus_dma_tag_destroy() calls as we don't use/require them.


# 1.17 15-Sep-2007 jsg

convert bus_dmamap_load() calls


# 1.16 15-Sep-2007 jsg

Properly fill in some of the pci information the driver uses internally.


# 1.15 15-Sep-2007 jsg

define BWI_DEBUG to make things easier


# 1.14 14-Sep-2007 mglocker

Get firmware load working. Adapt firmware routines that way so we can
use our one file firmware.


# 1.13 14-Sep-2007 mglocker

Use our standard ratesets from ieee80211 instead.


# 1.12 14-Sep-2007 mglocker

Sort prototypes.


# 1.11 14-Sep-2007 mglocker

Another cleanup run.


# 1.10 13-Sep-2007 mglocker

Move all debug lines to DPRINTF. KNF. Fix some tweaks while there.


# 1.9 13-Sep-2007 mglocker

Add if_detach(). Fixes kernel crash when detaching cardbus device.


# 1.8 13-Sep-2007 mglocker

Ops, remove temporary debug line.


# 1.7 13-Sep-2007 mglocker

Forgot to set psc->psc_pcitag. Replace all PCI/Cardbus config space
functions with our new one. Attachment seems to work now mainly.


# 1.6 13-Sep-2007 mglocker

Enable access to PCI and Cardbus config space from the driver. Lets us
power on the device.


# 1.5 12-Sep-2007 mglocker

Spacing run.


# 1.4 12-Sep-2007 mglocker

For now just return directly from the interrupt handler, or my amd64 will
crash badly.


# 1.3 12-Sep-2007 jsg

Tweak bwi_attach() a little.


# 1.2 12-Sep-2007 jsg

destatic/deinline


# 1.1 12-Sep-2007 jsg

Initial port of Sepherosa Ziehau's DragonFlyBSD driver
for Broadcom AirForce wireless devices.

Not yet functional, things like DMA and firmware handling
haven't been converted yet.

ok mglocker@


# 1.128 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.127 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.126 08-Sep-2017 deraadt

If you use sys/param.h, you don't need sys/types.h


# 1.125 03-Jul-2017 kevlo

Replace slot time durations with macros.

ok stsp@


Revision tags: OPENBSD_6_1_BASE
# 1.124 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@


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

G/C IFQ_SET_READY().


Revision tags: OPENBSD_5_9_BASE
# 1.122 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.121 12-Nov-2015 dlg

two newlines in the middle of a func doenst look right.


# 1.120 11-Nov-2015 mpi

Kill useless IFQ_POLL().

ok dlg@


# 1.119 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.118 25-Oct-2015 mpi

arp_ifinit() is no longer needed.


# 1.117 29-Aug-2015 deraadt

firmware sizes are known; use them for free()


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.116 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.115 10-Jan-2015 stsp

Remove pointless empty 64bit support code stubs from bwi(4).
It seems no 64bit bus space support is forthcoming. Nothing
has happened in DragonflyBSD for several years and FreeBSD
has a different driver for 64bit chips called bwn(4).
ok mpi@ some time ago


# 1.114 10-Jan-2015 stsp

Merge two bwi(4) fixes from FreeBSD:


# 1.113 22-Dec-2014 tedu

unifdef INET


# 1.112 19-Dec-2014 guenther

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

ok dlg@ mpi@ bcook@ millert@ miod@


# 1.111 16-Dec-2014 miod

Protect memory allocation and disposal with splvm(); gets rid of splassert
complaints during boot on i386.
ok stsp@


# 1.110 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


# 1.109 06-Sep-2014 jsg

reduce the amount of pci includes


Revision tags: OPENBSD_5_6_BASE
# 1.108 03-Aug-2014 jsg

When stsp changed bwi_encap() for 30 bit addresses in rev 1.106 code
that used to always initialise the error variable is no longer run.

And at the end of bwi_encap() there is:

if (error)
m_freem(m);
return (error);

Fixing this prevents packet loss stsp was seeing.

ok stsp@ miod@ deraadt@


# 1.107 22-Jul-2014 mpi

Fewer <netinet/in_systm.h>


# 1.106 20-Jul-2014 stsp

Always allocate bwi(4) ring descriptors below the 1GB boundary to give 30bit
devices a chance to work. Use bounce buffers for mbufs on 30bit devices.

This fixes "intr fatal TX/RX" errors that render the internal wifi on many
macppc machines unusable. However, packet loss problems remain. In my testing
the device works fine sometimes, but experiences packet loss rates of up
to 80% at other times. Still, this is a step forward.

Helpful hints from claudio@ and dlg@
Tested on macppc by mpi@ and myself
"go ahead" kettenis@, ok mpi@


# 1.105 20-Jul-2014 stsp

In bwi(4), don't declare an interrupt as unhandled in case the PHY TX error
bit is set. This interrupt condition is handled by resetting the device.
ok mpi@ as part of a larger diff


# 1.104 20-Jul-2014 stsp

Make bwi_dma_mbuf_create() use the correct loop counter in error case.
Bug inherited from DragonFly BSD.
ok mpi@ as part of a larger diff.


# 1.103 20-Jul-2014 stsp

Load bwi(4) firmware once, not every time the interface is brought up.
Fixes a panic if the interrupt handler decides to reset the device.
Firmware cannot be loaded in interrupt context.
ok mpi@ as part of a larger diff


# 1.102 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.101 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.100 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.99 14-Nov-2013 dlg

replace workqs with tasks for handling resume

from kimberley manning


# 1.98 01-Oct-2013 sf

Use %z* for size_t

while there, fix a few %d into %u


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.97 31-Dec-2012 miod

Spell `calculation' correctly.


# 1.96 05-Dec-2012 deraadt

Remove excessive sys/cdefs.h inclusion
ok guenther millert kettenis


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.95 27-Aug-2010 jsg

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


Revision tags: OPENBSD_4_8_BASE
# 1.94 07-Aug-2010 krw

No "\n" needed at the end of panic() strings.

Bogus chunks pointed out by matthew@ and miod@. No cookies for
marco@ and jasper@.

ok deraadt@ miod@ matthew@ jasper@ macro@


# 1.93 06-Aug-2010 mglocker

ACPI suspend/resume for bwi(4). Initial diff from todd@, finished and
tested by me on X40 with a BCM4306.

OK deraadt@


# 1.92 19-May-2010 oga

BUS_DMA_ZERO instead of alloc, map, bzero.

ok krw@


Revision tags: OPENBSD_4_7_BASE
# 1.91 13-Sep-2009 krw

M_DUP_PKTHDR() define -> m_dup_pkthdr() function to properly deal
with m_tag_copy_chain() failures.

Use m_defrag() to eliminate hand rolled defragging of mbufs and
some uses of M_DUP_PKTHDR().

Original diff from thib@, claudio@'s feedback integrated by me.

Tests kevlo@ claudio@, "reads ok" blambert@

ok thib@ claudio@, "m_defrag() bits ok" kettenis@


# 1.90 02-Aug-2009 blambert

timeout_add -> timeout_add_msec

ok mglocker@ jsg@


# 1.89 25-Jul-2009 krw

Fix crash in bwi on armish by properly aligning a 32-bit value. Not
to say it works great yet. Might fix bwi on any other alignment
sensitive archs we have.

My original hack generalized and made sane by jsg@. Didn't affect
operation on my macppc. Problem first noted by ian@ a long time
ago.

ok jsg@ (whose tree is currently unavailable to commit from)


# 1.88 19-Jul-2009 jsg

Include 0x4402 in the bbp id mapping table used on older
devices.
http://bcm-specs.sipsolutions.net/BackPlane agrees.


Revision tags: OPENBSD_4_6_BASE
# 1.87 02-Jun-2009 deraadt

change a sizeof() to nitems() because the array subtype is a short.
change all the N() macros to our favorite new macro nitems()
found by Parfait
ok oga guenther


# 1.86 24-May-2009 jsg

declare a variable at the start of bwi_dma_free() instead
of several times throughout the function, in and outside
of a loop.


Revision tags: OPENBSD_4_5_BASE
# 1.85 21-Jan-2009 grange

Replace timeout_add(msecs * hz / 1000) with timeout_add_msec(msecs).
No functional changes.

ok krw@ miod@


# 1.84 07-Jan-2009 jsg

declare bwi_modtype enum before it is used in function prototypes.


# 1.83 26-Nov-2008 dlg

dont have bpf.h expose the kernel ticks variable wherever it is includeing.

it is very confusing like this.

ok deraadt@ canacar@


# 1.82 15-Oct-2008 blambert

Second pass of simple timeout_add -> timeout_add_sec conversions
This should take care of the simpler ones (i.e., timeout values of
integer multiples of hz).

ok krw@, art@


# 1.81 27-Aug-2008 damien

another IEEE80211_RADIOTAP_F_FCS candidate.


# 1.80 27-Aug-2008 damien

override net80211's ic_node_alloc function to allocate a full
bwi_node structure (containing the rate control state).
because bwi(4) does not support HostAP or IBSS modes there is
no need to maintain a per-node rate control state, so we could
as well store it in bwi_softc but that will allow for future
improvements.

pointed out by Taylor R Campbell (campbell AT mumble DOT net)
on tech@


# 1.79 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.78 22-Aug-2008 deraadt

a ; in a bad place; dragonfly; ok mglocker


Revision tags: OPENBSD_4_4_BASE
# 1.77 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.76 11-Jun-2008 jsg

Don't get the address of the txstats pointers when doing bzero,
just use the actual pointers.

Debugged into the early hours of the morning with todd, without
being able to use a keyboard with ddb. Fixes a panic seen on his
powerbook.


# 1.75 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.74 25-Feb-2008 mglocker

Make bwi compile in debug mode again.


# 1.73 25-Feb-2008 mglocker

Sync up with DragonFlyBSD driver. Please read their commit message
for details:

http://leaf.dragonflybsd.org/mailarchive/commits/2008-02/msg00165.html

Tested and OK brad@, kettenis@


# 1.72 16-Feb-2008 mglocker

Zap KKASSERT porting macro and use KASSERT instead.


# 1.71 16-Feb-2008 mglocker

Count output packets.


# 1.70 16-Feb-2008 mglocker

Replace bwi_rate2plcp() with ieee80211_rate2plcp().


# 1.69 16-Feb-2008 mglocker

Fix spacing / comments.


# 1.68 16-Feb-2008 mglocker

While importing the driver a lot of printf's have been converted to
DPRINTF's by mistake. Fix this so we can see fatal errors without beeing
in DEBUG mode.


# 1.67 16-Feb-2008 mglocker

Report rssi and rate in rx radio tap.

From the DragonFlyBSD driver.


# 1.66 16-Feb-2008 mglocker

Better support for 11b mode.

From the DragonFlyBSD driver.


# 1.65 16-Feb-2008 mglocker

Remove some double prototype definitions.


# 1.64 16-Feb-2008 mglocker

Always print device name in front of debug messages.


# 1.63 17-Nov-2007 mglocker

- Add more LED support, like activity blinking (though just supporting
some devices yet).
- Calculate RX rate which can be used later in bpf_mtap().

Diff ported from DragonFlyBSD, tested by some.


# 1.62 18-Oct-2007 mglocker

Add some first LEDs support. Tested on my cardbus Linksys WPC54G Ver 3.

Diff ported from DragonFlyBSD


# 1.61 04-Oct-2007 mglocker

Since we know the firmware load works, merge the single firmware files
together to one single, finally.

You need to bump the firmware package to version 1.3!

OK jsg@


# 1.60 01-Oct-2007 mglocker

Spacing.


# 1.59 01-Oct-2007 mglocker

Fix `bogus xmit rate setup' panic, which mostly happened while associating
to an 11b AP due to not correct initialized tx rates.


# 1.58 01-Oct-2007 jsg

remove rate_fb variable as it always gets set to the same value
as rate anyway.


# 1.57 01-Oct-2007 jsg

Print the MAC address.


# 1.56 01-Oct-2007 jsg

Disable default debug setting, make tx power map printing debug only.


# 1.55 01-Oct-2007 mglocker

Use uint_* consistent.

Agreed with jsg@


# 1.54 30-Sep-2007 mglocker

Spacing.


# 1.53 30-Sep-2007 mglocker

Don't count interrupts with state "not of interest".

From Oleg Safiullin. OK jsg@


# 1.52 30-Sep-2007 kettenis

BWI_BBP_ATTEN is a 16-bit register, so use CSR_WRITE_2 to access it.
Fixes unaligned access on strict-alignment architectures.

ok mglocker@


# 1.51 29-Sep-2007 mglocker

Fix two panic's on macppc. Allows me first network communication over
my PowerBook G4 internal BCM4306 device.


# 1.50 27-Sep-2007 mglocker

Spacing.


# 1.49 27-Sep-2007 mglocker

Add automatic rate control (AMRR).


# 1.48 27-Sep-2007 mglocker

Spacing.


# 1.47 27-Sep-2007 mglocker

Kill __BIT* macros.

Help and OK jsg@


# 1.46 24-Sep-2007 mglocker

Add radio tap support. We still need to calculate correct RX rate and
RX signal strength.


# 1.45 23-Sep-2007 mglocker

Fix page fault kernel crash when changing media and device is up.


# 1.44 23-Sep-2007 mglocker

Add missing device name printf arguments for firmware load error output.


# 1.43 23-Sep-2007 mglocker

More debug ouput cleanup.


# 1.42 23-Sep-2007 mglocker

Correctly clear PCI_STATUS_TARGET_TARGET_ABORT bit.


# 1.41 23-Sep-2007 jsg

Properly handle the physical address in bwi_encap() as well.
With this change I can now scan, associate and ssh via bwi(4)


# 1.40 23-Sep-2007 jsg

Make sure to set physical address in bwi_newbuf()


# 1.39 18-Sep-2007 mglocker

Drag back the original DragonFlyBSD firmware loading routines, so we can
load the same firmware revision as they do. Our previously used firmware
images seem to contain the wrong revision. You need to bump your firmware
package to version 1.2.

Other than expected, loading the right firmware revision still doesn't fix
a fatal chip error at initialization time.


# 1.38 17-Sep-2007 mglocker

If device is down, don't handle any interrupts. Even don't read the
interrupt status register instead return directly. This fixes the machine
freeze on amd64 and let me receive proper interrupts if device is up.
This bit was originaly in the DragonFly code, and must have sneaked out
while porting ...


# 1.37 17-Sep-2007 mglocker

Several DPRINTF arguments was missing, which can lead to ugly kernel
crashes. Fix them.


# 1.36 17-Sep-2007 mglocker

In case of IV load failure free ucode.


# 1.35 16-Sep-2007 mglocker

Remove more obsolete firmware specific bits.


# 1.34 16-Sep-2007 mglocker

Remove obsolete firmware specific bits.


# 1.33 16-Sep-2007 jsg

Better version of fake KKASSERT until they are changed properly.


# 1.32 16-Sep-2007 mglocker

Do sc_disable when device gets stopped.

OK jsg@


# 1.31 16-Sep-2007 jsg

Clear error before starting m_defrag() equivalent.


# 1.30 16-Sep-2007 jsg

Move some noisy debug printfs to higher levels.


# 1.29 16-Sep-2007 jsg

CardBus works much better when sc_enable is called.
Remove some safety returns while here.

ok mglocker@


# 1.28 16-Sep-2007 mglocker

Free ucode if an error happens while FW / IV load. Always return a proper
code in case of error.


# 1.27 16-Sep-2007 jsg

Convert most of the remaining non firmware handling code.


# 1.26 16-Sep-2007 jsg

Remove most of the __unused due to to code being enabled.


# 1.25 15-Sep-2007 mglocker

Adapt firmware images prefix to driver name. Needs bump to firmware
package version 1.1.


# 1.24 15-Sep-2007 mglocker

Get IV load working. Simplified IV loading routine (mainly a rewrite).
Adapted IV loading routines so we can use it with our one file firmware.


# 1.23 15-Sep-2007 jsg

Give hardware physical addresses and add some missing
bus_dmamap_create() calls.


# 1.22 15-Sep-2007 jsg

most of the remaining bus_dma conversion


# 1.21 15-Sep-2007 jsg

Convert bus_dmamap_sync() calls.


# 1.20 15-Sep-2007 jsg

Convert bus_dma_load_mbuf() calls and remove unrequired callback
code previously used.


# 1.19 15-Sep-2007 brad

suitible -> suitable

ok mglocker@ dlg@


# 1.18 15-Sep-2007 jsg

convert bus_dmamap_unload() calls
remove bus_dma_tag_destroy() calls as we don't use/require them.


# 1.17 15-Sep-2007 jsg

convert bus_dmamap_load() calls


# 1.16 15-Sep-2007 jsg

Properly fill in some of the pci information the driver uses internally.


# 1.15 15-Sep-2007 jsg

define BWI_DEBUG to make things easier


# 1.14 14-Sep-2007 mglocker

Get firmware load working. Adapt firmware routines that way so we can
use our one file firmware.


# 1.13 14-Sep-2007 mglocker

Use our standard ratesets from ieee80211 instead.


# 1.12 14-Sep-2007 mglocker

Sort prototypes.


# 1.11 14-Sep-2007 mglocker

Another cleanup run.


# 1.10 13-Sep-2007 mglocker

Move all debug lines to DPRINTF. KNF. Fix some tweaks while there.


# 1.9 13-Sep-2007 mglocker

Add if_detach(). Fixes kernel crash when detaching cardbus device.


# 1.8 13-Sep-2007 mglocker

Ops, remove temporary debug line.


# 1.7 13-Sep-2007 mglocker

Forgot to set psc->psc_pcitag. Replace all PCI/Cardbus config space
functions with our new one. Attachment seems to work now mainly.


# 1.6 13-Sep-2007 mglocker

Enable access to PCI and Cardbus config space from the driver. Lets us
power on the device.


# 1.5 12-Sep-2007 mglocker

Spacing run.


# 1.4 12-Sep-2007 mglocker

For now just return directly from the interrupt handler, or my amd64 will
crash badly.


# 1.3 12-Sep-2007 jsg

Tweak bwi_attach() a little.


# 1.2 12-Sep-2007 jsg

destatic/deinline


# 1.1 12-Sep-2007 jsg

Initial port of Sepherosa Ziehau's DragonFlyBSD driver
for Broadcom AirForce wireless devices.

Not yet functional, things like DMA and firmware handling
haven't been converted yet.

ok mglocker@


# 1.127 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.126 08-Sep-2017 deraadt

If you use sys/param.h, you don't need sys/types.h


# 1.125 03-Jul-2017 kevlo

Replace slot time durations with macros.

ok stsp@


Revision tags: OPENBSD_6_1_BASE
# 1.124 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@


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

G/C IFQ_SET_READY().


Revision tags: OPENBSD_5_9_BASE
# 1.122 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.121 12-Nov-2015 dlg

two newlines in the middle of a func doenst look right.


# 1.120 11-Nov-2015 mpi

Kill useless IFQ_POLL().

ok dlg@


# 1.119 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.118 25-Oct-2015 mpi

arp_ifinit() is no longer needed.


# 1.117 29-Aug-2015 deraadt

firmware sizes are known; use them for free()


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.116 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.115 10-Jan-2015 stsp

Remove pointless empty 64bit support code stubs from bwi(4).
It seems no 64bit bus space support is forthcoming. Nothing
has happened in DragonflyBSD for several years and FreeBSD
has a different driver for 64bit chips called bwn(4).
ok mpi@ some time ago


# 1.114 10-Jan-2015 stsp

Merge two bwi(4) fixes from FreeBSD:


# 1.113 22-Dec-2014 tedu

unifdef INET


# 1.112 19-Dec-2014 guenther

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

ok dlg@ mpi@ bcook@ millert@ miod@


# 1.111 16-Dec-2014 miod

Protect memory allocation and disposal with splvm(); gets rid of splassert
complaints during boot on i386.
ok stsp@


# 1.110 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


# 1.109 06-Sep-2014 jsg

reduce the amount of pci includes


Revision tags: OPENBSD_5_6_BASE
# 1.108 03-Aug-2014 jsg

When stsp changed bwi_encap() for 30 bit addresses in rev 1.106 code
that used to always initialise the error variable is no longer run.

And at the end of bwi_encap() there is:

if (error)
m_freem(m);
return (error);

Fixing this prevents packet loss stsp was seeing.

ok stsp@ miod@ deraadt@


# 1.107 22-Jul-2014 mpi

Fewer <netinet/in_systm.h>


# 1.106 20-Jul-2014 stsp

Always allocate bwi(4) ring descriptors below the 1GB boundary to give 30bit
devices a chance to work. Use bounce buffers for mbufs on 30bit devices.

This fixes "intr fatal TX/RX" errors that render the internal wifi on many
macppc machines unusable. However, packet loss problems remain. In my testing
the device works fine sometimes, but experiences packet loss rates of up
to 80% at other times. Still, this is a step forward.

Helpful hints from claudio@ and dlg@
Tested on macppc by mpi@ and myself
"go ahead" kettenis@, ok mpi@


# 1.105 20-Jul-2014 stsp

In bwi(4), don't declare an interrupt as unhandled in case the PHY TX error
bit is set. This interrupt condition is handled by resetting the device.
ok mpi@ as part of a larger diff


# 1.104 20-Jul-2014 stsp

Make bwi_dma_mbuf_create() use the correct loop counter in error case.
Bug inherited from DragonFly BSD.
ok mpi@ as part of a larger diff.


# 1.103 20-Jul-2014 stsp

Load bwi(4) firmware once, not every time the interface is brought up.
Fixes a panic if the interrupt handler decides to reset the device.
Firmware cannot be loaded in interrupt context.
ok mpi@ as part of a larger diff


# 1.102 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.101 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.100 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.99 14-Nov-2013 dlg

replace workqs with tasks for handling resume

from kimberley manning


# 1.98 01-Oct-2013 sf

Use %z* for size_t

while there, fix a few %d into %u


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.97 31-Dec-2012 miod

Spell `calculation' correctly.


# 1.96 05-Dec-2012 deraadt

Remove excessive sys/cdefs.h inclusion
ok guenther millert kettenis


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.95 27-Aug-2010 jsg

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


Revision tags: OPENBSD_4_8_BASE
# 1.94 07-Aug-2010 krw

No "\n" needed at the end of panic() strings.

Bogus chunks pointed out by matthew@ and miod@. No cookies for
marco@ and jasper@.

ok deraadt@ miod@ matthew@ jasper@ macro@


# 1.93 06-Aug-2010 mglocker

ACPI suspend/resume for bwi(4). Initial diff from todd@, finished and
tested by me on X40 with a BCM4306.

OK deraadt@


# 1.92 19-May-2010 oga

BUS_DMA_ZERO instead of alloc, map, bzero.

ok krw@


Revision tags: OPENBSD_4_7_BASE
# 1.91 13-Sep-2009 krw

M_DUP_PKTHDR() define -> m_dup_pkthdr() function to properly deal
with m_tag_copy_chain() failures.

Use m_defrag() to eliminate hand rolled defragging of mbufs and
some uses of M_DUP_PKTHDR().

Original diff from thib@, claudio@'s feedback integrated by me.

Tests kevlo@ claudio@, "reads ok" blambert@

ok thib@ claudio@, "m_defrag() bits ok" kettenis@


# 1.90 02-Aug-2009 blambert

timeout_add -> timeout_add_msec

ok mglocker@ jsg@


# 1.89 25-Jul-2009 krw

Fix crash in bwi on armish by properly aligning a 32-bit value. Not
to say it works great yet. Might fix bwi on any other alignment
sensitive archs we have.

My original hack generalized and made sane by jsg@. Didn't affect
operation on my macppc. Problem first noted by ian@ a long time
ago.

ok jsg@ (whose tree is currently unavailable to commit from)


# 1.88 19-Jul-2009 jsg

Include 0x4402 in the bbp id mapping table used on older
devices.
http://bcm-specs.sipsolutions.net/BackPlane agrees.


Revision tags: OPENBSD_4_6_BASE
# 1.87 02-Jun-2009 deraadt

change a sizeof() to nitems() because the array subtype is a short.
change all the N() macros to our favorite new macro nitems()
found by Parfait
ok oga guenther


# 1.86 24-May-2009 jsg

declare a variable at the start of bwi_dma_free() instead
of several times throughout the function, in and outside
of a loop.


Revision tags: OPENBSD_4_5_BASE
# 1.85 21-Jan-2009 grange

Replace timeout_add(msecs * hz / 1000) with timeout_add_msec(msecs).
No functional changes.

ok krw@ miod@


# 1.84 07-Jan-2009 jsg

declare bwi_modtype enum before it is used in function prototypes.


# 1.83 26-Nov-2008 dlg

dont have bpf.h expose the kernel ticks variable wherever it is includeing.

it is very confusing like this.

ok deraadt@ canacar@


# 1.82 15-Oct-2008 blambert

Second pass of simple timeout_add -> timeout_add_sec conversions
This should take care of the simpler ones (i.e., timeout values of
integer multiples of hz).

ok krw@, art@


# 1.81 27-Aug-2008 damien

another IEEE80211_RADIOTAP_F_FCS candidate.


# 1.80 27-Aug-2008 damien

override net80211's ic_node_alloc function to allocate a full
bwi_node structure (containing the rate control state).
because bwi(4) does not support HostAP or IBSS modes there is
no need to maintain a per-node rate control state, so we could
as well store it in bwi_softc but that will allow for future
improvements.

pointed out by Taylor R Campbell (campbell AT mumble DOT net)
on tech@


# 1.79 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.78 22-Aug-2008 deraadt

a ; in a bad place; dragonfly; ok mglocker


Revision tags: OPENBSD_4_4_BASE
# 1.77 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.76 11-Jun-2008 jsg

Don't get the address of the txstats pointers when doing bzero,
just use the actual pointers.

Debugged into the early hours of the morning with todd, without
being able to use a keyboard with ddb. Fixes a panic seen on his
powerbook.


# 1.75 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.74 25-Feb-2008 mglocker

Make bwi compile in debug mode again.


# 1.73 25-Feb-2008 mglocker

Sync up with DragonFlyBSD driver. Please read their commit message
for details:

http://leaf.dragonflybsd.org/mailarchive/commits/2008-02/msg00165.html

Tested and OK brad@, kettenis@


# 1.72 16-Feb-2008 mglocker

Zap KKASSERT porting macro and use KASSERT instead.


# 1.71 16-Feb-2008 mglocker

Count output packets.


# 1.70 16-Feb-2008 mglocker

Replace bwi_rate2plcp() with ieee80211_rate2plcp().


# 1.69 16-Feb-2008 mglocker

Fix spacing / comments.


# 1.68 16-Feb-2008 mglocker

While importing the driver a lot of printf's have been converted to
DPRINTF's by mistake. Fix this so we can see fatal errors without beeing
in DEBUG mode.


# 1.67 16-Feb-2008 mglocker

Report rssi and rate in rx radio tap.

From the DragonFlyBSD driver.


# 1.66 16-Feb-2008 mglocker

Better support for 11b mode.

From the DragonFlyBSD driver.


# 1.65 16-Feb-2008 mglocker

Remove some double prototype definitions.


# 1.64 16-Feb-2008 mglocker

Always print device name in front of debug messages.


# 1.63 17-Nov-2007 mglocker

- Add more LED support, like activity blinking (though just supporting
some devices yet).
- Calculate RX rate which can be used later in bpf_mtap().

Diff ported from DragonFlyBSD, tested by some.


# 1.62 18-Oct-2007 mglocker

Add some first LEDs support. Tested on my cardbus Linksys WPC54G Ver 3.

Diff ported from DragonFlyBSD


# 1.61 04-Oct-2007 mglocker

Since we know the firmware load works, merge the single firmware files
together to one single, finally.

You need to bump the firmware package to version 1.3!

OK jsg@


# 1.60 01-Oct-2007 mglocker

Spacing.


# 1.59 01-Oct-2007 mglocker

Fix `bogus xmit rate setup' panic, which mostly happened while associating
to an 11b AP due to not correct initialized tx rates.


# 1.58 01-Oct-2007 jsg

remove rate_fb variable as it always gets set to the same value
as rate anyway.


# 1.57 01-Oct-2007 jsg

Print the MAC address.


# 1.56 01-Oct-2007 jsg

Disable default debug setting, make tx power map printing debug only.


# 1.55 01-Oct-2007 mglocker

Use uint_* consistent.

Agreed with jsg@


# 1.54 30-Sep-2007 mglocker

Spacing.


# 1.53 30-Sep-2007 mglocker

Don't count interrupts with state "not of interest".

From Oleg Safiullin. OK jsg@


# 1.52 30-Sep-2007 kettenis

BWI_BBP_ATTEN is a 16-bit register, so use CSR_WRITE_2 to access it.
Fixes unaligned access on strict-alignment architectures.

ok mglocker@


# 1.51 29-Sep-2007 mglocker

Fix two panic's on macppc. Allows me first network communication over
my PowerBook G4 internal BCM4306 device.


# 1.50 27-Sep-2007 mglocker

Spacing.


# 1.49 27-Sep-2007 mglocker

Add automatic rate control (AMRR).


# 1.48 27-Sep-2007 mglocker

Spacing.


# 1.47 27-Sep-2007 mglocker

Kill __BIT* macros.

Help and OK jsg@


# 1.46 24-Sep-2007 mglocker

Add radio tap support. We still need to calculate correct RX rate and
RX signal strength.


# 1.45 23-Sep-2007 mglocker

Fix page fault kernel crash when changing media and device is up.


# 1.44 23-Sep-2007 mglocker

Add missing device name printf arguments for firmware load error output.


# 1.43 23-Sep-2007 mglocker

More debug ouput cleanup.


# 1.42 23-Sep-2007 mglocker

Correctly clear PCI_STATUS_TARGET_TARGET_ABORT bit.


# 1.41 23-Sep-2007 jsg

Properly handle the physical address in bwi_encap() as well.
With this change I can now scan, associate and ssh via bwi(4)


# 1.40 23-Sep-2007 jsg

Make sure to set physical address in bwi_newbuf()


# 1.39 18-Sep-2007 mglocker

Drag back the original DragonFlyBSD firmware loading routines, so we can
load the same firmware revision as they do. Our previously used firmware
images seem to contain the wrong revision. You need to bump your firmware
package to version 1.2.

Other than expected, loading the right firmware revision still doesn't fix
a fatal chip error at initialization time.


# 1.38 17-Sep-2007 mglocker

If device is down, don't handle any interrupts. Even don't read the
interrupt status register instead return directly. This fixes the machine
freeze on amd64 and let me receive proper interrupts if device is up.
This bit was originaly in the DragonFly code, and must have sneaked out
while porting ...


# 1.37 17-Sep-2007 mglocker

Several DPRINTF arguments was missing, which can lead to ugly kernel
crashes. Fix them.


# 1.36 17-Sep-2007 mglocker

In case of IV load failure free ucode.


# 1.35 16-Sep-2007 mglocker

Remove more obsolete firmware specific bits.


# 1.34 16-Sep-2007 mglocker

Remove obsolete firmware specific bits.


# 1.33 16-Sep-2007 jsg

Better version of fake KKASSERT until they are changed properly.


# 1.32 16-Sep-2007 mglocker

Do sc_disable when device gets stopped.

OK jsg@


# 1.31 16-Sep-2007 jsg

Clear error before starting m_defrag() equivalent.


# 1.30 16-Sep-2007 jsg

Move some noisy debug printfs to higher levels.


# 1.29 16-Sep-2007 jsg

CardBus works much better when sc_enable is called.
Remove some safety returns while here.

ok mglocker@


# 1.28 16-Sep-2007 mglocker

Free ucode if an error happens while FW / IV load. Always return a proper
code in case of error.


# 1.27 16-Sep-2007 jsg

Convert most of the remaining non firmware handling code.


# 1.26 16-Sep-2007 jsg

Remove most of the __unused due to to code being enabled.


# 1.25 15-Sep-2007 mglocker

Adapt firmware images prefix to driver name. Needs bump to firmware
package version 1.1.


# 1.24 15-Sep-2007 mglocker

Get IV load working. Simplified IV loading routine (mainly a rewrite).
Adapted IV loading routines so we can use it with our one file firmware.


# 1.23 15-Sep-2007 jsg

Give hardware physical addresses and add some missing
bus_dmamap_create() calls.


# 1.22 15-Sep-2007 jsg

most of the remaining bus_dma conversion


# 1.21 15-Sep-2007 jsg

Convert bus_dmamap_sync() calls.


# 1.20 15-Sep-2007 jsg

Convert bus_dma_load_mbuf() calls and remove unrequired callback
code previously used.


# 1.19 15-Sep-2007 brad

suitible -> suitable

ok mglocker@ dlg@


# 1.18 15-Sep-2007 jsg

convert bus_dmamap_unload() calls
remove bus_dma_tag_destroy() calls as we don't use/require them.


# 1.17 15-Sep-2007 jsg

convert bus_dmamap_load() calls


# 1.16 15-Sep-2007 jsg

Properly fill in some of the pci information the driver uses internally.


# 1.15 15-Sep-2007 jsg

define BWI_DEBUG to make things easier


# 1.14 14-Sep-2007 mglocker

Get firmware load working. Adapt firmware routines that way so we can
use our one file firmware.


# 1.13 14-Sep-2007 mglocker

Use our standard ratesets from ieee80211 instead.


# 1.12 14-Sep-2007 mglocker

Sort prototypes.


# 1.11 14-Sep-2007 mglocker

Another cleanup run.


# 1.10 13-Sep-2007 mglocker

Move all debug lines to DPRINTF. KNF. Fix some tweaks while there.


# 1.9 13-Sep-2007 mglocker

Add if_detach(). Fixes kernel crash when detaching cardbus device.


# 1.8 13-Sep-2007 mglocker

Ops, remove temporary debug line.


# 1.7 13-Sep-2007 mglocker

Forgot to set psc->psc_pcitag. Replace all PCI/Cardbus config space
functions with our new one. Attachment seems to work now mainly.


# 1.6 13-Sep-2007 mglocker

Enable access to PCI and Cardbus config space from the driver. Lets us
power on the device.


# 1.5 12-Sep-2007 mglocker

Spacing run.


# 1.4 12-Sep-2007 mglocker

For now just return directly from the interrupt handler, or my amd64 will
crash badly.


# 1.3 12-Sep-2007 jsg

Tweak bwi_attach() a little.


# 1.2 12-Sep-2007 jsg

destatic/deinline


# 1.1 12-Sep-2007 jsg

Initial port of Sepherosa Ziehau's DragonFlyBSD driver
for Broadcom AirForce wireless devices.

Not yet functional, things like DMA and firmware handling
haven't been converted yet.

ok mglocker@