2005-01-07 02:29:27 +00:00
|
|
|
/*-
|
1999-12-04 17:41:31 +00:00
|
|
|
* Copyright (c) 1997, 1998, 1999
|
|
|
|
* Bill Paul <wpaul@ee.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$");
|
|
|
|
|
1999-12-04 17:41:31 +00:00
|
|
|
/*
|
|
|
|
* DEC "tulip" clone ethernet driver. Supports the DEC/Intel 21143
|
|
|
|
* series chips and several workalikes including the following:
|
|
|
|
*
|
2000-07-17 19:27:41 +00:00
|
|
|
* Macronix 98713/98715/98725/98727/98732 PMAC (www.macronix.com)
|
1999-12-04 17:41:31 +00:00
|
|
|
* Macronix/Lite-On 82c115 PNIC II (www.macronix.com)
|
|
|
|
* Lite-On 82c168/82c169 PNIC (www.litecom.com)
|
|
|
|
* ASIX Electronics AX88140A (www.asix.com.tw)
|
|
|
|
* ASIX Electronics AX88141 (www.asix.com.tw)
|
|
|
|
* ADMtek AL981 (www.admtek.com.tw)
|
|
|
|
* ADMtek AN985 (www.admtek.com.tw)
|
2003-07-19 06:01:15 +00:00
|
|
|
* Netgear FA511 (www.netgear.com) Appears to be rebadged ADMTek AN985
|
2000-01-19 19:03:08 +00:00
|
|
|
* Davicom DM9100, DM9102, DM9102A (www.davicom8.com)
|
2000-06-11 11:54:52 +00:00
|
|
|
* Accton EN1217 (www.accton.com)
|
2000-10-19 08:34:32 +00:00
|
|
|
* Xircom X3201 (www.xircom.com)
|
2000-10-28 09:00:20 +00:00
|
|
|
* Abocom FE2500
|
2001-09-04 17:10:11 +00:00
|
|
|
* Conexant LANfinity (www.conexant.com)
|
2003-05-12 19:50:21 +00:00
|
|
|
* 3Com OfficeConnect 10/100B 3CSOHO100B (www.3com.com)
|
1999-12-04 17:41:31 +00:00
|
|
|
*
|
|
|
|
* Datasheets for the 21143 are available at developer.intel.com.
|
|
|
|
* Datasheets for the clone parts can be found at their respective sites.
|
|
|
|
* (Except for the PNIC; see www.freebsd.org/~wpaul/PNIC/pnic.ps.gz.)
|
|
|
|
* The PNIC II is essentially a Macronix 98715A chip; the only difference
|
|
|
|
* worth noting is that its multicast hash table is only 128 bits wide
|
|
|
|
* instead of 512.
|
|
|
|
*
|
|
|
|
* Written by Bill Paul <wpaul@ee.columbia.edu>
|
|
|
|
* Electrical Engineering Department
|
|
|
|
* Columbia University, New York City
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* The Intel 21143 is the successor to the DEC 21140. It is basically
|
|
|
|
* the same as the 21140 but with a few new features. The 21143 supports
|
|
|
|
* three kinds of media attachments:
|
|
|
|
*
|
|
|
|
* o MII port, for 10Mbps and 100Mbps support and NWAY
|
|
|
|
* autonegotiation provided by an external PHY.
|
|
|
|
* o SYM port, for symbol mode 100Mbps support.
|
|
|
|
* o 10baseT port.
|
|
|
|
* o AUI/BNC port.
|
|
|
|
*
|
|
|
|
* The 100Mbps SYM port and 10baseT port can be used together in
|
|
|
|
* combination with the internal NWAY support to create a 10/100
|
|
|
|
* autosensing configuration.
|
|
|
|
*
|
|
|
|
* Note that not all tulip workalikes are handled in this driver: we only
|
|
|
|
* deal with those which are relatively well behaved. The Winbond is
|
|
|
|
* handled separately due to its different register offsets and the
|
|
|
|
* special handling needed for its various bugs. The PNIC is handled
|
|
|
|
* here, but I'm not thrilled about it.
|
|
|
|
*
|
|
|
|
* All of the workalike chips use some form of MII transceiver support
|
|
|
|
* with the exception of the Macronix chips, which also have a SYM port.
|
|
|
|
* The ASIX AX88140A is also documented to have a SYM port, but all
|
|
|
|
* the cards I've seen use an MII transceiver, probably because the
|
|
|
|
* AX88140A doesn't support internal NWAY.
|
|
|
|
*/
|
|
|
|
|
2005-10-05 10:09:17 +00:00
|
|
|
#ifdef HAVE_KERNEL_OPTION_HEADERS
|
|
|
|
#include "opt_device_polling.h"
|
|
|
|
#endif
|
|
|
|
|
1999-12-04 17:41:31 +00:00
|
|
|
#include <sys/param.h>
|
2003-07-09 15:03:10 +00:00
|
|
|
#include <sys/endian.h>
|
1999-12-04 17:41:31 +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>
|
1999-12-04 17:41:31 +00:00
|
|
|
#include <sys/socket.h>
|
For i386 architecture, remove an expensive m_devget() (and the
underlying unaligned bcopy) on incoming packets that are already
available (albeit unaligned) in a buffer.
The performance improvement varies, depending on CPU and memory
speed, but can be quite large especially on slow CPUs. I have seen
over 50% increase on forwarding speed on the sis driver for the
486/133 (embedded systems), which does exactly the same thing.
The behaviour is controlled by a sysctl variable, hw.dc_quick which
defaults to 1. Set it to 0 to restore the old behaviour.
After running a few experiments (in userland, though) I am convinced
that doing the m_devget() is detrimental to performance in almost
all cases.
Even if your CPU has degraded performance with misaligned data,
the bcopy() in the driver has the same overhead due to misaligment
as the one that you save in the uiomove(), plus you do one extra
copy and pollute the cache.
But more often than not, you do not even have to touch the payload,
e.g. when you are forwarding packets, and even in the often-cited
case of NFS, you often end up passing a pointer to the payload to
the disk controller.
In any case, you can play with the sysctl variable to toggle between
the two behaviours, and see if it makes a difference.
MFC-after: 3 days
2001-11-29 22:46:48 +00:00
|
|
|
#include <sys/sysctl.h>
|
1999-12-04 17:41:31 +00:00
|
|
|
|
|
|
|
#include <net/if.h>
|
|
|
|
#include <net/if_arp.h>
|
|
|
|
#include <net/ethernet.h>
|
|
|
|
#include <net/if_dl.h>
|
|
|
|
#include <net/if_media.h>
|
2002-01-16 16:33:58 +00:00
|
|
|
#include <net/if_types.h>
|
|
|
|
#include <net/if_vlan_var.h>
|
1999-12-04 17:41:31 +00:00
|
|
|
|
|
|
|
#include <net/bpf.h>
|
|
|
|
|
|
|
|
#include <machine/bus.h>
|
|
|
|
#include <machine/resource.h>
|
|
|
|
#include <sys/bus.h>
|
|
|
|
#include <sys/rman.h>
|
|
|
|
|
|
|
|
#include <dev/mii/mii.h>
|
|
|
|
#include <dev/mii/miivar.h>
|
|
|
|
|
2003-08-22 07:20:27 +00:00
|
|
|
#include <dev/pci/pcireg.h>
|
|
|
|
#include <dev/pci/pcivar.h>
|
1999-12-04 17:41:31 +00:00
|
|
|
|
|
|
|
#define DC_USEIOSPACE
|
2000-10-05 17:36:14 +00:00
|
|
|
#ifdef __alpha__
|
|
|
|
#define SRM_MEDIA
|
|
|
|
#endif
|
1999-12-04 17:41:31 +00:00
|
|
|
|
2005-10-18 06:09:42 +00:00
|
|
|
#include <dev/dc/if_dcreg.h>
|
1999-12-04 17:41:31 +00:00
|
|
|
|
2004-01-08 19:08:27 +00:00
|
|
|
#ifdef __sparc64__
|
|
|
|
#include <dev/ofw/openfirm.h>
|
|
|
|
#include <machine/ofw_machdep.h>
|
|
|
|
#endif
|
|
|
|
|
2003-04-15 06:37:30 +00:00
|
|
|
MODULE_DEPEND(dc, pci, 1, 1, 1);
|
|
|
|
MODULE_DEPEND(dc, ether, 1, 1, 1);
|
2000-04-29 13:41:57 +00:00
|
|
|
MODULE_DEPEND(dc, miibus, 1, 1, 1);
|
|
|
|
|
2005-08-29 18:45:21 +00:00
|
|
|
/*
|
|
|
|
* "device miibus" is required in kernel config. See GENERIC if you get
|
|
|
|
* errors here.
|
|
|
|
*/
|
1999-12-04 17:41:31 +00:00
|
|
|
#include "miibus_if.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Various supported device vendors/types and their names.
|
|
|
|
*/
|
|
|
|
static struct dc_type dc_devs[] = {
|
|
|
|
{ DC_VENDORID_DEC, DC_DEVICEID_21143,
|
|
|
|
"Intel 21143 10/100BaseTX" },
|
2003-01-09 20:51:39 +00:00
|
|
|
{ DC_VENDORID_DAVICOM, DC_DEVICEID_DM9009,
|
|
|
|
"Davicom DM9009 10/100BaseTX" },
|
1999-12-04 17:41:31 +00:00
|
|
|
{ DC_VENDORID_DAVICOM, DC_DEVICEID_DM9100,
|
|
|
|
"Davicom DM9100 10/100BaseTX" },
|
|
|
|
{ DC_VENDORID_DAVICOM, DC_DEVICEID_DM9102,
|
|
|
|
"Davicom DM9102 10/100BaseTX" },
|
2000-01-19 19:03:08 +00:00
|
|
|
{ DC_VENDORID_DAVICOM, DC_DEVICEID_DM9102,
|
|
|
|
"Davicom DM9102A 10/100BaseTX" },
|
1999-12-04 17:41:31 +00:00
|
|
|
{ DC_VENDORID_ADMTEK, DC_DEVICEID_AL981,
|
|
|
|
"ADMtek AL981 10/100BaseTX" },
|
|
|
|
{ DC_VENDORID_ADMTEK, DC_DEVICEID_AN985,
|
|
|
|
"ADMtek AN985 10/100BaseTX" },
|
2003-06-08 10:11:55 +00:00
|
|
|
{ DC_VENDORID_ADMTEK, DC_DEVICEID_ADM9511,
|
|
|
|
"ADMtek ADM9511 10/100BaseTX" },
|
|
|
|
{ DC_VENDORID_ADMTEK, DC_DEVICEID_ADM9513,
|
|
|
|
"ADMtek ADM9513 10/100BaseTX" },
|
2004-07-05 22:35:18 +00:00
|
|
|
{ DC_VENDORID_ADMTEK, DC_DEVICEID_FA511,
|
|
|
|
"Netgear FA511 10/100BaseTX" },
|
1999-12-04 17:41:31 +00:00
|
|
|
{ DC_VENDORID_ASIX, DC_DEVICEID_AX88140A,
|
|
|
|
"ASIX AX88140A 10/100BaseTX" },
|
|
|
|
{ DC_VENDORID_ASIX, DC_DEVICEID_AX88140A,
|
|
|
|
"ASIX AX88141 10/100BaseTX" },
|
|
|
|
{ DC_VENDORID_MX, DC_DEVICEID_98713,
|
|
|
|
"Macronix 98713 10/100BaseTX" },
|
|
|
|
{ DC_VENDORID_MX, DC_DEVICEID_98713,
|
|
|
|
"Macronix 98713A 10/100BaseTX" },
|
|
|
|
{ DC_VENDORID_CP, DC_DEVICEID_98713_CP,
|
|
|
|
"Compex RL100-TX 10/100BaseTX" },
|
|
|
|
{ DC_VENDORID_CP, DC_DEVICEID_98713_CP,
|
|
|
|
"Compex RL100-TX 10/100BaseTX" },
|
|
|
|
{ DC_VENDORID_MX, DC_DEVICEID_987x5,
|
|
|
|
"Macronix 98715/98715A 10/100BaseTX" },
|
2000-07-15 17:54:30 +00:00
|
|
|
{ DC_VENDORID_MX, DC_DEVICEID_987x5,
|
|
|
|
"Macronix 98715AEC-C 10/100BaseTX" },
|
1999-12-04 17:41:31 +00:00
|
|
|
{ DC_VENDORID_MX, DC_DEVICEID_987x5,
|
|
|
|
"Macronix 98725 10/100BaseTX" },
|
2000-07-17 19:27:41 +00:00
|
|
|
{ DC_VENDORID_MX, DC_DEVICEID_98727,
|
|
|
|
"Macronix 98727/98732 10/100BaseTX" },
|
1999-12-04 17:41:31 +00:00
|
|
|
{ DC_VENDORID_LO, DC_DEVICEID_82C115,
|
|
|
|
"LC82C115 PNIC II 10/100BaseTX" },
|
|
|
|
{ DC_VENDORID_LO, DC_DEVICEID_82C168,
|
|
|
|
"82c168 PNIC 10/100BaseTX" },
|
|
|
|
{ DC_VENDORID_LO, DC_DEVICEID_82C168,
|
|
|
|
"82c169 PNIC 10/100BaseTX" },
|
2000-06-11 11:54:52 +00:00
|
|
|
{ DC_VENDORID_ACCTON, DC_DEVICEID_EN1217,
|
|
|
|
"Accton EN1217 10/100BaseTX" },
|
2000-11-14 19:35:22 +00:00
|
|
|
{ DC_VENDORID_ACCTON, DC_DEVICEID_EN2242,
|
|
|
|
"Accton EN2242 MiniPCI 10/100BaseTX" },
|
2002-09-04 18:14:17 +00:00
|
|
|
{ DC_VENDORID_XIRCOM, DC_DEVICEID_X3201,
|
2000-10-19 08:34:32 +00:00
|
|
|
"Xircom X3201 10/100BaseTX" },
|
2000-10-28 09:00:20 +00:00
|
|
|
{ DC_VENDORID_ABOCOM, DC_DEVICEID_FE2500,
|
|
|
|
"Abocom FE2500 10/100BaseTX" },
|
2003-12-06 02:29:31 +00:00
|
|
|
{ DC_VENDORID_ABOCOM, DC_DEVICEID_FE2500MX,
|
|
|
|
"Abocom FE2500MX 10/100BaseTX" },
|
2001-09-04 17:10:11 +00:00
|
|
|
{ DC_VENDORID_CONEXANT, DC_DEVICEID_RS7112,
|
|
|
|
"Conexant LANfinity MiniPCI 10/100BaseTX" },
|
2003-01-10 05:37:15 +00:00
|
|
|
{ DC_VENDORID_HAWKING, DC_DEVICEID_HAWKING_PN672TX,
|
|
|
|
"Hawking CB102 CardBus 10/100" },
|
2003-04-18 15:42:25 +00:00
|
|
|
{ DC_VENDORID_PLANEX, DC_DEVICEID_FNW3602T,
|
|
|
|
"PlaneX FNW-3602-T CardBus 10/100" },
|
2003-05-12 19:50:21 +00:00
|
|
|
{ DC_VENDORID_3COM, DC_DEVICEID_3CSOHOB,
|
|
|
|
"3Com OfficeConnect 10/100B" },
|
2003-07-10 18:43:17 +00:00
|
|
|
{ DC_VENDORID_MICROSOFT, DC_DEVICEID_MSMN120,
|
|
|
|
"Microsoft MN-120 CardBus 10/100" },
|
|
|
|
{ DC_VENDORID_MICROSOFT, DC_DEVICEID_MSMN130,
|
|
|
|
"Microsoft MN-130 10/100" },
|
|
|
|
{ DC_VENDORID_MICROSOFT, DC_DEVICEID_MSMN130_FAKE,
|
|
|
|
"Microsoft MN-130 10/100" },
|
1999-12-04 17:41:31 +00:00
|
|
|
{ 0, 0, NULL }
|
|
|
|
};
|
|
|
|
|
2005-02-24 22:33:05 +00:00
|
|
|
static int dc_probe(device_t);
|
|
|
|
static int dc_attach(device_t);
|
|
|
|
static int dc_detach(device_t);
|
|
|
|
static int dc_suspend(device_t);
|
|
|
|
static int dc_resume(device_t);
|
|
|
|
static struct dc_type *dc_devtype(device_t);
|
|
|
|
static int dc_newbuf(struct dc_softc *, int, int);
|
|
|
|
static int dc_encap(struct dc_softc *, struct mbuf **);
|
|
|
|
static void dc_pnic_rx_bug_war(struct dc_softc *, int);
|
|
|
|
static int dc_rx_resync(struct dc_softc *);
|
|
|
|
static void dc_rxeof(struct dc_softc *);
|
|
|
|
static void dc_txeof(struct dc_softc *);
|
|
|
|
static void dc_tick(void *);
|
|
|
|
static void dc_tx_underrun(struct dc_softc *);
|
|
|
|
static void dc_intr(void *);
|
|
|
|
static void dc_start(struct ifnet *);
|
2005-08-18 19:10:07 +00:00
|
|
|
static void dc_start_locked(struct ifnet *);
|
2005-02-24 22:33:05 +00:00
|
|
|
static int dc_ioctl(struct ifnet *, u_long, caddr_t);
|
|
|
|
static void dc_init(void *);
|
2005-08-18 19:10:07 +00:00
|
|
|
static void dc_init_locked(struct dc_softc *);
|
2005-02-24 22:33:05 +00:00
|
|
|
static void dc_stop(struct dc_softc *);
|
|
|
|
static void dc_watchdog(struct ifnet *);
|
|
|
|
static void dc_shutdown(device_t);
|
|
|
|
static int dc_ifmedia_upd(struct ifnet *);
|
|
|
|
static void dc_ifmedia_sts(struct ifnet *, struct ifmediareq *);
|
1999-12-04 17:41:31 +00:00
|
|
|
|
2005-02-24 22:33:05 +00:00
|
|
|
static void dc_delay(struct dc_softc *);
|
|
|
|
static void dc_eeprom_idle(struct dc_softc *);
|
|
|
|
static void dc_eeprom_putbyte(struct dc_softc *, int);
|
|
|
|
static void dc_eeprom_getword(struct dc_softc *, int, u_int16_t *);
|
|
|
|
static void dc_eeprom_getword_pnic(struct dc_softc *, int, u_int16_t *);
|
|
|
|
static void dc_eeprom_getword_xircom(struct dc_softc *, int, u_int16_t *);
|
|
|
|
static void dc_eeprom_width(struct dc_softc *);
|
|
|
|
static void dc_read_eeprom(struct dc_softc *, caddr_t, int, int, int);
|
1999-12-04 17:41:31 +00:00
|
|
|
|
2005-02-24 22:33:05 +00:00
|
|
|
static void dc_mii_writebit(struct dc_softc *, int);
|
|
|
|
static int dc_mii_readbit(struct dc_softc *);
|
|
|
|
static void dc_mii_sync(struct dc_softc *);
|
|
|
|
static void dc_mii_send(struct dc_softc *, u_int32_t, int);
|
|
|
|
static int dc_mii_readreg(struct dc_softc *, struct dc_mii_frame *);
|
|
|
|
static int dc_mii_writereg(struct dc_softc *, struct dc_mii_frame *);
|
|
|
|
static int dc_miibus_readreg(device_t, int, int);
|
|
|
|
static int dc_miibus_writereg(device_t, int, int, int);
|
|
|
|
static void dc_miibus_statchg(device_t);
|
|
|
|
static void dc_miibus_mediainit(device_t);
|
1999-12-04 17:41:31 +00:00
|
|
|
|
2005-02-24 22:33:05 +00:00
|
|
|
static void dc_setcfg(struct dc_softc *, int);
|
|
|
|
static uint32_t dc_mchash_le(struct dc_softc *, const uint8_t *);
|
|
|
|
static uint32_t dc_mchash_be(const uint8_t *);
|
|
|
|
static void dc_setfilt_21143(struct dc_softc *);
|
|
|
|
static void dc_setfilt_asix(struct dc_softc *);
|
|
|
|
static void dc_setfilt_admtek(struct dc_softc *);
|
|
|
|
static void dc_setfilt_xircom(struct dc_softc *);
|
1999-12-04 17:41:31 +00:00
|
|
|
|
2005-02-24 22:33:05 +00:00
|
|
|
static void dc_setfilt(struct dc_softc *);
|
1999-12-04 17:41:31 +00:00
|
|
|
|
2005-02-24 22:33:05 +00:00
|
|
|
static void dc_reset(struct dc_softc *);
|
|
|
|
static int dc_list_rx_init(struct dc_softc *);
|
|
|
|
static int dc_list_tx_init(struct dc_softc *);
|
1999-12-04 17:41:31 +00:00
|
|
|
|
2005-02-24 22:33:05 +00:00
|
|
|
static void dc_read_srom(struct dc_softc *, int);
|
|
|
|
static void dc_parse_21143_srom(struct dc_softc *);
|
|
|
|
static void dc_decode_leaf_sia(struct dc_softc *, struct dc_eblock_sia *);
|
|
|
|
static void dc_decode_leaf_mii(struct dc_softc *, struct dc_eblock_mii *);
|
|
|
|
static void dc_decode_leaf_sym(struct dc_softc *, struct dc_eblock_sym *);
|
|
|
|
static void dc_apply_fixup(struct dc_softc *, int);
|
2000-10-05 17:36:14 +00:00
|
|
|
|
2005-02-24 22:33:05 +00:00
|
|
|
static void dc_dma_map_txbuf(void *, bus_dma_segment_t *, int, bus_size_t, int);
|
|
|
|
static void dc_dma_map_rxbuf(void *, bus_dma_segment_t *, int, bus_size_t, int);
|
2003-07-06 21:45:31 +00:00
|
|
|
|
1999-12-04 17:41:31 +00:00
|
|
|
#ifdef DC_USEIOSPACE
|
|
|
|
#define DC_RES SYS_RES_IOPORT
|
|
|
|
#define DC_RID DC_PCI_CFBIO
|
|
|
|
#else
|
|
|
|
#define DC_RES SYS_RES_MEMORY
|
|
|
|
#define DC_RID DC_PCI_CFBMA
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static device_method_t dc_methods[] = {
|
|
|
|
/* Device interface */
|
|
|
|
DEVMETHOD(device_probe, dc_probe),
|
|
|
|
DEVMETHOD(device_attach, dc_attach),
|
|
|
|
DEVMETHOD(device_detach, dc_detach),
|
2002-05-06 10:55:42 +00:00
|
|
|
DEVMETHOD(device_suspend, dc_suspend),
|
|
|
|
DEVMETHOD(device_resume, dc_resume),
|
1999-12-04 17:41:31 +00:00
|
|
|
DEVMETHOD(device_shutdown, dc_shutdown),
|
|
|
|
|
|
|
|
/* bus interface */
|
|
|
|
DEVMETHOD(bus_print_child, bus_generic_print_child),
|
|
|
|
DEVMETHOD(bus_driver_added, bus_generic_driver_added),
|
|
|
|
|
|
|
|
/* MII interface */
|
|
|
|
DEVMETHOD(miibus_readreg, dc_miibus_readreg),
|
|
|
|
DEVMETHOD(miibus_writereg, dc_miibus_writereg),
|
|
|
|
DEVMETHOD(miibus_statchg, dc_miibus_statchg),
|
2000-01-24 17:19:37 +00:00
|
|
|
DEVMETHOD(miibus_mediainit, dc_miibus_mediainit),
|
1999-12-04 17:41:31 +00:00
|
|
|
|
|
|
|
{ 0, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
static driver_t dc_driver = {
|
|
|
|
"dc",
|
|
|
|
dc_methods,
|
|
|
|
sizeof(struct dc_softc)
|
|
|
|
};
|
|
|
|
|
|
|
|
static devclass_t dc_devclass;
|
For i386 architecture, remove an expensive m_devget() (and the
underlying unaligned bcopy) on incoming packets that are already
available (albeit unaligned) in a buffer.
The performance improvement varies, depending on CPU and memory
speed, but can be quite large especially on slow CPUs. I have seen
over 50% increase on forwarding speed on the sis driver for the
486/133 (embedded systems), which does exactly the same thing.
The behaviour is controlled by a sysctl variable, hw.dc_quick which
defaults to 1. Set it to 0 to restore the old behaviour.
After running a few experiments (in userland, though) I am convinced
that doing the m_devget() is detrimental to performance in almost
all cases.
Even if your CPU has degraded performance with misaligned data,
the bcopy() in the driver has the same overhead due to misaligment
as the one that you save in the uiomove(), plus you do one extra
copy and pollute the cache.
But more often than not, you do not even have to touch the payload,
e.g. when you are forwarding packets, and even in the often-cited
case of NFS, you often end up passing a pointer to the payload to
the disk controller.
In any case, you can play with the sysctl variable to toggle between
the two behaviours, and see if it makes a difference.
MFC-after: 3 days
2001-11-29 22:46:48 +00:00
|
|
|
#ifdef __i386__
|
2003-06-01 19:26:34 +00:00
|
|
|
static int dc_quick = 1;
|
2003-07-06 14:36:33 +00:00
|
|
|
SYSCTL_INT(_hw, OID_AUTO, dc_quick, CTLFLAG_RW, &dc_quick, 0,
|
2003-11-02 21:43:29 +00:00
|
|
|
"do not m_devget() in dc driver");
|
For i386 architecture, remove an expensive m_devget() (and the
underlying unaligned bcopy) on incoming packets that are already
available (albeit unaligned) in a buffer.
The performance improvement varies, depending on CPU and memory
speed, but can be quite large especially on slow CPUs. I have seen
over 50% increase on forwarding speed on the sis driver for the
486/133 (embedded systems), which does exactly the same thing.
The behaviour is controlled by a sysctl variable, hw.dc_quick which
defaults to 1. Set it to 0 to restore the old behaviour.
After running a few experiments (in userland, though) I am convinced
that doing the m_devget() is detrimental to performance in almost
all cases.
Even if your CPU has degraded performance with misaligned data,
the bcopy() in the driver has the same overhead due to misaligment
as the one that you save in the uiomove(), plus you do one extra
copy and pollute the cache.
But more often than not, you do not even have to touch the payload,
e.g. when you are forwarding packets, and even in the often-cited
case of NFS, you often end up passing a pointer to the payload to
the disk controller.
In any case, you can play with the sysctl variable to toggle between
the two behaviours, and see if it makes a difference.
MFC-after: 3 days
2001-11-29 22:46:48 +00:00
|
|
|
#endif
|
1999-12-04 17:41:31 +00:00
|
|
|
|
2003-11-28 05:28:29 +00:00
|
|
|
DRIVER_MODULE(dc, cardbus, dc_driver, dc_devclass, 0, 0);
|
2003-04-15 06:37:30 +00:00
|
|
|
DRIVER_MODULE(dc, pci, dc_driver, dc_devclass, 0, 0);
|
1999-12-04 17:41:31 +00:00
|
|
|
DRIVER_MODULE(miibus, dc, miibus_driver, miibus_devclass, 0, 0);
|
|
|
|
|
|
|
|
#define DC_SETBIT(sc, reg, x) \
|
|
|
|
CSR_WRITE_4(sc, reg, CSR_READ_4(sc, reg) | (x))
|
|
|
|
|
|
|
|
#define DC_CLRBIT(sc, reg, x) \
|
|
|
|
CSR_WRITE_4(sc, reg, CSR_READ_4(sc, reg) & ~(x))
|
|
|
|
|
|
|
|
#define SIO_SET(x) DC_SETBIT(sc, DC_SIO, (x))
|
|
|
|
#define SIO_CLR(x) DC_CLRBIT(sc, DC_SIO, (x))
|
|
|
|
|
2002-08-23 23:49:02 +00:00
|
|
|
static void
|
2003-06-01 19:26:34 +00:00
|
|
|
dc_delay(struct dc_softc *sc)
|
1999-12-04 17:41:31 +00:00
|
|
|
{
|
2003-06-01 19:26:34 +00:00
|
|
|
int idx;
|
1999-12-04 17:41:31 +00:00
|
|
|
|
|
|
|
for (idx = (300 / 33) + 1; idx > 0; idx--)
|
|
|
|
CSR_READ_4(sc, DC_BUSCTL);
|
|
|
|
}
|
|
|
|
|
2002-10-16 09:04:52 +00:00
|
|
|
static void
|
2003-06-01 19:26:34 +00:00
|
|
|
dc_eeprom_width(struct dc_softc *sc)
|
2002-10-07 05:26:35 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* Force EEPROM to idle state. */
|
|
|
|
dc_eeprom_idle(sc);
|
|
|
|
|
|
|
|
/* Enter EEPROM access mode. */
|
|
|
|
CSR_WRITE_4(sc, DC_SIO, DC_SIO_EESEL);
|
|
|
|
dc_delay(sc);
|
|
|
|
DC_SETBIT(sc, DC_SIO, DC_SIO_ROMCTL_READ);
|
|
|
|
dc_delay(sc);
|
|
|
|
DC_CLRBIT(sc, DC_SIO, DC_SIO_EE_CLK);
|
|
|
|
dc_delay(sc);
|
|
|
|
DC_SETBIT(sc, DC_SIO, DC_SIO_EE_CS);
|
|
|
|
dc_delay(sc);
|
|
|
|
|
|
|
|
for (i = 3; i--;) {
|
|
|
|
if (6 & (1 << i))
|
|
|
|
DC_SETBIT(sc, DC_SIO, DC_SIO_EE_DATAIN);
|
|
|
|
else
|
|
|
|
DC_CLRBIT(sc, DC_SIO, DC_SIO_EE_DATAIN);
|
|
|
|
dc_delay(sc);
|
|
|
|
DC_SETBIT(sc, DC_SIO, DC_SIO_EE_CLK);
|
|
|
|
dc_delay(sc);
|
|
|
|
DC_CLRBIT(sc, DC_SIO, DC_SIO_EE_CLK);
|
|
|
|
dc_delay(sc);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 1; i <= 12; i++) {
|
|
|
|
DC_SETBIT(sc, DC_SIO, DC_SIO_EE_CLK);
|
|
|
|
dc_delay(sc);
|
|
|
|
if (!(CSR_READ_4(sc, DC_SIO) & DC_SIO_EE_DATAOUT)) {
|
|
|
|
DC_CLRBIT(sc, DC_SIO, DC_SIO_EE_CLK);
|
|
|
|
dc_delay(sc);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
DC_CLRBIT(sc, DC_SIO, DC_SIO_EE_CLK);
|
|
|
|
dc_delay(sc);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Turn off EEPROM access mode. */
|
|
|
|
dc_eeprom_idle(sc);
|
|
|
|
|
|
|
|
if (i < 4 || i > 12)
|
|
|
|
sc->dc_romwidth = 6;
|
|
|
|
else
|
|
|
|
sc->dc_romwidth = i;
|
|
|
|
|
|
|
|
/* Enter EEPROM access mode. */
|
|
|
|
CSR_WRITE_4(sc, DC_SIO, DC_SIO_EESEL);
|
|
|
|
dc_delay(sc);
|
|
|
|
DC_SETBIT(sc, DC_SIO, DC_SIO_ROMCTL_READ);
|
|
|
|
dc_delay(sc);
|
|
|
|
DC_CLRBIT(sc, DC_SIO, DC_SIO_EE_CLK);
|
|
|
|
dc_delay(sc);
|
|
|
|
DC_SETBIT(sc, DC_SIO, DC_SIO_EE_CS);
|
|
|
|
dc_delay(sc);
|
|
|
|
|
|
|
|
/* Turn off EEPROM access mode. */
|
|
|
|
dc_eeprom_idle(sc);
|
|
|
|
}
|
|
|
|
|
2002-08-23 23:49:02 +00:00
|
|
|
static void
|
2003-06-01 19:26:34 +00:00
|
|
|
dc_eeprom_idle(struct dc_softc *sc)
|
1999-12-04 17:41:31 +00:00
|
|
|
{
|
2003-06-01 19:26:34 +00:00
|
|
|
int i;
|
1999-12-04 17:41:31 +00:00
|
|
|
|
|
|
|
CSR_WRITE_4(sc, DC_SIO, DC_SIO_EESEL);
|
|
|
|
dc_delay(sc);
|
|
|
|
DC_SETBIT(sc, DC_SIO, DC_SIO_ROMCTL_READ);
|
|
|
|
dc_delay(sc);
|
|
|
|
DC_CLRBIT(sc, DC_SIO, DC_SIO_EE_CLK);
|
|
|
|
dc_delay(sc);
|
|
|
|
DC_SETBIT(sc, DC_SIO, DC_SIO_EE_CS);
|
|
|
|
dc_delay(sc);
|
|
|
|
|
|
|
|
for (i = 0; i < 25; i++) {
|
|
|
|
DC_CLRBIT(sc, DC_SIO, DC_SIO_EE_CLK);
|
|
|
|
dc_delay(sc);
|
|
|
|
DC_SETBIT(sc, DC_SIO, DC_SIO_EE_CLK);
|
|
|
|
dc_delay(sc);
|
|
|
|
}
|
|
|
|
|
|
|
|
DC_CLRBIT(sc, DC_SIO, DC_SIO_EE_CLK);
|
|
|
|
dc_delay(sc);
|
|
|
|
DC_CLRBIT(sc, DC_SIO, DC_SIO_EE_CS);
|
|
|
|
dc_delay(sc);
|
|
|
|
CSR_WRITE_4(sc, DC_SIO, 0x00000000);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Send a read command and address to the EEPROM, check for ACK.
|
|
|
|
*/
|
2002-08-23 23:49:02 +00:00
|
|
|
static void
|
2003-06-01 19:26:34 +00:00
|
|
|
dc_eeprom_putbyte(struct dc_softc *sc, int addr)
|
1999-12-04 17:41:31 +00:00
|
|
|
{
|
2003-06-01 19:26:34 +00:00
|
|
|
int d, i;
|
1999-12-04 17:41:31 +00:00
|
|
|
|
2002-10-07 05:26:35 +00:00
|
|
|
d = DC_EECMD_READ >> 6;
|
|
|
|
for (i = 3; i--; ) {
|
|
|
|
if (d & (1 << i))
|
|
|
|
DC_SETBIT(sc, DC_SIO, DC_SIO_EE_DATAIN);
|
|
|
|
else
|
|
|
|
DC_CLRBIT(sc, DC_SIO, DC_SIO_EE_DATAIN);
|
|
|
|
dc_delay(sc);
|
|
|
|
DC_SETBIT(sc, DC_SIO, DC_SIO_EE_CLK);
|
|
|
|
dc_delay(sc);
|
|
|
|
DC_CLRBIT(sc, DC_SIO, DC_SIO_EE_CLK);
|
|
|
|
dc_delay(sc);
|
|
|
|
}
|
1999-12-04 17:41:31 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Feed in each bit and strobe the clock.
|
|
|
|
*/
|
2002-10-07 05:26:35 +00:00
|
|
|
for (i = sc->dc_romwidth; i--;) {
|
|
|
|
if (addr & (1 << i)) {
|
1999-12-04 17:41:31 +00:00
|
|
|
SIO_SET(DC_SIO_EE_DATAIN);
|
|
|
|
} else {
|
|
|
|
SIO_CLR(DC_SIO_EE_DATAIN);
|
|
|
|
}
|
|
|
|
dc_delay(sc);
|
|
|
|
SIO_SET(DC_SIO_EE_CLK);
|
|
|
|
dc_delay(sc);
|
|
|
|
SIO_CLR(DC_SIO_EE_CLK);
|
|
|
|
dc_delay(sc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Read a word of data stored in the EEPROM at address 'addr.'
|
|
|
|
* The PNIC 82c168/82c169 has its own non-standard way to read
|
|
|
|
* the EEPROM.
|
|
|
|
*/
|
2002-08-23 23:49:02 +00:00
|
|
|
static void
|
2003-06-01 19:26:34 +00:00
|
|
|
dc_eeprom_getword_pnic(struct dc_softc *sc, int addr, u_int16_t *dest)
|
1999-12-04 17:41:31 +00:00
|
|
|
{
|
2003-06-01 19:26:34 +00:00
|
|
|
int i;
|
|
|
|
u_int32_t r;
|
1999-12-04 17:41:31 +00:00
|
|
|
|
2003-06-01 19:26:34 +00:00
|
|
|
CSR_WRITE_4(sc, DC_PN_SIOCTL, DC_PN_EEOPCODE_READ | addr);
|
1999-12-04 17:41:31 +00:00
|
|
|
|
|
|
|
for (i = 0; i < DC_TIMEOUT; i++) {
|
|
|
|
DELAY(1);
|
|
|
|
r = CSR_READ_4(sc, DC_SIO);
|
|
|
|
if (!(r & DC_PN_SIOCTL_BUSY)) {
|
|
|
|
*dest = (u_int16_t)(r & 0xFFFF);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-10-19 08:34:32 +00:00
|
|
|
/*
|
|
|
|
* Read a word of data stored in the EEPROM at address 'addr.'
|
|
|
|
* The Xircom X3201 has its own non-standard way to read
|
|
|
|
* the EEPROM, too.
|
|
|
|
*/
|
2002-08-23 23:49:02 +00:00
|
|
|
static void
|
2003-06-01 19:26:34 +00:00
|
|
|
dc_eeprom_getword_xircom(struct dc_softc *sc, int addr, u_int16_t *dest)
|
2000-10-19 08:34:32 +00:00
|
|
|
{
|
2003-06-01 19:26:34 +00:00
|
|
|
|
2000-10-19 08:34:32 +00:00
|
|
|
SIO_SET(DC_SIO_ROMSEL | DC_SIO_ROMCTL_READ);
|
|
|
|
|
|
|
|
addr *= 2;
|
|
|
|
CSR_WRITE_4(sc, DC_ROM, addr | 0x160);
|
2003-06-01 19:26:34 +00:00
|
|
|
*dest = (u_int16_t)CSR_READ_4(sc, DC_SIO) & 0xff;
|
2000-10-19 08:34:32 +00:00
|
|
|
addr += 1;
|
|
|
|
CSR_WRITE_4(sc, DC_ROM, addr | 0x160);
|
2003-06-01 19:26:34 +00:00
|
|
|
*dest |= ((u_int16_t)CSR_READ_4(sc, DC_SIO) & 0xff) << 8;
|
2000-10-19 08:34:32 +00:00
|
|
|
|
|
|
|
SIO_CLR(DC_SIO_ROMSEL | DC_SIO_ROMCTL_READ);
|
|
|
|
}
|
|
|
|
|
1999-12-04 17:41:31 +00:00
|
|
|
/*
|
|
|
|
* Read a word of data stored in the EEPROM at address 'addr.'
|
|
|
|
*/
|
2002-08-23 23:49:02 +00:00
|
|
|
static void
|
2003-06-01 19:26:34 +00:00
|
|
|
dc_eeprom_getword(struct dc_softc *sc, int addr, u_int16_t *dest)
|
1999-12-04 17:41:31 +00:00
|
|
|
{
|
2003-06-01 19:26:34 +00:00
|
|
|
int i;
|
|
|
|
u_int16_t word = 0;
|
1999-12-04 17:41:31 +00:00
|
|
|
|
|
|
|
/* Force EEPROM to idle state. */
|
|
|
|
dc_eeprom_idle(sc);
|
|
|
|
|
|
|
|
/* Enter EEPROM access mode. */
|
|
|
|
CSR_WRITE_4(sc, DC_SIO, DC_SIO_EESEL);
|
|
|
|
dc_delay(sc);
|
|
|
|
DC_SETBIT(sc, DC_SIO, DC_SIO_ROMCTL_READ);
|
|
|
|
dc_delay(sc);
|
|
|
|
DC_CLRBIT(sc, DC_SIO, DC_SIO_EE_CLK);
|
|
|
|
dc_delay(sc);
|
|
|
|
DC_SETBIT(sc, DC_SIO, DC_SIO_EE_CS);
|
|
|
|
dc_delay(sc);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Send address of word we want to read.
|
|
|
|
*/
|
|
|
|
dc_eeprom_putbyte(sc, addr);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Start reading bits from EEPROM.
|
|
|
|
*/
|
|
|
|
for (i = 0x8000; i; i >>= 1) {
|
|
|
|
SIO_SET(DC_SIO_EE_CLK);
|
|
|
|
dc_delay(sc);
|
|
|
|
if (CSR_READ_4(sc, DC_SIO) & DC_SIO_EE_DATAOUT)
|
|
|
|
word |= i;
|
|
|
|
dc_delay(sc);
|
|
|
|
SIO_CLR(DC_SIO_EE_CLK);
|
|
|
|
dc_delay(sc);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Turn off EEPROM access mode. */
|
|
|
|
dc_eeprom_idle(sc);
|
|
|
|
|
|
|
|
*dest = word;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Read a sequence of words from the EEPROM.
|
|
|
|
*/
|
2002-08-23 23:49:02 +00:00
|
|
|
static void
|
2004-10-01 15:23:31 +00:00
|
|
|
dc_read_eeprom(struct dc_softc *sc, caddr_t dest, int off, int cnt, int be)
|
1999-12-04 17:41:31 +00:00
|
|
|
{
|
2003-06-01 19:26:34 +00:00
|
|
|
int i;
|
|
|
|
u_int16_t word = 0, *ptr;
|
1999-12-04 17:41:31 +00:00
|
|
|
|
|
|
|
for (i = 0; i < cnt; i++) {
|
|
|
|
if (DC_IS_PNIC(sc))
|
|
|
|
dc_eeprom_getword_pnic(sc, off + i, &word);
|
2000-10-19 08:34:32 +00:00
|
|
|
else if (DC_IS_XIRCOM(sc))
|
|
|
|
dc_eeprom_getword_xircom(sc, off + i, &word);
|
1999-12-04 17:41:31 +00:00
|
|
|
else
|
|
|
|
dc_eeprom_getword(sc, off + i, &word);
|
|
|
|
ptr = (u_int16_t *)(dest + (i * 2));
|
2004-10-01 15:23:31 +00:00
|
|
|
if (be)
|
|
|
|
*ptr = be16toh(word);
|
1999-12-04 17:41:31 +00:00
|
|
|
else
|
2004-10-01 15:23:31 +00:00
|
|
|
*ptr = le16toh(word);
|
1999-12-04 17:41:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The following two routines are taken from the Macronix 98713
|
|
|
|
* Application Notes pp.19-21.
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* Write a bit to the MII bus.
|
|
|
|
*/
|
2002-08-23 23:49:02 +00:00
|
|
|
static void
|
2003-06-01 19:26:34 +00:00
|
|
|
dc_mii_writebit(struct dc_softc *sc, int bit)
|
1999-12-04 17:41:31 +00:00
|
|
|
{
|
2003-06-01 19:26:34 +00:00
|
|
|
|
1999-12-04 17:41:31 +00:00
|
|
|
if (bit)
|
|
|
|
CSR_WRITE_4(sc, DC_SIO,
|
2003-06-01 19:26:34 +00:00
|
|
|
DC_SIO_ROMCTL_WRITE | DC_SIO_MII_DATAOUT);
|
1999-12-04 17:41:31 +00:00
|
|
|
else
|
|
|
|
CSR_WRITE_4(sc, DC_SIO, DC_SIO_ROMCTL_WRITE);
|
|
|
|
|
|
|
|
DC_SETBIT(sc, DC_SIO, DC_SIO_MII_CLK);
|
|
|
|
DC_CLRBIT(sc, DC_SIO, DC_SIO_MII_CLK);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Read a bit from the MII bus.
|
|
|
|
*/
|
2002-08-23 23:49:02 +00:00
|
|
|
static int
|
2003-06-01 19:26:34 +00:00
|
|
|
dc_mii_readbit(struct dc_softc *sc)
|
1999-12-04 17:41:31 +00:00
|
|
|
{
|
2003-06-01 19:26:34 +00:00
|
|
|
|
|
|
|
CSR_WRITE_4(sc, DC_SIO, DC_SIO_ROMCTL_READ | DC_SIO_MII_DIR);
|
1999-12-04 17:41:31 +00:00
|
|
|
CSR_READ_4(sc, DC_SIO);
|
|
|
|
DC_SETBIT(sc, DC_SIO, DC_SIO_MII_CLK);
|
|
|
|
DC_CLRBIT(sc, DC_SIO, DC_SIO_MII_CLK);
|
|
|
|
if (CSR_READ_4(sc, DC_SIO) & DC_SIO_MII_DATAIN)
|
2003-06-01 19:26:34 +00:00
|
|
|
return (1);
|
1999-12-04 17:41:31 +00:00
|
|
|
|
2003-06-01 19:26:34 +00:00
|
|
|
return (0);
|
1999-12-04 17:41:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Sync the PHYs by setting data bit and strobing the clock 32 times.
|
|
|
|
*/
|
2002-08-23 23:49:02 +00:00
|
|
|
static void
|
2003-06-01 19:26:34 +00:00
|
|
|
dc_mii_sync(struct dc_softc *sc)
|
1999-12-04 17:41:31 +00:00
|
|
|
{
|
2003-06-01 19:26:34 +00:00
|
|
|
int i;
|
1999-12-04 17:41:31 +00:00
|
|
|
|
|
|
|
CSR_WRITE_4(sc, DC_SIO, DC_SIO_ROMCTL_WRITE);
|
|
|
|
|
|
|
|
for (i = 0; i < 32; i++)
|
|
|
|
dc_mii_writebit(sc, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Clock a series of bits through the MII.
|
|
|
|
*/
|
2002-08-23 23:49:02 +00:00
|
|
|
static void
|
2003-06-01 19:26:34 +00:00
|
|
|
dc_mii_send(struct dc_softc *sc, u_int32_t bits, int cnt)
|
1999-12-04 17:41:31 +00:00
|
|
|
{
|
2003-06-01 19:26:34 +00:00
|
|
|
int i;
|
1999-12-04 17:41:31 +00:00
|
|
|
|
|
|
|
for (i = (0x1 << (cnt - 1)); i; i >>= 1)
|
|
|
|
dc_mii_writebit(sc, bits & i);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Read an PHY register through the MII.
|
|
|
|
*/
|
2002-08-23 23:49:02 +00:00
|
|
|
static int
|
2003-06-01 19:26:34 +00:00
|
|
|
dc_mii_readreg(struct dc_softc *sc, struct dc_mii_frame *frame)
|
1999-12-04 17:41:31 +00:00
|
|
|
{
|
2003-06-01 19:26:34 +00:00
|
|
|
int i, ack;
|
1999-12-04 17:41:31 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Set up frame for RX.
|
|
|
|
*/
|
|
|
|
frame->mii_stdelim = DC_MII_STARTDELIM;
|
|
|
|
frame->mii_opcode = DC_MII_READOP;
|
|
|
|
frame->mii_turnaround = 0;
|
|
|
|
frame->mii_data = 0;
|
2003-06-01 19:26:34 +00:00
|
|
|
|
1999-12-04 17:41:31 +00:00
|
|
|
/*
|
|
|
|
* Sync the PHYs.
|
|
|
|
*/
|
|
|
|
dc_mii_sync(sc);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Send command/address info.
|
|
|
|
*/
|
|
|
|
dc_mii_send(sc, frame->mii_stdelim, 2);
|
|
|
|
dc_mii_send(sc, frame->mii_opcode, 2);
|
|
|
|
dc_mii_send(sc, frame->mii_phyaddr, 5);
|
|
|
|
dc_mii_send(sc, frame->mii_regaddr, 5);
|
|
|
|
|
|
|
|
#ifdef notdef
|
|
|
|
/* Idle bit */
|
|
|
|
dc_mii_writebit(sc, 1);
|
|
|
|
dc_mii_writebit(sc, 0);
|
|
|
|
#endif
|
|
|
|
|
2003-06-01 19:26:34 +00:00
|
|
|
/* Check for ack. */
|
1999-12-04 17:41:31 +00:00
|
|
|
ack = dc_mii_readbit(sc);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Now try reading data bits. If the ack failed, we still
|
|
|
|
* need to clock through 16 cycles to keep the PHY(s) in sync.
|
|
|
|
*/
|
|
|
|
if (ack) {
|
2003-06-01 19:26:34 +00:00
|
|
|
for (i = 0; i < 16; i++)
|
1999-12-04 17:41:31 +00:00
|
|
|
dc_mii_readbit(sc);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0x8000; i; i >>= 1) {
|
|
|
|
if (!ack) {
|
|
|
|
if (dc_mii_readbit(sc))
|
|
|
|
frame->mii_data |= i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fail:
|
|
|
|
|
|
|
|
dc_mii_writebit(sc, 0);
|
|
|
|
dc_mii_writebit(sc, 0);
|
|
|
|
|
|
|
|
if (ack)
|
2003-06-01 19:26:34 +00:00
|
|
|
return (1);
|
|
|
|
return (0);
|
1999-12-04 17:41:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Write to a PHY register through the MII.
|
|
|
|
*/
|
2002-08-23 23:49:02 +00:00
|
|
|
static int
|
2003-06-01 19:26:34 +00:00
|
|
|
dc_mii_writereg(struct dc_softc *sc, struct dc_mii_frame *frame)
|
1999-12-04 17:41:31 +00:00
|
|
|
{
|
2003-06-01 19:26:34 +00:00
|
|
|
|
1999-12-04 17:41:31 +00:00
|
|
|
/*
|
|
|
|
* Set up frame for TX.
|
|
|
|
*/
|
|
|
|
|
|
|
|
frame->mii_stdelim = DC_MII_STARTDELIM;
|
|
|
|
frame->mii_opcode = DC_MII_WRITEOP;
|
|
|
|
frame->mii_turnaround = DC_MII_TURNAROUND;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Sync the PHYs.
|
2003-06-01 19:26:34 +00:00
|
|
|
*/
|
1999-12-04 17:41:31 +00:00
|
|
|
dc_mii_sync(sc);
|
|
|
|
|
|
|
|
dc_mii_send(sc, frame->mii_stdelim, 2);
|
|
|
|
dc_mii_send(sc, frame->mii_opcode, 2);
|
|
|
|
dc_mii_send(sc, frame->mii_phyaddr, 5);
|
|
|
|
dc_mii_send(sc, frame->mii_regaddr, 5);
|
|
|
|
dc_mii_send(sc, frame->mii_turnaround, 2);
|
|
|
|
dc_mii_send(sc, frame->mii_data, 16);
|
|
|
|
|
|
|
|
/* Idle bit. */
|
|
|
|
dc_mii_writebit(sc, 0);
|
|
|
|
dc_mii_writebit(sc, 0);
|
|
|
|
|
2003-06-01 19:26:34 +00:00
|
|
|
return (0);
|
1999-12-04 17:41:31 +00:00
|
|
|
}
|
|
|
|
|
2002-08-23 23:49:02 +00:00
|
|
|
static int
|
2003-06-01 19:26:34 +00:00
|
|
|
dc_miibus_readreg(device_t dev, int phy, int reg)
|
1999-12-04 17:41:31 +00:00
|
|
|
{
|
2003-06-01 19:26:34 +00:00
|
|
|
struct dc_mii_frame frame;
|
|
|
|
struct dc_softc *sc;
|
|
|
|
int i, rval, phy_reg = 0;
|
1999-12-04 17:41:31 +00:00
|
|
|
|
|
|
|
sc = device_get_softc(dev);
|
2003-06-01 19:26:34 +00:00
|
|
|
bzero(&frame, sizeof(frame));
|
1999-12-04 17:41:31 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Note: both the AL981 and AN985 have internal PHYs,
|
|
|
|
* however the AL981 provides direct access to the PHY
|
|
|
|
* registers while the AN985 uses a serial MII interface.
|
|
|
|
* The AN985's MII interface is also buggy in that you
|
|
|
|
* can read from any MII address (0 to 31), but only address 1
|
|
|
|
* behaves normally. To deal with both cases, we pretend
|
|
|
|
* that the PHY is at MII address 1.
|
|
|
|
*/
|
|
|
|
if (DC_IS_ADMTEK(sc) && phy != DC_ADMTEK_PHYADDR)
|
2003-06-01 19:26:34 +00:00
|
|
|
return (0);
|
1999-12-04 17:41:31 +00:00
|
|
|
|
2001-09-04 17:10:11 +00:00
|
|
|
/*
|
|
|
|
* Note: the ukphy probes of the RS7112 report a PHY at
|
|
|
|
* MII address 0 (possibly HomePNA?) and 1 (ethernet)
|
|
|
|
* so we only respond to correct one.
|
|
|
|
*/
|
|
|
|
if (DC_IS_CONEXANT(sc) && phy != DC_CONEXANT_PHYADDR)
|
2003-06-01 19:26:34 +00:00
|
|
|
return (0);
|
2001-09-04 17:10:11 +00:00
|
|
|
|
2000-10-05 17:36:14 +00:00
|
|
|
if (sc->dc_pmode != DC_PMODE_MII) {
|
1999-12-04 17:41:31 +00:00
|
|
|
if (phy == (MII_NPHY - 1)) {
|
2003-06-01 19:26:34 +00:00
|
|
|
switch (reg) {
|
1999-12-04 17:41:31 +00:00
|
|
|
case MII_BMSR:
|
|
|
|
/*
|
|
|
|
* Fake something to make the probe
|
|
|
|
* code think there's a PHY here.
|
|
|
|
*/
|
2003-06-01 19:26:34 +00:00
|
|
|
return (BMSR_MEDIAMASK);
|
1999-12-04 17:41:31 +00:00
|
|
|
break;
|
|
|
|
case MII_PHYIDR1:
|
|
|
|
if (DC_IS_PNIC(sc))
|
2003-06-01 19:26:34 +00:00
|
|
|
return (DC_VENDORID_LO);
|
|
|
|
return (DC_VENDORID_DEC);
|
1999-12-04 17:41:31 +00:00
|
|
|
break;
|
|
|
|
case MII_PHYIDR2:
|
|
|
|
if (DC_IS_PNIC(sc))
|
2003-06-01 19:26:34 +00:00
|
|
|
return (DC_DEVICEID_82C168);
|
|
|
|
return (DC_DEVICEID_21143);
|
1999-12-04 17:41:31 +00:00
|
|
|
break;
|
|
|
|
default:
|
2003-06-01 19:26:34 +00:00
|
|
|
return (0);
|
1999-12-04 17:41:31 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else
|
2003-06-01 19:26:34 +00:00
|
|
|
return (0);
|
1999-12-04 17:41:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (DC_IS_PNIC(sc)) {
|
|
|
|
CSR_WRITE_4(sc, DC_PN_MII, DC_PN_MIIOPCODE_READ |
|
|
|
|
(phy << 23) | (reg << 18));
|
|
|
|
for (i = 0; i < DC_TIMEOUT; i++) {
|
|
|
|
DELAY(1);
|
|
|
|
rval = CSR_READ_4(sc, DC_PN_MII);
|
|
|
|
if (!(rval & DC_PN_MII_BUSY)) {
|
|
|
|
rval &= 0xFFFF;
|
2003-06-01 19:26:34 +00:00
|
|
|
return (rval == 0xFFFF ? 0 : rval);
|
1999-12-04 17:41:31 +00:00
|
|
|
}
|
|
|
|
}
|
2003-06-01 19:26:34 +00:00
|
|
|
return (0);
|
1999-12-04 17:41:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (DC_IS_COMET(sc)) {
|
2003-06-01 19:26:34 +00:00
|
|
|
switch (reg) {
|
1999-12-04 17:41:31 +00:00
|
|
|
case MII_BMCR:
|
|
|
|
phy_reg = DC_AL_BMCR;
|
|
|
|
break;
|
|
|
|
case MII_BMSR:
|
|
|
|
phy_reg = DC_AL_BMSR;
|
|
|
|
break;
|
|
|
|
case MII_PHYIDR1:
|
|
|
|
phy_reg = DC_AL_VENID;
|
|
|
|
break;
|
|
|
|
case MII_PHYIDR2:
|
|
|
|
phy_reg = DC_AL_DEVID;
|
|
|
|
break;
|
|
|
|
case MII_ANAR:
|
|
|
|
phy_reg = DC_AL_ANAR;
|
|
|
|
break;
|
|
|
|
case MII_ANLPAR:
|
|
|
|
phy_reg = DC_AL_LPAR;
|
|
|
|
break;
|
|
|
|
case MII_ANER:
|
|
|
|
phy_reg = DC_AL_ANER;
|
|
|
|
break;
|
|
|
|
default:
|
2005-08-10 20:33:46 +00:00
|
|
|
device_printf(dev, "phy_read: bad phy register %x\n",
|
|
|
|
reg);
|
2003-06-01 19:26:34 +00:00
|
|
|
return (0);
|
1999-12-04 17:41:31 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
rval = CSR_READ_4(sc, phy_reg) & 0x0000FFFF;
|
|
|
|
|
|
|
|
if (rval == 0xFFFF)
|
2003-06-01 19:26:34 +00:00
|
|
|
return (0);
|
|
|
|
return (rval);
|
1999-12-04 17:41:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
frame.mii_phyaddr = phy;
|
|
|
|
frame.mii_regaddr = reg;
|
2001-01-19 23:55:07 +00:00
|
|
|
if (sc->dc_type == DC_TYPE_98713) {
|
|
|
|
phy_reg = CSR_READ_4(sc, DC_NETCFG);
|
|
|
|
CSR_WRITE_4(sc, DC_NETCFG, phy_reg & ~DC_NETCFG_PORTSEL);
|
|
|
|
}
|
1999-12-04 17:41:31 +00:00
|
|
|
dc_mii_readreg(sc, &frame);
|
2001-01-19 23:55:07 +00:00
|
|
|
if (sc->dc_type == DC_TYPE_98713)
|
|
|
|
CSR_WRITE_4(sc, DC_NETCFG, phy_reg);
|
1999-12-04 17:41:31 +00:00
|
|
|
|
2003-06-01 19:26:34 +00:00
|
|
|
return (frame.mii_data);
|
1999-12-04 17:41:31 +00:00
|
|
|
}
|
|
|
|
|
2002-08-23 23:49:02 +00:00
|
|
|
static int
|
2003-06-01 19:26:34 +00:00
|
|
|
dc_miibus_writereg(device_t dev, int phy, int reg, int data)
|
1999-12-04 17:41:31 +00:00
|
|
|
{
|
2003-06-01 19:26:34 +00:00
|
|
|
struct dc_softc *sc;
|
|
|
|
struct dc_mii_frame frame;
|
|
|
|
int i, phy_reg = 0;
|
1999-12-04 17:41:31 +00:00
|
|
|
|
|
|
|
sc = device_get_softc(dev);
|
2003-06-01 19:26:34 +00:00
|
|
|
bzero(&frame, sizeof(frame));
|
1999-12-04 17:41:31 +00:00
|
|
|
|
|
|
|
if (DC_IS_ADMTEK(sc) && phy != DC_ADMTEK_PHYADDR)
|
2003-06-01 19:26:34 +00:00
|
|
|
return (0);
|
1999-12-04 17:41:31 +00:00
|
|
|
|
2001-09-04 17:10:11 +00:00
|
|
|
if (DC_IS_CONEXANT(sc) && phy != DC_CONEXANT_PHYADDR)
|
2003-06-01 19:26:34 +00:00
|
|
|
return (0);
|
2001-09-04 17:10:11 +00:00
|
|
|
|
1999-12-04 17:41:31 +00:00
|
|
|
if (DC_IS_PNIC(sc)) {
|
|
|
|
CSR_WRITE_4(sc, DC_PN_MII, DC_PN_MIIOPCODE_WRITE |
|
|
|
|
(phy << 23) | (reg << 10) | data);
|
|
|
|
for (i = 0; i < DC_TIMEOUT; i++) {
|
|
|
|
if (!(CSR_READ_4(sc, DC_PN_MII) & DC_PN_MII_BUSY))
|
|
|
|
break;
|
|
|
|
}
|
2003-06-01 19:26:34 +00:00
|
|
|
return (0);
|
1999-12-04 17:41:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (DC_IS_COMET(sc)) {
|
2003-06-01 19:26:34 +00:00
|
|
|
switch (reg) {
|
1999-12-04 17:41:31 +00:00
|
|
|
case MII_BMCR:
|
|
|
|
phy_reg = DC_AL_BMCR;
|
|
|
|
break;
|
|
|
|
case MII_BMSR:
|
|
|
|
phy_reg = DC_AL_BMSR;
|
|
|
|
break;
|
|
|
|
case MII_PHYIDR1:
|
|
|
|
phy_reg = DC_AL_VENID;
|
|
|
|
break;
|
|
|
|
case MII_PHYIDR2:
|
|
|
|
phy_reg = DC_AL_DEVID;
|
|
|
|
break;
|
|
|
|
case MII_ANAR:
|
|
|
|
phy_reg = DC_AL_ANAR;
|
|
|
|
break;
|
|
|
|
case MII_ANLPAR:
|
|
|
|
phy_reg = DC_AL_LPAR;
|
|
|
|
break;
|
|
|
|
case MII_ANER:
|
|
|
|
phy_reg = DC_AL_ANER;
|
|
|
|
break;
|
|
|
|
default:
|
2005-08-10 20:33:46 +00:00
|
|
|
device_printf(dev, "phy_write: bad phy register %x\n",
|
|
|
|
reg);
|
2003-06-01 19:26:34 +00:00
|
|
|
return (0);
|
1999-12-04 17:41:31 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
CSR_WRITE_4(sc, phy_reg, data);
|
2003-06-01 19:26:34 +00:00
|
|
|
return (0);
|
1999-12-04 17:41:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
frame.mii_phyaddr = phy;
|
|
|
|
frame.mii_regaddr = reg;
|
|
|
|
frame.mii_data = data;
|
|
|
|
|
2001-01-19 23:55:07 +00:00
|
|
|
if (sc->dc_type == DC_TYPE_98713) {
|
|
|
|
phy_reg = CSR_READ_4(sc, DC_NETCFG);
|
|
|
|
CSR_WRITE_4(sc, DC_NETCFG, phy_reg & ~DC_NETCFG_PORTSEL);
|
|
|
|
}
|
1999-12-04 17:41:31 +00:00
|
|
|
dc_mii_writereg(sc, &frame);
|
2001-01-19 23:55:07 +00:00
|
|
|
if (sc->dc_type == DC_TYPE_98713)
|
|
|
|
CSR_WRITE_4(sc, DC_NETCFG, phy_reg);
|
1999-12-04 17:41:31 +00:00
|
|
|
|
2003-06-01 19:26:34 +00:00
|
|
|
return (0);
|
1999-12-04 17:41:31 +00:00
|
|
|
}
|
|
|
|
|
2002-08-23 23:49:02 +00:00
|
|
|
static void
|
2003-06-01 19:26:34 +00:00
|
|
|
dc_miibus_statchg(device_t dev)
|
1999-12-04 17:41:31 +00:00
|
|
|
{
|
2003-06-01 19:26:34 +00:00
|
|
|
struct dc_softc *sc;
|
|
|
|
struct mii_data *mii;
|
|
|
|
struct ifmedia *ifm;
|
1999-12-04 17:41:31 +00:00
|
|
|
|
|
|
|
sc = device_get_softc(dev);
|
|
|
|
if (DC_IS_ADMTEK(sc))
|
|
|
|
return;
|
2000-10-05 17:36:14 +00:00
|
|
|
|
1999-12-04 17:41:31 +00:00
|
|
|
mii = device_get_softc(sc->dc_miibus);
|
2000-01-24 17:19:37 +00:00
|
|
|
ifm = &mii->mii_media;
|
|
|
|
if (DC_IS_DAVICOM(sc) &&
|
2002-04-29 05:32:44 +00:00
|
|
|
IFM_SUBTYPE(ifm->ifm_media) == IFM_HPNA_1) {
|
2000-01-24 17:19:37 +00:00
|
|
|
dc_setcfg(sc, ifm->ifm_media);
|
|
|
|
sc->dc_if_media = ifm->ifm_media;
|
|
|
|
} else {
|
|
|
|
dc_setcfg(sc, mii->mii_media_active);
|
|
|
|
sc->dc_if_media = mii->mii_media_active;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Special support for DM9102A cards with HomePNA PHYs. Note:
|
|
|
|
* with the Davicom DM9102A/DM9801 eval board that I have, it seems
|
|
|
|
* to be impossible to talk to the management interface of the DM9801
|
|
|
|
* PHY (its MDIO pin is not connected to anything). Consequently,
|
|
|
|
* the driver has to just 'know' about the additional mode and deal
|
|
|
|
* with it itself. *sigh*
|
|
|
|
*/
|
2002-08-23 23:49:02 +00:00
|
|
|
static void
|
2003-06-01 19:26:34 +00:00
|
|
|
dc_miibus_mediainit(device_t dev)
|
2000-01-24 17:19:37 +00:00
|
|
|
{
|
2003-06-01 19:26:34 +00:00
|
|
|
struct dc_softc *sc;
|
|
|
|
struct mii_data *mii;
|
|
|
|
struct ifmedia *ifm;
|
|
|
|
int rev;
|
2000-01-24 17:19:37 +00:00
|
|
|
|
|
|
|
rev = pci_read_config(dev, DC_PCI_CFRV, 4) & 0xFF;
|
|
|
|
|
|
|
|
sc = device_get_softc(dev);
|
|
|
|
mii = device_get_softc(sc->dc_miibus);
|
|
|
|
ifm = &mii->mii_media;
|
|
|
|
|
|
|
|
if (DC_IS_DAVICOM(sc) && rev >= DC_REVISION_DM9102A)
|
2003-06-01 19:26:34 +00:00
|
|
|
ifmedia_add(ifm, IFM_ETHER | IFM_HPNA_1, 0, NULL);
|
1999-12-04 17:41:31 +00:00
|
|
|
}
|
|
|
|
|
2000-07-15 17:54:30 +00:00
|
|
|
#define DC_BITS_512 9
|
|
|
|
#define DC_BITS_128 7
|
|
|
|
#define DC_BITS_64 6
|
1999-12-04 17:41:31 +00:00
|
|
|
|
2003-11-14 05:45:39 +00:00
|
|
|
static uint32_t
|
|
|
|
dc_mchash_le(struct dc_softc *sc, const uint8_t *addr)
|
1999-12-04 17:41:31 +00:00
|
|
|
{
|
2003-11-14 05:45:39 +00:00
|
|
|
uint32_t crc;
|
1999-12-04 17:41:31 +00:00
|
|
|
|
|
|
|
/* Compute CRC for the address value. */
|
2004-06-09 14:34:04 +00:00
|
|
|
crc = ether_crc32_le(addr, ETHER_ADDR_LEN);
|
1999-12-04 17:41:31 +00:00
|
|
|
|
2000-07-15 17:54:30 +00:00
|
|
|
/*
|
|
|
|
* The hash table on the PNIC II and the MX98715AEC-C/D/E
|
|
|
|
* chips is only 128 bits wide.
|
|
|
|
*/
|
|
|
|
if (sc->dc_flags & DC_128BIT_HASH)
|
|
|
|
return (crc & ((1 << DC_BITS_128) - 1));
|
|
|
|
|
|
|
|
/* The hash table on the MX98715BEC is only 64 bits wide. */
|
|
|
|
if (sc->dc_flags & DC_64BIT_HASH)
|
|
|
|
return (crc & ((1 << DC_BITS_64) - 1));
|
1999-12-04 17:41:31 +00:00
|
|
|
|
2000-10-19 08:34:32 +00:00
|
|
|
/* Xircom's hash filtering table is different (read: weird) */
|
|
|
|
/* Xircom uses the LEAST significant bits */
|
|
|
|
if (DC_IS_XIRCOM(sc)) {
|
|
|
|
if ((crc & 0x180) == 0x180)
|
2003-06-01 19:26:34 +00:00
|
|
|
return ((crc & 0x0F) + (crc & 0x70) * 3 + (14 << 4));
|
2000-10-19 08:34:32 +00:00
|
|
|
else
|
2003-06-01 19:26:34 +00:00
|
|
|
return ((crc & 0x1F) + ((crc >> 1) & 0xF0) * 3 +
|
|
|
|
(12 << 4));
|
2000-10-19 08:34:32 +00:00
|
|
|
}
|
|
|
|
|
2000-07-15 17:54:30 +00:00
|
|
|
return (crc & ((1 << DC_BITS_512) - 1));
|
1999-12-04 17:41:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Calculate CRC of a multicast group address, return the lower 6 bits.
|
|
|
|
*/
|
2003-11-14 05:45:39 +00:00
|
|
|
static uint32_t
|
|
|
|
dc_mchash_be(const uint8_t *addr)
|
1999-12-04 17:41:31 +00:00
|
|
|
{
|
2004-06-09 14:34:04 +00:00
|
|
|
uint32_t crc;
|
1999-12-04 17:41:31 +00:00
|
|
|
|
|
|
|
/* Compute CRC for the address value. */
|
2004-06-09 14:34:04 +00:00
|
|
|
crc = ether_crc32_be(addr, ETHER_ADDR_LEN);
|
1999-12-04 17:41:31 +00:00
|
|
|
|
2003-06-01 19:26:34 +00:00
|
|
|
/* Return the filter bit position. */
|
|
|
|
return ((crc >> 26) & 0x0000003F);
|
1999-12-04 17:41:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 21143-style RX filter setup routine. Filter programming is done by
|
|
|
|
* downloading a special setup frame into the TX engine. 21143, Macronix,
|
|
|
|
* PNIC, PNIC II and Davicom chips are programmed this way.
|
|
|
|
*
|
|
|
|
* We always program the chip using 'hash perfect' mode, i.e. one perfect
|
|
|
|
* address (our node address) and a 512-bit hash filter for multicast
|
|
|
|
* frames. We also sneak the broadcast address into the hash filter since
|
|
|
|
* we need that too.
|
|
|
|
*/
|
2002-10-16 09:04:52 +00:00
|
|
|
static void
|
2003-06-01 19:26:34 +00:00
|
|
|
dc_setfilt_21143(struct dc_softc *sc)
|
1999-12-04 17:41:31 +00:00
|
|
|
{
|
2003-06-01 19:26:34 +00:00
|
|
|
struct dc_desc *sframe;
|
|
|
|
u_int32_t h, *sp;
|
|
|
|
struct ifmultiaddr *ifma;
|
|
|
|
struct ifnet *ifp;
|
|
|
|
int i;
|
1999-12-04 17:41:31 +00:00
|
|
|
|
2005-06-10 16:49:24 +00:00
|
|
|
ifp = sc->dc_ifp;
|
1999-12-04 17:41:31 +00:00
|
|
|
|
|
|
|
i = sc->dc_cdata.dc_tx_prod;
|
|
|
|
DC_INC(sc->dc_cdata.dc_tx_prod, DC_TX_LIST_CNT);
|
|
|
|
sc->dc_cdata.dc_tx_cnt++;
|
|
|
|
sframe = &sc->dc_ldata->dc_tx_list[i];
|
2003-07-06 21:45:31 +00:00
|
|
|
sp = sc->dc_cdata.dc_sbuf;
|
2003-06-01 19:26:34 +00:00
|
|
|
bzero(sp, DC_SFRAME_LEN);
|
1999-12-04 17:41:31 +00:00
|
|
|
|
2003-07-09 15:03:10 +00:00
|
|
|
sframe->dc_data = htole32(sc->dc_saddr);
|
|
|
|
sframe->dc_ctl = htole32(DC_SFRAME_LEN | DC_TXCTL_SETUP |
|
|
|
|
DC_TXCTL_TLINK | DC_FILTER_HASHPERF | DC_TXCTL_FINT);
|
1999-12-04 17:41:31 +00:00
|
|
|
|
2003-07-06 21:45:31 +00:00
|
|
|
sc->dc_cdata.dc_tx_chain[i] = (struct mbuf *)sc->dc_cdata.dc_sbuf;
|
1999-12-04 17:41:31 +00:00
|
|
|
|
|
|
|
/* If we want promiscuous mode, set the allframes bit. */
|
|
|
|
if (ifp->if_flags & IFF_PROMISC)
|
|
|
|
DC_SETBIT(sc, DC_NETCFG, DC_NETCFG_RX_PROMISC);
|
|
|
|
else
|
|
|
|
DC_CLRBIT(sc, DC_NETCFG, DC_NETCFG_RX_PROMISC);
|
|
|
|
|
|
|
|
if (ifp->if_flags & IFF_ALLMULTI)
|
|
|
|
DC_SETBIT(sc, DC_NETCFG, DC_NETCFG_RX_ALLMULTI);
|
|
|
|
else
|
|
|
|
DC_CLRBIT(sc, DC_NETCFG, DC_NETCFG_RX_ALLMULTI);
|
|
|
|
|
2005-08-03 00:18:35 +00:00
|
|
|
IF_ADDR_LOCK(ifp);
|
2001-02-06 10:12:15 +00:00
|
|
|
TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
|
1999-12-04 17:41:31 +00:00
|
|
|
if (ifma->ifma_addr->sa_family != AF_LINK)
|
|
|
|
continue;
|
2003-11-13 20:55:53 +00:00
|
|
|
h = dc_mchash_le(sc,
|
1999-12-04 17:41:31 +00:00
|
|
|
LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
|
2003-07-09 15:03:10 +00:00
|
|
|
sp[h >> 4] |= htole32(1 << (h & 0xF));
|
1999-12-04 17:41:31 +00:00
|
|
|
}
|
2005-08-03 00:18:35 +00:00
|
|
|
IF_ADDR_UNLOCK(ifp);
|
1999-12-04 17:41:31 +00:00
|
|
|
|
|
|
|
if (ifp->if_flags & IFF_BROADCAST) {
|
2003-11-13 20:55:53 +00:00
|
|
|
h = dc_mchash_le(sc, ifp->if_broadcastaddr);
|
2003-07-09 15:03:10 +00:00
|
|
|
sp[h >> 4] |= htole32(1 << (h & 0xF));
|
1999-12-04 17:41:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Set our MAC address */
|
2005-11-22 01:51:57 +00:00
|
|
|
sp[39] = DC_SP_MAC((u_int16_t *)IF_LLADDR(sc->dc_ifp) + 0);
|
|
|
|
sp[40] = DC_SP_MAC((u_int16_t *)IF_LLADDR(sc->dc_ifp) + 1);
|
|
|
|
sp[41] = DC_SP_MAC((u_int16_t *)IF_LLADDR(sc->dc_ifp) + 2);
|
1999-12-04 17:41:31 +00:00
|
|
|
|
2003-07-09 15:03:10 +00:00
|
|
|
sframe->dc_status = htole32(DC_TXSTAT_OWN);
|
1999-12-04 17:41:31 +00:00
|
|
|
CSR_WRITE_4(sc, DC_TXSTART, 0xFFFFFFFF);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The PNIC takes an exceedingly long time to process its
|
|
|
|
* setup frame; wait 10ms after posting the setup frame
|
|
|
|
* before proceeding, just so it has time to swallow its
|
|
|
|
* medicine.
|
|
|
|
*/
|
|
|
|
DELAY(10000);
|
|
|
|
|
|
|
|
ifp->if_timer = 5;
|
|
|
|
}
|
|
|
|
|
2002-10-16 09:04:52 +00:00
|
|
|
static void
|
2003-06-01 19:26:34 +00:00
|
|
|
dc_setfilt_admtek(struct dc_softc *sc)
|
1999-12-04 17:41:31 +00:00
|
|
|
{
|
2003-06-01 19:26:34 +00:00
|
|
|
struct ifnet *ifp;
|
|
|
|
struct ifmultiaddr *ifma;
|
|
|
|
int h = 0;
|
|
|
|
u_int32_t hashes[2] = { 0, 0 };
|
1999-12-04 17:41:31 +00:00
|
|
|
|
2005-06-10 16:49:24 +00:00
|
|
|
ifp = sc->dc_ifp;
|
1999-12-04 17:41:31 +00:00
|
|
|
|
2003-06-01 19:26:34 +00:00
|
|
|
/* Init our MAC address. */
|
2005-11-11 16:04:59 +00:00
|
|
|
CSR_WRITE_4(sc, DC_AL_PAR0, *(u_int32_t *)(&IF_LLADDR(sc->dc_ifp)[0]));
|
|
|
|
CSR_WRITE_4(sc, DC_AL_PAR1, *(u_int32_t *)(&IF_LLADDR(sc->dc_ifp)[4]));
|
1999-12-04 17:41:31 +00:00
|
|
|
|
|
|
|
/* If we want promiscuous mode, set the allframes bit. */
|
|
|
|
if (ifp->if_flags & IFF_PROMISC)
|
|
|
|
DC_SETBIT(sc, DC_NETCFG, DC_NETCFG_RX_PROMISC);
|
|
|
|
else
|
|
|
|
DC_CLRBIT(sc, DC_NETCFG, DC_NETCFG_RX_PROMISC);
|
|
|
|
|
|
|
|
if (ifp->if_flags & IFF_ALLMULTI)
|
|
|
|
DC_SETBIT(sc, DC_NETCFG, DC_NETCFG_RX_ALLMULTI);
|
|
|
|
else
|
|
|
|
DC_CLRBIT(sc, DC_NETCFG, DC_NETCFG_RX_ALLMULTI);
|
|
|
|
|
2003-06-01 19:26:34 +00:00
|
|
|
/* First, zot all the existing hash bits. */
|
1999-12-04 17:41:31 +00:00
|
|
|
CSR_WRITE_4(sc, DC_AL_MAR0, 0);
|
|
|
|
CSR_WRITE_4(sc, DC_AL_MAR1, 0);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If we're already in promisc or allmulti mode, we
|
|
|
|
* don't have to bother programming the multicast filter.
|
|
|
|
*/
|
2003-06-01 19:26:34 +00:00
|
|
|
if (ifp->if_flags & (IFF_PROMISC | IFF_ALLMULTI))
|
1999-12-04 17:41:31 +00:00
|
|
|
return;
|
|
|
|
|
2003-06-01 19:26:34 +00:00
|
|
|
/* Now program new ones. */
|
2005-08-03 00:18:35 +00:00
|
|
|
IF_ADDR_LOCK(ifp);
|
2001-02-06 10:12:15 +00:00
|
|
|
TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
|
1999-12-04 17:41:31 +00:00
|
|
|
if (ifma->ifma_addr->sa_family != AF_LINK)
|
|
|
|
continue;
|
2003-05-01 09:31:01 +00:00
|
|
|
if (DC_IS_CENTAUR(sc))
|
2003-11-13 20:55:53 +00:00
|
|
|
h = dc_mchash_le(sc,
|
|
|
|
LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
|
2003-05-01 09:31:01 +00:00
|
|
|
else
|
2003-11-13 20:55:53 +00:00
|
|
|
h = dc_mchash_be(
|
|
|
|
LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
|
1999-12-04 17:41:31 +00:00
|
|
|
if (h < 32)
|
|
|
|
hashes[0] |= (1 << h);
|
|
|
|
else
|
|
|
|
hashes[1] |= (1 << (h - 32));
|
|
|
|
}
|
2005-08-03 00:18:35 +00:00
|
|
|
IF_ADDR_UNLOCK(ifp);
|
1999-12-04 17:41:31 +00:00
|
|
|
|
|
|
|
CSR_WRITE_4(sc, DC_AL_MAR0, hashes[0]);
|
|
|
|
CSR_WRITE_4(sc, DC_AL_MAR1, hashes[1]);
|
|
|
|
}
|
|
|
|
|
2002-10-16 09:04:52 +00:00
|
|
|
static void
|
2003-06-01 19:26:34 +00:00
|
|
|
dc_setfilt_asix(struct dc_softc *sc)
|
1999-12-04 17:41:31 +00:00
|
|
|
{
|
2003-06-01 19:26:34 +00:00
|
|
|
struct ifnet *ifp;
|
|
|
|
struct ifmultiaddr *ifma;
|
|
|
|
int h = 0;
|
|
|
|
u_int32_t hashes[2] = { 0, 0 };
|
1999-12-04 17:41:31 +00:00
|
|
|
|
2005-06-10 16:49:24 +00:00
|
|
|
ifp = sc->dc_ifp;
|
1999-12-04 17:41:31 +00:00
|
|
|
|
2002-09-04 18:14:17 +00:00
|
|
|
/* Init our MAC address */
|
|
|
|
CSR_WRITE_4(sc, DC_AX_FILTIDX, DC_AX_FILTIDX_PAR0);
|
|
|
|
CSR_WRITE_4(sc, DC_AX_FILTDATA,
|
2005-11-11 16:04:59 +00:00
|
|
|
*(u_int32_t *)(&IF_LLADDR(sc->dc_ifp)[0]));
|
2002-09-04 18:14:17 +00:00
|
|
|
CSR_WRITE_4(sc, DC_AX_FILTIDX, DC_AX_FILTIDX_PAR1);
|
|
|
|
CSR_WRITE_4(sc, DC_AX_FILTDATA,
|
2005-11-11 16:04:59 +00:00
|
|
|
*(u_int32_t *)(&IF_LLADDR(sc->dc_ifp)[4]));
|
1999-12-04 17:41:31 +00:00
|
|
|
|
|
|
|
/* If we want promiscuous mode, set the allframes bit. */
|
|
|
|
if (ifp->if_flags & IFF_PROMISC)
|
|
|
|
DC_SETBIT(sc, DC_NETCFG, DC_NETCFG_RX_PROMISC);
|
|
|
|
else
|
|
|
|
DC_CLRBIT(sc, DC_NETCFG, DC_NETCFG_RX_PROMISC);
|
|
|
|
|
|
|
|
if (ifp->if_flags & IFF_ALLMULTI)
|
|
|
|
DC_SETBIT(sc, DC_NETCFG, DC_NETCFG_RX_ALLMULTI);
|
|
|
|
else
|
|
|
|
DC_CLRBIT(sc, DC_NETCFG, DC_NETCFG_RX_ALLMULTI);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The ASIX chip has a special bit to enable reception
|
|
|
|
* of broadcast frames.
|
|
|
|
*/
|
|
|
|
if (ifp->if_flags & IFF_BROADCAST)
|
|
|
|
DC_SETBIT(sc, DC_NETCFG, DC_AX_NETCFG_RX_BROAD);
|
|
|
|
else
|
|
|
|
DC_CLRBIT(sc, DC_NETCFG, DC_AX_NETCFG_RX_BROAD);
|
|
|
|
|
|
|
|
/* first, zot all the existing hash bits */
|
|
|
|
CSR_WRITE_4(sc, DC_AX_FILTIDX, DC_AX_FILTIDX_MAR0);
|
|
|
|
CSR_WRITE_4(sc, DC_AX_FILTDATA, 0);
|
|
|
|
CSR_WRITE_4(sc, DC_AX_FILTIDX, DC_AX_FILTIDX_MAR1);
|
|
|
|
CSR_WRITE_4(sc, DC_AX_FILTDATA, 0);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If we're already in promisc or allmulti mode, we
|
|
|
|
* don't have to bother programming the multicast filter.
|
|
|
|
*/
|
2003-06-01 19:26:34 +00:00
|
|
|
if (ifp->if_flags & (IFF_PROMISC | IFF_ALLMULTI))
|
1999-12-04 17:41:31 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
/* now program new ones */
|
2005-08-03 00:18:35 +00:00
|
|
|
IF_ADDR_LOCK(ifp);
|
2001-02-06 10:12:15 +00:00
|
|
|
TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
|
1999-12-04 17:41:31 +00:00
|
|
|
if (ifma->ifma_addr->sa_family != AF_LINK)
|
|
|
|
continue;
|
2003-11-13 20:55:53 +00:00
|
|
|
h = dc_mchash_be(LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
|
1999-12-04 17:41:31 +00:00
|
|
|
if (h < 32)
|
|
|
|
hashes[0] |= (1 << h);
|
|
|
|
else
|
|
|
|
hashes[1] |= (1 << (h - 32));
|
|
|
|
}
|
2005-08-03 00:18:35 +00:00
|
|
|
IF_ADDR_UNLOCK(ifp);
|
1999-12-04 17:41:31 +00:00
|
|
|
|
|
|
|
CSR_WRITE_4(sc, DC_AX_FILTIDX, DC_AX_FILTIDX_MAR0);
|
|
|
|
CSR_WRITE_4(sc, DC_AX_FILTDATA, hashes[0]);
|
|
|
|
CSR_WRITE_4(sc, DC_AX_FILTIDX, DC_AX_FILTIDX_MAR1);
|
|
|
|
CSR_WRITE_4(sc, DC_AX_FILTDATA, hashes[1]);
|
|
|
|
}
|
|
|
|
|
2002-10-16 09:04:52 +00:00
|
|
|
static void
|
2003-06-01 19:26:34 +00:00
|
|
|
dc_setfilt_xircom(struct dc_softc *sc)
|
2000-10-19 08:34:32 +00:00
|
|
|
{
|
2003-06-01 19:26:34 +00:00
|
|
|
struct ifnet *ifp;
|
|
|
|
struct ifmultiaddr *ifma;
|
|
|
|
struct dc_desc *sframe;
|
|
|
|
u_int32_t h, *sp;
|
|
|
|
int i;
|
2000-10-19 08:34:32 +00:00
|
|
|
|
2005-06-10 16:49:24 +00:00
|
|
|
ifp = sc->dc_ifp;
|
2003-06-01 19:26:34 +00:00
|
|
|
DC_CLRBIT(sc, DC_NETCFG, (DC_NETCFG_TX_ON | DC_NETCFG_RX_ON));
|
2000-10-19 08:34:32 +00:00
|
|
|
|
|
|
|
i = sc->dc_cdata.dc_tx_prod;
|
|
|
|
DC_INC(sc->dc_cdata.dc_tx_prod, DC_TX_LIST_CNT);
|
|
|
|
sc->dc_cdata.dc_tx_cnt++;
|
|
|
|
sframe = &sc->dc_ldata->dc_tx_list[i];
|
2003-07-06 21:45:31 +00:00
|
|
|
sp = sc->dc_cdata.dc_sbuf;
|
2003-06-01 19:26:34 +00:00
|
|
|
bzero(sp, DC_SFRAME_LEN);
|
2000-10-19 08:34:32 +00:00
|
|
|
|
2003-07-09 15:03:10 +00:00
|
|
|
sframe->dc_data = htole32(sc->dc_saddr);
|
|
|
|
sframe->dc_ctl = htole32(DC_SFRAME_LEN | DC_TXCTL_SETUP |
|
|
|
|
DC_TXCTL_TLINK | DC_FILTER_HASHPERF | DC_TXCTL_FINT);
|
2000-10-19 08:34:32 +00:00
|
|
|
|
2003-07-06 21:45:31 +00:00
|
|
|
sc->dc_cdata.dc_tx_chain[i] = (struct mbuf *)sc->dc_cdata.dc_sbuf;
|
2000-10-19 08:34:32 +00:00
|
|
|
|
|
|
|
/* If we want promiscuous mode, set the allframes bit. */
|
|
|
|
if (ifp->if_flags & IFF_PROMISC)
|
|
|
|
DC_SETBIT(sc, DC_NETCFG, DC_NETCFG_RX_PROMISC);
|
|
|
|
else
|
|
|
|
DC_CLRBIT(sc, DC_NETCFG, DC_NETCFG_RX_PROMISC);
|
|
|
|
|
|
|
|
if (ifp->if_flags & IFF_ALLMULTI)
|
2002-09-04 18:14:17 +00:00
|
|
|
DC_SETBIT(sc, DC_NETCFG, DC_NETCFG_RX_ALLMULTI);
|
2000-10-19 08:34:32 +00:00
|
|
|
else
|
|
|
|
DC_CLRBIT(sc, DC_NETCFG, DC_NETCFG_RX_ALLMULTI);
|
|
|
|
|
2005-08-03 00:18:35 +00:00
|
|
|
IF_ADDR_LOCK(ifp);
|
2001-02-06 10:12:15 +00:00
|
|
|
TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
|
2000-10-19 08:34:32 +00:00
|
|
|
if (ifma->ifma_addr->sa_family != AF_LINK)
|
|
|
|
continue;
|
2003-11-13 20:55:53 +00:00
|
|
|
h = dc_mchash_le(sc,
|
2000-10-28 09:00:20 +00:00
|
|
|
LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
|
2003-07-09 15:03:10 +00:00
|
|
|
sp[h >> 4] |= htole32(1 << (h & 0xF));
|
2000-10-19 08:34:32 +00:00
|
|
|
}
|
2005-08-03 00:18:35 +00:00
|
|
|
IF_ADDR_UNLOCK(ifp);
|
2000-10-19 08:34:32 +00:00
|
|
|
|
|
|
|
if (ifp->if_flags & IFF_BROADCAST) {
|
2003-11-13 20:55:53 +00:00
|
|
|
h = dc_mchash_le(sc, ifp->if_broadcastaddr);
|
2003-07-09 15:03:10 +00:00
|
|
|
sp[h >> 4] |= htole32(1 << (h & 0xF));
|
2000-10-19 08:34:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Set our MAC address */
|
2005-11-22 01:51:57 +00:00
|
|
|
sp[0] = DC_SP_MAC((u_int16_t *)IF_LLADDR(sc->dc_ifp) + 0);
|
|
|
|
sp[1] = DC_SP_MAC((u_int16_t *)IF_LLADDR(sc->dc_ifp) + 1);
|
|
|
|
sp[2] = DC_SP_MAC((u_int16_t *)IF_LLADDR(sc->dc_ifp) + 2);
|
2003-06-01 19:26:34 +00:00
|
|
|
|
2000-10-19 08:34:32 +00:00
|
|
|
DC_SETBIT(sc, DC_NETCFG, DC_NETCFG_TX_ON);
|
|
|
|
DC_SETBIT(sc, DC_NETCFG, DC_NETCFG_RX_ON);
|
2005-08-09 10:20:02 +00:00
|
|
|
ifp->if_drv_flags |= IFF_DRV_RUNNING;
|
2003-07-09 15:03:10 +00:00
|
|
|
sframe->dc_status = htole32(DC_TXSTAT_OWN);
|
2000-10-19 08:34:32 +00:00
|
|
|
CSR_WRITE_4(sc, DC_TXSTART, 0xFFFFFFFF);
|
|
|
|
|
|
|
|
/*
|
2003-06-01 19:26:34 +00:00
|
|
|
* Wait some time...
|
2000-10-19 08:34:32 +00:00
|
|
|
*/
|
|
|
|
DELAY(1000);
|
|
|
|
|
|
|
|
ifp->if_timer = 5;
|
|
|
|
}
|
|
|
|
|
2002-08-23 23:49:02 +00:00
|
|
|
static void
|
2003-06-01 19:26:34 +00:00
|
|
|
dc_setfilt(struct dc_softc *sc)
|
1999-12-04 17:41:31 +00:00
|
|
|
{
|
2003-06-01 19:26:34 +00:00
|
|
|
|
1999-12-04 17:41:31 +00:00
|
|
|
if (DC_IS_INTEL(sc) || DC_IS_MACRONIX(sc) || DC_IS_PNIC(sc) ||
|
2001-09-04 17:10:11 +00:00
|
|
|
DC_IS_PNICII(sc) || DC_IS_DAVICOM(sc) || DC_IS_CONEXANT(sc))
|
1999-12-04 17:41:31 +00:00
|
|
|
dc_setfilt_21143(sc);
|
|
|
|
|
|
|
|
if (DC_IS_ASIX(sc))
|
|
|
|
dc_setfilt_asix(sc);
|
|
|
|
|
|
|
|
if (DC_IS_ADMTEK(sc))
|
|
|
|
dc_setfilt_admtek(sc);
|
|
|
|
|
2000-10-19 08:34:32 +00:00
|
|
|
if (DC_IS_XIRCOM(sc))
|
|
|
|
dc_setfilt_xircom(sc);
|
1999-12-04 17:41:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2003-06-01 19:26:34 +00:00
|
|
|
* In order to fiddle with the 'full-duplex' and '100Mbps' bits in
|
|
|
|
* the netconfig register, we first have to put the transmit and/or
|
|
|
|
* receive logic in the idle state.
|
1999-12-04 17:41:31 +00:00
|
|
|
*/
|
2002-08-23 23:49:02 +00:00
|
|
|
static void
|
2003-06-01 19:26:34 +00:00
|
|
|
dc_setcfg(struct dc_softc *sc, int media)
|
1999-12-04 17:41:31 +00:00
|
|
|
{
|
2003-06-01 19:26:34 +00:00
|
|
|
int i, restart = 0, watchdogreg;
|
|
|
|
u_int32_t isr;
|
1999-12-04 17:41:31 +00:00
|
|
|
|
|
|
|
if (IFM_SUBTYPE(media) == IFM_NONE)
|
|
|
|
return;
|
|
|
|
|
2003-06-01 19:26:34 +00:00
|
|
|
if (CSR_READ_4(sc, DC_NETCFG) & (DC_NETCFG_TX_ON | DC_NETCFG_RX_ON)) {
|
1999-12-04 17:41:31 +00:00
|
|
|
restart = 1;
|
2003-06-01 19:26:34 +00:00
|
|
|
DC_CLRBIT(sc, DC_NETCFG, (DC_NETCFG_TX_ON | DC_NETCFG_RX_ON));
|
1999-12-04 17:41:31 +00:00
|
|
|
|
|
|
|
for (i = 0; i < DC_TIMEOUT; i++) {
|
|
|
|
isr = CSR_READ_4(sc, DC_ISR);
|
2001-02-22 19:26:55 +00:00
|
|
|
if (isr & DC_ISR_TX_IDLE &&
|
2002-09-20 15:18:13 +00:00
|
|
|
((isr & DC_ISR_RX_STATE) == DC_RXSTATE_STOPPED ||
|
|
|
|
(isr & DC_ISR_RX_STATE) == DC_RXSTATE_WAIT))
|
1999-12-04 17:41:31 +00:00
|
|
|
break;
|
2001-02-22 19:26:55 +00:00
|
|
|
DELAY(10);
|
1999-12-04 17:41:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (i == DC_TIMEOUT)
|
2005-08-10 20:33:46 +00:00
|
|
|
if_printf(sc->dc_ifp,
|
|
|
|
"failed to force tx and rx to idle state\n");
|
1999-12-04 17:41:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (IFM_SUBTYPE(media) == IFM_100_TX) {
|
2000-06-07 17:07:44 +00:00
|
|
|
DC_CLRBIT(sc, DC_NETCFG, DC_NETCFG_SPEEDSEL);
|
|
|
|
DC_SETBIT(sc, DC_NETCFG, DC_NETCFG_HEARTBEAT);
|
1999-12-04 17:41:31 +00:00
|
|
|
if (sc->dc_pmode == DC_PMODE_MII) {
|
2000-08-07 17:03:20 +00:00
|
|
|
if (DC_IS_INTEL(sc)) {
|
2003-06-01 19:26:34 +00:00
|
|
|
/* There's a write enable bit here that reads as 1. */
|
2000-08-07 17:03:20 +00:00
|
|
|
watchdogreg = CSR_READ_4(sc, DC_WATCHDOG);
|
|
|
|
watchdogreg &= ~DC_WDOG_CTLWREN;
|
|
|
|
watchdogreg |= DC_WDOG_JABBERDIS;
|
2000-10-14 00:40:14 +00:00
|
|
|
CSR_WRITE_4(sc, DC_WATCHDOG, watchdogreg);
|
2000-08-07 17:03:20 +00:00
|
|
|
} else {
|
|
|
|
DC_SETBIT(sc, DC_WATCHDOG, DC_WDOG_JABBERDIS);
|
|
|
|
}
|
2003-06-01 19:26:34 +00:00
|
|
|
DC_CLRBIT(sc, DC_NETCFG, (DC_NETCFG_PCS |
|
|
|
|
DC_NETCFG_PORTSEL | DC_NETCFG_SCRAMBLER));
|
1999-12-04 17:41:31 +00:00
|
|
|
if (sc->dc_type == DC_TYPE_98713)
|
2003-06-01 19:26:34 +00:00
|
|
|
DC_SETBIT(sc, DC_NETCFG, (DC_NETCFG_PCS |
|
1999-12-04 17:41:31 +00:00
|
|
|
DC_NETCFG_SCRAMBLER));
|
2000-01-19 19:03:08 +00:00
|
|
|
if (!DC_IS_DAVICOM(sc))
|
|
|
|
DC_SETBIT(sc, DC_NETCFG, DC_NETCFG_PORTSEL);
|
1999-12-04 17:41:31 +00:00
|
|
|
DC_CLRBIT(sc, DC_10BTCTRL, 0xFFFF);
|
2000-10-31 00:06:39 +00:00
|
|
|
if (DC_IS_INTEL(sc))
|
|
|
|
dc_apply_fixup(sc, IFM_AUTO);
|
1999-12-04 17:41:31 +00:00
|
|
|
} else {
|
|
|
|
if (DC_IS_PNIC(sc)) {
|
|
|
|
DC_PN_GPIO_SETBIT(sc, DC_PN_GPIO_SPEEDSEL);
|
|
|
|
DC_PN_GPIO_SETBIT(sc, DC_PN_GPIO_100TX_LOOP);
|
|
|
|
DC_SETBIT(sc, DC_PN_NWAY, DC_PN_NWAY_SPEEDSEL);
|
|
|
|
}
|
2000-05-31 05:40:53 +00:00
|
|
|
DC_SETBIT(sc, DC_NETCFG, DC_NETCFG_PORTSEL);
|
|
|
|
DC_SETBIT(sc, DC_NETCFG, DC_NETCFG_PCS);
|
|
|
|
DC_SETBIT(sc, DC_NETCFG, DC_NETCFG_SCRAMBLER);
|
2000-10-05 17:36:14 +00:00
|
|
|
if (DC_IS_INTEL(sc))
|
|
|
|
dc_apply_fixup(sc,
|
|
|
|
(media & IFM_GMASK) == IFM_FDX ?
|
2003-06-01 19:26:34 +00:00
|
|
|
IFM_100_TX | IFM_FDX : IFM_100_TX);
|
1999-12-04 17:41:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IFM_SUBTYPE(media) == IFM_10_T) {
|
2000-06-07 17:07:44 +00:00
|
|
|
DC_SETBIT(sc, DC_NETCFG, DC_NETCFG_SPEEDSEL);
|
|
|
|
DC_CLRBIT(sc, DC_NETCFG, DC_NETCFG_HEARTBEAT);
|
1999-12-04 17:41:31 +00:00
|
|
|
if (sc->dc_pmode == DC_PMODE_MII) {
|
2003-06-01 19:26:34 +00:00
|
|
|
/* There's a write enable bit here that reads as 1. */
|
2000-10-14 00:40:14 +00:00
|
|
|
if (DC_IS_INTEL(sc)) {
|
|
|
|
watchdogreg = CSR_READ_4(sc, DC_WATCHDOG);
|
|
|
|
watchdogreg &= ~DC_WDOG_CTLWREN;
|
|
|
|
watchdogreg |= DC_WDOG_JABBERDIS;
|
|
|
|
CSR_WRITE_4(sc, DC_WATCHDOG, watchdogreg);
|
|
|
|
} else {
|
|
|
|
DC_SETBIT(sc, DC_WATCHDOG, DC_WDOG_JABBERDIS);
|
|
|
|
}
|
2003-06-01 19:26:34 +00:00
|
|
|
DC_CLRBIT(sc, DC_NETCFG, (DC_NETCFG_PCS |
|
|
|
|
DC_NETCFG_PORTSEL | DC_NETCFG_SCRAMBLER));
|
1999-12-04 17:41:31 +00:00
|
|
|
if (sc->dc_type == DC_TYPE_98713)
|
|
|
|
DC_SETBIT(sc, DC_NETCFG, DC_NETCFG_PCS);
|
2000-01-19 19:03:08 +00:00
|
|
|
if (!DC_IS_DAVICOM(sc))
|
|
|
|
DC_SETBIT(sc, DC_NETCFG, DC_NETCFG_PORTSEL);
|
1999-12-04 17:41:31 +00:00
|
|
|
DC_CLRBIT(sc, DC_10BTCTRL, 0xFFFF);
|
2000-10-31 00:06:39 +00:00
|
|
|
if (DC_IS_INTEL(sc))
|
|
|
|
dc_apply_fixup(sc, IFM_AUTO);
|
1999-12-04 17:41:31 +00:00
|
|
|
} else {
|
|
|
|
if (DC_IS_PNIC(sc)) {
|
|
|
|
DC_PN_GPIO_CLRBIT(sc, DC_PN_GPIO_SPEEDSEL);
|
|
|
|
DC_PN_GPIO_SETBIT(sc, DC_PN_GPIO_100TX_LOOP);
|
|
|
|
DC_CLRBIT(sc, DC_PN_NWAY, DC_PN_NWAY_SPEEDSEL);
|
|
|
|
}
|
|
|
|
DC_CLRBIT(sc, DC_NETCFG, DC_NETCFG_PORTSEL);
|
2000-05-31 05:40:53 +00:00
|
|
|
DC_CLRBIT(sc, DC_NETCFG, DC_NETCFG_PCS);
|
1999-12-04 17:41:31 +00:00
|
|
|
DC_CLRBIT(sc, DC_NETCFG, DC_NETCFG_SCRAMBLER);
|
2000-10-05 17:36:14 +00:00
|
|
|
if (DC_IS_INTEL(sc)) {
|
|
|
|
DC_CLRBIT(sc, DC_SIARESET, DC_SIA_RESET);
|
|
|
|
DC_CLRBIT(sc, DC_10BTCTRL, 0xFFFF);
|
|
|
|
if ((media & IFM_GMASK) == IFM_FDX)
|
|
|
|
DC_SETBIT(sc, DC_10BTCTRL, 0x7F3D);
|
|
|
|
else
|
|
|
|
DC_SETBIT(sc, DC_10BTCTRL, 0x7F3F);
|
|
|
|
DC_SETBIT(sc, DC_SIARESET, DC_SIA_RESET);
|
|
|
|
DC_CLRBIT(sc, DC_10BTCTRL,
|
|
|
|
DC_TCTL_AUTONEGENBL);
|
|
|
|
dc_apply_fixup(sc,
|
|
|
|
(media & IFM_GMASK) == IFM_FDX ?
|
2003-06-01 19:26:34 +00:00
|
|
|
IFM_10_T | IFM_FDX : IFM_10_T);
|
2000-10-05 17:36:14 +00:00
|
|
|
DELAY(20000);
|
|
|
|
}
|
1999-12-04 17:41:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-01-24 17:19:37 +00:00
|
|
|
/*
|
|
|
|
* If this is a Davicom DM9102A card with a DM9801 HomePNA
|
|
|
|
* PHY and we want HomePNA mode, set the portsel bit to turn
|
|
|
|
* on the external MII port.
|
|
|
|
*/
|
|
|
|
if (DC_IS_DAVICOM(sc)) {
|
2002-04-29 05:32:44 +00:00
|
|
|
if (IFM_SUBTYPE(media) == IFM_HPNA_1) {
|
2000-01-24 17:19:37 +00:00
|
|
|
DC_SETBIT(sc, DC_NETCFG, DC_NETCFG_PORTSEL);
|
|
|
|
sc->dc_link = 1;
|
|
|
|
} else {
|
|
|
|
DC_CLRBIT(sc, DC_NETCFG, DC_NETCFG_PORTSEL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-12-04 17:41:31 +00:00
|
|
|
if ((media & IFM_GMASK) == IFM_FDX) {
|
|
|
|
DC_SETBIT(sc, DC_NETCFG, DC_NETCFG_FULLDUPLEX);
|
|
|
|
if (sc->dc_pmode == DC_PMODE_SYM && DC_IS_PNIC(sc))
|
|
|
|
DC_SETBIT(sc, DC_PN_NWAY, DC_PN_NWAY_DUPLEX);
|
|
|
|
} else {
|
|
|
|
DC_CLRBIT(sc, DC_NETCFG, DC_NETCFG_FULLDUPLEX);
|
|
|
|
if (sc->dc_pmode == DC_PMODE_SYM && DC_IS_PNIC(sc))
|
|
|
|
DC_CLRBIT(sc, DC_PN_NWAY, DC_PN_NWAY_DUPLEX);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (restart)
|
2003-06-01 19:26:34 +00:00
|
|
|
DC_SETBIT(sc, DC_NETCFG, DC_NETCFG_TX_ON | DC_NETCFG_RX_ON);
|
1999-12-04 17:41:31 +00:00
|
|
|
}
|
|
|
|
|
2002-08-23 23:49:02 +00:00
|
|
|
static void
|
2003-06-01 19:26:34 +00:00
|
|
|
dc_reset(struct dc_softc *sc)
|
1999-12-04 17:41:31 +00:00
|
|
|
{
|
2003-06-01 19:26:34 +00:00
|
|
|
int i;
|
1999-12-04 17:41:31 +00:00
|
|
|
|
|
|
|
DC_SETBIT(sc, DC_BUSCTL, DC_BUSCTL_RESET);
|
|
|
|
|
|
|
|
for (i = 0; i < DC_TIMEOUT; i++) {
|
|
|
|
DELAY(10);
|
|
|
|
if (!(CSR_READ_4(sc, DC_BUSCTL) & DC_BUSCTL_RESET))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2001-09-04 17:10:11 +00:00
|
|
|
if (DC_IS_ASIX(sc) || DC_IS_ADMTEK(sc) || DC_IS_CONEXANT(sc) ||
|
2000-10-28 09:00:20 +00:00
|
|
|
DC_IS_XIRCOM(sc) || DC_IS_INTEL(sc)) {
|
1999-12-04 17:41:31 +00:00
|
|
|
DELAY(10000);
|
|
|
|
DC_CLRBIT(sc, DC_BUSCTL, DC_BUSCTL_RESET);
|
|
|
|
i = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i == DC_TIMEOUT)
|
2005-08-10 20:33:46 +00:00
|
|
|
if_printf(sc->dc_ifp, "reset never completed!\n");
|
1999-12-04 17:41:31 +00:00
|
|
|
|
|
|
|
/* Wait a little while for the chip to get its brains in order. */
|
|
|
|
DELAY(1000);
|
|
|
|
|
|
|
|
CSR_WRITE_4(sc, DC_IMR, 0x00000000);
|
|
|
|
CSR_WRITE_4(sc, DC_BUSCTL, 0x00000000);
|
|
|
|
CSR_WRITE_4(sc, DC_NETCFG, 0x00000000);
|
|
|
|
|
1999-12-13 21:45:13 +00:00
|
|
|
/*
|
|
|
|
* Bring the SIA out of reset. In some cases, it looks
|
|
|
|
* like failing to unreset the SIA soon enough gets it
|
|
|
|
* into a state where it will never come out of reset
|
|
|
|
* until we reset the whole chip again.
|
|
|
|
*/
|
2000-10-05 17:36:14 +00:00
|
|
|
if (DC_IS_INTEL(sc)) {
|
1999-12-13 21:45:13 +00:00
|
|
|
DC_SETBIT(sc, DC_SIARESET, DC_SIA_RESET);
|
2000-10-05 17:36:14 +00:00
|
|
|
CSR_WRITE_4(sc, DC_10BTCTRL, 0);
|
|
|
|
CSR_WRITE_4(sc, DC_WATCHDOG, 0);
|
|
|
|
}
|
1999-12-04 17:41:31 +00:00
|
|
|
}
|
|
|
|
|
2002-08-23 23:49:02 +00:00
|
|
|
static struct dc_type *
|
2003-06-01 19:26:34 +00:00
|
|
|
dc_devtype(device_t dev)
|
1999-12-04 17:41:31 +00:00
|
|
|
{
|
2003-06-01 19:26:34 +00:00
|
|
|
struct dc_type *t;
|
|
|
|
u_int32_t rev;
|
1999-12-04 17:41:31 +00:00
|
|
|
|
|
|
|
t = dc_devs;
|
|
|
|
|
2003-06-01 19:26:34 +00:00
|
|
|
while (t->dc_name != NULL) {
|
1999-12-04 17:41:31 +00:00
|
|
|
if ((pci_get_vendor(dev) == t->dc_vid) &&
|
|
|
|
(pci_get_device(dev) == t->dc_did)) {
|
|
|
|
/* Check the PCI revision */
|
|
|
|
rev = pci_read_config(dev, DC_PCI_CFRV, 4) & 0xFF;
|
|
|
|
if (t->dc_did == DC_DEVICEID_98713 &&
|
|
|
|
rev >= DC_REVISION_98713A)
|
|
|
|
t++;
|
|
|
|
if (t->dc_did == DC_DEVICEID_98713_CP &&
|
|
|
|
rev >= DC_REVISION_98713A)
|
|
|
|
t++;
|
2000-07-15 17:54:30 +00:00
|
|
|
if (t->dc_did == DC_DEVICEID_987x5 &&
|
|
|
|
rev >= DC_REVISION_98715AEC_C)
|
|
|
|
t++;
|
1999-12-04 17:41:31 +00:00
|
|
|
if (t->dc_did == DC_DEVICEID_987x5 &&
|
|
|
|
rev >= DC_REVISION_98725)
|
|
|
|
t++;
|
|
|
|
if (t->dc_did == DC_DEVICEID_AX88140A &&
|
|
|
|
rev >= DC_REVISION_88141)
|
|
|
|
t++;
|
|
|
|
if (t->dc_did == DC_DEVICEID_82C168 &&
|
|
|
|
rev >= DC_REVISION_82C169)
|
|
|
|
t++;
|
2000-01-19 19:03:08 +00:00
|
|
|
if (t->dc_did == DC_DEVICEID_DM9102 &&
|
|
|
|
rev >= DC_REVISION_DM9102A)
|
|
|
|
t++;
|
2003-07-10 18:43:17 +00:00
|
|
|
/*
|
|
|
|
* The Microsoft MN-130 has a device ID of 0x0002,
|
|
|
|
* which happens to be the same as the PNIC 82c168.
|
|
|
|
* To keep dc_attach() from getting confused, we
|
|
|
|
* pretend its ID is something different.
|
|
|
|
* XXX: ideally, dc_attach() should be checking
|
|
|
|
* vendorid+deviceid together to avoid such
|
|
|
|
* collisions.
|
|
|
|
*/
|
|
|
|
if (t->dc_vid == DC_VENDORID_MICROSOFT &&
|
|
|
|
t->dc_did == DC_DEVICEID_MSMN130)
|
|
|
|
t++;
|
2003-06-01 19:26:34 +00:00
|
|
|
return (t);
|
1999-12-04 17:41:31 +00:00
|
|
|
}
|
|
|
|
t++;
|
|
|
|
}
|
|
|
|
|
2003-06-01 19:26:34 +00:00
|
|
|
return (NULL);
|
1999-12-04 17:41:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Probe for a 21143 or clone chip. Check the PCI vendor and device
|
|
|
|
* IDs against our list and return a device name if we find a match.
|
|
|
|
* We do a little bit of extra work to identify the exact type of
|
|
|
|
* chip. The MX98713 and MX98713A have the same PCI vendor/device ID,
|
|
|
|
* but different revision IDs. The same is true for 98715/98715A
|
|
|
|
* chips and the 98725, as well as the ASIX and ADMtek chips. In some
|
|
|
|
* cases, the exact chip revision affects driver behavior.
|
|
|
|
*/
|
2002-08-23 23:49:02 +00:00
|
|
|
static int
|
2003-06-01 19:26:34 +00:00
|
|
|
dc_probe(device_t dev)
|
1999-12-04 17:41:31 +00:00
|
|
|
{
|
2003-06-01 19:26:34 +00:00
|
|
|
struct dc_type *t;
|
1999-12-04 17:41:31 +00:00
|
|
|
|
|
|
|
t = dc_devtype(dev);
|
|
|
|
|
|
|
|
if (t != NULL) {
|
|
|
|
device_set_desc(dev, t->dc_name);
|
2005-02-24 21:32:56 +00:00
|
|
|
return (BUS_PROBE_DEFAULT);
|
1999-12-04 17:41:31 +00:00
|
|
|
}
|
|
|
|
|
2003-06-01 19:26:34 +00:00
|
|
|
return (ENXIO);
|
1999-12-04 17:41:31 +00:00
|
|
|
}
|
|
|
|
|
2002-08-23 23:49:02 +00:00
|
|
|
static void
|
2003-06-01 19:26:34 +00:00
|
|
|
dc_apply_fixup(struct dc_softc *sc, int media)
|
2000-10-05 17:36:14 +00:00
|
|
|
{
|
2003-06-01 19:26:34 +00:00
|
|
|
struct dc_mediainfo *m;
|
|
|
|
u_int8_t *p;
|
|
|
|
int i;
|
|
|
|
u_int32_t reg;
|
2000-10-05 17:36:14 +00:00
|
|
|
|
|
|
|
m = sc->dc_mi;
|
|
|
|
|
|
|
|
while (m != NULL) {
|
|
|
|
if (m->dc_media == media)
|
|
|
|
break;
|
|
|
|
m = m->dc_next;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (i = 0, p = m->dc_reset_ptr; i < m->dc_reset_len; i++, p += 2) {
|
|
|
|
reg = (p[0] | (p[1] << 8)) << 16;
|
|
|
|
CSR_WRITE_4(sc, DC_WATCHDOG, reg);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0, p = m->dc_gp_ptr; i < m->dc_gp_len; i++, p += 2) {
|
|
|
|
reg = (p[0] | (p[1] << 8)) << 16;
|
|
|
|
CSR_WRITE_4(sc, DC_WATCHDOG, reg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-08-23 23:49:02 +00:00
|
|
|
static void
|
2003-06-01 19:26:34 +00:00
|
|
|
dc_decode_leaf_sia(struct dc_softc *sc, struct dc_eblock_sia *l)
|
2000-10-05 17:36:14 +00:00
|
|
|
{
|
2003-06-01 19:26:34 +00:00
|
|
|
struct dc_mediainfo *m;
|
2000-10-05 17:36:14 +00:00
|
|
|
|
2003-06-01 19:26:34 +00:00
|
|
|
m = malloc(sizeof(struct dc_mediainfo), M_DEVBUF, M_NOWAIT | M_ZERO);
|
2003-10-05 19:57:10 +00:00
|
|
|
switch (l->dc_sia_code & ~DC_SIA_CODE_EXT) {
|
|
|
|
case DC_SIA_CODE_10BT:
|
2000-10-05 17:36:14 +00:00
|
|
|
m->dc_media = IFM_10_T;
|
2003-10-05 19:57:10 +00:00
|
|
|
break;
|
|
|
|
case DC_SIA_CODE_10BT_FDX:
|
2003-06-01 19:26:34 +00:00
|
|
|
m->dc_media = IFM_10_T | IFM_FDX;
|
2003-10-05 19:57:10 +00:00
|
|
|
break;
|
|
|
|
case DC_SIA_CODE_10B2:
|
2000-10-05 17:36:14 +00:00
|
|
|
m->dc_media = IFM_10_2;
|
2003-10-05 19:57:10 +00:00
|
|
|
break;
|
|
|
|
case DC_SIA_CODE_10B5:
|
2000-10-05 17:36:14 +00:00
|
|
|
m->dc_media = IFM_10_5;
|
2003-10-05 19:57:10 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2000-10-05 17:36:14 +00:00
|
|
|
|
2003-10-05 19:57:10 +00:00
|
|
|
/*
|
|
|
|
* We need to ignore CSR13, CSR14, CSR15 for SIA mode.
|
|
|
|
* Things apparently already work for cards that do
|
|
|
|
* supply Media Specific Data.
|
|
|
|
*/
|
|
|
|
if (l->dc_sia_code & DC_SIA_CODE_EXT) {
|
|
|
|
m->dc_gp_len = 2;
|
|
|
|
m->dc_gp_ptr =
|
|
|
|
(u_int8_t *)&l->dc_un.dc_sia_ext.dc_sia_gpio_ctl;
|
|
|
|
} else {
|
|
|
|
m->dc_gp_len = 2;
|
|
|
|
m->dc_gp_ptr =
|
|
|
|
(u_int8_t *)&l->dc_un.dc_sia_noext.dc_sia_gpio_ctl;
|
|
|
|
}
|
2000-10-05 17:36:14 +00:00
|
|
|
|
|
|
|
m->dc_next = sc->dc_mi;
|
|
|
|
sc->dc_mi = m;
|
|
|
|
|
|
|
|
sc->dc_pmode = DC_PMODE_SIA;
|
|
|
|
}
|
|
|
|
|
2002-08-23 23:49:02 +00:00
|
|
|
static void
|
2003-06-01 19:26:34 +00:00
|
|
|
dc_decode_leaf_sym(struct dc_softc *sc, struct dc_eblock_sym *l)
|
2000-10-05 17:36:14 +00:00
|
|
|
{
|
2003-06-01 19:26:34 +00:00
|
|
|
struct dc_mediainfo *m;
|
2000-10-05 17:36:14 +00:00
|
|
|
|
2003-06-01 19:26:34 +00:00
|
|
|
m = malloc(sizeof(struct dc_mediainfo), M_DEVBUF, M_NOWAIT | M_ZERO);
|
2000-10-05 17:36:14 +00:00
|
|
|
if (l->dc_sym_code == DC_SYM_CODE_100BT)
|
|
|
|
m->dc_media = IFM_100_TX;
|
|
|
|
|
|
|
|
if (l->dc_sym_code == DC_SYM_CODE_100BT_FDX)
|
2003-06-01 19:26:34 +00:00
|
|
|
m->dc_media = IFM_100_TX | IFM_FDX;
|
2000-10-05 17:36:14 +00:00
|
|
|
|
|
|
|
m->dc_gp_len = 2;
|
|
|
|
m->dc_gp_ptr = (u_int8_t *)&l->dc_sym_gpio_ctl;
|
|
|
|
|
|
|
|
m->dc_next = sc->dc_mi;
|
|
|
|
sc->dc_mi = m;
|
|
|
|
|
|
|
|
sc->dc_pmode = DC_PMODE_SYM;
|
|
|
|
}
|
|
|
|
|
2002-08-23 23:49:02 +00:00
|
|
|
static void
|
2003-06-01 19:26:34 +00:00
|
|
|
dc_decode_leaf_mii(struct dc_softc *sc, struct dc_eblock_mii *l)
|
2000-10-05 17:36:14 +00:00
|
|
|
{
|
2003-06-01 19:26:34 +00:00
|
|
|
struct dc_mediainfo *m;
|
|
|
|
u_int8_t *p;
|
2000-10-05 17:36:14 +00:00
|
|
|
|
2003-06-01 19:26:34 +00:00
|
|
|
m = malloc(sizeof(struct dc_mediainfo), M_DEVBUF, M_NOWAIT | M_ZERO);
|
2000-10-05 17:36:14 +00:00
|
|
|
/* We abuse IFM_AUTO to represent MII. */
|
|
|
|
m->dc_media = IFM_AUTO;
|
|
|
|
m->dc_gp_len = l->dc_gpr_len;
|
|
|
|
|
|
|
|
p = (u_int8_t *)l;
|
|
|
|
p += sizeof(struct dc_eblock_mii);
|
|
|
|
m->dc_gp_ptr = p;
|
|
|
|
p += 2 * l->dc_gpr_len;
|
|
|
|
m->dc_reset_len = *p;
|
|
|
|
p++;
|
|
|
|
m->dc_reset_ptr = p;
|
|
|
|
|
|
|
|
m->dc_next = sc->dc_mi;
|
|
|
|
sc->dc_mi = m;
|
|
|
|
}
|
|
|
|
|
2002-10-16 09:04:52 +00:00
|
|
|
static void
|
2003-06-01 19:26:34 +00:00
|
|
|
dc_read_srom(struct dc_softc *sc, int bits)
|
2002-10-07 05:26:35 +00:00
|
|
|
{
|
|
|
|
int size;
|
|
|
|
|
|
|
|
size = 2 << bits;
|
|
|
|
sc->dc_srom = malloc(size, M_DEVBUF, M_NOWAIT);
|
|
|
|
dc_read_eeprom(sc, (caddr_t)sc->dc_srom, 0, (size / 2), 0);
|
|
|
|
}
|
|
|
|
|
2002-08-23 23:49:02 +00:00
|
|
|
static void
|
2003-06-01 19:26:34 +00:00
|
|
|
dc_parse_21143_srom(struct dc_softc *sc)
|
2000-10-05 17:36:14 +00:00
|
|
|
{
|
2003-06-01 19:26:34 +00:00
|
|
|
struct dc_leaf_hdr *lhdr;
|
|
|
|
struct dc_eblock_hdr *hdr;
|
|
|
|
int have_mii, i, loff;
|
|
|
|
char *ptr;
|
2000-10-05 17:36:14 +00:00
|
|
|
|
2003-05-15 16:53:29 +00:00
|
|
|
have_mii = 0;
|
2000-10-05 17:36:14 +00:00
|
|
|
loff = sc->dc_srom[27];
|
|
|
|
lhdr = (struct dc_leaf_hdr *)&(sc->dc_srom[loff]);
|
|
|
|
|
2003-05-15 16:53:29 +00:00
|
|
|
ptr = (char *)lhdr;
|
|
|
|
ptr += sizeof(struct dc_leaf_hdr) - 1;
|
|
|
|
/*
|
|
|
|
* Look if we got a MII media block.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < lhdr->dc_mcnt; i++) {
|
|
|
|
hdr = (struct dc_eblock_hdr *)ptr;
|
|
|
|
if (hdr->dc_type == DC_EBLOCK_MII)
|
|
|
|
have_mii++;
|
|
|
|
|
|
|
|
ptr += (hdr->dc_len & 0x7F);
|
|
|
|
ptr++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Do the same thing again. Only use SIA and SYM media
|
|
|
|
* blocks if no MII media block is available.
|
|
|
|
*/
|
2000-10-05 17:36:14 +00:00
|
|
|
ptr = (char *)lhdr;
|
|
|
|
ptr += sizeof(struct dc_leaf_hdr) - 1;
|
|
|
|
for (i = 0; i < lhdr->dc_mcnt; i++) {
|
|
|
|
hdr = (struct dc_eblock_hdr *)ptr;
|
2003-06-01 19:26:34 +00:00
|
|
|
switch (hdr->dc_type) {
|
2000-10-05 17:36:14 +00:00
|
|
|
case DC_EBLOCK_MII:
|
|
|
|
dc_decode_leaf_mii(sc, (struct dc_eblock_mii *)hdr);
|
|
|
|
break;
|
|
|
|
case DC_EBLOCK_SIA:
|
2003-05-15 16:53:29 +00:00
|
|
|
if (! have_mii)
|
|
|
|
dc_decode_leaf_sia(sc,
|
|
|
|
(struct dc_eblock_sia *)hdr);
|
2000-10-05 17:36:14 +00:00
|
|
|
break;
|
|
|
|
case DC_EBLOCK_SYM:
|
2003-05-15 16:53:29 +00:00
|
|
|
if (! have_mii)
|
|
|
|
dc_decode_leaf_sym(sc,
|
|
|
|
(struct dc_eblock_sym *)hdr);
|
2000-10-05 17:36:14 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* Don't care. Yet. */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
ptr += (hdr->dc_len & 0x7F);
|
|
|
|
ptr++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-07-06 21:45:31 +00:00
|
|
|
static void
|
|
|
|
dc_dma_map_addr(void *arg, bus_dma_segment_t *segs, int nseg, int error)
|
|
|
|
{
|
|
|
|
u_int32_t *paddr;
|
|
|
|
|
|
|
|
KASSERT(nseg == 1, ("wrong number of segments, should be 1"));
|
|
|
|
paddr = arg;
|
|
|
|
*paddr = segs->ds_addr;
|
|
|
|
}
|
|
|
|
|
1999-12-04 17:41:31 +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
|
2003-06-01 19:26:34 +00:00
|
|
|
dc_attach(device_t dev)
|
1999-12-04 17:41:31 +00:00
|
|
|
{
|
2003-06-01 19:26:34 +00:00
|
|
|
int tmp = 0;
|
|
|
|
u_char eaddr[ETHER_ADDR_LEN];
|
|
|
|
u_int32_t command;
|
|
|
|
struct dc_softc *sc;
|
|
|
|
struct ifnet *ifp;
|
|
|
|
u_int32_t revision;
|
2005-08-10 20:33:46 +00:00
|
|
|
int error = 0, rid, mac_offset;
|
2003-07-06 21:45:31 +00:00
|
|
|
int i;
|
2003-06-01 19:26:34 +00:00
|
|
|
u_int8_t *mac;
|
1999-12-04 17:41:31 +00:00
|
|
|
|
|
|
|
sc = device_get_softc(dev);
|
|
|
|
|
2002-04-04 21:03:38 +00:00
|
|
|
mtx_init(&sc->dc_mtx, device_get_nameunit(dev), MTX_NETWORK_LOCK,
|
2005-08-18 19:10:07 +00:00
|
|
|
MTX_DEF);
|
2004-06-28 20:07:03 +00:00
|
|
|
|
1999-12-04 17:41:31 +00:00
|
|
|
/*
|
|
|
|
* Map control/status registers.
|
|
|
|
*/
|
2001-02-21 20:54:22 +00:00
|
|
|
pci_enable_busmaster(dev);
|
1999-12-04 17:41:31 +00:00
|
|
|
|
|
|
|
rid = DC_RID;
|
2004-03-17 17:50:55 +00:00
|
|
|
sc->dc_res = bus_alloc_resource_any(dev, DC_RES, &rid, RF_ACTIVE);
|
1999-12-04 17:41:31 +00:00
|
|
|
|
|
|
|
if (sc->dc_res == NULL) {
|
2005-08-10 20:33:46 +00:00
|
|
|
device_printf(dev, "couldn't map ports/memory\n");
|
1999-12-04 17:41:31 +00:00
|
|
|
error = ENXIO;
|
2003-01-14 19:31:27 +00:00
|
|
|
goto fail;
|
1999-12-04 17:41:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sc->dc_btag = rman_get_bustag(sc->dc_res);
|
|
|
|
sc->dc_bhandle = rman_get_bushandle(sc->dc_res);
|
|
|
|
|
2003-06-01 19:26:34 +00:00
|
|
|
/* Allocate interrupt. */
|
2003-03-31 17:29:43 +00:00
|
|
|
rid = 0;
|
2004-03-17 17:50:55 +00:00
|
|
|
sc->dc_irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid,
|
2003-03-31 17:29:43 +00:00
|
|
|
RF_SHAREABLE | RF_ACTIVE);
|
|
|
|
|
|
|
|
if (sc->dc_irq == NULL) {
|
2005-08-10 20:33:46 +00:00
|
|
|
device_printf(dev, "couldn't map interrupt\n");
|
2003-03-31 17:29:43 +00:00
|
|
|
error = ENXIO;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
1999-12-04 17:41:31 +00:00
|
|
|
/* Need this info to decide on a chip type. */
|
|
|
|
sc->dc_info = dc_devtype(dev);
|
|
|
|
revision = pci_read_config(dev, DC_PCI_CFRV, 4) & 0x000000FF;
|
|
|
|
|
2003-02-12 07:16:15 +00:00
|
|
|
/* Get the eeprom width, but PNIC and XIRCOM have diff eeprom */
|
2003-02-07 23:12:51 +00:00
|
|
|
if (sc->dc_info->dc_did != DC_DEVICEID_82C168 &&
|
|
|
|
sc->dc_info->dc_did != DC_DEVICEID_X3201)
|
|
|
|
dc_eeprom_width(sc);
|
|
|
|
|
2003-06-01 19:26:34 +00:00
|
|
|
switch (sc->dc_info->dc_did) {
|
1999-12-04 17:41:31 +00:00
|
|
|
case DC_DEVICEID_21143:
|
|
|
|
sc->dc_type = DC_TYPE_21143;
|
2003-06-01 19:26:34 +00:00
|
|
|
sc->dc_flags |= DC_TX_POLL | DC_TX_USE_TX_INTR;
|
2000-06-07 17:07:44 +00:00
|
|
|
sc->dc_flags |= DC_REDUCED_MII_POLL;
|
2000-10-05 17:36:14 +00:00
|
|
|
/* Save EEPROM contents so we can parse them later. */
|
2002-10-07 05:26:35 +00:00
|
|
|
dc_read_srom(sc, sc->dc_romwidth);
|
1999-12-04 17:41:31 +00:00
|
|
|
break;
|
2003-01-09 20:51:39 +00:00
|
|
|
case DC_DEVICEID_DM9009:
|
1999-12-04 17:41:31 +00:00
|
|
|
case DC_DEVICEID_DM9100:
|
|
|
|
case DC_DEVICEID_DM9102:
|
|
|
|
sc->dc_type = DC_TYPE_DM9102;
|
2003-06-01 19:26:34 +00:00
|
|
|
sc->dc_flags |= DC_TX_COALESCE | DC_TX_INTR_ALWAYS;
|
|
|
|
sc->dc_flags |= DC_REDUCED_MII_POLL | DC_TX_STORENFWD;
|
2003-08-27 08:13:34 +00:00
|
|
|
sc->dc_flags |= DC_TX_ALIGN;
|
1999-12-04 17:41:31 +00:00
|
|
|
sc->dc_pmode = DC_PMODE_MII;
|
2000-10-27 00:15:04 +00:00
|
|
|
/* Increase the latency timer value. */
|
|
|
|
command = pci_read_config(dev, DC_PCI_CFLT, 4);
|
|
|
|
command &= 0xFFFF00FF;
|
|
|
|
command |= 0x00008000;
|
|
|
|
pci_write_config(dev, DC_PCI_CFLT, command, 4);
|
1999-12-04 17:41:31 +00:00
|
|
|
break;
|
|
|
|
case DC_DEVICEID_AL981:
|
|
|
|
sc->dc_type = DC_TYPE_AL981;
|
|
|
|
sc->dc_flags |= DC_TX_USE_TX_INTR;
|
|
|
|
sc->dc_flags |= DC_TX_ADMTEK_WAR;
|
|
|
|
sc->dc_pmode = DC_PMODE_MII;
|
2002-10-07 05:26:35 +00:00
|
|
|
dc_read_srom(sc, sc->dc_romwidth);
|
1999-12-04 17:41:31 +00:00
|
|
|
break;
|
|
|
|
case DC_DEVICEID_AN985:
|
2003-06-08 10:11:55 +00:00
|
|
|
case DC_DEVICEID_ADM9511:
|
|
|
|
case DC_DEVICEID_ADM9513:
|
2003-07-19 06:01:15 +00:00
|
|
|
case DC_DEVICEID_FA511:
|
2000-10-28 10:03:54 +00:00
|
|
|
case DC_DEVICEID_FE2500:
|
2000-11-14 19:35:22 +00:00
|
|
|
case DC_DEVICEID_EN2242:
|
2003-01-10 05:37:15 +00:00
|
|
|
case DC_DEVICEID_HAWKING_PN672TX:
|
2003-05-12 19:50:21 +00:00
|
|
|
case DC_DEVICEID_3CSOHOB:
|
2003-07-10 18:43:17 +00:00
|
|
|
case DC_DEVICEID_MSMN120:
|
|
|
|
case DC_DEVICEID_MSMN130_FAKE: /* XXX avoid collision with PNIC*/
|
1999-12-04 17:41:31 +00:00
|
|
|
sc->dc_type = DC_TYPE_AN985;
|
2003-05-01 09:31:01 +00:00
|
|
|
sc->dc_flags |= DC_64BIT_HASH;
|
1999-12-04 17:41:31 +00:00
|
|
|
sc->dc_flags |= DC_TX_USE_TX_INTR;
|
|
|
|
sc->dc_flags |= DC_TX_ADMTEK_WAR;
|
|
|
|
sc->dc_pmode = DC_PMODE_MII;
|
2003-09-16 05:01:27 +00:00
|
|
|
/* Don't read SROM for - auto-loaded on reset */
|
1999-12-04 17:41:31 +00:00
|
|
|
break;
|
|
|
|
case DC_DEVICEID_98713:
|
|
|
|
case DC_DEVICEID_98713_CP:
|
|
|
|
if (revision < DC_REVISION_98713A) {
|
|
|
|
sc->dc_type = DC_TYPE_98713;
|
|
|
|
}
|
2000-05-31 05:40:53 +00:00
|
|
|
if (revision >= DC_REVISION_98713A) {
|
1999-12-04 17:41:31 +00:00
|
|
|
sc->dc_type = DC_TYPE_98713A;
|
2000-05-31 05:40:53 +00:00
|
|
|
sc->dc_flags |= DC_21143_NWAY;
|
|
|
|
}
|
|
|
|
sc->dc_flags |= DC_REDUCED_MII_POLL;
|
2003-06-01 19:26:34 +00:00
|
|
|
sc->dc_flags |= DC_TX_POLL | DC_TX_USE_TX_INTR;
|
1999-12-04 17:41:31 +00:00
|
|
|
break;
|
|
|
|
case DC_DEVICEID_987x5:
|
2000-06-11 11:54:52 +00:00
|
|
|
case DC_DEVICEID_EN1217:
|
2000-07-15 17:54:30 +00:00
|
|
|
/*
|
|
|
|
* Macronix MX98715AEC-C/D/E parts have only a
|
|
|
|
* 128-bit hash table. We need to deal with these
|
|
|
|
* in the same manner as the PNIC II so that we
|
|
|
|
* get the right number of bits out of the
|
|
|
|
* CRC routine.
|
|
|
|
*/
|
|
|
|
if (revision >= DC_REVISION_98715AEC_C &&
|
|
|
|
revision < DC_REVISION_98725)
|
|
|
|
sc->dc_flags |= DC_128BIT_HASH;
|
1999-12-04 17:41:31 +00:00
|
|
|
sc->dc_type = DC_TYPE_987x5;
|
2003-06-01 19:26:34 +00:00
|
|
|
sc->dc_flags |= DC_TX_POLL | DC_TX_USE_TX_INTR;
|
|
|
|
sc->dc_flags |= DC_REDUCED_MII_POLL | DC_21143_NWAY;
|
1999-12-04 17:41:31 +00:00
|
|
|
break;
|
2000-07-17 19:27:41 +00:00
|
|
|
case DC_DEVICEID_98727:
|
|
|
|
sc->dc_type = DC_TYPE_987x5;
|
2003-06-01 19:26:34 +00:00
|
|
|
sc->dc_flags |= DC_TX_POLL | DC_TX_USE_TX_INTR;
|
|
|
|
sc->dc_flags |= DC_REDUCED_MII_POLL | DC_21143_NWAY;
|
2000-07-17 19:27:41 +00:00
|
|
|
break;
|
1999-12-04 17:41:31 +00:00
|
|
|
case DC_DEVICEID_82C115:
|
|
|
|
sc->dc_type = DC_TYPE_PNICII;
|
2003-06-01 19:26:34 +00:00
|
|
|
sc->dc_flags |= DC_TX_POLL | DC_TX_USE_TX_INTR | DC_128BIT_HASH;
|
|
|
|
sc->dc_flags |= DC_REDUCED_MII_POLL | DC_21143_NWAY;
|
1999-12-04 17:41:31 +00:00
|
|
|
break;
|
|
|
|
case DC_DEVICEID_82C168:
|
|
|
|
sc->dc_type = DC_TYPE_PNIC;
|
2003-06-01 19:26:34 +00:00
|
|
|
sc->dc_flags |= DC_TX_STORENFWD | DC_TX_INTR_ALWAYS;
|
1999-12-04 17:41:31 +00:00
|
|
|
sc->dc_flags |= DC_PNIC_RX_BUG_WAR;
|
|
|
|
sc->dc_pnic_rx_buf = malloc(DC_RXLEN * 5, M_DEVBUF, M_NOWAIT);
|
|
|
|
if (revision < DC_REVISION_82C169)
|
|
|
|
sc->dc_pmode = DC_PMODE_SYM;
|
|
|
|
break;
|
|
|
|
case DC_DEVICEID_AX88140A:
|
|
|
|
sc->dc_type = DC_TYPE_ASIX;
|
2003-06-01 19:26:34 +00:00
|
|
|
sc->dc_flags |= DC_TX_USE_TX_INTR | DC_TX_INTR_FIRSTFRAG;
|
1999-12-04 17:41:31 +00:00
|
|
|
sc->dc_flags |= DC_REDUCED_MII_POLL;
|
|
|
|
sc->dc_pmode = DC_PMODE_MII;
|
|
|
|
break;
|
2000-10-19 08:34:32 +00:00
|
|
|
case DC_DEVICEID_X3201:
|
|
|
|
sc->dc_type = DC_TYPE_XIRCOM;
|
2001-12-11 02:47:53 +00:00
|
|
|
sc->dc_flags |= DC_TX_INTR_ALWAYS | DC_TX_COALESCE |
|
2001-12-15 02:51:21 +00:00
|
|
|
DC_TX_ALIGN;
|
2000-10-19 08:34:32 +00:00
|
|
|
/*
|
|
|
|
* We don't actually need to coalesce, but we're doing
|
|
|
|
* it to obtain a double word aligned buffer.
|
2001-12-11 02:47:53 +00:00
|
|
|
* The DC_TX_COALESCE flag is required.
|
2000-10-19 08:34:32 +00:00
|
|
|
*/
|
2002-10-07 05:26:35 +00:00
|
|
|
sc->dc_pmode = DC_PMODE_MII;
|
2000-10-19 08:34:32 +00:00
|
|
|
break;
|
2001-09-04 17:10:11 +00:00
|
|
|
case DC_DEVICEID_RS7112:
|
|
|
|
sc->dc_type = DC_TYPE_CONEXANT;
|
|
|
|
sc->dc_flags |= DC_TX_INTR_ALWAYS;
|
|
|
|
sc->dc_flags |= DC_REDUCED_MII_POLL;
|
|
|
|
sc->dc_pmode = DC_PMODE_MII;
|
2002-10-07 05:26:35 +00:00
|
|
|
dc_read_srom(sc, sc->dc_romwidth);
|
2001-09-04 17:10:11 +00:00
|
|
|
break;
|
1999-12-04 17:41:31 +00:00
|
|
|
default:
|
2005-08-10 20:33:46 +00:00
|
|
|
device_printf(dev, "unknown device: %x\n", sc->dc_info->dc_did);
|
1999-12-04 17:41:31 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Save the cache line size. */
|
2000-01-19 19:03:08 +00:00
|
|
|
if (DC_IS_DAVICOM(sc))
|
|
|
|
sc->dc_cachesize = 0;
|
|
|
|
else
|
|
|
|
sc->dc_cachesize = pci_read_config(dev,
|
|
|
|
DC_PCI_CFLT, 4) & 0xFF;
|
1999-12-04 17:41:31 +00:00
|
|
|
|
|
|
|
/* Reset the adapter. */
|
|
|
|
dc_reset(sc);
|
|
|
|
|
|
|
|
/* Take 21143 out of snooze mode */
|
2000-10-19 08:34:32 +00:00
|
|
|
if (DC_IS_INTEL(sc) || DC_IS_XIRCOM(sc)) {
|
1999-12-04 17:41:31 +00:00
|
|
|
command = pci_read_config(dev, DC_PCI_CFDD, 4);
|
2003-06-01 19:26:34 +00:00
|
|
|
command &= ~(DC_CFDD_SNOOZE_MODE | DC_CFDD_SLEEP_MODE);
|
1999-12-04 17:41:31 +00:00
|
|
|
pci_write_config(dev, DC_PCI_CFDD, command, 4);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Try to learn something about the supported media.
|
|
|
|
* We know that ASIX and ADMtek and Davicom devices
|
|
|
|
* will *always* be using MII media, so that's a no-brainer.
|
|
|
|
* The tricky ones are the Macronix/PNIC II and the
|
|
|
|
* Intel 21143.
|
|
|
|
*/
|
2000-10-05 17:36:14 +00:00
|
|
|
if (DC_IS_INTEL(sc))
|
|
|
|
dc_parse_21143_srom(sc);
|
|
|
|
else if (DC_IS_MACRONIX(sc) || DC_IS_PNICII(sc)) {
|
1999-12-04 17:41:31 +00:00
|
|
|
if (sc->dc_type == DC_TYPE_98713)
|
|
|
|
sc->dc_pmode = DC_PMODE_MII;
|
|
|
|
else
|
|
|
|
sc->dc_pmode = DC_PMODE_SYM;
|
|
|
|
} else if (!sc->dc_pmode)
|
|
|
|
sc->dc_pmode = DC_PMODE_MII;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get station address from the EEPROM.
|
|
|
|
*/
|
|
|
|
switch(sc->dc_type) {
|
|
|
|
case DC_TYPE_98713:
|
|
|
|
case DC_TYPE_98713A:
|
|
|
|
case DC_TYPE_987x5:
|
|
|
|
case DC_TYPE_PNICII:
|
|
|
|
dc_read_eeprom(sc, (caddr_t)&mac_offset,
|
|
|
|
(DC_EE_NODEADDR_OFFSET / 2), 1, 0);
|
|
|
|
dc_read_eeprom(sc, (caddr_t)&eaddr, (mac_offset / 2), 3, 0);
|
|
|
|
break;
|
|
|
|
case DC_TYPE_PNIC:
|
|
|
|
dc_read_eeprom(sc, (caddr_t)&eaddr, 0, 3, 1);
|
|
|
|
break;
|
|
|
|
case DC_TYPE_DM9102:
|
2004-01-08 19:08:27 +00:00
|
|
|
dc_read_eeprom(sc, (caddr_t)&eaddr, DC_EE_NODEADDR, 3, 0);
|
|
|
|
#ifdef __sparc64__
|
|
|
|
/*
|
|
|
|
* If this is an onboard dc(4) the station address read from
|
|
|
|
* the EEPROM is all zero and we have to get it from the fcode.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < ETHER_ADDR_LEN; i++)
|
|
|
|
if (eaddr[i] != 0x00)
|
|
|
|
break;
|
2004-08-14 21:43:37 +00:00
|
|
|
if (i >= ETHER_ADDR_LEN)
|
2004-01-08 19:08:27 +00:00
|
|
|
OF_getetheraddr(dev, eaddr);
|
|
|
|
#endif
|
|
|
|
break;
|
1999-12-04 17:41:31 +00:00
|
|
|
case DC_TYPE_21143:
|
|
|
|
case DC_TYPE_ASIX:
|
|
|
|
dc_read_eeprom(sc, (caddr_t)&eaddr, DC_EE_NODEADDR, 3, 0);
|
|
|
|
break;
|
|
|
|
case DC_TYPE_AL981:
|
|
|
|
case DC_TYPE_AN985:
|
2003-09-16 05:01:27 +00:00
|
|
|
*(u_int32_t *)(&eaddr[0]) = CSR_READ_4(sc, DC_AL_PAR0);
|
|
|
|
*(u_int16_t *)(&eaddr[4]) = CSR_READ_4(sc, DC_AL_PAR1);
|
1999-12-04 17:41:31 +00:00
|
|
|
break;
|
2001-09-04 17:10:11 +00:00
|
|
|
case DC_TYPE_CONEXANT:
|
2003-06-01 19:26:34 +00:00
|
|
|
bcopy(sc->dc_srom + DC_CONEXANT_EE_NODEADDR, &eaddr,
|
|
|
|
ETHER_ADDR_LEN);
|
2001-09-04 17:10:11 +00:00
|
|
|
break;
|
2000-10-19 08:34:32 +00:00
|
|
|
case DC_TYPE_XIRCOM:
|
2003-06-01 19:26:34 +00:00
|
|
|
/* The MAC comes from the CIS. */
|
2002-11-27 07:04:10 +00:00
|
|
|
mac = pci_get_ether(dev);
|
|
|
|
if (!mac) {
|
|
|
|
device_printf(dev, "No station address in CIS!\n");
|
2003-01-14 19:31:27 +00:00
|
|
|
error = ENXIO;
|
2002-11-27 07:04:10 +00:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
bcopy(mac, eaddr, ETHER_ADDR_LEN);
|
2000-10-19 08:34:32 +00:00
|
|
|
break;
|
1999-12-04 17:41:31 +00:00
|
|
|
default:
|
|
|
|
dc_read_eeprom(sc, (caddr_t)&eaddr, DC_EE_NODEADDR, 3, 0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2003-07-06 21:45:31 +00:00
|
|
|
/* Allocate a busdma tag and DMA safe memory for TX/RX descriptors. */
|
|
|
|
error = bus_dma_tag_create(NULL, PAGE_SIZE, 0, BUS_SPACE_MAXADDR_32BIT,
|
|
|
|
BUS_SPACE_MAXADDR, NULL, NULL, sizeof(struct dc_list_data), 1,
|
|
|
|
sizeof(struct dc_list_data), 0, NULL, NULL, &sc->dc_ltag);
|
|
|
|
if (error) {
|
2005-08-10 20:33:46 +00:00
|
|
|
device_printf(dev, "failed to allocate busdma tag\n");
|
2003-07-06 21:45:31 +00:00
|
|
|
error = ENXIO;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
error = bus_dmamem_alloc(sc->dc_ltag, (void **)&sc->dc_ldata,
|
2003-07-27 14:00:02 +00:00
|
|
|
BUS_DMA_NOWAIT | BUS_DMA_ZERO, &sc->dc_lmap);
|
2003-07-06 21:45:31 +00:00
|
|
|
if (error) {
|
2005-08-10 20:33:46 +00:00
|
|
|
device_printf(dev, "failed to allocate DMA safe memory\n");
|
2003-07-06 21:45:31 +00:00
|
|
|
error = ENXIO;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
error = bus_dmamap_load(sc->dc_ltag, sc->dc_lmap, sc->dc_ldata,
|
|
|
|
sizeof(struct dc_list_data), dc_dma_map_addr, &sc->dc_laddr,
|
|
|
|
BUS_DMA_NOWAIT);
|
|
|
|
if (error) {
|
2005-08-10 20:33:46 +00:00
|
|
|
device_printf(dev, "cannot get address of the descriptors\n");
|
2003-07-06 21:45:31 +00:00
|
|
|
error = ENXIO;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate a busdma tag and DMA safe memory for the multicast
|
|
|
|
* setup frame.
|
|
|
|
*/
|
|
|
|
error = bus_dma_tag_create(NULL, PAGE_SIZE, 0, BUS_SPACE_MAXADDR_32BIT,
|
|
|
|
BUS_SPACE_MAXADDR, NULL, NULL, DC_SFRAME_LEN + DC_MIN_FRAMELEN, 1,
|
|
|
|
DC_SFRAME_LEN + DC_MIN_FRAMELEN, 0, NULL, NULL, &sc->dc_stag);
|
|
|
|
if (error) {
|
2005-08-10 20:33:46 +00:00
|
|
|
device_printf(dev, "failed to allocate busdma tag\n");
|
2003-07-06 21:45:31 +00:00
|
|
|
error = ENXIO;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
error = bus_dmamem_alloc(sc->dc_stag, (void **)&sc->dc_cdata.dc_sbuf,
|
|
|
|
BUS_DMA_NOWAIT, &sc->dc_smap);
|
|
|
|
if (error) {
|
2005-08-10 20:33:46 +00:00
|
|
|
device_printf(dev, "failed to allocate DMA safe memory\n");
|
2003-07-06 21:45:31 +00:00
|
|
|
error = ENXIO;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
error = bus_dmamap_load(sc->dc_stag, sc->dc_smap, sc->dc_cdata.dc_sbuf,
|
|
|
|
DC_SFRAME_LEN, dc_dma_map_addr, &sc->dc_saddr, BUS_DMA_NOWAIT);
|
|
|
|
if (error) {
|
2005-08-10 20:33:46 +00:00
|
|
|
device_printf(dev, "cannot get address of the descriptors\n");
|
2003-07-06 21:45:31 +00:00
|
|
|
error = ENXIO;
|
|
|
|
goto fail;
|
|
|
|
}
|
1999-12-04 17:41:31 +00:00
|
|
|
|
2003-07-06 21:45:31 +00:00
|
|
|
/* Allocate a busdma tag for mbufs. */
|
2005-03-08 23:25:46 +00:00
|
|
|
error = bus_dma_tag_create(NULL, 1, 0, BUS_SPACE_MAXADDR_32BIT,
|
2005-03-09 00:54:55 +00:00
|
|
|
BUS_SPACE_MAXADDR, NULL, NULL, MCLBYTES, DC_TX_LIST_CNT, MCLBYTES,
|
2005-03-08 23:25:46 +00:00
|
|
|
0, NULL, NULL, &sc->dc_mtag);
|
2003-07-06 21:45:31 +00:00
|
|
|
if (error) {
|
2005-08-10 20:33:46 +00:00
|
|
|
device_printf(dev, "failed to allocate busdma tag\n");
|
1999-12-04 17:41:31 +00:00
|
|
|
error = ENXIO;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2003-07-06 21:45:31 +00:00
|
|
|
/* Create the TX/RX busdma maps. */
|
|
|
|
for (i = 0; i < DC_TX_LIST_CNT; i++) {
|
2004-07-05 22:35:18 +00:00
|
|
|
error = bus_dmamap_create(sc->dc_mtag, 0,
|
2003-07-06 21:45:31 +00:00
|
|
|
&sc->dc_cdata.dc_tx_map[i]);
|
|
|
|
if (error) {
|
2005-08-10 20:33:46 +00:00
|
|
|
device_printf(dev, "failed to init TX ring\n");
|
2003-07-06 21:45:31 +00:00
|
|
|
error = ENXIO;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (i = 0; i < DC_RX_LIST_CNT; i++) {
|
2004-07-05 22:35:18 +00:00
|
|
|
error = bus_dmamap_create(sc->dc_mtag, 0,
|
2003-07-06 21:45:31 +00:00
|
|
|
&sc->dc_cdata.dc_rx_map[i]);
|
|
|
|
if (error) {
|
2005-08-10 20:33:46 +00:00
|
|
|
device_printf(dev, "failed to init RX ring\n");
|
2003-07-06 21:45:31 +00:00
|
|
|
error = ENXIO;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
error = bus_dmamap_create(sc->dc_mtag, 0, &sc->dc_sparemap);
|
|
|
|
if (error) {
|
2005-08-10 20:33:46 +00:00
|
|
|
device_printf(dev, "failed to init RX ring\n");
|
2003-07-06 21:45:31 +00:00
|
|
|
error = ENXIO;
|
|
|
|
goto fail;
|
|
|
|
}
|
1999-12-04 17:41:31 +00:00
|
|
|
|
2005-06-10 16:49:24 +00:00
|
|
|
ifp = sc->dc_ifp = if_alloc(IFT_ETHER);
|
|
|
|
if (ifp == NULL) {
|
2005-08-10 20:33:46 +00:00
|
|
|
device_printf(dev, "can not if_alloc()\n");
|
2005-06-10 16:49:24 +00:00
|
|
|
error = ENOSPC;
|
|
|
|
goto fail;
|
|
|
|
}
|
1999-12-04 17:41:31 +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));
|
2000-10-19 08:34:32 +00:00
|
|
|
/* XXX: bleah, MTU gets overwritten in ether_ifattach() */
|
1999-12-04 17:41:31 +00:00
|
|
|
ifp->if_mtu = ETHERMTU;
|
2004-10-01 07:01:38 +00:00
|
|
|
ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
|
1999-12-04 17:41:31 +00:00
|
|
|
ifp->if_ioctl = dc_ioctl;
|
|
|
|
ifp->if_start = dc_start;
|
|
|
|
ifp->if_watchdog = dc_watchdog;
|
|
|
|
ifp->if_init = dc_init;
|
|
|
|
ifp->if_baudrate = 10000000;
|
2004-10-01 07:04:09 +00:00
|
|
|
IFQ_SET_MAXLEN(&ifp->if_snd, DC_TX_LIST_CNT - 1);
|
|
|
|
ifp->if_snd.ifq_drv_maxlen = DC_TX_LIST_CNT - 1;
|
|
|
|
IFQ_SET_READY(&ifp->if_snd);
|
1999-12-04 17:41:31 +00:00
|
|
|
|
|
|
|
/*
|
2000-10-05 17:36:14 +00:00
|
|
|
* Do MII setup. If this is a 21143, check for a PHY on the
|
|
|
|
* MII bus after applying any necessary fixups to twiddle the
|
|
|
|
* GPIO bits. If we don't end up finding a PHY, restore the
|
|
|
|
* old selection (SIA only or SIA/SYM) and attach the dcphy
|
|
|
|
* driver instead.
|
1999-12-04 17:41:31 +00:00
|
|
|
*/
|
2000-10-05 17:36:14 +00:00
|
|
|
if (DC_IS_INTEL(sc)) {
|
|
|
|
dc_apply_fixup(sc, IFM_AUTO);
|
|
|
|
tmp = sc->dc_pmode;
|
|
|
|
sc->dc_pmode = DC_PMODE_MII;
|
|
|
|
}
|
|
|
|
|
2005-04-18 03:31:29 +00:00
|
|
|
/*
|
|
|
|
* Setup General Purpose port mode and data so the tulip can talk
|
|
|
|
* to the MII. This needs to be done before mii_phy_probe so that
|
|
|
|
* we can actually see them.
|
|
|
|
*/
|
|
|
|
if (DC_IS_XIRCOM(sc)) {
|
|
|
|
CSR_WRITE_4(sc, DC_SIAGP, DC_SIAGP_WRITE_EN | DC_SIAGP_INT1_EN |
|
|
|
|
DC_SIAGP_MD_GP2_OUTPUT | DC_SIAGP_MD_GP0_OUTPUT);
|
|
|
|
DELAY(10);
|
|
|
|
CSR_WRITE_4(sc, DC_SIAGP, DC_SIAGP_INT1_EN |
|
|
|
|
DC_SIAGP_MD_GP2_OUTPUT | DC_SIAGP_MD_GP0_OUTPUT);
|
|
|
|
DELAY(10);
|
|
|
|
}
|
|
|
|
|
1999-12-04 17:41:31 +00:00
|
|
|
error = mii_phy_probe(dev, &sc->dc_miibus,
|
|
|
|
dc_ifmedia_upd, dc_ifmedia_sts);
|
|
|
|
|
|
|
|
if (error && DC_IS_INTEL(sc)) {
|
2000-10-05 17:36:14 +00:00
|
|
|
sc->dc_pmode = tmp;
|
|
|
|
if (sc->dc_pmode != DC_PMODE_SIA)
|
|
|
|
sc->dc_pmode = DC_PMODE_SYM;
|
2000-06-07 17:07:44 +00:00
|
|
|
sc->dc_flags |= DC_21143_NWAY;
|
1999-12-04 17:41:31 +00:00
|
|
|
mii_phy_probe(dev, &sc->dc_miibus,
|
|
|
|
dc_ifmedia_upd, dc_ifmedia_sts);
|
2000-09-07 18:51:04 +00:00
|
|
|
/*
|
|
|
|
* For non-MII cards, we need to have the 21143
|
|
|
|
* drive the LEDs. Except there are some systems
|
|
|
|
* like the NEC VersaPro NoteBook PC which have no
|
|
|
|
* LEDs, and twiddling these bits has adverse effects
|
|
|
|
* on them. (I.e. you suddenly can't get a link.)
|
|
|
|
*/
|
|
|
|
if (pci_read_config(dev, DC_PCI_CSID, 4) != 0x80281033)
|
|
|
|
sc->dc_flags |= DC_TULIP_LEDS;
|
1999-12-04 17:41:31 +00:00
|
|
|
error = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (error) {
|
2005-08-10 20:33:46 +00:00
|
|
|
device_printf(dev, "MII without any PHY!\n");
|
1999-12-04 17:41:31 +00:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2003-02-05 21:21:26 +00:00
|
|
|
if (DC_IS_ADMTEK(sc)) {
|
|
|
|
/*
|
|
|
|
* Set automatic TX underrun recovery for the ADMtek chips
|
|
|
|
*/
|
|
|
|
DC_SETBIT(sc, DC_AL_CR, DC_AL_CR_ATUR);
|
|
|
|
}
|
|
|
|
|
2002-01-16 16:33:58 +00:00
|
|
|
/*
|
|
|
|
* Tell the upper layer(s) we support long frames.
|
|
|
|
*/
|
|
|
|
ifp->if_data.ifi_hdrlen = sizeof(struct ether_vlan_header);
|
2002-11-14 23:49:09 +00:00
|
|
|
ifp->if_capabilities |= IFCAP_VLAN_MTU;
|
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;
|
2004-04-11 13:47:15 +00:00
|
|
|
#ifdef DEVICE_POLLING
|
|
|
|
ifp->if_capabilities |= IFCAP_POLLING;
|
|
|
|
#endif
|
2002-01-16 16:33:58 +00:00
|
|
|
|
2005-08-18 19:10:07 +00:00
|
|
|
callout_init_mtx(&sc->dc_stat_ch, &sc->dc_mtx, 0);
|
1999-12-04 17:41:31 +00:00
|
|
|
|
2000-10-05 17:36:14 +00:00
|
|
|
#ifdef SRM_MEDIA
|
2002-09-04 18:14:17 +00:00
|
|
|
sc->dc_srm_media = 0;
|
2000-03-11 05:20:56 +00:00
|
|
|
|
|
|
|
/* Remember the SRM console media setting */
|
|
|
|
if (DC_IS_INTEL(sc)) {
|
|
|
|
command = pci_read_config(dev, DC_PCI_CFDD, 4);
|
2003-06-01 19:26:34 +00:00
|
|
|
command &= ~(DC_CFDD_SNOOZE_MODE | DC_CFDD_SLEEP_MODE);
|
2000-03-11 05:20:56 +00:00
|
|
|
switch ((command >> 8) & 0xff) {
|
2003-06-01 19:26:34 +00:00
|
|
|
case 3:
|
2000-03-11 05:20:56 +00:00
|
|
|
sc->dc_srm_media = IFM_10_T;
|
|
|
|
break;
|
2003-06-01 19:26:34 +00:00
|
|
|
case 4:
|
2000-03-11 05:20:56 +00:00
|
|
|
sc->dc_srm_media = IFM_10_T | IFM_FDX;
|
|
|
|
break;
|
2003-06-01 19:26:34 +00:00
|
|
|
case 5:
|
2000-03-11 05:20:56 +00:00
|
|
|
sc->dc_srm_media = IFM_100_TX;
|
|
|
|
break;
|
2003-06-01 19:26:34 +00:00
|
|
|
case 6:
|
2000-03-11 05:20:56 +00:00
|
|
|
sc->dc_srm_media = IFM_100_TX | IFM_FDX;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (sc->dc_srm_media)
|
|
|
|
sc->dc_srm_media |= IFM_ACTIVE | IFM_ETHER;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2003-01-14 19:31:27 +00:00
|
|
|
/*
|
|
|
|
* Call MI attach routine.
|
|
|
|
*/
|
|
|
|
ether_ifattach(ifp, eaddr);
|
|
|
|
|
2003-03-31 17:29:43 +00:00
|
|
|
/* Hook interrupt last to avoid having to lock softc */
|
2005-08-18 19:10:07 +00:00
|
|
|
error = bus_setup_intr(dev, sc->dc_irq, INTR_TYPE_NET | INTR_MPSAFE,
|
2003-01-14 19:31:27 +00:00
|
|
|
dc_intr, sc, &sc->dc_intrhand);
|
|
|
|
|
|
|
|
if (error) {
|
2005-08-10 20:33:46 +00:00
|
|
|
device_printf(dev, "couldn't set up irq\n");
|
2003-04-17 20:32:06 +00:00
|
|
|
ether_ifdetach(ifp);
|
2003-03-31 17:29:43 +00:00
|
|
|
goto fail;
|
2003-01-14 19:31:27 +00:00
|
|
|
}
|
2000-03-11 05:20:56 +00:00
|
|
|
|
1999-12-04 17:41:31 +00:00
|
|
|
fail:
|
2003-03-31 17:29:43 +00:00
|
|
|
if (error)
|
|
|
|
dc_detach(dev);
|
2003-01-14 19:31:27 +00:00
|
|
|
return (error);
|
1999-12-04 17:41:31 +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
|
2003-06-01 19:26:34 +00:00
|
|
|
dc_detach(device_t dev)
|
1999-12-04 17:41:31 +00:00
|
|
|
{
|
2003-06-01 19:26:34 +00:00
|
|
|
struct dc_softc *sc;
|
|
|
|
struct ifnet *ifp;
|
|
|
|
struct dc_mediainfo *m;
|
2003-07-06 21:45:31 +00:00
|
|
|
int i;
|
1999-12-04 17:41:31 +00:00
|
|
|
|
|
|
|
sc = device_get_softc(dev);
|
2003-03-31 20:22:00 +00:00
|
|
|
KASSERT(mtx_initialized(&sc->dc_mtx), ("dc mutex not initialized"));
|
2000-10-13 17:54:19 +00:00
|
|
|
|
2005-06-10 16:49:24 +00:00
|
|
|
ifp = sc->dc_ifp;
|
1999-12-04 17:41:31 +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
|
|
|
|
|
2003-04-17 20:32:06 +00:00
|
|
|
/* These should only be active if attach succeeded */
|
2003-04-21 18:34:04 +00:00
|
|
|
if (device_is_attached(dev)) {
|
2005-08-18 19:10:07 +00:00
|
|
|
DC_LOCK(sc);
|
2003-04-17 08:36:52 +00:00
|
|
|
dc_stop(sc);
|
2005-08-18 19:10:07 +00:00
|
|
|
DC_UNLOCK(sc);
|
|
|
|
callout_drain(&sc->dc_stat_ch);
|
2003-03-31 17:29:43 +00:00
|
|
|
ether_ifdetach(ifp);
|
|
|
|
}
|
2003-04-17 20:32:06 +00:00
|
|
|
if (sc->dc_miibus)
|
|
|
|
device_delete_child(dev, sc->dc_miibus);
|
|
|
|
bus_generic_detach(dev);
|
1999-12-04 17:41:31 +00:00
|
|
|
|
2003-03-31 17:29:43 +00:00
|
|
|
if (sc->dc_intrhand)
|
|
|
|
bus_teardown_intr(dev, sc->dc_irq, sc->dc_intrhand);
|
|
|
|
if (sc->dc_irq)
|
|
|
|
bus_release_resource(dev, SYS_RES_IRQ, 0, sc->dc_irq);
|
|
|
|
if (sc->dc_res)
|
|
|
|
bus_release_resource(dev, DC_RES, DC_RID, sc->dc_res);
|
1999-12-04 17:41:31 +00:00
|
|
|
|
2005-10-18 06:09:42 +00:00
|
|
|
if (ifp)
|
|
|
|
if_free(ifp);
|
|
|
|
|
2003-07-06 21:45:31 +00:00
|
|
|
if (sc->dc_cdata.dc_sbuf != NULL)
|
|
|
|
bus_dmamem_free(sc->dc_stag, sc->dc_cdata.dc_sbuf, sc->dc_smap);
|
|
|
|
if (sc->dc_ldata != NULL)
|
|
|
|
bus_dmamem_free(sc->dc_ltag, sc->dc_ldata, sc->dc_lmap);
|
2005-09-15 17:51:39 +00:00
|
|
|
if (sc->dc_mtag) {
|
|
|
|
for (i = 0; i < DC_TX_LIST_CNT; i++)
|
|
|
|
if (sc->dc_cdata.dc_tx_map[i] != NULL)
|
|
|
|
bus_dmamap_destroy(sc->dc_mtag,
|
|
|
|
sc->dc_cdata.dc_tx_map[i]);
|
|
|
|
for (i = 0; i < DC_RX_LIST_CNT; i++)
|
|
|
|
if (sc->dc_cdata.dc_rx_map[i] != NULL)
|
|
|
|
bus_dmamap_destroy(sc->dc_mtag,
|
|
|
|
sc->dc_cdata.dc_rx_map[i]);
|
|
|
|
bus_dmamap_destroy(sc->dc_mtag, sc->dc_sparemap);
|
|
|
|
}
|
2003-07-06 21:45:31 +00:00
|
|
|
if (sc->dc_stag)
|
|
|
|
bus_dma_tag_destroy(sc->dc_stag);
|
|
|
|
if (sc->dc_mtag)
|
|
|
|
bus_dma_tag_destroy(sc->dc_mtag);
|
|
|
|
if (sc->dc_ltag)
|
|
|
|
bus_dma_tag_destroy(sc->dc_ltag);
|
|
|
|
|
2003-03-31 17:29:43 +00:00
|
|
|
free(sc->dc_pnic_rx_buf, M_DEVBUF);
|
1999-12-04 17:41:31 +00:00
|
|
|
|
2003-06-01 19:26:34 +00:00
|
|
|
while (sc->dc_mi != NULL) {
|
2000-10-05 17:36:14 +00:00
|
|
|
m = sc->dc_mi->dc_next;
|
|
|
|
free(sc->dc_mi, M_DEVBUF);
|
|
|
|
sc->dc_mi = m;
|
|
|
|
}
|
2002-10-07 05:29:13 +00:00
|
|
|
free(sc->dc_srom, M_DEVBUF);
|
2000-10-05 17:36:14 +00:00
|
|
|
|
2000-10-13 17:54:19 +00:00
|
|
|
mtx_destroy(&sc->dc_mtx);
|
1999-12-04 17:41:31 +00:00
|
|
|
|
2003-06-01 19:26:34 +00:00
|
|
|
return (0);
|
1999-12-04 17:41:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize the transmit descriptors.
|
|
|
|
*/
|
2002-08-23 23:49:02 +00:00
|
|
|
static int
|
2003-06-01 19:26:34 +00:00
|
|
|
dc_list_tx_init(struct dc_softc *sc)
|
1999-12-04 17:41:31 +00:00
|
|
|
{
|
2003-06-01 19:26:34 +00:00
|
|
|
struct dc_chain_data *cd;
|
|
|
|
struct dc_list_data *ld;
|
|
|
|
int i, nexti;
|
1999-12-04 17:41:31 +00:00
|
|
|
|
|
|
|
cd = &sc->dc_cdata;
|
|
|
|
ld = sc->dc_ldata;
|
|
|
|
for (i = 0; i < DC_TX_LIST_CNT; i++) {
|
2003-07-06 14:36:33 +00:00
|
|
|
if (i == DC_TX_LIST_CNT - 1)
|
|
|
|
nexti = 0;
|
|
|
|
else
|
|
|
|
nexti = i + 1;
|
2003-07-09 15:03:10 +00:00
|
|
|
ld->dc_tx_list[i].dc_next = htole32(DC_TXDESC(sc, nexti));
|
1999-12-04 17:41:31 +00:00
|
|
|
cd->dc_tx_chain[i] = NULL;
|
|
|
|
ld->dc_tx_list[i].dc_data = 0;
|
|
|
|
ld->dc_tx_list[i].dc_ctl = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
cd->dc_tx_prod = cd->dc_tx_cons = cd->dc_tx_cnt = 0;
|
2003-07-06 21:45:31 +00:00
|
|
|
bus_dmamap_sync(sc->dc_ltag, sc->dc_lmap,
|
|
|
|
BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD);
|
2003-06-01 19:26:34 +00:00
|
|
|
return (0);
|
1999-12-04 17:41:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize the RX descriptors and allocate mbufs for them. Note that
|
|
|
|
* we arrange the descriptors in a closed ring, so that the last descriptor
|
|
|
|
* points back to the first.
|
|
|
|
*/
|
2002-08-23 23:49:02 +00:00
|
|
|
static int
|
2003-06-01 19:26:34 +00:00
|
|
|
dc_list_rx_init(struct dc_softc *sc)
|
1999-12-04 17:41:31 +00:00
|
|
|
{
|
2003-06-01 19:26:34 +00:00
|
|
|
struct dc_chain_data *cd;
|
|
|
|
struct dc_list_data *ld;
|
|
|
|
int i, nexti;
|
1999-12-04 17:41:31 +00:00
|
|
|
|
|
|
|
cd = &sc->dc_cdata;
|
|
|
|
ld = sc->dc_ldata;
|
|
|
|
|
|
|
|
for (i = 0; i < DC_RX_LIST_CNT; i++) {
|
2003-07-06 21:45:31 +00:00
|
|
|
if (dc_newbuf(sc, i, 1) != 0)
|
2003-06-01 19:26:34 +00:00
|
|
|
return (ENOBUFS);
|
2003-07-06 14:36:33 +00:00
|
|
|
if (i == DC_RX_LIST_CNT - 1)
|
|
|
|
nexti = 0;
|
|
|
|
else
|
|
|
|
nexti = i + 1;
|
2003-07-09 15:03:10 +00:00
|
|
|
ld->dc_rx_list[i].dc_next = htole32(DC_RXDESC(sc, nexti));
|
1999-12-04 17:41:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
cd->dc_rx_prod = 0;
|
2003-07-06 21:45:31 +00:00
|
|
|
bus_dmamap_sync(sc->dc_ltag, sc->dc_lmap,
|
|
|
|
BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD);
|
2003-06-01 19:26:34 +00:00
|
|
|
return (0);
|
1999-12-04 17:41:31 +00:00
|
|
|
}
|
|
|
|
|
2003-07-06 21:45:31 +00:00
|
|
|
static void
|
|
|
|
dc_dma_map_rxbuf(arg, segs, nseg, mapsize, error)
|
|
|
|
void *arg;
|
|
|
|
bus_dma_segment_t *segs;
|
|
|
|
int nseg;
|
|
|
|
bus_size_t mapsize;
|
|
|
|
int error;
|
|
|
|
{
|
|
|
|
struct dc_softc *sc;
|
|
|
|
struct dc_desc *c;
|
|
|
|
|
|
|
|
sc = arg;
|
|
|
|
c = &sc->dc_ldata->dc_rx_list[sc->dc_cdata.dc_rx_cur];
|
|
|
|
if (error) {
|
|
|
|
sc->dc_cdata.dc_rx_err = error;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
KASSERT(nseg == 1, ("wrong number of segments, should be 1"));
|
|
|
|
sc->dc_cdata.dc_rx_err = 0;
|
2003-07-09 15:03:10 +00:00
|
|
|
c->dc_data = htole32(segs->ds_addr);
|
2003-07-06 21:45:31 +00:00
|
|
|
}
|
|
|
|
|
1999-12-04 17:41:31 +00:00
|
|
|
/*
|
|
|
|
* Initialize an RX descriptor and attach an MBUF cluster.
|
|
|
|
*/
|
2002-08-23 23:49:02 +00:00
|
|
|
static int
|
2003-07-06 21:45:31 +00:00
|
|
|
dc_newbuf(struct dc_softc *sc, int i, int alloc)
|
1999-12-04 17:41:31 +00:00
|
|
|
{
|
2003-07-06 21:45:31 +00:00
|
|
|
struct mbuf *m_new;
|
|
|
|
bus_dmamap_t tmp;
|
|
|
|
int error;
|
1999-12-04 17:41:31 +00:00
|
|
|
|
2003-07-06 21:45:31 +00:00
|
|
|
if (alloc) {
|
|
|
|
m_new = m_getcl(M_DONTWAIT, MT_DATA, M_PKTHDR);
|
2001-12-04 02:30:53 +00:00
|
|
|
if (m_new == NULL)
|
2003-06-01 19:26:34 +00:00
|
|
|
return (ENOBUFS);
|
1999-12-04 17:41:31 +00:00
|
|
|
} else {
|
2003-07-06 21:45:31 +00:00
|
|
|
m_new = sc->dc_cdata.dc_rx_chain[i];
|
1999-12-04 17:41:31 +00:00
|
|
|
m_new->m_data = m_new->m_ext.ext_buf;
|
|
|
|
}
|
2003-07-06 21:45:31 +00:00
|
|
|
m_new->m_len = m_new->m_pkthdr.len = MCLBYTES;
|
1999-12-04 17:41:31 +00:00
|
|
|
m_adj(m_new, sizeof(u_int64_t));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If this is a PNIC chip, zero the buffer. This is part
|
|
|
|
* of the workaround for the receive bug in the 82c168 and
|
|
|
|
* 82c169 chips.
|
|
|
|
*/
|
|
|
|
if (sc->dc_flags & DC_PNIC_RX_BUG_WAR)
|
2003-06-01 19:26:34 +00:00
|
|
|
bzero(mtod(m_new, char *), m_new->m_len);
|
1999-12-04 17:41:31 +00:00
|
|
|
|
2003-07-06 21:45:31 +00:00
|
|
|
/* No need to remap the mbuf if we're reusing it. */
|
|
|
|
if (alloc) {
|
|
|
|
sc->dc_cdata.dc_rx_cur = i;
|
|
|
|
error = bus_dmamap_load_mbuf(sc->dc_mtag, sc->dc_sparemap,
|
|
|
|
m_new, dc_dma_map_rxbuf, sc, 0);
|
|
|
|
if (error) {
|
|
|
|
m_freem(m_new);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
if (sc->dc_cdata.dc_rx_err != 0) {
|
|
|
|
m_freem(m_new);
|
2004-07-05 22:35:18 +00:00
|
|
|
return (sc->dc_cdata.dc_rx_err);
|
2003-07-06 21:45:31 +00:00
|
|
|
}
|
|
|
|
bus_dmamap_unload(sc->dc_mtag, sc->dc_cdata.dc_rx_map[i]);
|
|
|
|
tmp = sc->dc_cdata.dc_rx_map[i];
|
|
|
|
sc->dc_cdata.dc_rx_map[i] = sc->dc_sparemap;
|
|
|
|
sc->dc_sparemap = tmp;
|
|
|
|
sc->dc_cdata.dc_rx_chain[i] = m_new;
|
|
|
|
}
|
|
|
|
|
2003-07-09 15:03:10 +00:00
|
|
|
sc->dc_ldata->dc_rx_list[i].dc_ctl = htole32(DC_RXCTL_RLINK | DC_RXLEN);
|
|
|
|
sc->dc_ldata->dc_rx_list[i].dc_status = htole32(DC_RXSTAT_OWN);
|
2003-07-06 21:45:31 +00:00
|
|
|
bus_dmamap_sync(sc->dc_mtag, sc->dc_cdata.dc_rx_map[i],
|
|
|
|
BUS_DMASYNC_PREREAD);
|
|
|
|
bus_dmamap_sync(sc->dc_ltag, sc->dc_lmap,
|
|
|
|
BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD);
|
2003-06-01 19:26:34 +00:00
|
|
|
return (0);
|
1999-12-04 17:41:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Grrrrr.
|
|
|
|
* The PNIC chip has a terrible bug in it that manifests itself during
|
|
|
|
* periods of heavy activity. The exact mode of failure if difficult to
|
|
|
|
* pinpoint: sometimes it only happens in promiscuous mode, sometimes it
|
|
|
|
* will happen on slow machines. The bug is that sometimes instead of
|
|
|
|
* uploading one complete frame during reception, it uploads what looks
|
|
|
|
* like the entire contents of its FIFO memory. The frame we want is at
|
|
|
|
* the end of the whole mess, but we never know exactly how much data has
|
|
|
|
* been uploaded, so salvaging the frame is hard.
|
|
|
|
*
|
|
|
|
* There is only one way to do it reliably, and it's disgusting.
|
|
|
|
* Here's what we know:
|
|
|
|
*
|
|
|
|
* - We know there will always be somewhere between one and three extra
|
|
|
|
* descriptors uploaded.
|
|
|
|
*
|
|
|
|
* - We know the desired received frame will always be at the end of the
|
|
|
|
* total data upload.
|
|
|
|
*
|
|
|
|
* - We know the size of the desired received frame because it will be
|
|
|
|
* provided in the length field of the status word in the last descriptor.
|
|
|
|
*
|
|
|
|
* Here's what we do:
|
|
|
|
*
|
|
|
|
* - When we allocate buffers for the receive ring, we bzero() them.
|
|
|
|
* This means that we know that the buffer contents should be all
|
|
|
|
* zeros, except for data uploaded by the chip.
|
|
|
|
*
|
|
|
|
* - We also force the PNIC chip to upload frames that include the
|
|
|
|
* ethernet CRC at the end.
|
|
|
|
*
|
|
|
|
* - We gather all of the bogus frame data into a single buffer.
|
|
|
|
*
|
|
|
|
* - We then position a pointer at the end of this buffer and scan
|
|
|
|
* backwards until we encounter the first non-zero byte of data.
|
|
|
|
* This is the end of the received frame. We know we will encounter
|
|
|
|
* some data at the end of the frame because the CRC will always be
|
|
|
|
* there, so even if the sender transmits a packet of all zeros,
|
|
|
|
* we won't be fooled.
|
|
|
|
*
|
|
|
|
* - We know the size of the actual received frame, so we subtract
|
|
|
|
* that value from the current pointer location. This brings us
|
|
|
|
* to the start of the actual received packet.
|
|
|
|
*
|
|
|
|
* - We copy this into an mbuf and pass it on, along with the actual
|
|
|
|
* frame length.
|
|
|
|
*
|
|
|
|
* The performance hit is tremendous, but it beats dropping frames all
|
|
|
|
* the time.
|
|
|
|
*/
|
|
|
|
|
2003-06-01 19:26:34 +00:00
|
|
|
#define DC_WHOLEFRAME (DC_RXSTAT_FIRSTFRAG | DC_RXSTAT_LASTFRAG)
|
2002-08-23 23:49:02 +00:00
|
|
|
static void
|
2003-06-01 19:26:34 +00:00
|
|
|
dc_pnic_rx_bug_war(struct dc_softc *sc, int idx)
|
1999-12-04 17:41:31 +00:00
|
|
|
{
|
2003-06-01 19:26:34 +00:00
|
|
|
struct dc_desc *cur_rx;
|
|
|
|
struct dc_desc *c = NULL;
|
|
|
|
struct mbuf *m = NULL;
|
|
|
|
unsigned char *ptr;
|
|
|
|
int i, total_len;
|
|
|
|
u_int32_t rxstat = 0;
|
1999-12-04 17:41:31 +00:00
|
|
|
|
|
|
|
i = sc->dc_pnic_rx_bug_save;
|
|
|
|
cur_rx = &sc->dc_ldata->dc_rx_list[idx];
|
|
|
|
ptr = sc->dc_pnic_rx_buf;
|
2003-06-01 22:09:12 +00:00
|
|
|
bzero(ptr, DC_RXLEN * 5);
|
1999-12-04 17:41:31 +00:00
|
|
|
|
|
|
|
/* Copy all the bytes from the bogus buffers. */
|
|
|
|
while (1) {
|
|
|
|
c = &sc->dc_ldata->dc_rx_list[i];
|
2003-07-09 15:03:10 +00:00
|
|
|
rxstat = le32toh(c->dc_status);
|
1999-12-04 17:41:31 +00:00
|
|
|
m = sc->dc_cdata.dc_rx_chain[i];
|
|
|
|
bcopy(mtod(m, char *), ptr, DC_RXLEN);
|
|
|
|
ptr += DC_RXLEN;
|
|
|
|
/* If this is the last buffer, break out. */
|
|
|
|
if (i == idx || rxstat & DC_RXSTAT_LASTFRAG)
|
|
|
|
break;
|
2003-07-06 21:45:31 +00:00
|
|
|
dc_newbuf(sc, i, 0);
|
1999-12-04 17:41:31 +00:00
|
|
|
DC_INC(i, DC_RX_LIST_CNT);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Find the length of the actual receive frame. */
|
|
|
|
total_len = DC_RXBYTES(rxstat);
|
|
|
|
|
|
|
|
/* Scan backwards until we hit a non-zero byte. */
|
2003-06-01 19:26:34 +00:00
|
|
|
while (*ptr == 0x00)
|
1999-12-04 17:41:31 +00:00
|
|
|
ptr--;
|
|
|
|
|
|
|
|
/* Round off. */
|
|
|
|
if ((uintptr_t)(ptr) & 0x3)
|
|
|
|
ptr -= 1;
|
|
|
|
|
|
|
|
/* Now find the start of the frame. */
|
|
|
|
ptr -= total_len;
|
|
|
|
if (ptr < sc->dc_pnic_rx_buf)
|
|
|
|
ptr = sc->dc_pnic_rx_buf;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Now copy the salvaged frame to the last mbuf and fake up
|
|
|
|
* the status word to make it look like a successful
|
2002-09-04 18:14:17 +00:00
|
|
|
* frame reception.
|
1999-12-04 17:41:31 +00:00
|
|
|
*/
|
2003-07-06 21:45:31 +00:00
|
|
|
dc_newbuf(sc, i, 0);
|
2003-06-01 19:26:34 +00:00
|
|
|
bcopy(ptr, mtod(m, char *), total_len);
|
2003-07-09 15:03:10 +00:00
|
|
|
cur_rx->dc_status = htole32(rxstat | DC_RXSTAT_FIRSTFRAG);
|
1999-12-04 17:41:31 +00:00
|
|
|
}
|
|
|
|
|
It appears that under certain circumstances that I still can't quite pin
down, the dc driver and receiver can fall out of sync with one another,
resulting in a condition where the chip continues to receive packets
but the driver never notices. Normally, the receive handler checks each
descriptor starting from the current producer index to see if the chip
has relinquished ownership, indicating that a packet has been received.
The driver hands the packet off to ether_input() and then prepares the
descriptor to receive another frame before moving on to the next
descriptor in the ring. But sometimes, the chip appears to skip a
descriptor. This leaves the driver testing the status word in a descriptor
that never gets updated. The driver still gets "RX done" interrupts but
never advances further into the RX ring, until the ring fills up and the
chip interrupts again to signal an error condition. Sometimes, the
driver will remain in this desynchronized state, resulting in spotty
performance until the interface is reset.
Fortunately, it's fairly simple to detect this condition: if we call
the rxeof routine but the number of received packets doesn't increase,
we suspect that there could be a problem. In this case, we call a new
routine called dc_rx_resync(), which scans ahead in the RX ring to see
if there's a frame waiting for us somewhere beyond that the driver thinks
is the current producer index. If it finds one, it bumps up the index
and calls the rxeof handler again to snarf up the packet and bring the
driver back in sync with the chip. (It may actually do this several times
in the event that there's more than one "hole" in the ring.)
So far the only card supported by if_dc which has exhibited this problem
is a LinkSys LNE100TX v2.0 (82c115 PNIC II), and it only seems to happen
on one particular system, however the fix is general enough and has low
enough overhead that we may as well apply it for all supported chipsets.
I also implemented the same fix for the 3Com xl driver, which is apparently
vulnerable to the same problem.
Problem originally noted and patch tested by: Matt Dillon
2000-01-03 15:28:47 +00:00
|
|
|
/*
|
|
|
|
* This routine searches the RX ring for dirty descriptors in the
|
|
|
|
* event that the rxeof routine falls out of sync with the chip's
|
|
|
|
* current descriptor pointer. This may happen sometimes as a result
|
|
|
|
* of a "no RX buffer available" condition that happens when the chip
|
|
|
|
* consumes all of the RX buffers before the driver has a chance to
|
|
|
|
* process the RX ring. This routine may need to be called more than
|
|
|
|
* once to bring the driver back in sync with the chip, however we
|
|
|
|
* should still be getting RX DONE interrupts to drive the search
|
|
|
|
* for new packets in the RX ring, so we should catch up eventually.
|
|
|
|
*/
|
2002-08-23 23:49:02 +00:00
|
|
|
static int
|
2003-06-01 19:26:34 +00:00
|
|
|
dc_rx_resync(struct dc_softc *sc)
|
It appears that under certain circumstances that I still can't quite pin
down, the dc driver and receiver can fall out of sync with one another,
resulting in a condition where the chip continues to receive packets
but the driver never notices. Normally, the receive handler checks each
descriptor starting from the current producer index to see if the chip
has relinquished ownership, indicating that a packet has been received.
The driver hands the packet off to ether_input() and then prepares the
descriptor to receive another frame before moving on to the next
descriptor in the ring. But sometimes, the chip appears to skip a
descriptor. This leaves the driver testing the status word in a descriptor
that never gets updated. The driver still gets "RX done" interrupts but
never advances further into the RX ring, until the ring fills up and the
chip interrupts again to signal an error condition. Sometimes, the
driver will remain in this desynchronized state, resulting in spotty
performance until the interface is reset.
Fortunately, it's fairly simple to detect this condition: if we call
the rxeof routine but the number of received packets doesn't increase,
we suspect that there could be a problem. In this case, we call a new
routine called dc_rx_resync(), which scans ahead in the RX ring to see
if there's a frame waiting for us somewhere beyond that the driver thinks
is the current producer index. If it finds one, it bumps up the index
and calls the rxeof handler again to snarf up the packet and bring the
driver back in sync with the chip. (It may actually do this several times
in the event that there's more than one "hole" in the ring.)
So far the only card supported by if_dc which has exhibited this problem
is a LinkSys LNE100TX v2.0 (82c115 PNIC II), and it only seems to happen
on one particular system, however the fix is general enough and has low
enough overhead that we may as well apply it for all supported chipsets.
I also implemented the same fix for the 3Com xl driver, which is apparently
vulnerable to the same problem.
Problem originally noted and patch tested by: Matt Dillon
2000-01-03 15:28:47 +00:00
|
|
|
{
|
2003-06-01 19:26:34 +00:00
|
|
|
struct dc_desc *cur_rx;
|
|
|
|
int i, pos;
|
It appears that under certain circumstances that I still can't quite pin
down, the dc driver and receiver can fall out of sync with one another,
resulting in a condition where the chip continues to receive packets
but the driver never notices. Normally, the receive handler checks each
descriptor starting from the current producer index to see if the chip
has relinquished ownership, indicating that a packet has been received.
The driver hands the packet off to ether_input() and then prepares the
descriptor to receive another frame before moving on to the next
descriptor in the ring. But sometimes, the chip appears to skip a
descriptor. This leaves the driver testing the status word in a descriptor
that never gets updated. The driver still gets "RX done" interrupts but
never advances further into the RX ring, until the ring fills up and the
chip interrupts again to signal an error condition. Sometimes, the
driver will remain in this desynchronized state, resulting in spotty
performance until the interface is reset.
Fortunately, it's fairly simple to detect this condition: if we call
the rxeof routine but the number of received packets doesn't increase,
we suspect that there could be a problem. In this case, we call a new
routine called dc_rx_resync(), which scans ahead in the RX ring to see
if there's a frame waiting for us somewhere beyond that the driver thinks
is the current producer index. If it finds one, it bumps up the index
and calls the rxeof handler again to snarf up the packet and bring the
driver back in sync with the chip. (It may actually do this several times
in the event that there's more than one "hole" in the ring.)
So far the only card supported by if_dc which has exhibited this problem
is a LinkSys LNE100TX v2.0 (82c115 PNIC II), and it only seems to happen
on one particular system, however the fix is general enough and has low
enough overhead that we may as well apply it for all supported chipsets.
I also implemented the same fix for the 3Com xl driver, which is apparently
vulnerable to the same problem.
Problem originally noted and patch tested by: Matt Dillon
2000-01-03 15:28:47 +00:00
|
|
|
|
|
|
|
pos = sc->dc_cdata.dc_rx_prod;
|
|
|
|
|
|
|
|
for (i = 0; i < DC_RX_LIST_CNT; i++) {
|
|
|
|
cur_rx = &sc->dc_ldata->dc_rx_list[pos];
|
2003-07-09 15:03:10 +00:00
|
|
|
if (!(le32toh(cur_rx->dc_status) & DC_RXSTAT_OWN))
|
It appears that under certain circumstances that I still can't quite pin
down, the dc driver and receiver can fall out of sync with one another,
resulting in a condition where the chip continues to receive packets
but the driver never notices. Normally, the receive handler checks each
descriptor starting from the current producer index to see if the chip
has relinquished ownership, indicating that a packet has been received.
The driver hands the packet off to ether_input() and then prepares the
descriptor to receive another frame before moving on to the next
descriptor in the ring. But sometimes, the chip appears to skip a
descriptor. This leaves the driver testing the status word in a descriptor
that never gets updated. The driver still gets "RX done" interrupts but
never advances further into the RX ring, until the ring fills up and the
chip interrupts again to signal an error condition. Sometimes, the
driver will remain in this desynchronized state, resulting in spotty
performance until the interface is reset.
Fortunately, it's fairly simple to detect this condition: if we call
the rxeof routine but the number of received packets doesn't increase,
we suspect that there could be a problem. In this case, we call a new
routine called dc_rx_resync(), which scans ahead in the RX ring to see
if there's a frame waiting for us somewhere beyond that the driver thinks
is the current producer index. If it finds one, it bumps up the index
and calls the rxeof handler again to snarf up the packet and bring the
driver back in sync with the chip. (It may actually do this several times
in the event that there's more than one "hole" in the ring.)
So far the only card supported by if_dc which has exhibited this problem
is a LinkSys LNE100TX v2.0 (82c115 PNIC II), and it only seems to happen
on one particular system, however the fix is general enough and has low
enough overhead that we may as well apply it for all supported chipsets.
I also implemented the same fix for the 3Com xl driver, which is apparently
vulnerable to the same problem.
Problem originally noted and patch tested by: Matt Dillon
2000-01-03 15:28:47 +00:00
|
|
|
break;
|
|
|
|
DC_INC(pos, DC_RX_LIST_CNT);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If the ring really is empty, then just return. */
|
|
|
|
if (i == DC_RX_LIST_CNT)
|
2003-06-01 19:26:34 +00:00
|
|
|
return (0);
|
It appears that under certain circumstances that I still can't quite pin
down, the dc driver and receiver can fall out of sync with one another,
resulting in a condition where the chip continues to receive packets
but the driver never notices. Normally, the receive handler checks each
descriptor starting from the current producer index to see if the chip
has relinquished ownership, indicating that a packet has been received.
The driver hands the packet off to ether_input() and then prepares the
descriptor to receive another frame before moving on to the next
descriptor in the ring. But sometimes, the chip appears to skip a
descriptor. This leaves the driver testing the status word in a descriptor
that never gets updated. The driver still gets "RX done" interrupts but
never advances further into the RX ring, until the ring fills up and the
chip interrupts again to signal an error condition. Sometimes, the
driver will remain in this desynchronized state, resulting in spotty
performance until the interface is reset.
Fortunately, it's fairly simple to detect this condition: if we call
the rxeof routine but the number of received packets doesn't increase,
we suspect that there could be a problem. In this case, we call a new
routine called dc_rx_resync(), which scans ahead in the RX ring to see
if there's a frame waiting for us somewhere beyond that the driver thinks
is the current producer index. If it finds one, it bumps up the index
and calls the rxeof handler again to snarf up the packet and bring the
driver back in sync with the chip. (It may actually do this several times
in the event that there's more than one "hole" in the ring.)
So far the only card supported by if_dc which has exhibited this problem
is a LinkSys LNE100TX v2.0 (82c115 PNIC II), and it only seems to happen
on one particular system, however the fix is general enough and has low
enough overhead that we may as well apply it for all supported chipsets.
I also implemented the same fix for the 3Com xl driver, which is apparently
vulnerable to the same problem.
Problem originally noted and patch tested by: Matt Dillon
2000-01-03 15:28:47 +00:00
|
|
|
|
|
|
|
/* We've fallen behing the chip: catch it. */
|
|
|
|
sc->dc_cdata.dc_rx_prod = pos;
|
|
|
|
|
2003-06-01 19:26:34 +00:00
|
|
|
return (EAGAIN);
|
It appears that under certain circumstances that I still can't quite pin
down, the dc driver and receiver can fall out of sync with one another,
resulting in a condition where the chip continues to receive packets
but the driver never notices. Normally, the receive handler checks each
descriptor starting from the current producer index to see if the chip
has relinquished ownership, indicating that a packet has been received.
The driver hands the packet off to ether_input() and then prepares the
descriptor to receive another frame before moving on to the next
descriptor in the ring. But sometimes, the chip appears to skip a
descriptor. This leaves the driver testing the status word in a descriptor
that never gets updated. The driver still gets "RX done" interrupts but
never advances further into the RX ring, until the ring fills up and the
chip interrupts again to signal an error condition. Sometimes, the
driver will remain in this desynchronized state, resulting in spotty
performance until the interface is reset.
Fortunately, it's fairly simple to detect this condition: if we call
the rxeof routine but the number of received packets doesn't increase,
we suspect that there could be a problem. In this case, we call a new
routine called dc_rx_resync(), which scans ahead in the RX ring to see
if there's a frame waiting for us somewhere beyond that the driver thinks
is the current producer index. If it finds one, it bumps up the index
and calls the rxeof handler again to snarf up the packet and bring the
driver back in sync with the chip. (It may actually do this several times
in the event that there's more than one "hole" in the ring.)
So far the only card supported by if_dc which has exhibited this problem
is a LinkSys LNE100TX v2.0 (82c115 PNIC II), and it only seems to happen
on one particular system, however the fix is general enough and has low
enough overhead that we may as well apply it for all supported chipsets.
I also implemented the same fix for the 3Com xl driver, which is apparently
vulnerable to the same problem.
Problem originally noted and patch tested by: Matt Dillon
2000-01-03 15:28:47 +00:00
|
|
|
}
|
|
|
|
|
1999-12-04 17:41:31 +00:00
|
|
|
/*
|
|
|
|
* A frame has been uploaded: pass the resulting mbuf chain up to
|
|
|
|
* the higher level protocols.
|
|
|
|
*/
|
2002-08-23 23:49:02 +00:00
|
|
|
static void
|
2003-06-01 19:26:34 +00:00
|
|
|
dc_rxeof(struct dc_softc *sc)
|
1999-12-04 17:41:31 +00:00
|
|
|
{
|
2003-06-01 19:26:34 +00:00
|
|
|
struct mbuf *m;
|
|
|
|
struct ifnet *ifp;
|
|
|
|
struct dc_desc *cur_rx;
|
|
|
|
int i, total_len = 0;
|
|
|
|
u_int32_t rxstat;
|
1999-12-04 17:41:31 +00:00
|
|
|
|
2003-11-14 19:00:32 +00:00
|
|
|
DC_LOCK_ASSERT(sc);
|
|
|
|
|
2005-06-10 16:49:24 +00:00
|
|
|
ifp = sc->dc_ifp;
|
1999-12-04 17:41:31 +00:00
|
|
|
i = sc->dc_cdata.dc_rx_prod;
|
|
|
|
|
2003-07-06 21:45:31 +00:00
|
|
|
bus_dmamap_sync(sc->dc_ltag, sc->dc_lmap, BUS_DMASYNC_POSTREAD);
|
2003-07-09 15:03:10 +00:00
|
|
|
while (!(le32toh(sc->dc_ldata->dc_rx_list[i].dc_status) &
|
|
|
|
DC_RXSTAT_OWN)) {
|
Device Polling code for -current.
Non-SMP, i386-only, no polling in the idle loop at the moment.
To use this code you must compile a kernel with
options DEVICE_POLLING
and at runtime enable polling with
sysctl kern.polling.enable=1
The percentage of CPU reserved to userland can be set with
sysctl kern.polling.user_frac=NN (default is 50)
while the remainder is used by polling device drivers and netisr's.
These are the only two variables that you should need to touch. There
are a few more parameters in kern.polling but the default values
are adequate for all purposes. See the code in kern_poll.c for
more details on them.
Polling in the idle loop will be implemented shortly by introducing
a kernel thread which does the job. Until then, the amount of CPU
dedicated to polling will never exceed (100-user_frac).
The equivalent (actually, better) code for -stable is at
http://info.iet.unipi.it/~luigi/polling/
and also supports polling in the idle loop.
NOTE to Alpha developers:
There is really nothing in this code that is i386-specific.
If you move the 2 lines supporting the new option from
sys/conf/{files,options}.i386 to sys/conf/{files,options} I am
pretty sure that this should work on the Alpha as well, just that
I do not have a suitable test box to try it. If someone feels like
trying it, I would appreciate it.
NOTE to other developers:
sure some things could be done better, and as always I am open to
constructive criticism, which a few of you have already given and
I greatly appreciated.
However, before proposing radical architectural changes, please
take some time to possibly try out this code, or at the very least
read the comments in kern_poll.c, especially re. the reason why I
am using a soft netisr and cannot (I believe) replace it with a
simple timeout.
Quick description of files touched by this commit:
sys/conf/files.i386
new file kern/kern_poll.c
sys/conf/options.i386
new option
sys/i386/i386/trap.c
poll in trap (disabled by default)
sys/kern/kern_clock.c
initialization and hardclock hooks.
sys/kern/kern_intr.c
minor swi_net changes
sys/kern/kern_poll.c
the bulk of the code.
sys/net/if.h
new flag
sys/net/if_var.h
declaration for functions used in device drivers.
sys/net/netisr.h
NETISR_POLL
sys/dev/fxp/if_fxp.c
sys/dev/fxp/if_fxpvar.h
sys/pci/if_dc.c
sys/pci/if_dcreg.h
sys/pci/if_sis.c
sys/pci/if_sisreg.h
device driver modifications
2001-12-14 17:56:12 +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) {
|
Device Polling code for -current.
Non-SMP, i386-only, no polling in the idle loop at the moment.
To use this code you must compile a kernel with
options DEVICE_POLLING
and at runtime enable polling with
sysctl kern.polling.enable=1
The percentage of CPU reserved to userland can be set with
sysctl kern.polling.user_frac=NN (default is 50)
while the remainder is used by polling device drivers and netisr's.
These are the only two variables that you should need to touch. There
are a few more parameters in kern.polling but the default values
are adequate for all purposes. See the code in kern_poll.c for
more details on them.
Polling in the idle loop will be implemented shortly by introducing
a kernel thread which does the job. Until then, the amount of CPU
dedicated to polling will never exceed (100-user_frac).
The equivalent (actually, better) code for -stable is at
http://info.iet.unipi.it/~luigi/polling/
and also supports polling in the idle loop.
NOTE to Alpha developers:
There is really nothing in this code that is i386-specific.
If you move the 2 lines supporting the new option from
sys/conf/{files,options}.i386 to sys/conf/{files,options} I am
pretty sure that this should work on the Alpha as well, just that
I do not have a suitable test box to try it. If someone feels like
trying it, I would appreciate it.
NOTE to other developers:
sure some things could be done better, and as always I am open to
constructive criticism, which a few of you have already given and
I greatly appreciated.
However, before proposing radical architectural changes, please
take some time to possibly try out this code, or at the very least
read the comments in kern_poll.c, especially re. the reason why I
am using a soft netisr and cannot (I believe) replace it with a
simple timeout.
Quick description of files touched by this commit:
sys/conf/files.i386
new file kern/kern_poll.c
sys/conf/options.i386
new option
sys/i386/i386/trap.c
poll in trap (disabled by default)
sys/kern/kern_clock.c
initialization and hardclock hooks.
sys/kern/kern_intr.c
minor swi_net changes
sys/kern/kern_poll.c
the bulk of the code.
sys/net/if.h
new flag
sys/net/if_var.h
declaration for functions used in device drivers.
sys/net/netisr.h
NETISR_POLL
sys/dev/fxp/if_fxp.c
sys/dev/fxp/if_fxpvar.h
sys/pci/if_dc.c
sys/pci/if_dcreg.h
sys/pci/if_sis.c
sys/pci/if_sisreg.h
device driver modifications
2001-12-14 17:56:12 +00:00
|
|
|
if (sc->rxcycles <= 0)
|
|
|
|
break;
|
|
|
|
sc->rxcycles--;
|
|
|
|
}
|
2003-06-01 19:26:34 +00:00
|
|
|
#endif
|
1999-12-04 17:41:31 +00:00
|
|
|
cur_rx = &sc->dc_ldata->dc_rx_list[i];
|
2003-07-09 15:03:10 +00:00
|
|
|
rxstat = le32toh(cur_rx->dc_status);
|
1999-12-04 17:41:31 +00:00
|
|
|
m = sc->dc_cdata.dc_rx_chain[i];
|
2003-07-06 21:45:31 +00:00
|
|
|
bus_dmamap_sync(sc->dc_mtag, sc->dc_cdata.dc_rx_map[i],
|
|
|
|
BUS_DMASYNC_POSTREAD);
|
1999-12-04 17:41:31 +00:00
|
|
|
total_len = DC_RXBYTES(rxstat);
|
|
|
|
|
|
|
|
if (sc->dc_flags & DC_PNIC_RX_BUG_WAR) {
|
|
|
|
if ((rxstat & DC_WHOLEFRAME) != DC_WHOLEFRAME) {
|
|
|
|
if (rxstat & DC_RXSTAT_FIRSTFRAG)
|
|
|
|
sc->dc_pnic_rx_bug_save = i;
|
|
|
|
if ((rxstat & DC_RXSTAT_LASTFRAG) == 0) {
|
|
|
|
DC_INC(i, DC_RX_LIST_CNT);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
dc_pnic_rx_bug_war(sc, i);
|
2003-07-09 15:03:10 +00:00
|
|
|
rxstat = le32toh(cur_rx->dc_status);
|
1999-12-04 17:41:31 +00:00
|
|
|
total_len = DC_RXBYTES(rxstat);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If an error occurs, update stats, clear the
|
|
|
|
* status word and leave the mbuf cluster in place:
|
|
|
|
* it should simply get re-used next time this descriptor
|
2002-01-16 16:33:58 +00:00
|
|
|
* comes up in the ring. However, don't report long
|
2003-06-01 19:26:34 +00:00
|
|
|
* frames as errors since they could be vlans.
|
1999-12-04 17:41:31 +00:00
|
|
|
*/
|
2003-06-01 19:26:34 +00:00
|
|
|
if ((rxstat & DC_RXSTAT_RXERR)) {
|
2002-01-16 16:33:58 +00:00
|
|
|
if (!(rxstat & DC_RXSTAT_GIANT) ||
|
|
|
|
(rxstat & (DC_RXSTAT_CRCERR | DC_RXSTAT_DRIBBLE |
|
|
|
|
DC_RXSTAT_MIIERE | DC_RXSTAT_COLLSEEN |
|
|
|
|
DC_RXSTAT_RUNT | DC_RXSTAT_DE))) {
|
|
|
|
ifp->if_ierrors++;
|
|
|
|
if (rxstat & DC_RXSTAT_COLLSEEN)
|
|
|
|
ifp->if_collisions++;
|
2003-07-06 21:45:31 +00:00
|
|
|
dc_newbuf(sc, i, 0);
|
2002-01-16 16:33:58 +00:00
|
|
|
if (rxstat & DC_RXSTAT_CRCERR) {
|
|
|
|
DC_INC(i, DC_RX_LIST_CNT);
|
|
|
|
continue;
|
|
|
|
} else {
|
2005-08-18 19:10:07 +00:00
|
|
|
dc_init_locked(sc);
|
2002-01-16 16:33:58 +00:00
|
|
|
return;
|
|
|
|
}
|
1999-12-04 17:41:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-06-01 19:26:34 +00:00
|
|
|
/* No errors; receive the packet. */
|
1999-12-04 17:41:31 +00:00
|
|
|
total_len -= ETHER_CRC_LEN;
|
For i386 architecture, remove an expensive m_devget() (and the
underlying unaligned bcopy) on incoming packets that are already
available (albeit unaligned) in a buffer.
The performance improvement varies, depending on CPU and memory
speed, but can be quite large especially on slow CPUs. I have seen
over 50% increase on forwarding speed on the sis driver for the
486/133 (embedded systems), which does exactly the same thing.
The behaviour is controlled by a sysctl variable, hw.dc_quick which
defaults to 1. Set it to 0 to restore the old behaviour.
After running a few experiments (in userland, though) I am convinced
that doing the m_devget() is detrimental to performance in almost
all cases.
Even if your CPU has degraded performance with misaligned data,
the bcopy() in the driver has the same overhead due to misaligment
as the one that you save in the uiomove(), plus you do one extra
copy and pollute the cache.
But more often than not, you do not even have to touch the payload,
e.g. when you are forwarding packets, and even in the often-cited
case of NFS, you often end up passing a pointer to the payload to
the disk controller.
In any case, you can play with the sysctl variable to toggle between
the two behaviours, and see if it makes a difference.
MFC-after: 3 days
2001-11-29 22:46:48 +00:00
|
|
|
#ifdef __i386__
|
|
|
|
/*
|
|
|
|
* On the x86 we do not have alignment problems, so try to
|
|
|
|
* allocate a new buffer for the receive ring, and pass up
|
|
|
|
* the one where the packet is already, saving the expensive
|
|
|
|
* copy done in m_devget().
|
|
|
|
* If we are on an architecture with alignment problems, or
|
|
|
|
* if the allocation fails, then use m_devget and leave the
|
|
|
|
* existing buffer in the receive ring.
|
|
|
|
*/
|
2003-07-06 21:45:31 +00:00
|
|
|
if (dc_quick && dc_newbuf(sc, i, 1) == 0) {
|
For i386 architecture, remove an expensive m_devget() (and the
underlying unaligned bcopy) on incoming packets that are already
available (albeit unaligned) in a buffer.
The performance improvement varies, depending on CPU and memory
speed, but can be quite large especially on slow CPUs. I have seen
over 50% increase on forwarding speed on the sis driver for the
486/133 (embedded systems), which does exactly the same thing.
The behaviour is controlled by a sysctl variable, hw.dc_quick which
defaults to 1. Set it to 0 to restore the old behaviour.
After running a few experiments (in userland, though) I am convinced
that doing the m_devget() is detrimental to performance in almost
all cases.
Even if your CPU has degraded performance with misaligned data,
the bcopy() in the driver has the same overhead due to misaligment
as the one that you save in the uiomove(), plus you do one extra
copy and pollute the cache.
But more often than not, you do not even have to touch the payload,
e.g. when you are forwarding packets, and even in the often-cited
case of NFS, you often end up passing a pointer to the payload to
the disk controller.
In any case, you can play with the sysctl variable to toggle between
the two behaviours, and see if it makes a difference.
MFC-after: 3 days
2001-11-29 22:46:48 +00:00
|
|
|
m->m_pkthdr.rcvif = ifp;
|
|
|
|
m->m_pkthdr.len = m->m_len = total_len;
|
|
|
|
DC_INC(i, DC_RX_LIST_CNT);
|
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
struct mbuf *m0;
|
1999-12-04 17:41:31 +00:00
|
|
|
|
For i386 architecture, remove an expensive m_devget() (and the
underlying unaligned bcopy) on incoming packets that are already
available (albeit unaligned) in a buffer.
The performance improvement varies, depending on CPU and memory
speed, but can be quite large especially on slow CPUs. I have seen
over 50% increase on forwarding speed on the sis driver for the
486/133 (embedded systems), which does exactly the same thing.
The behaviour is controlled by a sysctl variable, hw.dc_quick which
defaults to 1. Set it to 0 to restore the old behaviour.
After running a few experiments (in userland, though) I am convinced
that doing the m_devget() is detrimental to performance in almost
all cases.
Even if your CPU has degraded performance with misaligned data,
the bcopy() in the driver has the same overhead due to misaligment
as the one that you save in the uiomove(), plus you do one extra
copy and pollute the cache.
But more often than not, you do not even have to touch the payload,
e.g. when you are forwarding packets, and even in the often-cited
case of NFS, you often end up passing a pointer to the payload to
the disk controller.
In any case, you can play with the sysctl variable to toggle between
the two behaviours, and see if it makes a difference.
MFC-after: 3 days
2001-11-29 22:46:48 +00:00
|
|
|
m0 = m_devget(mtod(m, char *), total_len,
|
|
|
|
ETHER_ALIGN, ifp, NULL);
|
2003-07-06 21:45:31 +00:00
|
|
|
dc_newbuf(sc, i, 0);
|
For i386 architecture, remove an expensive m_devget() (and the
underlying unaligned bcopy) on incoming packets that are already
available (albeit unaligned) in a buffer.
The performance improvement varies, depending on CPU and memory
speed, but can be quite large especially on slow CPUs. I have seen
over 50% increase on forwarding speed on the sis driver for the
486/133 (embedded systems), which does exactly the same thing.
The behaviour is controlled by a sysctl variable, hw.dc_quick which
defaults to 1. Set it to 0 to restore the old behaviour.
After running a few experiments (in userland, though) I am convinced
that doing the m_devget() is detrimental to performance in almost
all cases.
Even if your CPU has degraded performance with misaligned data,
the bcopy() in the driver has the same overhead due to misaligment
as the one that you save in the uiomove(), plus you do one extra
copy and pollute the cache.
But more often than not, you do not even have to touch the payload,
e.g. when you are forwarding packets, and even in the often-cited
case of NFS, you often end up passing a pointer to the payload to
the disk controller.
In any case, you can play with the sysctl variable to toggle between
the two behaviours, and see if it makes a difference.
MFC-after: 3 days
2001-11-29 22:46:48 +00:00
|
|
|
DC_INC(i, DC_RX_LIST_CNT);
|
|
|
|
if (m0 == NULL) {
|
|
|
|
ifp->if_ierrors++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
m = m0;
|
1999-12-04 17:41:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ifp->if_ipackets++;
|
2003-11-14 19:00:32 +00:00
|
|
|
DC_UNLOCK(sc);
|
2002-11-14 23:49:09 +00:00
|
|
|
(*ifp->if_input)(ifp, m);
|
2003-11-14 19:00:32 +00:00
|
|
|
DC_LOCK(sc);
|
1999-12-04 17:41:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sc->dc_cdata.dc_rx_prod = i;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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
|
2003-06-01 19:26:34 +00:00
|
|
|
dc_txeof(struct dc_softc *sc)
|
1999-12-04 17:41:31 +00:00
|
|
|
{
|
2003-06-01 19:26:34 +00:00
|
|
|
struct dc_desc *cur_tx = NULL;
|
|
|
|
struct ifnet *ifp;
|
|
|
|
int idx;
|
2003-07-09 15:03:10 +00:00
|
|
|
u_int32_t ctl, txstat;
|
1999-12-04 17:41:31 +00:00
|
|
|
|
2005-06-10 16:49:24 +00:00
|
|
|
ifp = sc->dc_ifp;
|
1999-12-04 17:41:31 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Go through our tx list and free mbufs for those
|
|
|
|
* frames that have been transmitted.
|
|
|
|
*/
|
2003-07-06 21:45:31 +00:00
|
|
|
bus_dmamap_sync(sc->dc_ltag, sc->dc_lmap, BUS_DMASYNC_POSTREAD);
|
1999-12-04 17:41:31 +00:00
|
|
|
idx = sc->dc_cdata.dc_tx_cons;
|
2003-06-01 19:26:34 +00:00
|
|
|
while (idx != sc->dc_cdata.dc_tx_prod) {
|
1999-12-04 17:41:31 +00:00
|
|
|
|
|
|
|
cur_tx = &sc->dc_ldata->dc_tx_list[idx];
|
2003-07-09 15:03:10 +00:00
|
|
|
txstat = le32toh(cur_tx->dc_status);
|
|
|
|
ctl = le32toh(cur_tx->dc_ctl);
|
1999-12-04 17:41:31 +00:00
|
|
|
|
|
|
|
if (txstat & DC_TXSTAT_OWN)
|
|
|
|
break;
|
|
|
|
|
2004-01-08 06:22:15 +00:00
|
|
|
if (!(ctl & DC_TXCTL_LASTFRAG) || ctl & DC_TXCTL_SETUP) {
|
2003-07-09 15:03:10 +00:00
|
|
|
if (ctl & DC_TXCTL_SETUP) {
|
1999-12-04 17:41:31 +00:00
|
|
|
/*
|
|
|
|
* Yes, the PNIC is so brain damaged
|
|
|
|
* that it will sometimes generate a TX
|
|
|
|
* underrun error while DMAing the RX
|
|
|
|
* filter setup frame. If we detect this,
|
|
|
|
* we have to send the setup frame again,
|
|
|
|
* or else the filter won't be programmed
|
|
|
|
* correctly.
|
|
|
|
*/
|
|
|
|
if (DC_IS_PNIC(sc)) {
|
|
|
|
if (txstat & DC_TXSTAT_ERRSUM)
|
|
|
|
dc_setfilt(sc);
|
|
|
|
}
|
|
|
|
sc->dc_cdata.dc_tx_chain[idx] = NULL;
|
|
|
|
}
|
2002-06-30 22:05:46 +00:00
|
|
|
sc->dc_cdata.dc_tx_cnt--;
|
1999-12-04 17:41:31 +00:00
|
|
|
DC_INC(idx, DC_TX_LIST_CNT);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2001-12-19 18:23:45 +00:00
|
|
|
if (DC_IS_XIRCOM(sc) || DC_IS_CONEXANT(sc)) {
|
2000-10-19 08:34:32 +00:00
|
|
|
/*
|
|
|
|
* XXX: Why does my Xircom taunt me so?
|
|
|
|
* For some reason it likes setting the CARRLOST flag
|
2001-12-19 18:23:45 +00:00
|
|
|
* even when the carrier is there. wtf?!?
|
|
|
|
* Who knows, but Conexant chips have the
|
|
|
|
* same problem. Maybe they took lessons
|
|
|
|
* from Xircom.
|
|
|
|
*/
|
2000-10-19 08:34:32 +00:00
|
|
|
if (/*sc->dc_type == DC_TYPE_21143 &&*/
|
|
|
|
sc->dc_pmode == DC_PMODE_MII &&
|
2003-06-01 19:26:34 +00:00
|
|
|
((txstat & 0xFFFF) & ~(DC_TXSTAT_ERRSUM |
|
2001-12-19 18:23:45 +00:00
|
|
|
DC_TXSTAT_NOCARRIER)))
|
2000-10-19 08:34:32 +00:00
|
|
|
txstat &= ~DC_TXSTAT_ERRSUM;
|
|
|
|
} else {
|
|
|
|
if (/*sc->dc_type == DC_TYPE_21143 &&*/
|
|
|
|
sc->dc_pmode == DC_PMODE_MII &&
|
2003-06-01 19:26:34 +00:00
|
|
|
((txstat & 0xFFFF) & ~(DC_TXSTAT_ERRSUM |
|
|
|
|
DC_TXSTAT_NOCARRIER | DC_TXSTAT_CARRLOST)))
|
2000-10-19 08:34:32 +00:00
|
|
|
txstat &= ~DC_TXSTAT_ERRSUM;
|
|
|
|
}
|
1999-12-04 17:41:31 +00:00
|
|
|
|
|
|
|
if (txstat & DC_TXSTAT_ERRSUM) {
|
|
|
|
ifp->if_oerrors++;
|
|
|
|
if (txstat & DC_TXSTAT_EXCESSCOLL)
|
|
|
|
ifp->if_collisions++;
|
|
|
|
if (txstat & DC_TXSTAT_LATECOLL)
|
|
|
|
ifp->if_collisions++;
|
|
|
|
if (!(txstat & DC_TXSTAT_UNDERRUN)) {
|
2005-08-18 19:10:07 +00:00
|
|
|
dc_init_locked(sc);
|
1999-12-04 17:41:31 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ifp->if_collisions += (txstat & DC_TXSTAT_COLLCNT) >> 3;
|
|
|
|
|
|
|
|
ifp->if_opackets++;
|
|
|
|
if (sc->dc_cdata.dc_tx_chain[idx] != NULL) {
|
2003-07-06 21:45:31 +00:00
|
|
|
bus_dmamap_sync(sc->dc_mtag,
|
|
|
|
sc->dc_cdata.dc_tx_map[idx],
|
|
|
|
BUS_DMASYNC_POSTWRITE);
|
|
|
|
bus_dmamap_unload(sc->dc_mtag,
|
|
|
|
sc->dc_cdata.dc_tx_map[idx]);
|
1999-12-04 17:41:31 +00:00
|
|
|
m_freem(sc->dc_cdata.dc_tx_chain[idx]);
|
|
|
|
sc->dc_cdata.dc_tx_chain[idx] = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
sc->dc_cdata.dc_tx_cnt--;
|
|
|
|
DC_INC(idx, DC_TX_LIST_CNT);
|
|
|
|
}
|
|
|
|
|
2002-06-30 22:05:46 +00:00
|
|
|
if (idx != sc->dc_cdata.dc_tx_cons) {
|
2003-06-01 19:26:34 +00:00
|
|
|
/* Some buffers have been freed. */
|
2002-06-30 22:05:46 +00:00
|
|
|
sc->dc_cdata.dc_tx_cons = idx;
|
2005-08-09 10:20:02 +00:00
|
|
|
ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
|
2002-06-30 22:05:46 +00:00
|
|
|
}
|
|
|
|
ifp->if_timer = (sc->dc_cdata.dc_tx_cnt == 0) ? 0 : 5;
|
1999-12-04 17:41:31 +00:00
|
|
|
}
|
|
|
|
|
2002-08-23 23:49:02 +00:00
|
|
|
static void
|
2003-06-01 19:26:34 +00:00
|
|
|
dc_tick(void *xsc)
|
1999-12-04 17:41:31 +00:00
|
|
|
{
|
2003-06-01 19:26:34 +00:00
|
|
|
struct dc_softc *sc;
|
|
|
|
struct mii_data *mii;
|
|
|
|
struct ifnet *ifp;
|
|
|
|
u_int32_t r;
|
1999-12-04 17:41:31 +00:00
|
|
|
|
|
|
|
sc = xsc;
|
2005-08-18 19:10:07 +00:00
|
|
|
DC_LOCK_ASSERT(sc);
|
2005-06-10 16:49:24 +00:00
|
|
|
ifp = sc->dc_ifp;
|
1999-12-04 17:41:31 +00:00
|
|
|
mii = device_get_softc(sc->dc_miibus);
|
|
|
|
|
|
|
|
if (sc->dc_flags & DC_REDUCED_MII_POLL) {
|
2000-05-31 05:40:53 +00:00
|
|
|
if (sc->dc_flags & DC_21143_NWAY) {
|
|
|
|
r = CSR_READ_4(sc, DC_10BTSTAT);
|
|
|
|
if (IFM_SUBTYPE(mii->mii_media_active) ==
|
|
|
|
IFM_100_TX && (r & DC_TSTAT_LS100)) {
|
1999-12-04 17:41:31 +00:00
|
|
|
sc->dc_link = 0;
|
2000-05-31 05:40:53 +00:00
|
|
|
mii_mediachg(mii);
|
|
|
|
}
|
|
|
|
if (IFM_SUBTYPE(mii->mii_media_active) ==
|
|
|
|
IFM_10_T && (r & DC_TSTAT_LS10)) {
|
|
|
|
sc->dc_link = 0;
|
|
|
|
mii_mediachg(mii);
|
|
|
|
}
|
1999-12-07 19:18:41 +00:00
|
|
|
if (sc->dc_link == 0)
|
1999-12-04 17:41:31 +00:00
|
|
|
mii_tick(mii);
|
|
|
|
} else {
|
2000-05-31 05:40:53 +00:00
|
|
|
r = CSR_READ_4(sc, DC_ISR);
|
1999-12-04 17:41:31 +00:00
|
|
|
if ((r & DC_ISR_RX_STATE) == DC_RXSTATE_WAIT &&
|
2003-02-07 13:55:02 +00:00
|
|
|
sc->dc_cdata.dc_tx_cnt == 0) {
|
1999-12-04 17:41:31 +00:00
|
|
|
mii_tick(mii);
|
2000-06-07 17:07:44 +00:00
|
|
|
if (!(mii->mii_media_status & IFM_ACTIVE))
|
|
|
|
sc->dc_link = 0;
|
2003-02-07 13:55:02 +00:00
|
|
|
}
|
1999-12-04 17:41:31 +00:00
|
|
|
}
|
|
|
|
} else
|
|
|
|
mii_tick(mii);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* When the init routine completes, we expect to be able to send
|
|
|
|
* packets right away, and in fact the network code will send a
|
|
|
|
* gratuitous ARP the moment the init routine marks the interface
|
|
|
|
* as running. However, even though the MAC may have been initialized,
|
|
|
|
* there may be a delay of a few seconds before the PHY completes
|
|
|
|
* autonegotiation and the link is brought up. Any transmissions
|
|
|
|
* made during that delay will be lost. Dealing with this is tricky:
|
|
|
|
* we can't just pause in the init routine while waiting for the
|
|
|
|
* PHY to come ready since that would bring the whole system to
|
|
|
|
* a screeching halt for several seconds.
|
|
|
|
*
|
|
|
|
* What we do here is prevent the TX start routine from sending
|
|
|
|
* any packets until a link has been established. After the
|
|
|
|
* interface has been initialized, the tick routine will poll
|
|
|
|
* the state of the PHY until the IFM_ACTIVE flag is set. Until
|
|
|
|
* that time, packets will stay in the send queue, and once the
|
|
|
|
* link comes up, they will be flushed out to the wire.
|
|
|
|
*/
|
2001-09-29 19:28:31 +00:00
|
|
|
if (!sc->dc_link && mii->mii_media_status & IFM_ACTIVE &&
|
|
|
|
IFM_SUBTYPE(mii->mii_media_active) != IFM_NONE) {
|
|
|
|
sc->dc_link++;
|
2004-10-01 07:04:09 +00:00
|
|
|
if (!IFQ_DRV_IS_EMPTY(&ifp->if_snd))
|
2005-08-18 19:10:07 +00:00
|
|
|
dc_start_locked(ifp);
|
1999-12-04 17:41:31 +00:00
|
|
|
}
|
|
|
|
|
2000-05-31 05:40:53 +00:00
|
|
|
if (sc->dc_flags & DC_21143_NWAY && !sc->dc_link)
|
2000-11-25 08:00:10 +00:00
|
|
|
callout_reset(&sc->dc_stat_ch, hz/10, dc_tick, sc);
|
2000-05-31 05:40:53 +00:00
|
|
|
else
|
2000-11-25 08:00:10 +00:00
|
|
|
callout_reset(&sc->dc_stat_ch, hz, dc_tick, sc);
|
1999-12-04 17:41:31 +00:00
|
|
|
}
|
|
|
|
|
2001-02-22 19:26:55 +00:00
|
|
|
/*
|
|
|
|
* A transmit underrun has occurred. Back off the transmit threshold,
|
|
|
|
* or switch to store and forward mode if we have to.
|
|
|
|
*/
|
2002-08-23 23:49:02 +00:00
|
|
|
static void
|
2003-06-01 19:26:34 +00:00
|
|
|
dc_tx_underrun(struct dc_softc *sc)
|
2001-02-22 19:26:55 +00:00
|
|
|
{
|
2003-06-01 19:26:34 +00:00
|
|
|
u_int32_t isr;
|
|
|
|
int i;
|
2001-02-22 19:26:55 +00:00
|
|
|
|
|
|
|
if (DC_IS_DAVICOM(sc))
|
2005-08-18 19:10:07 +00:00
|
|
|
dc_init_locked(sc);
|
2001-02-22 19:26:55 +00:00
|
|
|
|
|
|
|
if (DC_IS_INTEL(sc)) {
|
|
|
|
/*
|
|
|
|
* The real 21143 requires that the transmitter be idle
|
|
|
|
* in order to change the transmit threshold or store
|
|
|
|
* and forward state.
|
|
|
|
*/
|
|
|
|
DC_CLRBIT(sc, DC_NETCFG, DC_NETCFG_TX_ON);
|
|
|
|
|
|
|
|
for (i = 0; i < DC_TIMEOUT; i++) {
|
|
|
|
isr = CSR_READ_4(sc, DC_ISR);
|
|
|
|
if (isr & DC_ISR_TX_IDLE)
|
|
|
|
break;
|
|
|
|
DELAY(10);
|
|
|
|
}
|
|
|
|
if (i == DC_TIMEOUT) {
|
2005-08-10 20:33:46 +00:00
|
|
|
if_printf(sc->dc_ifp,
|
|
|
|
"failed to force tx to idle state\n");
|
2005-08-18 19:10:07 +00:00
|
|
|
dc_init_locked(sc);
|
2001-02-22 19:26:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-08-10 20:33:46 +00:00
|
|
|
if_printf(sc->dc_ifp, "TX underrun -- ");
|
2001-02-22 19:26:55 +00:00
|
|
|
sc->dc_txthresh += DC_TXTHRESH_INC;
|
|
|
|
if (sc->dc_txthresh > DC_TXTHRESH_MAX) {
|
|
|
|
printf("using store and forward mode\n");
|
|
|
|
DC_SETBIT(sc, DC_NETCFG, DC_NETCFG_STORENFWD);
|
|
|
|
} else {
|
|
|
|
printf("increasing TX threshold\n");
|
|
|
|
DC_CLRBIT(sc, DC_NETCFG, DC_NETCFG_TX_THRESH);
|
|
|
|
DC_SETBIT(sc, DC_NETCFG, sc->dc_txthresh);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (DC_IS_INTEL(sc))
|
|
|
|
DC_SETBIT(sc, DC_NETCFG, DC_NETCFG_TX_ON);
|
|
|
|
}
|
|
|
|
|
Device Polling code for -current.
Non-SMP, i386-only, no polling in the idle loop at the moment.
To use this code you must compile a kernel with
options DEVICE_POLLING
and at runtime enable polling with
sysctl kern.polling.enable=1
The percentage of CPU reserved to userland can be set with
sysctl kern.polling.user_frac=NN (default is 50)
while the remainder is used by polling device drivers and netisr's.
These are the only two variables that you should need to touch. There
are a few more parameters in kern.polling but the default values
are adequate for all purposes. See the code in kern_poll.c for
more details on them.
Polling in the idle loop will be implemented shortly by introducing
a kernel thread which does the job. Until then, the amount of CPU
dedicated to polling will never exceed (100-user_frac).
The equivalent (actually, better) code for -stable is at
http://info.iet.unipi.it/~luigi/polling/
and also supports polling in the idle loop.
NOTE to Alpha developers:
There is really nothing in this code that is i386-specific.
If you move the 2 lines supporting the new option from
sys/conf/{files,options}.i386 to sys/conf/{files,options} I am
pretty sure that this should work on the Alpha as well, just that
I do not have a suitable test box to try it. If someone feels like
trying it, I would appreciate it.
NOTE to other developers:
sure some things could be done better, and as always I am open to
constructive criticism, which a few of you have already given and
I greatly appreciated.
However, before proposing radical architectural changes, please
take some time to possibly try out this code, or at the very least
read the comments in kern_poll.c, especially re. the reason why I
am using a soft netisr and cannot (I believe) replace it with a
simple timeout.
Quick description of files touched by this commit:
sys/conf/files.i386
new file kern/kern_poll.c
sys/conf/options.i386
new option
sys/i386/i386/trap.c
poll in trap (disabled by default)
sys/kern/kern_clock.c
initialization and hardclock hooks.
sys/kern/kern_intr.c
minor swi_net changes
sys/kern/kern_poll.c
the bulk of the code.
sys/net/if.h
new flag
sys/net/if_var.h
declaration for functions used in device drivers.
sys/net/netisr.h
NETISR_POLL
sys/dev/fxp/if_fxp.c
sys/dev/fxp/if_fxpvar.h
sys/pci/if_dc.c
sys/pci/if_dcreg.h
sys/pci/if_sis.c
sys/pci/if_sisreg.h
device driver modifications
2001-12-14 17:56:12 +00:00
|
|
|
#ifdef DEVICE_POLLING
|
|
|
|
static poll_handler_t dc_poll;
|
|
|
|
|
|
|
|
static void
|
|
|
|
dc_poll(struct ifnet *ifp, enum poll_cmd cmd, int count)
|
|
|
|
{
|
2003-06-01 19:26:34 +00:00
|
|
|
struct dc_softc *sc = ifp->if_softc;
|
Device Polling code for -current.
Non-SMP, i386-only, no polling in the idle loop at the moment.
To use this code you must compile a kernel with
options DEVICE_POLLING
and at runtime enable polling with
sysctl kern.polling.enable=1
The percentage of CPU reserved to userland can be set with
sysctl kern.polling.user_frac=NN (default is 50)
while the remainder is used by polling device drivers and netisr's.
These are the only two variables that you should need to touch. There
are a few more parameters in kern.polling but the default values
are adequate for all purposes. See the code in kern_poll.c for
more details on them.
Polling in the idle loop will be implemented shortly by introducing
a kernel thread which does the job. Until then, the amount of CPU
dedicated to polling will never exceed (100-user_frac).
The equivalent (actually, better) code for -stable is at
http://info.iet.unipi.it/~luigi/polling/
and also supports polling in the idle loop.
NOTE to Alpha developers:
There is really nothing in this code that is i386-specific.
If you move the 2 lines supporting the new option from
sys/conf/{files,options}.i386 to sys/conf/{files,options} I am
pretty sure that this should work on the Alpha as well, just that
I do not have a suitable test box to try it. If someone feels like
trying it, I would appreciate it.
NOTE to other developers:
sure some things could be done better, and as always I am open to
constructive criticism, which a few of you have already given and
I greatly appreciated.
However, before proposing radical architectural changes, please
take some time to possibly try out this code, or at the very least
read the comments in kern_poll.c, especially re. the reason why I
am using a soft netisr and cannot (I believe) replace it with a
simple timeout.
Quick description of files touched by this commit:
sys/conf/files.i386
new file kern/kern_poll.c
sys/conf/options.i386
new option
sys/i386/i386/trap.c
poll in trap (disabled by default)
sys/kern/kern_clock.c
initialization and hardclock hooks.
sys/kern/kern_intr.c
minor swi_net changes
sys/kern/kern_poll.c
the bulk of the code.
sys/net/if.h
new flag
sys/net/if_var.h
declaration for functions used in device drivers.
sys/net/netisr.h
NETISR_POLL
sys/dev/fxp/if_fxp.c
sys/dev/fxp/if_fxpvar.h
sys/pci/if_dc.c
sys/pci/if_dcreg.h
sys/pci/if_sis.c
sys/pci/if_sisreg.h
device driver modifications
2001-12-14 17:56:12 +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
|
|
|
DC_LOCK(sc);
|
|
|
|
|
|
|
|
if (!(ifp->if_drv_flags & IFF_DRV_RUNNING)) {
|
|
|
|
DC_UNLOCK(sc);
|
Device Polling code for -current.
Non-SMP, i386-only, no polling in the idle loop at the moment.
To use this code you must compile a kernel with
options DEVICE_POLLING
and at runtime enable polling with
sysctl kern.polling.enable=1
The percentage of CPU reserved to userland can be set with
sysctl kern.polling.user_frac=NN (default is 50)
while the remainder is used by polling device drivers and netisr's.
These are the only two variables that you should need to touch. There
are a few more parameters in kern.polling but the default values
are adequate for all purposes. See the code in kern_poll.c for
more details on them.
Polling in the idle loop will be implemented shortly by introducing
a kernel thread which does the job. Until then, the amount of CPU
dedicated to polling will never exceed (100-user_frac).
The equivalent (actually, better) code for -stable is at
http://info.iet.unipi.it/~luigi/polling/
and also supports polling in the idle loop.
NOTE to Alpha developers:
There is really nothing in this code that is i386-specific.
If you move the 2 lines supporting the new option from
sys/conf/{files,options}.i386 to sys/conf/{files,options} I am
pretty sure that this should work on the Alpha as well, just that
I do not have a suitable test box to try it. If someone feels like
trying it, I would appreciate it.
NOTE to other developers:
sure some things could be done better, and as always I am open to
constructive criticism, which a few of you have already given and
I greatly appreciated.
However, before proposing radical architectural changes, please
take some time to possibly try out this code, or at the very least
read the comments in kern_poll.c, especially re. the reason why I
am using a soft netisr and cannot (I believe) replace it with a
simple timeout.
Quick description of files touched by this commit:
sys/conf/files.i386
new file kern/kern_poll.c
sys/conf/options.i386
new option
sys/i386/i386/trap.c
poll in trap (disabled by default)
sys/kern/kern_clock.c
initialization and hardclock hooks.
sys/kern/kern_intr.c
minor swi_net changes
sys/kern/kern_poll.c
the bulk of the code.
sys/net/if.h
new flag
sys/net/if_var.h
declaration for functions used in device drivers.
sys/net/netisr.h
NETISR_POLL
sys/dev/fxp/if_fxp.c
sys/dev/fxp/if_fxpvar.h
sys/pci/if_dc.c
sys/pci/if_dcreg.h
sys/pci/if_sis.c
sys/pci/if_sisreg.h
device driver modifications
2001-12-14 17:56:12 +00:00
|
|
|
return;
|
|
|
|
}
|
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
|
|
|
|
Device Polling code for -current.
Non-SMP, i386-only, no polling in the idle loop at the moment.
To use this code you must compile a kernel with
options DEVICE_POLLING
and at runtime enable polling with
sysctl kern.polling.enable=1
The percentage of CPU reserved to userland can be set with
sysctl kern.polling.user_frac=NN (default is 50)
while the remainder is used by polling device drivers and netisr's.
These are the only two variables that you should need to touch. There
are a few more parameters in kern.polling but the default values
are adequate for all purposes. See the code in kern_poll.c for
more details on them.
Polling in the idle loop will be implemented shortly by introducing
a kernel thread which does the job. Until then, the amount of CPU
dedicated to polling will never exceed (100-user_frac).
The equivalent (actually, better) code for -stable is at
http://info.iet.unipi.it/~luigi/polling/
and also supports polling in the idle loop.
NOTE to Alpha developers:
There is really nothing in this code that is i386-specific.
If you move the 2 lines supporting the new option from
sys/conf/{files,options}.i386 to sys/conf/{files,options} I am
pretty sure that this should work on the Alpha as well, just that
I do not have a suitable test box to try it. If someone feels like
trying it, I would appreciate it.
NOTE to other developers:
sure some things could be done better, and as always I am open to
constructive criticism, which a few of you have already given and
I greatly appreciated.
However, before proposing radical architectural changes, please
take some time to possibly try out this code, or at the very least
read the comments in kern_poll.c, especially re. the reason why I
am using a soft netisr and cannot (I believe) replace it with a
simple timeout.
Quick description of files touched by this commit:
sys/conf/files.i386
new file kern/kern_poll.c
sys/conf/options.i386
new option
sys/i386/i386/trap.c
poll in trap (disabled by default)
sys/kern/kern_clock.c
initialization and hardclock hooks.
sys/kern/kern_intr.c
minor swi_net changes
sys/kern/kern_poll.c
the bulk of the code.
sys/net/if.h
new flag
sys/net/if_var.h
declaration for functions used in device drivers.
sys/net/netisr.h
NETISR_POLL
sys/dev/fxp/if_fxp.c
sys/dev/fxp/if_fxpvar.h
sys/pci/if_dc.c
sys/pci/if_dcreg.h
sys/pci/if_sis.c
sys/pci/if_sisreg.h
device driver modifications
2001-12-14 17:56:12 +00:00
|
|
|
sc->rxcycles = count;
|
|
|
|
dc_rxeof(sc);
|
|
|
|
dc_txeof(sc);
|
2005-08-09 10:20:02 +00:00
|
|
|
if (!IFQ_IS_EMPTY(&ifp->if_snd) &&
|
|
|
|
!(ifp->if_drv_flags & IFF_DRV_OACTIVE))
|
2005-08-18 19:10:07 +00:00
|
|
|
dc_start_locked(ifp);
|
Device Polling code for -current.
Non-SMP, i386-only, no polling in the idle loop at the moment.
To use this code you must compile a kernel with
options DEVICE_POLLING
and at runtime enable polling with
sysctl kern.polling.enable=1
The percentage of CPU reserved to userland can be set with
sysctl kern.polling.user_frac=NN (default is 50)
while the remainder is used by polling device drivers and netisr's.
These are the only two variables that you should need to touch. There
are a few more parameters in kern.polling but the default values
are adequate for all purposes. See the code in kern_poll.c for
more details on them.
Polling in the idle loop will be implemented shortly by introducing
a kernel thread which does the job. Until then, the amount of CPU
dedicated to polling will never exceed (100-user_frac).
The equivalent (actually, better) code for -stable is at
http://info.iet.unipi.it/~luigi/polling/
and also supports polling in the idle loop.
NOTE to Alpha developers:
There is really nothing in this code that is i386-specific.
If you move the 2 lines supporting the new option from
sys/conf/{files,options}.i386 to sys/conf/{files,options} I am
pretty sure that this should work on the Alpha as well, just that
I do not have a suitable test box to try it. If someone feels like
trying it, I would appreciate it.
NOTE to other developers:
sure some things could be done better, and as always I am open to
constructive criticism, which a few of you have already given and
I greatly appreciated.
However, before proposing radical architectural changes, please
take some time to possibly try out this code, or at the very least
read the comments in kern_poll.c, especially re. the reason why I
am using a soft netisr and cannot (I believe) replace it with a
simple timeout.
Quick description of files touched by this commit:
sys/conf/files.i386
new file kern/kern_poll.c
sys/conf/options.i386
new option
sys/i386/i386/trap.c
poll in trap (disabled by default)
sys/kern/kern_clock.c
initialization and hardclock hooks.
sys/kern/kern_intr.c
minor swi_net changes
sys/kern/kern_poll.c
the bulk of the code.
sys/net/if.h
new flag
sys/net/if_var.h
declaration for functions used in device drivers.
sys/net/netisr.h
NETISR_POLL
sys/dev/fxp/if_fxp.c
sys/dev/fxp/if_fxpvar.h
sys/pci/if_dc.c
sys/pci/if_dcreg.h
sys/pci/if_sis.c
sys/pci/if_sisreg.h
device driver modifications
2001-12-14 17:56:12 +00:00
|
|
|
|
|
|
|
if (cmd == POLL_AND_CHECK_STATUS) { /* also check status register */
|
|
|
|
u_int32_t status;
|
|
|
|
|
|
|
|
status = CSR_READ_4(sc, DC_ISR);
|
2003-06-01 19:26:34 +00:00
|
|
|
status &= (DC_ISR_RX_WATDOGTIMEO | DC_ISR_RX_NOBUF |
|
|
|
|
DC_ISR_TX_NOBUF | DC_ISR_TX_IDLE | DC_ISR_TX_UNDERRUN |
|
Device Polling code for -current.
Non-SMP, i386-only, no polling in the idle loop at the moment.
To use this code you must compile a kernel with
options DEVICE_POLLING
and at runtime enable polling with
sysctl kern.polling.enable=1
The percentage of CPU reserved to userland can be set with
sysctl kern.polling.user_frac=NN (default is 50)
while the remainder is used by polling device drivers and netisr's.
These are the only two variables that you should need to touch. There
are a few more parameters in kern.polling but the default values
are adequate for all purposes. See the code in kern_poll.c for
more details on them.
Polling in the idle loop will be implemented shortly by introducing
a kernel thread which does the job. Until then, the amount of CPU
dedicated to polling will never exceed (100-user_frac).
The equivalent (actually, better) code for -stable is at
http://info.iet.unipi.it/~luigi/polling/
and also supports polling in the idle loop.
NOTE to Alpha developers:
There is really nothing in this code that is i386-specific.
If you move the 2 lines supporting the new option from
sys/conf/{files,options}.i386 to sys/conf/{files,options} I am
pretty sure that this should work on the Alpha as well, just that
I do not have a suitable test box to try it. If someone feels like
trying it, I would appreciate it.
NOTE to other developers:
sure some things could be done better, and as always I am open to
constructive criticism, which a few of you have already given and
I greatly appreciated.
However, before proposing radical architectural changes, please
take some time to possibly try out this code, or at the very least
read the comments in kern_poll.c, especially re. the reason why I
am using a soft netisr and cannot (I believe) replace it with a
simple timeout.
Quick description of files touched by this commit:
sys/conf/files.i386
new file kern/kern_poll.c
sys/conf/options.i386
new option
sys/i386/i386/trap.c
poll in trap (disabled by default)
sys/kern/kern_clock.c
initialization and hardclock hooks.
sys/kern/kern_intr.c
minor swi_net changes
sys/kern/kern_poll.c
the bulk of the code.
sys/net/if.h
new flag
sys/net/if_var.h
declaration for functions used in device drivers.
sys/net/netisr.h
NETISR_POLL
sys/dev/fxp/if_fxp.c
sys/dev/fxp/if_fxpvar.h
sys/pci/if_dc.c
sys/pci/if_dcreg.h
sys/pci/if_sis.c
sys/pci/if_sisreg.h
device driver modifications
2001-12-14 17:56:12 +00:00
|
|
|
DC_ISR_BUS_ERR);
|
2003-11-14 19:00:32 +00:00
|
|
|
if (!status) {
|
|
|
|
DC_UNLOCK(sc);
|
2001-12-15 02:51:21 +00:00
|
|
|
return;
|
2003-11-14 19:00:32 +00:00
|
|
|
}
|
Device Polling code for -current.
Non-SMP, i386-only, no polling in the idle loop at the moment.
To use this code you must compile a kernel with
options DEVICE_POLLING
and at runtime enable polling with
sysctl kern.polling.enable=1
The percentage of CPU reserved to userland can be set with
sysctl kern.polling.user_frac=NN (default is 50)
while the remainder is used by polling device drivers and netisr's.
These are the only two variables that you should need to touch. There
are a few more parameters in kern.polling but the default values
are adequate for all purposes. See the code in kern_poll.c for
more details on them.
Polling in the idle loop will be implemented shortly by introducing
a kernel thread which does the job. Until then, the amount of CPU
dedicated to polling will never exceed (100-user_frac).
The equivalent (actually, better) code for -stable is at
http://info.iet.unipi.it/~luigi/polling/
and also supports polling in the idle loop.
NOTE to Alpha developers:
There is really nothing in this code that is i386-specific.
If you move the 2 lines supporting the new option from
sys/conf/{files,options}.i386 to sys/conf/{files,options} I am
pretty sure that this should work on the Alpha as well, just that
I do not have a suitable test box to try it. If someone feels like
trying it, I would appreciate it.
NOTE to other developers:
sure some things could be done better, and as always I am open to
constructive criticism, which a few of you have already given and
I greatly appreciated.
However, before proposing radical architectural changes, please
take some time to possibly try out this code, or at the very least
read the comments in kern_poll.c, especially re. the reason why I
am using a soft netisr and cannot (I believe) replace it with a
simple timeout.
Quick description of files touched by this commit:
sys/conf/files.i386
new file kern/kern_poll.c
sys/conf/options.i386
new option
sys/i386/i386/trap.c
poll in trap (disabled by default)
sys/kern/kern_clock.c
initialization and hardclock hooks.
sys/kern/kern_intr.c
minor swi_net changes
sys/kern/kern_poll.c
the bulk of the code.
sys/net/if.h
new flag
sys/net/if_var.h
declaration for functions used in device drivers.
sys/net/netisr.h
NETISR_POLL
sys/dev/fxp/if_fxp.c
sys/dev/fxp/if_fxpvar.h
sys/pci/if_dc.c
sys/pci/if_dcreg.h
sys/pci/if_sis.c
sys/pci/if_sisreg.h
device driver modifications
2001-12-14 17:56:12 +00:00
|
|
|
/* ack what we have */
|
|
|
|
CSR_WRITE_4(sc, DC_ISR, status);
|
|
|
|
|
2003-06-01 19:26:34 +00:00
|
|
|
if (status & (DC_ISR_RX_WATDOGTIMEO | DC_ISR_RX_NOBUF)) {
|
Device Polling code for -current.
Non-SMP, i386-only, no polling in the idle loop at the moment.
To use this code you must compile a kernel with
options DEVICE_POLLING
and at runtime enable polling with
sysctl kern.polling.enable=1
The percentage of CPU reserved to userland can be set with
sysctl kern.polling.user_frac=NN (default is 50)
while the remainder is used by polling device drivers and netisr's.
These are the only two variables that you should need to touch. There
are a few more parameters in kern.polling but the default values
are adequate for all purposes. See the code in kern_poll.c for
more details on them.
Polling in the idle loop will be implemented shortly by introducing
a kernel thread which does the job. Until then, the amount of CPU
dedicated to polling will never exceed (100-user_frac).
The equivalent (actually, better) code for -stable is at
http://info.iet.unipi.it/~luigi/polling/
and also supports polling in the idle loop.
NOTE to Alpha developers:
There is really nothing in this code that is i386-specific.
If you move the 2 lines supporting the new option from
sys/conf/{files,options}.i386 to sys/conf/{files,options} I am
pretty sure that this should work on the Alpha as well, just that
I do not have a suitable test box to try it. If someone feels like
trying it, I would appreciate it.
NOTE to other developers:
sure some things could be done better, and as always I am open to
constructive criticism, which a few of you have already given and
I greatly appreciated.
However, before proposing radical architectural changes, please
take some time to possibly try out this code, or at the very least
read the comments in kern_poll.c, especially re. the reason why I
am using a soft netisr and cannot (I believe) replace it with a
simple timeout.
Quick description of files touched by this commit:
sys/conf/files.i386
new file kern/kern_poll.c
sys/conf/options.i386
new option
sys/i386/i386/trap.c
poll in trap (disabled by default)
sys/kern/kern_clock.c
initialization and hardclock hooks.
sys/kern/kern_intr.c
minor swi_net changes
sys/kern/kern_poll.c
the bulk of the code.
sys/net/if.h
new flag
sys/net/if_var.h
declaration for functions used in device drivers.
sys/net/netisr.h
NETISR_POLL
sys/dev/fxp/if_fxp.c
sys/dev/fxp/if_fxpvar.h
sys/pci/if_dc.c
sys/pci/if_dcreg.h
sys/pci/if_sis.c
sys/pci/if_sisreg.h
device driver modifications
2001-12-14 17:56:12 +00:00
|
|
|
u_int32_t r = CSR_READ_4(sc, DC_FRAMESDISCARDED);
|
|
|
|
ifp->if_ierrors += (r & 0xffff) + ((r >> 17) & 0x7ff);
|
|
|
|
|
|
|
|
if (dc_rx_resync(sc))
|
|
|
|
dc_rxeof(sc);
|
|
|
|
}
|
|
|
|
/* restart transmit unit if necessary */
|
|
|
|
if (status & DC_ISR_TX_IDLE && sc->dc_cdata.dc_tx_cnt)
|
|
|
|
CSR_WRITE_4(sc, DC_TXSTART, 0xFFFFFFFF);
|
|
|
|
|
|
|
|
if (status & DC_ISR_TX_UNDERRUN)
|
|
|
|
dc_tx_underrun(sc);
|
|
|
|
|
|
|
|
if (status & DC_ISR_BUS_ERR) {
|
2005-08-10 20:33:46 +00:00
|
|
|
if_printf(ifp, "dc_poll: bus error\n");
|
Device Polling code for -current.
Non-SMP, i386-only, no polling in the idle loop at the moment.
To use this code you must compile a kernel with
options DEVICE_POLLING
and at runtime enable polling with
sysctl kern.polling.enable=1
The percentage of CPU reserved to userland can be set with
sysctl kern.polling.user_frac=NN (default is 50)
while the remainder is used by polling device drivers and netisr's.
These are the only two variables that you should need to touch. There
are a few more parameters in kern.polling but the default values
are adequate for all purposes. See the code in kern_poll.c for
more details on them.
Polling in the idle loop will be implemented shortly by introducing
a kernel thread which does the job. Until then, the amount of CPU
dedicated to polling will never exceed (100-user_frac).
The equivalent (actually, better) code for -stable is at
http://info.iet.unipi.it/~luigi/polling/
and also supports polling in the idle loop.
NOTE to Alpha developers:
There is really nothing in this code that is i386-specific.
If you move the 2 lines supporting the new option from
sys/conf/{files,options}.i386 to sys/conf/{files,options} I am
pretty sure that this should work on the Alpha as well, just that
I do not have a suitable test box to try it. If someone feels like
trying it, I would appreciate it.
NOTE to other developers:
sure some things could be done better, and as always I am open to
constructive criticism, which a few of you have already given and
I greatly appreciated.
However, before proposing radical architectural changes, please
take some time to possibly try out this code, or at the very least
read the comments in kern_poll.c, especially re. the reason why I
am using a soft netisr and cannot (I believe) replace it with a
simple timeout.
Quick description of files touched by this commit:
sys/conf/files.i386
new file kern/kern_poll.c
sys/conf/options.i386
new option
sys/i386/i386/trap.c
poll in trap (disabled by default)
sys/kern/kern_clock.c
initialization and hardclock hooks.
sys/kern/kern_intr.c
minor swi_net changes
sys/kern/kern_poll.c
the bulk of the code.
sys/net/if.h
new flag
sys/net/if_var.h
declaration for functions used in device drivers.
sys/net/netisr.h
NETISR_POLL
sys/dev/fxp/if_fxp.c
sys/dev/fxp/if_fxpvar.h
sys/pci/if_dc.c
sys/pci/if_dcreg.h
sys/pci/if_sis.c
sys/pci/if_sisreg.h
device driver modifications
2001-12-14 17:56:12 +00:00
|
|
|
dc_reset(sc);
|
2005-08-18 19:10:07 +00:00
|
|
|
dc_init_locked(sc);
|
Device Polling code for -current.
Non-SMP, i386-only, no polling in the idle loop at the moment.
To use this code you must compile a kernel with
options DEVICE_POLLING
and at runtime enable polling with
sysctl kern.polling.enable=1
The percentage of CPU reserved to userland can be set with
sysctl kern.polling.user_frac=NN (default is 50)
while the remainder is used by polling device drivers and netisr's.
These are the only two variables that you should need to touch. There
are a few more parameters in kern.polling but the default values
are adequate for all purposes. See the code in kern_poll.c for
more details on them.
Polling in the idle loop will be implemented shortly by introducing
a kernel thread which does the job. Until then, the amount of CPU
dedicated to polling will never exceed (100-user_frac).
The equivalent (actually, better) code for -stable is at
http://info.iet.unipi.it/~luigi/polling/
and also supports polling in the idle loop.
NOTE to Alpha developers:
There is really nothing in this code that is i386-specific.
If you move the 2 lines supporting the new option from
sys/conf/{files,options}.i386 to sys/conf/{files,options} I am
pretty sure that this should work on the Alpha as well, just that
I do not have a suitable test box to try it. If someone feels like
trying it, I would appreciate it.
NOTE to other developers:
sure some things could be done better, and as always I am open to
constructive criticism, which a few of you have already given and
I greatly appreciated.
However, before proposing radical architectural changes, please
take some time to possibly try out this code, or at the very least
read the comments in kern_poll.c, especially re. the reason why I
am using a soft netisr and cannot (I believe) replace it with a
simple timeout.
Quick description of files touched by this commit:
sys/conf/files.i386
new file kern/kern_poll.c
sys/conf/options.i386
new option
sys/i386/i386/trap.c
poll in trap (disabled by default)
sys/kern/kern_clock.c
initialization and hardclock hooks.
sys/kern/kern_intr.c
minor swi_net changes
sys/kern/kern_poll.c
the bulk of the code.
sys/net/if.h
new flag
sys/net/if_var.h
declaration for functions used in device drivers.
sys/net/netisr.h
NETISR_POLL
sys/dev/fxp/if_fxp.c
sys/dev/fxp/if_fxpvar.h
sys/pci/if_dc.c
sys/pci/if_dcreg.h
sys/pci/if_sis.c
sys/pci/if_sisreg.h
device driver modifications
2001-12-14 17:56:12 +00:00
|
|
|
}
|
|
|
|
}
|
2003-11-14 19:00:32 +00:00
|
|
|
DC_UNLOCK(sc);
|
Device Polling code for -current.
Non-SMP, i386-only, no polling in the idle loop at the moment.
To use this code you must compile a kernel with
options DEVICE_POLLING
and at runtime enable polling with
sysctl kern.polling.enable=1
The percentage of CPU reserved to userland can be set with
sysctl kern.polling.user_frac=NN (default is 50)
while the remainder is used by polling device drivers and netisr's.
These are the only two variables that you should need to touch. There
are a few more parameters in kern.polling but the default values
are adequate for all purposes. See the code in kern_poll.c for
more details on them.
Polling in the idle loop will be implemented shortly by introducing
a kernel thread which does the job. Until then, the amount of CPU
dedicated to polling will never exceed (100-user_frac).
The equivalent (actually, better) code for -stable is at
http://info.iet.unipi.it/~luigi/polling/
and also supports polling in the idle loop.
NOTE to Alpha developers:
There is really nothing in this code that is i386-specific.
If you move the 2 lines supporting the new option from
sys/conf/{files,options}.i386 to sys/conf/{files,options} I am
pretty sure that this should work on the Alpha as well, just that
I do not have a suitable test box to try it. If someone feels like
trying it, I would appreciate it.
NOTE to other developers:
sure some things could be done better, and as always I am open to
constructive criticism, which a few of you have already given and
I greatly appreciated.
However, before proposing radical architectural changes, please
take some time to possibly try out this code, or at the very least
read the comments in kern_poll.c, especially re. the reason why I
am using a soft netisr and cannot (I believe) replace it with a
simple timeout.
Quick description of files touched by this commit:
sys/conf/files.i386
new file kern/kern_poll.c
sys/conf/options.i386
new option
sys/i386/i386/trap.c
poll in trap (disabled by default)
sys/kern/kern_clock.c
initialization and hardclock hooks.
sys/kern/kern_intr.c
minor swi_net changes
sys/kern/kern_poll.c
the bulk of the code.
sys/net/if.h
new flag
sys/net/if_var.h
declaration for functions used in device drivers.
sys/net/netisr.h
NETISR_POLL
sys/dev/fxp/if_fxp.c
sys/dev/fxp/if_fxpvar.h
sys/pci/if_dc.c
sys/pci/if_dcreg.h
sys/pci/if_sis.c
sys/pci/if_sisreg.h
device driver modifications
2001-12-14 17:56:12 +00:00
|
|
|
}
|
|
|
|
#endif /* DEVICE_POLLING */
|
|
|
|
|
2002-08-23 23:49:02 +00:00
|
|
|
static void
|
2003-06-01 19:26:34 +00:00
|
|
|
dc_intr(void *arg)
|
1999-12-04 17:41:31 +00:00
|
|
|
{
|
2003-06-01 19:26:34 +00:00
|
|
|
struct dc_softc *sc;
|
|
|
|
struct ifnet *ifp;
|
|
|
|
u_int32_t status;
|
1999-12-04 17:41:31 +00:00
|
|
|
|
|
|
|
sc = arg;
|
|
|
|
|
2003-06-01 19:26:34 +00:00
|
|
|
if (sc->suspended)
|
2002-05-06 10:55:42 +00:00
|
|
|
return;
|
|
|
|
|
2001-12-15 02:51:21 +00:00
|
|
|
if ((CSR_READ_4(sc, DC_ISR) & DC_INTRS) == 0)
|
|
|
|
return;
|
2001-02-20 04:43:59 +00:00
|
|
|
|
|
|
|
DC_LOCK(sc);
|
2005-06-10 16:49:24 +00:00
|
|
|
ifp = sc->dc_ifp;
|
Device Polling code for -current.
Non-SMP, i386-only, no polling in the idle loop at the moment.
To use this code you must compile a kernel with
options DEVICE_POLLING
and at runtime enable polling with
sysctl kern.polling.enable=1
The percentage of CPU reserved to userland can be set with
sysctl kern.polling.user_frac=NN (default is 50)
while the remainder is used by polling device drivers and netisr's.
These are the only two variables that you should need to touch. There
are a few more parameters in kern.polling but the default values
are adequate for all purposes. See the code in kern_poll.c for
more details on them.
Polling in the idle loop will be implemented shortly by introducing
a kernel thread which does the job. Until then, the amount of CPU
dedicated to polling will never exceed (100-user_frac).
The equivalent (actually, better) code for -stable is at
http://info.iet.unipi.it/~luigi/polling/
and also supports polling in the idle loop.
NOTE to Alpha developers:
There is really nothing in this code that is i386-specific.
If you move the 2 lines supporting the new option from
sys/conf/{files,options}.i386 to sys/conf/{files,options} I am
pretty sure that this should work on the Alpha as well, just that
I do not have a suitable test box to try it. If someone feels like
trying it, I would appreciate it.
NOTE to other developers:
sure some things could be done better, and as always I am open to
constructive criticism, which a few of you have already given and
I greatly appreciated.
However, before proposing radical architectural changes, please
take some time to possibly try out this code, or at the very least
read the comments in kern_poll.c, especially re. the reason why I
am using a soft netisr and cannot (I believe) replace it with a
simple timeout.
Quick description of files touched by this commit:
sys/conf/files.i386
new file kern/kern_poll.c
sys/conf/options.i386
new option
sys/i386/i386/trap.c
poll in trap (disabled by default)
sys/kern/kern_clock.c
initialization and hardclock hooks.
sys/kern/kern_intr.c
minor swi_net changes
sys/kern/kern_poll.c
the bulk of the code.
sys/net/if.h
new flag
sys/net/if_var.h
declaration for functions used in device drivers.
sys/net/netisr.h
NETISR_POLL
sys/dev/fxp/if_fxp.c
sys/dev/fxp/if_fxpvar.h
sys/pci/if_dc.c
sys/pci/if_dcreg.h
sys/pci/if_sis.c
sys/pci/if_sisreg.h
device driver modifications
2001-12-14 17:56:12 +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) {
|
|
|
|
DC_UNLOCK(sc);
|
|
|
|
return;
|
Device Polling code for -current.
Non-SMP, i386-only, no polling in the idle loop at the moment.
To use this code you must compile a kernel with
options DEVICE_POLLING
and at runtime enable polling with
sysctl kern.polling.enable=1
The percentage of CPU reserved to userland can be set with
sysctl kern.polling.user_frac=NN (default is 50)
while the remainder is used by polling device drivers and netisr's.
These are the only two variables that you should need to touch. There
are a few more parameters in kern.polling but the default values
are adequate for all purposes. See the code in kern_poll.c for
more details on them.
Polling in the idle loop will be implemented shortly by introducing
a kernel thread which does the job. Until then, the amount of CPU
dedicated to polling will never exceed (100-user_frac).
The equivalent (actually, better) code for -stable is at
http://info.iet.unipi.it/~luigi/polling/
and also supports polling in the idle loop.
NOTE to Alpha developers:
There is really nothing in this code that is i386-specific.
If you move the 2 lines supporting the new option from
sys/conf/{files,options}.i386 to sys/conf/{files,options} I am
pretty sure that this should work on the Alpha as well, just that
I do not have a suitable test box to try it. If someone feels like
trying it, I would appreciate it.
NOTE to other developers:
sure some things could be done better, and as always I am open to
constructive criticism, which a few of you have already given and
I greatly appreciated.
However, before proposing radical architectural changes, please
take some time to possibly try out this code, or at the very least
read the comments in kern_poll.c, especially re. the reason why I
am using a soft netisr and cannot (I believe) replace it with a
simple timeout.
Quick description of files touched by this commit:
sys/conf/files.i386
new file kern/kern_poll.c
sys/conf/options.i386
new option
sys/i386/i386/trap.c
poll in trap (disabled by default)
sys/kern/kern_clock.c
initialization and hardclock hooks.
sys/kern/kern_intr.c
minor swi_net changes
sys/kern/kern_poll.c
the bulk of the code.
sys/net/if.h
new flag
sys/net/if_var.h
declaration for functions used in device drivers.
sys/net/netisr.h
NETISR_POLL
sys/dev/fxp/if_fxp.c
sys/dev/fxp/if_fxpvar.h
sys/pci/if_dc.c
sys/pci/if_dcreg.h
sys/pci/if_sis.c
sys/pci/if_sisreg.h
device driver modifications
2001-12-14 17:56:12 +00:00
|
|
|
}
|
2003-06-01 19:26:34 +00:00
|
|
|
#endif
|
2001-02-18 07:21:28 +00:00
|
|
|
|
|
|
|
/* Suppress unwanted interrupts */
|
1999-12-04 17:41:31 +00:00
|
|
|
if (!(ifp->if_flags & IFF_UP)) {
|
|
|
|
if (CSR_READ_4(sc, DC_ISR) & DC_INTRS)
|
|
|
|
dc_stop(sc);
|
2000-10-13 17:54:19 +00:00
|
|
|
DC_UNLOCK(sc);
|
1999-12-04 17:41:31 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Disable interrupts. */
|
|
|
|
CSR_WRITE_4(sc, DC_IMR, 0x00000000);
|
|
|
|
|
2003-06-01 19:26:34 +00:00
|
|
|
while (((status = CSR_READ_4(sc, DC_ISR)) & DC_INTRS)
|
2000-10-19 08:34:32 +00:00
|
|
|
&& status != 0xFFFFFFFF) {
|
1999-12-04 17:41:31 +00:00
|
|
|
|
|
|
|
CSR_WRITE_4(sc, DC_ISR, status);
|
|
|
|
|
It appears that under certain circumstances that I still can't quite pin
down, the dc driver and receiver can fall out of sync with one another,
resulting in a condition where the chip continues to receive packets
but the driver never notices. Normally, the receive handler checks each
descriptor starting from the current producer index to see if the chip
has relinquished ownership, indicating that a packet has been received.
The driver hands the packet off to ether_input() and then prepares the
descriptor to receive another frame before moving on to the next
descriptor in the ring. But sometimes, the chip appears to skip a
descriptor. This leaves the driver testing the status word in a descriptor
that never gets updated. The driver still gets "RX done" interrupts but
never advances further into the RX ring, until the ring fills up and the
chip interrupts again to signal an error condition. Sometimes, the
driver will remain in this desynchronized state, resulting in spotty
performance until the interface is reset.
Fortunately, it's fairly simple to detect this condition: if we call
the rxeof routine but the number of received packets doesn't increase,
we suspect that there could be a problem. In this case, we call a new
routine called dc_rx_resync(), which scans ahead in the RX ring to see
if there's a frame waiting for us somewhere beyond that the driver thinks
is the current producer index. If it finds one, it bumps up the index
and calls the rxeof handler again to snarf up the packet and bring the
driver back in sync with the chip. (It may actually do this several times
in the event that there's more than one "hole" in the ring.)
So far the only card supported by if_dc which has exhibited this problem
is a LinkSys LNE100TX v2.0 (82c115 PNIC II), and it only seems to happen
on one particular system, however the fix is general enough and has low
enough overhead that we may as well apply it for all supported chipsets.
I also implemented the same fix for the 3Com xl driver, which is apparently
vulnerable to the same problem.
Problem originally noted and patch tested by: Matt Dillon
2000-01-03 15:28:47 +00:00
|
|
|
if (status & DC_ISR_RX_OK) {
|
|
|
|
int curpkts;
|
|
|
|
curpkts = ifp->if_ipackets;
|
1999-12-04 17:41:31 +00:00
|
|
|
dc_rxeof(sc);
|
It appears that under certain circumstances that I still can't quite pin
down, the dc driver and receiver can fall out of sync with one another,
resulting in a condition where the chip continues to receive packets
but the driver never notices. Normally, the receive handler checks each
descriptor starting from the current producer index to see if the chip
has relinquished ownership, indicating that a packet has been received.
The driver hands the packet off to ether_input() and then prepares the
descriptor to receive another frame before moving on to the next
descriptor in the ring. But sometimes, the chip appears to skip a
descriptor. This leaves the driver testing the status word in a descriptor
that never gets updated. The driver still gets "RX done" interrupts but
never advances further into the RX ring, until the ring fills up and the
chip interrupts again to signal an error condition. Sometimes, the
driver will remain in this desynchronized state, resulting in spotty
performance until the interface is reset.
Fortunately, it's fairly simple to detect this condition: if we call
the rxeof routine but the number of received packets doesn't increase,
we suspect that there could be a problem. In this case, we call a new
routine called dc_rx_resync(), which scans ahead in the RX ring to see
if there's a frame waiting for us somewhere beyond that the driver thinks
is the current producer index. If it finds one, it bumps up the index
and calls the rxeof handler again to snarf up the packet and bring the
driver back in sync with the chip. (It may actually do this several times
in the event that there's more than one "hole" in the ring.)
So far the only card supported by if_dc which has exhibited this problem
is a LinkSys LNE100TX v2.0 (82c115 PNIC II), and it only seems to happen
on one particular system, however the fix is general enough and has low
enough overhead that we may as well apply it for all supported chipsets.
I also implemented the same fix for the 3Com xl driver, which is apparently
vulnerable to the same problem.
Problem originally noted and patch tested by: Matt Dillon
2000-01-03 15:28:47 +00:00
|
|
|
if (curpkts == ifp->if_ipackets) {
|
2003-06-01 19:26:34 +00:00
|
|
|
while (dc_rx_resync(sc))
|
It appears that under certain circumstances that I still can't quite pin
down, the dc driver and receiver can fall out of sync with one another,
resulting in a condition where the chip continues to receive packets
but the driver never notices. Normally, the receive handler checks each
descriptor starting from the current producer index to see if the chip
has relinquished ownership, indicating that a packet has been received.
The driver hands the packet off to ether_input() and then prepares the
descriptor to receive another frame before moving on to the next
descriptor in the ring. But sometimes, the chip appears to skip a
descriptor. This leaves the driver testing the status word in a descriptor
that never gets updated. The driver still gets "RX done" interrupts but
never advances further into the RX ring, until the ring fills up and the
chip interrupts again to signal an error condition. Sometimes, the
driver will remain in this desynchronized state, resulting in spotty
performance until the interface is reset.
Fortunately, it's fairly simple to detect this condition: if we call
the rxeof routine but the number of received packets doesn't increase,
we suspect that there could be a problem. In this case, we call a new
routine called dc_rx_resync(), which scans ahead in the RX ring to see
if there's a frame waiting for us somewhere beyond that the driver thinks
is the current producer index. If it finds one, it bumps up the index
and calls the rxeof handler again to snarf up the packet and bring the
driver back in sync with the chip. (It may actually do this several times
in the event that there's more than one "hole" in the ring.)
So far the only card supported by if_dc which has exhibited this problem
is a LinkSys LNE100TX v2.0 (82c115 PNIC II), and it only seems to happen
on one particular system, however the fix is general enough and has low
enough overhead that we may as well apply it for all supported chipsets.
I also implemented the same fix for the 3Com xl driver, which is apparently
vulnerable to the same problem.
Problem originally noted and patch tested by: Matt Dillon
2000-01-03 15:28:47 +00:00
|
|
|
dc_rxeof(sc);
|
|
|
|
}
|
|
|
|
}
|
1999-12-04 17:41:31 +00:00
|
|
|
|
2003-06-01 19:26:34 +00:00
|
|
|
if (status & (DC_ISR_TX_OK | DC_ISR_TX_NOBUF))
|
1999-12-04 17:41:31 +00:00
|
|
|
dc_txeof(sc);
|
|
|
|
|
|
|
|
if (status & DC_ISR_TX_IDLE) {
|
|
|
|
dc_txeof(sc);
|
|
|
|
if (sc->dc_cdata.dc_tx_cnt) {
|
|
|
|
DC_SETBIT(sc, DC_NETCFG, DC_NETCFG_TX_ON);
|
|
|
|
CSR_WRITE_4(sc, DC_TXSTART, 0xFFFFFFFF);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-02-22 19:26:55 +00:00
|
|
|
if (status & DC_ISR_TX_UNDERRUN)
|
|
|
|
dc_tx_underrun(sc);
|
1999-12-04 17:41:31 +00:00
|
|
|
|
|
|
|
if ((status & DC_ISR_RX_WATDOGTIMEO)
|
It appears that under certain circumstances that I still can't quite pin
down, the dc driver and receiver can fall out of sync with one another,
resulting in a condition where the chip continues to receive packets
but the driver never notices. Normally, the receive handler checks each
descriptor starting from the current producer index to see if the chip
has relinquished ownership, indicating that a packet has been received.
The driver hands the packet off to ether_input() and then prepares the
descriptor to receive another frame before moving on to the next
descriptor in the ring. But sometimes, the chip appears to skip a
descriptor. This leaves the driver testing the status word in a descriptor
that never gets updated. The driver still gets "RX done" interrupts but
never advances further into the RX ring, until the ring fills up and the
chip interrupts again to signal an error condition. Sometimes, the
driver will remain in this desynchronized state, resulting in spotty
performance until the interface is reset.
Fortunately, it's fairly simple to detect this condition: if we call
the rxeof routine but the number of received packets doesn't increase,
we suspect that there could be a problem. In this case, we call a new
routine called dc_rx_resync(), which scans ahead in the RX ring to see
if there's a frame waiting for us somewhere beyond that the driver thinks
is the current producer index. If it finds one, it bumps up the index
and calls the rxeof handler again to snarf up the packet and bring the
driver back in sync with the chip. (It may actually do this several times
in the event that there's more than one "hole" in the ring.)
So far the only card supported by if_dc which has exhibited this problem
is a LinkSys LNE100TX v2.0 (82c115 PNIC II), and it only seems to happen
on one particular system, however the fix is general enough and has low
enough overhead that we may as well apply it for all supported chipsets.
I also implemented the same fix for the 3Com xl driver, which is apparently
vulnerable to the same problem.
Problem originally noted and patch tested by: Matt Dillon
2000-01-03 15:28:47 +00:00
|
|
|
|| (status & DC_ISR_RX_NOBUF)) {
|
|
|
|
int curpkts;
|
|
|
|
curpkts = ifp->if_ipackets;
|
1999-12-04 17:41:31 +00:00
|
|
|
dc_rxeof(sc);
|
It appears that under certain circumstances that I still can't quite pin
down, the dc driver and receiver can fall out of sync with one another,
resulting in a condition where the chip continues to receive packets
but the driver never notices. Normally, the receive handler checks each
descriptor starting from the current producer index to see if the chip
has relinquished ownership, indicating that a packet has been received.
The driver hands the packet off to ether_input() and then prepares the
descriptor to receive another frame before moving on to the next
descriptor in the ring. But sometimes, the chip appears to skip a
descriptor. This leaves the driver testing the status word in a descriptor
that never gets updated. The driver still gets "RX done" interrupts but
never advances further into the RX ring, until the ring fills up and the
chip interrupts again to signal an error condition. Sometimes, the
driver will remain in this desynchronized state, resulting in spotty
performance until the interface is reset.
Fortunately, it's fairly simple to detect this condition: if we call
the rxeof routine but the number of received packets doesn't increase,
we suspect that there could be a problem. In this case, we call a new
routine called dc_rx_resync(), which scans ahead in the RX ring to see
if there's a frame waiting for us somewhere beyond that the driver thinks
is the current producer index. If it finds one, it bumps up the index
and calls the rxeof handler again to snarf up the packet and bring the
driver back in sync with the chip. (It may actually do this several times
in the event that there's more than one "hole" in the ring.)
So far the only card supported by if_dc which has exhibited this problem
is a LinkSys LNE100TX v2.0 (82c115 PNIC II), and it only seems to happen
on one particular system, however the fix is general enough and has low
enough overhead that we may as well apply it for all supported chipsets.
I also implemented the same fix for the 3Com xl driver, which is apparently
vulnerable to the same problem.
Problem originally noted and patch tested by: Matt Dillon
2000-01-03 15:28:47 +00:00
|
|
|
if (curpkts == ifp->if_ipackets) {
|
2003-06-01 19:26:34 +00:00
|
|
|
while (dc_rx_resync(sc))
|
It appears that under certain circumstances that I still can't quite pin
down, the dc driver and receiver can fall out of sync with one another,
resulting in a condition where the chip continues to receive packets
but the driver never notices. Normally, the receive handler checks each
descriptor starting from the current producer index to see if the chip
has relinquished ownership, indicating that a packet has been received.
The driver hands the packet off to ether_input() and then prepares the
descriptor to receive another frame before moving on to the next
descriptor in the ring. But sometimes, the chip appears to skip a
descriptor. This leaves the driver testing the status word in a descriptor
that never gets updated. The driver still gets "RX done" interrupts but
never advances further into the RX ring, until the ring fills up and the
chip interrupts again to signal an error condition. Sometimes, the
driver will remain in this desynchronized state, resulting in spotty
performance until the interface is reset.
Fortunately, it's fairly simple to detect this condition: if we call
the rxeof routine but the number of received packets doesn't increase,
we suspect that there could be a problem. In this case, we call a new
routine called dc_rx_resync(), which scans ahead in the RX ring to see
if there's a frame waiting for us somewhere beyond that the driver thinks
is the current producer index. If it finds one, it bumps up the index
and calls the rxeof handler again to snarf up the packet and bring the
driver back in sync with the chip. (It may actually do this several times
in the event that there's more than one "hole" in the ring.)
So far the only card supported by if_dc which has exhibited this problem
is a LinkSys LNE100TX v2.0 (82c115 PNIC II), and it only seems to happen
on one particular system, however the fix is general enough and has low
enough overhead that we may as well apply it for all supported chipsets.
I also implemented the same fix for the 3Com xl driver, which is apparently
vulnerable to the same problem.
Problem originally noted and patch tested by: Matt Dillon
2000-01-03 15:28:47 +00:00
|
|
|
dc_rxeof(sc);
|
|
|
|
}
|
|
|
|
}
|
1999-12-04 17:41:31 +00:00
|
|
|
|
|
|
|
if (status & DC_ISR_BUS_ERR) {
|
|
|
|
dc_reset(sc);
|
2005-08-18 19:10:07 +00:00
|
|
|
dc_init_locked(sc);
|
1999-12-04 17:41:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Re-enable interrupts. */
|
|
|
|
CSR_WRITE_4(sc, DC_IMR, DC_INTRS);
|
|
|
|
|
2004-10-01 07:04:09 +00:00
|
|
|
if (!IFQ_DRV_IS_EMPTY(&ifp->if_snd))
|
2005-08-18 19:10:07 +00:00
|
|
|
dc_start_locked(ifp);
|
1999-12-04 17:41:31 +00:00
|
|
|
|
2000-10-13 17:54:19 +00:00
|
|
|
DC_UNLOCK(sc);
|
1999-12-04 17:41:31 +00:00
|
|
|
}
|
|
|
|
|
2003-07-06 21:45:31 +00:00
|
|
|
static void
|
|
|
|
dc_dma_map_txbuf(arg, segs, nseg, mapsize, error)
|
|
|
|
void *arg;
|
|
|
|
bus_dma_segment_t *segs;
|
|
|
|
int nseg;
|
|
|
|
bus_size_t mapsize;
|
|
|
|
int error;
|
|
|
|
{
|
|
|
|
struct dc_softc *sc;
|
|
|
|
struct dc_desc *f;
|
|
|
|
int cur, first, frag, i;
|
|
|
|
|
|
|
|
sc = arg;
|
|
|
|
if (error) {
|
|
|
|
sc->dc_cdata.dc_tx_err = error;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
first = cur = frag = sc->dc_cdata.dc_tx_prod;
|
|
|
|
for (i = 0; i < nseg; i++) {
|
|
|
|
if ((sc->dc_flags & DC_TX_ADMTEK_WAR) &&
|
|
|
|
(frag == (DC_TX_LIST_CNT - 1)) &&
|
|
|
|
(first != sc->dc_cdata.dc_tx_first)) {
|
|
|
|
bus_dmamap_unload(sc->dc_mtag,
|
|
|
|
sc->dc_cdata.dc_tx_map[first]);
|
|
|
|
sc->dc_cdata.dc_tx_err = ENOBUFS;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
f = &sc->dc_ldata->dc_tx_list[frag];
|
2003-07-09 15:03:10 +00:00
|
|
|
f->dc_ctl = htole32(DC_TXCTL_TLINK | segs[i].ds_len);
|
2003-07-06 21:45:31 +00:00
|
|
|
if (i == 0) {
|
|
|
|
f->dc_status = 0;
|
2003-07-09 15:03:10 +00:00
|
|
|
f->dc_ctl |= htole32(DC_TXCTL_FIRSTFRAG);
|
2003-07-06 21:45:31 +00:00
|
|
|
} else
|
2003-07-09 15:03:10 +00:00
|
|
|
f->dc_status = htole32(DC_TXSTAT_OWN);
|
|
|
|
f->dc_data = htole32(segs[i].ds_addr);
|
2003-07-06 21:45:31 +00:00
|
|
|
cur = frag;
|
|
|
|
DC_INC(frag, DC_TX_LIST_CNT);
|
|
|
|
}
|
|
|
|
|
|
|
|
sc->dc_cdata.dc_tx_err = 0;
|
|
|
|
sc->dc_cdata.dc_tx_prod = frag;
|
|
|
|
sc->dc_cdata.dc_tx_cnt += nseg;
|
2003-07-09 15:03:10 +00:00
|
|
|
sc->dc_ldata->dc_tx_list[cur].dc_ctl |= htole32(DC_TXCTL_LASTFRAG);
|
2004-01-08 06:22:15 +00:00
|
|
|
sc->dc_cdata.dc_tx_chain[cur] = sc->dc_cdata.dc_tx_mapping;
|
2003-07-06 21:45:31 +00:00
|
|
|
if (sc->dc_flags & DC_TX_INTR_FIRSTFRAG)
|
2003-07-09 15:03:10 +00:00
|
|
|
sc->dc_ldata->dc_tx_list[first].dc_ctl |=
|
|
|
|
htole32(DC_TXCTL_FINT);
|
2003-07-06 21:45:31 +00:00
|
|
|
if (sc->dc_flags & DC_TX_INTR_ALWAYS)
|
2003-07-09 15:03:10 +00:00
|
|
|
sc->dc_ldata->dc_tx_list[cur].dc_ctl |= htole32(DC_TXCTL_FINT);
|
2003-07-06 21:45:31 +00:00
|
|
|
if (sc->dc_flags & DC_TX_USE_TX_INTR && sc->dc_cdata.dc_tx_cnt > 64)
|
2003-07-09 15:03:10 +00:00
|
|
|
sc->dc_ldata->dc_tx_list[cur].dc_ctl |= htole32(DC_TXCTL_FINT);
|
|
|
|
sc->dc_ldata->dc_tx_list[first].dc_status = htole32(DC_TXSTAT_OWN);
|
2003-07-06 21:45:31 +00:00
|
|
|
}
|
|
|
|
|
1999-12-04 17:41:31 +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
|
2003-10-19 23:05:19 +00:00
|
|
|
dc_encap(struct dc_softc *sc, struct mbuf **m_head)
|
1999-12-04 17:41:31 +00:00
|
|
|
{
|
2003-06-01 19:26:34 +00:00
|
|
|
struct mbuf *m;
|
2003-07-06 21:45:31 +00:00
|
|
|
int error, idx, chainlen = 0;
|
1999-12-04 17:41:31 +00:00
|
|
|
|
2003-03-29 21:27:07 +00:00
|
|
|
/*
|
|
|
|
* If there's no way we can send any packets, return now.
|
|
|
|
*/
|
|
|
|
if (DC_TX_LIST_CNT - sc->dc_cdata.dc_tx_cnt < 6)
|
|
|
|
return (ENOBUFS);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Count the number of frags in this chain to see if
|
|
|
|
* we need to m_defrag. Since the descriptor list is shared
|
|
|
|
* by all packets, we'll m_defrag long chains so that they
|
|
|
|
* do not use up the entire list, even if they would fit.
|
|
|
|
*/
|
2003-10-19 23:05:19 +00:00
|
|
|
for (m = *m_head; m != NULL; m = m->m_next)
|
2003-03-29 21:27:07 +00:00
|
|
|
chainlen++;
|
|
|
|
|
|
|
|
if ((chainlen > DC_TX_LIST_CNT / 4) ||
|
|
|
|
((DC_TX_LIST_CNT - (chainlen + sc->dc_cdata.dc_tx_cnt)) < 6)) {
|
2003-10-19 23:05:19 +00:00
|
|
|
m = m_defrag(*m_head, M_DONTWAIT);
|
2003-03-29 21:27:07 +00:00
|
|
|
if (m == NULL)
|
|
|
|
return (ENOBUFS);
|
2003-10-19 23:05:19 +00:00
|
|
|
*m_head = m;
|
2003-03-29 21:27:07 +00:00
|
|
|
}
|
2003-06-01 19:26:34 +00:00
|
|
|
|
1999-12-04 17:41:31 +00:00
|
|
|
/*
|
2002-09-04 18:14:17 +00:00
|
|
|
* Start packing the mbufs in this chain into
|
1999-12-04 17:41:31 +00:00
|
|
|
* the fragment pointers. Stop when we run out
|
2002-09-04 18:14:17 +00:00
|
|
|
* of fragments or hit the end of the mbuf chain.
|
1999-12-04 17:41:31 +00:00
|
|
|
*/
|
2003-07-06 21:45:31 +00:00
|
|
|
idx = sc->dc_cdata.dc_tx_prod;
|
2004-01-08 06:22:15 +00:00
|
|
|
sc->dc_cdata.dc_tx_mapping = *m_head;
|
2003-07-06 21:45:31 +00:00
|
|
|
error = bus_dmamap_load_mbuf(sc->dc_mtag, sc->dc_cdata.dc_tx_map[idx],
|
2003-10-19 23:05:19 +00:00
|
|
|
*m_head, dc_dma_map_txbuf, sc, 0);
|
2003-07-06 21:45:31 +00:00
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
if (sc->dc_cdata.dc_tx_err != 0)
|
2004-07-05 22:35:18 +00:00
|
|
|
return (sc->dc_cdata.dc_tx_err);
|
2003-07-06 21:45:31 +00:00
|
|
|
bus_dmamap_sync(sc->dc_mtag, sc->dc_cdata.dc_tx_map[idx],
|
|
|
|
BUS_DMASYNC_PREWRITE);
|
|
|
|
bus_dmamap_sync(sc->dc_ltag, sc->dc_lmap,
|
|
|
|
BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD);
|
2003-06-01 19:26:34 +00:00
|
|
|
return (0);
|
1999-12-04 17:41:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Main transmit routine. To avoid having to do mbuf copies, we put pointers
|
|
|
|
* to the mbuf data regions directly in the transmit lists. We also save a
|
|
|
|
* copy of the pointers since the transmit list fragment pointers are
|
|
|
|
* physical addresses.
|
|
|
|
*/
|
|
|
|
|
2002-08-23 23:49:02 +00:00
|
|
|
static void
|
2003-06-01 19:26:34 +00:00
|
|
|
dc_start(struct ifnet *ifp)
|
2005-08-18 19:10:07 +00:00
|
|
|
{
|
|
|
|
struct dc_softc *sc;
|
|
|
|
|
|
|
|
sc = ifp->if_softc;
|
|
|
|
DC_LOCK(sc);
|
|
|
|
dc_start_locked(ifp);
|
|
|
|
DC_UNLOCK(sc);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
dc_start_locked(struct ifnet *ifp)
|
1999-12-04 17:41:31 +00:00
|
|
|
{
|
2003-06-01 19:26:34 +00:00
|
|
|
struct dc_softc *sc;
|
|
|
|
struct mbuf *m_head = NULL, *m;
|
2004-10-01 07:04:09 +00:00
|
|
|
unsigned int queued = 0;
|
2003-06-01 19:26:34 +00:00
|
|
|
int idx;
|
1999-12-04 17:41:31 +00:00
|
|
|
|
|
|
|
sc = ifp->if_softc;
|
|
|
|
|
2005-08-18 19:10:07 +00:00
|
|
|
DC_LOCK_ASSERT(sc);
|
2000-10-13 17:54:19 +00:00
|
|
|
|
2005-08-18 19:10:07 +00:00
|
|
|
if (!sc->dc_link && ifp->if_snd.ifq_len < 10)
|
1999-12-04 17:41:31 +00:00
|
|
|
return;
|
|
|
|
|
2005-08-18 19:10:07 +00:00
|
|
|
if (ifp->if_drv_flags & IFF_DRV_OACTIVE)
|
1999-12-04 17:41:31 +00:00
|
|
|
return;
|
|
|
|
|
2003-07-06 21:45:31 +00:00
|
|
|
idx = sc->dc_cdata.dc_tx_first = sc->dc_cdata.dc_tx_prod;
|
1999-12-04 17:41:31 +00:00
|
|
|
|
2003-06-01 19:26:34 +00:00
|
|
|
while (sc->dc_cdata.dc_tx_chain[idx] == NULL) {
|
2004-10-01 07:04:09 +00:00
|
|
|
IFQ_DRV_DEQUEUE(&ifp->if_snd, m_head);
|
1999-12-04 17:41:31 +00:00
|
|
|
if (m_head == NULL)
|
|
|
|
break;
|
|
|
|
|
2001-12-11 02:47:53 +00:00
|
|
|
if (sc->dc_flags & DC_TX_COALESCE &&
|
|
|
|
(m_head->m_next != NULL ||
|
2001-12-15 02:51:21 +00:00
|
|
|
sc->dc_flags & DC_TX_ALIGN)) {
|
2003-03-29 21:27:07 +00:00
|
|
|
m = m_defrag(m_head, M_DONTWAIT);
|
|
|
|
if (m == NULL) {
|
2004-10-01 07:04:09 +00:00
|
|
|
IFQ_DRV_PREPEND(&ifp->if_snd, m_head);
|
2005-08-09 10:20:02 +00:00
|
|
|
ifp->if_drv_flags |= IFF_DRV_OACTIVE;
|
2000-01-12 22:24:05 +00:00
|
|
|
break;
|
2003-03-29 21:27:07 +00:00
|
|
|
} else {
|
|
|
|
m_head = m;
|
2000-01-12 22:24:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-10-19 23:05:19 +00:00
|
|
|
if (dc_encap(sc, &m_head)) {
|
2004-10-01 07:04:09 +00:00
|
|
|
IFQ_DRV_PREPEND(&ifp->if_snd, m_head);
|
2005-08-09 10:20:02 +00:00
|
|
|
ifp->if_drv_flags |= IFF_DRV_OACTIVE;
|
1999-12-04 17:41:31 +00:00
|
|
|
break;
|
|
|
|
}
|
2003-07-06 21:45:31 +00:00
|
|
|
idx = sc->dc_cdata.dc_tx_prod;
|
1999-12-04 17:41:31 +00:00
|
|
|
|
2004-10-01 07:04:09 +00:00
|
|
|
queued++;
|
1999-12-04 17:41:31 +00:00
|
|
|
/*
|
|
|
|
* If there's a BPF listener, bounce a copy of this frame
|
|
|
|
* to him.
|
|
|
|
*/
|
2002-11-14 23:49:09 +00:00
|
|
|
BPF_MTAP(ifp, m_head);
|
2000-10-05 17:36:14 +00:00
|
|
|
|
|
|
|
if (sc->dc_flags & DC_TX_ONE) {
|
2005-08-09 10:20:02 +00:00
|
|
|
ifp->if_drv_flags |= IFF_DRV_OACTIVE;
|
2000-10-05 17:36:14 +00:00
|
|
|
break;
|
|
|
|
}
|
1999-12-04 17:41:31 +00:00
|
|
|
}
|
|
|
|
|
2004-10-01 07:04:09 +00:00
|
|
|
if (queued > 0) {
|
|
|
|
/* Transmit */
|
|
|
|
if (!(sc->dc_flags & DC_TX_POLL))
|
|
|
|
CSR_WRITE_4(sc, DC_TXSTART, 0xFFFFFFFF);
|
1999-12-04 17:41:31 +00:00
|
|
|
|
2004-10-01 07:04:09 +00:00
|
|
|
/*
|
|
|
|
* Set a timeout in case the chip goes out to lunch.
|
|
|
|
*/
|
|
|
|
ifp->if_timer = 5;
|
|
|
|
}
|
1999-12-04 17:41:31 +00:00
|
|
|
}
|
|
|
|
|
2002-08-23 23:49:02 +00:00
|
|
|
static void
|
2003-06-01 19:26:34 +00:00
|
|
|
dc_init(void *xsc)
|
1999-12-04 17:41:31 +00:00
|
|
|
{
|
2003-06-01 19:26:34 +00:00
|
|
|
struct dc_softc *sc = xsc;
|
2005-08-18 19:10:07 +00:00
|
|
|
|
|
|
|
DC_LOCK(sc);
|
|
|
|
dc_init_locked(sc);
|
|
|
|
#ifdef SRM_MEDIA
|
|
|
|
if(sc->dc_srm_media) {
|
|
|
|
struct ifreq ifr;
|
|
|
|
struct mii_data *mii;
|
|
|
|
|
|
|
|
ifr.ifr_media = sc->dc_srm_media;
|
|
|
|
sc->dc_srm_media = 0;
|
|
|
|
DC_UNLOCK(sc);
|
|
|
|
mii = device_get_softc(sc->dc_miibus);
|
|
|
|
ifmedia_ioctl(sc->dc_ifp, &ifr, &mii->mii_media, SIOCSIFMEDIA);
|
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
DC_UNLOCK(sc);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
dc_init_locked(struct dc_softc *sc)
|
|
|
|
{
|
2005-06-10 16:49:24 +00:00
|
|
|
struct ifnet *ifp = sc->dc_ifp;
|
2003-06-01 19:26:34 +00:00
|
|
|
struct mii_data *mii;
|
1999-12-04 17:41:31 +00:00
|
|
|
|
2005-08-18 19:10:07 +00:00
|
|
|
DC_LOCK_ASSERT(sc);
|
1999-12-04 17:41:31 +00:00
|
|
|
|
|
|
|
mii = device_get_softc(sc->dc_miibus);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Cancel pending I/O and free all RX/TX buffers.
|
|
|
|
*/
|
|
|
|
dc_stop(sc);
|
|
|
|
dc_reset(sc);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set cache alignment and burst length.
|
|
|
|
*/
|
2000-01-19 19:03:08 +00:00
|
|
|
if (DC_IS_ASIX(sc) || DC_IS_DAVICOM(sc))
|
1999-12-04 17:41:31 +00:00
|
|
|
CSR_WRITE_4(sc, DC_BUSCTL, 0);
|
|
|
|
else
|
2003-06-01 19:26:34 +00:00
|
|
|
CSR_WRITE_4(sc, DC_BUSCTL, DC_BUSCTL_MRME | DC_BUSCTL_MRLE);
|
2001-10-27 00:59:17 +00:00
|
|
|
/*
|
|
|
|
* Evenly share the bus between receive and transmit process.
|
|
|
|
*/
|
|
|
|
if (DC_IS_INTEL(sc))
|
|
|
|
DC_SETBIT(sc, DC_BUSCTL, DC_BUSCTL_ARBITRATION);
|
1999-12-04 17:41:31 +00:00
|
|
|
if (DC_IS_DAVICOM(sc) || DC_IS_INTEL(sc)) {
|
|
|
|
DC_SETBIT(sc, DC_BUSCTL, DC_BURSTLEN_USECA);
|
|
|
|
} else {
|
|
|
|
DC_SETBIT(sc, DC_BUSCTL, DC_BURSTLEN_16LONG);
|
|
|
|
}
|
|
|
|
if (sc->dc_flags & DC_TX_POLL)
|
|
|
|
DC_SETBIT(sc, DC_BUSCTL, DC_TXPOLL_1);
|
|
|
|
switch(sc->dc_cachesize) {
|
|
|
|
case 32:
|
|
|
|
DC_SETBIT(sc, DC_BUSCTL, DC_CACHEALIGN_32LONG);
|
|
|
|
break;
|
|
|
|
case 16:
|
|
|
|
DC_SETBIT(sc, DC_BUSCTL, DC_CACHEALIGN_16LONG);
|
2003-06-01 19:26:34 +00:00
|
|
|
break;
|
1999-12-04 17:41:31 +00:00
|
|
|
case 8:
|
|
|
|
DC_SETBIT(sc, DC_BUSCTL, DC_CACHEALIGN_8LONG);
|
2003-06-01 19:26:34 +00:00
|
|
|
break;
|
1999-12-04 17:41:31 +00:00
|
|
|
case 0:
|
|
|
|
default:
|
|
|
|
DC_SETBIT(sc, DC_BUSCTL, DC_CACHEALIGN_NONE);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sc->dc_flags & DC_TX_STORENFWD)
|
|
|
|
DC_SETBIT(sc, DC_NETCFG, DC_NETCFG_STORENFWD);
|
|
|
|
else {
|
2001-02-22 19:26:55 +00:00
|
|
|
if (sc->dc_txthresh > DC_TXTHRESH_MAX) {
|
1999-12-04 17:41:31 +00:00
|
|
|
DC_SETBIT(sc, DC_NETCFG, DC_NETCFG_STORENFWD);
|
|
|
|
} else {
|
|
|
|
DC_CLRBIT(sc, DC_NETCFG, DC_NETCFG_STORENFWD);
|
|
|
|
DC_SETBIT(sc, DC_NETCFG, sc->dc_txthresh);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DC_SETBIT(sc, DC_NETCFG, DC_NETCFG_NO_RXCRC);
|
|
|
|
DC_CLRBIT(sc, DC_NETCFG, DC_NETCFG_TX_BACKOFF);
|
|
|
|
|
|
|
|
if (DC_IS_MACRONIX(sc) || DC_IS_PNICII(sc)) {
|
|
|
|
/*
|
|
|
|
* The app notes for the 98713 and 98715A say that
|
|
|
|
* in order to have the chips operate properly, a magic
|
|
|
|
* number must be written to CSR16. Macronix does not
|
|
|
|
* document the meaning of these bits so there's no way
|
|
|
|
* to know exactly what they do. The 98713 has a magic
|
|
|
|
* number all its own; the rest all use a different one.
|
|
|
|
*/
|
|
|
|
DC_CLRBIT(sc, DC_MX_MAGICPACKET, 0xFFFF0000);
|
|
|
|
if (sc->dc_type == DC_TYPE_98713)
|
|
|
|
DC_SETBIT(sc, DC_MX_MAGICPACKET, DC_MX_MAGIC_98713);
|
|
|
|
else
|
|
|
|
DC_SETBIT(sc, DC_MX_MAGICPACKET, DC_MX_MAGIC_98715);
|
|
|
|
}
|
|
|
|
|
2000-10-19 08:34:32 +00:00
|
|
|
if (DC_IS_XIRCOM(sc)) {
|
|
|
|
/*
|
|
|
|
* setup General Purpose Port mode and data so the tulip
|
|
|
|
* can talk to the MII.
|
|
|
|
*/
|
|
|
|
CSR_WRITE_4(sc, DC_SIAGP, DC_SIAGP_WRITE_EN | DC_SIAGP_INT1_EN |
|
|
|
|
DC_SIAGP_MD_GP2_OUTPUT | DC_SIAGP_MD_GP0_OUTPUT);
|
|
|
|
DELAY(10);
|
|
|
|
CSR_WRITE_4(sc, DC_SIAGP, DC_SIAGP_INT1_EN |
|
|
|
|
DC_SIAGP_MD_GP2_OUTPUT | DC_SIAGP_MD_GP0_OUTPUT);
|
|
|
|
DELAY(10);
|
|
|
|
}
|
|
|
|
|
1999-12-04 17:41:31 +00:00
|
|
|
DC_CLRBIT(sc, DC_NETCFG, DC_NETCFG_TX_THRESH);
|
2001-02-22 19:26:55 +00:00
|
|
|
DC_SETBIT(sc, DC_NETCFG, DC_TXTHRESH_MIN);
|
1999-12-04 17:41:31 +00:00
|
|
|
|
|
|
|
/* Init circular RX list. */
|
|
|
|
if (dc_list_rx_init(sc) == ENOBUFS) {
|
2005-08-10 20:33:46 +00:00
|
|
|
if_printf(ifp,
|
|
|
|
"initialization failed: no memory for rx buffers\n");
|
1999-12-04 17:41:31 +00:00
|
|
|
dc_stop(sc);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2003-07-06 21:45:31 +00:00
|
|
|
* Init TX descriptors.
|
1999-12-04 17:41:31 +00:00
|
|
|
*/
|
|
|
|
dc_list_tx_init(sc);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Load the address of the RX list.
|
|
|
|
*/
|
2003-07-06 21:45:31 +00:00
|
|
|
CSR_WRITE_4(sc, DC_RXADDR, DC_RXDESC(sc, 0));
|
|
|
|
CSR_WRITE_4(sc, DC_TXADDR, DC_TXDESC(sc, 0));
|
1999-12-04 17:41:31 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Enable interrupts.
|
|
|
|
*/
|
Device Polling code for -current.
Non-SMP, i386-only, no polling in the idle loop at the moment.
To use this code you must compile a kernel with
options DEVICE_POLLING
and at runtime enable polling with
sysctl kern.polling.enable=1
The percentage of CPU reserved to userland can be set with
sysctl kern.polling.user_frac=NN (default is 50)
while the remainder is used by polling device drivers and netisr's.
These are the only two variables that you should need to touch. There
are a few more parameters in kern.polling but the default values
are adequate for all purposes. See the code in kern_poll.c for
more details on them.
Polling in the idle loop will be implemented shortly by introducing
a kernel thread which does the job. Until then, the amount of CPU
dedicated to polling will never exceed (100-user_frac).
The equivalent (actually, better) code for -stable is at
http://info.iet.unipi.it/~luigi/polling/
and also supports polling in the idle loop.
NOTE to Alpha developers:
There is really nothing in this code that is i386-specific.
If you move the 2 lines supporting the new option from
sys/conf/{files,options}.i386 to sys/conf/{files,options} I am
pretty sure that this should work on the Alpha as well, just that
I do not have a suitable test box to try it. If someone feels like
trying it, I would appreciate it.
NOTE to other developers:
sure some things could be done better, and as always I am open to
constructive criticism, which a few of you have already given and
I greatly appreciated.
However, before proposing radical architectural changes, please
take some time to possibly try out this code, or at the very least
read the comments in kern_poll.c, especially re. the reason why I
am using a soft netisr and cannot (I believe) replace it with a
simple timeout.
Quick description of files touched by this commit:
sys/conf/files.i386
new file kern/kern_poll.c
sys/conf/options.i386
new option
sys/i386/i386/trap.c
poll in trap (disabled by default)
sys/kern/kern_clock.c
initialization and hardclock hooks.
sys/kern/kern_intr.c
minor swi_net changes
sys/kern/kern_poll.c
the bulk of the code.
sys/net/if.h
new flag
sys/net/if_var.h
declaration for functions used in device drivers.
sys/net/netisr.h
NETISR_POLL
sys/dev/fxp/if_fxp.c
sys/dev/fxp/if_fxpvar.h
sys/pci/if_dc.c
sys/pci/if_dcreg.h
sys/pci/if_sis.c
sys/pci/if_sisreg.h
device driver modifications
2001-12-14 17:56:12 +00:00
|
|
|
#ifdef DEVICE_POLLING
|
|
|
|
/*
|
|
|
|
* ... but only if we are not polling, and make sure they are off in
|
|
|
|
* the case of polling. Some cards (e.g. fxp) turn interrupts on
|
|
|
|
* after a reset.
|
|
|
|
*/
|
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)
|
Device Polling code for -current.
Non-SMP, i386-only, no polling in the idle loop at the moment.
To use this code you must compile a kernel with
options DEVICE_POLLING
and at runtime enable polling with
sysctl kern.polling.enable=1
The percentage of CPU reserved to userland can be set with
sysctl kern.polling.user_frac=NN (default is 50)
while the remainder is used by polling device drivers and netisr's.
These are the only two variables that you should need to touch. There
are a few more parameters in kern.polling but the default values
are adequate for all purposes. See the code in kern_poll.c for
more details on them.
Polling in the idle loop will be implemented shortly by introducing
a kernel thread which does the job. Until then, the amount of CPU
dedicated to polling will never exceed (100-user_frac).
The equivalent (actually, better) code for -stable is at
http://info.iet.unipi.it/~luigi/polling/
and also supports polling in the idle loop.
NOTE to Alpha developers:
There is really nothing in this code that is i386-specific.
If you move the 2 lines supporting the new option from
sys/conf/{files,options}.i386 to sys/conf/{files,options} I am
pretty sure that this should work on the Alpha as well, just that
I do not have a suitable test box to try it. If someone feels like
trying it, I would appreciate it.
NOTE to other developers:
sure some things could be done better, and as always I am open to
constructive criticism, which a few of you have already given and
I greatly appreciated.
However, before proposing radical architectural changes, please
take some time to possibly try out this code, or at the very least
read the comments in kern_poll.c, especially re. the reason why I
am using a soft netisr and cannot (I believe) replace it with a
simple timeout.
Quick description of files touched by this commit:
sys/conf/files.i386
new file kern/kern_poll.c
sys/conf/options.i386
new option
sys/i386/i386/trap.c
poll in trap (disabled by default)
sys/kern/kern_clock.c
initialization and hardclock hooks.
sys/kern/kern_intr.c
minor swi_net changes
sys/kern/kern_poll.c
the bulk of the code.
sys/net/if.h
new flag
sys/net/if_var.h
declaration for functions used in device drivers.
sys/net/netisr.h
NETISR_POLL
sys/dev/fxp/if_fxp.c
sys/dev/fxp/if_fxpvar.h
sys/pci/if_dc.c
sys/pci/if_dcreg.h
sys/pci/if_sis.c
sys/pci/if_sisreg.h
device driver modifications
2001-12-14 17:56:12 +00:00
|
|
|
CSR_WRITE_4(sc, DC_IMR, 0x00000000);
|
|
|
|
else
|
|
|
|
#endif
|
1999-12-04 17:41:31 +00:00
|
|
|
CSR_WRITE_4(sc, DC_IMR, DC_INTRS);
|
|
|
|
CSR_WRITE_4(sc, DC_ISR, 0xFFFFFFFF);
|
|
|
|
|
|
|
|
/* Enable transmitter. */
|
|
|
|
DC_SETBIT(sc, DC_NETCFG, DC_NETCFG_TX_ON);
|
|
|
|
|
2000-09-01 23:59:54 +00:00
|
|
|
/*
|
|
|
|
* If this is an Intel 21143 and we're not using the
|
|
|
|
* MII port, program the LED control pins so we get
|
|
|
|
* link and activity indications.
|
|
|
|
*/
|
2000-09-07 18:51:04 +00:00
|
|
|
if (sc->dc_flags & DC_TULIP_LEDS) {
|
2000-09-01 23:59:54 +00:00
|
|
|
CSR_WRITE_4(sc, DC_WATCHDOG,
|
2003-06-01 19:26:34 +00:00
|
|
|
DC_WDOG_CTLWREN | DC_WDOG_LINK | DC_WDOG_ACTIVITY);
|
2000-09-07 18:51:04 +00:00
|
|
|
CSR_WRITE_4(sc, DC_WATCHDOG, 0);
|
2000-09-01 23:59:54 +00:00
|
|
|
}
|
|
|
|
|
1999-12-04 17:41:31 +00:00
|
|
|
/*
|
|
|
|
* Load the RX/multicast filter. We do this sort of late
|
|
|
|
* because the filter programming scheme on the 21143 and
|
|
|
|
* some clones requires DMAing a setup frame via the TX
|
|
|
|
* engine, and we need the transmitter enabled for that.
|
|
|
|
*/
|
|
|
|
dc_setfilt(sc);
|
|
|
|
|
|
|
|
/* Enable receiver. */
|
|
|
|
DC_SETBIT(sc, DC_NETCFG, DC_NETCFG_RX_ON);
|
|
|
|
CSR_WRITE_4(sc, DC_RXSTART, 0xFFFFFFFF);
|
|
|
|
|
|
|
|
mii_mediachg(mii);
|
|
|
|
dc_setcfg(sc, sc->dc_if_media);
|
|
|
|
|
2005-08-09 10:20:02 +00:00
|
|
|
ifp->if_drv_flags |= IFF_DRV_RUNNING;
|
|
|
|
ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
|
1999-12-04 17:41:31 +00:00
|
|
|
|
2000-09-20 00:59:17 +00:00
|
|
|
/* Don't start the ticker if this is a homePNA link. */
|
2002-04-29 05:32:44 +00:00
|
|
|
if (IFM_SUBTYPE(mii->mii_media.ifm_media) == IFM_HPNA_1)
|
2000-09-20 00:59:17 +00:00
|
|
|
sc->dc_link = 1;
|
|
|
|
else {
|
|
|
|
if (sc->dc_flags & DC_21143_NWAY)
|
2000-11-25 08:00:10 +00:00
|
|
|
callout_reset(&sc->dc_stat_ch, hz/10, dc_tick, sc);
|
2000-09-20 00:59:17 +00:00
|
|
|
else
|
2000-11-25 08:00:10 +00:00
|
|
|
callout_reset(&sc->dc_stat_ch, hz, dc_tick, sc);
|
2000-09-20 00:59:17 +00:00
|
|
|
}
|
1999-12-04 17:41:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set media options.
|
|
|
|
*/
|
2002-08-23 23:49:02 +00:00
|
|
|
static int
|
2003-06-01 19:26:34 +00:00
|
|
|
dc_ifmedia_upd(struct ifnet *ifp)
|
1999-12-04 17:41:31 +00:00
|
|
|
{
|
2003-06-01 19:26:34 +00:00
|
|
|
struct dc_softc *sc;
|
|
|
|
struct mii_data *mii;
|
|
|
|
struct ifmedia *ifm;
|
1999-12-04 17:41:31 +00:00
|
|
|
|
|
|
|
sc = ifp->if_softc;
|
|
|
|
mii = device_get_softc(sc->dc_miibus);
|
2005-08-18 19:10:07 +00:00
|
|
|
DC_LOCK(sc);
|
1999-12-04 17:41:31 +00:00
|
|
|
mii_mediachg(mii);
|
2000-01-24 17:19:37 +00:00
|
|
|
ifm = &mii->mii_media;
|
|
|
|
|
|
|
|
if (DC_IS_DAVICOM(sc) &&
|
2002-04-29 05:32:44 +00:00
|
|
|
IFM_SUBTYPE(ifm->ifm_media) == IFM_HPNA_1)
|
2000-01-24 17:19:37 +00:00
|
|
|
dc_setcfg(sc, ifm->ifm_media);
|
|
|
|
else
|
|
|
|
sc->dc_link = 0;
|
2005-08-18 19:10:07 +00:00
|
|
|
DC_UNLOCK(sc);
|
1999-12-04 17:41:31 +00:00
|
|
|
|
2003-06-01 19:26:34 +00:00
|
|
|
return (0);
|
1999-12-04 17:41:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Report current media status.
|
|
|
|
*/
|
2002-08-23 23:49:02 +00:00
|
|
|
static void
|
2003-06-01 19:26:34 +00:00
|
|
|
dc_ifmedia_sts(struct ifnet *ifp, struct ifmediareq *ifmr)
|
1999-12-04 17:41:31 +00:00
|
|
|
{
|
2003-06-01 19:26:34 +00:00
|
|
|
struct dc_softc *sc;
|
|
|
|
struct mii_data *mii;
|
|
|
|
struct ifmedia *ifm;
|
1999-12-04 17:41:31 +00:00
|
|
|
|
|
|
|
sc = ifp->if_softc;
|
|
|
|
mii = device_get_softc(sc->dc_miibus);
|
2005-08-18 19:10:07 +00:00
|
|
|
DC_LOCK(sc);
|
1999-12-04 17:41:31 +00:00
|
|
|
mii_pollstat(mii);
|
2000-01-24 17:19:37 +00:00
|
|
|
ifm = &mii->mii_media;
|
|
|
|
if (DC_IS_DAVICOM(sc)) {
|
2002-04-29 05:32:44 +00:00
|
|
|
if (IFM_SUBTYPE(ifm->ifm_media) == IFM_HPNA_1) {
|
2000-01-24 17:19:37 +00:00
|
|
|
ifmr->ifm_active = ifm->ifm_media;
|
|
|
|
ifmr->ifm_status = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
1999-12-04 17:41:31 +00:00
|
|
|
ifmr->ifm_active = mii->mii_media_active;
|
|
|
|
ifmr->ifm_status = mii->mii_media_status;
|
2005-08-18 19:10:07 +00:00
|
|
|
DC_UNLOCK(sc);
|
1999-12-04 17:41:31 +00:00
|
|
|
}
|
|
|
|
|
2002-08-23 23:49:02 +00:00
|
|
|
static int
|
2003-06-01 19:26:34 +00:00
|
|
|
dc_ioctl(struct ifnet *ifp, u_long command, caddr_t data)
|
1999-12-04 17:41:31 +00:00
|
|
|
{
|
2003-06-01 19:26:34 +00:00
|
|
|
struct dc_softc *sc = ifp->if_softc;
|
|
|
|
struct ifreq *ifr = (struct ifreq *)data;
|
|
|
|
struct mii_data *mii;
|
|
|
|
int error = 0;
|
1999-12-04 17:41:31 +00:00
|
|
|
|
2003-06-01 19:26:34 +00:00
|
|
|
switch (command) {
|
1999-12-04 17:41:31 +00:00
|
|
|
case SIOCSIFFLAGS:
|
2005-08-18 19:10:07 +00:00
|
|
|
DC_LOCK(sc);
|
1999-12-04 17:41:31 +00:00
|
|
|
if (ifp->if_flags & IFF_UP) {
|
2002-11-25 19:28:01 +00:00
|
|
|
int need_setfilt = (ifp->if_flags ^ sc->dc_if_flags) &
|
|
|
|
(IFF_PROMISC | IFF_ALLMULTI);
|
|
|
|
|
2005-08-09 10:20:02 +00:00
|
|
|
if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
|
2002-11-25 19:28:01 +00:00
|
|
|
if (need_setfilt)
|
|
|
|
dc_setfilt(sc);
|
|
|
|
} else {
|
1999-12-04 17:41:31 +00:00
|
|
|
sc->dc_txthresh = 0;
|
2005-08-18 19:10:07 +00:00
|
|
|
dc_init_locked(sc);
|
1999-12-04 17:41:31 +00:00
|
|
|
}
|
|
|
|
} else {
|
2005-08-09 10:20:02 +00:00
|
|
|
if (ifp->if_drv_flags & IFF_DRV_RUNNING)
|
1999-12-04 17:41:31 +00:00
|
|
|
dc_stop(sc);
|
|
|
|
}
|
|
|
|
sc->dc_if_flags = ifp->if_flags;
|
2005-08-18 19:10:07 +00:00
|
|
|
DC_UNLOCK(sc);
|
1999-12-04 17:41:31 +00:00
|
|
|
error = 0;
|
|
|
|
break;
|
|
|
|
case SIOCADDMULTI:
|
|
|
|
case SIOCDELMULTI:
|
2005-08-18 19:10:07 +00:00
|
|
|
DC_LOCK(sc);
|
1999-12-04 17:41:31 +00:00
|
|
|
dc_setfilt(sc);
|
2005-08-18 19:10:07 +00:00
|
|
|
DC_UNLOCK(sc);
|
1999-12-04 17:41:31 +00:00
|
|
|
error = 0;
|
|
|
|
break;
|
|
|
|
case SIOCGIFMEDIA:
|
|
|
|
case SIOCSIFMEDIA:
|
|
|
|
mii = device_get_softc(sc->dc_miibus);
|
|
|
|
error = ifmedia_ioctl(ifp, ifr, &mii->mii_media, command);
|
2000-10-05 17:36:14 +00:00
|
|
|
#ifdef SRM_MEDIA
|
2005-08-18 19:10:07 +00:00
|
|
|
DC_LOCK(sc);
|
2000-03-11 05:20:56 +00:00
|
|
|
if (sc->dc_srm_media)
|
|
|
|
sc->dc_srm_media = 0;
|
2005-08-18 19:10:07 +00:00
|
|
|
DC_UNLOCK(sc);
|
2000-03-11 05:20:56 +00:00
|
|
|
#endif
|
1999-12-04 17:41:31 +00:00
|
|
|
break;
|
2004-04-11 13:47:15 +00:00
|
|
|
case SIOCSIFCAP:
|
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(dc_poll, ifp);
|
|
|
|
if (error)
|
|
|
|
return(error);
|
|
|
|
DC_LOCK(sc);
|
|
|
|
/* Disable interrupts */
|
|
|
|
CSR_WRITE_4(sc, DC_IMR, 0x00000000);
|
|
|
|
ifp->if_capenable |= IFCAP_POLLING;
|
|
|
|
DC_UNLOCK(sc);
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
}
|
|
|
|
if (!(ifr->ifr_reqcap & IFCAP_POLLING) &&
|
|
|
|
ifp->if_capenable & IFCAP_POLLING) {
|
|
|
|
error = ether_poll_deregister(ifp);
|
|
|
|
/* Enable interrupts. */
|
|
|
|
DC_LOCK(sc);
|
|
|
|
CSR_WRITE_4(sc, DC_IMR, DC_INTRS);
|
|
|
|
ifp->if_capenable &= ~IFCAP_POLLING;
|
|
|
|
DC_UNLOCK(sc);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
#endif /* DEVICE_POLLING */
|
2004-04-11 13:47:15 +00:00
|
|
|
break;
|
1999-12-04 17:41:31 +00:00
|
|
|
default:
|
2002-11-14 23:49:09 +00:00
|
|
|
error = ether_ioctl(ifp, command, data);
|
1999-12-04 17:41:31 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2003-06-01 19:26:34 +00:00
|
|
|
return (error);
|
1999-12-04 17:41:31 +00:00
|
|
|
}
|
|
|
|
|
2002-08-23 23:49:02 +00:00
|
|
|
static void
|
2003-06-01 19:26:34 +00:00
|
|
|
dc_watchdog(struct ifnet *ifp)
|
1999-12-04 17:41:31 +00:00
|
|
|
{
|
2003-06-01 19:26:34 +00:00
|
|
|
struct dc_softc *sc;
|
1999-12-04 17:41:31 +00:00
|
|
|
|
|
|
|
sc = ifp->if_softc;
|
|
|
|
|
2000-10-13 17:54:19 +00:00
|
|
|
DC_LOCK(sc);
|
|
|
|
|
1999-12-04 17:41:31 +00:00
|
|
|
ifp->if_oerrors++;
|
2005-08-10 20:33:46 +00:00
|
|
|
if_printf(ifp, "watchdog timeout\n");
|
1999-12-04 17:41:31 +00:00
|
|
|
|
|
|
|
dc_stop(sc);
|
|
|
|
dc_reset(sc);
|
2005-08-18 19:10:07 +00:00
|
|
|
dc_init_locked(sc);
|
1999-12-04 17:41:31 +00:00
|
|
|
|
2004-10-01 07:04:09 +00:00
|
|
|
if (!IFQ_DRV_IS_EMPTY(&ifp->if_snd))
|
2005-08-18 19:10:07 +00:00
|
|
|
dc_start_locked(ifp);
|
1999-12-04 17:41:31 +00:00
|
|
|
|
2000-10-13 17:54:19 +00:00
|
|
|
DC_UNLOCK(sc);
|
1999-12-04 17:41:31 +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
|
2003-06-01 19:26:34 +00:00
|
|
|
dc_stop(struct dc_softc *sc)
|
1999-12-04 17:41:31 +00:00
|
|
|
{
|
2003-06-01 19:26:34 +00:00
|
|
|
struct ifnet *ifp;
|
2003-07-06 14:36:33 +00:00
|
|
|
struct dc_list_data *ld;
|
|
|
|
struct dc_chain_data *cd;
|
|
|
|
int i;
|
2003-07-09 15:03:10 +00:00
|
|
|
u_int32_t ctl;
|
1999-12-04 17:41:31 +00:00
|
|
|
|
2005-08-18 19:10:07 +00:00
|
|
|
DC_LOCK_ASSERT(sc);
|
2000-10-13 17:54:19 +00:00
|
|
|
|
2005-06-10 16:49:24 +00:00
|
|
|
ifp = sc->dc_ifp;
|
1999-12-04 17:41:31 +00:00
|
|
|
ifp->if_timer = 0;
|
2003-07-06 14:36:33 +00:00
|
|
|
ld = sc->dc_ldata;
|
|
|
|
cd = &sc->dc_cdata;
|
1999-12-04 17:41:31 +00:00
|
|
|
|
2000-11-25 08:00:10 +00:00
|
|
|
callout_stop(&sc->dc_stat_ch);
|
1999-12-04 17:41:31 +00:00
|
|
|
|
2005-08-09 10:20:02 +00:00
|
|
|
ifp->if_drv_flags &= ~(IFF_DRV_RUNNING | IFF_DRV_OACTIVE);
|
2001-12-07 00:57:57 +00:00
|
|
|
|
2003-06-01 19:26:34 +00:00
|
|
|
DC_CLRBIT(sc, DC_NETCFG, (DC_NETCFG_RX_ON | DC_NETCFG_TX_ON));
|
1999-12-04 17:41:31 +00:00
|
|
|
CSR_WRITE_4(sc, DC_IMR, 0x00000000);
|
|
|
|
CSR_WRITE_4(sc, DC_TXADDR, 0x00000000);
|
|
|
|
CSR_WRITE_4(sc, DC_RXADDR, 0x00000000);
|
|
|
|
sc->dc_link = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Free data in the RX lists.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < DC_RX_LIST_CNT; i++) {
|
2003-07-06 14:36:33 +00:00
|
|
|
if (cd->dc_rx_chain[i] != NULL) {
|
2003-07-06 21:45:31 +00:00
|
|
|
m_freem(cd->dc_rx_chain[i]);
|
|
|
|
cd->dc_rx_chain[i] = NULL;
|
1999-12-04 17:41:31 +00:00
|
|
|
}
|
|
|
|
}
|
2003-07-06 14:36:33 +00:00
|
|
|
bzero(&ld->dc_rx_list, sizeof(ld->dc_rx_list));
|
1999-12-04 17:41:31 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Free the TX list buffers.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < DC_TX_LIST_CNT; i++) {
|
2003-07-06 14:36:33 +00:00
|
|
|
if (cd->dc_tx_chain[i] != NULL) {
|
2003-07-09 15:03:10 +00:00
|
|
|
ctl = le32toh(ld->dc_tx_list[i].dc_ctl);
|
|
|
|
if ((ctl & DC_TXCTL_SETUP) ||
|
2004-01-08 06:22:15 +00:00
|
|
|
!(ctl & DC_TXCTL_LASTFRAG)) {
|
2003-07-06 14:36:33 +00:00
|
|
|
cd->dc_tx_chain[i] = NULL;
|
1999-12-04 17:41:31 +00:00
|
|
|
continue;
|
|
|
|
}
|
2003-07-06 21:45:31 +00:00
|
|
|
bus_dmamap_unload(sc->dc_mtag, cd->dc_tx_map[i]);
|
|
|
|
m_freem(cd->dc_tx_chain[i]);
|
2003-07-06 14:36:33 +00:00
|
|
|
cd->dc_tx_chain[i] = NULL;
|
1999-12-04 17:41:31 +00:00
|
|
|
}
|
|
|
|
}
|
2003-07-06 14:36:33 +00:00
|
|
|
bzero(&ld->dc_tx_list, sizeof(ld->dc_tx_list));
|
1999-12-04 17:41:31 +00:00
|
|
|
}
|
|
|
|
|
2002-05-06 10:55:42 +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
|
2003-06-01 19:26:34 +00:00
|
|
|
dc_suspend(device_t dev)
|
2002-05-06 10:55:42 +00:00
|
|
|
{
|
2003-06-01 19:26:34 +00:00
|
|
|
struct dc_softc *sc;
|
2002-05-06 10:55:42 +00:00
|
|
|
|
|
|
|
sc = device_get_softc(dev);
|
2005-08-18 19:10:07 +00:00
|
|
|
DC_LOCK(sc);
|
2002-05-06 10:55:42 +00:00
|
|
|
dc_stop(sc);
|
|
|
|
sc->suspended = 1;
|
2005-08-18 19:10:07 +00:00
|
|
|
DC_UNLOCK(sc);
|
2002-05-06 10:55:42 +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
|
2003-06-01 19:26:34 +00:00
|
|
|
dc_resume(device_t dev)
|
2002-05-06 10:55:42 +00:00
|
|
|
{
|
2003-06-01 19:26:34 +00:00
|
|
|
struct dc_softc *sc;
|
|
|
|
struct ifnet *ifp;
|
2002-05-06 10:55:42 +00:00
|
|
|
|
|
|
|
sc = device_get_softc(dev);
|
2005-06-10 16:49:24 +00:00
|
|
|
ifp = sc->dc_ifp;
|
2002-05-06 10:55:42 +00:00
|
|
|
|
2002-09-04 18:14:17 +00:00
|
|
|
/* reinitialize interface if necessary */
|
2005-08-18 19:10:07 +00:00
|
|
|
DC_LOCK(sc);
|
2002-09-04 18:14:17 +00:00
|
|
|
if (ifp->if_flags & IFF_UP)
|
2005-08-18 19:10:07 +00:00
|
|
|
dc_init_locked(sc);
|
2002-05-06 10:55:42 +00:00
|
|
|
|
|
|
|
sc->suspended = 0;
|
2005-08-18 19:10:07 +00:00
|
|
|
DC_UNLOCK(sc);
|
2002-05-06 10:55:42 +00:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1999-12-04 17:41:31 +00:00
|
|
|
/*
|
|
|
|
* Stop all chip I/O so that the kernel's probe routines don't
|
|
|
|
* get confused by errant DMAs when rebooting.
|
|
|
|
*/
|
2002-08-23 23:49:02 +00:00
|
|
|
static void
|
2003-06-01 19:26:34 +00:00
|
|
|
dc_shutdown(device_t dev)
|
1999-12-04 17:41:31 +00:00
|
|
|
{
|
2003-06-01 19:26:34 +00:00
|
|
|
struct dc_softc *sc;
|
1999-12-04 17:41:31 +00:00
|
|
|
|
|
|
|
sc = device_get_softc(dev);
|
|
|
|
|
2005-08-18 19:10:07 +00:00
|
|
|
DC_LOCK(sc);
|
1999-12-04 17:41:31 +00:00
|
|
|
dc_stop(sc);
|
2005-08-18 19:10:07 +00:00
|
|
|
DC_UNLOCK(sc);
|
1999-12-04 17:41:31 +00:00
|
|
|
}
|