if_sm_nubus.c revision 1.1 1 1.1 briggs /* $NetBSD: if_sm_nubus.c,v 1.1 2000/07/30 21:43:40 briggs 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.1 briggs
30 1.1 briggs #include "opt_inet.h"
31 1.1 briggs
32 1.1 briggs #include <sys/param.h>
33 1.1 briggs #include <sys/device.h>
34 1.1 briggs #include <sys/errno.h>
35 1.1 briggs #include <sys/ioctl.h>
36 1.1 briggs #include <sys/socket.h>
37 1.1 briggs #include <sys/syslog.h>
38 1.1 briggs #include <sys/systm.h>
39 1.1 briggs
40 1.1 briggs #include <net/if.h>
41 1.1 briggs #include <net/if_ether.h>
42 1.1 briggs #include <net/if_media.h>
43 1.1 briggs
44 1.1 briggs #include <machine/bus.h>
45 1.1 briggs #include <machine/viareg.h>
46 1.1 briggs
47 1.1 briggs #include <dev/mii/mii.h>
48 1.1 briggs #include <dev/mii/miivar.h>
49 1.1 briggs
50 1.1 briggs #include <dev/ic/smc91cxxreg.h>
51 1.1 briggs #include <dev/ic/smc91cxxvar.h>
52 1.1 briggs
53 1.1 briggs #include <mac68k/nubus/nubus.h>
54 1.1 briggs
55 1.1 briggs static int sm_nubus_match __P((struct device *, struct cfdata *, void *));
56 1.1 briggs static void sm_nubus_attach __P((struct device *, struct device *, void *));
57 1.1 briggs
58 1.1 briggs struct cfattach sm_nubus_ca = {
59 1.1 briggs sizeof(struct smc91cxx_softc), sm_nubus_match, sm_nubus_attach
60 1.1 briggs };
61 1.1 briggs
62 1.1 briggs static int
63 1.1 briggs sm_nubus_match(parent, cf, aux)
64 1.1 briggs struct device *parent;
65 1.1 briggs struct cfdata *cf;
66 1.1 briggs void *aux;
67 1.1 briggs {
68 1.1 briggs struct nubus_attach_args *na = (struct nubus_attach_args *) aux;
69 1.1 briggs bus_space_handle_t bsh;
70 1.1 briggs int rv;
71 1.1 briggs
72 1.1 briggs if (bus_space_map(na->na_tag,
73 1.1 briggs NUBUS_SLOT2PA(na->slot), NBMEMSIZE, 0, &bsh))
74 1.1 briggs return (0);
75 1.1 briggs
76 1.1 briggs rv = 0;
77 1.1 briggs
78 1.1 briggs if (na->category == NUBUS_CATEGORY_NETWORK &&
79 1.1 briggs na->type == NUBUS_TYPE_ETHERNET) {
80 1.1 briggs switch (na->drsw) {
81 1.1 briggs case NUBUS_DRSW_FOCUS:
82 1.1 briggs case NUBUS_DRSW_ASANTEF:
83 1.1 briggs rv = 1;
84 1.1 briggs break;
85 1.1 briggs default:
86 1.1 briggs rv = 0;
87 1.1 briggs break;
88 1.1 briggs }
89 1.1 briggs }
90 1.1 briggs
91 1.1 briggs bus_space_unmap(na->na_tag, bsh, NBMEMSIZE);
92 1.1 briggs
93 1.1 briggs return rv;
94 1.1 briggs }
95 1.1 briggs
96 1.1 briggs /*
97 1.1 briggs * Install interface into kernel networking data structures
98 1.1 briggs */
99 1.1 briggs static void
100 1.1 briggs sm_nubus_attach(parent, self, aux)
101 1.1 briggs struct device *parent, *self;
102 1.1 briggs void *aux;
103 1.1 briggs {
104 1.1 briggs struct smc91cxx_softc *smc = (struct smc91cxx_softc *) self;
105 1.1 briggs struct nubus_attach_args *na = (struct nubus_attach_args *)aux;
106 1.1 briggs bus_space_tag_t bst = na->na_tag;
107 1.1 briggs bus_space_handle_t bsh, prom_bsh;
108 1.1 briggs u_int8_t myaddr[ETHER_ADDR_LEN];
109 1.1 briggs int i, success;
110 1.1 briggs char *cardtype;
111 1.1 briggs
112 1.1 briggs bst = na->na_tag;
113 1.1 briggs if (bus_space_map(bst, NUBUS_SLOT2PA(na->slot), NBMEMSIZE, 0, &bsh)) {
114 1.1 briggs printf(": failed to map memory space.\n");
115 1.1 briggs return;
116 1.1 briggs }
117 1.1 briggs
118 1.1 briggs mac68k_bus_space_handle_swapped(bst, &bsh);
119 1.1 briggs bsh.bsrm2 = mac68k_bsrm2;
120 1.1 briggs bsh.bsrm4 = mac68k_bsrm4;
121 1.1 briggs bsh.bswm2 = mac68k_bswm2;
122 1.1 briggs bsh.bswm4 = mac68k_bswm4;
123 1.1 briggs
124 1.1 briggs smc->sc_bst = bst;
125 1.1 briggs smc->sc_bsh = bsh;
126 1.1 briggs
127 1.1 briggs cardtype = nubus_get_card_name(bst, bsh, na->fmt);
128 1.1 briggs
129 1.1 briggs success = 0;
130 1.1 briggs
131 1.1 briggs switch (na->drsw) {
132 1.1 briggs case NUBUS_DRSW_FOCUS:
133 1.1 briggs if (bus_space_subregion(bst, bsh, 0xFF8000, 0x20, &prom_bsh)) {
134 1.1 briggs printf(": failed to map EEPROM space.\n");
135 1.1 briggs break;
136 1.1 briggs }
137 1.1 briggs
138 1.1 briggs success = 1;
139 1.1 briggs break;
140 1.1 briggs case NUBUS_DRSW_ASANTEF:
141 1.1 briggs if (bus_space_subregion(bst, bsh, 0xFE0000, 0x20, &prom_bsh)) {
142 1.1 briggs printf(": failed to map EEPROM space.\n");
143 1.1 briggs break;
144 1.1 briggs }
145 1.1 briggs
146 1.1 briggs success = 1;
147 1.1 briggs break;
148 1.1 briggs }
149 1.1 briggs
150 1.1 briggs if (!success) {
151 1.1 briggs bus_space_unmap(bst, bsh, NBMEMSIZE);
152 1.1 briggs return;
153 1.1 briggs }
154 1.1 briggs for (i=0 ; i<6 ; i++) {
155 1.1 briggs myaddr[i] = bus_space_read_1(bst, prom_bsh, i*4);
156 1.1 briggs }
157 1.1 briggs
158 1.1 briggs smc->sc_flags |= SMC_FLAGS_ENABLED;
159 1.1 briggs
160 1.1 briggs printf(": %s\n", cardtype);
161 1.1 briggs
162 1.1 briggs smc91cxx_attach(smc, myaddr);
163 1.1 briggs
164 1.1 briggs add_nubus_intr(na->slot, (void (*)(void *))smc91cxx_intr, smc);
165 1.1 briggs }
166