summaryrefslogtreecommitdiff
path: root/sys/dev/isa/if_rln_isa.c
blob: 874df69165cf3cdffc96169e17405f62e0661c16 (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
/*	$OpenBSD: if_rln_isa.c,v 1.2 2002/03/14 01:26:56 millert Exp $	*/

/*
 * David Leonard <d@openbsd.org>, 1999. Public domain.
 *
 * RangeLAN2 ISA card.
 *
 * The DIP switch settings on the card to set the i/o base address are
 *
 *     addr: 1 2 3 4 5 6 7  ['X' = on = down = towards the red/green leds]
 *	100: - - - - - X -
 *	120: - - X - - X -
 *	140: - - - X - X -
 *	218: X X - - - - X
 *	270: - X X X - - X  [default]
 *	280: - - - - X - X
 *	290: - X - - X - X
 *	298: X X - - X - X
 *	2a0: - - X - X - X
 *	2a8: X - X - X - X
 *	2e0: - - X X X - X
 *	300: - - - - - X X
 *	310: - X - - - X X
 *	358: X X - X - X X
 *	360: - - X X - X X
 *	368: X - X X - X X
 *
 * PnP:
 *	PXM0100 "Symphony Cordless PnP ISA Card"
 */

#include "bpfilter.h"

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

#include <net/if.h>

#ifdef INET
#include <netinet/in.h>
#include <netinet/if_ether.h>
#endif

#include <machine/cpu.h>
#include <machine/bus.h>
#include <machine/intr.h>

#include <dev/ic/rln.h>
#include <dev/ic/rlnvar.h>
#include <dev/ic/rlnreg.h>

#include <dev/isa/isavar.h>

static int rln_isa_probe(struct device *, void *, void *);
static void rln_isa_attach(struct device *, struct device *, void *);

struct cfattach rln_isa_ca = {
	sizeof(struct rln_softc), rln_isa_probe, rln_isa_attach
};

static const int rln_irq[] = {
	3, 4, 5, 7, 10, 11, 12, 15
};
#define NRLN_IRQ	(sizeof(rln_irq) / sizeof(rln_irq[0]))

static int
rln_isa_probe(parent, match, aux)
	struct device *parent;
	void *match, *aux;
{
	struct isa_attach_args *ia = aux;
	struct rln_softc *sc = match;

	/*
	 * The i/o base addr is set by the dip switches
	 * and must be specified in the kernel config.
	 */
	if (ia->ia_iobase == IOBASEUNK)
		return (0);

	/* Attempt a card reset through the io ports */
	sc->sc_iot = ia->ia_iot;
	sc->sc_width = 0;	/* Force width probe */
	if (bus_space_map(sc->sc_iot, ia->ia_iobase, RLN_NPORTS, 0, 
	    &sc->sc_ioh))
		return (0);

	if (rln_reset(sc)) {
		bus_space_unmap(sc->sc_iot, sc->sc_ioh, RLN_NPORTS);
		return (0);
	}

	ia->ia_iosize = RLN_NPORTS;
	return (1);
}

static void
rln_isa_attach(parent, self, aux)
	struct device *parent, *self;
	void *aux;
{
	struct rln_softc *sc = (void *)self;
	struct isa_attach_args *ia = aux;
	int irq = ia->ia_irq;
	int mask;
	int i;

	if (irq == IRQUNK) {
		/* Allocate a valid IRQ. */
		mask = 0;
		for (i = 0; i < NRLN_IRQ; i++)
			mask |= (1 << rln_irq[i]);
		if (isa_intr_alloc(ia->ia_ic, mask, IST_EDGE, &irq))
			panic("rln_isa_attach: can't allocate irq");
	} 
#ifdef DIAGNOSTIC
	else {
		/* Check given IRQ is valid. */
		for (i = 0; i < NRLN_IRQ; i++)
			if (irq == rln_irq[i])
				break;
		if (i == NRLN_IRQ)
			printf("rln_isa_probe: using invalid irq %d\n", irq);
	}
#endif

	printf(":");

	sc->sc_ih = isa_intr_establish(ia->ia_ic, irq, IST_EDGE,
	    IPL_NET, rlnintr, sc, sc->sc_dev.dv_xname);
#ifdef DIAGNOSTIC
	if (sc->sc_ih == NULL)
		panic("rln_isa_attach: couldn't establish interrupt");
#endif

	/* Tell the card which IRQ to use. */
	sc->sc_irq = irq;
	sc->sc_width = 0;	/* re-probe width */

	printf("%s: RangeLAN2 7100", sc->sc_dev.dv_xname);
	rlnconfig(sc);
	printf("\n");
}