Home | History | Annotate | Line # | Download | only in dev
if_le.c revision 1.26
      1  1.26    veego /*	$NetBSD: if_le.c,v 1.26 1997/03/27 21:15:13 veego Exp $	*/
      2   1.7      cgd 
      3  1.15   chopps /*-
      4  1.26    veego  * Copyright (c) 1997 Jason R. Thorpe and Bernd Ernesti.  All rights reserved.
      5  1.15   chopps  * Copyright (c) 1995 Charles M. Hannum.  All rights reserved.
      6  1.15   chopps  * Copyright (c) 1992, 1993
      7  1.15   chopps  *	The Regents of the University of California.  All rights reserved.
      8  1.15   chopps  *
      9  1.15   chopps  * This code is derived from software contributed to Berkeley by
     10  1.15   chopps  * Ralph Campbell and Rick Macklem.
     11   1.1       mw  *
     12   1.1       mw  * Redistribution and use in source and binary forms, with or without
     13   1.1       mw  * modification, are permitted provided that the following conditions
     14   1.1       mw  * are met:
     15   1.1       mw  * 1. Redistributions of source code must retain the above copyright
     16   1.1       mw  *    notice, this list of conditions and the following disclaimer.
     17   1.1       mw  * 2. Redistributions in binary form must reproduce the above copyright
     18   1.1       mw  *    notice, this list of conditions and the following disclaimer in the
     19   1.1       mw  *    documentation and/or other materials provided with the distribution.
     20   1.1       mw  * 3. All advertising materials mentioning features or use of this software
     21   1.1       mw  *    must display the following acknowledgement:
     22  1.26    veego  *	This product includes software developed for the NetBSD Project
     23  1.26    veego  *	by Bernd Ernesti and Jason R. Thorpe.
     24   1.1       mw  *	This product includes software developed by the University of
     25   1.1       mw  *	California, Berkeley and its contributors.
     26   1.1       mw  * 4. Neither the name of the University nor the names of its contributors
     27   1.1       mw  *    may be used to endorse or promote products derived from this software
     28   1.1       mw  *    without specific prior written permission.
     29   1.1       mw  *
     30   1.1       mw  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     31   1.1       mw  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     32   1.1       mw  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     33   1.1       mw  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     34   1.1       mw  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     35   1.1       mw  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     36   1.1       mw  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     37   1.1       mw  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     38   1.1       mw  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     39   1.1       mw  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     40   1.1       mw  * SUCH DAMAGE.
     41   1.1       mw  *
     42  1.15   chopps  *	@(#)if_le.c	8.2 (Berkeley) 11/16/93
     43   1.1       mw  */
     44   1.1       mw 
     45   1.1       mw #include "bpfilter.h"
     46   1.1       mw 
     47   1.5   chopps #include <sys/param.h>
     48   1.5   chopps #include <sys/systm.h>
     49   1.5   chopps #include <sys/mbuf.h>
     50  1.15   chopps #include <sys/syslog.h>
     51   1.5   chopps #include <sys/socket.h>
     52   1.6   chopps #include <sys/device.h>
     53   1.5   chopps 
     54   1.5   chopps #include <net/if.h>
     55  1.23       is #include <net/if_ether.h>
     56  1.24  thorpej #include <net/if_media.h>
     57   1.1       mw 
     58   1.1       mw #ifdef INET
     59   1.5   chopps #include <netinet/in.h>
     60  1.23       is #include <netinet/if_inarp.h>
     61   1.1       mw #endif
     62   1.1       mw 
     63   1.5   chopps #include <machine/cpu.h>
     64   1.5   chopps #include <machine/mtpr.h>
     65  1.15   chopps 
     66   1.6   chopps #include <amiga/amiga/device.h>
     67  1.10   chopps #include <amiga/amiga/isr.h>
     68  1.21  thorpej 
     69  1.21  thorpej #include <dev/ic/am7990reg.h>
     70  1.21  thorpej #include <dev/ic/am7990var.h>
     71  1.21  thorpej 
     72   1.9   chopps #include <amiga/dev/zbusvar.h>
     73  1.15   chopps #include <amiga/dev/if_levar.h>
     74   1.6   chopps 
     75  1.22    veego int le_zbus_match __P((struct device *, struct cfdata *, void *));
     76  1.17  thorpej void le_zbus_attach __P((struct device *, struct device *, void *));
     77   1.6   chopps 
     78  1.17  thorpej struct cfattach le_zbus_ca = {
     79  1.17  thorpej 	sizeof(struct le_softc), le_zbus_match, le_zbus_attach
     80  1.17  thorpej };
     81  1.17  thorpej 
     82  1.26    veego hide void lepcnet_reset __P((struct am7990_softc *));
     83  1.21  thorpej hide void lewrcsr __P((struct am7990_softc *, u_int16_t, u_int16_t));
     84  1.21  thorpej hide u_int16_t lerdcsr __P((struct am7990_softc *, u_int16_t));
     85   1.6   chopps 
     86  1.26    veego hide u_int16_t ariadne_swapreg __P((u_int16_t));
     87  1.26    veego hide void ariadne_wrcsr __P((struct am7990_softc *, u_int16_t, u_int16_t));
     88  1.26    veego hide u_int16_t ariadne_rdcsr __P((struct am7990_softc *, u_int16_t));
     89  1.26    veego hide void ariadne_wribcr __P((struct am7990_softc *, u_int16_t, u_int16_t));
     90  1.26    veego integrate void ariadne_copytodesc_word __P((struct am7990_softc *, void *, int, int));
     91  1.26    veego integrate void ariadne_copyfromdesc_word __P((struct am7990_softc *, void *, int, int));
     92  1.26    veego integrate void ariadne_copytobuf_word __P((struct am7990_softc *, void *, int, int));
     93  1.26    veego integrate void ariadne_copyfrombuf_word __P((struct am7990_softc *, void *, int, int));
     94  1.26    veego integrate void ariadne_zerobuf_word __P((struct am7990_softc *, int, int));
     95  1.26    veego void ariadne_autoselect __P((struct am7990_softc *, int));
     96  1.26    veego int ariadne_mediachange __P((struct am7990_softc *));
     97  1.26    veego void ariadne_hwinit __P((struct am7990_softc *));
     98  1.26    veego 
     99  1.26    veego /*
    100  1.26    veego  * Media types supported by the Ariadne.
    101  1.26    veego  */
    102  1.26    veego int lemedia_ariadne[] = {
    103  1.26    veego 	IFM_ETHER | IFM_10_T,
    104  1.26    veego 	IFM_ETHER | IFM_10_2,
    105  1.26    veego 	IFM_ETHER | IFM_AUTO,
    106  1.26    veego };
    107  1.26    veego #define NLEMEDIA_ARIADNE (sizeof(lemedia_ariadne) / sizeof(lemedia_ariadne[0]))
    108  1.26    veego 
    109  1.26    veego 
    110  1.26    veego hide u_int16_t
    111  1.26    veego ariadne_swapreg(val)
    112  1.26    veego 	u_int16_t val;
    113  1.26    veego {
    114  1.26    veego 
    115  1.26    veego 	return (((val & 0xff) << 8 ) | (( val >> 8) & 0xff));
    116  1.26    veego }
    117  1.26    veego 
    118  1.26    veego hide void
    119  1.26    veego ariadne_wrcsr(sc, port, val)
    120  1.26    veego 	struct am7990_softc *sc;
    121  1.26    veego 	u_int16_t port, val;
    122  1.26    veego {
    123  1.26    veego 	struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1;
    124  1.26    veego 
    125  1.26    veego 	ler1->ler1_rap = ariadne_swapreg(port);
    126  1.26    veego 	ler1->ler1_rdp = ariadne_swapreg(val);
    127  1.26    veego }
    128  1.26    veego 
    129  1.26    veego hide u_int16_t
    130  1.26    veego ariadne_rdcsr(sc, port)
    131  1.26    veego 	struct am7990_softc *sc;
    132  1.26    veego 	u_int16_t port;
    133  1.26    veego {
    134  1.26    veego 	struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1;
    135  1.26    veego 	u_int16_t val;
    136  1.26    veego 
    137  1.26    veego 	ler1->ler1_rap = ariadne_swapreg(port);
    138  1.26    veego 	val = ariadne_swapreg(ler1->ler1_rdp);
    139  1.26    veego 	return (val);
    140  1.26    veego }
    141  1.26    veego 
    142  1.26    veego hide void
    143  1.26    veego ariadne_wribcr(sc, port, val)
    144  1.26    veego 	struct am7990_softc *sc;
    145  1.26    veego 	u_int16_t port, val;
    146  1.26    veego {
    147  1.26    veego 	struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1;
    148  1.26    veego 
    149  1.26    veego 	ler1->ler1_rap = ariadne_swapreg(port);
    150  1.26    veego 	ler1->ler1_idp = ariadne_swapreg(val);
    151  1.26    veego }
    152  1.26    veego 
    153  1.21  thorpej hide void
    154  1.15   chopps lewrcsr(sc, port, val)
    155  1.21  thorpej 	struct am7990_softc *sc;
    156  1.15   chopps 	u_int16_t port, val;
    157  1.15   chopps {
    158  1.21  thorpej 	struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1;
    159   1.6   chopps 
    160  1.15   chopps 	ler1->ler1_rap = port;
    161  1.15   chopps 	ler1->ler1_rdp = val;
    162  1.15   chopps }
    163   1.6   chopps 
    164  1.21  thorpej hide u_int16_t
    165  1.15   chopps lerdcsr(sc, port)
    166  1.21  thorpej 	struct am7990_softc *sc;
    167  1.15   chopps 	u_int16_t port;
    168   1.6   chopps {
    169  1.21  thorpej 	struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1;
    170  1.15   chopps 	u_int16_t val;
    171   1.6   chopps 
    172  1.15   chopps 	ler1->ler1_rap = port;
    173  1.15   chopps 	val = ler1->ler1_rdp;
    174  1.15   chopps 	return (val);
    175  1.15   chopps }
    176   1.6   chopps 
    177  1.26    veego hide void
    178  1.26    veego lepcnet_reset(sc)
    179  1.26    veego 	struct am7990_softc *sc;
    180  1.26    veego {
    181  1.26    veego 	struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1;
    182  1.26    veego 	volatile int dummy;
    183  1.26    veego 
    184  1.26    veego 	dummy = ler1->ler1_reset;	/* Reset PCNet-ISA */
    185  1.26    veego }
    186  1.26    veego 
    187  1.26    veego void
    188  1.26    veego ariadne_autoselect(sc, on)
    189  1.26    veego 	struct am7990_softc *sc;
    190  1.26    veego 	int on;
    191  1.26    veego {
    192  1.26    veego 
    193  1.26    veego 	/*
    194  1.26    veego 	 * on = 0: autoselect disabled
    195  1.26    veego 	 * on = 1: autoselect enabled
    196  1.26    veego 	 */
    197  1.26    veego 	if (on == 0)
    198  1.26    veego 		ariadne_wribcr(sc, LE_BCR_MC, 0x0000);
    199  1.26    veego 	else
    200  1.26    veego 		ariadne_wribcr(sc, LE_BCR_MC, LE_MC_ASEL);
    201  1.26    veego }
    202  1.26    veego 
    203  1.26    veego int
    204  1.26    veego ariadne_mediachange(sc)
    205  1.26    veego 	struct am7990_softc *sc;
    206  1.26    veego {
    207  1.26    veego 	struct ifmedia *ifm = &sc->sc_media;
    208  1.26    veego 
    209  1.26    veego 	if (IFM_TYPE(ifm->ifm_media) != IFM_ETHER)
    210  1.26    veego 		return (EINVAL);
    211  1.26    veego 
    212  1.26    veego 	/*
    213  1.26    veego 	 * Switch to the selected media.  If autoselect is
    214  1.26    veego 	 * set, switch it on otherwise disable it.  We'll
    215  1.26    veego 	 * switch to the other media when we detect loss of
    216  1.26    veego 	 * carrier.
    217  1.26    veego 	 */
    218  1.26    veego 	switch (IFM_SUBTYPE(ifm->ifm_media)) {
    219  1.26    veego 	    case IFM_10_T:
    220  1.26    veego 		sc->sc_initmodemedia = 1;
    221  1.26    veego 		am7990_init(sc);
    222  1.26    veego 		break;
    223  1.26    veego 
    224  1.26    veego 	    case IFM_10_2:
    225  1.26    veego 		sc->sc_initmodemedia = 0;
    226  1.26    veego 		am7990_init(sc);
    227  1.26    veego 		break;
    228  1.26    veego 
    229  1.26    veego 	    case IFM_AUTO:
    230  1.26    veego 		sc->sc_initmodemedia = 2;
    231  1.26    veego 		ariadne_hwinit(sc);
    232  1.26    veego 		break;
    233  1.26    veego 
    234  1.26    veego 	    default:
    235  1.26    veego 		return (EINVAL);
    236  1.26    veego 	}
    237  1.26    veego 
    238  1.26    veego 	return (0);
    239  1.26    veego }
    240  1.26    veego 
    241  1.26    veego void
    242  1.26    veego ariadne_hwinit(sc)
    243  1.26    veego 	struct am7990_softc *sc;
    244  1.26    veego {
    245  1.26    veego 
    246  1.26    veego 	/*
    247  1.26    veego 	 * Re-program LEDs to match meaning used on the Ariadne board.
    248  1.26    veego          */
    249  1.26    veego 	ariadne_wribcr(sc, LE_BCR_LED1, 0x0090);
    250  1.26    veego 	ariadne_wribcr(sc, LE_BCR_LED2, 0x0081);
    251  1.26    veego 	ariadne_wribcr(sc, LE_BCR_LED3, 0x0084);
    252  1.26    veego 
    253  1.26    veego 	/*
    254  1.26    veego 	 * Enabel/Disable auto selection
    255  1.26    veego 	 */
    256  1.26    veego 	if (sc->sc_initmodemedia == 2)
    257  1.26    veego 		ariadne_autoselect(sc, 1);
    258  1.26    veego 	else
    259  1.26    veego 		ariadne_autoselect(sc, 0);
    260  1.26    veego }
    261  1.26    veego 
    262  1.15   chopps int
    263  1.22    veego le_zbus_match(parent, cfp, aux)
    264  1.15   chopps 	struct device *parent;
    265  1.22    veego 	struct cfdata *cfp;
    266  1.22    veego 	void *aux;
    267  1.15   chopps {
    268  1.15   chopps 	struct zbus_args *zap = aux;
    269   1.6   chopps 
    270   1.6   chopps 	/* Commodore ethernet card */
    271  1.15   chopps 	if (zap->manid == 514 && zap->prodid == 112)
    272  1.15   chopps 		return (1);
    273   1.6   chopps 
    274   1.6   chopps 	/* Ameristar ethernet card */
    275  1.15   chopps 	if (zap->manid == 1053 && zap->prodid == 1)
    276  1.15   chopps 		return (1);
    277   1.6   chopps 
    278  1.26    veego 	/* Ariadne ethernet card */
    279  1.26    veego 	if (zap->manid == 2167 && zap->prodid == 201)
    280  1.26    veego 		return (1);
    281  1.26    veego 
    282   1.6   chopps 	return (0);
    283   1.6   chopps }
    284   1.1       mw 
    285   1.6   chopps void
    286  1.17  thorpej le_zbus_attach(parent, self, aux)
    287  1.15   chopps 	struct device *parent, *self;
    288  1.15   chopps 	void *aux;
    289   1.1       mw {
    290  1.21  thorpej 	struct le_softc *lesc = (struct le_softc *)self;
    291  1.21  thorpej 	struct am7990_softc *sc = &lesc->sc_am7990;
    292  1.15   chopps 	struct zbus_args *zap = aux;
    293  1.15   chopps 	u_long ser;
    294   1.1       mw 
    295  1.26    veego 	/* This has no effect on PCnet-ISA LANCE chips */
    296  1.15   chopps 	sc->sc_conf3 = LE_C3_BSWP;
    297   1.6   chopps 
    298   1.6   chopps 	/*
    299   1.6   chopps 	 * Manufacturer decides the 3 first bytes, i.e. ethernet vendor ID.
    300   1.6   chopps 	 */
    301  1.15   chopps 	switch (zap->manid) {
    302  1.26    veego 	    case 514:
    303  1.15   chopps 		/* Commodore */
    304  1.15   chopps 		sc->sc_memsize = 32768;
    305  1.23       is 		sc->sc_enaddr[0] = 0x00;
    306  1.23       is 		sc->sc_enaddr[1] = 0x80;
    307  1.23       is 		sc->sc_enaddr[2] = 0x10;
    308  1.26    veego 		lesc->sc_r1 = (struct lereg1 *)(0x4000 + (int)zap->va);
    309  1.26    veego 		sc->sc_mem = (void *)(0x8000 + (int)zap->va);
    310  1.26    veego 		sc->sc_addr = 0x8000;
    311  1.26    veego 		sc->sc_copytodesc = am7990_copytobuf_contig;
    312  1.26    veego 		sc->sc_copyfromdesc = am7990_copyfrombuf_contig;
    313  1.26    veego 		sc->sc_copytobuf = am7990_copytobuf_contig;
    314  1.26    veego 		sc->sc_copyfrombuf = am7990_copyfrombuf_contig;
    315  1.26    veego 		sc->sc_zerobuf = am7990_zerobuf_contig;
    316  1.26    veego 		sc->sc_rdcsr = lerdcsr;
    317  1.26    veego 		sc->sc_wrcsr = lewrcsr;
    318  1.26    veego 		sc->sc_hwreset = NULL;
    319  1.26    veego 		sc->sc_hwinit = NULL;
    320  1.15   chopps 		break;
    321   1.6   chopps 
    322  1.26    veego 	    case 1053:
    323  1.15   chopps 		/* Ameristar */
    324  1.15   chopps 		sc->sc_memsize = 32768;
    325  1.23       is 		sc->sc_enaddr[0] = 0x00;
    326  1.23       is 		sc->sc_enaddr[1] = 0x00;
    327  1.23       is 		sc->sc_enaddr[2] = 0x9f;
    328  1.26    veego 		lesc->sc_r1 = (struct lereg1 *)(0x4000 + (int)zap->va);
    329  1.26    veego 		sc->sc_mem = (void *)(0x8000 + (int)zap->va);
    330  1.26    veego 		sc->sc_addr = 0x8000;
    331  1.26    veego 		sc->sc_copytodesc = am7990_copytobuf_contig;
    332  1.26    veego 		sc->sc_copyfromdesc = am7990_copyfrombuf_contig;
    333  1.26    veego 		sc->sc_copytobuf = am7990_copytobuf_contig;
    334  1.26    veego 		sc->sc_copyfrombuf = am7990_copyfrombuf_contig;
    335  1.26    veego 		sc->sc_zerobuf = am7990_zerobuf_contig;
    336  1.26    veego 		sc->sc_rdcsr = lerdcsr;
    337  1.26    veego 		sc->sc_wrcsr = lewrcsr;
    338  1.26    veego 		sc->sc_hwreset = NULL;
    339  1.26    veego 		sc->sc_hwinit = NULL;
    340  1.15   chopps 		break;
    341   1.6   chopps 
    342  1.26    veego 	    case 2167:
    343  1.26    veego 		/* Village Tronic */
    344  1.26    veego 		sc->sc_memsize = 32768;
    345  1.26    veego 		sc->sc_enaddr[0] = 0x00;
    346  1.26    veego 		sc->sc_enaddr[1] = 0x60;
    347  1.26    veego 		sc->sc_enaddr[2] = 0x30;
    348  1.26    veego 		lesc->sc_r1 = (struct lereg1 *)(0x0370 + (int)zap->va);
    349  1.26    veego 		sc->sc_mem = (void *)(0x8000 + (int)zap->va);
    350  1.26    veego 		sc->sc_addr = 0x8000;
    351  1.26    veego 		sc->sc_copytodesc = ariadne_copytodesc_word;
    352  1.26    veego 		sc->sc_copyfromdesc = ariadne_copyfromdesc_word;
    353  1.26    veego 		sc->sc_copytobuf = ariadne_copytobuf_word;
    354  1.26    veego 		sc->sc_copyfrombuf = ariadne_copyfrombuf_word;
    355  1.26    veego 		sc->sc_zerobuf = ariadne_zerobuf_word;
    356  1.26    veego 		sc->sc_rdcsr = ariadne_rdcsr;
    357  1.26    veego 		sc->sc_wrcsr = ariadne_wrcsr;
    358  1.26    veego 		sc->sc_hwreset = lepcnet_reset;
    359  1.26    veego 		sc->sc_hwinit = ariadne_hwinit;
    360  1.26    veego 		sc->sc_mediachange = ariadne_mediachange;
    361  1.26    veego 		sc->sc_supmedia = lemedia_ariadne;
    362  1.26    veego 		sc->sc_nsupmedia = NLEMEDIA_ARIADNE;
    363  1.26    veego 		sc->sc_defaultmedia = IFM_ETHER | IFM_AUTO;
    364  1.26    veego 		sc->sc_initmodemedia = 2;
    365  1.26    veego 		break;
    366  1.26    veego 
    367  1.26    veego 	    default:
    368  1.21  thorpej 		panic("le_zbus_attach: bad manid");
    369   1.1       mw 	}
    370   1.6   chopps 
    371   1.6   chopps 	/*
    372  1.15   chopps 	 * Serial number for board is used as host ID.
    373   1.6   chopps 	 */
    374  1.15   chopps 	ser = (u_long)zap->serno;
    375  1.23       is 	sc->sc_enaddr[3] = (ser >> 16) & 0xff;
    376  1.23       is 	sc->sc_enaddr[4] = (ser >>  8) & 0xff;
    377  1.23       is 	sc->sc_enaddr[5] = (ser      ) & 0xff;
    378   1.1       mw 
    379  1.21  thorpej 	am7990_config(sc);
    380   1.6   chopps 
    381  1.21  thorpej 	lesc->sc_isr.isr_intr = am7990_intr;
    382  1.21  thorpej 	lesc->sc_isr.isr_arg = sc;
    383  1.21  thorpej 	lesc->sc_isr.isr_ipl = 2;
    384  1.21  thorpej 	add_isr(&lesc->sc_isr);
    385  1.26    veego }
    386  1.26    veego 
    387  1.26    veego 
    388  1.26    veego integrate void
    389  1.26    veego ariadne_copytodesc_word(sc, from, boff, len)
    390  1.26    veego 	struct am7990_softc *sc;
    391  1.26    veego 	void *from;
    392  1.26    veego 	int boff, len;
    393  1.26    veego {
    394  1.26    veego 	u_short *b1 = from;
    395  1.26    veego 	volatile u_short *b2 = sc->sc_mem + boff;
    396  1.26    veego 
    397  1.26    veego 	for (len >>= 1; len > 0; len--)
    398  1.26    veego 		*b2++ = ariadne_swapreg(*b1++);
    399  1.26    veego }
    400  1.26    veego 
    401  1.26    veego integrate void
    402  1.26    veego ariadne_copyfromdesc_word(sc, to, boff, len)
    403  1.26    veego 	struct am7990_softc *sc;
    404  1.26    veego 	void *to;
    405  1.26    veego 	int boff, len;
    406  1.26    veego {
    407  1.26    veego 	volatile u_short *b1 = sc->sc_mem + boff;
    408  1.26    veego 	u_short *b2 = to;
    409  1.26    veego 
    410  1.26    veego 	for (len >>= 1; len > 0; len--)
    411  1.26    veego 		*b2++ = ariadne_swapreg(*b1++);
    412  1.26    veego }
    413  1.26    veego 
    414  1.26    veego #define	isodd(n)	((n) & 1)
    415  1.26    veego 
    416  1.26    veego integrate void
    417  1.26    veego ariadne_copytobuf_word(sc, from, boff, len)
    418  1.26    veego 	struct am7990_softc *sc;
    419  1.26    veego 	void *from;
    420  1.26    veego 	int boff, len;
    421  1.26    veego {
    422  1.26    veego 	u_char *a1 = from;
    423  1.26    veego 	volatile u_char *a2 = sc->sc_mem + boff;
    424  1.26    veego 	u_short *b1;
    425  1.26    veego 	volatile u_short *b2;
    426  1.26    veego 	int i;
    427  1.26    veego 
    428  1.26    veego 	if (len > 0 && isodd(boff)) {
    429  1.26    veego 		b1 = (u_short *)(a1 + 1);
    430  1.26    veego 		b2 = (u_short *)(a2 + 1);
    431  1.26    veego 		b2[-1] = (b2[-1] & 0xff00) | (b1[-1] & 0x00ff);
    432  1.26    veego 		--len;
    433  1.26    veego 	} else {
    434  1.26    veego 		b1 = (u_short *)a1;
    435  1.26    veego 		b2 = (u_short *)a2;
    436  1.26    veego 	}
    437  1.26    veego 
    438  1.26    veego 	for (i = len >> 1; i > 0; i--)
    439  1.26    veego 		*b2++ = *b1++;
    440  1.26    veego 
    441  1.26    veego 	if (isodd(len))
    442  1.26    veego 		*b2 = (*b2 & 0x00ff) | (*b1 & 0xff00);
    443  1.26    veego }
    444  1.26    veego 
    445  1.26    veego integrate void
    446  1.26    veego ariadne_copyfrombuf_word(sc, to, boff, len)
    447  1.26    veego 	struct am7990_softc *sc;
    448  1.26    veego 	void *to;
    449  1.26    veego 	int boff, len;
    450  1.26    veego {
    451  1.26    veego 	volatile u_char *a1 = sc->sc_mem + boff;
    452  1.26    veego 	u_char *a2 = to;
    453  1.26    veego 	volatile u_short *b1;
    454  1.26    veego 	u_short *b2;
    455  1.26    veego 	int i;
    456  1.26    veego 
    457  1.26    veego 	if (len > 0 && isodd(boff)) {
    458  1.26    veego 		b1 = (u_short *)(a1 + 1);
    459  1.26    veego 		b2 = (u_short *)(a2 + 1);
    460  1.26    veego 		b2[-1] = (b2[-1] & 0xff00) | (b1[-1] & 0x00ff);
    461  1.26    veego 		--len;
    462  1.26    veego 	} else {
    463  1.26    veego 		b1 = (u_short *)a1;
    464  1.26    veego 		b2 = (u_short *)a2;
    465  1.26    veego 	}
    466  1.26    veego 
    467  1.26    veego 	for (i = len >> 1; i > 0; i--)
    468  1.26    veego 		*b2++ = *b1++;
    469  1.26    veego 
    470  1.26    veego 	if (isodd(len))
    471  1.26    veego 		*b2 = (*b2 & 0x00ff) | (*b1 & 0xff00);
    472  1.26    veego }
    473  1.26    veego 
    474  1.26    veego integrate void
    475  1.26    veego ariadne_zerobuf_word(sc, boff, len)
    476  1.26    veego 	struct am7990_softc *sc;
    477  1.26    veego 	int boff, len;
    478  1.26    veego {
    479  1.26    veego 	volatile u_char *a1 = sc->sc_mem + boff;
    480  1.26    veego 	volatile u_short *b1;
    481  1.26    veego 	int i;
    482  1.26    veego 
    483  1.26    veego 	if (len > 0 && isodd(boff)) {
    484  1.26    veego 		b1 = (u_short *)(a1 + 1);
    485  1.26    veego 		b1[-1] &= 0xff00;
    486  1.26    veego 		--len;
    487  1.26    veego 	} else {
    488  1.26    veego 		b1 = (u_short *)a1;
    489  1.26    veego 	}
    490  1.26    veego 
    491  1.26    veego 	for (i = len >> 1; i > 0; i--)
    492  1.26    veego 		*b1++ = 0;
    493  1.26    veego 
    494  1.26    veego 	if (isodd(len))
    495  1.26    veego 		*b1 &= 0x00ff;
    496   1.1       mw }
    497