if_sn_jazzio.c revision 1.10
11.10Stsutsui/*	$NetBSD: if_sn_jazzio.c,v 1.10 2008/04/23 13:29:45 tsutsui 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 * 3. All advertising materials mentioning features or use of this software
191.1Sthorpej *    must display the following acknowledgement:
201.1Sthorpej *	This product includes software developed by the NetBSD
211.1Sthorpej *	Foundation, Inc. and its contributors.
221.1Sthorpej * 4. Neither the name of The NetBSD Foundation nor the names of its
231.1Sthorpej *    contributors may be used to endorse or promote products derived
241.1Sthorpej *    from this software without specific prior written permission.
251.1Sthorpej *
261.1Sthorpej * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
271.1Sthorpej * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
281.1Sthorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
291.1Sthorpej * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
301.1Sthorpej * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
311.1Sthorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
321.1Sthorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
331.1Sthorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
341.1Sthorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
351.1Sthorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
361.1Sthorpej * POSSIBILITY OF SUCH DAMAGE.
371.1Sthorpej */
381.1Sthorpej
391.1Sthorpej/*
401.1Sthorpej * Microsoft JAZZ front-end for for the National Semiconductor DP83932
411.1Sthorpej * Systems-Oriented Network Interface Controller (SONIC).
421.1Sthorpej */
431.5Slukem
441.5Slukem#include <sys/cdefs.h>
451.10Stsutsui__KERNEL_RCSID(0, "$NetBSD: if_sn_jazzio.c,v 1.10 2008/04/23 13:29:45 tsutsui Exp $");
461.1Sthorpej
471.1Sthorpej#include "bpfilter.h"
481.1Sthorpej
491.1Sthorpej#include <sys/param.h>
501.1Sthorpej#include <sys/systm.h>
511.1Sthorpej#include <sys/mbuf.h>
521.1Sthorpej#include <sys/malloc.h>
531.1Sthorpej#include <sys/kernel.h>
541.1Sthorpej#include <sys/socket.h>
551.1Sthorpej#include <sys/ioctl.h>
561.1Sthorpej#include <sys/errno.h>
571.1Sthorpej#include <sys/device.h>
581.1Sthorpej#include <sys/kcore.h>
591.1Sthorpej
601.1Sthorpej#include <net/if.h>
611.1Sthorpej#include <net/if_dl.h>
621.1Sthorpej#include <net/if_ether.h>
631.1Sthorpej
641.1Sthorpej#include <machine/autoconf.h>
651.1Sthorpej#include <machine/bus.h>
661.1Sthorpej#include <machine/intr.h>
671.1Sthorpej
681.1Sthorpej#include <dev/ic/dp83932reg.h>
691.1Sthorpej#include <dev/ic/dp83932var.h>
701.1Sthorpej
711.1Sthorpej#include <arc/arc/arcbios.h>
721.1Sthorpej#include <arc/jazz/jazziovar.h>
731.1Sthorpej
741.10Stsutsuiint	sonic_jazzio_match(device_t, cfdata_t, void *);
751.10Stsutsuivoid	sonic_jazzio_attach(device_t, device_t, void *);
761.1Sthorpej
771.10StsutsuiCFATTACH_DECL_NEW(sn_jazzio, sizeof(struct sonic_softc),
781.3Sthorpej    sonic_jazzio_match, sonic_jazzio_attach, NULL, NULL);
791.1Sthorpej
801.1Sthorpejint
811.10Stsutsuisonic_jazzio_match(device_t parent, cfdata_t cf, void *aux)
821.1Sthorpej{
831.1Sthorpej	struct jazzio_attach_args *ja = aux;
841.1Sthorpej
851.4Stsutsui	if (strcmp(ja->ja_name, "SONIC") != 0)
861.6Stsutsui		return 0;
871.1Sthorpej
881.6Stsutsui	return 1;
891.1Sthorpej}
901.1Sthorpej
911.1Sthorpejvoid
921.10Stsutsuisonic_jazzio_attach(device_t parent, device_t self, void *aux)
931.1Sthorpej{
941.10Stsutsui	struct sonic_softc *sc = device_private(self);
951.1Sthorpej	struct jazzio_attach_args *ja = aux;
961.1Sthorpej	int i;
971.1Sthorpej	uint8_t enaddr[ETHER_ADDR_LEN];
981.1Sthorpej
991.10Stsutsui	sc->sc_dev = self;
1001.1Sthorpej	sc->sc_st = ja->ja_bust;
1011.1Sthorpej	sc->sc_dmat = ja->ja_dmat;
1021.1Sthorpej
1031.10Stsutsui	aprint_normal(": SONIC Ethernet\n");
1041.1Sthorpej
1051.1Sthorpej	/* Map the device. */
1061.1Sthorpej	if (bus_space_map(sc->sc_st, ja->ja_addr, SONIC_NREGS * 4,
1071.1Sthorpej	    0, &sc->sc_sh) != 0) {
1081.10Stsutsui		aprint_error_dev(sc->sc_dev, "unable to map SONIC registers\n");
1091.1Sthorpej		return;
1101.1Sthorpej	}
1111.1Sthorpej
1121.1Sthorpej	/* We run in 32-bit mode. */
1131.1Sthorpej	sc->sc_32bit = 1;
1141.1Sthorpej
1151.1Sthorpej	/* BMODE is set for little-endian. */
1161.1Sthorpej	sc->sc_bigendian = 0;
1171.1Sthorpej
1181.1Sthorpej	/* Regs are 16-bit, plus 16-bit pad. */
1191.1Sthorpej	for (i = 0; i < SONIC_NREGS; i++)
1201.1Sthorpej		sc->sc_regmap[i] = i * 4;
1211.1Sthorpej
1221.1Sthorpej	/*
1231.1Sthorpej	 * Configure DCR:
1241.1Sthorpej	 *
1251.1Sthorpej	 *	- Latched bug retry
1261.1Sthorpej	 *	- Synchronous bus (memory cycle 2 clocks)
1271.1Sthorpej	 *	- 0 wait states added (WC0,WC1 == 0,0)
1281.8Stsutsui	 *	- 4 byte Rx DMA threshold (RFT0,RFT1 == 0,0)
1291.8Stsutsui	 *	- 28 byte Tx DMA threshold (TFT0,TFT1 == 1,1)
1301.8Stsutsui	 *	  XXX There was a comment
1311.8Stsutsui	 *	  	"XXX RFT & TFT according to MIPS manual"
1321.8Stsutsui	 *	      in old MD sys/arch/arc/dev/if_sn.c in Attic.
1331.1Sthorpej	 */
1341.8Stsutsui	sc->sc_dcr = DCR_LBR | DCR_SBUS | DCR_TFT0 | DCR_TFT1;
1351.1Sthorpej	sc->sc_dcr2 = 0;
1361.1Sthorpej
1371.1Sthorpej	/* Hook up our interrupt handler. */
1381.1Sthorpej	jazzio_intr_establish(ja->ja_intr, sonic_intr, sc);
1391.1Sthorpej
1401.1Sthorpej	/* The Ethernet address is from the product ID. */
1411.1Sthorpej	memcpy(enaddr, arc_product_id, sizeof(enaddr));
1421.1Sthorpej
1431.1Sthorpej	/* Finish off the attach. */
1441.1Sthorpej	sonic_attach(sc, enaddr);
1451.1Sthorpej}
146