2005-01-07 02:29:27 +00:00
|
|
|
/*-
|
Take the support for the 8139C+/8169/8169S/8110S chips out of the
rl(4) driver and put it in a new re(4) driver. The re(4) driver shares
the if_rlreg.h file with rl(4) but is a separate module. (Ultimately
I may change this. For now, it's convenient.)
rl(4) has been modified so that it will never attach to an 8139C+
chip, leaving it to re(4) instead. Only re(4) has the PCI IDs to
match the 8169/8169S/8110S gigE chips. if_re.c contains the same
basic code that was originally bolted onto if_rl.c, with the
following updates:
- Added support for jumbo frames. Currently, there seems to be
a limit of approximately 6200 bytes for jumbo frames on transmit.
(This was determined via experimentation.) The 8169S/8110S chips
apparently are limited to 7.5K frames on transmit. This may require
some more work, though the framework to handle jumbo frames on RX
is in place: the re_rxeof() routine will gather up frames than span
multiple 2K clusters into a single mbuf list.
- Fixed bug in re_txeof(): if we reap some of the TX buffers,
but there are still some pending, re-arm the timer before exiting
re_txeof() so that another timeout interrupt will be generated, just
in case re_start() doesn't do it for us.
- Handle the 'link state changed' interrupt
- Fix a detach bug. If re(4) is loaded as a module, and you do
tcpdump -i re0, then you do 'kldunload if_re,' the system will
panic after a few seconds. This happens because ether_ifdetach()
ends up calling the BPF detach code, which notices the interface
is in promiscuous mode and tries to switch promisc mode off while
detaching the BPF listner. This ultimately results in a call
to re_ioctl() (due to SIOCSIFFLAGS), which in turn calls re_init()
to handle the IFF_PROMISC flag change. Unfortunately, calling re_init()
here turns the chip back on and restarts the 1-second timeout loop
that drives re_tick(). By the time the timeout fires, if_re.ko
has been unloaded, which results in a call to invalid code and
blows up the system.
To fix this, I cleared the IFF_UP flag before calling ether_ifdetach(),
which stops the ioctl routine from trying to reset the chip.
- Modified comments in re_rxeof() relating to the difference in
RX descriptor status bit layout between the 8139C+ and the gigE
chips. The layout is different because the frame length field
was expanded from 12 bits to 13, and they got rid of one of the
status bits to make room.
- Add diagnostic code (re_diag()) to test for the case where a user
has installed a broken 32-bit 8169 PCI NIC in a 64-bit slot. Some
NICs have the REQ64# and ACK64# lines connected even though the
board is 32-bit only (in this case, they should be pulled high).
This fools the chip into doing 64-bit DMA transfers even though
there is no 64-bit data path. To detect this, re_diag() puts the
chip into digital loopback mode and sets the receiver to promiscuous
mode, then initiates a single 64-byte packet transmission. The
frame is echoed back to the host, and if the frame contents are
intact, we know DMA is working correctly, otherwise we complain
loudly on the console and abort the device attach. (At the moment,
I don't know of any way to work around the problem other than
physically modifying the board, so until/unless I can think of a
software workaround, this will have do to.)
- Created re(4) man page
- Modified rlphy.c to allow re(4) to attach as well as rl(4).
Note that this code works for the sample 8169/Marvell 88E1000 NIC
that I have, but probably won't work for the 8169S/8110S chips.
RealTek has sent me some sample NICs, but they haven't arrived yet.
I will probably need to add an rlgphy driver to handle the on-board
PHY in the 8169S/8110S (it needs special DSP initialization).
2003-09-08 02:11:25 +00:00
|
|
|
* Copyright (c) 1997, 1998
|
1998-10-18 16:24:34 +00:00
|
|
|
* Bill Paul <wpaul@ctr.columbia.edu>. All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by Bill Paul.
|
|
|
|
* 4. Neither the name of the author nor the names of any co-contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
|
|
|
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
|
|
|
* THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2003-11-14 17:16:58 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
1998-10-18 16:24:34 +00:00
|
|
|
/*
|
Take the support for the 8139C+/8169/8169S/8110S chips out of the
rl(4) driver and put it in a new re(4) driver. The re(4) driver shares
the if_rlreg.h file with rl(4) but is a separate module. (Ultimately
I may change this. For now, it's convenient.)
rl(4) has been modified so that it will never attach to an 8139C+
chip, leaving it to re(4) instead. Only re(4) has the PCI IDs to
match the 8169/8169S/8110S gigE chips. if_re.c contains the same
basic code that was originally bolted onto if_rl.c, with the
following updates:
- Added support for jumbo frames. Currently, there seems to be
a limit of approximately 6200 bytes for jumbo frames on transmit.
(This was determined via experimentation.) The 8169S/8110S chips
apparently are limited to 7.5K frames on transmit. This may require
some more work, though the framework to handle jumbo frames on RX
is in place: the re_rxeof() routine will gather up frames than span
multiple 2K clusters into a single mbuf list.
- Fixed bug in re_txeof(): if we reap some of the TX buffers,
but there are still some pending, re-arm the timer before exiting
re_txeof() so that another timeout interrupt will be generated, just
in case re_start() doesn't do it for us.
- Handle the 'link state changed' interrupt
- Fix a detach bug. If re(4) is loaded as a module, and you do
tcpdump -i re0, then you do 'kldunload if_re,' the system will
panic after a few seconds. This happens because ether_ifdetach()
ends up calling the BPF detach code, which notices the interface
is in promiscuous mode and tries to switch promisc mode off while
detaching the BPF listner. This ultimately results in a call
to re_ioctl() (due to SIOCSIFFLAGS), which in turn calls re_init()
to handle the IFF_PROMISC flag change. Unfortunately, calling re_init()
here turns the chip back on and restarts the 1-second timeout loop
that drives re_tick(). By the time the timeout fires, if_re.ko
has been unloaded, which results in a call to invalid code and
blows up the system.
To fix this, I cleared the IFF_UP flag before calling ether_ifdetach(),
which stops the ioctl routine from trying to reset the chip.
- Modified comments in re_rxeof() relating to the difference in
RX descriptor status bit layout between the 8139C+ and the gigE
chips. The layout is different because the frame length field
was expanded from 12 bits to 13, and they got rid of one of the
status bits to make room.
- Add diagnostic code (re_diag()) to test for the case where a user
has installed a broken 32-bit 8169 PCI NIC in a 64-bit slot. Some
NICs have the REQ64# and ACK64# lines connected even though the
board is 32-bit only (in this case, they should be pulled high).
This fools the chip into doing 64-bit DMA transfers even though
there is no 64-bit data path. To detect this, re_diag() puts the
chip into digital loopback mode and sets the receiver to promiscuous
mode, then initiates a single 64-byte packet transmission. The
frame is echoed back to the host, and if the frame contents are
intact, we know DMA is working correctly, otherwise we complain
loudly on the console and abort the device attach. (At the moment,
I don't know of any way to work around the problem other than
physically modifying the board, so until/unless I can think of a
software workaround, this will have do to.)
- Created re(4) man page
- Modified rlphy.c to allow re(4) to attach as well as rl(4).
Note that this code works for the sample 8169/Marvell 88E1000 NIC
that I have, but probably won't work for the 8169S/8110S chips.
RealTek has sent me some sample NICs, but they haven't arrived yet.
I will probably need to add an rlgphy driver to handle the on-board
PHY in the 8169S/8110S (it needs special DSP initialization).
2003-09-08 02:11:25 +00:00
|
|
|
* RealTek 8129/8139 PCI NIC driver
|
1998-10-18 16:24:34 +00:00
|
|
|
*
|
Take the support for the 8139C+/8169/8169S/8110S chips out of the
rl(4) driver and put it in a new re(4) driver. The re(4) driver shares
the if_rlreg.h file with rl(4) but is a separate module. (Ultimately
I may change this. For now, it's convenient.)
rl(4) has been modified so that it will never attach to an 8139C+
chip, leaving it to re(4) instead. Only re(4) has the PCI IDs to
match the 8169/8169S/8110S gigE chips. if_re.c contains the same
basic code that was originally bolted onto if_rl.c, with the
following updates:
- Added support for jumbo frames. Currently, there seems to be
a limit of approximately 6200 bytes for jumbo frames on transmit.
(This was determined via experimentation.) The 8169S/8110S chips
apparently are limited to 7.5K frames on transmit. This may require
some more work, though the framework to handle jumbo frames on RX
is in place: the re_rxeof() routine will gather up frames than span
multiple 2K clusters into a single mbuf list.
- Fixed bug in re_txeof(): if we reap some of the TX buffers,
but there are still some pending, re-arm the timer before exiting
re_txeof() so that another timeout interrupt will be generated, just
in case re_start() doesn't do it for us.
- Handle the 'link state changed' interrupt
- Fix a detach bug. If re(4) is loaded as a module, and you do
tcpdump -i re0, then you do 'kldunload if_re,' the system will
panic after a few seconds. This happens because ether_ifdetach()
ends up calling the BPF detach code, which notices the interface
is in promiscuous mode and tries to switch promisc mode off while
detaching the BPF listner. This ultimately results in a call
to re_ioctl() (due to SIOCSIFFLAGS), which in turn calls re_init()
to handle the IFF_PROMISC flag change. Unfortunately, calling re_init()
here turns the chip back on and restarts the 1-second timeout loop
that drives re_tick(). By the time the timeout fires, if_re.ko
has been unloaded, which results in a call to invalid code and
blows up the system.
To fix this, I cleared the IFF_UP flag before calling ether_ifdetach(),
which stops the ioctl routine from trying to reset the chip.
- Modified comments in re_rxeof() relating to the difference in
RX descriptor status bit layout between the 8139C+ and the gigE
chips. The layout is different because the frame length field
was expanded from 12 bits to 13, and they got rid of one of the
status bits to make room.
- Add diagnostic code (re_diag()) to test for the case where a user
has installed a broken 32-bit 8169 PCI NIC in a 64-bit slot. Some
NICs have the REQ64# and ACK64# lines connected even though the
board is 32-bit only (in this case, they should be pulled high).
This fools the chip into doing 64-bit DMA transfers even though
there is no 64-bit data path. To detect this, re_diag() puts the
chip into digital loopback mode and sets the receiver to promiscuous
mode, then initiates a single 64-byte packet transmission. The
frame is echoed back to the host, and if the frame contents are
intact, we know DMA is working correctly, otherwise we complain
loudly on the console and abort the device attach. (At the moment,
I don't know of any way to work around the problem other than
physically modifying the board, so until/unless I can think of a
software workaround, this will have do to.)
- Created re(4) man page
- Modified rlphy.c to allow re(4) to attach as well as rl(4).
Note that this code works for the sample 8169/Marvell 88E1000 NIC
that I have, but probably won't work for the 8169S/8110S chips.
RealTek has sent me some sample NICs, but they haven't arrived yet.
I will probably need to add an rlgphy driver to handle the on-board
PHY in the 8169S/8110S (it needs special DSP initialization).
2003-09-08 02:11:25 +00:00
|
|
|
* Supports several extremely cheap PCI 10/100 adapters based on
|
|
|
|
* the RealTek chipset. Datasheets can be obtained from
|
1998-10-18 16:24:34 +00:00
|
|
|
* www.realtek.com.tw.
|
|
|
|
*
|
Take the support for the 8139C+/8169/8169S/8110S chips out of the
rl(4) driver and put it in a new re(4) driver. The re(4) driver shares
the if_rlreg.h file with rl(4) but is a separate module. (Ultimately
I may change this. For now, it's convenient.)
rl(4) has been modified so that it will never attach to an 8139C+
chip, leaving it to re(4) instead. Only re(4) has the PCI IDs to
match the 8169/8169S/8110S gigE chips. if_re.c contains the same
basic code that was originally bolted onto if_rl.c, with the
following updates:
- Added support for jumbo frames. Currently, there seems to be
a limit of approximately 6200 bytes for jumbo frames on transmit.
(This was determined via experimentation.) The 8169S/8110S chips
apparently are limited to 7.5K frames on transmit. This may require
some more work, though the framework to handle jumbo frames on RX
is in place: the re_rxeof() routine will gather up frames than span
multiple 2K clusters into a single mbuf list.
- Fixed bug in re_txeof(): if we reap some of the TX buffers,
but there are still some pending, re-arm the timer before exiting
re_txeof() so that another timeout interrupt will be generated, just
in case re_start() doesn't do it for us.
- Handle the 'link state changed' interrupt
- Fix a detach bug. If re(4) is loaded as a module, and you do
tcpdump -i re0, then you do 'kldunload if_re,' the system will
panic after a few seconds. This happens because ether_ifdetach()
ends up calling the BPF detach code, which notices the interface
is in promiscuous mode and tries to switch promisc mode off while
detaching the BPF listner. This ultimately results in a call
to re_ioctl() (due to SIOCSIFFLAGS), which in turn calls re_init()
to handle the IFF_PROMISC flag change. Unfortunately, calling re_init()
here turns the chip back on and restarts the 1-second timeout loop
that drives re_tick(). By the time the timeout fires, if_re.ko
has been unloaded, which results in a call to invalid code and
blows up the system.
To fix this, I cleared the IFF_UP flag before calling ether_ifdetach(),
which stops the ioctl routine from trying to reset the chip.
- Modified comments in re_rxeof() relating to the difference in
RX descriptor status bit layout between the 8139C+ and the gigE
chips. The layout is different because the frame length field
was expanded from 12 bits to 13, and they got rid of one of the
status bits to make room.
- Add diagnostic code (re_diag()) to test for the case where a user
has installed a broken 32-bit 8169 PCI NIC in a 64-bit slot. Some
NICs have the REQ64# and ACK64# lines connected even though the
board is 32-bit only (in this case, they should be pulled high).
This fools the chip into doing 64-bit DMA transfers even though
there is no 64-bit data path. To detect this, re_diag() puts the
chip into digital loopback mode and sets the receiver to promiscuous
mode, then initiates a single 64-byte packet transmission. The
frame is echoed back to the host, and if the frame contents are
intact, we know DMA is working correctly, otherwise we complain
loudly on the console and abort the device attach. (At the moment,
I don't know of any way to work around the problem other than
physically modifying the board, so until/unless I can think of a
software workaround, this will have do to.)
- Created re(4) man page
- Modified rlphy.c to allow re(4) to attach as well as rl(4).
Note that this code works for the sample 8169/Marvell 88E1000 NIC
that I have, but probably won't work for the 8169S/8110S chips.
RealTek has sent me some sample NICs, but they haven't arrived yet.
I will probably need to add an rlgphy driver to handle the on-board
PHY in the 8169S/8110S (it needs special DSP initialization).
2003-09-08 02:11:25 +00:00
|
|
|
* Written by Bill Paul <wpaul@ctr.columbia.edu>
|
|
|
|
* Electrical Engineering Department
|
|
|
|
* Columbia University, New York City
|
1998-10-18 16:24:34 +00:00
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* The RealTek 8139 PCI NIC redefines the meaning of 'low end.' This is
|
|
|
|
* probably the worst PCI ethernet controller ever made, with the possible
|
|
|
|
* exception of the FEAST chip made by SMC. The 8139 supports bus-master
|
|
|
|
* DMA, but it has a terrible interface that nullifies any performance
|
|
|
|
* gains that bus-master DMA usually offers.
|
|
|
|
*
|
|
|
|
* For transmission, the chip offers a series of four TX descriptor
|
|
|
|
* registers. Each transmit frame must be in a contiguous buffer, aligned
|
1998-12-07 00:35:06 +00:00
|
|
|
* on a longword (32-bit) boundary. This means we almost always have to
|
1998-10-18 16:24:34 +00:00
|
|
|
* do mbuf copies in order to transmit a frame, except in the unlikely
|
|
|
|
* case where a) the packet fits into a single mbuf, and b) the packet
|
|
|
|
* is 32-bit aligned within the mbuf's data area. The presence of only
|
|
|
|
* four descriptor registers means that we can never have more than four
|
|
|
|
* packets queued for transmission at any one time.
|
|
|
|
*
|
|
|
|
* Reception is not much better. The driver has to allocate a single large
|
|
|
|
* buffer area (up to 64K in size) into which the chip will DMA received
|
|
|
|
* frames. Because we don't know where within this region received packets
|
|
|
|
* will begin or end, we have no choice but to copy data from the buffer
|
|
|
|
* area into mbufs in order to pass the packets up to the higher protocol
|
|
|
|
* levels.
|
|
|
|
*
|
|
|
|
* It's impossible given this rotten design to really achieve decent
|
|
|
|
* performance at 100Mbps, unless you happen to have a 400Mhz PII or
|
|
|
|
* some equally overmuscled CPU to drive it.
|
|
|
|
*
|
|
|
|
* On the bright side, the 8139 does have a built-in PHY, although
|
|
|
|
* rather than using an MDIO serial interface like most other NICs, the
|
|
|
|
* PHY registers are directly accessible through the 8139's register
|
|
|
|
* space. The 8139 supports autonegotiation, as well as a 64-bit multicast
|
|
|
|
* filter.
|
|
|
|
*
|
|
|
|
* The 8129 chip is an older version of the 8139 that uses an external PHY
|
|
|
|
* chip. The 8129 has a serial MDIO interface for accessing the MII where
|
|
|
|
* the 8139 lets you directly access the on-board PHY registers. We need
|
|
|
|
* to select which interface to use depending on the chip type.
|
|
|
|
*/
|
|
|
|
|
2005-10-05 10:09:17 +00:00
|
|
|
#ifdef HAVE_KERNEL_OPTION_HEADERS
|
|
|
|
#include "opt_device_polling.h"
|
|
|
|
#endif
|
|
|
|
|
1998-10-18 16:24:34 +00:00
|
|
|
#include <sys/param.h>
|
2003-01-05 21:36:59 +00:00
|
|
|
#include <sys/endian.h>
|
1998-10-18 16:24:34 +00:00
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/sockio.h>
|
|
|
|
#include <sys/mbuf.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/kernel.h>
|
2004-05-30 20:00:41 +00:00
|
|
|
#include <sys/module.h>
|
1998-10-18 16:24:34 +00:00
|
|
|
#include <sys/socket.h>
|
2008-11-02 16:50:57 +00:00
|
|
|
#include <sys/sysctl.h>
|
1998-10-18 16:24:34 +00:00
|
|
|
|
|
|
|
#include <net/if.h>
|
2013-10-26 17:58:36 +00:00
|
|
|
#include <net/if_var.h>
|
1998-10-18 16:24:34 +00:00
|
|
|
#include <net/if_arp.h>
|
|
|
|
#include <net/ethernet.h>
|
|
|
|
#include <net/if_dl.h>
|
|
|
|
#include <net/if_media.h>
|
2005-06-10 16:49:24 +00:00
|
|
|
#include <net/if_types.h>
|
1998-10-18 16:24:34 +00:00
|
|
|
|
|
|
|
#include <net/bpf.h>
|
|
|
|
|
1998-12-07 00:35:06 +00:00
|
|
|
#include <machine/bus.h>
|
1999-08-31 14:45:51 +00:00
|
|
|
#include <machine/resource.h>
|
|
|
|
#include <sys/bus.h>
|
|
|
|
#include <sys/rman.h>
|
|
|
|
|
|
|
|
#include <dev/mii/mii.h>
|
2011-11-01 16:13:59 +00:00
|
|
|
#include <dev/mii/mii_bitbang.h>
|
1999-08-31 14:45:51 +00:00
|
|
|
#include <dev/mii/miivar.h>
|
1998-10-18 16:24:34 +00:00
|
|
|
|
2003-09-08 04:28:20 +00:00
|
|
|
#include <dev/pci/pcireg.h>
|
|
|
|
#include <dev/pci/pcivar.h>
|
1998-10-18 16:24:34 +00:00
|
|
|
|
2003-04-15 06:37:30 +00:00
|
|
|
MODULE_DEPEND(rl, pci, 1, 1, 1);
|
|
|
|
MODULE_DEPEND(rl, ether, 1, 1, 1);
|
2000-04-29 13:41:57 +00:00
|
|
|
MODULE_DEPEND(rl, miibus, 1, 1, 1);
|
|
|
|
|
2005-10-22 05:06:55 +00:00
|
|
|
/* "device miibus" required. See GENERIC if you get errors here. */
|
1999-08-31 14:45:51 +00:00
|
|
|
#include "miibus_if.h"
|
|
|
|
|
1998-10-18 16:24:34 +00:00
|
|
|
#include <pci/if_rlreg.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Various supported device vendors/types and their names.
|
|
|
|
*/
|
2012-11-05 19:16:27 +00:00
|
|
|
static const struct rl_type rl_devs[] = {
|
2003-07-10 20:38:48 +00:00
|
|
|
{ RT_VENDORID, RT_DEVICEID_8129, RL_8129,
|
1998-10-18 16:24:34 +00:00
|
|
|
"RealTek 8129 10/100BaseTX" },
|
2003-07-10 20:38:48 +00:00
|
|
|
{ RT_VENDORID, RT_DEVICEID_8139, RL_8139,
|
1998-10-18 16:24:34 +00:00
|
|
|
"RealTek 8139 10/100BaseTX" },
|
2008-06-16 18:32:20 +00:00
|
|
|
{ RT_VENDORID, RT_DEVICEID_8139D, RL_8139,
|
|
|
|
"RealTek 8139 10/100BaseTX" },
|
2003-07-10 20:38:48 +00:00
|
|
|
{ RT_VENDORID, RT_DEVICEID_8138, RL_8139,
|
2000-10-28 09:00:20 +00:00
|
|
|
"RealTek 8139 10/100BaseTX CardBus" },
|
2003-08-15 22:47:55 +00:00
|
|
|
{ RT_VENDORID, RT_DEVICEID_8100, RL_8139,
|
|
|
|
"RealTek 8100 10/100BaseTX" },
|
2003-07-10 20:38:48 +00:00
|
|
|
{ ACCTON_VENDORID, ACCTON_DEVICEID_5030, RL_8139,
|
1998-11-18 21:03:58 +00:00
|
|
|
"Accton MPX 5030/5038 10/100BaseTX" },
|
2003-07-10 20:38:48 +00:00
|
|
|
{ DELTA_VENDORID, DELTA_DEVICEID_8139, RL_8139,
|
1999-02-23 15:38:25 +00:00
|
|
|
"Delta Electronics 8139 10/100BaseTX" },
|
2003-07-10 20:38:48 +00:00
|
|
|
{ ADDTRON_VENDORID, ADDTRON_DEVICEID_8139, RL_8139,
|
2008-11-01 17:02:01 +00:00
|
|
|
"Addtron Technology 8139 10/100BaseTX" },
|
2013-01-16 01:30:46 +00:00
|
|
|
{ DLINK_VENDORID, DLINK_DEVICEID_520TX_REVC1, RL_8139,
|
|
|
|
"D-Link DFE-520TX (rev. C1) 10/100BaseTX" },
|
2003-07-10 20:38:48 +00:00
|
|
|
{ DLINK_VENDORID, DLINK_DEVICEID_530TXPLUS, RL_8139,
|
2001-02-21 20:54:22 +00:00
|
|
|
"D-Link DFE-530TX+ 10/100BaseTX" },
|
2003-07-10 20:38:48 +00:00
|
|
|
{ DLINK_VENDORID, DLINK_DEVICEID_690TXD, RL_8139,
|
2002-05-06 13:43:00 +00:00
|
|
|
"D-Link DFE-690TXD 10/100BaseTX" },
|
2003-07-10 20:38:48 +00:00
|
|
|
{ NORTEL_VENDORID, ACCTON_DEVICEID_5030, RL_8139,
|
2002-04-11 06:12:51 +00:00
|
|
|
"Nortel Networks 10/100BaseTX" },
|
2003-07-10 20:38:48 +00:00
|
|
|
{ COREGA_VENDORID, COREGA_DEVICEID_FETHERCBTXD, RL_8139,
|
2002-09-06 16:38:06 +00:00
|
|
|
"Corega FEther CB-TXD" },
|
2003-07-10 20:38:48 +00:00
|
|
|
{ COREGA_VENDORID, COREGA_DEVICEID_FETHERIICBTXD, RL_8139,
|
2003-01-11 07:10:35 +00:00
|
|
|
"Corega FEtherII CB-TXD" },
|
2003-07-10 20:38:48 +00:00
|
|
|
{ PEPPERCON_VENDORID, PEPPERCON_DEVICEID_ROLF, RL_8139,
|
2003-02-23 23:35:35 +00:00
|
|
|
"Peppercon AG ROL-F" },
|
2007-11-26 18:25:07 +00:00
|
|
|
{ PLANEX_VENDORID, PLANEX_DEVICEID_FNW3603TX, RL_8139,
|
|
|
|
"Planex FNW-3603-TX" },
|
2003-07-10 20:38:48 +00:00
|
|
|
{ PLANEX_VENDORID, PLANEX_DEVICEID_FNW3800TX, RL_8139,
|
2003-03-18 14:57:09 +00:00
|
|
|
"Planex FNW-3800-TX" },
|
2003-07-10 20:38:48 +00:00
|
|
|
{ CP_VENDORID, RT_DEVICEID_8139, RL_8139,
|
|
|
|
"Compaq HNE-300" },
|
|
|
|
{ LEVEL1_VENDORID, LEVEL1_DEVICEID_FPC0106TX, RL_8139,
|
|
|
|
"LevelOne FPC-0106TX" },
|
|
|
|
{ EDIMAX_VENDORID, EDIMAX_DEVICEID_EP4103DL, RL_8139,
|
2008-03-03 04:15:08 +00:00
|
|
|
"Edimax EP-4103DL CardBus" }
|
1998-10-18 16:24:34 +00:00
|
|
|
};
|
|
|
|
|
2005-02-24 22:33:05 +00:00
|
|
|
static int rl_attach(device_t);
|
|
|
|
static int rl_detach(device_t);
|
2008-10-25 02:36:08 +00:00
|
|
|
static void rl_dmamap_cb(void *, bus_dma_segment_t *, int, int);
|
|
|
|
static int rl_dma_alloc(struct rl_softc *);
|
|
|
|
static void rl_dma_free(struct rl_softc *);
|
2005-02-24 22:33:05 +00:00
|
|
|
static void rl_eeprom_putbyte(struct rl_softc *, int);
|
|
|
|
static void rl_eeprom_getword(struct rl_softc *, int, uint16_t *);
|
2008-10-25 02:36:08 +00:00
|
|
|
static int rl_encap(struct rl_softc *, struct mbuf **);
|
2005-02-24 22:33:05 +00:00
|
|
|
static int rl_list_tx_init(struct rl_softc *);
|
2008-10-25 02:36:08 +00:00
|
|
|
static int rl_list_rx_init(struct rl_softc *);
|
2005-02-24 22:33:05 +00:00
|
|
|
static int rl_ifmedia_upd(struct ifnet *);
|
|
|
|
static void rl_ifmedia_sts(struct ifnet *, struct ifmediareq *);
|
|
|
|
static int rl_ioctl(struct ifnet *, u_long, caddr_t);
|
|
|
|
static void rl_intr(void *);
|
|
|
|
static void rl_init(void *);
|
|
|
|
static void rl_init_locked(struct rl_softc *sc);
|
|
|
|
static int rl_miibus_readreg(device_t, int, int);
|
|
|
|
static void rl_miibus_statchg(device_t);
|
|
|
|
static int rl_miibus_writereg(device_t, int, int, int);
|
2004-07-09 00:07:06 +00:00
|
|
|
#ifdef DEVICE_POLLING
|
2009-05-30 15:14:44 +00:00
|
|
|
static int rl_poll(struct ifnet *ifp, enum poll_cmd cmd, int count);
|
|
|
|
static int rl_poll_locked(struct ifnet *ifp, enum poll_cmd cmd, int count);
|
2004-07-09 00:07:06 +00:00
|
|
|
#endif
|
2005-02-24 22:33:05 +00:00
|
|
|
static int rl_probe(device_t);
|
|
|
|
static void rl_read_eeprom(struct rl_softc *, uint8_t *, int, int, int);
|
|
|
|
static void rl_reset(struct rl_softc *);
|
|
|
|
static int rl_resume(device_t);
|
2009-05-30 15:14:44 +00:00
|
|
|
static int rl_rxeof(struct rl_softc *);
|
2010-09-30 17:37:08 +00:00
|
|
|
static void rl_rxfilter(struct rl_softc *);
|
2007-11-22 02:45:00 +00:00
|
|
|
static int rl_shutdown(device_t);
|
2005-02-24 22:33:05 +00:00
|
|
|
static void rl_start(struct ifnet *);
|
|
|
|
static void rl_start_locked(struct ifnet *);
|
|
|
|
static void rl_stop(struct rl_softc *);
|
|
|
|
static int rl_suspend(device_t);
|
|
|
|
static void rl_tick(void *);
|
|
|
|
static void rl_txeof(struct rl_softc *);
|
2006-12-01 21:52:07 +00:00
|
|
|
static void rl_watchdog(struct rl_softc *);
|
2010-07-19 18:01:06 +00:00
|
|
|
static void rl_setwol(struct rl_softc *);
|
|
|
|
static void rl_clrwol(struct rl_softc *);
|
2001-08-15 17:38:43 +00:00
|
|
|
|
2011-11-01 16:13:59 +00:00
|
|
|
/*
|
|
|
|
* MII bit-bang glue
|
|
|
|
*/
|
|
|
|
static uint32_t rl_mii_bitbang_read(device_t);
|
|
|
|
static void rl_mii_bitbang_write(device_t, uint32_t);
|
|
|
|
|
|
|
|
static const struct mii_bitbang_ops rl_mii_bitbang_ops = {
|
|
|
|
rl_mii_bitbang_read,
|
|
|
|
rl_mii_bitbang_write,
|
|
|
|
{
|
|
|
|
RL_MII_DATAOUT, /* MII_BIT_MDO */
|
|
|
|
RL_MII_DATAIN, /* MII_BIT_MDI */
|
|
|
|
RL_MII_CLK, /* MII_BIT_MDC */
|
|
|
|
RL_MII_DIR, /* MII_BIT_DIR_HOST_PHY */
|
|
|
|
0, /* MII_BIT_DIR_PHY_HOST */
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
1999-08-31 14:45:51 +00:00
|
|
|
static device_method_t rl_methods[] = {
|
|
|
|
/* Device interface */
|
|
|
|
DEVMETHOD(device_probe, rl_probe),
|
|
|
|
DEVMETHOD(device_attach, rl_attach),
|
|
|
|
DEVMETHOD(device_detach, rl_detach),
|
2001-11-23 14:27:33 +00:00
|
|
|
DEVMETHOD(device_suspend, rl_suspend),
|
|
|
|
DEVMETHOD(device_resume, rl_resume),
|
1999-08-31 14:45:51 +00:00
|
|
|
DEVMETHOD(device_shutdown, rl_shutdown),
|
|
|
|
|
|
|
|
/* MII interface */
|
|
|
|
DEVMETHOD(miibus_readreg, rl_miibus_readreg),
|
|
|
|
DEVMETHOD(miibus_writereg, rl_miibus_writereg),
|
|
|
|
DEVMETHOD(miibus_statchg, rl_miibus_statchg),
|
|
|
|
|
2011-11-22 21:28:20 +00:00
|
|
|
DEVMETHOD_END
|
1999-08-31 14:45:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static driver_t rl_driver = {
|
1999-09-20 08:47:11 +00:00
|
|
|
"rl",
|
1999-08-31 14:45:51 +00:00
|
|
|
rl_methods,
|
|
|
|
sizeof(struct rl_softc)
|
|
|
|
};
|
|
|
|
|
|
|
|
static devclass_t rl_devclass;
|
|
|
|
|
2003-04-15 06:37:30 +00:00
|
|
|
DRIVER_MODULE(rl, pci, rl_driver, rl_devclass, 0, 0);
|
2003-11-28 05:28:29 +00:00
|
|
|
DRIVER_MODULE(rl, cardbus, rl_driver, rl_devclass, 0, 0);
|
1999-09-20 19:06:45 +00:00
|
|
|
DRIVER_MODULE(miibus, rl, miibus_driver, miibus_devclass, 0, 0);
|
1999-08-31 14:45:51 +00:00
|
|
|
|
1998-10-18 16:24:34 +00:00
|
|
|
#define EE_SET(x) \
|
|
|
|
CSR_WRITE_1(sc, RL_EECMD, \
|
|
|
|
CSR_READ_1(sc, RL_EECMD) | x)
|
|
|
|
|
|
|
|
#define EE_CLR(x) \
|
|
|
|
CSR_WRITE_1(sc, RL_EECMD, \
|
|
|
|
CSR_READ_1(sc, RL_EECMD) & ~x)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Send a read command and address to the EEPROM, check for ACK.
|
|
|
|
*/
|
2002-08-23 23:49:02 +00:00
|
|
|
static void
|
2004-07-05 02:46:42 +00:00
|
|
|
rl_eeprom_putbyte(struct rl_softc *sc, int addr)
|
1998-10-18 16:24:34 +00:00
|
|
|
{
|
|
|
|
register int d, i;
|
|
|
|
|
2000-10-30 07:54:38 +00:00
|
|
|
d = addr | sc->rl_eecmd_read;
|
1998-10-18 16:24:34 +00:00
|
|
|
|
|
|
|
/*
|
1999-12-28 06:04:29 +00:00
|
|
|
* Feed in each bit and strobe the clock.
|
1998-10-18 16:24:34 +00:00
|
|
|
*/
|
|
|
|
for (i = 0x400; i; i >>= 1) {
|
|
|
|
if (d & i) {
|
|
|
|
EE_SET(RL_EE_DATAIN);
|
|
|
|
} else {
|
|
|
|
EE_CLR(RL_EE_DATAIN);
|
|
|
|
}
|
|
|
|
DELAY(100);
|
|
|
|
EE_SET(RL_EE_CLK);
|
|
|
|
DELAY(150);
|
|
|
|
EE_CLR(RL_EE_CLK);
|
|
|
|
DELAY(100);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Read a word of data stored in the EEPROM at address 'addr.'
|
|
|
|
*/
|
2002-08-23 23:49:02 +00:00
|
|
|
static void
|
2004-07-05 02:46:42 +00:00
|
|
|
rl_eeprom_getword(struct rl_softc *sc, int addr, uint16_t *dest)
|
1998-10-18 16:24:34 +00:00
|
|
|
{
|
|
|
|
register int i;
|
2004-07-05 02:46:42 +00:00
|
|
|
uint16_t word = 0;
|
1998-10-18 16:24:34 +00:00
|
|
|
|
|
|
|
/* Enter EEPROM access mode. */
|
|
|
|
CSR_WRITE_1(sc, RL_EECMD, RL_EEMODE_PROGRAM|RL_EE_SEL);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Send address of word we want to read.
|
|
|
|
*/
|
|
|
|
rl_eeprom_putbyte(sc, addr);
|
|
|
|
|
|
|
|
CSR_WRITE_1(sc, RL_EECMD, RL_EEMODE_PROGRAM|RL_EE_SEL);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Start reading bits from EEPROM.
|
|
|
|
*/
|
|
|
|
for (i = 0x8000; i; i >>= 1) {
|
|
|
|
EE_SET(RL_EE_CLK);
|
|
|
|
DELAY(100);
|
|
|
|
if (CSR_READ_1(sc, RL_EECMD) & RL_EE_DATAOUT)
|
|
|
|
word |= i;
|
|
|
|
EE_CLR(RL_EE_CLK);
|
|
|
|
DELAY(100);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Turn off EEPROM access mode. */
|
|
|
|
CSR_WRITE_1(sc, RL_EECMD, RL_EEMODE_OFF);
|
|
|
|
|
|
|
|
*dest = word;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Read a sequence of words from the EEPROM.
|
|
|
|
*/
|
2002-08-23 23:49:02 +00:00
|
|
|
static void
|
2004-07-05 02:46:42 +00:00
|
|
|
rl_read_eeprom(struct rl_softc *sc, uint8_t *dest, int off, int cnt, int swap)
|
1998-10-18 16:24:34 +00:00
|
|
|
{
|
|
|
|
int i;
|
2004-07-05 02:46:42 +00:00
|
|
|
uint16_t word = 0, *ptr;
|
1998-10-18 16:24:34 +00:00
|
|
|
|
|
|
|
for (i = 0; i < cnt; i++) {
|
|
|
|
rl_eeprom_getword(sc, off + i, &word);
|
2004-07-05 02:46:42 +00:00
|
|
|
ptr = (uint16_t *)(dest + (i * 2));
|
1998-10-18 16:24:34 +00:00
|
|
|
if (swap)
|
|
|
|
*ptr = ntohs(word);
|
|
|
|
else
|
|
|
|
*ptr = word;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2011-11-01 16:13:59 +00:00
|
|
|
* Read the MII serial port for the MII bit-bang module.
|
1998-10-18 16:24:34 +00:00
|
|
|
*/
|
2011-11-01 16:13:59 +00:00
|
|
|
static uint32_t
|
|
|
|
rl_mii_bitbang_read(device_t dev)
|
1998-10-18 16:24:34 +00:00
|
|
|
{
|
2011-11-01 16:13:59 +00:00
|
|
|
struct rl_softc *sc;
|
|
|
|
uint32_t val;
|
1998-10-18 16:24:34 +00:00
|
|
|
|
2011-11-01 16:13:59 +00:00
|
|
|
sc = device_get_softc(dev);
|
1998-10-18 16:24:34 +00:00
|
|
|
|
2011-11-01 16:13:59 +00:00
|
|
|
val = CSR_READ_1(sc, RL_MII);
|
|
|
|
CSR_BARRIER(sc, RL_MII, 1,
|
|
|
|
BUS_SPACE_BARRIER_READ | BUS_SPACE_BARRIER_WRITE);
|
1998-10-18 16:24:34 +00:00
|
|
|
|
2011-11-01 16:13:59 +00:00
|
|
|
return (val);
|
1998-10-18 16:24:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2011-11-01 16:13:59 +00:00
|
|
|
* Write the MII serial port for the MII bit-bang module.
|
1998-10-18 16:24:34 +00:00
|
|
|
*/
|
2011-11-01 16:13:59 +00:00
|
|
|
static void
|
|
|
|
rl_mii_bitbang_write(device_t dev, uint32_t val)
|
1998-10-18 16:24:34 +00:00
|
|
|
{
|
2011-11-01 16:13:59 +00:00
|
|
|
struct rl_softc *sc;
|
1998-10-18 16:24:34 +00:00
|
|
|
|
2011-11-01 16:13:59 +00:00
|
|
|
sc = device_get_softc(dev);
|
1998-10-18 16:24:34 +00:00
|
|
|
|
2011-11-01 16:13:59 +00:00
|
|
|
CSR_WRITE_1(sc, RL_MII, val);
|
|
|
|
CSR_BARRIER(sc, RL_MII, 1,
|
|
|
|
BUS_SPACE_BARRIER_READ | BUS_SPACE_BARRIER_WRITE);
|
1998-10-18 16:24:34 +00:00
|
|
|
}
|
|
|
|
|
2002-08-23 23:49:02 +00:00
|
|
|
static int
|
2004-07-05 02:46:42 +00:00
|
|
|
rl_miibus_readreg(device_t dev, int phy, int reg)
|
1998-10-18 16:24:34 +00:00
|
|
|
{
|
1999-08-31 14:45:51 +00:00
|
|
|
struct rl_softc *sc;
|
2011-11-01 16:13:59 +00:00
|
|
|
uint16_t rl8139_reg;
|
1998-10-18 16:24:34 +00:00
|
|
|
|
1999-08-31 14:45:51 +00:00
|
|
|
sc = device_get_softc(dev);
|
|
|
|
|
Take the support for the 8139C+/8169/8169S/8110S chips out of the
rl(4) driver and put it in a new re(4) driver. The re(4) driver shares
the if_rlreg.h file with rl(4) but is a separate module. (Ultimately
I may change this. For now, it's convenient.)
rl(4) has been modified so that it will never attach to an 8139C+
chip, leaving it to re(4) instead. Only re(4) has the PCI IDs to
match the 8169/8169S/8110S gigE chips. if_re.c contains the same
basic code that was originally bolted onto if_rl.c, with the
following updates:
- Added support for jumbo frames. Currently, there seems to be
a limit of approximately 6200 bytes for jumbo frames on transmit.
(This was determined via experimentation.) The 8169S/8110S chips
apparently are limited to 7.5K frames on transmit. This may require
some more work, though the framework to handle jumbo frames on RX
is in place: the re_rxeof() routine will gather up frames than span
multiple 2K clusters into a single mbuf list.
- Fixed bug in re_txeof(): if we reap some of the TX buffers,
but there are still some pending, re-arm the timer before exiting
re_txeof() so that another timeout interrupt will be generated, just
in case re_start() doesn't do it for us.
- Handle the 'link state changed' interrupt
- Fix a detach bug. If re(4) is loaded as a module, and you do
tcpdump -i re0, then you do 'kldunload if_re,' the system will
panic after a few seconds. This happens because ether_ifdetach()
ends up calling the BPF detach code, which notices the interface
is in promiscuous mode and tries to switch promisc mode off while
detaching the BPF listner. This ultimately results in a call
to re_ioctl() (due to SIOCSIFFLAGS), which in turn calls re_init()
to handle the IFF_PROMISC flag change. Unfortunately, calling re_init()
here turns the chip back on and restarts the 1-second timeout loop
that drives re_tick(). By the time the timeout fires, if_re.ko
has been unloaded, which results in a call to invalid code and
blows up the system.
To fix this, I cleared the IFF_UP flag before calling ether_ifdetach(),
which stops the ioctl routine from trying to reset the chip.
- Modified comments in re_rxeof() relating to the difference in
RX descriptor status bit layout between the 8139C+ and the gigE
chips. The layout is different because the frame length field
was expanded from 12 bits to 13, and they got rid of one of the
status bits to make room.
- Add diagnostic code (re_diag()) to test for the case where a user
has installed a broken 32-bit 8169 PCI NIC in a 64-bit slot. Some
NICs have the REQ64# and ACK64# lines connected even though the
board is 32-bit only (in this case, they should be pulled high).
This fools the chip into doing 64-bit DMA transfers even though
there is no 64-bit data path. To detect this, re_diag() puts the
chip into digital loopback mode and sets the receiver to promiscuous
mode, then initiates a single 64-byte packet transmission. The
frame is echoed back to the host, and if the frame contents are
intact, we know DMA is working correctly, otherwise we complain
loudly on the console and abort the device attach. (At the moment,
I don't know of any way to work around the problem other than
physically modifying the board, so until/unless I can think of a
software workaround, this will have do to.)
- Created re(4) man page
- Modified rlphy.c to allow re(4) to attach as well as rl(4).
Note that this code works for the sample 8169/Marvell 88E1000 NIC
that I have, but probably won't work for the 8169S/8110S chips.
RealTek has sent me some sample NICs, but they haven't arrived yet.
I will probably need to add an rlgphy driver to handle the on-board
PHY in the 8169S/8110S (it needs special DSP initialization).
2003-09-08 02:11:25 +00:00
|
|
|
if (sc->rl_type == RL_8139) {
|
2004-07-05 02:46:42 +00:00
|
|
|
switch (reg) {
|
1999-08-31 14:45:51 +00:00
|
|
|
case MII_BMCR:
|
1998-10-18 16:24:34 +00:00
|
|
|
rl8139_reg = RL_BMCR;
|
|
|
|
break;
|
1999-08-31 14:45:51 +00:00
|
|
|
case MII_BMSR:
|
1998-10-18 16:24:34 +00:00
|
|
|
rl8139_reg = RL_BMSR;
|
|
|
|
break;
|
1999-08-31 14:45:51 +00:00
|
|
|
case MII_ANAR:
|
1998-10-18 16:24:34 +00:00
|
|
|
rl8139_reg = RL_ANAR;
|
|
|
|
break;
|
1999-08-31 14:45:51 +00:00
|
|
|
case MII_ANER:
|
|
|
|
rl8139_reg = RL_ANER;
|
|
|
|
break;
|
|
|
|
case MII_ANLPAR:
|
1998-10-18 16:24:34 +00:00
|
|
|
rl8139_reg = RL_LPAR;
|
|
|
|
break;
|
1999-08-31 14:45:51 +00:00
|
|
|
case MII_PHYIDR1:
|
|
|
|
case MII_PHYIDR2:
|
2004-07-05 02:46:42 +00:00
|
|
|
return (0);
|
2002-04-07 20:55:50 +00:00
|
|
|
/*
|
|
|
|
* Allow the rlphy driver to read the media status
|
|
|
|
* register. If we have a link partner which does not
|
|
|
|
* support NWAY, this is the register which will tell
|
|
|
|
* us the results of parallel detection.
|
|
|
|
*/
|
|
|
|
case RL_MEDIASTAT:
|
2011-11-01 16:13:59 +00:00
|
|
|
return (CSR_READ_1(sc, RL_MEDIASTAT));
|
1998-10-18 16:24:34 +00:00
|
|
|
default:
|
2006-09-15 10:40:54 +00:00
|
|
|
device_printf(sc->rl_dev, "bad phy register\n");
|
2004-07-05 02:46:42 +00:00
|
|
|
return (0);
|
1998-10-18 16:24:34 +00:00
|
|
|
}
|
2011-11-01 16:13:59 +00:00
|
|
|
return (CSR_READ_2(sc, rl8139_reg));
|
1998-10-18 16:24:34 +00:00
|
|
|
}
|
|
|
|
|
2011-11-01 16:13:59 +00:00
|
|
|
return (mii_bitbang_readreg(dev, &rl_mii_bitbang_ops, phy, reg));
|
1998-10-18 16:24:34 +00:00
|
|
|
}
|
|
|
|
|
2002-08-23 23:49:02 +00:00
|
|
|
static int
|
2004-07-05 02:46:42 +00:00
|
|
|
rl_miibus_writereg(device_t dev, int phy, int reg, int data)
|
1998-10-18 16:24:34 +00:00
|
|
|
{
|
1999-08-31 14:45:51 +00:00
|
|
|
struct rl_softc *sc;
|
2011-11-01 16:13:59 +00:00
|
|
|
uint16_t rl8139_reg;
|
1998-10-18 16:24:34 +00:00
|
|
|
|
1999-08-31 14:45:51 +00:00
|
|
|
sc = device_get_softc(dev);
|
|
|
|
|
Take the support for the 8139C+/8169/8169S/8110S chips out of the
rl(4) driver and put it in a new re(4) driver. The re(4) driver shares
the if_rlreg.h file with rl(4) but is a separate module. (Ultimately
I may change this. For now, it's convenient.)
rl(4) has been modified so that it will never attach to an 8139C+
chip, leaving it to re(4) instead. Only re(4) has the PCI IDs to
match the 8169/8169S/8110S gigE chips. if_re.c contains the same
basic code that was originally bolted onto if_rl.c, with the
following updates:
- Added support for jumbo frames. Currently, there seems to be
a limit of approximately 6200 bytes for jumbo frames on transmit.
(This was determined via experimentation.) The 8169S/8110S chips
apparently are limited to 7.5K frames on transmit. This may require
some more work, though the framework to handle jumbo frames on RX
is in place: the re_rxeof() routine will gather up frames than span
multiple 2K clusters into a single mbuf list.
- Fixed bug in re_txeof(): if we reap some of the TX buffers,
but there are still some pending, re-arm the timer before exiting
re_txeof() so that another timeout interrupt will be generated, just
in case re_start() doesn't do it for us.
- Handle the 'link state changed' interrupt
- Fix a detach bug. If re(4) is loaded as a module, and you do
tcpdump -i re0, then you do 'kldunload if_re,' the system will
panic after a few seconds. This happens because ether_ifdetach()
ends up calling the BPF detach code, which notices the interface
is in promiscuous mode and tries to switch promisc mode off while
detaching the BPF listner. This ultimately results in a call
to re_ioctl() (due to SIOCSIFFLAGS), which in turn calls re_init()
to handle the IFF_PROMISC flag change. Unfortunately, calling re_init()
here turns the chip back on and restarts the 1-second timeout loop
that drives re_tick(). By the time the timeout fires, if_re.ko
has been unloaded, which results in a call to invalid code and
blows up the system.
To fix this, I cleared the IFF_UP flag before calling ether_ifdetach(),
which stops the ioctl routine from trying to reset the chip.
- Modified comments in re_rxeof() relating to the difference in
RX descriptor status bit layout between the 8139C+ and the gigE
chips. The layout is different because the frame length field
was expanded from 12 bits to 13, and they got rid of one of the
status bits to make room.
- Add diagnostic code (re_diag()) to test for the case where a user
has installed a broken 32-bit 8169 PCI NIC in a 64-bit slot. Some
NICs have the REQ64# and ACK64# lines connected even though the
board is 32-bit only (in this case, they should be pulled high).
This fools the chip into doing 64-bit DMA transfers even though
there is no 64-bit data path. To detect this, re_diag() puts the
chip into digital loopback mode and sets the receiver to promiscuous
mode, then initiates a single 64-byte packet transmission. The
frame is echoed back to the host, and if the frame contents are
intact, we know DMA is working correctly, otherwise we complain
loudly on the console and abort the device attach. (At the moment,
I don't know of any way to work around the problem other than
physically modifying the board, so until/unless I can think of a
software workaround, this will have do to.)
- Created re(4) man page
- Modified rlphy.c to allow re(4) to attach as well as rl(4).
Note that this code works for the sample 8169/Marvell 88E1000 NIC
that I have, but probably won't work for the 8169S/8110S chips.
RealTek has sent me some sample NICs, but they haven't arrived yet.
I will probably need to add an rlgphy driver to handle the on-board
PHY in the 8169S/8110S (it needs special DSP initialization).
2003-09-08 02:11:25 +00:00
|
|
|
if (sc->rl_type == RL_8139) {
|
2004-07-05 02:46:42 +00:00
|
|
|
switch (reg) {
|
1999-08-31 14:45:51 +00:00
|
|
|
case MII_BMCR:
|
1998-10-18 16:24:34 +00:00
|
|
|
rl8139_reg = RL_BMCR;
|
|
|
|
break;
|
1999-08-31 14:45:51 +00:00
|
|
|
case MII_BMSR:
|
1998-10-18 16:24:34 +00:00
|
|
|
rl8139_reg = RL_BMSR;
|
|
|
|
break;
|
1999-08-31 14:45:51 +00:00
|
|
|
case MII_ANAR:
|
1998-10-18 16:24:34 +00:00
|
|
|
rl8139_reg = RL_ANAR;
|
|
|
|
break;
|
1999-08-31 14:45:51 +00:00
|
|
|
case MII_ANER:
|
|
|
|
rl8139_reg = RL_ANER;
|
|
|
|
break;
|
|
|
|
case MII_ANLPAR:
|
1998-10-18 16:24:34 +00:00
|
|
|
rl8139_reg = RL_LPAR;
|
|
|
|
break;
|
1999-08-31 14:45:51 +00:00
|
|
|
case MII_PHYIDR1:
|
|
|
|
case MII_PHYIDR2:
|
2004-07-05 02:46:42 +00:00
|
|
|
return (0);
|
1999-08-31 14:45:51 +00:00
|
|
|
break;
|
1998-10-18 16:24:34 +00:00
|
|
|
default:
|
2006-09-15 10:40:54 +00:00
|
|
|
device_printf(sc->rl_dev, "bad phy register\n");
|
2004-07-05 02:46:42 +00:00
|
|
|
return (0);
|
1998-10-18 16:24:34 +00:00
|
|
|
}
|
|
|
|
CSR_WRITE_2(sc, rl8139_reg, data);
|
2004-07-05 02:46:42 +00:00
|
|
|
return (0);
|
1998-10-18 16:24:34 +00:00
|
|
|
}
|
|
|
|
|
2011-11-01 16:13:59 +00:00
|
|
|
mii_bitbang_writereg(dev, &rl_mii_bitbang_ops, phy, reg, data);
|
1998-10-18 16:24:34 +00:00
|
|
|
|
2004-07-05 02:46:42 +00:00
|
|
|
return (0);
|
1999-08-31 14:45:51 +00:00
|
|
|
}
|
|
|
|
|
2002-08-23 23:49:02 +00:00
|
|
|
static void
|
2004-07-05 02:46:42 +00:00
|
|
|
rl_miibus_statchg(device_t dev)
|
1999-08-31 14:45:51 +00:00
|
|
|
{
|
2008-10-25 03:41:36 +00:00
|
|
|
struct rl_softc *sc;
|
|
|
|
struct ifnet *ifp;
|
|
|
|
struct mii_data *mii;
|
|
|
|
|
|
|
|
sc = device_get_softc(dev);
|
|
|
|
mii = device_get_softc(sc->rl_miibus);
|
|
|
|
ifp = sc->rl_ifp;
|
|
|
|
if (mii == NULL || ifp == NULL ||
|
|
|
|
(ifp->if_drv_flags & IFF_DRV_RUNNING) == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
sc->rl_flags &= ~RL_FLAG_LINK;
|
|
|
|
if ((mii->mii_media_status & (IFM_ACTIVE | IFM_AVALID)) ==
|
|
|
|
(IFM_ACTIVE | IFM_AVALID)) {
|
|
|
|
switch (IFM_SUBTYPE(mii->mii_media_active)) {
|
|
|
|
case IFM_10_T:
|
|
|
|
case IFM_100_TX:
|
|
|
|
sc->rl_flags |= RL_FLAG_LINK;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* RealTek controllers do not provide any interface to
|
|
|
|
* Tx/Rx MACs for resolved speed, duplex and flow-control
|
|
|
|
* parameters.
|
|
|
|
*/
|
1998-10-18 16:24:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Program the 64-bit multicast hash filter.
|
|
|
|
*/
|
2002-08-23 23:49:02 +00:00
|
|
|
static void
|
2010-09-30 17:37:08 +00:00
|
|
|
rl_rxfilter(struct rl_softc *sc)
|
1998-10-18 16:24:34 +00:00
|
|
|
{
|
2005-06-10 16:49:24 +00:00
|
|
|
struct ifnet *ifp = sc->rl_ifp;
|
1998-10-18 16:24:34 +00:00
|
|
|
int h = 0;
|
2004-07-05 02:46:42 +00:00
|
|
|
uint32_t hashes[2] = { 0, 0 };
|
1998-10-18 16:24:34 +00:00
|
|
|
struct ifmultiaddr *ifma;
|
2004-07-05 02:46:42 +00:00
|
|
|
uint32_t rxfilt;
|
1998-10-18 16:24:34 +00:00
|
|
|
|
2004-07-05 02:51:32 +00:00
|
|
|
RL_LOCK_ASSERT(sc);
|
|
|
|
|
1998-10-18 16:24:34 +00:00
|
|
|
rxfilt = CSR_READ_4(sc, RL_RXCFG);
|
2010-09-30 17:37:08 +00:00
|
|
|
rxfilt &= ~(RL_RXCFG_RX_ALLPHYS | RL_RXCFG_RX_BROAD |
|
|
|
|
RL_RXCFG_RX_MULTI);
|
|
|
|
/* Always accept frames destined for this host. */
|
|
|
|
rxfilt |= RL_RXCFG_RX_INDIV;
|
|
|
|
/* Set capture broadcast bit to capture broadcast frames. */
|
|
|
|
if (ifp->if_flags & IFF_BROADCAST)
|
|
|
|
rxfilt |= RL_RXCFG_RX_BROAD;
|
1999-01-22 15:25:04 +00:00
|
|
|
if (ifp->if_flags & IFF_ALLMULTI || ifp->if_flags & IFF_PROMISC) {
|
1998-10-18 16:24:34 +00:00
|
|
|
rxfilt |= RL_RXCFG_RX_MULTI;
|
2010-09-30 17:37:08 +00:00
|
|
|
if (ifp->if_flags & IFF_PROMISC)
|
|
|
|
rxfilt |= RL_RXCFG_RX_ALLPHYS;
|
|
|
|
hashes[0] = 0xFFFFFFFF;
|
|
|
|
hashes[1] = 0xFFFFFFFF;
|
|
|
|
} else {
|
|
|
|
/* Now program new ones. */
|
|
|
|
if_maddr_rlock(ifp);
|
|
|
|
TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
|
|
|
|
if (ifma->ifma_addr->sa_family != AF_LINK)
|
|
|
|
continue;
|
|
|
|
h = ether_crc32_be(LLADDR((struct sockaddr_dl *)
|
|
|
|
ifma->ifma_addr), ETHER_ADDR_LEN) >> 26;
|
|
|
|
if (h < 32)
|
|
|
|
hashes[0] |= (1 << h);
|
|
|
|
else
|
|
|
|
hashes[1] |= (1 << (h - 32));
|
|
|
|
}
|
|
|
|
if_maddr_runlock(ifp);
|
|
|
|
if (hashes[0] != 0 || hashes[1] != 0)
|
|
|
|
rxfilt |= RL_RXCFG_RX_MULTI;
|
1998-10-18 16:24:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CSR_WRITE_4(sc, RL_MAR0, hashes[0]);
|
|
|
|
CSR_WRITE_4(sc, RL_MAR4, hashes[1]);
|
2010-09-30 17:37:08 +00:00
|
|
|
CSR_WRITE_4(sc, RL_RXCFG, rxfilt);
|
1998-10-18 16:24:34 +00:00
|
|
|
}
|
|
|
|
|
2002-08-23 23:49:02 +00:00
|
|
|
static void
|
2004-07-05 02:46:42 +00:00
|
|
|
rl_reset(struct rl_softc *sc)
|
1998-10-18 16:24:34 +00:00
|
|
|
{
|
|
|
|
register int i;
|
|
|
|
|
2004-07-05 02:51:32 +00:00
|
|
|
RL_LOCK_ASSERT(sc);
|
|
|
|
|
1998-10-18 16:24:34 +00:00
|
|
|
CSR_WRITE_1(sc, RL_COMMAND, RL_CMD_RESET);
|
|
|
|
|
|
|
|
for (i = 0; i < RL_TIMEOUT; i++) {
|
|
|
|
DELAY(10);
|
|
|
|
if (!(CSR_READ_1(sc, RL_COMMAND) & RL_CMD_RESET))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (i == RL_TIMEOUT)
|
2006-09-15 10:40:54 +00:00
|
|
|
device_printf(sc->rl_dev, "reset never completed!\n");
|
1998-10-18 16:24:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Probe for a RealTek 8129/8139 chip. Check the PCI vendor and device
|
|
|
|
* IDs against our list and return a device name if we find a match.
|
|
|
|
*/
|
2002-08-23 23:49:02 +00:00
|
|
|
static int
|
2004-07-05 02:46:42 +00:00
|
|
|
rl_probe(device_t dev)
|
1998-10-18 16:24:34 +00:00
|
|
|
{
|
2011-11-01 16:13:59 +00:00
|
|
|
const struct rl_type *t;
|
2008-03-03 04:15:08 +00:00
|
|
|
uint16_t devid, revid, vendor;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
vendor = pci_get_vendor(dev);
|
|
|
|
devid = pci_get_device(dev);
|
|
|
|
revid = pci_get_revid(dev);
|
|
|
|
|
|
|
|
if (vendor == RT_VENDORID && devid == RT_DEVICEID_8139) {
|
|
|
|
if (revid == 0x20) {
|
|
|
|
/* 8139C+, let re(4) take care of this device. */
|
|
|
|
return (ENXIO);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
t = rl_devs;
|
|
|
|
for (i = 0; i < sizeof(rl_devs) / sizeof(rl_devs[0]); i++, t++) {
|
|
|
|
if (vendor == t->rl_vid && devid == t->rl_did) {
|
Take the support for the 8139C+/8169/8169S/8110S chips out of the
rl(4) driver and put it in a new re(4) driver. The re(4) driver shares
the if_rlreg.h file with rl(4) but is a separate module. (Ultimately
I may change this. For now, it's convenient.)
rl(4) has been modified so that it will never attach to an 8139C+
chip, leaving it to re(4) instead. Only re(4) has the PCI IDs to
match the 8169/8169S/8110S gigE chips. if_re.c contains the same
basic code that was originally bolted onto if_rl.c, with the
following updates:
- Added support for jumbo frames. Currently, there seems to be
a limit of approximately 6200 bytes for jumbo frames on transmit.
(This was determined via experimentation.) The 8169S/8110S chips
apparently are limited to 7.5K frames on transmit. This may require
some more work, though the framework to handle jumbo frames on RX
is in place: the re_rxeof() routine will gather up frames than span
multiple 2K clusters into a single mbuf list.
- Fixed bug in re_txeof(): if we reap some of the TX buffers,
but there are still some pending, re-arm the timer before exiting
re_txeof() so that another timeout interrupt will be generated, just
in case re_start() doesn't do it for us.
- Handle the 'link state changed' interrupt
- Fix a detach bug. If re(4) is loaded as a module, and you do
tcpdump -i re0, then you do 'kldunload if_re,' the system will
panic after a few seconds. This happens because ether_ifdetach()
ends up calling the BPF detach code, which notices the interface
is in promiscuous mode and tries to switch promisc mode off while
detaching the BPF listner. This ultimately results in a call
to re_ioctl() (due to SIOCSIFFLAGS), which in turn calls re_init()
to handle the IFF_PROMISC flag change. Unfortunately, calling re_init()
here turns the chip back on and restarts the 1-second timeout loop
that drives re_tick(). By the time the timeout fires, if_re.ko
has been unloaded, which results in a call to invalid code and
blows up the system.
To fix this, I cleared the IFF_UP flag before calling ether_ifdetach(),
which stops the ioctl routine from trying to reset the chip.
- Modified comments in re_rxeof() relating to the difference in
RX descriptor status bit layout between the 8139C+ and the gigE
chips. The layout is different because the frame length field
was expanded from 12 bits to 13, and they got rid of one of the
status bits to make room.
- Add diagnostic code (re_diag()) to test for the case where a user
has installed a broken 32-bit 8169 PCI NIC in a 64-bit slot. Some
NICs have the REQ64# and ACK64# lines connected even though the
board is 32-bit only (in this case, they should be pulled high).
This fools the chip into doing 64-bit DMA transfers even though
there is no 64-bit data path. To detect this, re_diag() puts the
chip into digital loopback mode and sets the receiver to promiscuous
mode, then initiates a single 64-byte packet transmission. The
frame is echoed back to the host, and if the frame contents are
intact, we know DMA is working correctly, otherwise we complain
loudly on the console and abort the device attach. (At the moment,
I don't know of any way to work around the problem other than
physically modifying the board, so until/unless I can think of a
software workaround, this will have do to.)
- Created re(4) man page
- Modified rlphy.c to allow re(4) to attach as well as rl(4).
Note that this code works for the sample 8169/Marvell 88E1000 NIC
that I have, but probably won't work for the 8169S/8110S chips.
RealTek has sent me some sample NICs, but they haven't arrived yet.
I will probably need to add an rlgphy driver to handle the on-board
PHY in the 8169S/8110S (it needs special DSP initialization).
2003-09-08 02:11:25 +00:00
|
|
|
device_set_desc(dev, t->rl_name);
|
2005-02-24 21:32:56 +00:00
|
|
|
return (BUS_PROBE_DEFAULT);
|
1998-10-18 16:24:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-07-05 02:46:42 +00:00
|
|
|
return (ENXIO);
|
1998-10-18 16:24:34 +00:00
|
|
|
}
|
|
|
|
|
2008-10-25 02:36:08 +00:00
|
|
|
struct rl_dmamap_arg {
|
|
|
|
bus_addr_t rl_busaddr;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
rl_dmamap_cb(void *arg, bus_dma_segment_t *segs, int nsegs, int error)
|
|
|
|
{
|
|
|
|
struct rl_dmamap_arg *ctx;
|
|
|
|
|
|
|
|
if (error != 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
KASSERT(nsegs == 1, ("%s: %d segments returned!", __func__, nsegs));
|
|
|
|
|
|
|
|
ctx = (struct rl_dmamap_arg *)arg;
|
|
|
|
ctx->rl_busaddr = segs[0].ds_addr;
|
|
|
|
}
|
|
|
|
|
1998-10-18 16:24:34 +00:00
|
|
|
/*
|
|
|
|
* Attach the interface. Allocate softc structures, do ifmedia
|
|
|
|
* setup and ethernet/BPF attach.
|
|
|
|
*/
|
2002-08-23 23:49:02 +00:00
|
|
|
static int
|
2004-07-05 02:46:42 +00:00
|
|
|
rl_attach(device_t dev)
|
1998-10-18 16:24:34 +00:00
|
|
|
{
|
2004-07-05 02:46:42 +00:00
|
|
|
uint8_t eaddr[ETHER_ADDR_LEN];
|
|
|
|
uint16_t as[3];
|
1998-10-18 16:24:34 +00:00
|
|
|
struct ifnet *ifp;
|
2004-07-05 02:46:42 +00:00
|
|
|
struct rl_softc *sc;
|
2011-11-01 16:13:59 +00:00
|
|
|
const struct rl_type *t;
|
2008-11-02 16:50:57 +00:00
|
|
|
struct sysctl_ctx_list *ctx;
|
|
|
|
struct sysctl_oid_list *children;
|
2010-10-15 14:52:11 +00:00
|
|
|
int error = 0, hwrev, i, phy, pmc, rid;
|
2010-08-22 21:26:35 +00:00
|
|
|
int prefer_iomap, unit;
|
2004-07-05 02:46:42 +00:00
|
|
|
uint16_t rl_did = 0;
|
2008-11-02 16:50:57 +00:00
|
|
|
char tn[32];
|
1998-10-18 16:24:34 +00:00
|
|
|
|
1999-08-31 14:45:51 +00:00
|
|
|
sc = device_get_softc(dev);
|
|
|
|
unit = device_get_unit(dev);
|
2006-09-15 10:40:54 +00:00
|
|
|
sc->rl_dev = dev;
|
1998-10-18 16:24:34 +00:00
|
|
|
|
2008-11-02 16:50:57 +00:00
|
|
|
sc->rl_twister_enable = 0;
|
|
|
|
snprintf(tn, sizeof(tn), "dev.rl.%d.twister_enable", unit);
|
|
|
|
TUNABLE_INT_FETCH(tn, &sc->rl_twister_enable);
|
|
|
|
ctx = device_get_sysctl_ctx(sc->rl_dev);
|
|
|
|
children = SYSCTL_CHILDREN(device_get_sysctl_tree(sc->rl_dev));
|
|
|
|
SYSCTL_ADD_INT(ctx, children, OID_AUTO, "twister_enable", CTLFLAG_RD,
|
|
|
|
&sc->rl_twister_enable, 0, "");
|
|
|
|
|
2002-04-04 21:03:38 +00:00
|
|
|
mtx_init(&sc->rl_mtx, device_get_nameunit(dev), MTX_NETWORK_LOCK,
|
2004-07-05 02:51:32 +00:00
|
|
|
MTX_DEF);
|
2005-09-29 16:52:19 +00:00
|
|
|
callout_init_mtx(&sc->rl_stat_callout, &sc->rl_mtx, 0);
|
2004-07-05 02:46:42 +00:00
|
|
|
|
2001-02-21 20:54:22 +00:00
|
|
|
pci_enable_busmaster(dev);
|
1998-10-18 16:24:34 +00:00
|
|
|
|
1999-08-31 14:45:51 +00:00
|
|
|
|
2010-08-22 21:26:35 +00:00
|
|
|
/*
|
|
|
|
* Map control/status registers.
|
|
|
|
* Default to using PIO access for this driver. On SMP systems,
|
|
|
|
* there appear to be problems with memory mapped mode: it looks
|
|
|
|
* like doing too many memory mapped access back to back in rapid
|
|
|
|
* succession can hang the bus. I'm inclined to blame this on
|
|
|
|
* crummy design/construction on the part of RealTek. Memory
|
|
|
|
* mapped mode does appear to work on uniprocessor systems though.
|
|
|
|
*/
|
|
|
|
prefer_iomap = 1;
|
|
|
|
snprintf(tn, sizeof(tn), "dev.rl.%d.prefer_iomap", unit);
|
|
|
|
TUNABLE_INT_FETCH(tn, &prefer_iomap);
|
|
|
|
if (prefer_iomap) {
|
|
|
|
sc->rl_res_id = PCIR_BAR(0);
|
|
|
|
sc->rl_res_type = SYS_RES_IOPORT;
|
|
|
|
sc->rl_res = bus_alloc_resource_any(dev, sc->rl_res_type,
|
|
|
|
&sc->rl_res_id, RF_ACTIVE);
|
|
|
|
}
|
|
|
|
if (prefer_iomap == 0 || sc->rl_res == NULL) {
|
|
|
|
sc->rl_res_id = PCIR_BAR(1);
|
|
|
|
sc->rl_res_type = SYS_RES_MEMORY;
|
|
|
|
sc->rl_res = bus_alloc_resource_any(dev, sc->rl_res_type,
|
|
|
|
&sc->rl_res_id, RF_ACTIVE);
|
|
|
|
}
|
1999-08-31 14:45:51 +00:00
|
|
|
if (sc->rl_res == NULL) {
|
2004-07-05 02:46:42 +00:00
|
|
|
device_printf(dev, "couldn't map ports/memory\n");
|
1999-08-31 14:45:51 +00:00
|
|
|
error = ENXIO;
|
1998-10-18 16:24:34 +00:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2003-07-10 20:38:48 +00:00
|
|
|
#ifdef notdef
|
2004-07-05 02:46:42 +00:00
|
|
|
/*
|
|
|
|
* Detect the Realtek 8139B. For some reason, this chip is very
|
2000-11-24 17:36:07 +00:00
|
|
|
* unstable when left to autoselect the media
|
|
|
|
* The best workaround is to set the device to the required
|
|
|
|
* media type or to set it to the 10 Meg speed.
|
|
|
|
*/
|
2004-07-05 02:46:42 +00:00
|
|
|
if ((rman_get_end(sc->rl_res) - rman_get_start(sc->rl_res)) == 0xFF)
|
|
|
|
device_printf(dev,
|
|
|
|
"Realtek 8139B detected. Warning, this may be unstable in autoselect mode\n");
|
2003-07-10 20:38:48 +00:00
|
|
|
#endif
|
2000-11-24 17:36:07 +00:00
|
|
|
|
1999-08-31 14:45:51 +00:00
|
|
|
sc->rl_btag = rman_get_bustag(sc->rl_res);
|
|
|
|
sc->rl_bhandle = rman_get_bushandle(sc->rl_res);
|
|
|
|
|
2003-03-31 17:29:43 +00:00
|
|
|
/* Allocate interrupt */
|
1999-08-31 14:45:51 +00:00
|
|
|
rid = 0;
|
2007-07-24 01:24:03 +00:00
|
|
|
sc->rl_irq[0] = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid,
|
1999-08-31 14:45:51 +00:00
|
|
|
RF_SHAREABLE | RF_ACTIVE);
|
|
|
|
|
2007-07-24 01:24:03 +00:00
|
|
|
if (sc->rl_irq[0] == NULL) {
|
2004-07-05 02:46:42 +00:00
|
|
|
device_printf(dev, "couldn't map interrupt\n");
|
1999-08-31 14:45:51 +00:00
|
|
|
error = ENXIO;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2012-02-25 04:54:51 +00:00
|
|
|
sc->rl_cfg0 = RL_8139_CFG0;
|
|
|
|
sc->rl_cfg1 = RL_8139_CFG1;
|
|
|
|
sc->rl_cfg2 = 0;
|
|
|
|
sc->rl_cfg3 = RL_8139_CFG3;
|
|
|
|
sc->rl_cfg4 = RL_8139_CFG4;
|
|
|
|
sc->rl_cfg5 = RL_8139_CFG5;
|
|
|
|
|
2004-07-05 02:51:32 +00:00
|
|
|
/*
|
|
|
|
* Reset the adapter. Only take the lock here as it's needed in
|
|
|
|
* order to call rl_reset().
|
|
|
|
*/
|
|
|
|
RL_LOCK(sc);
|
1998-10-18 16:24:34 +00:00
|
|
|
rl_reset(sc);
|
2004-07-05 02:51:32 +00:00
|
|
|
RL_UNLOCK(sc);
|
|
|
|
|
2000-10-30 07:54:38 +00:00
|
|
|
sc->rl_eecmd_read = RL_EECMD_READ_6BIT;
|
2004-07-05 02:46:42 +00:00
|
|
|
rl_read_eeprom(sc, (uint8_t *)&rl_did, 0, 1, 0);
|
2000-11-01 23:56:46 +00:00
|
|
|
if (rl_did != 0x8129)
|
2000-10-30 07:54:38 +00:00
|
|
|
sc->rl_eecmd_read = RL_EECMD_READ_8BIT;
|
1998-10-18 16:24:34 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Get station address from the EEPROM.
|
|
|
|
*/
|
2004-07-05 02:46:42 +00:00
|
|
|
rl_read_eeprom(sc, (uint8_t *)as, RL_EE_EADDR, 3, 0);
|
2003-01-05 21:36:59 +00:00
|
|
|
for (i = 0; i < 3; i++) {
|
|
|
|
eaddr[(i * 2) + 0] = as[i] & 0xff;
|
|
|
|
eaddr[(i * 2) + 1] = as[i] >> 8;
|
|
|
|
}
|
1998-10-18 16:24:34 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Now read the exact device type from the EEPROM to find
|
|
|
|
* out if it's an 8129 or 8139.
|
|
|
|
*/
|
2004-07-05 02:46:42 +00:00
|
|
|
rl_read_eeprom(sc, (uint8_t *)&rl_did, RL_EE_PCI_DID, 1, 0);
|
1998-10-18 16:24:34 +00:00
|
|
|
|
2003-07-10 20:38:48 +00:00
|
|
|
t = rl_devs;
|
Take the support for the 8139C+/8169/8169S/8110S chips out of the
rl(4) driver and put it in a new re(4) driver. The re(4) driver shares
the if_rlreg.h file with rl(4) but is a separate module. (Ultimately
I may change this. For now, it's convenient.)
rl(4) has been modified so that it will never attach to an 8139C+
chip, leaving it to re(4) instead. Only re(4) has the PCI IDs to
match the 8169/8169S/8110S gigE chips. if_re.c contains the same
basic code that was originally bolted onto if_rl.c, with the
following updates:
- Added support for jumbo frames. Currently, there seems to be
a limit of approximately 6200 bytes for jumbo frames on transmit.
(This was determined via experimentation.) The 8169S/8110S chips
apparently are limited to 7.5K frames on transmit. This may require
some more work, though the framework to handle jumbo frames on RX
is in place: the re_rxeof() routine will gather up frames than span
multiple 2K clusters into a single mbuf list.
- Fixed bug in re_txeof(): if we reap some of the TX buffers,
but there are still some pending, re-arm the timer before exiting
re_txeof() so that another timeout interrupt will be generated, just
in case re_start() doesn't do it for us.
- Handle the 'link state changed' interrupt
- Fix a detach bug. If re(4) is loaded as a module, and you do
tcpdump -i re0, then you do 'kldunload if_re,' the system will
panic after a few seconds. This happens because ether_ifdetach()
ends up calling the BPF detach code, which notices the interface
is in promiscuous mode and tries to switch promisc mode off while
detaching the BPF listner. This ultimately results in a call
to re_ioctl() (due to SIOCSIFFLAGS), which in turn calls re_init()
to handle the IFF_PROMISC flag change. Unfortunately, calling re_init()
here turns the chip back on and restarts the 1-second timeout loop
that drives re_tick(). By the time the timeout fires, if_re.ko
has been unloaded, which results in a call to invalid code and
blows up the system.
To fix this, I cleared the IFF_UP flag before calling ether_ifdetach(),
which stops the ioctl routine from trying to reset the chip.
- Modified comments in re_rxeof() relating to the difference in
RX descriptor status bit layout between the 8139C+ and the gigE
chips. The layout is different because the frame length field
was expanded from 12 bits to 13, and they got rid of one of the
status bits to make room.
- Add diagnostic code (re_diag()) to test for the case where a user
has installed a broken 32-bit 8169 PCI NIC in a 64-bit slot. Some
NICs have the REQ64# and ACK64# lines connected even though the
board is 32-bit only (in this case, they should be pulled high).
This fools the chip into doing 64-bit DMA transfers even though
there is no 64-bit data path. To detect this, re_diag() puts the
chip into digital loopback mode and sets the receiver to promiscuous
mode, then initiates a single 64-byte packet transmission. The
frame is echoed back to the host, and if the frame contents are
intact, we know DMA is working correctly, otherwise we complain
loudly on the console and abort the device attach. (At the moment,
I don't know of any way to work around the problem other than
physically modifying the board, so until/unless I can think of a
software workaround, this will have do to.)
- Created re(4) man page
- Modified rlphy.c to allow re(4) to attach as well as rl(4).
Note that this code works for the sample 8169/Marvell 88E1000 NIC
that I have, but probably won't work for the 8169S/8110S chips.
RealTek has sent me some sample NICs, but they haven't arrived yet.
I will probably need to add an rlgphy driver to handle the on-board
PHY in the 8169S/8110S (it needs special DSP initialization).
2003-09-08 02:11:25 +00:00
|
|
|
sc->rl_type = 0;
|
2003-07-10 20:38:48 +00:00
|
|
|
while(t->rl_name != NULL) {
|
|
|
|
if (rl_did == t->rl_did) {
|
|
|
|
sc->rl_type = t->rl_basetype;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
t++;
|
|
|
|
}
|
Take the support for the 8139C+/8169/8169S/8110S chips out of the
rl(4) driver and put it in a new re(4) driver. The re(4) driver shares
the if_rlreg.h file with rl(4) but is a separate module. (Ultimately
I may change this. For now, it's convenient.)
rl(4) has been modified so that it will never attach to an 8139C+
chip, leaving it to re(4) instead. Only re(4) has the PCI IDs to
match the 8169/8169S/8110S gigE chips. if_re.c contains the same
basic code that was originally bolted onto if_rl.c, with the
following updates:
- Added support for jumbo frames. Currently, there seems to be
a limit of approximately 6200 bytes for jumbo frames on transmit.
(This was determined via experimentation.) The 8169S/8110S chips
apparently are limited to 7.5K frames on transmit. This may require
some more work, though the framework to handle jumbo frames on RX
is in place: the re_rxeof() routine will gather up frames than span
multiple 2K clusters into a single mbuf list.
- Fixed bug in re_txeof(): if we reap some of the TX buffers,
but there are still some pending, re-arm the timer before exiting
re_txeof() so that another timeout interrupt will be generated, just
in case re_start() doesn't do it for us.
- Handle the 'link state changed' interrupt
- Fix a detach bug. If re(4) is loaded as a module, and you do
tcpdump -i re0, then you do 'kldunload if_re,' the system will
panic after a few seconds. This happens because ether_ifdetach()
ends up calling the BPF detach code, which notices the interface
is in promiscuous mode and tries to switch promisc mode off while
detaching the BPF listner. This ultimately results in a call
to re_ioctl() (due to SIOCSIFFLAGS), which in turn calls re_init()
to handle the IFF_PROMISC flag change. Unfortunately, calling re_init()
here turns the chip back on and restarts the 1-second timeout loop
that drives re_tick(). By the time the timeout fires, if_re.ko
has been unloaded, which results in a call to invalid code and
blows up the system.
To fix this, I cleared the IFF_UP flag before calling ether_ifdetach(),
which stops the ioctl routine from trying to reset the chip.
- Modified comments in re_rxeof() relating to the difference in
RX descriptor status bit layout between the 8139C+ and the gigE
chips. The layout is different because the frame length field
was expanded from 12 bits to 13, and they got rid of one of the
status bits to make room.
- Add diagnostic code (re_diag()) to test for the case where a user
has installed a broken 32-bit 8169 PCI NIC in a 64-bit slot. Some
NICs have the REQ64# and ACK64# lines connected even though the
board is 32-bit only (in this case, they should be pulled high).
This fools the chip into doing 64-bit DMA transfers even though
there is no 64-bit data path. To detect this, re_diag() puts the
chip into digital loopback mode and sets the receiver to promiscuous
mode, then initiates a single 64-byte packet transmission. The
frame is echoed back to the host, and if the frame contents are
intact, we know DMA is working correctly, otherwise we complain
loudly on the console and abort the device attach. (At the moment,
I don't know of any way to work around the problem other than
physically modifying the board, so until/unless I can think of a
software workaround, this will have do to.)
- Created re(4) man page
- Modified rlphy.c to allow re(4) to attach as well as rl(4).
Note that this code works for the sample 8169/Marvell 88E1000 NIC
that I have, but probably won't work for the 8169S/8110S chips.
RealTek has sent me some sample NICs, but they haven't arrived yet.
I will probably need to add an rlgphy driver to handle the on-board
PHY in the 8169S/8110S (it needs special DSP initialization).
2003-09-08 02:11:25 +00:00
|
|
|
|
|
|
|
if (sc->rl_type == 0) {
|
2008-12-15 21:54:23 +00:00
|
|
|
device_printf(dev, "unknown device ID: %x assuming 8139\n",
|
|
|
|
rl_did);
|
|
|
|
sc->rl_type = RL_8139;
|
|
|
|
/*
|
|
|
|
* Read RL_IDR register to get ethernet address as accessing
|
|
|
|
* EEPROM may not extract correct address.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < ETHER_ADDR_LEN; i++)
|
|
|
|
eaddr[i] = CSR_READ_1(sc, RL_IDR0 + i);
|
1998-10-18 16:24:34 +00:00
|
|
|
}
|
|
|
|
|
2008-10-25 02:36:08 +00:00
|
|
|
if ((error = rl_dma_alloc(sc)) != 0)
|
2003-03-31 17:29:43 +00:00
|
|
|
goto fail;
|
2001-08-15 17:38:43 +00:00
|
|
|
|
2005-06-11 01:37:46 +00:00
|
|
|
ifp = sc->rl_ifp = if_alloc(IFT_ETHER);
|
|
|
|
if (ifp == NULL) {
|
|
|
|
device_printf(dev, "can not if_alloc()\n");
|
|
|
|
error = ENOSPC;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2010-10-15 14:52:11 +00:00
|
|
|
#define RL_PHYAD_INTERNAL 0
|
|
|
|
|
1999-08-31 14:45:51 +00:00
|
|
|
/* Do MII setup */
|
2010-10-15 14:52:11 +00:00
|
|
|
phy = MII_PHY_ANY;
|
|
|
|
if (sc->rl_type == RL_8139)
|
|
|
|
phy = RL_PHYAD_INTERNAL;
|
|
|
|
error = mii_attach(dev, &sc->rl_miibus, ifp, rl_ifmedia_upd,
|
|
|
|
rl_ifmedia_sts, BMSR_DEFCAPMASK, phy, MII_OFFSET_ANY, 0);
|
|
|
|
if (error != 0) {
|
|
|
|
device_printf(dev, "attaching PHYs failed\n");
|
1999-08-31 14:45:51 +00:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
1998-10-18 16:24:34 +00:00
|
|
|
ifp->if_softc = sc;
|
2003-10-31 18:32:15 +00:00
|
|
|
if_initname(ifp, device_get_name(dev), device_get_unit(dev));
|
1998-10-18 16:24:34 +00:00
|
|
|
ifp->if_mtu = ETHERMTU;
|
|
|
|
ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
|
|
|
|
ifp->if_ioctl = rl_ioctl;
|
Take the support for the 8139C+/8169/8169S/8110S chips out of the
rl(4) driver and put it in a new re(4) driver. The re(4) driver shares
the if_rlreg.h file with rl(4) but is a separate module. (Ultimately
I may change this. For now, it's convenient.)
rl(4) has been modified so that it will never attach to an 8139C+
chip, leaving it to re(4) instead. Only re(4) has the PCI IDs to
match the 8169/8169S/8110S gigE chips. if_re.c contains the same
basic code that was originally bolted onto if_rl.c, with the
following updates:
- Added support for jumbo frames. Currently, there seems to be
a limit of approximately 6200 bytes for jumbo frames on transmit.
(This was determined via experimentation.) The 8169S/8110S chips
apparently are limited to 7.5K frames on transmit. This may require
some more work, though the framework to handle jumbo frames on RX
is in place: the re_rxeof() routine will gather up frames than span
multiple 2K clusters into a single mbuf list.
- Fixed bug in re_txeof(): if we reap some of the TX buffers,
but there are still some pending, re-arm the timer before exiting
re_txeof() so that another timeout interrupt will be generated, just
in case re_start() doesn't do it for us.
- Handle the 'link state changed' interrupt
- Fix a detach bug. If re(4) is loaded as a module, and you do
tcpdump -i re0, then you do 'kldunload if_re,' the system will
panic after a few seconds. This happens because ether_ifdetach()
ends up calling the BPF detach code, which notices the interface
is in promiscuous mode and tries to switch promisc mode off while
detaching the BPF listner. This ultimately results in a call
to re_ioctl() (due to SIOCSIFFLAGS), which in turn calls re_init()
to handle the IFF_PROMISC flag change. Unfortunately, calling re_init()
here turns the chip back on and restarts the 1-second timeout loop
that drives re_tick(). By the time the timeout fires, if_re.ko
has been unloaded, which results in a call to invalid code and
blows up the system.
To fix this, I cleared the IFF_UP flag before calling ether_ifdetach(),
which stops the ioctl routine from trying to reset the chip.
- Modified comments in re_rxeof() relating to the difference in
RX descriptor status bit layout between the 8139C+ and the gigE
chips. The layout is different because the frame length field
was expanded from 12 bits to 13, and they got rid of one of the
status bits to make room.
- Add diagnostic code (re_diag()) to test for the case where a user
has installed a broken 32-bit 8169 PCI NIC in a 64-bit slot. Some
NICs have the REQ64# and ACK64# lines connected even though the
board is 32-bit only (in this case, they should be pulled high).
This fools the chip into doing 64-bit DMA transfers even though
there is no 64-bit data path. To detect this, re_diag() puts the
chip into digital loopback mode and sets the receiver to promiscuous
mode, then initiates a single 64-byte packet transmission. The
frame is echoed back to the host, and if the frame contents are
intact, we know DMA is working correctly, otherwise we complain
loudly on the console and abort the device attach. (At the moment,
I don't know of any way to work around the problem other than
physically modifying the board, so until/unless I can think of a
software workaround, this will have do to.)
- Created re(4) man page
- Modified rlphy.c to allow re(4) to attach as well as rl(4).
Note that this code works for the sample 8169/Marvell 88E1000 NIC
that I have, but probably won't work for the 8169S/8110S chips.
RealTek has sent me some sample NICs, but they haven't arrived yet.
I will probably need to add an rlgphy driver to handle the on-board
PHY in the 8169S/8110S (it needs special DSP initialization).
2003-09-08 02:11:25 +00:00
|
|
|
ifp->if_start = rl_start;
|
1998-10-18 16:24:34 +00:00
|
|
|
ifp->if_init = rl_init;
|
2003-09-11 03:53:46 +00:00
|
|
|
ifp->if_capabilities = IFCAP_VLAN_MTU;
|
2010-07-19 18:01:06 +00:00
|
|
|
/* Check WOL for RTL8139B or newer controllers. */
|
|
|
|
if (sc->rl_type == RL_8139 &&
|
2011-03-23 13:10:15 +00:00
|
|
|
pci_find_cap(sc->rl_dev, PCIY_PMG, &pmc) == 0) {
|
2010-07-19 18:01:06 +00:00
|
|
|
hwrev = CSR_READ_4(sc, RL_TXCFG) & RL_TXCFG_HWREV;
|
|
|
|
switch (hwrev) {
|
|
|
|
case RL_HWREV_8139B:
|
|
|
|
case RL_HWREV_8130:
|
|
|
|
case RL_HWREV_8139C:
|
|
|
|
case RL_HWREV_8139D:
|
|
|
|
case RL_HWREV_8101:
|
|
|
|
case RL_HWREV_8100:
|
|
|
|
ifp->if_capabilities |= IFCAP_WOL;
|
|
|
|
/* Disable WOL. */
|
|
|
|
rl_clrwol(sc);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
Big polling(4) cleanup.
o Axe poll in trap.
o Axe IFF_POLLING flag from if_flags.
o Rework revision 1.21 (Giant removal), in such a way that
poll_mtx is not dropped during call to polling handler.
This fixes problem with idle polling.
o Make registration and deregistration from polling in a
functional way, insted of next tick/interrupt.
o Obsolete kern.polling.enable. Polling is turned on/off
with ifconfig.
Detailed kern_poll.c changes:
- Remove polling handler flags, introduced in 1.21. The are not
needed now.
- Forget and do not check if_flags, if_capenable and if_drv_flags.
- Call all registered polling handlers unconditionally.
- Do not drop poll_mtx, when entering polling handlers.
- In ether_poll() NET_LOCK_GIANT prior to locking poll_mtx.
- In netisr_poll() axe the block, where polling code asks drivers
to unregister.
- In netisr_poll() and ether_poll() do polling always, if any
handlers are present.
- In ether_poll_[de]register() remove a lot of error hiding code. Assert
that arguments are correct, instead.
- In ether_poll_[de]register() use standard return values in case of
error or success.
- Introduce poll_switch() that is a sysctl handler for kern.polling.enable.
poll_switch() goes through interface list and enabled/disables polling.
A message that kern.polling.enable is deprecated is printed.
Detailed driver changes:
- On attach driver announces IFCAP_POLLING in if_capabilities, but
not in if_capenable.
- On detach driver calls ether_poll_deregister() if polling is enabled.
- In polling handler driver obtains its lock and checks IFF_DRV_RUNNING
flag. If there is no, then unlocks and returns.
- In ioctl handler driver checks for IFCAP_POLLING flag requested to
be set or cleared. Driver first calls ether_poll_[de]register(), then
obtains driver lock and [dis/en]ables interrupts.
- In interrupt handler driver checks IFCAP_POLLING flag in if_capenable.
If present, then returns.This is important to protect from spurious
interrupts.
Reviewed by: ru, sam, jhb
2005-10-01 18:56:19 +00:00
|
|
|
ifp->if_capenable = ifp->if_capabilities;
|
2012-02-25 04:54:51 +00:00
|
|
|
ifp->if_capenable &= ~(IFCAP_WOL_UCAST | IFCAP_WOL_MCAST);
|
2004-04-11 16:23:16 +00:00
|
|
|
#ifdef DEVICE_POLLING
|
|
|
|
ifp->if_capabilities |= IFCAP_POLLING;
|
|
|
|
#endif
|
2010-05-03 07:32:50 +00:00
|
|
|
IFQ_SET_MAXLEN(&ifp->if_snd, ifqmaxlen);
|
|
|
|
ifp->if_snd.ifq_drv_maxlen = ifqmaxlen;
|
2004-07-02 12:16:02 +00:00
|
|
|
IFQ_SET_READY(&ifp->if_snd);
|
2004-07-05 02:46:42 +00:00
|
|
|
|
1998-10-18 16:24:34 +00:00
|
|
|
/*
|
2000-07-13 22:54:34 +00:00
|
|
|
* Call MI attach routine.
|
1998-10-18 16:24:34 +00:00
|
|
|
*/
|
2002-11-14 23:49:09 +00:00
|
|
|
ether_ifattach(ifp, eaddr);
|
1998-10-18 16:24:34 +00:00
|
|
|
|
2003-04-17 20:32:06 +00:00
|
|
|
/* Hook interrupt last to avoid having to lock softc */
|
2007-07-24 01:24:03 +00:00
|
|
|
error = bus_setup_intr(dev, sc->rl_irq[0], INTR_TYPE_NET | INTR_MPSAFE,
|
|
|
|
NULL, rl_intr, sc, &sc->rl_intrhand[0]);
|
2002-10-29 19:02:19 +00:00
|
|
|
if (error) {
|
2006-09-15 10:40:54 +00:00
|
|
|
device_printf(sc->rl_dev, "couldn't set up irq\n");
|
2003-04-17 20:32:06 +00:00
|
|
|
ether_ifdetach(ifp);
|
2002-10-29 19:02:19 +00:00
|
|
|
}
|
|
|
|
|
1998-10-18 16:24:34 +00:00
|
|
|
fail:
|
2003-03-31 17:29:43 +00:00
|
|
|
if (error)
|
|
|
|
rl_detach(dev);
|
|
|
|
|
2003-02-09 22:32:50 +00:00
|
|
|
return (error);
|
1999-08-31 14:45:51 +00:00
|
|
|
}
|
|
|
|
|
2003-04-17 20:32:06 +00:00
|
|
|
/*
|
|
|
|
* Shutdown hardware and free up resources. This can be called any
|
|
|
|
* time after the mutex has been initialized. It is called in both
|
|
|
|
* the error case in attach and the normal detach case so it needs
|
|
|
|
* to be careful about only freeing resources that have actually been
|
|
|
|
* allocated.
|
|
|
|
*/
|
2002-08-23 23:49:02 +00:00
|
|
|
static int
|
2004-07-05 02:46:42 +00:00
|
|
|
rl_detach(device_t dev)
|
1999-08-31 14:45:51 +00:00
|
|
|
{
|
|
|
|
struct rl_softc *sc;
|
|
|
|
struct ifnet *ifp;
|
|
|
|
|
|
|
|
sc = device_get_softc(dev);
|
2005-06-10 16:49:24 +00:00
|
|
|
ifp = sc->rl_ifp;
|
2004-07-05 02:46:42 +00:00
|
|
|
|
2003-03-31 20:22:00 +00:00
|
|
|
KASSERT(mtx_initialized(&sc->rl_mtx), ("rl mutex not initialized"));
|
2005-09-29 16:52:19 +00:00
|
|
|
|
Big polling(4) cleanup.
o Axe poll in trap.
o Axe IFF_POLLING flag from if_flags.
o Rework revision 1.21 (Giant removal), in such a way that
poll_mtx is not dropped during call to polling handler.
This fixes problem with idle polling.
o Make registration and deregistration from polling in a
functional way, insted of next tick/interrupt.
o Obsolete kern.polling.enable. Polling is turned on/off
with ifconfig.
Detailed kern_poll.c changes:
- Remove polling handler flags, introduced in 1.21. The are not
needed now.
- Forget and do not check if_flags, if_capenable and if_drv_flags.
- Call all registered polling handlers unconditionally.
- Do not drop poll_mtx, when entering polling handlers.
- In ether_poll() NET_LOCK_GIANT prior to locking poll_mtx.
- In netisr_poll() axe the block, where polling code asks drivers
to unregister.
- In netisr_poll() and ether_poll() do polling always, if any
handlers are present.
- In ether_poll_[de]register() remove a lot of error hiding code. Assert
that arguments are correct, instead.
- In ether_poll_[de]register() use standard return values in case of
error or success.
- Introduce poll_switch() that is a sysctl handler for kern.polling.enable.
poll_switch() goes through interface list and enabled/disables polling.
A message that kern.polling.enable is deprecated is printed.
Detailed driver changes:
- On attach driver announces IFCAP_POLLING in if_capabilities, but
not in if_capenable.
- On detach driver calls ether_poll_deregister() if polling is enabled.
- In polling handler driver obtains its lock and checks IFF_DRV_RUNNING
flag. If there is no, then unlocks and returns.
- In ioctl handler driver checks for IFCAP_POLLING flag requested to
be set or cleared. Driver first calls ether_poll_[de]register(), then
obtains driver lock and [dis/en]ables interrupts.
- In interrupt handler driver checks IFCAP_POLLING flag in if_capenable.
If present, then returns.This is important to protect from spurious
interrupts.
Reviewed by: ru, sam, jhb
2005-10-01 18:56:19 +00:00
|
|
|
#ifdef DEVICE_POLLING
|
|
|
|
if (ifp->if_capenable & IFCAP_POLLING)
|
|
|
|
ether_poll_deregister(ifp);
|
|
|
|
#endif
|
2004-08-09 20:22:17 +00:00
|
|
|
/* These should only be active if attach succeeded */
|
2005-09-16 11:11:51 +00:00
|
|
|
if (device_is_attached(dev)) {
|
2005-09-14 12:33:23 +00:00
|
|
|
RL_LOCK(sc);
|
|
|
|
rl_stop(sc);
|
|
|
|
RL_UNLOCK(sc);
|
2005-09-29 16:52:19 +00:00
|
|
|
callout_drain(&sc->rl_stat_callout);
|
2004-08-09 20:22:17 +00:00
|
|
|
ether_ifdetach(ifp);
|
2005-06-10 16:49:24 +00:00
|
|
|
}
|
2004-07-05 02:51:32 +00:00
|
|
|
#if 0
|
|
|
|
sc->suspended = 1;
|
|
|
|
#endif
|
2003-04-17 20:32:06 +00:00
|
|
|
if (sc->rl_miibus)
|
|
|
|
device_delete_child(dev, sc->rl_miibus);
|
|
|
|
bus_generic_detach(dev);
|
1999-08-31 14:45:51 +00:00
|
|
|
|
2007-07-24 01:24:03 +00:00
|
|
|
if (sc->rl_intrhand[0])
|
|
|
|
bus_teardown_intr(dev, sc->rl_irq[0], sc->rl_intrhand[0]);
|
|
|
|
if (sc->rl_irq[0])
|
|
|
|
bus_release_resource(dev, SYS_RES_IRQ, 0, sc->rl_irq[0]);
|
2003-03-31 17:29:43 +00:00
|
|
|
if (sc->rl_res)
|
2010-08-22 21:26:35 +00:00
|
|
|
bus_release_resource(dev, sc->rl_res_type, sc->rl_res_id,
|
|
|
|
sc->rl_res);
|
1999-08-31 14:45:51 +00:00
|
|
|
|
2005-10-13 21:11:20 +00:00
|
|
|
if (ifp)
|
|
|
|
if_free(ifp);
|
|
|
|
|
2008-10-25 02:36:08 +00:00
|
|
|
rl_dma_free(sc);
|
1999-08-31 14:45:51 +00:00
|
|
|
|
2000-10-13 17:54:19 +00:00
|
|
|
mtx_destroy(&sc->rl_mtx);
|
1999-08-31 14:45:51 +00:00
|
|
|
|
2004-07-05 02:46:42 +00:00
|
|
|
return (0);
|
1998-10-18 16:24:34 +00:00
|
|
|
}
|
|
|
|
|
2008-10-25 02:36:08 +00:00
|
|
|
static int
|
|
|
|
rl_dma_alloc(struct rl_softc *sc)
|
|
|
|
{
|
|
|
|
struct rl_dmamap_arg ctx;
|
|
|
|
int error, i;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate the parent bus DMA tag appropriate for PCI.
|
|
|
|
*/
|
|
|
|
error = bus_dma_tag_create(bus_get_dma_tag(sc->rl_dev), /* parent */
|
|
|
|
1, 0, /* alignment, boundary */
|
|
|
|
BUS_SPACE_MAXADDR_32BIT, /* lowaddr */
|
|
|
|
BUS_SPACE_MAXADDR, /* highaddr */
|
|
|
|
NULL, NULL, /* filter, filterarg */
|
|
|
|
BUS_SPACE_MAXSIZE_32BIT, 0, /* maxsize, nsegments */
|
|
|
|
BUS_SPACE_MAXSIZE_32BIT, /* maxsegsize */
|
|
|
|
0, /* flags */
|
|
|
|
NULL, NULL, /* lockfunc, lockarg */
|
|
|
|
&sc->rl_parent_tag);
|
|
|
|
if (error) {
|
|
|
|
device_printf(sc->rl_dev,
|
|
|
|
"failed to create parent DMA tag.\n");
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
/* Create DMA tag for Rx memory block. */
|
|
|
|
error = bus_dma_tag_create(sc->rl_parent_tag, /* parent */
|
|
|
|
RL_RX_8139_BUF_ALIGN, 0, /* alignment, boundary */
|
|
|
|
BUS_SPACE_MAXADDR, /* lowaddr */
|
|
|
|
BUS_SPACE_MAXADDR, /* highaddr */
|
|
|
|
NULL, NULL, /* filter, filterarg */
|
|
|
|
RL_RXBUFLEN + RL_RX_8139_BUF_GUARD_SZ, 1, /* maxsize,nsegments */
|
|
|
|
RL_RXBUFLEN + RL_RX_8139_BUF_GUARD_SZ, /* maxsegsize */
|
|
|
|
0, /* flags */
|
|
|
|
NULL, NULL, /* lockfunc, lockarg */
|
|
|
|
&sc->rl_cdata.rl_rx_tag);
|
|
|
|
if (error) {
|
|
|
|
device_printf(sc->rl_dev,
|
|
|
|
"failed to create Rx memory block DMA tag.\n");
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
/* Create DMA tag for Tx buffer. */
|
|
|
|
error = bus_dma_tag_create(sc->rl_parent_tag, /* parent */
|
|
|
|
RL_TX_8139_BUF_ALIGN, 0, /* alignment, boundary */
|
|
|
|
BUS_SPACE_MAXADDR, /* lowaddr */
|
|
|
|
BUS_SPACE_MAXADDR, /* highaddr */
|
|
|
|
NULL, NULL, /* filter, filterarg */
|
|
|
|
MCLBYTES, 1, /* maxsize, nsegments */
|
|
|
|
MCLBYTES, /* maxsegsize */
|
|
|
|
0, /* flags */
|
|
|
|
NULL, NULL, /* lockfunc, lockarg */
|
|
|
|
&sc->rl_cdata.rl_tx_tag);
|
|
|
|
if (error) {
|
|
|
|
device_printf(sc->rl_dev, "failed to create Tx DMA tag.\n");
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate DMA'able memory and load DMA map for Rx memory block.
|
|
|
|
*/
|
|
|
|
error = bus_dmamem_alloc(sc->rl_cdata.rl_rx_tag,
|
|
|
|
(void **)&sc->rl_cdata.rl_rx_buf, BUS_DMA_WAITOK |
|
|
|
|
BUS_DMA_COHERENT | BUS_DMA_ZERO, &sc->rl_cdata.rl_rx_dmamap);
|
|
|
|
if (error != 0) {
|
|
|
|
device_printf(sc->rl_dev,
|
|
|
|
"failed to allocate Rx DMA memory block.\n");
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
ctx.rl_busaddr = 0;
|
|
|
|
error = bus_dmamap_load(sc->rl_cdata.rl_rx_tag,
|
|
|
|
sc->rl_cdata.rl_rx_dmamap, sc->rl_cdata.rl_rx_buf,
|
|
|
|
RL_RXBUFLEN + RL_RX_8139_BUF_GUARD_SZ, rl_dmamap_cb, &ctx,
|
|
|
|
BUS_DMA_NOWAIT);
|
|
|
|
if (error != 0 || ctx.rl_busaddr == 0) {
|
|
|
|
device_printf(sc->rl_dev,
|
|
|
|
"could not load Rx DMA memory block.\n");
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
sc->rl_cdata.rl_rx_buf_paddr = ctx.rl_busaddr;
|
|
|
|
|
|
|
|
/* Create DMA maps for Tx buffers. */
|
|
|
|
for (i = 0; i < RL_TX_LIST_CNT; i++) {
|
|
|
|
sc->rl_cdata.rl_tx_chain[i] = NULL;
|
|
|
|
sc->rl_cdata.rl_tx_dmamap[i] = NULL;
|
|
|
|
error = bus_dmamap_create(sc->rl_cdata.rl_tx_tag, 0,
|
|
|
|
&sc->rl_cdata.rl_tx_dmamap[i]);
|
|
|
|
if (error != 0) {
|
|
|
|
device_printf(sc->rl_dev,
|
|
|
|
"could not create Tx dmamap.\n");
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Leave a few bytes before the start of the RX ring buffer. */
|
|
|
|
sc->rl_cdata.rl_rx_buf_ptr = sc->rl_cdata.rl_rx_buf;
|
|
|
|
sc->rl_cdata.rl_rx_buf += RL_RX_8139_BUF_RESERVE;
|
|
|
|
|
|
|
|
fail:
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
rl_dma_free(struct rl_softc *sc)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* Rx memory block. */
|
|
|
|
if (sc->rl_cdata.rl_rx_tag != NULL) {
|
|
|
|
if (sc->rl_cdata.rl_rx_dmamap != NULL)
|
|
|
|
bus_dmamap_unload(sc->rl_cdata.rl_rx_tag,
|
|
|
|
sc->rl_cdata.rl_rx_dmamap);
|
|
|
|
if (sc->rl_cdata.rl_rx_dmamap != NULL &&
|
|
|
|
sc->rl_cdata.rl_rx_buf_ptr != NULL)
|
|
|
|
bus_dmamem_free(sc->rl_cdata.rl_rx_tag,
|
|
|
|
sc->rl_cdata.rl_rx_buf_ptr,
|
|
|
|
sc->rl_cdata.rl_rx_dmamap);
|
|
|
|
sc->rl_cdata.rl_rx_buf_ptr = NULL;
|
|
|
|
sc->rl_cdata.rl_rx_buf = NULL;
|
|
|
|
sc->rl_cdata.rl_rx_dmamap = NULL;
|
|
|
|
bus_dma_tag_destroy(sc->rl_cdata.rl_rx_tag);
|
|
|
|
sc->rl_cdata.rl_tx_tag = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Tx buffers. */
|
|
|
|
if (sc->rl_cdata.rl_tx_tag != NULL) {
|
|
|
|
for (i = 0; i < RL_TX_LIST_CNT; i++) {
|
|
|
|
if (sc->rl_cdata.rl_tx_dmamap[i] != NULL) {
|
|
|
|
bus_dmamap_destroy(
|
|
|
|
sc->rl_cdata.rl_tx_tag,
|
|
|
|
sc->rl_cdata.rl_tx_dmamap[i]);
|
|
|
|
sc->rl_cdata.rl_tx_dmamap[i] = NULL;
|
|
|
|
}
|
2009-02-09 16:53:37 +00:00
|
|
|
}
|
2008-10-25 02:36:08 +00:00
|
|
|
bus_dma_tag_destroy(sc->rl_cdata.rl_tx_tag);
|
|
|
|
sc->rl_cdata.rl_tx_tag = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sc->rl_parent_tag != NULL) {
|
|
|
|
bus_dma_tag_destroy(sc->rl_parent_tag);
|
|
|
|
sc->rl_parent_tag = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-10-18 16:24:34 +00:00
|
|
|
/*
|
|
|
|
* Initialize the transmit descriptors.
|
|
|
|
*/
|
2002-08-23 23:49:02 +00:00
|
|
|
static int
|
2004-07-05 02:46:42 +00:00
|
|
|
rl_list_tx_init(struct rl_softc *sc)
|
1998-10-18 16:24:34 +00:00
|
|
|
{
|
|
|
|
struct rl_chain_data *cd;
|
|
|
|
int i;
|
|
|
|
|
2004-07-05 02:51:32 +00:00
|
|
|
RL_LOCK_ASSERT(sc);
|
|
|
|
|
1998-10-18 16:24:34 +00:00
|
|
|
cd = &sc->rl_cdata;
|
|
|
|
for (i = 0; i < RL_TX_LIST_CNT; i++) {
|
1999-04-12 21:37:00 +00:00
|
|
|
cd->rl_tx_chain[i] = NULL;
|
1999-06-19 20:17:38 +00:00
|
|
|
CSR_WRITE_4(sc,
|
2004-07-05 02:46:42 +00:00
|
|
|
RL_TXADDR0 + (i * sizeof(uint32_t)), 0x0000000);
|
1998-10-18 16:24:34 +00:00
|
|
|
}
|
|
|
|
|
1999-04-12 21:37:00 +00:00
|
|
|
sc->rl_cdata.cur_tx = 0;
|
|
|
|
sc->rl_cdata.last_tx = 0;
|
1998-10-18 16:24:34 +00:00
|
|
|
|
2004-07-05 02:46:42 +00:00
|
|
|
return (0);
|
1998-10-18 16:24:34 +00:00
|
|
|
}
|
|
|
|
|
2008-10-25 02:36:08 +00:00
|
|
|
static int
|
|
|
|
rl_list_rx_init(struct rl_softc *sc)
|
|
|
|
{
|
|
|
|
|
|
|
|
RL_LOCK_ASSERT(sc);
|
|
|
|
|
|
|
|
bzero(sc->rl_cdata.rl_rx_buf_ptr,
|
|
|
|
RL_RXBUFLEN + RL_RX_8139_BUF_GUARD_SZ);
|
|
|
|
bus_dmamap_sync(sc->rl_cdata.rl_tx_tag, sc->rl_cdata.rl_rx_dmamap,
|
|
|
|
BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1998-10-18 16:24:34 +00:00
|
|
|
/*
|
|
|
|
* A frame has been uploaded: pass the resulting mbuf chain up to
|
|
|
|
* the higher level protocols.
|
|
|
|
*
|
|
|
|
* You know there's something wrong with a PCI bus-master chip design
|
|
|
|
* when you have to use m_devget().
|
|
|
|
*
|
|
|
|
* The receive operation is badly documented in the datasheet, so I'll
|
|
|
|
* attempt to document it here. The driver provides a buffer area and
|
|
|
|
* places its base address in the RX buffer start address register.
|
|
|
|
* The chip then begins copying frames into the RX buffer. Each frame
|
2001-02-18 10:43:53 +00:00
|
|
|
* is preceded by a 32-bit RX status word which specifies the length
|
1998-10-18 16:24:34 +00:00
|
|
|
* of the frame and certain other status bits. Each frame (starting with
|
|
|
|
* the status word) is also 32-bit aligned. The frame length is in the
|
|
|
|
* first 16 bits of the status word; the lower 15 bits correspond with
|
|
|
|
* the 'rx status register' mentioned in the datasheet.
|
1999-06-19 20:17:38 +00:00
|
|
|
*
|
|
|
|
* Note: to make the Alpha happy, the frame payload needs to be aligned
|
2001-06-20 19:48:35 +00:00
|
|
|
* on a 32-bit boundary. To achieve this, we pass RL_ETHER_ALIGN (2 bytes)
|
2003-01-11 16:11:21 +00:00
|
|
|
* as the offset argument to m_devget().
|
1998-10-18 16:24:34 +00:00
|
|
|
*/
|
2009-05-30 15:14:44 +00:00
|
|
|
static int
|
2004-07-05 02:46:42 +00:00
|
|
|
rl_rxeof(struct rl_softc *sc)
|
1998-10-18 16:24:34 +00:00
|
|
|
{
|
2003-01-11 16:11:21 +00:00
|
|
|
struct mbuf *m;
|
2005-06-10 16:49:24 +00:00
|
|
|
struct ifnet *ifp = sc->rl_ifp;
|
2004-07-05 02:46:42 +00:00
|
|
|
uint8_t *rxbufpos;
|
1998-10-18 16:24:34 +00:00
|
|
|
int total_len = 0;
|
|
|
|
int wrap = 0;
|
2009-05-30 15:14:44 +00:00
|
|
|
int rx_npkts = 0;
|
2004-07-05 02:46:42 +00:00
|
|
|
uint32_t rxstat;
|
|
|
|
uint16_t cur_rx;
|
|
|
|
uint16_t limit;
|
|
|
|
uint16_t max_bytes, rx_bytes = 0;
|
1998-10-18 16:24:34 +00:00
|
|
|
|
2003-11-14 19:00:32 +00:00
|
|
|
RL_LOCK_ASSERT(sc);
|
|
|
|
|
2008-10-25 02:36:08 +00:00
|
|
|
bus_dmamap_sync(sc->rl_cdata.rl_rx_tag, sc->rl_cdata.rl_rx_dmamap,
|
|
|
|
BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE);
|
2001-08-15 17:38:43 +00:00
|
|
|
|
1998-10-18 16:24:34 +00:00
|
|
|
cur_rx = (CSR_READ_2(sc, RL_CURRXADDR) + 16) % RL_RXBUFLEN;
|
|
|
|
|
|
|
|
/* Do not try to read past this point. */
|
|
|
|
limit = CSR_READ_2(sc, RL_CURRXBUF) % RL_RXBUFLEN;
|
|
|
|
|
|
|
|
if (limit < cur_rx)
|
|
|
|
max_bytes = (RL_RXBUFLEN - cur_rx) + limit;
|
|
|
|
else
|
|
|
|
max_bytes = limit - cur_rx;
|
|
|
|
|
1999-01-16 21:03:57 +00:00
|
|
|
while((CSR_READ_1(sc, RL_COMMAND) & RL_CMD_EMPTY_RXBUF) == 0) {
|
2002-04-16 22:03:14 +00:00
|
|
|
#ifdef DEVICE_POLLING
|
Big polling(4) cleanup.
o Axe poll in trap.
o Axe IFF_POLLING flag from if_flags.
o Rework revision 1.21 (Giant removal), in such a way that
poll_mtx is not dropped during call to polling handler.
This fixes problem with idle polling.
o Make registration and deregistration from polling in a
functional way, insted of next tick/interrupt.
o Obsolete kern.polling.enable. Polling is turned on/off
with ifconfig.
Detailed kern_poll.c changes:
- Remove polling handler flags, introduced in 1.21. The are not
needed now.
- Forget and do not check if_flags, if_capenable and if_drv_flags.
- Call all registered polling handlers unconditionally.
- Do not drop poll_mtx, when entering polling handlers.
- In ether_poll() NET_LOCK_GIANT prior to locking poll_mtx.
- In netisr_poll() axe the block, where polling code asks drivers
to unregister.
- In netisr_poll() and ether_poll() do polling always, if any
handlers are present.
- In ether_poll_[de]register() remove a lot of error hiding code. Assert
that arguments are correct, instead.
- In ether_poll_[de]register() use standard return values in case of
error or success.
- Introduce poll_switch() that is a sysctl handler for kern.polling.enable.
poll_switch() goes through interface list and enabled/disables polling.
A message that kern.polling.enable is deprecated is printed.
Detailed driver changes:
- On attach driver announces IFCAP_POLLING in if_capabilities, but
not in if_capenable.
- On detach driver calls ether_poll_deregister() if polling is enabled.
- In polling handler driver obtains its lock and checks IFF_DRV_RUNNING
flag. If there is no, then unlocks and returns.
- In ioctl handler driver checks for IFCAP_POLLING flag requested to
be set or cleared. Driver first calls ether_poll_[de]register(), then
obtains driver lock and [dis/en]ables interrupts.
- In interrupt handler driver checks IFCAP_POLLING flag in if_capenable.
If present, then returns.This is important to protect from spurious
interrupts.
Reviewed by: ru, sam, jhb
2005-10-01 18:56:19 +00:00
|
|
|
if (ifp->if_capenable & IFCAP_POLLING) {
|
2002-04-16 22:03:14 +00:00
|
|
|
if (sc->rxcycles <= 0)
|
|
|
|
break;
|
|
|
|
sc->rxcycles--;
|
|
|
|
}
|
Big polling(4) cleanup.
o Axe poll in trap.
o Axe IFF_POLLING flag from if_flags.
o Rework revision 1.21 (Giant removal), in such a way that
poll_mtx is not dropped during call to polling handler.
This fixes problem with idle polling.
o Make registration and deregistration from polling in a
functional way, insted of next tick/interrupt.
o Obsolete kern.polling.enable. Polling is turned on/off
with ifconfig.
Detailed kern_poll.c changes:
- Remove polling handler flags, introduced in 1.21. The are not
needed now.
- Forget and do not check if_flags, if_capenable and if_drv_flags.
- Call all registered polling handlers unconditionally.
- Do not drop poll_mtx, when entering polling handlers.
- In ether_poll() NET_LOCK_GIANT prior to locking poll_mtx.
- In netisr_poll() axe the block, where polling code asks drivers
to unregister.
- In netisr_poll() and ether_poll() do polling always, if any
handlers are present.
- In ether_poll_[de]register() remove a lot of error hiding code. Assert
that arguments are correct, instead.
- In ether_poll_[de]register() use standard return values in case of
error or success.
- Introduce poll_switch() that is a sysctl handler for kern.polling.enable.
poll_switch() goes through interface list and enabled/disables polling.
A message that kern.polling.enable is deprecated is printed.
Detailed driver changes:
- On attach driver announces IFCAP_POLLING in if_capabilities, but
not in if_capenable.
- On detach driver calls ether_poll_deregister() if polling is enabled.
- In polling handler driver obtains its lock and checks IFF_DRV_RUNNING
flag. If there is no, then unlocks and returns.
- In ioctl handler driver checks for IFCAP_POLLING flag requested to
be set or cleared. Driver first calls ether_poll_[de]register(), then
obtains driver lock and [dis/en]ables interrupts.
- In interrupt handler driver checks IFCAP_POLLING flag in if_capenable.
If present, then returns.This is important to protect from spurious
interrupts.
Reviewed by: ru, sam, jhb
2005-10-01 18:56:19 +00:00
|
|
|
#endif
|
1998-10-18 16:24:34 +00:00
|
|
|
rxbufpos = sc->rl_cdata.rl_rx_buf + cur_rx;
|
2004-07-05 02:46:42 +00:00
|
|
|
rxstat = le32toh(*(uint32_t *)rxbufpos);
|
1998-10-18 16:24:34 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Here's a totally undocumented fact for you. When the
|
|
|
|
* RealTek chip is in the process of copying a packet into
|
|
|
|
* RAM for you, the length will be 0xfff0. If you spot a
|
|
|
|
* packet header with this value, you need to stop. The
|
|
|
|
* datasheet makes absolutely no mention of this and
|
|
|
|
* RealTek should be shot for this.
|
|
|
|
*/
|
2008-04-10 01:06:05 +00:00
|
|
|
total_len = rxstat >> 16;
|
|
|
|
if (total_len == RL_RXSTAT_UNFINISHED)
|
1998-10-18 16:24:34 +00:00
|
|
|
break;
|
2003-01-11 16:11:21 +00:00
|
|
|
|
2008-04-10 01:06:05 +00:00
|
|
|
if (!(rxstat & RL_RXSTAT_RXOK) ||
|
|
|
|
total_len < ETHER_MIN_LEN ||
|
|
|
|
total_len > ETHER_MAX_LEN + ETHER_VLAN_ENCAP_LEN) {
|
1998-10-18 16:24:34 +00:00
|
|
|
ifp->if_ierrors++;
|
2010-08-24 18:52:24 +00:00
|
|
|
ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
|
2004-07-09 00:07:06 +00:00
|
|
|
rl_init_locked(sc);
|
2009-05-30 15:14:44 +00:00
|
|
|
return (rx_npkts);
|
1998-10-18 16:24:34 +00:00
|
|
|
}
|
|
|
|
|
2003-01-11 16:11:21 +00:00
|
|
|
/* No errors; receive the packet. */
|
1998-10-18 16:24:34 +00:00
|
|
|
rx_bytes += total_len + 4;
|
|
|
|
|
1998-12-24 18:39:48 +00:00
|
|
|
/*
|
|
|
|
* XXX The RealTek chip includes the CRC with every
|
|
|
|
* received frame, and there's no way to turn this
|
|
|
|
* behavior off (at least, I can't find anything in
|
2003-01-11 16:11:21 +00:00
|
|
|
* the manual that explains how to do it) so we have
|
1998-12-24 18:39:48 +00:00
|
|
|
* to trim off the CRC manually.
|
|
|
|
*/
|
|
|
|
total_len -= ETHER_CRC_LEN;
|
|
|
|
|
1998-10-18 16:24:34 +00:00
|
|
|
/*
|
|
|
|
* Avoid trying to read more bytes than we know
|
|
|
|
* the chip has prepared for us.
|
|
|
|
*/
|
|
|
|
if (rx_bytes > max_bytes)
|
|
|
|
break;
|
|
|
|
|
|
|
|
rxbufpos = sc->rl_cdata.rl_rx_buf +
|
2004-07-05 02:46:42 +00:00
|
|
|
((cur_rx + sizeof(uint32_t)) % RL_RXBUFLEN);
|
1998-10-18 16:24:34 +00:00
|
|
|
if (rxbufpos == (sc->rl_cdata.rl_rx_buf + RL_RXBUFLEN))
|
|
|
|
rxbufpos = sc->rl_cdata.rl_rx_buf;
|
|
|
|
|
|
|
|
wrap = (sc->rl_cdata.rl_rx_buf + RL_RXBUFLEN) - rxbufpos;
|
|
|
|
if (total_len > wrap) {
|
2001-06-20 19:48:35 +00:00
|
|
|
m = m_devget(rxbufpos, total_len, RL_ETHER_ALIGN, ifp,
|
|
|
|
NULL);
|
2008-12-03 03:20:18 +00:00
|
|
|
if (m != NULL)
|
1998-10-18 16:24:34 +00:00
|
|
|
m_copyback(m, wrap, total_len - wrap,
|
|
|
|
sc->rl_cdata.rl_rx_buf);
|
1998-12-24 18:39:48 +00:00
|
|
|
cur_rx = (total_len - wrap + ETHER_CRC_LEN);
|
1998-10-18 16:24:34 +00:00
|
|
|
} else {
|
2001-06-20 19:48:35 +00:00
|
|
|
m = m_devget(rxbufpos, total_len, RL_ETHER_ALIGN, ifp,
|
|
|
|
NULL);
|
1998-12-24 18:39:48 +00:00
|
|
|
cur_rx += total_len + 4 + ETHER_CRC_LEN;
|
1998-10-18 16:24:34 +00:00
|
|
|
}
|
|
|
|
|
2004-07-05 02:46:42 +00:00
|
|
|
/* Round up to 32-bit boundary. */
|
1998-10-18 16:24:34 +00:00
|
|
|
cur_rx = (cur_rx + 3) & ~3;
|
|
|
|
CSR_WRITE_2(sc, RL_CURRXADDR, cur_rx - 16);
|
|
|
|
|
2008-12-03 03:20:18 +00:00
|
|
|
if (m == NULL) {
|
|
|
|
ifp->if_iqdrops++;
|
1998-10-18 16:24:34 +00:00
|
|
|
continue;
|
2008-12-03 03:20:18 +00:00
|
|
|
}
|
1998-10-18 16:24:34 +00:00
|
|
|
|
|
|
|
ifp->if_ipackets++;
|
2003-11-14 19:00:32 +00:00
|
|
|
RL_UNLOCK(sc);
|
2002-11-14 23:49:09 +00:00
|
|
|
(*ifp->if_input)(ifp, m);
|
2003-11-14 19:00:32 +00:00
|
|
|
RL_LOCK(sc);
|
2009-05-30 15:14:44 +00:00
|
|
|
rx_npkts++;
|
1998-10-18 16:24:34 +00:00
|
|
|
}
|
2008-10-25 02:36:08 +00:00
|
|
|
|
2008-11-01 17:02:01 +00:00
|
|
|
/* No need to sync Rx memory block as we didn't modify it. */
|
2009-05-30 15:14:44 +00:00
|
|
|
return (rx_npkts);
|
1998-10-18 16:24:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* A frame was downloaded to the chip. It's safe for us to clean up
|
|
|
|
* the list buffers.
|
|
|
|
*/
|
2002-08-23 23:49:02 +00:00
|
|
|
static void
|
2004-07-05 02:46:42 +00:00
|
|
|
rl_txeof(struct rl_softc *sc)
|
1998-10-18 16:24:34 +00:00
|
|
|
{
|
2005-06-10 16:49:24 +00:00
|
|
|
struct ifnet *ifp = sc->rl_ifp;
|
2004-07-05 02:46:42 +00:00
|
|
|
uint32_t txstat;
|
1998-10-18 16:24:34 +00:00
|
|
|
|
2004-07-05 02:51:32 +00:00
|
|
|
RL_LOCK_ASSERT(sc);
|
|
|
|
|
1998-10-18 16:24:34 +00:00
|
|
|
/*
|
|
|
|
* Go through our tx list and free mbufs for those
|
|
|
|
* frames that have been uploaded.
|
|
|
|
*/
|
1999-04-12 21:37:00 +00:00
|
|
|
do {
|
Fixed a few bugs in the rl(4) driver:
Under polling(4), we counted non-existent output packets and wasted
CPU cycles, corrected. (PR kern/64975.)
The fix in revision 1.71 to correct resetting of the watchdog timer
was wrong.
In rl(4), the TX list does not have a gap between the consumer and
producer, so the "empty TX list" test was wrong, corrected.
Also, resetting the timer to five each time we know there is still
some TX work to do was a bad idea -- under polling(4), if the chip
goes out to lunch, this results in the watchdog routine to _never_
be called. Instead, let the timer downgrade to zero and fire the
watchdog, then reset it to five when it is zero AND there is some
TX work left. (Most other network drivers need this fix too.)
MFC after: 3 days
2004-04-03 00:42:33 +00:00
|
|
|
if (RL_LAST_TXMBUF(sc) == NULL)
|
|
|
|
break;
|
1999-04-12 21:37:00 +00:00
|
|
|
txstat = CSR_READ_4(sc, RL_LAST_TXSTAT(sc));
|
|
|
|
if (!(txstat & (RL_TXSTAT_TX_OK|
|
|
|
|
RL_TXSTAT_TX_UNDERRUN|RL_TXSTAT_TXABRT)))
|
1998-10-18 16:24:34 +00:00
|
|
|
break;
|
|
|
|
|
1999-04-12 21:37:00 +00:00
|
|
|
ifp->if_collisions += (txstat & RL_TXSTAT_COLLCNT) >> 24;
|
1998-10-18 16:24:34 +00:00
|
|
|
|
2008-10-25 02:36:08 +00:00
|
|
|
bus_dmamap_sync(sc->rl_cdata.rl_tx_tag, RL_LAST_DMAMAP(sc),
|
|
|
|
BUS_DMASYNC_POSTWRITE);
|
|
|
|
bus_dmamap_unload(sc->rl_cdata.rl_tx_tag, RL_LAST_DMAMAP(sc));
|
Fixed a few bugs in the rl(4) driver:
Under polling(4), we counted non-existent output packets and wasted
CPU cycles, corrected. (PR kern/64975.)
The fix in revision 1.71 to correct resetting of the watchdog timer
was wrong.
In rl(4), the TX list does not have a gap between the consumer and
producer, so the "empty TX list" test was wrong, corrected.
Also, resetting the timer to five each time we know there is still
some TX work to do was a bad idea -- under polling(4), if the chip
goes out to lunch, this results in the watchdog routine to _never_
be called. Instead, let the timer downgrade to zero and fire the
watchdog, then reset it to five when it is zero AND there is some
TX work left. (Most other network drivers need this fix too.)
MFC after: 3 days
2004-04-03 00:42:33 +00:00
|
|
|
m_freem(RL_LAST_TXMBUF(sc));
|
|
|
|
RL_LAST_TXMBUF(sc) = NULL;
|
2005-02-11 01:05:52 +00:00
|
|
|
/*
|
|
|
|
* If there was a transmit underrun, bump the TX threshold.
|
|
|
|
* Make sure not to overflow the 63 * 32byte we can address
|
|
|
|
* with the 6 available bit.
|
|
|
|
*/
|
|
|
|
if ((txstat & RL_TXSTAT_TX_UNDERRUN) &&
|
|
|
|
(sc->rl_txthresh < 2016))
|
|
|
|
sc->rl_txthresh += 32;
|
1999-04-12 21:37:00 +00:00
|
|
|
if (txstat & RL_TXSTAT_TX_OK)
|
|
|
|
ifp->if_opackets++;
|
|
|
|
else {
|
1999-10-21 19:42:03 +00:00
|
|
|
int oldthresh;
|
1999-04-12 21:37:00 +00:00
|
|
|
ifp->if_oerrors++;
|
|
|
|
if ((txstat & RL_TXSTAT_TXABRT) ||
|
|
|
|
(txstat & RL_TXSTAT_OUTOFWIN))
|
|
|
|
CSR_WRITE_4(sc, RL_TXCFG, RL_TXCFG_CONFIG);
|
1999-10-21 19:42:03 +00:00
|
|
|
oldthresh = sc->rl_txthresh;
|
|
|
|
/* error recovery */
|
2010-08-24 18:52:24 +00:00
|
|
|
ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
|
2004-07-09 00:07:06 +00:00
|
|
|
rl_init_locked(sc);
|
2005-02-11 01:05:52 +00:00
|
|
|
/* restore original threshold */
|
|
|
|
sc->rl_txthresh = oldthresh;
|
1999-10-21 19:42:03 +00:00
|
|
|
return;
|
1999-04-12 21:37:00 +00:00
|
|
|
}
|
|
|
|
RL_INC(sc->rl_cdata.last_tx);
|
2005-08-09 10:20:02 +00:00
|
|
|
ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
|
1999-04-12 21:37:00 +00:00
|
|
|
} while (sc->rl_cdata.last_tx != sc->rl_cdata.cur_tx);
|
|
|
|
|
Fixed a few bugs in the rl(4) driver:
Under polling(4), we counted non-existent output packets and wasted
CPU cycles, corrected. (PR kern/64975.)
The fix in revision 1.71 to correct resetting of the watchdog timer
was wrong.
In rl(4), the TX list does not have a gap between the consumer and
producer, so the "empty TX list" test was wrong, corrected.
Also, resetting the timer to five each time we know there is still
some TX work to do was a bad idea -- under polling(4), if the chip
goes out to lunch, this results in the watchdog routine to _never_
be called. Instead, let the timer downgrade to zero and fire the
watchdog, then reset it to five when it is zero AND there is some
TX work left. (Most other network drivers need this fix too.)
MFC after: 3 days
2004-04-03 00:42:33 +00:00
|
|
|
if (RL_LAST_TXMBUF(sc) == NULL)
|
2006-12-01 21:52:07 +00:00
|
|
|
sc->rl_watchdog_timer = 0;
|
1999-08-31 14:45:51 +00:00
|
|
|
}
|
|
|
|
|
2008-10-31 23:24:13 +00:00
|
|
|
static void
|
|
|
|
rl_twister_update(struct rl_softc *sc)
|
|
|
|
{
|
|
|
|
uint16_t linktest;
|
|
|
|
/*
|
|
|
|
* Table provided by RealTek (Kinston <shangh@realtek.com.tw>) for
|
|
|
|
* Linux driver. Values undocumented otherwise.
|
|
|
|
*/
|
|
|
|
static const uint32_t param[4][4] = {
|
|
|
|
{0xcb39de43, 0xcb39ce43, 0xfb38de03, 0xcb38de43},
|
|
|
|
{0xcb39de43, 0xcb39ce43, 0xcb39ce83, 0xcb39ce83},
|
|
|
|
{0xcb39de43, 0xcb39ce43, 0xcb39ce83, 0xcb39ce83},
|
|
|
|
{0xbb39de43, 0xbb39ce43, 0xbb39ce83, 0xbb39ce83}
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Tune the so-called twister registers of the RTL8139. These
|
2008-11-01 17:02:01 +00:00
|
|
|
* are used to compensate for impedance mismatches. The
|
|
|
|
* method for tuning these registers is undocumented and the
|
|
|
|
* following procedure is collected from public sources.
|
2008-10-31 23:24:13 +00:00
|
|
|
*/
|
|
|
|
switch (sc->rl_twister)
|
|
|
|
{
|
|
|
|
case CHK_LINK:
|
|
|
|
/*
|
2008-11-01 17:02:01 +00:00
|
|
|
* If we have a sufficient link, then we can proceed in
|
2008-10-31 23:24:13 +00:00
|
|
|
* the state machine to the next stage. If not, then
|
|
|
|
* disable further tuning after writing sane defaults.
|
|
|
|
*/
|
|
|
|
if (CSR_READ_2(sc, RL_CSCFG) & RL_CSCFG_LINK_OK) {
|
|
|
|
CSR_WRITE_2(sc, RL_CSCFG, RL_CSCFG_LINK_DOWN_OFF_CMD);
|
|
|
|
sc->rl_twister = FIND_ROW;
|
|
|
|
} else {
|
|
|
|
CSR_WRITE_2(sc, RL_CSCFG, RL_CSCFG_LINK_DOWN_CMD);
|
|
|
|
CSR_WRITE_4(sc, RL_NWAYTST, RL_NWAYTST_CBL_TEST);
|
|
|
|
CSR_WRITE_4(sc, RL_PARA78, RL_PARA78_DEF);
|
|
|
|
CSR_WRITE_4(sc, RL_PARA7C, RL_PARA7C_DEF);
|
|
|
|
sc->rl_twister = DONE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case FIND_ROW:
|
|
|
|
/*
|
|
|
|
* Read how long it took to see the echo to find the tuning
|
|
|
|
* row to use.
|
|
|
|
*/
|
|
|
|
linktest = CSR_READ_2(sc, RL_CSCFG) & RL_CSCFG_STATUS;
|
|
|
|
if (linktest == RL_CSCFG_ROW3)
|
|
|
|
sc->rl_twist_row = 3;
|
|
|
|
else if (linktest == RL_CSCFG_ROW2)
|
|
|
|
sc->rl_twist_row = 2;
|
|
|
|
else if (linktest == RL_CSCFG_ROW1)
|
|
|
|
sc->rl_twist_row = 1;
|
|
|
|
else
|
|
|
|
sc->rl_twist_row = 0;
|
|
|
|
sc->rl_twist_col = 0;
|
|
|
|
sc->rl_twister = SET_PARAM;
|
|
|
|
break;
|
|
|
|
case SET_PARAM:
|
|
|
|
if (sc->rl_twist_col == 0)
|
|
|
|
CSR_WRITE_4(sc, RL_NWAYTST, RL_NWAYTST_RESET);
|
|
|
|
CSR_WRITE_4(sc, RL_PARA7C,
|
|
|
|
param[sc->rl_twist_row][sc->rl_twist_col]);
|
|
|
|
if (++sc->rl_twist_col == 4) {
|
|
|
|
if (sc->rl_twist_row == 3)
|
|
|
|
sc->rl_twister = RECHK_LONG;
|
|
|
|
else
|
|
|
|
sc->rl_twister = DONE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case RECHK_LONG:
|
|
|
|
/*
|
|
|
|
* For long cables, we have to double check to make sure we
|
|
|
|
* don't mistune.
|
|
|
|
*/
|
|
|
|
linktest = CSR_READ_2(sc, RL_CSCFG) & RL_CSCFG_STATUS;
|
|
|
|
if (linktest == RL_CSCFG_ROW3)
|
|
|
|
sc->rl_twister = DONE;
|
|
|
|
else {
|
|
|
|
CSR_WRITE_4(sc, RL_PARA7C, RL_PARA7C_RETUNE);
|
|
|
|
sc->rl_twister = RETUNE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case RETUNE:
|
|
|
|
/* Retune for a shorter cable (try column 2) */
|
|
|
|
CSR_WRITE_4(sc, RL_NWAYTST, RL_NWAYTST_CBL_TEST);
|
|
|
|
CSR_WRITE_4(sc, RL_PARA78, RL_PARA78_DEF);
|
|
|
|
CSR_WRITE_4(sc, RL_PARA7C, RL_PARA7C_DEF);
|
|
|
|
CSR_WRITE_4(sc, RL_NWAYTST, RL_NWAYTST_RESET);
|
|
|
|
sc->rl_twist_row--;
|
|
|
|
sc->rl_twist_col = 0;
|
|
|
|
sc->rl_twister = SET_PARAM;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DONE:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2002-08-23 23:49:02 +00:00
|
|
|
static void
|
2004-07-05 02:46:42 +00:00
|
|
|
rl_tick(void *xsc)
|
1999-08-31 14:45:51 +00:00
|
|
|
{
|
2004-07-05 02:46:42 +00:00
|
|
|
struct rl_softc *sc = xsc;
|
1999-08-31 14:45:51 +00:00
|
|
|
struct mii_data *mii;
|
2008-10-31 23:24:13 +00:00
|
|
|
int ticks;
|
1999-08-31 14:45:51 +00:00
|
|
|
|
2005-09-29 16:52:19 +00:00
|
|
|
RL_LOCK_ASSERT(sc);
|
2008-10-31 23:24:13 +00:00
|
|
|
/*
|
|
|
|
* If we're doing the twister cable calibration, then we need to defer
|
|
|
|
* watchdog timeouts. This is a no-op in normal operations, but
|
|
|
|
* can falsely trigger when the cable calibration takes a while and
|
|
|
|
* there was traffic ready to go when rl was started.
|
|
|
|
*
|
|
|
|
* We don't defer mii_tick since that updates the mii status, which
|
|
|
|
* helps the twister process, at least according to similar patches
|
|
|
|
* for the Linux driver I found online while doing the fixes. Worst
|
|
|
|
* case is a few extra mii reads during calibration.
|
|
|
|
*/
|
1999-08-31 14:45:51 +00:00
|
|
|
mii = device_get_softc(sc->rl_miibus);
|
|
|
|
mii_tick(mii);
|
2008-12-22 00:53:47 +00:00
|
|
|
if ((sc->rl_flags & RL_FLAG_LINK) == 0)
|
|
|
|
rl_miibus_statchg(sc->rl_dev);
|
2008-11-02 16:50:57 +00:00
|
|
|
if (sc->rl_twister_enable) {
|
|
|
|
if (sc->rl_twister == DONE)
|
|
|
|
rl_watchdog(sc);
|
|
|
|
else
|
|
|
|
rl_twister_update(sc);
|
|
|
|
if (sc->rl_twister == DONE)
|
|
|
|
ticks = hz;
|
|
|
|
else
|
|
|
|
ticks = hz / 10;
|
|
|
|
} else {
|
2008-10-31 23:24:13 +00:00
|
|
|
rl_watchdog(sc);
|
|
|
|
ticks = hz;
|
2008-11-02 16:50:57 +00:00
|
|
|
}
|
2006-12-01 21:52:07 +00:00
|
|
|
|
2008-10-31 23:24:13 +00:00
|
|
|
callout_reset(&sc->rl_stat_callout, ticks, rl_tick, sc);
|
1998-10-18 16:24:34 +00:00
|
|
|
}
|
|
|
|
|
2002-04-16 22:03:14 +00:00
|
|
|
#ifdef DEVICE_POLLING
|
2009-05-30 15:14:44 +00:00
|
|
|
static int
|
2004-07-09 00:07:06 +00:00
|
|
|
rl_poll(struct ifnet *ifp, enum poll_cmd cmd, int count)
|
2002-04-16 22:03:14 +00:00
|
|
|
{
|
|
|
|
struct rl_softc *sc = ifp->if_softc;
|
2009-05-30 15:14:44 +00:00
|
|
|
int rx_npkts = 0;
|
2002-04-16 22:03:14 +00:00
|
|
|
|
|
|
|
RL_LOCK(sc);
|
Big polling(4) cleanup.
o Axe poll in trap.
o Axe IFF_POLLING flag from if_flags.
o Rework revision 1.21 (Giant removal), in such a way that
poll_mtx is not dropped during call to polling handler.
This fixes problem with idle polling.
o Make registration and deregistration from polling in a
functional way, insted of next tick/interrupt.
o Obsolete kern.polling.enable. Polling is turned on/off
with ifconfig.
Detailed kern_poll.c changes:
- Remove polling handler flags, introduced in 1.21. The are not
needed now.
- Forget and do not check if_flags, if_capenable and if_drv_flags.
- Call all registered polling handlers unconditionally.
- Do not drop poll_mtx, when entering polling handlers.
- In ether_poll() NET_LOCK_GIANT prior to locking poll_mtx.
- In netisr_poll() axe the block, where polling code asks drivers
to unregister.
- In netisr_poll() and ether_poll() do polling always, if any
handlers are present.
- In ether_poll_[de]register() remove a lot of error hiding code. Assert
that arguments are correct, instead.
- In ether_poll_[de]register() use standard return values in case of
error or success.
- Introduce poll_switch() that is a sysctl handler for kern.polling.enable.
poll_switch() goes through interface list and enabled/disables polling.
A message that kern.polling.enable is deprecated is printed.
Detailed driver changes:
- On attach driver announces IFCAP_POLLING in if_capabilities, but
not in if_capenable.
- On detach driver calls ether_poll_deregister() if polling is enabled.
- In polling handler driver obtains its lock and checks IFF_DRV_RUNNING
flag. If there is no, then unlocks and returns.
- In ioctl handler driver checks for IFCAP_POLLING flag requested to
be set or cleared. Driver first calls ether_poll_[de]register(), then
obtains driver lock and [dis/en]ables interrupts.
- In interrupt handler driver checks IFCAP_POLLING flag in if_capenable.
If present, then returns.This is important to protect from spurious
interrupts.
Reviewed by: ru, sam, jhb
2005-10-01 18:56:19 +00:00
|
|
|
if (ifp->if_drv_flags & IFF_DRV_RUNNING)
|
2009-05-30 15:14:44 +00:00
|
|
|
rx_npkts = rl_poll_locked(ifp, cmd, count);
|
2004-07-09 00:07:06 +00:00
|
|
|
RL_UNLOCK(sc);
|
2009-05-30 15:14:44 +00:00
|
|
|
return (rx_npkts);
|
2004-07-09 00:07:06 +00:00
|
|
|
}
|
|
|
|
|
2009-05-30 15:14:44 +00:00
|
|
|
static int
|
2004-07-09 00:07:06 +00:00
|
|
|
rl_poll_locked(struct ifnet *ifp, enum poll_cmd cmd, int count)
|
|
|
|
{
|
|
|
|
struct rl_softc *sc = ifp->if_softc;
|
2009-05-30 15:14:44 +00:00
|
|
|
int rx_npkts;
|
2004-07-09 00:07:06 +00:00
|
|
|
|
|
|
|
RL_LOCK_ASSERT(sc);
|
2004-07-05 02:46:42 +00:00
|
|
|
|
2002-04-16 22:03:14 +00:00
|
|
|
sc->rxcycles = count;
|
2009-05-30 15:14:44 +00:00
|
|
|
rx_npkts = rl_rxeof(sc);
|
Take the support for the 8139C+/8169/8169S/8110S chips out of the
rl(4) driver and put it in a new re(4) driver. The re(4) driver shares
the if_rlreg.h file with rl(4) but is a separate module. (Ultimately
I may change this. For now, it's convenient.)
rl(4) has been modified so that it will never attach to an 8139C+
chip, leaving it to re(4) instead. Only re(4) has the PCI IDs to
match the 8169/8169S/8110S gigE chips. if_re.c contains the same
basic code that was originally bolted onto if_rl.c, with the
following updates:
- Added support for jumbo frames. Currently, there seems to be
a limit of approximately 6200 bytes for jumbo frames on transmit.
(This was determined via experimentation.) The 8169S/8110S chips
apparently are limited to 7.5K frames on transmit. This may require
some more work, though the framework to handle jumbo frames on RX
is in place: the re_rxeof() routine will gather up frames than span
multiple 2K clusters into a single mbuf list.
- Fixed bug in re_txeof(): if we reap some of the TX buffers,
but there are still some pending, re-arm the timer before exiting
re_txeof() so that another timeout interrupt will be generated, just
in case re_start() doesn't do it for us.
- Handle the 'link state changed' interrupt
- Fix a detach bug. If re(4) is loaded as a module, and you do
tcpdump -i re0, then you do 'kldunload if_re,' the system will
panic after a few seconds. This happens because ether_ifdetach()
ends up calling the BPF detach code, which notices the interface
is in promiscuous mode and tries to switch promisc mode off while
detaching the BPF listner. This ultimately results in a call
to re_ioctl() (due to SIOCSIFFLAGS), which in turn calls re_init()
to handle the IFF_PROMISC flag change. Unfortunately, calling re_init()
here turns the chip back on and restarts the 1-second timeout loop
that drives re_tick(). By the time the timeout fires, if_re.ko
has been unloaded, which results in a call to invalid code and
blows up the system.
To fix this, I cleared the IFF_UP flag before calling ether_ifdetach(),
which stops the ioctl routine from trying to reset the chip.
- Modified comments in re_rxeof() relating to the difference in
RX descriptor status bit layout between the 8139C+ and the gigE
chips. The layout is different because the frame length field
was expanded from 12 bits to 13, and they got rid of one of the
status bits to make room.
- Add diagnostic code (re_diag()) to test for the case where a user
has installed a broken 32-bit 8169 PCI NIC in a 64-bit slot. Some
NICs have the REQ64# and ACK64# lines connected even though the
board is 32-bit only (in this case, they should be pulled high).
This fools the chip into doing 64-bit DMA transfers even though
there is no 64-bit data path. To detect this, re_diag() puts the
chip into digital loopback mode and sets the receiver to promiscuous
mode, then initiates a single 64-byte packet transmission. The
frame is echoed back to the host, and if the frame contents are
intact, we know DMA is working correctly, otherwise we complain
loudly on the console and abort the device attach. (At the moment,
I don't know of any way to work around the problem other than
physically modifying the board, so until/unless I can think of a
software workaround, this will have do to.)
- Created re(4) man page
- Modified rlphy.c to allow re(4) to attach as well as rl(4).
Note that this code works for the sample 8169/Marvell 88E1000 NIC
that I have, but probably won't work for the 8169S/8110S chips.
RealTek has sent me some sample NICs, but they haven't arrived yet.
I will probably need to add an rlgphy driver to handle the on-board
PHY in the 8169S/8110S (it needs special DSP initialization).
2003-09-08 02:11:25 +00:00
|
|
|
rl_txeof(sc);
|
2004-07-05 02:46:42 +00:00
|
|
|
|
2004-07-09 00:07:06 +00:00
|
|
|
if (!IFQ_DRV_IS_EMPTY(&ifp->if_snd))
|
|
|
|
rl_start_locked(ifp);
|
2002-04-16 22:03:14 +00:00
|
|
|
|
2004-07-05 02:46:42 +00:00
|
|
|
if (cmd == POLL_AND_CHECK_STATUS) {
|
|
|
|
uint16_t status;
|
2002-04-16 22:03:14 +00:00
|
|
|
|
2004-07-05 02:46:42 +00:00
|
|
|
/* We should also check the status register. */
|
2002-04-16 22:03:14 +00:00
|
|
|
status = CSR_READ_2(sc, RL_ISR);
|
2002-07-30 17:31:42 +00:00
|
|
|
if (status == 0xffff)
|
2009-05-30 15:14:44 +00:00
|
|
|
return (rx_npkts);
|
2004-07-05 02:46:42 +00:00
|
|
|
if (status != 0)
|
2002-04-16 22:03:14 +00:00
|
|
|
CSR_WRITE_2(sc, RL_ISR, status);
|
|
|
|
|
2004-07-05 02:46:42 +00:00
|
|
|
/* XXX We should check behaviour on receiver stalls. */
|
2002-04-16 22:03:14 +00:00
|
|
|
|
2010-08-24 18:52:24 +00:00
|
|
|
if (status & RL_ISR_SYSTEM_ERR) {
|
|
|
|
ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
|
2004-07-09 00:07:06 +00:00
|
|
|
rl_init_locked(sc);
|
2010-08-24 18:52:24 +00:00
|
|
|
}
|
2002-04-16 22:03:14 +00:00
|
|
|
}
|
2009-05-30 15:14:44 +00:00
|
|
|
return (rx_npkts);
|
2002-04-16 22:03:14 +00:00
|
|
|
}
|
|
|
|
#endif /* DEVICE_POLLING */
|
|
|
|
|
2002-08-23 23:49:02 +00:00
|
|
|
static void
|
2004-07-05 02:46:42 +00:00
|
|
|
rl_intr(void *arg)
|
1998-10-18 16:24:34 +00:00
|
|
|
{
|
2004-07-05 02:46:42 +00:00
|
|
|
struct rl_softc *sc = arg;
|
2005-06-10 16:49:24 +00:00
|
|
|
struct ifnet *ifp = sc->rl_ifp;
|
2004-07-05 02:46:42 +00:00
|
|
|
uint16_t status;
|
2010-10-13 17:55:19 +00:00
|
|
|
int count;
|
2001-11-23 14:27:33 +00:00
|
|
|
|
2000-10-13 17:54:19 +00:00
|
|
|
RL_LOCK(sc);
|
2004-07-05 02:51:32 +00:00
|
|
|
|
2004-07-09 00:07:06 +00:00
|
|
|
if (sc->suspended)
|
|
|
|
goto done_locked;
|
1998-10-18 16:24:34 +00:00
|
|
|
|
2002-04-16 22:03:14 +00:00
|
|
|
#ifdef DEVICE_POLLING
|
Big polling(4) cleanup.
o Axe poll in trap.
o Axe IFF_POLLING flag from if_flags.
o Rework revision 1.21 (Giant removal), in such a way that
poll_mtx is not dropped during call to polling handler.
This fixes problem with idle polling.
o Make registration and deregistration from polling in a
functional way, insted of next tick/interrupt.
o Obsolete kern.polling.enable. Polling is turned on/off
with ifconfig.
Detailed kern_poll.c changes:
- Remove polling handler flags, introduced in 1.21. The are not
needed now.
- Forget and do not check if_flags, if_capenable and if_drv_flags.
- Call all registered polling handlers unconditionally.
- Do not drop poll_mtx, when entering polling handlers.
- In ether_poll() NET_LOCK_GIANT prior to locking poll_mtx.
- In netisr_poll() axe the block, where polling code asks drivers
to unregister.
- In netisr_poll() and ether_poll() do polling always, if any
handlers are present.
- In ether_poll_[de]register() remove a lot of error hiding code. Assert
that arguments are correct, instead.
- In ether_poll_[de]register() use standard return values in case of
error or success.
- Introduce poll_switch() that is a sysctl handler for kern.polling.enable.
poll_switch() goes through interface list and enabled/disables polling.
A message that kern.polling.enable is deprecated is printed.
Detailed driver changes:
- On attach driver announces IFCAP_POLLING in if_capabilities, but
not in if_capenable.
- On detach driver calls ether_poll_deregister() if polling is enabled.
- In polling handler driver obtains its lock and checks IFF_DRV_RUNNING
flag. If there is no, then unlocks and returns.
- In ioctl handler driver checks for IFCAP_POLLING flag requested to
be set or cleared. Driver first calls ether_poll_[de]register(), then
obtains driver lock and [dis/en]ables interrupts.
- In interrupt handler driver checks IFCAP_POLLING flag in if_capenable.
If present, then returns.This is important to protect from spurious
interrupts.
Reviewed by: ru, sam, jhb
2005-10-01 18:56:19 +00:00
|
|
|
if (ifp->if_capenable & IFCAP_POLLING)
|
2004-07-09 00:07:06 +00:00
|
|
|
goto done_locked;
|
Big polling(4) cleanup.
o Axe poll in trap.
o Axe IFF_POLLING flag from if_flags.
o Rework revision 1.21 (Giant removal), in such a way that
poll_mtx is not dropped during call to polling handler.
This fixes problem with idle polling.
o Make registration and deregistration from polling in a
functional way, insted of next tick/interrupt.
o Obsolete kern.polling.enable. Polling is turned on/off
with ifconfig.
Detailed kern_poll.c changes:
- Remove polling handler flags, introduced in 1.21. The are not
needed now.
- Forget and do not check if_flags, if_capenable and if_drv_flags.
- Call all registered polling handlers unconditionally.
- Do not drop poll_mtx, when entering polling handlers.
- In ether_poll() NET_LOCK_GIANT prior to locking poll_mtx.
- In netisr_poll() axe the block, where polling code asks drivers
to unregister.
- In netisr_poll() and ether_poll() do polling always, if any
handlers are present.
- In ether_poll_[de]register() remove a lot of error hiding code. Assert
that arguments are correct, instead.
- In ether_poll_[de]register() use standard return values in case of
error or success.
- Introduce poll_switch() that is a sysctl handler for kern.polling.enable.
poll_switch() goes through interface list and enabled/disables polling.
A message that kern.polling.enable is deprecated is printed.
Detailed driver changes:
- On attach driver announces IFCAP_POLLING in if_capabilities, but
not in if_capenable.
- On detach driver calls ether_poll_deregister() if polling is enabled.
- In polling handler driver obtains its lock and checks IFF_DRV_RUNNING
flag. If there is no, then unlocks and returns.
- In ioctl handler driver checks for IFCAP_POLLING flag requested to
be set or cleared. Driver first calls ether_poll_[de]register(), then
obtains driver lock and [dis/en]ables interrupts.
- In interrupt handler driver checks IFCAP_POLLING flag in if_capenable.
If present, then returns.This is important to protect from spurious
interrupts.
Reviewed by: ru, sam, jhb
2005-10-01 18:56:19 +00:00
|
|
|
#endif
|
1998-10-18 16:24:34 +00:00
|
|
|
|
2010-10-13 17:55:19 +00:00
|
|
|
if ((ifp->if_drv_flags & IFF_DRV_RUNNING) == 0)
|
|
|
|
goto done_locked2;
|
|
|
|
status = CSR_READ_2(sc, RL_ISR);
|
|
|
|
if (status == 0xffff || (status & RL_INTRS) == 0)
|
|
|
|
goto done_locked;
|
|
|
|
/*
|
|
|
|
* Ours, disable further interrupts.
|
|
|
|
*/
|
|
|
|
CSR_WRITE_2(sc, RL_IMR, 0);
|
|
|
|
for (count = 16; count > 0; count--) {
|
|
|
|
CSR_WRITE_2(sc, RL_ISR, status);
|
|
|
|
if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
|
|
|
|
if (status & (RL_ISR_RX_OK | RL_ISR_RX_ERR))
|
|
|
|
rl_rxeof(sc);
|
|
|
|
if (status & (RL_ISR_TX_OK | RL_ISR_TX_ERR))
|
|
|
|
rl_txeof(sc);
|
|
|
|
if (status & RL_ISR_SYSTEM_ERR) {
|
|
|
|
ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
|
|
|
|
rl_init_locked(sc);
|
|
|
|
RL_UNLOCK(sc);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
1998-10-18 16:24:34 +00:00
|
|
|
status = CSR_READ_2(sc, RL_ISR);
|
2004-07-05 02:46:42 +00:00
|
|
|
/* If the card has gone away, the read returns 0xffff. */
|
2010-10-13 17:55:19 +00:00
|
|
|
if (status == 0xffff || (status & RL_INTRS) == 0)
|
1998-10-18 16:24:34 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2004-07-02 12:16:02 +00:00
|
|
|
if (!IFQ_DRV_IS_EMPTY(&ifp->if_snd))
|
2004-07-09 00:07:06 +00:00
|
|
|
rl_start_locked(ifp);
|
|
|
|
|
2010-10-13 17:55:19 +00:00
|
|
|
done_locked2:
|
|
|
|
if (ifp->if_drv_flags & IFF_DRV_RUNNING)
|
|
|
|
CSR_WRITE_2(sc, RL_IMR, RL_INTRS);
|
2004-07-09 00:07:06 +00:00
|
|
|
done_locked:
|
|
|
|
RL_UNLOCK(sc);
|
1998-10-18 16:24:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Encapsulate an mbuf chain in a descriptor by coupling the mbuf data
|
|
|
|
* pointers to the fragment pointers.
|
|
|
|
*/
|
2002-08-23 23:49:02 +00:00
|
|
|
static int
|
2008-10-25 02:36:08 +00:00
|
|
|
rl_encap(struct rl_softc *sc, struct mbuf **m_head)
|
1998-10-18 16:24:34 +00:00
|
|
|
{
|
2008-10-25 02:36:08 +00:00
|
|
|
struct mbuf *m;
|
|
|
|
bus_dma_segment_t txsegs[1];
|
|
|
|
int error, nsegs, padlen;
|
1998-10-18 16:24:34 +00:00
|
|
|
|
2004-07-05 02:51:32 +00:00
|
|
|
RL_LOCK_ASSERT(sc);
|
|
|
|
|
2008-10-25 02:36:08 +00:00
|
|
|
m = *m_head;
|
|
|
|
padlen = 0;
|
|
|
|
/*
|
|
|
|
* Hardware doesn't auto-pad, so we have to make sure
|
|
|
|
* pad short frames out to the minimum frame length.
|
|
|
|
*/
|
|
|
|
if (m->m_pkthdr.len < RL_MIN_FRAMELEN)
|
|
|
|
padlen = RL_MIN_FRAMELEN - m->m_pkthdr.len;
|
1998-10-18 16:24:34 +00:00
|
|
|
/*
|
1999-04-12 21:37:00 +00:00
|
|
|
* The RealTek is brain damaged and wants longword-aligned
|
|
|
|
* TX buffers, plus we can only have one fragment buffer
|
|
|
|
* per packet. We have to copy pretty much all the time.
|
1998-10-18 16:24:34 +00:00
|
|
|
*/
|
2008-10-25 02:36:08 +00:00
|
|
|
if (m->m_next != NULL || (mtod(m, uintptr_t) & 3) != 0 ||
|
|
|
|
(padlen > 0 && M_TRAILINGSPACE(m) < padlen)) {
|
2012-12-05 08:04:20 +00:00
|
|
|
m = m_defrag(*m_head, M_NOWAIT);
|
2008-10-25 02:36:08 +00:00
|
|
|
if (m == NULL) {
|
|
|
|
m_freem(*m_head);
|
|
|
|
*m_head = NULL;
|
|
|
|
return (ENOMEM);
|
|
|
|
}
|
2003-04-15 04:06:01 +00:00
|
|
|
}
|
2008-10-25 02:36:08 +00:00
|
|
|
*m_head = m;
|
1998-10-18 16:24:34 +00:00
|
|
|
|
2008-10-25 02:36:08 +00:00
|
|
|
if (padlen > 0) {
|
1999-12-23 19:05:58 +00:00
|
|
|
/*
|
2008-11-01 17:02:01 +00:00
|
|
|
* Make security-conscious people happy: zero out the
|
1999-12-23 19:05:58 +00:00
|
|
|
* bytes in the pad area, since we don't know what
|
|
|
|
* this mbuf cluster buffer's previous user might
|
|
|
|
* have left in it.
|
2003-01-11 16:11:21 +00:00
|
|
|
*/
|
2008-10-25 02:36:08 +00:00
|
|
|
bzero(mtod(m, char *) + m->m_pkthdr.len, padlen);
|
|
|
|
m->m_pkthdr.len += padlen;
|
|
|
|
m->m_len = m->m_pkthdr.len;
|
|
|
|
}
|
|
|
|
|
|
|
|
error = bus_dmamap_load_mbuf_sg(sc->rl_cdata.rl_tx_tag,
|
|
|
|
RL_CUR_DMAMAP(sc), m, txsegs, &nsegs, 0);
|
|
|
|
if (error != 0)
|
|
|
|
return (error);
|
|
|
|
if (nsegs == 0) {
|
|
|
|
m_freem(*m_head);
|
|
|
|
*m_head = NULL;
|
|
|
|
return (EIO);
|
1998-11-18 21:03:58 +00:00
|
|
|
}
|
1998-10-18 16:24:34 +00:00
|
|
|
|
2008-10-25 02:36:08 +00:00
|
|
|
RL_CUR_TXMBUF(sc) = m;
|
|
|
|
bus_dmamap_sync(sc->rl_cdata.rl_tx_tag, RL_CUR_DMAMAP(sc),
|
|
|
|
BUS_DMASYNC_PREWRITE);
|
|
|
|
CSR_WRITE_4(sc, RL_CUR_TXADDR(sc), RL_ADDR_LO(txsegs[0].ds_addr));
|
1998-10-18 16:24:34 +00:00
|
|
|
|
2004-07-05 02:46:42 +00:00
|
|
|
return (0);
|
1998-10-18 16:24:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Main transmit routine.
|
|
|
|
*/
|
2002-08-23 23:49:02 +00:00
|
|
|
static void
|
2004-07-05 02:46:42 +00:00
|
|
|
rl_start(struct ifnet *ifp)
|
1998-10-18 16:24:34 +00:00
|
|
|
{
|
2004-07-05 02:46:42 +00:00
|
|
|
struct rl_softc *sc = ifp->if_softc;
|
1998-10-18 16:24:34 +00:00
|
|
|
|
2000-10-13 17:54:19 +00:00
|
|
|
RL_LOCK(sc);
|
2004-07-09 00:07:06 +00:00
|
|
|
rl_start_locked(ifp);
|
|
|
|
RL_UNLOCK(sc);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
rl_start_locked(struct ifnet *ifp)
|
|
|
|
{
|
|
|
|
struct rl_softc *sc = ifp->if_softc;
|
|
|
|
struct mbuf *m_head = NULL;
|
|
|
|
|
|
|
|
RL_LOCK_ASSERT(sc);
|
1998-10-18 16:24:34 +00:00
|
|
|
|
2008-10-25 03:41:36 +00:00
|
|
|
if ((ifp->if_drv_flags & (IFF_DRV_RUNNING | IFF_DRV_OACTIVE)) !=
|
|
|
|
IFF_DRV_RUNNING || (sc->rl_flags & RL_FLAG_LINK) == 0)
|
|
|
|
return;
|
|
|
|
|
2004-07-05 02:46:42 +00:00
|
|
|
while (RL_CUR_TXMBUF(sc) == NULL) {
|
2004-07-09 00:07:06 +00:00
|
|
|
|
2004-07-02 12:16:02 +00:00
|
|
|
IFQ_DRV_DEQUEUE(&ifp->if_snd, m_head);
|
2004-07-09 00:07:06 +00:00
|
|
|
|
1998-10-18 16:24:34 +00:00
|
|
|
if (m_head == NULL)
|
|
|
|
break;
|
|
|
|
|
2008-10-25 02:36:08 +00:00
|
|
|
if (rl_encap(sc, &m_head)) {
|
|
|
|
if (m_head == NULL)
|
|
|
|
break;
|
|
|
|
IFQ_DRV_PREPEND(&ifp->if_snd, m_head);
|
|
|
|
ifp->if_drv_flags |= IFF_DRV_OACTIVE;
|
2000-03-29 20:06:15 +00:00
|
|
|
break;
|
2008-10-25 02:36:08 +00:00
|
|
|
}
|
1998-10-18 16:24:34 +00:00
|
|
|
|
2004-07-05 02:46:42 +00:00
|
|
|
/* Pass a copy of this mbuf chain to the bpf subsystem. */
|
2002-11-14 23:49:09 +00:00
|
|
|
BPF_MTAP(ifp, RL_CUR_TXMBUF(sc));
|
1999-09-23 03:32:57 +00:00
|
|
|
|
2004-07-05 02:46:42 +00:00
|
|
|
/* Transmit the frame. */
|
1999-04-12 21:37:00 +00:00
|
|
|
CSR_WRITE_4(sc, RL_CUR_TXSTAT(sc),
|
1999-10-21 19:42:03 +00:00
|
|
|
RL_TXTHRESH(sc->rl_txthresh) |
|
|
|
|
RL_CUR_TXMBUF(sc)->m_pkthdr.len);
|
1999-04-12 21:37:00 +00:00
|
|
|
|
|
|
|
RL_INC(sc->rl_cdata.cur_tx);
|
2003-04-08 03:32:52 +00:00
|
|
|
|
2004-07-05 02:46:42 +00:00
|
|
|
/* Set a timeout in case the chip goes out to lunch. */
|
2006-12-01 21:52:07 +00:00
|
|
|
sc->rl_watchdog_timer = 5;
|
1998-10-18 16:24:34 +00:00
|
|
|
}
|
|
|
|
|
1999-04-12 21:37:00 +00:00
|
|
|
/*
|
|
|
|
* We broke out of the loop because all our TX slots are
|
|
|
|
* full. Mark the NIC as busy until it drains some of the
|
|
|
|
* packets from the queue.
|
|
|
|
*/
|
|
|
|
if (RL_CUR_TXMBUF(sc) != NULL)
|
2005-08-09 10:20:02 +00:00
|
|
|
ifp->if_drv_flags |= IFF_DRV_OACTIVE;
|
1998-10-18 16:24:34 +00:00
|
|
|
}
|
|
|
|
|
2002-08-23 23:49:02 +00:00
|
|
|
static void
|
2004-07-05 02:46:42 +00:00
|
|
|
rl_init(void *xsc)
|
1998-10-18 16:24:34 +00:00
|
|
|
{
|
|
|
|
struct rl_softc *sc = xsc;
|
2004-07-09 00:07:06 +00:00
|
|
|
|
|
|
|
RL_LOCK(sc);
|
|
|
|
rl_init_locked(sc);
|
|
|
|
RL_UNLOCK(sc);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
rl_init_locked(struct rl_softc *sc)
|
|
|
|
{
|
2005-06-10 16:49:24 +00:00
|
|
|
struct ifnet *ifp = sc->rl_ifp;
|
1999-08-31 14:45:51 +00:00
|
|
|
struct mii_data *mii;
|
2006-12-18 01:38:10 +00:00
|
|
|
uint32_t eaddr[2];
|
1998-10-18 16:24:34 +00:00
|
|
|
|
2004-07-09 00:07:06 +00:00
|
|
|
RL_LOCK_ASSERT(sc);
|
|
|
|
|
1999-08-31 14:45:51 +00:00
|
|
|
mii = device_get_softc(sc->rl_miibus);
|
1998-10-18 16:24:34 +00:00
|
|
|
|
2010-08-24 18:52:24 +00:00
|
|
|
if ((ifp->if_drv_flags & IFF_DRV_RUNNING) != 0)
|
|
|
|
return;
|
|
|
|
|
1998-10-18 16:24:34 +00:00
|
|
|
/*
|
|
|
|
* Cancel pending I/O and free all RX/TX buffers.
|
|
|
|
*/
|
|
|
|
rl_stop(sc);
|
|
|
|
|
2008-10-25 02:52:06 +00:00
|
|
|
rl_reset(sc);
|
2008-11-02 16:50:57 +00:00
|
|
|
if (sc->rl_twister_enable) {
|
|
|
|
/*
|
|
|
|
* Reset twister register tuning state. The twister
|
|
|
|
* registers and their tuning are undocumented, but
|
|
|
|
* are necessary to cope with bad links. rl_twister =
|
|
|
|
* DONE here will disable this entirely.
|
|
|
|
*/
|
|
|
|
sc->rl_twister = CHK_LINK;
|
|
|
|
}
|
2008-10-25 02:52:06 +00:00
|
|
|
|
2003-06-29 17:33:33 +00:00
|
|
|
/*
|
|
|
|
* Init our MAC address. Even though the chipset
|
|
|
|
* documentation doesn't mention it, we need to enter "Config
|
|
|
|
* register write enable" mode to modify the ID registers.
|
|
|
|
*/
|
|
|
|
CSR_WRITE_1(sc, RL_EECMD, RL_EEMODE_WRITECFG);
|
2006-12-18 01:38:10 +00:00
|
|
|
bzero(eaddr, sizeof(eaddr));
|
|
|
|
bcopy(IF_LLADDR(sc->rl_ifp), eaddr, ETHER_ADDR_LEN);
|
|
|
|
CSR_WRITE_STREAM_4(sc, RL_IDR0, eaddr[0]);
|
|
|
|
CSR_WRITE_STREAM_4(sc, RL_IDR4, eaddr[1]);
|
2003-06-29 17:33:33 +00:00
|
|
|
CSR_WRITE_1(sc, RL_EECMD, RL_EEMODE_OFF);
|
1998-10-18 16:24:34 +00:00
|
|
|
|
2008-10-25 02:36:08 +00:00
|
|
|
/* Init the RX memory block pointer register. */
|
|
|
|
CSR_WRITE_4(sc, RL_RXADDR, sc->rl_cdata.rl_rx_buf_paddr +
|
|
|
|
RL_RX_8139_BUF_RESERVE);
|
Take the support for the 8139C+/8169/8169S/8110S chips out of the
rl(4) driver and put it in a new re(4) driver. The re(4) driver shares
the if_rlreg.h file with rl(4) but is a separate module. (Ultimately
I may change this. For now, it's convenient.)
rl(4) has been modified so that it will never attach to an 8139C+
chip, leaving it to re(4) instead. Only re(4) has the PCI IDs to
match the 8169/8169S/8110S gigE chips. if_re.c contains the same
basic code that was originally bolted onto if_rl.c, with the
following updates:
- Added support for jumbo frames. Currently, there seems to be
a limit of approximately 6200 bytes for jumbo frames on transmit.
(This was determined via experimentation.) The 8169S/8110S chips
apparently are limited to 7.5K frames on transmit. This may require
some more work, though the framework to handle jumbo frames on RX
is in place: the re_rxeof() routine will gather up frames than span
multiple 2K clusters into a single mbuf list.
- Fixed bug in re_txeof(): if we reap some of the TX buffers,
but there are still some pending, re-arm the timer before exiting
re_txeof() so that another timeout interrupt will be generated, just
in case re_start() doesn't do it for us.
- Handle the 'link state changed' interrupt
- Fix a detach bug. If re(4) is loaded as a module, and you do
tcpdump -i re0, then you do 'kldunload if_re,' the system will
panic after a few seconds. This happens because ether_ifdetach()
ends up calling the BPF detach code, which notices the interface
is in promiscuous mode and tries to switch promisc mode off while
detaching the BPF listner. This ultimately results in a call
to re_ioctl() (due to SIOCSIFFLAGS), which in turn calls re_init()
to handle the IFF_PROMISC flag change. Unfortunately, calling re_init()
here turns the chip back on and restarts the 1-second timeout loop
that drives re_tick(). By the time the timeout fires, if_re.ko
has been unloaded, which results in a call to invalid code and
blows up the system.
To fix this, I cleared the IFF_UP flag before calling ether_ifdetach(),
which stops the ioctl routine from trying to reset the chip.
- Modified comments in re_rxeof() relating to the difference in
RX descriptor status bit layout between the 8139C+ and the gigE
chips. The layout is different because the frame length field
was expanded from 12 bits to 13, and they got rid of one of the
status bits to make room.
- Add diagnostic code (re_diag()) to test for the case where a user
has installed a broken 32-bit 8169 PCI NIC in a 64-bit slot. Some
NICs have the REQ64# and ACK64# lines connected even though the
board is 32-bit only (in this case, they should be pulled high).
This fools the chip into doing 64-bit DMA transfers even though
there is no 64-bit data path. To detect this, re_diag() puts the
chip into digital loopback mode and sets the receiver to promiscuous
mode, then initiates a single 64-byte packet transmission. The
frame is echoed back to the host, and if the frame contents are
intact, we know DMA is working correctly, otherwise we complain
loudly on the console and abort the device attach. (At the moment,
I don't know of any way to work around the problem other than
physically modifying the board, so until/unless I can think of a
software workaround, this will have do to.)
- Created re(4) man page
- Modified rlphy.c to allow re(4) to attach as well as rl(4).
Note that this code works for the sample 8169/Marvell 88E1000 NIC
that I have, but probably won't work for the 8169S/8110S chips.
RealTek has sent me some sample NICs, but they haven't arrived yet.
I will probably need to add an rlgphy driver to handle the on-board
PHY in the 8169S/8110S (it needs special DSP initialization).
2003-09-08 02:11:25 +00:00
|
|
|
/* Init TX descriptors. */
|
|
|
|
rl_list_tx_init(sc);
|
2008-10-25 02:36:08 +00:00
|
|
|
/* Init Rx memory block. */
|
|
|
|
rl_list_rx_init(sc);
|
1998-10-18 16:24:34 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Enable transmit and receive.
|
|
|
|
*/
|
|
|
|
CSR_WRITE_1(sc, RL_COMMAND, RL_CMD_TX_ENB|RL_CMD_RX_ENB);
|
|
|
|
|
|
|
|
/*
|
1999-04-12 21:37:00 +00:00
|
|
|
* Set the initial TX and RX configuration.
|
1998-10-18 16:24:34 +00:00
|
|
|
*/
|
1999-04-12 21:37:00 +00:00
|
|
|
CSR_WRITE_4(sc, RL_TXCFG, RL_TXCFG_CONFIG);
|
1998-10-18 16:24:34 +00:00
|
|
|
CSR_WRITE_4(sc, RL_RXCFG, RL_RXCFG_CONFIG);
|
|
|
|
|
2010-09-30 17:37:08 +00:00
|
|
|
/* Set RX filter. */
|
|
|
|
rl_rxfilter(sc);
|
1998-10-18 16:24:34 +00:00
|
|
|
|
2002-04-16 22:03:14 +00:00
|
|
|
#ifdef DEVICE_POLLING
|
2004-07-05 02:46:42 +00:00
|
|
|
/* Disable interrupts if we are polling. */
|
Big polling(4) cleanup.
o Axe poll in trap.
o Axe IFF_POLLING flag from if_flags.
o Rework revision 1.21 (Giant removal), in such a way that
poll_mtx is not dropped during call to polling handler.
This fixes problem with idle polling.
o Make registration and deregistration from polling in a
functional way, insted of next tick/interrupt.
o Obsolete kern.polling.enable. Polling is turned on/off
with ifconfig.
Detailed kern_poll.c changes:
- Remove polling handler flags, introduced in 1.21. The are not
needed now.
- Forget and do not check if_flags, if_capenable and if_drv_flags.
- Call all registered polling handlers unconditionally.
- Do not drop poll_mtx, when entering polling handlers.
- In ether_poll() NET_LOCK_GIANT prior to locking poll_mtx.
- In netisr_poll() axe the block, where polling code asks drivers
to unregister.
- In netisr_poll() and ether_poll() do polling always, if any
handlers are present.
- In ether_poll_[de]register() remove a lot of error hiding code. Assert
that arguments are correct, instead.
- In ether_poll_[de]register() use standard return values in case of
error or success.
- Introduce poll_switch() that is a sysctl handler for kern.polling.enable.
poll_switch() goes through interface list and enabled/disables polling.
A message that kern.polling.enable is deprecated is printed.
Detailed driver changes:
- On attach driver announces IFCAP_POLLING in if_capabilities, but
not in if_capenable.
- On detach driver calls ether_poll_deregister() if polling is enabled.
- In polling handler driver obtains its lock and checks IFF_DRV_RUNNING
flag. If there is no, then unlocks and returns.
- In ioctl handler driver checks for IFCAP_POLLING flag requested to
be set or cleared. Driver first calls ether_poll_[de]register(), then
obtains driver lock and [dis/en]ables interrupts.
- In interrupt handler driver checks IFCAP_POLLING flag in if_capenable.
If present, then returns.This is important to protect from spurious
interrupts.
Reviewed by: ru, sam, jhb
2005-10-01 18:56:19 +00:00
|
|
|
if (ifp->if_capenable & IFCAP_POLLING)
|
2002-04-16 22:03:14 +00:00
|
|
|
CSR_WRITE_2(sc, RL_IMR, 0);
|
2004-07-05 02:46:42 +00:00
|
|
|
else
|
Big polling(4) cleanup.
o Axe poll in trap.
o Axe IFF_POLLING flag from if_flags.
o Rework revision 1.21 (Giant removal), in such a way that
poll_mtx is not dropped during call to polling handler.
This fixes problem with idle polling.
o Make registration and deregistration from polling in a
functional way, insted of next tick/interrupt.
o Obsolete kern.polling.enable. Polling is turned on/off
with ifconfig.
Detailed kern_poll.c changes:
- Remove polling handler flags, introduced in 1.21. The are not
needed now.
- Forget and do not check if_flags, if_capenable and if_drv_flags.
- Call all registered polling handlers unconditionally.
- Do not drop poll_mtx, when entering polling handlers.
- In ether_poll() NET_LOCK_GIANT prior to locking poll_mtx.
- In netisr_poll() axe the block, where polling code asks drivers
to unregister.
- In netisr_poll() and ether_poll() do polling always, if any
handlers are present.
- In ether_poll_[de]register() remove a lot of error hiding code. Assert
that arguments are correct, instead.
- In ether_poll_[de]register() use standard return values in case of
error or success.
- Introduce poll_switch() that is a sysctl handler for kern.polling.enable.
poll_switch() goes through interface list and enabled/disables polling.
A message that kern.polling.enable is deprecated is printed.
Detailed driver changes:
- On attach driver announces IFCAP_POLLING in if_capabilities, but
not in if_capenable.
- On detach driver calls ether_poll_deregister() if polling is enabled.
- In polling handler driver obtains its lock and checks IFF_DRV_RUNNING
flag. If there is no, then unlocks and returns.
- In ioctl handler driver checks for IFCAP_POLLING flag requested to
be set or cleared. Driver first calls ether_poll_[de]register(), then
obtains driver lock and [dis/en]ables interrupts.
- In interrupt handler driver checks IFCAP_POLLING flag in if_capenable.
If present, then returns.This is important to protect from spurious
interrupts.
Reviewed by: ru, sam, jhb
2005-10-01 18:56:19 +00:00
|
|
|
#endif
|
2004-07-05 02:46:42 +00:00
|
|
|
/* Enable interrupts. */
|
Take the support for the 8139C+/8169/8169S/8110S chips out of the
rl(4) driver and put it in a new re(4) driver. The re(4) driver shares
the if_rlreg.h file with rl(4) but is a separate module. (Ultimately
I may change this. For now, it's convenient.)
rl(4) has been modified so that it will never attach to an 8139C+
chip, leaving it to re(4) instead. Only re(4) has the PCI IDs to
match the 8169/8169S/8110S gigE chips. if_re.c contains the same
basic code that was originally bolted onto if_rl.c, with the
following updates:
- Added support for jumbo frames. Currently, there seems to be
a limit of approximately 6200 bytes for jumbo frames on transmit.
(This was determined via experimentation.) The 8169S/8110S chips
apparently are limited to 7.5K frames on transmit. This may require
some more work, though the framework to handle jumbo frames on RX
is in place: the re_rxeof() routine will gather up frames than span
multiple 2K clusters into a single mbuf list.
- Fixed bug in re_txeof(): if we reap some of the TX buffers,
but there are still some pending, re-arm the timer before exiting
re_txeof() so that another timeout interrupt will be generated, just
in case re_start() doesn't do it for us.
- Handle the 'link state changed' interrupt
- Fix a detach bug. If re(4) is loaded as a module, and you do
tcpdump -i re0, then you do 'kldunload if_re,' the system will
panic after a few seconds. This happens because ether_ifdetach()
ends up calling the BPF detach code, which notices the interface
is in promiscuous mode and tries to switch promisc mode off while
detaching the BPF listner. This ultimately results in a call
to re_ioctl() (due to SIOCSIFFLAGS), which in turn calls re_init()
to handle the IFF_PROMISC flag change. Unfortunately, calling re_init()
here turns the chip back on and restarts the 1-second timeout loop
that drives re_tick(). By the time the timeout fires, if_re.ko
has been unloaded, which results in a call to invalid code and
blows up the system.
To fix this, I cleared the IFF_UP flag before calling ether_ifdetach(),
which stops the ioctl routine from trying to reset the chip.
- Modified comments in re_rxeof() relating to the difference in
RX descriptor status bit layout between the 8139C+ and the gigE
chips. The layout is different because the frame length field
was expanded from 12 bits to 13, and they got rid of one of the
status bits to make room.
- Add diagnostic code (re_diag()) to test for the case where a user
has installed a broken 32-bit 8169 PCI NIC in a 64-bit slot. Some
NICs have the REQ64# and ACK64# lines connected even though the
board is 32-bit only (in this case, they should be pulled high).
This fools the chip into doing 64-bit DMA transfers even though
there is no 64-bit data path. To detect this, re_diag() puts the
chip into digital loopback mode and sets the receiver to promiscuous
mode, then initiates a single 64-byte packet transmission. The
frame is echoed back to the host, and if the frame contents are
intact, we know DMA is working correctly, otherwise we complain
loudly on the console and abort the device attach. (At the moment,
I don't know of any way to work around the problem other than
physically modifying the board, so until/unless I can think of a
software workaround, this will have do to.)
- Created re(4) man page
- Modified rlphy.c to allow re(4) to attach as well as rl(4).
Note that this code works for the sample 8169/Marvell 88E1000 NIC
that I have, but probably won't work for the 8169S/8110S chips.
RealTek has sent me some sample NICs, but they haven't arrived yet.
I will probably need to add an rlgphy driver to handle the on-board
PHY in the 8169S/8110S (it needs special DSP initialization).
2003-09-08 02:11:25 +00:00
|
|
|
CSR_WRITE_2(sc, RL_IMR, RL_INTRS);
|
1998-10-18 16:24:34 +00:00
|
|
|
|
1999-10-21 19:42:03 +00:00
|
|
|
/* Set initial TX threshold */
|
|
|
|
sc->rl_txthresh = RL_TX_THRESH_INIT;
|
|
|
|
|
1998-10-18 16:24:34 +00:00
|
|
|
/* Start RX/TX process. */
|
|
|
|
CSR_WRITE_4(sc, RL_MISSEDPKT, 0);
|
Take the support for the 8139C+/8169/8169S/8110S chips out of the
rl(4) driver and put it in a new re(4) driver. The re(4) driver shares
the if_rlreg.h file with rl(4) but is a separate module. (Ultimately
I may change this. For now, it's convenient.)
rl(4) has been modified so that it will never attach to an 8139C+
chip, leaving it to re(4) instead. Only re(4) has the PCI IDs to
match the 8169/8169S/8110S gigE chips. if_re.c contains the same
basic code that was originally bolted onto if_rl.c, with the
following updates:
- Added support for jumbo frames. Currently, there seems to be
a limit of approximately 6200 bytes for jumbo frames on transmit.
(This was determined via experimentation.) The 8169S/8110S chips
apparently are limited to 7.5K frames on transmit. This may require
some more work, though the framework to handle jumbo frames on RX
is in place: the re_rxeof() routine will gather up frames than span
multiple 2K clusters into a single mbuf list.
- Fixed bug in re_txeof(): if we reap some of the TX buffers,
but there are still some pending, re-arm the timer before exiting
re_txeof() so that another timeout interrupt will be generated, just
in case re_start() doesn't do it for us.
- Handle the 'link state changed' interrupt
- Fix a detach bug. If re(4) is loaded as a module, and you do
tcpdump -i re0, then you do 'kldunload if_re,' the system will
panic after a few seconds. This happens because ether_ifdetach()
ends up calling the BPF detach code, which notices the interface
is in promiscuous mode and tries to switch promisc mode off while
detaching the BPF listner. This ultimately results in a call
to re_ioctl() (due to SIOCSIFFLAGS), which in turn calls re_init()
to handle the IFF_PROMISC flag change. Unfortunately, calling re_init()
here turns the chip back on and restarts the 1-second timeout loop
that drives re_tick(). By the time the timeout fires, if_re.ko
has been unloaded, which results in a call to invalid code and
blows up the system.
To fix this, I cleared the IFF_UP flag before calling ether_ifdetach(),
which stops the ioctl routine from trying to reset the chip.
- Modified comments in re_rxeof() relating to the difference in
RX descriptor status bit layout between the 8139C+ and the gigE
chips. The layout is different because the frame length field
was expanded from 12 bits to 13, and they got rid of one of the
status bits to make room.
- Add diagnostic code (re_diag()) to test for the case where a user
has installed a broken 32-bit 8169 PCI NIC in a 64-bit slot. Some
NICs have the REQ64# and ACK64# lines connected even though the
board is 32-bit only (in this case, they should be pulled high).
This fools the chip into doing 64-bit DMA transfers even though
there is no 64-bit data path. To detect this, re_diag() puts the
chip into digital loopback mode and sets the receiver to promiscuous
mode, then initiates a single 64-byte packet transmission. The
frame is echoed back to the host, and if the frame contents are
intact, we know DMA is working correctly, otherwise we complain
loudly on the console and abort the device attach. (At the moment,
I don't know of any way to work around the problem other than
physically modifying the board, so until/unless I can think of a
software workaround, this will have do to.)
- Created re(4) man page
- Modified rlphy.c to allow re(4) to attach as well as rl(4).
Note that this code works for the sample 8169/Marvell 88E1000 NIC
that I have, but probably won't work for the 8169S/8110S chips.
RealTek has sent me some sample NICs, but they haven't arrived yet.
I will probably need to add an rlgphy driver to handle the on-board
PHY in the 8169S/8110S (it needs special DSP initialization).
2003-09-08 02:11:25 +00:00
|
|
|
|
1998-10-18 16:24:34 +00:00
|
|
|
/* Enable receiver and transmitter. */
|
|
|
|
CSR_WRITE_1(sc, RL_COMMAND, RL_CMD_TX_ENB|RL_CMD_RX_ENB);
|
|
|
|
|
2008-10-25 03:41:36 +00:00
|
|
|
sc->rl_flags &= ~RL_FLAG_LINK;
|
1999-08-31 14:45:51 +00:00
|
|
|
mii_mediachg(mii);
|
1998-10-18 16:24:34 +00:00
|
|
|
|
2012-02-25 04:54:51 +00:00
|
|
|
CSR_WRITE_1(sc, sc->rl_cfg1, RL_CFG1_DRVLOAD|RL_CFG1_FULLDUPLEX);
|
1998-10-18 16:24:34 +00:00
|
|
|
|
2005-08-09 10:20:02 +00:00
|
|
|
ifp->if_drv_flags |= IFF_DRV_RUNNING;
|
|
|
|
ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
|
1998-10-18 16:24:34 +00:00
|
|
|
|
2005-09-29 16:52:19 +00:00
|
|
|
callout_reset(&sc->rl_stat_callout, hz, rl_tick, sc);
|
1998-10-18 16:24:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set media options.
|
|
|
|
*/
|
2002-08-23 23:49:02 +00:00
|
|
|
static int
|
2004-07-05 02:46:42 +00:00
|
|
|
rl_ifmedia_upd(struct ifnet *ifp)
|
1998-10-18 16:24:34 +00:00
|
|
|
{
|
2004-07-05 02:46:42 +00:00
|
|
|
struct rl_softc *sc = ifp->if_softc;
|
1999-08-31 14:45:51 +00:00
|
|
|
struct mii_data *mii;
|
1998-10-18 16:24:34 +00:00
|
|
|
|
1999-08-31 14:45:51 +00:00
|
|
|
mii = device_get_softc(sc->rl_miibus);
|
2004-07-05 02:46:42 +00:00
|
|
|
|
2005-09-29 16:52:19 +00:00
|
|
|
RL_LOCK(sc);
|
1999-08-31 14:45:51 +00:00
|
|
|
mii_mediachg(mii);
|
2005-09-29 16:52:19 +00:00
|
|
|
RL_UNLOCK(sc);
|
1998-10-18 16:24:34 +00:00
|
|
|
|
2004-07-05 02:46:42 +00:00
|
|
|
return (0);
|
1998-10-18 16:24:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Report current media status.
|
|
|
|
*/
|
2002-08-23 23:49:02 +00:00
|
|
|
static void
|
2004-07-05 02:46:42 +00:00
|
|
|
rl_ifmedia_sts(struct ifnet *ifp, struct ifmediareq *ifmr)
|
1998-10-18 16:24:34 +00:00
|
|
|
{
|
2004-07-05 02:46:42 +00:00
|
|
|
struct rl_softc *sc = ifp->if_softc;
|
1999-08-31 14:45:51 +00:00
|
|
|
struct mii_data *mii;
|
1998-10-18 16:24:34 +00:00
|
|
|
|
1999-08-31 14:45:51 +00:00
|
|
|
mii = device_get_softc(sc->rl_miibus);
|
1998-10-18 16:24:34 +00:00
|
|
|
|
2005-09-29 16:52:19 +00:00
|
|
|
RL_LOCK(sc);
|
1999-08-31 14:45:51 +00:00
|
|
|
mii_pollstat(mii);
|
|
|
|
ifmr->ifm_active = mii->mii_media_active;
|
|
|
|
ifmr->ifm_status = mii->mii_media_status;
|
2011-10-17 19:49:00 +00:00
|
|
|
RL_UNLOCK(sc);
|
1998-10-18 16:24:34 +00:00
|
|
|
}
|
|
|
|
|
2002-08-23 23:49:02 +00:00
|
|
|
static int
|
2004-07-05 02:46:42 +00:00
|
|
|
rl_ioctl(struct ifnet *ifp, u_long command, caddr_t data)
|
1998-10-18 16:24:34 +00:00
|
|
|
{
|
2004-07-05 02:46:42 +00:00
|
|
|
struct ifreq *ifr = (struct ifreq *)data;
|
1999-08-31 14:45:51 +00:00
|
|
|
struct mii_data *mii;
|
2004-07-05 02:46:42 +00:00
|
|
|
struct rl_softc *sc = ifp->if_softc;
|
2010-07-19 18:01:06 +00:00
|
|
|
int error = 0, mask;
|
1998-10-18 16:24:34 +00:00
|
|
|
|
2004-07-05 02:46:42 +00:00
|
|
|
switch (command) {
|
1998-10-18 16:24:34 +00:00
|
|
|
case SIOCSIFFLAGS:
|
2004-07-09 00:07:06 +00:00
|
|
|
RL_LOCK(sc);
|
1998-10-18 16:24:34 +00:00
|
|
|
if (ifp->if_flags & IFF_UP) {
|
2010-09-30 17:37:08 +00:00
|
|
|
if (ifp->if_drv_flags & IFF_DRV_RUNNING &&
|
|
|
|
((ifp->if_flags ^ sc->rl_if_flags) &
|
|
|
|
(IFF_PROMISC | IFF_ALLMULTI)))
|
|
|
|
rl_rxfilter(sc);
|
|
|
|
else
|
|
|
|
rl_init_locked(sc);
|
|
|
|
} else if (ifp->if_drv_flags & IFF_DRV_RUNNING)
|
|
|
|
rl_stop(sc);
|
|
|
|
sc->rl_if_flags = ifp->if_flags;
|
2004-07-09 00:07:06 +00:00
|
|
|
RL_UNLOCK(sc);
|
1998-10-18 16:24:34 +00:00
|
|
|
break;
|
|
|
|
case SIOCADDMULTI:
|
|
|
|
case SIOCDELMULTI:
|
2004-07-05 02:51:32 +00:00
|
|
|
RL_LOCK(sc);
|
2010-09-30 17:37:08 +00:00
|
|
|
rl_rxfilter(sc);
|
2004-07-05 02:51:32 +00:00
|
|
|
RL_UNLOCK(sc);
|
1998-10-18 16:24:34 +00:00
|
|
|
break;
|
|
|
|
case SIOCGIFMEDIA:
|
|
|
|
case SIOCSIFMEDIA:
|
1999-08-31 14:45:51 +00:00
|
|
|
mii = device_get_softc(sc->rl_miibus);
|
|
|
|
error = ifmedia_ioctl(ifp, ifr, &mii->mii_media, command);
|
1998-10-18 16:24:34 +00:00
|
|
|
break;
|
2004-04-11 16:23:16 +00:00
|
|
|
case SIOCSIFCAP:
|
2010-07-19 18:01:06 +00:00
|
|
|
mask = ifr->ifr_reqcap ^ ifp->if_capenable;
|
Big polling(4) cleanup.
o Axe poll in trap.
o Axe IFF_POLLING flag from if_flags.
o Rework revision 1.21 (Giant removal), in such a way that
poll_mtx is not dropped during call to polling handler.
This fixes problem with idle polling.
o Make registration and deregistration from polling in a
functional way, insted of next tick/interrupt.
o Obsolete kern.polling.enable. Polling is turned on/off
with ifconfig.
Detailed kern_poll.c changes:
- Remove polling handler flags, introduced in 1.21. The are not
needed now.
- Forget and do not check if_flags, if_capenable and if_drv_flags.
- Call all registered polling handlers unconditionally.
- Do not drop poll_mtx, when entering polling handlers.
- In ether_poll() NET_LOCK_GIANT prior to locking poll_mtx.
- In netisr_poll() axe the block, where polling code asks drivers
to unregister.
- In netisr_poll() and ether_poll() do polling always, if any
handlers are present.
- In ether_poll_[de]register() remove a lot of error hiding code. Assert
that arguments are correct, instead.
- In ether_poll_[de]register() use standard return values in case of
error or success.
- Introduce poll_switch() that is a sysctl handler for kern.polling.enable.
poll_switch() goes through interface list and enabled/disables polling.
A message that kern.polling.enable is deprecated is printed.
Detailed driver changes:
- On attach driver announces IFCAP_POLLING in if_capabilities, but
not in if_capenable.
- On detach driver calls ether_poll_deregister() if polling is enabled.
- In polling handler driver obtains its lock and checks IFF_DRV_RUNNING
flag. If there is no, then unlocks and returns.
- In ioctl handler driver checks for IFCAP_POLLING flag requested to
be set or cleared. Driver first calls ether_poll_[de]register(), then
obtains driver lock and [dis/en]ables interrupts.
- In interrupt handler driver checks IFCAP_POLLING flag in if_capenable.
If present, then returns.This is important to protect from spurious
interrupts.
Reviewed by: ru, sam, jhb
2005-10-01 18:56:19 +00:00
|
|
|
#ifdef DEVICE_POLLING
|
|
|
|
if (ifr->ifr_reqcap & IFCAP_POLLING &&
|
|
|
|
!(ifp->if_capenable & IFCAP_POLLING)) {
|
|
|
|
error = ether_poll_register(rl_poll, ifp);
|
|
|
|
if (error)
|
|
|
|
return(error);
|
|
|
|
RL_LOCK(sc);
|
|
|
|
/* Disable interrupts */
|
|
|
|
CSR_WRITE_2(sc, RL_IMR, 0x0000);
|
|
|
|
ifp->if_capenable |= IFCAP_POLLING;
|
|
|
|
RL_UNLOCK(sc);
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
}
|
|
|
|
if (!(ifr->ifr_reqcap & IFCAP_POLLING) &&
|
|
|
|
ifp->if_capenable & IFCAP_POLLING) {
|
|
|
|
error = ether_poll_deregister(ifp);
|
|
|
|
/* Enable interrupts. */
|
|
|
|
RL_LOCK(sc);
|
|
|
|
CSR_WRITE_2(sc, RL_IMR, RL_INTRS);
|
|
|
|
ifp->if_capenable &= ~IFCAP_POLLING;
|
|
|
|
RL_UNLOCK(sc);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
#endif /* DEVICE_POLLING */
|
2010-07-19 18:01:06 +00:00
|
|
|
if ((mask & IFCAP_WOL) != 0 &&
|
|
|
|
(ifp->if_capabilities & IFCAP_WOL) != 0) {
|
|
|
|
if ((mask & IFCAP_WOL_UCAST) != 0)
|
|
|
|
ifp->if_capenable ^= IFCAP_WOL_UCAST;
|
|
|
|
if ((mask & IFCAP_WOL_MCAST) != 0)
|
|
|
|
ifp->if_capenable ^= IFCAP_WOL_MCAST;
|
|
|
|
if ((mask & IFCAP_WOL_MAGIC) != 0)
|
|
|
|
ifp->if_capenable ^= IFCAP_WOL_MAGIC;
|
|
|
|
}
|
2004-04-11 16:23:16 +00:00
|
|
|
break;
|
1998-10-18 16:24:34 +00:00
|
|
|
default:
|
2002-11-14 23:49:09 +00:00
|
|
|
error = ether_ioctl(ifp, command, data);
|
1998-10-18 16:24:34 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2004-07-05 02:46:42 +00:00
|
|
|
return (error);
|
1998-10-18 16:24:34 +00:00
|
|
|
}
|
|
|
|
|
2002-08-23 23:49:02 +00:00
|
|
|
static void
|
2006-12-01 21:52:07 +00:00
|
|
|
rl_watchdog(struct rl_softc *sc)
|
1998-10-18 16:24:34 +00:00
|
|
|
{
|
|
|
|
|
2006-12-01 21:52:07 +00:00
|
|
|
RL_LOCK_ASSERT(sc);
|
2004-07-05 02:46:42 +00:00
|
|
|
|
2006-12-01 21:52:07 +00:00
|
|
|
if (sc->rl_watchdog_timer == 0 || --sc->rl_watchdog_timer >0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
device_printf(sc->rl_dev, "watchdog timeout\n");
|
|
|
|
sc->rl_ifp->if_oerrors++;
|
1999-08-31 14:45:51 +00:00
|
|
|
|
Take the support for the 8139C+/8169/8169S/8110S chips out of the
rl(4) driver and put it in a new re(4) driver. The re(4) driver shares
the if_rlreg.h file with rl(4) but is a separate module. (Ultimately
I may change this. For now, it's convenient.)
rl(4) has been modified so that it will never attach to an 8139C+
chip, leaving it to re(4) instead. Only re(4) has the PCI IDs to
match the 8169/8169S/8110S gigE chips. if_re.c contains the same
basic code that was originally bolted onto if_rl.c, with the
following updates:
- Added support for jumbo frames. Currently, there seems to be
a limit of approximately 6200 bytes for jumbo frames on transmit.
(This was determined via experimentation.) The 8169S/8110S chips
apparently are limited to 7.5K frames on transmit. This may require
some more work, though the framework to handle jumbo frames on RX
is in place: the re_rxeof() routine will gather up frames than span
multiple 2K clusters into a single mbuf list.
- Fixed bug in re_txeof(): if we reap some of the TX buffers,
but there are still some pending, re-arm the timer before exiting
re_txeof() so that another timeout interrupt will be generated, just
in case re_start() doesn't do it for us.
- Handle the 'link state changed' interrupt
- Fix a detach bug. If re(4) is loaded as a module, and you do
tcpdump -i re0, then you do 'kldunload if_re,' the system will
panic after a few seconds. This happens because ether_ifdetach()
ends up calling the BPF detach code, which notices the interface
is in promiscuous mode and tries to switch promisc mode off while
detaching the BPF listner. This ultimately results in a call
to re_ioctl() (due to SIOCSIFFLAGS), which in turn calls re_init()
to handle the IFF_PROMISC flag change. Unfortunately, calling re_init()
here turns the chip back on and restarts the 1-second timeout loop
that drives re_tick(). By the time the timeout fires, if_re.ko
has been unloaded, which results in a call to invalid code and
blows up the system.
To fix this, I cleared the IFF_UP flag before calling ether_ifdetach(),
which stops the ioctl routine from trying to reset the chip.
- Modified comments in re_rxeof() relating to the difference in
RX descriptor status bit layout between the 8139C+ and the gigE
chips. The layout is different because the frame length field
was expanded from 12 bits to 13, and they got rid of one of the
status bits to make room.
- Add diagnostic code (re_diag()) to test for the case where a user
has installed a broken 32-bit 8169 PCI NIC in a 64-bit slot. Some
NICs have the REQ64# and ACK64# lines connected even though the
board is 32-bit only (in this case, they should be pulled high).
This fools the chip into doing 64-bit DMA transfers even though
there is no 64-bit data path. To detect this, re_diag() puts the
chip into digital loopback mode and sets the receiver to promiscuous
mode, then initiates a single 64-byte packet transmission. The
frame is echoed back to the host, and if the frame contents are
intact, we know DMA is working correctly, otherwise we complain
loudly on the console and abort the device attach. (At the moment,
I don't know of any way to work around the problem other than
physically modifying the board, so until/unless I can think of a
software workaround, this will have do to.)
- Created re(4) man page
- Modified rlphy.c to allow re(4) to attach as well as rl(4).
Note that this code works for the sample 8169/Marvell 88E1000 NIC
that I have, but probably won't work for the 8169S/8110S chips.
RealTek has sent me some sample NICs, but they haven't arrived yet.
I will probably need to add an rlgphy driver to handle the on-board
PHY in the 8169S/8110S (it needs special DSP initialization).
2003-09-08 02:11:25 +00:00
|
|
|
rl_txeof(sc);
|
|
|
|
rl_rxeof(sc);
|
2010-08-24 18:52:24 +00:00
|
|
|
sc->rl_ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
|
2004-07-09 00:07:06 +00:00
|
|
|
rl_init_locked(sc);
|
1998-10-18 16:24:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Stop the adapter and free any mbufs allocated to the
|
|
|
|
* RX and TX lists.
|
|
|
|
*/
|
2002-08-23 23:49:02 +00:00
|
|
|
static void
|
2004-07-05 02:46:42 +00:00
|
|
|
rl_stop(struct rl_softc *sc)
|
1998-10-18 16:24:34 +00:00
|
|
|
{
|
|
|
|
register int i;
|
2005-06-10 16:49:24 +00:00
|
|
|
struct ifnet *ifp = sc->rl_ifp;
|
1998-10-18 16:24:34 +00:00
|
|
|
|
2004-07-05 02:51:32 +00:00
|
|
|
RL_LOCK_ASSERT(sc);
|
2004-07-05 02:46:42 +00:00
|
|
|
|
2006-12-01 21:52:07 +00:00
|
|
|
sc->rl_watchdog_timer = 0;
|
2005-09-29 16:52:19 +00:00
|
|
|
callout_stop(&sc->rl_stat_callout);
|
2005-08-09 10:20:02 +00:00
|
|
|
ifp->if_drv_flags &= ~(IFF_DRV_RUNNING | IFF_DRV_OACTIVE);
|
2008-10-25 03:41:36 +00:00
|
|
|
sc->rl_flags &= ~RL_FLAG_LINK;
|
1999-08-31 14:45:51 +00:00
|
|
|
|
1998-10-18 16:24:34 +00:00
|
|
|
CSR_WRITE_1(sc, RL_COMMAND, 0x00);
|
|
|
|
CSR_WRITE_2(sc, RL_IMR, 0x0000);
|
2008-10-25 03:06:47 +00:00
|
|
|
for (i = 0; i < RL_TIMEOUT; i++) {
|
|
|
|
DELAY(10);
|
|
|
|
if ((CSR_READ_1(sc, RL_COMMAND) &
|
|
|
|
(RL_CMD_RX_ENB | RL_CMD_TX_ENB)) == 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (i == RL_TIMEOUT)
|
|
|
|
device_printf(sc->rl_dev, "Unable to stop Tx/Rx MAC\n");
|
1998-10-18 16:24:34 +00:00
|
|
|
|
Take the support for the 8139C+/8169/8169S/8110S chips out of the
rl(4) driver and put it in a new re(4) driver. The re(4) driver shares
the if_rlreg.h file with rl(4) but is a separate module. (Ultimately
I may change this. For now, it's convenient.)
rl(4) has been modified so that it will never attach to an 8139C+
chip, leaving it to re(4) instead. Only re(4) has the PCI IDs to
match the 8169/8169S/8110S gigE chips. if_re.c contains the same
basic code that was originally bolted onto if_rl.c, with the
following updates:
- Added support for jumbo frames. Currently, there seems to be
a limit of approximately 6200 bytes for jumbo frames on transmit.
(This was determined via experimentation.) The 8169S/8110S chips
apparently are limited to 7.5K frames on transmit. This may require
some more work, though the framework to handle jumbo frames on RX
is in place: the re_rxeof() routine will gather up frames than span
multiple 2K clusters into a single mbuf list.
- Fixed bug in re_txeof(): if we reap some of the TX buffers,
but there are still some pending, re-arm the timer before exiting
re_txeof() so that another timeout interrupt will be generated, just
in case re_start() doesn't do it for us.
- Handle the 'link state changed' interrupt
- Fix a detach bug. If re(4) is loaded as a module, and you do
tcpdump -i re0, then you do 'kldunload if_re,' the system will
panic after a few seconds. This happens because ether_ifdetach()
ends up calling the BPF detach code, which notices the interface
is in promiscuous mode and tries to switch promisc mode off while
detaching the BPF listner. This ultimately results in a call
to re_ioctl() (due to SIOCSIFFLAGS), which in turn calls re_init()
to handle the IFF_PROMISC flag change. Unfortunately, calling re_init()
here turns the chip back on and restarts the 1-second timeout loop
that drives re_tick(). By the time the timeout fires, if_re.ko
has been unloaded, which results in a call to invalid code and
blows up the system.
To fix this, I cleared the IFF_UP flag before calling ether_ifdetach(),
which stops the ioctl routine from trying to reset the chip.
- Modified comments in re_rxeof() relating to the difference in
RX descriptor status bit layout between the 8139C+ and the gigE
chips. The layout is different because the frame length field
was expanded from 12 bits to 13, and they got rid of one of the
status bits to make room.
- Add diagnostic code (re_diag()) to test for the case where a user
has installed a broken 32-bit 8169 PCI NIC in a 64-bit slot. Some
NICs have the REQ64# and ACK64# lines connected even though the
board is 32-bit only (in this case, they should be pulled high).
This fools the chip into doing 64-bit DMA transfers even though
there is no 64-bit data path. To detect this, re_diag() puts the
chip into digital loopback mode and sets the receiver to promiscuous
mode, then initiates a single 64-byte packet transmission. The
frame is echoed back to the host, and if the frame contents are
intact, we know DMA is working correctly, otherwise we complain
loudly on the console and abort the device attach. (At the moment,
I don't know of any way to work around the problem other than
physically modifying the board, so until/unless I can think of a
software workaround, this will have do to.)
- Created re(4) man page
- Modified rlphy.c to allow re(4) to attach as well as rl(4).
Note that this code works for the sample 8169/Marvell 88E1000 NIC
that I have, but probably won't work for the 8169S/8110S chips.
RealTek has sent me some sample NICs, but they haven't arrived yet.
I will probably need to add an rlgphy driver to handle the on-board
PHY in the 8169S/8110S (it needs special DSP initialization).
2003-09-08 02:11:25 +00:00
|
|
|
/*
|
|
|
|
* Free the TX list buffers.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < RL_TX_LIST_CNT; i++) {
|
|
|
|
if (sc->rl_cdata.rl_tx_chain[i] != NULL) {
|
2008-10-25 02:36:08 +00:00
|
|
|
if (sc->rl_cdata.rl_tx_chain[i] != NULL) {
|
|
|
|
bus_dmamap_sync(sc->rl_cdata.rl_tx_tag,
|
|
|
|
sc->rl_cdata.rl_tx_dmamap[i],
|
|
|
|
BUS_DMASYNC_POSTWRITE);
|
|
|
|
bus_dmamap_unload(sc->rl_cdata.rl_tx_tag,
|
|
|
|
sc->rl_cdata.rl_tx_dmamap[i]);
|
|
|
|
m_freem(sc->rl_cdata.rl_tx_chain[i]);
|
|
|
|
sc->rl_cdata.rl_tx_chain[i] = NULL;
|
|
|
|
}
|
2004-07-05 02:46:42 +00:00
|
|
|
CSR_WRITE_4(sc, RL_TXADDR0 + (i * sizeof(uint32_t)),
|
2004-01-21 22:29:51 +00:00
|
|
|
0x0000000);
|
1998-10-18 16:24:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-11-23 14:27:33 +00:00
|
|
|
/*
|
|
|
|
* Device suspend routine. Stop the interface and save some PCI
|
|
|
|
* settings in case the BIOS doesn't restore them properly on
|
|
|
|
* resume.
|
|
|
|
*/
|
2002-08-23 23:49:02 +00:00
|
|
|
static int
|
2004-07-05 02:46:42 +00:00
|
|
|
rl_suspend(device_t dev)
|
2001-11-23 14:27:33 +00:00
|
|
|
{
|
|
|
|
struct rl_softc *sc;
|
|
|
|
|
|
|
|
sc = device_get_softc(dev);
|
2004-07-05 02:51:32 +00:00
|
|
|
|
|
|
|
RL_LOCK(sc);
|
2001-11-23 14:27:33 +00:00
|
|
|
rl_stop(sc);
|
2010-07-19 18:01:06 +00:00
|
|
|
rl_setwol(sc);
|
2001-11-23 14:27:33 +00:00
|
|
|
sc->suspended = 1;
|
2004-07-05 02:51:32 +00:00
|
|
|
RL_UNLOCK(sc);
|
2001-11-23 14:27:33 +00:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Device resume routine. Restore some PCI settings in case the BIOS
|
|
|
|
* doesn't, re-enable busmastering, and restart the interface if
|
|
|
|
* appropriate.
|
|
|
|
*/
|
2002-08-23 23:49:02 +00:00
|
|
|
static int
|
2004-07-05 02:46:42 +00:00
|
|
|
rl_resume(device_t dev)
|
2001-11-23 14:27:33 +00:00
|
|
|
{
|
|
|
|
struct rl_softc *sc;
|
|
|
|
struct ifnet *ifp;
|
2010-07-19 18:01:06 +00:00
|
|
|
int pmc;
|
|
|
|
uint16_t pmstat;
|
2001-11-23 14:27:33 +00:00
|
|
|
|
|
|
|
sc = device_get_softc(dev);
|
2005-06-10 16:49:24 +00:00
|
|
|
ifp = sc->rl_ifp;
|
2001-11-23 14:27:33 +00:00
|
|
|
|
2004-07-09 00:07:06 +00:00
|
|
|
RL_LOCK(sc);
|
|
|
|
|
2010-07-19 18:01:06 +00:00
|
|
|
if ((ifp->if_capabilities & IFCAP_WOL) != 0 &&
|
2011-03-23 13:10:15 +00:00
|
|
|
pci_find_cap(sc->rl_dev, PCIY_PMG, &pmc) == 0) {
|
2010-07-19 18:01:06 +00:00
|
|
|
/* Disable PME and clear PME status. */
|
|
|
|
pmstat = pci_read_config(sc->rl_dev,
|
|
|
|
pmc + PCIR_POWER_STATUS, 2);
|
|
|
|
if ((pmstat & PCIM_PSTAT_PMEENABLE) != 0) {
|
|
|
|
pmstat &= ~PCIM_PSTAT_PMEENABLE;
|
|
|
|
pci_write_config(sc->rl_dev,
|
|
|
|
pmc + PCIR_POWER_STATUS, pmstat, 2);
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Clear WOL matching such that normal Rx filtering
|
|
|
|
* wouldn't interfere with WOL patterns.
|
|
|
|
*/
|
|
|
|
rl_clrwol(sc);
|
|
|
|
}
|
|
|
|
|
2003-01-11 16:11:21 +00:00
|
|
|
/* reinitialize interface if necessary */
|
|
|
|
if (ifp->if_flags & IFF_UP)
|
2004-07-09 00:07:06 +00:00
|
|
|
rl_init_locked(sc);
|
2001-11-23 14:27:33 +00:00
|
|
|
|
|
|
|
sc->suspended = 0;
|
2004-07-09 00:07:06 +00:00
|
|
|
|
2004-07-05 02:51:32 +00:00
|
|
|
RL_UNLOCK(sc);
|
2001-11-23 14:27:33 +00:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1998-10-18 16:24:34 +00:00
|
|
|
/*
|
|
|
|
* Stop all chip I/O so that the kernel's probe routines don't
|
|
|
|
* get confused by errant DMAs when rebooting.
|
|
|
|
*/
|
2007-11-22 02:45:00 +00:00
|
|
|
static int
|
2004-07-05 02:46:42 +00:00
|
|
|
rl_shutdown(device_t dev)
|
1998-10-18 16:24:34 +00:00
|
|
|
{
|
1999-08-31 14:45:51 +00:00
|
|
|
struct rl_softc *sc;
|
|
|
|
|
|
|
|
sc = device_get_softc(dev);
|
2004-07-05 02:51:32 +00:00
|
|
|
|
|
|
|
RL_LOCK(sc);
|
1998-10-18 16:24:34 +00:00
|
|
|
rl_stop(sc);
|
2010-07-19 18:01:06 +00:00
|
|
|
/*
|
|
|
|
* Mark interface as down since otherwise we will panic if
|
|
|
|
* interrupt comes in later on, which can happen in some
|
|
|
|
* cases.
|
|
|
|
*/
|
|
|
|
sc->rl_ifp->if_flags &= ~IFF_UP;
|
|
|
|
rl_setwol(sc);
|
2004-07-05 02:51:32 +00:00
|
|
|
RL_UNLOCK(sc);
|
2007-11-22 02:45:00 +00:00
|
|
|
|
|
|
|
return (0);
|
1998-10-18 16:24:34 +00:00
|
|
|
}
|
2010-07-19 18:01:06 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
rl_setwol(struct rl_softc *sc)
|
|
|
|
{
|
|
|
|
struct ifnet *ifp;
|
|
|
|
int pmc;
|
|
|
|
uint16_t pmstat;
|
|
|
|
uint8_t v;
|
|
|
|
|
|
|
|
RL_LOCK_ASSERT(sc);
|
|
|
|
|
|
|
|
ifp = sc->rl_ifp;
|
|
|
|
if ((ifp->if_capabilities & IFCAP_WOL) == 0)
|
|
|
|
return;
|
2011-03-23 13:10:15 +00:00
|
|
|
if (pci_find_cap(sc->rl_dev, PCIY_PMG, &pmc) != 0)
|
2010-07-19 18:01:06 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
/* Enable config register write. */
|
|
|
|
CSR_WRITE_1(sc, RL_EECMD, RL_EE_MODE);
|
|
|
|
|
|
|
|
/* Enable PME. */
|
2012-02-25 04:54:51 +00:00
|
|
|
v = CSR_READ_1(sc, sc->rl_cfg1);
|
2010-07-19 18:01:06 +00:00
|
|
|
v &= ~RL_CFG1_PME;
|
|
|
|
if ((ifp->if_capenable & IFCAP_WOL) != 0)
|
|
|
|
v |= RL_CFG1_PME;
|
2012-02-25 04:54:51 +00:00
|
|
|
CSR_WRITE_1(sc, sc->rl_cfg1, v);
|
2010-07-19 18:01:06 +00:00
|
|
|
|
2012-02-25 04:54:51 +00:00
|
|
|
v = CSR_READ_1(sc, sc->rl_cfg3);
|
2010-07-19 18:01:06 +00:00
|
|
|
v &= ~(RL_CFG3_WOL_LINK | RL_CFG3_WOL_MAGIC);
|
|
|
|
if ((ifp->if_capenable & IFCAP_WOL_MAGIC) != 0)
|
|
|
|
v |= RL_CFG3_WOL_MAGIC;
|
2012-02-25 04:54:51 +00:00
|
|
|
CSR_WRITE_1(sc, sc->rl_cfg3, v);
|
2010-07-19 18:01:06 +00:00
|
|
|
|
2012-02-25 04:54:51 +00:00
|
|
|
v = CSR_READ_1(sc, sc->rl_cfg5);
|
2010-07-19 18:01:06 +00:00
|
|
|
v &= ~(RL_CFG5_WOL_BCAST | RL_CFG5_WOL_MCAST | RL_CFG5_WOL_UCAST);
|
|
|
|
v &= ~RL_CFG5_WOL_LANWAKE;
|
|
|
|
if ((ifp->if_capenable & IFCAP_WOL_UCAST) != 0)
|
|
|
|
v |= RL_CFG5_WOL_UCAST;
|
|
|
|
if ((ifp->if_capenable & IFCAP_WOL_MCAST) != 0)
|
|
|
|
v |= RL_CFG5_WOL_MCAST | RL_CFG5_WOL_BCAST;
|
|
|
|
if ((ifp->if_capenable & IFCAP_WOL) != 0)
|
|
|
|
v |= RL_CFG5_WOL_LANWAKE;
|
2012-02-25 04:54:51 +00:00
|
|
|
CSR_WRITE_1(sc, sc->rl_cfg5, v);
|
|
|
|
|
|
|
|
/* Config register write done. */
|
|
|
|
CSR_WRITE_1(sc, RL_EECMD, RL_EEMODE_OFF);
|
|
|
|
|
2010-07-19 18:01:06 +00:00
|
|
|
/* Request PME if WOL is requested. */
|
|
|
|
pmstat = pci_read_config(sc->rl_dev, pmc + PCIR_POWER_STATUS, 2);
|
|
|
|
pmstat &= ~(PCIM_PSTAT_PME | PCIM_PSTAT_PMEENABLE);
|
|
|
|
if ((ifp->if_capenable & IFCAP_WOL) != 0)
|
|
|
|
pmstat |= PCIM_PSTAT_PME | PCIM_PSTAT_PMEENABLE;
|
|
|
|
pci_write_config(sc->rl_dev, pmc + PCIR_POWER_STATUS, pmstat, 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
rl_clrwol(struct rl_softc *sc)
|
|
|
|
{
|
|
|
|
struct ifnet *ifp;
|
|
|
|
uint8_t v;
|
|
|
|
|
|
|
|
ifp = sc->rl_ifp;
|
|
|
|
if ((ifp->if_capabilities & IFCAP_WOL) == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Enable config register write. */
|
|
|
|
CSR_WRITE_1(sc, RL_EECMD, RL_EE_MODE);
|
|
|
|
|
2012-02-25 04:54:51 +00:00
|
|
|
v = CSR_READ_1(sc, sc->rl_cfg3);
|
2010-07-19 18:01:06 +00:00
|
|
|
v &= ~(RL_CFG3_WOL_LINK | RL_CFG3_WOL_MAGIC);
|
2012-02-25 04:54:51 +00:00
|
|
|
CSR_WRITE_1(sc, sc->rl_cfg3, v);
|
2010-07-19 18:01:06 +00:00
|
|
|
|
|
|
|
/* Config register write done. */
|
|
|
|
CSR_WRITE_1(sc, RL_EECMD, RL_EEMODE_OFF);
|
|
|
|
|
2012-02-25 04:54:51 +00:00
|
|
|
v = CSR_READ_1(sc, sc->rl_cfg5);
|
2010-07-19 18:01:06 +00:00
|
|
|
v &= ~(RL_CFG5_WOL_BCAST | RL_CFG5_WOL_MCAST | RL_CFG5_WOL_UCAST);
|
|
|
|
v &= ~RL_CFG5_WOL_LANWAKE;
|
2012-02-25 04:54:51 +00:00
|
|
|
CSR_WRITE_1(sc, sc->rl_cfg5, v);
|
2010-07-19 18:01:06 +00:00
|
|
|
}
|