2001-08-20 15:57:02 +04:00
|
|
|
/* $NetBSD: rtl81x9.c,v 1.39 2001/08/20 11:57:02 wiz Exp $ */
|
2000-04-10 11:42:55 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 1997, 1998
|
|
|
|
* Bill Paul <wpaul@ctr.columbia.edu>. All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by Bill Paul.
|
|
|
|
* 4. Neither the name of the author nor the names of any co-contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
|
|
|
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
|
|
|
* THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* FreeBSD Id: if_rl.c,v 1.17 1999/06/19 20:17:37 wpaul Exp
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* RealTek 8129/8139 PCI NIC driver
|
|
|
|
*
|
|
|
|
* Supports several extremely cheap PCI 10/100 adapters based on
|
|
|
|
* the RealTek chipset. Datasheets can be obtained from
|
|
|
|
* www.realtek.com.tw.
|
|
|
|
*
|
|
|
|
* Written by Bill Paul <wpaul@ctr.columbia.edu>
|
|
|
|
* Electrical Engineering Department
|
|
|
|
* Columbia University, New York City
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The RealTek 8139 PCI NIC redefines the meaning of 'low end.' This is
|
|
|
|
* probably the worst PCI ethernet controller ever made, with the possible
|
|
|
|
* exception of the FEAST chip made by SMC. The 8139 supports bus-master
|
|
|
|
* DMA, but it has a terrible interface that nullifies any performance
|
|
|
|
* gains that bus-master DMA usually offers.
|
|
|
|
*
|
|
|
|
* For transmission, the chip offers a series of four TX descriptor
|
|
|
|
* registers. Each transmit frame must be in a contiguous buffer, aligned
|
|
|
|
* on a longword (32-bit) boundary. This means we almost always have to
|
|
|
|
* do mbuf copies in order to transmit a frame, except in the unlikely
|
|
|
|
* case where a) the packet fits into a single mbuf, and b) the packet
|
|
|
|
* is 32-bit aligned within the mbuf's data area. The presence of only
|
|
|
|
* four descriptor registers means that we can never have more than four
|
|
|
|
* packets queued for transmission at any one time.
|
|
|
|
*
|
|
|
|
* Reception is not much better. The driver has to allocate a single large
|
|
|
|
* buffer area (up to 64K in size) into which the chip will DMA received
|
|
|
|
* frames. Because we don't know where within this region received packets
|
|
|
|
* will begin or end, we have no choice but to copy data from the buffer
|
|
|
|
* area into mbufs in order to pass the packets up to the higher protocol
|
|
|
|
* levels.
|
|
|
|
*
|
|
|
|
* It's impossible given this rotten design to really achieve decent
|
|
|
|
* performance at 100Mbps, unless you happen to have a 400Mhz PII or
|
|
|
|
* some equally overmuscled CPU to drive it.
|
|
|
|
*
|
|
|
|
* On the bright side, the 8139 does have a built-in PHY, although
|
|
|
|
* rather than using an MDIO serial interface like most other NICs, the
|
|
|
|
* PHY registers are directly accessible through the 8139's register
|
|
|
|
* space. The 8139 supports autonegotiation, as well as a 64-bit multicast
|
|
|
|
* filter.
|
|
|
|
*
|
|
|
|
* The 8129 chip is an older version of the 8139 that uses an external PHY
|
|
|
|
* chip. The 8129 has a serial MDIO interface for accessing the MII where
|
|
|
|
* the 8139 lets you directly access the on-board PHY registers. We need
|
|
|
|
* to select which interface to use depending on the chip type.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "bpfilter.h"
|
|
|
|
#include "rnd.h"
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/callout.h>
|
|
|
|
#include <sys/device.h>
|
|
|
|
#include <sys/sockio.h>
|
|
|
|
#include <sys/mbuf.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
|
2000-11-14 21:21:00 +03:00
|
|
|
#include <uvm/uvm_extern.h>
|
|
|
|
|
2000-04-10 11:42:55 +04:00
|
|
|
#include <net/if.h>
|
|
|
|
#include <net/if_arp.h>
|
|
|
|
#include <net/if_ether.h>
|
|
|
|
#include <net/if_dl.h>
|
|
|
|
#include <net/if_media.h>
|
|
|
|
|
|
|
|
#if NBPFILTER > 0
|
|
|
|
#include <net/bpf.h>
|
|
|
|
#endif
|
|
|
|
#if NRND > 0
|
|
|
|
#include <sys/rnd.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <machine/bus.h>
|
2000-04-25 18:16:46 +04:00
|
|
|
#include <machine/endian.h>
|
2000-04-10 11:42:55 +04:00
|
|
|
|
|
|
|
#include <dev/mii/mii.h>
|
|
|
|
#include <dev/mii/miivar.h>
|
|
|
|
|
|
|
|
#include <dev/ic/rtl81x9reg.h>
|
2000-04-26 18:02:34 +04:00
|
|
|
#include <dev/ic/rtl81x9var.h>
|
2000-04-10 11:42:55 +04:00
|
|
|
|
2000-12-05 14:11:49 +03:00
|
|
|
#if defined(DEBUG)
|
2000-04-10 11:42:55 +04:00
|
|
|
#define STATIC
|
|
|
|
#else
|
|
|
|
#define STATIC static
|
|
|
|
#endif
|
|
|
|
|
2000-05-15 05:55:12 +04:00
|
|
|
STATIC void rtk_reset __P((struct rtk_softc *));
|
|
|
|
STATIC void rtk_rxeof __P((struct rtk_softc *));
|
|
|
|
STATIC void rtk_txeof __P((struct rtk_softc *));
|
|
|
|
STATIC void rtk_start __P((struct ifnet *));
|
|
|
|
STATIC int rtk_ioctl __P((struct ifnet *, u_long, caddr_t));
|
2000-10-11 20:57:45 +04:00
|
|
|
STATIC int rtk_init __P((struct ifnet *));
|
|
|
|
STATIC void rtk_stop __P((struct ifnet *, int));
|
|
|
|
|
2000-05-19 17:42:29 +04:00
|
|
|
STATIC void rtk_watchdog __P((struct ifnet *));
|
|
|
|
STATIC void rtk_shutdown __P((void *));
|
2000-05-15 05:55:12 +04:00
|
|
|
STATIC int rtk_ifmedia_upd __P((struct ifnet *));
|
|
|
|
STATIC void rtk_ifmedia_sts __P((struct ifnet *, struct ifmediareq *));
|
2000-04-10 11:42:55 +04:00
|
|
|
|
2000-05-15 05:55:12 +04:00
|
|
|
STATIC u_int16_t rtk_read_eeprom __P((struct rtk_softc *, int, int));
|
|
|
|
STATIC void rtk_eeprom_putbyte __P((struct rtk_softc *, int, int));
|
2000-05-19 17:42:29 +04:00
|
|
|
STATIC void rtk_mii_sync __P((struct rtk_softc *));
|
|
|
|
STATIC void rtk_mii_send __P((struct rtk_softc *, u_int32_t, int));
|
2000-05-15 05:55:12 +04:00
|
|
|
STATIC int rtk_mii_readreg __P((struct rtk_softc *, struct rtk_mii_frame *));
|
|
|
|
STATIC int rtk_mii_writereg __P((struct rtk_softc *, struct rtk_mii_frame *));
|
2000-04-10 11:42:55 +04:00
|
|
|
|
2000-05-15 05:55:12 +04:00
|
|
|
STATIC int rtk_phy_readreg __P((struct device *, int, int));
|
|
|
|
STATIC void rtk_phy_writereg __P((struct device *, int, int, int));
|
|
|
|
STATIC void rtk_phy_statchg __P((struct device *));
|
2000-05-19 17:42:29 +04:00
|
|
|
STATIC void rtk_tick __P((void *));
|
2000-04-10 11:42:55 +04:00
|
|
|
|
2000-05-19 17:42:29 +04:00
|
|
|
STATIC int rtk_enable __P((struct rtk_softc *));
|
|
|
|
STATIC void rtk_disable __P((struct rtk_softc *));
|
|
|
|
STATIC void rtk_power __P((int, void *));
|
|
|
|
|
|
|
|
STATIC void rtk_setmulti __P((struct rtk_softc *));
|
2000-05-15 05:55:12 +04:00
|
|
|
STATIC int rtk_list_tx_init __P((struct rtk_softc *));
|
2000-04-10 11:42:55 +04:00
|
|
|
|
|
|
|
#define EE_SET(x) \
|
2000-05-19 17:42:29 +04:00
|
|
|
CSR_WRITE_1(sc, RTK_EECMD, \
|
|
|
|
CSR_READ_1(sc, RTK_EECMD) | (x))
|
2000-04-10 11:42:55 +04:00
|
|
|
|
|
|
|
#define EE_CLR(x) \
|
2000-05-19 17:42:29 +04:00
|
|
|
CSR_WRITE_1(sc, RTK_EECMD, \
|
|
|
|
CSR_READ_1(sc, RTK_EECMD) & ~(x))
|
2000-04-10 11:42:55 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Send a read command and address to the EEPROM, check for ACK.
|
|
|
|
*/
|
2000-05-15 05:55:12 +04:00
|
|
|
STATIC void rtk_eeprom_putbyte(sc, addr, addr_len)
|
2000-05-19 17:42:29 +04:00
|
|
|
struct rtk_softc *sc;
|
2000-04-30 16:00:40 +04:00
|
|
|
int addr, addr_len;
|
2000-04-10 11:42:55 +04:00
|
|
|
{
|
2000-04-24 19:25:00 +04:00
|
|
|
int d, i;
|
2000-04-10 11:42:55 +04:00
|
|
|
|
2000-05-19 17:42:29 +04:00
|
|
|
d = (RTK_EECMD_READ << addr_len) | addr;
|
2000-04-10 11:42:55 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Feed in each bit and stobe the clock.
|
|
|
|
*/
|
2000-12-05 14:11:49 +03:00
|
|
|
for (i = RTK_EECMD_LEN + addr_len; i > 0; i--) {
|
|
|
|
if (d & (1 << (i - 1))) {
|
2000-05-19 17:42:29 +04:00
|
|
|
EE_SET(RTK_EE_DATAIN);
|
2000-04-10 11:42:55 +04:00
|
|
|
} else {
|
2000-05-19 17:42:29 +04:00
|
|
|
EE_CLR(RTK_EE_DATAIN);
|
2000-04-10 11:42:55 +04:00
|
|
|
}
|
2000-12-05 14:11:49 +03:00
|
|
|
DELAY(4);
|
2000-05-19 17:42:29 +04:00
|
|
|
EE_SET(RTK_EE_CLK);
|
2000-12-05 14:11:49 +03:00
|
|
|
DELAY(4);
|
2000-05-19 17:42:29 +04:00
|
|
|
EE_CLR(RTK_EE_CLK);
|
2000-12-05 14:11:49 +03:00
|
|
|
DELAY(4);
|
2000-04-10 11:42:55 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Read a word of data stored in the EEPROM at address 'addr.'
|
|
|
|
*/
|
2000-05-15 05:55:12 +04:00
|
|
|
u_int16_t rtk_read_eeprom(sc, addr, addr_len)
|
2000-05-19 17:42:29 +04:00
|
|
|
struct rtk_softc *sc;
|
2000-04-30 16:00:40 +04:00
|
|
|
int addr, addr_len;
|
2000-04-10 11:42:55 +04:00
|
|
|
{
|
|
|
|
u_int16_t word = 0;
|
2000-04-30 16:00:40 +04:00
|
|
|
int i;
|
2000-04-10 11:42:55 +04:00
|
|
|
|
|
|
|
/* Enter EEPROM access mode. */
|
2000-05-19 17:42:29 +04:00
|
|
|
CSR_WRITE_1(sc, RTK_EECMD, RTK_EEMODE_PROGRAM|RTK_EE_SEL);
|
2000-04-10 11:42:55 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Send address of word we want to read.
|
|
|
|
*/
|
2000-05-15 05:55:12 +04:00
|
|
|
rtk_eeprom_putbyte(sc, addr, addr_len);
|
2000-04-10 11:42:55 +04:00
|
|
|
|
2000-05-19 17:42:29 +04:00
|
|
|
CSR_WRITE_1(sc, RTK_EECMD, RTK_EEMODE_PROGRAM|RTK_EE_SEL);
|
2000-04-10 11:42:55 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Start reading bits from EEPROM.
|
|
|
|
*/
|
2000-12-05 14:11:49 +03:00
|
|
|
for (i = 16; i > 0; i--) {
|
2000-05-19 17:42:29 +04:00
|
|
|
EE_SET(RTK_EE_CLK);
|
2000-12-05 14:11:49 +03:00
|
|
|
DELAY(4);
|
2000-05-19 17:42:29 +04:00
|
|
|
if (CSR_READ_1(sc, RTK_EECMD) & RTK_EE_DATAOUT)
|
2000-12-05 14:11:49 +03:00
|
|
|
word |= 1 << (i - 1);
|
2000-05-19 17:42:29 +04:00
|
|
|
EE_CLR(RTK_EE_CLK);
|
2000-12-05 14:11:49 +03:00
|
|
|
DELAY(4);
|
2000-04-10 11:42:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Turn off EEPROM access mode. */
|
2000-05-19 17:42:29 +04:00
|
|
|
CSR_WRITE_1(sc, RTK_EECMD, RTK_EEMODE_OFF);
|
2000-04-10 11:42:55 +04:00
|
|
|
|
2000-04-30 16:00:40 +04:00
|
|
|
return (word);
|
2000-04-10 11:42:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* MII access routines are provided for the 8129, which
|
|
|
|
* doesn't have a built-in PHY. For the 8139, we fake things
|
2000-05-15 05:55:12 +04:00
|
|
|
* up by diverting rtk_phy_readreg()/rtk_phy_writereg() to the
|
2000-04-10 11:42:55 +04:00
|
|
|
* direct access PHY registers.
|
|
|
|
*/
|
|
|
|
#define MII_SET(x) \
|
2000-12-05 14:11:49 +03:00
|
|
|
CSR_WRITE_1(sc, RTK_MII, \
|
2000-05-19 17:42:29 +04:00
|
|
|
CSR_READ_1(sc, RTK_MII) | (x))
|
2000-04-10 11:42:55 +04:00
|
|
|
|
|
|
|
#define MII_CLR(x) \
|
2000-12-05 14:11:49 +03:00
|
|
|
CSR_WRITE_1(sc, RTK_MII, \
|
2000-05-19 17:42:29 +04:00
|
|
|
CSR_READ_1(sc, RTK_MII) & ~(x))
|
2000-04-10 11:42:55 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Sync the PHYs by setting data bit and strobing the clock 32 times.
|
|
|
|
*/
|
2000-05-15 05:55:12 +04:00
|
|
|
STATIC void rtk_mii_sync(sc)
|
2000-05-19 17:42:29 +04:00
|
|
|
struct rtk_softc *sc;
|
2000-04-10 11:42:55 +04:00
|
|
|
{
|
2000-04-24 19:25:00 +04:00
|
|
|
int i;
|
2000-04-10 11:42:55 +04:00
|
|
|
|
2000-05-19 17:42:29 +04:00
|
|
|
MII_SET(RTK_MII_DIR|RTK_MII_DATAOUT);
|
2000-04-10 11:42:55 +04:00
|
|
|
|
|
|
|
for (i = 0; i < 32; i++) {
|
2000-05-19 17:42:29 +04:00
|
|
|
MII_SET(RTK_MII_CLK);
|
2000-04-10 11:42:55 +04:00
|
|
|
DELAY(1);
|
2000-05-19 17:42:29 +04:00
|
|
|
MII_CLR(RTK_MII_CLK);
|
2000-04-10 11:42:55 +04:00
|
|
|
DELAY(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Clock a series of bits through the MII.
|
|
|
|
*/
|
2000-05-15 05:55:12 +04:00
|
|
|
STATIC void rtk_mii_send(sc, bits, cnt)
|
2000-05-19 17:42:29 +04:00
|
|
|
struct rtk_softc *sc;
|
2000-04-10 11:42:55 +04:00
|
|
|
u_int32_t bits;
|
|
|
|
int cnt;
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2000-05-19 17:42:29 +04:00
|
|
|
MII_CLR(RTK_MII_CLK);
|
2000-04-10 11:42:55 +04:00
|
|
|
|
2000-12-05 14:11:49 +03:00
|
|
|
for (i = cnt; i > 0; i--) {
|
|
|
|
if (bits & (1 << (i - 1))) {
|
2000-05-19 17:42:29 +04:00
|
|
|
MII_SET(RTK_MII_DATAOUT);
|
2000-04-10 11:42:55 +04:00
|
|
|
} else {
|
2000-05-19 17:42:29 +04:00
|
|
|
MII_CLR(RTK_MII_DATAOUT);
|
2000-04-10 11:42:55 +04:00
|
|
|
}
|
|
|
|
DELAY(1);
|
2000-05-19 17:42:29 +04:00
|
|
|
MII_CLR(RTK_MII_CLK);
|
2000-04-10 11:42:55 +04:00
|
|
|
DELAY(1);
|
2000-05-19 17:42:29 +04:00
|
|
|
MII_SET(RTK_MII_CLK);
|
2000-04-10 11:42:55 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Read an PHY register through the MII.
|
|
|
|
*/
|
2000-05-15 05:55:12 +04:00
|
|
|
STATIC int rtk_mii_readreg(sc, frame)
|
2000-05-19 17:42:29 +04:00
|
|
|
struct rtk_softc *sc;
|
2000-05-15 05:55:12 +04:00
|
|
|
struct rtk_mii_frame *frame;
|
2000-04-10 11:42:55 +04:00
|
|
|
{
|
|
|
|
int i, ack, s;
|
|
|
|
|
2000-05-15 05:55:53 +04:00
|
|
|
s = splnet();
|
2000-04-10 11:42:55 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Set up frame for RX.
|
|
|
|
*/
|
2000-05-19 17:42:29 +04:00
|
|
|
frame->mii_stdelim = RTK_MII_STARTDELIM;
|
|
|
|
frame->mii_opcode = RTK_MII_READOP;
|
2000-04-10 11:42:55 +04:00
|
|
|
frame->mii_turnaround = 0;
|
|
|
|
frame->mii_data = 0;
|
2000-12-05 14:11:49 +03:00
|
|
|
|
2000-05-19 17:42:29 +04:00
|
|
|
CSR_WRITE_2(sc, RTK_MII, 0);
|
2000-04-10 11:42:55 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Turn on data xmit.
|
|
|
|
*/
|
2000-05-19 17:42:29 +04:00
|
|
|
MII_SET(RTK_MII_DIR);
|
2000-04-10 11:42:55 +04:00
|
|
|
|
2000-05-15 05:55:12 +04:00
|
|
|
rtk_mii_sync(sc);
|
2000-04-10 11:42:55 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Send command/address info.
|
|
|
|
*/
|
2000-05-15 05:55:12 +04:00
|
|
|
rtk_mii_send(sc, frame->mii_stdelim, 2);
|
|
|
|
rtk_mii_send(sc, frame->mii_opcode, 2);
|
|
|
|
rtk_mii_send(sc, frame->mii_phyaddr, 5);
|
|
|
|
rtk_mii_send(sc, frame->mii_regaddr, 5);
|
2000-04-10 11:42:55 +04:00
|
|
|
|
|
|
|
/* Idle bit */
|
2000-05-19 17:42:29 +04:00
|
|
|
MII_CLR((RTK_MII_CLK|RTK_MII_DATAOUT));
|
2000-04-10 11:42:55 +04:00
|
|
|
DELAY(1);
|
2000-05-19 17:42:29 +04:00
|
|
|
MII_SET(RTK_MII_CLK);
|
2000-04-10 11:42:55 +04:00
|
|
|
DELAY(1);
|
|
|
|
|
|
|
|
/* Turn off xmit. */
|
2000-05-19 17:42:29 +04:00
|
|
|
MII_CLR(RTK_MII_DIR);
|
2000-04-10 11:42:55 +04:00
|
|
|
|
|
|
|
/* Check for ack */
|
2000-05-19 17:42:29 +04:00
|
|
|
MII_CLR(RTK_MII_CLK);
|
2000-04-10 11:42:55 +04:00
|
|
|
DELAY(1);
|
2000-05-19 17:42:29 +04:00
|
|
|
MII_SET(RTK_MII_CLK);
|
2000-04-10 11:42:55 +04:00
|
|
|
DELAY(1);
|
2000-05-19 17:42:29 +04:00
|
|
|
ack = CSR_READ_2(sc, RTK_MII) & RTK_MII_DATAIN;
|
2000-04-10 11:42:55 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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) {
|
2000-12-05 14:11:49 +03:00
|
|
|
for (i = 0; i < 16; i++) {
|
2000-05-19 17:42:29 +04:00
|
|
|
MII_CLR(RTK_MII_CLK);
|
2000-04-10 11:42:55 +04:00
|
|
|
DELAY(1);
|
2000-05-19 17:42:29 +04:00
|
|
|
MII_SET(RTK_MII_CLK);
|
2000-04-10 11:42:55 +04:00
|
|
|
DELAY(1);
|
|
|
|
}
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2000-12-05 14:11:49 +03:00
|
|
|
for (i = 16; i > 0; i--) {
|
2000-05-19 17:42:29 +04:00
|
|
|
MII_CLR(RTK_MII_CLK);
|
2000-04-10 11:42:55 +04:00
|
|
|
DELAY(1);
|
|
|
|
if (!ack) {
|
2000-05-19 17:42:29 +04:00
|
|
|
if (CSR_READ_2(sc, RTK_MII) & RTK_MII_DATAIN)
|
2000-12-05 14:11:49 +03:00
|
|
|
frame->mii_data |= 1 << (i - 1);
|
2000-04-10 11:42:55 +04:00
|
|
|
DELAY(1);
|
|
|
|
}
|
2000-05-19 17:42:29 +04:00
|
|
|
MII_SET(RTK_MII_CLK);
|
2000-04-10 11:42:55 +04:00
|
|
|
DELAY(1);
|
|
|
|
}
|
|
|
|
|
2000-12-05 14:11:49 +03:00
|
|
|
fail:
|
2000-05-19 17:42:29 +04:00
|
|
|
MII_CLR(RTK_MII_CLK);
|
2000-04-10 11:42:55 +04:00
|
|
|
DELAY(1);
|
2000-05-19 17:42:29 +04:00
|
|
|
MII_SET(RTK_MII_CLK);
|
2000-04-10 11:42:55 +04:00
|
|
|
DELAY(1);
|
|
|
|
|
|
|
|
splx(s);
|
|
|
|
|
|
|
|
if (ack)
|
2000-12-05 14:11:49 +03:00
|
|
|
return (1);
|
|
|
|
return (0);
|
2000-04-10 11:42:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Write to a PHY register through the MII.
|
|
|
|
*/
|
2000-05-15 05:55:12 +04:00
|
|
|
STATIC int rtk_mii_writereg(sc, frame)
|
2000-05-19 17:42:29 +04:00
|
|
|
struct rtk_softc *sc;
|
2000-05-15 05:55:12 +04:00
|
|
|
struct rtk_mii_frame *frame;
|
2000-04-10 11:42:55 +04:00
|
|
|
{
|
|
|
|
int s;
|
|
|
|
|
2000-05-15 05:55:53 +04:00
|
|
|
s = splnet();
|
2000-04-10 11:42:55 +04:00
|
|
|
/*
|
|
|
|
* Set up frame for TX.
|
|
|
|
*/
|
2000-05-19 17:42:29 +04:00
|
|
|
frame->mii_stdelim = RTK_MII_STARTDELIM;
|
|
|
|
frame->mii_opcode = RTK_MII_WRITEOP;
|
|
|
|
frame->mii_turnaround = RTK_MII_TURNAROUND;
|
2000-04-10 11:42:55 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Turn on data output.
|
|
|
|
*/
|
2000-05-19 17:42:29 +04:00
|
|
|
MII_SET(RTK_MII_DIR);
|
2000-04-10 11:42:55 +04:00
|
|
|
|
2000-05-15 05:55:12 +04:00
|
|
|
rtk_mii_sync(sc);
|
2000-04-10 11:42:55 +04:00
|
|
|
|
2000-05-15 05:55:12 +04:00
|
|
|
rtk_mii_send(sc, frame->mii_stdelim, 2);
|
|
|
|
rtk_mii_send(sc, frame->mii_opcode, 2);
|
|
|
|
rtk_mii_send(sc, frame->mii_phyaddr, 5);
|
|
|
|
rtk_mii_send(sc, frame->mii_regaddr, 5);
|
|
|
|
rtk_mii_send(sc, frame->mii_turnaround, 2);
|
|
|
|
rtk_mii_send(sc, frame->mii_data, 16);
|
2000-04-10 11:42:55 +04:00
|
|
|
|
|
|
|
/* Idle bit. */
|
2000-05-19 17:42:29 +04:00
|
|
|
MII_SET(RTK_MII_CLK);
|
2000-04-10 11:42:55 +04:00
|
|
|
DELAY(1);
|
2000-05-19 17:42:29 +04:00
|
|
|
MII_CLR(RTK_MII_CLK);
|
2000-04-10 11:42:55 +04:00
|
|
|
DELAY(1);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Turn off xmit.
|
|
|
|
*/
|
2000-05-19 17:42:29 +04:00
|
|
|
MII_CLR(RTK_MII_DIR);
|
2000-04-10 11:42:55 +04:00
|
|
|
|
|
|
|
splx(s);
|
|
|
|
|
2000-12-05 14:11:49 +03:00
|
|
|
return (0);
|
2000-04-10 11:42:55 +04:00
|
|
|
}
|
|
|
|
|
2000-05-15 05:55:12 +04:00
|
|
|
STATIC int rtk_phy_readreg(self, phy, reg)
|
2000-04-10 11:42:55 +04:00
|
|
|
struct device *self;
|
|
|
|
int phy, reg;
|
|
|
|
{
|
2000-05-19 17:42:29 +04:00
|
|
|
struct rtk_softc *sc = (void *)self;
|
2000-05-15 05:55:12 +04:00
|
|
|
struct rtk_mii_frame frame;
|
2000-12-05 14:11:49 +03:00
|
|
|
int rval = 0;
|
|
|
|
int rtk8139_reg = 0;
|
2000-04-10 11:42:55 +04:00
|
|
|
|
2000-05-19 17:42:29 +04:00
|
|
|
if (sc->rtk_type == RTK_8139) {
|
2000-04-10 11:42:55 +04:00
|
|
|
if (phy != 7)
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
switch(reg) {
|
|
|
|
case MII_BMCR:
|
2000-05-19 17:42:29 +04:00
|
|
|
rtk8139_reg = RTK_BMCR;
|
2000-04-10 11:42:55 +04:00
|
|
|
break;
|
|
|
|
case MII_BMSR:
|
2000-05-19 17:42:29 +04:00
|
|
|
rtk8139_reg = RTK_BMSR;
|
2000-04-10 11:42:55 +04:00
|
|
|
break;
|
|
|
|
case MII_ANAR:
|
2000-05-19 17:42:29 +04:00
|
|
|
rtk8139_reg = RTK_ANAR;
|
2000-04-10 11:42:55 +04:00
|
|
|
break;
|
2000-09-01 19:07:23 +04:00
|
|
|
case MII_ANER:
|
|
|
|
rtk8139_reg = RTK_ANER;
|
|
|
|
break;
|
2000-04-10 11:42:55 +04:00
|
|
|
case MII_ANLPAR:
|
2000-05-19 17:42:29 +04:00
|
|
|
rtk8139_reg = RTK_LPAR;
|
2000-04-10 11:42:55 +04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
#if 0
|
|
|
|
printf("%s: bad phy register\n", sc->sc_dev.dv_xname);
|
|
|
|
#endif
|
2000-12-05 14:11:49 +03:00
|
|
|
return (0);
|
2000-04-10 11:42:55 +04:00
|
|
|
}
|
2000-05-19 17:42:29 +04:00
|
|
|
rval = CSR_READ_2(sc, rtk8139_reg);
|
2000-12-05 14:11:49 +03:00
|
|
|
return (rval);
|
2000-04-10 11:42:55 +04:00
|
|
|
}
|
|
|
|
|
2001-07-07 20:13:44 +04:00
|
|
|
memset((char *)&frame, 0, sizeof(frame));
|
2000-04-10 11:42:55 +04:00
|
|
|
|
|
|
|
frame.mii_phyaddr = phy;
|
|
|
|
frame.mii_regaddr = reg;
|
2000-05-15 05:55:12 +04:00
|
|
|
rtk_mii_readreg(sc, &frame);
|
2000-04-10 11:42:55 +04:00
|
|
|
|
2000-12-05 14:11:49 +03:00
|
|
|
return (frame.mii_data);
|
2000-04-10 11:42:55 +04:00
|
|
|
}
|
|
|
|
|
2000-05-15 05:55:12 +04:00
|
|
|
STATIC void rtk_phy_writereg(self, phy, reg, data)
|
2000-04-10 11:42:55 +04:00
|
|
|
struct device *self;
|
|
|
|
int phy, reg;
|
|
|
|
int data;
|
|
|
|
{
|
2000-05-19 17:42:29 +04:00
|
|
|
struct rtk_softc *sc = (void *)self;
|
2000-05-15 05:55:12 +04:00
|
|
|
struct rtk_mii_frame frame;
|
2000-12-05 14:11:49 +03:00
|
|
|
int rtk8139_reg = 0;
|
2000-04-10 11:42:55 +04:00
|
|
|
|
2000-05-19 17:42:29 +04:00
|
|
|
if (sc->rtk_type == RTK_8139) {
|
2000-04-10 11:42:55 +04:00
|
|
|
if (phy != 7)
|
|
|
|
return;
|
|
|
|
|
|
|
|
switch(reg) {
|
|
|
|
case MII_BMCR:
|
2000-05-19 17:42:29 +04:00
|
|
|
rtk8139_reg = RTK_BMCR;
|
2000-04-10 11:42:55 +04:00
|
|
|
break;
|
|
|
|
case MII_BMSR:
|
2000-05-19 17:42:29 +04:00
|
|
|
rtk8139_reg = RTK_BMSR;
|
2000-04-10 11:42:55 +04:00
|
|
|
break;
|
|
|
|
case MII_ANAR:
|
2000-05-19 17:42:29 +04:00
|
|
|
rtk8139_reg = RTK_ANAR;
|
2000-04-10 11:42:55 +04:00
|
|
|
break;
|
2000-09-01 19:07:23 +04:00
|
|
|
case MII_ANER:
|
|
|
|
rtk8139_reg = RTK_ANER;
|
|
|
|
break;
|
2000-04-10 11:42:55 +04:00
|
|
|
case MII_ANLPAR:
|
2000-05-19 17:42:29 +04:00
|
|
|
rtk8139_reg = RTK_LPAR;
|
2000-04-10 11:42:55 +04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
#if 0
|
|
|
|
printf("%s: bad phy register\n", sc->sc_dev.dv_xname);
|
|
|
|
#endif
|
|
|
|
return;
|
|
|
|
}
|
2000-05-19 17:42:29 +04:00
|
|
|
CSR_WRITE_2(sc, rtk8139_reg, data);
|
2000-04-10 11:42:55 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-07-07 20:13:44 +04:00
|
|
|
memset((char *)&frame, 0, sizeof(frame));
|
2000-04-10 11:42:55 +04:00
|
|
|
|
|
|
|
frame.mii_phyaddr = phy;
|
|
|
|
frame.mii_regaddr = reg;
|
|
|
|
frame.mii_data = data;
|
|
|
|
|
2000-05-15 05:55:12 +04:00
|
|
|
rtk_mii_writereg(sc, &frame);
|
2000-04-10 11:42:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
STATIC void
|
2000-05-15 05:55:12 +04:00
|
|
|
rtk_phy_statchg(v)
|
2000-04-10 11:42:55 +04:00
|
|
|
struct device *v;
|
|
|
|
{
|
|
|
|
|
|
|
|
/* Nothing to do. */
|
|
|
|
}
|
|
|
|
|
2000-05-15 05:55:12 +04:00
|
|
|
#define rtk_calchash(addr) \
|
2000-05-12 20:44:19 +04:00
|
|
|
(ether_crc32_be((addr), ETHER_ADDR_LEN) >> 26)
|
2000-04-10 11:42:55 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Program the 64-bit multicast hash filter.
|
|
|
|
*/
|
2000-05-15 05:55:12 +04:00
|
|
|
STATIC void rtk_setmulti(sc)
|
2000-05-19 17:42:29 +04:00
|
|
|
struct rtk_softc *sc;
|
2000-04-10 11:42:55 +04:00
|
|
|
{
|
|
|
|
struct ifnet *ifp;
|
|
|
|
int h = 0;
|
|
|
|
u_int32_t hashes[2] = { 0, 0 };
|
|
|
|
u_int32_t rxfilt;
|
|
|
|
int mcnt = 0;
|
|
|
|
struct ether_multi *enm;
|
|
|
|
struct ether_multistep step;
|
|
|
|
|
|
|
|
ifp = &sc->ethercom.ec_if;
|
|
|
|
|
2000-05-19 17:42:29 +04:00
|
|
|
rxfilt = CSR_READ_4(sc, RTK_RXCFG);
|
2000-04-10 11:42:55 +04:00
|
|
|
|
2001-01-29 04:24:42 +03:00
|
|
|
if (ifp->if_flags & IFF_PROMISC) {
|
|
|
|
allmulti:
|
|
|
|
ifp->if_flags |= IFF_ALLMULTI;
|
2000-05-19 17:42:29 +04:00
|
|
|
rxfilt |= RTK_RXCFG_RX_MULTI;
|
|
|
|
CSR_WRITE_4(sc, RTK_RXCFG, rxfilt);
|
|
|
|
CSR_WRITE_4(sc, RTK_MAR0, 0xFFFFFFFF);
|
|
|
|
CSR_WRITE_4(sc, RTK_MAR4, 0xFFFFFFFF);
|
2000-04-10 11:42:55 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* first, zot all the existing hash bits */
|
2000-05-19 17:42:29 +04:00
|
|
|
CSR_WRITE_4(sc, RTK_MAR0, 0);
|
|
|
|
CSR_WRITE_4(sc, RTK_MAR4, 0);
|
2000-04-10 11:42:55 +04:00
|
|
|
|
|
|
|
/* now program new ones */
|
|
|
|
ETHER_FIRST_MULTI(step, &sc->ethercom, enm);
|
|
|
|
while (enm != NULL) {
|
2000-04-26 18:02:34 +04:00
|
|
|
if (memcmp(enm->enm_addrlo, enm->enm_addrhi,
|
|
|
|
ETHER_ADDR_LEN) != 0)
|
2001-01-29 04:24:42 +03:00
|
|
|
goto allmulti;
|
2000-04-26 18:02:34 +04:00
|
|
|
|
2000-05-15 05:55:12 +04:00
|
|
|
h = rtk_calchash(enm->enm_addrlo);
|
2000-04-10 11:42:55 +04:00
|
|
|
if (h < 32)
|
|
|
|
hashes[0] |= (1 << h);
|
|
|
|
else
|
|
|
|
hashes[1] |= (1 << (h - 32));
|
|
|
|
mcnt++;
|
|
|
|
ETHER_NEXT_MULTI(step, enm);
|
|
|
|
}
|
|
|
|
|
2001-01-29 04:24:42 +03:00
|
|
|
ifp->if_flags &= ~IFF_ALLMULTI;
|
|
|
|
|
2000-04-10 11:42:55 +04:00
|
|
|
if (mcnt)
|
2000-05-19 17:42:29 +04:00
|
|
|
rxfilt |= RTK_RXCFG_RX_MULTI;
|
2000-04-10 11:42:55 +04:00
|
|
|
else
|
2000-05-19 17:42:29 +04:00
|
|
|
rxfilt &= ~RTK_RXCFG_RX_MULTI;
|
2000-04-10 11:42:55 +04:00
|
|
|
|
2000-05-19 17:42:29 +04:00
|
|
|
CSR_WRITE_4(sc, RTK_RXCFG, rxfilt);
|
|
|
|
CSR_WRITE_4(sc, RTK_MAR0, hashes[0]);
|
|
|
|
CSR_WRITE_4(sc, RTK_MAR4, hashes[1]);
|
2000-04-10 11:42:55 +04:00
|
|
|
}
|
|
|
|
|
2000-05-15 05:55:12 +04:00
|
|
|
void rtk_reset(sc)
|
2000-05-19 17:42:29 +04:00
|
|
|
struct rtk_softc *sc;
|
2000-04-10 11:42:55 +04:00
|
|
|
{
|
2000-04-24 19:25:00 +04:00
|
|
|
int i;
|
2000-04-10 11:42:55 +04:00
|
|
|
|
2000-05-19 17:42:29 +04:00
|
|
|
CSR_WRITE_1(sc, RTK_COMMAND, RTK_CMD_RESET);
|
2000-04-10 11:42:55 +04:00
|
|
|
|
2000-05-19 17:42:29 +04:00
|
|
|
for (i = 0; i < RTK_TIMEOUT; i++) {
|
2000-04-10 11:42:55 +04:00
|
|
|
DELAY(10);
|
2000-12-05 14:11:49 +03:00
|
|
|
if ((CSR_READ_1(sc, RTK_COMMAND) & RTK_CMD_RESET) == 0)
|
2000-04-10 11:42:55 +04:00
|
|
|
break;
|
|
|
|
}
|
2000-05-19 17:42:29 +04:00
|
|
|
if (i == RTK_TIMEOUT)
|
2000-04-10 11:42:55 +04:00
|
|
|
printf("%s: reset never completed!\n", sc->sc_dev.dv_xname);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Attach the interface. Allocate softc structures, do ifmedia
|
|
|
|
* setup and ethernet/BPF attach.
|
|
|
|
*/
|
|
|
|
void
|
2000-05-15 05:55:12 +04:00
|
|
|
rtk_attach(sc)
|
|
|
|
struct rtk_softc *sc;
|
2000-04-10 11:42:55 +04:00
|
|
|
{
|
|
|
|
struct ifnet *ifp;
|
2001-02-02 07:34:19 +03:00
|
|
|
struct rtk_tx_desc *txd;
|
2000-05-01 19:08:50 +04:00
|
|
|
u_int16_t val;
|
|
|
|
u_int8_t eaddr[ETHER_ADDR_LEN];
|
2000-05-19 17:42:29 +04:00
|
|
|
int error;
|
2000-12-05 14:11:49 +03:00
|
|
|
int i, addr_len;
|
2000-04-10 11:42:55 +04:00
|
|
|
|
2000-05-15 05:55:12 +04:00
|
|
|
callout_init(&sc->rtk_tick_ch);
|
2000-04-10 11:42:55 +04:00
|
|
|
|
2000-05-01 19:08:50 +04:00
|
|
|
/*
|
|
|
|
* Check EEPROM type 9346 or 9356.
|
|
|
|
*/
|
2000-05-19 17:42:29 +04:00
|
|
|
if (rtk_read_eeprom(sc, RTK_EE_ID, RTK_EEADDR_LEN1) == 0x8129)
|
|
|
|
addr_len = RTK_EEADDR_LEN1;
|
2000-05-01 19:08:50 +04:00
|
|
|
else
|
2000-05-19 17:42:29 +04:00
|
|
|
addr_len = RTK_EEADDR_LEN0;
|
2000-05-01 19:08:50 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Get station address.
|
|
|
|
*/
|
2000-05-19 17:42:29 +04:00
|
|
|
val = rtk_read_eeprom(sc, RTK_EE_EADDR0, addr_len);
|
2000-05-01 19:08:50 +04:00
|
|
|
eaddr[0] = val & 0xff;
|
|
|
|
eaddr[1] = val >> 8;
|
2000-05-19 17:42:29 +04:00
|
|
|
val = rtk_read_eeprom(sc, RTK_EE_EADDR1, addr_len);
|
2000-05-01 19:08:50 +04:00
|
|
|
eaddr[2] = val & 0xff;
|
|
|
|
eaddr[3] = val >> 8;
|
2000-05-19 17:42:29 +04:00
|
|
|
val = rtk_read_eeprom(sc, RTK_EE_EADDR2, addr_len);
|
2000-05-01 19:08:50 +04:00
|
|
|
eaddr[4] = val & 0xff;
|
|
|
|
eaddr[5] = val >> 8;
|
|
|
|
|
2000-04-10 11:42:55 +04:00
|
|
|
if ((error = bus_dmamem_alloc(sc->sc_dmat,
|
2000-12-05 14:11:49 +03:00
|
|
|
RTK_RXBUFLEN + 16, PAGE_SIZE, 0, &sc->sc_dmaseg, 1, &sc->sc_dmanseg,
|
2000-04-10 11:42:55 +04:00
|
|
|
BUS_DMA_NOWAIT)) != 0) {
|
|
|
|
printf("%s: can't allocate recv buffer, error = %d\n",
|
|
|
|
sc->sc_dev.dv_xname, error);
|
2000-05-19 17:42:29 +04:00
|
|
|
goto fail_0;
|
2000-04-10 11:42:55 +04:00
|
|
|
}
|
|
|
|
|
2000-05-19 17:42:29 +04:00
|
|
|
if ((error = bus_dmamem_map(sc->sc_dmat, &sc->sc_dmaseg, sc->sc_dmanseg,
|
2001-02-02 06:51:51 +03:00
|
|
|
RTK_RXBUFLEN + 16, (caddr_t *)&sc->rtk_rx_buf,
|
2000-04-10 11:42:55 +04:00
|
|
|
BUS_DMA_NOWAIT|BUS_DMA_COHERENT)) != 0) {
|
|
|
|
printf("%s: can't map recv buffer, error = %d\n",
|
|
|
|
sc->sc_dev.dv_xname, error);
|
2000-05-19 17:42:29 +04:00
|
|
|
goto fail_1;
|
2000-04-10 11:42:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((error = bus_dmamap_create(sc->sc_dmat,
|
2000-12-05 14:11:49 +03:00
|
|
|
RTK_RXBUFLEN + 16, 1, RTK_RXBUFLEN + 16, 0, BUS_DMA_NOWAIT,
|
2000-04-10 11:42:55 +04:00
|
|
|
&sc->recv_dmamap)) != 0) {
|
|
|
|
printf("%s: can't create recv buffer DMA map, error = %d\n",
|
|
|
|
sc->sc_dev.dv_xname, error);
|
2000-05-19 17:42:29 +04:00
|
|
|
goto fail_2;
|
2000-04-10 11:42:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((error = bus_dmamap_load(sc->sc_dmat, sc->recv_dmamap,
|
2001-02-02 06:51:51 +03:00
|
|
|
sc->rtk_rx_buf, RTK_RXBUFLEN + 16,
|
2001-07-19 20:25:23 +04:00
|
|
|
NULL, BUS_DMA_READ|BUS_DMA_NOWAIT)) != 0) {
|
2000-04-10 11:42:55 +04:00
|
|
|
printf("%s: can't load recv buffer DMA map, error = %d\n",
|
|
|
|
sc->sc_dev.dv_xname, error);
|
2000-05-19 17:42:29 +04:00
|
|
|
goto fail_3;
|
2000-04-10 11:42:55 +04:00
|
|
|
}
|
|
|
|
|
2001-02-02 07:34:19 +03:00
|
|
|
for (i = 0; i < RTK_TX_LIST_CNT; i++) {
|
|
|
|
txd = &sc->rtk_tx_descs[i];
|
2000-04-26 18:02:34 +04:00
|
|
|
if ((error = bus_dmamap_create(sc->sc_dmat,
|
2000-05-01 19:08:50 +04:00
|
|
|
MCLBYTES, 1, MCLBYTES, 0, BUS_DMA_NOWAIT,
|
2001-02-02 07:34:19 +03:00
|
|
|
&txd->txd_dmamap)) != 0) {
|
2000-04-26 18:02:34 +04:00
|
|
|
printf("%s: can't create snd buffer DMA map,"
|
|
|
|
" error = %d\n", sc->sc_dev.dv_xname, error);
|
2000-05-19 17:42:29 +04:00
|
|
|
goto fail_4;
|
2000-04-30 16:00:40 +04:00
|
|
|
}
|
2001-02-02 07:34:19 +03:00
|
|
|
txd->txd_txaddr = RTK_TXADDR0 + (i * 4);
|
|
|
|
txd->txd_txstat = RTK_TXSTAT0 + (i * 4);
|
|
|
|
}
|
|
|
|
SIMPLEQ_INIT(&sc->rtk_tx_free);
|
|
|
|
SIMPLEQ_INIT(&sc->rtk_tx_dirty);
|
|
|
|
|
2000-05-19 17:42:29 +04:00
|
|
|
/*
|
|
|
|
* From this point forward, the attachment cannot fail. A failure
|
|
|
|
* before this releases all resources thar may have been
|
|
|
|
* allocated.
|
|
|
|
*/
|
|
|
|
sc->sc_flags |= RTK_ATTACHED;
|
2000-04-10 11:42:55 +04:00
|
|
|
|
2001-07-25 13:57:31 +04:00
|
|
|
/* Init Early TX threshold. */
|
|
|
|
sc->sc_txthresh = TXTH_256;
|
|
|
|
|
2000-05-01 19:08:50 +04:00
|
|
|
/* Reset the adapter. */
|
2000-05-15 05:55:12 +04:00
|
|
|
rtk_reset(sc);
|
2000-05-01 19:08:50 +04:00
|
|
|
|
2000-12-05 14:11:49 +03:00
|
|
|
printf("%s: Ethernet address %s\n",
|
|
|
|
sc->sc_dev.dv_xname, ether_sprintf(eaddr));
|
2000-05-01 19:08:50 +04:00
|
|
|
|
2000-04-10 11:42:55 +04:00
|
|
|
ifp = &sc->ethercom.ec_if;
|
|
|
|
ifp->if_softc = sc;
|
2001-07-07 19:57:50 +04:00
|
|
|
strcpy(ifp->if_xname, sc->sc_dev.dv_xname);
|
2000-04-10 11:42:55 +04:00
|
|
|
ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
|
2000-05-15 05:55:12 +04:00
|
|
|
ifp->if_ioctl = rtk_ioctl;
|
|
|
|
ifp->if_start = rtk_start;
|
|
|
|
ifp->if_watchdog = rtk_watchdog;
|
2000-10-11 20:57:45 +04:00
|
|
|
ifp->if_init = rtk_init;
|
|
|
|
ifp->if_stop = rtk_stop;
|
2000-12-14 09:27:23 +03:00
|
|
|
IFQ_SET_READY(&ifp->if_snd);
|
2000-04-10 11:42:55 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Do ifmedia setup.
|
|
|
|
*/
|
|
|
|
sc->mii.mii_ifp = ifp;
|
2000-05-15 05:55:12 +04:00
|
|
|
sc->mii.mii_readreg = rtk_phy_readreg;
|
|
|
|
sc->mii.mii_writereg = rtk_phy_writereg;
|
|
|
|
sc->mii.mii_statchg = rtk_phy_statchg;
|
|
|
|
ifmedia_init(&sc->mii.mii_media, 0, rtk_ifmedia_upd, rtk_ifmedia_sts);
|
2000-04-10 11:42:55 +04:00
|
|
|
mii_attach(&sc->sc_dev, &sc->mii, 0xffffffff,
|
2000-12-05 14:11:49 +03:00
|
|
|
MII_PHY_ANY, MII_OFFSET_ANY, 0);
|
2000-04-10 11:42:55 +04:00
|
|
|
|
|
|
|
/* Choose a default media. */
|
|
|
|
if (LIST_FIRST(&sc->mii.mii_phys) == NULL) {
|
2000-05-19 17:42:29 +04:00
|
|
|
ifmedia_add(&sc->mii.mii_media, IFM_ETHER|IFM_NONE, 0, NULL);
|
2000-04-10 11:42:55 +04:00
|
|
|
ifmedia_set(&sc->mii.mii_media, IFM_ETHER|IFM_NONE);
|
|
|
|
} else {
|
|
|
|
ifmedia_set(&sc->mii.mii_media, IFM_ETHER|IFM_AUTO);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Call MI attach routines.
|
|
|
|
*/
|
|
|
|
if_attach(ifp);
|
|
|
|
ether_ifattach(ifp, eaddr);
|
|
|
|
|
2000-05-19 17:42:29 +04:00
|
|
|
/*
|
|
|
|
* Make sure the interface is shutdown during reboot.
|
|
|
|
*/
|
|
|
|
sc->sc_sdhook = shutdownhook_establish(rtk_shutdown, sc);
|
|
|
|
if (sc->sc_sdhook == NULL)
|
2001-08-07 06:59:53 +04:00
|
|
|
printf("%s: WARNING: unable to establish shutdown hook\n",
|
2000-12-05 14:11:49 +03:00
|
|
|
sc->sc_dev.dv_xname);
|
2000-05-19 17:42:29 +04:00
|
|
|
/*
|
|
|
|
* Add a suspend hook to make sure we come back up after a
|
|
|
|
* resume.
|
|
|
|
*/
|
|
|
|
sc->sc_powerhook = powerhook_establish(rtk_power, sc);
|
|
|
|
if (sc->sc_powerhook == NULL)
|
|
|
|
printf("%s: WARNING: unable to establish power hook\n",
|
2000-12-05 14:11:49 +03:00
|
|
|
sc->sc_dev.dv_xname);
|
2000-04-10 11:42:55 +04:00
|
|
|
|
2000-05-19 17:42:29 +04:00
|
|
|
return;
|
2000-12-05 14:11:49 +03:00
|
|
|
fail_4:
|
2001-02-02 07:34:19 +03:00
|
|
|
for (i = 0; i < RTK_TX_LIST_CNT; i++) {
|
|
|
|
txd = &sc->rtk_tx_descs[i];
|
|
|
|
if (txd->txd_dmamap != NULL)
|
|
|
|
bus_dmamap_destroy(sc->sc_dmat, txd->txd_dmamap);
|
|
|
|
}
|
2000-12-05 14:11:49 +03:00
|
|
|
fail_3:
|
2000-05-19 17:42:29 +04:00
|
|
|
bus_dmamap_destroy(sc->sc_dmat, sc->recv_dmamap);
|
2000-12-05 14:11:49 +03:00
|
|
|
fail_2:
|
2001-02-02 06:51:51 +03:00
|
|
|
bus_dmamem_unmap(sc->sc_dmat, (caddr_t)sc->rtk_rx_buf,
|
2000-12-05 14:11:49 +03:00
|
|
|
RTK_RXBUFLEN + 16);
|
|
|
|
fail_1:
|
2000-05-19 17:42:29 +04:00
|
|
|
bus_dmamem_free(sc->sc_dmat, &sc->sc_dmaseg, sc->sc_dmanseg);
|
2000-12-05 14:11:49 +03:00
|
|
|
fail_0:
|
2000-04-10 11:42:55 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize the transmit descriptors.
|
|
|
|
*/
|
2000-05-15 05:55:12 +04:00
|
|
|
STATIC int rtk_list_tx_init(sc)
|
2000-05-19 17:42:29 +04:00
|
|
|
struct rtk_softc *sc;
|
2000-04-10 11:42:55 +04:00
|
|
|
{
|
2001-02-02 07:34:19 +03:00
|
|
|
struct rtk_tx_desc *txd;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
while ((txd = SIMPLEQ_FIRST(&sc->rtk_tx_dirty)) != NULL)
|
|
|
|
SIMPLEQ_REMOVE_HEAD(&sc->rtk_tx_dirty, txd, txd_q);
|
|
|
|
while ((txd = SIMPLEQ_FIRST(&sc->rtk_tx_free)) != NULL)
|
|
|
|
SIMPLEQ_REMOVE_HEAD(&sc->rtk_tx_free, txd, txd_q);
|
2000-04-10 11:42:55 +04:00
|
|
|
|
2000-05-19 17:42:29 +04:00
|
|
|
for (i = 0; i < RTK_TX_LIST_CNT; i++) {
|
2001-02-02 07:34:19 +03:00
|
|
|
txd = &sc->rtk_tx_descs[i];
|
|
|
|
CSR_WRITE_4(sc, txd->txd_txaddr, 0);
|
|
|
|
SIMPLEQ_INSERT_TAIL(&sc->rtk_tx_free, txd, txd_q);
|
2000-04-10 11:42:55 +04:00
|
|
|
}
|
|
|
|
|
2000-12-05 14:11:49 +03:00
|
|
|
return (0);
|
2000-04-10 11:42:55 +04:00
|
|
|
}
|
|
|
|
|
2000-05-19 17:42:29 +04:00
|
|
|
/*
|
|
|
|
* rtk_activate:
|
|
|
|
* Handle device activation/deactivation requests.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
rtk_activate(self, act)
|
|
|
|
struct device *self;
|
|
|
|
enum devact act;
|
|
|
|
{
|
|
|
|
struct rtk_softc *sc = (void *) self;
|
|
|
|
int s, error = 0;
|
2000-12-05 14:11:49 +03:00
|
|
|
|
2000-05-19 17:42:29 +04:00
|
|
|
s = splnet();
|
|
|
|
switch (act) {
|
|
|
|
case DVACT_ACTIVATE:
|
|
|
|
error = EOPNOTSUPP;
|
|
|
|
break;
|
|
|
|
case DVACT_DEACTIVATE:
|
|
|
|
mii_activate(&sc->mii, act, MII_PHY_ANY, MII_OFFSET_ANY);
|
|
|
|
if_deactivate(&sc->ethercom.ec_if);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
splx(s);
|
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* rtk_detach:
|
|
|
|
* Detach a rtk interface.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
rtk_detach(sc)
|
|
|
|
struct rtk_softc *sc;
|
|
|
|
{
|
|
|
|
struct ifnet *ifp = &sc->ethercom.ec_if;
|
2001-02-02 07:34:19 +03:00
|
|
|
struct rtk_tx_desc *txd;
|
2000-05-19 17:42:29 +04:00
|
|
|
int i;
|
|
|
|
|
|
|
|
/*
|
2001-08-20 15:57:02 +04:00
|
|
|
* Succeed now if there isn't any work to do.
|
2000-05-19 17:42:29 +04:00
|
|
|
*/
|
|
|
|
if ((sc->sc_flags & RTK_ATTACHED) == 0)
|
|
|
|
return (0);
|
2000-12-05 14:11:49 +03:00
|
|
|
|
2000-05-19 17:42:29 +04:00
|
|
|
/* Unhook our tick handler. */
|
|
|
|
callout_stop(&sc->rtk_tick_ch);
|
|
|
|
|
|
|
|
/* Detach all PHYs. */
|
|
|
|
mii_detach(&sc->mii, MII_PHY_ANY, MII_OFFSET_ANY);
|
|
|
|
|
|
|
|
/* Delete all remaining media. */
|
|
|
|
ifmedia_delete_instance(&sc->mii.mii_media, IFM_INST_ANY);
|
|
|
|
|
|
|
|
ether_ifdetach(ifp);
|
|
|
|
if_detach(ifp);
|
|
|
|
|
2001-02-02 07:34:19 +03:00
|
|
|
for (i = 0; i < RTK_TX_LIST_CNT; i++) {
|
|
|
|
txd = &sc->rtk_tx_descs[i];
|
|
|
|
if (txd->txd_dmamap != NULL)
|
|
|
|
bus_dmamap_destroy(sc->sc_dmat, txd->txd_dmamap);
|
|
|
|
}
|
2000-05-19 17:42:29 +04:00
|
|
|
bus_dmamap_destroy(sc->sc_dmat, sc->recv_dmamap);
|
2001-02-02 06:51:51 +03:00
|
|
|
bus_dmamem_unmap(sc->sc_dmat, (caddr_t)sc->rtk_rx_buf,
|
2000-12-05 14:11:49 +03:00
|
|
|
RTK_RXBUFLEN + 16);
|
2000-12-09 05:02:20 +03:00
|
|
|
bus_dmamem_free(sc->sc_dmat, &sc->sc_dmaseg, sc->sc_dmanseg);
|
2000-05-19 17:42:29 +04:00
|
|
|
|
|
|
|
shutdownhook_disestablish(sc->sc_sdhook);
|
|
|
|
powerhook_disestablish(sc->sc_powerhook);
|
2000-12-05 14:11:49 +03:00
|
|
|
|
2000-05-19 17:42:29 +04:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* rtk_enable:
|
|
|
|
* Enable the RTL81X9 chip.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
rtk_enable(sc)
|
|
|
|
struct rtk_softc *sc;
|
|
|
|
{
|
2000-12-05 14:11:49 +03:00
|
|
|
|
2000-05-19 17:42:29 +04:00
|
|
|
if (RTK_IS_ENABLED(sc) == 0 && sc->sc_enable != NULL) {
|
|
|
|
if ((*sc->sc_enable)(sc) != 0) {
|
|
|
|
printf("%s: device enable failed\n",
|
2000-12-05 14:11:49 +03:00
|
|
|
sc->sc_dev.dv_xname);
|
|
|
|
return (EIO);
|
2000-05-19 17:42:29 +04:00
|
|
|
}
|
|
|
|
sc->sc_flags |= RTK_ENABLED;
|
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* rtk_disable:
|
|
|
|
* Disable the RTL81X9 chip.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
rtk_disable(sc)
|
|
|
|
struct rtk_softc *sc;
|
|
|
|
{
|
2000-12-05 14:11:49 +03:00
|
|
|
|
2000-05-19 17:42:29 +04:00
|
|
|
if (RTK_IS_ENABLED(sc) && sc->sc_disable != NULL) {
|
|
|
|
(*sc->sc_disable)(sc);
|
|
|
|
sc->sc_flags &= ~RTK_ENABLED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* rtk_power:
|
|
|
|
* Power management (suspend/resume) hook.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
rtk_power(why, arg)
|
|
|
|
int why;
|
|
|
|
void *arg;
|
|
|
|
{
|
|
|
|
struct rtk_softc *sc = (void *) arg;
|
|
|
|
struct ifnet *ifp = &sc->ethercom.ec_if;
|
|
|
|
int s;
|
|
|
|
|
|
|
|
s = splnet();
|
2000-11-26 14:08:57 +03:00
|
|
|
switch (why) {
|
|
|
|
case PWR_SUSPEND:
|
|
|
|
case PWR_STANDBY:
|
2000-10-11 20:57:45 +04:00
|
|
|
rtk_stop(ifp, 0);
|
2000-05-19 17:42:29 +04:00
|
|
|
if (sc->sc_power != NULL)
|
|
|
|
(*sc->sc_power)(sc, why);
|
2000-11-26 14:08:57 +03:00
|
|
|
break;
|
|
|
|
case PWR_RESUME:
|
|
|
|
if (ifp->if_flags & IFF_UP) {
|
|
|
|
if (sc->sc_power != NULL)
|
|
|
|
(*sc->sc_power)(sc, why);
|
|
|
|
rtk_init(ifp);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case PWR_SOFTSUSPEND:
|
|
|
|
case PWR_SOFTSTANDBY:
|
|
|
|
case PWR_SOFTRESUME:
|
|
|
|
break;
|
2000-05-19 17:42:29 +04:00
|
|
|
}
|
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
|
2000-04-10 11:42:55 +04:00
|
|
|
/*
|
|
|
|
* A frame has been uploaded: pass the resulting mbuf chain up to
|
|
|
|
* the higher level protocols.
|
|
|
|
*
|
2000-12-03 17:24:17 +03:00
|
|
|
* You know there's something wrong with a PCI bus-master chip design.
|
2000-04-10 11:42:55 +04:00
|
|
|
*
|
|
|
|
* The receive operation is badly documented in the datasheet, so I'll
|
|
|
|
* attempt to document it here. The driver provides a buffer area and
|
|
|
|
* places its base address in the RX buffer start address register.
|
|
|
|
* The chip then begins copying frames into the RX buffer. Each frame
|
2001-08-20 15:57:02 +04:00
|
|
|
* is preceded by a 32-bit RX status word which specifies the length
|
2000-04-10 11:42:55 +04:00
|
|
|
* of the frame and certain other status bits. Each frame (starting with
|
|
|
|
* the status word) is also 32-bit aligned. The frame length is in the
|
|
|
|
* first 16 bits of the status word; the lower 15 bits correspond with
|
|
|
|
* the 'rx status register' mentioned in the datasheet.
|
|
|
|
*
|
|
|
|
* Note: to make the Alpha happy, the frame payload needs to be aligned
|
2000-12-03 17:24:17 +03:00
|
|
|
* on a 32-bit boundary. To achieve this, we copy the data to mbuf
|
|
|
|
* shifted forward 2 bytes.
|
2000-04-10 11:42:55 +04:00
|
|
|
*/
|
2000-05-15 05:55:12 +04:00
|
|
|
STATIC void rtk_rxeof(sc)
|
2000-05-19 17:42:29 +04:00
|
|
|
struct rtk_softc *sc;
|
2000-04-10 11:42:55 +04:00
|
|
|
{
|
|
|
|
struct mbuf *m;
|
|
|
|
struct ifnet *ifp;
|
2000-12-03 17:24:17 +03:00
|
|
|
caddr_t rxbufpos, dst;
|
|
|
|
int total_len, wrap = 0;
|
2000-04-10 11:42:55 +04:00
|
|
|
u_int32_t rxstat;
|
2000-12-03 17:24:17 +03:00
|
|
|
u_int16_t cur_rx, new_rx;
|
2000-04-10 11:42:55 +04:00
|
|
|
u_int16_t limit;
|
|
|
|
u_int16_t rx_bytes = 0, max_bytes;
|
|
|
|
|
|
|
|
ifp = &sc->ethercom.ec_if;
|
|
|
|
|
2000-05-19 17:42:29 +04:00
|
|
|
cur_rx = (CSR_READ_2(sc, RTK_CURRXADDR) + 16) % RTK_RXBUFLEN;
|
2000-04-10 11:42:55 +04:00
|
|
|
|
|
|
|
/* Do not try to read past this point. */
|
2000-05-19 17:42:29 +04:00
|
|
|
limit = CSR_READ_2(sc, RTK_CURRXBUF) % RTK_RXBUFLEN;
|
2000-04-10 11:42:55 +04:00
|
|
|
|
|
|
|
if (limit < cur_rx)
|
2000-05-19 17:42:29 +04:00
|
|
|
max_bytes = (RTK_RXBUFLEN - cur_rx) + limit;
|
2000-04-10 11:42:55 +04:00
|
|
|
else
|
|
|
|
max_bytes = limit - cur_rx;
|
|
|
|
|
2000-05-19 17:42:29 +04:00
|
|
|
while((CSR_READ_1(sc, RTK_COMMAND) & RTK_CMD_EMPTY_RXBUF) == 0) {
|
2001-02-02 06:51:51 +03:00
|
|
|
rxbufpos = sc->rtk_rx_buf + cur_rx;
|
2000-04-26 18:02:34 +04:00
|
|
|
bus_dmamap_sync(sc->sc_dmat, sc->recv_dmamap, cur_rx,
|
2000-11-30 18:51:57 +03:00
|
|
|
RTK_RXSTAT_LEN, BUS_DMASYNC_POSTREAD);
|
2000-04-25 18:16:46 +04:00
|
|
|
rxstat = le32toh(*(u_int32_t *)rxbufpos);
|
2000-04-26 18:02:34 +04:00
|
|
|
bus_dmamap_sync(sc->sc_dmat, sc->recv_dmamap, cur_rx,
|
2000-11-30 18:51:57 +03:00
|
|
|
RTK_RXSTAT_LEN, BUS_DMASYNC_PREREAD);
|
2000-04-10 11:42:55 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Here's a totally undocumented fact for you. When the
|
|
|
|
* RealTek chip is in the process of copying a packet into
|
|
|
|
* RAM for you, the length will be 0xfff0. If you spot a
|
|
|
|
* packet header with this value, you need to stop. The
|
|
|
|
* datasheet makes absolutely no mention of this and
|
|
|
|
* RealTek should be shot for this.
|
|
|
|
*/
|
2000-12-03 17:24:17 +03:00
|
|
|
total_len = rxstat >> 16;
|
|
|
|
if (total_len == RTK_RXSTAT_UNFINISHED)
|
2000-04-10 11:42:55 +04:00
|
|
|
break;
|
2000-12-03 17:24:17 +03:00
|
|
|
|
2001-01-11 17:38:58 +03:00
|
|
|
if ((rxstat & RTK_RXSTAT_RXOK) == 0 ||
|
|
|
|
total_len > ETHER_MAX_LEN) {
|
2000-04-10 11:42:55 +04:00
|
|
|
ifp->if_ierrors++;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* submitted by:[netbsd-pcmcia:00484]
|
|
|
|
* Takahiro Kambe <taca@sky.yamashina.kyoto.jp>
|
|
|
|
* obtain from:
|
|
|
|
* FreeBSD if_rl.c rev 1.24->1.25
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#if 0
|
2000-05-19 17:42:29 +04:00
|
|
|
if (rxstat & (RTK_RXSTAT_BADSYM|RTK_RXSTAT_RUNT|
|
2000-11-30 18:51:57 +03:00
|
|
|
RTK_RXSTAT_GIANT|RTK_RXSTAT_CRCERR|
|
|
|
|
RTK_RXSTAT_ALIGNERR)) {
|
2000-05-19 17:42:29 +04:00
|
|
|
CSR_WRITE_2(sc, RTK_COMMAND, RTK_CMD_TX_ENB);
|
2000-11-30 18:51:57 +03:00
|
|
|
CSR_WRITE_2(sc, RTK_COMMAND,
|
|
|
|
RTK_CMD_TX_ENB|RTK_CMD_RX_ENB);
|
2000-05-19 17:42:29 +04:00
|
|
|
CSR_WRITE_4(sc, RTK_RXCFG, RTK_RXCFG_CONFIG);
|
|
|
|
CSR_WRITE_4(sc, RTK_RXADDR,
|
2000-11-30 18:51:57 +03:00
|
|
|
sc->recv_dmamap->dm_segs[0].ds_addr);
|
2000-04-10 11:42:55 +04:00
|
|
|
cur_rx = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
#else
|
2000-10-11 20:57:45 +04:00
|
|
|
rtk_init(ifp);
|
2000-04-10 11:42:55 +04:00
|
|
|
return;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/* No errors; receive the packet. */
|
2000-11-30 18:51:57 +03:00
|
|
|
rx_bytes += total_len + RTK_RXSTAT_LEN;
|
2000-04-10 11:42:55 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Avoid trying to read more bytes than we know
|
|
|
|
* the chip has prepared for us.
|
|
|
|
*/
|
|
|
|
if (rx_bytes > max_bytes)
|
|
|
|
break;
|
|
|
|
|
2000-12-03 17:24:17 +03:00
|
|
|
/*
|
|
|
|
* Skip the status word, wrapping around to the beginning
|
|
|
|
* of the Rx area, if necessary.
|
|
|
|
*/
|
2001-02-01 07:45:17 +03:00
|
|
|
cur_rx = (cur_rx + RTK_RXSTAT_LEN) % RTK_RXBUFLEN;
|
2001-02-02 06:51:51 +03:00
|
|
|
rxbufpos = sc->rtk_rx_buf + cur_rx;
|
2000-04-10 11:42:55 +04:00
|
|
|
|
2000-12-03 17:24:17 +03:00
|
|
|
/*
|
|
|
|
* Compute the number of bytes at which the packet
|
|
|
|
* will wrap to the beginning of the ring buffer.
|
|
|
|
*/
|
2001-02-01 07:45:17 +03:00
|
|
|
wrap = RTK_RXBUFLEN - cur_rx;
|
2000-04-10 11:42:55 +04:00
|
|
|
|
2000-12-03 17:24:17 +03:00
|
|
|
/*
|
|
|
|
* Compute where the next pending packet is.
|
|
|
|
*/
|
|
|
|
if (total_len > wrap)
|
|
|
|
new_rx = total_len - wrap;
|
|
|
|
else
|
|
|
|
new_rx = cur_rx + total_len;
|
|
|
|
/* Round up to 32-bit boundary. */
|
|
|
|
new_rx = (new_rx + 3) & ~3;
|
2000-04-10 11:42:55 +04:00
|
|
|
|
2000-12-03 17:24:17 +03:00
|
|
|
/*
|
|
|
|
* Now allocate an mbuf (and possibly a cluster) to hold
|
|
|
|
* the packet. Note we offset the packet 2 bytes so that
|
|
|
|
* data after the Ethernet header will be 4-byte aligned.
|
|
|
|
*/
|
|
|
|
MGETHDR(m, M_DONTWAIT, MT_DATA);
|
|
|
|
if (m == NULL) {
|
|
|
|
printf("%s: unable to allocate Rx mbuf\n",
|
|
|
|
sc->sc_dev.dv_xname);
|
|
|
|
ifp->if_ierrors++;
|
|
|
|
goto next_packet;
|
|
|
|
}
|
|
|
|
if (total_len > (MHLEN - RTK_ETHER_ALIGN)) {
|
|
|
|
MCLGET(m, M_DONTWAIT);
|
|
|
|
if ((m->m_flags & M_EXT) == 0) {
|
|
|
|
printf("%s: unable to allocate Rx cluster\n",
|
|
|
|
sc->sc_dev.dv_xname);
|
2000-04-10 11:42:55 +04:00
|
|
|
ifp->if_ierrors++;
|
2000-12-03 17:24:17 +03:00
|
|
|
m_freem(m);
|
|
|
|
m = NULL;
|
|
|
|
goto next_packet;
|
2000-04-10 11:42:55 +04:00
|
|
|
}
|
2000-12-03 17:24:17 +03:00
|
|
|
}
|
|
|
|
m->m_data += RTK_ETHER_ALIGN; /* for alignment */
|
|
|
|
m->m_pkthdr.rcvif = ifp;
|
|
|
|
m->m_pkthdr.len = m->m_len = total_len;
|
|
|
|
dst = mtod(m, caddr_t);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the packet wraps, copy up to the wrapping point.
|
|
|
|
*/
|
|
|
|
if (total_len > wrap) {
|
|
|
|
bus_dmamap_sync(sc->sc_dmat, sc->recv_dmamap,
|
|
|
|
cur_rx, wrap, BUS_DMASYNC_POSTREAD);
|
|
|
|
memcpy(dst, rxbufpos, wrap);
|
|
|
|
bus_dmamap_sync(sc->sc_dmat, sc->recv_dmamap,
|
|
|
|
cur_rx, wrap, BUS_DMASYNC_PREREAD);
|
|
|
|
cur_rx = 0;
|
2001-02-02 06:51:51 +03:00
|
|
|
rxbufpos = sc->rtk_rx_buf;
|
2000-12-03 17:24:17 +03:00
|
|
|
total_len -= wrap;
|
|
|
|
dst += wrap;
|
2000-04-10 11:42:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2000-12-03 17:24:17 +03:00
|
|
|
* ...and now the rest.
|
2000-04-10 11:42:55 +04:00
|
|
|
*/
|
2000-12-03 17:24:17 +03:00
|
|
|
bus_dmamap_sync(sc->sc_dmat, sc->recv_dmamap,
|
|
|
|
cur_rx, total_len, BUS_DMASYNC_POSTREAD);
|
|
|
|
memcpy(dst, rxbufpos, total_len);
|
|
|
|
bus_dmamap_sync(sc->sc_dmat, sc->recv_dmamap,
|
|
|
|
cur_rx, total_len, BUS_DMASYNC_PREREAD);
|
|
|
|
|
2000-12-05 14:11:49 +03:00
|
|
|
next_packet:
|
2000-12-03 17:24:17 +03:00
|
|
|
CSR_WRITE_2(sc, RTK_CURRXADDR, new_rx - 16);
|
|
|
|
cur_rx = new_rx;
|
2000-04-10 11:42:55 +04:00
|
|
|
|
|
|
|
if (m == NULL)
|
|
|
|
continue;
|
|
|
|
|
2000-10-15 23:56:31 +04:00
|
|
|
/*
|
|
|
|
* The RealTek chip includes the CRC with every
|
|
|
|
* incoming packet.
|
|
|
|
*/
|
|
|
|
m->m_flags |= M_HASFCS;
|
|
|
|
|
2000-04-10 11:42:55 +04:00
|
|
|
ifp->if_ipackets++;
|
|
|
|
|
|
|
|
#if NBPFILTER > 0
|
2000-10-02 03:32:39 +04:00
|
|
|
if (ifp->if_bpf)
|
2000-04-10 11:42:55 +04:00
|
|
|
bpf_mtap(ifp->if_bpf, m);
|
|
|
|
#endif
|
|
|
|
/* pass it on. */
|
|
|
|
(*ifp->if_input)(ifp, m);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* A frame was downloaded to the chip. It's safe for us to clean up
|
|
|
|
* the list buffers.
|
|
|
|
*/
|
2000-05-15 05:55:12 +04:00
|
|
|
STATIC void rtk_txeof(sc)
|
2000-05-19 17:42:29 +04:00
|
|
|
struct rtk_softc *sc;
|
2000-04-10 11:42:55 +04:00
|
|
|
{
|
2001-02-02 07:34:19 +03:00
|
|
|
struct ifnet *ifp;
|
|
|
|
struct rtk_tx_desc *txd;
|
|
|
|
u_int32_t txstat;
|
2000-04-10 11:42:55 +04:00
|
|
|
|
|
|
|
ifp = &sc->ethercom.ec_if;
|
|
|
|
|
|
|
|
/* Clear the timeout timer. */
|
|
|
|
ifp->if_timer = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Go through our tx list and free mbufs for those
|
|
|
|
* frames that have been uploaded.
|
|
|
|
*/
|
2001-02-02 07:34:19 +03:00
|
|
|
while ((txd = SIMPLEQ_FIRST(&sc->rtk_tx_dirty)) != NULL) {
|
|
|
|
txstat = CSR_READ_4(sc, txd->txd_txstat);
|
2000-12-05 14:11:49 +03:00
|
|
|
if ((txstat & (RTK_TXSTAT_TX_OK|
|
|
|
|
RTK_TXSTAT_TX_UNDERRUN|RTK_TXSTAT_TXABRT)) == 0)
|
2000-04-10 11:42:55 +04:00
|
|
|
break;
|
|
|
|
|
2001-02-02 07:34:19 +03:00
|
|
|
SIMPLEQ_REMOVE_HEAD(&sc->rtk_tx_dirty, txd, txd_q);
|
|
|
|
|
|
|
|
bus_dmamap_sync(sc->sc_dmat, txd->txd_dmamap, 0,
|
|
|
|
txd->txd_dmamap->dm_mapsize, BUS_DMASYNC_POSTWRITE);
|
|
|
|
bus_dmamap_unload(sc->sc_dmat, txd->txd_dmamap);
|
|
|
|
m_freem(txd->txd_mbuf);
|
|
|
|
txd->txd_mbuf = NULL;
|
2000-04-26 18:02:34 +04:00
|
|
|
|
2000-05-19 17:42:29 +04:00
|
|
|
ifp->if_collisions += (txstat & RTK_TXSTAT_COLLCNT) >> 24;
|
2000-04-10 11:42:55 +04:00
|
|
|
|
2000-05-19 17:42:29 +04:00
|
|
|
if (txstat & RTK_TXSTAT_TX_OK)
|
2000-04-10 11:42:55 +04:00
|
|
|
ifp->if_opackets++;
|
|
|
|
else {
|
|
|
|
ifp->if_oerrors++;
|
2001-07-25 13:57:31 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Increase Early TX threshold if underrun occurred.
|
|
|
|
* Increase step 64 bytes.
|
|
|
|
*/
|
|
|
|
if (txstat & RTK_TXSTAT_TX_UNDERRUN) {
|
|
|
|
printf("%s: transmit underrun;",
|
|
|
|
sc->sc_dev.dv_xname);
|
|
|
|
if (sc->sc_txthresh < TXTH_MAX) {
|
|
|
|
sc->sc_txthresh += 2;
|
|
|
|
printf(" new threshold: %d bytes",
|
|
|
|
sc->sc_txthresh * 32);
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
}
|
2000-12-05 14:11:49 +03:00
|
|
|
if (txstat & (RTK_TXSTAT_TXABRT|RTK_TXSTAT_OUTOFWIN))
|
2000-05-19 17:42:29 +04:00
|
|
|
CSR_WRITE_4(sc, RTK_TXCFG, RTK_TXCFG_CONFIG);
|
2000-04-10 11:42:55 +04:00
|
|
|
}
|
2001-02-02 07:34:19 +03:00
|
|
|
SIMPLEQ_INSERT_TAIL(&sc->rtk_tx_free, txd, txd_q);
|
2000-04-10 11:42:55 +04:00
|
|
|
ifp->if_flags &= ~IFF_OACTIVE;
|
2001-02-02 07:34:19 +03:00
|
|
|
}
|
2000-04-10 11:42:55 +04:00
|
|
|
}
|
|
|
|
|
2000-05-15 05:55:12 +04:00
|
|
|
int rtk_intr(arg)
|
2000-04-10 11:42:55 +04:00
|
|
|
void *arg;
|
|
|
|
{
|
2000-05-19 17:42:29 +04:00
|
|
|
struct rtk_softc *sc;
|
2000-04-10 11:42:55 +04:00
|
|
|
struct ifnet *ifp;
|
|
|
|
u_int16_t status;
|
|
|
|
int handled = 0;
|
|
|
|
|
|
|
|
sc = arg;
|
|
|
|
ifp = &sc->ethercom.ec_if;
|
|
|
|
|
|
|
|
/* Disable interrupts. */
|
2000-05-19 17:42:29 +04:00
|
|
|
CSR_WRITE_2(sc, RTK_IMR, 0x0000);
|
2000-04-10 11:42:55 +04:00
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
|
2000-05-19 17:42:29 +04:00
|
|
|
status = CSR_READ_2(sc, RTK_ISR);
|
2000-04-10 11:42:55 +04:00
|
|
|
if (status)
|
2000-05-19 17:42:29 +04:00
|
|
|
CSR_WRITE_2(sc, RTK_ISR, status);
|
2000-04-10 11:42:55 +04:00
|
|
|
|
|
|
|
handled = 1;
|
|
|
|
|
2000-05-19 17:42:29 +04:00
|
|
|
if ((status & RTK_INTRS) == 0)
|
2000-04-10 11:42:55 +04:00
|
|
|
break;
|
|
|
|
|
2000-05-19 17:42:29 +04:00
|
|
|
if (status & RTK_ISR_RX_OK)
|
2000-05-15 05:55:12 +04:00
|
|
|
rtk_rxeof(sc);
|
2000-04-10 11:42:55 +04:00
|
|
|
|
2000-05-19 17:42:29 +04:00
|
|
|
if (status & RTK_ISR_RX_ERR)
|
2000-05-15 05:55:12 +04:00
|
|
|
rtk_rxeof(sc);
|
2000-04-10 11:42:55 +04:00
|
|
|
|
2000-12-05 14:11:49 +03:00
|
|
|
if (status & (RTK_ISR_TX_OK|RTK_ISR_TX_ERR))
|
2000-05-15 05:55:12 +04:00
|
|
|
rtk_txeof(sc);
|
2000-04-10 11:42:55 +04:00
|
|
|
|
2000-05-19 17:42:29 +04:00
|
|
|
if (status & RTK_ISR_SYSTEM_ERR) {
|
2000-05-15 05:55:12 +04:00
|
|
|
rtk_reset(sc);
|
2000-10-11 20:57:45 +04:00
|
|
|
rtk_init(ifp);
|
2000-04-10 11:42:55 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Re-enable interrupts. */
|
2000-05-19 17:42:29 +04:00
|
|
|
CSR_WRITE_2(sc, RTK_IMR, RTK_INTRS);
|
2000-04-10 11:42:55 +04:00
|
|
|
|
2000-12-14 09:27:23 +03:00
|
|
|
if (IFQ_IS_EMPTY(&ifp->if_snd) == 0)
|
2000-05-15 05:55:12 +04:00
|
|
|
rtk_start(ifp);
|
2000-04-10 11:42:55 +04:00
|
|
|
|
|
|
|
return (handled);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Main transmit routine.
|
|
|
|
*/
|
|
|
|
|
2000-05-15 05:55:12 +04:00
|
|
|
STATIC void rtk_start(ifp)
|
2000-04-10 11:42:55 +04:00
|
|
|
struct ifnet *ifp;
|
|
|
|
{
|
2001-02-02 07:34:19 +03:00
|
|
|
struct rtk_softc *sc;
|
|
|
|
struct rtk_tx_desc *txd;
|
|
|
|
struct mbuf *m_head = NULL, *m_new;
|
|
|
|
int error, len;
|
2000-04-10 11:42:55 +04:00
|
|
|
|
|
|
|
sc = ifp->if_softc;
|
|
|
|
|
2001-02-02 07:34:19 +03:00
|
|
|
while ((txd = SIMPLEQ_FIRST(&sc->rtk_tx_free)) != NULL) {
|
2000-12-14 09:27:23 +03:00
|
|
|
IFQ_POLL(&ifp->if_snd, m_head);
|
2000-04-10 11:42:55 +04:00
|
|
|
if (m_head == NULL)
|
|
|
|
break;
|
2000-12-19 03:06:01 +03:00
|
|
|
m_new = NULL;
|
2000-04-10 11:42:55 +04:00
|
|
|
|
2000-04-26 18:02:34 +04:00
|
|
|
/*
|
|
|
|
* Load the DMA map. If this fails, the packet didn't
|
|
|
|
* fit in one DMA segment, and we need to copy. Note,
|
|
|
|
* the packet must also be aligned.
|
|
|
|
*/
|
2001-08-14 15:57:26 +04:00
|
|
|
if ((mtod(m_head, uintptr_t) & 3) != 0 ||
|
2001-02-02 07:34:19 +03:00
|
|
|
bus_dmamap_load_mbuf(sc->sc_dmat, txd->txd_dmamap,
|
2001-07-19 20:25:23 +04:00
|
|
|
m_head, BUS_DMA_WRITE|BUS_DMA_NOWAIT) != 0) {
|
2000-04-26 18:02:34 +04:00
|
|
|
MGETHDR(m_new, M_DONTWAIT, MT_DATA);
|
|
|
|
if (m_new == NULL) {
|
|
|
|
printf("%s: unable to allocate Tx mbuf\n",
|
|
|
|
sc->sc_dev.dv_xname);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (m_head->m_pkthdr.len > MHLEN) {
|
|
|
|
MCLGET(m_new, M_DONTWAIT);
|
|
|
|
if ((m_new->m_flags & M_EXT) == 0) {
|
|
|
|
printf("%s: unable to allocate Tx "
|
|
|
|
"cluster\n", sc->sc_dev.dv_xname);
|
|
|
|
m_freem(m_new);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
m_copydata(m_head, 0, m_head->m_pkthdr.len,
|
|
|
|
mtod(m_new, caddr_t));
|
|
|
|
m_new->m_pkthdr.len = m_new->m_len =
|
|
|
|
m_head->m_pkthdr.len;
|
|
|
|
error = bus_dmamap_load_mbuf(sc->sc_dmat,
|
2001-07-19 20:25:23 +04:00
|
|
|
txd->txd_dmamap, m_new,
|
|
|
|
BUS_DMA_WRITE|BUS_DMA_NOWAIT);
|
2000-04-26 18:02:34 +04:00
|
|
|
if (error) {
|
|
|
|
printf("%s: unable to load Tx buffer, "
|
|
|
|
"error = %d\n", sc->sc_dev.dv_xname, error);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2000-12-14 09:27:23 +03:00
|
|
|
IFQ_DEQUEUE(&ifp->if_snd, m_head);
|
2000-12-19 03:06:01 +03:00
|
|
|
if (m_new != NULL) {
|
|
|
|
m_freem(m_head);
|
|
|
|
m_head = m_new;
|
|
|
|
}
|
2001-02-02 07:34:19 +03:00
|
|
|
txd->txd_mbuf = m_head;
|
2000-04-26 18:02:34 +04:00
|
|
|
|
2001-02-02 07:34:19 +03:00
|
|
|
SIMPLEQ_REMOVE_HEAD(&sc->rtk_tx_free, txd, txd_q);
|
|
|
|
SIMPLEQ_INSERT_TAIL(&sc->rtk_tx_dirty, txd, txd_q);
|
2000-04-10 11:42:55 +04:00
|
|
|
|
|
|
|
#if NBPFILTER > 0
|
|
|
|
/*
|
|
|
|
* If there's a BPF listener, bounce a copy of this frame
|
|
|
|
* to him.
|
|
|
|
*/
|
|
|
|
if (ifp->if_bpf)
|
2001-02-02 07:34:19 +03:00
|
|
|
bpf_mtap(ifp->if_bpf, m_head);
|
2000-04-10 11:42:55 +04:00
|
|
|
#endif
|
|
|
|
/*
|
|
|
|
* Transmit the frame.
|
|
|
|
*/
|
2000-04-26 18:02:34 +04:00
|
|
|
bus_dmamap_sync(sc->sc_dmat,
|
2001-02-02 07:34:19 +03:00
|
|
|
txd->txd_dmamap, 0, txd->txd_dmamap->dm_mapsize,
|
2000-04-26 18:02:34 +04:00
|
|
|
BUS_DMASYNC_PREWRITE);
|
|
|
|
|
2001-02-02 07:34:19 +03:00
|
|
|
len = txd->txd_dmamap->dm_segs[0].ds_len;
|
2000-04-26 18:02:34 +04:00
|
|
|
if (len < (ETHER_MIN_LEN - ETHER_CRC_LEN))
|
|
|
|
len = (ETHER_MIN_LEN - ETHER_CRC_LEN);
|
|
|
|
|
2001-02-02 07:34:19 +03:00
|
|
|
CSR_WRITE_4(sc, txd->txd_txaddr,
|
|
|
|
txd->txd_dmamap->dm_segs[0].ds_addr);
|
2001-07-25 13:57:31 +04:00
|
|
|
CSR_WRITE_4(sc, txd->txd_txstat, RTK_TX_THRESH(sc) | len);
|
2000-04-10 11:42:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We broke out of the loop because all our TX slots are
|
|
|
|
* full. Mark the NIC as busy until it drains some of the
|
|
|
|
* packets from the queue.
|
|
|
|
*/
|
2001-02-02 07:34:19 +03:00
|
|
|
if (SIMPLEQ_FIRST(&sc->rtk_tx_free) == NULL)
|
2000-04-10 11:42:55 +04:00
|
|
|
ifp->if_flags |= IFF_OACTIVE;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set a timeout in case the chip goes out to lunch.
|
|
|
|
*/
|
|
|
|
ifp->if_timer = 5;
|
|
|
|
}
|
|
|
|
|
2000-10-11 20:57:45 +04:00
|
|
|
STATIC int rtk_init(ifp)
|
|
|
|
struct ifnet *ifp;
|
2000-04-10 11:42:55 +04:00
|
|
|
{
|
2000-10-11 20:57:45 +04:00
|
|
|
struct rtk_softc *sc = ifp->if_softc;
|
|
|
|
int error = 0, i;
|
2000-04-26 18:02:34 +04:00
|
|
|
u_int32_t rxcfg;
|
2000-04-10 11:42:55 +04:00
|
|
|
|
2000-10-11 20:57:45 +04:00
|
|
|
if ((error = rtk_enable(sc)) != 0)
|
|
|
|
goto out;
|
2000-04-10 11:42:55 +04:00
|
|
|
|
|
|
|
/*
|
2000-10-11 20:57:45 +04:00
|
|
|
* Cancel pending I/O.
|
2000-04-10 11:42:55 +04:00
|
|
|
*/
|
2000-10-11 20:57:45 +04:00
|
|
|
rtk_stop(ifp, 0);
|
2000-04-10 11:42:55 +04:00
|
|
|
|
|
|
|
/* Init our MAC address */
|
|
|
|
for (i = 0; i < ETHER_ADDR_LEN; i++) {
|
2000-05-19 17:42:29 +04:00
|
|
|
CSR_WRITE_1(sc, RTK_IDR0 + i, LLADDR(ifp->if_sadl)[i]);
|
2000-04-10 11:42:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Init the RX buffer pointer register. */
|
2000-04-26 18:02:34 +04:00
|
|
|
bus_dmamap_sync(sc->sc_dmat, sc->recv_dmamap, 0,
|
|
|
|
sc->recv_dmamap->dm_mapsize, BUS_DMASYNC_PREREAD);
|
2000-05-19 17:42:29 +04:00
|
|
|
CSR_WRITE_4(sc, RTK_RXADDR, sc->recv_dmamap->dm_segs[0].ds_addr);
|
2000-04-10 11:42:55 +04:00
|
|
|
|
|
|
|
/* Init TX descriptors. */
|
2000-05-15 05:55:12 +04:00
|
|
|
rtk_list_tx_init(sc);
|
2000-04-10 11:42:55 +04:00
|
|
|
|
2001-07-25 13:57:31 +04:00
|
|
|
/* Init Early TX threshold. */
|
|
|
|
sc->sc_txthresh = TXTH_256;
|
2000-04-10 11:42:55 +04:00
|
|
|
/*
|
|
|
|
* Enable transmit and receive.
|
|
|
|
*/
|
2000-05-19 17:42:29 +04:00
|
|
|
CSR_WRITE_1(sc, RTK_COMMAND, RTK_CMD_TX_ENB|RTK_CMD_RX_ENB);
|
2000-04-10 11:42:55 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Set the initial TX and RX configuration.
|
|
|
|
*/
|
2000-05-19 17:42:29 +04:00
|
|
|
CSR_WRITE_4(sc, RTK_TXCFG, RTK_TXCFG_CONFIG);
|
|
|
|
CSR_WRITE_4(sc, RTK_RXCFG, RTK_RXCFG_CONFIG);
|
2000-04-10 11:42:55 +04:00
|
|
|
|
|
|
|
/* Set the individual bit to receive frames for this host only. */
|
2000-05-19 17:42:29 +04:00
|
|
|
rxcfg = CSR_READ_4(sc, RTK_RXCFG);
|
|
|
|
rxcfg |= RTK_RXCFG_RX_INDIV;
|
2000-04-10 11:42:55 +04:00
|
|
|
|
|
|
|
/* If we want promiscuous mode, set the allframes bit. */
|
|
|
|
if (ifp->if_flags & IFF_PROMISC) {
|
2000-05-19 17:42:29 +04:00
|
|
|
rxcfg |= RTK_RXCFG_RX_ALLPHYS;
|
|
|
|
CSR_WRITE_4(sc, RTK_RXCFG, rxcfg);
|
2000-04-10 11:42:55 +04:00
|
|
|
} else {
|
2000-05-19 17:42:29 +04:00
|
|
|
rxcfg &= ~RTK_RXCFG_RX_ALLPHYS;
|
|
|
|
CSR_WRITE_4(sc, RTK_RXCFG, rxcfg);
|
2000-04-10 11:42:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set capture broadcast bit to capture broadcast frames.
|
|
|
|
*/
|
|
|
|
if (ifp->if_flags & IFF_BROADCAST) {
|
2000-05-19 17:42:29 +04:00
|
|
|
rxcfg |= RTK_RXCFG_RX_BROAD;
|
|
|
|
CSR_WRITE_4(sc, RTK_RXCFG, rxcfg);
|
2000-04-10 11:42:55 +04:00
|
|
|
} else {
|
2000-05-19 17:42:29 +04:00
|
|
|
rxcfg &= ~RTK_RXCFG_RX_BROAD;
|
|
|
|
CSR_WRITE_4(sc, RTK_RXCFG, rxcfg);
|
2000-04-10 11:42:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Program the multicast filter, if necessary.
|
|
|
|
*/
|
2000-05-15 05:55:12 +04:00
|
|
|
rtk_setmulti(sc);
|
2000-04-10 11:42:55 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Enable interrupts.
|
|
|
|
*/
|
2000-05-19 17:42:29 +04:00
|
|
|
CSR_WRITE_2(sc, RTK_IMR, RTK_INTRS);
|
2000-04-10 11:42:55 +04:00
|
|
|
|
|
|
|
/* Start RX/TX process. */
|
2000-05-19 17:42:29 +04:00
|
|
|
CSR_WRITE_4(sc, RTK_MISSEDPKT, 0);
|
2000-04-10 11:42:55 +04:00
|
|
|
|
|
|
|
/* Enable receiver and transmitter. */
|
2000-05-19 17:42:29 +04:00
|
|
|
CSR_WRITE_1(sc, RTK_COMMAND, RTK_CMD_TX_ENB|RTK_CMD_RX_ENB);
|
2000-04-10 11:42:55 +04:00
|
|
|
|
2000-05-19 17:42:29 +04:00
|
|
|
CSR_WRITE_1(sc, RTK_CFG1, RTK_CFG1_DRVLOAD|RTK_CFG1_FULLDUPLEX);
|
2000-04-10 11:42:55 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Set current media.
|
|
|
|
*/
|
|
|
|
mii_mediachg(&sc->mii);
|
|
|
|
|
|
|
|
ifp->if_flags |= IFF_RUNNING;
|
|
|
|
ifp->if_flags &= ~IFF_OACTIVE;
|
|
|
|
|
2000-05-15 05:55:12 +04:00
|
|
|
callout_reset(&sc->rtk_tick_ch, hz, rtk_tick, sc);
|
2000-10-11 20:57:45 +04:00
|
|
|
|
|
|
|
out:
|
|
|
|
if (error) {
|
|
|
|
ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE);
|
|
|
|
ifp->if_timer = 0;
|
|
|
|
printf("%s: interface not running\n", sc->sc_dev.dv_xname);
|
|
|
|
}
|
|
|
|
return (error);
|
2000-04-10 11:42:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set media options.
|
|
|
|
*/
|
2000-05-15 05:55:12 +04:00
|
|
|
STATIC int rtk_ifmedia_upd(ifp)
|
2000-04-10 11:42:55 +04:00
|
|
|
struct ifnet *ifp;
|
|
|
|
{
|
2000-05-19 17:42:29 +04:00
|
|
|
struct rtk_softc *sc;
|
2000-04-10 11:42:55 +04:00
|
|
|
|
|
|
|
sc = ifp->if_softc;
|
|
|
|
|
|
|
|
return (mii_mediachg(&sc->mii));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Report current media status.
|
|
|
|
*/
|
2000-05-15 05:55:12 +04:00
|
|
|
STATIC void rtk_ifmedia_sts(ifp, ifmr)
|
2000-04-10 11:42:55 +04:00
|
|
|
struct ifnet *ifp;
|
|
|
|
struct ifmediareq *ifmr;
|
|
|
|
{
|
2000-05-19 17:42:29 +04:00
|
|
|
struct rtk_softc *sc;
|
2000-04-10 11:42:55 +04:00
|
|
|
|
|
|
|
sc = ifp->if_softc;
|
|
|
|
|
|
|
|
mii_pollstat(&sc->mii);
|
|
|
|
ifmr->ifm_status = sc->mii.mii_media_status;
|
|
|
|
ifmr->ifm_active = sc->mii.mii_media_active;
|
|
|
|
}
|
|
|
|
|
2000-05-15 05:55:12 +04:00
|
|
|
STATIC int rtk_ioctl(ifp, command, data)
|
2000-04-10 11:42:55 +04:00
|
|
|
struct ifnet *ifp;
|
|
|
|
u_long command;
|
|
|
|
caddr_t data;
|
|
|
|
{
|
2000-05-19 17:42:29 +04:00
|
|
|
struct rtk_softc *sc = ifp->if_softc;
|
2000-04-10 11:42:55 +04:00
|
|
|
struct ifreq *ifr = (struct ifreq *) data;
|
|
|
|
int s, error = 0;
|
|
|
|
|
2000-05-15 05:55:53 +04:00
|
|
|
s = splnet();
|
2000-04-10 11:42:55 +04:00
|
|
|
|
2000-09-01 19:07:23 +04:00
|
|
|
switch (command) {
|
2000-04-10 11:42:55 +04:00
|
|
|
case SIOCGIFMEDIA:
|
|
|
|
case SIOCSIFMEDIA:
|
|
|
|
error = ifmedia_ioctl(ifp, ifr, &sc->mii.mii_media, command);
|
|
|
|
break;
|
2000-10-11 20:57:45 +04:00
|
|
|
|
2000-04-10 11:42:55 +04:00
|
|
|
default:
|
2000-10-11 20:57:45 +04:00
|
|
|
error = ether_ioctl(ifp, command, data);
|
|
|
|
if (error == ENETRESET) {
|
|
|
|
if (RTK_IS_ENABLED(sc)) {
|
|
|
|
/*
|
|
|
|
* Multicast list has changed. Set the
|
|
|
|
* hardware filter accordingly.
|
|
|
|
*/
|
|
|
|
rtk_setmulti(sc);
|
|
|
|
}
|
|
|
|
error = 0;
|
|
|
|
}
|
2000-04-10 11:42:55 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2000-09-01 19:07:23 +04:00
|
|
|
splx(s);
|
2000-04-10 11:42:55 +04:00
|
|
|
|
2000-12-05 14:11:49 +03:00
|
|
|
return (error);
|
2000-04-10 11:42:55 +04:00
|
|
|
}
|
|
|
|
|
2000-05-15 05:55:12 +04:00
|
|
|
STATIC void rtk_watchdog(ifp)
|
2000-04-10 11:42:55 +04:00
|
|
|
struct ifnet *ifp;
|
|
|
|
{
|
2000-05-19 17:42:29 +04:00
|
|
|
struct rtk_softc *sc;
|
2000-04-10 11:42:55 +04:00
|
|
|
|
|
|
|
sc = ifp->if_softc;
|
|
|
|
|
|
|
|
printf("%s: watchdog timeout\n", sc->sc_dev.dv_xname);
|
|
|
|
ifp->if_oerrors++;
|
2000-05-15 05:55:12 +04:00
|
|
|
rtk_txeof(sc);
|
|
|
|
rtk_rxeof(sc);
|
2000-10-11 20:57:45 +04:00
|
|
|
rtk_init(ifp);
|
2000-04-10 11:42:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Stop the adapter and free any mbufs allocated to the
|
|
|
|
* RX and TX lists.
|
|
|
|
*/
|
2000-10-11 20:57:45 +04:00
|
|
|
STATIC void rtk_stop(ifp, disable)
|
|
|
|
struct ifnet *ifp;
|
|
|
|
int disable;
|
2000-04-10 11:42:55 +04:00
|
|
|
{
|
2000-10-11 20:57:45 +04:00
|
|
|
struct rtk_softc *sc = ifp->if_softc;
|
2001-02-02 07:34:19 +03:00
|
|
|
struct rtk_tx_desc *txd;
|
2000-04-10 11:42:55 +04:00
|
|
|
|
2000-05-15 05:55:12 +04:00
|
|
|
callout_stop(&sc->rtk_tick_ch);
|
2000-04-10 11:42:55 +04:00
|
|
|
|
|
|
|
mii_down(&sc->mii);
|
|
|
|
|
2000-05-19 17:42:29 +04:00
|
|
|
CSR_WRITE_1(sc, RTK_COMMAND, 0x00);
|
|
|
|
CSR_WRITE_2(sc, RTK_IMR, 0x0000);
|
2000-04-10 11:42:55 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Free the TX list buffers.
|
|
|
|
*/
|
2001-02-02 07:34:19 +03:00
|
|
|
while ((txd = SIMPLEQ_FIRST(&sc->rtk_tx_dirty)) != NULL) {
|
|
|
|
SIMPLEQ_REMOVE_HEAD(&sc->rtk_tx_dirty, txd, txd_q);
|
|
|
|
bus_dmamap_unload(sc->sc_dmat, txd->txd_dmamap);
|
|
|
|
m_freem(txd->txd_mbuf);
|
|
|
|
txd->txd_mbuf = NULL;
|
|
|
|
CSR_WRITE_4(sc, txd->txd_txaddr, 0);
|
2000-04-10 11:42:55 +04:00
|
|
|
}
|
|
|
|
|
2000-10-11 20:57:45 +04:00
|
|
|
if (disable)
|
|
|
|
rtk_disable(sc);
|
2000-04-10 11:42:55 +04:00
|
|
|
|
2000-10-11 20:57:45 +04:00
|
|
|
ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE);
|
|
|
|
ifp->if_timer = 0;
|
2000-04-10 11:42:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Stop all chip I/O so that the kernel's probe routines don't
|
|
|
|
* get confused by errant DMAs when rebooting.
|
|
|
|
*/
|
2000-05-15 05:55:12 +04:00
|
|
|
STATIC void rtk_shutdown(vsc)
|
2000-04-10 11:42:55 +04:00
|
|
|
void *vsc;
|
|
|
|
{
|
2000-05-19 17:42:29 +04:00
|
|
|
struct rtk_softc *sc = (struct rtk_softc *)vsc;
|
2000-04-10 11:42:55 +04:00
|
|
|
|
2000-10-11 20:57:45 +04:00
|
|
|
rtk_stop(&sc->ethercom.ec_if, 0);
|
2000-04-10 11:42:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
STATIC void
|
2000-05-15 05:55:12 +04:00
|
|
|
rtk_tick(arg)
|
2000-04-10 11:42:55 +04:00
|
|
|
void *arg;
|
|
|
|
{
|
2000-05-15 05:55:12 +04:00
|
|
|
struct rtk_softc *sc = arg;
|
2000-04-10 11:42:55 +04:00
|
|
|
int s = splnet();
|
|
|
|
|
|
|
|
mii_tick(&sc->mii);
|
|
|
|
splx(s);
|
|
|
|
|
2000-05-15 05:55:12 +04:00
|
|
|
callout_reset(&sc->rtk_tick_ch, hz, rtk_tick, sc);
|
2000-04-10 11:42:55 +04:00
|
|
|
}
|