History log of /netbsd-current/sys/dev/ic/rtw.c
Revision (<<< Hide revision tags) (Show revision tags >>>) Date Author Comments
# 1.137 10-Nov-2021 msaitoh

s/desciptor/descriptor/ in comment.


Revision tags: thorpej-i2c-spi-conf2-base thorpej-futex2-base thorpej-cfargs2-base thorpej-i2c-spi-conf-base
# 1.136 16-Jun-2021 riastradh

if_attach and if_initialize cannot fail, don't test return value

These were originally made failable back in 2017 when if_initialize
allocated a softint in every interface for link state changes, so
that it could fail gracefully instead of panicking:

https://mail-index.NetBSD.org/source-changes/2017/10/23/msg089053.html

However, this spawned many seldom- or never-tested error branches,
which are risky to have around. And that softint in every interface
has since been replaced by a single global workqueue, because link
state changes require thread context but not low latency or high
throughput:

https://mail-index.NetBSD.org/source-changes/2020/02/06/msg113759.html

So there is no longer any reason for if_initialize to fail. (The
subroutine if_stats_init can't fail because percpu_alloc can't fail
either.)

There is a snag: the softint_establish in if_percpuq_create could
fail, potentially leading to bad consequences later on trying to use
the softint. This change doesn't introduce any new bugs because of
the snag -- if_percpuq_attach was already broken. However, the snag
can be better addressed without spawning error branches, either by
using a single softint or making softints less scarce.

(Separate commit will change the signatures of if_attach and
if_initialize to return void, scheduled to ride whatever is the next
convenient kernel bump.)

Patch and testing on amd64 and evbmips64-eb by maya@; commit message
soliloquy, and compile-testing on evbppc/i386/earmv7hf, by me.


Revision tags: cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 cjep_staticlib_x-base thorpej-cfargs-base thorpej-futex-base bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1 phil-wifi-20200411 bouyer-xenpvh-base is-mlppp-base phil-wifi-20200406 ad-namecache-base3
# 1.135 29-Jan-2020 thorpej

branches: 1.135.10;
Adopt <net/if_stats.h>.


Revision tags: ad-namecache-base2 ad-namecache-base1 ad-namecache-base phil-wifi-20191119
# 1.134 10-Nov-2019 chs

branches: 1.134.2;
in many device attach paths, allocate memory with M_WAITOK instead of M_NOWAIT
and remove code to handle failures that can no longer happen.


Revision tags: netbsd-9-2-RELEASE netbsd-9-1-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 netbsd-9-base phil-wifi-20190609
# 1.133 28-May-2019 msaitoh

Use ETHER_LOCK()/ETHER_UNLOCK() for all ethernet drivers to protect ec_multi*.


# 1.132 23-May-2019 msaitoh

Whitespace fix (mainly tabify).


# 1.131 23-May-2019 msaitoh

-No functional change:
- KNF
- u_int*_t -> uint*_t.


Revision tags: isaki-audio2-base
# 1.130 05-Feb-2019 msaitoh

Remove very old IFF_NOTRAILERS flag.


# 1.129 03-Feb-2019 mrg

- add or adjust /* FALLTHROUGH */ where appropriate
- add __unreachable() after functions that can return but won't in
this case, and thus can't be marked __dead easily


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 jdolecek-ncqfixes-base pgoyette-compat-0728 phil-wifi-base
# 1.128 26-Jun-2018 msaitoh

branches: 1.128.2;
Implement the BPF direction filter (BIOC[GS]DIRECTION). It provides backward
compatibility with BIOC[GS]SEESENT ioctl. The userland interface is the same
as FreeBSD.

This change also fixes a bug that the direction is misunderstand on some
environment by passing the direction to bpf_mtap*() instead of checking
m->m_pkthdr.rcvif.


Revision tags: pgoyette-compat-0625 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base tls-maxphys-base-20171202
# 1.127 23-Oct-2017 msaitoh

branches: 1.127.2;
If if_initialize() failed in the attach function, free resources and return.


Revision tags: matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base
# 1.126 23-May-2017 ozaki-r

branches: 1.126.2;
Apply deferred if_start to more drivers

And annotate some XXX_start as it runs in softint to clarify that
it doesn't need deferred if_start.


Revision tags: prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 nick-nhusb-base-20170204
# 1.125 02-Feb-2017 nonaka

wlan interfaces make interrupt routine running on softint context.

see http://mail-index.netbsd.org/tech-kern/2016/12/06/msg021281.html

tested device:
* ath at pci: AR5212, AR5424
* athn at pci: AR9287
* ipw at pci: 2100BG
* iwi at pci: 2915ABG
* iwm at pci: 3165, 7260, 8260
* iwn at pci: 4945, 6235
* ral at pci: RT2560
* rtwn at pci: RTL8192CE


Revision tags: bouyer-socketcan-base pgoyette-localcount-20170107 nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.124 15-Sep-2016 jdolecek

branches: 1.124.2;
remove last isolated islands using BUS_SPACE_BARRIER_SYNC and
BUS_SPACE_BARRIER_X_BEFORE_X - these were only ever defined for mips and ia64,
and never actually implemented even there


Revision tags: localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907
# 1.123 10-Jun-2016 ozaki-r

branches: 1.123.2;
Introduce m_set_rcvif and m_reset_rcvif

The API is used to set (or reset) a received interface of a mbuf.
They are counterpart of m_get_rcvif, which will come in another
commit, hide internal of rcvif operation, and reduce the diff of
the upcoming change.

No functional change.


Revision tags: nick-nhusb-base-20160529
# 1.122 16-May-2016 ozaki-r

Use M_GETCTX and M_SETCTX instead of open-coding rcvif

No functional change.


Revision tags: netbsd-7-2-RELEASE netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 netbsd-7-0-RELEASE nick-nhusb-base-20150921 netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 nick-nhusb-base-20150606 nick-nhusb-base-20150406 nick-nhusb-base netbsd-7-base yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 rmind-smpnet-nbase rmind-smpnet-base tls-maxphys-base
# 1.121 25-Feb-2014 pooka

branches: 1.121.6;
Ensure that the top level sysctl nodes (kern, vfs, net, ...) exist before
the sysctl link sets are processed, and remove redundancy.

Shaves >13kB off of an amd64 GENERIC, not to mention >1k duplicate
lines of code.


# 1.120 17-Oct-2013 christos

- remove unused variables
- move variables inside ifdef sections
- ifdef notdef unused code
- use __USE for debugging variables


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE yamt-pagecache-tag8 netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 agc-symver-base netbsd-6-1-RC2 netbsd-6-1-RC1 yamt-pagecache-base8 netbsd-6-0-1-RELEASE yamt-pagecache-base7 matt-nb6-plus-nbase yamt-pagecache-base6 netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base10 yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.119 04-Jul-2011 joerg

branches: 1.119.2; 1.119.12; 1.119.16;
Fix memset usage.


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base matt-mips64-premerge-20101231 rmind-uvmplock-base
# 1.118 15-Nov-2010 uebayasi

Socket ioctl definitions need sys/sockio.h.


# 1.117 13-Nov-2010 uebayasi

Don't pull in the whole uvm(9) API to access only PAGE_SIZE and
some other constants. These are provided by sys/param.h now.


Revision tags: uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10 uebayasi-xip-base1
# 1.116 05-Apr-2010 joerg

Push the bpf_ops usage back into bpf.h. Push the common ifp->if_bpf
check into the inline functions as well the fourth argument for
bpf_attach.


# 1.115 15-Mar-2010 dyoung

Make this compile on sparc64:

1 s/next_tick/next_tint/ because next_tick shadows a global on sparc64.

2 Fix the bus-barrier helper routines, which had the tag & handle
swapped (!!). Move the helpers from rtwreg.h to rtwvar.h, and
change RTW_BARRIER() into an inline subroutine called rtw_barrier().


Revision tags: yamt-nfs-mp-base9
# 1.114 24-Feb-2010 dyoung

branches: 1.114.2;
A pointer typedef entails trading too much flexibility to declare const
and non-const types, and the kernel uses both const and non-const
PMF qualifiers and device suspensors, so change the pmf_qual_t and
device_suspensor_t typedefs from "pointers to const" to non-pointer,
non-const types.


Revision tags: uebayasi-xip-base
# 1.113 31-Jan-2010 dyoung

branches: 1.113.2;
Add the missing newline to a verbose autoconf message.


# 1.112 19-Jan-2010 pooka

Redefine bpf linkage through an always present op vector, i.e.
#if NBPFILTER is no longer required in the client. This change
doesn't yet add support for loading bpf as a module, since drivers
can register before bpf is attached. However, callers of bpf can
now be modularized.

Dynamically loadable bpf could probably be done fairly easily with
coordination from the stub driver and the real driver by registering
attachments in the stub before the real driver is loaded and doing
a handoff. ... and I'm not going to ponder the depths of unload
here.

Tested with i386/MONOLITHIC, modified MONOLITHIC without bpf and rump.


# 1.111 08-Jan-2010 dyoung

Expand PMF_FN_* macros.


Revision tags: matt-premerge-20091211 jym-xensuspend-nbase
# 1.110 19-Oct-2009 rmind

Drop 3rd and 4th clauses from David Young's license.
Reviewed and approved by dyoung@ (copyright holder).


# 1.109 16-Sep-2009 dyoung

In pmf(9), improve the implementation of device self-suspension
and make suspension by self, by drvctl(8), and by ACPI system sleep
play nice together. Start solidifying some temporary API changes.

1. Extract a new header file, <sys/device_if.h>, from <sys/device.h> and
#include it from <sys/pmf.h> instead of <sys/device.h> to break the
circular dependency between <sys/device.h> and <sys/pmf.h>.

2. Introduce pmf_qual_t, an aggregate of qualifications on a PMF
suspend/resume call. Start to replace instances of PMF_FN_PROTO,
PMF_FN_ARGS, et cetera, with a pmf_qual_t.

3. Introduce the notion of a "suspensor," an entity that holds a
device in suspension. More than one suspensor may hold a device
at once. A device stays suspended as long as at least one
suspensor holds it. A device resumes when the last suspensor
releases it.

Currently, the kernel defines three suspensors,

3a the system-suspensor: for system suspension, initiated
by 'sysctl -w machdep.sleep_state=3', by lid closure, by
power-button press, et cetera,

3b the drvctl-suspensor: for device suspension by /dev/drvctl
ioctl, e.g., drvctl -S sip0.

3c the system self-suspensor: for device drivers that suspend
themselves and their children. Several drivers for network
interfaces put the network device to sleep while it is not
administratively up, that is, after the kernel calls if_stop(,
1). The self-suspensor should not be used directly. See
the description of suspensor delegates, below.

A suspensor can have one or more "delegates". A suspensor can
release devices that its delegates hold suspended. Right now,
only the system self-suspensor has delegates. For each device
that a self-suspending driver attaches, it creates the device's
self-suspensor, a delegate of the system self-suspensor.

Suspensors stop a system-wide suspend/resume cycle from waking
devices that the operator put to sleep with drvctl before the cycle.
They also help self-suspension to work more simply, safely, and in
accord with expectations.

4. Add the notion of device activation level, devact_level_t,
and a routine for checking the current activation level,
device_activation(). Current activation levels are DEVACT_LEVEL_BUS,
DEVACT_LEVEL_DRIVER, and DEVACT_LEVEL_CLASS, which respectively
indicate that the device's bus is active, that the bus and device are
active, and that the bus, device, and the functions of the device's
class (network, audio) are active.

Suspend/resume calls can be qualified with a devact_level_t.
The power-management framework treats a devact_level_t that
qualifies a device suspension as the device's current activation
level; it only runs hooks to reduce the activation level from
the presumed current level to the fully suspended state. The
framework treats a devact_level_t qualifying device resumption
as the target activation level; it only runs hooks to raise the
activation level to the target.

5. Use pmf_qual_t, devact_level_t, and self-suspensors in several
drivers.

6. Temporarily add an unused power-management workqueue that I will
remove or replace, soon.


Revision tags: yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5 yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 nick-hppapmap-base3 jym-xensuspend-base nick-hppapmap-base
# 1.108 07-Apr-2009 dyoung

Cosmetic: remove some dead code.


# 1.107 02-Apr-2009 dyoung

Add the WEP capability to our net80211 capability flags, since we do
sort of support hardware WEP. Only change the WEP key index in a Tx
descriptor from 0 if the type of our transmit key is _WEP, not _TKIP:
i.e., only if we're really doing WEP crypto in the hardware.

Ignore a watchdog timeout on any Tx ring if we can collect some packets
from that ring. Restart both the receiver and the transmitter when a
watchdog timeout occurs instead of restarting only the transmitter.


Revision tags: nick-hppapmap-base2 haad-dm-base2 haad-nbase2 ad-audiomp2-base haad-dm-base mjf-devfs2-base
# 1.106 12-Nov-2008 ad

branches: 1.106.4;
Remove LKMs and switch to the module framework, pass 1.

Proposed on tech-kern@.


# 1.105 07-Nov-2008 dyoung

*** Summary ***

When a link-layer address changes (e.g., ifconfig ex0 link
02:de:ad:be:ef:02 active), send a gratuitous ARP and/or a Neighbor
Advertisement to update the network-/link-layer address bindings
on our LAN peers.

Refuse a change of ethernet address to the address 00:00:00:00:00:00
or to any multicast/broadcast address. (Thanks matt@.)

Reorder ifnet ioctl operations so that driver ioctls may inherit
the functions of their "class"---ether_ioctl(), fddi_ioctl(), et
cetera---and the class ioctls may inherit from the generic ioctl,
ifioctl_common(), but both driver- and class-ioctls may override
the generic behavior. Make network drivers share more code.

Distinguish a "factory" link-layer address from others for the
purposes of both protecting that address from deletion and computing
EUI64.

Return consistent, appropriate error codes from network drivers.

Improve readability. KNF.

*** Details ***

In if_attach(), always initialize the interface ioctl routine,
ifnet->if_ioctl, if the driver has not already initialized it.
Delete if_ioctl == NULL tests everywhere else, because it cannot
happen.

In the ioctl routines of network interfaces, inherit common ioctl
behaviors by calling either ifioctl_common() or whichever ioctl
routine is appropriate for the class of interface---e.g., ether_ioctl()
for ethernets.

Stop (ab)using SIOCSIFADDR and start to use SIOCINITIFADDR. In
the user->kernel interface, SIOCSIFADDR's argument was an ifreq,
but on the protocol->ifnet interface, SIOCSIFADDR's argument was
an ifaddr. That was confusing, and it would work against me as I
make it possible for a network interface to overload most ioctls.
On the protocol->ifnet interface, replace SIOCSIFADDR with
SIOCINITIFADDR. In ifioctl(), return EPERM if userland tries to
invoke SIOCINITIFADDR.

In ifioctl(), give the interface the first shot at handling most
interface ioctls, and give the protocol the second shot, instead
of the other way around. Finally, let compatibility code (COMPAT_OSOCK)
take a shot.

Pull device initialization out of switch statements under
SIOCINITIFADDR. For example, pull ..._init() out of any switch
statement that looks like this:

switch (...->sa_family) {
case ...:
..._init();
...
break;
...
default:
..._init();
...
break;
}

Rewrite many if-else clauses that handle all permutations of IFF_UP
and IFF_RUNNING to use a switch statement,

switch (x & (IFF_UP|IFF_RUNNING)) {
case 0:
...
break;
case IFF_RUNNING:
...
break;
case IFF_UP:
...
break;
case IFF_UP|IFF_RUNNING:
...
break;
}

unifdef lots of code containing #ifdef FreeBSD, #ifdef NetBSD, and
#ifdef SIOCSIFMTU, especially in fwip(4) and in ndis(4).

In ipw(4), remove an if_set_sadl() call that is out of place.

In nfe(4), reuse the jumbo MTU logic in ether_ioctl().

Let ethernets register a callback for setting h/w state such as
promiscuous mode and the multicast filter in accord with a change
in the if_flags: ether_set_ifflags_cb() registers a callback that
returns ENETRESET if the caller should reset the ethernet by calling
if_init(), 0 on success, != 0 on failure. Pull common code from
ex(4), gem(4), nfe(4), sip(4), tlp(4), vge(4) into ether_ioctl(),
and register if_flags callbacks for those drivers.

Return ENOTTY instead of EINVAL for inappropriate ioctls. In
zyd(4), use ENXIO instead of ENOTTY to indicate that the device is
not any longer attached.

Add to if_set_sadl() a boolean 'factory' argument that indicates
whether a link-layer address was assigned by the factory or some
other source. In a comment, recommend using the factory address
for generating an EUI64, and update in6_get_hw_ifid() to prefer a
factory address to any other link-layer address.

Add a routing message, RTM_LLINFO_UPD, that tells protocols to
update the binding of network-layer addresses to link-layer addresses.
Implement this message in IPv4 and IPv6 by sending a gratuitous
ARP or a neighbor advertisement, respectively. Generate RTM_LLINFO_UPD
messages on a change of an interface's link-layer address.

In ether_ioctl(), do not let SIOCALIFADDR set a link-layer address
that is broadcast/multicast or equal to 00:00:00:00:00:00.

Make ether_ioctl() call ifioctl_common() to handle ioctls that it
does not understand.

In gif(4), initialize if_softc and use it, instead of assuming that
the gif_softc and ifp overlap.

Let ifioctl_common() handle SIOCGIFADDR.

Sprinkle rtcache_invariants(), which checks on DIAGNOSTIC kernels
that certain invariants on a struct route are satisfied.

In agr(4), rewrite agr_ioctl_filter() to be a bit more explicit
about the ioctls that we do not allow on an agr(4) member interface.

bzero -> memset. Delete unnecessary casts to void *. Use
sockaddr_in_init() and sockaddr_in6_init(). Compare pointers with
NULL instead of "testing truth". Replace some instances of (type
*)0 with NULL. Change some K&R prototypes to ANSI C, and join
lines.


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 wrstuden-revivesa-base-1 simonb-wapbl-nbase yamt-pf42-base4 simonb-wapbl-base yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 yamt-nfs-mp-base2 wrstuden-revivesa-base yamt-nfs-mp-base yamt-pf42-base ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 1.104 15-Mar-2008 dyoung

branches: 1.104.4; 1.104.10; 1.104.12;
Cosmetic: make rtw_hw_keysupp() return a bool instead of int. In
rtw_wep_setkeys(), add a debug printf, and move the initialization
of keylen from the for-loop to the declaration.


# 1.103 14-Mar-2008 dyoung

Extract subroutine rtw_tx_kick() from rtw_start(), and reuse it in
rtw_io_enable() to restart the transmitter after resetting it.


# 1.102 14-Mar-2008 dyoung

Change tests for "impossible" keys to KASSERT()s. Get rid of a
temporary variable. In rtw_key_delete(), do not invalidate the
hardware keys unless a WEP key is deleted.


# 1.101 12-Mar-2008 dyoung

Use device_t and its accessors throughout. Use aprint_*_dev().

Improve PMF-ability.

Add a 'flags' argument to suspend/resume handlers and
callers such as pmf_system_suspend().

Define a flag, PMF_F_SELF, which indicates to PMF that a
device is suspending/resuming itself. Add helper routines,
pmf_device_suspend_self(dev) and pmf_device_resume_self(dev),
that call pmf_device_suspend(dev, PMF_F_SELF) and
pmf_device_resume(dev, PMF_F_SELF), respectively. Use
PMF_F_SELF to suspend/resume self in ath(4), audio(4),
rtw(4), and sip(4).

In ath(4) and in rtw(4), replace the icky sc_enable/sc_disable
callbacks, provided by the bus front-end, with
self-suspension/resumption. Also, clean up the bus
front-ends. Make sure that the interrupt handler is
disestablished during suspension. Get rid of driver-private
flags (e.g., RTW_F_ENABLED, ath_softc->sc_invalid); use
device_is_active()/device_has_power() calls, instead.

In the network-class suspend handler, call if_stop(, 0)
instead of if_stop(, 1), because the latter is superfluous
(bus- and driver-suspension hooks will 'disable' the NIC),
and it may cause recursion.

In the network-class resume handler, prevent infinite
recursion through if_init() by getting out early if we are
self-suspending (PMF_F_SELF).

rtw(4) improvements:

Destroy rtw(4) callouts when we detach it. Make rtw at
pci detachable. Print some more information with the "rx
frame too long" warning.

Remove activate() methods:

Get rid of rtw_activate() and ath_activate(). The device
activate() methods are not good for much these days.

Make ath at cardbus resume with crypto functions intact:

Introduce a boolean device property, "pmf-powerdown". If
pmf-powerdown is present and false, it indicates that a
bus back-end should not remove power from a device.

Honor this property in cardbus_child_suspend().

Set this property to 'false' in ath_attach(), since removing
power from an ath at cardbus seems to lobotomize the WPA
crypto engine. XXX Should the pmf-powerdown property
propagate toward the root of the device tree?

Miscellaneous ath(4) changes:

Warn if ath(4) tries to write crypto keys to suspended
hardware.

Reduce differences between FreeBSD and NetBSD in ath(4)
multicast filter setup.

Make ath_printrxbuf() print an rx descriptor's status &
key index, to help debug crypto errors.

Shorten a staircase in ath_ioctl(). Don't check for
ieee80211_ioctl() return code ERESTART, it never happens.


# 1.100 12-Mar-2008 dyoung

Print the TPPoll register when the Tx DMA engine doesn't shut down
in the time we allow.


# 1.99 03-Mar-2008 tsutsui

Explicitly include <sys/device.h> for device_t.


Revision tags: nick-net80211-sync-base vmlocking2-base3 bouyer-xeni386-nbase bouyer-xeni386-base mjf-devfs-base matt-armv6-base hpcarm-cleanup-base
# 1.98 21-Dec-2007 dyoung

branches: 1.98.2; 1.98.6;
Do not embed a struct device in rtw_softc any longer. Register
both pci and cardbus attachments with CFATTACH_DECL_NEW(). Access
the softc through the device_t using device_private().

While I'm here, change a couple of KASSERT()s about the Rx buffer
length to a warning.


# 1.97 20-Dec-2007 dyoung

Remove shutdown hooks. Use KASSERT().


# 1.96 16-Dec-2007 dyoung

Fix a bug I introduced to rtw_chan2txpower() the other night.

Fix a bug in device detachment: change a break statement to a
/*FALLTHROUGH*/ in rtw_detach().


# 1.95 16-Dec-2007 dyoung

Synchronize device detachment with network interrupts. Use the
pmf network class instead of powerhooks.


Revision tags: yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 bouyer-xenamd64-base2 vmlocking-nbase bouyer-xenamd64-base jmcneill-pm-base reinoud-bufcleanup-base
# 1.94 18-Nov-2007 jnemeth

branches: 1.94.2; 1.94.6;
fix 'm' used unitialized


# 1.93 16-Nov-2007 dyoung

Accommodate the variety of RF front-ends when radiotapping frames:
tap only RSSI when there is a Philips RF front-end. Tap both Barker
lock quality and RSSI when there is any other RF front-end.

Provide radiotap listeners a more complete picture of channel
activity:

in promiscuous mode, tap frames who do not pass the CRC32 check.
Flag packets that were received with a short preamble. Ask
the NIC to pass us 802.11 Control frames. Pass frames to
radiotap listeners before stripping the FCS. Re-order operations
in rtw_intr_rx() in order to accomplish all of this, taking
care not to pass a broken packet to net80211!

Do not provide a flags field when tapping xmitted frames.

Assert sane Rx packet lengths. Really should check and drop instead
of KASSERTing. I will revisit this, soon.

Update copyright.


# 1.92 15-Nov-2007 dyoung

Fix order of operations:

rtw_rxdesc_init: before initializing a Rx descriptor's
control word, synchronize the Rx buffer

rtw_start, be paranoid: set the "NIC owns" bit on a Tx
descriptor dead last. Always reinitialize the "next
Tx descriptor" pointer, just in case it got clobbered
somehow.

Let the compiler decide whether to inline rtw_collect_txring or
not.


Revision tags: jmcneill-base
# 1.91 19-Oct-2007 ad

branches: 1.91.2;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h


Revision tags: yamt-x86pmap-base4 yamt-x86pmap-base3 yamt-x86pmap-base2 vmlocking-base
# 1.90 29-Sep-2007 scw

branches: 1.90.2;
s/NPBFILTER/NBPFILTER/ in some #endif comments. No functional change.


Revision tags: nick-csl-alignment-base5 yamt-x86pmap-base matt-mips64-base nick-csl-alignment-base mjf-ufs-trans-base
# 1.89 09-Jul-2007 ad

branches: 1.89.6; 1.89.8; 1.89.10;
Merge some of the less invasive changes from the vmlocking branch:

- kthread, callout, devsw API changes
- select()/poll() improvements
- miscellaneous MT safety improvements


# 1.88 29-May-2007 dyoung

Fix rtw(4) on NetBSD/macppc: use bus_space_write_region_stream_4()
instead of bus_space_write_region_4() to write WEP Rx keys to the
NIC. Thanks macallan@ for detecting the bug and testing the fix.


# 1.87 29-May-2007 dyoung

Cosmetic: simplify a memset() statement, use __arraycount(), and
remove a gratuitous return statement at the end of a void subroutine.


# 1.86 29-May-2007 dyoung

Simplify multicast filter programming, and take care to avoid
gratuitous device resets when the kernel adds/deletes a multicast
address.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base
# 1.85 04-Mar-2007 christos

branches: 1.85.2; 1.85.4;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.


Revision tags: ad-audiomp-base post-newlock2-merge newlock2-nbase newlock2-base
# 1.84 29-Jan-2007 dyoung

branches: 1.84.2;
In rtw_dequeue(), initialize *mp to NULL before anything else, so
that it is either NULL or a valid mbuf. Previously, it was possible
for rtw_dequeue() to exit with 0 before initializing *mp. rtw_start()
would have used whatever trash was in *mp, which would lead to
problems later on.


# 1.83 06-Jan-2007 dyoung

I have made a small change that suppresses "recovery" from (spurious?)
tx timeouts on the beacon queue. The driver's recovery process
badly disrupts the MAC's receiver. This needs a closer look, later.

Every other fix is by Charles M. Hannum. Charles writes:

"With these, the device is quite stable under load, does not experience
xmit timeouts, no longer mysteriously freezes, and does not spew
a lot of garbage. It does, however, continue to get some "tx fifo
underflow"s.

global, SYSCTL_SETUP():
a) Removed unused sysctl variables.

rtw_io_enable():
b) Change rtw_io_enable to take a softc, and make it call
rtw_txring_fixup().
c) Enable the PCI multiple read/write bit.
d) Always reset rdb_next to 0 when starting the receive engine.

rtw_intr_rx():
e) When processing receive packets, store the next pointer in rdb_next
and read it back on the next round, to fix a race condition vs.
rtw_tune() during AP discovery and association.
f) Remove the special "skip to 0th descriptor" code, because it is no
longer needed.

rtw_collect_txring():
g) In the "force" case, stop when we catch up to the hardware xmit
pointer.

rtw_intr_beacon():
h) Resetting tdb_next here looked fishy to me, in light of changes in
rtw_collect_txring(). XXX However, this is the one part I haven't
tested.

rtw_txring_fixup():
i) Add function and line arguments, so we can print out information
about the caller.
j) In addition to reading the hardware pointer, skip over any
additional packets with OWN set -- we may have queued more.

rtw_rxring_fixup():
k) Remove this, because it's completely wrong.

rtw_intr_ioerror():
l) Don't handle receive overruns here; handle them in the normal receive
path. Also changed RTW_INTR_RX and RTW_INTR_IOERROR accordingly.
m) Do not fiddle with CR; the transmit engine is still running just
fine.
n) Do not fiddle with IMR; it was unnecessary.
o) Don't touch the receive engine at all; not necessary now that we're
leaving CR alone.
p) Remove the rtw_do_chip_reset case; it was dangerous and not actually
used.

rtw_intr():
q) Don't mask off ISR bits when we pass down the ISR value; it's not
necessary, and sometimes the other bits useful in debugging output.

rtw_seg_too_short():
r) Don't spew here; the caller will do it if necessary. (Stops spewage
in an expected case.)

rtw_rxdesc_blk:
s) Minor change to make the elements have the same order as txdesc_blk.

general:
t) Added a bunch of debugging output, #ifdef RTW_DIAG, that was useful
while investigating the ring management problems. Also moved
rtw_txring_fixup() into RTW_DIAG, as I believe the transmit pointer
is always kept in sync now, and the function has potential race
conditions.


# 1.82 06-Jan-2007 dyoung

After we examine a rx/tx descriptor and find that it's still owned
by the NIC, re-sync the descriptor so that a cacheline will not
"cover" the NIC's modifications to the descriptor when we next
examine it.

This compiles, but I have not tested it, yet.


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase wrstuden-fixsa-base-1 netbsd-4-0-RELEASE netbsd-4-0-RC5 matt-nb4-arm-base netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 wrstuden-fixsa-base yamt-splraiseipl-base5 yamt-splraiseipl-base4 yamt-splraiseipl-base3 netbsd-4-base
# 1.81 16-Nov-2006 christos

__unused removal on arguments; approved by core.


# 1.80 13-Nov-2006 dyoung

Stop using typeof() in the bit-twiddling macros, per yamt@'s
suggestion. This change requires that I use the __PRIuBITS format
string in atw and rtw, so do that.


Revision tags: yamt-splraiseipl-base2
# 1.79 12-Oct-2006 xtraeme

Use __unused in function arguments where appropiate.


# 1.78 12-Oct-2006 christos

- sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386


# 1.77 24-Sep-2006 jmcneill

Add "name" parameter to powerhook_establish, to aid debugging. No objections
on tech-kern@


Revision tags: yamt-splraiseipl-base yamt-pdpolicy-base9 yamt-pdpolicy-base8 rpaulo-netinet-merge-pcb-base
# 1.76 03-Sep-2006 christos

branches: 1.76.2; 1.76.4;
- comment out impossible comparisons
- remove superfluous if statement


# 1.75 31-Aug-2006 dyoung

Per discussion on tech-kern and tech-userlevel, move the bit-twiddling
macros, __BIT, __BITS, SHIFTIN, SHIFTOUT, and __arraycount() from
lib/libkern/libkern.h to sys/cdefs.h. Add a __-prefix to SHIFTIN
and SHIFTOUT, and add a manual page for the bit-twiddling macros,
bits(3).

Make the __BIT and __BITS macros "widthless," as best I can, by
changing their type to uintmax_t from uint32_t. XXX The manual
page lags this change by a bit.

Define __PRIxBIT and __PRIxBITS printf(3) format strings.


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base7 yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base simonb-timecounters-base
# 1.74 26-May-2006 blymn

Clean up bogus whitespace


Revision tags: yamt-pdpolicy-base5
# 1.73 14-May-2006 christos

branches: 1.73.2;
XXX: GCC uninitialized


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 elad-kernelauth-base
# 1.72 28-Mar-2006 dyoung

Revamp ieee80211_get_rate. Now it does not use the rateset in the
ic->ic_bss, but it uses the rateset in its new ieee80211_node
argument, instead. If the rate is fixed by ic->ic_fixed_rate, but
the fixed rate is not in the node's rateset, choose a reasonable
default: prefer the lowest basic rate or, if there is no basic
rate, prefer the lowest rate, period.

Change a printf complaint to a debug message.

Adapt drivers to suit new ieee80211_get_rate calling convention.

XXX I really need to replace ieee80211_get_rate with a bitrate
XXX adaptation algorithm. Soon, soon....


# 1.71 27-Mar-2006 dyoung

Set the channel frequency and flags in the radiotap headers in
rtw_tune instead of in rtw_start, rtw_intr_rx.


# 1.70 27-Mar-2006 dyoung

Remove unused argument ifflagsp from rtw_dmamap_load_txbuf.


Revision tags: peter-altq-base yamt-pdpolicy-base2
# 1.69 08-Mar-2006 dyoung

branches: 1.69.2;
Change macro names to avoid collisions:

BIT -> __BIT
BITS -> __BITS


# 1.68 08-Mar-2006 dyoung

Move my bit-twiddling macros to libkern.h from my drivers, where
I had duplicated them. Improve the macros' names. Simplify their
implementation.

A brief description of each macro is below.

BIT(n): Return a bitmask with bit m set, where the least
significant bit is bit 0.

BITS(m, n): Return a bitmask with bits m through n, inclusive,
set. It does not matter whether m>n or m<=n.
The least significant bit is bit 0.

A "bitfield" is a span of consecutive bits defined by a
bitmask, where 1s select the bits in the bitfield. SHIFTIN,
SHIFTOUT, and SHIFTOUT_MASK help read and write bitfields
from device registers.

SHIFTIN(v, mask): Left-shift bits `v' into the bitfield
defined by `mask', and return them. No
side-effects.

SHIFTOUT(v, mask): Extract and return the bitfield selected
by `mask' from `v', right-shifting the
bits so that the rightmost selected bit
is at bit 0. No side-effects.

SHIFTOUT_MASK(mask): Right-shift the bits in `mask' so that
the rightmost non-zero bit is at bit
0. This is useful for finding the
greatest unsigned value that a bitfield
can hold. No side-effects. Note that
SHIFTOUT_MASK(m) = SHIFTOUT(m, m).

Examples:

/*
* Register definitions taken from the RFMD RF3000 manual.
*/
#define RF3000_GAINCTL 0x11 /* TX variable gain control */
#define RF3000_GAINCTL_TXVGC_MASK BITS(7, 2)
#define RF3000_GAINCTL_SCRAMBLER BIT(1)

/*
* Shift the transmit power into the transmit-power field of the
* gain-control register and write it to the baseband processor.
*/
atw_rf3000_write(sc, RF3000_GAINCTL,
SHIFTIN(txpower, RF3000_GAINCTL_TXVGC_MASK));


/*
* Register definitions taken from the ADMtek ADM8211 manual.
*
*/
#define ATW_RXSTAT_OWN BIT(31) /* 1: NIC may fill descriptor */
/* ... */
#define ATW_RXSTAT_DA1 BIT(17) /* DA bit 1, admin'd address */
#define ATW_RXSTAT_DA0 BIT(16) /* DA bit 0, group address */
#define ATW_RXSTAT_RXDR_MASK BITS(15,12) /* RX data rate */
#define ATW_RXSTAT_FL_MASK BITS(11,0) /* RX frame length, last
* descriptor only
*/

/* Extract the frame length from the Rx descriptor's
* status field.
*/
len = SHIFTOUT(rxstat, ATW_RXSTAT_FL_MASK);


Revision tags: yamt-pdpolicy-base yamt-uio_vmspace-base5
# 1.67 20-Feb-2006 thorpej

branches: 1.67.2; 1.67.4;
Use device_is_active() rather than testing dv_flags for DVF_ACTIVE
directly.


# 1.66 19-Feb-2006 dyoung

When rtw_enable is called, power may have been removed and re-applied,
so invalidate the WEP key registers to force us to write the keys
back to the hardware.

Revamp key handling: use the hardware WEP engine for 40-bit and
104-bit keys, only; use software WEP for all other key lengths.
Set the hardware key length to the length of the default Tx key,
or if there is no default Tx key, use the length of the longest
WEP key.


# 1.65 04-Feb-2006 dyoung

In rtw_{rx,tx}ring_fixup, do not set the tx/rx ring index to
something out of bounds if we read an invalid pointer form the
hardware. Prevents a panic when an rtw@cardbus is ejected.


# 1.64 29-Dec-2005 dyoung

branches: 1.64.2; 1.64.4; 1.64.6;
Add support for the GCT Semiconductor GRF5101 transceiver/synthesizer.
From OpenBSD.

GCT will not provide any documentation, so there are many magic
numbers in this code.


# 1.63 29-Dec-2005 dyoung

Update rtw(4) for the new IBSS merge idiom, where ieee80211_ibss_merge()
does not return ENETRESET if the driver should change its BSSID,
but it makes a RUN->RUN transition, instead.


# 1.62 29-Dec-2005 dyoung

In atw(4), use ieee80211_compute_duration() to compute IEEE 802.11
Duration and PLCP Length fields, and delete the abominable
atw_frame_setdurs() subroutine.

Make rtw(4) use the new ieee80211_compute_duration() calling
convention.

Add an ieee80211_key argument to ieee80211_compute_duration() and
lightly constify arguments. Get the crypto header length from the
key argument instead of blithely assuming a WEP header. Add some
inline documentation. Account for data padding (IEEE80211_F_DATAPAD).


# 1.61 24-Dec-2005 perry

Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.


# 1.60 13-Dec-2005 dyoung

Fix comments and debug printfs: Tx FIFOs underflow, they don't
overflow.


# 1.59 13-Dec-2005 dyoung

On a transmit FIFO overflow (err, actually an underflow...) reset
both the transmit & receive sections of the MAC.


Revision tags: yamt-readahead-base3 ktrace-lwp-base
# 1.58 23-Nov-2005 dyoung

Miscellaneous Realtek RTL8180L driver improvements:

1 Added new sysctl controls for debugging.

2 Improve detection & support for hardware WEP.

3 Revamp handling of transmit descriptor rings.

4 Reliably IFF_OACTIVE when transmit descriptors are available, to
stop the transmit section of the driver from freezing up.

5 Fix beacon transmission in adhoc and hostap modes. XXX There is
a wart in hostap mode, where beacons are transmitted at 1/2 the
correct rate. Load beacon descriptors when the RTW_INTR_BINT
interrupt arrives; schedule RTW_INTR_BINT 1ms ahead of the target
beacon time.

6 Recover more gracefully from tx/rx errors: avoid
transmitter/receiver/chip resets. Try to re-synchronize software
state with hardware state---e.g., load next descriptor pointer
from hardware.

7 Activate the transmit watchdog timer for beacons as well as other
packets.

8 Introduce rtw_idle() that waits for transmit DMA to finish; call
it before resetting the transmitter.


Revision tags: yamt-readahead-base2
# 1.57 18-Nov-2005 skrll

Adapt drivers to the new net80211(9).

Most of this is from dyoung@. Thanks!


Revision tags: yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base
# 1.56 22-Sep-2005 gdt

branches: 1.56.6;
Make arg of IFQ_SET_READY be &ifp->if_snd, to match all other drivers
and be compilable with altq enabled. Reviewed by dyoung@


# 1.55 07-Sep-2005 dogcow

With the assistance of dyoung, fix the following problems:
* some 8180L cards need a longer time for the srom to initialize; patch
suggested via OpenBSD.
* some cards give '0' for USA, some give '3'; for the meantime, accept both
as being USA locale cards.
* this is RTW, not ATW. :)


# 1.54 06-Sep-2005 dogcow

make rtw.c compile again after the 22-jun-05 net80211 import


# 1.53 11-Jul-2005 dyoung

Add undefined variable 'ic' to rtw_attach.


# 1.52 06-Jul-2005 dyoung

Historically, an(4), ath(4), atw(4), rtw(4), and wi(4) have printed
out their modes and rates at boot. Revert to the historical
behavior.


# 1.51 06-Jul-2005 dyoung

Avoid an unnecessary API difference between NetBSD and FreeBSD:
back out my change to ieee80211_crypto_encap that made it free its
mbuf argument on error. I had thought it was a bug. It was not.
It's the drivers that are broken. Make an(4), atw(4), ipw(4),
iwi(4), ral(4), rtw(4), ural(4), and wi(4) free the mbuf when
ieee80211_crypto_encap returns NULL. Also, return ath(4) to the
way it was---i.e., free the mbuf.

Thanks to Sam Leffler to pointing out my mistake.


# 1.50 28-Jun-2005 dyoung

branches: 1.50.2;
Here is a grotty hack that lets the RTL8180L handle WEP in the
receive direction, while software handles WEP in the transmit
direction. When net80211 calls rtw's rtw_key_set with a WEP key,
I point the key's wk_cipher at our "fake" cipher, rtw_cipher_wep,
which is alike to ieee80211_cipher_wep except it provides a different
crypto-decapsulation routine, rtw_wep_decap. rtw_wep_decap copies
the key passed to it by net80211, clears the key's SWCRYPT flag,
and then calls wep_decap. Now wep_decap will decapsulate, but it
will *not* re-decrypt.

XXX I need to check whether the hardware supports 40-bit WEP,
XXX 104-bit WEP, or both, and act accordingly.


# 1.49 27-Jun-2005 dyoung

rtw: Try to get hardware WEP to work. It seems to work in
the RX direction, but not in the TX direction. The
net80211 crypto framework doesn't seem to cope very well
with the assymetry (I'm probably missing something), so
I will use software WEP for now.

net80211: In ieee80211_compute_duration, figure out whether to add
the WEP header to the packet overhead by checking the
WEP bit in the Frame Control field of the 802.11 header,
instead of checking the IEEE80211_F_PRIVACY flag.

Also, if the WEP bit is present, assume that the frame
described by (wh, len) has already already been WEP
encapsulated, and adjust the payload length accordingly.
XXX that's a grotty hack that I will have to revisit,
later.


# 1.48 22-Jun-2005 dyoung

Resolve conflicts in importation of 18-May-2005 ath(4) / net80211(9)
from FreeBSD. Introduce compatibility shims (sys/dev/ic/ath_netbsd.[ch],
sys/net80211/ieee80211_netbsd.[ch]). Update drivers (an, atu, atw,
awi, ipw, iwi, rtw, wi) for the new net80211(9) API.


# 1.47 20-Jun-2005 atatat

Change the rest of the sysctl subsystem to use const consistently.
The __UNCONST macro is now used only where necessary and the RW macros
are gone. Most of the changes here are consumers of the
sysctl_createv(9) interface that now takes a pair of const pointers
which used not to be.


# 1.46 10-Jun-2005 dyoung

Sprinkle __UNCONST() and rename variables to quiet uiet -Wcast-qual,
-Wshadow complaints.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 yamt-km-base4 yamt-km-base3 netbsd-3-base kent-audio2-base
# 1.45 02-Mar-2005 dyoung

Misc. changes to improve ad hoc mode and to enable hostap mode:

Fix the work-around for the NIC bug where it skips to rx
descriptor 0. The driver used to skip to rx descriptor 1.
Hopefully this stops the out-of-order packet reception that
Charles Hannum saw.
When debugging is enabled, print rx-descriptor status flags
before printing the rx bit rate.

Add a debug message for when a beacon tx buffer reclamation.

Reset IFF_OACTIVE when we reset the transmitter.

Pass the consolidated LED state, a struct rtw_led_state,
to rtw_led_attach.

Choose the bit-rate for management frames (1Mb/s) at the
same place we choose for all other frames.

Do not use the NIC's short preamble or RTS options for
management frames. Label beacons for the NIC.

Following a Linux driver, take care not to zero arbitrary
bits in the TPPOLL register.

Use the new idiom for IBSS merges: disable transmitter,
kick the state machine.
Add a second descriptor to the beacon ring. The NIC seems
to like this much better.


# 1.44 27-Feb-2005 perry

nuke trailing whitespace


Revision tags: yamt-km-base2
# 1.43 31-Jan-2005 thorpej

Eliminate use of M_HASFCS.


Revision tags: yamt-km-base
# 1.42 16-Jan-2005 dyoung

branches: 1.42.2; 1.42.4;
Move the register access mode into struct rtw_regs. Change
rtw_set_access, rtw_set_access1 to match.

Add a subroutine for setting WEP keys. WEP isn't quite finished,
because I have to add the WEP header to Tx packets. Implement the
SIOCS80211NWKEY ioctl for setting WEP keys.

Program the LEDs based on operating state and packet activity.

* On a Revision F RTL8180, blink LED1 at 1Hz to indicate
scan/authenticate/associate states. In the run state, turn LED1
on. In every state, blink LED1 at 5Hz to indicate non-beacon
tx/rx activity. I would like to use two LEDs, but in all my
Rev. F instances, LED0 is not wired to an LED; instead, the
first LED is wired to indicate that the card's power is on.

* On a Revision D RTL8180, program the LEDs so that LED0 indicates
Tx, and LED1 indicates Rx. The Rx LED will blink annoyingly if
there are beacons in the air, but at least the Tx LED is useful.

* Store the hardware revision in the softc to support my futile
attempt at programming LEDs for both Rev. D and Rev. F parts;
I never did get Rev. D LEDs to work right.

* Add a debug flag RTW_DEBUG_LED for the LED transitions.

Add RTW_TPPOLL_ALL, RTW_TPPOLL_SALL to start and stop, respectively,
all of the transmit rings.

In ad hoc mode, allocate a beacon and load it into the beacon ring.
Start the ring. In one trial, the card re-transmitted the beacon
ring's contents several times before stopping. More programming
and testing for ad hoc mode is necessary. I'm not setting the
beacon flag in the transmit descriptor.

Revamp the transmit section to make better use of all the transmit
rings: beacon queue, high-, low-, and medium-priority rings. Put
beacon frames on the beacon ring. All other management frames,
and data frames, go on the medium-priority ring. Power-save data
frames go on the high-priority ring. (Note that powersaving is
not implemented!) This is a work in progress.

Send all 802.11 Management frames at 1Mbps.

After we put a packet on a transmit ring, tickle the right bit in
the TPPOLL to tell RTL8180. Stop all rings on error and in rtw_stop.

Use the RF chip type, not the RTL8180 revision, to choose between
host- and MAC-controlled RF serial I/O. Now the Netgear MA521
works.

Remove bogus definition of bit RTW_TPPOLL_FSWINT.


Revision tags: kent-audio1-beforemerge
# 1.41 04-Jan-2005 dyoung

Set initial conditions to guarantee that when read_seeprom toggles
Chip Select, it turns *on* rather than *off*.


# 1.40 04-Jan-2005 dyoung

Add the logic for IBSS merges.


# 1.39 03-Jan-2005 dyoung

sys/dev/ic/rtw.c:

Cosmetic: remove two short ladders from rtw_init. Fit the
NIC registers print-out onto one line using the RTW_PRINT_REGS
macro.

sys/dev/ic/rtwvar.h:

Add RTW_PRINT_REGS wrapper macro for rtw_print_regs. It
is a null op unless defined(RTW_DEBUG).


# 1.38 03-Jan-2005 dyoung

In sys/dev/ic/rtw.c:

Use clue from rtk(4) and re(4) to fix the rtw(4) packet
filter. Previously, I was using the wrong CRC32 function
to hash multicast addresses; to compensate, I set the
multicast filter to all 1s. Now that I hash the addresses
correctly, I do not any longer set the filter to all 1s.

In rtw_ioctl, avoid gratuitous re-initialization when the
interface flags change. If a !IFF_UP -> IFF_UP transition,
call rtw_init(); otherwise, only reload the packet filter.

In sys/dev/ic/rtwreg.h:

Put useful combinations of Receiver Control Register flags
in RTW_RCR_PKTFILT_MASK, RTW_RCR_MONITOR, and
RTW_RCR_PKTFILT_DEFAULT. (XXX RTW_RCR_MONITOR should be
called RTW_RCR_PKTFILT_MONITOR.)


# 1.37 02-Jan-2005 dyoung

Cosmetic: change u_int{8,16,32,64}_t to C99-style uint{8,16,32,64}_t,
which is preferred.


# 1.36 29-Dec-2004 dyoung

In rtw_detach, flag the rtw as "invalid" (RTW_F_INVALID). Do not
try to power-down the RF section of an invalid rtw.

The radiotap signal quality field is 16, not 8, bits wide. Convert
the byte order.


# 1.35 29-Dec-2004 dyoung

Remove some dead code.


# 1.34 29-Dec-2004 dyoung

I like the tlp/atw-style names for software descriptors, txsoft,
better than txctl. Change from rtw_txctl/rtw_rxctl to
rtw_txsoft/rtw_rxsoft. Change the descriptor blocks' names to
match: rtw_txctl_blk becomes rtw_txsoft_blk. Change the member-name
prefixes for both software and hardware descriptors.


# 1.33 29-Dec-2004 dyoung

Consolidate variables related to the rx ring in sc_rxdesc_blk,
which is a struct rtw_rxdesc_blk.

Put a copy of the DMA tag and the DMA map into the rx- and tx-ring
blocks so that I don't have to pass them to subroutines all of the
time.


# 1.32 28-Dec-2004 dyoung

Add bpf(4) packet taps to rtw(4). Now you can tap DLT_EN10MB
(Ethernet II), DLT_IEEE802_11 (802.11), and DLT_IEEE802_11_RADIO
(radiotap + 802.11).


# 1.31 28-Dec-2004 dyoung

If defined(RTW_DEBUG), provide a sysctl (hw.rtw.rxbufs_limit) for
limiting the number of rx buffers an rtw may allocate. Use this
sysctl to test the code that copes with buffer exhaustion.

Allocate at most RTW_RXQLEN rx buffers, stopping at the sysctl
limit. Record in sc_nrxdesc how many were allocated, and put the
end-of-ring indication on sc_rxdesc[sc_nrxdesc - 1]. In rtw_init,
if no rx buffers could be allocated, log a complaint, clear
IFF_RUNNING, and exit with an error.

Many changes to accomodate a short rx ring, mainly of the "add a
rx-ring length argument" variety. XXX I really should consolidate
all of the rx ring variables in one struct and pass that to the
rx-ring subroutines.

Bug fix: after calling MCLGET, use the (m->m_flags & M_EXT) idiom
to check for success, instead of m != NULL.

Bug fix: at the top of rtw_start, if IFF_RUNNING is not set, or
IFF_OACTIVE is, get out.


# 1.30 27-Dec-2004 dyoung

Use a table to convert the hardware's bit rates (0, 1, 2, 3) to
net80211 bit rates (2, 4, 11, 22).

Count input errors (if_ierrors++) for "DMA error/FIFO overflow"
and unknown bit rate.


# 1.29 27-Dec-2004 dyoung

Simplify the reset we do on a transmit timeout. Really, this could
be as simple as rtw_stop(, 0), rtw_init().


# 1.28 27-Dec-2004 mycroft

Use the last descriptor to count collisions and failed transmissions, too.


# 1.27 27-Dec-2004 mycroft

When checking if a split packet is completed, check the *last* segment, not
the first. Otherwise we can overwrite parts of the TX ring that we shouldn't.

Kluge the basic rate setting for now.

Minor simplification to the dequeueing logic.


# 1.26 27-Dec-2004 dyoung

Remove useless debug sysctls.

For AP scanning, change the channel dwell time from 1 second to
1/5 second.


# 1.25 27-Dec-2004 mycroft

Replace d_plcp_svc with d_residue. The latter is the number of whole
empty/unused octets to fill out the data time slot. The value is constrained
by math to 0 for <= 5.5Mb, 0-1 for 11Mb, and 0-2 for 22Mb. It is used to
signal to the MAC that there is residue.


# 1.24 26-Dec-2004 dyoung

Make rtw(4) build w/o RTW_DEBUG. Thanks to Charles Hannum for
pointing out my oversight.


# 1.23 25-Dec-2004 dyoung

The rx descriptor ring bug happens quite often, so printf'ing
occurrences is annoying. Only printf about it when rtw_debug
contains RTW_DEBUG_BUG.


# 1.22 25-Dec-2004 dyoung

IMPORTANT: set m->m_pkthdr.rcvif on rx'd packets. Illegal memory
references abound without this fix.

In rtw_intr_rx, skip to the next rx packet earlier if the rx packet
length is too short.

Also in rtw_intr_rx, if a packet is rx'd with unknown rate, printf
a warning, drop the packet, recycle the rx buffer, skip to next rx
packet.


# 1.21 25-Dec-2004 dyoung

Change rtw_debug from a debug level to a debug mask. Add a lot of
debug flags.

From Linux: handle an RTL8180 bug. Sometimes the NIC skips from
the middle of the ring to the 0th rx descriptor. Now the driver
resynchronizes.

Handle a receive descriptor underrun or Rx FIFO overflow condition
in the way that the Linux driver does. This kind of seems like
overkill, but whatever.

Protect rtw_ioctl with splnet().

Do not load a tx descriptor with a buffer shorter than 4 bytes.

Handle a transmit timeout less disruptively.


# 1.20 23-Dec-2004 dyoung

Oops, straggler from last commit: set the 802.11 Duration field
with the result from ieee80211_compute_duration.


# 1.19 23-Dec-2004 dyoung

Fix a bug in ieee80211_compute_duration: the 802.11 Duration field
in an 802.11 unicast data packet is equal to the duration of the
SIFS and Acknowledgement. That is, the amount of time reserved
*after* the packet has finished transmitting.

Change the arguments to ieee80211_compute_duration: pass the entire
packet length, not just the payload length. Add a 'debug' argument
to ieee80211_compute_duration and its helper subroutine,
ieee80211_compute_duration1.

If debug != 0, ieee80211_compute_duration printfs its arguments
and several local variables.

In rtw(4), load the 802.11 Duration field with the result from
ieee80211_compute_duration.


# 1.18 23-Dec-2004 dyoung

Bug fix: in rtw_rxbuf_alloc, unload the previous mbuf chain before
loading the new chain.


# 1.17 23-Dec-2004 dyoung

DMA-synchronize the Rx buffers before re-initializing them.
XXX not necessary?


# 1.16 23-Dec-2004 dyoung

Add more comprehensive debug messages as we setup transmit descriptors.
Also, dump packets if IFF_DEBUG|IFF_LINK2. Factor out a subroutine
for printing transmit-descriptor debug messages.


# 1.15 23-Dec-2004 dyoung

Disable interrupts and stop transmit DMA before disabling the
transmitter and receiver.


# 1.14 23-Dec-2004 dyoung

Shorten variables, s/txctl/ctl/. This is rtw_start, after all:
transmission is implied.


# 1.13 23-Dec-2004 dyoung

Do not indicate to the NIC that the host has appended the CRC32 to
Tx frames.


# 1.12 23-Dec-2004 dyoung

When we set up the supported rates table, mark 1Mb/s, 2Mb/s as
basic rates.


# 1.11 23-Dec-2004 dyoung

Extract the transmission status from a tx descriptor, and convert
to host byte-order, once.


# 1.10 20-Dec-2004 dyoung

Realtek sample sources are not consistent about the "Digital PHY"
bit in the SROM. It seems as if it is set to 1 when the PHY is
*analog*, not *digital*. Fix my sources.

In rtw_intr_rx, use units of 500kb/s instead of 100kb/s for rate,
to be consistent with net80211's expectations. Polish up some
debugging ugly messages. Dump raw 802.11 packets if IFF_DEBUG|IFF_LINK2
and RTW_DEBUG is defined.

Polish power-state (on/sleep/off) handling. Especially improve
support for RFMD (totally untested) and Maxim. For Philips, take
the Digital PHY property into account.

Call the net80211 watchdog function from rtw_watchdog, so that we
scan again if auth/assoc fails.

Be a little more cautious about writing register[RTW_TPPOLL], since
other drivers are.... Don't frob the high/low-priority queues
right now, since I don't use them.

Add rtw_join_bss which programs the card with the BSSID and other
properties of a BSS. Use it on state transitions. Factor out
rtw_set_nettype.

Make rtw_recv_beacon call ieee80211_recv_mgmt instead of dropping
beacons on the floor! TBD IBSS merges.

Change some rtw_debug=2 printfs to rtw_debug=3 (RTW_DPRINTF3)
printfs so the console doesn't get spammed so badly at rtw_debug=2.
Change some debugging printfs to RTW_DPRINTFs. E.g., print the
"RF programming method" only if debugging is enabled.


# 1.9 20-Dec-2004 dyoung

Fix bug in last commit: use &sc->sc_regs, regs is not defined.


# 1.8 20-Dec-2004 dyoung

Add some bus barriers. Remark where they are needed, e.g.,
read_eeprom.

Change some printfs to RTW_DPRINTF2s to quiet rtw(4) when debugging
is disabled.


# 1.7 20-Dec-2004 dyoung

Get rid of the silly char (*dvname)[IFNAMSIZ] pattern. Replace it
with const char *dvname. I'm not sure what I was thinking.


# 1.6 20-Dec-2004 dyoung

Assert that I'm DMA-syncing a non-negative number of transmit
descriptors.

As I free dirty transmit buffers, move them to the free list, not
back to the dirty list!

Add a 5-second transmit timeout.


# 1.5 19-Dec-2004 dyoung

Add the transmit section of rtw(4): build up and tear down transmit
descriptor rings, move packets from the transmit queues to the
transmit rings, handle transmission-completed interrupts. My
Linksys WPC11 ver. 4 with Maxim RF, generates interrupts like it
is successfully transmitting packets. Clearly there are bugs: my
G4 Powerbook locks up hard. I will debug tomorrow.


# 1.4 13-Dec-2004 dyoung

At last, I have rtw w/ Philips RF receiving packets.

I added some sysctls to aid debugging:

* hw.rtw.debug -- enable debugging

* hw.rtw.flush_rfio -- Linux voodoo: possibly makes the MAC
"flush" bits down the serial bus to the RF

* hw.rtw.host_rfio: force the host to bang bits to the RF, instead
of the MAC banging bits

* hw.rtw.rfio_delay: after telling the MAC to bang bits to the
RF front-end, delay rfio_delay microseconds.

* hw.rtw.rfprog_fallback: there is this notion of the "RF
programming method." I believe the choice influences the
polarity/timing of the serial bus used to program the RF
front-end. I know the correct choice for Intersil/RFMD/Philips
front-ends, only. For all other front-ends, I "fallback" to
rfprog_fallback.

Make rtw_txdac_enable take an rtw_softc argument. I will probably
revert this change.

Add some Linux voodoo to rtw_continuous_tx_enable. I will probably
revert this change.

Important: add rtw_set_rfprog, which sets the correct RF programming
method. This change and the following change are probably responsible
for making the Philips RF work.

Important: RTW_CONFIG1 is an 8-bit register, treat it that way!

Important: RTW_BRSR is 16-bit, RTW_CRCOUNT, RTW_PHYDELAY, and
RTW_MSR are 8-bit: treat them that way!

Vastly simplify rtw_resume_ticks.

Note to self: set the LED state to match the power state.

Hedge against the possibility that RTW_MSR is protected as
RTW_CONFIG[0123] are, meanwhile reworking that section of rtw_init
a little.

Add sc_anaparm, which isn't used, yet....


# 1.3 12-Dec-2004 dyoung

Miscellaneous changes. Details below. Important changes flagged
with []. Using the driver with my Linksys WPC11 ver. 4, it seems
to be receiving packets for a change. The WPC11 ver. 4 has a Maxim
RF section. My no-name rtw with Philips RF section still does not
receive any packets.

Keep access-level (analog params > config[0123] registers > none)
in sc_access. Add rtw_set_access for changing the access level.

Make rtw_continuous_tx_enable and other subroutines use rtw_set_access
instead of rtw_config0123_enable and rtw_anaparm_enable.

Factor part of the chip-reset code into rtw_chip_reset1.

Change the 'struct foo (*bar)[N]'-style arguments to
'struct foo *bar'-style arguments.

Consolidate software/hardware Tx/Rx ring setup in rtw_hwring_setup,
rtw_swring_setup.

Add a new constant, SA2400_OPMODE_DEFAULTS, for the bits that we
*always* set in the SA2400 OPMODE register.

Factor some code out into rtw_sa2400_calibrate. (Inspired by the
Linux driver.)

[] When the receiver goes into underrun/overflow state, call a new
subroutine, rtw_kick() that stops the Rx/Tx processes, resets
the chip, reinitializes the Tx/Rx rings, and restarts Rx/Tx
processes. (Inspired by the Linux driver.)

[] In rtw_intr_rx, check for too-short packets before calling
ieee80211_find_rxnode. I believe this will prevent a repeat of
the MCHK exception I saw once on macppc.

[] Use seconds-elapased as well as microseconds-elapsed to set the
next "due date" for the timeout interrupt. This keeps the driver
from programming the timeout to expire too early.

[] In rtw_intr, read RTW_ISR at most 10 times, then get out. If
the interface is not enabled (RTW_F_ENABLED), then get out.

[] In rtw_stop, get out if the interface is not enabled (RTW_F_ENABLED).
Block IPL_NET interrupts. Don't read/write any registers if
the interface is invalid (RTW_F_INVALID).

[] Call rtw_stop in rtw_detach.


Revision tags: kent-audio1-base
# 1.2 30-Oct-2004 thorpej

When adding/deleting multicast addresses, only whack the address
filter if the interface is marked RUNNING.

Fixes kern/27678.


# 1.1 26-Sep-2004 dyoung

branches: 1.1.2;
Add work-in-progress driver rtw(4) for Realtek RTL8180 MAC/baseband.

Add register definitions for Maxim MAX2820 and Philips SA2400 radio
front-ends.


# 1.136 16-Jun-2021 riastradh

if_attach and if_initialize cannot fail, don't test return value

These were originally made failable back in 2017 when if_initialize
allocated a softint in every interface for link state changes, so
that it could fail gracefully instead of panicking:

https://mail-index.NetBSD.org/source-changes/2017/10/23/msg089053.html

However, this spawned many seldom- or never-tested error branches,
which are risky to have around. And that softint in every interface
has since been replaced by a single global workqueue, because link
state changes require thread context but not low latency or high
throughput:

https://mail-index.NetBSD.org/source-changes/2020/02/06/msg113759.html

So there is no longer any reason for if_initialize to fail. (The
subroutine if_stats_init can't fail because percpu_alloc can't fail
either.)

There is a snag: the softint_establish in if_percpuq_create could
fail, potentially leading to bad consequences later on trying to use
the softint. This change doesn't introduce any new bugs because of
the snag -- if_percpuq_attach was already broken. However, the snag
can be better addressed without spawning error branches, either by
using a single softint or making softints less scarce.

(Separate commit will change the signatures of if_attach and
if_initialize to return void, scheduled to ride whatever is the next
convenient kernel bump.)

Patch and testing on amd64 and evbmips64-eb by maya@; commit message
soliloquy, and compile-testing on evbppc/i386/earmv7hf, by me.


Revision tags: cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 cjep_staticlib_x-base thorpej-i2c-spi-conf-base thorpej-cfargs-base thorpej-futex-base bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1 phil-wifi-20200411 bouyer-xenpvh-base is-mlppp-base phil-wifi-20200406 ad-namecache-base3
# 1.135 29-Jan-2020 thorpej

Adopt <net/if_stats.h>.


Revision tags: ad-namecache-base2 ad-namecache-base1 ad-namecache-base phil-wifi-20191119
# 1.134 10-Nov-2019 chs

branches: 1.134.2;
in many device attach paths, allocate memory with M_WAITOK instead of M_NOWAIT
and remove code to handle failures that can no longer happen.


Revision tags: netbsd-9-2-RELEASE netbsd-9-1-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 netbsd-9-base phil-wifi-20190609
# 1.133 28-May-2019 msaitoh

Use ETHER_LOCK()/ETHER_UNLOCK() for all ethernet drivers to protect ec_multi*.


# 1.132 23-May-2019 msaitoh

Whitespace fix (mainly tabify).


# 1.131 23-May-2019 msaitoh

-No functional change:
- KNF
- u_int*_t -> uint*_t.


Revision tags: isaki-audio2-base
# 1.130 05-Feb-2019 msaitoh

Remove very old IFF_NOTRAILERS flag.


# 1.129 03-Feb-2019 mrg

- add or adjust /* FALLTHROUGH */ where appropriate
- add __unreachable() after functions that can return but won't in
this case, and thus can't be marked __dead easily


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 jdolecek-ncqfixes-base pgoyette-compat-0728 phil-wifi-base
# 1.128 26-Jun-2018 msaitoh

branches: 1.128.2;
Implement the BPF direction filter (BIOC[GS]DIRECTION). It provides backward
compatibility with BIOC[GS]SEESENT ioctl. The userland interface is the same
as FreeBSD.

This change also fixes a bug that the direction is misunderstand on some
environment by passing the direction to bpf_mtap*() instead of checking
m->m_pkthdr.rcvif.


Revision tags: pgoyette-compat-0625 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base tls-maxphys-base-20171202
# 1.127 23-Oct-2017 msaitoh

branches: 1.127.2;
If if_initialize() failed in the attach function, free resources and return.


Revision tags: matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base
# 1.126 23-May-2017 ozaki-r

branches: 1.126.2;
Apply deferred if_start to more drivers

And annotate some XXX_start as it runs in softint to clarify that
it doesn't need deferred if_start.


Revision tags: prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 nick-nhusb-base-20170204
# 1.125 02-Feb-2017 nonaka

wlan interfaces make interrupt routine running on softint context.

see http://mail-index.netbsd.org/tech-kern/2016/12/06/msg021281.html

tested device:
* ath at pci: AR5212, AR5424
* athn at pci: AR9287
* ipw at pci: 2100BG
* iwi at pci: 2915ABG
* iwm at pci: 3165, 7260, 8260
* iwn at pci: 4945, 6235
* ral at pci: RT2560
* rtwn at pci: RTL8192CE


Revision tags: bouyer-socketcan-base pgoyette-localcount-20170107 nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.124 15-Sep-2016 jdolecek

branches: 1.124.2;
remove last isolated islands using BUS_SPACE_BARRIER_SYNC and
BUS_SPACE_BARRIER_X_BEFORE_X - these were only ever defined for mips and ia64,
and never actually implemented even there


Revision tags: localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907
# 1.123 10-Jun-2016 ozaki-r

branches: 1.123.2;
Introduce m_set_rcvif and m_reset_rcvif

The API is used to set (or reset) a received interface of a mbuf.
They are counterpart of m_get_rcvif, which will come in another
commit, hide internal of rcvif operation, and reduce the diff of
the upcoming change.

No functional change.


Revision tags: nick-nhusb-base-20160529
# 1.122 16-May-2016 ozaki-r

Use M_GETCTX and M_SETCTX instead of open-coding rcvif

No functional change.


Revision tags: netbsd-7-2-RELEASE netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 netbsd-7-0-RELEASE nick-nhusb-base-20150921 netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 nick-nhusb-base-20150606 nick-nhusb-base-20150406 nick-nhusb-base netbsd-7-base yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 rmind-smpnet-nbase rmind-smpnet-base tls-maxphys-base
# 1.121 25-Feb-2014 pooka

branches: 1.121.6;
Ensure that the top level sysctl nodes (kern, vfs, net, ...) exist before
the sysctl link sets are processed, and remove redundancy.

Shaves >13kB off of an amd64 GENERIC, not to mention >1k duplicate
lines of code.


# 1.120 17-Oct-2013 christos

- remove unused variables
- move variables inside ifdef sections
- ifdef notdef unused code
- use __USE for debugging variables


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE yamt-pagecache-tag8 netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 agc-symver-base netbsd-6-1-RC2 netbsd-6-1-RC1 yamt-pagecache-base8 netbsd-6-0-1-RELEASE yamt-pagecache-base7 matt-nb6-plus-nbase yamt-pagecache-base6 netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base10 yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.119 04-Jul-2011 joerg

branches: 1.119.2; 1.119.12; 1.119.16;
Fix memset usage.


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base matt-mips64-premerge-20101231 rmind-uvmplock-base
# 1.118 15-Nov-2010 uebayasi

Socket ioctl definitions need sys/sockio.h.


# 1.117 13-Nov-2010 uebayasi

Don't pull in the whole uvm(9) API to access only PAGE_SIZE and
some other constants. These are provided by sys/param.h now.


Revision tags: uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10 uebayasi-xip-base1
# 1.116 05-Apr-2010 joerg

Push the bpf_ops usage back into bpf.h. Push the common ifp->if_bpf
check into the inline functions as well the fourth argument for
bpf_attach.


# 1.115 15-Mar-2010 dyoung

Make this compile on sparc64:

1 s/next_tick/next_tint/ because next_tick shadows a global on sparc64.

2 Fix the bus-barrier helper routines, which had the tag & handle
swapped (!!). Move the helpers from rtwreg.h to rtwvar.h, and
change RTW_BARRIER() into an inline subroutine called rtw_barrier().


Revision tags: yamt-nfs-mp-base9
# 1.114 24-Feb-2010 dyoung

branches: 1.114.2;
A pointer typedef entails trading too much flexibility to declare const
and non-const types, and the kernel uses both const and non-const
PMF qualifiers and device suspensors, so change the pmf_qual_t and
device_suspensor_t typedefs from "pointers to const" to non-pointer,
non-const types.


Revision tags: uebayasi-xip-base
# 1.113 31-Jan-2010 dyoung

branches: 1.113.2;
Add the missing newline to a verbose autoconf message.


# 1.112 19-Jan-2010 pooka

Redefine bpf linkage through an always present op vector, i.e.
#if NBPFILTER is no longer required in the client. This change
doesn't yet add support for loading bpf as a module, since drivers
can register before bpf is attached. However, callers of bpf can
now be modularized.

Dynamically loadable bpf could probably be done fairly easily with
coordination from the stub driver and the real driver by registering
attachments in the stub before the real driver is loaded and doing
a handoff. ... and I'm not going to ponder the depths of unload
here.

Tested with i386/MONOLITHIC, modified MONOLITHIC without bpf and rump.


# 1.111 08-Jan-2010 dyoung

Expand PMF_FN_* macros.


Revision tags: matt-premerge-20091211 jym-xensuspend-nbase
# 1.110 19-Oct-2009 rmind

Drop 3rd and 4th clauses from David Young's license.
Reviewed and approved by dyoung@ (copyright holder).


# 1.109 16-Sep-2009 dyoung

In pmf(9), improve the implementation of device self-suspension
and make suspension by self, by drvctl(8), and by ACPI system sleep
play nice together. Start solidifying some temporary API changes.

1. Extract a new header file, <sys/device_if.h>, from <sys/device.h> and
#include it from <sys/pmf.h> instead of <sys/device.h> to break the
circular dependency between <sys/device.h> and <sys/pmf.h>.

2. Introduce pmf_qual_t, an aggregate of qualifications on a PMF
suspend/resume call. Start to replace instances of PMF_FN_PROTO,
PMF_FN_ARGS, et cetera, with a pmf_qual_t.

3. Introduce the notion of a "suspensor," an entity that holds a
device in suspension. More than one suspensor may hold a device
at once. A device stays suspended as long as at least one
suspensor holds it. A device resumes when the last suspensor
releases it.

Currently, the kernel defines three suspensors,

3a the system-suspensor: for system suspension, initiated
by 'sysctl -w machdep.sleep_state=3', by lid closure, by
power-button press, et cetera,

3b the drvctl-suspensor: for device suspension by /dev/drvctl
ioctl, e.g., drvctl -S sip0.

3c the system self-suspensor: for device drivers that suspend
themselves and their children. Several drivers for network
interfaces put the network device to sleep while it is not
administratively up, that is, after the kernel calls if_stop(,
1). The self-suspensor should not be used directly. See
the description of suspensor delegates, below.

A suspensor can have one or more "delegates". A suspensor can
release devices that its delegates hold suspended. Right now,
only the system self-suspensor has delegates. For each device
that a self-suspending driver attaches, it creates the device's
self-suspensor, a delegate of the system self-suspensor.

Suspensors stop a system-wide suspend/resume cycle from waking
devices that the operator put to sleep with drvctl before the cycle.
They also help self-suspension to work more simply, safely, and in
accord with expectations.

4. Add the notion of device activation level, devact_level_t,
and a routine for checking the current activation level,
device_activation(). Current activation levels are DEVACT_LEVEL_BUS,
DEVACT_LEVEL_DRIVER, and DEVACT_LEVEL_CLASS, which respectively
indicate that the device's bus is active, that the bus and device are
active, and that the bus, device, and the functions of the device's
class (network, audio) are active.

Suspend/resume calls can be qualified with a devact_level_t.
The power-management framework treats a devact_level_t that
qualifies a device suspension as the device's current activation
level; it only runs hooks to reduce the activation level from
the presumed current level to the fully suspended state. The
framework treats a devact_level_t qualifying device resumption
as the target activation level; it only runs hooks to raise the
activation level to the target.

5. Use pmf_qual_t, devact_level_t, and self-suspensors in several
drivers.

6. Temporarily add an unused power-management workqueue that I will
remove or replace, soon.


Revision tags: yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5 yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 nick-hppapmap-base3 jym-xensuspend-base nick-hppapmap-base
# 1.108 07-Apr-2009 dyoung

Cosmetic: remove some dead code.


# 1.107 02-Apr-2009 dyoung

Add the WEP capability to our net80211 capability flags, since we do
sort of support hardware WEP. Only change the WEP key index in a Tx
descriptor from 0 if the type of our transmit key is _WEP, not _TKIP:
i.e., only if we're really doing WEP crypto in the hardware.

Ignore a watchdog timeout on any Tx ring if we can collect some packets
from that ring. Restart both the receiver and the transmitter when a
watchdog timeout occurs instead of restarting only the transmitter.


Revision tags: nick-hppapmap-base2 haad-dm-base2 haad-nbase2 ad-audiomp2-base haad-dm-base mjf-devfs2-base
# 1.106 12-Nov-2008 ad

branches: 1.106.4;
Remove LKMs and switch to the module framework, pass 1.

Proposed on tech-kern@.


# 1.105 07-Nov-2008 dyoung

*** Summary ***

When a link-layer address changes (e.g., ifconfig ex0 link
02:de:ad:be:ef:02 active), send a gratuitous ARP and/or a Neighbor
Advertisement to update the network-/link-layer address bindings
on our LAN peers.

Refuse a change of ethernet address to the address 00:00:00:00:00:00
or to any multicast/broadcast address. (Thanks matt@.)

Reorder ifnet ioctl operations so that driver ioctls may inherit
the functions of their "class"---ether_ioctl(), fddi_ioctl(), et
cetera---and the class ioctls may inherit from the generic ioctl,
ifioctl_common(), but both driver- and class-ioctls may override
the generic behavior. Make network drivers share more code.

Distinguish a "factory" link-layer address from others for the
purposes of both protecting that address from deletion and computing
EUI64.

Return consistent, appropriate error codes from network drivers.

Improve readability. KNF.

*** Details ***

In if_attach(), always initialize the interface ioctl routine,
ifnet->if_ioctl, if the driver has not already initialized it.
Delete if_ioctl == NULL tests everywhere else, because it cannot
happen.

In the ioctl routines of network interfaces, inherit common ioctl
behaviors by calling either ifioctl_common() or whichever ioctl
routine is appropriate for the class of interface---e.g., ether_ioctl()
for ethernets.

Stop (ab)using SIOCSIFADDR and start to use SIOCINITIFADDR. In
the user->kernel interface, SIOCSIFADDR's argument was an ifreq,
but on the protocol->ifnet interface, SIOCSIFADDR's argument was
an ifaddr. That was confusing, and it would work against me as I
make it possible for a network interface to overload most ioctls.
On the protocol->ifnet interface, replace SIOCSIFADDR with
SIOCINITIFADDR. In ifioctl(), return EPERM if userland tries to
invoke SIOCINITIFADDR.

In ifioctl(), give the interface the first shot at handling most
interface ioctls, and give the protocol the second shot, instead
of the other way around. Finally, let compatibility code (COMPAT_OSOCK)
take a shot.

Pull device initialization out of switch statements under
SIOCINITIFADDR. For example, pull ..._init() out of any switch
statement that looks like this:

switch (...->sa_family) {
case ...:
..._init();
...
break;
...
default:
..._init();
...
break;
}

Rewrite many if-else clauses that handle all permutations of IFF_UP
and IFF_RUNNING to use a switch statement,

switch (x & (IFF_UP|IFF_RUNNING)) {
case 0:
...
break;
case IFF_RUNNING:
...
break;
case IFF_UP:
...
break;
case IFF_UP|IFF_RUNNING:
...
break;
}

unifdef lots of code containing #ifdef FreeBSD, #ifdef NetBSD, and
#ifdef SIOCSIFMTU, especially in fwip(4) and in ndis(4).

In ipw(4), remove an if_set_sadl() call that is out of place.

In nfe(4), reuse the jumbo MTU logic in ether_ioctl().

Let ethernets register a callback for setting h/w state such as
promiscuous mode and the multicast filter in accord with a change
in the if_flags: ether_set_ifflags_cb() registers a callback that
returns ENETRESET if the caller should reset the ethernet by calling
if_init(), 0 on success, != 0 on failure. Pull common code from
ex(4), gem(4), nfe(4), sip(4), tlp(4), vge(4) into ether_ioctl(),
and register if_flags callbacks for those drivers.

Return ENOTTY instead of EINVAL for inappropriate ioctls. In
zyd(4), use ENXIO instead of ENOTTY to indicate that the device is
not any longer attached.

Add to if_set_sadl() a boolean 'factory' argument that indicates
whether a link-layer address was assigned by the factory or some
other source. In a comment, recommend using the factory address
for generating an EUI64, and update in6_get_hw_ifid() to prefer a
factory address to any other link-layer address.

Add a routing message, RTM_LLINFO_UPD, that tells protocols to
update the binding of network-layer addresses to link-layer addresses.
Implement this message in IPv4 and IPv6 by sending a gratuitous
ARP or a neighbor advertisement, respectively. Generate RTM_LLINFO_UPD
messages on a change of an interface's link-layer address.

In ether_ioctl(), do not let SIOCALIFADDR set a link-layer address
that is broadcast/multicast or equal to 00:00:00:00:00:00.

Make ether_ioctl() call ifioctl_common() to handle ioctls that it
does not understand.

In gif(4), initialize if_softc and use it, instead of assuming that
the gif_softc and ifp overlap.

Let ifioctl_common() handle SIOCGIFADDR.

Sprinkle rtcache_invariants(), which checks on DIAGNOSTIC kernels
that certain invariants on a struct route are satisfied.

In agr(4), rewrite agr_ioctl_filter() to be a bit more explicit
about the ioctls that we do not allow on an agr(4) member interface.

bzero -> memset. Delete unnecessary casts to void *. Use
sockaddr_in_init() and sockaddr_in6_init(). Compare pointers with
NULL instead of "testing truth". Replace some instances of (type
*)0 with NULL. Change some K&R prototypes to ANSI C, and join
lines.


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 wrstuden-revivesa-base-1 simonb-wapbl-nbase yamt-pf42-base4 simonb-wapbl-base yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 yamt-nfs-mp-base2 wrstuden-revivesa-base yamt-nfs-mp-base yamt-pf42-base ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 1.104 15-Mar-2008 dyoung

branches: 1.104.4; 1.104.10; 1.104.12;
Cosmetic: make rtw_hw_keysupp() return a bool instead of int. In
rtw_wep_setkeys(), add a debug printf, and move the initialization
of keylen from the for-loop to the declaration.


# 1.103 14-Mar-2008 dyoung

Extract subroutine rtw_tx_kick() from rtw_start(), and reuse it in
rtw_io_enable() to restart the transmitter after resetting it.


# 1.102 14-Mar-2008 dyoung

Change tests for "impossible" keys to KASSERT()s. Get rid of a
temporary variable. In rtw_key_delete(), do not invalidate the
hardware keys unless a WEP key is deleted.


# 1.101 12-Mar-2008 dyoung

Use device_t and its accessors throughout. Use aprint_*_dev().

Improve PMF-ability.

Add a 'flags' argument to suspend/resume handlers and
callers such as pmf_system_suspend().

Define a flag, PMF_F_SELF, which indicates to PMF that a
device is suspending/resuming itself. Add helper routines,
pmf_device_suspend_self(dev) and pmf_device_resume_self(dev),
that call pmf_device_suspend(dev, PMF_F_SELF) and
pmf_device_resume(dev, PMF_F_SELF), respectively. Use
PMF_F_SELF to suspend/resume self in ath(4), audio(4),
rtw(4), and sip(4).

In ath(4) and in rtw(4), replace the icky sc_enable/sc_disable
callbacks, provided by the bus front-end, with
self-suspension/resumption. Also, clean up the bus
front-ends. Make sure that the interrupt handler is
disestablished during suspension. Get rid of driver-private
flags (e.g., RTW_F_ENABLED, ath_softc->sc_invalid); use
device_is_active()/device_has_power() calls, instead.

In the network-class suspend handler, call if_stop(, 0)
instead of if_stop(, 1), because the latter is superfluous
(bus- and driver-suspension hooks will 'disable' the NIC),
and it may cause recursion.

In the network-class resume handler, prevent infinite
recursion through if_init() by getting out early if we are
self-suspending (PMF_F_SELF).

rtw(4) improvements:

Destroy rtw(4) callouts when we detach it. Make rtw at
pci detachable. Print some more information with the "rx
frame too long" warning.

Remove activate() methods:

Get rid of rtw_activate() and ath_activate(). The device
activate() methods are not good for much these days.

Make ath at cardbus resume with crypto functions intact:

Introduce a boolean device property, "pmf-powerdown". If
pmf-powerdown is present and false, it indicates that a
bus back-end should not remove power from a device.

Honor this property in cardbus_child_suspend().

Set this property to 'false' in ath_attach(), since removing
power from an ath at cardbus seems to lobotomize the WPA
crypto engine. XXX Should the pmf-powerdown property
propagate toward the root of the device tree?

Miscellaneous ath(4) changes:

Warn if ath(4) tries to write crypto keys to suspended
hardware.

Reduce differences between FreeBSD and NetBSD in ath(4)
multicast filter setup.

Make ath_printrxbuf() print an rx descriptor's status &
key index, to help debug crypto errors.

Shorten a staircase in ath_ioctl(). Don't check for
ieee80211_ioctl() return code ERESTART, it never happens.


# 1.100 12-Mar-2008 dyoung

Print the TPPoll register when the Tx DMA engine doesn't shut down
in the time we allow.


# 1.99 03-Mar-2008 tsutsui

Explicitly include <sys/device.h> for device_t.


Revision tags: nick-net80211-sync-base vmlocking2-base3 bouyer-xeni386-nbase bouyer-xeni386-base mjf-devfs-base matt-armv6-base hpcarm-cleanup-base
# 1.98 21-Dec-2007 dyoung

branches: 1.98.2; 1.98.6;
Do not embed a struct device in rtw_softc any longer. Register
both pci and cardbus attachments with CFATTACH_DECL_NEW(). Access
the softc through the device_t using device_private().

While I'm here, change a couple of KASSERT()s about the Rx buffer
length to a warning.


# 1.97 20-Dec-2007 dyoung

Remove shutdown hooks. Use KASSERT().


# 1.96 16-Dec-2007 dyoung

Fix a bug I introduced to rtw_chan2txpower() the other night.

Fix a bug in device detachment: change a break statement to a
/*FALLTHROUGH*/ in rtw_detach().


# 1.95 16-Dec-2007 dyoung

Synchronize device detachment with network interrupts. Use the
pmf network class instead of powerhooks.


Revision tags: yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 bouyer-xenamd64-base2 vmlocking-nbase bouyer-xenamd64-base jmcneill-pm-base reinoud-bufcleanup-base
# 1.94 18-Nov-2007 jnemeth

branches: 1.94.2; 1.94.6;
fix 'm' used unitialized


# 1.93 16-Nov-2007 dyoung

Accommodate the variety of RF front-ends when radiotapping frames:
tap only RSSI when there is a Philips RF front-end. Tap both Barker
lock quality and RSSI when there is any other RF front-end.

Provide radiotap listeners a more complete picture of channel
activity:

in promiscuous mode, tap frames who do not pass the CRC32 check.
Flag packets that were received with a short preamble. Ask
the NIC to pass us 802.11 Control frames. Pass frames to
radiotap listeners before stripping the FCS. Re-order operations
in rtw_intr_rx() in order to accomplish all of this, taking
care not to pass a broken packet to net80211!

Do not provide a flags field when tapping xmitted frames.

Assert sane Rx packet lengths. Really should check and drop instead
of KASSERTing. I will revisit this, soon.

Update copyright.


# 1.92 15-Nov-2007 dyoung

Fix order of operations:

rtw_rxdesc_init: before initializing a Rx descriptor's
control word, synchronize the Rx buffer

rtw_start, be paranoid: set the "NIC owns" bit on a Tx
descriptor dead last. Always reinitialize the "next
Tx descriptor" pointer, just in case it got clobbered
somehow.

Let the compiler decide whether to inline rtw_collect_txring or
not.


Revision tags: jmcneill-base
# 1.91 19-Oct-2007 ad

branches: 1.91.2;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h


Revision tags: yamt-x86pmap-base4 yamt-x86pmap-base3 yamt-x86pmap-base2 vmlocking-base
# 1.90 29-Sep-2007 scw

branches: 1.90.2;
s/NPBFILTER/NBPFILTER/ in some #endif comments. No functional change.


Revision tags: nick-csl-alignment-base5 yamt-x86pmap-base matt-mips64-base nick-csl-alignment-base mjf-ufs-trans-base
# 1.89 09-Jul-2007 ad

branches: 1.89.6; 1.89.8; 1.89.10;
Merge some of the less invasive changes from the vmlocking branch:

- kthread, callout, devsw API changes
- select()/poll() improvements
- miscellaneous MT safety improvements


# 1.88 29-May-2007 dyoung

Fix rtw(4) on NetBSD/macppc: use bus_space_write_region_stream_4()
instead of bus_space_write_region_4() to write WEP Rx keys to the
NIC. Thanks macallan@ for detecting the bug and testing the fix.


# 1.87 29-May-2007 dyoung

Cosmetic: simplify a memset() statement, use __arraycount(), and
remove a gratuitous return statement at the end of a void subroutine.


# 1.86 29-May-2007 dyoung

Simplify multicast filter programming, and take care to avoid
gratuitous device resets when the kernel adds/deletes a multicast
address.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base
# 1.85 04-Mar-2007 christos

branches: 1.85.2; 1.85.4;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.


Revision tags: ad-audiomp-base post-newlock2-merge newlock2-nbase newlock2-base
# 1.84 29-Jan-2007 dyoung

branches: 1.84.2;
In rtw_dequeue(), initialize *mp to NULL before anything else, so
that it is either NULL or a valid mbuf. Previously, it was possible
for rtw_dequeue() to exit with 0 before initializing *mp. rtw_start()
would have used whatever trash was in *mp, which would lead to
problems later on.


# 1.83 06-Jan-2007 dyoung

I have made a small change that suppresses "recovery" from (spurious?)
tx timeouts on the beacon queue. The driver's recovery process
badly disrupts the MAC's receiver. This needs a closer look, later.

Every other fix is by Charles M. Hannum. Charles writes:

"With these, the device is quite stable under load, does not experience
xmit timeouts, no longer mysteriously freezes, and does not spew
a lot of garbage. It does, however, continue to get some "tx fifo
underflow"s.

global, SYSCTL_SETUP():
a) Removed unused sysctl variables.

rtw_io_enable():
b) Change rtw_io_enable to take a softc, and make it call
rtw_txring_fixup().
c) Enable the PCI multiple read/write bit.
d) Always reset rdb_next to 0 when starting the receive engine.

rtw_intr_rx():
e) When processing receive packets, store the next pointer in rdb_next
and read it back on the next round, to fix a race condition vs.
rtw_tune() during AP discovery and association.
f) Remove the special "skip to 0th descriptor" code, because it is no
longer needed.

rtw_collect_txring():
g) In the "force" case, stop when we catch up to the hardware xmit
pointer.

rtw_intr_beacon():
h) Resetting tdb_next here looked fishy to me, in light of changes in
rtw_collect_txring(). XXX However, this is the one part I haven't
tested.

rtw_txring_fixup():
i) Add function and line arguments, so we can print out information
about the caller.
j) In addition to reading the hardware pointer, skip over any
additional packets with OWN set -- we may have queued more.

rtw_rxring_fixup():
k) Remove this, because it's completely wrong.

rtw_intr_ioerror():
l) Don't handle receive overruns here; handle them in the normal receive
path. Also changed RTW_INTR_RX and RTW_INTR_IOERROR accordingly.
m) Do not fiddle with CR; the transmit engine is still running just
fine.
n) Do not fiddle with IMR; it was unnecessary.
o) Don't touch the receive engine at all; not necessary now that we're
leaving CR alone.
p) Remove the rtw_do_chip_reset case; it was dangerous and not actually
used.

rtw_intr():
q) Don't mask off ISR bits when we pass down the ISR value; it's not
necessary, and sometimes the other bits useful in debugging output.

rtw_seg_too_short():
r) Don't spew here; the caller will do it if necessary. (Stops spewage
in an expected case.)

rtw_rxdesc_blk:
s) Minor change to make the elements have the same order as txdesc_blk.

general:
t) Added a bunch of debugging output, #ifdef RTW_DIAG, that was useful
while investigating the ring management problems. Also moved
rtw_txring_fixup() into RTW_DIAG, as I believe the transmit pointer
is always kept in sync now, and the function has potential race
conditions.


# 1.82 06-Jan-2007 dyoung

After we examine a rx/tx descriptor and find that it's still owned
by the NIC, re-sync the descriptor so that a cacheline will not
"cover" the NIC's modifications to the descriptor when we next
examine it.

This compiles, but I have not tested it, yet.


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase wrstuden-fixsa-base-1 netbsd-4-0-RELEASE netbsd-4-0-RC5 matt-nb4-arm-base netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 wrstuden-fixsa-base yamt-splraiseipl-base5 yamt-splraiseipl-base4 yamt-splraiseipl-base3 netbsd-4-base
# 1.81 16-Nov-2006 christos

__unused removal on arguments; approved by core.


# 1.80 13-Nov-2006 dyoung

Stop using typeof() in the bit-twiddling macros, per yamt@'s
suggestion. This change requires that I use the __PRIuBITS format
string in atw and rtw, so do that.


Revision tags: yamt-splraiseipl-base2
# 1.79 12-Oct-2006 xtraeme

Use __unused in function arguments where appropiate.


# 1.78 12-Oct-2006 christos

- sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386


# 1.77 24-Sep-2006 jmcneill

Add "name" parameter to powerhook_establish, to aid debugging. No objections
on tech-kern@


Revision tags: yamt-splraiseipl-base yamt-pdpolicy-base9 yamt-pdpolicy-base8 rpaulo-netinet-merge-pcb-base
# 1.76 03-Sep-2006 christos

branches: 1.76.2; 1.76.4;
- comment out impossible comparisons
- remove superfluous if statement


# 1.75 31-Aug-2006 dyoung

Per discussion on tech-kern and tech-userlevel, move the bit-twiddling
macros, __BIT, __BITS, SHIFTIN, SHIFTOUT, and __arraycount() from
lib/libkern/libkern.h to sys/cdefs.h. Add a __-prefix to SHIFTIN
and SHIFTOUT, and add a manual page for the bit-twiddling macros,
bits(3).

Make the __BIT and __BITS macros "widthless," as best I can, by
changing their type to uintmax_t from uint32_t. XXX The manual
page lags this change by a bit.

Define __PRIxBIT and __PRIxBITS printf(3) format strings.


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base7 yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base simonb-timecounters-base
# 1.74 26-May-2006 blymn

Clean up bogus whitespace


Revision tags: yamt-pdpolicy-base5
# 1.73 14-May-2006 christos

branches: 1.73.2;
XXX: GCC uninitialized


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 elad-kernelauth-base
# 1.72 28-Mar-2006 dyoung

Revamp ieee80211_get_rate. Now it does not use the rateset in the
ic->ic_bss, but it uses the rateset in its new ieee80211_node
argument, instead. If the rate is fixed by ic->ic_fixed_rate, but
the fixed rate is not in the node's rateset, choose a reasonable
default: prefer the lowest basic rate or, if there is no basic
rate, prefer the lowest rate, period.

Change a printf complaint to a debug message.

Adapt drivers to suit new ieee80211_get_rate calling convention.

XXX I really need to replace ieee80211_get_rate with a bitrate
XXX adaptation algorithm. Soon, soon....


# 1.71 27-Mar-2006 dyoung

Set the channel frequency and flags in the radiotap headers in
rtw_tune instead of in rtw_start, rtw_intr_rx.


# 1.70 27-Mar-2006 dyoung

Remove unused argument ifflagsp from rtw_dmamap_load_txbuf.


Revision tags: peter-altq-base yamt-pdpolicy-base2
# 1.69 08-Mar-2006 dyoung

branches: 1.69.2;
Change macro names to avoid collisions:

BIT -> __BIT
BITS -> __BITS


# 1.68 08-Mar-2006 dyoung

Move my bit-twiddling macros to libkern.h from my drivers, where
I had duplicated them. Improve the macros' names. Simplify their
implementation.

A brief description of each macro is below.

BIT(n): Return a bitmask with bit m set, where the least
significant bit is bit 0.

BITS(m, n): Return a bitmask with bits m through n, inclusive,
set. It does not matter whether m>n or m<=n.
The least significant bit is bit 0.

A "bitfield" is a span of consecutive bits defined by a
bitmask, where 1s select the bits in the bitfield. SHIFTIN,
SHIFTOUT, and SHIFTOUT_MASK help read and write bitfields
from device registers.

SHIFTIN(v, mask): Left-shift bits `v' into the bitfield
defined by `mask', and return them. No
side-effects.

SHIFTOUT(v, mask): Extract and return the bitfield selected
by `mask' from `v', right-shifting the
bits so that the rightmost selected bit
is at bit 0. No side-effects.

SHIFTOUT_MASK(mask): Right-shift the bits in `mask' so that
the rightmost non-zero bit is at bit
0. This is useful for finding the
greatest unsigned value that a bitfield
can hold. No side-effects. Note that
SHIFTOUT_MASK(m) = SHIFTOUT(m, m).

Examples:

/*
* Register definitions taken from the RFMD RF3000 manual.
*/
#define RF3000_GAINCTL 0x11 /* TX variable gain control */
#define RF3000_GAINCTL_TXVGC_MASK BITS(7, 2)
#define RF3000_GAINCTL_SCRAMBLER BIT(1)

/*
* Shift the transmit power into the transmit-power field of the
* gain-control register and write it to the baseband processor.
*/
atw_rf3000_write(sc, RF3000_GAINCTL,
SHIFTIN(txpower, RF3000_GAINCTL_TXVGC_MASK));


/*
* Register definitions taken from the ADMtek ADM8211 manual.
*
*/
#define ATW_RXSTAT_OWN BIT(31) /* 1: NIC may fill descriptor */
/* ... */
#define ATW_RXSTAT_DA1 BIT(17) /* DA bit 1, admin'd address */
#define ATW_RXSTAT_DA0 BIT(16) /* DA bit 0, group address */
#define ATW_RXSTAT_RXDR_MASK BITS(15,12) /* RX data rate */
#define ATW_RXSTAT_FL_MASK BITS(11,0) /* RX frame length, last
* descriptor only
*/

/* Extract the frame length from the Rx descriptor's
* status field.
*/
len = SHIFTOUT(rxstat, ATW_RXSTAT_FL_MASK);


Revision tags: yamt-pdpolicy-base yamt-uio_vmspace-base5
# 1.67 20-Feb-2006 thorpej

branches: 1.67.2; 1.67.4;
Use device_is_active() rather than testing dv_flags for DVF_ACTIVE
directly.


# 1.66 19-Feb-2006 dyoung

When rtw_enable is called, power may have been removed and re-applied,
so invalidate the WEP key registers to force us to write the keys
back to the hardware.

Revamp key handling: use the hardware WEP engine for 40-bit and
104-bit keys, only; use software WEP for all other key lengths.
Set the hardware key length to the length of the default Tx key,
or if there is no default Tx key, use the length of the longest
WEP key.


# 1.65 04-Feb-2006 dyoung

In rtw_{rx,tx}ring_fixup, do not set the tx/rx ring index to
something out of bounds if we read an invalid pointer form the
hardware. Prevents a panic when an rtw@cardbus is ejected.


# 1.64 29-Dec-2005 dyoung

branches: 1.64.2; 1.64.4; 1.64.6;
Add support for the GCT Semiconductor GRF5101 transceiver/synthesizer.
From OpenBSD.

GCT will not provide any documentation, so there are many magic
numbers in this code.


# 1.63 29-Dec-2005 dyoung

Update rtw(4) for the new IBSS merge idiom, where ieee80211_ibss_merge()
does not return ENETRESET if the driver should change its BSSID,
but it makes a RUN->RUN transition, instead.


# 1.62 29-Dec-2005 dyoung

In atw(4), use ieee80211_compute_duration() to compute IEEE 802.11
Duration and PLCP Length fields, and delete the abominable
atw_frame_setdurs() subroutine.

Make rtw(4) use the new ieee80211_compute_duration() calling
convention.

Add an ieee80211_key argument to ieee80211_compute_duration() and
lightly constify arguments. Get the crypto header length from the
key argument instead of blithely assuming a WEP header. Add some
inline documentation. Account for data padding (IEEE80211_F_DATAPAD).


# 1.61 24-Dec-2005 perry

Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.


# 1.60 13-Dec-2005 dyoung

Fix comments and debug printfs: Tx FIFOs underflow, they don't
overflow.


# 1.59 13-Dec-2005 dyoung

On a transmit FIFO overflow (err, actually an underflow...) reset
both the transmit & receive sections of the MAC.


Revision tags: yamt-readahead-base3 ktrace-lwp-base
# 1.58 23-Nov-2005 dyoung

Miscellaneous Realtek RTL8180L driver improvements:

1 Added new sysctl controls for debugging.

2 Improve detection & support for hardware WEP.

3 Revamp handling of transmit descriptor rings.

4 Reliably IFF_OACTIVE when transmit descriptors are available, to
stop the transmit section of the driver from freezing up.

5 Fix beacon transmission in adhoc and hostap modes. XXX There is
a wart in hostap mode, where beacons are transmitted at 1/2 the
correct rate. Load beacon descriptors when the RTW_INTR_BINT
interrupt arrives; schedule RTW_INTR_BINT 1ms ahead of the target
beacon time.

6 Recover more gracefully from tx/rx errors: avoid
transmitter/receiver/chip resets. Try to re-synchronize software
state with hardware state---e.g., load next descriptor pointer
from hardware.

7 Activate the transmit watchdog timer for beacons as well as other
packets.

8 Introduce rtw_idle() that waits for transmit DMA to finish; call
it before resetting the transmitter.


Revision tags: yamt-readahead-base2
# 1.57 18-Nov-2005 skrll

Adapt drivers to the new net80211(9).

Most of this is from dyoung@. Thanks!


Revision tags: yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base
# 1.56 22-Sep-2005 gdt

branches: 1.56.6;
Make arg of IFQ_SET_READY be &ifp->if_snd, to match all other drivers
and be compilable with altq enabled. Reviewed by dyoung@


# 1.55 07-Sep-2005 dogcow

With the assistance of dyoung, fix the following problems:
* some 8180L cards need a longer time for the srom to initialize; patch
suggested via OpenBSD.
* some cards give '0' for USA, some give '3'; for the meantime, accept both
as being USA locale cards.
* this is RTW, not ATW. :)


# 1.54 06-Sep-2005 dogcow

make rtw.c compile again after the 22-jun-05 net80211 import


# 1.53 11-Jul-2005 dyoung

Add undefined variable 'ic' to rtw_attach.


# 1.52 06-Jul-2005 dyoung

Historically, an(4), ath(4), atw(4), rtw(4), and wi(4) have printed
out their modes and rates at boot. Revert to the historical
behavior.


# 1.51 06-Jul-2005 dyoung

Avoid an unnecessary API difference between NetBSD and FreeBSD:
back out my change to ieee80211_crypto_encap that made it free its
mbuf argument on error. I had thought it was a bug. It was not.
It's the drivers that are broken. Make an(4), atw(4), ipw(4),
iwi(4), ral(4), rtw(4), ural(4), and wi(4) free the mbuf when
ieee80211_crypto_encap returns NULL. Also, return ath(4) to the
way it was---i.e., free the mbuf.

Thanks to Sam Leffler to pointing out my mistake.


# 1.50 28-Jun-2005 dyoung

branches: 1.50.2;
Here is a grotty hack that lets the RTL8180L handle WEP in the
receive direction, while software handles WEP in the transmit
direction. When net80211 calls rtw's rtw_key_set with a WEP key,
I point the key's wk_cipher at our "fake" cipher, rtw_cipher_wep,
which is alike to ieee80211_cipher_wep except it provides a different
crypto-decapsulation routine, rtw_wep_decap. rtw_wep_decap copies
the key passed to it by net80211, clears the key's SWCRYPT flag,
and then calls wep_decap. Now wep_decap will decapsulate, but it
will *not* re-decrypt.

XXX I need to check whether the hardware supports 40-bit WEP,
XXX 104-bit WEP, or both, and act accordingly.


# 1.49 27-Jun-2005 dyoung

rtw: Try to get hardware WEP to work. It seems to work in
the RX direction, but not in the TX direction. The
net80211 crypto framework doesn't seem to cope very well
with the assymetry (I'm probably missing something), so
I will use software WEP for now.

net80211: In ieee80211_compute_duration, figure out whether to add
the WEP header to the packet overhead by checking the
WEP bit in the Frame Control field of the 802.11 header,
instead of checking the IEEE80211_F_PRIVACY flag.

Also, if the WEP bit is present, assume that the frame
described by (wh, len) has already already been WEP
encapsulated, and adjust the payload length accordingly.
XXX that's a grotty hack that I will have to revisit,
later.


# 1.48 22-Jun-2005 dyoung

Resolve conflicts in importation of 18-May-2005 ath(4) / net80211(9)
from FreeBSD. Introduce compatibility shims (sys/dev/ic/ath_netbsd.[ch],
sys/net80211/ieee80211_netbsd.[ch]). Update drivers (an, atu, atw,
awi, ipw, iwi, rtw, wi) for the new net80211(9) API.


# 1.47 20-Jun-2005 atatat

Change the rest of the sysctl subsystem to use const consistently.
The __UNCONST macro is now used only where necessary and the RW macros
are gone. Most of the changes here are consumers of the
sysctl_createv(9) interface that now takes a pair of const pointers
which used not to be.


# 1.46 10-Jun-2005 dyoung

Sprinkle __UNCONST() and rename variables to quiet uiet -Wcast-qual,
-Wshadow complaints.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 yamt-km-base4 yamt-km-base3 netbsd-3-base kent-audio2-base
# 1.45 02-Mar-2005 dyoung

Misc. changes to improve ad hoc mode and to enable hostap mode:

Fix the work-around for the NIC bug where it skips to rx
descriptor 0. The driver used to skip to rx descriptor 1.
Hopefully this stops the out-of-order packet reception that
Charles Hannum saw.
When debugging is enabled, print rx-descriptor status flags
before printing the rx bit rate.

Add a debug message for when a beacon tx buffer reclamation.

Reset IFF_OACTIVE when we reset the transmitter.

Pass the consolidated LED state, a struct rtw_led_state,
to rtw_led_attach.

Choose the bit-rate for management frames (1Mb/s) at the
same place we choose for all other frames.

Do not use the NIC's short preamble or RTS options for
management frames. Label beacons for the NIC.

Following a Linux driver, take care not to zero arbitrary
bits in the TPPOLL register.

Use the new idiom for IBSS merges: disable transmitter,
kick the state machine.
Add a second descriptor to the beacon ring. The NIC seems
to like this much better.


# 1.44 27-Feb-2005 perry

nuke trailing whitespace


Revision tags: yamt-km-base2
# 1.43 31-Jan-2005 thorpej

Eliminate use of M_HASFCS.


Revision tags: yamt-km-base
# 1.42 16-Jan-2005 dyoung

branches: 1.42.2; 1.42.4;
Move the register access mode into struct rtw_regs. Change
rtw_set_access, rtw_set_access1 to match.

Add a subroutine for setting WEP keys. WEP isn't quite finished,
because I have to add the WEP header to Tx packets. Implement the
SIOCS80211NWKEY ioctl for setting WEP keys.

Program the LEDs based on operating state and packet activity.

* On a Revision F RTL8180, blink LED1 at 1Hz to indicate
scan/authenticate/associate states. In the run state, turn LED1
on. In every state, blink LED1 at 5Hz to indicate non-beacon
tx/rx activity. I would like to use two LEDs, but in all my
Rev. F instances, LED0 is not wired to an LED; instead, the
first LED is wired to indicate that the card's power is on.

* On a Revision D RTL8180, program the LEDs so that LED0 indicates
Tx, and LED1 indicates Rx. The Rx LED will blink annoyingly if
there are beacons in the air, but at least the Tx LED is useful.

* Store the hardware revision in the softc to support my futile
attempt at programming LEDs for both Rev. D and Rev. F parts;
I never did get Rev. D LEDs to work right.

* Add a debug flag RTW_DEBUG_LED for the LED transitions.

Add RTW_TPPOLL_ALL, RTW_TPPOLL_SALL to start and stop, respectively,
all of the transmit rings.

In ad hoc mode, allocate a beacon and load it into the beacon ring.
Start the ring. In one trial, the card re-transmitted the beacon
ring's contents several times before stopping. More programming
and testing for ad hoc mode is necessary. I'm not setting the
beacon flag in the transmit descriptor.

Revamp the transmit section to make better use of all the transmit
rings: beacon queue, high-, low-, and medium-priority rings. Put
beacon frames on the beacon ring. All other management frames,
and data frames, go on the medium-priority ring. Power-save data
frames go on the high-priority ring. (Note that powersaving is
not implemented!) This is a work in progress.

Send all 802.11 Management frames at 1Mbps.

After we put a packet on a transmit ring, tickle the right bit in
the TPPOLL to tell RTL8180. Stop all rings on error and in rtw_stop.

Use the RF chip type, not the RTL8180 revision, to choose between
host- and MAC-controlled RF serial I/O. Now the Netgear MA521
works.

Remove bogus definition of bit RTW_TPPOLL_FSWINT.


Revision tags: kent-audio1-beforemerge
# 1.41 04-Jan-2005 dyoung

Set initial conditions to guarantee that when read_seeprom toggles
Chip Select, it turns *on* rather than *off*.


# 1.40 04-Jan-2005 dyoung

Add the logic for IBSS merges.


# 1.39 03-Jan-2005 dyoung

sys/dev/ic/rtw.c:

Cosmetic: remove two short ladders from rtw_init. Fit the
NIC registers print-out onto one line using the RTW_PRINT_REGS
macro.

sys/dev/ic/rtwvar.h:

Add RTW_PRINT_REGS wrapper macro for rtw_print_regs. It
is a null op unless defined(RTW_DEBUG).


# 1.38 03-Jan-2005 dyoung

In sys/dev/ic/rtw.c:

Use clue from rtk(4) and re(4) to fix the rtw(4) packet
filter. Previously, I was using the wrong CRC32 function
to hash multicast addresses; to compensate, I set the
multicast filter to all 1s. Now that I hash the addresses
correctly, I do not any longer set the filter to all 1s.

In rtw_ioctl, avoid gratuitous re-initialization when the
interface flags change. If a !IFF_UP -> IFF_UP transition,
call rtw_init(); otherwise, only reload the packet filter.

In sys/dev/ic/rtwreg.h:

Put useful combinations of Receiver Control Register flags
in RTW_RCR_PKTFILT_MASK, RTW_RCR_MONITOR, and
RTW_RCR_PKTFILT_DEFAULT. (XXX RTW_RCR_MONITOR should be
called RTW_RCR_PKTFILT_MONITOR.)


# 1.37 02-Jan-2005 dyoung

Cosmetic: change u_int{8,16,32,64}_t to C99-style uint{8,16,32,64}_t,
which is preferred.


# 1.36 29-Dec-2004 dyoung

In rtw_detach, flag the rtw as "invalid" (RTW_F_INVALID). Do not
try to power-down the RF section of an invalid rtw.

The radiotap signal quality field is 16, not 8, bits wide. Convert
the byte order.


# 1.35 29-Dec-2004 dyoung

Remove some dead code.


# 1.34 29-Dec-2004 dyoung

I like the tlp/atw-style names for software descriptors, txsoft,
better than txctl. Change from rtw_txctl/rtw_rxctl to
rtw_txsoft/rtw_rxsoft. Change the descriptor blocks' names to
match: rtw_txctl_blk becomes rtw_txsoft_blk. Change the member-name
prefixes for both software and hardware descriptors.


# 1.33 29-Dec-2004 dyoung

Consolidate variables related to the rx ring in sc_rxdesc_blk,
which is a struct rtw_rxdesc_blk.

Put a copy of the DMA tag and the DMA map into the rx- and tx-ring
blocks so that I don't have to pass them to subroutines all of the
time.


# 1.32 28-Dec-2004 dyoung

Add bpf(4) packet taps to rtw(4). Now you can tap DLT_EN10MB
(Ethernet II), DLT_IEEE802_11 (802.11), and DLT_IEEE802_11_RADIO
(radiotap + 802.11).


# 1.31 28-Dec-2004 dyoung

If defined(RTW_DEBUG), provide a sysctl (hw.rtw.rxbufs_limit) for
limiting the number of rx buffers an rtw may allocate. Use this
sysctl to test the code that copes with buffer exhaustion.

Allocate at most RTW_RXQLEN rx buffers, stopping at the sysctl
limit. Record in sc_nrxdesc how many were allocated, and put the
end-of-ring indication on sc_rxdesc[sc_nrxdesc - 1]. In rtw_init,
if no rx buffers could be allocated, log a complaint, clear
IFF_RUNNING, and exit with an error.

Many changes to accomodate a short rx ring, mainly of the "add a
rx-ring length argument" variety. XXX I really should consolidate
all of the rx ring variables in one struct and pass that to the
rx-ring subroutines.

Bug fix: after calling MCLGET, use the (m->m_flags & M_EXT) idiom
to check for success, instead of m != NULL.

Bug fix: at the top of rtw_start, if IFF_RUNNING is not set, or
IFF_OACTIVE is, get out.


# 1.30 27-Dec-2004 dyoung

Use a table to convert the hardware's bit rates (0, 1, 2, 3) to
net80211 bit rates (2, 4, 11, 22).

Count input errors (if_ierrors++) for "DMA error/FIFO overflow"
and unknown bit rate.


# 1.29 27-Dec-2004 dyoung

Simplify the reset we do on a transmit timeout. Really, this could
be as simple as rtw_stop(, 0), rtw_init().


# 1.28 27-Dec-2004 mycroft

Use the last descriptor to count collisions and failed transmissions, too.


# 1.27 27-Dec-2004 mycroft

When checking if a split packet is completed, check the *last* segment, not
the first. Otherwise we can overwrite parts of the TX ring that we shouldn't.

Kluge the basic rate setting for now.

Minor simplification to the dequeueing logic.


# 1.26 27-Dec-2004 dyoung

Remove useless debug sysctls.

For AP scanning, change the channel dwell time from 1 second to
1/5 second.


# 1.25 27-Dec-2004 mycroft

Replace d_plcp_svc with d_residue. The latter is the number of whole
empty/unused octets to fill out the data time slot. The value is constrained
by math to 0 for <= 5.5Mb, 0-1 for 11Mb, and 0-2 for 22Mb. It is used to
signal to the MAC that there is residue.


# 1.24 26-Dec-2004 dyoung

Make rtw(4) build w/o RTW_DEBUG. Thanks to Charles Hannum for
pointing out my oversight.


# 1.23 25-Dec-2004 dyoung

The rx descriptor ring bug happens quite often, so printf'ing
occurrences is annoying. Only printf about it when rtw_debug
contains RTW_DEBUG_BUG.


# 1.22 25-Dec-2004 dyoung

IMPORTANT: set m->m_pkthdr.rcvif on rx'd packets. Illegal memory
references abound without this fix.

In rtw_intr_rx, skip to the next rx packet earlier if the rx packet
length is too short.

Also in rtw_intr_rx, if a packet is rx'd with unknown rate, printf
a warning, drop the packet, recycle the rx buffer, skip to next rx
packet.


# 1.21 25-Dec-2004 dyoung

Change rtw_debug from a debug level to a debug mask. Add a lot of
debug flags.

From Linux: handle an RTL8180 bug. Sometimes the NIC skips from
the middle of the ring to the 0th rx descriptor. Now the driver
resynchronizes.

Handle a receive descriptor underrun or Rx FIFO overflow condition
in the way that the Linux driver does. This kind of seems like
overkill, but whatever.

Protect rtw_ioctl with splnet().

Do not load a tx descriptor with a buffer shorter than 4 bytes.

Handle a transmit timeout less disruptively.


# 1.20 23-Dec-2004 dyoung

Oops, straggler from last commit: set the 802.11 Duration field
with the result from ieee80211_compute_duration.


# 1.19 23-Dec-2004 dyoung

Fix a bug in ieee80211_compute_duration: the 802.11 Duration field
in an 802.11 unicast data packet is equal to the duration of the
SIFS and Acknowledgement. That is, the amount of time reserved
*after* the packet has finished transmitting.

Change the arguments to ieee80211_compute_duration: pass the entire
packet length, not just the payload length. Add a 'debug' argument
to ieee80211_compute_duration and its helper subroutine,
ieee80211_compute_duration1.

If debug != 0, ieee80211_compute_duration printfs its arguments
and several local variables.

In rtw(4), load the 802.11 Duration field with the result from
ieee80211_compute_duration.


# 1.18 23-Dec-2004 dyoung

Bug fix: in rtw_rxbuf_alloc, unload the previous mbuf chain before
loading the new chain.


# 1.17 23-Dec-2004 dyoung

DMA-synchronize the Rx buffers before re-initializing them.
XXX not necessary?


# 1.16 23-Dec-2004 dyoung

Add more comprehensive debug messages as we setup transmit descriptors.
Also, dump packets if IFF_DEBUG|IFF_LINK2. Factor out a subroutine
for printing transmit-descriptor debug messages.


# 1.15 23-Dec-2004 dyoung

Disable interrupts and stop transmit DMA before disabling the
transmitter and receiver.


# 1.14 23-Dec-2004 dyoung

Shorten variables, s/txctl/ctl/. This is rtw_start, after all:
transmission is implied.


# 1.13 23-Dec-2004 dyoung

Do not indicate to the NIC that the host has appended the CRC32 to
Tx frames.


# 1.12 23-Dec-2004 dyoung

When we set up the supported rates table, mark 1Mb/s, 2Mb/s as
basic rates.


# 1.11 23-Dec-2004 dyoung

Extract the transmission status from a tx descriptor, and convert
to host byte-order, once.


# 1.10 20-Dec-2004 dyoung

Realtek sample sources are not consistent about the "Digital PHY"
bit in the SROM. It seems as if it is set to 1 when the PHY is
*analog*, not *digital*. Fix my sources.

In rtw_intr_rx, use units of 500kb/s instead of 100kb/s for rate,
to be consistent with net80211's expectations. Polish up some
debugging ugly messages. Dump raw 802.11 packets if IFF_DEBUG|IFF_LINK2
and RTW_DEBUG is defined.

Polish power-state (on/sleep/off) handling. Especially improve
support for RFMD (totally untested) and Maxim. For Philips, take
the Digital PHY property into account.

Call the net80211 watchdog function from rtw_watchdog, so that we
scan again if auth/assoc fails.

Be a little more cautious about writing register[RTW_TPPOLL], since
other drivers are.... Don't frob the high/low-priority queues
right now, since I don't use them.

Add rtw_join_bss which programs the card with the BSSID and other
properties of a BSS. Use it on state transitions. Factor out
rtw_set_nettype.

Make rtw_recv_beacon call ieee80211_recv_mgmt instead of dropping
beacons on the floor! TBD IBSS merges.

Change some rtw_debug=2 printfs to rtw_debug=3 (RTW_DPRINTF3)
printfs so the console doesn't get spammed so badly at rtw_debug=2.
Change some debugging printfs to RTW_DPRINTFs. E.g., print the
"RF programming method" only if debugging is enabled.


# 1.9 20-Dec-2004 dyoung

Fix bug in last commit: use &sc->sc_regs, regs is not defined.


# 1.8 20-Dec-2004 dyoung

Add some bus barriers. Remark where they are needed, e.g.,
read_eeprom.

Change some printfs to RTW_DPRINTF2s to quiet rtw(4) when debugging
is disabled.


# 1.7 20-Dec-2004 dyoung

Get rid of the silly char (*dvname)[IFNAMSIZ] pattern. Replace it
with const char *dvname. I'm not sure what I was thinking.


# 1.6 20-Dec-2004 dyoung

Assert that I'm DMA-syncing a non-negative number of transmit
descriptors.

As I free dirty transmit buffers, move them to the free list, not
back to the dirty list!

Add a 5-second transmit timeout.


# 1.5 19-Dec-2004 dyoung

Add the transmit section of rtw(4): build up and tear down transmit
descriptor rings, move packets from the transmit queues to the
transmit rings, handle transmission-completed interrupts. My
Linksys WPC11 ver. 4 with Maxim RF, generates interrupts like it
is successfully transmitting packets. Clearly there are bugs: my
G4 Powerbook locks up hard. I will debug tomorrow.


# 1.4 13-Dec-2004 dyoung

At last, I have rtw w/ Philips RF receiving packets.

I added some sysctls to aid debugging:

* hw.rtw.debug -- enable debugging

* hw.rtw.flush_rfio -- Linux voodoo: possibly makes the MAC
"flush" bits down the serial bus to the RF

* hw.rtw.host_rfio: force the host to bang bits to the RF, instead
of the MAC banging bits

* hw.rtw.rfio_delay: after telling the MAC to bang bits to the
RF front-end, delay rfio_delay microseconds.

* hw.rtw.rfprog_fallback: there is this notion of the "RF
programming method." I believe the choice influences the
polarity/timing of the serial bus used to program the RF
front-end. I know the correct choice for Intersil/RFMD/Philips
front-ends, only. For all other front-ends, I "fallback" to
rfprog_fallback.

Make rtw_txdac_enable take an rtw_softc argument. I will probably
revert this change.

Add some Linux voodoo to rtw_continuous_tx_enable. I will probably
revert this change.

Important: add rtw_set_rfprog, which sets the correct RF programming
method. This change and the following change are probably responsible
for making the Philips RF work.

Important: RTW_CONFIG1 is an 8-bit register, treat it that way!

Important: RTW_BRSR is 16-bit, RTW_CRCOUNT, RTW_PHYDELAY, and
RTW_MSR are 8-bit: treat them that way!

Vastly simplify rtw_resume_ticks.

Note to self: set the LED state to match the power state.

Hedge against the possibility that RTW_MSR is protected as
RTW_CONFIG[0123] are, meanwhile reworking that section of rtw_init
a little.

Add sc_anaparm, which isn't used, yet....


# 1.3 12-Dec-2004 dyoung

Miscellaneous changes. Details below. Important changes flagged
with []. Using the driver with my Linksys WPC11 ver. 4, it seems
to be receiving packets for a change. The WPC11 ver. 4 has a Maxim
RF section. My no-name rtw with Philips RF section still does not
receive any packets.

Keep access-level (analog params > config[0123] registers > none)
in sc_access. Add rtw_set_access for changing the access level.

Make rtw_continuous_tx_enable and other subroutines use rtw_set_access
instead of rtw_config0123_enable and rtw_anaparm_enable.

Factor part of the chip-reset code into rtw_chip_reset1.

Change the 'struct foo (*bar)[N]'-style arguments to
'struct foo *bar'-style arguments.

Consolidate software/hardware Tx/Rx ring setup in rtw_hwring_setup,
rtw_swring_setup.

Add a new constant, SA2400_OPMODE_DEFAULTS, for the bits that we
*always* set in the SA2400 OPMODE register.

Factor some code out into rtw_sa2400_calibrate. (Inspired by the
Linux driver.)

[] When the receiver goes into underrun/overflow state, call a new
subroutine, rtw_kick() that stops the Rx/Tx processes, resets
the chip, reinitializes the Tx/Rx rings, and restarts Rx/Tx
processes. (Inspired by the Linux driver.)

[] In rtw_intr_rx, check for too-short packets before calling
ieee80211_find_rxnode. I believe this will prevent a repeat of
the MCHK exception I saw once on macppc.

[] Use seconds-elapased as well as microseconds-elapsed to set the
next "due date" for the timeout interrupt. This keeps the driver
from programming the timeout to expire too early.

[] In rtw_intr, read RTW_ISR at most 10 times, then get out. If
the interface is not enabled (RTW_F_ENABLED), then get out.

[] In rtw_stop, get out if the interface is not enabled (RTW_F_ENABLED).
Block IPL_NET interrupts. Don't read/write any registers if
the interface is invalid (RTW_F_INVALID).

[] Call rtw_stop in rtw_detach.


Revision tags: kent-audio1-base
# 1.2 30-Oct-2004 thorpej

When adding/deleting multicast addresses, only whack the address
filter if the interface is marked RUNNING.

Fixes kern/27678.


# 1.1 26-Sep-2004 dyoung

branches: 1.1.2;
Add work-in-progress driver rtw(4) for Realtek RTL8180 MAC/baseband.

Add register definitions for Maxim MAX2820 and Philips SA2400 radio
front-ends.


# 1.135 29-Jan-2020 thorpej

Adopt <net/if_stats.h>.


Revision tags: ad-namecache-base2 ad-namecache-base1 ad-namecache-base phil-wifi-20191119
# 1.134 10-Nov-2019 chs

in many device attach paths, allocate memory with M_WAITOK instead of M_NOWAIT
and remove code to handle failures that can no longer happen.


Revision tags: netbsd-9-0-RC1 netbsd-9-base phil-wifi-20190609
# 1.133 28-May-2019 msaitoh

Use ETHER_LOCK()/ETHER_UNLOCK() for all ethernet drivers to protect ec_multi*.


# 1.132 23-May-2019 msaitoh

Whitespace fix (mainly tabify).


# 1.131 23-May-2019 msaitoh

-No functional change:
- KNF
- u_int*_t -> uint*_t.


Revision tags: isaki-audio2-base
# 1.130 05-Feb-2019 msaitoh

Remove very old IFF_NOTRAILERS flag.


# 1.129 03-Feb-2019 mrg

- add or adjust /* FALLTHROUGH */ where appropriate
- add __unreachable() after functions that can return but won't in
this case, and thus can't be marked __dead easily


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 jdolecek-ncqfixes-base pgoyette-compat-0728 phil-wifi-base
# 1.128 26-Jun-2018 msaitoh

branches: 1.128.2;
Implement the BPF direction filter (BIOC[GS]DIRECTION). It provides backward
compatibility with BIOC[GS]SEESENT ioctl. The userland interface is the same
as FreeBSD.

This change also fixes a bug that the direction is misunderstand on some
environment by passing the direction to bpf_mtap*() instead of checking
m->m_pkthdr.rcvif.


Revision tags: pgoyette-compat-0625 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base tls-maxphys-base-20171202
# 1.127 23-Oct-2017 msaitoh

branches: 1.127.2;
If if_initialize() failed in the attach function, free resources and return.


Revision tags: matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base
# 1.126 23-May-2017 ozaki-r

branches: 1.126.2;
Apply deferred if_start to more drivers

And annotate some XXX_start as it runs in softint to clarify that
it doesn't need deferred if_start.


Revision tags: prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 nick-nhusb-base-20170204
# 1.125 02-Feb-2017 nonaka

wlan interfaces make interrupt routine running on softint context.

see http://mail-index.netbsd.org/tech-kern/2016/12/06/msg021281.html

tested device:
* ath at pci: AR5212, AR5424
* athn at pci: AR9287
* ipw at pci: 2100BG
* iwi at pci: 2915ABG
* iwm at pci: 3165, 7260, 8260
* iwn at pci: 4945, 6235
* ral at pci: RT2560
* rtwn at pci: RTL8192CE


Revision tags: bouyer-socketcan-base pgoyette-localcount-20170107 nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.124 15-Sep-2016 jdolecek

branches: 1.124.2;
remove last isolated islands using BUS_SPACE_BARRIER_SYNC and
BUS_SPACE_BARRIER_X_BEFORE_X - these were only ever defined for mips and ia64,
and never actually implemented even there


Revision tags: localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907
# 1.123 10-Jun-2016 ozaki-r

branches: 1.123.2;
Introduce m_set_rcvif and m_reset_rcvif

The API is used to set (or reset) a received interface of a mbuf.
They are counterpart of m_get_rcvif, which will come in another
commit, hide internal of rcvif operation, and reduce the diff of
the upcoming change.

No functional change.


Revision tags: nick-nhusb-base-20160529
# 1.122 16-May-2016 ozaki-r

Use M_GETCTX and M_SETCTX instead of open-coding rcvif

No functional change.


Revision tags: netbsd-7-2-RELEASE netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 netbsd-7-0-RELEASE nick-nhusb-base-20150921 netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 nick-nhusb-base-20150606 nick-nhusb-base-20150406 nick-nhusb-base netbsd-7-base yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 rmind-smpnet-nbase rmind-smpnet-base tls-maxphys-base
# 1.121 25-Feb-2014 pooka

branches: 1.121.6;
Ensure that the top level sysctl nodes (kern, vfs, net, ...) exist before
the sysctl link sets are processed, and remove redundancy.

Shaves >13kB off of an amd64 GENERIC, not to mention >1k duplicate
lines of code.


# 1.120 17-Oct-2013 christos

- remove unused variables
- move variables inside ifdef sections
- ifdef notdef unused code
- use __USE for debugging variables


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE yamt-pagecache-tag8 netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 agc-symver-base netbsd-6-1-RC2 netbsd-6-1-RC1 yamt-pagecache-base8 netbsd-6-0-1-RELEASE yamt-pagecache-base7 matt-nb6-plus-nbase yamt-pagecache-base6 netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base10 yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.119 04-Jul-2011 joerg

branches: 1.119.2; 1.119.12; 1.119.16;
Fix memset usage.


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base matt-mips64-premerge-20101231 rmind-uvmplock-base
# 1.118 15-Nov-2010 uebayasi

Socket ioctl definitions need sys/sockio.h.


# 1.117 13-Nov-2010 uebayasi

Don't pull in the whole uvm(9) API to access only PAGE_SIZE and
some other constants. These are provided by sys/param.h now.


Revision tags: uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10 uebayasi-xip-base1
# 1.116 05-Apr-2010 joerg

Push the bpf_ops usage back into bpf.h. Push the common ifp->if_bpf
check into the inline functions as well the fourth argument for
bpf_attach.


# 1.115 15-Mar-2010 dyoung

Make this compile on sparc64:

1 s/next_tick/next_tint/ because next_tick shadows a global on sparc64.

2 Fix the bus-barrier helper routines, which had the tag & handle
swapped (!!). Move the helpers from rtwreg.h to rtwvar.h, and
change RTW_BARRIER() into an inline subroutine called rtw_barrier().


Revision tags: yamt-nfs-mp-base9
# 1.114 24-Feb-2010 dyoung

branches: 1.114.2;
A pointer typedef entails trading too much flexibility to declare const
and non-const types, and the kernel uses both const and non-const
PMF qualifiers and device suspensors, so change the pmf_qual_t and
device_suspensor_t typedefs from "pointers to const" to non-pointer,
non-const types.


Revision tags: uebayasi-xip-base
# 1.113 31-Jan-2010 dyoung

branches: 1.113.2;
Add the missing newline to a verbose autoconf message.


# 1.112 19-Jan-2010 pooka

Redefine bpf linkage through an always present op vector, i.e.
#if NBPFILTER is no longer required in the client. This change
doesn't yet add support for loading bpf as a module, since drivers
can register before bpf is attached. However, callers of bpf can
now be modularized.

Dynamically loadable bpf could probably be done fairly easily with
coordination from the stub driver and the real driver by registering
attachments in the stub before the real driver is loaded and doing
a handoff. ... and I'm not going to ponder the depths of unload
here.

Tested with i386/MONOLITHIC, modified MONOLITHIC without bpf and rump.


# 1.111 08-Jan-2010 dyoung

Expand PMF_FN_* macros.


Revision tags: matt-premerge-20091211 jym-xensuspend-nbase
# 1.110 19-Oct-2009 rmind

Drop 3rd and 4th clauses from David Young's license.
Reviewed and approved by dyoung@ (copyright holder).


# 1.109 16-Sep-2009 dyoung

In pmf(9), improve the implementation of device self-suspension
and make suspension by self, by drvctl(8), and by ACPI system sleep
play nice together. Start solidifying some temporary API changes.

1. Extract a new header file, <sys/device_if.h>, from <sys/device.h> and
#include it from <sys/pmf.h> instead of <sys/device.h> to break the
circular dependency between <sys/device.h> and <sys/pmf.h>.

2. Introduce pmf_qual_t, an aggregate of qualifications on a PMF
suspend/resume call. Start to replace instances of PMF_FN_PROTO,
PMF_FN_ARGS, et cetera, with a pmf_qual_t.

3. Introduce the notion of a "suspensor," an entity that holds a
device in suspension. More than one suspensor may hold a device
at once. A device stays suspended as long as at least one
suspensor holds it. A device resumes when the last suspensor
releases it.

Currently, the kernel defines three suspensors,

3a the system-suspensor: for system suspension, initiated
by 'sysctl -w machdep.sleep_state=3', by lid closure, by
power-button press, et cetera,

3b the drvctl-suspensor: for device suspension by /dev/drvctl
ioctl, e.g., drvctl -S sip0.

3c the system self-suspensor: for device drivers that suspend
themselves and their children. Several drivers for network
interfaces put the network device to sleep while it is not
administratively up, that is, after the kernel calls if_stop(,
1). The self-suspensor should not be used directly. See
the description of suspensor delegates, below.

A suspensor can have one or more "delegates". A suspensor can
release devices that its delegates hold suspended. Right now,
only the system self-suspensor has delegates. For each device
that a self-suspending driver attaches, it creates the device's
self-suspensor, a delegate of the system self-suspensor.

Suspensors stop a system-wide suspend/resume cycle from waking
devices that the operator put to sleep with drvctl before the cycle.
They also help self-suspension to work more simply, safely, and in
accord with expectations.

4. Add the notion of device activation level, devact_level_t,
and a routine for checking the current activation level,
device_activation(). Current activation levels are DEVACT_LEVEL_BUS,
DEVACT_LEVEL_DRIVER, and DEVACT_LEVEL_CLASS, which respectively
indicate that the device's bus is active, that the bus and device are
active, and that the bus, device, and the functions of the device's
class (network, audio) are active.

Suspend/resume calls can be qualified with a devact_level_t.
The power-management framework treats a devact_level_t that
qualifies a device suspension as the device's current activation
level; it only runs hooks to reduce the activation level from
the presumed current level to the fully suspended state. The
framework treats a devact_level_t qualifying device resumption
as the target activation level; it only runs hooks to raise the
activation level to the target.

5. Use pmf_qual_t, devact_level_t, and self-suspensors in several
drivers.

6. Temporarily add an unused power-management workqueue that I will
remove or replace, soon.


Revision tags: yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5 yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 nick-hppapmap-base3 jym-xensuspend-base nick-hppapmap-base
# 1.108 07-Apr-2009 dyoung

Cosmetic: remove some dead code.


# 1.107 02-Apr-2009 dyoung

Add the WEP capability to our net80211 capability flags, since we do
sort of support hardware WEP. Only change the WEP key index in a Tx
descriptor from 0 if the type of our transmit key is _WEP, not _TKIP:
i.e., only if we're really doing WEP crypto in the hardware.

Ignore a watchdog timeout on any Tx ring if we can collect some packets
from that ring. Restart both the receiver and the transmitter when a
watchdog timeout occurs instead of restarting only the transmitter.


Revision tags: nick-hppapmap-base2 haad-dm-base2 haad-nbase2 ad-audiomp2-base haad-dm-base mjf-devfs2-base
# 1.106 12-Nov-2008 ad

branches: 1.106.4;
Remove LKMs and switch to the module framework, pass 1.

Proposed on tech-kern@.


# 1.105 07-Nov-2008 dyoung

*** Summary ***

When a link-layer address changes (e.g., ifconfig ex0 link
02:de:ad:be:ef:02 active), send a gratuitous ARP and/or a Neighbor
Advertisement to update the network-/link-layer address bindings
on our LAN peers.

Refuse a change of ethernet address to the address 00:00:00:00:00:00
or to any multicast/broadcast address. (Thanks matt@.)

Reorder ifnet ioctl operations so that driver ioctls may inherit
the functions of their "class"---ether_ioctl(), fddi_ioctl(), et
cetera---and the class ioctls may inherit from the generic ioctl,
ifioctl_common(), but both driver- and class-ioctls may override
the generic behavior. Make network drivers share more code.

Distinguish a "factory" link-layer address from others for the
purposes of both protecting that address from deletion and computing
EUI64.

Return consistent, appropriate error codes from network drivers.

Improve readability. KNF.

*** Details ***

In if_attach(), always initialize the interface ioctl routine,
ifnet->if_ioctl, if the driver has not already initialized it.
Delete if_ioctl == NULL tests everywhere else, because it cannot
happen.

In the ioctl routines of network interfaces, inherit common ioctl
behaviors by calling either ifioctl_common() or whichever ioctl
routine is appropriate for the class of interface---e.g., ether_ioctl()
for ethernets.

Stop (ab)using SIOCSIFADDR and start to use SIOCINITIFADDR. In
the user->kernel interface, SIOCSIFADDR's argument was an ifreq,
but on the protocol->ifnet interface, SIOCSIFADDR's argument was
an ifaddr. That was confusing, and it would work against me as I
make it possible for a network interface to overload most ioctls.
On the protocol->ifnet interface, replace SIOCSIFADDR with
SIOCINITIFADDR. In ifioctl(), return EPERM if userland tries to
invoke SIOCINITIFADDR.

In ifioctl(), give the interface the first shot at handling most
interface ioctls, and give the protocol the second shot, instead
of the other way around. Finally, let compatibility code (COMPAT_OSOCK)
take a shot.

Pull device initialization out of switch statements under
SIOCINITIFADDR. For example, pull ..._init() out of any switch
statement that looks like this:

switch (...->sa_family) {
case ...:
..._init();
...
break;
...
default:
..._init();
...
break;
}

Rewrite many if-else clauses that handle all permutations of IFF_UP
and IFF_RUNNING to use a switch statement,

switch (x & (IFF_UP|IFF_RUNNING)) {
case 0:
...
break;
case IFF_RUNNING:
...
break;
case IFF_UP:
...
break;
case IFF_UP|IFF_RUNNING:
...
break;
}

unifdef lots of code containing #ifdef FreeBSD, #ifdef NetBSD, and
#ifdef SIOCSIFMTU, especially in fwip(4) and in ndis(4).

In ipw(4), remove an if_set_sadl() call that is out of place.

In nfe(4), reuse the jumbo MTU logic in ether_ioctl().

Let ethernets register a callback for setting h/w state such as
promiscuous mode and the multicast filter in accord with a change
in the if_flags: ether_set_ifflags_cb() registers a callback that
returns ENETRESET if the caller should reset the ethernet by calling
if_init(), 0 on success, != 0 on failure. Pull common code from
ex(4), gem(4), nfe(4), sip(4), tlp(4), vge(4) into ether_ioctl(),
and register if_flags callbacks for those drivers.

Return ENOTTY instead of EINVAL for inappropriate ioctls. In
zyd(4), use ENXIO instead of ENOTTY to indicate that the device is
not any longer attached.

Add to if_set_sadl() a boolean 'factory' argument that indicates
whether a link-layer address was assigned by the factory or some
other source. In a comment, recommend using the factory address
for generating an EUI64, and update in6_get_hw_ifid() to prefer a
factory address to any other link-layer address.

Add a routing message, RTM_LLINFO_UPD, that tells protocols to
update the binding of network-layer addresses to link-layer addresses.
Implement this message in IPv4 and IPv6 by sending a gratuitous
ARP or a neighbor advertisement, respectively. Generate RTM_LLINFO_UPD
messages on a change of an interface's link-layer address.

In ether_ioctl(), do not let SIOCALIFADDR set a link-layer address
that is broadcast/multicast or equal to 00:00:00:00:00:00.

Make ether_ioctl() call ifioctl_common() to handle ioctls that it
does not understand.

In gif(4), initialize if_softc and use it, instead of assuming that
the gif_softc and ifp overlap.

Let ifioctl_common() handle SIOCGIFADDR.

Sprinkle rtcache_invariants(), which checks on DIAGNOSTIC kernels
that certain invariants on a struct route are satisfied.

In agr(4), rewrite agr_ioctl_filter() to be a bit more explicit
about the ioctls that we do not allow on an agr(4) member interface.

bzero -> memset. Delete unnecessary casts to void *. Use
sockaddr_in_init() and sockaddr_in6_init(). Compare pointers with
NULL instead of "testing truth". Replace some instances of (type
*)0 with NULL. Change some K&R prototypes to ANSI C, and join
lines.


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 wrstuden-revivesa-base-1 simonb-wapbl-nbase yamt-pf42-base4 simonb-wapbl-base yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 yamt-nfs-mp-base2 wrstuden-revivesa-base yamt-nfs-mp-base yamt-pf42-base ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 1.104 15-Mar-2008 dyoung

branches: 1.104.4; 1.104.10; 1.104.12;
Cosmetic: make rtw_hw_keysupp() return a bool instead of int. In
rtw_wep_setkeys(), add a debug printf, and move the initialization
of keylen from the for-loop to the declaration.


# 1.103 14-Mar-2008 dyoung

Extract subroutine rtw_tx_kick() from rtw_start(), and reuse it in
rtw_io_enable() to restart the transmitter after resetting it.


# 1.102 14-Mar-2008 dyoung

Change tests for "impossible" keys to KASSERT()s. Get rid of a
temporary variable. In rtw_key_delete(), do not invalidate the
hardware keys unless a WEP key is deleted.


# 1.101 12-Mar-2008 dyoung

Use device_t and its accessors throughout. Use aprint_*_dev().

Improve PMF-ability.

Add a 'flags' argument to suspend/resume handlers and
callers such as pmf_system_suspend().

Define a flag, PMF_F_SELF, which indicates to PMF that a
device is suspending/resuming itself. Add helper routines,
pmf_device_suspend_self(dev) and pmf_device_resume_self(dev),
that call pmf_device_suspend(dev, PMF_F_SELF) and
pmf_device_resume(dev, PMF_F_SELF), respectively. Use
PMF_F_SELF to suspend/resume self in ath(4), audio(4),
rtw(4), and sip(4).

In ath(4) and in rtw(4), replace the icky sc_enable/sc_disable
callbacks, provided by the bus front-end, with
self-suspension/resumption. Also, clean up the bus
front-ends. Make sure that the interrupt handler is
disestablished during suspension. Get rid of driver-private
flags (e.g., RTW_F_ENABLED, ath_softc->sc_invalid); use
device_is_active()/device_has_power() calls, instead.

In the network-class suspend handler, call if_stop(, 0)
instead of if_stop(, 1), because the latter is superfluous
(bus- and driver-suspension hooks will 'disable' the NIC),
and it may cause recursion.

In the network-class resume handler, prevent infinite
recursion through if_init() by getting out early if we are
self-suspending (PMF_F_SELF).

rtw(4) improvements:

Destroy rtw(4) callouts when we detach it. Make rtw at
pci detachable. Print some more information with the "rx
frame too long" warning.

Remove activate() methods:

Get rid of rtw_activate() and ath_activate(). The device
activate() methods are not good for much these days.

Make ath at cardbus resume with crypto functions intact:

Introduce a boolean device property, "pmf-powerdown". If
pmf-powerdown is present and false, it indicates that a
bus back-end should not remove power from a device.

Honor this property in cardbus_child_suspend().

Set this property to 'false' in ath_attach(), since removing
power from an ath at cardbus seems to lobotomize the WPA
crypto engine. XXX Should the pmf-powerdown property
propagate toward the root of the device tree?

Miscellaneous ath(4) changes:

Warn if ath(4) tries to write crypto keys to suspended
hardware.

Reduce differences between FreeBSD and NetBSD in ath(4)
multicast filter setup.

Make ath_printrxbuf() print an rx descriptor's status &
key index, to help debug crypto errors.

Shorten a staircase in ath_ioctl(). Don't check for
ieee80211_ioctl() return code ERESTART, it never happens.


# 1.100 12-Mar-2008 dyoung

Print the TPPoll register when the Tx DMA engine doesn't shut down
in the time we allow.


# 1.99 03-Mar-2008 tsutsui

Explicitly include <sys/device.h> for device_t.


Revision tags: nick-net80211-sync-base vmlocking2-base3 bouyer-xeni386-nbase bouyer-xeni386-base mjf-devfs-base matt-armv6-base hpcarm-cleanup-base
# 1.98 21-Dec-2007 dyoung

branches: 1.98.2; 1.98.6;
Do not embed a struct device in rtw_softc any longer. Register
both pci and cardbus attachments with CFATTACH_DECL_NEW(). Access
the softc through the device_t using device_private().

While I'm here, change a couple of KASSERT()s about the Rx buffer
length to a warning.


# 1.97 20-Dec-2007 dyoung

Remove shutdown hooks. Use KASSERT().


# 1.96 16-Dec-2007 dyoung

Fix a bug I introduced to rtw_chan2txpower() the other night.

Fix a bug in device detachment: change a break statement to a
/*FALLTHROUGH*/ in rtw_detach().


# 1.95 16-Dec-2007 dyoung

Synchronize device detachment with network interrupts. Use the
pmf network class instead of powerhooks.


Revision tags: yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 bouyer-xenamd64-base2 vmlocking-nbase bouyer-xenamd64-base jmcneill-pm-base reinoud-bufcleanup-base
# 1.94 18-Nov-2007 jnemeth

branches: 1.94.2; 1.94.6;
fix 'm' used unitialized


# 1.93 16-Nov-2007 dyoung

Accommodate the variety of RF front-ends when radiotapping frames:
tap only RSSI when there is a Philips RF front-end. Tap both Barker
lock quality and RSSI when there is any other RF front-end.

Provide radiotap listeners a more complete picture of channel
activity:

in promiscuous mode, tap frames who do not pass the CRC32 check.
Flag packets that were received with a short preamble. Ask
the NIC to pass us 802.11 Control frames. Pass frames to
radiotap listeners before stripping the FCS. Re-order operations
in rtw_intr_rx() in order to accomplish all of this, taking
care not to pass a broken packet to net80211!

Do not provide a flags field when tapping xmitted frames.

Assert sane Rx packet lengths. Really should check and drop instead
of KASSERTing. I will revisit this, soon.

Update copyright.


# 1.92 15-Nov-2007 dyoung

Fix order of operations:

rtw_rxdesc_init: before initializing a Rx descriptor's
control word, synchronize the Rx buffer

rtw_start, be paranoid: set the "NIC owns" bit on a Tx
descriptor dead last. Always reinitialize the "next
Tx descriptor" pointer, just in case it got clobbered
somehow.

Let the compiler decide whether to inline rtw_collect_txring or
not.


Revision tags: jmcneill-base
# 1.91 19-Oct-2007 ad

branches: 1.91.2;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h


Revision tags: yamt-x86pmap-base4 yamt-x86pmap-base3 yamt-x86pmap-base2 vmlocking-base
# 1.90 29-Sep-2007 scw

branches: 1.90.2;
s/NPBFILTER/NBPFILTER/ in some #endif comments. No functional change.


Revision tags: nick-csl-alignment-base5 yamt-x86pmap-base matt-mips64-base nick-csl-alignment-base mjf-ufs-trans-base
# 1.89 09-Jul-2007 ad

branches: 1.89.6; 1.89.8; 1.89.10;
Merge some of the less invasive changes from the vmlocking branch:

- kthread, callout, devsw API changes
- select()/poll() improvements
- miscellaneous MT safety improvements


# 1.88 29-May-2007 dyoung

Fix rtw(4) on NetBSD/macppc: use bus_space_write_region_stream_4()
instead of bus_space_write_region_4() to write WEP Rx keys to the
NIC. Thanks macallan@ for detecting the bug and testing the fix.


# 1.87 29-May-2007 dyoung

Cosmetic: simplify a memset() statement, use __arraycount(), and
remove a gratuitous return statement at the end of a void subroutine.


# 1.86 29-May-2007 dyoung

Simplify multicast filter programming, and take care to avoid
gratuitous device resets when the kernel adds/deletes a multicast
address.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base
# 1.85 04-Mar-2007 christos

branches: 1.85.2; 1.85.4;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.


Revision tags: ad-audiomp-base post-newlock2-merge newlock2-nbase newlock2-base
# 1.84 29-Jan-2007 dyoung

branches: 1.84.2;
In rtw_dequeue(), initialize *mp to NULL before anything else, so
that it is either NULL or a valid mbuf. Previously, it was possible
for rtw_dequeue() to exit with 0 before initializing *mp. rtw_start()
would have used whatever trash was in *mp, which would lead to
problems later on.


# 1.83 06-Jan-2007 dyoung

I have made a small change that suppresses "recovery" from (spurious?)
tx timeouts on the beacon queue. The driver's recovery process
badly disrupts the MAC's receiver. This needs a closer look, later.

Every other fix is by Charles M. Hannum. Charles writes:

"With these, the device is quite stable under load, does not experience
xmit timeouts, no longer mysteriously freezes, and does not spew
a lot of garbage. It does, however, continue to get some "tx fifo
underflow"s.

global, SYSCTL_SETUP():
a) Removed unused sysctl variables.

rtw_io_enable():
b) Change rtw_io_enable to take a softc, and make it call
rtw_txring_fixup().
c) Enable the PCI multiple read/write bit.
d) Always reset rdb_next to 0 when starting the receive engine.

rtw_intr_rx():
e) When processing receive packets, store the next pointer in rdb_next
and read it back on the next round, to fix a race condition vs.
rtw_tune() during AP discovery and association.
f) Remove the special "skip to 0th descriptor" code, because it is no
longer needed.

rtw_collect_txring():
g) In the "force" case, stop when we catch up to the hardware xmit
pointer.

rtw_intr_beacon():
h) Resetting tdb_next here looked fishy to me, in light of changes in
rtw_collect_txring(). XXX However, this is the one part I haven't
tested.

rtw_txring_fixup():
i) Add function and line arguments, so we can print out information
about the caller.
j) In addition to reading the hardware pointer, skip over any
additional packets with OWN set -- we may have queued more.

rtw_rxring_fixup():
k) Remove this, because it's completely wrong.

rtw_intr_ioerror():
l) Don't handle receive overruns here; handle them in the normal receive
path. Also changed RTW_INTR_RX and RTW_INTR_IOERROR accordingly.
m) Do not fiddle with CR; the transmit engine is still running just
fine.
n) Do not fiddle with IMR; it was unnecessary.
o) Don't touch the receive engine at all; not necessary now that we're
leaving CR alone.
p) Remove the rtw_do_chip_reset case; it was dangerous and not actually
used.

rtw_intr():
q) Don't mask off ISR bits when we pass down the ISR value; it's not
necessary, and sometimes the other bits useful in debugging output.

rtw_seg_too_short():
r) Don't spew here; the caller will do it if necessary. (Stops spewage
in an expected case.)

rtw_rxdesc_blk:
s) Minor change to make the elements have the same order as txdesc_blk.

general:
t) Added a bunch of debugging output, #ifdef RTW_DIAG, that was useful
while investigating the ring management problems. Also moved
rtw_txring_fixup() into RTW_DIAG, as I believe the transmit pointer
is always kept in sync now, and the function has potential race
conditions.


# 1.82 06-Jan-2007 dyoung

After we examine a rx/tx descriptor and find that it's still owned
by the NIC, re-sync the descriptor so that a cacheline will not
"cover" the NIC's modifications to the descriptor when we next
examine it.

This compiles, but I have not tested it, yet.


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase wrstuden-fixsa-base-1 netbsd-4-0-RELEASE netbsd-4-0-RC5 matt-nb4-arm-base netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 wrstuden-fixsa-base yamt-splraiseipl-base5 yamt-splraiseipl-base4 yamt-splraiseipl-base3 netbsd-4-base
# 1.81 16-Nov-2006 christos

__unused removal on arguments; approved by core.


# 1.80 13-Nov-2006 dyoung

Stop using typeof() in the bit-twiddling macros, per yamt@'s
suggestion. This change requires that I use the __PRIuBITS format
string in atw and rtw, so do that.


Revision tags: yamt-splraiseipl-base2
# 1.79 12-Oct-2006 xtraeme

Use __unused in function arguments where appropiate.


# 1.78 12-Oct-2006 christos

- sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386


# 1.77 24-Sep-2006 jmcneill

Add "name" parameter to powerhook_establish, to aid debugging. No objections
on tech-kern@


Revision tags: yamt-splraiseipl-base yamt-pdpolicy-base9 yamt-pdpolicy-base8 rpaulo-netinet-merge-pcb-base
# 1.76 03-Sep-2006 christos

branches: 1.76.2; 1.76.4;
- comment out impossible comparisons
- remove superfluous if statement


# 1.75 31-Aug-2006 dyoung

Per discussion on tech-kern and tech-userlevel, move the bit-twiddling
macros, __BIT, __BITS, SHIFTIN, SHIFTOUT, and __arraycount() from
lib/libkern/libkern.h to sys/cdefs.h. Add a __-prefix to SHIFTIN
and SHIFTOUT, and add a manual page for the bit-twiddling macros,
bits(3).

Make the __BIT and __BITS macros "widthless," as best I can, by
changing their type to uintmax_t from uint32_t. XXX The manual
page lags this change by a bit.

Define __PRIxBIT and __PRIxBITS printf(3) format strings.


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base7 yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base simonb-timecounters-base
# 1.74 26-May-2006 blymn

Clean up bogus whitespace


Revision tags: yamt-pdpolicy-base5
# 1.73 14-May-2006 christos

branches: 1.73.2;
XXX: GCC uninitialized


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 elad-kernelauth-base
# 1.72 28-Mar-2006 dyoung

Revamp ieee80211_get_rate. Now it does not use the rateset in the
ic->ic_bss, but it uses the rateset in its new ieee80211_node
argument, instead. If the rate is fixed by ic->ic_fixed_rate, but
the fixed rate is not in the node's rateset, choose a reasonable
default: prefer the lowest basic rate or, if there is no basic
rate, prefer the lowest rate, period.

Change a printf complaint to a debug message.

Adapt drivers to suit new ieee80211_get_rate calling convention.

XXX I really need to replace ieee80211_get_rate with a bitrate
XXX adaptation algorithm. Soon, soon....


# 1.71 27-Mar-2006 dyoung

Set the channel frequency and flags in the radiotap headers in
rtw_tune instead of in rtw_start, rtw_intr_rx.


# 1.70 27-Mar-2006 dyoung

Remove unused argument ifflagsp from rtw_dmamap_load_txbuf.


Revision tags: peter-altq-base yamt-pdpolicy-base2
# 1.69 08-Mar-2006 dyoung

branches: 1.69.2;
Change macro names to avoid collisions:

BIT -> __BIT
BITS -> __BITS


# 1.68 08-Mar-2006 dyoung

Move my bit-twiddling macros to libkern.h from my drivers, where
I had duplicated them. Improve the macros' names. Simplify their
implementation.

A brief description of each macro is below.

BIT(n): Return a bitmask with bit m set, where the least
significant bit is bit 0.

BITS(m, n): Return a bitmask with bits m through n, inclusive,
set. It does not matter whether m>n or m<=n.
The least significant bit is bit 0.

A "bitfield" is a span of consecutive bits defined by a
bitmask, where 1s select the bits in the bitfield. SHIFTIN,
SHIFTOUT, and SHIFTOUT_MASK help read and write bitfields
from device registers.

SHIFTIN(v, mask): Left-shift bits `v' into the bitfield
defined by `mask', and return them. No
side-effects.

SHIFTOUT(v, mask): Extract and return the bitfield selected
by `mask' from `v', right-shifting the
bits so that the rightmost selected bit
is at bit 0. No side-effects.

SHIFTOUT_MASK(mask): Right-shift the bits in `mask' so that
the rightmost non-zero bit is at bit
0. This is useful for finding the
greatest unsigned value that a bitfield
can hold. No side-effects. Note that
SHIFTOUT_MASK(m) = SHIFTOUT(m, m).

Examples:

/*
* Register definitions taken from the RFMD RF3000 manual.
*/
#define RF3000_GAINCTL 0x11 /* TX variable gain control */
#define RF3000_GAINCTL_TXVGC_MASK BITS(7, 2)
#define RF3000_GAINCTL_SCRAMBLER BIT(1)

/*
* Shift the transmit power into the transmit-power field of the
* gain-control register and write it to the baseband processor.
*/
atw_rf3000_write(sc, RF3000_GAINCTL,
SHIFTIN(txpower, RF3000_GAINCTL_TXVGC_MASK));


/*
* Register definitions taken from the ADMtek ADM8211 manual.
*
*/
#define ATW_RXSTAT_OWN BIT(31) /* 1: NIC may fill descriptor */
/* ... */
#define ATW_RXSTAT_DA1 BIT(17) /* DA bit 1, admin'd address */
#define ATW_RXSTAT_DA0 BIT(16) /* DA bit 0, group address */
#define ATW_RXSTAT_RXDR_MASK BITS(15,12) /* RX data rate */
#define ATW_RXSTAT_FL_MASK BITS(11,0) /* RX frame length, last
* descriptor only
*/

/* Extract the frame length from the Rx descriptor's
* status field.
*/
len = SHIFTOUT(rxstat, ATW_RXSTAT_FL_MASK);


Revision tags: yamt-pdpolicy-base yamt-uio_vmspace-base5
# 1.67 20-Feb-2006 thorpej

branches: 1.67.2; 1.67.4;
Use device_is_active() rather than testing dv_flags for DVF_ACTIVE
directly.


# 1.66 19-Feb-2006 dyoung

When rtw_enable is called, power may have been removed and re-applied,
so invalidate the WEP key registers to force us to write the keys
back to the hardware.

Revamp key handling: use the hardware WEP engine for 40-bit and
104-bit keys, only; use software WEP for all other key lengths.
Set the hardware key length to the length of the default Tx key,
or if there is no default Tx key, use the length of the longest
WEP key.


# 1.65 04-Feb-2006 dyoung

In rtw_{rx,tx}ring_fixup, do not set the tx/rx ring index to
something out of bounds if we read an invalid pointer form the
hardware. Prevents a panic when an rtw@cardbus is ejected.


# 1.64 29-Dec-2005 dyoung

branches: 1.64.2; 1.64.4; 1.64.6;
Add support for the GCT Semiconductor GRF5101 transceiver/synthesizer.
From OpenBSD.

GCT will not provide any documentation, so there are many magic
numbers in this code.


# 1.63 29-Dec-2005 dyoung

Update rtw(4) for the new IBSS merge idiom, where ieee80211_ibss_merge()
does not return ENETRESET if the driver should change its BSSID,
but it makes a RUN->RUN transition, instead.


# 1.62 29-Dec-2005 dyoung

In atw(4), use ieee80211_compute_duration() to compute IEEE 802.11
Duration and PLCP Length fields, and delete the abominable
atw_frame_setdurs() subroutine.

Make rtw(4) use the new ieee80211_compute_duration() calling
convention.

Add an ieee80211_key argument to ieee80211_compute_duration() and
lightly constify arguments. Get the crypto header length from the
key argument instead of blithely assuming a WEP header. Add some
inline documentation. Account for data padding (IEEE80211_F_DATAPAD).


# 1.61 24-Dec-2005 perry

Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.


# 1.60 13-Dec-2005 dyoung

Fix comments and debug printfs: Tx FIFOs underflow, they don't
overflow.


# 1.59 13-Dec-2005 dyoung

On a transmit FIFO overflow (err, actually an underflow...) reset
both the transmit & receive sections of the MAC.


Revision tags: yamt-readahead-base3 ktrace-lwp-base
# 1.58 23-Nov-2005 dyoung

Miscellaneous Realtek RTL8180L driver improvements:

1 Added new sysctl controls for debugging.

2 Improve detection & support for hardware WEP.

3 Revamp handling of transmit descriptor rings.

4 Reliably IFF_OACTIVE when transmit descriptors are available, to
stop the transmit section of the driver from freezing up.

5 Fix beacon transmission in adhoc and hostap modes. XXX There is
a wart in hostap mode, where beacons are transmitted at 1/2 the
correct rate. Load beacon descriptors when the RTW_INTR_BINT
interrupt arrives; schedule RTW_INTR_BINT 1ms ahead of the target
beacon time.

6 Recover more gracefully from tx/rx errors: avoid
transmitter/receiver/chip resets. Try to re-synchronize software
state with hardware state---e.g., load next descriptor pointer
from hardware.

7 Activate the transmit watchdog timer for beacons as well as other
packets.

8 Introduce rtw_idle() that waits for transmit DMA to finish; call
it before resetting the transmitter.


Revision tags: yamt-readahead-base2
# 1.57 18-Nov-2005 skrll

Adapt drivers to the new net80211(9).

Most of this is from dyoung@. Thanks!


Revision tags: yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base
# 1.56 22-Sep-2005 gdt

branches: 1.56.6;
Make arg of IFQ_SET_READY be &ifp->if_snd, to match all other drivers
and be compilable with altq enabled. Reviewed by dyoung@


# 1.55 07-Sep-2005 dogcow

With the assistance of dyoung, fix the following problems:
* some 8180L cards need a longer time for the srom to initialize; patch
suggested via OpenBSD.
* some cards give '0' for USA, some give '3'; for the meantime, accept both
as being USA locale cards.
* this is RTW, not ATW. :)


# 1.54 06-Sep-2005 dogcow

make rtw.c compile again after the 22-jun-05 net80211 import


# 1.53 11-Jul-2005 dyoung

Add undefined variable 'ic' to rtw_attach.


# 1.52 06-Jul-2005 dyoung

Historically, an(4), ath(4), atw(4), rtw(4), and wi(4) have printed
out their modes and rates at boot. Revert to the historical
behavior.


# 1.51 06-Jul-2005 dyoung

Avoid an unnecessary API difference between NetBSD and FreeBSD:
back out my change to ieee80211_crypto_encap that made it free its
mbuf argument on error. I had thought it was a bug. It was not.
It's the drivers that are broken. Make an(4), atw(4), ipw(4),
iwi(4), ral(4), rtw(4), ural(4), and wi(4) free the mbuf when
ieee80211_crypto_encap returns NULL. Also, return ath(4) to the
way it was---i.e., free the mbuf.

Thanks to Sam Leffler to pointing out my mistake.


# 1.50 28-Jun-2005 dyoung

branches: 1.50.2;
Here is a grotty hack that lets the RTL8180L handle WEP in the
receive direction, while software handles WEP in the transmit
direction. When net80211 calls rtw's rtw_key_set with a WEP key,
I point the key's wk_cipher at our "fake" cipher, rtw_cipher_wep,
which is alike to ieee80211_cipher_wep except it provides a different
crypto-decapsulation routine, rtw_wep_decap. rtw_wep_decap copies
the key passed to it by net80211, clears the key's SWCRYPT flag,
and then calls wep_decap. Now wep_decap will decapsulate, but it
will *not* re-decrypt.

XXX I need to check whether the hardware supports 40-bit WEP,
XXX 104-bit WEP, or both, and act accordingly.


# 1.49 27-Jun-2005 dyoung

rtw: Try to get hardware WEP to work. It seems to work in
the RX direction, but not in the TX direction. The
net80211 crypto framework doesn't seem to cope very well
with the assymetry (I'm probably missing something), so
I will use software WEP for now.

net80211: In ieee80211_compute_duration, figure out whether to add
the WEP header to the packet overhead by checking the
WEP bit in the Frame Control field of the 802.11 header,
instead of checking the IEEE80211_F_PRIVACY flag.

Also, if the WEP bit is present, assume that the frame
described by (wh, len) has already already been WEP
encapsulated, and adjust the payload length accordingly.
XXX that's a grotty hack that I will have to revisit,
later.


# 1.48 22-Jun-2005 dyoung

Resolve conflicts in importation of 18-May-2005 ath(4) / net80211(9)
from FreeBSD. Introduce compatibility shims (sys/dev/ic/ath_netbsd.[ch],
sys/net80211/ieee80211_netbsd.[ch]). Update drivers (an, atu, atw,
awi, ipw, iwi, rtw, wi) for the new net80211(9) API.


# 1.47 20-Jun-2005 atatat

Change the rest of the sysctl subsystem to use const consistently.
The __UNCONST macro is now used only where necessary and the RW macros
are gone. Most of the changes here are consumers of the
sysctl_createv(9) interface that now takes a pair of const pointers
which used not to be.


# 1.46 10-Jun-2005 dyoung

Sprinkle __UNCONST() and rename variables to quiet uiet -Wcast-qual,
-Wshadow complaints.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 yamt-km-base4 yamt-km-base3 netbsd-3-base kent-audio2-base
# 1.45 02-Mar-2005 dyoung

Misc. changes to improve ad hoc mode and to enable hostap mode:

Fix the work-around for the NIC bug where it skips to rx
descriptor 0. The driver used to skip to rx descriptor 1.
Hopefully this stops the out-of-order packet reception that
Charles Hannum saw.
When debugging is enabled, print rx-descriptor status flags
before printing the rx bit rate.

Add a debug message for when a beacon tx buffer reclamation.

Reset IFF_OACTIVE when we reset the transmitter.

Pass the consolidated LED state, a struct rtw_led_state,
to rtw_led_attach.

Choose the bit-rate for management frames (1Mb/s) at the
same place we choose for all other frames.

Do not use the NIC's short preamble or RTS options for
management frames. Label beacons for the NIC.

Following a Linux driver, take care not to zero arbitrary
bits in the TPPOLL register.

Use the new idiom for IBSS merges: disable transmitter,
kick the state machine.
Add a second descriptor to the beacon ring. The NIC seems
to like this much better.


# 1.44 27-Feb-2005 perry

nuke trailing whitespace


Revision tags: yamt-km-base2
# 1.43 31-Jan-2005 thorpej

Eliminate use of M_HASFCS.


Revision tags: yamt-km-base
# 1.42 16-Jan-2005 dyoung

branches: 1.42.2; 1.42.4;
Move the register access mode into struct rtw_regs. Change
rtw_set_access, rtw_set_access1 to match.

Add a subroutine for setting WEP keys. WEP isn't quite finished,
because I have to add the WEP header to Tx packets. Implement the
SIOCS80211NWKEY ioctl for setting WEP keys.

Program the LEDs based on operating state and packet activity.

* On a Revision F RTL8180, blink LED1 at 1Hz to indicate
scan/authenticate/associate states. In the run state, turn LED1
on. In every state, blink LED1 at 5Hz to indicate non-beacon
tx/rx activity. I would like to use two LEDs, but in all my
Rev. F instances, LED0 is not wired to an LED; instead, the
first LED is wired to indicate that the card's power is on.

* On a Revision D RTL8180, program the LEDs so that LED0 indicates
Tx, and LED1 indicates Rx. The Rx LED will blink annoyingly if
there are beacons in the air, but at least the Tx LED is useful.

* Store the hardware revision in the softc to support my futile
attempt at programming LEDs for both Rev. D and Rev. F parts;
I never did get Rev. D LEDs to work right.

* Add a debug flag RTW_DEBUG_LED for the LED transitions.

Add RTW_TPPOLL_ALL, RTW_TPPOLL_SALL to start and stop, respectively,
all of the transmit rings.

In ad hoc mode, allocate a beacon and load it into the beacon ring.
Start the ring. In one trial, the card re-transmitted the beacon
ring's contents several times before stopping. More programming
and testing for ad hoc mode is necessary. I'm not setting the
beacon flag in the transmit descriptor.

Revamp the transmit section to make better use of all the transmit
rings: beacon queue, high-, low-, and medium-priority rings. Put
beacon frames on the beacon ring. All other management frames,
and data frames, go on the medium-priority ring. Power-save data
frames go on the high-priority ring. (Note that powersaving is
not implemented!) This is a work in progress.

Send all 802.11 Management frames at 1Mbps.

After we put a packet on a transmit ring, tickle the right bit in
the TPPOLL to tell RTL8180. Stop all rings on error and in rtw_stop.

Use the RF chip type, not the RTL8180 revision, to choose between
host- and MAC-controlled RF serial I/O. Now the Netgear MA521
works.

Remove bogus definition of bit RTW_TPPOLL_FSWINT.


Revision tags: kent-audio1-beforemerge
# 1.41 04-Jan-2005 dyoung

Set initial conditions to guarantee that when read_seeprom toggles
Chip Select, it turns *on* rather than *off*.


# 1.40 04-Jan-2005 dyoung

Add the logic for IBSS merges.


# 1.39 03-Jan-2005 dyoung

sys/dev/ic/rtw.c:

Cosmetic: remove two short ladders from rtw_init. Fit the
NIC registers print-out onto one line using the RTW_PRINT_REGS
macro.

sys/dev/ic/rtwvar.h:

Add RTW_PRINT_REGS wrapper macro for rtw_print_regs. It
is a null op unless defined(RTW_DEBUG).


# 1.38 03-Jan-2005 dyoung

In sys/dev/ic/rtw.c:

Use clue from rtk(4) and re(4) to fix the rtw(4) packet
filter. Previously, I was using the wrong CRC32 function
to hash multicast addresses; to compensate, I set the
multicast filter to all 1s. Now that I hash the addresses
correctly, I do not any longer set the filter to all 1s.

In rtw_ioctl, avoid gratuitous re-initialization when the
interface flags change. If a !IFF_UP -> IFF_UP transition,
call rtw_init(); otherwise, only reload the packet filter.

In sys/dev/ic/rtwreg.h:

Put useful combinations of Receiver Control Register flags
in RTW_RCR_PKTFILT_MASK, RTW_RCR_MONITOR, and
RTW_RCR_PKTFILT_DEFAULT. (XXX RTW_RCR_MONITOR should be
called RTW_RCR_PKTFILT_MONITOR.)


# 1.37 02-Jan-2005 dyoung

Cosmetic: change u_int{8,16,32,64}_t to C99-style uint{8,16,32,64}_t,
which is preferred.


# 1.36 29-Dec-2004 dyoung

In rtw_detach, flag the rtw as "invalid" (RTW_F_INVALID). Do not
try to power-down the RF section of an invalid rtw.

The radiotap signal quality field is 16, not 8, bits wide. Convert
the byte order.


# 1.35 29-Dec-2004 dyoung

Remove some dead code.


# 1.34 29-Dec-2004 dyoung

I like the tlp/atw-style names for software descriptors, txsoft,
better than txctl. Change from rtw_txctl/rtw_rxctl to
rtw_txsoft/rtw_rxsoft. Change the descriptor blocks' names to
match: rtw_txctl_blk becomes rtw_txsoft_blk. Change the member-name
prefixes for both software and hardware descriptors.


# 1.33 29-Dec-2004 dyoung

Consolidate variables related to the rx ring in sc_rxdesc_blk,
which is a struct rtw_rxdesc_blk.

Put a copy of the DMA tag and the DMA map into the rx- and tx-ring
blocks so that I don't have to pass them to subroutines all of the
time.


# 1.32 28-Dec-2004 dyoung

Add bpf(4) packet taps to rtw(4). Now you can tap DLT_EN10MB
(Ethernet II), DLT_IEEE802_11 (802.11), and DLT_IEEE802_11_RADIO
(radiotap + 802.11).


# 1.31 28-Dec-2004 dyoung

If defined(RTW_DEBUG), provide a sysctl (hw.rtw.rxbufs_limit) for
limiting the number of rx buffers an rtw may allocate. Use this
sysctl to test the code that copes with buffer exhaustion.

Allocate at most RTW_RXQLEN rx buffers, stopping at the sysctl
limit. Record in sc_nrxdesc how many were allocated, and put the
end-of-ring indication on sc_rxdesc[sc_nrxdesc - 1]. In rtw_init,
if no rx buffers could be allocated, log a complaint, clear
IFF_RUNNING, and exit with an error.

Many changes to accomodate a short rx ring, mainly of the "add a
rx-ring length argument" variety. XXX I really should consolidate
all of the rx ring variables in one struct and pass that to the
rx-ring subroutines.

Bug fix: after calling MCLGET, use the (m->m_flags & M_EXT) idiom
to check for success, instead of m != NULL.

Bug fix: at the top of rtw_start, if IFF_RUNNING is not set, or
IFF_OACTIVE is, get out.


# 1.30 27-Dec-2004 dyoung

Use a table to convert the hardware's bit rates (0, 1, 2, 3) to
net80211 bit rates (2, 4, 11, 22).

Count input errors (if_ierrors++) for "DMA error/FIFO overflow"
and unknown bit rate.


# 1.29 27-Dec-2004 dyoung

Simplify the reset we do on a transmit timeout. Really, this could
be as simple as rtw_stop(, 0), rtw_init().


# 1.28 27-Dec-2004 mycroft

Use the last descriptor to count collisions and failed transmissions, too.


# 1.27 27-Dec-2004 mycroft

When checking if a split packet is completed, check the *last* segment, not
the first. Otherwise we can overwrite parts of the TX ring that we shouldn't.

Kluge the basic rate setting for now.

Minor simplification to the dequeueing logic.


# 1.26 27-Dec-2004 dyoung

Remove useless debug sysctls.

For AP scanning, change the channel dwell time from 1 second to
1/5 second.


# 1.25 27-Dec-2004 mycroft

Replace d_plcp_svc with d_residue. The latter is the number of whole
empty/unused octets to fill out the data time slot. The value is constrained
by math to 0 for <= 5.5Mb, 0-1 for 11Mb, and 0-2 for 22Mb. It is used to
signal to the MAC that there is residue.


# 1.24 26-Dec-2004 dyoung

Make rtw(4) build w/o RTW_DEBUG. Thanks to Charles Hannum for
pointing out my oversight.


# 1.23 25-Dec-2004 dyoung

The rx descriptor ring bug happens quite often, so printf'ing
occurrences is annoying. Only printf about it when rtw_debug
contains RTW_DEBUG_BUG.


# 1.22 25-Dec-2004 dyoung

IMPORTANT: set m->m_pkthdr.rcvif on rx'd packets. Illegal memory
references abound without this fix.

In rtw_intr_rx, skip to the next rx packet earlier if the rx packet
length is too short.

Also in rtw_intr_rx, if a packet is rx'd with unknown rate, printf
a warning, drop the packet, recycle the rx buffer, skip to next rx
packet.


# 1.21 25-Dec-2004 dyoung

Change rtw_debug from a debug level to a debug mask. Add a lot of
debug flags.

From Linux: handle an RTL8180 bug. Sometimes the NIC skips from
the middle of the ring to the 0th rx descriptor. Now the driver
resynchronizes.

Handle a receive descriptor underrun or Rx FIFO overflow condition
in the way that the Linux driver does. This kind of seems like
overkill, but whatever.

Protect rtw_ioctl with splnet().

Do not load a tx descriptor with a buffer shorter than 4 bytes.

Handle a transmit timeout less disruptively.


# 1.20 23-Dec-2004 dyoung

Oops, straggler from last commit: set the 802.11 Duration field
with the result from ieee80211_compute_duration.


# 1.19 23-Dec-2004 dyoung

Fix a bug in ieee80211_compute_duration: the 802.11 Duration field
in an 802.11 unicast data packet is equal to the duration of the
SIFS and Acknowledgement. That is, the amount of time reserved
*after* the packet has finished transmitting.

Change the arguments to ieee80211_compute_duration: pass the entire
packet length, not just the payload length. Add a 'debug' argument
to ieee80211_compute_duration and its helper subroutine,
ieee80211_compute_duration1.

If debug != 0, ieee80211_compute_duration printfs its arguments
and several local variables.

In rtw(4), load the 802.11 Duration field with the result from
ieee80211_compute_duration.


# 1.18 23-Dec-2004 dyoung

Bug fix: in rtw_rxbuf_alloc, unload the previous mbuf chain before
loading the new chain.


# 1.17 23-Dec-2004 dyoung

DMA-synchronize the Rx buffers before re-initializing them.
XXX not necessary?


# 1.16 23-Dec-2004 dyoung

Add more comprehensive debug messages as we setup transmit descriptors.
Also, dump packets if IFF_DEBUG|IFF_LINK2. Factor out a subroutine
for printing transmit-descriptor debug messages.


# 1.15 23-Dec-2004 dyoung

Disable interrupts and stop transmit DMA before disabling the
transmitter and receiver.


# 1.14 23-Dec-2004 dyoung

Shorten variables, s/txctl/ctl/. This is rtw_start, after all:
transmission is implied.


# 1.13 23-Dec-2004 dyoung

Do not indicate to the NIC that the host has appended the CRC32 to
Tx frames.


# 1.12 23-Dec-2004 dyoung

When we set up the supported rates table, mark 1Mb/s, 2Mb/s as
basic rates.


# 1.11 23-Dec-2004 dyoung

Extract the transmission status from a tx descriptor, and convert
to host byte-order, once.


# 1.10 20-Dec-2004 dyoung

Realtek sample sources are not consistent about the "Digital PHY"
bit in the SROM. It seems as if it is set to 1 when the PHY is
*analog*, not *digital*. Fix my sources.

In rtw_intr_rx, use units of 500kb/s instead of 100kb/s for rate,
to be consistent with net80211's expectations. Polish up some
debugging ugly messages. Dump raw 802.11 packets if IFF_DEBUG|IFF_LINK2
and RTW_DEBUG is defined.

Polish power-state (on/sleep/off) handling. Especially improve
support for RFMD (totally untested) and Maxim. For Philips, take
the Digital PHY property into account.

Call the net80211 watchdog function from rtw_watchdog, so that we
scan again if auth/assoc fails.

Be a little more cautious about writing register[RTW_TPPOLL], since
other drivers are.... Don't frob the high/low-priority queues
right now, since I don't use them.

Add rtw_join_bss which programs the card with the BSSID and other
properties of a BSS. Use it on state transitions. Factor out
rtw_set_nettype.

Make rtw_recv_beacon call ieee80211_recv_mgmt instead of dropping
beacons on the floor! TBD IBSS merges.

Change some rtw_debug=2 printfs to rtw_debug=3 (RTW_DPRINTF3)
printfs so the console doesn't get spammed so badly at rtw_debug=2.
Change some debugging printfs to RTW_DPRINTFs. E.g., print the
"RF programming method" only if debugging is enabled.


# 1.9 20-Dec-2004 dyoung

Fix bug in last commit: use &sc->sc_regs, regs is not defined.


# 1.8 20-Dec-2004 dyoung

Add some bus barriers. Remark where they are needed, e.g.,
read_eeprom.

Change some printfs to RTW_DPRINTF2s to quiet rtw(4) when debugging
is disabled.


# 1.7 20-Dec-2004 dyoung

Get rid of the silly char (*dvname)[IFNAMSIZ] pattern. Replace it
with const char *dvname. I'm not sure what I was thinking.


# 1.6 20-Dec-2004 dyoung

Assert that I'm DMA-syncing a non-negative number of transmit
descriptors.

As I free dirty transmit buffers, move them to the free list, not
back to the dirty list!

Add a 5-second transmit timeout.


# 1.5 19-Dec-2004 dyoung

Add the transmit section of rtw(4): build up and tear down transmit
descriptor rings, move packets from the transmit queues to the
transmit rings, handle transmission-completed interrupts. My
Linksys WPC11 ver. 4 with Maxim RF, generates interrupts like it
is successfully transmitting packets. Clearly there are bugs: my
G4 Powerbook locks up hard. I will debug tomorrow.


# 1.4 13-Dec-2004 dyoung

At last, I have rtw w/ Philips RF receiving packets.

I added some sysctls to aid debugging:

* hw.rtw.debug -- enable debugging

* hw.rtw.flush_rfio -- Linux voodoo: possibly makes the MAC
"flush" bits down the serial bus to the RF

* hw.rtw.host_rfio: force the host to bang bits to the RF, instead
of the MAC banging bits

* hw.rtw.rfio_delay: after telling the MAC to bang bits to the
RF front-end, delay rfio_delay microseconds.

* hw.rtw.rfprog_fallback: there is this notion of the "RF
programming method." I believe the choice influences the
polarity/timing of the serial bus used to program the RF
front-end. I know the correct choice for Intersil/RFMD/Philips
front-ends, only. For all other front-ends, I "fallback" to
rfprog_fallback.

Make rtw_txdac_enable take an rtw_softc argument. I will probably
revert this change.

Add some Linux voodoo to rtw_continuous_tx_enable. I will probably
revert this change.

Important: add rtw_set_rfprog, which sets the correct RF programming
method. This change and the following change are probably responsible
for making the Philips RF work.

Important: RTW_CONFIG1 is an 8-bit register, treat it that way!

Important: RTW_BRSR is 16-bit, RTW_CRCOUNT, RTW_PHYDELAY, and
RTW_MSR are 8-bit: treat them that way!

Vastly simplify rtw_resume_ticks.

Note to self: set the LED state to match the power state.

Hedge against the possibility that RTW_MSR is protected as
RTW_CONFIG[0123] are, meanwhile reworking that section of rtw_init
a little.

Add sc_anaparm, which isn't used, yet....


# 1.3 12-Dec-2004 dyoung

Miscellaneous changes. Details below. Important changes flagged
with []. Using the driver with my Linksys WPC11 ver. 4, it seems
to be receiving packets for a change. The WPC11 ver. 4 has a Maxim
RF section. My no-name rtw with Philips RF section still does not
receive any packets.

Keep access-level (analog params > config[0123] registers > none)
in sc_access. Add rtw_set_access for changing the access level.

Make rtw_continuous_tx_enable and other subroutines use rtw_set_access
instead of rtw_config0123_enable and rtw_anaparm_enable.

Factor part of the chip-reset code into rtw_chip_reset1.

Change the 'struct foo (*bar)[N]'-style arguments to
'struct foo *bar'-style arguments.

Consolidate software/hardware Tx/Rx ring setup in rtw_hwring_setup,
rtw_swring_setup.

Add a new constant, SA2400_OPMODE_DEFAULTS, for the bits that we
*always* set in the SA2400 OPMODE register.

Factor some code out into rtw_sa2400_calibrate. (Inspired by the
Linux driver.)

[] When the receiver goes into underrun/overflow state, call a new
subroutine, rtw_kick() that stops the Rx/Tx processes, resets
the chip, reinitializes the Tx/Rx rings, and restarts Rx/Tx
processes. (Inspired by the Linux driver.)

[] In rtw_intr_rx, check for too-short packets before calling
ieee80211_find_rxnode. I believe this will prevent a repeat of
the MCHK exception I saw once on macppc.

[] Use seconds-elapased as well as microseconds-elapsed to set the
next "due date" for the timeout interrupt. This keeps the driver
from programming the timeout to expire too early.

[] In rtw_intr, read RTW_ISR at most 10 times, then get out. If
the interface is not enabled (RTW_F_ENABLED), then get out.

[] In rtw_stop, get out if the interface is not enabled (RTW_F_ENABLED).
Block IPL_NET interrupts. Don't read/write any registers if
the interface is invalid (RTW_F_INVALID).

[] Call rtw_stop in rtw_detach.


Revision tags: kent-audio1-base
# 1.2 30-Oct-2004 thorpej

When adding/deleting multicast addresses, only whack the address
filter if the interface is marked RUNNING.

Fixes kern/27678.


# 1.1 26-Sep-2004 dyoung

branches: 1.1.2;
Add work-in-progress driver rtw(4) for Realtek RTL8180 MAC/baseband.

Add register definitions for Maxim MAX2820 and Philips SA2400 radio
front-ends.


# 1.134 10-Nov-2019 chs

in many device attach paths, allocate memory with M_WAITOK instead of M_NOWAIT
and remove code to handle failures that can no longer happen.


Revision tags: netbsd-9-base phil-wifi-20190609
# 1.133 28-May-2019 msaitoh

Use ETHER_LOCK()/ETHER_UNLOCK() for all ethernet drivers to protect ec_multi*.


# 1.132 23-May-2019 msaitoh

Whitespace fix (mainly tabify).


# 1.131 23-May-2019 msaitoh

-No functional change:
- KNF
- u_int*_t -> uint*_t.


Revision tags: isaki-audio2-base
# 1.130 05-Feb-2019 msaitoh

Remove very old IFF_NOTRAILERS flag.


# 1.129 03-Feb-2019 mrg

- add or adjust /* FALLTHROUGH */ where appropriate
- add __unreachable() after functions that can return but won't in
this case, and thus can't be marked __dead easily


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 jdolecek-ncqfixes-base pgoyette-compat-0728 phil-wifi-base
# 1.128 26-Jun-2018 msaitoh

branches: 1.128.2;
Implement the BPF direction filter (BIOC[GS]DIRECTION). It provides backward
compatibility with BIOC[GS]SEESENT ioctl. The userland interface is the same
as FreeBSD.

This change also fixes a bug that the direction is misunderstand on some
environment by passing the direction to bpf_mtap*() instead of checking
m->m_pkthdr.rcvif.


Revision tags: pgoyette-compat-0625 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base tls-maxphys-base-20171202
# 1.127 23-Oct-2017 msaitoh

branches: 1.127.2;
If if_initialize() failed in the attach function, free resources and return.


Revision tags: matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base
# 1.126 23-May-2017 ozaki-r

branches: 1.126.2;
Apply deferred if_start to more drivers

And annotate some XXX_start as it runs in softint to clarify that
it doesn't need deferred if_start.


Revision tags: prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 nick-nhusb-base-20170204
# 1.125 02-Feb-2017 nonaka

wlan interfaces make interrupt routine running on softint context.

see http://mail-index.netbsd.org/tech-kern/2016/12/06/msg021281.html

tested device:
* ath at pci: AR5212, AR5424
* athn at pci: AR9287
* ipw at pci: 2100BG
* iwi at pci: 2915ABG
* iwm at pci: 3165, 7260, 8260
* iwn at pci: 4945, 6235
* ral at pci: RT2560
* rtwn at pci: RTL8192CE


Revision tags: bouyer-socketcan-base pgoyette-localcount-20170107 nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.124 15-Sep-2016 jdolecek

branches: 1.124.2;
remove last isolated islands using BUS_SPACE_BARRIER_SYNC and
BUS_SPACE_BARRIER_X_BEFORE_X - these were only ever defined for mips and ia64,
and never actually implemented even there


Revision tags: localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907
# 1.123 10-Jun-2016 ozaki-r

branches: 1.123.2;
Introduce m_set_rcvif and m_reset_rcvif

The API is used to set (or reset) a received interface of a mbuf.
They are counterpart of m_get_rcvif, which will come in another
commit, hide internal of rcvif operation, and reduce the diff of
the upcoming change.

No functional change.


Revision tags: nick-nhusb-base-20160529
# 1.122 16-May-2016 ozaki-r

Use M_GETCTX and M_SETCTX instead of open-coding rcvif

No functional change.


Revision tags: netbsd-7-2-RELEASE netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 netbsd-7-0-RELEASE nick-nhusb-base-20150921 netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 nick-nhusb-base-20150606 nick-nhusb-base-20150406 nick-nhusb-base netbsd-7-base yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 rmind-smpnet-nbase rmind-smpnet-base tls-maxphys-base
# 1.121 25-Feb-2014 pooka

branches: 1.121.6;
Ensure that the top level sysctl nodes (kern, vfs, net, ...) exist before
the sysctl link sets are processed, and remove redundancy.

Shaves >13kB off of an amd64 GENERIC, not to mention >1k duplicate
lines of code.


# 1.120 17-Oct-2013 christos

- remove unused variables
- move variables inside ifdef sections
- ifdef notdef unused code
- use __USE for debugging variables


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE yamt-pagecache-tag8 netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 agc-symver-base netbsd-6-1-RC2 netbsd-6-1-RC1 yamt-pagecache-base8 netbsd-6-0-1-RELEASE yamt-pagecache-base7 matt-nb6-plus-nbase yamt-pagecache-base6 netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base10 yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.119 04-Jul-2011 joerg

branches: 1.119.2; 1.119.12; 1.119.16;
Fix memset usage.


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base matt-mips64-premerge-20101231 rmind-uvmplock-base
# 1.118 15-Nov-2010 uebayasi

Socket ioctl definitions need sys/sockio.h.


# 1.117 13-Nov-2010 uebayasi

Don't pull in the whole uvm(9) API to access only PAGE_SIZE and
some other constants. These are provided by sys/param.h now.


Revision tags: uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10 uebayasi-xip-base1
# 1.116 05-Apr-2010 joerg

Push the bpf_ops usage back into bpf.h. Push the common ifp->if_bpf
check into the inline functions as well the fourth argument for
bpf_attach.


# 1.115 15-Mar-2010 dyoung

Make this compile on sparc64:

1 s/next_tick/next_tint/ because next_tick shadows a global on sparc64.

2 Fix the bus-barrier helper routines, which had the tag & handle
swapped (!!). Move the helpers from rtwreg.h to rtwvar.h, and
change RTW_BARRIER() into an inline subroutine called rtw_barrier().


Revision tags: yamt-nfs-mp-base9
# 1.114 24-Feb-2010 dyoung

branches: 1.114.2;
A pointer typedef entails trading too much flexibility to declare const
and non-const types, and the kernel uses both const and non-const
PMF qualifiers and device suspensors, so change the pmf_qual_t and
device_suspensor_t typedefs from "pointers to const" to non-pointer,
non-const types.


Revision tags: uebayasi-xip-base
# 1.113 31-Jan-2010 dyoung

branches: 1.113.2;
Add the missing newline to a verbose autoconf message.


# 1.112 19-Jan-2010 pooka

Redefine bpf linkage through an always present op vector, i.e.
#if NBPFILTER is no longer required in the client. This change
doesn't yet add support for loading bpf as a module, since drivers
can register before bpf is attached. However, callers of bpf can
now be modularized.

Dynamically loadable bpf could probably be done fairly easily with
coordination from the stub driver and the real driver by registering
attachments in the stub before the real driver is loaded and doing
a handoff. ... and I'm not going to ponder the depths of unload
here.

Tested with i386/MONOLITHIC, modified MONOLITHIC without bpf and rump.


# 1.111 08-Jan-2010 dyoung

Expand PMF_FN_* macros.


Revision tags: matt-premerge-20091211 jym-xensuspend-nbase
# 1.110 19-Oct-2009 rmind

Drop 3rd and 4th clauses from David Young's license.
Reviewed and approved by dyoung@ (copyright holder).


# 1.109 16-Sep-2009 dyoung

In pmf(9), improve the implementation of device self-suspension
and make suspension by self, by drvctl(8), and by ACPI system sleep
play nice together. Start solidifying some temporary API changes.

1. Extract a new header file, <sys/device_if.h>, from <sys/device.h> and
#include it from <sys/pmf.h> instead of <sys/device.h> to break the
circular dependency between <sys/device.h> and <sys/pmf.h>.

2. Introduce pmf_qual_t, an aggregate of qualifications on a PMF
suspend/resume call. Start to replace instances of PMF_FN_PROTO,
PMF_FN_ARGS, et cetera, with a pmf_qual_t.

3. Introduce the notion of a "suspensor," an entity that holds a
device in suspension. More than one suspensor may hold a device
at once. A device stays suspended as long as at least one
suspensor holds it. A device resumes when the last suspensor
releases it.

Currently, the kernel defines three suspensors,

3a the system-suspensor: for system suspension, initiated
by 'sysctl -w machdep.sleep_state=3', by lid closure, by
power-button press, et cetera,

3b the drvctl-suspensor: for device suspension by /dev/drvctl
ioctl, e.g., drvctl -S sip0.

3c the system self-suspensor: for device drivers that suspend
themselves and their children. Several drivers for network
interfaces put the network device to sleep while it is not
administratively up, that is, after the kernel calls if_stop(,
1). The self-suspensor should not be used directly. See
the description of suspensor delegates, below.

A suspensor can have one or more "delegates". A suspensor can
release devices that its delegates hold suspended. Right now,
only the system self-suspensor has delegates. For each device
that a self-suspending driver attaches, it creates the device's
self-suspensor, a delegate of the system self-suspensor.

Suspensors stop a system-wide suspend/resume cycle from waking
devices that the operator put to sleep with drvctl before the cycle.
They also help self-suspension to work more simply, safely, and in
accord with expectations.

4. Add the notion of device activation level, devact_level_t,
and a routine for checking the current activation level,
device_activation(). Current activation levels are DEVACT_LEVEL_BUS,
DEVACT_LEVEL_DRIVER, and DEVACT_LEVEL_CLASS, which respectively
indicate that the device's bus is active, that the bus and device are
active, and that the bus, device, and the functions of the device's
class (network, audio) are active.

Suspend/resume calls can be qualified with a devact_level_t.
The power-management framework treats a devact_level_t that
qualifies a device suspension as the device's current activation
level; it only runs hooks to reduce the activation level from
the presumed current level to the fully suspended state. The
framework treats a devact_level_t qualifying device resumption
as the target activation level; it only runs hooks to raise the
activation level to the target.

5. Use pmf_qual_t, devact_level_t, and self-suspensors in several
drivers.

6. Temporarily add an unused power-management workqueue that I will
remove or replace, soon.


Revision tags: yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5 yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 nick-hppapmap-base3 jym-xensuspend-base nick-hppapmap-base
# 1.108 07-Apr-2009 dyoung

Cosmetic: remove some dead code.


# 1.107 02-Apr-2009 dyoung

Add the WEP capability to our net80211 capability flags, since we do
sort of support hardware WEP. Only change the WEP key index in a Tx
descriptor from 0 if the type of our transmit key is _WEP, not _TKIP:
i.e., only if we're really doing WEP crypto in the hardware.

Ignore a watchdog timeout on any Tx ring if we can collect some packets
from that ring. Restart both the receiver and the transmitter when a
watchdog timeout occurs instead of restarting only the transmitter.


Revision tags: nick-hppapmap-base2 haad-dm-base2 haad-nbase2 ad-audiomp2-base haad-dm-base mjf-devfs2-base
# 1.106 12-Nov-2008 ad

branches: 1.106.4;
Remove LKMs and switch to the module framework, pass 1.

Proposed on tech-kern@.


# 1.105 07-Nov-2008 dyoung

*** Summary ***

When a link-layer address changes (e.g., ifconfig ex0 link
02:de:ad:be:ef:02 active), send a gratuitous ARP and/or a Neighbor
Advertisement to update the network-/link-layer address bindings
on our LAN peers.

Refuse a change of ethernet address to the address 00:00:00:00:00:00
or to any multicast/broadcast address. (Thanks matt@.)

Reorder ifnet ioctl operations so that driver ioctls may inherit
the functions of their "class"---ether_ioctl(), fddi_ioctl(), et
cetera---and the class ioctls may inherit from the generic ioctl,
ifioctl_common(), but both driver- and class-ioctls may override
the generic behavior. Make network drivers share more code.

Distinguish a "factory" link-layer address from others for the
purposes of both protecting that address from deletion and computing
EUI64.

Return consistent, appropriate error codes from network drivers.

Improve readability. KNF.

*** Details ***

In if_attach(), always initialize the interface ioctl routine,
ifnet->if_ioctl, if the driver has not already initialized it.
Delete if_ioctl == NULL tests everywhere else, because it cannot
happen.

In the ioctl routines of network interfaces, inherit common ioctl
behaviors by calling either ifioctl_common() or whichever ioctl
routine is appropriate for the class of interface---e.g., ether_ioctl()
for ethernets.

Stop (ab)using SIOCSIFADDR and start to use SIOCINITIFADDR. In
the user->kernel interface, SIOCSIFADDR's argument was an ifreq,
but on the protocol->ifnet interface, SIOCSIFADDR's argument was
an ifaddr. That was confusing, and it would work against me as I
make it possible for a network interface to overload most ioctls.
On the protocol->ifnet interface, replace SIOCSIFADDR with
SIOCINITIFADDR. In ifioctl(), return EPERM if userland tries to
invoke SIOCINITIFADDR.

In ifioctl(), give the interface the first shot at handling most
interface ioctls, and give the protocol the second shot, instead
of the other way around. Finally, let compatibility code (COMPAT_OSOCK)
take a shot.

Pull device initialization out of switch statements under
SIOCINITIFADDR. For example, pull ..._init() out of any switch
statement that looks like this:

switch (...->sa_family) {
case ...:
..._init();
...
break;
...
default:
..._init();
...
break;
}

Rewrite many if-else clauses that handle all permutations of IFF_UP
and IFF_RUNNING to use a switch statement,

switch (x & (IFF_UP|IFF_RUNNING)) {
case 0:
...
break;
case IFF_RUNNING:
...
break;
case IFF_UP:
...
break;
case IFF_UP|IFF_RUNNING:
...
break;
}

unifdef lots of code containing #ifdef FreeBSD, #ifdef NetBSD, and
#ifdef SIOCSIFMTU, especially in fwip(4) and in ndis(4).

In ipw(4), remove an if_set_sadl() call that is out of place.

In nfe(4), reuse the jumbo MTU logic in ether_ioctl().

Let ethernets register a callback for setting h/w state such as
promiscuous mode and the multicast filter in accord with a change
in the if_flags: ether_set_ifflags_cb() registers a callback that
returns ENETRESET if the caller should reset the ethernet by calling
if_init(), 0 on success, != 0 on failure. Pull common code from
ex(4), gem(4), nfe(4), sip(4), tlp(4), vge(4) into ether_ioctl(),
and register if_flags callbacks for those drivers.

Return ENOTTY instead of EINVAL for inappropriate ioctls. In
zyd(4), use ENXIO instead of ENOTTY to indicate that the device is
not any longer attached.

Add to if_set_sadl() a boolean 'factory' argument that indicates
whether a link-layer address was assigned by the factory or some
other source. In a comment, recommend using the factory address
for generating an EUI64, and update in6_get_hw_ifid() to prefer a
factory address to any other link-layer address.

Add a routing message, RTM_LLINFO_UPD, that tells protocols to
update the binding of network-layer addresses to link-layer addresses.
Implement this message in IPv4 and IPv6 by sending a gratuitous
ARP or a neighbor advertisement, respectively. Generate RTM_LLINFO_UPD
messages on a change of an interface's link-layer address.

In ether_ioctl(), do not let SIOCALIFADDR set a link-layer address
that is broadcast/multicast or equal to 00:00:00:00:00:00.

Make ether_ioctl() call ifioctl_common() to handle ioctls that it
does not understand.

In gif(4), initialize if_softc and use it, instead of assuming that
the gif_softc and ifp overlap.

Let ifioctl_common() handle SIOCGIFADDR.

Sprinkle rtcache_invariants(), which checks on DIAGNOSTIC kernels
that certain invariants on a struct route are satisfied.

In agr(4), rewrite agr_ioctl_filter() to be a bit more explicit
about the ioctls that we do not allow on an agr(4) member interface.

bzero -> memset. Delete unnecessary casts to void *. Use
sockaddr_in_init() and sockaddr_in6_init(). Compare pointers with
NULL instead of "testing truth". Replace some instances of (type
*)0 with NULL. Change some K&R prototypes to ANSI C, and join
lines.


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 wrstuden-revivesa-base-1 simonb-wapbl-nbase yamt-pf42-base4 simonb-wapbl-base yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 yamt-nfs-mp-base2 wrstuden-revivesa-base yamt-nfs-mp-base yamt-pf42-base ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 1.104 15-Mar-2008 dyoung

branches: 1.104.4; 1.104.10; 1.104.12;
Cosmetic: make rtw_hw_keysupp() return a bool instead of int. In
rtw_wep_setkeys(), add a debug printf, and move the initialization
of keylen from the for-loop to the declaration.


# 1.103 14-Mar-2008 dyoung

Extract subroutine rtw_tx_kick() from rtw_start(), and reuse it in
rtw_io_enable() to restart the transmitter after resetting it.


# 1.102 14-Mar-2008 dyoung

Change tests for "impossible" keys to KASSERT()s. Get rid of a
temporary variable. In rtw_key_delete(), do not invalidate the
hardware keys unless a WEP key is deleted.


# 1.101 12-Mar-2008 dyoung

Use device_t and its accessors throughout. Use aprint_*_dev().

Improve PMF-ability.

Add a 'flags' argument to suspend/resume handlers and
callers such as pmf_system_suspend().

Define a flag, PMF_F_SELF, which indicates to PMF that a
device is suspending/resuming itself. Add helper routines,
pmf_device_suspend_self(dev) and pmf_device_resume_self(dev),
that call pmf_device_suspend(dev, PMF_F_SELF) and
pmf_device_resume(dev, PMF_F_SELF), respectively. Use
PMF_F_SELF to suspend/resume self in ath(4), audio(4),
rtw(4), and sip(4).

In ath(4) and in rtw(4), replace the icky sc_enable/sc_disable
callbacks, provided by the bus front-end, with
self-suspension/resumption. Also, clean up the bus
front-ends. Make sure that the interrupt handler is
disestablished during suspension. Get rid of driver-private
flags (e.g., RTW_F_ENABLED, ath_softc->sc_invalid); use
device_is_active()/device_has_power() calls, instead.

In the network-class suspend handler, call if_stop(, 0)
instead of if_stop(, 1), because the latter is superfluous
(bus- and driver-suspension hooks will 'disable' the NIC),
and it may cause recursion.

In the network-class resume handler, prevent infinite
recursion through if_init() by getting out early if we are
self-suspending (PMF_F_SELF).

rtw(4) improvements:

Destroy rtw(4) callouts when we detach it. Make rtw at
pci detachable. Print some more information with the "rx
frame too long" warning.

Remove activate() methods:

Get rid of rtw_activate() and ath_activate(). The device
activate() methods are not good for much these days.

Make ath at cardbus resume with crypto functions intact:

Introduce a boolean device property, "pmf-powerdown". If
pmf-powerdown is present and false, it indicates that a
bus back-end should not remove power from a device.

Honor this property in cardbus_child_suspend().

Set this property to 'false' in ath_attach(), since removing
power from an ath at cardbus seems to lobotomize the WPA
crypto engine. XXX Should the pmf-powerdown property
propagate toward the root of the device tree?

Miscellaneous ath(4) changes:

Warn if ath(4) tries to write crypto keys to suspended
hardware.

Reduce differences between FreeBSD and NetBSD in ath(4)
multicast filter setup.

Make ath_printrxbuf() print an rx descriptor's status &
key index, to help debug crypto errors.

Shorten a staircase in ath_ioctl(). Don't check for
ieee80211_ioctl() return code ERESTART, it never happens.


# 1.100 12-Mar-2008 dyoung

Print the TPPoll register when the Tx DMA engine doesn't shut down
in the time we allow.


# 1.99 03-Mar-2008 tsutsui

Explicitly include <sys/device.h> for device_t.


Revision tags: nick-net80211-sync-base vmlocking2-base3 bouyer-xeni386-nbase bouyer-xeni386-base mjf-devfs-base matt-armv6-base hpcarm-cleanup-base
# 1.98 21-Dec-2007 dyoung

branches: 1.98.2; 1.98.6;
Do not embed a struct device in rtw_softc any longer. Register
both pci and cardbus attachments with CFATTACH_DECL_NEW(). Access
the softc through the device_t using device_private().

While I'm here, change a couple of KASSERT()s about the Rx buffer
length to a warning.


# 1.97 20-Dec-2007 dyoung

Remove shutdown hooks. Use KASSERT().


# 1.96 16-Dec-2007 dyoung

Fix a bug I introduced to rtw_chan2txpower() the other night.

Fix a bug in device detachment: change a break statement to a
/*FALLTHROUGH*/ in rtw_detach().


# 1.95 16-Dec-2007 dyoung

Synchronize device detachment with network interrupts. Use the
pmf network class instead of powerhooks.


Revision tags: yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 bouyer-xenamd64-base2 vmlocking-nbase bouyer-xenamd64-base jmcneill-pm-base reinoud-bufcleanup-base
# 1.94 18-Nov-2007 jnemeth

branches: 1.94.2; 1.94.6;
fix 'm' used unitialized


# 1.93 16-Nov-2007 dyoung

Accommodate the variety of RF front-ends when radiotapping frames:
tap only RSSI when there is a Philips RF front-end. Tap both Barker
lock quality and RSSI when there is any other RF front-end.

Provide radiotap listeners a more complete picture of channel
activity:

in promiscuous mode, tap frames who do not pass the CRC32 check.
Flag packets that were received with a short preamble. Ask
the NIC to pass us 802.11 Control frames. Pass frames to
radiotap listeners before stripping the FCS. Re-order operations
in rtw_intr_rx() in order to accomplish all of this, taking
care not to pass a broken packet to net80211!

Do not provide a flags field when tapping xmitted frames.

Assert sane Rx packet lengths. Really should check and drop instead
of KASSERTing. I will revisit this, soon.

Update copyright.


# 1.92 15-Nov-2007 dyoung

Fix order of operations:

rtw_rxdesc_init: before initializing a Rx descriptor's
control word, synchronize the Rx buffer

rtw_start, be paranoid: set the "NIC owns" bit on a Tx
descriptor dead last. Always reinitialize the "next
Tx descriptor" pointer, just in case it got clobbered
somehow.

Let the compiler decide whether to inline rtw_collect_txring or
not.


Revision tags: jmcneill-base
# 1.91 19-Oct-2007 ad

branches: 1.91.2;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h


Revision tags: yamt-x86pmap-base4 yamt-x86pmap-base3 yamt-x86pmap-base2 vmlocking-base
# 1.90 29-Sep-2007 scw

branches: 1.90.2;
s/NPBFILTER/NBPFILTER/ in some #endif comments. No functional change.


Revision tags: nick-csl-alignment-base5 yamt-x86pmap-base matt-mips64-base nick-csl-alignment-base mjf-ufs-trans-base
# 1.89 09-Jul-2007 ad

branches: 1.89.6; 1.89.8; 1.89.10;
Merge some of the less invasive changes from the vmlocking branch:

- kthread, callout, devsw API changes
- select()/poll() improvements
- miscellaneous MT safety improvements


# 1.88 29-May-2007 dyoung

Fix rtw(4) on NetBSD/macppc: use bus_space_write_region_stream_4()
instead of bus_space_write_region_4() to write WEP Rx keys to the
NIC. Thanks macallan@ for detecting the bug and testing the fix.


# 1.87 29-May-2007 dyoung

Cosmetic: simplify a memset() statement, use __arraycount(), and
remove a gratuitous return statement at the end of a void subroutine.


# 1.86 29-May-2007 dyoung

Simplify multicast filter programming, and take care to avoid
gratuitous device resets when the kernel adds/deletes a multicast
address.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base
# 1.85 04-Mar-2007 christos

branches: 1.85.2; 1.85.4;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.


Revision tags: ad-audiomp-base post-newlock2-merge newlock2-nbase newlock2-base
# 1.84 29-Jan-2007 dyoung

branches: 1.84.2;
In rtw_dequeue(), initialize *mp to NULL before anything else, so
that it is either NULL or a valid mbuf. Previously, it was possible
for rtw_dequeue() to exit with 0 before initializing *mp. rtw_start()
would have used whatever trash was in *mp, which would lead to
problems later on.


# 1.83 06-Jan-2007 dyoung

I have made a small change that suppresses "recovery" from (spurious?)
tx timeouts on the beacon queue. The driver's recovery process
badly disrupts the MAC's receiver. This needs a closer look, later.

Every other fix is by Charles M. Hannum. Charles writes:

"With these, the device is quite stable under load, does not experience
xmit timeouts, no longer mysteriously freezes, and does not spew
a lot of garbage. It does, however, continue to get some "tx fifo
underflow"s.

global, SYSCTL_SETUP():
a) Removed unused sysctl variables.

rtw_io_enable():
b) Change rtw_io_enable to take a softc, and make it call
rtw_txring_fixup().
c) Enable the PCI multiple read/write bit.
d) Always reset rdb_next to 0 when starting the receive engine.

rtw_intr_rx():
e) When processing receive packets, store the next pointer in rdb_next
and read it back on the next round, to fix a race condition vs.
rtw_tune() during AP discovery and association.
f) Remove the special "skip to 0th descriptor" code, because it is no
longer needed.

rtw_collect_txring():
g) In the "force" case, stop when we catch up to the hardware xmit
pointer.

rtw_intr_beacon():
h) Resetting tdb_next here looked fishy to me, in light of changes in
rtw_collect_txring(). XXX However, this is the one part I haven't
tested.

rtw_txring_fixup():
i) Add function and line arguments, so we can print out information
about the caller.
j) In addition to reading the hardware pointer, skip over any
additional packets with OWN set -- we may have queued more.

rtw_rxring_fixup():
k) Remove this, because it's completely wrong.

rtw_intr_ioerror():
l) Don't handle receive overruns here; handle them in the normal receive
path. Also changed RTW_INTR_RX and RTW_INTR_IOERROR accordingly.
m) Do not fiddle with CR; the transmit engine is still running just
fine.
n) Do not fiddle with IMR; it was unnecessary.
o) Don't touch the receive engine at all; not necessary now that we're
leaving CR alone.
p) Remove the rtw_do_chip_reset case; it was dangerous and not actually
used.

rtw_intr():
q) Don't mask off ISR bits when we pass down the ISR value; it's not
necessary, and sometimes the other bits useful in debugging output.

rtw_seg_too_short():
r) Don't spew here; the caller will do it if necessary. (Stops spewage
in an expected case.)

rtw_rxdesc_blk:
s) Minor change to make the elements have the same order as txdesc_blk.

general:
t) Added a bunch of debugging output, #ifdef RTW_DIAG, that was useful
while investigating the ring management problems. Also moved
rtw_txring_fixup() into RTW_DIAG, as I believe the transmit pointer
is always kept in sync now, and the function has potential race
conditions.


# 1.82 06-Jan-2007 dyoung

After we examine a rx/tx descriptor and find that it's still owned
by the NIC, re-sync the descriptor so that a cacheline will not
"cover" the NIC's modifications to the descriptor when we next
examine it.

This compiles, but I have not tested it, yet.


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase wrstuden-fixsa-base-1 netbsd-4-0-RELEASE netbsd-4-0-RC5 matt-nb4-arm-base netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 wrstuden-fixsa-base yamt-splraiseipl-base5 yamt-splraiseipl-base4 yamt-splraiseipl-base3 netbsd-4-base
# 1.81 16-Nov-2006 christos

__unused removal on arguments; approved by core.


# 1.80 13-Nov-2006 dyoung

Stop using typeof() in the bit-twiddling macros, per yamt@'s
suggestion. This change requires that I use the __PRIuBITS format
string in atw and rtw, so do that.


Revision tags: yamt-splraiseipl-base2
# 1.79 12-Oct-2006 xtraeme

Use __unused in function arguments where appropiate.


# 1.78 12-Oct-2006 christos

- sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386


# 1.77 24-Sep-2006 jmcneill

Add "name" parameter to powerhook_establish, to aid debugging. No objections
on tech-kern@


Revision tags: yamt-splraiseipl-base yamt-pdpolicy-base9 yamt-pdpolicy-base8 rpaulo-netinet-merge-pcb-base
# 1.76 03-Sep-2006 christos

branches: 1.76.2; 1.76.4;
- comment out impossible comparisons
- remove superfluous if statement


# 1.75 31-Aug-2006 dyoung

Per discussion on tech-kern and tech-userlevel, move the bit-twiddling
macros, __BIT, __BITS, SHIFTIN, SHIFTOUT, and __arraycount() from
lib/libkern/libkern.h to sys/cdefs.h. Add a __-prefix to SHIFTIN
and SHIFTOUT, and add a manual page for the bit-twiddling macros,
bits(3).

Make the __BIT and __BITS macros "widthless," as best I can, by
changing their type to uintmax_t from uint32_t. XXX The manual
page lags this change by a bit.

Define __PRIxBIT and __PRIxBITS printf(3) format strings.


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base7 yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base simonb-timecounters-base
# 1.74 26-May-2006 blymn

Clean up bogus whitespace


Revision tags: yamt-pdpolicy-base5
# 1.73 14-May-2006 christos

branches: 1.73.2;
XXX: GCC uninitialized


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 elad-kernelauth-base
# 1.72 28-Mar-2006 dyoung

Revamp ieee80211_get_rate. Now it does not use the rateset in the
ic->ic_bss, but it uses the rateset in its new ieee80211_node
argument, instead. If the rate is fixed by ic->ic_fixed_rate, but
the fixed rate is not in the node's rateset, choose a reasonable
default: prefer the lowest basic rate or, if there is no basic
rate, prefer the lowest rate, period.

Change a printf complaint to a debug message.

Adapt drivers to suit new ieee80211_get_rate calling convention.

XXX I really need to replace ieee80211_get_rate with a bitrate
XXX adaptation algorithm. Soon, soon....


# 1.71 27-Mar-2006 dyoung

Set the channel frequency and flags in the radiotap headers in
rtw_tune instead of in rtw_start, rtw_intr_rx.


# 1.70 27-Mar-2006 dyoung

Remove unused argument ifflagsp from rtw_dmamap_load_txbuf.


Revision tags: peter-altq-base yamt-pdpolicy-base2
# 1.69 08-Mar-2006 dyoung

branches: 1.69.2;
Change macro names to avoid collisions:

BIT -> __BIT
BITS -> __BITS


# 1.68 08-Mar-2006 dyoung

Move my bit-twiddling macros to libkern.h from my drivers, where
I had duplicated them. Improve the macros' names. Simplify their
implementation.

A brief description of each macro is below.

BIT(n): Return a bitmask with bit m set, where the least
significant bit is bit 0.

BITS(m, n): Return a bitmask with bits m through n, inclusive,
set. It does not matter whether m>n or m<=n.
The least significant bit is bit 0.

A "bitfield" is a span of consecutive bits defined by a
bitmask, where 1s select the bits in the bitfield. SHIFTIN,
SHIFTOUT, and SHIFTOUT_MASK help read and write bitfields
from device registers.

SHIFTIN(v, mask): Left-shift bits `v' into the bitfield
defined by `mask', and return them. No
side-effects.

SHIFTOUT(v, mask): Extract and return the bitfield selected
by `mask' from `v', right-shifting the
bits so that the rightmost selected bit
is at bit 0. No side-effects.

SHIFTOUT_MASK(mask): Right-shift the bits in `mask' so that
the rightmost non-zero bit is at bit
0. This is useful for finding the
greatest unsigned value that a bitfield
can hold. No side-effects. Note that
SHIFTOUT_MASK(m) = SHIFTOUT(m, m).

Examples:

/*
* Register definitions taken from the RFMD RF3000 manual.
*/
#define RF3000_GAINCTL 0x11 /* TX variable gain control */
#define RF3000_GAINCTL_TXVGC_MASK BITS(7, 2)
#define RF3000_GAINCTL_SCRAMBLER BIT(1)

/*
* Shift the transmit power into the transmit-power field of the
* gain-control register and write it to the baseband processor.
*/
atw_rf3000_write(sc, RF3000_GAINCTL,
SHIFTIN(txpower, RF3000_GAINCTL_TXVGC_MASK));


/*
* Register definitions taken from the ADMtek ADM8211 manual.
*
*/
#define ATW_RXSTAT_OWN BIT(31) /* 1: NIC may fill descriptor */
/* ... */
#define ATW_RXSTAT_DA1 BIT(17) /* DA bit 1, admin'd address */
#define ATW_RXSTAT_DA0 BIT(16) /* DA bit 0, group address */
#define ATW_RXSTAT_RXDR_MASK BITS(15,12) /* RX data rate */
#define ATW_RXSTAT_FL_MASK BITS(11,0) /* RX frame length, last
* descriptor only
*/

/* Extract the frame length from the Rx descriptor's
* status field.
*/
len = SHIFTOUT(rxstat, ATW_RXSTAT_FL_MASK);


Revision tags: yamt-pdpolicy-base yamt-uio_vmspace-base5
# 1.67 20-Feb-2006 thorpej

branches: 1.67.2; 1.67.4;
Use device_is_active() rather than testing dv_flags for DVF_ACTIVE
directly.


# 1.66 19-Feb-2006 dyoung

When rtw_enable is called, power may have been removed and re-applied,
so invalidate the WEP key registers to force us to write the keys
back to the hardware.

Revamp key handling: use the hardware WEP engine for 40-bit and
104-bit keys, only; use software WEP for all other key lengths.
Set the hardware key length to the length of the default Tx key,
or if there is no default Tx key, use the length of the longest
WEP key.


# 1.65 04-Feb-2006 dyoung

In rtw_{rx,tx}ring_fixup, do not set the tx/rx ring index to
something out of bounds if we read an invalid pointer form the
hardware. Prevents a panic when an rtw@cardbus is ejected.


# 1.64 29-Dec-2005 dyoung

branches: 1.64.2; 1.64.4; 1.64.6;
Add support for the GCT Semiconductor GRF5101 transceiver/synthesizer.
From OpenBSD.

GCT will not provide any documentation, so there are many magic
numbers in this code.


# 1.63 29-Dec-2005 dyoung

Update rtw(4) for the new IBSS merge idiom, where ieee80211_ibss_merge()
does not return ENETRESET if the driver should change its BSSID,
but it makes a RUN->RUN transition, instead.


# 1.62 29-Dec-2005 dyoung

In atw(4), use ieee80211_compute_duration() to compute IEEE 802.11
Duration and PLCP Length fields, and delete the abominable
atw_frame_setdurs() subroutine.

Make rtw(4) use the new ieee80211_compute_duration() calling
convention.

Add an ieee80211_key argument to ieee80211_compute_duration() and
lightly constify arguments. Get the crypto header length from the
key argument instead of blithely assuming a WEP header. Add some
inline documentation. Account for data padding (IEEE80211_F_DATAPAD).


# 1.61 24-Dec-2005 perry

Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.


# 1.60 13-Dec-2005 dyoung

Fix comments and debug printfs: Tx FIFOs underflow, they don't
overflow.


# 1.59 13-Dec-2005 dyoung

On a transmit FIFO overflow (err, actually an underflow...) reset
both the transmit & receive sections of the MAC.


Revision tags: yamt-readahead-base3 ktrace-lwp-base
# 1.58 23-Nov-2005 dyoung

Miscellaneous Realtek RTL8180L driver improvements:

1 Added new sysctl controls for debugging.

2 Improve detection & support for hardware WEP.

3 Revamp handling of transmit descriptor rings.

4 Reliably IFF_OACTIVE when transmit descriptors are available, to
stop the transmit section of the driver from freezing up.

5 Fix beacon transmission in adhoc and hostap modes. XXX There is
a wart in hostap mode, where beacons are transmitted at 1/2 the
correct rate. Load beacon descriptors when the RTW_INTR_BINT
interrupt arrives; schedule RTW_INTR_BINT 1ms ahead of the target
beacon time.

6 Recover more gracefully from tx/rx errors: avoid
transmitter/receiver/chip resets. Try to re-synchronize software
state with hardware state---e.g., load next descriptor pointer
from hardware.

7 Activate the transmit watchdog timer for beacons as well as other
packets.

8 Introduce rtw_idle() that waits for transmit DMA to finish; call
it before resetting the transmitter.


Revision tags: yamt-readahead-base2
# 1.57 18-Nov-2005 skrll

Adapt drivers to the new net80211(9).

Most of this is from dyoung@. Thanks!


Revision tags: yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base
# 1.56 22-Sep-2005 gdt

branches: 1.56.6;
Make arg of IFQ_SET_READY be &ifp->if_snd, to match all other drivers
and be compilable with altq enabled. Reviewed by dyoung@


# 1.55 07-Sep-2005 dogcow

With the assistance of dyoung, fix the following problems:
* some 8180L cards need a longer time for the srom to initialize; patch
suggested via OpenBSD.
* some cards give '0' for USA, some give '3'; for the meantime, accept both
as being USA locale cards.
* this is RTW, not ATW. :)


# 1.54 06-Sep-2005 dogcow

make rtw.c compile again after the 22-jun-05 net80211 import


# 1.53 11-Jul-2005 dyoung

Add undefined variable 'ic' to rtw_attach.


# 1.52 06-Jul-2005 dyoung

Historically, an(4), ath(4), atw(4), rtw(4), and wi(4) have printed
out their modes and rates at boot. Revert to the historical
behavior.


# 1.51 06-Jul-2005 dyoung

Avoid an unnecessary API difference between NetBSD and FreeBSD:
back out my change to ieee80211_crypto_encap that made it free its
mbuf argument on error. I had thought it was a bug. It was not.
It's the drivers that are broken. Make an(4), atw(4), ipw(4),
iwi(4), ral(4), rtw(4), ural(4), and wi(4) free the mbuf when
ieee80211_crypto_encap returns NULL. Also, return ath(4) to the
way it was---i.e., free the mbuf.

Thanks to Sam Leffler to pointing out my mistake.


# 1.50 28-Jun-2005 dyoung

branches: 1.50.2;
Here is a grotty hack that lets the RTL8180L handle WEP in the
receive direction, while software handles WEP in the transmit
direction. When net80211 calls rtw's rtw_key_set with a WEP key,
I point the key's wk_cipher at our "fake" cipher, rtw_cipher_wep,
which is alike to ieee80211_cipher_wep except it provides a different
crypto-decapsulation routine, rtw_wep_decap. rtw_wep_decap copies
the key passed to it by net80211, clears the key's SWCRYPT flag,
and then calls wep_decap. Now wep_decap will decapsulate, but it
will *not* re-decrypt.

XXX I need to check whether the hardware supports 40-bit WEP,
XXX 104-bit WEP, or both, and act accordingly.


# 1.49 27-Jun-2005 dyoung

rtw: Try to get hardware WEP to work. It seems to work in
the RX direction, but not in the TX direction. The
net80211 crypto framework doesn't seem to cope very well
with the assymetry (I'm probably missing something), so
I will use software WEP for now.

net80211: In ieee80211_compute_duration, figure out whether to add
the WEP header to the packet overhead by checking the
WEP bit in the Frame Control field of the 802.11 header,
instead of checking the IEEE80211_F_PRIVACY flag.

Also, if the WEP bit is present, assume that the frame
described by (wh, len) has already already been WEP
encapsulated, and adjust the payload length accordingly.
XXX that's a grotty hack that I will have to revisit,
later.


# 1.48 22-Jun-2005 dyoung

Resolve conflicts in importation of 18-May-2005 ath(4) / net80211(9)
from FreeBSD. Introduce compatibility shims (sys/dev/ic/ath_netbsd.[ch],
sys/net80211/ieee80211_netbsd.[ch]). Update drivers (an, atu, atw,
awi, ipw, iwi, rtw, wi) for the new net80211(9) API.


# 1.47 20-Jun-2005 atatat

Change the rest of the sysctl subsystem to use const consistently.
The __UNCONST macro is now used only where necessary and the RW macros
are gone. Most of the changes here are consumers of the
sysctl_createv(9) interface that now takes a pair of const pointers
which used not to be.


# 1.46 10-Jun-2005 dyoung

Sprinkle __UNCONST() and rename variables to quiet uiet -Wcast-qual,
-Wshadow complaints.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 yamt-km-base4 yamt-km-base3 netbsd-3-base kent-audio2-base
# 1.45 02-Mar-2005 dyoung

Misc. changes to improve ad hoc mode and to enable hostap mode:

Fix the work-around for the NIC bug where it skips to rx
descriptor 0. The driver used to skip to rx descriptor 1.
Hopefully this stops the out-of-order packet reception that
Charles Hannum saw.
When debugging is enabled, print rx-descriptor status flags
before printing the rx bit rate.

Add a debug message for when a beacon tx buffer reclamation.

Reset IFF_OACTIVE when we reset the transmitter.

Pass the consolidated LED state, a struct rtw_led_state,
to rtw_led_attach.

Choose the bit-rate for management frames (1Mb/s) at the
same place we choose for all other frames.

Do not use the NIC's short preamble or RTS options for
management frames. Label beacons for the NIC.

Following a Linux driver, take care not to zero arbitrary
bits in the TPPOLL register.

Use the new idiom for IBSS merges: disable transmitter,
kick the state machine.
Add a second descriptor to the beacon ring. The NIC seems
to like this much better.


# 1.44 27-Feb-2005 perry

nuke trailing whitespace


Revision tags: yamt-km-base2
# 1.43 31-Jan-2005 thorpej

Eliminate use of M_HASFCS.


Revision tags: yamt-km-base
# 1.42 16-Jan-2005 dyoung

branches: 1.42.2; 1.42.4;
Move the register access mode into struct rtw_regs. Change
rtw_set_access, rtw_set_access1 to match.

Add a subroutine for setting WEP keys. WEP isn't quite finished,
because I have to add the WEP header to Tx packets. Implement the
SIOCS80211NWKEY ioctl for setting WEP keys.

Program the LEDs based on operating state and packet activity.

* On a Revision F RTL8180, blink LED1 at 1Hz to indicate
scan/authenticate/associate states. In the run state, turn LED1
on. In every state, blink LED1 at 5Hz to indicate non-beacon
tx/rx activity. I would like to use two LEDs, but in all my
Rev. F instances, LED0 is not wired to an LED; instead, the
first LED is wired to indicate that the card's power is on.

* On a Revision D RTL8180, program the LEDs so that LED0 indicates
Tx, and LED1 indicates Rx. The Rx LED will blink annoyingly if
there are beacons in the air, but at least the Tx LED is useful.

* Store the hardware revision in the softc to support my futile
attempt at programming LEDs for both Rev. D and Rev. F parts;
I never did get Rev. D LEDs to work right.

* Add a debug flag RTW_DEBUG_LED for the LED transitions.

Add RTW_TPPOLL_ALL, RTW_TPPOLL_SALL to start and stop, respectively,
all of the transmit rings.

In ad hoc mode, allocate a beacon and load it into the beacon ring.
Start the ring. In one trial, the card re-transmitted the beacon
ring's contents several times before stopping. More programming
and testing for ad hoc mode is necessary. I'm not setting the
beacon flag in the transmit descriptor.

Revamp the transmit section to make better use of all the transmit
rings: beacon queue, high-, low-, and medium-priority rings. Put
beacon frames on the beacon ring. All other management frames,
and data frames, go on the medium-priority ring. Power-save data
frames go on the high-priority ring. (Note that powersaving is
not implemented!) This is a work in progress.

Send all 802.11 Management frames at 1Mbps.

After we put a packet on a transmit ring, tickle the right bit in
the TPPOLL to tell RTL8180. Stop all rings on error and in rtw_stop.

Use the RF chip type, not the RTL8180 revision, to choose between
host- and MAC-controlled RF serial I/O. Now the Netgear MA521
works.

Remove bogus definition of bit RTW_TPPOLL_FSWINT.


Revision tags: kent-audio1-beforemerge
# 1.41 04-Jan-2005 dyoung

Set initial conditions to guarantee that when read_seeprom toggles
Chip Select, it turns *on* rather than *off*.


# 1.40 04-Jan-2005 dyoung

Add the logic for IBSS merges.


# 1.39 03-Jan-2005 dyoung

sys/dev/ic/rtw.c:

Cosmetic: remove two short ladders from rtw_init. Fit the
NIC registers print-out onto one line using the RTW_PRINT_REGS
macro.

sys/dev/ic/rtwvar.h:

Add RTW_PRINT_REGS wrapper macro for rtw_print_regs. It
is a null op unless defined(RTW_DEBUG).


# 1.38 03-Jan-2005 dyoung

In sys/dev/ic/rtw.c:

Use clue from rtk(4) and re(4) to fix the rtw(4) packet
filter. Previously, I was using the wrong CRC32 function
to hash multicast addresses; to compensate, I set the
multicast filter to all 1s. Now that I hash the addresses
correctly, I do not any longer set the filter to all 1s.

In rtw_ioctl, avoid gratuitous re-initialization when the
interface flags change. If a !IFF_UP -> IFF_UP transition,
call rtw_init(); otherwise, only reload the packet filter.

In sys/dev/ic/rtwreg.h:

Put useful combinations of Receiver Control Register flags
in RTW_RCR_PKTFILT_MASK, RTW_RCR_MONITOR, and
RTW_RCR_PKTFILT_DEFAULT. (XXX RTW_RCR_MONITOR should be
called RTW_RCR_PKTFILT_MONITOR.)


# 1.37 02-Jan-2005 dyoung

Cosmetic: change u_int{8,16,32,64}_t to C99-style uint{8,16,32,64}_t,
which is preferred.


# 1.36 29-Dec-2004 dyoung

In rtw_detach, flag the rtw as "invalid" (RTW_F_INVALID). Do not
try to power-down the RF section of an invalid rtw.

The radiotap signal quality field is 16, not 8, bits wide. Convert
the byte order.


# 1.35 29-Dec-2004 dyoung

Remove some dead code.


# 1.34 29-Dec-2004 dyoung

I like the tlp/atw-style names for software descriptors, txsoft,
better than txctl. Change from rtw_txctl/rtw_rxctl to
rtw_txsoft/rtw_rxsoft. Change the descriptor blocks' names to
match: rtw_txctl_blk becomes rtw_txsoft_blk. Change the member-name
prefixes for both software and hardware descriptors.


# 1.33 29-Dec-2004 dyoung

Consolidate variables related to the rx ring in sc_rxdesc_blk,
which is a struct rtw_rxdesc_blk.

Put a copy of the DMA tag and the DMA map into the rx- and tx-ring
blocks so that I don't have to pass them to subroutines all of the
time.


# 1.32 28-Dec-2004 dyoung

Add bpf(4) packet taps to rtw(4). Now you can tap DLT_EN10MB
(Ethernet II), DLT_IEEE802_11 (802.11), and DLT_IEEE802_11_RADIO
(radiotap + 802.11).


# 1.31 28-Dec-2004 dyoung

If defined(RTW_DEBUG), provide a sysctl (hw.rtw.rxbufs_limit) for
limiting the number of rx buffers an rtw may allocate. Use this
sysctl to test the code that copes with buffer exhaustion.

Allocate at most RTW_RXQLEN rx buffers, stopping at the sysctl
limit. Record in sc_nrxdesc how many were allocated, and put the
end-of-ring indication on sc_rxdesc[sc_nrxdesc - 1]. In rtw_init,
if no rx buffers could be allocated, log a complaint, clear
IFF_RUNNING, and exit with an error.

Many changes to accomodate a short rx ring, mainly of the "add a
rx-ring length argument" variety. XXX I really should consolidate
all of the rx ring variables in one struct and pass that to the
rx-ring subroutines.

Bug fix: after calling MCLGET, use the (m->m_flags & M_EXT) idiom
to check for success, instead of m != NULL.

Bug fix: at the top of rtw_start, if IFF_RUNNING is not set, or
IFF_OACTIVE is, get out.


# 1.30 27-Dec-2004 dyoung

Use a table to convert the hardware's bit rates (0, 1, 2, 3) to
net80211 bit rates (2, 4, 11, 22).

Count input errors (if_ierrors++) for "DMA error/FIFO overflow"
and unknown bit rate.


# 1.29 27-Dec-2004 dyoung

Simplify the reset we do on a transmit timeout. Really, this could
be as simple as rtw_stop(, 0), rtw_init().


# 1.28 27-Dec-2004 mycroft

Use the last descriptor to count collisions and failed transmissions, too.


# 1.27 27-Dec-2004 mycroft

When checking if a split packet is completed, check the *last* segment, not
the first. Otherwise we can overwrite parts of the TX ring that we shouldn't.

Kluge the basic rate setting for now.

Minor simplification to the dequeueing logic.


# 1.26 27-Dec-2004 dyoung

Remove useless debug sysctls.

For AP scanning, change the channel dwell time from 1 second to
1/5 second.


# 1.25 27-Dec-2004 mycroft

Replace d_plcp_svc with d_residue. The latter is the number of whole
empty/unused octets to fill out the data time slot. The value is constrained
by math to 0 for <= 5.5Mb, 0-1 for 11Mb, and 0-2 for 22Mb. It is used to
signal to the MAC that there is residue.


# 1.24 26-Dec-2004 dyoung

Make rtw(4) build w/o RTW_DEBUG. Thanks to Charles Hannum for
pointing out my oversight.


# 1.23 25-Dec-2004 dyoung

The rx descriptor ring bug happens quite often, so printf'ing
occurrences is annoying. Only printf about it when rtw_debug
contains RTW_DEBUG_BUG.


# 1.22 25-Dec-2004 dyoung

IMPORTANT: set m->m_pkthdr.rcvif on rx'd packets. Illegal memory
references abound without this fix.

In rtw_intr_rx, skip to the next rx packet earlier if the rx packet
length is too short.

Also in rtw_intr_rx, if a packet is rx'd with unknown rate, printf
a warning, drop the packet, recycle the rx buffer, skip to next rx
packet.


# 1.21 25-Dec-2004 dyoung

Change rtw_debug from a debug level to a debug mask. Add a lot of
debug flags.

From Linux: handle an RTL8180 bug. Sometimes the NIC skips from
the middle of the ring to the 0th rx descriptor. Now the driver
resynchronizes.

Handle a receive descriptor underrun or Rx FIFO overflow condition
in the way that the Linux driver does. This kind of seems like
overkill, but whatever.

Protect rtw_ioctl with splnet().

Do not load a tx descriptor with a buffer shorter than 4 bytes.

Handle a transmit timeout less disruptively.


# 1.20 23-Dec-2004 dyoung

Oops, straggler from last commit: set the 802.11 Duration field
with the result from ieee80211_compute_duration.


# 1.19 23-Dec-2004 dyoung

Fix a bug in ieee80211_compute_duration: the 802.11 Duration field
in an 802.11 unicast data packet is equal to the duration of the
SIFS and Acknowledgement. That is, the amount of time reserved
*after* the packet has finished transmitting.

Change the arguments to ieee80211_compute_duration: pass the entire
packet length, not just the payload length. Add a 'debug' argument
to ieee80211_compute_duration and its helper subroutine,
ieee80211_compute_duration1.

If debug != 0, ieee80211_compute_duration printfs its arguments
and several local variables.

In rtw(4), load the 802.11 Duration field with the result from
ieee80211_compute_duration.


# 1.18 23-Dec-2004 dyoung

Bug fix: in rtw_rxbuf_alloc, unload the previous mbuf chain before
loading the new chain.


# 1.17 23-Dec-2004 dyoung

DMA-synchronize the Rx buffers before re-initializing them.
XXX not necessary?


# 1.16 23-Dec-2004 dyoung

Add more comprehensive debug messages as we setup transmit descriptors.
Also, dump packets if IFF_DEBUG|IFF_LINK2. Factor out a subroutine
for printing transmit-descriptor debug messages.


# 1.15 23-Dec-2004 dyoung

Disable interrupts and stop transmit DMA before disabling the
transmitter and receiver.


# 1.14 23-Dec-2004 dyoung

Shorten variables, s/txctl/ctl/. This is rtw_start, after all:
transmission is implied.


# 1.13 23-Dec-2004 dyoung

Do not indicate to the NIC that the host has appended the CRC32 to
Tx frames.


# 1.12 23-Dec-2004 dyoung

When we set up the supported rates table, mark 1Mb/s, 2Mb/s as
basic rates.


# 1.11 23-Dec-2004 dyoung

Extract the transmission status from a tx descriptor, and convert
to host byte-order, once.


# 1.10 20-Dec-2004 dyoung

Realtek sample sources are not consistent about the "Digital PHY"
bit in the SROM. It seems as if it is set to 1 when the PHY is
*analog*, not *digital*. Fix my sources.

In rtw_intr_rx, use units of 500kb/s instead of 100kb/s for rate,
to be consistent with net80211's expectations. Polish up some
debugging ugly messages. Dump raw 802.11 packets if IFF_DEBUG|IFF_LINK2
and RTW_DEBUG is defined.

Polish power-state (on/sleep/off) handling. Especially improve
support for RFMD (totally untested) and Maxim. For Philips, take
the Digital PHY property into account.

Call the net80211 watchdog function from rtw_watchdog, so that we
scan again if auth/assoc fails.

Be a little more cautious about writing register[RTW_TPPOLL], since
other drivers are.... Don't frob the high/low-priority queues
right now, since I don't use them.

Add rtw_join_bss which programs the card with the BSSID and other
properties of a BSS. Use it on state transitions. Factor out
rtw_set_nettype.

Make rtw_recv_beacon call ieee80211_recv_mgmt instead of dropping
beacons on the floor! TBD IBSS merges.

Change some rtw_debug=2 printfs to rtw_debug=3 (RTW_DPRINTF3)
printfs so the console doesn't get spammed so badly at rtw_debug=2.
Change some debugging printfs to RTW_DPRINTFs. E.g., print the
"RF programming method" only if debugging is enabled.


# 1.9 20-Dec-2004 dyoung

Fix bug in last commit: use &sc->sc_regs, regs is not defined.


# 1.8 20-Dec-2004 dyoung

Add some bus barriers. Remark where they are needed, e.g.,
read_eeprom.

Change some printfs to RTW_DPRINTF2s to quiet rtw(4) when debugging
is disabled.


# 1.7 20-Dec-2004 dyoung

Get rid of the silly char (*dvname)[IFNAMSIZ] pattern. Replace it
with const char *dvname. I'm not sure what I was thinking.


# 1.6 20-Dec-2004 dyoung

Assert that I'm DMA-syncing a non-negative number of transmit
descriptors.

As I free dirty transmit buffers, move them to the free list, not
back to the dirty list!

Add a 5-second transmit timeout.


# 1.5 19-Dec-2004 dyoung

Add the transmit section of rtw(4): build up and tear down transmit
descriptor rings, move packets from the transmit queues to the
transmit rings, handle transmission-completed interrupts. My
Linksys WPC11 ver. 4 with Maxim RF, generates interrupts like it
is successfully transmitting packets. Clearly there are bugs: my
G4 Powerbook locks up hard. I will debug tomorrow.


# 1.4 13-Dec-2004 dyoung

At last, I have rtw w/ Philips RF receiving packets.

I added some sysctls to aid debugging:

* hw.rtw.debug -- enable debugging

* hw.rtw.flush_rfio -- Linux voodoo: possibly makes the MAC
"flush" bits down the serial bus to the RF

* hw.rtw.host_rfio: force the host to bang bits to the RF, instead
of the MAC banging bits

* hw.rtw.rfio_delay: after telling the MAC to bang bits to the
RF front-end, delay rfio_delay microseconds.

* hw.rtw.rfprog_fallback: there is this notion of the "RF
programming method." I believe the choice influences the
polarity/timing of the serial bus used to program the RF
front-end. I know the correct choice for Intersil/RFMD/Philips
front-ends, only. For all other front-ends, I "fallback" to
rfprog_fallback.

Make rtw_txdac_enable take an rtw_softc argument. I will probably
revert this change.

Add some Linux voodoo to rtw_continuous_tx_enable. I will probably
revert this change.

Important: add rtw_set_rfprog, which sets the correct RF programming
method. This change and the following change are probably responsible
for making the Philips RF work.

Important: RTW_CONFIG1 is an 8-bit register, treat it that way!

Important: RTW_BRSR is 16-bit, RTW_CRCOUNT, RTW_PHYDELAY, and
RTW_MSR are 8-bit: treat them that way!

Vastly simplify rtw_resume_ticks.

Note to self: set the LED state to match the power state.

Hedge against the possibility that RTW_MSR is protected as
RTW_CONFIG[0123] are, meanwhile reworking that section of rtw_init
a little.

Add sc_anaparm, which isn't used, yet....


# 1.3 12-Dec-2004 dyoung

Miscellaneous changes. Details below. Important changes flagged
with []. Using the driver with my Linksys WPC11 ver. 4, it seems
to be receiving packets for a change. The WPC11 ver. 4 has a Maxim
RF section. My no-name rtw with Philips RF section still does not
receive any packets.

Keep access-level (analog params > config[0123] registers > none)
in sc_access. Add rtw_set_access for changing the access level.

Make rtw_continuous_tx_enable and other subroutines use rtw_set_access
instead of rtw_config0123_enable and rtw_anaparm_enable.

Factor part of the chip-reset code into rtw_chip_reset1.

Change the 'struct foo (*bar)[N]'-style arguments to
'struct foo *bar'-style arguments.

Consolidate software/hardware Tx/Rx ring setup in rtw_hwring_setup,
rtw_swring_setup.

Add a new constant, SA2400_OPMODE_DEFAULTS, for the bits that we
*always* set in the SA2400 OPMODE register.

Factor some code out into rtw_sa2400_calibrate. (Inspired by the
Linux driver.)

[] When the receiver goes into underrun/overflow state, call a new
subroutine, rtw_kick() that stops the Rx/Tx processes, resets
the chip, reinitializes the Tx/Rx rings, and restarts Rx/Tx
processes. (Inspired by the Linux driver.)

[] In rtw_intr_rx, check for too-short packets before calling
ieee80211_find_rxnode. I believe this will prevent a repeat of
the MCHK exception I saw once on macppc.

[] Use seconds-elapased as well as microseconds-elapsed to set the
next "due date" for the timeout interrupt. This keeps the driver
from programming the timeout to expire too early.

[] In rtw_intr, read RTW_ISR at most 10 times, then get out. If
the interface is not enabled (RTW_F_ENABLED), then get out.

[] In rtw_stop, get out if the interface is not enabled (RTW_F_ENABLED).
Block IPL_NET interrupts. Don't read/write any registers if
the interface is invalid (RTW_F_INVALID).

[] Call rtw_stop in rtw_detach.


Revision tags: kent-audio1-base
# 1.2 30-Oct-2004 thorpej

When adding/deleting multicast addresses, only whack the address
filter if the interface is marked RUNNING.

Fixes kern/27678.


# 1.1 26-Sep-2004 dyoung

branches: 1.1.2;
Add work-in-progress driver rtw(4) for Realtek RTL8180 MAC/baseband.

Add register definitions for Maxim MAX2820 and Philips SA2400 radio
front-ends.


# 1.133 28-May-2019 msaitoh

Use ETHER_LOCK()/ETHER_UNLOCK() for all ethernet drivers to protect ec_multi*.


# 1.132 23-May-2019 msaitoh

Whitespace fix (mainly tabify).


# 1.131 23-May-2019 msaitoh

-No functional change:
- KNF
- u_int*_t -> uint*_t.


Revision tags: isaki-audio2-base
# 1.130 05-Feb-2019 msaitoh

Remove very old IFF_NOTRAILERS flag.


# 1.129 03-Feb-2019 mrg

- add or adjust /* FALLTHROUGH */ where appropriate
- add __unreachable() after functions that can return but won't in
this case, and thus can't be marked __dead easily


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 jdolecek-ncqfixes-base pgoyette-compat-0728 phil-wifi-base
# 1.128 26-Jun-2018 msaitoh

Implement the BPF direction filter (BIOC[GS]DIRECTION). It provides backward
compatibility with BIOC[GS]SEESENT ioctl. The userland interface is the same
as FreeBSD.

This change also fixes a bug that the direction is misunderstand on some
environment by passing the direction to bpf_mtap*() instead of checking
m->m_pkthdr.rcvif.


Revision tags: pgoyette-compat-0625 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base tls-maxphys-base-20171202
# 1.127 23-Oct-2017 msaitoh

branches: 1.127.2;
If if_initialize() failed in the attach function, free resources and return.


Revision tags: matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base
# 1.126 23-May-2017 ozaki-r

branches: 1.126.2;
Apply deferred if_start to more drivers

And annotate some XXX_start as it runs in softint to clarify that
it doesn't need deferred if_start.


Revision tags: prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 nick-nhusb-base-20170204
# 1.125 02-Feb-2017 nonaka

wlan interfaces make interrupt routine running on softint context.

see http://mail-index.netbsd.org/tech-kern/2016/12/06/msg021281.html

tested device:
* ath at pci: AR5212, AR5424
* athn at pci: AR9287
* ipw at pci: 2100BG
* iwi at pci: 2915ABG
* iwm at pci: 3165, 7260, 8260
* iwn at pci: 4945, 6235
* ral at pci: RT2560
* rtwn at pci: RTL8192CE


Revision tags: bouyer-socketcan-base pgoyette-localcount-20170107 nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.124 15-Sep-2016 jdolecek

branches: 1.124.2;
remove last isolated islands using BUS_SPACE_BARRIER_SYNC and
BUS_SPACE_BARRIER_X_BEFORE_X - these were only ever defined for mips and ia64,
and never actually implemented even there


Revision tags: localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907
# 1.123 10-Jun-2016 ozaki-r

branches: 1.123.2;
Introduce m_set_rcvif and m_reset_rcvif

The API is used to set (or reset) a received interface of a mbuf.
They are counterpart of m_get_rcvif, which will come in another
commit, hide internal of rcvif operation, and reduce the diff of
the upcoming change.

No functional change.


Revision tags: nick-nhusb-base-20160529
# 1.122 16-May-2016 ozaki-r

Use M_GETCTX and M_SETCTX instead of open-coding rcvif

No functional change.


Revision tags: netbsd-7-2-RELEASE netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 netbsd-7-0-RELEASE nick-nhusb-base-20150921 netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 nick-nhusb-base-20150606 nick-nhusb-base-20150406 nick-nhusb-base netbsd-7-base yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 rmind-smpnet-nbase rmind-smpnet-base tls-maxphys-base
# 1.121 25-Feb-2014 pooka

branches: 1.121.6;
Ensure that the top level sysctl nodes (kern, vfs, net, ...) exist before
the sysctl link sets are processed, and remove redundancy.

Shaves >13kB off of an amd64 GENERIC, not to mention >1k duplicate
lines of code.


# 1.120 17-Oct-2013 christos

- remove unused variables
- move variables inside ifdef sections
- ifdef notdef unused code
- use __USE for debugging variables


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE yamt-pagecache-tag8 netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 agc-symver-base netbsd-6-1-RC2 netbsd-6-1-RC1 yamt-pagecache-base8 netbsd-6-0-1-RELEASE yamt-pagecache-base7 matt-nb6-plus-nbase yamt-pagecache-base6 netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base10 yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.119 04-Jul-2011 joerg

branches: 1.119.2; 1.119.12; 1.119.16;
Fix memset usage.


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base matt-mips64-premerge-20101231 rmind-uvmplock-base
# 1.118 15-Nov-2010 uebayasi

Socket ioctl definitions need sys/sockio.h.


# 1.117 13-Nov-2010 uebayasi

Don't pull in the whole uvm(9) API to access only PAGE_SIZE and
some other constants. These are provided by sys/param.h now.


Revision tags: uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10 uebayasi-xip-base1
# 1.116 05-Apr-2010 joerg

Push the bpf_ops usage back into bpf.h. Push the common ifp->if_bpf
check into the inline functions as well the fourth argument for
bpf_attach.


# 1.115 15-Mar-2010 dyoung

Make this compile on sparc64:

1 s/next_tick/next_tint/ because next_tick shadows a global on sparc64.

2 Fix the bus-barrier helper routines, which had the tag & handle
swapped (!!). Move the helpers from rtwreg.h to rtwvar.h, and
change RTW_BARRIER() into an inline subroutine called rtw_barrier().


Revision tags: yamt-nfs-mp-base9
# 1.114 24-Feb-2010 dyoung

branches: 1.114.2;
A pointer typedef entails trading too much flexibility to declare const
and non-const types, and the kernel uses both const and non-const
PMF qualifiers and device suspensors, so change the pmf_qual_t and
device_suspensor_t typedefs from "pointers to const" to non-pointer,
non-const types.


Revision tags: uebayasi-xip-base
# 1.113 31-Jan-2010 dyoung

branches: 1.113.2;
Add the missing newline to a verbose autoconf message.


# 1.112 19-Jan-2010 pooka

Redefine bpf linkage through an always present op vector, i.e.
#if NBPFILTER is no longer required in the client. This change
doesn't yet add support for loading bpf as a module, since drivers
can register before bpf is attached. However, callers of bpf can
now be modularized.

Dynamically loadable bpf could probably be done fairly easily with
coordination from the stub driver and the real driver by registering
attachments in the stub before the real driver is loaded and doing
a handoff. ... and I'm not going to ponder the depths of unload
here.

Tested with i386/MONOLITHIC, modified MONOLITHIC without bpf and rump.


# 1.111 08-Jan-2010 dyoung

Expand PMF_FN_* macros.


Revision tags: matt-premerge-20091211 jym-xensuspend-nbase
# 1.110 19-Oct-2009 rmind

Drop 3rd and 4th clauses from David Young's license.
Reviewed and approved by dyoung@ (copyright holder).


# 1.109 16-Sep-2009 dyoung

In pmf(9), improve the implementation of device self-suspension
and make suspension by self, by drvctl(8), and by ACPI system sleep
play nice together. Start solidifying some temporary API changes.

1. Extract a new header file, <sys/device_if.h>, from <sys/device.h> and
#include it from <sys/pmf.h> instead of <sys/device.h> to break the
circular dependency between <sys/device.h> and <sys/pmf.h>.

2. Introduce pmf_qual_t, an aggregate of qualifications on a PMF
suspend/resume call. Start to replace instances of PMF_FN_PROTO,
PMF_FN_ARGS, et cetera, with a pmf_qual_t.

3. Introduce the notion of a "suspensor," an entity that holds a
device in suspension. More than one suspensor may hold a device
at once. A device stays suspended as long as at least one
suspensor holds it. A device resumes when the last suspensor
releases it.

Currently, the kernel defines three suspensors,

3a the system-suspensor: for system suspension, initiated
by 'sysctl -w machdep.sleep_state=3', by lid closure, by
power-button press, et cetera,

3b the drvctl-suspensor: for device suspension by /dev/drvctl
ioctl, e.g., drvctl -S sip0.

3c the system self-suspensor: for device drivers that suspend
themselves and their children. Several drivers for network
interfaces put the network device to sleep while it is not
administratively up, that is, after the kernel calls if_stop(,
1). The self-suspensor should not be used directly. See
the description of suspensor delegates, below.

A suspensor can have one or more "delegates". A suspensor can
release devices that its delegates hold suspended. Right now,
only the system self-suspensor has delegates. For each device
that a self-suspending driver attaches, it creates the device's
self-suspensor, a delegate of the system self-suspensor.

Suspensors stop a system-wide suspend/resume cycle from waking
devices that the operator put to sleep with drvctl before the cycle.
They also help self-suspension to work more simply, safely, and in
accord with expectations.

4. Add the notion of device activation level, devact_level_t,
and a routine for checking the current activation level,
device_activation(). Current activation levels are DEVACT_LEVEL_BUS,
DEVACT_LEVEL_DRIVER, and DEVACT_LEVEL_CLASS, which respectively
indicate that the device's bus is active, that the bus and device are
active, and that the bus, device, and the functions of the device's
class (network, audio) are active.

Suspend/resume calls can be qualified with a devact_level_t.
The power-management framework treats a devact_level_t that
qualifies a device suspension as the device's current activation
level; it only runs hooks to reduce the activation level from
the presumed current level to the fully suspended state. The
framework treats a devact_level_t qualifying device resumption
as the target activation level; it only runs hooks to raise the
activation level to the target.

5. Use pmf_qual_t, devact_level_t, and self-suspensors in several
drivers.

6. Temporarily add an unused power-management workqueue that I will
remove or replace, soon.


Revision tags: yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5 yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 nick-hppapmap-base3 jym-xensuspend-base nick-hppapmap-base
# 1.108 07-Apr-2009 dyoung

Cosmetic: remove some dead code.


# 1.107 02-Apr-2009 dyoung

Add the WEP capability to our net80211 capability flags, since we do
sort of support hardware WEP. Only change the WEP key index in a Tx
descriptor from 0 if the type of our transmit key is _WEP, not _TKIP:
i.e., only if we're really doing WEP crypto in the hardware.

Ignore a watchdog timeout on any Tx ring if we can collect some packets
from that ring. Restart both the receiver and the transmitter when a
watchdog timeout occurs instead of restarting only the transmitter.


Revision tags: nick-hppapmap-base2 haad-dm-base2 haad-nbase2 ad-audiomp2-base haad-dm-base mjf-devfs2-base
# 1.106 12-Nov-2008 ad

branches: 1.106.4;
Remove LKMs and switch to the module framework, pass 1.

Proposed on tech-kern@.


# 1.105 07-Nov-2008 dyoung

*** Summary ***

When a link-layer address changes (e.g., ifconfig ex0 link
02:de:ad:be:ef:02 active), send a gratuitous ARP and/or a Neighbor
Advertisement to update the network-/link-layer address bindings
on our LAN peers.

Refuse a change of ethernet address to the address 00:00:00:00:00:00
or to any multicast/broadcast address. (Thanks matt@.)

Reorder ifnet ioctl operations so that driver ioctls may inherit
the functions of their "class"---ether_ioctl(), fddi_ioctl(), et
cetera---and the class ioctls may inherit from the generic ioctl,
ifioctl_common(), but both driver- and class-ioctls may override
the generic behavior. Make network drivers share more code.

Distinguish a "factory" link-layer address from others for the
purposes of both protecting that address from deletion and computing
EUI64.

Return consistent, appropriate error codes from network drivers.

Improve readability. KNF.

*** Details ***

In if_attach(), always initialize the interface ioctl routine,
ifnet->if_ioctl, if the driver has not already initialized it.
Delete if_ioctl == NULL tests everywhere else, because it cannot
happen.

In the ioctl routines of network interfaces, inherit common ioctl
behaviors by calling either ifioctl_common() or whichever ioctl
routine is appropriate for the class of interface---e.g., ether_ioctl()
for ethernets.

Stop (ab)using SIOCSIFADDR and start to use SIOCINITIFADDR. In
the user->kernel interface, SIOCSIFADDR's argument was an ifreq,
but on the protocol->ifnet interface, SIOCSIFADDR's argument was
an ifaddr. That was confusing, and it would work against me as I
make it possible for a network interface to overload most ioctls.
On the protocol->ifnet interface, replace SIOCSIFADDR with
SIOCINITIFADDR. In ifioctl(), return EPERM if userland tries to
invoke SIOCINITIFADDR.

In ifioctl(), give the interface the first shot at handling most
interface ioctls, and give the protocol the second shot, instead
of the other way around. Finally, let compatibility code (COMPAT_OSOCK)
take a shot.

Pull device initialization out of switch statements under
SIOCINITIFADDR. For example, pull ..._init() out of any switch
statement that looks like this:

switch (...->sa_family) {
case ...:
..._init();
...
break;
...
default:
..._init();
...
break;
}

Rewrite many if-else clauses that handle all permutations of IFF_UP
and IFF_RUNNING to use a switch statement,

switch (x & (IFF_UP|IFF_RUNNING)) {
case 0:
...
break;
case IFF_RUNNING:
...
break;
case IFF_UP:
...
break;
case IFF_UP|IFF_RUNNING:
...
break;
}

unifdef lots of code containing #ifdef FreeBSD, #ifdef NetBSD, and
#ifdef SIOCSIFMTU, especially in fwip(4) and in ndis(4).

In ipw(4), remove an if_set_sadl() call that is out of place.

In nfe(4), reuse the jumbo MTU logic in ether_ioctl().

Let ethernets register a callback for setting h/w state such as
promiscuous mode and the multicast filter in accord with a change
in the if_flags: ether_set_ifflags_cb() registers a callback that
returns ENETRESET if the caller should reset the ethernet by calling
if_init(), 0 on success, != 0 on failure. Pull common code from
ex(4), gem(4), nfe(4), sip(4), tlp(4), vge(4) into ether_ioctl(),
and register if_flags callbacks for those drivers.

Return ENOTTY instead of EINVAL for inappropriate ioctls. In
zyd(4), use ENXIO instead of ENOTTY to indicate that the device is
not any longer attached.

Add to if_set_sadl() a boolean 'factory' argument that indicates
whether a link-layer address was assigned by the factory or some
other source. In a comment, recommend using the factory address
for generating an EUI64, and update in6_get_hw_ifid() to prefer a
factory address to any other link-layer address.

Add a routing message, RTM_LLINFO_UPD, that tells protocols to
update the binding of network-layer addresses to link-layer addresses.
Implement this message in IPv4 and IPv6 by sending a gratuitous
ARP or a neighbor advertisement, respectively. Generate RTM_LLINFO_UPD
messages on a change of an interface's link-layer address.

In ether_ioctl(), do not let SIOCALIFADDR set a link-layer address
that is broadcast/multicast or equal to 00:00:00:00:00:00.

Make ether_ioctl() call ifioctl_common() to handle ioctls that it
does not understand.

In gif(4), initialize if_softc and use it, instead of assuming that
the gif_softc and ifp overlap.

Let ifioctl_common() handle SIOCGIFADDR.

Sprinkle rtcache_invariants(), which checks on DIAGNOSTIC kernels
that certain invariants on a struct route are satisfied.

In agr(4), rewrite agr_ioctl_filter() to be a bit more explicit
about the ioctls that we do not allow on an agr(4) member interface.

bzero -> memset. Delete unnecessary casts to void *. Use
sockaddr_in_init() and sockaddr_in6_init(). Compare pointers with
NULL instead of "testing truth". Replace some instances of (type
*)0 with NULL. Change some K&R prototypes to ANSI C, and join
lines.


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 wrstuden-revivesa-base-1 simonb-wapbl-nbase yamt-pf42-base4 simonb-wapbl-base yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 yamt-nfs-mp-base2 wrstuden-revivesa-base yamt-nfs-mp-base yamt-pf42-base ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 1.104 15-Mar-2008 dyoung

branches: 1.104.4; 1.104.10; 1.104.12;
Cosmetic: make rtw_hw_keysupp() return a bool instead of int. In
rtw_wep_setkeys(), add a debug printf, and move the initialization
of keylen from the for-loop to the declaration.


# 1.103 14-Mar-2008 dyoung

Extract subroutine rtw_tx_kick() from rtw_start(), and reuse it in
rtw_io_enable() to restart the transmitter after resetting it.


# 1.102 14-Mar-2008 dyoung

Change tests for "impossible" keys to KASSERT()s. Get rid of a
temporary variable. In rtw_key_delete(), do not invalidate the
hardware keys unless a WEP key is deleted.


# 1.101 12-Mar-2008 dyoung

Use device_t and its accessors throughout. Use aprint_*_dev().

Improve PMF-ability.

Add a 'flags' argument to suspend/resume handlers and
callers such as pmf_system_suspend().

Define a flag, PMF_F_SELF, which indicates to PMF that a
device is suspending/resuming itself. Add helper routines,
pmf_device_suspend_self(dev) and pmf_device_resume_self(dev),
that call pmf_device_suspend(dev, PMF_F_SELF) and
pmf_device_resume(dev, PMF_F_SELF), respectively. Use
PMF_F_SELF to suspend/resume self in ath(4), audio(4),
rtw(4), and sip(4).

In ath(4) and in rtw(4), replace the icky sc_enable/sc_disable
callbacks, provided by the bus front-end, with
self-suspension/resumption. Also, clean up the bus
front-ends. Make sure that the interrupt handler is
disestablished during suspension. Get rid of driver-private
flags (e.g., RTW_F_ENABLED, ath_softc->sc_invalid); use
device_is_active()/device_has_power() calls, instead.

In the network-class suspend handler, call if_stop(, 0)
instead of if_stop(, 1), because the latter is superfluous
(bus- and driver-suspension hooks will 'disable' the NIC),
and it may cause recursion.

In the network-class resume handler, prevent infinite
recursion through if_init() by getting out early if we are
self-suspending (PMF_F_SELF).

rtw(4) improvements:

Destroy rtw(4) callouts when we detach it. Make rtw at
pci detachable. Print some more information with the "rx
frame too long" warning.

Remove activate() methods:

Get rid of rtw_activate() and ath_activate(). The device
activate() methods are not good for much these days.

Make ath at cardbus resume with crypto functions intact:

Introduce a boolean device property, "pmf-powerdown". If
pmf-powerdown is present and false, it indicates that a
bus back-end should not remove power from a device.

Honor this property in cardbus_child_suspend().

Set this property to 'false' in ath_attach(), since removing
power from an ath at cardbus seems to lobotomize the WPA
crypto engine. XXX Should the pmf-powerdown property
propagate toward the root of the device tree?

Miscellaneous ath(4) changes:

Warn if ath(4) tries to write crypto keys to suspended
hardware.

Reduce differences between FreeBSD and NetBSD in ath(4)
multicast filter setup.

Make ath_printrxbuf() print an rx descriptor's status &
key index, to help debug crypto errors.

Shorten a staircase in ath_ioctl(). Don't check for
ieee80211_ioctl() return code ERESTART, it never happens.


# 1.100 12-Mar-2008 dyoung

Print the TPPoll register when the Tx DMA engine doesn't shut down
in the time we allow.


# 1.99 03-Mar-2008 tsutsui

Explicitly include <sys/device.h> for device_t.


Revision tags: nick-net80211-sync-base vmlocking2-base3 bouyer-xeni386-nbase bouyer-xeni386-base mjf-devfs-base matt-armv6-base hpcarm-cleanup-base
# 1.98 21-Dec-2007 dyoung

branches: 1.98.2; 1.98.6;
Do not embed a struct device in rtw_softc any longer. Register
both pci and cardbus attachments with CFATTACH_DECL_NEW(). Access
the softc through the device_t using device_private().

While I'm here, change a couple of KASSERT()s about the Rx buffer
length to a warning.


# 1.97 20-Dec-2007 dyoung

Remove shutdown hooks. Use KASSERT().


# 1.96 16-Dec-2007 dyoung

Fix a bug I introduced to rtw_chan2txpower() the other night.

Fix a bug in device detachment: change a break statement to a
/*FALLTHROUGH*/ in rtw_detach().


# 1.95 16-Dec-2007 dyoung

Synchronize device detachment with network interrupts. Use the
pmf network class instead of powerhooks.


Revision tags: yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 bouyer-xenamd64-base2 vmlocking-nbase bouyer-xenamd64-base jmcneill-pm-base reinoud-bufcleanup-base
# 1.94 18-Nov-2007 jnemeth

branches: 1.94.2; 1.94.6;
fix 'm' used unitialized


# 1.93 16-Nov-2007 dyoung

Accommodate the variety of RF front-ends when radiotapping frames:
tap only RSSI when there is a Philips RF front-end. Tap both Barker
lock quality and RSSI when there is any other RF front-end.

Provide radiotap listeners a more complete picture of channel
activity:

in promiscuous mode, tap frames who do not pass the CRC32 check.
Flag packets that were received with a short preamble. Ask
the NIC to pass us 802.11 Control frames. Pass frames to
radiotap listeners before stripping the FCS. Re-order operations
in rtw_intr_rx() in order to accomplish all of this, taking
care not to pass a broken packet to net80211!

Do not provide a flags field when tapping xmitted frames.

Assert sane Rx packet lengths. Really should check and drop instead
of KASSERTing. I will revisit this, soon.

Update copyright.


# 1.92 15-Nov-2007 dyoung

Fix order of operations:

rtw_rxdesc_init: before initializing a Rx descriptor's
control word, synchronize the Rx buffer

rtw_start, be paranoid: set the "NIC owns" bit on a Tx
descriptor dead last. Always reinitialize the "next
Tx descriptor" pointer, just in case it got clobbered
somehow.

Let the compiler decide whether to inline rtw_collect_txring or
not.


Revision tags: jmcneill-base
# 1.91 19-Oct-2007 ad

branches: 1.91.2;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h


Revision tags: yamt-x86pmap-base4 yamt-x86pmap-base3 yamt-x86pmap-base2 vmlocking-base
# 1.90 29-Sep-2007 scw

branches: 1.90.2;
s/NPBFILTER/NBPFILTER/ in some #endif comments. No functional change.


Revision tags: nick-csl-alignment-base5 yamt-x86pmap-base matt-mips64-base nick-csl-alignment-base mjf-ufs-trans-base
# 1.89 09-Jul-2007 ad

branches: 1.89.6; 1.89.8; 1.89.10;
Merge some of the less invasive changes from the vmlocking branch:

- kthread, callout, devsw API changes
- select()/poll() improvements
- miscellaneous MT safety improvements


# 1.88 29-May-2007 dyoung

Fix rtw(4) on NetBSD/macppc: use bus_space_write_region_stream_4()
instead of bus_space_write_region_4() to write WEP Rx keys to the
NIC. Thanks macallan@ for detecting the bug and testing the fix.


# 1.87 29-May-2007 dyoung

Cosmetic: simplify a memset() statement, use __arraycount(), and
remove a gratuitous return statement at the end of a void subroutine.


# 1.86 29-May-2007 dyoung

Simplify multicast filter programming, and take care to avoid
gratuitous device resets when the kernel adds/deletes a multicast
address.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base
# 1.85 04-Mar-2007 christos

branches: 1.85.2; 1.85.4;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.


Revision tags: ad-audiomp-base post-newlock2-merge newlock2-nbase newlock2-base
# 1.84 29-Jan-2007 dyoung

branches: 1.84.2;
In rtw_dequeue(), initialize *mp to NULL before anything else, so
that it is either NULL or a valid mbuf. Previously, it was possible
for rtw_dequeue() to exit with 0 before initializing *mp. rtw_start()
would have used whatever trash was in *mp, which would lead to
problems later on.


# 1.83 06-Jan-2007 dyoung

I have made a small change that suppresses "recovery" from (spurious?)
tx timeouts on the beacon queue. The driver's recovery process
badly disrupts the MAC's receiver. This needs a closer look, later.

Every other fix is by Charles M. Hannum. Charles writes:

"With these, the device is quite stable under load, does not experience
xmit timeouts, no longer mysteriously freezes, and does not spew
a lot of garbage. It does, however, continue to get some "tx fifo
underflow"s.

global, SYSCTL_SETUP():
a) Removed unused sysctl variables.

rtw_io_enable():
b) Change rtw_io_enable to take a softc, and make it call
rtw_txring_fixup().
c) Enable the PCI multiple read/write bit.
d) Always reset rdb_next to 0 when starting the receive engine.

rtw_intr_rx():
e) When processing receive packets, store the next pointer in rdb_next
and read it back on the next round, to fix a race condition vs.
rtw_tune() during AP discovery and association.
f) Remove the special "skip to 0th descriptor" code, because it is no
longer needed.

rtw_collect_txring():
g) In the "force" case, stop when we catch up to the hardware xmit
pointer.

rtw_intr_beacon():
h) Resetting tdb_next here looked fishy to me, in light of changes in
rtw_collect_txring(). XXX However, this is the one part I haven't
tested.

rtw_txring_fixup():
i) Add function and line arguments, so we can print out information
about the caller.
j) In addition to reading the hardware pointer, skip over any
additional packets with OWN set -- we may have queued more.

rtw_rxring_fixup():
k) Remove this, because it's completely wrong.

rtw_intr_ioerror():
l) Don't handle receive overruns here; handle them in the normal receive
path. Also changed RTW_INTR_RX and RTW_INTR_IOERROR accordingly.
m) Do not fiddle with CR; the transmit engine is still running just
fine.
n) Do not fiddle with IMR; it was unnecessary.
o) Don't touch the receive engine at all; not necessary now that we're
leaving CR alone.
p) Remove the rtw_do_chip_reset case; it was dangerous and not actually
used.

rtw_intr():
q) Don't mask off ISR bits when we pass down the ISR value; it's not
necessary, and sometimes the other bits useful in debugging output.

rtw_seg_too_short():
r) Don't spew here; the caller will do it if necessary. (Stops spewage
in an expected case.)

rtw_rxdesc_blk:
s) Minor change to make the elements have the same order as txdesc_blk.

general:
t) Added a bunch of debugging output, #ifdef RTW_DIAG, that was useful
while investigating the ring management problems. Also moved
rtw_txring_fixup() into RTW_DIAG, as I believe the transmit pointer
is always kept in sync now, and the function has potential race
conditions.


# 1.82 06-Jan-2007 dyoung

After we examine a rx/tx descriptor and find that it's still owned
by the NIC, re-sync the descriptor so that a cacheline will not
"cover" the NIC's modifications to the descriptor when we next
examine it.

This compiles, but I have not tested it, yet.


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase wrstuden-fixsa-base-1 netbsd-4-0-RELEASE netbsd-4-0-RC5 matt-nb4-arm-base netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 wrstuden-fixsa-base yamt-splraiseipl-base5 yamt-splraiseipl-base4 yamt-splraiseipl-base3 netbsd-4-base
# 1.81 16-Nov-2006 christos

__unused removal on arguments; approved by core.


# 1.80 13-Nov-2006 dyoung

Stop using typeof() in the bit-twiddling macros, per yamt@'s
suggestion. This change requires that I use the __PRIuBITS format
string in atw and rtw, so do that.


Revision tags: yamt-splraiseipl-base2
# 1.79 12-Oct-2006 xtraeme

Use __unused in function arguments where appropiate.


# 1.78 12-Oct-2006 christos

- sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386


# 1.77 24-Sep-2006 jmcneill

Add "name" parameter to powerhook_establish, to aid debugging. No objections
on tech-kern@


Revision tags: yamt-splraiseipl-base yamt-pdpolicy-base9 yamt-pdpolicy-base8 rpaulo-netinet-merge-pcb-base
# 1.76 03-Sep-2006 christos

branches: 1.76.2; 1.76.4;
- comment out impossible comparisons
- remove superfluous if statement


# 1.75 31-Aug-2006 dyoung

Per discussion on tech-kern and tech-userlevel, move the bit-twiddling
macros, __BIT, __BITS, SHIFTIN, SHIFTOUT, and __arraycount() from
lib/libkern/libkern.h to sys/cdefs.h. Add a __-prefix to SHIFTIN
and SHIFTOUT, and add a manual page for the bit-twiddling macros,
bits(3).

Make the __BIT and __BITS macros "widthless," as best I can, by
changing their type to uintmax_t from uint32_t. XXX The manual
page lags this change by a bit.

Define __PRIxBIT and __PRIxBITS printf(3) format strings.


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base7 yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base simonb-timecounters-base
# 1.74 26-May-2006 blymn

Clean up bogus whitespace


Revision tags: yamt-pdpolicy-base5
# 1.73 14-May-2006 christos

branches: 1.73.2;
XXX: GCC uninitialized


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 elad-kernelauth-base
# 1.72 28-Mar-2006 dyoung

Revamp ieee80211_get_rate. Now it does not use the rateset in the
ic->ic_bss, but it uses the rateset in its new ieee80211_node
argument, instead. If the rate is fixed by ic->ic_fixed_rate, but
the fixed rate is not in the node's rateset, choose a reasonable
default: prefer the lowest basic rate or, if there is no basic
rate, prefer the lowest rate, period.

Change a printf complaint to a debug message.

Adapt drivers to suit new ieee80211_get_rate calling convention.

XXX I really need to replace ieee80211_get_rate with a bitrate
XXX adaptation algorithm. Soon, soon....


# 1.71 27-Mar-2006 dyoung

Set the channel frequency and flags in the radiotap headers in
rtw_tune instead of in rtw_start, rtw_intr_rx.


# 1.70 27-Mar-2006 dyoung

Remove unused argument ifflagsp from rtw_dmamap_load_txbuf.


Revision tags: peter-altq-base yamt-pdpolicy-base2
# 1.69 08-Mar-2006 dyoung

branches: 1.69.2;
Change macro names to avoid collisions:

BIT -> __BIT
BITS -> __BITS


# 1.68 08-Mar-2006 dyoung

Move my bit-twiddling macros to libkern.h from my drivers, where
I had duplicated them. Improve the macros' names. Simplify their
implementation.

A brief description of each macro is below.

BIT(n): Return a bitmask with bit m set, where the least
significant bit is bit 0.

BITS(m, n): Return a bitmask with bits m through n, inclusive,
set. It does not matter whether m>n or m<=n.
The least significant bit is bit 0.

A "bitfield" is a span of consecutive bits defined by a
bitmask, where 1s select the bits in the bitfield. SHIFTIN,
SHIFTOUT, and SHIFTOUT_MASK help read and write bitfields
from device registers.

SHIFTIN(v, mask): Left-shift bits `v' into the bitfield
defined by `mask', and return them. No
side-effects.

SHIFTOUT(v, mask): Extract and return the bitfield selected
by `mask' from `v', right-shifting the
bits so that the rightmost selected bit
is at bit 0. No side-effects.

SHIFTOUT_MASK(mask): Right-shift the bits in `mask' so that
the rightmost non-zero bit is at bit
0. This is useful for finding the
greatest unsigned value that a bitfield
can hold. No side-effects. Note that
SHIFTOUT_MASK(m) = SHIFTOUT(m, m).

Examples:

/*
* Register definitions taken from the RFMD RF3000 manual.
*/
#define RF3000_GAINCTL 0x11 /* TX variable gain control */
#define RF3000_GAINCTL_TXVGC_MASK BITS(7, 2)
#define RF3000_GAINCTL_SCRAMBLER BIT(1)

/*
* Shift the transmit power into the transmit-power field of the
* gain-control register and write it to the baseband processor.
*/
atw_rf3000_write(sc, RF3000_GAINCTL,
SHIFTIN(txpower, RF3000_GAINCTL_TXVGC_MASK));


/*
* Register definitions taken from the ADMtek ADM8211 manual.
*
*/
#define ATW_RXSTAT_OWN BIT(31) /* 1: NIC may fill descriptor */
/* ... */
#define ATW_RXSTAT_DA1 BIT(17) /* DA bit 1, admin'd address */
#define ATW_RXSTAT_DA0 BIT(16) /* DA bit 0, group address */
#define ATW_RXSTAT_RXDR_MASK BITS(15,12) /* RX data rate */
#define ATW_RXSTAT_FL_MASK BITS(11,0) /* RX frame length, last
* descriptor only
*/

/* Extract the frame length from the Rx descriptor's
* status field.
*/
len = SHIFTOUT(rxstat, ATW_RXSTAT_FL_MASK);


Revision tags: yamt-pdpolicy-base yamt-uio_vmspace-base5
# 1.67 20-Feb-2006 thorpej

branches: 1.67.2; 1.67.4;
Use device_is_active() rather than testing dv_flags for DVF_ACTIVE
directly.


# 1.66 19-Feb-2006 dyoung

When rtw_enable is called, power may have been removed and re-applied,
so invalidate the WEP key registers to force us to write the keys
back to the hardware.

Revamp key handling: use the hardware WEP engine for 40-bit and
104-bit keys, only; use software WEP for all other key lengths.
Set the hardware key length to the length of the default Tx key,
or if there is no default Tx key, use the length of the longest
WEP key.


# 1.65 04-Feb-2006 dyoung

In rtw_{rx,tx}ring_fixup, do not set the tx/rx ring index to
something out of bounds if we read an invalid pointer form the
hardware. Prevents a panic when an rtw@cardbus is ejected.


# 1.64 29-Dec-2005 dyoung

branches: 1.64.2; 1.64.4; 1.64.6;
Add support for the GCT Semiconductor GRF5101 transceiver/synthesizer.
From OpenBSD.

GCT will not provide any documentation, so there are many magic
numbers in this code.


# 1.63 29-Dec-2005 dyoung

Update rtw(4) for the new IBSS merge idiom, where ieee80211_ibss_merge()
does not return ENETRESET if the driver should change its BSSID,
but it makes a RUN->RUN transition, instead.


# 1.62 29-Dec-2005 dyoung

In atw(4), use ieee80211_compute_duration() to compute IEEE 802.11
Duration and PLCP Length fields, and delete the abominable
atw_frame_setdurs() subroutine.

Make rtw(4) use the new ieee80211_compute_duration() calling
convention.

Add an ieee80211_key argument to ieee80211_compute_duration() and
lightly constify arguments. Get the crypto header length from the
key argument instead of blithely assuming a WEP header. Add some
inline documentation. Account for data padding (IEEE80211_F_DATAPAD).


# 1.61 24-Dec-2005 perry

Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.


# 1.60 13-Dec-2005 dyoung

Fix comments and debug printfs: Tx FIFOs underflow, they don't
overflow.


# 1.59 13-Dec-2005 dyoung

On a transmit FIFO overflow (err, actually an underflow...) reset
both the transmit & receive sections of the MAC.


Revision tags: yamt-readahead-base3 ktrace-lwp-base
# 1.58 23-Nov-2005 dyoung

Miscellaneous Realtek RTL8180L driver improvements:

1 Added new sysctl controls for debugging.

2 Improve detection & support for hardware WEP.

3 Revamp handling of transmit descriptor rings.

4 Reliably IFF_OACTIVE when transmit descriptors are available, to
stop the transmit section of the driver from freezing up.

5 Fix beacon transmission in adhoc and hostap modes. XXX There is
a wart in hostap mode, where beacons are transmitted at 1/2 the
correct rate. Load beacon descriptors when the RTW_INTR_BINT
interrupt arrives; schedule RTW_INTR_BINT 1ms ahead of the target
beacon time.

6 Recover more gracefully from tx/rx errors: avoid
transmitter/receiver/chip resets. Try to re-synchronize software
state with hardware state---e.g., load next descriptor pointer
from hardware.

7 Activate the transmit watchdog timer for beacons as well as other
packets.

8 Introduce rtw_idle() that waits for transmit DMA to finish; call
it before resetting the transmitter.


Revision tags: yamt-readahead-base2
# 1.57 18-Nov-2005 skrll

Adapt drivers to the new net80211(9).

Most of this is from dyoung@. Thanks!


Revision tags: yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base
# 1.56 22-Sep-2005 gdt

branches: 1.56.6;
Make arg of IFQ_SET_READY be &ifp->if_snd, to match all other drivers
and be compilable with altq enabled. Reviewed by dyoung@


# 1.55 07-Sep-2005 dogcow

With the assistance of dyoung, fix the following problems:
* some 8180L cards need a longer time for the srom to initialize; patch
suggested via OpenBSD.
* some cards give '0' for USA, some give '3'; for the meantime, accept both
as being USA locale cards.
* this is RTW, not ATW. :)


# 1.54 06-Sep-2005 dogcow

make rtw.c compile again after the 22-jun-05 net80211 import


# 1.53 11-Jul-2005 dyoung

Add undefined variable 'ic' to rtw_attach.


# 1.52 06-Jul-2005 dyoung

Historically, an(4), ath(4), atw(4), rtw(4), and wi(4) have printed
out their modes and rates at boot. Revert to the historical
behavior.


# 1.51 06-Jul-2005 dyoung

Avoid an unnecessary API difference between NetBSD and FreeBSD:
back out my change to ieee80211_crypto_encap that made it free its
mbuf argument on error. I had thought it was a bug. It was not.
It's the drivers that are broken. Make an(4), atw(4), ipw(4),
iwi(4), ral(4), rtw(4), ural(4), and wi(4) free the mbuf when
ieee80211_crypto_encap returns NULL. Also, return ath(4) to the
way it was---i.e., free the mbuf.

Thanks to Sam Leffler to pointing out my mistake.


# 1.50 28-Jun-2005 dyoung

branches: 1.50.2;
Here is a grotty hack that lets the RTL8180L handle WEP in the
receive direction, while software handles WEP in the transmit
direction. When net80211 calls rtw's rtw_key_set with a WEP key,
I point the key's wk_cipher at our "fake" cipher, rtw_cipher_wep,
which is alike to ieee80211_cipher_wep except it provides a different
crypto-decapsulation routine, rtw_wep_decap. rtw_wep_decap copies
the key passed to it by net80211, clears the key's SWCRYPT flag,
and then calls wep_decap. Now wep_decap will decapsulate, but it
will *not* re-decrypt.

XXX I need to check whether the hardware supports 40-bit WEP,
XXX 104-bit WEP, or both, and act accordingly.


# 1.49 27-Jun-2005 dyoung

rtw: Try to get hardware WEP to work. It seems to work in
the RX direction, but not in the TX direction. The
net80211 crypto framework doesn't seem to cope very well
with the assymetry (I'm probably missing something), so
I will use software WEP for now.

net80211: In ieee80211_compute_duration, figure out whether to add
the WEP header to the packet overhead by checking the
WEP bit in the Frame Control field of the 802.11 header,
instead of checking the IEEE80211_F_PRIVACY flag.

Also, if the WEP bit is present, assume that the frame
described by (wh, len) has already already been WEP
encapsulated, and adjust the payload length accordingly.
XXX that's a grotty hack that I will have to revisit,
later.


# 1.48 22-Jun-2005 dyoung

Resolve conflicts in importation of 18-May-2005 ath(4) / net80211(9)
from FreeBSD. Introduce compatibility shims (sys/dev/ic/ath_netbsd.[ch],
sys/net80211/ieee80211_netbsd.[ch]). Update drivers (an, atu, atw,
awi, ipw, iwi, rtw, wi) for the new net80211(9) API.


# 1.47 20-Jun-2005 atatat

Change the rest of the sysctl subsystem to use const consistently.
The __UNCONST macro is now used only where necessary and the RW macros
are gone. Most of the changes here are consumers of the
sysctl_createv(9) interface that now takes a pair of const pointers
which used not to be.


# 1.46 10-Jun-2005 dyoung

Sprinkle __UNCONST() and rename variables to quiet uiet -Wcast-qual,
-Wshadow complaints.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 yamt-km-base4 yamt-km-base3 netbsd-3-base kent-audio2-base
# 1.45 02-Mar-2005 dyoung

Misc. changes to improve ad hoc mode and to enable hostap mode:

Fix the work-around for the NIC bug where it skips to rx
descriptor 0. The driver used to skip to rx descriptor 1.
Hopefully this stops the out-of-order packet reception that
Charles Hannum saw.
When debugging is enabled, print rx-descriptor status flags
before printing the rx bit rate.

Add a debug message for when a beacon tx buffer reclamation.

Reset IFF_OACTIVE when we reset the transmitter.

Pass the consolidated LED state, a struct rtw_led_state,
to rtw_led_attach.

Choose the bit-rate for management frames (1Mb/s) at the
same place we choose for all other frames.

Do not use the NIC's short preamble or RTS options for
management frames. Label beacons for the NIC.

Following a Linux driver, take care not to zero arbitrary
bits in the TPPOLL register.

Use the new idiom for IBSS merges: disable transmitter,
kick the state machine.
Add a second descriptor to the beacon ring. The NIC seems
to like this much better.


# 1.44 27-Feb-2005 perry

nuke trailing whitespace


Revision tags: yamt-km-base2
# 1.43 31-Jan-2005 thorpej

Eliminate use of M_HASFCS.


Revision tags: yamt-km-base
# 1.42 16-Jan-2005 dyoung

branches: 1.42.2; 1.42.4;
Move the register access mode into struct rtw_regs. Change
rtw_set_access, rtw_set_access1 to match.

Add a subroutine for setting WEP keys. WEP isn't quite finished,
because I have to add the WEP header to Tx packets. Implement the
SIOCS80211NWKEY ioctl for setting WEP keys.

Program the LEDs based on operating state and packet activity.

* On a Revision F RTL8180, blink LED1 at 1Hz to indicate
scan/authenticate/associate states. In the run state, turn LED1
on. In every state, blink LED1 at 5Hz to indicate non-beacon
tx/rx activity. I would like to use two LEDs, but in all my
Rev. F instances, LED0 is not wired to an LED; instead, the
first LED is wired to indicate that the card's power is on.

* On a Revision D RTL8180, program the LEDs so that LED0 indicates
Tx, and LED1 indicates Rx. The Rx LED will blink annoyingly if
there are beacons in the air, but at least the Tx LED is useful.

* Store the hardware revision in the softc to support my futile
attempt at programming LEDs for both Rev. D and Rev. F parts;
I never did get Rev. D LEDs to work right.

* Add a debug flag RTW_DEBUG_LED for the LED transitions.

Add RTW_TPPOLL_ALL, RTW_TPPOLL_SALL to start and stop, respectively,
all of the transmit rings.

In ad hoc mode, allocate a beacon and load it into the beacon ring.
Start the ring. In one trial, the card re-transmitted the beacon
ring's contents several times before stopping. More programming
and testing for ad hoc mode is necessary. I'm not setting the
beacon flag in the transmit descriptor.

Revamp the transmit section to make better use of all the transmit
rings: beacon queue, high-, low-, and medium-priority rings. Put
beacon frames on the beacon ring. All other management frames,
and data frames, go on the medium-priority ring. Power-save data
frames go on the high-priority ring. (Note that powersaving is
not implemented!) This is a work in progress.

Send all 802.11 Management frames at 1Mbps.

After we put a packet on a transmit ring, tickle the right bit in
the TPPOLL to tell RTL8180. Stop all rings on error and in rtw_stop.

Use the RF chip type, not the RTL8180 revision, to choose between
host- and MAC-controlled RF serial I/O. Now the Netgear MA521
works.

Remove bogus definition of bit RTW_TPPOLL_FSWINT.


Revision tags: kent-audio1-beforemerge
# 1.41 04-Jan-2005 dyoung

Set initial conditions to guarantee that when read_seeprom toggles
Chip Select, it turns *on* rather than *off*.


# 1.40 04-Jan-2005 dyoung

Add the logic for IBSS merges.


# 1.39 03-Jan-2005 dyoung

sys/dev/ic/rtw.c:

Cosmetic: remove two short ladders from rtw_init. Fit the
NIC registers print-out onto one line using the RTW_PRINT_REGS
macro.

sys/dev/ic/rtwvar.h:

Add RTW_PRINT_REGS wrapper macro for rtw_print_regs. It
is a null op unless defined(RTW_DEBUG).


# 1.38 03-Jan-2005 dyoung

In sys/dev/ic/rtw.c:

Use clue from rtk(4) and re(4) to fix the rtw(4) packet
filter. Previously, I was using the wrong CRC32 function
to hash multicast addresses; to compensate, I set the
multicast filter to all 1s. Now that I hash the addresses
correctly, I do not any longer set the filter to all 1s.

In rtw_ioctl, avoid gratuitous re-initialization when the
interface flags change. If a !IFF_UP -> IFF_UP transition,
call rtw_init(); otherwise, only reload the packet filter.

In sys/dev/ic/rtwreg.h:

Put useful combinations of Receiver Control Register flags
in RTW_RCR_PKTFILT_MASK, RTW_RCR_MONITOR, and
RTW_RCR_PKTFILT_DEFAULT. (XXX RTW_RCR_MONITOR should be
called RTW_RCR_PKTFILT_MONITOR.)


# 1.37 02-Jan-2005 dyoung

Cosmetic: change u_int{8,16,32,64}_t to C99-style uint{8,16,32,64}_t,
which is preferred.


# 1.36 29-Dec-2004 dyoung

In rtw_detach, flag the rtw as "invalid" (RTW_F_INVALID). Do not
try to power-down the RF section of an invalid rtw.

The radiotap signal quality field is 16, not 8, bits wide. Convert
the byte order.


# 1.35 29-Dec-2004 dyoung

Remove some dead code.


# 1.34 29-Dec-2004 dyoung

I like the tlp/atw-style names for software descriptors, txsoft,
better than txctl. Change from rtw_txctl/rtw_rxctl to
rtw_txsoft/rtw_rxsoft. Change the descriptor blocks' names to
match: rtw_txctl_blk becomes rtw_txsoft_blk. Change the member-name
prefixes for both software and hardware descriptors.


# 1.33 29-Dec-2004 dyoung

Consolidate variables related to the rx ring in sc_rxdesc_blk,
which is a struct rtw_rxdesc_blk.

Put a copy of the DMA tag and the DMA map into the rx- and tx-ring
blocks so that I don't have to pass them to subroutines all of the
time.


# 1.32 28-Dec-2004 dyoung

Add bpf(4) packet taps to rtw(4). Now you can tap DLT_EN10MB
(Ethernet II), DLT_IEEE802_11 (802.11), and DLT_IEEE802_11_RADIO
(radiotap + 802.11).


# 1.31 28-Dec-2004 dyoung

If defined(RTW_DEBUG), provide a sysctl (hw.rtw.rxbufs_limit) for
limiting the number of rx buffers an rtw may allocate. Use this
sysctl to test the code that copes with buffer exhaustion.

Allocate at most RTW_RXQLEN rx buffers, stopping at the sysctl
limit. Record in sc_nrxdesc how many were allocated, and put the
end-of-ring indication on sc_rxdesc[sc_nrxdesc - 1]. In rtw_init,
if no rx buffers could be allocated, log a complaint, clear
IFF_RUNNING, and exit with an error.

Many changes to accomodate a short rx ring, mainly of the "add a
rx-ring length argument" variety. XXX I really should consolidate
all of the rx ring variables in one struct and pass that to the
rx-ring subroutines.

Bug fix: after calling MCLGET, use the (m->m_flags & M_EXT) idiom
to check for success, instead of m != NULL.

Bug fix: at the top of rtw_start, if IFF_RUNNING is not set, or
IFF_OACTIVE is, get out.


# 1.30 27-Dec-2004 dyoung

Use a table to convert the hardware's bit rates (0, 1, 2, 3) to
net80211 bit rates (2, 4, 11, 22).

Count input errors (if_ierrors++) for "DMA error/FIFO overflow"
and unknown bit rate.


# 1.29 27-Dec-2004 dyoung

Simplify the reset we do on a transmit timeout. Really, this could
be as simple as rtw_stop(, 0), rtw_init().


# 1.28 27-Dec-2004 mycroft

Use the last descriptor to count collisions and failed transmissions, too.


# 1.27 27-Dec-2004 mycroft

When checking if a split packet is completed, check the *last* segment, not
the first. Otherwise we can overwrite parts of the TX ring that we shouldn't.

Kluge the basic rate setting for now.

Minor simplification to the dequeueing logic.


# 1.26 27-Dec-2004 dyoung

Remove useless debug sysctls.

For AP scanning, change the channel dwell time from 1 second to
1/5 second.


# 1.25 27-Dec-2004 mycroft

Replace d_plcp_svc with d_residue. The latter is the number of whole
empty/unused octets to fill out the data time slot. The value is constrained
by math to 0 for <= 5.5Mb, 0-1 for 11Mb, and 0-2 for 22Mb. It is used to
signal to the MAC that there is residue.


# 1.24 26-Dec-2004 dyoung

Make rtw(4) build w/o RTW_DEBUG. Thanks to Charles Hannum for
pointing out my oversight.


# 1.23 25-Dec-2004 dyoung

The rx descriptor ring bug happens quite often, so printf'ing
occurrences is annoying. Only printf about it when rtw_debug
contains RTW_DEBUG_BUG.


# 1.22 25-Dec-2004 dyoung

IMPORTANT: set m->m_pkthdr.rcvif on rx'd packets. Illegal memory
references abound without this fix.

In rtw_intr_rx, skip to the next rx packet earlier if the rx packet
length is too short.

Also in rtw_intr_rx, if a packet is rx'd with unknown rate, printf
a warning, drop the packet, recycle the rx buffer, skip to next rx
packet.


# 1.21 25-Dec-2004 dyoung

Change rtw_debug from a debug level to a debug mask. Add a lot of
debug flags.

From Linux: handle an RTL8180 bug. Sometimes the NIC skips from
the middle of the ring to the 0th rx descriptor. Now the driver
resynchronizes.

Handle a receive descriptor underrun or Rx FIFO overflow condition
in the way that the Linux driver does. This kind of seems like
overkill, but whatever.

Protect rtw_ioctl with splnet().

Do not load a tx descriptor with a buffer shorter than 4 bytes.

Handle a transmit timeout less disruptively.


# 1.20 23-Dec-2004 dyoung

Oops, straggler from last commit: set the 802.11 Duration field
with the result from ieee80211_compute_duration.


# 1.19 23-Dec-2004 dyoung

Fix a bug in ieee80211_compute_duration: the 802.11 Duration field
in an 802.11 unicast data packet is equal to the duration of the
SIFS and Acknowledgement. That is, the amount of time reserved
*after* the packet has finished transmitting.

Change the arguments to ieee80211_compute_duration: pass the entire
packet length, not just the payload length. Add a 'debug' argument
to ieee80211_compute_duration and its helper subroutine,
ieee80211_compute_duration1.

If debug != 0, ieee80211_compute_duration printfs its arguments
and several local variables.

In rtw(4), load the 802.11 Duration field with the result from
ieee80211_compute_duration.


# 1.18 23-Dec-2004 dyoung

Bug fix: in rtw_rxbuf_alloc, unload the previous mbuf chain before
loading the new chain.


# 1.17 23-Dec-2004 dyoung

DMA-synchronize the Rx buffers before re-initializing them.
XXX not necessary?


# 1.16 23-Dec-2004 dyoung

Add more comprehensive debug messages as we setup transmit descriptors.
Also, dump packets if IFF_DEBUG|IFF_LINK2. Factor out a subroutine
for printing transmit-descriptor debug messages.


# 1.15 23-Dec-2004 dyoung

Disable interrupts and stop transmit DMA before disabling the
transmitter and receiver.


# 1.14 23-Dec-2004 dyoung

Shorten variables, s/txctl/ctl/. This is rtw_start, after all:
transmission is implied.


# 1.13 23-Dec-2004 dyoung

Do not indicate to the NIC that the host has appended the CRC32 to
Tx frames.


# 1.12 23-Dec-2004 dyoung

When we set up the supported rates table, mark 1Mb/s, 2Mb/s as
basic rates.


# 1.11 23-Dec-2004 dyoung

Extract the transmission status from a tx descriptor, and convert
to host byte-order, once.


# 1.10 20-Dec-2004 dyoung

Realtek sample sources are not consistent about the "Digital PHY"
bit in the SROM. It seems as if it is set to 1 when the PHY is
*analog*, not *digital*. Fix my sources.

In rtw_intr_rx, use units of 500kb/s instead of 100kb/s for rate,
to be consistent with net80211's expectations. Polish up some
debugging ugly messages. Dump raw 802.11 packets if IFF_DEBUG|IFF_LINK2
and RTW_DEBUG is defined.

Polish power-state (on/sleep/off) handling. Especially improve
support for RFMD (totally untested) and Maxim. For Philips, take
the Digital PHY property into account.

Call the net80211 watchdog function from rtw_watchdog, so that we
scan again if auth/assoc fails.

Be a little more cautious about writing register[RTW_TPPOLL], since
other drivers are.... Don't frob the high/low-priority queues
right now, since I don't use them.

Add rtw_join_bss which programs the card with the BSSID and other
properties of a BSS. Use it on state transitions. Factor out
rtw_set_nettype.

Make rtw_recv_beacon call ieee80211_recv_mgmt instead of dropping
beacons on the floor! TBD IBSS merges.

Change some rtw_debug=2 printfs to rtw_debug=3 (RTW_DPRINTF3)
printfs so the console doesn't get spammed so badly at rtw_debug=2.
Change some debugging printfs to RTW_DPRINTFs. E.g., print the
"RF programming method" only if debugging is enabled.


# 1.9 20-Dec-2004 dyoung

Fix bug in last commit: use &sc->sc_regs, regs is not defined.


# 1.8 20-Dec-2004 dyoung

Add some bus barriers. Remark where they are needed, e.g.,
read_eeprom.

Change some printfs to RTW_DPRINTF2s to quiet rtw(4) when debugging
is disabled.


# 1.7 20-Dec-2004 dyoung

Get rid of the silly char (*dvname)[IFNAMSIZ] pattern. Replace it
with const char *dvname. I'm not sure what I was thinking.


# 1.6 20-Dec-2004 dyoung

Assert that I'm DMA-syncing a non-negative number of transmit
descriptors.

As I free dirty transmit buffers, move them to the free list, not
back to the dirty list!

Add a 5-second transmit timeout.


# 1.5 19-Dec-2004 dyoung

Add the transmit section of rtw(4): build up and tear down transmit
descriptor rings, move packets from the transmit queues to the
transmit rings, handle transmission-completed interrupts. My
Linksys WPC11 ver. 4 with Maxim RF, generates interrupts like it
is successfully transmitting packets. Clearly there are bugs: my
G4 Powerbook locks up hard. I will debug tomorrow.


# 1.4 13-Dec-2004 dyoung

At last, I have rtw w/ Philips RF receiving packets.

I added some sysctls to aid debugging:

* hw.rtw.debug -- enable debugging

* hw.rtw.flush_rfio -- Linux voodoo: possibly makes the MAC
"flush" bits down the serial bus to the RF

* hw.rtw.host_rfio: force the host to bang bits to the RF, instead
of the MAC banging bits

* hw.rtw.rfio_delay: after telling the MAC to bang bits to the
RF front-end, delay rfio_delay microseconds.

* hw.rtw.rfprog_fallback: there is this notion of the "RF
programming method." I believe the choice influences the
polarity/timing of the serial bus used to program the RF
front-end. I know the correct choice for Intersil/RFMD/Philips
front-ends, only. For all other front-ends, I "fallback" to
rfprog_fallback.

Make rtw_txdac_enable take an rtw_softc argument. I will probably
revert this change.

Add some Linux voodoo to rtw_continuous_tx_enable. I will probably
revert this change.

Important: add rtw_set_rfprog, which sets the correct RF programming
method. This change and the following change are probably responsible
for making the Philips RF work.

Important: RTW_CONFIG1 is an 8-bit register, treat it that way!

Important: RTW_BRSR is 16-bit, RTW_CRCOUNT, RTW_PHYDELAY, and
RTW_MSR are 8-bit: treat them that way!

Vastly simplify rtw_resume_ticks.

Note to self: set the LED state to match the power state.

Hedge against the possibility that RTW_MSR is protected as
RTW_CONFIG[0123] are, meanwhile reworking that section of rtw_init
a little.

Add sc_anaparm, which isn't used, yet....


# 1.3 12-Dec-2004 dyoung

Miscellaneous changes. Details below. Important changes flagged
with []. Using the driver with my Linksys WPC11 ver. 4, it seems
to be receiving packets for a change. The WPC11 ver. 4 has a Maxim
RF section. My no-name rtw with Philips RF section still does not
receive any packets.

Keep access-level (analog params > config[0123] registers > none)
in sc_access. Add rtw_set_access for changing the access level.

Make rtw_continuous_tx_enable and other subroutines use rtw_set_access
instead of rtw_config0123_enable and rtw_anaparm_enable.

Factor part of the chip-reset code into rtw_chip_reset1.

Change the 'struct foo (*bar)[N]'-style arguments to
'struct foo *bar'-style arguments.

Consolidate software/hardware Tx/Rx ring setup in rtw_hwring_setup,
rtw_swring_setup.

Add a new constant, SA2400_OPMODE_DEFAULTS, for the bits that we
*always* set in the SA2400 OPMODE register.

Factor some code out into rtw_sa2400_calibrate. (Inspired by the
Linux driver.)

[] When the receiver goes into underrun/overflow state, call a new
subroutine, rtw_kick() that stops the Rx/Tx processes, resets
the chip, reinitializes the Tx/Rx rings, and restarts Rx/Tx
processes. (Inspired by the Linux driver.)

[] In rtw_intr_rx, check for too-short packets before calling
ieee80211_find_rxnode. I believe this will prevent a repeat of
the MCHK exception I saw once on macppc.

[] Use seconds-elapased as well as microseconds-elapsed to set the
next "due date" for the timeout interrupt. This keeps the driver
from programming the timeout to expire too early.

[] In rtw_intr, read RTW_ISR at most 10 times, then get out. If
the interface is not enabled (RTW_F_ENABLED), then get out.

[] In rtw_stop, get out if the interface is not enabled (RTW_F_ENABLED).
Block IPL_NET interrupts. Don't read/write any registers if
the interface is invalid (RTW_F_INVALID).

[] Call rtw_stop in rtw_detach.


Revision tags: kent-audio1-base
# 1.2 30-Oct-2004 thorpej

When adding/deleting multicast addresses, only whack the address
filter if the interface is marked RUNNING.

Fixes kern/27678.


# 1.1 26-Sep-2004 dyoung

branches: 1.1.2;
Add work-in-progress driver rtw(4) for Realtek RTL8180 MAC/baseband.

Add register definitions for Maxim MAX2820 and Philips SA2400 radio
front-ends.


# 1.132 23-May-2019 msaitoh

Whitespace fix (mainly tabify).


# 1.131 23-May-2019 msaitoh

-No functional change:
- KNF
- u_int*_t -> uint*_t.


Revision tags: isaki-audio2-base
# 1.130 05-Feb-2019 msaitoh

Remove very old IFF_NOTRAILERS flag.


# 1.129 03-Feb-2019 mrg

- add or adjust /* FALLTHROUGH */ where appropriate
- add __unreachable() after functions that can return but won't in
this case, and thus can't be marked __dead easily


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 jdolecek-ncqfixes-base pgoyette-compat-0728 phil-wifi-base
# 1.128 26-Jun-2018 msaitoh

Implement the BPF direction filter (BIOC[GS]DIRECTION). It provides backward
compatibility with BIOC[GS]SEESENT ioctl. The userland interface is the same
as FreeBSD.

This change also fixes a bug that the direction is misunderstand on some
environment by passing the direction to bpf_mtap*() instead of checking
m->m_pkthdr.rcvif.


Revision tags: pgoyette-compat-0625 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base tls-maxphys-base-20171202
# 1.127 23-Oct-2017 msaitoh

branches: 1.127.2;
If if_initialize() failed in the attach function, free resources and return.


Revision tags: matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base
# 1.126 23-May-2017 ozaki-r

branches: 1.126.2;
Apply deferred if_start to more drivers

And annotate some XXX_start as it runs in softint to clarify that
it doesn't need deferred if_start.


Revision tags: prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 nick-nhusb-base-20170204
# 1.125 02-Feb-2017 nonaka

wlan interfaces make interrupt routine running on softint context.

see http://mail-index.netbsd.org/tech-kern/2016/12/06/msg021281.html

tested device:
* ath at pci: AR5212, AR5424
* athn at pci: AR9287
* ipw at pci: 2100BG
* iwi at pci: 2915ABG
* iwm at pci: 3165, 7260, 8260
* iwn at pci: 4945, 6235
* ral at pci: RT2560
* rtwn at pci: RTL8192CE


Revision tags: bouyer-socketcan-base pgoyette-localcount-20170107 nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.124 15-Sep-2016 jdolecek

branches: 1.124.2;
remove last isolated islands using BUS_SPACE_BARRIER_SYNC and
BUS_SPACE_BARRIER_X_BEFORE_X - these were only ever defined for mips and ia64,
and never actually implemented even there


Revision tags: localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907
# 1.123 10-Jun-2016 ozaki-r

branches: 1.123.2;
Introduce m_set_rcvif and m_reset_rcvif

The API is used to set (or reset) a received interface of a mbuf.
They are counterpart of m_get_rcvif, which will come in another
commit, hide internal of rcvif operation, and reduce the diff of
the upcoming change.

No functional change.


Revision tags: nick-nhusb-base-20160529
# 1.122 16-May-2016 ozaki-r

Use M_GETCTX and M_SETCTX instead of open-coding rcvif

No functional change.


Revision tags: netbsd-7-2-RELEASE netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 netbsd-7-0-RELEASE nick-nhusb-base-20150921 netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 nick-nhusb-base-20150606 nick-nhusb-base-20150406 nick-nhusb-base netbsd-7-base yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 rmind-smpnet-nbase rmind-smpnet-base tls-maxphys-base
# 1.121 25-Feb-2014 pooka

branches: 1.121.6;
Ensure that the top level sysctl nodes (kern, vfs, net, ...) exist before
the sysctl link sets are processed, and remove redundancy.

Shaves >13kB off of an amd64 GENERIC, not to mention >1k duplicate
lines of code.


# 1.120 17-Oct-2013 christos

- remove unused variables
- move variables inside ifdef sections
- ifdef notdef unused code
- use __USE for debugging variables


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE yamt-pagecache-tag8 netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 agc-symver-base netbsd-6-1-RC2 netbsd-6-1-RC1 yamt-pagecache-base8 netbsd-6-0-1-RELEASE yamt-pagecache-base7 matt-nb6-plus-nbase yamt-pagecache-base6 netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base10 yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.119 04-Jul-2011 joerg

branches: 1.119.2; 1.119.12; 1.119.16;
Fix memset usage.


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base matt-mips64-premerge-20101231 rmind-uvmplock-base
# 1.118 15-Nov-2010 uebayasi

Socket ioctl definitions need sys/sockio.h.


# 1.117 13-Nov-2010 uebayasi

Don't pull in the whole uvm(9) API to access only PAGE_SIZE and
some other constants. These are provided by sys/param.h now.


Revision tags: uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10 uebayasi-xip-base1
# 1.116 05-Apr-2010 joerg

Push the bpf_ops usage back into bpf.h. Push the common ifp->if_bpf
check into the inline functions as well the fourth argument for
bpf_attach.


# 1.115 15-Mar-2010 dyoung

Make this compile on sparc64:

1 s/next_tick/next_tint/ because next_tick shadows a global on sparc64.

2 Fix the bus-barrier helper routines, which had the tag & handle
swapped (!!). Move the helpers from rtwreg.h to rtwvar.h, and
change RTW_BARRIER() into an inline subroutine called rtw_barrier().


Revision tags: yamt-nfs-mp-base9
# 1.114 24-Feb-2010 dyoung

branches: 1.114.2;
A pointer typedef entails trading too much flexibility to declare const
and non-const types, and the kernel uses both const and non-const
PMF qualifiers and device suspensors, so change the pmf_qual_t and
device_suspensor_t typedefs from "pointers to const" to non-pointer,
non-const types.


Revision tags: uebayasi-xip-base
# 1.113 31-Jan-2010 dyoung

branches: 1.113.2;
Add the missing newline to a verbose autoconf message.


# 1.112 19-Jan-2010 pooka

Redefine bpf linkage through an always present op vector, i.e.
#if NBPFILTER is no longer required in the client. This change
doesn't yet add support for loading bpf as a module, since drivers
can register before bpf is attached. However, callers of bpf can
now be modularized.

Dynamically loadable bpf could probably be done fairly easily with
coordination from the stub driver and the real driver by registering
attachments in the stub before the real driver is loaded and doing
a handoff. ... and I'm not going to ponder the depths of unload
here.

Tested with i386/MONOLITHIC, modified MONOLITHIC without bpf and rump.


# 1.111 08-Jan-2010 dyoung

Expand PMF_FN_* macros.


Revision tags: matt-premerge-20091211 jym-xensuspend-nbase
# 1.110 19-Oct-2009 rmind

Drop 3rd and 4th clauses from David Young's license.
Reviewed and approved by dyoung@ (copyright holder).


# 1.109 16-Sep-2009 dyoung

In pmf(9), improve the implementation of device self-suspension
and make suspension by self, by drvctl(8), and by ACPI system sleep
play nice together. Start solidifying some temporary API changes.

1. Extract a new header file, <sys/device_if.h>, from <sys/device.h> and
#include it from <sys/pmf.h> instead of <sys/device.h> to break the
circular dependency between <sys/device.h> and <sys/pmf.h>.

2. Introduce pmf_qual_t, an aggregate of qualifications on a PMF
suspend/resume call. Start to replace instances of PMF_FN_PROTO,
PMF_FN_ARGS, et cetera, with a pmf_qual_t.

3. Introduce the notion of a "suspensor," an entity that holds a
device in suspension. More than one suspensor may hold a device
at once. A device stays suspended as long as at least one
suspensor holds it. A device resumes when the last suspensor
releases it.

Currently, the kernel defines three suspensors,

3a the system-suspensor: for system suspension, initiated
by 'sysctl -w machdep.sleep_state=3', by lid closure, by
power-button press, et cetera,

3b the drvctl-suspensor: for device suspension by /dev/drvctl
ioctl, e.g., drvctl -S sip0.

3c the system self-suspensor: for device drivers that suspend
themselves and their children. Several drivers for network
interfaces put the network device to sleep while it is not
administratively up, that is, after the kernel calls if_stop(,
1). The self-suspensor should not be used directly. See
the description of suspensor delegates, below.

A suspensor can have one or more "delegates". A suspensor can
release devices that its delegates hold suspended. Right now,
only the system self-suspensor has delegates. For each device
that a self-suspending driver attaches, it creates the device's
self-suspensor, a delegate of the system self-suspensor.

Suspensors stop a system-wide suspend/resume cycle from waking
devices that the operator put to sleep with drvctl before the cycle.
They also help self-suspension to work more simply, safely, and in
accord with expectations.

4. Add the notion of device activation level, devact_level_t,
and a routine for checking the current activation level,
device_activation(). Current activation levels are DEVACT_LEVEL_BUS,
DEVACT_LEVEL_DRIVER, and DEVACT_LEVEL_CLASS, which respectively
indicate that the device's bus is active, that the bus and device are
active, and that the bus, device, and the functions of the device's
class (network, audio) are active.

Suspend/resume calls can be qualified with a devact_level_t.
The power-management framework treats a devact_level_t that
qualifies a device suspension as the device's current activation
level; it only runs hooks to reduce the activation level from
the presumed current level to the fully suspended state. The
framework treats a devact_level_t qualifying device resumption
as the target activation level; it only runs hooks to raise the
activation level to the target.

5. Use pmf_qual_t, devact_level_t, and self-suspensors in several
drivers.

6. Temporarily add an unused power-management workqueue that I will
remove or replace, soon.


Revision tags: yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5 yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 nick-hppapmap-base3 jym-xensuspend-base nick-hppapmap-base
# 1.108 07-Apr-2009 dyoung

Cosmetic: remove some dead code.


# 1.107 02-Apr-2009 dyoung

Add the WEP capability to our net80211 capability flags, since we do
sort of support hardware WEP. Only change the WEP key index in a Tx
descriptor from 0 if the type of our transmit key is _WEP, not _TKIP:
i.e., only if we're really doing WEP crypto in the hardware.

Ignore a watchdog timeout on any Tx ring if we can collect some packets
from that ring. Restart both the receiver and the transmitter when a
watchdog timeout occurs instead of restarting only the transmitter.


Revision tags: nick-hppapmap-base2 haad-dm-base2 haad-nbase2 ad-audiomp2-base haad-dm-base mjf-devfs2-base
# 1.106 12-Nov-2008 ad

branches: 1.106.4;
Remove LKMs and switch to the module framework, pass 1.

Proposed on tech-kern@.


# 1.105 07-Nov-2008 dyoung

*** Summary ***

When a link-layer address changes (e.g., ifconfig ex0 link
02:de:ad:be:ef:02 active), send a gratuitous ARP and/or a Neighbor
Advertisement to update the network-/link-layer address bindings
on our LAN peers.

Refuse a change of ethernet address to the address 00:00:00:00:00:00
or to any multicast/broadcast address. (Thanks matt@.)

Reorder ifnet ioctl operations so that driver ioctls may inherit
the functions of their "class"---ether_ioctl(), fddi_ioctl(), et
cetera---and the class ioctls may inherit from the generic ioctl,
ifioctl_common(), but both driver- and class-ioctls may override
the generic behavior. Make network drivers share more code.

Distinguish a "factory" link-layer address from others for the
purposes of both protecting that address from deletion and computing
EUI64.

Return consistent, appropriate error codes from network drivers.

Improve readability. KNF.

*** Details ***

In if_attach(), always initialize the interface ioctl routine,
ifnet->if_ioctl, if the driver has not already initialized it.
Delete if_ioctl == NULL tests everywhere else, because it cannot
happen.

In the ioctl routines of network interfaces, inherit common ioctl
behaviors by calling either ifioctl_common() or whichever ioctl
routine is appropriate for the class of interface---e.g., ether_ioctl()
for ethernets.

Stop (ab)using SIOCSIFADDR and start to use SIOCINITIFADDR. In
the user->kernel interface, SIOCSIFADDR's argument was an ifreq,
but on the protocol->ifnet interface, SIOCSIFADDR's argument was
an ifaddr. That was confusing, and it would work against me as I
make it possible for a network interface to overload most ioctls.
On the protocol->ifnet interface, replace SIOCSIFADDR with
SIOCINITIFADDR. In ifioctl(), return EPERM if userland tries to
invoke SIOCINITIFADDR.

In ifioctl(), give the interface the first shot at handling most
interface ioctls, and give the protocol the second shot, instead
of the other way around. Finally, let compatibility code (COMPAT_OSOCK)
take a shot.

Pull device initialization out of switch statements under
SIOCINITIFADDR. For example, pull ..._init() out of any switch
statement that looks like this:

switch (...->sa_family) {
case ...:
..._init();
...
break;
...
default:
..._init();
...
break;
}

Rewrite many if-else clauses that handle all permutations of IFF_UP
and IFF_RUNNING to use a switch statement,

switch (x & (IFF_UP|IFF_RUNNING)) {
case 0:
...
break;
case IFF_RUNNING:
...
break;
case IFF_UP:
...
break;
case IFF_UP|IFF_RUNNING:
...
break;
}

unifdef lots of code containing #ifdef FreeBSD, #ifdef NetBSD, and
#ifdef SIOCSIFMTU, especially in fwip(4) and in ndis(4).

In ipw(4), remove an if_set_sadl() call that is out of place.

In nfe(4), reuse the jumbo MTU logic in ether_ioctl().

Let ethernets register a callback for setting h/w state such as
promiscuous mode and the multicast filter in accord with a change
in the if_flags: ether_set_ifflags_cb() registers a callback that
returns ENETRESET if the caller should reset the ethernet by calling
if_init(), 0 on success, != 0 on failure. Pull common code from
ex(4), gem(4), nfe(4), sip(4), tlp(4), vge(4) into ether_ioctl(),
and register if_flags callbacks for those drivers.

Return ENOTTY instead of EINVAL for inappropriate ioctls. In
zyd(4), use ENXIO instead of ENOTTY to indicate that the device is
not any longer attached.

Add to if_set_sadl() a boolean 'factory' argument that indicates
whether a link-layer address was assigned by the factory or some
other source. In a comment, recommend using the factory address
for generating an EUI64, and update in6_get_hw_ifid() to prefer a
factory address to any other link-layer address.

Add a routing message, RTM_LLINFO_UPD, that tells protocols to
update the binding of network-layer addresses to link-layer addresses.
Implement this message in IPv4 and IPv6 by sending a gratuitous
ARP or a neighbor advertisement, respectively. Generate RTM_LLINFO_UPD
messages on a change of an interface's link-layer address.

In ether_ioctl(), do not let SIOCALIFADDR set a link-layer address
that is broadcast/multicast or equal to 00:00:00:00:00:00.

Make ether_ioctl() call ifioctl_common() to handle ioctls that it
does not understand.

In gif(4), initialize if_softc and use it, instead of assuming that
the gif_softc and ifp overlap.

Let ifioctl_common() handle SIOCGIFADDR.

Sprinkle rtcache_invariants(), which checks on DIAGNOSTIC kernels
that certain invariants on a struct route are satisfied.

In agr(4), rewrite agr_ioctl_filter() to be a bit more explicit
about the ioctls that we do not allow on an agr(4) member interface.

bzero -> memset. Delete unnecessary casts to void *. Use
sockaddr_in_init() and sockaddr_in6_init(). Compare pointers with
NULL instead of "testing truth". Replace some instances of (type
*)0 with NULL. Change some K&R prototypes to ANSI C, and join
lines.


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 wrstuden-revivesa-base-1 simonb-wapbl-nbase yamt-pf42-base4 simonb-wapbl-base yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 yamt-nfs-mp-base2 wrstuden-revivesa-base yamt-nfs-mp-base yamt-pf42-base ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 1.104 15-Mar-2008 dyoung

branches: 1.104.4; 1.104.10; 1.104.12;
Cosmetic: make rtw_hw_keysupp() return a bool instead of int. In
rtw_wep_setkeys(), add a debug printf, and move the initialization
of keylen from the for-loop to the declaration.


# 1.103 14-Mar-2008 dyoung

Extract subroutine rtw_tx_kick() from rtw_start(), and reuse it in
rtw_io_enable() to restart the transmitter after resetting it.


# 1.102 14-Mar-2008 dyoung

Change tests for "impossible" keys to KASSERT()s. Get rid of a
temporary variable. In rtw_key_delete(), do not invalidate the
hardware keys unless a WEP key is deleted.


# 1.101 12-Mar-2008 dyoung

Use device_t and its accessors throughout. Use aprint_*_dev().

Improve PMF-ability.

Add a 'flags' argument to suspend/resume handlers and
callers such as pmf_system_suspend().

Define a flag, PMF_F_SELF, which indicates to PMF that a
device is suspending/resuming itself. Add helper routines,
pmf_device_suspend_self(dev) and pmf_device_resume_self(dev),
that call pmf_device_suspend(dev, PMF_F_SELF) and
pmf_device_resume(dev, PMF_F_SELF), respectively. Use
PMF_F_SELF to suspend/resume self in ath(4), audio(4),
rtw(4), and sip(4).

In ath(4) and in rtw(4), replace the icky sc_enable/sc_disable
callbacks, provided by the bus front-end, with
self-suspension/resumption. Also, clean up the bus
front-ends. Make sure that the interrupt handler is
disestablished during suspension. Get rid of driver-private
flags (e.g., RTW_F_ENABLED, ath_softc->sc_invalid); use
device_is_active()/device_has_power() calls, instead.

In the network-class suspend handler, call if_stop(, 0)
instead of if_stop(, 1), because the latter is superfluous
(bus- and driver-suspension hooks will 'disable' the NIC),
and it may cause recursion.

In the network-class resume handler, prevent infinite
recursion through if_init() by getting out early if we are
self-suspending (PMF_F_SELF).

rtw(4) improvements:

Destroy rtw(4) callouts when we detach it. Make rtw at
pci detachable. Print some more information with the "rx
frame too long" warning.

Remove activate() methods:

Get rid of rtw_activate() and ath_activate(). The device
activate() methods are not good for much these days.

Make ath at cardbus resume with crypto functions intact:

Introduce a boolean device property, "pmf-powerdown". If
pmf-powerdown is present and false, it indicates that a
bus back-end should not remove power from a device.

Honor this property in cardbus_child_suspend().

Set this property to 'false' in ath_attach(), since removing
power from an ath at cardbus seems to lobotomize the WPA
crypto engine. XXX Should the pmf-powerdown property
propagate toward the root of the device tree?

Miscellaneous ath(4) changes:

Warn if ath(4) tries to write crypto keys to suspended
hardware.

Reduce differences between FreeBSD and NetBSD in ath(4)
multicast filter setup.

Make ath_printrxbuf() print an rx descriptor's status &
key index, to help debug crypto errors.

Shorten a staircase in ath_ioctl(). Don't check for
ieee80211_ioctl() return code ERESTART, it never happens.


# 1.100 12-Mar-2008 dyoung

Print the TPPoll register when the Tx DMA engine doesn't shut down
in the time we allow.


# 1.99 03-Mar-2008 tsutsui

Explicitly include <sys/device.h> for device_t.


Revision tags: nick-net80211-sync-base vmlocking2-base3 bouyer-xeni386-nbase bouyer-xeni386-base mjf-devfs-base matt-armv6-base hpcarm-cleanup-base
# 1.98 21-Dec-2007 dyoung

branches: 1.98.2; 1.98.6;
Do not embed a struct device in rtw_softc any longer. Register
both pci and cardbus attachments with CFATTACH_DECL_NEW(). Access
the softc through the device_t using device_private().

While I'm here, change a couple of KASSERT()s about the Rx buffer
length to a warning.


# 1.97 20-Dec-2007 dyoung

Remove shutdown hooks. Use KASSERT().


# 1.96 16-Dec-2007 dyoung

Fix a bug I introduced to rtw_chan2txpower() the other night.

Fix a bug in device detachment: change a break statement to a
/*FALLTHROUGH*/ in rtw_detach().


# 1.95 16-Dec-2007 dyoung

Synchronize device detachment with network interrupts. Use the
pmf network class instead of powerhooks.


Revision tags: yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 bouyer-xenamd64-base2 vmlocking-nbase bouyer-xenamd64-base jmcneill-pm-base reinoud-bufcleanup-base
# 1.94 18-Nov-2007 jnemeth

branches: 1.94.2; 1.94.6;
fix 'm' used unitialized


# 1.93 16-Nov-2007 dyoung

Accommodate the variety of RF front-ends when radiotapping frames:
tap only RSSI when there is a Philips RF front-end. Tap both Barker
lock quality and RSSI when there is any other RF front-end.

Provide radiotap listeners a more complete picture of channel
activity:

in promiscuous mode, tap frames who do not pass the CRC32 check.
Flag packets that were received with a short preamble. Ask
the NIC to pass us 802.11 Control frames. Pass frames to
radiotap listeners before stripping the FCS. Re-order operations
in rtw_intr_rx() in order to accomplish all of this, taking
care not to pass a broken packet to net80211!

Do not provide a flags field when tapping xmitted frames.

Assert sane Rx packet lengths. Really should check and drop instead
of KASSERTing. I will revisit this, soon.

Update copyright.


# 1.92 15-Nov-2007 dyoung

Fix order of operations:

rtw_rxdesc_init: before initializing a Rx descriptor's
control word, synchronize the Rx buffer

rtw_start, be paranoid: set the "NIC owns" bit on a Tx
descriptor dead last. Always reinitialize the "next
Tx descriptor" pointer, just in case it got clobbered
somehow.

Let the compiler decide whether to inline rtw_collect_txring or
not.


Revision tags: jmcneill-base
# 1.91 19-Oct-2007 ad

branches: 1.91.2;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h


Revision tags: yamt-x86pmap-base4 yamt-x86pmap-base3 yamt-x86pmap-base2 vmlocking-base
# 1.90 29-Sep-2007 scw

branches: 1.90.2;
s/NPBFILTER/NBPFILTER/ in some #endif comments. No functional change.


Revision tags: nick-csl-alignment-base5 yamt-x86pmap-base matt-mips64-base nick-csl-alignment-base mjf-ufs-trans-base
# 1.89 09-Jul-2007 ad

branches: 1.89.6; 1.89.8; 1.89.10;
Merge some of the less invasive changes from the vmlocking branch:

- kthread, callout, devsw API changes
- select()/poll() improvements
- miscellaneous MT safety improvements


# 1.88 29-May-2007 dyoung

Fix rtw(4) on NetBSD/macppc: use bus_space_write_region_stream_4()
instead of bus_space_write_region_4() to write WEP Rx keys to the
NIC. Thanks macallan@ for detecting the bug and testing the fix.


# 1.87 29-May-2007 dyoung

Cosmetic: simplify a memset() statement, use __arraycount(), and
remove a gratuitous return statement at the end of a void subroutine.


# 1.86 29-May-2007 dyoung

Simplify multicast filter programming, and take care to avoid
gratuitous device resets when the kernel adds/deletes a multicast
address.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base
# 1.85 04-Mar-2007 christos

branches: 1.85.2; 1.85.4;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.


Revision tags: ad-audiomp-base post-newlock2-merge newlock2-nbase newlock2-base
# 1.84 29-Jan-2007 dyoung

branches: 1.84.2;
In rtw_dequeue(), initialize *mp to NULL before anything else, so
that it is either NULL or a valid mbuf. Previously, it was possible
for rtw_dequeue() to exit with 0 before initializing *mp. rtw_start()
would have used whatever trash was in *mp, which would lead to
problems later on.


# 1.83 06-Jan-2007 dyoung

I have made a small change that suppresses "recovery" from (spurious?)
tx timeouts on the beacon queue. The driver's recovery process
badly disrupts the MAC's receiver. This needs a closer look, later.

Every other fix is by Charles M. Hannum. Charles writes:

"With these, the device is quite stable under load, does not experience
xmit timeouts, no longer mysteriously freezes, and does not spew
a lot of garbage. It does, however, continue to get some "tx fifo
underflow"s.

global, SYSCTL_SETUP():
a) Removed unused sysctl variables.

rtw_io_enable():
b) Change rtw_io_enable to take a softc, and make it call
rtw_txring_fixup().
c) Enable the PCI multiple read/write bit.
d) Always reset rdb_next to 0 when starting the receive engine.

rtw_intr_rx():
e) When processing receive packets, store the next pointer in rdb_next
and read it back on the next round, to fix a race condition vs.
rtw_tune() during AP discovery and association.
f) Remove the special "skip to 0th descriptor" code, because it is no
longer needed.

rtw_collect_txring():
g) In the "force" case, stop when we catch up to the hardware xmit
pointer.

rtw_intr_beacon():
h) Resetting tdb_next here looked fishy to me, in light of changes in
rtw_collect_txring(). XXX However, this is the one part I haven't
tested.

rtw_txring_fixup():
i) Add function and line arguments, so we can print out information
about the caller.
j) In addition to reading the hardware pointer, skip over any
additional packets with OWN set -- we may have queued more.

rtw_rxring_fixup():
k) Remove this, because it's completely wrong.

rtw_intr_ioerror():
l) Don't handle receive overruns here; handle them in the normal receive
path. Also changed RTW_INTR_RX and RTW_INTR_IOERROR accordingly.
m) Do not fiddle with CR; the transmit engine is still running just
fine.
n) Do not fiddle with IMR; it was unnecessary.
o) Don't touch the receive engine at all; not necessary now that we're
leaving CR alone.
p) Remove the rtw_do_chip_reset case; it was dangerous and not actually
used.

rtw_intr():
q) Don't mask off ISR bits when we pass down the ISR value; it's not
necessary, and sometimes the other bits useful in debugging output.

rtw_seg_too_short():
r) Don't spew here; the caller will do it if necessary. (Stops spewage
in an expected case.)

rtw_rxdesc_blk:
s) Minor change to make the elements have the same order as txdesc_blk.

general:
t) Added a bunch of debugging output, #ifdef RTW_DIAG, that was useful
while investigating the ring management problems. Also moved
rtw_txring_fixup() into RTW_DIAG, as I believe the transmit pointer
is always kept in sync now, and the function has potential race
conditions.


# 1.82 06-Jan-2007 dyoung

After we examine a rx/tx descriptor and find that it's still owned
by the NIC, re-sync the descriptor so that a cacheline will not
"cover" the NIC's modifications to the descriptor when we next
examine it.

This compiles, but I have not tested it, yet.


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase wrstuden-fixsa-base-1 netbsd-4-0-RELEASE netbsd-4-0-RC5 matt-nb4-arm-base netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 wrstuden-fixsa-base yamt-splraiseipl-base5 yamt-splraiseipl-base4 yamt-splraiseipl-base3 netbsd-4-base
# 1.81 16-Nov-2006 christos

__unused removal on arguments; approved by core.


# 1.80 13-Nov-2006 dyoung

Stop using typeof() in the bit-twiddling macros, per yamt@'s
suggestion. This change requires that I use the __PRIuBITS format
string in atw and rtw, so do that.


Revision tags: yamt-splraiseipl-base2
# 1.79 12-Oct-2006 xtraeme

Use __unused in function arguments where appropiate.


# 1.78 12-Oct-2006 christos

- sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386


# 1.77 24-Sep-2006 jmcneill

Add "name" parameter to powerhook_establish, to aid debugging. No objections
on tech-kern@


Revision tags: yamt-splraiseipl-base yamt-pdpolicy-base9 yamt-pdpolicy-base8 rpaulo-netinet-merge-pcb-base
# 1.76 03-Sep-2006 christos

branches: 1.76.2; 1.76.4;
- comment out impossible comparisons
- remove superfluous if statement


# 1.75 31-Aug-2006 dyoung

Per discussion on tech-kern and tech-userlevel, move the bit-twiddling
macros, __BIT, __BITS, SHIFTIN, SHIFTOUT, and __arraycount() from
lib/libkern/libkern.h to sys/cdefs.h. Add a __-prefix to SHIFTIN
and SHIFTOUT, and add a manual page for the bit-twiddling macros,
bits(3).

Make the __BIT and __BITS macros "widthless," as best I can, by
changing their type to uintmax_t from uint32_t. XXX The manual
page lags this change by a bit.

Define __PRIxBIT and __PRIxBITS printf(3) format strings.


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base7 yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base simonb-timecounters-base
# 1.74 26-May-2006 blymn

Clean up bogus whitespace


Revision tags: yamt-pdpolicy-base5
# 1.73 14-May-2006 christos

branches: 1.73.2;
XXX: GCC uninitialized


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 elad-kernelauth-base
# 1.72 28-Mar-2006 dyoung

Revamp ieee80211_get_rate. Now it does not use the rateset in the
ic->ic_bss, but it uses the rateset in its new ieee80211_node
argument, instead. If the rate is fixed by ic->ic_fixed_rate, but
the fixed rate is not in the node's rateset, choose a reasonable
default: prefer the lowest basic rate or, if there is no basic
rate, prefer the lowest rate, period.

Change a printf complaint to a debug message.

Adapt drivers to suit new ieee80211_get_rate calling convention.

XXX I really need to replace ieee80211_get_rate with a bitrate
XXX adaptation algorithm. Soon, soon....


# 1.71 27-Mar-2006 dyoung

Set the channel frequency and flags in the radiotap headers in
rtw_tune instead of in rtw_start, rtw_intr_rx.


# 1.70 27-Mar-2006 dyoung

Remove unused argument ifflagsp from rtw_dmamap_load_txbuf.


Revision tags: peter-altq-base yamt-pdpolicy-base2
# 1.69 08-Mar-2006 dyoung

branches: 1.69.2;
Change macro names to avoid collisions:

BIT -> __BIT
BITS -> __BITS


# 1.68 08-Mar-2006 dyoung

Move my bit-twiddling macros to libkern.h from my drivers, where
I had duplicated them. Improve the macros' names. Simplify their
implementation.

A brief description of each macro is below.

BIT(n): Return a bitmask with bit m set, where the least
significant bit is bit 0.

BITS(m, n): Return a bitmask with bits m through n, inclusive,
set. It does not matter whether m>n or m<=n.
The least significant bit is bit 0.

A "bitfield" is a span of consecutive bits defined by a
bitmask, where 1s select the bits in the bitfield. SHIFTIN,
SHIFTOUT, and SHIFTOUT_MASK help read and write bitfields
from device registers.

SHIFTIN(v, mask): Left-shift bits `v' into the bitfield
defined by `mask', and return them. No
side-effects.

SHIFTOUT(v, mask): Extract and return the bitfield selected
by `mask' from `v', right-shifting the
bits so that the rightmost selected bit
is at bit 0. No side-effects.

SHIFTOUT_MASK(mask): Right-shift the bits in `mask' so that
the rightmost non-zero bit is at bit
0. This is useful for finding the
greatest unsigned value that a bitfield
can hold. No side-effects. Note that
SHIFTOUT_MASK(m) = SHIFTOUT(m, m).

Examples:

/*
* Register definitions taken from the RFMD RF3000 manual.
*/
#define RF3000_GAINCTL 0x11 /* TX variable gain control */
#define RF3000_GAINCTL_TXVGC_MASK BITS(7, 2)
#define RF3000_GAINCTL_SCRAMBLER BIT(1)

/*
* Shift the transmit power into the transmit-power field of the
* gain-control register and write it to the baseband processor.
*/
atw_rf3000_write(sc, RF3000_GAINCTL,
SHIFTIN(txpower, RF3000_GAINCTL_TXVGC_MASK));


/*
* Register definitions taken from the ADMtek ADM8211 manual.
*
*/
#define ATW_RXSTAT_OWN BIT(31) /* 1: NIC may fill descriptor */
/* ... */
#define ATW_RXSTAT_DA1 BIT(17) /* DA bit 1, admin'd address */
#define ATW_RXSTAT_DA0 BIT(16) /* DA bit 0, group address */
#define ATW_RXSTAT_RXDR_MASK BITS(15,12) /* RX data rate */
#define ATW_RXSTAT_FL_MASK BITS(11,0) /* RX frame length, last
* descriptor only
*/

/* Extract the frame length from the Rx descriptor's
* status field.
*/
len = SHIFTOUT(rxstat, ATW_RXSTAT_FL_MASK);


Revision tags: yamt-pdpolicy-base yamt-uio_vmspace-base5
# 1.67 20-Feb-2006 thorpej

branches: 1.67.2; 1.67.4;
Use device_is_active() rather than testing dv_flags for DVF_ACTIVE
directly.


# 1.66 19-Feb-2006 dyoung

When rtw_enable is called, power may have been removed and re-applied,
so invalidate the WEP key registers to force us to write the keys
back to the hardware.

Revamp key handling: use the hardware WEP engine for 40-bit and
104-bit keys, only; use software WEP for all other key lengths.
Set the hardware key length to the length of the default Tx key,
or if there is no default Tx key, use the length of the longest
WEP key.


# 1.65 04-Feb-2006 dyoung

In rtw_{rx,tx}ring_fixup, do not set the tx/rx ring index to
something out of bounds if we read an invalid pointer form the
hardware. Prevents a panic when an rtw@cardbus is ejected.


# 1.64 29-Dec-2005 dyoung

branches: 1.64.2; 1.64.4; 1.64.6;
Add support for the GCT Semiconductor GRF5101 transceiver/synthesizer.
From OpenBSD.

GCT will not provide any documentation, so there are many magic
numbers in this code.


# 1.63 29-Dec-2005 dyoung

Update rtw(4) for the new IBSS merge idiom, where ieee80211_ibss_merge()
does not return ENETRESET if the driver should change its BSSID,
but it makes a RUN->RUN transition, instead.


# 1.62 29-Dec-2005 dyoung

In atw(4), use ieee80211_compute_duration() to compute IEEE 802.11
Duration and PLCP Length fields, and delete the abominable
atw_frame_setdurs() subroutine.

Make rtw(4) use the new ieee80211_compute_duration() calling
convention.

Add an ieee80211_key argument to ieee80211_compute_duration() and
lightly constify arguments. Get the crypto header length from the
key argument instead of blithely assuming a WEP header. Add some
inline documentation. Account for data padding (IEEE80211_F_DATAPAD).


# 1.61 24-Dec-2005 perry

Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.


# 1.60 13-Dec-2005 dyoung

Fix comments and debug printfs: Tx FIFOs underflow, they don't
overflow.


# 1.59 13-Dec-2005 dyoung

On a transmit FIFO overflow (err, actually an underflow...) reset
both the transmit & receive sections of the MAC.


Revision tags: yamt-readahead-base3 ktrace-lwp-base
# 1.58 23-Nov-2005 dyoung

Miscellaneous Realtek RTL8180L driver improvements:

1 Added new sysctl controls for debugging.

2 Improve detection & support for hardware WEP.

3 Revamp handling of transmit descriptor rings.

4 Reliably IFF_OACTIVE when transmit descriptors are available, to
stop the transmit section of the driver from freezing up.

5 Fix beacon transmission in adhoc and hostap modes. XXX There is
a wart in hostap mode, where beacons are transmitted at 1/2 the
correct rate. Load beacon descriptors when the RTW_INTR_BINT
interrupt arrives; schedule RTW_INTR_BINT 1ms ahead of the target
beacon time.

6 Recover more gracefully from tx/rx errors: avoid
transmitter/receiver/chip resets. Try to re-synchronize software
state with hardware state---e.g., load next descriptor pointer
from hardware.

7 Activate the transmit watchdog timer for beacons as well as other
packets.

8 Introduce rtw_idle() that waits for transmit DMA to finish; call
it before resetting the transmitter.


Revision tags: yamt-readahead-base2
# 1.57 18-Nov-2005 skrll

Adapt drivers to the new net80211(9).

Most of this is from dyoung@. Thanks!


Revision tags: yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base
# 1.56 22-Sep-2005 gdt

branches: 1.56.6;
Make arg of IFQ_SET_READY be &ifp->if_snd, to match all other drivers
and be compilable with altq enabled. Reviewed by dyoung@


# 1.55 07-Sep-2005 dogcow

With the assistance of dyoung, fix the following problems:
* some 8180L cards need a longer time for the srom to initialize; patch
suggested via OpenBSD.
* some cards give '0' for USA, some give '3'; for the meantime, accept both
as being USA locale cards.
* this is RTW, not ATW. :)


# 1.54 06-Sep-2005 dogcow

make rtw.c compile again after the 22-jun-05 net80211 import


# 1.53 11-Jul-2005 dyoung

Add undefined variable 'ic' to rtw_attach.


# 1.52 06-Jul-2005 dyoung

Historically, an(4), ath(4), atw(4), rtw(4), and wi(4) have printed
out their modes and rates at boot. Revert to the historical
behavior.


# 1.51 06-Jul-2005 dyoung

Avoid an unnecessary API difference between NetBSD and FreeBSD:
back out my change to ieee80211_crypto_encap that made it free its
mbuf argument on error. I had thought it was a bug. It was not.
It's the drivers that are broken. Make an(4), atw(4), ipw(4),
iwi(4), ral(4), rtw(4), ural(4), and wi(4) free the mbuf when
ieee80211_crypto_encap returns NULL. Also, return ath(4) to the
way it was---i.e., free the mbuf.

Thanks to Sam Leffler to pointing out my mistake.


# 1.50 28-Jun-2005 dyoung

branches: 1.50.2;
Here is a grotty hack that lets the RTL8180L handle WEP in the
receive direction, while software handles WEP in the transmit
direction. When net80211 calls rtw's rtw_key_set with a WEP key,
I point the key's wk_cipher at our "fake" cipher, rtw_cipher_wep,
which is alike to ieee80211_cipher_wep except it provides a different
crypto-decapsulation routine, rtw_wep_decap. rtw_wep_decap copies
the key passed to it by net80211, clears the key's SWCRYPT flag,
and then calls wep_decap. Now wep_decap will decapsulate, but it
will *not* re-decrypt.

XXX I need to check whether the hardware supports 40-bit WEP,
XXX 104-bit WEP, or both, and act accordingly.


# 1.49 27-Jun-2005 dyoung

rtw: Try to get hardware WEP to work. It seems to work in
the RX direction, but not in the TX direction. The
net80211 crypto framework doesn't seem to cope very well
with the assymetry (I'm probably missing something), so
I will use software WEP for now.

net80211: In ieee80211_compute_duration, figure out whether to add
the WEP header to the packet overhead by checking the
WEP bit in the Frame Control field of the 802.11 header,
instead of checking the IEEE80211_F_PRIVACY flag.

Also, if the WEP bit is present, assume that the frame
described by (wh, len) has already already been WEP
encapsulated, and adjust the payload length accordingly.
XXX that's a grotty hack that I will have to revisit,
later.


# 1.48 22-Jun-2005 dyoung

Resolve conflicts in importation of 18-May-2005 ath(4) / net80211(9)
from FreeBSD. Introduce compatibility shims (sys/dev/ic/ath_netbsd.[ch],
sys/net80211/ieee80211_netbsd.[ch]). Update drivers (an, atu, atw,
awi, ipw, iwi, rtw, wi) for the new net80211(9) API.


# 1.47 20-Jun-2005 atatat

Change the rest of the sysctl subsystem to use const consistently.
The __UNCONST macro is now used only where necessary and the RW macros
are gone. Most of the changes here are consumers of the
sysctl_createv(9) interface that now takes a pair of const pointers
which used not to be.


# 1.46 10-Jun-2005 dyoung

Sprinkle __UNCONST() and rename variables to quiet uiet -Wcast-qual,
-Wshadow complaints.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 yamt-km-base4 yamt-km-base3 netbsd-3-base kent-audio2-base
# 1.45 02-Mar-2005 dyoung

Misc. changes to improve ad hoc mode and to enable hostap mode:

Fix the work-around for the NIC bug where it skips to rx
descriptor 0. The driver used to skip to rx descriptor 1.
Hopefully this stops the out-of-order packet reception that
Charles Hannum saw.
When debugging is enabled, print rx-descriptor status flags
before printing the rx bit rate.

Add a debug message for when a beacon tx buffer reclamation.

Reset IFF_OACTIVE when we reset the transmitter.

Pass the consolidated LED state, a struct rtw_led_state,
to rtw_led_attach.

Choose the bit-rate for management frames (1Mb/s) at the
same place we choose for all other frames.

Do not use the NIC's short preamble or RTS options for
management frames. Label beacons for the NIC.

Following a Linux driver, take care not to zero arbitrary
bits in the TPPOLL register.

Use the new idiom for IBSS merges: disable transmitter,
kick the state machine.
Add a second descriptor to the beacon ring. The NIC seems
to like this much better.


# 1.44 27-Feb-2005 perry

nuke trailing whitespace


Revision tags: yamt-km-base2
# 1.43 31-Jan-2005 thorpej

Eliminate use of M_HASFCS.


Revision tags: yamt-km-base
# 1.42 16-Jan-2005 dyoung

branches: 1.42.2; 1.42.4;
Move the register access mode into struct rtw_regs. Change
rtw_set_access, rtw_set_access1 to match.

Add a subroutine for setting WEP keys. WEP isn't quite finished,
because I have to add the WEP header to Tx packets. Implement the
SIOCS80211NWKEY ioctl for setting WEP keys.

Program the LEDs based on operating state and packet activity.

* On a Revision F RTL8180, blink LED1 at 1Hz to indicate
scan/authenticate/associate states. In the run state, turn LED1
on. In every state, blink LED1 at 5Hz to indicate non-beacon
tx/rx activity. I would like to use two LEDs, but in all my
Rev. F instances, LED0 is not wired to an LED; instead, the
first LED is wired to indicate that the card's power is on.

* On a Revision D RTL8180, program the LEDs so that LED0 indicates
Tx, and LED1 indicates Rx. The Rx LED will blink annoyingly if
there are beacons in the air, but at least the Tx LED is useful.

* Store the hardware revision in the softc to support my futile
attempt at programming LEDs for both Rev. D and Rev. F parts;
I never did get Rev. D LEDs to work right.

* Add a debug flag RTW_DEBUG_LED for the LED transitions.

Add RTW_TPPOLL_ALL, RTW_TPPOLL_SALL to start and stop, respectively,
all of the transmit rings.

In ad hoc mode, allocate a beacon and load it into the beacon ring.
Start the ring. In one trial, the card re-transmitted the beacon
ring's contents several times before stopping. More programming
and testing for ad hoc mode is necessary. I'm not setting the
beacon flag in the transmit descriptor.

Revamp the transmit section to make better use of all the transmit
rings: beacon queue, high-, low-, and medium-priority rings. Put
beacon frames on the beacon ring. All other management frames,
and data frames, go on the medium-priority ring. Power-save data
frames go on the high-priority ring. (Note that powersaving is
not implemented!) This is a work in progress.

Send all 802.11 Management frames at 1Mbps.

After we put a packet on a transmit ring, tickle the right bit in
the TPPOLL to tell RTL8180. Stop all rings on error and in rtw_stop.

Use the RF chip type, not the RTL8180 revision, to choose between
host- and MAC-controlled RF serial I/O. Now the Netgear MA521
works.

Remove bogus definition of bit RTW_TPPOLL_FSWINT.


Revision tags: kent-audio1-beforemerge
# 1.41 04-Jan-2005 dyoung

Set initial conditions to guarantee that when read_seeprom toggles
Chip Select, it turns *on* rather than *off*.


# 1.40 04-Jan-2005 dyoung

Add the logic for IBSS merges.


# 1.39 03-Jan-2005 dyoung

sys/dev/ic/rtw.c:

Cosmetic: remove two short ladders from rtw_init. Fit the
NIC registers print-out onto one line using the RTW_PRINT_REGS
macro.

sys/dev/ic/rtwvar.h:

Add RTW_PRINT_REGS wrapper macro for rtw_print_regs. It
is a null op unless defined(RTW_DEBUG).


# 1.38 03-Jan-2005 dyoung

In sys/dev/ic/rtw.c:

Use clue from rtk(4) and re(4) to fix the rtw(4) packet
filter. Previously, I was using the wrong CRC32 function
to hash multicast addresses; to compensate, I set the
multicast filter to all 1s. Now that I hash the addresses
correctly, I do not any longer set the filter to all 1s.

In rtw_ioctl, avoid gratuitous re-initialization when the
interface flags change. If a !IFF_UP -> IFF_UP transition,
call rtw_init(); otherwise, only reload the packet filter.

In sys/dev/ic/rtwreg.h:

Put useful combinations of Receiver Control Register flags
in RTW_RCR_PKTFILT_MASK, RTW_RCR_MONITOR, and
RTW_RCR_PKTFILT_DEFAULT. (XXX RTW_RCR_MONITOR should be
called RTW_RCR_PKTFILT_MONITOR.)


# 1.37 02-Jan-2005 dyoung

Cosmetic: change u_int{8,16,32,64}_t to C99-style uint{8,16,32,64}_t,
which is preferred.


# 1.36 29-Dec-2004 dyoung

In rtw_detach, flag the rtw as "invalid" (RTW_F_INVALID). Do not
try to power-down the RF section of an invalid rtw.

The radiotap signal quality field is 16, not 8, bits wide. Convert
the byte order.


# 1.35 29-Dec-2004 dyoung

Remove some dead code.


# 1.34 29-Dec-2004 dyoung

I like the tlp/atw-style names for software descriptors, txsoft,
better than txctl. Change from rtw_txctl/rtw_rxctl to
rtw_txsoft/rtw_rxsoft. Change the descriptor blocks' names to
match: rtw_txctl_blk becomes rtw_txsoft_blk. Change the member-name
prefixes for both software and hardware descriptors.


# 1.33 29-Dec-2004 dyoung

Consolidate variables related to the rx ring in sc_rxdesc_blk,
which is a struct rtw_rxdesc_blk.

Put a copy of the DMA tag and the DMA map into the rx- and tx-ring
blocks so that I don't have to pass them to subroutines all of the
time.


# 1.32 28-Dec-2004 dyoung

Add bpf(4) packet taps to rtw(4). Now you can tap DLT_EN10MB
(Ethernet II), DLT_IEEE802_11 (802.11), and DLT_IEEE802_11_RADIO
(radiotap + 802.11).


# 1.31 28-Dec-2004 dyoung

If defined(RTW_DEBUG), provide a sysctl (hw.rtw.rxbufs_limit) for
limiting the number of rx buffers an rtw may allocate. Use this
sysctl to test the code that copes with buffer exhaustion.

Allocate at most RTW_RXQLEN rx buffers, stopping at the sysctl
limit. Record in sc_nrxdesc how many were allocated, and put the
end-of-ring indication on sc_rxdesc[sc_nrxdesc - 1]. In rtw_init,
if no rx buffers could be allocated, log a complaint, clear
IFF_RUNNING, and exit with an error.

Many changes to accomodate a short rx ring, mainly of the "add a
rx-ring length argument" variety. XXX I really should consolidate
all of the rx ring variables in one struct and pass that to the
rx-ring subroutines.

Bug fix: after calling MCLGET, use the (m->m_flags & M_EXT) idiom
to check for success, instead of m != NULL.

Bug fix: at the top of rtw_start, if IFF_RUNNING is not set, or
IFF_OACTIVE is, get out.


# 1.30 27-Dec-2004 dyoung

Use a table to convert the hardware's bit rates (0, 1, 2, 3) to
net80211 bit rates (2, 4, 11, 22).

Count input errors (if_ierrors++) for "DMA error/FIFO overflow"
and unknown bit rate.


# 1.29 27-Dec-2004 dyoung

Simplify the reset we do on a transmit timeout. Really, this could
be as simple as rtw_stop(, 0), rtw_init().


# 1.28 27-Dec-2004 mycroft

Use the last descriptor to count collisions and failed transmissions, too.


# 1.27 27-Dec-2004 mycroft

When checking if a split packet is completed, check the *last* segment, not
the first. Otherwise we can overwrite parts of the TX ring that we shouldn't.

Kluge the basic rate setting for now.

Minor simplification to the dequeueing logic.


# 1.26 27-Dec-2004 dyoung

Remove useless debug sysctls.

For AP scanning, change the channel dwell time from 1 second to
1/5 second.


# 1.25 27-Dec-2004 mycroft

Replace d_plcp_svc with d_residue. The latter is the number of whole
empty/unused octets to fill out the data time slot. The value is constrained
by math to 0 for <= 5.5Mb, 0-1 for 11Mb, and 0-2 for 22Mb. It is used to
signal to the MAC that there is residue.


# 1.24 26-Dec-2004 dyoung

Make rtw(4) build w/o RTW_DEBUG. Thanks to Charles Hannum for
pointing out my oversight.


# 1.23 25-Dec-2004 dyoung

The rx descriptor ring bug happens quite often, so printf'ing
occurrences is annoying. Only printf about it when rtw_debug
contains RTW_DEBUG_BUG.


# 1.22 25-Dec-2004 dyoung

IMPORTANT: set m->m_pkthdr.rcvif on rx'd packets. Illegal memory
references abound without this fix.

In rtw_intr_rx, skip to the next rx packet earlier if the rx packet
length is too short.

Also in rtw_intr_rx, if a packet is rx'd with unknown rate, printf
a warning, drop the packet, recycle the rx buffer, skip to next rx
packet.


# 1.21 25-Dec-2004 dyoung

Change rtw_debug from a debug level to a debug mask. Add a lot of
debug flags.

From Linux: handle an RTL8180 bug. Sometimes the NIC skips from
the middle of the ring to the 0th rx descriptor. Now the driver
resynchronizes.

Handle a receive descriptor underrun or Rx FIFO overflow condition
in the way that the Linux driver does. This kind of seems like
overkill, but whatever.

Protect rtw_ioctl with splnet().

Do not load a tx descriptor with a buffer shorter than 4 bytes.

Handle a transmit timeout less disruptively.


# 1.20 23-Dec-2004 dyoung

Oops, straggler from last commit: set the 802.11 Duration field
with the result from ieee80211_compute_duration.


# 1.19 23-Dec-2004 dyoung

Fix a bug in ieee80211_compute_duration: the 802.11 Duration field
in an 802.11 unicast data packet is equal to the duration of the
SIFS and Acknowledgement. That is, the amount of time reserved
*after* the packet has finished transmitting.

Change the arguments to ieee80211_compute_duration: pass the entire
packet length, not just the payload length. Add a 'debug' argument
to ieee80211_compute_duration and its helper subroutine,
ieee80211_compute_duration1.

If debug != 0, ieee80211_compute_duration printfs its arguments
and several local variables.

In rtw(4), load the 802.11 Duration field with the result from
ieee80211_compute_duration.


# 1.18 23-Dec-2004 dyoung

Bug fix: in rtw_rxbuf_alloc, unload the previous mbuf chain before
loading the new chain.


# 1.17 23-Dec-2004 dyoung

DMA-synchronize the Rx buffers before re-initializing them.
XXX not necessary?


# 1.16 23-Dec-2004 dyoung

Add more comprehensive debug messages as we setup transmit descriptors.
Also, dump packets if IFF_DEBUG|IFF_LINK2. Factor out a subroutine
for printing transmit-descriptor debug messages.


# 1.15 23-Dec-2004 dyoung

Disable interrupts and stop transmit DMA before disabling the
transmitter and receiver.


# 1.14 23-Dec-2004 dyoung

Shorten variables, s/txctl/ctl/. This is rtw_start, after all:
transmission is implied.


# 1.13 23-Dec-2004 dyoung

Do not indicate to the NIC that the host has appended the CRC32 to
Tx frames.


# 1.12 23-Dec-2004 dyoung

When we set up the supported rates table, mark 1Mb/s, 2Mb/s as
basic rates.


# 1.11 23-Dec-2004 dyoung

Extract the transmission status from a tx descriptor, and convert
to host byte-order, once.


# 1.10 20-Dec-2004 dyoung

Realtek sample sources are not consistent about the "Digital PHY"
bit in the SROM. It seems as if it is set to 1 when the PHY is
*analog*, not *digital*. Fix my sources.

In rtw_intr_rx, use units of 500kb/s instead of 100kb/s for rate,
to be consistent with net80211's expectations. Polish up some
debugging ugly messages. Dump raw 802.11 packets if IFF_DEBUG|IFF_LINK2
and RTW_DEBUG is defined.

Polish power-state (on/sleep/off) handling. Especially improve
support for RFMD (totally untested) and Maxim. For Philips, take
the Digital PHY property into account.

Call the net80211 watchdog function from rtw_watchdog, so that we
scan again if auth/assoc fails.

Be a little more cautious about writing register[RTW_TPPOLL], since
other drivers are.... Don't frob the high/low-priority queues
right now, since I don't use them.

Add rtw_join_bss which programs the card with the BSSID and other
properties of a BSS. Use it on state transitions. Factor out
rtw_set_nettype.

Make rtw_recv_beacon call ieee80211_recv_mgmt instead of dropping
beacons on the floor! TBD IBSS merges.

Change some rtw_debug=2 printfs to rtw_debug=3 (RTW_DPRINTF3)
printfs so the console doesn't get spammed so badly at rtw_debug=2.
Change some debugging printfs to RTW_DPRINTFs. E.g., print the
"RF programming method" only if debugging is enabled.


# 1.9 20-Dec-2004 dyoung

Fix bug in last commit: use &sc->sc_regs, regs is not defined.


# 1.8 20-Dec-2004 dyoung

Add some bus barriers. Remark where they are needed, e.g.,
read_eeprom.

Change some printfs to RTW_DPRINTF2s to quiet rtw(4) when debugging
is disabled.


# 1.7 20-Dec-2004 dyoung

Get rid of the silly char (*dvname)[IFNAMSIZ] pattern. Replace it
with const char *dvname. I'm not sure what I was thinking.


# 1.6 20-Dec-2004 dyoung

Assert that I'm DMA-syncing a non-negative number of transmit
descriptors.

As I free dirty transmit buffers, move them to the free list, not
back to the dirty list!

Add a 5-second transmit timeout.


# 1.5 19-Dec-2004 dyoung

Add the transmit section of rtw(4): build up and tear down transmit
descriptor rings, move packets from the transmit queues to the
transmit rings, handle transmission-completed interrupts. My
Linksys WPC11 ver. 4 with Maxim RF, generates interrupts like it
is successfully transmitting packets. Clearly there are bugs: my
G4 Powerbook locks up hard. I will debug tomorrow.


# 1.4 13-Dec-2004 dyoung

At last, I have rtw w/ Philips RF receiving packets.

I added some sysctls to aid debugging:

* hw.rtw.debug -- enable debugging

* hw.rtw.flush_rfio -- Linux voodoo: possibly makes the MAC
"flush" bits down the serial bus to the RF

* hw.rtw.host_rfio: force the host to bang bits to the RF, instead
of the MAC banging bits

* hw.rtw.rfio_delay: after telling the MAC to bang bits to the
RF front-end, delay rfio_delay microseconds.

* hw.rtw.rfprog_fallback: there is this notion of the "RF
programming method." I believe the choice influences the
polarity/timing of the serial bus used to program the RF
front-end. I know the correct choice for Intersil/RFMD/Philips
front-ends, only. For all other front-ends, I "fallback" to
rfprog_fallback.

Make rtw_txdac_enable take an rtw_softc argument. I will probably
revert this change.

Add some Linux voodoo to rtw_continuous_tx_enable. I will probably
revert this change.

Important: add rtw_set_rfprog, which sets the correct RF programming
method. This change and the following change are probably responsible
for making the Philips RF work.

Important: RTW_CONFIG1 is an 8-bit register, treat it that way!

Important: RTW_BRSR is 16-bit, RTW_CRCOUNT, RTW_PHYDELAY, and
RTW_MSR are 8-bit: treat them that way!

Vastly simplify rtw_resume_ticks.

Note to self: set the LED state to match the power state.

Hedge against the possibility that RTW_MSR is protected as
RTW_CONFIG[0123] are, meanwhile reworking that section of rtw_init
a little.

Add sc_anaparm, which isn't used, yet....


# 1.3 12-Dec-2004 dyoung

Miscellaneous changes. Details below. Important changes flagged
with []. Using the driver with my Linksys WPC11 ver. 4, it seems
to be receiving packets for a change. The WPC11 ver. 4 has a Maxim
RF section. My no-name rtw with Philips RF section still does not
receive any packets.

Keep access-level (analog params > config[0123] registers > none)
in sc_access. Add rtw_set_access for changing the access level.

Make rtw_continuous_tx_enable and other subroutines use rtw_set_access
instead of rtw_config0123_enable and rtw_anaparm_enable.

Factor part of the chip-reset code into rtw_chip_reset1.

Change the 'struct foo (*bar)[N]'-style arguments to
'struct foo *bar'-style arguments.

Consolidate software/hardware Tx/Rx ring setup in rtw_hwring_setup,
rtw_swring_setup.

Add a new constant, SA2400_OPMODE_DEFAULTS, for the bits that we
*always* set in the SA2400 OPMODE register.

Factor some code out into rtw_sa2400_calibrate. (Inspired by the
Linux driver.)

[] When the receiver goes into underrun/overflow state, call a new
subroutine, rtw_kick() that stops the Rx/Tx processes, resets
the chip, reinitializes the Tx/Rx rings, and restarts Rx/Tx
processes. (Inspired by the Linux driver.)

[] In rtw_intr_rx, check for too-short packets before calling
ieee80211_find_rxnode. I believe this will prevent a repeat of
the MCHK exception I saw once on macppc.

[] Use seconds-elapased as well as microseconds-elapsed to set the
next "due date" for the timeout interrupt. This keeps the driver
from programming the timeout to expire too early.

[] In rtw_intr, read RTW_ISR at most 10 times, then get out. If
the interface is not enabled (RTW_F_ENABLED), then get out.

[] In rtw_stop, get out if the interface is not enabled (RTW_F_ENABLED).
Block IPL_NET interrupts. Don't read/write any registers if
the interface is invalid (RTW_F_INVALID).

[] Call rtw_stop in rtw_detach.


Revision tags: kent-audio1-base
# 1.2 30-Oct-2004 thorpej

When adding/deleting multicast addresses, only whack the address
filter if the interface is marked RUNNING.

Fixes kern/27678.


# 1.1 26-Sep-2004 dyoung

branches: 1.1.2;
Add work-in-progress driver rtw(4) for Realtek RTL8180 MAC/baseband.

Add register definitions for Maxim MAX2820 and Philips SA2400 radio
front-ends.


# 1.131 23-May-2019 msaitoh

-No functional change:
- KNF
- u_int*_t -> uint*_t.


Revision tags: isaki-audio2-base
# 1.130 05-Feb-2019 msaitoh

Remove very old IFF_NOTRAILERS flag.


# 1.129 03-Feb-2019 mrg

- add or adjust /* FALLTHROUGH */ where appropriate
- add __unreachable() after functions that can return but won't in
this case, and thus can't be marked __dead easily


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 jdolecek-ncqfixes-base pgoyette-compat-0728 phil-wifi-base
# 1.128 26-Jun-2018 msaitoh

Implement the BPF direction filter (BIOC[GS]DIRECTION). It provides backward
compatibility with BIOC[GS]SEESENT ioctl. The userland interface is the same
as FreeBSD.

This change also fixes a bug that the direction is misunderstand on some
environment by passing the direction to bpf_mtap*() instead of checking
m->m_pkthdr.rcvif.


Revision tags: pgoyette-compat-0625 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base tls-maxphys-base-20171202
# 1.127 23-Oct-2017 msaitoh

branches: 1.127.2;
If if_initialize() failed in the attach function, free resources and return.


Revision tags: matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base
# 1.126 23-May-2017 ozaki-r

branches: 1.126.2;
Apply deferred if_start to more drivers

And annotate some XXX_start as it runs in softint to clarify that
it doesn't need deferred if_start.


Revision tags: prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 nick-nhusb-base-20170204
# 1.125 02-Feb-2017 nonaka

wlan interfaces make interrupt routine running on softint context.

see http://mail-index.netbsd.org/tech-kern/2016/12/06/msg021281.html

tested device:
* ath at pci: AR5212, AR5424
* athn at pci: AR9287
* ipw at pci: 2100BG
* iwi at pci: 2915ABG
* iwm at pci: 3165, 7260, 8260
* iwn at pci: 4945, 6235
* ral at pci: RT2560
* rtwn at pci: RTL8192CE


Revision tags: bouyer-socketcan-base pgoyette-localcount-20170107 nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.124 15-Sep-2016 jdolecek

branches: 1.124.2;
remove last isolated islands using BUS_SPACE_BARRIER_SYNC and
BUS_SPACE_BARRIER_X_BEFORE_X - these were only ever defined for mips and ia64,
and never actually implemented even there


Revision tags: localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907
# 1.123 10-Jun-2016 ozaki-r

branches: 1.123.2;
Introduce m_set_rcvif and m_reset_rcvif

The API is used to set (or reset) a received interface of a mbuf.
They are counterpart of m_get_rcvif, which will come in another
commit, hide internal of rcvif operation, and reduce the diff of
the upcoming change.

No functional change.


Revision tags: nick-nhusb-base-20160529
# 1.122 16-May-2016 ozaki-r

Use M_GETCTX and M_SETCTX instead of open-coding rcvif

No functional change.


Revision tags: netbsd-7-2-RELEASE netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 netbsd-7-0-RELEASE nick-nhusb-base-20150921 netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 nick-nhusb-base-20150606 nick-nhusb-base-20150406 nick-nhusb-base netbsd-7-base yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 rmind-smpnet-nbase rmind-smpnet-base tls-maxphys-base
# 1.121 25-Feb-2014 pooka

branches: 1.121.6;
Ensure that the top level sysctl nodes (kern, vfs, net, ...) exist before
the sysctl link sets are processed, and remove redundancy.

Shaves >13kB off of an amd64 GENERIC, not to mention >1k duplicate
lines of code.


# 1.120 17-Oct-2013 christos

- remove unused variables
- move variables inside ifdef sections
- ifdef notdef unused code
- use __USE for debugging variables


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE yamt-pagecache-tag8 netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 agc-symver-base netbsd-6-1-RC2 netbsd-6-1-RC1 yamt-pagecache-base8 netbsd-6-0-1-RELEASE yamt-pagecache-base7 matt-nb6-plus-nbase yamt-pagecache-base6 netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base10 yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.119 04-Jul-2011 joerg

branches: 1.119.2; 1.119.12; 1.119.16;
Fix memset usage.


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base matt-mips64-premerge-20101231 rmind-uvmplock-base
# 1.118 15-Nov-2010 uebayasi

Socket ioctl definitions need sys/sockio.h.


# 1.117 13-Nov-2010 uebayasi

Don't pull in the whole uvm(9) API to access only PAGE_SIZE and
some other constants. These are provided by sys/param.h now.


Revision tags: uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10 uebayasi-xip-base1
# 1.116 05-Apr-2010 joerg

Push the bpf_ops usage back into bpf.h. Push the common ifp->if_bpf
check into the inline functions as well the fourth argument for
bpf_attach.


# 1.115 15-Mar-2010 dyoung

Make this compile on sparc64:

1 s/next_tick/next_tint/ because next_tick shadows a global on sparc64.

2 Fix the bus-barrier helper routines, which had the tag & handle
swapped (!!). Move the helpers from rtwreg.h to rtwvar.h, and
change RTW_BARRIER() into an inline subroutine called rtw_barrier().


Revision tags: yamt-nfs-mp-base9
# 1.114 24-Feb-2010 dyoung

branches: 1.114.2;
A pointer typedef entails trading too much flexibility to declare const
and non-const types, and the kernel uses both const and non-const
PMF qualifiers and device suspensors, so change the pmf_qual_t and
device_suspensor_t typedefs from "pointers to const" to non-pointer,
non-const types.


Revision tags: uebayasi-xip-base
# 1.113 31-Jan-2010 dyoung

branches: 1.113.2;
Add the missing newline to a verbose autoconf message.


# 1.112 19-Jan-2010 pooka

Redefine bpf linkage through an always present op vector, i.e.
#if NBPFILTER is no longer required in the client. This change
doesn't yet add support for loading bpf as a module, since drivers
can register before bpf is attached. However, callers of bpf can
now be modularized.

Dynamically loadable bpf could probably be done fairly easily with
coordination from the stub driver and the real driver by registering
attachments in the stub before the real driver is loaded and doing
a handoff. ... and I'm not going to ponder the depths of unload
here.

Tested with i386/MONOLITHIC, modified MONOLITHIC without bpf and rump.


# 1.111 08-Jan-2010 dyoung

Expand PMF_FN_* macros.


Revision tags: matt-premerge-20091211 jym-xensuspend-nbase
# 1.110 19-Oct-2009 rmind

Drop 3rd and 4th clauses from David Young's license.
Reviewed and approved by dyoung@ (copyright holder).


# 1.109 16-Sep-2009 dyoung

In pmf(9), improve the implementation of device self-suspension
and make suspension by self, by drvctl(8), and by ACPI system sleep
play nice together. Start solidifying some temporary API changes.

1. Extract a new header file, <sys/device_if.h>, from <sys/device.h> and
#include it from <sys/pmf.h> instead of <sys/device.h> to break the
circular dependency between <sys/device.h> and <sys/pmf.h>.

2. Introduce pmf_qual_t, an aggregate of qualifications on a PMF
suspend/resume call. Start to replace instances of PMF_FN_PROTO,
PMF_FN_ARGS, et cetera, with a pmf_qual_t.

3. Introduce the notion of a "suspensor," an entity that holds a
device in suspension. More than one suspensor may hold a device
at once. A device stays suspended as long as at least one
suspensor holds it. A device resumes when the last suspensor
releases it.

Currently, the kernel defines three suspensors,

3a the system-suspensor: for system suspension, initiated
by 'sysctl -w machdep.sleep_state=3', by lid closure, by
power-button press, et cetera,

3b the drvctl-suspensor: for device suspension by /dev/drvctl
ioctl, e.g., drvctl -S sip0.

3c the system self-suspensor: for device drivers that suspend
themselves and their children. Several drivers for network
interfaces put the network device to sleep while it is not
administratively up, that is, after the kernel calls if_stop(,
1). The self-suspensor should not be used directly. See
the description of suspensor delegates, below.

A suspensor can have one or more "delegates". A suspensor can
release devices that its delegates hold suspended. Right now,
only the system self-suspensor has delegates. For each device
that a self-suspending driver attaches, it creates the device's
self-suspensor, a delegate of the system self-suspensor.

Suspensors stop a system-wide suspend/resume cycle from waking
devices that the operator put to sleep with drvctl before the cycle.
They also help self-suspension to work more simply, safely, and in
accord with expectations.

4. Add the notion of device activation level, devact_level_t,
and a routine for checking the current activation level,
device_activation(). Current activation levels are DEVACT_LEVEL_BUS,
DEVACT_LEVEL_DRIVER, and DEVACT_LEVEL_CLASS, which respectively
indicate that the device's bus is active, that the bus and device are
active, and that the bus, device, and the functions of the device's
class (network, audio) are active.

Suspend/resume calls can be qualified with a devact_level_t.
The power-management framework treats a devact_level_t that
qualifies a device suspension as the device's current activation
level; it only runs hooks to reduce the activation level from
the presumed current level to the fully suspended state. The
framework treats a devact_level_t qualifying device resumption
as the target activation level; it only runs hooks to raise the
activation level to the target.

5. Use pmf_qual_t, devact_level_t, and self-suspensors in several
drivers.

6. Temporarily add an unused power-management workqueue that I will
remove or replace, soon.


Revision tags: yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5 yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 nick-hppapmap-base3 jym-xensuspend-base nick-hppapmap-base
# 1.108 07-Apr-2009 dyoung

Cosmetic: remove some dead code.


# 1.107 02-Apr-2009 dyoung

Add the WEP capability to our net80211 capability flags, since we do
sort of support hardware WEP. Only change the WEP key index in a Tx
descriptor from 0 if the type of our transmit key is _WEP, not _TKIP:
i.e., only if we're really doing WEP crypto in the hardware.

Ignore a watchdog timeout on any Tx ring if we can collect some packets
from that ring. Restart both the receiver and the transmitter when a
watchdog timeout occurs instead of restarting only the transmitter.


Revision tags: nick-hppapmap-base2 haad-dm-base2 haad-nbase2 ad-audiomp2-base haad-dm-base mjf-devfs2-base
# 1.106 12-Nov-2008 ad

branches: 1.106.4;
Remove LKMs and switch to the module framework, pass 1.

Proposed on tech-kern@.


# 1.105 07-Nov-2008 dyoung

*** Summary ***

When a link-layer address changes (e.g., ifconfig ex0 link
02:de:ad:be:ef:02 active), send a gratuitous ARP and/or a Neighbor
Advertisement to update the network-/link-layer address bindings
on our LAN peers.

Refuse a change of ethernet address to the address 00:00:00:00:00:00
or to any multicast/broadcast address. (Thanks matt@.)

Reorder ifnet ioctl operations so that driver ioctls may inherit
the functions of their "class"---ether_ioctl(), fddi_ioctl(), et
cetera---and the class ioctls may inherit from the generic ioctl,
ifioctl_common(), but both driver- and class-ioctls may override
the generic behavior. Make network drivers share more code.

Distinguish a "factory" link-layer address from others for the
purposes of both protecting that address from deletion and computing
EUI64.

Return consistent, appropriate error codes from network drivers.

Improve readability. KNF.

*** Details ***

In if_attach(), always initialize the interface ioctl routine,
ifnet->if_ioctl, if the driver has not already initialized it.
Delete if_ioctl == NULL tests everywhere else, because it cannot
happen.

In the ioctl routines of network interfaces, inherit common ioctl
behaviors by calling either ifioctl_common() or whichever ioctl
routine is appropriate for the class of interface---e.g., ether_ioctl()
for ethernets.

Stop (ab)using SIOCSIFADDR and start to use SIOCINITIFADDR. In
the user->kernel interface, SIOCSIFADDR's argument was an ifreq,
but on the protocol->ifnet interface, SIOCSIFADDR's argument was
an ifaddr. That was confusing, and it would work against me as I
make it possible for a network interface to overload most ioctls.
On the protocol->ifnet interface, replace SIOCSIFADDR with
SIOCINITIFADDR. In ifioctl(), return EPERM if userland tries to
invoke SIOCINITIFADDR.

In ifioctl(), give the interface the first shot at handling most
interface ioctls, and give the protocol the second shot, instead
of the other way around. Finally, let compatibility code (COMPAT_OSOCK)
take a shot.

Pull device initialization out of switch statements under
SIOCINITIFADDR. For example, pull ..._init() out of any switch
statement that looks like this:

switch (...->sa_family) {
case ...:
..._init();
...
break;
...
default:
..._init();
...
break;
}

Rewrite many if-else clauses that handle all permutations of IFF_UP
and IFF_RUNNING to use a switch statement,

switch (x & (IFF_UP|IFF_RUNNING)) {
case 0:
...
break;
case IFF_RUNNING:
...
break;
case IFF_UP:
...
break;
case IFF_UP|IFF_RUNNING:
...
break;
}

unifdef lots of code containing #ifdef FreeBSD, #ifdef NetBSD, and
#ifdef SIOCSIFMTU, especially in fwip(4) and in ndis(4).

In ipw(4), remove an if_set_sadl() call that is out of place.

In nfe(4), reuse the jumbo MTU logic in ether_ioctl().

Let ethernets register a callback for setting h/w state such as
promiscuous mode and the multicast filter in accord with a change
in the if_flags: ether_set_ifflags_cb() registers a callback that
returns ENETRESET if the caller should reset the ethernet by calling
if_init(), 0 on success, != 0 on failure. Pull common code from
ex(4), gem(4), nfe(4), sip(4), tlp(4), vge(4) into ether_ioctl(),
and register if_flags callbacks for those drivers.

Return ENOTTY instead of EINVAL for inappropriate ioctls. In
zyd(4), use ENXIO instead of ENOTTY to indicate that the device is
not any longer attached.

Add to if_set_sadl() a boolean 'factory' argument that indicates
whether a link-layer address was assigned by the factory or some
other source. In a comment, recommend using the factory address
for generating an EUI64, and update in6_get_hw_ifid() to prefer a
factory address to any other link-layer address.

Add a routing message, RTM_LLINFO_UPD, that tells protocols to
update the binding of network-layer addresses to link-layer addresses.
Implement this message in IPv4 and IPv6 by sending a gratuitous
ARP or a neighbor advertisement, respectively. Generate RTM_LLINFO_UPD
messages on a change of an interface's link-layer address.

In ether_ioctl(), do not let SIOCALIFADDR set a link-layer address
that is broadcast/multicast or equal to 00:00:00:00:00:00.

Make ether_ioctl() call ifioctl_common() to handle ioctls that it
does not understand.

In gif(4), initialize if_softc and use it, instead of assuming that
the gif_softc and ifp overlap.

Let ifioctl_common() handle SIOCGIFADDR.

Sprinkle rtcache_invariants(), which checks on DIAGNOSTIC kernels
that certain invariants on a struct route are satisfied.

In agr(4), rewrite agr_ioctl_filter() to be a bit more explicit
about the ioctls that we do not allow on an agr(4) member interface.

bzero -> memset. Delete unnecessary casts to void *. Use
sockaddr_in_init() and sockaddr_in6_init(). Compare pointers with
NULL instead of "testing truth". Replace some instances of (type
*)0 with NULL. Change some K&R prototypes to ANSI C, and join
lines.


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 wrstuden-revivesa-base-1 simonb-wapbl-nbase yamt-pf42-base4 simonb-wapbl-base yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 yamt-nfs-mp-base2 wrstuden-revivesa-base yamt-nfs-mp-base yamt-pf42-base ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 1.104 15-Mar-2008 dyoung

branches: 1.104.4; 1.104.10; 1.104.12;
Cosmetic: make rtw_hw_keysupp() return a bool instead of int. In
rtw_wep_setkeys(), add a debug printf, and move the initialization
of keylen from the for-loop to the declaration.


# 1.103 14-Mar-2008 dyoung

Extract subroutine rtw_tx_kick() from rtw_start(), and reuse it in
rtw_io_enable() to restart the transmitter after resetting it.


# 1.102 14-Mar-2008 dyoung

Change tests for "impossible" keys to KASSERT()s. Get rid of a
temporary variable. In rtw_key_delete(), do not invalidate the
hardware keys unless a WEP key is deleted.


# 1.101 12-Mar-2008 dyoung

Use device_t and its accessors throughout. Use aprint_*_dev().

Improve PMF-ability.

Add a 'flags' argument to suspend/resume handlers and
callers such as pmf_system_suspend().

Define a flag, PMF_F_SELF, which indicates to PMF that a
device is suspending/resuming itself. Add helper routines,
pmf_device_suspend_self(dev) and pmf_device_resume_self(dev),
that call pmf_device_suspend(dev, PMF_F_SELF) and
pmf_device_resume(dev, PMF_F_SELF), respectively. Use
PMF_F_SELF to suspend/resume self in ath(4), audio(4),
rtw(4), and sip(4).

In ath(4) and in rtw(4), replace the icky sc_enable/sc_disable
callbacks, provided by the bus front-end, with
self-suspension/resumption. Also, clean up the bus
front-ends. Make sure that the interrupt handler is
disestablished during suspension. Get rid of driver-private
flags (e.g., RTW_F_ENABLED, ath_softc->sc_invalid); use
device_is_active()/device_has_power() calls, instead.

In the network-class suspend handler, call if_stop(, 0)
instead of if_stop(, 1), because the latter is superfluous
(bus- and driver-suspension hooks will 'disable' the NIC),
and it may cause recursion.

In the network-class resume handler, prevent infinite
recursion through if_init() by getting out early if we are
self-suspending (PMF_F_SELF).

rtw(4) improvements:

Destroy rtw(4) callouts when we detach it. Make rtw at
pci detachable. Print some more information with the "rx
frame too long" warning.

Remove activate() methods:

Get rid of rtw_activate() and ath_activate(). The device
activate() methods are not good for much these days.

Make ath at cardbus resume with crypto functions intact:

Introduce a boolean device property, "pmf-powerdown". If
pmf-powerdown is present and false, it indicates that a
bus back-end should not remove power from a device.

Honor this property in cardbus_child_suspend().

Set this property to 'false' in ath_attach(), since removing
power from an ath at cardbus seems to lobotomize the WPA
crypto engine. XXX Should the pmf-powerdown property
propagate toward the root of the device tree?

Miscellaneous ath(4) changes:

Warn if ath(4) tries to write crypto keys to suspended
hardware.

Reduce differences between FreeBSD and NetBSD in ath(4)
multicast filter setup.

Make ath_printrxbuf() print an rx descriptor's status &
key index, to help debug crypto errors.

Shorten a staircase in ath_ioctl(). Don't check for
ieee80211_ioctl() return code ERESTART, it never happens.


# 1.100 12-Mar-2008 dyoung

Print the TPPoll register when the Tx DMA engine doesn't shut down
in the time we allow.


# 1.99 03-Mar-2008 tsutsui

Explicitly include <sys/device.h> for device_t.


Revision tags: nick-net80211-sync-base vmlocking2-base3 bouyer-xeni386-nbase bouyer-xeni386-base mjf-devfs-base matt-armv6-base hpcarm-cleanup-base
# 1.98 21-Dec-2007 dyoung

branches: 1.98.2; 1.98.6;
Do not embed a struct device in rtw_softc any longer. Register
both pci and cardbus attachments with CFATTACH_DECL_NEW(). Access
the softc through the device_t using device_private().

While I'm here, change a couple of KASSERT()s about the Rx buffer
length to a warning.


# 1.97 20-Dec-2007 dyoung

Remove shutdown hooks. Use KASSERT().


# 1.96 16-Dec-2007 dyoung

Fix a bug I introduced to rtw_chan2txpower() the other night.

Fix a bug in device detachment: change a break statement to a
/*FALLTHROUGH*/ in rtw_detach().


# 1.95 16-Dec-2007 dyoung

Synchronize device detachment with network interrupts. Use the
pmf network class instead of powerhooks.


Revision tags: yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 bouyer-xenamd64-base2 vmlocking-nbase bouyer-xenamd64-base jmcneill-pm-base reinoud-bufcleanup-base
# 1.94 18-Nov-2007 jnemeth

branches: 1.94.2; 1.94.6;
fix 'm' used unitialized


# 1.93 16-Nov-2007 dyoung

Accommodate the variety of RF front-ends when radiotapping frames:
tap only RSSI when there is a Philips RF front-end. Tap both Barker
lock quality and RSSI when there is any other RF front-end.

Provide radiotap listeners a more complete picture of channel
activity:

in promiscuous mode, tap frames who do not pass the CRC32 check.
Flag packets that were received with a short preamble. Ask
the NIC to pass us 802.11 Control frames. Pass frames to
radiotap listeners before stripping the FCS. Re-order operations
in rtw_intr_rx() in order to accomplish all of this, taking
care not to pass a broken packet to net80211!

Do not provide a flags field when tapping xmitted frames.

Assert sane Rx packet lengths. Really should check and drop instead
of KASSERTing. I will revisit this, soon.

Update copyright.


# 1.92 15-Nov-2007 dyoung

Fix order of operations:

rtw_rxdesc_init: before initializing a Rx descriptor's
control word, synchronize the Rx buffer

rtw_start, be paranoid: set the "NIC owns" bit on a Tx
descriptor dead last. Always reinitialize the "next
Tx descriptor" pointer, just in case it got clobbered
somehow.

Let the compiler decide whether to inline rtw_collect_txring or
not.


Revision tags: jmcneill-base
# 1.91 19-Oct-2007 ad

branches: 1.91.2;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h


Revision tags: yamt-x86pmap-base4 yamt-x86pmap-base3 yamt-x86pmap-base2 vmlocking-base
# 1.90 29-Sep-2007 scw

branches: 1.90.2;
s/NPBFILTER/NBPFILTER/ in some #endif comments. No functional change.


Revision tags: nick-csl-alignment-base5 yamt-x86pmap-base matt-mips64-base nick-csl-alignment-base mjf-ufs-trans-base
# 1.89 09-Jul-2007 ad

branches: 1.89.6; 1.89.8; 1.89.10;
Merge some of the less invasive changes from the vmlocking branch:

- kthread, callout, devsw API changes
- select()/poll() improvements
- miscellaneous MT safety improvements


# 1.88 29-May-2007 dyoung

Fix rtw(4) on NetBSD/macppc: use bus_space_write_region_stream_4()
instead of bus_space_write_region_4() to write WEP Rx keys to the
NIC. Thanks macallan@ for detecting the bug and testing the fix.


# 1.87 29-May-2007 dyoung

Cosmetic: simplify a memset() statement, use __arraycount(), and
remove a gratuitous return statement at the end of a void subroutine.


# 1.86 29-May-2007 dyoung

Simplify multicast filter programming, and take care to avoid
gratuitous device resets when the kernel adds/deletes a multicast
address.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base
# 1.85 04-Mar-2007 christos

branches: 1.85.2; 1.85.4;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.


Revision tags: ad-audiomp-base post-newlock2-merge newlock2-nbase newlock2-base
# 1.84 29-Jan-2007 dyoung

branches: 1.84.2;
In rtw_dequeue(), initialize *mp to NULL before anything else, so
that it is either NULL or a valid mbuf. Previously, it was possible
for rtw_dequeue() to exit with 0 before initializing *mp. rtw_start()
would have used whatever trash was in *mp, which would lead to
problems later on.


# 1.83 06-Jan-2007 dyoung

I have made a small change that suppresses "recovery" from (spurious?)
tx timeouts on the beacon queue. The driver's recovery process
badly disrupts the MAC's receiver. This needs a closer look, later.

Every other fix is by Charles M. Hannum. Charles writes:

"With these, the device is quite stable under load, does not experience
xmit timeouts, no longer mysteriously freezes, and does not spew
a lot of garbage. It does, however, continue to get some "tx fifo
underflow"s.

global, SYSCTL_SETUP():
a) Removed unused sysctl variables.

rtw_io_enable():
b) Change rtw_io_enable to take a softc, and make it call
rtw_txring_fixup().
c) Enable the PCI multiple read/write bit.
d) Always reset rdb_next to 0 when starting the receive engine.

rtw_intr_rx():
e) When processing receive packets, store the next pointer in rdb_next
and read it back on the next round, to fix a race condition vs.
rtw_tune() during AP discovery and association.
f) Remove the special "skip to 0th descriptor" code, because it is no
longer needed.

rtw_collect_txring():
g) In the "force" case, stop when we catch up to the hardware xmit
pointer.

rtw_intr_beacon():
h) Resetting tdb_next here looked fishy to me, in light of changes in
rtw_collect_txring(). XXX However, this is the one part I haven't
tested.

rtw_txring_fixup():
i) Add function and line arguments, so we can print out information
about the caller.
j) In addition to reading the hardware pointer, skip over any
additional packets with OWN set -- we may have queued more.

rtw_rxring_fixup():
k) Remove this, because it's completely wrong.

rtw_intr_ioerror():
l) Don't handle receive overruns here; handle them in the normal receive
path. Also changed RTW_INTR_RX and RTW_INTR_IOERROR accordingly.
m) Do not fiddle with CR; the transmit engine is still running just
fine.
n) Do not fiddle with IMR; it was unnecessary.
o) Don't touch the receive engine at all; not necessary now that we're
leaving CR alone.
p) Remove the rtw_do_chip_reset case; it was dangerous and not actually
used.

rtw_intr():
q) Don't mask off ISR bits when we pass down the ISR value; it's not
necessary, and sometimes the other bits useful in debugging output.

rtw_seg_too_short():
r) Don't spew here; the caller will do it if necessary. (Stops spewage
in an expected case.)

rtw_rxdesc_blk:
s) Minor change to make the elements have the same order as txdesc_blk.

general:
t) Added a bunch of debugging output, #ifdef RTW_DIAG, that was useful
while investigating the ring management problems. Also moved
rtw_txring_fixup() into RTW_DIAG, as I believe the transmit pointer
is always kept in sync now, and the function has potential race
conditions.


# 1.82 06-Jan-2007 dyoung

After we examine a rx/tx descriptor and find that it's still owned
by the NIC, re-sync the descriptor so that a cacheline will not
"cover" the NIC's modifications to the descriptor when we next
examine it.

This compiles, but I have not tested it, yet.


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase wrstuden-fixsa-base-1 netbsd-4-0-RELEASE netbsd-4-0-RC5 matt-nb4-arm-base netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 wrstuden-fixsa-base yamt-splraiseipl-base5 yamt-splraiseipl-base4 yamt-splraiseipl-base3 netbsd-4-base
# 1.81 16-Nov-2006 christos

__unused removal on arguments; approved by core.


# 1.80 13-Nov-2006 dyoung

Stop using typeof() in the bit-twiddling macros, per yamt@'s
suggestion. This change requires that I use the __PRIuBITS format
string in atw and rtw, so do that.


Revision tags: yamt-splraiseipl-base2
# 1.79 12-Oct-2006 xtraeme

Use __unused in function arguments where appropiate.


# 1.78 12-Oct-2006 christos

- sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386


# 1.77 24-Sep-2006 jmcneill

Add "name" parameter to powerhook_establish, to aid debugging. No objections
on tech-kern@


Revision tags: yamt-splraiseipl-base yamt-pdpolicy-base9 yamt-pdpolicy-base8 rpaulo-netinet-merge-pcb-base
# 1.76 03-Sep-2006 christos

branches: 1.76.2; 1.76.4;
- comment out impossible comparisons
- remove superfluous if statement


# 1.75 31-Aug-2006 dyoung

Per discussion on tech-kern and tech-userlevel, move the bit-twiddling
macros, __BIT, __BITS, SHIFTIN, SHIFTOUT, and __arraycount() from
lib/libkern/libkern.h to sys/cdefs.h. Add a __-prefix to SHIFTIN
and SHIFTOUT, and add a manual page for the bit-twiddling macros,
bits(3).

Make the __BIT and __BITS macros "widthless," as best I can, by
changing their type to uintmax_t from uint32_t. XXX The manual
page lags this change by a bit.

Define __PRIxBIT and __PRIxBITS printf(3) format strings.


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base7 yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base simonb-timecounters-base
# 1.74 26-May-2006 blymn

Clean up bogus whitespace


Revision tags: yamt-pdpolicy-base5
# 1.73 14-May-2006 christos

branches: 1.73.2;
XXX: GCC uninitialized


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 elad-kernelauth-base
# 1.72 28-Mar-2006 dyoung

Revamp ieee80211_get_rate. Now it does not use the rateset in the
ic->ic_bss, but it uses the rateset in its new ieee80211_node
argument, instead. If the rate is fixed by ic->ic_fixed_rate, but
the fixed rate is not in the node's rateset, choose a reasonable
default: prefer the lowest basic rate or, if there is no basic
rate, prefer the lowest rate, period.

Change a printf complaint to a debug message.

Adapt drivers to suit new ieee80211_get_rate calling convention.

XXX I really need to replace ieee80211_get_rate with a bitrate
XXX adaptation algorithm. Soon, soon....


# 1.71 27-Mar-2006 dyoung

Set the channel frequency and flags in the radiotap headers in
rtw_tune instead of in rtw_start, rtw_intr_rx.


# 1.70 27-Mar-2006 dyoung

Remove unused argument ifflagsp from rtw_dmamap_load_txbuf.


Revision tags: peter-altq-base yamt-pdpolicy-base2
# 1.69 08-Mar-2006 dyoung

branches: 1.69.2;
Change macro names to avoid collisions:

BIT -> __BIT
BITS -> __BITS


# 1.68 08-Mar-2006 dyoung

Move my bit-twiddling macros to libkern.h from my drivers, where
I had duplicated them. Improve the macros' names. Simplify their
implementation.

A brief description of each macro is below.

BIT(n): Return a bitmask with bit m set, where the least
significant bit is bit 0.

BITS(m, n): Return a bitmask with bits m through n, inclusive,
set. It does not matter whether m>n or m<=n.
The least significant bit is bit 0.

A "bitfield" is a span of consecutive bits defined by a
bitmask, where 1s select the bits in the bitfield. SHIFTIN,
SHIFTOUT, and SHIFTOUT_MASK help read and write bitfields
from device registers.

SHIFTIN(v, mask): Left-shift bits `v' into the bitfield
defined by `mask', and return them. No
side-effects.

SHIFTOUT(v, mask): Extract and return the bitfield selected
by `mask' from `v', right-shifting the
bits so that the rightmost selected bit
is at bit 0. No side-effects.

SHIFTOUT_MASK(mask): Right-shift the bits in `mask' so that
the rightmost non-zero bit is at bit
0. This is useful for finding the
greatest unsigned value that a bitfield
can hold. No side-effects. Note that
SHIFTOUT_MASK(m) = SHIFTOUT(m, m).

Examples:

/*
* Register definitions taken from the RFMD RF3000 manual.
*/
#define RF3000_GAINCTL 0x11 /* TX variable gain control */
#define RF3000_GAINCTL_TXVGC_MASK BITS(7, 2)
#define RF3000_GAINCTL_SCRAMBLER BIT(1)

/*
* Shift the transmit power into the transmit-power field of the
* gain-control register and write it to the baseband processor.
*/
atw_rf3000_write(sc, RF3000_GAINCTL,
SHIFTIN(txpower, RF3000_GAINCTL_TXVGC_MASK));


/*
* Register definitions taken from the ADMtek ADM8211 manual.
*
*/
#define ATW_RXSTAT_OWN BIT(31) /* 1: NIC may fill descriptor */
/* ... */
#define ATW_RXSTAT_DA1 BIT(17) /* DA bit 1, admin'd address */
#define ATW_RXSTAT_DA0 BIT(16) /* DA bit 0, group address */
#define ATW_RXSTAT_RXDR_MASK BITS(15,12) /* RX data rate */
#define ATW_RXSTAT_FL_MASK BITS(11,0) /* RX frame length, last
* descriptor only
*/

/* Extract the frame length from the Rx descriptor's
* status field.
*/
len = SHIFTOUT(rxstat, ATW_RXSTAT_FL_MASK);


Revision tags: yamt-pdpolicy-base yamt-uio_vmspace-base5
# 1.67 20-Feb-2006 thorpej

branches: 1.67.2; 1.67.4;
Use device_is_active() rather than testing dv_flags for DVF_ACTIVE
directly.


# 1.66 19-Feb-2006 dyoung

When rtw_enable is called, power may have been removed and re-applied,
so invalidate the WEP key registers to force us to write the keys
back to the hardware.

Revamp key handling: use the hardware WEP engine for 40-bit and
104-bit keys, only; use software WEP for all other key lengths.
Set the hardware key length to the length of the default Tx key,
or if there is no default Tx key, use the length of the longest
WEP key.


# 1.65 04-Feb-2006 dyoung

In rtw_{rx,tx}ring_fixup, do not set the tx/rx ring index to
something out of bounds if we read an invalid pointer form the
hardware. Prevents a panic when an rtw@cardbus is ejected.


# 1.64 29-Dec-2005 dyoung

branches: 1.64.2; 1.64.4; 1.64.6;
Add support for the GCT Semiconductor GRF5101 transceiver/synthesizer.
From OpenBSD.

GCT will not provide any documentation, so there are many magic
numbers in this code.


# 1.63 29-Dec-2005 dyoung

Update rtw(4) for the new IBSS merge idiom, where ieee80211_ibss_merge()
does not return ENETRESET if the driver should change its BSSID,
but it makes a RUN->RUN transition, instead.


# 1.62 29-Dec-2005 dyoung

In atw(4), use ieee80211_compute_duration() to compute IEEE 802.11
Duration and PLCP Length fields, and delete the abominable
atw_frame_setdurs() subroutine.

Make rtw(4) use the new ieee80211_compute_duration() calling
convention.

Add an ieee80211_key argument to ieee80211_compute_duration() and
lightly constify arguments. Get the crypto header length from the
key argument instead of blithely assuming a WEP header. Add some
inline documentation. Account for data padding (IEEE80211_F_DATAPAD).


# 1.61 24-Dec-2005 perry

Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.


# 1.60 13-Dec-2005 dyoung

Fix comments and debug printfs: Tx FIFOs underflow, they don't
overflow.


# 1.59 13-Dec-2005 dyoung

On a transmit FIFO overflow (err, actually an underflow...) reset
both the transmit & receive sections of the MAC.


Revision tags: yamt-readahead-base3 ktrace-lwp-base
# 1.58 23-Nov-2005 dyoung

Miscellaneous Realtek RTL8180L driver improvements:

1 Added new sysctl controls for debugging.

2 Improve detection & support for hardware WEP.

3 Revamp handling of transmit descriptor rings.

4 Reliably IFF_OACTIVE when transmit descriptors are available, to
stop the transmit section of the driver from freezing up.

5 Fix beacon transmission in adhoc and hostap modes. XXX There is
a wart in hostap mode, where beacons are transmitted at 1/2 the
correct rate. Load beacon descriptors when the RTW_INTR_BINT
interrupt arrives; schedule RTW_INTR_BINT 1ms ahead of the target
beacon time.

6 Recover more gracefully from tx/rx errors: avoid
transmitter/receiver/chip resets. Try to re-synchronize software
state with hardware state---e.g., load next descriptor pointer
from hardware.

7 Activate the transmit watchdog timer for beacons as well as other
packets.

8 Introduce rtw_idle() that waits for transmit DMA to finish; call
it before resetting the transmitter.


Revision tags: yamt-readahead-base2
# 1.57 18-Nov-2005 skrll

Adapt drivers to the new net80211(9).

Most of this is from dyoung@. Thanks!


Revision tags: yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base
# 1.56 22-Sep-2005 gdt

branches: 1.56.6;
Make arg of IFQ_SET_READY be &ifp->if_snd, to match all other drivers
and be compilable with altq enabled. Reviewed by dyoung@


# 1.55 07-Sep-2005 dogcow

With the assistance of dyoung, fix the following problems:
* some 8180L cards need a longer time for the srom to initialize; patch
suggested via OpenBSD.
* some cards give '0' for USA, some give '3'; for the meantime, accept both
as being USA locale cards.
* this is RTW, not ATW. :)


# 1.54 06-Sep-2005 dogcow

make rtw.c compile again after the 22-jun-05 net80211 import


# 1.53 11-Jul-2005 dyoung

Add undefined variable 'ic' to rtw_attach.


# 1.52 06-Jul-2005 dyoung

Historically, an(4), ath(4), atw(4), rtw(4), and wi(4) have printed
out their modes and rates at boot. Revert to the historical
behavior.


# 1.51 06-Jul-2005 dyoung

Avoid an unnecessary API difference between NetBSD and FreeBSD:
back out my change to ieee80211_crypto_encap that made it free its
mbuf argument on error. I had thought it was a bug. It was not.
It's the drivers that are broken. Make an(4), atw(4), ipw(4),
iwi(4), ral(4), rtw(4), ural(4), and wi(4) free the mbuf when
ieee80211_crypto_encap returns NULL. Also, return ath(4) to the
way it was---i.e., free the mbuf.

Thanks to Sam Leffler to pointing out my mistake.


# 1.50 28-Jun-2005 dyoung

branches: 1.50.2;
Here is a grotty hack that lets the RTL8180L handle WEP in the
receive direction, while software handles WEP in the transmit
direction. When net80211 calls rtw's rtw_key_set with a WEP key,
I point the key's wk_cipher at our "fake" cipher, rtw_cipher_wep,
which is alike to ieee80211_cipher_wep except it provides a different
crypto-decapsulation routine, rtw_wep_decap. rtw_wep_decap copies
the key passed to it by net80211, clears the key's SWCRYPT flag,
and then calls wep_decap. Now wep_decap will decapsulate, but it
will *not* re-decrypt.

XXX I need to check whether the hardware supports 40-bit WEP,
XXX 104-bit WEP, or both, and act accordingly.


# 1.49 27-Jun-2005 dyoung

rtw: Try to get hardware WEP to work. It seems to work in
the RX direction, but not in the TX direction. The
net80211 crypto framework doesn't seem to cope very well
with the assymetry (I'm probably missing something), so
I will use software WEP for now.

net80211: In ieee80211_compute_duration, figure out whether to add
the WEP header to the packet overhead by checking the
WEP bit in the Frame Control field of the 802.11 header,
instead of checking the IEEE80211_F_PRIVACY flag.

Also, if the WEP bit is present, assume that the frame
described by (wh, len) has already already been WEP
encapsulated, and adjust the payload length accordingly.
XXX that's a grotty hack that I will have to revisit,
later.


# 1.48 22-Jun-2005 dyoung

Resolve conflicts in importation of 18-May-2005 ath(4) / net80211(9)
from FreeBSD. Introduce compatibility shims (sys/dev/ic/ath_netbsd.[ch],
sys/net80211/ieee80211_netbsd.[ch]). Update drivers (an, atu, atw,
awi, ipw, iwi, rtw, wi) for the new net80211(9) API.


# 1.47 20-Jun-2005 atatat

Change the rest of the sysctl subsystem to use const consistently.
The __UNCONST macro is now used only where necessary and the RW macros
are gone. Most of the changes here are consumers of the
sysctl_createv(9) interface that now takes a pair of const pointers
which used not to be.


# 1.46 10-Jun-2005 dyoung

Sprinkle __UNCONST() and rename variables to quiet uiet -Wcast-qual,
-Wshadow complaints.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 yamt-km-base4 yamt-km-base3 netbsd-3-base kent-audio2-base
# 1.45 02-Mar-2005 dyoung

Misc. changes to improve ad hoc mode and to enable hostap mode:

Fix the work-around for the NIC bug where it skips to rx
descriptor 0. The driver used to skip to rx descriptor 1.
Hopefully this stops the out-of-order packet reception that
Charles Hannum saw.
When debugging is enabled, print rx-descriptor status flags
before printing the rx bit rate.

Add a debug message for when a beacon tx buffer reclamation.

Reset IFF_OACTIVE when we reset the transmitter.

Pass the consolidated LED state, a struct rtw_led_state,
to rtw_led_attach.

Choose the bit-rate for management frames (1Mb/s) at the
same place we choose for all other frames.

Do not use the NIC's short preamble or RTS options for
management frames. Label beacons for the NIC.

Following a Linux driver, take care not to zero arbitrary
bits in the TPPOLL register.

Use the new idiom for IBSS merges: disable transmitter,
kick the state machine.
Add a second descriptor to the beacon ring. The NIC seems
to like this much better.


# 1.44 27-Feb-2005 perry

nuke trailing whitespace


Revision tags: yamt-km-base2
# 1.43 31-Jan-2005 thorpej

Eliminate use of M_HASFCS.


Revision tags: yamt-km-base
# 1.42 16-Jan-2005 dyoung

branches: 1.42.2; 1.42.4;
Move the register access mode into struct rtw_regs. Change
rtw_set_access, rtw_set_access1 to match.

Add a subroutine for setting WEP keys. WEP isn't quite finished,
because I have to add the WEP header to Tx packets. Implement the
SIOCS80211NWKEY ioctl for setting WEP keys.

Program the LEDs based on operating state and packet activity.

* On a Revision F RTL8180, blink LED1 at 1Hz to indicate
scan/authenticate/associate states. In the run state, turn LED1
on. In every state, blink LED1 at 5Hz to indicate non-beacon
tx/rx activity. I would like to use two LEDs, but in all my
Rev. F instances, LED0 is not wired to an LED; instead, the
first LED is wired to indicate that the card's power is on.

* On a Revision D RTL8180, program the LEDs so that LED0 indicates
Tx, and LED1 indicates Rx. The Rx LED will blink annoyingly if
there are beacons in the air, but at least the Tx LED is useful.

* Store the hardware revision in the softc to support my futile
attempt at programming LEDs for both Rev. D and Rev. F parts;
I never did get Rev. D LEDs to work right.

* Add a debug flag RTW_DEBUG_LED for the LED transitions.

Add RTW_TPPOLL_ALL, RTW_TPPOLL_SALL to start and stop, respectively,
all of the transmit rings.

In ad hoc mode, allocate a beacon and load it into the beacon ring.
Start the ring. In one trial, the card re-transmitted the beacon
ring's contents several times before stopping. More programming
and testing for ad hoc mode is necessary. I'm not setting the
beacon flag in the transmit descriptor.

Revamp the transmit section to make better use of all the transmit
rings: beacon queue, high-, low-, and medium-priority rings. Put
beacon frames on the beacon ring. All other management frames,
and data frames, go on the medium-priority ring. Power-save data
frames go on the high-priority ring. (Note that powersaving is
not implemented!) This is a work in progress.

Send all 802.11 Management frames at 1Mbps.

After we put a packet on a transmit ring, tickle the right bit in
the TPPOLL to tell RTL8180. Stop all rings on error and in rtw_stop.

Use the RF chip type, not the RTL8180 revision, to choose between
host- and MAC-controlled RF serial I/O. Now the Netgear MA521
works.

Remove bogus definition of bit RTW_TPPOLL_FSWINT.


Revision tags: kent-audio1-beforemerge
# 1.41 04-Jan-2005 dyoung

Set initial conditions to guarantee that when read_seeprom toggles
Chip Select, it turns *on* rather than *off*.


# 1.40 04-Jan-2005 dyoung

Add the logic for IBSS merges.


# 1.39 03-Jan-2005 dyoung

sys/dev/ic/rtw.c:

Cosmetic: remove two short ladders from rtw_init. Fit the
NIC registers print-out onto one line using the RTW_PRINT_REGS
macro.

sys/dev/ic/rtwvar.h:

Add RTW_PRINT_REGS wrapper macro for rtw_print_regs. It
is a null op unless defined(RTW_DEBUG).


# 1.38 03-Jan-2005 dyoung

In sys/dev/ic/rtw.c:

Use clue from rtk(4) and re(4) to fix the rtw(4) packet
filter. Previously, I was using the wrong CRC32 function
to hash multicast addresses; to compensate, I set the
multicast filter to all 1s. Now that I hash the addresses
correctly, I do not any longer set the filter to all 1s.

In rtw_ioctl, avoid gratuitous re-initialization when the
interface flags change. If a !IFF_UP -> IFF_UP transition,
call rtw_init(); otherwise, only reload the packet filter.

In sys/dev/ic/rtwreg.h:

Put useful combinations of Receiver Control Register flags
in RTW_RCR_PKTFILT_MASK, RTW_RCR_MONITOR, and
RTW_RCR_PKTFILT_DEFAULT. (XXX RTW_RCR_MONITOR should be
called RTW_RCR_PKTFILT_MONITOR.)


# 1.37 02-Jan-2005 dyoung

Cosmetic: change u_int{8,16,32,64}_t to C99-style uint{8,16,32,64}_t,
which is preferred.


# 1.36 29-Dec-2004 dyoung

In rtw_detach, flag the rtw as "invalid" (RTW_F_INVALID). Do not
try to power-down the RF section of an invalid rtw.

The radiotap signal quality field is 16, not 8, bits wide. Convert
the byte order.


# 1.35 29-Dec-2004 dyoung

Remove some dead code.


# 1.34 29-Dec-2004 dyoung

I like the tlp/atw-style names for software descriptors, txsoft,
better than txctl. Change from rtw_txctl/rtw_rxctl to
rtw_txsoft/rtw_rxsoft. Change the descriptor blocks' names to
match: rtw_txctl_blk becomes rtw_txsoft_blk. Change the member-name
prefixes for both software and hardware descriptors.


# 1.33 29-Dec-2004 dyoung

Consolidate variables related to the rx ring in sc_rxdesc_blk,
which is a struct rtw_rxdesc_blk.

Put a copy of the DMA tag and the DMA map into the rx- and tx-ring
blocks so that I don't have to pass them to subroutines all of the
time.


# 1.32 28-Dec-2004 dyoung

Add bpf(4) packet taps to rtw(4). Now you can tap DLT_EN10MB
(Ethernet II), DLT_IEEE802_11 (802.11), and DLT_IEEE802_11_RADIO
(radiotap + 802.11).


# 1.31 28-Dec-2004 dyoung

If defined(RTW_DEBUG), provide a sysctl (hw.rtw.rxbufs_limit) for
limiting the number of rx buffers an rtw may allocate. Use this
sysctl to test the code that copes with buffer exhaustion.

Allocate at most RTW_RXQLEN rx buffers, stopping at the sysctl
limit. Record in sc_nrxdesc how many were allocated, and put the
end-of-ring indication on sc_rxdesc[sc_nrxdesc - 1]. In rtw_init,
if no rx buffers could be allocated, log a complaint, clear
IFF_RUNNING, and exit with an error.

Many changes to accomodate a short rx ring, mainly of the "add a
rx-ring length argument" variety. XXX I really should consolidate
all of the rx ring variables in one struct and pass that to the
rx-ring subroutines.

Bug fix: after calling MCLGET, use the (m->m_flags & M_EXT) idiom
to check for success, instead of m != NULL.

Bug fix: at the top of rtw_start, if IFF_RUNNING is not set, or
IFF_OACTIVE is, get out.


# 1.30 27-Dec-2004 dyoung

Use a table to convert the hardware's bit rates (0, 1, 2, 3) to
net80211 bit rates (2, 4, 11, 22).

Count input errors (if_ierrors++) for "DMA error/FIFO overflow"
and unknown bit rate.


# 1.29 27-Dec-2004 dyoung

Simplify the reset we do on a transmit timeout. Really, this could
be as simple as rtw_stop(, 0), rtw_init().


# 1.28 27-Dec-2004 mycroft

Use the last descriptor to count collisions and failed transmissions, too.


# 1.27 27-Dec-2004 mycroft

When checking if a split packet is completed, check the *last* segment, not
the first. Otherwise we can overwrite parts of the TX ring that we shouldn't.

Kluge the basic rate setting for now.

Minor simplification to the dequeueing logic.


# 1.26 27-Dec-2004 dyoung

Remove useless debug sysctls.

For AP scanning, change the channel dwell time from 1 second to
1/5 second.


# 1.25 27-Dec-2004 mycroft

Replace d_plcp_svc with d_residue. The latter is the number of whole
empty/unused octets to fill out the data time slot. The value is constrained
by math to 0 for <= 5.5Mb, 0-1 for 11Mb, and 0-2 for 22Mb. It is used to
signal to the MAC that there is residue.


# 1.24 26-Dec-2004 dyoung

Make rtw(4) build w/o RTW_DEBUG. Thanks to Charles Hannum for
pointing out my oversight.


# 1.23 25-Dec-2004 dyoung

The rx descriptor ring bug happens quite often, so printf'ing
occurrences is annoying. Only printf about it when rtw_debug
contains RTW_DEBUG_BUG.


# 1.22 25-Dec-2004 dyoung

IMPORTANT: set m->m_pkthdr.rcvif on rx'd packets. Illegal memory
references abound without this fix.

In rtw_intr_rx, skip to the next rx packet earlier if the rx packet
length is too short.

Also in rtw_intr_rx, if a packet is rx'd with unknown rate, printf
a warning, drop the packet, recycle the rx buffer, skip to next rx
packet.


# 1.21 25-Dec-2004 dyoung

Change rtw_debug from a debug level to a debug mask. Add a lot of
debug flags.

From Linux: handle an RTL8180 bug. Sometimes the NIC skips from
the middle of the ring to the 0th rx descriptor. Now the driver
resynchronizes.

Handle a receive descriptor underrun or Rx FIFO overflow condition
in the way that the Linux driver does. This kind of seems like
overkill, but whatever.

Protect rtw_ioctl with splnet().

Do not load a tx descriptor with a buffer shorter than 4 bytes.

Handle a transmit timeout less disruptively.


# 1.20 23-Dec-2004 dyoung

Oops, straggler from last commit: set the 802.11 Duration field
with the result from ieee80211_compute_duration.


# 1.19 23-Dec-2004 dyoung

Fix a bug in ieee80211_compute_duration: the 802.11 Duration field
in an 802.11 unicast data packet is equal to the duration of the
SIFS and Acknowledgement. That is, the amount of time reserved
*after* the packet has finished transmitting.

Change the arguments to ieee80211_compute_duration: pass the entire
packet length, not just the payload length. Add a 'debug' argument
to ieee80211_compute_duration and its helper subroutine,
ieee80211_compute_duration1.

If debug != 0, ieee80211_compute_duration printfs its arguments
and several local variables.

In rtw(4), load the 802.11 Duration field with the result from
ieee80211_compute_duration.


# 1.18 23-Dec-2004 dyoung

Bug fix: in rtw_rxbuf_alloc, unload the previous mbuf chain before
loading the new chain.


# 1.17 23-Dec-2004 dyoung

DMA-synchronize the Rx buffers before re-initializing them.
XXX not necessary?


# 1.16 23-Dec-2004 dyoung

Add more comprehensive debug messages as we setup transmit descriptors.
Also, dump packets if IFF_DEBUG|IFF_LINK2. Factor out a subroutine
for printing transmit-descriptor debug messages.


# 1.15 23-Dec-2004 dyoung

Disable interrupts and stop transmit DMA before disabling the
transmitter and receiver.


# 1.14 23-Dec-2004 dyoung

Shorten variables, s/txctl/ctl/. This is rtw_start, after all:
transmission is implied.


# 1.13 23-Dec-2004 dyoung

Do not indicate to the NIC that the host has appended the CRC32 to
Tx frames.


# 1.12 23-Dec-2004 dyoung

When we set up the supported rates table, mark 1Mb/s, 2Mb/s as
basic rates.


# 1.11 23-Dec-2004 dyoung

Extract the transmission status from a tx descriptor, and convert
to host byte-order, once.


# 1.10 20-Dec-2004 dyoung

Realtek sample sources are not consistent about the "Digital PHY"
bit in the SROM. It seems as if it is set to 1 when the PHY is
*analog*, not *digital*. Fix my sources.

In rtw_intr_rx, use units of 500kb/s instead of 100kb/s for rate,
to be consistent with net80211's expectations. Polish up some
debugging ugly messages. Dump raw 802.11 packets if IFF_DEBUG|IFF_LINK2
and RTW_DEBUG is defined.

Polish power-state (on/sleep/off) handling. Especially improve
support for RFMD (totally untested) and Maxim. For Philips, take
the Digital PHY property into account.

Call the net80211 watchdog function from rtw_watchdog, so that we
scan again if auth/assoc fails.

Be a little more cautious about writing register[RTW_TPPOLL], since
other drivers are.... Don't frob the high/low-priority queues
right now, since I don't use them.

Add rtw_join_bss which programs the card with the BSSID and other
properties of a BSS. Use it on state transitions. Factor out
rtw_set_nettype.

Make rtw_recv_beacon call ieee80211_recv_mgmt instead of dropping
beacons on the floor! TBD IBSS merges.

Change some rtw_debug=2 printfs to rtw_debug=3 (RTW_DPRINTF3)
printfs so the console doesn't get spammed so badly at rtw_debug=2.
Change some debugging printfs to RTW_DPRINTFs. E.g., print the
"RF programming method" only if debugging is enabled.


# 1.9 20-Dec-2004 dyoung

Fix bug in last commit: use &sc->sc_regs, regs is not defined.


# 1.8 20-Dec-2004 dyoung

Add some bus barriers. Remark where they are needed, e.g.,
read_eeprom.

Change some printfs to RTW_DPRINTF2s to quiet rtw(4) when debugging
is disabled.


# 1.7 20-Dec-2004 dyoung

Get rid of the silly char (*dvname)[IFNAMSIZ] pattern. Replace it
with const char *dvname. I'm not sure what I was thinking.


# 1.6 20-Dec-2004 dyoung

Assert that I'm DMA-syncing a non-negative number of transmit
descriptors.

As I free dirty transmit buffers, move them to the free list, not
back to the dirty list!

Add a 5-second transmit timeout.


# 1.5 19-Dec-2004 dyoung

Add the transmit section of rtw(4): build up and tear down transmit
descriptor rings, move packets from the transmit queues to the
transmit rings, handle transmission-completed interrupts. My
Linksys WPC11 ver. 4 with Maxim RF, generates interrupts like it
is successfully transmitting packets. Clearly there are bugs: my
G4 Powerbook locks up hard. I will debug tomorrow.


# 1.4 13-Dec-2004 dyoung

At last, I have rtw w/ Philips RF receiving packets.

I added some sysctls to aid debugging:

* hw.rtw.debug -- enable debugging

* hw.rtw.flush_rfio -- Linux voodoo: possibly makes the MAC
"flush" bits down the serial bus to the RF

* hw.rtw.host_rfio: force the host to bang bits to the RF, instead
of the MAC banging bits

* hw.rtw.rfio_delay: after telling the MAC to bang bits to the
RF front-end, delay rfio_delay microseconds.

* hw.rtw.rfprog_fallback: there is this notion of the "RF
programming method." I believe the choice influences the
polarity/timing of the serial bus used to program the RF
front-end. I know the correct choice for Intersil/RFMD/Philips
front-ends, only. For all other front-ends, I "fallback" to
rfprog_fallback.

Make rtw_txdac_enable take an rtw_softc argument. I will probably
revert this change.

Add some Linux voodoo to rtw_continuous_tx_enable. I will probably
revert this change.

Important: add rtw_set_rfprog, which sets the correct RF programming
method. This change and the following change are probably responsible
for making the Philips RF work.

Important: RTW_CONFIG1 is an 8-bit register, treat it that way!

Important: RTW_BRSR is 16-bit, RTW_CRCOUNT, RTW_PHYDELAY, and
RTW_MSR are 8-bit: treat them that way!

Vastly simplify rtw_resume_ticks.

Note to self: set the LED state to match the power state.

Hedge against the possibility that RTW_MSR is protected as
RTW_CONFIG[0123] are, meanwhile reworking that section of rtw_init
a little.

Add sc_anaparm, which isn't used, yet....


# 1.3 12-Dec-2004 dyoung

Miscellaneous changes. Details below. Important changes flagged
with []. Using the driver with my Linksys WPC11 ver. 4, it seems
to be receiving packets for a change. The WPC11 ver. 4 has a Maxim
RF section. My no-name rtw with Philips RF section still does not
receive any packets.

Keep access-level (analog params > config[0123] registers > none)
in sc_access. Add rtw_set_access for changing the access level.

Make rtw_continuous_tx_enable and other subroutines use rtw_set_access
instead of rtw_config0123_enable and rtw_anaparm_enable.

Factor part of the chip-reset code into rtw_chip_reset1.

Change the 'struct foo (*bar)[N]'-style arguments to
'struct foo *bar'-style arguments.

Consolidate software/hardware Tx/Rx ring setup in rtw_hwring_setup,
rtw_swring_setup.

Add a new constant, SA2400_OPMODE_DEFAULTS, for the bits that we
*always* set in the SA2400 OPMODE register.

Factor some code out into rtw_sa2400_calibrate. (Inspired by the
Linux driver.)

[] When the receiver goes into underrun/overflow state, call a new
subroutine, rtw_kick() that stops the Rx/Tx processes, resets
the chip, reinitializes the Tx/Rx rings, and restarts Rx/Tx
processes. (Inspired by the Linux driver.)

[] In rtw_intr_rx, check for too-short packets before calling
ieee80211_find_rxnode. I believe this will prevent a repeat of
the MCHK exception I saw once on macppc.

[] Use seconds-elapased as well as microseconds-elapsed to set the
next "due date" for the timeout interrupt. This keeps the driver
from programming the timeout to expire too early.

[] In rtw_intr, read RTW_ISR at most 10 times, then get out. If
the interface is not enabled (RTW_F_ENABLED), then get out.

[] In rtw_stop, get out if the interface is not enabled (RTW_F_ENABLED).
Block IPL_NET interrupts. Don't read/write any registers if
the interface is invalid (RTW_F_INVALID).

[] Call rtw_stop in rtw_detach.


Revision tags: kent-audio1-base
# 1.2 30-Oct-2004 thorpej

When adding/deleting multicast addresses, only whack the address
filter if the interface is marked RUNNING.

Fixes kern/27678.


# 1.1 26-Sep-2004 dyoung

branches: 1.1.2;
Add work-in-progress driver rtw(4) for Realtek RTL8180 MAC/baseband.

Add register definitions for Maxim MAX2820 and Philips SA2400 radio
front-ends.


Revision tags: isaki-audio2-base
# 1.130 05-Feb-2019 msaitoh

Remove very old IFF_NOTRAILERS flag.


# 1.129 03-Feb-2019 mrg

- add or adjust /* FALLTHROUGH */ where appropriate
- add __unreachable() after functions that can return but won't in
this case, and thus can't be marked __dead easily


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 jdolecek-ncqfixes-base pgoyette-compat-0728 phil-wifi-base
# 1.128 26-Jun-2018 msaitoh

Implement the BPF direction filter (BIOC[GS]DIRECTION). It provides backward
compatibility with BIOC[GS]SEESENT ioctl. The userland interface is the same
as FreeBSD.

This change also fixes a bug that the direction is misunderstand on some
environment by passing the direction to bpf_mtap*() instead of checking
m->m_pkthdr.rcvif.


Revision tags: pgoyette-compat-0625 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base tls-maxphys-base-20171202
# 1.127 23-Oct-2017 msaitoh

branches: 1.127.2;
If if_initialize() failed in the attach function, free resources and return.


Revision tags: matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base
# 1.126 23-May-2017 ozaki-r

branches: 1.126.2;
Apply deferred if_start to more drivers

And annotate some XXX_start as it runs in softint to clarify that
it doesn't need deferred if_start.


Revision tags: prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 nick-nhusb-base-20170204
# 1.125 02-Feb-2017 nonaka

wlan interfaces make interrupt routine running on softint context.

see http://mail-index.netbsd.org/tech-kern/2016/12/06/msg021281.html

tested device:
* ath at pci: AR5212, AR5424
* athn at pci: AR9287
* ipw at pci: 2100BG
* iwi at pci: 2915ABG
* iwm at pci: 3165, 7260, 8260
* iwn at pci: 4945, 6235
* ral at pci: RT2560
* rtwn at pci: RTL8192CE


Revision tags: bouyer-socketcan-base pgoyette-localcount-20170107 nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.124 15-Sep-2016 jdolecek

branches: 1.124.2;
remove last isolated islands using BUS_SPACE_BARRIER_SYNC and
BUS_SPACE_BARRIER_X_BEFORE_X - these were only ever defined for mips and ia64,
and never actually implemented even there


Revision tags: localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907
# 1.123 10-Jun-2016 ozaki-r

branches: 1.123.2;
Introduce m_set_rcvif and m_reset_rcvif

The API is used to set (or reset) a received interface of a mbuf.
They are counterpart of m_get_rcvif, which will come in another
commit, hide internal of rcvif operation, and reduce the diff of
the upcoming change.

No functional change.


Revision tags: nick-nhusb-base-20160529
# 1.122 16-May-2016 ozaki-r

Use M_GETCTX and M_SETCTX instead of open-coding rcvif

No functional change.


Revision tags: netbsd-7-2-RELEASE netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 netbsd-7-0-RELEASE nick-nhusb-base-20150921 netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 nick-nhusb-base-20150606 nick-nhusb-base-20150406 nick-nhusb-base netbsd-7-base yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 rmind-smpnet-nbase rmind-smpnet-base tls-maxphys-base
# 1.121 25-Feb-2014 pooka

branches: 1.121.6;
Ensure that the top level sysctl nodes (kern, vfs, net, ...) exist before
the sysctl link sets are processed, and remove redundancy.

Shaves >13kB off of an amd64 GENERIC, not to mention >1k duplicate
lines of code.


# 1.120 17-Oct-2013 christos

- remove unused variables
- move variables inside ifdef sections
- ifdef notdef unused code
- use __USE for debugging variables


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE yamt-pagecache-tag8 netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 agc-symver-base netbsd-6-1-RC2 netbsd-6-1-RC1 yamt-pagecache-base8 netbsd-6-0-1-RELEASE yamt-pagecache-base7 matt-nb6-plus-nbase yamt-pagecache-base6 netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base10 yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.119 04-Jul-2011 joerg

branches: 1.119.2; 1.119.12; 1.119.16;
Fix memset usage.


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base matt-mips64-premerge-20101231 rmind-uvmplock-base
# 1.118 15-Nov-2010 uebayasi

Socket ioctl definitions need sys/sockio.h.


# 1.117 13-Nov-2010 uebayasi

Don't pull in the whole uvm(9) API to access only PAGE_SIZE and
some other constants. These are provided by sys/param.h now.


Revision tags: uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10 uebayasi-xip-base1
# 1.116 05-Apr-2010 joerg

Push the bpf_ops usage back into bpf.h. Push the common ifp->if_bpf
check into the inline functions as well the fourth argument for
bpf_attach.


# 1.115 15-Mar-2010 dyoung

Make this compile on sparc64:

1 s/next_tick/next_tint/ because next_tick shadows a global on sparc64.

2 Fix the bus-barrier helper routines, which had the tag & handle
swapped (!!). Move the helpers from rtwreg.h to rtwvar.h, and
change RTW_BARRIER() into an inline subroutine called rtw_barrier().


Revision tags: yamt-nfs-mp-base9
# 1.114 24-Feb-2010 dyoung

branches: 1.114.2;
A pointer typedef entails trading too much flexibility to declare const
and non-const types, and the kernel uses both const and non-const
PMF qualifiers and device suspensors, so change the pmf_qual_t and
device_suspensor_t typedefs from "pointers to const" to non-pointer,
non-const types.


Revision tags: uebayasi-xip-base
# 1.113 31-Jan-2010 dyoung

branches: 1.113.2;
Add the missing newline to a verbose autoconf message.


# 1.112 19-Jan-2010 pooka

Redefine bpf linkage through an always present op vector, i.e.
#if NBPFILTER is no longer required in the client. This change
doesn't yet add support for loading bpf as a module, since drivers
can register before bpf is attached. However, callers of bpf can
now be modularized.

Dynamically loadable bpf could probably be done fairly easily with
coordination from the stub driver and the real driver by registering
attachments in the stub before the real driver is loaded and doing
a handoff. ... and I'm not going to ponder the depths of unload
here.

Tested with i386/MONOLITHIC, modified MONOLITHIC without bpf and rump.


# 1.111 08-Jan-2010 dyoung

Expand PMF_FN_* macros.


Revision tags: matt-premerge-20091211 jym-xensuspend-nbase
# 1.110 19-Oct-2009 rmind

Drop 3rd and 4th clauses from David Young's license.
Reviewed and approved by dyoung@ (copyright holder).


# 1.109 16-Sep-2009 dyoung

In pmf(9), improve the implementation of device self-suspension
and make suspension by self, by drvctl(8), and by ACPI system sleep
play nice together. Start solidifying some temporary API changes.

1. Extract a new header file, <sys/device_if.h>, from <sys/device.h> and
#include it from <sys/pmf.h> instead of <sys/device.h> to break the
circular dependency between <sys/device.h> and <sys/pmf.h>.

2. Introduce pmf_qual_t, an aggregate of qualifications on a PMF
suspend/resume call. Start to replace instances of PMF_FN_PROTO,
PMF_FN_ARGS, et cetera, with a pmf_qual_t.

3. Introduce the notion of a "suspensor," an entity that holds a
device in suspension. More than one suspensor may hold a device
at once. A device stays suspended as long as at least one
suspensor holds it. A device resumes when the last suspensor
releases it.

Currently, the kernel defines three suspensors,

3a the system-suspensor: for system suspension, initiated
by 'sysctl -w machdep.sleep_state=3', by lid closure, by
power-button press, et cetera,

3b the drvctl-suspensor: for device suspension by /dev/drvctl
ioctl, e.g., drvctl -S sip0.

3c the system self-suspensor: for device drivers that suspend
themselves and their children. Several drivers for network
interfaces put the network device to sleep while it is not
administratively up, that is, after the kernel calls if_stop(,
1). The self-suspensor should not be used directly. See
the description of suspensor delegates, below.

A suspensor can have one or more "delegates". A suspensor can
release devices that its delegates hold suspended. Right now,
only the system self-suspensor has delegates. For each device
that a self-suspending driver attaches, it creates the device's
self-suspensor, a delegate of the system self-suspensor.

Suspensors stop a system-wide suspend/resume cycle from waking
devices that the operator put to sleep with drvctl before the cycle.
They also help self-suspension to work more simply, safely, and in
accord with expectations.

4. Add the notion of device activation level, devact_level_t,
and a routine for checking the current activation level,
device_activation(). Current activation levels are DEVACT_LEVEL_BUS,
DEVACT_LEVEL_DRIVER, and DEVACT_LEVEL_CLASS, which respectively
indicate that the device's bus is active, that the bus and device are
active, and that the bus, device, and the functions of the device's
class (network, audio) are active.

Suspend/resume calls can be qualified with a devact_level_t.
The power-management framework treats a devact_level_t that
qualifies a device suspension as the device's current activation
level; it only runs hooks to reduce the activation level from
the presumed current level to the fully suspended state. The
framework treats a devact_level_t qualifying device resumption
as the target activation level; it only runs hooks to raise the
activation level to the target.

5. Use pmf_qual_t, devact_level_t, and self-suspensors in several
drivers.

6. Temporarily add an unused power-management workqueue that I will
remove or replace, soon.


Revision tags: yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5 yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 nick-hppapmap-base3 jym-xensuspend-base nick-hppapmap-base
# 1.108 07-Apr-2009 dyoung

Cosmetic: remove some dead code.


# 1.107 02-Apr-2009 dyoung

Add the WEP capability to our net80211 capability flags, since we do
sort of support hardware WEP. Only change the WEP key index in a Tx
descriptor from 0 if the type of our transmit key is _WEP, not _TKIP:
i.e., only if we're really doing WEP crypto in the hardware.

Ignore a watchdog timeout on any Tx ring if we can collect some packets
from that ring. Restart both the receiver and the transmitter when a
watchdog timeout occurs instead of restarting only the transmitter.


Revision tags: nick-hppapmap-base2 haad-dm-base2 haad-nbase2 ad-audiomp2-base haad-dm-base mjf-devfs2-base
# 1.106 12-Nov-2008 ad

branches: 1.106.4;
Remove LKMs and switch to the module framework, pass 1.

Proposed on tech-kern@.


# 1.105 07-Nov-2008 dyoung

*** Summary ***

When a link-layer address changes (e.g., ifconfig ex0 link
02:de:ad:be:ef:02 active), send a gratuitous ARP and/or a Neighbor
Advertisement to update the network-/link-layer address bindings
on our LAN peers.

Refuse a change of ethernet address to the address 00:00:00:00:00:00
or to any multicast/broadcast address. (Thanks matt@.)

Reorder ifnet ioctl operations so that driver ioctls may inherit
the functions of their "class"---ether_ioctl(), fddi_ioctl(), et
cetera---and the class ioctls may inherit from the generic ioctl,
ifioctl_common(), but both driver- and class-ioctls may override
the generic behavior. Make network drivers share more code.

Distinguish a "factory" link-layer address from others for the
purposes of both protecting that address from deletion and computing
EUI64.

Return consistent, appropriate error codes from network drivers.

Improve readability. KNF.

*** Details ***

In if_attach(), always initialize the interface ioctl routine,
ifnet->if_ioctl, if the driver has not already initialized it.
Delete if_ioctl == NULL tests everywhere else, because it cannot
happen.

In the ioctl routines of network interfaces, inherit common ioctl
behaviors by calling either ifioctl_common() or whichever ioctl
routine is appropriate for the class of interface---e.g., ether_ioctl()
for ethernets.

Stop (ab)using SIOCSIFADDR and start to use SIOCINITIFADDR. In
the user->kernel interface, SIOCSIFADDR's argument was an ifreq,
but on the protocol->ifnet interface, SIOCSIFADDR's argument was
an ifaddr. That was confusing, and it would work against me as I
make it possible for a network interface to overload most ioctls.
On the protocol->ifnet interface, replace SIOCSIFADDR with
SIOCINITIFADDR. In ifioctl(), return EPERM if userland tries to
invoke SIOCINITIFADDR.

In ifioctl(), give the interface the first shot at handling most
interface ioctls, and give the protocol the second shot, instead
of the other way around. Finally, let compatibility code (COMPAT_OSOCK)
take a shot.

Pull device initialization out of switch statements under
SIOCINITIFADDR. For example, pull ..._init() out of any switch
statement that looks like this:

switch (...->sa_family) {
case ...:
..._init();
...
break;
...
default:
..._init();
...
break;
}

Rewrite many if-else clauses that handle all permutations of IFF_UP
and IFF_RUNNING to use a switch statement,

switch (x & (IFF_UP|IFF_RUNNING)) {
case 0:
...
break;
case IFF_RUNNING:
...
break;
case IFF_UP:
...
break;
case IFF_UP|IFF_RUNNING:
...
break;
}

unifdef lots of code containing #ifdef FreeBSD, #ifdef NetBSD, and
#ifdef SIOCSIFMTU, especially in fwip(4) and in ndis(4).

In ipw(4), remove an if_set_sadl() call that is out of place.

In nfe(4), reuse the jumbo MTU logic in ether_ioctl().

Let ethernets register a callback for setting h/w state such as
promiscuous mode and the multicast filter in accord with a change
in the if_flags: ether_set_ifflags_cb() registers a callback that
returns ENETRESET if the caller should reset the ethernet by calling
if_init(), 0 on success, != 0 on failure. Pull common code from
ex(4), gem(4), nfe(4), sip(4), tlp(4), vge(4) into ether_ioctl(),
and register if_flags callbacks for those drivers.

Return ENOTTY instead of EINVAL for inappropriate ioctls. In
zyd(4), use ENXIO instead of ENOTTY to indicate that the device is
not any longer attached.

Add to if_set_sadl() a boolean 'factory' argument that indicates
whether a link-layer address was assigned by the factory or some
other source. In a comment, recommend using the factory address
for generating an EUI64, and update in6_get_hw_ifid() to prefer a
factory address to any other link-layer address.

Add a routing message, RTM_LLINFO_UPD, that tells protocols to
update the binding of network-layer addresses to link-layer addresses.
Implement this message in IPv4 and IPv6 by sending a gratuitous
ARP or a neighbor advertisement, respectively. Generate RTM_LLINFO_UPD
messages on a change of an interface's link-layer address.

In ether_ioctl(), do not let SIOCALIFADDR set a link-layer address
that is broadcast/multicast or equal to 00:00:00:00:00:00.

Make ether_ioctl() call ifioctl_common() to handle ioctls that it
does not understand.

In gif(4), initialize if_softc and use it, instead of assuming that
the gif_softc and ifp overlap.

Let ifioctl_common() handle SIOCGIFADDR.

Sprinkle rtcache_invariants(), which checks on DIAGNOSTIC kernels
that certain invariants on a struct route are satisfied.

In agr(4), rewrite agr_ioctl_filter() to be a bit more explicit
about the ioctls that we do not allow on an agr(4) member interface.

bzero -> memset. Delete unnecessary casts to void *. Use
sockaddr_in_init() and sockaddr_in6_init(). Compare pointers with
NULL instead of "testing truth". Replace some instances of (type
*)0 with NULL. Change some K&R prototypes to ANSI C, and join
lines.


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 wrstuden-revivesa-base-1 simonb-wapbl-nbase yamt-pf42-base4 simonb-wapbl-base yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 yamt-nfs-mp-base2 wrstuden-revivesa-base yamt-nfs-mp-base yamt-pf42-base ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 1.104 15-Mar-2008 dyoung

branches: 1.104.4; 1.104.10; 1.104.12;
Cosmetic: make rtw_hw_keysupp() return a bool instead of int. In
rtw_wep_setkeys(), add a debug printf, and move the initialization
of keylen from the for-loop to the declaration.


# 1.103 14-Mar-2008 dyoung

Extract subroutine rtw_tx_kick() from rtw_start(), and reuse it in
rtw_io_enable() to restart the transmitter after resetting it.


# 1.102 14-Mar-2008 dyoung

Change tests for "impossible" keys to KASSERT()s. Get rid of a
temporary variable. In rtw_key_delete(), do not invalidate the
hardware keys unless a WEP key is deleted.


# 1.101 12-Mar-2008 dyoung

Use device_t and its accessors throughout. Use aprint_*_dev().

Improve PMF-ability.

Add a 'flags' argument to suspend/resume handlers and
callers such as pmf_system_suspend().

Define a flag, PMF_F_SELF, which indicates to PMF that a
device is suspending/resuming itself. Add helper routines,
pmf_device_suspend_self(dev) and pmf_device_resume_self(dev),
that call pmf_device_suspend(dev, PMF_F_SELF) and
pmf_device_resume(dev, PMF_F_SELF), respectively. Use
PMF_F_SELF to suspend/resume self in ath(4), audio(4),
rtw(4), and sip(4).

In ath(4) and in rtw(4), replace the icky sc_enable/sc_disable
callbacks, provided by the bus front-end, with
self-suspension/resumption. Also, clean up the bus
front-ends. Make sure that the interrupt handler is
disestablished during suspension. Get rid of driver-private
flags (e.g., RTW_F_ENABLED, ath_softc->sc_invalid); use
device_is_active()/device_has_power() calls, instead.

In the network-class suspend handler, call if_stop(, 0)
instead of if_stop(, 1), because the latter is superfluous
(bus- and driver-suspension hooks will 'disable' the NIC),
and it may cause recursion.

In the network-class resume handler, prevent infinite
recursion through if_init() by getting out early if we are
self-suspending (PMF_F_SELF).

rtw(4) improvements:

Destroy rtw(4) callouts when we detach it. Make rtw at
pci detachable. Print some more information with the "rx
frame too long" warning.

Remove activate() methods:

Get rid of rtw_activate() and ath_activate(). The device
activate() methods are not good for much these days.

Make ath at cardbus resume with crypto functions intact:

Introduce a boolean device property, "pmf-powerdown". If
pmf-powerdown is present and false, it indicates that a
bus back-end should not remove power from a device.

Honor this property in cardbus_child_suspend().

Set this property to 'false' in ath_attach(), since removing
power from an ath at cardbus seems to lobotomize the WPA
crypto engine. XXX Should the pmf-powerdown property
propagate toward the root of the device tree?

Miscellaneous ath(4) changes:

Warn if ath(4) tries to write crypto keys to suspended
hardware.

Reduce differences between FreeBSD and NetBSD in ath(4)
multicast filter setup.

Make ath_printrxbuf() print an rx descriptor's status &
key index, to help debug crypto errors.

Shorten a staircase in ath_ioctl(). Don't check for
ieee80211_ioctl() return code ERESTART, it never happens.


# 1.100 12-Mar-2008 dyoung

Print the TPPoll register when the Tx DMA engine doesn't shut down
in the time we allow.


# 1.99 03-Mar-2008 tsutsui

Explicitly include <sys/device.h> for device_t.


Revision tags: nick-net80211-sync-base vmlocking2-base3 bouyer-xeni386-nbase bouyer-xeni386-base mjf-devfs-base matt-armv6-base hpcarm-cleanup-base
# 1.98 21-Dec-2007 dyoung

branches: 1.98.2; 1.98.6;
Do not embed a struct device in rtw_softc any longer. Register
both pci and cardbus attachments with CFATTACH_DECL_NEW(). Access
the softc through the device_t using device_private().

While I'm here, change a couple of KASSERT()s about the Rx buffer
length to a warning.


# 1.97 20-Dec-2007 dyoung

Remove shutdown hooks. Use KASSERT().


# 1.96 16-Dec-2007 dyoung

Fix a bug I introduced to rtw_chan2txpower() the other night.

Fix a bug in device detachment: change a break statement to a
/*FALLTHROUGH*/ in rtw_detach().


# 1.95 16-Dec-2007 dyoung

Synchronize device detachment with network interrupts. Use the
pmf network class instead of powerhooks.


Revision tags: yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 bouyer-xenamd64-base2 vmlocking-nbase bouyer-xenamd64-base jmcneill-pm-base reinoud-bufcleanup-base
# 1.94 18-Nov-2007 jnemeth

branches: 1.94.2; 1.94.6;
fix 'm' used unitialized


# 1.93 16-Nov-2007 dyoung

Accommodate the variety of RF front-ends when radiotapping frames:
tap only RSSI when there is a Philips RF front-end. Tap both Barker
lock quality and RSSI when there is any other RF front-end.

Provide radiotap listeners a more complete picture of channel
activity:

in promiscuous mode, tap frames who do not pass the CRC32 check.
Flag packets that were received with a short preamble. Ask
the NIC to pass us 802.11 Control frames. Pass frames to
radiotap listeners before stripping the FCS. Re-order operations
in rtw_intr_rx() in order to accomplish all of this, taking
care not to pass a broken packet to net80211!

Do not provide a flags field when tapping xmitted frames.

Assert sane Rx packet lengths. Really should check and drop instead
of KASSERTing. I will revisit this, soon.

Update copyright.


# 1.92 15-Nov-2007 dyoung

Fix order of operations:

rtw_rxdesc_init: before initializing a Rx descriptor's
control word, synchronize the Rx buffer

rtw_start, be paranoid: set the "NIC owns" bit on a Tx
descriptor dead last. Always reinitialize the "next
Tx descriptor" pointer, just in case it got clobbered
somehow.

Let the compiler decide whether to inline rtw_collect_txring or
not.


Revision tags: jmcneill-base
# 1.91 19-Oct-2007 ad

branches: 1.91.2;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h


Revision tags: yamt-x86pmap-base4 yamt-x86pmap-base3 yamt-x86pmap-base2 vmlocking-base
# 1.90 29-Sep-2007 scw

branches: 1.90.2;
s/NPBFILTER/NBPFILTER/ in some #endif comments. No functional change.


Revision tags: nick-csl-alignment-base5 yamt-x86pmap-base matt-mips64-base nick-csl-alignment-base mjf-ufs-trans-base
# 1.89 09-Jul-2007 ad

branches: 1.89.6; 1.89.8; 1.89.10;
Merge some of the less invasive changes from the vmlocking branch:

- kthread, callout, devsw API changes
- select()/poll() improvements
- miscellaneous MT safety improvements


# 1.88 29-May-2007 dyoung

Fix rtw(4) on NetBSD/macppc: use bus_space_write_region_stream_4()
instead of bus_space_write_region_4() to write WEP Rx keys to the
NIC. Thanks macallan@ for detecting the bug and testing the fix.


# 1.87 29-May-2007 dyoung

Cosmetic: simplify a memset() statement, use __arraycount(), and
remove a gratuitous return statement at the end of a void subroutine.


# 1.86 29-May-2007 dyoung

Simplify multicast filter programming, and take care to avoid
gratuitous device resets when the kernel adds/deletes a multicast
address.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base
# 1.85 04-Mar-2007 christos

branches: 1.85.2; 1.85.4;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.


Revision tags: ad-audiomp-base post-newlock2-merge newlock2-nbase newlock2-base
# 1.84 29-Jan-2007 dyoung

branches: 1.84.2;
In rtw_dequeue(), initialize *mp to NULL before anything else, so
that it is either NULL or a valid mbuf. Previously, it was possible
for rtw_dequeue() to exit with 0 before initializing *mp. rtw_start()
would have used whatever trash was in *mp, which would lead to
problems later on.


# 1.83 06-Jan-2007 dyoung

I have made a small change that suppresses "recovery" from (spurious?)
tx timeouts on the beacon queue. The driver's recovery process
badly disrupts the MAC's receiver. This needs a closer look, later.

Every other fix is by Charles M. Hannum. Charles writes:

"With these, the device is quite stable under load, does not experience
xmit timeouts, no longer mysteriously freezes, and does not spew
a lot of garbage. It does, however, continue to get some "tx fifo
underflow"s.

global, SYSCTL_SETUP():
a) Removed unused sysctl variables.

rtw_io_enable():
b) Change rtw_io_enable to take a softc, and make it call
rtw_txring_fixup().
c) Enable the PCI multiple read/write bit.
d) Always reset rdb_next to 0 when starting the receive engine.

rtw_intr_rx():
e) When processing receive packets, store the next pointer in rdb_next
and read it back on the next round, to fix a race condition vs.
rtw_tune() during AP discovery and association.
f) Remove the special "skip to 0th descriptor" code, because it is no
longer needed.

rtw_collect_txring():
g) In the "force" case, stop when we catch up to the hardware xmit
pointer.

rtw_intr_beacon():
h) Resetting tdb_next here looked fishy to me, in light of changes in
rtw_collect_txring(). XXX However, this is the one part I haven't
tested.

rtw_txring_fixup():
i) Add function and line arguments, so we can print out information
about the caller.
j) In addition to reading the hardware pointer, skip over any
additional packets with OWN set -- we may have queued more.

rtw_rxring_fixup():
k) Remove this, because it's completely wrong.

rtw_intr_ioerror():
l) Don't handle receive overruns here; handle them in the normal receive
path. Also changed RTW_INTR_RX and RTW_INTR_IOERROR accordingly.
m) Do not fiddle with CR; the transmit engine is still running just
fine.
n) Do not fiddle with IMR; it was unnecessary.
o) Don't touch the receive engine at all; not necessary now that we're
leaving CR alone.
p) Remove the rtw_do_chip_reset case; it was dangerous and not actually
used.

rtw_intr():
q) Don't mask off ISR bits when we pass down the ISR value; it's not
necessary, and sometimes the other bits useful in debugging output.

rtw_seg_too_short():
r) Don't spew here; the caller will do it if necessary. (Stops spewage
in an expected case.)

rtw_rxdesc_blk:
s) Minor change to make the elements have the same order as txdesc_blk.

general:
t) Added a bunch of debugging output, #ifdef RTW_DIAG, that was useful
while investigating the ring management problems. Also moved
rtw_txring_fixup() into RTW_DIAG, as I believe the transmit pointer
is always kept in sync now, and the function has potential race
conditions.


# 1.82 06-Jan-2007 dyoung

After we examine a rx/tx descriptor and find that it's still owned
by the NIC, re-sync the descriptor so that a cacheline will not
"cover" the NIC's modifications to the descriptor when we next
examine it.

This compiles, but I have not tested it, yet.


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase wrstuden-fixsa-base-1 netbsd-4-0-RELEASE netbsd-4-0-RC5 matt-nb4-arm-base netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 wrstuden-fixsa-base yamt-splraiseipl-base5 yamt-splraiseipl-base4 yamt-splraiseipl-base3 netbsd-4-base
# 1.81 16-Nov-2006 christos

__unused removal on arguments; approved by core.


# 1.80 13-Nov-2006 dyoung

Stop using typeof() in the bit-twiddling macros, per yamt@'s
suggestion. This change requires that I use the __PRIuBITS format
string in atw and rtw, so do that.


Revision tags: yamt-splraiseipl-base2
# 1.79 12-Oct-2006 xtraeme

Use __unused in function arguments where appropiate.


# 1.78 12-Oct-2006 christos

- sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386


# 1.77 24-Sep-2006 jmcneill

Add "name" parameter to powerhook_establish, to aid debugging. No objections
on tech-kern@


Revision tags: yamt-splraiseipl-base yamt-pdpolicy-base9 yamt-pdpolicy-base8 rpaulo-netinet-merge-pcb-base
# 1.76 03-Sep-2006 christos

branches: 1.76.2; 1.76.4;
- comment out impossible comparisons
- remove superfluous if statement


# 1.75 31-Aug-2006 dyoung

Per discussion on tech-kern and tech-userlevel, move the bit-twiddling
macros, __BIT, __BITS, SHIFTIN, SHIFTOUT, and __arraycount() from
lib/libkern/libkern.h to sys/cdefs.h. Add a __-prefix to SHIFTIN
and SHIFTOUT, and add a manual page for the bit-twiddling macros,
bits(3).

Make the __BIT and __BITS macros "widthless," as best I can, by
changing their type to uintmax_t from uint32_t. XXX The manual
page lags this change by a bit.

Define __PRIxBIT and __PRIxBITS printf(3) format strings.


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base7 yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base simonb-timecounters-base
# 1.74 26-May-2006 blymn

Clean up bogus whitespace


Revision tags: yamt-pdpolicy-base5
# 1.73 14-May-2006 christos

branches: 1.73.2;
XXX: GCC uninitialized


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 elad-kernelauth-base
# 1.72 28-Mar-2006 dyoung

Revamp ieee80211_get_rate. Now it does not use the rateset in the
ic->ic_bss, but it uses the rateset in its new ieee80211_node
argument, instead. If the rate is fixed by ic->ic_fixed_rate, but
the fixed rate is not in the node's rateset, choose a reasonable
default: prefer the lowest basic rate or, if there is no basic
rate, prefer the lowest rate, period.

Change a printf complaint to a debug message.

Adapt drivers to suit new ieee80211_get_rate calling convention.

XXX I really need to replace ieee80211_get_rate with a bitrate
XXX adaptation algorithm. Soon, soon....


# 1.71 27-Mar-2006 dyoung

Set the channel frequency and flags in the radiotap headers in
rtw_tune instead of in rtw_start, rtw_intr_rx.


# 1.70 27-Mar-2006 dyoung

Remove unused argument ifflagsp from rtw_dmamap_load_txbuf.


Revision tags: peter-altq-base yamt-pdpolicy-base2
# 1.69 08-Mar-2006 dyoung

branches: 1.69.2;
Change macro names to avoid collisions:

BIT -> __BIT
BITS -> __BITS


# 1.68 08-Mar-2006 dyoung

Move my bit-twiddling macros to libkern.h from my drivers, where
I had duplicated them. Improve the macros' names. Simplify their
implementation.

A brief description of each macro is below.

BIT(n): Return a bitmask with bit m set, where the least
significant bit is bit 0.

BITS(m, n): Return a bitmask with bits m through n, inclusive,
set. It does not matter whether m>n or m<=n.
The least significant bit is bit 0.

A "bitfield" is a span of consecutive bits defined by a
bitmask, where 1s select the bits in the bitfield. SHIFTIN,
SHIFTOUT, and SHIFTOUT_MASK help read and write bitfields
from device registers.

SHIFTIN(v, mask): Left-shift bits `v' into the bitfield
defined by `mask', and return them. No
side-effects.

SHIFTOUT(v, mask): Extract and return the bitfield selected
by `mask' from `v', right-shifting the
bits so that the rightmost selected bit
is at bit 0. No side-effects.

SHIFTOUT_MASK(mask): Right-shift the bits in `mask' so that
the rightmost non-zero bit is at bit
0. This is useful for finding the
greatest unsigned value that a bitfield
can hold. No side-effects. Note that
SHIFTOUT_MASK(m) = SHIFTOUT(m, m).

Examples:

/*
* Register definitions taken from the RFMD RF3000 manual.
*/
#define RF3000_GAINCTL 0x11 /* TX variable gain control */
#define RF3000_GAINCTL_TXVGC_MASK BITS(7, 2)
#define RF3000_GAINCTL_SCRAMBLER BIT(1)

/*
* Shift the transmit power into the transmit-power field of the
* gain-control register and write it to the baseband processor.
*/
atw_rf3000_write(sc, RF3000_GAINCTL,
SHIFTIN(txpower, RF3000_GAINCTL_TXVGC_MASK));


/*
* Register definitions taken from the ADMtek ADM8211 manual.
*
*/
#define ATW_RXSTAT_OWN BIT(31) /* 1: NIC may fill descriptor */
/* ... */
#define ATW_RXSTAT_DA1 BIT(17) /* DA bit 1, admin'd address */
#define ATW_RXSTAT_DA0 BIT(16) /* DA bit 0, group address */
#define ATW_RXSTAT_RXDR_MASK BITS(15,12) /* RX data rate */
#define ATW_RXSTAT_FL_MASK BITS(11,0) /* RX frame length, last
* descriptor only
*/

/* Extract the frame length from the Rx descriptor's
* status field.
*/
len = SHIFTOUT(rxstat, ATW_RXSTAT_FL_MASK);


Revision tags: yamt-pdpolicy-base yamt-uio_vmspace-base5
# 1.67 20-Feb-2006 thorpej

branches: 1.67.2; 1.67.4;
Use device_is_active() rather than testing dv_flags for DVF_ACTIVE
directly.


# 1.66 19-Feb-2006 dyoung

When rtw_enable is called, power may have been removed and re-applied,
so invalidate the WEP key registers to force us to write the keys
back to the hardware.

Revamp key handling: use the hardware WEP engine for 40-bit and
104-bit keys, only; use software WEP for all other key lengths.
Set the hardware key length to the length of the default Tx key,
or if there is no default Tx key, use the length of the longest
WEP key.


# 1.65 04-Feb-2006 dyoung

In rtw_{rx,tx}ring_fixup, do not set the tx/rx ring index to
something out of bounds if we read an invalid pointer form the
hardware. Prevents a panic when an rtw@cardbus is ejected.


# 1.64 29-Dec-2005 dyoung

branches: 1.64.2; 1.64.4; 1.64.6;
Add support for the GCT Semiconductor GRF5101 transceiver/synthesizer.
From OpenBSD.

GCT will not provide any documentation, so there are many magic
numbers in this code.


# 1.63 29-Dec-2005 dyoung

Update rtw(4) for the new IBSS merge idiom, where ieee80211_ibss_merge()
does not return ENETRESET if the driver should change its BSSID,
but it makes a RUN->RUN transition, instead.


# 1.62 29-Dec-2005 dyoung

In atw(4), use ieee80211_compute_duration() to compute IEEE 802.11
Duration and PLCP Length fields, and delete the abominable
atw_frame_setdurs() subroutine.

Make rtw(4) use the new ieee80211_compute_duration() calling
convention.

Add an ieee80211_key argument to ieee80211_compute_duration() and
lightly constify arguments. Get the crypto header length from the
key argument instead of blithely assuming a WEP header. Add some
inline documentation. Account for data padding (IEEE80211_F_DATAPAD).


# 1.61 24-Dec-2005 perry

Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.


# 1.60 13-Dec-2005 dyoung

Fix comments and debug printfs: Tx FIFOs underflow, they don't
overflow.


# 1.59 13-Dec-2005 dyoung

On a transmit FIFO overflow (err, actually an underflow...) reset
both the transmit & receive sections of the MAC.


Revision tags: yamt-readahead-base3 ktrace-lwp-base
# 1.58 23-Nov-2005 dyoung

Miscellaneous Realtek RTL8180L driver improvements:

1 Added new sysctl controls for debugging.

2 Improve detection & support for hardware WEP.

3 Revamp handling of transmit descriptor rings.

4 Reliably IFF_OACTIVE when transmit descriptors are available, to
stop the transmit section of the driver from freezing up.

5 Fix beacon transmission in adhoc and hostap modes. XXX There is
a wart in hostap mode, where beacons are transmitted at 1/2 the
correct rate. Load beacon descriptors when the RTW_INTR_BINT
interrupt arrives; schedule RTW_INTR_BINT 1ms ahead of the target
beacon time.

6 Recover more gracefully from tx/rx errors: avoid
transmitter/receiver/chip resets. Try to re-synchronize software
state with hardware state---e.g., load next descriptor pointer
from hardware.

7 Activate the transmit watchdog timer for beacons as well as other
packets.

8 Introduce rtw_idle() that waits for transmit DMA to finish; call
it before resetting the transmitter.


Revision tags: yamt-readahead-base2
# 1.57 18-Nov-2005 skrll

Adapt drivers to the new net80211(9).

Most of this is from dyoung@. Thanks!


Revision tags: yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base
# 1.56 22-Sep-2005 gdt

branches: 1.56.6;
Make arg of IFQ_SET_READY be &ifp->if_snd, to match all other drivers
and be compilable with altq enabled. Reviewed by dyoung@


# 1.55 07-Sep-2005 dogcow

With the assistance of dyoung, fix the following problems:
* some 8180L cards need a longer time for the srom to initialize; patch
suggested via OpenBSD.
* some cards give '0' for USA, some give '3'; for the meantime, accept both
as being USA locale cards.
* this is RTW, not ATW. :)


# 1.54 06-Sep-2005 dogcow

make rtw.c compile again after the 22-jun-05 net80211 import


# 1.53 11-Jul-2005 dyoung

Add undefined variable 'ic' to rtw_attach.


# 1.52 06-Jul-2005 dyoung

Historically, an(4), ath(4), atw(4), rtw(4), and wi(4) have printed
out their modes and rates at boot. Revert to the historical
behavior.


# 1.51 06-Jul-2005 dyoung

Avoid an unnecessary API difference between NetBSD and FreeBSD:
back out my change to ieee80211_crypto_encap that made it free its
mbuf argument on error. I had thought it was a bug. It was not.
It's the drivers that are broken. Make an(4), atw(4), ipw(4),
iwi(4), ral(4), rtw(4), ural(4), and wi(4) free the mbuf when
ieee80211_crypto_encap returns NULL. Also, return ath(4) to the
way it was---i.e., free the mbuf.

Thanks to Sam Leffler to pointing out my mistake.


# 1.50 28-Jun-2005 dyoung

branches: 1.50.2;
Here is a grotty hack that lets the RTL8180L handle WEP in the
receive direction, while software handles WEP in the transmit
direction. When net80211 calls rtw's rtw_key_set with a WEP key,
I point the key's wk_cipher at our "fake" cipher, rtw_cipher_wep,
which is alike to ieee80211_cipher_wep except it provides a different
crypto-decapsulation routine, rtw_wep_decap. rtw_wep_decap copies
the key passed to it by net80211, clears the key's SWCRYPT flag,
and then calls wep_decap. Now wep_decap will decapsulate, but it
will *not* re-decrypt.

XXX I need to check whether the hardware supports 40-bit WEP,
XXX 104-bit WEP, or both, and act accordingly.


# 1.49 27-Jun-2005 dyoung

rtw: Try to get hardware WEP to work. It seems to work in
the RX direction, but not in the TX direction. The
net80211 crypto framework doesn't seem to cope very well
with the assymetry (I'm probably missing something), so
I will use software WEP for now.

net80211: In ieee80211_compute_duration, figure out whether to add
the WEP header to the packet overhead by checking the
WEP bit in the Frame Control field of the 802.11 header,
instead of checking the IEEE80211_F_PRIVACY flag.

Also, if the WEP bit is present, assume that the frame
described by (wh, len) has already already been WEP
encapsulated, and adjust the payload length accordingly.
XXX that's a grotty hack that I will have to revisit,
later.


# 1.48 22-Jun-2005 dyoung

Resolve conflicts in importation of 18-May-2005 ath(4) / net80211(9)
from FreeBSD. Introduce compatibility shims (sys/dev/ic/ath_netbsd.[ch],
sys/net80211/ieee80211_netbsd.[ch]). Update drivers (an, atu, atw,
awi, ipw, iwi, rtw, wi) for the new net80211(9) API.


# 1.47 20-Jun-2005 atatat

Change the rest of the sysctl subsystem to use const consistently.
The __UNCONST macro is now used only where necessary and the RW macros
are gone. Most of the changes here are consumers of the
sysctl_createv(9) interface that now takes a pair of const pointers
which used not to be.


# 1.46 10-Jun-2005 dyoung

Sprinkle __UNCONST() and rename variables to quiet uiet -Wcast-qual,
-Wshadow complaints.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 yamt-km-base4 yamt-km-base3 netbsd-3-base kent-audio2-base
# 1.45 02-Mar-2005 dyoung

Misc. changes to improve ad hoc mode and to enable hostap mode:

Fix the work-around for the NIC bug where it skips to rx
descriptor 0. The driver used to skip to rx descriptor 1.
Hopefully this stops the out-of-order packet reception that
Charles Hannum saw.
When debugging is enabled, print rx-descriptor status flags
before printing the rx bit rate.

Add a debug message for when a beacon tx buffer reclamation.

Reset IFF_OACTIVE when we reset the transmitter.

Pass the consolidated LED state, a struct rtw_led_state,
to rtw_led_attach.

Choose the bit-rate for management frames (1Mb/s) at the
same place we choose for all other frames.

Do not use the NIC's short preamble or RTS options for
management frames. Label beacons for the NIC.

Following a Linux driver, take care not to zero arbitrary
bits in the TPPOLL register.

Use the new idiom for IBSS merges: disable transmitter,
kick the state machine.
Add a second descriptor to the beacon ring. The NIC seems
to like this much better.


# 1.44 27-Feb-2005 perry

nuke trailing whitespace


Revision tags: yamt-km-base2
# 1.43 31-Jan-2005 thorpej

Eliminate use of M_HASFCS.


Revision tags: yamt-km-base
# 1.42 16-Jan-2005 dyoung

branches: 1.42.2; 1.42.4;
Move the register access mode into struct rtw_regs. Change
rtw_set_access, rtw_set_access1 to match.

Add a subroutine for setting WEP keys. WEP isn't quite finished,
because I have to add the WEP header to Tx packets. Implement the
SIOCS80211NWKEY ioctl for setting WEP keys.

Program the LEDs based on operating state and packet activity.

* On a Revision F RTL8180, blink LED1 at 1Hz to indicate
scan/authenticate/associate states. In the run state, turn LED1
on. In every state, blink LED1 at 5Hz to indicate non-beacon
tx/rx activity. I would like to use two LEDs, but in all my
Rev. F instances, LED0 is not wired to an LED; instead, the
first LED is wired to indicate that the card's power is on.

* On a Revision D RTL8180, program the LEDs so that LED0 indicates
Tx, and LED1 indicates Rx. The Rx LED will blink annoyingly if
there are beacons in the air, but at least the Tx LED is useful.

* Store the hardware revision in the softc to support my futile
attempt at programming LEDs for both Rev. D and Rev. F parts;
I never did get Rev. D LEDs to work right.

* Add a debug flag RTW_DEBUG_LED for the LED transitions.

Add RTW_TPPOLL_ALL, RTW_TPPOLL_SALL to start and stop, respectively,
all of the transmit rings.

In ad hoc mode, allocate a beacon and load it into the beacon ring.
Start the ring. In one trial, the card re-transmitted the beacon
ring's contents several times before stopping. More programming
and testing for ad hoc mode is necessary. I'm not setting the
beacon flag in the transmit descriptor.

Revamp the transmit section to make better use of all the transmit
rings: beacon queue, high-, low-, and medium-priority rings. Put
beacon frames on the beacon ring. All other management frames,
and data frames, go on the medium-priority ring. Power-save data
frames go on the high-priority ring. (Note that powersaving is
not implemented!) This is a work in progress.

Send all 802.11 Management frames at 1Mbps.

After we put a packet on a transmit ring, tickle the right bit in
the TPPOLL to tell RTL8180. Stop all rings on error and in rtw_stop.

Use the RF chip type, not the RTL8180 revision, to choose between
host- and MAC-controlled RF serial I/O. Now the Netgear MA521
works.

Remove bogus definition of bit RTW_TPPOLL_FSWINT.


Revision tags: kent-audio1-beforemerge
# 1.41 04-Jan-2005 dyoung

Set initial conditions to guarantee that when read_seeprom toggles
Chip Select, it turns *on* rather than *off*.


# 1.40 04-Jan-2005 dyoung

Add the logic for IBSS merges.


# 1.39 03-Jan-2005 dyoung

sys/dev/ic/rtw.c:

Cosmetic: remove two short ladders from rtw_init. Fit the
NIC registers print-out onto one line using the RTW_PRINT_REGS
macro.

sys/dev/ic/rtwvar.h:

Add RTW_PRINT_REGS wrapper macro for rtw_print_regs. It
is a null op unless defined(RTW_DEBUG).


# 1.38 03-Jan-2005 dyoung

In sys/dev/ic/rtw.c:

Use clue from rtk(4) and re(4) to fix the rtw(4) packet
filter. Previously, I was using the wrong CRC32 function
to hash multicast addresses; to compensate, I set the
multicast filter to all 1s. Now that I hash the addresses
correctly, I do not any longer set the filter to all 1s.

In rtw_ioctl, avoid gratuitous re-initialization when the
interface flags change. If a !IFF_UP -> IFF_UP transition,
call rtw_init(); otherwise, only reload the packet filter.

In sys/dev/ic/rtwreg.h:

Put useful combinations of Receiver Control Register flags
in RTW_RCR_PKTFILT_MASK, RTW_RCR_MONITOR, and
RTW_RCR_PKTFILT_DEFAULT. (XXX RTW_RCR_MONITOR should be
called RTW_RCR_PKTFILT_MONITOR.)


# 1.37 02-Jan-2005 dyoung

Cosmetic: change u_int{8,16,32,64}_t to C99-style uint{8,16,32,64}_t,
which is preferred.


# 1.36 29-Dec-2004 dyoung

In rtw_detach, flag the rtw as "invalid" (RTW_F_INVALID). Do not
try to power-down the RF section of an invalid rtw.

The radiotap signal quality field is 16, not 8, bits wide. Convert
the byte order.


# 1.35 29-Dec-2004 dyoung

Remove some dead code.


# 1.34 29-Dec-2004 dyoung

I like the tlp/atw-style names for software descriptors, txsoft,
better than txctl. Change from rtw_txctl/rtw_rxctl to
rtw_txsoft/rtw_rxsoft. Change the descriptor blocks' names to
match: rtw_txctl_blk becomes rtw_txsoft_blk. Change the member-name
prefixes for both software and hardware descriptors.


# 1.33 29-Dec-2004 dyoung

Consolidate variables related to the rx ring in sc_rxdesc_blk,
which is a struct rtw_rxdesc_blk.

Put a copy of the DMA tag and the DMA map into the rx- and tx-ring
blocks so that I don't have to pass them to subroutines all of the
time.


# 1.32 28-Dec-2004 dyoung

Add bpf(4) packet taps to rtw(4). Now you can tap DLT_EN10MB
(Ethernet II), DLT_IEEE802_11 (802.11), and DLT_IEEE802_11_RADIO
(radiotap + 802.11).


# 1.31 28-Dec-2004 dyoung

If defined(RTW_DEBUG), provide a sysctl (hw.rtw.rxbufs_limit) for
limiting the number of rx buffers an rtw may allocate. Use this
sysctl to test the code that copes with buffer exhaustion.

Allocate at most RTW_RXQLEN rx buffers, stopping at the sysctl
limit. Record in sc_nrxdesc how many were allocated, and put the
end-of-ring indication on sc_rxdesc[sc_nrxdesc - 1]. In rtw_init,
if no rx buffers could be allocated, log a complaint, clear
IFF_RUNNING, and exit with an error.

Many changes to accomodate a short rx ring, mainly of the "add a
rx-ring length argument" variety. XXX I really should consolidate
all of the rx ring variables in one struct and pass that to the
rx-ring subroutines.

Bug fix: after calling MCLGET, use the (m->m_flags & M_EXT) idiom
to check for success, instead of m != NULL.

Bug fix: at the top of rtw_start, if IFF_RUNNING is not set, or
IFF_OACTIVE is, get out.


# 1.30 27-Dec-2004 dyoung

Use a table to convert the hardware's bit rates (0, 1, 2, 3) to
net80211 bit rates (2, 4, 11, 22).

Count input errors (if_ierrors++) for "DMA error/FIFO overflow"
and unknown bit rate.


# 1.29 27-Dec-2004 dyoung

Simplify the reset we do on a transmit timeout. Really, this could
be as simple as rtw_stop(, 0), rtw_init().


# 1.28 27-Dec-2004 mycroft

Use the last descriptor to count collisions and failed transmissions, too.


# 1.27 27-Dec-2004 mycroft

When checking if a split packet is completed, check the *last* segment, not
the first. Otherwise we can overwrite parts of the TX ring that we shouldn't.

Kluge the basic rate setting for now.

Minor simplification to the dequeueing logic.


# 1.26 27-Dec-2004 dyoung

Remove useless debug sysctls.

For AP scanning, change the channel dwell time from 1 second to
1/5 second.


# 1.25 27-Dec-2004 mycroft

Replace d_plcp_svc with d_residue. The latter is the number of whole
empty/unused octets to fill out the data time slot. The value is constrained
by math to 0 for <= 5.5Mb, 0-1 for 11Mb, and 0-2 for 22Mb. It is used to
signal to the MAC that there is residue.


# 1.24 26-Dec-2004 dyoung

Make rtw(4) build w/o RTW_DEBUG. Thanks to Charles Hannum for
pointing out my oversight.


# 1.23 25-Dec-2004 dyoung

The rx descriptor ring bug happens quite often, so printf'ing
occurrences is annoying. Only printf about it when rtw_debug
contains RTW_DEBUG_BUG.


# 1.22 25-Dec-2004 dyoung

IMPORTANT: set m->m_pkthdr.rcvif on rx'd packets. Illegal memory
references abound without this fix.

In rtw_intr_rx, skip to the next rx packet earlier if the rx packet
length is too short.

Also in rtw_intr_rx, if a packet is rx'd with unknown rate, printf
a warning, drop the packet, recycle the rx buffer, skip to next rx
packet.


# 1.21 25-Dec-2004 dyoung

Change rtw_debug from a debug level to a debug mask. Add a lot of
debug flags.

From Linux: handle an RTL8180 bug. Sometimes the NIC skips from
the middle of the ring to the 0th rx descriptor. Now the driver
resynchronizes.

Handle a receive descriptor underrun or Rx FIFO overflow condition
in the way that the Linux driver does. This kind of seems like
overkill, but whatever.

Protect rtw_ioctl with splnet().

Do not load a tx descriptor with a buffer shorter than 4 bytes.

Handle a transmit timeout less disruptively.


# 1.20 23-Dec-2004 dyoung

Oops, straggler from last commit: set the 802.11 Duration field
with the result from ieee80211_compute_duration.


# 1.19 23-Dec-2004 dyoung

Fix a bug in ieee80211_compute_duration: the 802.11 Duration field
in an 802.11 unicast data packet is equal to the duration of the
SIFS and Acknowledgement. That is, the amount of time reserved
*after* the packet has finished transmitting.

Change the arguments to ieee80211_compute_duration: pass the entire
packet length, not just the payload length. Add a 'debug' argument
to ieee80211_compute_duration and its helper subroutine,
ieee80211_compute_duration1.

If debug != 0, ieee80211_compute_duration printfs its arguments
and several local variables.

In rtw(4), load the 802.11 Duration field with the result from
ieee80211_compute_duration.


# 1.18 23-Dec-2004 dyoung

Bug fix: in rtw_rxbuf_alloc, unload the previous mbuf chain before
loading the new chain.


# 1.17 23-Dec-2004 dyoung

DMA-synchronize the Rx buffers before re-initializing them.
XXX not necessary?


# 1.16 23-Dec-2004 dyoung

Add more comprehensive debug messages as we setup transmit descriptors.
Also, dump packets if IFF_DEBUG|IFF_LINK2. Factor out a subroutine
for printing transmit-descriptor debug messages.


# 1.15 23-Dec-2004 dyoung

Disable interrupts and stop transmit DMA before disabling the
transmitter and receiver.


# 1.14 23-Dec-2004 dyoung

Shorten variables, s/txctl/ctl/. This is rtw_start, after all:
transmission is implied.


# 1.13 23-Dec-2004 dyoung

Do not indicate to the NIC that the host has appended the CRC32 to
Tx frames.


# 1.12 23-Dec-2004 dyoung

When we set up the supported rates table, mark 1Mb/s, 2Mb/s as
basic rates.


# 1.11 23-Dec-2004 dyoung

Extract the transmission status from a tx descriptor, and convert
to host byte-order, once.


# 1.10 20-Dec-2004 dyoung

Realtek sample sources are not consistent about the "Digital PHY"
bit in the SROM. It seems as if it is set to 1 when the PHY is
*analog*, not *digital*. Fix my sources.

In rtw_intr_rx, use units of 500kb/s instead of 100kb/s for rate,
to be consistent with net80211's expectations. Polish up some
debugging ugly messages. Dump raw 802.11 packets if IFF_DEBUG|IFF_LINK2
and RTW_DEBUG is defined.

Polish power-state (on/sleep/off) handling. Especially improve
support for RFMD (totally untested) and Maxim. For Philips, take
the Digital PHY property into account.

Call the net80211 watchdog function from rtw_watchdog, so that we
scan again if auth/assoc fails.

Be a little more cautious about writing register[RTW_TPPOLL], since
other drivers are.... Don't frob the high/low-priority queues
right now, since I don't use them.

Add rtw_join_bss which programs the card with the BSSID and other
properties of a BSS. Use it on state transitions. Factor out
rtw_set_nettype.

Make rtw_recv_beacon call ieee80211_recv_mgmt instead of dropping
beacons on the floor! TBD IBSS merges.

Change some rtw_debug=2 printfs to rtw_debug=3 (RTW_DPRINTF3)
printfs so the console doesn't get spammed so badly at rtw_debug=2.
Change some debugging printfs to RTW_DPRINTFs. E.g., print the
"RF programming method" only if debugging is enabled.


# 1.9 20-Dec-2004 dyoung

Fix bug in last commit: use &sc->sc_regs, regs is not defined.


# 1.8 20-Dec-2004 dyoung

Add some bus barriers. Remark where they are needed, e.g.,
read_eeprom.

Change some printfs to RTW_DPRINTF2s to quiet rtw(4) when debugging
is disabled.


# 1.7 20-Dec-2004 dyoung

Get rid of the silly char (*dvname)[IFNAMSIZ] pattern. Replace it
with const char *dvname. I'm not sure what I was thinking.


# 1.6 20-Dec-2004 dyoung

Assert that I'm DMA-syncing a non-negative number of transmit
descriptors.

As I free dirty transmit buffers, move them to the free list, not
back to the dirty list!

Add a 5-second transmit timeout.


# 1.5 19-Dec-2004 dyoung

Add the transmit section of rtw(4): build up and tear down transmit
descriptor rings, move packets from the transmit queues to the
transmit rings, handle transmission-completed interrupts. My
Linksys WPC11 ver. 4 with Maxim RF, generates interrupts like it
is successfully transmitting packets. Clearly there are bugs: my
G4 Powerbook locks up hard. I will debug tomorrow.


# 1.4 13-Dec-2004 dyoung

At last, I have rtw w/ Philips RF receiving packets.

I added some sysctls to aid debugging:

* hw.rtw.debug -- enable debugging

* hw.rtw.flush_rfio -- Linux voodoo: possibly makes the MAC
"flush" bits down the serial bus to the RF

* hw.rtw.host_rfio: force the host to bang bits to the RF, instead
of the MAC banging bits

* hw.rtw.rfio_delay: after telling the MAC to bang bits to the
RF front-end, delay rfio_delay microseconds.

* hw.rtw.rfprog_fallback: there is this notion of the "RF
programming method." I believe the choice influences the
polarity/timing of the serial bus used to program the RF
front-end. I know the correct choice for Intersil/RFMD/Philips
front-ends, only. For all other front-ends, I "fallback" to
rfprog_fallback.

Make rtw_txdac_enable take an rtw_softc argument. I will probably
revert this change.

Add some Linux voodoo to rtw_continuous_tx_enable. I will probably
revert this change.

Important: add rtw_set_rfprog, which sets the correct RF programming
method. This change and the following change are probably responsible
for making the Philips RF work.

Important: RTW_CONFIG1 is an 8-bit register, treat it that way!

Important: RTW_BRSR is 16-bit, RTW_CRCOUNT, RTW_PHYDELAY, and
RTW_MSR are 8-bit: treat them that way!

Vastly simplify rtw_resume_ticks.

Note to self: set the LED state to match the power state.

Hedge against the possibility that RTW_MSR is protected as
RTW_CONFIG[0123] are, meanwhile reworking that section of rtw_init
a little.

Add sc_anaparm, which isn't used, yet....


# 1.3 12-Dec-2004 dyoung

Miscellaneous changes. Details below. Important changes flagged
with []. Using the driver with my Linksys WPC11 ver. 4, it seems
to be receiving packets for a change. The WPC11 ver. 4 has a Maxim
RF section. My no-name rtw with Philips RF section still does not
receive any packets.

Keep access-level (analog params > config[0123] registers > none)
in sc_access. Add rtw_set_access for changing the access level.

Make rtw_continuous_tx_enable and other subroutines use rtw_set_access
instead of rtw_config0123_enable and rtw_anaparm_enable.

Factor part of the chip-reset code into rtw_chip_reset1.

Change the 'struct foo (*bar)[N]'-style arguments to
'struct foo *bar'-style arguments.

Consolidate software/hardware Tx/Rx ring setup in rtw_hwring_setup,
rtw_swring_setup.

Add a new constant, SA2400_OPMODE_DEFAULTS, for the bits that we
*always* set in the SA2400 OPMODE register.

Factor some code out into rtw_sa2400_calibrate. (Inspired by the
Linux driver.)

[] When the receiver goes into underrun/overflow state, call a new
subroutine, rtw_kick() that stops the Rx/Tx processes, resets
the chip, reinitializes the Tx/Rx rings, and restarts Rx/Tx
processes. (Inspired by the Linux driver.)

[] In rtw_intr_rx, check for too-short packets before calling
ieee80211_find_rxnode. I believe this will prevent a repeat of
the MCHK exception I saw once on macppc.

[] Use seconds-elapased as well as microseconds-elapsed to set the
next "due date" for the timeout interrupt. This keeps the driver
from programming the timeout to expire too early.

[] In rtw_intr, read RTW_ISR at most 10 times, then get out. If
the interface is not enabled (RTW_F_ENABLED), then get out.

[] In rtw_stop, get out if the interface is not enabled (RTW_F_ENABLED).
Block IPL_NET interrupts. Don't read/write any registers if
the interface is invalid (RTW_F_INVALID).

[] Call rtw_stop in rtw_detach.


Revision tags: kent-audio1-base
# 1.2 30-Oct-2004 thorpej

When adding/deleting multicast addresses, only whack the address
filter if the interface is marked RUNNING.

Fixes kern/27678.


# 1.1 26-Sep-2004 dyoung

branches: 1.1.2;
Add work-in-progress driver rtw(4) for Realtek RTL8180 MAC/baseband.

Add register definitions for Maxim MAX2820 and Philips SA2400 radio
front-ends.


# 1.127 23-Oct-2017 msaitoh

If if_initialize() failed in the attach function, free resources and return.


Revision tags: matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base
# 1.126 23-May-2017 ozaki-r

Apply deferred if_start to more drivers

And annotate some XXX_start as it runs in softint to clarify that
it doesn't need deferred if_start.


Revision tags: prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 nick-nhusb-base-20170204
# 1.125 02-Feb-2017 nonaka

wlan interfaces make interrupt routine running on softint context.

see http://mail-index.netbsd.org/tech-kern/2016/12/06/msg021281.html

tested device:
* ath at pci: AR5212, AR5424
* athn at pci: AR9287
* ipw at pci: 2100BG
* iwi at pci: 2915ABG
* iwm at pci: 3165, 7260, 8260
* iwn at pci: 4945, 6235
* ral at pci: RT2560
* rtwn at pci: RTL8192CE


Revision tags: bouyer-socketcan-base pgoyette-localcount-20170107 nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.124 15-Sep-2016 jdolecek

branches: 1.124.2;
remove last isolated islands using BUS_SPACE_BARRIER_SYNC and
BUS_SPACE_BARRIER_X_BEFORE_X - these were only ever defined for mips and ia64,
and never actually implemented even there


Revision tags: localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907
# 1.123 10-Jun-2016 ozaki-r

branches: 1.123.2;
Introduce m_set_rcvif and m_reset_rcvif

The API is used to set (or reset) a received interface of a mbuf.
They are counterpart of m_get_rcvif, which will come in another
commit, hide internal of rcvif operation, and reduce the diff of
the upcoming change.

No functional change.


Revision tags: nick-nhusb-base-20160529
# 1.122 16-May-2016 ozaki-r

Use M_GETCTX and M_SETCTX instead of open-coding rcvif

No functional change.


Revision tags: netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 netbsd-7-0-RELEASE nick-nhusb-base-20150921 netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 nick-nhusb-base-20150606 nick-nhusb-base-20150406 nick-nhusb-base netbsd-7-base yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 rmind-smpnet-nbase rmind-smpnet-base tls-maxphys-base
# 1.121 25-Feb-2014 pooka

branches: 1.121.6;
Ensure that the top level sysctl nodes (kern, vfs, net, ...) exist before
the sysctl link sets are processed, and remove redundancy.

Shaves >13kB off of an amd64 GENERIC, not to mention >1k duplicate
lines of code.


# 1.120 17-Oct-2013 christos

- remove unused variables
- move variables inside ifdef sections
- ifdef notdef unused code
- use __USE for debugging variables


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE yamt-pagecache-tag8 netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 agc-symver-base netbsd-6-1-RC2 netbsd-6-1-RC1 yamt-pagecache-base8 netbsd-6-0-1-RELEASE yamt-pagecache-base7 matt-nb6-plus-nbase yamt-pagecache-base6 netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base10 yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.119 04-Jul-2011 joerg

branches: 1.119.2; 1.119.12; 1.119.16;
Fix memset usage.


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base matt-mips64-premerge-20101231 rmind-uvmplock-base
# 1.118 15-Nov-2010 uebayasi

Socket ioctl definitions need sys/sockio.h.


# 1.117 13-Nov-2010 uebayasi

Don't pull in the whole uvm(9) API to access only PAGE_SIZE and
some other constants. These are provided by sys/param.h now.


Revision tags: uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10 uebayasi-xip-base1
# 1.116 05-Apr-2010 joerg

Push the bpf_ops usage back into bpf.h. Push the common ifp->if_bpf
check into the inline functions as well the fourth argument for
bpf_attach.


# 1.115 15-Mar-2010 dyoung

Make this compile on sparc64:

1 s/next_tick/next_tint/ because next_tick shadows a global on sparc64.

2 Fix the bus-barrier helper routines, which had the tag & handle
swapped (!!). Move the helpers from rtwreg.h to rtwvar.h, and
change RTW_BARRIER() into an inline subroutine called rtw_barrier().


Revision tags: yamt-nfs-mp-base9
# 1.114 24-Feb-2010 dyoung

branches: 1.114.2;
A pointer typedef entails trading too much flexibility to declare const
and non-const types, and the kernel uses both const and non-const
PMF qualifiers and device suspensors, so change the pmf_qual_t and
device_suspensor_t typedefs from "pointers to const" to non-pointer,
non-const types.


Revision tags: uebayasi-xip-base
# 1.113 31-Jan-2010 dyoung

branches: 1.113.2;
Add the missing newline to a verbose autoconf message.


# 1.112 19-Jan-2010 pooka

Redefine bpf linkage through an always present op vector, i.e.
#if NBPFILTER is no longer required in the client. This change
doesn't yet add support for loading bpf as a module, since drivers
can register before bpf is attached. However, callers of bpf can
now be modularized.

Dynamically loadable bpf could probably be done fairly easily with
coordination from the stub driver and the real driver by registering
attachments in the stub before the real driver is loaded and doing
a handoff. ... and I'm not going to ponder the depths of unload
here.

Tested with i386/MONOLITHIC, modified MONOLITHIC without bpf and rump.


# 1.111 08-Jan-2010 dyoung

Expand PMF_FN_* macros.


Revision tags: matt-premerge-20091211 jym-xensuspend-nbase
# 1.110 19-Oct-2009 rmind

Drop 3rd and 4th clauses from David Young's license.
Reviewed and approved by dyoung@ (copyright holder).


# 1.109 16-Sep-2009 dyoung

In pmf(9), improve the implementation of device self-suspension
and make suspension by self, by drvctl(8), and by ACPI system sleep
play nice together. Start solidifying some temporary API changes.

1. Extract a new header file, <sys/device_if.h>, from <sys/device.h> and
#include it from <sys/pmf.h> instead of <sys/device.h> to break the
circular dependency between <sys/device.h> and <sys/pmf.h>.

2. Introduce pmf_qual_t, an aggregate of qualifications on a PMF
suspend/resume call. Start to replace instances of PMF_FN_PROTO,
PMF_FN_ARGS, et cetera, with a pmf_qual_t.

3. Introduce the notion of a "suspensor," an entity that holds a
device in suspension. More than one suspensor may hold a device
at once. A device stays suspended as long as at least one
suspensor holds it. A device resumes when the last suspensor
releases it.

Currently, the kernel defines three suspensors,

3a the system-suspensor: for system suspension, initiated
by 'sysctl -w machdep.sleep_state=3', by lid closure, by
power-button press, et cetera,

3b the drvctl-suspensor: for device suspension by /dev/drvctl
ioctl, e.g., drvctl -S sip0.

3c the system self-suspensor: for device drivers that suspend
themselves and their children. Several drivers for network
interfaces put the network device to sleep while it is not
administratively up, that is, after the kernel calls if_stop(,
1). The self-suspensor should not be used directly. See
the description of suspensor delegates, below.

A suspensor can have one or more "delegates". A suspensor can
release devices that its delegates hold suspended. Right now,
only the system self-suspensor has delegates. For each device
that a self-suspending driver attaches, it creates the device's
self-suspensor, a delegate of the system self-suspensor.

Suspensors stop a system-wide suspend/resume cycle from waking
devices that the operator put to sleep with drvctl before the cycle.
They also help self-suspension to work more simply, safely, and in
accord with expectations.

4. Add the notion of device activation level, devact_level_t,
and a routine for checking the current activation level,
device_activation(). Current activation levels are DEVACT_LEVEL_BUS,
DEVACT_LEVEL_DRIVER, and DEVACT_LEVEL_CLASS, which respectively
indicate that the device's bus is active, that the bus and device are
active, and that the bus, device, and the functions of the device's
class (network, audio) are active.

Suspend/resume calls can be qualified with a devact_level_t.
The power-management framework treats a devact_level_t that
qualifies a device suspension as the device's current activation
level; it only runs hooks to reduce the activation level from
the presumed current level to the fully suspended state. The
framework treats a devact_level_t qualifying device resumption
as the target activation level; it only runs hooks to raise the
activation level to the target.

5. Use pmf_qual_t, devact_level_t, and self-suspensors in several
drivers.

6. Temporarily add an unused power-management workqueue that I will
remove or replace, soon.


Revision tags: yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5 yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 nick-hppapmap-base3 jym-xensuspend-base nick-hppapmap-base
# 1.108 07-Apr-2009 dyoung

Cosmetic: remove some dead code.


# 1.107 02-Apr-2009 dyoung

Add the WEP capability to our net80211 capability flags, since we do
sort of support hardware WEP. Only change the WEP key index in a Tx
descriptor from 0 if the type of our transmit key is _WEP, not _TKIP:
i.e., only if we're really doing WEP crypto in the hardware.

Ignore a watchdog timeout on any Tx ring if we can collect some packets
from that ring. Restart both the receiver and the transmitter when a
watchdog timeout occurs instead of restarting only the transmitter.


Revision tags: nick-hppapmap-base2 haad-dm-base2 haad-nbase2 ad-audiomp2-base haad-dm-base mjf-devfs2-base
# 1.106 12-Nov-2008 ad

branches: 1.106.4;
Remove LKMs and switch to the module framework, pass 1.

Proposed on tech-kern@.


# 1.105 07-Nov-2008 dyoung

*** Summary ***

When a link-layer address changes (e.g., ifconfig ex0 link
02:de:ad:be:ef:02 active), send a gratuitous ARP and/or a Neighbor
Advertisement to update the network-/link-layer address bindings
on our LAN peers.

Refuse a change of ethernet address to the address 00:00:00:00:00:00
or to any multicast/broadcast address. (Thanks matt@.)

Reorder ifnet ioctl operations so that driver ioctls may inherit
the functions of their "class"---ether_ioctl(), fddi_ioctl(), et
cetera---and the class ioctls may inherit from the generic ioctl,
ifioctl_common(), but both driver- and class-ioctls may override
the generic behavior. Make network drivers share more code.

Distinguish a "factory" link-layer address from others for the
purposes of both protecting that address from deletion and computing
EUI64.

Return consistent, appropriate error codes from network drivers.

Improve readability. KNF.

*** Details ***

In if_attach(), always initialize the interface ioctl routine,
ifnet->if_ioctl, if the driver has not already initialized it.
Delete if_ioctl == NULL tests everywhere else, because it cannot
happen.

In the ioctl routines of network interfaces, inherit common ioctl
behaviors by calling either ifioctl_common() or whichever ioctl
routine is appropriate for the class of interface---e.g., ether_ioctl()
for ethernets.

Stop (ab)using SIOCSIFADDR and start to use SIOCINITIFADDR. In
the user->kernel interface, SIOCSIFADDR's argument was an ifreq,
but on the protocol->ifnet interface, SIOCSIFADDR's argument was
an ifaddr. That was confusing, and it would work against me as I
make it possible for a network interface to overload most ioctls.
On the protocol->ifnet interface, replace SIOCSIFADDR with
SIOCINITIFADDR. In ifioctl(), return EPERM if userland tries to
invoke SIOCINITIFADDR.

In ifioctl(), give the interface the first shot at handling most
interface ioctls, and give the protocol the second shot, instead
of the other way around. Finally, let compatibility code (COMPAT_OSOCK)
take a shot.

Pull device initialization out of switch statements under
SIOCINITIFADDR. For example, pull ..._init() out of any switch
statement that looks like this:

switch (...->sa_family) {
case ...:
..._init();
...
break;
...
default:
..._init();
...
break;
}

Rewrite many if-else clauses that handle all permutations of IFF_UP
and IFF_RUNNING to use a switch statement,

switch (x & (IFF_UP|IFF_RUNNING)) {
case 0:
...
break;
case IFF_RUNNING:
...
break;
case IFF_UP:
...
break;
case IFF_UP|IFF_RUNNING:
...
break;
}

unifdef lots of code containing #ifdef FreeBSD, #ifdef NetBSD, and
#ifdef SIOCSIFMTU, especially in fwip(4) and in ndis(4).

In ipw(4), remove an if_set_sadl() call that is out of place.

In nfe(4), reuse the jumbo MTU logic in ether_ioctl().

Let ethernets register a callback for setting h/w state such as
promiscuous mode and the multicast filter in accord with a change
in the if_flags: ether_set_ifflags_cb() registers a callback that
returns ENETRESET if the caller should reset the ethernet by calling
if_init(), 0 on success, != 0 on failure. Pull common code from
ex(4), gem(4), nfe(4), sip(4), tlp(4), vge(4) into ether_ioctl(),
and register if_flags callbacks for those drivers.

Return ENOTTY instead of EINVAL for inappropriate ioctls. In
zyd(4), use ENXIO instead of ENOTTY to indicate that the device is
not any longer attached.

Add to if_set_sadl() a boolean 'factory' argument that indicates
whether a link-layer address was assigned by the factory or some
other source. In a comment, recommend using the factory address
for generating an EUI64, and update in6_get_hw_ifid() to prefer a
factory address to any other link-layer address.

Add a routing message, RTM_LLINFO_UPD, that tells protocols to
update the binding of network-layer addresses to link-layer addresses.
Implement this message in IPv4 and IPv6 by sending a gratuitous
ARP or a neighbor advertisement, respectively. Generate RTM_LLINFO_UPD
messages on a change of an interface's link-layer address.

In ether_ioctl(), do not let SIOCALIFADDR set a link-layer address
that is broadcast/multicast or equal to 00:00:00:00:00:00.

Make ether_ioctl() call ifioctl_common() to handle ioctls that it
does not understand.

In gif(4), initialize if_softc and use it, instead of assuming that
the gif_softc and ifp overlap.

Let ifioctl_common() handle SIOCGIFADDR.

Sprinkle rtcache_invariants(), which checks on DIAGNOSTIC kernels
that certain invariants on a struct route are satisfied.

In agr(4), rewrite agr_ioctl_filter() to be a bit more explicit
about the ioctls that we do not allow on an agr(4) member interface.

bzero -> memset. Delete unnecessary casts to void *. Use
sockaddr_in_init() and sockaddr_in6_init(). Compare pointers with
NULL instead of "testing truth". Replace some instances of (type
*)0 with NULL. Change some K&R prototypes to ANSI C, and join
lines.


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 wrstuden-revivesa-base-1 simonb-wapbl-nbase yamt-pf42-base4 simonb-wapbl-base yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 yamt-nfs-mp-base2 wrstuden-revivesa-base yamt-nfs-mp-base yamt-pf42-base ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 1.104 15-Mar-2008 dyoung

branches: 1.104.4; 1.104.10; 1.104.12;
Cosmetic: make rtw_hw_keysupp() return a bool instead of int. In
rtw_wep_setkeys(), add a debug printf, and move the initialization
of keylen from the for-loop to the declaration.


# 1.103 14-Mar-2008 dyoung

Extract subroutine rtw_tx_kick() from rtw_start(), and reuse it in
rtw_io_enable() to restart the transmitter after resetting it.


# 1.102 14-Mar-2008 dyoung

Change tests for "impossible" keys to KASSERT()s. Get rid of a
temporary variable. In rtw_key_delete(), do not invalidate the
hardware keys unless a WEP key is deleted.


# 1.101 12-Mar-2008 dyoung

Use device_t and its accessors throughout. Use aprint_*_dev().

Improve PMF-ability.

Add a 'flags' argument to suspend/resume handlers and
callers such as pmf_system_suspend().

Define a flag, PMF_F_SELF, which indicates to PMF that a
device is suspending/resuming itself. Add helper routines,
pmf_device_suspend_self(dev) and pmf_device_resume_self(dev),
that call pmf_device_suspend(dev, PMF_F_SELF) and
pmf_device_resume(dev, PMF_F_SELF), respectively. Use
PMF_F_SELF to suspend/resume self in ath(4), audio(4),
rtw(4), and sip(4).

In ath(4) and in rtw(4), replace the icky sc_enable/sc_disable
callbacks, provided by the bus front-end, with
self-suspension/resumption. Also, clean up the bus
front-ends. Make sure that the interrupt handler is
disestablished during suspension. Get rid of driver-private
flags (e.g., RTW_F_ENABLED, ath_softc->sc_invalid); use
device_is_active()/device_has_power() calls, instead.

In the network-class suspend handler, call if_stop(, 0)
instead of if_stop(, 1), because the latter is superfluous
(bus- and driver-suspension hooks will 'disable' the NIC),
and it may cause recursion.

In the network-class resume handler, prevent infinite
recursion through if_init() by getting out early if we are
self-suspending (PMF_F_SELF).

rtw(4) improvements:

Destroy rtw(4) callouts when we detach it. Make rtw at
pci detachable. Print some more information with the "rx
frame too long" warning.

Remove activate() methods:

Get rid of rtw_activate() and ath_activate(). The device
activate() methods are not good for much these days.

Make ath at cardbus resume with crypto functions intact:

Introduce a boolean device property, "pmf-powerdown". If
pmf-powerdown is present and false, it indicates that a
bus back-end should not remove power from a device.

Honor this property in cardbus_child_suspend().

Set this property to 'false' in ath_attach(), since removing
power from an ath at cardbus seems to lobotomize the WPA
crypto engine. XXX Should the pmf-powerdown property
propagate toward the root of the device tree?

Miscellaneous ath(4) changes:

Warn if ath(4) tries to write crypto keys to suspended
hardware.

Reduce differences between FreeBSD and NetBSD in ath(4)
multicast filter setup.

Make ath_printrxbuf() print an rx descriptor's status &
key index, to help debug crypto errors.

Shorten a staircase in ath_ioctl(). Don't check for
ieee80211_ioctl() return code ERESTART, it never happens.


# 1.100 12-Mar-2008 dyoung

Print the TPPoll register when the Tx DMA engine doesn't shut down
in the time we allow.


# 1.99 03-Mar-2008 tsutsui

Explicitly include <sys/device.h> for device_t.


Revision tags: nick-net80211-sync-base vmlocking2-base3 bouyer-xeni386-nbase bouyer-xeni386-base mjf-devfs-base matt-armv6-base hpcarm-cleanup-base
# 1.98 21-Dec-2007 dyoung

branches: 1.98.2; 1.98.6;
Do not embed a struct device in rtw_softc any longer. Register
both pci and cardbus attachments with CFATTACH_DECL_NEW(). Access
the softc through the device_t using device_private().

While I'm here, change a couple of KASSERT()s about the Rx buffer
length to a warning.


# 1.97 20-Dec-2007 dyoung

Remove shutdown hooks. Use KASSERT().


# 1.96 16-Dec-2007 dyoung

Fix a bug I introduced to rtw_chan2txpower() the other night.

Fix a bug in device detachment: change a break statement to a
/*FALLTHROUGH*/ in rtw_detach().


# 1.95 16-Dec-2007 dyoung

Synchronize device detachment with network interrupts. Use the
pmf network class instead of powerhooks.


Revision tags: yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 bouyer-xenamd64-base2 vmlocking-nbase bouyer-xenamd64-base jmcneill-pm-base reinoud-bufcleanup-base
# 1.94 18-Nov-2007 jnemeth

branches: 1.94.2; 1.94.6;
fix 'm' used unitialized


# 1.93 16-Nov-2007 dyoung

Accommodate the variety of RF front-ends when radiotapping frames:
tap only RSSI when there is a Philips RF front-end. Tap both Barker
lock quality and RSSI when there is any other RF front-end.

Provide radiotap listeners a more complete picture of channel
activity:

in promiscuous mode, tap frames who do not pass the CRC32 check.
Flag packets that were received with a short preamble. Ask
the NIC to pass us 802.11 Control frames. Pass frames to
radiotap listeners before stripping the FCS. Re-order operations
in rtw_intr_rx() in order to accomplish all of this, taking
care not to pass a broken packet to net80211!

Do not provide a flags field when tapping xmitted frames.

Assert sane Rx packet lengths. Really should check and drop instead
of KASSERTing. I will revisit this, soon.

Update copyright.


# 1.92 15-Nov-2007 dyoung

Fix order of operations:

rtw_rxdesc_init: before initializing a Rx descriptor's
control word, synchronize the Rx buffer

rtw_start, be paranoid: set the "NIC owns" bit on a Tx
descriptor dead last. Always reinitialize the "next
Tx descriptor" pointer, just in case it got clobbered
somehow.

Let the compiler decide whether to inline rtw_collect_txring or
not.


Revision tags: jmcneill-base
# 1.91 19-Oct-2007 ad

branches: 1.91.2;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h


Revision tags: yamt-x86pmap-base4 yamt-x86pmap-base3 yamt-x86pmap-base2 vmlocking-base
# 1.90 29-Sep-2007 scw

branches: 1.90.2;
s/NPBFILTER/NBPFILTER/ in some #endif comments. No functional change.


Revision tags: nick-csl-alignment-base5 yamt-x86pmap-base matt-mips64-base nick-csl-alignment-base mjf-ufs-trans-base
# 1.89 09-Jul-2007 ad

branches: 1.89.6; 1.89.8; 1.89.10;
Merge some of the less invasive changes from the vmlocking branch:

- kthread, callout, devsw API changes
- select()/poll() improvements
- miscellaneous MT safety improvements


# 1.88 29-May-2007 dyoung

Fix rtw(4) on NetBSD/macppc: use bus_space_write_region_stream_4()
instead of bus_space_write_region_4() to write WEP Rx keys to the
NIC. Thanks macallan@ for detecting the bug and testing the fix.


# 1.87 29-May-2007 dyoung

Cosmetic: simplify a memset() statement, use __arraycount(), and
remove a gratuitous return statement at the end of a void subroutine.


# 1.86 29-May-2007 dyoung

Simplify multicast filter programming, and take care to avoid
gratuitous device resets when the kernel adds/deletes a multicast
address.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base
# 1.85 04-Mar-2007 christos

branches: 1.85.2; 1.85.4;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.


Revision tags: ad-audiomp-base post-newlock2-merge newlock2-nbase newlock2-base
# 1.84 29-Jan-2007 dyoung

branches: 1.84.2;
In rtw_dequeue(), initialize *mp to NULL before anything else, so
that it is either NULL or a valid mbuf. Previously, it was possible
for rtw_dequeue() to exit with 0 before initializing *mp. rtw_start()
would have used whatever trash was in *mp, which would lead to
problems later on.


# 1.83 06-Jan-2007 dyoung

I have made a small change that suppresses "recovery" from (spurious?)
tx timeouts on the beacon queue. The driver's recovery process
badly disrupts the MAC's receiver. This needs a closer look, later.

Every other fix is by Charles M. Hannum. Charles writes:

"With these, the device is quite stable under load, does not experience
xmit timeouts, no longer mysteriously freezes, and does not spew
a lot of garbage. It does, however, continue to get some "tx fifo
underflow"s.

global, SYSCTL_SETUP():
a) Removed unused sysctl variables.

rtw_io_enable():
b) Change rtw_io_enable to take a softc, and make it call
rtw_txring_fixup().
c) Enable the PCI multiple read/write bit.
d) Always reset rdb_next to 0 when starting the receive engine.

rtw_intr_rx():
e) When processing receive packets, store the next pointer in rdb_next
and read it back on the next round, to fix a race condition vs.
rtw_tune() during AP discovery and association.
f) Remove the special "skip to 0th descriptor" code, because it is no
longer needed.

rtw_collect_txring():
g) In the "force" case, stop when we catch up to the hardware xmit
pointer.

rtw_intr_beacon():
h) Resetting tdb_next here looked fishy to me, in light of changes in
rtw_collect_txring(). XXX However, this is the one part I haven't
tested.

rtw_txring_fixup():
i) Add function and line arguments, so we can print out information
about the caller.
j) In addition to reading the hardware pointer, skip over any
additional packets with OWN set -- we may have queued more.

rtw_rxring_fixup():
k) Remove this, because it's completely wrong.

rtw_intr_ioerror():
l) Don't handle receive overruns here; handle them in the normal receive
path. Also changed RTW_INTR_RX and RTW_INTR_IOERROR accordingly.
m) Do not fiddle with CR; the transmit engine is still running just
fine.
n) Do not fiddle with IMR; it was unnecessary.
o) Don't touch the receive engine at all; not necessary now that we're
leaving CR alone.
p) Remove the rtw_do_chip_reset case; it was dangerous and not actually
used.

rtw_intr():
q) Don't mask off ISR bits when we pass down the ISR value; it's not
necessary, and sometimes the other bits useful in debugging output.

rtw_seg_too_short():
r) Don't spew here; the caller will do it if necessary. (Stops spewage
in an expected case.)

rtw_rxdesc_blk:
s) Minor change to make the elements have the same order as txdesc_blk.

general:
t) Added a bunch of debugging output, #ifdef RTW_DIAG, that was useful
while investigating the ring management problems. Also moved
rtw_txring_fixup() into RTW_DIAG, as I believe the transmit pointer
is always kept in sync now, and the function has potential race
conditions.


# 1.82 06-Jan-2007 dyoung

After we examine a rx/tx descriptor and find that it's still owned
by the NIC, re-sync the descriptor so that a cacheline will not
"cover" the NIC's modifications to the descriptor when we next
examine it.

This compiles, but I have not tested it, yet.


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase wrstuden-fixsa-base-1 netbsd-4-0-RELEASE netbsd-4-0-RC5 matt-nb4-arm-base netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 wrstuden-fixsa-base yamt-splraiseipl-base5 yamt-splraiseipl-base4 yamt-splraiseipl-base3 netbsd-4-base
# 1.81 16-Nov-2006 christos

__unused removal on arguments; approved by core.


# 1.80 13-Nov-2006 dyoung

Stop using typeof() in the bit-twiddling macros, per yamt@'s
suggestion. This change requires that I use the __PRIuBITS format
string in atw and rtw, so do that.


Revision tags: yamt-splraiseipl-base2
# 1.79 12-Oct-2006 xtraeme

Use __unused in function arguments where appropiate.


# 1.78 12-Oct-2006 christos

- sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386


# 1.77 24-Sep-2006 jmcneill

Add "name" parameter to powerhook_establish, to aid debugging. No objections
on tech-kern@


Revision tags: yamt-splraiseipl-base yamt-pdpolicy-base9 yamt-pdpolicy-base8 rpaulo-netinet-merge-pcb-base
# 1.76 03-Sep-2006 christos

branches: 1.76.2; 1.76.4;
- comment out impossible comparisons
- remove superfluous if statement


# 1.75 31-Aug-2006 dyoung

Per discussion on tech-kern and tech-userlevel, move the bit-twiddling
macros, __BIT, __BITS, SHIFTIN, SHIFTOUT, and __arraycount() from
lib/libkern/libkern.h to sys/cdefs.h. Add a __-prefix to SHIFTIN
and SHIFTOUT, and add a manual page for the bit-twiddling macros,
bits(3).

Make the __BIT and __BITS macros "widthless," as best I can, by
changing their type to uintmax_t from uint32_t. XXX The manual
page lags this change by a bit.

Define __PRIxBIT and __PRIxBITS printf(3) format strings.


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base7 yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base simonb-timecounters-base
# 1.74 26-May-2006 blymn

Clean up bogus whitespace


Revision tags: yamt-pdpolicy-base5
# 1.73 14-May-2006 christos

branches: 1.73.2;
XXX: GCC uninitialized


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 elad-kernelauth-base
# 1.72 28-Mar-2006 dyoung

Revamp ieee80211_get_rate. Now it does not use the rateset in the
ic->ic_bss, but it uses the rateset in its new ieee80211_node
argument, instead. If the rate is fixed by ic->ic_fixed_rate, but
the fixed rate is not in the node's rateset, choose a reasonable
default: prefer the lowest basic rate or, if there is no basic
rate, prefer the lowest rate, period.

Change a printf complaint to a debug message.

Adapt drivers to suit new ieee80211_get_rate calling convention.

XXX I really need to replace ieee80211_get_rate with a bitrate
XXX adaptation algorithm. Soon, soon....


# 1.71 27-Mar-2006 dyoung

Set the channel frequency and flags in the radiotap headers in
rtw_tune instead of in rtw_start, rtw_intr_rx.


# 1.70 27-Mar-2006 dyoung

Remove unused argument ifflagsp from rtw_dmamap_load_txbuf.


Revision tags: peter-altq-base yamt-pdpolicy-base2
# 1.69 08-Mar-2006 dyoung

branches: 1.69.2;
Change macro names to avoid collisions:

BIT -> __BIT
BITS -> __BITS


# 1.68 08-Mar-2006 dyoung

Move my bit-twiddling macros to libkern.h from my drivers, where
I had duplicated them. Improve the macros' names. Simplify their
implementation.

A brief description of each macro is below.

BIT(n): Return a bitmask with bit m set, where the least
significant bit is bit 0.

BITS(m, n): Return a bitmask with bits m through n, inclusive,
set. It does not matter whether m>n or m<=n.
The least significant bit is bit 0.

A "bitfield" is a span of consecutive bits defined by a
bitmask, where 1s select the bits in the bitfield. SHIFTIN,
SHIFTOUT, and SHIFTOUT_MASK help read and write bitfields
from device registers.

SHIFTIN(v, mask): Left-shift bits `v' into the bitfield
defined by `mask', and return them. No
side-effects.

SHIFTOUT(v, mask): Extract and return the bitfield selected
by `mask' from `v', right-shifting the
bits so that the rightmost selected bit
is at bit 0. No side-effects.

SHIFTOUT_MASK(mask): Right-shift the bits in `mask' so that
the rightmost non-zero bit is at bit
0. This is useful for finding the
greatest unsigned value that a bitfield
can hold. No side-effects. Note that
SHIFTOUT_MASK(m) = SHIFTOUT(m, m).

Examples:

/*
* Register definitions taken from the RFMD RF3000 manual.
*/
#define RF3000_GAINCTL 0x11 /* TX variable gain control */
#define RF3000_GAINCTL_TXVGC_MASK BITS(7, 2)
#define RF3000_GAINCTL_SCRAMBLER BIT(1)

/*
* Shift the transmit power into the transmit-power field of the
* gain-control register and write it to the baseband processor.
*/
atw_rf3000_write(sc, RF3000_GAINCTL,
SHIFTIN(txpower, RF3000_GAINCTL_TXVGC_MASK));


/*
* Register definitions taken from the ADMtek ADM8211 manual.
*
*/
#define ATW_RXSTAT_OWN BIT(31) /* 1: NIC may fill descriptor */
/* ... */
#define ATW_RXSTAT_DA1 BIT(17) /* DA bit 1, admin'd address */
#define ATW_RXSTAT_DA0 BIT(16) /* DA bit 0, group address */
#define ATW_RXSTAT_RXDR_MASK BITS(15,12) /* RX data rate */
#define ATW_RXSTAT_FL_MASK BITS(11,0) /* RX frame length, last
* descriptor only
*/

/* Extract the frame length from the Rx descriptor's
* status field.
*/
len = SHIFTOUT(rxstat, ATW_RXSTAT_FL_MASK);


Revision tags: yamt-pdpolicy-base yamt-uio_vmspace-base5
# 1.67 20-Feb-2006 thorpej

branches: 1.67.2; 1.67.4;
Use device_is_active() rather than testing dv_flags for DVF_ACTIVE
directly.


# 1.66 19-Feb-2006 dyoung

When rtw_enable is called, power may have been removed and re-applied,
so invalidate the WEP key registers to force us to write the keys
back to the hardware.

Revamp key handling: use the hardware WEP engine for 40-bit and
104-bit keys, only; use software WEP for all other key lengths.
Set the hardware key length to the length of the default Tx key,
or if there is no default Tx key, use the length of the longest
WEP key.


# 1.65 04-Feb-2006 dyoung

In rtw_{rx,tx}ring_fixup, do not set the tx/rx ring index to
something out of bounds if we read an invalid pointer form the
hardware. Prevents a panic when an rtw@cardbus is ejected.


# 1.64 29-Dec-2005 dyoung

branches: 1.64.2; 1.64.4; 1.64.6;
Add support for the GCT Semiconductor GRF5101 transceiver/synthesizer.
From OpenBSD.

GCT will not provide any documentation, so there are many magic
numbers in this code.


# 1.63 29-Dec-2005 dyoung

Update rtw(4) for the new IBSS merge idiom, where ieee80211_ibss_merge()
does not return ENETRESET if the driver should change its BSSID,
but it makes a RUN->RUN transition, instead.


# 1.62 29-Dec-2005 dyoung

In atw(4), use ieee80211_compute_duration() to compute IEEE 802.11
Duration and PLCP Length fields, and delete the abominable
atw_frame_setdurs() subroutine.

Make rtw(4) use the new ieee80211_compute_duration() calling
convention.

Add an ieee80211_key argument to ieee80211_compute_duration() and
lightly constify arguments. Get the crypto header length from the
key argument instead of blithely assuming a WEP header. Add some
inline documentation. Account for data padding (IEEE80211_F_DATAPAD).


# 1.61 24-Dec-2005 perry

Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.


# 1.60 13-Dec-2005 dyoung

Fix comments and debug printfs: Tx FIFOs underflow, they don't
overflow.


# 1.59 13-Dec-2005 dyoung

On a transmit FIFO overflow (err, actually an underflow...) reset
both the transmit & receive sections of the MAC.


Revision tags: yamt-readahead-base3 ktrace-lwp-base
# 1.58 23-Nov-2005 dyoung

Miscellaneous Realtek RTL8180L driver improvements:

1 Added new sysctl controls for debugging.

2 Improve detection & support for hardware WEP.

3 Revamp handling of transmit descriptor rings.

4 Reliably IFF_OACTIVE when transmit descriptors are available, to
stop the transmit section of the driver from freezing up.

5 Fix beacon transmission in adhoc and hostap modes. XXX There is
a wart in hostap mode, where beacons are transmitted at 1/2 the
correct rate. Load beacon descriptors when the RTW_INTR_BINT
interrupt arrives; schedule RTW_INTR_BINT 1ms ahead of the target
beacon time.

6 Recover more gracefully from tx/rx errors: avoid
transmitter/receiver/chip resets. Try to re-synchronize software
state with hardware state---e.g., load next descriptor pointer
from hardware.

7 Activate the transmit watchdog timer for beacons as well as other
packets.

8 Introduce rtw_idle() that waits for transmit DMA to finish; call
it before resetting the transmitter.


Revision tags: yamt-readahead-base2
# 1.57 18-Nov-2005 skrll

Adapt drivers to the new net80211(9).

Most of this is from dyoung@. Thanks!


Revision tags: yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base
# 1.56 22-Sep-2005 gdt

branches: 1.56.6;
Make arg of IFQ_SET_READY be &ifp->if_snd, to match all other drivers
and be compilable with altq enabled. Reviewed by dyoung@


# 1.55 07-Sep-2005 dogcow

With the assistance of dyoung, fix the following problems:
* some 8180L cards need a longer time for the srom to initialize; patch
suggested via OpenBSD.
* some cards give '0' for USA, some give '3'; for the meantime, accept both
as being USA locale cards.
* this is RTW, not ATW. :)


# 1.54 06-Sep-2005 dogcow

make rtw.c compile again after the 22-jun-05 net80211 import


# 1.53 11-Jul-2005 dyoung

Add undefined variable 'ic' to rtw_attach.


# 1.52 06-Jul-2005 dyoung

Historically, an(4), ath(4), atw(4), rtw(4), and wi(4) have printed
out their modes and rates at boot. Revert to the historical
behavior.


# 1.51 06-Jul-2005 dyoung

Avoid an unnecessary API difference between NetBSD and FreeBSD:
back out my change to ieee80211_crypto_encap that made it free its
mbuf argument on error. I had thought it was a bug. It was not.
It's the drivers that are broken. Make an(4), atw(4), ipw(4),
iwi(4), ral(4), rtw(4), ural(4), and wi(4) free the mbuf when
ieee80211_crypto_encap returns NULL. Also, return ath(4) to the
way it was---i.e., free the mbuf.

Thanks to Sam Leffler to pointing out my mistake.


# 1.50 28-Jun-2005 dyoung

branches: 1.50.2;
Here is a grotty hack that lets the RTL8180L handle WEP in the
receive direction, while software handles WEP in the transmit
direction. When net80211 calls rtw's rtw_key_set with a WEP key,
I point the key's wk_cipher at our "fake" cipher, rtw_cipher_wep,
which is alike to ieee80211_cipher_wep except it provides a different
crypto-decapsulation routine, rtw_wep_decap. rtw_wep_decap copies
the key passed to it by net80211, clears the key's SWCRYPT flag,
and then calls wep_decap. Now wep_decap will decapsulate, but it
will *not* re-decrypt.

XXX I need to check whether the hardware supports 40-bit WEP,
XXX 104-bit WEP, or both, and act accordingly.


# 1.49 27-Jun-2005 dyoung

rtw: Try to get hardware WEP to work. It seems to work in
the RX direction, but not in the TX direction. The
net80211 crypto framework doesn't seem to cope very well
with the assymetry (I'm probably missing something), so
I will use software WEP for now.

net80211: In ieee80211_compute_duration, figure out whether to add
the WEP header to the packet overhead by checking the
WEP bit in the Frame Control field of the 802.11 header,
instead of checking the IEEE80211_F_PRIVACY flag.

Also, if the WEP bit is present, assume that the frame
described by (wh, len) has already already been WEP
encapsulated, and adjust the payload length accordingly.
XXX that's a grotty hack that I will have to revisit,
later.


# 1.48 22-Jun-2005 dyoung

Resolve conflicts in importation of 18-May-2005 ath(4) / net80211(9)
from FreeBSD. Introduce compatibility shims (sys/dev/ic/ath_netbsd.[ch],
sys/net80211/ieee80211_netbsd.[ch]). Update drivers (an, atu, atw,
awi, ipw, iwi, rtw, wi) for the new net80211(9) API.


# 1.47 20-Jun-2005 atatat

Change the rest of the sysctl subsystem to use const consistently.
The __UNCONST macro is now used only where necessary and the RW macros
are gone. Most of the changes here are consumers of the
sysctl_createv(9) interface that now takes a pair of const pointers
which used not to be.


# 1.46 10-Jun-2005 dyoung

Sprinkle __UNCONST() and rename variables to quiet uiet -Wcast-qual,
-Wshadow complaints.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 yamt-km-base4 yamt-km-base3 netbsd-3-base kent-audio2-base
# 1.45 02-Mar-2005 dyoung

Misc. changes to improve ad hoc mode and to enable hostap mode:

Fix the work-around for the NIC bug where it skips to rx
descriptor 0. The driver used to skip to rx descriptor 1.
Hopefully this stops the out-of-order packet reception that
Charles Hannum saw.
When debugging is enabled, print rx-descriptor status flags
before printing the rx bit rate.

Add a debug message for when a beacon tx buffer reclamation.

Reset IFF_OACTIVE when we reset the transmitter.

Pass the consolidated LED state, a struct rtw_led_state,
to rtw_led_attach.

Choose the bit-rate for management frames (1Mb/s) at the
same place we choose for all other frames.

Do not use the NIC's short preamble or RTS options for
management frames. Label beacons for the NIC.

Following a Linux driver, take care not to zero arbitrary
bits in the TPPOLL register.

Use the new idiom for IBSS merges: disable transmitter,
kick the state machine.
Add a second descriptor to the beacon ring. The NIC seems
to like this much better.


# 1.44 27-Feb-2005 perry

nuke trailing whitespace


Revision tags: yamt-km-base2
# 1.43 31-Jan-2005 thorpej

Eliminate use of M_HASFCS.


Revision tags: yamt-km-base
# 1.42 16-Jan-2005 dyoung

branches: 1.42.2; 1.42.4;
Move the register access mode into struct rtw_regs. Change
rtw_set_access, rtw_set_access1 to match.

Add a subroutine for setting WEP keys. WEP isn't quite finished,
because I have to add the WEP header to Tx packets. Implement the
SIOCS80211NWKEY ioctl for setting WEP keys.

Program the LEDs based on operating state and packet activity.

* On a Revision F RTL8180, blink LED1 at 1Hz to indicate
scan/authenticate/associate states. In the run state, turn LED1
on. In every state, blink LED1 at 5Hz to indicate non-beacon
tx/rx activity. I would like to use two LEDs, but in all my
Rev. F instances, LED0 is not wired to an LED; instead, the
first LED is wired to indicate that the card's power is on.

* On a Revision D RTL8180, program the LEDs so that LED0 indicates
Tx, and LED1 indicates Rx. The Rx LED will blink annoyingly if
there are beacons in the air, but at least the Tx LED is useful.

* Store the hardware revision in the softc to support my futile
attempt at programming LEDs for both Rev. D and Rev. F parts;
I never did get Rev. D LEDs to work right.

* Add a debug flag RTW_DEBUG_LED for the LED transitions.

Add RTW_TPPOLL_ALL, RTW_TPPOLL_SALL to start and stop, respectively,
all of the transmit rings.

In ad hoc mode, allocate a beacon and load it into the beacon ring.
Start the ring. In one trial, the card re-transmitted the beacon
ring's contents several times before stopping. More programming
and testing for ad hoc mode is necessary. I'm not setting the
beacon flag in the transmit descriptor.

Revamp the transmit section to make better use of all the transmit
rings: beacon queue, high-, low-, and medium-priority rings. Put
beacon frames on the beacon ring. All other management frames,
and data frames, go on the medium-priority ring. Power-save data
frames go on the high-priority ring. (Note that powersaving is
not implemented!) This is a work in progress.

Send all 802.11 Management frames at 1Mbps.

After we put a packet on a transmit ring, tickle the right bit in
the TPPOLL to tell RTL8180. Stop all rings on error and in rtw_stop.

Use the RF chip type, not the RTL8180 revision, to choose between
host- and MAC-controlled RF serial I/O. Now the Netgear MA521
works.

Remove bogus definition of bit RTW_TPPOLL_FSWINT.


Revision tags: kent-audio1-beforemerge
# 1.41 04-Jan-2005 dyoung

Set initial conditions to guarantee that when read_seeprom toggles
Chip Select, it turns *on* rather than *off*.


# 1.40 04-Jan-2005 dyoung

Add the logic for IBSS merges.


# 1.39 03-Jan-2005 dyoung

sys/dev/ic/rtw.c:

Cosmetic: remove two short ladders from rtw_init. Fit the
NIC registers print-out onto one line using the RTW_PRINT_REGS
macro.

sys/dev/ic/rtwvar.h:

Add RTW_PRINT_REGS wrapper macro for rtw_print_regs. It
is a null op unless defined(RTW_DEBUG).


# 1.38 03-Jan-2005 dyoung

In sys/dev/ic/rtw.c:

Use clue from rtk(4) and re(4) to fix the rtw(4) packet
filter. Previously, I was using the wrong CRC32 function
to hash multicast addresses; to compensate, I set the
multicast filter to all 1s. Now that I hash the addresses
correctly, I do not any longer set the filter to all 1s.

In rtw_ioctl, avoid gratuitous re-initialization when the
interface flags change. If a !IFF_UP -> IFF_UP transition,
call rtw_init(); otherwise, only reload the packet filter.

In sys/dev/ic/rtwreg.h:

Put useful combinations of Receiver Control Register flags
in RTW_RCR_PKTFILT_MASK, RTW_RCR_MONITOR, and
RTW_RCR_PKTFILT_DEFAULT. (XXX RTW_RCR_MONITOR should be
called RTW_RCR_PKTFILT_MONITOR.)


# 1.37 02-Jan-2005 dyoung

Cosmetic: change u_int{8,16,32,64}_t to C99-style uint{8,16,32,64}_t,
which is preferred.


# 1.36 29-Dec-2004 dyoung

In rtw_detach, flag the rtw as "invalid" (RTW_F_INVALID). Do not
try to power-down the RF section of an invalid rtw.

The radiotap signal quality field is 16, not 8, bits wide. Convert
the byte order.


# 1.35 29-Dec-2004 dyoung

Remove some dead code.


# 1.34 29-Dec-2004 dyoung

I like the tlp/atw-style names for software descriptors, txsoft,
better than txctl. Change from rtw_txctl/rtw_rxctl to
rtw_txsoft/rtw_rxsoft. Change the descriptor blocks' names to
match: rtw_txctl_blk becomes rtw_txsoft_blk. Change the member-name
prefixes for both software and hardware descriptors.


# 1.33 29-Dec-2004 dyoung

Consolidate variables related to the rx ring in sc_rxdesc_blk,
which is a struct rtw_rxdesc_blk.

Put a copy of the DMA tag and the DMA map into the rx- and tx-ring
blocks so that I don't have to pass them to subroutines all of the
time.


# 1.32 28-Dec-2004 dyoung

Add bpf(4) packet taps to rtw(4). Now you can tap DLT_EN10MB
(Ethernet II), DLT_IEEE802_11 (802.11), and DLT_IEEE802_11_RADIO
(radiotap + 802.11).


# 1.31 28-Dec-2004 dyoung

If defined(RTW_DEBUG), provide a sysctl (hw.rtw.rxbufs_limit) for
limiting the number of rx buffers an rtw may allocate. Use this
sysctl to test the code that copes with buffer exhaustion.

Allocate at most RTW_RXQLEN rx buffers, stopping at the sysctl
limit. Record in sc_nrxdesc how many were allocated, and put the
end-of-ring indication on sc_rxdesc[sc_nrxdesc - 1]. In rtw_init,
if no rx buffers could be allocated, log a complaint, clear
IFF_RUNNING, and exit with an error.

Many changes to accomodate a short rx ring, mainly of the "add a
rx-ring length argument" variety. XXX I really should consolidate
all of the rx ring variables in one struct and pass that to the
rx-ring subroutines.

Bug fix: after calling MCLGET, use the (m->m_flags & M_EXT) idiom
to check for success, instead of m != NULL.

Bug fix: at the top of rtw_start, if IFF_RUNNING is not set, or
IFF_OACTIVE is, get out.


# 1.30 27-Dec-2004 dyoung

Use a table to convert the hardware's bit rates (0, 1, 2, 3) to
net80211 bit rates (2, 4, 11, 22).

Count input errors (if_ierrors++) for "DMA error/FIFO overflow"
and unknown bit rate.


# 1.29 27-Dec-2004 dyoung

Simplify the reset we do on a transmit timeout. Really, this could
be as simple as rtw_stop(, 0), rtw_init().


# 1.28 27-Dec-2004 mycroft

Use the last descriptor to count collisions and failed transmissions, too.


# 1.27 27-Dec-2004 mycroft

When checking if a split packet is completed, check the *last* segment, not
the first. Otherwise we can overwrite parts of the TX ring that we shouldn't.

Kluge the basic rate setting for now.

Minor simplification to the dequeueing logic.


# 1.26 27-Dec-2004 dyoung

Remove useless debug sysctls.

For AP scanning, change the channel dwell time from 1 second to
1/5 second.


# 1.25 27-Dec-2004 mycroft

Replace d_plcp_svc with d_residue. The latter is the number of whole
empty/unused octets to fill out the data time slot. The value is constrained
by math to 0 for <= 5.5Mb, 0-1 for 11Mb, and 0-2 for 22Mb. It is used to
signal to the MAC that there is residue.


# 1.24 26-Dec-2004 dyoung

Make rtw(4) build w/o RTW_DEBUG. Thanks to Charles Hannum for
pointing out my oversight.


# 1.23 25-Dec-2004 dyoung

The rx descriptor ring bug happens quite often, so printf'ing
occurrences is annoying. Only printf about it when rtw_debug
contains RTW_DEBUG_BUG.


# 1.22 25-Dec-2004 dyoung

IMPORTANT: set m->m_pkthdr.rcvif on rx'd packets. Illegal memory
references abound without this fix.

In rtw_intr_rx, skip to the next rx packet earlier if the rx packet
length is too short.

Also in rtw_intr_rx, if a packet is rx'd with unknown rate, printf
a warning, drop the packet, recycle the rx buffer, skip to next rx
packet.


# 1.21 25-Dec-2004 dyoung

Change rtw_debug from a debug level to a debug mask. Add a lot of
debug flags.

From Linux: handle an RTL8180 bug. Sometimes the NIC skips from
the middle of the ring to the 0th rx descriptor. Now the driver
resynchronizes.

Handle a receive descriptor underrun or Rx FIFO overflow condition
in the way that the Linux driver does. This kind of seems like
overkill, but whatever.

Protect rtw_ioctl with splnet().

Do not load a tx descriptor with a buffer shorter than 4 bytes.

Handle a transmit timeout less disruptively.


# 1.20 23-Dec-2004 dyoung

Oops, straggler from last commit: set the 802.11 Duration field
with the result from ieee80211_compute_duration.


# 1.19 23-Dec-2004 dyoung

Fix a bug in ieee80211_compute_duration: the 802.11 Duration field
in an 802.11 unicast data packet is equal to the duration of the
SIFS and Acknowledgement. That is, the amount of time reserved
*after* the packet has finished transmitting.

Change the arguments to ieee80211_compute_duration: pass the entire
packet length, not just the payload length. Add a 'debug' argument
to ieee80211_compute_duration and its helper subroutine,
ieee80211_compute_duration1.

If debug != 0, ieee80211_compute_duration printfs its arguments
and several local variables.

In rtw(4), load the 802.11 Duration field with the result from
ieee80211_compute_duration.


# 1.18 23-Dec-2004 dyoung

Bug fix: in rtw_rxbuf_alloc, unload the previous mbuf chain before
loading the new chain.


# 1.17 23-Dec-2004 dyoung

DMA-synchronize the Rx buffers before re-initializing them.
XXX not necessary?


# 1.16 23-Dec-2004 dyoung

Add more comprehensive debug messages as we setup transmit descriptors.
Also, dump packets if IFF_DEBUG|IFF_LINK2. Factor out a subroutine
for printing transmit-descriptor debug messages.


# 1.15 23-Dec-2004 dyoung

Disable interrupts and stop transmit DMA before disabling the
transmitter and receiver.


# 1.14 23-Dec-2004 dyoung

Shorten variables, s/txctl/ctl/. This is rtw_start, after all:
transmission is implied.


# 1.13 23-Dec-2004 dyoung

Do not indicate to the NIC that the host has appended the CRC32 to
Tx frames.


# 1.12 23-Dec-2004 dyoung

When we set up the supported rates table, mark 1Mb/s, 2Mb/s as
basic rates.


# 1.11 23-Dec-2004 dyoung

Extract the transmission status from a tx descriptor, and convert
to host byte-order, once.


# 1.10 20-Dec-2004 dyoung

Realtek sample sources are not consistent about the "Digital PHY"
bit in the SROM. It seems as if it is set to 1 when the PHY is
*analog*, not *digital*. Fix my sources.

In rtw_intr_rx, use units of 500kb/s instead of 100kb/s for rate,
to be consistent with net80211's expectations. Polish up some
debugging ugly messages. Dump raw 802.11 packets if IFF_DEBUG|IFF_LINK2
and RTW_DEBUG is defined.

Polish power-state (on/sleep/off) handling. Especially improve
support for RFMD (totally untested) and Maxim. For Philips, take
the Digital PHY property into account.

Call the net80211 watchdog function from rtw_watchdog, so that we
scan again if auth/assoc fails.

Be a little more cautious about writing register[RTW_TPPOLL], since
other drivers are.... Don't frob the high/low-priority queues
right now, since I don't use them.

Add rtw_join_bss which programs the card with the BSSID and other
properties of a BSS. Use it on state transitions. Factor out
rtw_set_nettype.

Make rtw_recv_beacon call ieee80211_recv_mgmt instead of dropping
beacons on the floor! TBD IBSS merges.

Change some rtw_debug=2 printfs to rtw_debug=3 (RTW_DPRINTF3)
printfs so the console doesn't get spammed so badly at rtw_debug=2.
Change some debugging printfs to RTW_DPRINTFs. E.g., print the
"RF programming method" only if debugging is enabled.


# 1.9 20-Dec-2004 dyoung

Fix bug in last commit: use &sc->sc_regs, regs is not defined.


# 1.8 20-Dec-2004 dyoung

Add some bus barriers. Remark where they are needed, e.g.,
read_eeprom.

Change some printfs to RTW_DPRINTF2s to quiet rtw(4) when debugging
is disabled.


# 1.7 20-Dec-2004 dyoung

Get rid of the silly char (*dvname)[IFNAMSIZ] pattern. Replace it
with const char *dvname. I'm not sure what I was thinking.


# 1.6 20-Dec-2004 dyoung

Assert that I'm DMA-syncing a non-negative number of transmit
descriptors.

As I free dirty transmit buffers, move them to the free list, not
back to the dirty list!

Add a 5-second transmit timeout.


# 1.5 19-Dec-2004 dyoung

Add the transmit section of rtw(4): build up and tear down transmit
descriptor rings, move packets from the transmit queues to the
transmit rings, handle transmission-completed interrupts. My
Linksys WPC11 ver. 4 with Maxim RF, generates interrupts like it
is successfully transmitting packets. Clearly there are bugs: my
G4 Powerbook locks up hard. I will debug tomorrow.


# 1.4 13-Dec-2004 dyoung

At last, I have rtw w/ Philips RF receiving packets.

I added some sysctls to aid debugging:

* hw.rtw.debug -- enable debugging

* hw.rtw.flush_rfio -- Linux voodoo: possibly makes the MAC
"flush" bits down the serial bus to the RF

* hw.rtw.host_rfio: force the host to bang bits to the RF, instead
of the MAC banging bits

* hw.rtw.rfio_delay: after telling the MAC to bang bits to the
RF front-end, delay rfio_delay microseconds.

* hw.rtw.rfprog_fallback: there is this notion of the "RF
programming method." I believe the choice influences the
polarity/timing of the serial bus used to program the RF
front-end. I know the correct choice for Intersil/RFMD/Philips
front-ends, only. For all other front-ends, I "fallback" to
rfprog_fallback.

Make rtw_txdac_enable take an rtw_softc argument. I will probably
revert this change.

Add some Linux voodoo to rtw_continuous_tx_enable. I will probably
revert this change.

Important: add rtw_set_rfprog, which sets the correct RF programming
method. This change and the following change are probably responsible
for making the Philips RF work.

Important: RTW_CONFIG1 is an 8-bit register, treat it that way!

Important: RTW_BRSR is 16-bit, RTW_CRCOUNT, RTW_PHYDELAY, and
RTW_MSR are 8-bit: treat them that way!

Vastly simplify rtw_resume_ticks.

Note to self: set the LED state to match the power state.

Hedge against the possibility that RTW_MSR is protected as
RTW_CONFIG[0123] are, meanwhile reworking that section of rtw_init
a little.

Add sc_anaparm, which isn't used, yet....


# 1.3 12-Dec-2004 dyoung

Miscellaneous changes. Details below. Important changes flagged
with []. Using the driver with my Linksys WPC11 ver. 4, it seems
to be receiving packets for a change. The WPC11 ver. 4 has a Maxim
RF section. My no-name rtw with Philips RF section still does not
receive any packets.

Keep access-level (analog params > config[0123] registers > none)
in sc_access. Add rtw_set_access for changing the access level.

Make rtw_continuous_tx_enable and other subroutines use rtw_set_access
instead of rtw_config0123_enable and rtw_anaparm_enable.

Factor part of the chip-reset code into rtw_chip_reset1.

Change the 'struct foo (*bar)[N]'-style arguments to
'struct foo *bar'-style arguments.

Consolidate software/hardware Tx/Rx ring setup in rtw_hwring_setup,
rtw_swring_setup.

Add a new constant, SA2400_OPMODE_DEFAULTS, for the bits that we
*always* set in the SA2400 OPMODE register.

Factor some code out into rtw_sa2400_calibrate. (Inspired by the
Linux driver.)

[] When the receiver goes into underrun/overflow state, call a new
subroutine, rtw_kick() that stops the Rx/Tx processes, resets
the chip, reinitializes the Tx/Rx rings, and restarts Rx/Tx
processes. (Inspired by the Linux driver.)

[] In rtw_intr_rx, check for too-short packets before calling
ieee80211_find_rxnode. I believe this will prevent a repeat of
the MCHK exception I saw once on macppc.

[] Use seconds-elapased as well as microseconds-elapsed to set the
next "due date" for the timeout interrupt. This keeps the driver
from programming the timeout to expire too early.

[] In rtw_intr, read RTW_ISR at most 10 times, then get out. If
the interface is not enabled (RTW_F_ENABLED), then get out.

[] In rtw_stop, get out if the interface is not enabled (RTW_F_ENABLED).
Block IPL_NET interrupts. Don't read/write any registers if
the interface is invalid (RTW_F_INVALID).

[] Call rtw_stop in rtw_detach.


Revision tags: kent-audio1-base
# 1.2 30-Oct-2004 thorpej

When adding/deleting multicast addresses, only whack the address
filter if the interface is marked RUNNING.

Fixes kern/27678.


# 1.1 26-Sep-2004 dyoung

branches: 1.1.2;
Add work-in-progress driver rtw(4) for Realtek RTL8180 MAC/baseband.

Add register definitions for Maxim MAX2820 and Philips SA2400 radio
front-ends.


# 1.126 23-May-2017 ozaki-r

Apply deferred if_start to more drivers

And annotate some XXX_start as it runs in softint to clarify that
it doesn't need deferred if_start.


Revision tags: prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 nick-nhusb-base-20170204
# 1.125 02-Feb-2017 nonaka

wlan interfaces make interrupt routine running on softint context.

see http://mail-index.netbsd.org/tech-kern/2016/12/06/msg021281.html

tested device:
* ath at pci: AR5212, AR5424
* athn at pci: AR9287
* ipw at pci: 2100BG
* iwi at pci: 2915ABG
* iwm at pci: 3165, 7260, 8260
* iwn at pci: 4945, 6235
* ral at pci: RT2560
* rtwn at pci: RTL8192CE


Revision tags: bouyer-socketcan-base pgoyette-localcount-20170107 nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.124 15-Sep-2016 jdolecek

branches: 1.124.2;
remove last isolated islands using BUS_SPACE_BARRIER_SYNC and
BUS_SPACE_BARRIER_X_BEFORE_X - these were only ever defined for mips and ia64,
and never actually implemented even there


Revision tags: localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907
# 1.123 10-Jun-2016 ozaki-r

branches: 1.123.2;
Introduce m_set_rcvif and m_reset_rcvif

The API is used to set (or reset) a received interface of a mbuf.
They are counterpart of m_get_rcvif, which will come in another
commit, hide internal of rcvif operation, and reduce the diff of
the upcoming change.

No functional change.


Revision tags: nick-nhusb-base-20160529
# 1.122 16-May-2016 ozaki-r

Use M_GETCTX and M_SETCTX instead of open-coding rcvif

No functional change.


Revision tags: netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 netbsd-7-0-RELEASE nick-nhusb-base-20150921 netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 nick-nhusb-base-20150606 nick-nhusb-base-20150406 nick-nhusb-base netbsd-7-base yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 rmind-smpnet-nbase rmind-smpnet-base tls-maxphys-base
# 1.121 25-Feb-2014 pooka

branches: 1.121.6;
Ensure that the top level sysctl nodes (kern, vfs, net, ...) exist before
the sysctl link sets are processed, and remove redundancy.

Shaves >13kB off of an amd64 GENERIC, not to mention >1k duplicate
lines of code.


# 1.120 17-Oct-2013 christos

- remove unused variables
- move variables inside ifdef sections
- ifdef notdef unused code
- use __USE for debugging variables


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE yamt-pagecache-tag8 netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 agc-symver-base netbsd-6-1-RC2 netbsd-6-1-RC1 yamt-pagecache-base8 netbsd-6-0-1-RELEASE yamt-pagecache-base7 matt-nb6-plus-nbase yamt-pagecache-base6 netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base10 yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.119 04-Jul-2011 joerg

branches: 1.119.2; 1.119.12; 1.119.16;
Fix memset usage.


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base matt-mips64-premerge-20101231 rmind-uvmplock-base
# 1.118 15-Nov-2010 uebayasi

Socket ioctl definitions need sys/sockio.h.


# 1.117 13-Nov-2010 uebayasi

Don't pull in the whole uvm(9) API to access only PAGE_SIZE and
some other constants. These are provided by sys/param.h now.


Revision tags: uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10 uebayasi-xip-base1
# 1.116 05-Apr-2010 joerg

Push the bpf_ops usage back into bpf.h. Push the common ifp->if_bpf
check into the inline functions as well the fourth argument for
bpf_attach.


# 1.115 15-Mar-2010 dyoung

Make this compile on sparc64:

1 s/next_tick/next_tint/ because next_tick shadows a global on sparc64.

2 Fix the bus-barrier helper routines, which had the tag & handle
swapped (!!). Move the helpers from rtwreg.h to rtwvar.h, and
change RTW_BARRIER() into an inline subroutine called rtw_barrier().


Revision tags: yamt-nfs-mp-base9
# 1.114 24-Feb-2010 dyoung

branches: 1.114.2;
A pointer typedef entails trading too much flexibility to declare const
and non-const types, and the kernel uses both const and non-const
PMF qualifiers and device suspensors, so change the pmf_qual_t and
device_suspensor_t typedefs from "pointers to const" to non-pointer,
non-const types.


Revision tags: uebayasi-xip-base
# 1.113 31-Jan-2010 dyoung

branches: 1.113.2;
Add the missing newline to a verbose autoconf message.


# 1.112 19-Jan-2010 pooka

Redefine bpf linkage through an always present op vector, i.e.
#if NBPFILTER is no longer required in the client. This change
doesn't yet add support for loading bpf as a module, since drivers
can register before bpf is attached. However, callers of bpf can
now be modularized.

Dynamically loadable bpf could probably be done fairly easily with
coordination from the stub driver and the real driver by registering
attachments in the stub before the real driver is loaded and doing
a handoff. ... and I'm not going to ponder the depths of unload
here.

Tested with i386/MONOLITHIC, modified MONOLITHIC without bpf and rump.


# 1.111 08-Jan-2010 dyoung

Expand PMF_FN_* macros.


Revision tags: matt-premerge-20091211 jym-xensuspend-nbase
# 1.110 19-Oct-2009 rmind

Drop 3rd and 4th clauses from David Young's license.
Reviewed and approved by dyoung@ (copyright holder).


# 1.109 16-Sep-2009 dyoung

In pmf(9), improve the implementation of device self-suspension
and make suspension by self, by drvctl(8), and by ACPI system sleep
play nice together. Start solidifying some temporary API changes.

1. Extract a new header file, <sys/device_if.h>, from <sys/device.h> and
#include it from <sys/pmf.h> instead of <sys/device.h> to break the
circular dependency between <sys/device.h> and <sys/pmf.h>.

2. Introduce pmf_qual_t, an aggregate of qualifications on a PMF
suspend/resume call. Start to replace instances of PMF_FN_PROTO,
PMF_FN_ARGS, et cetera, with a pmf_qual_t.

3. Introduce the notion of a "suspensor," an entity that holds a
device in suspension. More than one suspensor may hold a device
at once. A device stays suspended as long as at least one
suspensor holds it. A device resumes when the last suspensor
releases it.

Currently, the kernel defines three suspensors,

3a the system-suspensor: for system suspension, initiated
by 'sysctl -w machdep.sleep_state=3', by lid closure, by
power-button press, et cetera,

3b the drvctl-suspensor: for device suspension by /dev/drvctl
ioctl, e.g., drvctl -S sip0.

3c the system self-suspensor: for device drivers that suspend
themselves and their children. Several drivers for network
interfaces put the network device to sleep while it is not
administratively up, that is, after the kernel calls if_stop(,
1). The self-suspensor should not be used directly. See
the description of suspensor delegates, below.

A suspensor can have one or more "delegates". A suspensor can
release devices that its delegates hold suspended. Right now,
only the system self-suspensor has delegates. For each device
that a self-suspending driver attaches, it creates the device's
self-suspensor, a delegate of the system self-suspensor.

Suspensors stop a system-wide suspend/resume cycle from waking
devices that the operator put to sleep with drvctl before the cycle.
They also help self-suspension to work more simply, safely, and in
accord with expectations.

4. Add the notion of device activation level, devact_level_t,
and a routine for checking the current activation level,
device_activation(). Current activation levels are DEVACT_LEVEL_BUS,
DEVACT_LEVEL_DRIVER, and DEVACT_LEVEL_CLASS, which respectively
indicate that the device's bus is active, that the bus and device are
active, and that the bus, device, and the functions of the device's
class (network, audio) are active.

Suspend/resume calls can be qualified with a devact_level_t.
The power-management framework treats a devact_level_t that
qualifies a device suspension as the device's current activation
level; it only runs hooks to reduce the activation level from
the presumed current level to the fully suspended state. The
framework treats a devact_level_t qualifying device resumption
as the target activation level; it only runs hooks to raise the
activation level to the target.

5. Use pmf_qual_t, devact_level_t, and self-suspensors in several
drivers.

6. Temporarily add an unused power-management workqueue that I will
remove or replace, soon.


Revision tags: yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5 yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 nick-hppapmap-base3 jym-xensuspend-base nick-hppapmap-base
# 1.108 07-Apr-2009 dyoung

Cosmetic: remove some dead code.


# 1.107 02-Apr-2009 dyoung

Add the WEP capability to our net80211 capability flags, since we do
sort of support hardware WEP. Only change the WEP key index in a Tx
descriptor from 0 if the type of our transmit key is _WEP, not _TKIP:
i.e., only if we're really doing WEP crypto in the hardware.

Ignore a watchdog timeout on any Tx ring if we can collect some packets
from that ring. Restart both the receiver and the transmitter when a
watchdog timeout occurs instead of restarting only the transmitter.


Revision tags: nick-hppapmap-base2 haad-dm-base2 haad-nbase2 ad-audiomp2-base haad-dm-base mjf-devfs2-base
# 1.106 12-Nov-2008 ad

branches: 1.106.4;
Remove LKMs and switch to the module framework, pass 1.

Proposed on tech-kern@.


# 1.105 07-Nov-2008 dyoung

*** Summary ***

When a link-layer address changes (e.g., ifconfig ex0 link
02:de:ad:be:ef:02 active), send a gratuitous ARP and/or a Neighbor
Advertisement to update the network-/link-layer address bindings
on our LAN peers.

Refuse a change of ethernet address to the address 00:00:00:00:00:00
or to any multicast/broadcast address. (Thanks matt@.)

Reorder ifnet ioctl operations so that driver ioctls may inherit
the functions of their "class"---ether_ioctl(), fddi_ioctl(), et
cetera---and the class ioctls may inherit from the generic ioctl,
ifioctl_common(), but both driver- and class-ioctls may override
the generic behavior. Make network drivers share more code.

Distinguish a "factory" link-layer address from others for the
purposes of both protecting that address from deletion and computing
EUI64.

Return consistent, appropriate error codes from network drivers.

Improve readability. KNF.

*** Details ***

In if_attach(), always initialize the interface ioctl routine,
ifnet->if_ioctl, if the driver has not already initialized it.
Delete if_ioctl == NULL tests everywhere else, because it cannot
happen.

In the ioctl routines of network interfaces, inherit common ioctl
behaviors by calling either ifioctl_common() or whichever ioctl
routine is appropriate for the class of interface---e.g., ether_ioctl()
for ethernets.

Stop (ab)using SIOCSIFADDR and start to use SIOCINITIFADDR. In
the user->kernel interface, SIOCSIFADDR's argument was an ifreq,
but on the protocol->ifnet interface, SIOCSIFADDR's argument was
an ifaddr. That was confusing, and it would work against me as I
make it possible for a network interface to overload most ioctls.
On the protocol->ifnet interface, replace SIOCSIFADDR with
SIOCINITIFADDR. In ifioctl(), return EPERM if userland tries to
invoke SIOCINITIFADDR.

In ifioctl(), give the interface the first shot at handling most
interface ioctls, and give the protocol the second shot, instead
of the other way around. Finally, let compatibility code (COMPAT_OSOCK)
take a shot.

Pull device initialization out of switch statements under
SIOCINITIFADDR. For example, pull ..._init() out of any switch
statement that looks like this:

switch (...->sa_family) {
case ...:
..._init();
...
break;
...
default:
..._init();
...
break;
}

Rewrite many if-else clauses that handle all permutations of IFF_UP
and IFF_RUNNING to use a switch statement,

switch (x & (IFF_UP|IFF_RUNNING)) {
case 0:
...
break;
case IFF_RUNNING:
...
break;
case IFF_UP:
...
break;
case IFF_UP|IFF_RUNNING:
...
break;
}

unifdef lots of code containing #ifdef FreeBSD, #ifdef NetBSD, and
#ifdef SIOCSIFMTU, especially in fwip(4) and in ndis(4).

In ipw(4), remove an if_set_sadl() call that is out of place.

In nfe(4), reuse the jumbo MTU logic in ether_ioctl().

Let ethernets register a callback for setting h/w state such as
promiscuous mode and the multicast filter in accord with a change
in the if_flags: ether_set_ifflags_cb() registers a callback that
returns ENETRESET if the caller should reset the ethernet by calling
if_init(), 0 on success, != 0 on failure. Pull common code from
ex(4), gem(4), nfe(4), sip(4), tlp(4), vge(4) into ether_ioctl(),
and register if_flags callbacks for those drivers.

Return ENOTTY instead of EINVAL for inappropriate ioctls. In
zyd(4), use ENXIO instead of ENOTTY to indicate that the device is
not any longer attached.

Add to if_set_sadl() a boolean 'factory' argument that indicates
whether a link-layer address was assigned by the factory or some
other source. In a comment, recommend using the factory address
for generating an EUI64, and update in6_get_hw_ifid() to prefer a
factory address to any other link-layer address.

Add a routing message, RTM_LLINFO_UPD, that tells protocols to
update the binding of network-layer addresses to link-layer addresses.
Implement this message in IPv4 and IPv6 by sending a gratuitous
ARP or a neighbor advertisement, respectively. Generate RTM_LLINFO_UPD
messages on a change of an interface's link-layer address.

In ether_ioctl(), do not let SIOCALIFADDR set a link-layer address
that is broadcast/multicast or equal to 00:00:00:00:00:00.

Make ether_ioctl() call ifioctl_common() to handle ioctls that it
does not understand.

In gif(4), initialize if_softc and use it, instead of assuming that
the gif_softc and ifp overlap.

Let ifioctl_common() handle SIOCGIFADDR.

Sprinkle rtcache_invariants(), which checks on DIAGNOSTIC kernels
that certain invariants on a struct route are satisfied.

In agr(4), rewrite agr_ioctl_filter() to be a bit more explicit
about the ioctls that we do not allow on an agr(4) member interface.

bzero -> memset. Delete unnecessary casts to void *. Use
sockaddr_in_init() and sockaddr_in6_init(). Compare pointers with
NULL instead of "testing truth". Replace some instances of (type
*)0 with NULL. Change some K&R prototypes to ANSI C, and join
lines.


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 wrstuden-revivesa-base-1 simonb-wapbl-nbase yamt-pf42-base4 simonb-wapbl-base yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 yamt-nfs-mp-base2 wrstuden-revivesa-base yamt-nfs-mp-base yamt-pf42-base ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 1.104 15-Mar-2008 dyoung

branches: 1.104.4; 1.104.10; 1.104.12;
Cosmetic: make rtw_hw_keysupp() return a bool instead of int. In
rtw_wep_setkeys(), add a debug printf, and move the initialization
of keylen from the for-loop to the declaration.


# 1.103 14-Mar-2008 dyoung

Extract subroutine rtw_tx_kick() from rtw_start(), and reuse it in
rtw_io_enable() to restart the transmitter after resetting it.


# 1.102 14-Mar-2008 dyoung

Change tests for "impossible" keys to KASSERT()s. Get rid of a
temporary variable. In rtw_key_delete(), do not invalidate the
hardware keys unless a WEP key is deleted.


# 1.101 12-Mar-2008 dyoung

Use device_t and its accessors throughout. Use aprint_*_dev().

Improve PMF-ability.

Add a 'flags' argument to suspend/resume handlers and
callers such as pmf_system_suspend().

Define a flag, PMF_F_SELF, which indicates to PMF that a
device is suspending/resuming itself. Add helper routines,
pmf_device_suspend_self(dev) and pmf_device_resume_self(dev),
that call pmf_device_suspend(dev, PMF_F_SELF) and
pmf_device_resume(dev, PMF_F_SELF), respectively. Use
PMF_F_SELF to suspend/resume self in ath(4), audio(4),
rtw(4), and sip(4).

In ath(4) and in rtw(4), replace the icky sc_enable/sc_disable
callbacks, provided by the bus front-end, with
self-suspension/resumption. Also, clean up the bus
front-ends. Make sure that the interrupt handler is
disestablished during suspension. Get rid of driver-private
flags (e.g., RTW_F_ENABLED, ath_softc->sc_invalid); use
device_is_active()/device_has_power() calls, instead.

In the network-class suspend handler, call if_stop(, 0)
instead of if_stop(, 1), because the latter is superfluous
(bus- and driver-suspension hooks will 'disable' the NIC),
and it may cause recursion.

In the network-class resume handler, prevent infinite
recursion through if_init() by getting out early if we are
self-suspending (PMF_F_SELF).

rtw(4) improvements:

Destroy rtw(4) callouts when we detach it. Make rtw at
pci detachable. Print some more information with the "rx
frame too long" warning.

Remove activate() methods:

Get rid of rtw_activate() and ath_activate(). The device
activate() methods are not good for much these days.

Make ath at cardbus resume with crypto functions intact:

Introduce a boolean device property, "pmf-powerdown". If
pmf-powerdown is present and false, it indicates that a
bus back-end should not remove power from a device.

Honor this property in cardbus_child_suspend().

Set this property to 'false' in ath_attach(), since removing
power from an ath at cardbus seems to lobotomize the WPA
crypto engine. XXX Should the pmf-powerdown property
propagate toward the root of the device tree?

Miscellaneous ath(4) changes:

Warn if ath(4) tries to write crypto keys to suspended
hardware.

Reduce differences between FreeBSD and NetBSD in ath(4)
multicast filter setup.

Make ath_printrxbuf() print an rx descriptor's status &
key index, to help debug crypto errors.

Shorten a staircase in ath_ioctl(). Don't check for
ieee80211_ioctl() return code ERESTART, it never happens.


# 1.100 12-Mar-2008 dyoung

Print the TPPoll register when the Tx DMA engine doesn't shut down
in the time we allow.


# 1.99 03-Mar-2008 tsutsui

Explicitly include <sys/device.h> for device_t.


Revision tags: nick-net80211-sync-base vmlocking2-base3 bouyer-xeni386-nbase bouyer-xeni386-base mjf-devfs-base matt-armv6-base hpcarm-cleanup-base
# 1.98 21-Dec-2007 dyoung

branches: 1.98.2; 1.98.6;
Do not embed a struct device in rtw_softc any longer. Register
both pci and cardbus attachments with CFATTACH_DECL_NEW(). Access
the softc through the device_t using device_private().

While I'm here, change a couple of KASSERT()s about the Rx buffer
length to a warning.


# 1.97 20-Dec-2007 dyoung

Remove shutdown hooks. Use KASSERT().


# 1.96 16-Dec-2007 dyoung

Fix a bug I introduced to rtw_chan2txpower() the other night.

Fix a bug in device detachment: change a break statement to a
/*FALLTHROUGH*/ in rtw_detach().


# 1.95 16-Dec-2007 dyoung

Synchronize device detachment with network interrupts. Use the
pmf network class instead of powerhooks.


Revision tags: yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 bouyer-xenamd64-base2 vmlocking-nbase bouyer-xenamd64-base jmcneill-pm-base reinoud-bufcleanup-base
# 1.94 18-Nov-2007 jnemeth

branches: 1.94.2; 1.94.6;
fix 'm' used unitialized


# 1.93 16-Nov-2007 dyoung

Accommodate the variety of RF front-ends when radiotapping frames:
tap only RSSI when there is a Philips RF front-end. Tap both Barker
lock quality and RSSI when there is any other RF front-end.

Provide radiotap listeners a more complete picture of channel
activity:

in promiscuous mode, tap frames who do not pass the CRC32 check.
Flag packets that were received with a short preamble. Ask
the NIC to pass us 802.11 Control frames. Pass frames to
radiotap listeners before stripping the FCS. Re-order operations
in rtw_intr_rx() in order to accomplish all of this, taking
care not to pass a broken packet to net80211!

Do not provide a flags field when tapping xmitted frames.

Assert sane Rx packet lengths. Really should check and drop instead
of KASSERTing. I will revisit this, soon.

Update copyright.


# 1.92 15-Nov-2007 dyoung

Fix order of operations:

rtw_rxdesc_init: before initializing a Rx descriptor's
control word, synchronize the Rx buffer

rtw_start, be paranoid: set the "NIC owns" bit on a Tx
descriptor dead last. Always reinitialize the "next
Tx descriptor" pointer, just in case it got clobbered
somehow.

Let the compiler decide whether to inline rtw_collect_txring or
not.


Revision tags: jmcneill-base
# 1.91 19-Oct-2007 ad

branches: 1.91.2;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h


Revision tags: yamt-x86pmap-base4 yamt-x86pmap-base3 yamt-x86pmap-base2 vmlocking-base
# 1.90 29-Sep-2007 scw

branches: 1.90.2;
s/NPBFILTER/NBPFILTER/ in some #endif comments. No functional change.


Revision tags: nick-csl-alignment-base5 yamt-x86pmap-base matt-mips64-base nick-csl-alignment-base mjf-ufs-trans-base
# 1.89 09-Jul-2007 ad

branches: 1.89.6; 1.89.8; 1.89.10;
Merge some of the less invasive changes from the vmlocking branch:

- kthread, callout, devsw API changes
- select()/poll() improvements
- miscellaneous MT safety improvements


# 1.88 29-May-2007 dyoung

Fix rtw(4) on NetBSD/macppc: use bus_space_write_region_stream_4()
instead of bus_space_write_region_4() to write WEP Rx keys to the
NIC. Thanks macallan@ for detecting the bug and testing the fix.


# 1.87 29-May-2007 dyoung

Cosmetic: simplify a memset() statement, use __arraycount(), and
remove a gratuitous return statement at the end of a void subroutine.


# 1.86 29-May-2007 dyoung

Simplify multicast filter programming, and take care to avoid
gratuitous device resets when the kernel adds/deletes a multicast
address.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base
# 1.85 04-Mar-2007 christos

branches: 1.85.2; 1.85.4;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.


Revision tags: ad-audiomp-base post-newlock2-merge newlock2-nbase newlock2-base
# 1.84 29-Jan-2007 dyoung

branches: 1.84.2;
In rtw_dequeue(), initialize *mp to NULL before anything else, so
that it is either NULL or a valid mbuf. Previously, it was possible
for rtw_dequeue() to exit with 0 before initializing *mp. rtw_start()
would have used whatever trash was in *mp, which would lead to
problems later on.


# 1.83 06-Jan-2007 dyoung

I have made a small change that suppresses "recovery" from (spurious?)
tx timeouts on the beacon queue. The driver's recovery process
badly disrupts the MAC's receiver. This needs a closer look, later.

Every other fix is by Charles M. Hannum. Charles writes:

"With these, the device is quite stable under load, does not experience
xmit timeouts, no longer mysteriously freezes, and does not spew
a lot of garbage. It does, however, continue to get some "tx fifo
underflow"s.

global, SYSCTL_SETUP():
a) Removed unused sysctl variables.

rtw_io_enable():
b) Change rtw_io_enable to take a softc, and make it call
rtw_txring_fixup().
c) Enable the PCI multiple read/write bit.
d) Always reset rdb_next to 0 when starting the receive engine.

rtw_intr_rx():
e) When processing receive packets, store the next pointer in rdb_next
and read it back on the next round, to fix a race condition vs.
rtw_tune() during AP discovery and association.
f) Remove the special "skip to 0th descriptor" code, because it is no
longer needed.

rtw_collect_txring():
g) In the "force" case, stop when we catch up to the hardware xmit
pointer.

rtw_intr_beacon():
h) Resetting tdb_next here looked fishy to me, in light of changes in
rtw_collect_txring(). XXX However, this is the one part I haven't
tested.

rtw_txring_fixup():
i) Add function and line arguments, so we can print out information
about the caller.
j) In addition to reading the hardware pointer, skip over any
additional packets with OWN set -- we may have queued more.

rtw_rxring_fixup():
k) Remove this, because it's completely wrong.

rtw_intr_ioerror():
l) Don't handle receive overruns here; handle them in the normal receive
path. Also changed RTW_INTR_RX and RTW_INTR_IOERROR accordingly.
m) Do not fiddle with CR; the transmit engine is still running just
fine.
n) Do not fiddle with IMR; it was unnecessary.
o) Don't touch the receive engine at all; not necessary now that we're
leaving CR alone.
p) Remove the rtw_do_chip_reset case; it was dangerous and not actually
used.

rtw_intr():
q) Don't mask off ISR bits when we pass down the ISR value; it's not
necessary, and sometimes the other bits useful in debugging output.

rtw_seg_too_short():
r) Don't spew here; the caller will do it if necessary. (Stops spewage
in an expected case.)

rtw_rxdesc_blk:
s) Minor change to make the elements have the same order as txdesc_blk.

general:
t) Added a bunch of debugging output, #ifdef RTW_DIAG, that was useful
while investigating the ring management problems. Also moved
rtw_txring_fixup() into RTW_DIAG, as I believe the transmit pointer
is always kept in sync now, and the function has potential race
conditions.


# 1.82 06-Jan-2007 dyoung

After we examine a rx/tx descriptor and find that it's still owned
by the NIC, re-sync the descriptor so that a cacheline will not
"cover" the NIC's modifications to the descriptor when we next
examine it.

This compiles, but I have not tested it, yet.


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase wrstuden-fixsa-base-1 netbsd-4-0-RELEASE netbsd-4-0-RC5 matt-nb4-arm-base netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 wrstuden-fixsa-base yamt-splraiseipl-base5 yamt-splraiseipl-base4 yamt-splraiseipl-base3 netbsd-4-base
# 1.81 16-Nov-2006 christos

__unused removal on arguments; approved by core.


# 1.80 13-Nov-2006 dyoung

Stop using typeof() in the bit-twiddling macros, per yamt@'s
suggestion. This change requires that I use the __PRIuBITS format
string in atw and rtw, so do that.


Revision tags: yamt-splraiseipl-base2
# 1.79 12-Oct-2006 xtraeme

Use __unused in function arguments where appropiate.


# 1.78 12-Oct-2006 christos

- sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386


# 1.77 24-Sep-2006 jmcneill

Add "name" parameter to powerhook_establish, to aid debugging. No objections
on tech-kern@


Revision tags: yamt-splraiseipl-base yamt-pdpolicy-base9 yamt-pdpolicy-base8 rpaulo-netinet-merge-pcb-base
# 1.76 03-Sep-2006 christos

branches: 1.76.2; 1.76.4;
- comment out impossible comparisons
- remove superfluous if statement


# 1.75 31-Aug-2006 dyoung

Per discussion on tech-kern and tech-userlevel, move the bit-twiddling
macros, __BIT, __BITS, SHIFTIN, SHIFTOUT, and __arraycount() from
lib/libkern/libkern.h to sys/cdefs.h. Add a __-prefix to SHIFTIN
and SHIFTOUT, and add a manual page for the bit-twiddling macros,
bits(3).

Make the __BIT and __BITS macros "widthless," as best I can, by
changing their type to uintmax_t from uint32_t. XXX The manual
page lags this change by a bit.

Define __PRIxBIT and __PRIxBITS printf(3) format strings.


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base7 yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base simonb-timecounters-base
# 1.74 26-May-2006 blymn

Clean up bogus whitespace


Revision tags: yamt-pdpolicy-base5
# 1.73 14-May-2006 christos

branches: 1.73.2;
XXX: GCC uninitialized


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 elad-kernelauth-base
# 1.72 28-Mar-2006 dyoung

Revamp ieee80211_get_rate. Now it does not use the rateset in the
ic->ic_bss, but it uses the rateset in its new ieee80211_node
argument, instead. If the rate is fixed by ic->ic_fixed_rate, but
the fixed rate is not in the node's rateset, choose a reasonable
default: prefer the lowest basic rate or, if there is no basic
rate, prefer the lowest rate, period.

Change a printf complaint to a debug message.

Adapt drivers to suit new ieee80211_get_rate calling convention.

XXX I really need to replace ieee80211_get_rate with a bitrate
XXX adaptation algorithm. Soon, soon....


# 1.71 27-Mar-2006 dyoung

Set the channel frequency and flags in the radiotap headers in
rtw_tune instead of in rtw_start, rtw_intr_rx.


# 1.70 27-Mar-2006 dyoung

Remove unused argument ifflagsp from rtw_dmamap_load_txbuf.


Revision tags: peter-altq-base yamt-pdpolicy-base2
# 1.69 08-Mar-2006 dyoung

branches: 1.69.2;
Change macro names to avoid collisions:

BIT -> __BIT
BITS -> __BITS


# 1.68 08-Mar-2006 dyoung

Move my bit-twiddling macros to libkern.h from my drivers, where
I had duplicated them. Improve the macros' names. Simplify their
implementation.

A brief description of each macro is below.

BIT(n): Return a bitmask with bit m set, where the least
significant bit is bit 0.

BITS(m, n): Return a bitmask with bits m through n, inclusive,
set. It does not matter whether m>n or m<=n.
The least significant bit is bit 0.

A "bitfield" is a span of consecutive bits defined by a
bitmask, where 1s select the bits in the bitfield. SHIFTIN,
SHIFTOUT, and SHIFTOUT_MASK help read and write bitfields
from device registers.

SHIFTIN(v, mask): Left-shift bits `v' into the bitfield
defined by `mask', and return them. No
side-effects.

SHIFTOUT(v, mask): Extract and return the bitfield selected
by `mask' from `v', right-shifting the
bits so that the rightmost selected bit
is at bit 0. No side-effects.

SHIFTOUT_MASK(mask): Right-shift the bits in `mask' so that
the rightmost non-zero bit is at bit
0. This is useful for finding the
greatest unsigned value that a bitfield
can hold. No side-effects. Note that
SHIFTOUT_MASK(m) = SHIFTOUT(m, m).

Examples:

/*
* Register definitions taken from the RFMD RF3000 manual.
*/
#define RF3000_GAINCTL 0x11 /* TX variable gain control */
#define RF3000_GAINCTL_TXVGC_MASK BITS(7, 2)
#define RF3000_GAINCTL_SCRAMBLER BIT(1)

/*
* Shift the transmit power into the transmit-power field of the
* gain-control register and write it to the baseband processor.
*/
atw_rf3000_write(sc, RF3000_GAINCTL,
SHIFTIN(txpower, RF3000_GAINCTL_TXVGC_MASK));


/*
* Register definitions taken from the ADMtek ADM8211 manual.
*
*/
#define ATW_RXSTAT_OWN BIT(31) /* 1: NIC may fill descriptor */
/* ... */
#define ATW_RXSTAT_DA1 BIT(17) /* DA bit 1, admin'd address */
#define ATW_RXSTAT_DA0 BIT(16) /* DA bit 0, group address */
#define ATW_RXSTAT_RXDR_MASK BITS(15,12) /* RX data rate */
#define ATW_RXSTAT_FL_MASK BITS(11,0) /* RX frame length, last
* descriptor only
*/

/* Extract the frame length from the Rx descriptor's
* status field.
*/
len = SHIFTOUT(rxstat, ATW_RXSTAT_FL_MASK);


Revision tags: yamt-pdpolicy-base yamt-uio_vmspace-base5
# 1.67 20-Feb-2006 thorpej

branches: 1.67.2; 1.67.4;
Use device_is_active() rather than testing dv_flags for DVF_ACTIVE
directly.


# 1.66 19-Feb-2006 dyoung

When rtw_enable is called, power may have been removed and re-applied,
so invalidate the WEP key registers to force us to write the keys
back to the hardware.

Revamp key handling: use the hardware WEP engine for 40-bit and
104-bit keys, only; use software WEP for all other key lengths.
Set the hardware key length to the length of the default Tx key,
or if there is no default Tx key, use the length of the longest
WEP key.


# 1.65 04-Feb-2006 dyoung

In rtw_{rx,tx}ring_fixup, do not set the tx/rx ring index to
something out of bounds if we read an invalid pointer form the
hardware. Prevents a panic when an rtw@cardbus is ejected.


# 1.64 29-Dec-2005 dyoung

branches: 1.64.2; 1.64.4; 1.64.6;
Add support for the GCT Semiconductor GRF5101 transceiver/synthesizer.
From OpenBSD.

GCT will not provide any documentation, so there are many magic
numbers in this code.


# 1.63 29-Dec-2005 dyoung

Update rtw(4) for the new IBSS merge idiom, where ieee80211_ibss_merge()
does not return ENETRESET if the driver should change its BSSID,
but it makes a RUN->RUN transition, instead.


# 1.62 29-Dec-2005 dyoung

In atw(4), use ieee80211_compute_duration() to compute IEEE 802.11
Duration and PLCP Length fields, and delete the abominable
atw_frame_setdurs() subroutine.

Make rtw(4) use the new ieee80211_compute_duration() calling
convention.

Add an ieee80211_key argument to ieee80211_compute_duration() and
lightly constify arguments. Get the crypto header length from the
key argument instead of blithely assuming a WEP header. Add some
inline documentation. Account for data padding (IEEE80211_F_DATAPAD).


# 1.61 24-Dec-2005 perry

Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.


# 1.60 13-Dec-2005 dyoung

Fix comments and debug printfs: Tx FIFOs underflow, they don't
overflow.


# 1.59 13-Dec-2005 dyoung

On a transmit FIFO overflow (err, actually an underflow...) reset
both the transmit & receive sections of the MAC.


Revision tags: yamt-readahead-base3 ktrace-lwp-base
# 1.58 23-Nov-2005 dyoung

Miscellaneous Realtek RTL8180L driver improvements:

1 Added new sysctl controls for debugging.

2 Improve detection & support for hardware WEP.

3 Revamp handling of transmit descriptor rings.

4 Reliably IFF_OACTIVE when transmit descriptors are available, to
stop the transmit section of the driver from freezing up.

5 Fix beacon transmission in adhoc and hostap modes. XXX There is
a wart in hostap mode, where beacons are transmitted at 1/2 the
correct rate. Load beacon descriptors when the RTW_INTR_BINT
interrupt arrives; schedule RTW_INTR_BINT 1ms ahead of the target
beacon time.

6 Recover more gracefully from tx/rx errors: avoid
transmitter/receiver/chip resets. Try to re-synchronize software
state with hardware state---e.g., load next descriptor pointer
from hardware.

7 Activate the transmit watchdog timer for beacons as well as other
packets.

8 Introduce rtw_idle() that waits for transmit DMA to finish; call
it before resetting the transmitter.


Revision tags: yamt-readahead-base2
# 1.57 18-Nov-2005 skrll

Adapt drivers to the new net80211(9).

Most of this is from dyoung@. Thanks!


Revision tags: yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base
# 1.56 22-Sep-2005 gdt

branches: 1.56.6;
Make arg of IFQ_SET_READY be &ifp->if_snd, to match all other drivers
and be compilable with altq enabled. Reviewed by dyoung@


# 1.55 07-Sep-2005 dogcow

With the assistance of dyoung, fix the following problems:
* some 8180L cards need a longer time for the srom to initialize; patch
suggested via OpenBSD.
* some cards give '0' for USA, some give '3'; for the meantime, accept both
as being USA locale cards.
* this is RTW, not ATW. :)


# 1.54 06-Sep-2005 dogcow

make rtw.c compile again after the 22-jun-05 net80211 import


# 1.53 11-Jul-2005 dyoung

Add undefined variable 'ic' to rtw_attach.


# 1.52 06-Jul-2005 dyoung

Historically, an(4), ath(4), atw(4), rtw(4), and wi(4) have printed
out their modes and rates at boot. Revert to the historical
behavior.


# 1.51 06-Jul-2005 dyoung

Avoid an unnecessary API difference between NetBSD and FreeBSD:
back out my change to ieee80211_crypto_encap that made it free its
mbuf argument on error. I had thought it was a bug. It was not.
It's the drivers that are broken. Make an(4), atw(4), ipw(4),
iwi(4), ral(4), rtw(4), ural(4), and wi(4) free the mbuf when
ieee80211_crypto_encap returns NULL. Also, return ath(4) to the
way it was---i.e., free the mbuf.

Thanks to Sam Leffler to pointing out my mistake.


# 1.50 28-Jun-2005 dyoung

branches: 1.50.2;
Here is a grotty hack that lets the RTL8180L handle WEP in the
receive direction, while software handles WEP in the transmit
direction. When net80211 calls rtw's rtw_key_set with a WEP key,
I point the key's wk_cipher at our "fake" cipher, rtw_cipher_wep,
which is alike to ieee80211_cipher_wep except it provides a different
crypto-decapsulation routine, rtw_wep_decap. rtw_wep_decap copies
the key passed to it by net80211, clears the key's SWCRYPT flag,
and then calls wep_decap. Now wep_decap will decapsulate, but it
will *not* re-decrypt.

XXX I need to check whether the hardware supports 40-bit WEP,
XXX 104-bit WEP, or both, and act accordingly.


# 1.49 27-Jun-2005 dyoung

rtw: Try to get hardware WEP to work. It seems to work in
the RX direction, but not in the TX direction. The
net80211 crypto framework doesn't seem to cope very well
with the assymetry (I'm probably missing something), so
I will use software WEP for now.

net80211: In ieee80211_compute_duration, figure out whether to add
the WEP header to the packet overhead by checking the
WEP bit in the Frame Control field of the 802.11 header,
instead of checking the IEEE80211_F_PRIVACY flag.

Also, if the WEP bit is present, assume that the frame
described by (wh, len) has already already been WEP
encapsulated, and adjust the payload length accordingly.
XXX that's a grotty hack that I will have to revisit,
later.


# 1.48 22-Jun-2005 dyoung

Resolve conflicts in importation of 18-May-2005 ath(4) / net80211(9)
from FreeBSD. Introduce compatibility shims (sys/dev/ic/ath_netbsd.[ch],
sys/net80211/ieee80211_netbsd.[ch]). Update drivers (an, atu, atw,
awi, ipw, iwi, rtw, wi) for the new net80211(9) API.


# 1.47 20-Jun-2005 atatat

Change the rest of the sysctl subsystem to use const consistently.
The __UNCONST macro is now used only where necessary and the RW macros
are gone. Most of the changes here are consumers of the
sysctl_createv(9) interface that now takes a pair of const pointers
which used not to be.


# 1.46 10-Jun-2005 dyoung

Sprinkle __UNCONST() and rename variables to quiet uiet -Wcast-qual,
-Wshadow complaints.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 yamt-km-base4 yamt-km-base3 netbsd-3-base kent-audio2-base
# 1.45 02-Mar-2005 dyoung

Misc. changes to improve ad hoc mode and to enable hostap mode:

Fix the work-around for the NIC bug where it skips to rx
descriptor 0. The driver used to skip to rx descriptor 1.
Hopefully this stops the out-of-order packet reception that
Charles Hannum saw.
When debugging is enabled, print rx-descriptor status flags
before printing the rx bit rate.

Add a debug message for when a beacon tx buffer reclamation.

Reset IFF_OACTIVE when we reset the transmitter.

Pass the consolidated LED state, a struct rtw_led_state,
to rtw_led_attach.

Choose the bit-rate for management frames (1Mb/s) at the
same place we choose for all other frames.

Do not use the NIC's short preamble or RTS options for
management frames. Label beacons for the NIC.

Following a Linux driver, take care not to zero arbitrary
bits in the TPPOLL register.

Use the new idiom for IBSS merges: disable transmitter,
kick the state machine.
Add a second descriptor to the beacon ring. The NIC seems
to like this much better.


# 1.44 27-Feb-2005 perry

nuke trailing whitespace


Revision tags: yamt-km-base2
# 1.43 31-Jan-2005 thorpej

Eliminate use of M_HASFCS.


Revision tags: yamt-km-base
# 1.42 16-Jan-2005 dyoung

branches: 1.42.2; 1.42.4;
Move the register access mode into struct rtw_regs. Change
rtw_set_access, rtw_set_access1 to match.

Add a subroutine for setting WEP keys. WEP isn't quite finished,
because I have to add the WEP header to Tx packets. Implement the
SIOCS80211NWKEY ioctl for setting WEP keys.

Program the LEDs based on operating state and packet activity.

* On a Revision F RTL8180, blink LED1 at 1Hz to indicate
scan/authenticate/associate states. In the run state, turn LED1
on. In every state, blink LED1 at 5Hz to indicate non-beacon
tx/rx activity. I would like to use two LEDs, but in all my
Rev. F instances, LED0 is not wired to an LED; instead, the
first LED is wired to indicate that the card's power is on.

* On a Revision D RTL8180, program the LEDs so that LED0 indicates
Tx, and LED1 indicates Rx. The Rx LED will blink annoyingly if
there are beacons in the air, but at least the Tx LED is useful.

* Store the hardware revision in the softc to support my futile
attempt at programming LEDs for both Rev. D and Rev. F parts;
I never did get Rev. D LEDs to work right.

* Add a debug flag RTW_DEBUG_LED for the LED transitions.

Add RTW_TPPOLL_ALL, RTW_TPPOLL_SALL to start and stop, respectively,
all of the transmit rings.

In ad hoc mode, allocate a beacon and load it into the beacon ring.
Start the ring. In one trial, the card re-transmitted the beacon
ring's contents several times before stopping. More programming
and testing for ad hoc mode is necessary. I'm not setting the
beacon flag in the transmit descriptor.

Revamp the transmit section to make better use of all the transmit
rings: beacon queue, high-, low-, and medium-priority rings. Put
beacon frames on the beacon ring. All other management frames,
and data frames, go on the medium-priority ring. Power-save data
frames go on the high-priority ring. (Note that powersaving is
not implemented!) This is a work in progress.

Send all 802.11 Management frames at 1Mbps.

After we put a packet on a transmit ring, tickle the right bit in
the TPPOLL to tell RTL8180. Stop all rings on error and in rtw_stop.

Use the RF chip type, not the RTL8180 revision, to choose between
host- and MAC-controlled RF serial I/O. Now the Netgear MA521
works.

Remove bogus definition of bit RTW_TPPOLL_FSWINT.


Revision tags: kent-audio1-beforemerge
# 1.41 04-Jan-2005 dyoung

Set initial conditions to guarantee that when read_seeprom toggles
Chip Select, it turns *on* rather than *off*.


# 1.40 04-Jan-2005 dyoung

Add the logic for IBSS merges.


# 1.39 03-Jan-2005 dyoung

sys/dev/ic/rtw.c:

Cosmetic: remove two short ladders from rtw_init. Fit the
NIC registers print-out onto one line using the RTW_PRINT_REGS
macro.

sys/dev/ic/rtwvar.h:

Add RTW_PRINT_REGS wrapper macro for rtw_print_regs. It
is a null op unless defined(RTW_DEBUG).


# 1.38 03-Jan-2005 dyoung

In sys/dev/ic/rtw.c:

Use clue from rtk(4) and re(4) to fix the rtw(4) packet
filter. Previously, I was using the wrong CRC32 function
to hash multicast addresses; to compensate, I set the
multicast filter to all 1s. Now that I hash the addresses
correctly, I do not any longer set the filter to all 1s.

In rtw_ioctl, avoid gratuitous re-initialization when the
interface flags change. If a !IFF_UP -> IFF_UP transition,
call rtw_init(); otherwise, only reload the packet filter.

In sys/dev/ic/rtwreg.h:

Put useful combinations of Receiver Control Register flags
in RTW_RCR_PKTFILT_MASK, RTW_RCR_MONITOR, and
RTW_RCR_PKTFILT_DEFAULT. (XXX RTW_RCR_MONITOR should be
called RTW_RCR_PKTFILT_MONITOR.)


# 1.37 02-Jan-2005 dyoung

Cosmetic: change u_int{8,16,32,64}_t to C99-style uint{8,16,32,64}_t,
which is preferred.


# 1.36 29-Dec-2004 dyoung

In rtw_detach, flag the rtw as "invalid" (RTW_F_INVALID). Do not
try to power-down the RF section of an invalid rtw.

The radiotap signal quality field is 16, not 8, bits wide. Convert
the byte order.


# 1.35 29-Dec-2004 dyoung

Remove some dead code.


# 1.34 29-Dec-2004 dyoung

I like the tlp/atw-style names for software descriptors, txsoft,
better than txctl. Change from rtw_txctl/rtw_rxctl to
rtw_txsoft/rtw_rxsoft. Change the descriptor blocks' names to
match: rtw_txctl_blk becomes rtw_txsoft_blk. Change the member-name
prefixes for both software and hardware descriptors.


# 1.33 29-Dec-2004 dyoung

Consolidate variables related to the rx ring in sc_rxdesc_blk,
which is a struct rtw_rxdesc_blk.

Put a copy of the DMA tag and the DMA map into the rx- and tx-ring
blocks so that I don't have to pass them to subroutines all of the
time.


# 1.32 28-Dec-2004 dyoung

Add bpf(4) packet taps to rtw(4). Now you can tap DLT_EN10MB
(Ethernet II), DLT_IEEE802_11 (802.11), and DLT_IEEE802_11_RADIO
(radiotap + 802.11).


# 1.31 28-Dec-2004 dyoung

If defined(RTW_DEBUG), provide a sysctl (hw.rtw.rxbufs_limit) for
limiting the number of rx buffers an rtw may allocate. Use this
sysctl to test the code that copes with buffer exhaustion.

Allocate at most RTW_RXQLEN rx buffers, stopping at the sysctl
limit. Record in sc_nrxdesc how many were allocated, and put the
end-of-ring indication on sc_rxdesc[sc_nrxdesc - 1]. In rtw_init,
if no rx buffers could be allocated, log a complaint, clear
IFF_RUNNING, and exit with an error.

Many changes to accomodate a short rx ring, mainly of the "add a
rx-ring length argument" variety. XXX I really should consolidate
all of the rx ring variables in one struct and pass that to the
rx-ring subroutines.

Bug fix: after calling MCLGET, use the (m->m_flags & M_EXT) idiom
to check for success, instead of m != NULL.

Bug fix: at the top of rtw_start, if IFF_RUNNING is not set, or
IFF_OACTIVE is, get out.


# 1.30 27-Dec-2004 dyoung

Use a table to convert the hardware's bit rates (0, 1, 2, 3) to
net80211 bit rates (2, 4, 11, 22).

Count input errors (if_ierrors++) for "DMA error/FIFO overflow"
and unknown bit rate.


# 1.29 27-Dec-2004 dyoung

Simplify the reset we do on a transmit timeout. Really, this could
be as simple as rtw_stop(, 0), rtw_init().


# 1.28 27-Dec-2004 mycroft

Use the last descriptor to count collisions and failed transmissions, too.


# 1.27 27-Dec-2004 mycroft

When checking if a split packet is completed, check the *last* segment, not
the first. Otherwise we can overwrite parts of the TX ring that we shouldn't.

Kluge the basic rate setting for now.

Minor simplification to the dequeueing logic.


# 1.26 27-Dec-2004 dyoung

Remove useless debug sysctls.

For AP scanning, change the channel dwell time from 1 second to
1/5 second.


# 1.25 27-Dec-2004 mycroft

Replace d_plcp_svc with d_residue. The latter is the number of whole
empty/unused octets to fill out the data time slot. The value is constrained
by math to 0 for <= 5.5Mb, 0-1 for 11Mb, and 0-2 for 22Mb. It is used to
signal to the MAC that there is residue.


# 1.24 26-Dec-2004 dyoung

Make rtw(4) build w/o RTW_DEBUG. Thanks to Charles Hannum for
pointing out my oversight.


# 1.23 25-Dec-2004 dyoung

The rx descriptor ring bug happens quite often, so printf'ing
occurrences is annoying. Only printf about it when rtw_debug
contains RTW_DEBUG_BUG.


# 1.22 25-Dec-2004 dyoung

IMPORTANT: set m->m_pkthdr.rcvif on rx'd packets. Illegal memory
references abound without this fix.

In rtw_intr_rx, skip to the next rx packet earlier if the rx packet
length is too short.

Also in rtw_intr_rx, if a packet is rx'd with unknown rate, printf
a warning, drop the packet, recycle the rx buffer, skip to next rx
packet.


# 1.21 25-Dec-2004 dyoung

Change rtw_debug from a debug level to a debug mask. Add a lot of
debug flags.

From Linux: handle an RTL8180 bug. Sometimes the NIC skips from
the middle of the ring to the 0th rx descriptor. Now the driver
resynchronizes.

Handle a receive descriptor underrun or Rx FIFO overflow condition
in the way that the Linux driver does. This kind of seems like
overkill, but whatever.

Protect rtw_ioctl with splnet().

Do not load a tx descriptor with a buffer shorter than 4 bytes.

Handle a transmit timeout less disruptively.


# 1.20 23-Dec-2004 dyoung

Oops, straggler from last commit: set the 802.11 Duration field
with the result from ieee80211_compute_duration.


# 1.19 23-Dec-2004 dyoung

Fix a bug in ieee80211_compute_duration: the 802.11 Duration field
in an 802.11 unicast data packet is equal to the duration of the
SIFS and Acknowledgement. That is, the amount of time reserved
*after* the packet has finished transmitting.

Change the arguments to ieee80211_compute_duration: pass the entire
packet length, not just the payload length. Add a 'debug' argument
to ieee80211_compute_duration and its helper subroutine,
ieee80211_compute_duration1.

If debug != 0, ieee80211_compute_duration printfs its arguments
and several local variables.

In rtw(4), load the 802.11 Duration field with the result from
ieee80211_compute_duration.


# 1.18 23-Dec-2004 dyoung

Bug fix: in rtw_rxbuf_alloc, unload the previous mbuf chain before
loading the new chain.


# 1.17 23-Dec-2004 dyoung

DMA-synchronize the Rx buffers before re-initializing them.
XXX not necessary?


# 1.16 23-Dec-2004 dyoung

Add more comprehensive debug messages as we setup transmit descriptors.
Also, dump packets if IFF_DEBUG|IFF_LINK2. Factor out a subroutine
for printing transmit-descriptor debug messages.


# 1.15 23-Dec-2004 dyoung

Disable interrupts and stop transmit DMA before disabling the
transmitter and receiver.


# 1.14 23-Dec-2004 dyoung

Shorten variables, s/txctl/ctl/. This is rtw_start, after all:
transmission is implied.


# 1.13 23-Dec-2004 dyoung

Do not indicate to the NIC that the host has appended the CRC32 to
Tx frames.


# 1.12 23-Dec-2004 dyoung

When we set up the supported rates table, mark 1Mb/s, 2Mb/s as
basic rates.


# 1.11 23-Dec-2004 dyoung

Extract the transmission status from a tx descriptor, and convert
to host byte-order, once.


# 1.10 20-Dec-2004 dyoung

Realtek sample sources are not consistent about the "Digital PHY"
bit in the SROM. It seems as if it is set to 1 when the PHY is
*analog*, not *digital*. Fix my sources.

In rtw_intr_rx, use units of 500kb/s instead of 100kb/s for rate,
to be consistent with net80211's expectations. Polish up some
debugging ugly messages. Dump raw 802.11 packets if IFF_DEBUG|IFF_LINK2
and RTW_DEBUG is defined.

Polish power-state (on/sleep/off) handling. Especially improve
support for RFMD (totally untested) and Maxim. For Philips, take
the Digital PHY property into account.

Call the net80211 watchdog function from rtw_watchdog, so that we
scan again if auth/assoc fails.

Be a little more cautious about writing register[RTW_TPPOLL], since
other drivers are.... Don't frob the high/low-priority queues
right now, since I don't use them.

Add rtw_join_bss which programs the card with the BSSID and other
properties of a BSS. Use it on state transitions. Factor out
rtw_set_nettype.

Make rtw_recv_beacon call ieee80211_recv_mgmt instead of dropping
beacons on the floor! TBD IBSS merges.

Change some rtw_debug=2 printfs to rtw_debug=3 (RTW_DPRINTF3)
printfs so the console doesn't get spammed so badly at rtw_debug=2.
Change some debugging printfs to RTW_DPRINTFs. E.g., print the
"RF programming method" only if debugging is enabled.


# 1.9 20-Dec-2004 dyoung

Fix bug in last commit: use &sc->sc_regs, regs is not defined.


# 1.8 20-Dec-2004 dyoung

Add some bus barriers. Remark where they are needed, e.g.,
read_eeprom.

Change some printfs to RTW_DPRINTF2s to quiet rtw(4) when debugging
is disabled.


# 1.7 20-Dec-2004 dyoung

Get rid of the silly char (*dvname)[IFNAMSIZ] pattern. Replace it
with const char *dvname. I'm not sure what I was thinking.


# 1.6 20-Dec-2004 dyoung

Assert that I'm DMA-syncing a non-negative number of transmit
descriptors.

As I free dirty transmit buffers, move them to the free list, not
back to the dirty list!

Add a 5-second transmit timeout.


# 1.5 19-Dec-2004 dyoung

Add the transmit section of rtw(4): build up and tear down transmit
descriptor rings, move packets from the transmit queues to the
transmit rings, handle transmission-completed interrupts. My
Linksys WPC11 ver. 4 with Maxim RF, generates interrupts like it
is successfully transmitting packets. Clearly there are bugs: my
G4 Powerbook locks up hard. I will debug tomorrow.


# 1.4 13-Dec-2004 dyoung

At last, I have rtw w/ Philips RF receiving packets.

I added some sysctls to aid debugging:

* hw.rtw.debug -- enable debugging

* hw.rtw.flush_rfio -- Linux voodoo: possibly makes the MAC
"flush" bits down the serial bus to the RF

* hw.rtw.host_rfio: force the host to bang bits to the RF, instead
of the MAC banging bits

* hw.rtw.rfio_delay: after telling the MAC to bang bits to the
RF front-end, delay rfio_delay microseconds.

* hw.rtw.rfprog_fallback: there is this notion of the "RF
programming method." I believe the choice influences the
polarity/timing of the serial bus used to program the RF
front-end. I know the correct choice for Intersil/RFMD/Philips
front-ends, only. For all other front-ends, I "fallback" to
rfprog_fallback.

Make rtw_txdac_enable take an rtw_softc argument. I will probably
revert this change.

Add some Linux voodoo to rtw_continuous_tx_enable. I will probably
revert this change.

Important: add rtw_set_rfprog, which sets the correct RF programming
method. This change and the following change are probably responsible
for making the Philips RF work.

Important: RTW_CONFIG1 is an 8-bit register, treat it that way!

Important: RTW_BRSR is 16-bit, RTW_CRCOUNT, RTW_PHYDELAY, and
RTW_MSR are 8-bit: treat them that way!

Vastly simplify rtw_resume_ticks.

Note to self: set the LED state to match the power state.

Hedge against the possibility that RTW_MSR is protected as
RTW_CONFIG[0123] are, meanwhile reworking that section of rtw_init
a little.

Add sc_anaparm, which isn't used, yet....


# 1.3 12-Dec-2004 dyoung

Miscellaneous changes. Details below. Important changes flagged
with []. Using the driver with my Linksys WPC11 ver. 4, it seems
to be receiving packets for a change. The WPC11 ver. 4 has a Maxim
RF section. My no-name rtw with Philips RF section still does not
receive any packets.

Keep access-level (analog params > config[0123] registers > none)
in sc_access. Add rtw_set_access for changing the access level.

Make rtw_continuous_tx_enable and other subroutines use rtw_set_access
instead of rtw_config0123_enable and rtw_anaparm_enable.

Factor part of the chip-reset code into rtw_chip_reset1.

Change the 'struct foo (*bar)[N]'-style arguments to
'struct foo *bar'-style arguments.

Consolidate software/hardware Tx/Rx ring setup in rtw_hwring_setup,
rtw_swring_setup.

Add a new constant, SA2400_OPMODE_DEFAULTS, for the bits that we
*always* set in the SA2400 OPMODE register.

Factor some code out into rtw_sa2400_calibrate. (Inspired by the
Linux driver.)

[] When the receiver goes into underrun/overflow state, call a new
subroutine, rtw_kick() that stops the Rx/Tx processes, resets
the chip, reinitializes the Tx/Rx rings, and restarts Rx/Tx
processes. (Inspired by the Linux driver.)

[] In rtw_intr_rx, check for too-short packets before calling
ieee80211_find_rxnode. I believe this will prevent a repeat of
the MCHK exception I saw once on macppc.

[] Use seconds-elapased as well as microseconds-elapsed to set the
next "due date" for the timeout interrupt. This keeps the driver
from programming the timeout to expire too early.

[] In rtw_intr, read RTW_ISR at most 10 times, then get out. If
the interface is not enabled (RTW_F_ENABLED), then get out.

[] In rtw_stop, get out if the interface is not enabled (RTW_F_ENABLED).
Block IPL_NET interrupts. Don't read/write any registers if
the interface is invalid (RTW_F_INVALID).

[] Call rtw_stop in rtw_detach.


Revision tags: kent-audio1-base
# 1.2 30-Oct-2004 thorpej

When adding/deleting multicast addresses, only whack the address
filter if the interface is marked RUNNING.

Fixes kern/27678.


# 1.1 26-Sep-2004 dyoung

branches: 1.1.2;
Add work-in-progress driver rtw(4) for Realtek RTL8180 MAC/baseband.

Add register definitions for Maxim MAX2820 and Philips SA2400 radio
front-ends.


Revision tags: nick-nhusb-base-20170204
# 1.125 02-Feb-2017 nonaka

wlan interfaces make interrupt routine running on softint context.

see http://mail-index.netbsd.org/tech-kern/2016/12/06/msg021281.html

tested device:
* ath at pci: AR5212, AR5424
* athn at pci: AR9287
* ipw at pci: 2100BG
* iwi at pci: 2915ABG
* iwm at pci: 3165, 7260, 8260
* iwn at pci: 4945, 6235
* ral at pci: RT2560
* rtwn at pci: RTL8192CE


Revision tags: bouyer-socketcan-base pgoyette-localcount-20170107 nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.124 15-Sep-2016 jdolecek

remove last isolated islands using BUS_SPACE_BARRIER_SYNC and
BUS_SPACE_BARRIER_X_BEFORE_X - these were only ever defined for mips and ia64,
and never actually implemented even there


Revision tags: localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907
# 1.123 10-Jun-2016 ozaki-r

branches: 1.123.2;
Introduce m_set_rcvif and m_reset_rcvif

The API is used to set (or reset) a received interface of a mbuf.
They are counterpart of m_get_rcvif, which will come in another
commit, hide internal of rcvif operation, and reduce the diff of
the upcoming change.

No functional change.


Revision tags: nick-nhusb-base-20160529
# 1.122 16-May-2016 ozaki-r

Use M_GETCTX and M_SETCTX instead of open-coding rcvif

No functional change.


Revision tags: netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 netbsd-7-0-RELEASE nick-nhusb-base-20150921 netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 nick-nhusb-base-20150606 nick-nhusb-base-20150406 nick-nhusb-base netbsd-7-base yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 rmind-smpnet-nbase rmind-smpnet-base tls-maxphys-base
# 1.121 25-Feb-2014 pooka

branches: 1.121.6;
Ensure that the top level sysctl nodes (kern, vfs, net, ...) exist before
the sysctl link sets are processed, and remove redundancy.

Shaves >13kB off of an amd64 GENERIC, not to mention >1k duplicate
lines of code.


# 1.120 17-Oct-2013 christos

- remove unused variables
- move variables inside ifdef sections
- ifdef notdef unused code
- use __USE for debugging variables


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE yamt-pagecache-tag8 netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 agc-symver-base netbsd-6-1-RC2 netbsd-6-1-RC1 yamt-pagecache-base8 netbsd-6-0-1-RELEASE yamt-pagecache-base7 matt-nb6-plus-nbase yamt-pagecache-base6 netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base10 yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.119 04-Jul-2011 joerg

branches: 1.119.2; 1.119.12; 1.119.16;
Fix memset usage.


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base matt-mips64-premerge-20101231 rmind-uvmplock-base
# 1.118 15-Nov-2010 uebayasi

Socket ioctl definitions need sys/sockio.h.


# 1.117 13-Nov-2010 uebayasi

Don't pull in the whole uvm(9) API to access only PAGE_SIZE and
some other constants. These are provided by sys/param.h now.


Revision tags: uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10 uebayasi-xip-base1
# 1.116 05-Apr-2010 joerg

Push the bpf_ops usage back into bpf.h. Push the common ifp->if_bpf
check into the inline functions as well the fourth argument for
bpf_attach.


# 1.115 15-Mar-2010 dyoung

Make this compile on sparc64:

1 s/next_tick/next_tint/ because next_tick shadows a global on sparc64.

2 Fix the bus-barrier helper routines, which had the tag & handle
swapped (!!). Move the helpers from rtwreg.h to rtwvar.h, and
change RTW_BARRIER() into an inline subroutine called rtw_barrier().


Revision tags: yamt-nfs-mp-base9
# 1.114 24-Feb-2010 dyoung

branches: 1.114.2;
A pointer typedef entails trading too much flexibility to declare const
and non-const types, and the kernel uses both const and non-const
PMF qualifiers and device suspensors, so change the pmf_qual_t and
device_suspensor_t typedefs from "pointers to const" to non-pointer,
non-const types.


Revision tags: uebayasi-xip-base
# 1.113 31-Jan-2010 dyoung

branches: 1.113.2;
Add the missing newline to a verbose autoconf message.


# 1.112 19-Jan-2010 pooka

Redefine bpf linkage through an always present op vector, i.e.
#if NBPFILTER is no longer required in the client. This change
doesn't yet add support for loading bpf as a module, since drivers
can register before bpf is attached. However, callers of bpf can
now be modularized.

Dynamically loadable bpf could probably be done fairly easily with
coordination from the stub driver and the real driver by registering
attachments in the stub before the real driver is loaded and doing
a handoff. ... and I'm not going to ponder the depths of unload
here.

Tested with i386/MONOLITHIC, modified MONOLITHIC without bpf and rump.


# 1.111 08-Jan-2010 dyoung

Expand PMF_FN_* macros.


Revision tags: matt-premerge-20091211 jym-xensuspend-nbase
# 1.110 19-Oct-2009 rmind

Drop 3rd and 4th clauses from David Young's license.
Reviewed and approved by dyoung@ (copyright holder).


# 1.109 16-Sep-2009 dyoung

In pmf(9), improve the implementation of device self-suspension
and make suspension by self, by drvctl(8), and by ACPI system sleep
play nice together. Start solidifying some temporary API changes.

1. Extract a new header file, <sys/device_if.h>, from <sys/device.h> and
#include it from <sys/pmf.h> instead of <sys/device.h> to break the
circular dependency between <sys/device.h> and <sys/pmf.h>.

2. Introduce pmf_qual_t, an aggregate of qualifications on a PMF
suspend/resume call. Start to replace instances of PMF_FN_PROTO,
PMF_FN_ARGS, et cetera, with a pmf_qual_t.

3. Introduce the notion of a "suspensor," an entity that holds a
device in suspension. More than one suspensor may hold a device
at once. A device stays suspended as long as at least one
suspensor holds it. A device resumes when the last suspensor
releases it.

Currently, the kernel defines three suspensors,

3a the system-suspensor: for system suspension, initiated
by 'sysctl -w machdep.sleep_state=3', by lid closure, by
power-button press, et cetera,

3b the drvctl-suspensor: for device suspension by /dev/drvctl
ioctl, e.g., drvctl -S sip0.

3c the system self-suspensor: for device drivers that suspend
themselves and their children. Several drivers for network
interfaces put the network device to sleep while it is not
administratively up, that is, after the kernel calls if_stop(,
1). The self-suspensor should not be used directly. See
the description of suspensor delegates, below.

A suspensor can have one or more "delegates". A suspensor can
release devices that its delegates hold suspended. Right now,
only the system self-suspensor has delegates. For each device
that a self-suspending driver attaches, it creates the device's
self-suspensor, a delegate of the system self-suspensor.

Suspensors stop a system-wide suspend/resume cycle from waking
devices that the operator put to sleep with drvctl before the cycle.
They also help self-suspension to work more simply, safely, and in
accord with expectations.

4. Add the notion of device activation level, devact_level_t,
and a routine for checking the current activation level,
device_activation(). Current activation levels are DEVACT_LEVEL_BUS,
DEVACT_LEVEL_DRIVER, and DEVACT_LEVEL_CLASS, which respectively
indicate that the device's bus is active, that the bus and device are
active, and that the bus, device, and the functions of the device's
class (network, audio) are active.

Suspend/resume calls can be qualified with a devact_level_t.
The power-management framework treats a devact_level_t that
qualifies a device suspension as the device's current activation
level; it only runs hooks to reduce the activation level from
the presumed current level to the fully suspended state. The
framework treats a devact_level_t qualifying device resumption
as the target activation level; it only runs hooks to raise the
activation level to the target.

5. Use pmf_qual_t, devact_level_t, and self-suspensors in several
drivers.

6. Temporarily add an unused power-management workqueue that I will
remove or replace, soon.


Revision tags: yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5 yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 nick-hppapmap-base3 jym-xensuspend-base nick-hppapmap-base
# 1.108 07-Apr-2009 dyoung

Cosmetic: remove some dead code.


# 1.107 02-Apr-2009 dyoung

Add the WEP capability to our net80211 capability flags, since we do
sort of support hardware WEP. Only change the WEP key index in a Tx
descriptor from 0 if the type of our transmit key is _WEP, not _TKIP:
i.e., only if we're really doing WEP crypto in the hardware.

Ignore a watchdog timeout on any Tx ring if we can collect some packets
from that ring. Restart both the receiver and the transmitter when a
watchdog timeout occurs instead of restarting only the transmitter.


Revision tags: nick-hppapmap-base2 haad-dm-base2 haad-nbase2 ad-audiomp2-base haad-dm-base mjf-devfs2-base
# 1.106 12-Nov-2008 ad

branches: 1.106.4;
Remove LKMs and switch to the module framework, pass 1.

Proposed on tech-kern@.


# 1.105 07-Nov-2008 dyoung

*** Summary ***

When a link-layer address changes (e.g., ifconfig ex0 link
02:de:ad:be:ef:02 active), send a gratuitous ARP and/or a Neighbor
Advertisement to update the network-/link-layer address bindings
on our LAN peers.

Refuse a change of ethernet address to the address 00:00:00:00:00:00
or to any multicast/broadcast address. (Thanks matt@.)

Reorder ifnet ioctl operations so that driver ioctls may inherit
the functions of their "class"---ether_ioctl(), fddi_ioctl(), et
cetera---and the class ioctls may inherit from the generic ioctl,
ifioctl_common(), but both driver- and class-ioctls may override
the generic behavior. Make network drivers share more code.

Distinguish a "factory" link-layer address from others for the
purposes of both protecting that address from deletion and computing
EUI64.

Return consistent, appropriate error codes from network drivers.

Improve readability. KNF.

*** Details ***

In if_attach(), always initialize the interface ioctl routine,
ifnet->if_ioctl, if the driver has not already initialized it.
Delete if_ioctl == NULL tests everywhere else, because it cannot
happen.

In the ioctl routines of network interfaces, inherit common ioctl
behaviors by calling either ifioctl_common() or whichever ioctl
routine is appropriate for the class of interface---e.g., ether_ioctl()
for ethernets.

Stop (ab)using SIOCSIFADDR and start to use SIOCINITIFADDR. In
the user->kernel interface, SIOCSIFADDR's argument was an ifreq,
but on the protocol->ifnet interface, SIOCSIFADDR's argument was
an ifaddr. That was confusing, and it would work against me as I
make it possible for a network interface to overload most ioctls.
On the protocol->ifnet interface, replace SIOCSIFADDR with
SIOCINITIFADDR. In ifioctl(), return EPERM if userland tries to
invoke SIOCINITIFADDR.

In ifioctl(), give the interface the first shot at handling most
interface ioctls, and give the protocol the second shot, instead
of the other way around. Finally, let compatibility code (COMPAT_OSOCK)
take a shot.

Pull device initialization out of switch statements under
SIOCINITIFADDR. For example, pull ..._init() out of any switch
statement that looks like this:

switch (...->sa_family) {
case ...:
..._init();
...
break;
...
default:
..._init();
...
break;
}

Rewrite many if-else clauses that handle all permutations of IFF_UP
and IFF_RUNNING to use a switch statement,

switch (x & (IFF_UP|IFF_RUNNING)) {
case 0:
...
break;
case IFF_RUNNING:
...
break;
case IFF_UP:
...
break;
case IFF_UP|IFF_RUNNING:
...
break;
}

unifdef lots of code containing #ifdef FreeBSD, #ifdef NetBSD, and
#ifdef SIOCSIFMTU, especially in fwip(4) and in ndis(4).

In ipw(4), remove an if_set_sadl() call that is out of place.

In nfe(4), reuse the jumbo MTU logic in ether_ioctl().

Let ethernets register a callback for setting h/w state such as
promiscuous mode and the multicast filter in accord with a change
in the if_flags: ether_set_ifflags_cb() registers a callback that
returns ENETRESET if the caller should reset the ethernet by calling
if_init(), 0 on success, != 0 on failure. Pull common code from
ex(4), gem(4), nfe(4), sip(4), tlp(4), vge(4) into ether_ioctl(),
and register if_flags callbacks for those drivers.

Return ENOTTY instead of EINVAL for inappropriate ioctls. In
zyd(4), use ENXIO instead of ENOTTY to indicate that the device is
not any longer attached.

Add to if_set_sadl() a boolean 'factory' argument that indicates
whether a link-layer address was assigned by the factory or some
other source. In a comment, recommend using the factory address
for generating an EUI64, and update in6_get_hw_ifid() to prefer a
factory address to any other link-layer address.

Add a routing message, RTM_LLINFO_UPD, that tells protocols to
update the binding of network-layer addresses to link-layer addresses.
Implement this message in IPv4 and IPv6 by sending a gratuitous
ARP or a neighbor advertisement, respectively. Generate RTM_LLINFO_UPD
messages on a change of an interface's link-layer address.

In ether_ioctl(), do not let SIOCALIFADDR set a link-layer address
that is broadcast/multicast or equal to 00:00:00:00:00:00.

Make ether_ioctl() call ifioctl_common() to handle ioctls that it
does not understand.

In gif(4), initialize if_softc and use it, instead of assuming that
the gif_softc and ifp overlap.

Let ifioctl_common() handle SIOCGIFADDR.

Sprinkle rtcache_invariants(), which checks on DIAGNOSTIC kernels
that certain invariants on a struct route are satisfied.

In agr(4), rewrite agr_ioctl_filter() to be a bit more explicit
about the ioctls that we do not allow on an agr(4) member interface.

bzero -> memset. Delete unnecessary casts to void *. Use
sockaddr_in_init() and sockaddr_in6_init(). Compare pointers with
NULL instead of "testing truth". Replace some instances of (type
*)0 with NULL. Change some K&R prototypes to ANSI C, and join
lines.


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 wrstuden-revivesa-base-1 simonb-wapbl-nbase yamt-pf42-base4 simonb-wapbl-base yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 yamt-nfs-mp-base2 wrstuden-revivesa-base yamt-nfs-mp-base yamt-pf42-base ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 1.104 15-Mar-2008 dyoung

branches: 1.104.4; 1.104.10; 1.104.12;
Cosmetic: make rtw_hw_keysupp() return a bool instead of int. In
rtw_wep_setkeys(), add a debug printf, and move the initialization
of keylen from the for-loop to the declaration.


# 1.103 14-Mar-2008 dyoung

Extract subroutine rtw_tx_kick() from rtw_start(), and reuse it in
rtw_io_enable() to restart the transmitter after resetting it.


# 1.102 14-Mar-2008 dyoung

Change tests for "impossible" keys to KASSERT()s. Get rid of a
temporary variable. In rtw_key_delete(), do not invalidate the
hardware keys unless a WEP key is deleted.


# 1.101 12-Mar-2008 dyoung

Use device_t and its accessors throughout. Use aprint_*_dev().

Improve PMF-ability.

Add a 'flags' argument to suspend/resume handlers and
callers such as pmf_system_suspend().

Define a flag, PMF_F_SELF, which indicates to PMF that a
device is suspending/resuming itself. Add helper routines,
pmf_device_suspend_self(dev) and pmf_device_resume_self(dev),
that call pmf_device_suspend(dev, PMF_F_SELF) and
pmf_device_resume(dev, PMF_F_SELF), respectively. Use
PMF_F_SELF to suspend/resume self in ath(4), audio(4),
rtw(4), and sip(4).

In ath(4) and in rtw(4), replace the icky sc_enable/sc_disable
callbacks, provided by the bus front-end, with
self-suspension/resumption. Also, clean up the bus
front-ends. Make sure that the interrupt handler is
disestablished during suspension. Get rid of driver-private
flags (e.g., RTW_F_ENABLED, ath_softc->sc_invalid); use
device_is_active()/device_has_power() calls, instead.

In the network-class suspend handler, call if_stop(, 0)
instead of if_stop(, 1), because the latter is superfluous
(bus- and driver-suspension hooks will 'disable' the NIC),
and it may cause recursion.

In the network-class resume handler, prevent infinite
recursion through if_init() by getting out early if we are
self-suspending (PMF_F_SELF).

rtw(4) improvements:

Destroy rtw(4) callouts when we detach it. Make rtw at
pci detachable. Print some more information with the "rx
frame too long" warning.

Remove activate() methods:

Get rid of rtw_activate() and ath_activate(). The device
activate() methods are not good for much these days.

Make ath at cardbus resume with crypto functions intact:

Introduce a boolean device property, "pmf-powerdown". If
pmf-powerdown is present and false, it indicates that a
bus back-end should not remove power from a device.

Honor this property in cardbus_child_suspend().

Set this property to 'false' in ath_attach(), since removing
power from an ath at cardbus seems to lobotomize the WPA
crypto engine. XXX Should the pmf-powerdown property
propagate toward the root of the device tree?

Miscellaneous ath(4) changes:

Warn if ath(4) tries to write crypto keys to suspended
hardware.

Reduce differences between FreeBSD and NetBSD in ath(4)
multicast filter setup.

Make ath_printrxbuf() print an rx descriptor's status &
key index, to help debug crypto errors.

Shorten a staircase in ath_ioctl(). Don't check for
ieee80211_ioctl() return code ERESTART, it never happens.


# 1.100 12-Mar-2008 dyoung

Print the TPPoll register when the Tx DMA engine doesn't shut down
in the time we allow.


# 1.99 03-Mar-2008 tsutsui

Explicitly include <sys/device.h> for device_t.


Revision tags: nick-net80211-sync-base vmlocking2-base3 bouyer-xeni386-nbase bouyer-xeni386-base mjf-devfs-base matt-armv6-base hpcarm-cleanup-base
# 1.98 21-Dec-2007 dyoung

branches: 1.98.2; 1.98.6;
Do not embed a struct device in rtw_softc any longer. Register
both pci and cardbus attachments with CFATTACH_DECL_NEW(). Access
the softc through the device_t using device_private().

While I'm here, change a couple of KASSERT()s about the Rx buffer
length to a warning.


# 1.97 20-Dec-2007 dyoung

Remove shutdown hooks. Use KASSERT().


# 1.96 16-Dec-2007 dyoung

Fix a bug I introduced to rtw_chan2txpower() the other night.

Fix a bug in device detachment: change a break statement to a
/*FALLTHROUGH*/ in rtw_detach().


# 1.95 16-Dec-2007 dyoung

Synchronize device detachment with network interrupts. Use the
pmf network class instead of powerhooks.


Revision tags: yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 bouyer-xenamd64-base2 vmlocking-nbase bouyer-xenamd64-base jmcneill-pm-base reinoud-bufcleanup-base
# 1.94 18-Nov-2007 jnemeth

branches: 1.94.2; 1.94.6;
fix 'm' used unitialized


# 1.93 16-Nov-2007 dyoung

Accommodate the variety of RF front-ends when radiotapping frames:
tap only RSSI when there is a Philips RF front-end. Tap both Barker
lock quality and RSSI when there is any other RF front-end.

Provide radiotap listeners a more complete picture of channel
activity:

in promiscuous mode, tap frames who do not pass the CRC32 check.
Flag packets that were received with a short preamble. Ask
the NIC to pass us 802.11 Control frames. Pass frames to
radiotap listeners before stripping the FCS. Re-order operations
in rtw_intr_rx() in order to accomplish all of this, taking
care not to pass a broken packet to net80211!

Do not provide a flags field when tapping xmitted frames.

Assert sane Rx packet lengths. Really should check and drop instead
of KASSERTing. I will revisit this, soon.

Update copyright.


# 1.92 15-Nov-2007 dyoung

Fix order of operations:

rtw_rxdesc_init: before initializing a Rx descriptor's
control word, synchronize the Rx buffer

rtw_start, be paranoid: set the "NIC owns" bit on a Tx
descriptor dead last. Always reinitialize the "next
Tx descriptor" pointer, just in case it got clobbered
somehow.

Let the compiler decide whether to inline rtw_collect_txring or
not.


Revision tags: jmcneill-base
# 1.91 19-Oct-2007 ad

branches: 1.91.2;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h


Revision tags: yamt-x86pmap-base4 yamt-x86pmap-base3 yamt-x86pmap-base2 vmlocking-base
# 1.90 29-Sep-2007 scw

branches: 1.90.2;
s/NPBFILTER/NBPFILTER/ in some #endif comments. No functional change.


Revision tags: nick-csl-alignment-base5 yamt-x86pmap-base matt-mips64-base nick-csl-alignment-base mjf-ufs-trans-base
# 1.89 09-Jul-2007 ad

branches: 1.89.6; 1.89.8; 1.89.10;
Merge some of the less invasive changes from the vmlocking branch:

- kthread, callout, devsw API changes
- select()/poll() improvements
- miscellaneous MT safety improvements


# 1.88 29-May-2007 dyoung

Fix rtw(4) on NetBSD/macppc: use bus_space_write_region_stream_4()
instead of bus_space_write_region_4() to write WEP Rx keys to the
NIC. Thanks macallan@ for detecting the bug and testing the fix.


# 1.87 29-May-2007 dyoung

Cosmetic: simplify a memset() statement, use __arraycount(), and
remove a gratuitous return statement at the end of a void subroutine.


# 1.86 29-May-2007 dyoung

Simplify multicast filter programming, and take care to avoid
gratuitous device resets when the kernel adds/deletes a multicast
address.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base
# 1.85 04-Mar-2007 christos

branches: 1.85.2; 1.85.4;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.


Revision tags: ad-audiomp-base post-newlock2-merge newlock2-nbase newlock2-base
# 1.84 29-Jan-2007 dyoung

branches: 1.84.2;
In rtw_dequeue(), initialize *mp to NULL before anything else, so
that it is either NULL or a valid mbuf. Previously, it was possible
for rtw_dequeue() to exit with 0 before initializing *mp. rtw_start()
would have used whatever trash was in *mp, which would lead to
problems later on.


# 1.83 06-Jan-2007 dyoung

I have made a small change that suppresses "recovery" from (spurious?)
tx timeouts on the beacon queue. The driver's recovery process
badly disrupts the MAC's receiver. This needs a closer look, later.

Every other fix is by Charles M. Hannum. Charles writes:

"With these, the device is quite stable under load, does not experience
xmit timeouts, no longer mysteriously freezes, and does not spew
a lot of garbage. It does, however, continue to get some "tx fifo
underflow"s.

global, SYSCTL_SETUP():
a) Removed unused sysctl variables.

rtw_io_enable():
b) Change rtw_io_enable to take a softc, and make it call
rtw_txring_fixup().
c) Enable the PCI multiple read/write bit.
d) Always reset rdb_next to 0 when starting the receive engine.

rtw_intr_rx():
e) When processing receive packets, store the next pointer in rdb_next
and read it back on the next round, to fix a race condition vs.
rtw_tune() during AP discovery and association.
f) Remove the special "skip to 0th descriptor" code, because it is no
longer needed.

rtw_collect_txring():
g) In the "force" case, stop when we catch up to the hardware xmit
pointer.

rtw_intr_beacon():
h) Resetting tdb_next here looked fishy to me, in light of changes in
rtw_collect_txring(). XXX However, this is the one part I haven't
tested.

rtw_txring_fixup():
i) Add function and line arguments, so we can print out information
about the caller.
j) In addition to reading the hardware pointer, skip over any
additional packets with OWN set -- we may have queued more.

rtw_rxring_fixup():
k) Remove this, because it's completely wrong.

rtw_intr_ioerror():
l) Don't handle receive overruns here; handle them in the normal receive
path. Also changed RTW_INTR_RX and RTW_INTR_IOERROR accordingly.
m) Do not fiddle with CR; the transmit engine is still running just
fine.
n) Do not fiddle with IMR; it was unnecessary.
o) Don't touch the receive engine at all; not necessary now that we're
leaving CR alone.
p) Remove the rtw_do_chip_reset case; it was dangerous and not actually
used.

rtw_intr():
q) Don't mask off ISR bits when we pass down the ISR value; it's not
necessary, and sometimes the other bits useful in debugging output.

rtw_seg_too_short():
r) Don't spew here; the caller will do it if necessary. (Stops spewage
in an expected case.)

rtw_rxdesc_blk:
s) Minor change to make the elements have the same order as txdesc_blk.

general:
t) Added a bunch of debugging output, #ifdef RTW_DIAG, that was useful
while investigating the ring management problems. Also moved
rtw_txring_fixup() into RTW_DIAG, as I believe the transmit pointer
is always kept in sync now, and the function has potential race
conditions.


# 1.82 06-Jan-2007 dyoung

After we examine a rx/tx descriptor and find that it's still owned
by the NIC, re-sync the descriptor so that a cacheline will not
"cover" the NIC's modifications to the descriptor when we next
examine it.

This compiles, but I have not tested it, yet.


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase wrstuden-fixsa-base-1 netbsd-4-0-RELEASE netbsd-4-0-RC5 matt-nb4-arm-base netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 wrstuden-fixsa-base yamt-splraiseipl-base5 yamt-splraiseipl-base4 yamt-splraiseipl-base3 netbsd-4-base
# 1.81 16-Nov-2006 christos

__unused removal on arguments; approved by core.


# 1.80 13-Nov-2006 dyoung

Stop using typeof() in the bit-twiddling macros, per yamt@'s
suggestion. This change requires that I use the __PRIuBITS format
string in atw and rtw, so do that.


Revision tags: yamt-splraiseipl-base2
# 1.79 12-Oct-2006 xtraeme

Use __unused in function arguments where appropiate.


# 1.78 12-Oct-2006 christos

- sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386


# 1.77 24-Sep-2006 jmcneill

Add "name" parameter to powerhook_establish, to aid debugging. No objections
on tech-kern@


Revision tags: yamt-splraiseipl-base yamt-pdpolicy-base9 yamt-pdpolicy-base8 rpaulo-netinet-merge-pcb-base
# 1.76 03-Sep-2006 christos

branches: 1.76.2; 1.76.4;
- comment out impossible comparisons
- remove superfluous if statement


# 1.75 31-Aug-2006 dyoung

Per discussion on tech-kern and tech-userlevel, move the bit-twiddling
macros, __BIT, __BITS, SHIFTIN, SHIFTOUT, and __arraycount() from
lib/libkern/libkern.h to sys/cdefs.h. Add a __-prefix to SHIFTIN
and SHIFTOUT, and add a manual page for the bit-twiddling macros,
bits(3).

Make the __BIT and __BITS macros "widthless," as best I can, by
changing their type to uintmax_t from uint32_t. XXX The manual
page lags this change by a bit.

Define __PRIxBIT and __PRIxBITS printf(3) format strings.


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base7 yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base simonb-timecounters-base
# 1.74 26-May-2006 blymn

Clean up bogus whitespace


Revision tags: yamt-pdpolicy-base5
# 1.73 14-May-2006 christos

branches: 1.73.2;
XXX: GCC uninitialized


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 elad-kernelauth-base
# 1.72 28-Mar-2006 dyoung

Revamp ieee80211_get_rate. Now it does not use the rateset in the
ic->ic_bss, but it uses the rateset in its new ieee80211_node
argument, instead. If the rate is fixed by ic->ic_fixed_rate, but
the fixed rate is not in the node's rateset, choose a reasonable
default: prefer the lowest basic rate or, if there is no basic
rate, prefer the lowest rate, period.

Change a printf complaint to a debug message.

Adapt drivers to suit new ieee80211_get_rate calling convention.

XXX I really need to replace ieee80211_get_rate with a bitrate
XXX adaptation algorithm. Soon, soon....


# 1.71 27-Mar-2006 dyoung

Set the channel frequency and flags in the radiotap headers in
rtw_tune instead of in rtw_start, rtw_intr_rx.


# 1.70 27-Mar-2006 dyoung

Remove unused argument ifflagsp from rtw_dmamap_load_txbuf.


Revision tags: peter-altq-base yamt-pdpolicy-base2
# 1.69 08-Mar-2006 dyoung

branches: 1.69.2;
Change macro names to avoid collisions:

BIT -> __BIT
BITS -> __BITS


# 1.68 08-Mar-2006 dyoung

Move my bit-twiddling macros to libkern.h from my drivers, where
I had duplicated them. Improve the macros' names. Simplify their
implementation.

A brief description of each macro is below.

BIT(n): Return a bitmask with bit m set, where the least
significant bit is bit 0.

BITS(m, n): Return a bitmask with bits m through n, inclusive,
set. It does not matter whether m>n or m<=n.
The least significant bit is bit 0.

A "bitfield" is a span of consecutive bits defined by a
bitmask, where 1s select the bits in the bitfield. SHIFTIN,
SHIFTOUT, and SHIFTOUT_MASK help read and write bitfields
from device registers.

SHIFTIN(v, mask): Left-shift bits `v' into the bitfield
defined by `mask', and return them. No
side-effects.

SHIFTOUT(v, mask): Extract and return the bitfield selected
by `mask' from `v', right-shifting the
bits so that the rightmost selected bit
is at bit 0. No side-effects.

SHIFTOUT_MASK(mask): Right-shift the bits in `mask' so that
the rightmost non-zero bit is at bit
0. This is useful for finding the
greatest unsigned value that a bitfield
can hold. No side-effects. Note that
SHIFTOUT_MASK(m) = SHIFTOUT(m, m).

Examples:

/*
* Register definitions taken from the RFMD RF3000 manual.
*/
#define RF3000_GAINCTL 0x11 /* TX variable gain control */
#define RF3000_GAINCTL_TXVGC_MASK BITS(7, 2)
#define RF3000_GAINCTL_SCRAMBLER BIT(1)

/*
* Shift the transmit power into the transmit-power field of the
* gain-control register and write it to the baseband processor.
*/
atw_rf3000_write(sc, RF3000_GAINCTL,
SHIFTIN(txpower, RF3000_GAINCTL_TXVGC_MASK));


/*
* Register definitions taken from the ADMtek ADM8211 manual.
*
*/
#define ATW_RXSTAT_OWN BIT(31) /* 1: NIC may fill descriptor */
/* ... */
#define ATW_RXSTAT_DA1 BIT(17) /* DA bit 1, admin'd address */
#define ATW_RXSTAT_DA0 BIT(16) /* DA bit 0, group address */
#define ATW_RXSTAT_RXDR_MASK BITS(15,12) /* RX data rate */
#define ATW_RXSTAT_FL_MASK BITS(11,0) /* RX frame length, last
* descriptor only
*/

/* Extract the frame length from the Rx descriptor's
* status field.
*/
len = SHIFTOUT(rxstat, ATW_RXSTAT_FL_MASK);


Revision tags: yamt-pdpolicy-base yamt-uio_vmspace-base5
# 1.67 20-Feb-2006 thorpej

branches: 1.67.2; 1.67.4;
Use device_is_active() rather than testing dv_flags for DVF_ACTIVE
directly.


# 1.66 19-Feb-2006 dyoung

When rtw_enable is called, power may have been removed and re-applied,
so invalidate the WEP key registers to force us to write the keys
back to the hardware.

Revamp key handling: use the hardware WEP engine for 40-bit and
104-bit keys, only; use software WEP for all other key lengths.
Set the hardware key length to the length of the default Tx key,
or if there is no default Tx key, use the length of the longest
WEP key.


# 1.65 04-Feb-2006 dyoung

In rtw_{rx,tx}ring_fixup, do not set the tx/rx ring index to
something out of bounds if we read an invalid pointer form the
hardware. Prevents a panic when an rtw@cardbus is ejected.


# 1.64 29-Dec-2005 dyoung

branches: 1.64.2; 1.64.4; 1.64.6;
Add support for the GCT Semiconductor GRF5101 transceiver/synthesizer.
From OpenBSD.

GCT will not provide any documentation, so there are many magic
numbers in this code.


# 1.63 29-Dec-2005 dyoung

Update rtw(4) for the new IBSS merge idiom, where ieee80211_ibss_merge()
does not return ENETRESET if the driver should change its BSSID,
but it makes a RUN->RUN transition, instead.


# 1.62 29-Dec-2005 dyoung

In atw(4), use ieee80211_compute_duration() to compute IEEE 802.11
Duration and PLCP Length fields, and delete the abominable
atw_frame_setdurs() subroutine.

Make rtw(4) use the new ieee80211_compute_duration() calling
convention.

Add an ieee80211_key argument to ieee80211_compute_duration() and
lightly constify arguments. Get the crypto header length from the
key argument instead of blithely assuming a WEP header. Add some
inline documentation. Account for data padding (IEEE80211_F_DATAPAD).


# 1.61 24-Dec-2005 perry

Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.


# 1.60 13-Dec-2005 dyoung

Fix comments and debug printfs: Tx FIFOs underflow, they don't
overflow.


# 1.59 13-Dec-2005 dyoung

On a transmit FIFO overflow (err, actually an underflow...) reset
both the transmit & receive sections of the MAC.


Revision tags: yamt-readahead-base3 ktrace-lwp-base
# 1.58 23-Nov-2005 dyoung

Miscellaneous Realtek RTL8180L driver improvements:

1 Added new sysctl controls for debugging.

2 Improve detection & support for hardware WEP.

3 Revamp handling of transmit descriptor rings.

4 Reliably IFF_OACTIVE when transmit descriptors are available, to
stop the transmit section of the driver from freezing up.

5 Fix beacon transmission in adhoc and hostap modes. XXX There is
a wart in hostap mode, where beacons are transmitted at 1/2 the
correct rate. Load beacon descriptors when the RTW_INTR_BINT
interrupt arrives; schedule RTW_INTR_BINT 1ms ahead of the target
beacon time.

6 Recover more gracefully from tx/rx errors: avoid
transmitter/receiver/chip resets. Try to re-synchronize software
state with hardware state---e.g., load next descriptor pointer
from hardware.

7 Activate the transmit watchdog timer for beacons as well as other
packets.

8 Introduce rtw_idle() that waits for transmit DMA to finish; call
it before resetting the transmitter.


Revision tags: yamt-readahead-base2
# 1.57 18-Nov-2005 skrll

Adapt drivers to the new net80211(9).

Most of this is from dyoung@. Thanks!


Revision tags: yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base
# 1.56 22-Sep-2005 gdt

branches: 1.56.6;
Make arg of IFQ_SET_READY be &ifp->if_snd, to match all other drivers
and be compilable with altq enabled. Reviewed by dyoung@


# 1.55 07-Sep-2005 dogcow

With the assistance of dyoung, fix the following problems:
* some 8180L cards need a longer time for the srom to initialize; patch
suggested via OpenBSD.
* some cards give '0' for USA, some give '3'; for the meantime, accept both
as being USA locale cards.
* this is RTW, not ATW. :)


# 1.54 06-Sep-2005 dogcow

make rtw.c compile again after the 22-jun-05 net80211 import


# 1.53 11-Jul-2005 dyoung

Add undefined variable 'ic' to rtw_attach.


# 1.52 06-Jul-2005 dyoung

Historically, an(4), ath(4), atw(4), rtw(4), and wi(4) have printed
out their modes and rates at boot. Revert to the historical
behavior.


# 1.51 06-Jul-2005 dyoung

Avoid an unnecessary API difference between NetBSD and FreeBSD:
back out my change to ieee80211_crypto_encap that made it free its
mbuf argument on error. I had thought it was a bug. It was not.
It's the drivers that are broken. Make an(4), atw(4), ipw(4),
iwi(4), ral(4), rtw(4), ural(4), and wi(4) free the mbuf when
ieee80211_crypto_encap returns NULL. Also, return ath(4) to the
way it was---i.e., free the mbuf.

Thanks to Sam Leffler to pointing out my mistake.


# 1.50 28-Jun-2005 dyoung

branches: 1.50.2;
Here is a grotty hack that lets the RTL8180L handle WEP in the
receive direction, while software handles WEP in the transmit
direction. When net80211 calls rtw's rtw_key_set with a WEP key,
I point the key's wk_cipher at our "fake" cipher, rtw_cipher_wep,
which is alike to ieee80211_cipher_wep except it provides a different
crypto-decapsulation routine, rtw_wep_decap. rtw_wep_decap copies
the key passed to it by net80211, clears the key's SWCRYPT flag,
and then calls wep_decap. Now wep_decap will decapsulate, but it
will *not* re-decrypt.

XXX I need to check whether the hardware supports 40-bit WEP,
XXX 104-bit WEP, or both, and act accordingly.


# 1.49 27-Jun-2005 dyoung

rtw: Try to get hardware WEP to work. It seems to work in
the RX direction, but not in the TX direction. The
net80211 crypto framework doesn't seem to cope very well
with the assymetry (I'm probably missing something), so
I will use software WEP for now.

net80211: In ieee80211_compute_duration, figure out whether to add
the WEP header to the packet overhead by checking the
WEP bit in the Frame Control field of the 802.11 header,
instead of checking the IEEE80211_F_PRIVACY flag.

Also, if the WEP bit is present, assume that the frame
described by (wh, len) has already already been WEP
encapsulated, and adjust the payload length accordingly.
XXX that's a grotty hack that I will have to revisit,
later.


# 1.48 22-Jun-2005 dyoung

Resolve conflicts in importation of 18-May-2005 ath(4) / net80211(9)
from FreeBSD. Introduce compatibility shims (sys/dev/ic/ath_netbsd.[ch],
sys/net80211/ieee80211_netbsd.[ch]). Update drivers (an, atu, atw,
awi, ipw, iwi, rtw, wi) for the new net80211(9) API.


# 1.47 20-Jun-2005 atatat

Change the rest of the sysctl subsystem to use const consistently.
The __UNCONST macro is now used only where necessary and the RW macros
are gone. Most of the changes here are consumers of the
sysctl_createv(9) interface that now takes a pair of const pointers
which used not to be.


# 1.46 10-Jun-2005 dyoung

Sprinkle __UNCONST() and rename variables to quiet uiet -Wcast-qual,
-Wshadow complaints.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 yamt-km-base4 yamt-km-base3 netbsd-3-base kent-audio2-base
# 1.45 02-Mar-2005 dyoung

Misc. changes to improve ad hoc mode and to enable hostap mode:

Fix the work-around for the NIC bug where it skips to rx
descriptor 0. The driver used to skip to rx descriptor 1.
Hopefully this stops the out-of-order packet reception that
Charles Hannum saw.
When debugging is enabled, print rx-descriptor status flags
before printing the rx bit rate.

Add a debug message for when a beacon tx buffer reclamation.

Reset IFF_OACTIVE when we reset the transmitter.

Pass the consolidated LED state, a struct rtw_led_state,
to rtw_led_attach.

Choose the bit-rate for management frames (1Mb/s) at the
same place we choose for all other frames.

Do not use the NIC's short preamble or RTS options for
management frames. Label beacons for the NIC.

Following a Linux driver, take care not to zero arbitrary
bits in the TPPOLL register.

Use the new idiom for IBSS merges: disable transmitter,
kick the state machine.
Add a second descriptor to the beacon ring. The NIC seems
to like this much better.


# 1.44 27-Feb-2005 perry

nuke trailing whitespace


Revision tags: yamt-km-base2
# 1.43 31-Jan-2005 thorpej

Eliminate use of M_HASFCS.


Revision tags: yamt-km-base
# 1.42 16-Jan-2005 dyoung

branches: 1.42.2; 1.42.4;
Move the register access mode into struct rtw_regs. Change
rtw_set_access, rtw_set_access1 to match.

Add a subroutine for setting WEP keys. WEP isn't quite finished,
because I have to add the WEP header to Tx packets. Implement the
SIOCS80211NWKEY ioctl for setting WEP keys.

Program the LEDs based on operating state and packet activity.

* On a Revision F RTL8180, blink LED1 at 1Hz to indicate
scan/authenticate/associate states. In the run state, turn LED1
on. In every state, blink LED1 at 5Hz to indicate non-beacon
tx/rx activity. I would like to use two LEDs, but in all my
Rev. F instances, LED0 is not wired to an LED; instead, the
first LED is wired to indicate that the card's power is on.

* On a Revision D RTL8180, program the LEDs so that LED0 indicates
Tx, and LED1 indicates Rx. The Rx LED will blink annoyingly if
there are beacons in the air, but at least the Tx LED is useful.

* Store the hardware revision in the softc to support my futile
attempt at programming LEDs for both Rev. D and Rev. F parts;
I never did get Rev. D LEDs to work right.

* Add a debug flag RTW_DEBUG_LED for the LED transitions.

Add RTW_TPPOLL_ALL, RTW_TPPOLL_SALL to start and stop, respectively,
all of the transmit rings.

In ad hoc mode, allocate a beacon and load it into the beacon ring.
Start the ring. In one trial, the card re-transmitted the beacon
ring's contents several times before stopping. More programming
and testing for ad hoc mode is necessary. I'm not setting the
beacon flag in the transmit descriptor.

Revamp the transmit section to make better use of all the transmit
rings: beacon queue, high-, low-, and medium-priority rings. Put
beacon frames on the beacon ring. All other management frames,
and data frames, go on the medium-priority ring. Power-save data
frames go on the high-priority ring. (Note that powersaving is
not implemented!) This is a work in progress.

Send all 802.11 Management frames at 1Mbps.

After we put a packet on a transmit ring, tickle the right bit in
the TPPOLL to tell RTL8180. Stop all rings on error and in rtw_stop.

Use the RF chip type, not the RTL8180 revision, to choose between
host- and MAC-controlled RF serial I/O. Now the Netgear MA521
works.

Remove bogus definition of bit RTW_TPPOLL_FSWINT.


Revision tags: kent-audio1-beforemerge
# 1.41 04-Jan-2005 dyoung

Set initial conditions to guarantee that when read_seeprom toggles
Chip Select, it turns *on* rather than *off*.


# 1.40 04-Jan-2005 dyoung

Add the logic for IBSS merges.


# 1.39 03-Jan-2005 dyoung

sys/dev/ic/rtw.c:

Cosmetic: remove two short ladders from rtw_init. Fit the
NIC registers print-out onto one line using the RTW_PRINT_REGS
macro.

sys/dev/ic/rtwvar.h:

Add RTW_PRINT_REGS wrapper macro for rtw_print_regs. It
is a null op unless defined(RTW_DEBUG).


# 1.38 03-Jan-2005 dyoung

In sys/dev/ic/rtw.c:

Use clue from rtk(4) and re(4) to fix the rtw(4) packet
filter. Previously, I was using the wrong CRC32 function
to hash multicast addresses; to compensate, I set the
multicast filter to all 1s. Now that I hash the addresses
correctly, I do not any longer set the filter to all 1s.

In rtw_ioctl, avoid gratuitous re-initialization when the
interface flags change. If a !IFF_UP -> IFF_UP transition,
call rtw_init(); otherwise, only reload the packet filter.

In sys/dev/ic/rtwreg.h:

Put useful combinations of Receiver Control Register flags
in RTW_RCR_PKTFILT_MASK, RTW_RCR_MONITOR, and
RTW_RCR_PKTFILT_DEFAULT. (XXX RTW_RCR_MONITOR should be
called RTW_RCR_PKTFILT_MONITOR.)


# 1.37 02-Jan-2005 dyoung

Cosmetic: change u_int{8,16,32,64}_t to C99-style uint{8,16,32,64}_t,
which is preferred.


# 1.36 29-Dec-2004 dyoung

In rtw_detach, flag the rtw as "invalid" (RTW_F_INVALID). Do not
try to power-down the RF section of an invalid rtw.

The radiotap signal quality field is 16, not 8, bits wide. Convert
the byte order.


# 1.35 29-Dec-2004 dyoung

Remove some dead code.


# 1.34 29-Dec-2004 dyoung

I like the tlp/atw-style names for software descriptors, txsoft,
better than txctl. Change from rtw_txctl/rtw_rxctl to
rtw_txsoft/rtw_rxsoft. Change the descriptor blocks' names to
match: rtw_txctl_blk becomes rtw_txsoft_blk. Change the member-name
prefixes for both software and hardware descriptors.


# 1.33 29-Dec-2004 dyoung

Consolidate variables related to the rx ring in sc_rxdesc_blk,
which is a struct rtw_rxdesc_blk.

Put a copy of the DMA tag and the DMA map into the rx- and tx-ring
blocks so that I don't have to pass them to subroutines all of the
time.


# 1.32 28-Dec-2004 dyoung

Add bpf(4) packet taps to rtw(4). Now you can tap DLT_EN10MB
(Ethernet II), DLT_IEEE802_11 (802.11), and DLT_IEEE802_11_RADIO
(radiotap + 802.11).


# 1.31 28-Dec-2004 dyoung

If defined(RTW_DEBUG), provide a sysctl (hw.rtw.rxbufs_limit) for
limiting the number of rx buffers an rtw may allocate. Use this
sysctl to test the code that copes with buffer exhaustion.

Allocate at most RTW_RXQLEN rx buffers, stopping at the sysctl
limit. Record in sc_nrxdesc how many were allocated, and put the
end-of-ring indication on sc_rxdesc[sc_nrxdesc - 1]. In rtw_init,
if no rx buffers could be allocated, log a complaint, clear
IFF_RUNNING, and exit with an error.

Many changes to accomodate a short rx ring, mainly of the "add a
rx-ring length argument" variety. XXX I really should consolidate
all of the rx ring variables in one struct and pass that to the
rx-ring subroutines.

Bug fix: after calling MCLGET, use the (m->m_flags & M_EXT) idiom
to check for success, instead of m != NULL.

Bug fix: at the top of rtw_start, if IFF_RUNNING is not set, or
IFF_OACTIVE is, get out.


# 1.30 27-Dec-2004 dyoung

Use a table to convert the hardware's bit rates (0, 1, 2, 3) to
net80211 bit rates (2, 4, 11, 22).

Count input errors (if_ierrors++) for "DMA error/FIFO overflow"
and unknown bit rate.


# 1.29 27-Dec-2004 dyoung

Simplify the reset we do on a transmit timeout. Really, this could
be as simple as rtw_stop(, 0), rtw_init().


# 1.28 27-Dec-2004 mycroft

Use the last descriptor to count collisions and failed transmissions, too.


# 1.27 27-Dec-2004 mycroft

When checking if a split packet is completed, check the *last* segment, not
the first. Otherwise we can overwrite parts of the TX ring that we shouldn't.

Kluge the basic rate setting for now.

Minor simplification to the dequeueing logic.


# 1.26 27-Dec-2004 dyoung

Remove useless debug sysctls.

For AP scanning, change the channel dwell time from 1 second to
1/5 second.


# 1.25 27-Dec-2004 mycroft

Replace d_plcp_svc with d_residue. The latter is the number of whole
empty/unused octets to fill out the data time slot. The value is constrained
by math to 0 for <= 5.5Mb, 0-1 for 11Mb, and 0-2 for 22Mb. It is used to
signal to the MAC that there is residue.


# 1.24 26-Dec-2004 dyoung

Make rtw(4) build w/o RTW_DEBUG. Thanks to Charles Hannum for
pointing out my oversight.


# 1.23 25-Dec-2004 dyoung

The rx descriptor ring bug happens quite often, so printf'ing
occurrences is annoying. Only printf about it when rtw_debug
contains RTW_DEBUG_BUG.


# 1.22 25-Dec-2004 dyoung

IMPORTANT: set m->m_pkthdr.rcvif on rx'd packets. Illegal memory
references abound without this fix.

In rtw_intr_rx, skip to the next rx packet earlier if the rx packet
length is too short.

Also in rtw_intr_rx, if a packet is rx'd with unknown rate, printf
a warning, drop the packet, recycle the rx buffer, skip to next rx
packet.


# 1.21 25-Dec-2004 dyoung

Change rtw_debug from a debug level to a debug mask. Add a lot of
debug flags.

From Linux: handle an RTL8180 bug. Sometimes the NIC skips from
the middle of the ring to the 0th rx descriptor. Now the driver
resynchronizes.

Handle a receive descriptor underrun or Rx FIFO overflow condition
in the way that the Linux driver does. This kind of seems like
overkill, but whatever.

Protect rtw_ioctl with splnet().

Do not load a tx descriptor with a buffer shorter than 4 bytes.

Handle a transmit timeout less disruptively.


# 1.20 23-Dec-2004 dyoung

Oops, straggler from last commit: set the 802.11 Duration field
with the result from ieee80211_compute_duration.


# 1.19 23-Dec-2004 dyoung

Fix a bug in ieee80211_compute_duration: the 802.11 Duration field
in an 802.11 unicast data packet is equal to the duration of the
SIFS and Acknowledgement. That is, the amount of time reserved
*after* the packet has finished transmitting.

Change the arguments to ieee80211_compute_duration: pass the entire
packet length, not just the payload length. Add a 'debug' argument
to ieee80211_compute_duration and its helper subroutine,
ieee80211_compute_duration1.

If debug != 0, ieee80211_compute_duration printfs its arguments
and several local variables.

In rtw(4), load the 802.11 Duration field with the result from
ieee80211_compute_duration.


# 1.18 23-Dec-2004 dyoung

Bug fix: in rtw_rxbuf_alloc, unload the previous mbuf chain before
loading the new chain.


# 1.17 23-Dec-2004 dyoung

DMA-synchronize the Rx buffers before re-initializing them.
XXX not necessary?


# 1.16 23-Dec-2004 dyoung

Add more comprehensive debug messages as we setup transmit descriptors.
Also, dump packets if IFF_DEBUG|IFF_LINK2. Factor out a subroutine
for printing transmit-descriptor debug messages.


# 1.15 23-Dec-2004 dyoung

Disable interrupts and stop transmit DMA before disabling the
transmitter and receiver.


# 1.14 23-Dec-2004 dyoung

Shorten variables, s/txctl/ctl/. This is rtw_start, after all:
transmission is implied.


# 1.13 23-Dec-2004 dyoung

Do not indicate to the NIC that the host has appended the CRC32 to
Tx frames.


# 1.12 23-Dec-2004 dyoung

When we set up the supported rates table, mark 1Mb/s, 2Mb/s as
basic rates.


# 1.11 23-Dec-2004 dyoung

Extract the transmission status from a tx descriptor, and convert
to host byte-order, once.


# 1.10 20-Dec-2004 dyoung

Realtek sample sources are not consistent about the "Digital PHY"
bit in the SROM. It seems as if it is set to 1 when the PHY is
*analog*, not *digital*. Fix my sources.

In rtw_intr_rx, use units of 500kb/s instead of 100kb/s for rate,
to be consistent with net80211's expectations. Polish up some
debugging ugly messages. Dump raw 802.11 packets if IFF_DEBUG|IFF_LINK2
and RTW_DEBUG is defined.

Polish power-state (on/sleep/off) handling. Especially improve
support for RFMD (totally untested) and Maxim. For Philips, take
the Digital PHY property into account.

Call the net80211 watchdog function from rtw_watchdog, so that we
scan again if auth/assoc fails.

Be a little more cautious about writing register[RTW_TPPOLL], since
other drivers are.... Don't frob the high/low-priority queues
right now, since I don't use them.

Add rtw_join_bss which programs the card with the BSSID and other
properties of a BSS. Use it on state transitions. Factor out
rtw_set_nettype.

Make rtw_recv_beacon call ieee80211_recv_mgmt instead of dropping
beacons on the floor! TBD IBSS merges.

Change some rtw_debug=2 printfs to rtw_debug=3 (RTW_DPRINTF3)
printfs so the console doesn't get spammed so badly at rtw_debug=2.
Change some debugging printfs to RTW_DPRINTFs. E.g., print the
"RF programming method" only if debugging is enabled.


# 1.9 20-Dec-2004 dyoung

Fix bug in last commit: use &sc->sc_regs, regs is not defined.


# 1.8 20-Dec-2004 dyoung

Add some bus barriers. Remark where they are needed, e.g.,
read_eeprom.

Change some printfs to RTW_DPRINTF2s to quiet rtw(4) when debugging
is disabled.


# 1.7 20-Dec-2004 dyoung

Get rid of the silly char (*dvname)[IFNAMSIZ] pattern. Replace it
with const char *dvname. I'm not sure what I was thinking.


# 1.6 20-Dec-2004 dyoung

Assert that I'm DMA-syncing a non-negative number of transmit
descriptors.

As I free dirty transmit buffers, move them to the free list, not
back to the dirty list!

Add a 5-second transmit timeout.


# 1.5 19-Dec-2004 dyoung

Add the transmit section of rtw(4): build up and tear down transmit
descriptor rings, move packets from the transmit queues to the
transmit rings, handle transmission-completed interrupts. My
Linksys WPC11 ver. 4 with Maxim RF, generates interrupts like it
is successfully transmitting packets. Clearly there are bugs: my
G4 Powerbook locks up hard. I will debug tomorrow.


# 1.4 13-Dec-2004 dyoung

At last, I have rtw w/ Philips RF receiving packets.

I added some sysctls to aid debugging:

* hw.rtw.debug -- enable debugging

* hw.rtw.flush_rfio -- Linux voodoo: possibly makes the MAC
"flush" bits down the serial bus to the RF

* hw.rtw.host_rfio: force the host to bang bits to the RF, instead
of the MAC banging bits

* hw.rtw.rfio_delay: after telling the MAC to bang bits to the
RF front-end, delay rfio_delay microseconds.

* hw.rtw.rfprog_fallback: there is this notion of the "RF
programming method." I believe the choice influences the
polarity/timing of the serial bus used to program the RF
front-end. I know the correct choice for Intersil/RFMD/Philips
front-ends, only. For all other front-ends, I "fallback" to
rfprog_fallback.

Make rtw_txdac_enable take an rtw_softc argument. I will probably
revert this change.

Add some Linux voodoo to rtw_continuous_tx_enable. I will probably
revert this change.

Important: add rtw_set_rfprog, which sets the correct RF programming
method. This change and the following change are probably responsible
for making the Philips RF work.

Important: RTW_CONFIG1 is an 8-bit register, treat it that way!

Important: RTW_BRSR is 16-bit, RTW_CRCOUNT, RTW_PHYDELAY, and
RTW_MSR are 8-bit: treat them that way!

Vastly simplify rtw_resume_ticks.

Note to self: set the LED state to match the power state.

Hedge against the possibility that RTW_MSR is protected as
RTW_CONFIG[0123] are, meanwhile reworking that section of rtw_init
a little.

Add sc_anaparm, which isn't used, yet....


# 1.3 12-Dec-2004 dyoung

Miscellaneous changes. Details below. Important changes flagged
with []. Using the driver with my Linksys WPC11 ver. 4, it seems
to be receiving packets for a change. The WPC11 ver. 4 has a Maxim
RF section. My no-name rtw with Philips RF section still does not
receive any packets.

Keep access-level (analog params > config[0123] registers > none)
in sc_access. Add rtw_set_access for changing the access level.

Make rtw_continuous_tx_enable and other subroutines use rtw_set_access
instead of rtw_config0123_enable and rtw_anaparm_enable.

Factor part of the chip-reset code into rtw_chip_reset1.

Change the 'struct foo (*bar)[N]'-style arguments to
'struct foo *bar'-style arguments.

Consolidate software/hardware Tx/Rx ring setup in rtw_hwring_setup,
rtw_swring_setup.

Add a new constant, SA2400_OPMODE_DEFAULTS, for the bits that we
*always* set in the SA2400 OPMODE register.

Factor some code out into rtw_sa2400_calibrate. (Inspired by the
Linux driver.)

[] When the receiver goes into underrun/overflow state, call a new
subroutine, rtw_kick() that stops the Rx/Tx processes, resets
the chip, reinitializes the Tx/Rx rings, and restarts Rx/Tx
processes. (Inspired by the Linux driver.)

[] In rtw_intr_rx, check for too-short packets before calling
ieee80211_find_rxnode. I believe this will prevent a repeat of
the MCHK exception I saw once on macppc.

[] Use seconds-elapased as well as microseconds-elapsed to set the
next "due date" for the timeout interrupt. This keeps the driver
from programming the timeout to expire too early.

[] In rtw_intr, read RTW_ISR at most 10 times, then get out. If
the interface is not enabled (RTW_F_ENABLED), then get out.

[] In rtw_stop, get out if the interface is not enabled (RTW_F_ENABLED).
Block IPL_NET interrupts. Don't read/write any registers if
the interface is invalid (RTW_F_INVALID).

[] Call rtw_stop in rtw_detach.


Revision tags: kent-audio1-base
# 1.2 30-Oct-2004 thorpej

When adding/deleting multicast addresses, only whack the address
filter if the interface is marked RUNNING.

Fixes kern/27678.


# 1.1 26-Sep-2004 dyoung

branches: 1.1.2;
Add work-in-progress driver rtw(4) for Realtek RTL8180 MAC/baseband.

Add register definitions for Maxim MAX2820 and Philips SA2400 radio
front-ends.


Revision tags: nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.124 15-Sep-2016 jdolecek

remove last isolated islands using BUS_SPACE_BARRIER_SYNC and
BUS_SPACE_BARRIER_X_BEFORE_X - these were only ever defined for mips and ia64,
and never actually implemented even there


Revision tags: localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907
# 1.123 10-Jun-2016 ozaki-r

branches: 1.123.2;
Introduce m_set_rcvif and m_reset_rcvif

The API is used to set (or reset) a received interface of a mbuf.
They are counterpart of m_get_rcvif, which will come in another
commit, hide internal of rcvif operation, and reduce the diff of
the upcoming change.

No functional change.


Revision tags: nick-nhusb-base-20160529
# 1.122 16-May-2016 ozaki-r

Use M_GETCTX and M_SETCTX instead of open-coding rcvif

No functional change.


Revision tags: netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 netbsd-7-0-RELEASE nick-nhusb-base-20150921 netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 nick-nhusb-base-20150606 nick-nhusb-base-20150406 nick-nhusb-base netbsd-7-base yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 rmind-smpnet-nbase rmind-smpnet-base tls-maxphys-base
# 1.121 25-Feb-2014 pooka

branches: 1.121.6;
Ensure that the top level sysctl nodes (kern, vfs, net, ...) exist before
the sysctl link sets are processed, and remove redundancy.

Shaves >13kB off of an amd64 GENERIC, not to mention >1k duplicate
lines of code.


# 1.120 17-Oct-2013 christos

- remove unused variables
- move variables inside ifdef sections
- ifdef notdef unused code
- use __USE for debugging variables


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE yamt-pagecache-tag8 netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 agc-symver-base netbsd-6-1-RC2 netbsd-6-1-RC1 yamt-pagecache-base8 netbsd-6-0-1-RELEASE yamt-pagecache-base7 matt-nb6-plus-nbase yamt-pagecache-base6 netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base10 yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.119 04-Jul-2011 joerg

branches: 1.119.2; 1.119.12; 1.119.16;
Fix memset usage.


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base matt-mips64-premerge-20101231 rmind-uvmplock-base
# 1.118 15-Nov-2010 uebayasi

Socket ioctl definitions need sys/sockio.h.


# 1.117 13-Nov-2010 uebayasi

Don't pull in the whole uvm(9) API to access only PAGE_SIZE and
some other constants. These are provided by sys/param.h now.


Revision tags: uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10 uebayasi-xip-base1
# 1.116 05-Apr-2010 joerg

Push the bpf_ops usage back into bpf.h. Push the common ifp->if_bpf
check into the inline functions as well the fourth argument for
bpf_attach.


# 1.115 15-Mar-2010 dyoung

Make this compile on sparc64:

1 s/next_tick/next_tint/ because next_tick shadows a global on sparc64.

2 Fix the bus-barrier helper routines, which had the tag & handle
swapped (!!). Move the helpers from rtwreg.h to rtwvar.h, and
change RTW_BARRIER() into an inline subroutine called rtw_barrier().


Revision tags: yamt-nfs-mp-base9
# 1.114 24-Feb-2010 dyoung

branches: 1.114.2;
A pointer typedef entails trading too much flexibility to declare const
and non-const types, and the kernel uses both const and non-const
PMF qualifiers and device suspensors, so change the pmf_qual_t and
device_suspensor_t typedefs from "pointers to const" to non-pointer,
non-const types.


Revision tags: uebayasi-xip-base
# 1.113 31-Jan-2010 dyoung

branches: 1.113.2;
Add the missing newline to a verbose autoconf message.


# 1.112 19-Jan-2010 pooka

Redefine bpf linkage through an always present op vector, i.e.
#if NBPFILTER is no longer required in the client. This change
doesn't yet add support for loading bpf as a module, since drivers
can register before bpf is attached. However, callers of bpf can
now be modularized.

Dynamically loadable bpf could probably be done fairly easily with
coordination from the stub driver and the real driver by registering
attachments in the stub before the real driver is loaded and doing
a handoff. ... and I'm not going to ponder the depths of unload
here.

Tested with i386/MONOLITHIC, modified MONOLITHIC without bpf and rump.


# 1.111 08-Jan-2010 dyoung

Expand PMF_FN_* macros.


Revision tags: matt-premerge-20091211 jym-xensuspend-nbase
# 1.110 19-Oct-2009 rmind

Drop 3rd and 4th clauses from David Young's license.
Reviewed and approved by dyoung@ (copyright holder).


# 1.109 16-Sep-2009 dyoung

In pmf(9), improve the implementation of device self-suspension
and make suspension by self, by drvctl(8), and by ACPI system sleep
play nice together. Start solidifying some temporary API changes.

1. Extract a new header file, <sys/device_if.h>, from <sys/device.h> and
#include it from <sys/pmf.h> instead of <sys/device.h> to break the
circular dependency between <sys/device.h> and <sys/pmf.h>.

2. Introduce pmf_qual_t, an aggregate of qualifications on a PMF
suspend/resume call. Start to replace instances of PMF_FN_PROTO,
PMF_FN_ARGS, et cetera, with a pmf_qual_t.

3. Introduce the notion of a "suspensor," an entity that holds a
device in suspension. More than one suspensor may hold a device
at once. A device stays suspended as long as at least one
suspensor holds it. A device resumes when the last suspensor
releases it.

Currently, the kernel defines three suspensors,

3a the system-suspensor: for system suspension, initiated
by 'sysctl -w machdep.sleep_state=3', by lid closure, by
power-button press, et cetera,

3b the drvctl-suspensor: for device suspension by /dev/drvctl
ioctl, e.g., drvctl -S sip0.

3c the system self-suspensor: for device drivers that suspend
themselves and their children. Several drivers for network
interfaces put the network device to sleep while it is not
administratively up, that is, after the kernel calls if_stop(,
1). The self-suspensor should not be used directly. See
the description of suspensor delegates, below.

A suspensor can have one or more "delegates". A suspensor can
release devices that its delegates hold suspended. Right now,
only the system self-suspensor has delegates. For each device
that a self-suspending driver attaches, it creates the device's
self-suspensor, a delegate of the system self-suspensor.

Suspensors stop a system-wide suspend/resume cycle from waking
devices that the operator put to sleep with drvctl before the cycle.
They also help self-suspension to work more simply, safely, and in
accord with expectations.

4. Add the notion of device activation level, devact_level_t,
and a routine for checking the current activation level,
device_activation(). Current activation levels are DEVACT_LEVEL_BUS,
DEVACT_LEVEL_DRIVER, and DEVACT_LEVEL_CLASS, which respectively
indicate that the device's bus is active, that the bus and device are
active, and that the bus, device, and the functions of the device's
class (network, audio) are active.

Suspend/resume calls can be qualified with a devact_level_t.
The power-management framework treats a devact_level_t that
qualifies a device suspension as the device's current activation
level; it only runs hooks to reduce the activation level from
the presumed current level to the fully suspended state. The
framework treats a devact_level_t qualifying device resumption
as the target activation level; it only runs hooks to raise the
activation level to the target.

5. Use pmf_qual_t, devact_level_t, and self-suspensors in several
drivers.

6. Temporarily add an unused power-management workqueue that I will
remove or replace, soon.


Revision tags: yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5 yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 nick-hppapmap-base3 jym-xensuspend-base nick-hppapmap-base
# 1.108 07-Apr-2009 dyoung

Cosmetic: remove some dead code.


# 1.107 02-Apr-2009 dyoung

Add the WEP capability to our net80211 capability flags, since we do
sort of support hardware WEP. Only change the WEP key index in a Tx
descriptor from 0 if the type of our transmit key is _WEP, not _TKIP:
i.e., only if we're really doing WEP crypto in the hardware.

Ignore a watchdog timeout on any Tx ring if we can collect some packets
from that ring. Restart both the receiver and the transmitter when a
watchdog timeout occurs instead of restarting only the transmitter.


Revision tags: nick-hppapmap-base2 haad-dm-base2 haad-nbase2 ad-audiomp2-base haad-dm-base mjf-devfs2-base
# 1.106 12-Nov-2008 ad

branches: 1.106.4;
Remove LKMs and switch to the module framework, pass 1.

Proposed on tech-kern@.


# 1.105 07-Nov-2008 dyoung

*** Summary ***

When a link-layer address changes (e.g., ifconfig ex0 link
02:de:ad:be:ef:02 active), send a gratuitous ARP and/or a Neighbor
Advertisement to update the network-/link-layer address bindings
on our LAN peers.

Refuse a change of ethernet address to the address 00:00:00:00:00:00
or to any multicast/broadcast address. (Thanks matt@.)

Reorder ifnet ioctl operations so that driver ioctls may inherit
the functions of their "class"---ether_ioctl(), fddi_ioctl(), et
cetera---and the class ioctls may inherit from the generic ioctl,
ifioctl_common(), but both driver- and class-ioctls may override
the generic behavior. Make network drivers share more code.

Distinguish a "factory" link-layer address from others for the
purposes of both protecting that address from deletion and computing
EUI64.

Return consistent, appropriate error codes from network drivers.

Improve readability. KNF.

*** Details ***

In if_attach(), always initialize the interface ioctl routine,
ifnet->if_ioctl, if the driver has not already initialized it.
Delete if_ioctl == NULL tests everywhere else, because it cannot
happen.

In the ioctl routines of network interfaces, inherit common ioctl
behaviors by calling either ifioctl_common() or whichever ioctl
routine is appropriate for the class of interface---e.g., ether_ioctl()
for ethernets.

Stop (ab)using SIOCSIFADDR and start to use SIOCINITIFADDR. In
the user->kernel interface, SIOCSIFADDR's argument was an ifreq,
but on the protocol->ifnet interface, SIOCSIFADDR's argument was
an ifaddr. That was confusing, and it would work against me as I
make it possible for a network interface to overload most ioctls.
On the protocol->ifnet interface, replace SIOCSIFADDR with
SIOCINITIFADDR. In ifioctl(), return EPERM if userland tries to
invoke SIOCINITIFADDR.

In ifioctl(), give the interface the first shot at handling most
interface ioctls, and give the protocol the second shot, instead
of the other way around. Finally, let compatibility code (COMPAT_OSOCK)
take a shot.

Pull device initialization out of switch statements under
SIOCINITIFADDR. For example, pull ..._init() out of any switch
statement that looks like this:

switch (...->sa_family) {
case ...:
..._init();
...
break;
...
default:
..._init();
...
break;
}

Rewrite many if-else clauses that handle all permutations of IFF_UP
and IFF_RUNNING to use a switch statement,

switch (x & (IFF_UP|IFF_RUNNING)) {
case 0:
...
break;
case IFF_RUNNING:
...
break;
case IFF_UP:
...
break;
case IFF_UP|IFF_RUNNING:
...
break;
}

unifdef lots of code containing #ifdef FreeBSD, #ifdef NetBSD, and
#ifdef SIOCSIFMTU, especially in fwip(4) and in ndis(4).

In ipw(4), remove an if_set_sadl() call that is out of place.

In nfe(4), reuse the jumbo MTU logic in ether_ioctl().

Let ethernets register a callback for setting h/w state such as
promiscuous mode and the multicast filter in accord with a change
in the if_flags: ether_set_ifflags_cb() registers a callback that
returns ENETRESET if the caller should reset the ethernet by calling
if_init(), 0 on success, != 0 on failure. Pull common code from
ex(4), gem(4), nfe(4), sip(4), tlp(4), vge(4) into ether_ioctl(),
and register if_flags callbacks for those drivers.

Return ENOTTY instead of EINVAL for inappropriate ioctls. In
zyd(4), use ENXIO instead of ENOTTY to indicate that the device is
not any longer attached.

Add to if_set_sadl() a boolean 'factory' argument that indicates
whether a link-layer address was assigned by the factory or some
other source. In a comment, recommend using the factory address
for generating an EUI64, and update in6_get_hw_ifid() to prefer a
factory address to any other link-layer address.

Add a routing message, RTM_LLINFO_UPD, that tells protocols to
update the binding of network-layer addresses to link-layer addresses.
Implement this message in IPv4 and IPv6 by sending a gratuitous
ARP or a neighbor advertisement, respectively. Generate RTM_LLINFO_UPD
messages on a change of an interface's link-layer address.

In ether_ioctl(), do not let SIOCALIFADDR set a link-layer address
that is broadcast/multicast or equal to 00:00:00:00:00:00.

Make ether_ioctl() call ifioctl_common() to handle ioctls that it
does not understand.

In gif(4), initialize if_softc and use it, instead of assuming that
the gif_softc and ifp overlap.

Let ifioctl_common() handle SIOCGIFADDR.

Sprinkle rtcache_invariants(), which checks on DIAGNOSTIC kernels
that certain invariants on a struct route are satisfied.

In agr(4), rewrite agr_ioctl_filter() to be a bit more explicit
about the ioctls that we do not allow on an agr(4) member interface.

bzero -> memset. Delete unnecessary casts to void *. Use
sockaddr_in_init() and sockaddr_in6_init(). Compare pointers with
NULL instead of "testing truth". Replace some instances of (type
*)0 with NULL. Change some K&R prototypes to ANSI C, and join
lines.


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 wrstuden-revivesa-base-1 simonb-wapbl-nbase yamt-pf42-base4 simonb-wapbl-base yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 yamt-nfs-mp-base2 wrstuden-revivesa-base yamt-nfs-mp-base yamt-pf42-base ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 1.104 15-Mar-2008 dyoung

branches: 1.104.4; 1.104.10; 1.104.12;
Cosmetic: make rtw_hw_keysupp() return a bool instead of int. In
rtw_wep_setkeys(), add a debug printf, and move the initialization
of keylen from the for-loop to the declaration.


# 1.103 14-Mar-2008 dyoung

Extract subroutine rtw_tx_kick() from rtw_start(), and reuse it in
rtw_io_enable() to restart the transmitter after resetting it.


# 1.102 14-Mar-2008 dyoung

Change tests for "impossible" keys to KASSERT()s. Get rid of a
temporary variable. In rtw_key_delete(), do not invalidate the
hardware keys unless a WEP key is deleted.


# 1.101 12-Mar-2008 dyoung

Use device_t and its accessors throughout. Use aprint_*_dev().

Improve PMF-ability.

Add a 'flags' argument to suspend/resume handlers and
callers such as pmf_system_suspend().

Define a flag, PMF_F_SELF, which indicates to PMF that a
device is suspending/resuming itself. Add helper routines,
pmf_device_suspend_self(dev) and pmf_device_resume_self(dev),
that call pmf_device_suspend(dev, PMF_F_SELF) and
pmf_device_resume(dev, PMF_F_SELF), respectively. Use
PMF_F_SELF to suspend/resume self in ath(4), audio(4),
rtw(4), and sip(4).

In ath(4) and in rtw(4), replace the icky sc_enable/sc_disable
callbacks, provided by the bus front-end, with
self-suspension/resumption. Also, clean up the bus
front-ends. Make sure that the interrupt handler is
disestablished during suspension. Get rid of driver-private
flags (e.g., RTW_F_ENABLED, ath_softc->sc_invalid); use
device_is_active()/device_has_power() calls, instead.

In the network-class suspend handler, call if_stop(, 0)
instead of if_stop(, 1), because the latter is superfluous
(bus- and driver-suspension hooks will 'disable' the NIC),
and it may cause recursion.

In the network-class resume handler, prevent infinite
recursion through if_init() by getting out early if we are
self-suspending (PMF_F_SELF).

rtw(4) improvements:

Destroy rtw(4) callouts when we detach it. Make rtw at
pci detachable. Print some more information with the "rx
frame too long" warning.

Remove activate() methods:

Get rid of rtw_activate() and ath_activate(). The device
activate() methods are not good for much these days.

Make ath at cardbus resume with crypto functions intact:

Introduce a boolean device property, "pmf-powerdown". If
pmf-powerdown is present and false, it indicates that a
bus back-end should not remove power from a device.

Honor this property in cardbus_child_suspend().

Set this property to 'false' in ath_attach(), since removing
power from an ath at cardbus seems to lobotomize the WPA
crypto engine. XXX Should the pmf-powerdown property
propagate toward the root of the device tree?

Miscellaneous ath(4) changes:

Warn if ath(4) tries to write crypto keys to suspended
hardware.

Reduce differences between FreeBSD and NetBSD in ath(4)
multicast filter setup.

Make ath_printrxbuf() print an rx descriptor's status &
key index, to help debug crypto errors.

Shorten a staircase in ath_ioctl(). Don't check for
ieee80211_ioctl() return code ERESTART, it never happens.


# 1.100 12-Mar-2008 dyoung

Print the TPPoll register when the Tx DMA engine doesn't shut down
in the time we allow.


# 1.99 03-Mar-2008 tsutsui

Explicitly include <sys/device.h> for device_t.


Revision tags: nick-net80211-sync-base vmlocking2-base3 bouyer-xeni386-nbase bouyer-xeni386-base mjf-devfs-base matt-armv6-base hpcarm-cleanup-base
# 1.98 21-Dec-2007 dyoung

branches: 1.98.2; 1.98.6;
Do not embed a struct device in rtw_softc any longer. Register
both pci and cardbus attachments with CFATTACH_DECL_NEW(). Access
the softc through the device_t using device_private().

While I'm here, change a couple of KASSERT()s about the Rx buffer
length to a warning.


# 1.97 20-Dec-2007 dyoung

Remove shutdown hooks. Use KASSERT().


# 1.96 16-Dec-2007 dyoung

Fix a bug I introduced to rtw_chan2txpower() the other night.

Fix a bug in device detachment: change a break statement to a
/*FALLTHROUGH*/ in rtw_detach().


# 1.95 16-Dec-2007 dyoung

Synchronize device detachment with network interrupts. Use the
pmf network class instead of powerhooks.


Revision tags: yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 bouyer-xenamd64-base2 vmlocking-nbase bouyer-xenamd64-base jmcneill-pm-base reinoud-bufcleanup-base
# 1.94 18-Nov-2007 jnemeth

branches: 1.94.2; 1.94.6;
fix 'm' used unitialized


# 1.93 16-Nov-2007 dyoung

Accommodate the variety of RF front-ends when radiotapping frames:
tap only RSSI when there is a Philips RF front-end. Tap both Barker
lock quality and RSSI when there is any other RF front-end.

Provide radiotap listeners a more complete picture of channel
activity:

in promiscuous mode, tap frames who do not pass the CRC32 check.
Flag packets that were received with a short preamble. Ask
the NIC to pass us 802.11 Control frames. Pass frames to
radiotap listeners before stripping the FCS. Re-order operations
in rtw_intr_rx() in order to accomplish all of this, taking
care not to pass a broken packet to net80211!

Do not provide a flags field when tapping xmitted frames.

Assert sane Rx packet lengths. Really should check and drop instead
of KASSERTing. I will revisit this, soon.

Update copyright.


# 1.92 15-Nov-2007 dyoung

Fix order of operations:

rtw_rxdesc_init: before initializing a Rx descriptor's
control word, synchronize the Rx buffer

rtw_start, be paranoid: set the "NIC owns" bit on a Tx
descriptor dead last. Always reinitialize the "next
Tx descriptor" pointer, just in case it got clobbered
somehow.

Let the compiler decide whether to inline rtw_collect_txring or
not.


Revision tags: jmcneill-base
# 1.91 19-Oct-2007 ad

branches: 1.91.2;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h


Revision tags: yamt-x86pmap-base4 yamt-x86pmap-base3 yamt-x86pmap-base2 vmlocking-base
# 1.90 29-Sep-2007 scw

branches: 1.90.2;
s/NPBFILTER/NBPFILTER/ in some #endif comments. No functional change.


Revision tags: nick-csl-alignment-base5 yamt-x86pmap-base matt-mips64-base nick-csl-alignment-base mjf-ufs-trans-base
# 1.89 09-Jul-2007 ad

branches: 1.89.6; 1.89.8; 1.89.10;
Merge some of the less invasive changes from the vmlocking branch:

- kthread, callout, devsw API changes
- select()/poll() improvements
- miscellaneous MT safety improvements


# 1.88 29-May-2007 dyoung

Fix rtw(4) on NetBSD/macppc: use bus_space_write_region_stream_4()
instead of bus_space_write_region_4() to write WEP Rx keys to the
NIC. Thanks macallan@ for detecting the bug and testing the fix.


# 1.87 29-May-2007 dyoung

Cosmetic: simplify a memset() statement, use __arraycount(), and
remove a gratuitous return statement at the end of a void subroutine.


# 1.86 29-May-2007 dyoung

Simplify multicast filter programming, and take care to avoid
gratuitous device resets when the kernel adds/deletes a multicast
address.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base
# 1.85 04-Mar-2007 christos

branches: 1.85.2; 1.85.4;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.


Revision tags: ad-audiomp-base post-newlock2-merge newlock2-nbase newlock2-base
# 1.84 29-Jan-2007 dyoung

branches: 1.84.2;
In rtw_dequeue(), initialize *mp to NULL before anything else, so
that it is either NULL or a valid mbuf. Previously, it was possible
for rtw_dequeue() to exit with 0 before initializing *mp. rtw_start()
would have used whatever trash was in *mp, which would lead to
problems later on.


# 1.83 06-Jan-2007 dyoung

I have made a small change that suppresses "recovery" from (spurious?)
tx timeouts on the beacon queue. The driver's recovery process
badly disrupts the MAC's receiver. This needs a closer look, later.

Every other fix is by Charles M. Hannum. Charles writes:

"With these, the device is quite stable under load, does not experience
xmit timeouts, no longer mysteriously freezes, and does not spew
a lot of garbage. It does, however, continue to get some "tx fifo
underflow"s.

global, SYSCTL_SETUP():
a) Removed unused sysctl variables.

rtw_io_enable():
b) Change rtw_io_enable to take a softc, and make it call
rtw_txring_fixup().
c) Enable the PCI multiple read/write bit.
d) Always reset rdb_next to 0 when starting the receive engine.

rtw_intr_rx():
e) When processing receive packets, store the next pointer in rdb_next
and read it back on the next round, to fix a race condition vs.
rtw_tune() during AP discovery and association.
f) Remove the special "skip to 0th descriptor" code, because it is no
longer needed.

rtw_collect_txring():
g) In the "force" case, stop when we catch up to the hardware xmit
pointer.

rtw_intr_beacon():
h) Resetting tdb_next here looked fishy to me, in light of changes in
rtw_collect_txring(). XXX However, this is the one part I haven't
tested.

rtw_txring_fixup():
i) Add function and line arguments, so we can print out information
about the caller.
j) In addition to reading the hardware pointer, skip over any
additional packets with OWN set -- we may have queued more.

rtw_rxring_fixup():
k) Remove this, because it's completely wrong.

rtw_intr_ioerror():
l) Don't handle receive overruns here; handle them in the normal receive
path. Also changed RTW_INTR_RX and RTW_INTR_IOERROR accordingly.
m) Do not fiddle with CR; the transmit engine is still running just
fine.
n) Do not fiddle with IMR; it was unnecessary.
o) Don't touch the receive engine at all; not necessary now that we're
leaving CR alone.
p) Remove the rtw_do_chip_reset case; it was dangerous and not actually
used.

rtw_intr():
q) Don't mask off ISR bits when we pass down the ISR value; it's not
necessary, and sometimes the other bits useful in debugging output.

rtw_seg_too_short():
r) Don't spew here; the caller will do it if necessary. (Stops spewage
in an expected case.)

rtw_rxdesc_blk:
s) Minor change to make the elements have the same order as txdesc_blk.

general:
t) Added a bunch of debugging output, #ifdef RTW_DIAG, that was useful
while investigating the ring management problems. Also moved
rtw_txring_fixup() into RTW_DIAG, as I believe the transmit pointer
is always kept in sync now, and the function has potential race
conditions.


# 1.82 06-Jan-2007 dyoung

After we examine a rx/tx descriptor and find that it's still owned
by the NIC, re-sync the descriptor so that a cacheline will not
"cover" the NIC's modifications to the descriptor when we next
examine it.

This compiles, but I have not tested it, yet.


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase wrstuden-fixsa-base-1 netbsd-4-0-RELEASE netbsd-4-0-RC5 matt-nb4-arm-base netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 wrstuden-fixsa-base yamt-splraiseipl-base5 yamt-splraiseipl-base4 yamt-splraiseipl-base3 netbsd-4-base
# 1.81 16-Nov-2006 christos

__unused removal on arguments; approved by core.


# 1.80 13-Nov-2006 dyoung

Stop using typeof() in the bit-twiddling macros, per yamt@'s
suggestion. This change requires that I use the __PRIuBITS format
string in atw and rtw, so do that.


Revision tags: yamt-splraiseipl-base2
# 1.79 12-Oct-2006 xtraeme

Use __unused in function arguments where appropiate.


# 1.78 12-Oct-2006 christos

- sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386


# 1.77 24-Sep-2006 jmcneill

Add "name" parameter to powerhook_establish, to aid debugging. No objections
on tech-kern@


Revision tags: yamt-splraiseipl-base yamt-pdpolicy-base9 yamt-pdpolicy-base8 rpaulo-netinet-merge-pcb-base
# 1.76 03-Sep-2006 christos

branches: 1.76.2; 1.76.4;
- comment out impossible comparisons
- remove superfluous if statement


# 1.75 31-Aug-2006 dyoung

Per discussion on tech-kern and tech-userlevel, move the bit-twiddling
macros, __BIT, __BITS, SHIFTIN, SHIFTOUT, and __arraycount() from
lib/libkern/libkern.h to sys/cdefs.h. Add a __-prefix to SHIFTIN
and SHIFTOUT, and add a manual page for the bit-twiddling macros,
bits(3).

Make the __BIT and __BITS macros "widthless," as best I can, by
changing their type to uintmax_t from uint32_t. XXX The manual
page lags this change by a bit.

Define __PRIxBIT and __PRIxBITS printf(3) format strings.


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base7 yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base simonb-timecounters-base
# 1.74 26-May-2006 blymn

Clean up bogus whitespace


Revision tags: yamt-pdpolicy-base5
# 1.73 14-May-2006 christos

branches: 1.73.2;
XXX: GCC uninitialized


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 elad-kernelauth-base
# 1.72 28-Mar-2006 dyoung

Revamp ieee80211_get_rate. Now it does not use the rateset in the
ic->ic_bss, but it uses the rateset in its new ieee80211_node
argument, instead. If the rate is fixed by ic->ic_fixed_rate, but
the fixed rate is not in the node's rateset, choose a reasonable
default: prefer the lowest basic rate or, if there is no basic
rate, prefer the lowest rate, period.

Change a printf complaint to a debug message.

Adapt drivers to suit new ieee80211_get_rate calling convention.

XXX I really need to replace ieee80211_get_rate with a bitrate
XXX adaptation algorithm. Soon, soon....


# 1.71 27-Mar-2006 dyoung

Set the channel frequency and flags in the radiotap headers in
rtw_tune instead of in rtw_start, rtw_intr_rx.


# 1.70 27-Mar-2006 dyoung

Remove unused argument ifflagsp from rtw_dmamap_load_txbuf.


Revision tags: peter-altq-base yamt-pdpolicy-base2
# 1.69 08-Mar-2006 dyoung

branches: 1.69.2;
Change macro names to avoid collisions:

BIT -> __BIT
BITS -> __BITS


# 1.68 08-Mar-2006 dyoung

Move my bit-twiddling macros to libkern.h from my drivers, where
I had duplicated them. Improve the macros' names. Simplify their
implementation.

A brief description of each macro is below.

BIT(n): Return a bitmask with bit m set, where the least
significant bit is bit 0.

BITS(m, n): Return a bitmask with bits m through n, inclusive,
set. It does not matter whether m>n or m<=n.
The least significant bit is bit 0.

A "bitfield" is a span of consecutive bits defined by a
bitmask, where 1s select the bits in the bitfield. SHIFTIN,
SHIFTOUT, and SHIFTOUT_MASK help read and write bitfields
from device registers.

SHIFTIN(v, mask): Left-shift bits `v' into the bitfield
defined by `mask', and return them. No
side-effects.

SHIFTOUT(v, mask): Extract and return the bitfield selected
by `mask' from `v', right-shifting the
bits so that the rightmost selected bit
is at bit 0. No side-effects.

SHIFTOUT_MASK(mask): Right-shift the bits in `mask' so that
the rightmost non-zero bit is at bit
0. This is useful for finding the
greatest unsigned value that a bitfield
can hold. No side-effects. Note that
SHIFTOUT_MASK(m) = SHIFTOUT(m, m).

Examples:

/*
* Register definitions taken from the RFMD RF3000 manual.
*/
#define RF3000_GAINCTL 0x11 /* TX variable gain control */
#define RF3000_GAINCTL_TXVGC_MASK BITS(7, 2)
#define RF3000_GAINCTL_SCRAMBLER BIT(1)

/*
* Shift the transmit power into the transmit-power field of the
* gain-control register and write it to the baseband processor.
*/
atw_rf3000_write(sc, RF3000_GAINCTL,
SHIFTIN(txpower, RF3000_GAINCTL_TXVGC_MASK));


/*
* Register definitions taken from the ADMtek ADM8211 manual.
*
*/
#define ATW_RXSTAT_OWN BIT(31) /* 1: NIC may fill descriptor */
/* ... */
#define ATW_RXSTAT_DA1 BIT(17) /* DA bit 1, admin'd address */
#define ATW_RXSTAT_DA0 BIT(16) /* DA bit 0, group address */
#define ATW_RXSTAT_RXDR_MASK BITS(15,12) /* RX data rate */
#define ATW_RXSTAT_FL_MASK BITS(11,0) /* RX frame length, last
* descriptor only
*/

/* Extract the frame length from the Rx descriptor's
* status field.
*/
len = SHIFTOUT(rxstat, ATW_RXSTAT_FL_MASK);


Revision tags: yamt-pdpolicy-base yamt-uio_vmspace-base5
# 1.67 20-Feb-2006 thorpej

branches: 1.67.2; 1.67.4;
Use device_is_active() rather than testing dv_flags for DVF_ACTIVE
directly.


# 1.66 19-Feb-2006 dyoung

When rtw_enable is called, power may have been removed and re-applied,
so invalidate the WEP key registers to force us to write the keys
back to the hardware.

Revamp key handling: use the hardware WEP engine for 40-bit and
104-bit keys, only; use software WEP for all other key lengths.
Set the hardware key length to the length of the default Tx key,
or if there is no default Tx key, use the length of the longest
WEP key.


# 1.65 04-Feb-2006 dyoung

In rtw_{rx,tx}ring_fixup, do not set the tx/rx ring index to
something out of bounds if we read an invalid pointer form the
hardware. Prevents a panic when an rtw@cardbus is ejected.


# 1.64 29-Dec-2005 dyoung

branches: 1.64.2; 1.64.4; 1.64.6;
Add support for the GCT Semiconductor GRF5101 transceiver/synthesizer.
From OpenBSD.

GCT will not provide any documentation, so there are many magic
numbers in this code.


# 1.63 29-Dec-2005 dyoung

Update rtw(4) for the new IBSS merge idiom, where ieee80211_ibss_merge()
does not return ENETRESET if the driver should change its BSSID,
but it makes a RUN->RUN transition, instead.


# 1.62 29-Dec-2005 dyoung

In atw(4), use ieee80211_compute_duration() to compute IEEE 802.11
Duration and PLCP Length fields, and delete the abominable
atw_frame_setdurs() subroutine.

Make rtw(4) use the new ieee80211_compute_duration() calling
convention.

Add an ieee80211_key argument to ieee80211_compute_duration() and
lightly constify arguments. Get the crypto header length from the
key argument instead of blithely assuming a WEP header. Add some
inline documentation. Account for data padding (IEEE80211_F_DATAPAD).


# 1.61 24-Dec-2005 perry

Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.


# 1.60 13-Dec-2005 dyoung

Fix comments and debug printfs: Tx FIFOs underflow, they don't
overflow.


# 1.59 13-Dec-2005 dyoung

On a transmit FIFO overflow (err, actually an underflow...) reset
both the transmit & receive sections of the MAC.


Revision tags: yamt-readahead-base3 ktrace-lwp-base
# 1.58 23-Nov-2005 dyoung

Miscellaneous Realtek RTL8180L driver improvements:

1 Added new sysctl controls for debugging.

2 Improve detection & support for hardware WEP.

3 Revamp handling of transmit descriptor rings.

4 Reliably IFF_OACTIVE when transmit descriptors are available, to
stop the transmit section of the driver from freezing up.

5 Fix beacon transmission in adhoc and hostap modes. XXX There is
a wart in hostap mode, where beacons are transmitted at 1/2 the
correct rate. Load beacon descriptors when the RTW_INTR_BINT
interrupt arrives; schedule RTW_INTR_BINT 1ms ahead of the target
beacon time.

6 Recover more gracefully from tx/rx errors: avoid
transmitter/receiver/chip resets. Try to re-synchronize software
state with hardware state---e.g., load next descriptor pointer
from hardware.

7 Activate the transmit watchdog timer for beacons as well as other
packets.

8 Introduce rtw_idle() that waits for transmit DMA to finish; call
it before resetting the transmitter.


Revision tags: yamt-readahead-base2
# 1.57 18-Nov-2005 skrll

Adapt drivers to the new net80211(9).

Most of this is from dyoung@. Thanks!


Revision tags: yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base
# 1.56 22-Sep-2005 gdt

branches: 1.56.6;
Make arg of IFQ_SET_READY be &ifp->if_snd, to match all other drivers
and be compilable with altq enabled. Reviewed by dyoung@


# 1.55 07-Sep-2005 dogcow

With the assistance of dyoung, fix the following problems:
* some 8180L cards need a longer time for the srom to initialize; patch
suggested via OpenBSD.
* some cards give '0' for USA, some give '3'; for the meantime, accept both
as being USA locale cards.
* this is RTW, not ATW. :)


# 1.54 06-Sep-2005 dogcow

make rtw.c compile again after the 22-jun-05 net80211 import


# 1.53 11-Jul-2005 dyoung

Add undefined variable 'ic' to rtw_attach.


# 1.52 06-Jul-2005 dyoung

Historically, an(4), ath(4), atw(4), rtw(4), and wi(4) have printed
out their modes and rates at boot. Revert to the historical
behavior.


# 1.51 06-Jul-2005 dyoung

Avoid an unnecessary API difference between NetBSD and FreeBSD:
back out my change to ieee80211_crypto_encap that made it free its
mbuf argument on error. I had thought it was a bug. It was not.
It's the drivers that are broken. Make an(4), atw(4), ipw(4),
iwi(4), ral(4), rtw(4), ural(4), and wi(4) free the mbuf when
ieee80211_crypto_encap returns NULL. Also, return ath(4) to the
way it was---i.e., free the mbuf.

Thanks to Sam Leffler to pointing out my mistake.


# 1.50 28-Jun-2005 dyoung

branches: 1.50.2;
Here is a grotty hack that lets the RTL8180L handle WEP in the
receive direction, while software handles WEP in the transmit
direction. When net80211 calls rtw's rtw_key_set with a WEP key,
I point the key's wk_cipher at our "fake" cipher, rtw_cipher_wep,
which is alike to ieee80211_cipher_wep except it provides a different
crypto-decapsulation routine, rtw_wep_decap. rtw_wep_decap copies
the key passed to it by net80211, clears the key's SWCRYPT flag,
and then calls wep_decap. Now wep_decap will decapsulate, but it
will *not* re-decrypt.

XXX I need to check whether the hardware supports 40-bit WEP,
XXX 104-bit WEP, or both, and act accordingly.


# 1.49 27-Jun-2005 dyoung

rtw: Try to get hardware WEP to work. It seems to work in
the RX direction, but not in the TX direction. The
net80211 crypto framework doesn't seem to cope very well
with the assymetry (I'm probably missing something), so
I will use software WEP for now.

net80211: In ieee80211_compute_duration, figure out whether to add
the WEP header to the packet overhead by checking the
WEP bit in the Frame Control field of the 802.11 header,
instead of checking the IEEE80211_F_PRIVACY flag.

Also, if the WEP bit is present, assume that the frame
described by (wh, len) has already already been WEP
encapsulated, and adjust the payload length accordingly.
XXX that's a grotty hack that I will have to revisit,
later.


# 1.48 22-Jun-2005 dyoung

Resolve conflicts in importation of 18-May-2005 ath(4) / net80211(9)
from FreeBSD. Introduce compatibility shims (sys/dev/ic/ath_netbsd.[ch],
sys/net80211/ieee80211_netbsd.[ch]). Update drivers (an, atu, atw,
awi, ipw, iwi, rtw, wi) for the new net80211(9) API.


# 1.47 20-Jun-2005 atatat

Change the rest of the sysctl subsystem to use const consistently.
The __UNCONST macro is now used only where necessary and the RW macros
are gone. Most of the changes here are consumers of the
sysctl_createv(9) interface that now takes a pair of const pointers
which used not to be.


# 1.46 10-Jun-2005 dyoung

Sprinkle __UNCONST() and rename variables to quiet uiet -Wcast-qual,
-Wshadow complaints.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 yamt-km-base4 yamt-km-base3 netbsd-3-base kent-audio2-base
# 1.45 02-Mar-2005 dyoung

Misc. changes to improve ad hoc mode and to enable hostap mode:

Fix the work-around for the NIC bug where it skips to rx
descriptor 0. The driver used to skip to rx descriptor 1.
Hopefully this stops the out-of-order packet reception that
Charles Hannum saw.
When debugging is enabled, print rx-descriptor status flags
before printing the rx bit rate.

Add a debug message for when a beacon tx buffer reclamation.

Reset IFF_OACTIVE when we reset the transmitter.

Pass the consolidated LED state, a struct rtw_led_state,
to rtw_led_attach.

Choose the bit-rate for management frames (1Mb/s) at the
same place we choose for all other frames.

Do not use the NIC's short preamble or RTS options for
management frames. Label beacons for the NIC.

Following a Linux driver, take care not to zero arbitrary
bits in the TPPOLL register.

Use the new idiom for IBSS merges: disable transmitter,
kick the state machine.
Add a second descriptor to the beacon ring. The NIC seems
to like this much better.


# 1.44 27-Feb-2005 perry

nuke trailing whitespace


Revision tags: yamt-km-base2
# 1.43 31-Jan-2005 thorpej

Eliminate use of M_HASFCS.


Revision tags: yamt-km-base
# 1.42 16-Jan-2005 dyoung

branches: 1.42.2; 1.42.4;
Move the register access mode into struct rtw_regs. Change
rtw_set_access, rtw_set_access1 to match.

Add a subroutine for setting WEP keys. WEP isn't quite finished,
because I have to add the WEP header to Tx packets. Implement the
SIOCS80211NWKEY ioctl for setting WEP keys.

Program the LEDs based on operating state and packet activity.

* On a Revision F RTL8180, blink LED1 at 1Hz to indicate
scan/authenticate/associate states. In the run state, turn LED1
on. In every state, blink LED1 at 5Hz to indicate non-beacon
tx/rx activity. I would like to use two LEDs, but in all my
Rev. F instances, LED0 is not wired to an LED; instead, the
first LED is wired to indicate that the card's power is on.

* On a Revision D RTL8180, program the LEDs so that LED0 indicates
Tx, and LED1 indicates Rx. The Rx LED will blink annoyingly if
there are beacons in the air, but at least the Tx LED is useful.

* Store the hardware revision in the softc to support my futile
attempt at programming LEDs for both Rev. D and Rev. F parts;
I never did get Rev. D LEDs to work right.

* Add a debug flag RTW_DEBUG_LED for the LED transitions.

Add RTW_TPPOLL_ALL, RTW_TPPOLL_SALL to start and stop, respectively,
all of the transmit rings.

In ad hoc mode, allocate a beacon and load it into the beacon ring.
Start the ring. In one trial, the card re-transmitted the beacon
ring's contents several times before stopping. More programming
and testing for ad hoc mode is necessary. I'm not setting the
beacon flag in the transmit descriptor.

Revamp the transmit section to make better use of all the transmit
rings: beacon queue, high-, low-, and medium-priority rings. Put
beacon frames on the beacon ring. All other management frames,
and data frames, go on the medium-priority ring. Power-save data
frames go on the high-priority ring. (Note that powersaving is
not implemented!) This is a work in progress.

Send all 802.11 Management frames at 1Mbps.

After we put a packet on a transmit ring, tickle the right bit in
the TPPOLL to tell RTL8180. Stop all rings on error and in rtw_stop.

Use the RF chip type, not the RTL8180 revision, to choose between
host- and MAC-controlled RF serial I/O. Now the Netgear MA521
works.

Remove bogus definition of bit RTW_TPPOLL_FSWINT.


Revision tags: kent-audio1-beforemerge
# 1.41 04-Jan-2005 dyoung

Set initial conditions to guarantee that when read_seeprom toggles
Chip Select, it turns *on* rather than *off*.


# 1.40 04-Jan-2005 dyoung

Add the logic for IBSS merges.


# 1.39 03-Jan-2005 dyoung

sys/dev/ic/rtw.c:

Cosmetic: remove two short ladders from rtw_init. Fit the
NIC registers print-out onto one line using the RTW_PRINT_REGS
macro.

sys/dev/ic/rtwvar.h:

Add RTW_PRINT_REGS wrapper macro for rtw_print_regs. It
is a null op unless defined(RTW_DEBUG).


# 1.38 03-Jan-2005 dyoung

In sys/dev/ic/rtw.c:

Use clue from rtk(4) and re(4) to fix the rtw(4) packet
filter. Previously, I was using the wrong CRC32 function
to hash multicast addresses; to compensate, I set the
multicast filter to all 1s. Now that I hash the addresses
correctly, I do not any longer set the filter to all 1s.

In rtw_ioctl, avoid gratuitous re-initialization when the
interface flags change. If a !IFF_UP -> IFF_UP transition,
call rtw_init(); otherwise, only reload the packet filter.

In sys/dev/ic/rtwreg.h:

Put useful combinations of Receiver Control Register flags
in RTW_RCR_PKTFILT_MASK, RTW_RCR_MONITOR, and
RTW_RCR_PKTFILT_DEFAULT. (XXX RTW_RCR_MONITOR should be
called RTW_RCR_PKTFILT_MONITOR.)


# 1.37 02-Jan-2005 dyoung

Cosmetic: change u_int{8,16,32,64}_t to C99-style uint{8,16,32,64}_t,
which is preferred.


# 1.36 29-Dec-2004 dyoung

In rtw_detach, flag the rtw as "invalid" (RTW_F_INVALID). Do not
try to power-down the RF section of an invalid rtw.

The radiotap signal quality field is 16, not 8, bits wide. Convert
the byte order.


# 1.35 29-Dec-2004 dyoung

Remove some dead code.


# 1.34 29-Dec-2004 dyoung

I like the tlp/atw-style names for software descriptors, txsoft,
better than txctl. Change from rtw_txctl/rtw_rxctl to
rtw_txsoft/rtw_rxsoft. Change the descriptor blocks' names to
match: rtw_txctl_blk becomes rtw_txsoft_blk. Change the member-name
prefixes for both software and hardware descriptors.


# 1.33 29-Dec-2004 dyoung

Consolidate variables related to the rx ring in sc_rxdesc_blk,
which is a struct rtw_rxdesc_blk.

Put a copy of the DMA tag and the DMA map into the rx- and tx-ring
blocks so that I don't have to pass them to subroutines all of the
time.


# 1.32 28-Dec-2004 dyoung

Add bpf(4) packet taps to rtw(4). Now you can tap DLT_EN10MB
(Ethernet II), DLT_IEEE802_11 (802.11), and DLT_IEEE802_11_RADIO
(radiotap + 802.11).


# 1.31 28-Dec-2004 dyoung

If defined(RTW_DEBUG), provide a sysctl (hw.rtw.rxbufs_limit) for
limiting the number of rx buffers an rtw may allocate. Use this
sysctl to test the code that copes with buffer exhaustion.

Allocate at most RTW_RXQLEN rx buffers, stopping at the sysctl
limit. Record in sc_nrxdesc how many were allocated, and put the
end-of-ring indication on sc_rxdesc[sc_nrxdesc - 1]. In rtw_init,
if no rx buffers could be allocated, log a complaint, clear
IFF_RUNNING, and exit with an error.

Many changes to accomodate a short rx ring, mainly of the "add a
rx-ring length argument" variety. XXX I really should consolidate
all of the rx ring variables in one struct and pass that to the
rx-ring subroutines.

Bug fix: after calling MCLGET, use the (m->m_flags & M_EXT) idiom
to check for success, instead of m != NULL.

Bug fix: at the top of rtw_start, if IFF_RUNNING is not set, or
IFF_OACTIVE is, get out.


# 1.30 27-Dec-2004 dyoung

Use a table to convert the hardware's bit rates (0, 1, 2, 3) to
net80211 bit rates (2, 4, 11, 22).

Count input errors (if_ierrors++) for "DMA error/FIFO overflow"
and unknown bit rate.


# 1.29 27-Dec-2004 dyoung

Simplify the reset we do on a transmit timeout. Really, this could
be as simple as rtw_stop(, 0), rtw_init().


# 1.28 27-Dec-2004 mycroft

Use the last descriptor to count collisions and failed transmissions, too.


# 1.27 27-Dec-2004 mycroft

When checking if a split packet is completed, check the *last* segment, not
the first. Otherwise we can overwrite parts of the TX ring that we shouldn't.

Kluge the basic rate setting for now.

Minor simplification to the dequeueing logic.


# 1.26 27-Dec-2004 dyoung

Remove useless debug sysctls.

For AP scanning, change the channel dwell time from 1 second to
1/5 second.


# 1.25 27-Dec-2004 mycroft

Replace d_plcp_svc with d_residue. The latter is the number of whole
empty/unused octets to fill out the data time slot. The value is constrained
by math to 0 for <= 5.5Mb, 0-1 for 11Mb, and 0-2 for 22Mb. It is used to
signal to the MAC that there is residue.


# 1.24 26-Dec-2004 dyoung

Make rtw(4) build w/o RTW_DEBUG. Thanks to Charles Hannum for
pointing out my oversight.


# 1.23 25-Dec-2004 dyoung

The rx descriptor ring bug happens quite often, so printf'ing
occurrences is annoying. Only printf about it when rtw_debug
contains RTW_DEBUG_BUG.


# 1.22 25-Dec-2004 dyoung

IMPORTANT: set m->m_pkthdr.rcvif on rx'd packets. Illegal memory
references abound without this fix.

In rtw_intr_rx, skip to the next rx packet earlier if the rx packet
length is too short.

Also in rtw_intr_rx, if a packet is rx'd with unknown rate, printf
a warning, drop the packet, recycle the rx buffer, skip to next rx
packet.


# 1.21 25-Dec-2004 dyoung

Change rtw_debug from a debug level to a debug mask. Add a lot of
debug flags.

From Linux: handle an RTL8180 bug. Sometimes the NIC skips from
the middle of the ring to the 0th rx descriptor. Now the driver
resynchronizes.

Handle a receive descriptor underrun or Rx FIFO overflow condition
in the way that the Linux driver does. This kind of seems like
overkill, but whatever.

Protect rtw_ioctl with splnet().

Do not load a tx descriptor with a buffer shorter than 4 bytes.

Handle a transmit timeout less disruptively.


# 1.20 23-Dec-2004 dyoung

Oops, straggler from last commit: set the 802.11 Duration field
with the result from ieee80211_compute_duration.


# 1.19 23-Dec-2004 dyoung

Fix a bug in ieee80211_compute_duration: the 802.11 Duration field
in an 802.11 unicast data packet is equal to the duration of the
SIFS and Acknowledgement. That is, the amount of time reserved
*after* the packet has finished transmitting.

Change the arguments to ieee80211_compute_duration: pass the entire
packet length, not just the payload length. Add a 'debug' argument
to ieee80211_compute_duration and its helper subroutine,
ieee80211_compute_duration1.

If debug != 0, ieee80211_compute_duration printfs its arguments
and several local variables.

In rtw(4), load the 802.11 Duration field with the result from
ieee80211_compute_duration.


# 1.18 23-Dec-2004 dyoung

Bug fix: in rtw_rxbuf_alloc, unload the previous mbuf chain before
loading the new chain.


# 1.17 23-Dec-2004 dyoung

DMA-synchronize the Rx buffers before re-initializing them.
XXX not necessary?


# 1.16 23-Dec-2004 dyoung

Add more comprehensive debug messages as we setup transmit descriptors.
Also, dump packets if IFF_DEBUG|IFF_LINK2. Factor out a subroutine
for printing transmit-descriptor debug messages.


# 1.15 23-Dec-2004 dyoung

Disable interrupts and stop transmit DMA before disabling the
transmitter and receiver.


# 1.14 23-Dec-2004 dyoung

Shorten variables, s/txctl/ctl/. This is rtw_start, after all:
transmission is implied.


# 1.13 23-Dec-2004 dyoung

Do not indicate to the NIC that the host has appended the CRC32 to
Tx frames.


# 1.12 23-Dec-2004 dyoung

When we set up the supported rates table, mark 1Mb/s, 2Mb/s as
basic rates.


# 1.11 23-Dec-2004 dyoung

Extract the transmission status from a tx descriptor, and convert
to host byte-order, once.


# 1.10 20-Dec-2004 dyoung

Realtek sample sources are not consistent about the "Digital PHY"
bit in the SROM. It seems as if it is set to 1 when the PHY is
*analog*, not *digital*. Fix my sources.

In rtw_intr_rx, use units of 500kb/s instead of 100kb/s for rate,
to be consistent with net80211's expectations. Polish up some
debugging ugly messages. Dump raw 802.11 packets if IFF_DEBUG|IFF_LINK2
and RTW_DEBUG is defined.

Polish power-state (on/sleep/off) handling. Especially improve
support for RFMD (totally untested) and Maxim. For Philips, take
the Digital PHY property into account.

Call the net80211 watchdog function from rtw_watchdog, so that we
scan again if auth/assoc fails.

Be a little more cautious about writing register[RTW_TPPOLL], since
other drivers are.... Don't frob the high/low-priority queues
right now, since I don't use them.

Add rtw_join_bss which programs the card with the BSSID and other
properties of a BSS. Use it on state transitions. Factor out
rtw_set_nettype.

Make rtw_recv_beacon call ieee80211_recv_mgmt instead of dropping
beacons on the floor! TBD IBSS merges.

Change some rtw_debug=2 printfs to rtw_debug=3 (RTW_DPRINTF3)
printfs so the console doesn't get spammed so badly at rtw_debug=2.
Change some debugging printfs to RTW_DPRINTFs. E.g., print the
"RF programming method" only if debugging is enabled.


# 1.9 20-Dec-2004 dyoung

Fix bug in last commit: use &sc->sc_regs, regs is not defined.


# 1.8 20-Dec-2004 dyoung

Add some bus barriers. Remark where they are needed, e.g.,
read_eeprom.

Change some printfs to RTW_DPRINTF2s to quiet rtw(4) when debugging
is disabled.


# 1.7 20-Dec-2004 dyoung

Get rid of the silly char (*dvname)[IFNAMSIZ] pattern. Replace it
with const char *dvname. I'm not sure what I was thinking.


# 1.6 20-Dec-2004 dyoung

Assert that I'm DMA-syncing a non-negative number of transmit
descriptors.

As I free dirty transmit buffers, move them to the free list, not
back to the dirty list!

Add a 5-second transmit timeout.


# 1.5 19-Dec-2004 dyoung

Add the transmit section of rtw(4): build up and tear down transmit
descriptor rings, move packets from the transmit queues to the
transmit rings, handle transmission-completed interrupts. My
Linksys WPC11 ver. 4 with Maxim RF, generates interrupts like it
is successfully transmitting packets. Clearly there are bugs: my
G4 Powerbook locks up hard. I will debug tomorrow.


# 1.4 13-Dec-2004 dyoung

At last, I have rtw w/ Philips RF receiving packets.

I added some sysctls to aid debugging:

* hw.rtw.debug -- enable debugging

* hw.rtw.flush_rfio -- Linux voodoo: possibly makes the MAC
"flush" bits down the serial bus to the RF

* hw.rtw.host_rfio: force the host to bang bits to the RF, instead
of the MAC banging bits

* hw.rtw.rfio_delay: after telling the MAC to bang bits to the
RF front-end, delay rfio_delay microseconds.

* hw.rtw.rfprog_fallback: there is this notion of the "RF
programming method." I believe the choice influences the
polarity/timing of the serial bus used to program the RF
front-end. I know the correct choice for Intersil/RFMD/Philips
front-ends, only. For all other front-ends, I "fallback" to
rfprog_fallback.

Make rtw_txdac_enable take an rtw_softc argument. I will probably
revert this change.

Add some Linux voodoo to rtw_continuous_tx_enable. I will probably
revert this change.

Important: add rtw_set_rfprog, which sets the correct RF programming
method. This change and the following change are probably responsible
for making the Philips RF work.

Important: RTW_CONFIG1 is an 8-bit register, treat it that way!

Important: RTW_BRSR is 16-bit, RTW_CRCOUNT, RTW_PHYDELAY, and
RTW_MSR are 8-bit: treat them that way!

Vastly simplify rtw_resume_ticks.

Note to self: set the LED state to match the power state.

Hedge against the possibility that RTW_MSR is protected as
RTW_CONFIG[0123] are, meanwhile reworking that section of rtw_init
a little.

Add sc_anaparm, which isn't used, yet....


# 1.3 12-Dec-2004 dyoung

Miscellaneous changes. Details below. Important changes flagged
with []. Using the driver with my Linksys WPC11 ver. 4, it seems
to be receiving packets for a change. The WPC11 ver. 4 has a Maxim
RF section. My no-name rtw with Philips RF section still does not
receive any packets.

Keep access-level (analog params > config[0123] registers > none)
in sc_access. Add rtw_set_access for changing the access level.

Make rtw_continuous_tx_enable and other subroutines use rtw_set_access
instead of rtw_config0123_enable and rtw_anaparm_enable.

Factor part of the chip-reset code into rtw_chip_reset1.

Change the 'struct foo (*bar)[N]'-style arguments to
'struct foo *bar'-style arguments.

Consolidate software/hardware Tx/Rx ring setup in rtw_hwring_setup,
rtw_swring_setup.

Add a new constant, SA2400_OPMODE_DEFAULTS, for the bits that we
*always* set in the SA2400 OPMODE register.

Factor some code out into rtw_sa2400_calibrate. (Inspired by the
Linux driver.)

[] When the receiver goes into underrun/overflow state, call a new
subroutine, rtw_kick() that stops the Rx/Tx processes, resets
the chip, reinitializes the Tx/Rx rings, and restarts Rx/Tx
processes. (Inspired by the Linux driver.)

[] In rtw_intr_rx, check for too-short packets before calling
ieee80211_find_rxnode. I believe this will prevent a repeat of
the MCHK exception I saw once on macppc.

[] Use seconds-elapased as well as microseconds-elapsed to set the
next "due date" for the timeout interrupt. This keeps the driver
from programming the timeout to expire too early.

[] In rtw_intr, read RTW_ISR at most 10 times, then get out. If
the interface is not enabled (RTW_F_ENABLED), then get out.

[] In rtw_stop, get out if the interface is not enabled (RTW_F_ENABLED).
Block IPL_NET interrupts. Don't read/write any registers if
the interface is invalid (RTW_F_INVALID).

[] Call rtw_stop in rtw_detach.


Revision tags: kent-audio1-base
# 1.2 30-Oct-2004 thorpej

When adding/deleting multicast addresses, only whack the address
filter if the interface is marked RUNNING.

Fixes kern/27678.


# 1.1 26-Sep-2004 dyoung

branches: 1.1.2;
Add work-in-progress driver rtw(4) for Realtek RTL8180 MAC/baseband.

Add register definitions for Maxim MAX2820 and Philips SA2400 radio
front-ends.