Commit Graph

85 Commits

Author SHA1 Message Date
christos 53524e44ef Kill caddr_t; there will be some MI fallout, but it will be fixed shortly. 2007-03-04 05:59:00 +00:00
dyoung ba4e9d5953 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.
2007-01-29 07:08:09 +00:00
dyoung e356b87859 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.
2007-01-06 08:27:53 +00:00
dyoung d7436b96b1 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.
2007-01-06 06:07:55 +00:00
christos 168cd830d2 __unused removal on arguments; approved by core. 2006-11-16 01:32:37 +00:00
dyoung 075fd7d1e9 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.
2006-11-13 03:35:59 +00:00
xtraeme 1b2a823a5f Use __unused in function arguments where appropiate. 2006-10-12 07:43:39 +00:00
christos 4d595fd7b1 - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
2006-10-12 01:30:41 +00:00
jmcneill f135e0d607 Add "name" parameter to powerhook_establish, to aid debugging. No objections
on tech-kern@
2006-09-24 03:53:07 +00:00
christos 26733bed2e - comment out impossible comparisons
- remove superfluous if statement
2006-09-03 05:10:24 +00:00
dyoung 8cd106d3d2 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.
2006-08-31 19:24:37 +00:00
blymn a88dd3436a Clean up bogus whitespace 2006-05-26 12:52:45 +00:00
christos c0fdc5190f XXX: GCC uninitialized 2006-05-14 05:42:43 +00:00
dyoung b307a01ecd 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....
2006-03-28 00:48:10 +00:00
dyoung facc99b314 Set the channel frequency and flags in the radiotap headers in
rtw_tune instead of in rtw_start, rtw_intr_rx.
2006-03-27 22:03:36 +00:00
dyoung 3168e87b4f Remove unused argument ifflagsp from rtw_dmamap_load_txbuf. 2006-03-27 22:02:02 +00:00
dyoung cafe884d2c Change macro names to avoid collisions:
BIT -> __BIT
BITS -> __BITS
2006-03-08 08:26:50 +00:00
dyoung f66403a698 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);
2006-03-08 00:24:06 +00:00
thorpej 3ddf26777f Use device_is_active() rather than testing dv_flags for DVF_ACTIVE
directly.
2006-02-20 16:50:36 +00:00
dyoung a43fc3c20c 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.
2006-02-19 08:10:06 +00:00
dyoung e46f0f4008 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.
2006-02-04 23:22:27 +00:00
dyoung 92e2a6beb6 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.
2005-12-29 22:27:17 +00:00
dyoung 6910fdde2a 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.
2005-12-29 22:23:52 +00:00
dyoung 13283d6e4f 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).
2005-12-29 21:08:26 +00:00
perry 93124077ae Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete. 2005-12-24 20:27:29 +00:00
dyoung 47b698d0b8 Fix comments and debug printfs: Tx FIFOs underflow, they don't
overflow.
2005-12-13 05:10:55 +00:00
dyoung 830e4be4c8 On a transmit FIFO overflow (err, actually an underflow...) reset
both the transmit & receive sections of the MAC.
2005-12-13 05:07:14 +00:00
dyoung 63d8fb2cb6 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.
2005-11-23 04:12:33 +00:00
skrll 302689559d Adapt drivers to the new net80211(9).
Most of this is from dyoung@. Thanks!
2005-11-18 16:53:56 +00:00
gdt a73a22a4b2 Make arg of IFQ_SET_READY be &ifp->if_snd, to match all other drivers
and be compilable with altq enabled.  Reviewed by dyoung@
2005-09-22 16:15:20 +00:00
dogcow 52dfe86ca8 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. :)
2005-09-07 05:25:41 +00:00
dogcow 4ec2f95af9 make rtw.c compile again after the 22-jun-05 net80211 import 2005-09-06 01:59:26 +00:00
dyoung 55512dd5b2 Add undefined variable 'ic' to rtw_attach. 2005-07-11 06:01:42 +00:00
dyoung 83a9bf2c5c 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.
2005-07-06 23:58:14 +00:00
dyoung 707b2b4ae1 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.
2005-07-06 23:44:15 +00:00
dyoung dbad357b04 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.
2005-06-28 07:19:33 +00:00
dyoung c0a74e44c8 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.
2005-06-27 05:49:13 +00:00
dyoung 9063402978 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.
2005-06-22 06:14:51 +00:00
atatat df13e3579e 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.
2005-06-20 02:49:18 +00:00
dyoung d485a761e3 Sprinkle __UNCONST() and rename variables to quiet uiet -Wcast-qual,
-Wshadow complaints.
2005-06-10 02:35:34 +00:00
dyoung 8125cd1769 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.
2005-03-02 05:20:43 +00:00
perry f31bd063e9 nuke trailing whitespace 2005-02-27 00:26:58 +00:00
thorpej a0c36aaebd Eliminate use of M_HASFCS. 2005-01-31 02:51:17 +00:00
dyoung 55940f7c4e 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.
2005-01-16 11:50:43 +00:00
dyoung e470ffcf3b Set initial conditions to guarantee that when read_seeprom toggles
Chip Select, it turns *on* rather than *off*.
2005-01-04 01:04:52 +00:00
dyoung 9a756f795b Add the logic for IBSS merges. 2005-01-04 01:00:30 +00:00
dyoung 66e0c6fbb9 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).
2005-01-03 03:25:06 +00:00
dyoung 4903d25d90 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.)
2005-01-03 03:07:12 +00:00
dyoung 37420795ec Cosmetic: change u_int{8,16,32,64}_t to C99-style uint{8,16,32,64}_t,
which is preferred.
2005-01-02 04:23:03 +00:00
dyoung c3a19d4272 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.
2004-12-29 19:41:04 +00:00