Home | History | Annotate | Line # | Download | only in apbus
if_sn_ap.c revision 1.5
      1 /*	$NetBSD: if_sn_ap.c,v 1.5 2002/10/02 04:27:51 thorpej Exp $	*/
      2 
      3 /*
      4  * Copyright (C) 1997 Allen Briggs
      5  * All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  * 3. All advertising materials mentioning features or use of this software
     16  *    must display the following acknowledgement:
     17  *      This product includes software developed by Allen Briggs
     18  * 4. The name of the author may not be used to endorse or promote products
     19  *    derived from this software without specific prior written permission.
     20  *
     21  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     22  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     23  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     24  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     26  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     30  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     31  */
     32 
     33 #include "opt_inet.h"
     34 
     35 #include <sys/param.h>
     36 #include <sys/device.h>
     37 #include <sys/errno.h>
     38 #include <sys/ioctl.h>
     39 #include <sys/socket.h>
     40 #include <sys/syslog.h>
     41 #include <sys/systm.h>
     42 
     43 #include <net/if.h>
     44 #include <net/if_ether.h>
     45 
     46 #include <machine/cpu.h>
     47 #include <machine/adrsmap.h>
     48 
     49 #include <newsmips/apbus/apbusvar.h>
     50 #include <newsmips/apbus/if_snreg.h>
     51 #include <newsmips/apbus/if_snvar.h>
     52 
     53 #define SONIC_MACROM_OFFSET	0x40
     54 
     55 #define SONIC_APBUS_REG_OFFSET	0x00010000
     56 #define SONIC_APBUS_MEM_OFFSET	0x00020000
     57 #define SONIC_APBUS_CTL_OFFSET	(-0x00100000)
     58 
     59 static int	sn_ap_match __P((struct device *, struct cfdata *, void *));
     60 static void	sn_ap_attach __P((struct device *, struct device *, void *));
     61 static int	sn_ap_getaddr __P((struct sn_softc *, u_int8_t *));
     62 
     63 CFATTACH_DECL(sn_ap, sizeof(struct sn_softc),
     64     sn_ap_match, sn_ap_attach, NULL, NULL);
     65 
     66 static int
     67 sn_ap_match(parent, cf, aux)
     68 	struct device *parent;
     69 	struct cfdata *cf;
     70 	void *aux;
     71 {
     72 	struct apbus_attach_args *apa = aux;
     73 
     74 	if (strcmp(apa->apa_name, "sonic") != 0)
     75 		return 0;
     76 
     77 	return 1;
     78 }
     79 
     80 /*
     81  * Install interface into kernel networking data structures
     82  */
     83 static void
     84 sn_ap_attach(parent, self, aux)
     85 	struct device *parent, *self;
     86 	void   *aux;
     87 {
     88 	struct sn_softc *sc = (void *)self;
     89 	struct apbus_attach_args *apa = aux;
     90 	u_int8_t myaddr[ETHER_ADDR_LEN];
     91 	u_int intrmask;
     92 
     93 	sc->sc_hwbase = (caddr_t)apa->apa_hwbase;
     94 	sc->sc_regbase = (void *)(apa->apa_hwbase + SONIC_APBUS_REG_OFFSET);
     95 	sc->space = (void *)(apa->apa_hwbase + SONIC_APBUS_MEM_OFFSET);
     96 
     97 	printf(" slot%d addr 0x%lx", apa->apa_slotno, apa->apa_hwbase);
     98 
     99 	sc->snr_dcr = DCR_WAIT0 | DCR_DMABLOCK | DCR_RFT16 | DCR_TFT16;
    100 	sc->snr_dcr2 = 0;
    101 	sc->snr_dcr |= DCR_EXBUS;
    102 	sc->bitmode = 1;
    103 
    104 	if (sn_ap_getaddr(sc, myaddr)) {
    105 		printf(": failed to get MAC address\n");
    106 		return;
    107 	}
    108 
    109 	printf("\n");
    110 
    111 	/* snsetup returns 1 if something fails */
    112 	if (snsetup(sc, myaddr))
    113 		return;
    114 
    115 	intrmask = (apa->apa_slotno == 0) ?
    116 		NEWS5000_INT0_SONIC : SLOTTOMASK(apa->apa_slotno);
    117 
    118 	apbus_intr_establish(0, /* interrupt level (0 or 1) */
    119 			     intrmask,
    120 			     0, /* priority */
    121 			     snintr, sc, apa->apa_name, apa->apa_ctlnum);
    122 }
    123 
    124 int
    125 sn_ap_getaddr(sc, lladdr)
    126 	struct sn_softc	*sc;
    127 	u_int8_t *lladdr;
    128 {
    129 	u_int *p = (u_int *)(sc->sc_hwbase + SONIC_MACROM_OFFSET);
    130 	int i;
    131 
    132 	for (i = 0; i < 6; i++) {
    133 		int h = *p++ & 0x0f;
    134 		int l = *p++ & 0x0f;
    135 		*lladdr++ = (h << 4) + l;
    136 	}
    137 
    138 	return 0;
    139 }
    140 
    141 #define APSONIC_INT_MASK	0x00007f00	/* XXX */
    142 #define	APSONIC_INT_REG(base)	(((u_long)(base) & 0xffc00000) | 0x00100000)
    143 
    144 void
    145 sn_md_init(sc)
    146 	struct sn_softc *sc;
    147 {
    148 	u_int *reg = (u_int *)APSONIC_INT_REG(sc->sc_hwbase);
    149 
    150 	*reg = APSONIC_INT_MASK;
    151 	wbflush();
    152 	apbus_wbflush();
    153 	delay(10000);
    154 }
    155