This source file includes following definitions.
- ne_pci_lookup
- ne_pci_match
- ne_pci_attach
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 #include "bpfilter.h"
42
43 #include <sys/param.h>
44 #include <sys/systm.h>
45 #include <sys/mbuf.h>
46 #include <sys/syslog.h>
47 #include <sys/socket.h>
48 #include <sys/device.h>
49
50 #include <net/if.h>
51 #include <net/if_media.h>
52
53 #ifdef INET
54 #include <netinet/in.h>
55 #include <netinet/if_ether.h>
56 #endif
57
58 #include <machine/bus.h>
59 #include <machine/intr.h>
60
61 #include <dev/pci/pcireg.h>
62 #include <dev/pci/pcivar.h>
63 #include <dev/pci/pcidevs.h>
64
65 #include <dev/mii/miivar.h>
66
67 #include <dev/ic/dp8390reg.h>
68 #include <dev/ic/dp8390var.h>
69
70 #include <dev/ic/ne2000reg.h>
71 #include <dev/ic/ne2000var.h>
72
73 #include <dev/ic/rtl80x9reg.h>
74 #include <dev/ic/rtl80x9var.h>
75
76 struct ne_pci_softc {
77 struct ne2000_softc sc_ne2000;
78
79
80 void *sc_ih;
81 };
82
83 int ne_pci_match(struct device *, void *, void *);
84 void ne_pci_attach(struct device *, struct device *, void *);
85
86 struct cfattach ne_pci_ca = {
87 sizeof(struct ne_pci_softc), ne_pci_match, ne_pci_attach
88 };
89
90 const struct ne_pci_product {
91 pci_vendor_id_t npp_vendor;
92 pci_product_id_t npp_product;
93 int (*npp_mediachange)(struct dp8390_softc *);
94 void (*npp_mediastatus)(struct dp8390_softc *,
95 struct ifmediareq *);
96 void (*npp_init_card)(struct dp8390_softc *);
97 void (*npp_media_init)(struct dp8390_softc *);
98 } ne_pci_prod[] = {
99 { PCI_VENDOR_REALTEK, PCI_PRODUCT_REALTEK_RT8029,
100 rtl80x9_mediachange, rtl80x9_mediastatus,
101 rtl80x9_init_card, rtl80x9_media_init,
102 },
103
104 { PCI_VENDOR_WINBOND, PCI_PRODUCT_WINBOND_W89C940F,
105 NULL, NULL,
106 NULL, NULL,
107 },
108
109 { PCI_VENDOR_VIATECH, PCI_PRODUCT_VIATECH_VT86C926,
110 NULL, NULL,
111 NULL, NULL,
112 },
113
114 { PCI_VENDOR_SURECOM, PCI_PRODUCT_SURECOM_NE34,
115 NULL, NULL,
116 NULL, NULL,
117 },
118
119 { PCI_VENDOR_NETVIN, PCI_PRODUCT_NETVIN_NV5000,
120 NULL, NULL,
121 NULL, NULL,
122 },
123
124
125 { PCI_VENDOR_COMPEX, PCI_PRODUCT_COMPEX_COMPEXE,
126 NULL, NULL,
127 NULL, NULL,
128 },
129
130 { PCI_VENDOR_WINBOND2, PCI_PRODUCT_WINBOND2_W89C940,
131 NULL, NULL,
132 NULL, NULL,
133 },
134
135 { PCI_VENDOR_KTI, PCI_PRODUCT_KTI_KTIE,
136 NULL, NULL,
137 NULL, NULL,
138 },
139 };
140
141 const struct ne_pci_product *ne_pci_lookup(struct pci_attach_args *);
142
143 const struct ne_pci_product *
144 ne_pci_lookup(struct pci_attach_args *pa)
145 {
146 const struct ne_pci_product *npp;
147
148 for (npp = ne_pci_prod;
149 npp < &ne_pci_prod[sizeof(ne_pci_prod)/sizeof(ne_pci_prod[0])];
150 npp++) {
151 if (PCI_VENDOR(pa->pa_id) == npp->npp_vendor &&
152 PCI_PRODUCT(pa->pa_id) == npp->npp_product)
153 return (npp);
154 }
155 return (NULL);
156 }
157
158
159
160
161
162 #define PCI_CBIO 0x10
163
164 int
165 ne_pci_match(struct device *parent, void *match, void *aux)
166 {
167 struct pci_attach_args *pa = aux;
168
169 if (ne_pci_lookup(pa) != NULL)
170 return (1);
171
172 return (0);
173 }
174
175 void
176 ne_pci_attach(struct device *parent, struct device *self, void *aux)
177 {
178 struct ne_pci_softc *psc = (struct ne_pci_softc *)self;
179 struct ne2000_softc *nsc = &psc->sc_ne2000;
180 struct dp8390_softc *dsc = &nsc->sc_dp8390;
181 struct pci_attach_args *pa = aux;
182 pci_chipset_tag_t pc = pa->pa_pc;
183 bus_size_t iosize;
184 bus_space_tag_t nict;
185 bus_space_handle_t nich;
186 bus_space_tag_t asict;
187 bus_space_handle_t asich;
188 const char *intrstr;
189 const struct ne_pci_product *npp;
190 pci_intr_handle_t ih;
191
192 npp = ne_pci_lookup(pa);
193 if (npp == NULL) {
194 printf("\n");
195 panic("ne_pci_attach: impossible");
196 }
197
198 if (pci_mapreg_map(pa, PCI_CBIO, PCI_MAPREG_TYPE_IO, 0,
199 &nict, &nich, NULL, &iosize, 0)) {
200 printf(": can't map i/o space\n");
201 return;
202 }
203
204 asict = nict;
205 if (bus_space_subregion(nict, nich, NE2000_ASIC_OFFSET,
206 NE2000_ASIC_NPORTS, &asich)) {
207 printf(": can't subregion i/o space\n");
208 bus_space_unmap(nict, nich, iosize);
209 return;
210 }
211
212 dsc->sc_regt = nict;
213 dsc->sc_regh = nich;
214
215 nsc->sc_asict = asict;
216 nsc->sc_asich = asich;
217
218
219 dsc->sc_enabled = 1;
220
221 dsc->sc_mediachange = npp->npp_mediachange;
222 dsc->sc_mediastatus = npp->npp_mediastatus;
223 dsc->sc_media_init = npp->npp_media_init;
224 dsc->init_card = npp->npp_init_card;
225
226
227 if (pci_intr_map(pa, &ih)) {
228 printf(": couldn't map interrupt\n");
229 bus_space_unmap(nict, nich, iosize);
230 return;
231 }
232 intrstr = pci_intr_string(pc, ih);
233 psc->sc_ih = pci_intr_establish(pc, ih, IPL_NET, dp8390_intr, dsc,
234 dsc->sc_dev.dv_xname);
235 if (psc->sc_ih == NULL) {
236 printf(": couldn't establish interrupt");
237 if (intrstr != NULL)
238 printf(" at %s", intrstr);
239 printf("\n");
240 bus_space_unmap(nict, nich, iosize);
241 return;
242 }
243 printf(": %s", intrstr);
244
245
246
247
248
249 ne2000_attach(nsc, NULL);
250 }