if_txp.c revision 1.69 1 1.69 thorpej /* $NetBSD: if_txp.c,v 1.69 2020/03/09 00:32:53 thorpej Exp $ */
2 1.1 drochner
3 1.1 drochner /*
4 1.1 drochner * Copyright (c) 2001
5 1.1 drochner * Jason L. Wright <jason (at) thought.net>, Theo de Raadt, and
6 1.1 drochner * Aaron Campbell <aaron (at) monkey.org>. All rights reserved.
7 1.1 drochner *
8 1.1 drochner * Redistribution and use in source and binary forms, with or without
9 1.1 drochner * modification, are permitted provided that the following conditions
10 1.1 drochner * are met:
11 1.1 drochner * 1. Redistributions of source code must retain the above copyright
12 1.1 drochner * notice, this list of conditions and the following disclaimer.
13 1.1 drochner * 2. Redistributions in binary form must reproduce the above copyright
14 1.1 drochner * notice, this list of conditions and the following disclaimer in the
15 1.1 drochner * documentation and/or other materials provided with the distribution.
16 1.1 drochner *
17 1.1 drochner * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
18 1.1 drochner * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 1.1 drochner * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 1.1 drochner * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR THE VOICES IN THEIR HEADS
21 1.1 drochner * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 1.1 drochner * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 1.1 drochner * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 1.1 drochner * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 1.1 drochner * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 1.1 drochner * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
27 1.1 drochner * THE POSSIBILITY OF SUCH DAMAGE.
28 1.1 drochner */
29 1.1 drochner
30 1.1 drochner /*
31 1.1 drochner * Driver for 3c990 (Typhoon) Ethernet ASIC
32 1.1 drochner */
33 1.3 lukem
34 1.3 lukem #include <sys/cdefs.h>
35 1.69 thorpej __KERNEL_RCSID(0, "$NetBSD: if_txp.c,v 1.69 2020/03/09 00:32:53 thorpej Exp $");
36 1.1 drochner
37 1.1 drochner #include "opt_inet.h"
38 1.1 drochner
39 1.1 drochner #include <sys/param.h>
40 1.1 drochner #include <sys/systm.h>
41 1.1 drochner #include <sys/sockio.h>
42 1.1 drochner #include <sys/mbuf.h>
43 1.1 drochner #include <sys/malloc.h>
44 1.1 drochner #include <sys/kernel.h>
45 1.1 drochner #include <sys/socket.h>
46 1.1 drochner #include <sys/device.h>
47 1.1 drochner #include <sys/callout.h>
48 1.53 msaitoh #include <sys/bus.h>
49 1.1 drochner
50 1.1 drochner #include <net/if.h>
51 1.1 drochner #include <net/if_dl.h>
52 1.1 drochner #include <net/if_types.h>
53 1.1 drochner #include <net/if_ether.h>
54 1.1 drochner #include <net/if_arp.h>
55 1.53 msaitoh #include <net/if_media.h>
56 1.53 msaitoh #include <net/bpf.h>
57 1.1 drochner
58 1.1 drochner #ifdef INET
59 1.1 drochner #include <netinet/in.h>
60 1.1 drochner #include <netinet/in_systm.h>
61 1.1 drochner #include <netinet/in_var.h>
62 1.1 drochner #include <netinet/ip.h>
63 1.1 drochner #include <netinet/if_inarp.h>
64 1.1 drochner #endif
65 1.1 drochner
66 1.1 drochner #include <dev/mii/mii.h>
67 1.1 drochner #include <dev/mii/miivar.h>
68 1.1 drochner #include <dev/pci/pcireg.h>
69 1.1 drochner #include <dev/pci/pcivar.h>
70 1.1 drochner #include <dev/pci/pcidevs.h>
71 1.1 drochner
72 1.1 drochner #include <dev/pci/if_txpreg.h>
73 1.1 drochner
74 1.1 drochner #include <dev/microcode/typhoon/3c990img.h>
75 1.1 drochner
76 1.1 drochner /*
77 1.1 drochner * These currently break the 3c990 firmware, hopefully will be resolved
78 1.1 drochner * at some point.
79 1.1 drochner */
80 1.1 drochner #undef TRY_TX_UDP_CSUM
81 1.1 drochner #undef TRY_TX_TCP_CSUM
82 1.1 drochner
83 1.62 maxv static int txp_probe(device_t, cfdata_t, void *);
84 1.62 maxv static void txp_attach(device_t, device_t, void *);
85 1.62 maxv static int txp_intr(void *);
86 1.62 maxv static void txp_tick(void *);
87 1.62 maxv static bool txp_shutdown(device_t, int);
88 1.62 maxv static int txp_ioctl(struct ifnet *, u_long, void *);
89 1.62 maxv static void txp_start(struct ifnet *);
90 1.62 maxv static void txp_stop(struct txp_softc *);
91 1.62 maxv static void txp_init(struct txp_softc *);
92 1.62 maxv static void txp_watchdog(struct ifnet *);
93 1.62 maxv
94 1.62 maxv static int txp_chip_init(struct txp_softc *);
95 1.62 maxv static int txp_reset_adapter(struct txp_softc *);
96 1.62 maxv static int txp_download_fw(struct txp_softc *);
97 1.62 maxv static int txp_download_fw_wait(struct txp_softc *);
98 1.62 maxv static int txp_download_fw_section(struct txp_softc *,
99 1.12 chs const struct txp_fw_section_header *, int);
100 1.62 maxv static int txp_alloc_rings(struct txp_softc *);
101 1.62 maxv static void txp_dma_free(struct txp_softc *, struct txp_dma_alloc *);
102 1.62 maxv static int txp_dma_malloc(struct txp_softc *, bus_size_t, struct txp_dma_alloc *, int);
103 1.62 maxv static void txp_set_filter(struct txp_softc *);
104 1.1 drochner
105 1.62 maxv static int txp_cmd_desc_numfree(struct txp_softc *);
106 1.62 maxv static int txp_command(struct txp_softc *, uint16_t, uint16_t, uint32_t,
107 1.53 msaitoh uint32_t, uint16_t *, uint32_t *, uint32_t *, int);
108 1.62 maxv static int txp_command2(struct txp_softc *, uint16_t, uint16_t,
109 1.53 msaitoh uint32_t, uint32_t, struct txp_ext_desc *, uint8_t,
110 1.1 drochner struct txp_rsp_desc **, int);
111 1.62 maxv static int txp_response(struct txp_softc *, uint32_t, uint16_t, uint16_t,
112 1.1 drochner struct txp_rsp_desc **);
113 1.62 maxv static void txp_rsp_fixup(struct txp_softc *, struct txp_rsp_desc *,
114 1.1 drochner struct txp_rsp_desc *);
115 1.62 maxv static void txp_capabilities(struct txp_softc *);
116 1.1 drochner
117 1.62 maxv static void txp_ifmedia_sts(struct ifnet *, struct ifmediareq *);
118 1.62 maxv static int txp_ifmedia_upd(struct ifnet *);
119 1.62 maxv static void txp_tx_reclaim(struct txp_softc *, struct txp_tx_ring *,
120 1.1 drochner struct txp_dma_alloc *);
121 1.62 maxv static void txp_rxbuf_reclaim(struct txp_softc *);
122 1.62 maxv static void txp_rx_reclaim(struct txp_softc *, struct txp_rx_ring *,
123 1.1 drochner struct txp_dma_alloc *);
124 1.1 drochner
125 1.69 thorpej static void txp_rxd_free(struct txp_softc *, struct txp_swdesc *);
126 1.69 thorpej static struct txp_swdesc *txp_rxd_alloc(struct txp_softc *);
127 1.69 thorpej
128 1.39 chs CFATTACH_DECL_NEW(txp, sizeof(struct txp_softc), txp_probe, txp_attach,
129 1.2 drochner NULL, NULL);
130 1.2 drochner
131 1.62 maxv static const struct txp_pci_match {
132 1.2 drochner int vid, did, flags;
133 1.2 drochner } txp_devices[] = {
134 1.2 drochner { PCI_VENDOR_3COM, PCI_PRODUCT_3COM_3CR990, 0 },
135 1.2 drochner { PCI_VENDOR_3COM, PCI_PRODUCT_3COM_3CR990TX95, 0 },
136 1.2 drochner { PCI_VENDOR_3COM, PCI_PRODUCT_3COM_3CR990TX97, 0 },
137 1.2 drochner { PCI_VENDOR_3COM, PCI_PRODUCT_3COM_3CR990SVR95, TXP_SERVERVERSION },
138 1.2 drochner { PCI_VENDOR_3COM, PCI_PRODUCT_3COM_3CR990SVR97, TXP_SERVERVERSION },
139 1.2 drochner { PCI_VENDOR_3COM, PCI_PRODUCT_3COM_3C990B, TXP_USESUBSYSTEM },
140 1.2 drochner { PCI_VENDOR_3COM, PCI_PRODUCT_3COM_3C990BSVR, TXP_SERVERVERSION },
141 1.2 drochner { PCI_VENDOR_3COM, PCI_PRODUCT_3COM_3CR990FX, TXP_USESUBSYSTEM },
142 1.1 drochner };
143 1.1 drochner
144 1.2 drochner static const struct txp_pci_match *txp_pcilookup(pcireg_t);
145 1.2 drochner
146 1.2 drochner static const struct {
147 1.53 msaitoh uint16_t mask, value;
148 1.2 drochner int flags;
149 1.2 drochner } txp_subsysinfo[] = {
150 1.2 drochner {0xf000, 0x2000, TXP_SERVERVERSION},
151 1.2 drochner {0x0100, 0x0100, TXP_FIBER},
152 1.2 drochner #if 0 /* information from 3com header, unused */
153 1.2 drochner {0x0010, 0x0010, /* secured firmware */},
154 1.2 drochner {0x0003, 0x0000, /* variable DES */},
155 1.2 drochner {0x0003, 0x0001, /* single DES - "95" */},
156 1.2 drochner {0x0003, 0x0002, /* triple DES - "97" */},
157 1.2 drochner #endif
158 1.1 drochner };
159 1.1 drochner
160 1.2 drochner static const struct txp_pci_match *
161 1.25 dyoung txp_pcilookup(pcireg_t id)
162 1.2 drochner {
163 1.2 drochner int i;
164 1.2 drochner
165 1.25 dyoung for (i = 0; i < __arraycount(txp_devices); i++)
166 1.25 dyoung if (PCI_VENDOR(id) == txp_devices[i].vid &&
167 1.25 dyoung PCI_PRODUCT(id) == txp_devices[i].did)
168 1.25 dyoung return &txp_devices[i];
169 1.2 drochner return (0);
170 1.2 drochner }
171 1.2 drochner
172 1.62 maxv static int
173 1.25 dyoung txp_probe(device_t parent, cfdata_t match, void *aux)
174 1.1 drochner {
175 1.1 drochner struct pci_attach_args *pa = aux;
176 1.1 drochner
177 1.2 drochner if (txp_pcilookup(pa->pa_id))
178 1.1 drochner return (1);
179 1.1 drochner return (0);
180 1.1 drochner }
181 1.1 drochner
182 1.62 maxv static void
183 1.25 dyoung txp_attach(device_t parent, device_t self, void *aux)
184 1.1 drochner {
185 1.25 dyoung struct txp_softc *sc = device_private(self);
186 1.1 drochner struct pci_attach_args *pa = aux;
187 1.1 drochner pci_chipset_tag_t pc = pa->pa_pc;
188 1.1 drochner pci_intr_handle_t ih;
189 1.1 drochner const char *intrstr = NULL;
190 1.1 drochner struct ifnet *ifp = &sc->sc_arpcom.ec_if;
191 1.53 msaitoh uint32_t command;
192 1.53 msaitoh uint16_t p1;
193 1.53 msaitoh uint32_t p2;
194 1.1 drochner u_char enaddr[6];
195 1.24 dyoung const struct txp_pci_match *match;
196 1.53 msaitoh uint16_t subsys;
197 1.2 drochner int i, flags;
198 1.2 drochner char devinfo[256];
199 1.40 christos char intrbuf[PCI_INTRSTR_LEN];
200 1.1 drochner
201 1.39 chs sc->sc_dev = self;
202 1.1 drochner sc->sc_cold = 1;
203 1.1 drochner
204 1.24 dyoung match = txp_pcilookup(pa->pa_id);
205 1.24 dyoung flags = match->flags;
206 1.24 dyoung if (match->flags & TXP_USESUBSYSTEM) {
207 1.2 drochner subsys = PCI_PRODUCT(pci_conf_read(pc, pa->pa_tag,
208 1.2 drochner PCI_SUBSYS_ID_REG));
209 1.2 drochner for (i = 0;
210 1.2 drochner i < sizeof(txp_subsysinfo)/sizeof(txp_subsysinfo[0]);
211 1.2 drochner i++)
212 1.2 drochner if ((subsys & txp_subsysinfo[i].mask) ==
213 1.2 drochner txp_subsysinfo[i].value)
214 1.2 drochner flags |= txp_subsysinfo[i].flags;
215 1.2 drochner }
216 1.2 drochner sc->sc_flags = flags;
217 1.2 drochner
218 1.44 msaitoh aprint_naive("\n");
219 1.6 itojun pci_devinfo(pa->pa_id, 0, 0, devinfo, sizeof(devinfo));
220 1.53 msaitoh #define TXP_EXTRAINFO ((flags & (TXP_USESUBSYSTEM | TXP_SERVERVERSION)) == \
221 1.53 msaitoh (TXP_USESUBSYSTEM | TXP_SERVERVERSION) ? " (SVR)" : "")
222 1.44 msaitoh aprint_normal(": %s%s\n%s", devinfo, TXP_EXTRAINFO,
223 1.44 msaitoh device_xname(sc->sc_dev));
224 1.2 drochner
225 1.1 drochner command = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG);
226 1.1 drochner
227 1.1 drochner if (!(command & PCI_COMMAND_MASTER_ENABLE)) {
228 1.44 msaitoh aprint_error(": failed to enable bus mastering\n");
229 1.1 drochner return;
230 1.1 drochner }
231 1.1 drochner
232 1.1 drochner if (!(command & PCI_COMMAND_MEM_ENABLE)) {
233 1.44 msaitoh aprint_error(": failed to enable memory mapping\n");
234 1.1 drochner return;
235 1.1 drochner }
236 1.1 drochner if (pci_mapreg_map(pa, TXP_PCI_LOMEM, PCI_MAPREG_TYPE_MEM, 0,
237 1.1 drochner &sc->sc_bt, &sc->sc_bh, NULL, NULL)) {
238 1.44 msaitoh aprint_error(": can't map mem space %d\n", 0);
239 1.1 drochner return;
240 1.1 drochner }
241 1.1 drochner
242 1.64 thorpej if (pci_dma64_available(pa))
243 1.64 thorpej sc->sc_dmat = pa->pa_dmat64;
244 1.64 thorpej else
245 1.64 thorpej sc->sc_dmat = pa->pa_dmat;
246 1.1 drochner
247 1.1 drochner /*
248 1.1 drochner * Allocate our interrupt.
249 1.1 drochner */
250 1.1 drochner if (pci_intr_map(pa, &ih)) {
251 1.44 msaitoh aprint_error(": couldn't map interrupt\n");
252 1.1 drochner return;
253 1.1 drochner }
254 1.1 drochner
255 1.40 christos intrstr = pci_intr_string(pc, ih, intrbuf, sizeof(intrbuf));
256 1.51 jdolecek sc->sc_ih = pci_intr_establish_xname(pc, ih, IPL_NET, txp_intr, sc,
257 1.51 jdolecek device_xname(self));
258 1.1 drochner if (sc->sc_ih == NULL) {
259 1.44 msaitoh aprint_error(": couldn't establish interrupt");
260 1.1 drochner if (intrstr != NULL)
261 1.45 msaitoh aprint_normal(" at %s", intrstr);
262 1.45 msaitoh aprint_normal("\n");
263 1.1 drochner return;
264 1.1 drochner }
265 1.54 msaitoh aprint_normal(": interrupting at %s\n", intrstr);
266 1.1 drochner
267 1.1 drochner if (txp_chip_init(sc))
268 1.7 is goto cleanupintr;
269 1.1 drochner
270 1.1 drochner if (txp_download_fw(sc))
271 1.7 is goto cleanupintr;
272 1.1 drochner
273 1.1 drochner if (txp_alloc_rings(sc))
274 1.7 is goto cleanupintr;
275 1.1 drochner
276 1.1 drochner if (txp_command(sc, TXP_CMD_MAX_PKT_SIZE_WRITE, TXP_MAX_PKTLEN, 0, 0,
277 1.1 drochner NULL, NULL, NULL, 1))
278 1.7 is goto cleanupintr;
279 1.1 drochner
280 1.1 drochner if (txp_command(sc, TXP_CMD_STATION_ADDRESS_READ, 0, 0, 0,
281 1.1 drochner &p1, &p2, NULL, 1))
282 1.7 is goto cleanupintr;
283 1.1 drochner
284 1.1 drochner p1 = htole16(p1);
285 1.53 msaitoh enaddr[0] = ((uint8_t *)&p1)[1];
286 1.53 msaitoh enaddr[1] = ((uint8_t *)&p1)[0];
287 1.1 drochner p2 = htole32(p2);
288 1.53 msaitoh enaddr[2] = ((uint8_t *)&p2)[3];
289 1.53 msaitoh enaddr[3] = ((uint8_t *)&p2)[2];
290 1.53 msaitoh enaddr[4] = ((uint8_t *)&p2)[1];
291 1.53 msaitoh enaddr[5] = ((uint8_t *)&p2)[0];
292 1.1 drochner
293 1.44 msaitoh aprint_normal_dev(self, "Ethernet address %s\n",
294 1.44 msaitoh ether_sprintf(enaddr));
295 1.1 drochner sc->sc_cold = 0;
296 1.1 drochner
297 1.57 msaitoh /* Initialize ifmedia structures. */
298 1.57 msaitoh sc->sc_arpcom.ec_ifmedia = &sc->sc_ifmedia;
299 1.1 drochner ifmedia_init(&sc->sc_ifmedia, 0, txp_ifmedia_upd, txp_ifmedia_sts);
300 1.2 drochner if (flags & TXP_FIBER) {
301 1.53 msaitoh ifmedia_add(&sc->sc_ifmedia, IFM_ETHER | IFM_100_FX,
302 1.2 drochner 0, NULL);
303 1.53 msaitoh ifmedia_add(&sc->sc_ifmedia, IFM_ETHER | IFM_100_FX | IFM_FDX,
304 1.2 drochner 0, NULL);
305 1.2 drochner } else {
306 1.53 msaitoh ifmedia_add(&sc->sc_ifmedia, IFM_ETHER | IFM_10_T,
307 1.2 drochner 0, NULL);
308 1.53 msaitoh ifmedia_add(&sc->sc_ifmedia, IFM_ETHER | IFM_10_T | IFM_FDX,
309 1.2 drochner 0, NULL);
310 1.53 msaitoh ifmedia_add(&sc->sc_ifmedia, IFM_ETHER | IFM_100_TX,
311 1.2 drochner 0, NULL);
312 1.53 msaitoh ifmedia_add(&sc->sc_ifmedia, IFM_ETHER | IFM_100_TX | IFM_FDX,
313 1.2 drochner 0, NULL);
314 1.2 drochner }
315 1.55 msaitoh ifmedia_add(&sc->sc_ifmedia, IFM_ETHER | IFM_AUTO, 0, NULL);
316 1.1 drochner
317 1.1 drochner sc->sc_xcvr = TXP_XCVR_AUTO;
318 1.1 drochner txp_command(sc, TXP_CMD_XCVR_SELECT, TXP_XCVR_AUTO, 0, 0,
319 1.1 drochner NULL, NULL, NULL, 0);
320 1.53 msaitoh ifmedia_set(&sc->sc_ifmedia, IFM_ETHER | IFM_AUTO);
321 1.1 drochner
322 1.1 drochner ifp->if_softc = sc;
323 1.1 drochner ifp->if_mtu = ETHERMTU;
324 1.1 drochner ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
325 1.1 drochner ifp->if_ioctl = txp_ioctl;
326 1.1 drochner ifp->if_start = txp_start;
327 1.1 drochner ifp->if_watchdog = txp_watchdog;
328 1.1 drochner ifp->if_baudrate = 10000000;
329 1.1 drochner IFQ_SET_MAXLEN(&ifp->if_snd, TX_ENTRIES);
330 1.1 drochner IFQ_SET_READY(&ifp->if_snd);
331 1.1 drochner ifp->if_capabilities = 0;
332 1.39 chs strlcpy(ifp->if_xname, device_xname(sc->sc_dev), IFNAMSIZ);
333 1.1 drochner
334 1.1 drochner txp_capabilities(sc);
335 1.1 drochner
336 1.20 ad callout_init(&sc->sc_tick, 0);
337 1.1 drochner callout_setfunc(&sc->sc_tick, txp_tick, sc);
338 1.1 drochner
339 1.1 drochner /*
340 1.1 drochner * Attach us everywhere
341 1.1 drochner */
342 1.1 drochner if_attach(ifp);
343 1.46 ozaki if_deferred_start_init(ifp, NULL);
344 1.1 drochner ether_ifattach(ifp, enaddr);
345 1.1 drochner
346 1.35 tsutsui if (pmf_device_register1(self, NULL, NULL, txp_shutdown))
347 1.35 tsutsui pmf_class_network_register(self, ifp);
348 1.35 tsutsui else
349 1.35 tsutsui aprint_error_dev(self, "couldn't establish power handler\n");
350 1.7 is
351 1.7 is return;
352 1.7 is
353 1.7 is cleanupintr:
354 1.55 msaitoh pci_intr_disestablish(pc, sc->sc_ih);
355 1.7 is
356 1.7 is return;
357 1.7 is
358 1.1 drochner }
359 1.1 drochner
360 1.62 maxv static int
361 1.29 dsl txp_chip_init(struct txp_softc *sc)
362 1.1 drochner {
363 1.1 drochner /* disable interrupts */
364 1.1 drochner WRITE_REG(sc, TXP_IER, 0);
365 1.1 drochner WRITE_REG(sc, TXP_IMR,
366 1.1 drochner TXP_INT_SELF | TXP_INT_PCI_TABORT | TXP_INT_PCI_MABORT |
367 1.1 drochner TXP_INT_DMA3 | TXP_INT_DMA2 | TXP_INT_DMA1 | TXP_INT_DMA0 |
368 1.1 drochner TXP_INT_LATCH);
369 1.1 drochner
370 1.1 drochner /* ack all interrupts */
371 1.1 drochner WRITE_REG(sc, TXP_ISR, TXP_INT_RESERVED | TXP_INT_LATCH |
372 1.1 drochner TXP_INT_A2H_7 | TXP_INT_A2H_6 | TXP_INT_A2H_5 | TXP_INT_A2H_4 |
373 1.1 drochner TXP_INT_SELF | TXP_INT_PCI_TABORT | TXP_INT_PCI_MABORT |
374 1.1 drochner TXP_INT_DMA3 | TXP_INT_DMA2 | TXP_INT_DMA1 | TXP_INT_DMA0 |
375 1.1 drochner TXP_INT_A2H_3 | TXP_INT_A2H_2 | TXP_INT_A2H_1 | TXP_INT_A2H_0);
376 1.1 drochner
377 1.1 drochner if (txp_reset_adapter(sc))
378 1.1 drochner return (-1);
379 1.1 drochner
380 1.1 drochner /* disable interrupts */
381 1.1 drochner WRITE_REG(sc, TXP_IER, 0);
382 1.1 drochner WRITE_REG(sc, TXP_IMR,
383 1.1 drochner TXP_INT_SELF | TXP_INT_PCI_TABORT | TXP_INT_PCI_MABORT |
384 1.1 drochner TXP_INT_DMA3 | TXP_INT_DMA2 | TXP_INT_DMA1 | TXP_INT_DMA0 |
385 1.1 drochner TXP_INT_LATCH);
386 1.1 drochner
387 1.1 drochner /* ack all interrupts */
388 1.1 drochner WRITE_REG(sc, TXP_ISR, TXP_INT_RESERVED | TXP_INT_LATCH |
389 1.1 drochner TXP_INT_A2H_7 | TXP_INT_A2H_6 | TXP_INT_A2H_5 | TXP_INT_A2H_4 |
390 1.1 drochner TXP_INT_SELF | TXP_INT_PCI_TABORT | TXP_INT_PCI_MABORT |
391 1.1 drochner TXP_INT_DMA3 | TXP_INT_DMA2 | TXP_INT_DMA1 | TXP_INT_DMA0 |
392 1.1 drochner TXP_INT_A2H_3 | TXP_INT_A2H_2 | TXP_INT_A2H_1 | TXP_INT_A2H_0);
393 1.1 drochner
394 1.1 drochner return (0);
395 1.1 drochner }
396 1.1 drochner
397 1.62 maxv static int
398 1.29 dsl txp_reset_adapter(struct txp_softc *sc)
399 1.1 drochner {
400 1.53 msaitoh uint32_t r;
401 1.1 drochner int i;
402 1.1 drochner
403 1.1 drochner WRITE_REG(sc, TXP_SRR, TXP_SRR_ALL);
404 1.1 drochner DELAY(1000);
405 1.1 drochner WRITE_REG(sc, TXP_SRR, 0);
406 1.1 drochner
407 1.1 drochner /* Should wait max 6 seconds */
408 1.1 drochner for (i = 0; i < 6000; i++) {
409 1.1 drochner r = READ_REG(sc, TXP_A2H_0);
410 1.1 drochner if (r == STAT_WAITING_FOR_HOST_REQUEST)
411 1.1 drochner break;
412 1.1 drochner DELAY(1000);
413 1.1 drochner }
414 1.1 drochner
415 1.1 drochner if (r != STAT_WAITING_FOR_HOST_REQUEST) {
416 1.1 drochner printf("%s: reset hung\n", TXP_DEVNAME(sc));
417 1.1 drochner return (-1);
418 1.1 drochner }
419 1.1 drochner
420 1.1 drochner return (0);
421 1.1 drochner }
422 1.1 drochner
423 1.62 maxv static int
424 1.29 dsl txp_download_fw(struct txp_softc *sc)
425 1.1 drochner {
426 1.12 chs const struct txp_fw_file_header *fileheader;
427 1.12 chs const struct txp_fw_section_header *secthead;
428 1.1 drochner int sect;
429 1.53 msaitoh uint32_t r, i, ier, imr;
430 1.1 drochner
431 1.1 drochner ier = READ_REG(sc, TXP_IER);
432 1.1 drochner WRITE_REG(sc, TXP_IER, ier | TXP_INT_A2H_0);
433 1.1 drochner
434 1.1 drochner imr = READ_REG(sc, TXP_IMR);
435 1.1 drochner WRITE_REG(sc, TXP_IMR, imr | TXP_INT_A2H_0);
436 1.1 drochner
437 1.1 drochner for (i = 0; i < 10000; i++) {
438 1.1 drochner r = READ_REG(sc, TXP_A2H_0);
439 1.1 drochner if (r == STAT_WAITING_FOR_HOST_REQUEST)
440 1.1 drochner break;
441 1.1 drochner DELAY(50);
442 1.1 drochner }
443 1.1 drochner if (r != STAT_WAITING_FOR_HOST_REQUEST) {
444 1.1 drochner printf(": not waiting for host request\n");
445 1.1 drochner return (-1);
446 1.1 drochner }
447 1.1 drochner
448 1.1 drochner /* Ack the status */
449 1.1 drochner WRITE_REG(sc, TXP_ISR, TXP_INT_A2H_0);
450 1.1 drochner
451 1.12 chs fileheader = (const struct txp_fw_file_header *)tc990image;
452 1.44 msaitoh if (memcmp("TYPHOON", fileheader->magicid,
453 1.44 msaitoh sizeof(fileheader->magicid))) {
454 1.1 drochner printf(": fw invalid magic\n");
455 1.1 drochner return (-1);
456 1.1 drochner }
457 1.1 drochner
458 1.1 drochner /* Tell boot firmware to get ready for image */
459 1.1 drochner WRITE_REG(sc, TXP_H2A_1, le32toh(fileheader->addr));
460 1.67 thorpej WRITE_REG(sc, TXP_H2A_2, le32toh(fileheader->hmac[0]));
461 1.67 thorpej WRITE_REG(sc, TXP_H2A_3, le32toh(fileheader->hmac[1]));
462 1.67 thorpej WRITE_REG(sc, TXP_H2A_4, le32toh(fileheader->hmac[2]));
463 1.67 thorpej WRITE_REG(sc, TXP_H2A_5, le32toh(fileheader->hmac[3]));
464 1.67 thorpej WRITE_REG(sc, TXP_H2A_6, le32toh(fileheader->hmac[4]));
465 1.1 drochner WRITE_REG(sc, TXP_H2A_0, TXP_BOOTCMD_RUNTIME_IMAGE);
466 1.1 drochner
467 1.1 drochner if (txp_download_fw_wait(sc)) {
468 1.44 msaitoh printf("%s: fw wait failed, initial\n",
469 1.44 msaitoh device_xname(sc->sc_dev));
470 1.1 drochner return (-1);
471 1.1 drochner }
472 1.1 drochner
473 1.12 chs secthead = (const struct txp_fw_section_header *)
474 1.53 msaitoh (((const uint8_t *)tc990image) +
475 1.12 chs sizeof(struct txp_fw_file_header));
476 1.1 drochner
477 1.1 drochner for (sect = 0; sect < le32toh(fileheader->nsections); sect++) {
478 1.1 drochner if (txp_download_fw_section(sc, secthead, sect))
479 1.1 drochner return (-1);
480 1.12 chs secthead = (const struct txp_fw_section_header *)
481 1.53 msaitoh (((const uint8_t *)secthead) + le32toh(secthead->nbytes) +
482 1.1 drochner sizeof(*secthead));
483 1.1 drochner }
484 1.1 drochner
485 1.1 drochner WRITE_REG(sc, TXP_H2A_0, TXP_BOOTCMD_DOWNLOAD_COMPLETE);
486 1.1 drochner
487 1.1 drochner for (i = 0; i < 10000; i++) {
488 1.1 drochner r = READ_REG(sc, TXP_A2H_0);
489 1.1 drochner if (r == STAT_WAITING_FOR_BOOT)
490 1.1 drochner break;
491 1.1 drochner DELAY(50);
492 1.1 drochner }
493 1.1 drochner if (r != STAT_WAITING_FOR_BOOT) {
494 1.1 drochner printf(": not waiting for boot\n");
495 1.1 drochner return (-1);
496 1.1 drochner }
497 1.1 drochner
498 1.1 drochner WRITE_REG(sc, TXP_IER, ier);
499 1.1 drochner WRITE_REG(sc, TXP_IMR, imr);
500 1.1 drochner
501 1.1 drochner return (0);
502 1.1 drochner }
503 1.1 drochner
504 1.62 maxv static int
505 1.29 dsl txp_download_fw_wait(struct txp_softc *sc)
506 1.1 drochner {
507 1.53 msaitoh uint32_t i, r;
508 1.1 drochner
509 1.1 drochner for (i = 0; i < 10000; i++) {
510 1.1 drochner r = READ_REG(sc, TXP_ISR);
511 1.1 drochner if (r & TXP_INT_A2H_0)
512 1.1 drochner break;
513 1.1 drochner DELAY(50);
514 1.1 drochner }
515 1.1 drochner
516 1.1 drochner if (!(r & TXP_INT_A2H_0)) {
517 1.1 drochner printf(": fw wait failed comm0\n");
518 1.1 drochner return (-1);
519 1.1 drochner }
520 1.1 drochner
521 1.1 drochner WRITE_REG(sc, TXP_ISR, TXP_INT_A2H_0);
522 1.1 drochner
523 1.1 drochner r = READ_REG(sc, TXP_A2H_0);
524 1.1 drochner if (r != STAT_WAITING_FOR_SEGMENT) {
525 1.1 drochner printf(": fw not waiting for segment\n");
526 1.1 drochner return (-1);
527 1.1 drochner }
528 1.1 drochner return (0);
529 1.1 drochner }
530 1.1 drochner
531 1.62 maxv static int
532 1.44 msaitoh txp_download_fw_section(struct txp_softc *sc,
533 1.44 msaitoh const struct txp_fw_section_header *sect, int sectnum)
534 1.1 drochner {
535 1.1 drochner struct txp_dma_alloc dma;
536 1.1 drochner int rseg, err = 0;
537 1.1 drochner struct mbuf m;
538 1.14 christos #ifdef INET
539 1.53 msaitoh uint16_t csum;
540 1.14 christos #endif
541 1.1 drochner
542 1.1 drochner /* Skip zero length sections */
543 1.1 drochner if (sect->nbytes == 0)
544 1.1 drochner return (0);
545 1.1 drochner
546 1.1 drochner /* Make sure we aren't past the end of the image */
547 1.53 msaitoh rseg = ((const uint8_t *)sect) - ((const uint8_t *)tc990image);
548 1.1 drochner if (rseg >= sizeof(tc990image)) {
549 1.1 drochner printf(": fw invalid section address, section %d\n", sectnum);
550 1.1 drochner return (-1);
551 1.1 drochner }
552 1.1 drochner
553 1.1 drochner /* Make sure this section doesn't go past the end */
554 1.1 drochner rseg += le32toh(sect->nbytes);
555 1.1 drochner if (rseg >= sizeof(tc990image)) {
556 1.1 drochner printf(": fw truncated section %d\n", sectnum);
557 1.1 drochner return (-1);
558 1.1 drochner }
559 1.1 drochner
560 1.1 drochner /* map a buffer, copy segment to it, get physaddr */
561 1.1 drochner if (txp_dma_malloc(sc, le32toh(sect->nbytes), &dma, 0)) {
562 1.1 drochner printf(": fw dma malloc failed, section %d\n", sectnum);
563 1.1 drochner return (-1);
564 1.1 drochner }
565 1.1 drochner
566 1.53 msaitoh memcpy(dma.dma_vaddr, ((const uint8_t *)sect) + sizeof(*sect),
567 1.1 drochner le32toh(sect->nbytes));
568 1.1 drochner
569 1.1 drochner /*
570 1.1 drochner * dummy up mbuf and verify section checksum
571 1.1 drochner */
572 1.1 drochner m.m_type = MT_DATA;
573 1.1 drochner m.m_next = m.m_nextpkt = NULL;
574 1.50 msaitoh m.m_owner = NULL;
575 1.1 drochner m.m_len = le32toh(sect->nbytes);
576 1.1 drochner m.m_data = dma.dma_vaddr;
577 1.1 drochner m.m_flags = 0;
578 1.14 christos #ifdef INET
579 1.1 drochner csum = in_cksum(&m, le32toh(sect->nbytes));
580 1.1 drochner if (csum != sect->cksum) {
581 1.1 drochner printf(": fw section %d, bad cksum (expected 0x%x got 0x%x)\n",
582 1.1 drochner sectnum, sect->cksum, csum);
583 1.14 christos txp_dma_free(sc, &dma);
584 1.14 christos return -1;
585 1.1 drochner }
586 1.14 christos #endif
587 1.1 drochner
588 1.1 drochner bus_dmamap_sync(sc->sc_dmat, dma.dma_map, 0,
589 1.1 drochner dma.dma_map->dm_mapsize, BUS_DMASYNC_PREWRITE);
590 1.1 drochner
591 1.1 drochner WRITE_REG(sc, TXP_H2A_1, le32toh(sect->nbytes));
592 1.1 drochner WRITE_REG(sc, TXP_H2A_2, le32toh(sect->cksum));
593 1.1 drochner WRITE_REG(sc, TXP_H2A_3, le32toh(sect->addr));
594 1.65 thorpej WRITE_REG(sc, TXP_H2A_4, BUS_ADDR_HI32(dma.dma_paddr));
595 1.65 thorpej WRITE_REG(sc, TXP_H2A_5, BUS_ADDR_LO32(dma.dma_paddr));
596 1.1 drochner WRITE_REG(sc, TXP_H2A_0, TXP_BOOTCMD_SEGMENT_AVAILABLE);
597 1.1 drochner
598 1.1 drochner if (txp_download_fw_wait(sc)) {
599 1.1 drochner printf("%s: fw wait failed, section %d\n",
600 1.39 chs device_xname(sc->sc_dev), sectnum);
601 1.1 drochner err = -1;
602 1.1 drochner }
603 1.1 drochner
604 1.1 drochner bus_dmamap_sync(sc->sc_dmat, dma.dma_map, 0,
605 1.1 drochner dma.dma_map->dm_mapsize, BUS_DMASYNC_POSTWRITE);
606 1.1 drochner
607 1.1 drochner txp_dma_free(sc, &dma);
608 1.1 drochner return (err);
609 1.1 drochner }
610 1.1 drochner
611 1.62 maxv static int
612 1.29 dsl txp_intr(void *vsc)
613 1.1 drochner {
614 1.1 drochner struct txp_softc *sc = vsc;
615 1.1 drochner struct txp_hostvar *hv = sc->sc_hostvar;
616 1.53 msaitoh uint32_t isr;
617 1.1 drochner int claimed = 0;
618 1.1 drochner
619 1.1 drochner /* mask all interrupts */
620 1.1 drochner WRITE_REG(sc, TXP_IMR, TXP_INT_RESERVED | TXP_INT_SELF |
621 1.1 drochner TXP_INT_A2H_7 | TXP_INT_A2H_6 | TXP_INT_A2H_5 | TXP_INT_A2H_4 |
622 1.1 drochner TXP_INT_A2H_2 | TXP_INT_A2H_1 | TXP_INT_A2H_0 |
623 1.1 drochner TXP_INT_DMA3 | TXP_INT_DMA2 | TXP_INT_DMA1 | TXP_INT_DMA0 |
624 1.1 drochner TXP_INT_PCI_TABORT | TXP_INT_PCI_MABORT | TXP_INT_LATCH);
625 1.1 drochner
626 1.1 drochner bus_dmamap_sync(sc->sc_dmat, sc->sc_host_dma.dma_map, 0,
627 1.53 msaitoh sizeof(struct txp_hostvar),
628 1.53 msaitoh BUS_DMASYNC_POSTWRITE | BUS_DMASYNC_POSTREAD);
629 1.1 drochner
630 1.1 drochner isr = READ_REG(sc, TXP_ISR);
631 1.1 drochner while (isr) {
632 1.1 drochner claimed = 1;
633 1.1 drochner WRITE_REG(sc, TXP_ISR, isr);
634 1.1 drochner
635 1.1 drochner if ((*sc->sc_rxhir.r_roff) != (*sc->sc_rxhir.r_woff))
636 1.1 drochner txp_rx_reclaim(sc, &sc->sc_rxhir, &sc->sc_rxhiring_dma);
637 1.1 drochner if ((*sc->sc_rxlor.r_roff) != (*sc->sc_rxlor.r_woff))
638 1.1 drochner txp_rx_reclaim(sc, &sc->sc_rxlor, &sc->sc_rxloring_dma);
639 1.1 drochner
640 1.1 drochner if (hv->hv_rx_buf_write_idx == hv->hv_rx_buf_read_idx)
641 1.1 drochner txp_rxbuf_reclaim(sc);
642 1.1 drochner
643 1.1 drochner if (sc->sc_txhir.r_cnt && (sc->sc_txhir.r_cons !=
644 1.1 drochner TXP_OFFSET2IDX(le32toh(*(sc->sc_txhir.r_off)))))
645 1.1 drochner txp_tx_reclaim(sc, &sc->sc_txhir, &sc->sc_txhiring_dma);
646 1.1 drochner
647 1.1 drochner if (sc->sc_txlor.r_cnt && (sc->sc_txlor.r_cons !=
648 1.1 drochner TXP_OFFSET2IDX(le32toh(*(sc->sc_txlor.r_off)))))
649 1.1 drochner txp_tx_reclaim(sc, &sc->sc_txlor, &sc->sc_txloring_dma);
650 1.1 drochner
651 1.1 drochner isr = READ_REG(sc, TXP_ISR);
652 1.1 drochner }
653 1.1 drochner
654 1.1 drochner bus_dmamap_sync(sc->sc_dmat, sc->sc_host_dma.dma_map, 0,
655 1.53 msaitoh sizeof(struct txp_hostvar),
656 1.53 msaitoh BUS_DMASYNC_POSTWRITE | BUS_DMASYNC_POSTREAD);
657 1.1 drochner
658 1.1 drochner /* unmask all interrupts */
659 1.1 drochner WRITE_REG(sc, TXP_IMR, TXP_INT_A2H_3);
660 1.1 drochner
661 1.46 ozaki if_schedule_deferred_start(&sc->sc_arpcom.ec_if);
662 1.1 drochner
663 1.1 drochner return (claimed);
664 1.1 drochner }
665 1.1 drochner
666 1.69 thorpej static struct txp_swdesc *
667 1.69 thorpej txp_rxd_alloc(struct txp_softc *sc)
668 1.69 thorpej {
669 1.69 thorpej if (sc->sc_txd_pool_ptr == 0)
670 1.69 thorpej return NULL;
671 1.69 thorpej return sc->sc_rxd_pool[--sc->sc_txd_pool_ptr];
672 1.69 thorpej }
673 1.69 thorpej
674 1.69 thorpej static void
675 1.69 thorpej txp_rxd_free(struct txp_softc *sc, struct txp_swdesc *sd)
676 1.69 thorpej {
677 1.69 thorpej KASSERT(sc->sc_txd_pool_ptr < RXBUF_ENTRIES);
678 1.69 thorpej sc->sc_rxd_pool[sc->sc_txd_pool_ptr++] = sd;
679 1.69 thorpej }
680 1.69 thorpej
681 1.62 maxv static void
682 1.44 msaitoh txp_rx_reclaim(struct txp_softc *sc, struct txp_rx_ring *r,
683 1.44 msaitoh struct txp_dma_alloc *dma)
684 1.1 drochner {
685 1.1 drochner struct ifnet *ifp = &sc->sc_arpcom.ec_if;
686 1.1 drochner struct txp_rx_desc *rxd;
687 1.1 drochner struct mbuf *m;
688 1.1 drochner struct txp_swdesc *sd;
689 1.53 msaitoh uint32_t roff, woff;
690 1.1 drochner int sumflags = 0;
691 1.1 drochner int idx;
692 1.1 drochner
693 1.1 drochner roff = le32toh(*r->r_roff);
694 1.1 drochner woff = le32toh(*r->r_woff);
695 1.1 drochner idx = roff / sizeof(struct txp_rx_desc);
696 1.1 drochner rxd = r->r_desc + idx;
697 1.1 drochner
698 1.1 drochner while (roff != woff) {
699 1.1 drochner
700 1.1 drochner bus_dmamap_sync(sc->sc_dmat, dma->dma_map,
701 1.44 msaitoh idx * sizeof(struct txp_rx_desc),
702 1.44 msaitoh sizeof(struct txp_rx_desc), BUS_DMASYNC_POSTREAD);
703 1.1 drochner
704 1.1 drochner if (rxd->rx_flags & RX_FLAGS_ERROR) {
705 1.39 chs printf("%s: error 0x%x\n", device_xname(sc->sc_dev),
706 1.1 drochner le32toh(rxd->rx_stat));
707 1.63 thorpej if_statinc(ifp, if_ierrors);
708 1.1 drochner goto next;
709 1.1 drochner }
710 1.1 drochner
711 1.1 drochner /* retrieve stashed pointer */
712 1.34 tsutsui memcpy(&sd, __UNVOLATILE(&rxd->rx_vaddrlo), sizeof(sd));
713 1.1 drochner
714 1.1 drochner bus_dmamap_sync(sc->sc_dmat, sd->sd_map, 0,
715 1.1 drochner sd->sd_map->dm_mapsize, BUS_DMASYNC_POSTREAD);
716 1.1 drochner bus_dmamap_unload(sc->sc_dmat, sd->sd_map);
717 1.1 drochner m = sd->sd_mbuf;
718 1.69 thorpej txp_rxd_free(sc, sd);
719 1.1 drochner m->m_pkthdr.len = m->m_len = le16toh(rxd->rx_len);
720 1.1 drochner
721 1.1 drochner #ifdef __STRICT_ALIGNMENT
722 1.1 drochner {
723 1.1 drochner /*
724 1.1 drochner * XXX Nice chip, except it won't accept "off by 2"
725 1.1 drochner * buffers, so we're force to copy. Supposedly
726 1.1 drochner * this will be fixed in a newer firmware rev
727 1.1 drochner * and this will be temporary.
728 1.1 drochner */
729 1.1 drochner struct mbuf *mnew;
730 1.1 drochner
731 1.1 drochner MGETHDR(mnew, M_DONTWAIT, MT_DATA);
732 1.1 drochner if (mnew == NULL) {
733 1.1 drochner m_freem(m);
734 1.1 drochner goto next;
735 1.1 drochner }
736 1.1 drochner if (m->m_len > (MHLEN - 2)) {
737 1.1 drochner MCLGET(mnew, M_DONTWAIT);
738 1.1 drochner if (!(mnew->m_flags & M_EXT)) {
739 1.1 drochner m_freem(mnew);
740 1.1 drochner m_freem(m);
741 1.1 drochner goto next;
742 1.1 drochner }
743 1.1 drochner }
744 1.43 ozaki m_set_rcvif(mnew, ifp);
745 1.1 drochner mnew->m_pkthdr.len = mnew->m_len = m->m_len;
746 1.1 drochner mnew->m_data += 2;
747 1.34 tsutsui memcpy(mnew->m_data, m->m_data, m->m_len);
748 1.1 drochner m_freem(m);
749 1.1 drochner m = mnew;
750 1.1 drochner }
751 1.1 drochner #endif
752 1.1 drochner
753 1.1 drochner if (rxd->rx_stat & htole32(RX_STAT_IPCKSUMBAD))
754 1.53 msaitoh sumflags |= (M_CSUM_IPv4 | M_CSUM_IPv4_BAD);
755 1.1 drochner else if (rxd->rx_stat & htole32(RX_STAT_IPCKSUMGOOD))
756 1.2 drochner sumflags |= M_CSUM_IPv4;
757 1.1 drochner
758 1.1 drochner if (rxd->rx_stat & htole32(RX_STAT_TCPCKSUMBAD))
759 1.53 msaitoh sumflags |= (M_CSUM_TCPv4 | M_CSUM_TCP_UDP_BAD);
760 1.1 drochner else if (rxd->rx_stat & htole32(RX_STAT_TCPCKSUMGOOD))
761 1.2 drochner sumflags |= M_CSUM_TCPv4;
762 1.1 drochner
763 1.1 drochner if (rxd->rx_stat & htole32(RX_STAT_UDPCKSUMBAD))
764 1.53 msaitoh sumflags |= (M_CSUM_UDPv4 | M_CSUM_TCP_UDP_BAD);
765 1.1 drochner else if (rxd->rx_stat & htole32(RX_STAT_UDPCKSUMGOOD))
766 1.2 drochner sumflags |= M_CSUM_UDPv4;
767 1.1 drochner
768 1.2 drochner m->m_pkthdr.csum_flags = sumflags;
769 1.1 drochner
770 1.1 drochner if (rxd->rx_stat & htole32(RX_STAT_VLAN)) {
771 1.48 knakahar vlan_set_tag(m, htons(rxd->rx_vlan >> 16));
772 1.1 drochner }
773 1.1 drochner
774 1.42 ozaki if_percpuq_enqueue(ifp->if_percpuq, m);
775 1.1 drochner
776 1.1 drochner next:
777 1.1 drochner bus_dmamap_sync(sc->sc_dmat, dma->dma_map,
778 1.44 msaitoh idx * sizeof(struct txp_rx_desc),
779 1.44 msaitoh sizeof(struct txp_rx_desc), BUS_DMASYNC_PREREAD);
780 1.1 drochner
781 1.1 drochner roff += sizeof(struct txp_rx_desc);
782 1.1 drochner if (roff == (RX_ENTRIES * sizeof(struct txp_rx_desc))) {
783 1.1 drochner idx = 0;
784 1.1 drochner roff = 0;
785 1.1 drochner rxd = r->r_desc;
786 1.1 drochner } else {
787 1.1 drochner idx++;
788 1.1 drochner rxd++;
789 1.1 drochner }
790 1.1 drochner woff = le32toh(*r->r_woff);
791 1.1 drochner }
792 1.1 drochner
793 1.1 drochner *r->r_roff = htole32(woff);
794 1.1 drochner }
795 1.1 drochner
796 1.62 maxv static void
797 1.29 dsl txp_rxbuf_reclaim(struct txp_softc *sc)
798 1.1 drochner {
799 1.1 drochner struct ifnet *ifp = &sc->sc_arpcom.ec_if;
800 1.1 drochner struct txp_hostvar *hv = sc->sc_hostvar;
801 1.1 drochner struct txp_rxbuf_desc *rbd;
802 1.1 drochner struct txp_swdesc *sd;
803 1.53 msaitoh uint32_t i, end;
804 1.1 drochner
805 1.1 drochner end = TXP_OFFSET2IDX(le32toh(hv->hv_rx_buf_read_idx));
806 1.1 drochner i = TXP_OFFSET2IDX(le32toh(hv->hv_rx_buf_write_idx));
807 1.1 drochner
808 1.1 drochner if (++i == RXBUF_ENTRIES)
809 1.1 drochner i = 0;
810 1.1 drochner
811 1.1 drochner rbd = sc->sc_rxbufs + i;
812 1.1 drochner
813 1.1 drochner while (i != end) {
814 1.69 thorpej sd = txp_rxd_alloc(sc);
815 1.1 drochner if (sd == NULL)
816 1.1 drochner break;
817 1.1 drochner
818 1.1 drochner MGETHDR(sd->sd_mbuf, M_DONTWAIT, MT_DATA);
819 1.1 drochner if (sd->sd_mbuf == NULL)
820 1.1 drochner goto err_sd;
821 1.1 drochner
822 1.1 drochner MCLGET(sd->sd_mbuf, M_DONTWAIT);
823 1.1 drochner if ((sd->sd_mbuf->m_flags & M_EXT) == 0)
824 1.1 drochner goto err_mbuf;
825 1.43 ozaki m_set_rcvif(sd->sd_mbuf, ifp);
826 1.1 drochner sd->sd_mbuf->m_pkthdr.len = sd->sd_mbuf->m_len = MCLBYTES;
827 1.1 drochner if (bus_dmamap_load_mbuf(sc->sc_dmat, sd->sd_map, sd->sd_mbuf,
828 1.1 drochner BUS_DMA_NOWAIT)) {
829 1.1 drochner goto err_mbuf;
830 1.1 drochner }
831 1.1 drochner
832 1.1 drochner bus_dmamap_sync(sc->sc_dmat, sc->sc_rxbufring_dma.dma_map,
833 1.1 drochner i * sizeof(struct txp_rxbuf_desc),
834 1.1 drochner sizeof(struct txp_rxbuf_desc), BUS_DMASYNC_POSTWRITE);
835 1.10 perry
836 1.1 drochner /* stash away pointer */
837 1.34 tsutsui memcpy(__UNVOLATILE(&rbd->rb_vaddrlo), &sd, sizeof(sd));
838 1.1 drochner
839 1.65 thorpej rbd->rb_paddrlo =
840 1.65 thorpej htole32(BUS_ADDR_LO32(sd->sd_map->dm_segs[0].ds_addr));
841 1.65 thorpej rbd->rb_paddrhi =
842 1.65 thorpej htole32(BUS_ADDR_HI32(sd->sd_map->dm_segs[0].ds_addr));
843 1.1 drochner
844 1.1 drochner bus_dmamap_sync(sc->sc_dmat, sd->sd_map, 0,
845 1.1 drochner sd->sd_map->dm_mapsize, BUS_DMASYNC_PREREAD);
846 1.1 drochner
847 1.1 drochner bus_dmamap_sync(sc->sc_dmat, sc->sc_rxbufring_dma.dma_map,
848 1.1 drochner i * sizeof(struct txp_rxbuf_desc),
849 1.1 drochner sizeof(struct txp_rxbuf_desc), BUS_DMASYNC_PREWRITE);
850 1.1 drochner
851 1.1 drochner hv->hv_rx_buf_write_idx = htole32(TXP_IDX2OFFSET(i));
852 1.1 drochner
853 1.1 drochner if (++i == RXBUF_ENTRIES) {
854 1.1 drochner i = 0;
855 1.1 drochner rbd = sc->sc_rxbufs;
856 1.1 drochner } else
857 1.1 drochner rbd++;
858 1.1 drochner }
859 1.1 drochner return;
860 1.1 drochner
861 1.1 drochner err_mbuf:
862 1.1 drochner m_freem(sd->sd_mbuf);
863 1.1 drochner err_sd:
864 1.69 thorpej txp_rxd_free(sc, sd);
865 1.1 drochner }
866 1.1 drochner
867 1.1 drochner /*
868 1.1 drochner * Reclaim mbufs and entries from a transmit ring.
869 1.1 drochner */
870 1.62 maxv static void
871 1.44 msaitoh txp_tx_reclaim(struct txp_softc *sc, struct txp_tx_ring *r,
872 1.44 msaitoh struct txp_dma_alloc *dma)
873 1.1 drochner {
874 1.1 drochner struct ifnet *ifp = &sc->sc_arpcom.ec_if;
875 1.53 msaitoh uint32_t idx = TXP_OFFSET2IDX(le32toh(*(r->r_off)));
876 1.53 msaitoh uint32_t cons = r->r_cons, cnt = r->r_cnt;
877 1.1 drochner struct txp_tx_desc *txd = r->r_desc + cons;
878 1.1 drochner struct txp_swdesc *sd = sc->sc_txd + cons;
879 1.1 drochner struct mbuf *m;
880 1.1 drochner
881 1.1 drochner while (cons != idx) {
882 1.1 drochner if (cnt == 0)
883 1.1 drochner break;
884 1.1 drochner
885 1.1 drochner bus_dmamap_sync(sc->sc_dmat, dma->dma_map,
886 1.1 drochner cons * sizeof(struct txp_tx_desc),
887 1.1 drochner sizeof(struct txp_tx_desc),
888 1.1 drochner BUS_DMASYNC_POSTWRITE);
889 1.1 drochner
890 1.1 drochner if ((txd->tx_flags & TX_FLAGS_TYPE_M) ==
891 1.1 drochner TX_FLAGS_TYPE_DATA) {
892 1.1 drochner bus_dmamap_sync(sc->sc_dmat, sd->sd_map, 0,
893 1.1 drochner sd->sd_map->dm_mapsize, BUS_DMASYNC_POSTWRITE);
894 1.1 drochner bus_dmamap_unload(sc->sc_dmat, sd->sd_map);
895 1.1 drochner m = sd->sd_mbuf;
896 1.1 drochner if (m != NULL) {
897 1.1 drochner m_freem(m);
898 1.1 drochner txd->tx_addrlo = 0;
899 1.1 drochner txd->tx_addrhi = 0;
900 1.63 thorpej if_statinc(ifp, if_opackets);
901 1.1 drochner }
902 1.1 drochner }
903 1.1 drochner ifp->if_flags &= ~IFF_OACTIVE;
904 1.1 drochner
905 1.1 drochner if (++cons == TX_ENTRIES) {
906 1.1 drochner txd = r->r_desc;
907 1.1 drochner cons = 0;
908 1.1 drochner sd = sc->sc_txd;
909 1.1 drochner } else {
910 1.1 drochner txd++;
911 1.1 drochner sd++;
912 1.1 drochner }
913 1.1 drochner
914 1.1 drochner cnt--;
915 1.1 drochner }
916 1.1 drochner
917 1.1 drochner r->r_cons = cons;
918 1.1 drochner r->r_cnt = cnt;
919 1.1 drochner if (cnt == 0)
920 1.1 drochner ifp->if_timer = 0;
921 1.1 drochner }
922 1.1 drochner
923 1.62 maxv static bool
924 1.35 tsutsui txp_shutdown(device_t self, int howto)
925 1.1 drochner {
926 1.35 tsutsui struct txp_softc *sc;
927 1.35 tsutsui
928 1.35 tsutsui sc = device_private(self);
929 1.1 drochner
930 1.1 drochner /* mask all interrupts */
931 1.1 drochner WRITE_REG(sc, TXP_IMR,
932 1.1 drochner TXP_INT_SELF | TXP_INT_PCI_TABORT | TXP_INT_PCI_MABORT |
933 1.1 drochner TXP_INT_DMA3 | TXP_INT_DMA2 | TXP_INT_DMA1 | TXP_INT_DMA0 |
934 1.1 drochner TXP_INT_LATCH);
935 1.1 drochner
936 1.1 drochner txp_command(sc, TXP_CMD_TX_DISABLE, 0, 0, 0, NULL, NULL, NULL, 0);
937 1.1 drochner txp_command(sc, TXP_CMD_RX_DISABLE, 0, 0, 0, NULL, NULL, NULL, 0);
938 1.1 drochner txp_command(sc, TXP_CMD_HALT, 0, 0, 0, NULL, NULL, NULL, 0);
939 1.35 tsutsui
940 1.35 tsutsui return true;
941 1.1 drochner }
942 1.1 drochner
943 1.62 maxv static int
944 1.29 dsl txp_alloc_rings(struct txp_softc *sc)
945 1.1 drochner {
946 1.1 drochner struct ifnet *ifp = &sc->sc_arpcom.ec_if;
947 1.1 drochner struct txp_boot_record *boot;
948 1.1 drochner struct txp_swdesc *sd;
949 1.53 msaitoh uint32_t r;
950 1.15 christos int i, j, nb;
951 1.1 drochner
952 1.1 drochner /* boot record */
953 1.44 msaitoh if (txp_dma_malloc(sc, sizeof(struct txp_boot_record),
954 1.44 msaitoh &sc->sc_boot_dma, BUS_DMA_COHERENT)) {
955 1.1 drochner printf(": can't allocate boot record\n");
956 1.1 drochner return (-1);
957 1.1 drochner }
958 1.1 drochner boot = (struct txp_boot_record *)sc->sc_boot_dma.dma_vaddr;
959 1.32 cegger memset(boot, 0, sizeof(*boot));
960 1.1 drochner sc->sc_boot = boot;
961 1.1 drochner
962 1.1 drochner /* host variables */
963 1.1 drochner if (txp_dma_malloc(sc, sizeof(struct txp_hostvar), &sc->sc_host_dma,
964 1.1 drochner BUS_DMA_COHERENT)) {
965 1.1 drochner printf(": can't allocate host ring\n");
966 1.1 drochner goto bail_boot;
967 1.1 drochner }
968 1.32 cegger memset(sc->sc_host_dma.dma_vaddr, 0, sizeof(struct txp_hostvar));
969 1.65 thorpej boot->br_hostvar_lo = htole32(BUS_ADDR_LO32(sc->sc_host_dma.dma_paddr));
970 1.65 thorpej boot->br_hostvar_hi = htole32(BUS_ADDR_HI32(sc->sc_host_dma.dma_paddr));
971 1.1 drochner sc->sc_hostvar = (struct txp_hostvar *)sc->sc_host_dma.dma_vaddr;
972 1.1 drochner
973 1.1 drochner /* high priority tx ring */
974 1.1 drochner if (txp_dma_malloc(sc, sizeof(struct txp_tx_desc) * TX_ENTRIES,
975 1.1 drochner &sc->sc_txhiring_dma, BUS_DMA_COHERENT)) {
976 1.1 drochner printf(": can't allocate high tx ring\n");
977 1.1 drochner goto bail_host;
978 1.1 drochner }
979 1.44 msaitoh memset(sc->sc_txhiring_dma.dma_vaddr, 0,
980 1.44 msaitoh sizeof(struct txp_tx_desc) * TX_ENTRIES);
981 1.65 thorpej boot->br_txhipri_lo =
982 1.65 thorpej htole32(BUS_ADDR_LO32(sc->sc_txhiring_dma.dma_paddr));
983 1.65 thorpej boot->br_txhipri_hi =
984 1.65 thorpej htole32(BUS_ADDR_HI32(sc->sc_txhiring_dma.dma_paddr));
985 1.1 drochner boot->br_txhipri_siz = htole32(TX_ENTRIES * sizeof(struct txp_tx_desc));
986 1.1 drochner sc->sc_txhir.r_reg = TXP_H2A_1;
987 1.65 thorpej sc->sc_txhir.r_desc =
988 1.65 thorpej (struct txp_tx_desc *)sc->sc_txhiring_dma.dma_vaddr;
989 1.1 drochner sc->sc_txhir.r_cons = sc->sc_txhir.r_prod = sc->sc_txhir.r_cnt = 0;
990 1.1 drochner sc->sc_txhir.r_off = &sc->sc_hostvar->hv_tx_hi_desc_read_idx;
991 1.1 drochner for (i = 0; i < TX_ENTRIES; i++) {
992 1.1 drochner if (bus_dmamap_create(sc->sc_dmat, TXP_MAX_PKTLEN,
993 1.68 thorpej TXP_MAXTXSEGS, TXP_MAX_SEGLEN, 0, BUS_DMA_NOWAIT,
994 1.68 thorpej &sc->sc_txd[i].sd_map) != 0) {
995 1.1 drochner for (j = 0; j < i; j++) {
996 1.1 drochner bus_dmamap_destroy(sc->sc_dmat,
997 1.1 drochner sc->sc_txd[j].sd_map);
998 1.1 drochner sc->sc_txd[j].sd_map = NULL;
999 1.1 drochner }
1000 1.1 drochner goto bail_txhiring;
1001 1.1 drochner }
1002 1.1 drochner }
1003 1.1 drochner
1004 1.1 drochner /* low priority tx ring */
1005 1.1 drochner if (txp_dma_malloc(sc, sizeof(struct txp_tx_desc) * TX_ENTRIES,
1006 1.1 drochner &sc->sc_txloring_dma, BUS_DMA_COHERENT)) {
1007 1.1 drochner printf(": can't allocate low tx ring\n");
1008 1.1 drochner goto bail_txhiring;
1009 1.1 drochner }
1010 1.44 msaitoh memset(sc->sc_txloring_dma.dma_vaddr, 0,
1011 1.44 msaitoh sizeof(struct txp_tx_desc) * TX_ENTRIES);
1012 1.65 thorpej boot->br_txlopri_lo =
1013 1.65 thorpej htole32(BUS_ADDR_LO32(sc->sc_txloring_dma.dma_paddr));
1014 1.65 thorpej boot->br_txlopri_hi =
1015 1.65 thorpej htole32(BUS_ADDR_HI32(sc->sc_txloring_dma.dma_paddr));
1016 1.1 drochner boot->br_txlopri_siz = htole32(TX_ENTRIES * sizeof(struct txp_tx_desc));
1017 1.1 drochner sc->sc_txlor.r_reg = TXP_H2A_3;
1018 1.65 thorpej sc->sc_txlor.r_desc =
1019 1.65 thorpej (struct txp_tx_desc *)sc->sc_txloring_dma.dma_vaddr;
1020 1.1 drochner sc->sc_txlor.r_cons = sc->sc_txlor.r_prod = sc->sc_txlor.r_cnt = 0;
1021 1.1 drochner sc->sc_txlor.r_off = &sc->sc_hostvar->hv_tx_lo_desc_read_idx;
1022 1.1 drochner
1023 1.1 drochner /* high priority rx ring */
1024 1.1 drochner if (txp_dma_malloc(sc, sizeof(struct txp_rx_desc) * RX_ENTRIES,
1025 1.1 drochner &sc->sc_rxhiring_dma, BUS_DMA_COHERENT)) {
1026 1.1 drochner printf(": can't allocate high rx ring\n");
1027 1.1 drochner goto bail_txloring;
1028 1.1 drochner }
1029 1.44 msaitoh memset(sc->sc_rxhiring_dma.dma_vaddr, 0,
1030 1.44 msaitoh sizeof(struct txp_rx_desc) * RX_ENTRIES);
1031 1.65 thorpej boot->br_rxhipri_lo =
1032 1.65 thorpej htole32(BUS_ADDR_LO32(sc->sc_rxhiring_dma.dma_paddr));
1033 1.65 thorpej boot->br_rxhipri_hi =
1034 1.65 thorpej htole32(BUS_ADDR_HI32(sc->sc_rxhiring_dma.dma_paddr));
1035 1.1 drochner boot->br_rxhipri_siz = htole32(RX_ENTRIES * sizeof(struct txp_rx_desc));
1036 1.1 drochner sc->sc_rxhir.r_desc =
1037 1.1 drochner (struct txp_rx_desc *)sc->sc_rxhiring_dma.dma_vaddr;
1038 1.1 drochner sc->sc_rxhir.r_roff = &sc->sc_hostvar->hv_rx_hi_read_idx;
1039 1.1 drochner sc->sc_rxhir.r_woff = &sc->sc_hostvar->hv_rx_hi_write_idx;
1040 1.1 drochner bus_dmamap_sync(sc->sc_dmat, sc->sc_rxhiring_dma.dma_map,
1041 1.1 drochner 0, sc->sc_rxhiring_dma.dma_map->dm_mapsize, BUS_DMASYNC_PREREAD);
1042 1.1 drochner
1043 1.1 drochner /* low priority ring */
1044 1.1 drochner if (txp_dma_malloc(sc, sizeof(struct txp_rx_desc) * RX_ENTRIES,
1045 1.1 drochner &sc->sc_rxloring_dma, BUS_DMA_COHERENT)) {
1046 1.1 drochner printf(": can't allocate low rx ring\n");
1047 1.1 drochner goto bail_rxhiring;
1048 1.1 drochner }
1049 1.44 msaitoh memset(sc->sc_rxloring_dma.dma_vaddr, 0,
1050 1.44 msaitoh sizeof(struct txp_rx_desc) * RX_ENTRIES);
1051 1.65 thorpej boot->br_rxlopri_lo =
1052 1.65 thorpej htole32(BUS_ADDR_LO32(sc->sc_rxloring_dma.dma_paddr));
1053 1.65 thorpej boot->br_rxlopri_hi =
1054 1.65 thorpej htole32(BUS_ADDR_HI32(sc->sc_rxloring_dma.dma_paddr));
1055 1.1 drochner boot->br_rxlopri_siz = htole32(RX_ENTRIES * sizeof(struct txp_rx_desc));
1056 1.1 drochner sc->sc_rxlor.r_desc =
1057 1.1 drochner (struct txp_rx_desc *)sc->sc_rxloring_dma.dma_vaddr;
1058 1.1 drochner sc->sc_rxlor.r_roff = &sc->sc_hostvar->hv_rx_lo_read_idx;
1059 1.1 drochner sc->sc_rxlor.r_woff = &sc->sc_hostvar->hv_rx_lo_write_idx;
1060 1.1 drochner bus_dmamap_sync(sc->sc_dmat, sc->sc_rxloring_dma.dma_map,
1061 1.1 drochner 0, sc->sc_rxloring_dma.dma_map->dm_mapsize, BUS_DMASYNC_PREREAD);
1062 1.1 drochner
1063 1.1 drochner /* command ring */
1064 1.1 drochner if (txp_dma_malloc(sc, sizeof(struct txp_cmd_desc) * CMD_ENTRIES,
1065 1.1 drochner &sc->sc_cmdring_dma, BUS_DMA_COHERENT)) {
1066 1.1 drochner printf(": can't allocate command ring\n");
1067 1.1 drochner goto bail_rxloring;
1068 1.1 drochner }
1069 1.44 msaitoh memset(sc->sc_cmdring_dma.dma_vaddr, 0,
1070 1.44 msaitoh sizeof(struct txp_cmd_desc) * CMD_ENTRIES);
1071 1.65 thorpej boot->br_cmd_lo = htole32(BUS_ADDR_LO32(sc->sc_cmdring_dma.dma_paddr));
1072 1.65 thorpej boot->br_cmd_hi = htole32(BUS_ADDR_HI32(sc->sc_cmdring_dma.dma_paddr));
1073 1.1 drochner boot->br_cmd_siz = htole32(CMD_ENTRIES * sizeof(struct txp_cmd_desc));
1074 1.1 drochner sc->sc_cmdring.base = (struct txp_cmd_desc *)sc->sc_cmdring_dma.dma_vaddr;
1075 1.1 drochner sc->sc_cmdring.size = CMD_ENTRIES * sizeof(struct txp_cmd_desc);
1076 1.1 drochner sc->sc_cmdring.lastwrite = 0;
1077 1.1 drochner
1078 1.1 drochner /* response ring */
1079 1.1 drochner if (txp_dma_malloc(sc, sizeof(struct txp_rsp_desc) * RSP_ENTRIES,
1080 1.1 drochner &sc->sc_rspring_dma, BUS_DMA_COHERENT)) {
1081 1.1 drochner printf(": can't allocate response ring\n");
1082 1.1 drochner goto bail_cmdring;
1083 1.1 drochner }
1084 1.44 msaitoh memset(sc->sc_rspring_dma.dma_vaddr, 0,
1085 1.44 msaitoh sizeof(struct txp_rsp_desc) * RSP_ENTRIES);
1086 1.65 thorpej boot->br_resp_lo = htole32(BUS_ADDR_LO32(sc->sc_rspring_dma.dma_paddr));
1087 1.65 thorpej boot->br_resp_hi = htole32(BUS_ADDR_HI32(sc->sc_rspring_dma.dma_paddr));
1088 1.1 drochner boot->br_resp_siz = htole32(CMD_ENTRIES * sizeof(struct txp_rsp_desc));
1089 1.1 drochner sc->sc_rspring.base = (struct txp_rsp_desc *)sc->sc_rspring_dma.dma_vaddr;
1090 1.1 drochner sc->sc_rspring.size = RSP_ENTRIES * sizeof(struct txp_rsp_desc);
1091 1.1 drochner sc->sc_rspring.lastwrite = 0;
1092 1.1 drochner
1093 1.1 drochner /* receive buffer ring */
1094 1.1 drochner if (txp_dma_malloc(sc, sizeof(struct txp_rxbuf_desc) * RXBUF_ENTRIES,
1095 1.1 drochner &sc->sc_rxbufring_dma, BUS_DMA_COHERENT)) {
1096 1.1 drochner printf(": can't allocate rx buffer ring\n");
1097 1.1 drochner goto bail_rspring;
1098 1.1 drochner }
1099 1.44 msaitoh memset(sc->sc_rxbufring_dma.dma_vaddr, 0,
1100 1.44 msaitoh sizeof(struct txp_rxbuf_desc) * RXBUF_ENTRIES);
1101 1.65 thorpej boot->br_rxbuf_lo = htole32(BUS_ADDR_LO32(sc->sc_rxbufring_dma.dma_paddr));
1102 1.65 thorpej boot->br_rxbuf_hi = htole32(BUS_ADDR_HI32(sc->sc_rxbufring_dma.dma_paddr));
1103 1.1 drochner boot->br_rxbuf_siz = htole32(RXBUF_ENTRIES * sizeof(struct txp_rxbuf_desc));
1104 1.1 drochner sc->sc_rxbufs = (struct txp_rxbuf_desc *)sc->sc_rxbufring_dma.dma_vaddr;
1105 1.15 christos for (nb = 0; nb < RXBUF_ENTRIES; nb++) {
1106 1.69 thorpej sd = &sc->sc_rxd[nb];
1107 1.15 christos /* stash away pointer */
1108 1.44 msaitoh memcpy(__UNVOLATILE(&sc->sc_rxbufs[nb].rb_vaddrlo), &sd,
1109 1.44 msaitoh sizeof(sd));
1110 1.1 drochner
1111 1.69 thorpej MGETHDR(sd->sd_mbuf, M_WAIT, MT_DATA);
1112 1.1 drochner if (sd->sd_mbuf == NULL) {
1113 1.1 drochner goto bail_rxbufring;
1114 1.1 drochner }
1115 1.1 drochner
1116 1.69 thorpej MCLGET(sd->sd_mbuf, M_WAIT);
1117 1.1 drochner if ((sd->sd_mbuf->m_flags & M_EXT) == 0) {
1118 1.1 drochner goto bail_rxbufring;
1119 1.1 drochner }
1120 1.1 drochner sd->sd_mbuf->m_pkthdr.len = sd->sd_mbuf->m_len = MCLBYTES;
1121 1.43 ozaki m_set_rcvif(sd->sd_mbuf, ifp);
1122 1.1 drochner if (bus_dmamap_create(sc->sc_dmat, TXP_MAX_PKTLEN, 1,
1123 1.69 thorpej TXP_MAX_PKTLEN, 0, BUS_DMA_WAITOK, &sd->sd_map)) {
1124 1.1 drochner goto bail_rxbufring;
1125 1.1 drochner }
1126 1.1 drochner if (bus_dmamap_load_mbuf(sc->sc_dmat, sd->sd_map, sd->sd_mbuf,
1127 1.69 thorpej BUS_DMA_WAITOK)) {
1128 1.1 drochner bus_dmamap_destroy(sc->sc_dmat, sd->sd_map);
1129 1.1 drochner goto bail_rxbufring;
1130 1.1 drochner }
1131 1.1 drochner bus_dmamap_sync(sc->sc_dmat, sd->sd_map, 0,
1132 1.1 drochner sd->sd_map->dm_mapsize, BUS_DMASYNC_PREREAD);
1133 1.1 drochner
1134 1.15 christos sc->sc_rxbufs[nb].rb_paddrlo =
1135 1.65 thorpej htole32(BUS_ADDR_LO32(sd->sd_map->dm_segs[0].ds_addr));
1136 1.15 christos sc->sc_rxbufs[nb].rb_paddrhi =
1137 1.65 thorpej htole32(BUS_ADDR_HI32(sd->sd_map->dm_segs[0].ds_addr));
1138 1.1 drochner }
1139 1.1 drochner bus_dmamap_sync(sc->sc_dmat, sc->sc_rxbufring_dma.dma_map,
1140 1.1 drochner 0, sc->sc_rxbufring_dma.dma_map->dm_mapsize,
1141 1.1 drochner BUS_DMASYNC_PREWRITE);
1142 1.1 drochner sc->sc_hostvar->hv_rx_buf_write_idx = htole32((RXBUF_ENTRIES - 1) *
1143 1.1 drochner sizeof(struct txp_rxbuf_desc));
1144 1.1 drochner
1145 1.1 drochner /* zero dma */
1146 1.53 msaitoh if (txp_dma_malloc(sc, sizeof(uint32_t), &sc->sc_zero_dma,
1147 1.1 drochner BUS_DMA_COHERENT)) {
1148 1.1 drochner printf(": can't allocate response ring\n");
1149 1.1 drochner goto bail_rxbufring;
1150 1.1 drochner }
1151 1.53 msaitoh memset(sc->sc_zero_dma.dma_vaddr, 0, sizeof(uint32_t));
1152 1.65 thorpej boot->br_zero_lo = htole32(BUS_ADDR_LO32(sc->sc_zero_dma.dma_paddr));
1153 1.65 thorpej boot->br_zero_hi = htole32(BUS_ADDR_HI32(sc->sc_zero_dma.dma_paddr));
1154 1.1 drochner
1155 1.1 drochner /* See if it's waiting for boot, and try to boot it */
1156 1.1 drochner for (i = 0; i < 10000; i++) {
1157 1.1 drochner r = READ_REG(sc, TXP_A2H_0);
1158 1.1 drochner if (r == STAT_WAITING_FOR_BOOT)
1159 1.1 drochner break;
1160 1.1 drochner DELAY(50);
1161 1.1 drochner }
1162 1.1 drochner if (r != STAT_WAITING_FOR_BOOT) {
1163 1.1 drochner printf(": not waiting for boot\n");
1164 1.1 drochner goto bail;
1165 1.1 drochner }
1166 1.65 thorpej WRITE_REG(sc, TXP_H2A_2, BUS_ADDR_HI32(sc->sc_boot_dma.dma_paddr));
1167 1.65 thorpej WRITE_REG(sc, TXP_H2A_1, BUS_ADDR_LO32(sc->sc_boot_dma.dma_paddr));
1168 1.1 drochner WRITE_REG(sc, TXP_H2A_0, TXP_BOOTCMD_REGISTER_BOOT_RECORD);
1169 1.1 drochner
1170 1.1 drochner /* See if it booted */
1171 1.1 drochner for (i = 0; i < 10000; i++) {
1172 1.1 drochner r = READ_REG(sc, TXP_A2H_0);
1173 1.1 drochner if (r == STAT_RUNNING)
1174 1.1 drochner break;
1175 1.1 drochner DELAY(50);
1176 1.1 drochner }
1177 1.1 drochner if (r != STAT_RUNNING) {
1178 1.1 drochner printf(": fw not running\n");
1179 1.1 drochner goto bail;
1180 1.1 drochner }
1181 1.1 drochner
1182 1.1 drochner /* Clear TX and CMD ring write registers */
1183 1.1 drochner WRITE_REG(sc, TXP_H2A_1, TXP_BOOTCMD_NULL);
1184 1.1 drochner WRITE_REG(sc, TXP_H2A_2, TXP_BOOTCMD_NULL);
1185 1.1 drochner WRITE_REG(sc, TXP_H2A_3, TXP_BOOTCMD_NULL);
1186 1.1 drochner WRITE_REG(sc, TXP_H2A_0, TXP_BOOTCMD_NULL);
1187 1.1 drochner
1188 1.1 drochner return (0);
1189 1.1 drochner
1190 1.1 drochner bail:
1191 1.1 drochner txp_dma_free(sc, &sc->sc_zero_dma);
1192 1.1 drochner bail_rxbufring:
1193 1.15 christos if (nb == RXBUF_ENTRIES)
1194 1.15 christos nb--;
1195 1.15 christos for (i = 0; i <= nb; i++) {
1196 1.34 tsutsui memcpy(&sd, __UNVOLATILE(&sc->sc_rxbufs[i].rb_vaddrlo),
1197 1.15 christos sizeof(sd));
1198 1.69 thorpej /* XXXJRT */
1199 1.15 christos }
1200 1.1 drochner txp_dma_free(sc, &sc->sc_rxbufring_dma);
1201 1.1 drochner bail_rspring:
1202 1.1 drochner txp_dma_free(sc, &sc->sc_rspring_dma);
1203 1.1 drochner bail_cmdring:
1204 1.1 drochner txp_dma_free(sc, &sc->sc_cmdring_dma);
1205 1.1 drochner bail_rxloring:
1206 1.1 drochner txp_dma_free(sc, &sc->sc_rxloring_dma);
1207 1.1 drochner bail_rxhiring:
1208 1.1 drochner txp_dma_free(sc, &sc->sc_rxhiring_dma);
1209 1.1 drochner bail_txloring:
1210 1.1 drochner txp_dma_free(sc, &sc->sc_txloring_dma);
1211 1.1 drochner bail_txhiring:
1212 1.1 drochner txp_dma_free(sc, &sc->sc_txhiring_dma);
1213 1.1 drochner bail_host:
1214 1.1 drochner txp_dma_free(sc, &sc->sc_host_dma);
1215 1.1 drochner bail_boot:
1216 1.1 drochner txp_dma_free(sc, &sc->sc_boot_dma);
1217 1.1 drochner return (-1);
1218 1.1 drochner }
1219 1.1 drochner
1220 1.62 maxv static int
1221 1.44 msaitoh txp_dma_malloc(struct txp_softc *sc, bus_size_t size,
1222 1.44 msaitoh struct txp_dma_alloc *dma, int mapflags)
1223 1.1 drochner {
1224 1.1 drochner int r;
1225 1.1 drochner
1226 1.1 drochner if ((r = bus_dmamem_alloc(sc->sc_dmat, size, PAGE_SIZE, 0,
1227 1.1 drochner &dma->dma_seg, 1, &dma->dma_nseg, 0)) != 0)
1228 1.1 drochner goto fail_0;
1229 1.1 drochner
1230 1.1 drochner if ((r = bus_dmamem_map(sc->sc_dmat, &dma->dma_seg, dma->dma_nseg,
1231 1.1 drochner size, &dma->dma_vaddr, mapflags | BUS_DMA_NOWAIT)) != 0)
1232 1.1 drochner goto fail_1;
1233 1.1 drochner
1234 1.1 drochner if ((r = bus_dmamap_create(sc->sc_dmat, size, 1, size, 0,
1235 1.1 drochner BUS_DMA_NOWAIT, &dma->dma_map)) != 0)
1236 1.1 drochner goto fail_2;
1237 1.1 drochner
1238 1.1 drochner if ((r = bus_dmamap_load(sc->sc_dmat, dma->dma_map, dma->dma_vaddr,
1239 1.1 drochner size, NULL, BUS_DMA_NOWAIT)) != 0)
1240 1.1 drochner goto fail_3;
1241 1.1 drochner
1242 1.1 drochner dma->dma_paddr = dma->dma_map->dm_segs[0].ds_addr;
1243 1.1 drochner return (0);
1244 1.1 drochner
1245 1.1 drochner fail_3:
1246 1.1 drochner bus_dmamap_destroy(sc->sc_dmat, dma->dma_map);
1247 1.1 drochner fail_2:
1248 1.1 drochner bus_dmamem_unmap(sc->sc_dmat, dma->dma_vaddr, size);
1249 1.1 drochner fail_1:
1250 1.1 drochner bus_dmamem_free(sc->sc_dmat, &dma->dma_seg, dma->dma_nseg);
1251 1.1 drochner fail_0:
1252 1.1 drochner return (r);
1253 1.1 drochner }
1254 1.1 drochner
1255 1.62 maxv static void
1256 1.29 dsl txp_dma_free(struct txp_softc *sc, struct txp_dma_alloc *dma)
1257 1.1 drochner {
1258 1.54 msaitoh bus_size_t mapsize = dma->dma_map->dm_mapsize;
1259 1.54 msaitoh
1260 1.1 drochner bus_dmamap_unload(sc->sc_dmat, dma->dma_map);
1261 1.54 msaitoh bus_dmamem_unmap(sc->sc_dmat, dma->dma_vaddr, mapsize);
1262 1.1 drochner bus_dmamem_free(sc->sc_dmat, &dma->dma_seg, dma->dma_nseg);
1263 1.1 drochner bus_dmamap_destroy(sc->sc_dmat, dma->dma_map);
1264 1.1 drochner }
1265 1.1 drochner
1266 1.62 maxv static int
1267 1.27 dyoung txp_ioctl(struct ifnet *ifp, u_long command, void *data)
1268 1.1 drochner {
1269 1.1 drochner struct txp_softc *sc = ifp->if_softc;
1270 1.1 drochner struct ifaddr *ifa = (struct ifaddr *)data;
1271 1.1 drochner int s, error = 0;
1272 1.1 drochner
1273 1.1 drochner s = splnet();
1274 1.1 drochner
1275 1.1 drochner #if 0
1276 1.1 drochner if ((error = ether_ioctl(ifp, &sc->sc_arpcom, command, data)) > 0) {
1277 1.1 drochner splx(s);
1278 1.1 drochner return error;
1279 1.1 drochner }
1280 1.1 drochner #endif
1281 1.1 drochner
1282 1.55 msaitoh switch (command) {
1283 1.27 dyoung case SIOCINITIFADDR:
1284 1.1 drochner ifp->if_flags |= IFF_UP;
1285 1.27 dyoung txp_init(sc);
1286 1.1 drochner switch (ifa->ifa_addr->sa_family) {
1287 1.1 drochner #ifdef INET
1288 1.1 drochner case AF_INET:
1289 1.1 drochner arp_ifinit(ifp, ifa);
1290 1.1 drochner break;
1291 1.1 drochner #endif /* INET */
1292 1.1 drochner default:
1293 1.1 drochner break;
1294 1.1 drochner }
1295 1.1 drochner break;
1296 1.1 drochner case SIOCSIFFLAGS:
1297 1.27 dyoung if ((error = ifioctl_common(ifp, command, data)) != 0)
1298 1.27 dyoung break;
1299 1.1 drochner if (ifp->if_flags & IFF_UP) {
1300 1.1 drochner txp_init(sc);
1301 1.1 drochner } else {
1302 1.1 drochner if (ifp->if_flags & IFF_RUNNING)
1303 1.1 drochner txp_stop(sc);
1304 1.1 drochner }
1305 1.1 drochner break;
1306 1.1 drochner case SIOCADDMULTI:
1307 1.1 drochner case SIOCDELMULTI:
1308 1.23 dyoung if ((error = ether_ioctl(ifp, command, data)) != ENETRESET)
1309 1.23 dyoung break;
1310 1.23 dyoung
1311 1.23 dyoung error = 0;
1312 1.23 dyoung
1313 1.23 dyoung if (command != SIOCADDMULTI && command != SIOCDELMULTI)
1314 1.23 dyoung ;
1315 1.23 dyoung else if (ifp->if_flags & IFF_RUNNING) {
1316 1.1 drochner /*
1317 1.1 drochner * Multicast list has changed; set the hardware
1318 1.1 drochner * filter accordingly.
1319 1.1 drochner */
1320 1.23 dyoung txp_set_filter(sc);
1321 1.1 drochner }
1322 1.1 drochner break;
1323 1.1 drochner default:
1324 1.27 dyoung error = ether_ioctl(ifp, command, data);
1325 1.1 drochner break;
1326 1.1 drochner }
1327 1.1 drochner
1328 1.1 drochner splx(s);
1329 1.1 drochner
1330 1.55 msaitoh return (error);
1331 1.1 drochner }
1332 1.1 drochner
1333 1.62 maxv static void
1334 1.29 dsl txp_init(struct txp_softc *sc)
1335 1.1 drochner {
1336 1.1 drochner struct ifnet *ifp = &sc->sc_arpcom.ec_if;
1337 1.1 drochner int s;
1338 1.1 drochner
1339 1.1 drochner txp_stop(sc);
1340 1.1 drochner
1341 1.1 drochner s = splnet();
1342 1.1 drochner
1343 1.1 drochner txp_set_filter(sc);
1344 1.1 drochner
1345 1.1 drochner txp_command(sc, TXP_CMD_TX_ENABLE, 0, 0, 0, NULL, NULL, NULL, 1);
1346 1.1 drochner txp_command(sc, TXP_CMD_RX_ENABLE, 0, 0, 0, NULL, NULL, NULL, 1);
1347 1.1 drochner
1348 1.1 drochner WRITE_REG(sc, TXP_IER, TXP_INT_RESERVED | TXP_INT_SELF |
1349 1.1 drochner TXP_INT_A2H_7 | TXP_INT_A2H_6 | TXP_INT_A2H_5 | TXP_INT_A2H_4 |
1350 1.1 drochner TXP_INT_A2H_2 | TXP_INT_A2H_1 | TXP_INT_A2H_0 |
1351 1.1 drochner TXP_INT_DMA3 | TXP_INT_DMA2 | TXP_INT_DMA1 | TXP_INT_DMA0 |
1352 1.1 drochner TXP_INT_PCI_TABORT | TXP_INT_PCI_MABORT | TXP_INT_LATCH);
1353 1.1 drochner WRITE_REG(sc, TXP_IMR, TXP_INT_A2H_3);
1354 1.1 drochner
1355 1.1 drochner ifp->if_flags |= IFF_RUNNING;
1356 1.1 drochner ifp->if_flags &= ~IFF_OACTIVE;
1357 1.1 drochner ifp->if_timer = 0;
1358 1.1 drochner
1359 1.1 drochner if (!callout_pending(&sc->sc_tick))
1360 1.1 drochner callout_schedule(&sc->sc_tick, hz);
1361 1.1 drochner
1362 1.1 drochner splx(s);
1363 1.1 drochner }
1364 1.1 drochner
1365 1.62 maxv static void
1366 1.29 dsl txp_tick(void *vsc)
1367 1.1 drochner {
1368 1.1 drochner struct txp_softc *sc = vsc;
1369 1.1 drochner struct ifnet *ifp = &sc->sc_arpcom.ec_if;
1370 1.1 drochner struct txp_rsp_desc *rsp = NULL;
1371 1.1 drochner struct txp_ext_desc *ext;
1372 1.1 drochner int s;
1373 1.1 drochner
1374 1.1 drochner s = splnet();
1375 1.1 drochner txp_rxbuf_reclaim(sc);
1376 1.1 drochner
1377 1.1 drochner if (txp_command2(sc, TXP_CMD_READ_STATISTICS, 0, 0, 0, NULL, 0,
1378 1.1 drochner &rsp, 1))
1379 1.1 drochner goto out;
1380 1.1 drochner if (rsp->rsp_numdesc != 6)
1381 1.1 drochner goto out;
1382 1.1 drochner if (txp_command(sc, TXP_CMD_CLEAR_STATISTICS, 0, 0, 0,
1383 1.1 drochner NULL, NULL, NULL, 1))
1384 1.1 drochner goto out;
1385 1.1 drochner ext = (struct txp_ext_desc *)(rsp + 1);
1386 1.1 drochner
1387 1.63 thorpej net_stat_ref_t nsr = IF_STAT_GETREF(ifp);
1388 1.63 thorpej if_statadd_ref(nsr, if_ierrors,
1389 1.63 thorpej ext[3].ext_2 + ext[3].ext_3 + ext[3].ext_4 +
1390 1.63 thorpej ext[4].ext_1 + ext[4].ext_4);
1391 1.63 thorpej if_statadd_ref(nsr, if_oerrors,
1392 1.63 thorpej ext[0].ext_1 + ext[1].ext_1 + ext[1].ext_4 + ext[2].ext_1);
1393 1.63 thorpej if_statadd_ref(nsr, if_collisions,
1394 1.63 thorpej ext[0].ext_2 + ext[0].ext_3 + ext[1].ext_2 + ext[1].ext_3);
1395 1.63 thorpej if_statadd_ref(nsr, if_opackets, rsp->rsp_par2);
1396 1.63 thorpej IF_STAT_PUTREF(ifp);
1397 1.1 drochner
1398 1.1 drochner out:
1399 1.1 drochner if (rsp != NULL)
1400 1.1 drochner free(rsp, M_DEVBUF);
1401 1.1 drochner
1402 1.1 drochner splx(s);
1403 1.1 drochner callout_schedule(&sc->sc_tick, hz);
1404 1.1 drochner }
1405 1.1 drochner
1406 1.62 maxv static void
1407 1.29 dsl txp_start(struct ifnet *ifp)
1408 1.1 drochner {
1409 1.1 drochner struct txp_softc *sc = ifp->if_softc;
1410 1.1 drochner struct txp_tx_ring *r = &sc->sc_txhir;
1411 1.1 drochner struct txp_tx_desc *txd;
1412 1.1 drochner int txdidx;
1413 1.1 drochner struct txp_frag_desc *fxd;
1414 1.1 drochner struct mbuf *m, *mnew;
1415 1.1 drochner struct txp_swdesc *sd;
1416 1.68 thorpej uint32_t prod, cnt, i;
1417 1.68 thorpej int error;
1418 1.1 drochner
1419 1.1 drochner if ((ifp->if_flags & (IFF_RUNNING | IFF_OACTIVE)) != IFF_RUNNING)
1420 1.1 drochner return;
1421 1.1 drochner
1422 1.1 drochner prod = r->r_prod;
1423 1.1 drochner cnt = r->r_cnt;
1424 1.1 drochner
1425 1.1 drochner while (1) {
1426 1.68 thorpej if (cnt >= TX_ENTRIES - TXP_MAXTXSEGS - 4) {
1427 1.68 thorpej ifp->if_flags |= IFF_OACTIVE;
1428 1.68 thorpej break;
1429 1.68 thorpej }
1430 1.68 thorpej
1431 1.1 drochner IFQ_POLL(&ifp->if_snd, m);
1432 1.1 drochner if (m == NULL)
1433 1.1 drochner break;
1434 1.1 drochner mnew = NULL;
1435 1.1 drochner
1436 1.1 drochner sd = sc->sc_txd + prod;
1437 1.1 drochner
1438 1.68 thorpej /*
1439 1.68 thorpej * Load the DMA map. If this fails, the packet either
1440 1.68 thorpej * didn't fit in the alloted number of segments, or we
1441 1.68 thorpej * were short on resources. In this case, we'll copy
1442 1.68 thorpej * and try again.
1443 1.68 thorpej */
1444 1.1 drochner if (bus_dmamap_load_mbuf(sc->sc_dmat, sd->sd_map, m,
1445 1.68 thorpej BUS_DMA_NOWAIT) != 0) {
1446 1.1 drochner MGETHDR(mnew, M_DONTWAIT, MT_DATA);
1447 1.68 thorpej if (mnew == NULL) {
1448 1.68 thorpej printf("%s: unable to allocate Tx mbuf\n",
1449 1.68 thorpej device_xname(sc->sc_dev));
1450 1.68 thorpej break;
1451 1.68 thorpej }
1452 1.1 drochner if (m->m_pkthdr.len > MHLEN) {
1453 1.1 drochner MCLGET(mnew, M_DONTWAIT);
1454 1.1 drochner if ((mnew->m_flags & M_EXT) == 0) {
1455 1.68 thorpej printf("%s: unable to allocate Tx "
1456 1.68 thorpej "cluster\n",
1457 1.68 thorpej device_xname(sc->sc_dev));
1458 1.1 drochner m_freem(mnew);
1459 1.68 thorpej break;
1460 1.1 drochner }
1461 1.1 drochner }
1462 1.19 christos m_copydata(m, 0, m->m_pkthdr.len, mtod(mnew, void *));
1463 1.1 drochner mnew->m_pkthdr.len = mnew->m_len = m->m_pkthdr.len;
1464 1.68 thorpej error = bus_dmamap_load_mbuf(sc->sc_dmat, sd->sd_map,
1465 1.68 thorpej mnew, BUS_DMA_NOWAIT);
1466 1.68 thorpej if (error) {
1467 1.68 thorpej printf("%s: unable to load Tx buffer, "
1468 1.68 thorpej "error = %d\n", device_xname(sc->sc_dev),
1469 1.68 thorpej error);
1470 1.68 thorpej m_freem(mnew);
1471 1.68 thorpej break;
1472 1.68 thorpej }
1473 1.68 thorpej }
1474 1.68 thorpej
1475 1.68 thorpej IFQ_DEQUEUE(&ifp->if_snd, m);
1476 1.68 thorpej if (mnew != NULL) {
1477 1.1 drochner m_freem(m);
1478 1.1 drochner m = mnew;
1479 1.1 drochner }
1480 1.1 drochner
1481 1.68 thorpej /*
1482 1.68 thorpej * WE ARE NOW COMMITTED TO TRANSMITTING THE PACKET.
1483 1.68 thorpej */
1484 1.68 thorpej
1485 1.68 thorpej sd->sd_mbuf = m;
1486 1.1 drochner
1487 1.1 drochner txd = r->r_desc + prod;
1488 1.1 drochner txdidx = prod;
1489 1.1 drochner txd->tx_flags = TX_FLAGS_TYPE_DATA;
1490 1.1 drochner txd->tx_numdesc = 0;
1491 1.1 drochner txd->tx_addrlo = 0;
1492 1.1 drochner txd->tx_addrhi = 0;
1493 1.1 drochner txd->tx_totlen = m->m_pkthdr.len;
1494 1.1 drochner txd->tx_pflags = 0;
1495 1.1 drochner txd->tx_numdesc = sd->sd_map->dm_nsegs;
1496 1.1 drochner
1497 1.1 drochner if (++prod == TX_ENTRIES)
1498 1.1 drochner prod = 0;
1499 1.1 drochner
1500 1.48 knakahar if (vlan_has_tag(m))
1501 1.1 drochner txd->tx_pflags = TX_PFLAGS_VLAN |
1502 1.48 knakahar (htons(vlan_get_tag(m)) << TX_PFLAGS_VLANTAG_S);
1503 1.1 drochner
1504 1.2 drochner if (m->m_pkthdr.csum_flags & M_CSUM_IPv4)
1505 1.1 drochner txd->tx_pflags |= TX_PFLAGS_IPCKSUM;
1506 1.1 drochner #ifdef TRY_TX_TCP_CSUM
1507 1.2 drochner if (m->m_pkthdr.csum_flags & M_CSUM_TCPv4)
1508 1.1 drochner txd->tx_pflags |= TX_PFLAGS_TCPCKSUM;
1509 1.1 drochner #endif
1510 1.1 drochner #ifdef TRY_TX_UDP_CSUM
1511 1.2 drochner if (m->m_pkthdr.csum_flags & M_CSUM_UDPv4)
1512 1.1 drochner txd->tx_pflags |= TX_PFLAGS_UDPCKSUM;
1513 1.1 drochner #endif
1514 1.1 drochner
1515 1.1 drochner bus_dmamap_sync(sc->sc_dmat, sd->sd_map, 0,
1516 1.1 drochner sd->sd_map->dm_mapsize, BUS_DMASYNC_PREWRITE);
1517 1.1 drochner
1518 1.1 drochner fxd = (struct txp_frag_desc *)(r->r_desc + prod);
1519 1.1 drochner for (i = 0; i < sd->sd_map->dm_nsegs; i++) {
1520 1.1 drochner fxd->frag_flags = FRAG_FLAGS_TYPE_FRAG |
1521 1.1 drochner FRAG_FLAGS_VALID;
1522 1.1 drochner fxd->frag_rsvd1 = 0;
1523 1.65 thorpej fxd->frag_len = htole16(sd->sd_map->dm_segs[i].ds_len);
1524 1.1 drochner fxd->frag_addrlo =
1525 1.65 thorpej htole32(BUS_ADDR_LO32(sd->sd_map->dm_segs[i].ds_addr));
1526 1.1 drochner fxd->frag_addrhi =
1527 1.65 thorpej htole32(BUS_ADDR_HI32(sd->sd_map->dm_segs[i].ds_addr));
1528 1.1 drochner fxd->frag_rsvd2 = 0;
1529 1.1 drochner
1530 1.1 drochner bus_dmamap_sync(sc->sc_dmat,
1531 1.1 drochner sc->sc_txhiring_dma.dma_map,
1532 1.1 drochner prod * sizeof(struct txp_frag_desc),
1533 1.1 drochner sizeof(struct txp_frag_desc), BUS_DMASYNC_PREWRITE);
1534 1.1 drochner
1535 1.1 drochner if (++prod == TX_ENTRIES) {
1536 1.1 drochner fxd = (struct txp_frag_desc *)r->r_desc;
1537 1.1 drochner prod = 0;
1538 1.1 drochner } else
1539 1.1 drochner fxd++;
1540 1.1 drochner
1541 1.1 drochner }
1542 1.1 drochner
1543 1.1 drochner ifp->if_timer = 5;
1544 1.1 drochner
1545 1.49 msaitoh bpf_mtap(ifp, m, BPF_D_OUT);
1546 1.1 drochner
1547 1.1 drochner txd->tx_flags |= TX_FLAGS_VALID;
1548 1.1 drochner bus_dmamap_sync(sc->sc_dmat, sc->sc_txhiring_dma.dma_map,
1549 1.1 drochner txdidx * sizeof(struct txp_tx_desc),
1550 1.1 drochner sizeof(struct txp_tx_desc), BUS_DMASYNC_PREWRITE);
1551 1.1 drochner
1552 1.1 drochner #if 0
1553 1.1 drochner {
1554 1.1 drochner struct mbuf *mx;
1555 1.1 drochner int i;
1556 1.1 drochner
1557 1.1 drochner printf("txd: flags 0x%x ndesc %d totlen %d pflags 0x%x\n",
1558 1.1 drochner txd->tx_flags, txd->tx_numdesc, txd->tx_totlen,
1559 1.1 drochner txd->tx_pflags);
1560 1.1 drochner for (mx = m; mx != NULL; mx = mx->m_next) {
1561 1.1 drochner for (i = 0; i < mx->m_len; i++) {
1562 1.1 drochner printf(":%02x",
1563 1.53 msaitoh (uint8_t)m->m_data[i]);
1564 1.1 drochner }
1565 1.1 drochner }
1566 1.1 drochner printf("\n");
1567 1.1 drochner }
1568 1.1 drochner #endif
1569 1.1 drochner
1570 1.1 drochner WRITE_REG(sc, r->r_reg, TXP_IDX2OFFSET(prod));
1571 1.1 drochner }
1572 1.1 drochner
1573 1.1 drochner r->r_prod = prod;
1574 1.1 drochner r->r_cnt = cnt;
1575 1.1 drochner }
1576 1.1 drochner
1577 1.1 drochner /*
1578 1.1 drochner * Handle simple commands sent to the typhoon
1579 1.1 drochner */
1580 1.62 maxv static int
1581 1.53 msaitoh txp_command(struct txp_softc *sc, uint16_t id, uint16_t in1, uint32_t in2,
1582 1.53 msaitoh uint32_t in3, uint16_t *out1, uint32_t *out2, uint32_t *out3, int wait)
1583 1.1 drochner {
1584 1.1 drochner struct txp_rsp_desc *rsp = NULL;
1585 1.1 drochner
1586 1.1 drochner if (txp_command2(sc, id, in1, in2, in3, NULL, 0, &rsp, wait))
1587 1.1 drochner return (-1);
1588 1.1 drochner
1589 1.1 drochner if (!wait)
1590 1.1 drochner return (0);
1591 1.1 drochner
1592 1.1 drochner if (out1 != NULL)
1593 1.1 drochner *out1 = le16toh(rsp->rsp_par1);
1594 1.1 drochner if (out2 != NULL)
1595 1.1 drochner *out2 = le32toh(rsp->rsp_par2);
1596 1.1 drochner if (out3 != NULL)
1597 1.1 drochner *out3 = le32toh(rsp->rsp_par3);
1598 1.1 drochner free(rsp, M_DEVBUF);
1599 1.1 drochner return (0);
1600 1.1 drochner }
1601 1.1 drochner
1602 1.62 maxv static int
1603 1.53 msaitoh txp_command2(struct txp_softc *sc, uint16_t id, uint16_t in1, uint32_t in2,
1604 1.53 msaitoh uint32_t in3, struct txp_ext_desc *in_extp, uint8_t in_extn,
1605 1.44 msaitoh struct txp_rsp_desc **rspp, int wait)
1606 1.1 drochner {
1607 1.1 drochner struct txp_hostvar *hv = sc->sc_hostvar;
1608 1.1 drochner struct txp_cmd_desc *cmd;
1609 1.1 drochner struct txp_ext_desc *ext;
1610 1.53 msaitoh uint32_t idx, i;
1611 1.53 msaitoh uint16_t seq;
1612 1.1 drochner
1613 1.1 drochner if (txp_cmd_desc_numfree(sc) < (in_extn + 1)) {
1614 1.1 drochner printf("%s: no free cmd descriptors\n", TXP_DEVNAME(sc));
1615 1.1 drochner return (-1);
1616 1.1 drochner }
1617 1.1 drochner
1618 1.1 drochner idx = sc->sc_cmdring.lastwrite;
1619 1.53 msaitoh cmd = (struct txp_cmd_desc *)(((uint8_t *)sc->sc_cmdring.base) + idx);
1620 1.32 cegger memset(cmd, 0, sizeof(*cmd));
1621 1.1 drochner
1622 1.1 drochner cmd->cmd_numdesc = in_extn;
1623 1.1 drochner seq = sc->sc_seq++;
1624 1.1 drochner cmd->cmd_seq = htole16(seq);
1625 1.1 drochner cmd->cmd_id = htole16(id);
1626 1.1 drochner cmd->cmd_par1 = htole16(in1);
1627 1.1 drochner cmd->cmd_par2 = htole32(in2);
1628 1.1 drochner cmd->cmd_par3 = htole32(in3);
1629 1.1 drochner cmd->cmd_flags = CMD_FLAGS_TYPE_CMD |
1630 1.1 drochner (wait ? CMD_FLAGS_RESP : 0) | CMD_FLAGS_VALID;
1631 1.1 drochner
1632 1.1 drochner idx += sizeof(struct txp_cmd_desc);
1633 1.1 drochner if (idx == sc->sc_cmdring.size)
1634 1.1 drochner idx = 0;
1635 1.1 drochner
1636 1.1 drochner for (i = 0; i < in_extn; i++) {
1637 1.53 msaitoh ext = (struct txp_ext_desc *)(((uint8_t *)sc->sc_cmdring.base) + idx);
1638 1.34 tsutsui memcpy(ext, in_extp, sizeof(struct txp_ext_desc));
1639 1.1 drochner in_extp++;
1640 1.1 drochner idx += sizeof(struct txp_cmd_desc);
1641 1.1 drochner if (idx == sc->sc_cmdring.size)
1642 1.1 drochner idx = 0;
1643 1.1 drochner }
1644 1.1 drochner
1645 1.1 drochner sc->sc_cmdring.lastwrite = idx;
1646 1.1 drochner
1647 1.1 drochner WRITE_REG(sc, TXP_H2A_2, sc->sc_cmdring.lastwrite);
1648 1.1 drochner bus_dmamap_sync(sc->sc_dmat, sc->sc_host_dma.dma_map, 0,
1649 1.1 drochner sizeof(struct txp_hostvar), BUS_DMASYNC_PREREAD);
1650 1.1 drochner
1651 1.1 drochner if (!wait)
1652 1.1 drochner return (0);
1653 1.1 drochner
1654 1.1 drochner for (i = 0; i < 10000; i++) {
1655 1.1 drochner bus_dmamap_sync(sc->sc_dmat, sc->sc_host_dma.dma_map, 0,
1656 1.1 drochner sizeof(struct txp_hostvar), BUS_DMASYNC_POSTREAD);
1657 1.1 drochner idx = le32toh(hv->hv_resp_read_idx);
1658 1.1 drochner if (idx != le32toh(hv->hv_resp_write_idx)) {
1659 1.1 drochner *rspp = NULL;
1660 1.1 drochner if (txp_response(sc, idx, id, seq, rspp))
1661 1.1 drochner return (-1);
1662 1.1 drochner if (*rspp != NULL)
1663 1.1 drochner break;
1664 1.1 drochner }
1665 1.1 drochner bus_dmamap_sync(sc->sc_dmat, sc->sc_host_dma.dma_map, 0,
1666 1.1 drochner sizeof(struct txp_hostvar), BUS_DMASYNC_PREREAD);
1667 1.1 drochner DELAY(50);
1668 1.1 drochner }
1669 1.1 drochner if (i == 1000 || (*rspp) == NULL) {
1670 1.1 drochner printf("%s: 0x%x command failed\n", TXP_DEVNAME(sc), id);
1671 1.1 drochner return (-1);
1672 1.1 drochner }
1673 1.1 drochner
1674 1.1 drochner return (0);
1675 1.1 drochner }
1676 1.1 drochner
1677 1.62 maxv static int
1678 1.53 msaitoh txp_response(struct txp_softc *sc, uint32_t ridx, uint16_t id, uint16_t seq,
1679 1.44 msaitoh struct txp_rsp_desc **rspp)
1680 1.1 drochner {
1681 1.1 drochner struct txp_hostvar *hv = sc->sc_hostvar;
1682 1.1 drochner struct txp_rsp_desc *rsp;
1683 1.1 drochner
1684 1.1 drochner while (ridx != le32toh(hv->hv_resp_write_idx)) {
1685 1.53 msaitoh rsp = (struct txp_rsp_desc *)(((uint8_t *)sc->sc_rspring.base) + ridx);
1686 1.1 drochner
1687 1.1 drochner if (id == le16toh(rsp->rsp_id) && le16toh(rsp->rsp_seq) == seq) {
1688 1.1 drochner *rspp = (struct txp_rsp_desc *)malloc(
1689 1.1 drochner sizeof(struct txp_rsp_desc) * (rsp->rsp_numdesc + 1),
1690 1.1 drochner M_DEVBUF, M_NOWAIT);
1691 1.1 drochner if ((*rspp) == NULL)
1692 1.1 drochner return (-1);
1693 1.1 drochner txp_rsp_fixup(sc, rsp, *rspp);
1694 1.1 drochner return (0);
1695 1.1 drochner }
1696 1.1 drochner
1697 1.1 drochner if (rsp->rsp_flags & RSP_FLAGS_ERROR) {
1698 1.1 drochner printf("%s: response error: id 0x%x\n",
1699 1.1 drochner TXP_DEVNAME(sc), le16toh(rsp->rsp_id));
1700 1.1 drochner txp_rsp_fixup(sc, rsp, NULL);
1701 1.1 drochner ridx = le32toh(hv->hv_resp_read_idx);
1702 1.1 drochner continue;
1703 1.1 drochner }
1704 1.1 drochner
1705 1.1 drochner switch (le16toh(rsp->rsp_id)) {
1706 1.1 drochner case TXP_CMD_CYCLE_STATISTICS:
1707 1.1 drochner case TXP_CMD_MEDIA_STATUS_READ:
1708 1.1 drochner break;
1709 1.1 drochner case TXP_CMD_HELLO_RESPONSE:
1710 1.1 drochner printf("%s: hello\n", TXP_DEVNAME(sc));
1711 1.1 drochner break;
1712 1.1 drochner default:
1713 1.1 drochner printf("%s: unknown id(0x%x)\n", TXP_DEVNAME(sc),
1714 1.1 drochner le16toh(rsp->rsp_id));
1715 1.1 drochner }
1716 1.1 drochner
1717 1.1 drochner txp_rsp_fixup(sc, rsp, NULL);
1718 1.1 drochner ridx = le32toh(hv->hv_resp_read_idx);
1719 1.1 drochner hv->hv_resp_read_idx = le32toh(ridx);
1720 1.1 drochner }
1721 1.1 drochner
1722 1.1 drochner return (0);
1723 1.1 drochner }
1724 1.1 drochner
1725 1.62 maxv static void
1726 1.44 msaitoh txp_rsp_fixup(struct txp_softc *sc, struct txp_rsp_desc *rsp,
1727 1.44 msaitoh struct txp_rsp_desc *dst)
1728 1.1 drochner {
1729 1.1 drochner struct txp_rsp_desc *src = rsp;
1730 1.1 drochner struct txp_hostvar *hv = sc->sc_hostvar;
1731 1.53 msaitoh uint32_t i, ridx;
1732 1.1 drochner
1733 1.1 drochner ridx = le32toh(hv->hv_resp_read_idx);
1734 1.1 drochner
1735 1.1 drochner for (i = 0; i < rsp->rsp_numdesc + 1; i++) {
1736 1.1 drochner if (dst != NULL)
1737 1.34 tsutsui memcpy(dst++, src, sizeof(struct txp_rsp_desc));
1738 1.1 drochner ridx += sizeof(struct txp_rsp_desc);
1739 1.1 drochner if (ridx == sc->sc_rspring.size) {
1740 1.1 drochner src = sc->sc_rspring.base;
1741 1.1 drochner ridx = 0;
1742 1.1 drochner } else
1743 1.1 drochner src++;
1744 1.1 drochner sc->sc_rspring.lastwrite = ridx;
1745 1.1 drochner hv->hv_resp_read_idx = htole32(ridx);
1746 1.1 drochner }
1747 1.10 perry
1748 1.1 drochner hv->hv_resp_read_idx = htole32(ridx);
1749 1.1 drochner }
1750 1.1 drochner
1751 1.62 maxv static int
1752 1.29 dsl txp_cmd_desc_numfree(struct txp_softc *sc)
1753 1.1 drochner {
1754 1.1 drochner struct txp_hostvar *hv = sc->sc_hostvar;
1755 1.1 drochner struct txp_boot_record *br = sc->sc_boot;
1756 1.53 msaitoh uint32_t widx, ridx, nfree;
1757 1.1 drochner
1758 1.1 drochner widx = sc->sc_cmdring.lastwrite;
1759 1.1 drochner ridx = le32toh(hv->hv_cmd_read_idx);
1760 1.1 drochner
1761 1.1 drochner if (widx == ridx) {
1762 1.1 drochner /* Ring is completely free */
1763 1.1 drochner nfree = le32toh(br->br_cmd_siz) - sizeof(struct txp_cmd_desc);
1764 1.1 drochner } else {
1765 1.1 drochner if (widx > ridx)
1766 1.1 drochner nfree = le32toh(br->br_cmd_siz) -
1767 1.1 drochner (widx - ridx + sizeof(struct txp_cmd_desc));
1768 1.1 drochner else
1769 1.1 drochner nfree = ridx - widx - sizeof(struct txp_cmd_desc);
1770 1.1 drochner }
1771 1.1 drochner
1772 1.1 drochner return (nfree / sizeof(struct txp_cmd_desc));
1773 1.1 drochner }
1774 1.1 drochner
1775 1.62 maxv static void
1776 1.29 dsl txp_stop(struct txp_softc *sc)
1777 1.1 drochner {
1778 1.1 drochner txp_command(sc, TXP_CMD_TX_DISABLE, 0, 0, 0, NULL, NULL, NULL, 1);
1779 1.1 drochner txp_command(sc, TXP_CMD_RX_DISABLE, 0, 0, 0, NULL, NULL, NULL, 1);
1780 1.1 drochner
1781 1.1 drochner if (callout_pending(&sc->sc_tick))
1782 1.1 drochner callout_stop(&sc->sc_tick);
1783 1.1 drochner }
1784 1.1 drochner
1785 1.62 maxv static void
1786 1.18 christos txp_watchdog(struct ifnet *ifp)
1787 1.1 drochner {
1788 1.1 drochner }
1789 1.1 drochner
1790 1.62 maxv static int
1791 1.29 dsl txp_ifmedia_upd(struct ifnet *ifp)
1792 1.1 drochner {
1793 1.1 drochner struct txp_softc *sc = ifp->if_softc;
1794 1.1 drochner struct ifmedia *ifm = &sc->sc_ifmedia;
1795 1.53 msaitoh uint16_t new_xcvr;
1796 1.1 drochner
1797 1.1 drochner if (IFM_TYPE(ifm->ifm_media) != IFM_ETHER)
1798 1.1 drochner return (EINVAL);
1799 1.1 drochner
1800 1.1 drochner if (IFM_SUBTYPE(ifm->ifm_media) == IFM_10_T) {
1801 1.52 msaitoh if ((ifm->ifm_media & IFM_FDX) != 0)
1802 1.1 drochner new_xcvr = TXP_XCVR_10_FDX;
1803 1.1 drochner else
1804 1.1 drochner new_xcvr = TXP_XCVR_10_HDX;
1805 1.2 drochner } else if ((IFM_SUBTYPE(ifm->ifm_media) == IFM_100_TX) ||
1806 1.2 drochner (IFM_SUBTYPE(ifm->ifm_media) == IFM_100_FX)) {
1807 1.52 msaitoh if ((ifm->ifm_media & IFM_FDX) != 0)
1808 1.1 drochner new_xcvr = TXP_XCVR_100_FDX;
1809 1.1 drochner else
1810 1.1 drochner new_xcvr = TXP_XCVR_100_HDX;
1811 1.1 drochner } else if (IFM_SUBTYPE(ifm->ifm_media) == IFM_AUTO) {
1812 1.1 drochner new_xcvr = TXP_XCVR_AUTO;
1813 1.1 drochner } else
1814 1.1 drochner return (EINVAL);
1815 1.1 drochner
1816 1.1 drochner /* nothing to do */
1817 1.1 drochner if (sc->sc_xcvr == new_xcvr)
1818 1.1 drochner return (0);
1819 1.1 drochner
1820 1.1 drochner txp_command(sc, TXP_CMD_XCVR_SELECT, new_xcvr, 0, 0,
1821 1.1 drochner NULL, NULL, NULL, 0);
1822 1.1 drochner sc->sc_xcvr = new_xcvr;
1823 1.1 drochner
1824 1.1 drochner return (0);
1825 1.1 drochner }
1826 1.1 drochner
1827 1.62 maxv static void
1828 1.29 dsl txp_ifmedia_sts(struct ifnet *ifp, struct ifmediareq *ifmr)
1829 1.1 drochner {
1830 1.1 drochner struct txp_softc *sc = ifp->if_softc;
1831 1.1 drochner struct ifmedia *ifm = &sc->sc_ifmedia;
1832 1.53 msaitoh uint16_t bmsr, bmcr, anlpar;
1833 1.1 drochner
1834 1.1 drochner ifmr->ifm_status = IFM_AVALID;
1835 1.1 drochner ifmr->ifm_active = IFM_ETHER;
1836 1.1 drochner
1837 1.1 drochner if (txp_command(sc, TXP_CMD_PHY_MGMT_READ, 0, MII_BMSR, 0,
1838 1.1 drochner &bmsr, NULL, NULL, 1))
1839 1.1 drochner goto bail;
1840 1.1 drochner if (txp_command(sc, TXP_CMD_PHY_MGMT_READ, 0, MII_BMSR, 0,
1841 1.1 drochner &bmsr, NULL, NULL, 1))
1842 1.1 drochner goto bail;
1843 1.1 drochner
1844 1.1 drochner if (txp_command(sc, TXP_CMD_PHY_MGMT_READ, 0, MII_BMCR, 0,
1845 1.1 drochner &bmcr, NULL, NULL, 1))
1846 1.1 drochner goto bail;
1847 1.1 drochner
1848 1.1 drochner if (txp_command(sc, TXP_CMD_PHY_MGMT_READ, 0, MII_ANLPAR, 0,
1849 1.1 drochner &anlpar, NULL, NULL, 1))
1850 1.1 drochner goto bail;
1851 1.1 drochner
1852 1.1 drochner if (bmsr & BMSR_LINK)
1853 1.1 drochner ifmr->ifm_status |= IFM_ACTIVE;
1854 1.1 drochner
1855 1.1 drochner if (bmcr & BMCR_ISO) {
1856 1.1 drochner ifmr->ifm_active |= IFM_NONE;
1857 1.1 drochner ifmr->ifm_status = 0;
1858 1.1 drochner return;
1859 1.1 drochner }
1860 1.1 drochner
1861 1.1 drochner if (bmcr & BMCR_LOOP)
1862 1.1 drochner ifmr->ifm_active |= IFM_LOOP;
1863 1.1 drochner
1864 1.2 drochner if (!(sc->sc_flags & TXP_FIBER) && (bmcr & BMCR_AUTOEN)) {
1865 1.1 drochner if ((bmsr & BMSR_ACOMP) == 0) {
1866 1.1 drochner ifmr->ifm_active |= IFM_NONE;
1867 1.1 drochner return;
1868 1.1 drochner }
1869 1.1 drochner
1870 1.28 cegger if (anlpar & ANLPAR_TX_FD)
1871 1.53 msaitoh ifmr->ifm_active |= IFM_100_TX | IFM_FDX;
1872 1.28 cegger else if (anlpar & ANLPAR_T4)
1873 1.53 msaitoh ifmr->ifm_active |= IFM_100_T4 | IFM_HDX;
1874 1.1 drochner else if (anlpar & ANLPAR_TX)
1875 1.53 msaitoh ifmr->ifm_active |= IFM_100_TX | IFM_HDX;
1876 1.1 drochner else if (anlpar & ANLPAR_10_FD)
1877 1.53 msaitoh ifmr->ifm_active |= IFM_10_T | IFM_FDX;
1878 1.1 drochner else if (anlpar & ANLPAR_10)
1879 1.53 msaitoh ifmr->ifm_active |= IFM_10_T | IFM_HDX;
1880 1.1 drochner else
1881 1.1 drochner ifmr->ifm_active |= IFM_NONE;
1882 1.1 drochner } else
1883 1.1 drochner ifmr->ifm_active = ifm->ifm_cur->ifm_media;
1884 1.1 drochner return;
1885 1.1 drochner
1886 1.1 drochner bail:
1887 1.1 drochner ifmr->ifm_active |= IFM_NONE;
1888 1.1 drochner ifmr->ifm_status &= ~IFM_AVALID;
1889 1.1 drochner }
1890 1.1 drochner
1891 1.62 maxv #if 0 /* XXX XXX XXX UNUSED */
1892 1.62 maxv static void
1893 1.29 dsl txp_show_descriptor(void *d)
1894 1.1 drochner {
1895 1.1 drochner struct txp_cmd_desc *cmd = d;
1896 1.1 drochner struct txp_rsp_desc *rsp = d;
1897 1.1 drochner struct txp_tx_desc *txd = d;
1898 1.1 drochner struct txp_frag_desc *frgd = d;
1899 1.1 drochner
1900 1.1 drochner switch (cmd->cmd_flags & CMD_FLAGS_TYPE_M) {
1901 1.1 drochner case CMD_FLAGS_TYPE_CMD:
1902 1.1 drochner /* command descriptor */
1903 1.53 msaitoh printf("[cmd flags 0x%x num %d id %d seq %d par1 0x%x par2 "
1904 1.53 msaitoh "0x%x par3 0x%x]\n",
1905 1.1 drochner cmd->cmd_flags, cmd->cmd_numdesc, le16toh(cmd->cmd_id),
1906 1.1 drochner le16toh(cmd->cmd_seq), le16toh(cmd->cmd_par1),
1907 1.1 drochner le32toh(cmd->cmd_par2), le32toh(cmd->cmd_par3));
1908 1.1 drochner break;
1909 1.1 drochner case CMD_FLAGS_TYPE_RESP:
1910 1.1 drochner /* response descriptor */
1911 1.53 msaitoh printf("[rsp flags 0x%x num %d id %d seq %d par1 0x%x par2 "
1912 1.53 msaitoh "0x%x par3 0x%x]\n",
1913 1.1 drochner rsp->rsp_flags, rsp->rsp_numdesc, le16toh(rsp->rsp_id),
1914 1.1 drochner le16toh(rsp->rsp_seq), le16toh(rsp->rsp_par1),
1915 1.1 drochner le32toh(rsp->rsp_par2), le32toh(rsp->rsp_par3));
1916 1.1 drochner break;
1917 1.1 drochner case CMD_FLAGS_TYPE_DATA:
1918 1.1 drochner /* data header (assuming tx for now) */
1919 1.53 msaitoh printf("[data flags 0x%x num %d totlen %d addr 0x%x/0x%x "
1920 1.53 msaitoh "pflags 0x%x]",
1921 1.1 drochner txd->tx_flags, txd->tx_numdesc, txd->tx_totlen,
1922 1.1 drochner txd->tx_addrlo, txd->tx_addrhi, txd->tx_pflags);
1923 1.1 drochner break;
1924 1.1 drochner case CMD_FLAGS_TYPE_FRAG:
1925 1.1 drochner /* fragment descriptor */
1926 1.53 msaitoh printf("[frag flags 0x%x rsvd1 0x%x len %d addr 0x%x/0x%x "
1927 1.53 msaitoh "rsvd2 0x%x]",
1928 1.1 drochner frgd->frag_flags, frgd->frag_rsvd1, frgd->frag_len,
1929 1.1 drochner frgd->frag_addrlo, frgd->frag_addrhi, frgd->frag_rsvd2);
1930 1.1 drochner break;
1931 1.1 drochner default:
1932 1.53 msaitoh printf("[unknown(%x) flags 0x%x num %d id %d seq %d par1 "
1933 1.53 msaitoh "0x%x par2 0x%x par3 0x%x]\n",
1934 1.1 drochner cmd->cmd_flags & CMD_FLAGS_TYPE_M,
1935 1.1 drochner cmd->cmd_flags, cmd->cmd_numdesc, le16toh(cmd->cmd_id),
1936 1.1 drochner le16toh(cmd->cmd_seq), le16toh(cmd->cmd_par1),
1937 1.1 drochner le32toh(cmd->cmd_par2), le32toh(cmd->cmd_par3));
1938 1.1 drochner break;
1939 1.1 drochner }
1940 1.1 drochner }
1941 1.62 maxv #endif
1942 1.1 drochner
1943 1.62 maxv static void
1944 1.29 dsl txp_set_filter(struct txp_softc *sc)
1945 1.1 drochner {
1946 1.55 msaitoh struct ethercom *ec = &sc->sc_arpcom;
1947 1.1 drochner struct ifnet *ifp = &sc->sc_arpcom.ec_if;
1948 1.53 msaitoh uint32_t crc, carry, hashbit, hash[2];
1949 1.53 msaitoh uint16_t filter;
1950 1.53 msaitoh uint8_t octet;
1951 1.1 drochner int i, j, mcnt = 0;
1952 1.1 drochner struct ether_multi *enm;
1953 1.1 drochner struct ether_multistep step;
1954 1.1 drochner
1955 1.1 drochner if (ifp->if_flags & IFF_PROMISC) {
1956 1.1 drochner filter = TXP_RXFILT_PROMISC;
1957 1.1 drochner goto setit;
1958 1.1 drochner }
1959 1.1 drochner
1960 1.1 drochner again:
1961 1.1 drochner filter = TXP_RXFILT_DIRECT;
1962 1.1 drochner
1963 1.1 drochner if (ifp->if_flags & IFF_BROADCAST)
1964 1.1 drochner filter |= TXP_RXFILT_BROADCAST;
1965 1.1 drochner
1966 1.1 drochner if (ifp->if_flags & IFF_ALLMULTI)
1967 1.1 drochner filter |= TXP_RXFILT_ALLMULTI;
1968 1.1 drochner else {
1969 1.1 drochner hash[0] = hash[1] = 0;
1970 1.1 drochner
1971 1.56 msaitoh ETHER_LOCK(ec);
1972 1.55 msaitoh ETHER_FIRST_MULTI(step, ec, enm);
1973 1.1 drochner while (enm != NULL) {
1974 1.44 msaitoh if (memcmp(enm->enm_addrlo, enm->enm_addrhi,
1975 1.44 msaitoh ETHER_ADDR_LEN)) {
1976 1.1 drochner /*
1977 1.1 drochner * We must listen to a range of multicast
1978 1.1 drochner * addresses. For now, just accept all
1979 1.1 drochner * multicasts, rather than trying to set only
1980 1.1 drochner * those filter bits needed to match the range.
1981 1.1 drochner * (At this time, the only use of address
1982 1.1 drochner * ranges is for IP multicast routing, for
1983 1.1 drochner * which the range is big enough to require
1984 1.1 drochner * all bits set.)
1985 1.1 drochner */
1986 1.1 drochner ifp->if_flags |= IFF_ALLMULTI;
1987 1.56 msaitoh ETHER_UNLOCK(ec);
1988 1.1 drochner goto again;
1989 1.1 drochner }
1990 1.1 drochner
1991 1.1 drochner mcnt++;
1992 1.1 drochner crc = 0xffffffff;
1993 1.1 drochner
1994 1.1 drochner for (i = 0; i < ETHER_ADDR_LEN; i++) {
1995 1.1 drochner octet = enm->enm_addrlo[i];
1996 1.1 drochner for (j = 0; j < 8; j++) {
1997 1.1 drochner carry = ((crc & 0x80000000) ? 1 : 0) ^
1998 1.1 drochner (octet & 1);
1999 1.1 drochner crc <<= 1;
2000 1.1 drochner octet >>= 1;
2001 1.1 drochner if (carry)
2002 1.1 drochner crc = (crc ^ TXP_POLYNOMIAL) |
2003 1.1 drochner carry;
2004 1.1 drochner }
2005 1.1 drochner }
2006 1.53 msaitoh hashbit = (uint16_t)(crc & (64 - 1));
2007 1.1 drochner hash[hashbit / 32] |= (1 << hashbit % 32);
2008 1.1 drochner ETHER_NEXT_MULTI(step, enm);
2009 1.1 drochner }
2010 1.56 msaitoh ETHER_UNLOCK(ec);
2011 1.1 drochner
2012 1.1 drochner if (mcnt > 0) {
2013 1.1 drochner filter |= TXP_RXFILT_HASHMULTI;
2014 1.1 drochner txp_command(sc, TXP_CMD_MCAST_HASH_MASK_WRITE,
2015 1.1 drochner 2, hash[0], hash[1], NULL, NULL, NULL, 0);
2016 1.1 drochner }
2017 1.1 drochner }
2018 1.1 drochner
2019 1.1 drochner setit:
2020 1.1 drochner txp_command(sc, TXP_CMD_RX_FILTER_WRITE, filter, 0, 0,
2021 1.1 drochner NULL, NULL, NULL, 1);
2022 1.1 drochner }
2023 1.1 drochner
2024 1.62 maxv static void
2025 1.29 dsl txp_capabilities(struct txp_softc *sc)
2026 1.1 drochner {
2027 1.1 drochner struct ifnet *ifp = &sc->sc_arpcom.ec_if;
2028 1.1 drochner struct txp_rsp_desc *rsp = NULL;
2029 1.1 drochner struct txp_ext_desc *ext;
2030 1.1 drochner
2031 1.1 drochner if (txp_command2(sc, TXP_CMD_OFFLOAD_READ, 0, 0, 0, NULL, 0, &rsp, 1))
2032 1.1 drochner goto out;
2033 1.1 drochner
2034 1.1 drochner if (rsp->rsp_numdesc != 1)
2035 1.1 drochner goto out;
2036 1.1 drochner ext = (struct txp_ext_desc *)(rsp + 1);
2037 1.1 drochner
2038 1.1 drochner sc->sc_tx_capability = ext->ext_1 & OFFLOAD_MASK;
2039 1.1 drochner sc->sc_rx_capability = ext->ext_2 & OFFLOAD_MASK;
2040 1.1 drochner
2041 1.4 drochner sc->sc_arpcom.ec_capabilities |= ETHERCAP_VLAN_MTU;
2042 1.1 drochner if (rsp->rsp_par2 & rsp->rsp_par3 & OFFLOAD_VLAN) {
2043 1.1 drochner sc->sc_tx_capability |= OFFLOAD_VLAN;
2044 1.1 drochner sc->sc_rx_capability |= OFFLOAD_VLAN;
2045 1.4 drochner sc->sc_arpcom.ec_capabilities |= ETHERCAP_VLAN_HWTAGGING;
2046 1.59 msaitoh sc->sc_arpcom.ec_capenable |= ETHERCAP_VLAN_HWTAGGING;
2047 1.1 drochner }
2048 1.1 drochner
2049 1.1 drochner #if 0
2050 1.1 drochner /* not ready yet */
2051 1.1 drochner if (rsp->rsp_par2 & rsp->rsp_par3 & OFFLOAD_IPSEC) {
2052 1.1 drochner sc->sc_tx_capability |= OFFLOAD_IPSEC;
2053 1.1 drochner sc->sc_rx_capability |= OFFLOAD_IPSEC;
2054 1.1 drochner ifp->if_capabilities |= IFCAP_IPSEC;
2055 1.1 drochner }
2056 1.1 drochner #endif
2057 1.1 drochner
2058 1.1 drochner if (rsp->rsp_par2 & rsp->rsp_par3 & OFFLOAD_IPCKSUM) {
2059 1.1 drochner sc->sc_tx_capability |= OFFLOAD_IPCKSUM;
2060 1.1 drochner sc->sc_rx_capability |= OFFLOAD_IPCKSUM;
2061 1.11 yamt ifp->if_capabilities |= IFCAP_CSUM_IPv4_Tx | IFCAP_CSUM_IPv4_Rx;
2062 1.1 drochner }
2063 1.1 drochner
2064 1.1 drochner if (rsp->rsp_par2 & rsp->rsp_par3 & OFFLOAD_TCPCKSUM) {
2065 1.1 drochner sc->sc_rx_capability |= OFFLOAD_TCPCKSUM;
2066 1.1 drochner #ifdef TRY_TX_TCP_CSUM
2067 1.1 drochner sc->sc_tx_capability |= OFFLOAD_TCPCKSUM;
2068 1.11 yamt ifp->if_capabilities |=
2069 1.11 yamt IFCAP_CSUM_TCPv4_Tx | IFCAP_CSUM_TCPv4_Rx;
2070 1.1 drochner #endif
2071 1.1 drochner }
2072 1.1 drochner
2073 1.1 drochner if (rsp->rsp_par2 & rsp->rsp_par3 & OFFLOAD_UDPCKSUM) {
2074 1.1 drochner sc->sc_rx_capability |= OFFLOAD_UDPCKSUM;
2075 1.1 drochner #ifdef TRY_TX_UDP_CSUM
2076 1.1 drochner sc->sc_tx_capability |= OFFLOAD_UDPCKSUM;
2077 1.11 yamt ifp->if_capabilities |=
2078 1.11 yamt IFCAP_CSUM_UDPv4_Tx | IFCAP_CSUM_UDPv4_Rx;
2079 1.1 drochner #endif
2080 1.1 drochner }
2081 1.1 drochner
2082 1.1 drochner if (txp_command(sc, TXP_CMD_OFFLOAD_WRITE, 0,
2083 1.1 drochner sc->sc_tx_capability, sc->sc_rx_capability, NULL, NULL, NULL, 1))
2084 1.1 drochner goto out;
2085 1.1 drochner
2086 1.1 drochner out:
2087 1.1 drochner if (rsp != NULL)
2088 1.1 drochner free(rsp, M_DEVBUF);
2089 1.1 drochner }
2090