aboutsummaryrefslogtreecommitdiff
path: root/sys/dev/ar/if_ar_isa.c
blob: afe36153d0d375b9643b425e41d3a8d5cb099b6b (plain) (blame)
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
/*-
 * Copyright (c) 1995 - 2001 John Hay.  All rights reserved.
 *
 * 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. Neither the name of the author nor the names of any co-contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY John Hay ``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 John Hay 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/cdefs.h>
__FBSDID("$FreeBSD$");

/*
 * Programming assumptions and other issues.
 *
 * The descriptors of a DMA channel will fit in a 16K memory window.
 *
 * The buffers of a transmit DMA channel will fit in a 16K memory window.
 *
 * Only the ISA bus cards with X.21 and V.35 is tested.
 *
 * When interface is going up, handshaking is set and it is only cleared
 * when the interface is down'ed.
 *
 * There should be a way to set/reset Raw HDLC/PPP, Loopback, DCE/DTE,
 * internal/external clock, etc.....
 */

#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/module.h>
#include <sys/bus.h>
#include <machine/bus.h>
#include <machine/resource.h>
#include <sys/rman.h>

#include <isa/isavar.h>
#include "isa_if.h"

#include <dev/ic/hd64570.h>
#include <dev/ar/if_arregs.h>

#ifdef TRACE
#define TRC(x)               x
#else
#define TRC(x)
#endif

#define TRCL(x)              x

static int ar_isa_probe (device_t);
static int ar_isa_attach (device_t);

static struct isa_pnp_id ar_ids[] = {
	{0,		NULL}
};

static device_method_t ar_methods[] = {
	DEVMETHOD(device_probe,		ar_isa_probe),
	DEVMETHOD(device_attach,	ar_isa_attach),
	DEVMETHOD(device_detach,	ar_detach),
	{ 0, 0 }
};

static driver_t ar_isa_driver = {
	"ar",
	ar_methods,
	sizeof (struct ar_hardc)
};

DRIVER_MODULE(ar, isa, ar_isa_driver, ar_devclass, 0, 0);
MODULE_DEPEND(ar, isa, 1, 1, 1);

/*
 * Probe to see if it is there.
 * Get its information and fill it in.
 */
static int
ar_isa_probe(device_t device)
{
	int error;
	u_long membase, memsize;
	struct ar_hardc *hc;

	error = ISA_PNP_PROBE(device_get_parent(device), device, ar_ids);
	if(error == ENXIO || error == 0)
		return (error);

	hc = (struct ar_hardc *)device_get_softc(device);

	if((error = ar_allocate_ioport(device, 0, ARC_IO_SIZ))) {
		return (ENXIO);
	}

	/*
	 * Now see if the card is realy there.
	 *
	 * XXX For now I just check the undocumented ports
	 * for "570". We will probably have to do more checking.
	 */
	if((ar_inb(hc, AR_ID_5) != '5') ||
	   (ar_inb(hc, AR_ID_7) != '7') ||
	   (ar_inb(hc, AR_ID_0) != '0')) {
		ar_deallocate_resources(device);
		return (ENXIO);
	}
	membase = bus_get_resource_start(device, SYS_RES_MEMORY, 0);
	memsize = ar_inb(hc, AR_REV);
	memsize = 1 << ((memsize & AR_WSIZ_MSK) >> AR_WSIZ_SHFT);
	memsize *= ARC_WIN_SIZ;
	error = bus_set_resource(device, SYS_RES_MEMORY, 0, membase, memsize);
	ar_deallocate_resources(device);

	return (error);
}

/*
 * Malloc memory for the softc structures.
 * Reset the card to put it in a known state.
 * Register the ports on the adapter.
 * Fill in the info for each port.
 * Attach each port to sppp and bpf.
 */
static int
ar_isa_attach(device_t device)
{
	u_int tmp;
	u_long irq, junk;
	struct ar_hardc *hc;

	hc = (struct ar_hardc *)device_get_softc(device);
	if(ar_allocate_ioport(device, 0, ARC_IO_SIZ))
		return (ENXIO);

	tmp = ar_inb(hc, AR_BMI);
	hc->bustype = tmp & AR_BUS_MSK;
	hc->memsize = (tmp & AR_MEM_MSK) >> AR_MEM_SHFT;
	hc->memsize = 1 << hc->memsize;
	hc->memsize <<= 16;
	hc->interface[0] = (tmp & AR_IFACE_MSK);
	hc->interface[1] = hc->interface[0];
	hc->interface[2] = hc->interface[0];
	hc->interface[3] = hc->interface[0];
	tmp = ar_inb(hc, AR_REV);
	hc->revision = tmp & AR_REV_MSK;
	hc->winsize = 1 << ((tmp & AR_WSIZ_MSK) >> AR_WSIZ_SHFT);
	hc->winsize *= ARC_WIN_SIZ;
	hc->winmsk = hc->winsize - 1;
	hc->numports = ar_inb(hc, AR_PNUM);
	hc->handshake = ar_inb(hc, AR_HNDSH);

	if(ar_allocate_memory(device, 0, hc->winsize))
		return (ENXIO);

	hc->mem_start = rman_get_virtual(hc->res_memory);
	hc->mem_end = hc->mem_start + hc->winsize;
	hc->cunit = device_get_unit(device);

	switch(hc->interface[0]) {
	case AR_IFACE_EIA_232:
		printf("ar%d: The EIA 232 interface is not supported.\n",
			hc->cunit);
		ar_deallocate_resources(device);
		return (ENXIO);
	case AR_IFACE_V_35:
		break;
	case AR_IFACE_EIA_530:
		printf("ar%d: WARNING: The EIA 530 interface is untested.\n",
			hc->cunit);
		break;
	case AR_IFACE_X_21:
		break;
	case AR_IFACE_COMBO:
		printf("ar%d: WARNING: The COMBO interface is untested.\n",
			hc->cunit);
		break;
	}

	/*
	 * Do a little sanity check.
	 */
	if((hc->numports > NPORT) || (hc->memsize > (512*1024))) {
		ar_deallocate_resources(device);
		return (ENXIO);
	}

	if(ar_allocate_irq(device, 0, 1))
		return (ENXIO);

	if(bus_get_resource(device, SYS_RES_IRQ, 0, &irq, &junk)) {
		ar_deallocate_resources(device);
		return (ENXIO);
	}
	hc->isa_irq = irq;

	if(ar_attach(device)) {
		ar_deallocate_resources(device);
		return (ENXIO);
	}

	return (0);
}

/*
 ********************************* END ************************************
 */