xref: /netbsd-src/sys/arch/amiga/dev/xsurf.c (revision 23e63c4b5cecc703250c97faac1ad970f4954821)
1 /*	$NetBSD: xsurf.c,v 1.6 2023/12/20 00:40:42 thorpej Exp $ */
2 
3 /*-
4  * Copyright (c) 1998 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Bernd Ernesti.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #include <sys/cdefs.h>
33 __KERNEL_RCSID(0, "$NetBSD: xsurf.c,v 1.6 2023/12/20 00:40:42 thorpej Exp $");
34 
35 /*
36  * X-Surf driver, split from ne_zbus.
37  */
38 
39 #include <sys/param.h>
40 #include <sys/device.h>
41 #include <sys/mbuf.h>
42 #include <sys/socket.h>
43 #include <sys/syslog.h>
44 #include <sys/systm.h>
45 #include <sys/bus.h>
46 
47 #include <net/if.h>
48 #include <net/if_media.h>
49 #include <net/if_ether.h>
50 
51 #include <dev/ic/dp8390reg.h>
52 #include <dev/ic/dp8390var.h>
53 
54 #include <dev/ic/ne2000reg.h>
55 #include <dev/ic/ne2000var.h>
56 
57 #include <dev/ic/rtl80x9reg.h>
58 #include <dev/ic/rtl80x9var.h>
59 
60 #include <amiga/amiga/device.h>
61 #include <amiga/amiga/isr.h>
62 
63 #include <amiga/dev/zbusvar.h>
64 #include <amiga/dev/xsurfvar.h>
65 
66 //#include <amiga/clockport/clockportvar.h>
67 
68 int	xsurf_match(device_t, cfdata_t , void *);
69 void	xsurf_attach(device_t, device_t, void *);
70 static int xsurf_print(void *aux, const char *w);
71 
72 struct xsurf_softc {
73 	device_t sc_dev;
74 };
75 
76 CFATTACH_DECL_NEW(xsurf, sizeof(struct xsurf_softc),
77     xsurf_match, xsurf_attach, NULL, NULL);
78 
79 #define XSURF_NE_OFFSET		0x8000
80 #define XSURF_WDC_OFFSET	0xB000
81 
82 /*
83  * Clockport offsets.
84  */
85 #define XSURF_CP1_BASE		0xA001
86 #define XSURF_CP2_BASE		0xC000
87 
88 /*
89  * E3B Deneb firmware v11 creates fake X-Surf autoconfig entry.
90  * Do not attach ne driver to this fake card, otherwise kernel panic
91  * may occur.
92  */
93 #define DENEB_XSURF_SERNO	0xC0FFEE01	/* Serial of the fake card */
94 
95 int
xsurf_match(device_t parent,cfdata_t cf,void * aux)96 xsurf_match(device_t parent, cfdata_t cf, void *aux)
97 {
98 	struct zbus_args *zap = aux;
99 
100 	/* X-surf ethernet card */
101 	if (zap->manid == 4626 && zap->prodid == 23) {
102 			return (1);
103 	}
104 
105 	return (0);
106 }
107 
108 /*
109  * Install interface into kernel networking data structures.
110  */
111 void
xsurf_attach(device_t parent,device_t self,void * aux)112 xsurf_attach(device_t parent, device_t self, void *aux)
113 {
114 	struct xsurf_softc *sc;
115 	struct xsurfbus_attach_args xaa_ne;
116 	struct xsurfbus_attach_args xaa_gencp1;
117 	struct xsurfbus_attach_args xaa_gencp2;
118 	struct xsurfbus_attach_args xaa_wdc;
119 
120 	struct zbus_args *zap = aux;
121 
122 	sc = device_private(self);
123 	sc->sc_dev = self;
124 
125 	aprint_normal(": Individual Computers X-Surf\n");
126 
127 	/* Add clockport. */
128 	xaa_gencp1.xaa_base = (bus_addr_t)zap->va + XSURF_CP2_BASE;
129 	strcpy(xaa_gencp1.xaa_name, "gencp_xsurf");
130 	config_found(sc->sc_dev, &xaa_gencp1, xsurf_print, CFARGS_NONE);
131 
132 	/* Now... if we are a fake X-Surf that's enough. */
133 	if (zap->serno == DENEB_XSURF_SERNO) {
134 		aprint_naive_dev(sc->sc_dev, "fake X-Surf on E3B Deneb");
135 		return;
136 	}
137 
138 	/* Otherwise add one more clockport and continue... */
139 	xaa_gencp2.xaa_base = (bus_addr_t)zap->va + XSURF_CP1_BASE;
140 	strcpy(xaa_gencp2.xaa_name, "gencp_xsurf");
141 	config_found(sc->sc_dev, &xaa_gencp2, xsurf_print, CFARGS_NONE);
142 
143 	/* Add ne(4). */
144 	xaa_ne.xaa_base = (bus_addr_t)zap->va + XSURF_NE_OFFSET;
145 	strcpy(xaa_ne.xaa_name, "ne_xsurf");
146 	config_found(sc->sc_dev, &xaa_ne, xsurf_print, CFARGS_NONE);
147 
148 	/* Add wdc(4). */
149 	xaa_wdc.xaa_base = (bus_addr_t)zap->va + XSURF_WDC_OFFSET;
150 	strcpy(xaa_wdc.xaa_name, "wdc_xsurf");
151 	config_found(sc->sc_dev, &xaa_wdc, xsurf_print, CFARGS_NONE);
152 
153 }
154 
155 static int
xsurf_print(void * aux,const char * w)156 xsurf_print(void *aux, const char *w)
157 {
158 	if (w == NULL)
159 		return 0;
160 
161 	return 0;
162 }
163 
164