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