1*8ff6f65dSthorpej /* $NetBSD: if_sn_jazzio.c,v 1.16 2023/12/20 06:36:02 thorpej Exp $ */
2833e756eSthorpej
3833e756eSthorpej /*-
4833e756eSthorpej * Copyright (c) 2001 The NetBSD Foundation, Inc.
5833e756eSthorpej * All rights reserved.
6833e756eSthorpej *
7833e756eSthorpej * This code is derived from software contributed to The NetBSD Foundation
8833e756eSthorpej * by Jason R. Thorpe.
9833e756eSthorpej *
10833e756eSthorpej * Redistribution and use in source and binary forms, with or without
11833e756eSthorpej * modification, are permitted provided that the following conditions
12833e756eSthorpej * are met:
13833e756eSthorpej * 1. Redistributions of source code must retain the above copyright
14833e756eSthorpej * notice, this list of conditions and the following disclaimer.
15833e756eSthorpej * 2. Redistributions in binary form must reproduce the above copyright
16833e756eSthorpej * notice, this list of conditions and the following disclaimer in the
17833e756eSthorpej * documentation and/or other materials provided with the distribution.
18833e756eSthorpej *
19833e756eSthorpej * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20833e756eSthorpej * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21833e756eSthorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22833e756eSthorpej * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23833e756eSthorpej * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24833e756eSthorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25833e756eSthorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26833e756eSthorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27833e756eSthorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28833e756eSthorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29833e756eSthorpej * POSSIBILITY OF SUCH DAMAGE.
30833e756eSthorpej */
31833e756eSthorpej
32833e756eSthorpej /*
33821e159cSmsaitoh * Microsoft JAZZ front-end for the National Semiconductor DP83932
34833e756eSthorpej * Systems-Oriented Network Interface Controller (SONIC).
35833e756eSthorpej */
36833e756eSthorpej
37a4183603Slukem #include <sys/cdefs.h>
38*8ff6f65dSthorpej __KERNEL_RCSID(0, "$NetBSD: if_sn_jazzio.c,v 1.16 2023/12/20 06:36:02 thorpej Exp $");
39833e756eSthorpej
40833e756eSthorpej #include <sys/param.h>
41833e756eSthorpej #include <sys/systm.h>
42833e756eSthorpej #include <sys/mbuf.h>
43833e756eSthorpej #include <sys/kernel.h>
44833e756eSthorpej #include <sys/socket.h>
45833e756eSthorpej #include <sys/ioctl.h>
46833e756eSthorpej #include <sys/errno.h>
47833e756eSthorpej #include <sys/device.h>
48833e756eSthorpej #include <sys/kcore.h>
49833e756eSthorpej
50c537dc44Srin #include <sys/rndsource.h>
51c537dc44Srin
52833e756eSthorpej #include <net/if.h>
53833e756eSthorpej #include <net/if_dl.h>
54833e756eSthorpej #include <net/if_ether.h>
55833e756eSthorpej
56833e756eSthorpej #include <machine/autoconf.h>
57cf10107dSdyoung #include <sys/bus.h>
58833e756eSthorpej #include <machine/intr.h>
59833e756eSthorpej
60833e756eSthorpej #include <dev/ic/dp83932reg.h>
61833e756eSthorpej #include <dev/ic/dp83932var.h>
62833e756eSthorpej
63833e756eSthorpej #include <arc/arc/arcbios.h>
64833e756eSthorpej #include <arc/jazz/jazziovar.h>
65833e756eSthorpej
663b31064cStsutsui int sonic_jazzio_match(device_t, cfdata_t, void *);
673b31064cStsutsui void sonic_jazzio_attach(device_t, device_t, void *);
68833e756eSthorpej
693b31064cStsutsui CFATTACH_DECL_NEW(sn_jazzio, sizeof(struct sonic_softc),
70c5e91d44Sthorpej sonic_jazzio_match, sonic_jazzio_attach, NULL, NULL);
71833e756eSthorpej
72833e756eSthorpej int
sonic_jazzio_match(device_t parent,cfdata_t cf,void * aux)733b31064cStsutsui sonic_jazzio_match(device_t parent, cfdata_t cf, void *aux)
74833e756eSthorpej {
75833e756eSthorpej struct jazzio_attach_args *ja = aux;
76833e756eSthorpej
77da446ea2Stsutsui if (strcmp(ja->ja_name, "SONIC") != 0)
787fe2a5a0Stsutsui return 0;
79833e756eSthorpej
807fe2a5a0Stsutsui return 1;
81833e756eSthorpej }
82833e756eSthorpej
83833e756eSthorpej void
sonic_jazzio_attach(device_t parent,device_t self,void * aux)843b31064cStsutsui sonic_jazzio_attach(device_t parent, device_t self, void *aux)
85833e756eSthorpej {
863b31064cStsutsui struct sonic_softc *sc = device_private(self);
87833e756eSthorpej struct jazzio_attach_args *ja = aux;
88833e756eSthorpej int i;
89833e756eSthorpej uint8_t enaddr[ETHER_ADDR_LEN];
90833e756eSthorpej
913b31064cStsutsui sc->sc_dev = self;
92833e756eSthorpej sc->sc_st = ja->ja_bust;
93833e756eSthorpej sc->sc_dmat = ja->ja_dmat;
94833e756eSthorpej
953b31064cStsutsui aprint_normal(": SONIC Ethernet\n");
96833e756eSthorpej
97833e756eSthorpej /* Map the device. */
98833e756eSthorpej if (bus_space_map(sc->sc_st, ja->ja_addr, SONIC_NREGS * 4,
99833e756eSthorpej 0, &sc->sc_sh) != 0) {
1003b31064cStsutsui aprint_error_dev(sc->sc_dev, "unable to map SONIC registers\n");
101833e756eSthorpej return;
102833e756eSthorpej }
103833e756eSthorpej
104833e756eSthorpej /* We run in 32-bit mode. */
105833e756eSthorpej sc->sc_32bit = 1;
106833e756eSthorpej
107833e756eSthorpej /* BMODE is set for little-endian. */
108833e756eSthorpej sc->sc_bigendian = 0;
109833e756eSthorpej
110833e756eSthorpej /* Regs are 16-bit, plus 16-bit pad. */
111833e756eSthorpej for (i = 0; i < SONIC_NREGS; i++)
112833e756eSthorpej sc->sc_regmap[i] = i * 4;
113833e756eSthorpej
114833e756eSthorpej /*
115833e756eSthorpej * Configure DCR:
116833e756eSthorpej *
117833e756eSthorpej * - Latched bug retry
118833e756eSthorpej * - Synchronous bus (memory cycle 2 clocks)
119833e756eSthorpej * - 0 wait states added (WC0,WC1 == 0,0)
120d851aeffStsutsui * - 4 byte Rx DMA threshold (RFT0,RFT1 == 0,0)
121d851aeffStsutsui * - 28 byte Tx DMA threshold (TFT0,TFT1 == 1,1)
122d851aeffStsutsui * XXX There was a comment
123d851aeffStsutsui * "XXX RFT & TFT according to MIPS manual"
124d851aeffStsutsui * in old MD sys/arch/arc/dev/if_sn.c in Attic.
125833e756eSthorpej */
126d851aeffStsutsui sc->sc_dcr = DCR_LBR | DCR_SBUS | DCR_TFT0 | DCR_TFT1;
127833e756eSthorpej sc->sc_dcr2 = 0;
128833e756eSthorpej
129833e756eSthorpej /* Hook up our interrupt handler. */
130833e756eSthorpej jazzio_intr_establish(ja->ja_intr, sonic_intr, sc);
131833e756eSthorpej
132833e756eSthorpej /* The Ethernet address is from the product ID. */
133833e756eSthorpej memcpy(enaddr, arc_product_id, sizeof(enaddr));
134833e756eSthorpej
135833e756eSthorpej /* Finish off the attach. */
136833e756eSthorpej sonic_attach(sc, enaddr);
137833e756eSthorpej }
138