- Revert if_le_pci.c rev. 1.2; although lnc(4) is now gone, le_pci_probe()
still should return BUS_PROBE_LOW_PRIORITY instead of BUS_PROBE_DEFAULT in order to give pcn(4) a chance to attach in case it probes after le(4). - Rearrange the code related to RX interrupt handling so that ownership of RX descriptors is immediately returned to the NIC after we have copied the data of the hardware, allowing the NIC to already reuse the descriptor while we are processing the data in ifp->if_input(). This results in a small but measurable increase in RX throughput. As a side-effect, this moves the workaround for the LANCE revision C bug to am7900.c (still off by default as I doubt we will actually encounter such an old chip in a machine running FreeBSD) and the workaround for the bug in the VMware PCnet-PCI emulation to am79000.c, which is now also only compiled on i386 (resulting in a small increase in RX throughput on the other platforms). - Change the RX interrupt handlers so that the descriptor error bits are only check once in case there was no error instead of twice (inspired by the NetBSD pcn(4), which additionally predicts the error branch as false). - Fix the debugging output of the RX and TX interrupt handlers; while looping through the descriptors print info about the currently processed one instead of always the previously last used one; remove pointless printing of info about the RX descriptor bits after their values were reset. - Create the DMA tags used to allocate the memory for the init block, descriptors and packet buffers with the alignment the respective NIC actually requires rather than using PAGE_SIZE unconditionally. This might as well fix the alignment of the memory as it seems we do not inherit the alignment constraint from the parent DMA tag. - For the PCI variants double the number of RX descriptors and buffers from 8 to 16 as this minimizes the number of RX overflows im seeing with one NIC-mainboard combination. Nevertheless move reporting of overflows under debugging as they seem unavoidable with some crappy hardware. - Set the software style of the PCI variants to ILACC rather than PCnet-PCI as the former is was am79000.c actually implements. Should not make a difference for this driver though. - Fix the driver name part in the MODULE_DEPEND of the PCI front-end for ether. - Use different device descriptions for PCnet-Home and PCnet-PCI. - Fix some 0/NULL confusion in lance_get(). - Use bus_addr_t for sc_addr and bus_size_t for sc_memsize as these are more appropriate than u_long for these. - Remove the unused LE_DRIVER_NAME macro. - Add a comment describing why we are taking the LE_HTOLE* etc approach instead of using byteorder(9) functions directly. - Improve some comments and fix some wording. MFC after: 2 weeks
This commit is contained in:
parent
79652c510a
commit
60c430f511
@ -90,6 +90,8 @@ __FBSDID("$FreeBSD$");
|
||||
#include <net/if_media.h>
|
||||
#include <net/if_var.h>
|
||||
|
||||
#include <machine/bus.h>
|
||||
|
||||
#include <dev/le/lancereg.h>
|
||||
#include <dev/le/lancevar.h>
|
||||
#include <dev/le/am7990reg.h>
|
||||
@ -215,8 +217,14 @@ static void
|
||||
am7990_rint(struct lance_softc *sc)
|
||||
{
|
||||
struct ifnet *ifp = sc->sc_ifp;
|
||||
struct mbuf *m;
|
||||
struct lermd rmd;
|
||||
int bix, rp;
|
||||
#if defined(LANCE_REVC_BUG)
|
||||
struct ether_header *eh;
|
||||
/* Make sure this is short-aligned, for ether_cmp(). */
|
||||
static uint16_t bcast_enaddr[3] = { ~0, ~0, ~0 };
|
||||
#endif
|
||||
|
||||
bix = sc->sc_last_rd;
|
||||
|
||||
@ -228,35 +236,37 @@ am7990_rint(struct lance_softc *sc)
|
||||
if (rmd.rmd1_bits & LE_R1_OWN)
|
||||
break;
|
||||
|
||||
if (rmd.rmd1_bits & LE_R1_ERR) {
|
||||
if (rmd.rmd1_bits & LE_R1_ENP) {
|
||||
#ifdef LEDEBUG
|
||||
if ((rmd.rmd1_bits & LE_R1_OFLO) == 0) {
|
||||
if (rmd.rmd1_bits & LE_R1_FRAM)
|
||||
if_printf(ifp,
|
||||
"framing error\n");
|
||||
if (rmd.rmd1_bits & LE_R1_CRC)
|
||||
if_printf(ifp,
|
||||
"crc mismatch\n");
|
||||
}
|
||||
#endif
|
||||
} else {
|
||||
if (rmd.rmd1_bits & LE_R1_OFLO)
|
||||
if_printf(ifp, "overflow\n");
|
||||
}
|
||||
if (rmd.rmd1_bits & LE_R1_BUFF)
|
||||
if_printf(ifp, "receive buffer error\n");
|
||||
ifp->if_ierrors++;
|
||||
} else if ((rmd.rmd1_bits & (LE_R1_STP | LE_R1_ENP)) !=
|
||||
m = NULL;
|
||||
if ((rmd.rmd1_bits & (LE_R1_ERR | LE_R1_STP | LE_R1_ENP)) !=
|
||||
(LE_R1_STP | LE_R1_ENP)) {
|
||||
if_printf(ifp, "dropping chained buffer\n");
|
||||
ifp->if_ierrors++;
|
||||
if (rmd.rmd1_bits & LE_R1_ERR) {
|
||||
#ifdef LEDEBUG
|
||||
if (rmd.rmd1_bits & LE_R1_ENP) {
|
||||
if ((rmd.rmd1_bits & LE_R1_OFLO) == 0) {
|
||||
if (rmd.rmd1_bits & LE_R1_FRAM)
|
||||
if_printf(ifp,
|
||||
"framing error\n");
|
||||
if (rmd.rmd1_bits & LE_R1_CRC)
|
||||
if_printf(ifp,
|
||||
"crc mismatch\n");
|
||||
}
|
||||
} else
|
||||
if (rmd.rmd1_bits & LE_R1_OFLO)
|
||||
if_printf(ifp, "overflow\n");
|
||||
#endif
|
||||
if (rmd.rmd1_bits & LE_R1_BUFF)
|
||||
if_printf(ifp,
|
||||
"receive buffer error\n");
|
||||
} else if ((rmd.rmd1_bits & (LE_R1_STP | LE_R1_ENP)) !=
|
||||
(LE_R1_STP | LE_R1_ENP))
|
||||
if_printf(ifp, "dropping chained buffer\n");
|
||||
} else {
|
||||
#ifdef LEDEBUG
|
||||
if (sc->sc_flags & LE_DEBUG)
|
||||
am7990_recv_print(sc, sc->sc_last_rd);
|
||||
am7990_recv_print(sc, bix);
|
||||
#endif
|
||||
lance_read(sc, LE_RBUFADDR(sc, bix),
|
||||
/* Pull the packet off the interface. */
|
||||
m = lance_get(sc, LE_RBUFADDR(sc, bix),
|
||||
(int)rmd.rmd3 - ETHER_CRC_LEN);
|
||||
}
|
||||
|
||||
@ -265,17 +275,35 @@ am7990_rint(struct lance_softc *sc)
|
||||
rmd.rmd3 = 0;
|
||||
(*sc->sc_copytodesc)(sc, &rmd, rp, sizeof(rmd));
|
||||
|
||||
#ifdef LEDEBUG
|
||||
if (sc->sc_flags & LE_DEBUG)
|
||||
if_printf(ifp, "sc->sc_last_rd = %x, rmd: "
|
||||
"ladr %04x, hadr %02x, flags %02x, "
|
||||
"bcnt %04x, mcnt %04x\n",
|
||||
sc->sc_last_rd, rmd.rmd0, rmd.rmd1_hadr,
|
||||
rmd.rmd1_bits, rmd.rmd2, rmd.rmd3);
|
||||
#endif
|
||||
|
||||
if (++bix == sc->sc_nrbuf)
|
||||
bix = 0;
|
||||
|
||||
if (m != NULL) {
|
||||
ifp->if_ipackets++;
|
||||
|
||||
#ifdef LANCE_REVC_BUG
|
||||
/*
|
||||
* The old LANCE (Rev. C) chips have a bug which
|
||||
* causes garbage to be inserted in front of the
|
||||
* received packet. The workaround is to ignore
|
||||
* packets with an invalid destination address
|
||||
* (garbage will usually not match).
|
||||
* Of course, this precludes multicast support...
|
||||
*/
|
||||
eh = mtod(m, struct ether_header *);
|
||||
if (ether_cmp(eh->ether_dhost, sc->sc_enaddr) &&
|
||||
ether_cmp(eh->ether_dhost, bcast_enaddr)) {
|
||||
m_freem(m);
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Pass the packet up. */
|
||||
LE_UNLOCK(sc);
|
||||
(*ifp->if_input)(ifp, m);
|
||||
LE_LOCK(sc);
|
||||
} else
|
||||
ifp->if_ierrors++;
|
||||
}
|
||||
|
||||
sc->sc_last_rd = bix;
|
||||
@ -392,11 +420,11 @@ am7990_intr(void *arg)
|
||||
/*
|
||||
* Clear interrupt source flags and turn off interrupts. If we
|
||||
* don't clear these flags before processing their sources we
|
||||
* could completely miss some interrupt events as the the NIC
|
||||
* can change these flags while we're in this handler. We turn
|
||||
* of interrupts while processing them so we don't get another
|
||||
* one while we still process the previous one in ifp->if_input()
|
||||
* with the driver lock dropped.
|
||||
* could completely miss some interrupt events as the NIC can
|
||||
* change these flags while we're in this handler. We turn off
|
||||
* interrupts so we don't get another RX interrupt while still
|
||||
* processing the previous one in ifp->if_input() with the
|
||||
* driver lock dropped.
|
||||
*/
|
||||
(*sc->sc_wrcsr)(sc, LE_CSR0, isr & ~(LE_C0_INEA | LE_C0_TDMD |
|
||||
LE_C0_STOP | LE_C0_STRT | LE_C0_INIT));
|
||||
@ -529,7 +557,7 @@ am7990_start_locked(struct lance_softc *sc)
|
||||
|
||||
#ifdef LEDEBUG
|
||||
if (sc->sc_flags & LE_DEBUG)
|
||||
am7990_xmit_print(sc, sc->sc_last_td);
|
||||
am7990_xmit_print(sc, bix);
|
||||
#endif
|
||||
|
||||
(*sc->sc_wrcsr)(sc, LE_CSR0, LE_C0_INEA | LE_C0_TDMD);
|
||||
|
@ -128,6 +128,8 @@ __FBSDID("$FreeBSD$");
|
||||
#include <net/if_media.h>
|
||||
#include <net/if_var.h>
|
||||
|
||||
#include <machine/bus.h>
|
||||
|
||||
#include <dev/le/lancereg.h>
|
||||
#include <dev/le/lancevar.h>
|
||||
#include <dev/le/am79900reg.h>
|
||||
@ -255,9 +257,13 @@ static inline void
|
||||
am79900_rint(struct lance_softc *sc)
|
||||
{
|
||||
struct ifnet *ifp = sc->sc_ifp;
|
||||
struct mbuf *m;
|
||||
struct lermd rmd;
|
||||
uint32_t rmd1;
|
||||
int bix, rp;
|
||||
#if defined(__i386__) && !defined(PC98)
|
||||
struct ether_header *eh;
|
||||
#endif
|
||||
|
||||
bix = sc->sc_last_rd;
|
||||
|
||||
@ -270,35 +276,37 @@ am79900_rint(struct lance_softc *sc)
|
||||
if (rmd1 & LE_R1_OWN)
|
||||
break;
|
||||
|
||||
if (rmd1 & LE_R1_ERR) {
|
||||
if (rmd1 & LE_R1_ENP) {
|
||||
m = NULL;
|
||||
if ((rmd1 & (LE_R1_ERR | LE_R1_STP | LE_R1_ENP)) !=
|
||||
(LE_R1_STP | LE_R1_ENP)){
|
||||
if (rmd1 & LE_R1_ERR) {
|
||||
#ifdef LEDEBUG
|
||||
if ((rmd1 & LE_R1_OFLO) == 0) {
|
||||
if (rmd1 & LE_R1_FRAM)
|
||||
if_printf(ifp,
|
||||
"framing error\n");
|
||||
if (rmd1 & LE_R1_CRC)
|
||||
if_printf(ifp,
|
||||
"crc mismatch\n");
|
||||
}
|
||||
if (rmd1 & LE_R1_ENP) {
|
||||
if ((rmd1 & LE_R1_OFLO) == 0) {
|
||||
if (rmd1 & LE_R1_FRAM)
|
||||
if_printf(ifp,
|
||||
"framing error\n");
|
||||
if (rmd1 & LE_R1_CRC)
|
||||
if_printf(ifp,
|
||||
"crc mismatch\n");
|
||||
}
|
||||
} else
|
||||
if (rmd1 & LE_R1_OFLO)
|
||||
if_printf(ifp, "overflow\n");
|
||||
#endif
|
||||
} else {
|
||||
if (rmd1 & LE_R1_OFLO)
|
||||
if_printf(ifp, "overflow\n");
|
||||
}
|
||||
if (rmd1 & LE_R1_BUFF)
|
||||
if_printf(ifp, "receive buffer error\n");
|
||||
ifp->if_ierrors++;
|
||||
} else if ((rmd1 & (LE_R1_STP | LE_R1_ENP)) !=
|
||||
(LE_R1_STP | LE_R1_ENP)) {
|
||||
if_printf(ifp, "dropping chained buffer\n");
|
||||
ifp->if_ierrors++;
|
||||
if (rmd1 & LE_R1_BUFF)
|
||||
if_printf(ifp,
|
||||
"receive buffer error\n");
|
||||
} else if ((rmd1 & (LE_R1_STP | LE_R1_ENP)) !=
|
||||
(LE_R1_STP | LE_R1_ENP))
|
||||
if_printf(ifp, "dropping chained buffer\n");
|
||||
} else {
|
||||
#ifdef LEDEBUG
|
||||
if (sc->sc_flags & LE_DEBUG)
|
||||
am79900_recv_print(sc, sc->sc_last_rd);
|
||||
am79900_recv_print(sc, bix);
|
||||
#endif
|
||||
lance_read(sc, LE_RBUFADDR(sc, bix),
|
||||
/* Pull the packet off the interface. */
|
||||
m = lance_get(sc, LE_RBUFADDR(sc, bix),
|
||||
(LE_LE32TOH(rmd.rmd2) & 0xfff) - ETHER_CRC_LEN);
|
||||
}
|
||||
|
||||
@ -308,16 +316,31 @@ am79900_rint(struct lance_softc *sc)
|
||||
rmd.rmd3 = 0;
|
||||
(*sc->sc_copytodesc)(sc, &rmd, rp, sizeof(rmd));
|
||||
|
||||
#ifdef LEDEBUG
|
||||
if (sc->sc_flags & LE_DEBUG)
|
||||
if_printf(ifp, "sc->sc_last_rd = %x, rmd: "
|
||||
"adr %08x, flags/blen %08x\n",
|
||||
sc->sc_last_rd, LE_LE32TOH(rmd.rmd0),
|
||||
LE_LE32TOH(rmd.rmd1));
|
||||
#endif
|
||||
|
||||
if (++bix == sc->sc_nrbuf)
|
||||
bix = 0;
|
||||
|
||||
if (m != NULL) {
|
||||
ifp->if_ipackets++;
|
||||
|
||||
#if defined(__i386__) && !defined(PC98)
|
||||
/*
|
||||
* The VMware LANCE does not present IFF_SIMPLEX
|
||||
* behavior on multicast packets. Thus drop the
|
||||
* packet if it is from ourselves.
|
||||
*/
|
||||
eh = mtod(m, struct ether_header *);
|
||||
if (!ether_cmp(eh->ether_shost, sc->sc_enaddr)) {
|
||||
m_freem(m);
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Pass the packet up. */
|
||||
LE_UNLOCK(sc);
|
||||
(*ifp->if_input)(ifp, m);
|
||||
LE_LOCK(sc);
|
||||
} else
|
||||
ifp->if_ierrors++;
|
||||
}
|
||||
|
||||
sc->sc_last_rd = bix;
|
||||
@ -340,21 +363,22 @@ am79900_tint(struct lance_softc *sc)
|
||||
(*sc->sc_copyfromdesc)(sc, &tmd, LE_TMDADDR(sc, bix),
|
||||
sizeof(tmd));
|
||||
|
||||
tmd1 = LE_LE32TOH(tmd.tmd1);
|
||||
|
||||
#ifdef LEDEBUG
|
||||
if (sc->sc_flags & LE_DEBUG)
|
||||
if_printf(ifp, "trans tmd: "
|
||||
"adr %08x, flags/blen %08x\n",
|
||||
LE_LE32TOH(tmd.tmd0), LE_LE32TOH(tmd.tmd1));
|
||||
LE_LE32TOH(tmd.tmd0), tmd1);
|
||||
#endif
|
||||
|
||||
tmd1 = LE_LE32TOH(tmd.tmd1);
|
||||
if (tmd1 & LE_T1_OWN)
|
||||
break;
|
||||
|
||||
ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
|
||||
|
||||
tmd2 = LE_LE32TOH(tmd.tmd2);
|
||||
if (tmd1 & LE_T1_ERR) {
|
||||
tmd2 = LE_LE32TOH(tmd.tmd2);
|
||||
if (tmd2 & LE_T2_BUFF)
|
||||
if_printf(ifp, "transmit buffer error\n");
|
||||
else if (tmd2 & LE_T2_UFLO)
|
||||
@ -434,11 +458,11 @@ am79900_intr(void *arg)
|
||||
/*
|
||||
* Clear interrupt source flags and turn off interrupts. If we
|
||||
* don't clear these flags before processing their sources we
|
||||
* could completely miss some interrupt events as the the NIC
|
||||
* can change these flags while we're in this handler. We turn
|
||||
* of interrupts while processing them so we don't get another
|
||||
* one while we still process the previous one in ifp->if_input()
|
||||
* with the driver lock dropped.
|
||||
* could completely miss some interrupt events as the NIC can
|
||||
* change these flags while we're in this handler. We turn off
|
||||
* interrupts so we don't get another RX interrupt while still
|
||||
* processing the previous one in ifp->if_input() with the
|
||||
* driver lock dropped.
|
||||
*/
|
||||
(*sc->sc_wrcsr)(sc, LE_CSR0, isr & ~(LE_C0_INEA | LE_C0_TDMD |
|
||||
LE_C0_STOP | LE_C0_STRT | LE_C0_INIT));
|
||||
@ -572,7 +596,7 @@ am79900_start_locked(struct lance_softc *sc)
|
||||
|
||||
#ifdef LEDEBUG
|
||||
if (sc->sc_flags & LE_DEBUG)
|
||||
am79900_xmit_print(sc, sc->sc_last_td);
|
||||
am79900_xmit_print(sc, bix);
|
||||
#endif
|
||||
|
||||
(*sc->sc_wrcsr)(sc, LE_CSR0, LE_C0_INEA | LE_C0_TDMD);
|
||||
|
@ -69,6 +69,7 @@ __FBSDID("$FreeBSD$");
|
||||
#include <dev/le/lancevar.h>
|
||||
#include <dev/le/am7990var.h>
|
||||
|
||||
#define LEDMA_ALIGNMENT 8 /* ring desc. alignmet for NCR92C990 */
|
||||
#define LEDMA_BOUNDARY (16*1024*1024) /* must not cross 16MB boundary */
|
||||
#define LEDMA_MEMSIZE (16*1024) /* LANCE memory size */
|
||||
#define LEREG1_RDP 0 /* Register Data Port */
|
||||
@ -355,7 +356,8 @@ le_dma_attach(device_t dev)
|
||||
sc->sc_memsize = LEDMA_MEMSIZE;
|
||||
error = bus_dma_tag_create(
|
||||
dma->sc_parent_dmat, /* parent */
|
||||
1, LEDMA_BOUNDARY, /* alignment, boundary */
|
||||
LEDMA_ALIGNMENT, /* alignment */
|
||||
LEDMA_BOUNDARY, /* boundary */
|
||||
BUS_SPACE_MAXADDR_32BIT, /* lowaddr */
|
||||
BUS_SPACE_MAXADDR, /* highaddr */
|
||||
NULL, NULL, /* filter, filterarg */
|
||||
@ -405,14 +407,14 @@ le_dma_attach(device_t dev)
|
||||
|
||||
sc->sc_rdcsr = le_dma_rdcsr;
|
||||
sc->sc_wrcsr = le_dma_wrcsr;
|
||||
sc->sc_nocarrier = le_dma_nocarrier;
|
||||
sc->sc_hwreset = le_dma_hwreset;
|
||||
sc->sc_hwintr = le_dma_hwintr;
|
||||
sc->sc_nocarrier = le_dma_nocarrier;
|
||||
|
||||
error = am7990_config(&lesc->sc_am7990, device_get_name(dev),
|
||||
device_get_unit(dev));
|
||||
if (error != 0) {
|
||||
device_printf(dev, "cannot attach AM7990\n");
|
||||
device_printf(dev, "cannot attach Am7990\n");
|
||||
goto fail_dmap;
|
||||
}
|
||||
|
||||
|
@ -103,7 +103,7 @@ __FBSDID("$FreeBSD$");
|
||||
#define AMD_VENDOR 0x1022
|
||||
#define AMD_PCNET_PCI 0x2000
|
||||
#define AMD_PCNET_HOME 0x2001
|
||||
#define PCNET_MEMSIZE 16384
|
||||
#define PCNET_MEMSIZE (32*1024)
|
||||
#define PCNET_PCI_RDP 0x10
|
||||
#define PCNET_PCI_RAP 0x12
|
||||
#define PCNET_PCI_BDP 0x16
|
||||
@ -146,7 +146,7 @@ static device_method_t le_pci_methods[] = {
|
||||
|
||||
DEFINE_CLASS_0(le, le_pci_driver, le_pci_methods, sizeof(struct le_pci_softc));
|
||||
DRIVER_MODULE(le, pci, le_pci_driver, le_devclass, 0, 0);
|
||||
MODULE_DEPEND(le_DRIVER_NAME, ether, 1, 1, 1);
|
||||
MODULE_DEPEND(le, ether, 1, 1, 1);
|
||||
|
||||
static const int le_home_supmedia[] = {
|
||||
IFM_MAKEWORD(IFM_ETHER, IFM_HPNA_1, 0, 0)
|
||||
@ -263,8 +263,8 @@ static void
|
||||
le_pci_hwreset(struct lance_softc *sc)
|
||||
{
|
||||
|
||||
/* Chip is stopped. Set "software style" to 32-bit. */
|
||||
le_pci_wrbcr(sc, LE_BCR20, LE_B20_SSTYLE_PCNETPCI2);
|
||||
/* Chip is stopped. Set software style to ILACC (32-bit). */
|
||||
le_pci_wrbcr(sc, LE_BCR20, LE_B20_SSTYLE_ILACC);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -287,9 +287,13 @@ le_pci_probe(device_t dev)
|
||||
|
||||
switch (pci_get_device(dev)) {
|
||||
case AMD_PCNET_PCI:
|
||||
device_set_desc(dev, "AMD PCnet-PCI");
|
||||
/* Let pcn(4) win. */
|
||||
return (BUS_PROBE_LOW_PRIORITY);
|
||||
case AMD_PCNET_HOME:
|
||||
device_set_desc(dev, "AMD PCnet Ethernet");
|
||||
return (BUS_PROBE_DEFAULT);
|
||||
device_set_desc(dev, "AMD PCnet-Home");
|
||||
/* Let pcn(4) win. */
|
||||
return (BUS_PROBE_LOW_PRIORITY);
|
||||
default:
|
||||
return (ENXIO);
|
||||
}
|
||||
@ -331,7 +335,7 @@ le_pci_attach(device_t dev)
|
||||
|
||||
error = bus_dma_tag_create(
|
||||
NULL, /* parent */
|
||||
PAGE_SIZE, 0, /* alignment, boundary */
|
||||
1, 0, /* alignment, boundary */
|
||||
BUS_SPACE_MAXADDR_32BIT, /* lowaddr */
|
||||
BUS_SPACE_MAXADDR, /* highaddr */
|
||||
NULL, NULL, /* filter, filterarg */
|
||||
@ -347,9 +351,14 @@ le_pci_attach(device_t dev)
|
||||
}
|
||||
|
||||
sc->sc_memsize = PCNET_MEMSIZE;
|
||||
/*
|
||||
* For Am79C970A, Am79C971 and Am79C978 the init block must be 2-byte
|
||||
* aligned and the ring descriptors must be 16-byte aligned when using
|
||||
* a 32-bit software style.
|
||||
*/
|
||||
error = bus_dma_tag_create(
|
||||
lesc->sc_pdmat, /* parent */
|
||||
1, 0, /* alignment, boundary */
|
||||
16, 0, /* alignment, boundary */
|
||||
BUS_SPACE_MAXADDR_32BIT, /* lowaddr */
|
||||
BUS_SPACE_MAXADDR, /* highaddr */
|
||||
NULL, NULL, /* filter, filterarg */
|
||||
@ -382,6 +391,7 @@ le_pci_attach(device_t dev)
|
||||
sc->sc_flags = LE_BSWAP;
|
||||
sc->sc_conf3 = 0;
|
||||
|
||||
sc->sc_mediastatus = NULL;
|
||||
switch (pci_get_device(dev)) {
|
||||
case AMD_PCNET_HOME:
|
||||
sc->sc_mediachange = le_pci_mediachange;
|
||||
@ -412,11 +422,14 @@ le_pci_attach(device_t dev)
|
||||
sc->sc_rdcsr = le_pci_rdcsr;
|
||||
sc->sc_wrcsr = le_pci_wrcsr;
|
||||
sc->sc_hwreset = le_pci_hwreset;
|
||||
sc->sc_hwinit = NULL;
|
||||
sc->sc_hwintr = NULL;
|
||||
sc->sc_nocarrier = NULL;
|
||||
|
||||
error = am79900_config(&lesc->sc_am79900, device_get_name(dev),
|
||||
device_get_unit(dev));
|
||||
if (error != 0) {
|
||||
device_printf(dev, "cannot attach AM79900\n");
|
||||
device_printf(dev, "cannot attach Am79900\n");
|
||||
goto fail_dmap;
|
||||
}
|
||||
|
||||
|
@ -91,71 +91,21 @@ __FBSDID("$FreeBSD$");
|
||||
#include <net/if_types.h>
|
||||
#include <net/if_vlan_var.h>
|
||||
|
||||
#include <machine/bus.h>
|
||||
|
||||
#include <dev/le/lancereg.h>
|
||||
#include <dev/le/lancevar.h>
|
||||
|
||||
devclass_t le_devclass;
|
||||
|
||||
static inline uint16_t ether_cmp(void *, void *);
|
||||
|
||||
static void lance_start(struct ifnet *);
|
||||
static void lance_stop(struct lance_softc *);
|
||||
static void lance_init(void *);
|
||||
static struct mbuf *lance_get(struct lance_softc *, int, int);
|
||||
static void lance_watchdog(struct ifnet *);
|
||||
static int lance_mediachange(struct ifnet *);
|
||||
static void lance_mediastatus(struct ifnet *, struct ifmediareq *);
|
||||
static int lance_ioctl(struct ifnet *, u_long, caddr_t);
|
||||
|
||||
/*
|
||||
* Compare two Ether/802 addresses for equality, inlined and
|
||||
* unrolled for speed. Use this like memcmp().
|
||||
*
|
||||
* XXX: Add <machine/inlines.h> for stuff like this?
|
||||
* XXX: or maybe add it to libkern.h instead?
|
||||
*
|
||||
* "I'd love to have an inline assembler version of this."
|
||||
* XXX: Who wanted that? mycroft? I wrote one, but this
|
||||
* version in C is as good as hand-coded assembly. -gwr
|
||||
*
|
||||
* Please do NOT tweak this without looking at the actual
|
||||
* assembly code generated before and after your tweaks!
|
||||
*/
|
||||
static inline uint16_t
|
||||
ether_cmp(void *one, void *two)
|
||||
{
|
||||
uint16_t *a = (u_short *)one;
|
||||
uint16_t *b = (u_short *)two;
|
||||
uint16_t diff;
|
||||
|
||||
#ifdef m68k
|
||||
/*
|
||||
* The post-increment-pointer form produces the best
|
||||
* machine code for m68k. This was carefully tuned
|
||||
* so it compiles to just 8 short (2-byte) op-codes!
|
||||
*/
|
||||
diff = *a++ - *b++;
|
||||
diff |= *a++ - *b++;
|
||||
diff |= *a++ - *b++;
|
||||
#else
|
||||
/*
|
||||
* Most modern CPUs do better with a single expresion.
|
||||
* Note that short-cut evaluation is NOT helpful here,
|
||||
* because it just makes the code longer, not faster!
|
||||
*/
|
||||
diff = (a[0] - b[0]) | (a[1] - b[1]) | (a[2] - b[2]);
|
||||
#endif
|
||||
|
||||
return (diff);
|
||||
}
|
||||
|
||||
#define ETHER_CMP ether_cmp
|
||||
|
||||
#ifdef LANCE_REVC_BUG
|
||||
/* Make sure this is short-aligned, for ether_cmp(). */
|
||||
static uint16_t bcast_enaddr[3] = { ~0, ~0, ~0 };
|
||||
#endif
|
||||
|
||||
int
|
||||
lance_config(struct lance_softc *sc, const char* name, int unit)
|
||||
{
|
||||
@ -424,7 +374,7 @@ lance_put(struct lance_softc *sc, int boff, struct mbuf *m)
|
||||
* We copy the data into mbufs. When full cluster sized units are present
|
||||
* we copy into clusters.
|
||||
*/
|
||||
static struct mbuf *
|
||||
struct mbuf *
|
||||
lance_get(struct lance_softc *sc, int boff, int totlen)
|
||||
{
|
||||
struct ifnet *ifp = sc->sc_ifp;
|
||||
@ -432,9 +382,16 @@ lance_get(struct lance_softc *sc, int boff, int totlen)
|
||||
caddr_t newdata;
|
||||
int len;
|
||||
|
||||
if (totlen <= ETHER_HDR_LEN || totlen > LEBLEN - ETHER_CRC_LEN) {
|
||||
#ifdef LEDEBUG
|
||||
if_printf(ifp, "invalid packet size %d; dropping\n", totlen);
|
||||
#endif
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
MGETHDR(m0, M_DONTWAIT, MT_DATA);
|
||||
if (m0 == 0)
|
||||
return (0);
|
||||
if (m0 == NULL)
|
||||
return (NULL);
|
||||
m0->m_pkthdr.rcvif = ifp;
|
||||
m0->m_pkthdr.len = totlen;
|
||||
len = MHLEN;
|
||||
@ -473,68 +430,7 @@ lance_get(struct lance_softc *sc, int boff, int totlen)
|
||||
|
||||
bad:
|
||||
m_freem(m0);
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Pass a packet to the higher levels.
|
||||
*/
|
||||
void
|
||||
lance_read(struct lance_softc *sc, int boff, int len)
|
||||
{
|
||||
struct ifnet *ifp = sc->sc_ifp;
|
||||
struct ether_header *eh;
|
||||
struct mbuf *m;
|
||||
|
||||
LE_LOCK_ASSERT(sc, MA_OWNED);
|
||||
|
||||
if (len <= ETHER_HDR_LEN || len > LEBLEN - ETHER_CRC_LEN) {
|
||||
#ifdef LEDEBUG
|
||||
if_printf(ifp, "invalid packet size %d; dropping\n", len);
|
||||
#endif
|
||||
ifp->if_ierrors++;
|
||||
return;
|
||||
}
|
||||
|
||||
/* Pull packet off interface. */
|
||||
m = lance_get(sc, boff, len);
|
||||
if (m == 0) {
|
||||
ifp->if_ierrors++;
|
||||
return;
|
||||
}
|
||||
|
||||
ifp->if_ipackets++;
|
||||
|
||||
eh = mtod(m, struct ether_header *);
|
||||
|
||||
#ifdef LANCE_REVC_BUG
|
||||
/*
|
||||
* The old LANCE (Rev. C) chips have a bug which causes
|
||||
* garbage to be inserted in front of the received packet.
|
||||
* The work-around is to ignore packets with an invalid
|
||||
* destination address (garbage will usually not match).
|
||||
* Of course, this precludes multicast support...
|
||||
*/
|
||||
if (ETHER_CMP(eh->ether_dhost, sc->sc_enaddr) &&
|
||||
ETHER_CMP(eh->ether_dhost, bcast_enaddr)) {
|
||||
m_freem(m);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Some lance device does not present IFF_SIMPLEX behavior on multicast
|
||||
* packets. Make sure to drop it if it is from ourselves.
|
||||
*/
|
||||
if (!ETHER_CMP(eh->ether_shost, sc->sc_enaddr)) {
|
||||
m_freem(m);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Pass the packet up. */
|
||||
LE_UNLOCK(sc);
|
||||
(*ifp->if_input)(ifp, m);
|
||||
LE_LOCK(sc);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -702,7 +598,7 @@ lance_setladrf(struct lance_softc *sc, uint16_t *af)
|
||||
crc >>= 26;
|
||||
|
||||
/* Set the corresponding bit in the filter. */
|
||||
af[crc >> 4] |= LE_HTOLE16(1U << (crc & 0xf));
|
||||
af[crc >> 4] |= LE_HTOLE16(1 << (crc & 0xf));
|
||||
}
|
||||
IF_ADDR_UNLOCK(ifp);
|
||||
}
|
||||
|
@ -497,7 +497,7 @@
|
||||
#define LE_B20_SSIZE32 0x0100 /* Software Size 32-bit */
|
||||
#define LE_B20_SSTYLE 0x0007 /* Software Style */
|
||||
#define LE_B20_SSTYLE_LANCE 0 /* LANCE/PCnet-ISA (16-bit) */
|
||||
#define LE_B20_SSTYPE_ILACC 1 /* ILACC (32-bit) */
|
||||
#define LE_B20_SSTYLE_ILACC 1 /* ILACC (32-bit) */
|
||||
#define LE_B20_SSTYLE_PCNETPCI2 2 /* PCnet-PCI (32-bit) */
|
||||
#define LE_B20_SSTYLE_PCNETPCI3 3 /* PCnet-PCI II (32-bit) */
|
||||
|
||||
|
@ -42,8 +42,6 @@
|
||||
#ifndef _DEV_LE_LANCEVAR_H_
|
||||
#define _DEV_LE_LANCEVAR_H_
|
||||
|
||||
#define LE_DRIVER_NAME "le"
|
||||
|
||||
extern devclass_t le_devclass;
|
||||
|
||||
struct lance_softc {
|
||||
@ -92,10 +90,10 @@ struct lance_softc {
|
||||
|
||||
uint16_t sc_conf3; /* CSR3 value */
|
||||
|
||||
void *sc_mem; /* base address of RAM -- CPU's view */
|
||||
u_long sc_addr; /* base address of RAM -- LANCE's view */
|
||||
void *sc_mem; /* base address of RAM - CPU's view */
|
||||
bus_addr_t sc_addr; /* base address of RAM - LANCE's view */
|
||||
|
||||
u_long sc_memsize; /* size of RAM */
|
||||
bus_size_t sc_memsize; /* size of RAM */
|
||||
|
||||
int sc_nrbuf; /* number of receive buffers */
|
||||
int sc_ntbuf; /* number of transmit buffers */
|
||||
@ -131,6 +129,11 @@ struct lance_softc {
|
||||
#define LE_LOCK_ASSERT(_sc, _what) mtx_assert(&(_sc)->sc_mtx, (_what))
|
||||
#define LE_LOCK_DESTROY(_sc) mtx_destroy(&(_sc)->sc_mtx)
|
||||
|
||||
/*
|
||||
* Unfortunately, manual byte swapping is only necessary for the PCnet-PCI
|
||||
* variants but not for the original LANCE or ILACC so we cannot do this
|
||||
* with #ifdefs resolved at compile time.
|
||||
*/
|
||||
#define LE_HTOLE16(v) (((sc)->sc_flags & LE_BSWAP) ? htole16(v) : (v))
|
||||
#define LE_HTOLE32(v) (((sc)->sc_flags & LE_BSWAP) ? htole32(v) : (v))
|
||||
#define LE_LE16TOH(v) (((sc)->sc_flags & LE_BSWAP) ? le16toh(v) : (v))
|
||||
@ -143,7 +146,7 @@ void lance_suspend(struct lance_softc *);
|
||||
void lance_resume(struct lance_softc *);
|
||||
void lance_init_locked(struct lance_softc *);
|
||||
int lance_put(struct lance_softc *, int, struct mbuf *);
|
||||
void lance_read(struct lance_softc *, int, int);
|
||||
struct mbuf *lance_get(struct lance_softc *, int, int);
|
||||
void lance_setladrf(struct lance_softc *, u_int16_t *);
|
||||
|
||||
/*
|
||||
@ -166,4 +169,46 @@ void lance_copyfrombuf_gap16(struct lance_softc *, void *, int, int);
|
||||
void lance_zerobuf_gap16(struct lance_softc *, int, int);
|
||||
#endif /* Example only */
|
||||
|
||||
/*
|
||||
* Compare two Ether/802 addresses for equality, inlined and
|
||||
* unrolled for speed. Use this like memcmp().
|
||||
*
|
||||
* XXX: Add <machine/inlines.h> for stuff like this?
|
||||
* XXX: or maybe add it to libkern.h instead?
|
||||
*
|
||||
* "I'd love to have an inline assembler version of this."
|
||||
* XXX: Who wanted that? mycroft? I wrote one, but this
|
||||
* version in C is as good as hand-coded assembly. -gwr
|
||||
*
|
||||
* Please do NOT tweak this without looking at the actual
|
||||
* assembly code generated before and after your tweaks!
|
||||
*/
|
||||
static inline uint16_t
|
||||
ether_cmp(void *one, void *two)
|
||||
{
|
||||
uint16_t *a = (u_short *)one;
|
||||
uint16_t *b = (u_short *)two;
|
||||
uint16_t diff;
|
||||
|
||||
#ifdef m68k
|
||||
/*
|
||||
* The post-increment-pointer form produces the best
|
||||
* machine code for m68k. This was carefully tuned
|
||||
* so it compiles to just 8 short (2-byte) op-codes!
|
||||
*/
|
||||
diff = *a++ - *b++;
|
||||
diff |= *a++ - *b++;
|
||||
diff |= *a++ - *b++;
|
||||
#else
|
||||
/*
|
||||
* Most modern CPUs do better with a single expresion.
|
||||
* Note that short-cut evaluation is NOT helpful here,
|
||||
* because it just makes the code longer, not faster!
|
||||
*/
|
||||
diff = (a[0] - b[0]) | (a[1] - b[1]) | (a[2] - b[2]);
|
||||
#endif
|
||||
|
||||
return (diff);
|
||||
}
|
||||
|
||||
#endif /* _DEV_LE_LANCEVAR_H_ */
|
||||
|
Loading…
Reference in New Issue
Block a user