Home | History | Annotate | Line # | Download | only in ofw
      1 /*	$NetBSD: if_cs_ofisa_machdep.c,v 1.14 2020/11/22 03:57:19 thorpej Exp $	*/
      2 
      3 /*
      4  * Copyright 1998
      5  * Digital Equipment Corporation. All rights reserved.
      6  *
      7  * This software is furnished under license and may be used and
      8  * copied only in accordance with the following terms and conditions.
      9  * Subject to these conditions, you may download, copy, install,
     10  * use, modify and distribute this software in source and/or binary
     11  * form. No title or ownership is transferred hereby.
     12  *
     13  * 1) Any source code used, modified or distributed must reproduce
     14  *    and retain this copyright notice and list of conditions as
     15  *    they appear in the source file.
     16  *
     17  * 2) No right is granted to use any trade name, trademark, or logo of
     18  *    Digital Equipment Corporation. Neither the "Digital Equipment
     19  *    Corporation" name nor any trademark or logo of Digital Equipment
     20  *    Corporation may be used to endorse or promote products derived
     21  *    from this software without the prior written permission of
     22  *    Digital Equipment Corporation.
     23  *
     24  * 3) This software is provided "AS-IS" and any express or implied
     25  *    warranties, including but not limited to, any implied warranties
     26  *    of merchantability, fitness for a particular purpose, or
     27  *    non-infringement are disclaimed. In no event shall DIGITAL be
     28  *    liable for any damages whatsoever, and in particular, DIGITAL
     29  *    shall not be liable for special, indirect, consequential, or
     30  *    incidental damages or damages for lost profits, loss of
     31  *    revenue or loss of use, whether such damages arise in contract,
     32  *    negligence, tort, under statute, in equity, at law or otherwise,
     33  *    even if advised of the possibility of such damage.
     34  */
     35 
     36 /*
     37  * WARNING: THIS FILE IS VERY SHARK-SPECIFIC!
     38  */
     39 
     40 #include <sys/cdefs.h>
     41 __KERNEL_RCSID(0, "$NetBSD: if_cs_ofisa_machdep.c,v 1.14 2020/11/22 03:57:19 thorpej Exp $");
     42 
     43 #include "opt_compat_old_ofw.h"
     44 
     45 #include <sys/param.h>
     46 #include <sys/device.h>
     47 #include <sys/systm.h>
     48 #include <sys/kmem.h>
     49 #include <sys/socket.h>
     50 #include <sys/bus.h>
     51 #include <sys/rndsource.h>
     52 
     53 #include <net/if.h>
     54 #include <net/if_ether.h>
     55 #include <net/if_media.h>
     56 
     57 #include <machine/intr.h>
     58 
     59 #include <dev/ofw/openfirm.h>
     60 #include <dev/isa/isavar.h>
     61 #include <dev/ofisa/ofisavar.h>
     62 
     63 #include <dev/ic/cs89x0reg.h>
     64 #include <dev/ic/cs89x0var.h>
     65 
     66 #ifdef COMPAT_OLD_OFW
     67 
     68 int
     69 cs_ofisa_md_match(device_t parent, cfdata_t cf, void *aux)
     70 {
     71 	struct ofisa_attach_args *aa = aux;
     72 	char type[64];
     73 	char name[64];
     74 	char model[64];
     75 	char compatible[64];
     76 	int rv;
     77 
     78 	rv = 0;
     79 	if (1) {		/* XXX old firmware compat enabled */
     80 		/* At a minimum, must match type and name properties. */
     81 		if (OF_getprop(aa->oba.oba_phandle, "device_type", type,
     82 		    sizeof(type)) < 0 || strcmp(type, "network") != 0 ||
     83 		    OF_getprop(aa->oba.oba_phandle, "name", name,
     84 		    sizeof(name)) < 0 || strcmp(name, "ethernet") != 0)
     85 			return (0);
     86 
     87 		/* Full match on model. */
     88 		if (OF_getprop(aa->oba.oba_phandle, "model", model,
     89 		    sizeof(model)) > 0 && strcmp(model, "CS8900") == 0)
     90 			rv = 3;
     91 
     92 		/* Check for compatible match. */
     93 		if (OF_getprop(aa->oba.oba_phandle, "compatible", compatible,
     94 		    sizeof(compatible)) > 0 && pmatch(compatible, "*CS8900*",
     95 		    NULL) > 0)
     96 			rv = 2;
     97 	}
     98 	return (rv);
     99 }
    100 
    101 int
    102 cs_ofisa_md_reg_fixup(device_t parent, device_t self, void *aux,
    103     struct ofisa_reg_desc *descp, int ndescs, int ndescsfilled)
    104 {
    105 
    106 	if (1) {		/* XXX old firmware compat enabled */
    107 		/* We can't provide it. */
    108 		if (ndescs != 2)
    109 			return (ndescsfilled);
    110 
    111 		/* Firmware provided it. */
    112 		if (ndescsfilled == 2)
    113 			return (ndescsfilled);
    114 
    115 		descp[0].type = OFISA_REG_TYPE_IO;
    116 		descp[0].addr = 0x300;
    117 		descp[0].len  = CS8900_IOSIZE;
    118 
    119 		descp[1].type = OFISA_REG_TYPE_MEM;
    120 		descp[1].addr = 0xd0000;
    121 		descp[1].len  = 4096;
    122 	}
    123 	return (ndescsfilled);
    124 }
    125 
    126 int
    127 cs_ofisa_md_intr_fixup(device_t parent, device_t self, void *aux,
    128     struct ofisa_intr_desc *descp, int ndescs, int ndescsfilled)
    129 {
    130 
    131 	if (1)			/* XXX old firmware compat enabled */
    132 	if (ndescs > 0 && ndescsfilled > 0)
    133                 descp[0].share = IST_LEVEL;
    134 	return (ndescsfilled);
    135 }
    136 
    137 int *
    138 cs_ofisa_md_media_fixup(device_t parent, device_t self, void *aux, int *media,
    139     int *nmediap, int *defmediap)
    140 {
    141 
    142 	if (1) {		/* XXX old firmware compat enabled */
    143 		if (media == NULL) {
    144 			media = kmem_alloc(2 * sizeof(int), KM_SLEEP);
    145 			media[0] = IFM_ETHER | IFM_10_T;
    146 			media[1] = IFM_ETHER | IFM_10_T | IFM_FDX;
    147 			*nmediap = 2;
    148 			*defmediap = media[0];
    149 		}
    150 	}
    151 	return (media);
    152 }
    153 
    154 int
    155 cs_ofisa_md_dma_fixup(device_t parent, device_t self, void *aux,
    156     struct ofisa_dma_desc *descp, int ndescs, int ndescsfilled)
    157 {
    158 	struct ofisa_attach_args *aa = aux;
    159 
    160 	if (ndescs > 0 && ndescsfilled > 0) {
    161 		if (OF_getproplen(aa->oba.oba_phandle, "no-dma") >= 0)
    162 			descp[0].drq = -1;
    163 	}
    164 	return (ndescsfilled);
    165 }
    166 
    167 #endif /* COMPAT_OLD_OFW */
    168 
    169 int
    170 cs_ofisa_md_cfgflags_fixup(device_t parent, device_t self, void *aux)
    171 {
    172 
    173 	return (CFGFLG_USE_SA | CFGFLG_IOCHRDY | CFGFLG_NOT_EEPROM);
    174 }
    175