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