Home | History | Annotate | Line # | Download | only in ibus
if_le_ibus.c revision 1.2
      1  1.2  simonb /*	$NetBSD: if_le_ibus.c,v 1.2 2001/10/01 11:42:18 simonb 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.2  simonb 
     26  1.2  simonb #include <net/if.h>
     27  1.2  simonb #include <net/if_ether.h>
     28  1.2  simonb #include <net/if_media.h>
     29  1.2  simonb 
     30  1.2  simonb #ifdef INET
     31  1.2  simonb #include <netinet/in.h>
     32  1.2  simonb #include <netinet/if_inarp.h>
     33  1.2  simonb #endif
     34  1.2  simonb 
     35  1.2  simonb #include <dev/ic/lancevar.h>
     36  1.2  simonb #include <dev/ic/am7990var.h>
     37  1.2  simonb 
     38  1.2  simonb #include <dev/tc/if_levar.h>
     39  1.2  simonb #include <pmax/ibus/ibusvar.h>
     40  1.2  simonb #include <pmax/pmax/kn01.h>
     41  1.2  simonb 
     42  1.2  simonb static void le_dec_copyfrombuf_gap2(struct lance_softc *, void *, int, int);
     43  1.2  simonb static void le_dec_copytobuf_gap2(struct lance_softc *, void *, int, int);
     44  1.2  simonb static void le_dec_zerobuf_gap2(struct lance_softc *, int, int);
     45  1.2  simonb 
     46  1.2  simonb 
     47  1.2  simonb static int le_pmax_match(struct device *, struct cfdata *, void *);
     48  1.2  simonb static void le_pmax_attach(struct device *, struct device *, void *);
     49  1.2  simonb 
     50  1.2  simonb struct cfattach le_pmax_ca = {
     51  1.2  simonb 	sizeof(struct le_softc), le_pmax_match, le_pmax_attach
     52  1.2  simonb };
     53  1.2  simonb extern struct cfdriver ibus_cd;
     54  1.2  simonb 
     55  1.2  simonb int
     56  1.2  simonb le_pmax_match(struct device *parent, struct cfdata *match, void *aux)
     57  1.2  simonb {
     58  1.2  simonb 	struct ibus_attach_args *d = aux;
     59  1.2  simonb 
     60  1.2  simonb 	if (parent->dv_cfdata->cf_driver != &ibus_cd)
     61  1.2  simonb 		return (0);
     62  1.2  simonb 
     63  1.2  simonb 	if (strcmp("lance", d->ia_name) != 0)
     64  1.2  simonb 		return (0);
     65  1.2  simonb 	return (1);
     66  1.2  simonb }
     67  1.2  simonb 
     68  1.2  simonb void
     69  1.2  simonb le_pmax_attach(struct device *parent, struct device *self, void *aux)
     70  1.2  simonb {
     71  1.2  simonb 	struct le_softc *lesc = (void *)self;
     72  1.2  simonb 	struct lance_softc *sc = &lesc->sc_am7990.lsc;
     73  1.2  simonb 	u_char *cp;
     74  1.2  simonb 	struct ibus_attach_args *ia = aux;
     75  1.2  simonb 
     76  1.2  simonb 	/*
     77  1.2  simonb 	 * It's on the baseboard, with a dedicated interrupt line.
     78  1.2  simonb 	 */
     79  1.2  simonb 	lesc->sc_r1 = (struct lereg1 *)(ia->ia_addr);
     80  1.2  simonb 	sc->sc_mem = (void *)MIPS_PHYS_TO_KSEG1(KN01_SYS_LANCE_B_START);
     81  1.2  simonb 	cp = (u_char *)(MIPS_PHYS_TO_KSEG1(KN01_SYS_CLOCK) + 1);
     82  1.2  simonb 
     83  1.2  simonb 	sc->sc_copytodesc = le_dec_copytobuf_gap2;
     84  1.2  simonb 	sc->sc_copyfromdesc = le_dec_copyfrombuf_gap2;
     85  1.2  simonb 	sc->sc_copytobuf = le_dec_copytobuf_gap2;
     86  1.2  simonb 	sc->sc_copyfrombuf = le_dec_copyfrombuf_gap2;
     87  1.2  simonb 	sc->sc_zerobuf = le_dec_zerobuf_gap2;
     88  1.2  simonb 
     89  1.2  simonb 	dec_le_common_attach(&lesc->sc_am7990, cp);
     90  1.2  simonb 
     91  1.2  simonb 	ibus_intr_establish(parent, (void*)ia->ia_cookie, IPL_NET,
     92  1.2  simonb 	    am7990_intr, sc);
     93  1.2  simonb }
     94  1.2  simonb 
     95  1.2  simonb /*
     96  1.2  simonb  * gap2: two bytes of data followed by two bytes of pad.
     97  1.2  simonb  *
     98  1.2  simonb  * Buffers must be 4-byte aligned.  The code doesn't worry about
     99  1.2  simonb  * doing an extra byte.
    100  1.2  simonb  */
    101  1.2  simonb 
    102  1.2  simonb void
    103  1.2  simonb le_dec_copytobuf_gap2(struct lance_softc *sc, void *fromv, int boff, int len)
    104  1.2  simonb {
    105  1.2  simonb 	volatile caddr_t buf = sc->sc_mem;
    106  1.2  simonb 	caddr_t from = fromv;
    107  1.2  simonb 	volatile u_int16_t *bptr;
    108  1.2  simonb 
    109  1.2  simonb 	if (boff & 0x1) {
    110  1.2  simonb 		/* handle unaligned first byte */
    111  1.2  simonb 		bptr = ((volatile u_int16_t *)buf) + (boff - 1);
    112  1.2  simonb 		*bptr = (*from++ << 8) | (*bptr & 0xff);
    113  1.2  simonb 		bptr += 2;
    114  1.2  simonb 		len--;
    115  1.2  simonb 	} else
    116  1.2  simonb 		bptr = ((volatile u_int16_t *)buf) + boff;
    117  1.2  simonb 	while (len > 1) {
    118  1.2  simonb 		*bptr = (from[1] << 8) | (from[0] & 0xff);
    119  1.2  simonb 		bptr += 2;
    120  1.2  simonb 		from += 2;
    121  1.2  simonb 		len -= 2;
    122  1.2  simonb 	}
    123  1.2  simonb 	if (len == 1)
    124  1.2  simonb 		*bptr = (u_int16_t)*from;
    125  1.2  simonb }
    126  1.2  simonb 
    127  1.2  simonb void
    128  1.2  simonb le_dec_copyfrombuf_gap2(struct lance_softc *sc, void *tov, int boff, int len)
    129  1.2  simonb {
    130  1.2  simonb 	volatile caddr_t buf = sc->sc_mem;
    131  1.2  simonb 	caddr_t to = tov;
    132  1.2  simonb 	volatile u_int16_t *bptr;
    133  1.2  simonb 	u_int16_t tmp;
    134  1.2  simonb 
    135  1.2  simonb 	if (boff & 0x1) {
    136  1.2  simonb 		/* handle unaligned first byte */
    137  1.2  simonb 		bptr = ((volatile u_int16_t *)buf) + (boff - 1);
    138  1.2  simonb 		*to++ = (*bptr >> 8) & 0xff;
    139  1.2  simonb 		bptr += 2;
    140  1.2  simonb 		len--;
    141  1.2  simonb 	} else
    142  1.2  simonb 		bptr = ((volatile u_int16_t *)buf) + boff;
    143  1.2  simonb 	while (len > 1) {
    144  1.2  simonb 		tmp = *bptr;
    145  1.2  simonb 		*to++ = tmp & 0xff;
    146  1.2  simonb 		*to++ = (tmp >> 8) & 0xff;
    147  1.2  simonb 		bptr += 2;
    148  1.2  simonb 		len -= 2;
    149  1.2  simonb 	}
    150  1.2  simonb 	if (len == 1)
    151  1.2  simonb 		*to = *bptr & 0xff;
    152  1.2  simonb }
    153  1.2  simonb 
    154  1.2  simonb static void
    155  1.2  simonb le_dec_zerobuf_gap2(struct lance_softc *sc, int boff, int len)
    156  1.2  simonb {
    157  1.2  simonb 	volatile caddr_t buf = sc->sc_mem;
    158  1.2  simonb 	volatile u_int16_t *bptr;
    159  1.2  simonb 
    160  1.2  simonb 	if ((unsigned)boff & 0x1) {
    161  1.2  simonb 		bptr = ((volatile u_int16_t *)buf) + (boff - 1);
    162  1.2  simonb 		*bptr &= 0xff;
    163  1.2  simonb 		bptr += 2;
    164  1.2  simonb 		len--;
    165  1.2  simonb 	} else
    166  1.2  simonb 		bptr = ((volatile u_int16_t *)buf) + boff;
    167  1.2  simonb 	while (len > 0) {
    168  1.2  simonb 		*bptr = 0;
    169  1.2  simonb 		bptr += 2;
    170  1.2  simonb 		len -= 2;
    171  1.2  simonb 	}
    172  1.2  simonb }
    173