if_sn_jazzio.c revision 1.14
1/* $NetBSD: if_sn_jazzio.c,v 1.14 2021/02/20 09:36:30 rin Exp $ */ 2 3/*- 4 * Copyright (c) 2001 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Jason R. Thorpe. 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/* 33 * Microsoft JAZZ front-end for for the National Semiconductor DP83932 34 * Systems-Oriented Network Interface Controller (SONIC). 35 */ 36 37#include <sys/cdefs.h> 38__KERNEL_RCSID(0, "$NetBSD: if_sn_jazzio.c,v 1.14 2021/02/20 09:36:30 rin Exp $"); 39 40#include <sys/param.h> 41#include <sys/systm.h> 42#include <sys/mbuf.h> 43#include <sys/malloc.h> 44#include <sys/kernel.h> 45#include <sys/socket.h> 46#include <sys/ioctl.h> 47#include <sys/errno.h> 48#include <sys/device.h> 49#include <sys/kcore.h> 50 51#include <sys/rndsource.h> 52 53#include <net/if.h> 54#include <net/if_dl.h> 55#include <net/if_ether.h> 56 57#include <machine/autoconf.h> 58#include <sys/bus.h> 59#include <machine/intr.h> 60 61#include <dev/ic/dp83932reg.h> 62#include <dev/ic/dp83932var.h> 63 64#include <arc/arc/arcbios.h> 65#include <arc/jazz/jazziovar.h> 66 67int sonic_jazzio_match(device_t, cfdata_t, void *); 68void sonic_jazzio_attach(device_t, device_t, void *); 69 70CFATTACH_DECL_NEW(sn_jazzio, sizeof(struct sonic_softc), 71 sonic_jazzio_match, sonic_jazzio_attach, NULL, NULL); 72 73int 74sonic_jazzio_match(device_t parent, cfdata_t cf, void *aux) 75{ 76 struct jazzio_attach_args *ja = aux; 77 78 if (strcmp(ja->ja_name, "SONIC") != 0) 79 return 0; 80 81 return 1; 82} 83 84void 85sonic_jazzio_attach(device_t parent, device_t self, void *aux) 86{ 87 struct sonic_softc *sc = device_private(self); 88 struct jazzio_attach_args *ja = aux; 89 int i; 90 uint8_t enaddr[ETHER_ADDR_LEN]; 91 92 sc->sc_dev = self; 93 sc->sc_st = ja->ja_bust; 94 sc->sc_dmat = ja->ja_dmat; 95 96 aprint_normal(": SONIC Ethernet\n"); 97 98 /* Map the device. */ 99 if (bus_space_map(sc->sc_st, ja->ja_addr, SONIC_NREGS * 4, 100 0, &sc->sc_sh) != 0) { 101 aprint_error_dev(sc->sc_dev, "unable to map SONIC registers\n"); 102 return; 103 } 104 105 /* We run in 32-bit mode. */ 106 sc->sc_32bit = 1; 107 108 /* BMODE is set for little-endian. */ 109 sc->sc_bigendian = 0; 110 111 /* Regs are 16-bit, plus 16-bit pad. */ 112 for (i = 0; i < SONIC_NREGS; i++) 113 sc->sc_regmap[i] = i * 4; 114 115 /* 116 * Configure DCR: 117 * 118 * - Latched bug retry 119 * - Synchronous bus (memory cycle 2 clocks) 120 * - 0 wait states added (WC0,WC1 == 0,0) 121 * - 4 byte Rx DMA threshold (RFT0,RFT1 == 0,0) 122 * - 28 byte Tx DMA threshold (TFT0,TFT1 == 1,1) 123 * XXX There was a comment 124 * "XXX RFT & TFT according to MIPS manual" 125 * in old MD sys/arch/arc/dev/if_sn.c in Attic. 126 */ 127 sc->sc_dcr = DCR_LBR | DCR_SBUS | DCR_TFT0 | DCR_TFT1; 128 sc->sc_dcr2 = 0; 129 130 /* Hook up our interrupt handler. */ 131 jazzio_intr_establish(ja->ja_intr, sonic_intr, sc); 132 133 /* The Ethernet address is from the product ID. */ 134 memcpy(enaddr, arc_product_id, sizeof(enaddr)); 135 136 /* Finish off the attach. */ 137 sonic_attach(sc, enaddr); 138} 139