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