if_sm_nubus.c revision 1.9 1 1.9 matt /* $NetBSD: if_sm_nubus.c,v 1.9 2012/02/12 16:34:09 matt Exp $ */
2 1.1 briggs
3 1.1 briggs /*
4 1.1 briggs * Copyright (c) 2000 Allen Briggs.
5 1.1 briggs * All rights reserved.
6 1.1 briggs *
7 1.1 briggs * Redistribution and use in source and binary forms, with or without
8 1.1 briggs * modification, are permitted provided that the following conditions
9 1.1 briggs * are met:
10 1.1 briggs * 1. Redistributions of source code must retain the above copyright
11 1.1 briggs * notice, this list of conditions and the following disclaimer.
12 1.1 briggs * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 briggs * notice, this list of conditions and the following disclaimer in the
14 1.1 briggs * documentation and/or other materials provided with the distribution.
15 1.1 briggs * 3. The name of the author may not be used to endorse or promote products
16 1.1 briggs * derived from this software without specific prior written permission.
17 1.1 briggs *
18 1.1 briggs * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 1.1 briggs * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 1.1 briggs * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 1.1 briggs * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 1.1 briggs * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 1.1 briggs * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 1.1 briggs * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 1.1 briggs * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 1.1 briggs * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 1.1 briggs * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 1.1 briggs */
29 1.5 lukem
30 1.5 lukem #include <sys/cdefs.h>
31 1.9 matt __KERNEL_RCSID(0, "$NetBSD: if_sm_nubus.c,v 1.9 2012/02/12 16:34:09 matt Exp $");
32 1.1 briggs
33 1.1 briggs #include "opt_inet.h"
34 1.1 briggs
35 1.1 briggs #include <sys/param.h>
36 1.1 briggs #include <sys/device.h>
37 1.1 briggs #include <sys/errno.h>
38 1.1 briggs #include <sys/ioctl.h>
39 1.1 briggs #include <sys/socket.h>
40 1.1 briggs #include <sys/syslog.h>
41 1.1 briggs #include <sys/systm.h>
42 1.1 briggs
43 1.1 briggs #include <net/if.h>
44 1.1 briggs #include <net/if_ether.h>
45 1.1 briggs #include <net/if_media.h>
46 1.1 briggs
47 1.1 briggs #include <machine/bus.h>
48 1.1 briggs #include <machine/viareg.h>
49 1.1 briggs
50 1.1 briggs #include <dev/mii/mii.h>
51 1.1 briggs #include <dev/mii/miivar.h>
52 1.1 briggs
53 1.1 briggs #include <dev/ic/smc91cxxreg.h>
54 1.1 briggs #include <dev/ic/smc91cxxvar.h>
55 1.1 briggs
56 1.1 briggs #include <mac68k/nubus/nubus.h>
57 1.1 briggs
58 1.9 matt static int sm_nubus_match(device_t, cfdata_t, void *);
59 1.9 matt static void sm_nubus_attach(device_t, device_t, void *);
60 1.1 briggs
61 1.4 thorpej CFATTACH_DECL(sm_nubus, sizeof(struct smc91cxx_softc),
62 1.4 thorpej sm_nubus_match, sm_nubus_attach, NULL, NULL);
63 1.1 briggs
64 1.1 briggs static int
65 1.9 matt sm_nubus_match(device_t parent, cfdata_t cf, void *aux)
66 1.1 briggs {
67 1.1 briggs struct nubus_attach_args *na = (struct nubus_attach_args *) aux;
68 1.1 briggs bus_space_handle_t bsh;
69 1.1 briggs int rv;
70 1.1 briggs
71 1.1 briggs if (bus_space_map(na->na_tag,
72 1.1 briggs NUBUS_SLOT2PA(na->slot), NBMEMSIZE, 0, &bsh))
73 1.1 briggs return (0);
74 1.1 briggs
75 1.1 briggs rv = 0;
76 1.1 briggs
77 1.1 briggs if (na->category == NUBUS_CATEGORY_NETWORK &&
78 1.1 briggs na->type == NUBUS_TYPE_ETHERNET) {
79 1.1 briggs switch (na->drsw) {
80 1.1 briggs case NUBUS_DRSW_FOCUS:
81 1.1 briggs case NUBUS_DRSW_ASANTEF:
82 1.1 briggs rv = 1;
83 1.1 briggs break;
84 1.1 briggs default:
85 1.1 briggs rv = 0;
86 1.1 briggs break;
87 1.1 briggs }
88 1.1 briggs }
89 1.1 briggs
90 1.1 briggs bus_space_unmap(na->na_tag, bsh, NBMEMSIZE);
91 1.1 briggs
92 1.1 briggs return rv;
93 1.1 briggs }
94 1.1 briggs
95 1.1 briggs /*
96 1.1 briggs * Install interface into kernel networking data structures
97 1.1 briggs */
98 1.1 briggs static void
99 1.9 matt sm_nubus_attach(device_t parent, device_t self, void *aux)
100 1.1 briggs {
101 1.9 matt struct smc91cxx_softc *smc = device_private(self);
102 1.1 briggs struct nubus_attach_args *na = (struct nubus_attach_args *)aux;
103 1.1 briggs bus_space_tag_t bst = na->na_tag;
104 1.1 briggs bus_space_handle_t bsh, prom_bsh;
105 1.1 briggs u_int8_t myaddr[ETHER_ADDR_LEN];
106 1.1 briggs int i, success;
107 1.7 rjs const char *cardtype;
108 1.1 briggs
109 1.1 briggs bst = na->na_tag;
110 1.1 briggs if (bus_space_map(bst, NUBUS_SLOT2PA(na->slot), NBMEMSIZE, 0, &bsh)) {
111 1.1 briggs printf(": failed to map memory space.\n");
112 1.1 briggs return;
113 1.1 briggs }
114 1.1 briggs
115 1.1 briggs mac68k_bus_space_handle_swapped(bst, &bsh);
116 1.1 briggs
117 1.1 briggs smc->sc_bst = bst;
118 1.1 briggs smc->sc_bsh = bsh;
119 1.1 briggs
120 1.1 briggs cardtype = nubus_get_card_name(bst, bsh, na->fmt);
121 1.1 briggs
122 1.1 briggs success = 0;
123 1.1 briggs
124 1.1 briggs switch (na->drsw) {
125 1.1 briggs case NUBUS_DRSW_FOCUS:
126 1.1 briggs if (bus_space_subregion(bst, bsh, 0xFF8000, 0x20, &prom_bsh)) {
127 1.1 briggs printf(": failed to map EEPROM space.\n");
128 1.1 briggs break;
129 1.1 briggs }
130 1.1 briggs
131 1.1 briggs success = 1;
132 1.1 briggs break;
133 1.1 briggs case NUBUS_DRSW_ASANTEF:
134 1.1 briggs if (bus_space_subregion(bst, bsh, 0xFE0000, 0x20, &prom_bsh)) {
135 1.1 briggs printf(": failed to map EEPROM space.\n");
136 1.1 briggs break;
137 1.1 briggs }
138 1.1 briggs
139 1.1 briggs success = 1;
140 1.1 briggs break;
141 1.1 briggs }
142 1.1 briggs
143 1.1 briggs if (!success) {
144 1.1 briggs bus_space_unmap(bst, bsh, NBMEMSIZE);
145 1.1 briggs return;
146 1.1 briggs }
147 1.1 briggs for (i=0 ; i<6 ; i++) {
148 1.1 briggs myaddr[i] = bus_space_read_1(bst, prom_bsh, i*4);
149 1.1 briggs }
150 1.1 briggs
151 1.1 briggs smc->sc_flags |= SMC_FLAGS_ENABLED;
152 1.1 briggs
153 1.1 briggs printf(": %s\n", cardtype);
154 1.1 briggs
155 1.1 briggs smc91cxx_attach(smc, myaddr);
156 1.1 briggs
157 1.1 briggs add_nubus_intr(na->slot, (void (*)(void *))smc91cxx_intr, smc);
158 1.1 briggs }
159