Home | History | Annotate | Line # | Download | only in ibus
if_le_ibus.c revision 1.7
      1  1.7  thorpej /*	$NetBSD: if_le_ibus.c,v 1.7 2002/10/02 04:15:09 thorpej Exp $	*/
      2  1.2   simonb 
      3  1.2   simonb /*
      4  1.2   simonb  * Copyright 1996 The Board of Trustees of The Leland Stanford
      5  1.2   simonb  * Junior University. All Rights Reserved.
      6  1.2   simonb  *
      7  1.2   simonb  * Permission to use, copy, modify, and distribute this
      8  1.2   simonb  * software and its documentation for any purpose and without
      9  1.2   simonb  * fee is hereby granted, provided that the above copyright
     10  1.2   simonb  * notice appear in all copies.  Stanford University
     11  1.2   simonb  * makes no representations about the suitability of this
     12  1.2   simonb  * software for any purpose.  It is provided "as is" without
     13  1.2   simonb  * express or implied warranty.
     14  1.2   simonb  *
     15  1.2   simonb  * This driver was contributed by Jonathan Stone.
     16  1.2   simonb  */
     17  1.2   simonb 
     18  1.2   simonb /*
     19  1.2   simonb  * LANCE on Decstation kn01/kn220(?) baseboard.
     20  1.2   simonb  */
     21  1.2   simonb #include "opt_inet.h"
     22  1.2   simonb 
     23  1.2   simonb #include <sys/param.h>
     24  1.2   simonb #include <sys/socket.h>
     25  1.3      chs #include <sys/systm.h>
     26  1.2   simonb 
     27  1.2   simonb #include <net/if.h>
     28  1.2   simonb #include <net/if_ether.h>
     29  1.2   simonb #include <net/if_media.h>
     30  1.2   simonb 
     31  1.2   simonb #ifdef INET
     32  1.2   simonb #include <netinet/in.h>
     33  1.2   simonb #include <netinet/if_inarp.h>
     34  1.2   simonb #endif
     35  1.2   simonb 
     36  1.2   simonb #include <dev/ic/lancevar.h>
     37  1.2   simonb #include <dev/ic/am7990var.h>
     38  1.2   simonb 
     39  1.2   simonb #include <dev/tc/if_levar.h>
     40  1.2   simonb #include <pmax/ibus/ibusvar.h>
     41  1.2   simonb #include <pmax/pmax/kn01.h>
     42  1.2   simonb 
     43  1.2   simonb static void le_dec_copyfrombuf_gap2(struct lance_softc *, void *, int, int);
     44  1.2   simonb static void le_dec_copytobuf_gap2(struct lance_softc *, void *, int, int);
     45  1.2   simonb static void le_dec_zerobuf_gap2(struct lance_softc *, int, int);
     46  1.2   simonb 
     47  1.2   simonb 
     48  1.2   simonb static int le_pmax_match(struct device *, struct cfdata *, void *);
     49  1.2   simonb static void le_pmax_attach(struct device *, struct device *, void *);
     50  1.2   simonb 
     51  1.7  thorpej CFATTACH_DECL(le_pmax, sizeof(struct le_softc),
     52  1.7  thorpej     le_pmax_match, le_pmax_attach, NULL, NULL);
     53  1.2   simonb 
     54  1.2   simonb int
     55  1.2   simonb le_pmax_match(struct device *parent, struct cfdata *match, void *aux)
     56  1.2   simonb {
     57  1.2   simonb 	struct ibus_attach_args *d = aux;
     58  1.2   simonb 
     59  1.2   simonb 	if (strcmp("lance", d->ia_name) != 0)
     60  1.2   simonb 		return (0);
     61  1.2   simonb 	return (1);
     62  1.2   simonb }
     63  1.2   simonb 
     64  1.2   simonb void
     65  1.2   simonb le_pmax_attach(struct device *parent, struct device *self, void *aux)
     66  1.2   simonb {
     67  1.2   simonb 	struct le_softc *lesc = (void *)self;
     68  1.2   simonb 	struct lance_softc *sc = &lesc->sc_am7990.lsc;
     69  1.2   simonb 	u_char *cp;
     70  1.2   simonb 	struct ibus_attach_args *ia = aux;
     71  1.2   simonb 
     72  1.2   simonb 	/*
     73  1.2   simonb 	 * It's on the baseboard, with a dedicated interrupt line.
     74  1.2   simonb 	 */
     75  1.2   simonb 	lesc->sc_r1 = (struct lereg1 *)(ia->ia_addr);
     76  1.2   simonb 	sc->sc_mem = (void *)MIPS_PHYS_TO_KSEG1(KN01_SYS_LANCE_B_START);
     77  1.2   simonb 	cp = (u_char *)(MIPS_PHYS_TO_KSEG1(KN01_SYS_CLOCK) + 1);
     78  1.2   simonb 
     79  1.2   simonb 	sc->sc_copytodesc = le_dec_copytobuf_gap2;
     80  1.2   simonb 	sc->sc_copyfromdesc = le_dec_copyfrombuf_gap2;
     81  1.2   simonb 	sc->sc_copytobuf = le_dec_copytobuf_gap2;
     82  1.2   simonb 	sc->sc_copyfrombuf = le_dec_copyfrombuf_gap2;
     83  1.2   simonb 	sc->sc_zerobuf = le_dec_zerobuf_gap2;
     84  1.2   simonb 
     85  1.2   simonb 	dec_le_common_attach(&lesc->sc_am7990, cp);
     86  1.2   simonb 
     87  1.2   simonb 	ibus_intr_establish(parent, (void*)ia->ia_cookie, IPL_NET,
     88  1.2   simonb 	    am7990_intr, sc);
     89  1.2   simonb }
     90  1.2   simonb 
     91  1.2   simonb /*
     92  1.2   simonb  * gap2: two bytes of data followed by two bytes of pad.
     93  1.2   simonb  *
     94  1.2   simonb  * Buffers must be 4-byte aligned.  The code doesn't worry about
     95  1.2   simonb  * doing an extra byte.
     96  1.2   simonb  */
     97  1.2   simonb 
     98  1.2   simonb void
     99  1.2   simonb le_dec_copytobuf_gap2(struct lance_softc *sc, void *fromv, int boff, int len)
    100  1.2   simonb {
    101  1.2   simonb 	volatile caddr_t buf = sc->sc_mem;
    102  1.2   simonb 	caddr_t from = fromv;
    103  1.2   simonb 	volatile u_int16_t *bptr;
    104  1.2   simonb 
    105  1.2   simonb 	if (boff & 0x1) {
    106  1.2   simonb 		/* handle unaligned first byte */
    107  1.2   simonb 		bptr = ((volatile u_int16_t *)buf) + (boff - 1);
    108  1.2   simonb 		*bptr = (*from++ << 8) | (*bptr & 0xff);
    109  1.2   simonb 		bptr += 2;
    110  1.2   simonb 		len--;
    111  1.2   simonb 	} else
    112  1.2   simonb 		bptr = ((volatile u_int16_t *)buf) + boff;
    113  1.2   simonb 	while (len > 1) {
    114  1.2   simonb 		*bptr = (from[1] << 8) | (from[0] & 0xff);
    115  1.2   simonb 		bptr += 2;
    116  1.2   simonb 		from += 2;
    117  1.2   simonb 		len -= 2;
    118  1.2   simonb 	}
    119  1.2   simonb 	if (len == 1)
    120  1.2   simonb 		*bptr = (u_int16_t)*from;
    121  1.2   simonb }
    122  1.2   simonb 
    123  1.2   simonb void
    124  1.2   simonb le_dec_copyfrombuf_gap2(struct lance_softc *sc, void *tov, int boff, int len)
    125  1.2   simonb {
    126  1.2   simonb 	volatile caddr_t buf = sc->sc_mem;
    127  1.2   simonb 	caddr_t to = tov;
    128  1.2   simonb 	volatile u_int16_t *bptr;
    129  1.2   simonb 	u_int16_t tmp;
    130  1.2   simonb 
    131  1.2   simonb 	if (boff & 0x1) {
    132  1.2   simonb 		/* handle unaligned first byte */
    133  1.2   simonb 		bptr = ((volatile u_int16_t *)buf) + (boff - 1);
    134  1.2   simonb 		*to++ = (*bptr >> 8) & 0xff;
    135  1.2   simonb 		bptr += 2;
    136  1.2   simonb 		len--;
    137  1.2   simonb 	} else
    138  1.2   simonb 		bptr = ((volatile u_int16_t *)buf) + boff;
    139  1.2   simonb 	while (len > 1) {
    140  1.2   simonb 		tmp = *bptr;
    141  1.2   simonb 		*to++ = tmp & 0xff;
    142  1.2   simonb 		*to++ = (tmp >> 8) & 0xff;
    143  1.2   simonb 		bptr += 2;
    144  1.2   simonb 		len -= 2;
    145  1.2   simonb 	}
    146  1.2   simonb 	if (len == 1)
    147  1.2   simonb 		*to = *bptr & 0xff;
    148  1.2   simonb }
    149  1.2   simonb 
    150  1.2   simonb static void
    151  1.2   simonb le_dec_zerobuf_gap2(struct lance_softc *sc, int boff, int len)
    152  1.2   simonb {
    153  1.2   simonb 	volatile caddr_t buf = sc->sc_mem;
    154  1.2   simonb 	volatile u_int16_t *bptr;
    155  1.2   simonb 
    156  1.2   simonb 	if ((unsigned)boff & 0x1) {
    157  1.2   simonb 		bptr = ((volatile u_int16_t *)buf) + (boff - 1);
    158  1.2   simonb 		*bptr &= 0xff;
    159  1.2   simonb 		bptr += 2;
    160  1.2   simonb 		len--;
    161  1.2   simonb 	} else
    162  1.2   simonb 		bptr = ((volatile u_int16_t *)buf) + boff;
    163  1.2   simonb 	while (len > 0) {
    164  1.2   simonb 		*bptr = 0;
    165  1.2   simonb 		bptr += 2;
    166  1.2   simonb 		len -= 2;
    167  1.2   simonb 	}
    168  1.2   simonb }
    169