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