History log of /freebsd-current/sys/dev/usb/wlan/if_rsu.c
Revision Date Author Comments
# 75f29849 03-Nov-2023 Bjoern A. Zeeb <bz@FreeBSD.org>

Revert "Enter the network epoch in USB WiFi drivers when processing input"

This reverts commit 17c328b6aebfa03cd1c2cbfbbc617e3b341bf1e4.

Sponsored by: The FreeBSD Foundation
MFC after: 3 days


# 685dc743 16-Aug-2023 Warner Losh <imp@FreeBSD.org>

sys: Remove $FreeBSD$: one-line .c pattern

Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/


# 935b194d 07-Feb-2023 Justin Hibbits <jhibbits@FreeBSD.org>

Mechanically convert usb ethernet drivers to DrvAPI

Reviewed by: zlei
Sponsored by: Juniper Networks, Inc.
Differential Revision: https://reviews.freebsd.org/D37812


# 183783d3 07-Dec-2022 John Baldwin <jhb@FreeBSD.org>

if_rsu: Fix mismatches in array bounds.

Reported by: GCC -Warray-parameter
Reviewed by: imp, emaste
Differential Revision: https://reviews.freebsd.org/D37551


# bc9372d7 06-May-2022 John Baldwin <jhb@FreeBSD.org>

usb: Remove unused devclass arguments to DRIVER_MODULE.


# 9a669553 06-Jun-2021 Bjoern A. Zeeb <bz@FreeBSD.org>

net80211/drivers: improve ieee80211_rx_stats for band

While IEEE80211_R_BAND was defined, there was no place to store the
band. Add a field for that, adjust ieee80211_lookup_channel_rxstatus()
to require it, and update drivers passing "R_{FREQ|IEEE}" in already to
provide the band as well. For the moment keep the fall-back code
requiring all three fields.

Sponsored by: The FreeBSD Foundation
MFC after: 3 days
Reviewed by: adrian
Differential Revision: https://reviews.freebsd.org/D30662


# 453d8a7e 22-Mar-2021 Ed Maste <emaste@FreeBSD.org>

rsu: add KASSERT to document maximum mbuf size in rsu_tx_start

PR: 254479
Reviewed by: markj
Sponsored by: The FreeBSD Foundation


# 282381aa 30-Dec-2020 John Baldwin <jhb@FreeBSD.org>

rsu: Don't modify read-only firmware block.

The firmware header loaded into an rsu(4) device has to be customized
to reflect device settings. The driver was overwriting the header
from the shared firmware image before sending it to the device. If
two devices attached at the same time with different settings, one
device could potentially get a corrupted header. The recent changes
in a095390344fb1795c1b118a2f84da8f6a7f254ab exposed this bug in the
form of a panic as the firmware blobs are now marked read-only in
object files and mapped read-only by the kernel.

To avoid the bug, change the driver to allocate a copy of the firmware
header on the stack that is initialized before writing it to the
device.

PR: 252163
Reported by: vidwer+fbsdbugs@gmail.com
Tested by: vidwer+fbsdbugs@gmail.com
Reviewed by: hselasky, bz, emaste
Sponsored by: DARPA
Differential Revision: https://reviews.freebsd.org/D27850


# 9dd3156e 01-Sep-2020 Mateusz Guzik <mjg@FreeBSD.org>

usb: clean up empty lines in .c and .h files


# 2b9f12f6 24-Aug-2020 Bjoern A. Zeeb <bz@FreeBSD.org>

net80211: enhance getflags*() and ieee80211_add_channel*()

For ieee80211_add_channel+*() we are passing in an int flag for
ht40 and in some cases another int flag for vht80 where we'd only
need two bits really.
Convert these variables to a bitflag and fold them together into one.
This also allows for VHT160 and VHT80P80 and whatever may come to
be considered. Define the various options currently needed.

Change the drivers (rtwn and rsu) which actually set this bit to non-0.
For convenience the "1" currently used for HT40 is preserved.

Enahnce getflags_5ghz() to handle the full set of VHT flags based
on the input flags from the the driver.

Update the regdomain implementation as well to make use of the new
flags and deal with higher [V]HT bandwidths.

ieee80211_add_channel() specifically did not take flags so it will
not support naything beyond 20Mhz channels.

Note: I am not entirely happy with the "cbw_flag[s]" name, but we
do use chan_flags elsewhere already.

MFC after: 2 weeks
Reviewed by: adrian, gnn
Sponsored by: Rubicon Communications, LLC (d/b/a "Netgate")
Differential revision: https://reviews.freebsd.org/D26091


# 209be66e 15-Jun-2020 Adrian Chadd <adrian@FreeBSD.org>

[rsu] Update wme ie API use.

Whoops, forgot to land this one too!


# f8d2b1f3 15-Feb-2020 Pawel Biernacki <kaktus@FreeBSD.org>

Mark more nodes as CTLFLAG_MPSAFE or CTLFLAG_NEEDGIANT (2 of many)

r357614 added CTLFLAG_NEEDGIANT to make it easier to find nodes that are
still not MPSAFE (or already are but aren’t properly marked). Use it in
preparation for a general review of all nodes.
This is non-functional change that adds annotations to SYSCTL_NODE and
SYSCTL_PROC nodes using one of the soon-to-be-required flags.

Reviewed by: hselasky, kib
Approved by: kib (mentor)
Differential Revision: https://reviews.freebsd.org/D23632


# 17c328b6 24-Jan-2020 Gleb Smirnoff <glebius@FreeBSD.org>

Enter the network epoch in USB WiFi drivers when processing input
mbuf queues.

Submitted by: Idwer Vollering <vidwer gmail.com>


# 9c601934 14-Oct-2019 Gleb Smirnoff <glebius@FreeBSD.org>

Convert to if_foreach_llmaddr() KPI.

Reviewed by: hselasky


# 786ac703 10-Mar-2019 Andriy Voskoboinyk <avos@FreeBSD.org>

Fix ieee80211_radiotap(9) usage in wireless drivers:

- Alignment issues:
* Add missing __packed attributes + padding across all drivers; in
most places there was an assumption that padding will be always
minimally suitable; in few places - e.g., in urtw(4) / rtwn(4) -
padding was just missing.
* Add __aligned(8) attribute for all Rx radiotap headers since they can
contain 64-bit TSF timestamp; it cannot appear in Tx radiotap headers, so
just drop the attribute here. Refresh ieee80211_radiotap(9) man page
accordingly.

- Since net80211 automatically updates channel frequency / flags in
ieee80211_radiotap_chan_change() drop duplicate setup for these fields
in drivers.

Tested with Netgear WG111 v3 (urtw(4)), STA mode.

MFC after: 2 weeks


# f20e36c1 30-Jan-2019 Andriy Voskoboinyk <avos@FreeBSD.org>

rsu(4): add support for ifconfig(8) 'maxretry' option.

Tested with Asus USB-N10, STA mode; maxretry 0 / 1 / 6 / 12
Checked with RTL8188EE, MONITOR mode.

MFC after: 1 week


# 635588c2 28-Jan-2019 Andriy Voskoboinyk <avos@FreeBSD.org>

Drop some unneeded includes from wireless USB drivers.

MFC after: 1 week


# 701957cb 28-Jan-2019 Andriy Voskoboinyk <avos@FreeBSD.org>

rsu(4): do not ignore mgmtrate / mcastrate / ucastrate.

Enforce net80211 rates for control / management / multicast / EAPOL frames
and allow to override rate for unicast frames via ifconfig(8) 'ucastrate'
option; by default it still uses f/w rate adaptation for unicast frames.

MFC after: 1 week


# b84b3638 26-Jan-2019 Andriy Voskoboinyk <avos@FreeBSD.org>

Remove 2GHz channel list copies from wireless drivers.

Wrap ieee80211_add_channel_list_2ghz into another function
which supplies default (1-14) channel list to it and drop
its copies from drivers.

Checked with RTL8188EE, country US / JP / KR / UA.

MFC after: 2 weeks


# 98d2a76e 10-Dec-2018 Andriy Voskoboinyk <avos@FreeBSD.org>

rtwn, rsu: add more USB ids.

PR: 233638
Submitted by: cezary.sliwa@gmail.com
MFC after: 3 days


# d7c5a620 18-May-2018 Matt Macy <mmacy@FreeBSD.org>

ifnet: Replace if_addr_lock rwlock with epoch + mutex

Run on LLNW canaries and tested by pho@

gallatin:
Using a 14-core, 28-HTT single socket E5-2697 v3 with a 40GbE MLX5
based ConnectX 4-LX NIC, I see an almost 12% improvement in received
packet rate, and a larger improvement in bytes delivered all the way
to userspace.

When the host receiving 64 streams of netperf -H $DUT -t UDP_STREAM -- -m 1,
I see, using nstat -I mce0 1 before the patch:

InMpps OMpps InGbs OGbs err TCP Est %CPU syscalls csw irq GBfree
4.98 0.00 4.42 0.00 4235592 33 83.80 4720653 2149771 1235 247.32
4.73 0.00 4.20 0.00 4025260 33 82.99 4724900 2139833 1204 247.32
4.72 0.00 4.20 0.00 4035252 33 82.14 4719162 2132023 1264 247.32
4.71 0.00 4.21 0.00 4073206 33 83.68 4744973 2123317 1347 247.32
4.72 0.00 4.21 0.00 4061118 33 80.82 4713615 2188091 1490 247.32
4.72 0.00 4.21 0.00 4051675 33 85.29 4727399 2109011 1205 247.32
4.73 0.00 4.21 0.00 4039056 33 84.65 4724735 2102603 1053 247.32

After the patch

InMpps OMpps InGbs OGbs err TCP Est %CPU syscalls csw irq GBfree
5.43 0.00 4.20 0.00 3313143 33 84.96 5434214 1900162 2656 245.51
5.43 0.00 4.20 0.00 3308527 33 85.24 5439695 1809382 2521 245.51
5.42 0.00 4.19 0.00 3316778 33 87.54 5416028 1805835 2256 245.51
5.42 0.00 4.19 0.00 3317673 33 90.44 5426044 1763056 2332 245.51
5.42 0.00 4.19 0.00 3314839 33 88.11 5435732 1792218 2499 245.52
5.44 0.00 4.19 0.00 3293228 33 91.84 5426301 1668597 2121 245.52

Similarly, netperf reports 230Mb/s before the patch, and 270Mb/s after the patch

Reviewed by: gallatin
Sponsored by: Limelight Networks
Differential Revision: https://reviews.freebsd.org/D15366


# 76ff5929 01-Nov-2017 Andriy Voskoboinyk <avos@FreeBSD.org>

rsu(4): trim code for Rx rate calculation.

Include ridx <-> rate conversion functions from rtwn(4) +
reuse already calculated value for ieee80211_radiotap(9).

Tested with Asus USB-N10, STA mode.


# bd9175e1 30-Jul-2017 Hans Petter Selasky <hselasky@FreeBSD.org>

Properly range check length of parsed information elements in RSU driver.

Found by: Ilja van Sprundel <ivansprundel@ioactive.com>
MFC after: 3 days
Sponsored by: Mellanox Technologies


# 129adb62 09-Jan-2017 Adrian Chadd <adrian@FreeBSD.org>

[rsu] add support for the "green" rsu NICs.

They're still a 1T2R NIC, so reuse the same rfconfig and
nstream configuration.

Submitted by: Idwer Vollering <vidwer@gmail.com>


# 53d2e5b7 02-Jan-2017 Andriy Voskoboinyk <avos@FreeBSD.org>

rsu: restore 40Mhz channel support.

MFC after: 4 days.


# 3620e960 22-Dec-2016 Adrian Chadd <adrian@FreeBSD.org>

[rsu] convert rsu to use the ieee80211_rx_stats struct to pass up RSSI, PHY and rate information.

I don't yet know which RX descriptor bits map to shortgi, long-gi,
short-preamble, long-preamble, STBC, LDPC, HT40, etc - so I can't
easily add those just yet.

There's apparently no per-frame RX RSSI information exposed so we
also just use the results from the previous calibration task.

This also tidies up how the per-mbuf RSSI is pushed into the frame -
now that it's attached to the mbuf via rx_stats, we don't have to
do any silly hijinx to get it out of the frame processing path.

Tested:

* RTL8712, 1x1 cut 3, STA mode


# ef06a176 11-Dec-2016 Andriy Voskoboinyk <avos@FreeBSD.org>

rsu: fix and enable Rx TCP checksum offloading.

Tested with Asus USB-N10, STA mode.


# 14a8d2f9 10-Dec-2016 Andriy Voskoboinyk <avos@FreeBSD.org>

rsu: various initialization fixes.

- Do not ignore initialization errors; call ieee80211_stop()
when initialization failed.
- Use usb_pause_mtx() instead of DELAY() while waiting for firmware
loading; this fixes system freeze during firmware startup.
- Do not execute rsu_stop() when device is powered off; fixes
'unknown board type (rfconfig=0xff)' error when the device is
reattached.

Tested with Asus USB-N10.


# 88c2e36a 10-Dec-2016 Andriy Voskoboinyk <avos@FreeBSD.org>

rsu: use bitmap for all debug messages.

- Replace all remaining DPRINTF(N)'s with RSU_DPRINTF.
- Add new RSU_DEBUG_USB flag to track error codes returned by
usbd_do_request_flags().
- Improve few messages.


# f06ccf88 10-Dec-2016 Andriy Voskoboinyk <avos@FreeBSD.org>

rsu: add promiscuous mode support.

- Add partial promiscuous mode support (no management frames;
they cannot be received by the firmware and net80211 at the same time).
- Add monitor mode support (all frames).

Tested with Asus, USB-N10.


# 88e8709e 10-Dec-2016 Andriy Voskoboinyk <avos@FreeBSD.org>

rsu: add TSF field into Rx radiotap.

Tested with Asus USB-N10.


# 4a19d712 07-Dec-2016 Andriy Voskoboinyk <avos@FreeBSD.org>

net80211 + drivers: convert to ieee80211_crypto_get_key_wepidx().

Proposed by: adrian


# 8e61c3f8 05-Dec-2016 Andriy Voskoboinyk <avos@FreeBSD.org>

rsu: fix printf format specifiers.


# 31847d94 05-Dec-2016 Andriy Voskoboinyk <avos@FreeBSD.org>

rsu: add hardware crypto support (WEP, TKIP and CCMP).

This change includes firmware commands for key setup +
some additional checking via CAMREAD / CAMWRITE registers.
Nothing (except rsu_delete_key() for pairwise keys) is deferred;
to ensure that things are done in order rsu_set_key() will wait
until key deletion task will be finished.

Tested with Asus USB-N10 (all ciphers).

Differences from initial (reviewed) patch:
- Pause AC queues before disassociation - since CMD_DISCONNECT clears
crypto state all pending frames must be processed / dropped before it.
- Check sc_running flag before trying to set static keys.
- Clear key index from bitmap even when firmware command fails
(it will be invalidated via CAMWRITE anyway).

Reviewed by: adrian, kevlo
Tested by: kevlo
Differential Revision: https://reviews.freebsd.org/D8706


# c057023b 04-Dec-2016 Andriy Voskoboinyk <avos@FreeBSD.org>

rsu: fix RSSI reporting, partially revert r288414.

- Append RCR_APP_PHYSTS bit after firmware loading - otherwise
firmware will reset the register and this modification will be lost.
(without it Rx PHY descriptor section will contain garbage).
- Check if R92S_RXDW0_PHYST bit is set (like it is done in rtwn(4)) -
even if infosz is non-zero the section may not contain anything useful.
- In case, if descriptor is absent (A-MPDU?) use last calibrated RSSI
(rtwn(4) uses RSSI from the previous (sub)frame; probably, this
approach should be used here too).

Tested with Asus USB-N10, STA mode.


# 61278053 03-Dec-2016 Andriy Voskoboinyk <avos@FreeBSD.org>

rsu: fix frame processing in the Rx path (similar to r292207).

- Fill in Rx radiotap header correctly (for every packet in a chain;
not once per chain).
- Fix rate / flags fields in Rx radiotap.
- Add debug messages for discarded frames.
- Pass received control (< sizeof(struct ieee80211_frame)) frames
to net80211 (if allowed by device filter; cannot happen yet).

Tested with Asus USB-N10.

Differential Revision: https://reviews.freebsd.org/D5723


# bcb07181 03-Dec-2016 Andriy Voskoboinyk <avos@FreeBSD.org>

rsu: remove unused structures / variables.


# 935b4fcc 27-Nov-2016 Andriy Voskoboinyk <avos@FreeBSD.org>

rsu: add support for hardware multicast filter setup.

The algorithm is the same as in rtwn(4).

Tested with Asus USB-N10 (STA) + RTL8188CUS (AP).


# 5dbbb84e 26-Nov-2016 Andriy Voskoboinyk <avos@FreeBSD.org>

rsu: various scanning fixes.

- Set IEEE80211_FEXT_SCAN_OFFLOAD flag; firmware can send null data
frames when associated.
- Check IEEE80211_SCAN_ACTIVE scan flag instead of IEEE80211_F_ASCAN
ic flag; the last is never set since r170530.
- Eliminate software scan (net80211) <-> site_survey (driver) race:
* override ic_scan_curchan and ic_scan_mindwell pointers so net80211
will not try to finish scanning automatically;
* inform net80211 about current status via ieee80211_cancel_scan()
and ieee80211_scan_done();
* remove corresponding workaround from rsu_join_bss().

Now the driver can associate to an AP with hidden SSID.

Tested with Asus USB-N10.


# bdc7291e 12-Oct-2016 Andriy Voskoboinyk <avos@FreeBSD.org>

net80211: convert all ieee80211_input_mimo*() consumers
to ieee80211_add_rx_params() + drop last (ieee80211_rx_stats) parameter

Note: there is an additional check for ieee80211_get_rx_params()
return value (which does not exist in the original diff).

Reviewed by: adrian
Differential Revision: https://reviews.freebsd.org/D8207


# e97796e2 07-Oct-2016 Adrian Chadd <adrian@FreeBSD.org>

[net80211] extend the ieee80211_rx_stats struct to include more information.

There are a variety of more interesting RX statistics that we should
keep track of but we don't. This is a starting point for adding more
information.

Specifically:

* now the RX rate information and some of the packet status is
passed up;
* The 32 bit or 64 bit TSF is passed up;
* the PHY mode is passed up;
* the "I'm decap'ed AMSDU!" state is passed up;
* number of RX chains is bumped to 4.

This is all mostly a placeholder for getting the data into the RX status
before we pass it up to net80211 - unfortunately we don't yet enforce
that drivers provide it, nor do we pass the provided info back up the
stack so anyone can use the data.

We're going to need to use some of this data moving forward.
Notably, now that some hardware can do AMSDU decap for us (the intel iwm
driver can do it when we flip it on; the ath10k port I'm doing does
it for us) then we need to pass it up through the stack so the duplicate
RX sequence numbers and crypto/IV details don't cause the packet to
be dropped and/or counted against a replay counter.

It's also the beginning of being able to do more interesting node
accounting in net80211. Specifically, once drivers start populating
per-packet rate information, AMPDU information, timestamps, etc,
we can start providing histograms of rate-versus-RSSI, account
for receive time spent per node and other such interesting things.

(Note: I'm also hoping to include ranging and RTT information for
future chipset support; and it's likely going to include it in
this kind of fashion.)


# fbc9d202 25-Sep-2016 Andriy Voskoboinyk <avos@FreeBSD.org>

rsu: do not restart calibration task when going out of RUN state.

Clear 'sc_calibrating' flag and stop calibration task when interface
is not associated; this fixes possible panic after detach.

Reported and tested by: hselasky
Reviewed by: adrian
MFC after: 6 days


# a7c31fe1 26-May-2016 Andriy Voskoboinyk <avos@FreeBSD.org>

urtwn, rtwn, rsu: switch to ieee80211_add_channel_list_2ghz().

- Use device's channel list instead of default one (from
ieee80211_init_channels()); adds 12 - 14 2GHz channels.
- Add ic_getradiocaps() method.


# a061fea6 29-Apr-2016 Andriy Voskoboinyk <avos@FreeBSD.org>

net80211 + drivers: hide size of 'bands' array behind a macro.

Auto-replace 'howmany(IEEE80211_MODE_MAX, 8)' with 'IEEE80211_MODE_BYTES'.
No functional changes.


# b60322c9 05-Apr-2016 Adrian Chadd <adrian@FreeBSD.org>

[rsu] We don't do A-MPDU transmit right now, so don't bother registering
for it.


# 8ec07310 01-Feb-2016 Gleb Smirnoff <glebius@FreeBSD.org>

These files were getting sys/malloc.h and vm/uma.h with header pollution
via sys/mbuf.h


# 0046e186 07-Jan-2016 Andriy Voskoboinyk <avos@FreeBSD.org>

net80211 drivers: fix ieee80211_init_channels() usage

Fix out-of-bounds read (all) / write (11n capable) for drivers
that are using ieee80211_init_channels() to initialize channel list.

Tested with:
* RTL8188EU, STA mode.
* RTL8188CUS, STA mode.
* WUSB54GC, HOSTAP mode.

Approved by: adrian (mentor)
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D4818


# f809f280 10-Dec-2015 Warner Losh <imp@FreeBSD.org>

Create a USB_PNP_INFO and use it to export the existing PNP
tables. Some drivers needed some slight re-arrangement of declarations
to accommodate this. Change the USB pnp tables slightly to allow
better compatibility with the system by moving linux driver info from
start of each entry to the end. All other PNP tables in the system
have the per-device flags and such at the end of the elements rather
that at the beginning.

Differential Review: https://reviews.freebsd.org/D3458


# d957a93a 11-Oct-2015 Adrian Chadd <adrian@FreeBSD.org>

net80211: move ieee80211_free_node() call on error from ic_raw_xmit() to ieee80211_raw_output().

This doesn't free the mbuf upon error; the driver ic_raw_xmit method is still
doing that.

Submitted by: <s3erios@gmail.com>
Differential Revision: https://reviews.freebsd.org/D3774


# a3767659 29-Sep-2015 Adrian Chadd <adrian@FreeBSD.org>

modify the rssi logic a bit to actually return a useful rssi.

The fullmac firmware doesn't seem to populate a useful rssi indicator
in the RX descriptor, so if one plotted said values, they'd basically
look like garbage.

The reference driver implements a "get current rssi" firmware command
which I guess is really meant for station operation only (as hostap
operation would need rssi per station, not a single firmware read.)

So:

* populate sc_currssi during each calibration run;
* use this in the RX path instead of trying to reconstruct the RSSI
value and passing it around as a pointer;
* do up a quick hack to map the rssi hardware value to some useful
signal level;
* the survey results provide an RSSI value between 0..100, so just
do another quick hack to map it into some usefulish signal level;
* supply a faked noise floor - I haven't yet found how to pull it
out of the firmware.

The scan results and the station RSSI information is now more useful
for indicating signal strength / distance.


# 85dafc69 29-Sep-2015 Adrian Chadd <adrian@FreeBSD.org>

rsu(4): Add support for 1T2R and 2T2R NICs.

This logic is mostly crimed from the reference driver and the linux
r92su driver.

I verified that it (a) worked on the rsu hardware I have, and (b)
did traffic testing whilst watching what ath(4) sent as a hostap.
It successfully sent MCS8..15 rates (which requires 2-stream reception)
as well as MCS0..7 (which is 1-stream.)

Tested:

* RTL8712, 1T1R NIC, MCS rates 0..7.
* RTL8712, 1T2R NIC, MCS rates 0..15

TODO:

* Find a 2T2R NIC!


# 3a8545c3 27-Sep-2015 Adrian Chadd <adrian@FreeBSD.org>

include opt_wlan.h . Tsk adrian.


# ac9e537c 26-Sep-2015 Adrian Chadd <adrian@FreeBSD.org>

Free the TX/RX list buffers /before/ tearing down net80211 state.

Otherwise buffers in the RX queue get freed with their parent vap
being gone and you end up with a juicy kernel panic.


# 74d7b9a8 26-Sep-2015 Adrian Chadd <adrian@FreeBSD.org>

* Add 11n HT40 support - i needed to send both HTINFO and HTCAP fields
in the join message so the firmware would pick it up.

* Strip out the direct hardware fiddling for 40MHz mode - the firmware
we're using doesn't require it (the rtl8712su firmware does; it
is less 'fullmac' than what we're using.)

* Fix the mbuf handling during errors - rsu_tx shouldn't free mbufs;
it's up to the caller to do so. This brings it in line with
what other drivers do or should be doing.

Tested:

* RTL8712, HT40 channel, STA mode (during this commit)


# 44369387 21-Sep-2015 Adrian Chadd <adrian@FreeBSD.org>

Send a power command to the firmware to shut down the radio as well
during rsu_stop().


# 6acf853d 21-Sep-2015 Adrian Chadd <adrian@FreeBSD.org>

Begin fleshing out basic power-on / power-off and A-MPDU TX support.

* Add a new method to control NIC poweron / network-sleep / power off;
* Add in A-MPDU TX negotiation support, but comment it out because it
does break TX traffic;
* blank out the tx buffer before sending a firmware message, just in case;
* go into network-sleep once associated;

TODO:

* figure out why ampdu negotiation isn't working and breaking TX traffic,
then enable it.


# 39089f06 20-Sep-2015 Adrian Chadd <adrian@FreeBSD.org>

Flip on 11n by default; update TODO items.


# 77435f18 20-Sep-2015 Adrian Chadd <adrian@FreeBSD.org>

Convert if_rsu to use a deferred transmit task rather than using rsu_start()
to do it directly.

Ensure that we re-queue starting transmit upon TX completion.

This solves two issues:

* It stops tx stalls - before this, if the transmit path filled the
mbuf queue then it'd never start another transmit.

* It enforces ordering - this is very required for 802.11n which
requires frames to be transmitted in the order they're queued.
Since everything remotely involved in USB has an unlock/thing/relock
pattern with that mutex, the only way to guarantee TX ordering is
to 100% defer it into a separate thread.

This now survives an iperf test and gets a reliable 30mbit/sec.


# 829e0b0b 20-Sep-2015 Adrian Chadd <adrian@FreeBSD.org>

Drain the mbuf queue upon rsu_stop().

Correctly (I hope!) remove net80211 references before doing so.
Just doing a dumb mbufq drain isn't enough.

If enough traffic occurs and the mbuf queue fills up then transmit
stalls (which I'm not fixing in this commit!) but then the mbuf queue
stays full until the driver is removed. There's also the net80211
node refcounting leak.

This just ensures that during rsu_stop and detach the mbuf queue
is purged (and references!) so the queue-full situation can be
recovered from.


# 3d07cc29 20-Sep-2015 Adrian Chadd <adrian@FreeBSD.org>

Disable HT40 in if_rsu for now. There's something missing in the HT40
setup pieces and so (at least) transmit doesn't work.

It'll just fall back to being a straight HT20 device and negotiate
HT20 only.

Tested by: Idwer Vollering <vidwer@gmail.com>


# 23386fa4 18-Sep-2015 Adrian Chadd <adrian@FreeBSD.org>

Add in a temporary (hah!) workaround for net80211 scanning versus NIC
requirements.

Don't start the opmode and join path until a pending survey is finished.
This seems to reliably fix things.

Ideally I'd just finish off the net80211 pluggable scan stuff and implement
the methods here so if_rsu can just drive the scan machinery.
However, that's a .. later thing.

Whilst here, remove the getbuf debugging; it's okay to run out of transmit
buffers under load; it however isn't okay to not be able to send commands.
I'll fix that later.


# de76b5b7 18-Sep-2015 Adrian Chadd <adrian@FreeBSD.org>

Refactor out the tx buffer free code into a routine, rsu_freebuf().

This makes it easier to add more transmit buffers, have different buffer
pools for things, etc.


# a12cbef7 17-Sep-2015 Adrian Chadd <adrian@FreeBSD.org>

Set AMPDU density/size parameters during vap creation.

Inspired from: Linux r92su


# 237c4b43 17-Sep-2015 Adrian Chadd <adrian@FreeBSD.org>

Add a very hacked up station only A-MPDU negotiation path.

This is enough to set things up; there are still lots of retransmits
seen but it's enough to get things working.


# 4b9d9eee 17-Sep-2015 Adrian Chadd <adrian@FreeBSD.org>

Add initial 11n support to if_rsu.

* Add a tunable to enable 11n if it's available, so to not anger people
who upgrade.

kenv hw.usb.rsu.enable_11n=1 before inserting the device.

* Add initial 11n htconfig bits;
* Enable 40MHz mode if it's available;
* Add 11n channels;
* Set 11n bits in the firmware.

It works for RX; I haven't tested TX aggregation just yet.
However the firmware doesn't do RX re-ordering, so I have to tie it into
the net80211 A-MPDU RX reorder path before I flip this on by default.

I've verified that I'm indeed actually seeing MCS 0->7 rates being received.
I haven't dug into whether it's actually transmitting 11n rates; I'll dig into
that later.


# a851c667 17-Sep-2015 Adrian Chadd <adrian@FreeBSD.org>

.. oops, flip on QoS.


# b4d4079c 16-Sep-2015 Adrian Chadd <adrian@FreeBSD.org>

Bring over the QoS logic from the Linux r92su driver.

* the tx descriptor TID is priority, not TID.
* the tx descriptor queue id mapping is separate from the
TID/priority; rather than just "BE".

TODO:

* go and re-re-re-verify the queue mappings; the linux and openbsd
mappings aren't exactly the same. I need to verify all of this
before I try to flip on 11n RX.


# b8303685 16-Sep-2015 Adrian Chadd <adrian@FreeBSD.org>

Program the firmware setup stuff with the current hardware setup:

* Do 1T1R for now, until we read the config out of ROM and use it.
* Disable turbo mode, I dunno what this is, but the linux drivers
have this disabled.
* Set the firmware endpoints to what we read from USB.

Tested:

* RTL8712 cut 3, STA mode


# bc6a9865 16-Sep-2015 Adrian Chadd <adrian@FreeBSD.org>

Use the H2C endpoint for sending firmware commands, rather than the voice
data queues.

This is similar to the openbsd and rtlwifi/r92su drivers.

Note: this driver still assumes it's a 4-endpoint device; I'll enforce
that in a follow-up commit.


# 882704d0 16-Sep-2015 Adrian Chadd <adrian@FreeBSD.org>

Add 11n and QoS methods.

The firmware takes care of ampdu tx/rx (except for RX reordering, grr),
QoS/WME and other bits/pieces. So they're stubs, just in case.


# 47b0d9dd 16-Sep-2015 Adrian Chadd <adrian@FreeBSD.org>

Prepare for 11n - get the number of endpoints and whether 11n is available.


# 17ebf553 16-Sep-2015 Adrian Chadd <adrian@FreeBSD.org>

Use DELAY() rather than usb_pause_mtx() - the latter releases the lock
before waiting, which prevents the lock from really acting like
a hardware serialiser. Sigh.


# 89fd8237 14-Sep-2015 Adrian Chadd <adrian@FreeBSD.org>

Replace the scan event input path hack with the new rx-stats based method.
This allows for arbitrary channel info to be placed in the input call rather
than the totally gross hack of overriding ic_curchan.

Without this I'm sure ic_curchan setting was racing with the scan code
setting the channel itself..


# cf52bbe0 13-Sep-2015 Adrian Chadd <adrian@FreeBSD.org>

Disable mgmt frame sending in if_rsu.

The firmware in this NIC sends management frames. So far I'm not sure which
ones it handles and which ones it doesn't handle - but this is what openbsd
does.

The association messages are handled by the firmware; the key negotiation
for 802.1x and WPA are done as raw frames, not management frames.

This successfully allows it to associate to my home networks whereas it didn't
work beforehand.

Tested:

* RTL8712, cut 3, STA mode

TODO:

* The firmware does send a join response with a status code; that should be
logged in a more obvious way to assist with debugging. Ie, the firmware
is the thing that is saying "couldn't join, sorry!", not net80211.


# a934198b 12-Sep-2015 Adrian Chadd <adrian@FreeBSD.org>

Add RSSI logging to the event survey results.


# 9b6916db 12-Sep-2015 Adrian Chadd <adrian@FreeBSD.org>

After reading the linux driver, document what this bit is doing
(doing a full NIC awake.)


# e6d258f6 12-Sep-2015 Adrian Chadd <adrian@FreeBSD.org>

* fiddle with some more of the debugging output
* yes, when a "sta disconnect" message comes through we should, like,
disconnect things. We're not currently generating beacon miss messages,
and net80211 isn't disconnecting things via software beacon miss receive.

Tested:

* RTL8712, cut 3, STA mode


# 4914fa0f 12-Sep-2015 Adrian Chadd <adrian@FreeBSD.org>

if_rsu debug fixes:

* use an ath/iwn style debug bitmap - it's still global rather than per-device,
but it's better than debug levels
* disable bgscan - it just makes things unstable/unpredictable for now.

Tested:

* if_rsu - RTL8712 cut 3, STA mode


# 7a79cebf 27-Aug-2015 Gleb Smirnoff <glebius@FreeBSD.org>

Replay r286410. Change KPI of how device drivers that provide wireless
connectivity interact with the net80211 stack.

Historical background: originally wireless devices created an interface,
just like Ethernet devices do. Name of an interface matched the name of
the driver that created. Later, wlan(4) layer was introduced, and the
wlanX interfaces become the actual interface, leaving original ones as
"a parent interface" of wlanX. Kernelwise, the KPI between net80211 layer
and a driver became a mix of methods that pass a pointer to struct ifnet
as identifier and methods that pass pointer to struct ieee80211com. From
user point of view, the parent interface just hangs on in the ifconfig
list, and user can't do anything useful with it.

Now, the struct ifnet goes away. The struct ieee80211com is the only
KPI between a device driver and net80211. Details:

- The struct ieee80211com is embedded into drivers softc.
- Packets are sent via new ic_transmit method, which is very much like
the previous if_transmit.
- Bringing parent up/down is done via new ic_parent method, which notifies
driver about any changes: number of wlan(4) interfaces, number of them
in promisc or allmulti state.
- Device specific ioctls (if any) are received on new ic_ioctl method.
- Packets/errors accounting are done by the stack. In certain cases, when
driver experiences errors and can not attribute them to any specific
interface, driver updates ic_oerrors or ic_ierrors counters.

Details on interface configuration with new world order:
- A sequence of commands needed to bring up wireless DOESN"T change.
- /etc/rc.conf parameters DON'T change.
- List of devices that can be used to create wlan(4) interfaces is
now provided by net.wlan.devices sysctl.

Most drivers in this change were converted by me, except of wpi(4),
that was done by Andriy Voskoboinyk. Big thanks to Kevin Lo for testing
changes to at least 8 drivers. Thanks to pluknet@, Oliver Hartmann,
Olivier Cochard, gjb@, mmoll@, op@ and lev@, who also participated in
testing.

Reviewed by: adrian
Sponsored by: Netflix
Sponsored by: Nginx, Inc.


# d3fdd08c 19-Aug-2015 Adrian Chadd <adrian@FreeBSD.org>

Further conversions from ifp->if_softc -> ic_softc.


# ba2c1fbc 07-Aug-2015 Adrian Chadd <adrian@FreeBSD.org>

Revert the wifi ifnet changes until things are more baked and tested.

* 286410
* 286413
* 286416

The initial commit broke a variety of debug and features that aren't
in the GENERIC kernels but are enabled in other platforms.


# 79d2c5e8 07-Aug-2015 Gleb Smirnoff <glebius@FreeBSD.org>

Change KPI of how device drivers that provide wireless connectivity interact
with the net80211 stack.

Historical background: originally wireless devices created an interface,
just like Ethernet devices do. Name of an interface matched the name of
the driver that created. Later, wlan(4) layer was introduced, and the
wlanX interfaces become the actual interface, leaving original ones as
"a parent interface" of wlanX. Kernelwise, the KPI between net80211 layer
and a driver became a mix of methods that pass a pointer to struct ifnet
as identifier and methods that pass pointer to struct ieee80211com. From
user point of view, the parent interface just hangs on in the ifconfig
list, and user can't do anything useful with it.

Now, the struct ifnet goes away. The struct ieee80211com is the only
KPI between a device driver and net80211. Details:

- The struct ieee80211com is embedded into drivers softc.
- Packets are sent via new ic_transmit method, which is very much like
the previous if_transmit.
- Bringing parent up/down is done via new ic_parent method, which notifies
driver about any changes: number of wlan(4) interfaces, number of them
in promisc or allmulti state.
- Device specific ioctls (if any) are received on new ic_ioctl method.
- Packets/errors accounting are done by the stack. In certain cases, when
driver experiences errors and can not attribute them to any specific
interface, driver updates ic_oerrors or ic_ierrors counters.

Details on interface configuration with new world order:
- A sequence of commands needed to bring up wireless DOESN"T change.
- /etc/rc.conf parameters DON'T change.
- List of devices that can be used to create wlan(4) interfaces is
now provided by net.wlan.devices sysctl.

Most drivers in this change were converted by me, except of wpi(4),
that was done by Andriy Voskoboinyk. Big thanks to Kevin Lo for testing
changes to at least 8 drivers. Thanks to Olivier Cochard, gjb@, mmoll@,
op@ and lev@, who also participated in testing. Details here:

https://wiki.freebsd.org/projects/ifnet/net80211

Still, drivers: ndis, wtap, mwl, ipw, bwn, wi, upgt, uath were not
tested. Changes to mwl, ipw, bwn, wi, upgt are trivial and chances
of problems are low. The wtap wasn't compilable even before this change.
But the ndis driver is complex, and it is likely to be broken with this
commit. Help with testing and debugging it is appreciated.

Differential Revision: D2655, D2740
Sponsored by: Nginx, Inc.
Sponsored by: Netflix


# 272f6ade 25-May-2015 Gleb Smirnoff <glebius@FreeBSD.org>

Change three methods in struct ieee80211com, namely ic_updateslot,
ic_update_mcast and ic_update_promisc, to pass pointer to the ieee80211com,
not to the ifnet.

Sponsored by: Netflix
Sponsored by: Nginx, Inc.


# 59686fe9 25-May-2015 Gleb Smirnoff <glebius@FreeBSD.org>

Set ic_softc in all 802.11 drivers. Not required right now, but will be
used quite soon.

Sponsored by: Netflix
Sponsored by: Nginx, Inc.


# c8550c02 25-May-2015 Gleb Smirnoff <glebius@FreeBSD.org>

Make net80211 drivers supply their device name to the net80211 layer, so
that the latter doesn't need to go through struct ifnet to get their name.

Sponsored by: Netflix
Sponsored by: Nginx, Inc.


# ece4b0bd 05-Jan-2015 Hans Petter Selasky <hselasky@FreeBSD.org>

Make a bunch of USB debug SYSCTLs tunable, so that their value(s) can
be set before the USB device(s) are probed.


# abfa11d6 03-Jan-2015 Hans Petter Selasky <hselasky@FreeBSD.org>

Make sure an error case exits unlocked.

Submitted by: Dmitry Luhtionov <dmitryluhtionov@gmail.com>
MFC after: 1 week


# fa20eb98 18-Nov-2014 Kevin Lo <kevlo@FreeBSD.org>

Add Trendnet TEW-646UBH.

Submitted by: bolshakov_1 at yahoo dot com


# a001989d 19-Sep-2014 Gleb Smirnoff <glebius@FreeBSD.org>

Mechanically convert to if_inc_counter().


# bb03cd6f 04-Jun-2014 Hans Petter Selasky <hselasky@FreeBSD.org>

More RSU fixes:
- Properly align temporary buffer to 32-bit.
- Add an extra parenthesis to make expression clear.
- Range check the association ID received from hardware.

MFC after: 1 week


# 910593b5 04-Jun-2014 Hans Petter Selasky <hselasky@FreeBSD.org>

Fixes for the RSU driver:
- The R92S_TCR register is an 8-bit register. Don't access it like a
16-bit register.
- Disable parsing the delete station event, due to many false events.
- Ensure that there is only one transfer queue for each endpoint, so
that packets transmitted don't get out of order.

MFC after: 1 week


# 1593e875 21-May-2014 Hans Petter Selasky <hselasky@FreeBSD.org>

- Give firmware loading more time.

MFC after: 3 days


# 885476cb 22-May-2014 Hans Petter Selasky <hselasky@FreeBSD.org>

- Stop transfers when RSU init fails.
- Make sure TX/RX lists don't leak and are only allocated once.
- Fix off-by one transfer index computation.
- Give firmware loading more time.

MFC after: 3 days


# 400b4e53 21-May-2014 Hans Petter Selasky <hselasky@FreeBSD.org>

- Split transmit queue into one for each type. Apparently there will
be a race when using a single active queue for all transmit types.
- Last argument of usb_pause_mtx() is ticks and not milliseconds.
- Remove unused watchdog.
- Remove some unused fields from the RSU softc structure.
- Workaround usbd_transfer_start() recursion from inside of completion
callback.

MFC after: 3 days


# 302a703b 21-May-2014 Hans Petter Selasky <hselasky@FreeBSD.org>

Avoid starting a USB transfer inside the callback function, right
after its been submitted.

MFC after: 3 days


# b41381ae 20-May-2014 Hans Petter Selasky <hselasky@FreeBSD.org>

- The DELAY() should not be used in USB drivers.
- The usb_pause_mtx() function takes ticks and not milliseconds as last argument.

MFC after: 3 days


# 7243077c 19-May-2014 Hans Petter Selasky <hselasky@FreeBSD.org>

Make sure detach code is executed in all cases. This fixes a panic
when debugging is enabled.

Reported by: Idwer Vollering <vidwer@gmail.com>
MFC after: 3 days


# 107f00c0 10-Jan-2014 Kevin Lo <kevlo@FreeBSD.org>

Use m_get2() instead of m_getcl().

Spotted by: glebius


# 569dfed3 09-Jan-2014 Kevin Lo <kevlo@FreeBSD.org>

Use m_getcl() instead of MGETHDR/MCLGET macros.

Suggested by: glebius


# 115ea7c1 08-Jan-2014 Kevin Lo <kevlo@FreeBSD.org>

Replace deprecated M_DONTWAIT with M_NOWAIT.


# 5945b5f5 08-Jan-2014 Kevin Lo <kevlo@FreeBSD.org>

Rename definition of IEEE80211_FC1_WEP to IEEE80211_FC1_PROTECTED.

The origin of WEP comes from IEEE Std 802.11-1997 where it defines
whether the frame body of MAC frame has been encrypted using WEP
algorithm or not.
IEEE Std. 802.11-2007 changes WEP to Protected Frame, indicates
whether the frame is protected by a cryptographic encapsulation
algorithm.

Reviewed by: adrian, rpaulo


# 8cfe5440 03-Dec-2013 Hans Petter Selasky <hselasky@FreeBSD.org>

Fix external compiler warning(s). Avoid pointer dereferencing.


# bf124fcf 11-Nov-2013 Kevin Lo <kevlo@FreeBSD.org>

Use the real product name for Edimax rsu(4) id.


# bb2f69e8 05-Nov-2013 Hans Petter Selasky <hselasky@FreeBSD.org>

Check for "ieee80211_vap_setup()" failure in all USB WLAN drivers.

MFC after: 1 week


# 76039bc8 26-Oct-2013 Gleb Smirnoff <glebius@FreeBSD.org>

The r48589 promised to remove implicit inclusion of if_var.h soon. Prepare
to this event, adding if_var.h to files that do need it. Also, include
all includes that now are included due to implicit pollution via if_var.h

Sponsored by: Netflix
Sponsored by: Nginx, Inc.


# 53dfd5c1 31-Jul-2013 Rui Paulo <rpaulo@FreeBSD.org>

Cleanup the allocations when the attachment fails.


# 6d9b2f85 30-Jul-2013 Rui Paulo <rpaulo@FreeBSD.org>

Unbreak sparc64 LINT. Need to fix this correctly at some point in the future.


# 31d98677 29-Jul-2013 Rui Paulo <rpaulo@FreeBSD.org>

Import OpenBSD's rsu(4) WLAN driver.
Support chipsets are the Realtek RTL8188SU, RTL8191SU, and RTL8192SU.

Many thanks to Idwer Vollering for porting/writing the man page and for
testing.

Reviewed by: adrian, hselasky
Obtained from: OpenBSD
Tested by: kevlo, Idwer Vollering <vidwer at gmail.com>