2012-07-22 18:32:49 +04:00
|
|
|
/* $NetBSD: hme.c,v 1.89 2012/07/22 14:32:57 matt Exp $ */
|
1999-06-27 16:26:32 +04:00
|
|
|
|
|
|
|
/*-
|
|
|
|
* Copyright (c) 1999 The NetBSD Foundation, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by Paul Kranenburg.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 THE FOUNDATION OR CONTRIBUTORS
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* HME Ethernet module driver.
|
|
|
|
*/
|
|
|
|
|
2001-11-13 16:14:31 +03:00
|
|
|
#include <sys/cdefs.h>
|
2012-07-22 18:32:49 +04:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: hme.c,v 1.89 2012/07/22 14:32:57 matt Exp $");
|
2001-11-13 16:14:31 +03:00
|
|
|
|
2003-11-03 23:30:14 +03:00
|
|
|
/* #define HMEDEBUG */
|
1999-06-27 16:26:32 +04:00
|
|
|
|
|
|
|
#include "opt_inet.h"
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
1999-12-18 17:05:37 +03:00
|
|
|
#include <sys/kernel.h>
|
2004-10-27 02:52:44 +04:00
|
|
|
#include <sys/mbuf.h>
|
1999-06-27 16:26:32 +04:00
|
|
|
#include <sys/syslog.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/device.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/errno.h>
|
|
|
|
#include <sys/rnd.h>
|
|
|
|
|
|
|
|
#include <net/if.h>
|
|
|
|
#include <net/if_dl.h>
|
|
|
|
#include <net/if_ether.h>
|
|
|
|
#include <net/if_media.h>
|
|
|
|
|
|
|
|
#ifdef INET
|
2009-03-29 11:33:52 +04:00
|
|
|
#include <net/if_vlanvar.h>
|
1999-06-27 16:26:32 +04:00
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <netinet/if_inarp.h>
|
|
|
|
#include <netinet/in_systm.h>
|
|
|
|
#include <netinet/in_var.h>
|
|
|
|
#include <netinet/ip.h>
|
2005-02-18 03:40:32 +03:00
|
|
|
#include <netinet/tcp.h>
|
|
|
|
#include <netinet/udp.h>
|
1999-06-27 16:26:32 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#include <net/bpf.h>
|
|
|
|
#include <net/bpfdesc.h>
|
|
|
|
|
|
|
|
#include <dev/mii/mii.h>
|
|
|
|
#include <dev/mii/miivar.h>
|
|
|
|
|
2007-10-19 15:59:34 +04:00
|
|
|
#include <sys/bus.h>
|
1999-06-27 16:26:32 +04:00
|
|
|
|
|
|
|
#include <dev/ic/hmereg.h>
|
|
|
|
#include <dev/ic/hmevar.h>
|
|
|
|
|
2009-09-08 22:35:42 +04:00
|
|
|
static void hme_start(struct ifnet *);
|
|
|
|
static void hme_stop(struct ifnet *, int);
|
|
|
|
static int hme_ioctl(struct ifnet *, u_long, void *);
|
|
|
|
static void hme_tick(void *);
|
|
|
|
static void hme_watchdog(struct ifnet *);
|
|
|
|
static bool hme_shutdown(device_t, int);
|
2009-11-04 01:06:30 +03:00
|
|
|
static int hme_init(struct ifnet *);
|
2009-09-08 22:35:42 +04:00
|
|
|
static void hme_meminit(struct hme_softc *);
|
|
|
|
static void hme_mifinit(struct hme_softc *);
|
2009-09-18 16:40:15 +04:00
|
|
|
static void hme_reset(struct hme_softc *);
|
2009-09-08 22:35:42 +04:00
|
|
|
static void hme_chipreset(struct hme_softc *);
|
|
|
|
static void hme_setladrf(struct hme_softc *);
|
1999-06-27 16:26:32 +04:00
|
|
|
|
|
|
|
/* MII methods & callbacks */
|
2009-05-12 18:16:35 +04:00
|
|
|
static int hme_mii_readreg(device_t, int, int);
|
|
|
|
static void hme_mii_writereg(device_t, int, int, int);
|
2012-07-22 18:32:49 +04:00
|
|
|
static void hme_mii_statchg(struct ifnet *);
|
1999-06-27 16:26:32 +04:00
|
|
|
|
2009-09-08 22:35:42 +04:00
|
|
|
static int hme_mediachange(struct ifnet *);
|
1999-06-27 16:26:32 +04:00
|
|
|
|
2009-09-08 22:35:42 +04:00
|
|
|
static struct mbuf *hme_get(struct hme_softc *, int, uint32_t);
|
|
|
|
static int hme_put(struct hme_softc *, int, struct mbuf *);
|
|
|
|
static void hme_read(struct hme_softc *, int, uint32_t);
|
|
|
|
static int hme_eint(struct hme_softc *, u_int);
|
|
|
|
static int hme_rint(struct hme_softc *);
|
|
|
|
static int hme_tint(struct hme_softc *);
|
1999-06-27 16:26:32 +04:00
|
|
|
|
2009-09-08 22:35:42 +04:00
|
|
|
#if 0
|
2001-11-26 13:39:29 +03:00
|
|
|
/* Default buffer copy routines */
|
2009-09-08 22:35:42 +04:00
|
|
|
static void hme_copytobuf_contig(struct hme_softc *, void *, int, int);
|
|
|
|
static void hme_copyfrombuf_contig(struct hme_softc *, void *, int, int);
|
|
|
|
#endif
|
2001-11-26 13:39:29 +03:00
|
|
|
|
1999-06-27 16:26:32 +04:00
|
|
|
void
|
2009-03-14 18:35:58 +03:00
|
|
|
hme_config(struct hme_softc *sc)
|
1999-06-27 16:26:32 +04:00
|
|
|
{
|
|
|
|
struct ifnet *ifp = &sc->sc_ethercom.ec_if;
|
|
|
|
struct mii_data *mii = &sc->sc_mii;
|
1999-12-18 17:05:37 +03:00
|
|
|
struct mii_softc *child;
|
2000-05-10 02:42:08 +04:00
|
|
|
bus_dma_tag_t dmatag = sc->sc_dmatag;
|
1999-06-27 16:26:32 +04:00
|
|
|
bus_dma_segment_t seg;
|
|
|
|
bus_size_t size;
|
2001-11-26 13:39:29 +03:00
|
|
|
int rseg, error;
|
1999-06-27 16:26:32 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* HME common initialization.
|
|
|
|
*
|
|
|
|
* hme_softc fields that must be initialized by the front-end:
|
|
|
|
*
|
|
|
|
* the bus tag:
|
|
|
|
* sc_bustag
|
|
|
|
*
|
2003-05-03 22:10:37 +04:00
|
|
|
* the DMA bus tag:
|
1999-06-27 16:26:32 +04:00
|
|
|
* sc_dmatag
|
|
|
|
*
|
|
|
|
* the bus handles:
|
|
|
|
* sc_seb (Shared Ethernet Block registers)
|
|
|
|
* sc_erx (Receiver Unit registers)
|
|
|
|
* sc_etx (Transmitter Unit registers)
|
|
|
|
* sc_mac (MAC registers)
|
2003-04-27 02:07:12 +04:00
|
|
|
* sc_mif (Management Interface registers)
|
1999-06-27 16:26:32 +04:00
|
|
|
*
|
|
|
|
* the maximum bus burst size:
|
|
|
|
* sc_burst
|
|
|
|
*
|
2001-11-26 13:39:29 +03:00
|
|
|
* (notyet:DMA capable memory for the ring descriptors & packet buffers:
|
|
|
|
* rb_membase, rb_dmabase)
|
|
|
|
*
|
1999-06-27 16:26:32 +04:00
|
|
|
* the local Ethernet address:
|
|
|
|
* sc_enaddr
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Make sure the chip is stopped. */
|
2009-09-08 21:16:33 +04:00
|
|
|
hme_chipreset(sc);
|
1999-06-27 16:26:32 +04:00
|
|
|
|
2001-11-26 13:39:29 +03:00
|
|
|
/*
|
|
|
|
* Allocate descriptors and buffers
|
|
|
|
* XXX - do all this differently.. and more configurably,
|
|
|
|
* eg. use things as `dma_load_mbuf()' on transmit,
|
|
|
|
* and a pool of `EXTMEM' mbufs (with buffers DMA-mapped
|
2003-11-02 14:07:44 +03:00
|
|
|
* all the time) on the receiver side.
|
2001-11-26 13:39:29 +03:00
|
|
|
*
|
|
|
|
* Note: receive buffers must be 64-byte aligned.
|
|
|
|
* Also, apparently, the buffers must extend to a DMA burst
|
|
|
|
* boundary beyond the maximum packet size.
|
|
|
|
*/
|
|
|
|
#define _HME_NDESC 128
|
|
|
|
#define _HME_BUFSZ 1600
|
|
|
|
|
|
|
|
/* Note: the # of descriptors must be a multiple of 16 */
|
|
|
|
sc->sc_rb.rb_ntbuf = _HME_NDESC;
|
|
|
|
sc->sc_rb.rb_nrbuf = _HME_NDESC;
|
1999-06-27 16:26:32 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate DMA capable memory
|
|
|
|
* Buffer descriptors must be aligned on a 2048 byte boundary;
|
|
|
|
* take this into account when calculating the size. Note that
|
|
|
|
* the maximum number of descriptors (256) occupies 2048 bytes,
|
2001-11-26 13:39:29 +03:00
|
|
|
* so we allocate that much regardless of _HME_NDESC.
|
1999-06-27 16:26:32 +04:00
|
|
|
*/
|
2001-11-26 13:39:29 +03:00
|
|
|
size = 2048 + /* TX descriptors */
|
|
|
|
2048 + /* RX descriptors */
|
|
|
|
sc->sc_rb.rb_ntbuf * _HME_BUFSZ + /* TX buffers */
|
2005-02-18 03:40:32 +03:00
|
|
|
sc->sc_rb.rb_nrbuf * _HME_BUFSZ; /* RX buffers */
|
2000-05-10 02:42:08 +04:00
|
|
|
|
|
|
|
/* Allocate DMA buffer */
|
2001-11-26 13:39:29 +03:00
|
|
|
if ((error = bus_dmamem_alloc(dmatag, size,
|
|
|
|
2048, 0,
|
|
|
|
&seg, 1, &rseg, BUS_DMA_NOWAIT)) != 0) {
|
2009-05-17 04:40:43 +04:00
|
|
|
aprint_error_dev(sc->sc_dev, "DMA buffer alloc error %d\n",
|
2008-04-08 16:07:25 +04:00
|
|
|
error);
|
2000-04-05 09:54:02 +04:00
|
|
|
return;
|
1999-06-27 16:26:32 +04:00
|
|
|
}
|
|
|
|
|
2000-05-10 02:42:08 +04:00
|
|
|
/* Map DMA memory in CPU addressable space */
|
|
|
|
if ((error = bus_dmamem_map(dmatag, &seg, rseg, size,
|
2001-11-26 13:39:29 +03:00
|
|
|
&sc->sc_rb.rb_membase,
|
|
|
|
BUS_DMA_NOWAIT|BUS_DMA_COHERENT)) != 0) {
|
2009-05-17 04:40:43 +04:00
|
|
|
aprint_error_dev(sc->sc_dev, "DMA buffer map error %d\n",
|
2008-04-08 16:07:25 +04:00
|
|
|
error);
|
2000-05-10 02:42:08 +04:00
|
|
|
bus_dmamap_unload(dmatag, sc->sc_dmamap);
|
|
|
|
bus_dmamem_free(dmatag, &seg, rseg);
|
1999-06-27 16:26:32 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2000-05-18 18:00:46 +04:00
|
|
|
if ((error = bus_dmamap_create(dmatag, size, 1, size, 0,
|
2001-11-26 13:39:29 +03:00
|
|
|
BUS_DMA_NOWAIT, &sc->sc_dmamap)) != 0) {
|
2009-05-17 04:40:43 +04:00
|
|
|
aprint_error_dev(sc->sc_dev, "DMA map create error %d\n",
|
2008-04-08 16:07:25 +04:00
|
|
|
error);
|
2000-05-18 18:00:46 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Load the buffer */
|
|
|
|
if ((error = bus_dmamap_load(dmatag, sc->sc_dmamap,
|
2000-10-20 10:08:02 +04:00
|
|
|
sc->sc_rb.rb_membase, size, NULL,
|
|
|
|
BUS_DMA_NOWAIT|BUS_DMA_COHERENT)) != 0) {
|
2009-05-17 04:40:43 +04:00
|
|
|
aprint_error_dev(sc->sc_dev, "DMA buffer map load error %d\n",
|
2008-04-08 16:07:25 +04:00
|
|
|
error);
|
2000-05-18 18:00:46 +04:00
|
|
|
bus_dmamem_free(dmatag, &seg, rseg);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
sc->sc_rb.rb_dmabase = sc->sc_dmamap->dm_segs[0].ds_addr;
|
|
|
|
|
2009-05-17 04:40:43 +04:00
|
|
|
aprint_normal_dev(sc->sc_dev, "Ethernet address %s\n",
|
2001-10-05 21:49:43 +04:00
|
|
|
ether_sprintf(sc->sc_enaddr));
|
1999-12-15 02:58:15 +03:00
|
|
|
|
1999-06-27 16:26:32 +04:00
|
|
|
/* Initialize ifnet structure. */
|
2009-05-17 04:40:43 +04:00
|
|
|
strlcpy(ifp->if_xname, device_xname(sc->sc_dev), IFNAMSIZ);
|
1999-06-27 16:26:32 +04:00
|
|
|
ifp->if_softc = sc;
|
|
|
|
ifp->if_start = hme_start;
|
2009-09-08 21:16:33 +04:00
|
|
|
ifp->if_stop = hme_stop;
|
1999-06-27 16:26:32 +04:00
|
|
|
ifp->if_ioctl = hme_ioctl;
|
2009-11-04 01:06:30 +03:00
|
|
|
ifp->if_init = hme_init;
|
1999-06-27 16:26:32 +04:00
|
|
|
ifp->if_watchdog = hme_watchdog;
|
|
|
|
ifp->if_flags =
|
|
|
|
IFF_BROADCAST | IFF_SIMPLEX | IFF_NOTRAILERS | IFF_MULTICAST;
|
2004-06-29 00:50:52 +04:00
|
|
|
sc->sc_if_flags = ifp->if_flags;
|
2005-05-02 19:34:31 +04:00
|
|
|
ifp->if_capabilities |=
|
|
|
|
IFCAP_CSUM_TCPv4_Tx | IFCAP_CSUM_TCPv4_Rx |
|
|
|
|
IFCAP_CSUM_UDPv4_Tx | IFCAP_CSUM_UDPv4_Rx;
|
2000-12-14 09:27:23 +03:00
|
|
|
IFQ_SET_READY(&ifp->if_snd);
|
1999-06-27 16:26:32 +04:00
|
|
|
|
|
|
|
/* Initialize ifmedia structures and MII info */
|
|
|
|
mii->mii_ifp = ifp;
|
2003-02-20 23:09:56 +03:00
|
|
|
mii->mii_readreg = hme_mii_readreg;
|
1999-06-27 16:26:32 +04:00
|
|
|
mii->mii_writereg = hme_mii_writereg;
|
|
|
|
mii->mii_statchg = hme_mii_statchg;
|
|
|
|
|
Make many ethernet drivers share the common code for MII media
handling, ether_mediastatus() and ether_mediachange(). Check for
a non-ENXIO error return from mii_mediachg(). (ENXIO indicates
that a PHY is suspended.)
This patch shrinks the source code size by 979 lines. There was
a 5100-byte savings on the NetBSD/i386 kernel configuration, ALL.
I have made a few miscellaneous changes, too:
gem(4): use LIST_EMPTY(), LIST_FOREACH().
mtd(4): handle media ioctls, for a change!
axe(4): do not track link status in sc->axe_link any longer
nfe(4), aue(4), axe(4), udav(4), url(4): do not reset all PHYs
on a change of media
Except for the change to mtd(4), no functional changes are intended.
XXX This patch affects more architectures than I can feasibly
XXX compile and run. I have compiled macppc, sparc64, i386. I
XXX have run the patches on i386 boxen with bnx(4) and sip(4).
XXX Compiling and running on evbmips (MERAKI, ADM5120) is in
XXX progress.
2008-01-20 01:10:14 +03:00
|
|
|
sc->sc_ethercom.ec_mii = mii;
|
|
|
|
ifmedia_init(&mii->mii_media, 0, hme_mediachange, ether_mediastatus);
|
1999-06-27 16:26:32 +04:00
|
|
|
|
1999-12-17 17:37:15 +03:00
|
|
|
hme_mifinit(sc);
|
|
|
|
|
2009-05-17 04:40:43 +04:00
|
|
|
mii_attach(sc->sc_dev, mii, 0xffffffff,
|
2012-06-24 13:37:28 +04:00
|
|
|
MII_PHY_ANY, MII_OFFSET_ANY, MIIF_FORCEANEG);
|
1999-12-15 02:58:15 +03:00
|
|
|
|
1999-12-18 17:05:37 +03:00
|
|
|
child = LIST_FIRST(&mii->mii_phys);
|
|
|
|
if (child == NULL) {
|
1999-06-27 16:26:32 +04:00
|
|
|
/* No PHY attached */
|
Make many ethernet drivers share the common code for MII media
handling, ether_mediastatus() and ether_mediachange(). Check for
a non-ENXIO error return from mii_mediachg(). (ENXIO indicates
that a PHY is suspended.)
This patch shrinks the source code size by 979 lines. There was
a 5100-byte savings on the NetBSD/i386 kernel configuration, ALL.
I have made a few miscellaneous changes, too:
gem(4): use LIST_EMPTY(), LIST_FOREACH().
mtd(4): handle media ioctls, for a change!
axe(4): do not track link status in sc->axe_link any longer
nfe(4), aue(4), axe(4), udav(4), url(4): do not reset all PHYs
on a change of media
Except for the change to mtd(4), no functional changes are intended.
XXX This patch affects more architectures than I can feasibly
XXX compile and run. I have compiled macppc, sparc64, i386. I
XXX have run the patches on i386 boxen with bnx(4) and sip(4).
XXX Compiling and running on evbmips (MERAKI, ADM5120) is in
XXX progress.
2008-01-20 01:10:14 +03:00
|
|
|
ifmedia_add(&sc->sc_mii.mii_media, IFM_ETHER|IFM_MANUAL, 0, NULL);
|
|
|
|
ifmedia_set(&sc->sc_mii.mii_media, IFM_ETHER|IFM_MANUAL);
|
1999-06-27 16:26:32 +04:00
|
|
|
} else {
|
1999-12-18 17:05:37 +03:00
|
|
|
/*
|
|
|
|
* Walk along the list of attached MII devices and
|
|
|
|
* establish an `MII instance' to `phy number'
|
|
|
|
* mapping. We'll use this mapping in media change
|
|
|
|
* requests to determine which phy to use to program
|
|
|
|
* the MIF configuration register.
|
|
|
|
*/
|
|
|
|
for (; child != NULL; child = LIST_NEXT(child, mii_list)) {
|
|
|
|
/*
|
|
|
|
* Note: we support just two PHYs: the built-in
|
|
|
|
* internal device and an external on the MII
|
|
|
|
* connector.
|
|
|
|
*/
|
|
|
|
if (child->mii_phy > 1 || child->mii_inst > 1) {
|
2009-05-17 04:40:43 +04:00
|
|
|
aprint_error_dev(sc->sc_dev,
|
|
|
|
"cannot accommodate MII device %s"
|
2001-11-26 13:39:29 +03:00
|
|
|
" at phy %d, instance %d\n",
|
2008-05-04 21:06:09 +04:00
|
|
|
device_xname(child->mii_dev),
|
2001-11-26 13:39:29 +03:00
|
|
|
child->mii_phy, child->mii_inst);
|
1999-12-18 17:05:37 +03:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
sc->sc_phys[child->mii_inst] = child->mii_phy;
|
|
|
|
}
|
|
|
|
|
1999-06-27 16:26:32 +04:00
|
|
|
/*
|
2009-05-07 00:40:19 +04:00
|
|
|
* Set the default media to auto negotiation if the phy has
|
|
|
|
* the auto negotiation capability.
|
|
|
|
* XXX; What to do otherwise?
|
1999-06-27 16:26:32 +04:00
|
|
|
*/
|
2009-05-07 00:40:19 +04:00
|
|
|
if (ifmedia_match(&sc->sc_mii.mii_media, IFM_ETHER|IFM_AUTO, 0))
|
|
|
|
ifmedia_set(&sc->sc_mii.mii_media, IFM_ETHER|IFM_AUTO);
|
|
|
|
/*
|
|
|
|
else
|
|
|
|
ifmedia_set(&sc->sc_mii.mii_media, sc->sc_defaultmedia);
|
|
|
|
*/
|
1999-06-27 16:26:32 +04:00
|
|
|
}
|
|
|
|
|
2001-11-26 13:39:29 +03:00
|
|
|
/* claim 802.1q capability */
|
2001-11-26 09:51:12 +03:00
|
|
|
sc->sc_ethercom.ec_capabilities |= ETHERCAP_VLAN_MTU;
|
|
|
|
|
1999-06-27 16:26:32 +04:00
|
|
|
/* Attach the interface. */
|
|
|
|
if_attach(ifp);
|
|
|
|
ether_ifattach(ifp, sc->sc_enaddr);
|
|
|
|
|
2009-09-08 21:16:33 +04:00
|
|
|
if (pmf_device_register1(sc->sc_dev, NULL, NULL, hme_shutdown))
|
|
|
|
pmf_class_network_register(sc->sc_dev, ifp);
|
|
|
|
else
|
|
|
|
aprint_error_dev(sc->sc_dev,
|
|
|
|
"couldn't establish power handler\n");
|
1999-06-27 16:26:32 +04:00
|
|
|
|
2009-05-17 04:40:43 +04:00
|
|
|
rnd_attach_source(&sc->rnd_source, device_xname(sc->sc_dev),
|
1999-06-27 16:26:32 +04:00
|
|
|
RND_TYPE_NET, 0);
|
1999-12-18 17:05:37 +03:00
|
|
|
|
2007-07-10 00:51:58 +04:00
|
|
|
callout_init(&sc->sc_tick_ch, 0);
|
1999-12-18 17:05:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-03-14 18:35:58 +03:00
|
|
|
hme_tick(void *arg)
|
1999-12-18 17:05:37 +03:00
|
|
|
{
|
|
|
|
struct hme_softc *sc = arg;
|
|
|
|
int s;
|
|
|
|
|
|
|
|
s = splnet();
|
|
|
|
mii_tick(&sc->sc_mii);
|
|
|
|
splx(s);
|
|
|
|
|
2000-03-23 10:01:25 +03:00
|
|
|
callout_reset(&sc->sc_tick_ch, hz, hme_tick, sc);
|
1999-06-27 16:26:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-03-14 18:35:58 +03:00
|
|
|
hme_reset(struct hme_softc *sc)
|
1999-06-27 16:26:32 +04:00
|
|
|
{
|
|
|
|
int s;
|
|
|
|
|
|
|
|
s = splnet();
|
2009-11-04 01:06:30 +03:00
|
|
|
(void)hme_init(&sc->sc_ethercom.ec_if);
|
1999-06-27 16:26:32 +04:00
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-09-08 21:16:33 +04:00
|
|
|
hme_chipreset(struct hme_softc *sc)
|
1999-06-27 16:26:32 +04:00
|
|
|
{
|
|
|
|
bus_space_tag_t t = sc->sc_bustag;
|
|
|
|
bus_space_handle_t seb = sc->sc_seb;
|
|
|
|
int n;
|
|
|
|
|
2003-02-13 15:10:20 +03:00
|
|
|
/* Mask all interrupts */
|
|
|
|
bus_space_write_4(t, seb, HME_SEBI_IMASK, 0xffffffff);
|
|
|
|
|
1999-06-27 16:26:32 +04:00
|
|
|
/* Reset transmitter and receiver */
|
|
|
|
bus_space_write_4(t, seb, HME_SEBI_RESET,
|
2001-11-26 13:39:29 +03:00
|
|
|
(HME_SEB_RESET_ETX | HME_SEB_RESET_ERX));
|
1999-06-27 16:26:32 +04:00
|
|
|
|
|
|
|
for (n = 0; n < 20; n++) {
|
2009-04-16 18:08:18 +04:00
|
|
|
uint32_t v = bus_space_read_4(t, seb, HME_SEBI_RESET);
|
1999-06-27 16:26:32 +04:00
|
|
|
if ((v & (HME_SEB_RESET_ETX | HME_SEB_RESET_ERX)) == 0)
|
|
|
|
return;
|
|
|
|
DELAY(20);
|
|
|
|
}
|
|
|
|
|
2009-09-08 21:16:33 +04:00
|
|
|
printf("%s: %s: reset failed\n", device_xname(sc->sc_dev), __func__);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
hme_stop(struct ifnet *ifp, int disable)
|
|
|
|
{
|
|
|
|
struct hme_softc *sc;
|
|
|
|
|
|
|
|
sc = ifp->if_softc;
|
|
|
|
|
|
|
|
ifp->if_timer = 0;
|
|
|
|
ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE);
|
|
|
|
|
|
|
|
callout_stop(&sc->sc_tick_ch);
|
|
|
|
mii_down(&sc->sc_mii);
|
|
|
|
|
|
|
|
hme_chipreset(sc);
|
1999-06-27 16:26:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-03-14 18:35:58 +03:00
|
|
|
hme_meminit(struct hme_softc *sc)
|
1999-06-27 16:26:32 +04:00
|
|
|
{
|
2001-11-26 13:39:29 +03:00
|
|
|
bus_addr_t txbufdma, rxbufdma;
|
1999-06-27 16:26:32 +04:00
|
|
|
bus_addr_t dma;
|
2007-03-04 08:59:00 +03:00
|
|
|
char *p;
|
2001-11-26 13:39:29 +03:00
|
|
|
unsigned int ntbuf, nrbuf, i;
|
1999-06-27 16:26:32 +04:00
|
|
|
struct hme_ring *hr = &sc->sc_rb;
|
|
|
|
|
|
|
|
p = hr->rb_membase;
|
|
|
|
dma = hr->rb_dmabase;
|
|
|
|
|
2001-11-26 13:39:29 +03:00
|
|
|
ntbuf = hr->rb_ntbuf;
|
|
|
|
nrbuf = hr->rb_nrbuf;
|
|
|
|
|
1999-06-27 16:26:32 +04:00
|
|
|
/*
|
|
|
|
* Allocate transmit descriptors
|
|
|
|
*/
|
|
|
|
hr->rb_txd = p;
|
|
|
|
hr->rb_txddma = dma;
|
2001-11-26 13:39:29 +03:00
|
|
|
p += ntbuf * HME_XD_SIZE;
|
|
|
|
dma += ntbuf * HME_XD_SIZE;
|
1999-12-17 17:37:15 +03:00
|
|
|
/* We have reserved descriptor space until the next 2048 byte boundary.*/
|
|
|
|
dma = (bus_addr_t)roundup((u_long)dma, 2048);
|
2007-03-04 08:59:00 +03:00
|
|
|
p = (void *)roundup((u_long)p, 2048);
|
1999-06-27 16:26:32 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate receive descriptors
|
|
|
|
*/
|
|
|
|
hr->rb_rxd = p;
|
|
|
|
hr->rb_rxddma = dma;
|
2001-11-26 13:39:29 +03:00
|
|
|
p += nrbuf * HME_XD_SIZE;
|
|
|
|
dma += nrbuf * HME_XD_SIZE;
|
1999-12-17 17:37:15 +03:00
|
|
|
/* Again move forward to the next 2048 byte boundary.*/
|
|
|
|
dma = (bus_addr_t)roundup((u_long)dma, 2048);
|
2007-03-04 08:59:00 +03:00
|
|
|
p = (void *)roundup((u_long)p, 2048);
|
1999-06-27 16:26:32 +04:00
|
|
|
|
2001-11-26 13:39:29 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate transmit buffers
|
|
|
|
*/
|
|
|
|
hr->rb_txbuf = p;
|
|
|
|
txbufdma = dma;
|
|
|
|
p += ntbuf * _HME_BUFSZ;
|
|
|
|
dma += ntbuf * _HME_BUFSZ;
|
|
|
|
|
1999-06-27 16:26:32 +04:00
|
|
|
/*
|
2001-11-26 13:39:29 +03:00
|
|
|
* Allocate receive buffers
|
1999-06-27 16:26:32 +04:00
|
|
|
*/
|
2001-11-26 13:39:29 +03:00
|
|
|
hr->rb_rxbuf = p;
|
|
|
|
rxbufdma = dma;
|
|
|
|
p += nrbuf * _HME_BUFSZ;
|
|
|
|
dma += nrbuf * _HME_BUFSZ;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize transmit buffer descriptors
|
|
|
|
*/
|
|
|
|
for (i = 0; i < ntbuf; i++) {
|
|
|
|
HME_XD_SETADDR(sc->sc_pci, hr->rb_txd, i, txbufdma + i * _HME_BUFSZ);
|
2000-06-25 05:05:16 +04:00
|
|
|
HME_XD_SETFLAGS(sc->sc_pci, hr->rb_txd, i, 0);
|
1999-06-27 16:26:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2001-11-26 13:39:29 +03:00
|
|
|
* Initialize receive buffer descriptors
|
1999-06-27 16:26:32 +04:00
|
|
|
*/
|
2001-11-26 13:39:29 +03:00
|
|
|
for (i = 0; i < nrbuf; i++) {
|
|
|
|
HME_XD_SETADDR(sc->sc_pci, hr->rb_rxd, i, rxbufdma + i * _HME_BUFSZ);
|
2000-06-25 05:05:16 +04:00
|
|
|
HME_XD_SETFLAGS(sc->sc_pci, hr->rb_rxd, i,
|
2001-11-26 13:39:29 +03:00
|
|
|
HME_XD_OWN | HME_XD_ENCODE_RSIZE(_HME_BUFSZ));
|
1999-06-27 16:26:32 +04:00
|
|
|
}
|
|
|
|
|
2001-11-26 13:39:29 +03:00
|
|
|
hr->rb_tdhead = hr->rb_tdtail = 0;
|
|
|
|
hr->rb_td_nbusy = 0;
|
|
|
|
hr->rb_rdtail = 0;
|
1999-06-27 16:26:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialization of interface; set up initialization block
|
|
|
|
* and transmit/receive descriptor rings.
|
|
|
|
*/
|
Make many ethernet drivers share the common code for MII media
handling, ether_mediastatus() and ether_mediachange(). Check for
a non-ENXIO error return from mii_mediachg(). (ENXIO indicates
that a PHY is suspended.)
This patch shrinks the source code size by 979 lines. There was
a 5100-byte savings on the NetBSD/i386 kernel configuration, ALL.
I have made a few miscellaneous changes, too:
gem(4): use LIST_EMPTY(), LIST_FOREACH().
mtd(4): handle media ioctls, for a change!
axe(4): do not track link status in sc->axe_link any longer
nfe(4), aue(4), axe(4), udav(4), url(4): do not reset all PHYs
on a change of media
Except for the change to mtd(4), no functional changes are intended.
XXX This patch affects more architectures than I can feasibly
XXX compile and run. I have compiled macppc, sparc64, i386. I
XXX have run the patches on i386 boxen with bnx(4) and sip(4).
XXX Compiling and running on evbmips (MERAKI, ADM5120) is in
XXX progress.
2008-01-20 01:10:14 +03:00
|
|
|
int
|
2009-11-04 01:06:30 +03:00
|
|
|
hme_init(struct ifnet *ifp)
|
1999-06-27 16:26:32 +04:00
|
|
|
{
|
2009-11-04 01:06:30 +03:00
|
|
|
struct hme_softc *sc = ifp->if_softc;
|
1999-06-27 16:26:32 +04:00
|
|
|
bus_space_tag_t t = sc->sc_bustag;
|
|
|
|
bus_space_handle_t seb = sc->sc_seb;
|
|
|
|
bus_space_handle_t etx = sc->sc_etx;
|
|
|
|
bus_space_handle_t erx = sc->sc_erx;
|
|
|
|
bus_space_handle_t mac = sc->sc_mac;
|
2009-04-16 18:08:18 +04:00
|
|
|
uint8_t *ea;
|
|
|
|
uint32_t v;
|
Make many ethernet drivers share the common code for MII media
handling, ether_mediastatus() and ether_mediachange(). Check for
a non-ENXIO error return from mii_mediachg(). (ENXIO indicates
that a PHY is suspended.)
This patch shrinks the source code size by 979 lines. There was
a 5100-byte savings on the NetBSD/i386 kernel configuration, ALL.
I have made a few miscellaneous changes, too:
gem(4): use LIST_EMPTY(), LIST_FOREACH().
mtd(4): handle media ioctls, for a change!
axe(4): do not track link status in sc->axe_link any longer
nfe(4), aue(4), axe(4), udav(4), url(4): do not reset all PHYs
on a change of media
Except for the change to mtd(4), no functional changes are intended.
XXX This patch affects more architectures than I can feasibly
XXX compile and run. I have compiled macppc, sparc64, i386. I
XXX have run the patches on i386 boxen with bnx(4) and sip(4).
XXX Compiling and running on evbmips (MERAKI, ADM5120) is in
XXX progress.
2008-01-20 01:10:14 +03:00
|
|
|
int rc;
|
1999-06-27 16:26:32 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialization sequence. The numbered steps below correspond
|
|
|
|
* to the sequence outlined in section 6.3.5.1 in the Ethernet
|
|
|
|
* Channel Engine manual (part of the PCIO manual).
|
|
|
|
* See also the STP2002-STQ document from Sun Microsystems.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* step 1 & 2. Reset the Ethernet Channel */
|
2009-09-08 21:16:33 +04:00
|
|
|
hme_stop(ifp, 0);
|
1999-06-27 16:26:32 +04:00
|
|
|
|
1999-12-17 17:37:15 +03:00
|
|
|
/* Re-initialize the MIF */
|
|
|
|
hme_mifinit(sc);
|
|
|
|
|
1999-06-27 16:26:32 +04:00
|
|
|
/* Call MI reset function if any */
|
|
|
|
if (sc->sc_hwreset)
|
|
|
|
(*sc->sc_hwreset)(sc);
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
/* Mask all MIF interrupts, just in case */
|
|
|
|
bus_space_write_4(t, mif, HME_MIFI_IMASK, 0xffff);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* step 3. Setup data structures in host memory */
|
|
|
|
hme_meminit(sc);
|
|
|
|
|
|
|
|
/* step 4. TX MAC registers & counters */
|
|
|
|
bus_space_write_4(t, mac, HME_MACI_NCCNT, 0);
|
|
|
|
bus_space_write_4(t, mac, HME_MACI_FCCNT, 0);
|
|
|
|
bus_space_write_4(t, mac, HME_MACI_EXCNT, 0);
|
|
|
|
bus_space_write_4(t, mac, HME_MACI_LTCNT, 0);
|
2001-11-26 13:39:29 +03:00
|
|
|
bus_space_write_4(t, mac, HME_MACI_TXSIZE,
|
|
|
|
(sc->sc_ethercom.ec_capenable & ETHERCAP_VLAN_MTU) ?
|
2005-03-05 21:36:23 +03:00
|
|
|
ETHER_VLAN_ENCAP_LEN + ETHER_MAX_LEN : ETHER_MAX_LEN);
|
2005-02-18 03:22:11 +03:00
|
|
|
sc->sc_ec_capenable = sc->sc_ethercom.ec_capenable;
|
1999-06-27 16:26:32 +04:00
|
|
|
|
|
|
|
/* Load station MAC address */
|
|
|
|
ea = sc->sc_enaddr;
|
|
|
|
bus_space_write_4(t, mac, HME_MACI_MACADDR0, (ea[0] << 8) | ea[1]);
|
|
|
|
bus_space_write_4(t, mac, HME_MACI_MACADDR1, (ea[2] << 8) | ea[3]);
|
|
|
|
bus_space_write_4(t, mac, HME_MACI_MACADDR2, (ea[4] << 8) | ea[5]);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Init seed for backoff
|
|
|
|
* (source suggested by manual: low 10 bits of MAC address)
|
2004-10-27 02:52:44 +04:00
|
|
|
*/
|
1999-06-27 16:26:32 +04:00
|
|
|
v = ((ea[4] << 8) | ea[5]) & 0x3fff;
|
|
|
|
bus_space_write_4(t, mac, HME_MACI_RANDSEED, v);
|
|
|
|
|
|
|
|
|
|
|
|
/* Note: Accepting power-on default for other MAC registers here.. */
|
|
|
|
|
|
|
|
|
|
|
|
/* step 5. RX MAC registers & counters */
|
|
|
|
hme_setladrf(sc);
|
|
|
|
|
|
|
|
/* step 6 & 7. Program Descriptor Ring Base Addresses */
|
|
|
|
bus_space_write_4(t, etx, HME_ETXI_RING, sc->sc_rb.rb_txddma);
|
2001-11-26 13:39:29 +03:00
|
|
|
bus_space_write_4(t, etx, HME_ETXI_RSIZE, sc->sc_rb.rb_ntbuf);
|
1999-06-27 16:26:32 +04:00
|
|
|
|
|
|
|
bus_space_write_4(t, erx, HME_ERXI_RING, sc->sc_rb.rb_rxddma);
|
2001-11-26 13:39:29 +03:00
|
|
|
bus_space_write_4(t, mac, HME_MACI_RXSIZE,
|
|
|
|
(sc->sc_ethercom.ec_capenable & ETHERCAP_VLAN_MTU) ?
|
2005-03-05 21:36:23 +03:00
|
|
|
ETHER_VLAN_ENCAP_LEN + ETHER_MAX_LEN : ETHER_MAX_LEN);
|
1999-06-27 16:26:32 +04:00
|
|
|
|
|
|
|
/* step 8. Global Configuration & Interrupt Mask */
|
|
|
|
bus_space_write_4(t, seb, HME_SEBI_IMASK,
|
2001-11-26 13:39:29 +03:00
|
|
|
~(
|
|
|
|
/*HME_SEB_STAT_GOTFRAME | HME_SEB_STAT_SENTFRAME |*/
|
|
|
|
HME_SEB_STAT_HOSTTOTX |
|
|
|
|
HME_SEB_STAT_RXTOHOST |
|
|
|
|
HME_SEB_STAT_TXALL |
|
|
|
|
HME_SEB_STAT_TXPERR |
|
|
|
|
HME_SEB_STAT_RCNTEXP |
|
2009-05-07 00:40:19 +04:00
|
|
|
HME_SEB_STAT_MIFIRQ |
|
2001-11-26 13:39:29 +03:00
|
|
|
HME_SEB_STAT_ALL_ERRORS ));
|
1999-06-27 16:26:32 +04:00
|
|
|
|
|
|
|
switch (sc->sc_burst) {
|
|
|
|
default:
|
|
|
|
v = 0;
|
|
|
|
break;
|
|
|
|
case 16:
|
|
|
|
v = HME_SEB_CFG_BURST16;
|
|
|
|
break;
|
|
|
|
case 32:
|
|
|
|
v = HME_SEB_CFG_BURST32;
|
|
|
|
break;
|
|
|
|
case 64:
|
|
|
|
v = HME_SEB_CFG_BURST64;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
bus_space_write_4(t, seb, HME_SEBI_CFG, v);
|
|
|
|
|
|
|
|
/* step 9. ETX Configuration: use mostly default values */
|
|
|
|
|
|
|
|
/* Enable DMA */
|
1999-12-15 02:58:15 +03:00
|
|
|
v = bus_space_read_4(t, etx, HME_ETXI_CFG);
|
1999-06-27 16:26:32 +04:00
|
|
|
v |= HME_ETX_CFG_DMAENABLE;
|
1999-12-15 02:58:15 +03:00
|
|
|
bus_space_write_4(t, etx, HME_ETXI_CFG, v);
|
1999-06-27 16:26:32 +04:00
|
|
|
|
1999-12-15 13:33:31 +03:00
|
|
|
/* Transmit Descriptor ring size: in increments of 16 */
|
2001-11-26 13:39:29 +03:00
|
|
|
bus_space_write_4(t, etx, HME_ETXI_RSIZE, _HME_NDESC / 16 - 1);
|
|
|
|
|
1999-06-27 16:26:32 +04:00
|
|
|
|
1999-12-15 13:33:31 +03:00
|
|
|
/* step 10. ERX Configuration */
|
1999-12-15 02:58:15 +03:00
|
|
|
v = bus_space_read_4(t, erx, HME_ERXI_CFG);
|
2001-11-26 13:39:29 +03:00
|
|
|
|
|
|
|
/* Encode Receive Descriptor ring size: four possible values */
|
|
|
|
switch (_HME_NDESC /*XXX*/) {
|
|
|
|
case 32:
|
|
|
|
v |= HME_ERX_CFG_RINGSIZE32;
|
|
|
|
break;
|
|
|
|
case 64:
|
|
|
|
v |= HME_ERX_CFG_RINGSIZE64;
|
|
|
|
break;
|
|
|
|
case 128:
|
|
|
|
v |= HME_ERX_CFG_RINGSIZE128;
|
|
|
|
break;
|
|
|
|
case 256:
|
|
|
|
v |= HME_ERX_CFG_RINGSIZE256;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printf("hme: invalid Receive Descriptor ring size\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
1999-12-15 13:33:31 +03:00
|
|
|
/* Enable DMA */
|
2001-11-26 13:39:29 +03:00
|
|
|
v |= HME_ERX_CFG_DMAENABLE;
|
2005-02-18 03:40:32 +03:00
|
|
|
|
|
|
|
/* set h/w rx checksum start offset (# of half-words) */
|
2005-03-05 21:36:23 +03:00
|
|
|
#ifdef INET
|
2009-03-29 11:33:52 +04:00
|
|
|
v |= (((ETHER_HDR_LEN + sizeof(struct ip)) / sizeof(uint16_t))
|
|
|
|
<< HME_ERX_CFG_CSUMSHIFT) &
|
2005-02-18 03:40:32 +03:00
|
|
|
HME_ERX_CFG_CSUMSTART;
|
2005-03-05 21:36:23 +03:00
|
|
|
#endif
|
1999-12-15 02:58:15 +03:00
|
|
|
bus_space_write_4(t, erx, HME_ERXI_CFG, v);
|
1999-06-27 16:26:32 +04:00
|
|
|
|
|
|
|
/* step 11. XIF Configuration */
|
|
|
|
v = bus_space_read_4(t, mac, HME_MACI_XIF);
|
|
|
|
v |= HME_MAC_XIF_OE;
|
|
|
|
bus_space_write_4(t, mac, HME_MACI_XIF, v);
|
|
|
|
|
|
|
|
/* step 12. RX_MAC Configuration Register */
|
|
|
|
v = bus_space_read_4(t, mac, HME_MACI_RXCFG);
|
2005-02-18 03:40:32 +03:00
|
|
|
v |= HME_MAC_RXCFG_ENABLE | HME_MAC_RXCFG_PSTRIP;
|
1999-06-27 16:26:32 +04:00
|
|
|
bus_space_write_4(t, mac, HME_MACI_RXCFG, v);
|
|
|
|
|
|
|
|
/* step 13. TX_MAC Configuration Register */
|
|
|
|
v = bus_space_read_4(t, mac, HME_MACI_TXCFG);
|
1999-12-15 02:58:15 +03:00
|
|
|
v |= (HME_MAC_TXCFG_ENABLE | HME_MAC_TXCFG_DGIVEUP);
|
1999-06-27 16:26:32 +04:00
|
|
|
bus_space_write_4(t, mac, HME_MACI_TXCFG, v);
|
|
|
|
|
|
|
|
/* step 14. Issue Transmit Pending command */
|
|
|
|
|
|
|
|
/* Call MI initialization function if any */
|
|
|
|
if (sc->sc_hwinit)
|
|
|
|
(*sc->sc_hwinit)(sc);
|
|
|
|
|
2002-05-05 07:02:38 +04:00
|
|
|
/* Set the current media. */
|
Make many ethernet drivers share the common code for MII media
handling, ether_mediastatus() and ether_mediachange(). Check for
a non-ENXIO error return from mii_mediachg(). (ENXIO indicates
that a PHY is suspended.)
This patch shrinks the source code size by 979 lines. There was
a 5100-byte savings on the NetBSD/i386 kernel configuration, ALL.
I have made a few miscellaneous changes, too:
gem(4): use LIST_EMPTY(), LIST_FOREACH().
mtd(4): handle media ioctls, for a change!
axe(4): do not track link status in sc->axe_link any longer
nfe(4), aue(4), axe(4), udav(4), url(4): do not reset all PHYs
on a change of media
Except for the change to mtd(4), no functional changes are intended.
XXX This patch affects more architectures than I can feasibly
XXX compile and run. I have compiled macppc, sparc64, i386. I
XXX have run the patches on i386 boxen with bnx(4) and sip(4).
XXX Compiling and running on evbmips (MERAKI, ADM5120) is in
XXX progress.
2008-01-20 01:10:14 +03:00
|
|
|
if ((rc = hme_mediachange(ifp)) != 0)
|
|
|
|
return rc;
|
2002-05-05 07:02:38 +04:00
|
|
|
|
2000-03-23 10:01:25 +03:00
|
|
|
/* Start the one second timer. */
|
|
|
|
callout_reset(&sc->sc_tick_ch, hz, hme_tick, sc);
|
|
|
|
|
1999-06-27 16:26:32 +04:00
|
|
|
ifp->if_flags |= IFF_RUNNING;
|
|
|
|
ifp->if_flags &= ~IFF_OACTIVE;
|
2004-06-29 00:50:52 +04:00
|
|
|
sc->sc_if_flags = ifp->if_flags;
|
1999-06-27 16:26:32 +04:00
|
|
|
ifp->if_timer = 0;
|
|
|
|
hme_start(ifp);
|
Make many ethernet drivers share the common code for MII media
handling, ether_mediastatus() and ether_mediachange(). Check for
a non-ENXIO error return from mii_mediachg(). (ENXIO indicates
that a PHY is suspended.)
This patch shrinks the source code size by 979 lines. There was
a 5100-byte savings on the NetBSD/i386 kernel configuration, ALL.
I have made a few miscellaneous changes, too:
gem(4): use LIST_EMPTY(), LIST_FOREACH().
mtd(4): handle media ioctls, for a change!
axe(4): do not track link status in sc->axe_link any longer
nfe(4), aue(4), axe(4), udav(4), url(4): do not reset all PHYs
on a change of media
Except for the change to mtd(4), no functional changes are intended.
XXX This patch affects more architectures than I can feasibly
XXX compile and run. I have compiled macppc, sparc64, i386. I
XXX have run the patches on i386 boxen with bnx(4) and sip(4).
XXX Compiling and running on evbmips (MERAKI, ADM5120) is in
XXX progress.
2008-01-20 01:10:14 +03:00
|
|
|
return 0;
|
1999-06-27 16:26:32 +04:00
|
|
|
}
|
|
|
|
|
2001-11-26 13:39:29 +03:00
|
|
|
/*
|
|
|
|
* Routine to copy from mbuf chain to transmit buffer in
|
|
|
|
* network buffer memory.
|
|
|
|
* Returns the amount of data copied.
|
|
|
|
*/
|
|
|
|
int
|
2009-03-15 00:04:01 +03:00
|
|
|
hme_put(struct hme_softc *sc, int ri, struct mbuf *m)
|
|
|
|
/* ri: Ring index */
|
2001-11-26 13:39:29 +03:00
|
|
|
{
|
|
|
|
struct mbuf *n;
|
|
|
|
int len, tlen = 0;
|
2007-03-04 08:59:00 +03:00
|
|
|
char *bp;
|
2001-11-26 13:39:29 +03:00
|
|
|
|
2007-03-04 08:59:00 +03:00
|
|
|
bp = (char *)sc->sc_rb.rb_txbuf + (ri % sc->sc_rb.rb_ntbuf) * _HME_BUFSZ;
|
2001-11-26 13:39:29 +03:00
|
|
|
for (; m; m = n) {
|
|
|
|
len = m->m_len;
|
|
|
|
if (len == 0) {
|
|
|
|
MFREE(m, n);
|
|
|
|
continue;
|
|
|
|
}
|
2007-03-04 08:59:00 +03:00
|
|
|
memcpy(bp, mtod(m, void *), len);
|
2001-11-26 13:39:29 +03:00
|
|
|
bp += len;
|
|
|
|
tlen += len;
|
|
|
|
MFREE(m, n);
|
|
|
|
}
|
|
|
|
return (tlen);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Pull data off an interface.
|
|
|
|
* Len is length of data, with local net header stripped.
|
|
|
|
* We copy the data into mbufs. When full cluster sized units are present
|
|
|
|
* we copy into clusters.
|
|
|
|
*/
|
|
|
|
struct mbuf *
|
2009-04-16 18:08:18 +04:00
|
|
|
hme_get(struct hme_softc *sc, int ri, uint32_t flags)
|
2001-11-26 13:39:29 +03:00
|
|
|
{
|
|
|
|
struct ifnet *ifp = &sc->sc_ethercom.ec_if;
|
|
|
|
struct mbuf *m, *m0, *newm;
|
2007-03-04 08:59:00 +03:00
|
|
|
char *bp;
|
2005-02-18 03:40:32 +03:00
|
|
|
int len, totlen;
|
2009-04-16 18:39:11 +04:00
|
|
|
#ifdef INET
|
|
|
|
int csum_flags;
|
|
|
|
#endif
|
2001-11-26 13:39:29 +03:00
|
|
|
|
2005-02-18 03:40:32 +03:00
|
|
|
totlen = HME_XD_DECODE_RSIZE(flags);
|
2001-11-26 13:39:29 +03:00
|
|
|
MGETHDR(m0, M_DONTWAIT, MT_DATA);
|
|
|
|
if (m0 == 0)
|
|
|
|
return (0);
|
|
|
|
m0->m_pkthdr.rcvif = ifp;
|
|
|
|
m0->m_pkthdr.len = totlen;
|
|
|
|
len = MHLEN;
|
|
|
|
m = m0;
|
|
|
|
|
2007-03-04 08:59:00 +03:00
|
|
|
bp = (char *)sc->sc_rb.rb_rxbuf + (ri % sc->sc_rb.rb_nrbuf) * _HME_BUFSZ;
|
2001-11-26 13:39:29 +03:00
|
|
|
|
|
|
|
while (totlen > 0) {
|
|
|
|
if (totlen >= MINCLSIZE) {
|
|
|
|
MCLGET(m, M_DONTWAIT);
|
|
|
|
if ((m->m_flags & M_EXT) == 0)
|
|
|
|
goto bad;
|
|
|
|
len = MCLBYTES;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m == m0) {
|
2007-03-04 08:59:00 +03:00
|
|
|
char *newdata = (char *)
|
2001-11-26 13:39:29 +03:00
|
|
|
ALIGN(m->m_data + sizeof(struct ether_header)) -
|
|
|
|
sizeof(struct ether_header);
|
|
|
|
len -= newdata - m->m_data;
|
|
|
|
m->m_data = newdata;
|
|
|
|
}
|
|
|
|
|
|
|
|
m->m_len = len = min(totlen, len);
|
2007-03-04 08:59:00 +03:00
|
|
|
memcpy(mtod(m, void *), bp, len);
|
2001-11-26 13:39:29 +03:00
|
|
|
bp += len;
|
|
|
|
|
|
|
|
totlen -= len;
|
|
|
|
if (totlen > 0) {
|
|
|
|
MGET(newm, M_DONTWAIT, MT_DATA);
|
|
|
|
if (newm == 0)
|
|
|
|
goto bad;
|
|
|
|
len = MLEN;
|
|
|
|
m = m->m_next = newm;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-03-05 21:36:23 +03:00
|
|
|
#ifdef INET
|
|
|
|
/* hardware checksum */
|
2009-04-16 18:39:11 +04:00
|
|
|
csum_flags = 0;
|
2005-03-17 18:51:28 +03:00
|
|
|
if (ifp->if_csum_flags_rx & (M_CSUM_TCPv4 | M_CSUM_UDPv4)) {
|
2005-02-18 03:40:32 +03:00
|
|
|
struct ether_header *eh;
|
2009-03-29 11:33:52 +04:00
|
|
|
struct ether_vlan_header *evh;
|
2005-02-18 03:40:32 +03:00
|
|
|
struct ip *ip;
|
|
|
|
struct udphdr *uh;
|
|
|
|
uint16_t *opts;
|
|
|
|
int32_t hlen, pktlen;
|
2009-04-16 18:39:11 +04:00
|
|
|
uint32_t csum_data;
|
2005-02-18 03:40:32 +03:00
|
|
|
|
2009-03-29 11:33:52 +04:00
|
|
|
eh = mtod(m0, struct ether_header *);
|
|
|
|
if (ntohs(eh->ether_type) == ETHERTYPE_IP) {
|
|
|
|
ip = (struct ip *)((char *)eh + ETHER_HDR_LEN);
|
2005-02-18 03:40:32 +03:00
|
|
|
pktlen = m0->m_pkthdr.len - ETHER_HDR_LEN;
|
2009-03-29 11:33:52 +04:00
|
|
|
} else if (ntohs(eh->ether_type) == ETHERTYPE_VLAN) {
|
|
|
|
evh = (struct ether_vlan_header *)eh;
|
|
|
|
if (ntohs(evh->evl_proto != ETHERTYPE_IP))
|
|
|
|
goto swcsum;
|
|
|
|
ip = (struct ip *)((char *)eh + ETHER_HDR_LEN +
|
|
|
|
ETHER_VLAN_ENCAP_LEN);
|
|
|
|
pktlen = m0->m_pkthdr.len -
|
|
|
|
ETHER_HDR_LEN - ETHER_VLAN_ENCAP_LEN;
|
|
|
|
} else
|
2005-02-18 03:40:32 +03:00
|
|
|
goto swcsum;
|
|
|
|
|
|
|
|
/* IPv4 only */
|
|
|
|
if (ip->ip_v != IPVERSION)
|
|
|
|
goto swcsum;
|
|
|
|
|
|
|
|
hlen = ip->ip_hl << 2;
|
2005-02-27 03:26:58 +03:00
|
|
|
if (hlen < sizeof(struct ip))
|
2005-02-18 03:40:32 +03:00
|
|
|
goto swcsum;
|
|
|
|
|
2005-03-05 21:36:23 +03:00
|
|
|
/*
|
|
|
|
* bail if too short, has random trailing garbage, truncated,
|
|
|
|
* fragment, or has ethernet pad.
|
|
|
|
*/
|
2009-04-16 18:39:11 +04:00
|
|
|
if (ntohs(ip->ip_len) < hlen ||
|
|
|
|
ntohs(ip->ip_len) != pktlen ||
|
|
|
|
(ntohs(ip->ip_off) & (IP_MF | IP_OFFMASK)) != 0)
|
2005-03-05 21:36:23 +03:00
|
|
|
goto swcsum;
|
2005-02-18 03:40:32 +03:00
|
|
|
|
|
|
|
switch (ip->ip_p) {
|
|
|
|
case IPPROTO_TCP:
|
2009-04-16 18:39:11 +04:00
|
|
|
if ((ifp->if_csum_flags_rx & M_CSUM_TCPv4) == 0)
|
2005-02-18 03:40:32 +03:00
|
|
|
goto swcsum;
|
|
|
|
if (pktlen < (hlen + sizeof(struct tcphdr)))
|
|
|
|
goto swcsum;
|
2009-04-16 18:39:11 +04:00
|
|
|
csum_flags =
|
|
|
|
M_CSUM_TCPv4 | M_CSUM_DATA | M_CSUM_NO_PSEUDOHDR;
|
2005-02-18 03:40:32 +03:00
|
|
|
break;
|
|
|
|
case IPPROTO_UDP:
|
2009-04-16 18:39:11 +04:00
|
|
|
if ((ifp->if_csum_flags_rx & M_CSUM_UDPv4) == 0)
|
2005-02-18 03:40:32 +03:00
|
|
|
goto swcsum;
|
|
|
|
if (pktlen < (hlen + sizeof(struct udphdr)))
|
|
|
|
goto swcsum;
|
2007-03-04 08:59:00 +03:00
|
|
|
uh = (struct udphdr *)((char *)ip + hlen);
|
2005-02-18 03:40:32 +03:00
|
|
|
/* no checksum */
|
|
|
|
if (uh->uh_sum == 0)
|
|
|
|
goto swcsum;
|
2009-04-16 18:39:11 +04:00
|
|
|
csum_flags =
|
|
|
|
M_CSUM_UDPv4 | M_CSUM_DATA | M_CSUM_NO_PSEUDOHDR;
|
2005-02-18 03:40:32 +03:00
|
|
|
break;
|
|
|
|
default:
|
2005-03-05 21:36:23 +03:00
|
|
|
goto swcsum;
|
2005-02-18 03:40:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* w/ M_CSUM_NO_PSEUDOHDR, the uncomplemented sum is expected */
|
2009-04-16 18:39:11 +04:00
|
|
|
csum_data = ~flags & HME_XD_RXCKSUM;
|
2005-02-18 03:40:32 +03:00
|
|
|
|
2009-03-29 11:33:52 +04:00
|
|
|
/*
|
|
|
|
* If data offset is different from RX cksum start offset,
|
|
|
|
* we have to deduct them.
|
|
|
|
*/
|
2009-04-16 18:39:11 +04:00
|
|
|
hlen = ((char *)ip + hlen) -
|
2009-03-29 11:33:52 +04:00
|
|
|
((char *)eh + ETHER_HDR_LEN + sizeof(struct ip));
|
2009-04-16 18:39:11 +04:00
|
|
|
if (hlen > 1) {
|
2005-02-18 03:40:32 +03:00
|
|
|
uint32_t optsum;
|
|
|
|
|
|
|
|
optsum = 0;
|
2009-03-29 11:33:52 +04:00
|
|
|
opts = (uint16_t *)((char *)eh +
|
|
|
|
ETHER_HDR_LEN + sizeof(struct ip));
|
2005-02-18 03:40:32 +03:00
|
|
|
|
2009-04-16 18:39:11 +04:00
|
|
|
while (hlen > 1) {
|
2005-02-18 03:40:32 +03:00
|
|
|
optsum += ntohs(*opts++);
|
2009-04-16 18:39:11 +04:00
|
|
|
hlen -= 2;
|
2005-02-18 03:40:32 +03:00
|
|
|
}
|
|
|
|
while (optsum >> 16)
|
|
|
|
optsum = (optsum >> 16) + (optsum & 0xffff);
|
|
|
|
|
2009-03-16 15:02:00 +03:00
|
|
|
/* Deduct the ip opts sum from the hwsum. */
|
2009-04-16 18:39:11 +04:00
|
|
|
csum_data += (uint16_t)~optsum;
|
2005-02-18 03:40:32 +03:00
|
|
|
|
2009-04-16 18:39:11 +04:00
|
|
|
while (csum_data >> 16)
|
|
|
|
csum_data =
|
|
|
|
(csum_data >> 16) + (csum_data & 0xffff);
|
2005-02-18 03:40:32 +03:00
|
|
|
}
|
2009-04-16 18:39:11 +04:00
|
|
|
m0->m_pkthdr.csum_data = csum_data;
|
|
|
|
}
|
2005-02-27 03:26:58 +03:00
|
|
|
swcsum:
|
2009-04-16 18:39:11 +04:00
|
|
|
m0->m_pkthdr.csum_flags = csum_flags;
|
2005-03-05 21:36:23 +03:00
|
|
|
#endif
|
|
|
|
|
2001-11-26 13:39:29 +03:00
|
|
|
return (m0);
|
|
|
|
|
|
|
|
bad:
|
|
|
|
m_freem(m0);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Pass a packet to the higher levels.
|
|
|
|
*/
|
|
|
|
void
|
2009-04-16 18:08:18 +04:00
|
|
|
hme_read(struct hme_softc *sc, int ix, uint32_t flags)
|
2001-11-26 13:39:29 +03:00
|
|
|
{
|
|
|
|
struct ifnet *ifp = &sc->sc_ethercom.ec_if;
|
|
|
|
struct mbuf *m;
|
2005-02-18 03:40:32 +03:00
|
|
|
int len;
|
2001-11-26 13:39:29 +03:00
|
|
|
|
2005-02-18 03:40:32 +03:00
|
|
|
len = HME_XD_DECODE_RSIZE(flags);
|
2001-11-26 13:39:29 +03:00
|
|
|
if (len <= sizeof(struct ether_header) ||
|
|
|
|
len > ((sc->sc_ethercom.ec_capenable & ETHERCAP_VLAN_MTU) ?
|
|
|
|
ETHER_VLAN_ENCAP_LEN + ETHERMTU + sizeof(struct ether_header) :
|
|
|
|
ETHERMTU + sizeof(struct ether_header))) {
|
|
|
|
#ifdef HMEDEBUG
|
|
|
|
printf("%s: invalid packet size %d; dropping\n",
|
2009-05-17 04:40:43 +04:00
|
|
|
device_xname(sc->sc_dev), len);
|
2001-11-26 13:39:29 +03:00
|
|
|
#endif
|
|
|
|
ifp->if_ierrors++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Pull packet off interface. */
|
2005-02-18 03:40:32 +03:00
|
|
|
m = hme_get(sc, ix, flags);
|
2001-11-26 13:39:29 +03:00
|
|
|
if (m == 0) {
|
|
|
|
ifp->if_ierrors++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ifp->if_ipackets++;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check if there's a BPF listener on this interface.
|
|
|
|
* If so, hand off the raw packet to BPF.
|
|
|
|
*/
|
2010-04-05 11:19:28 +04:00
|
|
|
bpf_mtap(ifp, m);
|
2001-11-26 13:39:29 +03:00
|
|
|
|
|
|
|
/* Pass the packet up. */
|
|
|
|
(*ifp->if_input)(ifp, m);
|
|
|
|
}
|
|
|
|
|
1999-06-27 16:26:32 +04:00
|
|
|
void
|
2009-03-14 18:35:58 +03:00
|
|
|
hme_start(struct ifnet *ifp)
|
1999-06-27 16:26:32 +04:00
|
|
|
{
|
2009-05-17 04:40:43 +04:00
|
|
|
struct hme_softc *sc = ifp->if_softc;
|
2007-03-04 08:59:00 +03:00
|
|
|
void *txd = sc->sc_rb.rb_txd;
|
1999-06-27 16:26:32 +04:00
|
|
|
struct mbuf *m;
|
2005-02-18 03:40:32 +03:00
|
|
|
unsigned int txflags;
|
2009-09-08 21:16:33 +04:00
|
|
|
unsigned int ri, len, obusy;
|
2001-11-26 13:39:29 +03:00
|
|
|
unsigned int ntbuf = sc->sc_rb.rb_ntbuf;
|
1999-06-27 16:26:32 +04:00
|
|
|
|
|
|
|
if ((ifp->if_flags & (IFF_RUNNING | IFF_OACTIVE)) != IFF_RUNNING)
|
|
|
|
return;
|
|
|
|
|
2001-11-26 13:39:29 +03:00
|
|
|
ri = sc->sc_rb.rb_tdhead;
|
2009-09-08 21:16:33 +04:00
|
|
|
obusy = sc->sc_rb.rb_td_nbusy;
|
2001-11-26 13:39:29 +03:00
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
IFQ_DEQUEUE(&ifp->if_snd, m);
|
|
|
|
if (m == 0)
|
1999-06-27 16:26:32 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If BPF is listening on this interface, let it see the
|
|
|
|
* packet before we commit it to the wire.
|
|
|
|
*/
|
2010-04-05 11:19:28 +04:00
|
|
|
bpf_mtap(ifp, m);
|
1999-06-27 16:26:32 +04:00
|
|
|
|
2005-03-05 21:36:23 +03:00
|
|
|
#ifdef INET
|
2005-02-18 03:40:32 +03:00
|
|
|
/* collect bits for h/w csum, before hme_put frees the mbuf */
|
|
|
|
if (ifp->if_csum_flags_tx & (M_CSUM_TCPv4 | M_CSUM_UDPv4) &&
|
|
|
|
m->m_pkthdr.csum_flags & (M_CSUM_TCPv4 | M_CSUM_UDPv4)) {
|
|
|
|
struct ether_header *eh;
|
|
|
|
uint16_t offset, start;
|
|
|
|
|
|
|
|
eh = mtod(m, struct ether_header *);
|
|
|
|
switch (ntohs(eh->ether_type)) {
|
|
|
|
case ETHERTYPE_IP:
|
|
|
|
start = ETHER_HDR_LEN;
|
|
|
|
break;
|
|
|
|
case ETHERTYPE_VLAN:
|
|
|
|
start = ETHER_HDR_LEN + ETHER_VLAN_ENCAP_LEN;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* unsupported, drop it */
|
|
|
|
m_free(m);
|
|
|
|
continue;
|
|
|
|
}
|
2005-02-21 05:12:48 +03:00
|
|
|
start += M_CSUM_DATA_IPv4_IPHL(m->m_pkthdr.csum_data);
|
|
|
|
offset = M_CSUM_DATA_IPv4_OFFSET(m->m_pkthdr.csum_data)
|
|
|
|
+ start;
|
2005-02-18 03:40:32 +03:00
|
|
|
txflags = HME_XD_TXCKSUM |
|
|
|
|
(offset << HME_XD_TXCSSTUFFSHIFT) |
|
|
|
|
(start << HME_XD_TXCSSTARTSHIFT);
|
|
|
|
} else
|
2005-03-05 21:36:23 +03:00
|
|
|
#endif
|
2005-02-18 03:40:32 +03:00
|
|
|
txflags = 0;
|
|
|
|
|
2001-11-26 13:39:29 +03:00
|
|
|
/*
|
|
|
|
* Copy the mbuf chain into the transmit buffer.
|
|
|
|
*/
|
|
|
|
len = hme_put(sc, ri, m);
|
2001-11-26 01:12:01 +03:00
|
|
|
|
2001-11-26 13:39:29 +03:00
|
|
|
/*
|
|
|
|
* Initialize transmit registers and start transmission
|
|
|
|
*/
|
|
|
|
HME_XD_SETFLAGS(sc->sc_pci, txd, ri,
|
|
|
|
HME_XD_OWN | HME_XD_SOP | HME_XD_EOP |
|
2005-02-18 03:40:32 +03:00
|
|
|
HME_XD_ENCODE_TSIZE(len) | txflags);
|
2001-11-26 01:12:01 +03:00
|
|
|
|
2001-11-26 13:39:29 +03:00
|
|
|
/*if (sc->sc_rb.rb_td_nbusy <= 0)*/
|
2001-11-26 01:12:01 +03:00
|
|
|
bus_space_write_4(sc->sc_bustag, sc->sc_etx, HME_ETXI_PENDING,
|
2001-11-26 13:39:29 +03:00
|
|
|
HME_ETX_TP_DMAWAKEUP);
|
|
|
|
|
|
|
|
if (++ri == ntbuf)
|
|
|
|
ri = 0;
|
|
|
|
|
|
|
|
if (++sc->sc_rb.rb_td_nbusy == ntbuf) {
|
|
|
|
ifp->if_flags |= IFF_OACTIVE;
|
|
|
|
break;
|
|
|
|
}
|
1999-06-27 16:26:32 +04:00
|
|
|
}
|
|
|
|
|
2009-09-08 21:16:33 +04:00
|
|
|
if (obusy != sc->sc_rb.rb_td_nbusy) {
|
|
|
|
sc->sc_rb.rb_tdhead = ri;
|
|
|
|
ifp->if_timer = 5;
|
|
|
|
}
|
1999-06-27 16:26:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Transmit interrupt.
|
|
|
|
*/
|
|
|
|
int
|
2009-03-14 18:35:58 +03:00
|
|
|
hme_tint(struct hme_softc *sc)
|
1999-06-27 16:26:32 +04:00
|
|
|
{
|
|
|
|
struct ifnet *ifp = &sc->sc_ethercom.ec_if;
|
2001-11-26 13:39:29 +03:00
|
|
|
bus_space_tag_t t = sc->sc_bustag;
|
|
|
|
bus_space_handle_t mac = sc->sc_mac;
|
1999-06-27 16:26:32 +04:00
|
|
|
unsigned int ri, txflags;
|
2001-11-26 13:39:29 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Unload collision counters
|
|
|
|
*/
|
|
|
|
ifp->if_collisions +=
|
|
|
|
bus_space_read_4(t, mac, HME_MACI_NCCNT) +
|
2009-05-07 00:40:19 +04:00
|
|
|
bus_space_read_4(t, mac, HME_MACI_FCCNT);
|
|
|
|
ifp->if_oerrors +=
|
2001-11-26 13:39:29 +03:00
|
|
|
bus_space_read_4(t, mac, HME_MACI_EXCNT) +
|
|
|
|
bus_space_read_4(t, mac, HME_MACI_LTCNT);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* then clear the hardware counters.
|
|
|
|
*/
|
|
|
|
bus_space_write_4(t, mac, HME_MACI_NCCNT, 0);
|
|
|
|
bus_space_write_4(t, mac, HME_MACI_FCCNT, 0);
|
|
|
|
bus_space_write_4(t, mac, HME_MACI_EXCNT, 0);
|
|
|
|
bus_space_write_4(t, mac, HME_MACI_LTCNT, 0);
|
1999-06-27 16:26:32 +04:00
|
|
|
|
|
|
|
/* Fetch current position in the transmit ring */
|
2001-11-26 13:39:29 +03:00
|
|
|
ri = sc->sc_rb.rb_tdtail;
|
1999-06-27 16:26:32 +04:00
|
|
|
|
|
|
|
for (;;) {
|
2001-11-26 13:39:29 +03:00
|
|
|
if (sc->sc_rb.rb_td_nbusy <= 0)
|
1999-06-27 16:26:32 +04:00
|
|
|
break;
|
|
|
|
|
2000-06-25 05:05:16 +04:00
|
|
|
txflags = HME_XD_GETFLAGS(sc->sc_pci, sc->sc_rb.rb_txd, ri);
|
1999-06-27 16:26:32 +04:00
|
|
|
|
|
|
|
if (txflags & HME_XD_OWN)
|
|
|
|
break;
|
|
|
|
|
|
|
|
ifp->if_flags &= ~IFF_OACTIVE;
|
2001-11-26 13:39:29 +03:00
|
|
|
ifp->if_opackets++;
|
2001-11-26 01:12:01 +03:00
|
|
|
|
2001-11-26 13:39:29 +03:00
|
|
|
if (++ri == sc->sc_rb.rb_ntbuf)
|
1999-06-27 16:26:32 +04:00
|
|
|
ri = 0;
|
|
|
|
|
2001-11-26 13:39:29 +03:00
|
|
|
--sc->sc_rb.rb_td_nbusy;
|
1999-06-27 16:26:32 +04:00
|
|
|
}
|
|
|
|
|
1999-12-15 13:33:31 +03:00
|
|
|
/* Update ring */
|
2001-11-26 13:39:29 +03:00
|
|
|
sc->sc_rb.rb_tdtail = ri;
|
1999-06-27 16:26:32 +04:00
|
|
|
|
|
|
|
hme_start(ifp);
|
|
|
|
|
2001-11-26 13:39:29 +03:00
|
|
|
if (sc->sc_rb.rb_td_nbusy == 0)
|
1999-06-27 16:26:32 +04:00
|
|
|
ifp->if_timer = 0;
|
|
|
|
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Receive interrupt.
|
|
|
|
*/
|
|
|
|
int
|
2009-03-14 18:35:58 +03:00
|
|
|
hme_rint(struct hme_softc *sc)
|
1999-06-27 16:26:32 +04:00
|
|
|
{
|
2009-05-07 00:40:19 +04:00
|
|
|
struct ifnet *ifp = &sc->sc_ethercom.ec_if;
|
|
|
|
bus_space_tag_t t = sc->sc_bustag;
|
|
|
|
bus_space_handle_t mac = sc->sc_mac;
|
2007-03-04 08:59:00 +03:00
|
|
|
void *xdr = sc->sc_rb.rb_rxd;
|
2001-11-26 13:39:29 +03:00
|
|
|
unsigned int nrbuf = sc->sc_rb.rb_nrbuf;
|
2005-02-18 03:40:32 +03:00
|
|
|
unsigned int ri;
|
2009-04-16 18:08:18 +04:00
|
|
|
uint32_t flags;
|
1999-06-27 16:26:32 +04:00
|
|
|
|
2001-11-26 13:39:29 +03:00
|
|
|
ri = sc->sc_rb.rb_rdtail;
|
1999-06-27 16:26:32 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Process all buffers with valid data.
|
|
|
|
*/
|
|
|
|
for (;;) {
|
2001-11-26 13:39:29 +03:00
|
|
|
flags = HME_XD_GETFLAGS(sc->sc_pci, xdr, ri);
|
1999-06-27 16:26:32 +04:00
|
|
|
if (flags & HME_XD_OWN)
|
|
|
|
break;
|
|
|
|
|
1999-12-17 17:37:15 +03:00
|
|
|
if (flags & HME_XD_OFL) {
|
|
|
|
printf("%s: buffer overflow, ri=%d; flags=0x%x\n",
|
2009-05-17 04:40:43 +04:00
|
|
|
device_xname(sc->sc_dev), ri, flags);
|
2005-02-18 03:40:32 +03:00
|
|
|
} else
|
|
|
|
hme_read(sc, ri, flags);
|
1999-06-27 16:26:32 +04:00
|
|
|
|
2001-11-26 13:39:29 +03:00
|
|
|
/* This buffer can be used by the hardware again */
|
|
|
|
HME_XD_SETFLAGS(sc->sc_pci, xdr, ri,
|
|
|
|
HME_XD_OWN | HME_XD_ENCODE_RSIZE(_HME_BUFSZ));
|
2001-11-26 01:12:01 +03:00
|
|
|
|
2001-11-26 13:39:29 +03:00
|
|
|
if (++ri == nrbuf)
|
1999-06-27 16:26:32 +04:00
|
|
|
ri = 0;
|
|
|
|
}
|
|
|
|
|
2001-11-26 13:39:29 +03:00
|
|
|
sc->sc_rb.rb_rdtail = ri;
|
|
|
|
|
2009-05-07 00:40:19 +04:00
|
|
|
/* Read error counters ... */
|
|
|
|
ifp->if_ierrors +=
|
|
|
|
bus_space_read_4(t, mac, HME_MACI_STAT_LCNT) +
|
|
|
|
bus_space_read_4(t, mac, HME_MACI_STAT_ACNT) +
|
|
|
|
bus_space_read_4(t, mac, HME_MACI_STAT_CCNT) +
|
|
|
|
bus_space_read_4(t, mac, HME_MACI_STAT_CVCNT);
|
|
|
|
|
|
|
|
/* ... then clear the hardware counters. */
|
|
|
|
bus_space_write_4(t, mac, HME_MACI_STAT_LCNT, 0);
|
|
|
|
bus_space_write_4(t, mac, HME_MACI_STAT_ACNT, 0);
|
|
|
|
bus_space_write_4(t, mac, HME_MACI_STAT_CCNT, 0);
|
|
|
|
bus_space_write_4(t, mac, HME_MACI_STAT_CVCNT, 0);
|
1999-06-27 16:26:32 +04:00
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2009-03-14 18:35:58 +03:00
|
|
|
hme_eint(struct hme_softc *sc, u_int status)
|
1999-06-27 16:26:32 +04:00
|
|
|
{
|
2009-05-07 00:40:19 +04:00
|
|
|
struct ifnet *ifp = &sc->sc_ethercom.ec_if;
|
1999-06-27 16:26:32 +04:00
|
|
|
char bits[128];
|
|
|
|
|
|
|
|
if ((status & HME_SEB_STAT_MIFIRQ) != 0) {
|
2003-02-13 15:10:20 +03:00
|
|
|
bus_space_tag_t t = sc->sc_bustag;
|
|
|
|
bus_space_handle_t mif = sc->sc_mif;
|
2009-04-16 18:08:18 +04:00
|
|
|
uint32_t cf, st, sm;
|
2003-02-13 15:10:20 +03:00
|
|
|
cf = bus_space_read_4(t, mif, HME_MIFI_CFG);
|
|
|
|
st = bus_space_read_4(t, mif, HME_MIFI_STAT);
|
|
|
|
sm = bus_space_read_4(t, mif, HME_MIFI_SM);
|
|
|
|
printf("%s: XXXlink status changed: cfg=%x, stat %x, sm %x\n",
|
2009-05-17 04:40:43 +04:00
|
|
|
device_xname(sc->sc_dev), cf, st, sm);
|
1999-06-27 16:26:32 +04:00
|
|
|
return (1);
|
|
|
|
}
|
2009-05-07 00:40:19 +04:00
|
|
|
|
|
|
|
/* Receive error counters rolled over */
|
|
|
|
if (status & HME_SEB_STAT_ACNTEXP)
|
|
|
|
ifp->if_ierrors += 0xff;
|
|
|
|
if (status & HME_SEB_STAT_CCNTEXP)
|
|
|
|
ifp->if_ierrors += 0xff;
|
|
|
|
if (status & HME_SEB_STAT_LCNTEXP)
|
|
|
|
ifp->if_ierrors += 0xff;
|
|
|
|
if (status & HME_SEB_STAT_CVCNTEXP)
|
|
|
|
ifp->if_ierrors += 0xff;
|
|
|
|
|
|
|
|
/* RXTERR locks up the interface, so do a reset */
|
|
|
|
if (status & HME_SEB_STAT_RXTERR)
|
|
|
|
hme_reset(sc);
|
|
|
|
|
2008-12-17 01:35:21 +03:00
|
|
|
snprintb(bits, sizeof(bits), HME_SEB_STAT_BITS, status);
|
2009-05-17 04:40:43 +04:00
|
|
|
printf("%s: status=%s\n", device_xname(sc->sc_dev), bits);
|
2008-12-17 01:35:21 +03:00
|
|
|
|
1999-06-27 16:26:32 +04:00
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2009-03-14 18:35:58 +03:00
|
|
|
hme_intr(void *v)
|
1999-06-27 16:26:32 +04:00
|
|
|
{
|
2009-05-17 04:40:43 +04:00
|
|
|
struct hme_softc *sc = v;
|
1999-06-27 16:26:32 +04:00
|
|
|
bus_space_tag_t t = sc->sc_bustag;
|
|
|
|
bus_space_handle_t seb = sc->sc_seb;
|
2009-04-16 18:08:18 +04:00
|
|
|
uint32_t status;
|
1999-06-27 16:26:32 +04:00
|
|
|
int r = 0;
|
|
|
|
|
|
|
|
status = bus_space_read_4(t, seb, HME_SEBI_STAT);
|
|
|
|
|
|
|
|
if ((status & HME_SEB_STAT_ALL_ERRORS) != 0)
|
|
|
|
r |= hme_eint(sc, status);
|
|
|
|
|
|
|
|
if ((status & (HME_SEB_STAT_TXALL | HME_SEB_STAT_HOSTTOTX)) != 0)
|
|
|
|
r |= hme_tint(sc);
|
|
|
|
|
|
|
|
if ((status & HME_SEB_STAT_RXTOHOST) != 0)
|
|
|
|
r |= hme_rint(sc);
|
|
|
|
|
2004-01-21 03:47:37 +03:00
|
|
|
rnd_add_uint32(&sc->rnd_source, status);
|
|
|
|
|
1999-06-27 16:26:32 +04:00
|
|
|
return (r);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2009-03-14 18:35:58 +03:00
|
|
|
hme_watchdog(struct ifnet *ifp)
|
1999-06-27 16:26:32 +04:00
|
|
|
{
|
|
|
|
struct hme_softc *sc = ifp->if_softc;
|
|
|
|
|
2009-05-17 04:40:43 +04:00
|
|
|
log(LOG_ERR, "%s: device timeout\n", device_xname(sc->sc_dev));
|
1999-06-27 16:26:32 +04:00
|
|
|
++ifp->if_oerrors;
|
|
|
|
|
|
|
|
hme_reset(sc);
|
|
|
|
}
|
|
|
|
|
1999-12-17 17:37:15 +03:00
|
|
|
/*
|
|
|
|
* Initialize the MII Management Interface
|
|
|
|
*/
|
|
|
|
void
|
2009-03-14 18:35:58 +03:00
|
|
|
hme_mifinit(struct hme_softc *sc)
|
1999-12-17 17:37:15 +03:00
|
|
|
{
|
|
|
|
bus_space_tag_t t = sc->sc_bustag;
|
|
|
|
bus_space_handle_t mif = sc->sc_mif;
|
2003-02-27 17:58:22 +03:00
|
|
|
bus_space_handle_t mac = sc->sc_mac;
|
2003-02-13 15:10:20 +03:00
|
|
|
int instance, phy;
|
2009-04-16 18:08:18 +04:00
|
|
|
uint32_t v;
|
1999-12-17 17:37:15 +03:00
|
|
|
|
Make many ethernet drivers share the common code for MII media
handling, ether_mediastatus() and ether_mediachange(). Check for
a non-ENXIO error return from mii_mediachg(). (ENXIO indicates
that a PHY is suspended.)
This patch shrinks the source code size by 979 lines. There was
a 5100-byte savings on the NetBSD/i386 kernel configuration, ALL.
I have made a few miscellaneous changes, too:
gem(4): use LIST_EMPTY(), LIST_FOREACH().
mtd(4): handle media ioctls, for a change!
axe(4): do not track link status in sc->axe_link any longer
nfe(4), aue(4), axe(4), udav(4), url(4): do not reset all PHYs
on a change of media
Except for the change to mtd(4), no functional changes are intended.
XXX This patch affects more architectures than I can feasibly
XXX compile and run. I have compiled macppc, sparc64, i386. I
XXX have run the patches on i386 boxen with bnx(4) and sip(4).
XXX Compiling and running on evbmips (MERAKI, ADM5120) is in
XXX progress.
2008-01-20 01:10:14 +03:00
|
|
|
if (sc->sc_mii.mii_media.ifm_cur != NULL) {
|
|
|
|
instance = IFM_INST(sc->sc_mii.mii_media.ifm_cur->ifm_media);
|
2003-02-13 15:10:20 +03:00
|
|
|
phy = sc->sc_phys[instance];
|
|
|
|
} else
|
|
|
|
/* No media set yet, pick phy arbitrarily.. */
|
|
|
|
phy = HME_PHYAD_EXTERNAL;
|
2002-12-19 02:13:02 +03:00
|
|
|
|
2003-02-13 15:10:20 +03:00
|
|
|
/* Configure the MIF in frame mode, no poll, current phy select */
|
|
|
|
v = 0;
|
|
|
|
if (phy == HME_PHYAD_EXTERNAL)
|
|
|
|
v |= HME_MIF_CFG_PHY;
|
|
|
|
bus_space_write_4(t, mif, HME_MIFI_CFG, v);
|
2003-02-27 17:58:22 +03:00
|
|
|
|
|
|
|
/* If an external transceiver is selected, enable its MII drivers */
|
|
|
|
v = bus_space_read_4(t, mac, HME_MACI_XIF);
|
|
|
|
v &= ~HME_MAC_XIF_MIIENABLE;
|
|
|
|
if (phy == HME_PHYAD_EXTERNAL)
|
|
|
|
v |= HME_MAC_XIF_MIIENABLE;
|
|
|
|
bus_space_write_4(t, mac, HME_MACI_XIF, v);
|
1999-12-17 17:37:15 +03:00
|
|
|
}
|
|
|
|
|
1999-06-27 16:26:32 +04:00
|
|
|
/*
|
|
|
|
* MII interface
|
|
|
|
*/
|
|
|
|
static int
|
2009-05-12 18:16:35 +04:00
|
|
|
hme_mii_readreg(device_t self, int phy, int reg)
|
1999-06-27 16:26:32 +04:00
|
|
|
{
|
2009-05-17 04:40:43 +04:00
|
|
|
struct hme_softc *sc = device_private(self);
|
1999-06-27 16:26:32 +04:00
|
|
|
bus_space_tag_t t = sc->sc_bustag;
|
|
|
|
bus_space_handle_t mif = sc->sc_mif;
|
2003-02-27 17:58:22 +03:00
|
|
|
bus_space_handle_t mac = sc->sc_mac;
|
2009-04-16 18:08:18 +04:00
|
|
|
uint32_t v, xif_cfg, mifi_cfg;
|
1999-06-27 16:26:32 +04:00
|
|
|
int n;
|
|
|
|
|
2003-02-13 15:10:20 +03:00
|
|
|
/* We can at most have two PHYs */
|
|
|
|
if (phy != HME_PHYAD_EXTERNAL && phy != HME_PHYAD_INTERNAL)
|
2002-12-19 02:13:02 +03:00
|
|
|
return (0);
|
|
|
|
|
1999-12-18 17:05:37 +03:00
|
|
|
/* Select the desired PHY in the MIF configuration register */
|
2003-02-13 15:10:20 +03:00
|
|
|
v = mifi_cfg = bus_space_read_4(t, mif, HME_MIFI_CFG);
|
1999-12-18 17:05:37 +03:00
|
|
|
v &= ~HME_MIF_CFG_PHY;
|
|
|
|
if (phy == HME_PHYAD_EXTERNAL)
|
|
|
|
v |= HME_MIF_CFG_PHY;
|
|
|
|
bus_space_write_4(t, mif, HME_MIFI_CFG, v);
|
|
|
|
|
2004-10-27 02:52:44 +04:00
|
|
|
/* Enable MII drivers on external transceiver */
|
2003-02-27 17:58:22 +03:00
|
|
|
v = xif_cfg = bus_space_read_4(t, mac, HME_MACI_XIF);
|
|
|
|
if (phy == HME_PHYAD_EXTERNAL)
|
|
|
|
v |= HME_MAC_XIF_MIIENABLE;
|
|
|
|
else
|
|
|
|
v &= ~HME_MAC_XIF_MIIENABLE;
|
|
|
|
bus_space_write_4(t, mac, HME_MACI_XIF, v);
|
|
|
|
|
2003-02-13 15:10:20 +03:00
|
|
|
#if 0
|
|
|
|
/* This doesn't work reliably; the MDIO_1 bit is off most of the time */
|
|
|
|
/*
|
|
|
|
* Check whether a transceiver is connected by testing
|
|
|
|
* the MIF configuration register's MDI_X bits. Note that
|
|
|
|
* MDI_0 (int) == 0x100 and MDI_1 (ext) == 0x200; see hmereg.h
|
|
|
|
*/
|
|
|
|
mif_mdi_bit = 1 << (8 + (1 - phy));
|
|
|
|
delay(100);
|
|
|
|
v = bus_space_read_4(t, mif, HME_MIFI_CFG);
|
|
|
|
if ((v & mif_mdi_bit) == 0)
|
|
|
|
return (0);
|
|
|
|
#endif
|
|
|
|
|
1999-06-27 16:26:32 +04:00
|
|
|
/* Construct the frame command */
|
|
|
|
v = (MII_COMMAND_START << HME_MIF_FO_ST_SHIFT) |
|
|
|
|
HME_MIF_FO_TAMSB |
|
|
|
|
(MII_COMMAND_READ << HME_MIF_FO_OPC_SHIFT) |
|
|
|
|
(phy << HME_MIF_FO_PHYAD_SHIFT) |
|
|
|
|
(reg << HME_MIF_FO_REGAD_SHIFT);
|
|
|
|
|
|
|
|
bus_space_write_4(t, mif, HME_MIFI_FO, v);
|
|
|
|
for (n = 0; n < 100; n++) {
|
1999-12-15 02:58:15 +03:00
|
|
|
DELAY(1);
|
1999-06-27 16:26:32 +04:00
|
|
|
v = bus_space_read_4(t, mif, HME_MIFI_FO);
|
2003-02-13 15:10:20 +03:00
|
|
|
if (v & HME_MIF_FO_TALSB) {
|
|
|
|
v &= HME_MIF_FO_DATA;
|
|
|
|
goto out;
|
|
|
|
}
|
1999-06-27 16:26:32 +04:00
|
|
|
}
|
|
|
|
|
2003-02-13 15:10:20 +03:00
|
|
|
v = 0;
|
2009-05-17 04:40:43 +04:00
|
|
|
printf("%s: mii_read timeout\n", device_xname(sc->sc_dev));
|
2003-02-13 15:10:20 +03:00
|
|
|
|
|
|
|
out:
|
|
|
|
/* Restore MIFI_CFG register */
|
|
|
|
bus_space_write_4(t, mif, HME_MIFI_CFG, mifi_cfg);
|
2003-02-27 17:58:22 +03:00
|
|
|
/* Restore XIF register */
|
|
|
|
bus_space_write_4(t, mac, HME_MACI_XIF, xif_cfg);
|
2003-02-13 15:10:20 +03:00
|
|
|
return (v);
|
1999-06-27 16:26:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-05-12 18:16:35 +04:00
|
|
|
hme_mii_writereg(device_t self, int phy, int reg, int val)
|
1999-06-27 16:26:32 +04:00
|
|
|
{
|
2009-05-17 04:40:43 +04:00
|
|
|
struct hme_softc *sc = device_private(self);
|
1999-06-27 16:26:32 +04:00
|
|
|
bus_space_tag_t t = sc->sc_bustag;
|
|
|
|
bus_space_handle_t mif = sc->sc_mif;
|
2003-02-27 17:58:22 +03:00
|
|
|
bus_space_handle_t mac = sc->sc_mac;
|
2009-04-16 18:08:18 +04:00
|
|
|
uint32_t v, xif_cfg, mifi_cfg;
|
1999-06-27 16:26:32 +04:00
|
|
|
int n;
|
|
|
|
|
2003-02-13 15:10:20 +03:00
|
|
|
/* We can at most have two PHYs */
|
|
|
|
if (phy != HME_PHYAD_EXTERNAL && phy != HME_PHYAD_INTERNAL)
|
2002-12-19 02:13:02 +03:00
|
|
|
return;
|
|
|
|
|
1999-12-18 17:05:37 +03:00
|
|
|
/* Select the desired PHY in the MIF configuration register */
|
2003-02-13 15:10:20 +03:00
|
|
|
v = mifi_cfg = bus_space_read_4(t, mif, HME_MIFI_CFG);
|
1999-12-18 17:05:37 +03:00
|
|
|
v &= ~HME_MIF_CFG_PHY;
|
|
|
|
if (phy == HME_PHYAD_EXTERNAL)
|
|
|
|
v |= HME_MIF_CFG_PHY;
|
|
|
|
bus_space_write_4(t, mif, HME_MIFI_CFG, v);
|
|
|
|
|
2004-10-27 02:52:44 +04:00
|
|
|
/* Enable MII drivers on external transceiver */
|
2003-02-27 17:58:22 +03:00
|
|
|
v = xif_cfg = bus_space_read_4(t, mac, HME_MACI_XIF);
|
|
|
|
if (phy == HME_PHYAD_EXTERNAL)
|
|
|
|
v |= HME_MAC_XIF_MIIENABLE;
|
|
|
|
else
|
|
|
|
v &= ~HME_MAC_XIF_MIIENABLE;
|
|
|
|
bus_space_write_4(t, mac, HME_MACI_XIF, v);
|
|
|
|
|
2003-02-13 15:10:20 +03:00
|
|
|
#if 0
|
|
|
|
/* This doesn't work reliably; the MDIO_1 bit is off most of the time */
|
|
|
|
/*
|
|
|
|
* Check whether a transceiver is connected by testing
|
|
|
|
* the MIF configuration register's MDI_X bits. Note that
|
|
|
|
* MDI_0 (int) == 0x100 and MDI_1 (ext) == 0x200; see hmereg.h
|
|
|
|
*/
|
|
|
|
mif_mdi_bit = 1 << (8 + (1 - phy));
|
|
|
|
delay(100);
|
|
|
|
v = bus_space_read_4(t, mif, HME_MIFI_CFG);
|
|
|
|
if ((v & mif_mdi_bit) == 0)
|
|
|
|
return;
|
|
|
|
#endif
|
|
|
|
|
1999-06-27 16:26:32 +04:00
|
|
|
/* Construct the frame command */
|
|
|
|
v = (MII_COMMAND_START << HME_MIF_FO_ST_SHIFT) |
|
|
|
|
HME_MIF_FO_TAMSB |
|
|
|
|
(MII_COMMAND_WRITE << HME_MIF_FO_OPC_SHIFT) |
|
|
|
|
(phy << HME_MIF_FO_PHYAD_SHIFT) |
|
|
|
|
(reg << HME_MIF_FO_REGAD_SHIFT) |
|
|
|
|
(val & HME_MIF_FO_DATA);
|
|
|
|
|
|
|
|
bus_space_write_4(t, mif, HME_MIFI_FO, v);
|
|
|
|
for (n = 0; n < 100; n++) {
|
1999-12-15 02:58:15 +03:00
|
|
|
DELAY(1);
|
1999-06-27 16:26:32 +04:00
|
|
|
v = bus_space_read_4(t, mif, HME_MIFI_FO);
|
|
|
|
if (v & HME_MIF_FO_TALSB)
|
2003-02-13 15:10:20 +03:00
|
|
|
goto out;
|
1999-06-27 16:26:32 +04:00
|
|
|
}
|
|
|
|
|
2009-05-17 04:40:43 +04:00
|
|
|
printf("%s: mii_write timeout\n", device_xname(sc->sc_dev));
|
2003-02-13 15:10:20 +03:00
|
|
|
out:
|
|
|
|
/* Restore MIFI_CFG register */
|
|
|
|
bus_space_write_4(t, mif, HME_MIFI_CFG, mifi_cfg);
|
2003-02-27 17:58:22 +03:00
|
|
|
/* Restore XIF register */
|
|
|
|
bus_space_write_4(t, mac, HME_MACI_XIF, xif_cfg);
|
1999-06-27 16:26:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-07-22 18:32:49 +04:00
|
|
|
hme_mii_statchg(struct ifnet *ifp)
|
1999-06-27 16:26:32 +04:00
|
|
|
{
|
2012-07-22 18:32:49 +04:00
|
|
|
struct hme_softc *sc = ifp->if_softc;
|
1999-06-27 16:26:32 +04:00
|
|
|
bus_space_tag_t t = sc->sc_bustag;
|
|
|
|
bus_space_handle_t mac = sc->sc_mac;
|
2009-04-16 18:08:18 +04:00
|
|
|
uint32_t v;
|
1999-06-27 16:26:32 +04:00
|
|
|
|
1999-12-18 17:05:37 +03:00
|
|
|
#ifdef HMEDEBUG
|
|
|
|
if (sc->sc_debug)
|
2003-02-13 15:10:20 +03:00
|
|
|
printf("hme_mii_statchg: status change\n");
|
1999-12-18 17:05:37 +03:00
|
|
|
#endif
|
1999-06-27 16:26:32 +04:00
|
|
|
|
1999-12-18 17:05:37 +03:00
|
|
|
/* Set the MAC Full Duplex bit appropriately */
|
2002-08-29 18:33:03 +04:00
|
|
|
/* Apparently the hme chip is SIMPLEX if working in full duplex mode,
|
|
|
|
but not otherwise. */
|
1999-06-27 16:26:32 +04:00
|
|
|
v = bus_space_read_4(t, mac, HME_MACI_TXCFG);
|
2002-08-29 18:33:03 +04:00
|
|
|
if ((IFM_OPTIONS(sc->sc_mii.mii_media_active) & IFM_FDX) != 0) {
|
1999-06-27 16:26:32 +04:00
|
|
|
v |= HME_MAC_TXCFG_FULLDPLX;
|
2002-08-29 18:33:03 +04:00
|
|
|
sc->sc_ethercom.ec_if.if_flags |= IFF_SIMPLEX;
|
|
|
|
} else {
|
1999-06-27 16:26:32 +04:00
|
|
|
v &= ~HME_MAC_TXCFG_FULLDPLX;
|
2002-08-29 18:33:03 +04:00
|
|
|
sc->sc_ethercom.ec_if.if_flags &= ~IFF_SIMPLEX;
|
|
|
|
}
|
2004-06-29 00:50:52 +04:00
|
|
|
sc->sc_if_flags = sc->sc_ethercom.ec_if.if_flags;
|
1999-06-27 16:26:32 +04:00
|
|
|
bus_space_write_4(t, mac, HME_MACI_TXCFG, v);
|
1999-12-18 17:05:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2009-03-14 18:35:58 +03:00
|
|
|
hme_mediachange(struct ifnet *ifp)
|
1999-12-18 17:05:37 +03:00
|
|
|
{
|
|
|
|
struct hme_softc *sc = ifp->if_softc;
|
2003-02-13 15:10:20 +03:00
|
|
|
bus_space_tag_t t = sc->sc_bustag;
|
|
|
|
bus_space_handle_t mif = sc->sc_mif;
|
|
|
|
bus_space_handle_t mac = sc->sc_mac;
|
|
|
|
int instance = IFM_INST(sc->sc_mii.mii_media.ifm_cur->ifm_media);
|
|
|
|
int phy = sc->sc_phys[instance];
|
Make many ethernet drivers share the common code for MII media
handling, ether_mediastatus() and ether_mediachange(). Check for
a non-ENXIO error return from mii_mediachg(). (ENXIO indicates
that a PHY is suspended.)
This patch shrinks the source code size by 979 lines. There was
a 5100-byte savings on the NetBSD/i386 kernel configuration, ALL.
I have made a few miscellaneous changes, too:
gem(4): use LIST_EMPTY(), LIST_FOREACH().
mtd(4): handle media ioctls, for a change!
axe(4): do not track link status in sc->axe_link any longer
nfe(4), aue(4), axe(4), udav(4), url(4): do not reset all PHYs
on a change of media
Except for the change to mtd(4), no functional changes are intended.
XXX This patch affects more architectures than I can feasibly
XXX compile and run. I have compiled macppc, sparc64, i386. I
XXX have run the patches on i386 boxen with bnx(4) and sip(4).
XXX Compiling and running on evbmips (MERAKI, ADM5120) is in
XXX progress.
2008-01-20 01:10:14 +03:00
|
|
|
int rc;
|
2009-04-16 18:08:18 +04:00
|
|
|
uint32_t v;
|
1999-12-18 17:05:37 +03:00
|
|
|
|
2003-02-13 15:10:20 +03:00
|
|
|
#ifdef HMEDEBUG
|
|
|
|
if (sc->sc_debug)
|
|
|
|
printf("hme_mediachange: phy = %d\n", phy);
|
|
|
|
#endif
|
1999-12-18 17:05:37 +03:00
|
|
|
|
2003-02-13 15:10:20 +03:00
|
|
|
/* Select the current PHY in the MIF configuration register */
|
|
|
|
v = bus_space_read_4(t, mif, HME_MIFI_CFG);
|
|
|
|
v &= ~HME_MIF_CFG_PHY;
|
|
|
|
if (phy == HME_PHYAD_EXTERNAL)
|
|
|
|
v |= HME_MIF_CFG_PHY;
|
|
|
|
bus_space_write_4(t, mif, HME_MIFI_CFG, v);
|
|
|
|
|
|
|
|
/* If an external transceiver is selected, enable its MII drivers */
|
|
|
|
v = bus_space_read_4(t, mac, HME_MACI_XIF);
|
|
|
|
v &= ~HME_MAC_XIF_MIIENABLE;
|
|
|
|
if (phy == HME_PHYAD_EXTERNAL)
|
|
|
|
v |= HME_MAC_XIF_MIIENABLE;
|
|
|
|
bus_space_write_4(t, mac, HME_MACI_XIF, v);
|
|
|
|
|
Make many ethernet drivers share the common code for MII media
handling, ether_mediastatus() and ether_mediachange(). Check for
a non-ENXIO error return from mii_mediachg(). (ENXIO indicates
that a PHY is suspended.)
This patch shrinks the source code size by 979 lines. There was
a 5100-byte savings on the NetBSD/i386 kernel configuration, ALL.
I have made a few miscellaneous changes, too:
gem(4): use LIST_EMPTY(), LIST_FOREACH().
mtd(4): handle media ioctls, for a change!
axe(4): do not track link status in sc->axe_link any longer
nfe(4), aue(4), axe(4), udav(4), url(4): do not reset all PHYs
on a change of media
Except for the change to mtd(4), no functional changes are intended.
XXX This patch affects more architectures than I can feasibly
XXX compile and run. I have compiled macppc, sparc64, i386. I
XXX have run the patches on i386 boxen with bnx(4) and sip(4).
XXX Compiling and running on evbmips (MERAKI, ADM5120) is in
XXX progress.
2008-01-20 01:10:14 +03:00
|
|
|
if ((rc = mii_mediachg(&sc->sc_mii)) == ENXIO)
|
|
|
|
return 0;
|
|
|
|
return rc;
|
1999-06-27 16:26:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Process an ioctl request.
|
|
|
|
*/
|
|
|
|
int
|
*** Summary ***
When a link-layer address changes (e.g., ifconfig ex0 link
02:de:ad:be:ef:02 active), send a gratuitous ARP and/or a Neighbor
Advertisement to update the network-/link-layer address bindings
on our LAN peers.
Refuse a change of ethernet address to the address 00:00:00:00:00:00
or to any multicast/broadcast address. (Thanks matt@.)
Reorder ifnet ioctl operations so that driver ioctls may inherit
the functions of their "class"---ether_ioctl(), fddi_ioctl(), et
cetera---and the class ioctls may inherit from the generic ioctl,
ifioctl_common(), but both driver- and class-ioctls may override
the generic behavior. Make network drivers share more code.
Distinguish a "factory" link-layer address from others for the
purposes of both protecting that address from deletion and computing
EUI64.
Return consistent, appropriate error codes from network drivers.
Improve readability. KNF.
*** Details ***
In if_attach(), always initialize the interface ioctl routine,
ifnet->if_ioctl, if the driver has not already initialized it.
Delete if_ioctl == NULL tests everywhere else, because it cannot
happen.
In the ioctl routines of network interfaces, inherit common ioctl
behaviors by calling either ifioctl_common() or whichever ioctl
routine is appropriate for the class of interface---e.g., ether_ioctl()
for ethernets.
Stop (ab)using SIOCSIFADDR and start to use SIOCINITIFADDR. In
the user->kernel interface, SIOCSIFADDR's argument was an ifreq,
but on the protocol->ifnet interface, SIOCSIFADDR's argument was
an ifaddr. That was confusing, and it would work against me as I
make it possible for a network interface to overload most ioctls.
On the protocol->ifnet interface, replace SIOCSIFADDR with
SIOCINITIFADDR. In ifioctl(), return EPERM if userland tries to
invoke SIOCINITIFADDR.
In ifioctl(), give the interface the first shot at handling most
interface ioctls, and give the protocol the second shot, instead
of the other way around. Finally, let compatibility code (COMPAT_OSOCK)
take a shot.
Pull device initialization out of switch statements under
SIOCINITIFADDR. For example, pull ..._init() out of any switch
statement that looks like this:
switch (...->sa_family) {
case ...:
..._init();
...
break;
...
default:
..._init();
...
break;
}
Rewrite many if-else clauses that handle all permutations of IFF_UP
and IFF_RUNNING to use a switch statement,
switch (x & (IFF_UP|IFF_RUNNING)) {
case 0:
...
break;
case IFF_RUNNING:
...
break;
case IFF_UP:
...
break;
case IFF_UP|IFF_RUNNING:
...
break;
}
unifdef lots of code containing #ifdef FreeBSD, #ifdef NetBSD, and
#ifdef SIOCSIFMTU, especially in fwip(4) and in ndis(4).
In ipw(4), remove an if_set_sadl() call that is out of place.
In nfe(4), reuse the jumbo MTU logic in ether_ioctl().
Let ethernets register a callback for setting h/w state such as
promiscuous mode and the multicast filter in accord with a change
in the if_flags: ether_set_ifflags_cb() registers a callback that
returns ENETRESET if the caller should reset the ethernet by calling
if_init(), 0 on success, != 0 on failure. Pull common code from
ex(4), gem(4), nfe(4), sip(4), tlp(4), vge(4) into ether_ioctl(),
and register if_flags callbacks for those drivers.
Return ENOTTY instead of EINVAL for inappropriate ioctls. In
zyd(4), use ENXIO instead of ENOTTY to indicate that the device is
not any longer attached.
Add to if_set_sadl() a boolean 'factory' argument that indicates
whether a link-layer address was assigned by the factory or some
other source. In a comment, recommend using the factory address
for generating an EUI64, and update in6_get_hw_ifid() to prefer a
factory address to any other link-layer address.
Add a routing message, RTM_LLINFO_UPD, that tells protocols to
update the binding of network-layer addresses to link-layer addresses.
Implement this message in IPv4 and IPv6 by sending a gratuitous
ARP or a neighbor advertisement, respectively. Generate RTM_LLINFO_UPD
messages on a change of an interface's link-layer address.
In ether_ioctl(), do not let SIOCALIFADDR set a link-layer address
that is broadcast/multicast or equal to 00:00:00:00:00:00.
Make ether_ioctl() call ifioctl_common() to handle ioctls that it
does not understand.
In gif(4), initialize if_softc and use it, instead of assuming that
the gif_softc and ifp overlap.
Let ifioctl_common() handle SIOCGIFADDR.
Sprinkle rtcache_invariants(), which checks on DIAGNOSTIC kernels
that certain invariants on a struct route are satisfied.
In agr(4), rewrite agr_ioctl_filter() to be a bit more explicit
about the ioctls that we do not allow on an agr(4) member interface.
bzero -> memset. Delete unnecessary casts to void *. Use
sockaddr_in_init() and sockaddr_in6_init(). Compare pointers with
NULL instead of "testing truth". Replace some instances of (type
*)0 with NULL. Change some K&R prototypes to ANSI C, and join
lines.
2008-11-07 03:20:01 +03:00
|
|
|
hme_ioctl(struct ifnet *ifp, unsigned long cmd, void *data)
|
1999-06-27 16:26:32 +04:00
|
|
|
{
|
|
|
|
struct hme_softc *sc = ifp->if_softc;
|
|
|
|
struct ifaddr *ifa = (struct ifaddr *)data;
|
|
|
|
int s, error = 0;
|
|
|
|
|
|
|
|
s = splnet();
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
|
*** Summary ***
When a link-layer address changes (e.g., ifconfig ex0 link
02:de:ad:be:ef:02 active), send a gratuitous ARP and/or a Neighbor
Advertisement to update the network-/link-layer address bindings
on our LAN peers.
Refuse a change of ethernet address to the address 00:00:00:00:00:00
or to any multicast/broadcast address. (Thanks matt@.)
Reorder ifnet ioctl operations so that driver ioctls may inherit
the functions of their "class"---ether_ioctl(), fddi_ioctl(), et
cetera---and the class ioctls may inherit from the generic ioctl,
ifioctl_common(), but both driver- and class-ioctls may override
the generic behavior. Make network drivers share more code.
Distinguish a "factory" link-layer address from others for the
purposes of both protecting that address from deletion and computing
EUI64.
Return consistent, appropriate error codes from network drivers.
Improve readability. KNF.
*** Details ***
In if_attach(), always initialize the interface ioctl routine,
ifnet->if_ioctl, if the driver has not already initialized it.
Delete if_ioctl == NULL tests everywhere else, because it cannot
happen.
In the ioctl routines of network interfaces, inherit common ioctl
behaviors by calling either ifioctl_common() or whichever ioctl
routine is appropriate for the class of interface---e.g., ether_ioctl()
for ethernets.
Stop (ab)using SIOCSIFADDR and start to use SIOCINITIFADDR. In
the user->kernel interface, SIOCSIFADDR's argument was an ifreq,
but on the protocol->ifnet interface, SIOCSIFADDR's argument was
an ifaddr. That was confusing, and it would work against me as I
make it possible for a network interface to overload most ioctls.
On the protocol->ifnet interface, replace SIOCSIFADDR with
SIOCINITIFADDR. In ifioctl(), return EPERM if userland tries to
invoke SIOCINITIFADDR.
In ifioctl(), give the interface the first shot at handling most
interface ioctls, and give the protocol the second shot, instead
of the other way around. Finally, let compatibility code (COMPAT_OSOCK)
take a shot.
Pull device initialization out of switch statements under
SIOCINITIFADDR. For example, pull ..._init() out of any switch
statement that looks like this:
switch (...->sa_family) {
case ...:
..._init();
...
break;
...
default:
..._init();
...
break;
}
Rewrite many if-else clauses that handle all permutations of IFF_UP
and IFF_RUNNING to use a switch statement,
switch (x & (IFF_UP|IFF_RUNNING)) {
case 0:
...
break;
case IFF_RUNNING:
...
break;
case IFF_UP:
...
break;
case IFF_UP|IFF_RUNNING:
...
break;
}
unifdef lots of code containing #ifdef FreeBSD, #ifdef NetBSD, and
#ifdef SIOCSIFMTU, especially in fwip(4) and in ndis(4).
In ipw(4), remove an if_set_sadl() call that is out of place.
In nfe(4), reuse the jumbo MTU logic in ether_ioctl().
Let ethernets register a callback for setting h/w state such as
promiscuous mode and the multicast filter in accord with a change
in the if_flags: ether_set_ifflags_cb() registers a callback that
returns ENETRESET if the caller should reset the ethernet by calling
if_init(), 0 on success, != 0 on failure. Pull common code from
ex(4), gem(4), nfe(4), sip(4), tlp(4), vge(4) into ether_ioctl(),
and register if_flags callbacks for those drivers.
Return ENOTTY instead of EINVAL for inappropriate ioctls. In
zyd(4), use ENXIO instead of ENOTTY to indicate that the device is
not any longer attached.
Add to if_set_sadl() a boolean 'factory' argument that indicates
whether a link-layer address was assigned by the factory or some
other source. In a comment, recommend using the factory address
for generating an EUI64, and update in6_get_hw_ifid() to prefer a
factory address to any other link-layer address.
Add a routing message, RTM_LLINFO_UPD, that tells protocols to
update the binding of network-layer addresses to link-layer addresses.
Implement this message in IPv4 and IPv6 by sending a gratuitous
ARP or a neighbor advertisement, respectively. Generate RTM_LLINFO_UPD
messages on a change of an interface's link-layer address.
In ether_ioctl(), do not let SIOCALIFADDR set a link-layer address
that is broadcast/multicast or equal to 00:00:00:00:00:00.
Make ether_ioctl() call ifioctl_common() to handle ioctls that it
does not understand.
In gif(4), initialize if_softc and use it, instead of assuming that
the gif_softc and ifp overlap.
Let ifioctl_common() handle SIOCGIFADDR.
Sprinkle rtcache_invariants(), which checks on DIAGNOSTIC kernels
that certain invariants on a struct route are satisfied.
In agr(4), rewrite agr_ioctl_filter() to be a bit more explicit
about the ioctls that we do not allow on an agr(4) member interface.
bzero -> memset. Delete unnecessary casts to void *. Use
sockaddr_in_init() and sockaddr_in6_init(). Compare pointers with
NULL instead of "testing truth". Replace some instances of (type
*)0 with NULL. Change some K&R prototypes to ANSI C, and join
lines.
2008-11-07 03:20:01 +03:00
|
|
|
case SIOCINITIFADDR:
|
1999-06-27 16:26:32 +04:00
|
|
|
switch (ifa->ifa_addr->sa_family) {
|
|
|
|
#ifdef INET
|
|
|
|
case AF_INET:
|
2004-06-29 00:50:52 +04:00
|
|
|
if (ifp->if_flags & IFF_UP)
|
|
|
|
hme_setladrf(sc);
|
|
|
|
else {
|
|
|
|
ifp->if_flags |= IFF_UP;
|
2009-11-04 01:06:30 +03:00
|
|
|
error = hme_init(ifp);
|
2004-06-29 00:50:52 +04:00
|
|
|
}
|
1999-06-27 16:26:32 +04:00
|
|
|
arp_ifinit(ifp, ifa);
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
2004-06-29 00:50:52 +04:00
|
|
|
ifp->if_flags |= IFF_UP;
|
2009-11-04 01:06:30 +03:00
|
|
|
error = hme_init(ifp);
|
1999-06-27 16:26:32 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SIOCSIFFLAGS:
|
2005-02-18 03:22:11 +03:00
|
|
|
#ifdef HMEDEBUG
|
*** Summary ***
When a link-layer address changes (e.g., ifconfig ex0 link
02:de:ad:be:ef:02 active), send a gratuitous ARP and/or a Neighbor
Advertisement to update the network-/link-layer address bindings
on our LAN peers.
Refuse a change of ethernet address to the address 00:00:00:00:00:00
or to any multicast/broadcast address. (Thanks matt@.)
Reorder ifnet ioctl operations so that driver ioctls may inherit
the functions of their "class"---ether_ioctl(), fddi_ioctl(), et
cetera---and the class ioctls may inherit from the generic ioctl,
ifioctl_common(), but both driver- and class-ioctls may override
the generic behavior. Make network drivers share more code.
Distinguish a "factory" link-layer address from others for the
purposes of both protecting that address from deletion and computing
EUI64.
Return consistent, appropriate error codes from network drivers.
Improve readability. KNF.
*** Details ***
In if_attach(), always initialize the interface ioctl routine,
ifnet->if_ioctl, if the driver has not already initialized it.
Delete if_ioctl == NULL tests everywhere else, because it cannot
happen.
In the ioctl routines of network interfaces, inherit common ioctl
behaviors by calling either ifioctl_common() or whichever ioctl
routine is appropriate for the class of interface---e.g., ether_ioctl()
for ethernets.
Stop (ab)using SIOCSIFADDR and start to use SIOCINITIFADDR. In
the user->kernel interface, SIOCSIFADDR's argument was an ifreq,
but on the protocol->ifnet interface, SIOCSIFADDR's argument was
an ifaddr. That was confusing, and it would work against me as I
make it possible for a network interface to overload most ioctls.
On the protocol->ifnet interface, replace SIOCSIFADDR with
SIOCINITIFADDR. In ifioctl(), return EPERM if userland tries to
invoke SIOCINITIFADDR.
In ifioctl(), give the interface the first shot at handling most
interface ioctls, and give the protocol the second shot, instead
of the other way around. Finally, let compatibility code (COMPAT_OSOCK)
take a shot.
Pull device initialization out of switch statements under
SIOCINITIFADDR. For example, pull ..._init() out of any switch
statement that looks like this:
switch (...->sa_family) {
case ...:
..._init();
...
break;
...
default:
..._init();
...
break;
}
Rewrite many if-else clauses that handle all permutations of IFF_UP
and IFF_RUNNING to use a switch statement,
switch (x & (IFF_UP|IFF_RUNNING)) {
case 0:
...
break;
case IFF_RUNNING:
...
break;
case IFF_UP:
...
break;
case IFF_UP|IFF_RUNNING:
...
break;
}
unifdef lots of code containing #ifdef FreeBSD, #ifdef NetBSD, and
#ifdef SIOCSIFMTU, especially in fwip(4) and in ndis(4).
In ipw(4), remove an if_set_sadl() call that is out of place.
In nfe(4), reuse the jumbo MTU logic in ether_ioctl().
Let ethernets register a callback for setting h/w state such as
promiscuous mode and the multicast filter in accord with a change
in the if_flags: ether_set_ifflags_cb() registers a callback that
returns ENETRESET if the caller should reset the ethernet by calling
if_init(), 0 on success, != 0 on failure. Pull common code from
ex(4), gem(4), nfe(4), sip(4), tlp(4), vge(4) into ether_ioctl(),
and register if_flags callbacks for those drivers.
Return ENOTTY instead of EINVAL for inappropriate ioctls. In
zyd(4), use ENXIO instead of ENOTTY to indicate that the device is
not any longer attached.
Add to if_set_sadl() a boolean 'factory' argument that indicates
whether a link-layer address was assigned by the factory or some
other source. In a comment, recommend using the factory address
for generating an EUI64, and update in6_get_hw_ifid() to prefer a
factory address to any other link-layer address.
Add a routing message, RTM_LLINFO_UPD, that tells protocols to
update the binding of network-layer addresses to link-layer addresses.
Implement this message in IPv4 and IPv6 by sending a gratuitous
ARP or a neighbor advertisement, respectively. Generate RTM_LLINFO_UPD
messages on a change of an interface's link-layer address.
In ether_ioctl(), do not let SIOCALIFADDR set a link-layer address
that is broadcast/multicast or equal to 00:00:00:00:00:00.
Make ether_ioctl() call ifioctl_common() to handle ioctls that it
does not understand.
In gif(4), initialize if_softc and use it, instead of assuming that
the gif_softc and ifp overlap.
Let ifioctl_common() handle SIOCGIFADDR.
Sprinkle rtcache_invariants(), which checks on DIAGNOSTIC kernels
that certain invariants on a struct route are satisfied.
In agr(4), rewrite agr_ioctl_filter() to be a bit more explicit
about the ioctls that we do not allow on an agr(4) member interface.
bzero -> memset. Delete unnecessary casts to void *. Use
sockaddr_in_init() and sockaddr_in6_init(). Compare pointers with
NULL instead of "testing truth". Replace some instances of (type
*)0 with NULL. Change some K&R prototypes to ANSI C, and join
lines.
2008-11-07 03:20:01 +03:00
|
|
|
{
|
|
|
|
struct ifreq *ifr = data;
|
|
|
|
sc->sc_debug =
|
|
|
|
(ifr->ifr_flags & IFF_DEBUG) != 0 ? 1 : 0;
|
|
|
|
}
|
2005-02-18 03:22:11 +03:00
|
|
|
#endif
|
*** Summary ***
When a link-layer address changes (e.g., ifconfig ex0 link
02:de:ad:be:ef:02 active), send a gratuitous ARP and/or a Neighbor
Advertisement to update the network-/link-layer address bindings
on our LAN peers.
Refuse a change of ethernet address to the address 00:00:00:00:00:00
or to any multicast/broadcast address. (Thanks matt@.)
Reorder ifnet ioctl operations so that driver ioctls may inherit
the functions of their "class"---ether_ioctl(), fddi_ioctl(), et
cetera---and the class ioctls may inherit from the generic ioctl,
ifioctl_common(), but both driver- and class-ioctls may override
the generic behavior. Make network drivers share more code.
Distinguish a "factory" link-layer address from others for the
purposes of both protecting that address from deletion and computing
EUI64.
Return consistent, appropriate error codes from network drivers.
Improve readability. KNF.
*** Details ***
In if_attach(), always initialize the interface ioctl routine,
ifnet->if_ioctl, if the driver has not already initialized it.
Delete if_ioctl == NULL tests everywhere else, because it cannot
happen.
In the ioctl routines of network interfaces, inherit common ioctl
behaviors by calling either ifioctl_common() or whichever ioctl
routine is appropriate for the class of interface---e.g., ether_ioctl()
for ethernets.
Stop (ab)using SIOCSIFADDR and start to use SIOCINITIFADDR. In
the user->kernel interface, SIOCSIFADDR's argument was an ifreq,
but on the protocol->ifnet interface, SIOCSIFADDR's argument was
an ifaddr. That was confusing, and it would work against me as I
make it possible for a network interface to overload most ioctls.
On the protocol->ifnet interface, replace SIOCSIFADDR with
SIOCINITIFADDR. In ifioctl(), return EPERM if userland tries to
invoke SIOCINITIFADDR.
In ifioctl(), give the interface the first shot at handling most
interface ioctls, and give the protocol the second shot, instead
of the other way around. Finally, let compatibility code (COMPAT_OSOCK)
take a shot.
Pull device initialization out of switch statements under
SIOCINITIFADDR. For example, pull ..._init() out of any switch
statement that looks like this:
switch (...->sa_family) {
case ...:
..._init();
...
break;
...
default:
..._init();
...
break;
}
Rewrite many if-else clauses that handle all permutations of IFF_UP
and IFF_RUNNING to use a switch statement,
switch (x & (IFF_UP|IFF_RUNNING)) {
case 0:
...
break;
case IFF_RUNNING:
...
break;
case IFF_UP:
...
break;
case IFF_UP|IFF_RUNNING:
...
break;
}
unifdef lots of code containing #ifdef FreeBSD, #ifdef NetBSD, and
#ifdef SIOCSIFMTU, especially in fwip(4) and in ndis(4).
In ipw(4), remove an if_set_sadl() call that is out of place.
In nfe(4), reuse the jumbo MTU logic in ether_ioctl().
Let ethernets register a callback for setting h/w state such as
promiscuous mode and the multicast filter in accord with a change
in the if_flags: ether_set_ifflags_cb() registers a callback that
returns ENETRESET if the caller should reset the ethernet by calling
if_init(), 0 on success, != 0 on failure. Pull common code from
ex(4), gem(4), nfe(4), sip(4), tlp(4), vge(4) into ether_ioctl(),
and register if_flags callbacks for those drivers.
Return ENOTTY instead of EINVAL for inappropriate ioctls. In
zyd(4), use ENXIO instead of ENOTTY to indicate that the device is
not any longer attached.
Add to if_set_sadl() a boolean 'factory' argument that indicates
whether a link-layer address was assigned by the factory or some
other source. In a comment, recommend using the factory address
for generating an EUI64, and update in6_get_hw_ifid() to prefer a
factory address to any other link-layer address.
Add a routing message, RTM_LLINFO_UPD, that tells protocols to
update the binding of network-layer addresses to link-layer addresses.
Implement this message in IPv4 and IPv6 by sending a gratuitous
ARP or a neighbor advertisement, respectively. Generate RTM_LLINFO_UPD
messages on a change of an interface's link-layer address.
In ether_ioctl(), do not let SIOCALIFADDR set a link-layer address
that is broadcast/multicast or equal to 00:00:00:00:00:00.
Make ether_ioctl() call ifioctl_common() to handle ioctls that it
does not understand.
In gif(4), initialize if_softc and use it, instead of assuming that
the gif_softc and ifp overlap.
Let ifioctl_common() handle SIOCGIFADDR.
Sprinkle rtcache_invariants(), which checks on DIAGNOSTIC kernels
that certain invariants on a struct route are satisfied.
In agr(4), rewrite agr_ioctl_filter() to be a bit more explicit
about the ioctls that we do not allow on an agr(4) member interface.
bzero -> memset. Delete unnecessary casts to void *. Use
sockaddr_in_init() and sockaddr_in6_init(). Compare pointers with
NULL instead of "testing truth". Replace some instances of (type
*)0 with NULL. Change some K&R prototypes to ANSI C, and join
lines.
2008-11-07 03:20:01 +03:00
|
|
|
if ((error = ifioctl_common(ifp, cmd, data)) != 0)
|
|
|
|
break;
|
2005-02-18 03:22:11 +03:00
|
|
|
|
*** Summary ***
When a link-layer address changes (e.g., ifconfig ex0 link
02:de:ad:be:ef:02 active), send a gratuitous ARP and/or a Neighbor
Advertisement to update the network-/link-layer address bindings
on our LAN peers.
Refuse a change of ethernet address to the address 00:00:00:00:00:00
or to any multicast/broadcast address. (Thanks matt@.)
Reorder ifnet ioctl operations so that driver ioctls may inherit
the functions of their "class"---ether_ioctl(), fddi_ioctl(), et
cetera---and the class ioctls may inherit from the generic ioctl,
ifioctl_common(), but both driver- and class-ioctls may override
the generic behavior. Make network drivers share more code.
Distinguish a "factory" link-layer address from others for the
purposes of both protecting that address from deletion and computing
EUI64.
Return consistent, appropriate error codes from network drivers.
Improve readability. KNF.
*** Details ***
In if_attach(), always initialize the interface ioctl routine,
ifnet->if_ioctl, if the driver has not already initialized it.
Delete if_ioctl == NULL tests everywhere else, because it cannot
happen.
In the ioctl routines of network interfaces, inherit common ioctl
behaviors by calling either ifioctl_common() or whichever ioctl
routine is appropriate for the class of interface---e.g., ether_ioctl()
for ethernets.
Stop (ab)using SIOCSIFADDR and start to use SIOCINITIFADDR. In
the user->kernel interface, SIOCSIFADDR's argument was an ifreq,
but on the protocol->ifnet interface, SIOCSIFADDR's argument was
an ifaddr. That was confusing, and it would work against me as I
make it possible for a network interface to overload most ioctls.
On the protocol->ifnet interface, replace SIOCSIFADDR with
SIOCINITIFADDR. In ifioctl(), return EPERM if userland tries to
invoke SIOCINITIFADDR.
In ifioctl(), give the interface the first shot at handling most
interface ioctls, and give the protocol the second shot, instead
of the other way around. Finally, let compatibility code (COMPAT_OSOCK)
take a shot.
Pull device initialization out of switch statements under
SIOCINITIFADDR. For example, pull ..._init() out of any switch
statement that looks like this:
switch (...->sa_family) {
case ...:
..._init();
...
break;
...
default:
..._init();
...
break;
}
Rewrite many if-else clauses that handle all permutations of IFF_UP
and IFF_RUNNING to use a switch statement,
switch (x & (IFF_UP|IFF_RUNNING)) {
case 0:
...
break;
case IFF_RUNNING:
...
break;
case IFF_UP:
...
break;
case IFF_UP|IFF_RUNNING:
...
break;
}
unifdef lots of code containing #ifdef FreeBSD, #ifdef NetBSD, and
#ifdef SIOCSIFMTU, especially in fwip(4) and in ndis(4).
In ipw(4), remove an if_set_sadl() call that is out of place.
In nfe(4), reuse the jumbo MTU logic in ether_ioctl().
Let ethernets register a callback for setting h/w state such as
promiscuous mode and the multicast filter in accord with a change
in the if_flags: ether_set_ifflags_cb() registers a callback that
returns ENETRESET if the caller should reset the ethernet by calling
if_init(), 0 on success, != 0 on failure. Pull common code from
ex(4), gem(4), nfe(4), sip(4), tlp(4), vge(4) into ether_ioctl(),
and register if_flags callbacks for those drivers.
Return ENOTTY instead of EINVAL for inappropriate ioctls. In
zyd(4), use ENXIO instead of ENOTTY to indicate that the device is
not any longer attached.
Add to if_set_sadl() a boolean 'factory' argument that indicates
whether a link-layer address was assigned by the factory or some
other source. In a comment, recommend using the factory address
for generating an EUI64, and update in6_get_hw_ifid() to prefer a
factory address to any other link-layer address.
Add a routing message, RTM_LLINFO_UPD, that tells protocols to
update the binding of network-layer addresses to link-layer addresses.
Implement this message in IPv4 and IPv6 by sending a gratuitous
ARP or a neighbor advertisement, respectively. Generate RTM_LLINFO_UPD
messages on a change of an interface's link-layer address.
In ether_ioctl(), do not let SIOCALIFADDR set a link-layer address
that is broadcast/multicast or equal to 00:00:00:00:00:00.
Make ether_ioctl() call ifioctl_common() to handle ioctls that it
does not understand.
In gif(4), initialize if_softc and use it, instead of assuming that
the gif_softc and ifp overlap.
Let ifioctl_common() handle SIOCGIFADDR.
Sprinkle rtcache_invariants(), which checks on DIAGNOSTIC kernels
that certain invariants on a struct route are satisfied.
In agr(4), rewrite agr_ioctl_filter() to be a bit more explicit
about the ioctls that we do not allow on an agr(4) member interface.
bzero -> memset. Delete unnecessary casts to void *. Use
sockaddr_in_init() and sockaddr_in6_init(). Compare pointers with
NULL instead of "testing truth". Replace some instances of (type
*)0 with NULL. Change some K&R prototypes to ANSI C, and join
lines.
2008-11-07 03:20:01 +03:00
|
|
|
switch (ifp->if_flags & (IFF_UP|IFF_RUNNING)) {
|
|
|
|
case IFF_RUNNING:
|
1999-06-27 16:26:32 +04:00
|
|
|
/*
|
|
|
|
* If interface is marked down and it is running, then
|
|
|
|
* stop it.
|
|
|
|
*/
|
2009-09-08 21:16:33 +04:00
|
|
|
hme_stop(ifp, 0);
|
1999-06-27 16:26:32 +04:00
|
|
|
ifp->if_flags &= ~IFF_RUNNING;
|
*** Summary ***
When a link-layer address changes (e.g., ifconfig ex0 link
02:de:ad:be:ef:02 active), send a gratuitous ARP and/or a Neighbor
Advertisement to update the network-/link-layer address bindings
on our LAN peers.
Refuse a change of ethernet address to the address 00:00:00:00:00:00
or to any multicast/broadcast address. (Thanks matt@.)
Reorder ifnet ioctl operations so that driver ioctls may inherit
the functions of their "class"---ether_ioctl(), fddi_ioctl(), et
cetera---and the class ioctls may inherit from the generic ioctl,
ifioctl_common(), but both driver- and class-ioctls may override
the generic behavior. Make network drivers share more code.
Distinguish a "factory" link-layer address from others for the
purposes of both protecting that address from deletion and computing
EUI64.
Return consistent, appropriate error codes from network drivers.
Improve readability. KNF.
*** Details ***
In if_attach(), always initialize the interface ioctl routine,
ifnet->if_ioctl, if the driver has not already initialized it.
Delete if_ioctl == NULL tests everywhere else, because it cannot
happen.
In the ioctl routines of network interfaces, inherit common ioctl
behaviors by calling either ifioctl_common() or whichever ioctl
routine is appropriate for the class of interface---e.g., ether_ioctl()
for ethernets.
Stop (ab)using SIOCSIFADDR and start to use SIOCINITIFADDR. In
the user->kernel interface, SIOCSIFADDR's argument was an ifreq,
but on the protocol->ifnet interface, SIOCSIFADDR's argument was
an ifaddr. That was confusing, and it would work against me as I
make it possible for a network interface to overload most ioctls.
On the protocol->ifnet interface, replace SIOCSIFADDR with
SIOCINITIFADDR. In ifioctl(), return EPERM if userland tries to
invoke SIOCINITIFADDR.
In ifioctl(), give the interface the first shot at handling most
interface ioctls, and give the protocol the second shot, instead
of the other way around. Finally, let compatibility code (COMPAT_OSOCK)
take a shot.
Pull device initialization out of switch statements under
SIOCINITIFADDR. For example, pull ..._init() out of any switch
statement that looks like this:
switch (...->sa_family) {
case ...:
..._init();
...
break;
...
default:
..._init();
...
break;
}
Rewrite many if-else clauses that handle all permutations of IFF_UP
and IFF_RUNNING to use a switch statement,
switch (x & (IFF_UP|IFF_RUNNING)) {
case 0:
...
break;
case IFF_RUNNING:
...
break;
case IFF_UP:
...
break;
case IFF_UP|IFF_RUNNING:
...
break;
}
unifdef lots of code containing #ifdef FreeBSD, #ifdef NetBSD, and
#ifdef SIOCSIFMTU, especially in fwip(4) and in ndis(4).
In ipw(4), remove an if_set_sadl() call that is out of place.
In nfe(4), reuse the jumbo MTU logic in ether_ioctl().
Let ethernets register a callback for setting h/w state such as
promiscuous mode and the multicast filter in accord with a change
in the if_flags: ether_set_ifflags_cb() registers a callback that
returns ENETRESET if the caller should reset the ethernet by calling
if_init(), 0 on success, != 0 on failure. Pull common code from
ex(4), gem(4), nfe(4), sip(4), tlp(4), vge(4) into ether_ioctl(),
and register if_flags callbacks for those drivers.
Return ENOTTY instead of EINVAL for inappropriate ioctls. In
zyd(4), use ENXIO instead of ENOTTY to indicate that the device is
not any longer attached.
Add to if_set_sadl() a boolean 'factory' argument that indicates
whether a link-layer address was assigned by the factory or some
other source. In a comment, recommend using the factory address
for generating an EUI64, and update in6_get_hw_ifid() to prefer a
factory address to any other link-layer address.
Add a routing message, RTM_LLINFO_UPD, that tells protocols to
update the binding of network-layer addresses to link-layer addresses.
Implement this message in IPv4 and IPv6 by sending a gratuitous
ARP or a neighbor advertisement, respectively. Generate RTM_LLINFO_UPD
messages on a change of an interface's link-layer address.
In ether_ioctl(), do not let SIOCALIFADDR set a link-layer address
that is broadcast/multicast or equal to 00:00:00:00:00:00.
Make ether_ioctl() call ifioctl_common() to handle ioctls that it
does not understand.
In gif(4), initialize if_softc and use it, instead of assuming that
the gif_softc and ifp overlap.
Let ifioctl_common() handle SIOCGIFADDR.
Sprinkle rtcache_invariants(), which checks on DIAGNOSTIC kernels
that certain invariants on a struct route are satisfied.
In agr(4), rewrite agr_ioctl_filter() to be a bit more explicit
about the ioctls that we do not allow on an agr(4) member interface.
bzero -> memset. Delete unnecessary casts to void *. Use
sockaddr_in_init() and sockaddr_in6_init(). Compare pointers with
NULL instead of "testing truth". Replace some instances of (type
*)0 with NULL. Change some K&R prototypes to ANSI C, and join
lines.
2008-11-07 03:20:01 +03:00
|
|
|
break;
|
|
|
|
case IFF_UP:
|
1999-06-27 16:26:32 +04:00
|
|
|
/*
|
|
|
|
* If interface is marked up and it is stopped, then
|
|
|
|
* start it.
|
|
|
|
*/
|
2009-11-04 01:06:30 +03:00
|
|
|
error = hme_init(ifp);
|
*** Summary ***
When a link-layer address changes (e.g., ifconfig ex0 link
02:de:ad:be:ef:02 active), send a gratuitous ARP and/or a Neighbor
Advertisement to update the network-/link-layer address bindings
on our LAN peers.
Refuse a change of ethernet address to the address 00:00:00:00:00:00
or to any multicast/broadcast address. (Thanks matt@.)
Reorder ifnet ioctl operations so that driver ioctls may inherit
the functions of their "class"---ether_ioctl(), fddi_ioctl(), et
cetera---and the class ioctls may inherit from the generic ioctl,
ifioctl_common(), but both driver- and class-ioctls may override
the generic behavior. Make network drivers share more code.
Distinguish a "factory" link-layer address from others for the
purposes of both protecting that address from deletion and computing
EUI64.
Return consistent, appropriate error codes from network drivers.
Improve readability. KNF.
*** Details ***
In if_attach(), always initialize the interface ioctl routine,
ifnet->if_ioctl, if the driver has not already initialized it.
Delete if_ioctl == NULL tests everywhere else, because it cannot
happen.
In the ioctl routines of network interfaces, inherit common ioctl
behaviors by calling either ifioctl_common() or whichever ioctl
routine is appropriate for the class of interface---e.g., ether_ioctl()
for ethernets.
Stop (ab)using SIOCSIFADDR and start to use SIOCINITIFADDR. In
the user->kernel interface, SIOCSIFADDR's argument was an ifreq,
but on the protocol->ifnet interface, SIOCSIFADDR's argument was
an ifaddr. That was confusing, and it would work against me as I
make it possible for a network interface to overload most ioctls.
On the protocol->ifnet interface, replace SIOCSIFADDR with
SIOCINITIFADDR. In ifioctl(), return EPERM if userland tries to
invoke SIOCINITIFADDR.
In ifioctl(), give the interface the first shot at handling most
interface ioctls, and give the protocol the second shot, instead
of the other way around. Finally, let compatibility code (COMPAT_OSOCK)
take a shot.
Pull device initialization out of switch statements under
SIOCINITIFADDR. For example, pull ..._init() out of any switch
statement that looks like this:
switch (...->sa_family) {
case ...:
..._init();
...
break;
...
default:
..._init();
...
break;
}
Rewrite many if-else clauses that handle all permutations of IFF_UP
and IFF_RUNNING to use a switch statement,
switch (x & (IFF_UP|IFF_RUNNING)) {
case 0:
...
break;
case IFF_RUNNING:
...
break;
case IFF_UP:
...
break;
case IFF_UP|IFF_RUNNING:
...
break;
}
unifdef lots of code containing #ifdef FreeBSD, #ifdef NetBSD, and
#ifdef SIOCSIFMTU, especially in fwip(4) and in ndis(4).
In ipw(4), remove an if_set_sadl() call that is out of place.
In nfe(4), reuse the jumbo MTU logic in ether_ioctl().
Let ethernets register a callback for setting h/w state such as
promiscuous mode and the multicast filter in accord with a change
in the if_flags: ether_set_ifflags_cb() registers a callback that
returns ENETRESET if the caller should reset the ethernet by calling
if_init(), 0 on success, != 0 on failure. Pull common code from
ex(4), gem(4), nfe(4), sip(4), tlp(4), vge(4) into ether_ioctl(),
and register if_flags callbacks for those drivers.
Return ENOTTY instead of EINVAL for inappropriate ioctls. In
zyd(4), use ENXIO instead of ENOTTY to indicate that the device is
not any longer attached.
Add to if_set_sadl() a boolean 'factory' argument that indicates
whether a link-layer address was assigned by the factory or some
other source. In a comment, recommend using the factory address
for generating an EUI64, and update in6_get_hw_ifid() to prefer a
factory address to any other link-layer address.
Add a routing message, RTM_LLINFO_UPD, that tells protocols to
update the binding of network-layer addresses to link-layer addresses.
Implement this message in IPv4 and IPv6 by sending a gratuitous
ARP or a neighbor advertisement, respectively. Generate RTM_LLINFO_UPD
messages on a change of an interface's link-layer address.
In ether_ioctl(), do not let SIOCALIFADDR set a link-layer address
that is broadcast/multicast or equal to 00:00:00:00:00:00.
Make ether_ioctl() call ifioctl_common() to handle ioctls that it
does not understand.
In gif(4), initialize if_softc and use it, instead of assuming that
the gif_softc and ifp overlap.
Let ifioctl_common() handle SIOCGIFADDR.
Sprinkle rtcache_invariants(), which checks on DIAGNOSTIC kernels
that certain invariants on a struct route are satisfied.
In agr(4), rewrite agr_ioctl_filter() to be a bit more explicit
about the ioctls that we do not allow on an agr(4) member interface.
bzero -> memset. Delete unnecessary casts to void *. Use
sockaddr_in_init() and sockaddr_in6_init(). Compare pointers with
NULL instead of "testing truth". Replace some instances of (type
*)0 with NULL. Change some K&R prototypes to ANSI C, and join
lines.
2008-11-07 03:20:01 +03:00
|
|
|
break;
|
|
|
|
case IFF_UP|IFF_RUNNING:
|
1999-06-27 16:26:32 +04:00
|
|
|
/*
|
2004-06-29 00:50:52 +04:00
|
|
|
* If setting debug or promiscuous mode, do not reset
|
|
|
|
* the chip; for everything else, call hme_init()
|
|
|
|
* which will trigger a reset.
|
1999-06-27 16:26:32 +04:00
|
|
|
*/
|
2004-06-29 00:50:52 +04:00
|
|
|
#define RESETIGN (IFF_CANTCHANGE | IFF_DEBUG)
|
2005-02-18 03:40:32 +03:00
|
|
|
if (ifp->if_flags != sc->sc_if_flags) {
|
2005-02-18 03:22:11 +03:00
|
|
|
if ((ifp->if_flags & (~RESETIGN))
|
|
|
|
== (sc->sc_if_flags & (~RESETIGN)))
|
|
|
|
hme_setladrf(sc);
|
|
|
|
else
|
2009-11-04 01:06:30 +03:00
|
|
|
error = hme_init(ifp);
|
2005-02-18 03:22:11 +03:00
|
|
|
}
|
2004-06-29 00:50:52 +04:00
|
|
|
#undef RESETIGN
|
*** Summary ***
When a link-layer address changes (e.g., ifconfig ex0 link
02:de:ad:be:ef:02 active), send a gratuitous ARP and/or a Neighbor
Advertisement to update the network-/link-layer address bindings
on our LAN peers.
Refuse a change of ethernet address to the address 00:00:00:00:00:00
or to any multicast/broadcast address. (Thanks matt@.)
Reorder ifnet ioctl operations so that driver ioctls may inherit
the functions of their "class"---ether_ioctl(), fddi_ioctl(), et
cetera---and the class ioctls may inherit from the generic ioctl,
ifioctl_common(), but both driver- and class-ioctls may override
the generic behavior. Make network drivers share more code.
Distinguish a "factory" link-layer address from others for the
purposes of both protecting that address from deletion and computing
EUI64.
Return consistent, appropriate error codes from network drivers.
Improve readability. KNF.
*** Details ***
In if_attach(), always initialize the interface ioctl routine,
ifnet->if_ioctl, if the driver has not already initialized it.
Delete if_ioctl == NULL tests everywhere else, because it cannot
happen.
In the ioctl routines of network interfaces, inherit common ioctl
behaviors by calling either ifioctl_common() or whichever ioctl
routine is appropriate for the class of interface---e.g., ether_ioctl()
for ethernets.
Stop (ab)using SIOCSIFADDR and start to use SIOCINITIFADDR. In
the user->kernel interface, SIOCSIFADDR's argument was an ifreq,
but on the protocol->ifnet interface, SIOCSIFADDR's argument was
an ifaddr. That was confusing, and it would work against me as I
make it possible for a network interface to overload most ioctls.
On the protocol->ifnet interface, replace SIOCSIFADDR with
SIOCINITIFADDR. In ifioctl(), return EPERM if userland tries to
invoke SIOCINITIFADDR.
In ifioctl(), give the interface the first shot at handling most
interface ioctls, and give the protocol the second shot, instead
of the other way around. Finally, let compatibility code (COMPAT_OSOCK)
take a shot.
Pull device initialization out of switch statements under
SIOCINITIFADDR. For example, pull ..._init() out of any switch
statement that looks like this:
switch (...->sa_family) {
case ...:
..._init();
...
break;
...
default:
..._init();
...
break;
}
Rewrite many if-else clauses that handle all permutations of IFF_UP
and IFF_RUNNING to use a switch statement,
switch (x & (IFF_UP|IFF_RUNNING)) {
case 0:
...
break;
case IFF_RUNNING:
...
break;
case IFF_UP:
...
break;
case IFF_UP|IFF_RUNNING:
...
break;
}
unifdef lots of code containing #ifdef FreeBSD, #ifdef NetBSD, and
#ifdef SIOCSIFMTU, especially in fwip(4) and in ndis(4).
In ipw(4), remove an if_set_sadl() call that is out of place.
In nfe(4), reuse the jumbo MTU logic in ether_ioctl().
Let ethernets register a callback for setting h/w state such as
promiscuous mode and the multicast filter in accord with a change
in the if_flags: ether_set_ifflags_cb() registers a callback that
returns ENETRESET if the caller should reset the ethernet by calling
if_init(), 0 on success, != 0 on failure. Pull common code from
ex(4), gem(4), nfe(4), sip(4), tlp(4), vge(4) into ether_ioctl(),
and register if_flags callbacks for those drivers.
Return ENOTTY instead of EINVAL for inappropriate ioctls. In
zyd(4), use ENXIO instead of ENOTTY to indicate that the device is
not any longer attached.
Add to if_set_sadl() a boolean 'factory' argument that indicates
whether a link-layer address was assigned by the factory or some
other source. In a comment, recommend using the factory address
for generating an EUI64, and update in6_get_hw_ifid() to prefer a
factory address to any other link-layer address.
Add a routing message, RTM_LLINFO_UPD, that tells protocols to
update the binding of network-layer addresses to link-layer addresses.
Implement this message in IPv4 and IPv6 by sending a gratuitous
ARP or a neighbor advertisement, respectively. Generate RTM_LLINFO_UPD
messages on a change of an interface's link-layer address.
In ether_ioctl(), do not let SIOCALIFADDR set a link-layer address
that is broadcast/multicast or equal to 00:00:00:00:00:00.
Make ether_ioctl() call ifioctl_common() to handle ioctls that it
does not understand.
In gif(4), initialize if_softc and use it, instead of assuming that
the gif_softc and ifp overlap.
Let ifioctl_common() handle SIOCGIFADDR.
Sprinkle rtcache_invariants(), which checks on DIAGNOSTIC kernels
that certain invariants on a struct route are satisfied.
In agr(4), rewrite agr_ioctl_filter() to be a bit more explicit
about the ioctls that we do not allow on an agr(4) member interface.
bzero -> memset. Delete unnecessary casts to void *. Use
sockaddr_in_init() and sockaddr_in6_init(). Compare pointers with
NULL instead of "testing truth". Replace some instances of (type
*)0 with NULL. Change some K&R prototypes to ANSI C, and join
lines.
2008-11-07 03:20:01 +03:00
|
|
|
break;
|
|
|
|
case 0:
|
|
|
|
break;
|
1999-06-27 16:26:32 +04:00
|
|
|
}
|
2005-02-18 03:22:11 +03:00
|
|
|
|
|
|
|
if (sc->sc_ec_capenable != sc->sc_ethercom.ec_capenable)
|
2009-11-04 01:06:30 +03:00
|
|
|
error = hme_init(ifp);
|
2005-02-18 03:22:11 +03:00
|
|
|
|
1999-06-27 16:26:32 +04:00
|
|
|
break;
|
|
|
|
|
2008-02-07 04:21:52 +03:00
|
|
|
default:
|
|
|
|
if ((error = ether_ioctl(ifp, cmd, data)) != ENETRESET)
|
|
|
|
break;
|
|
|
|
|
|
|
|
error = 0;
|
|
|
|
|
|
|
|
if (cmd != SIOCADDMULTI && cmd != SIOCDELMULTI)
|
|
|
|
;
|
|
|
|
else if (ifp->if_flags & IFF_RUNNING) {
|
1999-06-27 16:26:32 +04:00
|
|
|
/*
|
|
|
|
* Multicast list has changed; set the hardware filter
|
|
|
|
* accordingly.
|
|
|
|
*/
|
2008-02-07 04:21:52 +03:00
|
|
|
hme_setladrf(sc);
|
1999-06-27 16:26:32 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2004-06-29 00:50:52 +04:00
|
|
|
sc->sc_if_flags = ifp->if_flags;
|
1999-06-27 16:26:32 +04:00
|
|
|
splx(s);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2009-09-08 21:16:33 +04:00
|
|
|
bool
|
|
|
|
hme_shutdown(device_t self, int howto)
|
1999-06-27 16:26:32 +04:00
|
|
|
{
|
2009-05-17 04:40:43 +04:00
|
|
|
struct hme_softc *sc;
|
2009-09-08 21:16:33 +04:00
|
|
|
struct ifnet *ifp;
|
|
|
|
|
|
|
|
sc = device_private(self);
|
|
|
|
ifp = &sc->sc_ethercom.ec_if;
|
|
|
|
hme_stop(ifp, 1);
|
2001-11-26 13:39:29 +03:00
|
|
|
|
2009-09-08 21:16:33 +04:00
|
|
|
return true;
|
1999-06-27 16:26:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set up the logical address filter.
|
|
|
|
*/
|
|
|
|
void
|
2009-03-14 18:35:58 +03:00
|
|
|
hme_setladrf(struct hme_softc *sc)
|
1999-06-27 16:26:32 +04:00
|
|
|
{
|
|
|
|
struct ifnet *ifp = &sc->sc_ethercom.ec_if;
|
|
|
|
struct ether_multi *enm;
|
|
|
|
struct ether_multistep step;
|
2001-11-26 13:39:29 +03:00
|
|
|
struct ethercom *ec = &sc->sc_ethercom;
|
1999-06-27 16:26:32 +04:00
|
|
|
bus_space_tag_t t = sc->sc_bustag;
|
|
|
|
bus_space_handle_t mac = sc->sc_mac;
|
2009-09-19 08:55:45 +04:00
|
|
|
uint32_t v;
|
2009-04-16 18:08:18 +04:00
|
|
|
uint32_t crc;
|
|
|
|
uint32_t hash[4];
|
1999-06-27 16:26:32 +04:00
|
|
|
|
2000-06-15 19:34:32 +04:00
|
|
|
/* Clear hash table */
|
|
|
|
hash[3] = hash[2] = hash[1] = hash[0] = 0;
|
|
|
|
|
|
|
|
/* Get current RX configuration */
|
|
|
|
v = bus_space_read_4(t, mac, HME_MACI_RXCFG);
|
|
|
|
|
|
|
|
if ((ifp->if_flags & IFF_PROMISC) != 0) {
|
|
|
|
/* Turn on promiscuous mode; turn off the hash filter */
|
|
|
|
v |= HME_MAC_RXCFG_PMISC;
|
|
|
|
v &= ~HME_MAC_RXCFG_HENABLE;
|
|
|
|
ifp->if_flags |= IFF_ALLMULTI;
|
|
|
|
goto chipit;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Turn off promiscuous mode; turn on the hash filter */
|
|
|
|
v &= ~HME_MAC_RXCFG_PMISC;
|
|
|
|
v |= HME_MAC_RXCFG_HENABLE;
|
|
|
|
|
1999-06-27 16:26:32 +04:00
|
|
|
/*
|
|
|
|
* Set up multicast address filter by passing all multicast addresses
|
|
|
|
* through a crc generator, and then using the high order 6 bits as an
|
|
|
|
* index into the 64 bit logical address filter. The high order bit
|
|
|
|
* selects the word, while the rest of the bits select the bit within
|
|
|
|
* the word.
|
|
|
|
*/
|
|
|
|
|
2001-11-26 13:39:29 +03:00
|
|
|
ETHER_FIRST_MULTI(step, ec, enm);
|
1999-06-27 16:26:32 +04:00
|
|
|
while (enm != NULL) {
|
2009-03-07 19:46:25 +03:00
|
|
|
if (memcmp(enm->enm_addrlo, enm->enm_addrhi, ETHER_ADDR_LEN)) {
|
1999-06-27 16:26:32 +04:00
|
|
|
/*
|
|
|
|
* We must listen to a range of multicast addresses.
|
|
|
|
* For now, just accept all multicasts, rather than
|
|
|
|
* trying to set only those filter bits needed to match
|
|
|
|
* the range. (At this time, the only use of address
|
|
|
|
* ranges is for IP multicast routing, for which the
|
|
|
|
* range is big enough to require all bits set.)
|
|
|
|
*/
|
2000-06-15 19:34:32 +04:00
|
|
|
hash[3] = hash[2] = hash[1] = hash[0] = 0xffff;
|
|
|
|
ifp->if_flags |= IFF_ALLMULTI;
|
|
|
|
goto chipit;
|
1999-06-27 16:26:32 +04:00
|
|
|
}
|
|
|
|
|
2009-09-19 08:55:45 +04:00
|
|
|
crc = ether_crc32_le(enm->enm_addrlo, ETHER_ADDR_LEN);
|
|
|
|
|
1999-06-27 16:26:32 +04:00
|
|
|
/* Just want the 6 most significant bits. */
|
|
|
|
crc >>= 26;
|
|
|
|
|
|
|
|
/* Set the corresponding bit in the filter. */
|
|
|
|
hash[crc >> 4] |= 1 << (crc & 0xf);
|
|
|
|
|
|
|
|
ETHER_NEXT_MULTI(step, enm);
|
|
|
|
}
|
|
|
|
|
2000-06-15 19:34:32 +04:00
|
|
|
ifp->if_flags &= ~IFF_ALLMULTI;
|
|
|
|
|
|
|
|
chipit:
|
|
|
|
/* Now load the hash table into the chip */
|
1999-06-27 16:26:32 +04:00
|
|
|
bus_space_write_4(t, mac, HME_MACI_HASHTAB0, hash[0]);
|
|
|
|
bus_space_write_4(t, mac, HME_MACI_HASHTAB1, hash[1]);
|
|
|
|
bus_space_write_4(t, mac, HME_MACI_HASHTAB2, hash[2]);
|
|
|
|
bus_space_write_4(t, mac, HME_MACI_HASHTAB3, hash[3]);
|
2000-06-15 19:34:32 +04:00
|
|
|
bus_space_write_4(t, mac, HME_MACI_RXCFG, v);
|
1999-06-27 16:26:32 +04:00
|
|
|
}
|
|
|
|
|
2001-11-26 13:39:29 +03:00
|
|
|
/*
|
|
|
|
* Routines for accessing the transmit and receive buffers.
|
|
|
|
* The various CPU and adapter configurations supported by this
|
|
|
|
* driver require three different access methods for buffers
|
|
|
|
* and descriptors:
|
|
|
|
* (1) contig (contiguous data; no padding),
|
|
|
|
* (2) gap2 (two bytes of data followed by two bytes of padding),
|
|
|
|
* (3) gap16 (16 bytes of data followed by 16 bytes of padding).
|
|
|
|
*/
|
2001-11-26 01:12:01 +03:00
|
|
|
|
2001-11-26 13:39:29 +03:00
|
|
|
#if 0
|
|
|
|
/*
|
|
|
|
* contig: contiguous data with no padding.
|
|
|
|
*
|
|
|
|
* Buffers may have any alignment.
|
|
|
|
*/
|
2001-11-26 01:12:01 +03:00
|
|
|
|
2001-11-26 13:39:29 +03:00
|
|
|
void
|
2009-03-15 00:04:01 +03:00
|
|
|
hme_copytobuf_contig(struct hme_softc *sc, void *from, int ri, int len)
|
2001-11-26 13:39:29 +03:00
|
|
|
{
|
2007-03-04 08:59:00 +03:00
|
|
|
volatile void *buf = sc->sc_rb.rb_txbuf + (ri * _HME_BUFSZ);
|
1999-06-27 16:26:32 +04:00
|
|
|
|
|
|
|
/*
|
2001-11-26 13:39:29 +03:00
|
|
|
* Just call memcpy() to do the work.
|
1999-06-27 16:26:32 +04:00
|
|
|
*/
|
2001-11-26 13:39:29 +03:00
|
|
|
memcpy(buf, from, len);
|
1999-06-27 16:26:32 +04:00
|
|
|
}
|
|
|
|
|
2001-11-26 13:39:29 +03:00
|
|
|
void
|
2009-03-15 00:04:01 +03:00
|
|
|
hme_copyfrombuf_contig(struct hme_softc *sc, void *to, int boff, int len)
|
1999-06-27 16:26:32 +04:00
|
|
|
{
|
2007-03-04 08:59:00 +03:00
|
|
|
volatile void *buf = sc->sc_rb.rb_rxbuf + (ri * _HME_BUFSZ);
|
2001-11-26 01:12:01 +03:00
|
|
|
|
2001-11-26 13:39:29 +03:00
|
|
|
/*
|
|
|
|
* Just call memcpy() to do the work.
|
|
|
|
*/
|
|
|
|
memcpy(to, buf, len);
|
1999-06-27 16:26:32 +04:00
|
|
|
}
|
2001-11-26 13:39:29 +03:00
|
|
|
#endif
|