if_ep_pcmcia.c revision 1.1.2.10 1 1.1.2.10 enami /* $NetBSD: if_ep_pcmcia.c,v 1.1.2.10 1997/10/15 02:41:28 enami Exp $ */
2 1.1.2.9 thorpej
3 1.1.2.9 thorpej #include "bpfilter.h"
4 1.1.2.9 thorpej
5 1.1.2.1 marc #include <sys/param.h>
6 1.1.2.1 marc #include <sys/systm.h>
7 1.1.2.9 thorpej #include <sys/mbuf.h>
8 1.1.2.9 thorpej #include <sys/socket.h>
9 1.1.2.1 marc #include <sys/ioctl.h>
10 1.1.2.1 marc #include <sys/errno.h>
11 1.1.2.1 marc #include <sys/syslog.h>
12 1.1.2.1 marc #include <sys/select.h>
13 1.1.2.1 marc #include <sys/device.h>
14 1.1.2.1 marc
15 1.1.2.1 marc #include <net/if.h>
16 1.1.2.1 marc #include <net/if_dl.h>
17 1.1.2.1 marc #include <net/if_ether.h>
18 1.1.2.1 marc #include <net/if_media.h>
19 1.1.2.1 marc
20 1.1.2.1 marc #ifdef INET
21 1.1.2.1 marc #include <netinet/in.h>
22 1.1.2.1 marc #include <netinet/in_systm.h>
23 1.1.2.1 marc #include <netinet/in_var.h>
24 1.1.2.9 thorpej #include <netinet/ip.h>
25 1.1.2.1 marc #include <netinet/if_inarp.h>
26 1.1.2.1 marc #endif
27 1.1.2.9 thorpej
28 1.1.2.1 marc #ifdef NS
29 1.1.2.1 marc #include <netns/ns.h>
30 1.1.2.1 marc #include <netns/ns_if.h>
31 1.1.2.1 marc #endif
32 1.1.2.9 thorpej
33 1.1.2.1 marc #if NBPFILTER > 0
34 1.1.2.1 marc #include <net/bpf.h>
35 1.1.2.1 marc #include <net/bpfdesc.h>
36 1.1.2.1 marc #endif
37 1.1.2.1 marc
38 1.1.2.1 marc #include <machine/cpu.h>
39 1.1.2.1 marc #include <machine/bus.h>
40 1.1.2.1 marc #include <machine/intr.h>
41 1.1.2.1 marc
42 1.1.2.1 marc #include <dev/ic/elink3var.h>
43 1.1.2.1 marc #include <dev/ic/elink3reg.h>
44 1.1.2.1 marc
45 1.1.2.1 marc #include <dev/pcmcia/pcmciareg.h>
46 1.1.2.1 marc #include <dev/pcmcia/pcmciavar.h>
47 1.1.2.1 marc
48 1.1.2.9 thorpej #define PCMCIA_MANUFACTURER_3COM 0x101
49 1.1.2.9 thorpej #define PCMCIA_PRODUCT_3COM_3C562 0x562
50 1.1.2.9 thorpej #define PCMCIA_PRODUCT_3COM_3C589 0x589
51 1.1.2.1 marc
52 1.1.2.1 marc #ifdef __BROKEN_INDIRECT_CONFIG
53 1.1.2.9 thorpej int ep_pcmcia_match __P((struct device *, void *, void *));
54 1.1.2.1 marc #else
55 1.1.2.9 thorpej int ep_pcmcia_match __P((struct device *, struct cfdata *, void *));
56 1.1.2.1 marc #endif
57 1.1.2.9 thorpej void ep_pcmcia_attach __P((struct device *, struct device *, void *));
58 1.1.2.1 marc
59 1.1.2.9 thorpej int ep_pcmcia_get_enaddr __P((struct pcmcia_tuple *, void *));
60 1.1.2.9 thorpej int ep_pcmcia_enable __P((struct ep_softc *));
61 1.1.2.9 thorpej void ep_pcmcia_disable __P((struct ep_softc *));
62 1.1.2.1 marc
63 1.1.2.4 thorpej struct ep_pcmcia_softc {
64 1.1.2.4 thorpej struct ep_softc sc_ep; /* real "ep" softc */
65 1.1.2.4 thorpej
66 1.1.2.4 thorpej /* PCMCIA-specific goo */
67 1.1.2.4 thorpej struct pcmcia_io_handle sc_pcioh; /* PCMCIA i/o space info */
68 1.1.2.4 thorpej int sc_io_window; /* our i/o window */
69 1.1.2.5 thorpej struct pcmcia_function *sc_pf; /* our PCMCIA function */
70 1.1.2.4 thorpej };
71 1.1.2.4 thorpej
72 1.1.2.1 marc struct cfattach ep_pcmcia_ca = {
73 1.1.2.9 thorpej sizeof(struct ep_pcmcia_softc), ep_pcmcia_match, ep_pcmcia_attach
74 1.1.2.1 marc };
75 1.1.2.1 marc
76 1.1.2.1 marc int
77 1.1.2.1 marc ep_pcmcia_match(parent, match, aux)
78 1.1.2.9 thorpej struct device *parent;
79 1.1.2.1 marc #ifdef __BROKEN_INDIRECT_CONFIG
80 1.1.2.9 thorpej void *match;
81 1.1.2.1 marc #else
82 1.1.2.9 thorpej struct cfdata *cf;
83 1.1.2.1 marc #endif
84 1.1.2.9 thorpej void *aux;
85 1.1.2.1 marc {
86 1.1.2.10 enami struct pcmcia_attach_args *pa = aux;
87 1.1.2.1 marc
88 1.1.2.9 thorpej if ((pa->manufacturer == PCMCIA_MANUFACTURER_3COM) &&
89 1.1.2.9 thorpej (pa->product == PCMCIA_PRODUCT_3COM_3C562) &&
90 1.1.2.9 thorpej (pa->pf->number == 0))
91 1.1.2.9 thorpej return (1);
92 1.1.2.9 thorpej
93 1.1.2.9 thorpej if ((pa->manufacturer == PCMCIA_MANUFACTURER_3COM) &&
94 1.1.2.9 thorpej (pa->product == PCMCIA_PRODUCT_3COM_3C589) &&
95 1.1.2.9 thorpej (pa->pf->number == 0))
96 1.1.2.9 thorpej return (1);
97 1.1.2.1 marc
98 1.1.2.9 thorpej return (0);
99 1.1.2.1 marc }
100 1.1.2.1 marc
101 1.1.2.7 thorpej int
102 1.1.2.7 thorpej ep_pcmcia_enable(sc)
103 1.1.2.9 thorpej struct ep_softc *sc;
104 1.1.2.6 marc {
105 1.1.2.9 thorpej struct ep_pcmcia_softc *psc = (struct ep_pcmcia_softc *) sc;
106 1.1.2.7 thorpej
107 1.1.2.9 thorpej return (pcmcia_function_enable(psc->sc_pf));
108 1.1.2.6 marc }
109 1.1.2.6 marc
110 1.1.2.7 thorpej void
111 1.1.2.7 thorpej ep_pcmcia_disable(sc)
112 1.1.2.9 thorpej struct ep_softc *sc;
113 1.1.2.6 marc {
114 1.1.2.9 thorpej struct ep_pcmcia_softc *psc = (struct ep_pcmcia_softc *) sc;
115 1.1.2.7 thorpej
116 1.1.2.9 thorpej pcmcia_function_disable(psc->sc_pf);
117 1.1.2.6 marc }
118 1.1.2.6 marc
119 1.1.2.1 marc void
120 1.1.2.1 marc ep_pcmcia_attach(parent, self, aux)
121 1.1.2.9 thorpej struct device *parent, *self;
122 1.1.2.9 thorpej void *aux;
123 1.1.2.1 marc {
124 1.1.2.9 thorpej struct ep_pcmcia_softc *psc = (void *) self;
125 1.1.2.9 thorpej struct ep_softc *sc = &psc->sc_ep;
126 1.1.2.9 thorpej struct pcmcia_attach_args *pa = aux;
127 1.1.2.9 thorpej struct pcmcia_config_entry *cfe;
128 1.1.2.9 thorpej int i;
129 1.1.2.9 thorpej u_int8_t myla[ETHER_ADDR_LEN];
130 1.1.2.9 thorpej u_int8_t *enaddr;
131 1.1.2.9 thorpej char *model;
132 1.1.2.9 thorpej
133 1.1.2.9 thorpej psc->sc_pf = pa->pf;
134 1.1.2.9 thorpej cfe = pa->pf->cfe_head.sqh_first;
135 1.1.2.9 thorpej
136 1.1.2.9 thorpej /* Enable the card. */
137 1.1.2.9 thorpej pcmcia_function_init(pa->pf, cfe);
138 1.1.2.9 thorpej if (pcmcia_function_enable(pa->pf))
139 1.1.2.9 thorpej printf(": function enable failed\n");
140 1.1.2.9 thorpej
141 1.1.2.9 thorpej sc->enabled = 1;
142 1.1.2.9 thorpej /* turn off the bit which disables the modem */
143 1.1.2.9 thorpej if (pa->product == PCMCIA_PRODUCT_3COM_3C562) {
144 1.1.2.9 thorpej int reg;
145 1.1.2.9 thorpej
146 1.1.2.9 thorpej reg = pcmcia_ccr_read(pa->pf, PCMCIA_CCR_OPTION);
147 1.1.2.9 thorpej reg &= ~0x08;
148 1.1.2.9 thorpej pcmcia_ccr_write(pa->pf, PCMCIA_CCR_OPTION, reg);
149 1.1.2.1 marc }
150 1.1.2.9 thorpej if (cfe->num_memspace != 0)
151 1.1.2.9 thorpej printf(": unexpected number of memory spaces %d should be 0\n",
152 1.1.2.9 thorpej cfe->num_memspace);
153 1.1.2.9 thorpej
154 1.1.2.9 thorpej if (cfe->num_iospace != 1)
155 1.1.2.9 thorpej printf(": unexpected number of I/O spaces %d should be 1\n",
156 1.1.2.9 thorpej cfe->num_iospace);
157 1.1.2.9 thorpej
158 1.1.2.9 thorpej /*
159 1.1.2.9 thorpej * XXX there's a comment in the linux driver about the io address
160 1.1.2.9 thorpej * having to be between 0x00 and 0x70 mod 0x100. weird.
161 1.1.2.9 thorpej */
162 1.1.2.9 thorpej
163 1.1.2.9 thorpej /* XXX Will have to fix this!! */
164 1.1.2.9 thorpej
165 1.1.2.9 thorpej if (pa->product == PCMCIA_PRODUCT_3COM_3C562) {
166 1.1.2.9 thorpej for (i = 0x300; i < 0x1000;
167 1.1.2.9 thorpej i += ((i % 0x100) == 0x70) ? 0x90 : 0x10) {
168 1.1.2.9 thorpej if (pcmcia_io_alloc(pa->pf, i, cfe->iospace[0].length,
169 1.1.2.9 thorpej 0, &psc->sc_pcioh) == 0)
170 1.1.2.9 thorpej break;
171 1.1.2.9 thorpej }
172 1.1.2.9 thorpej if (i == 0x1000) {
173 1.1.2.9 thorpej printf(": can't allocate i/o space\n");
174 1.1.2.9 thorpej return;
175 1.1.2.9 thorpej }
176 1.1.2.9 thorpej } else {
177 1.1.2.9 thorpej if (pcmcia_io_alloc(pa->pf, 0, cfe->iospace[0].length,
178 1.1.2.9 thorpej cfe->iospace[0].length, &psc->sc_pcioh))
179 1.1.2.9 thorpej printf(": can't allocate i/o space\n");
180 1.1.2.1 marc }
181 1.1.2.9 thorpej
182 1.1.2.9 thorpej sc->sc_iot = psc->sc_pcioh.iot;
183 1.1.2.9 thorpej sc->sc_ioh = psc->sc_pcioh.ioh;
184 1.1.2.9 thorpej
185 1.1.2.9 thorpej if (pcmcia_io_map(pa->pf, ((cfe->flags & PCMCIA_CFE_IO16) ?
186 1.1.2.9 thorpej PCMCIA_WIDTH_IO16 : PCMCIA_WIDTH_IO8), 0, cfe->iospace[0].length,
187 1.1.2.9 thorpej &psc->sc_pcioh, &psc->sc_io_window)) {
188 1.1.2.9 thorpej printf(": can't map i/o space\n");
189 1.1.2.9 thorpej return;
190 1.1.2.9 thorpej }
191 1.1.2.9 thorpej if (pa->product == PCMCIA_PRODUCT_3COM_3C562) {
192 1.1.2.9 thorpej if (pcmcia_scan_cis(parent, ep_pcmcia_get_enaddr, myla)) {
193 1.1.2.9 thorpej printf(": can't read ethernet address from CIS\n");
194 1.1.2.9 thorpej return;
195 1.1.2.9 thorpej }
196 1.1.2.9 thorpej enaddr = myla;
197 1.1.2.9 thorpej } else {
198 1.1.2.9 thorpej enaddr = NULL;
199 1.1.2.9 thorpej }
200 1.1.2.9 thorpej
201 1.1.2.9 thorpej sc->bustype = EP_BUS_PCMCIA;
202 1.1.2.9 thorpej
203 1.1.2.9 thorpej switch (pa->product) {
204 1.1.2.9 thorpej case PCMCIA_PRODUCT_3COM_3C589:
205 1.1.2.9 thorpej model = "3Com 3C589 Ethernet";
206 1.1.2.9 thorpej break;
207 1.1.2.9 thorpej case PCMCIA_PRODUCT_3COM_3C562:
208 1.1.2.9 thorpej model = "3Com 3C562 Ethernet";
209 1.1.2.9 thorpej break;
210 1.1.2.9 thorpej default:
211 1.1.2.9 thorpej model = "3Com Ethernet, model unknown";
212 1.1.2.9 thorpej break;
213 1.1.2.1 marc }
214 1.1.2.6 marc
215 1.1.2.9 thorpej printf(": %s\n", model);
216 1.1.2.9 thorpej
217 1.1.2.9 thorpej sc->enable = ep_pcmcia_enable;
218 1.1.2.9 thorpej sc->disable = ep_pcmcia_disable;
219 1.1.2.6 marc
220 1.1.2.9 thorpej epconfig(sc, EP_CHIPSET_3C509, enaddr);
221 1.1.2.9 thorpej
222 1.1.2.9 thorpej /* establish the interrupt. */
223 1.1.2.9 thorpej sc->sc_ih = pcmcia_intr_establish(pa->pf, IPL_NET, epintr, sc);
224 1.1.2.9 thorpej if (sc->sc_ih == NULL) {
225 1.1.2.9 thorpej printf("%s: couldn't establish interrupt\n",
226 1.1.2.9 thorpej sc->sc_dev.dv_xname);
227 1.1.2.9 thorpej return;
228 1.1.2.9 thorpej }
229 1.1.2.9 thorpej sc->enabled = 0;
230 1.1.2.9 thorpej
231 1.1.2.9 thorpej pcmcia_function_disable(pa->pf);
232 1.1.2.1 marc }
233 1.1.2.1 marc
234 1.1.2.1 marc int
235 1.1.2.1 marc ep_pcmcia_get_enaddr(tuple, arg)
236 1.1.2.9 thorpej struct pcmcia_tuple *tuple;
237 1.1.2.9 thorpej void *arg;
238 1.1.2.1 marc {
239 1.1.2.10 enami u_int8_t *myla = arg;
240 1.1.2.9 thorpej int i;
241 1.1.2.1 marc
242 1.1.2.9 thorpej /* this is 3c562 magic */
243 1.1.2.1 marc
244 1.1.2.9 thorpej if (tuple->code == 0x88) {
245 1.1.2.9 thorpej if (tuple->length < ETHER_ADDR_LEN)
246 1.1.2.9 thorpej return (0);
247 1.1.2.1 marc
248 1.1.2.9 thorpej for (i = 0; i < ETHER_ADDR_LEN; i += 2) {
249 1.1.2.9 thorpej myla[i] = pcmcia_tuple_read_1(tuple, i + 1);
250 1.1.2.9 thorpej myla[i + 1] = pcmcia_tuple_read_1(tuple, i);
251 1.1.2.9 thorpej }
252 1.1.2.1 marc
253 1.1.2.9 thorpej return (1);
254 1.1.2.9 thorpej }
255 1.1.2.9 thorpej return (0);
256 1.1.2.1 marc }
257