2005-01-06 01:43:34 +00:00
|
|
|
/*-
|
2001-05-31 21:44:26 +00:00
|
|
|
* Copyright (c) 2001 Wind River Systems
|
|
|
|
* Copyright (c) 1997, 1998, 1999, 2000, 2001
|
|
|
|
* Bill Paul <william.paul@windriver.com>. 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-08-24 17:55:58 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
2001-05-31 21:44:26 +00:00
|
|
|
/*
|
|
|
|
* Level 1 LXT1001 gigabit ethernet driver for FreeBSD. Public
|
|
|
|
* documentation not available, but ask me nicely.
|
|
|
|
*
|
|
|
|
* The Level 1 chip is used on some D-Link, SMC and Addtron NICs.
|
|
|
|
* It's a 64-bit PCI part that supports TCP/IP checksum offload,
|
|
|
|
* VLAN tagging/insertion, GMII and TBI (1000baseX) ports. There
|
|
|
|
* are three supported methods for data transfer between host and
|
|
|
|
* NIC: programmed I/O, traditional scatter/gather DMA and Packet
|
|
|
|
* Propulsion Technology (tm) DMA. The latter mechanism is a form
|
|
|
|
* of double buffer DMA where the packet data is copied to a
|
|
|
|
* pre-allocated DMA buffer who's physical address has been loaded
|
|
|
|
* into a table at device initialization time. The rationale is that
|
|
|
|
* the virtual to physical address translation needed for normal
|
|
|
|
* scatter/gather DMA is more expensive than the data copy needed
|
|
|
|
* for double buffering. This may be true in Windows NT and the like,
|
|
|
|
* but it isn't true for us, at least on the x86 arch. This driver
|
|
|
|
* uses the scatter/gather I/O method for both TX and RX.
|
|
|
|
*
|
|
|
|
* The LXT1001 only supports TCP/IP checksum offload on receive.
|
|
|
|
* Also, the VLAN tagging is done using a 16-entry table which allows
|
|
|
|
* the chip to perform hardware filtering based on VLAN tags. Sadly,
|
|
|
|
* our vlan support doesn't currently play well with this kind of
|
|
|
|
* hardware support.
|
|
|
|
*
|
|
|
|
* Special thanks to:
|
|
|
|
* - Jeff James at Intel, for arranging to have the LXT1001 manual
|
|
|
|
* released (at long last)
|
|
|
|
* - Beny Chen at D-Link, for actually sending it to me
|
|
|
|
* - Brad Short and Keith Alexis at SMC, for sending me sample
|
|
|
|
* SMC9462SX and SMC9462TX adapters for testing
|
|
|
|
* - Paul Saab at Y!, for not killing me (though it remains to be seen
|
|
|
|
* if in fact he did me much of a favor)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/sockio.h>
|
|
|
|
#include <sys/mbuf.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/kernel.h>
|
2004-05-30 20:08:47 +00:00
|
|
|
#include <sys/module.h>
|
2001-05-31 21:44:26 +00:00
|
|
|
#include <sys/socket.h>
|
|
|
|
|
|
|
|
#include <net/if.h>
|
|
|
|
#include <net/if_arp.h>
|
|
|
|
#include <net/ethernet.h>
|
|
|
|
#include <net/if_dl.h>
|
|
|
|
#include <net/if_media.h>
|
2005-06-10 16:49:24 +00:00
|
|
|
#include <net/if_types.h>
|
2001-05-31 21:44:26 +00:00
|
|
|
|
|
|
|
#include <net/bpf.h>
|
|
|
|
|
|
|
|
#include <vm/vm.h> /* for vtophys */
|
|
|
|
#include <vm/pmap.h> /* for vtophys */
|
|
|
|
#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:39:05 +00:00
|
|
|
#include <dev/pci/pcireg.h>
|
|
|
|
#include <dev/pci/pcivar.h>
|
2001-05-31 21:44:26 +00:00
|
|
|
|
|
|
|
#define LGE_USEIOSPACE
|
|
|
|
|
|
|
|
#include <dev/lge/if_lgereg.h>
|
|
|
|
|
2005-10-22 05:06:55 +00:00
|
|
|
/* "device miibus" required. See GENERIC if you get errors here. */
|
2001-05-31 21:44:26 +00:00
|
|
|
#include "miibus_if.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Various supported device vendors/types and their names.
|
|
|
|
*/
|
2012-11-05 19:16:27 +00:00
|
|
|
static const struct lge_type lge_devs[] = {
|
2001-05-31 21:44:26 +00:00
|
|
|
{ LGE_VENDORID, LGE_DEVICEID, "Level 1 Gigabit Ethernet" },
|
|
|
|
{ 0, 0, NULL }
|
|
|
|
};
|
|
|
|
|
2002-07-06 16:34:32 +00:00
|
|
|
static int lge_probe(device_t);
|
|
|
|
static int lge_attach(device_t);
|
|
|
|
static int lge_detach(device_t);
|
|
|
|
|
|
|
|
static int lge_alloc_jumbo_mem(struct lge_softc *);
|
|
|
|
static void lge_free_jumbo_mem(struct lge_softc *);
|
|
|
|
static void *lge_jalloc(struct lge_softc *);
|
|
|
|
static void lge_jfree(void *, void *);
|
|
|
|
|
|
|
|
static int lge_newbuf(struct lge_softc *, struct lge_rx_desc *, struct mbuf *);
|
|
|
|
static int lge_encap(struct lge_softc *, struct mbuf *, u_int32_t *);
|
|
|
|
static void lge_rxeof(struct lge_softc *, int);
|
|
|
|
static void lge_rxeoc(struct lge_softc *);
|
|
|
|
static void lge_txeof(struct lge_softc *);
|
|
|
|
static void lge_intr(void *);
|
|
|
|
static void lge_tick(void *);
|
|
|
|
static void lge_start(struct ifnet *);
|
2005-11-23 18:51:34 +00:00
|
|
|
static void lge_start_locked(struct ifnet *);
|
2002-07-06 16:34:32 +00:00
|
|
|
static int lge_ioctl(struct ifnet *, u_long, caddr_t);
|
|
|
|
static void lge_init(void *);
|
2005-11-23 18:51:34 +00:00
|
|
|
static void lge_init_locked(struct lge_softc *);
|
2002-07-06 16:34:32 +00:00
|
|
|
static void lge_stop(struct lge_softc *);
|
2009-11-19 22:14:23 +00:00
|
|
|
static void lge_watchdog(struct lge_softc *);
|
2007-11-22 02:45:00 +00:00
|
|
|
static int lge_shutdown(device_t);
|
2002-07-06 16:34:32 +00:00
|
|
|
static int lge_ifmedia_upd(struct ifnet *);
|
2005-11-23 18:51:34 +00:00
|
|
|
static void lge_ifmedia_upd_locked(struct ifnet *);
|
2002-07-06 16:34:32 +00:00
|
|
|
static void lge_ifmedia_sts(struct ifnet *, struct ifmediareq *);
|
|
|
|
|
|
|
|
static void lge_eeprom_getword(struct lge_softc *, int, u_int16_t *);
|
|
|
|
static void lge_read_eeprom(struct lge_softc *, caddr_t, int, int, int);
|
|
|
|
|
|
|
|
static int lge_miibus_readreg(device_t, int, int);
|
|
|
|
static int lge_miibus_writereg(device_t, int, int, int);
|
|
|
|
static void lge_miibus_statchg(device_t);
|
|
|
|
|
|
|
|
static void lge_setmulti(struct lge_softc *);
|
|
|
|
static void lge_reset(struct lge_softc *);
|
|
|
|
static int lge_list_rx_init(struct lge_softc *);
|
|
|
|
static int lge_list_tx_init(struct lge_softc *);
|
2001-05-31 21:44:26 +00:00
|
|
|
|
|
|
|
#ifdef LGE_USEIOSPACE
|
|
|
|
#define LGE_RES SYS_RES_IOPORT
|
|
|
|
#define LGE_RID LGE_PCI_LOIO
|
|
|
|
#else
|
|
|
|
#define LGE_RES SYS_RES_MEMORY
|
|
|
|
#define LGE_RID LGE_PCI_LOMEM
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static device_method_t lge_methods[] = {
|
|
|
|
/* Device interface */
|
|
|
|
DEVMETHOD(device_probe, lge_probe),
|
|
|
|
DEVMETHOD(device_attach, lge_attach),
|
|
|
|
DEVMETHOD(device_detach, lge_detach),
|
|
|
|
DEVMETHOD(device_shutdown, lge_shutdown),
|
|
|
|
|
|
|
|
/* MII interface */
|
|
|
|
DEVMETHOD(miibus_readreg, lge_miibus_readreg),
|
|
|
|
DEVMETHOD(miibus_writereg, lge_miibus_writereg),
|
|
|
|
DEVMETHOD(miibus_statchg, lge_miibus_statchg),
|
|
|
|
|
2011-11-22 21:28:20 +00:00
|
|
|
DEVMETHOD_END
|
2001-05-31 21:44:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static driver_t lge_driver = {
|
|
|
|
"lge",
|
|
|
|
lge_methods,
|
|
|
|
sizeof(struct lge_softc)
|
|
|
|
};
|
|
|
|
|
|
|
|
static devclass_t lge_devclass;
|
|
|
|
|
2003-04-15 06:37:30 +00:00
|
|
|
DRIVER_MODULE(lge, pci, lge_driver, lge_devclass, 0, 0);
|
2001-05-31 21:44:26 +00:00
|
|
|
DRIVER_MODULE(miibus, lge, miibus_driver, miibus_devclass, 0, 0);
|
2003-04-15 06:37:30 +00:00
|
|
|
MODULE_DEPEND(lge, pci, 1, 1, 1);
|
|
|
|
MODULE_DEPEND(lge, ether, 1, 1, 1);
|
|
|
|
MODULE_DEPEND(lge, miibus, 1, 1, 1);
|
2001-05-31 21:44:26 +00:00
|
|
|
|
|
|
|
#define LGE_SETBIT(sc, reg, x) \
|
|
|
|
CSR_WRITE_4(sc, reg, \
|
|
|
|
CSR_READ_4(sc, reg) | (x))
|
|
|
|
|
|
|
|
#define LGE_CLRBIT(sc, reg, x) \
|
|
|
|
CSR_WRITE_4(sc, reg, \
|
|
|
|
CSR_READ_4(sc, reg) & ~(x))
|
|
|
|
|
|
|
|
#define SIO_SET(x) \
|
|
|
|
CSR_WRITE_4(sc, LGE_MEAR, CSR_READ_4(sc, LGE_MEAR) | x)
|
|
|
|
|
|
|
|
#define SIO_CLR(x) \
|
|
|
|
CSR_WRITE_4(sc, LGE_MEAR, CSR_READ_4(sc, LGE_MEAR) & ~x)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Read a word of data stored in the EEPROM at address 'addr.'
|
|
|
|
*/
|
2002-07-06 16:34:32 +00:00
|
|
|
static void
|
|
|
|
lge_eeprom_getword(sc, addr, dest)
|
2001-05-31 21:44:26 +00:00
|
|
|
struct lge_softc *sc;
|
|
|
|
int addr;
|
|
|
|
u_int16_t *dest;
|
|
|
|
{
|
|
|
|
register int i;
|
|
|
|
u_int32_t val;
|
|
|
|
|
|
|
|
CSR_WRITE_4(sc, LGE_EECTL, LGE_EECTL_CMD_READ|
|
|
|
|
LGE_EECTL_SINGLEACCESS|((addr >> 1) << 8));
|
|
|
|
|
|
|
|
for (i = 0; i < LGE_TIMEOUT; i++)
|
|
|
|
if (!(CSR_READ_4(sc, LGE_EECTL) & LGE_EECTL_CMD_READ))
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (i == LGE_TIMEOUT) {
|
2006-09-15 15:16:12 +00:00
|
|
|
device_printf(sc->lge_dev, "EEPROM read timed out\n");
|
2001-05-31 21:44:26 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
val = CSR_READ_4(sc, LGE_EEDATA);
|
|
|
|
|
|
|
|
if (addr & 1)
|
|
|
|
*dest = (val >> 16) & 0xFFFF;
|
|
|
|
else
|
|
|
|
*dest = val & 0xFFFF;
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Read a sequence of words from the EEPROM.
|
|
|
|
*/
|
2002-07-06 16:34:32 +00:00
|
|
|
static void
|
|
|
|
lge_read_eeprom(sc, dest, off, cnt, swap)
|
2001-05-31 21:44:26 +00:00
|
|
|
struct lge_softc *sc;
|
|
|
|
caddr_t dest;
|
|
|
|
int off;
|
|
|
|
int cnt;
|
|
|
|
int swap;
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
u_int16_t word = 0, *ptr;
|
|
|
|
|
|
|
|
for (i = 0; i < cnt; i++) {
|
|
|
|
lge_eeprom_getword(sc, off + i, &word);
|
|
|
|
ptr = (u_int16_t *)(dest + (i * 2));
|
|
|
|
if (swap)
|
|
|
|
*ptr = ntohs(word);
|
|
|
|
else
|
|
|
|
*ptr = word;
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-07-06 16:34:32 +00:00
|
|
|
static int
|
|
|
|
lge_miibus_readreg(dev, phy, reg)
|
2001-05-31 21:44:26 +00:00
|
|
|
device_t dev;
|
|
|
|
int phy, reg;
|
|
|
|
{
|
|
|
|
struct lge_softc *sc;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
sc = device_get_softc(dev);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If we have a non-PCS PHY, pretend that the internal
|
|
|
|
* autoneg stuff at PHY address 0 isn't there so that
|
|
|
|
* the miibus code will find only the GMII PHY.
|
|
|
|
*/
|
|
|
|
if (sc->lge_pcs == 0 && phy == 0)
|
|
|
|
return(0);
|
|
|
|
|
|
|
|
CSR_WRITE_4(sc, LGE_GMIICTL, (phy << 8) | reg | LGE_GMIICMD_READ);
|
|
|
|
|
|
|
|
for (i = 0; i < LGE_TIMEOUT; i++)
|
|
|
|
if (!(CSR_READ_4(sc, LGE_GMIICTL) & LGE_GMIICTL_CMDBUSY))
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (i == LGE_TIMEOUT) {
|
2006-09-15 15:16:12 +00:00
|
|
|
device_printf(sc->lge_dev, "PHY read timed out\n");
|
2001-05-31 21:44:26 +00:00
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
return(CSR_READ_4(sc, LGE_GMIICTL) >> 16);
|
|
|
|
}
|
|
|
|
|
2002-07-06 16:34:32 +00:00
|
|
|
static int
|
|
|
|
lge_miibus_writereg(dev, phy, reg, data)
|
2001-05-31 21:44:26 +00:00
|
|
|
device_t dev;
|
|
|
|
int phy, reg, data;
|
|
|
|
{
|
|
|
|
struct lge_softc *sc;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
sc = device_get_softc(dev);
|
|
|
|
|
|
|
|
CSR_WRITE_4(sc, LGE_GMIICTL,
|
|
|
|
(data << 16) | (phy << 8) | reg | LGE_GMIICMD_WRITE);
|
|
|
|
|
|
|
|
for (i = 0; i < LGE_TIMEOUT; i++)
|
|
|
|
if (!(CSR_READ_4(sc, LGE_GMIICTL) & LGE_GMIICTL_CMDBUSY))
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (i == LGE_TIMEOUT) {
|
2006-09-15 15:16:12 +00:00
|
|
|
device_printf(sc->lge_dev, "PHY write timed out\n");
|
2001-05-31 21:44:26 +00:00
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
2002-07-06 16:34:32 +00:00
|
|
|
static void
|
|
|
|
lge_miibus_statchg(dev)
|
2001-05-31 21:44:26 +00:00
|
|
|
device_t dev;
|
|
|
|
{
|
|
|
|
struct lge_softc *sc;
|
|
|
|
struct mii_data *mii;
|
|
|
|
|
|
|
|
sc = device_get_softc(dev);
|
|
|
|
mii = device_get_softc(sc->lge_miibus);
|
|
|
|
|
|
|
|
LGE_CLRBIT(sc, LGE_GMIIMODE, LGE_GMIIMODE_SPEED);
|
|
|
|
switch (IFM_SUBTYPE(mii->mii_media_active)) {
|
2002-04-28 20:34:20 +00:00
|
|
|
case IFM_1000_T:
|
2001-05-31 21:44:26 +00:00
|
|
|
case IFM_1000_SX:
|
|
|
|
LGE_SETBIT(sc, LGE_GMIIMODE, LGE_SPEED_1000);
|
|
|
|
break;
|
|
|
|
case IFM_100_TX:
|
|
|
|
LGE_SETBIT(sc, LGE_GMIIMODE, LGE_SPEED_100);
|
|
|
|
break;
|
|
|
|
case IFM_10_T:
|
|
|
|
LGE_SETBIT(sc, LGE_GMIIMODE, LGE_SPEED_10);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/*
|
|
|
|
* Choose something, even if it's wrong. Clearing
|
|
|
|
* all the bits will hose autoneg on the internal
|
|
|
|
* PHY.
|
|
|
|
*/
|
|
|
|
LGE_SETBIT(sc, LGE_GMIIMODE, LGE_SPEED_1000);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((mii->mii_media_active & IFM_GMASK) == IFM_FDX) {
|
|
|
|
LGE_SETBIT(sc, LGE_GMIIMODE, LGE_GMIIMODE_FDX);
|
|
|
|
} else {
|
|
|
|
LGE_CLRBIT(sc, LGE_GMIIMODE, LGE_GMIIMODE_FDX);
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-07-06 16:34:32 +00:00
|
|
|
static void
|
|
|
|
lge_setmulti(sc)
|
2001-05-31 21:44:26 +00:00
|
|
|
struct lge_softc *sc;
|
|
|
|
{
|
|
|
|
struct ifnet *ifp;
|
|
|
|
struct ifmultiaddr *ifma;
|
|
|
|
u_int32_t h = 0, hashes[2] = { 0, 0 };
|
|
|
|
|
2005-06-10 16:49:24 +00:00
|
|
|
ifp = sc->lge_ifp;
|
2005-11-23 18:51:34 +00:00
|
|
|
LGE_LOCK_ASSERT(sc);
|
2001-05-31 21:44:26 +00:00
|
|
|
|
|
|
|
/* Make sure multicast hash table is enabled. */
|
|
|
|
CSR_WRITE_4(sc, LGE_MODE1, LGE_MODE1_SETRST_CTL1|LGE_MODE1_RX_MCAST);
|
|
|
|
|
|
|
|
if (ifp->if_flags & IFF_ALLMULTI || ifp->if_flags & IFF_PROMISC) {
|
|
|
|
CSR_WRITE_4(sc, LGE_MAR0, 0xFFFFFFFF);
|
|
|
|
CSR_WRITE_4(sc, LGE_MAR1, 0xFFFFFFFF);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* first, zot all the existing hash bits */
|
|
|
|
CSR_WRITE_4(sc, LGE_MAR0, 0);
|
|
|
|
CSR_WRITE_4(sc, LGE_MAR1, 0);
|
|
|
|
|
|
|
|
/* now program new ones */
|
2009-06-26 11:45:06 +00:00
|
|
|
if_maddr_rlock(ifp);
|
2001-05-31 21:44:26 +00:00
|
|
|
TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
|
|
|
|
if (ifma->ifma_addr->sa_family != AF_LINK)
|
|
|
|
continue;
|
2004-06-09 14:34:04 +00:00
|
|
|
h = ether_crc32_be(LLADDR((struct sockaddr_dl *)
|
|
|
|
ifma->ifma_addr), ETHER_ADDR_LEN) >> 26;
|
2001-05-31 21:44:26 +00:00
|
|
|
if (h < 32)
|
|
|
|
hashes[0] |= (1 << h);
|
|
|
|
else
|
|
|
|
hashes[1] |= (1 << (h - 32));
|
|
|
|
}
|
2009-06-26 11:45:06 +00:00
|
|
|
if_maddr_runlock(ifp);
|
2001-05-31 21:44:26 +00:00
|
|
|
|
|
|
|
CSR_WRITE_4(sc, LGE_MAR0, hashes[0]);
|
|
|
|
CSR_WRITE_4(sc, LGE_MAR1, hashes[1]);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-07-06 16:34:32 +00:00
|
|
|
static void
|
|
|
|
lge_reset(sc)
|
2001-05-31 21:44:26 +00:00
|
|
|
struct lge_softc *sc;
|
|
|
|
{
|
|
|
|
register int i;
|
|
|
|
|
|
|
|
LGE_SETBIT(sc, LGE_MODE1, LGE_MODE1_SETRST_CTL0|LGE_MODE1_SOFTRST);
|
|
|
|
|
|
|
|
for (i = 0; i < LGE_TIMEOUT; i++) {
|
|
|
|
if (!(CSR_READ_4(sc, LGE_MODE1) & LGE_MODE1_SOFTRST))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i == LGE_TIMEOUT)
|
2006-09-15 15:16:12 +00:00
|
|
|
device_printf(sc->lge_dev, "reset never completed\n");
|
2001-05-31 21:44:26 +00:00
|
|
|
|
|
|
|
/* Wait a little while for the chip to get its brains in order. */
|
|
|
|
DELAY(1000);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Probe for a Level 1 chip. Check the PCI vendor and device
|
|
|
|
* IDs against our list and return a device name if we find a match.
|
|
|
|
*/
|
2002-07-06 16:34:32 +00:00
|
|
|
static int
|
|
|
|
lge_probe(dev)
|
2001-05-31 21:44:26 +00:00
|
|
|
device_t dev;
|
|
|
|
{
|
2011-10-11 21:52:24 +00:00
|
|
|
const struct lge_type *t;
|
2001-05-31 21:44:26 +00:00
|
|
|
|
|
|
|
t = lge_devs;
|
|
|
|
|
|
|
|
while(t->lge_name != NULL) {
|
|
|
|
if ((pci_get_vendor(dev) == t->lge_vid) &&
|
|
|
|
(pci_get_device(dev) == t->lge_did)) {
|
|
|
|
device_set_desc(dev, t->lge_name);
|
2005-03-05 18:17:35 +00:00
|
|
|
return(BUS_PROBE_DEFAULT);
|
2001-05-31 21:44:26 +00:00
|
|
|
}
|
|
|
|
t++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return(ENXIO);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Attach the interface. Allocate softc structures, do ifmedia
|
|
|
|
* setup and ethernet/BPF attach.
|
|
|
|
*/
|
2002-07-06 16:34:32 +00:00
|
|
|
static int
|
|
|
|
lge_attach(dev)
|
2001-05-31 21:44:26 +00:00
|
|
|
device_t dev;
|
|
|
|
{
|
|
|
|
u_char eaddr[ETHER_ADDR_LEN];
|
|
|
|
struct lge_softc *sc;
|
2005-10-03 15:52:34 +00:00
|
|
|
struct ifnet *ifp = NULL;
|
|
|
|
int error = 0, rid;
|
2001-05-31 21:44:26 +00:00
|
|
|
|
|
|
|
sc = device_get_softc(dev);
|
2006-09-15 15:16:12 +00:00
|
|
|
sc->lge_dev = dev;
|
|
|
|
|
2005-11-23 18:51:34 +00:00
|
|
|
mtx_init(&sc->lge_mtx, device_get_nameunit(dev), MTX_NETWORK_LOCK,
|
|
|
|
MTX_DEF);
|
|
|
|
callout_init_mtx(&sc->lge_stat_callout, &sc->lge_mtx, 0);
|
2005-10-03 15:52:34 +00:00
|
|
|
|
2001-05-31 21:44:26 +00:00
|
|
|
/*
|
|
|
|
* Map control/status registers.
|
|
|
|
*/
|
|
|
|
pci_enable_busmaster(dev);
|
|
|
|
|
|
|
|
rid = LGE_RID;
|
2004-03-17 17:50:55 +00:00
|
|
|
sc->lge_res = bus_alloc_resource_any(dev, LGE_RES, &rid, RF_ACTIVE);
|
2001-05-31 21:44:26 +00:00
|
|
|
|
|
|
|
if (sc->lge_res == NULL) {
|
2005-10-03 15:52:34 +00:00
|
|
|
device_printf(dev, "couldn't map ports/memory\n");
|
2001-05-31 21:44:26 +00:00
|
|
|
error = ENXIO;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
sc->lge_btag = rman_get_bustag(sc->lge_res);
|
|
|
|
sc->lge_bhandle = rman_get_bushandle(sc->lge_res);
|
|
|
|
|
|
|
|
/* Allocate interrupt */
|
|
|
|
rid = 0;
|
2004-03-17 17:50:55 +00:00
|
|
|
sc->lge_irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid,
|
2001-05-31 21:44:26 +00:00
|
|
|
RF_SHAREABLE | RF_ACTIVE);
|
|
|
|
|
|
|
|
if (sc->lge_irq == NULL) {
|
2005-10-03 15:52:34 +00:00
|
|
|
device_printf(dev, "couldn't map interrupt\n");
|
2001-05-31 21:44:26 +00:00
|
|
|
error = ENXIO;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Reset the adapter. */
|
|
|
|
lge_reset(sc);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get station address from the EEPROM.
|
|
|
|
*/
|
|
|
|
lge_read_eeprom(sc, (caddr_t)&eaddr[0], LGE_EE_NODEADDR_0, 1, 0);
|
|
|
|
lge_read_eeprom(sc, (caddr_t)&eaddr[2], LGE_EE_NODEADDR_1, 1, 0);
|
|
|
|
lge_read_eeprom(sc, (caddr_t)&eaddr[4], LGE_EE_NODEADDR_2, 1, 0);
|
|
|
|
|
|
|
|
sc->lge_ldata = contigmalloc(sizeof(struct lge_list_data), M_DEVBUF,
|
2005-11-23 18:51:34 +00:00
|
|
|
M_NOWAIT | M_ZERO, 0, 0xffffffff, PAGE_SIZE, 0);
|
2001-05-31 21:44:26 +00:00
|
|
|
|
|
|
|
if (sc->lge_ldata == NULL) {
|
2005-10-03 15:52:34 +00:00
|
|
|
device_printf(dev, "no memory for list buffers!\n");
|
2001-05-31 21:44:26 +00:00
|
|
|
error = ENXIO;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Try to allocate memory for jumbo buffers. */
|
|
|
|
if (lge_alloc_jumbo_mem(sc)) {
|
2005-10-03 15:52:34 +00:00
|
|
|
device_printf(dev, "jumbo buffer allocation failed\n");
|
2001-05-31 21:44:26 +00:00
|
|
|
error = ENXIO;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2005-06-10 16:49:24 +00:00
|
|
|
ifp = sc->lge_ifp = if_alloc(IFT_ETHER);
|
|
|
|
if (ifp == NULL) {
|
2005-10-03 15:52:34 +00:00
|
|
|
device_printf(dev, "can not if_alloc()\n");
|
2005-06-10 16:49:24 +00:00
|
|
|
error = ENOSPC;
|
|
|
|
goto fail;
|
|
|
|
}
|
2001-05-31 21:44:26 +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));
|
2005-11-23 18:51:34 +00:00
|
|
|
ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
|
2001-05-31 21:44:26 +00:00
|
|
|
ifp->if_ioctl = lge_ioctl;
|
|
|
|
ifp->if_start = lge_start;
|
|
|
|
ifp->if_init = lge_init;
|
|
|
|
ifp->if_snd.ifq_maxlen = LGE_TX_LIST_CNT - 1;
|
2001-09-18 20:19:28 +00:00
|
|
|
ifp->if_capabilities = IFCAP_RXCSUM;
|
|
|
|
ifp->if_capenable = ifp->if_capabilities;
|
2001-05-31 21:44:26 +00:00
|
|
|
|
|
|
|
if (CSR_READ_4(sc, LGE_GMIIMODE) & LGE_GMIIMODE_PCSENH)
|
|
|
|
sc->lge_pcs = 1;
|
|
|
|
else
|
|
|
|
sc->lge_pcs = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Do MII setup.
|
|
|
|
*/
|
2010-10-15 15:00:30 +00:00
|
|
|
error = mii_attach(dev, &sc->lge_miibus, ifp, lge_ifmedia_upd,
|
|
|
|
lge_ifmedia_sts, BMSR_DEFCAPMASK, MII_PHY_ANY, MII_OFFSET_ANY, 0);
|
|
|
|
if (error != 0) {
|
|
|
|
device_printf(dev, "attaching PHYs failed\n");
|
2001-05-31 21:44:26 +00:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Call MI attach routine.
|
|
|
|
*/
|
2002-11-14 23:54:55 +00:00
|
|
|
ether_ifattach(ifp, eaddr);
|
2005-11-23 18:51:34 +00:00
|
|
|
|
|
|
|
error = bus_setup_intr(dev, sc->lge_irq, INTR_TYPE_NET | INTR_MPSAFE,
|
2007-02-23 12:19:07 +00:00
|
|
|
NULL, lge_intr, sc, &sc->lge_intrhand);
|
2005-11-23 18:51:34 +00:00
|
|
|
|
|
|
|
if (error) {
|
|
|
|
ether_ifdetach(ifp);
|
|
|
|
device_printf(dev, "couldn't set up irq\n");
|
|
|
|
goto fail;
|
|
|
|
}
|
2005-10-03 15:52:34 +00:00
|
|
|
return (0);
|
2001-05-31 21:44:26 +00:00
|
|
|
|
|
|
|
fail:
|
2008-03-05 05:36:09 +00:00
|
|
|
lge_free_jumbo_mem(sc);
|
2005-10-03 15:52:34 +00:00
|
|
|
if (sc->lge_ldata)
|
|
|
|
contigfree(sc->lge_ldata,
|
|
|
|
sizeof(struct lge_list_data), M_DEVBUF);
|
|
|
|
if (ifp)
|
|
|
|
if_free(ifp);
|
|
|
|
if (sc->lge_irq)
|
|
|
|
bus_release_resource(dev, SYS_RES_IRQ, 0, sc->lge_irq);
|
|
|
|
if (sc->lge_res)
|
|
|
|
bus_release_resource(dev, LGE_RES, LGE_RID, sc->lge_res);
|
2005-11-23 18:51:34 +00:00
|
|
|
mtx_destroy(&sc->lge_mtx);
|
2001-05-31 21:44:26 +00:00
|
|
|
return(error);
|
|
|
|
}
|
|
|
|
|
2002-07-06 16:34:32 +00:00
|
|
|
static int
|
|
|
|
lge_detach(dev)
|
2001-05-31 21:44:26 +00:00
|
|
|
device_t dev;
|
|
|
|
{
|
|
|
|
struct lge_softc *sc;
|
|
|
|
struct ifnet *ifp;
|
|
|
|
|
|
|
|
sc = device_get_softc(dev);
|
2005-06-10 16:49:24 +00:00
|
|
|
ifp = sc->lge_ifp;
|
2001-05-31 21:44:26 +00:00
|
|
|
|
2005-11-23 18:51:34 +00:00
|
|
|
LGE_LOCK(sc);
|
2001-05-31 21:44:26 +00:00
|
|
|
lge_reset(sc);
|
|
|
|
lge_stop(sc);
|
2005-11-23 18:51:34 +00:00
|
|
|
LGE_UNLOCK(sc);
|
|
|
|
callout_drain(&sc->lge_stat_callout);
|
2002-11-14 23:54:55 +00:00
|
|
|
ether_ifdetach(ifp);
|
2001-05-31 21:44:26 +00:00
|
|
|
|
|
|
|
bus_generic_detach(dev);
|
|
|
|
device_delete_child(dev, sc->lge_miibus);
|
|
|
|
|
|
|
|
bus_teardown_intr(dev, sc->lge_irq, sc->lge_intrhand);
|
|
|
|
bus_release_resource(dev, SYS_RES_IRQ, 0, sc->lge_irq);
|
|
|
|
bus_release_resource(dev, LGE_RES, LGE_RID, sc->lge_res);
|
|
|
|
|
|
|
|
contigfree(sc->lge_ldata, sizeof(struct lge_list_data), M_DEVBUF);
|
2005-09-19 03:10:21 +00:00
|
|
|
if_free(ifp);
|
2001-05-31 21:44:26 +00:00
|
|
|
lge_free_jumbo_mem(sc);
|
2005-11-23 18:51:34 +00:00
|
|
|
mtx_destroy(&sc->lge_mtx);
|
2001-05-31 21:44:26 +00:00
|
|
|
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize the transmit descriptors.
|
|
|
|
*/
|
2002-07-06 16:34:32 +00:00
|
|
|
static int
|
|
|
|
lge_list_tx_init(sc)
|
2001-05-31 21:44:26 +00:00
|
|
|
struct lge_softc *sc;
|
|
|
|
{
|
|
|
|
struct lge_list_data *ld;
|
|
|
|
struct lge_ring_data *cd;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
cd = &sc->lge_cdata;
|
|
|
|
ld = sc->lge_ldata;
|
|
|
|
for (i = 0; i < LGE_TX_LIST_CNT; i++) {
|
|
|
|
ld->lge_tx_list[i].lge_mbuf = NULL;
|
|
|
|
ld->lge_tx_list[i].lge_ctl = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
cd->lge_tx_prod = cd->lge_tx_cons = 0;
|
|
|
|
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize the RX descriptors and allocate mbufs for them. Note that
|
|
|
|
* we arralge the descriptors in a closed ring, so that the last descriptor
|
|
|
|
* points back to the first.
|
|
|
|
*/
|
2002-07-06 16:34:32 +00:00
|
|
|
static int
|
|
|
|
lge_list_rx_init(sc)
|
2001-05-31 21:44:26 +00:00
|
|
|
struct lge_softc *sc;
|
|
|
|
{
|
|
|
|
struct lge_list_data *ld;
|
|
|
|
struct lge_ring_data *cd;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
ld = sc->lge_ldata;
|
|
|
|
cd = &sc->lge_cdata;
|
|
|
|
|
|
|
|
cd->lge_rx_prod = cd->lge_rx_cons = 0;
|
|
|
|
|
|
|
|
CSR_WRITE_4(sc, LGE_RXDESC_ADDR_HI, 0);
|
|
|
|
|
|
|
|
for (i = 0; i < LGE_RX_LIST_CNT; i++) {
|
|
|
|
if (CSR_READ_1(sc, LGE_RXCMDFREE_8BIT) == 0)
|
|
|
|
break;
|
|
|
|
if (lge_newbuf(sc, &ld->lge_rx_list[i], NULL) == ENOBUFS)
|
|
|
|
return(ENOBUFS);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Clear possible 'rx command queue empty' interrupt. */
|
|
|
|
CSR_READ_4(sc, LGE_ISR);
|
|
|
|
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize an RX descriptor and attach an MBUF cluster.
|
|
|
|
*/
|
2002-07-06 16:34:32 +00:00
|
|
|
static int
|
|
|
|
lge_newbuf(sc, c, m)
|
2001-05-31 21:44:26 +00:00
|
|
|
struct lge_softc *sc;
|
|
|
|
struct lge_rx_desc *c;
|
|
|
|
struct mbuf *m;
|
|
|
|
{
|
|
|
|
struct mbuf *m_new = NULL;
|
|
|
|
caddr_t *buf = NULL;
|
|
|
|
|
|
|
|
if (m == NULL) {
|
2012-12-04 09:32:43 +00:00
|
|
|
MGETHDR(m_new, M_NOWAIT, MT_DATA);
|
2001-05-31 21:44:26 +00:00
|
|
|
if (m_new == NULL) {
|
2006-09-15 15:16:12 +00:00
|
|
|
device_printf(sc->lge_dev, "no memory for rx list "
|
2005-10-03 15:52:34 +00:00
|
|
|
"-- packet dropped!\n");
|
2001-05-31 21:44:26 +00:00
|
|
|
return(ENOBUFS);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Allocate the jumbo buffer */
|
|
|
|
buf = lge_jalloc(sc);
|
|
|
|
if (buf == NULL) {
|
|
|
|
#ifdef LGE_VERBOSE
|
2006-09-15 15:16:12 +00:00
|
|
|
device_printf(sc->lge_dev, "jumbo allocation failed "
|
2005-10-03 15:52:34 +00:00
|
|
|
"-- packet dropped!\n");
|
2001-05-31 21:44:26 +00:00
|
|
|
#endif
|
|
|
|
m_freem(m_new);
|
|
|
|
return(ENOBUFS);
|
|
|
|
}
|
|
|
|
/* Attach the buffer to the mbuf */
|
|
|
|
m_new->m_data = (void *)buf;
|
2001-06-18 22:04:40 +00:00
|
|
|
m_new->m_len = m_new->m_pkthdr.len = LGE_JUMBO_FRAMELEN;
|
|
|
|
MEXTADD(m_new, buf, LGE_JUMBO_FRAMELEN, lge_jfree,
|
2008-02-01 19:36:27 +00:00
|
|
|
buf, (struct lge_softc *)sc, 0, EXT_NET_DRV);
|
2001-05-31 21:44:26 +00:00
|
|
|
} else {
|
|
|
|
m_new = m;
|
2001-06-18 22:04:40 +00:00
|
|
|
m_new->m_len = m_new->m_pkthdr.len = LGE_JUMBO_FRAMELEN;
|
2001-05-31 21:44:26 +00:00
|
|
|
m_new->m_data = m_new->m_ext.ext_buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Adjust alignment so packet payload begins on a
|
|
|
|
* longword boundary. Mandatory for Alpha, useful on
|
|
|
|
* x86 too.
|
|
|
|
*/
|
|
|
|
m_adj(m_new, ETHER_ALIGN);
|
|
|
|
|
|
|
|
c->lge_mbuf = m_new;
|
|
|
|
c->lge_fragptr_hi = 0;
|
|
|
|
c->lge_fragptr_lo = vtophys(mtod(m_new, caddr_t));
|
|
|
|
c->lge_fraglen = m_new->m_len;
|
|
|
|
c->lge_ctl = m_new->m_len | LGE_RXCTL_WANTINTR | LGE_FRAGCNT(1);
|
|
|
|
c->lge_sts = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Put this buffer in the RX command FIFO. To do this,
|
|
|
|
* we just write the physical address of the descriptor
|
|
|
|
* into the RX descriptor address registers. Note that
|
|
|
|
* there are two registers, one high DWORD and one low
|
|
|
|
* DWORD, which lets us specify a 64-bit address if
|
|
|
|
* desired. We only use a 32-bit address for now.
|
|
|
|
* Writing to the low DWORD register is what actually
|
|
|
|
* causes the command to be issued, so we do that
|
|
|
|
* last.
|
|
|
|
*/
|
|
|
|
CSR_WRITE_4(sc, LGE_RXDESC_ADDR_LO, vtophys(c));
|
|
|
|
LGE_INC(sc->lge_cdata.lge_rx_prod, LGE_RX_LIST_CNT);
|
|
|
|
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
2002-07-06 16:34:32 +00:00
|
|
|
static int
|
|
|
|
lge_alloc_jumbo_mem(sc)
|
2001-05-31 21:44:26 +00:00
|
|
|
struct lge_softc *sc;
|
|
|
|
{
|
|
|
|
caddr_t ptr;
|
|
|
|
register int i;
|
|
|
|
struct lge_jpool_entry *entry;
|
|
|
|
|
|
|
|
/* Grab a big chunk o' storage. */
|
|
|
|
sc->lge_cdata.lge_jumbo_buf = contigmalloc(LGE_JMEM, M_DEVBUF,
|
|
|
|
M_NOWAIT, 0, 0xffffffff, PAGE_SIZE, 0);
|
|
|
|
|
|
|
|
if (sc->lge_cdata.lge_jumbo_buf == NULL) {
|
2006-09-15 15:16:12 +00:00
|
|
|
device_printf(sc->lge_dev, "no memory for jumbo buffers!\n");
|
2001-05-31 21:44:26 +00:00
|
|
|
return(ENOBUFS);
|
|
|
|
}
|
|
|
|
|
|
|
|
SLIST_INIT(&sc->lge_jfree_listhead);
|
|
|
|
SLIST_INIT(&sc->lge_jinuse_listhead);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Now divide it up into 9K pieces and save the addresses
|
|
|
|
* in an array.
|
|
|
|
*/
|
|
|
|
ptr = sc->lge_cdata.lge_jumbo_buf;
|
|
|
|
for (i = 0; i < LGE_JSLOTS; i++) {
|
|
|
|
sc->lge_cdata.lge_jslots[i] = ptr;
|
2001-06-18 22:04:40 +00:00
|
|
|
ptr += LGE_JLEN;
|
2005-10-03 15:52:34 +00:00
|
|
|
entry = malloc(sizeof(struct lge_jpool_entry),
|
2001-05-31 21:44:26 +00:00
|
|
|
M_DEVBUF, M_NOWAIT);
|
|
|
|
if (entry == NULL) {
|
2006-09-15 15:16:12 +00:00
|
|
|
device_printf(sc->lge_dev, "no memory for jumbo "
|
2005-10-03 15:52:34 +00:00
|
|
|
"buffer queue!\n");
|
2001-05-31 21:44:26 +00:00
|
|
|
return(ENOBUFS);
|
|
|
|
}
|
|
|
|
entry->slot = i;
|
|
|
|
SLIST_INSERT_HEAD(&sc->lge_jfree_listhead,
|
|
|
|
entry, jpool_entries);
|
|
|
|
}
|
|
|
|
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
2002-07-06 16:34:32 +00:00
|
|
|
static void
|
|
|
|
lge_free_jumbo_mem(sc)
|
2001-05-31 21:44:26 +00:00
|
|
|
struct lge_softc *sc;
|
|
|
|
{
|
|
|
|
struct lge_jpool_entry *entry;
|
|
|
|
|
2008-03-05 05:36:09 +00:00
|
|
|
if (sc->lge_cdata.lge_jumbo_buf == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
while ((entry = SLIST_FIRST(&sc->lge_jinuse_listhead))) {
|
|
|
|
device_printf(sc->lge_dev,
|
|
|
|
"asked to free buffer that is in use!\n");
|
|
|
|
SLIST_REMOVE_HEAD(&sc->lge_jinuse_listhead, jpool_entries);
|
|
|
|
SLIST_INSERT_HEAD(&sc->lge_jfree_listhead, entry,
|
|
|
|
jpool_entries);
|
|
|
|
}
|
|
|
|
while (!SLIST_EMPTY(&sc->lge_jfree_listhead)) {
|
2001-05-31 21:44:26 +00:00
|
|
|
entry = SLIST_FIRST(&sc->lge_jfree_listhead);
|
|
|
|
SLIST_REMOVE_HEAD(&sc->lge_jfree_listhead, jpool_entries);
|
2001-06-18 22:04:40 +00:00
|
|
|
free(entry, M_DEVBUF);
|
2001-05-31 21:44:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
contigfree(sc->lge_cdata.lge_jumbo_buf, LGE_JMEM, M_DEVBUF);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate a jumbo buffer.
|
|
|
|
*/
|
2002-07-06 16:34:32 +00:00
|
|
|
static void *
|
|
|
|
lge_jalloc(sc)
|
2001-05-31 21:44:26 +00:00
|
|
|
struct lge_softc *sc;
|
|
|
|
{
|
|
|
|
struct lge_jpool_entry *entry;
|
|
|
|
|
|
|
|
entry = SLIST_FIRST(&sc->lge_jfree_listhead);
|
|
|
|
|
|
|
|
if (entry == NULL) {
|
|
|
|
#ifdef LGE_VERBOSE
|
2006-09-15 15:16:12 +00:00
|
|
|
device_printf(sc->lge_dev, "no free jumbo buffers\n");
|
2001-05-31 21:44:26 +00:00
|
|
|
#endif
|
|
|
|
return(NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
SLIST_REMOVE_HEAD(&sc->lge_jfree_listhead, jpool_entries);
|
|
|
|
SLIST_INSERT_HEAD(&sc->lge_jinuse_listhead, entry, jpool_entries);
|
|
|
|
return(sc->lge_cdata.lge_jslots[entry->slot]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Release a jumbo buffer.
|
|
|
|
*/
|
2002-07-06 16:34:32 +00:00
|
|
|
static void
|
|
|
|
lge_jfree(buf, args)
|
2002-06-29 01:36:59 +00:00
|
|
|
void *buf;
|
2001-05-31 21:44:26 +00:00
|
|
|
void *args;
|
|
|
|
{
|
|
|
|
struct lge_softc *sc;
|
|
|
|
int i;
|
|
|
|
struct lge_jpool_entry *entry;
|
|
|
|
|
|
|
|
/* Extract the softc struct pointer. */
|
|
|
|
sc = args;
|
|
|
|
|
|
|
|
if (sc == NULL)
|
|
|
|
panic("lge_jfree: can't find softc pointer!");
|
|
|
|
|
|
|
|
/* calculate the slot this buffer belongs to */
|
|
|
|
i = ((vm_offset_t)buf
|
|
|
|
- (vm_offset_t)sc->lge_cdata.lge_jumbo_buf) / LGE_JLEN;
|
|
|
|
|
|
|
|
if ((i < 0) || (i >= LGE_JSLOTS))
|
|
|
|
panic("lge_jfree: asked to free buffer that we don't manage!");
|
|
|
|
|
|
|
|
entry = SLIST_FIRST(&sc->lge_jinuse_listhead);
|
|
|
|
if (entry == NULL)
|
|
|
|
panic("lge_jfree: buffer not in use!");
|
|
|
|
entry->slot = i;
|
|
|
|
SLIST_REMOVE_HEAD(&sc->lge_jinuse_listhead, jpool_entries);
|
|
|
|
SLIST_INSERT_HEAD(&sc->lge_jfree_listhead, entry, jpool_entries);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* A frame has been uploaded: pass the resulting mbuf chain up to
|
|
|
|
* the higher level protocols.
|
|
|
|
*/
|
2002-07-06 16:34:32 +00:00
|
|
|
static void
|
|
|
|
lge_rxeof(sc, cnt)
|
2001-05-31 21:44:26 +00:00
|
|
|
struct lge_softc *sc;
|
|
|
|
int cnt;
|
|
|
|
{
|
|
|
|
struct mbuf *m;
|
|
|
|
struct ifnet *ifp;
|
|
|
|
struct lge_rx_desc *cur_rx;
|
|
|
|
int c, i, total_len = 0;
|
|
|
|
u_int32_t rxsts, rxctl;
|
|
|
|
|
2005-06-10 16:49:24 +00:00
|
|
|
ifp = sc->lge_ifp;
|
2001-05-31 21:44:26 +00:00
|
|
|
|
|
|
|
/* Find out how many frames were processed. */
|
|
|
|
c = cnt;
|
|
|
|
i = sc->lge_cdata.lge_rx_cons;
|
|
|
|
|
|
|
|
/* Suck them in. */
|
|
|
|
while(c) {
|
|
|
|
struct mbuf *m0 = NULL;
|
|
|
|
|
|
|
|
cur_rx = &sc->lge_ldata->lge_rx_list[i];
|
|
|
|
rxctl = cur_rx->lge_ctl;
|
|
|
|
rxsts = cur_rx->lge_sts;
|
|
|
|
m = cur_rx->lge_mbuf;
|
|
|
|
cur_rx->lge_mbuf = NULL;
|
|
|
|
total_len = LGE_RXBYTES(cur_rx);
|
|
|
|
LGE_INC(i, LGE_RX_LIST_CNT);
|
|
|
|
c--;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
* comes up in the ring.
|
|
|
|
*/
|
|
|
|
if (rxctl & LGE_RXCTL_ERRMASK) {
|
|
|
|
ifp->if_ierrors++;
|
|
|
|
lge_newbuf(sc, &LGE_RXTAIL(sc), m);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lge_newbuf(sc, &LGE_RXTAIL(sc), NULL) == ENOBUFS) {
|
2001-06-20 19:48:35 +00:00
|
|
|
m0 = m_devget(mtod(m, char *), total_len, ETHER_ALIGN,
|
|
|
|
ifp, NULL);
|
2001-05-31 21:44:26 +00:00
|
|
|
lge_newbuf(sc, &LGE_RXTAIL(sc), m);
|
|
|
|
if (m0 == NULL) {
|
2006-09-15 15:16:12 +00:00
|
|
|
device_printf(sc->lge_dev, "no receive buffers "
|
2005-10-03 15:52:34 +00:00
|
|
|
"available -- packet dropped!\n");
|
2001-05-31 21:44:26 +00:00
|
|
|
ifp->if_ierrors++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
m = m0;
|
|
|
|
} else {
|
|
|
|
m->m_pkthdr.rcvif = ifp;
|
|
|
|
m->m_pkthdr.len = m->m_len = total_len;
|
|
|
|
}
|
|
|
|
|
|
|
|
ifp->if_ipackets++;
|
|
|
|
|
|
|
|
/* Do IP checksum checking. */
|
|
|
|
if (rxsts & LGE_RXSTS_ISIP)
|
|
|
|
m->m_pkthdr.csum_flags |= CSUM_IP_CHECKED;
|
|
|
|
if (!(rxsts & LGE_RXSTS_IPCSUMERR))
|
|
|
|
m->m_pkthdr.csum_flags |= CSUM_IP_VALID;
|
|
|
|
if ((rxsts & LGE_RXSTS_ISTCP &&
|
|
|
|
!(rxsts & LGE_RXSTS_TCPCSUMERR)) ||
|
|
|
|
(rxsts & LGE_RXSTS_ISUDP &&
|
|
|
|
!(rxsts & LGE_RXSTS_UDPCSUMERR))) {
|
|
|
|
m->m_pkthdr.csum_flags |=
|
|
|
|
CSUM_DATA_VALID|CSUM_PSEUDO_HDR;
|
2001-06-15 19:02:55 +00:00
|
|
|
m->m_pkthdr.csum_data = 0xffff;
|
2001-05-31 21:44:26 +00:00
|
|
|
}
|
2001-06-15 19:02:55 +00:00
|
|
|
|
2005-11-23 18:51:34 +00:00
|
|
|
LGE_UNLOCK(sc);
|
2002-11-14 23:54:55 +00:00
|
|
|
(*ifp->if_input)(ifp, m);
|
2005-11-23 18:51:34 +00:00
|
|
|
LGE_LOCK(sc);
|
2001-05-31 21:44:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sc->lge_cdata.lge_rx_cons = i;
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-09-28 17:15:38 +00:00
|
|
|
static void
|
2002-07-06 16:34:32 +00:00
|
|
|
lge_rxeoc(sc)
|
2001-05-31 21:44:26 +00:00
|
|
|
struct lge_softc *sc;
|
|
|
|
{
|
|
|
|
struct ifnet *ifp;
|
|
|
|
|
2005-06-10 16:49:24 +00:00
|
|
|
ifp = sc->lge_ifp;
|
2005-08-09 10:20:02 +00:00
|
|
|
ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
|
2005-11-23 18:51:34 +00:00
|
|
|
lge_init_locked(sc);
|
2001-05-31 21:44:26 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* A frame was downloaded to the chip. It's safe for us to clean up
|
|
|
|
* the list buffers.
|
|
|
|
*/
|
|
|
|
|
2002-07-06 16:34:32 +00:00
|
|
|
static void
|
|
|
|
lge_txeof(sc)
|
2001-05-31 21:44:26 +00:00
|
|
|
struct lge_softc *sc;
|
|
|
|
{
|
|
|
|
struct lge_tx_desc *cur_tx = NULL;
|
|
|
|
struct ifnet *ifp;
|
|
|
|
u_int32_t idx, txdone;
|
|
|
|
|
2005-06-10 16:49:24 +00:00
|
|
|
ifp = sc->lge_ifp;
|
2001-05-31 21:44:26 +00:00
|
|
|
|
|
|
|
/* Clear the timeout timer. */
|
2009-11-19 22:14:23 +00:00
|
|
|
sc->lge_timer = 0;
|
2001-05-31 21:44:26 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Go through our tx list and free mbufs for those
|
|
|
|
* frames that have been transmitted.
|
|
|
|
*/
|
|
|
|
idx = sc->lge_cdata.lge_tx_cons;
|
|
|
|
txdone = CSR_READ_1(sc, LGE_TXDMADONE_8BIT);
|
|
|
|
|
|
|
|
while (idx != sc->lge_cdata.lge_tx_prod && txdone) {
|
|
|
|
cur_tx = &sc->lge_ldata->lge_tx_list[idx];
|
|
|
|
|
|
|
|
ifp->if_opackets++;
|
|
|
|
if (cur_tx->lge_mbuf != NULL) {
|
|
|
|
m_freem(cur_tx->lge_mbuf);
|
|
|
|
cur_tx->lge_mbuf = NULL;
|
|
|
|
}
|
|
|
|
cur_tx->lge_ctl = 0;
|
|
|
|
|
|
|
|
txdone--;
|
|
|
|
LGE_INC(idx, LGE_TX_LIST_CNT);
|
2009-11-19 22:14:23 +00:00
|
|
|
sc->lge_timer = 0;
|
2001-05-31 21:44:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sc->lge_cdata.lge_tx_cons = idx;
|
|
|
|
|
|
|
|
if (cur_tx != NULL)
|
2005-08-09 10:20:02 +00:00
|
|
|
ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
|
2001-05-31 21:44:26 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-07-06 16:34:32 +00:00
|
|
|
static void
|
|
|
|
lge_tick(xsc)
|
2001-05-31 21:44:26 +00:00
|
|
|
void *xsc;
|
|
|
|
{
|
|
|
|
struct lge_softc *sc;
|
|
|
|
struct mii_data *mii;
|
|
|
|
struct ifnet *ifp;
|
|
|
|
|
|
|
|
sc = xsc;
|
2005-06-10 16:49:24 +00:00
|
|
|
ifp = sc->lge_ifp;
|
2005-11-23 18:51:34 +00:00
|
|
|
LGE_LOCK_ASSERT(sc);
|
2001-05-31 21:44:26 +00:00
|
|
|
|
|
|
|
CSR_WRITE_4(sc, LGE_STATSIDX, LGE_STATS_SINGLE_COLL_PKTS);
|
|
|
|
ifp->if_collisions += CSR_READ_4(sc, LGE_STATSVAL);
|
|
|
|
CSR_WRITE_4(sc, LGE_STATSIDX, LGE_STATS_MULTI_COLL_PKTS);
|
|
|
|
ifp->if_collisions += CSR_READ_4(sc, LGE_STATSVAL);
|
|
|
|
|
|
|
|
if (!sc->lge_link) {
|
|
|
|
mii = device_get_softc(sc->lge_miibus);
|
|
|
|
mii_tick(mii);
|
|
|
|
if (mii->mii_media_status & IFM_ACTIVE &&
|
|
|
|
IFM_SUBTYPE(mii->mii_media_active) != IFM_NONE) {
|
|
|
|
sc->lge_link++;
|
2004-11-08 19:21:57 +00:00
|
|
|
if (bootverbose &&
|
|
|
|
(IFM_SUBTYPE(mii->mii_media_active) == IFM_1000_SX||
|
|
|
|
IFM_SUBTYPE(mii->mii_media_active) == IFM_1000_T))
|
2006-09-15 15:16:12 +00:00
|
|
|
device_printf(sc->lge_dev, "gigabit link up\n");
|
2001-05-31 21:44:26 +00:00
|
|
|
if (ifp->if_snd.ifq_head != NULL)
|
2005-11-23 18:51:34 +00:00
|
|
|
lge_start_locked(ifp);
|
2001-05-31 21:44:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-19 22:14:23 +00:00
|
|
|
if (sc->lge_timer != 0 && --sc->lge_timer == 0)
|
|
|
|
lge_watchdog(sc);
|
2005-11-23 18:51:34 +00:00
|
|
|
callout_reset(&sc->lge_stat_callout, hz, lge_tick, sc);
|
2001-05-31 21:44:26 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-07-06 16:34:32 +00:00
|
|
|
static void
|
|
|
|
lge_intr(arg)
|
2001-05-31 21:44:26 +00:00
|
|
|
void *arg;
|
|
|
|
{
|
|
|
|
struct lge_softc *sc;
|
|
|
|
struct ifnet *ifp;
|
|
|
|
u_int32_t status;
|
|
|
|
|
|
|
|
sc = arg;
|
2005-06-10 16:49:24 +00:00
|
|
|
ifp = sc->lge_ifp;
|
2005-11-23 18:51:34 +00:00
|
|
|
LGE_LOCK(sc);
|
2001-05-31 21:44:26 +00:00
|
|
|
|
|
|
|
/* Supress unwanted interrupts */
|
|
|
|
if (!(ifp->if_flags & IFF_UP)) {
|
|
|
|
lge_stop(sc);
|
2005-11-23 18:51:34 +00:00
|
|
|
LGE_UNLOCK(sc);
|
2001-05-31 21:44:26 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
/*
|
|
|
|
* Reading the ISR register clears all interrupts, and
|
|
|
|
* clears the 'interrupts enabled' bit in the IMR
|
|
|
|
* register.
|
|
|
|
*/
|
|
|
|
status = CSR_READ_4(sc, LGE_ISR);
|
|
|
|
|
|
|
|
if ((status & LGE_INTRS) == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if ((status & (LGE_ISR_TXCMDFIFO_EMPTY|LGE_ISR_TXDMA_DONE)))
|
|
|
|
lge_txeof(sc);
|
|
|
|
|
|
|
|
if (status & LGE_ISR_RXDMA_DONE)
|
|
|
|
lge_rxeof(sc, LGE_RX_DMACNT(status));
|
|
|
|
|
|
|
|
if (status & LGE_ISR_RXCMDFIFO_EMPTY)
|
|
|
|
lge_rxeoc(sc);
|
|
|
|
|
|
|
|
if (status & LGE_ISR_PHY_INTR) {
|
|
|
|
sc->lge_link = 0;
|
2005-11-23 18:51:34 +00:00
|
|
|
callout_stop(&sc->lge_stat_callout);
|
2001-05-31 21:44:26 +00:00
|
|
|
lge_tick(sc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Re-enable interrupts. */
|
|
|
|
CSR_WRITE_4(sc, LGE_IMR, LGE_IMR_SETRST_CTL0|LGE_IMR_INTR_ENB);
|
|
|
|
|
|
|
|
if (ifp->if_snd.ifq_head != NULL)
|
2005-11-23 18:51:34 +00:00
|
|
|
lge_start_locked(ifp);
|
2001-05-31 21:44:26 +00:00
|
|
|
|
2005-11-23 18:51:34 +00:00
|
|
|
LGE_UNLOCK(sc);
|
2001-05-31 21:44:26 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Encapsulate an mbuf chain in a descriptor by coupling the mbuf data
|
|
|
|
* pointers to the fragment pointers.
|
|
|
|
*/
|
2002-07-06 16:34:32 +00:00
|
|
|
static int
|
|
|
|
lge_encap(sc, m_head, txidx)
|
2001-05-31 21:44:26 +00:00
|
|
|
struct lge_softc *sc;
|
|
|
|
struct mbuf *m_head;
|
|
|
|
u_int32_t *txidx;
|
|
|
|
{
|
|
|
|
struct lge_frag *f = NULL;
|
|
|
|
struct lge_tx_desc *cur_tx;
|
|
|
|
struct mbuf *m;
|
|
|
|
int frag = 0, tot_len = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Start packing the mbufs in this chain into
|
|
|
|
* the fragment pointers. Stop when we run out
|
|
|
|
* of fragments or hit the end of the mbuf chain.
|
|
|
|
*/
|
|
|
|
m = m_head;
|
|
|
|
cur_tx = &sc->lge_ldata->lge_tx_list[*txidx];
|
|
|
|
frag = 0;
|
|
|
|
|
|
|
|
for (m = m_head; m != NULL; m = m->m_next) {
|
|
|
|
if (m->m_len != 0) {
|
|
|
|
tot_len += m->m_len;
|
|
|
|
f = &cur_tx->lge_frags[frag];
|
|
|
|
f->lge_fraglen = m->m_len;
|
|
|
|
f->lge_fragptr_lo = vtophys(mtod(m, vm_offset_t));
|
|
|
|
f->lge_fragptr_hi = 0;
|
|
|
|
frag++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m != NULL)
|
|
|
|
return(ENOBUFS);
|
|
|
|
|
|
|
|
cur_tx->lge_mbuf = m_head;
|
|
|
|
cur_tx->lge_ctl = LGE_TXCTL_WANTINTR|LGE_FRAGCNT(frag)|tot_len;
|
2001-06-06 19:16:02 +00:00
|
|
|
LGE_INC((*txidx), LGE_TX_LIST_CNT);
|
2001-05-31 21:44:26 +00:00
|
|
|
|
|
|
|
/* Queue for transmit */
|
|
|
|
CSR_WRITE_4(sc, LGE_TXDESC_ADDR_LO, vtophys(cur_tx));
|
|
|
|
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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-07-06 16:34:32 +00:00
|
|
|
static void
|
|
|
|
lge_start(ifp)
|
2001-05-31 21:44:26 +00:00
|
|
|
struct ifnet *ifp;
|
|
|
|
{
|
|
|
|
struct lge_softc *sc;
|
2005-11-23 18:51:34 +00:00
|
|
|
|
|
|
|
sc = ifp->if_softc;
|
|
|
|
LGE_LOCK(sc);
|
|
|
|
lge_start_locked(ifp);
|
|
|
|
LGE_UNLOCK(sc);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
lge_start_locked(ifp)
|
|
|
|
struct ifnet *ifp;
|
|
|
|
{
|
|
|
|
struct lge_softc *sc;
|
2001-05-31 21:44:26 +00:00
|
|
|
struct mbuf *m_head = NULL;
|
|
|
|
u_int32_t idx;
|
|
|
|
|
|
|
|
sc = ifp->if_softc;
|
|
|
|
|
|
|
|
if (!sc->lge_link)
|
|
|
|
return;
|
|
|
|
|
|
|
|
idx = sc->lge_cdata.lge_tx_prod;
|
|
|
|
|
2005-08-09 10:20:02 +00:00
|
|
|
if (ifp->if_drv_flags & IFF_DRV_OACTIVE)
|
2001-05-31 21:44:26 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
while(sc->lge_ldata->lge_tx_list[idx].lge_mbuf == NULL) {
|
|
|
|
if (CSR_READ_1(sc, LGE_TXCMDFREE_8BIT) == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
IF_DEQUEUE(&ifp->if_snd, m_head);
|
|
|
|
if (m_head == NULL)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (lge_encap(sc, m_head, &idx)) {
|
|
|
|
IF_PREPEND(&ifp->if_snd, m_head);
|
2005-08-09 10:20:02 +00:00
|
|
|
ifp->if_drv_flags |= IFF_DRV_OACTIVE;
|
2001-05-31 21:44:26 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If there's a BPF listener, bounce a copy of this frame
|
|
|
|
* to him.
|
|
|
|
*/
|
2002-11-14 23:54:55 +00:00
|
|
|
BPF_MTAP(ifp, m_head);
|
2001-05-31 21:44:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sc->lge_cdata.lge_tx_prod = idx;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set a timeout in case the chip goes out to lunch.
|
|
|
|
*/
|
2009-11-19 22:14:23 +00:00
|
|
|
sc->lge_timer = 5;
|
2001-05-31 21:44:26 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-07-06 16:34:32 +00:00
|
|
|
static void
|
|
|
|
lge_init(xsc)
|
2001-05-31 21:44:26 +00:00
|
|
|
void *xsc;
|
|
|
|
{
|
|
|
|
struct lge_softc *sc = xsc;
|
2005-11-23 18:51:34 +00:00
|
|
|
|
|
|
|
LGE_LOCK(sc);
|
|
|
|
lge_init_locked(sc);
|
|
|
|
LGE_UNLOCK(sc);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
lge_init_locked(sc)
|
|
|
|
struct lge_softc *sc;
|
|
|
|
{
|
2005-06-10 16:49:24 +00:00
|
|
|
struct ifnet *ifp = sc->lge_ifp;
|
2001-05-31 21:44:26 +00:00
|
|
|
|
2005-11-23 18:51:34 +00:00
|
|
|
LGE_LOCK_ASSERT(sc);
|
2005-08-09 10:20:02 +00:00
|
|
|
if (ifp->if_drv_flags & IFF_DRV_RUNNING)
|
2001-05-31 21:44:26 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Cancel pending I/O and free all RX/TX buffers.
|
|
|
|
*/
|
|
|
|
lge_stop(sc);
|
|
|
|
lge_reset(sc);
|
|
|
|
|
|
|
|
/* Set MAC address */
|
2005-11-11 16:04:59 +00:00
|
|
|
CSR_WRITE_4(sc, LGE_PAR0, *(u_int32_t *)(&IF_LLADDR(sc->lge_ifp)[0]));
|
|
|
|
CSR_WRITE_4(sc, LGE_PAR1, *(u_int32_t *)(&IF_LLADDR(sc->lge_ifp)[4]));
|
2001-05-31 21:44:26 +00:00
|
|
|
|
|
|
|
/* Init circular RX list. */
|
|
|
|
if (lge_list_rx_init(sc) == ENOBUFS) {
|
2006-09-15 15:16:12 +00:00
|
|
|
device_printf(sc->lge_dev, "initialization failed: no "
|
2005-10-03 15:52:34 +00:00
|
|
|
"memory for rx buffers\n");
|
2001-05-31 21:44:26 +00:00
|
|
|
lge_stop(sc);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Init tx descriptors.
|
|
|
|
*/
|
|
|
|
lge_list_tx_init(sc);
|
|
|
|
|
|
|
|
/* Set initial value for MODE1 register. */
|
|
|
|
CSR_WRITE_4(sc, LGE_MODE1, LGE_MODE1_RX_UCAST|
|
|
|
|
LGE_MODE1_TX_CRC|LGE_MODE1_TXPAD|
|
|
|
|
LGE_MODE1_RX_FLOWCTL|LGE_MODE1_SETRST_CTL0|
|
|
|
|
LGE_MODE1_SETRST_CTL1|LGE_MODE1_SETRST_CTL2);
|
|
|
|
|
|
|
|
/* If we want promiscuous mode, set the allframes bit. */
|
|
|
|
if (ifp->if_flags & IFF_PROMISC) {
|
|
|
|
CSR_WRITE_4(sc, LGE_MODE1,
|
|
|
|
LGE_MODE1_SETRST_CTL1|LGE_MODE1_RX_PROMISC);
|
|
|
|
} else {
|
|
|
|
CSR_WRITE_4(sc, LGE_MODE1, LGE_MODE1_RX_PROMISC);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set the capture broadcast bit to capture broadcast frames.
|
|
|
|
*/
|
|
|
|
if (ifp->if_flags & IFF_BROADCAST) {
|
|
|
|
CSR_WRITE_4(sc, LGE_MODE1,
|
|
|
|
LGE_MODE1_SETRST_CTL1|LGE_MODE1_RX_BCAST);
|
|
|
|
} else {
|
|
|
|
CSR_WRITE_4(sc, LGE_MODE1, LGE_MODE1_RX_BCAST);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Packet padding workaround? */
|
|
|
|
CSR_WRITE_4(sc, LGE_MODE1, LGE_MODE1_SETRST_CTL1|LGE_MODE1_RMVPAD);
|
|
|
|
|
|
|
|
/* No error frames */
|
|
|
|
CSR_WRITE_4(sc, LGE_MODE1, LGE_MODE1_RX_ERRPKTS);
|
|
|
|
|
|
|
|
/* Receive large frames */
|
|
|
|
CSR_WRITE_4(sc, LGE_MODE1, LGE_MODE1_SETRST_CTL1|LGE_MODE1_RX_GIANTS);
|
|
|
|
|
|
|
|
/* Workaround: disable RX/TX flow control */
|
|
|
|
CSR_WRITE_4(sc, LGE_MODE1, LGE_MODE1_TX_FLOWCTL);
|
|
|
|
CSR_WRITE_4(sc, LGE_MODE1, LGE_MODE1_RX_FLOWCTL);
|
|
|
|
|
|
|
|
/* Make sure to strip CRC from received frames */
|
|
|
|
CSR_WRITE_4(sc, LGE_MODE1, LGE_MODE1_RX_CRC);
|
|
|
|
|
|
|
|
/* Turn off magic packet mode */
|
|
|
|
CSR_WRITE_4(sc, LGE_MODE1, LGE_MODE1_MPACK_ENB);
|
|
|
|
|
|
|
|
/* Turn off all VLAN stuff */
|
|
|
|
CSR_WRITE_4(sc, LGE_MODE1, LGE_MODE1_VLAN_RX|LGE_MODE1_VLAN_TX|
|
|
|
|
LGE_MODE1_VLAN_STRIP|LGE_MODE1_VLAN_INSERT);
|
|
|
|
|
|
|
|
/* Workarond: FIFO overflow */
|
|
|
|
CSR_WRITE_2(sc, LGE_RXFIFO_HIWAT, 0x3FFF);
|
|
|
|
CSR_WRITE_4(sc, LGE_IMR, LGE_IMR_SETRST_CTL1|LGE_IMR_RXFIFO_WAT);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Load the multicast filter.
|
|
|
|
*/
|
|
|
|
lge_setmulti(sc);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Enable hardware checksum validation for all received IPv4
|
|
|
|
* packets, do not reject packets with bad checksums.
|
|
|
|
*/
|
|
|
|
CSR_WRITE_4(sc, LGE_MODE2, LGE_MODE2_RX_IPCSUM|
|
|
|
|
LGE_MODE2_RX_TCPCSUM|LGE_MODE2_RX_UDPCSUM|
|
|
|
|
LGE_MODE2_RX_ERRCSUM);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Enable the delivery of PHY interrupts based on
|
|
|
|
* link/speed/duplex status chalges.
|
|
|
|
*/
|
|
|
|
CSR_WRITE_4(sc, LGE_MODE1, LGE_MODE1_SETRST_CTL0|LGE_MODE1_GMIIPOLL);
|
|
|
|
|
|
|
|
/* Enable receiver and transmitter. */
|
|
|
|
CSR_WRITE_4(sc, LGE_RXDESC_ADDR_HI, 0);
|
|
|
|
CSR_WRITE_4(sc, LGE_MODE1, LGE_MODE1_SETRST_CTL1|LGE_MODE1_RX_ENB);
|
|
|
|
|
|
|
|
CSR_WRITE_4(sc, LGE_TXDESC_ADDR_HI, 0);
|
|
|
|
CSR_WRITE_4(sc, LGE_MODE1, LGE_MODE1_SETRST_CTL1|LGE_MODE1_TX_ENB);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Enable interrupts.
|
|
|
|
*/
|
|
|
|
CSR_WRITE_4(sc, LGE_IMR, LGE_IMR_SETRST_CTL0|
|
|
|
|
LGE_IMR_SETRST_CTL1|LGE_IMR_INTR_ENB|LGE_INTRS);
|
|
|
|
|
2005-11-23 18:51:34 +00:00
|
|
|
lge_ifmedia_upd_locked(ifp);
|
2001-05-31 21:44:26 +00:00
|
|
|
|
2005-08-09 10:20:02 +00:00
|
|
|
ifp->if_drv_flags |= IFF_DRV_RUNNING;
|
|
|
|
ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
|
2001-05-31 21:44:26 +00:00
|
|
|
|
2005-11-23 18:51:34 +00:00
|
|
|
callout_reset(&sc->lge_stat_callout, hz, lge_tick, sc);
|
2001-05-31 21:44:26 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set media options.
|
|
|
|
*/
|
2002-07-06 16:34:32 +00:00
|
|
|
static int
|
|
|
|
lge_ifmedia_upd(ifp)
|
2001-05-31 21:44:26 +00:00
|
|
|
struct ifnet *ifp;
|
|
|
|
{
|
|
|
|
struct lge_softc *sc;
|
2005-11-23 18:51:34 +00:00
|
|
|
|
|
|
|
sc = ifp->if_softc;
|
|
|
|
LGE_LOCK(sc);
|
|
|
|
lge_ifmedia_upd_locked(ifp);
|
|
|
|
LGE_UNLOCK(sc);
|
|
|
|
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
lge_ifmedia_upd_locked(ifp)
|
|
|
|
struct ifnet *ifp;
|
|
|
|
{
|
|
|
|
struct lge_softc *sc;
|
2001-05-31 21:44:26 +00:00
|
|
|
struct mii_data *mii;
|
- Remove attempts to implement setting of BMCR_LOOP/MIIF_NOLOOP
(reporting IFM_LOOP based on BMCR_LOOP is left in place though as
it might provide useful for debugging). For most mii(4) drivers it
was unclear whether the PHYs driven by them actually support
loopback or not. Moreover, typically loopback mode also needs to
be activated on the MAC, which none of the Ethernet drivers using
mii(4) implements. Given that loopback media has no real use (and
obviously hardly had a chance to actually work) besides for driver
development (which just loopback mode should be sufficient for
though, i.e one doesn't necessary need support for loopback media)
support for it is just dropped as both NetBSD and OpenBSD already
did quite some time ago.
- Let mii_phy_add_media() also announce the support of IFM_NONE.
- Restructure the PHY entry points to use a structure of entry points
instead of discrete function pointers, and extend this to include
a "reset" entry point. Make sure any PHY-specific reset routine is
always used, and provide one for lxtphy(4) which disables MII
interrupts (as is done for a few other PHYs we have drivers for).
This includes changing NIC drivers which previously just called the
generic mii_phy_reset() to now actually call the PHY-specific reset
routine, which might be crucial in some cases. While at it, the
redundant checks in these NIC drivers for mii->mii_instance not being
zero before calling the reset routines were removed because as soon
as one PHY driver attaches mii->mii_instance is incremented and we
hardly can end up in their media change callbacks etc if no PHY driver
has attached as mii_attach() would have failed in that case and not
attach a miibus(4) instance.
Consequently, NIC drivers now no longer should call mii_phy_reset()
directly, so it was removed from EXPORT_SYMS.
- Add a mii_phy_dev_attach() as a companion helper to mii_phy_dev_probe().
The purpose of that function is to perform the common steps to attach
a PHY driver instance and to hook it up to the miibus(4) instance and to
optionally also handle the probing, addition and initialization of the
supported media. So all a PHY driver without any special requirements
has to do in its bus attach method is to call mii_phy_dev_attach()
along with PHY-specific MIIF_* flags, a pointer to its PHY functions
and the add_media set to one. All PHY drivers were updated to take
advantage of mii_phy_dev_attach() as appropriate. Along with these
changes the capability mask was added to the mii_softc structure so
PHY drivers taking advantage of mii_phy_dev_attach() but still
handling media on their own do not need to fiddle with the MII attach
arguments anyway.
- Keep track of the PHY offset in the mii_softc structure. This is done
for compatibility with NetBSD/OpenBSD.
- Keep track of the PHY's OUI, model and revision in the mii_softc
structure. Several PHY drivers require this information also after
attaching and previously had to wrap their own softc around mii_softc.
NetBSD/OpenBSD also keep track of the model and revision on their
mii_softc structure. All PHY drivers were updated to take advantage
as appropriate.
- Convert the mebers of the MII data structure to unsigned where
appropriate. This is partly inspired by NetBSD/OpenBSD.
- According to IEEE 802.3-2002 the bits actually have to be reversed
when mapping an OUI to the MII ID registers. All PHY drivers and
miidevs where changed as necessary. Actually this now again allows to
largely share miidevs with NetBSD, which fixed this problem already
9 years ago. Consequently miidevs was synced as far as possible.
- Add MIIF_NOMANPAUSE and mii_phy_flowstatus() calls to drivers that
weren't explicitly converted to support flow control before. It's
unclear whether flow control actually works with these but typically
it should and their net behavior should be more correct with these
changes in place than without if the MAC driver sets MIIF_DOPAUSE.
Obtained from: NetBSD (partially)
Reviewed by: yongari (earlier version), silence on arch@ and net@
2011-05-03 19:51:29 +00:00
|
|
|
struct mii_softc *miisc;
|
2001-05-31 21:44:26 +00:00
|
|
|
|
|
|
|
sc = ifp->if_softc;
|
|
|
|
|
2005-11-23 18:51:34 +00:00
|
|
|
LGE_LOCK_ASSERT(sc);
|
2001-05-31 21:44:26 +00:00
|
|
|
mii = device_get_softc(sc->lge_miibus);
|
|
|
|
sc->lge_link = 0;
|
- Remove attempts to implement setting of BMCR_LOOP/MIIF_NOLOOP
(reporting IFM_LOOP based on BMCR_LOOP is left in place though as
it might provide useful for debugging). For most mii(4) drivers it
was unclear whether the PHYs driven by them actually support
loopback or not. Moreover, typically loopback mode also needs to
be activated on the MAC, which none of the Ethernet drivers using
mii(4) implements. Given that loopback media has no real use (and
obviously hardly had a chance to actually work) besides for driver
development (which just loopback mode should be sufficient for
though, i.e one doesn't necessary need support for loopback media)
support for it is just dropped as both NetBSD and OpenBSD already
did quite some time ago.
- Let mii_phy_add_media() also announce the support of IFM_NONE.
- Restructure the PHY entry points to use a structure of entry points
instead of discrete function pointers, and extend this to include
a "reset" entry point. Make sure any PHY-specific reset routine is
always used, and provide one for lxtphy(4) which disables MII
interrupts (as is done for a few other PHYs we have drivers for).
This includes changing NIC drivers which previously just called the
generic mii_phy_reset() to now actually call the PHY-specific reset
routine, which might be crucial in some cases. While at it, the
redundant checks in these NIC drivers for mii->mii_instance not being
zero before calling the reset routines were removed because as soon
as one PHY driver attaches mii->mii_instance is incremented and we
hardly can end up in their media change callbacks etc if no PHY driver
has attached as mii_attach() would have failed in that case and not
attach a miibus(4) instance.
Consequently, NIC drivers now no longer should call mii_phy_reset()
directly, so it was removed from EXPORT_SYMS.
- Add a mii_phy_dev_attach() as a companion helper to mii_phy_dev_probe().
The purpose of that function is to perform the common steps to attach
a PHY driver instance and to hook it up to the miibus(4) instance and to
optionally also handle the probing, addition and initialization of the
supported media. So all a PHY driver without any special requirements
has to do in its bus attach method is to call mii_phy_dev_attach()
along with PHY-specific MIIF_* flags, a pointer to its PHY functions
and the add_media set to one. All PHY drivers were updated to take
advantage of mii_phy_dev_attach() as appropriate. Along with these
changes the capability mask was added to the mii_softc structure so
PHY drivers taking advantage of mii_phy_dev_attach() but still
handling media on their own do not need to fiddle with the MII attach
arguments anyway.
- Keep track of the PHY offset in the mii_softc structure. This is done
for compatibility with NetBSD/OpenBSD.
- Keep track of the PHY's OUI, model and revision in the mii_softc
structure. Several PHY drivers require this information also after
attaching and previously had to wrap their own softc around mii_softc.
NetBSD/OpenBSD also keep track of the model and revision on their
mii_softc structure. All PHY drivers were updated to take advantage
as appropriate.
- Convert the mebers of the MII data structure to unsigned where
appropriate. This is partly inspired by NetBSD/OpenBSD.
- According to IEEE 802.3-2002 the bits actually have to be reversed
when mapping an OUI to the MII ID registers. All PHY drivers and
miidevs where changed as necessary. Actually this now again allows to
largely share miidevs with NetBSD, which fixed this problem already
9 years ago. Consequently miidevs was synced as far as possible.
- Add MIIF_NOMANPAUSE and mii_phy_flowstatus() calls to drivers that
weren't explicitly converted to support flow control before. It's
unclear whether flow control actually works with these but typically
it should and their net behavior should be more correct with these
changes in place than without if the MAC driver sets MIIF_DOPAUSE.
Obtained from: NetBSD (partially)
Reviewed by: yongari (earlier version), silence on arch@ and net@
2011-05-03 19:51:29 +00:00
|
|
|
LIST_FOREACH(miisc, &mii->mii_phys, mii_list)
|
|
|
|
PHY_RESET(miisc);
|
2001-05-31 21:44:26 +00:00
|
|
|
mii_mediachg(mii);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Report current media status.
|
|
|
|
*/
|
2002-07-06 16:34:32 +00:00
|
|
|
static void
|
|
|
|
lge_ifmedia_sts(ifp, ifmr)
|
2001-05-31 21:44:26 +00:00
|
|
|
struct ifnet *ifp;
|
|
|
|
struct ifmediareq *ifmr;
|
|
|
|
{
|
|
|
|
struct lge_softc *sc;
|
|
|
|
struct mii_data *mii;
|
|
|
|
|
|
|
|
sc = ifp->if_softc;
|
|
|
|
|
2005-11-23 18:51:34 +00:00
|
|
|
LGE_LOCK(sc);
|
2001-05-31 21:44:26 +00:00
|
|
|
mii = device_get_softc(sc->lge_miibus);
|
|
|
|
mii_pollstat(mii);
|
|
|
|
ifmr->ifm_active = mii->mii_media_active;
|
|
|
|
ifmr->ifm_status = mii->mii_media_status;
|
2011-10-17 19:49:00 +00:00
|
|
|
LGE_UNLOCK(sc);
|
2001-05-31 21:44:26 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-07-06 16:34:32 +00:00
|
|
|
static int
|
|
|
|
lge_ioctl(ifp, command, data)
|
2001-05-31 21:44:26 +00:00
|
|
|
struct ifnet *ifp;
|
|
|
|
u_long command;
|
|
|
|
caddr_t data;
|
|
|
|
{
|
|
|
|
struct lge_softc *sc = ifp->if_softc;
|
|
|
|
struct ifreq *ifr = (struct ifreq *) data;
|
|
|
|
struct mii_data *mii;
|
2005-11-23 18:51:34 +00:00
|
|
|
int error = 0;
|
2001-05-31 21:44:26 +00:00
|
|
|
|
|
|
|
switch(command) {
|
|
|
|
case SIOCSIFMTU:
|
2005-11-23 18:51:34 +00:00
|
|
|
LGE_LOCK(sc);
|
2001-05-31 21:44:26 +00:00
|
|
|
if (ifr->ifr_mtu > LGE_JUMBO_MTU)
|
|
|
|
error = EINVAL;
|
|
|
|
else
|
|
|
|
ifp->if_mtu = ifr->ifr_mtu;
|
2005-11-23 18:51:34 +00:00
|
|
|
LGE_UNLOCK(sc);
|
2001-05-31 21:44:26 +00:00
|
|
|
break;
|
|
|
|
case SIOCSIFFLAGS:
|
2005-11-23 18:51:34 +00:00
|
|
|
LGE_LOCK(sc);
|
2001-05-31 21:44:26 +00:00
|
|
|
if (ifp->if_flags & IFF_UP) {
|
2005-08-09 10:20:02 +00:00
|
|
|
if (ifp->if_drv_flags & IFF_DRV_RUNNING &&
|
2001-05-31 21:44:26 +00:00
|
|
|
ifp->if_flags & IFF_PROMISC &&
|
|
|
|
!(sc->lge_if_flags & IFF_PROMISC)) {
|
|
|
|
CSR_WRITE_4(sc, LGE_MODE1,
|
|
|
|
LGE_MODE1_SETRST_CTL1|
|
|
|
|
LGE_MODE1_RX_PROMISC);
|
2005-08-09 10:20:02 +00:00
|
|
|
} else if (ifp->if_drv_flags & IFF_DRV_RUNNING &&
|
2001-05-31 21:44:26 +00:00
|
|
|
!(ifp->if_flags & IFF_PROMISC) &&
|
|
|
|
sc->lge_if_flags & IFF_PROMISC) {
|
|
|
|
CSR_WRITE_4(sc, LGE_MODE1,
|
|
|
|
LGE_MODE1_RX_PROMISC);
|
|
|
|
} else {
|
2005-08-09 10:20:02 +00:00
|
|
|
ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
|
2005-11-23 18:51:34 +00:00
|
|
|
lge_init_locked(sc);
|
2001-05-31 21:44:26 +00:00
|
|
|
}
|
|
|
|
} else {
|
2005-08-09 10:20:02 +00:00
|
|
|
if (ifp->if_drv_flags & IFF_DRV_RUNNING)
|
2001-05-31 21:44:26 +00:00
|
|
|
lge_stop(sc);
|
|
|
|
}
|
|
|
|
sc->lge_if_flags = ifp->if_flags;
|
2005-11-23 18:51:34 +00:00
|
|
|
LGE_UNLOCK(sc);
|
2001-05-31 21:44:26 +00:00
|
|
|
error = 0;
|
|
|
|
break;
|
|
|
|
case SIOCADDMULTI:
|
|
|
|
case SIOCDELMULTI:
|
2005-11-23 18:51:34 +00:00
|
|
|
LGE_LOCK(sc);
|
2001-05-31 21:44:26 +00:00
|
|
|
lge_setmulti(sc);
|
2005-11-23 18:51:34 +00:00
|
|
|
LGE_UNLOCK(sc);
|
2001-05-31 21:44:26 +00:00
|
|
|
error = 0;
|
|
|
|
break;
|
|
|
|
case SIOCGIFMEDIA:
|
|
|
|
case SIOCSIFMEDIA:
|
|
|
|
mii = device_get_softc(sc->lge_miibus);
|
|
|
|
error = ifmedia_ioctl(ifp, ifr, &mii->mii_media, command);
|
|
|
|
break;
|
|
|
|
default:
|
2002-11-14 23:54:55 +00:00
|
|
|
error = ether_ioctl(ifp, command, data);
|
2001-05-31 21:44:26 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return(error);
|
|
|
|
}
|
|
|
|
|
2002-07-06 16:34:32 +00:00
|
|
|
static void
|
2009-11-19 22:14:23 +00:00
|
|
|
lge_watchdog(sc)
|
2001-05-31 21:44:26 +00:00
|
|
|
struct lge_softc *sc;
|
2009-11-19 22:14:23 +00:00
|
|
|
{
|
|
|
|
struct ifnet *ifp;
|
2001-05-31 21:44:26 +00:00
|
|
|
|
2009-11-19 22:14:23 +00:00
|
|
|
LGE_LOCK_ASSERT(sc);
|
|
|
|
ifp = sc->lge_ifp;
|
2001-05-31 21:44:26 +00:00
|
|
|
|
|
|
|
ifp->if_oerrors++;
|
2005-10-03 15:52:34 +00:00
|
|
|
if_printf(ifp, "watchdog timeout\n");
|
2001-05-31 21:44:26 +00:00
|
|
|
|
|
|
|
lge_stop(sc);
|
|
|
|
lge_reset(sc);
|
2005-08-09 10:20:02 +00:00
|
|
|
ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
|
2005-11-23 18:51:34 +00:00
|
|
|
lge_init_locked(sc);
|
2001-05-31 21:44:26 +00:00
|
|
|
|
|
|
|
if (ifp->if_snd.ifq_head != NULL)
|
2005-11-23 18:51:34 +00:00
|
|
|
lge_start_locked(ifp);
|
2001-05-31 21:44:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Stop the adapter and free any mbufs allocated to the
|
|
|
|
* RX and TX lists.
|
|
|
|
*/
|
2002-07-06 16:34:32 +00:00
|
|
|
static void
|
|
|
|
lge_stop(sc)
|
2001-05-31 21:44:26 +00:00
|
|
|
struct lge_softc *sc;
|
|
|
|
{
|
|
|
|
register int i;
|
|
|
|
struct ifnet *ifp;
|
|
|
|
|
2005-11-23 18:51:34 +00:00
|
|
|
LGE_LOCK_ASSERT(sc);
|
2005-06-10 16:49:24 +00:00
|
|
|
ifp = sc->lge_ifp;
|
2009-11-19 22:14:23 +00:00
|
|
|
sc->lge_timer = 0;
|
2005-11-23 18:51:34 +00:00
|
|
|
callout_stop(&sc->lge_stat_callout);
|
2001-05-31 21:44:26 +00:00
|
|
|
CSR_WRITE_4(sc, LGE_IMR, LGE_IMR_INTR_ENB);
|
|
|
|
|
|
|
|
/* Disable receiver and transmitter. */
|
|
|
|
CSR_WRITE_4(sc, LGE_MODE1, LGE_MODE1_RX_ENB|LGE_MODE1_TX_ENB);
|
|
|
|
sc->lge_link = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Free data in the RX lists.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < LGE_RX_LIST_CNT; i++) {
|
|
|
|
if (sc->lge_ldata->lge_rx_list[i].lge_mbuf != NULL) {
|
|
|
|
m_freem(sc->lge_ldata->lge_rx_list[i].lge_mbuf);
|
|
|
|
sc->lge_ldata->lge_rx_list[i].lge_mbuf = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
bzero((char *)&sc->lge_ldata->lge_rx_list,
|
|
|
|
sizeof(sc->lge_ldata->lge_rx_list));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Free the TX list buffers.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < LGE_TX_LIST_CNT; i++) {
|
|
|
|
if (sc->lge_ldata->lge_tx_list[i].lge_mbuf != NULL) {
|
|
|
|
m_freem(sc->lge_ldata->lge_tx_list[i].lge_mbuf);
|
|
|
|
sc->lge_ldata->lge_tx_list[i].lge_mbuf = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bzero((char *)&sc->lge_ldata->lge_tx_list,
|
|
|
|
sizeof(sc->lge_ldata->lge_tx_list));
|
|
|
|
|
2005-08-09 10:20:02 +00:00
|
|
|
ifp->if_drv_flags &= ~(IFF_DRV_RUNNING | IFF_DRV_OACTIVE);
|
2001-05-31 21:44:26 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Stop all chip I/O so that the kernel's probe routines don't
|
|
|
|
* get confused by errant DMAs when rebooting.
|
|
|
|
*/
|
2007-11-22 02:45:00 +00:00
|
|
|
static int
|
2002-07-06 16:34:32 +00:00
|
|
|
lge_shutdown(dev)
|
2001-05-31 21:44:26 +00:00
|
|
|
device_t dev;
|
|
|
|
{
|
|
|
|
struct lge_softc *sc;
|
|
|
|
|
|
|
|
sc = device_get_softc(dev);
|
|
|
|
|
2005-11-23 18:51:34 +00:00
|
|
|
LGE_LOCK(sc);
|
2001-05-31 21:44:26 +00:00
|
|
|
lge_reset(sc);
|
|
|
|
lge_stop(sc);
|
2005-11-23 18:51:34 +00:00
|
|
|
LGE_UNLOCK(sc);
|
2001-05-31 21:44:26 +00:00
|
|
|
|
2007-11-22 02:45:00 +00:00
|
|
|
return (0);
|
2001-05-31 21:44:26 +00:00
|
|
|
}
|