xref: /openbsd-src/sys/dev/sbus/if_ti_sbus.c (revision 22e452df2392a375fd2998343a374f72c327cac3)
1 /*	$OpenBSD: if_ti_sbus.c,v 1.5 2022/03/13 13:34:54 mpi Exp $	*/
2 /*
3  * Copyright (c) 2009 Mark Kettenis
4  *
5  * Permission to use, copy, modify, and distribute this software for any
6  * purpose with or without fee is hereby granted, provided that the above
7  * copyright notice and this permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16  */
17 
18 #include <sys/param.h>
19 #include <sys/device.h>
20 #include <sys/socket.h>
21 #include <sys/systm.h>
22 
23 #include <net/if.h>
24 #include <net/if_media.h>
25 
26 #include <netinet/in.h>
27 #include <netinet/if_ether.h>
28 
29 #include <machine/bus.h>
30 #include <machine/intr.h>
31 #include <machine/autoconf.h>
32 
33 #include <dev/sbus/sbusvar.h>
34 
35 #include <dev/pci/pcireg.h>
36 
37 #include <dev/ic/tireg.h>
38 #include <dev/ic/tivar.h>
39 
40 struct ti_sbus_softc {
41 	struct ti_softc		tsc_sc;
42 };
43 
44 int	ti_sbus_match(struct device *, void *, void *);
45 void	ti_sbus_attach(struct device *, struct device *, void *);
46 
47 const struct cfattach ti_sbus_ca = {
48 	sizeof(struct ti_sbus_softc), ti_sbus_match, ti_sbus_attach
49 };
50 
51 int
ti_sbus_match(struct device * parent,void * match,void * aux)52 ti_sbus_match(struct device *parent, void *match, void *aux)
53 {
54 	struct sbus_attach_args *sa = aux;
55 
56 	return (strcmp("SUNW,vge", sa->sa_name) == 0);
57 }
58 
59 void
ti_sbus_attach(struct device * parent,struct device * self,void * aux)60 ti_sbus_attach(struct device *parent, struct device *self, void *aux)
61 {
62 	struct sbus_attach_args *sa = aux;
63 	struct ti_sbus_softc *tsc = (void *)self;
64 	struct ti_softc *sc = &tsc->tsc_sc;
65 	bus_space_handle_t ioh;
66 
67 	/* Pass on the bus tags */
68 	sc->ti_btag = sa->sa_bustag;
69 	sc->sc_dmatag = sa->sa_dmatag;
70 
71 	if (sa->sa_nintr < 1) {
72                 printf(": no interrupt\n");
73                 return;
74         }
75 
76 	if (sa->sa_nreg < 2) {
77                 printf(": only %d register sets\n", sa->sa_nreg);
78 		return;
79 	}
80 
81 	if (sbus_bus_map(sa->sa_bustag, sa->sa_reg[1].sbr_slot,
82 	    sa->sa_reg[1].sbr_offset, sa->sa_reg[1].sbr_size,
83 	    0, 0, &sc->ti_bhandle)) {
84 		printf(": can't map registers\n");
85 		return;
86 	}
87 
88 	if (sbus_bus_map(sa->sa_bustag, sa->sa_reg[0].sbr_slot,
89 	    sa->sa_reg[0].sbr_offset, sa->sa_reg[0].sbr_size,
90 	    0, 0, &ioh)) {
91 		printf(": can't map registers\n");
92 		goto unmap;
93 	}
94 
95 	bus_intr_establish(sa->sa_bustag, sa->sa_pri, IPL_NET, 0, ti_intr,
96 	    sc, self->dv_xname);
97 
98 	bus_space_write_4(sa->sa_bustag, ioh, TI_PCI_CMDSTAT, 0x02000006);
99 	bus_space_write_4(sa->sa_bustag, ioh, TI_PCI_BIST, 0xffffffff);
100 	bus_space_write_4(sa->sa_bustag, ioh, TI_PCI_LOMEM, 0x00000400);
101 
102 	bus_space_unmap(sa->sa_bustag, ioh, sa->sa_reg[0].sbr_size);
103 
104 	sc->ti_sbus = 1;
105 	if (ti_attach(sc) == 0)
106 		return;
107 
108 unmap:
109 	    bus_space_unmap(sa->sa_bustag, sc->ti_bhandle,
110 		sa->sa_reg[1].sbr_size);
111 }
112