1 /* $NetBSD: if_tr_mca.c,v 1.20 2009/05/12 13:15:24 cegger Exp $ */
4 * Copyright (c) 2000 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Gregory McGarry <g.mcgarry@ieee.org>.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
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.
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.
32 #include <sys/cdefs.h>
33 __KERNEL_RCSID(0, "$NetBSD: if_tr_mca.c,v 1.20 2009/05/12 13:15:24 cegger Exp $");
35 #include <sys/param.h>
36 #include <sys/systm.h>
37 #include <sys/socket.h>
38 #include <sys/device.h>
40 #include <dev/mca/mcareg.h>
41 #include <dev/mca/mcavar.h>
42 #include <dev/mca/mcadevs.h>
45 #include <net/if_media.h>
46 #include <net/if_ether.h>
48 #include <dev/ic/tropicreg.h>
49 #include <dev/ic/tropicvar.h>
52 #define DPRINTF(x) printf x
57 #define TR_PRI_IOADDR 0x0a20
58 #define TR_ALT_IOADDR 0x0a24
60 #define TR_MMIOSIZE 8192
64 int tr_mca_probe(device_t
, cfdata_t
, void *);
65 void tr_mca_attach(device_t
, device_t
, void *);
67 CFATTACH_DECL(tr_mca
, sizeof(struct tr_softc
),
68 tr_mca_probe
, tr_mca_attach
, NULL
, NULL
);
70 /* supported products */
71 static const struct tr_mca_product
{
74 } tr_mca_products
[] = {
75 { MCA_PRODUCT_ITR
, "IBM Token Ring 16/4 Adapter/A" },
79 static const struct tr_mca_product
*tr_mca_lookup(int);
81 static const struct tr_mca_product
*
84 const struct tr_mca_product
*trp
;
86 for(trp
= tr_mca_products
; trp
->tr_name
; trp
++)
94 tr_mca_probe(device_t parent
, cfdata_t match
,
97 struct mca_attach_args
*ma
= aux
;
99 if (tr_mca_lookup(ma
->ma_id
) != NULL
)
107 tr_mca_attach(device_t parent
, device_t self
, void *aux
)
109 struct tr_softc
*sc
= device_private(self
);
110 struct mca_attach_args
*ma
= aux
;
111 bus_space_handle_t pioh
, mmioh
, sramh
;
112 int iobase
, irq
, sram_size
, sram_addr
, rom_addr
;
113 int pos2
, pos3
, pos4
, pos5
;
114 const struct tr_mca_product
*tp
;
116 pos2
= mca_conf_read(ma
->ma_mc
, ma
->ma_slot
, 2);
117 pos3
= mca_conf_read(ma
->ma_mc
, ma
->ma_slot
, 3);
118 pos4
= mca_conf_read(ma
->ma_mc
, ma
->ma_slot
, 4);
119 pos5
= mca_conf_read(ma
->ma_mc
, ma
->ma_slot
, 5);
122 * POS register 2: (adf pos0)
125 * \___________/ \__ enable: 0=adapter disabled, 1=adapter enabled
126 * \__________ RAM addr: pos2&0xfe
128 * POS register 3: (adf pos1)
131 * | \___/ | | | \__ port address: 1=0x0a24-0x0a27, 0=0x0a20-0x0a23
132 * | | \ / \____ speed: 0=4Mbps, 1=16Mbps
133 * | | \_______ RAM size: 00=8kb, 01=16kb, 10=32kb, 11=64kb
134 * | \____________ reserved: 010
135 * \________________ irq component: 0=2, 1=3 (see also pos4)
137 * POS register 4: (adf pos2)
140 * \___________/ \__ interrupt controller: 0=1st, 1=2nd
141 * \__________ ROM address: pos4&0xfe
143 * POS register 5: (adf pos3)
147 * | | \_____ reserved: 0x0
148 * | \__________ autosense: 0=off, 1=on
149 * \____________ boot rom: 0=enabled, 1=disabled
153 iobase
= TR_ALT_IOADDR
;
155 iobase
= TR_PRI_IOADDR
;
157 irq
= 2 + (pos3
>> 7) + ((pos4
& 0x01) << 3);
161 tp
= tr_mca_lookup(ma
->ma_id
);
163 printf(" slot %d irq %d: %s\n", ma
->ma_slot
+ 1, irq
, tp
->tr_name
);
165 sram_size
= 8 << (((pos3
& 0x0c) >> 2) + 10);
166 sram_addr
= (pos2
& 0xfe) << 12;
168 rom_addr
= (pos4
& 0xfe) << 12;
170 /* map the pio registers */
171 if (bus_space_map(ma
->ma_iot
, iobase
, TR_PIOSIZE
, 0, &pioh
)) {
172 aprint_error_dev(&sc
->sc_dev
, "unable to map PIO space\n");
176 /* map the mmio registers */
177 if (bus_space_map(ma
->ma_memt
, rom_addr
, TR_MMIOSIZE
, 0, &mmioh
)) {
178 aprint_error_dev(&sc
->sc_dev
, "unable to map MMIO space\n");
182 /* map the sram space */
183 if (bus_space_map(ma
->ma_memt
, sram_addr
, sram_size
, 0, &sramh
)) {
184 aprint_error_dev(&sc
->sc_dev
, "unable to map SRAM space\n");
188 sc
->sc_piot
= ma
->ma_iot
;
190 sc
->sc_memt
= ma
->ma_memt
;
191 sc
->sc_mmioh
= mmioh
;
192 sc
->sc_sramh
= sramh
;
195 sc
->sc_aca
= TR_ACA_OFFSET
;
196 sc
->sc_memwinsz
= sram_size
;
197 sc
->sc_maddr
= sram_addr
;
200 * Determine total RAM on adapter and decide how much to use.
201 * XXX Since we don't use RAM paging, use sc_memwinsz for now.
203 sc
->sc_memsize
= sc
->sc_memwinsz
;
204 sc
->sc_memreserved
= 0;
206 if (tr_reset(sc
) != 0)
209 /* XXX not implemented (yet) */
210 sc
->sc_mediastatus
= NULL
;
211 sc
->sc_mediachange
= NULL
;
213 /* do generic attach */
214 if (tr_attach(sc
) != 0)
217 /* establish interrupt handler */
218 sc
->sc_ih
= mca_intr_establish(ma
->ma_mc
, irq
, IPL_NET
, tr_intr
, sc
);
219 if (sc
->sc_ih
== NULL
) {
220 aprint_error_dev(&sc
->sc_dev
, "couldn't establish interrupt handler\n");