summaryrefslogtreecommitdiff
path: root/sys/dev/isa/if_tribm_isa.c
blob: 57cfc1c5b949add3f2063bece3fb3bc35d298211 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
/*	$OpenBSD: if_tribm_isa.c,v 1.3 2002/03/14 01:26:56 millert Exp $	*/
/*	$NetBSD: if_tribm_isa.c,v 1.2 1999/03/22 23:01:37 bad Exp $	*/

/*
 * Copyright (c) 1999 The NetBSD Foundation, Inc.
 * All rights reserved.
 *
 * This code is derived from software contributed to The NetBSD Foundation
 * by Onno van der Linden.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *        This product includes software developed by The NetBSD
 *        Foundation, Inc. and its contributors.
 * 4. Neither the name of The NetBSD Foundation nor the names of its 
 *    contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#include <sys/param.h>
#include <sys/systm.h>
#include <sys/socket.h>
#include <sys/device.h>
#include <sys/timeout.h>

#include <net/if.h>
#include <net/if_media.h>
#include <netinet/in.h>
#include <netinet/if_ether.h>

#include <machine/bus.h>

#include <dev/isa/isavar.h>

#include <dev/ic/tropicreg.h>
#include <dev/ic/tropicvar.h>

int	tribm_isa_probe(struct device *, void *, void *);
int	tr_isa_map_io(struct isa_attach_args *, bus_space_handle_t *,
	    bus_space_handle_t *);
void	tr_isa_unmap_io(struct isa_attach_args *, bus_space_handle_t,
	    bus_space_handle_t);

int
tribm_isa_probe(parent, match, aux)
	struct device *parent;
	void *match, *aux;
{
	struct isa_attach_args *ia = aux;
	static int irq_f[4] = { 9, 3, 6, 7 };
	static int irq_e[4] = { 9, 3, 10, 11 };
	bus_space_tag_t piot = ia->ia_iot;
	bus_space_tag_t memt = ia->ia_memt;
	bus_space_handle_t pioh, mmioh;
	int i, irq;
	u_int8_t s;

#ifdef notyet
/* XXX Try both 0xa20 and 0xa24 and store that info like 3com */
	if (ia->ia_iobase == IOBASEUNK)
		ia->ia_iobase = 0xa20;
#else
	if (ia->ia_iobase == IOBASEUNK)
		return 0;
#endif

	ia->ia_iosize = 4;
	ia->ia_aux = NULL;

	if (tr_isa_map_io(ia, &pioh, &mmioh))
		return 0;

/*
 * F = Token-Ring Network PC Adapter
 *     Token-Ring Network PC Adapter II
 *     Token-Ring Network Adapter/A
 * E = Token-Ring Network 16/4 Adapter/A (long card)
 *     Token-Ring Network 16/4 Adapter
 * D = Token-Ring Network 16/4 Adapter/A (short card)
 *     16/4 ISA-16 Adapter
 * C = Auto 16/4 Token-Ring ISA Adapter
 *     Auto 16/4 Token-Ring MC Adapter
 */
/*
 * XXX Both 0xD and 0xC types should be able to use 16-bit read and writes
 */
	switch (bus_space_read_1(memt, mmioh, TR_TYP_OFFSET)) {
	case 0xF:
	case 0xE:
	case 0xD:
		if (ia->ia_maddr == MADDRUNK)
#ifdef notyet
			ia->ia_maddr = TR_SRAM_DEFAULT;
#else
			return 0;
#endif
		break;
	case 0xC:
		i = bus_space_read_1(memt, mmioh, TR_ACA_OFFSET) << 12;
		if (ia->ia_maddr == MADDRUNK)
			ia->ia_maddr = i;
		else if (ia->ia_maddr != i) {
			printf(
"tribm_isa_probe: sram mismatch; kernel configured %x != board configured %x\n",
				ia->ia_maddr, i);
			tr_isa_unmap_io(ia, pioh, mmioh);
			return 0;
		}
		break;
	default:
		printf("tribm_isa_probe: unknown type code %x\n",
		    bus_space_read_1(memt, mmioh, TR_TYP_OFFSET));
		tr_isa_unmap_io(ia, pioh, mmioh);
		return 0;
	}

	s = bus_space_read_1(piot, pioh, TR_SWITCH);

	switch (bus_space_read_1(memt, mmioh, TR_IRQ_OFFSET)) {
	case 0xF:
		irq = irq_f[s & 3];
		break;
	case 0xE:
		irq = irq_e[s & 3];
		break;
	default:
		printf("tribm_isa_probe: Unknown IRQ code %x\n",
		    bus_space_read_1(memt, mmioh, TR_IRQ_OFFSET));
		tr_isa_unmap_io(ia, pioh, mmioh);
		return 0;
	}

	if (ia->ia_irq == IRQUNK)
		ia->ia_irq = irq;
	else if (ia->ia_irq != irq) {
		printf(
"tribm_isa_probe: irq mismatch; kernel configured %d != board configured %d\n",
			ia->ia_irq, irq);
		tr_isa_unmap_io(ia, pioh, mmioh);
		return 0;
	}
/*
 * XXX 0x0c == MSIZEMASK (MSIZEBITS)
 */
	ia->ia_msize = 8192 <<
	    ((bus_space_read_1(memt, mmioh, TR_ACA_OFFSET + 1) & 0x0c) >> 2);
	tr_isa_unmap_io(ia, pioh, mmioh);
	/* Check alignment of membase. */
	if ((ia->ia_maddr & (ia->ia_msize-1)) != 0) {
		printf("tribm_isa_probe: SRAM unaligned 0x%04x/%d\n",
		    ia->ia_maddr, ia->ia_msize);
		return 0;
	}
 	return 1;
}