Commit Graph

293 Commits

Author SHA1 Message Date
Adrian Chadd
85dafc6977 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!
2015-09-29 06:56:00 +00:00
Adrian Chadd
24c2763fb1 urtwn driver fixes - missing include, free node references, shut down xfers first
* include opt_wlan.h like a good little wlan driver;
* add a function to free the mbufq /and/ the node references on it, or we will leak
  said node references;
* free the mbufq upon NIC shutdown otherwise we may end up with a full list that
  we never begin transmit work on, and thus never drain it;
* .. which frees it upon NIC detach too;
* ensure urtwn_start() gets called after the completion of frame TX even if the
  pending queue is empty, otherwise transmit will stall.  It's highly unlikely that
  the usb tx queue would be empty whilst the incoming send queue is full, but hey,
  who knows.

This passes some iperf testing with and without the NIC being actively removed during
said active iperf test.

Tested:

* urtwn0: MAC/BB RTL8188EU, RF 6052 1T1R ; STA mode
2015-09-29 05:03:24 +00:00
Adrian Chadd
3a8545c312 include opt_wlan.h . Tsk adrian. 2015-09-28 01:16:44 +00:00
Adrian Chadd
ac9e537ce0 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.
2015-09-26 22:20:30 +00:00
Adrian Chadd
74d7b9a832 * 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)
2015-09-26 07:25:53 +00:00
Adrian Chadd
0cf00015be net80211: include one copy of struct ieee80211_beacon_offsets into ieee80211vap
Submitted by:	Andriy Voskoboinyk <s3erios@gmail.com>
Differential Revision:	https://reviews.freebsd.org/D3658
2015-09-22 06:34:07 +00:00
Adrian Chadd
44369387a1 Send a power command to the firmware to shut down the radio as well
during rsu_stop().
2015-09-22 05:48:51 +00:00
Adrian Chadd
6acf853d7a 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.
2015-09-22 02:57:18 +00:00
Adrian Chadd
82e8c646b4 net80211 & wireless drivers: remove duplicate defines (noop)
- IEEE80211_DIR_DSTODS(wh) -> IEEE80211_IS_DSTODS(wh).
- N(a) -> nitems(a).
- Remove LE_READ_2(p)/LE_READ_4(p) definitions (and include ieee80211_input.h instead).
- <drvname>_TXOP_TO_US(txop) -> IEEE80211_TXOP_TO_US(txop).
- Put IEEE80211_RV(v) into ieee80211_proto.h and remove local RV(v) definitions.

Submitted by:   Andriy Voskoboinyk <s3erios@gmail.com>
Differential Revision:  https://reviews.freebsd.org/D3705
2015-09-22 02:48:59 +00:00
Adrian Chadd
39089f06bf Flip on 11n by default; update TODO items. 2015-09-21 02:32:11 +00:00
Adrian Chadd
77435f1835 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.
2015-09-21 02:30:22 +00:00
Adrian Chadd
829e0b0b84 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.
2015-09-21 02:12:01 +00:00
Adrian Chadd
3d07cc29cf 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>
2015-09-20 22:52:40 +00:00
Adrian Chadd
23386fa4b6 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.
2015-09-18 07:55:33 +00:00
Adrian Chadd
de76b5b7fe 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.
2015-09-18 07:26:34 +00:00
Adrian Chadd
a12cbef7b0 Set AMPDU density/size parameters during vap creation.
Inspired from: Linux r92su
2015-09-18 05:59:15 +00:00
Adrian Chadd
237c4b4378 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.
2015-09-18 05:03:01 +00:00
Adrian Chadd
4b9d9eee03 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.
2015-09-18 04:12:11 +00:00
Adrian Chadd
a851c66778 .. oops, flip on QoS. 2015-09-17 07:04:15 +00:00
Adrian Chadd
b4d4079c85 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.
2015-09-17 04:45:29 +00:00
Adrian Chadd
b8303685fa 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
2015-09-17 03:42:18 +00:00
Adrian Chadd
bc6a9865d6 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.
2015-09-17 03:19:09 +00:00
Adrian Chadd
882704d0ce 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.
2015-09-17 03:13:01 +00:00
Adrian Chadd
47b0d9dd88 Prepare for 11n - get the number of endpoints and whether 11n is available. 2015-09-17 03:08:02 +00:00
Adrian Chadd
ddf4995dc5 Bump RX_LIST_COUNT so we don't fall behind during active traffic. 2015-09-17 03:01:55 +00:00
Adrian Chadd
17ebf55362 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.
2015-09-17 03:01:19 +00:00
Kevin Lo
97ad4604d7 Use M_WAITOK rather than M_NOWAIT since it's not used within
interrupt context.
2015-09-16 07:26:18 +00:00
Kevin Lo
4bae831003 Fix a debug message which didn't quite get it right about eeprom version. 2015-09-16 07:18:54 +00:00
Kevin Lo
f75281b8f2 Remove checks for a NULL return value from M_WAITOK allocations. 2015-09-16 07:16:21 +00:00
Adrian Chadd
89fd823782 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..
2015-09-15 03:01:40 +00:00
Adrian Chadd
cf52bbe053 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.
2015-09-13 19:17:26 +00:00
Adrian Chadd
a934198b02 Add RSSI logging to the event survey results. 2015-09-13 05:22:20 +00:00
Adrian Chadd
9b6916dbed After reading the linux driver, document what this bit is doing
(doing a full NIC awake.)
2015-09-13 04:41:13 +00:00
Adrian Chadd
e6d258f6ac * 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
2015-09-13 04:12:51 +00:00
Adrian Chadd
4914fa0fd6 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
2015-09-12 23:10:34 +00:00
Kevin Lo
b904ffbde5 Correct setting R92C_TDECTRL_BLK_DESC_NUM_M bit. 2015-09-09 01:51:38 +00:00
Kevin Lo
599acbbcd8 Enable TSF timer in monitor mode.
Tested on RT5370, sta mode.
Submitted by:	Andriy Voskoboinyk <s3erios at gmail com>
Differential Revision:	https://reviews.freebsd.org/D3591
2015-09-08 08:06:20 +00:00
Kevin Lo
ef9c07684c Add TSF field into TX/RX radiotap headers
Tested on RT5370, sta mode.
Submitted by:	Andriy Voskoboinyk <s3erios at gmail com>
Differential Revision:	https://reviews.freebsd.org/D3590
2015-09-08 08:02:14 +00:00
Kevin Lo
3257f9021a Fix comparison in run_key_set_cb().
Tested on RT5370, sta mode.

Submitted by:	Andriy Voskoboinyk <s3erios at gmail com>
Differential Revision:	https://reviews.freebsd.org/D3589
2015-09-08 07:53:10 +00:00
Kevin Lo
de7eb46ed4 - Remove empty key_update_* functions.
- Hide "struct ieee80211_node *" -> "struct run_node *" casting behind
  RUN_NODE() macro.
- Simplify IEEE80211_HAS_ADDR4 macro definition
- Fix a comment (desn't -> doesn't)

Submitted by:	Andriy Voskoboinyk <s3erios at gmail com>
Differential Revision:	https://reviews.freebsd.org/D3588
2015-09-08 07:50:35 +00:00
Gleb Smirnoff
7a79cebfba 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.
2015-08-27 08:56:39 +00:00
Adrian Chadd
d3fdd08cf3 Further conversions from ifp->if_softc -> ic_softc. 2015-08-20 05:13:54 +00:00
Adrian Chadd
3843c5e486 Remove some if_softc references from urtwn(4).
The only ones that are left are in if_start, if_stop and ioctl.

Tested:

* urtwn0: MAC/BB RTL8188CUS, RF 6052 1T1R, STA mode
2015-08-20 03:57:41 +00:00
Adrian Chadd
ba2c1fbc03 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.
2015-08-08 01:10:17 +00:00
Gleb Smirnoff
ad30bc5aec Fix mtx_assert() argument. 2015-08-07 16:23:16 +00:00
Gleb Smirnoff
79d2c5e857 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
2015-08-07 11:43:14 +00:00
Gleb Smirnoff
272f6ade9b 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.
2015-05-25 19:53:29 +00:00
Gleb Smirnoff
59686fe935 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.
2015-05-25 18:50:26 +00:00
Gleb Smirnoff
c8550c0278 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.
2015-05-25 13:51:13 +00:00
Kevin Lo
997d8c7a89 - Fix a wrong R92C_USTIME_TSF register definition
- Fix intitial transmit rate to an 11g rate for the RTL8188EU
- Add a comment about response rate settings
2015-05-08 09:01:00 +00:00