1 /*	$NetBSD: if_en.c,v 1.29 2011/07/18 00:58:52 mrg Exp $	*/
2 
3 /*
4  * Copyright (c) 1996 Charles D. Cranor and Washington University.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 /*
29  *
30  * i f _ e n _ s b u s . c
31  *
32  * author: Chuck Cranor <chuck@ccrc.wustl.edu>
33  * started: spring, 1996.
34  *
35  * SBUS glue for the eni155s card.
36  */
37 
38 #include <sys/cdefs.h>
39 __KERNEL_RCSID(0, "$NetBSD: if_en.c,v 1.29 2011/07/18 00:58:52 mrg Exp $");
40 
41 #include <sys/param.h>
42 #include <sys/systm.h>
43 #include <sys/device.h>
44 #include <sys/mbuf.h>
45 #include <sys/socket.h>
46 #include <sys/socketvar.h>
47 
48 #include <net/if.h>
49 
50 #include <sys/bus.h>
51 #include <sys/intr.h>
52 #include <sys/cpu.h>
53 
54 #include <dev/sbus/sbusvar.h>
55 
56 #include <dev/ic/midwayreg.h>
57 #include <dev/ic/midwayvar.h>
58 
59 
60 /*
61  * prototypes
62  */
63 static	int en_sbus_match(device_t, cfdata_t, void *);
64 static	void en_sbus_attach(device_t, device_t, void *);
65 
66 /*
67  * SBus autoconfig attachments
68  */
69 
70 CFATTACH_DECL_NEW(en_sbus, sizeof(struct en_softc),
71     en_sbus_match, en_sbus_attach, NULL, NULL);
72 
73 /***********************************************************************/
74 
75 /*
76  * autoconfig stuff
77  */
78 
79 static int
en_sbus_match(device_t parent,cfdata_t cf,void * aux)80 en_sbus_match(device_t parent, cfdata_t cf, void *aux)
81 {
82 	struct sbus_attach_args *sa = aux;
83 
84 	if (strcmp("ENI-155s", sa->sa_name) == 0)  {
85 		if (CPU_ISSUN4M) {
86 #ifdef DEBUG
87 			printf("%s: sun4m DMA not supported yet\n",
88 			    sa->sa_name);
89 #endif
90 			return (0);
91 		}
92 		return (1);
93 	} else {
94 		return (0);
95 	}
96 }
97 
98 
99 static void
en_sbus_attach(device_t parent,device_t self,void * aux)100 en_sbus_attach(device_t parent, device_t self, void *aux)
101 {
102 	struct sbus_attach_args *sa = aux;
103 	struct en_softc *sc = device_private(self);
104 
105 	sc->sc_dev = self;
106 
107 	printf("\n");
108 
109 	if (sbus_bus_map(sa->sa_bustag,
110 			 sa->sa_slot,
111 			 sa->sa_offset,
112 			 4*1024*1024,
113 			 0, &sc->en_base) != 0) {
114 		aprint_error_dev(self, "cannot map registers\n");
115 		return;
116 	}
117 
118 	/* Establish interrupt handler */
119 	if (sa->sa_nintr != 0)
120 		(void)bus_intr_establish(sa->sa_bustag, sa->sa_pri,
121 					 IPL_NET, en_intr, sc);
122 
123 	sc->ipl = sa->sa_pri;	/* appropriate? */
124 
125 	/*
126 	 * done SBUS specific stuff
127 	 */
128 	en_attach(sc);
129 }
130