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