Home | History | Annotate | Line # | Download | only in ic
hme.c revision 1.51.2.4
      1  1.51.2.4     yamt /*	$NetBSD: hme.c,v 1.51.2.4 2007/10/27 11:30:42 yamt Exp $	*/
      2       1.1       pk 
      3       1.1       pk /*-
      4       1.1       pk  * Copyright (c) 1999 The NetBSD Foundation, Inc.
      5       1.1       pk  * All rights reserved.
      6       1.1       pk  *
      7       1.1       pk  * This code is derived from software contributed to The NetBSD Foundation
      8       1.1       pk  * by Paul Kranenburg.
      9       1.1       pk  *
     10       1.1       pk  * Redistribution and use in source and binary forms, with or without
     11       1.1       pk  * modification, are permitted provided that the following conditions
     12       1.1       pk  * are met:
     13       1.1       pk  * 1. Redistributions of source code must retain the above copyright
     14       1.1       pk  *    notice, this list of conditions and the following disclaimer.
     15       1.1       pk  * 2. Redistributions in binary form must reproduce the above copyright
     16       1.1       pk  *    notice, this list of conditions and the following disclaimer in the
     17       1.1       pk  *    documentation and/or other materials provided with the distribution.
     18       1.1       pk  * 3. All advertising materials mentioning features or use of this software
     19       1.1       pk  *    must display the following acknowledgement:
     20       1.1       pk  *        This product includes software developed by the NetBSD
     21       1.1       pk  *        Foundation, Inc. and its contributors.
     22       1.1       pk  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23       1.1       pk  *    contributors may be used to endorse or promote products derived
     24       1.1       pk  *    from this software without specific prior written permission.
     25       1.1       pk  *
     26       1.1       pk  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27       1.1       pk  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28       1.1       pk  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29       1.1       pk  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30       1.1       pk  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31       1.1       pk  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32       1.1       pk  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33       1.1       pk  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34       1.1       pk  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35       1.1       pk  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36       1.1       pk  * POSSIBILITY OF SUCH DAMAGE.
     37       1.1       pk  */
     38       1.1       pk 
     39       1.1       pk /*
     40       1.1       pk  * HME Ethernet module driver.
     41       1.1       pk  */
     42      1.25    lukem 
     43      1.25    lukem #include <sys/cdefs.h>
     44  1.51.2.4     yamt __KERNEL_RCSID(0, "$NetBSD: hme.c,v 1.51.2.4 2007/10/27 11:30:42 yamt Exp $");
     45       1.1       pk 
     46      1.39   petrov /* #define HMEDEBUG */
     47       1.1       pk 
     48       1.1       pk #include "opt_inet.h"
     49       1.1       pk #include "bpfilter.h"
     50       1.1       pk #include "rnd.h"
     51       1.1       pk 
     52       1.1       pk #include <sys/param.h>
     53       1.1       pk #include <sys/systm.h>
     54       1.5       pk #include <sys/kernel.h>
     55      1.42     heas #include <sys/mbuf.h>
     56       1.1       pk #include <sys/syslog.h>
     57       1.1       pk #include <sys/socket.h>
     58       1.1       pk #include <sys/device.h>
     59       1.1       pk #include <sys/malloc.h>
     60       1.1       pk #include <sys/ioctl.h>
     61       1.1       pk #include <sys/errno.h>
     62       1.1       pk #if NRND > 0
     63       1.1       pk #include <sys/rnd.h>
     64       1.1       pk #endif
     65       1.1       pk 
     66       1.1       pk #include <net/if.h>
     67       1.1       pk #include <net/if_dl.h>
     68       1.1       pk #include <net/if_ether.h>
     69       1.1       pk #include <net/if_media.h>
     70       1.1       pk 
     71       1.1       pk #ifdef INET
     72       1.1       pk #include <netinet/in.h>
     73       1.1       pk #include <netinet/if_inarp.h>
     74       1.1       pk #include <netinet/in_systm.h>
     75       1.1       pk #include <netinet/in_var.h>
     76       1.1       pk #include <netinet/ip.h>
     77      1.46     heas #include <netinet/tcp.h>
     78      1.46     heas #include <netinet/udp.h>
     79       1.1       pk #endif
     80       1.1       pk 
     81       1.1       pk 
     82       1.1       pk #if NBPFILTER > 0
     83       1.1       pk #include <net/bpf.h>
     84       1.1       pk #include <net/bpfdesc.h>
     85       1.1       pk #endif
     86       1.1       pk 
     87       1.1       pk #include <dev/mii/mii.h>
     88       1.1       pk #include <dev/mii/miivar.h>
     89       1.1       pk 
     90  1.51.2.4     yamt #include <sys/bus.h>
     91       1.1       pk 
     92       1.1       pk #include <dev/ic/hmereg.h>
     93       1.1       pk #include <dev/ic/hmevar.h>
     94       1.1       pk 
     95      1.44    perry void		hme_start(struct ifnet *);
     96  1.51.2.3     yamt void		hme_stop(struct hme_softc *,bool);
     97  1.51.2.3     yamt int		hme_ioctl(struct ifnet *, u_long, void *);
     98      1.44    perry void		hme_tick(void *);
     99      1.44    perry void		hme_watchdog(struct ifnet *);
    100      1.44    perry void		hme_shutdown(void *);
    101      1.44    perry void		hme_init(struct hme_softc *);
    102      1.44    perry void		hme_meminit(struct hme_softc *);
    103      1.44    perry void		hme_mifinit(struct hme_softc *);
    104      1.44    perry void		hme_reset(struct hme_softc *);
    105      1.44    perry void		hme_setladrf(struct hme_softc *);
    106       1.1       pk 
    107       1.1       pk /* MII methods & callbacks */
    108      1.44    perry static int	hme_mii_readreg(struct device *, int, int);
    109      1.44    perry static void	hme_mii_writereg(struct device *, int, int, int);
    110      1.44    perry static void	hme_mii_statchg(struct device *);
    111      1.44    perry 
    112      1.44    perry int		hme_mediachange(struct ifnet *);
    113      1.44    perry void		hme_mediastatus(struct ifnet *, struct ifmediareq *);
    114      1.44    perry 
    115      1.46     heas struct mbuf	*hme_get(struct hme_softc *, int, uint32_t);
    116      1.44    perry int		hme_put(struct hme_softc *, int, struct mbuf *);
    117      1.46     heas void		hme_read(struct hme_softc *, int, uint32_t);
    118      1.44    perry int		hme_eint(struct hme_softc *, u_int);
    119      1.44    perry int		hme_rint(struct hme_softc *);
    120      1.44    perry int		hme_tint(struct hme_softc *);
    121       1.1       pk 
    122      1.44    perry static int	ether_cmp(u_char *, u_char *);
    123      1.28     tron 
    124      1.28     tron /* Default buffer copy routines */
    125      1.44    perry void	hme_copytobuf_contig(struct hme_softc *, void *, int, int);
    126      1.44    perry void	hme_copyfrombuf_contig(struct hme_softc *, void *, int, int);
    127      1.44    perry void	hme_zerobuf_contig(struct hme_softc *, int, int);
    128      1.28     tron 
    129      1.28     tron 
    130       1.1       pk void
    131       1.1       pk hme_config(sc)
    132       1.1       pk 	struct hme_softc *sc;
    133       1.1       pk {
    134       1.1       pk 	struct ifnet *ifp = &sc->sc_ethercom.ec_if;
    135       1.1       pk 	struct mii_data *mii = &sc->sc_mii;
    136       1.5       pk 	struct mii_softc *child;
    137      1.11       pk 	bus_dma_tag_t dmatag = sc->sc_dmatag;
    138       1.1       pk 	bus_dma_segment_t seg;
    139       1.1       pk 	bus_size_t size;
    140      1.28     tron 	int rseg, error;
    141       1.1       pk 
    142       1.1       pk 	/*
    143       1.1       pk 	 * HME common initialization.
    144       1.1       pk 	 *
    145       1.1       pk 	 * hme_softc fields that must be initialized by the front-end:
    146       1.1       pk 	 *
    147       1.1       pk 	 * the bus tag:
    148       1.1       pk 	 *	sc_bustag
    149       1.1       pk 	 *
    150      1.37      wiz 	 * the DMA bus tag:
    151       1.1       pk 	 *	sc_dmatag
    152       1.1       pk 	 *
    153       1.1       pk 	 * the bus handles:
    154       1.1       pk 	 *	sc_seb		(Shared Ethernet Block registers)
    155       1.1       pk 	 *	sc_erx		(Receiver Unit registers)
    156       1.1       pk 	 *	sc_etx		(Transmitter Unit registers)
    157       1.1       pk 	 *	sc_mac		(MAC registers)
    158      1.36      wiz 	 *	sc_mif		(Management Interface registers)
    159       1.1       pk 	 *
    160       1.1       pk 	 * the maximum bus burst size:
    161       1.1       pk 	 *	sc_burst
    162       1.1       pk 	 *
    163      1.28     tron 	 * (notyet:DMA capable memory for the ring descriptors & packet buffers:
    164      1.28     tron 	 *	rb_membase, rb_dmabase)
    165      1.28     tron 	 *
    166       1.1       pk 	 * the local Ethernet address:
    167       1.1       pk 	 *	sc_enaddr
    168       1.1       pk 	 *
    169       1.1       pk 	 */
    170       1.1       pk 
    171       1.1       pk 	/* Make sure the chip is stopped. */
    172  1.51.2.3     yamt 	hme_stop(sc, true);
    173       1.1       pk 
    174       1.1       pk 
    175      1.28     tron 	/*
    176      1.28     tron 	 * Allocate descriptors and buffers
    177      1.28     tron 	 * XXX - do all this differently.. and more configurably,
    178      1.28     tron 	 * eg. use things as `dma_load_mbuf()' on transmit,
    179      1.28     tron 	 *     and a pool of `EXTMEM' mbufs (with buffers DMA-mapped
    180      1.38      wiz 	 *     all the time) on the receiver side.
    181      1.28     tron 	 *
    182      1.28     tron 	 * Note: receive buffers must be 64-byte aligned.
    183      1.28     tron 	 * Also, apparently, the buffers must extend to a DMA burst
    184      1.28     tron 	 * boundary beyond the maximum packet size.
    185      1.28     tron 	 */
    186      1.28     tron #define _HME_NDESC	128
    187      1.28     tron #define _HME_BUFSZ	1600
    188      1.28     tron 
    189      1.28     tron 	/* Note: the # of descriptors must be a multiple of 16 */
    190      1.28     tron 	sc->sc_rb.rb_ntbuf = _HME_NDESC;
    191      1.28     tron 	sc->sc_rb.rb_nrbuf = _HME_NDESC;
    192       1.1       pk 
    193       1.1       pk 	/*
    194       1.1       pk 	 * Allocate DMA capable memory
    195       1.1       pk 	 * Buffer descriptors must be aligned on a 2048 byte boundary;
    196       1.1       pk 	 * take this into account when calculating the size. Note that
    197       1.1       pk 	 * the maximum number of descriptors (256) occupies 2048 bytes,
    198      1.28     tron 	 * so we allocate that much regardless of _HME_NDESC.
    199       1.1       pk 	 */
    200      1.28     tron 	size =	2048 +					/* TX descriptors */
    201      1.28     tron 		2048 +					/* RX descriptors */
    202      1.28     tron 		sc->sc_rb.rb_ntbuf * _HME_BUFSZ +	/* TX buffers */
    203      1.46     heas 		sc->sc_rb.rb_nrbuf * _HME_BUFSZ;	/* RX buffers */
    204      1.11       pk 
    205      1.11       pk 	/* Allocate DMA buffer */
    206      1.28     tron 	if ((error = bus_dmamem_alloc(dmatag, size,
    207      1.28     tron 				      2048, 0,
    208      1.28     tron 				      &seg, 1, &rseg, BUS_DMA_NOWAIT)) != 0) {
    209       1.1       pk 		printf("%s: DMA buffer alloc error %d\n",
    210      1.28     tron 			sc->sc_dev.dv_xname, error);
    211      1.10      mrg 		return;
    212       1.1       pk 	}
    213       1.1       pk 
    214      1.11       pk 	/* Map DMA memory in CPU addressable space */
    215      1.11       pk 	if ((error = bus_dmamem_map(dmatag, &seg, rseg, size,
    216      1.28     tron 				    &sc->sc_rb.rb_membase,
    217      1.28     tron 				    BUS_DMA_NOWAIT|BUS_DMA_COHERENT)) != 0) {
    218       1.1       pk 		printf("%s: DMA buffer map error %d\n",
    219      1.28     tron 			sc->sc_dev.dv_xname, error);
    220      1.11       pk 		bus_dmamap_unload(dmatag, sc->sc_dmamap);
    221      1.11       pk 		bus_dmamem_free(dmatag, &seg, rseg);
    222       1.1       pk 		return;
    223       1.1       pk 	}
    224      1.13      mrg 
    225      1.13      mrg 	if ((error = bus_dmamap_create(dmatag, size, 1, size, 0,
    226      1.28     tron 				    BUS_DMA_NOWAIT, &sc->sc_dmamap)) != 0) {
    227      1.13      mrg 		printf("%s: DMA map create error %d\n",
    228      1.28     tron 			sc->sc_dev.dv_xname, error);
    229      1.13      mrg 		return;
    230      1.13      mrg 	}
    231      1.13      mrg 
    232      1.13      mrg 	/* Load the buffer */
    233      1.13      mrg 	if ((error = bus_dmamap_load(dmatag, sc->sc_dmamap,
    234      1.17      mrg 	    sc->sc_rb.rb_membase, size, NULL,
    235      1.17      mrg 	    BUS_DMA_NOWAIT|BUS_DMA_COHERENT)) != 0) {
    236      1.13      mrg 		printf("%s: DMA buffer map load error %d\n",
    237      1.28     tron 			sc->sc_dev.dv_xname, error);
    238      1.13      mrg 		bus_dmamem_free(dmatag, &seg, rseg);
    239      1.13      mrg 		return;
    240      1.13      mrg 	}
    241      1.13      mrg 	sc->sc_rb.rb_dmabase = sc->sc_dmamap->dm_segs[0].ds_addr;
    242       1.1       pk 
    243      1.22  thorpej 	printf("%s: Ethernet address %s\n", sc->sc_dev.dv_xname,
    244      1.22  thorpej 	    ether_sprintf(sc->sc_enaddr));
    245       1.2       pk 
    246       1.1       pk 	/* Initialize ifnet structure. */
    247      1.21  thorpej 	strcpy(ifp->if_xname, sc->sc_dev.dv_xname);
    248       1.1       pk 	ifp->if_softc = sc;
    249       1.1       pk 	ifp->if_start = hme_start;
    250       1.1       pk 	ifp->if_ioctl = hme_ioctl;
    251       1.1       pk 	ifp->if_watchdog = hme_watchdog;
    252       1.1       pk 	ifp->if_flags =
    253       1.1       pk 	    IFF_BROADCAST | IFF_SIMPLEX | IFF_NOTRAILERS | IFF_MULTICAST;
    254      1.41     heas 	sc->sc_if_flags = ifp->if_flags;
    255      1.51     yamt 	ifp->if_capabilities |=
    256      1.51     yamt 	    IFCAP_CSUM_TCPv4_Tx | IFCAP_CSUM_TCPv4_Rx |
    257      1.51     yamt 	    IFCAP_CSUM_UDPv4_Tx | IFCAP_CSUM_UDPv4_Rx;
    258      1.20  thorpej 	IFQ_SET_READY(&ifp->if_snd);
    259       1.1       pk 
    260       1.1       pk 	/* Initialize ifmedia structures and MII info */
    261       1.1       pk 	mii->mii_ifp = ifp;
    262      1.34   petrov 	mii->mii_readreg = hme_mii_readreg;
    263       1.1       pk 	mii->mii_writereg = hme_mii_writereg;
    264       1.1       pk 	mii->mii_statchg = hme_mii_statchg;
    265       1.1       pk 
    266      1.33       pk 	ifmedia_init(&mii->mii_media, 0, hme_mediachange, hme_mediastatus);
    267       1.1       pk 
    268       1.4       pk 	hme_mifinit(sc);
    269       1.4       pk 
    270       1.6  thorpej 	mii_attach(&sc->sc_dev, mii, 0xffffffff,
    271      1.34   petrov 			MII_PHY_ANY, MII_OFFSET_ANY, MIIF_FORCEANEG);
    272       1.2       pk 
    273       1.5       pk 	child = LIST_FIRST(&mii->mii_phys);
    274       1.5       pk 	if (child == NULL) {
    275       1.1       pk 		/* No PHY attached */
    276       1.1       pk 		ifmedia_add(&sc->sc_media, IFM_ETHER|IFM_MANUAL, 0, NULL);
    277       1.1       pk 		ifmedia_set(&sc->sc_media, IFM_ETHER|IFM_MANUAL);
    278       1.1       pk 	} else {
    279       1.1       pk 		/*
    280       1.5       pk 		 * Walk along the list of attached MII devices and
    281       1.5       pk 		 * establish an `MII instance' to `phy number'
    282       1.5       pk 		 * mapping. We'll use this mapping in media change
    283       1.5       pk 		 * requests to determine which phy to use to program
    284       1.5       pk 		 * the MIF configuration register.
    285       1.5       pk 		 */
    286       1.5       pk 		for (; child != NULL; child = LIST_NEXT(child, mii_list)) {
    287       1.5       pk 			/*
    288       1.5       pk 			 * Note: we support just two PHYs: the built-in
    289       1.5       pk 			 * internal device and an external on the MII
    290       1.5       pk 			 * connector.
    291       1.5       pk 			 */
    292       1.5       pk 			if (child->mii_phy > 1 || child->mii_inst > 1) {
    293  1.51.2.2     yamt 				printf("%s: cannot accommodate MII device %s"
    294      1.28     tron 				       " at phy %d, instance %d\n",
    295      1.28     tron 				       sc->sc_dev.dv_xname,
    296      1.28     tron 				       child->mii_dev.dv_xname,
    297      1.28     tron 				       child->mii_phy, child->mii_inst);
    298       1.5       pk 				continue;
    299       1.5       pk 			}
    300       1.5       pk 
    301       1.5       pk 			sc->sc_phys[child->mii_inst] = child->mii_phy;
    302       1.5       pk 		}
    303       1.5       pk 
    304       1.5       pk 		/*
    305       1.1       pk 		 * XXX - we can really do the following ONLY if the
    306       1.1       pk 		 * phy indeed has the auto negotiation capability!!
    307       1.1       pk 		 */
    308       1.1       pk 		ifmedia_set(&sc->sc_media, IFM_ETHER|IFM_AUTO);
    309       1.1       pk 	}
    310      1.27     tron 
    311      1.28     tron 	/* claim 802.1q capability */
    312      1.27     tron 	sc->sc_ethercom.ec_capabilities |= ETHERCAP_VLAN_MTU;
    313       1.1       pk 
    314       1.1       pk 	/* Attach the interface. */
    315       1.1       pk 	if_attach(ifp);
    316       1.1       pk 	ether_ifattach(ifp, sc->sc_enaddr);
    317       1.1       pk 
    318       1.1       pk 	sc->sc_sh = shutdownhook_establish(hme_shutdown, sc);
    319       1.1       pk 	if (sc->sc_sh == NULL)
    320       1.1       pk 		panic("hme_config: can't establish shutdownhook");
    321       1.1       pk 
    322       1.1       pk #if NRND > 0
    323       1.1       pk 	rnd_attach_source(&sc->rnd_source, sc->sc_dev.dv_xname,
    324       1.1       pk 			  RND_TYPE_NET, 0);
    325       1.1       pk #endif
    326       1.5       pk 
    327  1.51.2.3     yamt 	callout_init(&sc->sc_tick_ch, 0);
    328       1.5       pk }
    329       1.5       pk 
    330       1.5       pk void
    331       1.5       pk hme_tick(arg)
    332       1.5       pk 	void *arg;
    333       1.5       pk {
    334       1.5       pk 	struct hme_softc *sc = arg;
    335       1.5       pk 	int s;
    336       1.5       pk 
    337       1.5       pk 	s = splnet();
    338       1.5       pk 	mii_tick(&sc->sc_mii);
    339       1.5       pk 	splx(s);
    340       1.5       pk 
    341       1.9  thorpej 	callout_reset(&sc->sc_tick_ch, hz, hme_tick, sc);
    342       1.1       pk }
    343       1.1       pk 
    344       1.1       pk void
    345       1.1       pk hme_reset(sc)
    346       1.1       pk 	struct hme_softc *sc;
    347       1.1       pk {
    348       1.1       pk 	int s;
    349       1.1       pk 
    350       1.1       pk 	s = splnet();
    351       1.1       pk 	hme_init(sc);
    352       1.1       pk 	splx(s);
    353       1.1       pk }
    354       1.1       pk 
    355       1.1       pk void
    356  1.51.2.3     yamt hme_stop(struct hme_softc *sc, bool chip_only)
    357       1.1       pk {
    358       1.1       pk 	bus_space_tag_t t = sc->sc_bustag;
    359       1.1       pk 	bus_space_handle_t seb = sc->sc_seb;
    360       1.1       pk 	int n;
    361       1.1       pk 
    362  1.51.2.3     yamt 	if (!chip_only) {
    363  1.51.2.3     yamt 		callout_stop(&sc->sc_tick_ch);
    364  1.51.2.3     yamt 		mii_down(&sc->sc_mii);
    365  1.51.2.3     yamt 	}
    366       1.5       pk 
    367      1.33       pk 	/* Mask all interrupts */
    368      1.33       pk 	bus_space_write_4(t, seb, HME_SEBI_IMASK, 0xffffffff);
    369      1.33       pk 
    370       1.1       pk 	/* Reset transmitter and receiver */
    371       1.1       pk 	bus_space_write_4(t, seb, HME_SEBI_RESET,
    372      1.28     tron 			  (HME_SEB_RESET_ETX | HME_SEB_RESET_ERX));
    373       1.1       pk 
    374       1.1       pk 	for (n = 0; n < 20; n++) {
    375       1.1       pk 		u_int32_t v = bus_space_read_4(t, seb, HME_SEBI_RESET);
    376       1.1       pk 		if ((v & (HME_SEB_RESET_ETX | HME_SEB_RESET_ERX)) == 0)
    377       1.1       pk 			return;
    378       1.1       pk 		DELAY(20);
    379       1.1       pk 	}
    380       1.1       pk 
    381       1.1       pk 	printf("%s: hme_stop: reset failed\n", sc->sc_dev.dv_xname);
    382       1.1       pk }
    383       1.1       pk 
    384       1.1       pk void
    385       1.1       pk hme_meminit(sc)
    386       1.1       pk 	struct hme_softc *sc;
    387       1.1       pk {
    388      1.28     tron 	bus_addr_t txbufdma, rxbufdma;
    389       1.1       pk 	bus_addr_t dma;
    390  1.51.2.3     yamt 	char *p;
    391      1.28     tron 	unsigned int ntbuf, nrbuf, i;
    392       1.1       pk 	struct hme_ring *hr = &sc->sc_rb;
    393       1.1       pk 
    394       1.1       pk 	p = hr->rb_membase;
    395       1.1       pk 	dma = hr->rb_dmabase;
    396       1.1       pk 
    397      1.28     tron 	ntbuf = hr->rb_ntbuf;
    398      1.28     tron 	nrbuf = hr->rb_nrbuf;
    399      1.28     tron 
    400       1.1       pk 	/*
    401       1.1       pk 	 * Allocate transmit descriptors
    402       1.1       pk 	 */
    403       1.1       pk 	hr->rb_txd = p;
    404       1.1       pk 	hr->rb_txddma = dma;
    405      1.28     tron 	p += ntbuf * HME_XD_SIZE;
    406      1.28     tron 	dma += ntbuf * HME_XD_SIZE;
    407       1.4       pk 	/* We have reserved descriptor space until the next 2048 byte boundary.*/
    408       1.4       pk 	dma = (bus_addr_t)roundup((u_long)dma, 2048);
    409  1.51.2.3     yamt 	p = (void *)roundup((u_long)p, 2048);
    410       1.1       pk 
    411       1.1       pk 	/*
    412       1.1       pk 	 * Allocate receive descriptors
    413       1.1       pk 	 */
    414       1.1       pk 	hr->rb_rxd = p;
    415       1.1       pk 	hr->rb_rxddma = dma;
    416      1.28     tron 	p += nrbuf * HME_XD_SIZE;
    417      1.28     tron 	dma += nrbuf * HME_XD_SIZE;
    418       1.4       pk 	/* Again move forward to the next 2048 byte boundary.*/
    419       1.4       pk 	dma = (bus_addr_t)roundup((u_long)dma, 2048);
    420  1.51.2.3     yamt 	p = (void *)roundup((u_long)p, 2048);
    421       1.1       pk 
    422      1.28     tron 
    423       1.1       pk 	/*
    424      1.28     tron 	 * Allocate transmit buffers
    425       1.1       pk 	 */
    426      1.28     tron 	hr->rb_txbuf = p;
    427      1.28     tron 	txbufdma = dma;
    428      1.28     tron 	p += ntbuf * _HME_BUFSZ;
    429      1.28     tron 	dma += ntbuf * _HME_BUFSZ;
    430      1.28     tron 
    431      1.28     tron 	/*
    432      1.28     tron 	 * Allocate receive buffers
    433      1.28     tron 	 */
    434      1.28     tron 	hr->rb_rxbuf = p;
    435      1.28     tron 	rxbufdma = dma;
    436      1.28     tron 	p += nrbuf * _HME_BUFSZ;
    437      1.28     tron 	dma += nrbuf * _HME_BUFSZ;
    438      1.28     tron 
    439      1.28     tron 	/*
    440      1.28     tron 	 * Initialize transmit buffer descriptors
    441      1.28     tron 	 */
    442      1.28     tron 	for (i = 0; i < ntbuf; i++) {
    443      1.28     tron 		HME_XD_SETADDR(sc->sc_pci, hr->rb_txd, i, txbufdma + i * _HME_BUFSZ);
    444      1.15      eeh 		HME_XD_SETFLAGS(sc->sc_pci, hr->rb_txd, i, 0);
    445       1.1       pk 	}
    446       1.1       pk 
    447       1.1       pk 	/*
    448      1.28     tron 	 * Initialize receive buffer descriptors
    449       1.1       pk 	 */
    450      1.28     tron 	for (i = 0; i < nrbuf; i++) {
    451      1.28     tron 		HME_XD_SETADDR(sc->sc_pci, hr->rb_rxd, i, rxbufdma + i * _HME_BUFSZ);
    452      1.15      eeh 		HME_XD_SETFLAGS(sc->sc_pci, hr->rb_rxd, i,
    453      1.28     tron 				HME_XD_OWN | HME_XD_ENCODE_RSIZE(_HME_BUFSZ));
    454       1.1       pk 	}
    455       1.1       pk 
    456      1.28     tron 	hr->rb_tdhead = hr->rb_tdtail = 0;
    457      1.28     tron 	hr->rb_td_nbusy = 0;
    458      1.28     tron 	hr->rb_rdtail = 0;
    459       1.1       pk }
    460       1.1       pk 
    461       1.1       pk /*
    462       1.1       pk  * Initialization of interface; set up initialization block
    463       1.1       pk  * and transmit/receive descriptor rings.
    464       1.1       pk  */
    465       1.1       pk void
    466       1.1       pk hme_init(sc)
    467       1.1       pk 	struct hme_softc *sc;
    468       1.1       pk {
    469       1.1       pk 	struct ifnet *ifp = &sc->sc_ethercom.ec_if;
    470       1.1       pk 	bus_space_tag_t t = sc->sc_bustag;
    471       1.1       pk 	bus_space_handle_t seb = sc->sc_seb;
    472       1.1       pk 	bus_space_handle_t etx = sc->sc_etx;
    473       1.1       pk 	bus_space_handle_t erx = sc->sc_erx;
    474       1.1       pk 	bus_space_handle_t mac = sc->sc_mac;
    475       1.1       pk 	u_int8_t *ea;
    476       1.1       pk 	u_int32_t v;
    477       1.1       pk 
    478       1.1       pk 	/*
    479       1.1       pk 	 * Initialization sequence. The numbered steps below correspond
    480       1.1       pk 	 * to the sequence outlined in section 6.3.5.1 in the Ethernet
    481       1.1       pk 	 * Channel Engine manual (part of the PCIO manual).
    482       1.1       pk 	 * See also the STP2002-STQ document from Sun Microsystems.
    483       1.1       pk 	 */
    484       1.1       pk 
    485       1.1       pk 	/* step 1 & 2. Reset the Ethernet Channel */
    486  1.51.2.3     yamt 	hme_stop(sc, false);
    487       1.1       pk 
    488       1.4       pk 	/* Re-initialize the MIF */
    489       1.4       pk 	hme_mifinit(sc);
    490       1.4       pk 
    491       1.1       pk 	/* Call MI reset function if any */
    492       1.1       pk 	if (sc->sc_hwreset)
    493       1.1       pk 		(*sc->sc_hwreset)(sc);
    494       1.1       pk 
    495       1.1       pk #if 0
    496       1.1       pk 	/* Mask all MIF interrupts, just in case */
    497       1.1       pk 	bus_space_write_4(t, mif, HME_MIFI_IMASK, 0xffff);
    498       1.1       pk #endif
    499       1.1       pk 
    500       1.1       pk 	/* step 3. Setup data structures in host memory */
    501       1.1       pk 	hme_meminit(sc);
    502       1.1       pk 
    503       1.1       pk 	/* step 4. TX MAC registers & counters */
    504       1.1       pk 	bus_space_write_4(t, mac, HME_MACI_NCCNT, 0);
    505       1.1       pk 	bus_space_write_4(t, mac, HME_MACI_FCCNT, 0);
    506       1.1       pk 	bus_space_write_4(t, mac, HME_MACI_EXCNT, 0);
    507       1.1       pk 	bus_space_write_4(t, mac, HME_MACI_LTCNT, 0);
    508      1.28     tron 	bus_space_write_4(t, mac, HME_MACI_TXSIZE,
    509      1.28     tron 	    (sc->sc_ethercom.ec_capenable & ETHERCAP_VLAN_MTU) ?
    510      1.49     heas 	    ETHER_VLAN_ENCAP_LEN + ETHER_MAX_LEN : ETHER_MAX_LEN);
    511      1.45     heas 	sc->sc_ec_capenable = sc->sc_ethercom.ec_capenable;
    512       1.1       pk 
    513       1.1       pk 	/* Load station MAC address */
    514       1.1       pk 	ea = sc->sc_enaddr;
    515       1.1       pk 	bus_space_write_4(t, mac, HME_MACI_MACADDR0, (ea[0] << 8) | ea[1]);
    516       1.1       pk 	bus_space_write_4(t, mac, HME_MACI_MACADDR1, (ea[2] << 8) | ea[3]);
    517       1.1       pk 	bus_space_write_4(t, mac, HME_MACI_MACADDR2, (ea[4] << 8) | ea[5]);
    518       1.1       pk 
    519       1.1       pk 	/*
    520       1.1       pk 	 * Init seed for backoff
    521       1.1       pk 	 * (source suggested by manual: low 10 bits of MAC address)
    522      1.42     heas 	 */
    523       1.1       pk 	v = ((ea[4] << 8) | ea[5]) & 0x3fff;
    524       1.1       pk 	bus_space_write_4(t, mac, HME_MACI_RANDSEED, v);
    525       1.1       pk 
    526       1.1       pk 
    527       1.1       pk 	/* Note: Accepting power-on default for other MAC registers here.. */
    528       1.1       pk 
    529       1.1       pk 
    530       1.1       pk 	/* step 5. RX MAC registers & counters */
    531       1.1       pk 	hme_setladrf(sc);
    532       1.1       pk 
    533       1.1       pk 	/* step 6 & 7. Program Descriptor Ring Base Addresses */
    534       1.1       pk 	bus_space_write_4(t, etx, HME_ETXI_RING, sc->sc_rb.rb_txddma);
    535      1.28     tron 	bus_space_write_4(t, etx, HME_ETXI_RSIZE, sc->sc_rb.rb_ntbuf);
    536       1.1       pk 
    537       1.1       pk 	bus_space_write_4(t, erx, HME_ERXI_RING, sc->sc_rb.rb_rxddma);
    538      1.28     tron 	bus_space_write_4(t, mac, HME_MACI_RXSIZE,
    539      1.28     tron 	    (sc->sc_ethercom.ec_capenable & ETHERCAP_VLAN_MTU) ?
    540      1.49     heas 	    ETHER_VLAN_ENCAP_LEN + ETHER_MAX_LEN : ETHER_MAX_LEN);
    541       1.1       pk 
    542       1.1       pk 	/* step 8. Global Configuration & Interrupt Mask */
    543       1.1       pk 	bus_space_write_4(t, seb, HME_SEBI_IMASK,
    544      1.28     tron 			~(
    545      1.28     tron 			  /*HME_SEB_STAT_GOTFRAME | HME_SEB_STAT_SENTFRAME |*/
    546      1.28     tron 			  HME_SEB_STAT_HOSTTOTX |
    547      1.28     tron 			  HME_SEB_STAT_RXTOHOST |
    548      1.28     tron 			  HME_SEB_STAT_TXALL |
    549      1.28     tron 			  HME_SEB_STAT_TXPERR |
    550      1.28     tron 			  HME_SEB_STAT_RCNTEXP |
    551      1.33       pk 			  /*HME_SEB_STAT_MIFIRQ |*/
    552      1.28     tron 			  HME_SEB_STAT_ALL_ERRORS ));
    553       1.1       pk 
    554       1.1       pk 	switch (sc->sc_burst) {
    555       1.1       pk 	default:
    556       1.1       pk 		v = 0;
    557       1.1       pk 		break;
    558       1.1       pk 	case 16:
    559       1.1       pk 		v = HME_SEB_CFG_BURST16;
    560       1.1       pk 		break;
    561       1.1       pk 	case 32:
    562       1.1       pk 		v = HME_SEB_CFG_BURST32;
    563       1.1       pk 		break;
    564       1.1       pk 	case 64:
    565       1.1       pk 		v = HME_SEB_CFG_BURST64;
    566       1.1       pk 		break;
    567       1.1       pk 	}
    568       1.1       pk 	bus_space_write_4(t, seb, HME_SEBI_CFG, v);
    569       1.1       pk 
    570       1.1       pk 	/* step 9. ETX Configuration: use mostly default values */
    571       1.1       pk 
    572       1.1       pk 	/* Enable DMA */
    573       1.2       pk 	v = bus_space_read_4(t, etx, HME_ETXI_CFG);
    574       1.1       pk 	v |= HME_ETX_CFG_DMAENABLE;
    575       1.2       pk 	bus_space_write_4(t, etx, HME_ETXI_CFG, v);
    576       1.1       pk 
    577       1.3       pk 	/* Transmit Descriptor ring size: in increments of 16 */
    578      1.28     tron 	bus_space_write_4(t, etx, HME_ETXI_RSIZE, _HME_NDESC / 16 - 1);
    579      1.28     tron 
    580       1.1       pk 
    581       1.3       pk 	/* step 10. ERX Configuration */
    582       1.2       pk 	v = bus_space_read_4(t, erx, HME_ERXI_CFG);
    583      1.28     tron 
    584      1.28     tron 	/* Encode Receive Descriptor ring size: four possible values */
    585      1.28     tron 	switch (_HME_NDESC /*XXX*/) {
    586      1.28     tron 	case 32:
    587      1.28     tron 		v |= HME_ERX_CFG_RINGSIZE32;
    588      1.28     tron 		break;
    589      1.28     tron 	case 64:
    590      1.28     tron 		v |= HME_ERX_CFG_RINGSIZE64;
    591      1.28     tron 		break;
    592      1.28     tron 	case 128:
    593      1.28     tron 		v |= HME_ERX_CFG_RINGSIZE128;
    594      1.28     tron 		break;
    595      1.28     tron 	case 256:
    596      1.28     tron 		v |= HME_ERX_CFG_RINGSIZE256;
    597      1.28     tron 		break;
    598      1.28     tron 	default:
    599      1.28     tron 		printf("hme: invalid Receive Descriptor ring size\n");
    600      1.28     tron 		break;
    601      1.28     tron 	}
    602      1.28     tron 
    603       1.3       pk 	/* Enable DMA */
    604      1.28     tron 	v |= HME_ERX_CFG_DMAENABLE;
    605      1.46     heas 
    606      1.46     heas 	/* set h/w rx checksum start offset (# of half-words) */
    607      1.49     heas #ifdef INET
    608      1.48    perry 	v |= (((ETHER_HDR_LEN + sizeof(struct ip) +
    609      1.46     heas 		((sc->sc_ethercom.ec_capenable & ETHERCAP_VLAN_MTU) ?
    610      1.46     heas 		ETHER_VLAN_ENCAP_LEN : 0)) / 2) << HME_ERX_CFG_CSUMSHIFT) &
    611      1.46     heas 		HME_ERX_CFG_CSUMSTART;
    612      1.49     heas #endif
    613       1.2       pk 	bus_space_write_4(t, erx, HME_ERXI_CFG, v);
    614       1.1       pk 
    615       1.1       pk 	/* step 11. XIF Configuration */
    616       1.1       pk 	v = bus_space_read_4(t, mac, HME_MACI_XIF);
    617       1.1       pk 	v |= HME_MAC_XIF_OE;
    618       1.1       pk 	bus_space_write_4(t, mac, HME_MACI_XIF, v);
    619       1.1       pk 
    620       1.1       pk 	/* step 12. RX_MAC Configuration Register */
    621       1.1       pk 	v = bus_space_read_4(t, mac, HME_MACI_RXCFG);
    622      1.46     heas 	v |= HME_MAC_RXCFG_ENABLE | HME_MAC_RXCFG_PSTRIP;
    623       1.1       pk 	bus_space_write_4(t, mac, HME_MACI_RXCFG, v);
    624       1.1       pk 
    625       1.1       pk 	/* step 13. TX_MAC Configuration Register */
    626       1.1       pk 	v = bus_space_read_4(t, mac, HME_MACI_TXCFG);
    627       1.2       pk 	v |= (HME_MAC_TXCFG_ENABLE | HME_MAC_TXCFG_DGIVEUP);
    628       1.1       pk 	bus_space_write_4(t, mac, HME_MACI_TXCFG, v);
    629       1.1       pk 
    630       1.1       pk 	/* step 14. Issue Transmit Pending command */
    631       1.1       pk 
    632       1.1       pk 	/* Call MI initialization function if any */
    633       1.1       pk 	if (sc->sc_hwinit)
    634       1.1       pk 		(*sc->sc_hwinit)(sc);
    635      1.29  thorpej 
    636      1.29  thorpej 	/* Set the current media. */
    637      1.29  thorpej 	mii_mediachg(&sc->sc_mii);
    638       1.9  thorpej 
    639       1.9  thorpej 	/* Start the one second timer. */
    640       1.9  thorpej 	callout_reset(&sc->sc_tick_ch, hz, hme_tick, sc);
    641       1.1       pk 
    642       1.1       pk 	ifp->if_flags |= IFF_RUNNING;
    643       1.1       pk 	ifp->if_flags &= ~IFF_OACTIVE;
    644      1.41     heas 	sc->sc_if_flags = ifp->if_flags;
    645       1.1       pk 	ifp->if_timer = 0;
    646       1.1       pk 	hme_start(ifp);
    647       1.1       pk }
    648       1.1       pk 
    649      1.28     tron /*
    650      1.28     tron  * Compare two Ether/802 addresses for equality, inlined and unrolled for
    651      1.28     tron  * speed.
    652      1.28     tron  */
    653  1.51.2.1     yamt static inline int
    654      1.28     tron ether_cmp(a, b)
    655      1.28     tron 	u_char *a, *b;
    656      1.42     heas {
    657      1.42     heas 
    658      1.28     tron 	if (a[5] != b[5] || a[4] != b[4] || a[3] != b[3] ||
    659      1.28     tron 	    a[2] != b[2] || a[1] != b[1] || a[0] != b[0])
    660      1.28     tron 		return (0);
    661      1.28     tron 	return (1);
    662      1.28     tron }
    663      1.28     tron 
    664      1.28     tron 
    665      1.28     tron /*
    666      1.28     tron  * Routine to copy from mbuf chain to transmit buffer in
    667      1.28     tron  * network buffer memory.
    668      1.28     tron  * Returns the amount of data copied.
    669      1.28     tron  */
    670      1.28     tron int
    671      1.28     tron hme_put(sc, ri, m)
    672      1.28     tron 	struct hme_softc *sc;
    673      1.28     tron 	int ri;			/* Ring index */
    674      1.28     tron 	struct mbuf *m;
    675      1.28     tron {
    676      1.28     tron 	struct mbuf *n;
    677      1.28     tron 	int len, tlen = 0;
    678  1.51.2.3     yamt 	char *bp;
    679      1.28     tron 
    680  1.51.2.3     yamt 	bp = (char *)sc->sc_rb.rb_txbuf + (ri % sc->sc_rb.rb_ntbuf) * _HME_BUFSZ;
    681      1.28     tron 	for (; m; m = n) {
    682      1.28     tron 		len = m->m_len;
    683      1.28     tron 		if (len == 0) {
    684      1.28     tron 			MFREE(m, n);
    685      1.28     tron 			continue;
    686      1.28     tron 		}
    687  1.51.2.3     yamt 		memcpy(bp, mtod(m, void *), len);
    688      1.28     tron 		bp += len;
    689      1.28     tron 		tlen += len;
    690      1.28     tron 		MFREE(m, n);
    691      1.28     tron 	}
    692      1.28     tron 	return (tlen);
    693      1.28     tron }
    694      1.28     tron 
    695      1.28     tron /*
    696      1.28     tron  * Pull data off an interface.
    697      1.28     tron  * Len is length of data, with local net header stripped.
    698      1.28     tron  * We copy the data into mbufs.  When full cluster sized units are present
    699      1.28     tron  * we copy into clusters.
    700      1.28     tron  */
    701      1.28     tron struct mbuf *
    702      1.46     heas hme_get(sc, ri, flags)
    703      1.28     tron 	struct hme_softc *sc;
    704      1.46     heas 	int ri;
    705      1.46     heas 	u_int32_t flags;
    706      1.28     tron {
    707      1.28     tron 	struct ifnet *ifp = &sc->sc_ethercom.ec_if;
    708      1.28     tron 	struct mbuf *m, *m0, *newm;
    709  1.51.2.3     yamt 	char *bp;
    710      1.46     heas 	int len, totlen;
    711      1.28     tron 
    712      1.46     heas 	totlen = HME_XD_DECODE_RSIZE(flags);
    713      1.28     tron 	MGETHDR(m0, M_DONTWAIT, MT_DATA);
    714      1.28     tron 	if (m0 == 0)
    715      1.28     tron 		return (0);
    716      1.28     tron 	m0->m_pkthdr.rcvif = ifp;
    717      1.28     tron 	m0->m_pkthdr.len = totlen;
    718      1.28     tron 	len = MHLEN;
    719      1.28     tron 	m = m0;
    720      1.28     tron 
    721  1.51.2.3     yamt 	bp = (char *)sc->sc_rb.rb_rxbuf + (ri % sc->sc_rb.rb_nrbuf) * _HME_BUFSZ;
    722      1.28     tron 
    723      1.28     tron 	while (totlen > 0) {
    724      1.28     tron 		if (totlen >= MINCLSIZE) {
    725      1.28     tron 			MCLGET(m, M_DONTWAIT);
    726      1.28     tron 			if ((m->m_flags & M_EXT) == 0)
    727      1.28     tron 				goto bad;
    728      1.28     tron 			len = MCLBYTES;
    729      1.28     tron 		}
    730      1.28     tron 
    731      1.28     tron 		if (m == m0) {
    732  1.51.2.3     yamt 			char *newdata = (char *)
    733      1.28     tron 			    ALIGN(m->m_data + sizeof(struct ether_header)) -
    734      1.28     tron 			    sizeof(struct ether_header);
    735      1.28     tron 			len -= newdata - m->m_data;
    736      1.28     tron 			m->m_data = newdata;
    737      1.28     tron 		}
    738      1.28     tron 
    739      1.28     tron 		m->m_len = len = min(totlen, len);
    740  1.51.2.3     yamt 		memcpy(mtod(m, void *), bp, len);
    741      1.28     tron 		bp += len;
    742      1.28     tron 
    743      1.28     tron 		totlen -= len;
    744      1.28     tron 		if (totlen > 0) {
    745      1.28     tron 			MGET(newm, M_DONTWAIT, MT_DATA);
    746      1.28     tron 			if (newm == 0)
    747      1.28     tron 				goto bad;
    748      1.28     tron 			len = MLEN;
    749      1.28     tron 			m = m->m_next = newm;
    750      1.28     tron 		}
    751      1.28     tron 	}
    752      1.28     tron 
    753      1.49     heas #ifdef INET
    754      1.49     heas 	/* hardware checksum */
    755      1.50    rafal 	if (ifp->if_csum_flags_rx & (M_CSUM_TCPv4 | M_CSUM_UDPv4)) {
    756      1.46     heas 		struct ether_header *eh;
    757      1.46     heas 		struct ip *ip;
    758      1.46     heas 		struct udphdr *uh;
    759      1.46     heas 		uint16_t *opts;
    760      1.46     heas 		int32_t hlen, pktlen;
    761      1.46     heas 		uint32_t temp;
    762      1.46     heas 
    763      1.46     heas 		if (sc->sc_ethercom.ec_capenable & ETHERCAP_VLAN_MTU) {
    764      1.46     heas 			pktlen = m0->m_pkthdr.len - ETHER_HDR_LEN -
    765      1.46     heas 				ETHER_VLAN_ENCAP_LEN;
    766  1.51.2.3     yamt 			eh = (struct ether_header *) mtod(m0, void *) +
    767      1.46     heas 				ETHER_VLAN_ENCAP_LEN;
    768      1.46     heas 		} else {
    769      1.46     heas 			pktlen = m0->m_pkthdr.len - ETHER_HDR_LEN;
    770      1.46     heas 			eh = mtod(m0, struct ether_header *);
    771      1.46     heas 		}
    772      1.46     heas 		if (ntohs(eh->ether_type) != ETHERTYPE_IP)
    773      1.46     heas 			goto swcsum;
    774  1.51.2.3     yamt 		ip = (struct ip *) ((char *)eh + ETHER_HDR_LEN);
    775      1.46     heas 
    776      1.46     heas 		/* IPv4 only */
    777      1.46     heas 		if (ip->ip_v != IPVERSION)
    778      1.46     heas 			goto swcsum;
    779      1.46     heas 
    780      1.46     heas 		hlen = ip->ip_hl << 2;
    781      1.48    perry 		if (hlen < sizeof(struct ip))
    782      1.46     heas 			goto swcsum;
    783      1.46     heas 
    784      1.49     heas 		/*
    785      1.49     heas 		 * bail if too short, has random trailing garbage, truncated,
    786      1.49     heas 		 * fragment, or has ethernet pad.
    787      1.49     heas 		 */
    788      1.49     heas 		if ((ntohs(ip->ip_len) < hlen) || (ntohs(ip->ip_len) != pktlen)
    789      1.46     heas 		    || (ntohs(ip->ip_off) & (IP_MF | IP_OFFMASK)))
    790      1.49     heas 			goto swcsum;
    791      1.46     heas 
    792      1.46     heas 		switch (ip->ip_p) {
    793      1.46     heas 		case IPPROTO_TCP:
    794      1.46     heas 			if (! (ifp->if_csum_flags_rx & M_CSUM_TCPv4))
    795      1.46     heas 				goto swcsum;
    796      1.46     heas 			if (pktlen < (hlen + sizeof(struct tcphdr)))
    797      1.46     heas 				goto swcsum;
    798      1.46     heas 			m0->m_pkthdr.csum_flags = M_CSUM_TCPv4;
    799      1.46     heas 			break;
    800      1.46     heas 		case IPPROTO_UDP:
    801      1.46     heas 			if (! (ifp->if_csum_flags_rx & M_CSUM_UDPv4))
    802      1.46     heas 				goto swcsum;
    803      1.46     heas 			if (pktlen < (hlen + sizeof(struct udphdr)))
    804      1.46     heas 				goto swcsum;
    805  1.51.2.3     yamt 			uh = (struct udphdr *)((char *)ip + hlen);
    806      1.46     heas 			/* no checksum */
    807      1.46     heas 			if (uh->uh_sum == 0)
    808      1.46     heas 				goto swcsum;
    809      1.46     heas 			m0->m_pkthdr.csum_flags = M_CSUM_UDPv4;
    810      1.46     heas 			break;
    811      1.46     heas 		default:
    812      1.49     heas 			goto swcsum;
    813      1.46     heas 		}
    814      1.46     heas 
    815      1.46     heas 		/* w/ M_CSUM_NO_PSEUDOHDR, the uncomplemented sum is expected */
    816      1.46     heas 		m0->m_pkthdr.csum_data = (~flags) & HME_XD_RXCKSUM;
    817      1.46     heas 
    818      1.46     heas 		/* if the pkt had ip options, we have to deduct them */
    819      1.46     heas 		if (hlen > sizeof(struct ip)) {
    820      1.46     heas 			uint32_t optsum;
    821      1.46     heas 
    822      1.46     heas 			optsum = 0;
    823      1.46     heas 			temp = hlen - sizeof(struct ip);
    824  1.51.2.3     yamt 			opts = (uint16_t *)((char *)ip + sizeof(struct ip));
    825      1.46     heas 
    826      1.49     heas 			while (temp > 1) {
    827      1.46     heas 				optsum += ntohs(*opts++);
    828      1.46     heas 				temp -= 2;
    829      1.46     heas 			}
    830      1.46     heas 			while (optsum >> 16)
    831      1.46     heas 				optsum = (optsum >> 16) + (optsum & 0xffff);
    832      1.46     heas 
    833      1.46     heas 			/* Deduct the ip opts sum from the hwsum (rfc 1624). */
    834      1.46     heas 			m0->m_pkthdr.csum_data = ~((~m0->m_pkthdr.csum_data) -
    835      1.46     heas 						   ~optsum);
    836      1.46     heas 
    837      1.46     heas 			while (m0->m_pkthdr.csum_data >> 16)
    838      1.46     heas 				m0->m_pkthdr.csum_data =
    839      1.46     heas 					(m0->m_pkthdr.csum_data >> 16) +
    840      1.46     heas 					(m0->m_pkthdr.csum_data & 0xffff);
    841      1.46     heas 		}
    842      1.46     heas 
    843      1.46     heas 		m0->m_pkthdr.csum_flags |= M_CSUM_DATA | M_CSUM_NO_PSEUDOHDR;
    844      1.46     heas 	}
    845      1.49     heas swcsum:
    846      1.49     heas 		m0->m_pkthdr.csum_flags = 0;
    847      1.49     heas #endif
    848      1.46     heas 
    849      1.28     tron 	return (m0);
    850      1.28     tron 
    851      1.28     tron bad:
    852      1.28     tron 	m_freem(m0);
    853      1.28     tron 	return (0);
    854      1.28     tron }
    855      1.28     tron 
    856      1.28     tron /*
    857      1.28     tron  * Pass a packet to the higher levels.
    858      1.28     tron  */
    859      1.28     tron void
    860      1.46     heas hme_read(sc, ix, flags)
    861      1.28     tron 	struct hme_softc *sc;
    862      1.46     heas 	int ix;
    863      1.46     heas 	u_int32_t flags;
    864      1.28     tron {
    865      1.28     tron 	struct ifnet *ifp = &sc->sc_ethercom.ec_if;
    866      1.28     tron 	struct mbuf *m;
    867      1.46     heas 	int len;
    868      1.28     tron 
    869      1.46     heas 	len = HME_XD_DECODE_RSIZE(flags);
    870      1.28     tron 	if (len <= sizeof(struct ether_header) ||
    871      1.28     tron 	    len > ((sc->sc_ethercom.ec_capenable & ETHERCAP_VLAN_MTU) ?
    872      1.28     tron 	    ETHER_VLAN_ENCAP_LEN + ETHERMTU + sizeof(struct ether_header) :
    873      1.28     tron 	    ETHERMTU + sizeof(struct ether_header))) {
    874      1.28     tron #ifdef HMEDEBUG
    875      1.28     tron 		printf("%s: invalid packet size %d; dropping\n",
    876      1.28     tron 		    sc->sc_dev.dv_xname, len);
    877      1.28     tron #endif
    878      1.28     tron 		ifp->if_ierrors++;
    879      1.28     tron 		return;
    880      1.28     tron 	}
    881      1.28     tron 
    882      1.28     tron 	/* Pull packet off interface. */
    883      1.46     heas 	m = hme_get(sc, ix, flags);
    884      1.28     tron 	if (m == 0) {
    885      1.28     tron 		ifp->if_ierrors++;
    886      1.28     tron 		return;
    887      1.28     tron 	}
    888      1.28     tron 
    889      1.28     tron 	ifp->if_ipackets++;
    890      1.28     tron 
    891      1.28     tron #if NBPFILTER > 0
    892      1.28     tron 	/*
    893      1.28     tron 	 * Check if there's a BPF listener on this interface.
    894      1.28     tron 	 * If so, hand off the raw packet to BPF.
    895      1.28     tron 	 */
    896      1.28     tron 	if (ifp->if_bpf)
    897      1.28     tron 		bpf_mtap(ifp->if_bpf, m);
    898      1.28     tron #endif
    899      1.28     tron 
    900      1.28     tron 	/* Pass the packet up. */
    901      1.28     tron 	(*ifp->if_input)(ifp, m);
    902      1.28     tron }
    903      1.28     tron 
    904       1.1       pk void
    905       1.1       pk hme_start(ifp)
    906       1.1       pk 	struct ifnet *ifp;
    907       1.1       pk {
    908       1.1       pk 	struct hme_softc *sc = (struct hme_softc *)ifp->if_softc;
    909  1.51.2.3     yamt 	void *txd = sc->sc_rb.rb_txd;
    910       1.1       pk 	struct mbuf *m;
    911      1.46     heas 	unsigned int txflags;
    912      1.28     tron 	unsigned int ri, len;
    913      1.28     tron 	unsigned int ntbuf = sc->sc_rb.rb_ntbuf;
    914       1.1       pk 
    915       1.1       pk 	if ((ifp->if_flags & (IFF_RUNNING | IFF_OACTIVE)) != IFF_RUNNING)
    916       1.1       pk 		return;
    917       1.1       pk 
    918      1.28     tron 	ri = sc->sc_rb.rb_tdhead;
    919      1.28     tron 
    920      1.28     tron 	for (;;) {
    921      1.28     tron 		IFQ_DEQUEUE(&ifp->if_snd, m);
    922      1.28     tron 		if (m == 0)
    923       1.1       pk 			break;
    924       1.1       pk 
    925       1.1       pk #if NBPFILTER > 0
    926       1.1       pk 		/*
    927       1.1       pk 		 * If BPF is listening on this interface, let it see the
    928       1.1       pk 		 * packet before we commit it to the wire.
    929       1.1       pk 		 */
    930       1.1       pk 		if (ifp->if_bpf)
    931       1.1       pk 			bpf_mtap(ifp->if_bpf, m);
    932       1.1       pk #endif
    933       1.1       pk 
    934      1.49     heas #ifdef INET
    935      1.46     heas 		/* collect bits for h/w csum, before hme_put frees the mbuf */
    936      1.46     heas 		if (ifp->if_csum_flags_tx & (M_CSUM_TCPv4 | M_CSUM_UDPv4) &&
    937      1.46     heas 		    m->m_pkthdr.csum_flags & (M_CSUM_TCPv4 | M_CSUM_UDPv4)) {
    938      1.46     heas 			struct ether_header *eh;
    939      1.46     heas 			uint16_t offset, start;
    940      1.46     heas 
    941      1.46     heas 			eh = mtod(m, struct ether_header *);
    942      1.46     heas 			switch (ntohs(eh->ether_type)) {
    943      1.46     heas 			case ETHERTYPE_IP:
    944      1.46     heas 				start = ETHER_HDR_LEN;
    945      1.46     heas 				break;
    946      1.46     heas 			case ETHERTYPE_VLAN:
    947      1.46     heas 				start = ETHER_HDR_LEN + ETHER_VLAN_ENCAP_LEN;
    948      1.46     heas 				break;
    949      1.46     heas 			default:
    950      1.46     heas 				/* unsupported, drop it */
    951      1.46     heas 				m_free(m);
    952      1.46     heas 				continue;
    953      1.46     heas 			}
    954      1.47  thorpej 			start += M_CSUM_DATA_IPv4_IPHL(m->m_pkthdr.csum_data);
    955      1.47  thorpej 			offset = M_CSUM_DATA_IPv4_OFFSET(m->m_pkthdr.csum_data)
    956      1.47  thorpej 			    + start;
    957      1.46     heas 			txflags = HME_XD_TXCKSUM |
    958      1.46     heas 				  (offset << HME_XD_TXCSSTUFFSHIFT) |
    959      1.46     heas 		  		  (start << HME_XD_TXCSSTARTSHIFT);
    960      1.46     heas 		} else
    961      1.49     heas #endif
    962      1.46     heas 			txflags = 0;
    963      1.46     heas 
    964      1.28     tron 		/*
    965      1.28     tron 		 * Copy the mbuf chain into the transmit buffer.
    966      1.28     tron 		 */
    967      1.28     tron 		len = hme_put(sc, ri, m);
    968      1.28     tron 
    969      1.28     tron 		/*
    970      1.28     tron 		 * Initialize transmit registers and start transmission
    971      1.28     tron 		 */
    972      1.28     tron 		HME_XD_SETFLAGS(sc->sc_pci, txd, ri,
    973      1.28     tron 			HME_XD_OWN | HME_XD_SOP | HME_XD_EOP |
    974      1.46     heas 			HME_XD_ENCODE_TSIZE(len) | txflags);
    975      1.28     tron 
    976      1.28     tron 		/*if (sc->sc_rb.rb_td_nbusy <= 0)*/
    977      1.28     tron 		bus_space_write_4(sc->sc_bustag, sc->sc_etx, HME_ETXI_PENDING,
    978      1.28     tron 				  HME_ETX_TP_DMAWAKEUP);
    979      1.28     tron 
    980      1.28     tron 		if (++ri == ntbuf)
    981      1.28     tron 			ri = 0;
    982      1.28     tron 
    983      1.28     tron 		if (++sc->sc_rb.rb_td_nbusy == ntbuf) {
    984      1.26     tron 			ifp->if_flags |= IFF_OACTIVE;
    985      1.26     tron 			break;
    986      1.26     tron 		}
    987       1.1       pk 	}
    988       1.1       pk 
    989      1.28     tron 	sc->sc_rb.rb_tdhead = ri;
    990       1.1       pk }
    991       1.1       pk 
    992       1.1       pk /*
    993       1.1       pk  * Transmit interrupt.
    994       1.1       pk  */
    995       1.1       pk int
    996       1.1       pk hme_tint(sc)
    997       1.1       pk 	struct hme_softc *sc;
    998       1.1       pk {
    999       1.1       pk 	struct ifnet *ifp = &sc->sc_ethercom.ec_if;
   1000      1.28     tron 	bus_space_tag_t t = sc->sc_bustag;
   1001      1.28     tron 	bus_space_handle_t mac = sc->sc_mac;
   1002       1.1       pk 	unsigned int ri, txflags;
   1003      1.28     tron 
   1004      1.28     tron 	/*
   1005      1.28     tron 	 * Unload collision counters
   1006      1.28     tron 	 */
   1007      1.28     tron 	ifp->if_collisions +=
   1008      1.28     tron 		bus_space_read_4(t, mac, HME_MACI_NCCNT) +
   1009      1.28     tron 		bus_space_read_4(t, mac, HME_MACI_FCCNT) +
   1010      1.28     tron 		bus_space_read_4(t, mac, HME_MACI_EXCNT) +
   1011      1.28     tron 		bus_space_read_4(t, mac, HME_MACI_LTCNT);
   1012      1.28     tron 
   1013      1.28     tron 	/*
   1014      1.28     tron 	 * then clear the hardware counters.
   1015      1.28     tron 	 */
   1016      1.28     tron 	bus_space_write_4(t, mac, HME_MACI_NCCNT, 0);
   1017      1.28     tron 	bus_space_write_4(t, mac, HME_MACI_FCCNT, 0);
   1018      1.28     tron 	bus_space_write_4(t, mac, HME_MACI_EXCNT, 0);
   1019      1.28     tron 	bus_space_write_4(t, mac, HME_MACI_LTCNT, 0);
   1020       1.1       pk 
   1021       1.1       pk 	/* Fetch current position in the transmit ring */
   1022      1.28     tron 	ri = sc->sc_rb.rb_tdtail;
   1023       1.1       pk 
   1024       1.1       pk 	for (;;) {
   1025      1.28     tron 		if (sc->sc_rb.rb_td_nbusy <= 0)
   1026       1.1       pk 			break;
   1027       1.1       pk 
   1028      1.15      eeh 		txflags = HME_XD_GETFLAGS(sc->sc_pci, sc->sc_rb.rb_txd, ri);
   1029       1.1       pk 
   1030       1.1       pk 		if (txflags & HME_XD_OWN)
   1031       1.1       pk 			break;
   1032       1.1       pk 
   1033       1.1       pk 		ifp->if_flags &= ~IFF_OACTIVE;
   1034      1.28     tron 		ifp->if_opackets++;
   1035      1.26     tron 
   1036      1.28     tron 		if (++ri == sc->sc_rb.rb_ntbuf)
   1037       1.1       pk 			ri = 0;
   1038       1.1       pk 
   1039      1.28     tron 		--sc->sc_rb.rb_td_nbusy;
   1040       1.1       pk 	}
   1041       1.1       pk 
   1042       1.3       pk 	/* Update ring */
   1043      1.28     tron 	sc->sc_rb.rb_tdtail = ri;
   1044       1.1       pk 
   1045       1.1       pk 	hme_start(ifp);
   1046       1.1       pk 
   1047      1.28     tron 	if (sc->sc_rb.rb_td_nbusy == 0)
   1048       1.1       pk 		ifp->if_timer = 0;
   1049       1.1       pk 
   1050       1.1       pk 	return (1);
   1051       1.1       pk }
   1052       1.1       pk 
   1053       1.1       pk /*
   1054       1.1       pk  * Receive interrupt.
   1055       1.1       pk  */
   1056       1.1       pk int
   1057       1.1       pk hme_rint(sc)
   1058       1.1       pk 	struct hme_softc *sc;
   1059       1.1       pk {
   1060  1.51.2.3     yamt 	void *xdr = sc->sc_rb.rb_rxd;
   1061      1.28     tron 	unsigned int nrbuf = sc->sc_rb.rb_nrbuf;
   1062      1.46     heas 	unsigned int ri;
   1063       1.1       pk 	u_int32_t flags;
   1064       1.1       pk 
   1065      1.28     tron 	ri = sc->sc_rb.rb_rdtail;
   1066       1.1       pk 
   1067       1.1       pk 	/*
   1068       1.1       pk 	 * Process all buffers with valid data.
   1069       1.1       pk 	 */
   1070       1.1       pk 	for (;;) {
   1071      1.28     tron 		flags = HME_XD_GETFLAGS(sc->sc_pci, xdr, ri);
   1072       1.1       pk 		if (flags & HME_XD_OWN)
   1073       1.1       pk 			break;
   1074       1.1       pk 
   1075       1.4       pk 		if (flags & HME_XD_OFL) {
   1076       1.4       pk 			printf("%s: buffer overflow, ri=%d; flags=0x%x\n",
   1077      1.28     tron 					sc->sc_dev.dv_xname, ri, flags);
   1078      1.46     heas 		} else
   1079      1.46     heas 			hme_read(sc, ri, flags);
   1080       1.1       pk 
   1081      1.28     tron 		/* This buffer can be used by the hardware again */
   1082      1.28     tron 		HME_XD_SETFLAGS(sc->sc_pci, xdr, ri,
   1083      1.28     tron 				HME_XD_OWN | HME_XD_ENCODE_RSIZE(_HME_BUFSZ));
   1084      1.26     tron 
   1085      1.28     tron 		if (++ri == nrbuf)
   1086       1.1       pk 			ri = 0;
   1087       1.1       pk 	}
   1088       1.1       pk 
   1089      1.28     tron 	sc->sc_rb.rb_rdtail = ri;
   1090      1.28     tron 
   1091       1.1       pk 	return (1);
   1092       1.1       pk }
   1093       1.1       pk 
   1094       1.1       pk int
   1095       1.1       pk hme_eint(sc, status)
   1096       1.1       pk 	struct hme_softc *sc;
   1097       1.1       pk 	u_int status;
   1098       1.1       pk {
   1099       1.1       pk 	char bits[128];
   1100       1.1       pk 
   1101       1.1       pk 	if ((status & HME_SEB_STAT_MIFIRQ) != 0) {
   1102      1.33       pk 		bus_space_tag_t t = sc->sc_bustag;
   1103      1.33       pk 		bus_space_handle_t mif = sc->sc_mif;
   1104      1.33       pk 		u_int32_t cf, st, sm;
   1105      1.33       pk 		cf = bus_space_read_4(t, mif, HME_MIFI_CFG);
   1106      1.33       pk 		st = bus_space_read_4(t, mif, HME_MIFI_STAT);
   1107      1.33       pk 		sm = bus_space_read_4(t, mif, HME_MIFI_SM);
   1108      1.33       pk 		printf("%s: XXXlink status changed: cfg=%x, stat %x, sm %x\n",
   1109      1.33       pk 			sc->sc_dev.dv_xname, cf, st, sm);
   1110       1.1       pk 		return (1);
   1111       1.1       pk 	}
   1112       1.1       pk 
   1113       1.1       pk 	printf("%s: status=%s\n", sc->sc_dev.dv_xname,
   1114      1.28     tron 		bitmask_snprintf(status, HME_SEB_STAT_BITS, bits,sizeof(bits)));
   1115       1.1       pk 	return (1);
   1116       1.1       pk }
   1117       1.1       pk 
   1118       1.1       pk int
   1119       1.1       pk hme_intr(v)
   1120       1.1       pk 	void *v;
   1121       1.1       pk {
   1122       1.1       pk 	struct hme_softc *sc = (struct hme_softc *)v;
   1123       1.1       pk 	bus_space_tag_t t = sc->sc_bustag;
   1124       1.1       pk 	bus_space_handle_t seb = sc->sc_seb;
   1125       1.1       pk 	u_int32_t status;
   1126       1.1       pk 	int r = 0;
   1127       1.1       pk 
   1128       1.1       pk 	status = bus_space_read_4(t, seb, HME_SEBI_STAT);
   1129       1.1       pk 
   1130       1.1       pk 	if ((status & HME_SEB_STAT_ALL_ERRORS) != 0)
   1131       1.1       pk 		r |= hme_eint(sc, status);
   1132       1.1       pk 
   1133       1.1       pk 	if ((status & (HME_SEB_STAT_TXALL | HME_SEB_STAT_HOSTTOTX)) != 0)
   1134       1.1       pk 		r |= hme_tint(sc);
   1135       1.1       pk 
   1136       1.1       pk 	if ((status & HME_SEB_STAT_RXTOHOST) != 0)
   1137       1.1       pk 		r |= hme_rint(sc);
   1138       1.1       pk 
   1139      1.40      abs #if NRND > 0
   1140      1.40      abs 	rnd_add_uint32(&sc->rnd_source, status);
   1141      1.40      abs #endif
   1142      1.40      abs 
   1143       1.1       pk 	return (r);
   1144       1.1       pk }
   1145       1.1       pk 
   1146       1.1       pk 
   1147       1.1       pk void
   1148       1.1       pk hme_watchdog(ifp)
   1149       1.1       pk 	struct ifnet *ifp;
   1150       1.1       pk {
   1151       1.1       pk 	struct hme_softc *sc = ifp->if_softc;
   1152       1.1       pk 
   1153       1.1       pk 	log(LOG_ERR, "%s: device timeout\n", sc->sc_dev.dv_xname);
   1154       1.1       pk 	++ifp->if_oerrors;
   1155       1.1       pk 
   1156       1.1       pk 	hme_reset(sc);
   1157       1.4       pk }
   1158       1.4       pk 
   1159       1.4       pk /*
   1160       1.4       pk  * Initialize the MII Management Interface
   1161       1.4       pk  */
   1162       1.4       pk void
   1163       1.4       pk hme_mifinit(sc)
   1164       1.4       pk 	struct hme_softc *sc;
   1165       1.4       pk {
   1166       1.4       pk 	bus_space_tag_t t = sc->sc_bustag;
   1167       1.4       pk 	bus_space_handle_t mif = sc->sc_mif;
   1168      1.35       pk 	bus_space_handle_t mac = sc->sc_mac;
   1169      1.33       pk 	int instance, phy;
   1170       1.4       pk 	u_int32_t v;
   1171       1.4       pk 
   1172      1.33       pk 	if (sc->sc_media.ifm_cur != NULL) {
   1173      1.33       pk 		instance = IFM_INST(sc->sc_media.ifm_cur->ifm_media);
   1174      1.33       pk 		phy = sc->sc_phys[instance];
   1175      1.33       pk 	} else
   1176      1.33       pk 		/* No media set yet, pick phy arbitrarily.. */
   1177      1.33       pk 		phy = HME_PHYAD_EXTERNAL;
   1178      1.33       pk 
   1179      1.33       pk 	/* Configure the MIF in frame mode, no poll, current phy select */
   1180      1.33       pk 	v = 0;
   1181      1.33       pk 	if (phy == HME_PHYAD_EXTERNAL)
   1182      1.33       pk 		v |= HME_MIF_CFG_PHY;
   1183       1.4       pk 	bus_space_write_4(t, mif, HME_MIFI_CFG, v);
   1184      1.35       pk 
   1185      1.35       pk 	/* If an external transceiver is selected, enable its MII drivers */
   1186      1.35       pk 	v = bus_space_read_4(t, mac, HME_MACI_XIF);
   1187      1.35       pk 	v &= ~HME_MAC_XIF_MIIENABLE;
   1188      1.35       pk 	if (phy == HME_PHYAD_EXTERNAL)
   1189      1.35       pk 		v |= HME_MAC_XIF_MIIENABLE;
   1190      1.35       pk 	bus_space_write_4(t, mac, HME_MACI_XIF, v);
   1191       1.1       pk }
   1192       1.1       pk 
   1193       1.1       pk /*
   1194       1.1       pk  * MII interface
   1195       1.1       pk  */
   1196       1.1       pk static int
   1197       1.1       pk hme_mii_readreg(self, phy, reg)
   1198       1.1       pk 	struct device *self;
   1199       1.1       pk 	int phy, reg;
   1200       1.1       pk {
   1201       1.1       pk 	struct hme_softc *sc = (void *)self;
   1202       1.1       pk 	bus_space_tag_t t = sc->sc_bustag;
   1203       1.1       pk 	bus_space_handle_t mif = sc->sc_mif;
   1204      1.35       pk 	bus_space_handle_t mac = sc->sc_mac;
   1205      1.35       pk 	u_int32_t v, xif_cfg, mifi_cfg;
   1206       1.1       pk 	int n;
   1207       1.1       pk 
   1208      1.33       pk 	/* We can at most have two PHYs */
   1209      1.33       pk 	if (phy != HME_PHYAD_EXTERNAL && phy != HME_PHYAD_INTERNAL)
   1210      1.32   martin 		return (0);
   1211      1.32   martin 
   1212       1.5       pk 	/* Select the desired PHY in the MIF configuration register */
   1213      1.33       pk 	v = mifi_cfg = bus_space_read_4(t, mif, HME_MIFI_CFG);
   1214       1.5       pk 	v &= ~HME_MIF_CFG_PHY;
   1215       1.5       pk 	if (phy == HME_PHYAD_EXTERNAL)
   1216       1.5       pk 		v |= HME_MIF_CFG_PHY;
   1217       1.5       pk 	bus_space_write_4(t, mif, HME_MIFI_CFG, v);
   1218       1.5       pk 
   1219      1.42     heas 	/* Enable MII drivers on external transceiver */
   1220      1.35       pk 	v = xif_cfg = bus_space_read_4(t, mac, HME_MACI_XIF);
   1221      1.35       pk 	if (phy == HME_PHYAD_EXTERNAL)
   1222      1.35       pk 		v |= HME_MAC_XIF_MIIENABLE;
   1223      1.35       pk 	else
   1224      1.35       pk 		v &= ~HME_MAC_XIF_MIIENABLE;
   1225      1.35       pk 	bus_space_write_4(t, mac, HME_MACI_XIF, v);
   1226      1.35       pk 
   1227      1.33       pk #if 0
   1228      1.33       pk /* This doesn't work reliably; the MDIO_1 bit is off most of the time */
   1229      1.33       pk 	/*
   1230      1.33       pk 	 * Check whether a transceiver is connected by testing
   1231      1.33       pk 	 * the MIF configuration register's MDI_X bits. Note that
   1232      1.33       pk 	 * MDI_0 (int) == 0x100 and MDI_1 (ext) == 0x200; see hmereg.h
   1233      1.33       pk 	 */
   1234      1.33       pk 	mif_mdi_bit = 1 << (8 + (1 - phy));
   1235      1.33       pk 	delay(100);
   1236      1.33       pk 	v = bus_space_read_4(t, mif, HME_MIFI_CFG);
   1237      1.33       pk 	if ((v & mif_mdi_bit) == 0)
   1238      1.33       pk 		return (0);
   1239      1.33       pk #endif
   1240      1.33       pk 
   1241       1.1       pk 	/* Construct the frame command */
   1242       1.1       pk 	v = (MII_COMMAND_START << HME_MIF_FO_ST_SHIFT) |
   1243       1.1       pk 	    HME_MIF_FO_TAMSB |
   1244       1.1       pk 	    (MII_COMMAND_READ << HME_MIF_FO_OPC_SHIFT) |
   1245       1.1       pk 	    (phy << HME_MIF_FO_PHYAD_SHIFT) |
   1246       1.1       pk 	    (reg << HME_MIF_FO_REGAD_SHIFT);
   1247       1.1       pk 
   1248       1.1       pk 	bus_space_write_4(t, mif, HME_MIFI_FO, v);
   1249       1.1       pk 	for (n = 0; n < 100; n++) {
   1250       1.2       pk 		DELAY(1);
   1251       1.1       pk 		v = bus_space_read_4(t, mif, HME_MIFI_FO);
   1252      1.33       pk 		if (v & HME_MIF_FO_TALSB) {
   1253      1.33       pk 			v &= HME_MIF_FO_DATA;
   1254      1.33       pk 			goto out;
   1255      1.33       pk 		}
   1256       1.1       pk 	}
   1257       1.1       pk 
   1258      1.33       pk 	v = 0;
   1259       1.1       pk 	printf("%s: mii_read timeout\n", sc->sc_dev.dv_xname);
   1260      1.33       pk 
   1261      1.33       pk out:
   1262      1.33       pk 	/* Restore MIFI_CFG register */
   1263      1.33       pk 	bus_space_write_4(t, mif, HME_MIFI_CFG, mifi_cfg);
   1264      1.35       pk 	/* Restore XIF register */
   1265      1.35       pk 	bus_space_write_4(t, mac, HME_MACI_XIF, xif_cfg);
   1266      1.33       pk 	return (v);
   1267       1.1       pk }
   1268       1.1       pk 
   1269       1.1       pk static void
   1270       1.1       pk hme_mii_writereg(self, phy, reg, val)
   1271       1.1       pk 	struct device *self;
   1272       1.1       pk 	int phy, reg, val;
   1273       1.1       pk {
   1274       1.1       pk 	struct hme_softc *sc = (void *)self;
   1275       1.1       pk 	bus_space_tag_t t = sc->sc_bustag;
   1276       1.1       pk 	bus_space_handle_t mif = sc->sc_mif;
   1277      1.35       pk 	bus_space_handle_t mac = sc->sc_mac;
   1278      1.35       pk 	u_int32_t v, xif_cfg, mifi_cfg;
   1279       1.1       pk 	int n;
   1280      1.32   martin 
   1281      1.33       pk 	/* We can at most have two PHYs */
   1282      1.33       pk 	if (phy != HME_PHYAD_EXTERNAL && phy != HME_PHYAD_INTERNAL)
   1283      1.32   martin 		return;
   1284       1.1       pk 
   1285       1.5       pk 	/* Select the desired PHY in the MIF configuration register */
   1286      1.33       pk 	v = mifi_cfg = bus_space_read_4(t, mif, HME_MIFI_CFG);
   1287       1.5       pk 	v &= ~HME_MIF_CFG_PHY;
   1288       1.5       pk 	if (phy == HME_PHYAD_EXTERNAL)
   1289       1.5       pk 		v |= HME_MIF_CFG_PHY;
   1290       1.5       pk 	bus_space_write_4(t, mif, HME_MIFI_CFG, v);
   1291       1.5       pk 
   1292      1.42     heas 	/* Enable MII drivers on external transceiver */
   1293      1.35       pk 	v = xif_cfg = bus_space_read_4(t, mac, HME_MACI_XIF);
   1294      1.35       pk 	if (phy == HME_PHYAD_EXTERNAL)
   1295      1.35       pk 		v |= HME_MAC_XIF_MIIENABLE;
   1296      1.35       pk 	else
   1297      1.35       pk 		v &= ~HME_MAC_XIF_MIIENABLE;
   1298      1.35       pk 	bus_space_write_4(t, mac, HME_MACI_XIF, v);
   1299      1.35       pk 
   1300      1.33       pk #if 0
   1301      1.33       pk /* This doesn't work reliably; the MDIO_1 bit is off most of the time */
   1302      1.33       pk 	/*
   1303      1.33       pk 	 * Check whether a transceiver is connected by testing
   1304      1.33       pk 	 * the MIF configuration register's MDI_X bits. Note that
   1305      1.33       pk 	 * MDI_0 (int) == 0x100 and MDI_1 (ext) == 0x200; see hmereg.h
   1306      1.33       pk 	 */
   1307      1.33       pk 	mif_mdi_bit = 1 << (8 + (1 - phy));
   1308      1.33       pk 	delay(100);
   1309      1.33       pk 	v = bus_space_read_4(t, mif, HME_MIFI_CFG);
   1310      1.33       pk 	if ((v & mif_mdi_bit) == 0)
   1311      1.33       pk 		return;
   1312      1.33       pk #endif
   1313      1.33       pk 
   1314       1.1       pk 	/* Construct the frame command */
   1315       1.1       pk 	v = (MII_COMMAND_START << HME_MIF_FO_ST_SHIFT)	|
   1316       1.1       pk 	    HME_MIF_FO_TAMSB				|
   1317       1.1       pk 	    (MII_COMMAND_WRITE << HME_MIF_FO_OPC_SHIFT)	|
   1318       1.1       pk 	    (phy << HME_MIF_FO_PHYAD_SHIFT)		|
   1319       1.1       pk 	    (reg << HME_MIF_FO_REGAD_SHIFT)		|
   1320       1.1       pk 	    (val & HME_MIF_FO_DATA);
   1321       1.1       pk 
   1322       1.1       pk 	bus_space_write_4(t, mif, HME_MIFI_FO, v);
   1323       1.1       pk 	for (n = 0; n < 100; n++) {
   1324       1.2       pk 		DELAY(1);
   1325       1.1       pk 		v = bus_space_read_4(t, mif, HME_MIFI_FO);
   1326       1.1       pk 		if (v & HME_MIF_FO_TALSB)
   1327      1.33       pk 			goto out;
   1328       1.1       pk 	}
   1329       1.1       pk 
   1330       1.2       pk 	printf("%s: mii_write timeout\n", sc->sc_dev.dv_xname);
   1331      1.33       pk out:
   1332      1.33       pk 	/* Restore MIFI_CFG register */
   1333      1.33       pk 	bus_space_write_4(t, mif, HME_MIFI_CFG, mifi_cfg);
   1334      1.35       pk 	/* Restore XIF register */
   1335      1.35       pk 	bus_space_write_4(t, mac, HME_MACI_XIF, xif_cfg);
   1336       1.1       pk }
   1337       1.1       pk 
   1338       1.1       pk static void
   1339       1.1       pk hme_mii_statchg(dev)
   1340       1.1       pk 	struct device *dev;
   1341       1.1       pk {
   1342       1.3       pk 	struct hme_softc *sc = (void *)dev;
   1343       1.1       pk 	bus_space_tag_t t = sc->sc_bustag;
   1344       1.1       pk 	bus_space_handle_t mac = sc->sc_mac;
   1345       1.1       pk 	u_int32_t v;
   1346       1.1       pk 
   1347       1.5       pk #ifdef HMEDEBUG
   1348       1.5       pk 	if (sc->sc_debug)
   1349      1.33       pk 		printf("hme_mii_statchg: status change\n");
   1350       1.5       pk #endif
   1351       1.1       pk 
   1352       1.5       pk 	/* Set the MAC Full Duplex bit appropriately */
   1353      1.30   martin 	/* Apparently the hme chip is SIMPLEX if working in full duplex mode,
   1354      1.30   martin 	   but not otherwise. */
   1355       1.1       pk 	v = bus_space_read_4(t, mac, HME_MACI_TXCFG);
   1356      1.30   martin 	if ((IFM_OPTIONS(sc->sc_mii.mii_media_active) & IFM_FDX) != 0) {
   1357       1.1       pk 		v |= HME_MAC_TXCFG_FULLDPLX;
   1358      1.30   martin 		sc->sc_ethercom.ec_if.if_flags |= IFF_SIMPLEX;
   1359      1.30   martin 	} else {
   1360       1.1       pk 		v &= ~HME_MAC_TXCFG_FULLDPLX;
   1361      1.30   martin 		sc->sc_ethercom.ec_if.if_flags &= ~IFF_SIMPLEX;
   1362      1.30   martin 	}
   1363      1.41     heas 	sc->sc_if_flags = sc->sc_ethercom.ec_if.if_flags;
   1364       1.1       pk 	bus_space_write_4(t, mac, HME_MACI_TXCFG, v);
   1365       1.5       pk }
   1366       1.5       pk 
   1367       1.5       pk int
   1368       1.5       pk hme_mediachange(ifp)
   1369       1.5       pk 	struct ifnet *ifp;
   1370       1.5       pk {
   1371       1.5       pk 	struct hme_softc *sc = ifp->if_softc;
   1372      1.33       pk 	bus_space_tag_t t = sc->sc_bustag;
   1373      1.33       pk 	bus_space_handle_t mif = sc->sc_mif;
   1374      1.33       pk 	bus_space_handle_t mac = sc->sc_mac;
   1375      1.33       pk 	int instance = IFM_INST(sc->sc_mii.mii_media.ifm_cur->ifm_media);
   1376      1.33       pk 	int phy = sc->sc_phys[instance];
   1377      1.33       pk 	u_int32_t v;
   1378       1.5       pk 
   1379      1.33       pk #ifdef HMEDEBUG
   1380      1.33       pk 	if (sc->sc_debug)
   1381      1.33       pk 		printf("hme_mediachange: phy = %d\n", phy);
   1382      1.33       pk #endif
   1383       1.5       pk 	if (IFM_TYPE(sc->sc_media.ifm_media) != IFM_ETHER)
   1384       1.5       pk 		return (EINVAL);
   1385      1.33       pk 
   1386      1.33       pk 	/* Select the current PHY in the MIF configuration register */
   1387      1.33       pk 	v = bus_space_read_4(t, mif, HME_MIFI_CFG);
   1388      1.33       pk 	v &= ~HME_MIF_CFG_PHY;
   1389      1.33       pk 	if (phy == HME_PHYAD_EXTERNAL)
   1390      1.33       pk 		v |= HME_MIF_CFG_PHY;
   1391      1.33       pk 	bus_space_write_4(t, mif, HME_MIFI_CFG, v);
   1392      1.33       pk 
   1393      1.33       pk 	/* If an external transceiver is selected, enable its MII drivers */
   1394      1.33       pk 	v = bus_space_read_4(t, mac, HME_MACI_XIF);
   1395      1.33       pk 	v &= ~HME_MAC_XIF_MIIENABLE;
   1396      1.33       pk 	if (phy == HME_PHYAD_EXTERNAL)
   1397      1.33       pk 		v |= HME_MAC_XIF_MIIENABLE;
   1398      1.33       pk 	bus_space_write_4(t, mac, HME_MACI_XIF, v);
   1399       1.5       pk 
   1400       1.5       pk 	return (mii_mediachg(&sc->sc_mii));
   1401       1.1       pk }
   1402       1.1       pk 
   1403       1.1       pk void
   1404       1.1       pk hme_mediastatus(ifp, ifmr)
   1405       1.1       pk 	struct ifnet *ifp;
   1406       1.1       pk 	struct ifmediareq *ifmr;
   1407       1.1       pk {
   1408       1.1       pk 	struct hme_softc *sc = ifp->if_softc;
   1409       1.1       pk 
   1410       1.1       pk 	if ((ifp->if_flags & IFF_UP) == 0)
   1411       1.1       pk 		return;
   1412       1.1       pk 
   1413       1.1       pk 	mii_pollstat(&sc->sc_mii);
   1414       1.1       pk 	ifmr->ifm_active = sc->sc_mii.mii_media_active;
   1415       1.1       pk 	ifmr->ifm_status = sc->sc_mii.mii_media_status;
   1416       1.1       pk }
   1417       1.1       pk 
   1418       1.1       pk /*
   1419       1.1       pk  * Process an ioctl request.
   1420       1.1       pk  */
   1421       1.1       pk int
   1422       1.1       pk hme_ioctl(ifp, cmd, data)
   1423       1.1       pk 	struct ifnet *ifp;
   1424       1.1       pk 	u_long cmd;
   1425  1.51.2.3     yamt 	void *data;
   1426       1.1       pk {
   1427       1.1       pk 	struct hme_softc *sc = ifp->if_softc;
   1428       1.1       pk 	struct ifaddr *ifa = (struct ifaddr *)data;
   1429       1.1       pk 	struct ifreq *ifr = (struct ifreq *)data;
   1430       1.1       pk 	int s, error = 0;
   1431       1.1       pk 
   1432       1.1       pk 	s = splnet();
   1433       1.1       pk 
   1434       1.1       pk 	switch (cmd) {
   1435       1.1       pk 
   1436       1.1       pk 	case SIOCSIFADDR:
   1437       1.1       pk 		switch (ifa->ifa_addr->sa_family) {
   1438       1.1       pk #ifdef INET
   1439       1.1       pk 		case AF_INET:
   1440      1.41     heas 			if (ifp->if_flags & IFF_UP)
   1441      1.41     heas 				hme_setladrf(sc);
   1442      1.41     heas 			else {
   1443      1.41     heas 				ifp->if_flags |= IFF_UP;
   1444      1.41     heas 				hme_init(sc);
   1445      1.41     heas 			}
   1446       1.1       pk 			arp_ifinit(ifp, ifa);
   1447       1.1       pk 			break;
   1448       1.1       pk #endif
   1449       1.1       pk 		default:
   1450      1.41     heas 			ifp->if_flags |= IFF_UP;
   1451       1.1       pk 			hme_init(sc);
   1452       1.1       pk 			break;
   1453       1.1       pk 		}
   1454       1.1       pk 		break;
   1455       1.1       pk 
   1456       1.1       pk 	case SIOCSIFFLAGS:
   1457      1.45     heas #ifdef HMEDEBUG
   1458      1.45     heas 		sc->sc_debug = (ifp->if_flags & IFF_DEBUG) != 0 ? 1 : 0;
   1459      1.45     heas #endif
   1460      1.45     heas 
   1461       1.1       pk 		if ((ifp->if_flags & IFF_UP) == 0 &&
   1462       1.1       pk 		    (ifp->if_flags & IFF_RUNNING) != 0) {
   1463       1.1       pk 			/*
   1464       1.1       pk 			 * If interface is marked down and it is running, then
   1465       1.1       pk 			 * stop it.
   1466       1.1       pk 			 */
   1467  1.51.2.3     yamt 			hme_stop(sc, false);
   1468       1.1       pk 			ifp->if_flags &= ~IFF_RUNNING;
   1469       1.1       pk 		} else if ((ifp->if_flags & IFF_UP) != 0 &&
   1470       1.1       pk 		    	   (ifp->if_flags & IFF_RUNNING) == 0) {
   1471       1.1       pk 			/*
   1472       1.1       pk 			 * If interface is marked up and it is stopped, then
   1473       1.1       pk 			 * start it.
   1474       1.1       pk 			 */
   1475       1.1       pk 			hme_init(sc);
   1476       1.1       pk 		} else if ((ifp->if_flags & IFF_UP) != 0) {
   1477       1.1       pk 			/*
   1478      1.41     heas 			 * If setting debug or promiscuous mode, do not reset
   1479      1.41     heas 			 * the chip; for everything else, call hme_init()
   1480      1.41     heas 			 * which will trigger a reset.
   1481       1.1       pk 			 */
   1482      1.41     heas #define RESETIGN (IFF_CANTCHANGE | IFF_DEBUG)
   1483      1.46     heas 			if (ifp->if_flags != sc->sc_if_flags) {
   1484      1.45     heas 				if ((ifp->if_flags & (~RESETIGN))
   1485      1.45     heas 				    == (sc->sc_if_flags & (~RESETIGN)))
   1486      1.45     heas 					hme_setladrf(sc);
   1487      1.45     heas 				else
   1488      1.45     heas 					hme_init(sc);
   1489      1.45     heas 			}
   1490      1.41     heas #undef RESETIGN
   1491       1.1       pk 		}
   1492      1.45     heas 
   1493      1.45     heas 		if (sc->sc_ec_capenable != sc->sc_ethercom.ec_capenable)
   1494      1.45     heas 			hme_init(sc);
   1495      1.45     heas 
   1496       1.1       pk 		break;
   1497       1.1       pk 
   1498       1.1       pk 	case SIOCADDMULTI:
   1499       1.1       pk 	case SIOCDELMULTI:
   1500  1.51.2.3     yamt 		if ((error = ether_ioctl(ifp, cmd, data)) == ENETRESET) {
   1501       1.1       pk 			/*
   1502       1.1       pk 			 * Multicast list has changed; set the hardware filter
   1503       1.1       pk 			 * accordingly.
   1504       1.1       pk 			 */
   1505      1.43  thorpej 			if (ifp->if_flags & IFF_RUNNING)
   1506      1.43  thorpej 				hme_setladrf(sc);
   1507       1.1       pk 			error = 0;
   1508       1.1       pk 		}
   1509       1.1       pk 		break;
   1510       1.1       pk 
   1511       1.1       pk 	case SIOCGIFMEDIA:
   1512       1.1       pk 	case SIOCSIFMEDIA:
   1513       1.1       pk 		error = ifmedia_ioctl(ifp, ifr, &sc->sc_media, cmd);
   1514       1.1       pk 		break;
   1515       1.1       pk 
   1516       1.1       pk 	default:
   1517       1.1       pk 		error = EINVAL;
   1518       1.1       pk 		break;
   1519       1.1       pk 	}
   1520       1.1       pk 
   1521      1.41     heas 	sc->sc_if_flags = ifp->if_flags;
   1522       1.1       pk 	splx(s);
   1523       1.1       pk 	return (error);
   1524       1.1       pk }
   1525       1.1       pk 
   1526       1.1       pk void
   1527       1.1       pk hme_shutdown(arg)
   1528       1.1       pk 	void *arg;
   1529       1.1       pk {
   1530      1.28     tron 
   1531  1.51.2.3     yamt 	hme_stop((struct hme_softc *)arg, false);
   1532       1.1       pk }
   1533       1.1       pk 
   1534       1.1       pk /*
   1535       1.1       pk  * Set up the logical address filter.
   1536       1.1       pk  */
   1537       1.1       pk void
   1538       1.1       pk hme_setladrf(sc)
   1539       1.1       pk 	struct hme_softc *sc;
   1540       1.1       pk {
   1541       1.1       pk 	struct ifnet *ifp = &sc->sc_ethercom.ec_if;
   1542       1.1       pk 	struct ether_multi *enm;
   1543       1.1       pk 	struct ether_multistep step;
   1544      1.28     tron 	struct ethercom *ec = &sc->sc_ethercom;
   1545       1.1       pk 	bus_space_tag_t t = sc->sc_bustag;
   1546       1.1       pk 	bus_space_handle_t mac = sc->sc_mac;
   1547       1.1       pk 	u_char *cp;
   1548       1.1       pk 	u_int32_t crc;
   1549       1.1       pk 	u_int32_t hash[4];
   1550      1.14       pk 	u_int32_t v;
   1551       1.1       pk 	int len;
   1552       1.1       pk 
   1553      1.14       pk 	/* Clear hash table */
   1554      1.14       pk 	hash[3] = hash[2] = hash[1] = hash[0] = 0;
   1555      1.14       pk 
   1556      1.14       pk 	/* Get current RX configuration */
   1557      1.14       pk 	v = bus_space_read_4(t, mac, HME_MACI_RXCFG);
   1558      1.14       pk 
   1559      1.14       pk 	if ((ifp->if_flags & IFF_PROMISC) != 0) {
   1560      1.14       pk 		/* Turn on promiscuous mode; turn off the hash filter */
   1561      1.14       pk 		v |= HME_MAC_RXCFG_PMISC;
   1562      1.14       pk 		v &= ~HME_MAC_RXCFG_HENABLE;
   1563      1.14       pk 		ifp->if_flags |= IFF_ALLMULTI;
   1564      1.14       pk 		goto chipit;
   1565      1.14       pk 	}
   1566      1.14       pk 
   1567      1.14       pk 	/* Turn off promiscuous mode; turn on the hash filter */
   1568      1.14       pk 	v &= ~HME_MAC_RXCFG_PMISC;
   1569      1.14       pk 	v |= HME_MAC_RXCFG_HENABLE;
   1570      1.14       pk 
   1571       1.1       pk 	/*
   1572       1.1       pk 	 * Set up multicast address filter by passing all multicast addresses
   1573       1.1       pk 	 * through a crc generator, and then using the high order 6 bits as an
   1574       1.1       pk 	 * index into the 64 bit logical address filter.  The high order bit
   1575       1.1       pk 	 * selects the word, while the rest of the bits select the bit within
   1576       1.1       pk 	 * the word.
   1577       1.1       pk 	 */
   1578       1.1       pk 
   1579      1.28     tron 	ETHER_FIRST_MULTI(step, ec, enm);
   1580       1.1       pk 	while (enm != NULL) {
   1581      1.28     tron 		if (ether_cmp(enm->enm_addrlo, enm->enm_addrhi)) {
   1582       1.1       pk 			/*
   1583       1.1       pk 			 * We must listen to a range of multicast addresses.
   1584       1.1       pk 			 * For now, just accept all multicasts, rather than
   1585       1.1       pk 			 * trying to set only those filter bits needed to match
   1586       1.1       pk 			 * the range.  (At this time, the only use of address
   1587       1.1       pk 			 * ranges is for IP multicast routing, for which the
   1588       1.1       pk 			 * range is big enough to require all bits set.)
   1589       1.1       pk 			 */
   1590      1.14       pk 			hash[3] = hash[2] = hash[1] = hash[0] = 0xffff;
   1591      1.14       pk 			ifp->if_flags |= IFF_ALLMULTI;
   1592      1.14       pk 			goto chipit;
   1593       1.1       pk 		}
   1594       1.1       pk 
   1595       1.1       pk 		cp = enm->enm_addrlo;
   1596       1.1       pk 		crc = 0xffffffff;
   1597       1.1       pk 		for (len = sizeof(enm->enm_addrlo); --len >= 0;) {
   1598       1.1       pk 			int octet = *cp++;
   1599       1.1       pk 			int i;
   1600       1.1       pk 
   1601       1.1       pk #define MC_POLY_LE	0xedb88320UL	/* mcast crc, little endian */
   1602       1.1       pk 			for (i = 0; i < 8; i++) {
   1603       1.1       pk 				if ((crc & 1) ^ (octet & 1)) {
   1604       1.1       pk 					crc >>= 1;
   1605       1.1       pk 					crc ^= MC_POLY_LE;
   1606       1.1       pk 				} else {
   1607       1.1       pk 					crc >>= 1;
   1608       1.1       pk 				}
   1609       1.1       pk 				octet >>= 1;
   1610       1.1       pk 			}
   1611       1.1       pk 		}
   1612       1.1       pk 		/* Just want the 6 most significant bits. */
   1613       1.1       pk 		crc >>= 26;
   1614       1.1       pk 
   1615       1.1       pk 		/* Set the corresponding bit in the filter. */
   1616       1.1       pk 		hash[crc >> 4] |= 1 << (crc & 0xf);
   1617       1.1       pk 
   1618       1.1       pk 		ETHER_NEXT_MULTI(step, enm);
   1619       1.1       pk 	}
   1620       1.1       pk 
   1621      1.14       pk 	ifp->if_flags &= ~IFF_ALLMULTI;
   1622      1.14       pk 
   1623      1.14       pk chipit:
   1624      1.14       pk 	/* Now load the hash table into the chip */
   1625       1.1       pk 	bus_space_write_4(t, mac, HME_MACI_HASHTAB0, hash[0]);
   1626       1.1       pk 	bus_space_write_4(t, mac, HME_MACI_HASHTAB1, hash[1]);
   1627       1.1       pk 	bus_space_write_4(t, mac, HME_MACI_HASHTAB2, hash[2]);
   1628       1.1       pk 	bus_space_write_4(t, mac, HME_MACI_HASHTAB3, hash[3]);
   1629      1.14       pk 	bus_space_write_4(t, mac, HME_MACI_RXCFG, v);
   1630       1.1       pk }
   1631       1.1       pk 
   1632      1.28     tron /*
   1633      1.28     tron  * Routines for accessing the transmit and receive buffers.
   1634      1.28     tron  * The various CPU and adapter configurations supported by this
   1635      1.28     tron  * driver require three different access methods for buffers
   1636      1.28     tron  * and descriptors:
   1637      1.28     tron  *	(1) contig (contiguous data; no padding),
   1638      1.28     tron  *	(2) gap2 (two bytes of data followed by two bytes of padding),
   1639      1.28     tron  *	(3) gap16 (16 bytes of data followed by 16 bytes of padding).
   1640      1.28     tron  */
   1641      1.28     tron 
   1642      1.28     tron #if 0
   1643      1.28     tron /*
   1644      1.28     tron  * contig: contiguous data with no padding.
   1645      1.28     tron  *
   1646      1.28     tron  * Buffers may have any alignment.
   1647      1.28     tron  */
   1648      1.28     tron 
   1649      1.28     tron void
   1650      1.28     tron hme_copytobuf_contig(sc, from, ri, len)
   1651      1.26     tron 	struct hme_softc *sc;
   1652      1.28     tron 	void *from;
   1653      1.28     tron 	int ri, len;
   1654      1.26     tron {
   1655  1.51.2.3     yamt 	volatile void *buf = sc->sc_rb.rb_txbuf + (ri * _HME_BUFSZ);
   1656      1.26     tron 
   1657       1.1       pk 	/*
   1658      1.28     tron 	 * Just call memcpy() to do the work.
   1659       1.1       pk 	 */
   1660      1.28     tron 	memcpy(buf, from, len);
   1661       1.1       pk }
   1662       1.1       pk 
   1663      1.28     tron void
   1664      1.28     tron hme_copyfrombuf_contig(sc, to, boff, len)
   1665       1.1       pk 	struct hme_softc *sc;
   1666      1.28     tron 	void *to;
   1667      1.28     tron 	int boff, len;
   1668       1.1       pk {
   1669  1.51.2.3     yamt 	volatile void *buf = sc->sc_rb.rb_rxbuf + (ri * _HME_BUFSZ);
   1670      1.26     tron 
   1671      1.28     tron 	/*
   1672      1.28     tron 	 * Just call memcpy() to do the work.
   1673      1.28     tron 	 */
   1674      1.28     tron 	memcpy(to, buf, len);
   1675       1.1       pk }
   1676      1.28     tron #endif
   1677