if_sn_ap.c revision 1.13 1 1.13 tsutsui /* $NetBSD: if_sn_ap.c,v 1.13 2018/10/14 00:10:11 tsutsui 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.6 lukem
33 1.6 lukem #include <sys/cdefs.h>
34 1.13 tsutsui __KERNEL_RCSID(0, "$NetBSD: if_sn_ap.c,v 1.13 2018/10/14 00:10:11 tsutsui Exp $");
35 1.1 tsubai
36 1.1 tsubai #include "opt_inet.h"
37 1.1 tsubai
38 1.1 tsubai #include <sys/param.h>
39 1.1 tsubai #include <sys/device.h>
40 1.1 tsubai #include <sys/errno.h>
41 1.1 tsubai #include <sys/ioctl.h>
42 1.1 tsubai #include <sys/socket.h>
43 1.1 tsubai #include <sys/syslog.h>
44 1.1 tsubai #include <sys/systm.h>
45 1.1 tsubai
46 1.1 tsubai #include <net/if.h>
47 1.1 tsubai #include <net/if_ether.h>
48 1.1 tsubai
49 1.1 tsubai #include <machine/cpu.h>
50 1.1 tsubai #include <machine/adrsmap.h>
51 1.1 tsubai
52 1.1 tsubai #include <newsmips/apbus/apbusvar.h>
53 1.1 tsubai #include <newsmips/apbus/if_snreg.h>
54 1.1 tsubai #include <newsmips/apbus/if_snvar.h>
55 1.1 tsubai
56 1.13 tsutsui #include <newsmips/newsmips/machid.h>
57 1.13 tsutsui
58 1.1 tsubai #define SONIC_MACROM_OFFSET 0x40
59 1.1 tsubai
60 1.1 tsubai #define SONIC_APBUS_REG_OFFSET 0x00010000
61 1.1 tsubai #define SONIC_APBUS_MEM_OFFSET 0x00020000
62 1.1 tsubai #define SONIC_APBUS_CTL_OFFSET (-0x00100000)
63 1.1 tsubai
64 1.11 tsutsui static int sn_ap_match(device_t, cfdata_t, void *);
65 1.11 tsutsui static void sn_ap_attach(device_t, device_t, void *);
66 1.7 tsutsui static int sn_ap_getaddr(struct sn_softc *, uint8_t *);
67 1.1 tsubai
68 1.11 tsutsui CFATTACH_DECL_NEW(sn_ap, sizeof(struct sn_softc),
69 1.5 thorpej sn_ap_match, sn_ap_attach, NULL, NULL);
70 1.1 tsubai
71 1.1 tsubai static int
72 1.11 tsutsui sn_ap_match(device_t parent, cfdata_t cf, void *aux)
73 1.1 tsubai {
74 1.1 tsubai struct apbus_attach_args *apa = aux;
75 1.1 tsubai
76 1.1 tsubai if (strcmp(apa->apa_name, "sonic") != 0)
77 1.1 tsubai return 0;
78 1.1 tsubai
79 1.1 tsubai return 1;
80 1.1 tsubai }
81 1.1 tsubai
82 1.1 tsubai /*
83 1.1 tsubai * Install interface into kernel networking data structures
84 1.1 tsubai */
85 1.1 tsubai static void
86 1.11 tsutsui sn_ap_attach(device_t parent, device_t self, void *aux)
87 1.1 tsubai {
88 1.11 tsutsui struct sn_softc *sc = device_private(self);
89 1.1 tsubai struct apbus_attach_args *apa = aux;
90 1.7 tsutsui uint8_t myaddr[ETHER_ADDR_LEN];
91 1.13 tsutsui uint32_t intrmask = 0;
92 1.1 tsubai
93 1.11 tsutsui sc->sc_dev = self;
94 1.13 tsutsui sc->slotno = apa->apa_slotno;
95 1.13 tsutsui if (systype == NEWS4000 && sc->slotno == 0) {
96 1.13 tsutsui sc->sc_flags |= F_NWS40S0;
97 1.13 tsutsui }
98 1.13 tsutsui if ((sc->sc_flags & F_NWS40S0) != 0) {
99 1.13 tsutsui sc->sc_hwbase = (void *)apa->apa_hwbase;
100 1.13 tsutsui sc->sc_regbase = (void *)apa->apa_hwbase;
101 1.13 tsutsui sc->memory = (void *)NEWS4000_SONIC_MEMORY;
102 1.13 tsutsui sc->buffer = (void *)NEWS4000_SONIC_BUFFER;
103 1.13 tsutsui } else {
104 1.13 tsutsui sc->sc_hwbase = (void *)apa->apa_hwbase;
105 1.13 tsutsui sc->sc_regbase =
106 1.13 tsutsui (void *)(apa->apa_hwbase + SONIC_APBUS_REG_OFFSET);
107 1.13 tsutsui sc->memory =
108 1.13 tsutsui (void *)(apa->apa_hwbase + SONIC_APBUS_MEM_OFFSET);
109 1.13 tsutsui }
110 1.1 tsubai
111 1.11 tsutsui aprint_normal(" slot%d addr 0x%lx", apa->apa_slotno, apa->apa_hwbase);
112 1.1 tsubai
113 1.13 tsutsui if ((sc->sc_flags & F_NWS40S0) != 0) {
114 1.13 tsutsui sc->snr_dcr = DCR_STERM | DCR_TFT28;
115 1.13 tsutsui sc->snr_dcr2 = 0x0100;
116 1.13 tsutsui } else {
117 1.13 tsutsui sc->snr_dcr = DCR_WAIT0 | DCR_DMABLOCK | DCR_RFT16 | DCR_TFT16;
118 1.13 tsutsui sc->snr_dcr2 = 0;
119 1.13 tsutsui sc->snr_dcr |= DCR_EXBUS;
120 1.13 tsutsui }
121 1.1 tsubai sc->bitmode = 1;
122 1.1 tsubai
123 1.1 tsubai if (sn_ap_getaddr(sc, myaddr)) {
124 1.11 tsutsui aprint_error(": failed to get MAC address\n");
125 1.1 tsubai return;
126 1.1 tsubai }
127 1.1 tsubai
128 1.11 tsutsui aprint_normal("\n");
129 1.1 tsubai
130 1.1 tsubai /* snsetup returns 1 if something fails */
131 1.1 tsubai if (snsetup(sc, myaddr))
132 1.1 tsubai return;
133 1.1 tsubai
134 1.13 tsutsui if (systype == NEWS5000) {
135 1.13 tsutsui intrmask = (apa->apa_slotno == 0) ?
136 1.13 tsutsui NEWS5000_INT0_SONIC : NEWS5000_SLOTTOMASK(apa->apa_slotno);
137 1.13 tsutsui }
138 1.13 tsutsui if (systype == NEWS4000) {
139 1.13 tsutsui intrmask = (apa->apa_slotno == 0) ?
140 1.13 tsutsui NEWS4000_INT0_SONIC : NEWS4000_SLOTTOMASK(apa->apa_slotno);
141 1.13 tsutsui }
142 1.1 tsubai
143 1.1 tsubai apbus_intr_establish(0, /* interrupt level (0 or 1) */
144 1.7 tsutsui intrmask,
145 1.7 tsutsui 0, /* priority */
146 1.12 tsutsui snintr, sc, device_xname(self), apa->apa_ctlnum);
147 1.1 tsubai }
148 1.1 tsubai
149 1.1 tsubai int
150 1.7 tsutsui sn_ap_getaddr(struct sn_softc *sc, uint8_t *lladdr)
151 1.1 tsubai {
152 1.1 tsubai
153 1.13 tsutsui if ((sc->sc_flags & F_NWS40S0) != 0) {
154 1.13 tsutsui extern struct idrom idrom;
155 1.13 tsutsui memcpy(lladdr, idrom.id_macadrs, sizeof(idrom.id_macadrs));
156 1.13 tsutsui } else {
157 1.13 tsutsui uint32_t *p;
158 1.13 tsutsui int i;
159 1.13 tsutsui
160 1.13 tsutsui p = (uint32_t *)((uint8_t *)sc->sc_hwbase +
161 1.13 tsutsui SONIC_MACROM_OFFSET);
162 1.13 tsutsui for (i = 0; i < ETHER_ADDR_LEN; i++) {
163 1.13 tsutsui int h = *p++ & 0x0f;
164 1.13 tsutsui int l = *p++ & 0x0f;
165 1.13 tsutsui *lladdr++ = (h << 4) + l;
166 1.13 tsutsui }
167 1.1 tsubai }
168 1.1 tsubai
169 1.1 tsubai return 0;
170 1.1 tsubai }
171 1.1 tsubai
172 1.2 tsubai #define APSONIC_INT_MASK 0x00007f00 /* XXX */
173 1.3 onoe #define APSONIC_INT_REG(base) (((u_long)(base) & 0xffc00000) | 0x00100000)
174 1.1 tsubai
175 1.1 tsubai void
176 1.7 tsutsui sn_md_init(struct sn_softc *sc)
177 1.1 tsubai {
178 1.1 tsubai
179 1.13 tsutsui if ((sc->sc_flags & F_NWS40S0) != 0) {
180 1.13 tsutsui *(volatile uint32_t *)0xbf700000 = 1;
181 1.13 tsutsui } else {
182 1.13 tsutsui volatile uint32_t *reg =
183 1.13 tsutsui (uint32_t *)APSONIC_INT_REG(sc->sc_hwbase);
184 1.13 tsutsui
185 1.13 tsutsui *reg = APSONIC_INT_MASK;
186 1.13 tsutsui }
187 1.1 tsubai wbflush();
188 1.1 tsubai apbus_wbflush();
189 1.1 tsubai delay(10000);
190 1.1 tsubai }
191