summaryrefslogtreecommitdiff
path: root/sys/dev/mca/if_tra_mca.c
blob: 64edcd19d1cf63bb42341a23ef9d7b4cca9d1e53 (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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
/*	$NetBSD: if_tra_mca.c,v 1.18 2016/07/11 11:31:51 msaitoh Exp $	*/

/*-
 * Copyright (c) 2004 The NetBSD Foundation, Inc.
 * All rights reserved.
 *
 * This code is derived from software contributed to The NetBSD Foundation
 * by Jaromir Dolecek.
 *
 * 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.
 *
 * 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.
 */

/*
 * Driver for Tiara LANCard/E II and friends adapted from if_ate_mca.c
 * by Dave J. Barnes 2004.
 */

#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: if_tra_mca.c,v 1.18 2016/07/11 11:31:51 msaitoh Exp $");

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

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

#include <sys/bus.h>
#include <sys/intr.h>

#include <dev/ic/mb86950reg.h>
#include <dev/ic/mb86950var.h>

#include <dev/mca/mcavar.h>
#include <dev/mca/mcadevs.h>

int	tiara_mca_match(device_t, cfdata_t, void *);
void	tiara_mca_attach(device_t, device_t, void *);

#define TIARA_NPORTS 0x20 /* 32 */
#define TIARA_PROM_ID 24 /* offset to mac addr stored in prom */

struct tiara_softc {
	struct	mb86950_softc sc_mb86950;	/* real "mb86950" softc */

	/* MCA-specific goo. */
	void	*sc_ih;				/* interrupt cookie */
};

CFATTACH_DECL_NEW(tra_mca, sizeof(struct tiara_softc),
    tiara_mca_match, tiara_mca_attach, NULL, NULL);

static const struct tiara_mca_product {
	u_int32_t	tra_prodid;	/* MCA product ID */
	const char	*tra_name;	/* device name */
} tiara_mca_products[] = {
	{ MCA_PRODUCT_TIARA,	"Tiara LANCard/E2"},
	{ MCA_PRODUCT_TIARA_TP,	"Tiara LANCard/E2 TP"},
	{ MCA_PRODUCT_SMC3016,  "SMC 3016/MC"},
	{ 0,			NULL },
};

static const struct tiara_mca_product *tiara_mca_lookup(u_int32_t);

static const struct tiara_mca_product *
tiara_mca_lookup(u_int32_t id)
{
	const struct tiara_mca_product *tra_p;

	for (tra_p = tiara_mca_products; tra_p->tra_name != NULL; tra_p++)
		if (id == tra_p->tra_prodid)
			return (tra_p);

	return (NULL);
}

int
tiara_mca_match(device_t parent, cfdata_t match, void *aux)
{
	struct mca_attach_args *ma = (struct mca_attach_args *) aux;

	if (tiara_mca_lookup(ma->ma_id) != NULL)
		return (1);

	return (0);
}

/* see POS diagrams below for explanation */
static const int tiara_irq[] = {
	3, 4, 7, 9
};
static const int smc_iobase[] = {
	0x300, 0x340, 0x360, 0x1980, 0x2000, 0x5680, 0x5900, 0x8080
};
static const int smc_irq[] = {
	9, 10, 11, 15, 3, 5, 7, 4
};

void
tiara_mca_attach(device_t parent, device_t self, void *aux)
{
	struct tiara_softc *isc = device_private(self);
	struct mb86950_softc *sc = &isc->sc_mb86950;
	struct mca_attach_args *ma = aux;
	bus_space_tag_t iot = ma->ma_iot;
	bus_space_handle_t ioh;
	u_int8_t myea[ETHER_ADDR_LEN];
	int pos2;
	int iobase = 0, irq = 0;
	const struct tiara_mca_product *tra_p;

	pos2 = mca_conf_read(ma->ma_mc, ma->ma_slot, 2);

	tra_p = tiara_mca_lookup(ma->ma_id);

	switch (tra_p->tra_prodid) {

	case MCA_PRODUCT_TIARA:
	case MCA_PRODUCT_TIARA_TP:
		/*
		 * POS register 2: (adf pos0)
		 * 7 6 5 4 3 2 1 0
		 * \_____/ \_/  \ \__ enable: 0=disabled, 1=enabled
		 *       \   \   \___ boot rom: 0=disabled, 1=enabled
		 *        \   \______ IRQ 00=3 01=4 10=7 11=9
		 *         \_________ Base I/O Port
		 *			0000=0x1200 0001=0x1220 ... 1110=0x13c0 1111=0x13e0
		 *
		 * POS register 3: (adf pos1) not used
		 * POS register 4: (adf pos2) not used
		 *
		 * POS register 5: (adf pos3) ignored
		 *
		 * 7 6 5 4 3 2 1 0
		 * 1 1 0 X \____/
		 *              \____EPROM Address
		 */
		iobase = 0x1200 + ((pos2 & 0xf0) << 1);
		irq = tiara_irq[((pos2 & 0x0c) >> 2)];

		/* XXX SWAG for number pkts. */
		/* My Tiara LANCard has 128K memory ?!? */
		sc->txb_num_pkt = 4;
		sc->rxb_num_pkt = (65535 - 8192 - 4) / 64;
		/* XXX                       */

		break;

	case MCA_PRODUCT_SMC3016:
		/*
		 * POS register 2: (adf pos0)
		 * 7 6 5 4 3 2 1 0
		 * \_____/ \___/  \__ enable: 0=disabled, 1=enabled
		 *       \     \_____ I/O Address (see ioaddr table)
		 *        \__________ IRQ (see irq table)
		 *
		 * POS register 3: (adf pos1) ignored
		 * 7 6 5 4 3 2 1 0
		 * X X X X \____/
		 *              \____EPROM Address (0000 = not used)
		 */
		iobase = smc_iobase[((pos2 & 0x0e) >> 1)];
		if ((pos2 & 0x80) != 0)
			irq = smc_irq[((pos2 & 0x70) >> 4)];
		else {
			aprint_error_dev(self, "unsupported irq selected\n");
			return;
		}

		/* XXX SWAG for number pkts. */
		/* The SMC3016 has a 12K rx buffer and a 4k tx buffer */
		sc->txb_num_pkt = 2;
		sc->rxb_num_pkt = (12288 - 4) / 64;
		/* XXX                       */

		break;
	}


#ifdef DIAGNOSTIC
	tra_p = tiara_mca_lookup(ma->ma_id);
	if (tra_p == NULL) {
		aprint_normal("\n");
		aprint_error_dev(self, "where did the card go?\n");
		return;
	}
#endif

	printf(" slot %d ports %#x-%#x irq %d: %s\n", ma->ma_slot + 1,iobase,
	    iobase + TIARA_NPORTS, irq, tra_p->tra_name);

	/* Map i/o space. */
	if (bus_space_map(iot, iobase, TIARA_NPORTS, 0, &ioh)) {
		aprint_error_dev(self, "can't map i/o space\n");
		return;
	}

	sc->sc_dev = self;
	sc->sc_bst = iot;
	sc->sc_bsh = ioh;

	/* Get ethernet address from PROM */
	bus_space_read_region_1(iot, ioh, TIARA_PROM_ID, myea, ETHER_ADDR_LEN);

	/* This interface is always enabled. */
	/* XXX
	sc->sc_stat |= NIC_STAT_ENABLED;
	*/

	/*
	 * Do generic MB86950 attach.
	 */
	mb86950_attach(sc, myea);


	mb86950_config(sc, NULL, 0, 0);

	/* Establish the interrupt handler. */
	isc->sc_ih = mca_intr_establish(ma->ma_mc, irq, IPL_NET,
			mb86950_intr, sc);
	if (isc->sc_ih == NULL) {
		aprint_error_dev(self,
		    "couldn't establish interrupt handler\n");
		return;
	}
}