Home | History | Annotate | Line # | Download | only in dev
xsurf.c revision 1.5
      1 /*	$NetBSD: xsurf.c,v 1.5 2021/08/07 16:18: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.5 2021/08/07 16:18: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/malloc.h>
     42 #include <sys/mbuf.h>
     43 #include <sys/socket.h>
     44 #include <sys/syslog.h>
     45 #include <sys/systm.h>
     46 #include <sys/bus.h>
     47 
     48 #include <net/if.h>
     49 #include <net/if_media.h>
     50 #include <net/if_ether.h>
     51 
     52 #include <dev/ic/dp8390reg.h>
     53 #include <dev/ic/dp8390var.h>
     54 
     55 #include <dev/ic/ne2000reg.h>
     56 #include <dev/ic/ne2000var.h>
     57 
     58 #include <dev/ic/rtl80x9reg.h>
     59 #include <dev/ic/rtl80x9var.h>
     60 
     61 #include <amiga/amiga/device.h>
     62 #include <amiga/amiga/isr.h>
     63 
     64 #include <amiga/dev/zbusvar.h>
     65 #include <amiga/dev/xsurfvar.h>
     66 
     67 //#include <amiga/clockport/clockportvar.h>
     68 
     69 int	xsurf_match(device_t, cfdata_t , void *);
     70 void	xsurf_attach(device_t, device_t, void *);
     71 static int xsurf_print(void *aux, const char *w);
     72 
     73 struct xsurf_softc {
     74 	device_t sc_dev;
     75 };
     76 
     77 CFATTACH_DECL_NEW(xsurf, sizeof(struct xsurf_softc),
     78     xsurf_match, xsurf_attach, NULL, NULL);
     79 
     80 #define XSURF_NE_OFFSET		0x8000
     81 #define XSURF_WDC_OFFSET	0xB000
     82 
     83 /*
     84  * Clockport offsets.
     85  */
     86 #define XSURF_CP1_BASE		0xA001
     87 #define XSURF_CP2_BASE		0xC000
     88 
     89 /*
     90  * E3B Deneb firmware v11 creates fake X-Surf autoconfig entry.
     91  * Do not attach ne driver to this fake card, otherwise kernel panic
     92  * may occur.
     93  */
     94 #define DENEB_XSURF_SERNO	0xC0FFEE01	/* Serial of the fake card */
     95 
     96 int
     97 xsurf_match(device_t parent, cfdata_t cf, void *aux)
     98 {
     99 	struct zbus_args *zap = aux;
    100 
    101 	/* X-surf ethernet card */
    102 	if (zap->manid == 4626 && zap->prodid == 23) {
    103 			return (1);
    104 	}
    105 
    106 	return (0);
    107 }
    108 
    109 /*
    110  * Install interface into kernel networking data structures.
    111  */
    112 void
    113 xsurf_attach(device_t parent, device_t self, void *aux)
    114 {
    115 	struct xsurf_softc *sc;
    116 	struct xsurfbus_attach_args xaa_ne;
    117 	struct xsurfbus_attach_args xaa_gencp1;
    118 	struct xsurfbus_attach_args xaa_gencp2;
    119 	struct xsurfbus_attach_args xaa_wdc;
    120 
    121 	struct zbus_args *zap = aux;
    122 
    123 	sc = device_private(self);
    124 	sc->sc_dev = self;
    125 
    126 	aprint_normal(": Individual Computers X-Surf\n");
    127 
    128 	/* Add clockport. */
    129 	xaa_gencp1.xaa_base = (bus_addr_t)zap->va + XSURF_CP2_BASE;
    130 	strcpy(xaa_gencp1.xaa_name, "gencp_xsurf");
    131 	config_found(sc->sc_dev, &xaa_gencp1, xsurf_print, CFARGS_NONE);
    132 
    133 	/* Now... if we are a fake X-Surf that's enough. */
    134 	if (zap->serno == DENEB_XSURF_SERNO) {
    135 		aprint_naive_dev(sc->sc_dev, "fake X-Surf on E3B Deneb");
    136 		return;
    137 	}
    138 
    139 	/* Otherwise add one more clockport and continue... */
    140 	xaa_gencp2.xaa_base = (bus_addr_t)zap->va + XSURF_CP1_BASE;
    141 	strcpy(xaa_gencp2.xaa_name, "gencp_xsurf");
    142 	config_found(sc->sc_dev, &xaa_gencp2, xsurf_print, CFARGS_NONE);
    143 
    144 	/* Add ne(4). */
    145 	xaa_ne.xaa_base = (bus_addr_t)zap->va + XSURF_NE_OFFSET;
    146 	strcpy(xaa_ne.xaa_name, "ne_xsurf");
    147 	config_found(sc->sc_dev, &xaa_ne, xsurf_print, CFARGS_NONE);
    148 
    149 	/* Add wdc(4). */
    150 	xaa_wdc.xaa_base = (bus_addr_t)zap->va + XSURF_WDC_OFFSET;
    151 	strcpy(xaa_wdc.xaa_name, "wdc_xsurf");
    152 	config_found(sc->sc_dev, &xaa_wdc, xsurf_print, CFARGS_NONE);
    153 
    154 }
    155 
    156 static int
    157 xsurf_print(void *aux, const char *w)
    158 {
    159 	if (w == NULL)
    160 		return 0;
    161 
    162 	return 0;
    163 }
    164 
    165