if_sn_jazzio.c revision 1.16
11.16Sthorpej/*	$NetBSD: if_sn_jazzio.c,v 1.16 2023/12/20 06:36:02 thorpej Exp $	*/
21.1Sthorpej
31.1Sthorpej/*-
41.1Sthorpej * Copyright (c) 2001 The NetBSD Foundation, Inc.
51.1Sthorpej * All rights reserved.
61.1Sthorpej *
71.1Sthorpej * This code is derived from software contributed to The NetBSD Foundation
81.1Sthorpej * by Jason R. Thorpe.
91.1Sthorpej *
101.1Sthorpej * Redistribution and use in source and binary forms, with or without
111.1Sthorpej * modification, are permitted provided that the following conditions
121.1Sthorpej * are met:
131.1Sthorpej * 1. Redistributions of source code must retain the above copyright
141.1Sthorpej *    notice, this list of conditions and the following disclaimer.
151.1Sthorpej * 2. Redistributions in binary form must reproduce the above copyright
161.1Sthorpej *    notice, this list of conditions and the following disclaimer in the
171.1Sthorpej *    documentation and/or other materials provided with the distribution.
181.1Sthorpej *
191.1Sthorpej * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
201.1Sthorpej * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
211.1Sthorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
221.1Sthorpej * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
231.1Sthorpej * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
241.1Sthorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
251.1Sthorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
261.1Sthorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
271.1Sthorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
281.1Sthorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
291.1Sthorpej * POSSIBILITY OF SUCH DAMAGE.
301.1Sthorpej */
311.1Sthorpej
321.1Sthorpej/*
331.15Smsaitoh * Microsoft JAZZ front-end for the National Semiconductor DP83932
341.1Sthorpej * Systems-Oriented Network Interface Controller (SONIC).
351.1Sthorpej */
361.5Slukem
371.5Slukem#include <sys/cdefs.h>
381.16Sthorpej__KERNEL_RCSID(0, "$NetBSD: if_sn_jazzio.c,v 1.16 2023/12/20 06:36:02 thorpej Exp $");
391.1Sthorpej
401.1Sthorpej#include <sys/param.h>
411.1Sthorpej#include <sys/systm.h>
421.1Sthorpej#include <sys/mbuf.h>
431.1Sthorpej#include <sys/kernel.h>
441.1Sthorpej#include <sys/socket.h>
451.1Sthorpej#include <sys/ioctl.h>
461.1Sthorpej#include <sys/errno.h>
471.1Sthorpej#include <sys/device.h>
481.1Sthorpej#include <sys/kcore.h>
491.1Sthorpej
501.14Srin#include <sys/rndsource.h>
511.14Srin
521.1Sthorpej#include <net/if.h>
531.1Sthorpej#include <net/if_dl.h>
541.1Sthorpej#include <net/if_ether.h>
551.1Sthorpej
561.1Sthorpej#include <machine/autoconf.h>
571.13Sdyoung#include <sys/bus.h>
581.1Sthorpej#include <machine/intr.h>
591.1Sthorpej
601.1Sthorpej#include <dev/ic/dp83932reg.h>
611.1Sthorpej#include <dev/ic/dp83932var.h>
621.1Sthorpej
631.1Sthorpej#include <arc/arc/arcbios.h>
641.1Sthorpej#include <arc/jazz/jazziovar.h>
651.1Sthorpej
661.10Stsutsuiint	sonic_jazzio_match(device_t, cfdata_t, void *);
671.10Stsutsuivoid	sonic_jazzio_attach(device_t, device_t, void *);
681.1Sthorpej
691.10StsutsuiCFATTACH_DECL_NEW(sn_jazzio, sizeof(struct sonic_softc),
701.3Sthorpej    sonic_jazzio_match, sonic_jazzio_attach, NULL, NULL);
711.1Sthorpej
721.1Sthorpejint
731.10Stsutsuisonic_jazzio_match(device_t parent, cfdata_t cf, void *aux)
741.1Sthorpej{
751.1Sthorpej	struct jazzio_attach_args *ja = aux;
761.1Sthorpej
771.4Stsutsui	if (strcmp(ja->ja_name, "SONIC") != 0)
781.6Stsutsui		return 0;
791.1Sthorpej
801.6Stsutsui	return 1;
811.1Sthorpej}
821.1Sthorpej
831.1Sthorpejvoid
841.10Stsutsuisonic_jazzio_attach(device_t parent, device_t self, void *aux)
851.1Sthorpej{
861.10Stsutsui	struct sonic_softc *sc = device_private(self);
871.1Sthorpej	struct jazzio_attach_args *ja = aux;
881.1Sthorpej	int i;
891.1Sthorpej	uint8_t enaddr[ETHER_ADDR_LEN];
901.1Sthorpej
911.10Stsutsui	sc->sc_dev = self;
921.1Sthorpej	sc->sc_st = ja->ja_bust;
931.1Sthorpej	sc->sc_dmat = ja->ja_dmat;
941.1Sthorpej
951.10Stsutsui	aprint_normal(": SONIC Ethernet\n");
961.1Sthorpej
971.1Sthorpej	/* Map the device. */
981.1Sthorpej	if (bus_space_map(sc->sc_st, ja->ja_addr, SONIC_NREGS * 4,
991.1Sthorpej	    0, &sc->sc_sh) != 0) {
1001.10Stsutsui		aprint_error_dev(sc->sc_dev, "unable to map SONIC registers\n");
1011.1Sthorpej		return;
1021.1Sthorpej	}
1031.1Sthorpej
1041.1Sthorpej	/* We run in 32-bit mode. */
1051.1Sthorpej	sc->sc_32bit = 1;
1061.1Sthorpej
1071.1Sthorpej	/* BMODE is set for little-endian. */
1081.1Sthorpej	sc->sc_bigendian = 0;
1091.1Sthorpej
1101.1Sthorpej	/* Regs are 16-bit, plus 16-bit pad. */
1111.1Sthorpej	for (i = 0; i < SONIC_NREGS; i++)
1121.1Sthorpej		sc->sc_regmap[i] = i * 4;
1131.1Sthorpej
1141.1Sthorpej	/*
1151.1Sthorpej	 * Configure DCR:
1161.1Sthorpej	 *
1171.1Sthorpej	 *	- Latched bug retry
1181.1Sthorpej	 *	- Synchronous bus (memory cycle 2 clocks)
1191.1Sthorpej	 *	- 0 wait states added (WC0,WC1 == 0,0)
1201.8Stsutsui	 *	- 4 byte Rx DMA threshold (RFT0,RFT1 == 0,0)
1211.8Stsutsui	 *	- 28 byte Tx DMA threshold (TFT0,TFT1 == 1,1)
1221.8Stsutsui	 *	  XXX There was a comment
1231.8Stsutsui	 *	  	"XXX RFT & TFT according to MIPS manual"
1241.8Stsutsui	 *	      in old MD sys/arch/arc/dev/if_sn.c in Attic.
1251.1Sthorpej	 */
1261.8Stsutsui	sc->sc_dcr = DCR_LBR | DCR_SBUS | DCR_TFT0 | DCR_TFT1;
1271.1Sthorpej	sc->sc_dcr2 = 0;
1281.1Sthorpej
1291.1Sthorpej	/* Hook up our interrupt handler. */
1301.1Sthorpej	jazzio_intr_establish(ja->ja_intr, sonic_intr, sc);
1311.1Sthorpej
1321.1Sthorpej	/* The Ethernet address is from the product ID. */
1331.1Sthorpej	memcpy(enaddr, arc_product_id, sizeof(enaddr));
1341.1Sthorpej
1351.1Sthorpej	/* Finish off the attach. */
1361.1Sthorpej	sonic_attach(sc, enaddr);
1371.1Sthorpej}
138